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


Ignore:
Timestamp:
Apr 19, 2020, 1:23:02 AM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
5ba732a
Parents:
6385d0f
Message:

Change VulkanGame::addObject() to return a reference to the newly-created object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new-game.cpp

    r6385d0f r4994692  
    501501   defineModelGroupAttrib(modelGroups[TYPE_SHIP], "ubo_index", ATTRIB_OBJECT_VARYING,
    502502      1, GL_UNSIGNED_INT, offset_of(&SceneObject::ubo_offset));
    503 /*** END OF REFACTORED CODE ***/
    504503
    505504   defineModelGroupUniform(modelGroups[TYPE_SHIP], "view", ATTRIB_UNIFORM,
     
    510509   initModelGroupAttribs(modelGroups[TYPE_SHIP]);
    511510
    512 /*** START OF REFACTORED CODE ***/
    513511   modelGroups[TYPE_ASTEROID] = createModelGroup(
    514512      loadShaderProgram("gl-shaders/asteroid.vert", "gl-shaders/asteroid.frag"));
     
    523521   defineModelGroupAttrib(modelGroups[TYPE_ASTEROID], "ubo_index", ATTRIB_OBJECT_VARYING,
    524522      1, GL_UNSIGNED_INT, offset_of(&SceneObject::ubo_offset));
    525 /*** END OF REFACTORED CODE ***/
    526523
    527524   defineModelGroupUniform(modelGroups[TYPE_ASTEROID], "view", ATTRIB_UNIFORM,
     
    532529   initModelGroupAttribs(modelGroups[TYPE_ASTEROID]);
    533530
    534 /*** START OF REFACTORED CODE ***/
    535531   modelGroups[TYPE_LASER] = createModelGroup(
    536532      loadShaderProgram("gl-shaders/laser.vert", "gl-shaders/laser.frag"));
     
    543539   defineModelGroupAttrib(modelGroups[TYPE_LASER], "ubo_index", ATTRIB_OBJECT_VARYING,
    544540      1, GL_UNSIGNED_INT, offset_of(&SceneObject::ubo_offset));
    545 /*** END OF REFACTORED CODE ***/
    546541
    547542   defineModelGroupUniform(modelGroups[TYPE_LASER], "view", ATTRIB_UNIFORM,
     
    553548
    554549   initModelGroupAttribs(modelGroups[TYPE_LASER]);
    555 
    556 /*** START OF REFACTORED CODE ***/
     550/*** END OF REFACTORED CODE ***/
     551
    557552   modelGroups[TYPE_EXPLOSION] = createModelGroup(
    558553      loadShaderProgram("gl-shaders/explosion.vert", "gl-shaders/explosion.frag"));
     
    565560   defineModelGroupAttrib(modelGroups[TYPE_EXPLOSION], "ubo_index", ATTRIB_OBJECT_VARYING,
    566561      1, GL_UNSIGNED_INT, offset_of(&SceneObject::ubo_offset));
    567 /*** END OF REFACTORED CODE ***/
    568562
    569563   defineModelGroupUniform(modelGroups[TYPE_EXPLOSION], "cur_time", ATTRIB_UNIFORM,
     
    829823
    830824            leftLaser = createLaser(
    831                vec3(-0.21f, -1.19f, 1.76f)+offset,
    832                vec3(-0.21f, -1.19f, -3.0f)+offset,
     825               vec3(-0.21f, -1.19f, 1.76f) + offset,
     826               vec3(-0.21f, -1.19f, -3.0f) + offset,
    833827               vec3(0.0f, 1.0f, 0.0f), 0.03f);
    834828            addObjectToScene(leftLaser, shaderBufferInfo, modelGroups, ubo);
     
    18871881   // To project point P onto line AB:
    18881882   // projection = A + dot(AP,AB) / dot(AB,AB) * AB
    1889    vec3 projOnLaser = start + glm::dot(cam_pos-start, ray) / (length*length) * ray;
     1883   vec3 projOnLaser = start + glm::dot(cam_pos - start, ray) / (length * length) * ray;
    18901884   vec3 laserToCam = cam_pos - projOnLaser;
    18911885
     
    19441938}
    19451939
     1940/*** START OF REFACTORED CODE ***/
    19461941void defineModelGroupUniform(ShaderModelGroup& modelGroup, string name, AttribType attribType,
    19471942                  GLint size, UniformType type, GLfloat* data) {
     
    19571952
    19581953void initModelGroupAttribs(ShaderModelGroup& modelGroup) {
    1959 /*** START OF REFACTORED CODE ***/
    19601954   glBindVertexArray(modelGroup.vao);
    19611955
    19621956   map<string, AttribInfo>::iterator it;
    19631957   for (it = modelGroup.attribs.begin(); it != modelGroup.attribs.end(); it++) {
    1964 /*** END OF REFACTORED CODE ***/
    19651958      if (it->second.attribType == ATTRIB_UNIFORM) {
    19661959         it->second.buffer = glGetUniformLocation(modelGroup.shaderProgram, it->first.c_str());
    1967 /*** START OF REFACTORED CODE ***/
    19681960      } else {
    19691961         glEnableVertexAttribArray(it->second.index);
     
    19841976      }
    19851977   }
    1986 /*** START OF REFACTORED CODE ***/
    1987 }
     1978}
     1979/*** END OF REFACTORED CODE ***/
    19881980
    19891981void bindUniformData(AttribInfo& attrib) {
Note: See TracChangeset for help on using the changeset viewer.