From: Mikko Rasa Date: Mon, 27 Aug 2012 21:05:08 +0000 (+0300) Subject: Check the relevant extensions when using pixel formats X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=41b4cb3002f3551ce1bd6fdf15994ee7bc523788 Check the relevant extensions when using pixel formats --- diff --git a/source/arb_texture_float.cpp b/source/arb_texture_float.cpp new file mode 100644 index 00000000..9f76b3fd --- /dev/null +++ b/source/arb_texture_float.cpp @@ -0,0 +1,22 @@ +#include "arb_texture_float.h" + +namespace Msp { +namespace GL { + +Extension::SupportLevel init_arb_texture_float() +{ + if(is_version_at_least(3, 0)) + { + return Extension::CORE; + } + if(is_supported("GL_ARB_texture_float")) + { + return Extension::EXTENSION; + } + return Extension::UNSUPPORTED; +} + +Extension ARB_texture_float("GL_ARB_texture_float", init_arb_texture_float); + +} // namespace GL +} // namespace Msp diff --git a/source/arb_texture_float.h b/source/arb_texture_float.h new file mode 100644 index 00000000..9eef6148 --- /dev/null +++ b/source/arb_texture_float.h @@ -0,0 +1,16 @@ +#ifndef MSP_GL_ARB_TEXTURE_FLOAT_ +#define MSP_GL_ARB_TEXTURE_FLOAT_ + +#include "extension.h" +#include "gl.h" +#include + +namespace Msp { +namespace GL { + +extern Extension ARB_texture_float; + +} // namespace GL +} // namespace Msp + +#endif diff --git a/source/ext_bgra.cpp b/source/ext_bgra.cpp new file mode 100644 index 00000000..d104717b --- /dev/null +++ b/source/ext_bgra.cpp @@ -0,0 +1,22 @@ +#include "ext_bgra.h" + +namespace Msp { +namespace GL { + +Extension::SupportLevel init_ext_bgra() +{ + if(is_version_at_least(1, 2)) + { + return Extension::CORE; + } + if(is_supported("GL_EXT_bgra")) + { + return Extension::EXTENSION; + } + return Extension::UNSUPPORTED; +} + +Extension EXT_bgra("GL_EXT_bgra", init_ext_bgra); + +} // namespace GL +} // namespace Msp diff --git a/source/ext_bgra.h b/source/ext_bgra.h new file mode 100644 index 00000000..b4ac19d9 --- /dev/null +++ b/source/ext_bgra.h @@ -0,0 +1,16 @@ +#ifndef MSP_GL_EXT_BGRA_ +#define MSP_GL_EXT_BGRA_ + +#include "extension.h" +#include "gl.h" +#include + +namespace Msp { +namespace GL { + +extern Extension EXT_bgra; + +} // namespace GL +} // namespace Msp + +#endif diff --git a/source/pixelformat.cpp b/source/pixelformat.cpp index 60fdc111..4b3dade1 100644 --- a/source/pixelformat.cpp +++ b/source/pixelformat.cpp @@ -1,4 +1,6 @@ #include +#include "arb_texture_float.h" +#include "ext_bgra.h" #include "pixelformat.h" using namespace std; @@ -73,5 +75,28 @@ PixelFormat get_base_pixelformat(PixelFormat pf) } } +void require_pixelformat(PixelFormat pf) +{ + switch(pf) + { + case RGB16F: + case RGB32F: + case RGBA16F: + case RGBA32F: + case LUMINANCE16F: + case LUMINANCE32F: + case LUMINANCE_ALPHA16F: + case LUMINANCE_ALPHA32F: + { static Require _req(ARB_texture_float); } + break; + case BGR: + case BGRA: + { static Require _req(EXT_bgra); } + break; + default: + break; + } +} + } // namespace GL } // namespace Msp diff --git a/source/pixelformat.h b/source/pixelformat.h index 145e2a38..55115cf7 100644 --- a/source/pixelformat.h +++ b/source/pixelformat.h @@ -44,6 +44,8 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat); PixelFormat get_base_pixelformat(PixelFormat); +void require_pixelformat(PixelFormat); + } // namespace GL } // namespace Msp diff --git a/source/renderbuffer.cpp b/source/renderbuffer.cpp index c920633e..8f0b582a 100644 --- a/source/renderbuffer.cpp +++ b/source/renderbuffer.cpp @@ -19,6 +19,7 @@ Renderbuffer::~Renderbuffer() void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht) { + require_pixelformat(fmt); Bind _bind(this, true); width = wd; height = ht; @@ -28,6 +29,7 @@ void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht) void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsigned wd, unsigned ht) { static Require _req(EXT_framebuffer_multisample); + require_pixelformat(fmt); Bind _bind(this, true); width = wd; diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 8c8ad378..dfd93f57 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -20,6 +20,7 @@ void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht) throw invalid_operation("Texture2D::storage"); if(wd==0 || ht==0) throw invalid_argument("Texture2D::storage"); + require_pixelformat(fmt); ifmt = fmt; width = wd; diff --git a/source/texture3d.cpp b/source/texture3d.cpp index 0ad65f88..95b96903 100644 --- a/source/texture3d.cpp +++ b/source/texture3d.cpp @@ -26,6 +26,7 @@ void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp) throw invalid_operation("Texture3D::storage"); if(wd==0 || ht==0 || dp==0) throw invalid_argument("Texture3D::storage"); + require_pixelformat(fmt); width = wd; height = ht; diff --git a/source/texturecube.cpp b/source/texturecube.cpp index bbe6a6b6..a5874a6a 100644 --- a/source/texturecube.cpp +++ b/source/texturecube.cpp @@ -32,6 +32,7 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz) throw invalid_operation("TextureCube::storage"); if(sz==0) throw invalid_argument("TextureCube::storage"); + require_pixelformat(fmt); ifmt = fmt; size = sz;