Expeand the wireframe to the primitive entities and the polyvox

This commit is contained in:
samcake 2017-03-15 16:58:31 -07:00
parent ea2f1359bc
commit 0399249a03
6 changed files with 36 additions and 7 deletions

View file

@ -53,6 +53,8 @@
#include "PhysicalEntitySimulation.h" #include "PhysicalEntitySimulation.h"
gpu::PipelinePointer RenderablePolyVoxEntityItem::_pipeline = nullptr; gpu::PipelinePointer RenderablePolyVoxEntityItem::_pipeline = nullptr;
gpu::PipelinePointer RenderablePolyVoxEntityItem::_wireframePipeline = nullptr;
const float MARCHING_CUBE_COLLISION_HULL_OFFSET = 0.5; const float MARCHING_CUBE_COLLISION_HULL_OFFSET = 0.5;
@ -696,7 +698,7 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
!mesh->getIndexBuffer()._buffer) { !mesh->getIndexBuffer()._buffer) {
return; return;
} }
if (!_pipeline) { if (!_pipeline) {
gpu::ShaderPointer vertexShader = gpu::Shader::createVertex(std::string(polyvox_vert)); gpu::ShaderPointer vertexShader = gpu::Shader::createVertex(std::string(polyvox_vert));
gpu::ShaderPointer pixelShader = gpu::Shader::createPixel(std::string(polyvox_frag)); gpu::ShaderPointer pixelShader = gpu::Shader::createPixel(std::string(polyvox_frag));
@ -715,6 +717,13 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
state->setDepthTest(true, true, gpu::LESS_EQUAL); state->setDepthTest(true, true, gpu::LESS_EQUAL);
_pipeline = gpu::Pipeline::create(program, state); _pipeline = gpu::Pipeline::create(program, state);
auto wireframeState = std::make_shared<gpu::State>();
wireframeState->setCullMode(gpu::State::CULL_BACK);
wireframeState->setDepthTest(true, true, gpu::LESS_EQUAL);
wireframeState->setFillMode(gpu::State::FILL_LINE);
_wireframePipeline = gpu::Pipeline::create(program, wireframeState);
} }
if (!_vertexFormat) { if (!_vertexFormat) {
@ -725,7 +734,11 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
} }
gpu::Batch& batch = *args->_batch; gpu::Batch& batch = *args->_batch;
batch.setPipeline(_pipeline);
// Pick correct Pipeline
bool wireframe = (render::ShapeKey(args->_globalShapeKey).isWireframe());
auto pipeline = (wireframe ? _wireframePipeline : _pipeline);
batch.setPipeline(pipeline);
Transform transform(voxelToWorldMatrix()); Transform transform(voxelToWorldMatrix());
batch.setModelTransform(transform); batch.setModelTransform(transform);
@ -762,7 +775,7 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
batch.setResourceTexture(2, DependencyManager::get<TextureCache>()->getWhiteTexture()); batch.setResourceTexture(2, DependencyManager::get<TextureCache>()->getWhiteTexture());
} }
int voxelVolumeSizeLocation = _pipeline->getProgram()->getUniforms().findLocation("voxelVolumeSize"); int voxelVolumeSizeLocation = pipeline->getProgram()->getUniforms().findLocation("voxelVolumeSize");
batch._glUniform3f(voxelVolumeSizeLocation, voxelVolumeSize.x, voxelVolumeSize.y, voxelVolumeSize.z); batch._glUniform3f(voxelVolumeSizeLocation, voxelVolumeSize.x, voxelVolumeSize.y, voxelVolumeSize.z);
batch.drawIndexed(gpu::TRIANGLES, (gpu::uint32)mesh->getNumIndices(), 0); batch.drawIndexed(gpu::TRIANGLES, (gpu::uint32)mesh->getNumIndices(), 0);

View file

@ -163,6 +163,7 @@ private:
const int MATERIAL_GPU_SLOT = 3; const int MATERIAL_GPU_SLOT = 3;
render::ItemID _myItem{ render::Item::INVALID_ITEM_ID }; render::ItemID _myItem{ render::Item::INVALID_ITEM_ID };
static gpu::PipelinePointer _pipeline; static gpu::PipelinePointer _pipeline;
static gpu::PipelinePointer _wireframePipeline;
ShapeInfo _shapeInfo; ShapeInfo _shapeInfo;

View file

@ -114,13 +114,22 @@ void RenderableShapeEntityItem::render(RenderArgs* args) {
auto outColor = _procedural->getColor(color); auto outColor = _procedural->getColor(color);
outColor.a *= _procedural->isFading() ? Interpolate::calculateFadeRatio(_procedural->getFadeStartTime()) : 1.0f; outColor.a *= _procedural->isFading() ? Interpolate::calculateFadeRatio(_procedural->getFadeStartTime()) : 1.0f;
batch._glColor4f(outColor.r, outColor.g, outColor.b, outColor.a); batch._glColor4f(outColor.r, outColor.g, outColor.b, outColor.a);
DependencyManager::get<GeometryCache>()->renderShape(batch, MAPPING[_shape]); if (render::ShapeKey(args->_globalShapeKey).isWireframe()) {
DependencyManager::get<GeometryCache>()->renderWireShape(batch, MAPPING[_shape]);
} else {
DependencyManager::get<GeometryCache>()->renderShape(batch, MAPPING[_shape]);
}
} else { } else {
// FIXME, support instanced multi-shape rendering using multidraw indirect // FIXME, support instanced multi-shape rendering using multidraw indirect
color.a *= _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f; color.a *= _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f;
auto geometryCache = DependencyManager::get<GeometryCache>(); auto geometryCache = DependencyManager::get<GeometryCache>();
auto pipeline = color.a < 1.0f ? geometryCache->getTransparentShapePipeline() : geometryCache->getOpaqueShapePipeline(); auto pipeline = color.a < 1.0f ? geometryCache->getTransparentShapePipeline() : geometryCache->getOpaqueShapePipeline();
geometryCache->renderSolidShapeInstance(batch, MAPPING[_shape], color, pipeline);
if (render::ShapeKey(args->_globalShapeKey).isWireframe()) {
geometryCache->renderWireShapeInstance(batch, MAPPING[_shape], color, pipeline);
} else {
geometryCache->renderSolidShapeInstance(batch, MAPPING[_shape], color, pipeline);
}
} }
static const auto triCount = DependencyManager::get<GeometryCache>()->getShapeTriangleCount(MAPPING[_shape]); static const auto triCount = DependencyManager::get<GeometryCache>()->getShapeTriangleCount(MAPPING[_shape]);

View file

@ -265,9 +265,12 @@ void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderCont
keyBuilder.withWireframe(); keyBuilder.withWireframe();
} }
ShapeKey globalKey = keyBuilder.build(); ShapeKey globalKey = keyBuilder.build();
args->_globalShapeKey = globalKey._flags.to_ulong();
renderShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn, globalKey); renderShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn, globalKey);
args->_batch = nullptr; args->_batch = nullptr;
args->_globalShapeKey = 0;
}); });
config->setNumDrawn((int)inItems.size()); config->setNumDrawn((int)inItems.size());
@ -308,6 +311,7 @@ void DrawStateSortDeferred::run(const SceneContextPointer& sceneContext, const R
keyBuilder.withWireframe(); keyBuilder.withWireframe();
} }
ShapeKey globalKey = keyBuilder.build(); ShapeKey globalKey = keyBuilder.build();
args->_globalShapeKey = globalKey._flags.to_ulong();
if (_stateSort) { if (_stateSort) {
renderStateSortShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn, globalKey); renderStateSortShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn, globalKey);
@ -315,6 +319,7 @@ void DrawStateSortDeferred::run(const SceneContextPointer& sceneContext, const R
renderShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn, globalKey); renderShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn, globalKey);
} }
args->_batch = nullptr; args->_batch = nullptr;
args->_globalShapeKey = 0;
}); });
config->setNumDrawn((int)inItems.size()); config->setNumDrawn((int)inItems.size());

View file

@ -148,7 +148,7 @@ public:
bool isSkinned() const { return _flags[SKINNED]; } bool isSkinned() const { return _flags[SKINNED]; }
bool isDepthOnly() const { return _flags[DEPTH_ONLY]; } bool isDepthOnly() const { return _flags[DEPTH_ONLY]; }
bool isDepthBiased() const { return _flags[DEPTH_BIAS]; } bool isDepthBiased() const { return _flags[DEPTH_BIAS]; }
bool isWireFrame() const { return _flags[WIREFRAME]; } bool isWireframe() const { return _flags[WIREFRAME]; }
bool isCullFace() const { return !_flags[NO_CULL_FACE]; } bool isCullFace() const { return !_flags[NO_CULL_FACE]; }
bool hasOwnPipeline() const { return _flags[OWN_PIPELINE]; } bool hasOwnPipeline() const { return _flags[OWN_PIPELINE]; }
@ -184,7 +184,7 @@ inline QDebug operator<<(QDebug debug, const ShapeKey& key) {
<< "isSkinned:" << key.isSkinned() << "isSkinned:" << key.isSkinned()
<< "isDepthOnly:" << key.isDepthOnly() << "isDepthOnly:" << key.isDepthOnly()
<< "isDepthBiased:" << key.isDepthBiased() << "isDepthBiased:" << key.isDepthBiased()
<< "isWireFrame:" << key.isWireFrame() << "isWireframe:" << key.isWireframe()
<< "isCullFace:" << key.isCullFace() << "isCullFace:" << key.isCullFace()
<< "]"; << "]";
} }

View file

@ -122,6 +122,7 @@ public:
gpu::Batch* _batch = nullptr; gpu::Batch* _batch = nullptr;
std::shared_ptr<gpu::Texture> _whiteTexture; std::shared_ptr<gpu::Texture> _whiteTexture;
uint32_t _globalShapeKey { 0 };
bool _enableTexturing { true }; bool _enableTexturing { true };
RenderDetails _details; RenderDetails _details;