Restructure directories

This commit is contained in:
rexy712 2022-02-10 16:56:01 -08:00
parent daa5f13a60
commit 85d6acad11
85 changed files with 614 additions and 511 deletions

View File

@ -19,15 +19,15 @@
#ifndef OUR_DICK_BASIC_FRAMEBUFFER_HPP #ifndef OUR_DICK_BASIC_FRAMEBUFFER_HPP
#define OUR_DICK_BASIC_FRAMEBUFFER_HPP #define OUR_DICK_BASIC_FRAMEBUFFER_HPP
#include "graphics/texture.hpp" #include "gfx/ogl/texture.hpp"
#include "graphics/rbo.hpp" #include "gfx/ogl/rbo.hpp"
#include "graphics/fbo.hpp" #include "gfx/ogl/fbo.hpp"
class basic_framebuffer : public gfx::fbo class basic_framebuffer : public gfx::ogl::fbo
{ {
private: private:
gfx::texture m_colorbuffer; gfx::ogl::texture m_colorbuffer;
gfx::rbo m_depthbuffer; gfx::ogl::rbo m_depthbuffer;
public: public:
basic_framebuffer(int width, int height); basic_framebuffer(int width, int height);
@ -36,11 +36,11 @@ public:
basic_framebuffer& operator=(basic_framebuffer&&) = default; basic_framebuffer& operator=(basic_framebuffer&&) = default;
gfx::texture& colorbuffer(void); gfx::ogl::texture& colorbuffer(void);
const gfx::texture& colorbuffer(void)const; const gfx::ogl::texture& colorbuffer(void)const;
gfx::rbo& depthbuffer(void); gfx::ogl::rbo& depthbuffer(void);
const gfx::rbo& depthbuffer(void)const; const gfx::ogl::rbo& depthbuffer(void)const;
}; };
#endif #endif

View File

@ -19,7 +19,6 @@
#ifndef OUR_DICK_ENGINE_CAMERA_HPP #ifndef OUR_DICK_ENGINE_CAMERA_HPP
#define OUR_DICK_ENGINE_CAMERA_HPP #define OUR_DICK_ENGINE_CAMERA_HPP
#include "graphics/gl_include.hpp" //GLfloat
#include "math/math.hpp" #include "math/math.hpp"
#include "object.hpp" #include "object.hpp"
@ -38,15 +37,15 @@ namespace egn{
protected: protected:
//mutable because they're only really a cached value representation of the data //mutable because they're only really a cached value representation of the data
//in position, orientation, near, far, etc //in position, orientation, near, far, etc
mutable math::mat4<GLfloat> m_projection_matrix; //camera-to-sceen matrix mutable math::mat4f m_projection_matrix; //camera-to-sceen matrix
mutable math::mat4<GLfloat> m_view_matrix; //world-to-camera matrix mutable math::mat4f m_view_matrix; //world-to-camera matrix
GLfloat m_near = 1; //near clipping plane in camera space float m_near = 1; //near clipping plane in camera space
GLfloat m_far = 100; //far clipping plane in camera space float m_far = 100; //far clipping plane in camera space
public: public:
camera_iface(void) = default; camera_iface(void) = default;
//Initialize with given projection matrix and clipping planes //Initialize with given projection matrix and clipping planes
camera_iface(const math::mat4<GLfloat>& proj, GLfloat n, GLfloat f); camera_iface(const math::mat4f& proj, float n, float f);
camera_iface(const camera_iface&) = default; camera_iface(const camera_iface&) = default;
camera_iface(camera_iface&&) = default; camera_iface(camera_iface&&) = default;
virtual ~camera_iface(void) = default; virtual ~camera_iface(void) = default;
@ -55,19 +54,19 @@ namespace egn{
camera_iface& operator=(camera_iface&&) = default; camera_iface& operator=(camera_iface&&) = default;
//Set the camera's location and update relevant data structures //Set the camera's location and update relevant data structures
void set_position(const math::vec3<GLfloat>& pos)override; void set_position(const math::vec3f& pos)override;
//Set the camera's facing angle and update relevant data structures //Set the camera's facing angle and update relevant data structures
void set_orientation(const math::quaternion<GLfloat>& distance)override; void set_orientation(const math::quat_f& distance)override;
//getters //getters
const math::mat4<GLfloat>& get_projection_matrix()const; const math::mat4f& get_projection_matrix()const;
const math::mat4<GLfloat>& get_view_matrix()const; const math::mat4f& get_view_matrix()const;
GLfloat get_near_plane()const; float get_near_plane()const;
GLfloat get_far_plane()const; float get_far_plane()const;
//setters //setters
void set_near_plane(GLfloat n); void set_near_plane(float n);
void set_far_plane(GLfloat f); void set_far_plane(float f);
//No control over matrices directly is done purposefully //No control over matrices directly is done purposefully
protected: protected:
@ -79,11 +78,11 @@ namespace egn{
class ortho_camera : public camera_iface class ortho_camera : public camera_iface
{ {
protected: protected:
GLfloat m_width, m_height; //width and height of the camera space box float m_width, m_height; //width and height of the camera space box
public: public:
//Build camera with width, height, near, and far planes //Build camera with width, height, near, and far planes
ortho_camera(GLfloat w, GLfloat h, GLfloat n, GLfloat f); ortho_camera(float w, float h, float n, float f);
ortho_camera(const ortho_camera&) = default; ortho_camera(const ortho_camera&) = default;
ortho_camera(ortho_camera&&) = default; ortho_camera(ortho_camera&&) = default;
~ortho_camera() = default; ~ortho_camera() = default;
@ -92,13 +91,13 @@ namespace egn{
ortho_camera& operator=(ortho_camera&&) = default; ortho_camera& operator=(ortho_camera&&) = default;
//Getters //Getters
GLfloat get_projection_width()const; float get_projection_width()const;
GLfloat get_projection_height()const; float get_projection_height()const;
//Setters //Setters
void set_projection_width(GLfloat w); void set_projection_width(float w);
void set_projection_height(GLfloat h); void set_projection_height(float h);
void set_projection_box(GLfloat w, GLfloat h); void set_projection_box(float w, float h);
protected: protected:
void recalc_projection_matrix()const override; void recalc_projection_matrix()const override;
}; };

View File

@ -27,23 +27,23 @@
#include <memory> #include <memory>
#include <algorithm> //min, max #include <algorithm> //min, max
#include "graphics/texture.hpp" #include "gfx/ogl/texture.hpp"
#include "config.hpp" #include "config.hpp"
namespace egn{ namespace egn{
struct font_character{ struct font_character{
math::vec2<size_t> atlas_offset; math::vec2<size_t> atlas_offset;
math::vec2<int> size; math::vec2i size;
math::vec2<int> bearing; math::vec2i bearing;
math::vec2<int> advance; math::vec2i advance;
math::vec2<float> texture_coords[4]; math::vec2f texture_coords[4];
public: public:
float aspect_ratio(void)const; float aspect_ratio(void)const;
}; };
class font_atlas : public gfx::texture class font_atlas : public gfx::ogl::texture
{ {
public: public:
using map_type = std::map<int, font_character>; using map_type = std::map<int, font_character>;
@ -53,7 +53,7 @@ namespace egn{
size_t m_requested_width, m_requested_height; size_t m_requested_width, m_requested_height;
public: public:
font_atlas(gfx::texture&& t, map_type&& map, size_t w, size_t h); font_atlas(gfx::ogl::texture&& t, map_type&& map, size_t w, size_t h);
font_atlas(const font_atlas&) = default; font_atlas(const font_atlas&) = default;
font_atlas(font_atlas&&) = default; font_atlas(font_atlas&&) = default;
~font_atlas(void) = default; ~font_atlas(void) = default;
@ -87,13 +87,13 @@ namespace egn{
template<class... Ts> template<class... Ts>
font_atlas generate_atlas(size_t glyph_w, size_t glyph_h, Ts&&... ranges); font_atlas generate_atlas(size_t glyph_w, size_t glyph_h, Ts&&... ranges);
std::optional<gfx::texture> generate_glyph(char character, int width, int height); std::optional<gfx::ogl::texture> generate_glyph(char character, int width, int height);
private: private:
using atlas_meta = std::tuple<size_t,size_t,size_t,size_t>; using atlas_meta = std::tuple<size_t,size_t,size_t,size_t>;
template<class... Ts> template<class... Ts>
void generate_atlas_piece_(gfx::texture& atlas, font_atlas::map_type& metadata, math::vec2<size_t>& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair<int,int>& range, Ts&&... ranges); void generate_atlas_piece_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, math::vec2<size_t>& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair<int,int>& range, Ts&&... ranges);
void generate_atlas_piece_impl_(gfx::texture& atlas, font_atlas::map_type& metadata, math::vec2<size_t>& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair<int,int>& range); void generate_atlas_piece_impl_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, math::vec2<size_t>& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair<int,int>& range);
template<class... Ts> template<class... Ts>
atlas_meta get_atlas_size_ranges_(Ts&&... ranges); atlas_meta get_atlas_size_ranges_(Ts&&... ranges);
template<class... Ts> template<class... Ts>
@ -108,7 +108,7 @@ namespace egn{
template<class... Ts> template<class... Ts>
void font::generate_atlas_piece_(gfx::texture& atlas, font_atlas::map_type& metadata, math::vec2<size_t>& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair<int,int>& range, Ts&&... ranges){ void font::generate_atlas_piece_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, math::vec2<size_t>& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair<int,int>& range, Ts&&... ranges){
generate_atlas_piece_impl_(atlas, metadata, target_pos, info, data_buffer, range); generate_atlas_piece_impl_(atlas, metadata, target_pos, info, data_buffer, range);
if constexpr(sizeof...(ranges) > 0){ if constexpr(sizeof...(ranges) > 0){
@ -123,7 +123,7 @@ namespace egn{
const auto format = (m_depth == 3) ? GL_RGB : GL_RED; const auto format = (m_depth == 3) ? GL_RGB : GL_RED;
gfx::texture atlas(format, atlas_width, atlas_height, GL_UNSIGNED_BYTE, false); gfx::ogl::texture atlas(format, atlas_width, atlas_height, GL_UNSIGNED_BYTE, false);
font_atlas::map_type atlas_metadata; font_atlas::map_type atlas_metadata;
math::vec2<size_t> target_position = {0, 0}; math::vec2<size_t> target_position = {0, 0};
std::unique_ptr<unsigned char[]> dest_data(new unsigned char[max_glyph_height * max_glyph_width * m_depth]); std::unique_ptr<unsigned char[]> dest_data(new unsigned char[max_glyph_height * max_glyph_width * m_depth]);

View File

@ -21,7 +21,7 @@
#include "observable.hpp" #include "observable.hpp"
#include "game_state.hpp" #include "game_state.hpp"
#include "graphics/window.hpp" #include "gfx/ogl/window.hpp"
#include "input.hpp" #include "input.hpp"
#include "math/vec.hpp" #include "math/vec.hpp"
@ -32,7 +32,7 @@ namespace egn{
class game : public observer<game_state_event> class game : public observer<game_state_event>
{ {
protected: protected:
gfx::window m_window; gfx::ogl::window m_window;
game_state_manager m_states_manager; game_state_manager m_states_manager;
std::queue<input_event> m_event_queue; std::queue<input_event> m_event_queue;
double m_last_time; double m_last_time;

View File

@ -19,7 +19,7 @@
#ifndef OUR_DICK_ENGINE_OBJECT_HPP #ifndef OUR_DICK_ENGINE_OBJECT_HPP
#define OUR_DICK_ENGINE_OBJECT_HPP #define OUR_DICK_ENGINE_OBJECT_HPP
#include "graphics/gl_include.hpp" //GLfloat #include "gfx/ogl/gl_include.hpp" //GLfloat
#include "math/math.hpp" #include "math/math.hpp"
#include "base_types.hpp" #include "base_types.hpp"

View File

@ -20,28 +20,27 @@
#define OUR_DICK_GRAPHICS_LIGHTABLE_HPP #define OUR_DICK_GRAPHICS_LIGHTABLE_HPP
#include "math/vec.hpp" #include "math/vec.hpp"
#include "gl_include.hpp"
namespace gfx{ namespace gfx{
class lightable class lightable
{ {
protected: protected:
math::vec3<GLfloat> m_ambient; math::vec3f m_ambient;
math::vec3<GLfloat> m_diffuse; math::vec3f m_diffuse;
math::vec3<GLfloat> m_specular; math::vec3f m_specular;
GLfloat m_shininess; float m_shininess;
public: public:
void set_ambient(const math::vec3<GLfloat>& a); void set_ambient(const math::vec3f& a);
void set_diffuse(const math::vec3<GLfloat>& d); void set_diffuse(const math::vec3f& d);
void set_specular(const math::vec3<GLfloat>& s); void set_specular(const math::vec3f& s);
void set_shininess(GLfloat s); void set_shininess(float s);
const math::vec3<GLfloat>& get_ambient()const; const math::vec3f& get_ambient()const;
const math::vec3<GLfloat>& get_diffuse()const; const math::vec3f& get_diffuse()const;
const math::vec3<GLfloat>& get_specular()const; const math::vec3f& get_specular()const;
GLfloat get_shininess()const; float get_shininess()const;
}; };
} }

View File

@ -20,18 +20,18 @@
#define OUR_DICK_GRAPHICS_MATERIAL_HPP #define OUR_DICK_GRAPHICS_MATERIAL_HPP
#include "lightable.hpp" #include "lightable.hpp"
#include "texture.hpp" #include "ogl/texture.hpp"
namespace gfx{ namespace gfx{
class material : public lightable, public texture class material : public lightable, public ogl::texture
{ {
public: public:
using texture::texture; using ogl::texture::texture;
using texture::operator=; using ogl::texture::operator=;
//tmp //tmp
material(texture&&); material(ogl::texture&&);
}; };
} }

View File

@ -20,9 +20,9 @@
#define OUR_DICK_GRAPHICS_MESH_HPP #define OUR_DICK_GRAPHICS_MESH_HPP
#include "math/vec.hpp" #include "math/vec.hpp"
#include "vao.hpp" #include "ogl/vao.hpp"
#include "vbo.hpp" #include "ogl/vbo.hpp"
#include "shader_program.hpp" #include "ogl/shader_program.hpp"
#include "material.hpp" #include "material.hpp"
#include <vector> #include <vector>
@ -31,9 +31,9 @@
namespace gfx{ namespace gfx{
struct vertex { struct vertex {
math::vec3<float> position; math::vec3f position;
math::vec3<float> normal; math::vec3f normal;
math::vec2<float> tex_coords; math::vec2f tex_coords;
}; };
class vertex_mesh class vertex_mesh
@ -41,8 +41,8 @@ namespace gfx{
protected: protected:
std::vector<vertex> m_vertices; std::vector<vertex> m_vertices;
gfx::vao m_vao; gfx::ogl::vao m_vao;
gfx::vbo m_vbo; gfx::ogl::vbo m_vbo;
public: public:
vertex_mesh(const std::vector<vertex>& verts); vertex_mesh(const std::vector<vertex>& verts);
@ -61,7 +61,7 @@ namespace gfx{
const vertex& get_vertex(size_t index)const; const vertex& get_vertex(size_t index)const;
void set_vertex(size_t index, const vertex& v); void set_vertex(size_t index, const vertex& v);
void render(shader_program& shader); void render(ogl::shader_program& shader);
}; };
class material_mesh class material_mesh
@ -78,7 +78,7 @@ namespace gfx{
void set_material(size_t index, const material& new_texture); void set_material(size_t index, const material& new_texture);
void set_material(size_t index, const material* new_texture); void set_material(size_t index, const material* new_texture);
void render(shader_program& shader); void render(ogl::shader_program& shader);
}; };
class unified_mesh class unified_mesh
@ -105,7 +105,7 @@ namespace gfx{
void configure(); void configure();
void render(shader_program& shader); void render(ogl::shader_program& shader);
}; };
} }

View File

@ -20,7 +20,7 @@
#define OUR_DICK_GRAPHICS_MODEL_HPP #define OUR_DICK_GRAPHICS_MODEL_HPP
#include "mesh.hpp" #include "mesh.hpp"
#include "shader_program.hpp" #include "ogl/shader_program.hpp"
#include <vector> #include <vector>
#include <type_traits> //enable_if, decay, is_same #include <type_traits> //enable_if, decay, is_same
@ -56,7 +56,7 @@ namespace gfx{
unified_mesh& mesh(size_t index); unified_mesh& mesh(size_t index);
const unified_mesh& mesh(size_t index)const; const unified_mesh& mesh(size_t index)const;
void render(shader_program& s); void render(ogl::shader_program& s);
}; };
template<typename... Args, std::enable_if_t<(std::is_same_v<std::decay_t<Args>,::gfx::unified_mesh> && ...),int>> template<typename... Args, std::enable_if_t<(std::is_same_v<std::decay_t<Args>,::gfx::unified_mesh> && ...),int>>

View File

@ -16,14 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_BUFFER_MAP_HPP #ifndef OUR_DICK_GRAPHICS_OGL_BUFFER_MAP_HPP
#define OUR_DICK_GRAPHICS_BUFFER_MAP_HPP #define OUR_DICK_GRAPHICS_OGL_BUFFER_MAP_HPP
#include "gl_include.hpp" #include "gl_include.hpp"
#include <cstdlib> //size_t, ptrdiff_t #include <cstdlib> //size_t, ptrdiff_t
namespace gfx{ namespace gfx::ogl{
namespace buffer{ namespace buffer{
//strongly typed enum for different mapping styles //strongly typed enum for different mapping styles

View File

@ -16,13 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_BUFFER_MAP_TPP #ifndef OUR_DICK_GRAPHICS_OGL_BUFFER_MAP_TPP
#define OUR_DICK_GRAPHICS_BUFFER_MAP_TPP #define OUR_DICK_GRAPHICS_OGL_BUFFER_MAP_TPP
#include <utility> //exchange, swap #include <utility> //exchange, swap
#include "gl_include.hpp" #include "gl_include.hpp"
namespace gfx{ namespace gfx::ogl{
template<typename T> template<typename T>
scoped_buffer_map<T>::scoped_buffer_map(GLuint bid, buffer::maptype m): scoped_buffer_map<T>::scoped_buffer_map(GLuint bid, buffer::maptype m):

View File

@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_FBO_HPP #ifndef OUR_DICK_GRAPHICS_OGL_FBO_HPP
#define OUR_DICK_GRAPHICS_FBO_HPP #define OUR_DICK_GRAPHICS_OGL_FBO_HPP
#include "gl_include.hpp" #include "gl_include.hpp"
#include "texture.hpp" #include "texture.hpp"
@ -25,7 +25,7 @@
#include "math/vec.hpp" #include "math/vec.hpp"
#include "util/init_constants.hpp" #include "util/init_constants.hpp"
namespace gfx{ namespace gfx::ogl{
class fbo class fbo
{ {

View File

@ -17,8 +17,8 @@
*/ */
//ensure proper inclusion order at all times //ensure proper inclusion order at all times
#ifndef OUR_DICK_GRAPHICS_GL_INCLUDE_HPP #ifndef OUR_DICK_GRAPHICS_OGL_GL_INCLUDE_HPP
#define OUR_DICK_GRAPHICS_GL_INCLUDE_HPP #define OUR_DICK_GRAPHICS_OGL_GL_INCLUDE_HPP
#include <glad/glad.h> #include <glad/glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>

View File

@ -16,12 +16,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_RBO_HPP #ifndef OUR_DICK_GRAPHICS_OGL_RBO_HPP
#define OUR_DICK_GRAPHICS_RBO_HPP #define OUR_DICK_GRAPHICS_OGL_RBO_HPP
#include "gl_include.hpp" #include "gl_include.hpp"
namespace gfx{ namespace gfx::ogl{
class rbo class rbo
{ {

View File

@ -16,13 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_SHADER_HPP #ifndef OUR_DICK_GRAPHICS_OGL_SHADER_HPP
#define OUR_DICK_GRAPHICS_SHADER_HPP #define OUR_DICK_GRAPHICS_OGL_SHADER_HPP
#include "gl_include.hpp" #include "gl_include.hpp"
#include <string> #include <string>
namespace gfx{ namespace gfx::ogl{
//class representing an opengl shader (NOT an opengl program) //class representing an opengl shader (NOT an opengl program)
class shader class shader

View File

@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_SHADER_PROGRAM_HPP #ifndef OUR_DICK_GRAPHICS_OGL_SHADER_PROGRAM_HPP
#define OUR_DICK_GRAPHICS_SHADER_PROGRAM_HPP #define OUR_DICK_GRAPHICS_OGL_SHADER_PROGRAM_HPP
#include "gl_include.hpp" #include "gl_include.hpp"
#include "shader.hpp" #include "shader.hpp"
@ -29,7 +29,7 @@
#include "math/math.hpp" #include "math/math.hpp"
namespace gfx{ namespace gfx::ogl{
using namespace math; using namespace math;

View File

@ -16,14 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_TEXTURE_HPP #ifndef OUR_DICK_GRAPHICS_OGL_TEXTURE_HPP
#define OUR_DICK_GRAPHICS_TEXTURE_HPP #define OUR_DICK_GRAPHICS_OGL_TEXTURE_HPP
#include "engine/image.hpp" #include "egn/image.hpp"
#include "gl_include.hpp" #include "gl_include.hpp"
#include "math/vec.hpp" #include "math/vec.hpp"
namespace gfx{ namespace gfx::ogl{
class texture; class texture;

View File

@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_UBO_HPP #ifndef OUR_DICK_GRAPHICS_OGL_UBO_HPP
#define OUR_DICK_GRAPHICS_UBO_HPP #define OUR_DICK_GRAPHICS_OGL_UBO_HPP
#include "gl_include.hpp" #include "gl_include.hpp"
@ -28,7 +28,7 @@
#include "buffer_map.hpp" #include "buffer_map.hpp"
namespace gfx{ namespace gfx::ogl{
namespace detail{ namespace detail{
template<class T> template<class T>

View File

@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_UBO_TPP #ifndef OUR_DICK_GRAPHICS_OGL_UBO_TPP
#define OUR_DICK_GRAPHICS_UBO_TPP #define OUR_DICK_GRAPHICS_OGL_UBO_TPP
#include <utility> //swap, exchange #include <utility> //swap, exchange
#include <type_traits> //a lot of stuff #include <type_traits> //a lot of stuff
@ -25,7 +25,7 @@
#include <array> #include <array>
#include <cstring> //memcpy, memset #include <cstring> //memcpy, memset
namespace gfx{ namespace gfx::ogl{
template<class... Types> template<class... Types>
ubo<Types...>::ubo(buffer::usage usage){ ubo<Types...>::ubo(buffer::usage usage){

View File

@ -16,14 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_VAO_HPP #ifndef OUR_DICK_GRAPHICS_OGL_VAO_HPP
#define OUR_DICK_GRAPHICS_VAO_HPP #define OUR_DICK_GRAPHICS_OGL_VAO_HPP
#include "gl_include.hpp" #include "gl_include.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include "vbo.hpp" #include "vbo.hpp"
namespace gfx{ namespace gfx::ogl{
using namespace math; using namespace math;
class vertex_attribute; class vertex_attribute;

View File

@ -16,15 +16,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_VBO_HPP #ifndef OUR_DICK_GRAPHICS_OGL_VBO_HPP
#define OUR_DICK_GRAPHICS_VBO_HPP #define OUR_DICK_GRAPHICS_OGL_VBO_HPP
#include "gl_include.hpp" #include "gl_include.hpp"
#include <cstdlib> //size_t #include <cstdlib> //size_t
#include "buffer_map.hpp" #include "buffer_map.hpp"
namespace gfx{ namespace gfx::ogl{
//class representing a vertex buffer object //class representing a vertex buffer object
class vbo class vbo

View File

@ -16,17 +16,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OUR_DICK_GRAPHICS_WINDOW_HPP #ifndef OUR_DICK_GRAPHICS_OGL_WINDOW_HPP
#define OUR_DICK_GRAPHICS_WINDOW_HPP #define OUR_DICK_GRAPHICS_OGL_WINDOW_HPP
#include "gl_include.hpp" #include "gl_include.hpp"
#include "init.hpp" #include "../init.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include "util/init_constants.hpp" #include "util/init_constants.hpp"
#include "fbo.hpp" #include "fbo.hpp"
#include "resource_manager.hpp" #include "../resource_manager.hpp"
namespace gfx{ namespace gfx::ogl{
using namespace math; using namespace math;

View File

@ -0,0 +1,90 @@
/**
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_RESOURCE_CONTAINER_HPP
#define OUR_DICK_GRAPHICS_RESOURCE_CONTAINER_HPP
#include <string>
#include <map>
#include <utility> //pair, forward
#include <tuple>
#include <memory> //shared_ptr
#include "util/deferred.hpp"
namespace gfx{
template<class T>
class resource_container
{
public:
using value_type = T;
using key_type = std::string;
using reference = T&;
using const_reference = const T&;
using pointer = T*;
using const_pointer = const T*;
using node = std::shared_ptr<value_type>;
using const_node = std::shared_ptr<value_type>;
private:
std::map<key_type,std::shared_ptr<value_type>> m_map;
public:
resource_container(void) = default;
resource_container(const resource_container&) = default;
resource_container(resource_container&&) = default;
~resource_container(void) = default;
resource_container& operator=(const resource_container&) = default;
resource_container& operator=(resource_container&&) = default;
bool has_value(const char* key)const;
template<class... Args>
std::pair<node,bool> emplace_value(const char* key, Args&&... args);
node get_value(const char* file);
bool erase_value(const char* key);
};
template<class T>
bool resource_container<T>::has_value(const char* key)const{
if(auto it = m_map.find(key);it != m_map.end())
return true;
return false;
}
template<class T>
template<class... Args>
auto resource_container<T>::emplace_value(const char* key, Args&&... args) -> std::pair<node,bool>{
auto p = m_map.try_emplace(key, util::deferred_function(std::make_shared<T,Args&&...>, std::forward<Args>(args)...));
return {(*p.first).second, p.second};
}
template<class T>
auto resource_container<T>::get_value(const char* key) -> node{
if(auto it = m_map.find(key);it != m_map.end())
return (*it).second;
return nullptr;
}
template<class T>
bool resource_container<T>::erase_value(const char* key){
return m_map.erase(key) == 1;
}
}
#endif

View File

@ -19,63 +19,26 @@
#ifndef OUR_DICK_GRAPHICS_RESOURCE_MANAGER_HPP #ifndef OUR_DICK_GRAPHICS_RESOURCE_MANAGER_HPP
#define OUR_DICK_GRAPHICS_RESOURCE_MANAGER_HPP #define OUR_DICK_GRAPHICS_RESOURCE_MANAGER_HPP
#include <string> #include "resource_container.hpp"
#include <map> #include "ogl/texture.hpp"
#include <utility> //pair, forward #include "ogl/shader_program.hpp"
#include <tuple>
#include "graphics/texture.hpp" #include "egn/font.hpp"
#include "graphics/shader_program.hpp"
#include "engine/font.hpp" #include <utility> //forward
#include "util/deferred.hpp"
namespace gfx{ namespace gfx{
namespace detail{
template<class T>
class resource_manager
{
public:
using value_type = T;
using key_type = std::string;
using reference = T&;
using const_reference = const T&;
using pointer = T*;
using const_pointer = const T*;
using node = std::shared_ptr<value_type>;
using const_node = std::shared_ptr<value_type>;
private:
std::map<key_type,std::shared_ptr<value_type>> m_map;
public:
resource_manager(void) = default;
resource_manager(const resource_manager&) = default;
resource_manager(resource_manager&&) = default;
~resource_manager(void) = default;
resource_manager& operator=(const resource_manager&) = default;
resource_manager& operator=(resource_manager&&) = default;
bool has_value(const char* key)const;
template<class... Args>
std::pair<node,bool> emplace_value(const char* key, Args&&... args);
node get_value(const char* file);
bool erase_value(const char* key);
};
}
class resource_manager class resource_manager
{ {
public: public:
template<class T> template<class T>
using container_type = detail::resource_manager<T>; using container_type = resource_container<T>;
private: private:
container_type<texture> m_textures; container_type<ogl::texture> m_textures;
container_type<egn::font_atlas> m_fonts; container_type<egn::font_atlas> m_fonts;
container_type<texture_array> m_texture_arrays; container_type<ogl::texture_array> m_texture_arrays;
container_type<shader_program> m_shaders; container_type<ogl::shader_program> m_shaders;
public: public:
resource_manager(void) = default; resource_manager(void) = default;
@ -90,13 +53,13 @@ namespace gfx{
bool has_texture_array(const char* key)const; bool has_texture_array(const char* key)const;
template<class... Args> template<class... Args>
auto emplace_texture_array(const char* key, Args&&... args); auto emplace_texture_array(const char* key, Args&&... args);
container_type<texture_array>::node get_texture_array(const char* file); container_type<ogl::texture_array>::node get_texture_array(const char* file);
bool erase_texture_array(const char* key); bool erase_texture_array(const char* key);
bool has_texture(const char* key)const; bool has_texture(const char* key)const;
template<class... Args> template<class... Args>
auto emplace_texture(const char* key, Args&&... args); auto emplace_texture(const char* key, Args&&... args);
container_type<texture>::node get_texture(const char* file); container_type<ogl::texture>::node get_texture(const char* file);
bool erase_texture(const char* key); bool erase_texture(const char* key);
bool has_font(const char* key)const; bool has_font(const char* key)const;
@ -108,35 +71,10 @@ namespace gfx{
bool has_shader(const char* key)const; bool has_shader(const char* key)const;
template<class... Args> template<class... Args>
auto emplace_shader(const char* key, Args&&... args); auto emplace_shader(const char* key, Args&&... args);
container_type<shader_program>::node get_shader(const char* key); container_type<ogl::shader_program>::node get_shader(const char* key);
bool erase_shader(const char* key); bool erase_shader(const char* key);
}; };
namespace detail{
template<class T>
bool resource_manager<T>::has_value(const char* key)const{
if(auto it = m_map.find(key);it != m_map.end())
return true;
return false;
}
template<class T>
template<class... Args>
auto resource_manager<T>::emplace_value(const char* key, Args&&... args) -> std::pair<node,bool>{
auto p = m_map.try_emplace(key, util::deferred_function(std::make_shared<T,Args&&...>, std::forward<Args>(args)...));
return {(*p.first).second, p.second};
}
template<class T>
auto resource_manager<T>::get_value(const char* key) -> node{
if(auto it = m_map.find(key);it != m_map.end())
return (*it).second;
return nullptr;
}
template<class T>
bool resource_manager<T>::erase_value(const char* key){
return m_map.erase(key) == 1;
}
}
template<class... Args> template<class... Args>
auto resource_manager::emplace_texture_array(const char* key, Args&&... args){ auto resource_manager::emplace_texture_array(const char* key, Args&&... args){
return m_texture_arrays.emplace_value(key, std::forward<Args>(args)...); return m_texture_arrays.emplace_value(key, std::forward<Args>(args)...);

View File

@ -19,15 +19,15 @@
#ifndef OUR_DICK_RENDERABLE_HPP #ifndef OUR_DICK_RENDERABLE_HPP
#define OUR_DICK_RENDERABLE_HPP #define OUR_DICK_RENDERABLE_HPP
#include "graphics/shader_program.hpp" #include "gfx/ogl/shader_program.hpp"
#include "engine/object.hpp" #include "egn/object.hpp"
class renderable_iface class renderable_iface
{ {
public: public:
virtual ~renderable_iface() = default; virtual ~renderable_iface() = default;
virtual void render(gfx::shader_program&) = 0; virtual void render(gfx::ogl::shader_program&) = 0;
}; };
class renderable_object : public renderable_iface, public egn::object_base{}; class renderable_object : public renderable_iface, public egn::object_base{};

View File

@ -19,10 +19,10 @@
#ifndef OUR_DICK_SCENE_HPP #ifndef OUR_DICK_SCENE_HPP
#define OUR_DICK_SCENE_HPP #define OUR_DICK_SCENE_HPP
#include "graphics/texture.hpp" //TODO: use material interface instead of direct texture #include "gfx/ogl/texture.hpp" //TODO: use material interface instead of direct texture
#include "engine/camera.hpp" #include "egn/camera.hpp"
#include "renderable.hpp" #include "renderable.hpp"
#include "graphics/model.hpp" #include "gfx/model.hpp"
#include <vector> //vector #include <vector> //vector
#include <memory> //unique_ptr #include <memory> //unique_ptr

View File

@ -19,17 +19,116 @@
#ifndef OUR_DICK_BOARD_HPP #ifndef OUR_DICK_BOARD_HPP
#define OUR_DICK_BOARD_HPP #define OUR_DICK_BOARD_HPP
#include "graphics/shader_program.hpp" #include "gfx/ogl/shader_program.hpp"
#include "renderable.hpp" #include "renderable.hpp"
#include "graphics/resource_manager.hpp" #include "gfx/resource_manager.hpp"
#include "math/vec.hpp" #include "math/vec.hpp"
#include "config.hpp" #include "config.hpp"
#include <memory> //unique_ptr #include <memory> //unique_ptr, shared_ptr
#include <vector>
#include "gfx/ogl/shader_program.hpp"
#include "gfx/ogl/vbo.hpp"
#include "gfx/ogl/vao.hpp"
#include "gfx/ogl/texture.hpp"
#include "wip/renderer.hpp"
class board_gfx; class board_gfx;
struct vertex{
math::vec3f position;
math::vec2f tex_coords;
};
class material
{
public:
std::shared_ptr<gfx::ogl::shader_program> shader;
std::shared_ptr<gfx::ogl::texture> diffuse_texture;
math::vec3f diffuse;
math::vec3f specular;
math::vec3f ambient;
float shininess;
material(const std::shared_ptr<gfx::ogl::shader_program>& sh);
material(const material&) = default;
material(material&&) = default;
~material(void) = default;
material& operator=(const material&) = default;
material& operator=(material&&) = default;
void bind(void){
shader->get_uniform("diffuse_texture").set(*diffuse_texture, 0);
//set uniforms for other lighting stuff or switch to a ubo
}
};
class mesh
{
private:
size_t m_num_vertices;
gfx::ogl::vbo m_buffer;
gfx::ogl::vao m_attributes;
public:
mesh(const std::vector<vertex>& vertices);
void bind(void);
void render(wip::gfx::renderer& r, material&){
m_attributes.bind();
r.draw_tris(0, m_num_vertices);
}
};
class new_tile
{
public:
enum class state{
BLANK = 0,
X,
O
};
private:
std::shared_ptr<mesh> m_mesh;
public:
std::shared_ptr<material> image;
state value;
new_tile(const std::shared_ptr<mesh>& me, const std::shared_ptr<material>& ma);
void render(wip::gfx::renderer& r){
m_mesh->render(r, *image);
}
};
class new_board
{
private:
std::shared_ptr<material> m_blank;
std::shared_ptr<material> m_x;
std::shared_ptr<material> m_o;
std::unique_ptr<new_tile[]> m_tiles;
public:
new_board(wip::gfx::renderer& r);
void render(wip::gfx::renderer& r){
for(size_t i = 0;i < 9;++i){
auto& tile = m_tiles[i];
tile.render(r);
}
}
void update(float /*dtime*/){
}
};
class tile : public egn::object_base class tile : public egn::object_base
{ {
public: public:
@ -77,7 +176,7 @@ public:
void reset(void); void reset(void);
void render(gfx::shader_program& sh)override; void render(gfx::ogl::shader_program& sh)override;
private: private:
tile::value check_rows_(void)const; tile::value check_rows_(void)const;

View File

@ -19,11 +19,11 @@
#ifndef OUR_DICK_BOARD_GFX_HPP #ifndef OUR_DICK_BOARD_GFX_HPP
#define OUR_DICK_BOARD_GFX_HPP #define OUR_DICK_BOARD_GFX_HPP
#include "graphics/material.hpp" #include "gfx/material.hpp"
#include "graphics/vbo.hpp" #include "gfx/ogl/vbo.hpp"
#include "graphics/vao.hpp" #include "gfx/ogl/vao.hpp"
#include "graphics/shader_program.hpp" #include "gfx/ogl/shader_program.hpp"
#include "graphics/resource_manager.hpp" #include "gfx/resource_manager.hpp"
#include <utility> //pair #include <utility> //pair
#include <memory> //shared_ptr #include <memory> //shared_ptr
@ -33,21 +33,21 @@ class tile;
class board_gfx class board_gfx
{ {
private: private:
std::shared_ptr<gfx::texture_array> m_textures; std::shared_ptr<gfx::ogl::texture_array> m_textures;
gfx::vao m_vao; gfx::ogl::vao m_vao;
gfx::vbo m_vbo; gfx::ogl::vbo m_vbo;
public: public:
board_gfx(gfx::resource_manager& resman); board_gfx(gfx::resource_manager& resman);
~board_gfx(void) = default; ~board_gfx(void) = default;
void set_uniforms(gfx::shader_program& sh); void set_uniforms(gfx::ogl::shader_program& sh);
void bind_buffers(void); void bind_buffers(void);
void bind_attributes(void); void bind_attributes(void);
void buffer_tiles(const tile* t); void buffer_tiles(const tile* t);
void render(gfx::shader_program& shader); void render(gfx::ogl::shader_program& shader);
}; };
#endif #endif

View File

@ -19,12 +19,12 @@
#ifndef OUR_DICK_MAIN_RENDERER_HPP #ifndef OUR_DICK_MAIN_RENDERER_HPP
#define OUR_DICK_MAIN_RENDERER_HPP #define OUR_DICK_MAIN_RENDERER_HPP
#include "graphics/shader_program.hpp" #include "gfx/ogl/shader_program.hpp"
#include "graphics/vao.hpp" #include "gfx/ogl/vao.hpp"
#include "graphics/vbo.hpp" #include "gfx/ogl/vbo.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include "scene.hpp" #include "scene.hpp"
#include "graphics/resource_manager.hpp" #include "gfx/resource_manager.hpp"
#include "basic_framebuffer.hpp" #include "basic_framebuffer.hpp"
#include <memory> //shared_ptr #include <memory> //shared_ptr
@ -46,20 +46,20 @@ private:
}; };
private: private:
basic_framebuffer m_fb; basic_framebuffer m_fb;
gfx::fbo m_primary_fb; gfx::ogl::fbo m_primary_fb;
std::shared_ptr<gfx::shader_program> m_square_shader; std::shared_ptr<gfx::ogl::shader_program> m_square_shader;
std::shared_ptr<gfx::shader_program> m_screen_shader; std::shared_ptr<gfx::ogl::shader_program> m_screen_shader;
gfx::vbo m_vbo; gfx::ogl::vbo m_vbo;
gfx::vao m_vao; gfx::ogl::vao m_vao;
gfx::vao m_board_vao; gfx::ogl::vao m_board_vao;
gfx::vbo m_board_vbo; gfx::ogl::vbo m_board_vbo;
public: public:
main_renderer(gfx::resource_manager& res, int width, int height); main_renderer(gfx::resource_manager& res, int width, int height);
void set_vp_matrix(const math::mat4<GLfloat>& vp); void set_vp_matrix(const math::mat4<GLfloat>& vp);
void render(scene&); void render(scene&);
gfx::texture& color_buffer(void); gfx::ogl::texture& color_buffer(void);
void resize_viewport(int width, int height); void resize_viewport(int width, int height);
const math::vec4<GLfloat>& get_viewport(void)const; const math::vec4<GLfloat>& get_viewport(void)const;
}; };

View File

@ -19,9 +19,9 @@
#ifndef OUR_DICK_PAUSE_STATE_HPP #ifndef OUR_DICK_PAUSE_STATE_HPP
#define OUR_DICK_PAUSE_STATE_HPP #define OUR_DICK_PAUSE_STATE_HPP
#include "engine/game_state.hpp" #include "egn/game_state.hpp"
#include "engine/input.hpp" #include "egn/input.hpp"
#include "graphics/texture.hpp" #include "gfx/ogl/texture.hpp"
#include "screen_renderer.hpp" #include "screen_renderer.hpp"
class pause_state : public egn::game_state_iface class pause_state : public egn::game_state_iface

View File

@ -19,11 +19,11 @@
#ifndef OUR_DICK_PLAY_STATE_HPP #ifndef OUR_DICK_PLAY_STATE_HPP
#define OUR_DICK_PLAY_STATE_HPP #define OUR_DICK_PLAY_STATE_HPP
#include "engine/game_state.hpp" #include "egn/game_state.hpp"
#include "scene.hpp" #include "scene.hpp"
#include "main_renderer.hpp" #include "main_renderer.hpp"
#include "engine/camera.hpp" #include "egn/camera.hpp"
#include "math/vec.hpp" #include "math/vec.hpp"
class play_state : public egn::game_state_iface class play_state : public egn::game_state_iface

View File

@ -19,15 +19,15 @@
#ifndef OUR_DICK_SCREEN_RENDERER_HPP #ifndef OUR_DICK_SCREEN_RENDERER_HPP
#define OUR_DICK_SCREEN_RENDERER_HPP #define OUR_DICK_SCREEN_RENDERER_HPP
#include "graphics/vbo.hpp" #include "gfx/ogl/vbo.hpp"
#include "graphics/vao.hpp" #include "gfx/ogl/vao.hpp"
#include "graphics/texture.hpp" #include "gfx/ogl/texture.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include "graphics/shader_program.hpp" #include "gfx/ogl/shader_program.hpp"
#include "graphics/resource_manager.hpp" #include "gfx/resource_manager.hpp"
#include "scene.hpp" #include "scene.hpp"
#include "engine/font.hpp" #include "egn/font.hpp"
#include <memory> //shared_ptr #include <memory> //shared_ptr
@ -35,8 +35,8 @@ class screen_renderer
{ {
private: private:
struct vertex{ struct vertex{
math::vec2<GLfloat> pos; math::vec2f pos;
math::vec2<GLfloat> tex_coord; math::vec2f tex_coord;
}; };
static constexpr vertex s_vertices[] = { static constexpr vertex s_vertices[] = {
{{-1.0f, 1.0f}, {0.0f, 1.0f}}, {{-1.0f, 1.0f}, {0.0f, 1.0f}},
@ -47,14 +47,14 @@ private:
{{-1.0f, 1.0f}, {0.0f, 1.0f}} {{-1.0f, 1.0f}, {0.0f, 1.0f}}
}; };
private: private:
std::shared_ptr<gfx::shader_program> m_screen_shader; std::shared_ptr<gfx::ogl::shader_program> m_screen_shader;
gfx::vbo m_vbo; gfx::ogl::vbo m_vbo;
gfx::vao m_vao; gfx::ogl::vao m_vao;
std::shared_ptr<gfx::texture> m_texture; std::shared_ptr<gfx::ogl::texture> m_texture;
int m_screen_width, m_screen_height; int m_screen_width, m_screen_height;
public: public:
screen_renderer(gfx::resource_manager& res, int width, int height, const std::shared_ptr<gfx::texture>& base_tex); screen_renderer(gfx::resource_manager& res, int width, int height, const std::shared_ptr<gfx::ogl::texture>& base_tex);
void render(scene&); void render(scene&);
void resize_viewport(int width, int height); void resize_viewport(int width, int height);

View File

@ -19,8 +19,8 @@
#ifndef OUR_DICK_TIC_TAC_TOE_HPP #ifndef OUR_DICK_TIC_TAC_TOE_HPP
#define OUR_DICK_TIC_TAC_TOE_HPP #define OUR_DICK_TIC_TAC_TOE_HPP
#include "engine/game.hpp" #include "egn/game.hpp"
#include "engine/game_state.hpp" #include "egn/game_state.hpp"
#include "config.hpp" #include "config.hpp"
#include <queue> #include <queue>

80
include/wip/renderer.hpp Normal file
View File

@ -0,0 +1,80 @@
/**
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_RENDERER_HPP
#define OUR_DICK_GRAPHICS_WIP_RENDERER_HPP
#include "gfx/resource_container.hpp"
#include "math/vec.hpp"
#include "gfx/ogl/shader_program.hpp"
#include "gfx/ogl/texture.hpp"
#include "gfx/ogl/ubo.hpp"
namespace wip::gfx::ogl{
class material;
class mesh;
struct draw_command{
const material* mat;
const mesh* m;
float distance;
};
class renderer
{
public:
template<class T>
using container_type = ::gfx::resource_container<T>;
private:
container_type<material> m_shader_programs;
container_type<mesh> m_shaders;
::gfx::ogl::ubo<math::mat4f> m_camera; //TODO
public:
renderer(void) = default;
renderer(const renderer&) = default;
renderer(renderer&&) = default;
~renderer(void) = default;
renderer& operator=(const renderer&) = default;
renderer& operator=(renderer&&) = default;
void render(void);
void set_viewport(const math::vec4f& vp);
void draw_tris(int offset, int vertex_count);
//Access to resources
const container_type<mesh>& meshs(void)const;
container_type<mesh>& meshs(void);
const container_type<material>& materials(void)const;
container_type<material>& materials(void);
};
}
namespace wip::gfx{
class renderer : public wip::gfx::ogl::renderer{};
}
#endif

View File

@ -0,0 +1,50 @@
/**
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_RESOURCE_MANEGER_HPP
#define OUR_DICK_GRAPHICS_WIP_RESOURCE_MANAGER_HPP
#include "math/vec.hpp"
#include "graphics/resource_manager_base.hpp"
#include "graphics/shader_program.hpp"
#include "graphics/texture.hpp"
namespace wip::gfx::ogl{
class resource_manager
{
private:
detail::resource_manager<shader_program> m_shader_programs;
detail::resource_manager<shader> m_shaders;
detail::resource_manager<texture> m_textures;
detail::resource_manager<texture_array> m_texture_arrays;
public:
const resource_manager<shader_program>& shader_programs(void)const;
resource_manager<shader_program>& shader_programs(void);
const resource_manager<shader>& shaders(void)const;
resource_manager<shader>& shaders(void);
const resource_manager<texture>& textures(void)const;
resource_manager<texture>& textures(void);
const resource_manager<texture_array>& texture_arrays(void)const;
resource_manager<texture_array>& texture_arrays(void);
};
}
#endif

View File

@ -1,89 +0,0 @@
/**
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_RENDERER_HPP
#define OUR_DICK_RENDERER_HPP
#include <vector>
#include <variant>
#include <utility> //pair, forward
#include <queue>
#include "math/vec.hpp"
#include "graphics/gl_include.hpp"
struct draw_command{
private:
using uniform_variant = std::variant<GLint,GLuint,GLfloat,math::vec2f,math::vec3f,math::vec4f,math::mat2f,math::mat3f,math::mat4f>;
public:
using framebuffer_type = GLuint;
using shader_type = GLuint;
using vao_type = GLuint;
using uniform_type = GLint;
using uniform_block_type = GLuint;
using binding_type = GLuint;
using shape_type = GLenum;
using texture_type = GLuint;
public:
framebuffer_type framebuffer;
math::vec4f viewport;
shader_type shader;
vao_type vertex_arrays;
shape_type shape;
size_t shape_count;
std::vector<std::pair<uniform_type,uniform_variant>> uniforms;
std::vector<std::pair<uniform_block_type, binding_type>> uniform_blocks;
std::vector<std::pair<texture_type,binding_type>> texture_binds;
GLuint clear = 0;
};
class wip_renderer
{
private:
std::queue<draw_command> m_draws;
public:
wip_renderer(void) = default;
wip_renderer(const wip_renderer&) = default;
wip_renderer(wip_renderer&&) = default;
~wip_renderer(void) = default;
wip_renderer& operator=(const wip_renderer&) = default;
wip_renderer& operator=(wip_renderer&&) = default;
void add_command(const draw_command&);
void add_command(draw_command&&);
template<class... Args>
void emplace_command(Args&&... args);
void render(void);
};
template<class... Args>
void wip_renderer::emplace_command(Args&&... args){
m_draws.emplace(std::forward<Args>(args)...);
}
#endif

View File

@ -19,7 +19,7 @@ ifeq ($(OS),Windows_NT)
WINDOWS::=1 WINDOWS::=1
endif endif
SOURCE_DIRS::=src src/audio src/audio/impl src/graphics src/engine src/ttt SOURCE_DIRS::=src src/audio src/audio/impl src/gfx src/gfx/ogl src/egn src/ttt
SOURCES::= SOURCES::=
OBJDIR::=obj OBJDIR::=obj
DEPDIR::=$(OBJDIR)/dep DEPDIR::=$(OBJDIR)/dep

View File

@ -19,24 +19,24 @@
#include "basic_framebuffer.hpp" #include "basic_framebuffer.hpp"
basic_framebuffer::basic_framebuffer(int width, int height): basic_framebuffer::basic_framebuffer(int width, int height):
gfx::fbo(), gfx::ogl::fbo(),
m_colorbuffer(GL_RGBA, width, height, GL_UNSIGNED_BYTE), m_colorbuffer(GL_RGBA, width, height, GL_UNSIGNED_BYTE),
m_depthbuffer(width, height, GL_DEPTH24_STENCIL8) m_depthbuffer(width, height, GL_DEPTH24_STENCIL8)
{ {
attach(m_colorbuffer, GL_COLOR_ATTACHMENT0); attach(m_colorbuffer, GL_COLOR_ATTACHMENT0);
attach(m_depthbuffer, GL_DEPTH_STENCIL_ATTACHMENT); attach(m_depthbuffer, GL_DEPTH_STENCIL_ATTACHMENT);
} }
gfx::texture& basic_framebuffer::colorbuffer(void){ gfx::ogl::texture& basic_framebuffer::colorbuffer(void){
return m_colorbuffer; return m_colorbuffer;
} }
const gfx::texture& basic_framebuffer::colorbuffer(void)const{ const gfx::ogl::texture& basic_framebuffer::colorbuffer(void)const{
return m_colorbuffer; return m_colorbuffer;
} }
gfx::rbo& basic_framebuffer::depthbuffer(void){ gfx::ogl::rbo& basic_framebuffer::depthbuffer(void){
return m_depthbuffer; return m_depthbuffer;
} }
const gfx::rbo& basic_framebuffer::depthbuffer(void)const{ const gfx::ogl::rbo& basic_framebuffer::depthbuffer(void)const{
return m_depthbuffer; return m_depthbuffer;
} }

View File

@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "engine/base_types.hpp" #include "egn/base_types.hpp"
namespace egn{ namespace egn{

View File

@ -16,32 +16,32 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "engine/camera.hpp" #include "egn/camera.hpp"
#include "config.hpp" #include "config.hpp"
#include "math/projection.hpp" #include "math/projection.hpp"
namespace egn{ namespace egn{
camera_iface::camera_iface(const math::mat4<GLfloat>& proj, GLfloat n, GLfloat f): camera_iface::camera_iface(const math::mat4f& proj, float n, float f):
m_projection_matrix(proj), m_projection_matrix(proj),
m_near(n), m_far(f){} m_near(n), m_far(f){}
void camera_iface::set_position(const math::vec3<GLfloat>& pos){ void camera_iface::set_position(const math::vec3f& pos){
object_base::set_position(pos); object_base::set_position(pos);
m_update_flag |= VIEW_UPDATE; m_update_flag |= VIEW_UPDATE;
} }
void camera_iface::set_orientation(const math::quaternion<GLfloat>& orient){ void camera_iface::set_orientation(const math::quat_f& orient){
object_base::set_orientation(orient); object_base::set_orientation(orient);
m_update_flag |= VIEW_UPDATE; m_update_flag |= VIEW_UPDATE;
} }
const math::mat4<GLfloat>& camera_iface::get_projection_matrix()const{ const math::mat4f& camera_iface::get_projection_matrix()const{
if(m_update_flag & PROJ_UPDATE){ if(m_update_flag & PROJ_UPDATE){
recalc_projection_matrix(); recalc_projection_matrix();
m_update_flag ^= PROJ_UPDATE; m_update_flag ^= PROJ_UPDATE;
} }
return m_projection_matrix; return m_projection_matrix;
} }
const math::mat4<GLfloat>& camera_iface::get_view_matrix()const{ const math::mat4f& camera_iface::get_view_matrix()const{
if(m_update_flag & VIEW_UPDATE){ if(m_update_flag & VIEW_UPDATE){
recalc_view_matrix(); recalc_view_matrix();
m_update_flag ^= VIEW_UPDATE; m_update_flag ^= VIEW_UPDATE;
@ -49,17 +49,17 @@ namespace egn{
return m_view_matrix; return m_view_matrix;
} }
GLfloat camera_iface::get_near_plane()const{ float camera_iface::get_near_plane()const{
return m_near; return m_near;
} }
GLfloat camera_iface::get_far_plane()const{ float camera_iface::get_far_plane()const{
return m_far; return m_far;
} }
void camera_iface::set_near_plane(GLfloat n){ void camera_iface::set_near_plane(float n){
m_update_flag |= PROJ_UPDATE; m_update_flag |= PROJ_UPDATE;
m_near = n; m_near = n;
} }
void camera_iface::set_far_plane(GLfloat f){ void camera_iface::set_far_plane(float f){
m_update_flag |= PROJ_UPDATE; m_update_flag |= PROJ_UPDATE;
m_far = f; m_far = f;
} }
@ -73,26 +73,26 @@ namespace egn{
} }
ortho_camera::ortho_camera(GLfloat w, GLfloat h, GLfloat n, GLfloat f): ortho_camera::ortho_camera(float w, float h, float n, float f):
camera_iface(math::ortho_projection(w, h, n, f), n, f), camera_iface(math::ortho_projection(w, h, n, f), n, f),
m_width(w), m_width(w),
m_height(h){} m_height(h){}
GLfloat ortho_camera::get_projection_width()const{ float ortho_camera::get_projection_width()const{
return m_width; return m_width;
} }
GLfloat ortho_camera::get_projection_height()const{ float ortho_camera::get_projection_height()const{
return m_height; return m_height;
} }
void ortho_camera::set_projection_width(GLfloat w){ void ortho_camera::set_projection_width(float w){
m_update_flag |= PROJ_UPDATE; m_update_flag |= PROJ_UPDATE;
m_width = w; m_width = w;
} }
void ortho_camera::set_projection_height(GLfloat h){ void ortho_camera::set_projection_height(float h){
m_update_flag |= PROJ_UPDATE; m_update_flag |= PROJ_UPDATE;
m_height = h; m_height = h;
} }
void ortho_camera::set_projection_box(GLfloat w, GLfloat h){ void ortho_camera::set_projection_box(float w, float h){
m_update_flag |= PROJ_UPDATE; m_update_flag |= PROJ_UPDATE;
m_width = w; m_width = w;
m_height = h; m_height = h;

View File

@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "engine/collision.hpp" #include "egn/collision.hpp"
#include "engine/base_types.hpp" #include "egn/base_types.hpp"
namespace egn{ namespace egn{

View File

@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "engine/font.hpp" #include "egn/font.hpp"
#include "math/vec.hpp" #include "math/vec.hpp"
#include <cmath> //sqrt, round #include <cmath> //sqrt, round
#include <utility> //move #include <utility> //move
@ -28,7 +28,7 @@ namespace egn{
return ((float)size.x()) / size.y(); return ((float)size.x()) / size.y();
} }
font_atlas::font_atlas(gfx::texture&& t, map_type&& map, size_t w, size_t h): font_atlas::font_atlas(gfx::ogl::texture&& t, map_type&& map, size_t w, size_t h):
texture(std::move(t)), texture(std::move(t)),
m_atlas_data(std::move(map)), m_atlas_data(std::move(map)),
m_requested_width(w), m_requested_width(w),
@ -105,7 +105,7 @@ namespace egn{
src += pitch; src += pitch;
} }
} }
void font::generate_atlas_piece_impl_(gfx::texture& atlas, font_atlas::map_type& metadata, math::vec2<size_t>& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair<int,int>& range){ void font::generate_atlas_piece_impl_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, math::vec2<size_t>& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair<int,int>& range){
const auto& [atlas_width, atlas_height, max_glyph_width, max_glyph_height] = info; const auto& [atlas_width, atlas_height, max_glyph_width, max_glyph_height] = info;
const auto format = (m_depth == 3) ? GL_RGB : GL_RED; const auto format = (m_depth == 3) ? GL_RGB : GL_RED;
const int freetype_load_flags = FT_LOAD_RENDER | ((m_depth == 3) ? FT_LOAD_TARGET_LCD : 0); const int freetype_load_flags = FT_LOAD_RENDER | ((m_depth == 3) ? FT_LOAD_TARGET_LCD : 0);
@ -132,14 +132,14 @@ namespace egn{
} }
} }
std::optional<gfx::texture> font::generate_glyph(char character, int width, int height){ std::optional<gfx::ogl::texture> font::generate_glyph(char character, int width, int height){
FT_Set_Pixel_Sizes(m_face, width, height); FT_Set_Pixel_Sizes(m_face, width, height);
if(FT_Load_Char(m_face, character, FT_LOAD_RENDER | FT_LOAD_TARGET_LCD)){ if(FT_Load_Char(m_face, character, FT_LOAD_RENDER | FT_LOAD_TARGET_LCD)){
debug_print_error("Failed to load character '%c', from font '%s'\n", character, m_face->family_name); debug_print_error("Failed to load character '%c', from font '%s'\n", character, m_face->family_name);
return {}; return {};
} }
auto& bitmap = m_face->glyph->bitmap; auto& bitmap = m_face->glyph->bitmap;
return {gfx::texture(bitmap.buffer, GL_RED, bitmap.width, bitmap.rows, GL_UNSIGNED_BYTE)}; return {gfx::ogl::texture(bitmap.buffer, GL_RED, bitmap.width, bitmap.rows, GL_UNSIGNED_BYTE)};
} }

View File

@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "engine/game.hpp" #include "egn/game.hpp"
#include "graphics/gl_include.hpp" //TODO #include "gfx/ogl/gl_include.hpp" //TODO
#include "config.hpp" #include "config.hpp"
namespace egn{ namespace egn{

View File

@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "engine/game_state.hpp" #include "egn/game_state.hpp"
#include "engine/input.hpp" #include "egn/input.hpp"
#include "config.hpp" #include "config.hpp"
#include <queue> //queue #include <queue> //queue

View File

@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "engine/image.hpp" #include "egn/image.hpp"
#include "engine/stb_include.hpp" #include "egn/stb_include.hpp"
#include "config.hpp" #include "config.hpp"
#include <cstring> //memcpy #include <cstring> //memcpy
#include <utility> //exchange #include <utility> //exchange

View File

@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "engine/object.hpp" #include "egn/object.hpp"
#include "config.hpp" #include "config.hpp"
namespace egn{ namespace egn{

View File

@ -18,7 +18,7 @@
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "engine/stb_alloc.hpp" #include "egn/stb_alloc.hpp"
#define STBI_MALLOC(size) our_dick_stb_malloc(size) #define STBI_MALLOC(size) our_dick_stb_malloc(size)
#define STBI_FREE(data) our_dick_stb_free(data) #define STBI_FREE(data) our_dick_stb_free(data)

View File

@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "engine/stb_alloc.hpp" #include "egn/stb_alloc.hpp"
#include <cstdlib> //size_t #include <cstdlib> //size_t
#include <new> //new, delete #include <new> //new, delete

View File

@ -16,10 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/init.hpp" #include "gfx/init.hpp"
#include "config.hpp" #include "config.hpp"
#include "graphics/gl_include.hpp" #include "gfx/ogl/gl_include.hpp"
#include <mutex> //lock_guard, mutex #include <mutex> //lock_guard, mutex

View File

@ -16,33 +16,33 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/lightable.hpp" #include "gfx/lightable.hpp"
namespace gfx{ namespace gfx{
void lightable::set_ambient(const math::vec3<GLfloat>& a){ void lightable::set_ambient(const math::vec3f& a){
m_ambient = a; m_ambient = a;
} }
void lightable::set_diffuse(const math::vec3<GLfloat>& d){ void lightable::set_diffuse(const math::vec3f& d){
m_diffuse = d; m_diffuse = d;
} }
void lightable::set_specular(const math::vec3<GLfloat>& s){ void lightable::set_specular(const math::vec3f& s){
m_specular = s; m_specular = s;
} }
void lightable::set_shininess(GLfloat s){ void lightable::set_shininess(float s){
m_shininess = s; m_shininess = s;
} }
const math::vec3<GLfloat>& lightable::get_ambient()const{ const math::vec3f& lightable::get_ambient()const{
return m_ambient; return m_ambient;
} }
const math::vec3<GLfloat>& lightable::get_diffuse()const{ const math::vec3f& lightable::get_diffuse()const{
return m_diffuse; return m_diffuse;
} }
const math::vec3<GLfloat>& lightable::get_specular()const{ const math::vec3f& lightable::get_specular()const{
return m_specular; return m_specular;
} }
GLfloat lightable::get_shininess()const{ float lightable::get_shininess()const{
return m_shininess; return m_shininess;
} }

View File

@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/material.hpp" #include "gfx/material.hpp"
#include <utility> //move #include <utility> //move

View File

@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/mesh.hpp" #include "gfx/mesh.hpp"
#include "config.hpp" #include "config.hpp"
#include <cstdlib> //offsetof #include <cstdlib> //offsetof
@ -26,20 +26,20 @@ namespace gfx{
vertex_mesh::vertex_mesh(const std::vector<vertex>& verts): vertex_mesh::vertex_mesh(const std::vector<vertex>& verts):
m_vertices(verts), m_vertices(verts),
m_vbo(&verts[0], sizeof(vertex) * verts.size(), buffer::usage::STATIC_DRAW) m_vbo(&verts[0], sizeof(vertex) * verts.size(), ogl::buffer::usage::STATIC_DRAW)
{ {
m_vao.bind_buffer(m_vbo, 0, 0, sizeof(vertex)); m_vao.bind_buffer(m_vbo, 0, 0, sizeof(vertex));
configure(); configure();
} }
vertex_mesh::vertex_mesh(std::vector<vertex>&& verts): vertex_mesh::vertex_mesh(std::vector<vertex>&& verts):
m_vertices(std::move(verts)), m_vertices(std::move(verts)),
m_vbo(&verts[0], sizeof(vertex) * verts.size(), buffer::usage::STATIC_DRAW) m_vbo(&verts[0], sizeof(vertex) * verts.size(), ogl::buffer::usage::STATIC_DRAW)
{ {
m_vao.bind_buffer(m_vbo, 0, 0, sizeof(vertex)); m_vao.bind_buffer(m_vbo, 0, 0, sizeof(vertex));
configure(); configure();
} }
vertex_mesh::vertex_mesh(const vertex* verts, size_t nverts): vertex_mesh::vertex_mesh(const vertex* verts, size_t nverts):
m_vbo(verts, sizeof(vertex) * nverts, buffer::usage::STATIC_DRAW) m_vbo(verts, sizeof(vertex) * nverts, ogl::buffer::usage::STATIC_DRAW)
{ {
m_vertices.reserve(nverts); m_vertices.reserve(nverts);
for(size_t i = 0;i < nverts;++i) for(size_t i = 0;i < nverts;++i)
@ -70,7 +70,7 @@ namespace gfx{
void vertex_mesh::set_vertex(size_t index, const vertex& v){ void vertex_mesh::set_vertex(size_t index, const vertex& v){
m_vertices[index] = v; m_vertices[index] = v;
} }
void vertex_mesh::render(shader_program&){ void vertex_mesh::render(ogl::shader_program&){
m_vao.bind(); m_vao.bind();
glDrawArrays(GL_TRIANGLES, 0, m_vertices.size()); glDrawArrays(GL_TRIANGLES, 0, m_vertices.size());
} }
@ -95,7 +95,7 @@ namespace gfx{
void material_mesh::set_material(size_t index, const material* new_texture){ void material_mesh::set_material(size_t index, const material* new_texture){
m_materials[index] = new_texture; m_materials[index] = new_texture;
} }
void material_mesh::render(shader_program& shader){ void material_mesh::render(ogl::shader_program& shader){
size_t tex1_loc = shader.get_uniform_loc("texture1"); size_t tex1_loc = shader.get_uniform_loc("texture1");
for(size_t i = 0;i < m_materials.size();++i){ for(size_t i = 0;i < m_materials.size();++i){
m_materials[i]->bind_unit(i); m_materials[i]->bind_unit(i);
@ -125,7 +125,7 @@ namespace gfx{
void unified_mesh::configure(){ void unified_mesh::configure(){
m_v_mesh.configure(); m_v_mesh.configure();
} }
void unified_mesh::render(shader_program& shader){ void unified_mesh::render(ogl::shader_program& shader){
m_m_mesh.render(shader); m_m_mesh.render(shader);
m_v_mesh.render(shader); m_v_mesh.render(shader);
} }

View File

@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/model.hpp" #include "gfx/model.hpp"
#include <utility> //move #include <utility> //move
@ -44,7 +44,7 @@ namespace gfx{
const unified_mesh& model::mesh(size_t index)const{ const unified_mesh& model::mesh(size_t index)const{
return m_meshes[index]; return m_meshes[index];
} }
void model::render(shader_program& s){ void model::render(ogl::shader_program& s){
for(size_t i = 0;i < m_meshes.size();++i){ for(size_t i = 0;i < m_meshes.size();++i){
m_meshes[i].render(s); m_meshes[i].render(s);
} }

View File

@ -16,13 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/buffer_map.hpp" #include "gfx/ogl/buffer_map.hpp"
#include "config.hpp" #include "config.hpp"
#include <utility> //exchange, swap #include <utility> //exchange, swap
namespace gfx{ namespace gfx::ogl{
scoped_buffer_map<void>::scoped_buffer_map(GLuint bid, buffer::maptype m): scoped_buffer_map<void>::scoped_buffer_map(GLuint bid, buffer::maptype m):
m_buffer(bid) m_buffer(bid)

View File

@ -16,11 +16,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/fbo.hpp" #include "gfx/ogl/fbo.hpp"
#include <utility> //swap, exchange #include <utility> //swap, exchange
#include "config.hpp" #include "config.hpp"
namespace gfx{ namespace gfx::ogl{
fbo::fbo(){ fbo::fbo(){
glCreateFramebuffers(1, &m_buffer); glCreateFramebuffers(1, &m_buffer);

View File

@ -16,10 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/rbo.hpp" #include "gfx/ogl/rbo.hpp"
#include <utility> //swap, exchange #include <utility> //swap, exchange
namespace gfx{ namespace gfx::ogl{
rbo::rbo(GLsizei width, GLsizei height, GLenum format, GLsizei samples): rbo::rbo(GLsizei width, GLsizei height, GLenum format, GLsizei samples):
m_format(format), m_format(format),

View File

@ -16,13 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/shader.hpp" #include "gfx/ogl/shader.hpp"
#include "config.hpp" #include "config.hpp"
#include <utility> //exchange, swap #include <utility> //exchange, swap
#include <string> #include <string>
namespace gfx{ namespace gfx::ogl{
shader::shader(type t): shader::shader(type t):
m_shader_id(glCreateShader(static_cast<GLuint>(t))){} m_shader_id(glCreateShader(static_cast<GLuint>(t))){}

View File

@ -16,14 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/shader_program.hpp" #include "gfx/ogl/shader_program.hpp"
#include "config.hpp" #include "config.hpp"
#include <utility> //exchange, swap #include <utility> //exchange, swap
#include <string> #include <string>
#include <memory> //unique_ptr #include <memory> //unique_ptr
namespace gfx{ namespace gfx::ogl{
shader_program::shader_program(void): shader_program::shader_program(void):
m_shader_id(glCreateProgram()){} m_shader_id(glCreateProgram()){}

View File

@ -16,13 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/texture.hpp" #include "gfx/ogl/texture.hpp"
#include "config.hpp" #include "config.hpp"
#include <utility> //exchange, swap #include <utility> //exchange, swap
#include <rexy/utility.hpp> #include <rexy/utility.hpp>
namespace gfx{ namespace gfx::ogl{
[[maybe_unused]] [[maybe_unused]]
static constexpr bool is_format_compatible(GLenum format, int channel_count){ static constexpr bool is_format_compatible(GLenum format, int channel_count){

View File

@ -16,10 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/vao.hpp" #include "gfx/ogl/vao.hpp"
#include <utility> //exchange, swap #include <utility> //exchange, swap
namespace gfx{ namespace gfx::ogl{
void vertex_attribute::enable(){ void vertex_attribute::enable(){
glEnableVertexArrayAttrib(m_vao, m_index); glEnableVertexArrayAttrib(m_vao, m_index);

View File

@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/vbo.hpp" #include "gfx/ogl/vbo.hpp"
#include "config.hpp" #include "config.hpp"
#include <rexy/utility.hpp> #include <rexy/utility.hpp>
@ -24,7 +24,7 @@
#include <cstring> //memset #include <cstring> //memset
namespace gfx{ namespace gfx::ogl{
vbo::vbo(size_t size, buffer::usage t): vbo::vbo(size_t size, buffer::usage t):
m_buffer_size(0) m_buffer_size(0)

View File

@ -16,15 +16,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/window.hpp" #include "gfx/ogl/window.hpp"
#include "graphics/init.hpp" #include "gfx/init.hpp"
#include "graphics/backend_check.hpp" #include "gfx/backend_check.hpp"
#include <utility> //exchange, swap, pair #include <utility> //exchange, swap, pair
#include <cstring> //strlen, strncpy #include <cstring> //strlen, strncpy
#include "config.hpp" #include "config.hpp"
namespace gfx{ namespace gfx::ogl{
#ifdef OUR_DICK_ENABLE_DEBUG_CONTEXT #ifdef OUR_DICK_ENABLE_DEBUG_CONTEXT
static void APIENTRY our_dick_gl_debug_output(GLenum source, GLenum type, unsigned int /*id*/, GLenum severity, static void APIENTRY our_dick_gl_debug_output(GLenum source, GLenum type, unsigned int /*id*/, GLenum severity,

View File

@ -16,14 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "graphics/resource_manager.hpp" #include "gfx/resource_manager.hpp"
namespace gfx{ namespace gfx{
bool resource_manager::has_texture_array(const char* key)const{ bool resource_manager::has_texture_array(const char* key)const{
return m_texture_arrays.has_value(key); return m_texture_arrays.has_value(key);
} }
auto resource_manager::get_texture_array(const char* file) -> container_type<texture_array>::node{ auto resource_manager::get_texture_array(const char* file) -> container_type<ogl::texture_array>::node{
return m_texture_arrays.get_value(file); return m_texture_arrays.get_value(file);
} }
bool resource_manager::erase_texture_array(const char* key){ bool resource_manager::erase_texture_array(const char* key){
@ -33,7 +33,7 @@ namespace gfx{
bool resource_manager::has_texture(const char* key)const{ bool resource_manager::has_texture(const char* key)const{
return m_textures.has_value(key); return m_textures.has_value(key);
} }
auto resource_manager::get_texture(const char* file) -> container_type<texture>::node{ auto resource_manager::get_texture(const char* file) -> container_type<ogl::texture>::node{
return m_textures.get_value(file); return m_textures.get_value(file);
} }
bool resource_manager::erase_texture(const char* key){ bool resource_manager::erase_texture(const char* key){
@ -53,7 +53,7 @@ namespace gfx{
bool resource_manager::has_shader(const char* key)const{ bool resource_manager::has_shader(const char* key)const{
return m_shaders.has_value(key); return m_shaders.has_value(key);
} }
auto resource_manager::get_shader(const char* key) -> container_type<shader_program>::node{ auto resource_manager::get_shader(const char* key) -> container_type<ogl::shader_program>::node{
return m_shaders.get_value(key); return m_shaders.get_value(key);
} }
bool resource_manager::erase_shader(const char* key){ bool resource_manager::erase_shader(const char* key){

View File

@ -25,9 +25,7 @@
#include "config.hpp" #include "config.hpp"
#include "ttt/tic_tac_toe.hpp" #include "ttt/tic_tac_toe.hpp"
#include "engine/font.hpp" #include "egn/font.hpp"
#include "graphics/ubo.hpp"
#include "math/debug.hpp" #include "math/debug.hpp"

View File

@ -19,8 +19,6 @@
#include "ttt/board.hpp" #include "ttt/board.hpp"
#include "ttt/board_gfx.hpp" #include "ttt/board_gfx.hpp"
#include "graphics/gl_include.hpp" //GLfloat
void tile::set_value(value t){ void tile::set_value(value t){
m_active_value = t; m_active_value = t;
} }
@ -49,7 +47,7 @@ board::board(gfx::resource_manager& resman):
m_tiles[8].set_position({ 2.125, -2.125, -1}); m_tiles[8].set_position({ 2.125, -2.125, -1});
} }
void board::render(gfx::shader_program& sh){ void board::render(gfx::ogl::shader_program& sh){
m_gfx->buffer_tiles(m_tiles.get()); m_gfx->buffer_tiles(m_tiles.get());
m_gfx->render(sh); m_gfx->render(sh);
} }
@ -62,15 +60,15 @@ bool board::is_full(void)const{
return true; return true;
} }
int board::click_collision_cheat(const math::vec3<GLfloat>& unproj_3)const{ int board::click_collision_cheat(const math::vec3f& unproj_3)const{
math::vec4<GLfloat> unproj_4 = {unproj_3[0], unproj_3[1], unproj_3[2], 1}; math::vec4f unproj_4 = {unproj_3[0], unproj_3[1], unproj_3[2], 1};
math::vec4<GLfloat> mod_coord = model_matrix().inverse() * unproj_4; math::vec4f mod_coord = model_matrix().inverse() * unproj_4;
mod_coord /= mod_coord[3]; mod_coord /= mod_coord[3];
math::vec3<GLfloat> projected1 = {mod_coord[0], mod_coord[1], mod_coord[2]}; math::vec3f projected1 = {mod_coord[0], mod_coord[1], mod_coord[2]};
for(size_t i = 0;i < 9;++i){ for(size_t i = 0;i < 9;++i){
const tile& sq = m_tiles[i]; const tile& sq = m_tiles[i];
const math::vec3<GLfloat>& sq_pos = sq.position(); const math::vec3f& sq_pos = sq.position();
if((projected1.x() > (sq_pos.x() - 1.0f) && projected1.x() < (sq_pos.x() + 1.0f)) && if((projected1.x() > (sq_pos.x() - 1.0f) && projected1.x() < (sq_pos.x() + 1.0f)) &&
(projected1.y() > (sq_pos.y() - 1.0f) && projected1.y() < (sq_pos.y() + 1.0f))) (projected1.y() > (sq_pos.y() - 1.0f) && projected1.y() < (sq_pos.y() + 1.0f)))
{ {

View File

@ -20,7 +20,7 @@
#include "ttt/board.hpp" #include "ttt/board.hpp"
board_gfx::board_gfx(gfx::resource_manager& resman): board_gfx::board_gfx(gfx::resource_manager& resman):
m_vbo((16 * sizeof(GLfloat) + 4 * sizeof(GLfloat) + 1 * sizeof(GLint)) * 9, gfx::buffer::usage::DYNAMIC_DRAW) m_vbo((16 * sizeof(GLfloat) + 4 * sizeof(GLfloat) + 1 * sizeof(GLint)) * 9, gfx::ogl::buffer::usage::DYNAMIC_DRAW)
{ {
auto result = resman.emplace_texture_array("board_textures", 3); auto result = resman.emplace_texture_array("board_textures", 3);
m_textures = std::move(result.first); m_textures = std::move(result.first);
@ -63,7 +63,7 @@ board_gfx::board_gfx(gfx::resource_manager& resman):
attrib.enable(); attrib.enable();
} }
void board_gfx::set_uniforms(gfx::shader_program& sh){ void board_gfx::set_uniforms(gfx::ogl::shader_program& sh){
sh.get_uniform("textures").set(*m_textures, 0); sh.get_uniform("textures").set(*m_textures, 0);
} }
void board_gfx::bind_buffers(void){ void board_gfx::bind_buffers(void){
@ -80,7 +80,7 @@ void board_gfx::buffer_tiles(const tile* t){
} }
} }
void board_gfx::render(gfx::shader_program& shader){ void board_gfx::render(gfx::ogl::shader_program& shader){
set_uniforms(shader); set_uniforms(shader);
bind_buffers(); bind_buffers();
glDrawArrays(GL_POINTS, 0, 9); glDrawArrays(GL_POINTS, 0, 9);

View File

@ -17,7 +17,7 @@
*/ */
#include "ttt/main_renderer.hpp" #include "ttt/main_renderer.hpp"
#include "graphics/shader.hpp" #include "gfx/ogl/shader.hpp"
#include "ttt/square_shader.hpp" #include "ttt/square_shader.hpp"
#include "ttt/screen_shader.hpp" #include "ttt/screen_shader.hpp"
#include "util/deferred.hpp" #include "util/deferred.hpp"
@ -31,20 +31,20 @@
main_renderer::main_renderer(gfx::resource_manager& res, int width, int height): main_renderer::main_renderer(gfx::resource_manager& res, int width, int height):
m_fb(MAX_WIDTH, MAX_HEIGHT), m_fb(MAX_WIDTH, MAX_HEIGHT),
m_primary_fb(util::no_initialize), m_primary_fb(util::no_initialize),
m_vbo(s_vertices, sizeof(s_vertices), gfx::buffer::usage::DYNAMIC_DRAW), m_vbo(s_vertices, sizeof(s_vertices), gfx::ogl::buffer::usage::DYNAMIC_DRAW),
m_board_vbo((16*sizeof(GLfloat)+sizeof(GLint)+4*sizeof(GLfloat)) * 9, gfx::buffer::usage::DYNAMIC_DRAW) m_board_vbo((16*sizeof(GLfloat)+sizeof(GLint)+4*sizeof(GLfloat)) * 9, gfx::ogl::buffer::usage::DYNAMIC_DRAW)
{ {
m_square_shader = res.emplace_shader("square_shader", util::make_deferred<gfx::shader>(square_shader::fragment_shader_text, gfx::shader::type::FRAGMENT), m_square_shader = res.emplace_shader("square_shader", util::make_deferred<gfx::ogl::shader>(square_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT),
util::make_deferred<gfx::shader>(square_shader::geometry_shader_text, gfx::shader::type::GEOMETRY), util::make_deferred<gfx::ogl::shader>(square_shader::geometry_shader_text, gfx::ogl::shader::type::GEOMETRY),
util::make_deferred<gfx::shader>(square_shader::vertex_shader_text, gfx::shader::type::VERTEX)).first; util::make_deferred<gfx::ogl::shader>(square_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX)).first;
if(m_square_shader->has_link_error()){ if(m_square_shader->has_link_error()){
debug_print_error("%s\n", m_square_shader->get_error().c_str()); debug_print_error("%s\n", m_square_shader->get_error().c_str());
} }
m_square_shader->get_uniform("vp_mat").set(math::mat4<GLfloat>{}); m_square_shader->get_uniform("vp_mat").set(math::mat4<GLfloat>{});
m_screen_shader = res.emplace_shader("screen_shader", util::make_deferred<gfx::shader>(screen_shader::fragment_shader_text, gfx::shader::type::FRAGMENT), m_screen_shader = res.emplace_shader("screen_shader", util::make_deferred<gfx::ogl::shader>(screen_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT),
util::make_deferred<gfx::shader>(screen_shader::vertex_shader_text, gfx::shader::type::VERTEX)).first; util::make_deferred<gfx::ogl::shader>(screen_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX)).first;
m_screen_shader->get_uniform("vp_mat").set(math::mat4<GLfloat>{}); m_screen_shader->get_uniform("vp_mat").set(math::mat4<GLfloat>{});
m_vao.bind_buffer(m_vbo, 0, 0, sizeof(vertex)); m_vao.bind_buffer(m_vbo, 0, 0, sizeof(vertex));
@ -87,7 +87,7 @@ void main_renderer::render(scene& s){
void main_renderer::resize_viewport(int width, int height){ void main_renderer::resize_viewport(int width, int height){
m_fb.set_viewport(0, 0, width, height); m_fb.set_viewport(0, 0, width, height);
auto map = m_vbo.map(gfx::buffer::maptype::WRITE); auto map = m_vbo.map(gfx::ogl::buffer::maptype::WRITE);
vertex* data = reinterpret_cast<vertex*>(map.raw()); vertex* data = reinterpret_cast<vertex*>(map.raw());
GLfloat x1 = 0, y1 = 0; GLfloat x1 = 0, y1 = 0;
GLfloat x2 = (GLfloat)width / m_fb.colorbuffer().get_width(); GLfloat x2 = (GLfloat)width / m_fb.colorbuffer().get_width();

View File

@ -17,10 +17,10 @@
*/ */
#include "ttt/pause_state.hpp" #include "ttt/pause_state.hpp"
#include "engine/game.hpp" #include "egn/game.hpp"
#include "util/deferred.hpp" #include "util/deferred.hpp"
#include "graphics/gl_include.hpp" //TODO #include "gfx/ogl/gl_include.hpp" //TODO
#include "config.hpp" #include "config.hpp"

View File

@ -19,11 +19,11 @@
#include "ttt/play_state.hpp" #include "ttt/play_state.hpp"
#include "ttt/pause_state.hpp" #include "ttt/pause_state.hpp"
#include "graphics/gl_include.hpp" //TODO: separate key definitions from GLFW #include "gfx/ogl/gl_include.hpp" //TODO: separate key definitions from GLFW
#include "engine/image.hpp" //TODO: move image to engine namespace #include "egn/image.hpp" //TODO: move image to engine namespace
#include "math/math.hpp" #include "math/math.hpp"
#include "config.hpp" #include "config.hpp"
#include "engine/game.hpp" #include "egn/game.hpp"
#include "ttt/board.hpp" #include "ttt/board.hpp"
play_state::play_state(egn::game& owner, int width, int height): play_state::play_state(egn::game& owner, int width, int height):

View File

@ -18,24 +18,24 @@
#include "ttt/screen_renderer.hpp" #include "ttt/screen_renderer.hpp"
#include "graphics/shader.hpp" #include "gfx/ogl/shader.hpp"
#include "ttt/screen_shader.hpp" #include "ttt/screen_shader.hpp"
#include "util/deferred.hpp" #include "util/deferred.hpp"
#include <tuple> #include <tuple>
#include <utility> //piecewise_construct #include <utility> //piecewise_construct
#include "engine/font.hpp" #include "egn/font.hpp"
#include "ttt/font_shader.hpp" #include "ttt/font_shader.hpp"
#include "math/debug.hpp" #include "math/debug.hpp"
screen_renderer::screen_renderer(gfx::resource_manager& res, int width, int height, const std::shared_ptr<gfx::texture>& base_tex): screen_renderer::screen_renderer(gfx::resource_manager& res, int width, int height, const std::shared_ptr<gfx::ogl::texture>& base_tex):
m_vbo(s_vertices, sizeof(s_vertices), gfx::buffer::usage::DYNAMIC_DRAW), m_vbo(s_vertices, sizeof(s_vertices), gfx::ogl::buffer::usage::DYNAMIC_DRAW),
m_texture(base_tex), m_texture(base_tex),
m_screen_width(width), m_screen_height(height) m_screen_width(width), m_screen_height(height)
{ {
m_screen_shader = res.emplace_shader("screen_shader", util::make_deferred<gfx::shader>(screen_shader::vertex_shader_text, gfx::shader::type::VERTEX), m_screen_shader = res.emplace_shader("screen_shader", util::make_deferred<gfx::ogl::shader>(screen_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX),
util::make_deferred<gfx::shader>(screen_shader::fragment_shader_text, gfx::shader::type::FRAGMENT)).first; util::make_deferred<gfx::ogl::shader>(screen_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT)).first;
if(m_screen_shader->has_link_error()){ if(m_screen_shader->has_link_error()){
debug_print_error("%s\n", m_screen_shader->get_error().c_str()); debug_print_error("%s\n", m_screen_shader->get_error().c_str());
} }

View File

@ -17,7 +17,7 @@
*/ */
#include "ttt/tic_tac_toe.hpp" #include "ttt/tic_tac_toe.hpp"
#include "engine/game_state.hpp" #include "egn/game_state.hpp"
#include "ttt/play_state.hpp" #include "ttt/play_state.hpp"
#include "config.hpp" #include "config.hpp"

View File

@ -1,59 +0,0 @@
/**
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/>.
*/
#include "wip_renderer.hpp"
#include "graphics/shader_program.hpp"
#include "graphics/gl_include.hpp"
void wip_renderer::add_command(const draw_command& c){
m_draws.push(c);
}
void wip_renderer::add_command(draw_command&& c){
m_draws.push(std::move(c));
}
void wip_renderer::render(void){
while(!m_draws.empty()){
auto& command = m_draws.front();
glBindFramebuffer(GL_FRAMEBUFFER, command.framebuffer);
glViewport(command.viewport[0], command.viewport[1],
command.viewport[2], command.viewport[3]);
if(command.clear)
glClear(command.clear);
glUseProgram(command.shader);
glBindVertexArray(command.vertex_arrays);
for(auto& uniform_pair : command.uniforms){
gfx::uniform tmp{command.shader, uniform_pair.first};
std::visit([&](const auto& i){tmp.set(i);}, uniform_pair.second);
}
for(auto& uniform_block_pair : command.uniform_blocks){
gfx::uniform_block tmp{command.shader, uniform_block_pair.first};
tmp.set_binding(uniform_block_pair.second);
}
for(auto& texture_bind_pair : command.texture_binds){
glBindTextureUnit(texture_bind_pair.second, texture_bind_pair.first);
}
glDrawArrays(command.shape, 0, command.shape_count);
m_draws.pop();
}
}