48 #include <private/qgl_p.h> 53 #include <qdesktopwidget> 57 #include <private/qeglproperties_p.h> 58 #include <private/qeglcontext_p.h> 59 #include <private/qgl_egl_p.h> 112 d->widget->makeCurrent();
139 int devType = device()->devType();
141 qWarning(
"QGLContext::chooseContext(): Cannot create QGLContext's for paint device type %d", devType);
147 d->ownsEglContext =
true;
159 if (!
d->eglContext->chooseConfig(configProps)) {
160 delete d->eglContext;
169 if (!
d->eglContext->createContext
170 (shareContext ? shareContext->d_func()->eglContext : 0)) {
171 delete d->eglContext;
175 d->sharing =
d->eglContext->isSharing();
176 if (
d->sharing && shareContext)
177 const_cast<QGLContext *
>(shareContext)->d_func()->sharing =
true;
179 #if defined(EGL_VERSION_1_1) 181 eglSwapInterval(
d->eglContext->display(),
d->glFormat.swapInterval());
185 d->eglSurface =
d->eglContext->createSurface(device());
186 if (
d->eglSurface == EGL_NO_SURFACE) {
187 delete d->eglContext;
200 return (((!a) && (!b)) || (a && b));
226 void resize(
int newSize);
228 int find(
QRgb color)
const;
229 int findNearest(
QRgb color)
const;
232 void setEntry(
int idx,
QRgb color,
uint flags = 0,
quint8 context = 0);
234 const QRgb* colors()
const;
274 return d->colorArray.size();
302 if (newSize < 0 || newSize >
d->maxSize) {
303 qWarning(
"QGLCmap::resize(): size out of range");
306 int oldSize = size();
309 d->colorArray.resize(newSize);
310 d->allocArray.resize(newSize);
311 d->contextArray.resize(newSize);
312 if (newSize > oldSize) {
313 memset(
d->allocArray.data() + oldSize, 0, newSize - oldSize);
314 memset(
d->contextArray.data() + oldSize, 0, newSize - oldSize);
322 if (it !=
d->colorMap.end())
330 int idx = find(color);
333 int mapSize = size();
334 int mindist = 200000;
337 int b =
qBlue(color);
338 int rx, gx, bx, dist;
339 for (
int i=0; i < mapSize; i++) {
342 QRgb ci =
d->colorArray[i];
346 dist = rx*rx + gx*gx + bx*bx;
347 if (dist < mindist) {
360 int idx = find(color);
364 int mapSize =
d->colorArray.size();
380 d->colorArray[newIdx] = color;
386 d->colorMap.insert(color, newIdx);
388 d->contextArray[newIdx] = context;
395 if (idx < 0 || idx >=
d->maxSize) {
396 qWarning(
"QGLCmap::set(): Index out of range");
400 int mapSize = size();
401 if (idx >= mapSize) {
405 d->colorArray[idx] = color;
411 d->colorMap.insert(color, idx);
413 d->contextArray[idx] = context;
419 return d->colorArray.data();
431 initContext(ctx, shareWidget);
433 if (q->isValid() && q->context()->format().hasOverlay()) {
435 if (!olcx->create(shareWidget ? shareWidget->
overlayContext() : 0)) {
438 glcx->d_func()->glFormat.setOverlay(
false);
453 for (
int i = 0; i < cols.
size(); i++) {
455 pe.peRed =
qRed(color);
456 pe.peGreen =
qGreen(color);
457 pe.peBlue =
qBlue(color);
460 SetPaletteEntries(cmap, i, 1, &pe);
469 HDC hdc = GetDC(q->winId());
470 SelectPalette(hdc, (HPALETTE)
cmap.handle(),
TRUE);
473 ReleaseDC(q->winId(), hdc);
480 setContext(
new QGLContext(
d->glcx->requestedFormat(),
this));
483 if (isValid() && context()->
format().hasOverlay()) {
485 if (!
d->olcx->create(isSharing() ?
d->glcx : 0)) {
488 d->glcx->d_func()->glFormat.setOverlay(
false);
507 if (!
d->glcx->initialized())
509 resizeGL(width(), height());
511 makeOverlayCurrent();
512 resizeOverlayGL(width(), height());
519 return d_func()->olcx;
527 d->olcx->makeCurrent();
528 if (!
d->olcx->initialized()) {
529 initializeOverlayGL();
530 d->olcx->setInitialized(
true);
540 makeOverlayCurrent();
542 if (
d->olcx->format().doubleBuffer()) {
544 d->olcx->swapBuffers();
554 bool deleteOldContext)
558 qWarning(
"QGLWidget::setContext: Cannot set null context");
562 qWarning(
"QGLWidget::setContext: Context must refer to this widget");
567 d->glcx->doneCurrent();
572 if (oldcx && oldcx->d_func()->win == winId() && !
d->glcx->deviceIsPixmap()) {
576 doShow = isVisible();
578 QPoint pos = geometry().topLeft();
579 setParent(pW, windowFlags());
583 if (!
d->glcx->isValid()) {
584 d->glcx->create(shareContext ? shareContext : oldcx);
589 d->glcx->d_ptr->sharing =
false;
592 if (deleteOldContext)
604 HDC hdc = GetDC(q->winId());
605 SelectPalette(hdc, (HPALETTE) GetStockObject(DEFAULT_PALETTE),
FALSE);
606 DeleteObject((HPALETTE)
cmap.handle());
607 ReleaseDC(q->winId(), hdc);
615 return d_func()->cmap;
623 if (
d->cmap.handle()) {
626 LOGPALETTE *lpal = (LOGPALETTE *) malloc(
sizeof(LOGPALETTE)
627 +c.
size()*
sizeof(PALETTEENTRY));
628 lpal->palVersion = 0x300;
629 lpal->palNumEntries = c.
size();
630 d->cmap.setHandle(CreatePalette(lpal));
void qt_glformat_from_eglconfig(QGLFormat &format, const EGLConfig config)
#define QT_END_NAMESPACE
This macro expands to.
QPointer< QWidget > widget
#define it(className, varName)
int size() const
Returns the number of colorcells in the colormap.
void setEntry(int idx, QRgb color, uint flags=0, quint8 context=0)
long ASN1_INTEGER_get ASN1_INTEGER * a
int allocate(QRgb color, uint flags=0, quint8 context=0)
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
int find(QRgb color) const
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setRenderableType(QEgl::API api)
QVector< quint8 > contextArray
The QGLContext class encapsulates an OpenGL rendering context.
The QResizeEvent class contains event parameters for resize events.
Q_CORE_EXPORT void qWarning(const char *,...)
#define FALSE
Synonym for false.
QPaintDevice * device() const
Returns the paint device set for this context.
bool deviceIsPixmap() const
Returns true if the paint device of this context is a pixmap; otherwise returns false.
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
The QGLColormap class is used for installing custom colormaps into a QGLWidget.
int findNearest(QRgb color) const
virtual int choosePixelFormat(void *pfd, HDC pdc)
Win32 only: This virtual function chooses a pixel format that matches the OpenGL format.
#define TRUE
Synonym for true.
QRgb entryRgb(int idx) const
Returns the QRgb value in the colorcell with index idx.
virtual bool chooseContext(const QGLContext *shareContext=0)
This semi-internal function is called by create().
const QRgb * colors() const
static bool qLogEq(bool a, bool b)
The QPoint class defines a point in the plane using integer precision.
QGLTemporaryContext(bool directRendering=true, QWidget *parent=0)
void setPaintDeviceFormat(QPaintDevice *dev)
QVector< quint8 > allocArray
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
static void qStoreColors(HPALETTE cmap, const QGLColormap &cols)
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
void setDeviceType(int devType)
void qt_eglproperties_set_glformat(QEglProperties &eglProperties, const QGLFormat &glFormat)
QGLCmap & operator=(const QGLCmap &map)
QMap< uint, int > colorMap
QVector< uint > colorArray