Commit 45965b10 by Geoff Lang

Clean up copyvertex.h

* Move "private" functions into copyvertex.inl. * Capitalize global function names give them more descriptive names. * Use size_t for all dimensions. * Use uint8_t pointers instead of unsigned char pointers. Change-Id: I408cf7ebb28655c5811ad18979a20f4273d278cd Reviewed-on: https://chromium-review.googlesource.com/207373Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 301d161d
...@@ -206,6 +206,7 @@ ...@@ -206,6 +206,7 @@
<None Include="..\..\src\angle.gyp"/> <None Include="..\..\src\angle.gyp"/>
<None Include="..\..\src\libGLESv2\libGLESv2.def"/> <None Include="..\..\src\libGLESv2\libGLESv2.def"/>
<None Include="..\..\src\libGLESv2\renderer\loadimage.inl"/> <None Include="..\..\src\libGLESv2\renderer\loadimage.inl"/>
<None Include="..\..\src\libGLESv2\renderer\copyvertex.inl"/>
<None Include="..\..\src\libGLESv2\renderer\generatemip.inl"/> <None Include="..\..\src\libGLESv2\renderer\generatemip.inl"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -303,6 +303,9 @@ ...@@ -303,6 +303,9 @@
<ClInclude Include="..\..\src\libGLESv2\renderer\VertexArrayImpl.h"> <ClInclude Include="..\..\src\libGLESv2\renderer\VertexArrayImpl.h">
<Filter>src\libGLESv2\renderer</Filter> <Filter>src\libGLESv2\renderer</Filter>
</ClInclude> </ClInclude>
<None Include="..\..\src\libGLESv2\renderer\copyvertex.inl">
<Filter>src\libGLESv2\renderer</Filter>
</None>
<ClInclude Include="..\..\src\libGLESv2\renderer\SwapChain.h"> <ClInclude Include="..\..\src\libGLESv2\renderer\SwapChain.h">
<Filter>src\libGLESv2\renderer</Filter> <Filter>src\libGLESv2\renderer</Filter>
</ClInclude> </ClInclude>
......
...@@ -118,6 +118,7 @@ ...@@ -118,6 +118,7 @@
'libGLESv2/renderer/copyimage.cpp', 'libGLESv2/renderer/copyimage.cpp',
'libGLESv2/renderer/copyimage.h', 'libGLESv2/renderer/copyimage.h',
'libGLESv2/renderer/copyvertex.h', 'libGLESv2/renderer/copyvertex.h',
'libGLESv2/renderer/copyvertex.inl',
'libGLESv2/renderer/generatemip.h', 'libGLESv2/renderer/generatemip.h',
'libGLESv2/renderer/generatemip.inl', 'libGLESv2/renderer/generatemip.inl',
'libGLESv2/renderer/imageformats.h', 'libGLESv2/renderer/imageformats.h',
......
...@@ -31,7 +31,7 @@ typedef void (*ColorReadFunction)(const void *source, void *dest); ...@@ -31,7 +31,7 @@ typedef void (*ColorReadFunction)(const void *source, void *dest);
typedef void (*ColorWriteFunction)(const void *source, void *dest); typedef void (*ColorWriteFunction)(const void *source, void *dest);
typedef void (*ColorCopyFunction)(const void *source, void *dest); typedef void (*ColorCopyFunction)(const void *source, void *dest);
typedef void (*VertexCopyFunction)(const void *input, size_t stride, size_t count, void *output); typedef void (*VertexCopyFunction)(const uint8_t *input, size_t stride, size_t count, uint8_t *output);
namespace gl namespace gl
{ {
......
//
// 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.
//
namespace rx
{
template <typename T, size_t componentCount, uint32_t widenDefaultValueBits>
inline void CopyNativeVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output)
{
const size_t attribSize = sizeof(T)* componentCount;
const T defaultValue = gl::bitCast<T>(widenDefaultValueBits);
const bool widen = (widenDefaultValueBits != 0);
if (attribSize == stride && !widen)
{
memcpy(output, input, count * attribSize);
}
else
{
size_t outputStride = widen ? 4 : componentCount;
for (size_t i = 0; i < count; i++)
{
const T *offsetInput = reinterpret_cast<const T*>(input + (i * stride));
T *offsetOutput = reinterpret_cast<T*>(output) + i * outputStride;
for (size_t j = 0; j < componentCount; j++)
{
offsetOutput[j] = offsetInput[j];
}
if (widen)
{
offsetOutput[3] = defaultValue;
}
}
}
}
template <size_t componentCount>
inline void Copy32FixedTo32FVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output)
{
static const float divisor = 1.0f / (1 << 16);
for (size_t i = 0; i < count; i++)
{
const GLfixed* offsetInput = reinterpret_cast<const GLfixed*>(input + (stride * i));
float* offsetOutput = reinterpret_cast<float*>(output) + i * componentCount;
for (size_t j = 0; j < componentCount; j++)
{
offsetOutput[j] = static_cast<float>(offsetInput[j]) * divisor;
}
}
}
template <typename T, size_t componentCount, bool normalized>
inline void CopyTo32FVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output)
{
typedef std::numeric_limits<T> NL;
for (size_t i = 0; i < count; i++)
{
const T *offsetInput = reinterpret_cast<const T*>(input + (stride * i));
float *offsetOutput = reinterpret_cast<float*>(output) + i * componentCount;
for (size_t j = 0; j < componentCount; j++)
{
if (normalized)
{
if (NL::is_signed)
{
const float divisor = 1.0f / (2 * static_cast<float>(NL::max()) + 1);
offsetOutput[j] = (2 * static_cast<float>(offsetInput[j]) + 1) * divisor;
}
else
{
offsetOutput[j] = static_cast<float>(offsetInput[j]) / NL::max();
}
}
else
{
offsetOutput[j] = static_cast<float>(offsetInput[j]);
}
}
}
}
namespace priv
{
template <bool isSigned, bool normalized, bool toFloat>
static inline void CopyPackedRGB(uint32_t data, uint8_t *output)
{
const uint32_t rgbSignMask = 0x200; // 1 set at the 9 bit
const uint32_t negativeMask = 0xFFFFFC00; // All bits from 10 to 31 set to 1
if (toFloat)
{
GLfloat *floatOutput = reinterpret_cast<GLfloat*>(output);
if (isSigned)
{
GLfloat finalValue = 0;
if (data & rgbSignMask)
{
int negativeNumber = data | negativeMask;
finalValue = static_cast<GLfloat>(negativeNumber);
}
else
{
finalValue = static_cast<GLfloat>(data);
}
if (normalized)
{
const int32_t maxValue = 0x1FF; // 1 set in bits 0 through 8
const int32_t minValue = 0xFFFFFE01; // Inverse of maxValue
// A 10-bit two's complement number has the possibility of being minValue - 1 but
// OpenGL's normalization rules dictate that it should be clamped to minValue in this
// case.
if (finalValue < minValue)
{
finalValue = minValue;
}
const int32_t halfRange = (maxValue - minValue) >> 1;
*floatOutput = ((finalValue - minValue) / halfRange) - 1.0f;
}
else
{
*floatOutput = finalValue;
}
}
else
{
if (normalized)
{
const uint32_t maxValue = 0x3FF; // 1 set in bits 0 through 9
*floatOutput = static_cast<GLfloat>(data) / static_cast<GLfloat>(maxValue);
}
else
{
*floatOutput = static_cast<GLfloat>(data);
}
}
}
else
{
if (isSigned)
{
GLshort *intOutput = reinterpret_cast<GLshort*>(output);
if (data & rgbSignMask)
{
*intOutput = data | negativeMask;
}
else
{
*intOutput = data;
}
}
else
{
GLushort *uintOutput = reinterpret_cast<GLushort*>(output);
*uintOutput = data;
}
}
}
template <bool isSigned, bool normalized, bool toFloat>
inline void CopyPackedAlpha(uint32_t data, uint8_t *output)
{
if (toFloat)
{
GLfloat *floatOutput = reinterpret_cast<GLfloat*>(output);
if (isSigned)
{
if (normalized)
{
switch (data)
{
case 0x0: *floatOutput = 0.0f; break;
case 0x1: *floatOutput = 1.0f; break;
case 0x2: *floatOutput = -1.0f; break;
case 0x3: *floatOutput = -1.0f; break;
default: UNREACHABLE();
}
}
else
{
switch (data)
{
case 0x0: *floatOutput = 0.0f; break;
case 0x1: *floatOutput = 1.0f; break;
case 0x2: *floatOutput = -2.0f; break;
case 0x3: *floatOutput = -1.0f; break;
default: UNREACHABLE();
}
}
}
else
{
if (normalized)
{
switch (data)
{
case 0x0: *floatOutput = 0.0f / 3.0f; break;
case 0x1: *floatOutput = 1.0f / 3.0f; break;
case 0x2: *floatOutput = 2.0f / 3.0f; break;
case 0x3: *floatOutput = 3.0f / 3.0f; break;
default: UNREACHABLE();
}
}
else
{
switch (data)
{
case 0x0: *floatOutput = 0.0f; break;
case 0x1: *floatOutput = 1.0f; break;
case 0x2: *floatOutput = 2.0f; break;
case 0x3: *floatOutput = 3.0f; break;
default: UNREACHABLE();
}
}
}
}
else
{
if (isSigned)
{
GLshort *intOutput = reinterpret_cast<GLshort*>(output);
switch (data)
{
case 0x0: *intOutput = 0; break;
case 0x1: *intOutput = 1; break;
case 0x2: *intOutput = -2; break;
case 0x3: *intOutput = -1; break;
default: UNREACHABLE();
}
}
else
{
GLushort *uintOutput = reinterpret_cast<GLushort*>(output);
switch (data)
{
case 0x0: *uintOutput = 0; break;
case 0x1: *uintOutput = 1; break;
case 0x2: *uintOutput = 2; break;
case 0x3: *uintOutput = 3; break;
default: UNREACHABLE();
}
}
}
}
}
template <bool isSigned, bool normalized, bool toFloat>
inline void CopyXYZ10W2ToXYZW32FVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output)
{
const size_t outputComponentSize = toFloat ? 4 : 2;
const size_t componentCount = 4;
const uint32_t rgbMask = 0x3FF; // 1 set in bits 0 through 9
const size_t redShift = 0; // red is bits 0 through 9
const size_t greenShift = 10; // green is bits 10 through 19
const size_t blueShift = 20; // blue is bits 20 through 29
const uint32_t alphaMask = 0x3; // 1 set in bits 0 and 1
const size_t alphaShift = 30; // Alpha is the 30 and 31 bits
for (size_t i = 0; i < count; i++)
{
GLuint packedValue = *reinterpret_cast<const GLuint*>(input + (i * stride));
uint8_t *offsetOutput = output + (i * outputComponentSize * componentCount);
priv::CopyPackedRGB<isSigned, normalized, toFloat>( (packedValue >> redShift) & rgbMask, offsetOutput + (0 * outputComponentSize));
priv::CopyPackedRGB<isSigned, normalized, toFloat>( (packedValue >> greenShift) & rgbMask, offsetOutput + (1 * outputComponentSize));
priv::CopyPackedRGB<isSigned, normalized, toFloat>( (packedValue >> blueShift) & rgbMask, offsetOutput + (2 * outputComponentSize));
priv::CopyPackedAlpha<isSigned, normalized, toFloat>((packedValue >> alphaShift) & alphaMask, offsetOutput + (3 * outputComponentSize));
}
}
}
...@@ -83,24 +83,24 @@ bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, co ...@@ -83,24 +83,24 @@ bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, co
return false; return false;
} }
char* output = reinterpret_cast<char*>(mappedResource.pData) + offset; uint8_t* output = reinterpret_cast<uint8_t*>(mappedResource.pData) + offset;
const char *input = NULL; const uint8_t *input = NULL;
if (attrib.enabled) if (attrib.enabled)
{ {
if (buffer) if (buffer)
{ {
Buffer11 *storage = Buffer11::makeBuffer11(buffer->getImplementation()); Buffer11 *storage = Buffer11::makeBuffer11(buffer->getImplementation());
input = static_cast<const char*>(storage->getData()) + static_cast<int>(attrib.offset); input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
} }
else else
{ {
input = static_cast<const char*>(attrib.pointer); input = static_cast<const uint8_t*>(attrib.pointer);
} }
} }
else else
{ {
input = reinterpret_cast<const char*>(currentValue.FloatValues); input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
} }
if (instances == 0 || attrib.divisor == 0) if (instances == 0 || attrib.divisor == 0)
......
...@@ -77,7 +77,7 @@ bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, con ...@@ -77,7 +77,7 @@ bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, con
DWORD lockFlags = mDynamicUsage ? D3DLOCK_NOOVERWRITE : 0; DWORD lockFlags = mDynamicUsage ? D3DLOCK_NOOVERWRITE : 0;
void *mapPtr = NULL; uint8_t *mapPtr = NULL;
unsigned int mapSize; unsigned int mapSize;
if (!spaceRequired(attrib, count, instances, &mapSize)) if (!spaceRequired(attrib, count, instances, &mapSize))
...@@ -85,7 +85,7 @@ bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, con ...@@ -85,7 +85,7 @@ bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, con
return false; return false;
} }
HRESULT result = mVertexBuffer->Lock(offset, mapSize, &mapPtr, lockFlags); HRESULT result = mVertexBuffer->Lock(offset, mapSize, reinterpret_cast<void**>(&mapPtr), lockFlags);
if (FAILED(result)) if (FAILED(result))
{ {
...@@ -93,22 +93,22 @@ bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, con ...@@ -93,22 +93,22 @@ bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, con
return false; return false;
} }
const char *input = NULL; const uint8_t *input = NULL;
if (attrib.enabled) if (attrib.enabled)
{ {
if (buffer) if (buffer)
{ {
BufferImpl *storage = buffer->getImplementation(); BufferImpl *storage = buffer->getImplementation();
input = static_cast<const char*>(storage->getData()) + static_cast<int>(attrib.offset); input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
} }
else else
{ {
input = static_cast<const char*>(attrib.pointer); input = static_cast<const uint8_t*>(attrib.pointer);
} }
} }
else else
{ {
input = reinterpret_cast<const char*>(currentValue.FloatValues); input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
} }
if (instances == 0 || attrib.divisor == 0) if (instances == 0 || attrib.divisor == 0)
......
...@@ -154,11 +154,13 @@ struct VertexDataConverter ...@@ -154,11 +154,13 @@ struct VertexDataConverter
static const bool identity = (WidenRule::initialWidth == WidenRule::finalWidth) && Converter::identity; static const bool identity = (WidenRule::initialWidth == WidenRule::finalWidth) && Converter::identity;
static const std::size_t finalSize = WidenRule::finalWidth * sizeof(OutputType); static const std::size_t finalSize = WidenRule::finalWidth * sizeof(OutputType);
static void convertArray(const InputType *in, std::size_t stride, std::size_t n, OutputType *out) static void convertArray(const uint8_t *input, size_t stride, size_t n, uint8_t *output)
{ {
OutputType *out = reinterpret_cast<OutputType*>(output);
for (std::size_t i = 0; i < n; i++) for (std::size_t i = 0; i < n; i++)
{ {
const InputType *ein = pointerAddBytes(in, i * stride); const InputType *ein = reinterpret_cast<const InputType*>(input + i * stride);
copyComponent(out, ein, 0, static_cast<OutputType>(DefaultValueRule::zero())); copyComponent(out, ein, 0, static_cast<OutputType>(DefaultValueRule::zero()));
copyComponent(out, ein, 1, static_cast<OutputType>(DefaultValueRule::zero())); copyComponent(out, ein, 1, static_cast<OutputType>(DefaultValueRule::zero()));
...@@ -169,19 +171,7 @@ struct VertexDataConverter ...@@ -169,19 +171,7 @@ struct VertexDataConverter
} }
} }
static void convertArray(const void *in, std::size_t stride, std::size_t n, void *out)
{
return convertArray(static_cast<const InputType*>(in), stride, n, static_cast<OutputType*>(out));
}
private: private:
// Advance the given pointer by a number of bytes (not pointed-to elements).
template <class T>
static T *pointerAddBytes(T *basePtr, std::size_t numBytes)
{
return reinterpret_cast<T *>(reinterpret_cast<uintptr_t>(basePtr) + numBytes);
}
static void copyComponent(OutputType *out, const InputType *in, std::size_t elementindex, OutputType defaultvalue) static void copyComponent(OutputType *out, const InputType *in, std::size_t elementindex, OutputType defaultvalue)
{ {
if (WidenRule::finalWidth > elementindex) if (WidenRule::finalWidth > elementindex)
......
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