Commit 57f9b6d5 by Geoff Lang

Clean up generatemip.h.

* Move "private" functions into generatemip.inl. * Use size_t for all dimensions. * Use uint8_t pointers instead of unsigned char pointers. BUG=angle:666 Change-Id: I8a1324802e4d670c042e0961c2b6f6fd53f4ebc7 Reviewed-on: https://chromium-review.googlesource.com/202503Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 86846e24
......@@ -387,6 +387,7 @@ if (is_win) {
"src/libGLESv2/renderer/copyimage.h",
"src/libGLESv2/renderer/copyvertex.h",
"src/libGLESv2/renderer/generatemip.h",
"src/libGLESv2/renderer/generatemip.inl",
"src/libGLESv2/renderer/imageformats.h",
"src/libGLESv2/renderer/loadimage.cpp",
"src/libGLESv2/renderer/loadimage.h",
......
......@@ -114,6 +114,7 @@
<None Include="..\..\src\angle.gyp"/>
<None Include="..\..\src\libGLESv2\libGLESv2.def"/>
<None Include="..\..\src\libGLESv2\renderer\loadimage.inl"/>
<None Include="..\..\src\libGLESv2\renderer\generatemip.inl"/>
<None Include="..\..\src\libGLESv2\renderer\d3d\d3d11\shaders\Swizzle11.hlsl"/>
<None Include="..\..\src\libGLESv2\renderer\d3d\d3d11\shaders\generate_shaders.bat"/>
<None Include="..\..\src\libGLESv2\renderer\d3d\d3d11\shaders\Passthrough3D11.hlsl"/>
......@@ -330,12 +331,12 @@
<ClCompile Include="..\..\src\libGLESv2\Texture.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\ResourceManager.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\copyimage.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\TextureStorage.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\loadimage.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\loadimageSSE2.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\Image.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\Renderer.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\IndexRangeCache.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\TextureStorage.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\d3d\HLSLCompiler.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\d3d\BufferD3D.cpp"/>
<ClCompile Include="..\..\src\libGLESv2\renderer\d3d\IndexBuffer.cpp"/>
......
......@@ -267,6 +267,9 @@
<None Include="..\..\src\libGLESv2\renderer\loadimage.inl">
<Filter>src\libGLESv2\renderer</Filter>
</None>
<ClCompile Include="..\..\src\libGLESv2\renderer\TextureStorage.cpp">
<Filter>src\libGLESv2\renderer</Filter>
</ClCompile>
<ClInclude Include="..\..\src\libGLESv2\renderer\ShaderExecutable.h">
<Filter>src\libGLESv2\renderer</Filter>
</ClInclude>
......@@ -327,9 +330,9 @@
<ClCompile Include="..\..\src\libGLESv2\renderer\IndexRangeCache.cpp">
<Filter>src\libGLESv2\renderer</Filter>
</ClCompile>
<ClCompile Include="..\..\src\libGLESv2\renderer\TextureStorage.cpp">
<None Include="..\..\src\libGLESv2\renderer\generatemip.inl">
<Filter>src\libGLESv2\renderer</Filter>
</ClCompile>
</None>
<ClCompile Include="..\..\src\libGLESv2\renderer\d3d\HLSLCompiler.cpp">
<Filter>src\libGLESv2\renderer\d3d</Filter>
</ClCompile>
......
......@@ -16,9 +16,9 @@
#include <cstddef>
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 (*MipGenerationFunction)(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch);
typedef void (*LoadImageFunction)(size_t width, size_t height, size_t depth,
const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
......
......@@ -67,8 +67,8 @@ void Image11::generateMipmap(Image11 *dest, Image11 *src)
return;
}
const unsigned char *sourceData = reinterpret_cast<const unsigned char*>(srcMapped.pData);
unsigned char *destData = reinterpret_cast<unsigned char*>(destMapped.pData);
const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(srcMapped.pData);
uint8_t *destData = reinterpret_cast<uint8_t*>(destMapped.pData);
mipFunction(src->getWidth(), src->getHeight(), src->getDepth(), sourceData, srcMapped.RowPitch, srcMapped.DepthPitch,
destData, destMapped.RowPitch, destMapped.DepthPitch);
......
......@@ -64,8 +64,8 @@ void Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sour
result = destSurface->LockRect(&destLocked, NULL, 0);
ASSERT(SUCCEEDED(result));
const unsigned char *sourceData = reinterpret_cast<const unsigned char*>(sourceLocked.pBits);
unsigned char *destData = reinterpret_cast<unsigned char*>(destLocked.pBits);
const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(sourceLocked.pBits);
uint8_t *destData = reinterpret_cast<uint8_t*>(destLocked.pBits);
if (sourceData && destData)
{
......
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Copyright (c) 2002-2014 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.
//
......@@ -10,260 +10,19 @@
#ifndef LIBGLESV2_RENDERER_GENERATEMIP_H_
#define LIBGLESV2_RENDERER_GENERATEMIP_H_
#include "common/mathutil.h"
#include "imageformats.h"
#include "libGLESv2/renderer/imageformats.h"
#include "libGLESv2/angletypes.h"
namespace rx
{
namespace priv
{
template <typename T>
static inline T *GetPixel(void *data, unsigned int x, unsigned int y, unsigned int z, unsigned int rowPitch, unsigned int depthPitch)
{
return reinterpret_cast<T*>(reinterpret_cast<unsigned char*>(data) + (x * sizeof(T)) + (y * rowPitch) + (z * depthPitch));
}
template <typename T>
static inline const T *GetPixel(const void *data, unsigned int x, unsigned int y, unsigned int z, unsigned int rowPitch, unsigned int depthPitch)
{
return reinterpret_cast<const T*>(reinterpret_cast<const unsigned char*>(data) + (x * sizeof(T)) + (y * rowPitch) + (z * depthPitch));
}
template <typename T>
static void GenerateMip_Y(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned int destWidth, unsigned int destHeight, unsigned int destDepth,
unsigned char *destData, int destRowPitch, int destDepthPitch)
{
ASSERT(sourceWidth == 1);
ASSERT(sourceHeight > 1);
ASSERT(sourceDepth == 1);
for (unsigned int y = 0; y < destHeight; y++)
{
const T *src0 = GetPixel<T>(sourceData, 0, y * 2, 0, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, 0, y * 2 + 1, 0, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, 0, y, 0, destRowPitch, destDepthPitch);
T::average(dst, src0, src1);
}
}
template <typename T>
static void GenerateMip_X(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned int destWidth, unsigned int destHeight, unsigned int destDepth,
unsigned char *destData, int destRowPitch, int destDepthPitch)
{
ASSERT(sourceWidth > 1);
ASSERT(sourceHeight == 1);
ASSERT(sourceDepth == 1);
for (unsigned int x = 0; x < destWidth; x++)
{
const T *src0 = GetPixel<T>(sourceData, x * 2, 0, 0, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, x * 2 + 1, 0, 0, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, x, 0, 0, destRowPitch, destDepthPitch);
T::average(dst, src0, src1);
}
}
template <typename T>
static void GenerateMip_Z(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned int destWidth, unsigned int destHeight, unsigned int destDepth,
unsigned char *destData, int destRowPitch, int destDepthPitch)
{
ASSERT(sourceWidth == 1);
ASSERT(sourceHeight == 1);
ASSERT(sourceDepth > 1);
for (unsigned int z = 0; z < destDepth; z++)
{
const T *src0 = GetPixel<T>(sourceData, 0, 0, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, 0, 0, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, 0, 0, z, destRowPitch, destDepthPitch);
T::average(dst, src0, src1);
}
}
template <typename T>
static void GenerateMip_XY(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned int destWidth, unsigned int destHeight, unsigned int destDepth,
unsigned char *destData, int destRowPitch, int destDepthPitch)
{
ASSERT(sourceWidth > 1);
ASSERT(sourceHeight > 1);
ASSERT(sourceDepth == 1);
for (unsigned int y = 0; y < destHeight; y++)
{
for (unsigned int x = 0; x < destWidth; x++)
{
const T *src0 = GetPixel<T>(sourceData, x * 2, y * 2, 0, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, x * 2, y * 2 + 1, 0, sourceRowPitch, sourceDepthPitch);
const T *src2 = GetPixel<T>(sourceData, x * 2 + 1, y * 2, 0, sourceRowPitch, sourceDepthPitch);
const T *src3 = GetPixel<T>(sourceData, x * 2 + 1, y * 2 + 1, 0, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, x, y, 0, destRowPitch, destDepthPitch);
T tmp0, tmp1;
T::average(&tmp0, src0, src1);
T::average(&tmp1, src2, src3);
T::average(dst, &tmp0, &tmp1);
}
}
}
template <typename T>
static void GenerateMip_YZ(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned int destWidth, unsigned int destHeight, unsigned int destDepth,
unsigned char *destData, int destRowPitch, int destDepthPitch)
{
ASSERT(sourceWidth == 1);
ASSERT(sourceHeight > 1);
ASSERT(sourceDepth > 1);
for (unsigned int z = 0; z < destDepth; z++)
{
for (unsigned int y = 0; y < destHeight; y++)
{
const T *src0 = GetPixel<T>(sourceData, 0, y * 2, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, 0, y * 2, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
const T *src2 = GetPixel<T>(sourceData, 0, y * 2 + 1, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src3 = GetPixel<T>(sourceData, 0, y * 2 + 1, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, 0, y, z, destRowPitch, destDepthPitch);
T tmp0, tmp1;
T::average(&tmp0, src0, src1);
T::average(&tmp1, src2, src3);
T::average(dst, &tmp0, &tmp1);
}
}
}
template <typename T>
static void GenerateMip_XZ(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned int destWidth, unsigned int destHeight, unsigned int destDepth,
unsigned char *destData, int destRowPitch, int destDepthPitch)
{
ASSERT(sourceWidth > 1);
ASSERT(sourceHeight == 1);
ASSERT(sourceDepth > 1);
for (unsigned int z = 0; z < destDepth; z++)
{
for (unsigned int x = 0; x < destWidth; x++)
{
const T *src0 = GetPixel<T>(sourceData, x * 2, 0, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, x * 2, 0, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
const T *src2 = GetPixel<T>(sourceData, x * 2 + 1, 0, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src3 = GetPixel<T>(sourceData, x * 2 + 1, 0, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, x, 0, z, destRowPitch, destDepthPitch);
inline void GenerateMip(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch);
T tmp0, tmp1;
T::average(&tmp0, src0, src1);
T::average(&tmp1, src2, src3);
T::average(dst, &tmp0, &tmp1);
}
}
}
template <typename T>
static void GenerateMip_XYZ(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned int destWidth, unsigned int destHeight, unsigned int destDepth,
unsigned char *destData, int destRowPitch, int destDepthPitch)
{
ASSERT(sourceWidth > 1);
ASSERT(sourceHeight > 1);
ASSERT(sourceDepth > 1);
for (unsigned int z = 0; z < destDepth; z++)
{
for (unsigned int y = 0; y < destHeight; y++)
{
for (unsigned int x = 0; x < destWidth; x++)
{
const T *src0 = GetPixel<T>(sourceData, x * 2, y * 2, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, x * 2, y * 2, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
const T *src2 = GetPixel<T>(sourceData, x * 2, y * 2 + 1, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src3 = GetPixel<T>(sourceData, x * 2, y * 2 + 1, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
const T *src4 = GetPixel<T>(sourceData, x * 2 + 1, y * 2, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src5 = GetPixel<T>(sourceData, x * 2 + 1, y * 2, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
const T *src6 = GetPixel<T>(sourceData, x * 2 + 1, y * 2 + 1, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src7 = GetPixel<T>(sourceData, x * 2 + 1, y * 2 + 1, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, x, y, z, destRowPitch, destDepthPitch);
T tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
T::average(&tmp0, src0, src1);
T::average(&tmp1, src2, src3);
T::average(&tmp2, src4, src5);
T::average(&tmp3, src6, src7);
T::average(&tmp4, &tmp0, &tmp1);
T::average(&tmp5, &tmp2, &tmp3);
T::average(dst, &tmp4, &tmp5);
}
}
}
}
typedef void (*MipGenerationFunction)(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned int destWidth, unsigned int destHeight, unsigned int destDepth,
unsigned char *destData, int destRowPitch, int destDepthPitch);
template <typename T>
static MipGenerationFunction GetMipGenerationFunction(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth)
{
unsigned char index = ((sourceWidth > 1) ? 1 : 0) |
((sourceHeight > 1) ? 2 : 0) |
((sourceDepth > 1) ? 4 : 0);
switch (index)
{
case 1: return GenerateMip_X<T>; // W x 1 x 1
case 2: return GenerateMip_Y<T>; // 1 x H x 1
case 3: return GenerateMip_XY<T>; // W x H x 1
case 4: return GenerateMip_Z<T>; // 1 x 1 x D
case 5: return GenerateMip_XZ<T>; // W x 1 x D
case 6: return GenerateMip_YZ<T>; // 1 x H x D
case 7: return GenerateMip_XYZ<T>; // W x H x D
default: return NULL;
}
}
}
template <typename T>
static void GenerateMip(unsigned int sourceWidth, unsigned int sourceHeight, unsigned int sourceDepth,
const unsigned char *sourceData, int sourceRowPitch, int sourceDepthPitch,
unsigned char *destData, int destRowPitch, int destDepthPitch)
{
unsigned int mipWidth = std::max(1U, sourceWidth >> 1);
unsigned int mipHeight = std::max(1U, sourceHeight >> 1);
unsigned int mipDepth = std::max(1U, sourceDepth >> 1);
priv::MipGenerationFunction generationFunction = priv::GetMipGenerationFunction<T>(sourceWidth, sourceHeight, sourceDepth);
ASSERT(generationFunction != NULL);
generationFunction(sourceWidth, sourceHeight, sourceDepth, sourceData, sourceRowPitch, sourceDepthPitch,
mipWidth, mipHeight, mipDepth, destData, destRowPitch, destDepthPitch);
}
}
#include "generatemip.inl"
#endif // LIBGLESV2_RENDERER_GENERATEMIP_H_
//
// Copyright (c) 2014 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.
//
// generatemip.inl: Defines the GenerateMip function, templated on the format
// type of the image for which mip levels are being generated.
#include "common/mathutil.h"
namespace rx
{
namespace priv
{
template <typename T>
static inline T *GetPixel(uint8_t *data, size_t x, size_t y, size_t z, size_t rowPitch, size_t depthPitch)
{
return reinterpret_cast<T*>(data + (x * sizeof(T)) + (y * rowPitch) + (z * depthPitch));
}
template <typename T>
static inline const T *GetPixel(const uint8_t *data, size_t x, size_t y, size_t z, size_t rowPitch, size_t depthPitch)
{
return reinterpret_cast<const T*>(data + (x * sizeof(T)) + (y * rowPitch) + (z * depthPitch));
}
template <typename T>
static void GenerateMip_Y(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
size_t destWidth, size_t destHeight, size_t destDepth,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch)
{
ASSERT(sourceWidth == 1);
ASSERT(sourceHeight > 1);
ASSERT(sourceDepth == 1);
for (size_t y = 0; y < destHeight; y++)
{
const T *src0 = GetPixel<T>(sourceData, 0, y * 2, 0, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, 0, y * 2 + 1, 0, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, 0, y, 0, destRowPitch, destDepthPitch);
T::average(dst, src0, src1);
}
}
template <typename T>
static void GenerateMip_X(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
size_t destWidth, size_t destHeight, size_t destDepth,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch)
{
ASSERT(sourceWidth > 1);
ASSERT(sourceHeight == 1);
ASSERT(sourceDepth == 1);
for (size_t x = 0; x < destWidth; x++)
{
const T *src0 = GetPixel<T>(sourceData, x * 2, 0, 0, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, x * 2 + 1, 0, 0, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, x, 0, 0, destRowPitch, destDepthPitch);
T::average(dst, src0, src1);
}
}
template <typename T>
static void GenerateMip_Z(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
size_t destWidth, size_t destHeight, size_t destDepth,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch)
{
ASSERT(sourceWidth == 1);
ASSERT(sourceHeight == 1);
ASSERT(sourceDepth > 1);
for (size_t z = 0; z < destDepth; z++)
{
const T *src0 = GetPixel<T>(sourceData, 0, 0, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, 0, 0, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, 0, 0, z, destRowPitch, destDepthPitch);
T::average(dst, src0, src1);
}
}
template <typename T>
static void GenerateMip_XY(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
size_t destWidth, size_t destHeight, size_t destDepth,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch)
{
ASSERT(sourceWidth > 1);
ASSERT(sourceHeight > 1);
ASSERT(sourceDepth == 1);
for (size_t y = 0; y < destHeight; y++)
{
for (size_t x = 0; x < destWidth; x++)
{
const T *src0 = GetPixel<T>(sourceData, x * 2, y * 2, 0, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, x * 2, y * 2 + 1, 0, sourceRowPitch, sourceDepthPitch);
const T *src2 = GetPixel<T>(sourceData, x * 2 + 1, y * 2, 0, sourceRowPitch, sourceDepthPitch);
const T *src3 = GetPixel<T>(sourceData, x * 2 + 1, y * 2 + 1, 0, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, x, y, 0, destRowPitch, destDepthPitch);
T tmp0, tmp1;
T::average(&tmp0, src0, src1);
T::average(&tmp1, src2, src3);
T::average(dst, &tmp0, &tmp1);
}
}
}
template <typename T>
static void GenerateMip_YZ(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
size_t destWidth, size_t destHeight, size_t destDepth,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch)
{
ASSERT(sourceWidth == 1);
ASSERT(sourceHeight > 1);
ASSERT(sourceDepth > 1);
for (size_t z = 0; z < destDepth; z++)
{
for (size_t y = 0; y < destHeight; y++)
{
const T *src0 = GetPixel<T>(sourceData, 0, y * 2, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, 0, y * 2, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
const T *src2 = GetPixel<T>(sourceData, 0, y * 2 + 1, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src3 = GetPixel<T>(sourceData, 0, y * 2 + 1, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, 0, y, z, destRowPitch, destDepthPitch);
T tmp0, tmp1;
T::average(&tmp0, src0, src1);
T::average(&tmp1, src2, src3);
T::average(dst, &tmp0, &tmp1);
}
}
}
template <typename T>
static void GenerateMip_XZ(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
size_t destWidth, size_t destHeight, size_t destDepth,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch)
{
ASSERT(sourceWidth > 1);
ASSERT(sourceHeight == 1);
ASSERT(sourceDepth > 1);
for (size_t z = 0; z < destDepth; z++)
{
for (size_t x = 0; x < destWidth; x++)
{
const T *src0 = GetPixel<T>(sourceData, x * 2, 0, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, x * 2, 0, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
const T *src2 = GetPixel<T>(sourceData, x * 2 + 1, 0, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src3 = GetPixel<T>(sourceData, x * 2 + 1, 0, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, x, 0, z, destRowPitch, destDepthPitch);
T tmp0, tmp1;
T::average(&tmp0, src0, src1);
T::average(&tmp1, src2, src3);
T::average(dst, &tmp0, &tmp1);
}
}
}
template <typename T>
static void GenerateMip_XYZ(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
size_t destWidth, size_t destHeight, size_t destDepth,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch)
{
ASSERT(sourceWidth > 1);
ASSERT(sourceHeight > 1);
ASSERT(sourceDepth > 1);
for (size_t z = 0; z < destDepth; z++)
{
for (size_t y = 0; y < destHeight; y++)
{
for (size_t x = 0; x < destWidth; x++)
{
const T *src0 = GetPixel<T>(sourceData, x * 2, y * 2, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src1 = GetPixel<T>(sourceData, x * 2, y * 2, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
const T *src2 = GetPixel<T>(sourceData, x * 2, y * 2 + 1, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src3 = GetPixel<T>(sourceData, x * 2, y * 2 + 1, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
const T *src4 = GetPixel<T>(sourceData, x * 2 + 1, y * 2, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src5 = GetPixel<T>(sourceData, x * 2 + 1, y * 2, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
const T *src6 = GetPixel<T>(sourceData, x * 2 + 1, y * 2 + 1, z * 2, sourceRowPitch, sourceDepthPitch);
const T *src7 = GetPixel<T>(sourceData, x * 2 + 1, y * 2 + 1, z * 2 + 1, sourceRowPitch, sourceDepthPitch);
T *dst = GetPixel<T>(destData, x, y, z, destRowPitch, destDepthPitch);
T tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
T::average(&tmp0, src0, src1);
T::average(&tmp1, src2, src3);
T::average(&tmp2, src4, src5);
T::average(&tmp3, src6, src7);
T::average(&tmp4, &tmp0, &tmp1);
T::average(&tmp5, &tmp2, &tmp3);
T::average(dst, &tmp4, &tmp5);
}
}
}
}
typedef void (*MipGenerationFunction)(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
size_t destWidth, size_t destHeight, size_t destDepth,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch);
template <typename T>
static MipGenerationFunction GetMipGenerationFunction(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth)
{
uint8_t index = ((sourceWidth > 1) ? 1 : 0) |
((sourceHeight > 1) ? 2 : 0) |
((sourceDepth > 1) ? 4 : 0);
switch (index)
{
case 0: return NULL;
case 1: return GenerateMip_X<T>; // W x 1 x 1
case 2: return GenerateMip_Y<T>; // 1 x H x 1
case 3: return GenerateMip_XY<T>; // W x H x 1
case 4: return GenerateMip_Z<T>; // 1 x 1 x D
case 5: return GenerateMip_XZ<T>; // W x 1 x D
case 6: return GenerateMip_YZ<T>; // 1 x H x D
case 7: return GenerateMip_XYZ<T>; // W x H x D
}
UNREACHABLE();
return NULL;
}
}
template <typename T>
inline void GenerateMip(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch)
{
size_t mipWidth = std::max(1U, sourceWidth >> 1);
size_t mipHeight = std::max(1U, sourceHeight >> 1);
size_t mipDepth = std::max(1U, sourceDepth >> 1);
priv::MipGenerationFunction generationFunction = priv::GetMipGenerationFunction<T>(sourceWidth, sourceHeight, sourceDepth);
ASSERT(generationFunction != NULL);
generationFunction(sourceWidth, sourceHeight, sourceDepth, sourceData, sourceRowPitch, sourceDepthPitch,
mipWidth, mipHeight, mipDepth, destData, destRowPitch, destDepthPitch);
}
}
......@@ -10,7 +10,7 @@
#ifndef LIBGLESV2_RENDERER_IMAGEFORMATS_H_
#define LIBGLESV2_RENDERER_IMAGEFORMATS_H_
#include "libGLESv2/angletypes.h"
#include "common/mathutil.h"
namespace rx
{
......
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