Remove need to know the shader type from pause_state. Moves rendering api dependance elsewhere
This commit is contained in:
parent
621bf0349a
commit
f7c0b4a177
@ -20,6 +20,7 @@
|
||||
#define OUR_DICK_GRAPHICS_OGL_SHADER_HPP
|
||||
|
||||
#include "gl_include.hpp"
|
||||
#include "wip/shader_source.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace gfx::ogl{
|
||||
@ -29,7 +30,7 @@ namespace gfx::ogl{
|
||||
{
|
||||
public:
|
||||
//Strongly typed enum of possible shader types
|
||||
enum class type : GLuint{
|
||||
enum class type : unsigned int{
|
||||
FRAGMENT = GL_FRAGMENT_SHADER,
|
||||
VERTEX = GL_VERTEX_SHADER,
|
||||
GEOMETRY = GL_GEOMETRY_SHADER,
|
||||
@ -43,8 +44,9 @@ namespace gfx::ogl{
|
||||
public:
|
||||
//initialize this shader with the type 't' and add no source text
|
||||
explicit shader(type t);
|
||||
//initialize this shader with the type 't't and load in 'data' as source text
|
||||
//initialize this shader with the type 't' and load in 'data' as source text
|
||||
shader(const char* data, type t);
|
||||
shader(const wip::gfx::shader_source&);
|
||||
shader(const shader&);
|
||||
shader(shader&&);
|
||||
~shader(void);
|
||||
|
||||
@ -19,50 +19,11 @@
|
||||
#ifndef OUR_DICK_GRAPHICS_WIP_BASE_SHADER_HPP
|
||||
#define OUR_DICK_GRAPHICS_WIP_BASE_SHADER_HPP
|
||||
|
||||
namespace wip::gfx::base_shader{
|
||||
#include "ogl_base_shader.hpp"
|
||||
|
||||
static constexpr char vertex_shader_text[] =
|
||||
R"glsl(
|
||||
#version 430 core
|
||||
|
||||
layout (location = 0) in vec3 position;
|
||||
layout (location = 1) in vec2 tex_coords;
|
||||
|
||||
|
||||
layout (std140) uniform mvp_matrix{
|
||||
mat4 vp_mat;
|
||||
mat4 model_mat;
|
||||
};
|
||||
|
||||
out VS_OUT{
|
||||
vec2 tex_coords;
|
||||
}vs_out;
|
||||
|
||||
const vec4 vertices[6] = vec4[](vec4(0,1,0,1), vec4(0,0,0,1), vec4(1,0,0,1), vec4(1,0,0,1), vec4(1,1,0,1), vec4(0,1,0,1));
|
||||
|
||||
void main(){
|
||||
gl_Position = vp_mat * model_mat * vec4(position, 1);
|
||||
vs_out.tex_coords = tex_coords;
|
||||
}
|
||||
)glsl";
|
||||
|
||||
static constexpr char fragment_shader_text[] =
|
||||
R"glsl(
|
||||
#version 430 core
|
||||
|
||||
in VS_OUT{
|
||||
vec2 tex_coords;
|
||||
}fs_in;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
uniform sampler2D diffuse_texture;
|
||||
|
||||
void main(){
|
||||
frag_color = texture(diffuse_texture, fs_in.tex_coords);;
|
||||
}
|
||||
)glsl";
|
||||
namespace wip::gfx{
|
||||
|
||||
using base_shader = ogl::base_shader;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
87
include/wip/ogl_base_shader.hpp
Normal file
87
include/wip/ogl_base_shader.hpp
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
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_GRAPHICS_WIP_OGL_BASE_SHADER_HPP
|
||||
#define OUR_DICK_GRAPHICS_WIP_OGL_BASE_SHADER_HPP
|
||||
|
||||
#include "shader_source.hpp"
|
||||
#include "gfx/ogl/shader.hpp"
|
||||
|
||||
namespace wip::gfx::ogl{
|
||||
|
||||
class base_shader
|
||||
{
|
||||
public:
|
||||
static inline constexpr shader_source sources[] = {
|
||||
{
|
||||
.text =
|
||||
R"glsl(
|
||||
#version 430 core
|
||||
|
||||
layout (location = 0) in vec3 position;
|
||||
layout (location = 1) in vec2 tex_coords;
|
||||
|
||||
|
||||
layout (std140) uniform mvp_matrix{
|
||||
mat4 vp_mat;
|
||||
mat4 model_mat;
|
||||
};
|
||||
|
||||
out VS_OUT{
|
||||
vec2 tex_coords;
|
||||
}vs_out;
|
||||
|
||||
const vec4 vertices[6] = vec4[](vec4(0,1,0,1), vec4(0,0,0,1), vec4(1,0,0,1), vec4(1,0,0,1), vec4(1,1,0,1), vec4(0,1,0,1));
|
||||
|
||||
void main(){
|
||||
gl_Position = vp_mat * model_mat * vec4(position, 1);
|
||||
vs_out.tex_coords = tex_coords;
|
||||
}
|
||||
)glsl",
|
||||
.len = 0,
|
||||
.type = static_cast<unsigned int>(::gfx::ogl::shader::type::VERTEX)
|
||||
},
|
||||
{
|
||||
.text =
|
||||
R"glsl(
|
||||
#version 430 core
|
||||
|
||||
in VS_OUT{
|
||||
vec2 tex_coords;
|
||||
}fs_in;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
uniform sampler2D diffuse_texture;
|
||||
|
||||
void main(){
|
||||
frag_color = texture(diffuse_texture, fs_in.tex_coords);;
|
||||
}
|
||||
)glsl",
|
||||
.len = 0,
|
||||
.type = static_cast<unsigned int>(::gfx::ogl::shader::type::FRAGMENT)
|
||||
}
|
||||
};
|
||||
static inline constexpr const char* vertex_shader_text = sources[0].text;
|
||||
static inline constexpr const char* fragment_shader_text = sources[1].text;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
34
include/wip/shader_source.hpp
Normal file
34
include/wip/shader_source.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
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_GRAPHICS_WIP_SHADER_SOURCE_HPP
|
||||
#define OUR_DICK_GRAPHICS_WIP_SHADER_SOURCE_HPP
|
||||
|
||||
#include <cstdlib> //size_t
|
||||
|
||||
namespace wip::gfx{
|
||||
|
||||
struct shader_source{
|
||||
const char* text;
|
||||
size_t len;
|
||||
unsigned int type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -31,6 +31,8 @@ namespace gfx::ogl{
|
||||
{
|
||||
load(data);
|
||||
}
|
||||
shader::shader(const wip::gfx::shader_source& s):
|
||||
shader(s.text, static_cast<type>(s.type)){}
|
||||
shader::shader(const shader& s):
|
||||
shader(s.get_type())
|
||||
{
|
||||
|
||||
@ -43,8 +43,8 @@ pause_state::pause_state(egn::game& owner, egn::game_state_iface* under):
|
||||
m_elapsed_time(0)
|
||||
{
|
||||
//TODO hide GL implementation details somewhere else
|
||||
auto vert = renderer().shaders().emplace_value("base_vert", wip::gfx::base_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX).first;
|
||||
auto frag = renderer().shaders().emplace_value("base_frag", wip::gfx::base_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT).first;
|
||||
auto vert = renderer().shaders().emplace_value("base_vert", wip::gfx::base_shader::sources[0]).first;
|
||||
auto frag = renderer().shaders().emplace_value("base_frag", wip::gfx::base_shader::sources[1]).first;
|
||||
auto shader = renderer().shader_programs().emplace_value("base_shader", *vert, *frag).first;
|
||||
auto tex = renderer().textures().emplace_value("test_texture", util::make_deferred<egn::image>("assets/images/x.jpg", true)).first;
|
||||
auto material = renderer().materials().emplace_value("test_material", shader).first;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user