Ejemplo n.º 1
0
void AppPanini::Update(float* pFieldOfView)
{
	ASSERT(g_pfnPaniniToggleCallback);

	// if we're not using dynamic GUI, don't do any updates
	if (!gPaniniSettingsDynamic.pGui) return;

	// handle toggle event
	static bool gbWasPaniniEnabled = gPaniniSettingsDynamic.mEnablePaniniProjection;	// state cache
	if (gPaniniSettingsDynamic.mEnablePaniniProjection != gbWasPaniniEnabled)
	{
		gbWasPaniniEnabled = gPaniniSettingsDynamic.mEnablePaniniProjection;
		if (gbWasPaniniEnabled)
		{
			gPaniniSettingsDynamic.mDynamicUIControls.ShowDynamicProperties(gPaniniSettingsDynamic.pGui);
		}
		else
		{
			gPaniniSettingsDynamic.mDynamicUIControls.HideDynamicProperties(gPaniniSettingsDynamic.pGui);
		}
		g_pfnPaniniToggleCallback(gbWasPaniniEnabled);
	}

	// update projection matrix parameters of the app of it has a dynamic GUI
	if (pFieldOfView)
	{
		*pFieldOfView = gPaniniSettingsDynamic.mParams.FoVH * (PI / 180.0f);
	}
	else
	{
		LOGWARNINGF("Panini Projection post process has been initialized with dynamic GUI but the FoV" \
					" parameter passed to updatePanini() is null. Changing FoV through the GUI will have no effect");
	}
}
Ejemplo n.º 2
0
JSASTStatement* JSASTNode::ParseStatement(const rapidjson::Value &value)
{
    assert(value.IsObject());

    JSASTStatement* statement = NULL;

    const Value::Member* mtype = value.FindMember("type");
    assert(mtype);

    String type = mtype->value.GetString();

    if (type == "ExpressionStatement")
    {
        statement = new JSASTExpressionStatement();
    }
    else if (type == "VariableDeclaration")
    {
        statement = new JSASTVariableDeclaration();
    }
    else if (type == "ReturnStatement")
    {
        statement = new JSASTReturnStatement();
    }
    else if (type == "FunctionDeclaration")
    {
        statement = new JSASTFunctionDeclaration();
    }
    else if (type == "IfStatement")
    {
        statement = new JSASTIfStatement();
    }
    else if (type == "BlockStatement")
    {
        statement = new JSASTBlockStatement();
    }
    else if (type == "EmptyStatement")
    {
        statement = new JSASTBlockStatement();
    }
    else if (type == "ForStatement")
    {
        statement = new JSASTForStatement();
    }
    else if (type == "LabeledStatement")
    {
        statement = new JSASTLabeledStatement();
    }

    if (!statement)
    {
        LOGWARNINGF("Unknown JSASTStatement: %s", type.CString());
    }
    else
    {
        statement->Parse(value);
    }

    return statement;

}
Ejemplo n.º 3
0
// 
// void URender11::Init( UEngine* InEngine )
// {
// 	URenderBase::Init(InEngine);
// }
// 
// void URender11::Destroy()
// {
// 	URenderBase::Destroy();
// }
// 
// UBOOL URender11::Exec( const TCHAR* Cmd, FOutputDevice& Ar )
// {
// 	return true;
// }
// 
void URender11::PreRender( FSceneNode* Frame )
{
    assert(Frame);
    assert(Frame->Viewport);
    assert(Frame->Viewport->RenDev);
    //Check if we recognize the renderer
    if (Frame->Viewport->RenDev->GetClass() != UD3D11RenderDevice::StaticClass())
    {
        LOGWARNINGF(L"Incompatible renderer: %s.", Frame->Viewport->RenDev->GetName());
    }

    URender::PreRender(Frame);
}
Ejemplo n.º 4
0
bool BuildBase::BuildClean(const String& path)
{
    if (buildFailed_)
    {
        LOGERRORF("BuildBase::BuildClean - Attempt to clean directory of failed build, %s", path.CString());
        return false;
    }

    FileSystem* fileSystem = GetSubsystem<FileSystem>();

    if (!fileSystem->DirExists(path))
        return true;

    // On Windows, do a little dance with the folder to avoid issues
    // with deleting folder and immediately recreating it

    String pathName, fileName, ext;
    SplitPath(path, pathName, fileName, ext);
    pathName = AddTrailingSlash(pathName);    

    unsigned i = 0;
    while (true) 
    {
        String newPath = ToString("%s%s_Temp_%u", pathName.CString(), fileName.CString(), i++);
        if (!fileSystem->DirExists(newPath))
        {
            if (!MoveFileExW(GetWideNativePath(path).CString(), GetWideNativePath(newPath).CString(), MOVEFILE_WRITE_THROUGH))
            {
                FailBuild(ToString("BuildBase::BuildClean: Unable to move directory %s -> ", path.CString(), newPath.CString()));
                return false;
            }

            // Remove the moved directory
            return BuildRemoveDirectory(newPath);

        }
        else
        {
            LOGWARNINGF("BuildBase::BuildClean - temp build folder exists, removing: %s", newPath.CString());
            fileSystem->RemoveDir(newPath, true);
        }

        if (i == 255)
        {
            FailBuild(ToString("BuildBase::BuildClean: Unable to move directory ( i == 255) %s -> ", path.CString(), newPath.CString()));
            return false;
        }
    }

    return false;
}
Ejemplo n.º 5
0
bool ShaderProgram::Link()
{
    PROFILE(LinkShaderProgram);

    Release();

    if (!graphics || !graphics->IsInitialized())
    {
        LOGERROR("Can not link shader program without initialized Graphics subsystem");
        return false;
    }
    if (!vs || !ps)
    {
        LOGERROR("Shader(s) are null, can not link shader program");
        return false;
    }
    if (!vs->GLShader() || !ps->GLShader())
    {
        LOGERROR("Shaders have not been compiled, can not link shader program");
        return false;
    }

    const String& vsSourceCode = vs->Parent() ? vs->Parent()->SourceCode() : String::EMPTY;
    const String& psSourceCode = ps->Parent() ? ps->Parent()->SourceCode() : String::EMPTY;

    program = glCreateProgram();
    if (!program)
    {
        LOGERROR("Could not create shader program");
        return false;
    }

    glAttachShader(program, vs->GLShader());
    glAttachShader(program, ps->GLShader());
    glLinkProgram(program);

    int linked;
    glGetProgramiv(program, GL_LINK_STATUS, &linked);
    if (!linked)
    {
        int length, outLength;
        String errorString;

        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
        errorString.Resize(length);
        glGetProgramInfoLog(program, length, &outLength, &errorString[0]);
        glDeleteProgram(program);
        program = 0;

        LOGERRORF("Could not link shaders %s: %s", FullName().CString(), errorString.CString());
        return false;
    }

    LOGDEBUGF("Linked shaders %s", FullName().CString());

    glUseProgram(program);

    char nameBuffer[MAX_NAME_LENGTH];
    int numAttributes, numUniforms, numUniformBlocks, nameLength, numElements;
    GLenum type;

    attributes.Clear();

    glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &numAttributes);
    for (int i = 0; i < numAttributes; ++i)
    {
        glGetActiveAttrib(program, i, (GLsizei)MAX_NAME_LENGTH, &nameLength, &numElements, &type, nameBuffer);

        VertexAttribute newAttribute;
        newAttribute.name = String(nameBuffer, nameLength);
        newAttribute.semantic = SEM_POSITION;
        newAttribute.index = 0;

        for (size_t j = 0; elementSemanticNames[j]; ++j)
        {
            if (newAttribute.name.StartsWith(elementSemanticNames[j], false))
            {
                int index = NumberPostfix(newAttribute.name);
                if (index >= 0)
                    newAttribute.index = (unsigned char)index;
                break;
            }
            newAttribute.semantic = (ElementSemantic)(newAttribute.semantic + 1);
        }

        if (newAttribute.semantic == MAX_ELEMENT_SEMANTICS)
        {
            LOGWARNINGF("Found vertex attribute %s with no known semantic in shader program %s", newAttribute.name.CString(), FullName().CString());
            continue;
        }

        newAttribute.location = glGetAttribLocation(program, newAttribute.name.CString());
        attributes.Push(newAttribute);
    }

    glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numUniforms);
    int numTextures = 0;
    for (int i = 0; i < numUniforms; ++i)
    {
        glGetActiveUniform(program, i, MAX_NAME_LENGTH, &nameLength, &numElements, &type, nameBuffer);

        String name(nameBuffer, nameLength);
        if (type >= GL_SAMPLER_1D && type <= GL_SAMPLER_2D_SHADOW)
        {
            // Assign sampler uniforms to a texture unit according to the number appended to the sampler name
            int location = glGetUniformLocation(program, name.CString());
            int unit = NumberPostfix(name);
            // If no unit number specified, assign in appearance order starting from unit 0
            if (unit < 0)
                unit = numTextures;

            // Array samplers may have multiple elements, assign each sequentially
            if (numElements > 1)
            {
                Vector<int> units;
                for (int j = 0; j < numElements; ++j)
                    units.Push(unit++);
                glUniform1iv(location, numElements, &units[0]);
            }
            else
                glUniform1iv(location, 1, &unit);

            numTextures += numElements;
        }
    }

    glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &numUniformBlocks);
    for (int i = 0; i < numUniformBlocks; ++i)
    {
        glGetActiveUniformBlockName(program, i, (GLsizei)MAX_NAME_LENGTH, &nameLength, nameBuffer);

        // Determine whether uniform block belongs to vertex or pixel shader
        String name(nameBuffer, nameLength);
        bool foundVs = vsSourceCode.Contains(name);
        bool foundPs = psSourceCode.Contains(name);
        if (foundVs && foundPs)
        {
            LOGWARNINGF("Found uniform block %s in both vertex and pixel shader in shader program %s");
            continue;
        }

        // Vertex shader constant buffer bindings occupy slots starting from zero to maximum supported, pixel shader bindings
        // from that point onward
        unsigned blockIndex = glGetUniformBlockIndex(program, name.CString());

        int bindingIndex = NumberPostfix(name);
        // If no number postfix in the name, use the block index
        if (bindingIndex < 0)
            bindingIndex = blockIndex;
        if (foundPs)
            bindingIndex += (unsigned)graphics->NumVSConstantBuffers();

        glUniformBlockBinding(program, blockIndex, bindingIndex);
    }

    return true;
}
Ejemplo n.º 6
0
JSASTExpression* JSASTNode::ParseExpression(const rapidjson::Value &value, JSASTType astType)
{
    if (!value.IsObject())
        return NULL;

    JSASTExpression* expr = NULL;

    const Value::Member* mtype = value.FindMember("type");
    assert(mtype);

    String type = mtype->value.GetString();
    if (type == "Identifier" && (astType == JSAST_UNDEFINED || astType == JSAST_IDENTIFIER))
    {
        expr = new JSASTIdentifier();
    }
    else if (type == "Literal" && (astType == JSAST_UNDEFINED || astType == JSAST_LITERAL))
    {
        expr = new JSASTLiteral();
    }
    else if (type == "UnaryExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_UNARYEXPRESSION))
    {
        expr = new JSASTUnaryExpression();
    }
    else if (type == "UpdateExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_UPDATEEXPRESSION))
    {
        expr = new JSASTUpdateExpression();
    }
    else if (type == "NewExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_NEWEXPRESSION))
    {
        expr = new JSASTNewExpression();
    }
    else if (type == "FunctionExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_FUNCTIONEXPRESSION))
    {
        expr = new JSASTFunctionExpression();
    }
    else if (type == "BinaryExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_BINARYEXPRESSION))
    {
        expr = new JSASTBinaryExpression();
    }
    else if (type == "AssignmentExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_ASSIGNMENTEXPRESSION))
    {
        expr = new JSASTAssignmentExpression();
    }
    else if (type == "LogicalExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_LOGICALEXPRESSION))
    {
        expr = new JSASTAssignmentExpression();
    }
    else if (type == "CallExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_CALLEXPRESSION))
    {
        expr = new JSASTCallExpression();
    }
    else if (type == "VariableDeclarator" && (astType == JSAST_UNDEFINED || astType == JSAST_VARIABLEDECLARATOR))
    {
        expr = new JSASTVariableDeclarator();
    }
    else if (type == "MemberExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_MEMBEREXPRESSION))
    {
        expr = new JSASTMemberExpression();
    }
    else if (type == "ArrayExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_ARRAYEXPRESSION))
    {
        expr = new JSASTArrayExpression();
    }
    else if (type == "ObjectExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_OBJECTEXPRESSION))
    {
        expr = new JSASTObjectExpression();
    }
    else if (type == "ConditionalExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_CONDITIONALEXPRESSION))
    {
        expr = new JSASTConditionalExpression();
    }
    else if (type == "ThisExpression" && (astType == JSAST_UNDEFINED || astType == JSAST_THISEXPRESSION))
    {
        expr = new JSASTThisExpression();
    }

    if (!expr)
    {
        LOGWARNINGF("Unknown JSASTExpression: %s", type.CString());
    }
    else
    {
        expr->Parse(value);
    }

    return expr;

}