viewer/opengl: minor code improvements
This commit is contained in:
@@ -37,23 +37,23 @@ const GLfloat blit_vertices[] = {
|
||||
};
|
||||
|
||||
const GLfloat blit_texcoords[] = {
|
||||
0.0, 0.0,
|
||||
1.0, 0.0,
|
||||
1.0, 1.0,
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
1.0f, 1.0f,
|
||||
|
||||
0.0, 0.0,
|
||||
0.0, 1.0,
|
||||
1.0, 1.0
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f
|
||||
};
|
||||
|
||||
const GLfloat flipped_blit_texcoords[] = {
|
||||
0.0, 1.0,
|
||||
1.0, 1.0,
|
||||
1.0, 0.0,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
|
||||
0.0, 1.0,
|
||||
0.0, 0.0,
|
||||
1.0, 0.0
|
||||
0.0f, 1.0f,
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,8 @@ const GLfloat flipped_blit_texcoords[] = {
|
||||
*
|
||||
* Currently active QOpenGLFunctions object (use context()->functions() if unsure).
|
||||
*/
|
||||
void OpenGLRenderFunctions::PrepareToDraw(QOpenGLFunctions* f) {
|
||||
void OpenGLRenderFunctions::PrepareToDraw(QOpenGLFunctions* f)
|
||||
{
|
||||
f->glGenerateMipmap(GL_TEXTURE_2D);
|
||||
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
@@ -141,7 +142,6 @@ void OpenGLRenderFunctions::Blit(OpenGLShaderPtr pipeline, bool flipped, QMatrix
|
||||
|
||||
void OpenGLRenderFunctions::Blit(OpenGLShader *pipeline, bool flipped, QMatrix4x4 matrix)
|
||||
{
|
||||
// FIXME: is currentContext() reliable here?
|
||||
QOpenGLFunctions* func = QOpenGLContext::currentContext()->functions();
|
||||
|
||||
PrepareToDraw(func);
|
||||
@@ -153,13 +153,13 @@ void OpenGLRenderFunctions::Blit(OpenGLShader *pipeline, bool flipped, QMatrix4x
|
||||
QOpenGLBuffer m_vbo;
|
||||
m_vbo.create();
|
||||
m_vbo.bind();
|
||||
m_vbo.allocate(blit_vertices, 18 * static_cast<int>(sizeof(GLfloat)));
|
||||
m_vbo.allocate(blit_vertices, 18 * sizeof(GLfloat));
|
||||
m_vbo.release();
|
||||
|
||||
QOpenGLBuffer m_vbo2;
|
||||
m_vbo2.create();
|
||||
m_vbo2.bind();
|
||||
m_vbo2.allocate(flipped ? flipped_blit_texcoords : blit_texcoords, 12 * static_cast<int>(sizeof(GLfloat)));
|
||||
m_vbo2.allocate(flipped ? flipped_blit_texcoords : blit_texcoords, 12 * sizeof(GLfloat));
|
||||
m_vbo2.release();
|
||||
|
||||
pipeline->bind();
|
||||
@@ -167,13 +167,13 @@ void OpenGLRenderFunctions::Blit(OpenGLShader *pipeline, bool flipped, QMatrix4x
|
||||
pipeline->setUniformValue("ove_mvpmat", matrix);
|
||||
pipeline->setUniformValue("ove_maintex", 0);
|
||||
|
||||
GLuint vertex_location = static_cast<GLuint>(pipeline->attributeLocation("a_position"));
|
||||
int vertex_location = pipeline->attributeLocation("a_position");
|
||||
m_vbo.bind();
|
||||
func->glEnableVertexAttribArray(vertex_location);
|
||||
func->glVertexAttribPointer(vertex_location, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
m_vbo.release();
|
||||
|
||||
GLuint tex_location = static_cast<GLuint>(pipeline->attributeLocation("a_texcoord"));
|
||||
int tex_location = pipeline->attributeLocation("a_texcoord");
|
||||
m_vbo2.bind();
|
||||
func->glEnableVertexAttribArray(tex_location);
|
||||
func->glVertexAttribPointer(tex_location, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
|
||||
@@ -61,8 +61,8 @@ OpenGLShaderPtr OpenGLShader::CreateOCIO(QOpenGLContext* ctx,
|
||||
shaderDesc.setLut3DEdgeLen(OCIO_LUT3D_EDGE_SIZE);
|
||||
|
||||
// Compute LUT
|
||||
GLfloat* ocio_lut_data = new GLfloat[OCIO_NUM_3D_ENTRIES];
|
||||
processor->getGpuLut3D(ocio_lut_data, shaderDesc);
|
||||
std::vector<float> ocio_lut_data(OCIO_NUM_3D_ENTRIES);
|
||||
processor->getGpuLut3D(&ocio_lut_data[0], shaderDesc);
|
||||
|
||||
// Create LUT texture
|
||||
xf->glGenTextures(1, &lut_texture);
|
||||
@@ -81,10 +81,7 @@ OpenGLShaderPtr OpenGLShader::CreateOCIO(QOpenGLContext* ctx,
|
||||
// Allocate storage for texture
|
||||
xf->glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F,
|
||||
OCIO_LUT3D_EDGE_SIZE, OCIO_LUT3D_EDGE_SIZE, OCIO_LUT3D_EDGE_SIZE,
|
||||
0, GL_RGB, GL_FLOAT, ocio_lut_data);
|
||||
|
||||
// Delete local copy
|
||||
delete [] ocio_lut_data;
|
||||
0, GL_RGB, GL_FLOAT, &ocio_lut_data[0]);
|
||||
|
||||
// Create OCIO shader code
|
||||
QString shader_text;
|
||||
|
||||
@@ -266,7 +266,7 @@ void ViewerGLWidget::paintGL()
|
||||
framebuffer_.Attach(&managed_texture_);
|
||||
framebuffer_.Bind();
|
||||
|
||||
context()->functions()->glViewport(0, 0, managed_texture_.width(), managed_texture_.height());
|
||||
f->glViewport(0, 0, managed_texture_.width(), managed_texture_.height());
|
||||
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ void ViewerGLWidget::paintGL()
|
||||
// Bind retrieved texture
|
||||
managed_texture_.Bind();
|
||||
|
||||
context()->functions()->glViewport(0, 0, width(), height());
|
||||
f->glViewport(0, 0, width(), height());
|
||||
|
||||
OpenGLRenderFunctions::Blit(managed_copy_pipeline_);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user