예제 #1
0
//! Attach a texture (stencilTexID) to the stencil buffer attachment point.
int
FrameBuffer::attachStencilTexture(GLuint stencilTexID)
{
	bindBuffer();
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, 
							  GL_TEXTURE_2D, stencilTexID, 0);
	m_stencilID = stencilTexID;
	m_includedBuffers |= GL_STENCIL_BUFFER_BIT;
	unbindBuffer();
	return 1;
}
예제 #2
0
//! Attach a texture (depthTexID) to the depth buffer attachment point.
int
FrameBuffer::attachDepthTexture(GLuint depthTexID)
{
	bindBuffer();
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, 
							  GL_TEXTURE_2D, depthTexID, 0);
	m_depthID = depthTexID;
	m_includedBuffers |= GL_DEPTH_BUFFER_BIT;
	unbindBuffer();
	return 1;
}
void QSoundSourcePrivate::release()
{
    if (m_alSource) {
#ifdef DEBUG_AUDIOENGINE
    qDebug() << "QSoundSourcePrivate::release";
#endif
        stop();
        unbindBuffer();
        alDeleteSources(1, &m_alSource);
        QAudioEnginePrivate::checkNoError("delete source");
        m_alSource = 0;
    }
}
예제 #4
0
/*!
	Attach a texture (colorTexID) to one of the color buffer attachment points 
	This function is not completely general, as it does not allow specification
	of which MIPmap level to draw to (it uses the base, level 0).
 */
int
FrameBuffer::attachColorTexture(GLuint colorTexID, int colorBuffer)
{
	// If the colorBuffer value is valid, then bind the texture to the color buffer.
	if (colorBuffer < m_maxColorBuffers)
	{
		bindBuffer();
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+colorBuffer, 
								  GL_TEXTURE_2D, colorTexID, 0);
		m_includedBuffers |= GL_COLOR_BUFFER_BIT;
		unbindBuffer();
		if (m_colorIDs[colorBuffer]==0 && colorTexID>0 ) m_numColorAttachments++;
		if (m_colorIDs[colorBuffer]!=0 && colorTexID==0) m_numColorAttachments--;
	}
	else
		return 0;
	m_colorIDs[colorBuffer] = colorTexID;
	return 1;
}
예제 #5
0
//! Attach a renderbuffer (colorBufID) to one of the color buffer attachment points.
int
FrameBuffer::attachColorBuffer(GLuint colorBufID, int colorBuffer)
{
	// If the colorBuffer value is valid, then bind the texture to the color buffer.
	if (colorBuffer < m_maxColorBuffers)
	{
		bindBuffer();
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorBufID);
		glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, 
		                         m_width, m_height);
		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+colorBuffer, 
									 GL_RENDERBUFFER_EXT, colorBufID);
		m_includedBuffers |= GL_COLOR_BUFFER_BIT;
		if (m_colorIDs[colorBuffer]==0 && colorBufID>0 ) m_numColorAttachments++;
		if (m_colorIDs[colorBuffer]!=0 && colorBufID==0) m_numColorAttachments--;
		unbindBuffer();
	}
	else
		return 0;
	m_colorIDs[colorBuffer] = colorBufID;
	return 1;
}
예제 #6
0
FrameBuffer::FrameBuffer(int test) :
	m_width(512), m_height(512), m_depth(-1), m_automaticMipmapsEnabled(0)
{
	glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorBuffers);
	m_colorIDs = new GLuint[m_maxColorBuffers]; m_colorType = new GLenum[m_maxColorBuffers];
	m_depthID = m_stencilID = m_prevFrameBuf = m_includedBuffers = 0;
	for (int i=0; i<m_maxColorBuffers; i++)
	{
		m_colorIDs[i] = 0;
		m_colorType[i] = GL_TEXTURE_2D_ARRAY_EXT;
	}
	m_depthType = m_stencilType = GL_TEXTURE_2D_ARRAY_EXT;
	sprintf(m_FBOName, "Test CubeMap Framebuffer");
	
	m_numColorAttachments = 1;
	m_includedBuffers = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
	glGenFramebuffersEXT(1, &m_ID);
	
	glGenTextures(1, m_colorIDs);
	glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, m_colorIDs[0]);
	glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexImage3D(GL_TEXTURE_2D_ARRAY_EXT, 0, GL_LUMINANCE, m_width, m_height, 6, 0, GL_RGBA, GL_FLOAT, NULL);
	
	glGenTextures(1, &m_depthID);
	glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, m_depthID);
	glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);	
	glTexImage3D(GL_TEXTURE_2D_ARRAY_EXT, 0, GL_DEPTH_COMPONENT, m_width, m_height, 6, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
	
	glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, 0);
	
	bindBuffer();
	glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, m_colorIDs[0], 0);
	glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, m_depthID, 0);
	unbindBuffer();
	
}
예제 #7
0
FrameBuffer::FrameBuffer(GLenum type, int w, int h, int d, 
						 GLuint colorBufType, int numColorBufs, int hasZbuf, 
						 bool enableAutomaticMipmaps, const char *name) :
	m_width(w), m_height(h), m_depth(d), 
	m_automaticMipmapsEnabled(enableAutomaticMipmaps?1:0)
{
	if (type == GL_TEXTURE_1D || type == GL_TEXTURE_3D)
		printf("Warning!  FrameBuffer constructor called with untested texture type!\n");
	
	glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorBuffers);
	m_colorIDs = new GLuint[m_maxColorBuffers];
	m_colorType = new GLenum[m_maxColorBuffers];
	m_depthID = m_stencilID = m_prevFrameBuf = m_includedBuffers = 0;
	for (int i=0; i<m_maxColorBuffers; i++)
	{
		m_colorIDs[i] = 0;
		m_colorType[i] = type;
	}
	m_depthType = m_stencilType = type;
	
	if (!name) sprintf(m_FBOName, "Framebuffer %d", m_ID);
	else strncpy(m_FBOName, name, 79);
	
	glGenFramebuffersEXT(1, &m_ID);
	

	m_numColorAttachments = numColorBufs;
	if (numColorBufs > 0)
	{
		m_includedBuffers |= GL_COLOR_BUFFER_BIT;
		glGenTextures(numColorBufs, m_colorIDs);
		
		for (int i=0; i<numColorBufs; i++)
		{
			glBindTexture(type, m_colorIDs[i]);
			glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexParameteri(type, GL_GENERATE_MIPMAP, m_automaticMipmapsEnabled > 0 ? GL_TRUE : GL_FALSE);
			if (type == GL_TEXTURE_CUBE_MAP)
			{
				glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
				glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
				glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
				glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
				glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
				glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
			}
			else if (type == GL_TEXTURE_2D_ARRAY_EXT || type == GL_TEXTURE_3D)
				glTexImage3D(type, 0, colorBufType, m_width, m_height, m_depth, 0, GL_RGBA, GL_FLOAT, NULL);
			else if (type == GL_TEXTURE_2D || type == GL_TEXTURE_1D_ARRAY_EXT)
				glTexImage2D(type, 0, colorBufType, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL);
			else if (type == GL_TEXTURE_1D)
				glTexImage1D(type, 0, colorBufType, m_width, 0, GL_RGBA, GL_FLOAT, NULL);
			if (enableAutomaticMipmaps) glGenerateMipmapEXT(type);
			bindBuffer();
			
			glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, m_colorIDs[i], 0);
			unbindBuffer();
		}
	}
	if (hasZbuf > 0)
	{
		m_includedBuffers |= GL_DEPTH_BUFFER_BIT;
		glGenTextures(1, &m_depthID);
		
		glBindTexture(type, m_depthID);
		glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(type, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
		if (type == GL_TEXTURE_CUBE_MAP)
		{
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
			glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
		}
		else if (type == GL_TEXTURE_2D_ARRAY_EXT || type == GL_TEXTURE_3D)
			glTexImage3D(type, 0, GL_DEPTH_COMPONENT, m_width, m_height, m_depth, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
		else if (type == GL_TEXTURE_2D || type == GL_TEXTURE_1D_ARRAY_EXT)
			glTexImage2D(type, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
		else if (type == GL_TEXTURE_1D)
			glTexImage1D(type, 0, GL_DEPTH_COMPONENT, m_width, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
		bindBuffer();
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, m_depthID, 0);
		unbindBuffer();
	}
	
	glBindTexture(type, 0);
}