ShaderMgr.cpp (pymol-open-source-2.2.0) | : | ShaderMgr.cpp (pymol-open-source-2.3.0) | ||
---|---|---|---|---|
skipping to change at line 96 | skipping to change at line 96 | |||
#define WARNING_IF_GLERROR(msg) { \ | #define WARNING_IF_GLERROR(msg) { \ | |||
GLenum err; \ | GLenum err; \ | |||
if ((err = glGetError())){ \ | if ((err = glGetError())){ \ | |||
PRINTFB(G, FB_ShaderMgr, FB_Warnings) "GLERROR 0x%04x: %s\n", err, msg ENDFB (G); \ | PRINTFB(G, FB_ShaderMgr, FB_Warnings) "GLERROR 0x%04x: %s\n", err, msg ENDFB (G); \ | |||
} \ | } \ | |||
} | } | |||
static void glShaderSource1String(GLuint shad, const string &strobj){ | static void glShaderSource1String(GLuint shad, const string &strobj){ | |||
const GLchar *str = (const GLchar *)strobj.c_str(); | const GLchar *str = (const GLchar *)strobj.c_str(); | |||
glShaderSource(shad, 1, (const GLchar **)&str, NULL); | glShaderSource(shad, 1, (const GLchar **)&str, nullptr); | |||
} | } | |||
bool CShaderPrg::reload(){ | bool CShaderPrg::reload(){ | |||
// skip programs with empty file names, assume their code is managed | // skip programs with empty file names, assume their code is managed | |||
// outside of the reload logic (like ARB shaders). | // outside of the reload logic (like ARB shaders). | |||
if (is_valid || vertfile.empty()) | if (is_valid || vertfile.empty()) | |||
return true; | return true; | |||
string gs, vs, fs; | string gs, vs, fs; | |||
CShaderMgr *I = G->ShaderMgr; | CShaderMgr *I = G->ShaderMgr; | |||
skipping to change at line 232 | skipping to change at line 232 | |||
is_linked = false; | is_linked = false; | |||
is_valid = true; | is_valid = true; | |||
return true; | return true; | |||
} | } | |||
#define MASK_SHADERS_PRESENT_GEOMETRY 0x2; | #define MASK_SHADERS_PRESENT_GEOMETRY 0x2; | |||
#define MASK_SHADERS_PRESENT_SMAA 0x4; | #define MASK_SHADERS_PRESENT_SMAA 0x4; | |||
void getGLVersion(PyMOLGlobals * G, int *major, int* minor); | static void getGLVersion(PyMOLGlobals * G, int *major, int* minor); | |||
void getGLSLVersion(PyMOLGlobals * G, int* major, int* minor); | static void getGLSLVersion(PyMOLGlobals * G, int* major, int* minor); | |||
static void disableShaders(PyMOLGlobals * G); | static void disableShaders(PyMOLGlobals * G); | |||
#ifdef WIN32 | #ifdef WIN32 | |||
/* REMOVE US */ | /* REMOVE US */ | |||
PFNGLTEXIMAGE3DPROC getTexImage3D(){ | PFNGLTEXIMAGE3DPROC getTexImage3D(){ | |||
static PFNGLTEXIMAGE3DPROC my_glTexImage3D = NULL; | static PFNGLTEXIMAGE3DPROC my_glTexImage3D = NULL; | |||
if (!my_glTexImage3D) | if (!my_glTexImage3D) | |||
my_glTexImage3D = (PFNGLTEXIMAGE3DPROC) wglGetProcAddress("glTexImage3D"); | my_glTexImage3D = (PFNGLTEXIMAGE3DPROC) wglGetProcAddress("glTexImage3D"); | |||
return my_glTexImage3D; | return my_glTexImage3D; | |||
} | } | |||
#endif | #endif | |||
/* | /* | |||
* Use this to turn off shaders if the renderer cannot use them. | * Use this to turn off shaders if the renderer cannot use them. | |||
*/ | */ | |||
void disableShaders(PyMOLGlobals * G) { | void disableShaders(PyMOLGlobals * G) { | |||
/* Auto-disable shader-based rendering */ | /* Auto-disable shader-based rendering */ | |||
SettingSetGlobal_b(G, cSetting_use_shaders, 0); | SettingSetGlobal_b(G, cSetting_use_shaders, false); | |||
} | } | |||
static void disableGeometryShaders(PyMOLGlobals * G) { | static void disableGeometryShaders(PyMOLGlobals * G) { | |||
SettingSetGlobal_b(G, cSetting_use_geometry_shaders, 0); | SettingSetGlobal_b(G, cSetting_use_geometry_shaders, false); | |||
if(G->ShaderMgr) | if(G->ShaderMgr) | |||
G->ShaderMgr->SetPreprocVar("use_geometry_shaders", 0); | G->ShaderMgr->SetPreprocVar("use_geometry_shaders", false); | |||
if (G->Option && !G->Option->quiet) | if (G->Option && !G->Option->quiet) | |||
PRINTFB(G, FB_ShaderMgr, FB_Warnings) | PRINTFB(G, FB_ShaderMgr, FB_Warnings) | |||
" Geometry shaders not available\n" ENDFB(G); | " Geometry shaders not available\n" ENDFB(G); | |||
} | } | |||
/* | /* | |||
* Replace strings from a list of pairs. | * Replace strings from a list of pairs. | |||
* | * | |||
* src: string to modify | * src: string to modify | |||
skipping to change at line 343 | skipping to change at line 343 | |||
lightstrings[3] = " * 0.0"; | lightstrings[3] = " * 0.0"; | |||
} | } | |||
accstr << stringReplaceAll(rawtemplate, lightstrings); | accstr << stringReplaceAll(rawtemplate, lightstrings); | |||
} | } | |||
SetShaderSource("CallComputeColorForLight", accstr.str()); | SetShaderSource("CallComputeColorForLight", accstr.str()); | |||
} | } | |||
void CShaderMgr::Invalidate_All_Shaders(){ | void CShaderMgr::Invalidate_All_Shaders(){ | |||
for (map<string, CShaderPrg*>::iterator | for (auto& prog : programs) { | |||
it = programs.begin(); it != programs.end(); ++it) { | prog.second->Invalidate(); | |||
it->second->Invalidate(); | ||||
} | } | |||
} | } | |||
void CShaderMgr::Reload_All_Shaders(){ | void CShaderMgr::Reload_All_Shaders(){ | |||
Reload_Shader_Variables(); | Reload_Shader_Variables(); | |||
Reload_CallComputeColorForLight(); | Reload_CallComputeColorForLight(); | |||
if (SettingGetGlobal_i(G, cSetting_transparency_mode) == 3) { | if (SettingGetGlobal_i(G, cSetting_transparency_mode) == 3) { | |||
Reload_Derivatives("NO_ORDER_TRANSP"); | Reload_Derivatives("NO_ORDER_TRANSP"); | |||
} | } | |||
for (auto it = programs.begin(); it != programs.end(); ++it) { | for (auto& prog : programs) { | |||
if (it->second->derivative.empty()) | if (prog.second->derivative.empty()) | |||
it->second->reload(); | prog.second->reload(); | |||
} | } | |||
} | } | |||
// bitmasks for preprocessor parsing | // bitmasks for preprocessor parsing | |||
#define IFDEF 1 // #ifdef or #ifndef | #define IFDEF 1 // #ifdef or #ifndef | |||
#define IFNDEF 2 // #ifndef | #define IFNDEF 2 // #ifndef | |||
#define ELSE 4 // #else | #define ELSE 4 // #else | |||
#define ENDIF 8 // #endif | #define ENDIF 8 // #endif | |||
#define INCLUDE 16 // #include | #define INCLUDE 16 // #include | |||
#define LOOKUP 32 // #ifdef or #ifndef or #include | #define LOOKUP 32 // #ifdef or #ifndef or #include | |||
skipping to change at line 442 | skipping to change at line 441 | |||
* filename: file name of the shader file inside $PYMOL_DATA/shaders | * filename: file name of the shader file inside $PYMOL_DATA/shaders | |||
*/ | */ | |||
string CShaderMgr::GetShaderSource(const string &filename) | string CShaderMgr::GetShaderSource(const string &filename) | |||
{ | { | |||
// processed cache | // processed cache | |||
auto it = shader_cache_processed.find(filename); | auto it = shader_cache_processed.find(filename); | |||
if (it != shader_cache_processed.end()) { | if (it != shader_cache_processed.end()) { | |||
return it->second; | return it->second; | |||
} | } | |||
char* buffer = NULL; | char* buffer = nullptr; | |||
const char *pl = NULL, *newpl, *tpl; | const char *pl = nullptr, *newpl, *tpl; | |||
std::ostringstream newbuffer; | std::ostringstream newbuffer; | |||
/* "if_depth" counts the level of nesting, and "true_depth" how far the | /* "if_depth" counts the level of nesting, and "true_depth" how far the | |||
* if conditions were actually true. So if the current block is true, then | * if conditions were actually true. So if the current block is true, then | |||
* if_depth == true_depth, otherwise if_depth > true_depth. | * if_depth == true_depth, otherwise if_depth > true_depth. | |||
*/ | */ | |||
int if_depth = 0, true_depth = 0; | int if_depth = 0, true_depth = 0; | |||
#ifndef _PYMOL_IOS | #ifndef _PYMOL_IOS | |||
/* read the file from disk */ | /* read the file from disk */ | |||
if (SettingGetGlobal_b(G, cSetting_shaders_from_disk)) { | if (SettingGetGlobal_b(G, cSetting_shaders_from_disk)) { | |||
const char * pymol_data = getenv("PYMOL_DATA"); | const char * pymol_data = getenv("PYMOL_DATA"); | |||
if (pymol_data && pymol_data[0]) { | if (pymol_data && pymol_data[0]) { | |||
string path(pymol_data); | string path(pymol_data); | |||
path.append(PATH_SEP).append("shaders").append(PATH_SEP).append(filename); | path.append(PATH_SEP).append("shaders").append(PATH_SEP).append(filename); | |||
pl = buffer = FileGetContents(path.c_str(), NULL); | pl = buffer = FileGetContents(path.c_str(), nullptr); | |||
if (!buffer) { | if (!buffer) { | |||
PRINTFB(G, FB_ShaderMgr, FB_Warnings) | PRINTFB(G, FB_ShaderMgr, FB_Warnings) | |||
" Warning: shaders_from_dist=on, but unable to open file '%s'\n", | " Warning: shaders_from_dist=on, but unable to open file '%s'\n", | |||
path.c_str() ENDFB(G); | path.c_str() ENDFB(G); | |||
} | } | |||
} else { | } else { | |||
PRINTFB(G, FB_ShaderMgr, FB_Warnings) | PRINTFB(G, FB_ShaderMgr, FB_Warnings) | |||
" Warning: shaders_from_dist=on, but PYMOL_DATA not set\n" ENDFB(G); | " Warning: shaders_from_dist=on, but PYMOL_DATA not set\n" ENDFB(G); | |||
} | } | |||
skipping to change at line 571 | skipping to change at line 570 | |||
if ((reload_bits & RELOAD_VARIABLES)) { | if ((reload_bits & RELOAD_VARIABLES)) { | |||
reload_bits &= ~RELOAD_VARIABLES; | reload_bits &= ~RELOAD_VARIABLES; | |||
} else { | } else { | |||
return; | return; | |||
} | } | |||
int bg_image_mode = SettingGetGlobal_i(G, cSetting_bg_image_mode); | int bg_image_mode = SettingGetGlobal_i(G, cSetting_bg_image_mode); | |||
int bg_gradient = SettingGetGlobal_b(G, cSetting_bg_gradient); | int bg_gradient = SettingGetGlobal_b(G, cSetting_bg_gradient); | |||
int bg_image_mode_solid; | int bg_image_mode_solid; | |||
int stereo, stereo_mode; | int stereo, stereo_mode; | |||
const char * bg_image_filename = SettingGet_s(G, NULL, NULL, cSetting_bg_image _filename); | const char * bg_image_filename = SettingGet_s(G, nullptr, nullptr, cSetting_bg _image_filename); | |||
short bg_image = bg_image_filename && bg_image_filename[0]; | short bg_image = bg_image_filename && bg_image_filename[0]; | |||
bg_image_mode_solid = !(bg_gradient || bg_image || OrthoBackgroundDataIsSet(G) ); | bg_image_mode_solid = !(bg_gradient || bg_image || OrthoBackgroundDataIsSet(*G ->Ortho)); | |||
SetPreprocVar("bg_image_mode_solid", bg_image_mode_solid); | SetPreprocVar("bg_image_mode_solid", bg_image_mode_solid); | |||
if (!bg_image_mode_solid) { | if (!bg_image_mode_solid) { | |||
SetPreprocVar("bg_image_mode_1_or_3", (bg_image_mode == 1 || bg_image_mode = = 3)); | SetPreprocVar("bg_image_mode_1_or_3", (bg_image_mode == 1 || bg_image_mode = = 3)); | |||
SetPreprocVar("bg_image_mode_2_or_3", (bg_image_mode == 2 || bg_image_mode = = 3)); | SetPreprocVar("bg_image_mode_2_or_3", (bg_image_mode == 2 || bg_image_mode = = 3)); | |||
} | } | |||
#ifndef PYMOL_EDU | #ifndef PYMOL_EDU | |||
SetPreprocVar("volume_mode", SettingGetGlobal_i(G, cSetting_volume_mode)); | SetPreprocVar("volume_mode", SettingGetGlobal_i(G, cSetting_volume_mode)); | |||
#endif | #endif | |||
skipping to change at line 598 | skipping to change at line 597 | |||
#ifndef PURE_OPENGL_ES_2 | #ifndef PURE_OPENGL_ES_2 | |||
SetPreprocVar("use_geometry_shaders", SettingGetGlobal_b(G, cSetting_use_geome try_shaders)); | SetPreprocVar("use_geometry_shaders", SettingGetGlobal_b(G, cSetting_use_geome try_shaders)); | |||
#endif | #endif | |||
SetPreprocVar("line_smooth", SettingGetGlobal_b(G, cSetting_line_smooth)); | SetPreprocVar("line_smooth", SettingGetGlobal_b(G, cSetting_line_smooth)); | |||
stereo = SettingGetGlobal_i(G, cSetting_stereo); | stereo = SettingGetGlobal_i(G, cSetting_stereo); | |||
stereo_mode = SettingGetGlobal_i(G, cSetting_stereo_mode); | stereo_mode = SettingGetGlobal_i(G, cSetting_stereo_mode); | |||
SetPreprocVar("ANAGLYPH", (stereo && stereo_mode==cStereo_anaglyph) ? 1 : 0); | SetPreprocVar("ANAGLYPH", stereo && stereo_mode == cStereo_anaglyph); | |||
SetPreprocVar("ray_trace_mode_3", SettingGetGlobal_i(G, cSetting_ray_trace_mod e) == 3); | SetPreprocVar("ray_trace_mode_3", SettingGetGlobal_i(G, cSetting_ray_trace_mod e) == 3); | |||
SetPreprocVar("transparency_mode_3", SettingGetGlobal_i(G, cSetting_transparen cy_mode)==3); | SetPreprocVar("transparency_mode_3", SettingGetGlobal_i(G, cSetting_transparen cy_mode)==3); | |||
#ifndef _PYMOL_NO_AA_SHADERS | #ifndef _PYMOL_NO_AA_SHADERS | |||
#endif | #endif | |||
SetPreprocVar("precomputed_lighting", SettingGetGlobal_b(G, cSetting_precomput ed_lighting)); | SetPreprocVar("precomputed_lighting", SettingGetGlobal_b(G, cSetting_precomput ed_lighting)); | |||
SetPreprocVar("ray_transparency_oblique", SettingGetGlobal_f(G, cSetting_ray_t ransparency_oblique) > R_SMALL4); | SetPreprocVar("ray_transparency_oblique", SettingGetGlobal_f(G, cSetting_ray_t ransparency_oblique) > R_SMALL4); | |||
int chromadepth = SettingGetGlobal_i(G, cSetting_chromadepth); | int chromadepth = SettingGetGlobal_i(G, cSetting_chromadepth); | |||
skipping to change at line 668 | skipping to change at line 667 | |||
/* | /* | |||
* Print the given message as ShaderMgr-Error, followed by the shader info log. | * Print the given message as ShaderMgr-Error, followed by the shader info log. | |||
*/ | */ | |||
void CShaderPrg::ErrorMsgWithShaderInfoLog(const GLuint sid, const char * msg) { | void CShaderPrg::ErrorMsgWithShaderInfoLog(const GLuint sid, const char * msg) { | |||
if (!G->Option || G->Option->quiet) | if (!G->Option || G->Option->quiet) | |||
return; | return; | |||
GLint infoLogLength = 0; | GLint infoLogLength = 0; | |||
glGetShaderiv(sid, GL_INFO_LOG_LENGTH, &infoLogLength); | glGetShaderiv(sid, GL_INFO_LOG_LENGTH, &infoLogLength); | |||
vector<GLchar> infoLog(infoLogLength); | vector<GLchar> infoLog(infoLogLength); | |||
glGetShaderInfoLog(sid, infoLogLength, NULL, infoLog.data()); | glGetShaderInfoLog(sid, infoLogLength, nullptr, infoLog.data()); | |||
PRINTFB(G, FB_ShaderPrg, FB_Errors) " ShaderPrg-Error: %s; name='%s'\n", | PRINTFB(G, FB_ShaderPrg, FB_Errors) " ShaderPrg-Error: %s; name='%s'\n", | |||
msg, name.c_str() ENDFB(G); | msg, name.c_str() ENDFB(G); | |||
PRINTFB(G, FB_ShaderPrg, FB_Errors) " ShaderPrg-Error-InfoLog:\n%s\n", | PRINTFB(G, FB_ShaderPrg, FB_Errors) " ShaderPrg-Error-InfoLog:\n%s\n", | |||
infoLog.data() ENDFB(G); | infoLog.data() ENDFB(G); | |||
} | } | |||
/* ShaderMgrConfig -- Called from PyMOL.c, configures the global ShaderMgr | /* ShaderMgrConfig -- Called from PyMOL.c, configures the global ShaderMgr | |||
* This needs to be called once the OpenGL context has been created, it is | * This needs to be called once the OpenGL context has been created, it is | |||
skipping to change at line 717 | skipping to change at line 716 | |||
else { | else { | |||
/* print info on glew error? */ | /* print info on glew error? */ | |||
FeedbackAdd(G, " There was an error intializing GLEW. Basic graphics, inclu ding\n shaders and volumes may be unavailable.\n"); | FeedbackAdd(G, " There was an error intializing GLEW. Basic graphics, inclu ding\n shaders and volumes may be unavailable.\n"); | |||
disableShaders(G); | disableShaders(G); | |||
fprintf(stderr, " GLEW-Error: %s\n", glewGetErrorString(err)); | fprintf(stderr, " GLEW-Error: %s\n", glewGetErrorString(err)); | |||
return; | return; | |||
} | } | |||
#endif | #endif | |||
// static preprocessor values | // static preprocessor values | |||
preproc_vars["GLEW_VERSION_3_0"] = GLEW_VERSION_3_0 ? 1 : 0; | preproc_vars["GLEW_VERSION_3_0"] = GLEW_VERSION_3_0 ? true : false; | |||
if (TM3_IS_ONEBUF){ | if (TM3_IS_ONEBUF){ | |||
preproc_vars["ONE_DRAW_BUFFER"] = 1; | preproc_vars["ONE_DRAW_BUFFER"] = true; | |||
} | } | |||
#ifdef PURE_OPENGL_ES_2 | #ifdef PURE_OPENGL_ES_2 | |||
preproc_vars["PURE_OPENGL_ES_2"] = 1; | preproc_vars["PURE_OPENGL_ES_2"] = 1; | |||
preproc_vars["PYMOL_WEBGL"] = 1; | preproc_vars["PYMOL_WEBGL"] = 1; | |||
preproc_vars["PYMOL_WEBGL_IOS"] = 1; | preproc_vars["PYMOL_WEBGL_IOS"] = 1; | |||
#else | #else | |||
preproc_vars["gl_VertexID_enabled"] = GLEW_EXT_gpu_shader4; | preproc_vars["gl_VertexID_enabled"] = GLEW_EXT_gpu_shader4; | |||
#endif | #endif | |||
// shaders | // shaders | |||
skipping to change at line 798 | skipping to change at line 797 | |||
// other shader compilation tests | // other shader compilation tests | |||
if (GET_FRAGDEPTH_SUPPORT()) { | if (GET_FRAGDEPTH_SUPPORT()) { | |||
check_program("cylinder", cSetting_render_as_cylinders, 0); | check_program("cylinder", cSetting_render_as_cylinders, 0); | |||
check_program("sphere", cSetting_sphere_mode, 0); | check_program("sphere", cSetting_sphere_mode, 0); | |||
} | } | |||
#ifndef _PYMOL_NO_AA_SHADERS | #ifndef _PYMOL_NO_AA_SHADERS | |||
#endif | #endif | |||
// get filename -> shader program dependencies | // get filename -> shader program dependencies | |||
for (auto it = programs.begin(); it != programs.end(); ++it) { | for (auto& prog : programs) { | |||
RegisterDependantFileNames(it->second); | RegisterDependantFileNames(prog.second); | |||
} | } | |||
// make transparency_mode_3 shader derivatives | // make transparency_mode_3 shader derivatives | |||
MakeDerivatives("_t", "NO_ORDER_TRANSP"); | MakeDerivatives("_t", "NO_ORDER_TRANSP"); | |||
#ifndef PURE_OPENGL_ES_2 | #ifndef PURE_OPENGL_ES_2 | |||
/* report GLSL version */ | /* report GLSL version */ | |||
if (G && G->Option && !G->Option->quiet) { | if (G && G->Option && !G->Option->quiet) { | |||
char buf[50]; | char buf[50]; | |||
int major, minor; | int major, minor; | |||
getGLSLVersion(G, &major, &minor); | getGLSLVersion(G, &major, &minor); | |||
sprintf(buf, " Detected GLSL version %d.%d.\n", major, minor); | sprintf(buf, " Detected GLSL version %d.%d.\n", major, minor); | |||
FeedbackAdd(G, buf); | FeedbackAdd(G, buf); | |||
} | } | |||
#endif | #endif | |||
shaders_present |= 0x1; | shaders_present |= 0x1; | |||
SettingSetGlobal_b(G, cSetting_use_shaders, 1); | SettingSetGlobal_b(G, cSetting_use_shaders, true); | |||
is_configured = true; | is_configured = true; | |||
return; | return; | |||
ok_except1: | ok_except1: | |||
disableShaders(G); | disableShaders(G); | |||
G->ShaderMgr->shaders_present = 0; | G->ShaderMgr->shaders_present = 0; | |||
is_configured = true; | is_configured = true; | |||
} | } | |||
/* getGLVersion -- determine user's GL version | /* getGLVersion -- determine user's GL version | |||
skipping to change at line 838 | skipping to change at line 837 | |||
* major, return value for major | * major, return value for major | |||
* minor, return value for minor | * minor, return value for minor | |||
* | * | |||
* RETURNS | * RETURNS | |||
* nothing; writes to major and minor | * nothing; writes to major and minor | |||
*/ | */ | |||
void getGLVersion(PyMOLGlobals * G, int *major, int* minor) { | void getGLVersion(PyMOLGlobals * G, int *major, int* minor) { | |||
/* query the version string */ | /* query the version string */ | |||
const char* verstr = (const char*) glGetString(GL_VERSION); | const char* verstr = (const char*) glGetString(GL_VERSION); | |||
/* attempt to store the values into major and minor */ | /* attempt to store the values into major and minor */ | |||
if ((verstr==NULL) || (sscanf(verstr,"%d.%d", major, minor) != 2)) { | if (!verstr || sscanf(verstr, "%d.%d", major, minor) != 2) { | |||
*major = *minor = 0; | *major = *minor = 0; | |||
/* Use PyMOL FB system, instead of fprintf */ | /* Use PyMOL FB system, instead of fprintf */ | |||
PRINTFD(G, FB_ObjectVolume) | PRINTFD(G, FB_ObjectVolume) | |||
"Invalid GL_VERSION format.\n" ENDFD; | "Invalid GL_VERSION format.\n" ENDFD; | |||
} | } | |||
} | } | |||
/* getGLSLVersion -- determine user's GLSL version | /* getGLSLVersion -- determine user's GLSL version | |||
* PARAMS | * PARAMS | |||
* major, rval for major | * major, rval for major | |||
skipping to change at line 862 | skipping to change at line 861 | |||
void getGLSLVersion(PyMOLGlobals * G, int* major, int* minor) { | void getGLSLVersion(PyMOLGlobals * G, int* major, int* minor) { | |||
int gl_major, gl_minor; | int gl_major, gl_minor; | |||
*major = *minor = 0; | *major = *minor = 0; | |||
/* grab the GL version */ | /* grab the GL version */ | |||
getGLVersion(G, &gl_major, &gl_minor); | getGLVersion(G, &gl_major, &gl_minor); | |||
/* GL version 1 */ | /* GL version 1 */ | |||
if (1==gl_major) { | if (1==gl_major) { | |||
const char* extstr = (const char*) glGetString(GL_EXTENSIONS); | const char* extstr = (const char*) glGetString(GL_EXTENSIONS); | |||
if ((extstr!=NULL) && | if (extstr && strstr(extstr, "GL_ARB_shading_language_100")) { | |||
(strstr(extstr, "GL_ARB_shading_language_100")!=NULL)){ | ||||
*major = 1; | *major = 1; | |||
*minor = 0; | *minor = 0; | |||
} | } | |||
} | } | |||
/* GL > version 1 */ | /* GL > version 1 */ | |||
else if (gl_major>=2) { | else if (gl_major>=2) { | |||
const char* verstr = (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION); | const char* verstr = (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION); | |||
if ((verstr==NULL) || (sscanf(verstr, "%d.%d", major, minor)!=2)){ | if (!verstr || sscanf(verstr, "%d.%d", major, minor) != 2) { | |||
*major = *minor = 0; | *major = *minor = 0; | |||
if (G && G->Option && !G->Option->quiet) { | if (G && G->Option && !G->Option->quiet) { | |||
PRINTFD(G, FB_ObjectVolume) | PRINTFD(G, FB_ObjectVolume) | |||
"Invalid GL_SHADING_LANGUAGE_VERSION format.\n" ENDFD; | "Invalid GL_SHADING_LANGUAGE_VERSION format.\n" ENDFD; | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
#endif | #endif | |||
/* ============================================================================ | /* ============================================================================ | |||
* CShaderMgr -- Simple Shader Manager class | * CShaderMgr -- Simple Shader Manager class | |||
*/ | */ | |||
CShaderMgr::CShaderMgr(PyMOLGlobals * G_) | CShaderMgr::CShaderMgr(PyMOLGlobals * G_) | |||
{ | { | |||
G = G_; | G = G_; | |||
current_shader = 0; | current_shader = nullptr; | |||
shaders_present = 0; | shaders_present = 0; | |||
stereo_flag = 0; | stereo_flag = 0; | |||
stereo_blend = 0; | stereo_blend = 0; | |||
#ifdef _PYMOL_LIB | #ifdef _PYMOL_LIB | |||
print_warnings = 0; | print_warnings = 0; | |||
#else | #else | |||
print_warnings = 1; | print_warnings = 1; | |||
#endif | #endif | |||
lightingTexture = 0; | lightingTexture = 0; | |||
is_picking = 0; | is_picking = 0; | |||
reload_bits = RELOAD_ALL_SHADERS; | reload_bits = RELOAD_ALL_SHADERS; | |||
#ifndef _WEBGL | #ifndef _WEBGL | |||
vbos_to_free.reserve(256); | vbos_to_free.reserve(256); | |||
#endif | #endif | |||
} | } | |||
CShaderMgr::~CShaderMgr() { | CShaderMgr::~CShaderMgr() { | |||
for (auto it = programs.begin(); it != programs.end(); ++it) { | for (auto& prog : programs) { | |||
delete it->second; | delete prog.second; | |||
} | } | |||
programs.clear(); | programs.clear(); | |||
shader_cache_processed.clear(); | shader_cache_processed.clear(); | |||
for (int i = 0; i < 3; ++i) | for (int i = 0; i < 3; ++i) | |||
freeGPUBuffer(offscreen_rt[i]); | freeGPUBuffer(offscreen_rt[i]); | |||
for (int i = 0; i < 2; ++i) | for (int i = 0; i < 2; ++i) | |||
freeGPUBuffer(oit_rt[i]); | freeGPUBuffer(oit_rt[i]); | |||
skipping to change at line 959 | skipping to change at line 957 | |||
* shader manager. If `pass` is provided and is less than zero, and we are | * shader manager. If `pass` is provided and is less than zero, and we are | |||
* in transparency_mode 3, then look up the NO_ORDER_TRANSP derivative.h | * in transparency_mode 3, then look up the NO_ORDER_TRANSP derivative.h | |||
*/ | */ | |||
CShaderPrg * CShaderMgr::GetShaderPrg(std::string name, short set_current_shader , short pass) { | CShaderPrg * CShaderMgr::GetShaderPrg(std::string name, short set_current_shader , short pass) { | |||
if (pass < 0 && SettingGetGlobal_i(G, cSetting_transparency_mode) == 3) { | if (pass < 0 && SettingGetGlobal_i(G, cSetting_transparency_mode) == 3) { | |||
name += "_t"; | name += "_t"; | |||
} | } | |||
auto it = programs.find(name); | auto it = programs.find(name); | |||
if (it == programs.end()) | if (it == programs.end()) | |||
return NULL; | return nullptr; | |||
if (set_current_shader) | if (set_current_shader) | |||
current_shader = it->second; | current_shader = it->second; | |||
return it->second; | return it->second; | |||
} | } | |||
int CShaderMgr::ShaderPrgExists(const char * name){ | int CShaderMgr::ShaderPrgExists(const char * name){ | |||
return (programs.find(name) != programs.end()); | return (programs.find(name) != programs.end()); | |||
} | } | |||
skipping to change at line 1030 | skipping to change at line 1028 | |||
CShaderPrg *CShaderMgr::Enable_DefaultShaderWithSettings( | CShaderPrg *CShaderMgr::Enable_DefaultShaderWithSettings( | |||
const CSetting *set1, | const CSetting *set1, | |||
const CSetting *set2, int pass) { | const CSetting *set2, int pass) { | |||
CShaderPrg * shaderPrg = Get_DefaultShader(pass); | CShaderPrg * shaderPrg = Get_DefaultShader(pass); | |||
return Setup_DefaultShader(shaderPrg, set1, set2); | return Setup_DefaultShader(shaderPrg, set1, set2); | |||
} | } | |||
CShaderPrg *CShaderMgr::Enable_DefaultShader(int pass){ | CShaderPrg *CShaderMgr::Enable_DefaultShader(int pass){ | |||
CShaderPrg * shaderPrg = Get_DefaultShader(pass); | CShaderPrg * shaderPrg = Get_DefaultShader(pass); | |||
return Setup_DefaultShader(shaderPrg, NULL, NULL); | return Setup_DefaultShader(shaderPrg, nullptr, nullptr); | |||
} | } | |||
CShaderPrg *CShaderMgr::Enable_LineShader(int pass){ | CShaderPrg *CShaderMgr::Enable_LineShader(int pass){ | |||
CShaderPrg * shaderPrg = Get_LineShader(pass); | CShaderPrg * shaderPrg = Get_LineShader(pass); | |||
return Setup_DefaultShader(shaderPrg, NULL, NULL); | return Setup_DefaultShader(shaderPrg, nullptr, nullptr); | |||
} | } | |||
CShaderPrg *CShaderMgr::Enable_SurfaceShader(int pass){ | CShaderPrg *CShaderMgr::Enable_SurfaceShader(int pass){ | |||
CShaderPrg * shaderPrg = Get_SurfaceShader(pass); | CShaderPrg * shaderPrg = Get_SurfaceShader(pass); | |||
return Setup_DefaultShader(shaderPrg, NULL, NULL); | return Setup_DefaultShader(shaderPrg, nullptr, nullptr); | |||
} | } | |||
CShaderPrg *CShaderMgr::Enable_ConnectorShader(int pass){ | CShaderPrg *CShaderMgr::Enable_ConnectorShader(int pass){ | |||
CShaderPrg * shaderPrg = Get_ConnectorShader(pass); | CShaderPrg * shaderPrg = Get_ConnectorShader(pass); | |||
if (!shaderPrg) | if (!shaderPrg) | |||
return 0; | return nullptr; | |||
shaderPrg = Setup_DefaultShader(shaderPrg, NULL, NULL); | shaderPrg = Setup_DefaultShader(shaderPrg, nullptr, nullptr); | |||
shaderPrg->SetLightingEnabled(0); | shaderPrg->SetLightingEnabled(0); | |||
{ | { | |||
float front, back; | float front, back; | |||
front = SceneGetCurrentFrontSafe(G); | front = SceneGetCurrentFrontSafe(G); | |||
back = SceneGetCurrentBackSafe(G); | back = SceneGetCurrentBackSafe(G); | |||
shaderPrg->Set1f("front", front); | shaderPrg->Set1f("front", front); | |||
shaderPrg->Set1f("clipRange", back - front); | shaderPrg->Set1f("clipRange", back - front); | |||
} | } | |||
int width, height; | int width, height; | |||
SceneGetWidthHeightStereo(G, &width, &height); | SceneGetWidthHeightStereo(G, &width, &height); | |||
shaderPrg->Set2f("screenSize", width, height); | shaderPrg->Set2f("screenSize", width, height); | |||
{ | { | |||
float v_scale = SceneGetScreenVertexScale(G, NULL); | float v_scale = SceneGetScreenVertexScale(G, nullptr); | |||
shaderPrg->Set1f("screenOriginVertexScale", v_scale/2.f); | shaderPrg->Set1f("screenOriginVertexScale", v_scale/2.f); | |||
} | } | |||
return shaderPrg; | return shaderPrg; | |||
} | } | |||
CShaderPrg *CShaderMgr::Setup_DefaultShader(CShaderPrg * shaderPrg, | CShaderPrg *CShaderMgr::Setup_DefaultShader(CShaderPrg * shaderPrg, | |||
const CSetting *set1, | const CSetting *set1, | |||
const CSetting *set2) { | const CSetting *set2) { | |||
if (!shaderPrg){ | if (!shaderPrg){ | |||
current_shader = NULL; | current_shader = nullptr; | |||
return shaderPrg; | return shaderPrg; | |||
} | } | |||
shaderPrg->Enable(); | shaderPrg->Enable(); | |||
shaderPrg->SetBgUniforms(); | shaderPrg->SetBgUniforms(); | |||
shaderPrg->Set_Stereo_And_AnaglyphMode(); | shaderPrg->Set_Stereo_And_AnaglyphMode(); | |||
bool two_sided_lighting_enabled = SceneGetTwoSidedLightingSettings(G, set1, se t2); | bool two_sided_lighting_enabled = SceneGetTwoSidedLightingSettings(G, set1, se t2); | |||
shaderPrg->SetLightingEnabled(1); // lighting on by default | shaderPrg->SetLightingEnabled(1); // lighting on by default | |||
shaderPrg->Set1i("two_sided_lighting_enabled", two_sided_lighting_enabled); | shaderPrg->Set1i("two_sided_lighting_enabled", two_sided_lighting_enabled); | |||
skipping to change at line 1116 | skipping to change at line 1114 | |||
return Enable_CylinderShader("cylinder", pass); | return Enable_CylinderShader("cylinder", pass); | |||
} | } | |||
CShaderPrg *CShaderMgr::Enable_CylinderShader(const char *shader_name, int pass) { | CShaderPrg *CShaderMgr::Enable_CylinderShader(const char *shader_name, int pass) { | |||
int width, height; | int width, height; | |||
CShaderPrg *shaderPrg; | CShaderPrg *shaderPrg; | |||
SceneGetWidthHeightStereo(G, &width, &height); | SceneGetWidthHeightStereo(G, &width, &height); | |||
shaderPrg = GetShaderPrg(shader_name, 1, pass); | shaderPrg = GetShaderPrg(shader_name, 1, pass); | |||
if (!shaderPrg) | if (!shaderPrg) | |||
return NULL; | return nullptr; | |||
shaderPrg->Enable(); | shaderPrg->Enable(); | |||
shaderPrg->SetLightingEnabled(1); // lighting on by default | shaderPrg->SetLightingEnabled(1); // lighting on by default | |||
shaderPrg->Set1f("uni_radius", 0.f); | shaderPrg->Set1f("uni_radius", 0.f); | |||
shaderPrg->Set_Stereo_And_AnaglyphMode(); | shaderPrg->Set_Stereo_And_AnaglyphMode(); | |||
shaderPrg->Set1f("inv_height", 1.0/height); | shaderPrg->Set1f("inv_height", 1.0/height); | |||
shaderPrg->Set1i("no_flat_caps", 1); | shaderPrg->Set1i("no_flat_caps", 1); | |||
skipping to change at line 1148 | skipping to change at line 1146 | |||
glEnable(GL_CULL_FACE); | glEnable(GL_CULL_FACE); | |||
return shaderPrg; | return shaderPrg; | |||
} | } | |||
CShaderPrg *CShaderMgr::Get_DefaultSphereShader(int pass){ | CShaderPrg *CShaderMgr::Get_DefaultSphereShader(int pass){ | |||
return GetShaderPrg("sphere", 1, pass); | return GetShaderPrg("sphere", 1, pass); | |||
} | } | |||
CShaderPrg *CShaderMgr::Enable_DefaultSphereShader(int pass) { | CShaderPrg *CShaderMgr::Enable_DefaultSphereShader(int pass) { | |||
CShaderPrg *shaderPrg = Get_DefaultSphereShader(pass); | CShaderPrg *shaderPrg = Get_DefaultSphereShader(pass); | |||
if (!shaderPrg) return NULL; | if (!shaderPrg) return nullptr; | |||
shaderPrg->Enable(); | shaderPrg->Enable(); | |||
shaderPrg->SetLightingEnabled(1); | shaderPrg->SetLightingEnabled(1); | |||
shaderPrg->Set1f("sphere_size_scale", 1.f); | shaderPrg->Set1f("sphere_size_scale", 1.f); | |||
shaderPrg->Set_Stereo_And_AnaglyphMode(); | shaderPrg->Set_Stereo_And_AnaglyphMode(); | |||
shaderPrg->Set_Specular_Values(); | shaderPrg->Set_Specular_Values(); | |||
shaderPrg->Set_Matrices(); | shaderPrg->Set_Matrices(); | |||
shaderPrg->SetBgUniforms(); | shaderPrg->SetBgUniforms(); | |||
return (shaderPrg); | return (shaderPrg); | |||
} | } | |||
#ifdef _PYMOL_ARB_SHADERS | #ifdef _PYMOL_ARB_SHADERS | |||
CShaderPrg *CShaderMgr::Enable_SphereShaderARB(){ | CShaderPrg *CShaderMgr::Enable_SphereShaderARB(){ | |||
CShaderPrg *shaderPrg = NULL; | CShaderPrg *shaderPrg = nullptr; | |||
/* load the vertex program */ | /* load the vertex program */ | |||
if (current_shader) | if (current_shader) | |||
current_shader->Disable(); | current_shader->Disable(); | |||
shaderPrg = GetShaderPrg("sphere_arb"); | shaderPrg = GetShaderPrg("sphere_arb"); | |||
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, shaderPrg->vid); | glBindProgramARB(GL_VERTEX_PROGRAM_ARB, shaderPrg->vid); | |||
/* load the fragment program */ | /* load the fragment program */ | |||
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shaderPrg->fid); | glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shaderPrg->fid); | |||
/* load some safe initial values */ | /* load some safe initial values */ | |||
skipping to change at line 1296 | skipping to change at line 1294 | |||
#ifndef PURE_OPENGL_ES_2 | #ifndef PURE_OPENGL_ES_2 | |||
glDisable(GL_ALPHA_TEST); | glDisable(GL_ALPHA_TEST); | |||
#endif | #endif | |||
return shaderPrg; | return shaderPrg; | |||
} | } | |||
CShaderPrg *CShaderMgr::Enable_LabelShader(int pass){ | CShaderPrg *CShaderMgr::Enable_LabelShader(int pass){ | |||
CShaderPrg *shaderPrg; | CShaderPrg *shaderPrg; | |||
shaderPrg = Get_LabelShader(pass); | shaderPrg = Get_LabelShader(pass); | |||
if (!shaderPrg) | if (!shaderPrg) | |||
return NULL; | return nullptr; | |||
shaderPrg->Enable(); | shaderPrg->Enable(); | |||
return Setup_LabelShader(shaderPrg); | return Setup_LabelShader(shaderPrg); | |||
} | } | |||
CShaderPrg *CShaderMgr::Enable_ScreenShader(){ | CShaderPrg *CShaderMgr::Enable_ScreenShader(){ | |||
CShaderPrg *shaderPrg; | CShaderPrg *shaderPrg; | |||
shaderPrg = Get_ScreenShader(); | shaderPrg = Get_ScreenShader(); | |||
if (!shaderPrg) | if (!shaderPrg) | |||
return NULL; | return nullptr; | |||
shaderPrg->Enable(); | shaderPrg->Enable(); | |||
int ortho_width, ortho_height; | int ortho_width, ortho_height; | |||
OrthoGetSize(G, &ortho_width, &ortho_height); | std::tie(ortho_width, ortho_height) = OrthoGetSize(*G->Ortho); | |||
shaderPrg->Set2f("t2PixelSize", 2.f / ortho_width, 2.f / ortho_height); | shaderPrg->Set2f("t2PixelSize", 2.f / ortho_width, 2.f / ortho_height); | |||
return Setup_LabelShader(shaderPrg); | return Setup_LabelShader(shaderPrg); | |||
} | } | |||
CShaderPrg *CShaderMgr::Enable_RampShader(){ | CShaderPrg *CShaderMgr::Enable_RampShader(){ | |||
CShaderPrg *shaderPrg; | CShaderPrg *shaderPrg; | |||
shaderPrg = Get_RampShader(); | shaderPrg = Get_RampShader(); | |||
if (!shaderPrg) | if (!shaderPrg) | |||
return NULL; | return nullptr; | |||
shaderPrg->Enable(); | shaderPrg->Enable(); | |||
return Setup_LabelShader(shaderPrg); | return Setup_LabelShader(shaderPrg); | |||
} | } | |||
CShaderPrg *CShaderMgr::Setup_LabelShader(CShaderPrg *shaderPrg) { | CShaderPrg *CShaderMgr::Setup_LabelShader(CShaderPrg *shaderPrg) { | |||
int width = 0, height = 0; | int width = 0, height = 0; | |||
shaderPrg->Set_Matrices(); | shaderPrg->Set_Matrices(); | |||
glActiveTexture(GL_TEXTURE3); | glActiveTexture(GL_TEXTURE3); | |||
skipping to change at line 1344 | skipping to change at line 1342 | |||
} | } | |||
SceneGetWidthHeightStereo(G, &width, &height); | SceneGetWidthHeightStereo(G, &width, &height); | |||
if (width) | if (width) | |||
shaderPrg->Set2f("screenSize", width, height); | shaderPrg->Set2f("screenSize", width, height); | |||
shaderPrg->SetBgUniforms(); | shaderPrg->SetBgUniforms(); | |||
{ | { | |||
float v_scale = SceneGetScreenVertexScale(G, NULL); | float v_scale = SceneGetScreenVertexScale(G, nullptr); | |||
shaderPrg->Set1f("screenOriginVertexScale", v_scale/2.f); | shaderPrg->Set1f("screenOriginVertexScale", v_scale/2.f); | |||
} | } | |||
{ | { | |||
float front, back; | float front, back; | |||
front = SceneGetCurrentFrontSafe(G); | front = SceneGetCurrentFrontSafe(G); | |||
back = SceneGetCurrentBackSafe(G); | back = SceneGetCurrentBackSafe(G); | |||
shaderPrg->Set1f("front", front); | shaderPrg->Set1f("front", front); | |||
shaderPrg->Set1f("clipRange", back - front); | shaderPrg->Set1f("clipRange", back - front); | |||
} | } | |||
return shaderPrg; | return shaderPrg; | |||
} | } | |||
CShaderPrg *CShaderMgr::Get_LabelShader(int pass){ | CShaderPrg *CShaderMgr::Get_LabelShader(int pass){ | |||
return GetShaderPrg("label", 1, pass); | return GetShaderPrg("label", 1, pass); | |||
} | } | |||
CShaderPrg *CShaderMgr::Get_ScreenShader() { | CShaderPrg *CShaderMgr::Get_ScreenShader() { | |||
if (is_picking) | if (is_picking) | |||
return NULL; | return nullptr; | |||
return GetShaderPrg("screen"); | return GetShaderPrg("screen"); | |||
} | } | |||
CShaderPrg *CShaderMgr::Get_RampShader() { | CShaderPrg *CShaderMgr::Get_RampShader() { | |||
return GetShaderPrg("ramp"); | return GetShaderPrg("ramp"); | |||
} | } | |||
CShaderPrg *CShaderMgr::Get_IndicatorShader() { | CShaderPrg *CShaderMgr::Get_IndicatorShader() { | |||
return GetShaderPrg("indicator"); | return GetShaderPrg("indicator"); | |||
} | } | |||
skipping to change at line 1399 | skipping to change at line 1397 | |||
} | } | |||
#ifdef PURE_OPENGL_ES_2 | #ifdef PURE_OPENGL_ES_2 | |||
shaderPrg->SetMat4fc("g_ModelViewMatrix", SceneGetModelViewMatrix(G)); | shaderPrg->SetMat4fc("g_ModelViewMatrix", SceneGetModelViewMatrix(G)); | |||
shaderPrg->SetMat4fc("g_ProjectionMatrix", SceneGetProjectionMatrix(G)); | shaderPrg->SetMat4fc("g_ProjectionMatrix", SceneGetProjectionMatrix(G)); | |||
#endif | #endif | |||
return (shaderPrg); | return (shaderPrg); | |||
} | } | |||
void CShaderMgr::ResetUniformSet() { | void CShaderMgr::ResetUniformSet() { | |||
for (map<string, CShaderPrg*>::iterator | for (auto & prog : programs) { | |||
it = programs.begin(), | prog.second->uniform_set = 0; | |||
end = programs.end(); it != end; ++it) { | ||||
it->second->uniform_set = 0; | ||||
} | } | |||
} | } | |||
void CShaderMgr::SetIsPicking(int is_picking) { | void CShaderMgr::SetIsPicking(int is_picking) { | |||
this->is_picking = is_picking; | this->is_picking = is_picking; | |||
} | } | |||
int CShaderMgr::GetIsPicking() { | int CShaderMgr::GetIsPicking() { | |||
return is_picking; | return is_picking; | |||
} | } | |||
skipping to change at line 1580 | skipping to change at line 1576 | |||
reload_bits |= bits; | reload_bits |= bits; | |||
} | } | |||
void CShaderMgr::Check_Reload() { | void CShaderMgr::Check_Reload() { | |||
if(!SettingGetGlobal_b(G, cSetting_use_shaders)) { | if(!SettingGetGlobal_b(G, cSetting_use_shaders)) { | |||
return; | return; | |||
} | } | |||
if (reload_bits){ | if (reload_bits){ | |||
if (reload_bits == RELOAD_ALL_SHADERS) { | if (reload_bits == RELOAD_ALL_SHADERS) { | |||
for (auto it = programs.begin(); it != programs.end(); ++it) | for (auto& prog : programs) | |||
it->second->is_valid = false; | prog.second->is_valid = false; | |||
shader_cache_processed.clear(); | shader_cache_processed.clear(); | |||
} | } | |||
Reload_All_Shaders(); | Reload_All_Shaders(); | |||
reload_bits = 0; | reload_bits = 0; | |||
} | } | |||
} | } | |||
GLfloat *CShaderMgr::GetLineWidthRange() { | GLfloat *CShaderMgr::GetLineWidthRange() { | |||
return line_width_range; | return line_width_range; | |||
skipping to change at line 1637 | skipping to change at line 1633 | |||
std::set<std::string> shadernames; | std::set<std::string> shadernames; | |||
std::vector<std::string> filenames; | std::vector<std::string> filenames; | |||
// variable -> files | // variable -> files | |||
for (const char ** filenameptr = ifdef_deps[variable]; | for (const char ** filenameptr = ifdef_deps[variable]; | |||
*filenameptr; ++filenameptr) { | *filenameptr; ++filenameptr) { | |||
CollectDependantFileNames(*filenameptr, filenames); | CollectDependantFileNames(*filenameptr, filenames); | |||
} | } | |||
// files -> shaders | // files -> shaders | |||
for (auto f_it = filenames.begin(); f_it != filenames.end(); ++f_it) { | for (auto& filename : filenames) { | |||
auto &vec = shader_deps[*f_it]; | auto &vec = shader_deps[filename]; | |||
for (auto n_it = vec.begin(); n_it != vec.end(); ++n_it) { | for (auto& n_it : vec) { | |||
shadernames.insert(*n_it); | shadernames.insert(n_it); | |||
} | } | |||
} | } | |||
// create shader derivatives | // create shader derivatives | |||
for (auto s_it = shadernames.begin(); s_it != shadernames.end(); ++s_it) { | for (const auto& shadername : shadernames) { | |||
CShaderPrg * shader = programs[*s_it]->DerivativeCopy(*s_it + suffix, variab | auto shader = programs[shadername]->DerivativeCopy(shadername + suffix, vari | |||
le); | able); | |||
programs[shader->name] = shader; | programs[shader->name] = shader; | |||
// register dependency | // register dependency | |||
RegisterDependantFileNames(shader); | RegisterDependantFileNames(shader); | |||
} | } | |||
} | } | |||
/* | /* | |||
* Reload the derivative shaders for `variable` | * Reload the derivative shaders for `variable` | |||
*/ | */ | |||
void CShaderMgr::Reload_Derivatives(const std::string &variable, bool value) { | void CShaderMgr::Reload_Derivatives(const std::string &variable, bool value) { | |||
SetPreprocVar(variable, value, false); | SetPreprocVar(variable, value, false); | |||
for (auto it = programs.begin(); it != programs.end(); ++it) { | for (auto& prog : programs) { | |||
if (it->second->derivative == variable) | if (prog.second->derivative == variable) | |||
it->second->reload(); | prog.second->reload(); | |||
} | } | |||
SetPreprocVar(variable, !value, false); | SetPreprocVar(variable, !value, false); | |||
} | } | |||
/* | /* | |||
* Removes `filename` and all it's parents from the shader source cache, | * Removes `filename` and all it's parents from the shader source cache, | |||
* and if `invshaders` is true, also clear the `is_valid` flag for all | * and if `invshaders` is true, also clear the `is_valid` flag for all | |||
* shader infos that depend on `filename`. | * shader infos that depend on `filename`. | |||
*/ | */ | |||
skipping to change at line 1686 | skipping to change at line 1682 | |||
if (it != include_deps.end()) { | if (it != include_deps.end()) { | |||
for (const char ** filenameptr = it->second; | for (const char ** filenameptr = it->second; | |||
*filenameptr; ++filenameptr) { | *filenameptr; ++filenameptr) { | |||
ShaderSourceInvalidate(*filenameptr, invshaders); | ShaderSourceInvalidate(*filenameptr, invshaders); | |||
} | } | |||
} | } | |||
// invalidate shaders | // invalidate shaders | |||
if (invshaders) { | if (invshaders) { | |||
auto &vec = shader_deps[filename]; | auto &vec = shader_deps[filename]; | |||
for (auto it = vec.begin(); it != vec.end(); ++it) { | for (const auto& shadername : vec) { | |||
programs[*it]->is_valid = false; | programs[shadername]->is_valid = false; | |||
} | } | |||
} | } | |||
// invalidate source file | // invalidate source file | |||
auto repl_it = shader_cache_processed.find(filename); | auto repl_it = shader_cache_processed.find(filename); | |||
if (repl_it != shader_cache_processed.end()) { | if (repl_it != shader_cache_processed.end()) { | |||
shader_cache_processed.erase(repl_it); | shader_cache_processed.erase(repl_it); | |||
} | } | |||
} | } | |||
skipping to change at line 1781 | skipping to change at line 1777 | |||
int uid = attribute_uids_by_name.size() + 1; | int uid = attribute_uids_by_name.size() + 1; | |||
attribute_uids_by_name[name] = uid; | attribute_uids_by_name[name] = uid; | |||
attribute_uids[uid] = name; | attribute_uids[uid] = name; | |||
return uid; | return uid; | |||
} | } | |||
const char *CShaderMgr::GetAttributeName(int uid) | const char *CShaderMgr::GetAttributeName(int uid) | |||
{ | { | |||
auto uloc = attribute_uids.find(uid); | auto uloc = attribute_uids.find(uid); | |||
if (uloc == attribute_uids.end()) | if (uloc == attribute_uids.end()) | |||
return NULL; | return nullptr; | |||
return attribute_uids[uid].c_str(); | return attribute_uids[uid].c_str(); | |||
} | } | |||
// SceneRenderBindToOffscreen | // SceneRenderBindToOffscreen | |||
void CShaderMgr::bindOffscreen(int width, int height, GridInfo *grid) { | void CShaderMgr::bindOffscreen(int width, int height, GridInfo *grid) { | |||
using namespace tex; | using namespace tex; | |||
ivec2 req_size(width, height); | ivec2 req_size(width, height); | |||
#ifndef _PYMOL_NO_AA_SHADERS | #ifndef _PYMOL_NO_AA_SHADERS | |||
#endif | #endif | |||
End of changes. 45 change blocks. | ||||
67 lines changed or deleted | 63 lines changed or added |