Shadow mapping
This commit is contained in:
82
texture.hh
82
texture.hh
@@ -22,6 +22,88 @@ static unsigned ilog2(unsigned in)
|
||||
return ret;
|
||||
}
|
||||
|
||||
class Framebuffer {
|
||||
public:
|
||||
Framebuffer() {
|
||||
glGenFramebuffers(1, &_fbID);
|
||||
}
|
||||
|
||||
~Framebuffer() {
|
||||
glDeleteFramebuffers(1, &_fbID);
|
||||
}
|
||||
|
||||
void bind() const {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbID);
|
||||
}
|
||||
|
||||
GLuint getID() const {
|
||||
return _fbID;
|
||||
}
|
||||
|
||||
void attachTexture(GLenum textarget, GLuint texID) {
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
||||
textarget, texID, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
GLuint _fbID;
|
||||
};
|
||||
|
||||
class TextureCubeMap {
|
||||
public:
|
||||
TextureCubeMap(unsigned size) {
|
||||
glGenTextures(1, &_texID);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, _texID);
|
||||
|
||||
if(SDL_GL_ExtensionSupported("GL_ARB_texture_storage"))
|
||||
glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT24,
|
||||
size, size);
|
||||
else {
|
||||
std::printf("Warning: extension GL_ARB_texture_storage not supported!\n");
|
||||
for (unsigned i = 0;i < 6;++i) {
|
||||
GLenum const face[6] = {GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z};
|
||||
glTexImage2D(face[i], 0, static_cast<GLint>(GL_DEPTH_COMPONENT16), size, size, 0,
|
||||
GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);
|
||||
}
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(GL_LINEAR));
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, static_cast<GLint>(GL_LINEAR));
|
||||
}
|
||||
|
||||
~TextureCubeMap() {
|
||||
glDeleteTextures(1, &_texID);
|
||||
}
|
||||
|
||||
TextureCubeMap(TextureCubeMap const& copy) = delete;
|
||||
TextureCubeMap& operator=(TextureCubeMap const& copy) = delete;
|
||||
|
||||
TextureCubeMap(TextureCubeMap && move) : _texID(move._texID) {
|
||||
move._texID = 0;
|
||||
}
|
||||
|
||||
TextureCubeMap& operator=(TextureCubeMap && move) {
|
||||
glDeleteTextures(1, &_texID);
|
||||
_texID = move._texID;
|
||||
move._texID = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void bind() const {
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, _texID);
|
||||
}
|
||||
|
||||
GLuint getID() const {
|
||||
return _texID;
|
||||
}
|
||||
|
||||
private:
|
||||
GLuint _texID;
|
||||
};
|
||||
|
||||
class Texture2D {
|
||||
public:
|
||||
Texture2D(unsigned width, unsigned height) {
|
||||
|
||||
Reference in New Issue
Block a user