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
05305f7d
Commit
05305f7d
authored
Feb 09, 2012
by
Robert Menzel
Browse files
ShaderProgramControlFiles can handle complete mapping lists
parent
c3a088af
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/ACGL/OpenGL/Controller.hh
View file @
05305f7d
...
@@ -25,7 +25,6 @@
...
@@ -25,7 +25,6 @@
#include <ACGL/OpenGL/Controller/RenderBufferControl.hh>
#include <ACGL/OpenGL/Controller/RenderBufferControl.hh>
#include <ACGL/OpenGL/Controller/RenderObjectControl.hh>
#include <ACGL/OpenGL/Controller/RenderObjectControl.hh>
#include <ACGL/OpenGL/Controller/ShaderControlFile.hh>
#include <ACGL/OpenGL/Controller/ShaderControlFile.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramControlAutoFiles.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramControlFiles.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramControlFiles.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramObjectControl.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramObjectControl.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
...
...
include/ACGL/OpenGL/Controller/ShaderProgramControlFiles.hh
View file @
05305f7d
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/GL.hh>
#include <vector>
#include <vector>
#include <ACGL/OpenGL/Data/LocationMappings.hh>
namespace
ACGL
{
namespace
ACGL
{
namespace
OpenGL
{
namespace
OpenGL
{
...
@@ -45,8 +46,8 @@ public:
...
@@ -45,8 +46,8 @@ public:
ShaderProgramControlFiles
(
const
std
::
string
&
_fileName
,
GLenum
_type
=
GL_INVALID_VALUE
)
ShaderProgramControlFiles
(
const
std
::
string
&
_fileName
,
GLenum
_type
=
GL_INVALID_VALUE
)
:
Resource
::
FileController
<
ShaderProgram
>
(
_fileName
),
:
Resource
::
FileController
<
ShaderProgram
>
(
_fileName
),
mShaderType
(),
mShaderType
(),
mAttributeLocations
(),
mAttributeLocations
(
new
LocationMappings
),
mFragmentDataLocations
()
mFragmentDataLocations
(
new
LocationMappings
)
{
{
if
(
_type
!=
GL_INVALID_VALUE
)
{
if
(
_type
!=
GL_INVALID_VALUE
)
{
andFile
(
_fileName
,
_type
);
andFile
(
_fileName
,
_type
);
...
@@ -66,6 +67,10 @@ public:
...
@@ -66,6 +67,10 @@ public:
// ============================================================================================ METHODS \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
// ==================================================================================================== \/
public:
public:
//
// Adding files:
//
//! adds a single file, the shader type will be guessed by the ending:
//! adds a single file, the shader type will be guessed by the ending:
inline
ShaderProgramControlFiles
&
andFile
(
const
std
::
string
&
_fileName
)
{
mFileName
.
push_back
(
_fileName
);
mShaderType
.
push_back
(
GL_INVALID_VALUE
);
return
*
this
;
}
inline
ShaderProgramControlFiles
&
andFile
(
const
std
::
string
&
_fileName
)
{
mFileName
.
push_back
(
_fileName
);
mShaderType
.
push_back
(
GL_INVALID_VALUE
);
return
*
this
;
}
...
@@ -76,8 +81,26 @@ public:
...
@@ -76,8 +81,26 @@ public:
//! adds all files begining with the given name, the shader type will be guessed by the ending:
//! adds all files begining with the given name, the shader type will be guessed by the ending:
ShaderProgramControlFiles
&
autoFiles
(
const
std
::
string
&
_fileName
);
ShaderProgramControlFiles
&
autoFiles
(
const
std
::
string
&
_fileName
);
inline
ShaderProgramControlFiles
&
attributeLocation
(
const
std
::
string
&
_attributeName
)
{
mAttributeLocations
.
push_back
(
_attributeName
);
return
*
this
;
}
//
inline
ShaderProgramControlFiles
&
fragmentDataLocation
(
const
std
::
string
&
_fragmentDataName
)
{
mFragmentDataLocations
.
push_back
(
_fragmentDataName
);
return
*
this
;
}
// Adding locations:
//
//! adds an attribute location to the next free location number:
inline
ShaderProgramControlFiles
&
attributeLocation
(
const
std
::
string
&
_attributeName
)
{
mAttributeLocations
->
setLocation
(
_attributeName
);
return
*
this
;
}
//! adds an attribute location to the given location number:
inline
ShaderProgramControlFiles
&
attributeLocation
(
const
std
::
string
&
_attributeName
,
GLuint
_location
)
{
mAttributeLocations
->
setLocation
(
_attributeName
,
_location
);
return
*
this
;
}
//! adds a fragment output location to the next free location number:
inline
ShaderProgramControlFiles
&
fragmentDataLocation
(
const
std
::
string
&
_fragmentDataName
)
{
mFragmentDataLocations
->
setLocation
(
_fragmentDataName
);
return
*
this
;
}
//! adds a fragment output location to the given location number:
inline
ShaderProgramControlFiles
&
fragmentDataLocation
(
const
std
::
string
&
_fragmentDataName
,
GLuint
_location
)
{
mFragmentDataLocations
->
setLocation
(
_fragmentDataName
,
_location
);
return
*
this
;
}
//! adds a whole list of mappings
inline
ShaderProgramControlFiles
&
attributeLocations
(
const
SharedLocationMappings
&
_mapping
)
{
mAttributeLocations
->
addLocations
(
_mapping
);
return
*
this
;
}
//! adds a whole list of mappings
inline
ShaderProgramControlFiles
&
fragmentDataLocations
(
const
SharedLocationMappings
&
_mapping
)
{
mFragmentDataLocations
->
addLocations
(
_mapping
);
return
*
this
;
}
// ===================================================================================================== \/
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ============================================================================================ OVERRIDE \/
...
@@ -92,8 +115,9 @@ public:
...
@@ -92,8 +115,9 @@ public:
protected:
protected:
std
::
vector
<
GLenum
>
mShaderType
;
std
::
vector
<
GLenum
>
mShaderType
;
std
::
vector
<
std
::
string
>
mFileName
;
std
::
vector
<
std
::
string
>
mFileName
;
std
::
vector
<
std
::
string
>
mAttributeLocations
;
std
::
vector
<
std
::
string
>
mFragmentDataLocations
;
SharedLocationMappings
mAttributeLocations
;
SharedLocationMappings
mFragmentDataLocations
;
private:
private:
// set attribute & fragdata locations prior to shader program linking
// set attribute & fragdata locations prior to shader program linking
...
...
include/ACGL/OpenGL/Data/LocationMappings.hh
View file @
05305f7d
...
@@ -62,6 +62,8 @@ public:
...
@@ -62,6 +62,8 @@ public:
//! Returns the raw location map:
//! Returns the raw location map:
const
LocationMap
&
getLocations
()
const
{
return
mMappings
;
}
const
LocationMap
&
getLocations
()
const
{
return
mMappings
;
}
inline
size_t
getSize
()
{
return
mMappings
.
size
();
}
// ==================================================================================================== \/
// ==================================================================================================== \/
// ============================================================================================ SETTERS \/
// ============================================================================================ SETTERS \/
// ==================================================================================================== \/
// ==================================================================================================== \/
...
@@ -70,6 +72,13 @@ public:
...
@@ -70,6 +72,13 @@ public:
//! Adds one location:
//! Adds one location:
void
setLocation
(
const
std
::
string
&
_name
,
GLuint
_location
);
void
setLocation
(
const
std
::
string
&
_name
,
GLuint
_location
);
//! Adds one location, uses the next free integer as the location
//! this way the locations can get the number of the order they were added (if only this function gets used)
void
setLocation
(
const
std
::
string
&
_name
);
//! adds all given locations:
void
addLocations
(
const
ptr
::
shared_ptr
<
LocationMappings
>
&
_other
);
// ==================================================================================================== \/
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
// ==================================================================================================== \/
...
@@ -85,7 +94,6 @@ public:
...
@@ -85,7 +94,6 @@ public:
protected:
protected:
LocationMap
mMappings
;
LocationMap
mMappings
;
};
};
ACGL_SMARTPOINTER_TYPEDEFS
(
LocationMappings
)
ACGL_SMARTPOINTER_TYPEDEFS
(
LocationMappings
)
}
// OpenGL
}
// OpenGL
...
...
src/ACGL/OpenGL/Controller/ShaderProgramControlFiles.cc
View file @
05305f7d
...
@@ -109,25 +109,20 @@ SharedShaderProgram ShaderProgramControlFiles::create(void)
...
@@ -109,25 +109,20 @@ SharedShaderProgram ShaderProgramControlFiles::create(void)
}
}
}
}
setBindings
(
shaderProgram
);
if
(
!
shaderProgram
->
link
())
{
return
SharedShaderProgram
();
// linking failed
if
(
shaderProgram
->
link
())
{
return
shaderProgram
;
}
}
return
SharedShaderProgram
();
// linking failed
setBindings
(
shaderProgram
);
// will relink, but needs a linked program :-(
return
shaderProgram
;
}
}
void
ShaderProgramControlFiles
::
setBindings
(
SharedShaderProgram
&
_shaderProgram
)
void
ShaderProgramControlFiles
::
setBindings
(
SharedShaderProgram
&
_shaderProgram
)
{
{
#if (ACGL_OPENGL_VERSION >= 30)
#if (ACGL_OPENGL_VERSION >= 30)
for
(
std
::
vector
<
std
::
string
>::
size_type
i
=
0
;
i
<
mAttributeLocations
.
size
();
++
i
)
{
_shaderProgram
->
setFragmentDataLocations
(
mFragmentDataLocations
);
_shaderProgram
->
bindAttributeLocation
(
mAttributeLocations
[
i
],
i
);
_shaderProgram
->
setAttributeLocations
(
mAttributeLocations
);
}
for
(
std
::
vector
<
std
::
string
>::
size_type
i
=
0
;
i
<
mFragmentDataLocations
.
size
();
++
i
)
{
_shaderProgram
->
bindFragmentDataLocation
(
mFragmentDataLocations
[
i
],
i
);
}
#else
#else
if
(
(
mAttributeLocations
.
s
ize
()
>
0
)
&&
(
mFragmentDataLocations
.
s
ize
()
>
0
)
)
{
if
(
(
mAttributeLocations
.
getS
ize
()
>
0
)
&&
(
mFragmentDataLocations
.
getS
ize
()
>
0
)
)
{
Utils
::
error
()
<<
"can't set explicit attribute/fragdata locations on OpenGL < 3.0 "
<<
std
::
endl
;
Utils
::
error
()
<<
"can't set explicit attribute/fragdata locations on OpenGL < 3.0 "
<<
std
::
endl
;
}
}
#endif
#endif
...
...
src/ACGL/OpenGL/Data/LocationMappings.cc
View file @
05305f7d
...
@@ -29,9 +29,36 @@ void LocationMappings::setLocation(const std::string& _name, GLuint _location)
...
@@ -29,9 +29,36 @@ void LocationMappings::setLocation(const std::string& _name, GLuint _location)
ACGL
::
Utils
::
warning
()
<<
"LocationMappings: Overwriting location mapping for "
<<
_name
;
ACGL
::
Utils
::
warning
()
<<
"LocationMappings: Overwriting location mapping for "
<<
_name
;
ACGL
::
Utils
::
warning
()
<<
" (previous value: "
<<
mMappings
[
_name
]
<<
", new value: "
<<
_location
<<
")"
<<
std
::
endl
;
ACGL
::
Utils
::
warning
()
<<
" (previous value: "
<<
mMappings
[
_name
]
<<
", new value: "
<<
_location
<<
")"
<<
std
::
endl
;
}
}
//ACGL::Utils::debug() << "setLocation: " << _name << " value: " << _location<< "" << std::endl;
mMappings
[
_name
]
=
_location
;
mMappings
[
_name
]
=
_location
;
}
}
void
LocationMappings
::
setLocation
(
const
std
::
string
&
_name
)
{
LocationMap
::
const_iterator
end
=
mMappings
.
end
();
GLuint
nextFreeLocation
=
0
;
// most likely not the fastest way ;-)
LocationMap
::
const_iterator
it
=
mMappings
.
begin
();
while
(
it
!=
end
)
{
if
(
it
->
second
==
nextFreeLocation
)
{
nextFreeLocation
++
;
it
=
mMappings
.
begin
();
}
else
{
++
it
;
}
}
setLocation
(
_name
,
nextFreeLocation
);
}
void
LocationMappings
::
addLocations
(
const
SharedLocationMappings
&
_other
)
{
LocationMap
::
const_iterator
end
=
_other
->
mMappings
.
end
();
for
(
LocationMap
::
const_iterator
it
=
_other
->
mMappings
.
begin
();
it
!=
end
;
++
it
)
{
setLocation
(
it
->
first
,
it
->
second
);
}
}
void
LocationMappings
::
printMapping
()
void
LocationMappings
::
printMapping
()
{
{
...
...
src/ACGL/OpenGL/Objects/ShaderProgram.cc
View file @
05305f7d
...
@@ -52,6 +52,8 @@ bool ShaderProgram::link() const
...
@@ -52,6 +52,8 @@ bool ShaderProgram::link() const
void
ShaderProgram
::
setAttributeLocations
(
ConstSharedLocationMappings
_locationMappings
)
void
ShaderProgram
::
setAttributeLocations
(
ConstSharedLocationMappings
_locationMappings
)
{
{
if
(
!
_locationMappings
)
return
;
bool
needsRelink
=
false
;
bool
needsRelink
=
false
;
// search through all attributes:
// search through all attributes:
...
@@ -82,6 +84,8 @@ void ShaderProgram::setAttributeLocations(ConstSharedLocationMappings _locationM
...
@@ -82,6 +84,8 @@ void ShaderProgram::setAttributeLocations(ConstSharedLocationMappings _locationM
void
ShaderProgram
::
setFragmentDataLocations
(
ConstSharedLocationMappings
_locationMappings
)
void
ShaderProgram
::
setFragmentDataLocations
(
ConstSharedLocationMappings
_locationMappings
)
{
{
if
(
!
_locationMappings
)
return
;
bool
needsRelink
=
false
;
bool
needsRelink
=
false
;
// search through all color attachments:
// search through all color attachments:
...
...
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