OpenClonk
C4ScriptShader Class Reference

#include <C4Shader.h>

Public Types

enum  ShaderType { VertexShader, FragmentShader }
 

Public Member Functions

int Add (const std::string &shaderName, ShaderType type, const std::string &source)
 
bool Remove (int id)
 

Protected Member Functions

std::set< int > GetShaderIDs (const std::vector< std::string > &cats)
 

Friends

class C4Shader
 
class C4ShaderCall
 

Detailed Description

Definition at line 376 of file C4Shader.h.

Member Enumeration Documentation

◆ ShaderType

Enumerator
VertexShader 
FragmentShader 

Definition at line 382 of file C4Shader.h.

383  {
384  VertexShader, // Note: Reloading is currently only implemented for fragment shaders.
386  };

Member Function Documentation

◆ Add()

int C4ScriptShader::Add ( const std::string &  shaderName,
ShaderType  type,
const std::string &  source 
)

Definition at line 728 of file C4Shader.cpp.

References C4TimeMilliseconds::AsInt(), and C4TimeMilliseconds::Now().

729 {
730  int id = NextID++;
731  LastUpdate = C4TimeMilliseconds::Now().AsInt();
732  // Hack: Always prepend a newline as the slice parser doesn't recognize
733  // slices that don't begin with a newline.
734  auto nsource = "\n" + source;
735  shaders.emplace(std::make_pair(id, ShaderInstance{type, nsource}));
736  categories[shaderName].emplace(id);
737  return id;
738 }
uint32_t AsInt() const
static C4TimeMilliseconds Now()
Here is the call graph for this function:

◆ GetShaderIDs()

std::set< int > C4ScriptShader::GetShaderIDs ( const std::vector< std::string > &  cats)
protected

Definition at line 719 of file C4Shader.cpp.

Referenced by C4Shader::Refresh(), and C4Shader::SetScriptCategories().

720 {
721  std::set<int> result;
722  for (auto& cat : cats)
723  for (auto& id : categories[cat])
724  result.emplace(id);
725  return result;
726 }
Here is the caller graph for this function:

◆ Remove()

bool C4ScriptShader::Remove ( int  id)

Definition at line 740 of file C4Shader.cpp.

References C4TimeMilliseconds::AsInt(), and C4TimeMilliseconds::Now().

741 {
742  // We have to perform a rather inefficient full search. We'll have to see
743  // whether this turns out to be a performance issue.
744  if (shaders.erase(id))
745  {
746  for (auto& kv : categories)
747  if (kv.second.erase(id))
748  break; // each id can appear in one category only
749  LastUpdate = C4TimeMilliseconds::Now().AsInt();
750  return true;
751  }
752  return false;
753 }
uint32_t AsInt() const
static C4TimeMilliseconds Now()
Here is the call graph for this function:

Friends And Related Function Documentation

◆ C4Shader

friend class C4Shader
friend

Definition at line 378 of file C4Shader.h.

◆ C4ShaderCall

friend class C4ShaderCall
friend

Definition at line 379 of file C4Shader.h.


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