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
ca43376d
Commit
ca43376d
authored
Jul 16, 2013
by
Philip Trettner
Browse files
further shader parser fixes
parent
82115120
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/ACGL/OpenGL/Creator/ShaderParser.hh
View file @
ca43376d
...
...
@@ -48,6 +48,12 @@ public:
*/
bool
existsSourcefile
(
std
::
string
const
&
_filename
);
/**
* @brief parses a complete file
* @param _filename the file to parse
*/
void
parse
(
std
::
string
const
&
_filename
);
protected:
/**
...
...
include/ACGL/OpenGL/Creator/ShaderProgramCreator.hh
View file @
ca43376d
...
...
@@ -39,7 +39,8 @@ public:
//! The filenames (sorted and concatenated) will also be the name of the resource (can be changed by setResourceName() below).
//! If the filename has a dot in it (or _type is set), it will be treated as a single file, otherwise all
//! files starting with that string will be used.
ShaderProgramCreator
(
const
std
::
string
&
_fileName
,
GLenum
_type
=
GL_INVALID_VALUE
)
//! The empty c'tor is supported for containers and everything that needs one
ShaderProgramCreator
(
const
std
::
string
&
_fileName
=
""
,
GLenum
_type
=
GL_INVALID_VALUE
)
:
Resource
::
MultiFileBasedCreator
<
ShaderProgram
>
(),
mShaderType
(),
mAttributeLocations
(
new
LocationMappings
),
...
...
include/ACGL/Resource/MultiFileBasedCreator.hh
View file @
ca43376d
...
...
@@ -69,6 +69,15 @@ public:
//! this should update the resource and return true if successful
virtual
bool
update
(
ptr
::
shared_ptr
<
RESOURCE
>&
)
=
0
;
//! returns true iff _all_ files are up to date
bool
filesAreUpToDate
(
void
)
const
{
bool
b
=
true
;
for
(
unsigned
int
i
=
0
;
i
<
mFileNames
.
size
();
++
i
)
{
b
&=
(
Utils
::
FileHelpers
::
getFileModificationTime
(
mBasePath
+
mFileNames
[
i
]
)
==
mFileModificationTime
[
i
]
);
}
return
b
;
}
protected:
//! This constructor does not add any files, use this only on derived types which constructor will add a file itself!
MultiFileBasedCreator
()
:
mBasePath
(
""
)
{}
...
...
@@ -79,15 +88,6 @@ protected:
mFileModificationTime
.
push_back
(
Utils
::
FileHelpers
::
FileModificationTime
()
);
}
//! returns true iff _all_ files are up to date
bool
filesAreUpToDate
(
void
)
{
bool
b
=
true
;
for
(
unsigned
int
i
=
0
;
i
<
mFileNames
.
size
();
++
i
)
{
b
&=
(
Utils
::
FileHelpers
::
getFileModificationTime
(
mBasePath
+
mFileNames
[
i
]
)
==
mFileModificationTime
[
i
]
);
}
return
b
;
}
//! updates _all_ modification times
void
updateFileModificationTimes
(
void
)
{
for
(
unsigned
int
i
=
0
;
i
<
mFileNames
.
size
();
++
i
)
{
...
...
src/ACGL/OpenGL/Creator/ShaderCreator.cc
View file @
ca43376d
...
...
@@ -23,6 +23,7 @@ SharedShader ShaderCreator::create()
SharedShader
shader
(
new
Shader
(
mType
));
SharedShaderParser
sp
(
mShaderParserFactory
->
createParser
(
mFullFilePath
)
);
sp
->
parse
(
mFullFilePath
);
if
(
shader
->
setFromFile
(
sp
))
{
unsigned
int
importedSourcesCount
=
sp
->
getNumberOfImportedFiles
();
mImportedShaders
.
reserve
(
importedSourcesCount
);
...
...
@@ -55,6 +56,7 @@ bool ShaderCreator::update(SharedShader& shader)
{
// try to compile the source in another shader, only proceed if that worked!
Shader
dummy
(
shader
->
getType
()
);
SharedShaderParser
sp
(
mShaderParserFactory
->
createParser
(
mFullFilePath
)
);
sp
->
parse
(
mFullFilePath
);
if
(
!
dummy
.
setFromFile
(
sp
))
{
// we had a shader compile error, update the timestamp to prevent a second try
...
...
@@ -78,6 +80,7 @@ bool ShaderCreator::update(SharedShader& shader)
// it worked, so load the source in "our" shader:
{
SharedShaderParser
sp
(
mShaderParserFactory
->
createParser
(
mFullFilePath
)
);
sp
->
parse
(
mFullFilePath
);
shader
->
setFromFile
(
sp
);
}
...
...
src/ACGL/OpenGL/Creator/ShaderParser.cc
View file @
ca43376d
...
...
@@ -5,6 +5,7 @@
**********************************************************************/
#include <ACGL/OpenGL/Creator/ShaderParser.hh>
#include <ACGL/Base/Settings.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/Utils/StringHelpers.hh>
...
...
@@ -17,17 +18,8 @@ using namespace ACGL::OpenGL;
ShaderParser
::
ShaderParser
(
const
std
::
string
&
_filename
)
{
mMaxVersion
=
110
;
mSources
.
push_back
(
"#version 330
\n
"
);
std
::
string
path
,
file
;
StringHelpers
::
splitLastFileOrFolder
(
_filename
,
path
,
file
);
//readin( "./"+path+"/"+file );
readin
(
_filename
);
if
(
mMaxVersion
>
110
)
{
mSources
[
0
]
=
"#version "
+
StringHelpers
::
toString
(
mMaxVersion
)
+
"
\n
"
;
}
// moved to parse
// calling virtual functions in c'tor is quite the bad idea
}
...
...
@@ -92,6 +84,24 @@ bool ShaderParser::existsSourcefile(const std::string &_filename)
return
std
::
find
(
mSourceFileNames
.
begin
(),
mSourceFileNames
.
end
(),
_filename
)
!=
mSourceFileNames
.
end
();
}
void
ShaderParser
::
parse
(
const
std
::
string
&
_filename
)
{
mMaxVersion
=
110
;
mSources
.
clear
();
mSourceFileNames
.
clear
();
mSources
.
push_back
(
"#version 330
\n
"
);
std
::
string
path
,
file
;
StringHelpers
::
splitLastFileOrFolder
(
_filename
,
path
,
file
);
//readin( "./"+path+"/"+file );
readin
(
_filename
);
if
(
mMaxVersion
>
110
)
{
mSources
[
0
]
=
"#version "
+
StringHelpers
::
toString
(
mMaxVersion
)
+
"
\n
"
;
}
}
int
ShaderParser
::
registerSourceFile
(
const
std
::
string
&
_name
)
{
mSourceFileNames
.
push_back
(
_name
);
...
...
@@ -184,9 +194,13 @@ bool IncludingShaderParser::processPragma(const std::vector<std::string> &_token
std
::
string
fileToImport
(
_tokens
[
1
]);
// strip '"' or '<' also allows mix of them, but not recommended
// currently no difference in behavior
bool
absolute
=
false
;
size_t
startName
=
fileToImport
.
find
(
'"'
,
0
);
if
(
startName
==
std
::
string
::
npos
)
startName
=
fileToImport
.
find
(
'<'
,
0
);
if
(
startName
==
std
::
string
::
npos
)
{
startName
=
fileToImport
.
find
(
'<'
,
0
);
absolute
=
true
;
}
if
(
startName
==
std
::
string
::
npos
)
return
false
;
size_t
endName
=
fileToImport
.
find
(
'"'
,
startName
+
1
);
if
(
endName
==
std
::
string
::
npos
)
endName
=
fileToImport
.
find
(
'>'
,
startName
+
1
);
...
...
@@ -203,8 +217,17 @@ bool IncludingShaderParser::processPragma(const std::vector<std::string> &_token
if
(
fileToImport
.
size
()
>
2
&&
fileToImport
[
0
]
==
'.'
&&
fileToImport
[
1
]
==
'/'
)
fileToImport
=
fileToImport
.
substr
(
2
,
fileToImport
.
size
()
-
2
);
// absolute/relative handling
std
::
string
path
,
file
;
StringHelpers
::
splitLastFileOrFolder
(
_filename
,
path
,
file
);
if
(
absolute
)
{
path
=
ACGL
::
Base
::
Settings
::
the
()
->
getFullShaderPath
();
if
(
path
.
size
()
==
0
)
path
=
"."
;
}
else
StringHelpers
::
splitLastFileOrFolder
(
_filename
,
path
,
file
);
fileToImport
=
path
+
"/"
+
fileToImport
;
}
...
...
src/ACGL/OpenGL/Objects/Shader.cc
View file @
ca43376d
...
...
@@ -55,6 +55,8 @@ bool Shader::setFromFileNoImportParsing(const std::string& _filename)
bool
Shader
::
setFromFile
(
SharedShaderParser
const
&
_sp
)
{
assert
(
_sp
->
getSources
().
size
()
>
0
);
// did you forget to call _sp->parse(...)?
bool
compileErrors
=
true
;
if
(
setSources
(
_sp
->
getSources
(),
false
)
)
{
// don't check for errors, we will do that on our own:
std
::
string
compileLog
;
...
...
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