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 186 of file C4Shader.h.

Constructor & Destructor Documentation

C4ShaderCall::C4ShaderCall ( const C4Shader pShader)
inline

Definition at line 190 of file C4Shader.h.

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

Definition at line 193 of file C4Shader.h.

References Finish().

193 { Finish(); }
void Finish()
Definition: C4Shader.cpp:707

Here is the call graph for this function:

Member Function Documentation

GLint C4ShaderCall::AllocTexUnit ( int  iUniform)

Definition at line 670 of file C4Shader.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ShaderCall::Finish ( )

Definition at line 707 of file C4Shader.cpp.

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

708 {
709  // Remove shader
710  if (fStarted) {
711  glUseProgram(0);
712  }
713 
714  iUnits = 0;
715  fStarted = false;
716 }

Here is the caller graph for this function:

GLint C4ShaderCall::GetAttribute ( int  iAttribute) const
inline

Definition at line 195 of file C4Shader.h.

References C4Shader::GetAttribute().

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

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

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 214 of file C4Shader.h.

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

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

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

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 226 of file C4Shader.h.

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

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

Here is the call graph for this function:

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

Definition at line 210 of file C4Shader.h.

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

Referenced by AllocTexUnit().

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

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 222 of file C4Shader.h.

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

Referenced by C4LandscapeRenderGL::Draw().

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

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 218 of file C4Shader.h.

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

Referenced by C4LandscapeRenderGL::Draw().

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

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 230 of file C4Shader.h.

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

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

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

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 234 of file C4Shader.h.

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

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

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

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 238 of file C4Shader.h.

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

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

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

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 244 of file C4Shader.h.

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

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

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

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 264 of file C4Shader.h.

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

265  {
266  if (pShader->HaveUniform(iUniform))
267  {
268  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) };
269  glUniformMatrix3fv(pShader->GetUniform(iUniform), 1, GL_FALSE, mat);
270  }
271  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:118
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:123

Here is the call graph for this function:

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

Definition at line 249 of file C4Shader.h.

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

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

Here is the call graph for this function:

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

Definition at line 273 of file C4Shader.h.

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

Referenced by CStdGL::SetupMultiBlt().

274  {
275  if (pShader->HaveUniform(iUniform))
276  {
277  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) };
278  glUniformMatrix3fv(pShader->GetUniform(iUniform), 1, GL_FALSE, mat);
279  }
280  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:118
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:123

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 282 of file C4Shader.h.

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

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

Here is the call graph for this function:

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

Definition at line 254 of file C4Shader.h.

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

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

Here is the call graph for this function:

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

Definition at line 288 of file C4Shader.h.

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

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

289  {
290  if (pShader->HaveUniform(iUniform))
291  {
292  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 };
293  glUniformMatrix4fv(pShader->GetUniform(iUniform), 1, GL_FALSE, mat);
294  }
295  }
GLint GetUniform(int iUniform) const
Definition: C4Shader.h:118
bool HaveUniform(int iUniform) const
Definition: C4Shader.h:123

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 297 of file C4Shader.h.

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

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

Here is the call graph for this function:

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

Definition at line 259 of file C4Shader.h.

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

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

Here is the call graph for this function:

void C4ShaderCall::Start ( )

Definition at line 693 of file C4Shader.cpp.

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

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

694 {
695  assert(!fStarted);
696  assert(pShader->hProg != 0); // Shader must be initialized
697 
698  // Possibly refresh shader
699  if (ScriptShader.LastUpdate > pShader->LastRefresh || C4TimeMilliseconds::Now() > pShader->LastRefresh + C4Shader_RefreshInterval)
700  const_cast<C4Shader *>(pShader)->Refresh();
701 
702  // Activate shader
703  glUseProgram(pShader->hProg);
704  fStarted = true;
705 }
C4ScriptShader ScriptShader
Definition: C4Shader.cpp:721
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 188 of file C4Shader.h.


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