Changeset 0b1b52d in opengl-game for graphics-pipeline_opengl.cpp


Ignore:
Timestamp:
Oct 4, 2019, 8:27:07 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
771b33a
Parents:
83b5b4b
Message:

In openglgame, port over the functionality to specify and initialize varying attributes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • graphics-pipeline_opengl.cpp

    r83b5b4b r0b1b52d  
    66using namespace std;
    77
    8 GraphicsPipeline_OpenGL::GraphicsPipeline_OpenGL() {
     8GraphicsPipeline_OpenGL::GraphicsPipeline_OpenGL(Viewport viewport) {
     9   this->viewport = viewport;
    910}
    1011
     
    1213}
    1314
     15void GraphicsPipeline_OpenGL::addVaryingAttribute(VaryingAttribType attribType, GLint size, GLenum type,
     16      size_t fieldOffset) {
     17   // TODO: Throw an exception instead
     18   if (type != GL_FLOAT && type != GL_UNSIGNED_INT) {
     19      cout << "Unknown shader program attribute type: " << type << endl;
     20      return;
     21   }
     22
     23   VaryingAttribInfo attributeDesc;
     24
     25   attributeDesc.attribType = attribType;
     26   attributeDesc.index = this->varyingAttribs.size();
     27   attributeDesc.size = size;
     28   attributeDesc.type = type;
     29   attributeDesc.fieldOffset = fieldOffset;
     30
     31   this->varyingAttribs.push_back(attributeDesc);
     32}
     33
    1434void GraphicsPipeline_OpenGL::createPipeline(string vertShaderFile, string fragShaderFile) {
    1535   shaderProgram = loadShaderProgram(vertShaderFile, fragShaderFile);
    1636
    17    glGenVertexArrays(1, &vao);
    18    numPoints = 0;
     37   this->numPoints = 0;
     38   glGenVertexArrays(1, &this->vao);
     39   glBindVertexArray(this->vao);
     40
     41   vector<VaryingAttribInfo>::iterator it;
     42   for (it = this->varyingAttribs.begin(); it != this->varyingAttribs.end(); it++) {
     43      glEnableVertexAttribArray(it->index);
     44
     45      glGenBuffers(1, &it->buffer);
     46      glBindBuffer(GL_ARRAY_BUFFER, it->buffer);
     47
     48      switch (it->type) {
     49         case GL_FLOAT: {
     50            glVertexAttribPointer(it->index, it->size, it->type, GL_FALSE, 0, NULL);
     51            break;
     52         }
     53         case GL_UNSIGNED_INT: {
     54            glVertexAttribIPointer(it->index, it->size, it->type, 0, NULL);
     55            break;
     56         }
     57      }
     58   }
    1959}
    2060
Note: See TracChangeset for help on using the changeset viewer.