Changeset a926b79 in opengl-game for new-game.cpp


Ignore:
Timestamp:
Mar 29, 2019, 6:47:06 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
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)
Message:

For TYPE_SHIP objects, switch to using vbos specific to the model group as opposed to the generic vbos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new-game.cpp

    rb05e2b5 ra926b79  
    521521   initModelGroupAttribs(modelGroups[TYPE_SHIP]);
    522522
    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 
    539523   modelGroups[TYPE_ASTEROID] = createModelGroup(
    540524      loadShaderProgram("./asteroid.vert", "./asteroid.frag"));
     
    635619
    636620   // player ship
    637    SceneObject* ship = createShip();
    638    objects.push_back(ship);
     621   objects.push_back(createShip());
    639622
    640623   vector<SceneObject>::iterator obj_it;
     
    19871970}
    19881971
     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
    19891977void removeModelFromGroup(ShaderModelGroup& modelGroup, SceneObject& model) {
    19901978   // TODO: Implement
     
    22772265      smg->numPoints = 0;
    22782266      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      }
    22912288   }
    22922289
     
    23222319   BufferInfo* bufferInfo = &shaderBufferInfo[modelGroups[obj.type].shaderProgram];
    23232320
    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   }
    23252326   obj.ubo_offset = bufferInfo->ubo_base + bufferInfo->ubo_offset;
    23262327
     
    23472348               break;
    23482349            case ATTRIB_UNIFORM:
    2349               break;
     2350               break;
    23502351         }
    23512352      }
     
    25362537   glBindVertexArray(modelGroups[TYPE_SHIP].vao);
    25372538
    2538    glDrawArrays(GL_TRIANGLES, shaderBufferInfo[modelGroups[TYPE_SHIP].shaderProgram].vbo_base, modelGroups[TYPE_SHIP].numPoints);
     2539   glDrawArrays(GL_TRIANGLES, 0, modelGroups[TYPE_SHIP].numPoints);
    25392540
    25402541   glUseProgram(modelGroups[TYPE_ASTEROID].shaderProgram);
Note: See TracChangeset for help on using the changeset viewer.