medfall

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

commit f47395491fbc1e8f7e686573592781cd22fb230d
parent aa3d3b19f81a7d1a36bdd435701acecaf5c1f456
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Nov 27 00:32:52 +0200

Get rid of glsl.cc/glsl.h

Diffstat:
Makefile | 2+-
btt.cc | 2--
glsl.cc | 77-----------------------------------------------------------------------------
glsl.h | 12------------
hm.cc | 7+++----
shadow_map.cc | 10+++++-----
6 files changed, 9 insertions(+), 101 deletions(-)
diff --git a/Makefile b/Makefile @@ -29,7 +29,7 @@ xxhash.o: CXXFLAGS += -O3 visitors/linear_algebra.h: linear_algebra.h # Common dependencies -COMMON_OBJS := log.o memory_arena.o work_queue.o immediate.o benchmark.o stb_truetype.o renderer.o glsl.o strlcpy.o +COMMON_OBJS := log.o memory_arena.o work_queue.o immediate.o benchmark.o stb_truetype.o renderer.o strlcpy.o # Compiler flags WARNINGS := -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wconversion -Wshadow -Wcast-align -Wstrict-overflow diff --git a/btt.cc b/btt.cc @@ -1,5 +1,3 @@ -#include "glsl.h" - #include "intrinsics.h" #include "memory_arena.h" #include "btt.h" diff --git a/glsl.cc b/glsl.cc @@ -1,77 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#include "glad.h" -#include "glsl.h" - -#include "log.h" - -// TODO: this is kinda crap because it calls delete -void check_compile_status( GLuint shader ) { - GLint ok; - glGetShaderiv( shader, GL_COMPILE_STATUS, &ok ); - - if( ok == GL_FALSE ) { - GLint len; - glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &len ); - - char * buf = ( char * ) malloc( len ); - if( buf == NULL ) { - FATAL( "malloc" ); - } - glGetShaderInfoLog( shader, len, NULL, buf ); - - fprintf( stderr, "compiling the shader failed:\n%s", buf ); - free( buf ); - - glDeleteShader( shader ); - } -} - -void check_link_status( GLuint program ) { - GLint ok; - glGetProgramiv( program, GL_LINK_STATUS, &ok ); - - if( ok == GL_FALSE ) { - GLint len; - glGetProgramiv( program, GL_INFO_LOG_LENGTH, &len ); - - char * buf = ( char * ) malloc( len ); - if( buf == NULL ) { - FATAL( "malloc" ); - } - glGetProgramInfoLog( program, len, NULL, buf ); - - fprintf( stderr, "linking the shader failed:\n%s", buf ); - free( buf ); - - glDeleteProgram( program ); - } -} - -GLuint compile_shader( const char * vert, const char * frag, const char * out ) { - GLuint vs = glCreateShader( GL_VERTEX_SHADER ); - GLuint fs = glCreateShader( GL_FRAGMENT_SHADER ); - - glShaderSource( vs, 1, &vert, NULL ); - glShaderSource( fs, 1, &frag, NULL ); - - glCompileShader( vs ); - check_compile_status( vs ); - glCompileShader( fs ); - check_compile_status( fs ); - - GLuint prog = glCreateProgram(); - - glAttachShader( prog, vs ); - glAttachShader( prog, fs ); - glBindFragDataLocation( prog, 0, out ); - glLinkProgram( prog ); - - glDeleteShader( vs ); - glDeleteShader( fs ); - - check_link_status( prog ); - - return prog; -} diff --git a/glsl.h b/glsl.h @@ -1,12 +0,0 @@ -#ifndef _GLSL_H_ -#define _GLSL_H_ - -#include "glad.h" - -#define GLSL( shader ) "#version 330\n" #shader - -void check_compile_status( GLuint shader ); -void check_link_status( GLuint prog ); -GLuint compile_shader( const char * vert, const char * frag, const char * out ); - -#endif // _GLSL_H_ diff --git a/hm.cc b/hm.cc @@ -2,7 +2,6 @@ #include <math.h> #include "glad.h" -#include "glsl.h" #include "game.h" #include "intrinsics.h" @@ -123,7 +122,7 @@ extern "C" GAME_INIT( game_init ) { terrain_init( &game->tm, "terrains/gta.png.parts", &mem->persistent_arena, &game->background_tasks ); terrain_teleport( &game->tm, game->pos ); - game->test_shader = compile_shader( vert_src, frag_src, "screen_colour" ); + game->test_shader = renderer_new_shader( vert_src, frag_src ); game->test_at_position = glGetAttribLocation( game->test_shader, "position" ); game->test_at_colour = glGetAttribLocation( game->test_shader, "colour" ); @@ -190,13 +189,13 @@ extern "C" GAME_INIT( game_init ) { // // game->assets[ ASSET_FONT ] = font_asset; - game->test_tex_shader = compile_shader( textured_vert_src, textured_frag_src, "screen_colour" ); + game->test_tex_shader = renderer_new_shader( textured_vert_src, textured_frag_src ); game->test_tex_at_pos = glGetAttribLocation( game->test_tex_shader, "position" ); game->test_tex_at_colour = glGetAttribLocation( game->test_tex_shader, "colour" ); game->test_tex_at_uv = glGetAttribLocation( game->test_tex_shader, "uv" ); game->test_tex_un_tex = glGetUniformLocation( game->test_tex_shader, "tex" ); - game->font_shader = compile_shader( font_vert_src, font_frag_src, "screen_colour" ); + game->font_shader = renderer_new_shader( font_vert_src, font_frag_src ); game->font_at_position = glGetAttribLocation( game->font_shader, "position" ); game->font_at_colour = glGetAttribLocation( game->font_shader, "colour" ); game->font_at_uv = glGetAttribLocation( game->font_shader, "uv" ); diff --git a/shadow_map.cc b/shadow_map.cc @@ -1,9 +1,9 @@ #include "glad.h" -#include "glsl.h" #include "game.h" #include "intrinsics.h" #include "linear_algebra.h" +#include "renderer.h" #include "log.h" static ImmediateTriangle triangles[ 512000 ]; @@ -11,12 +11,12 @@ static ImmediateContext imm; static GLuint screen_vao, screen_vbo; -static GLuint prog; +static Shader prog; static GLint at_position; static GLint at_colour; static GLint un_vp; -static GLuint depth_prog; +static Shader depth_prog; static GLint depth_at_position; static GLint depth_un_tex; @@ -133,12 +133,12 @@ const u32 SHADOW_WIDTH = 1024; const u32 SHADOW_HEIGHT = 1024; extern "C" GAME_INIT( game_init ) { - prog = compile_shader( vert_src, frag_src, "screen_colour" ); + prog = renderer_new_shader( vert_src, frag_src ); at_position = glGetAttribLocation( prog, "position" ); at_colour = glGetAttribLocation( prog, "colour" ); un_vp = glGetUniformLocation( prog, "VP" ); - depth_prog = compile_shader( depth_vert_src, depth_frag_src, "screen_colour" ); + depth_prog = renderer_new_shader( depth_vert_src, depth_frag_src ); depth_at_position = glGetAttribLocation( depth_prog, "position" ); depth_un_tex = glGetUniformLocation( depth_prog, "tex" );