2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** glstate.cpp
|
|
|
|
**
|
|
|
|
** 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "glstate.h"
|
2014-01-19 23:57:40 +00:00
|
|
|
#include "shader.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
#include "etc.h"
|
2014-05-30 21:01:35 +00:00
|
|
|
#include "gl-fun.h"
|
2013-12-04 16:48:37 +00:00
|
|
|
|
|
|
|
#include <SDL_rect.h>
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
void GLClearColor::apply(const Vec4 &value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.ClearColor(value.x, value.y, value.z, value.w);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLScissorBox::apply(const IntRect &value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Scissor(value.x, value.y, value.w, value.h);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLScissorBox::setIntersect(const IntRect &value)
|
|
|
|
{
|
|
|
|
IntRect ¤t = get();
|
|
|
|
|
|
|
|
SDL_Rect r1 = { current.x, current.y, current.w, current.h };
|
|
|
|
SDL_Rect r2 = { value.x, value.y, value.w, value.h };
|
|
|
|
|
|
|
|
SDL_Rect result;
|
|
|
|
if (!SDL_IntersectRect(&r1, &r2, &result))
|
|
|
|
result.w = result.h = 0;
|
|
|
|
|
|
|
|
set(IntRect(result.x, result.y, result.w, result.h));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLScissorTest::apply(const bool &value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
value ? gl.Enable(GL_SCISSOR_TEST) : gl.Disable(GL_SCISSOR_TEST);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLBlendMode::apply(const BlendType &value)
|
|
|
|
{
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case BlendNone :
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.BlendEquation(GL_FUNC_ADD);
|
|
|
|
gl.BlendFunc(GL_ONE, GL_ZERO);
|
2013-09-01 14:27:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlendNormal :
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.BlendEquation(GL_FUNC_ADD);
|
|
|
|
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
|
|
|
|
GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2013-09-01 14:27:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlendAddition :
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.BlendEquation(GL_FUNC_ADD);
|
|
|
|
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
|
|
|
|
GL_ONE, GL_ONE);
|
2013-09-01 14:27:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlendSubstraction :
|
|
|
|
// FIXME Alpha calculation is untested
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.BlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
|
|
|
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
|
|
|
|
GL_ONE, GL_ONE);
|
2013-09-01 14:27:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewport::apply(const IntRect &value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Viewport(value.x, value.y, value.w, value.h);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2014-01-19 23:57:40 +00:00
|
|
|
void GLProgram::apply(const unsigned int &value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.UseProgram(value);
|
2014-01-19 23:57:40 +00:00
|
|
|
}
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
GLState::Caps::Caps()
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.GetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLState::GLState()
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Enable(GL_BLEND);
|
|
|
|
gl.Disable(GL_DEPTH_TEST);
|
2013-09-04 19:05:47 +00:00
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
clearColor.init(Vec4(0, 0, 0, 1));
|
|
|
|
blendMode.init(BlendNormal);
|
|
|
|
scissorTest.init(false);
|
|
|
|
scissorBox.init(IntRect(0, 0, 640, 480));
|
2014-01-19 23:57:40 +00:00
|
|
|
program.init(0);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|