Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/desktop/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "gl_legacy_renderer.h"
#endif
#include "gl_common.h"
#include "gl_wrappers.h"
#endif
#ifdef ENABLE_SW_RENDERER
#include "sw_renderer.h"
Expand Down
11 changes: 7 additions & 4 deletions src/gl/gl_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "utils.h"
#include "image_decoder.h"
#include "gl_common.h"
#include "gl_wrappers.h"

// ===[ Constants ]===
#define MAX_QUADS 4096
Expand Down Expand Up @@ -52,22 +53,20 @@ static const char* baseFragmentShader =

static bool hasFBO() {
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
return (glGenFramebuffers || glGenFramebuffersEXT);
return glGenFramebuffers;
#else
return true;
#endif
}

static bool hasVAO() {
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
return (glGenVertexArrays || glGenVertexArraysOES);
return glGenVertexArrays;
#else
return true;
#endif
}

#include "gl_wrappers.h"

static inline uint8_t floatToUnormByte(float v) {
if (v <= 0.0f) return 0;
if (v >= 1.0f) return 255;
Expand Down Expand Up @@ -280,6 +279,10 @@ static void glInit(Renderer* renderer, DataWin* dataWin) {
abort();
}

#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
gl_init_wrappers();
#endif

char vertSrc[1024];
char fragSrc[1024];
const char* vertHeader = "";
Expand Down
2 changes: 0 additions & 2 deletions src/gl_common/gl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "utils.h"
#include "renderer.h" // for bm_* constants

#include "gl_wrappers.h"

// ===[ Letterbox blit ]===

void GLCommon_computeLetterbox(int32_t gameW, int32_t gameH, int32_t windowW, int32_t windowH, int32_t* outStartX, int32_t* outStartY, int32_t* outEndX, int32_t* outEndY) {
Expand Down
90 changes: 23 additions & 67 deletions src/gl_common/gl_wrappers.h
Original file line number Diff line number Diff line change
@@ -1,83 +1,39 @@
#if !defined(_BS_GL_WRAPPERS_H_) && !defined(__EMSCRIPTEN__) && !defined(PLATFORM_PS3) && !defined(__ANDROID__)
#define _BS_GL_WRAPPERS_H_

static inline void rt_glBindVertexArray(GLuint vao) {
if (glBindVertexArray) glBindVertexArray(vao);
else glBindVertexArrayOES(vao);
}
#undef glBindVertexArray
#define glBindVertexArray rt_glBindVertexArray
static inline void gl_init_wrappers(void) {
if (!glBindVertexArray)
glBindVertexArray = glBindVertexArrayOES;

static inline void rt_glGenVertexArrays(GLsizei n, GLuint* arrays) {
if (glGenVertexArrays) glGenVertexArrays(n, arrays);
else glGenVertexArraysOES(n, arrays);
}
#undef glGenVertexArrays
#define glGenVertexArrays rt_glGenVertexArrays
if (!glGenVertexArrays)
glGenVertexArrays = glGenVertexArraysOES;

static inline void rt_glDeleteVertexArrays(GLsizei n, const GLuint* arrays) {
if (glDeleteVertexArrays) glDeleteVertexArrays(n, arrays);
else glDeleteVertexArraysOES(n, arrays);
}
#undef glDeleteVertexArrays
#define glDeleteVertexArrays rt_glDeleteVertexArrays
if (!glDeleteVertexArrays)
glDeleteVertexArrays = glDeleteVertexArraysOES;

static inline void rt_glGenFramebuffers(GLsizei n, GLuint* ids) {
if (glGenFramebuffers) glGenFramebuffers(n, ids);
else glGenFramebuffersEXT(n, ids);
}
#undef glGenFramebuffers
#define glGenFramebuffers rt_glGenFramebuffers
if (!glGenFramebuffers)
glGenFramebuffers = glGenFramebuffersEXT;

static inline void rt_glBindFramebuffer(GLenum target, GLuint fb) {
if (glBindFramebuffer) glBindFramebuffer(target, fb);
else glBindFramebufferEXT(target, fb);
}
#undef glBindFramebuffer
#define glBindFramebuffer rt_glBindFramebuffer
if (!glBindFramebuffer)
glBindFramebuffer = glBindFramebufferEXT;

static inline void rt_glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) {
if (glFramebufferTexture2D) glFramebufferTexture2D(target, attachment, textarget, texture, level);
else glFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
}
#undef glFramebufferTexture2D
#define glFramebufferTexture2D rt_glFramebufferTexture2D
if (!glFramebufferTexture2D)
glFramebufferTexture2D = glFramebufferTexture2DEXT;

static inline void rt_glDeleteFramebuffers(GLsizei n, const GLuint* ids) {
if (glDeleteFramebuffers) glDeleteFramebuffers(n, ids);
else glDeleteFramebuffersEXT(n, ids);
}
#undef glDeleteFramebuffers
#define glDeleteFramebuffers rt_glDeleteFramebuffers
if (!glDeleteFramebuffers)
glDeleteFramebuffers = glDeleteFramebuffersEXT;

static inline GLenum rt_glCheckFramebufferStatus(GLenum target) {
if (glCheckFramebufferStatus) return glCheckFramebufferStatus(target);
else return glCheckFramebufferStatusEXT(target);
}
#undef glCheckFramebufferStatus
#define glCheckFramebufferStatus rt_glCheckFramebufferStatus
if (!glCheckFramebufferStatus)
glCheckFramebufferStatus = glCheckFramebufferStatusEXT;

static inline void rt_glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
GLbitfield mask, GLenum filter) {
if (glBlitFramebuffer) glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
else glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
}
#undef glBlitFramebuffer
#define glBlitFramebuffer rt_glBlitFramebuffer
if (!glBlitFramebuffer)
glBlitFramebuffer = glBlitFramebufferEXT;

static inline void rt_glBlendEquation(GLenum mode) {
if (glBlendEquation) glBlendEquation(mode);
else glBlendEquationEXT(mode);
}
#undef glBlendEquation
#define glBlendEquation rt_glBlendEquation
if (!glBlendEquation)
glBlendEquation = glBlendEquationEXT;

static inline void rt_glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) {
if (glBlendFuncSeparate) glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha);
else glBlendFuncSeparateEXT(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha);
if (!glBlendFuncSeparate)
glBlendFuncSeparate = glBlendFuncSeparateEXT;
}
#undef glBlendFuncSeparate
#define glBlendFuncSeparate rt_glBlendFuncSeparate

#endif
26 changes: 15 additions & 11 deletions src/gl_legacy/gl_legacy_renderer.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gl_legacy_renderer.h"
#include "matrix_math.h"
#include "text_utils.h"
#include "gl_wrappers.h"


#ifdef PLATFORM_PS3
Expand Down Expand Up @@ -45,6 +46,15 @@ static inline int32_t nextPow2(int32_t v) {
return r;
}

#include "stb_image.h"
#include "stb_ds.h"
#include "utils.h"
#include "image_decoder.h"
#include "gl_common.h"
#include "gl_wrappers.h"

// ===[ Runtime OpenGL extension checks ]===

// Checks whether an OpenGL extension is available. Uses the modern
// (glGetStringi + GL_NUM_EXTENSIONS) path when glGetStringi is non-null
// (GL 3.0+), otherwise falls back to the legacy glGetString(GL_EXTENSIONS)
Expand Down Expand Up @@ -72,24 +82,14 @@ static bool hasGLExtension(const char* name) {
}
#endif

#include "stb_image.h"
#include "stb_ds.h"
#include "utils.h"
#include "image_decoder.h"
#include "gl_common.h"

// ===[ Runtime OpenGL extension checks ]===

static bool hasFBO() {
#ifdef PLATFORM_PS3
return true;
#else
return (glGenFramebuffers || (glGenFramebuffersEXT && glBlitFramebufferEXT));
return (glGenFramebuffers && glBlitFramebuffer);
#endif
}

#include "gl_wrappers.h"

// ===[ Helpers ]===

static void glApplyViewport(GLLegacyRenderer* gl, int32_t x, int32_t y, int32_t w, int32_t h) {
Expand Down Expand Up @@ -144,6 +144,10 @@ static void glInit(Renderer* renderer, DataWin* dataWin) {
abort();
}

#ifndef PLATFORM_PS3
gl_init_wrappers();
#endif

// GL 2.0+ has NPOT textures as core; older GL (1.x) may or may not have
// GL_ARB_texture_non_power_of_two. Only round up to power-of-two on GPUs
// that actually need it (Intel 82865G etc.).
Expand Down
Loading