Added cTexture::Update helper.

Small fix on cAudioDevice::GetFormatFromChannelCount.
This commit is contained in:
Martín Lucas Golini
2013-08-15 15:36:26 -03:00
parent c9ab704016
commit 322fbdbe52
5 changed files with 53 additions and 8 deletions

View File

@@ -81,7 +81,6 @@ class EE_API cSoundStream : private cThread, private cSound {
*/
void Loop( const bool& Loop);
/** Tell whether or not the stream is looping
* @return True if the music is looping, false otherwise
*/

View File

@@ -82,6 +82,21 @@ class EE_API cTexture : public cImage {
/** Copy an image inside the texture */
void CopyImage( cImage * Img, const eeUint& x, const eeUint& y );
/** @brief Update a part of the texture from an array of pixels
** The size of the @a pixel array must match the @a width and
** @a height arguments.
** No additional check is performed on the size of the pixel
** array or the bounds of the area to update, passing invalid
** arguments will lead to an undefined behaviour.
** This function does nothing if @a pixels is null or if the
** texture was not previously created.
** @param pixels Array of pixels to copy to the texture
** @param width Width of the pixel region contained in @a pixels
** @param height Height of the pixel region contained in @a pixels
** @param x X offset in the texture where to copy the source pixels
** @param y Y offset in the texture where to copy the source pixels */
void Update( const Uint8* pixels, Uint32 width, Uint32 height, Uint32 x = 0, Uint32 y = 0, EE_PIXEL_FORMAT pf = PF_RGBA );
/** Flip the texture ( rotate the texture 90º ). Warning: This is flipped in memory, a real flipping. */
void Flip();

View File

@@ -154,6 +154,16 @@ enum EE_TEXTURE_SOURCE {
TEX_SRC_PREVIOUS
};
/** @enum EE_PIXEL_FORMAT Pixel formats to write into a texture image. */
enum EE_PIXEL_FORMAT {
PF_RED = 0x1903,
PF_RG = 0x8227,
PF_RGB = 0x1907,
PF_BGR = 0x80E0,
PF_RGBA = 0x1908,
PF_BGRA = 0x80E1
};
}}
#endif

View File

@@ -81,16 +81,22 @@ bool cAudioDevice::IsExtensionSupported( const std::string& extension ) {
int cAudioDevice::GetFormatFromChannelCount( unsigned int ChannelCount ) {
EnsureALInit();
int format = 0;
switch ( ChannelCount ) {
case 1 : return AL_FORMAT_MONO16;
case 2 : return AL_FORMAT_STEREO16;
case 4 : return alGetEnumValue("AL_FORMAT_QUAD16");
case 6 : return alGetEnumValue("AL_FORMAT_51CHN16");
case 7 : return alGetEnumValue("AL_FORMAT_61CHN16");
case 8 : return alGetEnumValue("AL_FORMAT_71CHN16");
case 1 : format = AL_FORMAT_MONO16; break;
case 2 : format = AL_FORMAT_STEREO16; break;
case 4 : format = alGetEnumValue("AL_FORMAT_QUAD16"); break;
case 6 : format = alGetEnumValue("AL_FORMAT_51CHN16"); break;
case 7 : format = alGetEnumValue("AL_FORMAT_61CHN16"); break;
case 8 : format = alGetEnumValue("AL_FORMAT_71CHN16"); break;
default: format = 0;
}
return 0;
if ( -1 == format )
format = 0;
return format;
}
bool cAudioDevice::IsAvailable() {

View File

@@ -382,6 +382,21 @@ void cTexture::Reload() {
}
}
void cTexture::Update( const Uint8* pixels, Uint32 width, Uint32 height, Uint32 x, Uint32 y, EE_PIXEL_FORMAT pf ) {
if ( NULL != pixels && mTexture && x + width <= mWidth && y + height <= mHeight ) {
GLint PreviousTexture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture);
if ( mTexture != PreviousTexture )
glBindTexture( GL_TEXTURE_2D, mTexture );
glTexSubImage2D( GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels );
if ( mTexture != PreviousTexture )
glBindTexture(GL_TEXTURE_2D, PreviousTexture);
}
}
const Uint32& cTexture::HashName() const {
return mId;
}