|
@@ -8,15 +8,17 @@
|
|
|
#define SR_MAX_ATTRIBUTE_COUNT 32
|
|
|
#define SR_MAX_LIGHT_COUNT 8
|
|
|
|
|
|
-#define SR_CLIP_LEFT_PLANE 1 << 0
|
|
|
-#define SR_CLIP_BOTTOM_PLANE 1 << 1
|
|
|
-#define SR_CLIP_NEAR_PLANE 1 << 2
|
|
|
-#define SR_CLIP_RIGHT_PLANE 1 << 3
|
|
|
-#define SR_CLIP_TOP_PLANE 1 << 4
|
|
|
-
|
|
|
#define SR_WINDING_ORDER_CCW 1
|
|
|
#define SR_WINDING_ORDER_CW -1
|
|
|
|
|
|
+enum sr_clip_plane {
|
|
|
+ SR_CLIP_LEFT_PLANE = 1 << 0,
|
|
|
+ SR_CLIP_BOTTOM_PLANE = 1 << 1,
|
|
|
+ SR_CLIP_NEAR_PLANE = 1 << 2,
|
|
|
+ SR_CLIP_RIGHT_PLANE = 1 << 3,
|
|
|
+ SR_CLIP_TOP_PLANE = 1 << 4
|
|
|
+};
|
|
|
+
|
|
|
enum sr_primitive {
|
|
|
SR_POINT_LIST,
|
|
|
SR_LINE_LIST,
|
|
@@ -33,14 +35,14 @@ enum sr_matrix_mode {
|
|
|
};
|
|
|
|
|
|
enum sr_light {
|
|
|
- SR_LIGHT_1,
|
|
|
- SR_LIGHT_2,
|
|
|
- SR_LIGHT_3,
|
|
|
- SR_LIGHT_4,
|
|
|
- SR_LIGHT_5,
|
|
|
- SR_LIGHT_6,
|
|
|
- SR_LIGHT_7,
|
|
|
- SR_LIGHT_8,
|
|
|
+ SR_LIGHT_1 = 0,
|
|
|
+ SR_LIGHT_2 = 1,
|
|
|
+ SR_LIGHT_3 = 2,
|
|
|
+ SR_LIGHT_4 = 3,
|
|
|
+ SR_LIGHT_5 = 4,
|
|
|
+ SR_LIGHT_6 = 5,
|
|
|
+ SR_LIGHT_7 = 6,
|
|
|
+ SR_LIGHT_8 = 7,
|
|
|
};
|
|
|
|
|
|
enum sr_light_attr {
|
|
@@ -75,75 +77,12 @@ enum sr_light_type {
|
|
|
typedef void (*vs_f)(float* out, float* in, void* uniform);
|
|
|
typedef void (*fs_f)(uint32_t* out, float* in, void* uniform);
|
|
|
|
|
|
-/*********************************************************************
|
|
|
- * *
|
|
|
- * public data structures *
|
|
|
- * *
|
|
|
- *********************************************************************/
|
|
|
-
|
|
|
-/*********
|
|
|
- * light *
|
|
|
- *********/
|
|
|
-
|
|
|
-/* holds light data */
|
|
|
-struct light {
|
|
|
- uint8_t type;
|
|
|
- float pos[3];
|
|
|
- float color[4];
|
|
|
-
|
|
|
- float dir[3];
|
|
|
- float spot_angle;
|
|
|
- float spot_penumbra;
|
|
|
-
|
|
|
- float attn_const;
|
|
|
- float attn_lin;
|
|
|
- float attn_quad;
|
|
|
-};
|
|
|
-
|
|
|
-/************
|
|
|
- * material *
|
|
|
- ************/
|
|
|
-
|
|
|
-struct material {
|
|
|
- float ambient[4];
|
|
|
- float diffuse[4];
|
|
|
- float specular[4];
|
|
|
- float blend;
|
|
|
- float shininess;
|
|
|
-};
|
|
|
-
|
|
|
-/**************
|
|
|
- * sr_uniform *
|
|
|
- **************/
|
|
|
-
|
|
|
-/* the uniform variables for the fixed lib shaders */
|
|
|
-struct sr_uniform {
|
|
|
-
|
|
|
- /* geometry */
|
|
|
- struct mat4* model;
|
|
|
- struct mat4* normal_transform;
|
|
|
- struct mat4* mvp;
|
|
|
- float cam_pos[3];
|
|
|
-
|
|
|
- /* material */
|
|
|
- int has_texture;
|
|
|
- struct material* material;
|
|
|
- struct sr_texture* texture;
|
|
|
-
|
|
|
- /* light */
|
|
|
- uint8_t light_state;
|
|
|
- struct light* lights;
|
|
|
- float ka;
|
|
|
- float kd;
|
|
|
- float ks;
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
/******************
|
|
|
* sr_framebuffer *
|
|
|
******************/
|
|
|
|
|
|
/* interface to whatever writes to the screen */
|
|
|
+
|
|
|
struct sr_framebuffer {
|
|
|
uint32_t* colors;
|
|
|
float* depths;
|
|
@@ -160,34 +99,19 @@ struct sr_framebuffer {
|
|
|
* memory required to render an indexed list of
|
|
|
* arbitrary length
|
|
|
*/
|
|
|
+
|
|
|
struct sr_pipeline {
|
|
|
struct sr_framebuffer* fbuf;
|
|
|
void* uniform;
|
|
|
vs_f vs;
|
|
|
fs_f fs;
|
|
|
-
|
|
|
float* pts_in;
|
|
|
int n_pts;
|
|
|
int n_attr_in;
|
|
|
int n_attr_out;
|
|
|
-
|
|
|
int winding;
|
|
|
};
|
|
|
|
|
|
-/*********************************************************************
|
|
|
- * *
|
|
|
- * file input *
|
|
|
- * *
|
|
|
- *********************************************************************/
|
|
|
-
|
|
|
-
|
|
|
-/*********************************************************************
|
|
|
- * *
|
|
|
- * struct helpers *
|
|
|
- * *
|
|
|
- *********************************************************************/
|
|
|
-
|
|
|
-
|
|
|
/*********************************************************************
|
|
|
* *
|
|
|
* render pipeline *
|
|
@@ -196,38 +120,15 @@ struct sr_pipeline {
|
|
|
|
|
|
/* render interface */
|
|
|
|
|
|
-extern void
|
|
|
-sr_bind_pts(float* pts, int n_pts, int n_attr);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_bind_framebuffer(int width, int height, uint32_t* colors, float* depths);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_bind_vs(vs_f vs, int n_attr_out);
|
|
|
-
|
|
|
-/* WARNING can't use matrix stack, default shaders, or lights if called */
|
|
|
-extern void
|
|
|
-sr_bind_uniform(void* uniform);
|
|
|
-
|
|
|
-/* restores default uniform if sr_bind_uniform was called */
|
|
|
-extern void
|
|
|
-sr_restore_uniform();
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_bind_fs(fs_f fs);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_bind_texture(uint32_t* colors, int width, int height);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_bind_base_color(float r, float g, float b);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_renderl(int* indices, int n_indices, enum sr_primitive prim_type);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_render(struct sr_pipeline* pipe, int* indices,
|
|
|
- int n_indices, enum sr_primitive prim_type);
|
|
|
+void sr_bind_vertices(float* pts, int n_pts, int n_attr);
|
|
|
+void sr_bind_framebuffer(int width, int height, uint32_t* colors, float* depths);
|
|
|
+void sr_bind_uniform(void* uniform);
|
|
|
+void sr_restore_uniform();
|
|
|
+void sr_bind_texture(uint32_t* colors, int width, int height);
|
|
|
+void sr_bind_base_color(float r, float g, float b);
|
|
|
+void sr_renderl(int* indices, int n_indices, enum sr_primitive prim_type);
|
|
|
+void sr_render(struct sr_pipeline* pipe, int* indices,
|
|
|
+ int n_indices, enum sr_primitive prim_type);
|
|
|
|
|
|
/*********************************************************************
|
|
|
* *
|
|
@@ -235,23 +136,12 @@ sr_render(struct sr_pipeline* pipe, int* indices,
|
|
|
* *
|
|
|
*********************************************************************/
|
|
|
|
|
|
-extern void
|
|
|
-sr_light(enum sr_light slot, enum sr_light_attr attr, float* data);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_glight(enum sr_light_attr attr, float* data);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_light_type(enum sr_light slot, enum sr_light_type type);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_light_enable(enum sr_light slot);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_light_disable(enum sr_light slot);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_material(enum sr_light_attr attr, float* data);
|
|
|
+void sr_light(enum sr_light slot, enum sr_light_attr attr, float* data);
|
|
|
+void sr_glight(enum sr_light_attr attr, float* data);
|
|
|
+void sr_light_type(enum sr_light slot, enum sr_light_type type);
|
|
|
+void sr_light_enable(enum sr_light slot);
|
|
|
+void sr_light_disable(enum sr_light slot);
|
|
|
+void sr_material(enum sr_light_attr attr, float* data);
|
|
|
|
|
|
/*********************************************************************
|
|
|
* *
|
|
@@ -259,44 +149,21 @@ sr_material(enum sr_light_attr attr, float* data);
|
|
|
* *
|
|
|
*********************************************************************/
|
|
|
|
|
|
-extern void
|
|
|
-sr_matrix_mode(enum sr_matrix_mode mode);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_dump_matrix(float* dest);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_load_matrix(float* src);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_load_identity();
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_perspective(float fovy, float aspect, float near, float far);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_frustum(float left, float right, float bottom,
|
|
|
- float top, float near, float far);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_translate(float x, float y, float z);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_rotate_x(float t);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_rotate_y(float t);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_rotate_z(float t);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_scale(float sx, float sy, float sz);
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_look_at(float ex, float ey, float ez,
|
|
|
- float cx, float cy, float cz,
|
|
|
- float ux, float uy, float uz);
|
|
|
+void sr_matrix_mode(enum sr_matrix_mode mode);
|
|
|
+void sr_dump_matrix(float* dest);
|
|
|
+void sr_load_matrix(float* src);
|
|
|
+void sr_load_identity();
|
|
|
+void sr_perspective(float fovy, float aspect, float near, float far);
|
|
|
+void sr_frustum(float left, float right, float bottom,
|
|
|
+ float top, float near, float far);
|
|
|
+void sr_translate(float x, float y, float z);
|
|
|
+void sr_rotate_x(float t);
|
|
|
+void sr_rotate_y(float t);
|
|
|
+void sr_rotate_z(float t);
|
|
|
+void sr_scale(float sx, float sy, float sz);
|
|
|
+void sr_look_at(float ex, float ey, float ez,
|
|
|
+ float cx, float cy, float cz,
|
|
|
+ float ux, float uy, float uz);
|
|
|
|
|
|
/*********************************************************************
|
|
|
* *
|
|
@@ -304,22 +171,13 @@ sr_look_at(float ex, float ey, float ez,
|
|
|
* *
|
|
|
*********************************************************************/
|
|
|
|
|
|
-extern void
|
|
|
-sr_bind_color_vs();
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_bind_color_fs();
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_bind_texture_vs();
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_bind_texture_fs();
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_bind_std_vs();
|
|
|
-
|
|
|
-extern void
|
|
|
-sr_bind_phong_fs();
|
|
|
+void sr_bind_custom_vs(vs_f vs, int n_attr_out);
|
|
|
+void sr_bind_custom_fs(fs_f fs);
|
|
|
+void sr_bind_color_vs();
|
|
|
+void sr_bind_color_fs();
|
|
|
+void sr_bind_texture_vs();
|
|
|
+void sr_bind_texture_fs();
|
|
|
+void sr_bind_std_vs();
|
|
|
+void sr_bind_phong_fs();
|
|
|
|
|
|
#endif /* SR_H */
|