Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ACGL
acgl
Commits
ff41ea3a
Commit
ff41ea3a
authored
Jan 18, 2012
by
Janis Born
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement ShaderProgram::setAttributeLocationsByVAO
parent
a9cebf32
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
15 deletions
+54
-15
include/ACGL/OpenGL/Objects/ShaderProgram.hh
include/ACGL/OpenGL/Objects/ShaderProgram.hh
+11
-4
include/ACGL/OpenGL/Objects/VertexArrayObject.hh
include/ACGL/OpenGL/Objects/VertexArrayObject.hh
+12
-11
src/ACGL/OpenGL/Objects/ShaderProgram.cc
src/ACGL/OpenGL/Objects/ShaderProgram.cc
+31
-0
No files found.
include/ACGL/OpenGL/Objects/ShaderProgram.hh
View file @
ff41ea3a
...
@@ -54,6 +54,9 @@
...
@@ -54,6 +54,9 @@
namespace
ACGL
{
namespace
ACGL
{
namespace
OpenGL
{
namespace
OpenGL
{
class
VertexArrayObject
;
ACGL_SHARED_TYPEDEF
(
VertexArrayObject
)
class
ShaderProgram
class
ShaderProgram
{
{
ACGL_NOT_COPYABLE
(
ShaderProgram
)
ACGL_NOT_COPYABLE
(
ShaderProgram
)
...
@@ -112,12 +115,17 @@ public:
...
@@ -112,12 +115,17 @@ public:
bool
link
(
void
)
const
;
bool
link
(
void
)
const
;
// ===================================================================================================== \/
// ============================================================================================= METHODS \/
// ===================================================================================================== \/
public:
//! Matches the attribute locations of this ShaderProgram to the names of the ArrayBuffer attributes currently attached to _vao
void
setAttributeLocationsByVAO
(
const
SharedVertexArrayObject
&
_vao
);
// ===================================================================================================== \/
// ===================================================================================================== \/
// ============================================================================================ UNIFORMS \/
// ============================================================================================ UNIFORMS \/
// ===================================================================================================== \/
// ===================================================================================================== \/
public:
// int by location
// int by location
inline
void
setUniform
(
GLint
_location
,
GLint
_v
)
const
{
glUniform1i
(
_location
,
_v
);
}
inline
void
setUniform
(
GLint
_location
,
GLint
_v
)
const
{
glUniform1i
(
_location
,
_v
);
}
inline
void
setUniform
(
GLint
_location
,
GLsizei
_n
,
GLint
*
_v
)
const
{
glUniform1iv
(
_location
,
_n
,
_v
);
}
inline
void
setUniform
(
GLint
_location
,
GLsizei
_n
,
GLint
*
_v
)
const
{
glUniform1iv
(
_location
,
_n
,
_v
);
}
...
@@ -231,7 +239,7 @@ public:
...
@@ -231,7 +239,7 @@ public:
// ======================================================================================================= \/
// ======================================================================================================= \/
// ============================================================================================ HIGH LEVEL \/
// ============================================================================================ HIGH LEVEL \/
// ======================================================================================================= \/
// ======================================================================================================= \/
public:
// normal:
// normal:
template
<
typename
T
>
template
<
typename
T
>
inline
void
setUniform
(
const
std
::
string
&
_nameInShader
,
T
_v
)
const
inline
void
setUniform
(
const
std
::
string
&
_nameInShader
,
T
_v
)
const
...
@@ -277,7 +285,6 @@ public:
...
@@ -277,7 +285,6 @@ public:
inline
void
setTexture
(
const
std
::
string
&
_nameInShader
,
const
ConstSharedTexture
&
_texture
,
GLenum
_unit
=
0
)
const
{
setUniform
(
getUniformLocation
(
_nameInShader
),
(
GLint
)
_unit
);
_texture
->
bind
(
_unit
);
}
inline
void
setTexture
(
const
std
::
string
&
_nameInShader
,
const
ConstSharedTexture
&
_texture
,
GLenum
_unit
=
0
)
const
{
setUniform
(
getUniformLocation
(
_nameInShader
),
(
GLint
)
_unit
);
_texture
->
bind
(
_unit
);
}
inline
void
setProgramTexture
(
GLint
_location
,
const
ConstSharedTexture
&
_texture
,
GLenum
_unit
=
0
)
const
{
glProgramUniform1i
(
mObjectName
,
_location
,
_unit
);
_texture
->
bind
(
_unit
);
}
inline
void
setProgramTexture
(
GLint
_location
,
const
ConstSharedTexture
&
_texture
,
GLenum
_unit
=
0
)
const
{
glProgramUniform1i
(
mObjectName
,
_location
,
_unit
);
_texture
->
bind
(
_unit
);
}
// =================================================================================================== \/
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
// =================================================================================================== \/
...
...
include/ACGL/OpenGL/Objects/VertexArrayObject.hh
View file @
ff41ea3a
...
@@ -56,6 +56,12 @@ public:
...
@@ -56,6 +56,12 @@ public:
// more Attribute properties can be looked up in the ArrayBuffer (like the name)
// more Attribute properties can be looked up in the ArrayBuffer (like the name)
};
};
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef
std
::
vector
<
Attribute
>
AttributeVec
;
// ========================================================================================================= \/
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
// ========================================================================================================= \/
...
@@ -90,7 +96,8 @@ public:
...
@@ -90,7 +96,8 @@ public:
public:
public:
inline
GLuint
operator
()
(
void
)
const
{
return
mObjectName
;
}
inline
GLuint
operator
()
(
void
)
const
{
return
mObjectName
;
}
inline
GLuint
getObjectName
(
void
)
const
{
return
mObjectName
;
}
inline
GLuint
getObjectName
(
void
)
const
{
return
mObjectName
;
}
inline
GLenum
getMode
(
void
)
const
{
return
mMode
;
}
inline
const
AttributeVec
&
getAttributes
(
void
)
const
{
return
mAttributes
;
}
inline
GLenum
getMode
(
void
)
const
{
return
mMode
;
}
// ==================================================================================================== \/
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ============================================================================================ METHODS \/
...
@@ -231,7 +238,7 @@ public:
...
@@ -231,7 +238,7 @@ public:
* Return true if setAttributeMappingsByShaderProgram(_shaderProgram) would do nothing.
* Return true if setAttributeMappingsByShaderProgram(_shaderProgram) would do nothing.
* That means the VAO and ShaderProgram have already matching layouts.
* That means the VAO and ShaderProgram have already matching layouts.
*/
*/
bool
mappingsMatchShaderProgram
(
const
Const
SharedShaderProgram
&
_shaderProgram
)
const
bool
mappingsMatchShaderProgram
(
const
SharedShaderProgram
&
_shaderProgram
)
const
{
{
for
(
AttributeVec
::
size_type
i
=
0
;
i
<
mAttributes
.
size
();
++
i
)
for
(
AttributeVec
::
size_type
i
=
0
;
i
<
mAttributes
.
size
();
++
i
)
{
{
...
@@ -247,7 +254,7 @@ public:
...
@@ -247,7 +254,7 @@ public:
* Query the attribute locations based on the attribute names in the ArrayBuffers and the ShaderProgram
* Query the attribute locations based on the attribute names in the ArrayBuffers and the ShaderProgram
* If they match, use the location reported from the ShaderProgram.
* If they match, use the location reported from the ShaderProgram.
*/
*/
void
setAttributeLocationsByShaderProgram
(
const
Const
SharedShaderProgram
&
_shaderProgram
)
void
setAttributeLocationsByShaderProgram
(
const
SharedShaderProgram
&
_shaderProgram
)
{
{
bool
fullUpdateNeeded
=
false
;
bool
fullUpdateNeeded
=
false
;
...
@@ -394,12 +401,6 @@ public:
...
@@ -394,12 +401,6 @@ public:
drawArrays
(
mAttributes
[
0
].
arrayBuffer
->
getElements
());
drawArrays
(
mAttributes
[
0
].
arrayBuffer
->
getElements
());
}
}
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
protected:
typedef
std
::
vector
<
Attribute
>
AttributeVec
;
// =================================================================================================== \/
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
// =================================================================================================== \/
...
...
src/ACGL/OpenGL/Objects/ShaderProgram.cc
View file @
ff41ea3a
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/OpenGL/Tools.hh>
using
namespace
ACGL
::
OpenGL
;
using
namespace
ACGL
::
OpenGL
;
...
@@ -47,3 +48,33 @@ bool ShaderProgram::link(void) const
...
@@ -47,3 +48,33 @@ bool ShaderProgram::link(void) const
#endif
#endif
return
true
;
return
true
;
}
}
void
ShaderProgram
::
setAttributeLocationsByVAO
(
const
SharedVertexArrayObject
&
_vao
)
{
bool
needsRelink
=
false
;
// search through all attributes of _vao
VertexArrayObject
::
AttributeVec
vaoAttributes
=
_vao
->
getAttributes
();
for
(
VertexArrayObject
::
AttributeVec
::
size_type
i
=
0
;
i
<
vaoAttributes
.
size
();
++
i
)
{
if
(
vaoAttributes
[
i
].
location
==
-
1
)
continue
;
// find the name of the current attribute in its ArrayBuffer
std
::
string
arrayBufferAttributeName
=
vaoAttributes
[
i
].
arrayBuffer
->
getAttributes
()[
vaoAttributes
[
i
].
attributeID
].
name
;
// find out whether an attribute with a matching name exists in this ShaderProgram
GLint
attribLocation
=
getAttributeLocation
(
arrayBufferAttributeName
);
if
(
attribLocation
!=
-
1
// attribute with that name exists?
&&
attribLocation
!=
vaoAttributes
[
i
].
location
)
// attribute with that name not already bound correctly?
{
bindAttributeLocation
(
arrayBufferAttributeName
,
vaoAttributes
[
i
].
location
);
needsRelink
=
true
;
}
}
// re-link the program only if necessary
if
(
needsRelink
)
link
();
}
Write
Preview
Markdown
is supported
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