void display()
{
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

	glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	glViewport(0, 0, Window.Size.x, Window.Size.y);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]);

	glUseProgram(ProgramName);
	glUniformMatrix4fv(UniformMVP, 1, GL_FALSE, &MVP[0][0]);

	glBindVertexArray(VertexArrayName);
	glPatchParameteri(GL_PATCH_VERTICES, VertexCount);
	glPatchParameterfv(GL_PATCH_DEFAULT_INNER_LEVEL, &glm::vec2(16.f)[0]);
	glPatchParameterfv(GL_PATCH_DEFAULT_OUTER_LEVEL, &glm::vec4(16.f)[0]);
	glDrawArraysInstanced(GL_PATCHES, 0, VertexCount, 1);

	glf::checkError("display");
	glf::swapBuffers();
}
Ejemplo n.º 2
0
void Renderer::RenderPatch(bsp_face *face) {
  Shader &shader = *current_shader_;
  auto offset = face->vertex;

  glUniform1ui(shader.patchWidth_, face->size[0]);
  glUniform1ui(shader.patchHeight_, face->size[1]);

  if ((face->size[0] == 15 || face->size[1] == 15) ||
      (face->size[0] == 9 && face->size[1] == 5)) {
    logger::Debug("patch size: %d %d %d", face->size[0], face->size[1],
                  face->num_vertices);
    return;
  }

  if (face->size[0] * face->size[1] != face->num_vertices) {
    logger::Debug("VERY BAD VERY BAD");
    return;
  }

  glVertexAttribPointer(shader.position_idx_, 3, GL_FLOAT, GL_FALSE,
                        sizeof(bsp_vertex),
                        reinterpret_cast<void *>(offset * sizeof(bsp_vertex)));

  glVertexAttribPointer(shader.tex_coord_idx_, 2, GL_FLOAT, GL_FALSE,
                        sizeof(bsp_vertex),
                        reinterpret_cast<void *>(offset * sizeof(bsp_vertex) +
                                                 sizeof(glm::vec3)));

  glVertexAttribPointer(
      shader.lm_coord_idx_, 2, GL_FLOAT, GL_FALSE, sizeof(bsp_vertex),
      reinterpret_cast<void *>(offset * sizeof(bsp_vertex) + sizeof(glm::vec3) +
                               sizeof(glm::vec2)));

  glVertexAttribPointer(
      shader.color_idx_, 4, GL_BYTE, GL_FALSE, sizeof(bsp_vertex),
      reinterpret_cast<void *>(offset * sizeof(bsp_vertex) + sizeof(glm::vec3) +
                               sizeof(glm::vec2) + sizeof(glm::vec2) +
                               sizeof(glm::vec3)));

  float subdivisions[] = {10.0f, 10.0f, 10.0f, 10.0f};
  glPatchParameterfv(GL_PATCH_DEFAULT_OUTER_LEVEL, subdivisions);
  glPatchParameterfv(GL_PATCH_DEFAULT_INNER_LEVEL, subdivisions);
  glPatchParameteri(GL_PATCH_VERTICES, face->num_vertices);
  glDrawArrays(GL_PATCHES, 0, face->num_vertices);

  /*
  std::vector<bezier *> patches = world.map_->patches_[face];

  for (int i = 0; i < patches.size(); ++i) {
    const bezier *b = patches[i];

    glVertexAttribPointer(current_shader_->position_idx_, 3, GL_FLOAT,
  GL_FALSE,
                          sizeof(bsp_vertex),
                          reinterpret_cast<void *>(b->m_vertex_offset));

    glVertexAttribPointer(
        current_shader_->tex_coord_idx_, 2, GL_FLOAT, GL_FALSE,
        sizeof(bsp_vertex),
        reinterpret_cast<void *>(b->m_vertex_offset + sizeof(glm::vec3)));

    glVertexAttribPointer(current_shader_->lm_coord_idx_, 2, GL_FLOAT,
  GL_FALSE,
                          sizeof(bsp_vertex),
                          reinterpret_cast<void *>(b->m_vertex_offset +
                                                   sizeof(glm::vec3) +
                                                   sizeof(glm::vec2)));

    glVertexAttribPointer(
        current_shader_->color_idx_, 4, GL_BYTE, GL_FALSE,
  sizeof(bsp_vertex),
        reinterpret_cast<void *>(b->m_vertex_offset + sizeof(float) * 10));

    // double work for each bezier, doesnt seem to be needed.. or maybe it
  does
    // because of vertex colors! then 0 shouldnt be there
    // prepare_shader(shader, 0, current_face.lm_index);

    unsigned int count[10] = {22, 22, 22, 22, 22, 22, 22, 22, 22, 22};
    GLvoid *indices[10];
    for (int k = 0; k < 10; k++) {
      indices[k] =
          (GLvoid *)(b->m_index_offset + sizeof(unsigned int) * k * 11 * 2);
    }

    glMultiDrawElements(GL_TRIANGLE_STRIP, (const GLsizei *)count,
                        GL_UNSIGNED_INT, (const GLvoid **)indices, 10);
  }

  */
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL40_nglPatchParameterfv(JNIEnv *__env, jclass clazz, jint pname, jlong valuesAddress, jlong __functionAddress) {
	const GLfloat *values = (const GLfloat *)(intptr_t)valuesAddress;
	glPatchParameterfvPROC glPatchParameterfv = (glPatchParameterfvPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	glPatchParameterfv(pname, values);
}