Exemplo n.º 1
0
bool cShaderObject::SetFragmentShader( const char* string_ptr)
{
	if(mFragmentShader == 0)
	{
		mFragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
	}
	if(GL_FRAGMENT_SHADER != GetShaderType(mFragmentShader))
	{
		Log::Error("mFragmentShader is not a valid shader object");
		return false;
	}
	if(GL_NO_ERROR != LoadShaderImpl(FRAGMENT_SHADER, string_ptr))
	{
		return false;
	}
	return true;
}
Exemplo n.º 2
0
bool cShaderObject::SetVertexShader(const char* string_ptr)
{
	if (mVertexShader == 0)
	{
		mVertexShader = glCreateShader(GL_VERTEX_SHADER);
	}
	if(GL_VERTEX_SHADER != GetShaderType(mVertexShader))
	{
		Log::Error("mVertexShader is not a valid shader object");
		return false;
	}
	if(GL_NO_ERROR != LoadShaderImpl(VERTEX_SHADER, string_ptr))
	{
		return false;
	}
	return true;
}
Exemplo n.º 3
0
bool cShaderObject::SetGeometryShader(const char* string_ptr)
{
	if (mGeometryShader == 0)
	{
		mGeometryShader = glCreateShader(GL_GEOMETRY_SHADER);
	}
	if (GL_GEOMETRY_SHADER != GetShaderType(mGeometryShader))
	{
		Log::Error("mGeometryShader is not a valid shader object");
		return false;
	}
	if (GL_NO_ERROR != LoadShaderImpl(GEOMETRY_SHADER, string_ptr))
	{
		FatalError::Die("broken geometry shader");
	}
	return true;
}
Exemplo n.º 4
0
bool Material::AddShader(ShaderTypes shaderType, const char * shaderText)
{
	if (finalized)
	{
		SetErrorMessage("Already finalized the shader!");
		return false;
	}

	GLuint shaderObj;
	if (!SH::CreateShader(shaderProg, shaderObj, shaderText, GetShaderType(shaderType)))
	{
		SetErrorMessage(SH::GetErrorMessage());
		return false;
	}

	ShaderObjList::iterator it;

	it = shaderObjects.begin();
	it = shaderObjects.insert(it, shaderObj);

	return true;
}
Exemplo n.º 5
0
	void PrelightPipeline::DrawRenderable(const std::shared_ptr<Pass> &pass, const std::shared_ptr<SceneNode> &node)
	{
		auto render = node->GetComponent<MeshRender>();
		if (render == nullptr || !render->GetRenderable())
			return;

		auto mesh = render->GetMesh();
		auto material = render->GetMaterial();
		auto shader = material->GetShaderForPass(pass->GetRenderIndex());

		if (shader == nullptr)
			shader = pass->GetShader(material->GetShaderType());

		if (shader == nullptr)
		{
			LOGW << "Failed to draw " << node->GetName() << ", data incomplete!";
			return;
		}

		shader->Bind();
		shader->BindCamera(m_CurrentCamera);
		shader->BindMatrix(Matrix4::WORLD_MATRIX, node->GetWorldMatrix());

		shader->BindMesh(mesh);
		shader->BindMaterial(material);

		for (unsigned int i = 0; i < pass->GetTextureCount(true); i++)
		{
			auto ptr = pass->GetTextureAt(i, true);
			shader->BindTexture(ptr->GetName(), ptr);
		}

		glDrawElements(GL_TRIANGLES, mesh->Indices.Data.size(), GL_UNSIGNED_INT, 0);

		shader->UnBind();

		m_DrawCall++;
	}
///////////////////////////////////////////////
//  CONSTRUCTOR / DECONSTRUCT / OP OVERLOADS
///////////////////////////////////////////////
DiffuseRenderComponent::DiffuseRenderComponent(int componentType, int componentID) :
	RenderComponent(GetShaderType(), componentType, componentID)
{	
}
static gcSHADER
CompileFile(
    IN gcoOS Os,
    IN gctCONST_STRING FileName,
    IN gcoHAL Hal,
    IN gctUINT Option,
    IN gctBOOL DumpLog,
    IN gctBOOL DumpCompiledShader
    )
{
    gceSTATUS   status;
    gctINT      shaderType;
    gctSIZE_T   sourceSize;
    gctSTRING   source          = gcvNULL;
    gcSHADER    binary;
    gctSTRING   log             = gcvNULL;
    gctSIZE_T   bufferSize;
    gctSTRING   buffer;
    gctSTRING   dataFileName    = gcvNULL;
    gctSIZE_T   length;
    gctFILE     logFile         = gcvNULL;

    gcmASSERT(FileName);

    shaderType = GetShaderType(FileName);

    if (!ReadSource(Os, FileName, &sourceSize, &source)) return gcvNULL;

    status = gcCompileShader(Hal,
                             shaderType,
                             sourceSize, source,
                             &binary,
                             &log);

    if (log != gcvNULL)
    {
        printf("<LOG>\n");
        printf("%s", log);
        printf("</LOG>\n");
    }

    if (gcmIS_ERROR(status))
    {
        gcmASSERT(binary == gcvNULL);
        binary = gcvNULL;

        printf("*ERROR* Failed to compile %s (error: %d)\n", FileName, status);
        goto Exit;
    }

    gcmASSERT(binary != gcvNULL);

    if (DumpLog)
    {
        gcmVERIFY_OK(gcoOS_StrLen(FileName, &length));
        length += 5;
        gcmVERIFY_OK(gcoOS_Allocate(Os, length, (gctPOINTER *) &dataFileName));
        gcmVERIFY_OK(gcoOS_StrCopySafe(dataFileName, length, FileName));
        gcmVERIFY_OK(gcoOS_StrCatSafe(dataFileName, length, ".log"));

        status = gcoOS_Open(Os, dataFileName, gcvFILE_CREATETEXT, &logFile);
        if (gcmIS_ERROR(status))
        {
            logFile = gcvNULL;

            printf("*ERROR* Failed to open the log file: %s\n", dataFileName);
        }
        gcoOS_Free(Os, dataFileName);
    }

    gcmVERIFY_OK(gcSHADER_SetOptimizationOption(binary, Option));

    status = gcOptimizeShader(binary, logFile);

    if (!gcmIS_SUCCESS(status))
    {
        printf("*ERROR* Failed to optimize %s (error: %d)\n", FileName, status);
    }

    if (logFile != gcvNULL)
    {
        gcmVERIFY_OK(gcoOS_Close(Os, logFile));
    }

    if (DumpCompiledShader)
    {
        status = gcSHADER_Save(binary, gcvNULL, &bufferSize);
        if (gcmIS_ERROR(status))
        {
            printf("*ERROR* Failed to get the buffer size of the shader\n");
            goto Exit;
        }

        status = gcoOS_Allocate(Os, bufferSize, (gctPOINTER *) &buffer);
        if (!gcmIS_SUCCESS(status))
        {
            printf("*ERROR* Not enough memory\n");
            goto Exit;
        }

        status = gcSHADER_Save(binary, buffer, &bufferSize);
        if (status != gcvSTATUS_OK)
        {
            printf("*ERROR* Failed to get the buffer size of the shader\n");
            gcoOS_Free(Os, buffer);
            goto Exit;
        }

        OutputShaderData(Os, FileName, bufferSize, buffer);

        gcoOS_Free(Os, buffer);
    }


Exit:
    if (DumpLog && log != gcvNULL)
    {
        printf("**************** Compile Log ****************");
        printf("%s", log);
        printf("*********************************************");
    }

    if (log != gcvNULL) gcoOS_Free(Os, log);

    if (source != gcvNULL) gcoOS_Free(Os, source);

    return binary;
}