2013-08-17 09:23:51 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2017-06-02 10:03:46 +00:00
|
|
|
#include <cstring>
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2020-09-24 07:24:03 +00:00
|
|
|
#include "ppsspp_config.h"
|
2024-02-12 17:03:39 +00:00
|
|
|
|
|
|
|
#include "Common/CPUDetect.h"
|
|
|
|
#include "Common/Common.h"
|
|
|
|
#include "Common/Log.h"
|
2020-09-23 23:56:20 +00:00
|
|
|
|
|
|
|
#ifdef _M_SSE
|
|
|
|
#include <emmintrin.h>
|
|
|
|
#endif
|
2020-09-24 07:24:03 +00:00
|
|
|
#if PPSSPP_ARCH(ARM_NEON)
|
2020-09-23 23:56:20 +00:00
|
|
|
|
2020-09-24 07:24:03 +00:00
|
|
|
#if defined(_MSC_VER) && PPSSPP_ARCH(ARM64)
|
|
|
|
#include <arm64_neon.h>
|
|
|
|
#else
|
|
|
|
#include <arm_neon.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
2024-02-12 17:03:39 +00:00
|
|
|
|
|
|
|
#include "GPU/Common/IndexGenerator.h"
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
// Points don't need indexing...
|
2017-01-28 11:03:45 +00:00
|
|
|
const u8 IndexGenerator::indexedPrimitiveType[7] = {
|
2013-08-17 09:23:51 +00:00
|
|
|
GE_PRIM_POINTS,
|
|
|
|
GE_PRIM_LINES,
|
|
|
|
GE_PRIM_LINES,
|
|
|
|
GE_PRIM_TRIANGLES,
|
|
|
|
GE_PRIM_TRIANGLES,
|
|
|
|
GE_PRIM_TRIANGLES,
|
|
|
|
GE_PRIM_RECTANGLES,
|
|
|
|
};
|
|
|
|
|
2023-10-02 09:25:27 +00:00
|
|
|
void IndexGenerator::AddPrim(int prim, int vertexCount, int indexOffset, bool clockwise) {
|
2013-08-17 09:23:51 +00:00
|
|
|
switch (prim) {
|
2023-10-02 09:25:27 +00:00
|
|
|
case GE_PRIM_POINTS: AddPoints(vertexCount, indexOffset); break;
|
|
|
|
case GE_PRIM_LINES: AddLineList(vertexCount, indexOffset); break;
|
|
|
|
case GE_PRIM_LINE_STRIP: AddLineStrip(vertexCount, indexOffset); break;
|
|
|
|
case GE_PRIM_TRIANGLES: AddList(vertexCount, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_TRIANGLE_STRIP: AddStrip(vertexCount, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_TRIANGLE_FAN: AddFan(vertexCount, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_RECTANGLES: AddRectangles(vertexCount, indexOffset); break; // Same
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-02 09:25:27 +00:00
|
|
|
void IndexGenerator::AddPoints(int numVerts, int indexOffset) {
|
2013-11-05 06:49:28 +00:00
|
|
|
u16 *outInds = inds_;
|
2013-08-17 09:23:51 +00:00
|
|
|
for (int i = 0; i < numVerts; i++)
|
2023-10-02 09:25:27 +00:00
|
|
|
*outInds++ = indexOffset + i;
|
2013-11-05 06:49:28 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 09:25:27 +00:00
|
|
|
void IndexGenerator::AddList(int numVerts, int indexOffset, bool clockwise) {
|
2013-11-05 06:49:28 +00:00
|
|
|
u16 *outInds = inds_;
|
2018-06-05 02:39:40 +00:00
|
|
|
const int v1 = clockwise ? 1 : 2;
|
|
|
|
const int v2 = clockwise ? 2 : 1;
|
2013-10-01 16:02:09 +00:00
|
|
|
for (int i = 0; i < numVerts; i += 3) {
|
2023-10-02 09:25:27 +00:00
|
|
|
*outInds++ = indexOffset + i;
|
|
|
|
*outInds++ = indexOffset + i + v1;
|
|
|
|
*outInds++ = indexOffset + i + v2;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-11-05 06:49:28 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 07:24:03 +00:00
|
|
|
alignas(16) static const u16 offsets_clockwise[24] = {
|
|
|
|
0, (u16)(0 + 1), (u16)(0 + 2),
|
2024-07-17 14:11:23 +00:00
|
|
|
(u16)(1 + 1), 1, (u16)(1 + 2),
|
2020-09-24 07:24:03 +00:00
|
|
|
2, (u16)(2 + 1), (u16)(2 + 2),
|
2024-07-17 14:11:23 +00:00
|
|
|
(u16)(3 + 1), 3, (u16)(3 + 2),
|
2020-09-24 07:24:03 +00:00
|
|
|
4, (u16)(4 + 1), (u16)(4 + 2),
|
2024-07-17 14:11:23 +00:00
|
|
|
(u16)(5 + 1), 5, (u16)(5 + 2),
|
2020-09-24 07:24:03 +00:00
|
|
|
6, (u16)(6 + 1), (u16)(6 + 2),
|
2024-07-17 14:11:23 +00:00
|
|
|
(u16)(7 + 1), 7, (u16)(7 + 2),
|
2020-09-24 07:24:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
alignas(16) static const uint16_t offsets_counter_clockwise[24] = {
|
|
|
|
0, (u16)(0 + 2), (u16)(0 + 1),
|
|
|
|
1, (u16)(1 + 1), (u16)(1 + 2),
|
|
|
|
2, (u16)(2 + 2), (u16)(2 + 1),
|
|
|
|
3, (u16)(3 + 1), (u16)(3 + 2),
|
|
|
|
4, (u16)(4 + 2), (u16)(4 + 1),
|
|
|
|
5, (u16)(5 + 1), (u16)(5 + 2),
|
|
|
|
6, (u16)(6 + 2), (u16)(6 + 1),
|
|
|
|
7, (u16)(7 + 1), (u16)(7 + 2),
|
|
|
|
};
|
|
|
|
|
2023-10-02 09:25:27 +00:00
|
|
|
void IndexGenerator::AddStrip(int numVerts, int indexOffset, bool clockwise) {
|
2020-09-23 23:56:20 +00:00
|
|
|
int numTris = numVerts - 2;
|
2023-11-02 02:07:40 +00:00
|
|
|
if (numTris <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
2020-09-23 23:56:20 +00:00
|
|
|
#ifdef _M_SSE
|
|
|
|
// In an SSE2 register we can fit 8 16-bit integers.
|
|
|
|
// However, we need to output a multiple of 3 indices.
|
|
|
|
// The first such multiple is 24, which means we'll generate 24 indices per cycle,
|
|
|
|
// which corresponds to 8 triangles. That's pretty cool.
|
|
|
|
|
2020-09-24 07:36:39 +00:00
|
|
|
// We allow ourselves to write some extra indices to avoid the fallback loop.
|
|
|
|
// That's alright as we're appending to a buffer - they will get overwritten anyway.
|
2023-10-02 09:25:27 +00:00
|
|
|
__m128i ibase8 = _mm_set1_epi16(indexOffset);
|
2020-09-24 08:03:07 +00:00
|
|
|
const __m128i *offsets = (const __m128i *)(clockwise ? offsets_clockwise : offsets_counter_clockwise);
|
|
|
|
__m128i *dst = (__m128i *)inds_;
|
2023-06-13 09:35:26 +00:00
|
|
|
__m128i offsets0 = _mm_add_epi16(ibase8, _mm_load_si128(offsets));
|
|
|
|
// A single store is always enough for two triangles, which is a very common case.
|
2023-05-29 22:37:01 +00:00
|
|
|
_mm_storeu_si128(dst, offsets0);
|
2023-06-13 09:35:26 +00:00
|
|
|
if (numTris > 2) {
|
|
|
|
__m128i offsets1 = _mm_add_epi16(ibase8, _mm_load_si128(offsets + 1));
|
2023-05-29 22:37:01 +00:00
|
|
|
_mm_storeu_si128(dst + 1, offsets1);
|
2023-06-13 09:35:26 +00:00
|
|
|
if (numTris > 5) {
|
|
|
|
__m128i offsets2 = _mm_add_epi16(ibase8, _mm_load_si128(offsets + 2));
|
|
|
|
_mm_storeu_si128(dst + 2, offsets2);
|
|
|
|
__m128i increment = _mm_set1_epi16(8);
|
2023-11-02 03:30:04 +00:00
|
|
|
int numChunks = (numTris + 7) >> 3;
|
2023-06-13 09:35:26 +00:00
|
|
|
for (int i = 1; i < numChunks; i++) {
|
|
|
|
dst += 3;
|
|
|
|
offsets0 = _mm_add_epi16(offsets0, increment);
|
|
|
|
offsets1 = _mm_add_epi16(offsets1, increment);
|
|
|
|
offsets2 = _mm_add_epi16(offsets2, increment);
|
|
|
|
_mm_storeu_si128(dst, offsets0);
|
|
|
|
_mm_storeu_si128(dst + 1, offsets1);
|
|
|
|
_mm_storeu_si128(dst + 2, offsets2);
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 23:56:20 +00:00
|
|
|
}
|
2020-09-24 08:03:07 +00:00
|
|
|
inds_ += numTris * 3;
|
2020-09-23 23:56:20 +00:00
|
|
|
// wind doesn't need to be updated, an even number of triangles have been drawn.
|
2020-09-24 07:24:03 +00:00
|
|
|
#elif PPSSPP_ARCH(ARM_NEON)
|
2023-10-02 09:25:27 +00:00
|
|
|
uint16x8_t ibase8 = vdupq_n_u16(indexOffset);
|
2020-09-24 08:03:07 +00:00
|
|
|
const u16 *offsets = clockwise ? offsets_clockwise : offsets_counter_clockwise;
|
|
|
|
u16 *dst = inds_;
|
2023-06-13 09:38:45 +00:00
|
|
|
uint16x8_t offsets0 = vaddq_u16(ibase8, vld1q_u16(offsets));
|
|
|
|
vst1q_u16(dst, offsets0);
|
2023-06-13 09:47:31 +00:00
|
|
|
if (numTris > 2) {
|
|
|
|
uint16x8_t offsets1 = vaddq_u16(ibase8, vld1q_u16(offsets + 8));
|
2023-06-13 09:38:45 +00:00
|
|
|
vst1q_u16(dst + 8, offsets1);
|
2023-06-13 09:47:31 +00:00
|
|
|
if (numTris > 5) {
|
|
|
|
uint16x8_t offsets2 = vaddq_u16(ibase8, vld1q_u16(offsets + 16));
|
|
|
|
vst1q_u16(dst + 16, offsets2);
|
|
|
|
uint16x8_t increment = vdupq_n_u16(8);
|
2023-11-02 03:30:04 +00:00
|
|
|
int numChunks = (numTris + 7) >> 3;
|
2023-06-13 09:47:31 +00:00
|
|
|
for (int i = 1; i < numChunks; i++) {
|
|
|
|
dst += 3 * 8;
|
|
|
|
offsets0 = vaddq_u16(offsets0, increment);
|
|
|
|
offsets1 = vaddq_u16(offsets1, increment);
|
|
|
|
offsets2 = vaddq_u16(offsets2, increment);
|
|
|
|
vst1q_u16(dst, offsets0);
|
|
|
|
vst1q_u16(dst + 8, offsets1);
|
|
|
|
vst1q_u16(dst + 16, offsets2);
|
|
|
|
}
|
|
|
|
}
|
2020-09-24 07:24:03 +00:00
|
|
|
}
|
2020-09-24 08:03:07 +00:00
|
|
|
inds_ += numTris * 3;
|
2020-09-24 07:36:39 +00:00
|
|
|
#else
|
|
|
|
// Slow fallback loop.
|
2020-09-24 08:03:07 +00:00
|
|
|
int wind = clockwise ? 1 : 2;
|
2023-10-02 09:25:27 +00:00
|
|
|
int ibase = indexOffset;
|
2020-09-24 08:03:07 +00:00
|
|
|
size_t numPairs = numTris / 2;
|
|
|
|
u16 *outInds = inds_;
|
2020-09-16 07:21:42 +00:00
|
|
|
while (numPairs > 0) {
|
|
|
|
*outInds++ = ibase;
|
|
|
|
*outInds++ = ibase + wind;
|
|
|
|
*outInds++ = ibase + (wind ^ 3);
|
|
|
|
*outInds++ = ibase + 1;
|
|
|
|
*outInds++ = ibase + 1 + (wind ^ 3);
|
|
|
|
*outInds++ = ibase + 1 + wind;
|
|
|
|
ibase += 2;
|
|
|
|
numPairs--;
|
|
|
|
}
|
|
|
|
if (numTris & 1) {
|
2013-11-05 06:49:28 +00:00
|
|
|
*outInds++ = ibase;
|
|
|
|
*outInds++ = ibase + wind;
|
2013-10-07 19:13:52 +00:00
|
|
|
wind ^= 3; // toggle between 1 and 2
|
2013-11-05 06:49:28 +00:00
|
|
|
*outInds++ = ibase + wind;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2020-09-24 08:03:07 +00:00
|
|
|
inds_ = outInds;
|
2020-09-24 07:36:39 +00:00
|
|
|
#endif
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 09:25:27 +00:00
|
|
|
void IndexGenerator::AddFan(int numVerts, int indexOffset, bool clockwise) {
|
2013-11-05 06:49:28 +00:00
|
|
|
const int numTris = numVerts - 2;
|
|
|
|
u16 *outInds = inds_;
|
2018-06-03 14:29:50 +00:00
|
|
|
const int v1 = clockwise ? 1 : 2;
|
|
|
|
const int v2 = clockwise ? 2 : 1;
|
2013-08-17 09:23:51 +00:00
|
|
|
for (int i = 0; i < numTris; i++) {
|
2023-10-02 09:25:27 +00:00
|
|
|
*outInds++ = indexOffset;
|
|
|
|
*outInds++ = indexOffset + i + v1;
|
|
|
|
*outInds++ = indexOffset + i + v2;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-11-05 06:49:28 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Lines
|
2023-10-02 09:25:27 +00:00
|
|
|
void IndexGenerator::AddLineList(int numVerts, int indexOffset) {
|
2013-11-05 06:49:28 +00:00
|
|
|
u16 *outInds = inds_;
|
2024-02-12 17:03:39 +00:00
|
|
|
numVerts &= ~1;
|
2013-10-01 16:02:09 +00:00
|
|
|
for (int i = 0; i < numVerts; i += 2) {
|
2023-10-02 09:25:27 +00:00
|
|
|
*outInds++ = indexOffset + i;
|
|
|
|
*outInds++ = indexOffset + i + 1;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-11-05 06:49:28 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 09:25:27 +00:00
|
|
|
void IndexGenerator::AddLineStrip(int numVerts, int indexOffset) {
|
2013-11-05 06:49:28 +00:00
|
|
|
const int numLines = numVerts - 1;
|
|
|
|
u16 *outInds = inds_;
|
2013-08-17 09:23:51 +00:00
|
|
|
for (int i = 0; i < numLines; i++) {
|
2023-10-02 09:25:27 +00:00
|
|
|
*outInds++ = indexOffset + i;
|
|
|
|
*outInds++ = indexOffset + i + 1;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-11-05 06:49:28 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 09:25:27 +00:00
|
|
|
void IndexGenerator::AddRectangles(int numVerts, int indexOffset) {
|
2013-11-05 06:49:28 +00:00
|
|
|
u16 *outInds = inds_;
|
2015-02-02 21:30:47 +00:00
|
|
|
//rectangles always need 2 vertices, disregard the last one if there's an odd number
|
|
|
|
numVerts = numVerts & ~1;
|
|
|
|
for (int i = 0; i < numVerts; i += 2) {
|
2023-10-02 09:25:27 +00:00
|
|
|
*outInds++ = indexOffset + i;
|
|
|
|
*outInds++ = indexOffset + i + 1;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-11-05 06:49:28 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 10:43:10 +00:00
|
|
|
template <class ITypeLE>
|
2016-04-10 08:52:51 +00:00
|
|
|
void IndexGenerator::TranslatePoints(int numInds, const ITypeLE *inds, int indexOffset) {
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
2013-08-17 09:23:51 +00:00
|
|
|
for (int i = 0; i < numInds; i++)
|
2013-10-07 19:35:22 +00:00
|
|
|
*outInds++ = indexOffset + inds[i];
|
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 10:43:10 +00:00
|
|
|
template <class ITypeLE>
|
2016-04-10 08:52:51 +00:00
|
|
|
void IndexGenerator::TranslateLineList(int numInds, const ITypeLE *inds, int indexOffset) {
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
2016-04-10 08:59:23 +00:00
|
|
|
numInds = numInds & ~1;
|
|
|
|
for (int i = 0; i < numInds; i += 2) {
|
2013-10-07 19:35:22 +00:00
|
|
|
*outInds++ = indexOffset + inds[i];
|
|
|
|
*outInds++ = indexOffset + inds[i + 1];
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-10-07 19:35:22 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 10:43:10 +00:00
|
|
|
template <class ITypeLE>
|
2016-04-10 08:52:51 +00:00
|
|
|
void IndexGenerator::TranslateLineStrip(int numInds, const ITypeLE *inds, int indexOffset) {
|
2016-04-10 08:59:23 +00:00
|
|
|
int numLines = numInds - 1;
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
2016-04-10 08:59:23 +00:00
|
|
|
for (int i = 0; i < numLines; i++) {
|
2013-10-07 19:35:22 +00:00
|
|
|
*outInds++ = indexOffset + inds[i];
|
|
|
|
*outInds++ = indexOffset + inds[i + 1];
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-10-07 19:35:22 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 10:43:10 +00:00
|
|
|
template <class ITypeLE>
|
2018-06-05 02:39:40 +00:00
|
|
|
void IndexGenerator::TranslateList(int numInds, const ITypeLE *inds, int indexOffset, bool clockwise) {
|
2017-06-02 10:03:46 +00:00
|
|
|
// We only bother doing this minor optimization in triangle list, since it's by far the most
|
|
|
|
// common operation that can benefit.
|
2018-11-30 03:03:38 +00:00
|
|
|
if (sizeof(ITypeLE) == sizeof(inds_[0]) && indexOffset == 0 && clockwise) {
|
2017-06-02 10:03:46 +00:00
|
|
|
memcpy(inds_, inds, numInds * sizeof(ITypeLE));
|
|
|
|
inds_ += numInds;
|
|
|
|
} else {
|
|
|
|
u16 *outInds = inds_;
|
|
|
|
int numTris = numInds / 3; // Round to whole triangles
|
|
|
|
numInds = numTris * 3;
|
2018-06-05 02:39:40 +00:00
|
|
|
const int v1 = clockwise ? 1 : 2;
|
|
|
|
const int v2 = clockwise ? 2 : 1;
|
2023-10-02 09:25:27 +00:00
|
|
|
// TODO: This can actually be SIMD-d, although will need complex shuffles if clockwise.
|
2017-06-02 10:03:46 +00:00
|
|
|
for (int i = 0; i < numInds; i += 3) {
|
|
|
|
*outInds++ = indexOffset + inds[i];
|
2018-06-05 02:39:40 +00:00
|
|
|
*outInds++ = indexOffset + inds[i + v1];
|
|
|
|
*outInds++ = indexOffset + inds[i + v2];
|
2017-06-02 10:03:46 +00:00
|
|
|
}
|
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-06 10:43:10 +00:00
|
|
|
template <class ITypeLE>
|
2018-04-27 13:49:43 +00:00
|
|
|
void IndexGenerator::TranslateStrip(int numInds, const ITypeLE *inds, int indexOffset, bool clockwise) {
|
|
|
|
int wind = clockwise ? 1 : 2;
|
2013-08-17 09:23:51 +00:00
|
|
|
int numTris = numInds - 2;
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
2013-08-17 09:23:51 +00:00
|
|
|
for (int i = 0; i < numTris; i++) {
|
2013-10-07 19:35:22 +00:00
|
|
|
*outInds++ = indexOffset + inds[i];
|
|
|
|
*outInds++ = indexOffset + inds[i + wind];
|
2013-10-07 19:13:52 +00:00
|
|
|
wind ^= 3; // Toggle between 1 and 2
|
2013-10-07 19:35:22 +00:00
|
|
|
*outInds++ = indexOffset + inds[i + wind];
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-10-07 19:35:22 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 10:43:10 +00:00
|
|
|
template <class ITypeLE>
|
2018-06-03 14:29:50 +00:00
|
|
|
void IndexGenerator::TranslateFan(int numInds, const ITypeLE *inds, int indexOffset, bool clockwise) {
|
2013-08-17 09:23:51 +00:00
|
|
|
if (numInds <= 0) return;
|
|
|
|
int numTris = numInds - 2;
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
2018-06-03 14:29:50 +00:00
|
|
|
const int v1 = clockwise ? 1 : 2;
|
|
|
|
const int v2 = clockwise ? 2 : 1;
|
2013-08-17 09:23:51 +00:00
|
|
|
for (int i = 0; i < numTris; i++) {
|
2013-10-07 19:35:22 +00:00
|
|
|
*outInds++ = indexOffset + inds[0];
|
2018-06-03 14:50:35 +00:00
|
|
|
*outInds++ = indexOffset + inds[i + v1];
|
|
|
|
*outInds++ = indexOffset + inds[i + v2];
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-10-07 19:35:22 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 10:43:10 +00:00
|
|
|
template <class ITypeLE>
|
2016-04-10 08:52:51 +00:00
|
|
|
inline void IndexGenerator::TranslateRectangles(int numInds, const ITypeLE *inds, int indexOffset) {
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
2016-04-10 08:59:23 +00:00
|
|
|
//rectangles always need 2 vertices, disregard the last one if there's an odd number
|
2015-02-11 20:53:20 +00:00
|
|
|
numInds = numInds & ~1;
|
2013-10-01 16:02:09 +00:00
|
|
|
for (int i = 0; i < numInds; i += 2) {
|
2013-10-07 19:35:22 +00:00
|
|
|
*outInds++ = indexOffset + inds[i];
|
|
|
|
*outInds++ = indexOffset + inds[i+1];
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-10-07 19:35:22 +00:00
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:59:23 +00:00
|
|
|
// Could template this too, but would have to define in header.
|
2018-04-27 13:49:43 +00:00
|
|
|
void IndexGenerator::TranslatePrim(int prim, int numInds, const u8 *inds, int indexOffset, bool clockwise) {
|
2016-04-10 08:59:23 +00:00
|
|
|
switch (prim) {
|
2023-10-06 10:43:10 +00:00
|
|
|
case GE_PRIM_POINTS: TranslatePoints<u8>(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_LINES: TranslateLineList<u8>(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_LINE_STRIP: TranslateLineStrip<u8>(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_TRIANGLES: TranslateList<u8>(numInds, inds, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_TRIANGLE_STRIP: TranslateStrip<u8>(numInds, inds, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_TRIANGLE_FAN: TranslateFan<u8>(numInds, inds, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_RECTANGLES: TranslateRectangles<u8>(numInds, inds, indexOffset); break; // Same
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 13:49:43 +00:00
|
|
|
void IndexGenerator::TranslatePrim(int prim, int numInds, const u16_le *inds, int indexOffset, bool clockwise) {
|
2016-04-10 08:59:23 +00:00
|
|
|
switch (prim) {
|
2023-10-06 10:43:10 +00:00
|
|
|
case GE_PRIM_POINTS: TranslatePoints<u16_le>(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_LINES: TranslateLineList<u16_le>(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_LINE_STRIP: TranslateLineStrip<u16_le>(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_TRIANGLES: TranslateList<u16_le>(numInds, inds, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_TRIANGLE_STRIP: TranslateStrip<u16_le>(numInds, inds, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_TRIANGLE_FAN: TranslateFan<u16_le>(numInds, inds, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_RECTANGLES: TranslateRectangles<u16_le>(numInds, inds, indexOffset); break; // Same
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 13:49:43 +00:00
|
|
|
void IndexGenerator::TranslatePrim(int prim, int numInds, const u32_le *inds, int indexOffset, bool clockwise) {
|
2016-04-10 08:59:23 +00:00
|
|
|
switch (prim) {
|
2023-10-06 10:43:10 +00:00
|
|
|
case GE_PRIM_POINTS: TranslatePoints<u32_le>(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_LINES: TranslateLineList<u32_le>(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_LINE_STRIP: TranslateLineStrip<u32_le>(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_TRIANGLES: TranslateList<u32_le>(numInds, inds, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_TRIANGLE_STRIP: TranslateStrip<u32_le>(numInds, inds, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_TRIANGLE_FAN: TranslateFan<u32_le>(numInds, inds, indexOffset, clockwise); break;
|
|
|
|
case GE_PRIM_RECTANGLES: TranslateRectangles<u32_le>(numInds, inds, indexOffset); break; // Same
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2016-04-10 08:52:51 +00:00
|
|
|
}
|