CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Common/IndexGenerator.h
Views: 1401
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
void Reset() {
29
this->inds_ = indsBase_;
30
}
31
32
static bool PrimCompatible(int prim1, int prim2) {
33
if (prim1 == GE_PRIM_INVALID || prim2 == GE_PRIM_KEEP_PREVIOUS)
34
return true;
35
return indexedPrimitiveType[prim1] == indexedPrimitiveType[prim2];
36
}
37
38
static GEPrimitiveType GeneralPrim(GEPrimitiveType prim) {
39
switch (prim) {
40
case GE_PRIM_LINE_STRIP: return GE_PRIM_LINES; break;
41
case GE_PRIM_TRIANGLE_STRIP:
42
case GE_PRIM_TRIANGLE_FAN: return GE_PRIM_TRIANGLES; break;
43
default:
44
return prim;
45
}
46
}
47
48
void AddPrim(int prim, int vertexCount, int indexOffset, bool clockwise);
49
void TranslatePrim(int prim, int numInds, const u8 *inds, int indexOffset, bool clockwise);
50
void TranslatePrim(int prim, int numInds, const u16_le *inds, int indexOffset, bool clockwise);
51
void TranslatePrim(int prim, int numInds, const u32_le *inds, int indexOffset, bool clockwise);
52
53
// This is really the number of generated indices, or 3x the number of triangles.
54
int VertexCount() const { return inds_ - indsBase_; }
55
56
private:
57
// Points (why index these? code simplicity)
58
void AddPoints(int numVerts, int indexOffset);
59
// Triangles
60
void AddList(int numVerts, int indexOffset, bool clockwise);
61
void AddStrip(int numVerts, int indexOffset, bool clockwise);
62
void AddFan(int numVerts, int indexOffset, bool clockwise);
63
// Lines
64
void AddLineList(int numVerts, int indexOffset);
65
void AddLineStrip(int numVerts, int indexOffset);
66
// Rectangles
67
void AddRectangles(int numVerts, int indexOffset);
68
69
// These translate already indexed lists
70
template <class ITypeLE>
71
void TranslatePoints(int numVerts, const ITypeLE *inds, int indexOffset);
72
template <class ITypeLE>
73
void TranslateList(int numVerts, const ITypeLE *inds, int indexOffset, bool clockwise);
74
template <class ITypeLE>
75
inline void TranslateLineList(int numVerts, const ITypeLE *inds, int indexOffset);
76
template <class ITypeLE>
77
inline void TranslateLineStrip(int numVerts, const ITypeLE *inds, int indexOffset);
78
79
template <class ITypeLE>
80
void TranslateStrip(int numVerts, const ITypeLE *inds, int indexOffset, bool clockwise);
81
template <class ITypeLE>
82
void TranslateFan(int numVerts, const ITypeLE *inds, int indexOffset, bool clockwise);
83
84
template <class ITypeLE>
85
inline void TranslateRectangles(int numVerts, const ITypeLE *inds, int indexOffset);
86
87
u16 *indsBase_;
88
u16 *inds_;
89
90
static const u8 indexedPrimitiveType[7];
91
};
92
93
94