changes sam made to get normals to work on a mesh

This commit is contained in:
Seth Alves 2015-05-26 14:12:01 -07:00
parent d71921fd03
commit 728e6d121b
5 changed files with 50 additions and 27 deletions

View file

@ -144,10 +144,10 @@ void RenderablePolyVoxEntityItem::getModel() {
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh; PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created. //Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor // PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
(_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
// PolyVox::MarchingCubesSurfaceExtractor<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
// (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); // (_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
PolyVox::MarchingCubesSurfaceExtractor<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
(_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
//Execute the surface extractor. //Execute the surface extractor.
surfaceExtractor.execute(); surfaceExtractor.execute();
@ -179,6 +179,11 @@ void RenderablePolyVoxEntityItem::getModel() {
sizeof(PolyVox::PositionMaterialNormal), sizeof(PolyVox::PositionMaterialNormal),
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)));
auto normalAttrib = mesh->getAttributeBuffer(gpu::Stream::NORMAL);
for (auto normal = normalAttrib.begin<glm::vec3>(); normal != normalAttrib.end<glm::vec3>(); normal++) {
(*normal) = -(*normal);
}
qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------" << usecTimestampNow(); qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------" << usecTimestampNow();
qDebug() << "---- vecIndices.size() =" << vecIndices.size(); qDebug() << "---- vecIndices.size() =" << vecIndices.size();

View file

@ -228,13 +228,14 @@ public:
{ {
public: public:
Iterator(T* ptr = NULL) { _ptr = ptr; } Iterator(T* ptr = NULL, int stride = sizeof(T)): _ptr(ptr), _stride(stride) { }
Iterator(const Iterator<T>& iterator) = default; Iterator(const Iterator<T>& iterator) = default;
~Iterator() {} ~Iterator() {}
Iterator<T>& operator=(const Iterator<T>& iterator) = default; Iterator<T>& operator=(const Iterator<T>& iterator) = default;
Iterator<T>& operator=(T* ptr) { Iterator<T>& operator=(T* ptr) {
_ptr = ptr; _ptr = ptr;
// stride is left unchanged
return (*this); return (*this);
} }
@ -249,43 +250,49 @@ public:
bool operator==(const Iterator<T>& iterator) const { return (_ptr == iterator.getConstPtr()); } bool operator==(const Iterator<T>& iterator) const { return (_ptr == iterator.getConstPtr()); }
bool operator!=(const Iterator<T>& iterator) const { return (_ptr != iterator.getConstPtr()); } bool operator!=(const Iterator<T>& iterator) const { return (_ptr != iterator.getConstPtr()); }
void movePtr(const Index& movement) {
auto byteptr = ((Byte*)_ptr);
byteptr += _stride * movement;
_ptr = (T*)byteptr;
}
Iterator<T>& operator+=(const Index& movement) { Iterator<T>& operator+=(const Index& movement) {
_ptr += movement; movePtr(movement);
return (*this); return (*this);
} }
Iterator<T>& operator-=(const Index& movement) { Iterator<T>& operator-=(const Index& movement) {
_ptr -= movement; movePtr(-movement);
return (*this); return (*this);
} }
Iterator<T>& operator++() { Iterator<T>& operator++() {
++_ptr; movePtr(1);
return (*this); return (*this);
} }
Iterator<T>& operator--() { Iterator<T>& operator--() {
--_ptr; movePtr(-1);
return (*this); return (*this);
} }
Iterator<T> operator++(Index) { Iterator<T> operator++(Index) {
auto temp(*this); auto temp(*this);
++_ptr; movePtr(1);
return temp; return temp;
} }
Iterator<T> operator--(Index) { Iterator<T> operator--(Index) {
auto temp(*this); auto temp(*this);
--_ptr; movePtr(-1);
return temp; return temp;
} }
Iterator<T> operator+(const Index& movement) { Iterator<T> operator+(const Index& movement) {
auto oldPtr = _ptr; auto oldPtr = _ptr;
_ptr += movement; movePtr(movement);
auto temp(*this); auto temp(*this);
_ptr = oldPtr; _ptr = oldPtr;
return temp; return temp;
} }
Iterator<T> operator-(const Index& movement) { Iterator<T> operator-(const Index& movement) {
auto oldPtr = _ptr; auto oldPtr = _ptr;
_ptr -= movement; movePtr(-movement);
auto temp(*this); auto temp(*this);
_ptr = oldPtr; _ptr = oldPtr;
return temp; return temp;
} }
@ -302,16 +309,17 @@ public:
protected: protected:
T* _ptr; T* _ptr;
int _stride = sizeof(T);
}; };
template <typename T> Iterator<T> begin() { return Iterator<T>(&edit<T>(0)); } template <typename T> Iterator<T> begin() { return Iterator<T>(&edit<T>(0), _stride); }
template <typename T> Iterator<T> end() { return Iterator<T>(&edit<T>(getNum<T>())); } template <typename T> Iterator<T> end() { return Iterator<T>(&edit<T>(getNum<T>()), _stride); }
template <typename T> Iterator<const T> cbegin() const { return Iterator<const T>(&get<T>(0)); } template <typename T> Iterator<const T> cbegin() const { return Iterator<const T>(&get<T>(0), _stride); }
template <typename T> Iterator<const T> cend() const { return Iterator<const T>(&get<T>(getNum<T>())); } template <typename T> Iterator<const T> cend() const { return Iterator<const T>(&get<T>(getNum<T>()), _stride); }
// the number of elements of the specified type fitting in the view size // the number of elements of the specified type fitting in the view size
template <typename T> Index getNum() const { template <typename T> Index getNum() const {
return Index(_size / sizeof(T)); return Index(_size / _stride);
} }
template <typename T> const T& get() const { template <typename T> const T& get() const {
@ -347,7 +355,7 @@ public:
} }
template <typename T> const T& get(const Index index) const { template <typename T> const T& get(const Index index) const {
Resource::Size elementOffset = index * sizeof(T) + _offset; Resource::Size elementOffset = index * _stride + _offset;
#if _DEBUG #if _DEBUG
if (!_buffer) { if (!_buffer) {
qDebug() << "Accessing null gpu::buffer!"; qDebug() << "Accessing null gpu::buffer!";
@ -363,7 +371,7 @@ public:
} }
template <typename T> T& edit(const Index index) const { template <typename T> T& edit(const Index index) const {
Resource::Size elementOffset = index * sizeof(T) + _offset; Resource::Size elementOffset = index * _stride + _offset;
#if _DEBUG #if _DEBUG
if (!_buffer) { if (!_buffer) {
qDebug() << "Accessing null gpu::buffer!"; qDebug() << "Accessing null gpu::buffer!";

View file

@ -42,6 +42,15 @@ void Mesh::addAttribute(Slot slot, const BufferView& buffer) {
evalVertexFormat(); 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() { void Mesh::evalVertexFormat() {
auto vf = new VertexFormat(); auto vf = new VertexFormat();
int channelNum = 0; int channelNum = 0;

View file

@ -52,6 +52,7 @@ public:
// Attribute Buffers // Attribute Buffers
int getNumAttributes() const { return _attributeBuffers.size(); } int getNumAttributes() const { return _attributeBuffers.size(); }
void addAttribute(Slot slot, const BufferView& buffer); void addAttribute(Slot slot, const BufferView& buffer);
const BufferView getAttributeBuffer(int attrib) const;
// Stream format // Stream format
const gpu::Stream::FormatPointer getVertexFormat() const { return _vertexFormat; } const gpu::Stream::FormatPointer getVertexFormat() const { return _vertexFormat; }

View file

@ -93,16 +93,16 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
} }
void DeferredLightingEffect::bindSimpleProgram() { void DeferredLightingEffect::bindSimpleProgram() {
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, true, true); // DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, true, true);
_simpleProgram.bind(); _simpleProgram.bind();
_simpleProgram.setUniformValue(_glowIntensityLocation, DependencyManager::get<GlowEffect>()->getIntensity()); _simpleProgram.setUniformValue(_glowIntensityLocation, DependencyManager::get<GlowEffect>()->getIntensity());
glDisable(GL_BLEND); // glDisable(GL_BLEND);
} }
void DeferredLightingEffect::releaseSimpleProgram() { void DeferredLightingEffect::releaseSimpleProgram() {
glEnable(GL_BLEND); // glEnable(GL_BLEND);
_simpleProgram.release(); _simpleProgram.release();
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, false, false); // DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, false, false);
} }
void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color) { void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color) {