medfall

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

commit 3392bcfb15f028bdbcf0498fcb0444da42056bb8
parent e833e9edacb4dcab5bc1a9de1b506a574b3f9c3b
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat Nov 26 22:44:09 +0200

Add depth writing/cull face/triangle strips to renderer

Diffstat:
gl.cc | 4----
renderer.cc | 13++++++++++++-
renderer.h | 8++++++++
3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/gl.cc b/gl.cc @@ -121,10 +121,6 @@ GLFWwindow * gl_init() { glEnable( GL_FRAMEBUFFER_SRGB ); - glEnable( GL_CULL_FACE ); - glCullFace( GL_FRONT ); // TODO: change this to back like everyone else - glFrontFace( GL_CCW ); // not necessary but I always forget the default - return window; } diff --git a/renderer.cc b/renderer.cc @@ -391,6 +391,7 @@ void renderer_delete_mesh( const Mesh & mesh ) { static GLenum primitivetype_to_glenum( PrimitiveType primitive_type ) { switch( primitive_type ) { case PRIMITIVETYPE_TRIANGLES: return GL_TRIANGLES; + case PRIMITIVETYPE_TRIANGLE_STRIP: return GL_TRIANGLE_STRIP; case PRIMITIVETYPE_POINTS: return GL_POINTS; case PRIMITIVETYPE_LINES: return GL_LINES; } @@ -418,7 +419,17 @@ void renderer_draw_mesh( const Mesh & mesh, RenderState state ) { glBindTexture( GL_TEXTURE_BUFFER, checked_cast< GLuint >( state.tbs[ i ].texture ) ); } - // TODO: set depth func, etc + glDepthMask( state.disable_depth_writes ? GL_FALSE : GL_TRUE ); + if( state.cull_face == CULLFACE_DISABLED ) { + glDisable( GL_CULL_FACE ); + } + else { + glEnable( GL_CULL_FACE ); + // TODO: current renderer is fucked and this should be the other way around + glCullFace( state.cull_face == CULLFACE_FRONT ? GL_BACK : GL_FRONT ); + } + + // TODO: missing a bunch of stuff here GLenum primitive = primitivetype_to_glenum( mesh.primitive_type ); if( mesh.indexed ) { diff --git a/renderer.h b/renderer.h @@ -32,6 +32,12 @@ enum DrawCallType { DRAWCALL_FINISH_FRAME, }; +enum CullFace { + CULLFACE_BACK, + CULLFACE_FRONT, + CULLFACE_DISABLED, +}; + enum DepthFunc { DEPTHFUNC_LESS, DEPTHFUNC_EQUAL, @@ -59,12 +65,14 @@ struct RenderState { UB ubs[ RENDERER_MAX_UBS ]; Shader shader; DepthFunc depth_func; + CullFace cull_face; bool disable_depth_writes; bool disable_colour_writes; }; enum PrimitiveType { PRIMITIVETYPE_TRIANGLES, + PRIMITIVETYPE_TRIANGLE_STRIP, PRIMITIVETYPE_POINTS, PRIMITIVETYPE_LINES, };