From 4ed24ab7db2c56e84f8dfed78d0893634a4bba2f Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 19 Jun 2013 00:18:17 +0000 Subject: [PATCH] gpu: use the RenderContext class in a few friendly places. --- neercs/video/render.cpp | 10 +++++--- neercs/video/text-render.cpp | 50 ++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/neercs/video/render.cpp b/neercs/video/render.cpp index a0d17ef..78953e4 100644 --- a/neercs/video/render.cpp +++ b/neercs/video/render.cpp @@ -1450,8 +1450,11 @@ void Render::Draw2D() glViewport(0, 0, screen_size.x, screen_size.y); /* Clear the back buffer */ + + RenderContext rc; + rc.SetAlphaBlend(true); + glEnable(GL_TEXTURE_2D); - glEnable(GL_BLEND); glBlendFunc(GL_SRC_COLOR, GL_DST_ALPHA); Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); @@ -1475,8 +1478,9 @@ void Render::Draw3D() if (!m_shader) return; - glDisable(GL_DEPTH_TEST); - glDisable(GL_BLEND); + RenderContext rc; + rc.SetAlphaBlend(false); + rc.SetDepthTest(false); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx); diff --git a/neercs/video/text-render.cpp b/neercs/video/text-render.cpp index 565737c..ff116dc 100644 --- a/neercs/video/text-render.cpp +++ b/neercs/video/text-render.cpp @@ -143,34 +143,38 @@ void TextRender::Render() m_vbo2->Unlock(); m_fbo->Bind(); - glViewport(0, 0, m_fbo_size.x, m_fbo_size.y); - glDisable(GL_DEPTH_TEST); + { + RenderContext rc; + rc.SetDepthTest(false); + + glViewport(0, 0, m_fbo_size.x, m_fbo_size.y); #if !defined HAVE_GLES_2X - glEnable(GL_POINT_SPRITE); - //glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); - glDisable(GL_POINT_SMOOTH); - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); - glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); + glEnable(GL_POINT_SPRITE); + //glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); + glDisable(GL_POINT_SMOOTH); + glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); + glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); #endif - m_shader->Bind(); - m_font->Bind(); - m_shader->SetUniform(m_texture, 0); - m_shader->SetUniform(m_transform, xform); - m_shader->SetUniform(m_datasize, vec2(m_canvas_size.x, + m_shader->Bind(); + m_font->Bind(); + m_shader->SetUniform(m_texture, 0); + m_shader->SetUniform(m_transform, xform); + m_shader->SetUniform(m_datasize, vec2(m_canvas_size.x, max(m_font_size.x, m_font_size.y))); - m_vdecl->SetStream(m_vbo1, m_color); - m_vdecl->SetStream(m_vbo2, m_char); + m_vdecl->SetStream(m_vbo1, m_color); + m_vdecl->SetStream(m_vbo2, m_char); #if !HAVE_SHADER_4 - m_vdecl->SetStream(m_vbo3, m_vertexid); + m_vdecl->SetStream(m_vbo3, m_vertexid); #endif - m_vdecl->Bind(); - m_vdecl->DrawElements(MeshPrimitive::Points, 0, m_cells); - m_vdecl->Unbind(); - m_font->Unbind(); - m_shader->Unbind(); + m_vdecl->Bind(); + m_vdecl->DrawElements(MeshPrimitive::Points, 0, m_cells); + m_vdecl->Unbind(); + m_font->Unbind(); + m_shader->Unbind(); #if !defined HAVE_GLES_2X - glDisable(GL_POINT_SPRITE); + glDisable(GL_POINT_SPRITE); #endif + } m_fbo->Unbind(); } @@ -181,7 +185,9 @@ void TextRender::Blit(ivec2 pos, ivec2 size) ShaderTexture t = m_fbo->GetTexture(); uint64_t const &x = *(uint64_t const *)&t; - glDisable(GL_BLEND); + RenderContext rc; + rc.SetAlphaBlend(false); + glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, (int)x); glColor3f(1.0f, 1.0f, 1.0f);