Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor|Model Renderer: Moved shader variables to another source file
Shader variables are not specific to models in any way.
- Loading branch information
Showing
6 changed files
with
372 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** @file render/shadervar.h | ||
* | ||
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef DENG_CLIENT_RENDER_SHADERVAR_H | ||
#define DENG_CLIENT_RENDER_SHADERVAR_H | ||
|
||
#include <de/Animation> | ||
#include <de/GLUniform> | ||
#include <de/Range> | ||
#include <QList> | ||
|
||
/** | ||
* Animatable variable bound to a GL uniform. The value can have 1...4 float | ||
* components. | ||
*/ | ||
struct ShaderVar | ||
{ | ||
struct Value { | ||
de::Animation anim; | ||
de::Rangef wrap; | ||
|
||
Value(de::Animation const &a) : anim(a) {} | ||
}; | ||
QList<Value> values; | ||
de::GLUniform *uniform = nullptr; // owned | ||
|
||
public: | ||
virtual ~ShaderVar(); | ||
|
||
void init(float value); | ||
|
||
template <typename VecType> | ||
void init(VecType const &vec) | ||
{ | ||
values.clear(); | ||
for (int i = 0; i < vec.size(); ++i) | ||
{ | ||
values.append(de::Animation(vec[i], de::Animation::Linear)); | ||
} | ||
} | ||
|
||
float currentValue(int index) const; | ||
|
||
/** | ||
* Copies the current values to the uniform. | ||
*/ | ||
void updateUniform(); | ||
}; | ||
|
||
struct ShaderVars | ||
{ | ||
QHash<de::String, ShaderVar *> members; | ||
|
||
DENG2_ERROR(DefinitionError); | ||
|
||
public: | ||
virtual ~ShaderVars(); | ||
|
||
void initVariableFromDefinition(de::String const &variableName, | ||
de::Record const &valueDef, | ||
de::Record &bindingNames); | ||
|
||
void addBinding(de::Record &names, de::String const &varName, de::Animation &anim); | ||
}; | ||
|
||
#endif // DENG_CLIENT_RENDER_SHADERVAR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.