23 template <
typename T >
24 struct alignas(8)
gvec2
29 gvec2( const ::vec2& v ) : x(v.x), y(v.y) {}
37 template <
typename T >
38 struct alignas(16)
gvec3
43 gvec3( const ::vec3& v ) : x(v.x), y(v.y), z(v.z) {}
44 gvec3(
const Point& v ) : x(v.x), y(v.y), z(v.z) {}
45 gvec3(
const Vector& v ) : x(v.x), y(v.y), z(v.z) {}
53 template <
typename T >
54 struct alignas(16)
gvec4
56 alignas(4) T x, y, z, w;
59 gvec4( const ::vec4& v ) : x(v.x), y(v.y), z(v.z), w(v.w) {}
69class StorageBuffer :
public App
73 StorageBuffer( ) :
App(1024, 640, 4, 3) {}
87 vertex( ) : position(), normal(), texcoord() {}
103 vertex( ) : position(), normal(), texcoord() {}
109 std::vector<vertex> data(m_mesh.vertex_count());
110 for(
int i= 0; i < m_mesh.vertex_count(); i++)
112 data[i].position= m_mesh.positions().at(i);
113 data[i].normal= m_mesh.normals().at(i);
114 data[i].texcoord= m_mesh.texcoords().at(i);
118 glGenVertexArrays(1, &m_vao);
119 glBindVertexArray(m_vao);
122 glGenBuffers(1, &m_buffer);
124 glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_buffer);
125 glBufferData(GL_SHADER_STORAGE_BUFFER,
sizeof(
vertex) * data.size(), data.data(), GL_STREAM_READ);
128 m_program=
read_program(
"gkit2_tutos/tuto_storage_buffer.glsl");
133 m_mesh.bounds(pmin, pmax);
134 m_camera.lookat(pmin, pmax);
139 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
142 glDepthFunc(GL_LESS);
143 glEnable(GL_DEPTH_TEST);
153 glDeleteTextures(1, &m_texture);
154 glDeleteBuffers(1, &m_buffer);
155 glDeleteVertexArrays(1, &m_vao);
162 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
165 update_camera( m_camera );
167 glBindVertexArray(m_vao);
168 glUseProgram(m_program);
176 program_uniform(m_program,
"mvMatrix", mv);
177 program_uniform(m_program,
"normalMatrix", mv.
normal());
178 program_uniform(m_program,
"mvpMatrix", mvp);
183 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_buffer);
185 glDrawArrays(GL_TRIANGLES, 0, m_mesh.vertex_count());
201int main(
int argc,
char **argv )
int run()
execution de l'application.
App(const int width, const int height, const int major=3, const int minor=3)
constructeur, dimensions de la fenetre et version d'openGL.
representation d'un objet / maillage.
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
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 window_height()
renvoie la hauteur de la fenetre de l'application.
int window_width()
renvoie la largeur de la fenetre de l'application.
float global_time()
renvoie le temps ecoule depuis le lancement de l'application, en millisecondes.
Transform RotationY(const float a)
renvoie la matrice representation une rotation de a degree autour de l'axe Y.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
GLuint read_program(const char *filename, const char *definitions)
int program_print_errors(const GLuint program, const char *filename)
affiche les erreurs de compilation.
int release_program(const GLuint program)
detruit les shaders et le program.
void program_use_texture(const GLuint program, const char *uniform, const int unit, const GLuint texture, const GLuint sampler)
configure le pipeline et le shader program pour utiliser une texture, et des parametres de filtrage,...
GLuint read_texture(const int unit, const char *filename, const GLenum texel_type)
representation d'un point 3d.
vecteur generique, utilitaire.
vecteur generique, utilitaire.
representation de l'indexation complete d'un sommet