History

repairs to MetavoxelSystem after reset to upstream

Stephen Birarda committed 11 years ago

Commit fa8b7021 parent c18c45a1 file · +175 −174Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 1 file). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+175−174
@@ -40,13 +40,13 @@ REGISTER_META_OBJECT(StaticModelRenderer) · 39 unmodified lines
40REGISTER_META_OBJECT(HeightfieldRenderer)40REGISTER_META_OBJECT(HeightfieldRenderer)
41 41
42MetavoxelSystem::NetworkSimulation::NetworkSimulation(float dropRate, float repeatRate,42MetavoxelSystem::NetworkSimulation::NetworkSimulation(float dropRate, float repeatRate,
43 int minimumDelay, int maximumDelay, int bandwidthLimit) :43 int minimumDelay, int maximumDelay, int bandwidthLimit) :
44dropRate(dropRate),44 dropRate(dropRate),
45repeatRate(repeatRate),45 repeatRate(repeatRate),
46minimumDelay(minimumDelay),46 minimumDelay(minimumDelay),
47maximumDelay(maximumDelay),47 maximumDelay(maximumDelay),
48bandwidthLimit(bandwidthLimit) {48 bandwidthLimit(bandwidthLimit) {
49}49}
50 50
51MetavoxelSystem::~MetavoxelSystem() {51MetavoxelSystem::~MetavoxelSystem() {
52 // kill the updater before we delete our network simulation objects52 // kill the updater before we delete our network simulation objects
@@ -59,14 +59,14 @@ void MetavoxelSystem::init() { · 6 unmodified lines
59 MetavoxelClientManager::init();59 MetavoxelClientManager::init();
60 60
61 _voxelBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(61 _voxelBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(
62 new BufferDataAttribute("voxelBuffer"));62 new BufferDataAttribute("voxelBuffer"));
63 _voxelBufferAttribute->setLODThresholdMultiplier(63 _voxelBufferAttribute->setLODThresholdMultiplier(
64 AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier());64 AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier());
65 65
66 _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +66 _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
67 "shaders/metavoxel_heightfield_base.vert");67 "shaders/metavoxel_heightfield_base.vert");
68 _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +68 _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
69 "shaders/metavoxel_heightfield_base.frag");69 "shaders/metavoxel_heightfield_base.frag");
70 _baseHeightfieldProgram.link();70 _baseHeightfieldProgram.link();
71 71
72 _baseHeightfieldProgram.bind();72 _baseHeightfieldProgram.bind();
@@ -79,9 +79,9 @@ void MetavoxelSystem::init() { · 6 unmodified lines
79 loadSplatProgram("heightfield", _splatHeightfieldProgram, _splatHeightfieldLocations);79 loadSplatProgram("heightfield", _splatHeightfieldProgram, _splatHeightfieldLocations);
80 80
81 _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +81 _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
82 "shaders/metavoxel_heightfield_cursor.vert");82 "shaders/metavoxel_heightfield_cursor.vert");
83 _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +83 _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
84 "shaders/metavoxel_cursor.frag");84 "shaders/metavoxel_cursor.frag");
85 _heightfieldCursorProgram.link();85 _heightfieldCursorProgram.link();
86 86
87 _heightfieldCursorProgram.bind();87 _heightfieldCursorProgram.bind();
@@ -89,17 +89,17 @@ void MetavoxelSystem::init() { · 1 unmodified line
89 _heightfieldCursorProgram.release();89 _heightfieldCursorProgram.release();
90 90
91 _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +91 _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
92 "shaders/metavoxel_voxel_base.vert");92 "shaders/metavoxel_voxel_base.vert");
93 _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +93 _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
94 "shaders/metavoxel_voxel_base.frag");94 "shaders/metavoxel_voxel_base.frag");
95 _baseVoxelProgram.link();95 _baseVoxelProgram.link();
96 96
97 loadSplatProgram("voxel", _splatVoxelProgram, _splatVoxelLocations);97 loadSplatProgram("voxel", _splatVoxelProgram, _splatVoxelLocations);
98 98
99 _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +99 _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
100 "shaders/metavoxel_voxel_cursor.vert");100 "shaders/metavoxel_voxel_cursor.vert");
101 _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +101 _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
102 "shaders/metavoxel_cursor.frag");102 "shaders/metavoxel_cursor.frag");
103 _voxelCursorProgram.link();103 _voxelCursorProgram.link();
104}104}
105 105
@@ -124,16 +124,16 @@ public: · 18 unmodified lines
124 SimulateVisitor(float deltaTime, const MetavoxelLOD& lod);124 SimulateVisitor(float deltaTime, const MetavoxelLOD& lod);
125 125
126 virtual int visit(MetavoxelInfo& info);126 virtual int visit(MetavoxelInfo& info);
127 127
128private:128private:
129 129
130 float _deltaTime;130 float _deltaTime;
131};131};
132 132
133SimulateVisitor::SimulateVisitor(float deltaTime, const MetavoxelLOD& lod) :133SimulateVisitor::SimulateVisitor(float deltaTime, const MetavoxelLOD& lod) :
134MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),134 MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),
135 QVector<AttributePointer>(), lod),135 QVector<AttributePointer>(), lod),
136_deltaTime(deltaTime) {136 _deltaTime(deltaTime) {
137}137}
138 138
139int SimulateVisitor::visit(MetavoxelInfo& info) {139int SimulateVisitor::visit(MetavoxelInfo& info) {
@@ -141,7 +141,7 @@ int SimulateVisitor::visit(MetavoxelInfo& info) { · 1 unmodified line
141 return DEFAULT_ORDER;141 return DEFAULT_ORDER;
142 }142 }
143 static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<143 static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
144 SharedObjectPointer>().data())->getImplementation()->simulate(*_data, _deltaTime, info, _lod);144 SharedObjectPointer>().data())->getImplementation()->simulate(*_data, _deltaTime, info, _lod);
145 return STOP_RECURSION;145 return STOP_RECURSION;
146}146}
147 147
@@ -152,7 +152,7 @@ void MetavoxelSystem::simulate(float deltaTime) { · 4 unmodified lines
152 const float DEFAULT_LOD_THRESHOLD = 0.01f;152 const float DEFAULT_LOD_THRESHOLD = 0.01f;
153 _lod = MetavoxelLOD(Application::getInstance()->getCamera()->getPosition(), DEFAULT_LOD_THRESHOLD);153 _lod = MetavoxelLOD(Application::getInstance()->getCamera()->getPosition(), DEFAULT_LOD_THRESHOLD);
154 }154 }
155 155
156 SimulateVisitor simulateVisitor(deltaTime, getLOD());156 SimulateVisitor simulateVisitor(deltaTime, getLOD());
157 guideToAugmented(simulateVisitor);157 guideToAugmented(simulateVisitor);
158}158}
@@ -166,8 +166,8 @@ public: · 7 unmodified lines
166};166};
167 167
168RenderVisitor::RenderVisitor(const MetavoxelLOD& lod) :168RenderVisitor::RenderVisitor(const MetavoxelLOD& lod) :
169MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),169 MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),
170 QVector<AttributePointer>(), lod) {170 QVector<AttributePointer>(), lod) {
171}171}
172 172
173int RenderVisitor::visit(MetavoxelInfo& info) {173int RenderVisitor::visit(MetavoxelInfo& info) {
@@ -175,7 +175,7 @@ int RenderVisitor::visit(MetavoxelInfo& info) { · 1 unmodified line
175 return DEFAULT_ORDER;175 return DEFAULT_ORDER;
176 }176 }
177 static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<177 static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
178 SharedObjectPointer>().data())->getImplementation()->render(*_data, info, _lod);178 SharedObjectPointer>().data())->getImplementation()->render(*_data, info, _lod);
179 return STOP_RECURSION;179 return STOP_RECURSION;
180}180}
181 181
@@ -195,18 +195,18 @@ void MetavoxelSystem::render() { · 13 unmodified lines
195 // update the frustum195 // update the frustum
196 ViewFrustum* viewFrustum = Application::getInstance()->getDisplayViewFrustum();196 ViewFrustum* viewFrustum = Application::getInstance()->getDisplayViewFrustum();
197 _frustum.set(viewFrustum->getFarTopLeft(), viewFrustum->getFarTopRight(), viewFrustum->getFarBottomLeft(),197 _frustum.set(viewFrustum->getFarTopLeft(), viewFrustum->getFarTopRight(), viewFrustum->getFarBottomLeft(),
198 viewFrustum->getFarBottomRight(), viewFrustum->getNearTopLeft(), viewFrustum->getNearTopRight(),198 viewFrustum->getFarBottomRight(), viewFrustum->getNearTopLeft(), viewFrustum->getNearTopRight(),
199 viewFrustum->getNearBottomLeft(), viewFrustum->getNearBottomRight());199 viewFrustum->getNearBottomLeft(), viewFrustum->getNearBottomRight());
200 200
201 RenderVisitor renderVisitor(getLOD());201 RenderVisitor renderVisitor(getLOD());
202 guideToAugmented(renderVisitor, true);202 guideToAugmented(renderVisitor, true);
203 203
204 if (!_heightfieldBaseBatches.isEmpty()) {204 if (!_heightfieldBaseBatches.isEmpty()) {
205 glEnableClientState(GL_VERTEX_ARRAY);205 glEnableClientState(GL_VERTEX_ARRAY);
206 glEnableClientState(GL_TEXTURE_COORD_ARRAY);206 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
207 207
208 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true);208 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true);
209 209
210 glDisable(GL_BLEND);210 glDisable(GL_BLEND);
211 glEnable(GL_CULL_FACE);211 glEnable(GL_CULL_FACE);
212 glEnable(GL_ALPHA_TEST);212 glEnable(GL_ALPHA_TEST);
@@ -225,7 +225,7 @@ void MetavoxelSystem::render() { · 12 unmodified lines
225 225
226 batch.vertexBuffer->bind();226 batch.vertexBuffer->bind();
227 batch.indexBuffer->bind();227 batch.indexBuffer->bind();
228 228
229 HeightfieldPoint* point = 0;229 HeightfieldPoint* point = 0;
230 glVertexPointer(3, GL_FLOAT, sizeof(HeightfieldPoint), &point->vertex);230 glVertexPointer(3, GL_FLOAT, sizeof(HeightfieldPoint), &point->vertex);
231 glTexCoordPointer(2, GL_FLOAT, sizeof(HeightfieldPoint), &point->textureCoord);231 glTexCoordPointer(2, GL_FLOAT, sizeof(HeightfieldPoint), &point->textureCoord);
@@ -234,7 +234,7 @@ void MetavoxelSystem::render() { · 2 unmodified lines
234 234
235 _baseHeightfieldProgram.setUniform(_baseHeightScaleLocation, batch.heightScale);235 _baseHeightfieldProgram.setUniform(_baseHeightScaleLocation, batch.heightScale);
236 _baseHeightfieldProgram.setUniform(_baseColorScaleLocation, batch.colorScale);236 _baseHeightfieldProgram.setUniform(_baseColorScaleLocation, batch.colorScale);
237 237
238 glActiveTexture(GL_TEXTURE1);238 glActiveTexture(GL_TEXTURE1);
239 glBindTexture(GL_TEXTURE_2D, batch.colorTextureID);239 glBindTexture(GL_TEXTURE_2D, batch.colorTextureID);
240 240
@@ -244,10 +244,10 @@ void MetavoxelSystem::render() { · 3 unmodified lines
244 244
245 glActiveTexture(GL_TEXTURE0);245 glActiveTexture(GL_TEXTURE0);
246 glBindTexture(GL_TEXTURE_2D, 0);246 glBindTexture(GL_TEXTURE_2D, 0);
247 247
248 batch.vertexBuffer->release();248 batch.vertexBuffer->release();
249 batch.indexBuffer->release();249 batch.indexBuffer->release();
250 250
251 glPopMatrix();251 glPopMatrix();
252 }252 }
253 253
@@ -275,7 +275,7 @@ void MetavoxelSystem::render() { · 21 unmodified lines
275 275
276 batch.vertexBuffer->bind();276 batch.vertexBuffer->bind();
277 batch.indexBuffer->bind();277 batch.indexBuffer->bind();
278 278
279 HeightfieldPoint* point = 0;279 HeightfieldPoint* point = 0;
280 glVertexPointer(3, GL_FLOAT, sizeof(HeightfieldPoint), &point->vertex);280 glVertexPointer(3, GL_FLOAT, sizeof(HeightfieldPoint), &point->vertex);
281 glTexCoordPointer(2, GL_FLOAT, sizeof(HeightfieldPoint), &point->textureCoord);281 glTexCoordPointer(2, GL_FLOAT, sizeof(HeightfieldPoint), &point->textureCoord);
@@ -283,7 +283,7 @@ void MetavoxelSystem::render() { · 1 unmodified line
283 glBindTexture(GL_TEXTURE_2D, batch.heightTextureID);283 glBindTexture(GL_TEXTURE_2D, batch.heightTextureID);
284 284
285 _splatHeightfieldProgram.setUniformValue(_splatHeightfieldLocations.heightScale,285 _splatHeightfieldProgram.setUniformValue(_splatHeightfieldLocations.heightScale,
286 batch.heightScale.x, batch.heightScale.y);286 batch.heightScale.x, batch.heightScale.y);
287 _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.textureScale, batch.textureScale);287 _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.textureScale, batch.textureScale);
288 _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureOffset, batch.splatTextureOffset);288 _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureOffset, batch.splatTextureOffset);
289 289
@@ -291,18 +291,18 @@ void MetavoxelSystem::render() { · 1 unmodified line
291 _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureScalesS, batch.splatTextureScalesS);291 _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureScalesS, batch.splatTextureScalesS);
292 _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureScalesT, batch.splatTextureScalesT);292 _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureScalesT, batch.splatTextureScalesT);
293 _splatHeightfieldProgram.setUniformValue(293 _splatHeightfieldProgram.setUniformValue(
294 _splatHeightfieldLocations.textureValueMinima,294 _splatHeightfieldLocations.textureValueMinima,
295 (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,295 (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
296 (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,296 (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
297 (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,297 (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
298 (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP);298 (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP);
299 _splatHeightfieldProgram.setUniformValue(299 _splatHeightfieldProgram.setUniformValue(
300 _splatHeightfieldLocations.textureValueMaxima,300 _splatHeightfieldLocations.textureValueMaxima,
301 (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,301 (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
302 (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,302 (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
303 (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,303 (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
304 (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP);304 (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP);
305 305
306 glActiveTexture(GL_TEXTURE1);306 glActiveTexture(GL_TEXTURE1);
307 glBindTexture(GL_TEXTURE_2D, batch.materialTextureID);307 glBindTexture(GL_TEXTURE_2D, batch.materialTextureID);
308 308
@@ -312,22 +312,22 @@ void MetavoxelSystem::render() { · 3 unmodified lines
312 }312 }
313 313
314 glDrawRangeElements(GL_TRIANGLES, 0, batch.vertexCount - 1, batch.indexCount, GL_UNSIGNED_INT, 0);314 glDrawRangeElements(GL_TRIANGLES, 0, batch.vertexCount - 1, batch.indexCount, GL_UNSIGNED_INT, 0);
315 315
316 for (int i = 0; i < SPLAT_COUNT; i++) {316 for (int i = 0; i < SPLAT_COUNT; i++) {
317 glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]);317 glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]);
318 glBindTexture(GL_TEXTURE_2D, 0);318 glBindTexture(GL_TEXTURE_2D, 0);
319 }319 }
320 320
321 glActiveTexture(GL_TEXTURE1);321 glActiveTexture(GL_TEXTURE1);
322 glBindTexture(GL_TEXTURE_2D, 0);322 glBindTexture(GL_TEXTURE_2D, 0);
323 323
324 glActiveTexture(GL_TEXTURE0);324 glActiveTexture(GL_TEXTURE0);
325 glBindTexture(GL_TEXTURE_2D, 0);325 glBindTexture(GL_TEXTURE_2D, 0);
326 326
327 batch.vertexBuffer->release();327 batch.vertexBuffer->release();
328 batch.indexBuffer->release();328 batch.indexBuffer->release();
329 329
330 glPopMatrix();330 glPopMatrix();
331 }331 }
332 332
333 _splatHeightfieldProgram.release();333 _splatHeightfieldProgram.release();
@@ -341,15 +341,15 @@ void MetavoxelSystem::render() { · 7 unmodified lines
341 341
342 glDisable(GL_CULL_FACE);342 glDisable(GL_CULL_FACE);
343 343
344 glDisableClientState(GL_TEXTURE_COORD_ARRAY);344 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
345 glDisableClientState(GL_VERTEX_ARRAY);345 glDisableClientState(GL_VERTEX_ARRAY);
346 346
347 _heightfieldBaseBatches.clear();347 _heightfieldBaseBatches.clear();
348 }348 }
349 349
350 if (!_voxelBaseBatches.isEmpty()) {350 if (!_voxelBaseBatches.isEmpty()) {
351 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true);351 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true);
352 352
353 glEnableClientState(GL_VERTEX_ARRAY);353 glEnableClientState(GL_VERTEX_ARRAY);
354 glDisable(GL_BLEND);354 glDisable(GL_BLEND);
355 glEnable(GL_CULL_FACE);355 glEnable(GL_CULL_FACE);
@@ -360,7 +360,7 @@ void MetavoxelSystem::render() { · 4 unmodified lines
360 360
361 glEnableClientState(GL_COLOR_ARRAY);361 glEnableClientState(GL_COLOR_ARRAY);
362 glEnableClientState(GL_NORMAL_ARRAY);362 glEnableClientState(GL_NORMAL_ARRAY);
363 363
364 _baseVoxelProgram.bind();364 _baseVoxelProgram.bind();
365 365
366 foreach (const VoxelBatch& batch, _voxelBaseBatches) {366 foreach (const VoxelBatch& batch, _voxelBaseBatches) {
@@ -379,10 +379,10 @@ void MetavoxelSystem::render() { · 12 unmodified lines
379 }379 }
380 380
381 _baseVoxelProgram.release();381 _baseVoxelProgram.release();
382 382
383 glDisable(GL_ALPHA_TEST);383 glDisable(GL_ALPHA_TEST);
384 glEnable(GL_BLEND);384 glEnable(GL_BLEND);
385 385
386 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false);386 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false);
387 387
388 if (!_voxelSplatBatches.isEmpty()) {388 if (!_voxelSplatBatches.isEmpty()) {
@@ -406,25 +406,25 @@ void MetavoxelSystem::render() { · 17 unmodified lines
406 glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal);406 glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal);
407 407
408 _splatVoxelProgram.setAttributeBuffer(_splatVoxelLocations.materials,408 _splatVoxelProgram.setAttributeBuffer(_splatVoxelLocations.materials,
409 GL_UNSIGNED_BYTE, (qint64)&point->materials, SPLAT_COUNT, sizeof(VoxelPoint));409 GL_UNSIGNED_BYTE, (qint64)&point->materials, SPLAT_COUNT, sizeof(VoxelPoint));
410 _splatVoxelProgram.setAttributeBuffer(_splatVoxelLocations.materialWeights,410 _splatVoxelProgram.setAttributeBuffer(_splatVoxelLocations.materialWeights,
411 GL_UNSIGNED_BYTE, (qint64)&point->materialWeights, SPLAT_COUNT, sizeof(VoxelPoint));411 GL_UNSIGNED_BYTE, (qint64)&point->materialWeights, SPLAT_COUNT, sizeof(VoxelPoint));
412 412
413 const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL;413 const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL;
414 _splatVoxelProgram.setUniform(_splatVoxelLocations.splatTextureScalesS, batch.splatTextureScalesS);414 _splatVoxelProgram.setUniform(_splatVoxelLocations.splatTextureScalesS, batch.splatTextureScalesS);
415 _splatVoxelProgram.setUniform(_splatVoxelLocations.splatTextureScalesT, batch.splatTextureScalesT);415 _splatVoxelProgram.setUniform(_splatVoxelLocations.splatTextureScalesT, batch.splatTextureScalesT);
416 _splatVoxelProgram.setUniformValue(416 _splatVoxelProgram.setUniformValue(
417 _splatVoxelLocations.textureValueMinima,417 _splatVoxelLocations.textureValueMinima,
418 (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,418 (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
419 (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,419 (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
420 (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,420 (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
421 (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP);421 (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP);
422 _splatVoxelProgram.setUniformValue(422 _splatVoxelProgram.setUniformValue(
423 _splatVoxelLocations.textureValueMaxima,423 _splatVoxelLocations.textureValueMaxima,
424 (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,424 (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
425 (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,425 (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
426 (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,426 (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
427 (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP);427 (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP);
428 428
429 for (int i = 0; i < SPLAT_COUNT; i++) {429 for (int i = 0; i < SPLAT_COUNT; i++) {
430 glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]);430 glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]);
@@ -437,9 +437,9 @@ void MetavoxelSystem::render() { · 6 unmodified lines
437 glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]);437 glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]);
438 glBindTexture(GL_TEXTURE_2D, 0);438 glBindTexture(GL_TEXTURE_2D, 0);
439 }439 }
440 440
441 glActiveTexture(GL_TEXTURE0);441 glActiveTexture(GL_TEXTURE0);
442 442
443 batch.vertexBuffer->release();443 batch.vertexBuffer->release();
444 batch.indexBuffer->release();444 batch.indexBuffer->release();
445 }445 }
@@ -517,10 +517,10 @@ public: · 71 unmodified lines
517};517};
518 518
519RayVoxelIntersectionVisitor::RayVoxelIntersectionVisitor(const glm::vec3& origin,519RayVoxelIntersectionVisitor::RayVoxelIntersectionVisitor(const glm::vec3& origin,
520 const glm::vec3& direction, const MetavoxelLOD& lod) :520 const glm::vec3& direction, const MetavoxelLOD& lod) :
521RayIntersectionVisitor(origin, direction, QVector<AttributePointer>() <<521 RayIntersectionVisitor(origin, direction, QVector<AttributePointer>() <<
522 Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), QVector<AttributePointer>(), lod),522 Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), QVector<AttributePointer>(), lod),
523intersectionDistance(FLT_MAX) {523 intersectionDistance(FLT_MAX) {
524}524}
525 525
526int RayVoxelIntersectionVisitor::visit(MetavoxelInfo& info, float distance) {526int RayVoxelIntersectionVisitor::visit(MetavoxelInfo& info, float distance) {
@@ -528,7 +528,7 @@ int RayVoxelIntersectionVisitor::visit(MetavoxelInfo& info, float distance) { · 1 unmodified line
528 return _order;528 return _order;
529 }529 }
530 const VoxelBuffer* buffer = static_cast<VoxelBuffer*>(530 const VoxelBuffer* buffer = static_cast<VoxelBuffer*>(
531 info.inputValues.at(0).getInlineValue<BufferDataPointer>().data());531 info.inputValues.at(0).getInlineValue<BufferDataPointer>().data());
532 if (!buffer) {532 if (!buffer) {
533 return STOP_RECURSION;533 return STOP_RECURSION;
534 }534 }
@@ -630,7 +630,7 @@ public: · 95 unmodified lines
630 virtual bool visit(Spanner* spanner);630 virtual bool visit(Spanner* spanner);
631 631
632 virtual int visit(MetavoxelInfo& info);632 virtual int visit(MetavoxelInfo& info);
633 633
634private:634private:
635 635
636 Box _bounds;636 Box _bounds;
@@ -693,17 +693,17 @@ class BufferCursorRenderVisitor : public MetavoxelVisitor { · 56 unmodified lines
693public:693public:
694 694
695 BufferCursorRenderVisitor(const AttributePointer& attribute, const Box& bounds);695 BufferCursorRenderVisitor(const AttributePointer& attribute, const Box& bounds);
696 696
697 virtual int visit(MetavoxelInfo& info);697 virtual int visit(MetavoxelInfo& info);
698 698
699private:699private:
700 700
701 Box _bounds;701 Box _bounds;
702};702};
703 703
704BufferCursorRenderVisitor::BufferCursorRenderVisitor(const AttributePointer& attribute, const Box& bounds) :704BufferCursorRenderVisitor::BufferCursorRenderVisitor(const AttributePointer& attribute, const Box& bounds) :
705MetavoxelVisitor(QVector<AttributePointer>() << attribute),705 MetavoxelVisitor(QVector<AttributePointer>() << attribute),
706_bounds(bounds) {706 _bounds(bounds) {
707}707}
708 708
709int BufferCursorRenderVisitor::visit(MetavoxelInfo& info) {709int BufferCursorRenderVisitor::visit(MetavoxelInfo& info) {
@@ -766,11 +766,11 @@ void MetavoxelSystem::renderVoxelCursor(const glm::vec3& position, float radius) · 56 unmodified lines
766 766
767class MaterialEditApplier : public SignalHandler {767class MaterialEditApplier : public SignalHandler {
768public:768public:
769 769
770 MaterialEditApplier(const MetavoxelEditMessage& message, const QSharedPointer<NetworkTexture> texture);770 MaterialEditApplier(const MetavoxelEditMessage& message, const QSharedPointer<NetworkTexture> texture);
771 771
772 virtual void handle();772 virtual void handle();
773 773
774protected:774protected:
775 775
776 MetavoxelEditMessage _message;776 MetavoxelEditMessage _message;
@@ -778,8 +778,8 @@ protected: · 1 unmodified line
778};778};
779 779
780MaterialEditApplier::MaterialEditApplier(const MetavoxelEditMessage& message, const QSharedPointer<NetworkTexture> texture) :780MaterialEditApplier::MaterialEditApplier(const MetavoxelEditMessage& message, const QSharedPointer<NetworkTexture> texture) :
781_message(message),781 _message(message),
782_texture(texture) {782 _texture(texture) {
783}783}
784 784
785void MaterialEditApplier::handle() {785void MaterialEditApplier::handle() {
@@ -794,16 +794,16 @@ void MetavoxelSystem::applyMaterialEdit(const MetavoxelEditMessage& message, boo · 8 unmodified lines
794 if (material && material->getDiffuse().isValid()) {794 if (material && material->getDiffuse().isValid()) {
795 if (QThread::currentThread() != thread()) {795 if (QThread::currentThread() != thread()) {
796 QMetaObject::invokeMethod(this, "applyMaterialEdit", Q_ARG(const MetavoxelEditMessage&, message),796 QMetaObject::invokeMethod(this, "applyMaterialEdit", Q_ARG(const MetavoxelEditMessage&, message),
797 Q_ARG(bool, reliable));797 Q_ARG(bool, reliable));
798 return;798 return;
799 }799 }
800 QSharedPointer<NetworkTexture> texture = Application::getInstance()->getTextureCache()->getTexture(800 QSharedPointer<NetworkTexture> texture = Application::getInstance()->getTextureCache()->getTexture(
801 material->getDiffuse(), SPLAT_TEXTURE);801 material->getDiffuse(), SPLAT_TEXTURE);
802 if (texture->isLoaded()) {802 if (texture->isLoaded()) {
803 MetavoxelEditMessage newMessage = message;803 MetavoxelEditMessage newMessage = message;
804 static_cast<MaterialEdit*>(newMessage.edit.data())->averageColor = texture->getAverageColor();804 static_cast<MaterialEdit*>(newMessage.edit.data())->averageColor = texture->getAverageColor();
805 applyEdit(newMessage, true);805 applyEdit(newMessage, true);
806 806
807 } else {807 } else {
808 MaterialEditApplier* applier = new MaterialEditApplier(message, texture);808 MaterialEditApplier* applier = new MaterialEditApplier(message, texture);
809 connect(texture.data(), &Resource::loaded, applier, &SignalHandler::handle);809 connect(texture.data(), &Resource::loaded, applier, &SignalHandler::handle);
@@ -818,7 +818,7 @@ MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) { · 8 unmodified lines
818}818}
819 819
820void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) {820void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) {
821 NodeList::getInstance()->eachNode([&visitor, &render](const SharedNodePointer& node) {821 NodeList::getInstance()->eachNode([&visitor, &render](const SharedNodePointer& node){
822 if (node->getType() == NodeType::MetavoxelServer) {822 if (node->getType() == NodeType::MetavoxelServer) {
823 QMutexLocker locker(&node->getMutex());823 QMutexLocker locker(&node->getMutex());
824 MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());824 MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
@@ -837,9 +837,9 @@ void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) { · 12 unmodified lines
837 837
838void MetavoxelSystem::loadSplatProgram(const char* type, ProgramObject& program, SplatLocations& locations) {838void MetavoxelSystem::loadSplatProgram(const char* type, ProgramObject& program, SplatLocations& locations) {
839 program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +839 program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
840 "shaders/metavoxel_" + type + "_splat.vert");840 "shaders/metavoxel_" + type + "_splat.vert");
841 program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +841 program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
842 "shaders/metavoxel_" + type + "_splat.frag");842 "shaders/metavoxel_" + type + "_splat.frag");
843 program.link();843 program.link();
844 844
845 program.bind();845 program.bind();
@@ -859,8 +859,8 @@ void MetavoxelSystem::loadSplatProgram(const char* type, ProgramObject& program, · 13 unmodified lines
859}859}
860 860
861Throttle::Throttle() :861Throttle::Throttle() :
862_limit(INT_MAX),862 _limit(INT_MAX),
863_total(0) {863 _total(0) {
864}864}
865 865
866bool Throttle::shouldThrottle(int bytes) {866bool Throttle::shouldThrottle(int bytes) {
@@ -881,7 +881,7 @@ bool Throttle::shouldThrottle(int bytes) { · 14 unmodified lines
881}881}
882 882
883MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) :883MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) :
884MetavoxelClient(node, updater) {884 MetavoxelClient(node, updater) {
885}885}
886 886
887void MetavoxelSystemClient::setAugmentedData(const MetavoxelData& data) {887void MetavoxelSystemClient::setAugmentedData(const MetavoxelData& data) {
@@ -898,11 +898,11 @@ class ReceiveDelayer : public QObject { · 10 unmodified lines
898public:898public:
899 899
900 ReceiveDelayer(const SharedNodePointer& node, const QByteArray& packet);900 ReceiveDelayer(const SharedNodePointer& node, const QByteArray& packet);
901 901
902protected:902protected:
903 903
904 virtual void timerEvent(QTimerEvent* event);904 virtual void timerEvent(QTimerEvent* event);
905 905
906private:906private:
907 907
908 SharedNodePointer _node;908 SharedNodePointer _node;
@@ -910,8 +910,8 @@ private: · 1 unmodified line
910};910};
911 911
912ReceiveDelayer::ReceiveDelayer(const SharedNodePointer& node, const QByteArray& packet) :912ReceiveDelayer::ReceiveDelayer(const SharedNodePointer& node, const QByteArray& packet) :
913_node(node),913 _node(node),
914_packet(packet) {914 _packet(packet) {
915}915}
916 916
917void ReceiveDelayer::timerEvent(QTimerEvent* event) {917void ReceiveDelayer::timerEvent(QTimerEvent* event) {
@@ -956,16 +956,16 @@ public: · 38 unmodified lines
956 AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData);956 AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData);
957 957
958 virtual int visit(MetavoxelInfo& info);958 virtual int visit(MetavoxelInfo& info);
959 959
960private:960private:
961 961
962 const MetavoxelData& _previousData;962 const MetavoxelData& _previousData;
963};963};
964 964
965AugmentVisitor::AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData) :965AugmentVisitor::AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData) :
966MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),966 MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(),
967 QVector<AttributePointer>(), lod),967 QVector<AttributePointer>(), lod),
968_previousData(previousData) {968 _previousData(previousData) {
969}969}
970 970
971int AugmentVisitor::visit(MetavoxelInfo& info) {971int AugmentVisitor::visit(MetavoxelInfo& info) {
@@ -973,7 +973,7 @@ int AugmentVisitor::visit(MetavoxelInfo& info) { · 1 unmodified line
973 return DEFAULT_ORDER;973 return DEFAULT_ORDER;
974 }974 }
975 static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<975 static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue<
976 SharedObjectPointer>().data())->getImplementation()->augment(*_data, _previousData, info, _lod);976 SharedObjectPointer>().data())->getImplementation()->augment(*_data, _previousData, info, _lod);
977 return STOP_RECURSION;977 return STOP_RECURSION;
978}978}
979 979
@@ -981,10 +981,10 @@ class Augmenter : public QRunnable { · 1 unmodified line
981public:981public:
982 982
983 Augmenter(const SharedNodePointer& node, const MetavoxelData& data,983 Augmenter(const SharedNodePointer& node, const MetavoxelData& data,
984 const MetavoxelData& previousData, const MetavoxelLOD& lod);984 const MetavoxelData& previousData, const MetavoxelLOD& lod);
985 985
986 virtual void run();986 virtual void run();
987 987
988private:988private:
989 989
990 QWeakPointer<Node> _node;990 QWeakPointer<Node> _node;
@@ -994,11 +994,11 @@ private: · 3 unmodified lines
994};994};
995 995
996Augmenter::Augmenter(const SharedNodePointer& node, const MetavoxelData& data,996Augmenter::Augmenter(const SharedNodePointer& node, const MetavoxelData& data,
997 const MetavoxelData& previousData, const MetavoxelLOD& lod) :997 const MetavoxelData& previousData, const MetavoxelLOD& lod) :
998_node(node),998 _node(node),
999_data(data),999 _data(data),
1000_previousData(previousData),1000 _previousData(previousData),
1001_lod(lod) {1001 _lod(lod) {
1002}1002}
1003 1003
1004void Augmenter::run() {1004void Augmenter::run() {
@@ -1016,7 +1016,7 @@ void MetavoxelSystemClient::refreshVoxelData() { · 11 unmodified lines
1016 // make it look as if all the colors have changed1016 // make it look as if all the colors have changed
1017 MetavoxelData oldData = getAugmentedData();1017 MetavoxelData oldData = getAugmentedData();
1018 oldData.touch(AttributeRegistry::getInstance()->getVoxelColorAttribute());1018 oldData.touch(AttributeRegistry::getInstance()->getVoxelColorAttribute());
1019 1019
1020 QThreadPool::globalInstance()->start(new Augmenter(_node, _data, oldData, _remoteDataLOD));1020 QThreadPool::globalInstance()->start(new Augmenter(_node, _data, oldData, _remoteDataLOD));
1021}1021}
1022 1022
@@ -1029,9 +1029,9 @@ class SendDelayer : public QObject { · 6 unmodified lines
1029public:1029public:
1030 1030
1031 SendDelayer(const SharedNodePointer& node, const QByteArray& data);1031 SendDelayer(const SharedNodePointer& node, const QByteArray& data);
1032 1032
1033 virtual void timerEvent(QTimerEvent* event);1033 virtual void timerEvent(QTimerEvent* event);
1034 1034
1035private:1035private:
1036 1036
1037 SharedNodePointer _node;1037 SharedNodePointer _node;
@@ -1039,8 +1039,8 @@ private: · 1 unmodified line
1039};1039};
1040 1040
1041SendDelayer::SendDelayer(const SharedNodePointer& node, const QByteArray& data) :1041SendDelayer::SendDelayer(const SharedNodePointer& node, const QByteArray& data) :
1042_node(node),1042 _node(node),
1043_data(data.constData(), data.size()) {1043 _data(data.constData(), data.size()) {
1044}1044}
1045 1045
1046void SendDelayer::timerEvent(QTimerEvent* event) {1046void SendDelayer::timerEvent(QTimerEvent* event) {
@@ -1083,21 +1083,21 @@ void VoxelPoint::setNormal(const glm::vec3& normal) { · 36 unmodified lines
1083}1083}
1084 1084
1085VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>& indices, const QVector<glm::vec3>& hermite,1085VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>& indices, const QVector<glm::vec3>& hermite,
1086 const QMultiHash<VoxelCoord, int>& quadIndices, int size, const QVector<SharedObjectPointer>& materials) :1086 const QMultiHash<VoxelCoord, int>& quadIndices, int size, const QVector<SharedObjectPointer>& materials) :
1087_vertices(vertices),1087 _vertices(vertices),
1088_indices(indices),1088 _indices(indices),
1089_hermite(hermite),1089 _hermite(hermite),
1090_quadIndices(quadIndices),1090 _quadIndices(quadIndices),
1091_size(size),1091 _size(size),
1092_vertexCount(vertices.size()),1092 _vertexCount(vertices.size()),
1093_indexCount(indices.size()),1093 _indexCount(indices.size()),
1094_hermiteCount(hermite.size()),1094 _hermiteCount(hermite.size()),
1095_indexBuffer(QOpenGLBuffer::IndexBuffer),1095 _indexBuffer(QOpenGLBuffer::IndexBuffer),
1096_materials(materials) {1096 _materials(materials) {
1097}1097}
1098 1098
1099bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,1099bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,
1100 const glm::vec3& direction, float& distance) const {1100 const glm::vec3& direction, float& distance) const {
1101 float highest = _size - 1.0f;1101 float highest = _size - 1.0f;
1102 glm::vec3 position = entry * highest;1102 glm::vec3 position = entry * highest;
1103 glm::vec3 floors = glm::floor(position);1103 glm::vec3 floors = glm::floor(position);
@@ -1105,14 +1105,14 @@ bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::ve · 1 unmodified line
1105 int x = qMin((int)floors.x, max), y = qMin((int)floors.y, max), z = qMin((int)floors.z, max);1105 int x = qMin((int)floors.x, max), y = qMin((int)floors.y, max), z = qMin((int)floors.z, max);
1106 forever {1106 forever {
1107 for (QMultiHash<VoxelCoord, int>::const_iterator it = _quadIndices.constFind(qRgb(x + 1, y + 1, z + 1));1107 for (QMultiHash<VoxelCoord, int>::const_iterator it = _quadIndices.constFind(qRgb(x + 1, y + 1, z + 1));
1108 it != _quadIndices.constEnd(); it++) {1108 it != _quadIndices.constEnd(); it++) {
1109 const int* indices = _indices.constData() + *it;1109 const int* indices = _indices.constData() + *it;
1110 if (findRayTriangleIntersection(origin, direction, _vertices.at(indices[0]).vertex,1110 if (findRayTriangleIntersection(origin, direction, _vertices.at(indices[0]).vertex,
1111 _vertices.at(indices[1]).vertex, _vertices.at(indices[2]).vertex, distance) ||1111 _vertices.at(indices[1]).vertex, _vertices.at(indices[2]).vertex, distance) ||
1112 findRayTriangleIntersection(origin, direction, _vertices.at(indices[0]).vertex,1112 findRayTriangleIntersection(origin, direction, _vertices.at(indices[0]).vertex,
1113 _vertices.at(indices[2]).vertex, _vertices.at(indices[3]).vertex, distance)) {1113 _vertices.at(indices[2]).vertex, _vertices.at(indices[3]).vertex, distance)) {
1114 return true;1114 return true;
1115 }1115 }
1116 }1116 }
1117 float xDistance = FLT_MAX, yDistance = FLT_MAX, zDistance = FLT_MAX;1117 float xDistance = FLT_MAX, yDistance = FLT_MAX, zDistance = FLT_MAX;
1118 if (direction.x > 0.0f) {1118 if (direction.x > 0.0f) {
@@ -1181,7 +1181,7 @@ void VoxelBuffer::render(bool cursor) { · 62 unmodified lines
1181 const SharedObjectPointer material = _materials.at(i);1181 const SharedObjectPointer material = _materials.at(i);
1182 if (material) {1182 if (material) {
1183 _networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture(1183 _networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture(
1184 static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);1184 static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
1185 }1185 }
1186 }1186 }
1187 }1187 }
@@ -1216,7 +1216,7 @@ void VoxelBuffer::render(bool cursor) { · 28 unmodified lines
1216 splatBatch.indexBuffer = &_indexBuffer;1216 splatBatch.indexBuffer = &_indexBuffer;
1217 splatBatch.vertexCount = _vertexCount;1217 splatBatch.vertexCount = _vertexCount;
1218 splatBatch.indexCount = _indexCount;1218 splatBatch.indexCount = _indexCount;
1219 1219
1220 for (int i = 0; i < _materials.size(); i += SPLAT_COUNT) {1220 for (int i = 0; i < _materials.size(); i += SPLAT_COUNT) {
1221 for (int j = 0; j < SPLAT_COUNT; j++) {1221 for (int j = 0; j < SPLAT_COUNT; j++) {
1222 int index = i + j;1222 int index = i + j;
@@ -1227,7 +1227,7 @@ void VoxelBuffer::render(bool cursor) { · 4 unmodified lines
1227 splatBatch.splatTextureScalesS[j] = 1.0f / material->getScaleS();1227 splatBatch.splatTextureScalesS[j] = 1.0f / material->getScaleS();
1228 splatBatch.splatTextureScalesT[j] = 1.0f / material->getScaleT();1228 splatBatch.splatTextureScalesT[j] = 1.0f / material->getScaleT();
1229 splatBatch.splatTextureIDs[j] = texture->getID();1229 splatBatch.splatTextureIDs[j] = texture->getID();
1230 1230
1231 } else {1231 } else {
1232 splatBatch.splatTextureIDs[j] = 0;1232 splatBatch.splatTextureIDs[j] = 0;
1233 }1233 }
@@ -1256,7 +1256,7 @@ void VoxelBuffer::render(bool cursor) { · 22 unmodified lines
1256}1256}
1257 1257
1258BufferDataAttribute::BufferDataAttribute(const QString& name) :1258BufferDataAttribute::BufferDataAttribute(const QString& name) :
1259InlineAttribute<BufferDataPointer>(name) {1259 InlineAttribute<BufferDataPointer>(name) {
1260}1260}
1261 1261
1262bool BufferDataAttribute::merge(void*& parent, void* children[], bool postRead) const {1262bool BufferDataAttribute::merge(void*& parent, void* children[], bool postRead) const {
@@ -1278,17 +1278,17 @@ DefaultMetavoxelRendererImplementation::DefaultMetavoxelRendererImplementation() · 15 unmodified lines
1278 1278
1279class VoxelAugmentVisitor : public MetavoxelVisitor {1279class VoxelAugmentVisitor : public MetavoxelVisitor {
1280public:1280public:
1281 1281
1282 VoxelAugmentVisitor(const MetavoxelLOD& lod);1282 VoxelAugmentVisitor(const MetavoxelLOD& lod);
1283 1283
1284 virtual int visit(MetavoxelInfo& info);1284 virtual int visit(MetavoxelInfo& info);
1285};1285};
1286 1286
1287VoxelAugmentVisitor::VoxelAugmentVisitor(const MetavoxelLOD& lod) :1287VoxelAugmentVisitor::VoxelAugmentVisitor(const MetavoxelLOD& lod) :
1288MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getVoxelColorAttribute() <<1288 MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getVoxelColorAttribute() <<
1289 AttributeRegistry::getInstance()->getVoxelMaterialAttribute() <<1289 AttributeRegistry::getInstance()->getVoxelMaterialAttribute() <<
1290 AttributeRegistry::getInstance()->getVoxelHermiteAttribute(), QVector<AttributePointer>() <<1290 AttributeRegistry::getInstance()->getVoxelHermiteAttribute(), QVector<AttributePointer>() <<
1291 Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), lod) {1291 Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), lod) {
1292}1292}
1293 1293
1294class EdgeCrossing {1294class EdgeCrossing {
@@ -1446,9 +1446,9 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 151 unmodified lines
1446 // its properties (color, material, normal) if one is present; as before, boundary edges are excluded1446 // its properties (color, material, normal) if one is present; as before, boundary edges are excluded
1447 int clampedX = qMax(x - 1, 0), clampedY = qMax(y - 1, 0), clampedZ = qMax(z - 1, 0);1447 int clampedX = qMax(x - 1, 0), clampedY = qMax(y - 1, 0), clampedZ = qMax(z - 1, 0);
1448 const QRgb* hermiteBase = hermiteData + clampedZ * hermiteArea + clampedY * hermiteStride +1448 const QRgb* hermiteBase = hermiteData + clampedZ * hermiteArea + clampedY * hermiteStride +
1449 clampedX * VoxelHermiteData::EDGE_COUNT;1449 clampedX * VoxelHermiteData::EDGE_COUNT;
1450 const char* materialBase = materialData ?1450 const char* materialBase = materialData ?
1451 (materialData + clampedZ * area + clampedY * size + clampedX) : NULL;1451 (materialData + clampedZ * area + clampedY * size + clampedX) : NULL;
1452 int crossingCount = 0;1452 int crossingCount = 0;
1453 if (middleX) {1453 if (middleX) {
1454 if (alpha0 != alpha1) {1454 if (alpha0 != alpha1) {
@@ -1650,7 +1650,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 195 unmodified lines
1650 1650
1651 if (displayHermite) {1651 if (displayHermite) {
1652 glm::vec3 start = info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) +1652 glm::vec3 start = info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) +
1653 crossing.point) * scale;1653 crossing.point) * scale;
1654 hermiteSegments.append(start);1654 hermiteSegments.append(start);
1655 hermiteSegments.append(start + crossing.normal * scale);1655 hermiteSegments.append(start + crossing.normal * scale);
1656 }1656 }
@@ -1710,18 +1710,18 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 53 unmodified lines
1710 for (int i = 0; i < MAX_ITERATIONS; i++) {1710 for (int i = 0; i < MAX_ITERATIONS; i++) {
1711 glm::vec3 offDiagonals = glm::abs(glm::vec3(d[1][0], d[2][0], d[2][1]));1711 glm::vec3 offDiagonals = glm::abs(glm::vec3(d[1][0], d[2][0], d[2][1]));
1712 int largestIndex = (offDiagonals[0] > offDiagonals[1]) ? (offDiagonals[0] > offDiagonals[2] ? 0 : 2) :1712 int largestIndex = (offDiagonals[0] > offDiagonals[1]) ? (offDiagonals[0] > offDiagonals[2] ? 0 : 2) :
1713 (offDiagonals[1] > offDiagonals[2] ? 1 : 2);1713 (offDiagonals[1] > offDiagonals[2] ? 1 : 2);
1714 const float DESIRED_PRECISION = 0.00001f;1714 const float DESIRED_PRECISION = 0.00001f;
1715 if (offDiagonals[largestIndex] < DESIRED_PRECISION) {1715 if (offDiagonals[largestIndex] < DESIRED_PRECISION) {
1716 break;1716 break;
1717 }1717 }
1718 int largestJ = (largestIndex == 2) ? 1 : 0;1718 int largestJ = (largestIndex == 2) ? 1 : 0;
1719 int largestI = (largestIndex == 0) ? 1 : 2;1719 int largestI = (largestIndex == 0) ? 1 : 2;
1720 float sjj = d[largestJ][largestJ];1720 float sjj = d[largestJ][largestJ];
1721 float sii = d[largestI][largestI];1721 float sii = d[largestI][largestI];
1722 float angle = glm::atan(2.0f * d[largestJ][largestI], sjj - sii) / 2.0f;1722 float angle = glm::atan(2.0f * d[largestJ][largestI], sjj - sii) / 2.0f;
1723 glm::quat rotation = glm::angleAxis(angle, largestIndex == 0 ? glm::vec3(0.0f, 0.0f, -1.0f) :1723 glm::quat rotation = glm::angleAxis(angle, largestIndex == 0 ? glm::vec3(0.0f, 0.0f, -1.0f) :
1724 (largestIndex == 1 ? glm::vec3(0.0f, 1.0f, 0.0f) : glm::vec3(-1.0f, 0.0f, 0.0f)));1724 (largestIndex == 1 ? glm::vec3(0.0f, 1.0f, 0.0f) : glm::vec3(-1.0f, 0.0f, 0.0f)));
1725 combinedRotation = glm::normalize(rotation * combinedRotation);1725 combinedRotation = glm::normalize(rotation * combinedRotation);
1726 glm::mat3 matrix = glm::mat3_cast(combinedRotation);1726 glm::mat3 matrix = glm::mat3_cast(combinedRotation);
1727 d = matrix * ata * glm::transpose(matrix);1727 d = matrix * ata * glm::transpose(matrix);
@@ -1735,7 +1735,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines
1735 1735
1736 // compute the pseudo-inverse, ataplus, and use to find the minimizing solution1736 // compute the pseudo-inverse, ataplus, and use to find the minimizing solution
1737 glm::mat3 u = glm::mat3_cast(combinedRotation);1737 glm::mat3 u = glm::mat3_cast(combinedRotation);
1738 glm::mat3 ataplus = glm::transpose(u) * d * u;1738 glm::mat3 ataplus = glm::transpose(u) * d * u;
1739 glm::vec3 solution = (ataplus * atrans * b) + center;1739 glm::vec3 solution = (ataplus * atrans * b) + center;
1740 1740
1741 // make sure it doesn't fall beyond the cell boundaries1741 // make sure it doesn't fall beyond the cell boundaries
@@ -1774,7 +1774,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 32 unmodified lines
1774 1774
1775 const glm::vec3& first = vertices.at(index.indices[0]).vertex;1775 const glm::vec3& first = vertices.at(index.indices[0]).vertex;
1776 glm::vec3 normal = glm::cross(vertices.at(index1.indices[0]).vertex - first,1776 glm::vec3 normal = glm::cross(vertices.at(index1.indices[0]).vertex - first,
1777 vertices.at(index3.indices[0]).vertex - first);1777 vertices.at(index3.indices[0]).vertex - first);
1778 1778
1779 if (alpha0 == 0) { // quad faces negative x1779 if (alpha0 == 0) { // quad faces negative x
1780 indices.append(index3.getClosestIndex(normal = -normal, vertices));1780 indices.append(index3.getClosestIndex(normal = -normal, vertices));
@@ -1800,7 +1800,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 19 unmodified lines
1800 1800
1801 const glm::vec3& first = vertices.at(index.indices[0]).vertex;1801 const glm::vec3& first = vertices.at(index.indices[0]).vertex;
1802 glm::vec3 normal = glm::cross(vertices.at(index3.indices[0]).vertex - first,1802 glm::vec3 normal = glm::cross(vertices.at(index3.indices[0]).vertex - first,
1803 vertices.at(index1.indices[0]).vertex - first);1803 vertices.at(index1.indices[0]).vertex - first);
1804 1804
1805 if (alpha0 == 0) { // quad faces negative y1805 if (alpha0 == 0) { // quad faces negative y
1806 indices.append(index1.getClosestIndex(normal = -normal, vertices));1806 indices.append(index1.getClosestIndex(normal = -normal, vertices));
@@ -1826,7 +1826,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 19 unmodified lines
1826 1826
1827 const glm::vec3& first = vertices.at(index.indices[0]).vertex;1827 const glm::vec3& first = vertices.at(index.indices[0]).vertex;
1828 glm::vec3 normal = glm::cross(vertices.at(index1.indices[0]).vertex - first,1828 glm::vec3 normal = glm::cross(vertices.at(index1.indices[0]).vertex - first,
1829 vertices.at(index3.indices[0]).vertex - first);1829 vertices.at(index3.indices[0]).vertex - first);
1830 1830
1831 if (alpha0 == 0) { // quad faces negative z1831 if (alpha0 == 0) { // quad faces negative z
1832 indices.append(index3.getClosestIndex(normal = -normal, vertices));1832 indices.append(index3.getClosestIndex(normal = -normal, vertices));
@@ -1861,7 +1861,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 28 unmodified lines
1861 }1861 }
1862 }1862 }
1863 buffer = new VoxelBuffer(vertices, indices, hermiteSegments, quadIndices, size,1863 buffer = new VoxelBuffer(vertices, indices, hermiteSegments, quadIndices, size,
1864 material ? material->getMaterials() : QVector<SharedObjectPointer>());1864 material ? material->getMaterials() : QVector<SharedObjectPointer>());
1865 }1865 }
1866 BufferDataPointer pointer(buffer);1866 BufferDataPointer pointer(buffer);
1867 info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));1867 info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));
@@ -1869,14 +1869,14 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 1 unmodified line
1869}1869}
1870 1870
1871void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous,1871void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous,
1872 MetavoxelInfo& info, const MetavoxelLOD& lod) {1872 MetavoxelInfo& info, const MetavoxelLOD& lod) {
1873 // copy the previous buffers1873 // copy the previous buffers
1874 MetavoxelData expandedPrevious = previous;1874 MetavoxelData expandedPrevious = previous;
1875 while (expandedPrevious.getSize() < data.getSize()) {1875 while (expandedPrevious.getSize() < data.getSize()) {
1876 expandedPrevious.expand();1876 expandedPrevious.expand();
1877 }1877 }
1878 const AttributePointer& voxelBufferAttribute =1878 const AttributePointer& voxelBufferAttribute =
1879 Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute();1879 Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute();
1880 MetavoxelNode* root = expandedPrevious.getRoot(voxelBufferAttribute);1880 MetavoxelNode* root = expandedPrevious.getRoot(voxelBufferAttribute);
1881 if (root) {1881 if (root) {
1882 data.setRoot(voxelBufferAttribute, root);1882 data.setRoot(voxelBufferAttribute, root);
@@ -1892,16 +1892,16 @@ public: · 9 unmodified lines
1892 SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod);1892 SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod);
1893 1893
1894 virtual bool visit(Spanner* spanner);1894 virtual bool visit(Spanner* spanner);
1895 1895
1896private:1896private:
1897 1897
1898 float _deltaTime;1898 float _deltaTime;
1899};1899};
1900 1900
1901SpannerSimulateVisitor::SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod) :1901SpannerSimulateVisitor::SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod) :
1902SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),1902 SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
1903 QVector<AttributePointer>(), QVector<AttributePointer>(), lod),1903 QVector<AttributePointer>(), QVector<AttributePointer>(), lod),
1904_deltaTime(deltaTime) {1904 _deltaTime(deltaTime) {
1905}1905}
1906 1906
1907bool SpannerSimulateVisitor::visit(Spanner* spanner) {1907bool SpannerSimulateVisitor::visit(Spanner* spanner) {
@@ -1910,7 +1910,7 @@ bool SpannerSimulateVisitor::visit(Spanner* spanner) { · 2 unmodified lines
1910}1910}
1911 1911
1912void DefaultMetavoxelRendererImplementation::simulate(MetavoxelData& data, float deltaTime,1912void DefaultMetavoxelRendererImplementation::simulate(MetavoxelData& data, float deltaTime,
1913 MetavoxelInfo& info, const MetavoxelLOD& lod) {1913 MetavoxelInfo& info, const MetavoxelLOD& lod) {
1914 SpannerSimulateVisitor spannerSimulateVisitor(deltaTime, lod);1914 SpannerSimulateVisitor spannerSimulateVisitor(deltaTime, lod);
1915 data.guide(spannerSimulateVisitor);1915 data.guide(spannerSimulateVisitor);
1916}1916}
@@ -1921,7 +1921,7 @@ public: · 4 unmodified lines
1921 BufferRenderVisitor(const AttributePointer& attribute);1921 BufferRenderVisitor(const AttributePointer& attribute);
1922 1922
1923 virtual int visit(MetavoxelInfo& info);1923 virtual int visit(MetavoxelInfo& info);
1924 1924
1925private:1925private:
1926 1926
1927 int _order;1927 int _order;
@@ -1929,15 +1929,15 @@ private: · 1 unmodified line
1929};1929};
1930 1930
1931BufferRenderVisitor::BufferRenderVisitor(const AttributePointer& attribute) :1931BufferRenderVisitor::BufferRenderVisitor(const AttributePointer& attribute) :
1932MetavoxelVisitor(QVector<AttributePointer>() << attribute),1932 MetavoxelVisitor(QVector<AttributePointer>() << attribute),
1933_order(encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())),1933 _order(encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())),
1934_containmentDepth(INT_MAX) {1934 _containmentDepth(INT_MAX) {
1935}1935}
1936 1936
1937int BufferRenderVisitor::visit(MetavoxelInfo& info) {1937int BufferRenderVisitor::visit(MetavoxelInfo& info) {
1938 if (_containmentDepth >= _depth) {1938 if (_containmentDepth >= _depth) {
1939 Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(1939 Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
1940 info.getBounds());1940 info.getBounds());
1941 if (intersection == Frustum::NO_INTERSECTION) {1941 if (intersection == Frustum::NO_INTERSECTION) {
1942 return STOP_RECURSION;1942 return STOP_RECURSION;
1943 }1943 }
@@ -2007,12 +2007,12 @@ void CuboidRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor · 63 unmodified lines
2007}2007}
2008 2008
2009StaticModelRenderer::StaticModelRenderer() :2009StaticModelRenderer::StaticModelRenderer() :
2010_model(new Model(this)) {2010 _model(new Model(this)) {
2011}2011}
2012 2012
2013void StaticModelRenderer::init(Spanner* spanner) {2013void StaticModelRenderer::init(Spanner* spanner) {
2014 SpannerRenderer::init(spanner);2014 SpannerRenderer::init(spanner);
2015 2015
2016 _model->init();2016 _model->init();
2017 2017
2018 StaticModel* staticModel = static_cast<StaticModel*>(spanner);2018 StaticModel* staticModel = static_cast<StaticModel*>(spanner);
@@ -2035,7 +2035,7 @@ void StaticModelRenderer::simulate(float deltaTime) { · 16 unmodified lines
2035 bounds = Box(extents.minimum, extents.maximum);2035 bounds = Box(extents.minimum, extents.maximum);
2036 }2036 }
2037 static_cast<StaticModel*>(_spanner)->setBounds(glm::translate(_model->getTranslation()) *2037 static_cast<StaticModel*>(_spanner)->setBounds(glm::translate(_model->getTranslation()) *
2038 glm::mat4_cast(_model->getRotation()) * glm::scale(_model->getScale()) * bounds);2038 glm::mat4_cast(_model->getRotation()) * glm::scale(_model->getScale()) * bounds);
2039 _model->simulate(deltaTime);2039 _model->simulate(deltaTime);
2040}2040}
2041 2041
@@ -2251,7 +2251,7 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g · 209 unmodified lines
2251 if (cursor) {2251 if (cursor) {
2252 bufferPair.first.bind();2252 bufferPair.first.bind();
2253 bufferPair.second.bind();2253 bufferPair.second.bind();
2254 2254
2255 glPushMatrix();2255 glPushMatrix();
2256 glTranslatef(translation.x, translation.y, translation.z);2256 glTranslatef(translation.x, translation.y, translation.z);
2257 glm::vec3 axis = glm::axis(rotation);2257 glm::vec3 axis = glm::axis(rotation);
@@ -2286,7 +2286,7 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g · 28 unmodified lines
2286 baseBatch.heightScale = glm::vec4(1.0f / width, 1.0f / height, (innerWidth - 1) / -2.0f, (innerHeight - 1) / -2.0f);2286 baseBatch.heightScale = glm::vec4(1.0f / width, 1.0f / height, (innerWidth - 1) / -2.0f, (innerHeight - 1) / -2.0f);
2287 baseBatch.colorTextureID = _colorTextureID;2287 baseBatch.colorTextureID = _colorTextureID;
2288 baseBatch.colorScale = glm::vec2((float)width / innerWidth, (float)height / innerHeight);2288 baseBatch.colorScale = glm::vec2((float)width / innerWidth, (float)height / innerHeight);
2289 Application::getInstance()->getMetavoxels()->addHeightfieldBaseBatch(baseBatch);2289 Application::getInstance()->getMetavoxels()->addHeightfieldBaseBatch(baseBatch);
2290 2290
2291 if (!_networkTextures.isEmpty()) {2291 if (!_networkTextures.isEmpty()) {
2292 HeightfieldSplatBatch splatBatch;2292 HeightfieldSplatBatch splatBatch;
@@ -2331,3 +2331,4 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g · 38 unmodified lines
2331}2331}
2332 2332
2333QHash<HeightfieldNodeRenderer::IntPair, HeightfieldNodeRenderer::BufferPair> HeightfieldNodeRenderer::_bufferPairs;2333QHash<HeightfieldNodeRenderer::IntPair, HeightfieldNodeRenderer::BufferPair> HeightfieldNodeRenderer::_bufferPairs;
2334

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t