Last active
October 18, 2015 13:01
-
-
Save RikkaW/7f900b55a47655ed7707 to your computer and use it in GitHub Desktop.
MSAA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
修改自 BTE Alpha 的 Renderer | |
正版默认有 MSAA 并自带一个 FBO | |
给正版用启动参数加 -nofbo -nomsaa | |
(很奇怪我的正版不会默认开 MSAA | |
*/ | |
// 初始化 FBO | |
{ | |
/* | |
N卡可以开 CSAA 用之前检查一下 GL_NV_framebuffer_multisample_coverage 扩展 | |
coverageSamples 和 colorSamples 怎么填看 http://www.nvidia.com/object/coverage-sampled-aa.html | |
*/ | |
qglGenFramebuffersEXT(1, &s_MSAAFBO.s_hBackBufferFBO); | |
qglBindFramebufferEXT(GL_FRAMEBUFFER, s_MSAAFBO.s_hBackBufferFBO); | |
qglGenRenderbuffersEXT(1, &s_MSAAFBO.s_hBackBufferCB); | |
qglBindRenderbufferEXT(GL_RENDERBUFFER, s_MSAAFBO.s_hBackBufferCB); | |
if (qglRenderbufferStorageMultisampleCoverageNV) | |
qglRenderbufferStorageMultisampleCoverageNV(GL_RENDERBUFFER, 8, 4, GL_RGBA8_EXT, g_iVideoWidth, g_iVideoHeight); | |
else | |
qglRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 4, GL_RGBA8_EXT, g_iVideoWidth, g_iVideoHeight); | |
qglFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, s_MSAAFBO.s_hBackBufferCB); | |
qglGenRenderbuffersEXT(1, &s_MSAAFBO.s_hBackBufferDB); | |
qglBindRenderbufferEXT(GL_RENDERBUFFER, s_MSAAFBO.s_hBackBufferDB); | |
if (qglRenderbufferStorageMultisampleCoverageNV) | |
qglRenderbufferStorageMultisampleCoverageNV(GL_RENDERBUFFER, 8, 4, GL_DEPTH_COMPONENT24, g_iVideoWidth, g_iVideoHeight); | |
else | |
qglRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT24, g_iVideoWidth, g_iVideoHeight); | |
qglFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, s_MSAAFBO.s_hBackBufferDB); | |
} | |
#define R_RENDERVIEW_SIG "\xD9\x05\x80\x75\xEC\x01\xD8\x1D\x8C\x70\xE8\x01\x83\xEC\x14\xDF" | |
#define R_RENDERVIEW_SIG_NEW "\x55\x8B\xEC\x83\xEC\x14\xD9\x05\x2A\x2A\x2A\x2A\xD8\x1D\x2A\x2A\x2A\x2A\xDF\xE0\xF6\xC4\x44" | |
// hook | |
{ | |
// g_dwEngineBuildnum >= 5971 use R_RENDERVIEW_SIG_NEW | |
gRefFuncs.R_RenderView = (void(*)(void))g_pMetaHookAPI->SearchPattern((void *)g_dwEngineBase, g_dwEngineSize, R_RENDERVIEW_SIG, sizeof(R_RENDERVIEW_SIG) - 1); | |
g_pMetaHookAPI->InlineHook(gRefFuncs.R_RenderView, R_RenderView, (void *&)gRefFuncs.R_RenderView); | |
} | |
void R_RenderView(void) | |
{ | |
// 先取一下现在的 FBO | |
GLint drawFBOId = 0; | |
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &drawFBOId); | |
// 将默认帧缓冲复制进 MSAA FBO | |
qglBindFramebufferEXT(GL_READ_FRAMEBUFFER, drawFBOId); | |
qglBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, s_MSAAFBO.s_hBackBufferFBO); | |
qglBlitFramebufferEXT(0, 0, g_iVideoWidth, g_iVideoHeight, 0, 0, g_iVideoWidth, g_iVideoHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); | |
gRefFuncs.R_RenderView(); | |
// 画完之后再复制回去 | |
qglBindFramebufferEXT(GL_READ_FRAMEBUFFER, s_MSAAFBO.s_hBackBufferFBO); | |
qglBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, drawFBOId); | |
qglBlitFramebufferEXT(0, 0, g_iVideoWidth, g_iVideoHeight, 0, 0, g_iVideoWidth, g_iVideoHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); | |
// 最后还原 read FBO | |
qglBindFramebufferEXT(GL_READ_FRAMEBUFFER, drawFBOId); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment