bool initFramebuffer()
{
	glGenFramebuffers(framebuffer::MAX, &FramebufferName[0]);

	glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::RENDER]);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureName[texture::MULTISAMPLE], 0);
	if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
		return false;
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::RESOLVE]);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0);
	if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
		return false;
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	return glf::checkError("initFramebuffer");
}
Ejemplo n.º 2
0
	void FBO_Shadow::bind_for_point_shadow_pass()
	{
		bind_fbo();
		//Bind all cubemap, the geometry shader will take care of the faces
		glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_point_cube, 0);
		glDrawBuffer(GL_NONE);


	}
Ejemplo n.º 3
0
bool FrameBuffer::Allocate( int width, int height, int type /* = GL_RGBA */ )
{
    // TODO: Check for FBO extensions!

    bool b = glewGetExtension("GL_ARB_framebuffer_object");
    GL_ASSERT( b, "Missing extension 'ARB_framebuffer_object'!");

    glGenFramebuffers(1, (GLuint*)&m_FrameBufferID);
    GL_ASSERT( m_FrameBufferID > 0 , "Error generating frame buffer!" );
    glBindFramebuffer(GL_FRAMEBUFFER, m_FrameBufferID);

    // add a draw buffer - default = true
    if ( m_Flags & F_ENABLE_COLOR_BUFFER_F ) {

        // create a depth buffer
        if ( m_Flags & F_ENABLE_DEPTH_BUFFER_F ) {
            glGenRenderbuffers(1, (GLuint*)&m_DepthBufferID);
            GL_ASSERT( m_DepthBufferID > 0, "Error generating depth buffer!" );
            glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBufferID);
            glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
            // we will need to get access to this depth buffer - if we don't attach a texture
            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_DepthBufferID);
        }

        // create a texture to render into
        b = m_Texture->Allocate( width, height, type );
        ASSERT( b, "Error allocating texture!" );
        // Set "renderedTexture" as our colour attachement #0
        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_Texture->GetTextureId(), 0);
        glDrawBuffer( GL_COLOR_ATTACHMENT0 );
    }
    else if ( m_Flags & F_ENABLE_DEPTH_BUFFER_F ) {
        // depth buffer only
        // create a texture to render into
        b = m_Texture->Allocate( width, height, 16 ); // 16 bit float depth texture!
        ASSERT( b, "Error allocating texture!" );
        // Set "renderedTexture" as our depth attachement #0
        glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_Texture->GetTextureId(), 0);
        glDrawBuffer( NULL );
    }

    b &= ( glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE );
    return b;
}
void CascadedShadowMappingRenderer::initRendering()
{
    initCamera(
        NvCameraXformType::MAIN,
        nv::vec3f(-15.0f, 5.0f, 15.0f), // position
        nv::vec3f(0.0f, 0.0f, 0.0f));   // look at point

    // Setup the light parameters.
    initLight(
        nv::vec3f(100.0f, 100.0f, 100.0f),
        nv::vec3f(0.0f, 0.0f, 0.0f),
        nv::vec3f(0.0f, 1.0f, 0.0f));

    // Load shaders.
    NvAssetLoaderAddSearchPath("gl4-maxwell/CascadedShadowMapping");

    m_cameraProgram = new CameraProgram();
    m_cameraProgram->init("shaders/Camera.vert", "shaders/Camera.frag");

    m_lightStandardProgram = new LightProgram();
    m_lightStandardProgram->init("shaders/Light.vert", "shaders/LightStandard.geom");

    m_lightGsCullProgram = new LightProgram();
    m_lightGsCullProgram->init("shaders/Light.vert", "shaders/LightGsCull.geom");

    m_lightGsMulticastCullProgram = new LightProgram();
    m_lightGsMulticastCullProgram->init("shaders/Light.vert", "shaders/LightMulticast.geom");

    m_lightFgsMulticastCullProgram = new LightProgram();
    m_lightFgsMulticastCullProgram->init("shaders/Light.vert", "shaders/LightFgsMulticast.geom");

    m_lightVsOnlyMulticastProgram = new LightVsOnlyProgram();
    m_lightVsOnlyMulticastProgram->init("shaders/LightVsOnly.vert");

    // Setup geometry.
    initGeometry(10);

    // Setup resources for shadow pass.
    glGenFramebuffers(1, &m_lightFBO);
    glBindFramebuffer(GL_FRAMEBUFFER, m_lightFBO);

    glGenTextures(1, &m_lightTex);
    glBindTexture(GL_TEXTURE_2D_ARRAY, m_lightTex);
    glTexStorage3D(GL_TEXTURE_2D_ARRAY, LIGHT_TEXUTRE_MIPMAP_LEVELS, GL_DEPTH_COMPONENT32F, LIGHT_TEXTURE_SIZE, LIGHT_TEXTURE_SIZE, MAX_CAMERA_FRUSTUM_SPLIT_COUNT);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

    glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_lightTex, 0);

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, m_app.getMainFBO());

    glGetFloatv(GL_MAX_VIEWPORT_DIMS, m_viewportDims._array);
}
Ejemplo n.º 5
0
void ParticlesControl::init(Vertices* vertices, GLuint particlePosTexID[]) {

    /// Common initialization.
    preinit(vertices, passthrough_vshader, particles_control_fshader, NULL, "vertexPosition2D");

    /// The Sampler uniforms always refer to texture indices 0 and 1.
    /// The binding to textures 0 and 1 are however flipped every frame.
    GLuint uniformID = glGetUniformLocation(_programID, "particlePosTex");
    glUniform1i( uniformID, 0);
    uniformID = glGetUniformLocation(_programID, "particleVelTex");
    glUniform1i( uniformID, 1);

    /// Generate the two position and velocity textures (last and current).
    glGenTextures(4, _particleTexID);
    particlePosTexID[0] = _particleTexID[0];
    particlePosTexID[1] = _particleTexID[1];

    /// Position and velocity : three components, unclamped 32 bits float.
    /// Filtering technique has to be set, even that texels are fetch
    /// individually by fetchTexel() which bypass any filtering.
    /// Attach the textures to the corresponding FBO color attachments.
    glGenFramebuffers(1, &_framebufferID);
    glBindFramebuffer(GL_FRAMEBUFFER, _framebufferID);
    for(int k=0; k<4; ++k) {
        glBindTexture(GL_TEXTURE_1D, _particleTexID[k]);
        glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB32F, _width, 0, GL_RGB, GL_FLOAT, 0);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + k, _particleTexID[k], 0);
    }

    /// Initial particles position and velocity.
    /// Particles can be in x=[-1,1], y=[-1,1], z=[0,5].
    /// While g++ does, VC++ does not support particlesPos[3*nParticles] as
    /// nParticles isn't a compile-time constant. Allocate dynamically on the heap.
    const unsigned int nParticles = _nParticlesSide*_nParticlesSide*_nParticlesSide;
    float *particlesPos = new float[3*nParticles];
    float *particlesVel = new float[3*nParticles];
    for(int k=0; k<nParticles; ++k) {
        particlesPos[3*k+0] = 2.0f * float(k % (_nParticlesSide*_nParticlesSide) % _nParticlesSide) / float(_nParticlesSide) - 1.0f;  // x
        particlesPos[3*k+1] = 2.0f * float(k % (_nParticlesSide*_nParticlesSide) / _nParticlesSide) / float(_nParticlesSide) - 1.0f;  // y
        particlesPos[3*k+2] = 2.0f * float(k / (_nParticlesSide*_nParticlesSide)                  ) / float(_nParticlesSide) + 6.2f;  // z
        particlesVel[3*k+0] = 0.0f;  // x
        particlesVel[3*k+1] = 0.0f;  // y
        particlesVel[3*k+2] = 0.1f * float(k / (_nParticlesSide*_nParticlesSide)                  ) / float(_nParticlesSide) + 0.0f;  // z
    }
    glBindTexture(GL_TEXTURE_1D, _particleTexID[0]);
    glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB32F, _width, 0, GL_RGB, GL_FLOAT, particlesPos);
    glBindTexture(GL_TEXTURE_1D, _particleTexID[2]);
    glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB32F, _width, 0, GL_RGB, GL_FLOAT, particlesVel);
    delete[] particlesPos, particlesVel;

    /// Set uniform IDs.
    _deltaTID = glGetUniformLocation(_programID, "deltaT");

}
Ejemplo n.º 6
0
void Framebuffer::AttachTexture(GLenum attachment, const BaseTexture &texture, GLint level)
{
	GLint bind_draw = 0, bind_read = 0;
	glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &bind_draw);
	glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &bind_read);
	Bind();
	glFramebufferTexture(target, attachment, texture.GetId(), level);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, bind_draw);
	glBindFramebuffer(GL_READ_FRAMEBUFFER, bind_read);
}
Ejemplo n.º 7
0
void RenderTarget::initDepth(int width, int heigth, GLint depthFormat)
{
	m_isUsedDepth = true;
	glGenTextures(depthFormat, &m_depthBuffer);
	glBindTexture(GL_TEXTURE_2D, m_depthBuffer);
	glTexStorage2D(GL_TEXTURE_2D, 1, depthFormat, width, heigth);
	glBindTexture(GL_TEXTURE_2D, 0);

	glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_depthBuffer, 0);
}
static void
initialize_fbo()
{
	unsigned fbo;
	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0);
	assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) ==
	       GL_FRAMEBUFFER_COMPLETE);
}
Ejemplo n.º 9
0
void FBO::texture(const unsigned int attachment, const unsigned int textureID, const int level){
	attachments.push_back(attachment);

	glFramebufferTexture(target,
						 attachment,
						 textureID,
						 level);

	loaded = true;
}
Ejemplo n.º 10
0
void
piglit_init(int argc, char **argv)
{
	bool pass = true;
	GLuint fbo, texture;

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D_ARRAY, texture);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER,
			GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER,
			GL_NEAREST_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, 32, 32, 2, 0,
		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glGenerateMipmap(GL_TEXTURE_2D_ARRAY);

	if(!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	/* Check Default Values */
	pass = check_texture_parameters(GL_NONE, 0, 0, 0, GL_FALSE) && pass;

	/* Attach Texture to Framebuffer's Color Attachment0 */
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 2);

	/* Check Values of Texture */
	pass = check_texture_parameters(GL_TEXTURE, texture, 2, 0, GL_TRUE) && pass;

	/* Attach Texture of Zero to Framebuffer's Color Attachment0 */
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 0, 0);

	/* Check Values reset to default values */
	pass = check_texture_parameters(GL_NONE, 0, 0, 0, GL_FALSE) && pass;

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
Ejemplo n.º 11
0
void GLFBO::Bind() {
    is_active_ = true;
    glBindFramebuffer(Type_, names_);

    if (use_color_) {
        GLuint *attachments = new GLuint[numColorAttachments_];
        size_t i = 0;
        for (i; i < numColorAttachments_; i++) {
            glFramebufferTexture(Type_, GL_COLOR_ATTACHMENT0 + GLuint(i),
                                 *Color_Texture_.at(i)->GetData(), 0);
            attachments[i] = {GL_COLOR_ATTACHMENT0 + GLuint(i)};
        }
        glDrawBuffers(GLuint(i), attachments);
    }
    if (use_depth_) {
        glFramebufferTexture(Type_, GL_DEPTH_ATTACHMENT, *Depth_Texture_->GetData(),
                             0);
    }
}
Ejemplo n.º 12
0
NLightSystem::NLightSystem()
{
    glGenFramebuffers(1,&FrameBuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, FrameBuffer);

    //Texture
    glGenTextures(1,&FrameBufferTexture);
    glBindTexture(GL_TEXTURE_2D,FrameBufferTexture);
    glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, GetGame()->GetWindowWidth(), GetGame()->GetWindowHeight(), 0,GL_RGB, GL_UNSIGNED_BYTE, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //According to the tutorial I'm following, frame buffers require bad filtering.
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glFramebufferTexture(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,FrameBufferTexture,0);

    //Stencil
    /*glGenTextures(1,&StencilBuffer);
    glBindTexture(GL_TEXTURE_2D,StencilBuffer);
    glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, GetGame()->GetWindowWidth(), GetGame()->GetWindowHeight(), 0,GL_RGB, GL_UNSIGNED_BYTE, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //According to the tutorial I'm following, frame buffers require bad filtering.
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glFramebufferTexture(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,StencilBuffer,0);*/
    glGenRenderbuffers(1,&StencilBuffer);
    glBindRenderbuffer(GL_RENDERBUFFER,StencilBuffer);
    glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_STENCIL,GetGame()->GetWindowWidth(),GetGame()->GetWindowHeight());
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,StencilBuffer);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER,StencilBuffer);

    GetGame()->GetRender()->CheckFramebuffer();
    glClearColor(1,1,1,1);
    glClearStencil(0);
    glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glBindTexture(GL_TEXTURE_2D, 0);
    glBindFramebuffer(GL_FRAMEBUFFER,0);

    //Generate screen quad
    Shader = GetGame()->GetRender()->GetShader("flat_colorless");
    if (Shader != NULL)
    {
        TextureLoc = Shader->GetUniformLocation("Texture");
    }
    glGenBuffers(2,VertexBuffers);
    Verts.clear();
    UVs.clear();
    Verts.push_back(glm::vec2(-1,-1));
    UVs.push_back(glm::vec2(0,0));
    Verts.push_back(glm::vec2(1,-1));
    UVs.push_back(glm::vec2(1,0));
    Verts.push_back(glm::vec2(1,1));
    UVs.push_back(glm::vec2(1,1));
    Verts.push_back(glm::vec2(-1,1));
    UVs.push_back(glm::vec2(0,1));
    glBindBuffer(GL_ARRAY_BUFFER,VertexBuffers[0]);
    glBufferData(GL_ARRAY_BUFFER,Verts.size()*sizeof(glm::vec2),&Verts[0],GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER,VertexBuffers[1]);
    glBufferData(GL_ARRAY_BUFFER,UVs.size()*sizeof(glm::vec2),&UVs[0],GL_STATIC_DRAW);
}
Ejemplo n.º 13
0
bool
test_framebuffertexture(GLenum textureType)
{
	bool pass = true;
	GLuint fbo, texture;

	float expected[] = { 0, 1, 0 };

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	texture = create_bind_texture(textureType);

	/* Attach the texture to the framebuffer object */
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			     texture, 0);

	if(!piglit_check_gl_error(GL_NO_ERROR) ||
	   !check_framebuffer_status(GL_FRAMEBUFFER, GL_FRAMEBUFFER_COMPLETE)) {
		glDeleteFramebuffers(1, &fbo);
		glDeleteTextures(1, &texture);
		printf("Texture Type: %s. Error during setup.\n",
		       piglit_get_gl_enum_name(textureType));
		return false;
	}

	piglit_draw_rect(-1, -1, 2, 2);

	/* If the texture is a multisample texture,
	 * convert it to a 2D texture */
	if(textureType == GL_TEXTURE_2D_MULTISAMPLE ||
	   textureType == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
		ConvertMultiSample2DToTexture2D(fbo);
	}

	/* Probe for the expected color value */
	if(textureType == GL_TEXTURE_1D ||
	   textureType == GL_TEXTURE_1D_ARRAY) {
		if(!piglit_probe_rect_rgb(0, 0, 6, 1, expected)) {
			pass = false;
		}
	} else {
		if(!piglit_probe_rect_rgb(0, 0, 6, 6, expected)) {
			pass = false;
		}
	}

	/* Clean up */
	glDeleteFramebuffers(1, &fbo);
	glDeleteTextures(1, &texture);

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	return pass;
}
Ejemplo n.º 14
0
void NzRenderTexture::Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index)
{
	#if NAZARA_RENDERER_SAFE
	if (!m_impl)
	{
		NazaraError("Render texture not created");
		return;
	}

	if (attachmentPoint != nzAttachmentPoint_Color && index > 0)
	{
		NazaraError("Index must be 0 for non-color attachments");
		return;
	}
	#endif

	unsigned int attachIndex = attachmentIndex[attachmentPoint]+index;
	if (attachIndex >= m_impl->attachements.size())
		return;

	Attachment& attachement = m_impl->attachements[attachIndex];
	if (!attachement.isUsed)
		return;

	if (!Lock())
	{
		NazaraError("Failed to lock render texture");
		return;
	}

	attachement.isUsed = false;

	if (attachement.isBuffer)
	{
		glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_RENDERBUFFER, 0);
		glDeleteRenderbuffers(1, &attachement.buffer);
	}
	else
	{
		if (glFramebufferTexture)
			glFramebufferTexture(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, 0, 0);
		else
			glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, 0, 0, 0);

		attachement.texture->RemoveResourceListener(this);
		attachement.texture->SetRenderTexture(nullptr);
	}

	Unlock();

	m_impl->checked = false;
	m_impl->drawBuffersUpdated = false;

}
Ejemplo n.º 15
0
void GLDepthRenderTarget::makeTargetLayer(int l) {
	GLRenderTarget::makeTarget();
	
	if(passes[0]->arrayTexture)
		glFramebufferTextureLayerEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, passes[0]->texmaps[0], 0, l);
	else
		glFramebufferTexture(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, passes[0]->texmaps[0], 0);
#ifdef DEBUG
	GLSL_catchLastError("GLDepthRenderTarget::makeTargetLayer");
#endif
}
Ejemplo n.º 16
0
	bool initFramebuffer()
	{
		glGenFramebuffers(1, &FramebufferName);
		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, TextureName[texture::RENDERBUFFER], 0);

		if(!this->checkFramebuffer(FramebufferName))
			return false;

		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		GLint const EncodingLinear = GL_LINEAR;
		GLint const EncodingSRGB = GL_SRGB;

		GLint Encoding = 0;
		glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &Encoding);

		return true;
	}
EVA::Light::Light(const Type type, const bool shadows, const unsigned int shadowSize)
{
	m_Type = type;
	m_Shadows = shadows;
	m_ShadowMapSize = shadowSize;

	if(!shadows)
		return;;

	if(m_Type == Directional)
	{
		glGenTextures(1, &m_DepthMap);
		glBindTexture(GL_TEXTURE_2D, m_DepthMap);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
			m_ShadowMapSize, m_ShadowMapSize, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

		float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
		glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);

		glGenFramebuffers(1, &m_DepthMapFb);
		glBindFramebuffer(GL_FRAMEBUFFER, m_DepthMapFb);
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_DepthMap, 0);
		glDrawBuffer(GL_NONE);
		glReadBuffer(GL_NONE);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}
	else
	{
		glGenTextures(1, &m_DepthMap);
		glBindTexture(GL_TEXTURE_CUBE_MAP, m_DepthMap);

		for (unsigned int i = 0; i < 6; ++i)
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT,
				m_ShadowMapSize, m_ShadowMapSize, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);

		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		
		glGenFramebuffers(1, &m_DepthMapFb);
		glBindFramebuffer(GL_FRAMEBUFFER, m_DepthMapFb);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0);
		glDrawBuffer(GL_NONE);
		glReadBuffer(GL_NONE);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}
}
Ejemplo n.º 18
0
void FramebufferObject::bindStencilTexture(TextureBuffer* TB)
{
	bind();
	glFramebufferTexture(
		GL_DRAW_FRAMEBUFFER,
		GL_STENCIL_ATTACHMENT,
		TB->mTex,
		0
		);
	mStencilBuffer = TB;
}
Ejemplo n.º 19
0
void FramebufferObject::bindDepthTexture(TextureBuffer* TB)
{
	bind();
	glFramebufferTexture(
		GL_DRAW_FRAMEBUFFER,
		GL_DEPTH_ATTACHMENT,
		TB->mTex,
		0
		);
	mDepthBuffer = TB;
}
	bool initFramebuffer()
	{
		glGenFramebuffers(framebuffer::MAX, &this->FramebufferName[0]);

		glBindFramebuffer(GL_FRAMEBUFFER, this->FramebufferName[framebuffer::RENDER]);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureName[texture::MULTISAMPLE_COLORBUFFER], 0);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, TextureName[texture::MULTISAMPLE_DEPTHBUFFER], 0);

		glBindFramebuffer(GL_FRAMEBUFFER, this->FramebufferName[framebuffer::RESOLVE]);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0);

		if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
			return false;
		if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
			return false;

		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		return true;
	}
Ejemplo n.º 21
0
    void startup() override
    {
        LoadShaders();
        static const char* const objNames[] =
        {
            "media/objects/dragon.sbm",
            "media/objects/sphere.sbm",
            "media/objects/cube.sbm",
            "media/objects/torus.sbm"
        };
        for (int i = 0; i < OBJECT_COUNT; i++)
        {
            Objects[i].Obj.load(objNames[i]);
        }
        glGenFramebuffers(1, &_depthFBO);
        glBindFramebuffer(GL_FRAMEBUFFER, _depthFBO);

        glGenTextures(1, &_depthTex);
        glBindTexture(GL_TEXTURE_2D, _depthTex);

        glTexStorage2D(GL_TEXTURE_2D, 11, GL_DEPTH_COMPONENT32F, DEPTH_TEXTURE_SIZE, DEPTH_TEXTURE_SIZE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

        glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _depthTex, 0);

        glGenTextures(1, &_depthDebugTex);
        glBindTexture(GL_TEXTURE_2D, _depthDebugTex);
        glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, DEPTH_TEXTURE_SIZE, DEPTH_TEXTURE_SIZE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _depthDebugTex, 0);
        glBindTexture(GL_TEXTURE_2D, 0);
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        glEnable(GL_DEPTH_TEST);
        glGenVertexArrays(1, &_quadVao);
        glBindVertexArray(_quadVao);
    }
Ejemplo n.º 22
0
void
piglit_init(int argc, char **argv)
{
	int i, j;
	GLenum fbstatus;
	float *colorLayers =
		malloc(sizeof(float) * layers *
		       piglit_width * piglit_height * 3);
	float colors[3][3] = {
		{0.0, 0.0, 1.0},
		{0.0, 1.0, 0.0},
		{1.0, 0.0, 0.0}
	};

	/* Create color data for texture */
	for(j = 0; j < layers; j++) {
		float *thisLayer =
			&colorLayers[j * piglit_width * piglit_height * 3];
		for(i = 0; i < piglit_width*piglit_height; i++) {
			thisLayer[i*3+0] = colors[j][0];
			thisLayer[i*3+1] = colors[j][1];
			thisLayer[i*3+2] = colors[j][2];
		}
	}

	glGenTextures(2, texture);
	glGenFramebuffers(2, fbo);
	for(i = 0; i < 2; i++) {
		/* Create texture */
		glBindTexture(GL_TEXTURE_2D_ARRAY, texture[i]);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_R, GL_REPEAT);
		glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, piglit_width, piglit_height,
			     layers, 0, GL_RGB, GL_FLOAT, colorLayers);

		/* Gen Framebuffer */
		glBindFramebuffer(GL_FRAMEBUFFER, fbo[i]);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				     texture[i], 0);

		fbstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
		if(fbstatus != GL_FRAMEBUFFER_COMPLETE){
			printf("%s\n", piglit_get_gl_enum_name(fbstatus));
			piglit_report_result(PIGLIT_FAIL);
		}
	}

	if(!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);
}
Ejemplo n.º 23
0
void regenerateMainFBORenderDepthBuffer() {
    renderScaleChanged = false;
    
    const int numBuffers = 1;
    if(fbos[0] != 0) {
        glDeleteBuffers(numBuffers, fbos);
    }
    if(depthBuffer != 0) {
        glDeleteRenderbuffers(1, &depthBuffer);
    }
    if(textures[0] != 0) {
        glDeleteTextures(numBuffers, textures);
    }
    
    glGenFramebuffers(numBuffers, fbos);
    glGenRenderbuffers(1, &depthBuffer);
    glGenTextures(numBuffers, textures);
    
    for (int i = 0; i < numBuffers; ++i) {
        glBindFramebuffer(GL_FRAMEBUFFER, fbos[i]);
        glBindTexture(GL_TEXTURE_2D, textures[i]);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
        //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textures[i], 0);
		// Set the list of draw buffers.
		GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
		glDrawBuffers(1, DrawBuffers); // "1" is the size of DrawBuffers
        
        glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
        if (i == 0) {
            glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32,//24,
                                  textureWidth, textureHeight);
        }
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                                  GL_RENDERBUFFER, depthBuffer);
        if (!checkForErrors()) {
            std::cerr << "Stage 1 - Problem generating FBO " << i << std::endl;
            exit(EXIT_FAILURE);
        }
        
        std::cout << "Generating FBO #" << i << std::endl;
        std::cout << "FBO: " << textureWidth << "x" << textureHeight << std::endl;
        
        if (!checkForErrors() ||
            glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
            std::cerr << "Stage 2 - Problem generating FBO " << i << std::endl;
            exit(EXIT_FAILURE);
        }
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
    }
}
Ejemplo n.º 24
0
bool initFramebuffer()
{
	bool Validated(true);

	glGenFramebuffers(framebuffer::MAX, &FramebufferName[0]);

	glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::FRAMEBUFFER]);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, TextureName[texture::RENDERBUFFER], 0);
	if(glf::checkFramebuffer(FramebufferName[framebuffer::FRAMEBUFFER]))
		return false;

	glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::SHADOW]);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, TextureName[texture::SHADOWMAP], 0);
	glDrawBuffer(GL_NONE);
	if(glf::checkFramebuffer(FramebufferName[framebuffer::FRAMEBUFFER]))
		return false;

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	return true;
}
GLuint WaterFrameBuffers::createDepthTextureAttachment(int width, int height) {
    GLuint texture;
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height,
                 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                         texture, 0);
    return texture;
}
void
piglit_init(int argc, char **argv)
{
	int i;
	bool pass = true;
	GLenum fbStatus;
	GLuint fbo, texture;
	GLint attachmentLayeredStatus;

	for(i = 0; i < ARRAY_SIZE(textureType); i++) {
		glGenFramebuffers(1, &fbo);
		glBindFramebuffer(GL_FRAMEBUFFER, fbo);

		texture = create_bind_texture(textureType[i]);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				     texture, 0);

		if(!piglit_check_gl_error(GL_NO_ERROR)) {
			printf("Error creating texture and framebuffer setup\n"
			       "texture type: %s\n",
			       piglit_get_gl_enum_name(textureType[i]));
			glDeleteFramebuffers(1, &fbo);
			glDeleteTextures(1, &texture);
			piglit_report_result(PIGLIT_FAIL);
		}

		fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
		if(fbStatus != GL_FRAMEBUFFER_COMPLETE) {
			printf("Framebuffer Status: %s\n",
				piglit_get_gl_enum_name(fbStatus));
			glDeleteFramebuffers(1, &fbo);
			glDeleteTextures(1, &texture);
			piglit_report_result(PIGLIT_FAIL);
		}

		/* Check if the attachment is layered */
		glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
						      GL_COLOR_ATTACHMENT0,
						      GL_FRAMEBUFFER_ATTACHMENT_LAYERED,
						      &attachmentLayeredStatus);

		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

		if(attachmentLayeredStatus != GL_TRUE) {
			pass = false;
		}

		glDeleteFramebuffers(1, &fbo);
		glDeleteTextures(1, &texture);
	}

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
Ejemplo n.º 27
0
	bool initFramebuffer()
	{
		glGenFramebuffers(1, &FramebufferName);

		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureName[texture::RENDERBUFFER], 0);
		if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
			return false;
		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		return this->checkError("initFramebuffer");
	}
	bool initFramebuffer()
	{
		glGenFramebuffers(1, &FramebufferName);
		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0);

		if(!this->checkFramebuffer(FramebufferName))
			return false;

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		return true;
	}
bool initFramebuffer()
{
	glGenFramebuffers(1, &FramebufferName);
	glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureColorbufferName, 0);

	if(glf::checkFramebuffer(FramebufferName))
		return false;

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	return true;
}
GLuint WaterFrameBuffers::createTextureAttachment(int width, int height) {
    GLuint texture;
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height,
                 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                         texture, 0);
    return texture;
}