OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ShaderCall Class Reference

#include <C4Shader.h>

Public Member Functions

 C4ShaderCall (const C4Shader *pShader)
 
 ~C4ShaderCall ()
 
GLint GetAttribute (int iAttribute) const
 
GLint AllocTexUnit (int iUniform)
 
void SetUniform1i (int iUniform, int iX) const
 
void SetUniform1f (int iUniform, float gX) const
 
void SetUniform2f (int iUniform, float gX, float gY) const
 
void SetUniform1iv (int iUniform, int iLength, const int *pVals) const
 
void SetUniform1fv (int iUniform, int iLength, const float *pVals) const
 
void SetUniform2fv (int iUniform, int iLength, const float *pVals) const
 
void SetUniform3fv (int iUniform, int iLength, const float *pVals) const
 
void SetUniform4fv (int iUniform, int iLength, const float *pVals) const
 
void SetUniformMatrix2x3fv (int iUniform, int iLength, const float *pVals) const
 
void SetUniformMatrix3x3fv (int iUniform, int iLength, const float *pVals) const
 
void SetUniformMatrix3x4fv (int iUniform, int iLength, const float *pVals) const
 
void SetUniformMatrix4x4fv (int iUniform, int iLength, const float *pVals) const
 
void SetUniformMatrix3x3 (int iUniform, const StdMeshMatrix &matrix)
 
void SetUniformMatrix3x3Transpose (int iUniform, const StdMeshMatrix &matrix)
 
void SetUniformMatrix3x4 (int iUniform, const StdMeshMatrix &matrix)
 
void SetUniformMatrix4x4 (int iUniform, const StdMeshMatrix &matrix)
 
void SetUniformMatrix4x4 (int iUniform, const StdProjectionMatrix &matrix)
 
void Start ()
 
void Finish ()
 

Friends

class C4ScriptUniform
 

Detailed Description

Definition at line 185 of file C4Shader.h.

Constructor & Destructor Documentation

C4ShaderCall::C4ShaderCall ( const C4Shader pShader)
inline

Definition at line 189 of file C4Shader.h.

190  : fStarted(false), pShader(pShader), iUnits(0)
191  { }
C4ShaderCall::~C4ShaderCall ( )
inline

Definition at line 192 of file C4Shader.h.

References Finish().

192 { Finish(); }
void Finish()
Definition: C4Shader.cpp:703

Here is the call graph for this function:

Member Function Documentation

GLint C4ShaderCall::AllocTexUnit ( int  iUniform)

Definition at line 666 of file C4Shader.cpp.

References C4ShaderCall_MaxUnits, C4Shader::HaveUniform(), and SetUniform1i().

Referenced by C4LandscapeRenderGL::Draw(), C4FoWRegion::Render(), and CStdGL::SetupMultiBlt().

667 {
668 
669  // Want to bind uniform automatically? If not, the caller will take
670  // care of it.
671  if (iUniform >= 0) {
672 
673  // If uniform isn't used, we should skip this. Also check texunit range.
674  if (!pShader->HaveUniform(iUniform)) return 0;
675  assert(iUnits < C4ShaderCall_MaxUnits);
676  if (iUnits >= C4ShaderCall_MaxUnits) return 0;
677 
678  // Set the uniform
679  SetUniform1i(iUniform, iUnits);
680  }
681 
682  // Activate the texture
683  GLint hTex = GL_TEXTURE0 + iUnits;
684  glActiveTexture(hTex);
685  iUnits++;
686  return hTex;
687 }
void SetUniform1i(int iUniform, int iX) const
Definition: C4Shader.h:209
const int C4ShaderCall_MaxUnits
Definition: C4Shader.h:42
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::Finish ( )

Definition at line 703 of file C4Shader.cpp.

Referenced by C4LandscapeRenderGL::Draw(), C4FoWRegion::Render(), C4FoW::Render(), and ~C4ShaderCall().

704 {
705  // Remove shader
706  if (fStarted) {
707  glUseProgram(0);
708  }
709 
710  iUnits = 0;
711  fStarted = false;
712 }

Here is the caller graph for this function:

GLint C4ShaderCall::GetAttribute ( int  iAttribute) const
inline

Definition at line 194 of file C4Shader.h.

References C4Shader::GetAttribute().

Referenced by C4ParticleChunk::Draw(), C4FoWDrawLightTextureStrategy::End(), C4FoWDrawWireframeStrategy::End(), and CStdGL::PerformMultiBlt().

195  {
196  return pShader->GetAttribute(iAttribute);
197  }
GLint GetAttribute(int iAttribute) const
Definition: C4Shader.h:127

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniform1f ( int  iUniform,
float  gX 
) const
inline

Definition at line 213 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

Referenced by C4LandscapeRenderGL::Draw(), and CStdGL::SetupMultiBlt().

213  {
214  if (pShader->HaveUniform(iUniform))
215  glUniform1f(pShader->GetUniform(iUniform), gX);
216  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniform1fv ( int  iUniform,
int  iLength,
const float *  pVals 
) const
inline

Definition at line 225 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

225  {
226  if (pShader->HaveUniform(iUniform))
227  glUniform1fv(pShader->GetUniform(iUniform), iLength, pVals);
228  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

void C4ShaderCall::SetUniform1i ( int  iUniform,
int  iX 
) const
inline

Definition at line 209 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

Referenced by AllocTexUnit().

209  {
210  if (pShader->HaveUniform(iUniform))
211  glUniform1i(pShader->GetUniform(iUniform), iX);
212  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniform1iv ( int  iUniform,
int  iLength,
const int *  pVals 
) const
inline

Definition at line 221 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

Referenced by C4LandscapeRenderGL::Draw().

221  {
222  if (pShader->HaveUniform(iUniform))
223  glUniform1iv(pShader->GetUniform(iUniform), iLength, pVals);
224  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniform2f ( int  iUniform,
float  gX,
float  gY 
) const
inline

Definition at line 217 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

Referenced by C4LandscapeRenderGL::Draw().

217  {
218  if (pShader->HaveUniform(iUniform))
219  glUniform2f(pShader->GetUniform(iUniform), gX, gY);
220  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniform2fv ( int  iUniform,
int  iLength,
const float *  pVals 
) const
inline

Definition at line 229 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

Referenced by C4FoWDrawLightTextureStrategy::End(), and C4FoWDrawWireframeStrategy::End().

229  {
230  if (pShader->HaveUniform(iUniform))
231  glUniform2fv(pShader->GetUniform(iUniform), iLength, pVals);
232  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniform3fv ( int  iUniform,
int  iLength,
const float *  pVals 
) const
inline

Definition at line 233 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

Referenced by C4LandscapeRenderGL::Draw(), and CStdGL::SetupMultiBlt().

233  {
234  if (pShader->HaveUniform(iUniform))
235  glUniform3fv(pShader->GetUniform(iUniform), iLength, pVals);
236  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniform4fv ( int  iUniform,
int  iLength,
const float *  pVals 
) const
inline

Definition at line 237 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

Referenced by C4LandscapeRenderGL::Draw(), and CStdGL::SetupMultiBlt().

237  {
238  if (pShader->HaveUniform(iUniform))
239  glUniform4fv(pShader->GetUniform(iUniform), iLength, pVals);
240  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniformMatrix2x3fv ( int  iUniform,
int  iLength,
const float *  pVals 
) const
inline

Definition at line 243 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

Referenced by C4LandscapeRenderGL::Draw(), and CStdGL::SetupMultiBlt().

243  {
244  if (pShader->HaveUniform(iUniform))
245  glUniformMatrix3x2fv(pShader->GetUniform(iUniform), iLength, GL_TRUE, pVals);
246  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniformMatrix3x3 ( int  iUniform,
const StdMeshMatrix &  matrix 
)
inline

Definition at line 263 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

264  {
265  if (pShader->HaveUniform(iUniform))
266  {
267  const float mat[9] = { matrix(0, 0), matrix(1, 0), matrix(2, 0), matrix(0, 1), matrix(1, 1), matrix(2, 1), matrix(0, 2), matrix(1, 2), matrix(2, 2) };
268  glUniformMatrix3fv(pShader->GetUniform(iUniform), 1, GL_FALSE, mat);
269  }
270  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

void C4ShaderCall::SetUniformMatrix3x3fv ( int  iUniform,
int  iLength,
const float *  pVals 
) const
inline

Definition at line 248 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

248  {
249  if (pShader->HaveUniform(iUniform))
250  glUniformMatrix3fv(pShader->GetUniform(iUniform), iLength, GL_TRUE, pVals);
251  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

void C4ShaderCall::SetUniformMatrix3x3Transpose ( int  iUniform,
const StdMeshMatrix &  matrix 
)
inline

Definition at line 272 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

Referenced by CStdGL::SetupMultiBlt().

273  {
274  if (pShader->HaveUniform(iUniform))
275  {
276  const float mat[9] = { matrix(0, 0), matrix(0, 1), matrix(0, 2), matrix(1, 0), matrix(1, 1), matrix(1, 2), matrix(2, 0), matrix(2, 1), matrix(2, 2) };
277  glUniformMatrix3fv(pShader->GetUniform(iUniform), 1, GL_FALSE, mat);
278  }
279  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniformMatrix3x4 ( int  iUniform,
const StdMeshMatrix &  matrix 
)
inline

Definition at line 281 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

282  {
283  if (pShader->HaveUniform(iUniform))
284  glUniformMatrix4x3fv(pShader->GetUniform(iUniform), 1, GL_TRUE, matrix.data());
285  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

void C4ShaderCall::SetUniformMatrix3x4fv ( int  iUniform,
int  iLength,
const float *  pVals 
) const
inline

Definition at line 253 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

253  {
254  if (pShader->HaveUniform(iUniform))
255  glUniformMatrix4x3fv(pShader->GetUniform(iUniform), iLength, GL_TRUE, pVals);
256  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

void C4ShaderCall::SetUniformMatrix4x4 ( int  iUniform,
const StdMeshMatrix &  matrix 
)
inline

Definition at line 287 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

Referenced by C4LandscapeRenderGL::Draw(), C4ParticleChunk::Draw(), C4FoWRegion::Render(), C4FoW::Render(), and CStdGL::SetupMultiBlt().

288  {
289  if (pShader->HaveUniform(iUniform))
290  {
291  const float mat[16] = { matrix(0, 0), matrix(1, 0), matrix(2, 0), 0.0f, matrix(0, 1), matrix(1, 1), matrix(2, 1), 0.0f, matrix(0, 2), matrix(1, 2), matrix(2, 2), 0.0f, matrix(0, 3), matrix(1, 3), matrix(2, 3), 1.0f };
292  glUniformMatrix4fv(pShader->GetUniform(iUniform), 1, GL_FALSE, mat);
293  }
294  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::SetUniformMatrix4x4 ( int  iUniform,
const StdProjectionMatrix &  matrix 
)
inline

Definition at line 296 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

297  {
298  if (pShader->HaveUniform(iUniform))
299  glUniformMatrix4fv(pShader->GetUniform(iUniform), 1, GL_TRUE, matrix.data());
300  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

void C4ShaderCall::SetUniformMatrix4x4fv ( int  iUniform,
int  iLength,
const float *  pVals 
) const
inline

Definition at line 258 of file C4Shader.h.

References C4Shader::GetUniform(), and C4Shader::HaveUniform().

258  {
259  if (pShader->HaveUniform(iUniform))
260  glUniformMatrix4fv(pShader->GetUniform(iUniform), iLength, GL_TRUE, pVals);
261  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:117
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:122

Here is the call graph for this function:

void C4ShaderCall::Start ( )

Definition at line 689 of file C4Shader.cpp.

References C4Shader_RefreshInterval, C4TimeMilliseconds::Now(), and ScriptShader.

Referenced by C4LandscapeRenderGL::Draw(), C4FoWRegion::Render(), C4FoW::Render(), and CStdGL::SetupMultiBlt().

690 {
691  assert(!fStarted);
692  assert(pShader->hProg != 0); // Shader must be initialized
693 
694  // Possibly refresh shader
695  if (ScriptShader.LastUpdate > pShader->LastRefresh || C4TimeMilliseconds::Now() > pShader->LastRefresh + C4Shader_RefreshInterval)
696  const_cast<C4Shader *>(pShader)->Refresh();
697 
698  // Activate shader
699  glUseProgram(pShader->hProg);
700  fStarted = true;
701 }
C4ScriptShader ScriptShader
Definition: C4Shader.cpp:717
const uint32_t C4Shader_RefreshInterval
Definition: C4Shader.cpp:23
static C4TimeMilliseconds Now()

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4ScriptUniform
friend

Definition at line 187 of file C4Shader.h.


The documentation for this class was generated from the following files: