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


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

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


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

示例1: mirror


//.........这里部分代码省略.........
			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
	glGetIntegerv(GL_VIEWPORT, currentViewport);
	glViewport(0, 0, dim, dim);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo_heightmap);
	glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
			texdata.heightmap, 0);
	glDrawBuffer(GL_COLOR_ATTACHMENT0);

	// Bind the source texture
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, backupTex);

	//Bind the stamp texture if it uses one
	if (stamp->IsTexStamp())
	{
		glActiveTexture(GL_TEXTURE1);
		stamp->BindTexture();
	}
	
	// Bind the shader and set the uniform values
	glUseProgram(shaderID);
	glUniform2fv(glGetUniformLocation(shaderID, "clickPos"), 1, clickPos.v);
	glUniform2f (glGetUniformLocation(shaderID, "stamp_scale"), SIRM.x, SIRM.x);
	glUniformMatrix2fv(glGetUniformLocation(shaderID, "stamp_rotation"), 1, GL_FALSE, stampRot.m);
	if (stamp->IsTexStamp())
	{
		// Controls for mirroring the texture
		vector2 mirror(0.0f, -1.0f);
		if (SIRM.w != 0)
			mirror = vector2(1.0f);
		glUniform2fv(glGetUniformLocation(shaderID, "stamp_mirror"), 1, mirror.v);
	}

	glUniform1f(glGetUniformLocation(shaderID, "intensity"), SIRM.y);

	// Call a predefined function if need be
	if (stamp->initShader)
		stamp->initShader(stamp, clickPos, SIRM.x, SIRM.y);

	// Bind the Vertex Array Object containing the Render Quad and its texture coordinates
	glBindVertexArray(m_vao);

	// RENDER to (DEFORM) the heightmap
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	// Reset viewport and framebuffer as it was
	glViewport(currentViewport[0], currentViewport[1], currentViewport[2], currentViewport[3]);	
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
	
	////// PHASE 3: Regenerate Mipmap and Copy Backup
	/////////////////////////////////////////////////
	glBindTexture(GL_TEXTURE_2D, texdata.heightmap);
	glGenerateMipmap(GL_TEXTURE_2D);

	// If it's the Coarsemap, we must copy these changes into its double buffer (backup texture)
	if (isCoarse)
	{
		// Setup textures to copy heightmap changes to the other map
		glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_heightmap);
		glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
				texdata.heightmap, 0);
		glReadBuffer(GL_COLOR_ATTACHMENT0);
		glBindTexture(GL_TEXTURE_2D, m_coarseBackup);

		// Copy the changed subimage
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, copyX, copyY, copyX, copyY, copyW, copyH);
		glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);	
	}
}
开发者ID:JuzzWuzz,项目名称:defter,代码行数:101,代码来源:deform.cpp


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