OpenGL MSAA多采样中的蒙版(stencil)使用

在OpenGL中进行MSAA多采样时,需要进行如下设置FBO

glGenFramebuffers(1, &mfbo);
		glBindFramebuffer(GL_FRAMEBUFFER, mfbo);
		//create color render buffer
		glGenRenderbuffers(1, &colorBuffer);
		glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
		glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4 /* 4 samples */, GL_RGBA8, width, height);
		glBindRenderbuffer(GL_RENDERBUFFER, 0);
		glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer);
		// multi sampled depth buffer
		glGenRenderbuffers(1, &depthBuffer);
		glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
		glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4 /* 4 samples */, GL_RGBA8, width, height);
		glBindRenderbuffer(GL_RENDERBUFFER, 0);
		glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);


		GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER);

		if (result == GL_FRAMEBUFFER_COMPLETE) {
			isMultiFBODone = true;
		}
		else {
			isMultiFBODone = false;
		}

		glBindFramebuffer(GL_FRAMEBUFFER, 0);

如果程序中还需要使用蒙版缓冲(stencil buffer),则需要将此FBO设置为如下格式:

glGenFramebuffers(1, &mfbo);
		glBindFramebuffer(GL_FRAMEBUFFER, mfbo);
		//create color render buffer
		glGenRenderbuffers(1, &colorBuffer);
		glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
		glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4 /* 4 samples */, GL_RGBA8, width, height);
		glBindRenderbuffer(GL_RENDERBUFFER, 0);
		glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer);
		// multi sampled depth buffer
		glGenRenderbuffers(1, &depthBuffer);
		glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
		glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4 /* 4 samples */, GL_DEPTH24_STENCIL8, width, height);
		glBindRenderbuffer(GL_RENDERBUFFER, 0);
		glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);


		GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER);

		if (result == GL_FRAMEBUFFER_COMPLETE) {
			isMultiFBODone = true;
		}
		else {
			isMultiFBODone = false;
		}

		glBindFramebuffer(GL_FRAMEBUFFER, 0);

然后在根据需要写关于蒙版的代码即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值