| 665 | } |
| 666 | |
| 667 | static void DrawControlledFace(const Box& box_, const Object* object_, int face_selected_, FaceDisplay face_display_) { |
| 668 | PROFILER_GPU_ZONE(g_profiler_ctx, "DrawControlledFace"); |
| 669 | |
| 670 | mat4 translate_mat; |
| 671 | translate_mat.SetTranslation(box_.center); |
| 672 | mat4 model_mat = object_->GetTransform() * translate_mat; |
| 673 | |
| 674 | static const GLfloat vertices[] = { |
| 675 | -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, // front (in coord system: +x to the right, +y up, -z into distance) |
| 676 | -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, // back |
| 677 | -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, // left |
| 678 | 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, // right |
| 679 | -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, // bottom |
| 680 | -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f // top |
| 681 | }; |
| 682 | static const GLuint faces[] = { |
| 683 | 0, 1, 2, 0, 2, 3, 5, 4, 7, 5, 7, 6, 8, 9, 10, 8, 10, 11, |
| 684 | 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23}; |
| 685 | |
| 686 | static VBOContainer vertices_vbo; |
| 687 | static VBOContainer faces_vbo; |
| 688 | if (!vertices_vbo.valid()) { |
| 689 | vertices_vbo.Fill(kVBOStatic | kVBOFloat, sizeof(vertices), (void*)vertices); |
| 690 | faces_vbo.Fill(kVBOStatic | kVBOElement, sizeof(faces), (void*)faces); |
| 691 | } |
| 692 | |
| 693 | Graphics* graphics = Graphics::Instance(); |
| 694 | |
| 695 | GLState gl_state; |
| 696 | gl_state.depth_test = true; |
| 697 | gl_state.blend = true; |
| 698 | gl_state.cull_face = false; |
| 699 | gl_state.depth_write = false; |
| 700 | graphics->setGLState(gl_state); |
| 701 | graphics->setDepthFunc(GL_LEQUAL); |
| 702 | |
| 703 | mat4 scale_mat; |
| 704 | scale_mat.SetScale(box_.dims); |
| 705 | mat4 new_model_mat = model_mat * scale_mat; |
| 706 | |
| 707 | // Draw selected face |
| 708 | if (face_selected_ != -1) { |
| 709 | Shaders* shaders = Shaders::Instance(); |
| 710 | Camera* cam = ActiveCameras::Get(); |
| 711 | int shader_id = shaders->returnProgram("face_stipple"); |
| 712 | shaders->setProgram(shader_id); |
| 713 | mat4 mvp_mat = cam->GetProjMatrix() * cam->GetViewMatrix() * new_model_mat; |
| 714 | shaders->SetUniformMat4("mvp_mat", mvp_mat); |
| 715 | shaders->SetUniformVec4("color", vec4(0.1f, 1.0f, 0.4f, 1.0f)); |
| 716 | int vert_coord_id = shaders->returnShaderAttrib("vert_coord", shader_id); |
| 717 | vertices_vbo.Bind(); |
| 718 | faces_vbo.Bind(); |
| 719 | graphics->EnableVertexAttribArray(vert_coord_id); |
| 720 | glVertexAttribPointer(vert_coord_id, 3, GL_FLOAT, false, 3 * sizeof(GLfloat), 0); |
| 721 | graphics->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, (const void*)(sizeof(GLuint) * (face_selected_ * 6))); |
| 722 | graphics->ResetVertexAttribArrays(); |
| 723 | // Draw direction line for selected face |
| 724 | if (face_display_.facing || face_display_.plane) { |
no test coverage detected