medfall

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

commit d8cf101bd7e45449b8e92010939b771244a82a64
parent 9fef45b91adcb20df6cd1735e98597bbe6bbeff3
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue Sep  8 19:39:32 +0200

Merge shitty_glsl.h into platform_opengl.h

Diffstat:
bsp.cc | 1-
btt.cc | 1-
hm.cc | 3---
platform_opengl.h | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
shitty_glsl.h | 76----------------------------------------------------------------------------
terrain_manager.cc | 2+-
6 files changed, 71 insertions(+), 82 deletions(-)
diff --git a/bsp.cc b/bsp.cc @@ -12,7 +12,6 @@ #include "gl.h" #include "bsp.h" #include "bsp_renderer.h" -#include "shitty_glsl.h" static ImmediateTriangle triangles[ 512000 ]; static ImmediateContext imm; diff --git a/btt.cc b/btt.cc @@ -8,7 +8,6 @@ #include "btt.h" #include "heightmap.h" #include "gl.h" -#include "shitty_glsl.h" static ImmediateTriangle triangles[ 512000 ]; static ImmediateContext imm; diff --git a/hm.cc b/hm.cc @@ -19,9 +19,6 @@ #include "stb_perlin.h" #include "stb_truetype.h" -#include "platform_opengl.h" -#include "shitty_glsl.h" - static const GLchar * const vert_src = GLSL( in vec3 position; in vec4 colour; diff --git a/platform_opengl.h b/platform_opengl.h @@ -9,6 +9,7 @@ #endif #include <stdio.h> +#include <stdlib.h> inline void glterrible() { GLenum err = glGetError(); @@ -26,4 +27,73 @@ inline void glterrible() { printf( "GL error: %s\n", error ); } +#define GLSL( shader ) "#version 150\n" #shader + +// this is taken from somewhere online +inline void show_info_log( + GLuint object, + PFNGLGETSHADERIVPROC glGet__iv, + PFNGLGETSHADERINFOLOGPROC glGet__InfoLog +) +{ + GLint log_length; + char *log; + + glGet__iv(object, GL_INFO_LOG_LENGTH, &log_length); + log = ( char * ) malloc(log_length); + glGet__InfoLog(object, log_length, nullptr, log); + fprintf(stderr, "%s", log); + free(log); +} + +// this is taken from somewhere online +inline void check_compile_status( const GLuint shader ) { + GLint ok; + glGetShaderiv( shader, GL_COMPILE_STATUS, &ok ); + + if( !ok ) { + fprintf( stderr, "shit bruh:\n" ); + show_info_log( shader, glGetShaderiv, glGetShaderInfoLog ); + glDeleteShader( shader ); + } +} + +// this is taken from somewhere online +inline void check_link_status( const GLuint prog ) { + GLint ok; + glGetProgramiv(prog, GL_LINK_STATUS, &ok); + if (!ok) { + fprintf(stderr, "Failed to link shader program:\n"); + show_info_log(prog, glGetProgramiv, glGetProgramInfoLog); + glDeleteProgram(prog); + } +} + +inline GLuint compile_shader( const char * const vert, const char * const frag, const char * const out ) { + const GLuint vs = glCreateShader( GL_VERTEX_SHADER ); + const 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 ); + + const 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; +} + #endif // _PLATFORM_OPENGL_H_ diff --git a/shitty_glsl.h b/shitty_glsl.h @@ -1,76 +0,0 @@ -#ifndef _SHITTY_H_ -#define _SHITTY_H_ - -#include <stdio.h> -#include "platform_opengl.h" - -#define GLSL( shader ) "#version 150\n" #shader - -// this is taken from somewhere online -inline void show_info_log( - GLuint object, - PFNGLGETSHADERIVPROC glGet__iv, - PFNGLGETSHADERINFOLOGPROC glGet__InfoLog -) -{ - GLint log_length; - char *log; - - glGet__iv(object, GL_INFO_LOG_LENGTH, &log_length); - log = ( char * ) malloc(log_length); - glGet__InfoLog(object, log_length, nullptr, log); - fprintf(stderr, "%s", log); - free(log); -} - -// this is taken from somewhere online -inline void check_compile_status( const GLuint shader ) { - GLint ok; - glGetShaderiv( shader, GL_COMPILE_STATUS, &ok ); - - if( !ok ) { - fprintf( stderr, "shit bruh:\n" ); - show_info_log( shader, glGetShaderiv, glGetShaderInfoLog ); - glDeleteShader( shader ); - } -} - -// this is taken from somewhere online -inline void check_link_status( const GLuint prog ) { - GLint ok; - glGetProgramiv(prog, GL_LINK_STATUS, &ok); - if (!ok) { - fprintf(stderr, "Failed to link shader program:\n"); - show_info_log(prog, glGetProgramiv, glGetProgramInfoLog); - glDeleteProgram(prog); - } -} - -inline GLuint compile_shader( const char * const vert, const char * const frag, const char * const out ) { - const GLuint vs = glCreateShader( GL_VERTEX_SHADER ); - const 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 ); - - const 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; -} - -#endif // _SHITTY_H_ diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -10,13 +10,13 @@ #include <string.h> +#include "platform_opengl.h" #include <glm/glm.hpp> #include <glm/gtc/type_ptr.hpp> #include "intrinsics.h" #include "heightmap.h" #include "terrain_manager.h" -#include "shitty_glsl.h" static const GLchar * const vert_src = GLSL( in vec3 position;