Skip to content

Commit

Permalink
Fix GLSL output
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 26, 2025
1 parent 8f9ebb5 commit 923aaee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sources/backends/glsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ static void write_functions(char *code, size_t *offset, shader_stage stage, type
}
case OPCODE_LOAD_MEMBER: {
uint64_t global_var_index = 0;
for (global_id j = 0; get_global(j)->type != NO_TYPE; ++j) {
for (global_id j = 0; get_global(j) != NULL && get_global(j)->type != NO_TYPE; ++j) {
global *g = get_global(j);
if (o->op_load_member.from.index == g->var_index) {
global_var_index = g->var_index;
Expand Down Expand Up @@ -358,8 +358,9 @@ static void write_functions(char *code, size_t *offset, shader_stage stage, type
indent(code, offset, indentation + 1);
*offset += sprintf(&code[*offset], "gl_Position.y = _%" PRIu64 ".%s.y;\n", o->op_return.var.index, get_name(t->members.m[0].name));
indent(code, offset, indentation + 1);
*offset += sprintf(&code[*offset], "gl_Position.z = (_%" PRIu64 ".%s.z * 2.0) - _%" PRIu64 ".%s.w;\n", o->op_return.var.index,
get_name(t->members.m[0].name), o->op_return.var.index, get_name(t->members.m[0].name));
*offset +=
sprintf(&code[*offset], "gl_Position.z = (_%" PRIu64 ".%s.z * 2.0) - _%" PRIu64 ".%s.w; // OpenGL clip space z is from -1 to 1\n",
o->op_return.var.index, get_name(t->members.m[0].name), o->op_return.var.index, get_name(t->members.m[0].name));
indent(code, offset, indentation + 1);
*offset += sprintf(&code[*offset], "gl_Position.w = _%" PRIu64 ".%s.w;\n", o->op_return.var.index, get_name(t->members.m[0].name));

Expand All @@ -369,7 +370,7 @@ static void write_functions(char *code, size_t *offset, shader_stage stage, type
o->op_return.var.index, get_name(t->members.m[j].name));
}

indent(code, offset, indentation);
indent(code, offset, indentation + 1);
*offset += sprintf(&code[*offset], "return;\n");
indent(code, offset, indentation);
*offset += sprintf(&code[*offset], "}\n");
Expand Down Expand Up @@ -518,7 +519,7 @@ void glsl_export(char *directory) {

memset(global_register_indices, 0, sizeof(global_register_indices));

for (global_id i = 0; get_global(i)->type != NO_TYPE; ++i) {
for (global_id i = 0; get_global(i) != NULL && get_global(i)->type != NO_TYPE; ++i) {
global *g = get_global(i);
if (g->type == sampler_type_id) {
global_register_indices[i] = sampler_index;
Expand Down
14 changes: 14 additions & 0 deletions sources/integrations/kore3.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ static const char *structure_type(type_id type, api_kind api) {
return "KORE_WEBGPU_VERTEX_FORMAT_FLOAT32X4";
}
}
else if (api == API_OPENGL) {
if (type == float_id) {
return "KORE_OPENGL_VERTEX_FORMAT_FLOAT32";
}
if (type == float2_id) {
return "KORE_OPENGL_VERTEX_FORMAT_FLOAT32X2";
}
if (type == float3_id) {
return "KORE_OPENGL_VERTEX_FORMAT_FLOAT32X3";
}
if (type == float4_id) {
return "KORE_OPENGL_VERTEX_FORMAT_FLOAT32X4";
}
}
debug_context context = {0};
error(context, "Unknown type for vertex structure");
return "UNKNOWN";
Expand Down

0 comments on commit 923aaee

Please sign in to comment.