moved Sprite Batcher's default shader to Renderer; no longer a global var

This commit is contained in:
Noel Berry
2022-02-10 01:13:20 -08:00
parent 2619d2d9e0
commit f56e3bb2b2
8 changed files with 167 additions and 216 deletions

View File

@ -343,6 +343,51 @@ typedef void (APIENTRY* DEBUGPROC)(GLenum source,
namespace Blah
{
const ShaderData opengl_batch_shader_data = {
// vertex shader
#ifdef __EMSCRIPTEN__
"#version 300 es\n"
#else
"#version 330\n"
#endif
"uniform mat4 u_matrix;\n"
"layout(location=0) in vec2 a_position;\n"
"layout(location=1) in vec2 a_tex;\n"
"layout(location=2) in vec4 a_color;\n"
"layout(location=3) in vec4 a_type;\n"
"out vec2 v_tex;\n"
"out vec4 v_col;\n"
"out vec4 v_type;\n"
"void main(void)\n"
"{\n"
" gl_Position = u_matrix * vec4(a_position.xy, 0, 1);\n"
" v_tex = a_tex;\n"
" v_col = a_color;\n"
" v_type = a_type;\n"
"}",
// fragment shader
#ifdef __EMSCRIPTEN__
"#version 300 es\n"
"precision mediump float;\n"
#else
"#version 330\n"
#endif
"uniform sampler2D u_texture;\n"
"in vec2 v_tex;\n"
"in vec4 v_col;\n"
"in vec4 v_type;\n"
"out vec4 o_color;\n"
"void main(void)\n"
"{\n"
" vec4 color = texture(u_texture, v_tex);\n"
" o_color = \n"
" v_type.x * color * v_col + \n"
" v_type.y * color.a * v_col + \n"
" v_type.z * v_col;\n"
"}"
};
class Renderer_OpenGL : public Renderer
{
public:
@ -1158,6 +1203,9 @@ namespace Blah
features.origin_bottom_left = true;
features.max_texture_size = max_texture_size;
// create the default batch shader
default_batcher_shader = Shader::create(opengl_batch_shader_data);
return true;
}