Commit 9611c761 authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

Added additional Functy code to support shader rendering using control variables.

parent a835c983
......@@ -8,6 +8,8 @@ varying float fDist;
varying vec3 vFuncParams;
varying mat3 vNormalMatrix;
/*REPLACE:controlvars*//*END*/
float DifferentialX (float x, float y, float t);
float DifferentialY (float x, float y, float t);
vec4 Colour (float x, float y, float z, float t);
......
......@@ -8,6 +8,8 @@ varying float fDist;
varying vec3 vFuncParams;
varying mat3 vNormalMatrix;
/*REPLACE:controlvars*//*END*/
float FunctionZ (float x, float y, float t);
void main() {
......
......@@ -8,6 +8,8 @@ varying float fDist;
varying vec3 vFuncParams;
varying mat3 vNormalMatrix;
/*REPLACE:controlvars*//*END*/
float FunctionR (float a, float p, float t);
vec3 FunctionD1 (float a, float t);
vec3 FunctionD2 (float a, float t);
......
......@@ -8,6 +8,8 @@ varying float fDist;
varying vec3 vFuncParams;
varying mat3 vNormalMatrix;
/*REPLACE:controlvars*//*END*/
vec3 FunctionC (float a, float t);
float FunctionR (float a, float p, float t);
vec3 FunctionD1 (float a, float t);
......
......@@ -8,6 +8,8 @@ varying float fDist;
varying vec3 vFuncParams;
varying mat3 vNormalMatrix;
/*REPLACE:controlvars*//*END*/
float DifferentialA (float a, float p, float t);
float DifferentialP (float a, float p, float t);
vec4 Colour (float a, float p, float r, float t);
......
......@@ -8,6 +8,8 @@ varying float fDist;
varying vec3 vFuncParams;
varying mat3 vNormalMatrix;
/*REPLACE:controlvars*//*END*/
float FunctionR (float a, float p, float t);
void main() {
......
......@@ -37,9 +37,33 @@ struct _ControlvarPersist {
///////////////////////////////////////////////////////////////////
// Function prototypes
void DeleteControlvarDataCallback (gpointer data, gpointer user_data);
///////////////////////////////////////////////////////////////////
// Function definitions
FnControlPersist * NewFnControlPersist () {
FnControlPersist * psFnControlData;
psFnControlData = g_new0 (FnControlPersist, 1);
psFnControlData->psControlvarList = NULL;
return psFnControlData;
}
void DeleteFnControlPersist (FnControlPersist * psFnControlData) {
// Delete all of the control varaibles
g_slist_foreach (psFnControlData->psControlvarList, DeleteControlvarDataCallback, NULL);
g_slist_free (psFnControlData->psControlvarList);
g_free (psFnControlData);
}
void DeleteControlvarDataCallback (gpointer data, gpointer user_data) {
DeleteControlvarPersist ((ControlvarPersist *)data);
}
ControlvarPersist * NewControlvarPersist () {
ControlvarPersist * psControlvarData;
......@@ -108,7 +132,7 @@ gint ControlvarCompare (gconstpointer a, gconstpointer b) {
return nResult;
}
bool AssignControlVarsToVariables (GSList * psControlVars, Variable * psVariables) {
bool AssignControlVarsToVariables (FnControlPersist * psFnControlData, Variable * psVariables) {
GSList * psToAssign;
Variable * psVarFound;
char const * szVarName;
......@@ -116,7 +140,7 @@ bool AssignControlVarsToVariables (GSList * psControlVars, Variable * psVariable
bool boFound;
boFound = FALSE;
psToAssign = psControlVars;
psToAssign = psFnControlData->psControlvarList;
while (psToAssign) {
szVarName = GetControlvarName ((ControlvarPersist *)psToAssign->data);
......
......@@ -24,12 +24,19 @@
typedef struct _ControlvarPersist ControlvarPersist;
typedef struct _FnControlPersist {
GSList * psControlvarList;
} FnControlPersist;
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
FnControlPersist * NewFnControlPersist ();
void DeleteFnControlPersist (FnControlPersist * psFnControlData);
ControlvarPersist * NewControlvarPersist ();
void DeleteControlvarPersist (ControlvarPersist * psControlvarData);
......@@ -39,7 +46,7 @@ char const * GetControlvarName (ControlvarPersist * psControlvarData);
char const * GetControlvarValueString (ControlvarPersist * psControlvarData);
double GetControlvarValueDouble (ControlvarPersist * psControlvarData);
gint ControlvarCompare (gconstpointer a, gconstpointer b);
bool AssignControlVarsToVariables (GSList * psControlVars, Variable * psVariables);
bool AssignControlVarsToVariables (FnControlPersist * psFnControlData, Variable * psVariables);
///////////////////////////////////////////////////////////////////
// Function definitions
......
......@@ -16,7 +16,6 @@
#include "function.h"
#include "function_private.h"
#include "textures.h"
#include "controlvar.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -33,6 +32,7 @@
// Function prototypes
void GenerateVertices (FuncPersist * psFuncData);
char * ShaderAddControlVars (char * szShader, FnControlPersist * psFnControlData, FuncPersist * psFuncData);
///////////////////////////////////////////////////////////////////
// Function definitions
......@@ -109,6 +109,8 @@ FuncPersist * NewFuncPersist (FUNCTYPE eType) {
psFuncData->szShaderBlue = g_string_new ("1");
psFuncData->szShaderAlpha = g_string_new ("1");
psFuncData->psFnControlData = NULL;
InitShader (psFuncData);
SetFunction (FUNCTION0, psFuncData);
......@@ -250,6 +252,10 @@ void InitShader (FuncPersist * psFuncData) {
}
}
void SetFunctionControlVars (FnControlPersist * psFnControlData, FuncPersist * psFuncData) {
psFuncData->psFnControlData = psFnControlData;
}
void LoadVertexShader (char const * const szFilename, FuncPersist * psFuncData) {
// Free up any previously loaded shader source
if (psFuncData->szShaderVertexSource) {
......@@ -349,6 +355,7 @@ void FunctionShadersRegenerate (FuncPersist * psFuncData) {
// Do absolutely nothing
break;
}
szShader = ShaderAddControlVars (szShader, psFuncData->psFnControlData, psFuncData);
ShaderRegenerateVertex (szShader, psFuncData->psShaderData);
if (szShader) {
......@@ -371,6 +378,7 @@ void FunctionShadersRegenerate (FuncPersist * psFuncData) {
// Do absolutely nothing
break;
}
szShader = ShaderAddControlVars (szShader, psFuncData->psFnControlData, psFuncData);
ShaderRegenerateFragment (szShader, psFuncData->psShaderData);
if (szShader) {
......@@ -841,10 +849,14 @@ int CountStoredFaces (double fMultiplier, FuncPersist const * psFuncData) {
return nFaces;
}
void AssignControlVarsToFunction (GSList * psControlVars, FuncPersist * psFuncData) {
void AssignControlVarsToFunction (FnControlPersist * psFnControlData, FuncPersist * psFuncData) {
AssignControlVarsToVariables (psFnControlData, psFuncData->psVariables);
}
void AssignControlVarsToFunctionPopulate (FnControlPersist * psFnControlData, FuncPersist * psFuncData) {
bool boFound;
boFound = AssignControlVarsToVariables (psControlVars, psFuncData->psVariables);
boFound = AssignControlVarsToVariables (psFnControlData, psFuncData->psVariables);
psFuncData->psVariables = FreeVariables (psFuncData->psVariables);
if (boFound) {
......@@ -852,3 +864,33 @@ void AssignControlVarsToFunction (GSList * psControlVars, FuncPersist * psFuncDa
}
}
char * ShaderAddControlVars (char * szShader, FnControlPersist * psFnControlData, FuncPersist * psFuncData) {
GString * szControlVarBlock;
char const * szVarName;
GSList * psControlvarList;
if (psFnControlData) {
szControlVarBlock = g_string_new ("");
// First check whether the varaible is already there
psControlvarList = psFnControlData->psControlvarList;
while (psControlvarList) {
szVarName = GetControlvarName (((ControlvarPersist *)(psControlvarList->data)));
g_string_append_printf (szControlVarBlock, "uniform float %s;\n", szVarName);
psControlvarList = g_slist_next (psControlvarList);
}
if (szShader) {
szShader = ReplaceTextMove (szShader, "controlvars", szControlVarBlock->str);
}
g_string_free (szControlVarBlock, TRUE);
}
return szShader;
}
......@@ -15,6 +15,7 @@
// Includes
#include "recall.h"
#include "controlvar.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -92,7 +93,9 @@ int OutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenCoords, bo
int OutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int CountStoredVertices (double fMultiplier, FuncPersist const * psFuncData);
int CountStoredFaces (double fMultiplier, FuncPersist const * psFuncData);
void AssignControlVarsToFunction (GSList * psControlVars, FuncPersist * psFuncData);
void AssignControlVarsToFunction (FnControlPersist * psFnControlData, FuncPersist * psFuncData);
void AssignControlVarsToFunctionPopulate (FnControlPersist * psFnControlData, FuncPersist * psFuncData);
void SetFunctionControlVars (FnControlPersist * psFnControlData, FuncPersist * psFuncData);
///////////////////////////////////////////////////////////////////
// Function definitions
......
......@@ -97,6 +97,9 @@ struct _FuncPersist {
GString * szShaderGreen;
GString * szShaderBlue;
GString * szShaderAlpha;
// Control variables - this is only a pointer, do doesn't need to be freed
FnControlPersist * psFnControlData;
};
///////////////////////////////////////////////////////////////////
......
......@@ -810,6 +810,8 @@ static gboolean PlotFunctionApply (GtkWidget * psWidget, gpointer psData) {
break;
}
AssignControlVarsSingle (psFunctyData->psFuncEdit, psFunctyData->psVisData);
PopulateVertices (psFunctyData->psFuncEdit);
gdk_window_invalidate_rect (psFunctionList->window, NULL, TRUE);
......@@ -903,6 +905,8 @@ static gboolean PlotFunctionApply (GtkWidget * psWidget, gpointer psData) {
AddFunction (psFuncData, psFunctionListModel);
psFunctyData->psFuncEdit = psFuncData;
AssignControlVarsSingle (psFunctyData->psFuncEdit, psFunctyData->psVisData);
}
g_free (szRed);
......
......@@ -27,7 +27,6 @@
#include "spherical.h"
#include "curve.h"
#include "exportply.h"
#include "controlvar.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -149,7 +148,7 @@ struct _VisPersist {
GSList * psFuncList;
GSList * psControlvarList;
FnControlPersist * psFnControlData;
TexPersist * psTexData;
GLfloat afTexCoords[4];
......@@ -194,7 +193,6 @@ void DrawNumbersX (double fY, double fZ, VisPersist * psVisData);
void DrawNumbersY (double fX, double fZ, VisPersist * psVisData);
void DrawNumbersZ (double fX, double fY, VisPersist * psVisData);
void DeleteFuncDataCallback (gpointer data, gpointer user_data);
void DeleteControlvarDataCallback (gpointer data, gpointer user_data);
void ShuntFunctionPositionCallback (gpointer data, gpointer user_data);
void AnimateFunction (VisPersist * psVisData);
void SetFunctionPositionCallback (gpointer data, gpointer user_data);
......@@ -280,7 +278,9 @@ VisPersist * NewVisPersist (void) {
// Make sure the function list is empty
psVisData->psFuncList = NULL;
psVisData->psControlvarList = NULL;
psVisData->psFnControlData = NewFnControlPersist ();
/*
// Add a function to the list
......@@ -312,8 +312,7 @@ void DeleteVisPersist (VisPersist * psVisData) {
g_slist_free (psVisData->psFuncList);
// Delete all of the control varaibles
g_slist_foreach (psVisData->psControlvarList, DeleteControlvarDataCallback, NULL);
g_slist_free (psVisData->psControlvarList);
DeleteFnControlPersist (psVisData->psFnControlData);
// Free the textures
DeleteTexPersist (psVisData->psTexData);
......@@ -326,15 +325,12 @@ void DeleteFuncDataCallback (gpointer data, gpointer user_data) {
DeleteFuncPersist ((FuncPersist *)data);
}
void DeleteControlvarDataCallback (gpointer data, gpointer user_data) {
DeleteControlvarPersist ((ControlvarPersist *)data);
}
FuncPersist * AddNewFunction (FUNCTYPE eType, VisPersist * psVisData) {
FuncPersist * psFuncData;
psFuncData = NewFuncPersist (eType);
SetFunctionTexture (TEXTURE_NONE, psFuncData);
SetFunctionControlVars (psVisData->psFnControlData, psFuncData);
psVisData->psFuncList = g_slist_append (psVisData->psFuncList, psFuncData);
......@@ -2185,7 +2181,7 @@ void SetControlVar (char const * const szVarName, char const * const szVarValue,
// First check whether the varaible is already there
psControlvarData = NULL;
psControlvarList = psVisData->psControlvarList;
psControlvarList = psVisData->psFnControlData->psControlvarList;
while (psControlvarList) {
szSearchName = GetControlvarName (((ControlvarPersist *)(psControlvarList->data)));
......@@ -2199,7 +2195,7 @@ void SetControlVar (char const * const szVarName, char const * const szVarValue,
if (psControlvarData == NULL) {
// Create the variable
psControlvarData = NewControlvarPersist ();
psVisData->psControlvarList = g_slist_append (psVisData->psControlvarList, psControlvarData);
psVisData->psFnControlData->psControlvarList = g_slist_append (psVisData->psFnControlData->psControlvarList, psControlvarData);
}
// Set the variable value
......@@ -2207,16 +2203,19 @@ void SetControlVar (char const * const szVarName, char const * const szVarValue,
SetControlvarValue (szVarValue, psControlvarData);
}
GSList * GetControlVarList (VisPersist * psVisData) {
return psVisData->psControlvarList;
FnControlPersist * GetControlVarList (VisPersist * psVisData) {
return psVisData->psFnControlData;
}
void AssignControlVarsToFunctionList (VisPersist * psVisData) {
g_slist_foreach (psVisData->psFuncList, AssignControlVarsCallback, psVisData->psControlvarList);
g_slist_foreach (psVisData->psFuncList, AssignControlVarsCallback, psVisData->psFnControlData);
}
void AssignControlVarsCallback (gpointer data, gpointer user_data) {
AssignControlVarsToFunction ((GSList *)user_data, (FuncPersist *)data);
AssignControlVarsToFunctionPopulate ((FnControlPersist *)user_data, (FuncPersist *)data);
}
void AssignControlVarsSingle (FuncPersist * psFuncData, VisPersist * psVisData) {
AssignControlVarsToFunction (psVisData->psFnControlData, psFuncData);
}
......@@ -16,6 +16,7 @@
#include "utils.h"
#include "function.h"
#include "controlvar.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -106,8 +107,9 @@ bool ExportModelFile (char const * szFilename, bool boBinary, bool boScreenCoord
bool ExportModelFileAnimated (char const * szFilename, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, double fScale, double fTimeStart, double fTimeEnd, int nFrames, VisPersist * psVisData);
void PauseAnimation (bool boPause, VisPersist * psVisData);
void SetControlVar (char const * const szVarName, char const * const szVarValue, VisPersist * psVisData);
GSList * GetControlVarList (VisPersist * psVisData);
FnControlPersist * GetControlVarList (VisPersist * psVisData);
void AssignControlVarsToFunctionList (VisPersist * psVisData);
void AssignControlVarsSingle (FuncPersist * psFuncData, VisPersist * psVisData);
///////////////////////////////////////////////////////////////////
// Function definitions
......
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