예제 #1
0
void RenderStage::init(const JSONValue& renderStageJSON)
{
    auto renderStageRenderPassesJSON = renderStageJSON.getJSONValue("renderPasses");
    if(!renderStageRenderPassesJSON.isNull())
    {
        for(unsigned int i = 0; i < renderStageRenderPassesJSON.getSize(); ++i)
            if(!renderStageRenderPassesJSON.getJSONArrayItem(i).isNull())
                renderPasses.pushBack(createRenderPassFromJson(renderStageRenderPassesJSON.getJSONArrayItem(i)));
    }
}
예제 #2
0
void DeferredStage::init(const JSONValue& deferredgStageJSON)
{
    auto gbufferRenderPassJSON = deferredgStageJSON.getJSONValue("GbufferRenderPass");
    if(!gbufferRenderPassJSON.isNull())
        renderPasses.pushBack(createRenderPassFromJson(gbufferRenderPassJSON));
}
예제 #3
0
RenderPass RenderStage::createRenderPassFromJson(const JSONValue& renderPassJSON)
{
    GraphicSystem& graphicSystem = renderer.getGraphicSystem();

    RenderPass renderPass;
    auto clearColorJSON = renderPassJSON.getJSONValue("clearColor");
    auto colorWriteJSON = renderPassJSON.getJSONValue("colorWrite");
    auto depthWriteJSON = renderPassJSON.getJSONValue("depthWrite");
    auto renderTargetLayerJSON = renderPassJSON.getJSONValue("renderTargetLayer");
    auto flagsJSON = renderPassJSON.getJSONValue("flags");

    if(!clearColorJSON.isNull())
        renderPass.clearColor = clearColorJSON.getVector4();
    if(!colorWriteJSON.isNull())
        renderPass.colorWrite = colorWriteJSON.getBool();
    if(!depthWriteJSON.isNull())
        renderPass.depthWrite = depthWriteJSON.getBool();
    if(!renderTargetLayerJSON.isNull())
        renderPass.renderTargetLayer = renderTargetLayerJSON.getInt();
    if(!flagsJSON.isNull())
    {
        unsigned int flags = 0;
        for(unsigned int i = 0; i < flagsJSON.getSize(); ++i)
        {
            if(flagsJSON.getJSONArrayItem(i).getString().compare("CLEAR_COLOR") == 0)
                flags |= CLEAR_COLOR;
            if(flagsJSON.getJSONArrayItem(i).getString().compare("CLEAR_DEPTH") == 0)
                flags |= CLEAR_DEPTH;
        }
        renderPass.flags = flags;
    }

    auto viewPortJSON = renderPassJSON.getJSONValue("viewPort");
    if(!viewPortJSON.isNull())
    {
        FixedArray<int, 4> viewPort = viewPortJSON.getInt4();
        renderPass.viewPort.set(viewPort[0], viewPort[1], viewPort[2], viewPort[3]);
    }
    else
        renderPass.viewPort = renderer.getScreenViewPort();

    auto renderTargetJSON = renderPassJSON.getJSONValue("renderTarget");
    renderPass.renderTarget = graphicSystem.createRenderTarget(renderTargetJSON);

    auto shaderPasses = renderPassJSON.getJSONValue("shaderPasses");

    if(!shaderPasses.isNull())
    {
        for(unsigned int i = 0; i < shaderPasses.getSize(); ++i)
        {
            auto shaderPassJSON = shaderPasses.getJSONArrayItem(i);
            auto programJSON = shaderPassJSON.getJSONValue("shaderProgram");
            auto vertexDataJSON = shaderPassJSON.getJSONValue("vertexData");
            auto rasterStateJSON = shaderPassJSON.getJSONValue("rasterState");
            auto shaderParameterBlocksJSON = shaderPassJSON.getJSONValue("shaderParameterBlocks");
            auto texturesJSON = shaderPassJSON.getJSONValue("textures");
            ShaderPass shaderPass;

            if(!vertexDataJSON.isNull())
            {
                if(vertexDataJSON.getString().compare("fullScreenQuad") == 0)
                    shaderPass.vertexData = renderer.getFullScreenQuad();
            }
            if(!rasterStateJSON.isNull())
            {
                auto blendFunctionJSON = rasterStateJSON.getJSONValue("blendFunction");
                auto compareFunctionJSON = rasterStateJSON.getJSONValue("compareFunction");
                auto cullFaceJSON = rasterStateJSON.getJSONValue("cullFace");
                auto blendState = !blendFunctionJSON.isNull() ? BlendState(true, enumFromString<BlendFunction>(blendFunctionJSON.getString())) : BlendState(false, BlendFunction::Replace);
                auto compareState = !compareFunctionJSON.isNull() ? CompareState(true, enumFromString<CompareFunction>(compareFunctionJSON.getString())) : CompareState(false, CompareFunction::Never);
                auto cullState = !cullFaceJSON.isNull() ? CullState(true, enumFromString<CullFace>(cullFaceJSON.getString())) : CullState(false, CullFace::Back);
                shaderPass.rasterState = RasterState(blendState, compareState, cullState);
            }

            if(!shaderParameterBlocksJSON.isNull())
            {
                for(unsigned int j = 0; j < shaderParameterBlocksJSON.getSize(); ++j)
                {
                    ShaderParameterBlock* block = graphicSystem.createShaderParameterBlock(shaderParameterBlocksJSON.getJSONArrayItem(j));
                    if(block)
                        shaderPass.shaderParameterBlocks.pushBack(block);
                }
            }
            if(!texturesJSON.isNull())
            {
                for(unsigned int j = 0; j < texturesJSON.getSize(); ++j)
                {
                    Texture* texture = graphicSystem.createTexture(texturesJSON.getJSONArrayItem(j));
                    if(texture)
                        shaderPass.textures.pushBack(texture);
                }
            }

            if(!programJSON.isNull())
                shaderPass.program = graphicSystem.createShaderProgram(programJSON);

            renderPass.shaderPasses.pushBack(shaderPass);
        }
    }
    return renderPass;
}