OpenClonk
C4ScriptUniform Class Reference

#include <C4Shader.h>

Classes

class  Popper
 
union  Uniform.__unnamed12__
 

Public Member Functions

void Clear ()
 
std::unique_ptr< PopperPush (C4PropList *proplist)
 
void Apply (C4ShaderCall &call)
 
 C4ScriptUniform ()
 

Friends

class C4Shader
 

Detailed Description

Definition at line 414 of file C4Shader.h.


Class Documentation

◆ C4ScriptUniform::Uniform.__unnamed12__

union C4ScriptUniform::Uniform.__unnamed12__

Definition at line 422 of file C4Shader.h.

Class Members
int intVec[4]

Constructor & Destructor Documentation

◆ C4ScriptUniform()

C4ScriptUniform::C4ScriptUniform ( )
inline

Definition at line 450 of file C4Shader.h.

450 { Clear(); }

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Apply()

void C4ScriptUniform::Apply ( C4ShaderCall call)

Definition at line 828 of file C4Shader.cpp.

829 {
830 #ifndef USE_CONSOLE
831  for (auto& p : uniformStack.top())
832  {
833  // The existing SetUniform* methods only work for pre-defined indexed uniforms. The script
834  // uniforms are unknown at shader compile time, so we have to use OpenGL functions directly
835  // here.
836  GLint loc = glGetUniformLocation(call.pShader->hProg, p.first.c_str());
837  // Is this uniform defined in the shader?
838  if (loc == -1) continue;
839  auto& intVec = p.second.intVec;
840  switch (p.second.type)
841  {
842  case GL_INT: glUniform1iv(loc, 1, intVec); break;
843  case GL_INT_VEC2: glUniform2iv(loc, 1, intVec); break;
844  case GL_INT_VEC3: glUniform3iv(loc, 1, intVec); break;
845  case GL_INT_VEC4: glUniform4iv(loc, 1, intVec); break;
846  default:
847  assert(false && "unsupported uniform type");
848  }
849  }
850 #endif
851 }

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

Here is the caller graph for this function:

◆ Clear()

void C4ScriptUniform::Clear ( )

Definition at line 822 of file C4Shader.cpp.

823 {
824  uniformStack = std::stack<UniformMap>();
825  uniformStack.emplace();
826 }

Referenced by C4ScriptUniform(), and C4Draw::Default().

Here is the caller graph for this function:

◆ Push()

std::unique_ptr< C4ScriptUniform::Popper > C4ScriptUniform::Push ( C4PropList proplist)

Definition at line 757 of file C4Shader.cpp.

758 {
759 #ifdef USE_CONSOLE
760  return std::unique_ptr<C4ScriptUniform::Popper>();
761 #else
762  C4Value ulist;
763  if (!proplist->GetProperty(P_Uniforms, &ulist) || ulist.GetType() != C4V_PropList)
764  return std::unique_ptr<C4ScriptUniform::Popper>();
765 
766  uniformStack.emplace();
767  auto& uniforms = uniformStack.top();
768  Uniform u;
769  for (const C4Property* prop : *ulist.getPropList())
770  {
771  if (!prop->Key) continue;
772  switch (prop->Value.GetType())
773  {
774  case C4V_Int:
775  u.type = GL_INT;
776  u.intVec[0] = prop->Value._getInt();
777  break;
778  case C4V_Array:
779  {
780  auto array = prop->Value._getArray();
781  switch (array->GetSize())
782  {
783  case 1: u.type = GL_INT; break;
784  case 2: u.type = GL_INT_VEC2; break;
785  case 3: u.type = GL_INT_VEC3; break;
786  case 4: u.type = GL_INT_VEC4; break;
787  default: continue;
788  }
789  for (int32_t i = 0; i < array->GetSize(); i++)
790  {
791  auto& item = array->_GetItem(i);
792  switch (item.GetType())
793  {
794  case C4V_Int:
795  u.intVec[i] = item._getInt();
796  break;
797  default:
798  goto skip;
799  }
800  }
801  break;
802  }
803  default:
804  continue;
805  }
806  // Uniform is now filled properly. Note that array contents are undefined for higher slots
807  // when "type" only requires a smaller array.
808  uniforms.insert({prop->Key->GetCStr(), u});
809 skip:;
810  }
811  // Debug
812  /*
813  for (auto& p : uniforms)
814  {
815  LogF("Uniform %s (type %d) = %d %d %d %d", p.first.c_str(), p.second.type, p.second.intVec[0], p.second.intVec[1], p.second.intVec[2], p.second.intVec[3]);
816  }
817  */
818  return std::make_unique<C4ScriptUniform::Popper>(this);
819 #endif
820 }
@ P_Uniforms
@ C4V_Int
Definition: C4Value.h:26
@ C4V_PropList
Definition: C4Value.h:28
@ C4V_Array
Definition: C4Value.h:30
bool GetProperty(C4PropertyName k, C4Value *pResult) const
Definition: C4PropList.h:105
C4V_Type GetType() const
Definition: C4Value.h:161
C4PropList * getPropList() const
Definition: C4Value.h:116

References C4V_Array, C4V_Int, C4V_PropList, C4PropList::GetProperty(), C4Value::getPropList(), C4Value::GetType(), and P_Uniforms.

Referenced by C4Object::Draw(), and C4Viewport::Execute().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4Shader

friend class C4Shader
friend

Definition at line 416 of file C4Shader.h.


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