History

possible fix for gl crash

SamGondelman committed 8 years ago

Commit 9dfc61a1 parent 937955d1 file · +39 −4Browse files

Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 1 file). Show all

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+39−4
@@ -122,6 +122,9 @@ static const gpu::Element TEXCOORD4_ELEMENT { gpu::VEC4, gpu::FLOAT, gpu::XYZW } · 121 unmodified lines
122122 static gpu::Stream::FormatPointer SOLID_STREAM_FORMAT;
123123 static gpu::Stream::FormatPointer INSTANCED_SOLID_STREAM_FORMAT;
124124 static gpu::Stream::FormatPointer INSTANCED_SOLID_FADE_STREAM_FORMAT;
125+static gpu::Stream::FormatPointer WIRE_STREAM_FORMAT;
126+static gpu::Stream::FormatPointer INSTANCED_WIRE_STREAM_FORMAT;
127+static gpu::Stream::FormatPointer INSTANCED_WIRE_FADE_STREAM_FORMAT;
125128
126129 static const uint SHAPE_VERTEX_STRIDE = sizeof(GeometryCache::ShapeVertex); // position, normal, texcoords, tangent
127130 static const uint SHAPE_NORMALS_OFFSET = offsetof(GeometryCache::ShapeVertex, normal);
@@ -690,6 +693,38 @@ gpu::Stream::FormatPointer& getInstancedSolidFadeStreamFormat() { · 562 unmodified lines
690693 return INSTANCED_SOLID_FADE_STREAM_FORMAT;
691694 }
692695
696+gpu::Stream::FormatPointer& getWireStreamFormat() {
697+ if (!WIRE_STREAM_FORMAT) {
698+ WIRE_STREAM_FORMAT = std::make_shared<gpu::Stream::Format>(); // 1 for everyone
699+ WIRE_STREAM_FORMAT->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, POSITION_ELEMENT);
700+ WIRE_STREAM_FORMAT->setAttribute(gpu::Stream::NORMAL, gpu::Stream::NORMAL, NORMAL_ELEMENT);
701+ }
702+ return WIRE_STREAM_FORMAT;
703+}
704+
705+gpu::Stream::FormatPointer& getInstancedWireStreamFormat() {
706+ if (!INSTANCED_WIRE_STREAM_FORMAT) {
707+ INSTANCED_WIRE_STREAM_FORMAT = std::make_shared<gpu::Stream::Format>(); // 1 for everyone
708+ INSTANCED_WIRE_STREAM_FORMAT->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, POSITION_ELEMENT);
709+ INSTANCED_WIRE_STREAM_FORMAT->setAttribute(gpu::Stream::NORMAL, gpu::Stream::NORMAL, NORMAL_ELEMENT);
710+ INSTANCED_WIRE_STREAM_FORMAT->setAttribute(gpu::Stream::COLOR, gpu::Stream::COLOR, COLOR_ELEMENT, 0, gpu::Stream::PER_INSTANCE);
711+ }
712+ return INSTANCED_WIRE_STREAM_FORMAT;
713+}
714+
715+gpu::Stream::FormatPointer& getInstancedWireFadeStreamFormat() {
716+ if (!INSTANCED_WIRE_FADE_STREAM_FORMAT) {
717+ INSTANCED_WIRE_FADE_STREAM_FORMAT = std::make_shared<gpu::Stream::Format>(); // 1 for everyone
718+ INSTANCED_WIRE_FADE_STREAM_FORMAT->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, POSITION_ELEMENT);
719+ INSTANCED_WIRE_FADE_STREAM_FORMAT->setAttribute(gpu::Stream::NORMAL, gpu::Stream::NORMAL, NORMAL_ELEMENT);
720+ INSTANCED_WIRE_FADE_STREAM_FORMAT->setAttribute(gpu::Stream::COLOR, gpu::Stream::COLOR, COLOR_ELEMENT, 0, gpu::Stream::PER_INSTANCE);
721+ INSTANCED_WIRE_FADE_STREAM_FORMAT->setAttribute(gpu::Stream::TEXCOORD2, gpu::Stream::TEXCOORD2, TEXCOORD4_ELEMENT, 0, gpu::Stream::PER_INSTANCE);
722+ INSTANCED_WIRE_FADE_STREAM_FORMAT->setAttribute(gpu::Stream::TEXCOORD3, gpu::Stream::TEXCOORD3, TEXCOORD4_ELEMENT, 0, gpu::Stream::PER_INSTANCE);
723+ INSTANCED_WIRE_FADE_STREAM_FORMAT->setAttribute(gpu::Stream::TEXCOORD4, gpu::Stream::TEXCOORD4, TEXCOORD4_ELEMENT, 0, gpu::Stream::PER_INSTANCE);
724+ }
725+ return INSTANCED_WIRE_FADE_STREAM_FORMAT;
726+}
727+
693728 QHash<SimpleProgramKey, gpu::PipelinePointer> GeometryCache::_simplePrograms;
694729
695730 gpu::ShaderPointer GeometryCache::_simpleShader;
@@ -827,7 +862,7 @@ void GeometryCache::renderShape(gpu::Batch& batch, Shape shape) { · 131 unmodified lines
827862 }
828863
829864 void GeometryCache::renderWireShape(gpu::Batch& batch, Shape shape) {
830− batch.setInputFormat(getSolidStreamFormat());
865+ batch.setInputFormat(getWireStreamFormat());
831866 _shapes[shape].drawWire(batch);
832867 }
833868
@@ -839,7 +874,7 @@ void GeometryCache::renderShape(gpu::Batch& batch, Shape shape, const glm::vec4& · 5 unmodified lines
839874 }
840875
841876 void GeometryCache::renderWireShape(gpu::Batch& batch, Shape shape, const glm::vec4& color) {
842− batch.setInputFormat(getSolidStreamFormat());
877+ batch.setInputFormat(getWireStreamFormat());
843878 // Color must be set after input format
844879 batch._glColor4f(color.r, color.g, color.b, color.a);
845880 _shapes[shape].drawWire(batch);
@@ -857,7 +892,7 @@ void GeometryCache::renderShapeInstances(gpu::Batch& batch, Shape shape, size_t · 11 unmodified lines
857892 }
858893
859894 void GeometryCache::renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer) {
860− batch.setInputFormat(getInstancedSolidStreamFormat());
895+ batch.setInputFormat(getInstancedWireStreamFormat());
861896 setupBatchInstance(batch, colorBuffer);
862897 _shapes[shape].drawWireInstances(batch, count);
863898 }
@@ -883,7 +918,7 @@ void GeometryCache::renderFadeShapeInstances(gpu::Batch& batch, Shape shape, siz · 19 unmodified lines
883918
884919 void GeometryCache::renderWireFadeShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer,
885920 gpu::BufferPointer& fadeBuffer1, gpu::BufferPointer& fadeBuffer2, gpu::BufferPointer& fadeBuffer3) {
886− batch.setInputFormat(getInstancedSolidFadeStreamFormat());
921+ batch.setInputFormat(getInstancedWireFadeStreamFormat());
887922 setupBatchFadeInstance(batch, colorBuffer, fadeBuffer1, fadeBuffer2, fadeBuffer3);
888923 _shapes[shape].drawWireInstances(batch, count);
889924 }