OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 312 of file C4Shader.h.

Member Enumeration Documentation

Enumerator
VertexShader 
FragmentShader 

Definition at line 318 of file C4Shader.h.

319  {
320  VertexShader, // Note: Reloading is currently only implemented for fragment shaders.
322  };

Member Function Documentation

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:

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

Definition at line 719 of file C4Shader.cpp.

Referenced by C4Shader::Refresh().

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:

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

friend class C4Shader
friend

Definition at line 314 of file C4Shader.h.

friend class C4ShaderCall
friend

Definition at line 315 of file C4Shader.h.


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