Fixed GL_CHECK macro and replaced all renderer_gl_check usage with GL_CHECK

dev
Shariq Shah 7 years ago
parent 6b105f467c
commit 90cb201359
  1. 284
      include/common/KHR/khrplatform.h
  2. 1155
      include/common/glad/glad.h
  3. 45
      src/libsymmetry/framebuffer.c
  4. 4
      src/libsymmetry/game.c
  5. 7
      src/libsymmetry/game.h
  6. 20
      src/libsymmetry/geometry.c
  7. 5
      src/libsymmetry/gl_load.c
  8. 5
      src/libsymmetry/gl_load.h
  9. 2705
      src/libsymmetry/glad.c
  10. 23
      src/libsymmetry/renderer.c
  11. 11
      src/libsymmetry/shader.c
  12. 32
      src/libsymmetry/sprite.c
  13. 39
      src/libsymmetry/texture.c

@ -1,284 +0,0 @@
#ifndef __khrplatform_h_
#define __khrplatform_h_
/*
** Copyright (c) 2008-2009 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
/* Khronos platform-specific types and definitions.
*
* $Revision: 32517 $ on $Date: 2016-03-11 02:41:19 -0800 (Fri, 11 Mar 2016) $
*
* Adopters may modify this file to suit their platform. Adopters are
* encouraged to submit platform specific modifications to the Khronos
* group so that they can be included in future versions of this file.
* Please submit changes by sending them to the public Khronos Bugzilla
* (http://khronos.org/bugzilla) by filing a bug against product
* "Khronos (general)" component "Registry".
*
* A predefined template which fills in some of the bug fields can be
* reached using http://tinyurl.com/khrplatform-h-bugreport, but you
* must create a Bugzilla login first.
*
*
* See the Implementer's Guidelines for information about where this file
* should be located on your system and for more details of its use:
* http://www.khronos.org/registry/implementers_guide.pdf
*
* This file should be included as
* #include <KHR/khrplatform.h>
* by Khronos client API header files that use its types and defines.
*
* The types in khrplatform.h should only be used to define API-specific types.
*
* Types defined in khrplatform.h:
* khronos_int8_t signed 8 bit
* khronos_uint8_t unsigned 8 bit
* khronos_int16_t signed 16 bit
* khronos_uint16_t unsigned 16 bit
* khronos_int32_t signed 32 bit
* khronos_uint32_t unsigned 32 bit
* khronos_int64_t signed 64 bit
* khronos_uint64_t unsigned 64 bit
* khronos_intptr_t signed same number of bits as a pointer
* khronos_uintptr_t unsigned same number of bits as a pointer
* khronos_ssize_t signed size
* khronos_usize_t unsigned size
* khronos_float_t signed 32 bit floating point
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
* nanoseconds
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
* khronos_boolean_enum_t enumerated boolean type. This should
* only be used as a base type when a client API's boolean type is
* an enum. Client APIs which use an integer or other type for
* booleans cannot use this as the base type for their boolean.
*
* Tokens defined in khrplatform.h:
*
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
*
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
*
* Calling convention macros defined in this file:
* KHRONOS_APICALL
* KHRONOS_APIENTRY
* KHRONOS_APIATTRIBUTES
*
* These may be used in function prototypes as:
*
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
* int arg1,
* int arg2) KHRONOS_APIATTRIBUTES;
*/
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APICALL
*-------------------------------------------------------------------------
* This precedes the return type of the function in the function prototype.
*/
#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
# define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__)
# define KHRONOS_APICALL IMPORT_C
#elif defined(__ANDROID__)
# define KHRONOS_APICALL __attribute__((visibility("default")))
#else
# define KHRONOS_APICALL
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIENTRY
*-------------------------------------------------------------------------
* This follows the return type of the function and precedes the function
* name in the function prototype.
*/
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
/* Win32 but not WinCE */
# define KHRONOS_APIENTRY __stdcall
#else
# define KHRONOS_APIENTRY
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIATTRIBUTES
*-------------------------------------------------------------------------
* This follows the closing parenthesis of the function prototype arguments.
*/
#if defined (__ARMCC_2__)
#define KHRONOS_APIATTRIBUTES __softfp
#else
#define KHRONOS_APIATTRIBUTES
#endif
/*-------------------------------------------------------------------------
* basic type definitions
*-----------------------------------------------------------------------*/
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
/*
* Using <stdint.h>
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(__VMS ) || defined(__sgi)
/*
* Using <inttypes.h>
*/
#include <inttypes.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
/*
* Win32
*/
typedef __int32 khronos_int32_t;
typedef unsigned __int32 khronos_uint32_t;
typedef __int64 khronos_int64_t;
typedef unsigned __int64 khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(__sun__) || defined(__digital__)
/*
* Sun or Digital
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#if defined(__arch64__) || defined(_LP64)
typedef long int khronos_int64_t;
typedef unsigned long int khronos_uint64_t;
#else
typedef long long int khronos_int64_t;
typedef unsigned long long int khronos_uint64_t;
#endif /* __arch64__ */
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif 0
/*
* Hypothetical platform with no float or int64 support
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#define KHRONOS_SUPPORT_INT64 0
#define KHRONOS_SUPPORT_FLOAT 0
#else
/*
* Generic fallback
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#endif
/*
* Types that are (so far) the same on all platforms
*/
typedef signed char khronos_int8_t;
typedef unsigned char khronos_uint8_t;
typedef signed short int khronos_int16_t;
typedef unsigned short int khronos_uint16_t;
/*
* Types that differ between LLP64 and LP64 architectures - in LLP64,
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
* to be the only LLP64 architecture in current use.
*/
#ifdef _WIN64
typedef signed long long int khronos_intptr_t;
typedef unsigned long long int khronos_uintptr_t;
typedef signed long long int khronos_ssize_t;
typedef unsigned long long int khronos_usize_t;
#else
typedef signed long int khronos_intptr_t;
typedef unsigned long int khronos_uintptr_t;
typedef signed long int khronos_ssize_t;
typedef unsigned long int khronos_usize_t;
#endif
#if KHRONOS_SUPPORT_FLOAT
/*
* Float type
*/
typedef float khronos_float_t;
#endif
#if KHRONOS_SUPPORT_INT64
/* Time types
*
* These types can be used to represent a time interval in nanoseconds or
* an absolute Unadjusted System Time. Unadjusted System Time is the number
* of nanoseconds since some arbitrary system event (e.g. since the last
* time the system booted). The Unadjusted System Time is an unsigned
* 64 bit value that wraps back to 0 every 584 years. Time intervals
* may be either signed or unsigned.
*/
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
typedef khronos_int64_t khronos_stime_nanoseconds_t;
#endif
/*
* Dummy value used to pad enum types to 32 bits.
*/
#ifndef KHRONOS_MAX_ENUM
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
#endif
/*
* Enumerated boolean type
*
* Values other than zero should be considered to be true. Therefore
* comparisons should not be made against KHRONOS_TRUE.
*/
typedef enum {
KHRONOS_FALSE = 0,
KHRONOS_TRUE = 1,
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
} khronos_boolean_enum_t;
#endif /* __khrplatform_h_ */

File diff suppressed because it is too large Load Diff

@ -51,16 +51,14 @@ int framebuffer_create(int width, int height, bool has_depth, bool has_color, bo
{ {
glGenRenderbuffers(1, &depth_renderbuffer); glGenRenderbuffers(1, &depth_renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depth_renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, depth_renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER,
GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT,
width, width,
height); height));
renderer_check_glerror("framebuffer:create:depth_renderbuffer"); GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER,
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, GL_RENDERBUFFER,
depth_renderbuffer); depth_renderbuffer));
renderer_check_glerror("framebuffer:create:depth_renderbuffer");
glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindRenderbuffer(GL_RENDERBUFFER, 0);
} }
@ -68,26 +66,22 @@ int framebuffer_create(int width, int height, bool has_depth, bool has_color, bo
{ {
glGenRenderbuffers(1, &color_renderbuffer); glGenRenderbuffers(1, &color_renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, color_renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, color_renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER,
GL_RGBA8, GL_RGBA8,
width, width,
height); height));
renderer_check_glerror("framebuffer:create:color_renderbuffer"); GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER,
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, GL_RENDERBUFFER,
color_renderbuffer); color_renderbuffer));
renderer_check_glerror("framebuffer:create:color_renderbuffer");
glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindRenderbuffer(GL_RENDERBUFFER, 0);
} }
glDrawBuffer(has_color ? GL_COLOR_ATTACHMENT0 : GL_NONE); GL_CHECK(glDrawBuffer(has_color ? GL_COLOR_ATTACHMENT0 : GL_NONE));
renderer_check_glerror("framebuffer:create");
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE) if(status != GL_FRAMEBUFFER_COMPLETE)
{ {
log_error("framebuffer:create", "Framebuffer not created!"); log_error("framebuffer:create", "Framebuffer not created!");
renderer_check_glerror("framebuffer:create");
} }
else else
{ {
@ -188,15 +182,13 @@ void framebuffer_texture_set(int index, int texture, enum Framebuffer_Attachment
if(texture == -1) return; if(texture == -1) return;
GLint current_fbo = 0; GLint current_fbo = 0;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo); GL_CHECK(glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo));
renderer_check_glerror("framebuffer:set_texture:glGet");
framebuffer_bind(index); framebuffer_bind(index);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
gl_attachment, gl_attachment,
GL_TEXTURE_2D, GL_TEXTURE_2D,
texture_get_texture_handle(texture), texture_get_texture_handle(texture),
0); 0));
renderer_check_glerror("framebuffer:set_texture:glFramebuffertexture2d");
fbo->texture_attachments[attachment] = texture; fbo->texture_attachments[attachment] = texture;
if(attachment == FA_COLOR_ATTACHMENT0) glDrawBuffer(GL_COLOR_ATTACHMENT0); if(attachment == FA_COLOR_ATTACHMENT0) glDrawBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
@ -223,19 +215,17 @@ void framebuffer_resize(int index, int width, int height)
width -= (width % 2); width -= (width % 2);
height -= (height % 2); height -= (height % 2);
GLint current_fbo = 0; GLint current_fbo = 0;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo); GL_CHECK(glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo));
renderer_check_glerror("framebuffer:resize:glGet");
struct FBO* fbo = &fbo_list[index]; struct FBO* fbo = &fbo_list[index];
if(!fbo->resizeable) return; if(!fbo->resizeable) return;
framebuffer_bind(index); framebuffer_bind(index);
if(fbo->depth_renderbuffer != 0) if(fbo->depth_renderbuffer != 0)
{ {
glBindRenderbuffer(GL_RENDERBUFFER, fbo->depth_renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, fbo->depth_renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER,
GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT,
width, width,
height); height));
renderer_check_glerror("framebuffer:resize:depth_renderbuffer");
glFramebufferRenderbuffer(GL_FRAMEBUFFER, glFramebufferRenderbuffer(GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, GL_RENDERBUFFER,
@ -246,11 +236,10 @@ void framebuffer_resize(int index, int width, int height)
if(fbo->color_renderbuffer != 0) if(fbo->color_renderbuffer != 0)
{ {
glBindRenderbuffer(GL_RENDERBUFFER, fbo->color_renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, fbo->color_renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER,
GL_RGBA8, GL_RGBA8,
width, width,
height); height));
renderer_check_glerror("framebuffer:resize:color_renderbuffer");
glFramebufferRenderbuffer(GL_FRAMEBUFFER, glFramebufferRenderbuffer(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, GL_RENDERBUFFER,

@ -103,6 +103,8 @@ bool game_init(struct Window* window, struct Platform_Api* platform_api)
editor_init(); editor_init();
renderer_init(game_state->renderer); renderer_init(game_state->renderer);
scene_init(game_state->scene); scene_init(game_state->scene);
game_state->game_mode = GM_GAME;
} }
/* Debug scene setup */ /* Debug scene setup */
@ -496,7 +498,7 @@ void game_update(float dt, bool* window_should_close)
return; return;
} }
game_debug(dt); //game_debug(dt);
//debug_gui(dt); //debug_gui(dt);
scene_update(game_state->scene, dt); scene_update(game_state->scene, dt);
editor_update(dt); editor_update(dt);

@ -16,9 +16,16 @@ struct Scene;
struct Entity; struct Entity;
struct Player; struct Player;
enum Game_Mode
{
GM_GAME = 0,
GM_EDITOR
};
struct Game_State struct Game_State
{ {
bool is_initialized; bool is_initialized;
int game_mode;
struct Window* window; struct Window* window;
struct Renderer* renderer; struct Renderer* renderer;
struct Scene* scene; struct Scene* scene;

@ -289,11 +289,10 @@ static void create_vao(struct Geometry* geometry)
glGenBuffers(1, &geometry->vertex_vbo); glGenBuffers(1, &geometry->vertex_vbo);
glBindBuffer(GL_ARRAY_BUFFER, geometry->vertex_vbo); glBindBuffer(GL_ARRAY_BUFFER, geometry->vertex_vbo);
glBufferData(GL_ARRAY_BUFFER, GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
array_len(geometry->vertices) * sizeof(vec3), array_len(geometry->vertices) * sizeof(vec3),
geometry->vertices, geometry->vertices,
GL_STATIC_DRAW); GL_STATIC_DRAW));
renderer_check_glerror("geometry:create_vbo:vertex");
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
@ -301,11 +300,10 @@ static void create_vao(struct Geometry* geometry)
{ {
glGenBuffers(1, &geometry->normal_vbo); glGenBuffers(1, &geometry->normal_vbo);
glBindBuffer(GL_ARRAY_BUFFER, geometry->normal_vbo); glBindBuffer(GL_ARRAY_BUFFER, geometry->normal_vbo);
glBufferData(GL_ARRAY_BUFFER, GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
array_len(geometry->normals) * sizeof(vec3), array_len(geometry->normals) * sizeof(vec3),
geometry->normals, geometry->normals,
GL_STATIC_DRAW); GL_STATIC_DRAW));
renderer_check_glerror("geometry:create_vbo:normal");
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_TRUE, 0, 0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_TRUE, 0, 0);
} }
@ -314,11 +312,10 @@ static void create_vao(struct Geometry* geometry)
{ {
glGenBuffers(1, &geometry->uv_vbo); glGenBuffers(1, &geometry->uv_vbo);
glBindBuffer(GL_ARRAY_BUFFER, geometry->uv_vbo); glBindBuffer(GL_ARRAY_BUFFER, geometry->uv_vbo);
glBufferData(GL_ARRAY_BUFFER, GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
array_len(geometry->uvs) * sizeof(vec2), array_len(geometry->uvs) * sizeof(vec2),
geometry->uvs, geometry->uvs,
GL_STATIC_DRAW); GL_STATIC_DRAW));
renderer_check_glerror("geometry:create_vbo:uv");
glEnableVertexAttribArray(2); glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
} }
@ -327,11 +324,10 @@ static void create_vao(struct Geometry* geometry)
{ {
glGenBuffers(1, &geometry->color_vbo); glGenBuffers(1, &geometry->color_vbo);
glBindBuffer(GL_ARRAY_BUFFER, geometry->color_vbo); glBindBuffer(GL_ARRAY_BUFFER, geometry->color_vbo);
glBufferData(GL_ARRAY_BUFFER, GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
array_len(geometry->vertex_colors) * sizeof(vec3), array_len(geometry->vertex_colors) * sizeof(vec3),
geometry->vertex_colors, geometry->vertex_colors,
GL_STATIC_DRAW); GL_STATIC_DRAW));
renderer_check_glerror("geometry:create_vbo:color");
glEnableVertexAttribArray(3); glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, 0);
} }

@ -30,7 +30,8 @@ bool gl_load_extentions(void)
{ {
bool success = true; bool success = true;
#ifdef USE_GLAD #ifdef USE_GLAD
if(!gladLoadGLLoader(platform->load_function_gl)) success = false; if(!gladLoadGLLoader(platform->load_function_gl))
success = false;
#else #else
#define GLE(ret, name, ...) \ #define GLE(ret, name, ...) \
@ -65,6 +66,4 @@ void gl_check_error(const char * expression, unsigned int line, const char * fil
log_error("GL", "(%s:%d:%s) : %s", file, line, expression, error_string); log_error("GL", "(%s:%d:%s) : %s", file, line, expression, error_string);
else else
error = 0; error = 0;
return error;
} }

@ -62,11 +62,10 @@ SYMMETRY_GL_LIST
#endif #endif
#ifdef GL_DEBUG #ifdef GL_DEBUG_CONTEXT
#define GL_CHECK(expression) do { gl_check(#expression, __LINE__, __FILE__)} while(false) #define GL_CHECK(expression) do { expression; gl_check_error(#expression, __LINE__, __FILE__);} while(false)
#else #else
#define GL_CHECK(expression) (expression) #define GL_CHECK(expression) (expression)
#endif #endif
int gl_load_library(void); int gl_load_library(void);

File diff suppressed because it is too large Load Diff

@ -467,29 +467,6 @@ void renderer_clearcolor_set(float red, float green, float blue, float alpha)
glClearColor(red, green, blue, alpha); glClearColor(red, green, blue, alpha);
} }
int renderer_check_glerror(const char* context)
{
int error = 1;
GLenum error_code = glGetError();
const char* error_string = "No Error";
switch(error_code)
{
case GL_INVALID_OPERATION: error_string = "Invalid Operation"; break;
case GL_NO_ERROR: error_string = "No Error"; break;
case GL_INVALID_ENUM: error_string = "Invalid ENUM"; break;
case GL_INVALID_VALUE: error_string = "Invalid Value"; break;
case GL_INVALID_FRAMEBUFFER_OPERATION: error_string = "Invalid FrameBuffer Operation"; break;
case GL_OUT_OF_MEMORY: error_string = "Out of Memory"; break;
}
if(error_code != GL_NO_ERROR)
log_error(context, error_string);
else
error = 0;
return error;
}
struct Material * renderer_material_get(int material_type) struct Material * renderer_material_get(int material_type)
{ {
return NULL; return NULL;

@ -152,12 +152,11 @@ int shader_create(const char* vert_shader_name, const char* frag_shader_name)
glAttachShader(program, frag_shader); glAttachShader(program, frag_shader);
// Bind attribute locations // Bind attribute locations
glBindAttribLocation(program, ATTRIB_LOC_POSITION, "vPosition"); GL_CHECK(glBindAttribLocation(program, ATTRIB_LOC_POSITION, "vPosition"));
glBindAttribLocation(program, ATTRIB_LOC_NORMAL, "vNormal"); GL_CHECK(glBindAttribLocation(program, ATTRIB_LOC_NORMAL, "vNormal"));
glBindAttribLocation(program, ATRRIB_LOC_UV, "vUV"); GL_CHECK(glBindAttribLocation(program, ATRRIB_LOC_UV, "vUV"));
glBindAttribLocation(program, ATTRIB_LOC_COLOR, "vColor"); GL_CHECK(glBindAttribLocation(program, ATTRIB_LOC_COLOR, "vColor"));
renderer_check_glerror("shader:create"); GL_CHECK(glLinkProgram(program));
glLinkProgram(program);
GLint is_linked = 0; GLint is_linked = 0;
glGetProgramiv(program, GL_LINK_STATUS, &is_linked); glGetProgramiv(program, GL_LINK_STATUS, &is_linked);

@ -19,29 +19,22 @@ void sprite_batch_create(struct Sprite_Batch* batch, const char* texture_name, c
glGenBuffers(1, &batch->vbo); glGenBuffers(1, &batch->vbo);
glBindBuffer(GL_ARRAY_BUFFER, batch->vbo); glBindBuffer(GL_ARRAY_BUFFER, batch->vbo);
glBufferData(GL_ARRAY_BUFFER, GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
sizeof(struct Sprite_Vertex) * MAX_SPRITE_VERTICES * SPRITE_BATCH_SIZE, sizeof(struct Sprite_Vertex) * MAX_SPRITE_VERTICES * SPRITE_BATCH_SIZE,
NULL, NULL,
GL_STREAM_DRAW); GL_STREAM_DRAW));
renderer_check_glerror("sprite_batch_create:glBufferData");
// Position // Position
glVertexAttribPointer(ATTRIB_LOC_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(struct Sprite_Vertex), 0); GL_CHECK(glVertexAttribPointer(ATTRIB_LOC_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(struct Sprite_Vertex), 0));
renderer_check_glerror("sprite_batch_create:glVertexAttribPointer"); GL_CHECK(glEnableVertexAttribArray(ATTRIB_LOC_POSITION));
glEnableVertexAttribArray(ATTRIB_LOC_POSITION);
renderer_check_glerror("sprite_batch_create:glEnableVertexAttribPointer");
// Uvs // Uvs
glVertexAttribPointer(ATRRIB_LOC_UV, 2, GL_FLOAT, GL_FALSE, sizeof(struct Sprite_Vertex), sizeof(vec2)); GL_CHECK(glVertexAttribPointer(ATRRIB_LOC_UV, 2, GL_FLOAT, GL_FALSE, sizeof(struct Sprite_Vertex), sizeof(vec2)));
renderer_check_glerror("sprite_batch_create:glVertexAttribPointer"); GL_CHECK(glEnableVertexAttribArray(ATRRIB_LOC_UV));
glEnableVertexAttribArray(ATRRIB_LOC_UV);
renderer_check_glerror("sprite_batch_create:glEnableVertexAttribPointer");
// Color // Color
glVertexAttribPointer(ATTRIB_LOC_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(struct Sprite_Vertex), sizeof(vec2) + sizeof(vec2)); GL_CHECK(glVertexAttribPointer(ATTRIB_LOC_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(struct Sprite_Vertex), sizeof(vec2) + sizeof(vec2)));
renderer_check_glerror("sprite_batch_create:glVertexAttribPointer"); GL_CHECK(glEnableVertexAttribArray(ATTRIB_LOC_COLOR));
glEnableVertexAttribArray(ATTRIB_LOC_COLOR);
renderer_check_glerror("sprite_batch_create:glEnableVertexAttribPointer");
//glBindBuffer(GL_ARRAY_BUFFER, 0); //glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0); glBindVertexArray(0);
@ -62,6 +55,7 @@ void sprite_batch_create(struct Sprite_Batch* batch, const char* texture_name, c
} }
batch->shader = shader; batch->shader = shader;
batch->draw_mode = draw_mode; batch->draw_mode = draw_mode;
batch->current_sprite_count = 0;
} }
void sprite_batch_remove(struct Sprite_Batch * batch) void sprite_batch_remove(struct Sprite_Batch * batch)
@ -119,11 +113,10 @@ void sprite_batch_end(struct Sprite_Batch* batch)
{ {
assert(batch); assert(batch);
glBindBuffer(GL_ARRAY_BUFFER, batch->vbo); glBindBuffer(GL_ARRAY_BUFFER, batch->vbo);
glBufferSubData(GL_ARRAY_BUFFER, GL_CHECK(glBufferSubData(GL_ARRAY_BUFFER,
0, 0,
sizeof(struct Sprite_Vertex) * MAX_SPRITE_VERTICES * batch->current_sprite_count, sizeof(struct Sprite_Vertex) * MAX_SPRITE_VERTICES * batch->current_sprite_count,
&batch->sprites[0]); &batch->sprites[0]));
renderer_check_glerror("sprite_batch_end:glBufferSubData");
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
} }
@ -134,8 +127,7 @@ void sprite_batch_render(struct Sprite_Batch* batch)
texture_bind(batch->texture); texture_bind(batch->texture);
glBindVertexArray(batch->vao); glBindVertexArray(batch->vao);
glDrawArrays(batch->draw_mode, 0, MAX_SPRITE_VERTICES * batch->current_sprite_count); GL_CHECK(glDrawArrays(batch->draw_mode, 0, MAX_SPRITE_VERTICES * batch->current_sprite_count));
renderer_check_glerror("sprite_batch_render:glDrawArrays");
glBindVertexArray(0); glBindVertexArray(0);
texture_unbind(batch->texture); texture_unbind(batch->texture);

@ -48,7 +48,7 @@ static int* empty_indices;
static int load_img(FILE* file, GLubyte** image_data, int* width, int* height, int* fmt, int* internal_format); static int load_img(FILE* file, GLubyte** image_data, int* width, int* height, int* fmt, int* internal_format);
static void debug_write_tga(struct Tga_Header* header, GLubyte* image_data); static void debug_write_tga(struct Tga_Header* header, GLubyte* image_data);
static void copy_tga_pixel(GLubyte* source, GLubyte* dest, size_t bytes_per_pixel); static void copy_tga_pixel(GLubyte* source, GLubyte* dest, size_t bytes_per_pixel);
static int create_gl_texture(uint* out_handle, int width, int height, int format, int internal_format, int type, const void* data); static void create_gl_texture(uint* out_handle, int width, int height, int format, int internal_format, int type, const void* data);
void texture_init(void) void texture_init(void)
{ {
@ -311,12 +311,9 @@ void texture_set_param(int index, int parameter, int value)
return; return;
GLint curr_texture = 0; GLint curr_texture = 0;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_texture); GL_CHECK(glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_texture));
renderer_check_glerror("texture:set_param:glGetIntegerv"); GL_CHECK(glBindTexture(GL_TEXTURE_2D, texture->handle));
glBindTexture(GL_TEXTURE_2D, texture->handle); GL_CHECK(glTexParameteri(GL_TEXTURE_2D, parameter, value));
renderer_check_glerror("texture:set_param:glBindTexture");
glTexParameteri(GL_TEXTURE_2D, parameter, value);
renderer_check_glerror("texture:set_param:glTexParameteri");
if(curr_texture != 0) if(curr_texture != 0)
glBindTexture(GL_TEXTURE_2D, curr_texture); glBindTexture(GL_TEXTURE_2D, curr_texture);
} }
@ -385,9 +382,7 @@ int texture_create(const char* name,
assert(texture_unit > -1 && texture_unit <= TU_SHADOWMAP4); assert(texture_unit > -1 && texture_unit <= TU_SHADOWMAP4);
int index = -1; int index = -1;
uint handle = 0; uint handle = 0;
int success = create_gl_texture(&handle, width, height, format, internal_format, type, data); create_gl_texture(&handle, width, height, format, internal_format, type, data);
if(success)
{
struct Texture* new_tex = NULL; struct Texture* new_tex = NULL;
if(array_len(empty_indices) > 0) if(array_len(empty_indices) > 0)
{ {
@ -407,11 +402,10 @@ int texture_create(const char* name,
new_tex->format = format; new_tex->format = format;
new_tex->internal_format = internal_format; new_tex->internal_format = internal_format;
new_tex->type = type; new_tex->type = type;
}
return index; return index;
} }
int create_gl_texture(uint* out_handle, void create_gl_texture(uint* out_handle,
int width, int width,
int height, int height,
int format, int format,
@ -419,21 +413,10 @@ int create_gl_texture(uint* out_handle,
int type, int type,
const void* data) const void* data)
{ {
int success = 1; GL_CHECK(glGenTextures(1, out_handle));
glGenTextures(1, out_handle);
if(renderer_check_glerror("texture:create_gl_texture:glGentexture"))
{
success = 0;
}
else
{
glBindTexture(GL_TEXTURE_2D, *out_handle); glBindTexture(GL_TEXTURE_2D, *out_handle);
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, type, data); GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, type, data));
if(renderer_check_glerror("texture:create_gl_texture:glTexImage2d"))
success = 0;
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
}
return success;
} }
void texture_resize(int index, int width, int height, const void* data) void texture_resize(int index, int width, int height, const void* data)
@ -444,10 +427,8 @@ void texture_resize(int index, int width, int height, const void* data)
struct Texture* texture = &texture_list[index]; struct Texture* texture = &texture_list[index];
GLint curr_texture = 0; GLint curr_texture = 0;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_texture); GL_CHECK(glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_texture));
renderer_check_glerror("texture:set_param:glGetIntegerv"); GL_CHECK(glBindTexture(GL_TEXTURE_2D, texture->handle));
glBindTexture(GL_TEXTURE_2D, texture->handle);
renderer_check_glerror("texture:set_param:glBindTexture");
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
texture->internal_format, texture->internal_format,

Loading…
Cancel
Save