Use RGBA8 frame buffer format when RGB10A2 fails

This commit is contained in:
yvt 2013-08-26 01:59:10 +09:00
parent ef2b588141
commit ae3d10d3f9
4 changed files with 46 additions and 14 deletions

View File

@ -27,6 +27,7 @@ namespace spades {
SPLog("Initializing framebuffer manager");
useMultisample = (int)r_multisamples > 0;
useHighPrec = true;
if(useMultisample){
SPLog("Multi-sample Antialiasing Enabled");
@ -38,11 +39,22 @@ namespace spades {
multisampledColorRenderbuffer = dev->GenRenderbuffer();
dev->BindRenderbuffer(IGLDevice::Renderbuffer,
multisampledColorRenderbuffer);
dev->RenderbufferStorage(IGLDevice::Renderbuffer,
(int)r_multisamples,
IGLDevice::RGB10A2,
dev->ScreenWidth(),
dev->ScreenHeight());
try{
dev->RenderbufferStorage(IGLDevice::Renderbuffer,
(int)r_multisamples,
IGLDevice::RGB10A2,
dev->ScreenWidth(),
dev->ScreenHeight());
}catch(...){
SPLog("Renderbuffer creation failed: trying with RGB8");
useHighPrec = false;
dev->RenderbufferStorage(IGLDevice::Renderbuffer,
(int)r_multisamples,
IGLDevice::RGBA8,
dev->ScreenWidth(),
dev->ScreenHeight());
}
SPLog("MSAA Color Buffer Allocated");
multisampledDepthRenderbuffer = dev->GenRenderbuffer();
@ -82,14 +94,27 @@ namespace spades {
renderColorTexture = dev->GenTexture();
dev->BindTexture(IGLDevice::Texture2D,
renderColorTexture);
dev->TexImage2D(IGLDevice::Texture2D,
0,
IGLDevice::RGB10A2,
dev->ScreenWidth(),
dev->ScreenHeight(),
0,
IGLDevice::RGBA,
IGLDevice::UnsignedByte, NULL);
try{
dev->TexImage2D(IGLDevice::Texture2D,
0,
IGLDevice::RGB10A2,
dev->ScreenWidth(),
dev->ScreenHeight(),
0,
IGLDevice::RGBA,
IGLDevice::UnsignedByte, NULL);
}catch(...){
SPLog("Texture creation failed: trying with RGB8");
useHighPrec = false;
dev->TexImage2D(IGLDevice::Texture2D,
0,
IGLDevice::RGBA8,
dev->ScreenWidth(),
dev->ScreenHeight(),
0,
IGLDevice::RGBA,
IGLDevice::UnsignedByte, NULL);
}
SPLog("Color Buffer Allocated");
dev->TexParamater(IGLDevice::Texture2D,
IGLDevice::TextureMagFilter,
@ -310,7 +335,9 @@ namespace spades {
tex);
device->TexImage2D(IGLDevice::Texture2D,
0,
alpha?IGLDevice::RGBA:IGLDevice::RGB10A2,
alpha?IGLDevice::RGBA8:
(useHighPrec?IGLDevice::RGB10A2:
IGLDevice::RGB8),
w,
h,
0,

View File

@ -49,6 +49,7 @@ namespace spades {
};
bool useMultisample;
bool useHighPrec;
IGLDevice::UInteger multisampledFramebuffer;

View File

@ -142,6 +142,8 @@ namespace spades {
R16F,
RGB5,
RGB5A1,
RGB8,
RGBA8,
// Texture wrap
ClampToEdge,

View File

@ -471,6 +471,8 @@ namespace spades {
case R16F: return GL_R16F;
case RGB5: return GL_RGB5;
case RGB5A1: return GL_RGB5_A1;
case RGB8: return GL_RGB8;
case RGBA8: return GL_RGBA8;
default: SPInvalidEnum("v", v);
}
}