PICCANTE  0.4
The hottest HDR imaging library!
filter_sampler_2d.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_GL_FILTERING_FILTER_SAMPLER_2D_HPP
19 #define PIC_GL_FILTERING_FILTER_SAMPLER_2D_HPP
20 
21 #include "../../gl/filtering/filter.hpp"
22 
23 namespace pic {
24 
29 {
30 protected:
31  float scale;
32 
36  void initShaders()
37  {
39  (
40  uniform sampler2D u_tex; \n
41  uniform float scale; \n
42  out vec4 f_color; \n
43 
44  void main(void) { \n
45  vec2 coords = gl_FragCoord.xy / vec2(scale);
46  vec3 color = texelFetch(u_tex, ivec2(coords), 0).xyz; \n
47  f_color = vec4(color.xyz, 1.0); \n
48  }
49  );
50 
51  technique.initStandard("330", vertex_source, fragment_source, "FilterGLSampler2D");
52  }
53 
54 public:
60  {
61  initShaders();
62  update(scale);
63  }
64 
66  {
67  release();
68  }
69 
78  void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
79  {
80  if(imgIn.empty()) {
81  width = -1;
82  height = -2;
83  channels = -2;
84  frames = -2;
85  }
86 
87  if(imgIn.size() == 1) {
88  width = int(imgIn[0]->widthf * scale);
89  height = int(imgIn[0]->heightf * scale);
90  } else {
91  width = imgIn[1]->width;
92  height = imgIn[1]->height;
93  }
94 
95  channels = imgIn[0]->channels;
96  frames = imgIn[0]->frames;
97  }
98 
103  void update(float scale)
104  {
105  if(scale > 0.0f) {
106  this->scale = scale;
107  }
108 
109  if(technique.isValid()) {
110  technique.bind();
111  technique.setUniform1f("scale", scale);
112  technique.unbind();
113  }
114  }
115 
123  static ImageGL *execute(ImageGL *imgIn, ImageGL *imgOut, float scale)
124  {
125  imgIn->generateTextureGL(GL_TEXTURE_2D, GL_FLOAT, false);
126 
127  FilterGLSampler2D filter(scale);
128 
129  imgOut = filter.Process(SingleGL(imgIn), imgOut);
130 
131  return imgOut;
132  }
133 };
134 
135 
136 } // end namespace pic
137 
138 #endif /* PIC_GL_FILTERING_FILTER_SAMPLER_2D_HPP */
139 
TechniqueGL technique
Definition: display.hpp:45
void update(float scale)
update
Definition: filter_sampler_2d.hpp:103
GLuint generateTextureGL(GLenum target, GLenum format_type, bool mipmap)
generateTextureGL
FilterGLSampler2D(float scale)
FilterGLSampler2D.
Definition: filter_sampler_2d.hpp:59
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
PIC_INLINE ImageGLVec SingleGL(ImageGL *img)
SingleGL creates a single for filters input.
Definition: image_vec.hpp:39
The ImageGL class.
Definition: image.hpp:42
void setUniform1f(const char *name_uniform, float value0)
SetUniform1f.
Definition: display.hpp:247
virtual ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: display.hpp:258
The FilterGL class.
Definition: filter.hpp:35
void initShaders()
initShaders
Definition: filter_sampler_2d.hpp:36
The FilterGLSampler2D class.
Definition: filter_sampler_2d.hpp:28
bool initStandard(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source, std::string name)
initStandard
Definition: display.hpp:114
void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_sampler_2d.hpp:78
void unbind()
unbind
Definition: display.hpp:197
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
static ImageGL * execute(ImageGL *imgIn, ImageGL *imgOut, float scale)
execute
Definition: filter_sampler_2d.hpp:123
~FilterGLSampler2D()
Definition: filter_sampler_2d.hpp:65
bool isValid()
Definition: display.hpp:62
std::string fragment_source
Definition: display.hpp:57
float scale
Definition: filter_sampler_2d.hpp:31
std::vector< ImageGL * > ImageGLVec
ImageGLVec an std::vector of pic::ImageGL.
Definition: image_vec.hpp:32
void release()
release
Definition: display.hpp:85