Commit d0db9b1a authored by Christopher Tenter's avatar Christopher Tenter

screenquad: draw as tri-strip for geometry shader support and with instancing

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@19915 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 604d84b1
......@@ -55,6 +55,8 @@
#include "ScreenQuad.hh"
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/GL/GLError.hh>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/globjects.hh>
//== NAMESPACES ===============================================================
......@@ -104,10 +106,10 @@ void ScreenQuad::init ()
{
float quad[] =
{
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f
1.0f, -1.0f, -1.0f
};
glGenBuffers(1, &vbo_);
......@@ -148,7 +150,19 @@ void ScreenQuad::draw (GLSL::Program* _prog)
//----------------------------------------------------------------------------
void ScreenQuad::intDraw (GLSL::Program* _prog)
void ScreenQuad::drawInstanced( int _count, GLSL::Program* _prog /*= 0*/ )
{
if (_prog)
_prog->use();
ScreenQuad& quad = instance();
quad.intDraw(_prog, _count);
}
//----------------------------------------------------------------------------
void ScreenQuad::intDraw (GLSL::Program* _prog, int _numInstances)
{
if (!vbo_)
{
......@@ -165,7 +179,17 @@ void ScreenQuad::intDraw (GLSL::Program* _prog)
glPolygonMode(GL_FRONT, GL_FILL);
glDrawArrays(GL_QUADS, 0, 4);
if (_numInstances < 1)
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
else
{
#ifdef GL_VERSION_3_1
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, _numInstances);
#else
std::cerr << "error: instanced ScreenQuad draw - outdated glew version" << std::endl;
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
#endif
}
if (_prog)
decl_->deactivateShaderPipeline(_prog);
......
......@@ -85,6 +85,14 @@ public:
*/
static void draw(GLSL::Program* _prog = 0);
/** \brief Draw the screen quad with instancing
*
* Can be used for render to 2D-array / 3D volume
* The quad is in projected space with coordinates in [-1, 1].
* @param _count number of instances
* @param _prog GLSL shader to bind attribute id's if needed. Pass null-pointer for fixed function rendering
*/
static void drawInstanced(int _count, GLSL::Program* _prog = 0);
/** \brief Draw a 2D texture to screen
......@@ -111,7 +119,7 @@ private:
void init();
/// Internal draw function
void intDraw(GLSL::Program* _prog);
void intDraw(GLSL::Program* _prog, int _numInstances = 0);
......
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