made web compatible

This commit is contained in:
DaniTheSkunk 2023-01-14 18:06:44 +00:00
parent 3d41defaf9
commit fdfb5b8032
2 changed files with 18 additions and 5 deletions

View File

@ -7,7 +7,9 @@
static f32 screen_rect[12] = { static f32 screen_rect[12] = {
-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; -1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f};
static u32 sw_screen_vao, vbo;
u32 sw_screen_vao;
static u32 vbo;
struct sw_framebuffer *sw_framebuffer_create(struct sw_vec2i size) { struct sw_framebuffer *sw_framebuffer_create(struct sw_vec2i size) {
struct sw_framebuffer *fb; struct sw_framebuffer *fb;
@ -60,7 +62,7 @@ void sw_framebuffer_render(struct sw_framebuffer *fb) {
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 12); glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0); glBindVertexArray(0);
} }
@ -84,13 +86,15 @@ void sw_framebuffer_resize(
); );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, fb->_fbtex, 0); glFramebufferTexture2D(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb->_fbtex, 0
);
glBindTexture(GL_TEXTURE_2D, fb->_fbdepth); glBindTexture(GL_TEXTURE_2D, fb->_fbdepth);
glTexImage2D( glTexImage2D(
GL_TEXTURE_2D, GL_TEXTURE_2D,
0, 0,
GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT16,
new_size.x, new_size.x,
new_size.y, new_size.y,
0, 0,
@ -101,5 +105,7 @@ void sw_framebuffer_resize(
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, fb->_fbdepth, 0); glFramebufferTexture2D(
GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, fb->_fbdepth, 0
);
} }

View File

@ -15,6 +15,8 @@ static void _tick();
static struct sw_window *_tick_window; static struct sw_window *_tick_window;
static void (*_tick_fn)(); static void (*_tick_fn)();
static void win_callback(GLFWwindow *glfw_win, i32 width, i32 height); static void win_callback(GLFWwindow *glfw_win, i32 width, i32 height);
#ifndef __EMSCRIPTEN__
static void GLAPIENTRY gldebug( static void GLAPIENTRY gldebug(
GLenum source, GLenum source,
GLenum type, GLenum type,
@ -24,6 +26,7 @@ static void GLAPIENTRY gldebug(
const char *msg, const char *msg,
const void *user const void *user
); );
#endif
struct sw_window *sw_window_create(struct sw_vec2i size, char *title) { struct sw_window *sw_window_create(struct sw_vec2i size, char *title) {
struct sw_window *win; struct sw_window *win;
@ -42,7 +45,9 @@ struct sw_window *sw_window_create(struct sw_vec2i size, char *title) {
glfwMakeContextCurrent(win->_window); glfwMakeContextCurrent(win->_window);
glewInit(); glewInit();
glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT);
#ifndef __EMSCRIPTEN__
glDebugMessageCallback(gldebug, 0); glDebugMessageCallback(gldebug, 0);
#endif
glfwSwapInterval(1); glfwSwapInterval(1);
sw_log("setup ogl defaults"); sw_log("setup ogl defaults");
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -101,6 +106,7 @@ static void win_callback(GLFWwindow *glfw_win, i32 width, i32 height) {
win->window_size = sw_vec2i(width, height); win->window_size = sw_vec2i(width, height);
} }
#ifndef __EMSCRIPTEN__
void GLAPIENTRY gldebug( void GLAPIENTRY gldebug(
GLenum source, GLenum source,
GLenum type, GLenum type,
@ -122,3 +128,4 @@ void GLAPIENTRY gldebug(
sw_log("%s", msg); sw_log("%s", msg);
} }
} }
#endif