Created new helper functions for converting texture formats, loading images and…

Created new helper functions for converting texture formats, loading images and generating mipmaps." TRAC #22972 Signed-off-by: Jamie Madill Signed-off-by: Nicolas Capens Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2313 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 89200d93
//
// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// formatutils.h: Queries for GL image formats.
#ifndef LIBGLESV2_FORMATUTILS_H_
#define LIBGLESV2_FORMATUTILS_H_
#define GL_APICALL
#include <GLES3/gl3.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
typedef void (*MipGenerationFunction)(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned char *destData, int destRowPitch, int destDepthPitch);
typedef void (*LoadImageFunction)(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
namespace rx
{
class Renderer;
}
namespace gl
{
class Context;
bool IsValidInternalFormat(GLint internalFormat, const Context *context);
bool IsValidFormat(GLenum format, GLuint clientVersion);
bool IsValidType(GLenum type, GLuint clientVersion);
bool IsValidFormatCombination(GLint internalFormat, GLenum format, GLenum type, GLuint clientVersion);
bool IsValidCopyTexImageCombination(GLenum textureFormat, GLenum frameBufferFormat, GLuint clientVersion);
bool IsSizedInternalFormat(GLint internalFormat, GLuint clientVersion);
GLint GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion);
GLuint GetPixelBytes(GLint internalFormat, GLuint clientVersion);
GLuint GetAlphaBits(GLint internalFormat, GLuint clientVersion);
GLuint GetRedBits(GLint internalFormat, GLuint clientVersion);
GLuint GetGreenBits(GLint internalFormat, GLuint clientVersion);
GLuint GetBlueBits(GLint internalFormat, GLuint clientVersion);
GLuint GetLuminanceBits(GLint internalFormat, GLuint clientVersion);
GLuint GetDepthBits(GLint internalFormat, GLuint clientVersion);
GLuint GetStencilBits(GLint internalFormat, GLuint clientVersion);
GLenum GetFormat(GLint internalFormat, GLuint clientVersion);
GLenum GetType(GLint internalFormat, GLuint clientVersion);
bool IsColorRenderingSupported(GLint internalFormat, const rx::Renderer *renderer);
bool IsColorRenderingSupported(GLint internalFormat, const Context *context);
bool IsTextureFilteringSupported(GLint internalFormat, const rx::Renderer *renderer);
bool IsTextureFilteringSupported(GLint internalFormat, const Context *context);
bool IsDepthRenderingSupported(GLint internalFormat, const rx::Renderer *renderer);
bool IsDepthRenderingSupported(GLint internalFormat, const Context *context);
bool IsStencilRenderingSupported(GLint internalFormat, const rx::Renderer *renderer);
bool IsStencilRenderingSupported(GLint internalFormat, const Context *context);
GLuint GetRowPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment);
GLuint GetDepthPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment);
GLuint GetBlockSize(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height);
bool IsFormatCompressed(GLint internalFormat, GLuint clientVersion);
GLuint GetCompressedBlockWidth(GLint internalFormat, GLuint clientVersion);
GLuint GetCompressedBlockHeight(GLint internalFormat, GLuint clientVersion);
}
#endif LIBGLESV2_FORMATUTILS_H_
...@@ -244,6 +244,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -244,6 +244,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
</ClCompile> </ClCompile>
<ClCompile Include="Fence.cpp" /> <ClCompile Include="Fence.cpp" />
<ClCompile Include="Float16ToFloat32.cpp" /> <ClCompile Include="Float16ToFloat32.cpp" />
<ClCompile Include="formatutils.cpp" />
<ClCompile Include="Framebuffer.cpp" /> <ClCompile Include="Framebuffer.cpp" />
<ClCompile Include="HandleAllocator.cpp" /> <ClCompile Include="HandleAllocator.cpp" />
<ClCompile Include="libGLESv2.cpp" /> <ClCompile Include="libGLESv2.cpp" />
...@@ -265,6 +266,8 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -265,6 +266,8 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClCompile Include="renderer\BufferStorage.cpp" /> <ClCompile Include="renderer\BufferStorage.cpp" />
<ClCompile Include="renderer\BufferStorage11.cpp" /> <ClCompile Include="renderer\BufferStorage11.cpp" />
<ClCompile Include="renderer\BufferStorage9.cpp" /> <ClCompile Include="renderer\BufferStorage9.cpp" />
<ClCompile Include="renderer\formatutils11.cpp" />
<ClCompile Include="renderer\formatutils9.cpp" />
<ClCompile Include="renderer\Image.cpp" /> <ClCompile Include="renderer\Image.cpp" />
<ClCompile Include="renderer\Image9.cpp" /> <ClCompile Include="renderer\Image9.cpp" />
<ClCompile Include="renderer\IndexBuffer.cpp" /> <ClCompile Include="renderer\IndexBuffer.cpp" />
...@@ -274,6 +277,8 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -274,6 +277,8 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClCompile Include="renderer\ImageSSE2.cpp" /> <ClCompile Include="renderer\ImageSSE2.cpp" />
<ClCompile Include="renderer\Image11.cpp" /> <ClCompile Include="renderer\Image11.cpp" />
<ClCompile Include="renderer\InputLayoutCache.cpp" /> <ClCompile Include="renderer\InputLayoutCache.cpp" />
<ClCompile Include="renderer\loadimage.cpp" />
<ClCompile Include="renderer\loadimageSSE2.cpp" />
<ClCompile Include="renderer\Query11.cpp" /> <ClCompile Include="renderer\Query11.cpp" />
<ClCompile Include="renderer\Query9.cpp" /> <ClCompile Include="renderer\Query9.cpp" />
<ClCompile Include="renderer\Renderer.cpp" /> <ClCompile Include="renderer\Renderer.cpp" />
...@@ -318,6 +323,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -318,6 +323,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClInclude Include="constants.h" /> <ClInclude Include="constants.h" />
<ClInclude Include="Context.h" /> <ClInclude Include="Context.h" />
<ClInclude Include="Fence.h" /> <ClInclude Include="Fence.h" />
<ClInclude Include="formatutils.h" />
<ClInclude Include="Framebuffer.h" /> <ClInclude Include="Framebuffer.h" />
<ClInclude Include="HandleAllocator.h" /> <ClInclude Include="HandleAllocator.h" />
<ClInclude Include="main.h" /> <ClInclude Include="main.h" />
...@@ -335,6 +341,8 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -335,6 +341,8 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClInclude Include="renderer\BufferStorage.h" /> <ClInclude Include="renderer\BufferStorage.h" />
<ClInclude Include="renderer\BufferStorage11.h" /> <ClInclude Include="renderer\BufferStorage11.h" />
<ClInclude Include="renderer\BufferStorage9.h" /> <ClInclude Include="renderer\BufferStorage9.h" />
<ClInclude Include="renderer\formatutils11.h" />
<ClInclude Include="renderer\formatutils9.h" />
<ClInclude Include="renderer\generatemip.h" /> <ClInclude Include="renderer\generatemip.h" />
<ClInclude Include="renderer\Image.h" /> <ClInclude Include="renderer\Image.h" />
<ClInclude Include="renderer\Image11.h" /> <ClInclude Include="renderer\Image11.h" />
...@@ -344,6 +352,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -344,6 +352,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClInclude Include="renderer\IndexBuffer9.h" /> <ClInclude Include="renderer\IndexBuffer9.h" />
<ClInclude Include="renderer\IndexDataManager.h" /> <ClInclude Include="renderer\IndexDataManager.h" />
<ClInclude Include="renderer\InputLayoutCache.h" /> <ClInclude Include="renderer\InputLayoutCache.h" />
<ClInclude Include="renderer\loadimage.h" />
<ClInclude Include="renderer\Query11.h" /> <ClInclude Include="renderer\Query11.h" />
<ClInclude Include="renderer\QueryImpl.h" /> <ClInclude Include="renderer\QueryImpl.h" />
<ClInclude Include="renderer\Query9.h" /> <ClInclude Include="renderer\Query9.h" />
......
...@@ -218,6 +218,21 @@ ...@@ -218,6 +218,21 @@
<ClCompile Include="precompiled.cpp"> <ClCompile Include="precompiled.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="renderer\loadimage.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="renderer\loadimageSSE2.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="renderer\formatutils9.cpp">
<Filter>Source Files\Renderer9</Filter>
</ClCompile>
<ClCompile Include="renderer\formatutils11.cpp">
<Filter>Source Files\Renderer11</Filter>
</ClCompile>
<ClCompile Include="formatutils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="BinaryStream.h"> <ClInclude Include="BinaryStream.h">
...@@ -493,6 +508,18 @@ ...@@ -493,6 +508,18 @@
<ClInclude Include="renderer\shaders\compiled\clearsingle11ps.h"> <ClInclude Include="renderer\shaders\compiled\clearsingle11ps.h">
<Filter>Shaders\Compiled</Filter> <Filter>Shaders\Compiled</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="renderer\loadimage.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="renderer\formatutils11.h">
<Filter>Header Files\Renderer11</Filter>
</ClInclude>
<ClInclude Include="renderer\formatutils9.h">
<Filter>Header Files\Renderer9</Filter>
</ClInclude>
<ClInclude Include="formatutils.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="renderer\shaders\Blit.ps"> <None Include="renderer\shaders\Blit.ps">
......
//
// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// formatutils11.h: Queries for GL image formats and their translations to D3D11
// formats.
#ifndef LIBGLESV2_RENDERER_FORMATUTILS11_H_
#define LIBGLESV2_RENDERER_FORMATUTILS11_H_
#include "libGLESv2/formatutils.h"
namespace rx
{
namespace d3d11
{
MipGenerationFunction GetMipGenerationFunction(DXGI_FORMAT format);
LoadImageFunction GetImageLoadFunction(GLint internalFormat, GLenum type, GLuint clientVersion);
GLuint GetFormatPixelBytes(DXGI_FORMAT format);
GLuint GetBlockWidth(DXGI_FORMAT format);
GLuint GetBlockHeight(DXGI_FORMAT format);
void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset);
}
namespace gl_d3d11
{
DXGI_FORMAT GetTexFormat(GLint internalFormat, GLuint clientVersion);
DXGI_FORMAT GetSRVFormat(GLint internalFormat, GLuint clientVersion);
DXGI_FORMAT GetRTVFormat(GLint internalFormat, GLuint clientVersion);
DXGI_FORMAT GetDSVFormat(GLint internalFormat, GLuint clientVersion);
}
namespace d3d11_gl
{
GLint GetInternalFormat(DXGI_FORMAT format);
}
}
#endif // LIBGLESV2_RENDERER_FORMATUTILS11_H_
//
// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// formatutils9.h: Queries for GL image formats and their translations to D3D9
// formats.
#ifndef LIBGLESV2_RENDERER_FORMATUTILS9_H_
#define LIBGLESV2_RENDERER_FORMATUTILS9_H_
#include "libGLESv2/formatutils.h"
namespace rx
{
class Renderer9;
namespace d3d9
{
MipGenerationFunction GetMipGenerationFunction(D3DFORMAT format);
LoadImageFunction GetImageLoadFunction(GLint internalFormat, const Renderer9 *renderer);
GLuint GetFormatPixelBytes(D3DFORMAT format);
GLuint GetBlockWidth(D3DFORMAT format);
GLuint GetBlockHeight(D3DFORMAT format);
GLuint GetBlockSize(D3DFORMAT format, GLuint width, GLuint height);
void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset);
}
namespace gl_d3d9
{
D3DFORMAT GetTexureFormat(GLint internalFormat, const Renderer9 *renderer);
D3DFORMAT GetRenderFormat(GLint internalFormat, const Renderer9 *renderer);
D3DMULTISAMPLE_TYPE GetMultisampleType(GLsizei samples);
}
namespace d3d9_gl
{
GLint GetInternalFormat(D3DFORMAT format);
GLsizei GetSamplesCount(D3DMULTISAMPLE_TYPE type);
bool IsFormatChannelEquivalent(D3DFORMAT d3dformat, GLenum format, GLuint clientVersion);
}
}
#endif // LIBGLESV2_RENDERER_FORMATUTILS9_H_
...@@ -54,6 +54,7 @@ struct A8R8G8B8 ...@@ -54,6 +54,7 @@ struct A8R8G8B8
}; };
typedef A8R8G8B8 R8G8B8A8; // R8G8B8A8 type is functionally equivalent for mip purposes typedef A8R8G8B8 R8G8B8A8; // R8G8B8A8 type is functionally equivalent for mip purposes
typedef A8R8G8B8 B8G8R8A8; // B8G8R8A8 type is functionally equivalent for mip purposes
struct A16B16G16R16F struct A16B16G16R16F
{ {
...@@ -93,6 +94,8 @@ struct R16G16F ...@@ -93,6 +94,8 @@ struct R16G16F
} }
}; };
typedef A16B16G16R16F R16G16B16A16F;
struct A32B32G32R32F struct A32B32G32R32F
{ {
float R; float R;
...@@ -145,6 +148,11 @@ struct R32G32B32F ...@@ -145,6 +148,11 @@ struct R32G32B32F
} }
}; };
typedef A32B32G32R32F R32G32B32A32F;
namespace priv
{
template <typename T> template <typename T>
static inline T *GetPixel(void *data, unsigned int x, unsigned int y, unsigned int z, unsigned int rowPitch, unsigned int depthPitch) static inline T *GetPixel(void *data, unsigned int x, unsigned int y, unsigned int z, unsigned int rowPitch, unsigned int depthPitch)
{ {
...@@ -346,6 +354,7 @@ static void GenerateMip_XYZ(unsigned int sourceWidth, unsigned int sourceHeight, ...@@ -346,6 +354,7 @@ static void GenerateMip_XYZ(unsigned int sourceWidth, unsigned int sourceHeight,
} }
} }
typedef void (*MipGenerationFunction)(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth, typedef void (*MipGenerationFunction)(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch, const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned int destWidth, unsigned int destHeight, unsigned int destDepth, unsigned int destWidth, unsigned int destHeight, unsigned int destDepth,
...@@ -371,6 +380,8 @@ static MipGenerationFunction GetMipGenerationFunction(unsigned int sourceWidth, ...@@ -371,6 +380,8 @@ static MipGenerationFunction GetMipGenerationFunction(unsigned int sourceWidth,
} }
} }
}
template <typename T> template <typename T>
static void GenerateMip(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth, static void GenerateMip(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch, const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
...@@ -380,7 +391,7 @@ static void GenerateMip(unsigned int sourceWidth, unsigned int sourceHeight, uns ...@@ -380,7 +391,7 @@ static void GenerateMip(unsigned int sourceWidth, unsigned int sourceHeight, uns
unsigned int mipHeight = std::max(1U, sourceHeight >> 1); unsigned int mipHeight = std::max(1U, sourceHeight >> 1);
unsigned int mipDepth = std::max(1U, sourceDepth >> 1); unsigned int mipDepth = std::max(1U, sourceDepth >> 1);
MipGenerationFunction generationFunction = GetMipGenerationFunction<T>(sourceWidth, sourceHeight, sourceDepth); priv::MipGenerationFunction generationFunction = priv::GetMipGenerationFunction<T>(sourceWidth, sourceHeight, sourceDepth);
ASSERT(generationFunction != NULL); ASSERT(generationFunction != NULL);
generationFunction(sourceWidth, sourceHeight, sourceDepth, sourceData, sourceRowPitch, sourceDepthPitch, generationFunction(sourceWidth, sourceHeight, sourceDepth, sourceData, sourceRowPitch, sourceDepthPitch,
......
//
// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// loadimage.h: Defines image loading functions
#ifndef LIBGLESV2_RENDERER_LOADIMAGE_H_
#define LIBGLESV2_RENDERER_LOADIMAGE_H_
namespace rx
{
void loadAlphaDataToBGRA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadAlphaDataToNative(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadAlphaDataToBGRASSE2(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadAlphaFloatDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadAlphaHalfFloatDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadLuminanceDataToNative(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadLuminanceDataToBGRA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadLuminanceFloatDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadLuminanceFloatDataToRGB(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadLuminanceHalfFloatDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadLuminanceAlphaDataToNative(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadLuminanceAlphaDataToBGRA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadLuminanceAlphaFloatDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadLuminanceAlphaHalfFloatDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBUByteDataToBGRX(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBUByteDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGB565DataToBGRA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGB565DataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBFloatDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBFloatDataToNative(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBHalfFloatDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBAUByteDataToBGRASSE2(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBAUByteDataToBGRA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBAUByteDataToNative(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBA4444DataToBGRA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBA4444DataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBA5551DataToBGRA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBA5551DataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBAFloatDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadRGBAHalfFloatDataToRGBA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
void loadBGRADataToBGRA(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
template <unsigned int blockWidth, unsigned int blockHeight, unsigned int blockSize>
void loadCompressedBlockDataToNative(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
{
int columns = (width + (blockWidth - 1)) / blockWidth;
int rows = (height + (blockHeight - 1)) / blockHeight;
for (int z = 0; z < depth; ++z)
{
for (int y = 0; y < rows; ++y)
{
void *source = (void*)((char*)input + y * inputRowPitch + z * inputDepthPitch);
void *dest = (void*)((char*)output + y * outputRowPitch + z * outputDepthPitch);
memcpy(dest, source, columns * blockSize);
}
}
}
}
#endif // LIBGLESV2_RENDERER_LOADIMAGE_H_
#include "precompiled.h"
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// loadimage.cpp: Defines image loading functions. It's
// in a separated file for GCC, which can enable SSE usage only per-file,
// not for code blocks that use SSE2 explicitly.
#include "libGLESv2/renderer/loadimage.h"
namespace rx
{
void loadAlphaDataToBGRASSE2(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
{
const unsigned char *source = NULL;
unsigned int *dest = NULL;
__m128i zeroWide = _mm_setzero_si128();
for (int z = 0; z < depth; z++)
{
for (int y = 0; y < height; y++)
{
source = static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch;
dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
int x;
// Make output writes aligned
for (x = 0; ((reinterpret_cast<intptr_t>(&dest[x]) & 0xF) != 0 && x < width); x++)
{
dest[x] = static_cast<unsigned int>(source[x]) << 24;
}
for (; x + 7 < width; x += 8)
{
__m128i sourceData = _mm_loadl_epi64(reinterpret_cast<const __m128i*>(&source[x]));
// Interleave each byte to 16bit, make the lower byte to zero
sourceData = _mm_unpacklo_epi8(zeroWide, sourceData);
// Interleave each 16bit to 32bit, make the lower 16bit to zero
__m128i lo = _mm_unpacklo_epi16(zeroWide, sourceData);
__m128i hi = _mm_unpackhi_epi16(zeroWide, sourceData);
_mm_store_si128(reinterpret_cast<__m128i*>(&dest[x]), lo);
_mm_store_si128(reinterpret_cast<__m128i*>(&dest[x + 4]), hi);
}
// Handle the remainder
for (; x < width; x++)
{
dest[x] = static_cast<unsigned int>(source[x]) << 24;
}
}
}
}
void loadRGBAUByteDataToBGRASSE2(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
{
const unsigned int *source = NULL;
unsigned int *dest = NULL;
__m128i brMask = _mm_set1_epi32(0x00ff00ff);
for (int z = 0; z < depth; z++)
{
for (int y = 0; y < height; y++)
{
source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
int x = 0;
// Make output writes aligned
for (x = 0; ((reinterpret_cast<intptr_t>(&dest[x]) & 15) != 0) && x < width; x++)
{
unsigned int rgba = source[x];
dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
}
for (; x + 3 < width; x += 4)
{
__m128i sourceData = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&source[x]));
// Mask out g and a, which don't change
__m128i gaComponents = _mm_andnot_si128(brMask, sourceData);
// Mask out b and r
__m128i brComponents = _mm_and_si128(sourceData, brMask);
// Swap b and r
__m128i brSwapped = _mm_shufflehi_epi16(_mm_shufflelo_epi16(brComponents, _MM_SHUFFLE(2, 3, 0, 1)), _MM_SHUFFLE(2, 3, 0, 1));
__m128i result = _mm_or_si128(gaComponents, brSwapped);
_mm_store_si128(reinterpret_cast<__m128i*>(&dest[x]), result);
}
// Perform leftover writes
for (; x < width; x++)
{
unsigned int rgba = source[x];
dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment