Qt 4.8
Functions
qwaylandglwindowsurface.cpp File Reference
#include "qwaylandglwindowsurface.h"
#include "qwaylanddisplay.h"
#include "qwaylandwindow.h"
#include "qwaylandscreen.h"
#include <QtOpenGL/QGLFramebufferObject>
#include <QtOpenGL/QGLContext>
#include <QtOpenGL/private/qglengineshadermanager_p.h>

Go to the source code of this file.

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 &br)
 

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 104 of file qwaylandglwindowsurface.cpp.

Referenced by QWaylandGLWindowSurface::flush().

105 {
106  glDisable(GL_DEPTH_TEST);
107  glDisable(GL_SCISSOR_TEST);
108  glDisable(GL_BLEND);
109  glViewport(0, 0, viewport.width(), viewport.height());
110 
111  QGLShaderProgram *blitProgram =
113  blitProgram->bind();
114  blitProgram->setUniformValue("imageTexture", 0 /*QT_IMAGE_TEXTURE_UNIT*/);
115 
116  // The shader manager's blit program does not multiply the
117  // vertices by the pmv matrix, so we need to do the effect
118  // of the orthographic projection here ourselves.
119  QRectF r;
120  qreal w = viewport.width();
121  qreal h = viewport.height();
122  r.setLeft((targetRect.left() / w) * 2.0f - 1.0f);
123  if (targetRect.right() == (viewport.width() - 1))
124  r.setRight(1.0f);
125  else
126  r.setRight((targetRect.right() / w) * 2.0f - 1.0f);
127  r.setBottom((targetRect.top() / h) * 2.0f - 1.0f);
128  if (targetRect.bottom() == (viewport.height() - 1))
129  r.setTop(1.0f);
130  else
131  r.setTop((targetRect.bottom() / w) * 2.0f - 1.0f);
132 
133  drawTexture(r, texture, texSize, sourceRect);
134 }
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
#define GL_BLEND
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &br)
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 br 
)
static

Definition at line 55 of file qwaylandglwindowsurface.cpp.

Referenced by blitTexture().

56 {
57 #if !defined(QT_OPENGL_ES_2)
59 #endif
60  const GLenum target = GL_TEXTURE_2D;
61  QRectF src = br.isEmpty()
62  ? QRectF(QPointF(), texSize)
63  : QRectF(QPointF(br.x(), texSize.height() - br.bottom()), br.size());
64 
65  if (target == GL_TEXTURE_2D) {
66  qreal width = texSize.width();
67  qreal height = texSize.height();
68 
69  src.setLeft(src.left() / width);
70  src.setRight(src.right() / width);
71  src.setTop(src.top() / height);
72  src.setBottom(src.bottom() / height);
73  }
74 
75  const GLfloat tx1 = src.left();
76  const GLfloat tx2 = src.right();
77  const GLfloat ty1 = src.top();
78  const GLfloat ty2 = src.bottom();
79 
80  GLfloat texCoordArray[4*2] = {
81  tx1, ty2, tx2, ty2, tx2, ty1, tx1, ty1
82  };
83 
84  GLfloat vertexArray[4*2];
85  vertexArray[0] = rect.left(); vertexArray[1] = rect.top();
86  vertexArray[2] = rect.right(); vertexArray[3] = rect.top();
87  vertexArray[4] = rect.right(); vertexArray[5] = rect.bottom();
88  vertexArray[6] = rect.left(); vertexArray[7] = rect.bottom();
89 
92 
93  glBindTexture(target, tex_id);
94 
97  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
100 
101  glBindTexture(target, 0);
102 }
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
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
#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
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
#define GL_TRIANGLE_FAN
#define GL_FLOAT
unsigned int GLenum
Definition: main.cpp:50
#define glDisableVertexAttribArray
#define ctx
Definition: qgl.cpp:6094
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