{"action":"created","comment":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/41287506","id":41287506,"diff_hunk":"@@ -0,0 +1,638 @@\n+//\n+//  ModelRenderItem.cpp\n+//  interface/src/renderer\n+//\n+//  Created by Sam Gateau on 10/3/15.\n+//  Copyright 2015 High Fidelity, Inc.\n+//\n+//  Distributed under the Apache License, Version 2.0.\n+//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html\n+//\n+\n+#include \"ModelRenderItem.h\"\n+\n+#include <PerfStat.h>\n+\n+#include \"DeferredLightingEffect.h\"\n+\n+#include \"Model.h\"\n+\n+#include \"model_vert.h\"\n+#include \"model_shadow_vert.h\"\n+#include \"model_normal_map_vert.h\"\n+#include \"model_lightmap_vert.h\"\n+#include \"model_lightmap_normal_map_vert.h\"\n+#include \"skin_model_vert.h\"\n+#include \"skin_model_shadow_vert.h\"\n+#include \"skin_model_normal_map_vert.h\"\n+\n+#include \"model_frag.h\"\n+#include \"model_shadow_frag.h\"\n+#include \"model_normal_map_frag.h\"\n+#include \"model_normal_specular_map_frag.h\"\n+#include \"model_specular_map_frag.h\"\n+#include \"model_lightmap_frag.h\"\n+#include \"model_lightmap_normal_map_frag.h\"\n+#include \"model_lightmap_normal_specular_map_frag.h\"\n+#include \"model_lightmap_specular_map_frag.h\"\n+#include \"model_translucent_frag.h\"\n+\n+ModelRender::RenderPipelineLib ModelRender::_renderPipelineLib;\n+\n+const ModelRender::RenderPipelineLib& ModelRender::getRenderPipelineLib() {\n+    if (_renderPipelineLib.empty()) {\n+        // Vertex shaders\n+        auto modelVertex = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(model_vert)));\n+        auto modelNormalMapVertex = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(model_normal_map_vert)));\n+        auto modelLightmapVertex = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(model_lightmap_vert)));\n+        auto modelLightmapNormalMapVertex = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(model_lightmap_normal_map_vert)));\n+        auto modelShadowVertex = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(model_shadow_vert)));\n+        auto skinModelVertex = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(skin_model_vert)));\n+        auto skinModelNormalMapVertex = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(skin_model_normal_map_vert)));\n+        auto skinModelShadowVertex = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(skin_model_shadow_vert)));\n+\n+        // Pixel shaders\n+        auto modelPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_frag)));\n+        auto modelNormalMapPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_normal_map_frag)));\n+        auto modelSpecularMapPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_specular_map_frag)));\n+        auto modelNormalSpecularMapPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_normal_specular_map_frag)));\n+        auto modelTranslucentPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_translucent_frag)));\n+        auto modelShadowPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_shadow_frag)));\n+        auto modelLightmapPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_lightmap_frag)));\n+        auto modelLightmapNormalMapPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_lightmap_normal_map_frag)));\n+        auto modelLightmapSpecularMapPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_lightmap_specular_map_frag)));\n+        auto modelLightmapNormalSpecularMapPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_lightmap_normal_specular_map_frag)));\n+\n+        // Fill the renderPipelineLib\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(0),\n+            modelVertex, modelPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::HAS_TANGENTS),\n+            modelNormalMapVertex, modelNormalMapPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::HAS_SPECULAR),\n+            modelVertex, modelSpecularMapPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR),\n+            modelNormalMapVertex, modelNormalSpecularMapPixel);\n+\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_TRANSLUCENT),\n+            modelVertex, modelTranslucentPixel);\n+        // FIXME Ignore lightmap for translucents meshpart\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_TRANSLUCENT | RenderKey::HAS_LIGHTMAP),\n+            modelVertex, modelTranslucentPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::HAS_TANGENTS | RenderKey::IS_TRANSLUCENT),\n+            modelNormalMapVertex, modelTranslucentPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT),\n+            modelVertex, modelTranslucentPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT),\n+            modelNormalMapVertex, modelTranslucentPixel);\n+\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::HAS_LIGHTMAP),\n+            modelLightmapVertex, modelLightmapPixel);\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_TANGENTS),\n+            modelLightmapNormalMapVertex, modelLightmapNormalMapPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_SPECULAR),\n+            modelLightmapVertex, modelLightmapSpecularMapPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR),\n+            modelLightmapNormalMapVertex, modelLightmapNormalSpecularMapPixel);\n+\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_SKINNED),\n+            skinModelVertex, modelPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS),\n+            skinModelNormalMapVertex, modelNormalMapPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_SPECULAR),\n+            skinModelVertex, modelSpecularMapPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR),\n+            skinModelNormalMapVertex, modelNormalSpecularMapPixel);\n+\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_SKINNED | RenderKey::IS_TRANSLUCENT),\n+            skinModelVertex, modelTranslucentPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS | RenderKey::IS_TRANSLUCENT),\n+            skinModelNormalMapVertex, modelTranslucentPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT),\n+            skinModelVertex, modelTranslucentPixel);\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR | RenderKey::IS_TRANSLUCENT),\n+            skinModelNormalMapVertex, modelTranslucentPixel);\n+\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_DEPTH_ONLY | RenderKey::IS_SHADOW),\n+            modelShadowVertex, modelShadowPixel);\n+\n+\n+        _renderPipelineLib.addRenderPipeline(\n+            RenderKey(RenderKey::IS_SKINNED | RenderKey::IS_DEPTH_ONLY | RenderKey::IS_SHADOW),\n+            skinModelShadowVertex, modelShadowPixel);\n+    }\n+\n+    return _renderPipelineLib;\n+}\n+\n+\n+void ModelRender::RenderPipelineLib::addRenderPipeline(ModelRender::RenderKey key,\n+    gpu::ShaderPointer& vertexShader,\n+    gpu::ShaderPointer& pixelShader) {\n+\n+    gpu::Shader::BindingSet slotBindings;\n+    \n+    slotBindings.insert(gpu::Shader::Binding(std::string(\"skinClusterBuffer\"), ModelRender::SKINNING_GPU_SLOT));\n+    slotBindings.insert(gpu::Shader::Binding(std::string(\"materialBuffer\"), ModelRender::MATERIAL_GPU_SLOT));\n+    slotBindings.insert(gpu::Shader::Binding(std::string(\"diffuseMap\"), ModelRender::DIFFUSE_MAP_SLOT));\n+    slotBindings.insert(gpu::Shader::Binding(std::string(\"normalMap\"), ModelRender::NORMAL_MAP_SLOT));\n+    slotBindings.insert(gpu::Shader::Binding(std::string(\"specularMap\"), ModelRender::SPECULAR_MAP_SLOT));\n+    slotBindings.insert(gpu::Shader::Binding(std::string(\"emissiveMap\"), ModelRender::LIGHTMAP_MAP_SLOT));\n+    slotBindings.insert(gpu::Shader::Binding(std::string(\"lightBuffer\"), ModelRender::LIGHT_BUFFER_SLOT));\n+    slotBindings.insert(gpu::Shader::Binding(std::string(\"normalFittingMap\"), DeferredLightingEffect::NORMAL_FITTING_MAP_SLOT));\n+\n+    gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vertexShader, pixelShader));\n+    gpu::Shader::makeProgram(*program, slotBindings);\n+\n+\n+    auto locations = std::make_shared<Locations>();\n+    initLocations(program, *locations);\n+\n+\n+    auto state = std::make_shared<gpu::State>();\n+\n+    // Backface on shadow\n+    if (key.isShadow()) {\n+        state->setCullMode(gpu::State::CULL_FRONT);\n+        state->setDepthBias(1.0f);\n+        state->setDepthBiasSlopeScale(4.0f);\n+    } else {\n+        state->setCullMode(gpu::State::CULL_BACK);\n+    }\n+\n+    // Z test depends if transparent or not\n+    state->setDepthTest(true, !key.isTranslucent(), gpu::LESS_EQUAL);\n+\n+    // Blend on transparent\n+    state->setBlendFunction(key.isTranslucent(),\n+        gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, // For transparent only, this keep the highlight intensity\n+        gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);\n+\n+    // Good to go add the brand new pipeline\n+    auto pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));\n+    insert(value_type(key.getRaw(), RenderPipeline(pipeline, locations)));\n+\n+\n+    if (!key.isWireFrame()) {\n+\n+        RenderKey wireframeKey(key.getRaw() | RenderKey::IS_WIREFRAME);\n+        auto wireframeState = std::make_shared<gpu::State>(state->getValues());\n+\n+        wireframeState->setFillMode(gpu::State::FILL_LINE);\n+\n+        // create a new RenderPipeline with the same shader side and the mirrorState\n+        auto wireframePipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, wireframeState));\n+        insert(value_type(wireframeKey.getRaw(), RenderPipeline(wireframePipeline, locations)));\n+    }\n+\n+    // If not a shadow pass, create the mirror version from the same state, just change the FrontFace\n+    if (!key.isShadow()) {\n+\n+        RenderKey mirrorKey(key.getRaw() | RenderKey::IS_MIRROR);\n+        auto mirrorState = std::make_shared<gpu::State>(state->getValues());\n+\n+        // create a new RenderPipeline with the same shader side and the mirrorState\n+        auto mirrorPipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, mirrorState));\n+        insert(value_type(mirrorKey.getRaw(), RenderPipeline(mirrorPipeline, locations)));\n+\n+        if (!key.isWireFrame()) {\n+            RenderKey wireframeKey(key.getRaw() | RenderKey::IS_MIRROR | RenderKey::IS_WIREFRAME);\n+            auto wireframeState = std::make_shared<gpu::State>(state->getValues());\n+\n+            wireframeState->setFillMode(gpu::State::FILL_LINE);\n+\n+            // create a new RenderPipeline with the same shader side and the mirrorState\n+            auto wireframePipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, wireframeState));\n+            insert(value_type(wireframeKey.getRaw(), RenderPipeline(wireframePipeline, locations)));\n+        }\n+    }\n+}\n+\n+\n+void ModelRender::RenderPipelineLib::initLocations(gpu::ShaderPointer& program, ModelRender::Locations& locations) {\n+    locations.alphaThreshold = program->getUniforms().findLocation(\"alphaThreshold\");\n+    locations.texcoordMatrices = program->getUniforms().findLocation(\"texcoordMatrices\");\n+    locations.emissiveParams = program->getUniforms().findLocation(\"emissiveParams\");\n+    locations.glowIntensity = program->getUniforms().findLocation(\"glowIntensity\");\n+    locations.normalFittingMapUnit = program->getTextures().findLocation(\"normalFittingMap\");\n+    locations.diffuseTextureUnit = program->getTextures().findLocation(\"diffuseMap\");\n+    locations.normalTextureUnit = program->getTextures().findLocation(\"normalMap\");\n+    locations.specularTextureUnit = program->getTextures().findLocation(\"specularMap\");\n+    locations.emissiveTextureUnit = program->getTextures().findLocation(\"emissiveMap\");\n+    locations.materialBufferUnit = program->getBuffers().findLocation(\"materialBuffer\");\n+    locations.lightBufferUnit = program->getBuffers().findLocation(\"lightBuffer\");\n+    locations.skinClusterBufferUnit = program->getBuffers().findLocation(\"skinClusterBuffer\");\n+}\n+\n+\n+void ModelRender::pickPrograms(gpu::Batch& batch, RenderArgs::RenderMode mode, bool translucent, float alphaThreshold,\n+    bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, bool isWireframe, RenderArgs* args,\n+    Locations*& locations) {\n+\n+    PerformanceTimer perfTimer(\"ModelRender::pickPrograms\");\n+    getRenderPipelineLib();\n+\n+    RenderKey key(mode, translucent, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned, isWireframe);\n+    if (mode == RenderArgs::MIRROR_RENDER_MODE) {\n+        key = RenderKey(key.getRaw() | RenderKey::IS_MIRROR);\n+    }\n+    auto pipeline = _renderPipelineLib.find(key.getRaw());\n+    if (pipeline == _renderPipelineLib.end()) {\n+        qDebug() << \"No good, couldn't find a pipeline from the key ?\" << key.getRaw();\n+        locations = 0;\n+        return;\n+    }\n+\n+    gpu::ShaderPointer program = (*pipeline).second._pipeline->getProgram();\n+    locations = (*pipeline).second._locations.get();\n+\n+\n+    // Setup the One pipeline\n+    batch.setPipeline((*pipeline).second._pipeline);\n+\n+    if ((locations->alphaThreshold > -1) && (mode != RenderArgs::SHADOW_RENDER_MODE)) {\n+        batch._glUniform1f(locations->alphaThreshold, alphaThreshold);\n+    }\n+\n+    if ((locations->glowIntensity > -1) && (mode != RenderArgs::SHADOW_RENDER_MODE)) {\n+        const float DEFAULT_GLOW_INTENSITY = 1.0f; // FIXME - glow is removed\n+        batch._glUniform1f(locations->glowIntensity, DEFAULT_GLOW_INTENSITY);\n+    }\n+\n+    if ((locations->normalFittingMapUnit > -1)) {\n+        batch.setResourceTexture(locations->normalFittingMapUnit,\n+            DependencyManager::get<TextureCache>()->getNormalFittingTexture());\n+    }\n+}\n+\n+namespace render {\n+    template <> const ItemKey payloadGetKey(const MeshPartPayload::Pointer& payload) {\n+        if (payload) {\n+            return payload->getKey();\n+        }\n+        // Return opaque for lack of a better idea\n+        return ItemKey::Builder::opaqueShape();\n+    }\n+    \n+    template <> const Item::Bound payloadGetBound(const MeshPartPayload::Pointer& payload) {\n+        if (payload) {\n+            return payload->getBound();\n+        }\n+        return render::Item::Bound();\n+    }\n+    template <> void payloadRender(const MeshPartPayload::Pointer& payload, RenderArgs* args) {\n+        return payload->render(args);\n+    }\n+}\n+\n+using namespace render;\n+\n+MeshPartPayload::MeshPartPayload(Model* model, int meshIndex, int partIndex, int shapeIndex) :\n+    model(model), url(model->getURL()), meshIndex(meshIndex), partIndex(partIndex), _shapeID(shapeIndex)\n+{\n+    initCache();\n+}\n+\n+void MeshPartPayload::initCache() {\n+    const std::vector<std::unique_ptr<NetworkMesh>>& networkMeshes = model->_geometry->getMeshes();\n+    const NetworkMesh& networkMesh = *(networkMeshes.at(meshIndex).get());\n+    _drawMesh = networkMesh._mesh;\n+\n+    const FBXGeometry& geometry = model->_geometry->getFBXGeometry();\n+    const FBXMesh& mesh = geometry.meshes.at(meshIndex);\n+    _hasColorAttrib = !mesh.colors.isEmpty();\n+    _isBlendShaped = !mesh.blendshapes.isEmpty();\n+    _isSkinned = !mesh.clusterIndices.isEmpty();\n+\n+\n+    _drawPart = _drawMesh->getPartBuffer().get<model::Mesh::Part>(partIndex);\n+\n+    auto networkMaterial = model->_geometry->getShapeMaterial(_shapeID);\n+    if (networkMaterial) {\n+        _drawMaterial = networkMaterial->_material;\n+    };\n+\n+}\n+\n+render::ItemKey MeshPartPayload::getKey() const {\n+    ItemKey::Builder builder;\n+    builder.withTypeShape();\n+\n+    if (!model->isVisible()) {\n+        builder.withInvisible();\n+    }\n+\n+    if (_isBlendShaped || _isSkinned) {\n+        builder.withDeformed();\n+    }\n+\n+    if (_drawMaterial) {\n+        auto matKey = _drawMaterial->getKey();\n+        if (matKey.isTransparent() || matKey.isTransparentMap()) {\n+            builder.withTransparent();\n+        }\n+    }\n+\n+    return builder.build();\n+}\n+\n+render::Item::Bound MeshPartPayload::getBound() const {\n+    if (_isBoundInvalid) {\n+        model->getPartBounds(meshIndex, partIndex);\n+        _isBoundInvalid = false;\n+    }\n+    return _bound;\n+}\n+\n+void MeshPartPayload::drawCall(gpu::Batch& batch) const {\n+    batch.drawIndexed(gpu::TRIANGLES, _drawPart._numIndices, _drawPart._startIndex);\n+}\n+\n+void MeshPartPayload::bindMesh(gpu::Batch& batch) const {\n+    if (!_isBlendShaped) {\n+        batch.setIndexBuffer(gpu::UINT32, (_drawMesh->getIndexBuffer()._buffer), 0);\n+        \n+        batch.setInputFormat((_drawMesh->getVertexFormat()));\n+        \n+        batch.setInputStream(0, _drawMesh->getVertexStream());\n+    } else {\n+        batch.setIndexBuffer(gpu::UINT32, (_drawMesh->getIndexBuffer()._buffer), 0);\n+\n+        batch.setInputFormat((_drawMesh->getVertexFormat()));\n+\n+        batch.setInputBuffer(0, model->_blendedVertexBuffers[meshIndex], 0, sizeof(glm::vec3));\n+        batch.setInputBuffer(1, model->_blendedVertexBuffers[meshIndex], _drawMesh->getNumVertices() * sizeof(glm::vec3), sizeof(glm::vec3));\n+        batch.setInputStream(2, _drawMesh->getVertexStream().makeRangedStream(2));\n+    }\n+    \n+    // TODO: Get rid of that extra call\n+    if (!_hasColorAttrib) {\n+        batch._glColor4f(1.0f, 1.0f, 1.0f, 1.0f);\n+    }\n+}\n+\n+void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ModelRender::Locations* locations) const {","path":"libraries/render-utils/src/ModelRenderItem.cpp","position":415,"original_position":415,"commit_id":"59afbf1a04ba3c19bb78c518b9748ece6b2d4e5c","original_commit_id":"59afbf1a04ba3c19bb78c518b9748ece6b2d4e5c","user":{"login":"ZappoMan","id":2093195,"avatar_url":"https://avatars.githubusercontent.com/u/2093195?v=3","gravatar_id":"","url":"https://api.github.com/users/ZappoMan","html_url":"https://github.com/ZappoMan","followers_url":"https://api.github.com/users/ZappoMan/followers","following_url":"https://api.github.com/users/ZappoMan/following{/other_user}","gists_url":"https://api.github.com/users/ZappoMan/gists{/gist_id}","starred_url":"https://api.github.com/users/ZappoMan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZappoMan/subscriptions","organizations_url":"https://api.github.com/users/ZappoMan/orgs","repos_url":"https://api.github.com/users/ZappoMan/repos","events_url":"https://api.github.com/users/ZappoMan/events{/privacy}","received_events_url":"https://api.github.com/users/ZappoMan/received_events","type":"User","site_admin":false},"body":"coding standard: these should be in MeshPartPayload.cpp","created_at":"2015-10-06T16:25:50Z","updated_at":"2015-10-06T16:25:50Z","html_url":"https://github.com/highfidelity/hifi/pull/6000#discussion_r41287506","pull_request_url":"https://api.github.com/repos/highfidelity/hifi/pulls/6000","_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/41287506"},"html":{"href":"https://github.com/highfidelity/hifi/pull/6000#discussion_r41287506"},"pull_request":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6000"}}},"pull_request":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/6000","id":46868477,"html_url":"https://github.com/highfidelity/hifi/pull/6000","diff_url":"https://github.com/highfidelity/hifi/pull/6000.diff","patch_url":"https://github.com/highfidelity/hifi/pull/6000.patch","issue_url":"https://api.github.com/repos/highfidelity/hifi/issues/6000","number":6000,"state":"open","locked":false,"title":"DO NOT MERGE: Migrate FBXReader to use model::Mesh and clean Model Part rendering","user":{"login":"samcake","id":2230265,"avatar_url":"https://avatars.githubusercontent.com/u/2230265?v=3","gravatar_id":"","url":"https://api.github.com/users/samcake","html_url":"https://github.com/samcake","followers_url":"https://api.github.com/users/samcake/followers","following_url":"https://api.github.com/users/samcake/following{/other_user}","gists_url":"https://api.github.com/users/samcake/gists{/gist_id}","starred_url":"https://api.github.com/users/samcake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samcake/subscriptions","organizations_url":"https://api.github.com/users/samcake/orgs","repos_url":"https://api.github.com/users/samcake/repos","events_url":"https://api.github.com/users/samcake/events{/privacy}","received_events_url":"https://api.github.com/users/samcake/received_events","type":"User","site_admin":false},"body":"- FBXReader now generate a model::Mesh object for each FBXMesh. This model::Mesh is ready for rendering and as a consequence the NetworkMesh doesn't need to allocate the vertex and index buffers anymore.\r\n\r\n- A mesh can contains several Parts which can each have different Material. The parts are defined as indices range in the index buffer, thus when rendering the parts of  a mesh the index buffer or Vertex buffer doesn't need to change, it s just a new drawcall with different indexStart and number of indices.\r\n The next step is to try to combine all the FBXMeshes of a model ( and then of the models of the scene) into a single VertexBuffer and Index Buffer so we can draw it using MultiDrawIndirect in only a few drawcalls... to be continued.\r\n\r\n- The piece of code that was generating the Merged Triangles and Quad triangles of a MeshPart has been replaced by creating the \"quadTriangleIndices\" in the FBXMeshPart  and using it during the model::Mesh creation.\r\n\r\n- Fixed a bug in GLBackend::do_drawIndexed and do_drawIndexedInstanced, the offset computation for the index buffer was wrong, this is no fix and let us draw successfully the different parts of a single Mesh.\r\n\r\n- Moved the MeshPartPayload class and everything about rendering the Model(.h, .cpp) into the new file called ModelRenderItem (.h, .cpp)\r\n The MeshPartPayload is now cashing the Mesh, Part and Material it s using for rendering and exposes new methods which together are contributing to the rendering of the part.\r\n\r\n- Moved the skinning code used in the shader in it's on shared shader file \"Skinning.slh\" used by the 3 current skinning vector shaders.\r\n\r\n- Lastly, i couldn't resist and replaced the old school mat uniforms used to pass the skeleton current bind-pose matrices for every clusters by a UniformBuffer managed from Model.cpp and updated along the sys mem version of the clusterMatrices data.\r\n\r\nTODO BEFORE SHIPPING:\r\n- clean\r\n- Test performances\r\n\r\n ","created_at":"2015-10-06T07:05:10Z","updated_at":"2015-10-06T16:25:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2b5543858efadbac4e5a053b594a7821abc3878b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/highfidelity/hifi/pulls/6000/commits","review_comments_url":"https://api.github.com/repos/highfidelity/hifi/pulls/6000/comments","review_comment_url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/highfidelity/hifi/issues/6000/comments","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/59afbf1a04ba3c19bb78c518b9748ece6b2d4e5c","head":{"label":"samcake:hobbes","ref":"hobbes","sha":"59afbf1a04ba3c19bb78c518b9748ece6b2d4e5c","user":{"login":"samcake","id":2230265,"avatar_url":"https://avatars.githubusercontent.com/u/2230265?v=3","gravatar_id":"","url":"https://api.github.com/users/samcake","html_url":"https://github.com/samcake","followers_url":"https://api.github.com/users/samcake/followers","following_url":"https://api.github.com/users/samcake/following{/other_user}","gists_url":"https://api.github.com/users/samcake/gists{/gist_id}","starred_url":"https://api.github.com/users/samcake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samcake/subscriptions","organizations_url":"https://api.github.com/users/samcake/orgs","repos_url":"https://api.github.com/users/samcake/repos","events_url":"https://api.github.com/users/samcake/events{/privacy}","received_events_url":"https://api.github.com/users/samcake/received_events","type":"User","site_admin":false},"repo":{"id":24736064,"name":"hifi","full_name":"samcake/hifi","owner":{"login":"samcake","id":2230265,"avatar_url":"https://avatars.githubusercontent.com/u/2230265?v=3","gravatar_id":"","url":"https://api.github.com/users/samcake","html_url":"https://github.com/samcake","followers_url":"https://api.github.com/users/samcake/followers","following_url":"https://api.github.com/users/samcake/following{/other_user}","gists_url":"https://api.github.com/users/samcake/gists{/gist_id}","starred_url":"https://api.github.com/users/samcake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samcake/subscriptions","organizations_url":"https://api.github.com/users/samcake/orgs","repos_url":"https://api.github.com/users/samcake/repos","events_url":"https://api.github.com/users/samcake/events{/privacy}","received_events_url":"https://api.github.com/users/samcake/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/samcake/hifi","description":"Open, decentralized virtual worlds using sensors to control avatars and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.io/jobs  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":true,"url":"https://api.github.com/repos/samcake/hifi","forks_url":"https://api.github.com/repos/samcake/hifi/forks","keys_url":"https://api.github.com/repos/samcake/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/samcake/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/samcake/hifi/teams","hooks_url":"https://api.github.com/repos/samcake/hifi/hooks","issue_events_url":"https://api.github.com/repos/samcake/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/samcake/hifi/events","assignees_url":"https://api.github.com/repos/samcake/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/samcake/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/samcake/hifi/tags","blobs_url":"https://api.github.com/repos/samcake/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/samcake/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/samcake/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/samcake/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/samcake/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/samcake/hifi/languages","stargazers_url":"https://api.github.com/repos/samcake/hifi/stargazers","contributors_url":"https://api.github.com/repos/samcake/hifi/contributors","subscribers_url":"https://api.github.com/repos/samcake/hifi/subscribers","subscription_url":"https://api.github.com/repos/samcake/hifi/subscription","commits_url":"https://api.github.com/repos/samcake/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/samcake/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/samcake/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/samcake/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/samcake/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/samcake/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/samcake/hifi/merges","archive_url":"https://api.github.com/repos/samcake/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/samcake/hifi/downloads","issues_url":"https://api.github.com/repos/samcake/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/samcake/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/samcake/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/samcake/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/samcake/hifi/labels{/name}","releases_url":"https://api.github.com/repos/samcake/hifi/releases{/id}","created_at":"2014-10-02T20:49:37Z","updated_at":"2015-04-02T23:12:49Z","pushed_at":"2015-10-06T08:16:04Z","git_url":"git://github.com/samcake/hifi.git","ssh_url":"git@github.com:samcake/hifi.git","clone_url":"https://github.com/samcake/hifi.git","svn_url":"https://github.com/samcake/hifi","homepage":"","size":181483,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"highfidelity:master","ref":"master","sha":"a554f3afb70ca2df4b38c3e431fa447abe892ab3","user":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"repo":{"id":5372872,"name":"hifi","full_name":"highfidelity/hifi","owner":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/highfidelity/hifi","description":"Open source software for shared virtual worlds using HMDs and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.com/jobs  Documentation at http://docs.highfidelity.com  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":false,"url":"https://api.github.com/repos/highfidelity/hifi","forks_url":"https://api.github.com/repos/highfidelity/hifi/forks","keys_url":"https://api.github.com/repos/highfidelity/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/highfidelity/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/highfidelity/hifi/teams","hooks_url":"https://api.github.com/repos/highfidelity/hifi/hooks","issue_events_url":"https://api.github.com/repos/highfidelity/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/highfidelity/hifi/events","assignees_url":"https://api.github.com/repos/highfidelity/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/highfidelity/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/highfidelity/hifi/tags","blobs_url":"https://api.github.com/repos/highfidelity/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/highfidelity/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/highfidelity/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/highfidelity/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/highfidelity/hifi/languages","stargazers_url":"https://api.github.com/repos/highfidelity/hifi/stargazers","contributors_url":"https://api.github.com/repos/highfidelity/hifi/contributors","subscribers_url":"https://api.github.com/repos/highfidelity/hifi/subscribers","subscription_url":"https://api.github.com/repos/highfidelity/hifi/subscription","commits_url":"https://api.github.com/repos/highfidelity/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/highfidelity/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/highfidelity/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/highfidelity/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/highfidelity/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/highfidelity/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/highfidelity/hifi/merges","archive_url":"https://api.github.com/repos/highfidelity/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/highfidelity/hifi/downloads","issues_url":"https://api.github.com/repos/highfidelity/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/highfidelity/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/highfidelity/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/highfidelity/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/highfidelity/hifi/labels{/name}","releases_url":"https://api.github.com/repos/highfidelity/hifi/releases{/id}","created_at":"2012-08-10T18:26:22Z","updated_at":"2015-10-01T15:27:15Z","pushed_at":"2015-10-06T16:24:22Z","git_url":"git://github.com/highfidelity/hifi.git","ssh_url":"git@github.com:highfidelity/hifi.git","clone_url":"https://github.com/highfidelity/hifi.git","svn_url":"https://github.com/highfidelity/hifi","homepage":"","size":240154,"stargazers_count":311,"watchers_count":311,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":178,"mirror_url":null,"open_issues_count":58,"forks":178,"open_issues":58,"watchers":311,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6000"},"html":{"href":"https://github.com/highfidelity/hifi/pull/6000"},"issue":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/6000"},"comments":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/6000/comments"},"review_comments":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6000/comments"},"review_comment":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6000/commits"},"statuses":{"href":"https://api.github.com/repos/highfidelity/hifi/statuses/59afbf1a04ba3c19bb78c518b9748ece6b2d4e5c"}}}}