19 (
const SLchar*)
"(e0001) not a valid program object",
20 (
const SLchar*)
"(e0002) not a valid object",
21 (
const SLchar*)
"(e0003) out of memory",
22 (
const SLchar*)
"(e0004) unknown compiler error"};
94 SL_WARN_MSG(
"SLGLShader::createAndCompile: Nothing to compile!");
95 std::cout <<
"file: " <<
_file << std::endl;
102 _shaderID = glCreateShader(GL_VERTEX_SHADER);
115 _shaderID = glCreateShader(GL_FRAGMENT_SHADER);
118 SL_EXIT_MSG(
"SLGLShader::load: Unknown shader type.");
125 SLstring srcVersion =
"#version " + verGLSL;
126 if (state->
glIsES3()) srcVersion +=
" es";
134 const char* src =
_code.c_str();
135 glShaderSource(
_shaderID, 1, &src,
nullptr);
142 SLint compileSuccess = 0;
143 glGetShaderiv(
_shaderID, GL_COMPILE_STATUS, &compileSuccess);
145 if (compileSuccess == GL_FALSE)
150 SL_LOG(
"*** COMPILER ERROR ***");
155 for (
string& line : lines)
156 SL_LOG(
"%4d: %s", lineNum++, line.c_str());
161 #ifndef SL_EMSCRIPTEN
165 # if defined(DEBUG) || defined(_DEBUG)
173 SL_LOG(
"Exported Shader : %s", filename.c_str());
186 SL_LOG(
"Exported Shader : %s", filename.c_str());
194 SL_WARN_MSG(
"**** No shader path and filename for shader ***");
210 if (src[i] ==
'/' && src[i + 1] ==
'/')
214 while (i < len && src[i] !=
'\n')
218 else if (src[i] ==
'/' && src[i + 1] ==
'*')
220 while (i < len && !(src[i] ==
'*' && src[i + 1] ==
'/'))
222 if (src[i] ==
'\n') dst +=
'\n';
249 default:
return "Unknown";
257 size_t pragmaStart = inCode.find(
"#pragma");
258 if (pragmaStart == string::npos)
265 for (
string& line : codeLines)
267 pragmaStart = line.find(
"#pragma");
268 if (pragmaStart == string::npos)
269 outCode += line +
'\n';
275 for (
auto& part : pragmaParts)
278 if (pragmaParts[1] ==
"include")
282 string pathFile = path + filename;
287 outCode += includeCode +
'\n';
291 SL_LOG(
"SLGLShader::preprocessPragmas: File doesn't exist: %s",
293 outCode += line +
'\n';
297 outCode += line +
'\n';
307 size_t pragmaStart = inCode.find(
"#pragma");
308 if (pragmaStart == string::npos)
315 for (
string& line : codeLines)
317 pragmaStart = line.find(
"#pragma");
318 if (pragmaStart == string::npos)
319 outCode += line +
'\n';
325 for (
auto& part : pragmaParts)
328 if (pragmaParts[1] ==
"define")
330 if (pragmaParts[2] ==
"NUM_LIGHTS")
332 outCode +=
"#define NUM_LIGHTS " +
333 std::to_string(lights->size()) +
"\n";
336 outCode += line +
'\n';
339 outCode += line +
'\n';
#define SL_WARN_MSG(message)
vector< SLstring > SLVstring
#define SL_EXIT_MSG(message)
SLShaderType
Shader type enumeration for vertex or fragment (pixel) shader.
const SLchar * aGLSLErrorString[]
Singleton class for global render state.
vector< SLLight * > SLVLight
STL vector of light pointers.
SLstring preprocessIncludePragmas(SLstring inCode)
Replaces our custom pragma include directives in GLSL code.
SLuint _shaderID
Program Object.
void load(const SLstring &filename)
SLGLShader::load loads a shader file into string _shaderSource.
SLShaderType _type
Shader type enumeration.
SLstring _file
Path & filename of shader.
SLstring typeName()
Returns the shader type as string.
SLstring _code
ASCII Source-Code.
SLbool createAndCompile(SLVLight *lights)
SLGLShader::createAndCompile creates & compiles the OpenGL shader object.
void loadFromMemory(const SLstring &program)
SLGLShader::load loads a shader file from memory into memory.
SLstring preprocessDefinePragmas(SLstring inCode, SLVLight *lights)
Replaces our custom pragma define directives in GLSL code.
static SLstring removeComments(SLstring src)
SLGLShader::removeComments for C/C++ comments removal from shader code.
SLGLShader()
Default constructor.
Singleton class holding all OpenGL states.
static SLGLState * instance()
Public static instance getter for singleton pattern.
Base class for all other classes.
SLIOBuffer readIntoBuffer(std::string path, SLIOStreamKind kind)
Reads an entire file into memory.
bool exists(std::string path, SLIOStreamKind kind)
Checks whether a given file exists.
std::string readIntoString(std::string path, SLIOStreamKind kind)
Reads an entire file into a string.
void writeString(std::string path, SLIOStreamKind kind, const std::string &string)
Writes a string to a file.
Utils provides utilities for string & file handling, logging and math functions.
bool dirExists(const string &path)
Returns true if a directory exists.
bool containsString(const string &container, const string &search)
Returns true if container contains the search string.
vector< string > getStringLines(const string &multiLineString)
Returns a vector of string one per line of a multiline string.
string getFileName(const string &pathFilename)
Returns the filename of path-filename string.
void splitString(const string &s, char delimiter, vector< string > &splits)
Splits an input string at a delimiter character into a string vector.
string getPath(const string &pathFilename)
Returns the path w. '\' of path-filename string.
string getDirName(const string &pathFilename)
Strip last component from file name.
string trimString(const string &s, const string &drop)
Trims a string at both end.
bool onlyErrorLogs
if this flag is set to true all calls to log get ignored
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
Utility struct that holds a pointer and its length.
void deallocate()
Deallocates the data owned by the buffer.