textures working on web, separation of vertex and index buffers (actually matters)
This commit is contained in:
@ -50,8 +50,9 @@ bool render_init(void) {
|
||||
|
||||
log_info("OpenGL context: %s\n", glGetString(GL_VERSION));
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST);
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
|
||||
glHint(GL_FOG_HINT, GL_FASTEST);
|
||||
|
||||
@ -196,59 +197,79 @@ static void finally_use_2d_pipeline(void) {
|
||||
pipeline_last_used = PIPELINE_2D;
|
||||
}
|
||||
|
||||
|
||||
static void setup_ghostly_texture_mode(void) {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
static GLuint list = 0;
|
||||
if (!list) {
|
||||
list = glGenLists(1);
|
||||
glNewList(list, GL_COMPILE);
|
||||
#endif
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
glEndList();
|
||||
}
|
||||
glCallList(list);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void setup_seethrough_texture_mode(void) {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
static GLuint list = 0;
|
||||
if (!list) {
|
||||
list = glGenLists(1);
|
||||
glNewList(list, GL_COMPILE);
|
||||
#endif
|
||||
glDisable(GL_BLEND);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc(GL_EQUAL, 1.0f);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
glEndList();
|
||||
}
|
||||
glCallList(list);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void setup_opaque_texture_mode(void) {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
static GLuint list = 0;
|
||||
if (!list) {
|
||||
list = glGenLists(1);
|
||||
glNewList(list, GL_COMPILE);
|
||||
#endif
|
||||
glDisable(GL_BLEND);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
glEndList();
|
||||
}
|
||||
glCallList(list);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* TODO: ensure we minimize depth func switching to enable Hi-Z (hierarchical depth) optimizations */
|
||||
static void finally_use_texture_mode(TextureMode mode) {
|
||||
if (texture_mode_last_used == mode)
|
||||
return;
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
static GLuint lists = 0;
|
||||
if (!lists) {
|
||||
lists = glGenLists(3);
|
||||
|
||||
/* ghostly */
|
||||
glNewList(lists + 0, GL_COMPILE); {
|
||||
#endif
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
} glEndList();
|
||||
|
||||
/* seethrough */
|
||||
glNewList(lists + 1, GL_COMPILE); {
|
||||
#endif
|
||||
glDisable(GL_BLEND);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc(GL_EQUAL, 1.0f);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
} glEndList();
|
||||
|
||||
/* opaque */
|
||||
glNewList(lists + 2, GL_COMPILE); {
|
||||
#endif
|
||||
glDisable(GL_BLEND);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
} glEndList();
|
||||
}
|
||||
|
||||
if (mode == TEXTURE_MODE_GHOSTLY) {
|
||||
glCallList(lists + 0);
|
||||
setup_ghostly_texture_mode();
|
||||
} else if (mode == TEXTURE_MODE_SEETHROUGH) {
|
||||
glCallList(lists + 1);
|
||||
setup_seethrough_texture_mode();
|
||||
} else {
|
||||
glCallList(lists + 2);
|
||||
setup_opaque_texture_mode();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
texture_mode_last_used = mode;
|
||||
}
|
||||
|
||||
@ -287,6 +308,40 @@ void finish_vertex_builder(VertexBufferBuilder *builder) {
|
||||
}
|
||||
|
||||
|
||||
IndexBufferBuilder build_index_buffer(IndexBuffer buffer, size_t bytes) {
|
||||
SDL_assert(bytes != 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bytes, NULL, GL_STREAM_DRAW);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
void *mapping = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
#else
|
||||
void *mapping = SDL_malloc(bytes);
|
||||
#endif
|
||||
if (!mapping)
|
||||
CRY("build_vertex_buffer", "Error mapping a vertex array buffer");
|
||||
|
||||
return (IndexBufferBuilder) {
|
||||
.base = mapping,
|
||||
.size = bytes,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
void finish_index_builder(IndexBufferBuilder *builder) {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (!glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER))
|
||||
CRY("finish_vertex_builder", "Error unmapping a vertex array buffer");
|
||||
#else
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, builder->size, builder->base, GL_STREAM_DRAW);
|
||||
SDL_free(builder->base);
|
||||
#endif
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
builder->base = 0;
|
||||
builder->size = 0;
|
||||
}
|
||||
|
||||
|
||||
static void load_cubemap_side(const char *path, GLenum target) {
|
||||
SDL_Surface *surface = textures_load_surface(path);
|
||||
/* TODO: sanity check whether all of them have same dimensions? */
|
||||
|
Reference in New Issue
Block a user