attempt to build web version out of emscripten legacy gl wrapper

This commit is contained in:
veclavtalica
2025-02-21 18:07:04 +03:00
parent 85e47dd677
commit dd4fc45be3
10 changed files with 123 additions and 68 deletions

View File

@ -5,12 +5,13 @@
#include <stb_ds.h>
#ifdef EMSCRIPTEN
#include <GLES2/gl2.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>
#else
#include <glad/glad.h>
#endif
void setup_viewport(int x, int y, int width, int height) {
glViewport(x, y, width, height);
}
@ -127,12 +128,7 @@ GPUTexture create_gpu_texture(TextureFilter filter, bool generate_mipmaps, int c
SDL_assert(width > 0 && height > 0);
SDL_assert(channels > 0 && channels <= 4);
#if !defined(EMSCRIPTEN)
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLboolean)generate_mipmaps);
#else
if (generate_mipmaps)
glGenerateMipmap(GL_TEXTURE_2D);
#endif
if (filter == TEXTURE_FILTER_NEAREAST) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -145,24 +141,14 @@ GPUTexture create_gpu_texture(TextureFilter filter, bool generate_mipmaps, int c
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
#if !defined(EMSCRIPTEN)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#endif
int format_internal, format;
if (channels == 4) {
#ifdef EMSCRIPTEN
format_internal = GL_RGBA;
#else
format_internal = GL_RGBA8;
#endif
format = GL_RGBA;
} else if (channels == 3) {
#ifdef EMSCRIPTEN
format_internal = GL_RGBA;
#else
format_internal = GL_RGBA8;
#endif
format = GL_RGB;
} else if (channels == 1) {
format_internal = GL_ALPHA;