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/.
|
|
|
|
|
|
|
|
#include "IndexGenerator.h"
|
|
|
|
|
|
|
|
#include "Common/Common.h"
|
|
|
|
|
|
|
|
// Points don't need indexing...
|
|
|
|
static const u8 indexedPrimitiveType[7] = {
|
|
|
|
GE_PRIM_POINTS,
|
|
|
|
GE_PRIM_LINES,
|
|
|
|
GE_PRIM_LINES,
|
|
|
|
GE_PRIM_TRIANGLES,
|
|
|
|
GE_PRIM_TRIANGLES,
|
|
|
|
GE_PRIM_TRIANGLES,
|
|
|
|
GE_PRIM_RECTANGLES,
|
|
|
|
};
|
|
|
|
|
|
|
|
void IndexGenerator::Reset() {
|
2013-09-04 09:19:36 +00:00
|
|
|
prim_ = GE_PRIM_INVALID;
|
2013-08-17 09:23:51 +00:00
|
|
|
count_ = 0;
|
|
|
|
index_ = 0;
|
|
|
|
seenPrims_ = 0;
|
|
|
|
pureCount_ = 0;
|
|
|
|
this->inds_ = indsBase_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexGenerator::PrimCompatible(int prim1, int prim2) {
|
2015-01-17 21:09:25 +00:00
|
|
|
if (prim1 == GE_PRIM_INVALID || prim2 == GE_PRIM_KEEP_PREVIOUS)
|
2013-08-17 09:23:51 +00:00
|
|
|
return true;
|
|
|
|
return indexedPrimitiveType[prim1] == indexedPrimitiveType[prim2];
|
|
|
|
}
|
|
|
|
|
2014-12-07 22:00:14 +00:00
|
|
|
bool IndexGenerator::PrimCompatible(int prim) const {
|
2015-01-17 21:09:25 +00:00
|
|
|
if (prim_ == GE_PRIM_INVALID || prim == GE_PRIM_KEEP_PREVIOUS)
|
2013-08-17 09:23:51 +00:00
|
|
|
return true;
|
|
|
|
return indexedPrimitiveType[prim] == prim_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::Setup(u16 *inds) {
|
|
|
|
this->indsBase_ = inds;
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::AddPrim(int prim, int vertexCount) {
|
|
|
|
switch (prim) {
|
|
|
|
case GE_PRIM_POINTS: AddPoints(vertexCount); break;
|
|
|
|
case GE_PRIM_LINES: AddLineList(vertexCount); break;
|
|
|
|
case GE_PRIM_LINE_STRIP: AddLineStrip(vertexCount); break;
|
|
|
|
case GE_PRIM_TRIANGLES: AddList(vertexCount); break;
|
|
|
|
case GE_PRIM_TRIANGLE_STRIP: AddStrip(vertexCount); break;
|
|
|
|
case GE_PRIM_TRIANGLE_FAN: AddFan(vertexCount); break;
|
|
|
|
case GE_PRIM_RECTANGLES: AddRectangles(vertexCount); break; // Same
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::AddPoints(int numVerts) {
|
2013-11-05 06:49:28 +00:00
|
|
|
u16 *outInds = inds_;
|
|
|
|
const int startIndex = index_;
|
2013-08-17 09:23:51 +00:00
|
|
|
for (int i = 0; i < numVerts; i++)
|
2013-11-05 06:49:28 +00:00
|
|
|
*outInds++ = startIndex + i;
|
|
|
|
inds_ = outInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
// ignore overflow verts
|
|
|
|
index_ += numVerts;
|
|
|
|
count_ += numVerts;
|
|
|
|
prim_ = GE_PRIM_POINTS;
|
|
|
|
seenPrims_ |= 1 << GE_PRIM_POINTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::AddList(int numVerts) {
|
2013-11-05 06:49:28 +00:00
|
|
|
u16 *outInds = inds_;
|
|
|
|
const int startIndex = index_;
|
2013-10-01 16:02:09 +00:00
|
|
|
for (int i = 0; i < numVerts; i += 3) {
|
2013-11-05 06:49:28 +00:00
|
|
|
*outInds++ = startIndex + i;
|
|
|
|
*outInds++ = startIndex + i + 1;
|
|
|
|
*outInds++ = startIndex + i + 2;
|
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
|
|
|
// ignore overflow verts
|
|
|
|
index_ += numVerts;
|
2013-10-01 16:02:09 +00:00
|
|
|
count_ += numVerts;
|
2013-08-17 09:23:51 +00:00
|
|
|
prim_ = GE_PRIM_TRIANGLES;
|
|
|
|
seenPrims_ |= 1 << GE_PRIM_TRIANGLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::AddStrip(int numVerts) {
|
2013-10-07 19:13:52 +00:00
|
|
|
int wind = 1;
|
2013-11-05 06:49:28 +00:00
|
|
|
const int numTris = numVerts - 2;
|
|
|
|
u16 *outInds = inds_;
|
2013-11-08 11:29:39 +00:00
|
|
|
int ibase = index_;
|
2013-11-09 18:33:40 +00:00
|
|
|
for (int i = 0; i < numTris; i++) {
|
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-11-08 11:29:39 +00:00
|
|
|
ibase++;
|
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
|
|
|
index_ += numVerts;
|
2013-11-10 00:23:31 +00:00
|
|
|
if (numTris > 0)
|
|
|
|
count_ += numTris * 3;
|
2013-08-17 09:23:51 +00:00
|
|
|
// This is so we can detect one single strip by just looking at seenPrims_.
|
|
|
|
if (!seenPrims_) {
|
|
|
|
seenPrims_ = 1 << GE_PRIM_TRIANGLE_STRIP;
|
|
|
|
prim_ = GE_PRIM_TRIANGLE_STRIP;
|
|
|
|
pureCount_ = numVerts;
|
|
|
|
} else {
|
2015-01-10 23:09:17 +00:00
|
|
|
seenPrims_ |= (1 << GE_PRIM_TRIANGLE_STRIP) | (1 << GE_PRIM_TRIANGLES);
|
2013-08-17 09:23:51 +00:00
|
|
|
prim_ = GE_PRIM_TRIANGLES;
|
|
|
|
pureCount_ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::AddFan(int numVerts) {
|
2013-11-05 06:49:28 +00:00
|
|
|
const int numTris = numVerts - 2;
|
|
|
|
u16 *outInds = inds_;
|
|
|
|
const int startIndex = index_;
|
2013-08-17 09:23:51 +00:00
|
|
|
for (int i = 0; i < numTris; i++) {
|
2013-11-05 06:49:28 +00:00
|
|
|
*outInds++ = startIndex;
|
|
|
|
*outInds++ = startIndex + i + 1;
|
|
|
|
*outInds++ = startIndex + i + 2;
|
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
|
|
|
index_ += numVerts;
|
|
|
|
count_ += numTris * 3;
|
|
|
|
prim_ = GE_PRIM_TRIANGLES;
|
|
|
|
seenPrims_ |= 1 << GE_PRIM_TRIANGLE_FAN;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Lines
|
|
|
|
void IndexGenerator::AddLineList(int numVerts) {
|
2013-11-05 06:49:28 +00:00
|
|
|
u16 *outInds = inds_;
|
|
|
|
const int startIndex = index_;
|
2013-10-01 16:02:09 +00:00
|
|
|
for (int i = 0; i < numVerts; i += 2) {
|
2013-11-05 06:49:28 +00:00
|
|
|
*outInds++ = startIndex + i;
|
|
|
|
*outInds++ = startIndex + 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
|
|
|
index_ += numVerts;
|
2013-10-01 16:02:09 +00:00
|
|
|
count_ += numVerts;
|
2013-08-17 09:23:51 +00:00
|
|
|
prim_ = GE_PRIM_LINES;
|
|
|
|
seenPrims_ |= 1 << prim_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::AddLineStrip(int numVerts) {
|
2013-11-05 06:49:28 +00:00
|
|
|
const int numLines = numVerts - 1;
|
|
|
|
u16 *outInds = inds_;
|
|
|
|
const int startIndex = index_;
|
2013-08-17 09:23:51 +00:00
|
|
|
for (int i = 0; i < numLines; i++) {
|
2013-11-05 06:49:28 +00:00
|
|
|
*outInds++ = startIndex + i;
|
|
|
|
*outInds++ = startIndex + 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
|
|
|
index_ += numVerts;
|
|
|
|
count_ += numLines * 2;
|
|
|
|
prim_ = GE_PRIM_LINES;
|
|
|
|
seenPrims_ |= 1 << GE_PRIM_LINE_STRIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::AddRectangles(int numVerts) {
|
2013-11-05 06:49:28 +00:00
|
|
|
u16 *outInds = inds_;
|
|
|
|
const int startIndex = index_;
|
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) {
|
2013-11-05 06:49:28 +00:00
|
|
|
*outInds++ = startIndex + i;
|
|
|
|
*outInds++ = startIndex + 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
|
|
|
index_ += numVerts;
|
2013-10-01 16:02:09 +00:00
|
|
|
count_ += numVerts;
|
2013-08-17 09:23:51 +00:00
|
|
|
prim_ = GE_PRIM_RECTANGLES;
|
|
|
|
seenPrims_ |= 1 << GE_PRIM_RECTANGLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslatePrim(int prim, int numInds, const u8 *inds, int indexOffset) {
|
|
|
|
switch (prim) {
|
|
|
|
case GE_PRIM_POINTS: TranslatePoints(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_LINES: TranslateLineList(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_LINE_STRIP: TranslateLineStrip(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_TRIANGLES: TranslateList(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_TRIANGLE_STRIP: TranslateStrip(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_TRIANGLE_FAN: TranslateFan(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_RECTANGLES: TranslateRectangles(numInds, inds, indexOffset); break; // Same
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslatePrim(int prim, int numInds, const u16 *inds, int indexOffset) {
|
|
|
|
switch (prim) {
|
|
|
|
case GE_PRIM_POINTS: TranslatePoints(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_LINES: TranslateLineList(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_LINE_STRIP: TranslateLineStrip(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_TRIANGLES: TranslateList(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_TRIANGLE_STRIP: TranslateStrip(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_TRIANGLE_FAN: TranslateFan(numInds, inds, indexOffset); break;
|
|
|
|
case GE_PRIM_RECTANGLES: TranslateRectangles(numInds, inds, indexOffset); break; // Same
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslatePoints(int numInds, const u8 *inds, int indexOffset) {
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - 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
|
|
|
count_ += numInds;
|
|
|
|
prim_ = GE_PRIM_POINTS;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_POINTS) | SEEN_INDEX8;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslatePoints(int numInds, const u16 *_inds, int indexOffset) {
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
2013-08-17 09:23:51 +00:00
|
|
|
const u16_le *inds = (u16_le*)_inds;
|
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
|
|
|
count_ += numInds;
|
|
|
|
prim_ = GE_PRIM_POINTS;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_POINTS) | SEEN_INDEX16;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateList(int numInds, const u8 *inds, int indexOffset) {
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
2015-02-12 10:44:06 +00:00
|
|
|
int numTris = numInds / 3; // Round to whole triangles
|
|
|
|
numInds = numTris * 3;
|
2013-10-01 16:02:09 +00:00
|
|
|
for (int i = 0; i < numInds; i += 3) {
|
2013-10-07 19:35:22 +00:00
|
|
|
*outInds++ = indexOffset + inds[i];
|
|
|
|
*outInds++ = indexOffset + inds[i + 1];
|
|
|
|
*outInds++ = indexOffset + inds[i + 2];
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-10-07 19:35:22 +00:00
|
|
|
inds_ = outInds;
|
2013-10-01 16:02:09 +00:00
|
|
|
count_ += numInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
prim_ = GE_PRIM_TRIANGLES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_TRIANGLES) | SEEN_INDEX8;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateStrip(int numInds, const u8 *inds, int indexOffset) {
|
2013-10-07 19:13:52 +00:00
|
|
|
int wind = 1;
|
|
|
|
indexOffset = index_ - indexOffset;
|
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
|
|
|
count_ += numTris * 3;
|
|
|
|
prim_ = GE_PRIM_TRIANGLES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_TRIANGLE_STRIP) | SEEN_INDEX8;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateFan(int numInds, const u8 *inds, int indexOffset) {
|
|
|
|
if (numInds <= 0) return;
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
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[0];
|
|
|
|
*outInds++ = indexOffset + inds[i + 1];
|
|
|
|
*outInds++ = indexOffset + inds[i + 2];
|
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
|
|
|
count_ += numTris * 3;
|
|
|
|
prim_ = GE_PRIM_TRIANGLES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_TRIANGLE_FAN) | SEEN_INDEX8;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateList(int numInds, const u16 *_inds, int indexOffset) {
|
|
|
|
const u16_le *inds = (u16_le*)_inds;
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
2015-02-12 10:44:06 +00:00
|
|
|
int numTris = numInds / 3; // Round to whole triangles
|
|
|
|
numInds = numTris * 3;
|
2013-10-01 16:02:09 +00:00
|
|
|
for (int i = 0; i < numInds; i += 3) {
|
2013-10-07 19:35:22 +00:00
|
|
|
*outInds++ = indexOffset + inds[i];
|
|
|
|
*outInds++ = indexOffset + inds[i + 1];
|
|
|
|
*outInds++ = indexOffset + inds[i + 2];
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-10-07 19:35:22 +00:00
|
|
|
inds_ = outInds;
|
2013-10-01 16:02:09 +00:00
|
|
|
count_ += numInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
prim_ = GE_PRIM_TRIANGLES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_TRIANGLES) | SEEN_INDEX16;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateStrip(int numInds, const u16 *_inds, int indexOffset) {
|
|
|
|
const u16_le *inds = (u16_le*)_inds;
|
2013-10-07 19:13:52 +00:00
|
|
|
int wind = 1;
|
|
|
|
indexOffset = index_ - indexOffset;
|
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
|
|
|
count_ += numTris * 3;
|
|
|
|
prim_ = GE_PRIM_TRIANGLES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_TRIANGLE_STRIP) | SEEN_INDEX16;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateFan(int numInds, const u16 *_inds, int indexOffset) {
|
|
|
|
const u16_le *inds = (u16_le*)_inds;
|
|
|
|
if (numInds <= 0) return;
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
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[0];
|
|
|
|
*outInds++ = indexOffset + inds[i + 1];
|
|
|
|
*outInds++ = indexOffset + inds[i + 2];
|
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
|
|
|
count_ += numTris * 3;
|
|
|
|
prim_ = GE_PRIM_TRIANGLES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_TRIANGLE_FAN) | SEEN_INDEX16;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateLineList(int numInds, const u8 *inds, int indexOffset) {
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
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;
|
2015-02-11 20:53:20 +00:00
|
|
|
count_ += numInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
prim_ = GE_PRIM_LINES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_LINES) | SEEN_INDEX8;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateLineStrip(int numInds, const u8 *inds, int indexOffset) {
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
2013-08-17 09:23:51 +00:00
|
|
|
int numLines = numInds - 1;
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
2013-08-17 09:23:51 +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
|
|
|
count_ += numLines * 2;
|
|
|
|
prim_ = GE_PRIM_LINES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_LINE_STRIP) | SEEN_INDEX8;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateLineList(int numInds, const u16 *_inds, int indexOffset) {
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
2013-08-17 09:23:51 +00:00
|
|
|
const u16_le *inds = (u16_le*)_inds;
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
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-10-01 16:02:09 +00:00
|
|
|
count_ += numInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
prim_ = GE_PRIM_LINES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_LINES) | SEEN_INDEX16;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateLineStrip(int numInds, const u16 *_inds, int indexOffset) {
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
2013-08-17 09:23:51 +00:00
|
|
|
const u16_le *inds = (u16_le*)_inds;
|
|
|
|
int numLines = numInds - 1;
|
2013-10-07 19:35:22 +00:00
|
|
|
u16 *outInds = inds_;
|
2013-08-17 09:23:51 +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
|
|
|
count_ += numLines * 2;
|
|
|
|
prim_ = GE_PRIM_LINES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_LINE_STRIP) | SEEN_INDEX16;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateRectangles(int numInds, const u8 *inds, int indexOffset) {
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
2013-10-07 19:35:22 +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
|
|
|
|
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-10-01 16:02:09 +00:00
|
|
|
count_ += numInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
prim_ = GE_PRIM_RECTANGLES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_RECTANGLES) | SEEN_INDEX8;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexGenerator::TranslateRectangles(int numInds, const u16 *_inds, int indexOffset) {
|
2013-10-07 19:13:52 +00:00
|
|
|
indexOffset = index_ - indexOffset;
|
2013-08-17 09:23:51 +00:00
|
|
|
const u16_le *inds = (u16_le*)_inds;
|
2013-10-07 19:35:22 +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
|
|
|
|
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;
|
2015-03-08 03:52:09 +00:00
|
|
|
count_ += numInds;
|
2013-08-17 09:23:51 +00:00
|
|
|
prim_ = GE_PRIM_RECTANGLES;
|
|
|
|
seenPrims_ |= (1 << GE_PRIM_RECTANGLES) | SEEN_INDEX16;
|
|
|
|
}
|