@@ -43,8 +43,6 @@ namespace GLSLPT
43
43
44
44
Renderer::Renderer (Scene *scene, const std::string& shadersDirectory)
45
45
: BVHTex(0 )
46
- , BBoxminTex(0 )
47
- , BBoxmaxTex(0 )
48
46
, vertexIndicesTex(0 )
49
47
, verticesTex(0 )
50
48
, normalsTex(0 )
@@ -78,8 +76,6 @@ namespace GLSLPT
78
76
delete quad;
79
77
80
78
glDeleteTextures (1 , &BVHTex);
81
- glDeleteTextures (1 , &BBoxminTex);
82
- glDeleteTextures (1 , &BBoxmaxTex);
83
79
glDeleteTextures (1 , &vertexIndicesTex);
84
80
glDeleteTextures (1 , &verticesTex);
85
81
glDeleteTextures (1 , &normalsTex);
@@ -108,52 +104,37 @@ namespace GLSLPT
108
104
109
105
quad = new Quad ();
110
106
111
- // Create texture for BVH Tree
107
+ // Create Buffer and Texture for BVH Tree
108
+ glGenBuffers (1 , &BVHBuffer);
109
+ glBindBuffer (GL_TEXTURE_BUFFER, BVHBuffer);
110
+ glBufferData (GL_TEXTURE_BUFFER, sizeof (RadeonRays::BvhTranslator::Node) * scene->bvhTranslator .nodes .size (), &scene->bvhTranslator .nodes [0 ], GL_STATIC_DRAW);
112
111
glGenTextures (1 , &BVHTex);
113
- glBindTexture (GL_TEXTURE_2D, BVHTex);
114
- glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGB32I, scene->bvhTranslator .nodeTexWidth , scene->bvhTranslator .nodeTexWidth , 0 , GL_RGB_INTEGER, GL_INT, &scene->bvhTranslator .nodes [0 ]);
115
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
116
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
117
- glBindTexture (GL_TEXTURE_2D, 0 );
118
-
119
- // Create texture for Bounding boxes
120
- glGenTextures (1 , &BBoxminTex);
121
- glBindTexture (GL_TEXTURE_2D, BBoxminTex);
122
- glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGB32F, scene->bvhTranslator .nodeTexWidth , scene->bvhTranslator .nodeTexWidth , 0 , GL_RGB, GL_FLOAT, &scene->bvhTranslator .bboxmin [0 ]);
123
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
124
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
125
- glBindTexture (GL_TEXTURE_2D, 0 );
126
-
127
- glGenTextures (1 , &BBoxmaxTex);
128
- glBindTexture (GL_TEXTURE_2D, BBoxmaxTex);
129
- glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGB32F, scene->bvhTranslator .nodeTexWidth , scene->bvhTranslator .nodeTexWidth , 0 , GL_RGB, GL_FLOAT, &scene->bvhTranslator .bboxmax [0 ]);
130
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
131
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
132
- glBindTexture (GL_TEXTURE_2D, 0 );
112
+ glBindTexture (GL_TEXTURE_BUFFER, BVHTex);
113
+ glTexBuffer (GL_TEXTURE_BUFFER, GL_RGB32F, BVHBuffer);
133
114
134
- // Create texture for VertexIndices
115
+ // Create Buffer and Texture for VertexIndices
116
+ glGenBuffers (1 , &vertexIndicesBuffer);
117
+ glBindBuffer (GL_TEXTURE_BUFFER, vertexIndicesBuffer);
118
+ glBufferData (GL_TEXTURE_BUFFER, sizeof (Indices) * scene->vertIndices .size (), &scene->vertIndices [0 ], GL_STATIC_DRAW);
135
119
glGenTextures (1 , &vertexIndicesTex);
136
- glBindTexture (GL_TEXTURE_2D, vertexIndicesTex);
137
- glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGB32I, scene->indicesTexWidth , scene->indicesTexWidth , 0 , GL_RGB_INTEGER, GL_INT, &scene->vertIndices [0 ]);
138
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
139
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
140
- glBindTexture (GL_TEXTURE_2D, 0 );
120
+ glBindTexture (GL_TEXTURE_BUFFER, vertexIndicesTex);
121
+ glTexBuffer (GL_TEXTURE_BUFFER, GL_RGB32I, vertexIndicesBuffer);
141
122
142
- // Create texture for Vertices
123
+ // Create Buffer and Texture for Vertices
124
+ glGenBuffers (1 , &verticesBuffer);
125
+ glBindBuffer (GL_TEXTURE_BUFFER, verticesBuffer);
126
+ glBufferData (GL_TEXTURE_BUFFER, sizeof (Vec4) * scene->verticesUVX .size (), &scene->verticesUVX [0 ], GL_STATIC_DRAW);
143
127
glGenTextures (1 , &verticesTex);
144
- glBindTexture (GL_TEXTURE_2D , verticesTex);
145
- glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA32F, scene-> triDataTexWidth , scene-> triDataTexWidth , 0 , GL_RGBA, GL_FLOAT, &scene-> verticesUVX [ 0 ] );
146
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
147
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
148
- glBindTexture (GL_TEXTURE_2D, 0 );
149
-
150
- // Create texture for Normals
128
+ glBindTexture (GL_TEXTURE_BUFFER , verticesTex);
129
+ glTexBuffer (GL_TEXTURE_BUFFER, GL_RGBA32F, verticesBuffer );
130
+
131
+ // Create Buffer and Texture for Normals
132
+ glGenBuffers ( 1 , &normalsBuffer );
133
+ glBindBuffer (GL_TEXTURE_BUFFER, normalsBuffer);
134
+ glBufferData (GL_TEXTURE_BUFFER, sizeof (Vec4) * scene-> normalsUVY . size (), &scene-> normalsUVY [ 0 ], GL_STATIC_DRAW);
151
135
glGenTextures (1 , &normalsTex);
152
- glBindTexture (GL_TEXTURE_2D, normalsTex);
153
- glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA32F, scene->triDataTexWidth , scene->triDataTexWidth , 0 , GL_RGBA, GL_FLOAT, &scene->normalsUVY [0 ]);
154
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
155
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
156
- glBindTexture (GL_TEXTURE_2D, 0 );
136
+ glBindTexture (GL_TEXTURE_BUFFER, normalsTex);
137
+ glTexBuffer (GL_TEXTURE_BUFFER, GL_RGBA32F, normalsBuffer);
157
138
158
139
// Create texture for Materials
159
140
glGenTextures (1 , &materialsTex);
@@ -232,17 +213,10 @@ namespace GLSLPT
232
213
glBindTexture (GL_TEXTURE_2D, materialsTex);
233
214
glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA32F, (sizeof (Material) / sizeof (Vec4)) * scene->materials .size (), 1 , 0 , GL_RGBA, GL_FLOAT, &scene->materials [0 ]);
234
215
235
- int yPos = scene->bvhTranslator .topLevelIndexPackedXY & 0x00000FFF ;
236
- int index = yPos * scene->bvhTranslator .nodeTexWidth ;
237
-
238
- glBindTexture (GL_TEXTURE_2D, BVHTex);
239
- glTexSubImage2D (GL_TEXTURE_2D, 0 , 0 , yPos, scene->bvhTranslator .nodeTexWidth , scene->bvhTranslator .nodeTexWidth - yPos, GL_RGB_INTEGER, GL_INT, &scene->bvhTranslator .nodes [index]);
240
-
241
- glBindTexture (GL_TEXTURE_2D, BBoxminTex);
242
- glTexSubImage2D (GL_TEXTURE_2D, 0 , 0 , yPos, scene->bvhTranslator .nodeTexWidth , scene->bvhTranslator .nodeTexWidth - yPos, GL_RGB, GL_FLOAT, &scene->bvhTranslator .bboxmin [index]);
216
+ int index = scene->bvhTranslator .topLevelIndex ;
243
217
244
- glBindTexture (GL_TEXTURE_2D, BBoxmaxTex );
245
- glTexSubImage2D (GL_TEXTURE_2D, 0 , 0 , yPos, scene-> bvhTranslator . nodeTexWidth , scene->bvhTranslator .nodeTexWidth - yPos, GL_RGB, GL_FLOAT, &scene->bvhTranslator .bboxmax [index]);
218
+ glBindBuffer (GL_TEXTURE_BUFFER, BVHBuffer );
219
+ glBufferSubData (GL_TEXTURE_BUFFER, sizeof (RadeonRays::BvhTranslator::Node) * index, sizeof (RadeonRays::BvhTranslator::Node) * ( scene->bvhTranslator .nodes . size () - index), &scene->bvhTranslator .nodes [index]);
246
220
}
247
221
}
248
222
}
0 commit comments