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

Member Enumeration Documentation

Enumerator
VertexShader 
FragmentShader 

Definition at line 319 of file C4Shader.h.

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

Member Function Documentation

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

Definition at line 732 of file C4Shader.cpp.

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

733 {
734  int id = NextID++;
735  LastUpdate = C4TimeMilliseconds::Now().AsInt();
736  // Hack: Always prepend a newline as the slice parser doesn't recognize
737  // slices that don't begin with a newline.
738  auto nsource = "\n" + source;
739  shaders.emplace(std::make_pair(id, ShaderInstance{type, nsource}));
740  categories[shaderName].emplace(id);
741  return id;
742 }
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 723 of file C4Shader.cpp.

Referenced by C4Shader::Refresh().

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

Here is the caller graph for this function:

bool C4ScriptShader::Remove ( int  id)

Definition at line 744 of file C4Shader.cpp.

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

745 {
746  // We have to perform a rather inefficient full search. We'll have to see
747  // whether this turns out to be a performance issue.
748  if (shaders.erase(id))
749  {
750  for (auto& kv : categories)
751  if (kv.second.erase(id))
752  break; // each id can appear in one category only
753  LastUpdate = C4TimeMilliseconds::Now().AsInt();
754  return true;
755  }
756  return false;
757 }
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 315 of file C4Shader.h.

friend class C4ShaderCall
friend

Definition at line 316 of file C4Shader.h.


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