void blinnphong_app::startup() { load_shaders(); glGenBuffers(1, &uniforms_buffer); glBindBuffer(GL_UNIFORM_BUFFER, uniforms_buffer); glBufferData(GL_UNIFORM_BUFFER, sizeof(uniforms_block), NULL, GL_DYNAMIC_DRAW); object.load("media/objects/sphere.sbm"); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); }
void multidrawindirect_app::startup() { int i; load_shaders(); object.load("media/objects/asteroids.sbm"); glGenBuffers(1, &indirect_draw_buffer); glBindBuffer(GL_DRAW_INDIRECT_BUFFER, indirect_draw_buffer); glBufferData(GL_DRAW_INDIRECT_BUFFER, NUM_DRAWS * sizeof(DrawArraysIndirectCommand), NULL, GL_STATIC_DRAW); DrawArraysIndirectCommand * cmd = (DrawArraysIndirectCommand *) glMapBufferRange(GL_DRAW_INDIRECT_BUFFER, 0, NUM_DRAWS * sizeof(DrawArraysIndirectCommand), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); for (i = 0; i < NUM_DRAWS; i++) { object.get_sub_object_info(i % object.get_sub_object_count(), cmd[i].first, cmd[i].count); cmd[i].primCount = 1; cmd[i].baseInstance = i; } glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER); glBindVertexArray(object.get_vao()); glGenBuffers(1, &draw_index_buffer); glBindBuffer(GL_ARRAY_BUFFER, draw_index_buffer); glBufferData(GL_ARRAY_BUFFER, NUM_DRAWS * sizeof(GLuint), NULL, GL_STATIC_DRAW); GLuint * draw_index = (GLuint *)glMapBufferRange(GL_ARRAY_BUFFER, 0, NUM_DRAWS * sizeof(GLuint), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); for (i = 0; i < NUM_DRAWS; i++) { draw_index[i] = i; } glUnmapBuffer(GL_ARRAY_BUFFER); glVertexAttribIPointer(10, 1, GL_UNSIGNED_INT, 0, NULL); glVertexAttribDivisor(10, 1); glEnableVertexAttribArray(10); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); }