diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index c998e2dbc6..2b731c2a27 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -144,10 +144,10 @@ void RenderablePolyVoxEntityItem::getModel() { PolyVox::SurfaceMesh polyVoxMesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. - PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor - (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - // PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + // PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor // (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); //Execute the surface extractor. surfaceExtractor.execute(); @@ -179,6 +179,11 @@ void RenderablePolyVoxEntityItem::getModel() { sizeof(PolyVox::PositionMaterialNormal), gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); + auto normalAttrib = mesh->getAttributeBuffer(gpu::Stream::NORMAL); + for (auto normal = normalAttrib.begin(); normal != normalAttrib.end(); normal++) { + (*normal) = -(*normal); + } + qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------" << usecTimestampNow(); qDebug() << "---- vecIndices.size() =" << vecIndices.size(); diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index 7f3f850339..c7763e108b 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -228,13 +228,14 @@ public: { public: - Iterator(T* ptr = NULL) { _ptr = ptr; } + Iterator(T* ptr = NULL, int stride = sizeof(T)): _ptr(ptr), _stride(stride) { } Iterator(const Iterator& iterator) = default; ~Iterator() {} Iterator& operator=(const Iterator& iterator) = default; Iterator& operator=(T* ptr) { _ptr = ptr; + // stride is left unchanged return (*this); } @@ -249,43 +250,49 @@ public: bool operator==(const Iterator& iterator) const { return (_ptr == iterator.getConstPtr()); } bool operator!=(const Iterator& iterator) const { return (_ptr != iterator.getConstPtr()); } + void movePtr(const Index& movement) { + auto byteptr = ((Byte*)_ptr); + byteptr += _stride * movement; + _ptr = (T*)byteptr; + } + Iterator& operator+=(const Index& movement) { - _ptr += movement; + movePtr(movement); return (*this); } Iterator& operator-=(const Index& movement) { - _ptr -= movement; + movePtr(-movement); return (*this); } Iterator& operator++() { - ++_ptr; + movePtr(1); return (*this); } Iterator& operator--() { - --_ptr; - return (*this); + movePtr(-1); + return (*this); } Iterator operator++(Index) { auto temp(*this); - ++_ptr; - return temp; + movePtr(1); + return temp; } Iterator operator--(Index) { auto temp(*this); - --_ptr; - return temp; + movePtr(-1); + return temp; } Iterator operator+(const Index& movement) { auto oldPtr = _ptr; - _ptr += movement; + movePtr(movement); auto temp(*this); _ptr = oldPtr; return temp; } Iterator operator-(const Index& movement) { auto oldPtr = _ptr; - _ptr -= movement; - auto temp(*this); + movePtr(-movement); + auto temp(*this); _ptr = oldPtr; return temp; } @@ -302,16 +309,17 @@ public: protected: T* _ptr; + int _stride = sizeof(T); }; - template Iterator begin() { return Iterator(&edit(0)); } - template Iterator end() { return Iterator(&edit(getNum())); } - template Iterator cbegin() const { return Iterator(&get(0)); } - template Iterator cend() const { return Iterator(&get(getNum())); } + template Iterator begin() { return Iterator(&edit(0), _stride); } + template Iterator end() { return Iterator(&edit(getNum()), _stride); } + template Iterator cbegin() const { return Iterator(&get(0), _stride); } + template Iterator cend() const { return Iterator(&get(getNum()), _stride); } // the number of elements of the specified type fitting in the view size template Index getNum() const { - return Index(_size / sizeof(T)); + return Index(_size / _stride); } template const T& get() const { @@ -347,7 +355,7 @@ public: } template const T& get(const Index index) const { - Resource::Size elementOffset = index * sizeof(T) + _offset; + Resource::Size elementOffset = index * _stride + _offset; #if _DEBUG if (!_buffer) { qDebug() << "Accessing null gpu::buffer!"; @@ -363,7 +371,7 @@ public: } template T& edit(const Index index) const { - Resource::Size elementOffset = index * sizeof(T) + _offset; + Resource::Size elementOffset = index * _stride + _offset; #if _DEBUG if (!_buffer) { qDebug() << "Accessing null gpu::buffer!"; diff --git a/libraries/model/src/model/Geometry.cpp b/libraries/model/src/model/Geometry.cpp index ed0201763a..7f0abbd9b9 100755 --- a/libraries/model/src/model/Geometry.cpp +++ b/libraries/model/src/model/Geometry.cpp @@ -42,6 +42,15 @@ void Mesh::addAttribute(Slot slot, const BufferView& buffer) { evalVertexFormat(); } +const BufferView Mesh::getAttributeBuffer(int attrib) const { + auto attribBuffer = _attributeBuffers.find(attrib); + if (attribBuffer != _attributeBuffers.end()) { + return attribBuffer->second; + } else { + return BufferView(); + } +} + void Mesh::evalVertexFormat() { auto vf = new VertexFormat(); int channelNum = 0; diff --git a/libraries/model/src/model/Geometry.h b/libraries/model/src/model/Geometry.h index 95f1c3bce7..736047e886 100755 --- a/libraries/model/src/model/Geometry.h +++ b/libraries/model/src/model/Geometry.h @@ -52,6 +52,7 @@ public: // Attribute Buffers int getNumAttributes() const { return _attributeBuffers.size(); } void addAttribute(Slot slot, const BufferView& buffer); + const BufferView getAttributeBuffer(int attrib) const; // Stream format const gpu::Stream::FormatPointer getVertexFormat() const { return _vertexFormat; } diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 54e5388ec8..795b2a4389 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -93,16 +93,16 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { } void DeferredLightingEffect::bindSimpleProgram() { - DependencyManager::get()->setPrimaryDrawBuffers(true, true, true); + // DependencyManager::get()->setPrimaryDrawBuffers(true, true, true); _simpleProgram.bind(); _simpleProgram.setUniformValue(_glowIntensityLocation, DependencyManager::get()->getIntensity()); - glDisable(GL_BLEND); + // glDisable(GL_BLEND); } void DeferredLightingEffect::releaseSimpleProgram() { - glEnable(GL_BLEND); + // glEnable(GL_BLEND); _simpleProgram.release(); - DependencyManager::get()->setPrimaryDrawBuffers(true, false, false); + // DependencyManager::get()->setPrimaryDrawBuffers(true, false, false); } void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color) {