Commit 7e3ec493 authored by Jan Möbius's avatar Jan Möbius
Browse files

Moved geometry shader support down one step

Renamed input and output of color in geometry fragment and vertex shader

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16278 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 88a89c79
......@@ -514,6 +514,9 @@ QString IRenderer::dumpCurrentRenderObjectsToString(ACG::RenderObject** _list, b
outStrm << "\n";
// TODO: Remove!!!
_list[i]->shaderDesc.geometryShader = true;
outStrm << _list[i]->shaderDesc.toString();
ShaderProgGenerator progGen(&(_list[i]->shaderDesc));
......@@ -526,7 +529,7 @@ QString IRenderer::dumpCurrentRenderObjectsToString(ACG::RenderObject** _list, b
outStrm << "\n---------------------geometry-shader--------------------\n\n";
if ( progGen.hasGeometryShader() )
for (int i = 0; i < progGen.getGeometryShaderCode().size(); ++i)
outStrm << progGen.getGeometryShaderCode()[i] << "";
outStrm << progGen.getGeometryShaderCode()[i] << "\n";
else
outStrm << "No geometry shader\n";
outStrm << "\n---------------------end-geometry-shader--------------------\n\n";
......@@ -546,6 +549,9 @@ QString IRenderer::dumpCurrentRenderObjectsToString(ACG::RenderObject** _list, b
outStrm << "\n";
// TODO: Remove!!!
_list[i]->shaderDesc.geometryShader = true;
outStrm << renderObjects_[i].shaderDesc.toString();
ShaderProgGenerator progGen(&(renderObjects_[i].shaderDesc));
......
......@@ -58,8 +58,6 @@
#include <ACG/GL/gl.hh>
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <QGLFormat>
namespace ACG
{
......@@ -67,16 +65,6 @@ namespace ACG
ShaderCache::ShaderCache()
{
// Check for geometry shader support on creation
// We need at least version 2.0 or higher
QGLFormat::OpenGLVersionFlags flags = QGLFormat::openGLVersionFlags();
geometryShaderSupported_ = flags.testFlag(QGLFormat::OpenGL_Version_3_2);
if ( geometryShaderSupported_ )
std::cerr << "ok" << std::endl;
}
ShaderCache::~ShaderCache()
......@@ -121,7 +109,6 @@ GLSL::Program* ACG::ShaderCache::getProgram( const ShaderGenDesc* _desc, unsigne
}
// glsl program not in cache, generate shaders
ShaderProgGenerator progGen(_desc, _usage);
#ifdef SG_DEBUG_OUTPUT
......@@ -178,7 +165,7 @@ GLSL::Program* ACG::ShaderCache::getProgram( const ShaderGenDesc* _desc, unsigne
prog->attach(fragShader);
// Check if we have a geometry shader and if we have support for it, enable it here
if ( geometryShaderSupported_ && progGen.hasGeometryShader() ) {
if ( progGen.hasGeometryShader() ) {
GLSL::GeometryShader* geomShader = new GLSL::GeometryShader();
geomShader->setSource(progGen.getGeometryShaderCode());
geomShader->compile();
......
......@@ -93,11 +93,6 @@ public:
protected:
ShaderCache();
/** Flag if geometry shaders are supported
* set in constructor
*/
bool geometryShaderSupported_;
struct CacheEntry
{
ShaderGenDesc desc;
......
......@@ -50,6 +50,7 @@
#include <QFileInfo>
#include <QDir>
#include <QTextStream>
#include <QGLFormat>
namespace ACG
......@@ -103,12 +104,12 @@ void ShaderGenerator::initVertexShaderIO(const ShaderGenDesc* _desc)
std::string strColorOut = "";
if (_desc->shadeMode == SG_SHADE_FLAT)
strColorOut = "flat out vec4 outColor;";
strColorOut = "flat out vec4 outVertexColor;";
else
{
if (_desc->shadeMode == SG_SHADE_GOURAUD ||
_desc->vertexColors)
strColorOut = "vec4 outColor";
strColorOut = "vec4 outVertexColor";
}
if (strColorOut.size())
......@@ -149,6 +150,9 @@ void ShaderGenerator::initGeometryShaderIO(const ShaderGenDesc* _desc) {
break;
}
addInput("outVertexColor[]");
addOutput("outGeometryColor");
// TODO: Correctly pass information about the available data
// addStringToList("VertexData {", &inputs_, "in ", "");
// addStringToList("vec2 texCoord;", &inputs_, "", "");
......@@ -169,13 +173,20 @@ void ShaderGenerator::initFragmentShaderIO(const ShaderGenDesc* _desc)
std::string strColorOut = "";
std::string inputColorName = "outVertexColor";
if ( _desc->geometryShader ) {
inputColorName = "outGeometryColor";
}
if (_desc->shadeMode == SG_SHADE_FLAT)
strColorOut = "flat in vec4 outColor;";
strColorOut = "flat in vec4 " + inputColorName + ";";
else
{
if (_desc->shadeMode == SG_SHADE_GOURAUD ||
_desc->vertexColors)
strColorOut = "vec4 outColor";
strColorOut = "vec4 " + inputColorName + ";";
}
if (strColorOut.size())
......@@ -403,6 +414,10 @@ ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc,
{
memcpy(&desc_, _desc, sizeof(ShaderGenDesc));
// We need at least version 2.0 or higher to support geometry shaders
QGLFormat::OpenGLVersionFlags flags = QGLFormat::openGLVersionFlags();
desc_.geometryShader &= flags.testFlag(QGLFormat::OpenGL_Version_3_2);
loadLightingFunctions();
generateShaders();
......@@ -583,8 +598,6 @@ void ShaderProgGenerator::buildVertexShader()
}
vertex_->buildShaderCode(&mainCode);
}
......@@ -640,7 +653,7 @@ void ShaderProgGenerator::addVertexEndCode(QStringList* _code)
if (desc_.shadeMode == SG_SHADE_GOURAUD ||
desc_.shadeMode == SG_SHADE_FLAT ||
desc_.vertexColors)
_code->push_back("outColor = sg_cColor;");
_code->push_back("outVertexColor = sg_cColor;");
if (desc_.shadeMode == SG_SHADE_PHONG)
{
......@@ -931,9 +944,14 @@ void ShaderProgGenerator::addFragmentBeginCode(QStringList* _code)
_code->push_back("vec4 sg_cColor = vec4(g_cEmissive, ALPHA);");
if (desc_.shadeMode == SG_SHADE_GOURAUD ||
desc_.shadeMode == SG_SHADE_FLAT ||
desc_.vertexColors)
_code->push_back("sg_cColor = outColor;");
desc_.shadeMode == SG_SHADE_FLAT ||
desc_.vertexColors)
{
if ( desc_.geometryShader )
_code->push_back("sg_cColor = outGeometryColor;");
else
_code->push_back("sg_cColor = outVertexColor;");
}
if (desc_.shadeMode == SG_SHADE_PHONG)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment