18 #ifndef PIC_UTIL_GL_MASK_HPP 19 #define PIC_UTIL_GL_MASK_HPP 21 #include "../../base.hpp" 36 GLuint tex = 0,
unsigned char *tmpBuffer = NULL,
bool mipmap =
false)
38 bool bGen = (tex == 0);
41 glGenTextures(1, &tex);
44 glBindTexture(GL_TEXTURE_2D, tex);
47 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
50 unsigned char *data = NULL;
53 int n = width * height;
55 if(tmpBuffer != NULL) {
58 data =
new unsigned char[n * 3];
61 #pragma omp parallel for 63 for(
int i = 0; i < n; i++) {
64 data[i] = buffer[i] ? 255 : 0;
71 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
76 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
77 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
78 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
86 glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, data);
89 glGenerateMipmap(GL_TEXTURE_2D);
92 glBindTexture(GL_TEXTURE_2D, 0);
94 if(data != NULL && tmpBuffer == NULL) {
PIC_INLINE GLuint GenerateMask(int width, int height, bool *buffer=NULL, GLuint tex=0, unsigned char *tmpBuffer=NULL, bool mipmap=false)
GenerateMask creates an opengl mask (a texture) from a buffer of bool values.
Definition: mask.hpp:35
#define PIC_INLINE
Definition: base.hpp:33
Definition: bilateral_separation.hpp:25