Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Common/IndexGenerator.h
3186 views
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
19
#pragma once
20
21
#include "Common/CommonTypes.h"
22
#include "Common/Swap.h"
23
#include "GPU/ge_constants.h"
24
25
class IndexGenerator {
26
public:
27
void Setup(u16 *indexptr) {
28
indsBase_ = indexptr;
29
inds_ = indexptr;
30
}
31
void Reset() {
32
inds_ = indsBase_;
33
}
34
35
static bool PrimCompatible(int prim1, int prim2) {
36
if (prim1 == GE_PRIM_INVALID || prim2 == GE_PRIM_KEEP_PREVIOUS)
37
return true;
38
return indexedPrimitiveType[prim1] == indexedPrimitiveType[prim2];
39
}
40
41
static GEPrimitiveType GeneralPrim(GEPrimitiveType prim) {
42
switch (prim) {
43
case GE_PRIM_LINE_STRIP: return GE_PRIM_LINES; break;
44
case GE_PRIM_TRIANGLE_STRIP:
45
case GE_PRIM_TRIANGLE_FAN: return GE_PRIM_TRIANGLES; break;
46
default:
47
return prim;
48
}
49
}
50
51
void AddPrim(int prim, int vertexCount, int indexOffset, bool clockwise);
52
void TranslatePrim(int prim, int numInds, const u8 *inds, int indexOffset, bool clockwise);
53
void TranslatePrim(int prim, int numInds, const u16_le *inds, int indexOffset, bool clockwise);
54
void TranslatePrim(int prim, int numInds, const u32_le *inds, int indexOffset, bool clockwise);
55
56
// This is really the number of generated indices, or 3x the number of triangles.
57
int VertexCount() const { return (int)(inds_ - indsBase_); }
58
59
private:
60
// Points (why index these? code simplicity)
61
void AddPoints(int numVerts, int indexOffset);
62
// Triangles
63
void AddList(int numVerts, int indexOffset, bool clockwise);
64
void AddStrip(int numVerts, int indexOffset, bool clockwise);
65
void AddFan(int numVerts, int indexOffset, bool clockwise);
66
// Lines
67
void AddLineList(int numVerts, int indexOffset);
68
void AddLineStrip(int numVerts, int indexOffset);
69
// Rectangles
70
void AddRectangles(int numVerts, int indexOffset);
71
72
// These translate already indexed lists
73
template <class ITypeLE>
74
void TranslatePoints(int numVerts, const ITypeLE *inds, int indexOffset);
75
template <class ITypeLE>
76
void TranslateList(int numVerts, const ITypeLE *inds, int indexOffset, bool clockwise);
77
template <class ITypeLE>
78
inline void TranslateLineList(int numVerts, const ITypeLE *inds, int indexOffset);
79
template <class ITypeLE>
80
inline void TranslateLineStrip(int numVerts, const ITypeLE *inds, int indexOffset);
81
82
template <class ITypeLE>
83
void TranslateStrip(int numVerts, const ITypeLE *inds, int indexOffset, bool clockwise);
84
template <class ITypeLE>
85
void TranslateFan(int numVerts, const ITypeLE *inds, int indexOffset, bool clockwise);
86
87
template <class ITypeLE>
88
inline void TranslateRectangles(int numVerts, const ITypeLE *inds, int indexOffset);
89
90
u16 *indsBase_;
91
u16 *inds_;
92
93
static const u8 indexedPrimitiveType[7];
94
};
95
96
97