mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 11:33:44 +02:00
changes sam made to get normals to work on a mesh
This commit is contained in:
parent
d71921fd03
commit
728e6d121b
5 changed files with 50 additions and 27 deletions
|
@ -144,10 +144,10 @@ void RenderablePolyVoxEntityItem::getModel() {
|
|||
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
|
||||
|
||||
//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
|
||||
(_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
|
||||
// PolyVox::MarchingCubesSurfaceExtractor<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);
|
||||
|
||||
//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<glm::vec3>(); normal != normalAttrib.end<glm::vec3>(); normal++) {
|
||||
(*normal) = -(*normal);
|
||||
}
|
||||
|
||||
|
||||
qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------" << usecTimestampNow();
|
||||
qDebug() << "---- vecIndices.size() =" << vecIndices.size();
|
||||
|
|
|
@ -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<T>& iterator) = default;
|
||||
~Iterator() {}
|
||||
|
||||
Iterator<T>& operator=(const Iterator<T>& iterator) = default;
|
||||
Iterator<T>& operator=(T* ptr) {
|
||||
_ptr = ptr;
|
||||
// stride is left unchanged
|
||||
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()); }
|
||||
|
||||
void movePtr(const Index& movement) {
|
||||
auto byteptr = ((Byte*)_ptr);
|
||||
byteptr += _stride * movement;
|
||||
_ptr = (T*)byteptr;
|
||||
}
|
||||
|
||||
Iterator<T>& operator+=(const Index& movement) {
|
||||
_ptr += movement;
|
||||
movePtr(movement);
|
||||
return (*this);
|
||||
}
|
||||
Iterator<T>& operator-=(const Index& movement) {
|
||||
_ptr -= movement;
|
||||
movePtr(-movement);
|
||||
return (*this);
|
||||
}
|
||||
Iterator<T>& operator++() {
|
||||
++_ptr;
|
||||
movePtr(1);
|
||||
return (*this);
|
||||
}
|
||||
Iterator<T>& operator--() {
|
||||
--_ptr;
|
||||
return (*this);
|
||||
movePtr(-1);
|
||||
return (*this);
|
||||
}
|
||||
Iterator<T> operator++(Index) {
|
||||
auto temp(*this);
|
||||
++_ptr;
|
||||
return temp;
|
||||
movePtr(1);
|
||||
return temp;
|
||||
}
|
||||
Iterator<T> operator--(Index) {
|
||||
auto temp(*this);
|
||||
--_ptr;
|
||||
return temp;
|
||||
movePtr(-1);
|
||||
return temp;
|
||||
}
|
||||
Iterator<T> operator+(const Index& movement) {
|
||||
auto oldPtr = _ptr;
|
||||
_ptr += movement;
|
||||
movePtr(movement);
|
||||
auto temp(*this);
|
||||
_ptr = oldPtr;
|
||||
return temp;
|
||||
}
|
||||
Iterator<T> 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 <typename T> Iterator<T> begin() { return Iterator<T>(&edit<T>(0)); }
|
||||
template <typename T> Iterator<T> end() { return Iterator<T>(&edit<T>(getNum<T>())); }
|
||||
template <typename T> Iterator<const T> cbegin() const { return Iterator<const T>(&get<T>(0)); }
|
||||
template <typename T> Iterator<const T> cend() const { return Iterator<const T>(&get<T>(getNum<T>())); }
|
||||
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>()), _stride); }
|
||||
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>()), _stride); }
|
||||
|
||||
// the number of elements of the specified type fitting in the view size
|
||||
template <typename T> Index getNum() const {
|
||||
return Index(_size / sizeof(T));
|
||||
return Index(_size / _stride);
|
||||
}
|
||||
|
||||
template <typename T> const T& get() const {
|
||||
|
@ -347,7 +355,7 @@ public:
|
|||
}
|
||||
|
||||
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 (!_buffer) {
|
||||
qDebug() << "Accessing null gpu::buffer!";
|
||||
|
@ -363,7 +371,7 @@ public:
|
|||
}
|
||||
|
||||
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 (!_buffer) {
|
||||
qDebug() << "Accessing null gpu::buffer!";
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -93,16 +93,16 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
|
|||
}
|
||||
|
||||
void DeferredLightingEffect::bindSimpleProgram() {
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, true, true);
|
||||
// DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, true, true);
|
||||
_simpleProgram.bind();
|
||||
_simpleProgram.setUniformValue(_glowIntensityLocation, DependencyManager::get<GlowEffect>()->getIntensity());
|
||||
glDisable(GL_BLEND);
|
||||
// glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void DeferredLightingEffect::releaseSimpleProgram() {
|
||||
glEnable(GL_BLEND);
|
||||
// glEnable(GL_BLEND);
|
||||
_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) {
|
||||
|
|
Loading…
Reference in a new issue