Permalink
Browse files

Renderers demo now generally working

  • Loading branch information...
1 parent da3d8e7 commit 8182997a4adf01d2ec68402d410592407fbd789c @orangeduck committed Aug 19, 2012
View
BIN corange.dll
Binary file not shown.
View
BIN corange.res
Binary file not shown.
View
BIN demos/renderers/corange.dll
Binary file not shown.
View
BIN demos/renderers/renderers.exe
Binary file not shown.
View
8 demos/renderers/src/renderers.c
@@ -152,7 +152,7 @@ void renderers_init() {
SDL_GL_CheckError();
- asset_hndl r_imrod = asset_hndl_new(P("./resources/imrod/imrod.obj"));
+ asset_hndl r_imrod = asset_hndl_new(P("./resources/imrod/imrod.smd"));
((renderable*)asset_hndl_ptr(r_imrod))->material = asset_hndl_new(P("./resources/imrod/imrod_animated.mat"));
animated_object* a_imrod = entity_new("imrod", animated_object);
@@ -446,16 +446,22 @@ void renderers_render() {
shadow_mapper_begin();
shadow_mapper_render_static(s_podium);
+ SDL_GL_CheckError();
if (object_id == 0) {
shadow_mapper_render_static(s_cello);
+ SDL_GL_CheckError();
} else if (object_id == 1) {
shadow_mapper_render_static(s_piano);
+ SDL_GL_CheckError();
} else if (object_id == 2) {
shadow_mapper_render_animated(a_imrod);
+ SDL_GL_CheckError();
} else if (object_id == 3) {
shadow_mapper_render_static(s_dino);
+ SDL_GL_CheckError();
}
shadow_mapper_end();
+ SDL_GL_CheckError();
if (use_deferred) {
View
3 include/assets/renderable.h
@@ -15,8 +15,6 @@ typedef struct {
int num_verticies;
int num_triangles;
-
- bool is_rigged;
} renderable_surface;
renderable_surface* renderable_surface_new(mesh* m);
@@ -26,6 +24,7 @@ void renderable_surface_delete(renderable_surface* surface);
typedef struct {
renderable_surface** surfaces;
int num_surfaces;
+ bool is_rigged;
asset_hndl material;
} renderable;
View
23 src/assets/renderable.c
@@ -28,6 +28,7 @@ renderable* renderable_new() {
r->material = asset_hndl_new_load(P("$CORANGE/shaders/basic.mat"));
r->num_surfaces = 0;
r->surfaces = NULL;
+ r->is_rigged = false;
return r;
@@ -44,7 +45,11 @@ void renderable_delete(renderable* r) {
}
model* renderable_to_model(renderable* r) {
-
+
+ if (r->is_rigged) {
+ error("Cannot convert rigged renderable to model");
+ }
+
model* m = model_new();
m->num_meshes = r->num_surfaces;
@@ -54,10 +59,6 @@ model* renderable_to_model(renderable* r) {
renderable_surface* s = r->surfaces[i];
- if (s->is_rigged) {
- error("Cannot convert rigged renderable to model");
- }
-
float* vb_data = malloc(sizeof(float) * s->num_verticies * 18);
int* ib_data = malloc(sizeof(int) * s->num_triangles * 3);
@@ -121,7 +122,6 @@ renderable_surface* renderable_surface_new(mesh* m) {
glGenBuffers(1, &s->vertex_vbo);
glGenBuffers(1, &s->triangle_vbo);
- s->is_rigged = false;
s->num_verticies = m->num_verts;
s->num_triangles = m->num_triangles;
@@ -185,7 +185,6 @@ renderable_surface* renderable_surface_new_rigged(mesh* m, vertex_weight* weight
glGenBuffers(1, &s->vertex_vbo);
glGenBuffers(1, &s->triangle_vbo);
- s->is_rigged = true;
s->num_verticies = m->num_verts;
s->num_triangles = m->num_triangles;
@@ -263,6 +262,7 @@ renderable* bmf_load_file(char* filename) {
renderable* r = malloc(sizeof(renderable));
r->material = asset_hndl_new(P("$CORANGE/resources/basic.mat"));
+ r->is_rigged = false;
SDL_RWops* file = SDL_RWFromFile(filename, "rb");
@@ -291,8 +291,6 @@ renderable* bmf_load_file(char* filename) {
for(int i = 0; i < r->num_surfaces; i++) {
renderable_surface* s = malloc(sizeof(renderable_surface));
- s->is_rigged = false;
-
SDL_RWread(file, &s->num_verticies, 4, 1);
float* vert_data = malloc(sizeof(float) * 18 * s->num_verticies);
@@ -886,15 +884,16 @@ renderable* smd_load_file(char* filename) {
mesh_generate_tangents(smd_mesh);
- renderable* renderable = renderable_new();
- renderable_add_mesh_rigged(renderable, smd_mesh, weights);
+ renderable* r = renderable_new();
+ renderable_add_mesh_rigged(r, smd_mesh, weights);
+ r->is_rigged = true;
vertex_hashtable_delete(hashes);
vertex_list_delete(vert_list);
int_list_delete(tri_list);
mesh_delete(smd_mesh);
free(weights);
- return renderable;
+ return r;
}
View
247 src/cengine.c
@@ -451,26 +451,26 @@ float vec2_length(vec2 v) {
return sqrt(vec2_length_sqrd(v));
}
-float vec2_dist_sqrd(vec2 v1, vec2 vec2) {
- return (v1.x - vec2.x) * (v1.x - vec2.x) +
- (v1.y - vec2.y) * (v1.y - vec2.y);
+float vec2_dist_sqrd(vec2 v1, vec2 v2) {
+ return (v1.x - v2.x) * (v1.x - v2.x) +
+ (v1.y - v2.y) * (v1.y - v2.y);
}
-float vec2_dist(vec2 v1, vec2 vec2) {
- return sqrt(vec2_dist_sqrd(v1, vec2));
+float vec2_dist(vec2 v1, vec2 v2) {
+ return sqrt(vec2_dist_sqrd(v1, v2));
}
-float vec2_dist_manhattan(vec2 v1, vec2 vec2) {
- return fabs(v1.x - vec2.x) + fabs(v1.y - vec2.y);
+float vec2_dist_manhattan(vec2 v1, vec2 v2) {
+ return fabs(v1.x - v2.x) + fabs(v1.y - v2.y);
}
vec2 vec2_normalize(vec2 v) {
float len = vec2_length(v);
return vec2_div(v, len);
}
-vec2 vec2_reflect(vec2 v1, vec2 vec2) {
- return vec2_sub(v1, vec2_mul(vec2, 2 * vec2_dot(v1, vec2)));
+vec2 vec2_reflect(vec2 v1, vec2 v2) {
+ return vec2_sub(v1, vec2_mul(v2, 2 * vec2_dot(v1, v2)));
}
vec2 vec2_from_string(char* s) {
@@ -487,9 +487,9 @@ vec2 vec2_from_string(char* s) {
return v;
}
-bool vec2_equ(vec2 v1, vec2 vec2) {
- if(!(v1.x == vec2.x)) { return false; }
- if(!(v1.y == vec2.y)) { return false; }
+bool vec2_equ(vec2 v1, vec2 v2) {
+ if(!(v1.x == v2.x)) { return false; }
+ if(!(v1.y == v2.y)) { return false; }
return true;
}
@@ -596,19 +596,19 @@ vec3 vec3_grey() {
return vec3_new(0.5, 0.5, 0.5);
}
-vec3 vec3_add(vec3 v1, vec3 vec2) {
+vec3 vec3_add(vec3 v1, vec3 v2) {
vec3 v;
- v.x = v1.x + vec2.x;
- v.y = v1.y + vec2.y;
- v.z = v1.z + vec2.z;
+ v.x = v1.x + v2.x;
+ v.y = v1.y + v2.y;
+ v.z = v1.z + v2.z;
return v;
}
-vec3 vec3_sub(vec3 v1, vec3 vec2) {
+vec3 vec3_sub(vec3 v1, vec3 v2) {
vec3 v;
- v.x = v1.x - vec2.x;
- v.y = v1.y - vec2.y;
- v.z = v1.z - vec2.z;
+ v.x = v1.x - v2.x;
+ v.y = v1.y - v2.y;
+ v.z = v1.z - v2.z;
return v;
}
@@ -626,11 +626,11 @@ vec3 vec3_mul(vec3 v, float fac) {
return v;
}
-vec3 vec3_mul_vec3(vec3 v1, vec3 vec2) {
+vec3 vec3_mul_vec3(vec3 v1, vec3 v2) {
vec3 v;
- v.x = v1.x * vec2.x;
- v.y = v1.y * vec2.y;
- v.z = v1.z * vec2.z;
+ v.x = v1.x * v2.x;
+ v.y = v1.y * v2.y;
+ v.z = v1.z * v2.z;
return v;
}
@@ -673,15 +673,15 @@ void vec3_print(vec3 v) {
printf("vec3(%4.2f,%4.2f,%4.2f)", v.x, v.y, v.z);
}
-float vec3_dot(vec3 v1, vec3 vec2) {
- return (v1.x * vec2.x) + (v1.y * vec2.y) + (v1.z * vec2.z);
+float vec3_dot(vec3 v1, vec3 v2) {
+ return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
}
-vec3 vec3_cross(vec3 v1, vec3 vec2) {
+vec3 vec3_cross(vec3 v1, vec3 v2) {
vec3 v;
- v.x = (v1.y * vec2.z) - (v1.z * vec2.y);
- v.y = (v1.z * vec2.x) - (v1.x * vec2.z);
- v.z = (v1.x * vec2.y) - (v1.y * vec2.x);
+ v.x = (v1.y * v2.z) - (v1.z * v2.y);
+ v.y = (v1.z * v2.x) - (v1.x * v2.z);
+ v.z = (v1.x * v2.y) - (v1.y * v2.x);
return v;
}
@@ -697,18 +697,18 @@ float vec3_length(vec3 v) {
return sqrt(vec3_length_sqrd(v));
}
-float vec3_dist_sqrd(vec3 v1, vec3 vec2) {
- return (v1.x - vec2.x) * (v1.x - vec2.x) +
- (v1.y - vec2.y) * (v1.y - vec2.y) +
- (v1.z - vec2.z) * (v1.z - vec2.z);
+float vec3_dist_sqrd(vec3 v1, vec3 v2) {
+ return (v1.x - v2.x) * (v1.x - v2.x) +
+ (v1.y - v2.y) * (v1.y - v2.y) +
+ (v1.z - v2.z) * (v1.z - v2.z);
}
-float vec3_dist(vec3 v1, vec3 vec2) {
- return sqrt(vec3_dist_sqrd(v1, vec2));
+float vec3_dist(vec3 v1, vec3 v2) {
+ return sqrt(vec3_dist_sqrd(v1, v2));
}
-float vec3_dist_manhattan(vec3 v1, vec3 vec2) {
- return fabs(v1.x - vec2.x) + fabs(v1.y - vec2.y) + fabs(v1.z - vec2.z);
+float vec3_dist_manhattan(vec3 v1, vec3 v2) {
+ return fabs(v1.x - v2.x) + fabs(v1.y - v2.y) + fabs(v1.z - v2.z);
}
vec3 vec3_normalize(vec3 v) {
@@ -720,8 +720,8 @@ vec3 vec3_normalize(vec3 v) {
}
}
-vec3 vec3_reflect(vec3 v1, vec3 vec2) {
- return vec3_sub(v1, vec3_mul(vec2, 2 * vec3_dot(v1, vec2)));
+vec3 vec3_reflect(vec3 v1, vec3 v2) {
+ return vec3_sub(v1, vec3_mul(v2, 2 * vec3_dot(v1, v2)));
}
vec3 vec3_from_string(char* s) {
@@ -741,10 +741,10 @@ vec3 vec3_from_string(char* s) {
}
-bool vec3_equ(vec3 v1, vec3 vec2) {
- if(!(v1.x == vec2.x)) { return false; }
- if(!(v1.y == vec2.y)) { return false; }
- if(!(v1.z == vec2.z)) { return false; }
+bool vec3_equ(vec3 v1, vec3 v2) {
+ if(!(v1.x == v2.x)) { return false; }
+ if(!(v1.y == v2.y)) { return false; }
+ if(!(v1.z == v2.z)) { return false; }
return true;
}
@@ -791,12 +791,12 @@ vec3 vec3_smootherstep(vec3 v1, vec3 v2, float amount) {
/* vec4 */
-vec4 vec4_new(float w, float x, float y, float z) {
+vec4 vec4_new(float x, float y, float z, float w) {
vec4 v;
- v.w = w;
v.x = x;
v.y = y;
v.z = z;
+ v.w = w;
return v;
}
@@ -869,9 +869,9 @@ vec4 vec4_mul(vec4 v, float fac) {
vec4 vec4_mul_vec4(vec4 v1, vec4 v2) {
vec4 v;
v.x = v1.x * v2.x;
- v.y = v1.y * v2.x;
- v.z = v1.z * v2.x;
- v.w = v1.w * v2.x;
+ v.y = v1.y * v2.y;
+ v.z = v1.z * v2.z;
+ v.w = v1.w * v2.w;
return v;
}
@@ -919,8 +919,8 @@ void vec4_print(vec4 v) {
printf("vec4(%4.2f, %4.2f, %4.2f, %4.2f)", v.x, v.y, v.z, v.w);
}
-float vec4_dot(vec4 v1, vec4 vec2) {
- return (v1.x * vec2.x) + (v1.y * vec2.y) + (v1.z * vec2.z) + (v1.w * vec2.w);
+float vec4_dot(vec4 v1, vec4 v2) {
+ return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z) + (v1.w * v2.w);
}
float vec4_length_sqrd(vec4 v) {
@@ -936,19 +936,19 @@ float vec4_length(vec4 v) {
return sqrt(vec4_length_sqrd(v));
}
-float vec4_dist_sqrd(vec4 v1, vec4 vec2) {
- return (v1.x - vec2.x) * (v1.x - vec2.x) +
- (v1.y - vec2.y) * (v1.y - vec2.y) +
- (v1.y - vec2.z) * (v1.y - vec2.z) +
- (v1.y - vec2.w) * (v1.y - vec2.w);
+float vec4_dist_sqrd(vec4 v1, vec4 v2) {
+ return (v1.x - v2.x) * (v1.x - v2.x) +
+ (v1.y - v2.y) * (v1.y - v2.y) +
+ (v1.y - v2.z) * (v1.y - v2.z) +
+ (v1.y - v2.w) * (v1.y - v2.w);
}
-float vec4_dist(vec4 v1, vec4 vec2) {
- return sqrt(vec4_dist_sqrd(v1, vec2));
+float vec4_dist(vec4 v1, vec4 v2) {
+ return sqrt(vec4_dist_sqrd(v1, v2));
}
-float vec4_dist_manhattan(vec4 v1, vec4 vec2) {
- return fabs(v1.x - vec2.x) + fabs(v1.y - vec2.y) + fabs(v1.z - vec2.z) + fabs(v1.w - vec2.w);
+float vec4_dist_manhattan(vec4 v1, vec4 v2) {
+ return fabs(v1.x - v2.x) + fabs(v1.y - v2.y) + fabs(v1.z - v2.z) + fabs(v1.w - v2.w);
}
vec4 vec4_normalize(vec4 v) {
@@ -960,17 +960,17 @@ vec4 vec4_normalize(vec4 v) {
}
}
-vec4 vec4_reflect(vec4 v1, vec4 vec2) {
- return vec4_sub(v1, vec4_mul(vec2, 2 * vec4_dot(v1, vec2)));
+vec4 vec4_reflect(vec4 v1, vec4 v2) {
+ return vec4_sub(v1, vec4_mul(v2, 2 * vec4_dot(v1, v2)));
}
vec4 vec4_from_string(char* s) {
- char* pEnd;
+ char* end;
double d1, d2, d3, d4;
- d1 = strtod(s,&pEnd);
- d2 = strtod(pEnd,&pEnd);
- d3 = strtod(pEnd,&pEnd);
- d4 = strtod(pEnd,NULL);
+ d1 = strtod(s,&end);
+ d2 = strtod(end,&end);
+ d3 = strtod(end,&end);
+ d4 = strtod(end,NULL);
vec4 v;
v.x = d1;
@@ -981,11 +981,11 @@ vec4 vec4_from_string(char* s) {
return v;
}
-bool vec4_equ(vec4 v1, vec4 vec2) {
- if(!(v1.x == vec2.x)) { return false; }
- if(!(v1.y == vec2.y)) { return false; }
- if(!(v1.z == vec2.z)) { return false; }
- if(!(v1.w == vec2.w)) { return false; }
+bool vec4_equ(vec4 v1, vec4 v2) {
+ if(!(v1.x == v2.x)) { return false; }
+ if(!(v1.y == v2.y)) { return false; }
+ if(!(v1.z == v2.z)) { return false; }
+ if(!(v1.w == v2.w)) { return false; }
return true;
}
@@ -1015,31 +1015,31 @@ vec4 vec4_saturate(vec4 v) {
return v;
}
-vec4 vec4_lerp(vec4 v1, vec4 vec2, float amount) {
+vec4 vec4_lerp(vec4 v1, vec4 v2, float amount) {
vec4 v;
- v.x = lerp(v1.x, vec2.x, amount);
- v.y = lerp(v1.y, vec2.y, amount);
- v.z = lerp(v1.z, vec2.z, amount);
- v.w = lerp(v1.w, vec2.w, amount);
+ v.x = lerp(v1.x, v2.x, amount);
+ v.y = lerp(v1.y, v2.y, amount);
+ v.z = lerp(v1.z, v2.z, amount);
+ v.w = lerp(v1.w, v2.w, amount);
return v;
}
-vec4 vec4_smoothstep(vec4 v1, vec4 vec2, float amount) {
+vec4 vec4_smoothstep(vec4 v1, vec4 v2, float amount) {
float scaled_amount = amount*amount*(3 - 2*amount);
- return vec4_lerp( v1, vec2, scaled_amount );
+ return vec4_lerp( v1, v2, scaled_amount );
}
-vec4 vec4_smootherstep(vec4 v1, vec4 vec2, float amount) {
+vec4 vec4_smootherstep(vec4 v1, vec4 v2, float amount) {
float scaled_amount = amount*amount*amount*(amount*(amount*6 - 15) + 10);
- return vec4_lerp( v1, vec2, scaled_amount );
+ return vec4_lerp( v1, v2, scaled_amount );
}
-vec4 vec4_nearest_interp(vec4 v1, vec4 vec2, float amount) {
+vec4 vec4_nearest_interp(vec4 v1, vec4 v2, float amount) {
vec4 v;
- v.w = nearest_interp(v1.w, vec2.w, amount);
- v.x = nearest_interp(v1.x, vec2.x, amount);
- v.y = nearest_interp(v1.y, vec2.y, amount);
- v.z = nearest_interp(v1.z, vec2.z, amount);
+ v.w = nearest_interp(v1.w, v2.w, amount);
+ v.x = nearest_interp(v1.x, v2.x, amount);
+ v.y = nearest_interp(v1.y, v2.y, amount);
+ v.z = nearest_interp(v1.z, v2.z, amount);
return v;
}
@@ -1142,34 +1142,24 @@ vec4 quaternion_swap_handedness(vec4 q) {
mat2 mat2_id() {
mat2 mat;
-
- mat.xx = 1.0f;
- mat.xy = 0.0f;
- mat.yx = 0.0f;
- mat.yy = 1.0f;
-
+ mat.xx = 1.0f; mat.xy = 0.0f;
+ mat.yx = 0.0f; mat.yy = 1.0f;
return mat;
}
mat2 mat2_zero() {
mat2 mat;
-
- mat.xx = 0.0f;
- mat.xy = 0.0f;
- mat.yx = 0.0f;
- mat.yy = 0.0f;
-
+ mat.xx = 0.0f; mat.xy = 0.0f;
+ mat.yx = 0.0f; mat.yy = 0.0f;
return mat;
}
mat2 mat2_new(float xx, float xy, float yx, float yy) {
mat2 mat;
-
mat.xx = xx;
mat.xy = xy;
mat.yx = yx;
mat.yy = yy;
-
return mat;
}
@@ -1766,12 +1756,6 @@ void mat4_print(mat4 m) {
}
mat4 mat4_view_look_at(vec3 position, vec3 target, vec3 up) {
-
- /*
-Taken From:
-http://www.opengl.org/wiki/GluLookAt_code
-
-*/
vec3 zaxis = vec3_normalize( vec3_sub(target, position) );
vec3 xaxis = vec3_normalize( vec3_cross(up, zaxis) );
@@ -1790,16 +1774,13 @@ Taken From:
view_matrix.zy = -zaxis.y;
view_matrix.zz = -zaxis.z;
- // Also unsure of this.
view_matrix = mat4_mul_mat4(view_matrix, mat4_translation(vec3_neg(position)) );
return view_matrix;
}
mat4 mat4_perspective(float fov, float near_clip, float far_clip, float ratio) {
- /* http://www.opengl.org/wiki/GluPerspective_code */
-
float right, left, bottom, top;
right = -(near_clip * tanf(fov));
@@ -1925,29 +1906,28 @@ mat4 mat4_rotation_euler(float x, float y, float z) {
mat4 m = mat4_zero();
-float cosx = cos(x);
-float cosy = cos(y);
-float cosz = cos(z);
-float sinx = sin(x);
-float siny = sin(y);
-float sinz = sin(z);
+ float cosx = cos(x);
+ float cosy = cos(y);
+ float cosz = cos(z);
+ float sinx = sin(x);
+ float siny = sin(y);
+ float sinz = sin(z);
-m.xx = cosy * cosz;
-m.yx = -cosx * sinz + sinx * siny * cosz;
-m.zx = sinx * sinz + cosx * siny * cosz;
+ m.xx = cosy * cosz;
+ m.yx = -cosx * sinz + sinx * siny * cosz;
+ m.zx = sinx * sinz + cosx * siny * cosz;
-m.xy = cosy * sinz;
-m.yy = cosx * cosz + sinx * siny * sinz;
-m.zy = -sinx * cosz + cosx * siny * sinz;
+ m.xy = cosy * sinz;
+ m.yy = cosx * cosz + sinx * siny * sinz;
+ m.zy = -sinx * cosz + cosx * siny * sinz;
-m.xz = -siny;
-m.yz = sinx * cosy;
-m.zz = cosx * cosy;
+ m.xz = -siny;
+ m.yz = sinx * cosy;
+ m.zz = cosx * cosy;
-m.ww = 1;
+ m.ww = 1;
return m;
-
}
mat4 mat4_rotation_quaternion(vec4 q) {
@@ -2042,7 +2022,6 @@ mat4 mat4_smoothstep(mat4 m1, mat4 m2, float amount) {
/* Geometry Functions */
-
plane plane_new(vec3 position, vec3 direction) {
plane p;
p.position = position;
@@ -2335,7 +2314,6 @@ void mesh_generate_tangents(mesh* m) {
}
/* normalize all tangents */
-
for(int i = 0; i < m->num_verts; i++) {
m->verticies[i].tangent = vec3_normalize( m->verticies[i].tangent );
m->verticies[i].binormal = vec3_normalize( m->verticies[i].binormal );
@@ -2346,13 +2324,11 @@ void mesh_generate_tangents(mesh* m) {
void mesh_generate_normals(mesh* m) {
/* Clear all normals to 0,0,0 */
-
for(int i = 0; i < m->num_verts; i++) {
m->verticies[i].normal = vec3_zero();
}
/* Loop over faces, calculate normals and append to verticies of that face */
-
int i = 0;
while( i < m->num_triangles * 3) {
@@ -2378,7 +2354,6 @@ void mesh_generate_normals(mesh* m) {
}
/* normalize all normals */
-
for(int i = 0; i < m->num_verts; i++) {
m->verticies[i].normal = vec3_normalize( m->verticies[i].normal );
}
@@ -2575,19 +2550,15 @@ void model_generate_tangents(model* m) {
}
void model_generate_orthagonal_tangents(model* m) {
-
for(int i = 0; i < m->num_meshes; i++) {
mesh_generate_orthagonal_tangents( m->meshes[i] );
}
-
}
void model_generate_texcoords_cylinder(model* m) {
-
for(int i = 0; i < m->num_meshes; i++) {
mesh_generate_texcoords_cylinder( m->meshes[i] );
}
-
}
float model_surface_area(model* m) {
@@ -2601,27 +2572,21 @@ float model_surface_area(model* m) {
}
void model_translate(model* m, vec3 translation) {
-
for(int i = 0; i < m->num_meshes; i++) {
mesh_translate(m->meshes[i], translation);
}
-
}
void model_scale(model* m, float scale) {
-
for(int i = 0; i < m->num_meshes; i++) {
mesh_scale(m->meshes[i], scale);
}
-
}
void model_transform(model* m, mat4 transform) {
-
for(int i = 0; i < m->num_meshes; i++) {
mesh_transform(m->meshes[i], transform);
}
-
}
vec3 triangle_tangent(vertex vert1, vertex vert2, vertex vert3) {
View
1 src/centity.c
@@ -173,6 +173,7 @@ void entity_delete(char* name) {
for(int i = 0; i < entity_names->num_items; i++) {
if ( strcmp(list_get(entity_names, i), name) == 0 ) {
list_pop_at(entity_names, i);
+ break;
}
}
View
2 src/data/int_list.c
@@ -37,7 +37,7 @@ static void int_list_reserve_less(int_list* l) {
int int_list_pop_back(int_list* l) {
assert( l->num_items > 0 );
- int item = l->items[ l->num_items ];
+ int item = l->items[ l->num_items-1 ];
l->num_items--;
int_list_reserve_less(l);
View
11 src/data/list.c
@@ -31,7 +31,7 @@ static void list_reserve_less(list* l) {
void* list_pop_back(list* l) {
assert( l->num_items > 0 );
- void* item = l->items[ l->num_items ];
+ void* item = l->items[ l->num_items-1 ];
l->num_items--;
list_reserve_less(l);
@@ -55,11 +55,19 @@ void* list_pop_at(list* l, int index) {
}
void* list_get(list* l, int index) {
+
+ if (index < 0) { error("Index out of bounds"); return NULL; }
+ if (index >= l->num_items) { error("Index out of bounds"); return NULL; }
+
return l->items[index];
}
void list_set(list* l, int index, void* item) {
+
+ if (index < 0) { error("Index out of bounds"); }
+ if (index >= l->num_items) { error("Index out of bounds"); }
+
l->items[index] = item;
}
@@ -95,7 +103,6 @@ void list_clear_with(list* l, void func(void*)) {
while( l->num_items > 0) {
void* item = list_pop_back(l);
func(item);
- free(item);
}
}
View
2 src/data/vertex_list.c
@@ -37,7 +37,7 @@ static void vertex_list_reserve_less(vertex_list* l) {
vertex vertex_list_pop_back(vertex_list* l) {
assert( l->num_items > 0 );
- vertex item = l->items[ l->num_items ];
+ vertex item = l->items[ l->num_items-1 ];
l->num_items--;
vertex_list_reserve_less(l);
View
14 src/rendering/deferred_renderer.c
@@ -766,12 +766,13 @@ void deferred_renderer_render_static(static_object* so) {
renderable* r = asset_hndl_ptr(so->renderable);
+ if(r->is_rigged) {
+ error("Static object is rigged!");
+ }
+
for(int i=0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(s->is_rigged) {
- error("Renderable for static object is rigged!");
- }
shader_program* program_static = material_get_entry(asset_hndl_ptr(MAT_STATIC), 0)->program;
@@ -848,12 +849,13 @@ void deferred_renderer_render_animated(animated_object* ao) {
renderable* r = asset_hndl_ptr(ao->renderable);
+ if(!r->is_rigged) {
+ error("Animated object is not rigged!");
+ }
+
for(int i = 0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(!s->is_rigged) {
- error("Animated object is not rigged!");
- }
shader_program* program_animated = material_get_entry(asset_hndl_ptr(MAT_ANIMATED), 0)->program;
View
61 src/rendering/depth_mapper.c
@@ -138,14 +138,14 @@ void depth_mapper_render_static(static_object* s) {
renderable* r = asset_hndl_ptr(s->renderable);
+ if(r->is_rigged) {
+ error("Static Object is rigged!");
+ }
+
for(int i=0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(s->is_rigged) {
- error("Static Object is rigged!");
- }
-
material_entry* me = material_get_entry(asset_hndl_ptr(depth_mat), 0);
if (material_entry_has_item(me, "alpha_test")) {
@@ -234,37 +234,36 @@ void depth_mapper_render_animated(animated_object* ao) {
renderable* r = asset_hndl_ptr(ao->renderable);
+ if(!r->is_rigged) {
+ error("animated object is not rigged");
+ }
+
for(int i = 0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(s->is_rigged) {
- GLsizei stride = sizeof(float) * 24;
-
- glBindBuffer(GL_ARRAY_BUFFER, s->vertex_vbo);
-
- glVertexPointer(3, GL_FLOAT, stride, (void*)0);
- glEnableClientState(GL_VERTEX_ARRAY);
-
- glVertexAttribPointer(BONE_INDICIES, 3, GL_FLOAT, GL_FALSE, stride, (void*)(sizeof(float) * 18));
- glEnableVertexAttribArray(BONE_INDICIES);
-
- glVertexAttribPointer(BONE_WEIGHTS, 3, GL_FLOAT, GL_FALSE, stride, (void*)(sizeof(float) * 21));
- glEnableVertexAttribArray(BONE_WEIGHTS);
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->triangle_vbo);
- glDrawElements(GL_TRIANGLES, s->num_triangles * 3, GL_UNSIGNED_INT, (void*)0);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableVertexAttribArray(BONE_INDICIES);
- glDisableVertexAttribArray(BONE_WEIGHTS);
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- } else {
- error("animated object is not rigged");
- }
+ GLsizei stride = sizeof(float) * 24;
+
+ glBindBuffer(GL_ARRAY_BUFFER, s->vertex_vbo);
+
+ glVertexPointer(3, GL_FLOAT, stride, (void*)0);
+ glEnableClientState(GL_VERTEX_ARRAY);
+
+ glVertexAttribPointer(BONE_INDICIES, 3, GL_FLOAT, GL_FALSE, stride, (void*)(sizeof(float) * 18));
+ glEnableVertexAttribArray(BONE_INDICIES);
+
+ glVertexAttribPointer(BONE_WEIGHTS, 3, GL_FLOAT, GL_FALSE, stride, (void*)(sizeof(float) * 21));
+ glEnableVertexAttribArray(BONE_WEIGHTS);
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->triangle_vbo);
+ glDrawElements(GL_TRIANGLES, s->num_triangles * 3, GL_UNSIGNED_INT, (void*)0);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableVertexAttribArray(BONE_INDICIES);
+ glDisableVertexAttribArray(BONE_WEIGHTS);
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
}
View
36 src/rendering/forward_renderer.c
@@ -690,12 +690,14 @@ void forward_renderer_render_static(static_object* so) {
renderable* r = asset_hndl_ptr(so->renderable);
+ if(r->is_rigged) {
+ error("Static object is rigged!");
+ }
+
for(int i=0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(s->is_rigged) {
- error("Renderable for static object is rigged!");
- }
+
int mat_id = min(i, ((material*)asset_hndl_ptr(r->material))->num_entries-1);
material_entry* me = material_get_entry(asset_hndl_ptr(r->material), mat_id);
@@ -742,12 +744,13 @@ void forward_renderer_render_static_tess(static_object* so) {
renderable* r = asset_hndl_ptr(so->renderable);
+ if(r->is_rigged) {
+ error("Static object is rigged!");
+ }
+
for(int i=0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(s->is_rigged) {
- error("Renderable for static object is rigged!");
- }
int mat_id = min(i, ((material*)asset_hndl_ptr(r->material))->num_entries-1);
material_entry* me = material_get_entry(asset_hndl_ptr(r->material), mat_id);
@@ -791,12 +794,13 @@ void forward_renderer_render_instance(instance_object* io) {
renderable* r = asset_hndl_ptr(io->renderable);
+ if(r->is_rigged) {
+ error("Static object is rigged!");
+ }
+
for(int i=0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(s->is_rigged) {
- error("Renderable for static object is rigged!");
- }
int mat_id = min(i, ((material*)asset_hndl_ptr(r->material))->num_entries-1);
material_entry* me = material_get_entry(asset_hndl_ptr(r->material), mat_id);
@@ -834,12 +838,13 @@ void forward_renderer_render_physics(physics_object* po) {
renderable* r = asset_hndl_ptr(po->renderable);
+ if(r->is_rigged) {
+ error("Physics object is rigged!");
+ }
+
for(int i=0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(s->is_rigged) {
- error("Physics object is rigged!");
- }
int mat_id = min(i, ((material*)asset_hndl_ptr(r->material))->num_entries-1);
material_entry* me = material_get_entry(asset_hndl_ptr(r->material), mat_id);
@@ -896,12 +901,13 @@ void forward_renderer_render_animated(animated_object* ao) {
renderable* r = asset_hndl_ptr(ao->renderable);
+ if(!r->is_rigged) {
+ error("animated object is not rigged");
+ }
+
for(int i = 0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(!s->is_rigged) {
- error("animated object is not rigged");
- }
int mat_id = min(i, ((material*)asset_hndl_ptr(r->material))->num_entries-1);
material_entry* me = material_get_entry(asset_hndl_ptr(r->material), mat_id);
View
45 src/rendering/shadow_mapper.c
@@ -27,13 +27,13 @@ static int BONE_INDICIES;
static int BONE_WEIGHTS;
void shadow_mapper_init(light* l) {
-
+
LIGHT = l;
depth_mat = asset_hndl_new_load(P("$CORANGE/shaders/depth.mat"));
depth_mat_animated = asset_hndl_new_load(P("$CORANGE/shaders/depth_animated.mat"));
- shader_program* depth_shader_animated = material_get_entry(asset_hndl_ptr(depth_mat), 0)->program;
+ shader_program* depth_shader_animated = material_get_entry(asset_hndl_ptr(depth_mat_animated), 0)->program;
BONE_INDICIES = glGetAttribLocation(shader_program_handle(depth_shader_animated), "bone_indicies");
BONE_WEIGHTS = glGetAttribLocation(shader_program_handle(depth_shader_animated), "bone_weights");
@@ -148,14 +148,14 @@ void shadow_mapper_render_static(static_object* s) {
renderable* r = asset_hndl_ptr(s->renderable);
+ if(r->is_rigged) {
+ error("Static Object is rigged!");
+ }
+
for(int i=0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(s->is_rigged) {
- error("Static Object is rigged!");
- }
-
material_entry* me = material_get_entry(asset_hndl_ptr(depth_mat), 0);
if (material_entry_has_item(me, "alpha_test")) {
@@ -206,13 +206,15 @@ static float bone_matrix_data[4 * 4 * MAX_BONES];
void shadow_mapper_render_animated(animated_object* ao) {
skeleton* skel = asset_hndl_ptr(ao->skeleton);
+ SDL_GL_CheckError();
if (skel->num_bones > MAX_BONES) {
error("animated object skeleton has too many bones (over %i)", MAX_BONES);
}
mat4 r_world_matrix = mat4_world( ao->position, ao->scale, ao->rotation );
mat4_to_array(r_world_matrix, world_matrix);
+ SDL_GL_CheckError();
for(int i = 0; i < skel->num_bones; i++) {
mat4 base, ani;
@@ -222,60 +224,77 @@ void shadow_mapper_render_animated(animated_object* ao) {
bone_matrices[i] = mat4_mul_mat4(ani, mat4_inverse(base));
mat4_to_array(bone_matrices[i], bone_matrix_data + (i * 4 * 4));
}
+ SDL_GL_CheckError();
shader_program* depth_shader_animated = material_get_entry(asset_hndl_ptr(depth_mat_animated), 0)->program;
+ SDL_GL_CheckError();
glUseProgram(*depth_shader_animated);
+ SDL_GL_CheckError();
GLint bone_world_matrices_u = glGetUniformLocation(*depth_shader_animated, "bone_world_matrices");
glUniformMatrix4fv(bone_world_matrices_u, skel->num_bones, GL_FALSE, bone_matrix_data);
+ SDL_GL_CheckError();
GLint bone_count_u = glGetUniformLocation(*depth_shader_animated, "bone_count");
glUniform1i(bone_count_u, skel->num_bones);
+ SDL_GL_CheckError();
GLint world_matrix_u = glGetUniformLocation(*depth_shader_animated, "world_matrix");
glUniformMatrix4fv(world_matrix_u, 1, 0, world_matrix);
+ SDL_GL_CheckError();
GLint proj_matrix_u = glGetUniformLocation(*depth_shader_animated, "proj_matrix");
glUniformMatrix4fv(proj_matrix_u, 1, 0, proj_matrix);
+ SDL_GL_CheckError();
GLint view_matrix_u = glGetUniformLocation(*depth_shader_animated, "view_matrix");
glUniformMatrix4fv(view_matrix_u, 1, 0, view_matrix);
+ SDL_GL_CheckError();
renderable* r = asset_hndl_ptr(ao->renderable);
+ if(!r->is_rigged) {
+ error("animated object is not rigged");
+ }
+
for(int i = 0; i < r->num_surfaces; i++) {
renderable_surface* s = r->surfaces[i];
- if(!s->is_rigged) {
- error("animated object is not rigged");
- }
-
GLsizei stride = sizeof(float) * 24;
glBindBuffer(GL_ARRAY_BUFFER, s->vertex_vbo);
-
+ SDL_GL_CheckError();
+
glVertexPointer(3, GL_FLOAT, stride, (void*)0);
glEnableClientState(GL_VERTEX_ARRAY);
+ SDL_GL_CheckError();
glVertexAttribPointer(BONE_INDICIES, 3, GL_FLOAT, GL_FALSE, stride, (void*)(sizeof(float) * 18));
+ SDL_GL_CheckError();
glEnableVertexAttribArray(BONE_INDICIES);
+ SDL_GL_CheckError();
glVertexAttribPointer(BONE_WEIGHTS, 3, GL_FLOAT, GL_FALSE, stride, (void*)(sizeof(float) * 21));
glEnableVertexAttribArray(BONE_WEIGHTS);
+ SDL_GL_CheckError();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->triangle_vbo);
glDrawElements(GL_TRIANGLES, s->num_triangles * 3, GL_UNSIGNED_INT, (void*)0);
-
+ SDL_GL_CheckError();
+
glDisableClientState(GL_VERTEX_ARRAY);
glDisableVertexAttribArray(BONE_INDICIES);
glDisableVertexAttribArray(BONE_WEIGHTS);
+ SDL_GL_CheckError();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
-
+ SDL_GL_CheckError();
+
}
+ SDL_GL_CheckError();
glUseProgram(0);

0 comments on commit 8182997

Please sign in to comment.