Back to shapeContext, compiling

This commit is contained in:
Zach Pomerantz 2016-01-05 11:35:28 -08:00
parent cf35974f02
commit 63444aac72
11 changed files with 73 additions and 67 deletions

View file

@ -129,7 +129,7 @@ void MeshPartPayload::bindMesh(gpu::Batch& batch) const {
}
}
void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locations* locations) const {
void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::LocationsPointer locations) const {
if (!_drawMaterial) {
return;
}
@ -162,7 +162,7 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
if (materialKey.isNormalMap()) {
auto normalMap = textureMaps[model::MaterialKey::NORMAL_MAP];
if (normalMap && normalMap->isDefined()) {
batch.setResourceTexture(ShapePipeline::Slots::::NORMAL_MAP, normalMap->getTextureView());
batch.setResourceTexture(ShapePipeline::Slots::NORMAL_MAP, normalMap->getTextureView());
// texcoord are assumed to be the same has diffuse
} else {
@ -183,7 +183,7 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
batch.setResourceTexture(ShapePipeline::Slots::SPECULAR_MAP, textureCache->getBlackTexture());
}
} else {
batch.setResourceTexture(ShapePipeline::SPECULAR_MAP, nullptr);
batch.setResourceTexture(ShapePipeline::Slots::SPECULAR_MAP, nullptr);
}
// TODO: For now lightmaop is piped into the emissive map unit, we need to fix that and support for real emissive too
@ -191,7 +191,7 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
auto lightmapMap = textureMaps[model::MaterialKey::LIGHTMAP_MAP];
if (lightmapMap && lightmapMap->isDefined()) {
batch.setResourceTexture(ShapePipeline::LIGHTMAP_MAP, lightmapMap->getTextureView());
batch.setResourceTexture(ShapePipeline::Slots::LIGHTMAP_MAP, lightmapMap->getTextureView());
auto lightmapOffsetScale = lightmapMap->getLightmapOffsetScale();
batch._glUniform2f(locations->emissiveParams, lightmapOffsetScale.x, lightmapOffsetScale.y);
@ -200,10 +200,10 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
lightmapMap->getTextureTransform().getMatrix(texcoordTransform[1]);
}
} else {
batch.setResourceTexture(ShapePipeline::LIGHTMAP_MAP, textureCache->getGrayTexture());
batch.setResourceTexture(ShapePipeline::Slots::LIGHTMAP_MAP, textureCache->getGrayTexture());
}
} else {
batch.setResourceTexture(ShapePipeline::LIGHTMAP_MAP, nullptr);
batch.setResourceTexture(ShapePipeline::Slots::LIGHTMAP_MAP, nullptr);
}
// Texcoord transforms ?
@ -212,7 +212,7 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
}
}
void MeshPartPayload::bindTransform(gpu::Batch& batch, const ShapePipeline::Locations* locations) const {
void MeshPartPayload::bindTransform(gpu::Batch& batch, const ShapePipeline::LocationsPointer locations) const {
batch.setModelTransform(_drawTransform);
}
@ -431,16 +431,16 @@ void ModelMeshPartPayload::bindMesh(gpu::Batch& batch) const {
}
}
void ModelMeshPartPayload::bindTransform(gpu::Batch& batch, const ShapePipeline::Locations* locations) const {
void ModelMeshPartPayload::bindTransform(gpu::Batch& batch, const ShapePipeline::LocationsPointer locations) const {
// Still relying on the raw data from the model
const Model::MeshState& state = _model->_meshStates.at(_meshIndex);
Transform transform;
if (state.clusterBuffer) {
if (_model->_cauterizeBones) {
batch.setUniformBuffer(ShapePipeline::SKINNING_GPU, state.cauterizedClusterBuffer);
batch.setUniformBuffer(ShapePipeline::Slots::SKINNING_GPU, state.cauterizedClusterBuffer);
} else {
batch.setUniformBuffer(ShapePipeline::SKINNING_GPU, state.clusterBuffer);
batch.setUniformBuffer(ShapePipeline::Slots::SKINNING_GPU, state.clusterBuffer);
}
} else {
if (_model->_cauterizeBones) {

View file

@ -46,8 +46,8 @@ public:
// ModelMeshPartPayload functions to perform render
void drawCall(gpu::Batch& batch) const;
virtual void bindMesh(gpu::Batch& batch) const;
virtual void bindMaterial(gpu::Batch& batch, const render::ShapePipeline::Locations* locations) const;
virtual void bindTransform(gpu::Batch& batch, const render::ShapePipeline::Locations* locations) const;
virtual void bindMaterial(gpu::Batch& batch, const render::ShapePipeline::LocationsPointer locations) const;
virtual void bindTransform(gpu::Batch& batch, const render::ShapePipeline::LocationsPointer locations) const;
// Payload resource cached values
model::MeshPointer _drawMesh;
@ -89,7 +89,7 @@ public:
// ModelMeshPartPayload functions to perform render
void bindMesh(gpu::Batch& batch) const override;
void bindTransform(gpu::Batch& batch, const render::ShapePipeline::Locations* locations) const override;
void bindTransform(gpu::Batch& batch, const render::ShapePipeline::LocationsPointer locations) const override;
void initCache();

View file

@ -1193,7 +1193,7 @@ void Model::segregateMeshGroups() {
int totalParts = mesh.parts.size();
for (int partIndex = 0; partIndex < totalParts; partIndex++) {
if (showingCollisionHull) {
_renderItemsSet << std::make_shared<MeshPartPayload>(networkMesh._mesh, partIndex, ModelRender::getCollisionHullMaterial(), transform, offset);
_renderItemsSet << std::make_shared<MeshPartPayload>(networkMesh._mesh, partIndex, ShapeRender::getCollisionHullMaterial(), transform, offset);
} else {
_renderItemsSet << std::make_shared<ModelMeshPartPayload>(this, i, partIndex, shapeID, transform, offset);

View file

@ -177,7 +177,7 @@ void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const Rend
assert(renderContext->getArgs()->_viewFrustum);
RenderArgs* args = renderContext->getArgs();
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
batch.setViewportTransform(args->_viewport);
batch.setStateScissorRect(args->_viewport);
args->_batch = &batch;
@ -193,7 +193,7 @@ void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const Rend
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat);
renderShapes(sceneContext, renderContext, _context, inItems, opaque.maxDrawn);
renderShapes(sceneContext, renderContext, _renderer, inItems, opaque.maxDrawn);
args->_batch = nullptr;
});
}
@ -203,7 +203,7 @@ void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const
assert(renderContext->getArgs()->_viewFrustum);
RenderArgs* args = renderContext->getArgs();
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
batch.setViewportTransform(args->_viewport);
batch.setStateScissorRect(args->_viewport);
args->_batch = &batch;
@ -219,7 +219,7 @@ void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat);
renderShapes(sceneContext, renderContext, _context, inItems, transparent.maxDrawn);
renderShapes(sceneContext, renderContext, _renderer, inItems, transparent.maxDrawn);
args->_batch = nullptr;
});
}
@ -276,7 +276,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon
}
// Render the items
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
args->_batch = &batch;
args->_whiteTexture = DependencyManager::get<TextureCache>()->getWhiteTexture();
@ -292,7 +292,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon
batch.setPipeline(getOpaquePipeline());
batch.setResourceTexture(0, args->_whiteTexture);
renderShapes(sceneContext, renderContext, _context, inItems, renderContext->getItemsConfig().overlay3D.maxDrawn);
renderShapes(sceneContext, renderContext, _renderer, inItems, renderContext->getItemsConfig().overlay3D.maxDrawn);
});
args->_batch = nullptr;
args->_whiteTexture.reset();

View file

@ -51,7 +51,7 @@ public:
};
class DrawOpaqueDeferred {
class JobContext : public render::Job::Context, public ShapeRender {} _context;
ShapeRender _renderer;
public:
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const render::ItemIDsBounds& inItems);
@ -59,7 +59,7 @@ public:
};
class DrawTransparentDeferred {
class JobContext : public render::Job::Context, public ShapeRender {} _context;
ShapeRender _renderer;
public:
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const render::ItemIDsBounds& inItems);
@ -85,8 +85,7 @@ public:
class DrawOverlay3D {
static gpu::PipelinePointer _opaquePipeline; //lazy evaluation hence mutable
class JobContext : public render::Job::Context, public ShapeRender {} _context;
ShapeRender _renderer;
public:
static const gpu::PipelinePointer& getOpaquePipeline();

View file

@ -37,7 +37,7 @@
#include "model_lightmap_specular_map_frag.h"
#include "model_translucent_frag.h"
void ShapeRender::ShapeRender() {
ShapeRender::ShapeRender() {
// TODO: There is probably a cleaner way to init the pipeline that in a derived class
if (_pipelineLib.empty()) {
initPipeline();
@ -72,104 +72,105 @@ void ShapeRender::initPipeline() {
// Fill the pipelineLib
_pipelineLib.addPipeline(
RenderKey(0),
Key::Builder(),
modelVertex, modelPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::HAS_TANGENTS),
Key::Builder().withTangents(),
modelNormalMapVertex, modelNormalMapPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::HAS_SPECULAR),
Key::Builder().withSpecular(),
modelVertex, modelSpecularMapPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR),
Key::Builder().withTangents().withSpecular(),
modelNormalMapVertex, modelNormalSpecularMapPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_TRANSLUCENT),
Key::Builder().withTranslucent(),
modelVertex, modelTranslucentPixel);
// FIXME Ignore lightmap for translucents meshpart
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_TRANSLUCENT | RenderKey::HAS_LIGHTMAP),
Key::Builder().withTranslucent().withLightmap(),
modelVertex, modelTranslucentPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::HAS_TANGENTS | RenderKey::IS_TRANSLUCENT),
Key::Builder().withTangents().withTranslucent(),
modelNormalMapVertex, modelTranslucentPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT),
Key::Builder().withSpecular().withTranslucent(),
modelVertex, modelTranslucentPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT),
Key::Builder().withTangents().withSpecular().withTranslucent(),
modelNormalMapVertex, modelTranslucentPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::HAS_LIGHTMAP),
Key::Builder().withLightmap(),
modelLightmapVertex, modelLightmapPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_TANGENTS),
Key::Builder().withLightmap().withTangents(),
modelLightmapNormalMapVertex, modelLightmapNormalMapPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_SPECULAR),
Key::Builder().withLightmap().withSpecular(),
modelLightmapVertex, modelLightmapSpecularMapPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR),
Key::Builder().withLightmap().withTangents().withSpecular(),
modelLightmapNormalMapVertex, modelLightmapNormalSpecularMapPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_SKINNED),
Key::Builder().withSkinned(),
skinModelVertex, modelPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS),
Key::Builder().withSkinned().withTangents(),
skinModelNormalMapVertex, modelNormalMapPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_SPECULAR),
Key::Builder().withSkinned().withSpecular(),
skinModelVertex, modelSpecularMapPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR),
Key::Builder().withSkinned().withTangents().withSpecular(),
skinModelNormalMapVertex, modelNormalSpecularMapPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_SKINNED | RenderKey::IS_TRANSLUCENT),
Key::Builder().withSkinned().withTranslucent(),
skinModelVertex, modelTranslucentPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS | RenderKey::IS_TRANSLUCENT),
Key::Builder().withSkinned().withTangents().withTranslucent(),
skinModelNormalMapVertex, modelTranslucentPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT),
Key::Builder().withSkinned().withSpecular().withTranslucent(),
skinModelVertex, modelTranslucentPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT),
Key::Builder().withSkinned().withTangents().withSpecular().withTranslucent(),
skinModelNormalMapVertex, modelTranslucentPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_DEPTH_ONLY | RenderKey::IS_SHADOW),
Key::Builder().withDepthOnly().withShadow(),
modelShadowVertex, modelShadowPixel);
_pipelineLib.addPipeline(
RenderKey(RenderKey::IS_SKINNED | RenderKey::IS_DEPTH_ONLY | RenderKey::IS_SHADOW),
Key::Builder().withSkinned().withDepthOnly().withShadow(),
skinModelShadowVertex, modelShadowPixel);
}
const render::PipelinePointer ShapeRender::pickPipeline(RenderArgs* args, Key& key) {
const ShapeRender::PipelinePointer ShapeRender::pickPipeline(RenderArgs* args, const Key& key) const {
PerformanceTimer perfTimer("ShapeRender::pickPipeline");
auto pipeline = _pickPipeline(args, key);
@ -178,9 +179,11 @@ const render::PipelinePointer ShapeRender::pickPipeline(RenderArgs* args, Key& k
}
if ((pipeline->locations->normalFittingMapUnit > -1)) {
batch.setResourceTexture(pipeline->locations->normalFittingMapUnit,
args->_batch->setResourceTexture(pipeline->locations->normalFittingMapUnit,
DependencyManager::get<TextureCache>()->getNormalFittingTexture());
}
return pipeline;
}
model::MaterialPointer ShapeRender::_collisionHullMaterial;

View file

@ -13,6 +13,7 @@
#define hifi_render_utils_Shape_h
#include <render/Shape.h>
#include <model/Material.h>
class ShapeRender : public render::Shape {
static model::MaterialPointer _collisionHullMaterial;
@ -20,10 +21,9 @@ class ShapeRender : public render::Shape {
public:
ShapeRender();
static void initPipeline();
const render::PipelinePointer pickPipeline(RenderArgs* args, Key& key) override;
const PipelinePointer pickPipeline(RenderArgs* args, const Key& key) const override;
static model::MaterialPointer getCollisionHullMaterial();
};
#endif // hifi_render_utils_Shape_h

View file

@ -209,41 +209,43 @@ void DepthSortItems::run(const SceneContextPointer& sceneContext, const RenderCo
depthSortItems(sceneContext, renderContext, _frontToBack, inItems, outItems);
}
void render::renderLights(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Job::ContextPointer& jobContext, const ItemIDsBounds& inItems) {
void render::renderLights(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems) {
auto& scene = sceneContext->_scene;
RenderArgs* args = renderContext->getArgs();
for (const auto& itemDetails : inItems) {
const auto& item = scene->getItem(itemDetails.id);
// FIXME: Every item is copied because item.render cannot mutate a const
auto item = scene->getItem(itemDetails.id);
item.render(args);
}
}
void renderShape(RenderArgs* args, const Job::ContextPointer& jobContext, const Item& item) {
assert(item.isShape());
const auto& key = item._payload.getShapeKey();
args->_pipeline = jobContext->pickPipeline(args, key);
void renderShape(RenderArgs* args, const Shape& shapeContext, Item& item) {
assert(item.getKey().isShape());
const auto& key = item.getShapeKey();
args->_pipeline = shapeContext.pickPipeline(args, key);
// only render with a pipeline
if (args->_pipeline) {
item.render(args);
}
}
void render::renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Job::ContextPointer& jobContext, const ItemIDsBounds& inItems, int maxDrawnItems) {
void render::renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Shape& shapeContext, const ItemIDsBounds& inItems, int maxDrawnItems) {
auto& scene = sceneContext->_scene;
RenderArgs* args = renderContext->getArgs();
if ((maxDrawnItems < 0) || (maxDrawnItems > (int)inItems.size())) {
for (const auto& itemDetails : inItems) {
const auto& item = scene->getItem(itemDetails.id);
renderShape(args, jobContext, item);
// FIXME: Every item is copied because item.render cannot mutate a const
auto item = scene->getItem(itemDetails.id);
renderShape(args, shapeContext, item);
}
} else {
int numItems = 0;
for (const auto& itemDetails : inItems) {
numItems++;
const auto& item = scene->getItem(itemDetails.id);
renderShape(args, jobContext, item);
auto item = scene->getItem(itemDetails.id);
renderShape(args, shapeContext, item);
if (numItems >= maxDrawnItems) {
break;
}

View file

@ -13,6 +13,7 @@
#define hifi_render_Task_h
#include "Engine.h"
#include "Shape.h"
#include "gpu/Batch.h"
#include <PerfStat.h>
@ -104,7 +105,7 @@ public:
public:
class Context {
public:
virtual ShapePipeline pickPipeline(RenderArgs* args, const ShapeKey& key) = 0;
virtual const ShapePipeline pickPipeline(RenderArgs* args, const ShapeKey& key) = 0;
};
using ContextPointer = std::shared_ptr<Context>;
@ -227,7 +228,7 @@ typedef std::vector<Job> Jobs;
void cullItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems, ItemIDsBounds& outITems);
void depthSortItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, bool frontToBack, const ItemIDsBounds& inItems, ItemIDsBounds& outITems);
void renderLights(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems);
void renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Job::ContextPointer& jobContext, const ItemIDsBounds& inItems, int maxDrawnItems = -1);
void renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Shape& shapeContext, const ItemIDsBounds& inItems, int maxDrawnItems = -1);
class FetchItems {

View file

@ -15,7 +15,7 @@
using namespace render;
Shape::PipelineLib _pipelineLip;
Shape::PipelineLib Shape::_pipelineLib;
const Shape::PipelinePointer Shape::_pickPipeline(RenderArgs* args, const Key& key) {
assert(!_pipelineLib.empty());

View file

@ -138,6 +138,7 @@ public:
int materialBufferUnit;
int lightBufferUnit;
};
using LocationsPointer = std::shared_ptr<Locations>;
gpu::PipelinePointer pipeline;
std::shared_ptr<Locations> locations;
@ -165,7 +166,7 @@ public:
static void addPipeline(Key key, gpu::ShaderPointer& vertexShader, gpu::ShaderPointer& pixelShader) {
_pipelineLib.addPipeline(key, vertexShader, pixelShader);
}
virtual const PipelinePointer pickPipeline(RenderArgs* args, const Key& key) {
virtual const PipelinePointer pickPipeline(RenderArgs* args, const Key& key) const {
return Shape::_pickPipeline(args, key);
}