Skip to content

Commit

Permalink
Refactor|Model Renderer: Moved shader variables to another source file
Browse files Browse the repository at this point in the history
Shader variables are not specific to models in any way.
  • Loading branch information
skyjake committed Jun 1, 2016
1 parent d32bf0c commit 11bb878
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 273 deletions.
81 changes: 81 additions & 0 deletions doomsday/apps/client/include/render/shadervar.h
@@ -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
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/render/model.cpp
Expand Up @@ -29,12 +29,12 @@ Model::AnimSequence::AnimSequence(String const &name, Record const &def)
, def(&def)
{
// Parse timeline events.
if(def.hasSubrecord(DEF_TIMELINE))
if (def.hasSubrecord(DEF_TIMELINE))
{
timeline = new Scheduler;
timeline->addFromInfo(def.subrecord(DEF_TIMELINE));
}
else if(def.hasMember(DEF_TIMELINE))
else if (def.hasMember(DEF_TIMELINE))
{
// Uses a shared timeline in the definition. This will be looked up when
// the animation starts.
Expand All @@ -46,7 +46,7 @@ Model::~Model()
{
// The commit group will be deleted now.
unsetAtlas();

qDeleteAll(timelines.values());
}

Expand Down

0 comments on commit 11bb878

Please sign in to comment.