Don't use shared_ptr<GLuint> for shader programs, fix compiling windows

This commit is contained in:
SeanOMik 2021-12-12 22:17:59 -05:00
parent d7fccea2c6
commit a507e2f169
15 changed files with 43 additions and 47 deletions

View File

@ -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<GLuint> 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));

View File

@ -6,7 +6,7 @@
#ifdef __linux__
#include <GL/glew.h>
#elif
#else
#include <gl/glew.h>
#endif

View File

@ -21,7 +21,7 @@ namespace simpleengine::gfx {
gfx::Shader shader;
Model(GLFWwindow* window, gfx::Shader shader, std::vector<Vertex> vertices, std::vector<GLuint> indicies = std::vector<GLuint>());
Model(GLFWwindow* window, std::shared_ptr<GLuint> shader_program, std::vector<Vertex> vertices,
Model(GLFWwindow* window, GLuint shader_program, std::vector<Vertex> vertices,
std::vector<GLuint> indicies = std::vector<GLuint>());
protected:
void setup_vertexes();

View File

@ -5,7 +5,7 @@
#ifdef __linux__
#include <GL/glew.h>
#include <GL/gl.h>
#elif
#else
#include <gl/glew.h>
#include <gl/gl.h>
#endif
@ -39,21 +39,17 @@ namespace simpleengine::gfx {
};
class Shader {
protected:
Shader() {
}
public:
std::shared_ptr<GLuint> program;
GLuint program;
GLuint shader;
Shader(std::shared_ptr<GLuint> program);
Shader(std::shared_ptr<GLuint> 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<GLuint> 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<GLuint> 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<GLuint> program);
void attach(GLuint program);
/**
* @brief Get the location of the uniform variable in the shader.

View File

@ -3,7 +3,7 @@
#ifdef __linux__
#include <GL/glew.h>
#include <GL/gl.h>
#elif
#else
#include <gl/glew.h>
#include <gl/gl.h>
#endif

View File

@ -22,7 +22,7 @@ namespace simpleengine::gfx {
TexturedModel(GLFWwindow* window, gfx::Shader shader, gfx::Texture texture, std::vector<Vertex> vertices,
std::vector<GLuint> indicies = std::vector<GLuint>());
TexturedModel(GLFWwindow* window, std::shared_ptr<GLuint> shader_program, gfx::Texture texture, std::vector<Vertex> vertices,
TexturedModel(GLFWwindow* window, GLuint shader_program, gfx::Texture texture, std::vector<Vertex> vertices,
std::vector<GLuint> indicies = std::vector<GLuint>());
virtual void update(const float& delta_time) override;

View File

@ -3,7 +3,7 @@
#ifdef __linux__
#include <GL/glew.h>
#include <GL/gl.h>
#elif
#else
#include <gl/glew.h>
#include <gl/gl.h>
#endif

View File

@ -3,7 +3,7 @@
#ifdef __linux__
#include <GL/glew.h>
#include <GL/gl.h>
#elif
#else
#include <gl/glew.h>
#include <gl/gl.h>
#endif

View File

@ -3,7 +3,7 @@
#ifdef __linux__
#include <GL/glew.h>
#include <GL/gl.h>
#elif
#else
#include <gl/glew.h>
#include <gl/gl.h>
#endif
@ -26,15 +26,15 @@ namespace simpleengine {
private:
using super = simpleengine::Event;
public:
std::shared_ptr<GLuint> program;
GLuint program;
std::vector<gfx::Shader> shaders;
ShaderProgram() : program(std::make_shared<GLuint>(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);
}
};
}

View File

@ -4,7 +4,7 @@
#ifdef __linux__
#include <GL/glew.h>
#include <GL/gl.h>
#elif
#else
#include <gl/glew.h>
#include <gl/gl.h>
#endif

View File

@ -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<GLuint> 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) {

View File

@ -7,7 +7,7 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <GL/gl.h>
#elif
#else
#include <gl/glew.h>
#include <GLFW/glfw3.h>
#include <gl/gl.h>

View File

@ -8,7 +8,7 @@ namespace simpleengine::gfx {
setup_vertexes();
}
Model::Model(GLFWwindow* window, std::shared_ptr<GLuint> shader_program, std::vector<Vertex> vertices, std::vector<GLuint> indicies) :
Model::Model(GLFWwindow* window, GLuint shader_program, std::vector<Vertex> vertices, std::vector<GLuint> indicies) :
Model(window, gfx::Shader(shader_program), vertices, indicies) {
}

View File

@ -5,16 +5,16 @@
#include <memory>
namespace simpleengine::gfx {
Shader::Shader(std::shared_ptr<GLuint> program) : program(program) {
Shader::Shader(GLuint program) : program(program) {
}
Shader::Shader(std::shared_ptr<GLuint> 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<GLuint>(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<GLuint> 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<GLuint>(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<GLuint> 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<GLuint> 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;
}

View File

@ -6,7 +6,7 @@ namespace simpleengine::gfx {
}
TexturedModel::TexturedModel(GLFWwindow* window, std::shared_ptr<GLuint> shader_program, gfx::Texture texture,
TexturedModel::TexturedModel(GLFWwindow* window, GLuint shader_program, gfx::Texture texture,
std::vector<Vertex> vertices, std::vector<GLuint> indicies) : TexturedModel(window, gfx::Shader(shader_program),
texture, vertices, indicies) {