for both OpenGL and the PS3.legacy
@@ -190,6 +190,9 @@ void DebugQuad::TickDraw(float deltams) | |||||
colors[i * 3 + 2] = p.z; | colors[i * 3 + 2] = p.z; | ||||
} | } | ||||
/* Our default quad color */ | |||||
vec4 orange(0.8f, 0.5f, 0.2f, 1.0f); | |||||
/* Cheap iterators */ | /* Cheap iterators */ | ||||
#if !defined __CELLOS_LV2__ && !defined ANDROID_NDK | #if !defined __CELLOS_LV2__ && !defined ANDROID_NDK | ||||
GLuint *array = data->array; | GLuint *array = data->array; | ||||
@@ -207,7 +210,7 @@ void DebugQuad::TickDraw(float deltams) | |||||
* Renders an orange square. | * Renders an orange square. | ||||
*/ | */ | ||||
#if defined HAVE_GLBEGIN || defined USE_GLEW | #if defined HAVE_GLBEGIN || defined USE_GLEW | ||||
glColor3f(0.8f, 0.5f, 0.2f); | |||||
glColor3f(orange.x, orange.y, orange.z); | |||||
glBegin(GL_TRIANGLES); | glBegin(GL_TRIANGLES); | ||||
glVertex3f(data->aa.x, data->bb.y, 0.0f); | glVertex3f(data->aa.x, data->bb.y, 0.0f); | ||||
glVertex3f(data->bb.x, data->bb.y, 0.0f); | glVertex3f(data->bb.x, data->bb.y, 0.0f); | ||||
@@ -428,7 +431,7 @@ void DebugQuad::TickDraw(float deltams) | |||||
* Renders an orange square. | * Renders an orange square. | ||||
*/ | */ | ||||
#if !defined ANDROID_NDK | #if !defined ANDROID_NDK | ||||
glColor4f(0.8f, 0.5f, 0.2f, 1.0f); | |||||
glColor4f(orange.x, orange.y, orange.z, orange.w); | |||||
glEnableClientState(GL_VERTEX_ARRAY); | glEnableClientState(GL_VERTEX_ARRAY); | ||||
glVertexPointer(3, GL_FLOAT, 0, data->GetVertexArray()); | glVertexPointer(3, GL_FLOAT, 0, data->GetVertexArray()); | ||||
@@ -574,12 +577,8 @@ void DebugQuad::TickDraw(float deltams) | |||||
uni[0] = shader[0]->GetUniformLocation("in_Color"); | uni[0] = shader[0]->GetUniformLocation("in_Color"); | ||||
} | } | ||||
shader[0]->Bind(); | shader[0]->Bind(); | ||||
shader[0]->SetUniform(uni[0], orange); | |||||
shader++; | shader++; | ||||
#if !defined __CELLOS_LV2__ | |||||
glUniform4f(uni[0], 0.8f, 0.5f, 0.2f, 1.0f); | |||||
#else | |||||
cgGLSetParameter4f((CGparameter)(intptr_t)uni[0], 0.8f, 0.5f, 0.2f, 1.0f); | |||||
#endif | |||||
uni++; | uni++; | ||||
glEnableClientState(GL_VERTEX_ARRAY); | glEnableClientState(GL_VERTEX_ARRAY); | ||||
@@ -691,12 +690,8 @@ void DebugQuad::TickDraw(float deltams) | |||||
uni[0] = shader[0]->GetUniformLocation("in_Matrix"); | uni[0] = shader[0]->GetUniformLocation("in_Matrix"); | ||||
} | } | ||||
shader[0]->Bind(); | shader[0]->Bind(); | ||||
shader[0]->SetUniform(uni[0], t2); | |||||
shader++; | shader++; | ||||
#if !defined __CELLOS_LV2__ | |||||
glUniformMatrix4fv(uni[0], 1, GL_FALSE, &t2[0][0]); | |||||
#else | |||||
cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni[0], &t2[0][0]); | |||||
#endif | |||||
uni++; | uni++; | ||||
glEnableClientState(GL_VERTEX_ARRAY); | glEnableClientState(GL_VERTEX_ARRAY); | ||||
@@ -266,24 +266,17 @@ void Scene::Render() // XXX: rename to Blit() | |||||
stdshader->Bind(); | stdshader->Bind(); | ||||
#if !defined __CELLOS_LV2__ | |||||
uni_mat = stdshader->GetUniformLocation("proj_matrix"); | uni_mat = stdshader->GetUniformLocation("proj_matrix"); | ||||
glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &Video::GetProjMatrix()[0][0]); | |||||
stdshader->SetUniform(uni_mat, Video::GetProjMatrix()); | |||||
uni_mat = stdshader->GetUniformLocation("view_matrix"); | uni_mat = stdshader->GetUniformLocation("view_matrix"); | ||||
glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &Video::GetViewMatrix()[0][0]); | |||||
stdshader->SetUniform(uni_mat, Video::GetViewMatrix()); | |||||
uni_mat = stdshader->GetUniformLocation("model_matrix"); | uni_mat = stdshader->GetUniformLocation("model_matrix"); | ||||
glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &data->model_matrix[0][0]); | |||||
stdshader->SetUniform(uni_mat, data->model_matrix); | |||||
#if !defined __CELLOS_LV2__ | |||||
uni_tex = stdshader->GetUniformLocation("in_Texture"); | uni_tex = stdshader->GetUniformLocation("in_Texture"); | ||||
glUniform1i(uni_tex, 0); | glUniform1i(uni_tex, 0); | ||||
#else | #else | ||||
uni_mat = stdshader->GetUniformLocation("proj_matrix"); | |||||
cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni_mat, &Video::GetProjMatrix()[0][0]); | |||||
uni_mat = stdshader->GetUniformLocation("view_matrix"); | |||||
cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni_mat, &Video::GetViewMatrix()[0][0]); | |||||
uni_mat = stdshader->GetUniformLocation("model_matrix"); | |||||
cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni_mat, &data->model_matrix[0][0]); | |||||
// WTF? this doesn't exist | // WTF? this doesn't exist | ||||
//uni_tex = stdshader->GetUniformLocation("in_Texture"); | //uni_tex = stdshader->GetUniformLocation("in_Texture"); | ||||
//cgGLSetParameter1i((CGparameter)(intptr_t)uni_tex, 0); | //cgGLSetParameter1i((CGparameter)(intptr_t)uni_tex, 0); | ||||
@@ -186,6 +186,52 @@ int Shader::GetUniformLocation(char const *uni) const | |||||
#endif | #endif | ||||
} | } | ||||
void Shader::SetUniform(int uni, float f) | |||||
{ | |||||
#if !defined __CELLOS_LV2__ | |||||
glUniform1f(uni, f); | |||||
#else | |||||
cgGLSetParameter1f((CGparameter)(intptr_t)uni, f); | |||||
#endif | |||||
} | |||||
void Shader::SetUniform(int uni, vec2 const &v) | |||||
{ | |||||
#if !defined __CELLOS_LV2__ | |||||
glUniform2f(uni, v.x, v.y); | |||||
#else | |||||
cgGLSetParameter2f((CGparameter)(intptr_t)uni, v.x, v.y); | |||||
#endif | |||||
} | |||||
void Shader::SetUniform(int uni, vec3 const &v) | |||||
{ | |||||
#if !defined __CELLOS_LV2__ | |||||
glUniform3f(uni, v.x, v.y, v.z); | |||||
#else | |||||
cgGLSetParameter3f((CGparameter)(intptr_t)uni, v.x, v.y, v.z); | |||||
#endif | |||||
} | |||||
void Shader::SetUniform(int uni, vec4 const &v) | |||||
{ | |||||
/* FIXME: use the array versions of these functions */ | |||||
#if !defined __CELLOS_LV2__ | |||||
glUniform4f(uni, v.x, v.y, v.z, v.w); | |||||
#else | |||||
cgGLSetParameter4f((CGparameter)(intptr_t)uni, v.x, v.y, v.z, v.w); | |||||
#endif | |||||
} | |||||
void Shader::SetUniform(int uni, mat4 const &m) | |||||
{ | |||||
#if !defined __CELLOS_LV2__ | |||||
glUniformMatrix4fv(uni, 1, GL_FALSE, &m[0][0]); | |||||
#else | |||||
cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni, &m[0][0]); | |||||
#endif | |||||
} | |||||
void Shader::Bind() const | void Shader::Bind() const | ||||
{ | { | ||||
#if !defined __CELLOS_LV2__ | #if !defined __CELLOS_LV2__ | ||||
@@ -28,7 +28,13 @@ public: | |||||
static void Destroy(Shader *shader); | static void Destroy(Shader *shader); | ||||
int GetAttribLocation(char const *attr) const; | int GetAttribLocation(char const *attr) const; | ||||
int GetUniformLocation(char const *uni) const; | int GetUniformLocation(char const *uni) const; | ||||
void SetUniform(int uni, float f); | |||||
void SetUniform(int uni, vec2 const &v); | |||||
void SetUniform(int uni, vec3 const &v); | |||||
void SetUniform(int uni, vec4 const &v); | |||||
void SetUniform(int uni, mat4 const &m); | |||||
void Bind() const; | void Bind() const; | ||||