Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ACGL
acgl
Commits
0469d2c4
Commit
0469d2c4
authored
Feb 09, 2012
by
Robert Menzel
Browse files
RenderObject, SPO and Uniform should still work (with minor adjustments), VBO is broken
parent
6c294ed8
Changes
11
Hide whitespace changes
Inline
Side-by-side
include/ACGL/OpenGL/Controller/ShaderProgramObjectControl.hh
View file @
0469d2c4
...
...
@@ -46,7 +46,7 @@ public:
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
ShaderProgramObjectControl
(
const
Const
SharedShaderProgram
&
_shaderProgram
)
ShaderProgramObjectControl
(
const
SharedShaderProgram
&
_shaderProgram
)
:
Resource
::
BasicCreateController
<
ShaderProgramObject
>
(),
mShaderProgram
(
_shaderProgram
),
mUniformAttachmentDefines
(),
...
...
@@ -58,7 +58,7 @@ public:
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline
ShaderProgramObjectControl
&
shaderProgram
(
const
Const
SharedShaderProgram
&
_shaderProgram
)
{
mShaderProgram
=
_shaderProgram
;
return
*
this
;
}
inline
ShaderProgramObjectControl
&
shaderProgram
(
const
SharedShaderProgram
&
_shaderProgram
)
{
mShaderProgram
=
_shaderProgram
;
return
*
this
;
}
inline
ShaderProgramObjectControl
&
uniform
(
const
std
::
string
&
_name
,
const
ConstSharedUniform
&
_uniform
)
{
...
...
@@ -84,7 +84,7 @@ public:
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
Const
SharedShaderProgram
mShaderProgram
;
SharedShaderProgram
mShaderProgram
;
UniformAttachmentDefineVec
mUniformAttachmentDefines
;
UniformTextureAttachmentDefineVec
mUniformTextureAttachmentDefines
;
};
...
...
include/ACGL/OpenGL/HiLevelObjects/RenderObject.hh
View file @
0469d2c4
...
...
@@ -6,20 +6,18 @@
#ifndef ACGL_OPENGL_OBJECTS_RENDEROBJECT_HH
#define ACGL_OPENGL_OBJECTS_RENDEROBJECT_HH
/*
/*
*
* A RenderObject combines a FrameBuffer to draw to, a ShaderProgramObject
* to draw with and a VertexBufferObject to name what to draw.
*
* Instead of setting those objects individually and hoping that they match
* a RenderObject can take care of that.
*
* The FBO is optional, if none is set, rendering is performed onscreen.
* A Viewport is also optional.
*
*
* 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...
* NOTE: The RenderObject can change the Attributelocation mappings of the VAO
* as well as the frag data locations of the ShaderProgram.
*/
#include <ACGL/ACGL.hh>
...
...
@@ -43,8 +41,8 @@ class RenderObject
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
RenderObject
(
Const
SharedVertexArrayObject
_vertexArrayObject
,
Const
SharedShaderProgramObject
_shaderProgramObject
,
RenderObject
(
SharedVertexArrayObject
_vertexArrayObject
,
SharedShaderProgramObject
_shaderProgramObject
,
ConstSharedFrameBufferObject
_frameBufferObject
=
ConstSharedFrameBufferObject
(),
ConstSharedViewport
_viewport
=
ConstSharedViewport
())
:
mpVertexArrayObject
(
_vertexArrayObject
),
...
...
@@ -59,9 +57,9 @@ public:
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline
Const
SharedVertexArrayObject
getVertexArrayObject
()
const
{
return
mpVertexArrayObject
;
}
inline
SharedVertexArrayObject
getVertexArrayObject
()
const
{
return
mpVertexArrayObject
;
}
inline
ConstSharedFrameBufferObject
getFrameBufferObject
()
const
{
return
mpFrameBufferObject
;
}
inline
Const
SharedShaderProgramObject
getShaderProgramObject
()
const
{
return
mpShaderProgramObject
;
}
inline
SharedShaderProgramObject
getShaderProgramObject
()
const
{
return
mpShaderProgramObject
;
}
inline
ConstSharedViewport
getViewport
()
const
{
return
mpViewport
;
}
// ==================================================================================================== \/
...
...
@@ -71,45 +69,64 @@ public:
//! Assigns the attribute locations of the VAO to the locations of the ShaderProgram where there are matching names
void
updateMappings
();
void
bindFrameBufferObject
()
const
;
void
useShaderProgramObject
()
const
;
void
enableVertexArrayObject
()
const
;
void
disableVertexArrayObject
()
const
;
void
useViewport
()
const
;
inline
void
enable
()
const
//! setup everything for drawing and store old states
inline
void
enable
()
{
bind
FrameBufferObject
();
us
eShaderProgramObject
();
enable
FrameBufferObject
();
enabl
eShaderProgramObject
();
enableVertexArrayObject
();
us
eViewport
();
enabl
eViewport
();
}
inline
void
disable
()
const
//! restore old states
inline
void
disable
()
{
disableViewport
();
disableVertexArrayObject
();
disableShaderProgramObject
();
disableFrameBufferObject
();
}
//! draws the VAO, call enable() first!
inline
void
draw
()
const
{
mpVertexArrayObject
->
draw
();
}
inline
void
render
()
const
//! draws the VAO, everything needed for drawing is performed by this call
inline
void
render
()
{
enable
();
draw
();
disable
();
}
private:
void
enableFrameBufferObject
();
void
disableFrameBufferObject
();
void
enableShaderProgramObject
();
void
disableShaderProgramObject
();
void
enableViewport
();
void
disableViewport
();
void
enableVertexArrayObject
();
void
disableVertexArrayObject
();
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ConstSharedVertexArrayObject
mpVertexArrayObject
;
ConstSharedShaderProgramObject
mpShaderProgramObject
;
ConstSharedFrameBufferObject
mpFrameBufferObject
;
ConstSharedViewport
mpViewport
;
SharedVertexArrayObject
mpVertexArrayObject
;
// mandatory
SharedShaderProgramObject
mpShaderProgramObject
;
// mandatory
ConstSharedFrameBufferObject
mpFrameBufferObject
;
// optional
ConstSharedViewport
mpViewport
;
// optional
Viewport
mLastViewport
;
GLint
mLastShaderProgram
;
GLint
mLastFBO
;
GLint
mLastVAO
;
};
ACGL_SMARTPOINTER_TYPEDEFS
(
RenderObject
)
...
...
include/ACGL/OpenGL/HiLevelObjects/ShaderProgramObject.hh
View file @
0469d2c4
...
...
@@ -62,10 +62,8 @@ public:
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
ShaderProgramObject
(
const
ConstSharedShaderProgram
&
_shaderProgram
)
:
mpShaderProgram
(
_shaderProgram
),
mUniformAttachments
(),
mUniformTextureAttachments
()
ShaderProgramObject
(
const
SharedShaderProgram
&
_shaderProgram
)
:
mpShaderProgram
(
_shaderProgram
)
{}
virtual
~
ShaderProgramObject
(
void
)
{}
...
...
@@ -74,9 +72,9 @@ public:
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline
const
Const
SharedShaderProgram
&
getShaderProgram
(
void
)
const
{
return
mpShaderProgram
;
}
inline
const
UniformAttachmentVec
&
getUniformAttachments
(
void
)
const
{
return
mUniformAttachments
;
}
inline
const
UniformTextureAttachmentVec
&
getUniformTextureAttachments
(
void
)
const
{
return
mUniformTextureAttachments
;
}
inline
SharedShaderProgram
getShaderProgram
(
void
)
const
{
return
mpShaderProgram
;
}
inline
UniformAttachmentVec
getUniformAttachments
(
void
)
const
{
return
mUniformAttachments
;
}
inline
UniformTextureAttachmentVec
getUniformTextureAttachments
(
void
)
const
{
return
mUniformTextureAttachments
;
}
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
...
...
@@ -89,9 +87,7 @@ public:
const
std
::
string
&
_name
,
const
ConstSharedUniform
&
_uniform
)
{
UniformAttachment
uniformAttachment
=
{
mpShaderProgram
->
getUniformLocation
(
_name
),
_uniform
};
UniformAttachment
uniformAttachment
=
{
mpShaderProgram
->
getUniformLocation
(
_name
),
_uniform
};
mUniformAttachments
.
push_back
(
uniformAttachment
);
}
...
...
@@ -99,9 +95,7 @@ public:
const
std
::
string
&
_name
,
const
ConstSharedUniformTexture
&
_uniformTexture
)
{
UniformTextureAttachment
uniformTextureAttachment
=
{
mpShaderProgram
->
getUniformLocation
(
_name
),
_uniformTexture
};
UniformTextureAttachment
uniformTextureAttachment
=
{
mpShaderProgram
->
getUniformLocation
(
_name
),
_uniformTexture
};
mUniformTextureAttachments
.
push_back
(
uniformTextureAttachment
);
}
...
...
@@ -109,7 +103,7 @@ public:
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
Const
SharedShaderProgram
mpShaderProgram
;
SharedShaderProgram
mpShaderProgram
;
UniformAttachmentVec
mUniformAttachments
;
UniformTextureAttachmentVec
mUniformTextureAttachments
;
};
...
...
include/ACGL/OpenGL/HiLevelObjects/VertexBufferObject.hh
View file @
0469d2c4
...
...
@@ -6,6 +6,11 @@
#ifndef ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH
#define ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH
////////////////////////////////////////////////////////////////////////////////
// WARNING: broken due to refactoring of low-level objects, might get removed //
// alternative: maybe VertexBufferObjects //
////////////////////////////////////////////////////////////////////////////////
/*
* A VertexBufferObject combines the two tightly related buffers from the
* ARB_vertex_buffer_object extension.
...
...
include/ACGL/OpenGL/HiLevelObjects/Viewport.hh
View file @
0469d2c4
...
...
@@ -53,7 +53,7 @@ public:
public:
inline
void
use
(
void
)
const
{
glViewport
(
mOffsetX
,
mOffsetY
,
mWidth
,
mHeight
);
glViewport
(
mOffsetX
,
mOffsetY
,
mWidth
,
mHeight
);
openGLRareError
();
}
inline
void
setOffset
(
GLint
_offsetX
,
GLint
_offsetY
)
...
...
@@ -68,6 +68,15 @@ public:
mHeight
=
_height
;
}
//! gets the current viewport form OpenGL
void
setFromGLContext
()
{
GLint
viewport
[
4
];
glGetIntegerv
(
GL_VIEWPORT
,
&
(
viewport
[
0
])
);
setOffset
(
viewport
[
0
],
viewport
[
1
]);
setSize
(
viewport
[
1
],
viewport
[
2
]);
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
...
...
include/ACGL/OpenGL/Objects/FrameBufferObject.hh
View file @
0469d2c4
...
...
@@ -180,6 +180,33 @@ public:
return
true
;
}
//! x,y coordinate is the FBO size in pixels, z coordinate the number of color attachments. x,y are both 0 if the FBO has no useful size
glm
::
uvec3
getSize
()
const
{
glm
::
uvec3
size
;
if
(
mDepthAttachment
.
texture
)
{
// use the size of the depth texture
size
=
mDepthAttachment
.
texture
->
getSize
();
}
else
if
(
mDepthAttachment
.
renderBuffer
)
{
// use the size of the depth render buffer
size
=
glm
::
uvec3
(
mDepthAttachment
.
renderBuffer
->
getSize
(),
0
);
}
else
if
(
mColorAttachments
.
size
()
>
0
)
{
if
(
mColorAttachments
[
0
].
texture
)
{
// use the size of the first texture:
size
=
mColorAttachments
[
0
].
texture
->
getSize
();
}
else
if
(
mColorAttachments
[
0
].
renderBuffer
)
{
// use the size of the first renderBuffer:
size
=
glm
::
uvec3
(
mColorAttachments
[
0
].
renderBuffer
->
getSize
(),
0
);
}
}
else
{
size
=
glm
::
uvec3
(
0
);
}
size
.
z
=
mColorAttachments
.
size
();
return
size
;
}
// =================================================================================================== \/
// =========================================================================================== METHODS \/
// =================================================================================================== \/
...
...
@@ -188,7 +215,7 @@ public:
void
setAttachmentLocations
(
ConstSharedLocationMappings
_locationMappings
);
//! get a list of attachment locations and names that can be used to set up a ShaderProgram
SharedLocationMappings
getAttachmentLocations
();
SharedLocationMappings
getAttachmentLocations
()
const
;
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
...
...
include/ACGL/OpenGL/Objects/RenderBuffer.hh
View file @
0469d2c4
...
...
@@ -19,7 +19,7 @@
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/Math/Math.hh>
namespace
ACGL
{
namespace
OpenGL
{
...
...
@@ -60,6 +60,7 @@ public:
inline
GLenum
getInternalFormat
(
void
)
const
{
return
mInternalFormat
;
}
inline
GLsizei
getWidth
(
void
)
const
{
return
mWidth
;
}
inline
GLsizei
getHeight
(
void
)
const
{
return
mHeight
;
}
inline
glm
::
uvec2
getSize
(
void
)
const
{
return
glm
::
uvec2
(
mWidth
,
mHeight
);
}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
...
...
include/ACGL/OpenGL/Objects/Texture.hh
View file @
0469d2c4
...
...
@@ -80,6 +80,8 @@ public:
inline
GLenum
getWrapT
(
void
)
const
{
return
mWrapT
;
}
inline
GLenum
getWrapR
(
void
)
const
{
return
mWrapR
;
}
inline
glm
::
uvec3
getSize
(
void
)
const
{
return
glm
::
uvec3
(
mWidth
,
mHeight
,
mDepth
);
}
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
...
...
src/ACGL/OpenGL/Controller/ShaderProgramObjectControl.cc
View file @
0469d2c4
...
...
@@ -9,7 +9,7 @@ using namespace ACGL::OpenGL;
SharedShaderProgramObject
ShaderProgramObjectControl
::
create
(
void
)
{
SharedShaderProgramObject
shaderProgramObject
(
new
ShaderProgramObject
(
mShaderProgram
));
SharedShaderProgramObject
shaderProgramObject
=
SharedShaderProgramObject
(
new
ShaderProgramObject
(
mShaderProgram
));
for
(
UniformAttachmentDefineVec
::
size_type
i
=
0
;
i
<
mUniformAttachmentDefines
.
size
();
i
++
)
shaderProgramObject
->
attachUniform
(
mUniformAttachmentDefines
[
i
].
name
,
mUniformAttachmentDefines
[
i
].
uniform
);
...
...
src/ACGL/OpenGL/HiLevelObjects/RenderObject.cc
View file @
0469d2c4
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University
//
// Copyright (c) 2011,
2012
Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
...
...
@@ -8,6 +8,7 @@
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/Base/StringOperations.hh>
#include <ACGL/OpenGL/Data/LocationMappings.hh>
#include <iostream>
#include <fstream>
...
...
@@ -18,89 +19,82 @@ using namespace ACGL::OpenGL;
void
RenderObject
::
updateMappings
()
{
// TODO: reimplement
/*
for(VertexBufferObject::AttributeVec::size_type i = 0; i < mpVertexBufferObject->getAttributes().size(); ++i)
{
AttributeMapping mapping = {(int_t)i, (int_t)mpShaderProgramObject->getShaderProgram()->getAttributeLocation(mpVertexBufferObject->getAttributes()[i].name)};
bool inserted = false;
for (AttributeMappingVec::iterator it = mAttributeMappings.begin(); it < mAttributeMappings.end() && !inserted; it++)
{
if(mpVertexBufferObject->getAttributes()[(*it).attributeID].bufferID > mpVertexBufferObject->getAttributes()[mapping.attributeID].bufferID)
{
mAttributeMappings.insert(it, mapping);
inserted = true;
}
}
if(!inserted)
mAttributeMappings.push_back(mapping);
if
(
mpFrameBufferObject
)
{
// set ShaderProgram out-mappings by the definition of the FBO
mpShaderProgramObject
->
getShaderProgram
()
->
setFragmentDataLocations
(
mpFrameBufferObject
->
getAttachmentLocations
()
);
}
if(mpFrameBufferObject)
{
mpDrawBuffers = new GLuint[mpFrameBufferObject->getColorAttachments().size()];
for(FrameBufferObject::AttachmentVec::size_type i = 0; i < mpFrameBufferObject->getColorAttachments().size(); ++i)
mpDrawBuffers[i] = GL_COLOR_ATTACHMENT0 + mpShaderProgramObject->getShaderProgram()->getFragmentDataLocation(mpFrameBufferObject->getColorAttachments()[i].name);
}
*/
// update the attribute locations of the VAO
// TODO: better move this to the controller
//mpVertexArrayObject->setAttributeLocationsByShaderProgram(mpShaderProgramObject->getShaderProgram());
// update the fragment data locations of the FBO
//mpFrameBufferObject->setAttachmentsByShaderProgram(mpShaderProgramObject->getShaderProgram());
mpVertexArrayObject
->
setAttributeLocations
(
mpShaderProgramObject
->
getShaderProgram
()
->
getAttributeLocations
()
);
openGLRareError
();
}
void
RenderObject
::
bind
FrameBufferObject
()
const
void
RenderObject
::
enable
FrameBufferObject
()
{
glGetIntegerv
(
GL_FRAMEBUFFER_BINDING
,
&
mLastFBO
);
if
(
mpFrameBufferObject
)
{
mpFrameBufferObject
->
bind
();
//glDrawBuffers(mpFrameBufferObject->getColorAttachments().size(), mpDrawBuffers);
}
else
{
glBindFramebuffer
(
GL_FRAMEBUFFER
,
0
);
glBindFramebuffer
(
GL_FRAMEBUFFER
,
0
);
}
openGLRareError
();
}
void
RenderObject
::
useShaderProgram
Object
()
const
void
RenderObject
::
disableFrameBuffer
Object
()
{
glBindFramebuffer
(
GL_FRAMEBUFFER
,
mLastFBO
);
openGLRareError
();
}
void
RenderObject
::
enableShaderProgramObject
()
{
glGetIntegerv
(
GL_CURRENT_PROGRAM
,
&
mLastShaderProgram
);
mpShaderProgramObject
->
use
();
openGLRareError
();
}
void
RenderObject
::
en
able
VertexAr
ra
y
Object
()
const
void
RenderObject
::
dis
able
ShaderProg
ra
m
Object
()
{
if
(
mpVertexArrayObject
)
{
mpVertexArrayObject
->
bind
();
}
else
{
glBindVertexArray
(
0
);
}
glUseProgram
(
mLastShaderProgram
);
openGLRareError
();
}
void
RenderObject
::
enableVertexArrayObject
()
{
// remember old VAO
glGetIntegerv
(
GL_VERTEX_ARRAY_BINDING
,
&
mLastVAO
);
mpVertexArrayObject
->
bind
();
openGLRareError
();
}
void
RenderObject
::
disableVertexArrayObject
()
const
void
RenderObject
::
disableVertexArrayObject
()
{
glBindVertexArray
(
0
);
glBindVertexArray
(
mLastVAO
);
openGLRareError
();
}
void
RenderObject
::
us
eViewport
()
const
void
RenderObject
::
enabl
eViewport
()
{
mLastViewport
.
setFromGLContext
();
if
(
mpViewport
)
{
mpViewport
->
use
();
}
else
if
(
mpFrameBufferObject
)
{
glm
::
uvec3
size
=
mpFrameBufferObject
->
getSize
();
glViewport
(
0
,
0
,
size
.
x
,
size
.
y
);
openGLRareError
();
}
openGLRareError
();
}
void
RenderObject
::
disableViewport
()
{
mLastViewport
.
use
();
}
#endif
src/ACGL/OpenGL/Objects/FrameBufferObject.cc
View file @
0469d2c4
...
...
@@ -179,7 +179,7 @@ void FrameBufferObject::setAttachmentLocations(ConstSharedLocationMappings _loca
}
SharedLocationMappings
FrameBufferObject
::
getAttachmentLocations
()
SharedLocationMappings
FrameBufferObject
::
getAttachmentLocations
()
const
{
SharedLocationMappings
locationMap
=
SharedLocationMappings
(
new
LocationMappings
()
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment