From ab9764ce228916644cdd33216b635284008f28a4 Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Sun, 12 Jan 2025 14:20:00 +0300 Subject: [PATCH] lighting: move computation of color channels count to new function We might be using this in more places. --- src/gc_gl.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/gc_gl.c b/src/gc_gl.c index 6b0258d..4e3f336 100644 --- a/src/gc_gl.c +++ b/src/gc_gl.c @@ -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) { @@ -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);