Commit 256338d1 authored by Robert Menzel's avatar Robert Menzel

Compatibility improvements

* Some GL 2.1 compatibility improvements:
  * On GL 2.1 the shaderfiles are read from a different folder by default
  * 3.0+ functions are not compiled for 2.1 any more
  * The RenderObject is not 2.1 compatible, so it's not compiled for old systems
    atm. A port could be possible.
  * ACGL compiles for GL 2.1 now
* Added compile warning in case the desired OpenGL version is not defined by
  the build system (which could screw up conditional compile)
* Minor fixes
parent 257a0859
......@@ -32,7 +32,13 @@ protected:
mTexturePath ("Texture/"),
mGeometryPath ("Geometry/"),
mShaderPath ("Shader/")
{}
{
# if defined(ACGL_OPENGL_VERSION_21)
// use an alternative path if compiled for old OpenGL
mShaderPath = "Shader21/";
ACGL::Utils::message() << "compiled for OpenGL 2.1: using alternative shader folder Shader21/" << std::endl;
# endif
}
public:
~Settings(){}
......
......@@ -7,10 +7,11 @@
#define ACGL_OPENGL_CONTROLLER_RENDEROBJECTCONTROL_HH
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/GL.hh>
#if (ACGL_OPENGL_VERSION >= 30)
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/RenderObject.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
......@@ -69,4 +70,6 @@ protected:
} // OpenGL
} // ACGL
#endif // GL >= 3.0
#endif // ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH
......@@ -62,6 +62,7 @@
# define ACGL_OPENGL_VERSION 42
# else
// failback:
# warning NO ACGL_OPENGL_VERSION_XY SET!
# define ACGL_OPENGL_VERSION_32
# define ACGL_OPENGL_VERSION 32
# endif
......
......@@ -29,8 +29,6 @@ typedef Resource::NameManager<FrameBufferObject> FrameBufferObjectNameManager;
typedef Resource::NameManager<RenderBuffer> RenderBufferNameManager;
typedef Resource::NameManager<RenderObject> RenderObjectNameManager;
typedef Resource::NameManager<Shader> ShaderNameManager;
typedef Resource::FileManager<Shader> ShaderFileManager;
......@@ -56,6 +54,10 @@ typedef Resource::FileManager<VertexBufferObject> VertexBufferObjectFileManager;
typedef Resource::NameManager<Viewport> ViewportNameManager;
#if (ACGL_OPENGL_VERSION >= 30)
typedef Resource::NameManager<RenderObject> RenderObjectNameManager;
#endif // GL >= 3.0
} // OpenGL
} // ACGL
......
......@@ -12,17 +12,26 @@
*
* Instead of setting those objects individually and hoping that they match
* a RenderObject can take care of that.
*
*
*
* The RenderObject build around automatic mapping of VBOs to Shader-Attribute-Names
* to Shader-Outputs to Texture-Names.
* The needed calls (and GLSL in/out type shader-inputs/outputs) are not supported
* on GL prior to 3.0, so RenderObject is not available on older GL implementations.
* A similar class however could get implemented for GL 2.1 and GLES 2.0...
*/
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/GL.hh>
#if (ACGL_OPENGL_VERSION >= 30)
#include <vector>
#include <string>
#include <tr1/memory>
#include <iostream>
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Objects/VertexBufferObject.hh>
#include <ACGL/OpenGL/Objects/FrameBufferObject.hh>
......@@ -151,4 +160,6 @@ ACGL_SHARED_TYPEDEF(RenderObject)
} // OpenGL
} // ACGL
#endif
#endif // ACGL_OPENGL_OBJECTS_RENDEROBJECT_HH
......@@ -93,12 +93,12 @@ public:
// ===================================================================================================== \/
public:
inline GLint getUniformLocation (const std::string& _nameInShader) const { return glGetUniformLocation (mContext, _nameInShader.c_str()); }
#if (ACGL_OPENGL_VERSION >= 30)
inline GLint getAttributeLocation (const std::string& _nameInShader) const { return glGetAttribLocation (mContext, _nameInShader.c_str()); }
inline GLint getFragmentDataLocation (const std::string& _nameInShader) const { return glGetFragDataLocation(mContext, _nameInShader.c_str()); }
inline void bindAttributeLocation (const std::string& _nameInShader, GLuint _location) const { glBindAttribLocation (mContext, _location, _nameInShader.c_str()); }
inline void bindFragmentDataLocation (const std::string& _nameInShader, GLuint _location) const { glBindFragDataLocation (mContext, _location, _nameInShader.c_str()); }
#endif
inline void use(void) const { glUseProgram(mContext); }
inline void attachShader(const ConstSharedShader& _shader)
......
......@@ -7,26 +7,30 @@
using namespace ACGL::OpenGL;
// inline GLint getFragmentDataLocation (const std::string& _nameInShader) const { return glGetFragDataLocation(mContext, _nameInShader.c_str()); }
SharedFrameBufferObject FrameBufferObjectControl::create(void)
{
SharedFrameBufferObject frameBuffer(new FrameBufferObject());
frameBuffer->bind();
#if (ACGL_OPENGL_VERSION >= 30)
if(mpShaderProgram)
{
std::vector<int_t> assignmentOrder(mColorAttachments.size());
for(std::vector<int_t>::size_type i = 0; i < assignmentOrder.size(); ++i) assignmentOrder[i] = -1;
for(FrameBufferObject::AttachmentVec::size_type i = 0; i < mColorAttachments.size(); ++i)
{
GLint location = mpShaderProgram->getFragmentDataLocation(mColorAttachments[i].name);
if (location < 0) {
ACGL::Utils::warning() << "ShaderProgram has no FragDataLocation named " << mColorAttachments[i].name << " - ignored" << std::endl;
}
assignmentOrder[location] = i;
}
for(std::vector<int_t>::size_type j = 0; j < assignmentOrder.size(); ++j)
{
if (assignmentOrder[j] < 0) continue;
if(mColorAttachments[assignmentOrder[j]].texture)
frameBuffer->attachColorTexture(mColorAttachments[assignmentOrder[j]].name, mColorAttachments[assignmentOrder[j]].texture);
else if(mColorAttachments[assignmentOrder[j]].renderBuffer)
......@@ -35,6 +39,7 @@ SharedFrameBufferObject FrameBufferObjectControl::create(void)
}
else
#endif
{
for(FrameBufferObject::AttachmentVec::size_type i = 0; i < mColorAttachments.size(); ++i)
{
......
......@@ -56,10 +56,12 @@ SharedShaderProgram ShaderProgramControlAutoFiles::create(void)
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".fsh").type(GL_FRAGMENT_SHADER)))
shaderProgram->attachShader(shader);
#if (ACGL_OPENGL_VERSION >= 30)
for (std::vector<std::string>::size_type i = 0; i < mAttributeLocations.size(); ++i)
shaderProgram->bindAttributeLocation(mAttributeLocations[i], i);
for (std::vector<std::string>::size_type i = 0; i < mFragmentDataLocations.size(); ++i)
shaderProgram->bindFragmentDataLocation(mFragmentDataLocations[i], i);
#endif
if(shaderProgram->link())
return shaderProgram;
......
......@@ -33,6 +33,7 @@ SharedVertexBufferObject VertexBufferObjectControl::create(void)
for(AttributeDefineVec::size_type i = 0; i < mAttributeDefines.size(); i++)
{
#if (ACGL_OPENGL_VERSION >= 30)
if(mpShaderProgram)
{
vertexBuffer->attachAttribute(
......@@ -42,6 +43,7 @@ SharedVertexBufferObject VertexBufferObjectControl::create(void)
mpShaderProgram->getAttributeLocation(mAttributeDefines[i].attributeName));
}
else
#endif
{
vertexBuffer->attachAttribute(
mAttributeDefines[i].name,
......
......@@ -294,10 +294,15 @@ bool VertexBufferObjectControlFileOBJ::loadOBJ(SharedVertexBufferObject& _vertex
arrayBuffer->removeAttributes();
_vertexBuffer->removeAttributes();
#if (ACGL_OPENGL_VERSION >= 30)
GLint shaderIndexPosition = (mpShaderProgram) ? mpShaderProgram->getAttributeLocation("aPosition") : 0;
GLint shaderIndexNormal = (mpShaderProgram) ? mpShaderProgram->getAttributeLocation("aNormal") : 1;
GLint shaderIndexTexCoord = (mpShaderProgram) ? mpShaderProgram->getAttributeLocation("aTexCoord") : ((hasNormals) ? 2 : 1);
#else
GLint shaderIndexPosition = 0;
GLint shaderIndexNormal = 1;
GLint shaderIndexTexCoord = ((hasNormals) ? 2 : 1);
#endif
arrayBuffer->attachAttribute("aPosition", GL_FLOAT, 4, GL_FALSE);
_vertexBuffer->attachAttribute("aPosition", 0, "aPosition", shaderIndexPosition);
if(hasNormals)
......
......@@ -4,6 +4,8 @@
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Objects/RenderObject.hh>
#if (ACGL_OPENGL_VERSION >= 30)
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/Base/StringOperations.hh>
......@@ -39,6 +41,7 @@ void RenderObject::updateMappings (void)
for(FrameBufferObject::AttachmentVec::size_type i = 0; i < mpFrameBufferObject->getColorAttachments().size(); ++i)
mpDrawBuffers[i] = GL_COLOR_ATTACHMENT0 + mpShaderProgramObject->getShaderProgram()->getFragmentDataLocation(mpFrameBufferObject->getColorAttachments()[i].name);
}
}
void RenderObject::bindFrameBufferObject (void) const
......@@ -95,3 +98,5 @@ void RenderObject::disableVertexBufferObject (void) const
openGLRareError();
}
}
#endif
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