Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader textures #100

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
80e03d8
getters: fix glGetBoolean for GL_UNPACK_LSB_FIRST and GL_PACK_SWAP_BYTES
mardy Jan 16, 2025
5e4a4c8
Move draw_arrays_general() function to avoid forward declaration
mardy Jan 3, 2025
4008a94
Store drawing parameters into a struct
mardy Jan 3, 2025
599200a
glArrayElement() can also be called outside glBegin/glEnd
mardy Jan 8, 2025
1049d12
glArrayElement(): the glVertex command must be issued last
mardy Jan 8, 2025
a6c0595
Fix reading of vertex components
mardy Jan 8, 2025
cf093f7
arrays: build vertex attributes readers at drawing time
mardy Jan 9, 2025
639aa52
Implement getters for vertex attribute arrays
mardy Jan 9, 2025
78571e7
functions: get ready to expose OpenGL 2.0 functions
mardy Jan 6, 2025
153e480
getters: set GL_VERSION to 2.0 if glUseProgram is available
mardy Jan 6, 2025
a9b5052
lighting: move computation of color channels count to new function
mardy Jan 12, 2025
9fa885a
Add ogx_set_projection() function
mardy Jan 6, 2025
097be65
Refactor array readers API
mardy Jan 14, 2025
b4d0b5a
arrays: remove attribute readers from the global state
mardy Jan 18, 2025
8308d30
arrays: store readers into an array
mardy Jan 18, 2025
93259d1
Add murmurhash3 hashing functions
mardy Jan 20, 2025
40defed
include: update glext file with latest from Mesa
mardy Jan 23, 2025
ae8fded
Add support for OpenGL 2.0
mardy Jan 1, 2025
d08303c
examples: add OPenGL 2.0 example with SDL2
mardy Jan 21, 2025
44dc385
build: add src/ directory to library include directories
mardy Jan 23, 2025
a8ba386
examples: make the gl2gears example work with opengx
mardy Jan 23, 2025
25b8d89
examples: add joystick support to gl2gears
mardy Jan 23, 2025
6b3454e
arrays: store VBO at array definition time
mardy Jan 27, 2025
0cf188c
examples: add OpenGL 2.0 texturing example
mardy Jan 27, 2025
5b75eb2
arrays: support constant arrays with color data
mardy Jan 27, 2025
707d695
shader: support retrieving data from GL_SAMPLER_* uniforms
mardy Jan 27, 2025
d667dcb
shader: add a public API for retrieving the GXTexObj
mardy Jan 27, 2025
5f3205d
examples: make the cube_tex example work on the console
mardy Jan 27, 2025
defe5d1
shaders: rename public APIs for matrix management
mardy Feb 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor array readers API
Part of this API will be made public in some later commit to allow
it to be used by developers writing shader replacements. For this goal,
a more flexible API is introduced, where vertex attribute arrays can be
added from a OgxVertexAttribArray structure provided by the client.
  • Loading branch information
mardy committed Jan 17, 2025
commit 097be65cf2dc87c7a25a75130e65105a2ac708e6
767 changes: 457 additions & 310 deletions src/arrays.cpp

Large diffs are not rendered by default.

45 changes: 32 additions & 13 deletions src/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,16 @@ typedef struct {
uint32_t reader[6];
} OgxArrayReader;

void _ogx_array_reader_init(OgxArrayReader *reader,
uint8_t vertex_attribute,
const OgxVertexAttribArray *attr_data);
void _ogx_arrays_setup_draw(const OgxDrawData *draw_data,
bool has_normals, uint8_t num_colors,
uint8_t tex_unit_mask);
/* Get the mask of units having texture coordinates. This is not necessarily
* the same as glparamstate.cs.texcoord_enabled, because we might have
* generated more arrays via software if the mode is not supported by the
* hardware (GL_SPHERE_MAP) */
uint8_t _ogx_arrays_get_units_with_tex_coord();
typedef enum {
OGX_DRAW_FLAG_NONE = 0,
OGX_DRAW_FLAG_FLAT = 1 << 0,
} OgxDrawFlags;

void _ogx_arrays_setup_draw(const OgxDrawData *draw_data, OgxDrawFlags flags);

void _ogx_arrays_process_element(int index);
/* Any memory allocated by the OgxArrayReader objects can be released. */
void _ogx_arrays_draw_done();
void _ogx_array_reader_enable_dup_color(OgxArrayReader *reader,
bool dup_color);
void _ogx_array_reader_process_element(OgxArrayReader *reader, int index);
uint8_t _ogx_array_reader_get_tex_coord_source(OgxArrayReader *reader);

Expand All @@ -75,6 +69,31 @@ void _ogx_array_reader_read_tex2f(OgxArrayReader *reader,
void _ogx_array_reader_read_color(OgxArrayReader *reader,
int index, GXColor *color);

void _ogx_arrays_reset(void);
OgxArrayReader *_ogx_array_add_constant_fv(uint8_t attribute, int size,
const float *values);
OgxArrayReader *_ogx_array_add(uint8_t attribute,
const OgxVertexAttribArray *array);

typedef void (*OgxGenerator_fv)(int index, float *values_out);
OgxArrayReader *_ogx_array_add_generator_fv(uint8_t attribute, int size,
OgxGenerator_fv generator);

/* Enumerate active array readers. Start by passing NULL, then pass the reader
* obtained from the previous call, until this returns NULL.
*/
OgxArrayReader *_ogx_array_reader_next(OgxArrayReader *reader);

/* This returns the libogc constants describing the vertex format:
* - attribute: libogc's vtxattr
* - inputmode: libogc's vtxattrin
* - type: libogc's comptype
* - size: libogc's comptype
*/
void _ogx_array_reader_get_format(OgxArrayReader *reader,
uint8_t *attribute, uint8_t *inputmode,
uint8_t *type, uint8_t *size);

#ifdef __cplusplus
} // extern C
#endif
Expand Down
53 changes: 42 additions & 11 deletions src/call_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ typedef struct
union client_state cs;
u32 list_size;
void *gxlist;
struct AttribFormat {
unsigned attribute : 5;
/* Most of these only require 2-3 bits, but let's round it */
unsigned inputmode : 3;
unsigned comptype : 4;
unsigned compsize : 4;
} formats[4 + MAX_TEXTURE_UNITS]; /* 4: pos, norm, clr1 and clr2 */
#define CALL_LIST_DRAW_FORMATS(fmt) (sizeof(fmt) / sizeof(fmt[0]))
} draw_geometry;

float color[4];
Expand Down Expand Up @@ -231,12 +239,20 @@ static void setup_draw_geometry(struct DrawGeometry *dg,
dg->count,
/* The remaining fields are not used when drawing through lists */
};
_ogx_arrays_setup_draw(&draw_data,
dg->cs.normal_enabled,
dg->cs.color_enabled ? 2 : 0,
dg->cs.texcoord_enabled);
/* Setup the same vertex attribute descriptions that were in place when the
* list was created */
GX_ClearVtxDesc();
for (int i = 0; i < CALL_LIST_DRAW_FORMATS(dg->formats); i++) {
if (dg->formats[i].inputmode == GX_NONE) continue;
uint8_t attribute = dg->formats[i].attribute;
GX_SetVtxDesc(attribute, dg->formats[i].inputmode);
GX_SetVtxAttrFmt(GX_VTXFMT0, attribute,
dg->formats[i].comptype, dg->formats[i].compsize, 0);
}

if (!dg->cs.normal_enabled) {
GX_SetVtxDesc(GX_VA_NRM, GX_INDEX8);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
GX_SetArray(GX_VA_NRM, s_current_normal, 12);
floatcpy(s_current_normal, glparamstate.imm_mode.current_normal, 3);
/* Not needed on Dolphin, but it is on a Wii */
Expand All @@ -245,6 +261,8 @@ static void setup_draw_geometry(struct DrawGeometry *dg,
if (!dg->cs.color_enabled) {
GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8);
GX_SetVtxDesc(GX_VA_CLR1, GX_INDEX8);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGB8, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR1, GX_CLR_RGBA, GX_RGB8, 0);
s_current_color = current_color;
GX_SetArray(GX_VA_CLR0, &s_current_color, 4);
GX_SetArray(GX_VA_CLR1, &s_current_color, 4);
Expand Down Expand Up @@ -434,10 +452,21 @@ static void queue_draw_geometry(struct DrawGeometry *dg,
dg->count = count + gxmode.loop;

if (glparamstate.dirty.bits.dirty_attributes)
_ogx_update_vertex_array_readers();

if (dg->cs.color_enabled) {
_ogx_array_reader_enable_dup_color(&glparamstate.color_reader, true);
_ogx_update_vertex_array_readers(gxmode);

/* Get the GX formats used right now */
OgxArrayReader *reader = NULL;
int format_index = 0;
memset(dg->formats, 0, sizeof(dg->formats));
while (reader = _ogx_array_reader_next(reader)) {
uint8_t attribute, inputmode, size, type;
_ogx_array_reader_get_format(reader, &attribute, &inputmode,
&type, &size);
dg->formats[format_index].attribute = attribute;
dg->formats[format_index].inputmode = inputmode;
dg->formats[format_index].comptype = type;
dg->formats[format_index].compsize = size;
format_index++;
}

GX_BeginDispList(dg->gxlist, MAX_GXLIST_SIZE);
Expand All @@ -456,11 +485,13 @@ static void queue_draw_geometry(struct DrawGeometry *dg,
GX_Normal1x8(0);
}

/* The color data is duplicated to CLR0 and CLR1 */
if (dg->cs.color_enabled) {
_ogx_array_reader_process_element(&glparamstate.color_reader, index);
_ogx_array_reader_process_element(&glparamstate.color_reader[0], index);
_ogx_array_reader_process_element(&glparamstate.color_reader[0], index);
} else {
GX_Color1x8(0); // CLR0
GX_Color1x8(0); // CLR1
GX_Color1x8(0);
GX_Color1x8(0);
}

for (int tex = 0; tex < MAX_TEXTURE_UNITS; tex++) {
Expand Down
Loading