-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderDriverOpenGL1_DrawBvhLevels.cpp
174 lines (122 loc) · 4.39 KB
/
RenderDriverOpenGL1_DrawBvhLevels.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "HydraRenderDriverAPI.h"
#include "RenderDriverOpenGL1.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include "LiteMath.h"
using namespace LiteMath;
#include <cassert>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#define MAX_BVH_LEVELS 32
int g_drawBVHIdInput = 0;
static void glutWireCube(GLdouble dSize)
{
float s = float(dSize * 0.5f);
glBegin(GL_LINE_LOOP); glVertex3d(+s, -s, +s); glVertex3d(+s, -s, -s); glVertex3d(+s, +s, -s); glVertex3d(+s, +s, +s); glEnd();
glBegin(GL_LINE_LOOP); glVertex3d(+s, +s, +s); glVertex3d(+s, +s, -s); glVertex3d(-s, +s, -s); glVertex3d(-s, +s, +s); glEnd();
glBegin(GL_LINE_LOOP); glVertex3d(+s, +s, +s); glVertex3d(-s, +s, +s); glVertex3d(-s, -s, +s); glVertex3d(+s, -s, +s); glEnd();
glBegin(GL_LINE_LOOP); glVertex3d(-s, -s, +s); glVertex3d(-s, +s, +s); glVertex3d(-s, +s, -s); glVertex3d(-s, -s, -s); glEnd();
glBegin(GL_LINE_LOOP); glVertex3d(-s, -s, +s); glVertex3d(-s, -s, -s); glVertex3d(+s, -s, -s); glVertex3d(+s, -s, +s); glEnd();
glBegin(GL_LINE_LOOP); glVertex3d(-s, -s, -s); glVertex3d(-s, +s, -s); glVertex3d(+s, +s, -s); glVertex3d(+s, -s, -s); glEnd();
}
static void DrawBox(const float4 a_boxMin, const float4 a_boxMax)
{
const float4 scale = a_boxMax - a_boxMin;
const float4 cent = a_boxMin + 0.5f*scale;
glPushMatrix();
glTranslatef(cent.x, cent.y, cent.z);
glScalef(scale.x, scale.y, scale.z);
glutWireCube(1);
glPopMatrix();
}
struct RD_OGL1_DebugDrawBVH : public RD_OGL1_Debug
{
typedef RD_OGL1_Debug Base;
RD_OGL1_DebugDrawBVH();
~RD_OGL1_DebugDrawBVH() override { glDeleteLists(m_boxesDisplayLists, MAX_BVH_LEVELS); }
void GetRenderDriverName(std::wstring &name) override { name = std::wstring(L"opengl1DrawBvh");};
void BeginScene(pugi::xml_node a_sceneNode) override;
void EndScene() override;
protected:
void LoadRays();
GLuint m_boxesDisplayLists;
int m_numDebugRays;
};
IHRRenderDriver* CreateOpenGL1DrawBVH_RenderDriver()
{
return new RD_OGL1_DebugDrawBVH;
}
RD_OGL1_DebugDrawBVH::RD_OGL1_DebugDrawBVH() : m_numDebugRays(0), m_boxesDisplayLists(0)
{
m_boxesDisplayLists = glGenLists(GLsizei(MAX_BVH_LEVELS));
LoadRays();
}
void RD_OGL1_DebugDrawBVH::BeginScene(pugi::xml_node a_sceneNode)
{
Base::BeginScene(a_sceneNode);
}
void RD_OGL1_DebugDrawBVH::EndScene()
{
Base::EndScene();
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glColor3f(0, 1, 0);
glCallList(m_boxesDisplayLists + g_drawBVHIdInput);
}
void RD_OGL1_DebugDrawBVH::LoadRays()
{
bool fileIsOpened = false;
int currLevel = 1;
std::string path = "D:/temp/bvh_layers2";
m_numDebugRays = 0;
do
{
std::stringstream fileNameStream;
fileNameStream << path.c_str() << "/level_" << currLevel << ".array4f";
std::stringstream fileNameStream2;
fileNameStream2 << path.c_str() << "/matrix_level_" << currLevel << ".array4f";
const std::string fileName1 = fileNameStream.str();
const std::string fileName2 = fileNameStream2.str();
std::cout << "loading level = " << currLevel << std::endl;
int arraySize = 0;
int arraySize2 = 0;
std::ifstream fin(fileName1.c_str(), std::ios::binary);
std::ifstream fin2(fileName2.c_str(), std::ios::binary);
fileIsOpened = fin.is_open();
if (fileIsOpened)
{
fin.read((char*)&arraySize, sizeof(int));
fin2.read((char*)&arraySize2, sizeof(int));
assert(arraySize2 == arraySize*2);
std::vector<float4> boxesData(arraySize);
fin.read((char*)&boxesData[0], boxesData.size() * sizeof(float4));
std::vector<float4x4> matrixData(arraySize/2);
fin2.read((char*)&matrixData[0], matrixData.size() * sizeof(float4x4));
fin.close();
fin2.close();
glNewList(m_boxesDisplayLists + GLuint(m_numDebugRays), GL_COMPILE);
for (size_t i = 0; i < boxesData.size(); i += 2)
{
float4 boxMin = boxesData[i + 0];
float4 boxMax = boxesData[i + 1];
float4x4 matrixT = transpose(matrixData[i / 2]);
glPushMatrix();
glMultMatrixf(matrixT.L());
DrawBox(boxMin, boxMax);
glPopMatrix();
}
glEndList();
}
currLevel++;
m_numDebugRays++;
if (currLevel >= 22)
{
m_numDebugRays++;
break;
}
} while (fileIsOpened && m_numDebugRays < MAX_BVH_LEVELS);
std::cout << "after loading bvh levels ... " << std::endl;
}