Skip to content

Commit

Permalink
arrays: add one more function to reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
mardy committed Nov 14, 2024
1 parent 61d639e commit a46b37a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
29 changes: 29 additions & 0 deletions src/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include <variant>

static char s_num_tex_arrays = 0;
static bool s_has_normals = false;
static uint8_t s_num_colors = 0;
static uint8_t s_tex_unit_mask = 0;

struct GxVertexFormat {
uint8_t attribute;
Expand Down Expand Up @@ -465,6 +468,32 @@ void _ogx_arrays_setup_draw(bool has_normals, uint8_t num_colors,
}
}
}

s_has_normals = has_normals;
s_num_colors = num_colors;
s_tex_unit_mask = tex_unit_mask;
}

void _ogx_arrays_process_element(int index)
{
get_reader(&glparamstate.vertex_array)->process_element(index);

if (s_has_normals) {
get_reader(&glparamstate.normal_array)->process_element(index);
}

if (s_num_colors) {
get_reader(&glparamstate.color_array)->process_element(index);
}

if (s_tex_unit_mask) {
for (int i = 0; i < MAX_TEXTURE_UNITS; i++) {
if (s_tex_unit_mask & (1 << i)) {
get_reader(&glparamstate.texcoord_array[i])->
process_element(index);
}
}
}
}

void _ogx_array_reader_enable_dup_color(OgxArrayReader *reader,
Expand Down
1 change: 1 addition & 0 deletions src/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void _ogx_array_reader_init(OgxArrayReader *reader,
int num_components, GLenum type, int stride);
void _ogx_arrays_setup_draw(bool has_normals, uint8_t num_colors,
uint8_t tex_unit_mask);
void _ogx_arrays_process_element(int index);
void _ogx_array_reader_enable_dup_color(OgxArrayReader *reader,
bool dup_color);
void _ogx_array_reader_process_element(OgxArrayReader *reader, int index);
Expand Down
34 changes: 2 additions & 32 deletions src/gc_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2310,22 +2310,7 @@ static void draw_elements_general(DrawMode gxmode, int count, GLenum type,
GX_Begin(gxmode.mode, GX_VTXFMT0, count + loop);
for (int i = 0; i < count + loop; i++) {
int index = read_index(indices, type, i % count);
_ogx_array_reader_process_element(&glparamstate.vertex_array, index);

if (ne) {
_ogx_array_reader_process_element(&glparamstate.normal_array, index);
}

if (color_provide) {
_ogx_array_reader_process_element(&glparamstate.color_array, index);
}

for (int tex = 0; tex < MAX_TEXTURE_UNITS; tex++) {
if (texen & (1 << tex)) {
_ogx_array_reader_process_element(
&glparamstate.texcoord_array[tex], index);
}
}
_ogx_arrays_process_element(index);
}
GX_End();
}
Expand Down Expand Up @@ -2487,22 +2472,7 @@ static void draw_arrays_general(DrawMode gxmode, int first, int count, int ne,
int i;
for (i = 0; i < count + loop; i++) {
int j = i % count + first;
_ogx_array_reader_process_element(&glparamstate.vertex_array, j);

if (ne) {
_ogx_array_reader_process_element(&glparamstate.normal_array, j);
}

if (color_provide) {
_ogx_array_reader_process_element(&glparamstate.color_array, j);
}

for (int tex = 0; tex < MAX_TEXTURE_UNITS; tex++) {
if (texen & (1 << tex)) {
_ogx_array_reader_process_element(
&glparamstate.texcoord_array[tex], j);
}
}
_ogx_arrays_process_element(j);
}
GX_End();
}
Expand Down

0 comments on commit a46b37a

Please sign in to comment.