Changeset a926b79 in opengl-game for new-game.cpp
- Timestamp:
- Mar 29, 2019, 6:47:06 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- c4c205e
- Parents:
- b05e2b5
- git-author:
- Dmitry Portnoy <dmitry.portnoy@…> (03/29/19 18:43:20)
- git-committer:
- Dmitry Portnoy <dmitry.portnoy@…> (03/29/19 18:47:06)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rb05e2b5 ra926b79 521 521 initModelGroupAttribs(modelGroups[TYPE_SHIP]); 522 522 523 glBindBuffer(GL_ARRAY_BUFFER, points_vbo);524 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);525 modelGroups[TYPE_SHIP].attribs["vertex_position"].buffer = points_vbo;526 527 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);528 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);529 modelGroups[TYPE_SHIP].attribs["vertex_color"].buffer = colors_vbo;530 531 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo);532 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL);533 modelGroups[TYPE_SHIP].attribs["vertex_normal"].buffer = normals_vbo;534 535 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo);536 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, NULL);537 modelGroups[TYPE_SHIP].attribs["ubo_index"].buffer = model_mat_idx_vbo;538 539 523 modelGroups[TYPE_ASTEROID] = createModelGroup( 540 524 loadShaderProgram("./asteroid.vert", "./asteroid.frag")); … … 635 619 636 620 // player ship 637 SceneObject* ship = createShip(); 638 objects.push_back(ship); 621 objects.push_back(createShip()); 639 622 640 623 vector<SceneObject>::iterator obj_it; … … 1987 1970 } 1988 1971 1972 // TODO: Add the code to resize the buffers here 1973 // addObjectToScene and removeObjectFromScene pretty much already do this. 1974 // However, when addObjectToScene resizes the buffers, it resizes them for all object types 1975 // It would be more efficient to only resize them for the object type in question 1976 1989 1977 void removeModelFromGroup(ShaderModelGroup& modelGroup, SceneObject& model) { 1990 1978 // TODO: Implement … … 2277 2265 smg->numPoints = 0; 2278 2266 smg->vboCapacity = shaderCounts[smg->shaderProgram] * 2; 2279 /* 2280 if (modelGroupIt->first == TYPE_LASER) { 2281 smg = &modelGroups[modelGroupIt->first]; 2282 smg->numPoints = shaderCounts[smg->shaderProgram]; 2283 2284 // Here, I could add glBufferData calls to allocate space for laser buffers 2285 if (modelGroupIt->first == TYPE_LASER) { 2286 glBindBuffer(GL_ARRAY_BUFFER, smg->attribs["vertex_position"].buffer); 2287 glBufferData(GL_ARRAY_BUFFER, smg->numPoints * sizeof(GLfloat) * smg->attribs["vertex_position"].size, NULL, GL_DYNAMIC_DRAW); 2288 } 2289 } 2290 */ 2267 2268 if (modelGroupIt->first == TYPE_SHIP) { 2269 int numPoints = shaderCounts[smg->shaderProgram]; 2270 AttribInfo* attrib; 2271 2272 attrib = &smg->attribs["vertex_position"]; 2273 glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer); 2274 glBufferData(GL_ARRAY_BUFFER, numPoints * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW); 2275 2276 attrib = &smg->attribs["vertex_color"]; 2277 glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer); 2278 glBufferData(GL_ARRAY_BUFFER, numPoints * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW); 2279 2280 attrib = &smg->attribs["vertex_normal"]; 2281 glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer); 2282 glBufferData(GL_ARRAY_BUFFER, numPoints * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW); 2283 2284 attrib = &smg->attribs["ubo_index"]; 2285 glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer); 2286 glBufferData(GL_ARRAY_BUFFER, numPoints * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW); 2287 } 2291 2288 } 2292 2289 … … 2322 2319 BufferInfo* bufferInfo = &shaderBufferInfo[modelGroups[obj.type].shaderProgram]; 2323 2320 2324 obj.vertex_vbo_offset = bufferInfo->vbo_base + modelGroups[obj.type].numPoints; 2321 if (obj.type == TYPE_SHIP) { 2322 obj.vertex_vbo_offset = modelGroups[obj.type].numPoints; 2323 } else { 2324 obj.vertex_vbo_offset = bufferInfo->vbo_base + modelGroups[obj.type].numPoints; 2325 } 2325 2326 obj.ubo_offset = bufferInfo->ubo_base + bufferInfo->ubo_offset; 2326 2327 … … 2347 2348 break; 2348 2349 case ATTRIB_UNIFORM: 2349 break;2350 break; 2350 2351 } 2351 2352 } … … 2536 2537 glBindVertexArray(modelGroups[TYPE_SHIP].vao); 2537 2538 2538 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[modelGroups[TYPE_SHIP].shaderProgram].vbo_base, modelGroups[TYPE_SHIP].numPoints);2539 glDrawArrays(GL_TRIANGLES, 0, modelGroups[TYPE_SHIP].numPoints); 2539 2540 2540 2541 glUseProgram(modelGroups[TYPE_ASTEROID].shaderProgram);
Note:
See TracChangeset
for help on using the changeset viewer.