-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderDriverOpenGL1_TestCustomAttributes.cpp
120 lines (93 loc) · 3.86 KB
/
RenderDriverOpenGL1_TestCustomAttributes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "HydraRenderDriverAPI.h"
#include "RenderDriverOpenGL1.h"
bool RD_OGL1_ShowCustomAttr::UpdateMesh(int32_t a_meshId, pugi::xml_node a_meshNode, const HRMeshDriverInput& a_input, const HRBatchInfo* a_batchList, int32_t a_listSize)
{
if (a_input.triNum == 0)
{
glNewList(m_displayLists + GLuint(a_meshId), GL_COMPILE);
glEndList();
return true;
}
bool invalidMaterial = m_diffTexId.empty();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// get custom aatrib pointers
const float* color4f = nullptr;
const float* darkness1f = nullptr;
pugi::xml_node colorNode = a_meshNode.child(L"color");
pugi::xml_node darkNode = a_meshNode.child(L"darkness");
if (colorNode != nullptr)
color4f = (float*)(a_input.allData + colorNode.attribute(L"offset").as_int());
if(darkNode != nullptr)
darkness1f = (float*)(a_input.allData + darkNode.attribute(L"offset").as_int());
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
glNewList(m_displayLists + GLuint(a_meshId), GL_COMPILE);
for (int32_t batchId = 0; batchId < a_listSize; batchId++)
{
HRBatchInfo batch = a_batchList[batchId];
const int drawElementsNum = batch.triEnd - batch.triBegin;
float color[3] = { 1,1,1 };
if (!invalidMaterial)
{
if (m_diffTexId[batch.matId] >= 0)
{
int texId = m_diffTexId[batch.matId];
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_texturesList[texId]);
}
else
glDisable(GL_TEXTURE_2D);
color[0] = m_diffColors[batch.matId * 3 + 0];
color[1] = m_diffColors[batch.matId * 3 + 1];
color[2] = m_diffColors[batch.matId * 3 + 2];
glColor3fv(color);
}
else
{
glDisable(GL_TEXTURE_2D);
glColor3f(1.0f, 1.0f, 1.0f);
}
glBegin(GL_TRIANGLES);
for (int triId = batch.triBegin; triId < batch.triBegin + drawElementsNum; triId++)
{
const int v0 = a_input.indices[triId * 3 + 0];
const int v1 = a_input.indices[triId * 3 + 1];
const int v2 = a_input.indices[triId * 3 + 2];
if (color4f != nullptr)
glColor3fv(&color4f[v0 * 4 + 0]);
else if (darkness1f != nullptr)
{
const float mul = darkness1f[v0];
glColor3f(color[0]*mul, color[1] * mul, color[2] * mul);
}
glTexCoord2f(a_input.texcoord2f[v0 * 2 + 0], a_input.texcoord2f[v0 * 2 + 1]);
glNormal3f(a_input.norm4f[v0 * 4 + 0], a_input.norm4f[v0 * 4 + 1], a_input.norm4f[v0 * 4 + 2]);
glVertex3f(a_input.pos4f[v0 * 4 + 0], a_input.pos4f[v0 * 4 + 1], a_input.pos4f[v0 * 4 + 2]);
if (color4f != nullptr)
glColor3fv(&color4f[v1 * 4 + 0]);
else if (darkness1f != nullptr)
{
const float mul = darkness1f[v1];
glColor3f(color[0] * mul, color[1] * mul, color[2] * mul);
}
glTexCoord2f(a_input.texcoord2f[v1 * 2 + 0], a_input.texcoord2f[v1 * 2 + 1]);
glNormal3f(a_input.norm4f[v1 * 4 + 0], a_input.norm4f[v1 * 4 + 1], a_input.norm4f[v1 * 4 + 2]);
glVertex3f(a_input.pos4f[v1 * 4 + 0], a_input.pos4f[v1 * 4 + 1], a_input.pos4f[v1 * 4 + 2]);
if (color4f != nullptr)
glColor3fv(&color4f[v2 * 4 + 0]);
else if (darkness1f != nullptr)
{
const float mul = darkness1f[v2];
glColor3f(color[0] * mul, color[1] * mul, color[2] * mul);
}
glTexCoord2f(a_input.texcoord2f[v2 * 2 + 0], a_input.texcoord2f[v2 * 2 + 1]);
glNormal3f(a_input.norm4f[v2 * 4 + 0], a_input.norm4f[v2 * 4 + 1], a_input.norm4f[v2 * 4 + 2]);
glVertex3f(a_input.pos4f[v2 * 4 + 0], a_input.pos4f[v2 * 4 + 1], a_input.pos4f[v2 * 4 + 2]);
}
glEnd();
}
glEndList();
return true;
}
IHRRenderDriver* CreateOpenGL1Debug_TestCustomAttributes()
{
return new RD_OGL1_ShowCustomAttr;
}