CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/GPU/OpenGL/GLSLProgram.h
Views: 1401
1
// Utility code for loading GLSL shaders.
2
// Has support for auto-reload, see glsl_refresh
3
4
#pragma once
5
6
#include <string>
7
#include <time.h>
8
9
#include "Common/GPU/OpenGL/GLCommon.h"
10
11
// Represent a compiled and linked vshader/fshader pair.
12
// A just-constructed object is valid but cannot be used as a shader program, meaning that
13
// yes, you can declare these as globals if you like.
14
struct GLSLProgram {
15
char name[16];
16
char vshader_filename[256];
17
char fshader_filename[256];
18
const char *vshader_source;
19
const char *fshader_source;
20
time_t vshader_mtime;
21
time_t fshader_mtime;
22
23
// Locations to some common uniforms. Hardcoded for speed.
24
GLint sampler0;
25
GLint sampler1;
26
GLint u_worldviewproj;
27
GLint u_world;
28
GLint u_viewproj;
29
GLint u_fog; // rgb = color, a = density
30
GLint u_sundir;
31
GLint u_camerapos;
32
33
GLint a_position;
34
GLint a_color;
35
GLint a_normal;
36
GLint a_texcoord0;
37
GLint a_texcoord1;
38
39
// Private to the implementation, do not touch
40
GLuint vsh_;
41
GLuint fsh_;
42
GLuint program_;
43
};
44
45
// C API, old skool. Not much point either...
46
47
// From files (VFS)
48
GLSLProgram *glsl_create(const char *vshader_file, const char *fshader_file, std::string *error_message = 0);
49
// Directly from source code
50
GLSLProgram *glsl_create_source(const char *vshader_src, const char *fshader_src, std::string *error_message = 0);
51
void glsl_destroy(GLSLProgram *program);
52
53
// If recompilation of the program fails, the program is untouched and error messages
54
// are logged and the function returns false.
55
bool glsl_recompile(GLSLProgram *program, std::string *error_message = 0);
56
void glsl_bind(const GLSLProgram *program);
57
const GLSLProgram *glsl_get_program();
58
void glsl_unbind();
59
int glsl_attrib_loc(const GLSLProgram *program, const char *name);
60
int glsl_uniform_loc(const GLSLProgram *program, const char *name);
61
62