Skip to content

Commit

Permalink
lighting: move computation of color channels count to new function
Browse files Browse the repository at this point in the history
We might be using this in more places.
  • Loading branch information
mardy committed Jan 14, 2025
1 parent f7ded0b commit ab9764c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/gc_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,19 @@ static LightMasks prepare_lighting()
return masks;
}

static int count_color_channels()
{
int color_provide = 0;
if (glparamstate.cs.color_enabled &&
(!glparamstate.lighting.enabled || glparamstate.lighting.color_material_enabled)) { // Vertex colouring
if (glparamstate.lighting.enabled)
color_provide = 2; // Lighting requires two color channels
else
color_provide = 1;
}
return color_provide;
}

void _ogx_update_vertex_array_readers()
{
if (glparamstate.cs.vertex_enabled) {
Expand Down Expand Up @@ -2538,14 +2551,7 @@ static bool setup_draw(const OgxDrawData *draw_data)

if (!glparamstate.current_program) {
uint8_t texen = glparamstate.texture_enabled;
uint8_t color_provide = 0;
if (glparamstate.cs.color_enabled &&
(!glparamstate.lighting.enabled || glparamstate.lighting.color_material_enabled)) { // Vertex colouring
if (glparamstate.lighting.enabled)
color_provide = 2; // Lighting requires two color channels
else
color_provide = 1;
}
uint8_t color_provide = count_color_channels();
_ogx_arrays_setup_draw(draw_data,
glparamstate.cs.normal_enabled, color_provide, texen);

Expand Down

0 comments on commit ab9764c

Please sign in to comment.