gKit2 light
Loading...
Searching...
No Matches
PipelineCache Class Reference

ensemble de shader programs compiles. singleton. More...

#include <program.h>

Public Member Functions

PipelineProgram * find (const char *filename, const char *definitions="")
 renvoie un shader program compile. et l'ajoute dans le cache, si necessaire...
PipelineProgram * find (const GLuint program, const char *filename, const char *definitions="")
 renvoie un shader program compile. et l'ajoute dans le cache, si necessaire...
PipelineProgram * reload (const GLuint program, const char *definitions="")
 recharge et recompile un programme du cache.
void reload ()
 recompile tous les shaders. du cache.
void dump ()

Static Public Member Functions

static PipelineCache & manager ()
 acces au singleton.

Protected Member Functions

 PipelineCache ()
 constructeur prive.
PipelineProgram * insert (const char *filename, const char *definitions="")
 compile un shader et l'ajoute au cache.
PipelineProgram * insert (const GLuint program, const char *filename, const char *definitions="")
 ajoute un shader dans le cache.

Protected Attributes

std::vector< PipelineProgram * > m_programs

Detailed Description

ensemble de shader programs compiles. singleton.

Definition at line 59 of file program.h.

Constructor & Destructor Documentation

◆ ~PipelineCache()

PipelineCache::~PipelineCache ( )
inline

Definition at line 62 of file program.h.

63 {
64 printf("[pipeline cache] %d programs.\n", int(m_programs.size()));
65 // le contexte est deja detruit lorsque ce destructeur est appele...
66 // trop tard pour detruire les programs et les shaders...
67
68 //~ dump();
69 for(auto& cache : m_programs)
70 delete cache;
71 }
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
Definition text.cpp:140

◆ PipelineCache()

PipelineCache::PipelineCache ( )
inlineprotected

constructeur prive.

Definition at line 155 of file program.h.

155: m_programs() {}

Member Function Documentation

◆ find() [1/2]

PipelineProgram * PipelineCache::find ( const char * filename,
const char * definitions = "" )
inline

renvoie un shader program compile. et l'ajoute dans le cache, si necessaire...

Definition at line 74 of file program.h.

75 {
76 // unordered_map sans doute plus rapide ? mais il y a peu de shaders utilises...
77 for(auto cache : m_programs)
78 {
79 if(cache->filename == filename && cache->definitions == definitions)
80 return cache;
81 }
82
83 return insert(filename, definitions);
84 }
PipelineProgram * insert(const char *filename, const char *definitions="")
compile un shader et l'ajoute au cache.
Definition program.h:158

◆ find() [2/2]

PipelineProgram * PipelineCache::find ( const GLuint program,
const char * filename,
const char * definitions = "" )
inline

renvoie un shader program compile. et l'ajoute dans le cache, si necessaire...

Definition at line 87 of file program.h.

88 {
89 for(auto cache : m_programs)
90 {
91 if(cache->program == program && cache->filename == filename && cache->definitions == definitions)
92 return cache;
93 }
94
95 return insert(program, filename, definitions);
96 }

◆ reload() [1/2]

PipelineProgram * PipelineCache::reload ( const GLuint program,
const char * definitions = "" )
inline

recharge et recompile un programme du cache.

Definition at line 99 of file program.h.

100 {
101 int update_program( const GLuint program, const char *filename, const char *definitions );
102
103 for(auto cache : m_programs)
104 {
105 if(cache->program == program)
106 {
107 if(definitions && definitions[0])
108 // modifier le cache avec les nouvelles definitions, uniquement si elles sont non nulles.
109 cache->definitions= definitions;
110
111 // recharge et recompile le shader.
112 update_program(program, cache->filename.c_str(), cache->definitions.c_str());
113 program_print_errors(program);
114 return cache;
115 }
116 }
117
118 // ne devrait pas arriver...
119 return nullptr;
120 }
int program_print_errors(const GLuint program, const char *filename="")
affiche les erreurs de compilation.
Definition program.cpp:459

◆ reload() [2/2]

void PipelineCache::reload ( )
inline

recompile tous les shaders. du cache.

Definition at line 123 of file program.h.

124 {
125 int update_program( const GLuint program, const char *filename, const char *definitions );
126
127 for(auto cache : m_programs)
128 {
129 update_program(cache->program, cache->filename.c_str(), cache->definitions.c_str());
130 program_print_errors(cache->program);
131 }
132 }

◆ dump()

void PipelineCache::dump ( )
inline

Definition at line 135 of file program.h.

136 {
137 for(unsigned i= 0; i < m_programs.size(); i++)
138 {
139 PipelineProgram *cache= m_programs[i];
140 printf("[%d] '%s'\n", i, cache->filename.c_str());
141 if(!cache->definitions.empty())
142 printf(" %s\n", cache->definitions.c_str());
143 }
144 }

◆ manager()

PipelineCache & PipelineCache::manager ( )
inlinestatic

acces au singleton.

Definition at line 147 of file program.h.

148 {
149 static PipelineCache cache;
150 return cache;
151 }
PipelineCache()
constructeur prive.
Definition program.h:155

◆ insert() [1/2]

PipelineProgram * PipelineCache::insert ( const char * filename,
const char * definitions = "" )
inlineprotected

compile un shader et l'ajoute au cache.

Definition at line 158 of file program.h.

159 {
160 int update_program( const GLuint program, const char *filename, const char *definitions );
161
162 // cree le programme s'il n'existe pas deja...
163 GLuint program= glCreateProgram();
164 update_program(program, filename, definitions);
165 program_print_errors(program);
166
167 return insert(program, filename, definitions);
168 }

◆ insert() [2/2]

PipelineProgram * PipelineCache::insert ( const GLuint program,
const char * filename,
const char * definitions = "" )
inlineprotected

ajoute un shader dans le cache.

Definition at line 171 of file program.h.

172 {
173 PipelineProgram *cache= new PipelineProgram { filename, definitions, program };
174 m_programs.push_back(cache);
175
176 return cache;
177 }

Member Data Documentation

◆ m_programs

std::vector<PipelineProgram *> PipelineCache::m_programs
protected

Definition at line 179 of file program.h.


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