Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
CAMP
campvis-public
Commits
5f72759e
Commit
5f72759e
authored
Jan 13, 2014
by
Christian Schulte zu Berge
Browse files
Extended tgt::ShaderManager to support both global GLSL version and per-shader version setting.
parent
08793132
Changes
3
Hide whitespace changes
Inline
Side-by-side
application/campvisapplication.cpp
View file @
5f72759e
...
...
@@ -104,7 +104,7 @@ namespace campvis {
tgt
::
GLContextScopedLock
lock
(
_localContext
);
tgt
::
initGL
(
featureset
);
ShdrMgr
.
set
GlobalHeader
(
"#v
ersion
330
\n
"
);
ShdrMgr
.
set
DefaultGlslV
ersion
(
"
330"
);
LGL_ERROR
;
// ensure matching OpenGL specs
...
...
ext/tgt/shadermanager.cpp
View file @
5f72759e
...
...
@@ -135,9 +135,20 @@ void ShaderPreprocessor::parse() {
result_
.
clear
();
includedFilenames_
.
clear
();
outputComment
(
"BEGIN GLOBAL HEADER"
);
parsePart
(
ShdrMgr
.
getGlobalHeader
(),
"GLOBAL HEADER"
);
outputComment
(
"END GLOBAL HEADER"
);
if
(
!
shd_
->
customGlslVersion_
.
empty
())
{
parsePart
(
"#version "
+
shd_
->
customGlslVersion_
+
"
\n
"
,
"Custom per-shader version"
);
}
else
{
if
(
!
ShdrMgr
.
getDefaultGlslVersion
().
empty
())
{
parsePart
(
"#version "
+
ShdrMgr
.
getDefaultGlslVersion
()
+
"
\n
"
,
"Global version"
);
}
}
if
(
!
ShdrMgr
.
getGlobalHeader
().
empty
())
{
outputComment
(
"BEGIN GLOBAL HEADER"
);
parsePart
(
ShdrMgr
.
getGlobalHeader
(),
"GLOBAL HEADER"
);
outputComment
(
"END GLOBAL HEADER"
);
}
if
(
!
shd_
->
header_
.
empty
())
{
outputComment
(
"BEGIN HEADER"
);
...
...
@@ -600,7 +611,7 @@ void Shader::load(const string& filename, const string& customHeader) throw (Exc
}
void
Shader
::
loadSeparate
(
const
string
&
vert_filename
,
const
string
&
geom_filename
,
const
string
&
frag_filename
,
const
string
&
customHeader
)
const
string
&
frag_filename
,
const
string
&
customHeader
,
const
std
::
string
&
customGlslVersion
)
throw
(
Exception
)
{
ShaderObject
*
frag
=
0
;
...
...
@@ -613,6 +624,9 @@ void Shader::loadSeparate(const string& vert_filename, const string& geom_filena
if
(
!
customHeader
.
empty
())
{
vert
->
setHeader
(
customHeader
);
}
if
(
!
customGlslVersion
.
empty
())
{
vert
->
setCustomGlslVersion
(
customGlslVersion
);
}
try
{
vert
->
loadSourceFromFile
(
vert_filename
);
...
...
@@ -639,6 +653,9 @@ void Shader::loadSeparate(const string& vert_filename, const string& geom_filena
if
(
!
customHeader
.
empty
())
{
geom
->
setHeader
(
customHeader
);
}
if
(
!
customGlslVersion
.
empty
())
{
geom
->
setCustomGlslVersion
(
customGlslVersion
);
}
try
{
geom
->
loadSourceFromFile
(
geom_filename
);
...
...
@@ -666,6 +683,9 @@ void Shader::loadSeparate(const string& vert_filename, const string& geom_filena
if
(
!
customHeader
.
empty
())
{
frag
->
setHeader
(
customHeader
);
}
if
(
!
customGlslVersion
.
empty
())
{
frag
->
setCustomGlslVersion
(
customGlslVersion
);
}
try
{
frag
->
loadSourceFromFile
(
frag_filename
);
...
...
@@ -1289,22 +1309,22 @@ ShaderManager::ShaderManager()
{}
Shader
*
ShaderManager
::
load
(
const
string
&
filename
,
const
string
&
customHeader
,
bool
activate
)
bool
activate
,
const
std
::
string
&
customGlslVersion
/*= ""*/
)
throw
(
Exception
)
{
return
loadSeparate
(
filename
+
".vert"
,
filename
+
".frag"
,
customHeader
,
activate
);
return
loadSeparate
(
filename
+
".vert"
,
filename
+
".frag"
,
customHeader
,
activate
,
customGlslVersion
);
}
Shader
*
ShaderManager
::
loadSeparate
(
const
string
&
vert_filename
,
const
string
&
frag_filename
,
const
string
&
customHeader
,
bool
activate
)
const
string
&
customHeader
,
bool
activate
,
const
std
::
string
&
customGlslVersion
/*= ""*/
)
throw
(
Exception
)
{
return
loadSeparate
(
vert_filename
,
""
,
frag_filename
,
customHeader
,
activate
);
return
loadSeparate
(
vert_filename
,
""
,
frag_filename
,
customHeader
,
activate
,
customGlslVersion
);
}
Shader
*
ShaderManager
::
loadSeparate
(
const
string
&
vert_filename
,
const
string
&
geom_filename
,
const
string
&
frag_filename
,
const
string
&
customHeader
,
bool
activate
)
const
string
&
customHeader
,
bool
activate
,
const
std
::
string
&
customGlslVersion
/*= ""*/
)
throw
(
Exception
)
{
LDEBUG
(
"Loading files "
<<
vert_filename
<<
" and "
<<
frag_filename
);
...
...
ext/tgt/shadermanager.h
View file @
5f72759e
...
...
@@ -118,6 +118,10 @@ public:
*/
void
setHeader
(
const
std
::
string
&
h
);
void
setCustomGlslVersion
(
const
std
::
string
&
version
)
{
customGlslVersion_
=
version
;
}
ShaderType
getType
()
{
return
shaderType_
;
}
void
setSource
(
std
::
string
source
)
{
...
...
@@ -160,6 +164,7 @@ protected:
std
::
string
source_
;
std
::
string
unparsedSource_
;
std
::
string
header_
;
std
::
string
customGlslVersion_
;
///< Optional custom GLSL version, will override global GLSL version if set
bool
isCompiled_
;
GLint
inputType_
;
GLint
outputType_
;
...
...
@@ -385,7 +390,7 @@ protected:
* @throw Exception if loading failed
*/
void
loadSeparate
(
const
std
::
string
&
vertFilename
,
const
std
::
string
&
geomFilename
,
const
std
::
string
&
fragFilename
,
const
std
::
string
&
customHeader
=
""
)
const
std
::
string
&
fragFilename
,
const
std
::
string
&
customHeader
=
""
,
const
std
::
string
&
customGlslVersion
=
""
)
throw
(
Exception
);
typedef
std
::
list
<
ShaderObject
*>
ShaderObjects
;
...
...
@@ -430,7 +435,7 @@ public:
* @throw Exception if loading failed
*/
Shader
*
load
(
const
std
::
string
&
filename
,
const
std
::
string
&
customHeader
=
""
,
bool
activate
=
true
)
bool
activate
=
true
,
const
std
::
string
&
customGlslVersion
=
""
)
throw
(
Exception
);
/**
...
...
@@ -447,7 +452,7 @@ public:
* @throw Exception if loading failed
*/
Shader
*
loadSeparate
(
const
std
::
string
&
vertFilename
,
const
std
::
string
&
fragFilename
,
const
std
::
string
&
customHeader
=
""
,
bool
activate
=
true
)
const
std
::
string
&
customHeader
=
""
,
bool
activate
=
true
,
const
std
::
string
&
customGlslVersion
=
""
)
throw
(
Exception
);
/**
...
...
@@ -465,7 +470,7 @@ public:
*/
Shader
*
loadSeparate
(
const
std
::
string
&
vertFilename
,
const
std
::
string
&
geomFilename
,
const
std
::
string
&
fragFilename
,
const
std
::
string
&
customHeader
,
bool
activate
=
true
)
const
std
::
string
&
customHeader
,
bool
activate
=
true
,
const
std
::
string
&
customGlslVersion
=
""
)
throw
(
Exception
);
bool
rebuildAllShadersFromFile
();
...
...
@@ -486,7 +491,25 @@ public:
return
globalHeader_
;
}
/**
* Sets the default GLSL version string, will be added to the '#version' pragma
* at the beginning of each shader.
* \param version Default GLSL version string.
*/
void
setDefaultGlslVersion
(
const
std
::
string
&
version
)
{
defaultGlslVersion_
=
version
;
}
/**
* Gets the default GLSL version string, will be added to the '#version' pragma
* at the beginning of each shader.
*/
const
std
::
string
&
getDefaultGlslVersion
()
const
{
return
defaultGlslVersion_
;
}
protected:
std
::
string
defaultGlslVersion_
;
///< Default GLSL version string, will be added to the '#version' pragma at the beginning of each shader
std
::
string
globalHeader_
;
///< Global header that will be added to all shaders.
static
const
std
::
string
loggerCat_
;
...
...
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