MeVisLab Toolbox Reference
View2DShaderGLSL.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2010, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #pragma once
14 
15 #include "SoView2DSystem.h"
16 #include "mlDataTypes.h"
17 
18 #include "View2DShader.h"
19 
20 #include <string>
21 
22 //-----------------------------------------------------------------------------------------------
24 
33 {
34 public:
36  ~View2DShaderGLSL() override;
37 
39  static bool mayUseShaders();
40 
42  struct ShaderConfig {
44  use16Bit = false;
45  filter = FILTER_LINEAR;
46  }
47 
48  ShaderConfig(View2DTextureFilter filter, bool use16Bit) {
49  this->filter = filter;
50  this->use16Bit = use16Bit;
51  }
52 
53  bool operator==(const ShaderConfig& other) const {
54  return other.filter == this->filter &&
55  other.use16Bit == use16Bit;
56  }
57 
59  bool use16Bit;
60  };
61 
63  struct Shader {
64 
65  Shader(const ShaderConfig& config) {
66  this->config = config;
67  }
68 
70 
71  ml::GLSLFragmentShader fragmentShader;
72  ml::GLSLVertexShader vertexShader;
73  ml::GLSLProgram program;
74  };
75 
77  void bind(View2DTexture* texture, int tw, int th) override;
78 
80  const char* name() override;
81 
83  static bool runsInHardware();
84 
86  void unbind() override;
87 };
88 
91 {
92 public:
96 
98  static View2DShaderCacheGLSL* self();
99 
100 private:
102  std::vector<View2DShaderGLSL::Shader*> _shaders;
103 
105  static View2DShaderCacheGLSL* _self;
106 
108  static std::string getShaderErrors(GLuint shaderId);
110  static std::string getProgramErrors(GLuint programId);
111 
113  static bool create(View2DShaderGLSL::Shader* shader);
114 
116  static bool create(View2DShaderGLSL::Shader* shader, const char* vertexShader, const char* fragmentShader);
117 
118  static void createCubicShader(std::stringstream& str, bool use16BitLut);
119  static void createNearestShader(std::stringstream& str, bool use16BitLut);
120  static void createLinearShader(std::stringstream& str, bool use16BitLut);
121  static void createTextHaloShader(std::stringstream& str, bool use16BitLut);
122  static void createARGBShader(std::stringstream& str);
123 };
View2DTextureFilter
Filter mode.
@ FILTER_LINEAR
Bilinear filtering (after classification/LUT)
#define SOVIEW2D_API
File to resolve system dependencies in View2D library.
Global GLSL shader cache for all shaders that are used in the SoView2D.
View2DShaderGLSL::Shader * findOrCreateShader(const View2DShaderGLSL::ShaderConfig &config)
Finds the given shader or creates it if not yet available The returned shader contains an already com...
specialized shader that uses GLSL to implement a (up-to) 16 bit Hardware Lut
void unbind() override
deactivates the shader
void bind(View2DTexture *texture, int tw, int th) override
binds/activates the shader
const char * name() override
get the shader's name
static bool mayUseShaders()
returns if GLSL shaders may be used
static bool runsInHardware()
returns if the shader is supported and would run in hardware (calling this method requires a valid GL...
~View2DShaderGLSL() override
abstract base class for shaders that use a 2D texture for LUT lookup
Definition: View2DShader.h:88
A class to render images as OpenGL Textures.
Definition: View2DTexture.h:47
Stores a shader configuration.
bool operator==(const ShaderConfig &other) const
ShaderConfig(View2DTextureFilter filter, bool use16Bit)
Stores a full shader program for the given configuration.
Shader(const ShaderConfig &config)
ml::GLSLFragmentShader fragmentShader
ml::GLSLVertexShader vertexShader