Beispiel #1
0
 def paintGL(self):
     qDebug("paintGL()")
     gl = QOpenGLContext.currentContext().versionFunctions(glVersionProfile)
     
     vaoBinder = QOpenGLVertexArrayObject.Binder(self.vao)
     
     # Draw checkerboard so transparency is obvious
     self.transparecyProgram.bind()
     
     if self.backgroundColour and self.backgroundColour.isValid():
         self.transparecyProgram.setUniformValue("backgroundColour", self.backgroundColour)
     
     gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
     
     self.transparecyProgram.release()
     
     self.program.bind()
         
     if self.texture:
         self.texture.bind()
     
     gl.glEnable(gl.GL_BLEND)
     gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     
     gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
     
     if self.texture:
         self.texture.release()
     self.program.release()
Beispiel #2
0
 def initializeGL(self):
     qDebug("initializeGL()")
     if self.logger:
         self.logger.initialize()
         self.logger.messageLogged.connect(lambda message: qDebug(self.__tr("OpenGL debug message: {0}").fomat(message.message())))
         self.logger.startLogging()
     
     gl = QOpenGLContext.currentContext().versionFunctions(glVersionProfile)
     QOpenGLContext.currentContext().aboutToBeDestroyed.connect(self.cleanup)
     
     self.clean = False
     
     fragmentShader = None
     vertexShader = vertexShader2D
     if self.ddsFile.isCubemap:
         fragmentShader = fragmentShaderCube
         vertexShader = vertexShaderCube
         if QOpenGLContext.currentContext().hasExtension(b"GL_ARB_seamless_cube_map"):
             GL_TEXTURE_CUBE_MAP_SEAMLESS = 0x884F
             gl.glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS)
     elif self.ddsFile.glFormat.samplerType == "F":
         fragmentShader = fragmentShaderFloat
     elif self.ddsFile.glFormat.samplerType == "UI":
         fragmentShader = fragmentShaderUInt
     else:
         fragmentShader = fragmentShaderSInt
     
     self.program = QOpenGLShaderProgram(self)
     self.program.addShaderFromSourceCode(QOpenGLShader.Vertex, vertexShader)
     self.program.addShaderFromSourceCode(QOpenGLShader.Fragment, fragmentShader)
     self.program.bindAttributeLocation("position", 0)
     self.program.bindAttributeLocation("texCoordIn", 1)
     self.program.link()
     
     self.transparecyProgram = QOpenGLShaderProgram(self)
     self.transparecyProgram.addShaderFromSourceCode(QOpenGLShader.Vertex, transparencyVS)
     self.transparecyProgram.addShaderFromSourceCode(QOpenGLShader.Fragment, transparencyFS)
     self.transparecyProgram.bindAttributeLocation("position", 0)
     self.transparecyProgram.link()
     
     self.vao = QOpenGLVertexArrayObject(self)
     vaoBinder = QOpenGLVertexArrayObject.Binder(self.vao)
     
     self.vbo = QOpenGLBuffer(QOpenGLBuffer.VertexBuffer)
     self.vbo.create()
     self.vbo.bind()
     
     theBytes = struct.pack("%sf" % len(vertices), *vertices)
     self.vbo.allocate(theBytes, len(theBytes))
     
     gl.glEnableVertexAttribArray(0)
     gl.glEnableVertexAttribArray(1)
     gl.glVertexAttribPointer(0, 4, gl.GL_FLOAT, False, 6 * 4, 0)
     gl.glVertexAttribPointer(1, 2, gl.GL_FLOAT, False, 6 * 4, 4 * 4)
     
     self.texture = self.ddsFile.asQOpenGLTexture(gl, QOpenGLContext.currentContext())