]> git.tdb.fi Git - libs/gl.git/commitdiff
Check the relevant extensions when using pixel formats
authorMikko Rasa <tdb@tdb.fi>
Mon, 27 Aug 2012 21:05:08 +0000 (00:05 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 27 Aug 2012 21:05:08 +0000 (00:05 +0300)
source/arb_texture_float.cpp [new file with mode: 0644]
source/arb_texture_float.h [new file with mode: 0644]
source/ext_bgra.cpp [new file with mode: 0644]
source/ext_bgra.h [new file with mode: 0644]
source/pixelformat.cpp
source/pixelformat.h
source/renderbuffer.cpp
source/texture2d.cpp
source/texture3d.cpp
source/texturecube.cpp

diff --git a/source/arb_texture_float.cpp b/source/arb_texture_float.cpp
new file mode 100644 (file)
index 0000000..9f76b3f
--- /dev/null
@@ -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 (file)
index 0000000..9eef614
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef MSP_GL_ARB_TEXTURE_FLOAT_
+#define MSP_GL_ARB_TEXTURE_FLOAT_
+
+#include "extension.h"
+#include "gl.h"
+#include <GL/glext.h>
+
+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 (file)
index 0000000..d104717
--- /dev/null
@@ -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 (file)
index 0000000..b4ac19d
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef MSP_GL_EXT_BGRA_
+#define MSP_GL_EXT_BGRA_
+
+#include "extension.h"
+#include "gl.h"
+#include <GL/glext.h>
+
+namespace Msp {
+namespace GL {
+
+extern Extension EXT_bgra;
+
+} // namespace GL
+} // namespace Msp
+
+#endif
index 60fdc111e427c5e6ba563bfe0b849b1f4976537f..4b3dade14e4a9eef0b1052d4764c8e0c4c2b8a51 100644 (file)
@@ -1,4 +1,6 @@
 #include <msp/strings/format.h>
+#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
index 145e2a3861d835517eb5493d755d1a8904cf2b1f..55115cf77e7bbde4a2ac3af6f92d42ae7fcd9edb 100644 (file)
@@ -44,6 +44,8 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat);
 
 PixelFormat get_base_pixelformat(PixelFormat);
 
+void require_pixelformat(PixelFormat);
+
 } // namespace GL
 } // namespace Msp
 
index c920633e0f2e0e84a009cab91477a1b0197a93c8..8f0b582a1ba7b6cf0249dd27ee95a252c368d97f 100644 (file)
@@ -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;
index 8c8ad3784e4a0a32faad55b49a25dca54fd9c2fb..dfd93f57c42e811a9c15c199083c50bd49d5497b 100644 (file)
@@ -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;
index 0ad65f8887437da0bf1283c93ed00b7628efdc36..95b96903254d222507e1aed834c07fa13672b109 100644 (file)
@@ -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;
index bbe6a6b679fe259915e6710036ed75336634816e..a5874a6a66bbe9c64cbbec58e7e1477761c5e8e7 100644 (file)
@@ -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;