26 template <
typename T >
27 struct alignas(8)
gvec2
32 gvec2(
const vec2& v ) : x(v.x), y(v.y) {}
40 template <
typename T >
41 struct alignas(16)
gvec3
46 gvec3(
const vec3& v ) : x(v.x), y(v.y), z(v.z) {}
47 gvec3(
const Point& v ) : x(v.x), y(v.y), z(v.z) {}
48 gvec3(
const Vector& v ) : x(v.x), y(v.y), z(v.z) {}
56 template <
typename T >
57 struct alignas(16)
gvec4
59 alignas(4) T x, y, z, w;
62 gvec4(
const vec4& v ) : x(v.x), y(v.y), z(v.z), w(v.w) {}
75 RT(
const char *filename ) :
AppTime(1024, 640)
82 if(m_mesh.vertex_count() == 0)
86 m_mesh.bounds(pmin, pmax);
87 m_camera.lookat(pmin, pmax);
89 glGenVertexArrays(1, &m_vao);
90 glBindVertexArray(m_vao);
92 glGenBuffers(1, &m_buffer);
93 glBindBuffer(GL_UNIFORM_BUFFER, m_buffer);
103 std::vector<triangle> data;
104 data.reserve(m_mesh.triangle_count());
105 for(
int i= 0; i < m_mesh.triangle_count(); i++)
113 if(data.size() < 1024)
115 glBufferData(GL_UNIFORM_BUFFER, data.size() *
sizeof(triangle), data.data(), GL_STATIC_READ);
118 m_program=
read_program(
"gkit2_tutos/M2/raytrace.glsl");
122 GLint index= glGetUniformBlockIndex(m_program,
"triangleData");
123 glUniformBlockBinding(m_program, index, 0);
135 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
141 m_mesh.bounds(pmin, pmax);
142 m_camera.lookat(pmin, pmax);
147 unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
148 if(mb & SDL_BUTTON(1))
149 m_camera.rotation(mx, my);
150 else if(mb & SDL_BUTTON(3))
152 else if(mb & SDL_BUTTON(2))
161 glBindVertexArray(m_vao);
162 glUseProgram(m_program);
165 glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_buffer);
166 program_uniform(m_program,
"triangle_count", std::min((
int) m_mesh.triangle_count(), 1024) );
168 program_uniform(m_program,
"mvpInvMatrix", mvp.
inverse());
169 glDrawArrays(GL_TRIANGLES, 0, 3);
184int main(
int argc,
char **argv )
186 const char *filename=
"data/cornell.obj";
AppTime(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.
representation d'un objet / maillage.
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
int window_height()
renvoie la hauteur de la fenetre de l'application.
void clear_key_state(const SDL_Keycode key)
desactive une touche du clavier.
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
int window_width()
renvoie la largeur de la fenetre de l'application.
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)
affiche les erreurs de compilation.
representation d'un point 3d.
int init()
a deriver pour creer les objets openGL.
int render()
a deriver pour afficher les objets.
int quit()
a deriver pour detruire les objets openGL.
representation d'un triangle.