Commit 78578d4b authored by Jan Möbius's avatar Jan Möbius
Browse files

Check for geometry shader support and if it is required

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16273 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4258d7b5
......@@ -524,8 +524,11 @@ QString IRenderer::dumpCurrentRenderObjectsToString(ACG::RenderObject** _list, b
outStrm << "\n---------------------end-vertex-shader--------------------\n\n";
outStrm << "\n---------------------geometry-shader--------------------\n\n";
for (int i = 0; i < progGen.getGeometryShaderCode().size(); ++i)
outStrm << progGen.getGeometryShaderCode()[i] << "\n";
if ( progGen.hasGeometryShader() )
for (int i = 0; i < progGen.getGeometryShaderCode().size(); ++i)
outStrm << progGen.getGeometryShaderCode()[i] << "";
else
outStrm << "No geometry shader\n";
outStrm << "\n---------------------end-geometry-shader--------------------\n\n";
......@@ -553,8 +556,11 @@ QString IRenderer::dumpCurrentRenderObjectsToString(ACG::RenderObject** _list, b
outStrm << "\n---------------------end-vertex-shader--------------------\n\n";
outStrm << "\n---------------------geometry-shader--------------------\n\n";
for (int i = 0; i < progGen.getGeometryShaderCode().size(); ++i)
outStrm << progGen.getGeometryShaderCode()[i] << "\n";
if ( progGen.hasGeometryShader() )
for (int i = 0; i < progGen.getGeometryShaderCode().size(); ++i)
outStrm << progGen.getGeometryShaderCode()[i] << "\n";
else
outStrm << "No geometry shader\n";
outStrm << "\n---------------------end-geometry-shader--------------------\n\n";
outStrm << "\n---------------------fragment-shader--------------------\n\n";
......
......@@ -49,6 +49,7 @@
#include <iostream>
#include <algorithm>
#include <QFile>
#include <QFileInfo>
#include <QDir>
......@@ -57,6 +58,8 @@
#include <ACG/GL/gl.hh>
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <QGLFormat>
namespace ACG
{
......@@ -64,6 +67,15 @@ 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;
}
......@@ -135,8 +147,9 @@ GLSL::Program* ACG::ShaderCache::getProgram( const ShaderGenDesc* _desc, unsigne
outStrm << "\n---------------------geometry-shader--------------------\n\n";
for (int i = 0; i < progGen.getGeometryShaderCode().size(); ++i)
outStrm << progGen.getVertexShaderCode()[i] << "\n";
if (progprogGen.hasGeometryShader() )
for (int i = 0; i < progGen.getGeometryShaderCode().size(); ++i)
outStrm << progGen.getVertexShaderCode()[i] << "\n";
outStrm << "\n---------------------fragment-shader--------------------\n\n";
......@@ -152,25 +165,27 @@ GLSL::Program* ACG::ShaderCache::getProgram( const ShaderGenDesc* _desc, unsigne
// TODO: Build geometry shader only if supported!
GLSL::FragmentShader* fragShader = new GLSL::FragmentShader();
// GLSL::GeometryShader* geomShader = new GLSL::GeometryShader();
GLSL::VertexShader* vertShader = new GLSL::VertexShader();
vertShader->setSource(progGen.getVertexShaderCode());
progGen.getGeometryShaderCode();
//geomShader->setSource(progGen.getGeometryShaderCode());
fragShader->setSource(progGen.getFragmentShaderCode());
vertShader->compile();
//geomShader->compile();
fragShader->compile();
GLSL::Program* prog = new GLSL::Program();
prog->attach(vertShader);
//prog->attach(geomShader);
prog->attach(fragShader);
// Check if we have a geometry shader and if we have support for it, enable it here
if ( geometryShaderSupported_ && progGen.hasGeometryShader() ) {
GLSL::GeometryShader* geomShader = new GLSL::GeometryShader();
geomShader->setSource(progGen.getGeometryShaderCode());
geomShader->compile();
prog->attach(geomShader);
}
prog->link();
glCheckErrors();
......
......@@ -93,7 +93,10 @@ public:
protected:
ShaderCache();
/** Flag if geometry shaders are supported
* set in constructor
*/
bool geometryShaderSupported_;
struct CacheEntry
{
......
......@@ -663,6 +663,10 @@ void ShaderProgGenerator::buildGeometryShader()
delete geometry_;
// Only build a geometry shader if enabled
if ( !desc_.geometryShader )
return;
geometry_ = new ShaderGenerator();
......
......@@ -90,9 +90,12 @@ struct ShaderGenDesc
const char* geometryTemplateFile;
const char* fragmentTemplateFile;
/// convert ShaderGenDesc to string format for debugging
QString toString() const;
/// Flag setting, if we want a geometry shader
bool geometryShader;
};
......@@ -622,6 +625,8 @@ public:
*/
static unsigned int registerModifier(ShaderModifier* _modifier);
bool hasGeometryShader() { return desc_.geometryShader; };
private:
/** \brief Loads external shader templates
......
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