2022-01-02 19:28:16 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2022-01-09 23:37:48 -05:00
|
|
|
#include <time.h>
|
2022-01-02 19:28:16 -05:00
|
|
|
#include <GL/glew.h>
|
|
|
|
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
|
2022-01-09 23:37:48 -05:00
|
|
|
#include <SDL.h>
|
|
|
|
|
2022-01-02 19:28:16 -05:00
|
|
|
class ShaderProgram
|
|
|
|
{
|
2022-01-09 23:37:48 -05:00
|
|
|
/* TODO there's gotta be a better way of doing this! */
|
|
|
|
std::string mVertexPath, mGeometryPath, mFragmentPath;
|
|
|
|
SDL_TimerID mShaderWatchTimer;
|
|
|
|
/* most recent modification times for the three in order */
|
|
|
|
time_t mMtime[3];
|
|
|
|
|
2022-01-02 19:28:16 -05:00
|
|
|
bool mUniformLocationsNeedRefresh;
|
|
|
|
std::map<const std::string, GLint> UniformLocationCache;
|
2022-01-09 23:37:48 -05:00
|
|
|
|
2022-01-08 18:59:40 -05:00
|
|
|
static GLint my_checkCompileSuccess (const GLuint, const GLenum);
|
2022-01-09 23:37:48 -05:00
|
|
|
static Uint32 my_WatchShaderHelper (Uint32 interval, void* param);
|
|
|
|
|
|
|
|
GLint getCachedLoc (const std::string&);
|
|
|
|
|
2022-01-02 19:28:16 -05:00
|
|
|
public:
|
2022-01-09 23:37:48 -05:00
|
|
|
/*
|
|
|
|
* Set-able
|
|
|
|
*/
|
2022-01-02 19:28:16 -05:00
|
|
|
GLuint ID;
|
2022-01-09 23:37:48 -05:00
|
|
|
|
2022-01-02 19:28:16 -05:00
|
|
|
ShaderProgram (const std::string&, const std::string&, const std::string&);
|
2022-01-09 23:37:48 -05:00
|
|
|
|
|
|
|
~ShaderProgram (void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gl* stuff. These modify the current `ID`.
|
|
|
|
*/
|
2022-01-02 19:28:16 -05:00
|
|
|
void RefreshUniformLocations (void);
|
2022-01-08 18:59:40 -05:00
|
|
|
void Use (void);
|
|
|
|
void Bool (const std::string&, const bool&);
|
|
|
|
void Float (const std::string&, const float&);
|
|
|
|
void Int (const std::string&, const int&);
|
|
|
|
void Vec2 (const std::string&, const glm::vec2&);
|
|
|
|
void Vec3 (const std::string&, const glm::vec3&);
|
|
|
|
void Vec4 (const std::string&, const glm::vec4&);
|
|
|
|
void Mat2 (const std::string&, const glm::mat2&);
|
|
|
|
void Mat3 (const std::string&, const glm::mat3&);
|
|
|
|
void Mat4 (const std::string&, const glm::mat4&);
|
2022-01-02 19:28:16 -05:00
|
|
|
|
2022-01-09 23:37:48 -05:00
|
|
|
/*
|
|
|
|
* Program/util stuff
|
|
|
|
*/
|
2022-01-08 18:59:40 -05:00
|
|
|
GLuint CompileShaderBuffer (const std::string&, const GLenum);
|
|
|
|
GLuint Compile3ShaderBuffers (const std::string&, const std::string&, const std::string&);
|
|
|
|
GLuint CompileShaderPath (const std::string&, const GLenum);
|
2022-01-02 19:28:16 -05:00
|
|
|
GLint LinkProgram (void);
|
2022-01-09 23:37:48 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Monitor the modification time of the loaded shaders
|
|
|
|
*/
|
|
|
|
void StartWatchingShader (void);
|
|
|
|
void StopWatchingShader (void);
|
|
|
|
bool NeedsReloading (bool);
|
|
|
|
|
|
|
|
const std::string& getVertexPath (void) const { return mVertexPath; }
|
|
|
|
const std::string& getGeometryPath (void) const { return mGeometryPath; }
|
|
|
|
const std::string& getFragmentPath (void) const { return mFragmentPath; }
|
2022-01-02 19:28:16 -05:00
|
|
|
};
|