Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling under c++ under emscipten fails #99

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion gs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7791,7 +7791,7 @@ gs_util_string_concat(char* s1, const char* s2)
const size_t a = strlen(s1);
const size_t b = strlen(s2);
const size_t ab = a + b + 1;
s1 = gs_realloc(s1, ab);
s1 = (char*)gs_realloc(s1, ab);
memcpy(s1 + a, s2, b + 1);
return s1;
}
Expand Down
58 changes: 33 additions & 25 deletions impl/gs_graphics_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ void gsgl_pipeline_state()
glDisable(GL_BLEND);
CHECK_GL_CORE(
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
glDisable(GL_MULTISAMPLE);
);
glDisable(GL_MULTISAMPLE);

CHECK_GL_CORE(
gs_graphics_info_t* info = gs_graphics_info();
Expand All @@ -205,15 +205,17 @@ void gsgl_pipeline_state()
)
}

void GLAPIENTRY
void// GLAPIENTRY (error: variable has incomplete type 'void')
gsgl_message_cb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
const GLchar* message, void* user_param)
{
return;
/*
if (type == GL_DEBUG_TYPE_ERROR) {
gs_println("GL [DEBUG]: %s type = 0x%x, severity = 0x%x, message = %s",
type == GL_DEBUG_TYPE_ERROR ? "GL ERROR" : "", type, severity, message);
}
*/
}

/* GS/OGL Utilities */
Expand Down Expand Up @@ -1499,7 +1501,7 @@ gs_grapics_storage_buffer_unlock_impl(gs_handle(gs_graphics_storage_buffer_t) hn
gsgl_data_t* ogl = (gsgl_data_t*)gs_subsystem(graphics)->user_data;
if (!gs_slot_array_handle_valid(ogl->storage_buffers, hndl.id)) {
gs_log_warning("Storage buffer handle invalid: %zu", hndl.id);
return NULL;
return;
}
gsgl_storage_buffer_t* sbo = gs_slot_array_getp(ogl->storage_buffers, hndl.id);

Expand All @@ -1515,8 +1517,10 @@ gs_grapics_storage_buffer_unlock_impl(gs_handle(gs_graphics_storage_buffer_t) hn

// Check for persistence here?...
if (sbo->map) {
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); // Do this via DSA instead...
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
CHECK_GL_CORE(
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); // Do this via DSA instead...
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
);
}
}

Expand Down Expand Up @@ -1546,16 +1550,18 @@ gs_grapics_storage_buffer_lock_impl(gs_handle(gs_graphics_storage_buffer_t) hndl
}
}
if (!sbo->map) {
// Get buffer size
glBindBuffer(GL_SHADER_STORAGE_BUFFER, sbo->buffer);
GLint buffer_sz = 0;
glGetBufferParameteriv(GL_SHADER_STORAGE_BUFFER, GL_BUFFER_SIZE, &buffer_sz);
gs_println("SZ: %zu, requested: %zu", buffer_sz, sz);
sbo->map = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, (GLintptr)offset, (GLsizeiptr)sz, GL_MAP_READ_BIT);
GLenum err = glGetError();
if (err) {
gs_println("GL ERROR: 0x%x: %s", err, glGetString(err));
}
CHECK_GL_CORE(
// Get buffer size
glBindBuffer(GL_SHADER_STORAGE_BUFFER, sbo->buffer);
GLint buffer_sz = 0;
glGetBufferParameteriv(GL_SHADER_STORAGE_BUFFER, GL_BUFFER_SIZE, &buffer_sz);
gs_println("SZ: %zu, requested: %zu", buffer_sz, sz);
sbo->map = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, (GLintptr)offset, (GLsizeiptr)sz, GL_MAP_READ_BIT);
GLenum err = glGetError();
if (err) {
gs_println("GL ERROR: 0x%x: %s", err, glGetString(err));
}
);
}
return sbo->map;
}
Expand All @@ -1567,16 +1573,18 @@ gs_storage_buffer_get_data_impl(gs_handle(gs_graphics_storage_buffer_t) hndl, si
gsgl_data_t* ogl = (gsgl_data_t*)gs_subsystem(graphics)->user_data;
if (!gs_slot_array_handle_valid(ogl->storage_buffers, hndl.id)) {
gs_log_warning("Storage buffer handle invalid: %zu", hndl.id);
return NULL;
return;
}
gsgl_storage_buffer_t* sbo = gs_slot_array_getp(ogl->storage_buffers, hndl.id);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, sbo->buffer);
glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, stride, out);
// GLenum err = glGetError();
// if (err) {
// gs_println("GL ERROR: 0x%x: %s", err, glGetString(err));
// }
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
CHECK_GL_CORE(
glBindBuffer(GL_SHADER_STORAGE_BUFFER, sbo->buffer);
glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, stride, out);
// GLenum err = glGetError();
// if (err) {
// gs_println("GL ERROR: 0x%x: %s", err, glGetString(err));
// }
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
);
}

#define __ogl_push_command(CB, OP_CODE, ...)\
Expand Down Expand Up @@ -2961,8 +2969,8 @@ gs_graphics_init(gs_graphics_t* graphics)
graphics->api.command_buffer_submit = gs_graphics_command_buffer_submit_impl;

// Enable debug output
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(gsgl_message_cb, 0);
//glEnable(GL_DEBUG_OUTPUT);
//glDebugMessageCallback(gsgl_message_cb, 0);
}


Expand Down
8 changes: 4 additions & 4 deletions util/gs_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -4800,12 +4800,12 @@ gs_gui_render(gs_gui_context_t* ctx, gs_command_buffer_t* cb)
{
case GSI_LAYOUT_VATTR:
{
gsi_vattr_list(&ctx->gsi, cmd->pipeline.layout, cmd->pipeline.layout_sz);
gsi_vattr_list(&ctx->gsi, (gsi_vattr_type*)cmd->pipeline.layout, cmd->pipeline.layout_sz);
} break;

case GSI_LAYOUT_MESH:
{
gsi_vattr_list_mesh(&ctx->gsi, cmd->pipeline.layout, cmd->pipeline.layout_sz);
gsi_vattr_list_mesh(&ctx->gsi, (gs_asset_mesh_layout_t*)cmd->pipeline.layout, cmd->pipeline.layout_sz);
} break;
}
}
Expand All @@ -4830,7 +4830,7 @@ gs_gui_render(gs_gui_context_t* ctx, gs_command_buffer_t* cb)
// Treat as byte buffer, read data
gs_byte_buffer_t buffer = gs_default_val();
buffer.capacity = GS_GUI_COMMANDLIST_SIZE;
buffer.data = cmd->uniforms.data;
buffer.data = (uint8_t*)cmd->uniforms.data;

// Write count
gs_byte_buffer_readc(&buffer, uint16_t, ct);
Expand Down Expand Up @@ -5296,7 +5296,7 @@ gs_gui_bind_uniforms(gs_gui_context_t* ctx,
// Treat as byte buffer, write into data then set size
gs_byte_buffer_t buffer = gs_default_val();
buffer.capacity = GS_GUI_COMMANDLIST_SIZE;
buffer.data = cmd->uniforms.data;
buffer.data = (uint8_t*)cmd->uniforms.data;

const uint16_t ct = uniforms_sz / sizeof(gs_graphics_bind_uniform_desc_t);

Expand Down