2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** glstate.h
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
|
|
**
|
|
|
|
** mkxp 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.
|
|
|
|
**
|
|
|
|
** mkxp 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 mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GLSTATE_H
|
|
|
|
#define GLSTATE_H
|
|
|
|
|
|
|
|
#include "etc.h"
|
2013-12-27 19:10:01 +00:00
|
|
|
|
|
|
|
#include <stack>
|
2014-07-20 11:15:03 +00:00
|
|
|
#include <assert.h>
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2017-04-23 10:28:34 +00:00
|
|
|
struct Config;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
template<typename T>
|
|
|
|
struct GLProperty
|
|
|
|
{
|
2014-07-20 11:15:03 +00:00
|
|
|
~GLProperty()
|
|
|
|
{
|
|
|
|
assert(stack.size() == 0);
|
|
|
|
}
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
void init(const T &value)
|
|
|
|
{
|
|
|
|
current = value;
|
|
|
|
apply(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void push() { stack.push(current); }
|
2013-12-27 19:10:01 +00:00
|
|
|
void pop() { set(stack.top()); stack.pop(); }
|
2014-12-24 04:37:26 +00:00
|
|
|
const T &get() { return current; }
|
2013-09-01 14:27:21 +00:00
|
|
|
void set(const T &value)
|
|
|
|
{
|
|
|
|
if (value == current)
|
|
|
|
return;
|
|
|
|
|
|
|
|
init(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pushSet(const T &value)
|
|
|
|
{
|
|
|
|
push();
|
|
|
|
set(value);
|
|
|
|
}
|
|
|
|
|
2014-01-01 00:56:20 +00:00
|
|
|
void refresh()
|
|
|
|
{
|
|
|
|
apply(current);
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
private:
|
|
|
|
virtual void apply(const T &value) = 0;
|
|
|
|
|
|
|
|
T current;
|
2013-12-27 19:10:01 +00:00
|
|
|
std::stack<T> stack;
|
2013-09-01 14:27:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GLClearColor : public GLProperty<Vec4>
|
|
|
|
{
|
|
|
|
void apply(const Vec4 &);
|
|
|
|
};
|
|
|
|
|
|
|
|
class GLScissorBox : public GLProperty<IntRect>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/* Sets the intersection of the current box with value */
|
|
|
|
void setIntersect(const IntRect &value);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void apply(const IntRect &value);
|
|
|
|
};
|
|
|
|
|
|
|
|
class GLScissorTest : public GLProperty<bool>
|
|
|
|
{
|
|
|
|
void apply(const bool &value);
|
|
|
|
};
|
|
|
|
|
|
|
|
class GLBlendMode : public GLProperty<BlendType>
|
|
|
|
{
|
|
|
|
void apply(const BlendType &value);
|
|
|
|
};
|
|
|
|
|
2014-07-20 11:17:12 +00:00
|
|
|
class GLBlend : public GLProperty<bool>
|
|
|
|
{
|
|
|
|
void apply(const bool &value);
|
|
|
|
};
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
class GLViewport : public GLProperty<IntRect>
|
|
|
|
{
|
|
|
|
void apply(const IntRect &value);
|
|
|
|
};
|
|
|
|
|
2014-01-19 23:57:40 +00:00
|
|
|
class GLProgram : public GLProperty<unsigned int> /* GLuint */
|
|
|
|
{
|
|
|
|
void apply(const unsigned int &value);
|
|
|
|
};
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
class GLState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GLClearColor clearColor;
|
|
|
|
GLScissorBox scissorBox;
|
|
|
|
GLScissorTest scissorTest;
|
|
|
|
GLBlendMode blendMode;
|
2014-07-20 11:17:12 +00:00
|
|
|
GLBlend blend;
|
2013-09-01 14:27:21 +00:00
|
|
|
GLViewport viewport;
|
2014-01-19 23:57:40 +00:00
|
|
|
GLProgram program;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
struct Caps
|
|
|
|
{
|
|
|
|
int maxTexSize;
|
|
|
|
|
|
|
|
Caps();
|
|
|
|
|
|
|
|
} caps;
|
|
|
|
|
2017-04-23 10:28:34 +00:00
|
|
|
GLState(const Config &conf);
|
2013-09-01 14:27:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GLSTATE_H
|