Skip to content
Open
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
43 changes: 40 additions & 3 deletions renderers/RSGL_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ RSGL_rendererProc RSGL_GL_rendererProc() {
return proc;
}

void RSGL_GL_deleteTexture(RSGL_glRenderer* ctx, RSGL_texture tex) { glDeleteTextures(1, (u32*)&tex); }
void RSGL_GL_viewport(RSGL_glRenderer* ctx, i32 x, i32 y, i32 w, i32 h) { glViewport(x, y, w ,h); }
void RSGL_GL_deleteTexture(RSGL_glRenderer* ctx, RSGL_texture tex) { RSGL_UNUSED(ctx); glDeleteTextures(1, (u32*)&tex); }
void RSGL_GL_viewport(RSGL_glRenderer* ctx, i32 x, i32 y, i32 w, i32 h) { RSGL_UNUSED(ctx); glViewport(x, y, w ,h); }

void RSGL_GL_clear(RSGL_glRenderer* ctx, RSGL_framebuffer framebuffer, float r, float g, float b, float a) {
RSGL_UNUSED(ctx);

glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

glClearColor(r, g, b, a);
Expand Down Expand Up @@ -185,6 +187,8 @@ GLuint RSGL_GL_bufferTypeToNative(RSGL_bufferType type) {
}

void RSGL_GL_createBuffer(RSGL_glRenderer* ctx, RSGL_bufferType type, size_t size, const void* data, size_t* buffer) {
RSGL_UNUSED(ctx);

glGenBuffers(1, (u32*)buffer);

GLenum usage = GL_STATIC_DRAW;
Expand All @@ -196,15 +200,21 @@ void RSGL_GL_createBuffer(RSGL_glRenderer* ctx, RSGL_bufferType type, size_t siz
}

void RSGL_GL_updateBuffer(RSGL_glRenderer* ctx, RSGL_bufferType type, size_t buffer, const void* data, size_t start, size_t end) {
RSGL_UNUSED(ctx);

glBindBuffer(RSGL_GL_bufferTypeToNative(type), *(u32*)&buffer);
glBufferSubData(RSGL_GL_bufferTypeToNative(type), start, end, data);
}

void RSGL_GL_deleteBuffer(RSGL_glRenderer* ctx, size_t buffer) {
RSGL_UNUSED(ctx);

glDeleteBuffers(1, (u32*)&buffer);
}

RSGL_programBlob RSGL_GL_defaultBlob(RSGL_glRenderer* ctx) {
RSGL_UNUSED(ctx);

#ifdef RSGL_GL3

static const char *defaultVShaderCode = RSGL_MULTILINE_STR(
Expand Down Expand Up @@ -414,12 +424,16 @@ void RSGL_GL_render(RSGL_glRenderer* ctx, const RSGL_renderPass* pass) {
}

void RSGL_GL_scissorStart(RSGL_glRenderer* ctx, float x, float y, float w, float h, float renderer_height) {
RSGL_UNUSED(ctx);

glEnable(GL_SCISSOR_TEST);

glScissor(x, renderer_height - (y + h), w, h);
}

void RSGL_GL_scissorEnd(RSGL_glRenderer* ctx) {
RSGL_UNUSED(ctx);

glDisable(GL_SCISSOR_TEST);
}

Expand Down Expand Up @@ -468,6 +482,7 @@ GLuint RSGL_GL_textureFilterToNative(RSGL_textureFilter filter) {

/* textures / images */
RSGL_texture RSGL_GL_createTexture(RSGL_glRenderer* ctx, const RSGL_textureBlob* blob) {
RSGL_UNUSED(ctx);
unsigned int id = 0;

glBindTexture(GL_TEXTURE_2D, 0);
Expand Down Expand Up @@ -511,6 +526,8 @@ RSGL_texture RSGL_GL_createTexture(RSGL_glRenderer* ctx, const RSGL_textureBlob*
}

void RSGL_GL_copyToTexture(RSGL_glRenderer* ctx, RSGL_texture texture, size_t x, size_t y, const RSGL_textureBlob* blob) {
RSGL_UNUSED(ctx);

glBindTexture(GL_TEXTURE_2D, texture);

#ifndef RSGL_GLES2
Expand Down Expand Up @@ -600,6 +617,8 @@ void RSGL_debug_shader(u32 src, const char *shader, const char *action) {
}

RSGL_programInfo RSGL_GL_createProgram(RSGL_glRenderer* ctx, RSGL_programBlob* blob) {
RSGL_UNUSED(ctx);

RSGL_programInfo program;
u32 vShader, fShader;

Expand Down Expand Up @@ -638,7 +657,7 @@ RSGL_programInfo RSGL_GL_createProgram(RSGL_glRenderer* ctx, RSGL_programBlob* b
program.perspectiveView = glGetUniformLocation(program.program, "pv");
program.model = glGetUniformLocation(program.program, "model");

if (program.perspectiveView < 0 || program.model < 0) {
if (program.perspectiveView == SIZE_MAX || program.model == SIZE_MAX) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only real notable change. both perspectiveView and model are size_t so -1 value would wrap to SIZE_MAX

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but this is a little weird to do. It might be better to check the return values from glGetUniformLocation as signed ints first, just so this part is less 'odd'.

RSGL_debugCallback(RSGL_typeError, RSGL_errorQueryFail, "Failed to locate the shader variables\n");
}

Expand All @@ -649,25 +668,35 @@ RSGL_programInfo RSGL_GL_createProgram(RSGL_glRenderer* ctx, RSGL_programBlob* b
}

void RSGL_GL_deleteProgram(RSGL_glRenderer* ctx, const RSGL_programInfo* program) {
RSGL_UNUSED(ctx);

glUseProgram(0);
glDeleteProgram(program->program);
}

size_t RSGL_GL_findShaderArray(RSGL_glRenderer* ctx, const RSGL_programInfo* program, const char* var, const size_t len) {
RSGL_UNUSED(ctx);
RSGL_UNUSED(len);

glUseProgram(program->program);
int loc = glGetAttribLocation(program->program, var);
glUseProgram(0);
return loc;
}

size_t RSGL_GL_findShaderVariable(RSGL_glRenderer* ctx, const RSGL_programInfo* program, const char* var, const size_t len) {
RSGL_UNUSED(ctx);
RSGL_UNUSED(len);

glUseProgram(program->program);
int loc = glGetUniformLocation(program->program, var);
glUseProgram(0);
return loc;
}

void RSGL_GL_updateShaderVariable(RSGL_glRenderer* ctx, const RSGL_programInfo* program, size_t var, const float value[], u8 len) {
RSGL_UNUSED(ctx);

glUseProgram(program->program);
int loc = (int)var;

Expand All @@ -684,12 +713,18 @@ void RSGL_GL_updateShaderVariable(RSGL_glRenderer* ctx, const RSGL_programInfo*
}

RSGL_framebuffer RSGL_GL_createFramebuffer(RSGL_glRenderer* ctx, size_t width, size_t height) {
RSGL_UNUSED(ctx);
RSGL_UNUSED(width);
RSGL_UNUSED(height);

u32 result = 0;
glGenFramebuffers(1, &result);
return (RSGL_framebuffer)result;
}

void RSGL_GL_attachFramebuffer(RSGL_glRenderer* ctx, RSGL_framebuffer fbo, RSGL_texture tex, u8 attachType, u8 mipLevel) {
RSGL_UNUSED(ctx);

glBindFramebuffer(GL_FRAMEBUFFER, fbo);

if (attachType < 8)
Expand All @@ -705,6 +740,8 @@ void RSGL_GL_attachFramebuffer(RSGL_glRenderer* ctx, RSGL_framebuffer fbo, RSGL_
}

void RSGL_GL_deleteFramebuffer(RSGL_glRenderer* ctx, RSGL_framebuffer fbo) {
RSGL_UNUSED(ctx);

u32 value = fbo;
glDeleteFramebuffers(1, &value);
}
Expand Down
Loading