MeVisLabToolboxReference
|
00001 #ifndef __View2DShaderGLSL_H 00002 #define __View2DShaderGLSL_H 00003 //---------------------------------------------------------------------------------- 00004 // **InsertLicense** code 00005 //---------------------------------------------------------------------------------- 00012 //---------------------------------------------------------------------------------- 00013 00014 #include "SoView2DSystem.h" 00015 #include "mlDataTypes.h" 00016 00017 #include "View2DShader.h" 00018 00019 #include <string> 00020 00021 //----------------------------------------------------------------------------------------------- 00023 00031 class View2DShaderGLSL : public View2DTextureLUTShader { 00032 00033 public: 00034 View2DShaderGLSL(); 00035 virtual ~View2DShaderGLSL(); 00036 00038 static bool mayUseShaders(); 00039 00041 struct ShaderConfig { 00042 ShaderConfig() { 00043 use16Bit = false; 00044 filter = FILTER_LINEAR; 00045 } 00046 00047 ShaderConfig(View2DTextureFilter filter, bool use16Bit) { 00048 this->filter = filter; 00049 this->use16Bit = use16Bit; 00050 } 00051 00052 bool operator==(const ShaderConfig& other) const { 00053 return other.filter == this->filter && 00054 other.use16Bit == use16Bit; 00055 } 00056 00057 View2DTextureFilter filter; 00058 bool use16Bit; 00059 }; 00060 00062 struct Shader { 00063 00064 Shader(const ShaderConfig& config) { 00065 this->config = config; 00066 } 00067 00068 ShaderConfig config; 00069 00070 ml::GLSLFragmentShader fragmentShader; 00071 ml::GLSLVertexShader vertexShader; 00072 ml::GLSLProgram program; 00073 }; 00074 00076 virtual void bind(View2DTexture* texture, int tw, int th); 00077 00079 const char* name() { return "GLSL"; } 00080 00082 static bool runsInHardware(); 00083 00085 virtual void unbind(); 00086 00087 protected: 00088 00089 }; 00090 00092 class View2DShaderCacheGLSL { 00093 00094 public: 00097 View2DShaderGLSL::Shader* findOrCreateShader(const View2DShaderGLSL::ShaderConfig& config); 00098 00100 static View2DShaderCacheGLSL* self(); 00101 00102 private: 00104 std::vector<View2DShaderGLSL::Shader*> _shaders; 00105 00107 static View2DShaderCacheGLSL* _self; 00108 00110 static std::string getShaderErrors(GLuint shaderId); 00112 static std::string getProgramErrors(GLuint programId); 00113 00115 static bool create(View2DShaderGLSL::Shader* shader); 00116 00118 static bool create(View2DShaderGLSL::Shader* shader, const char* vertexShader, const char* fragmentShader); 00119 00120 static void createCubicShader(std::stringstream& str, bool use16BitLut); 00121 static void createNearestShader(std::stringstream& str, bool use16BitLut); 00122 static void createLinearShader(std::stringstream& str, bool use16BitLut); 00123 static void createTextHaloShader(std::stringstream& str, bool use16BitLut); 00124 00125 }; 00126 00127 #endif