poll workers for non-threaded support, emscripten main loop, remove twn_model.c

This commit is contained in:
veclavtalica
2025-02-21 21:16:15 +03:00
parent dc6b298532
commit d76ea06470
12 changed files with 105 additions and 289 deletions

View File

@ -5,7 +5,7 @@
#include "twn_types.h"
#include "twn_deferred_commands.h"
#ifdef EMSCRIPTEN
#ifdef __EMSCRIPTEN__
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>
@ -41,7 +41,7 @@ static void APIENTRY opengl_log(GLenum source,
bool render_init(void) {
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
if (gladLoadGLLoader(&SDL_GL_GetProcAddress) == 0) {
CRY("Init", "GLAD failed");
return false;
@ -50,7 +50,7 @@ bool render_init(void) {
log_info("OpenGL context: %s\n", glGetString(GL_VERSION));
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST);
glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
glHint(GL_FOG_HINT, GL_FASTEST);
@ -98,7 +98,7 @@ static void finally_use_space_pipeline(void) {
depth_range_high = 1.0;
depth_range_low = 0.0;
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
static GLuint list = 0;
if (!list) {
list = glGenLists(1);
@ -109,7 +109,7 @@ static void finally_use_space_pipeline(void) {
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_FLAT);
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
if (GLAD_GL_ARB_depth_clamp)
glDisable(GL_DEPTH_CLAMP);
#endif
@ -125,7 +125,7 @@ static void finally_use_space_pipeline(void) {
/* solid white, no modulation */
glColor4ub(255, 255, 255, 255);
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
} glEndList();
glCallList(list);
@ -152,7 +152,7 @@ static void finally_use_2d_pipeline(void) {
if (pipeline_last_used == PIPELINE_2D)
return;
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
static GLuint list = 0;
if (!list) {
list = glGenLists(1);
@ -161,7 +161,7 @@ static void finally_use_2d_pipeline(void) {
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glShadeModel(GL_FLAT);
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
/* removes near/far plane comparison and discard */
if (GLAD_GL_ARB_depth_clamp)
glEnable(GL_DEPTH_CLAMP);
@ -171,7 +171,7 @@ static void finally_use_2d_pipeline(void) {
glActiveTexture(GL_TEXTURE0);
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
} glEndList();
} glCallList(list);
@ -201,7 +201,7 @@ static void finally_use_texture_mode(TextureMode mode) {
if (texture_mode_last_used == mode)
return;
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
static GLuint lists = 0;
if (!lists) {
lists = glGenLists(3);
@ -214,7 +214,7 @@ static void finally_use_texture_mode(TextureMode mode) {
glDepthFunc(GL_LESS);
glDepthMask(GL_FALSE);
glDisable(GL_ALPHA_TEST);
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
} glEndList();
/* seethrough */
@ -225,7 +225,7 @@ static void finally_use_texture_mode(TextureMode mode) {
glDepthMask(GL_TRUE);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_EQUAL, 1.0f);
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
} glEndList();
/* opaque */
@ -235,7 +235,7 @@ static void finally_use_texture_mode(TextureMode mode) {
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
glDisable(GL_ALPHA_TEST);
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
} glEndList();
}
@ -257,7 +257,7 @@ VertexBufferBuilder build_vertex_buffer(VertexBuffer buffer, size_t bytes) {
SDL_assert(bytes != 0);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, bytes, NULL, GL_STREAM_DRAW);
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
void *mapping = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
#else
void *mapping = SDL_malloc(bytes);
@ -273,7 +273,7 @@ VertexBufferBuilder build_vertex_buffer(VertexBuffer buffer, size_t bytes) {
void finish_vertex_builder(VertexBufferBuilder *builder) {
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
if (!glUnmapBuffer(GL_ARRAY_BUFFER))
CRY("finish_vertex_builder", "Error unmapping a vertex array buffer");
#else
@ -372,7 +372,7 @@ void finally_render_skybox(DeferredCommandDrawSkybox command) {
/* TODO: figure out which coordinates to use to not have issues with far z */
/* TODO: recalculate the list if far z requirement changes */
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
static GLuint list = 0;
if (!list) {
list = glGenLists(1);
@ -384,7 +384,7 @@ void finally_render_skybox(DeferredCommandDrawSkybox command) {
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
/* removes near/far plane comparison and discard */
if (GLAD_GL_ARB_depth_clamp)
glEnable(GL_DEPTH_CLAMP);
@ -452,7 +452,7 @@ void finally_render_skybox(DeferredCommandDrawSkybox command) {
glVertex3f(-50.f, 50.f, -50.f);
} glEnd();
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
if (GLAD_GL_ARB_depth_clamp)
glDisable(GL_DEPTH_CLAMP);
#endif
@ -460,7 +460,7 @@ void finally_render_skybox(DeferredCommandDrawSkybox command) {
glDepthMask(GL_TRUE);
glDisable(GL_TEXTURE_CUBE_MAP);
#ifndef EMSCRIPTEN
#ifndef __EMSCRIPTEN__
} glEndList();
glCallList(list);
#endif