aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2014-11-06 11:35:35 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2014-11-07 11:42:54 +0100
commit911b940c97e88dd9769d4831807e132706c38125 (patch)
tree2dcb8b3291566d408a8ea368f9d00a9aa7308ad8
parentefa81f8354f70d99e6341ffa5428495b28e68641 (diff)
Debug: Make it possible to save distance field cache on Windows
This makes compilation possible of the saveTexture() function which is used to store the distance field glyph cache on disk when debugging. It also changes the warnings output from here to have no prefix, since this is anyway always available as the context in Qt 5. Change-Id: If3b64f0921a59c485b5321a5465369708e764afc Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
-rw-r--r--src/quick/scenegraph/qsgadaptationlayer.cpp142
1 files changed, 67 insertions, 75 deletions
diff --git a/src/quick/scenegraph/qsgadaptationlayer.cpp b/src/quick/scenegraph/qsgadaptationlayer.cpp
index 9e4b572ea6..83704cf0ec 100644
--- a/src/quick/scenegraph/qsgadaptationlayer.cpp
+++ b/src/quick/scenegraph/qsgadaptationlayer.cpp
@@ -294,30 +294,32 @@ void QSGDistanceFieldGlyphCache::updateTexture(GLuint oldTex, GLuint newTex, con
void QSGDistanceFieldGlyphCache::saveTexture(GLuint textureId, int width, int height) const
{
+ QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
+
GLuint fboId;
- glGenFramebuffers(1, &fboId);
+ functions->glGenFramebuffers(1, &fboId);
GLuint tmpTexture = 0;
- glGenTextures(1, &tmpTexture);
- glBindTexture(GL_TEXTURE_2D, tmpTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glBindTexture(GL_TEXTURE_2D, 0);
-
- glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId);
- glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D,
- tmpTexture, 0);
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, textureId);
-
- glDisable(GL_STENCIL_TEST);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_SCISSOR_TEST);
- glDisable(GL_BLEND);
+ functions->glGenTextures(1, &tmpTexture);
+ functions->glBindTexture(GL_TEXTURE_2D, tmpTexture);
+ functions->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ functions->glBindTexture(GL_TEXTURE_2D, 0);
+
+ functions->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId);
+ functions->glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D,
+ tmpTexture, 0);
+
+ functions->glActiveTexture(GL_TEXTURE0);
+ functions->glBindTexture(GL_TEXTURE_2D, textureId);
+
+ functions->glDisable(GL_STENCIL_TEST);
+ functions->glDisable(GL_DEPTH_TEST);
+ functions->glDisable(GL_SCISSOR_TEST);
+ functions->glDisable(GL_BLEND);
GLfloat textureCoordinateArray[8];
textureCoordinateArray[0] = 0.0f;
@@ -339,9 +341,9 @@ void QSGDistanceFieldGlyphCache::saveTexture(GLuint textureId, int width, int he
vertexCoordinateArray[6] = -1.0f;
vertexCoordinateArray[7] = 1.0f;
- glViewport(0, 0, width, height);
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray);
+ functions->glViewport(0, 0, width, height);
+ functions->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray);
+ functions->glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray);
{
static const char *vertexShaderSource =
@@ -362,72 +364,64 @@ void QSGDistanceFieldGlyphCache::saveTexture(GLuint textureId, int width, int he
" gl_FragColor = texture2D(texture, textureCoords); \n"
"} \n";
- GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
- GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
+ GLuint vertexShader = functions->glCreateShader(GL_VERTEX_SHADER);
+ GLuint fragmentShader = functions->glCreateShader(GL_FRAGMENT_SHADER);
if (vertexShader == 0 || fragmentShader == 0) {
- GLenum error = glGetError();
- qWarning("SharedGraphicsCacheServer::setupShaderPrograms: Failed to create shaders. (GL error: %x)",
+ GLenum error = functions->glGetError();
+ qWarning("QSGDistanceFieldGlyphCache::saveTexture: Failed to create shaders. (GL error: %x)",
error);
return;
}
- glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
- glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
- glCompileShader(vertexShader);
+ functions->glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
+ functions->glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
+ functions->glCompileShader(vertexShader);
GLint len = 1;
- glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &len);
+ functions->glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &len);
char infoLog[2048];
- glGetShaderInfoLog(vertexShader, 2048, NULL, infoLog);
- if (qstrlen(infoLog) > 0) {
- qWarning("SharedGraphicsCacheServer::setupShaderPrograms, problems compiling vertex shader:\n %s",
- infoLog);
- }
+ functions->glGetShaderInfoLog(vertexShader, 2048, NULL, infoLog);
+ if (qstrlen(infoLog) > 0)
+ qWarning("Problems compiling vertex shader:\n %s", infoLog);
- glCompileShader(fragmentShader);
- glGetShaderInfoLog(fragmentShader, 2048, NULL, infoLog);
- if (qstrlen(infoLog) > 0) {
- qWarning("SharedGraphicsCacheServer::setupShaderPrograms, problems compiling fragent shader:\n %s",
- infoLog);
- }
+ functions->glCompileShader(fragmentShader);
+ functions->glGetShaderInfoLog(fragmentShader, 2048, NULL, infoLog);
+ if (qstrlen(infoLog) > 0)
+ qWarning("Problems compiling fragment shader:\n %s", infoLog);
- GLuint shaderProgram = glCreateProgram();
- glAttachShader(shaderProgram, vertexShader);
- glAttachShader(shaderProgram, fragmentShader);
+ GLuint shaderProgram = functions->glCreateProgram();
+ functions->glAttachShader(shaderProgram, vertexShader);
+ functions->glAttachShader(shaderProgram, fragmentShader);
- glBindAttribLocation(shaderProgram, 0, "vertexCoordsArray");
- glBindAttribLocation(shaderProgram, 1, "textureCoordArray");
+ functions->glBindAttribLocation(shaderProgram, 0, "vertexCoordsArray");
+ functions->glBindAttribLocation(shaderProgram, 1, "textureCoordArray");
- glLinkProgram(shaderProgram);
- glGetProgramInfoLog(shaderProgram, 2048, NULL, infoLog);
- if (qstrlen(infoLog) > 0) {
- qWarning("SharedGraphicsCacheServer::setupShaderPrograms, problems linking shaders:\n %s",
- infoLog);
- }
+ functions->glLinkProgram(shaderProgram);
+ functions->glGetProgramInfoLog(shaderProgram, 2048, NULL, infoLog);
+ if (qstrlen(infoLog) > 0)
+ qWarning("Problems linking shaders:\n %s", infoLog);
- glUseProgram(shaderProgram);
- glEnableVertexAttribArray(0);
- glEnableVertexAttribArray(1);
+ functions->glUseProgram(shaderProgram);
+ functions->glEnableVertexAttribArray(0);
+ functions->glEnableVertexAttribArray(1);
- int textureUniformLocation = glGetUniformLocation(shaderProgram, "texture");
- glUniform1i(textureUniformLocation, 0);
+ int textureUniformLocation = functions->glGetUniformLocation(shaderProgram, "texture");
+ functions->glUniform1i(textureUniformLocation, 0);
}
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ functions->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
{
- GLenum error = glGetError();
- if (error != GL_NO_ERROR) {
- qWarning("SharedGraphicsCacheServer::readBackBuffer: glDrawArrays reported error 0x%x",
- error);
- }
+ GLenum error = functions->glGetError();
+ if (error != GL_NO_ERROR)
+ qWarning("glDrawArrays reported error 0x%x", error);
}
uchar *data = new uchar[width * height * 4];
- glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ functions->glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
QImage image(data, width, height, QImage::Format_ARGB32);
@@ -437,18 +431,16 @@ void QSGDistanceFieldGlyphCache::saveTexture(GLuint textureId, int width, int he
image.save(QString::fromLocal8Bit(fileName));
{
- GLenum error = glGetError();
- if (error != GL_NO_ERROR) {
- qWarning("SharedGraphicsCacheServer::readBackBuffer: glReadPixels reported error 0x%x",
- error);
- }
+ GLenum error = functions->glGetError();
+ if (error != GL_NO_ERROR)
+ qWarning("glReadPixels reported error 0x%x", error);
}
- glDisableVertexAttribArray(0);
- glDisableVertexAttribArray(1);
+ functions->glDisableVertexAttribArray(0);
+ functions->glDisableVertexAttribArray(1);
- glDeleteFramebuffers(1, &fboId);
- glDeleteTextures(1, &tmpTexture);
+ functions->glDeleteFramebuffers(1, &fboId);
+ functions->glDeleteTextures(1, &tmpTexture);
delete[] data;
}