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 730 of file C4Shader.cpp.

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

References C4TimeMilliseconds::AsInt(), and 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 721 of file C4Shader.cpp.

722 {
723  std::set<int> result;
724  for (auto& cat : cats)
725  for (auto& id : categories[cat])
726  result.emplace(id);
727  return result;
728 }

Referenced by C4Shader::Refresh().

Here is the caller graph for this function:

◆ Remove()

bool C4ScriptShader::Remove ( int  id)

Definition at line 742 of file C4Shader.cpp.

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

References C4TimeMilliseconds::AsInt(), and 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: