our_dick/include/ttt/font_shader.hpp
rexy712 e0924c5895 I forgot to commit for a while so there's a lot in here.
Added ubo class template for handling Uniform Buffer Objects. This class automatically finds the offset and alignment for given data in a GLSL std140 uniform block. This makes it easy to just assign data through the gfx::ubo interface and bind that to the relevant shader_program's uniform block
Changed shader_program's method of handling uniforms to match more closely to how vao handles its attributes. That is to call  with the location as argument to get a proxy object on which to operate. I find this nicer to work with than having everything to do with uniforms in the shader_program class itself
Add a flat_camera class which just assigns the near and far plane to 0 and 1 respectively
Start work on a gui system which i'm really not confident about.
Attempting to rethink how renderers work, but also no really confident about where i'm going with it
Break out vbo_scoped_map into a more general scoped_buffer_map class so that vbo and ubo can utilize it
Remove old gl_buffers units that were not really being used since my change over to opengl DSA functions
Change the gfx::resource_manager to keep shared_ptr's in the container so the data can be more nicely shared
Add missing aliases in math::fwd_declare.hpp for boolean types
Change orthographic projection generator function to have the z values behave more in line with how opengl handles z depth. May have to undo this at some point but it seems to behave correctly now
Fix some rvalue related aspects of util::deferred
'
2022-02-04 13:49:22 -08:00

148 lines
4.2 KiB
C++

/**
This file is a part of our_dick
Copyright (C) 2022 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_FONT_SHADER_HPP
#define OUR_DICK_FONT_SHADER_HPP
namespace font_shader{
static constexpr char vertex_shader_text[] =
R"glsl(
#version 430 core
layout (location = 0) in vec4 tex_coords;
layout (location = 1) in vec4 color;
layout (location = 2) in vec2 offset;
layout (location = 3) in vec2 size;
out VS_OUT{
vec4 tex_coords;
vec4 color;
vec2 offset;
vec2 size;
}vs_out;
void main(){
vs_out.tex_coords = tex_coords;
vs_out.color = color;
vs_out.offset = offset;
vs_out.size = size;
}
)glsl";
static constexpr char geometry_shader_text[] =
R"glsl(
#version 430 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
in VS_OUT{
vec4 tex_coords;
vec4 color;
vec2 offset;
vec2 size;
}gs_in[];
out GS_OUT{
vec2 tex_coords;
flat vec4 color;
}gs_out;
layout (std140) uniform view_proj_matrix{
mat4 vp_mat;
};
uniform vec2 start_pos;
void main(){
//texture coordinates need done botleft->topleft->botright->topright
//whereas the position goes topleft->botleft->topright->botright
//because freetype generates bitmaps with inverse y axis to opengl
const vec4 position = vec4(gs_in[0].offset, -1, 1);
const mat2 scaler = mat2(vp_mat[0][0], vp_mat[0][1], vp_mat[1][0], vp_mat[1][1]);
const vec2 start_position = scaler * start_pos;
const vec2 screen_pos = start_position + (scaler * gs_in[0].offset);
const vec2 size = scaler * gs_in[0].size;
const mat4 scale = vp_mat;
const vec4 p1 = scale * vec4(gs_in[0].offset.x, gs_in[0].offset.y + gs_in[0].size.y, -1, 1);
const vec4 p2 = scale * vec4(gs_in[0].offset, -1, 1);
const vec4 p3 = scale * vec4(gs_in[0].offset.x + gs_in[0].size.x, gs_in[0].offset.y + gs_in[0].size.y, -1, 1);
const vec4 p4 = scale * vec4(gs_in[0].offset.x + gs_in[0].size.x, gs_in[0].offset.y, -1, 1);
gl_Position = p1;
gs_out.tex_coords = gs_in[0].tex_coords.xy;
gs_out.color = gs_in[0].color;
EmitVertex();
gl_Position = p2;
gs_out.tex_coords = gs_in[0].tex_coords.xw;
gs_out.color = gs_in[0].color;
EmitVertex();
gl_Position = p3;
gs_out.tex_coords = gs_in[0].tex_coords.zy;
gs_out.color = gs_in[0].color;
EmitVertex();
gl_Position = p4;
gs_out.tex_coords = gs_in[0].tex_coords.zw;
gs_out.color = gs_in[0].color;
EmitVertex();
/* gl_Position = vec4(screen_pos.x, screen_pos.y + size.y, -1.0, 1.0);
gs_out.tex_coords = gs_in[0].tex_coords.xy;
gs_out.color = gs_in[0].color;
EmitVertex();
gl_Position = vec4(screen_pos, -1.0, 1.0);
gs_out.tex_coords = gs_in[0].tex_coords.xw;
gs_out.color = gs_in[0].color;
EmitVertex();
gl_Position = vec4(screen_pos.x + size.x, screen_pos.y + size.y, -1.0, 1.0);
gs_out.tex_coords = gs_in[0].tex_coords.zy;
gs_out.color = gs_in[0].color;
EmitVertex();
gl_Position = vec4(screen_pos.x + size.x, screen_pos.y, -1.0, 1.0);
gs_out.tex_coords = gs_in[0].tex_coords.zw;
gs_out.color = gs_in[0].color;
EmitVertex();
*/
EndPrimitive();
}
)glsl";
static constexpr char fragment_shader_text[] =
R"glsl(
#version 430 core
out vec4 frag_color;
in GS_OUT{
vec2 tex_coords;
flat vec4 color;
}fs_in;
uniform sampler2D texture1;
void main(){
vec4 s = texture(texture1, fs_in.tex_coords);
float alpha = (s.r + s.g + s.b) / 3.0;
vec4 alpha_texture = vec4(s.rgb, alpha);
frag_color = alpha_texture * fs_in.color; //NOT the dot product in glsl
}
)glsl";
}
#endif