Commit d384b78a authored by Christopher Tenter's avatar Christopher Tenter
Browse files

ShaderGenerator:

- namespace ACG
- moved template filename to ShaderDesc
- simplified interface of ShaderProgGenerator

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14606 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c88a0ab5
......@@ -9,8 +9,12 @@
#include <QDir>
#include <QTextStream>
// sprintf_s warning
//#pragma warning(disable : 4996)
namespace ACG
{
#define LIGHTING_CODE_FILE "../SG_LIGHTING.GLSL"
......@@ -311,6 +315,8 @@ ShaderProgGenerator::ShaderProgGenerator(ShaderGenDesc* _desc)
memcpy(&desc_, _desc, sizeof(ShaderGenDesc));
loadLightingFunctions();
generateShaders();
}
ShaderProgGenerator::~ShaderProgGenerator(void)
......@@ -321,14 +327,14 @@ ShaderProgGenerator::~ShaderProgGenerator(void)
void ShaderProgGenerator::loadStringListFromFile(const char* _fileName, QStringList* _out)
void ShaderProgGenerator::loadStringListFromFile(QString _fileName, QStringList* _out)
{
QFile file(_fileName);
file.open(QIODevice::ReadOnly | QIODevice::Text);
if (!file.isReadable())
std::cout << "error: file missing -> \"" << _fileName << "\"" << std::endl;
std::cout << "error: file missing -> \"" << (const char*)_fileName.toAscii() << "\"" << std::endl;
else
{
......@@ -714,11 +720,22 @@ void ShaderProgGenerator::addLightingFunctions(QStringList* _code)
void ShaderProgGenerator::generateShaders()
{
loadShaderTemplateFromFile();
buildVertexShader();
buildFragmentShader();
}
const QStringList& ShaderProgGenerator::getVertexShaderCode()
{
return vertex_->getShaderCode();
}
const QStringList& ShaderProgGenerator::getFragmentShaderCode()
{
return fragment_->getShaderCode();
}
void ShaderProgGenerator::saveVertexShToFile(const char* _fileName)
{
......@@ -731,14 +748,15 @@ void ShaderProgGenerator::saveFragmentShToFile(const char* _fileName)
}
void ShaderProgGenerator::loadShaderTemplateFromFile(const char *_vertexShaderFile,
const char *_fragmentShaderFile)
void ShaderProgGenerator::loadShaderTemplateFromFile()
{
loadStringListFromFile(_vertexShaderFile, &vertexTemplate_);
loadStringListFromFile(_fragmentShaderFile, &fragmentTemplate_);
if (!desc_.vertexTemplateFile.isEmpty())
loadStringListFromFile(desc_.vertexTemplateFile, &vertexTemplate_);
if (!desc_.fragmentTemplateFile.isEmpty())
loadStringListFromFile(desc_.fragmentTemplateFile, &fragmentTemplate_);
vertexShaderFile_ = _vertexShaderFile;
fragmentShaderFile_ = _fragmentShaderFile;
vertexShaderFile_ = desc_.vertexTemplateFile;
fragmentShaderFile_ = desc_.fragmentTemplateFile;
}
QString ShaderProgGenerator::getPathName(QString _strFileName)
......@@ -746,3 +764,8 @@ QString ShaderProgGenerator::getPathName(QString _strFileName)
QFileInfo fileInfo(_strFileName);
return fileInfo.absolutePath();
}
}
\ No newline at end of file
......@@ -5,6 +5,10 @@
#include <string>
#include <list>
namespace ACG
{
// #define MAX_SHADER_INPUT_UNITS 32
// #define MAX_SHADER_CONSTANTS 0x200
// #define MAX_SHADER_GEN_DEFINES 0x100
......@@ -36,6 +40,10 @@ struct ShaderGenDesc
bool vertexColors;
bool textured;
// optionally specify shader template file names
QString vertexTemplateFile;
QString fragmentTemplateFile;
};
//typedef std::list<std::string> StringList;
......@@ -164,19 +172,29 @@ public:
ShaderProgGenerator(ShaderGenDesc* _desc);
virtual ~ShaderProgGenerator(void);
void saveVertexShToFile(const char* _fileName);
void saveFragmentShToFile(const char* _fileName);
/**
loads external shader templates, that
returns generated vertex shader code
*/
void loadShaderTemplateFromFile(const char* _vertexShaderFile,
const char* _fragmentShaderFile);
void generateShaders();
const QStringList& getVertexShaderCode();
void saveVertexShToFile(const char* _fileName);
void saveFragmentShToFile(const char* _fileName);
/**
returns generated fragment shader code
*/
const QStringList& getFragmentShaderCode();
private:
/**
loads external shader templates
*/
void loadShaderTemplateFromFile();
void generateShaders();
void buildVertexShader();
void buildFragmentShader();
......@@ -205,7 +223,7 @@ private:
static void loadLightingFunctions();
static void loadStringListFromFile(const char* _fileName, QStringList* _out);
static void loadStringListFromFile(QString _fileName, QStringList* _out);
ShaderGenerator* vertex_;
ShaderGenerator* fragment_;
......@@ -227,3 +245,6 @@ private:
};
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment