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

#include <C4Shader.h>

Classes

class  Popper
 
union  Uniform.__unnamed__
 

Public Member Functions

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

Friends

class C4Shader
 

Detailed Description

Definition at line 351 of file C4Shader.h.


Class Documentation

union C4ScriptUniform::Uniform.__unnamed__

Definition at line 359 of file C4Shader.h.

Class Members
int intVec[4]

Constructor & Destructor Documentation

C4ScriptUniform::C4ScriptUniform ( )
inline

Definition at line 387 of file C4Shader.h.

References Clear().

387 { Clear(); }

Here is the call graph for this function:

Member Function Documentation

void C4ScriptUniform::Apply ( C4ShaderCall call)

Definition at line 830 of file C4Shader.cpp.

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

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

Here is the caller graph for this function:

void C4ScriptUniform::Clear ( )

Definition at line 824 of file C4Shader.cpp.

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

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

Here is the caller graph for this function:

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

Definition at line 759 of file C4Shader.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4Shader
friend

Definition at line 353 of file C4Shader.h.


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