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


Class Documentation

union C4ScriptUniform::Uniform.__unnamed__

Definition at line 358 of file C4Shader.h.

Class Members
int intVec[4]

Constructor & Destructor Documentation

C4ScriptUniform::C4ScriptUniform ( )
inline

Definition at line 386 of file C4Shader.h.

References Clear().

386 { Clear(); }

Here is the call graph for this function:

Member Function Documentation

void C4ScriptUniform::Apply ( C4ShaderCall call)

Definition at line 826 of file C4Shader.cpp.

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

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

Here is the caller graph for this function:

void C4ScriptUniform::Clear ( )

Definition at line 820 of file C4Shader.cpp.

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

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

Here is the caller graph for this function:

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

Definition at line 755 of file C4Shader.cpp.

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

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

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

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


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