OpenClonk
StdMeshMaterialProgram Class Reference

#include <StdMeshMaterial.h>

Public Member Functions

 StdMeshMaterialProgram (const char *name, const StdMeshMaterialShader *fragment_shader, const StdMeshMaterialShader *vertex_shader, const StdMeshMaterialShader *geometry_shader)
 
bool AddParameterNames (const StdMeshMaterialShaderParameters &parameters)
 
bool IsCompiled () const
 
bool Compile (StdMeshMaterialLoader &loader)
 
const C4ShaderGetShader (int ssc) const
 
int GetParameterIndex (const char *name) const
 
const StdMeshMaterialShaderGetFragmentShader () const
 
const StdMeshMaterialShaderGetVertexShader () const
 
const StdMeshMaterialShaderGetGeometryShader () const
 

Detailed Description

Definition at line 156 of file StdMeshMaterial.h.

Constructor & Destructor Documentation

◆ StdMeshMaterialProgram()

StdMeshMaterialProgram::StdMeshMaterialProgram ( const char *  name,
const StdMeshMaterialShader fragment_shader,
const StdMeshMaterialShader vertex_shader,
const StdMeshMaterialShader geometry_shader 
)

Definition at line 813 of file StdMeshMaterial.cpp.

813  :
814  Name(name), FragmentShader(fragment_shader), VertexShader(vertex_shader), GeometryShader(geometry_shader)
815 {
816  assert(FragmentShader != nullptr);
817  assert(VertexShader != nullptr);
818  // Geometry shader is optional (and not even implemented at the moment!)
819 }

Member Function Documentation

◆ AddParameterNames()

bool StdMeshMaterialProgram::AddParameterNames ( const StdMeshMaterialShaderParameters parameters)

Definition at line 821 of file StdMeshMaterial.cpp.

References C4Shader::AddFragmentSlices(), StdMeshMaterialLoader::AddShaderSlices(), C4Shader::AddVertexSlices(), StdStrBuf::Append(), C4SSA_BoneIndices0, C4SSA_BoneIndices1, C4SSA_BoneWeights0, C4SSA_BoneWeights1, C4SSA_Color, C4SSA_Count, C4SSA_Normal, C4SSA_Position, C4SSA_TexCoord, C4SSU_AmbientBrightness, C4SSU_AmbientTex, C4SSU_AmbientTransform, C4SSU_BaseTex, C4SSU_Bones, C4SSU_ClrMod, C4SSU_Count, C4SSU_CullMode, C4SSU_FrameCounter, C4SSU_Gamma, C4SSU_LightTex, C4SSU_LightTransform, C4SSU_MaterialAmbient, C4SSU_MaterialDiffuse, C4SSU_MaterialEmission, C4SSU_MaterialShininess, C4SSU_MaterialSpecular, C4SSU_ModelViewMatrix, C4SSU_NormalMatrix, C4SSU_NormalTex, C4SSU_OverlayClr, C4SSU_OverlayTex, C4SSU_ProjectionMatrix, C4SSU_Resolution, StdMeshMaterialShader::GetCode(), StdMeshMaterialShader::GetFilename(), and StdMeshMaterialShaderParameters::NamedParameters.

Referenced by StdMeshMatManager::AddProgram().

822 {
823  // TODO: This is O(n^2) -- not optimal!
824  bool added = false;
825  for (const auto & NamedParameter : parameters.NamedParameters)
826  {
827  const std::vector<StdCopyStrBuf>::const_iterator iter = std::find(ParameterNames.begin(), ParameterNames.end(), NamedParameter.first);
828  if (iter == ParameterNames.end())
829  {
830  ParameterNames.push_back(NamedParameter.first);
831  added = true;
832  }
833  }
834 
835  return added;
836 }
std::vector< std::pair< StdCopyStrBuf, StdMeshMaterialShaderParameter > > NamedParameters
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Compile()

bool StdMeshMaterialProgram::Compile ( StdMeshMaterialLoader loader)

Definition at line 897 of file StdMeshMaterial.cpp.

Referenced by StdMeshMatManager::AddProgram().

898 {
899 #ifndef USE_CONSOLE
900  if (!CompileShader(loader, Shader, 0)) return false;
901  if (!CompileShader(loader, ShaderMod2, C4SSC_MOD2)) return false;
902  if (!CompileShader(loader, ShaderLight, C4SSC_LIGHT)) return false;
903  if (!CompileShader(loader, ShaderLightMod2, C4SSC_LIGHT | C4SSC_MOD2)) return false;
904 #endif
905  return true;
906 }
Here is the caller graph for this function:

◆ GetFragmentShader()

const StdMeshMaterialShader* StdMeshMaterialProgram::GetFragmentShader ( ) const
inline

Definition at line 168 of file StdMeshMaterial.h.

Referenced by StdMeshMaterialPass::ProgramInstance::ProgramInstance().

168 { return FragmentShader; }
Here is the caller graph for this function:

◆ GetGeometryShader()

const StdMeshMaterialShader* StdMeshMaterialProgram::GetGeometryShader ( ) const
inline

Definition at line 170 of file StdMeshMaterial.h.

Referenced by StdMeshMaterialPass::ProgramInstance::ProgramInstance().

170 { return GeometryShader; }
Here is the caller graph for this function:

◆ GetParameterIndex()

int StdMeshMaterialProgram::GetParameterIndex ( const char *  name) const

Definition at line 929 of file StdMeshMaterial.cpp.

References C4SSU_Count.

Referenced by StdMeshMaterialPass::ProgramInstance::ProgramInstance().

930 {
931 #ifndef USE_CONSOLE
932  std::vector<StdCopyStrBuf>::const_iterator iter = std::find(ParameterNames.begin(), ParameterNames.end(), name);
933  if(iter == ParameterNames.end()) return -1;
934  return C4SSU_Count + std::distance(ParameterNames.begin(), iter);
935 #else
936  return -1;
937 #endif
938 }
Here is the caller graph for this function:

◆ GetShader()

const C4Shader * StdMeshMaterialProgram::GetShader ( int  ssc) const

Definition at line 908 of file StdMeshMaterial.cpp.

909 {
910 #ifndef USE_CONSOLE
911  const C4Shader* shaders[4] = {
912  &Shader,
913  &ShaderMod2,
914  &ShaderLight,
915  &ShaderLightMod2
916  };
917 
918  int index = 0;
919  if(ssc & C4SSC_MOD2) index += 1;
920  if(ssc & C4SSC_LIGHT) index += 2;
921 
922  assert(index < 4);
923  return shaders[index];
924 #else
925  return nullptr;
926 #endif
927 }

◆ GetVertexShader()

const StdMeshMaterialShader* StdMeshMaterialProgram::GetVertexShader ( ) const
inline

Definition at line 169 of file StdMeshMaterial.h.

Referenced by StdMeshMaterialPass::ProgramInstance::ProgramInstance().

169 { return VertexShader; }
Here is the caller graph for this function:

◆ IsCompiled()

bool StdMeshMaterialProgram::IsCompiled ( ) const
inline

Definition at line 162 of file StdMeshMaterial.h.

Referenced by StdMeshMatManager::AddProgram().

162 { return Shader.Initialised(); }
bool Initialised() const
Definition: C4Shader.h:106
Here is the caller graph for this function:

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