#include <gl_Cg_shader.h>
Public Member Functions | |
void | addUniform (Uniform *uniform) |
void | bind () |
Bind our object. | |
void | compile (const std::string &Parameters=std::string()) |
Compiles current shader. | |
const std::string & | getClassName () const |
Returns name of class of our object. | |
std::string | getLanguageID () const |
const std::string & | getObjectName () const |
Returns name of our object. | |
std::string | getSource () const |
Returns current source of shader. | |
void | getSpecificParameter (const std::string &ParameterName, void *ParameterValue) |
Method for obtaining some specific parameters, such as texture specific params, and so on. | |
GLCgShader (const std::string &ShaderName, CGcontext CgContext, CGprofile CgProfile, ShaderSystem *system) | |
bool | isActive () const |
bool | isCompiled () const |
Simple method for checking compilation status. | |
bool | isDebugEnabled () const |
Check for debugging our shader. | |
bool | isLocked () const |
returns state of object. | |
void | preCompute () |
Precompute shader. | |
void | removeUniform (Uniform *uniform) |
Remove uniform variable from shader. | |
void | setSource (const std::string &ShaderSource) |
Performs basic initialization of shader and sets up shader source. | |
void | unbind () |
Unbind our object. | |
void | validate () |
Validate Shader. | |
~GLCgShader () | |
Protected Member Functions | |
void | addSpecificParameter (const std::string &ParameterName, void *ParameterValue, size_t Size) |
void | lock () |
void | unlock () |
Private Types | |
typedef std::list< Uniform * > | UniformVector |
Private Member Functions | |
void | setUniformSampler (Uniform *uniform) |
void | setUniformVariable (Uniform *uniform) |
Private Attributes | |
CGcontext | mCgContextID |
Setting up these variables performs in method CgGLShaderSystem::createShader. | |
CGprofile | mCgFragmentProfileID |
CGprogram | mCgFragmentProgramID |
bool | mIsCompiled |
bool | mIsDebug |
std::string | mShaderCompilerParams |
std::string | mShaderSource |
UniformVector | mUniformVector |
Friends | |
class | GLCgShaderSystem |
Definition at line 46 of file gl_Cg_shader.h.
typedef std::list<Uniform *> gpucalc::GLCgShader::UniformVector [private] |
Definition at line 139 of file gl_Cg_shader.h.
gpucalc::GLCgShader::GLCgShader | ( | const std::string & | ShaderName, | |
CGcontext | CgContext, | |||
CGprofile | CgProfile, | |||
ShaderSystem * | system | |||
) |
Definition at line 43 of file gl_Cg_shader.cpp.
00043 : 00044 Object(_GLCgShaderClassName, ShaderName), Shader(_GLCgShaderClassName, ShaderName, system), mCgContextID(CgContext), 00045 mCgFragmentProfileID(CgProfile),mIsCompiled(false), mIsDebug(false), mShaderSource(), mShaderCompilerParams(), mUniformVector() 00046 { 00047 }
gpucalc::GLCgShader::~GLCgShader | ( | ) |
Definition at line 50 of file gl_Cg_shader.cpp.
00051 { 00052 cgDestroyProgram(mCgFragmentProgramID); 00053 }
void gpucalc::Object::addSpecificParameter | ( | const std::string & | ParameterName, | |
void * | ParameterValue, | |||
size_t | Size | |||
) | [inline, protected, inherited] |
Definition at line 254 of file object.h.
00255 { 00256 SpecificParametersMap::iterator i = mSpecificParameters.find(ParameterName); 00257 if (i != mSpecificParameters.end()) 00258 { 00259 mSpecificParameters.erase(i); 00260 } 00261 mSpecificParameters[ParameterName] = Any(ParameterValue, Size); 00262 }
void gpucalc::GLCgShader::addUniform | ( | Uniform * | uniform | ) | [virtual] |
Set uniform variable, declared in our shader.
uniform | - pointer to class Uniform, that contain all necessary members for correct setting uniform variable. |
Implements gpucalc::Shader.
Definition at line 63 of file gl_Cg_shader.cpp.
00064 { 00065 if (addToContainer(uniform, mUniformVector)) 00066 { 00067 uniform->uploadToGPU(); 00068 } 00069 }
void gpucalc::Shader::bind | ( | ) | [inline, virtual, inherited] |
Bind our object.
For example, set in some active state (Texture, Shader and so on)
Implements gpucalc::Bindable.
Definition at line 140 of file shader.h.
00141 { 00142 mDefaultShaderSystem->bind(this); 00143 }
void gpucalc::GLCgShader::compile | ( | const std::string & | Parameters = std::string() |
) | [virtual] |
Compiles current shader.
Implements gpucalc::Shader.
Definition at line 78 of file gl_Cg_shader.cpp.
00079 { 00080 //remember compiler params for recompilation 00081 mShaderCompilerParams = Parameters; 00082 00083 if (mIsCompiled) 00084 { 00085 cgDestroyProgram(mCgFragmentProgramID); 00086 } 00087 00088 LogManager::getSingleton().logMessage(this, "Using following compiler parameters: \"" + Parameters + "\".", LML_Critical); 00089 const char ** Params = new const char * [2]; 00090 Params[0] = Parameters.c_str(); 00091 Params[1] = 0; 00092 mCgFragmentProgramID = cgCreateProgram(mCgContextID, CG_SOURCE, mShaderSource.c_str(), 00093 mCgFragmentProfileID, "main", Params); 00094 00095 delete [] Params; 00096 00097 cgGLLoadProgram(mCgFragmentProgramID); 00098 mIsCompiled = true; 00099 mIsDebug = (Parameters.find("-debug") != std::string::npos); 00100 }
const std::string& gpucalc::Object::getClassName | ( | ) | const [inline, inherited] |
Returns name of class of our object.
Definition at line 92 of file object.h.
00093 { 00094 return mClassName; 00095 }
std::string gpucalc::GLCgShader::getLanguageID | ( | ) | const [inline, virtual] |
const std::string& gpucalc::Object::getObjectName | ( | ) | const [inline, inherited] |
Returns name of our object.
Definition at line 101 of file object.h.
00102 { 00103 return mObjectName; 00104 }
std::string gpucalc::GLCgShader::getSource | ( | ) | const [inline, virtual] |
Returns current source of shader.
Implements gpucalc::Shader.
Definition at line 66 of file gl_Cg_shader.h.
00067 { 00068 return mShaderSource; 00069 }
void gpucalc::Object::getSpecificParameter | ( | const std::string & | ParameterName, | |
void * | ParameterValue | |||
) | [inline, inherited] |
Method for obtaining some specific parameters, such as texture specific params, and so on.
ParameterName | - name of parameter, usually it similar to specific method of some object (for example, GLTextureID) | |
ParameterValue | - contain value of named parameter, it must be allocated and have sufficient size. |
Definition at line 128 of file object.h.
00129 { 00130 SpecificParametersMap::iterator i = mSpecificParameters.find(ParameterName); 00131 if (i != mSpecificParameters.end()) 00132 { 00133 i->second.copyValue(ParameterValue); 00134 } 00135 else 00136 { 00137 Except<ERR_ITEM_NOT_FOUND>(this, "Parameter \"" + ParameterName + "\" does not exists.", "Object::getSpecificParameter()", __FILE__, __LINE__); 00138 } 00139 }
bool gpucalc::Shader::isActive | ( | ) | const [inline, virtual, inherited] |
Implements gpucalc::Bindable.
Definition at line 134 of file shader.h.
00135 { 00136 return (this == mDefaultShaderSystem->getActiveShader()); 00137 }
bool gpucalc::GLCgShader::isCompiled | ( | ) | const [inline, virtual] |
Simple method for checking compilation status.
Implements gpucalc::Shader.
Definition at line 84 of file gl_Cg_shader.h.
00085 { 00086 return mIsCompiled; 00087 }
bool gpucalc::GLCgShader::isDebugEnabled | ( | ) | const [inline, virtual] |
Check for debugging our shader.
Implements gpucalc::Shader.
Definition at line 96 of file gl_Cg_shader.h.
00097 { 00098 return mIsDebug; 00099 }
bool gpucalc::Object::isLocked | ( | ) | const [inline, inherited] |
void gpucalc::Object::lock | ( | ) | [inline, protected, inherited] |
void gpucalc::GLCgShader::preCompute | ( | ) | [virtual] |
Precompute shader.
Implements gpucalc::Shader.
Definition at line 109 of file gl_Cg_shader.cpp.
00110 { 00111 if (!mIsCompiled) 00112 { 00113 compile(mShaderCompilerParams); 00114 } 00115 00116 bind(); 00117 cgGLEnableProfile(mCgFragmentProfileID); 00118 for (UniformVector::iterator i = mUniformVector.begin(); i != mUniformVector.end(); ++i) 00119 { 00120 Uniform * uniform = (*i); 00121 Uniform::UniformType uniform_type = uniform->getUniformType(); 00122 if ((uniform_type == Uniform::UT_TEX_1) || (uniform_type == Uniform::UT_TEX_2)) 00123 { 00124 setUniformSampler(uniform); 00125 } 00126 else 00127 { 00128 setUniformVariable(uniform); 00129 } 00130 } 00131 }
void gpucalc::GLCgShader::removeUniform | ( | Uniform * | uniform | ) | [virtual] |
Remove uniform variable from shader.
Implements gpucalc::Shader.
Definition at line 72 of file gl_Cg_shader.cpp.
00073 { 00074 removeFromContainer(uniform, mUniformVector); 00075 }
void gpucalc::GLCgShader::setSource | ( | const std::string & | ShaderSource | ) | [virtual] |
Performs basic initialization of shader and sets up shader source.
Depending on shader type this method can compile shader or not.
Implements gpucalc::Shader.
Definition at line 56 of file gl_Cg_shader.cpp.
00057 { 00058 mShaderSource = ShaderSource; 00059 mIsCompiled = false; 00060 }
void gpucalc::GLCgShader::setUniformSampler | ( | Uniform * | uniform | ) | [private] |
Definition at line 192 of file gl_Cg_shader.cpp.
00193 { 00194 CGparameter SamplerParameter = cgGetNamedParameter(mCgFragmentProgramID, uniform->getObjectName().c_str()); 00195 00196 GLuint GLTextureID = 0; 00197 uniform->getSampler()->getSpecificParameter("GLTextureID", &GLTextureID); 00198 cgGLSetTextureParameter(SamplerParameter, GLTextureID); 00199 cgGLEnableTextureParameter(SamplerParameter); 00200 }
void gpucalc::GLCgShader::setUniformVariable | ( | Uniform * | uniform | ) | [private] |
Definition at line 134 of file gl_Cg_shader.cpp.
00135 { 00136 CGparameter VariableParameter = cgGetNamedParameter(mCgFragmentProgramID, uniform->getObjectName().c_str()); 00137 switch (uniform->getUniformType()) 00138 { 00139 case Uniform::UT_INT_1: 00140 cgSetParameter1iv(VariableParameter, static_cast<const int *>(uniform->pointer())); 00141 break; 00142 00143 case Uniform::UT_INT_2: 00144 cgSetParameter2iv(VariableParameter, static_cast<const int *>(uniform->pointer())); 00145 break; 00146 00147 case Uniform::UT_INT_3: 00148 cgSetParameter3iv(VariableParameter, static_cast<const int *>(uniform->pointer())); 00149 break; 00150 00151 case Uniform::UT_INT_4: 00152 cgSetParameter4iv(VariableParameter, static_cast<const int *>(uniform->pointer())); 00153 break; 00154 00155 case Uniform::UT_FLOAT_1: 00156 cgSetParameter1fv(VariableParameter, static_cast<const float *>(uniform->pointer())); 00157 break; 00158 00159 00160 case Uniform::UT_FLOAT_2: 00161 cgSetParameter2fv(VariableParameter, static_cast<const float *>(uniform->pointer())); 00162 break; 00163 00164 case Uniform::UT_FLOAT_3: 00165 cgSetParameter3fv(VariableParameter, static_cast<const float *>(uniform->pointer())); 00166 break; 00167 00168 case Uniform::UT_FLOAT_4: 00169 cgSetParameter4fv(VariableParameter, static_cast<const float *>(uniform->pointer())); 00170 break; 00171 00172 00173 /*case Uniform::UT_MAT_2X2: 00174 cgSetParameter1iv(VariableParameter, false, static_cast<const float *>(uniform->pointer())); 00175 break; 00176 00177 case Uniform::UT_MAT_3X3: 00178 cgSetParameter1iv(VariableParameter, false, static_cast<const float *>(uniform->pointer())); 00179 break; 00180 00181 case Uniform::UT_MAT_4X4: 00182 cgSetParameter1iv(VariableParameter, false, static_cast<const float *>(uniform->pointer())); 00183 break; 00184 */ 00185 default: 00186 Except<ERR_NOT_IMPLEMENTED>(this, "Other uniform types not implemented.", "GLCgShader::setUniformVariable", __FILE__, __LINE__); 00187 break; 00188 } 00189 }
void gpucalc::Shader::unbind | ( | ) | [inline, virtual, inherited] |
Unbind our object.
For example, set in some inactive state (Texture, Shader and so on)
Implements gpucalc::Bindable.
Definition at line 146 of file shader.h.
00147 { 00148 mDefaultShaderSystem->unbind(this); 00149 }
void gpucalc::Object::unlock | ( | ) | [inline, protected, inherited] |
void gpucalc::GLCgShader::validate | ( | ) | [virtual] |
Validate Shader.
This method checks that all uniform variables are set. Also it checks that this program is ready for use.
Implements gpucalc::Shader.
Definition at line 103 of file gl_Cg_shader.cpp.
friend class GLCgShaderSystem [friend] |
Definition at line 53 of file gl_Cg_shader.h.
CGcontext gpucalc::GLCgShader::mCgContextID [private] |
Setting up these variables performs in method CgGLShaderSystem::createShader.
Definition at line 112 of file gl_Cg_shader.h.
CGprofile gpucalc::GLCgShader::mCgFragmentProfileID [private] |
Definition at line 115 of file gl_Cg_shader.h.
CGprogram gpucalc::GLCgShader::mCgFragmentProgramID [private] |
Definition at line 118 of file gl_Cg_shader.h.
bool gpucalc::GLCgShader::mIsCompiled [private] |
Definition at line 121 of file gl_Cg_shader.h.
bool gpucalc::GLCgShader::mIsDebug [private] |
Definition at line 124 of file gl_Cg_shader.h.
std::string gpucalc::GLCgShader::mShaderCompilerParams [private] |
Definition at line 136 of file gl_Cg_shader.h.
std::string gpucalc::GLCgShader::mShaderSource [private] |
Definition at line 133 of file gl_Cg_shader.h.
Definition at line 140 of file gl_Cg_shader.h.