Skip to content

Commit 384094d

Browse files
committed
Add texture cube map initialization utility function
1 parent 33bdd04 commit 384094d

9 files changed

+47
-0
lines changed

source/globjects/include/globjects/Texture.h

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ class GLOBJECTS_API Texture : public Object
125125

126126
void generateMipmap();
127127

128+
void cubeMapImage(gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data);
129+
void cubeMapImage(gl::GLint level, gl::GLenum internalFormat, const glm::ivec2 & size, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data);
130+
128131
TextureHandle textureHandle() const;
129132
TextureHandle textureHandle(Sampler * sampler) const;
130133

source/globjects/source/Texture.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,16 @@ void Texture::generateMipmap()
404404
implementation().generateMipMap(this);
405405
}
406406

407+
void Texture::cubeMapImage(gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data)
408+
{
409+
implementation().cubeMapImage(this, level, internalFormat, width, height, border, format, type, data);
410+
}
411+
412+
void Texture::cubeMapImage(gl::GLint level, gl::GLenum internalFormat, const glm::ivec2 & size, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data)
413+
{
414+
cubeMapImage(level, internalFormat, size.x, size.y, border, format, type, data);
415+
}
416+
407417
void Texture::accept(ObjectVisitor& visitor)
408418
{
409419
visitor.visitTexture(this);

source/globjects/source/implementations/AbstractTextureImplementation.h

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class AbstractTextureImplementation
4747
virtual void storage2D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height) const = 0;
4848
virtual void storage3D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLsizei depth) const = 0;
4949

50+
virtual void cubeMapImage(const Texture * texture, gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data) const = 0;
51+
5052
virtual void texBuffer(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer) const = 0;
5153
virtual void texBufferRange(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer, const gl::GLintptr offset, const gl::GLsizeiptr size) const = 0;
5254

source/globjects/source/implementations/TextureImplementation_DirectStateAccessARB.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ void TextureImplementation_DirectStateAccessARB::storage3D(const Texture * textu
144144
gl::glTextureStorage3D(texture->id(), levels, internalFormat, width, height, depth);
145145
}
146146

147+
void TextureImplementation_DirectStateAccessARB::cubeMapImage(const Texture * texture, gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data) const
148+
{
149+
get(Texture::BindlessImplementation::DirectStateAccessEXT)->cubeMapImage(texture, level, internalFormat, width, height, border, format, type, data);
150+
}
151+
147152
void TextureImplementation_DirectStateAccessARB::texBuffer(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer) const
148153
{
149154
gl::glTextureBuffer(texture->id(), internalFormat, buffer ? buffer->id() : 0);

source/globjects/source/implementations/TextureImplementation_DirectStateAccessARB.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class TextureImplementation_DirectStateAccessARB : public AbstractTextureImpleme
4545
virtual void storage2D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height) const override;
4646
virtual void storage3D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLsizei depth) const override;
4747

48+
virtual void cubeMapImage(const Texture * texture, gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data) const override;
49+
4850
virtual void texBuffer(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer) const override;
4951
virtual void texBufferRange(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer, const gl::GLintptr offset, const gl::GLsizeiptr size) const override;
5052

source/globjects/source/implementations/TextureImplementation_DirectStateAccessEXT.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ void TextureImplementation_DirectStateAccessEXT::storage3D(const Texture * textu
139139
gl::glTextureStorage3DEXT(texture->id(), texture->target(), levels, internalFormat, width, height, depth);
140140
}
141141

142+
void TextureImplementation_DirectStateAccessEXT::cubeMapImage(const Texture * texture, gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data) const
143+
{
144+
texture->bind();
145+
146+
for (int i = 0; i < 6; ++i)
147+
{
148+
gl::glTextureImage2DEXT(texture->id(), gl::GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, level, static_cast<gl::GLint>(internalFormat), width, height, border, format, type, data);
149+
}
150+
}
151+
142152
void TextureImplementation_DirectStateAccessEXT::texBuffer(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer) const
143153
{
144154
gl::glTextureBufferEXT(texture->id(), texture->target(), internalFormat, buffer ? buffer->id() : 0);

source/globjects/source/implementations/TextureImplementation_DirectStateAccessEXT.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class TextureImplementation_DirectStateAccessEXT : public AbstractTextureImpleme
4545
virtual void storage2D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height) const override;
4646
virtual void storage3D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLsizei depth) const override;
4747

48+
virtual void cubeMapImage(const Texture * texture, gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data) const override;
49+
4850
virtual void texBuffer(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer) const override;
4951
virtual void texBufferRange(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer, const gl::GLintptr offset, const gl::GLsizeiptr size) const override;
5052

source/globjects/source/implementations/TextureImplementation_Legacy.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <glm/gtc/type_ptr.hpp>
55

66
#include <glbinding/gl/functions.h>
7+
#include <glbinding/gl/enum.h>
78

89
#include <globjects/globjects.h>
910

@@ -180,6 +181,16 @@ void TextureImplementation_Legacy::storage3D(const Texture * texture, gl::GLsize
180181
gl::glTexStorage3D(texture->target(), levels, internalFormat, width, height, depth);
181182
}
182183

184+
void TextureImplementation_Legacy::cubeMapImage(const Texture * texture, gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data) const
185+
{
186+
texture->bind();
187+
188+
for (int i = 0; i < 6; ++i)
189+
{
190+
gl::glTexImage2D(gl::GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, level, static_cast<gl::GLint>(internalFormat), width, height, border, format, type, data);
191+
}
192+
}
193+
183194
void TextureImplementation_Legacy::texBuffer(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer) const
184195
{
185196
texture->bind();

source/globjects/source/implementations/TextureImplementation_Legacy.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class TextureImplementation_Legacy : public AbstractTextureImplementation
4545
virtual void storage2D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height) const override;
4646
virtual void storage3D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLsizei depth) const override;
4747

48+
virtual void cubeMapImage(const Texture * texture, gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data) const override;
49+
4850
virtual void texBuffer(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer) const override;
4951
virtual void texBufferRange(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer, const gl::GLintptr offset, const gl::GLsizeiptr size) const override;
5052

0 commit comments

Comments
 (0)