17 #include <osg/BufferObject>
21 #include <osg/FrameStamp>
22 #include <osg/StateAttribute>
27 #ifndef GL_VERSION_1_2
30 #define GL_BGRA 0x80E1
31 #define GL_UNSIGNED_BYTE_3_3_2 0x8032
32 #define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
33 #define GL_UNSIGNED_SHORT_5_6_5 0x8363
34 #define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
35 #define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
36 #define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
37 #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
38 #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
39 #define GL_UNSIGNED_INT_8_8_8_8 0x8035
40 #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
41 #define GL_UNSIGNED_INT_10_10_10_2 0x8036
42 #define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
45 #ifndef GL_COMPRESSED_ALPHA
46 #define GL_COMPRESSED_ALPHA 0x84E9
47 #define GL_COMPRESSED_LUMINANCE 0x84EA
48 #define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB
49 #define GL_COMPRESSED_INTENSITY 0x84EC
50 #define GL_COMPRESSED_RGB 0x84ED
51 #define GL_COMPRESSED_RGBA 0x84EE
56 #define GL_ABGR_EXT 0x8000
59 #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
61 #define GL_GREEN 0x1904
62 #define GL_BLUE 0x1905
63 #define GL_DEPTH_COMPONENT 0x1902
64 #define GL_STENCIL_INDEX 0x1901
67 #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GL3_AVAILABLE)
68 #define GL_BITMAP 0x1A00
69 #define GL_COLOR_INDEX 0x1900
70 #define GL_INTENSITY12 0x804C
71 #define GL_INTENSITY16 0x804D
72 #define GL_INTENSITY 0x8049
73 #define GL_INTENSITY4 0x804A
74 #define GL_INTENSITY8 0x804B
75 #define GL_LUMINANCE12 0x8041
76 #define GL_LUMINANCE12_ALPHA4 0x8046
77 #define GL_LUMINANCE12_ALPHA12 0x8047
78 #define GL_LUMINANCE16 0x8042
79 #define GL_LUMINANCE16_ALPHA16 0x8048
80 #define GL_LUMINANCE4 0x803F
81 #define GL_LUMINANCE4_ALPHA4 0x8043
82 #define GL_LUMINANCE6_ALPHA2 0x8044
83 #define GL_LUMINANCE8 0x8040
84 #define GL_LUMINANCE8_ALPHA8 0x8045
85 #define GL_RGBA8 0x8058
86 #define GL_RGBA16 0x805B
87 #define GL_PACK_ROW_LENGTH 0x0D02
90 #ifndef GL_PACK_SKIP_IMAGES
91 #define GL_PACK_SKIP_IMAGES 0x806B
92 #define GL_PACK_IMAGE_HEIGHT 0x806C
93 #define GL_UNPACK_SKIP_IMAGES 0x806D
94 #define GL_UNPACK_IMAGE_HEIGHT 0x806E
97 #ifndef GL_OES_compressed_ETC1_RGB8_texture
98 #define GL_ETC1_RGB8_OES 0x8D64
101 #ifndef GL_ARB_ES3_compatibility
102 #define GL_COMPRESSED_RGB8_ETC2 0x9274
103 #define GL_COMPRESSED_SRGB8_ETC2 0x9275
104 #define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276
105 #define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277
106 #define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
107 #define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279
108 #define GL_COMPRESSED_R11_EAC 0x9270
109 #define GL_COMPRESSED_SIGNED_R11_EAC 0x9271
110 #define GL_COMPRESSED_RG11_EAC 0x9272
111 #define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273
114 #ifndef GL_DEPTH_COMPONENT
115 #define GL_DEPTH_COMPONENT 0x1902
118 #ifndef GL_VERSION_1_4
119 #define GL_DEPTH_COMPONENT16 0x81A5
120 #define GL_DEPTH_COMPONENT24 0x81A6
121 #define GL_DEPTH_COMPONENT32 0x81A7
124 #ifndef GL_DEPTH_COMPONENT32F
125 #define GL_DEPTH_COMPONENT32F 0x8CAC
128 #ifndef GL_DEPTH_COMPONENT32F_NV
129 #define GL_DEPTH_COMPONENT32F_NV 0x8DAB
152 virtual const char*
className()
const {
return "Image"; }
158 virtual unsigned int getTotalDataSize()
const {
return getTotalSizeInBytesIncludingMipmaps(); }
161 virtual int compare(
const Image& rhs)
const;
163 void setFileName(
const std::string& fileName);
164 inline const std::string&
getFileName()
const {
return _fileName; }
189 virtual void allocateImage(
int s,
int t,
int r,
190 GLenum pixelFormat,GLenum
type,
195 virtual void setImage(
int s,
int t,
int r,
196 GLint internalTextureformat,
197 GLenum pixelFormat,GLenum
type,
200 int packing=1,
int rowLength=0);
205 virtual void readPixels(
int x,
int y,
int width,
int height,
206 GLenum pixelFormat, GLenum
type,
int packing=1);
212 virtual void readImageFromCurrentTexture(
unsigned int contextID,
bool copyMipMapsIfAvailable, GLenum
type = GL_UNSIGNED_BYTE,
unsigned int face = 0);
221 virtual void scaleImage(
int s,
int t,
int r, GLenum newDataType);
230 virtual void copySubImage(
int s_offset,
int t_offset,
int r_offset,
const osg::Image* source);
251 inline int s()
const {
return _s; }
254 inline int t()
const {
return _t; }
257 inline int r()
const {
return _r; }
259 void setRowLength(
int length);
265 void setPixelFormat(GLenum pixelFormat);
268 void setDataType(GLenum dataType);
271 void setPacking(
unsigned int packing) { _packing = packing; }
275 bool isCompressed()
const;
284 inline unsigned int getPixelSizeInBits()
const {
return computePixelSizeInBits(_pixelFormat,_dataType); }
287 inline unsigned int getRowSizeInBytes()
const {
return computeRowWidthInBytes(_s,_pixelFormat,_dataType,_packing); }
291 inline unsigned int getRowStepInBytes()
const {
return computeRowWidthInBytes(_rowLength==0?_s:_rowLength,_pixelFormat,_dataType,_packing); }
304 unsigned int getTotalSizeInBytesIncludingMipmaps()
const;
307 bool valid()
const {
return _s!=0 && _t!=0 && _r!=0 && _data!=0 && _dataType!=0; }
312 inline unsigned char*
data() {
return _data; }
317 inline const unsigned char*
data()
const {
return _data; }
319 inline unsigned char*
data(
unsigned int column,
unsigned int row = 0,
unsigned int image = 0)
321 if (!_data)
return NULL;
322 return _data+(column*getPixelSizeInBits())/8+row*getRowStepInBytes()+image*getImageSizeInBytes();
325 inline const unsigned char*
data(
unsigned int column,
unsigned int row = 0,
unsigned int image = 0)
const
327 if (!_data)
return NULL;
328 return _data+(column*getPixelSizeInBits())/8+row*getRowStepInBytes()+image*getImageSizeInBytes();
346 bool valid()
const {
return _currentPtr!=0; }
349 const unsigned char*
data()
const {
return _currentPtr; }
352 unsigned int size()
const {
return _currentSize; }
368 Vec4 getColor(
unsigned int s,
unsigned t=0,
unsigned r=0)
const;
374 Vec4 getColor(
const Vec3& texcoord)
const;
377 void setColor(
const osg::Vec4& color,
unsigned int s,
unsigned int t=0,
unsigned int r=0);
386 void flipHorizontal();
399 void ensureValidSizeForTexturing(GLint maxTextureSize);
401 static bool isPackedType(GLenum
type);
402 static GLenum computePixelFormat(GLenum pixelFormat);
403 static GLenum computeFormatDataType(GLenum pixelFormat);
404 static unsigned int computeBlockSize(GLenum pixelFormat, GLenum packing);
405 static unsigned int computeNumComponents(GLenum pixelFormat);
406 static unsigned int computePixelSizeInBits(GLenum pixelFormat,GLenum
type);
407 static unsigned int computeRowWidthInBytes(
int width,GLenum pixelFormat,GLenum
type,
int packing);
408 static unsigned int computeImageSizeInBytes(
int width,
int height,
int depth, GLenum pixelFormat, GLenum
type,
int packing = 1,
int slice_packing = 1,
int image_packing = 1);
409 static int computeNearestPowerOfTwo(
int s,
float bias=0.5f);
410 static int computeNumberOfMipmapLevels(
int s,
int t = 1,
int r = 1);
415 inline bool isMipmap()
const {
return !_mipmapData.empty();};
419 return static_cast<unsigned int>(_mipmapData.size())+1;
423 inline void setMipmapLevels(
const MipmapDataType& mipmapDataVector) { _mipmapData = mipmapDataVector; }
431 else if (mipmapLevel < getNumMipmapLevels())
432 return _mipmapData[mipmapLevel-1];
438 return _data+getMipmapOffset(mipmapLevel);
443 return _data+getMipmapOffset(mipmapLevel);
447 bool supportsTextureSubloading()
const;
450 virtual bool isImageTranslucent()
const;
491 virtual void operator()(
osg::Image* image) = 0;
507 for(DimensionsChangedCallbackVector::iterator i = _dimensionsChangedCallbacks.begin(); i != _dimensionsChangedCallbacks.end(); ++i)
509 (*i)->operator()(
this);
529 void deallocateData();
553 #endif // __SG_IMAGE_H
void setMipmapLevels(const MipmapDataType &mipmapDataVector)
virtual const char * libraryName() const
virtual bool isSameKindAs(const Object *obj) const
virtual bool sendPointerEvent(int, int, int)
void handleDimensionsChangedCallbacks()
GLint GLenum internalFormat
unsigned int getPixelSizeInBits() const
unsigned int getMipmapOffset(unsigned int mipmapLevel) const
virtual const GLvoid * getDataPointer() const
unsigned int getImageStepInBytes() const
virtual void setFrameLastRendered(const osg::FrameStamp *)
void setPixelBufferObject(PixelBufferObject *buffer)
GLint GLenum GLsizei GLsizei GLsizei depth
unsigned int getImageSizeInBytes() const
GLenum getPixelFormat() const
const unsigned char * data() const
const MipmapDataType & getMipmapLevels() const
unsigned int getPacking() const
const osg::Image * _image
void scaleImage(int s, int t, int r)
const unsigned char * getMipmapData(unsigned int mipmapLevel) const
void setWriteHint(WriteHint writeHint)
AllocationMode getAllocationMode() const
void swap(MixinVector< ValueT > &left, MixinVector< ValueT > &right)
unsigned int size() const
std::vector< unsigned int > MipmapDataType
virtual unsigned int getTotalDataSize() const
const unsigned char * data() const
virtual const char * className() const
Vec4 getColor(const Vec2 &texcoord) const
PixelBufferObject * getPixelBufferObject()
virtual void update(NodeVisitor *)
GLint GLenum GLsizei width
std::vector< osg::ref_ptr< DimensionsChangedCallback > > DimensionsChangedCallbackVector
void setColor(const osg::Vec4 &color, const osg::Vec2 &texcoord)
void setPixelAspectRatio(float pixelAspectRatio)
unsigned int getRowStepInBytes() const
virtual bool sendKeyEvent(int, bool)
unsigned int getTotalSizeInBytes() const
DimensionsChangedCallbackVector _dimensionsChangedCallbacks
void setAllocationMode(AllocationMode mode)
bool isDataContiguous() const
GLenum getDataType() const
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
const unsigned char * data(unsigned int column, unsigned int row=0, unsigned int image=0) const
GLint GLenum GLsizei GLsizei height
virtual bool requiresUpdateCall() const
GLint getInternalTextureFormat() const
void setOrigin(Origin origin)
unsigned int getNumMipmapLevels() const
unsigned char * getMipmapData(unsigned int mipmapLevel)
void setPacking(unsigned int packing)
virtual Object * clone(const CopyOp ©op) const
const std::string & getFileName() const
virtual bool sendFocusHint(bool)
virtual Object * cloneType() const
AllocationMode _allocationMode
const PixelBufferObject * getPixelBufferObject() const
GLint _internalTextureFormat
float getPixelAspectRatio() const
virtual osg::Image * asImage()
DimensionsChangedCallback()
unsigned char * data(unsigned int column, unsigned int row=0, unsigned int image=0)
MipmapDataType _mipmapData
WriteHint getWriteHint() const
const unsigned char * _currentPtr
unsigned int getRowSizeInBytes() const
OSG_EXPORT Geode * createGeodeForImage(Image *image)
virtual const osg::Image * asImage() const
unsigned int _currentSize