We don’t actually use a fragment shader. Here is our code:
//-----------------------------------------------------------------------------
//
//
bool IrayRenderer::DrawOpenGl(int width, int height)
{
bool retval = m_buffer_ready;
m_buffer_lock.lock();
{
if (m_buffer != nullptr && m_buffer_ready)
{
mi::nrx::Util_ogl::clear(0.0f, 0.0f, 0.0f, 0.0f); // for debugging: clear to green
mi::nrx::Util_ogl::copy_to_texture(m_ogl_tex_id, GL_RGB32F, GL_FLOAT, width, height, m_buffer);
mi::nrx::Util_ogl::draw_texture_quad(m_ogl_tex_id, true);
m_buffer_ready = false;
}
}
m_buffer_lock.unlock();
return retval;
}
Where the helpers are as follows:
//-----------------------------------------------------------------------------
//
//
void Util_ogl::copy_to_texture(unsigned texture, int internal_format, int type, int src_width, int src_height,
const void *pixels)
{
int format = internal_format;
if (internal_format == GL_RGBA32F)
format = GL_RGBA;
if (internal_format == GL_RGB32F)
format = GL_RGB;
GL_CHECK(glBindTexture(GL_TEXTURE_2D, texture));
GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, internal_format, src_width, src_height, 0, format, type, pixels));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
}
//-----------------------------------------------------------------------------
//
//
void Util_ogl::draw_texture_quad(unsigned texture, const bool bigger)
{
GL_CHECK(glMatrixMode(GL_MODELVIEW));
GL_CHECK(glPushMatrix());
GL_CHECK(glLoadIdentity());
GL_CHECK(glMatrixMode(GL_PROJECTION));
GL_CHECK(glPushMatrix());
GL_CHECK(glLoadIdentity());
GL_CHECK(gluOrtho2D(-1, 1, -1, 1));
GL_CHECK(glEnable(GL_TEXTURE_2D));
GL_CHECK(glDisable(GL_LIGHTING));
GL_CHECK(glColor3f(1, 1, 1));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, texture));
// only generate/update mipmaps if triggered in texpipeline (cam res > viewport res)
if (glGenerateMipmap && bigger)
{
GL_CHECK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
GL_CHECK(glGenerateMipmap(GL_TEXTURE_2D));
}
else
GL_CHECK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
// FULLSCRQUAD();
{
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex4f(-1, -1, 0, 1);
glTexCoord2f(1, 0);
glVertex4f(1, -1, 0, 1);
glTexCoord2f(1, 1);
glVertex4f(1, 1, 0, 1);
glTexCoord2f(0, 1);
glVertex4f(-1, 1, 0, 1);
glEnd();
}
GL_CHECK(glDisable(GL_TEXTURE_2D));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
GL_CHECK(glPopMatrix());
GL_CHECK(glMatrixMode(GL_MODELVIEW));
GL_CHECK(glPopMatrix());
}