MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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{
34public:
37
39 static bool mayUseShaders();
40
43 {
45 {
46 use16Bit = false;
47 filter = FILTER_LINEAR;
48 }
49
50 ShaderConfig(View2DTextureFilter filter, bool use16Bit)
51 {
52 this->filter = filter;
53 this->use16Bit = use16Bit;
54 }
55
56 bool operator==(const ShaderConfig& other) const
57 {
58 return other.filter == this->filter && other.use16Bit == use16Bit;
59 }
60
63 };
64
66 struct Shader
67 {
68
69 Shader(const ShaderConfig& config)
70 {
71 this->config = config;
72 }
73
75
76 ml::GLSLFragmentShader fragmentShader;
77 ml::GLSLVertexShader vertexShader;
78 ml::GLSLProgram program;
79 };
80
82 void bind(View2DTexture* texture, int tw, int th) override;
83
85 const char* name() override;
86
88 static bool runsInHardware();
89
91 void unbind() override;
92};
93
96{
97public:
101
104
105private:
107 std::vector<View2DShaderGLSL::Shader*> _shaders;
108
110 static View2DShaderCacheGLSL* _self;
111
113 static std::string getShaderErrors(GLuint shaderId);
115 static std::string getProgramErrors(GLuint programId);
116
118 static bool create(View2DShaderGLSL::Shader* shader);
119
121 static bool create(View2DShaderGLSL::Shader* shader, const char* vertexShader, const char* fragmentShader);
122
123 static void createCubicShader(std::stringstream& str, bool use16BitLut);
124 static void createNearestShader(std::stringstream& str, bool use16BitLut);
125 static void createLinearShader(std::stringstream& str, bool use16BitLut);
126 static void createTextHaloShader(std::stringstream& str, bool use16BitLut);
127 static void createARGBShader(std::stringstream& str);
128};
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.
static View2DShaderCacheGLSL * self()
get the shader cache singleton (creates it if not yet present)
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
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...
const char * name() override
get the shader's name
~View2DShaderGLSL() override
abstract base class for shaders that use a 2D texture for LUT lookup
A class to render images as OpenGL Textures.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
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