gKit2 light
Loading...
Searching...
No Matches
ReadBuffer Struct Reference
Inheritance diagram for ReadBuffer:

Public Member Functions

int init ()
 a deriver pour creer les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
int quit ()
 a deriver pour detruire les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
int render ()
 a deriver pour afficher les objets. renvoie 1 pour continuer, 0 pour fermer l'application.
int init ()
 a deriver pour creer les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
int quit ()
 a deriver pour detruire les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
int render ()
 a deriver pour afficher les objets. renvoie 1 pour continuer, 0 pour fermer l'application.
Public Member Functions inherited from App
 App (const int width, const int height, const int major=3, const int minor=3, const int samples=0)
 constructeur, dimensions de la fenetre et version d'openGL.
virtual int update (const float time, const float delta)
 a deriver et redefinir pour animer les objets en fonction du temps.
int run ()
 execution de l'application.

Public Attributes

GLuint m_gpu_buffer1
GLuint m_gpu_buffer2
GLuint m_gpu_count
GLuint m_read_buffer
GLuint m_program

Additional Inherited Members

Protected Member Functions inherited from App
virtual int prerender ()
virtual int postrender ()
void vsync_off ()
Protected Attributes inherited from App
Window m_window
Context m_context
bool sync

Detailed Description

Definition at line 25 of file tuto_count_buffer.cpp.

Constructor & Destructor Documentation

◆ ReadBuffer() [1/2]

ReadBuffer::ReadBuffer ( )
inline

Definition at line 27 of file tuto_count_buffer.cpp.

27: App(1280, 768, 4,3) {}
App(const int width, const int height, const int major=3, const int minor=3, const int samples=0)
constructeur, dimensions de la fenetre et version d'openGL.
Definition app.cpp:11

◆ ReadBuffer() [2/2]

ReadBuffer::ReadBuffer ( )
inline

Definition at line 30 of file tuto_read_buffer.cpp.

30: App(1280, 768, 4,3) {}

Member Function Documentation

◆ init() [1/2]

int ReadBuffer::init ( )
inlinevirtual

a deriver pour creer les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.

Implements App.

Definition at line 29 of file tuto_count_buffer.cpp.

30 {
31 {
32 if(!GLAD_GL_KHR_shader_subgroup)
33 printf("no shader_subgroups.\n");
34
35 if(GLAD_GL_KHR_shader_subgroup)
36 {
37 printf("shader_subgroups:\n");
38
39 GLint size= 0;
40 glGetIntegerv(GL_SUBGROUP_SIZE_KHR, &size);
41 printf("subgroup size %d\n", size);
42
43 GLint stages= 0;
44 glGetIntegerv(GL_SUBGROUP_SUPPORTED_STAGES_KHR, &stages);
45 printf("stages:\n");
46 if(stages & GL_COMPUTE_SHADER_BIT) printf(" compute\n"); else printf(" no compute\n");
47 if(stages & GL_VERTEX_SHADER_BIT) printf(" vertex\n"); else printf(" no vertex\n");
48 if(stages & GL_TESS_CONTROL_SHADER_BIT) printf(" tesselation control\n"); else printf(" no tesselation control\n");
49 if(stages & GL_TESS_EVALUATION_SHADER_BIT) printf(" tesselation evaluation\n"); else printf(" no tesselation evaluation\n");
50 if(stages & GL_GEOMETRY_SHADER_BIT) printf(" geometry\n"); else printf(" no geometry\n");
51 if(stages & GL_FRAGMENT_SHADER_BIT) printf(" fragment\n"); else printf(" no fragment\n");
52 if(stages & GL_MESH_SHADER_BIT_EXT) printf(" mesh\n"); else printf(" no mesh\n");
53 if(stages & GL_TASK_SHADER_BIT_EXT) printf(" mesh task\n"); else printf(" no mesh task\n");
54
55 GLint features;
56 glGetIntegerv(GL_SUBGROUP_SUPPORTED_FEATURES_KHR, &features);
57 printf("features:\n");
58 if(features & GL_SUBGROUP_FEATURE_BASIC_BIT_KHR) printf(" basic\n"); else printf(" no basic\n");
59 if(features & GL_SUBGROUP_FEATURE_VOTE_BIT_KHR) printf(" vote\n"); else printf(" no vote\n");
60 if(features & GL_SUBGROUP_FEATURE_ARITHMETIC_BIT_KHR) printf(" arithmetic\n"); else printf(" no arithmetic\n");
61 if(features & GL_SUBGROUP_FEATURE_BALLOT_BIT_KHR) printf(" ballot\n"); else printf(" no ballot\n");
62 if(features & GL_SUBGROUP_FEATURE_SHUFFLE_BIT_KHR) printf(" shuffle\n"); else printf(" no shuffle\n");
63 if(features & GL_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT_KHR) printf(" shuffle relative\n"); else printf(" no shuffle relative\n");
64 if(features & GL_SUBGROUP_FEATURE_CLUSTERED_BIT_KHR) printf(" clustered\n"); else printf(" no clustered\n");
65 if(features & GL_SUBGROUP_FEATURE_QUAD_BIT_KHR) printf(" quad\n"); else printf(" no quad\n");
66 }
67 }
68
69 m_program= read_program("gkit2_tutos/M2/count_buffer.glsl");
70 program_print_errors(m_program);
71
72 std::vector<int> data(1024);
73 for(unsigned i= 0; i < data.size(); i++)
74 data[i]= i % 16;
75
76
77 glGenBuffers(1, &m_gpu_buffer1);
78 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_gpu_buffer1);
79 #ifdef USE_BUFFER_STORAGE
80 glBufferStorage(GL_SHADER_STORAGE_BUFFER, sizeof(int) * data.size(), data.data(), 0);
81 #else
82 glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(int) * data.size(), data.data(), GL_STATIC_COPY);
83 #endif
84
85 glGenBuffers(1, &m_gpu_buffer2);
86 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_gpu_buffer2);
87 #ifdef USE_BUFFER_STORAGE
88 glBufferStorage(GL_SHADER_STORAGE_BUFFER, sizeof(int) * data.size(), nullptr, 0);
89 #else
90 glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(int) * data.size(), nullptr, GL_STATIC_COPY);
91 #endif
92
93 glGenBuffers(1, &m_gpu_count);
94 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_gpu_count);
95 #ifdef USE_BUFFER_STORAGE
96 glBufferStorage(GL_SHADER_STORAGE_BUFFER, sizeof(int), nullptr, 0);
97 #else
98 glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(int), nullptr, GL_STATIC_COPY);
99 #endif
100
101 glGenBuffers(1, &m_read_buffer);
102 glBindBuffer(GL_COPY_READ_BUFFER, m_read_buffer);
103 #ifdef USE_BUFFER_STORAGE
104 #ifdef USE_MAP
105 glBufferStorage(GL_COPY_READ_BUFFER, sizeof(int) * data.size(), nullptr, GL_CLIENT_STORAGE_BIT | GL_MAP_READ_BIT);
106 #else
107 glBufferStorage(GL_COPY_READ_BUFFER, sizeof(int) * data.size(), nullptr, GL_CLIENT_STORAGE_BIT);
108 #endif
109 #else
110 glBufferData(GL_COPY_READ_BUFFER, sizeof(int) * data.size(), nullptr, GL_DYNAMIC_READ);
111 #endif
112
113 #ifdef USE_BUFFER_STORAGE
114 printf("!! use buffer storage\n");
115 #else
116 printf("!! use buffer data\n");
117 #endif
118
119 return 0;
120 }
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:218
int program_print_errors(const GLuint program)
affiche les erreurs de compilation.
Definition program.cpp:446

◆ quit() [1/2]

int ReadBuffer::quit ( )
inlinevirtual

a deriver pour detruire les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.

Implements App.

Definition at line 122 of file tuto_count_buffer.cpp.

123 {
124 release_program(m_program);
125 glDeleteBuffers(1, &m_gpu_buffer1);
126 glDeleteBuffers(1, &m_gpu_buffer2);
127 glDeleteBuffers(1, &m_read_buffer);
128
129 return 0;
130 }
int release_program(const GLuint program)
detruit les shaders et le program.
Definition program.cpp:225

◆ render() [1/2]

int ReadBuffer::render ( )
inlinevirtual

a deriver pour afficher les objets. renvoie 1 pour continuer, 0 pour fermer l'application.

Implements App.

Definition at line 132 of file tuto_count_buffer.cpp.

133 {
134 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_gpu_buffer1);
135 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_gpu_buffer2);
136
137 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_gpu_count);
138 // remet le compteur a zero
139 int zero= 0;
140 glClearBufferData(GL_SHADER_STORAGE_BUFFER, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, &zero);
141
142 glUseProgram(m_program);
143 glDispatchCompute(4, 1, 1);
144
145 glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
146
147 glBindBuffer(GL_COPY_READ_BUFFER, m_read_buffer);
148 glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_gpu_buffer2);
149 glCopyBufferSubData(GL_SHADER_STORAGE_BUFFER, GL_COPY_READ_BUFFER, 0, 0, sizeof(int)*1024);
150
151 #ifdef USE_MAP
152 printf("!! use map\n");
153
154 // TODO: recupere n, le nombre de valeurs...
155
156 int *tmp= (int *) glMapBuffer(GL_COPY_READ_BUFFER, GL_READ_ONLY);
157 {
158 for(unsigned i= 0; i < 1024; i++)
159 printf("%d ", tmp[i]);
160 printf("\n");
161 }
162 glUnmapBuffer(GL_COPY_READ_BUFFER);
163
164 #else
165 printf("!! use get buffer\n");
166
167 // recupere le nombre de valeurs stockees dans le buffer resultat
168 int n= 0;
169 glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_gpu_count);
170 glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, sizeof(int), &n);
171
172 printf("%d values\n", n);
173
174 // recupere les valeurs
175 std::vector<int> tmp(n);
176 glGetBufferSubData(GL_COPY_READ_BUFFER, 0, sizeof(int) * tmp.size(), tmp.data());
177
178 for(unsigned i= 0; i < tmp.size(); i++)
179 printf("%d ", tmp[i]);
180 printf("\n");
181 #endif
182
183 return 0;
184 }

◆ init() [2/2]

int ReadBuffer::init ( )
inlinevirtual

a deriver pour creer les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.

Implements App.

Definition at line 32 of file tuto_read_buffer.cpp.

33 {
34 m_program= read_program("gkit2_tutos/M2/read_buffer.glsl");
35 program_print_errors(m_program);
36
37 std::vector<int> data(1024);
38
39 glGenBuffers(1, &m_gpu_buffer1);
40 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_gpu_buffer1);
41 #ifdef USE_BUFFER_STORAGE
42 glBufferStorage(GL_SHADER_STORAGE_BUFFER, sizeof(int) * data.size(), data.data(), 0);
43 #else
44 glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(int) * data.size(), data.data(), GL_STATIC_COPY);
45 #endif
46
47 glGenBuffers(1, &m_gpu_buffer2);
48 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_gpu_buffer2);
49 #ifdef USE_BUFFER_STORAGE
50 glBufferStorage(GL_SHADER_STORAGE_BUFFER, sizeof(int) * data.size(), nullptr, 0);
51 #else
52 glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(int) * data.size(), nullptr, GL_STATIC_COPY);
53 #endif
54
55 glGenBuffers(1, &m_read_buffer);
56 glBindBuffer(GL_COPY_READ_BUFFER, m_read_buffer);
57 #ifdef USE_BUFFER_STORAGE
58 #ifdef USE_MAP
59 glBufferStorage(GL_COPY_READ_BUFFER, sizeof(int) * data.size(), nullptr, GL_CLIENT_STORAGE_BIT | GL_MAP_READ_BIT);
60 #else
61 glBufferStorage(GL_COPY_READ_BUFFER, sizeof(int) * data.size(), nullptr, GL_CLIENT_STORAGE_BIT);
62 #endif
63 #else
64 glBufferData(GL_COPY_READ_BUFFER, sizeof(int) * data.size(), nullptr, GL_DYNAMIC_READ);
65 #endif
66
67 #ifdef USE_BUFFER_STORAGE
68 printf("!! use buffer storage\n");
69 #else
70 printf("!! use buffer data\n");
71 #endif
72
73 return 0;
74 }

◆ quit() [2/2]

int ReadBuffer::quit ( )
inlinevirtual

a deriver pour detruire les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.

Implements App.

Definition at line 76 of file tuto_read_buffer.cpp.

77 {
78 release_program(m_program);
79 glDeleteBuffers(1, &m_gpu_buffer1);
80 glDeleteBuffers(1, &m_gpu_buffer2);
81 glDeleteBuffers(1, &m_read_buffer);
82
83 return 0;
84 }

◆ render() [2/2]

int ReadBuffer::render ( )
inlinevirtual

a deriver pour afficher les objets. renvoie 1 pour continuer, 0 pour fermer l'application.

Implements App.

Definition at line 86 of file tuto_read_buffer.cpp.

87 {
88 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_gpu_buffer1);
89 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_gpu_buffer2);
90
91 // execute le shader
92 glUseProgram(m_program);
93 glDispatchCompute(4, 1, 1);
94
95 // attends les resultats
96 glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
97
98 // et maintenant comment on recupere les donnees qui se trouvent dans un buffer prive du gpu ?
99 // etape 1 : on commence par copier les donnees dans un buffer intermediaire qui est accessible a l'application,
100 // ie pas un buffer prive, cf la creation des 2 types de buffers dans init()...
101 glBindBuffer(GL_COPY_READ_BUFFER, m_read_buffer);
102 glCopyBufferSubData(GL_SHADER_STORAGE_BUFFER, GL_COPY_READ_BUFFER, 0, 0, sizeof(int)*1024);
103
104 // etape 2 : on relit le contenu du buffer qui contient la copie des donnees
105 #ifdef USE_MAP
106 // soit avec map()
107 printf("!! use map\n");
108
109 int *tmp= (int *) glMapBuffer(GL_COPY_READ_BUFFER, GL_READ_ONLY);
110 {
111 for(unsigned i= 0; i < 1024; i++)
112 printf("%d ", tmp[i]);
113 printf("\n");
114 }
115 glUnmapBuffer(GL_COPY_READ_BUFFER);
116
117 #else
118 // soit avec getbuffer()
119 printf("!! use get buffer\n");
120
121 std::vector<int> tmp(1024);
122 glGetBufferSubData(GL_COPY_READ_BUFFER, 0, sizeof(int) * tmp.size(), tmp.data());
123 for(unsigned i= 0; i < tmp.size(); i++)
124 printf("%d ", tmp[i]);
125 printf("\n");
126 #endif
127
128 return 0;
129 }

Member Data Documentation

◆ m_gpu_buffer1

GLuint ReadBuffer::m_gpu_buffer1

Definition at line 186 of file tuto_count_buffer.cpp.

◆ m_gpu_buffer2

GLuint ReadBuffer::m_gpu_buffer2

Definition at line 187 of file tuto_count_buffer.cpp.

◆ m_gpu_count

GLuint ReadBuffer::m_gpu_count

Definition at line 188 of file tuto_count_buffer.cpp.

◆ m_read_buffer

GLuint ReadBuffer::m_read_buffer

Definition at line 189 of file tuto_count_buffer.cpp.

◆ m_program

GLuint ReadBuffer::m_program

Definition at line 190 of file tuto_count_buffer.cpp.


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