improve tex unit allocation

main
Dominik Madarász 2024-03-21 07:43:51 +01:00
parent c8a6c79bf1
commit fad3653201
5 changed files with 111 additions and 100 deletions

View File

@ -39,6 +39,7 @@ int main() {
model_t m2 = model("suzanne.obj", MODEL_NO_ANIMATIONS|MODEL_MATCAPS);
// model_t m3 = model("damagedhelmet.gltf", MODEL_NO_ANIMATIONS|MODEL_PBR);
model_t m3 = model("Scutum_low.fbx", MODEL_NO_ANIMATIONS|MODEL_PBR);
// model_t m4 = model("avp/scene.gltf", MODEL_NO_ANIMATIONS|MODEL_PBR);
// model_t m3 = model("Cerberus_LP.FBX", MODEL_NO_ANIMATIONS|MODEL_PBR);
// spawn object1 (diffuse)
@ -72,6 +73,13 @@ int main() {
object_move(obj4, vec3(-10+6*3,0,-10));
object_pivot(obj4, vec3(0,0,90));
// spawn object5 (pbr)
// object_t* obj5 = scene_spawn();
// object_model(obj5, m4);
// object_scale(obj5, vec3(3,3,3));
// object_move(obj5, vec3(-10+6*3,0,-10));
// object_pivot(obj5, vec3(0,0,90));
// create point light
scene_spawn_light(); // sun
light_t* l = scene_spawn_light();

View File

@ -26,7 +26,7 @@ int main()
camera_t cam = camera();
skybox_t sky = skybox(0, 0); skybox_mie_calc_sh(&sky, 2.0f);
model_t mdl = model(option("--model","gazebo.obj"), 0);
litm = model("cube.obj", MODEL_MATCAPS);
litm = model("cube.obj", 0);
{
mat44 lp; scaling44(lp, 0.3, 0.3, 0.3); translate44(lp, 8,4,0);
copy44(litm.pivot, lp);

View File

@ -370072,7 +370072,7 @@ void glDebugEnable() {
static
void glCopyBackbufferToTexture( texture_t *tex ) { // unused
glActiveTexture( GL_TEXTURE0 + tex->unit );
glActiveTexture( GL_TEXTURE0 + allocate_texture_unit() );
glBindTexture( GL_TEXTURE_2D, tex->id );
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, window_width(), window_height(), 0 );
}
@ -373755,6 +373755,9 @@ void model_draw_call(model_t m, int shader) {
if(!m.iqm) return;
iqm_t *q = m.iqm;
handle old_shader = last_shader;
shader_bind(shader);
glBindVertexArray( q->vao );
struct iqmtriangle *tris = NULL;
@ -373762,9 +373765,8 @@ void model_draw_call(model_t m, int shader) {
struct iqmmesh *im = &q->meshes[i];
if (m.shading != SHADING_PBR) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, q->textures[i] );
glUniform1i(glGetUniformLocation(shader, "u_texture2d"), allocate_texture_unit() );
shader_texture_unit("u_texture2d", q->textures[i], allocate_texture_unit());
shader_texture("u_lightmap", m.lightmap);
int loc;
if ((loc = glGetUniformLocation(shader, "u_textured")) >= 0) {
@ -373775,9 +373777,6 @@ void model_draw_call(model_t m, int shader) {
}
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m.lightmap.id);
glUniform1i(glGetUniformLocation(shader, "u_lightmap"), allocate_texture_unit() );
} else {
const pbr_material_t *material = &m.pbr_materials[i];
shader_colormap( "map_diffuse", material->diffuse );
@ -373798,6 +373797,8 @@ void model_draw_call(model_t m, int shader) {
}
glBindVertexArray( 0 );
shader_bind(old_shader);
}
void model_render_instanced(model_t m, mat44 proj, mat44 view, mat44* models, int shader, unsigned count) {

View File

@ -45,7 +45,7 @@ void glDebugEnable() {
static
void glCopyBackbufferToTexture( texture_t *tex ) { // unused
glActiveTexture( GL_TEXTURE0 + tex->unit );
glActiveTexture( GL_TEXTURE0 + allocate_texture_unit() );
glBindTexture( GL_TEXTURE_2D, tex->id );
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, window_width(), window_height(), 0 );
}
@ -3728,6 +3728,9 @@ void model_draw_call(model_t m, int shader) {
if(!m.iqm) return;
iqm_t *q = m.iqm;
handle old_shader = last_shader;
shader_bind(shader);
glBindVertexArray( q->vao );
struct iqmtriangle *tris = NULL;
@ -3735,9 +3738,8 @@ void model_draw_call(model_t m, int shader) {
struct iqmmesh *im = &q->meshes[i];
if (m.shading != SHADING_PBR) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, q->textures[i] );
glUniform1i(glGetUniformLocation(shader, "u_texture2d"), allocate_texture_unit() );
shader_texture_unit("u_texture2d", q->textures[i], allocate_texture_unit());
shader_texture("u_lightmap", m.lightmap);
int loc;
if ((loc = glGetUniformLocation(shader, "u_textured")) >= 0) {
@ -3748,9 +3750,6 @@ void model_draw_call(model_t m, int shader) {
}
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m.lightmap.id);
glUniform1i(glGetUniformLocation(shader, "u_lightmap"), allocate_texture_unit() );
} else {
const pbr_material_t *material = &m.pbr_materials[i];
shader_colormap( "map_diffuse", material->diffuse );
@ -3771,6 +3770,8 @@ void model_draw_call(model_t m, int shader) {
}
glBindVertexArray( 0 );
shader_bind(old_shader);
}
void model_render_instanced(model_t m, mat44 proj, mat44 view, mat44* models, int shader, unsigned count) {

View File

@ -17219,7 +17219,7 @@ void glDebugEnable() {
static
void glCopyBackbufferToTexture( texture_t *tex ) { // unused
glActiveTexture( GL_TEXTURE0 + tex->unit );
glActiveTexture( GL_TEXTURE0 + allocate_texture_unit() );
glBindTexture( GL_TEXTURE_2D, tex->id );
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, window_width(), window_height(), 0 );
}
@ -20902,6 +20902,9 @@ void model_draw_call(model_t m, int shader) {
if(!m.iqm) return;
iqm_t *q = m.iqm;
handle old_shader = last_shader;
shader_bind(shader);
glBindVertexArray( q->vao );
struct iqmtriangle *tris = NULL;
@ -20909,9 +20912,8 @@ void model_draw_call(model_t m, int shader) {
struct iqmmesh *im = &q->meshes[i];
if (m.shading != SHADING_PBR) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, q->textures[i] );
glUniform1i(glGetUniformLocation(shader, "u_texture2d"), allocate_texture_unit() );
shader_texture_unit("u_texture2d", q->textures[i], allocate_texture_unit());
shader_texture("u_lightmap", m.lightmap);
int loc;
if ((loc = glGetUniformLocation(shader, "u_textured")) >= 0) {
@ -20922,9 +20924,6 @@ void model_draw_call(model_t m, int shader) {
}
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m.lightmap.id);
glUniform1i(glGetUniformLocation(shader, "u_lightmap"), allocate_texture_unit() );
} else {
const pbr_material_t *material = &m.pbr_materials[i];
shader_colormap( "map_diffuse", material->diffuse );
@ -20945,6 +20944,8 @@ void model_draw_call(model_t m, int shader) {
}
glBindVertexArray( 0 );
shader_bind(old_shader);
}
void model_render_instanced(model_t m, mat44 proj, mat44 view, mat44* models, int shader, unsigned count) {