18 #ifndef PIC_UTIL_GL_BUFFER_OP_HPP 19 #define PIC_UTIL_GL_BUFFER_OP_HPP 21 #include "../../base.hpp" 23 #include "../../util/array.hpp" 25 #include "../../util/string.hpp" 26 #include "../../util/gl/quad.hpp" 27 #include "../../util/gl/fbo.hpp" 92 void Process(GLuint tex0, GLuint tex1, GLuint texOut,
int width,
int height);
105 memcpy(this->
c0,
c0, 4 *
sizeof(
float));
111 memcpy(this->
c1,
c1, 4 *
sizeof(
float));
132 std::string strOp =
"vec4 ret = ";
141 size_t I_found = strOp.find(
"I0x");
143 if(I_found != std::string::npos) {
145 strOp.replace(I_found, 3,
"texelFetch(u_tex_0, coords, 0).xxxx");
147 strOp.replace(I_found, 3,
"texture(u_tex_0, coords).xxxx");
154 strOp =
"vec4 tmp0x = texelFetch(u_tex_0, coords, 0);\n" + strOp;
156 strOp =
"vec4 tmp0x = texture(u_tex_0, coords);\n" + strOp;
166 size_t I_found = strOp.find(
"I1x");
168 if(I_found != std::string::npos) {
170 strOp.replace(I_found, 3,
"texelFetch(u_tex_1, coords, 0).xxxx");
172 strOp.replace(I_found, 3,
"texture(u_tex_1, coords).xxxx");
179 strOp =
"vec4 tmp1x = texelFetch(u_tex_1, coords, 0);\n" + strOp;
181 strOp =
"vec4 tmp1x = texture(u_tex_1, coords);\n" + strOp;
191 size_t I_found = strOp.find(
"I0");
193 if(I_found != std::string::npos) {
195 strOp.replace(I_found, 2,
"texelFetch(u_tex_0, coords, 0)");
197 strOp.replace(I_found, 2,
"texture(u_tex_0, coords)");
203 strOp =
"vec4 tmp0 = texelFetch(u_tex_0, coords, 0);\n" + strOp;
205 strOp =
"vec4 tmp0 = texture(u_tex_0, coords);\n" + strOp;
216 size_t I_found = strOp.find(
"I1");
218 if(I_found != std::string::npos) {
220 strOp.replace(I_found, 2,
"texelFetch(u_tex_1, coords, 0)");
222 strOp.replace(I_found, 2,
"texture(u_tex_1, coords)");
228 strOp =
"vec4 tmp1 = texelFetch(u_tex_1, coords, 0);\n" + strOp;
230 strOp =
"vec4 tmp1 = texture(u_tex_1, coords);\n" + strOp;
243 uniform sampler2D u_tex_0; \n
244 uniform sampler2D u_tex_1; \n
245 uniform vec4 u_val_0; \n
246 uniform vec4 u_val_1; \n
247 in vec2 v_tex_coord; \n
251 _COORDINATES_FOR_FETCHING_ \n
252 _PROCESSING_OPERATOR_ \n
258 size_t processing_found =
fragment_source.find(
"_COORDINATES_FOR_FETCHING_");
260 "ivec2 coords = ivec2(gl_FragCoord.xy);\n");
262 size_t processing_found =
fragment_source.find(
"_COORDINATES_FOR_FETCHING_");
264 "vec2 coords = v_tex_coord.xy;\n");
267 size_t processing_found =
fragment_source.find(
"_PROCESSING_OPERATOR_");
298 memcpy(this->c0,
c0,
sizeof(
float) * 4);
302 memcpy(this->
c1,
c1,
sizeof(
float) * 4);
330 printf(
"BufferOpGL::Process: the output texture, texOut, is empty.\n");
339 fbo->
create(width, height, 1,
false, texOut);
343 glViewport(0, 0, (GLsizei)width, (GLsizei)height);
349 glActiveTexture(GL_TEXTURE0);
350 glBindTexture(GL_TEXTURE_2D, tex0);
352 glActiveTexture(GL_TEXTURE1);
353 glBindTexture(GL_TEXTURE_2D, tex1);
364 glActiveTexture(GL_TEXTURE1);
365 glBindTexture(GL_TEXTURE_2D, 0);
367 glActiveTexture(GL_TEXTURE0);
368 glBindTexture(GL_TEXTURE_2D, 0);
QuadGL * quad
Definition: buffer_op.hpp:42
static std::string getVertexProgramWithTexCoordinates()
getVertexProgramWithTexCoordinates creates a simple vertex program with texture coordinates as input...
Definition: quad.hpp:253
std::string op
Definition: buffer_op.hpp:48
The BufferOpGL class.
Definition: buffer_op.hpp:34
The Fbo class.
Definition: display.hpp:32
void Process(GLuint tex0, GLuint tex1, GLuint texOut, int width, int height)
Process.
int countSubString(std::string str, std::string subStr)
countSubString counts how many subStr are in str.
Definition: string.hpp:240
void setOutputFragmentShaderIndex(const char *fragment_output_color_name, unsigned int index)
setOutputFragmentShaderIndex
Definition: technique.hpp:215
BufferOpGL(std::string op, bool bTexelFetch, float *c0, float *c1)
BufferOpGL.
void unbind()
unbind
Definition: technique.hpp:197
void link()
link
Definition: technique.hpp:205
The Fbo class.
Definition: fbo.hpp:32
std::string vertex_source
Definition: buffer_op.hpp:59
#define MAKE_STRING(input_string)
void initShaders()
initShaders
bool init(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source)
Definition: technique.hpp:67
void update(const float *c0, const float *c1)
update
The TechniqueGL class.
Definition: technique.hpp:31
bool bTexelFetch
Definition: buffer_op.hpp:50
TechniqueGL technique
Definition: buffer_op.hpp:45
static std::string getVertexProgramV3()
getVertexProgramV3 creates a simple vertex program.
Definition: quad.hpp:216
The QuadGL class.
Definition: quad.hpp:30
Fbo * fbo
Definition: buffer_op.hpp:39
void setUniform4fv(const char *name_uniform, const float *value)
setUniform4
Definition: technique.hpp:343
void printLog(std::string name)
printLog
Definition: technique.hpp:176
std::string fragment_source
Definition: buffer_op.hpp:59
#define PIC_INLINE
Definition: base.hpp:33
bool create(int width, int height, bool bDepth)
create
void setAttributeIndex(const char *attribute_name, unsigned int index)
setAttributeIndex
Definition: technique.hpp:225
void Render()
Render draws a quad on screen.
Definition: quad.hpp:140
std::string stdStringRepAll(std::string str, std::string strSub, std::string strRep)
stdStringRepAll replaces all strSub in str with strRep.
Definition: string.hpp:79
GLenum target
Definition: buffer_op.hpp:46
float c1[4]
Definition: buffer_op.hpp:49
Definition: bilateral_separation.hpp:25
static T * assign(T *data, int size, T *ret)
assign
Definition: array.hpp:464
The QuadGL class.
Definition: display.hpp:30
std::string geometry_source
Definition: buffer_op.hpp:59
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: technique.hpp:236
void bind()
bind
Definition: technique.hpp:189
float c0[4]
Definition: buffer_op.hpp:49