# HG changeset patch # User Teemu Piippo # Date 1580564037 -7200 # Node ID 90443fb328eaca5a4dcfa5f50b6ec63fb7cc381e # Parent bbb901b974040157b2c024292f7784a5e424104c wired renderstyle up diff -r bbb901b97404 -r 90443fb328ea locale/fi.ts --- a/locale/fi.ts Fri Jan 31 00:25:35 2020 +0200 +++ b/locale/fi.ts Sat Feb 01 15:33:57 2020 +0200 @@ -209,7 +209,7 @@ PartRenderer - + Rendering error @@ -256,22 +256,22 @@ gl::Compiler - + Vertex shader: - + Fragment shader: - + Shader compile error - + Could not compile shaders. diff -r bbb901b97404 -r 90443fb328ea src/gl/common.h --- a/src/gl/common.h Fri Jan 31 00:25:35 2020 +0200 +++ b/src/gl/common.h Sat Feb 01 15:33:57 2020 +0200 @@ -141,4 +141,13 @@ BfcRedGreen, RandomColors }; + + // These are also defined in shaders + enum class FragmentStyle + { + Normal = 0, + BfcGreen = 1, + BfcRed = 2, + RandomColors = 3, + }; } diff -r bbb901b97404 -r 90443fb328ea src/gl/compiler.cpp --- a/src/gl/compiler.cpp Fri Jan 31 00:25:35 2020 +0200 +++ b/src/gl/compiler.cpp Sat Feb 01 15:33:57 2020 +0200 @@ -37,12 +37,29 @@ uniform mat4 modelMatrix; uniform mat4 viewMatrix; uniform mat4 projectionMatrix; +uniform int fragmentStyle; + +const int FRAGSTYLE_Normal = 0; +const int FRAGSTYLE_BfcGreen = 1; +const int FRAGSTYLE_BfcRed = 2; +const int FRAGSTYLE_Random = 3; void main() { mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); vNormal = normalize(normalMatrix * normal); - vColor = color; + if (fragmentStyle == FRAGSTYLE_BfcGreen) + { + vColor = vec4(0.2, 0.9, 0.2, 1.0); + } + else if (fragmentStyle == FRAGSTYLE_BfcRed) + { + vColor = vec4(0.9, 0.2, 0.2, 1.0); + } + else + { + vColor = color; + } vFragPos = vec3(modelMatrix * vec4(position, 1.0)); gl_Position = projectionMatrix * viewMatrix * vec4(vFragPos, 1.0); } diff -r bbb901b97404 -r 90443fb328ea src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Fri Jan 31 00:25:35 2020 +0200 +++ b/src/gl/partrenderer.cpp Sat Feb 01 15:33:57 2020 +0200 @@ -103,26 +103,49 @@ glClearColor(0.8f, 0.8f, 0.8f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); - glEnable(GL_LIGHTING); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f, 1.0f); switch (this->renderStyle) { case gl::RenderStyle::Normal: + this->setFragmentStyle(gl::FragmentStyle::Normal); + this->renderAllArrays(); + break; case gl::RenderStyle::BfcRedGreen: + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + this->setFragmentStyle(gl::FragmentStyle::BfcGreen); + renderVao(gl::ArrayClass::Triangles); + renderVao(gl::ArrayClass::Quads); + glCullFace(GL_FRONT); + this->setFragmentStyle(gl::FragmentStyle::BfcRed); + renderVao(gl::ArrayClass::Triangles); + renderVao(gl::ArrayClass::Quads); + glDisable(GL_CULL_FACE); + this->setFragmentStyle(gl::FragmentStyle::Normal); + renderVao(gl::ArrayClass::Lines); case gl::RenderStyle::RandomColors: + this->setFragmentStyle(gl::FragmentStyle::RandomColors); + this->renderAllArrays(); break; case gl::RenderStyle::Wireframe: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + this->setFragmentStyle(gl::FragmentStyle::Normal); + this->renderAllArrays(); break; } + glDisable(GL_POLYGON_OFFSET_FILL); +} + +void PartRenderer::renderAllArrays() +{ // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering. renderVao(gl::ArrayClass::Triangles); renderVao(gl::ArrayClass::Quads); renderVao(gl::ArrayClass::Lines); - glDisable(GL_POLYGON_OFFSET_FILL); } + void PartRenderer::updateViewMatrix() { // I'm not quite sure why using the exponent function on the zoom factor causes linear zoom behavior @@ -188,6 +211,19 @@ this->update(); } +/** + * @brief Changes the color of rendered fragments + * @param newFragmentStyle new fragment style to use + */ +void PartRenderer::setFragmentStyle(gl::FragmentStyle newFragmentStyle) +{ + this->compiler->setUniform("fragmentStyle", static_cast(newFragmentStyle)); +} + +/** + * @brief Changes the way the scene is rendered + * @param newStyle new render style to use + */ void PartRenderer::setRenderStyle(const gl::RenderStyle newStyle) { this->renderStyle = newStyle; diff -r bbb901b97404 -r 90443fb328ea src/gl/partrenderer.h --- a/src/gl/partrenderer.h Fri Jan 31 00:25:35 2020 +0200 +++ b/src/gl/partrenderer.h Sat Feb 01 15:33:57 2020 +0200 @@ -29,6 +29,8 @@ void mouseMoveEvent(QMouseEvent* event) override; void wheelEvent(QWheelEvent* event) override; private: + void setFragmentStyle(gl::FragmentStyle fragStyle); + void renderAllArrays(); void renderScene(); void updateViewMatrix(); Model* const model;