CGVIS Utils
Loading...
Searching...
No Matches
GLDepthTexture.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "GLEnv.h"
6
20public:
30 GLDepthTexture(GLint magFilter=GL_LINEAR, GLint minFilter=GL_LINEAR,
31 GLint wrapX=GL_CLAMP_TO_EDGE, GLint wrapY=GL_CLAMP_TO_EDGE) :
32 id{ 0 },
33 width{ 0 },
34 height{ 0 },
35 dataType{ GLDepthDataType::DEPTH24 }
36 {
37 GL(glGenTextures(1, &id));
38 GL(glBindTexture(GL_TEXTURE_2D, id));
39 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapX));
40 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapY));
41 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter));
42 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter));
43 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE));
44 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS));
45 }
46
49 GL(glDeleteTextures(1, &id));
50 }
51
56 const GLuint getId() const {return id;}
57
66 void setEmpty(uint32_t width, uint32_t height,
68 this->width = width;
69 this->height = height;
70
71 GL(glBindTexture(GL_TEXTURE_2D, id));
72 GL(glPixelStorei(GL_PACK_ALIGNMENT ,1));
73 GL(glPixelStorei(GL_UNPACK_ALIGNMENT ,1));
74
75 switch (dataType) {
77 GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, GLsizei(width),
78 GLsizei(height), 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0));
79 break;
81 GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, GLsizei(width),
82 GLsizei(height), 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0));
83 break;
85 GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, GLsizei(width),
86 GLsizei(height), 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0));
87 break;
88 }
89 }
90
93
94 uint32_t getHeight() const {return height;}
96 uint32_t getWidth() const {return width;}
98 GLDepthDataType getType() const {return dataType;}
100
106 void setFilter(GLint magFilter, GLint minFilter) {
107 GL(glBindTexture(GL_TEXTURE_2D, id));
108 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter));
109 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter));
110 }
111
112private:
113 GLuint id;
114 uint32_t width;
115 uint32_t height;
116 GLDepthDataType dataType;
117};
#define GL(stmt)
Debug wrapper that flushes and reports GL errors around a statement.
Definition GLDebug.h:101
Cross‑platform OpenGL window/context helper for desktop and Emscripten.
GLDepthDataType
Depth storage selection for depth textures.
Definition GLEnv.h:48
@ DEPTH24
Definition GLEnv.h:48
@ DEPTH16
Definition GLEnv.h:48
@ DEPTH32
Definition GLEnv.h:48
void setFilter(GLint magFilter, GLint minFilter)
Update the filtering parameters on the bound texture.
Definition GLDepthTexture.h:106
uint32_t getHeight() const
Face height in texels.
Definition GLDepthTexture.h:94
GLDepthDataType getType() const
Depth storage type used for allocation.
Definition GLDepthTexture.h:98
~GLDepthTexture()
Destroy and delete the GL texture name.
Definition GLDepthTexture.h:48
uint32_t getWidth() const
Face width in texels.
Definition GLDepthTexture.h:96
void setEmpty(uint32_t width, uint32_t height, GLDepthDataType dataType=GLDepthDataType::DEPTH24)
Allocate empty depth storage of the requested size/format.
Definition GLDepthTexture.h:66
GLDepthTexture(GLint magFilter=GL_LINEAR, GLint minFilter=GL_LINEAR, GLint wrapX=GL_CLAMP_TO_EDGE, GLint wrapY=GL_CLAMP_TO_EDGE)
Create a depth texture with initial sampler parameters.
Definition GLDepthTexture.h:30
const GLuint getId() const
Retrieve the OpenGL texture object name.
Definition GLDepthTexture.h:56