diff options
author | Marius Kintel <marius@kintel.net> | 2013-05-24 22:40:09 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-05-24 22:40:09 (GMT) |
commit | e1766faeeda4218a453121ec81f8007cc1a1734d (patch) | |
tree | 409e8ae7f7fb2065499cf44b038497b6a5daf689 /src/renderer.cc | |
parent | ef9d8a853be1a6d6ca48239fcc79106ba374ee21 (diff) |
Initial implementation of improved operator handling. Provides the bulk of work for #304
Diffstat (limited to 'src/renderer.cc')
-rw-r--r-- | src/renderer.cc | 94 |
1 files changed, 44 insertions, 50 deletions
diff --git a/src/renderer.cc b/src/renderer.cc index 77dcde9..7c4f8d7 100644 --- a/src/renderer.cc +++ b/src/renderer.cc @@ -1,49 +1,11 @@ #include "renderer.h" #include "rendersettings.h" -#include "linalg.h" -void Renderer::setColor(const float color[4], GLint *shaderinfo) const +bool Renderer::getColor(Renderer::ColorMode colormode, Color4f &col) const { - Color4f col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR); - float c[4] = {color[0], color[1], color[2], color[3]}; - if (c[0] < 0) c[0] = col[0]; - if (c[1] < 0) c[1] = col[1]; - if (c[2] < 0) c[2] = col[2]; - if (c[3] < 0) c[3] = col[3]; - glColor4fv(c); - if (shaderinfo) { - glUniform4f(shaderinfo[1], c[0], c[1], c[2], c[3]); - glUniform4f(shaderinfo[2], (c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2, 1.0); - } -} - -void Renderer::setColor(ColorMode colormode, const float color[4], GLint *shaderinfo) const -{ - if (colormode == COLORMODE_BACKGROUND && - color[0] >= 0 || color[1] >= 0 || color[2] >= 0 || color[3] >= 0) { - - Color4f col; - col.setRgb(180, 180, 180, 255); - float c[4] = {color[0], color[1], color[2], color[3]}; - if (c[0] < 0) c[0] = col[0]; - if (c[1] < 0) c[1] = col[1]; - if (c[2] < 0) c[2] = col[2]; - if (c[3] < 0) c[3] = col[3]; - - c[3] /= 2; // Background objects are half-transparent - setColor(c, shaderinfo); - } - else { - setColor(colormode, shaderinfo); - } -} - -void Renderer::setColor(ColorMode colormode, GLint *shaderinfo) const -{ - Color4f col; switch (colormode) { case COLORMODE_NONE: - return; + return false; break; case COLORMODE_MATERIAL: col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR); @@ -52,7 +14,7 @@ void Renderer::setColor(ColorMode colormode, GLint *shaderinfo) const col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_BACK_COLOR); break; case COLORMODE_HIGHLIGHT: - col.setRgb(255, 157, 81, 128); + col.setRgb(255, 81, 81, 128); break; case COLORMODE_BACKGROUND: col.setRgb(180, 180, 180, 128); @@ -70,19 +32,51 @@ void Renderer::setColor(ColorMode colormode, GLint *shaderinfo) const col.setRgb(150, 150, 150, 128); break; default: - return; + return false; break; } - float rgba[4]; - rgba[0] = col[0]; - rgba[1] = col[1]; - rgba[2] = col[2]; - rgba[3] = col[3]; - glColor4fv(rgba); + return true; +} + +void Renderer::setColor(const float color[4], GLint *shaderinfo) const +{ + Color4f col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR); + float c[4] = {color[0], color[1], color[2], color[3]}; + if (c[0] < 0) c[0] = col[0]; + if (c[1] < 0) c[1] = col[1]; + if (c[2] < 0) c[2] = col[2]; + if (c[3] < 0) c[3] = col[3]; + glColor4fv(c); #ifdef ENABLE_OPENCSG if (shaderinfo) { - glUniform4f(shaderinfo[1], col[0], col[1], col[2], 1.0f); - glUniform4f(shaderinfo[2], (col[0]+1)/2, (col[1]+1)/2, (col[2]+1)/2, 1.0f); + glUniform4f(shaderinfo[1], c[0], c[1], c[2], c[3]); + glUniform4f(shaderinfo[2], (c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2, 1.0); } #endif } + +void Renderer::setColor(ColorMode colormode, const float color[4], GLint *shaderinfo) const +{ + Color4f basecol; + if (getColor(colormode, basecol)) { + if (colormode == COLORMODE_BACKGROUND) { + basecol = Color4f(color[0] >= 0 ? color[0] : basecol[0], + color[1] >= 0 ? color[1] : basecol[1], + color[2] >= 0 ? color[2] : basecol[2], + color[3] >= 0 ? color[3] : basecol[3]); + } + else if (colormode != COLORMODE_HIGHLIGHT) { + basecol = Color4f(color[0] >= 0 ? color[0] : basecol[0], + color[1] >= 0 ? color[1] : basecol[1], + color[2] >= 0 ? color[2] : basecol[2], + color[3] >= 0 ? color[3] : basecol[3]); + } + setColor(basecol.data(), shaderinfo); + } +} + +void Renderer::setColor(ColorMode colormode, GLint *shaderinfo) const +{ + float c[4] = {-1,-1,-1,-1}; + setColor(colormode, c, shaderinfo); +} |