TiledLightRenderer::TiledLightRenderer(DeferredRenderer& deferred, bool hdr) : LightContextRenderer(deferred)
{
    _tileCount = deferred.resolution() / TILE_SIZE;
    if(deferred.resolution().x() % TILE_SIZE.x() != 0)
        _tileCount.x()++;
    if(deferred.resolution().y() % TILE_SIZE.y() != 0)
        _tileCount.y()++;

    ShaderCompiler shader(ShaderCompiler::COMPUTE_SHADER);
    shader.setSource(StringUtils::readFile("shader/tiledLightShader.cs"));

    auto optShader = Shader::linkComputeShader(shader.compile({}));

    if(!optShader.hasValue())
    {
        LOG("shader/tiledLightShader.cs error:\n", shader.error());
        LOG("Link erorr:", Shader::lastLinkError());
    }
    else
        _computeShader = optShader.value();

    _computeShader->bind();
    _nbLightUniformId = _computeShader->uniformLocation("nbLight");

    Texture::GenTexParam param;
    param.format = Texture::RGB16;
    param.nbLevels = 1;
    param.size = uivec3(256,256,1);
    float* dat = new float[256*256*3];
    std::ifstream inDat("shader/brdf_256.dat", std::ios_base::binary);
    inDat.read((char*)dat, sizeof(float)*256*256*3);
    _processedBrdf = Texture::genTexture2D(param, dat, 3);
    delete[] dat;
}
TextureBufferPool::Buffer TextureBufferPool::createBuffer(const Key& k)
{
    Buffer buf;
    if(k.type == Key::DEFERRED_BUFFER)
    {
        buf.fbo = new FrameBuffer(k.res.to<2>());
        FrameBuffer::setupDefferedFBO(*buf.fbo, buf.texs);
    }
    else if(k.type == Key::DEPTH_MAP_ARRAY)
    {
        renderer::Texture::GenTexParam p;
        p.format = renderer::Texture::Format::DEPTHCOMPONENT;
        p.nbLevels = 1;
        p.size = k.res;

        buf.texs.push_back(renderer::Texture::genTextureArray2D(p));
        buf.fbo = new FrameBuffer(k.res.to<2>());
    }
    else
    {
        if(!k.onlyTextures)
            buf.fbo = new FrameBuffer(k.res.to<2>());

        for(uint i=0 ; i<k.res.z() ; ++i)
        {
            Texture::GenTexParam param;
            param.size = uivec3(k.res.to<2>(),1);
            param.nbLevels = 1;
            param.format = k.hdr ? Texture::RGBA16F : Texture::RGBA8;

            buf.texs.push_back( Texture::genTexture2D(param) );

            if(!k.onlyTextures)
            {
                buf.fbo->attachTexture(i, buf.texs.back());
            }

        }

        if(!k.onlyTextures)
            buf.fbo->unbind();
    }

    buf.id = _idGenerator;
    return buf;
}
Esempio n. 3
0
void *
AttributeValues::getProp(unsigned int prop, Enums::DataType type) {

	void *val;

	switch (type) {

		case Enums::ENUM:
			if (m_EnumProps.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_EnumProps[prop] = *(int *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined attribute of type ENUM");
					SLOG("Accessing undefined attribute of type ENUM - This should never occur");
					m_EnumProps[prop] = 0;
				}
			}
			return(&(m_EnumProps[prop]));
			break;
		case Enums::INT:
			if (m_IntProps.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_IntProps[prop] = *(int *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined attribute of type INT");
					SLOG("Accessing undefined attribute of type INT - This should never occur");
					m_IntProps[prop] = 0;
				}
			}
			return(&(m_IntProps[prop]));
			break;
		case Enums::IVEC2:
			if (m_Int2Props.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)	
					m_Int2Props[prop] = *(ivec2 *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined attribute of type IVEC2");
					SLOG("Accessing undefined attribute of type IVEC2 - This should never occur");
					m_Int2Props[prop] = 0;
				}
			}
			return(&(m_Int2Props[prop]));
			break;
		case Enums::UINT:
			if (m_UIntProps.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_UIntProps[prop] = *(unsigned int *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined attribute of type UINT");
					SLOG("Accessing undefined attribute of type UINT - This should never occur");
					m_UIntProps[prop] = 0;
				}
			}
			return(&(m_UIntProps[prop]));
			break;
		case Enums::UIVEC2:
			if (m_UInt2Props.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_UInt2Props[prop] = *(uivec2 *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined attribute of type UINT2");
					SLOG("Accessing undefined attribute of type UINT2 - This should never occur");
					m_UInt2Props[prop] = uivec2(0);
				}
			}
			return(&(m_UInt3Props[prop]));
			break;
		case Enums::UIVEC3:
			if (m_UInt3Props.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_UInt3Props[prop] = *(uivec3 *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined attribute of type UINT3");
					SLOG("Accessing undefined attribute of type UINT3 - This should never occur");
					m_UInt3Props[prop] = uivec3(0);
				}
			}
			return(&(m_UInt3Props[prop]));
			break;
		case Enums::BOOL:
			if (m_BoolProps.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_BoolProps[prop] = *(bool *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined attribute of type BOOL");
					SLOG("Accessing undefined attribute of type BOOL - This should never occur");
					m_BoolProps[prop] = 0;
				}
			}
			return(&(m_BoolProps[prop]));
			break;
		case Enums::BVEC4:
			if (m_Bool4Props.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_Bool4Props[prop] = *(bvec4 *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined attribute of type BVEC4");
					SLOG("Accessing undefined attribute of type BVEC4 - This should never occur");
					m_Bool4Props[prop] = 0;
				}
			}
			return(&(m_Bool4Props[prop]));
			break;
		case Enums::FLOAT:
			if (m_FloatProps.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_FloatProps[prop] = *(float *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined user attribute of type FLOAT");
					SLOG("Accessing undefined user attribute of type FLOAT - This should never occur");
					m_FloatProps[prop] = 0;
				}
			}
			return(&(m_FloatProps[prop]));
			break;
		case Enums::VEC4:
			if (m_Float4Props.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_Float4Props[prop] = *(vec4 *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined user attribute of type VEC4");
					SLOG("Accessing undefined user attribute of type VEC4 - This should never occur");
					m_Float4Props[prop] = vec4(0.0f);
				}
			}
			return(&(m_Float4Props[prop]));
			break;
		case Enums::VEC3:
			if (m_Float3Props.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_Float3Props[prop] = *(vec3 *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined user attribute of type VEC3");
					SLOG("Accessing undefined user attribute of type VEC3 - This should never occur");
					m_Float3Props[prop] = vec3(0.0f);
				}
			}
			return(&(m_Float3Props[prop]));
			break;
		case Enums::VEC2:
			if (m_Float2Props.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_Float2Props[prop] = *(vec2 *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined user attribute of type VEC2");
					SLOG("Accessing undefined user attribute of type VEC2 - This should never occur");
					m_Float2Props[prop] = vec2(0.0f);
				}
			}
			return(&(m_Float2Props[prop]));
			break;
		case Enums::MAT4:
			if (m_Mat4Props.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_Mat4Props[prop] = *(mat4 *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined user attribute of type MAT4");
					SLOG("Accessing undefined user attribute of type MAT4 - This should never occur");
					m_Mat4Props[prop] = mat4();
				}
			}
			return(&(m_Mat4Props[prop]));
			break;
		case Enums::MAT3:
			if (m_Mat3Props.count(prop) == 0) {
				val = m_Attribs->getDefault(prop, type);
				if (val != NULL)
					m_Mat3Props[prop] = *(mat3 *)val;
				else { // life goes on ... except in debug mode
					assert(false && "Accessing undefined user attribute of type MAT3");
					SLOG("Accessing undefined user attribute of type MAT3 - This should never occur");
					m_Mat3Props[prop] = mat3();
				}
			}
			return(&(m_Mat3Props[prop]));
			break;
		default:
			assert(false && "Missing Data Type in class attributeValues");
			return NULL;
	}
};