gKit2 light
Loading...
Searching...
No Matches
program.h
Go to the documentation of this file.
1
2#ifndef _PROGRAM_H
3#define _PROGRAM_H
4
5#include <vector>
6#include <string>
7
8#include "glcore.h"
9
10
13
16
22GLuint read_program( const char *filename, const char *definitions= "" );
23
25int release_program( const GLuint program );
26
31int reload_program( const GLuint program, const char *filename, const char *definitions= "" );
32
34int reload_program( const GLuint program );
35
37int program_format_errors( const GLuint program, std::string& errors );
38
40int program_print_errors( const GLuint program, const char *filename= "" );
41
43bool program_ready( const GLuint program );
44
46bool program_errors( const GLuint program );
47
48
51{
52 std::string filename;
53 std::string definitions;
54 GLuint program;
55};
56
59{
60public:
62 {
63 printf("[pipeline cache] %d programs.\n", int(m_programs.size()));
64 // le contexte est deja detruit lorsque ce destructeur est appele...
65 // trop tard pour detruire les programs et les shaders...
66 }
67
69 PipelineProgram *find( const char *filename, const char *definitions= "" )
70 {
71 // todo unordered_map sans doute plus rapide ? mais il y a peu de shaders utilises...
72 for(auto cache : m_programs)
73 {
74 if(cache->filename == filename && cache->definitions == definitions)
75 return cache;
76 }
77
78 return insert(filename, definitions);
79 }
80
82 PipelineProgram *insert( const char *filename, const char *definitions= "" )
83 {
84 int update_program( const GLuint program, const char *filename, const char *definitions );
85
86 // cree le programme s'il n'existe pas deja...
87 GLuint program= glCreateProgram();
88 update_program(program, filename, definitions);
89 program_print_errors(program);
90
91 return insert(program, filename, definitions);
92 }
93
95 PipelineProgram *insert( const GLuint program, const char *filename, const char *definitions= "" )
96 {
97 PipelineProgram *cache= new PipelineProgram { filename, definitions, program };
98 m_programs.push_back(cache);
99
100 return cache;
101 }
102
104 PipelineProgram *reload( const GLuint program )
105 {
106 for(auto cache : m_programs)
107 {
108 if(cache->program == program)
109 {
110 reload_program(program, cache->filename.c_str(), cache->definitions.c_str());
111 program_print_errors(program);
112 return cache;
113 }
114 }
115
116 return nullptr;
117 }
118
120 void reload( )
121 {
122 for(auto cache : m_programs)
123 {
124 reload_program(cache->program, cache->filename.c_str(), cache->definitions.c_str());
125 program_print_errors(cache->program);
126 }
127 }
128
131 {
132 static PipelineCache cache;
133 return cache;
134 }
135
136protected:
138 PipelineCache( ) : m_programs() {}
139
140 std::vector<PipelineProgram *> m_programs;
141};
142
143
145#endif
void reload()
recompile tous les shaders. du cache.
Definition program.h:120
PipelineProgram * reload(const GLuint program)
recharge et recompile un programme du cache.
Definition program.h:104
PipelineProgram * insert(const GLuint program, const char *filename, const char *definitions="")
ajoute un shader dans le cache
Definition program.h:95
PipelineCache()
constructeur prive.
Definition program.h:138
PipelineProgram * insert(const char *filename, const char *definitions="")
ajoute un shader dans le cache
Definition program.h:82
PipelineProgram * find(const char *filename, const char *definitions="")
renvoie un shader program compile. et l'ajoute dans le cache...
Definition program.h:69
static PipelineCache & manager()
acces au singleton.
Definition program.h:130
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
GLuint read_program(const char *filename, const char *definitions="")
Definition program.cpp:217
int program_print_errors(const GLuint program, const char *filename="")
affiche les erreurs de compilation.
Definition program.cpp:461
int release_program(const GLuint program)
detruit les shaders et le program.
Definition program.cpp:240
bool program_errors(const GLuint program)
renvoie vrai si le programme n'est pas pret.
Definition program.cpp:288
int reload_program(const GLuint program, const char *filename, const char *definitions="")
Definition program.cpp:228
bool program_ready(const GLuint program)
renvoie vrai si le programme est pret. (pas d'erreurs de compilation des shaders, pas d'erreur de lin...
Definition program.cpp:265
int program_format_errors(const GLuint program, std::string &errors)
renvoie les erreurs de compilation.
Definition program.cpp:395
description d'un shader program compile.
Definition program.h:51