2012-03-31 11:16:13 +02:00
|
|
|
// Utility code for loading GLSL shaders.
|
|
|
|
// Has support for auto-reload, see glsl_refresh
|
|
|
|
|
2013-10-13 11:56:42 +02:00
|
|
|
#pragma once
|
2012-03-24 23:39:19 +01:00
|
|
|
|
2013-10-13 11:56:42 +02:00
|
|
|
#include <string>
|
2012-03-24 23:39:19 +01:00
|
|
|
#include <time.h>
|
|
|
|
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/GPU/OpenGL/GLCommon.h"
|
2012-03-24 23:39:19 +01:00
|
|
|
|
|
|
|
// Represent a compiled and linked vshader/fshader pair.
|
|
|
|
// A just-constructed object is valid but cannot be used as a shader program, meaning that
|
|
|
|
// yes, you can declare these as globals if you like.
|
2017-12-07 14:56:19 +01:00
|
|
|
struct GLSLProgram {
|
2012-10-30 13:20:55 +01:00
|
|
|
char name[16];
|
|
|
|
char vshader_filename[256];
|
|
|
|
char fshader_filename[256];
|
|
|
|
const char *vshader_source;
|
|
|
|
const char *fshader_source;
|
|
|
|
time_t vshader_mtime;
|
|
|
|
time_t fshader_mtime;
|
|
|
|
|
|
|
|
// Locations to some common uniforms. Hardcoded for speed.
|
|
|
|
GLint sampler0;
|
|
|
|
GLint sampler1;
|
|
|
|
GLint u_worldviewproj;
|
|
|
|
GLint u_world;
|
|
|
|
GLint u_viewproj;
|
|
|
|
GLint u_fog; // rgb = color, a = density
|
2012-03-24 23:39:19 +01:00
|
|
|
GLint u_sundir;
|
|
|
|
GLint u_camerapos;
|
|
|
|
|
2012-10-30 13:20:55 +01:00
|
|
|
GLint a_position;
|
|
|
|
GLint a_color;
|
|
|
|
GLint a_normal;
|
|
|
|
GLint a_texcoord0;
|
|
|
|
GLint a_texcoord1;
|
2012-03-24 23:39:19 +01:00
|
|
|
|
2012-10-30 13:20:55 +01:00
|
|
|
// Private to the implementation, do not touch
|
|
|
|
GLuint vsh_;
|
|
|
|
GLuint fsh_;
|
|
|
|
GLuint program_;
|
2012-03-24 23:39:19 +01:00
|
|
|
};
|
|
|
|
|
2013-10-13 11:56:42 +02:00
|
|
|
// C API, old skool. Not much point either...
|
2012-08-13 20:11:24 +02:00
|
|
|
|
2012-08-27 23:28:52 +02:00
|
|
|
// From files (VFS)
|
2013-10-13 11:56:42 +02:00
|
|
|
GLSLProgram *glsl_create(const char *vshader_file, const char *fshader_file, std::string *error_message = 0);
|
2012-08-27 23:28:52 +02:00
|
|
|
// Directly from source code
|
2013-10-13 11:56:42 +02:00
|
|
|
GLSLProgram *glsl_create_source(const char *vshader_src, const char *fshader_src, std::string *error_message = 0);
|
2012-03-24 23:39:19 +01:00
|
|
|
void glsl_destroy(GLSLProgram *program);
|
|
|
|
|
|
|
|
// If recompilation of the program fails, the program is untouched and error messages
|
|
|
|
// are logged and the function returns false.
|
2013-10-13 11:56:42 +02:00
|
|
|
bool glsl_recompile(GLSLProgram *program, std::string *error_message = 0);
|
2012-03-24 23:39:19 +01:00
|
|
|
void glsl_bind(const GLSLProgram *program);
|
2017-02-15 12:32:48 +01:00
|
|
|
const GLSLProgram *glsl_get_program();
|
2012-03-24 23:39:19 +01:00
|
|
|
void glsl_unbind();
|
|
|
|
int glsl_attrib_loc(const GLSLProgram *program, const char *name);
|
|
|
|
int glsl_uniform_loc(const GLSLProgram *program, const char *name);
|