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


Ignore:
Timestamp:
Feb 11, 2019, 4:20:35 AM (6 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
a0eb547
Parents:
b62c109
Message:

Remove SceneObject.shader_program and use the object type to get the shader program from the ShaderModelGroup map instead

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new-game.cpp

    rb62c109 rdd9771c  
    6666   mat4 model_mat, model_base, model_transform;
    6767   mat4 translate_mat; // beginning of doing what's mentioned above
    68    GLuint shader_program;
    6968   unsigned int num_points;
    7069   GLuint vertex_vbo_offset;
     
    202201
    203202// TODO: instead of using these methods, create constructors for these
    204 SceneObject* createShip(GLuint shader);
    205 Asteroid* createAsteroid(vec3 pos, GLuint shader);
    206 Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width, GLuint laser_sp);
    207 SceneObject* createExplosion(GLuint shader);
     203SceneObject* createShip();
     204Asteroid* createAsteroid(vec3 pos);
     205Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width);
     206SceneObject* createExplosion();
    208207
    209208void translateLaser(Laser* laser, const vec3& translation, GLuint ubo);
     
    479478
    480479   // player ship
    481    SceneObject* ship = createShip(modelGroups[TYPE_SHIP].shaderProgram);
     480   SceneObject* ship = createShip();
    482481   objects.push_back(ship);
    483482
     
    750749         elapsed_seconds_spawn += elapsed_seconds;
    751750         if (elapsed_seconds_spawn > 0.5f) {
    752             SceneObject* obj = createAsteroid(vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f)), modelGroups[TYPE_ASTEROID].shaderProgram);
     751            SceneObject* obj = createAsteroid(vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f)));
    753752            addObjectToScene(obj, shaderBufferInfo, modelGroups,
    754753               points_vbo,
     
    807806            vec3 offset(objects[0]->model_transform * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    808807
    809             leftLaser = createLaser(vec3(-0.21f, -1.19f, 1.76f)+offset, vec3(-0.21f, -1.19f, -3.0f)+offset,
    810                vec3(0.0f, 1.0f, 0.0f), 0.03f, modelGroups[TYPE_LASER].shaderProgram);
     808            leftLaser = createLaser(
     809               vec3(-0.21f, -1.19f, 1.76f)+offset,
     810               vec3(-0.21f, -1.19f, -3.0f)+offset,
     811               vec3(0.0f, 1.0f, 0.0f), 0.03f);
    811812            addObjectToScene(leftLaser, shaderBufferInfo, modelGroups,
    812813               points_vbo,
     
    823824            vec3 offset(objects[0]->model_transform * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    824825
    825             rightLaser = createLaser(vec3(0.21f, -1.19f, 1.76f) + offset, vec3(0.21f, -1.19f, -3.0f) + offset,
    826                vec3(0.0f, 1.0f, 0.0f), 0.03f, modelGroups[TYPE_LASER].shaderProgram);
     826            rightLaser = createLaser(
     827               vec3(0.21f, -1.19f, 1.76f) + offset,
     828               vec3(0.21f, -1.19f, -3.0f) + offset,
     829               vec3(0.0f, 1.0f, 0.0f), 0.03f);
    827830            addObjectToScene(rightLaser, shaderBufferInfo, modelGroups,
    828831               points_vbo,
     
    13291332   objects.push_back(obj);
    13301333
    1331    BufferInfo* bufferInfo = &shaderBufferInfo[obj->shader_program];
     1334   BufferInfo* bufferInfo = &shaderBufferInfo[modelGroups[obj->type].shaderProgram];
    13321335
    13331336   // Check if the buffers aren't large enough to fit the new object and, if so, call
     
    14251428}
    14261429
    1427 SceneObject* createShip(GLuint shader) {
     1430SceneObject* createShip() {
    14281431   SceneObject* ship = new SceneObject();
    14291432
    14301433   ship->type = TYPE_SHIP;
    1431    ship->shader_program = shader;
    14321434
    14331435   ship->points = {
     
    18221824*/
    18231825// TODO: Make the color parameter have an effect
    1824 Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width, GLuint laser_sp) {
     1826Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width) {
    18251827   Laser* obj = new Laser();
    18261828   obj->type = TYPE_LASER;
    18271829   obj->targetAsteroid = NULL;
    1828    obj->shader_program = laser_sp;
    18291830
    18301831   vec3 ray = end - start;
     
    20012002   glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL);
    20022003
    2003    objExplosion = createExplosion(modelGroups[TYPE_EXPLOSION].shaderProgram);
     2004   objExplosion = createExplosion();
    20042005   addObjectToScene(objExplosion, shaderBufferInfo, modelGroups,
    20052006      points_vbo,
     
    20492050         num_objects++;
    20502051
    2051          shaderCounts[(*it)->shader_program] += (*it)->num_points;
    2052          shaderUboCounts[(*it)->shader_program]++;
     2052         shaderCounts[modelGroups[(*it)->type].shaderProgram] += (*it)->num_points;
     2053         shaderUboCounts[modelGroups[(*it)->type].shaderProgram]++;
    20532054
    20542055         it++;
     
    21312132                  GLuint ubo,
    21322133                  GLuint model_mat_idx_vbo) {
    2133    BufferInfo* bufferInfo = &shaderBufferInfo[obj.shader_program];
     2134   BufferInfo* bufferInfo = &shaderBufferInfo[modelGroups[obj.type].shaderProgram];
    21342135
    21352136   obj.vertex_vbo_offset = bufferInfo->vbo_base + modelGroups[obj.type].numPoints;
     
    24702471}
    24712472
    2472 Asteroid* createAsteroid(vec3 pos, GLuint shader) {
     2473Asteroid* createAsteroid(vec3 pos) {
    24732474   Asteroid* obj = new Asteroid();
    24742475   obj->type = TYPE_ASTEROID;
    2475    obj->shader_program = shader;
    24762476   obj->hp = 10.0f;
    24772477
     
    25932593}
    25942594
    2595 SceneObject* createExplosion(GLuint shader) {
     2595SceneObject* createExplosion() {
    25962596   SceneObject* obj = new SceneObject();
    25972597   obj->type = TYPE_EXPLOSION;
    2598    obj->shader_program = shader;
    25992598
    26002599   obj->points = {};
Note: See TracChangeset for help on using the changeset viewer.