diff --git a/include/simpleengine/camera.h b/include/simpleengine/camera.h index 4118fd7..a78c850 100644 --- a/include/simpleengine/camera.h +++ b/include/simpleengine/camera.h @@ -31,7 +31,7 @@ namespace simpleengine { float near_plane = 0.1f, float far_plane = 1000.f, glm::vec3 world_up = glm::vec3(0.f, 1.f, 0.f), glm::vec3 cam_front = glm::vec3(0.f, 0.f, -1.f)); - Camera(GLFWwindow* window, std::shared_ptr shader_prog, float fov = 70, glm::vec3 position = glm::vec3(0.f), + Camera(GLFWwindow* window, GLuint shader_prog, float fov = 70, glm::vec3 position = glm::vec3(0.f), glm::vec3 rotation = glm::vec3(0.f), float near_plane = 0.1f, float far_plane = 1000.f, glm::vec3 world_up = glm::vec3(0.f, 1.f, 0.f), glm::vec3 cam_front = glm::vec3(0.f, 0.f, -1.f)); diff --git a/include/simpleengine/game.h b/include/simpleengine/game.h index 90dfa12..9a87ee4 100644 --- a/include/simpleengine/game.h +++ b/include/simpleengine/game.h @@ -6,7 +6,7 @@ #ifdef __linux__ #include -#elif +#else #include #endif diff --git a/include/simpleengine/gfx/model.h b/include/simpleengine/gfx/model.h index 5935405..4ab41b5 100644 --- a/include/simpleengine/gfx/model.h +++ b/include/simpleengine/gfx/model.h @@ -21,7 +21,7 @@ namespace simpleengine::gfx { gfx::Shader shader; Model(GLFWwindow* window, gfx::Shader shader, std::vector vertices, std::vector indicies = std::vector()); - Model(GLFWwindow* window, std::shared_ptr shader_program, std::vector vertices, + Model(GLFWwindow* window, GLuint shader_program, std::vector vertices, std::vector indicies = std::vector()); protected: void setup_vertexes(); diff --git a/include/simpleengine/gfx/shader.h b/include/simpleengine/gfx/shader.h index e542dee..8fc581a 100644 --- a/include/simpleengine/gfx/shader.h +++ b/include/simpleengine/gfx/shader.h @@ -5,7 +5,7 @@ #ifdef __linux__ #include #include -#elif +#else #include #include #endif @@ -39,21 +39,17 @@ namespace simpleengine::gfx { }; class Shader { - protected: - Shader() { - - } public: - std::shared_ptr program; + GLuint program; GLuint shader; - Shader(std::shared_ptr program); - - Shader(std::shared_ptr program, GLuint shader); + Shader() = default; + Shader(GLuint program); + Shader(GLuint program, GLuint shader); static Shader from_source(const ShaderType& type, std::string& shader_source); - static Shader from_source(std::shared_ptr program, const ShaderType& type, std::string& shader_source); + static Shader from_source(GLuint program, const ShaderType& type, std::string& shader_source); /** * @brief Load a shader from a filepath. @@ -70,7 +66,7 @@ namespace simpleengine::gfx { * @param type The type of the shader. * @param shader_path The path of shader source. */ - static Shader from_filepath(std::shared_ptr program, const ShaderType& type, const std::string& shader_path); + static Shader from_filepath(GLuint program, const ShaderType& type, const std::string& shader_path); virtual ~Shader(); @@ -103,7 +99,7 @@ namespace simpleengine::gfx { * * @param program The program to attach the shader to. */ - void attach(std::shared_ptr program); + void attach(GLuint program); /** * @brief Get the location of the uniform variable in the shader. diff --git a/include/simpleengine/gfx/texture.h b/include/simpleengine/gfx/texture.h index a1c0fc2..5194c60 100644 --- a/include/simpleengine/gfx/texture.h +++ b/include/simpleengine/gfx/texture.h @@ -3,7 +3,7 @@ #ifdef __linux__ #include #include -#elif +#else #include #include #endif diff --git a/include/simpleengine/gfx/textured_model.h b/include/simpleengine/gfx/textured_model.h index 935e568..bba943b 100644 --- a/include/simpleengine/gfx/textured_model.h +++ b/include/simpleengine/gfx/textured_model.h @@ -22,7 +22,7 @@ namespace simpleengine::gfx { TexturedModel(GLFWwindow* window, gfx::Shader shader, gfx::Texture texture, std::vector vertices, std::vector indicies = std::vector()); - TexturedModel(GLFWwindow* window, std::shared_ptr shader_program, gfx::Texture texture, std::vector vertices, + TexturedModel(GLFWwindow* window, GLuint shader_program, gfx::Texture texture, std::vector vertices, std::vector indicies = std::vector()); virtual void update(const float& delta_time) override; diff --git a/include/simpleengine/gfx/vao.h b/include/simpleengine/gfx/vao.h index ad86891..ee1644d 100644 --- a/include/simpleengine/gfx/vao.h +++ b/include/simpleengine/gfx/vao.h @@ -3,7 +3,7 @@ #ifdef __linux__ #include #include -#elif +#else #include #include #endif diff --git a/include/simpleengine/gfx/vbo.h b/include/simpleengine/gfx/vbo.h index 4ab1839..49214a4 100644 --- a/include/simpleengine/gfx/vbo.h +++ b/include/simpleengine/gfx/vbo.h @@ -3,7 +3,7 @@ #ifdef __linux__ #include #include -#elif +#else #include #include #endif diff --git a/include/simpleengine/shader_program.h b/include/simpleengine/shader_program.h index 8739786..ec3880d 100644 --- a/include/simpleengine/shader_program.h +++ b/include/simpleengine/shader_program.h @@ -3,7 +3,7 @@ #ifdef __linux__ #include #include -#elif +#else #include #include #endif @@ -26,15 +26,15 @@ namespace simpleengine { private: using super = simpleengine::Event; public: - std::shared_ptr program; + GLuint program; std::vector shaders; - ShaderProgram() : program(std::make_shared(glCreateProgram())) { + ShaderProgram() : program(glCreateProgram()) { } virtual ~ShaderProgram() { - glDeleteProgram(*program); + glDeleteProgram(program); } /** @@ -93,10 +93,10 @@ namespace simpleengine { throw std::runtime_error("Shaders cannot be empty when running simpleengine::ShaderProgram::link()!"); } - glLinkProgram(*program); + glLinkProgram(program); GLint success = false; - glGetProgramiv(*program, GL_LINK_STATUS, &success); + glGetProgramiv(program, GL_LINK_STATUS, &success); if (!success) { std::cerr << "Failed to link shader program!" << std::endl; @@ -113,7 +113,7 @@ namespace simpleengine { } virtual void render(GLFWwindow* target) { - glUseProgram(*program); + glUseProgram(program); } }; } \ No newline at end of file diff --git a/include/simpleengine/vertex.h b/include/simpleengine/vertex.h index 98aec1b..baf1616 100644 --- a/include/simpleengine/vertex.h +++ b/include/simpleengine/vertex.h @@ -4,7 +4,7 @@ #ifdef __linux__ #include #include -#elif +#else #include #include #endif diff --git a/src/camera.cpp b/src/camera.cpp index 454ba18..e56d217 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -13,7 +13,7 @@ namespace simpleengine { projection_matrix = glm::perspective(glm::radians(fov), ((float) width) / height, near_plane, far_plane); } - Camera::Camera(GLFWwindow* window, std::shared_ptr shader_prog, float fov, glm::vec3 position, glm::vec3 rotation, + Camera::Camera(GLFWwindow* window, GLuint shader_prog, float fov, glm::vec3 position, glm::vec3 rotation, float near_plane, float far_plane, glm::vec3 world_up, glm::vec3 cam_front) : Camera(window, gfx::Shader(shader_prog), fov, position, rotation, near_plane, far_plane, world_up, cam_front) { diff --git a/src/game.cpp b/src/game.cpp index 7780f9f..9cc4a3c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -7,7 +7,7 @@ #include #include #include -#elif +#else #include #include #include diff --git a/src/gfx/model.cpp b/src/gfx/model.cpp index 9786723..0b6e67f 100644 --- a/src/gfx/model.cpp +++ b/src/gfx/model.cpp @@ -8,7 +8,7 @@ namespace simpleengine::gfx { setup_vertexes(); } - Model::Model(GLFWwindow* window, std::shared_ptr shader_program, std::vector vertices, std::vector indicies) : + Model::Model(GLFWwindow* window, GLuint shader_program, std::vector vertices, std::vector indicies) : Model(window, gfx::Shader(shader_program), vertices, indicies) { } diff --git a/src/gfx/shader.cpp b/src/gfx/shader.cpp index 701cfc0..025cf66 100644 --- a/src/gfx/shader.cpp +++ b/src/gfx/shader.cpp @@ -5,16 +5,16 @@ #include namespace simpleengine::gfx { - Shader::Shader(std::shared_ptr program) : program(program) { + Shader::Shader(GLuint program) : program(program) { } - Shader::Shader(std::shared_ptr program, GLuint shader) : program(program), shader(shader) { + Shader::Shader(GLuint program, GLuint shader) : program(program), shader(shader) { } Shader Shader::from_source(const ShaderType& type, std::string& shader_source) { - Shader shd = Shader::from_source(std::make_shared(glCreateProgram()), type, shader_source); + Shader shd = Shader::from_source(glCreateProgram(), type, shader_source); shd.link(); shd.delete_shader(); @@ -22,7 +22,7 @@ namespace simpleengine::gfx { return shd; } - Shader Shader::from_source(std::shared_ptr program, const ShaderType& type, std::string& shader_source) { + Shader Shader::from_source(GLuint program, const ShaderType& type, std::string& shader_source) { Shader shd; shd.program = program; shd.shader = glCreateShader(type); @@ -48,7 +48,7 @@ namespace simpleengine::gfx { } Shader Shader::from_filepath(const ShaderType& type, const std::string& shader_path) { - Shader shd = Shader::from_filepath(std::make_shared(glCreateProgram()), type, shader_path); + Shader shd = Shader::from_filepath(glCreateProgram(), type, shader_path); shd.link(); shd.delete_shader(); @@ -56,7 +56,7 @@ namespace simpleengine::gfx { return shd; } - Shader Shader::from_filepath(std::shared_ptr program, const ShaderType& type, + Shader Shader::from_filepath(GLuint program, const ShaderType& type, const std::string& shader_path) { std::ifstream fstream(shader_path, std::ios::in); @@ -83,10 +83,10 @@ namespace simpleengine::gfx { } void Shader::link() { - glLinkProgram(*program); + glLinkProgram(program); GLint success = false; - glGetProgramiv(*program, GL_LINK_STATUS, &success); + glGetProgramiv(program, GL_LINK_STATUS, &success); if (!success) { std::cerr << "Failed to link shader program!" << std::endl; @@ -99,15 +99,15 @@ namespace simpleengine::gfx { } void Shader::use() const { - glUseProgram(*program); + glUseProgram(program); } void Shader::unuse() { glUseProgram(0); } - void Shader::attach(std::shared_ptr program) { - glAttachShader(*program, shader); + void Shader::attach(GLuint program) { + glAttachShader(program, shader); } int Shader::get_uniform_location(const std::string& uniform_name) const { @@ -115,14 +115,14 @@ namespace simpleengine::gfx { } int Shader::get_uniform_location(const char* uniform_name) const { - return glGetUniformLocation(*program, uniform_name); + return glGetUniformLocation(program, uniform_name); } GLfloat Shader::get_uniform_float(GLint location) const { use(); GLfloat fl; - glGetUniformfv(*program, location, &fl); + glGetUniformfv(program, location, &fl); return fl; } @@ -136,7 +136,7 @@ namespace simpleengine::gfx { use(); GLint _int; - glGetUniformiv(*program, location, &_int); + glGetUniformiv(program, location, &_int); return _int; } @@ -150,7 +150,7 @@ namespace simpleengine::gfx { use(); GLuint _uint; - glGetUniformuiv(*program, location, &_uint); + glGetUniformuiv(program, location, &_uint); return _uint; } @@ -164,7 +164,7 @@ namespace simpleengine::gfx { use(); GLdouble dbl; - glGetUniformdv(*program, location, &dbl); + glGetUniformdv(program, location, &dbl); return dbl; } diff --git a/src/gfx/textured_model.cpp b/src/gfx/textured_model.cpp index f6148d4..bb7f9b1 100644 --- a/src/gfx/textured_model.cpp +++ b/src/gfx/textured_model.cpp @@ -6,7 +6,7 @@ namespace simpleengine::gfx { } - TexturedModel::TexturedModel(GLFWwindow* window, std::shared_ptr shader_program, gfx::Texture texture, + TexturedModel::TexturedModel(GLFWwindow* window, GLuint shader_program, gfx::Texture texture, std::vector vertices, std::vector indicies) : TexturedModel(window, gfx::Shader(shader_program), texture, vertices, indicies) {