Merge pull request #1957 from lioncash/cs
Coding style cleanup from the zfreeze merge
This commit is contained in:
commit
bf0293231f
|
@ -41,10 +41,9 @@ static size_t s_baseVertex;
|
||||||
static size_t s_index_offset;
|
static size_t s_index_offset;
|
||||||
|
|
||||||
VertexManager::VertexManager()
|
VertexManager::VertexManager()
|
||||||
|
: m_cpu_v_buffer(MAX_VBUFFER_SIZE), m_cpu_i_buffer(MAX_IBUFFER_SIZE)
|
||||||
{
|
{
|
||||||
CreateDeviceObjects();
|
CreateDeviceObjects();
|
||||||
CpuVBuffer.resize(MAX_VBUFFER_SIZE);
|
|
||||||
CpuIBuffer.resize(MAX_IBUFFER_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexManager::~VertexManager()
|
VertexManager::~VertexManager()
|
||||||
|
@ -83,13 +82,13 @@ void VertexManager::PrepareDrawBuffers(u32 stride)
|
||||||
|
|
||||||
void VertexManager::ResetBuffer(u32 stride)
|
void VertexManager::ResetBuffer(u32 stride)
|
||||||
{
|
{
|
||||||
if (CullAll)
|
if (s_cull_all)
|
||||||
{
|
{
|
||||||
// This buffer isn't getting sent to the GPU. Just allocate it on the cpu.
|
// This buffer isn't getting sent to the GPU. Just allocate it on the cpu.
|
||||||
s_pCurBufferPointer = s_pBaseBufferPointer = CpuVBuffer.data();
|
s_pCurBufferPointer = s_pBaseBufferPointer = m_cpu_v_buffer.data();
|
||||||
s_pEndBufferPointer = s_pBaseBufferPointer + CpuVBuffer.size();
|
s_pEndBufferPointer = s_pBaseBufferPointer + m_cpu_v_buffer.size();
|
||||||
|
|
||||||
IndexGenerator::Start((u16*)CpuIBuffer.data());
|
IndexGenerator::Start((u16*)m_cpu_i_buffer.data());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,8 +47,8 @@ private:
|
||||||
void PrepareDrawBuffers(u32 stride);
|
void PrepareDrawBuffers(u32 stride);
|
||||||
|
|
||||||
// Alternative buffers in CPU memory for primatives we are going to discard.
|
// Alternative buffers in CPU memory for primatives we are going to discard.
|
||||||
std::vector<u8> CpuVBuffer;
|
std::vector<u8> m_cpu_v_buffer;
|
||||||
std::vector<u16> CpuIBuffer;
|
std::vector<u16> m_cpu_i_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,10 @@ u8 *VertexManager::s_pEndBufferPointer;
|
||||||
|
|
||||||
PrimitiveType VertexManager::current_primitive_type;
|
PrimitiveType VertexManager::current_primitive_type;
|
||||||
|
|
||||||
Slope VertexManager::ZSlope;
|
Slope VertexManager::s_zslope;
|
||||||
|
|
||||||
bool VertexManager::IsFlushed;
|
bool VertexManager::s_is_flushed;
|
||||||
bool VertexManager::CullAll;
|
bool VertexManager::s_cull_all;
|
||||||
|
|
||||||
static const PrimitiveType primitive_from_gx[8] = {
|
static const PrimitiveType primitive_from_gx[8] = {
|
||||||
PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS
|
PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS
|
||||||
|
@ -44,8 +44,8 @@ static const PrimitiveType primitive_from_gx[8] = {
|
||||||
|
|
||||||
VertexManager::VertexManager()
|
VertexManager::VertexManager()
|
||||||
{
|
{
|
||||||
IsFlushed = true;
|
s_is_flushed = true;
|
||||||
CullAll = false;
|
s_cull_all = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexManager::~VertexManager()
|
VertexManager::~VertexManager()
|
||||||
|
@ -68,8 +68,8 @@ DataReader VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32
|
||||||
current_primitive_type = primitive_from_gx[primitive];
|
current_primitive_type = primitive_from_gx[primitive];
|
||||||
|
|
||||||
// Check for size in buffer, if the buffer gets full, call Flush()
|
// Check for size in buffer, if the buffer gets full, call Flush()
|
||||||
if ( !IsFlushed && ( count > IndexGenerator::GetRemainingIndices() ||
|
if (!s_is_flushed && ( count > IndexGenerator::GetRemainingIndices() ||
|
||||||
count > GetRemainingIndices(primitive) || needed_vertex_bytes > GetRemainingSize() ) )
|
count > GetRemainingIndices(primitive) || needed_vertex_bytes > GetRemainingSize()))
|
||||||
{
|
{
|
||||||
Flush();
|
Flush();
|
||||||
|
|
||||||
|
@ -83,13 +83,13 @@ DataReader VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32
|
||||||
"Increase MAXVBUFFERSIZE or we need primitive breaking after all.");
|
"Increase MAXVBUFFERSIZE or we need primitive breaking after all.");
|
||||||
}
|
}
|
||||||
|
|
||||||
CullAll = cullall;
|
s_cull_all = cullall;
|
||||||
|
|
||||||
// need to alloc new buffer
|
// need to alloc new buffer
|
||||||
if (IsFlushed)
|
if (s_is_flushed)
|
||||||
{
|
{
|
||||||
g_vertex_manager->ResetBuffer(stride);
|
g_vertex_manager->ResetBuffer(stride);
|
||||||
IsFlushed = false;
|
s_is_flushed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DataReader(s_pCurBufferPointer, s_pEndBufferPointer);
|
return DataReader(s_pCurBufferPointer, s_pEndBufferPointer);
|
||||||
|
@ -160,7 +160,7 @@ u32 VertexManager::GetRemainingIndices(int primitive)
|
||||||
|
|
||||||
void VertexManager::Flush()
|
void VertexManager::Flush()
|
||||||
{
|
{
|
||||||
if (IsFlushed)
|
if (s_is_flushed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// loading a state will invalidate BP, so check for it
|
// loading a state will invalidate BP, so check for it
|
||||||
|
@ -197,7 +197,7 @@ void VertexManager::Flush()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// If the primitave is marked CullAll. All we need to do is update the vertex constants and calculate the zfreeze refrence slope
|
// If the primitave is marked CullAll. All we need to do is update the vertex constants and calculate the zfreeze refrence slope
|
||||||
if (!CullAll)
|
if (!s_cull_all)
|
||||||
{
|
{
|
||||||
BitSet32 usedtextures;
|
BitSet32 usedtextures;
|
||||||
for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i)
|
for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i)
|
||||||
|
@ -220,7 +220,9 @@ void VertexManager::Flush()
|
||||||
PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
|
PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
ERROR_LOG(VIDEO, "error loading texture");
|
ERROR_LOG(VIDEO, "error loading texture");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,13 +235,13 @@ void VertexManager::Flush()
|
||||||
// Must be done after VertexShaderManager::SetConstants()
|
// Must be done after VertexShaderManager::SetConstants()
|
||||||
CalculateZSlope(VertexLoaderManager::GetCurrentVertexFormat());
|
CalculateZSlope(VertexLoaderManager::GetCurrentVertexFormat());
|
||||||
}
|
}
|
||||||
else if (ZSlope.dirty && !CullAll) // or apply any dirty ZSlopes
|
else if (s_zslope.dirty && !s_cull_all) // or apply any dirty ZSlopes
|
||||||
{
|
{
|
||||||
PixelShaderManager::SetZSlope(ZSlope.dfdx, ZSlope.dfdy, ZSlope.f0);
|
PixelShaderManager::SetZSlope(s_zslope.dfdx, s_zslope.dfdy, s_zslope.f0);
|
||||||
ZSlope.dirty = false;
|
s_zslope.dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CullAll)
|
if (!s_cull_all)
|
||||||
{
|
{
|
||||||
// set the rest of the global constants
|
// set the rest of the global constants
|
||||||
GeometryShaderManager::SetConstants();
|
GeometryShaderManager::SetConstants();
|
||||||
|
@ -262,17 +264,17 @@ void VertexManager::Flush()
|
||||||
if (xfmem.numTexGen.numTexGens != bpmem.genMode.numtexgens)
|
if (xfmem.numTexGen.numTexGens != bpmem.genMode.numtexgens)
|
||||||
ERROR_LOG(VIDEO, "xf.numtexgens (%d) does not match bp.numtexgens (%d). Error in command stream.", xfmem.numTexGen.numTexGens, bpmem.genMode.numtexgens.Value());
|
ERROR_LOG(VIDEO, "xf.numtexgens (%d) does not match bp.numtexgens (%d). Error in command stream.", xfmem.numTexGen.numTexGens, bpmem.genMode.numtexgens.Value());
|
||||||
|
|
||||||
IsFlushed = true;
|
s_is_flushed = true;
|
||||||
CullAll = false;
|
s_cull_all = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexManager::DoState(PointerWrap& p)
|
void VertexManager::DoState(PointerWrap& p)
|
||||||
{
|
{
|
||||||
p.Do(ZSlope);
|
p.Do(s_zslope);
|
||||||
g_vertex_manager->vDoState(p);
|
g_vertex_manager->vDoState(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexManager::CalculateZSlope(NativeVertexFormat *format)
|
void VertexManager::CalculateZSlope(NativeVertexFormat* format)
|
||||||
{
|
{
|
||||||
float vtx[9];
|
float vtx[9];
|
||||||
float out[12];
|
float out[12];
|
||||||
|
@ -324,8 +326,8 @@ void VertexManager::CalculateZSlope(NativeVertexFormat *format)
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ZSlope.dfdx = -a / c;
|
s_zslope.dfdx = -a / c;
|
||||||
ZSlope.dfdy = -b / c;
|
s_zslope.dfdy = -b / c;
|
||||||
ZSlope.f0 = out[2] - (out[0] * ZSlope.dfdx + out[1] * ZSlope.dfdy);
|
s_zslope.f0 = out[2] - (out[0] * s_zslope.dfdx + out[1] * s_zslope.dfdy);
|
||||||
ZSlope.dirty = true;
|
s_zslope.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,13 +64,13 @@ protected:
|
||||||
static u32 GetRemainingSize();
|
static u32 GetRemainingSize();
|
||||||
static u32 GetRemainingIndices(int primitive);
|
static u32 GetRemainingIndices(int primitive);
|
||||||
|
|
||||||
static Slope ZSlope;
|
static Slope s_zslope;
|
||||||
static void CalculateZSlope(NativeVertexFormat *format);
|
static void CalculateZSlope(NativeVertexFormat* format);
|
||||||
|
|
||||||
static bool CullAll;
|
static bool s_cull_all;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool IsFlushed;
|
static bool s_is_flushed;
|
||||||
|
|
||||||
virtual void vFlush(bool useDstAlpha) = 0;
|
virtual void vFlush(bool useDstAlpha) = 0;
|
||||||
|
|
||||||
|
|
|
@ -690,13 +690,13 @@ void VertexShaderManager::ResetView()
|
||||||
bProjectionChanged = true;
|
bProjectionChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexShaderManager::TransformToClipSpace(const float* data, float *out, u32 MtxIdx)
|
void VertexShaderManager::TransformToClipSpace(const float* data, float* out, u32 MtxIdx)
|
||||||
{
|
{
|
||||||
const float *world_matrix = (const float *)xfmem.posMatrices + (MtxIdx & 0x3f) * 4;
|
const float* world_matrix = (const float*)xfmem.posMatrices + (MtxIdx & 0x3f) * 4;
|
||||||
// We use the projection matrix calculated by vertexShaderManager, because it
|
// We use the projection matrix calculated by vertexShaderManager, because it
|
||||||
// includes any free look transformations.
|
// includes any free look transformations.
|
||||||
// Make sure VertexManager::SetConstants() has been called first.
|
// Make sure VertexManager::SetConstants() has been called first.
|
||||||
const float *proj_matrix = &g_fProjectionMatrix[0];
|
const float* proj_matrix = &g_fProjectionMatrix[0];
|
||||||
|
|
||||||
float t[3];
|
float t[3];
|
||||||
t[0] = data[0] * world_matrix[0] + data[1] * world_matrix[1] + data[2] * world_matrix[2] + world_matrix[3];
|
t[0] = data[0] * world_matrix[0] + data[1] * world_matrix[1] + data[2] * world_matrix[2] + world_matrix[3];
|
||||||
|
|
|
@ -35,10 +35,10 @@ public:
|
||||||
static void ResetView();
|
static void ResetView();
|
||||||
|
|
||||||
// data: 3 floats representing the X, Y and Z vertex model coordinates and the posmatrix index.
|
// data: 3 floats representing the X, Y and Z vertex model coordinates and the posmatrix index.
|
||||||
// out: 4 floats which will be initialized with the corresponding clip space coordinates
|
// out: 4 floats which will be initialized with the corresponding clip space coordinates
|
||||||
// NOTE: g_fProjectionMatrix must be up to date when this is called
|
// NOTE: g_fProjectionMatrix must be up to date when this is called
|
||||||
// (i.e. VertexShaderManager::SetConstants needs to be called before using this!)
|
// (i.e. VertexShaderManager::SetConstants needs to be called before using this!)
|
||||||
static void TransformToClipSpace(const float* data, float *out, u32 mtxIdx);
|
static void TransformToClipSpace(const float* data, float* out, u32 mtxIdx);
|
||||||
|
|
||||||
static VertexShaderConstants constants;
|
static VertexShaderConstants constants;
|
||||||
static bool dirty;
|
static bool dirty;
|
||||||
|
|
Loading…
Reference in New Issue