当前位置: 首页>>代码示例>>C++>>正文


C++ Stamp::BindTexture方法代码示例

本文整理汇总了C++中Stamp::BindTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ Stamp::BindTexture方法的具体用法?C++ Stamp::BindTexture怎么用?C++ Stamp::BindTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stamp的用法示例。


在下文中一共展示了Stamp::BindTexture方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mirror

//--------------------------------------------------------
// Used to apply deformations to the given heightmap
void
Deform::displace_heightmap(TexData texdata, vector2 clickPos, vector2 clickOffset, vector4 SIRM, bool isCoarse, string stampName, GLuint copySrcTex)
{
	GLuint	backupTex;
	int 	currentViewport[4];
	int		dim;
	int		copyX, copyY;
	int		copyW, copyH;
	float	metre_scale;
	matrix2 stampRot;
	Stamp	*stamp;
	GLuint	shaderID;

	// Setup transforms
	SIRM.x			= 0.5f * SIRM.x;				// scale in metres
	stampRot		= rotate_tr2(SIRM.z);			// rotation

	// Stamp controls
	if (stampName.compare("") == 0)
		stamp		= GetStampMan()->GetCurrentStamp();
	else
		stamp		= GetStampMan()->GetStamp(stampName);
	shaderID		= stamp->GetShaderID();

	// Setup variables dependent on whether it is Coarse or High detail deformation
	if (isCoarse)
	{
		dim			= m_coarseDim;
		metre_scale = m_metre_to_tex;
		SIRM.x		= SIRM.x * metre_scale;
		// Scale because the coarsemap uses float textures which aren't normalized to [0, 1]
		SIRM.y		= SIRM.y * VERT_SCALE;	
		clickPos	= (clickPos * metre_scale) + vector2(0.5f) + clickOffset;
		backupTex	= m_coarseBackup;
	}
	else
	{
		dim			= m_highDim;
		metre_scale	= m_metre_to_detail_tex;
		SIRM.x		= SIRM.x * metre_scale;
		clickPos	= (clickPos * metre_scale) + clickOffset;
		backupTex	= m_highBackup;
	}

	// Calculate bounds of the render area as texel coordinates where X,Y in [0, dim-1]
	copyW 		= (int)ceil(2.9f * SIRM.x * dim) ;
	copyH 		= (int)ceil(2.9f * SIRM.x * dim);
	copyX 		= max(0, (int)(dim * clickPos.x) - copyW / 2);
	copyY 		= max(0, (int)(dim * clickPos.y) - copyH / 2);

	// Make sure it's not out of bounds
	copyW 		= copyX + copyW > dim-1 ? dim - copyX : copyW;
	copyH 		= copyY + copyH > dim-1 ? dim - copyY : copyH;

	////// PHASE 1: Copy To Backup
	//////////////////////////////
	// For HD textures, we need to copy the heightmap into a double buffer for it to read from
	// For Coarsemap, we only need to do a copy the first time as it does not share the texture
	if (!isCoarse || !m_initialised) {
		// Setup the Read framebuffer
		glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_heightmap);
		glReadBuffer(GL_COLOR_ATTACHMENT0);

		// Set up textures and attachments for the copy
		if (copySrcTex != 0){
			// If we're writing to an HD for the first time, we need to fill it with the Zero tex
			glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
					copySrcTex, 0);
			glBindTexture(GL_TEXTURE_2D, texdata.heightmap);
			// Use the Zero texture to read the current state from
			backupTex = copySrcTex;
		} 
		else {
			// Otherwise copy the current state of the render region into the backup
			glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
					texdata.heightmap, 0);
			glBindTexture(GL_TEXTURE_2D, backupTex);
		}

		// Perform copy
		if (isCoarse || copySrcTex != 0)
			glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, dim, dim);
		else
			//glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, dim, dim);
			glCopyTexSubImage2D(GL_TEXTURE_2D, 0, copyX, copyY, copyX, copyY, copyW, copyH);

		// Unbind FBO, texture and regenerate mipmap
		glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);	
		glGenerateMipmap(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, 0);

		// set that has been initialised
		m_initialised |= isCoarse;
	}

	////// PHASE 2: Render to Texture
	/////////////////////////////////
	// First we set up the Framebuffer and it's viewport and bind our target attachment
//.........这里部分代码省略.........
开发者ID:JuzzWuzz,项目名称:defter,代码行数:101,代码来源:deform.cpp


注:本文中的Stamp::BindTexture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。