Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.
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
41 changes: 27 additions & 14 deletions src/refresh/gl/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ typedef struct {
typedef struct {
bool registering;
bool use_shaders;
glbackend_t backend;
struct {
bsp_t *cache;
memhunk_t hunk;
Expand Down Expand Up @@ -127,7 +126,7 @@ typedef struct {
bool framebuffer_ok;
} glRefdef_t;

enum {
typedef enum {
QGL_CAP_LEGACY = BIT(0),
QGL_CAP_SHADER = BIT(1),
QGL_CAP_TEXTURE_BITS = BIT(2),
Expand All @@ -136,7 +135,7 @@ enum {
QGL_CAP_TEXTURE_LOD_BIAS = BIT(5),
QGL_CAP_TEXTURE_NON_POWER_OF_TWO = BIT(6),
QGL_CAP_TEXTURE_ANISOTROPY = BIT(7),
};
} glcap_t;

#define QGL_VER(major, minor) ((major) * 100 + (minor))
#define QGL_UNPACK_VER(ver) (ver) / 100, (ver) % 100
Expand All @@ -145,7 +144,7 @@ typedef struct {
int ver_gl;
int ver_es;
int ver_sl;
int caps;
glcap_t caps;
int colorbits;
int depthbits;
int stencilbits;
Expand Down Expand Up @@ -364,6 +363,8 @@ typedef struct {

extern glState_t gls;

extern const glbackend_t *gl_backend;

static inline void GL_ActiveTexture(GLuint tmu)
{
if (gls.server_tmu != tmu) {
Expand All @@ -383,15 +384,15 @@ static inline void GL_ClientActiveTexture(GLuint tmu)
static inline void GL_StateBits(GLbitfield bits)
{
if (gls.state_bits != bits) {
gl_static.backend.state_bits(bits);
gl_backend->state_bits(bits);
gls.state_bits = bits;
}
}

static inline void GL_ArrayBits(GLbitfield bits)
{
if (gls.array_bits != bits) {
gl_static.backend.array_bits(bits);
gl_backend->array_bits(bits);
gls.array_bits = bits;
}
}
Expand All @@ -412,14 +413,14 @@ static inline void GL_UnlockArrays(void)

static inline void GL_ForceMatrix(const GLfloat *matrix)
{
gl_static.backend.load_view_matrix(matrix);
gl_backend->load_view_matrix(matrix);
gls.currentmatrix = matrix;
}

static inline void GL_LoadMatrix(const GLfloat *matrix)
{
if (gls.currentmatrix != matrix) {
gl_static.backend.load_view_matrix(matrix);
gl_backend->load_view_matrix(matrix);
gls.currentmatrix = matrix;
}
}
Expand All @@ -440,12 +441,24 @@ static inline void GL_DepthRange(GLfloat n, GLfloat f)
qglDepthRange(n, f);
}

#define GL_VertexPointer gl_static.backend.vertex_pointer
#define GL_TexCoordPointer gl_static.backend.tex_coord_pointer
#define GL_LightCoordPointer gl_static.backend.light_coord_pointer
#define GL_ColorBytePointer gl_static.backend.color_byte_pointer
#define GL_ColorFloatPointer gl_static.backend.color_float_pointer
#define GL_Color gl_static.backend.color
#define VBO_OFS(n) ((void *)(sizeof(GLfloat) * (n)))

#define GL_VertexPointer(size, stride, ptr) \
gl_backend->vertex_pointer((size), (stride) * sizeof(GLfloat), (ptr))

#define GL_TexCoordPointer(size, stride, ptr) \
gl_backend->tex_coord_pointer((size), (stride) * sizeof(GLfloat), (ptr))

#define GL_LightCoordPointer(size, stride, ptr) \
gl_backend->light_coord_pointer((size), (stride) * sizeof(GLfloat), (ptr))

#define GL_ColorBytePointer(size, stride, ptr) \
gl_backend->color_byte_pointer((size), (stride) * sizeof(GLfloat), (ptr))

#define GL_ColorFloatPointer(size, stride, ptr) \
gl_backend->color_float_pointer((size), (stride) * sizeof(GLfloat), (ptr))

#define GL_Color(r, g, b, a) gl_backend->color(r, g, b, a)

void GL_ForceTexture(GLuint tmu, GLuint texnum);
void GL_BindTexture(GLuint tmu, GLuint texnum);
Expand Down
10 changes: 5 additions & 5 deletions src/refresh/gl/legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,29 @@ static void legacy_array_bits(GLbitfield bits)

static void legacy_vertex_pointer(GLint size, GLsizei stride, const GLfloat *pointer)
{
qglVertexPointer(size, GL_FLOAT, sizeof(GLfloat) * stride, pointer);
qglVertexPointer(size, GL_FLOAT, stride, pointer);
}

static void legacy_tex_coord_pointer(GLint size, GLsizei stride, const GLfloat *pointer)
{
GL_ClientActiveTexture(0);
qglTexCoordPointer(size, GL_FLOAT, sizeof(GLfloat) * stride, pointer);
qglTexCoordPointer(size, GL_FLOAT, stride, pointer);
}

static void legacy_light_coord_pointer(GLint size, GLsizei stride, const GLfloat *pointer)
{
GL_ClientActiveTexture(1);
qglTexCoordPointer(size, GL_FLOAT, sizeof(GLfloat) * stride, pointer);
qglTexCoordPointer(size, GL_FLOAT, stride, pointer);
}

static void legacy_color_byte_pointer(GLint size, GLsizei stride, const GLubyte *pointer)
{
qglColorPointer(size, GL_UNSIGNED_BYTE, sizeof(GLfloat) * stride, pointer);
qglColorPointer(size, GL_UNSIGNED_BYTE, stride, pointer);
}

static void legacy_color_float_pointer(GLint size, GLsizei stride, const GLfloat *pointer)
{
qglColorPointer(size, GL_FLOAT, sizeof(GLfloat) * stride, pointer);
qglColorPointer(size, GL_FLOAT, stride, pointer);
}

static void legacy_color(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
Expand Down
10 changes: 5 additions & 5 deletions src/refresh/gl/shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,27 @@ static void shader_array_bits(GLbitfield bits)

static void shader_vertex_pointer(GLint size, GLsizei stride, const GLfloat *pointer)
{
qglVertexAttribPointer(VERT_ATTR_POS, size, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * stride, pointer);
qglVertexAttribPointer(VERT_ATTR_POS, size, GL_FLOAT, GL_FALSE, stride, pointer);
}

static void shader_tex_coord_pointer(GLint size, GLsizei stride, const GLfloat *pointer)
{
qglVertexAttribPointer(VERT_ATTR_TC, size, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * stride, pointer);
qglVertexAttribPointer(VERT_ATTR_TC, size, GL_FLOAT, GL_FALSE, stride, pointer);
}

static void shader_light_coord_pointer(GLint size, GLsizei stride, const GLfloat *pointer)
{
qglVertexAttribPointer(VERT_ATTR_LMTC, size, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * stride, pointer);
qglVertexAttribPointer(VERT_ATTR_LMTC, size, GL_FLOAT, GL_FALSE, stride, pointer);
}

static void shader_color_byte_pointer(GLint size, GLsizei stride, const GLubyte *pointer)
{
qglVertexAttribPointer(VERT_ATTR_COLOR, size, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(GLfloat) * stride, pointer);
qglVertexAttribPointer(VERT_ATTR_COLOR, size, GL_UNSIGNED_BYTE, GL_TRUE, stride, pointer);
}

static void shader_color_float_pointer(GLint size, GLsizei stride, const GLfloat *pointer)
{
qglVertexAttribPointer(VERT_ATTR_COLOR, size, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * stride, pointer);
qglVertexAttribPointer(VERT_ATTR_COLOR, size, GL_FLOAT, GL_FALSE, stride, pointer);
}

static void shader_color(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
Expand Down
27 changes: 15 additions & 12 deletions src/refresh/gl/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,

glState_t gls;

const glbackend_t *gl_backend;

// for uploading
void GL_ForceTexture(GLuint tmu, GLuint texnum)
{
Expand Down Expand Up @@ -150,7 +152,7 @@ void GL_Ortho(GLfloat xmin, GLfloat xmax, GLfloat ymin, GLfloat ymax, GLfloat zn
matrix[11] = 0;
matrix[15] = 1;

gl_static.backend.load_proj_matrix(matrix);
gl_backend->load_proj_matrix(matrix);
}

void GL_Setup2D(void)
Expand All @@ -168,10 +170,10 @@ void GL_Setup2D(void)
draw.scissor = false;
}

if (gl_static.backend.setup_2d)
gl_static.backend.setup_2d();
if (gl_backend->setup_2d)
gl_backend->setup_2d();

gl_static.backend.load_view_matrix(NULL);
gl_backend->load_view_matrix(NULL);
}

void GL_Frustum(GLfloat fov_x, GLfloat fov_y, GLfloat reflect_x, GLfloat near_scale)
Expand Down Expand Up @@ -217,7 +219,7 @@ void GL_Frustum(GLfloat fov_x, GLfloat fov_y, GLfloat reflect_x, GLfloat near_sc
matrix[11] = -1;
matrix[15] = 0;

gl_static.backend.load_proj_matrix(matrix);
gl_backend->load_proj_matrix(matrix);
}

static void GL_RotateForViewer(void)
Expand Down Expand Up @@ -257,8 +259,8 @@ void GL_Setup3D(bool waterwarp)
qglViewport(glr.fd.x, r_config.height - (glr.fd.y + glr.fd.height),
glr.fd.width, glr.fd.height);

if (gl_static.backend.setup_3d)
gl_static.backend.setup_3d();
if (gl_backend->setup_3d)
gl_backend->setup_3d();

GL_Frustum(glr.fd.fov_x, glr.fd.fov_y, 1.0f, 1.0f);

Expand Down Expand Up @@ -316,7 +318,7 @@ void GL_ClearState(void)
qglCullFace(GL_BACK);
qglEnable(GL_CULL_FACE);

gl_static.backend.clear_state();
gl_backend->clear_state();

qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | gl_static.stencil_buffer_bit);

Expand All @@ -342,13 +344,14 @@ void GL_InitState(void)
}
}

gl_static.backend = gl_static.use_shaders ? backend_shader : backend_legacy;
gl_static.backend.init();
gl_backend = gl_static.use_shaders ? &backend_shader : &backend_legacy;
gl_backend->init();

Com_Printf("Using %s rendering backend.\n", gl_static.backend.name);
Com_Printf("Using %s rendering backend.\n", gl_backend->name);
}

void GL_ShutdownState(void)
{
gl_static.backend.shutdown();
gl_backend->shutdown();
gl_backend = NULL;
}
8 changes: 4 additions & 4 deletions src/refresh/gl/tess.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ void GL_BindArrays(void)
} else {
qglBindBuffer(GL_ARRAY_BUFFER, gl_static.world.bufnum);

GL_VertexPointer(3, VERTEX_SIZE, (GLfloat *)0);
GL_TexCoordPointer(2, VERTEX_SIZE, (GLfloat *)(sizeof(GLfloat) * 4));
GL_VertexPointer(3, VERTEX_SIZE, VBO_OFS(0));
GL_TexCoordPointer(2, VERTEX_SIZE, VBO_OFS(4));
if (lm.nummaps) {
GL_LightCoordPointer(2, VERTEX_SIZE, (GLfloat *)(sizeof(GLfloat) * 6));
GL_LightCoordPointer(2, VERTEX_SIZE, VBO_OFS(6));
}
GL_ColorBytePointer(4, VERTEX_SIZE, (GLubyte *)(sizeof(GLfloat) * 3));
GL_ColorBytePointer(4, VERTEX_SIZE, VBO_OFS(3));

qglBindBuffer(GL_ARRAY_BUFFER, 0);
}
Expand Down