Commit fe28ca06 by Geoff Lang Committed by Shannon Woods

Added table entries for reading colors from D3D and DXGI formats and writing…

Added table entries for reading colors from D3D and DXGI formats and writing colors to format/type combinations. TRAC #23256 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Geoff Lang
parent 446a4477
...@@ -271,6 +271,8 @@ ...@@ -271,6 +271,8 @@
'libGLESv2/Renderbuffer.h', 'libGLESv2/Renderbuffer.h',
'libGLESv2/renderer/Blit.cpp', 'libGLESv2/renderer/Blit.cpp',
'libGLESv2/renderer/Blit.h', 'libGLESv2/renderer/Blit.h',
'libGLESv2/renderer/copyimage.cpp',
'libGLESv2/renderer/copyimage.h',
'libGLESv2/renderer/BufferStorage.h', 'libGLESv2/renderer/BufferStorage.h',
'libGLESv2/renderer/BufferStorage.cpp', 'libGLESv2/renderer/BufferStorage.cpp',
'libGLESv2/renderer/BufferStorage9.cpp', 'libGLESv2/renderer/BufferStorage9.cpp',
......
...@@ -39,6 +39,13 @@ Config::Config(rx::ConfigDesc desc, EGLint minInterval, EGLint maxInterval, EGLi ...@@ -39,6 +39,13 @@ Config::Config(rx::ConfigDesc desc, EGLint minInterval, EGLint maxInterval, EGLi
mBlueSize = 5; mBlueSize = 5;
mAlphaSize = 1; mAlphaSize = 1;
break; break;
case GL_BGR5_A1_ANGLEX:
mBufferSize = 16;
mRedSize = 5;
mGreenSize = 5;
mBlueSize = 5;
mAlphaSize = 1;
break;
case GL_RGBA8_OES: case GL_RGBA8_OES:
mBufferSize = 32; mBufferSize = 32;
mRedSize = 8; mRedSize = 8;
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
#include "libGLESv2/angletypes.h"
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 char *destData, int destRowPitch, int destDepthPitch); unsigned char *destData, int destRowPitch, int destDepthPitch);
...@@ -22,6 +24,10 @@ typedef void (*LoadImageFunction)(int width, int height, int depth, ...@@ -22,6 +24,10 @@ typedef void (*LoadImageFunction)(int width, int height, int depth,
const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch); void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch);
typedef void (*ColorReadFunction)(const void *source, void *dest);
typedef void (*ColorWriteFunction)(const void *source, void *dest);
typedef void (*ColorCopyFunction)(const void *source, void *dest);
namespace rx namespace rx
{ {
...@@ -81,6 +87,8 @@ bool IsFormatCompressed(GLint internalFormat, GLuint clientVersion); ...@@ -81,6 +87,8 @@ bool IsFormatCompressed(GLint internalFormat, GLuint clientVersion);
GLuint GetCompressedBlockWidth(GLint internalFormat, GLuint clientVersion); GLuint GetCompressedBlockWidth(GLint internalFormat, GLuint clientVersion);
GLuint GetCompressedBlockHeight(GLint internalFormat, GLuint clientVersion); GLuint GetCompressedBlockHeight(GLint internalFormat, GLuint clientVersion);
ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type, GLuint clientVersion);
} }
#endif LIBGLESV2_FORMATUTILS_H_ #endif LIBGLESV2_FORMATUTILS_H_
...@@ -268,6 +268,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -268,6 +268,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClCompile Include="..\common\RefCountObject.cpp" /> <ClCompile Include="..\common\RefCountObject.cpp" />
<ClCompile Include="Renderbuffer.cpp" /> <ClCompile Include="Renderbuffer.cpp" />
<ClCompile Include="renderer\Blit.cpp" /> <ClCompile Include="renderer\Blit.cpp" />
<ClCompile Include="renderer\copyimage.cpp" />
<ClCompile Include="renderer\Fence11.cpp" /> <ClCompile Include="renderer\Fence11.cpp" />
<ClCompile Include="renderer\Fence9.cpp" /> <ClCompile Include="renderer\Fence9.cpp" />
<ClCompile Include="renderer\BufferStorage.cpp" /> <ClCompile Include="renderer\BufferStorage.cpp" />
...@@ -342,6 +343,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -342,6 +343,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClInclude Include="..\common\RefCountObject.h" /> <ClInclude Include="..\common\RefCountObject.h" />
<ClInclude Include="Renderbuffer.h" /> <ClInclude Include="Renderbuffer.h" />
<ClInclude Include="renderer\Blit.h" /> <ClInclude Include="renderer\Blit.h" />
<ClInclude Include="renderer\copyimage.h" />
<ClInclude Include="renderer\Fence11.h" /> <ClInclude Include="renderer\Fence11.h" />
<ClInclude Include="renderer\Fence9.h" /> <ClInclude Include="renderer\Fence9.h" />
<ClInclude Include="renderer\FenceImpl.h" /> <ClInclude Include="renderer\FenceImpl.h" />
......
...@@ -233,6 +233,9 @@ ...@@ -233,6 +233,9 @@
<ClCompile Include="..\common\mathutil.cpp"> <ClCompile Include="..\common\mathutil.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="renderer\copyimage.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="BinaryStream.h"> <ClInclude Include="BinaryStream.h">
...@@ -544,6 +547,9 @@ ...@@ -544,6 +547,9 @@
<ClInclude Include="renderer\imageformats.h"> <ClInclude Include="renderer\imageformats.h">
<Filter>Header Files\Renderer</Filter> <Filter>Header Files\Renderer</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="renderer\copyimage.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="renderer\shaders\Blit.ps"> <None Include="renderer\shaders\Blit.ps">
......
#include "precompiled.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.
//
// copyimage.cpp: Defines image copying functions
#include "libGLESv2/renderer/copyImage.h"
namespace rx
{
void CopyBGRAUByteToRGBAUByte(const void *source, void *dest)
{
unsigned int argb = *(unsigned int*)source;
*(unsigned int*)dest = (argb & 0xFF00FF00) | // Keep alpha and green
(argb & 0x00FF0000) >> 16 | // Move red to blue
(argb & 0x000000FF) << 16; // Move blue to red
}
}
//
// 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.
//
// copyimage.h: Defines image copying functions
#ifndef LIBGLESV2_RENDERER_COPYIMAGE_H_
#define LIBGLESV2_RENDERER_COPYIMAGE_H_
#include "common/mathutil.h"
#include "libGLESv2/angletypes.h"
namespace rx
{
template <typename sourceType, typename colorDataType>
void ReadColor(const void *source, void *dest)
{
sourceType::readColor(reinterpret_cast<gl::Color<colorDataType>*>(dest), reinterpret_cast<const sourceType*>(source));
}
template <typename destType, typename colorDataType>
void WriteColor(const void *source, void *dest)
{
destType::writeColor(reinterpret_cast<destType*>(dest), reinterpret_cast<const gl::Color<colorDataType>*>(source));
}
template <typename sourceType, typename destType, typename colorDataType>
void CopyPixel(const void *source, void *dest)
{
colorType temp;
ReadColor<sourceType, colorDataType>(source, &temp);
WriteColor<destType, colorDataType>(&temp, dest);
}
void CopyBGRAUByteToRGBAUByte(const void *source, void *dest);
}
#endif // LIBGLESV2_RENDERER_COPYIMAGE_H_
...@@ -31,6 +31,9 @@ void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsi ...@@ -31,6 +31,9 @@ void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsi
const DXGIFormatSet &GetAllUsedDXGIFormats(); const DXGIFormatSet &GetAllUsedDXGIFormats();
ColorReadFunction GetColorReadFunction(DXGI_FORMAT format);
ColorCopyFunction GetFastCopyFunction(DXGI_FORMAT sourceFormat, GLenum destFormat, GLenum destType, GLuint clientVersion);
} }
namespace gl_d3d11 namespace gl_d3d11
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "libGLESv2/renderer/Renderer9.h" #include "libGLESv2/renderer/Renderer9.h"
#include "libGLESv2/renderer/generatemip.h" #include "libGLESv2/renderer/generatemip.h"
#include "libGLESv2/renderer/loadimage.h" #include "libGLESv2/renderer/loadimage.h"
#include "libGLESv2/renderer/copyimage.h"
namespace rx namespace rx
{ {
...@@ -161,15 +162,17 @@ struct D3DFormatInfo ...@@ -161,15 +162,17 @@ struct D3DFormatInfo
GLint mInternalFormat; GLint mInternalFormat;
MipGenerationFunction mMipGenerationFunction; MipGenerationFunction mMipGenerationFunction;
ColorReadFunction mColorReadFunction;
D3DFormatInfo() D3DFormatInfo()
: mPixelBits(0), mBlockWidth(0), mBlockHeight(0), mInternalFormat(GL_NONE), mMipGenerationFunction(NULL) : mPixelBits(0), mBlockWidth(0), mBlockHeight(0), mInternalFormat(GL_NONE), mMipGenerationFunction(NULL),
mColorReadFunction(NULL)
{ } { }
D3DFormatInfo(GLuint pixelBits, GLuint blockWidth, GLuint blockHeight, GLint internalFormat, D3DFormatInfo(GLuint pixelBits, GLuint blockWidth, GLuint blockHeight, GLint internalFormat,
MipGenerationFunction mipFunc) MipGenerationFunction mipFunc, ColorReadFunction readFunc)
: mPixelBits(pixelBits), mBlockWidth(blockWidth), mBlockHeight(blockHeight), mInternalFormat(internalFormat), : mPixelBits(pixelBits), mBlockWidth(blockWidth), mBlockHeight(blockHeight), mInternalFormat(internalFormat),
mMipGenerationFunction(mipFunc) mMipGenerationFunction(mipFunc), mColorReadFunction(readFunc)
{ } { }
}; };
...@@ -180,31 +183,31 @@ static D3D9FormatInfoMap BuildD3D9FormatInfoMap() ...@@ -180,31 +183,31 @@ static D3D9FormatInfoMap BuildD3D9FormatInfoMap()
{ {
D3D9FormatInfoMap map; D3D9FormatInfoMap map;
// | D3DFORMAT | | S |W |H | Internal format | Mip generation function | // | D3DFORMAT | | S |W |H | Internal format | Mip generation function | Color read function |
map.insert(D3D9FormatInfoPair(D3DFMT_NULL, D3DFormatInfo( 0, 0, 0, GL_NONE, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_NULL, D3DFormatInfo( 0, 0, 0, GL_NONE, NULL, NULL )));
map.insert(D3D9FormatInfoPair(D3DFMT_UNKNOWN, D3DFormatInfo( 0, 0, 0, GL_NONE, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_UNKNOWN, D3DFormatInfo( 0, 0, 0, GL_NONE, NULL, NULL )));
map.insert(D3D9FormatInfoPair(D3DFMT_L8, D3DFormatInfo( 8, 1, 1, GL_LUMINANCE8_EXT, GenerateMip<L8> ))); map.insert(D3D9FormatInfoPair(D3DFMT_L8, D3DFormatInfo( 8, 1, 1, GL_LUMINANCE8_EXT, GenerateMip<L8>, ReadColor<L8, GLfloat> )));
map.insert(D3D9FormatInfoPair(D3DFMT_A8, D3DFormatInfo( 8, 1, 1, GL_ALPHA8_EXT, GenerateMip<A8> ))); map.insert(D3D9FormatInfoPair(D3DFMT_A8, D3DFormatInfo( 8, 1, 1, GL_ALPHA8_EXT, GenerateMip<A8>, ReadColor<A8, GLfloat> )));
map.insert(D3D9FormatInfoPair(D3DFMT_A8L8, D3DFormatInfo( 16, 1, 1, GL_LUMINANCE8_ALPHA8_EXT, GenerateMip<A8L8> ))); map.insert(D3D9FormatInfoPair(D3DFMT_A8L8, D3DFormatInfo( 16, 1, 1, GL_LUMINANCE8_ALPHA8_EXT, GenerateMip<A8L8>, ReadColor<A8L8, GLfloat> )));
map.insert(D3D9FormatInfoPair(D3DFMT_A4R4G4B4, D3DFormatInfo( 16, 1, 1, GL_RGBA4, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_A4R4G4B4, D3DFormatInfo( 16, 1, 1, GL_BGRA4_ANGLEX, GenerateMip<B4G4R4A4>, ReadColor<B4G4R4A4, GLfloat> )));
map.insert(D3D9FormatInfoPair(D3DFMT_A1R5G5B5, D3DFormatInfo( 16, 1, 1, GL_RGB5_A1, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_A1R5G5B5, D3DFormatInfo( 16, 1, 1, GL_BGR5_A1_ANGLEX, GenerateMip<B5G5R5A1>, ReadColor<B5G5R5A1, GLfloat> )));
map.insert(D3D9FormatInfoPair(D3DFMT_R5G6B5, D3DFormatInfo( 16, 1, 1, GL_RGB565, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_R5G6B5, D3DFormatInfo( 16, 1, 1, GL_RGB565, GenerateMip<R5G6B5>, ReadColor<R5G6B5, GLfloat> )));
map.insert(D3D9FormatInfoPair(D3DFMT_X8R8G8B8, D3DFormatInfo( 32, 1, 1, GL_RGB8_OES, GenerateMip<A8R8G8B8> ))); map.insert(D3D9FormatInfoPair(D3DFMT_X8R8G8B8, D3DFormatInfo( 32, 1, 1, GL_BGRA8_EXT, GenerateMip<A8R8G8B8>, ReadColor<A8R8G8B8, GLfloat> )));
map.insert(D3D9FormatInfoPair(D3DFMT_A8R8G8B8, D3DFormatInfo( 32, 1, 1, GL_RGBA8_OES, GenerateMip<A8R8G8B8> ))); map.insert(D3D9FormatInfoPair(D3DFMT_A8R8G8B8, D3DFormatInfo( 32, 1, 1, GL_BGRA8_EXT, GenerateMip<A8R8G8B8>, ReadColor<A8R8G8B8, GLfloat> )));
map.insert(D3D9FormatInfoPair(D3DFMT_A16B16G16R16F, D3DFormatInfo( 64, 1, 1, GL_RGBA16F_EXT, GenerateMip<A16B16G16R16F>))); map.insert(D3D9FormatInfoPair(D3DFMT_A16B16G16R16F, D3DFormatInfo( 64, 1, 1, GL_RGBA16F_EXT, GenerateMip<A16B16G16R16F>, ReadColor<A16B16G16R16F, GLfloat>)));
map.insert(D3D9FormatInfoPair(D3DFMT_A32B32G32R32F, D3DFormatInfo(128, 1, 1, GL_RGBA32F_EXT, GenerateMip<A32B32G32R32F>))); map.insert(D3D9FormatInfoPair(D3DFMT_A32B32G32R32F, D3DFormatInfo(128, 1, 1, GL_RGBA32F_EXT, GenerateMip<A32B32G32R32F>, ReadColor<A32B32G32R32F, GLfloat>)));
map.insert(D3D9FormatInfoPair(D3DFMT_D16, D3DFormatInfo( 16, 1, 1, GL_DEPTH_COMPONENT16, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_D16, D3DFormatInfo( 16, 1, 1, GL_DEPTH_COMPONENT16, NULL, NULL )));
map.insert(D3D9FormatInfoPair(D3DFMT_D24S8, D3DFormatInfo( 32, 1, 1, GL_DEPTH24_STENCIL8_OES, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_D24S8, D3DFormatInfo( 32, 1, 1, GL_DEPTH24_STENCIL8_OES, NULL, NULL )));
map.insert(D3D9FormatInfoPair(D3DFMT_D24X8, D3DFormatInfo( 32, 1, 1, GL_DEPTH_COMPONENT16, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_D24X8, D3DFormatInfo( 32, 1, 1, GL_DEPTH_COMPONENT16, NULL, NULL )));
map.insert(D3D9FormatInfoPair(D3DFMT_D32, D3DFormatInfo( 32, 1, 1, GL_DEPTH_COMPONENT32_OES, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_D32, D3DFormatInfo( 32, 1, 1, GL_DEPTH_COMPONENT32_OES, NULL, NULL )));
map.insert(D3D9FormatInfoPair(D3DFMT_INTZ, D3DFormatInfo( 32, 1, 1, GL_DEPTH24_STENCIL8_OES, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_INTZ, D3DFormatInfo( 32, 1, 1, GL_DEPTH24_STENCIL8_OES, NULL, NULL )));
map.insert(D3D9FormatInfoPair(D3DFMT_DXT1, D3DFormatInfo( 64, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_DXT1, D3DFormatInfo( 64, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL, NULL )));
map.insert(D3D9FormatInfoPair(D3DFMT_DXT3, D3DFormatInfo(128, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_DXT3, D3DFormatInfo(128, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL, NULL )));
map.insert(D3D9FormatInfoPair(D3DFMT_DXT5, D3DFormatInfo(128, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, NULL ))); map.insert(D3D9FormatInfoPair(D3DFMT_DXT5, D3DFormatInfo(128, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, NULL, NULL )));
return map; return map;
} }
...@@ -245,6 +248,34 @@ static d3d9::D3DFormatSet BuildAllD3DFormatSet() ...@@ -245,6 +248,34 @@ static d3d9::D3DFormatSet BuildAllD3DFormatSet()
return set; return set;
} }
struct D3D9FastCopyFormat
{
D3DFORMAT mSourceFormat;
GLenum mDestFormat;
GLenum mDestType;
D3D9FastCopyFormat(D3DFORMAT sourceFormat, GLenum destFormat, GLenum destType)
: mSourceFormat(sourceFormat), mDestFormat(destFormat), mDestType(destType)
{ }
bool operator<(const D3D9FastCopyFormat& other) const
{
return memcmp(this, &other, sizeof(D3D9FastCopyFormat)) < 0;
}
};
typedef std::map<D3D9FastCopyFormat, ColorCopyFunction> D3D9FastCopyMap;
typedef std::pair<D3D9FastCopyFormat, ColorCopyFunction> D3D9FastCopyPair;
static D3D9FastCopyMap BuildFastCopyMap()
{
D3D9FastCopyMap map;
map.insert(D3D9FastCopyPair(D3D9FastCopyFormat(D3DFMT_A8R8G8B8, GL_RGBA, GL_UNSIGNED_BYTE), CopyBGRAUByteToRGBAUByte));
return map;
}
namespace d3d9 namespace d3d9
{ {
...@@ -372,6 +403,27 @@ const D3DFormatSet &GetAllUsedD3DFormats() ...@@ -372,6 +403,27 @@ const D3DFormatSet &GetAllUsedD3DFormats()
return formatSet; return formatSet;
} }
ColorReadFunction GetColorReadFunction(D3DFORMAT format)
{
D3DFormatInfo d3dFormatInfo;
if (GetD3D9FormatInfo(format, &d3dFormatInfo))
{
return d3dFormatInfo.mColorReadFunction;
}
else
{
UNREACHABLE();
return NULL;
}
}
ColorCopyFunction GetFastCopyFunction(D3DFORMAT sourceFormat, GLenum destFormat, GLenum destType, GLuint clientVersion)
{
static const D3D9FastCopyMap fastCopyMap = BuildFastCopyMap();
D3D9FastCopyMap::const_iterator iter = fastCopyMap.find(D3D9FastCopyFormat(sourceFormat, destFormat, destType));
return (iter != fastCopyMap.end()) ? iter->second : NULL;
}
} }
namespace gl_d3d9 namespace gl_d3d9
......
...@@ -34,6 +34,9 @@ void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsize ...@@ -34,6 +34,9 @@ void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsize
const D3DFormatSet &GetAllUsedD3DFormats(); const D3DFormatSet &GetAllUsedD3DFormats();
ColorReadFunction GetColorReadFunction(D3DFORMAT format);
ColorCopyFunction GetFastCopyFunction(D3DFORMAT sourceFormat, GLenum destFormat, GLenum destType, GLuint clientVersion);
} }
namespace gl_d3d9 namespace gl_d3d9
......
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