Commit 29512bd1 authored by Jan Möbius's avatar Jan Möbius
Browse files

Christopher:

Uniform pool for render objects
Wireframe of MeshNode2 now uses linewidth

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17547 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 30119480
......@@ -94,7 +94,6 @@ void IRenderer::addRenderObject(ACG::RenderObject* _renderObject)
p->internalFlags_ = 0;
// precompile shader
ACG::ShaderCache::getInstance()->getProgram(&p->shaderDesc);
......@@ -111,7 +110,11 @@ void IRenderer::collectRenderObjects( ACG::GLState* _glState, ACG::SceneGraph::D
numLights_ = 0; // reset light counter
// flush render objects
// clear() may actually free memory, resulting in capacity = 0
for (size_t i = 0; i < renderObjects_.size(); ++i)
{
delete renderObjects_[i].uniformPool;
renderObjects_[i].uniformPool = 0;
}
renderObjects_.resize(0);
......@@ -315,23 +318,8 @@ void IRenderer::bindObjectUniforms( ACG::RenderObject* _obj, GLSL::Program* _pro
// Additional Uniforms defined in the render Object
for ( QMap<QString, QPair<unsigned int, QVariant> >::iterator additionalUniformsIter = _obj->additionalUniforms_.begin();
additionalUniformsIter != _obj->additionalUniforms_.end(); ++additionalUniformsIter ) {
switch (additionalUniformsIter.value().first) {
case GL_FLOAT:
_prog->setUniform(additionalUniformsIter.key().toLatin1(),additionalUniformsIter.value().second.toFloat());
break;
case GL_INT:
_prog->setUniform(additionalUniformsIter.key().toLatin1(),additionalUniformsIter.value().second.toInt());
break;
default:
std::cerr << "IRenderer Error: Additional Uniform data type not supported" << std::endl;
break;
}
}
if ( _obj->uniformPool )
_obj->uniformPool->bind(_prog);
// texture
for (std::map<size_t,RenderObject::Texture>::const_iterator iter = _obj->textures().begin();
......
......@@ -181,8 +181,9 @@ RenderObject::RenderObject()
alpha(1.0f), shininess(100.0f),
debugID(0), debugName(0),
internalFlags_(0)
internalFlags_(0),
uniformPool(0)
{
// set modelview and proj to identity
......@@ -363,6 +364,78 @@ void RenderObject::setGeometryShaderInputFromDrawCall(GLenum _mode) {
}
void RenderObject::setUniform( const char *_name, GLint _value )
{
if (!uniformPool)
uniformPool = new GLSL::UniformPool();
uniformPool->setUniform(_name, _value);
}
void RenderObject::setUniform( const char *_name, GLfloat _value )
{
if (!uniformPool)
uniformPool = new GLSL::UniformPool();
uniformPool->setUniform(_name, _value);
}
void RenderObject::setUniform( const char *_name, const ACG::Vec2f &_value )
{
if (!uniformPool)
uniformPool = new GLSL::UniformPool();
uniformPool->setUniform(_name, _value);
}
void RenderObject::setUniform( const char *_name, const ACG::Vec3f &_value )
{
if (!uniformPool)
uniformPool = new GLSL::UniformPool();
uniformPool->setUniform(_name, _value);
}
void RenderObject::setUniform( const char *_name, const ACG::Vec4f &_value )
{
if (!uniformPool)
uniformPool = new GLSL::UniformPool();
uniformPool->setUniform(_name, _value);
}
void RenderObject::setUniform( const char *_name, const ACG::GLMatrixf &_value, bool _transposed /*= false*/ )
{
if (!uniformPool)
uniformPool = new GLSL::UniformPool();
uniformPool->setUniform(_name, _value, _transposed);
}
void RenderObject::setUniformMat3( const char *_name, const ACG::GLMatrixf &_value, bool _transposed /*= false*/ )
{
if (!uniformPool)
uniformPool = new GLSL::UniformPool();
uniformPool->setUniform(_name, _value, _transposed);
}
void RenderObject::setUniform( const char *_name, GLint *_values, int _count )
{
if (!uniformPool)
uniformPool = new GLSL::UniformPool();
uniformPool->setUniform(_name, _values, _count);
}
void RenderObject::setUniform( const char *_name, GLfloat *_values, int _count )
{
if (!uniformPool)
uniformPool = new GLSL::UniformPool();
uniformPool->setUniform(_name, _values, _count);
}
} // namespace ACG end
......@@ -55,6 +55,7 @@
namespace GLSL{
class Program;
class UniformPool;
}
namespace ACG
......@@ -99,12 +100,15 @@ namespace SceneGraph {
*/
struct ACGDLLEXPORT RenderObject
{
friend class IRenderer;
/** default constructor
* set all members to 0
* keep renderobject a POD to avoid possible problems
*/
RenderObject();
/** \brief Priority to allow sorting of objects
*
* The renderer sorts objects based on priority from high to low before rendering.
......@@ -350,11 +354,22 @@ public:
* @param _value QVariant encapsuled value of the type
*
*/
void addUniformValue(QString _uniformName, unsigned int _dataType, QVariant _value) {
additionalUniforms_[_uniformName] = QPair<unsigned int, QVariant>( _dataType, _value );
}
void setUniform(const char *_name, GLint _value);
void setUniform(const char *_name, GLfloat _value);
void setUniform(const char *_name, const ACG::Vec2f &_value);
void setUniform(const char *_name, const ACG::Vec3f &_value);
void setUniform(const char *_name, const ACG::Vec4f &_value);
QMap<QString, QPair<unsigned int, QVariant> > additionalUniforms_;
void setUniform(const char *_name, const ACG::GLMatrixf &_value, bool _transposed = false);
void setUniformMat3(const char *_name, const ACG::GLMatrixf &_value, bool _transposed = false);
void setUniform(const char *_name, GLint *_values, int _count);
void setUniform(const char *_name, GLfloat *_values, int _count);
private:
GLSL::UniformPool* uniformPool;
};
//=============================================================================
......
......@@ -720,6 +720,8 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.shaderDesc.geometryShaderOutput = SG_GEOMETRY_OUT_TRIANGLE_STRIP;
ro.shaderDesc.geometryShaderMaxOutputPrimitives = 3;
ro.setUniform("lineWidth", _state.line_width());
add_face_RenderObjects(_renderer, &ro);
ro.shaderDesc.geometryShader = false;
......@@ -753,6 +755,8 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.shaderDesc.geometryShaderOutput = SG_GEOMETRY_OUT_TRIANGLE_STRIP;
ro.shaderDesc.geometryShaderMaxOutputPrimitives = 3;
ro.setUniform("lineWidth", _state.line_width());
add_face_RenderObjects(_renderer, &ro);
ro.shaderDesc.geometryShader = false;
......@@ -785,6 +789,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.shaderDesc.geometryShaderOutput = SG_GEOMETRY_OUT_TRIANGLE_STRIP;
ro.shaderDesc.geometryShaderMaxOutputPrimitives = 4;
ro.setUniform("screenSize", Vec2f((float)_state.viewport_width(), (float)_state.viewport_height()));
ro.setUniform("lineWidth", _state.line_width());
_renderer->addRenderObject(&ro);
ro.shaderDesc.geometryShader = false;
......@@ -822,6 +829,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.shaderDesc.geometryShaderOutput = SG_GEOMETRY_OUT_TRIANGLE_STRIP;
ro.shaderDesc.geometryShaderMaxOutputPrimitives = 4;
ro.setUniform("screenSize", Vec2f((float)_state.viewport_width(), (float)_state.viewport_height()));
ro.setUniform("lineWidth", _state.line_width());
_renderer->addRenderObject(&ro);
ro.shaderDesc.geometryShader = false;
......@@ -853,6 +863,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.shaderDesc.geometryShaderOutput = SG_GEOMETRY_OUT_TRIANGLE_STRIP;
ro.shaderDesc.geometryShaderMaxOutputPrimitives = 4;
ro.setUniform("screenSize", Vec2f((float)_state.viewport_width(), (float)_state.viewport_height()));
ro.setUniform("lineWidth", _state.line_width());
add_line_RenderObjects(_renderer, &ro);
ro.shaderDesc.geometryShader = false;
......
......@@ -2,6 +2,7 @@
in vec3 outGeometryBary;
uniform float lineWidth;
float edgeFactor()
{
......@@ -9,7 +10,7 @@ float edgeFactor()
// http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/
vec3 d = fwidth(outGeometryBary);
vec3 a3 = smoothstep(vec3(0.0), d*1.5, outGeometryBary);
vec3 a3 = smoothstep(vec3(0.0), d*lineWidth, outGeometryBary);
return min(min(a3.x, a3.y), a3.z);
}
......
......@@ -2,6 +2,7 @@
in vec3 outGeometryBary;
uniform float lineWidth;
float edgeFactor()
{
......@@ -9,7 +10,7 @@ float edgeFactor()
// http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/
vec3 d = fwidth(outGeometryBary);
vec3 a3 = smoothstep(vec3(0.0), d*1.5, outGeometryBary);
vec3 a3 = smoothstep(vec3(0.0), d*lineWidth, outGeometryBary);
return min(min(a3.x, a3.y), a3.z);
}
......
// template file for shader generator
uniform float lineWidth;
uniform vec2 screenSize;
void main()
{
const float lineWidth = 0.005;
const vec2 screenSize = vec2(1.0, 1.0);
// start/end points of line
vec4 p0 = gl_in[0].gl_Position;
vec4 p1 = gl_in[1].gl_Position;
......
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