Exemplo n.º 1
0
void testDrawIndexing::render()
{
    float Depth(1.0f);
    glClearBufferfv(GL_DEPTH, 0, &Depth);
    glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]);

    {
        glBindBuffer(GL_UNIFORM_BUFFER, this->BufferName[buffer::BUFFER_FRAME]);
        glm::mat4* Pointer = reinterpret_cast<glm::mat4*>(glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT));

        glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 2048.0f);
        glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -this->TranlationCurrent.y - 512));
        glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, this->RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
        glm::mat4 View = glm::rotate(ViewRotateX, this->RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
        glm::mat4 Model = glm::mat4(1.0f);

        *Pointer = Projection * View * Model;
        glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    glViewportIndexedfv(0, &glm::vec4(0, 0, this->getWindowSize())[0]);

    this->beginTimer();
    switch(this->Indexing)
    {
    case DRAW:
    case DIVISOR_MULTI_INDEXING:
    case ID_INDEXING:
    {
        int const DrawChunk = 2;
        for(int i = 0; i < DrawChunk; ++i)
            glMultiDrawArraysIndirect(GL_TRIANGLES, 0, static_cast<GLsizei>(DrawCount / DrawChunk), 0);
    }
    case DIVISOR_INDEXING:
    {
        for(std::size_t DrawIndex(0); DrawIndex < DrawCount; ++DrawIndex)
            glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 1, static_cast<GLuint>(DrawIndex));
    }
    break;
    case ATTRIB_INDEXING:
    {
        for(std::size_t DrawIndex(0); DrawIndex < DrawCount; ++DrawIndex)
        {
            glVertexAttribI1i(1, DrawIndex % 2 ? 0 : 1); // 1 is DRAW_ID attribute location
            glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 1, 0);
        }
    }
    break;
    case UNIFORM_INDEXING:
    {
        for(std::size_t DrawIndex(0); DrawIndex < DrawCount; ++DrawIndex)
        {
            glProgramUniform1i(this->ProgramName, UniformDrawIndex, DrawIndex % 2 ? 0 : 1);
            glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 1, 0);
        }
    }
    break;
    default:
        assert(0);
        break;
    }
    this->endTimer();
}
Exemplo n.º 2
0
void RenderMeshSkinned(Camera* pCamera, Shader* pShader, Mesh* pMesh,
    const Vec4f& position, const Mat4f& orientation) {
  if(pShader == NULL) return; // should go away when we sort
  if(pMesh == NULL) return; // should go away when we sort

  MeshSkinned* skinnedMesh = dynamic_cast<MeshSkinned*>(pMesh);
  if(!skinnedMesh) return;
  //skinnedMesh->updateFullPoses(); // do on demand? or setup dirty system and do both?
  
  pShader->StartUsing();
  pShader->SetPosition(&position);
  pShader->SetOrientation(&orientation);
  pShader->SetCameraParams(pCamera);
  GLuint colorHandle = pShader->GetColorHandle();
  
  GLint boneIndexHandle = pShader->getAttrib("vertBoneIndex");
  GLint boneRotations = pShader->getUniform("boneRotations");
  GLint bonePositions = pShader->getUniform("bonePositions");
  if(boneIndexHandle == -1 || boneRotations == -1 || bonePositions == -1) {
    printf("RenderMeshSkinned problem with shader handles\n");
  }

  if(!skinnedMesh->_boneRotations.empty()) {
    glUniformMatrix4fv(boneRotations, (::std::min)(20, (int)skinnedMesh->_boneRotations.size()), GL_FALSE, skinnedMesh->_boneRotations[0].raw()); // huh, this might not work actually, need to check we didn't pad
  }
  if(!skinnedMesh->_bonePositions.empty()) {
    glUniform4fv(bonePositions, (::std::min)(20, (int)skinnedMesh->_bonePositions.size()), skinnedMesh->_bonePositions[0].raw()); // also might not work due to extra padding
  }

  // wow ugly now need to do buffers
  int numTris = pMesh->getNumberTriangles();
  int startTriangle = 0;
  int endTriangle = numTris;
  glBegin(GL_TRIANGLES);
  Vec4f a, b, c;
  Vec4f colorA, colorB, colorC;
  int aInd, bInd, cInd;
  for (int t = startTriangle; t < endTriangle && t < numTris; t++) {
    pMesh->getIndexedTriangle(t, aInd, bInd, cInd, a, b, c);
    if(colorHandle != -1) {
      pMesh->getColors(t, colorA, colorB, colorC);
      glVertexAttrib4fv(colorHandle, colorA.raw());
    }
    glVertexAttribI1i(boneIndexHandle, *skinnedMesh->getBoneIndex(aInd));
    glVertex4fv(a.raw());

    if(colorHandle != -1) {
      glVertexAttrib4fv(colorHandle, colorB.raw());
    }
    glVertexAttribI1i(boneIndexHandle, *skinnedMesh->getBoneIndex(bInd));
    glVertex4fv(b.raw());

    if(colorHandle != -1) {
      glVertexAttrib4fv(colorHandle, colorC.raw());
    }
    glVertexAttribI1i(boneIndexHandle, *skinnedMesh->getBoneIndex(cInd));
    glVertex4fv(c.raw());
  }
  glEnd();
  pShader->StopUsing();
}
Exemplo n.º 3
0
void PShader::setAttribute(std::string name, GLint value) {
    glVertexAttribI1i(glGetAttribLocation(glProgram, name.c_str()), value);
}