demos: fix lmap and lod demo

main
Dominik Madarász 2024-04-11 00:51:47 +02:00
parent 99111665ba
commit b4d410212f
5 changed files with 47 additions and 29 deletions

View File

@ -187,6 +187,8 @@ int main() {
cam.position = vec3(1.667,0.503,2.417);
camera_lookat(&cam, vec3(0,0,0));
renderstate_t state = renderstate();
mesh_t m = mesh();
InitModel(&m);
@ -221,6 +223,7 @@ int main() {
mesh_area(&m);
}
renderstate_apply(&state);
DrawModel(&m);
if( ui_panel("LODs", PANEL_OPEN) ) {

View File

@ -6,14 +6,14 @@ int main() {
// set up pipeline
renderstate_t state = renderstate();
state.clearColor[0] = 0.2f;
state.clearColor[1] = 0.2f;
state.clearColor[2] = 0.2f;
state.clearColor[3] = 1.0f;
state.depthTestEnabled = GL_TRUE;
state.depthFunc = GL_LEQUAL;
state.blendEnabled = GL_FALSE;
state.cullFaceEnabled = GL_TRUE;
state.clear_color[0] = 0.2f;
state.clear_color[1] = 0.2f;
state.clear_color[2] = 0.2f;
state.clear_color[3] = 1.0f;
state.depth_test_enabled = GL_TRUE;
state.depth_func = GL_LEQUAL;
state.blend_enabled = GL_FALSE;
state.cull_face_enabled = GL_TRUE;
// prepare triangle buffer
float vertices[] = {

View File

@ -370197,8 +370197,8 @@ bool renderstate_compare(const renderstate_t *stateA, const renderstate_t *state
void renderstate_apply(const renderstate_t *state) {
if (state != NULL) {
// Apply viewport parameters
glViewport(state->viewport_x, state->viewport_y, state->viewport_width, state->viewport_height);
// Apply viewport parameters @fixme
// glViewport(state->viewport_x, state->viewport_y, state->viewport_width, state->viewport_height);
// Apply clear color
glClearColor(state->clear_color[0], state->clear_color[1], state->clear_color[2], state->clear_color[3]);
@ -374051,6 +374051,8 @@ float model_animate(model_t m, float curframe) {
return model_animate_clip(m, curframe, 0, q->numframes-1, true);
}
static bool model_lightmap_hook = 0; //@fixme: delete this
static
void model_draw_call(model_t m, int shader) {
if(!m.iqm) return;
@ -374061,6 +374063,12 @@ void model_draw_call(model_t m, int shader) {
renderstate_apply(&m.rs);
//@fixme lightmap_bake state hook
if (model_lightmap_hook) {
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
}
glBindVertexArray( q->vao );
struct iqmtriangle *tris = NULL;
@ -374250,9 +374258,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
ASSERT(lm->ready);
// @fixme: use xatlas to UV pack all models, update their UV1 and upload them to GPU.
GLint cullface=0;
glGetIntegerv(GL_CULL_FACE, &cullface);
glDisable(GL_CULL_FACE);
model_lightmap_hook=1;
int w = lm->w, h = lm->h;
for (int i = 0; i < array_count(lm->models); i++) {
@ -374281,7 +374287,6 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, texcoord), sizeof(iqm_vertex),
m->num_tris*3, LM_UNSIGNED_INT, m->tris);
glDisable(GL_BLEND);
int vp[4];
float view[16], projection[16];
while (lmBegin(lm->ctx, vp, view, projection))
@ -374318,7 +374323,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
}
}
if (cullface) glEnable(GL_CULL_FACE);
model_lightmap_hook = 0;
}
#line 0

View File

@ -122,8 +122,8 @@ bool renderstate_compare(const renderstate_t *stateA, const renderstate_t *state
void renderstate_apply(const renderstate_t *state) {
if (state != NULL) {
// Apply viewport parameters
glViewport(state->viewport_x, state->viewport_y, state->viewport_width, state->viewport_height);
// Apply viewport parameters @fixme
// glViewport(state->viewport_x, state->viewport_y, state->viewport_width, state->viewport_height);
// Apply clear color
glClearColor(state->clear_color[0], state->clear_color[1], state->clear_color[2], state->clear_color[3]);
@ -3976,6 +3976,8 @@ float model_animate(model_t m, float curframe) {
return model_animate_clip(m, curframe, 0, q->numframes-1, true);
}
static bool model_lightmap_hook = 0; //@fixme: delete this
static
void model_draw_call(model_t m, int shader) {
if(!m.iqm) return;
@ -3986,6 +3988,12 @@ void model_draw_call(model_t m, int shader) {
renderstate_apply(&m.rs);
//@fixme lightmap_bake state hook
if (model_lightmap_hook) {
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
}
glBindVertexArray( q->vao );
struct iqmtriangle *tris = NULL;
@ -4175,9 +4183,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
ASSERT(lm->ready);
// @fixme: use xatlas to UV pack all models, update their UV1 and upload them to GPU.
GLint cullface=0;
glGetIntegerv(GL_CULL_FACE, &cullface);
glDisable(GL_CULL_FACE);
model_lightmap_hook=1;
int w = lm->w, h = lm->h;
for (int i = 0; i < array_count(lm->models); i++) {
@ -4206,7 +4212,6 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, texcoord), sizeof(iqm_vertex),
m->num_tris*3, LM_UNSIGNED_INT, m->tris);
glDisable(GL_BLEND);
int vp[4];
float view[16], projection[16];
while (lmBegin(lm->ctx, vp, view, projection))
@ -4243,6 +4248,6 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
}
}
if (cullface) glEnable(GL_CULL_FACE);
model_lightmap_hook = 0;
}

View File

@ -17289,8 +17289,8 @@ bool renderstate_compare(const renderstate_t *stateA, const renderstate_t *state
void renderstate_apply(const renderstate_t *state) {
if (state != NULL) {
// Apply viewport parameters
glViewport(state->viewport_x, state->viewport_y, state->viewport_width, state->viewport_height);
// Apply viewport parameters @fixme
// glViewport(state->viewport_x, state->viewport_y, state->viewport_width, state->viewport_height);
// Apply clear color
glClearColor(state->clear_color[0], state->clear_color[1], state->clear_color[2], state->clear_color[3]);
@ -21143,6 +21143,8 @@ float model_animate(model_t m, float curframe) {
return model_animate_clip(m, curframe, 0, q->numframes-1, true);
}
static bool model_lightmap_hook = 0; //@fixme: delete this
static
void model_draw_call(model_t m, int shader) {
if(!m.iqm) return;
@ -21153,6 +21155,12 @@ void model_draw_call(model_t m, int shader) {
renderstate_apply(&m.rs);
//@fixme lightmap_bake state hook
if (model_lightmap_hook) {
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
}
glBindVertexArray( q->vao );
struct iqmtriangle *tris = NULL;
@ -21342,9 +21350,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
ASSERT(lm->ready);
// @fixme: use xatlas to UV pack all models, update their UV1 and upload them to GPU.
GLint cullface=0;
glGetIntegerv(GL_CULL_FACE, &cullface);
glDisable(GL_CULL_FACE);
model_lightmap_hook=1;
int w = lm->w, h = lm->h;
for (int i = 0; i < array_count(lm->models); i++) {
@ -21373,7 +21379,6 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
LM_FLOAT, (uint8_t*)m->verts + offsetof(iqm_vertex, texcoord), sizeof(iqm_vertex),
m->num_tris*3, LM_UNSIGNED_INT, m->tris);
glDisable(GL_BLEND);
int vp[4];
float view[16], projection[16];
while (lmBegin(lm->ctx, vp, view, projection))
@ -21410,7 +21415,7 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
}
}
if (cullface) glEnable(GL_CULL_FACE);
model_lightmap_hook = 0;
}
#line 0