[spline/bezier]minor fix

This commit is contained in:
xebra 2018-09-30 11:07:28 +09:00
parent 405ead8d41
commit 5f9022ae14
2 changed files with 30 additions and 28 deletions

View File

@ -498,18 +498,19 @@ void DrawEngineCommon::SubmitSpline(const void *control_points, const void *indi
SimpleBufferManager managedBuf(decoded, DECODED_VERTEX_BUFFER_SIZE);
int num_points = count_u * count_v;
u16 index_lower_bound = 0;
u16 index_upper_bound = count_u * count_v - 1;
u16 index_upper_bound = num_points - 1;
IndexConverter ConvertIndex(vertType, indices);
if (indices)
GetIndexBounds(indices, count_u * count_v, vertType, &index_lower_bound, &index_upper_bound);
GetIndexBounds(indices, num_points, vertType, &index_lower_bound, &index_upper_bound);
VertexDecoder *origVDecoder = GetVertexDecoder((vertType & 0xFFFFFF) | (gstate.getUVGenMode() << 24));
*bytesRead = count_u * count_v * origVDecoder->VertexSize();
*bytesRead = num_points * origVDecoder->VertexSize();
// Simplify away bones and morph before proceeding
SimpleVertex *simplified_control_points = (SimpleVertex *)managedBuf.Allocate(sizeof(SimpleVertex) * (index_upper_bound + 1));
u8 *temp_buffer = managedBuf.Allocate(sizeof(SimpleVertex) * count_u * count_v);
u8 *temp_buffer = managedBuf.Allocate(sizeof(SimpleVertex) * num_points);
u32 origVertType = vertType;
vertType = NormalizeVertices((u8 *)simplified_control_points, temp_buffer, (u8 *)control_points, index_lower_bound, index_upper_bound, vertType);
@ -522,8 +523,8 @@ void DrawEngineCommon::SubmitSpline(const void *control_points, const void *indi
}
// Make an array of pointers to the control points, to get rid of indices.
const SimpleVertex **points = (const SimpleVertex **)managedBuf.Allocate(sizeof(SimpleVertex *) * count_u * count_v);
for (int idx = 0; idx < count_u * count_v; idx++)
const SimpleVertex **points = (const SimpleVertex **)managedBuf.Allocate(sizeof(SimpleVertex *) * num_points);
for (int idx = 0; idx < num_points; idx++)
points[idx] = simplified_control_points + (indices ? ConvertIndex(idx) : idx);
OutputBuffers output;
@ -547,7 +548,7 @@ void DrawEngineCommon::SubmitSpline(const void *control_points, const void *indi
if (CanUseHardwareTessellation(prim_type)) {
HardwareTessellation(output, surface, origVertType, points, tessDataTransfer);
} else {
ControlPoints cpoints(points, count_u * count_v, managedBuf);
ControlPoints cpoints(points, num_points, managedBuf);
SoftwareTessellation(output, surface, origVertType, cpoints);
}
@ -586,19 +587,20 @@ void DrawEngineCommon::SubmitBezier(const void *control_points, const void *indi
SimpleBufferManager managedBuf(decoded, DECODED_VERTEX_BUFFER_SIZE);
int num_points = count_u * count_v;
u16 index_lower_bound = 0;
u16 index_upper_bound = count_u * count_v - 1;
u16 index_upper_bound = num_points - 1;
IndexConverter ConvertIndex(vertType, indices);
if (indices)
GetIndexBounds(indices, count_u*count_v, vertType, &index_lower_bound, &index_upper_bound);
GetIndexBounds(indices, num_points, vertType, &index_lower_bound, &index_upper_bound);
VertexDecoder *origVDecoder = GetVertexDecoder((vertType & 0xFFFFFF) | (gstate.getUVGenMode() << 24));
*bytesRead = count_u * count_v * origVDecoder->VertexSize();
*bytesRead = num_points * origVDecoder->VertexSize();
// Simplify away bones and morph before proceeding
// There are normally not a lot of control points so just splitting decoded should be reasonably safe, although not great.
SimpleVertex *simplified_control_points = (SimpleVertex *)managedBuf.Allocate(sizeof(SimpleVertex) * (index_upper_bound + 1));
u8 *temp_buffer = managedBuf.Allocate(sizeof(SimpleVertex) * count_u * count_v);
u8 *temp_buffer = managedBuf.Allocate(sizeof(SimpleVertex) * num_points);
u32 origVertType = vertType;
vertType = NormalizeVertices((u8 *)simplified_control_points, temp_buffer, (u8 *)control_points, index_lower_bound, index_upper_bound, vertType);
@ -611,8 +613,8 @@ void DrawEngineCommon::SubmitBezier(const void *control_points, const void *indi
}
// Make an array of pointers to the control points, to get rid of indices.
const SimpleVertex **points = (const SimpleVertex **)managedBuf.Allocate(sizeof(SimpleVertex *) * count_u * count_v);
for (int idx = 0; idx < count_u * count_v; idx++)
const SimpleVertex **points = (const SimpleVertex **)managedBuf.Allocate(sizeof(SimpleVertex *) * num_points);
for (int idx = 0; idx < num_points; idx++)
points[idx] = simplified_control_points + (indices ? ConvertIndex(idx) : idx);
OutputBuffers output;
@ -634,7 +636,7 @@ void DrawEngineCommon::SubmitBezier(const void *control_points, const void *indi
if (CanUseHardwareTessellation(prim_type)) {
HardwareTessellation(output, surface, origVertType, points, tessDataTransfer);
} else {
ControlPoints cpoints(points, count_u * count_v, managedBuf);
ControlPoints cpoints(points, num_points, managedBuf);
SoftwareTessellation(output, surface, origVertType, cpoints);
}

View File

@ -183,10 +183,10 @@ static void ExpandBezier(int &count, int op, const std::vector<SimpleVertex> &si
surface.primType = gstate.getPatchPrimitiveType();
surface.patchFacing = false;
int size = count_u * count_v;
int num_points = count_u * count_v;
// Make an array of pointers to the control points, to get rid of indices.
std::vector<const SimpleVertex *> points(size);
for (int idx = 0; idx < size; idx++)
std::vector<const SimpleVertex *> points(num_points);
for (int idx = 0; idx < num_points; idx++)
points[idx] = simpleVerts.data() + (!indices.empty() ? indices[idx] : idx);
int total_patches = surface.num_patches_u * surface.num_patches_v;
@ -199,10 +199,10 @@ static void ExpandBezier(int &count, int op, const std::vector<SimpleVertex> &si
output.count = 0;
ControlPoints cpoints;
cpoints.pos = (Vec3f *)AllocateAlignedMemory(sizeof(Vec3f) * size, 16);
cpoints.tex = (Vec2f *)AllocateAlignedMemory(sizeof(Vec2f) * size, 16);
cpoints.col = (Vec4f *)AllocateAlignedMemory(sizeof(Vec4f) * size, 16);
cpoints.Convert(points.data(), size);
cpoints.pos = (Vec3f *)AllocateAlignedMemory(sizeof(Vec3f) * num_points, 16);
cpoints.tex = (Vec2f *)AllocateAlignedMemory(sizeof(Vec2f) * num_points, 16);
cpoints.col = (Vec4f *)AllocateAlignedMemory(sizeof(Vec4f) * num_points, 16);
cpoints.Convert(points.data(), num_points);
surface.Init(generatedVerts.size());
SoftwareTessellation(output, surface, gstate.vertType, cpoints);
@ -234,10 +234,10 @@ static void ExpandSpline(int &count, int op, const std::vector<SimpleVertex> &si
surface.primType = gstate.getPatchPrimitiveType();
surface.patchFacing = false;
int size = count_u * count_v;
int num_points = count_u * count_v;
// Make an array of pointers to the control points, to get rid of indices.
std::vector<const SimpleVertex *> points(size);
for (int idx = 0; idx < size; idx++)
std::vector<const SimpleVertex *> points(num_points);
for (int idx = 0; idx < num_points; idx++)
points[idx] = simpleVerts.data() + (!indices.empty() ? indices[idx] : idx);
int patch_div_s = surface.num_patches_u * surface.tess_u;
@ -251,10 +251,10 @@ static void ExpandSpline(int &count, int op, const std::vector<SimpleVertex> &si
output.count = 0;
ControlPoints cpoints;
cpoints.pos = (Vec3f *)AllocateAlignedMemory(sizeof(Vec3f) * size, 16);
cpoints.tex = (Vec2f *)AllocateAlignedMemory(sizeof(Vec2f) * size, 16);
cpoints.col = (Vec4f *)AllocateAlignedMemory(sizeof(Vec4f) * size, 16);
cpoints.Convert(points.data(), size);
cpoints.pos = (Vec3f *)AllocateAlignedMemory(sizeof(Vec3f) * num_points, 16);
cpoints.tex = (Vec2f *)AllocateAlignedMemory(sizeof(Vec2f) * num_points, 16);
cpoints.col = (Vec4f *)AllocateAlignedMemory(sizeof(Vec4f) * num_points, 16);
cpoints.Convert(points.data(), num_points);
surface.Init(generatedVerts.size());
SoftwareTessellation(output, surface, gstate.vertType, cpoints);