11#ifndef GAMP_RENDER_GL_TEXTURE_TEXTUREDATA_HPP_
12#define GAMP_RENDER_GL_TEXTURE_TEXTUREDATA_HPP_
54 GLenum m_internalFormat;
57 bool m_dataIsCompressed;
58 bool m_mustFlipVertically;
62 std::vector<bytes_t> m_mipmapData;
65 unsigned m_estimatedMemorySize;
116 bool dataIsCompressed,
117 bool mustFlipVertically,
119 :
TextureData(glp, internalFormat, size, border, GLPixelAttributes(pixelFormat, pixelType),
120 mipmap, dataIsCompressed, mustFlipVertically, buffer, flusher) {}
165 GLPixelAttributes pixelAttributes,
167 bool dataIsCompressed,
168 bool mustFlipVertically,
170 if (mipmap && dataIsCompressed) {
173 this.glProfile = glp;
175 this.height = height;
176 this.border = border;
177 this.pixelAttributes = pixelAttributes;
178 this.internalFormat = internalFormat;
179 this.mipmap = mipmap;
180 this.dataIsCompressed = dataIsCompressed;
181 this.mustFlipVertically = mustFlipVertically;
182 this.buffer = buffer;
183 this.flusher = flusher;
228 final int internalFormat,
232 final int pixelFormat,
234 final boolean dataIsCompressed,
235 final boolean mustFlipVertically,
236 final Buffer[] mipmapData,
237 final Flusher flusher)
throws IllegalArgumentException {
238 this(glp, internalFormat, width, height, border,
new GLPixelAttributes(pixelFormat, pixelType),
239 dataIsCompressed, mustFlipVertically, mipmapData, flusher);
281 final int internalFormat,
285 final GLPixelAttributes pixelAttributes,
286 final boolean dataIsCompressed,
287 final boolean mustFlipVertically,
288 final Buffer[] mipmapData,
289 final Flusher flusher)
throws IllegalArgumentException {
290 this.glProfile = glp;
292 this.height = height;
293 this.border = border;
294 this.pixelAttributes = pixelAttributes;
295 this.internalFormat = internalFormat;
296 this.dataIsCompressed = dataIsCompressed;
297 this.mustFlipVertically = mustFlipVertically;
298 this.mipmapData = mipmapData.clone();
299 this.flusher = flusher;
301 for (
int i = 0; i < mipmapData.length; i++) {
319 protected TextureData(
final GLProfile glp) { this.glProfile = glp; this.pixelAttributes = GLPixelAttributes.UNDEF; }
339 return pixelAttributes;
343 return pixelAttributes.format;
347 return pixelAttributes.type;
351 return internalFormat;
359 return dataIsCompressed;
364 return mustFlipVertically;
387 public void setWidth(
final int width) { this.width = width; }
389 public void setHeight(
final int height) { this.height = height; }
391 public void setBorder(
final int border) { this.border = border; }
393 public void setPixelAttributes(
final GLPixelAttributes pixelAttributes) { this.pixelAttributes = pixelAttributes; }
401 if( pixelAttributes.format != pixelFormat ) {
402 pixelAttributes =
new GLPixelAttributes(pixelFormat, pixelAttributes.type);
412 if( pixelAttributes.type != pixelType) {
413 pixelAttributes =
new GLPixelAttributes(pixelAttributes.format, pixelType);
417 public void setInternalFormat(
final int internalFormat) { this.internalFormat = internalFormat; }
419 public void setMipmap(
final boolean mipmap) { this.mipmap = mipmap; }
424 public void setMustFlipVertically(
final boolean mustFlipVertically) { this.mustFlipVertically = mustFlipVertically; }
427 this.buffer = buffer;
431 public void setAlignment(
final int alignment) { this.alignment = alignment; }
435 public void setRowLength(
final int rowLength) { this.rowLength = rowLength; }
440 this.haveEXTABGR = haveEXTABGR;
447 this.haveGL12 = haveGL12;
465 if (flusher != null) {
489 final String optImageType = null != srcImageType ?
", "+srcImageType :
"";
490 return "TextureData["+width+
"x"+height+
", y-flip "+mustFlipVertically+
", internFormat 0x"+
Integer.toHexString(internalFormat)+
", "+
491 pixelAttributes+
", border "+border+
", estSize "+
estimatedMemorySize+
", alignment "+alignment+
", rowlen "+rowLength+optImageType;
499 if (buffer == null) {
502 return buffer.capacity() * Buffers.sizeOfBufferElem(buffer);
Specifies the OpenGL profile.
Point2I< uint32_t > Point2u32
Represents the data for an OpenGL texture.
boolean getMustFlipVertically()
Indicates whether the texture coordinates must be flipped vertically for proper display.
int getBorder()
Returns the border in pixels of the texture data.
final ImageType getSourceImageType()
Returns the source ImageType if applicable and known, otherwise null.
Buffer[] getMipmapData()
Returns all mipmap levels for the texture data, or null if it is specified as a single image.
void setAlignment(final int alignment)
Sets the required byte alignment for the texture data.
int getInternalFormat()
Returns the intended OpenGL internal format of the texture data.
GLProfile getGLProfile()
Returns the GLProfile this texture data is intended and created for.
int getPixelType()
Returns the intended OpenGL pixel type of the texture data using getPixelAttributes().
int getWidth()
Returns the width in pixels of the texture data.
TextureData(const GLProfile &glp, GLenum internalFormat, Point2u32 &size, unsigned border, GLenum pixelFormat, GLenum pixelType, bool mipmap, bool dataIsCompressed, bool mustFlipVertically, bytes_t &buffer)
Constructs a new TextureData object with the specified parameters and data contained in the given Buf...
void setHaveEXTABGR(final boolean haveEXTABGR)
Indicates to this TextureData whether the GL_EXT_abgr extension is available.
void setWidth(final int width)
Sets the width in pixels of the texture data.
void setMipmap(final boolean mipmap)
Sets whether mipmaps should be generated for the texture data.
int getHeight()
Returns the height in pixels of the texture data.
void setRowLength(final int rowLength)
Sets the row length needed for correct GL_UNPACK_ROW_LENGTH specification.
void setPixelFormat(final int pixelFormat)
Sets the intended OpenGL pixel format component of GLPixelAttributes of the texture data.
ColorSpace getColorSpace()
Returns the color space of the pixel data.
static int estimatedMemorySize(final Buffer buffer)
void setHaveGL12(final boolean haveGL12)
Indicates to this TextureData whether OpenGL version 1.2 is available.
void setColorSpace(final ColorSpace cs)
Set the color space of the pixel data, which defaults to ColorSpace#RGB.
GLPixelAttributes getPixelAttributes()
Returns the intended OpenGL GLPixelAttributes of the texture data, i.e.
int getEstimatedMemorySize()
Returns an estimate of the amount of memory in bytes this TextureData will consume once uploaded to t...
TextureData(final GLProfile glp)
Used only by subclasses.
void setPixelType(final int pixelType)
Sets the intended OpenGL pixel type component of GLPixelAttributes of the texture data.
void setMustFlipVertically(final boolean mustFlipVertically)
Sets whether the texture coordinates must be flipped vertically for proper display.
TextureData(final GLProfile glp, final int internalFormat, final int width, final int height, final int border, final int pixelFormat, final int pixelType, final boolean dataIsCompressed, final boolean mustFlipVertically, final Buffer[] mipmapData, final Flusher flusher)
Constructs a new TextureData object with the specified parameters and data for multiple mipmap levels...
void setHeight(final int height)
Sets the height in pixels of the texture data.
static interface Flusher
Defines a callback mechanism to allow the user to explicitly deallocate native resources (memory-mapp...
ColorSpace
ColorSpace of pixel data.
void setIsDataCompressed(final boolean compressed)
Sets whether the texture data is in compressed form.
void flush()
Flushes resources associated with this TextureData by calling Flusher.flush().
void setBorder(final int border)
Sets the border in pixels of the texture data.
TextureData(final GLProfile glp, final int internalFormat, final int width, final int height, final int border, final GLPixelAttributes pixelAttributes, final boolean dataIsCompressed, final boolean mustFlipVertically, final Buffer[] mipmapData, final Flusher flusher)
Constructs a new TextureData object with the specified parameters and data for multiple mipmap levels...
int getRowLength()
Returns the row length needed for correct GL_UNPACK_ROW_LENGTH specification.
void destroy()
Calls flush()
int getAlignment()
Returns the required byte alignment for the texture data.
boolean getMipmap()
Returns whether mipmaps should be generated for the texture data.
void setBuffer(final Buffer buffer)
Sets the texture data.
void setInternalFormat(final int internalFormat)
Sets the intended OpenGL internal format of the texture data.
void setPixelAttributes(final GLPixelAttributes pixelAttributes)
Sets the intended OpenGL pixel format of the texture data.
int getPixelFormat()
Returns the intended OpenGL pixel format of the texture data using getPixelAttributes().
Buffer getBuffer()
Returns the texture data, or null if it is specified as a set of mipmaps.
TextureData(const GLProfile &glp, int internalFormat, Point2u32 &size, int border, GLPixelAttributes pixelAttributes, bool mipmap, bool dataIsCompressed, bool mustFlipVertically, bytes_t &buffer)
Constructs a new TextureData object with the specified parameters and data contained in the given Buf...
std::vector< uint8_t > bytes_t
boolean isDataCompressed()
Indicates whether the texture data is in compressed form.