Skip to content
GitLab
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
0545b116
Commit
0545b116
authored
Aug 19, 2011
by
Lars Krecklau
Browse files
-Added controller for the uniforms
-Added SPOs to the state object
parent
0a3c77c3
Changes
9
Hide whitespace changes
Inline
Side-by-side
include/ACGL/OpenGL/Controller.hh
View file @
0545b116
...
...
@@ -28,6 +28,7 @@
#include
<ACGL/OpenGL/Controller/StateControl.hh>
#include
<ACGL/OpenGL/Controller/TextureControl.hh>
#include
<ACGL/OpenGL/Controller/TextureControlFileJPG.hh>
#include
<ACGL/OpenGL/Controller/UniformControl.hh>
#include
<ACGL/OpenGL/Controller/VertexBufferObjectControl.hh>
#include
<ACGL/OpenGL/Controller/VertexBufferObjectControlFileOBJ.hh>
...
...
include/ACGL/OpenGL/Controller/StateControl.hh
View file @
0545b116
...
...
@@ -24,11 +24,11 @@ public:
StateControl
(
const
ConstSharedVertexBufferObject
&
_vertexBufferObject
,
const
ConstSharedFrameBufferObject
&
_frameBufferObject
,
const
ConstSharedShaderProgram
&
_shaderProgram
,
const
ConstSharedShaderProgram
Object
&
_shaderProgram
Object
,
const
ConstSharedViewport
&
_viewport
)
:
mpVertexBufferObject
(
_vertexBufferObject
),
mpFrameBufferObject
(
_frameBufferObject
),
mpShaderProgram
(
_shaderProgram
),
mpShaderProgram
Object
(
_shaderProgram
Object
),
mpViewport
(
_viewport
)
{}
virtual
~
StateControl
(
void
)
{}
...
...
@@ -37,10 +37,10 @@ public:
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline
StateControl
&
vertexBuffer
(
const
ConstSharedVertexBufferObject
&
_vertexBufferObject
)
{
mpVertexBufferObject
=
_vertexBufferObject
;
return
*
this
;
}
inline
StateControl
&
frameBuffer
(
const
ConstSharedFrameBufferObject
&
_frameBufferObject
)
{
mpFrameBufferObject
=
_frameBufferObject
;
return
*
this
;
}
inline
StateControl
&
shaderProgram
(
const
ConstSharedShaderProgram
&
_shaderProgram
)
{
mpShaderProgram
=
_shaderProgram
;
return
*
this
;
}
inline
StateControl
&
viewport
(
const
ConstSharedViewport
&
_viewport
)
{
mpViewport
=
_viewport
;
return
*
this
;
}
inline
StateControl
&
vertexBuffer
Object
(
const
ConstSharedVertexBufferObject
&
_vertexBufferObject
)
{
mpVertexBufferObject
=
_vertexBufferObject
;
return
*
this
;
}
inline
StateControl
&
frameBuffer
Object
(
const
ConstSharedFrameBufferObject
&
_frameBufferObject
)
{
mpFrameBufferObject
=
_frameBufferObject
;
return
*
this
;
}
inline
StateControl
&
shaderProgram
Object
(
const
ConstSharedShaderProgram
Object
&
_shaderProgram
Object
)
{
mpShaderProgram
Object
=
_shaderProgram
Object
;
return
*
this
;
}
inline
StateControl
&
viewport
(
const
ConstSharedViewport
&
_viewport
)
{
mpViewport
=
_viewport
;
return
*
this
;
}
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
...
...
@@ -48,7 +48,7 @@ public:
public:
virtual
SharedState
create
(
void
)
{
SharedState
state
(
new
State
(
mpVertexBufferObject
,
mpFrameBufferObject
,
mpShaderProgram
,
mpViewport
));
SharedState
state
(
new
State
(
mpVertexBufferObject
,
mpFrameBufferObject
,
mpShaderProgram
Object
,
mpViewport
));
return
state
;
}
...
...
@@ -57,10 +57,10 @@ public:
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ConstSharedVertexBufferObject
mpVertexBufferObject
;
ConstSharedFrameBufferObject
mpFrameBufferObject
;
ConstSharedShaderProgram
mpShaderProgram
;
ConstSharedViewport
mpViewport
;
ConstSharedVertexBufferObject
mpVertexBufferObject
;
ConstSharedFrameBufferObject
mpFrameBufferObject
;
ConstSharedShaderProgram
Object
mpShaderProgram
Object
;
ConstSharedViewport
mpViewport
;
};
}
// OpenGL
...
...
include/ACGL/OpenGL/Controller/UniformControl.hh
0 → 100644
View file @
0545b116
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_UNIFORMCONTROL_HH
#define ACGL_OPENGL_CONTROLLER_UNIFORMCONTROL_HH
#include
<ACGL/ACGL.hh>
#include
<ACGL/Resource/BasicCreateController.hh>
#include
<ACGL/OpenGL/Objects/Uniform.hh>
#include
<ACGL/OpenGL/GL.hh>
namespace
ACGL
{
namespace
OpenGL
{
template
<
class
UNIFORM
>
class
UniformControl
:
public
Resource
::
BasicCreateController
<
UNIFORM
>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
UniformControl
(
const
typename
UNIFORM
::
DATA_TYPE
&
_value
)
:
mValue
(
_value
)
{}
virtual
~
UniformControl
()
{}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline
UniformControl
&
value
(
const
typename
UNIFORM
::
DATA_TYPE
&
_value
)
{
mValue
=
_value
;
return
*
this
;
}
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual
std
::
tr1
::
shared_ptr
<
UNIFORM
>
create
(
void
)
{
std
::
tr1
::
shared_ptr
<
UNIFORM
>
uniform
(
new
UNIFORM
());
uniform
->
setValue
(
mValue
);
return
uniform
;
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
typename
UNIFORM
::
DATA_TYPE
mValue
;
};
typedef
UniformControl
<
Uniform1i
>
Uniform1iControl
;
typedef
UniformControl
<
Uniform1f
>
Uniform1fControl
;
typedef
UniformControl
<
Uniform2f
>
Uniform2fControl
;
typedef
UniformControl
<
Uniform3f
>
Uniform3fControl
;
typedef
UniformControl
<
Uniform4f
>
Uniform4fControl
;
typedef
UniformControl
<
UniformMatrix2f
>
UniformMatrix2fControl
;
typedef
UniformControl
<
UniformMatrix3f
>
UniformMatrix3fControl
;
typedef
UniformControl
<
UniformMatrix4f
>
UniformMatrix4fControl
;
typedef
UniformControl
<
UniformTexture
>
UniformTextureControl
;
}
// OpenGL
}
// ACGL
#endif // ACGL_OPENGL_CONTROLLER_ARRAYBUFFERCONTROL_HH
include/ACGL/OpenGL/Objects/Shader.hh
View file @
0545b116
...
...
@@ -26,8 +26,8 @@ class Shader
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef
std
::
vector
<
std
::
string
>
AttributeVec
;
typedef
std
::
vector
<
std
::
string
>
FragmentDataVec
;
typedef
std
::
vector
<
std
::
string
>
Attribute
Name
Vec
;
typedef
std
::
vector
<
std
::
string
>
FragmentData
Name
Vec
;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
...
...
@@ -53,8 +53,9 @@ public:
inline
GLuint
getContext
(
void
)
const
{
return
mContext
;
}
inline
GLenum
getType
(
void
)
const
{
return
mType
;
}
inline
const
std
::
vector
<
std
::
string
>&
getAttributes
()
const
{
return
mAttributes
;
}
inline
const
std
::
vector
<
std
::
string
>&
getFragmentData
()
const
{
return
mFragmentData
;
}
inline
const
std
::
vector
<
std
::
string
>&
getAttributeNames
(
void
)
const
{
return
mAttributeNames
;
}
inline
const
std
::
vector
<
std
::
string
>&
getFragmentDataNames
(
void
)
const
{
return
mFragmentDataNames
;
}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
...
...
@@ -69,10 +70,10 @@ protected:
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
GLuint
mContext
;
GLenum
mType
;
AttributeVec
mAttributes
;
FragmentDataVec
mFragmentData
;
GLuint
mContext
;
GLenum
mType
;
Attribute
Name
Vec
mAttribute
Name
s
;
FragmentData
Name
Vec
mFragmentData
Names
;
};
ACGL_SHARED_TYPEDEF
(
Shader
)
...
...
include/ACGL/OpenGL/Objects/State.hh
View file @
0545b116
...
...
@@ -18,7 +18,7 @@
#include
<ACGL/OpenGL/Objects/VertexBufferObject.hh>
#include
<ACGL/OpenGL/Objects/FrameBufferObject.hh>
#include
<ACGL/OpenGL/Objects/ShaderProgram.hh>
#include
<ACGL/OpenGL/Objects/ShaderProgram
Object
.hh>
#include
<ACGL/OpenGL/Objects/Viewport.hh>
namespace
ACGL
{
...
...
@@ -54,13 +54,13 @@ private:
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
State
(
ConstSharedVertexBufferObject
_
V
ertexBufferObject
,
ConstSharedFrameBufferObject
_
F
rameBufferObject
,
ConstSharedShaderProgram
_shaderProgram
,
State
(
ConstSharedVertexBufferObject
_
v
ertexBufferObject
,
ConstSharedFrameBufferObject
_
f
rameBufferObject
,
ConstSharedShaderProgram
Object
_shaderProgram
,
ConstSharedViewport
_viewport
)
:
mpVertexBufferObject
(
_
V
ertexBufferObject
),
mpFrameBufferObject
(
_
F
rameBufferObject
),
mpShaderProgram
(
_shaderProgram
),
:
mpVertexBufferObject
(
_
v
ertexBufferObject
),
mpFrameBufferObject
(
_
f
rameBufferObject
),
mpShaderProgram
Object
(
_shaderProgram
),
mpViewport
(
_viewport
),
mAttributeMappings
(),
mFragmentDataMappings
(),
...
...
@@ -81,18 +81,20 @@ public:
public:
inline
ConstSharedVertexBufferObject
getVertexBufferObject
(
void
)
const
{
return
mpVertexBufferObject
;
}
inline
ConstSharedFrameBufferObject
getFrameBufferObject
(
void
)
const
{
return
mpFrameBufferObject
;
}
inline
ConstSharedShaderProgram
getShaderProgram
(
void
)
const
{
return
mpShaderProgram
;
}
inline
ConstSharedShaderProgram
Object
getShaderProgram
Object
(
void
)
const
{
return
mpShaderProgram
Object
;
}
inline
ConstSharedViewport
getViewport
(
void
)
const
{
return
mpViewport
;
}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
void
useViewport
(
void
);
void
enableVertexBufferObject
(
void
);
void
bindFrameBufferObject
(
void
);
void
disableVertexBufferObject
(
void
);
void
updateMappings
(
void
);
void
updateMappings
(
void
);
void
useViewport
(
void
)
const
;
void
useShaderProgramObject
(
void
)
const
;
void
bindFrameBufferObject
(
void
)
const
;
void
enableVertexBufferObject
(
void
)
const
;
void
disableVertexBufferObject
(
void
)
const
;
inline
void
validate
(
void
)
const
{
...
...
@@ -100,14 +102,15 @@ public:
mpVertexBufferObject
->
validate
();
}
inline
void
draw
(
void
)
inline
void
draw
(
void
)
const
{
mpVertexBufferObject
->
draw
();
}
inline
void
render
(
void
)
inline
void
render
(
void
)
const
{
useViewport
();
useShaderProgramObject
();
bindFrameBufferObject
();
enableVertexBufferObject
();
draw
();
...
...
@@ -120,8 +123,8 @@ public:
protected:
ConstSharedVertexBufferObject
mpVertexBufferObject
;
ConstSharedFrameBufferObject
mpFrameBufferObject
;
ConstSharedShaderProgram
mpShaderProgram
;
ConstSharedViewport
mpViewport
;
ConstSharedShaderProgram
Object
mpShaderProgram
Object
;
ConstSharedViewport
mpViewport
;
AttributeMappingVec
mAttributeMappings
;
FragmentDataMappingVec
mFragmentDataMappings
;
...
...
include/ACGL/OpenGL/Objects/Uniform.hh
View file @
0545b116
...
...
@@ -36,6 +36,12 @@ ACGL_SHARED_TYPEDEF(Uniform)
template
<
typename
T
>
class
UniformData
{
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef
T
DATA_TYPE
;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
...
...
src/ACGL/OpenGL/Objects/Shader.cc
View file @
0545b116
...
...
@@ -46,7 +46,8 @@ bool Shader::setSource(const std::string& _source)
std
::
istringstream
stream
(
_source
);
std
::
string
line
=
""
;
mAttributes
.
clear
();
mAttributeNames
.
clear
();
mFragmentDataNames
.
clear
();
while
(
stream
.
good
())
{
...
...
@@ -62,7 +63,7 @@ bool Shader::setSource(const std::string& _source)
std
::
vector
<
std
::
string
>
tokensOfToken
=
StringOperations
::
split
(
tokens
[
2
],
';'
);
if
(
tokensOfToken
.
size
()
>
0
)
{
mAttributes
.
push_back
(
tokensOfToken
[
0
]);
mAttribute
Name
s
.
push_back
(
tokensOfToken
[
0
]);
}
}
}
...
...
@@ -77,7 +78,7 @@ bool Shader::setSource(const std::string& _source)
std
::
vector
<
std
::
string
>
tokensOfToken
=
StringOperations
::
split
(
tokens
[
2
],
';'
);
if
(
tokensOfToken
.
size
()
>
0
)
{
mFragmentData
.
push_back
(
tokensOfToken
[
0
]);
mFragmentData
Names
.
push_back
(
tokensOfToken
[
0
]);
}
}
}
...
...
src/ACGL/OpenGL/Objects/ShaderProgram.cc
View file @
0545b116
...
...
@@ -14,10 +14,9 @@ void ShaderProgram::bindAttributeLocations() const
{
for
(
ConstSharedShaderVec
::
size_type
i
=
0
;
i
<
mShaders
.
size
();
++
i
)
{
const
Shader
::
AttributeVec
&
attribs
=
mShaders
[
i
]
->
getAttributes
();
for
(
Shader
::
AttributeVec
::
size_type
k
=
0
;
k
<
attribs
.
size
();
++
k
)
for
(
Shader
::
AttributeNameVec
::
size_type
k
=
0
;
k
<
mShaders
[
i
]
->
getAttributeNames
().
size
();
++
k
)
{
glBindAttribLocation
(
mContext
,
k
,
attribs
[
k
].
c_str
());
glBindAttribLocation
(
mContext
,
k
,
mShaders
[
i
]
->
getAttributeNames
()
[
k
].
c_str
());
}
}
}
...
...
@@ -26,10 +25,9 @@ void ShaderProgram::bindFragmentDataLocations() const
{
for
(
ConstSharedShaderVec
::
size_type
i
=
0
;
i
<
mShaders
.
size
();
++
i
)
{
const
Shader
::
FragmentDataVec
&
fragData
=
mShaders
[
i
]
->
getFragmentData
();
for
(
Shader
::
FragmentDataVec
::
size_type
k
=
0
;
k
<
fragData
.
size
();
++
k
)
for
(
Shader
::
FragmentDataNameVec
::
size_type
k
=
0
;
k
<
mShaders
[
i
]
->
getFragmentDataNames
().
size
();
++
k
)
{
glBindFragDataLocation
(
mContext
,
k
,
fragData
[
k
].
c_str
());
glBindFragDataLocation
(
mContext
,
k
,
mShaders
[
i
]
->
getFragmentDataNames
()
[
k
].
c_str
());
}
}
}
...
...
src/ACGL/OpenGL/Objects/State.cc
View file @
0545b116
...
...
@@ -14,18 +14,65 @@ using namespace ACGL::Base;
using
namespace
ACGL
::
Utils
;
using
namespace
ACGL
::
OpenGL
;
void
State
::
useViewport
()
void
State
::
updateMappings
(
void
)
{
ShaderProgram
::
ConstSharedShaderVec
shaders
=
mpShaderProgramObject
->
getShaderProgram
()
->
getShaders
();
for
(
ShaderProgram
::
ConstSharedShaderVec
::
size_type
shader
=
0
;
shader
<
shaders
.
size
();
shader
++
)
{
for
(
Shader
::
AttributeNameVec
::
size_type
k
=
0
;
k
<
shaders
[
shader
]
->
getAttributeNames
().
size
();
k
++
)
{
AttributeMapping
mapping
;
mapping
.
shaderProgramAttributeLocation
=
mpShaderProgramObject
->
getShaderProgram
()
->
getAttributeLocation
(
shaders
[
shader
]
->
getAttributeNames
()[
k
]);
mapping
.
vertexBufferObjectAttribute
=
mpVertexBufferObject
->
getAttributeIndexByName
(
shaders
[
shader
]
->
getAttributeNames
()[
k
]);
mapping
.
arrayBufferID
=
mpVertexBufferObject
->
getArrayBufferIDByAttributeIndex
(
mapping
.
vertexBufferObjectAttribute
);
bool
inserted
=
false
;
for
(
AttributeMappingVec
::
iterator
it
=
mAttributeMappings
.
begin
();
it
<
mAttributeMappings
.
end
()
&&
!
inserted
;
it
++
)
{
if
((
*
it
).
arrayBufferID
>
mapping
.
arrayBufferID
)
{
mAttributeMappings
.
insert
(
it
,
mapping
);
inserted
=
true
;
}
}
if
(
!
inserted
)
mAttributeMappings
.
push_back
(
mapping
);
}
for
(
Shader
::
FragmentDataNameVec
::
size_type
k
=
0
;
k
<
shaders
[
shader
]
->
getFragmentDataNames
().
size
();
k
++
)
{
FragmentDataMapping
mapping
;
mapping
.
shaderProgramFragmentDataLocation
=
mpShaderProgramObject
->
getShaderProgram
()
->
getFragmentDataLocation
(
shaders
[
shader
]
->
getFragmentDataNames
()[
k
]);
mapping
.
frameBufferObjectColorAttachment
=
mpFrameBufferObject
->
getColorAttachmentIndexByName
(
shaders
[
shader
]
->
getFragmentDataNames
()[
k
]);
mFragmentDataMappings
.
push_back
(
mapping
);
}
}
mpBuffers
=
new
GLuint
[
mFragmentDataMappings
.
size
()];
for
(
FragmentDataMappingVec
::
size_type
k
=
0
;
k
<
mFragmentDataMappings
.
size
();
k
++
)
mpBuffers
[
k
]
=
GL_COLOR_ATTACHMENT0
+
mFragmentDataMappings
[
k
].
frameBufferObjectColorAttachment
;
}
void
State
::
useViewport
(
void
)
const
{
mpViewport
->
use
();
}
void
State
::
bindFrameBufferObject
()
void
State
::
useShaderProgramObject
(
void
)
const
{
mpShaderProgramObject
->
use
();
}
void
State
::
bindFrameBufferObject
(
void
)
const
{
mpFrameBufferObject
->
bind
();
glDrawBuffers
(
mFragmentDataMappings
.
size
(),
mpBuffers
);
}
void
State
::
enableVertexBufferObject
()
void
State
::
enableVertexBufferObject
(
void
)
const
{
if
(
mpVertexBufferObject
->
getElementArrayBuffer
())
mpVertexBufferObject
->
getElementArrayBuffer
()
->
bind
();
...
...
@@ -45,7 +92,7 @@ void State::enableVertexBufferObject()
}
}
void
State
::
disableVertexBufferObject
()
void
State
::
disableVertexBufferObject
(
void
)
const
{
int
currentArrayBufferID
=
-
1
;
for
(
AttributeMappingVec
::
size_type
k
=
0
;
k
<
mAttributeMappings
.
size
();
k
++
)
...
...
@@ -59,49 +106,3 @@ void State::disableVertexBufferObject()
openGLRareError
();
}
}
void
State
::
updateMappings
(
void
)
{
ShaderProgram
::
ConstSharedShaderVec
shaders
=
mpShaderProgram
->
getShaders
();
for
(
ShaderProgram
::
ConstSharedShaderVec
::
size_type
shader
=
0
;
shader
<
shaders
.
size
();
shader
++
)
{
const
Shader
::
AttributeVec
&
attributeVec
=
shaders
[
shader
]
->
getAttributes
();
for
(
Shader
::
AttributeVec
::
size_type
k
=
0
;
k
<
attributeVec
.
size
();
k
++
)
{
AttributeMapping
mapping
;
mapping
.
shaderProgramAttributeLocation
=
mpShaderProgram
->
getAttributeLocation
(
attributeVec
[
k
]);
mapping
.
vertexBufferObjectAttribute
=
mpVertexBufferObject
->
getAttributeIndexByName
(
attributeVec
[
k
]);
mapping
.
arrayBufferID
=
mpVertexBufferObject
->
getArrayBufferIDByAttributeIndex
(
mapping
.
vertexBufferObjectAttribute
);
bool
inserted
=
false
;
for
(
AttributeMappingVec
::
iterator
it
=
mAttributeMappings
.
begin
();
it
<
mAttributeMappings
.
end
()
&&
!
inserted
;
it
++
)
{
if
((
*
it
).
arrayBufferID
>
mapping
.
arrayBufferID
)
{
mAttributeMappings
.
insert
(
it
,
mapping
);
inserted
=
true
;
}
}
if
(
!
inserted
)
mAttributeMappings
.
push_back
(
mapping
);
}
const
Shader
::
FragmentDataVec
&
fragmentDataVec
=
shaders
[
shader
]
->
getFragmentData
();
for
(
Shader
::
FragmentDataVec
::
size_type
k
=
0
;
k
<
fragmentDataVec
.
size
();
k
++
)
{
FragmentDataMapping
mapping
;
mapping
.
shaderProgramFragmentDataLocation
=
mpShaderProgram
->
getFragmentDataLocation
(
fragmentDataVec
[
k
]);
mapping
.
frameBufferObjectColorAttachment
=
mpFrameBufferObject
->
getColorAttachmentIndexByName
(
fragmentDataVec
[
k
]);
mFragmentDataMappings
.
push_back
(
mapping
);
}
}
mpBuffers
=
new
GLuint
[
mFragmentDataMappings
.
size
()];
for
(
FragmentDataMappingVec
::
size_type
k
=
0
;
k
<
mFragmentDataMappings
.
size
();
k
++
)
mpBuffers
[
k
]
=
GL_COLOR_ATTACHMENT0
+
mFragmentDataMappings
[
k
].
frameBufferObjectColorAttachment
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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