medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit cef68e2f02e38bcba7d3a5d6b79f5a512af413bf
parent f6253b30be1973db22e5452076e1c3092288dc5c
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Nov 27 14:16:54 +0200

Enable DepthFunc in the renderer

Diffstat:
renderer.cc | 27+++++++++++++++++++++++++++
renderer.h | 1+
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/renderer.cc b/renderer.cc @@ -422,6 +422,18 @@ void renderer_delete_mesh( const Mesh & mesh ) { glDeleteVertexArrays( 1, &vao ); } +static GLenum depthfunc_to_glenum( DepthFunc depth_func ) { + switch( depth_func ) { + case DEPTHFUNC_LESS: return GL_LESS; + case DEPTHFUNC_EQUAL: return GL_EQUAL; + case DEPTHFUNC_ALWAYS: return GL_ALWAYS; + case DEPTHFUNC_DISABLED: return GL_ALWAYS; + } + + FATAL( "unsupported DepthFunc: %d", depth_func ); + return 0; +} + static GLenum primitivetype_to_glenum( PrimitiveType primitive_type ) { switch( primitive_type ) { case PRIMITIVETYPE_TRIANGLES: return GL_TRIANGLES; @@ -439,21 +451,27 @@ void renderer_draw_mesh( const Mesh & mesh, RenderState state ) { glUseProgram( state.shader ); glBindVertexArray( mesh.vao ); + // uniforms for( size_t i = 0; i < RENDERER_MAX_UBS; i++ ) { glBindBufferBase( GL_UNIFORM_BUFFER, checked_cast< GLuint >( i ), state.ubs[ i ] ); } + // textures for( size_t i = 0; i < RENDERER_MAX_TEXTURES; i++ ) { glActiveTexture( GL_TEXTURE0 + i ); glBindTexture( GL_TEXTURE_2D, checked_cast< GLuint >( state.textures[ i ] ) ); } + // texture buffers for( size_t i = 0; i < RENDERER_MAX_TEXTURE_BUFFERS; i++ ) { glActiveTexture( GL_TEXTURE0 + i + RENDERER_MAX_TEXTURES ); glBindTexture( GL_TEXTURE_BUFFER, checked_cast< GLuint >( state.tbs[ i ].texture ) ); } + // depth writing glDepthMask( state.disable_depth_writes ? GL_FALSE : GL_TRUE ); + + // backface culling if( state.cull_face == CULLFACE_DISABLED ) { glDisable( GL_CULL_FACE ); } @@ -463,6 +481,15 @@ void renderer_draw_mesh( const Mesh & mesh, RenderState state ) { glCullFace( state.cull_face == CULLFACE_FRONT ? GL_BACK : GL_FRONT ); } + // depth testing + if( state.depth_func == DEPTHFUNC_DISABLED ) { + glDisable( GL_DEPTH_TEST ); + } + else { + glEnable( GL_DEPTH_TEST ); + glDepthFunc( depthfunc_to_glenum( state.depth_func ) ); + } + // TODO: missing a bunch of stuff here GLenum primitive = primitivetype_to_glenum( mesh.primitive_type ); diff --git a/renderer.h b/renderer.h @@ -42,6 +42,7 @@ enum DepthFunc { DEPTHFUNC_LESS, DEPTHFUNC_EQUAL, DEPTHFUNC_ALWAYS, + DEPTHFUNC_DISABLED, // also disables writing }; enum BufferUsage {