2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** shader.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 "shader.h"
|
2013-10-09 10:30:33 +00:00
|
|
|
#include "sharedstate.h"
|
2013-09-23 05:15:01 +00:00
|
|
|
#include "glstate.h"
|
2013-12-30 00:38:10 +00:00
|
|
|
#include "exception.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-12-11 19:46:54 +00:00
|
|
|
#include <assert.h>
|
2014-07-19 14:26:42 +00:00
|
|
|
#include <string.h>
|
2013-12-30 00:38:10 +00:00
|
|
|
#include <iostream>
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-12-23 17:33:33 +00:00
|
|
|
#include "common.h.xxd"
|
2014-11-30 16:50:24 +00:00
|
|
|
#include "sprite.frag.xxd"
|
|
|
|
#include "hue.frag.xxd"
|
|
|
|
#include "trans.frag.xxd"
|
|
|
|
#include "transSimple.frag.xxd"
|
|
|
|
#include "bitmapBlit.frag.xxd"
|
|
|
|
#include "plane.frag.xxd"
|
2014-12-23 17:56:00 +00:00
|
|
|
#include "gray.frag.xxd"
|
|
|
|
#include "flatColor.frag.xxd"
|
2014-11-30 16:50:24 +00:00
|
|
|
#include "simple.frag.xxd"
|
|
|
|
#include "simpleColor.frag.xxd"
|
|
|
|
#include "simpleAlpha.frag.xxd"
|
2014-12-23 16:52:32 +00:00
|
|
|
#include "simpleAlphaUni.frag.xxd"
|
2014-11-30 16:50:24 +00:00
|
|
|
#include "flashMap.frag.xxd"
|
2014-12-23 17:56:00 +00:00
|
|
|
#include "minimal.vert.xxd"
|
2014-11-30 16:50:24 +00:00
|
|
|
#include "simple.vert.xxd"
|
|
|
|
#include "simpleColor.vert.xxd"
|
|
|
|
#include "sprite.vert.xxd"
|
|
|
|
#include "tilemap.vert.xxd"
|
|
|
|
#include "blur.frag.xxd"
|
|
|
|
#include "simpleMatrix.vert.xxd"
|
|
|
|
#include "blurH.vert.xxd"
|
|
|
|
#include "blurV.vert.xxd"
|
|
|
|
#include "tilemapvx.vert.xxd"
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
|
2013-12-30 00:38:10 +00:00
|
|
|
#define INIT_SHADER(vert, frag, name) \
|
2013-10-09 10:26:42 +00:00
|
|
|
{ \
|
2017-08-10 21:23:55 +00:00
|
|
|
Shader::init(mkxp_shader_##vert##_vert, mkxp_shader_##vert##_vert_len, mkxp_shader_##frag##_frag, mkxp_shader_##frag##_frag_len, \
|
2013-12-30 00:38:10 +00:00
|
|
|
#vert, #frag, #name); \
|
2013-10-09 10:26:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 21:01:35 +00:00
|
|
|
#define GET_U(name) u_##name = gl.GetUniformLocation(program, #name)
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-12-30 00:38:10 +00:00
|
|
|
static void printShaderLog(GLuint shader)
|
|
|
|
{
|
|
|
|
GLint logLength;
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
|
2013-12-30 00:38:10 +00:00
|
|
|
|
|
|
|
std::string log(logLength, '\0');
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.GetShaderInfoLog(shader, log.size(), 0, &log[0]);
|
2013-12-30 00:38:10 +00:00
|
|
|
|
|
|
|
std::clog << "Shader log:\n" << log;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printProgramLog(GLuint program)
|
|
|
|
{
|
|
|
|
GLint logLength;
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
|
2013-12-30 00:38:10 +00:00
|
|
|
|
|
|
|
std::string log(logLength, '\0');
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.GetProgramInfoLog(program, log.size(), 0, &log[0]);
|
2013-12-30 00:38:10 +00:00
|
|
|
|
|
|
|
std::clog << "Program log:\n" << log;
|
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
Shader::Shader()
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
vertShader = gl.CreateShader(GL_VERTEX_SHADER);
|
|
|
|
fragShader = gl.CreateShader(GL_FRAGMENT_SHADER);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
2014-05-30 21:01:35 +00:00
|
|
|
program = gl.CreateProgram();
|
2013-09-23 05:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Shader::~Shader()
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.UseProgram(0);
|
|
|
|
gl.DeleteProgram(program);
|
|
|
|
gl.DeleteShader(vertShader);
|
|
|
|
gl.DeleteShader(fragShader);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
void Shader::bind()
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-01-19 23:57:40 +00:00
|
|
|
glState.program.set(program);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
void Shader::unbind()
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.ActiveTexture(GL_TEXTURE0);
|
2014-01-19 23:57:40 +00:00
|
|
|
glState.program.set(0);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2014-12-23 17:33:33 +00:00
|
|
|
static void setupShaderSource(GLuint shader, GLenum type,
|
|
|
|
const unsigned char *body, int bodySize)
|
2014-07-19 14:26:42 +00:00
|
|
|
{
|
2014-12-23 17:33:33 +00:00
|
|
|
static const char glesDefine[] = "#define GLSLES\n";
|
|
|
|
static const char fragDefine[] = "#define FRAGMENT_SHADER\n";
|
|
|
|
|
|
|
|
const GLchar *shaderSrc[4];
|
|
|
|
GLint shaderSrcSize[4];
|
|
|
|
size_t i = 0;
|
2014-07-19 14:26:42 +00:00
|
|
|
|
|
|
|
if (gl.glsles)
|
|
|
|
{
|
2014-12-23 17:33:33 +00:00
|
|
|
shaderSrc[i] = glesDefine;
|
|
|
|
shaderSrcSize[i] = sizeof(glesDefine)-1;
|
|
|
|
++i;
|
2014-07-19 14:26:42 +00:00
|
|
|
}
|
2014-12-23 17:33:33 +00:00
|
|
|
|
|
|
|
if (type == GL_FRAGMENT_SHADER)
|
2014-07-19 14:26:42 +00:00
|
|
|
{
|
2014-12-23 17:33:33 +00:00
|
|
|
shaderSrc[i] = fragDefine;
|
|
|
|
shaderSrcSize[i] = sizeof(fragDefine)-1;
|
|
|
|
++i;
|
2014-07-19 14:26:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 21:23:55 +00:00
|
|
|
shaderSrc[i] = (const GLchar*) mkxp_shader_common_h;
|
|
|
|
shaderSrcSize[i] = mkxp_shader_common_h_len;
|
2014-12-23 17:33:33 +00:00
|
|
|
++i;
|
|
|
|
|
|
|
|
shaderSrc[i] = (const GLchar*) body;
|
|
|
|
shaderSrcSize[i] = bodySize;
|
|
|
|
++i;
|
|
|
|
|
|
|
|
gl.ShaderSource(shader, i, shaderSrc, shaderSrcSize);
|
2014-07-19 14:26:42 +00:00
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
void Shader::init(const unsigned char *vert, int vertSize,
|
2013-12-30 00:38:10 +00:00
|
|
|
const unsigned char *frag, int fragSize,
|
|
|
|
const char *vertName, const char *fragName,
|
|
|
|
const char *programName)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
|
|
|
GLint success;
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
/* Compile vertex shader */
|
2014-12-23 17:33:33 +00:00
|
|
|
setupShaderSource(vertShader, GL_VERTEX_SHADER, vert, vertSize);
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.CompileShader(vertShader);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-07-14 02:13:15 +00:00
|
|
|
gl.GetShaderiv(vertShader, GL_COMPILE_STATUS, &success);
|
2013-12-30 00:38:10 +00:00
|
|
|
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
printShaderLog(vertShader);
|
|
|
|
throw Exception(Exception::MKXPError,
|
|
|
|
"GLSL: An error occured while compiling vertex shader '%s' in program '%s'",
|
|
|
|
vertName, programName);
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
/* Compile fragment shader */
|
2014-12-23 17:33:33 +00:00
|
|
|
setupShaderSource(fragShader, GL_FRAGMENT_SHADER, frag, fragSize);
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.CompileShader(fragShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
2014-07-14 02:13:15 +00:00
|
|
|
gl.GetShaderiv(fragShader, GL_COMPILE_STATUS, &success);
|
2013-12-30 00:38:10 +00:00
|
|
|
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
printShaderLog(fragShader);
|
|
|
|
throw Exception(Exception::MKXPError,
|
|
|
|
"GLSL: An error occured while compiling fragment shader '%s' in program '%s'",
|
|
|
|
fragName, programName);
|
|
|
|
}
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
/* Link shader program */
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.AttachShader(program, vertShader);
|
|
|
|
gl.AttachShader(program, fragShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.BindAttribLocation(program, Position, "position");
|
|
|
|
gl.BindAttribLocation(program, TexCoord, "texCoord");
|
|
|
|
gl.BindAttribLocation(program, Color, "color");
|
2013-09-23 05:15:01 +00:00
|
|
|
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.LinkProgram(program);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-07-14 02:13:15 +00:00
|
|
|
gl.GetProgramiv(program, GL_LINK_STATUS, &success);
|
2013-12-30 00:38:10 +00:00
|
|
|
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
printProgramLog(program);
|
|
|
|
throw Exception(Exception::MKXPError,
|
|
|
|
"GLSL: An error occured while linking program '%s' (vertex '%s', fragment '%s')",
|
|
|
|
programName, vertName, fragName);
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 00:38:10 +00:00
|
|
|
void Shader::initFromFile(const char *_vertFile, const char *_fragFile,
|
|
|
|
const char *programName)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2013-12-11 19:46:54 +00:00
|
|
|
std::string vertContents, fragContents;
|
|
|
|
readFile(_vertFile, vertContents);
|
|
|
|
readFile(_fragFile, fragContents);
|
|
|
|
|
|
|
|
init((const unsigned char*) vertContents.c_str(), vertContents.size(),
|
2013-12-30 00:38:10 +00:00
|
|
|
(const unsigned char*) fragContents.c_str(), fragContents.size(),
|
|
|
|
_vertFile, _fragFile, programName);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
void Shader::setVec4Uniform(GLint location, const Vec4 &vec)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform4f(location, vec.x, vec.y, vec.z, vec.w);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
void Shader::setTexUniform(GLint location, unsigned unitIndex, TEX::ID texture)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
|
|
|
GLenum texUnit = GL_TEXTURE0 + unitIndex;
|
|
|
|
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.ActiveTexture(texUnit);
|
|
|
|
gl.BindTexture(GL_TEXTURE_2D, texture.gl);
|
|
|
|
gl.Uniform1i(location, unitIndex);
|
|
|
|
gl.ActiveTexture(GL_TEXTURE0);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
void ShaderBase::GLProjMat::apply(const Vec2i &value)
|
|
|
|
{
|
|
|
|
/* glOrtho replacement */
|
|
|
|
const float a = 2.f / value.x;
|
|
|
|
const float b = 2.f / value.y;
|
|
|
|
const float c = -2.f;
|
|
|
|
|
|
|
|
GLfloat mat[16] =
|
|
|
|
{
|
|
|
|
a, 0, 0, 0,
|
|
|
|
0, b, 0, 0,
|
|
|
|
0, 0, c, 0,
|
|
|
|
-1, -1, -1, 1
|
|
|
|
};
|
|
|
|
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.UniformMatrix4fv(u_mat, 1, GL_FALSE, mat);
|
2013-09-23 05:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderBase::init()
|
|
|
|
{
|
|
|
|
GET_U(texSizeInv);
|
|
|
|
GET_U(translation);
|
|
|
|
|
2014-05-30 21:01:35 +00:00
|
|
|
projMat.u_mat = gl.GetUniformLocation(program, "projMat");
|
2013-09-23 05:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderBase::applyViewportProj()
|
|
|
|
{
|
|
|
|
const IntRect &vp = glState.viewport.get();
|
|
|
|
projMat.set(Vec2i(vp.w, vp.h));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderBase::setTexSize(const Vec2i &value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform2f(u_texSizeInv, 1.f / value.x, 1.f / value.y);
|
2013-09-23 05:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderBase::setTranslation(const Vec2i &value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform2f(u_translation, value.x, value.y);
|
2013-09-23 05:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-23 17:56:00 +00:00
|
|
|
FlatColorShader::FlatColorShader()
|
|
|
|
{
|
|
|
|
INIT_SHADER(minimal, flatColor, FlatColorShader);
|
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
|
|
|
|
GET_U(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlatColorShader::setColor(const Vec4 &value)
|
|
|
|
{
|
|
|
|
setVec4Uniform(u_color, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
SimpleShader::SimpleShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(simple, simple, SimpleShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
|
|
|
|
GET_U(texOffsetX);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleShader::setTexOffsetX(int value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_texOffsetX, value);
|
2013-09-23 05:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimpleColorShader::SimpleColorShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(simpleColor, simpleColor, SimpleColorShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimpleAlphaShader::SimpleAlphaShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(simpleColor, simpleAlpha, SimpleAlphaShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimpleSpriteShader::SimpleSpriteShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(sprite, simple, SimpleSpriteShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
|
|
|
|
GET_U(spriteMat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleSpriteShader::setSpriteMat(const float value[16])
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.UniformMatrix4fv(u_spriteMat, 1, GL_FALSE, value);
|
2013-09-23 05:15:01 +00:00
|
|
|
}
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-12-23 16:52:32 +00:00
|
|
|
AlphaSpriteShader::AlphaSpriteShader()
|
|
|
|
{
|
|
|
|
INIT_SHADER(sprite, simpleAlphaUni, AlphaSpriteShader);
|
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
|
|
|
|
GET_U(spriteMat);
|
|
|
|
GET_U(alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlphaSpriteShader::setSpriteMat(const float value[16])
|
|
|
|
{
|
|
|
|
gl.UniformMatrix4fv(u_spriteMat, 1, GL_FALSE, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlphaSpriteShader::setAlpha(float value)
|
|
|
|
{
|
|
|
|
gl.Uniform1f(u_alpha, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
TransShader::TransShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(simple, trans, TransShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
GET_U(currentScene);
|
|
|
|
GET_U(frozenScene);
|
|
|
|
GET_U(transMap);
|
|
|
|
GET_U(prog);
|
|
|
|
GET_U(vague);
|
|
|
|
}
|
|
|
|
|
2013-09-06 10:26:41 +00:00
|
|
|
void TransShader::setCurrentScene(TEX::ID tex)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-07-16 02:48:40 +00:00
|
|
|
setTexUniform(u_currentScene, 1, tex);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-06 10:26:41 +00:00
|
|
|
void TransShader::setFrozenScene(TEX::ID tex)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-07-16 02:48:40 +00:00
|
|
|
setTexUniform(u_frozenScene, 2, tex);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-06 10:26:41 +00:00
|
|
|
void TransShader::setTransMap(TEX::ID tex)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-07-16 02:48:40 +00:00
|
|
|
setTexUniform(u_transMap, 3, tex);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransShader::setProg(float value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_prog, value);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransShader::setVague(float value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_vague, value);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimpleTransShader::SimpleTransShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(simple, transSimple, SimpleTransShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
GET_U(currentScene);
|
|
|
|
GET_U(frozenScene);
|
|
|
|
GET_U(prog);
|
|
|
|
}
|
|
|
|
|
2013-09-06 10:26:41 +00:00
|
|
|
void SimpleTransShader::setCurrentScene(TEX::ID tex)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-07-16 02:48:40 +00:00
|
|
|
setTexUniform(u_currentScene, 1, tex);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-06 10:26:41 +00:00
|
|
|
void SimpleTransShader::setFrozenScene(TEX::ID tex)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-07-16 02:48:40 +00:00
|
|
|
setTexUniform(u_frozenScene, 2, tex);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTransShader::setProg(float value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_prog, value);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SpriteShader::SpriteShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(sprite, sprite, SpriteShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
GET_U(spriteMat);
|
2013-09-01 14:27:21 +00:00
|
|
|
GET_U(tone);
|
|
|
|
GET_U(color);
|
|
|
|
GET_U(opacity);
|
|
|
|
GET_U(bushDepth);
|
|
|
|
GET_U(bushOpacity);
|
|
|
|
}
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
void SpriteShader::setSpriteMat(const float value[16])
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.UniformMatrix4fv(u_spriteMat, 1, GL_FALSE, value);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteShader::setTone(const Vec4 &tone)
|
|
|
|
{
|
|
|
|
setVec4Uniform(u_tone, tone);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteShader::setColor(const Vec4 &color)
|
|
|
|
{
|
|
|
|
setVec4Uniform(u_color, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteShader::setOpacity(float value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_opacity, value);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteShader::setBushDepth(float value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_bushDepth, value);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteShader::setBushOpacity(float value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_bushOpacity, value);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
PlaneShader::PlaneShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(simple, plane, PlaneShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
|
|
|
|
GET_U(tone);
|
|
|
|
GET_U(color);
|
|
|
|
GET_U(flash);
|
|
|
|
GET_U(opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaneShader::setTone(const Vec4 &tone)
|
|
|
|
{
|
|
|
|
setVec4Uniform(u_tone, tone);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaneShader::setColor(const Vec4 &color)
|
|
|
|
{
|
|
|
|
setVec4Uniform(u_color, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaneShader::setFlash(const Vec4 &flash)
|
|
|
|
{
|
|
|
|
setVec4Uniform(u_flash, flash);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaneShader::setOpacity(float value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_opacity, value);
|
2013-09-23 05:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-23 17:56:00 +00:00
|
|
|
GrayShader::GrayShader()
|
|
|
|
{
|
|
|
|
INIT_SHADER(simple, gray, GrayShader);
|
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
|
|
|
|
GET_U(gray);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrayShader::setGray(float value)
|
|
|
|
{
|
|
|
|
gl.Uniform1f(u_gray, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Tilemap: Use vertex shader based autotile animation strategy
Previously, we would just stuff the entire tilemap vertex data
four times into the buffers, with only the autotile vertices
offset according to the animation frame. This meant we could
prepare the buffers once, and then just bind a different offset
for each animation frame without any shader changes, but it also
lead to a huge amount of data being duplicated (and blowing up
the buffer sizes).
The new method only requires one buffer, and instead animates by
recognizing vertices belonging to autotiles in a custom vertex
shader, which offsets them on the fly according to the animation
index.
With giant tilemaps, this method would turn out to be a little
less efficient, but considering the Tilemap is planned to be
rewritten to only hold the range of tiles visible on the screen
in its buffers, the on the fly offsetting will become neglient,
while at the same time the amount of data we have to send to the
GPU everytime the tilemap is updated is greatly reduced; so a
net win in the end.
2014-07-06 17:44:19 +00:00
|
|
|
TilemapShader::TilemapShader()
|
|
|
|
{
|
|
|
|
INIT_SHADER(tilemap, simple, TilemapShader);
|
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
|
|
|
|
GET_U(aniIndex);
|
2019-05-12 15:52:05 +00:00
|
|
|
GET_U(t1Ani);
|
|
|
|
GET_U(t2Ani);
|
|
|
|
GET_U(t3Ani);
|
|
|
|
GET_U(t4Ani);
|
|
|
|
GET_U(t5Ani);
|
|
|
|
GET_U(t6Ani);
|
|
|
|
GET_U(t7Ani);
|
Tilemap: Use vertex shader based autotile animation strategy
Previously, we would just stuff the entire tilemap vertex data
four times into the buffers, with only the autotile vertices
offset according to the animation frame. This meant we could
prepare the buffers once, and then just bind a different offset
for each animation frame without any shader changes, but it also
lead to a huge amount of data being duplicated (and blowing up
the buffer sizes).
The new method only requires one buffer, and instead animates by
recognizing vertices belonging to autotiles in a custom vertex
shader, which offsets them on the fly according to the animation
index.
With giant tilemaps, this method would turn out to be a little
less efficient, but considering the Tilemap is planned to be
rewritten to only hold the range of tiles visible on the screen
in its buffers, the on the fly offsetting will become neglient,
while at the same time the amount of data we have to send to the
GPU everytime the tilemap is updated is greatly reduced; so a
net win in the end.
2014-07-06 17:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TilemapShader::setAniIndex(int value)
|
|
|
|
{
|
|
|
|
gl.Uniform1f(u_aniIndex, value);
|
|
|
|
}
|
|
|
|
|
2019-05-12 15:52:05 +00:00
|
|
|
void TilemapShader::setAniIndices(int value[])
|
|
|
|
{
|
|
|
|
gl.Uniform1f(u_t1Ani, value[0]);
|
|
|
|
gl.Uniform1f(u_t2Ani, value[1]);
|
|
|
|
gl.Uniform1f(u_t3Ani, value[2]);
|
|
|
|
gl.Uniform1f(u_t4Ani, value[3]);
|
|
|
|
gl.Uniform1f(u_t5Ani, value[4]);
|
|
|
|
gl.Uniform1f(u_t6Ani, value[5]);
|
|
|
|
gl.Uniform1f(u_t7Ani, value[6]);
|
|
|
|
}
|
Tilemap: Use vertex shader based autotile animation strategy
Previously, we would just stuff the entire tilemap vertex data
four times into the buffers, with only the autotile vertices
offset according to the animation frame. This meant we could
prepare the buffers once, and then just bind a different offset
for each animation frame without any shader changes, but it also
lead to a huge amount of data being duplicated (and blowing up
the buffer sizes).
The new method only requires one buffer, and instead animates by
recognizing vertices belonging to autotiles in a custom vertex
shader, which offsets them on the fly according to the animation
index.
With giant tilemaps, this method would turn out to be a little
less efficient, but considering the Tilemap is planned to be
rewritten to only hold the range of tiles visible on the screen
in its buffers, the on the fly offsetting will become neglient,
while at the same time the amount of data we have to send to the
GPU everytime the tilemap is updated is greatly reduced; so a
net win in the end.
2014-07-06 17:44:19 +00:00
|
|
|
|
|
|
|
|
2013-09-23 06:27:28 +00:00
|
|
|
FlashMapShader::FlashMapShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(simpleColor, flashMap, FlashMapShader);
|
2013-09-23 06:27:28 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
|
|
|
|
GET_U(alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlashMapShader::setAlpha(float value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_alpha, value);
|
2013-09-23 06:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
HueShader::HueShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(simple, hue, HueShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
GET_U(hueAdjust);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HueShader::setHueAdjust(float value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_hueAdjust, value);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 20:40:09 +00:00
|
|
|
SimpleMatrixShader::SimpleMatrixShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(simpleMatrix, simpleAlpha, SimpleMatrixShader);
|
2013-10-02 20:40:09 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
|
|
|
|
GET_U(matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleMatrixShader::setMatrix(const float value[16])
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.UniformMatrix4fv(u_matrix, 1, GL_FALSE, value);
|
2013-10-02 20:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-01 16:10:43 +00:00
|
|
|
BlurShader::HPass::HPass()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(blurH, blur, BlurShader::HPass);
|
2013-10-01 16:10:43 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
BlurShader::VPass::VPass()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(blurV, blur, BlurShader::VPass);
|
2013-10-01 16:10:43 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:59:28 +00:00
|
|
|
|
|
|
|
TilemapVXShader::TilemapVXShader()
|
|
|
|
{
|
|
|
|
INIT_SHADER(tilemapvx, simple, TilemapVXShader);
|
|
|
|
|
|
|
|
ShaderBase::init();
|
|
|
|
|
|
|
|
GET_U(aniOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TilemapVXShader::setAniOffset(const Vec2 &value)
|
|
|
|
{
|
|
|
|
gl.Uniform2f(u_aniOffset, value.x, value.y);
|
|
|
|
}
|
|
|
|
|
2013-10-01 16:10:43 +00:00
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
BltShader::BltShader()
|
|
|
|
{
|
2013-12-30 00:38:10 +00:00
|
|
|
INIT_SHADER(simple, bitmapBlit, BltShader);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
ShaderBase::init();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
GET_U(source);
|
|
|
|
GET_U(destination);
|
|
|
|
GET_U(subRect);
|
|
|
|
GET_U(opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BltShader::setSource()
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1i(u_source, 0);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-06 10:26:41 +00:00
|
|
|
void BltShader::setDestination(const TEX::ID value)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
|
|
|
setTexUniform(u_destination, 1, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BltShader::setSubRect(const FloatRect &value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform4f(u_subRect, value.x, value.y, value.w, value.h);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BltShader::setOpacity(float value)
|
|
|
|
{
|
2014-05-30 21:01:35 +00:00
|
|
|
gl.Uniform1f(u_opacity, value);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|