Qt 4.8
Classes | Macros | Functions | Variables
qwindowsurface_gl.cpp File Reference
#include <QtGui/QApplication>
#include <QtGui/QColormap>
#include <QtGui/QDesktopWidget>
#include <QtGui/QPaintDevice>
#include <QtGui/QWidget>
#include <qglframebufferobject.h>
#include <qglpixelbuffer.h>
#include <qcolormap.h>
#include <qdesktopwidget.h>
#include <private/qwidget_p.h>
#include "qdebug.h"
#include <private/qt_x11_p.h>
#include <qx11info_x11.h>
#include <GL/glx.h>
#include <X11/Xlib.h>
#include <private/qglextensions_p.h>
#include <private/qwindowsurface_gl_p.h>
#include <private/qgl_p.h>
#include <private/qglpixelbuffer_p.h>
#include <private/qgraphicssystem_gl_p.h>
#include <private/qpaintengineex_opengl2_p.h>
#include <private/qpixmapdata_gl_p.h>
#include <private/qpaintengine_opengl_p.h>
#include <private/qeglcontext_p.h>

Go to the source code of this file.

Classes

class  QGLGlobalShareWidget
 
struct  QGLWindowSurfacePrivate
 

Macros

#define GLX_SAMPLE_BUFFERS_ARB   100000
 
#define GLX_SAMPLES_ARB   100001
 

Functions

static void blitTexture (QGLContext *ctx, GLuint texture, const QSize &viewport, const QSize &texSize, const QRect &targetRect, const QRect &sourceRect)
 
static void drawTexture (const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &src=QRectF())
 
 Q_GLOBAL_STATIC_WITH_INITIALIZER (QGLGlobalShareWidget, _qt_gl_share_widget, { qAddPostRoutine(qt_cleanup_gl_share_widget);}) static void qt_cleanup_gl_share_widget()
 
static void qt_cleanup_gl_share_widget ()
 
void qt_destroy_gl_share_widget ()
 
const QGLContextqt_gl_share_context ()
 
QGLWidgetqt_gl_share_widget ()
 
bool qt_initializing_gl_share_widget ()
 

Variables

Q_GUI_EXPORT bool qt_win_owndc_required
 

Macro Definition Documentation

◆ GLX_SAMPLE_BUFFERS_ARB

#define GLX_SAMPLE_BUFFERS_ARB   100000

Definition at line 81 of file qwindowsurface_gl.cpp.

Referenced by QGLGraphicsSystem::QGLGraphicsSystem().

◆ GLX_SAMPLES_ARB

#define GLX_SAMPLES_ARB   100001

Definition at line 82 of file qwindowsurface_gl.cpp.

Referenced by QGLGraphicsSystem::QGLGraphicsSystem().

Function Documentation

◆ blitTexture()

static void blitTexture ( QGLContext ctx,
GLuint  texture,
const QSize viewport,
const QSize texSize,
const QRect targetRect,
const QRect sourceRect 
)
static

Definition at line 548 of file qwindowsurface_gl.cpp.

Referenced by QGLWindowSurface::flush().

549 {
550  glDisable(GL_DEPTH_TEST);
551  glDisable(GL_SCISSOR_TEST);
552  glDisable(GL_BLEND);
553 
554  glViewport(0, 0, viewport.width(), viewport.height());
555 
556  QGLShaderProgram *blitProgram =
558  blitProgram->bind();
559  blitProgram->setUniformValue("imageTexture", 0 /*QT_IMAGE_TEXTURE_UNIT*/);
560 
561  // The shader manager's blit program does not multiply the
562  // vertices by the pmv matrix, so we need to do the effect
563  // of the orthographic projection here ourselves.
564  QRectF r;
565  qreal w = viewport.width();
566  qreal h = viewport.height();
567  r.setLeft((targetRect.left() / w) * 2.0f - 1.0f);
568  if (targetRect.right() == (viewport.width() - 1))
569  r.setRight(1.0f);
570  else
571  r.setRight((targetRect.right() / w) * 2.0f - 1.0f);
572  r.setBottom((targetRect.top() / h) * 2.0f - 1.0f);
573  if (targetRect.bottom() == (viewport.height() - 1))
574  r.setTop(1.0f);
575  else
576  r.setTop((targetRect.bottom() / w) * 2.0f - 1.0f);
577 
578  drawTexture(r, texture, texSize, sourceRect);
579 }
double qreal
Definition: qglobal.h:1193
void setLeft(qreal pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:670
#define GL_DEPTH_TEST
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
void setTop(qreal pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:674
QGLShaderProgram * blitProgram()
void setBottom(qreal pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:676
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
static QGLEngineSharedShaders * shadersForContext(const QGLContext *context)
void setRight(qreal pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:672
#define GL_SCISSOR_TEST
int width() const
Returns the width.
Definition: qsize.h:126
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &src=QRectF())
#define GL_BLEND
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
int height() const
Returns the height.
Definition: qsize.h:129
bool bind()
Binds this shader program to the active QGLContext and makes it the current shader program...
The QGLShaderProgram class allows OpenGL shader programs to be linked and used.

◆ drawTexture()

static void drawTexture ( const QRectF rect,
GLuint  tex_id,
const QSize texSize,
const QRectF src = QRectF() 
)
static

Definition at line 1092 of file qwindowsurface_gl.cpp.

Referenced by blitTexture(), QGLWindowSurface::flush(), QGLWindowSurface::paintDevice(), QGL2PaintEngineExPrivate::QGL2PaintEngineExPrivate(), and QGLWindowSurface::scroll().

1093 {
1094  const GLenum target = GL_TEXTURE_2D;
1095  QRectF src = br.isEmpty()
1096  ? QRectF(QPointF(), texSize)
1097  : QRectF(QPointF(br.x(), texSize.height() - br.bottom()), br.size());
1098 
1099  if (target == GL_TEXTURE_2D) {
1100  qreal width = texSize.width();
1101  qreal height = texSize.height();
1102 
1103  src.setLeft(src.left() / width);
1104  src.setRight(src.right() / width);
1105  src.setTop(src.top() / height);
1106  src.setBottom(src.bottom() / height);
1107  }
1108 
1109  const GLfloat tx1 = src.left();
1110  const GLfloat tx2 = src.right();
1111  const GLfloat ty1 = src.top();
1112  const GLfloat ty2 = src.bottom();
1113 
1114  GLfloat texCoordArray[4*2] = {
1115  tx1, ty2, tx2, ty2, tx2, ty1, tx1, ty1
1116  };
1117 
1118  GLfloat vertexArray[4*2];
1119  extern void qt_add_rect_to_array(const QRectF &r, GLfloat *array); // qpaintengine_opengl.cpp
1120  qt_add_rect_to_array(rect, vertexArray);
1121 
1122 #if !defined(QT_OPENGL_ES_2)
1123  glVertexPointer(2, GL_FLOAT, 0, vertexArray);
1124  glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray);
1125 
1126  glBindTexture(target, tex_id);
1127  glEnable(target);
1128 
1129  glEnableClientState(GL_VERTEX_ARRAY);
1130  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1131  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1132  glDisableClientState(GL_VERTEX_ARRAY);
1133  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1134 
1135  glDisable(target);
1136  glBindTexture(target, 0);
1137 #else
1140 
1141  glBindTexture(target, tex_id);
1142 
1145  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1148 
1149  glBindTexture(target, 0);
1150 #endif
1151 }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
double qreal
Definition: qglobal.h:1193
void setLeft(qreal pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:670
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
void setTop(qreal pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:674
#define glVertexAttribPointer
Definition: glfunctions.h:71
void setBottom(qreal pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:676
#define glEnableVertexAttribArray
#define GL_TEXTURE_2D
void setRight(qreal pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:672
#define GL_FALSE
int width() const
Returns the width.
Definition: qsize.h:126
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void qt_add_rect_to_array(const QRectF &r, GLfloat *array)
Definition: qgl.cpp:2972
#define GL_TRIANGLE_FAN
#define GL_FLOAT
unsigned int GLenum
Definition: main.cpp:50
#define glDisableVertexAttribArray
int height() const
Returns the height.
Definition: qsize.h:129
static const GLuint QT_TEXTURE_COORDS_ATTR
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
static const GLuint QT_VERTEX_COORDS_ATTR
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658

◆ Q_GLOBAL_STATIC_WITH_INITIALIZER()

Q_GLOBAL_STATIC_WITH_INITIALIZER ( QGLGlobalShareWidget  ,
_qt_gl_share_widget  ,
{ qAddPostRoutine(qt_cleanup_gl_share_widget);}   
)

Definition at line 253 of file qwindowsurface_gl.cpp.

254  {
256  })
257 
258 static void qt_cleanup_gl_share_widget()
259 {
261  _qt_gl_share_widget()->cleanup();
262 }
static void qt_cleanup_gl_share_widget()
void qAddPostRoutine(QtCleanUpFunction ptr)
Adds a global routine that will be called from the QApplication destructor.

◆ qt_cleanup_gl_share_widget()

static void qt_cleanup_gl_share_widget ( )
static

◆ qt_destroy_gl_share_widget()

void qt_destroy_gl_share_widget ( )

Definition at line 271 of file qwindowsurface_gl.cpp.

Referenced by QGLWindowSurface::~QGLWindowSurface(), and QMeeGoGraphicsSystem::~QMeeGoGraphicsSystem().

272 {
274  _qt_gl_share_widget()->destroy();
275 }

◆ qt_gl_share_context()

const QGLContext* qt_gl_share_context ( )

Definition at line 284 of file qwindowsurface_gl.cpp.

Referenced by QGLPixmapData::copy(), QGLPixmapData::copyBackFromRenderFbo(), QGLPixmapData::createPixmapForImage(), QGLPixmapData::ensureCreated(), QGLPixmapData::fromData(), QGLPixmapData::fromFile(), QGLWindowSurface::hijackWindow(), QGLPixmapData::isValidContext(), QGLPixmapData::paintEngine(), QGLPixmapData::resize(), QGLPixmapData::toImage(), QGLPixmapData::~QGLPixmapData(), and QGLWindowSurface::~QGLWindowSurface().

285 {
287  if (widget)
288  return widget->context();
289  return 0;
290 }
QPointer< QWidget > widget
const QGLContext * context() const
Returns the context of this widget.
Definition: qgl.cpp:5303
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
QGLWidget * qt_gl_share_widget()

◆ qt_gl_share_widget()

QGLWidget* qt_gl_share_widget ( )

◆ qt_initializing_gl_share_widget()

bool qt_initializing_gl_share_widget ( )

Definition at line 277 of file qwindowsurface_gl.cpp.

Referenced by QGLWidgetPrivate::QGLWidgetPrivate().

278 {
280  return _qt_gl_share_widget()->initializing();
281  return false;
282 }

Variable Documentation

◆ qt_win_owndc_required

Q_GUI_EXPORT bool qt_win_owndc_required