void RenderTarget::glInit(){
    this->glBind();
    pTex->glBind();
    pDepth->glBind();

    if( numSamples ){
      glFramebufferTexture1D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_1D, pTex->glGetInternalTexture() ,0 );
      glFramebufferTexture1D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,GL_TEXTURE_1D, pDepth->glGetInternalTexture() ,0 );
    }else{
      glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pTex->glGetInternalTexture(), 0 );
      glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, pDepth->glGetInternalTexture(), 0 );
    }
  }
void FramebufferImplementation_Legacy::attachTexture(const Framebuffer * fbo, GLenum attachment, Texture * texture, GLint level) const
{
    fbo->bind(s_workingTarget);

    if (texture == nullptr)
    {
        glFramebufferTexture(s_workingTarget, attachment, 0, level);
    }
    else
    {
        switch (texture->target())
        {
        case GL_TEXTURE_1D:
            glFramebufferTexture1D(s_workingTarget, attachment, texture->target(), texture->id(), level);
            break;
        case GL_TEXTURE_2D:
        case GL_TEXTURE_RECTANGLE:
        case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
        case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
        case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
        case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
        case GL_TEXTURE_2D_MULTISAMPLE:
            glFramebufferTexture2D(s_workingTarget, attachment, texture->target(), texture->id(), level);
            break;
        default:
            glFramebufferTexture(s_workingTarget, attachment, texture->id(), level);
            break;
        }
    }
}
예제 #3
0
bool RenderTargetTexture::allocate() {
	glGenFramebuffers(1, &m_fbo);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);

//	glBindTexture(m_texture->m_textureTarget, m_texture->m_texID);
	switch (m_texture->m_textureTarget) {
	case GL_TEXTURE_1D:
		glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture->m_textureTarget,
				m_texture->m_texID, 0);
		break;
	case GL_TEXTURE_2D:
	default:
		glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture->m_textureTarget,
				m_texture->m_texID, 0);
	}
	if (m_texture->m_useMipmaps) {
		glGenerateMipmap(m_texture->m_textureTarget);
	}
	if (m_useDepth) {
		glGenRenderbuffers(1, &m_depthBuffer);
		glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer);
		glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_multisample, GL_DEPTH_COMPONENT32, m_texture->m_width,
				m_texture->m_height);
		glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthBuffer);
	}
	GLenum status = _checkFramebufferStatus();
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
	return status == GL_FRAMEBUFFER_COMPLETE;
}
예제 #4
0
void RenderTargetTexture::bind() {
	// bind buffer for writing
	assert(m_fbo && glIsFramebuffer(m_fbo));
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);

	switch (m_texture->m_textureTarget) {
	case GL_TEXTURE_1D:
		glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture->m_textureTarget,
				m_texture->m_texID, 0);
		break;
	case GL_TEXTURE_2D:
	default:
		glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture->m_textureTarget,
				m_texture->m_texID, 0);
	}

	GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
	if (m_useDepth) {
		clearMask |= GL_DEPTH_BUFFER_BIT;
		glEnable(GL_DEPTH_TEST);
	}

	glClear(clearMask);

}
예제 #5
0
파일: Framebuffer.cpp 프로젝트: 0x2A/NoWork
bool Framebuffer::BindTexture(RenderTexturePtr renderTexture, AttachmentType targetAttachmentType)
{
	if (!renderTexture)
		return false;

	glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
	switch (renderTexture->GetType())
	{
	case GL_TEXTURE_1D:
		glFramebufferTexture1D(GL_FRAMEBUFFER, targetAttachmentType, renderTexture->GetType(), renderTexture->GetTextureId(), 0);
		break;
	case GL_TEXTURE_2D:
		glFramebufferTexture2D(GL_FRAMEBUFFER, targetAttachmentType, renderTexture->GetType(), renderTexture->GetTextureId(), 0);
		break;
	case GL_TEXTURE_3D:
		glFramebufferTexture3D(GL_FRAMEBUFFER, targetAttachmentType, renderTexture->GetType(), renderTexture->GetTextureId(), 0, 0);
		break;
	default:
		glFramebufferTexture(GL_FRAMEBUFFER, targetAttachmentType, renderTexture->GetTextureId(), 0);
	}

	// check FBO status
	GLenum FBOstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
	if (FBOstatus != GL_FRAMEBUFFER_COMPLETE)
	{
		LOG_ERROR("GLError: GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO\n");
		return false;
	}

	// switch back to window-system-provided framebuffer
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	return true;
}
예제 #6
0
void FrameBufferObject::attachDepthTexture( const kvs::Texture1D& texture, const int mip_level ) const
{
    GuardedBinder binder( *this );
    const GLuint id = texture.id();
    const GLenum attachment = GL_DEPTH_ATTACHMENT;
    const GLenum type = GL_TEXTURE_1D;
    KVS_GL_CALL( glFramebufferTexture1D( GL_FRAMEBUFFER, attachment, type, id, mip_level ) );
}
예제 #7
0
void FrameBufferObject::attachColorTexture( const kvs::Texture1D& texture, const size_t color_buffer, const int mip_level ) const
{
    KVS_ASSERT( static_cast<GLint>( color_buffer ) < kvs::OpenGL::MaxColorAttachments() );
    GuardedBinder binder( *this );
    const GLuint id = texture.id();
    const GLenum attachment = GL_COLOR_ATTACHMENT0 + color_buffer;
    const GLenum type = GL_TEXTURE_1D;
    KVS_GL_CALL( glFramebufferTexture1D( GL_FRAMEBUFFER, attachment, type, id, mip_level ) );
}
예제 #8
0
void R_AttachFBOTexture1D(int texId, int index)
{
	if (index < 0 || index >= glConfig2.maxColorAttachments)
	{
		Ren_Warning("R_AttachFBOTexture1D: invalid attachment index %i\n", index);
		return;
	}

	glFramebufferTexture1D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_TEXTURE_1D, texId, 0);
}
 inline void VL_glFramebufferTexture1D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
 {
   if (glFramebufferTexture1D)
     glFramebufferTexture1D(target, attachment, textarget, texture, level);
   else
   if (glFramebufferTexture1DEXT)
     glFramebufferTexture1DEXT(target, attachment, textarget, texture, level);
   else
     VL_UNSUPPORTED_FUNC();
 }
예제 #10
0
void FBO::texture1D(const unsigned int attachment, const unsigned int textureID, const int level){
	attachments.push_back(attachment);

	glFramebufferTexture1D(target,
						   attachment,
						   GL_TEXTURE_1D,
						   textureID,
						   level);

	loaded = true;
}
	bool GL3FrameBufferProvider::attach_object(GLenum opengl_attachment, const Texture &texture, int level, int zoffset, GLuint texture_target)
	{
		int internal_attachment_offset = decode_internal_attachment_offset(opengl_attachment);

		// Check for object replacement
		bool is_replaced_object = false;
		if (!attached_renderbuffers[internal_attachment_offset].is_null())
		{
			is_replaced_object = true;
			attached_renderbuffers[internal_attachment_offset] = RenderBuffer();
		}
		if (!attached_textures[internal_attachment_offset].is_null())
		{
			is_replaced_object = true;
			attached_textures[internal_attachment_offset] = Texture2D();
		}

		// Store the texture
		attached_textures[internal_attachment_offset] = texture;

		// Bind the renderbuffer
		GL3TextureProvider *gl_texture_provider = dynamic_cast<GL3TextureProvider*>(texture.get_provider());
		if (!gl_texture_provider)
			throw Exception("Invalid texture");

		GLuint texture_type = gl_texture_provider->get_texture_type();
		GLuint texture_handle = gl_texture_provider->get_handle();

		GLenum target = GL_DRAW_FRAMEBUFFER;
		if (bind_target == framebuffer_read)
			target = GL_READ_FRAMEBUFFER;

		if (!texture_target)
			texture_target = texture_type;

		if (texture_type == GL_TEXTURE_1D)
		{
			glFramebufferTexture1D(target, opengl_attachment, texture_target, texture_handle, level);
		}
		else if (texture_type == GL_TEXTURE_2D)
		{
			glFramebufferTexture2D(target, opengl_attachment, texture_target, texture_handle, level);
		}
		else if (texture_type == GL_TEXTURE_3D)
		{
			glFramebufferTexture3D(target, opengl_attachment, texture_target, texture_handle, level, zoffset);
		}
		else if (texture_type == GL_TEXTURE_2D_ARRAY || texture_type == GL_TEXTURE_1D_ARRAY)
		{
			glFramebufferTextureLayer(target, opengl_attachment, texture_handle, level, zoffset);
		}
		return is_replaced_object;
	}
예제 #12
0
파일: tr_fbo.c 프로젝트: otty/cake3
/*
=================
R_AttachFBOTexture1D
=================
*/
void R_AttachFBOTexture1D(int texId, int index)
{
#if defined(USE_D3D10)
	// TODO
#else
	if(index < 0 || index >= glConfig2.maxColorAttachments)
	{
		ri.Printf(PRINT_WARNING, "R_AttachFBOTexture1D: invalid attachment index %i\n", index);
		return;
	}

	glFramebufferTexture1D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_TEXTURE_1D, texId, 0);
#endif
}
예제 #13
0
	void GLTextureBuffer::bindToFramebuffer(GLenum attachment, UINT32 zoffset, bool allLayers)
	{
		if(mTarget == GL_TEXTURE_1D || mTarget == GL_TEXTURE_2D)
			allLayers = true;

		if(allLayers)
		{
			switch (mTarget)
			{
			case GL_TEXTURE_1D:
				glFramebufferTexture1D(GL_FRAMEBUFFER, attachment, mFaceTarget, mTextureID, mLevel);
				BS_CHECK_GL_ERROR();
				break;
			case GL_TEXTURE_2D:
				glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, mFaceTarget, mTextureID, mLevel);
				BS_CHECK_GL_ERROR();
				break;
			case GL_TEXTURE_2D_MULTISAMPLE:
				glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, mFaceTarget, mTextureID, 0);
				BS_CHECK_GL_ERROR();
				break;
			case GL_TEXTURE_CUBE_MAP:
			case GL_TEXTURE_3D:
			default: // Texture arrays (binding all layers)
				glFramebufferTexture(GL_FRAMEBUFFER, attachment, mTextureID, mLevel);
				BS_CHECK_GL_ERROR();
				break;
			}
		}
		else
		{
			switch (mTarget)
			{
			case GL_TEXTURE_3D:
				glFramebufferTexture3D(GL_FRAMEBUFFER, attachment, mFaceTarget, mTextureID, mLevel, zoffset);
				BS_CHECK_GL_ERROR();
				break;
			case GL_TEXTURE_CUBE_MAP:
				glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, mFaceTarget, mTextureID, mLevel);
				BS_CHECK_GL_ERROR();
				break;
			default: // Texture arrays
				glFramebufferTextureLayer(GL_FRAMEBUFFER, attachment, mTextureID, mLevel, mFace);
				BS_CHECK_GL_ERROR();
				break;
			}
		}
	}
예제 #14
0
/// Bind a texture to the "attachment" point of this FBO (GL_COLOR_ATTACHMENT0_EXT, textarget, texID)
void FrameBufferObject::attachTexture( GLenum attachment, GLenum texType, GLuint texId,int mipLevel, int zSlice)
{
	if (texType == GL_TEXTURE_1D) {
		glFramebufferTexture1D( GL_FRAMEBUFFER, attachment,
								   GL_TEXTURE_1D, texId, mipLevel );
	}
	else if (texType == GL_TEXTURE_3D) {
		glFramebufferTexture3D( GL_FRAMEBUFFER, attachment,
								   GL_TEXTURE_3D, texId, mipLevel, zSlice );
	}
	else {
		// Default is GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, or cube faces
		glFramebufferTexture2D( GL_FRAMEBUFFER, attachment,
								   texType, texId, mipLevel );
	}
}
예제 #15
0
static GLuint
create_texture_1d(void)
{
	GLuint tex, fb;
	GLenum status;
	int i, dim;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_1D, tex);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	for (i = 0, dim = TEX_SIZE; dim >0; i++, dim /= 2) {
		glTexImage1D(GL_TEXTURE_1D, i, format, dim, 0,
			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	}

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

	glFramebufferTexture1D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			       GL_TEXTURE_1D, tex, 0);

	status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
	if (status != GL_FRAMEBUFFER_COMPLETE) {
		load_texture_1d();
		goto done;
	}

	glViewport(0, 0, TEX_SIZE, 1);
	piglit_ortho_projection(TEX_SIZE, 1, GL_FALSE);

	glColor4fv(colors[0]);
	piglit_draw_rect(0, 0, TEX_SIZE / 4, 1);
	glColor4fv(colors[1]);
	piglit_draw_rect(TEX_SIZE / 4, 0, TEX_SIZE / 4, 1);
	glColor4fv(colors[2]);
	piglit_draw_rect(TEX_SIZE / 2, 0, TEX_SIZE / 4, 1);
	glColor4fv(colors[3]);
	piglit_draw_rect(TEX_SIZE/4 * 3, 0, TEX_SIZE / 4, 1);

done:
	glDeleteFramebuffers(1, &fb);
	glGenerateMipmap(GL_TEXTURE_1D);
	return tex;
}
예제 #16
0
void FramebufferObject::attachTexture(Texture* texture, GLenum attachment, int mipLevel, int zSlice) {
	switch(texture->type()) {
		case GL_TEXTURE_1D:
			glFramebufferTexture1D( GL_FRAMEBUFFER, attachment, GL_TEXTURE_1D, *texture, mipLevel );
			break;
		case GL_TEXTURE_3D:
			glFramebufferTexture3D( GL_FRAMEBUFFER, attachment, GL_TEXTURE_3D, *texture, mipLevel, zSlice );
			break;
		case GL_TEXTURE_2D_ARRAY:
			glFramebufferTextureLayer( GL_FRAMEBUFFER, attachment, *texture, mipLevel, zSlice );
			break;
		default: //GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE
			glFramebufferTexture2D( GL_FRAMEBUFFER, attachment, texture->type(), GLuint(*texture), mipLevel );
			break;
	}
	_attachedTextures[attachment] = texture;
}
	void GL3FrameBufferProvider::detach_object(GLenum opengl_attachment)
	{
		int internal_attachment_offset = decode_internal_attachment_offset(opengl_attachment);

		GLenum target = GL_DRAW_FRAMEBUFFER;
		if (bind_target == framebuffer_read)
			target = GL_READ_FRAMEBUFFER;

		if (!attached_renderbuffers[internal_attachment_offset].is_null())
		{
			glFramebufferRenderbuffer(target, opengl_attachment, GL_RENDERBUFFER, 0);
			attached_renderbuffers[internal_attachment_offset] = RenderBuffer();
		}

		if (!attached_textures[internal_attachment_offset].is_null())
		{
			GL3TextureProvider *gl_texture_provider = dynamic_cast<GL3TextureProvider*>(attached_textures[internal_attachment_offset].get_provider());
			GLuint texture_type = gl_texture_provider->get_texture_type();

			if (texture_type == GL_TEXTURE_1D)
			{
				glFramebufferTexture1D(target, opengl_attachment, texture_type, 0, 0);
			}
			else if (texture_type == GL_TEXTURE_2D)
			{
				glFramebufferTexture2D(target, opengl_attachment, texture_type, 0, 0);
			}
			else if (texture_type == GL_TEXTURE_3D)
			{
				glFramebufferTexture3D(target, opengl_attachment, texture_type, 0, 0, 0);
			}
			else if (texture_type == GL_TEXTURE_2D_ARRAY || texture_type == GL_TEXTURE_1D_ARRAY)
			{
				glFramebufferTextureLayer(target, opengl_attachment, 0, 0, 0);
			}

			attached_textures[internal_attachment_offset] = Texture();
		}
	}
예제 #18
0
 void RenderTargetFBO::AttachmentTexture::bind1D( AttachmentTarget attachment, GLuint textureId )
 {
   glFramebufferTexture1D( GL_FRAMEBUFFER_EXT, static_cast<GLenum>(attachment), m_textureTarget, textureId, m_level );
 }
예제 #19
0
bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture, unsigned int z)
{
	#if NAZARA_RENDERER_SAFE
	if (!m_impl)
	{
		NazaraError("Render texture not created");
		return false;
	}

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

	if (attachmentPoint == nzAttachmentPoint_Stencil)
	{
		NazaraError("Targeting stencil-only textures is not supported");
		return false;
	}

	unsigned int depthStencilIndex = attachmentIndex[nzAttachmentPoint_DepthStencil];
	if (attachmentPoint == nzAttachmentPoint_Stencil && m_impl->attachements.size() > depthStencilIndex &&
		m_impl->attachements[depthStencilIndex].isUsed)
	{
		NazaraError("Stencil target already attached by DepthStencil attachment");
		return false;
	}

	if (!texture || !texture->IsValid())
	{
		NazaraError("Invalid texture");
		return false;
	}

	if (texture->GetWidth() < m_impl->width || texture->GetHeight() < m_impl->height)
	{
		NazaraError("Texture cannot be smaller than render texture");
		return false;
	}

	unsigned int depth = (texture->GetType() == nzImageType_Cubemap) ? 6 : texture->GetDepth();
	if (z >= depth)
	{
		NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')');
		return false;
	}

	if (texture->GetRenderTexture() != nullptr)
	{
		NazaraError("Texture already used by another render texture");
		return false;
	}

	if (formatTypeToAttachment[NzPixelFormat::GetType(texture->GetFormat())] != attachmentPoint)
	{
		NazaraError("Pixel format type does not match attachment point type");
		return false;
	}
	#endif

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

	// Détachement de l'attache précédente (Si il y a)
	Detach(attachmentPoint, index);

	switch (texture->GetType())
	{
		case nzImageType_1D:
			glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_TEXTURE_1D, texture->GetOpenGLID(), 0);
			break;

		case nzImageType_1D_Array:
		case nzImageType_2D_Array:
			glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, texture->GetOpenGLID(), 0, z);
			break;

		case nzImageType_2D:
			glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, NzOpenGL::TextureTarget[texture->GetType()], texture->GetOpenGLID(), 0);
			break;

		case nzImageType_3D:
			glFramebufferTexture3D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_TEXTURE_3D, texture->GetOpenGLID(), 0, z);
			break;

		case nzImageType_Cubemap:
			glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, NzOpenGL::CubemapFace[z], texture->GetOpenGLID(), 0);
			break;
	}

	Unlock();

	unsigned int minSize = attachmentIndex[attachmentPoint]+index+1;
	if (m_impl->attachements.size() < minSize)
		m_impl->attachements.resize(minSize);

	Attachment& attachment = m_impl->attachements[minSize-1];
	attachment.isBuffer = false;
	attachment.isUsed = true;
	attachment.texture = texture;

	texture->AddResourceListener(this);
	texture->SetRenderTexture(this);

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

	return true;
}
예제 #20
0
	void attach1d(GLenum attachment, GLenum texture_target, GLuint texture_id, GLint level) { scoped_bind<framebuffer> bound(*this); glFramebufferTexture1D(target, attachment, texture_target, texture_id, level); throw_on_texture_opengl_error(); }
예제 #21
0
	void OGLTexture1D::CopyToSubTexture1D(Texture& target,
			uint32_t dst_array_index, uint32_t dst_level, uint32_t dst_x_offset, uint32_t dst_width,
			uint32_t src_array_index, uint32_t src_level, uint32_t src_x_offset, uint32_t src_width)
	{
		BOOST_ASSERT(type_ == target.Type());
		
		if ((format_ == target.Format()) && !IsCompressedFormat(format_) && (glloader_GL_VERSION_4_3() || glloader_GL_ARB_copy_image())
			&& (src_width == dst_width) && (1 == sample_count_))
		{
			OGLTexture& ogl_target = *checked_cast<OGLTexture*>(&target);
			glCopyImageSubData(
				texture_, target_type_, src_level,
				src_x_offset, 0, src_array_index,
				ogl_target.GLTexture(), ogl_target.GLType(), dst_level,
				dst_x_offset, 0, dst_array_index, src_width, 1, 1);
		}
		else
		{
			OGLRenderEngine& re = *checked_cast<OGLRenderEngine*>(&Context::Instance().RenderFactoryInstance().RenderEngineInstance());
			if ((sample_count_ > 1) && !IsCompressedFormat(format_) && (glloader_GL_ARB_texture_rg() || (4 == NumComponents(format_))))
			{
				GLuint fbo_src, fbo_dst;
				re.GetFBOForBlit(fbo_src, fbo_dst);

				GLuint old_fbo = re.BindFramebuffer();

				glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_src);
				if (array_size_ > 1)
				{
					glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture_, src_level, src_array_index);
				}
				else
				{
					if (sample_count_ <= 1)
					{
						glFramebufferTexture1D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target_type_, texture_, src_level);
					}
					else
					{
						glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER,
											GL_COLOR_ATTACHMENT0,
											GL_RENDERBUFFER, texture_);
					}
				}

				OGLTexture& ogl_target = *checked_cast<OGLTexture*>(&target);
				glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_dst);
				if (array_size_ > 1)
				{
					glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ogl_target.GLTexture(), dst_level, dst_array_index);
				}
				else
				{
					glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target_type_, ogl_target.GLTexture(), dst_level);
				}

				glBlitFramebuffer(src_x_offset, 0, src_x_offset + src_width, 1,
								dst_x_offset, 0, dst_x_offset + dst_width, 1,
								GL_COLOR_BUFFER_BIT, (src_width == dst_width) ? GL_NEAREST : GL_LINEAR);

				re.BindFramebuffer(old_fbo, true);
			}
			else
			{
				if ((src_width == dst_width) && (format_ == target.Format()))
				{
					if (IsCompressedFormat(format_))
					{
						BOOST_ASSERT(0 == (src_x_offset & 0x3));
						BOOST_ASSERT(0 == (dst_x_offset & 0x3));
						BOOST_ASSERT(0 == (src_width & 0x3));
						BOOST_ASSERT(0 == (dst_width & 0x3));

						Texture::Mapper mapper_src(*this, src_array_index, src_level, TMA_Read_Only, 0, this->Width(src_level));
						Texture::Mapper mapper_dst(target, dst_array_index, dst_level, TMA_Write_Only, 0, target.Width(dst_level));

						uint32_t const block_size = NumFormatBytes(format_) * 4;
						uint8_t const * s = mapper_src.Pointer<uint8_t>() + (src_x_offset / 4 * block_size);
						uint8_t* d = mapper_dst.Pointer<uint8_t>() + (dst_x_offset / 4 * block_size);
						std::memcpy(d, s, src_width / 4 * block_size);
					}
					else
					{
						size_t const format_size = NumFormatBytes(format_);

						Texture::Mapper mapper_src(*this, src_array_index, src_level, TMA_Read_Only, src_x_offset, src_width);
						Texture::Mapper mapper_dst(target, dst_array_index, dst_level, TMA_Write_Only, dst_x_offset, dst_width);
						uint8_t const * s = mapper_src.Pointer<uint8_t>();
						uint8_t* d = mapper_dst.Pointer<uint8_t>();

						std::memcpy(d, s, src_width * format_size);
					}
				}
				else
				{
					this->ResizeTexture1D(target, dst_array_index, dst_level, dst_x_offset, dst_width,
						src_array_index, src_level, src_x_offset, src_width, true);
				}
			}
		}
	}
예제 #22
0
파일: GLBuffers.cpp 프로젝트: Apicio/rpcs3
void GLfbo::Texture1D(u32 attachment, u32 texture, int level)
{
	glFramebufferTexture1D(m_type, attachment, GL_TEXTURE_1D, texture, level);
}
예제 #23
0
파일: shadernode.cpp 프로젝트: bigfug/Fugio
void ShaderNode::bindOutputBuffers( QVector<GLenum> &Buffers, QList< QSharedPointer<InterfacePin> > &OutPinLst, int &W, int &H, int &D )
{
	for( QList< QSharedPointer<InterfacePin> >::iterator it = OutPinLst.begin() ; it != OutPinLst.end() ; it++ )
	{
		QSharedPointer<InterfacePin>	OutPin = *it;

		if( !OutPin->isConnected() )
		{
			continue;
		}

		QSharedPointer<InterfacePin>			DstPin = OutPin->connectedPin();

		if( DstPin == 0 )
		{
			continue;
		}

		QSharedPointer<InterfacePinControl>		DstControl = DstPin->control();

		if( DstControl == 0 )
		{
			continue;
		}

		InterfaceTexture		*DstTexture = qobject_cast<InterfaceTexture *>( DstControl->object() );

		if( DstTexture == 0 )
		{
			continue;
		}

		if( DstTexture->textureId() == 0 )
		{
			DstTexture->update( 0, 0 );

			if( DstTexture->textureId() == 0 )
			{
				continue;
			}
		}

		if( Buffers.empty() )
		{
			W = DstTexture->size().at( 0 );
			H = DstTexture->size().at( 1 );
			D = DstTexture->size().at( 2 );
		}

		//glBindTexture( DstTexture->target(), 0 );

		if( mFrameBufferId == 0 )
		{
			glGenFramebuffers( 1, &mFrameBufferId );

			if( mFrameBufferId == 0 )
			{
				continue;
			}
		}

		glBindFramebuffer( GL_FRAMEBUFFER, mFrameBufferId );

		switch( DstTexture->target() )
		{
			case GL_TEXTURE_1D:
				glFramebufferTexture1D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + Buffers.size(), DstTexture->target(), DstTexture->textureId(), 0 );
				break;

			case GL_TEXTURE_2D:
			case GL_TEXTURE_RECTANGLE:
				glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + Buffers.size(), DstTexture->target(), DstTexture->textureId(), 0 );
				break;

			case GL_TEXTURE_3D:
				glFramebufferTexture3D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + Buffers.size(), DstTexture->target(), DstTexture->textureId(), 0, 0 );
				break;
		}

		OPENGL_PLUGIN_DEBUG;

		Buffers.append( GL_COLOR_ATTACHMENT0 + Buffers.size() );
	}
}