Set and update scissorbox based on current render resolution

This commit is contained in:
Roza 2020-02-26 13:28:51 -05:00
parent 1434e9e313
commit 85a8d7cfb7
2 changed files with 783 additions and 958 deletions

View file

@ -20,109 +20,88 @@
*/
#include "glstate.h"
#include "shader.h"
#include "config.h"
#include "etc.h"
#include "gl-fun.h"
#include "config.h"
#include "shader.h"
#include <SDL_rect.h>
static void applyBool(GLenum state, bool mode)
{
mode ? gl.Enable(state) : gl.Disable(state);
static void applyBool(GLenum state, bool mode) {
mode ? gl.Enable(state) : gl.Disable(state);
}
void GLClearColor::apply(const Vec4 &value)
{
gl.ClearColor(value.x, value.y, value.z, value.w);
void GLClearColor::apply(const Vec4 &value) {
gl.ClearColor(value.x, value.y, value.z, value.w);
}
void GLScissorBox::apply(const IntRect &value)
{
gl.Scissor(value.x, value.y, value.w, value.h);
void GLScissorBox::apply(const IntRect &value) {
gl.Scissor(value.x, value.y, value.w, value.h);
}
void GLScissorBox::setIntersect(const IntRect &value)
{
const IntRect &current = get();
void GLScissorBox::setIntersect(const IntRect &value) {
const IntRect &current = 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 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;
SDL_Rect result;
if (!SDL_IntersectRect(&r1, &r2, &result))
result.w = result.h = 0;
set(IntRect(result.x, result.y, result.w, result.h));
set(IntRect(result.x, result.y, result.w, result.h));
}
void GLScissorTest::apply(const bool &value)
{
applyBool(GL_SCISSOR_TEST, value);
void GLScissorTest::apply(const bool &value) {
applyBool(GL_SCISSOR_TEST, value);
}
void GLBlendMode::apply(const BlendType &value)
{
switch (value)
{
case BlendKeepDestAlpha :
gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
GL_ZERO, GL_ONE);
break;
void GLBlendMode::apply(const BlendType &value) {
switch (value) {
case BlendKeepDestAlpha:
gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
break;
case BlendNormal :
gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
break;
case BlendNormal:
gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE,
GL_ONE_MINUS_SRC_ALPHA);
break;
case BlendAddition :
gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
GL_ONE, GL_ONE);
break;
case BlendAddition:
gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE);
break;
case BlendSubstraction :
// FIXME Alpha calculation is untested
gl.BlendEquation(GL_FUNC_REVERSE_SUBTRACT);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
GL_ONE, GL_ONE);
break;
}
case BlendSubstraction:
// FIXME Alpha calculation is untested
gl.BlendEquation(GL_FUNC_REVERSE_SUBTRACT);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE);
break;
}
}
void GLBlend::apply(const bool &value)
{
applyBool(GL_BLEND, value);
void GLBlend::apply(const bool &value) { applyBool(GL_BLEND, value); }
void GLViewport::apply(const IntRect &value) {
gl.Viewport(value.x, value.y, value.w, value.h);
}
void GLViewport::apply(const IntRect &value)
{
gl.Viewport(value.x, value.y, value.w, value.h);
}
void GLProgram::apply(const unsigned int &value)
{
gl.UseProgram(value);
}
GLState::Caps::Caps()
{
gl.GetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
}
GLState::GLState(const Config &conf)
{
gl.Disable(GL_DEPTH_TEST);
clearColor.init(Vec4(0, 0, 0, 1));
blendMode.init(BlendNormal);
blend.init(true);
scissorTest.init(false);
scissorBox.init(IntRect(0, 0, 640, 480));
program.init(0);
if (conf.maxTextureSize > 0)
caps.maxTexSize = conf.maxTextureSize;
void GLProgram::apply(const unsigned int &value) { gl.UseProgram(value); }
GLState::Caps::Caps() { gl.GetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize); }
GLState::GLState(const Config &conf) {
gl.Disable(GL_DEPTH_TEST);
clearColor.init(Vec4(0, 0, 0, 1));
blendMode.init(BlendNormal);
blend.init(true);
scissorTest.init(false);
scissorBox.init(IntRect(0, 0, conf.defScreenW, conf.defScreenH));
program.init(0);
if (conf.maxTextureSize > 0)
caps.maxTexSize = conf.maxTextureSize;
}

File diff suppressed because it is too large Load diff