Cocoa Port:

- If a video filter is used, upload textures in BGRA8888 instead of RGBA8888 format.
- Do some cleanup of the OpenGL display code.
This commit is contained in:
rogerman 2014-03-05 04:26:08 +00:00
parent 48f20e49f7
commit 4d50b396dd
4 changed files with 81 additions and 18 deletions

View File

@ -79,10 +79,9 @@ OGLVideoOutput::OGLVideoOutput()
_rotation = 0.0f;
_displayTexFilter = GL_NEAREST;
_glTexPixelFormat = GL_UNSIGNED_SHORT_1_5_5_5_REV;
_glTexBackWidth = GetNearestPositivePOT((uint32_t)_normalWidth);
_glTexBackHeight = GetNearestPositivePOT((uint32_t)_normalHeight);
_glTexBack = (GLvoid *)calloc(_glTexBackWidth * _glTexBackHeight, sizeof(uint16_t));
_glTexBack = (GLvoid *)calloc(_glTexBackWidth * _glTexBackHeight, sizeof(uint32_t));
_vfSingle = new VideoFilter(GPU_DISPLAY_WIDTH, GPU_DISPLAY_HEIGHT, VideoFilterTypeID_None, 0);
_vfDual = new VideoFilter(GPU_DISPLAY_WIDTH, GPU_DISPLAY_HEIGHT*2, VideoFilterTypeID_None, 2);
@ -370,20 +369,17 @@ void OGLVideoOutput::SetVideoFilterOGL(const VideoFilterTypeID videoFilterTypeID
const GLsizei vfDstWidth = this->_vf->GetDstWidth();
const GLsizei vfDstHeight = (this->_displayMode == DS_DISPLAY_TYPE_DUAL) ? this->_vf->GetDstHeight() : this->_vf->GetDstHeight() * 2;
const GLenum newPixFormat = (videoFilterTypeID == VideoFilterTypeID_None) ? GL_UNSIGNED_SHORT_1_5_5_5_REV : GL_UNSIGNED_INT_8_8_8_8_REV;
// Convert textures to Power-of-Two to support older GPUs
// Example: Radeon X1600M on the 2006 MacBook Pro
const GLsizei potW = GetNearestPositivePOT((uint32_t)vfDstWidth);
const GLsizei potH = GetNearestPositivePOT((uint32_t)vfDstHeight);
const size_t colorDepth = (newPixFormat == GL_UNSIGNED_SHORT_1_5_5_5_REV) ? sizeof(uint16_t) : sizeof(uint32_t);
const size_t texBackSize = potW * potH * colorDepth;
const size_t texBackSize = potW * potH * sizeof(uint32_t);
if (this->_glTexBackWidth != potW || this->_glTexBackHeight != potH || this->_glTexPixelFormat != newPixFormat)
if (this->_glTexBackWidth != potW || this->_glTexBackHeight != potH)
{
this->_glTexBackWidth = potW;
this->_glTexBackHeight = potH;
this->_glTexPixelFormat = newPixFormat;
this->_glTexBack = (GLvoid *)realloc(this->_glTexBack, texBackSize);
if (this->_glTexBack == NULL)
@ -399,7 +395,7 @@ void OGLVideoOutput::SetVideoFilterOGL(const VideoFilterTypeID videoFilterTypeID
this->UpdateTexCoords(s, t);
glBindTexture(GL_TEXTURE_2D, this->_displayTexID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)potW, (GLsizei)potH, 0, GL_BGRA, this->_glTexPixelFormat, this->_glTexBack);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)potW, (GLsizei)potH, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, this->_glTexBack);
glBindTexture(GL_TEXTURE_2D, 0);
this->UploadTexCoordsOGL();
}
@ -554,7 +550,7 @@ void OGLVideoOutput::UploadTexCoordsOGL()
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}
void OGLVideoOutput::UploadDisplayTextureOGL(const GLvoid *textureData, GLsizei texWidth, GLsizei texHeight)
void OGLVideoOutput::UploadDisplayTextureOGL(const GLvoid *textureData, const GLenum texPixelFormat, const GLenum texPixelType, GLsizei texWidth, GLsizei texHeight)
{
if (textureData == NULL)
{
@ -564,7 +560,7 @@ void OGLVideoOutput::UploadDisplayTextureOGL(const GLvoid *textureData, GLsizei
const GLint lineOffset = (this->_displayMode == DS_DISPLAY_TYPE_TOUCH) ? texHeight : 0;
glBindTexture(GL_TEXTURE_2D, this->_displayTexID);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, lineOffset, texWidth, texHeight, GL_RGBA, this->_glTexPixelFormat, textureData);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, lineOffset, texWidth, texHeight, texPixelFormat, texPixelType, textureData);
glBindTexture(GL_TEXTURE_2D, 0);
}
@ -633,17 +629,30 @@ void OGLVideoOutput::UpdateTexCoords(GLfloat s, GLfloat t)
void OGLVideoOutput::PrerenderOGL(const GLvoid *textureData, GLsizei texWidth, GLsizei texHeight)
{
GLenum texPixelFormat = GL_RGBA;
GLenum texPixelType = GL_UNSIGNED_SHORT_1_5_5_5_REV;
uint32_t *vfTextureData = (uint32_t *)textureData;
if (this->_vf->GetTypeID() != VideoFilterTypeID_None)
VideoFilter *currentFilter = this->_vf;
if (currentFilter->GetTypeID() != VideoFilterTypeID_None)
{
RGB555ToRGBA8888Buffer((const uint16_t *)textureData, (uint32_t *)this->_vf->GetSrcBufferPtr(), texWidth * texHeight);
texWidth = this->_vf->GetDstWidth();
texHeight = this->_vf->GetDstHeight();
vfTextureData = this->_vf->RunFilter();
if (texPixelType == GL_UNSIGNED_SHORT_1_5_5_5_REV)
{
RGB555ToBGRA8888Buffer((const uint16_t *)vfTextureData, (uint32_t *)currentFilter->GetSrcBufferPtr(), texWidth * texHeight);
texPixelFormat = GL_BGRA;
texPixelType = GL_UNSIGNED_INT_8_8_8_8_REV;
}
else
{
memcpy(currentFilter->GetSrcBufferPtr(), vfTextureData, texWidth * texHeight * sizeof(uint32_t));
}
this->UploadDisplayTextureOGL(vfTextureData, texWidth, texHeight);
vfTextureData = currentFilter->RunFilter();
texWidth = currentFilter->GetDstWidth();
texHeight = currentFilter->GetDstHeight();
}
this->UploadDisplayTextureOGL(vfTextureData, texPixelFormat, texPixelType, texWidth, texHeight);
}
void OGLVideoOutput::RenderOGL()

View File

@ -34,6 +34,7 @@ protected:
VideoFilter *_vfSingle;
VideoFilter *_vfDual;
VideoFilter *_vf;
bool _isShaderSupported;
double _normalWidth;
double _normalHeight;
@ -47,7 +48,6 @@ protected:
GLfloat _gapScalar;
GLfloat _rotation;
GLenum _glTexPixelFormat;
GLvoid *_glTexBack;
GLsizei _glTexBackWidth;
GLsizei _glTexBackHeight;
@ -88,7 +88,7 @@ public:
virtual void UploadVerticesOGL();
virtual void UploadTexCoordsOGL();
virtual void UploadDisplayTextureOGL(const GLvoid *textureData, GLsizei texWidth, GLsizei texHeight);
virtual void UploadDisplayTextureOGL(const GLvoid *textureData, const GLenum texPixelFormat, const GLenum texPixelType, GLsizei texWidth, GLsizei texHeight);
virtual void PrerenderOGL(const GLvoid *textureData, GLsizei texWidth, GLsizei texHeight);
virtual void RenderOGL();

View File

@ -148,6 +148,28 @@ inline uint32_t RGB555ToRGBA8888(const uint16_t color16)
0xFF000000;
}
/********************************************************************************************
RGB555ToBGRA8888() - INLINE
Converts a color from 15-bit RGB555 format into 32-bit BGRA8888 format.
Takes:
color16 - The pixel in 15-bit RGB555 format.
Returns:
A 32-bit unsigned integer containing the BGRA8888 formatted color.
Details:
The input and output pixels are expected to have little-endian byte order.
********************************************************************************************/
inline uint32_t RGB555ToBGRA8888(const uint16_t color16)
{
return (bits5to8[((color16 >> 10) & 0x001F)] << 0) |
(bits5to8[((color16 >> 5) & 0x001F)] << 8) |
(bits5to8[((color16 >> 0) & 0x001F)] << 16) |
0xFF000000;
}
/********************************************************************************************
RGBA8888ForceOpaque() - INLINE
@ -197,6 +219,36 @@ void RGB555ToRGBA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t *__
}
}
/********************************************************************************************
RGB555ToBGRA8888Buffer()
Copies a 15-bit RGB555 pixel buffer into a 32-bit BGRA8888 pixel buffer.
Takes:
srcBuffer - Pointer to the source 15-bit RGB555 pixel buffer.
destBuffer - Pointer to the destination 32-bit BGRA8888 pixel buffer.
pixelCount - The number of pixels to copy.
Returns:
Nothing.
Details:
The source and destination pixels are expected to have little-endian byte order.
Also, it is the caller's responsibility to ensure that the source and destination
buffers are large enough to accomodate the requested number of pixels.
********************************************************************************************/
void RGB555ToBGRA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, size_t pixelCount)
{
const uint32_t *__restrict__ destBufferEnd = destBuffer + pixelCount;
while (destBuffer < destBufferEnd)
{
*destBuffer++ = RGB555ToBGRA8888(*srcBuffer++);
}
}
/********************************************************************************************
RGBA8888ForceOpaqueBuffer()

View File

@ -30,8 +30,10 @@ extern "C"
bool IsOSXVersionSupported(const unsigned int major, const unsigned int minor, const unsigned int revision);
uint32_t RGB555ToRGBA8888(const uint16_t color16);
uint32_t RGB555ToBGRA8888(const uint16_t color16);
uint32_t RGBA8888ForceOpaque(const uint32_t color32);
void RGB555ToRGBA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, size_t pixelCount);
void RGB555ToBGRA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, size_t pixelCount);
void RGBA8888ForceOpaqueBuffer(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, size_t pixelCount);
CGSize GetTransformedBounds(const double normalBoundsWidth, const double normalBoundsHeight,