Commit 843044dd authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

Function rendering GPU constants set up for shadows. Moved function rendering...

Function rendering GPU constants set up for shadows. Moved function rendering code from vis to function source (where it belongs). Added simplified function rendering for the shadows.
parent 22b98fe9
......@@ -28,6 +28,10 @@
///////////////////////////////////////////////////////////////////
// Global variables
static GLfloat gMatDiffuse[] = { 1.0, 1.0, 1.0, 1.0 };
static GLfloat gBoardSpecular[] = { 0.7, 0.7, 0.7, 0.9 };
static GLfloat gBoardShininess[] = { 10.0 };
///////////////////////////////////////////////////////////////////
// Function prototypes
......@@ -987,6 +991,244 @@ int CountStoredFaces (double fMultiplier, FuncPersist const * psFuncData) {
return nFaces;
}
void DrawGraph (FuncPersist * psFuncData) {
int nXIndex;
GLfloat * afVertices;
GLfloat * afNormals;
GLushort * auIndices;
GLfloat * afColours;
GLfloat * afTextureCoords;
int nYVertices;
int nXVertices;
GLfloat afGraphColour[4];
bool boColours;
FUNCTYPE eFuncType;
GLuint uTexture;
//GLuint uBumpMap;
GLuint uShaderProgram;
GLint nVar;
Matrix4 * pmLightTransform;
Matrix4 mLightTranslate;
float fShadowBias;
float fShadowBlur;
static GLdouble afClipEquations[4][4] = {{-1.0, 0.0, 0.0, AXIS_XHSIZE},
{1.0, 0.0, 0.0, AXIS_XHSIZE},
{0.0, -1.0, 0.0, AXIS_YHSIZE},
{0.0, 1.0, 0.0, AXIS_YHSIZE}};
eFuncType = GetFunctionType (psFuncData);
afVertices = GetVertices (psFuncData);
afNormals = GetNormals (psFuncData);
auIndices = GetIndices (psFuncData);
GetVertexDimensions (& nXVertices, & nYVertices, psFuncData);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, gBoardSpecular);
glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, gBoardShininess);
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, gMatDiffuse);
glPushMatrix();
ActivateFunctionShader (psFuncData);
uShaderProgram = GetShaderProgram (psFuncData->psShaderData);
if ((eFuncType == FUNCTYPE_SPHERICAL) || (eFuncType == FUNCTYPE_CURVE)) {
// Enable the spherical clipping planes
glClipPlane (GL_CLIP_PLANE0, afClipEquations[0]);
glClipPlane (GL_CLIP_PLANE1, afClipEquations[1]);
glClipPlane (GL_CLIP_PLANE2, afClipEquations[2]);
glClipPlane (GL_CLIP_PLANE3, afClipEquations[3]);
glEnable (GL_CLIP_PLANE0);
glEnable (GL_CLIP_PLANE1);
glEnable (GL_CLIP_PLANE2);
glEnable (GL_CLIP_PLANE3);
RecentreGraph (psFuncData);
}
pmLightTransform = GetLightTransform (psFuncData->psShadowData);
MultMatrixMatrix4 (& mLightTranslate, pmLightTransform, & psFuncData->mStructureTransform);
boColours = GetColour (afGraphColour, psFuncData);
uTexture = GetShadowTexture (psFuncData->psShadowData);
glActiveTexture (GL_TEXTURE2);
glBindTexture (GL_TEXTURE_2D, uTexture);
nVar = glGetUniformLocation (uShaderProgram, "tShadow");
glUniform1i (nVar, 2);
//uBumpMap = GetFunctionBumpTexture (psFuncData);
uTexture = GetFunctionTexture (psFuncData);
if (uTexture != TEXTURE_NONE) {
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_TEXTURE_2D);
glActiveTexture (GL_TEXTURE0);
glBindTexture (GL_TEXTURE_2D, uTexture);
nVar = glGetUniformLocation (uShaderProgram, "tTexture");
glUniform1i (nVar, 0);
//glActiveTexture (GL_TEXTURE1);
//glBindTexture (GL_TEXTURE_2D, uBumpMap);
//nVar = glGetUniformLocation (uShaderProgram, "tBumpMap");
//glUniform1i (nVar, 1);
glActiveTexture (GL_TEXTURE0);
//glBindTexture (GL_TEXTURE_2D, uTexture);
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
afTextureCoords = GetTextureCoords (psFuncData);
glEnableClientState (GL_VERTEX_ARRAY);
glEnableClientState (GL_NORMAL_ARRAY);
//nVar = glGetUniformLocation (uShaderProgram, "fTextureStrength");
//glUniform1fv (nVar, 1, (GLfloat *)(& psFuncData->fTextureStrength));
//nVar = glGetUniformLocation (uShaderProgram, "fBumpScale");
//glUniform1fv (nVar, 1, (GLfloat *)(& psFuncData->fBumpScale));
nVar = glGetUniformLocation (uShaderProgram, "mLightTransform");
glUniformMatrix4fv (nVar, 1, false, (GLfloat *)(mLightTranslate.aafM));
fShadowBias = GetShadowBias (psFuncData->psShadowData);
nVar = glGetUniformLocation (uShaderProgram, "fShadowBias");
glUniform1fv (nVar, 1, (GLfloat *)(& fShadowBias));
fShadowBlur = 2.0f / (float)ShadowGetScreenWidth (psFuncData->psShadowData);
nVar = glGetUniformLocation (uShaderProgram, "fShadowBlurX");
glUniform1fv (nVar, 1, (GLfloat *)(& fShadowBlur));
fShadowBlur = 2.0f / (float)ShadowGetScreenHeight (psFuncData->psShadowData);
nVar = glGetUniformLocation (uShaderProgram, "fShadowBlurY");
glUniform1fv (nVar, 1, (GLfloat *)(& fShadowBlur));
if (boColours) {
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, afGraphColour);
for (nXIndex = 0; nXIndex < nXVertices - 1; nXIndex++) {
glVertexPointer (3, GL_FLOAT, 0, afVertices + (nXIndex * (nYVertices * 3)));
glNormalPointer (GL_FLOAT, 0, afNormals + (nXIndex * (nYVertices * 3)));
if (uTexture != TEXTURE_NONE) {
glTexCoordPointer (2, GL_FLOAT, 0, afTextureCoords + (nXIndex * (nYVertices * 2)));
}
glDrawElements (GL_TRIANGLE_STRIP, nYVertices * 2, GL_UNSIGNED_SHORT, auIndices);
}
}
else {
afColours = GetColours (psFuncData);
glEnable (GL_COLOR_MATERIAL);
glEnableClientState (GL_COLOR_ARRAY);
for (nXIndex = 0; nXIndex < nXVertices - 1; nXIndex++) {
glVertexPointer (3, GL_FLOAT, 0, afVertices + (nXIndex * (nYVertices * 3)));
glNormalPointer (GL_FLOAT, 0, afNormals + (nXIndex * (nYVertices * 3)));
glColorPointer (4, GL_FLOAT, 0, afColours + (nXIndex * (nYVertices * 4)));
if (uTexture != TEXTURE_NONE) {
glTexCoordPointer (2, GL_FLOAT, 0, afTextureCoords + (nXIndex * (nYVertices * 2)));
}
glDrawElements (GL_TRIANGLE_STRIP, nYVertices * 2, GL_UNSIGNED_SHORT, auIndices);
}
glDisableClientState (GL_COLOR_ARRAY);
glDisable (GL_COLOR_MATERIAL);
}
glDisableClientState (GL_VERTEX_ARRAY);
glDisableClientState (GL_NORMAL_ARRAY);
if (uTexture != TEXTURE_NONE) {
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
glDisable (GL_TEXTURE_2D);
glDisable (GL_BLEND);
}
if ((eFuncType == FUNCTYPE_SPHERICAL) || (eFuncType == FUNCTYPE_CURVE)) {
// Disable the spherical clipping planes
glDisable (GL_CLIP_PLANE0);
glDisable (GL_CLIP_PLANE1);
glDisable (GL_CLIP_PLANE2);
glDisable (GL_CLIP_PLANE3);
}
DeactivateFunctionShader (psFuncData);
glPopMatrix ();
glDisable (GL_BLEND);
}
void DrawGraphShadow (FuncPersist * psFuncData) {
int nXIndex;
GLfloat * afVertices;
GLushort * auIndices;
int nYVertices;
int nXVertices;
FUNCTYPE eFuncType;
//GLuint uShaderProgram;
static GLdouble afClipEquations[4][4] = {{-1.0, 0.0, 0.0, AXIS_XHSIZE},
{1.0, 0.0, 0.0, AXIS_XHSIZE},
{0.0, -1.0, 0.0, AXIS_YHSIZE},
{0.0, 1.0, 0.0, AXIS_YHSIZE}};
eFuncType = GetFunctionType (psFuncData);
afVertices = GetVertices (psFuncData);
auIndices = GetIndices (psFuncData);
GetVertexDimensions (& nXVertices, & nYVertices, psFuncData);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
ActivateFunctionShaderShadow (psFuncData);
//uShaderProgram = GetShaderProgram (psFuncData->psShaderData);
if ((eFuncType == FUNCTYPE_SPHERICAL) || (eFuncType == FUNCTYPE_CURVE)) {
// Enable the spherical clipping planes
glClipPlane (GL_CLIP_PLANE0, afClipEquations[0]);
glClipPlane (GL_CLIP_PLANE1, afClipEquations[1]);
glClipPlane (GL_CLIP_PLANE2, afClipEquations[2]);
glClipPlane (GL_CLIP_PLANE3, afClipEquations[3]);
glEnable (GL_CLIP_PLANE0);
glEnable (GL_CLIP_PLANE1);
glEnable (GL_CLIP_PLANE2);
glEnable (GL_CLIP_PLANE3);
RecentreGraph (psFuncData);
}
glEnableClientState (GL_VERTEX_ARRAY);
for (nXIndex = 0; nXIndex < nXVertices - 1; nXIndex++) {
glVertexPointer (3, GL_FLOAT, 0, afVertices + (nXIndex * (nYVertices * 3)));
glDrawElements (GL_TRIANGLE_STRIP, nYVertices * 2, GL_UNSIGNED_SHORT, auIndices);
}
glDisableClientState (GL_VERTEX_ARRAY);
if ((eFuncType == FUNCTYPE_SPHERICAL) || (eFuncType == FUNCTYPE_CURVE)) {
// Disable the spherical clipping planes
glDisable (GL_CLIP_PLANE0);
glDisable (GL_CLIP_PLANE1);
glDisable (GL_CLIP_PLANE2);
glDisable (GL_CLIP_PLANE3);
}
DeactivateFunctionShaderShadow (psFuncData);
glPopMatrix ();
glDisable (GL_BLEND);
}
void RecentreGraph (FuncPersist * psFuncData) {
GLdouble afCentre[3];
Vector3 vTranslate;
......
......@@ -98,6 +98,8 @@ int OutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int
int CountStoredVertices (double fMultiplier, FuncPersist const * psFuncData);
int CountStoredFaces (double fMultiplier, FuncPersist const * psFuncData);
void RecentreGraph (FuncPersist * psFuncData);
void DrawGraph (FuncPersist * psFuncData);
void DrawGraphShadow (FuncPersist * psFuncData);
void AssignControlVarsToFunction (FnControlPersist * psFnControlData, FuncPersist * psFuncData);
void AssignControlVarsToFunctionPopulate (FnControlPersist * psFnControlData, FuncPersist * psFuncData);
void SetFunctionControlVars (FnControlPersist * psFnControlData, FuncPersist * psFuncData);
......
......@@ -199,7 +199,6 @@ void inline swap (float * pfVar1, float * pfVar2);
void inline order (float * pfVar1, float * pfVar2);
void DrawAxes (VisPersist * psVisData);
void DrawGraphs (VisPersist * psVisData);
void DrawGraph (FuncPersist * psFuncData);
GLfloat SelectFunction (int nXPos, int nYPos, VisPersist * psVisData);
void ConvertCoords (GLdouble fXMousePos, GLdouble fYMousePos, float fZPos, double * pfX, double * pfY, double * pfZ, VisPersist * psVisData);
void ShuntFunctionPosition (double fX, double fY, double fZ, VisPersist * psVisData);
......@@ -393,6 +392,7 @@ FuncPersist * AddNewFunction (FUNCTYPE eType, VisPersist * psVisData) {
psFuncData = NewFuncPersist (eType);
SetFunctionTexture (TEXTURE_NONE, psFuncData);
SetFunctionControlVars (psVisData->psFnControlData, psFuncData);
SetFunctionShadowData (psVisData->psShadowData, psFuncData);
psVisData->psFuncList = g_slist_append (psVisData->psFuncList, psFuncData);
......@@ -1500,124 +1500,6 @@ void DrawGraphs (VisPersist * psVisData) {
}
}
void DrawGraph (FuncPersist * psFuncData) {
int nXIndex;
GLfloat * afVertices;
GLfloat * afNormals;
GLushort * auIndices;
GLfloat * afColours;
GLfloat * afTextureCoords;
int nYVertices;
int nXVertices;
GLfloat afGraphColour[4];
bool boColours;
FUNCTYPE eFuncType;
GLuint uTexture;
static GLdouble afClipEquations[4][4] = {{-1.0, 0.0, 0.0, AXIS_XHSIZE},
{1.0, 0.0, 0.0, AXIS_XHSIZE},
{0.0, -1.0, 0.0, AXIS_YHSIZE},
{0.0, 1.0, 0.0, AXIS_YHSIZE}};
eFuncType = GetFunctionType (psFuncData);
afVertices = GetVertices (psFuncData);
afNormals = GetNormals (psFuncData);
auIndices = GetIndices (psFuncData);
GetVertexDimensions (& nXVertices, & nYVertices, psFuncData);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, gBoardSpecular);
glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, gBoardShininess);
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, gMatDiffuse);
glPushMatrix();
ActivateFunctionShader (psFuncData);
if ((eFuncType == FUNCTYPE_SPHERICAL) || (eFuncType == FUNCTYPE_CURVE)) {
// Enable the spherical clipping planes
glClipPlane (GL_CLIP_PLANE0, afClipEquations[0]);
glClipPlane (GL_CLIP_PLANE1, afClipEquations[1]);
glClipPlane (GL_CLIP_PLANE2, afClipEquations[2]);
glClipPlane (GL_CLIP_PLANE3, afClipEquations[3]);
glEnable (GL_CLIP_PLANE0);
glEnable (GL_CLIP_PLANE1);
glEnable (GL_CLIP_PLANE2);
glEnable (GL_CLIP_PLANE3);
RecentreGraph (psFuncData);
}
boColours = GetColour (afGraphColour, psFuncData);
uTexture = GetFunctionTexture (psFuncData);
if (uTexture != TEXTURE_NONE) {
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, uTexture);
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
}
afTextureCoords = GetTextureCoords (psFuncData);
glEnableClientState (GL_VERTEX_ARRAY);
glEnableClientState (GL_NORMAL_ARRAY);
if (boColours) {
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, afGraphColour);
for (nXIndex = 0; nXIndex < nXVertices - 1; nXIndex++) {
glVertexPointer (3, GL_FLOAT, 0, afVertices + (nXIndex * (nYVertices * 3)));
glNormalPointer (GL_FLOAT, 0, afNormals + (nXIndex * (nYVertices * 3)));
if (uTexture != TEXTURE_NONE) {
glTexCoordPointer (2, GL_FLOAT, 0, afTextureCoords + (nXIndex * (nYVertices * 2)));
}
glDrawElements (GL_TRIANGLE_STRIP, nYVertices * 2, GL_UNSIGNED_SHORT, auIndices);
}
}
else {
afColours = GetColours (psFuncData);
glEnable (GL_COLOR_MATERIAL);
glEnableClientState (GL_COLOR_ARRAY);
for (nXIndex = 0; nXIndex < nXVertices - 1; nXIndex++) {
glVertexPointer (3, GL_FLOAT, 0, afVertices + (nXIndex * (nYVertices * 3)));
glNormalPointer (GL_FLOAT, 0, afNormals + (nXIndex * (nYVertices * 3)));
glColorPointer (4, GL_FLOAT, 0, afColours + (nXIndex * (nYVertices * 4)));
if (uTexture != TEXTURE_NONE) {
glTexCoordPointer (2, GL_FLOAT, 0, afTextureCoords + (nXIndex * (nYVertices * 2)));
}
glDrawElements (GL_TRIANGLE_STRIP, nYVertices * 2, GL_UNSIGNED_SHORT, auIndices);
}
glDisableClientState (GL_COLOR_ARRAY);
glDisable (GL_COLOR_MATERIAL);
}
glDisableClientState (GL_VERTEX_ARRAY);
glDisableClientState (GL_NORMAL_ARRAY);
if (uTexture != TEXTURE_NONE) {
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
glDisable (GL_TEXTURE_2D);
glDisable (GL_BLEND);
}
if ((eFuncType == FUNCTYPE_SPHERICAL) || (eFuncType == FUNCTYPE_CURVE)) {
// Disable the spherical clipping planes
glDisable (GL_CLIP_PLANE0);
glDisable (GL_CLIP_PLANE1);
glDisable (GL_CLIP_PLANE2);
glDisable (GL_CLIP_PLANE3);
}
DeactivateFunctionShader (psFuncData);
glPopMatrix ();
glDisable (GL_BLEND);
}
void DrawTextOverlay (VisPersist * psVisData) {
GString * szString;
//int nStringWidth;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment