Skip to content

Commit

Permalink
f shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
mardy committed Jan 15, 2025
1 parent 1b70349 commit da84fad
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/opengx.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ typedef void (*OgxSetupDrawCb)(GLuint shader, const OgxDrawData *draw_data,
void *user_data);
void ogx_shader_set_setup_draw_cb(GLuint shader,
OgxSetupDrawCb setup_draw, void *data);

/* These can be called from the setup_draw callback */
void ogx_shader_setup_attribute_array(int index, uint8_t gx_attr,
const OgxDrawData *draw_data);
void *ogx_shader_get_data(GLuint shader);

#ifdef __cplusplus
Expand Down
12 changes: 6 additions & 6 deletions src/shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,12 @@ void glVertexAttribPointer(GLuint index, GLint size, GLenum type,
OgxVertexAttribState *v = &s_state.vertex_attribs[index];
if (!v) return;

v->size = size;
v->type = type;
v->normalized = normalized;
assert(stride < (1 << (8 * sizeof(v->stride))));
v->stride = stride;
v->pointer = pointer;
v->array.size = size;
v->array.type = type;
v->array.normalized = normalized;
assert(stride < (1 << (8 * sizeof(v->array.stride))));
v->array.stride = stride;
v->array.pointer = pointer;
}

void ogx_shader_register_program_processor(const OgxProgramProcessor *processor)
Expand Down
24 changes: 11 additions & 13 deletions src/shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,21 @@ typedef struct {
OgxProgram *programs;

struct _OgxVertexAttribState {
/* Array-related fields (used when array_enabled is true) */
unsigned array_enabled : 1;
unsigned normalized : 1;
uint8_t stride;
GLenum type;
GLint size;
const void *pointer;

/* Data fields (used when array_enabled is false) */
union {
GLfloat vec4f[4];
GLuint vec4ui[4];
GLint vec4i[4];
} d;
/* Used when array_enabled is true: */
OgxVertexAttribArray array;

OgxVariable *bound_attribute;
} vertex_attribs[MAX_VERTEX_ATTRIBS];

/* Data fields (used when array_enabled is false). We keep these in a
* separate struct (well, union) so that we can use consecutive elements as
* matrix columns. */
union {
GLfloat vec4f[4];
GLuint vec4ui[4];
GLint vec4i[4];
} vertex_attrib_data[MAX_VERTEX_ATTRIBS];
} OgxShaderState;

typedef struct _OgxVertexAttribState OgxVertexAttribState;
Expand Down
3 changes: 2 additions & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ typedef float Norm3f[3];
typedef float Tex2f[2];

typedef struct _OgxVertexAttribArray {
uint8_t size; /* max is 4, using a bitfield might be an option */
unsigned normalized : 1;
unsigned size : 3; /* max is 4 */
uint8_t stride;
GLenum type;
const void *pointer;
Expand Down

0 comments on commit da84fad

Please sign in to comment.