From c34da2dbd034cfe591e2020ef0b50265d0571fc5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 5 Dec 2017 13:51:35 +0200 Subject: [PATCH] Check for maximum number of samples This makes it more apparent what the error is if a too large sample count is requested. Otherwise it would result in an "incomplete attachment" error from the framebuffer object. --- source/renderbuffer.cpp | 12 ++++++++++++ source/renderbuffer.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/source/renderbuffer.cpp b/source/renderbuffer.cpp index f146a915..5bea07fc 100644 --- a/source/renderbuffer.cpp +++ b/source/renderbuffer.cpp @@ -1,8 +1,11 @@ #include #include #include +#include "misc.h" #include "renderbuffer.h" +using namespace std; + namespace Msp { namespace GL { @@ -44,12 +47,21 @@ void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht) } } +unsigned Renderbuffer::get_max_samples() +{ + static unsigned max_samples = (EXT_framebuffer_multisample ? get_i(GL_MAX_SAMPLES) : 0); + return max_samples; +} + void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsigned wd, unsigned ht) { if(!samples) return storage(fmt, wd, ht); static Require _req(EXT_framebuffer_multisample); + if(samples>get_max_samples()) + throw out_of_range("Renderbuffer::storage_multisample"); + fmt = normalize_format(fmt); require_pixelformat(fmt); diff --git a/source/renderbuffer.h b/source/renderbuffer.h index 0ccf4967..751374bd 100644 --- a/source/renderbuffer.h +++ b/source/renderbuffer.h @@ -38,6 +38,10 @@ public: /** Allocates storage for the renderbuffer. */ void storage(PixelFormat fmt, unsigned wd, unsigned ht); + /** Returns the maximum supported sample count for multisampling. If + multisampling is not supported, returns 0. */ + static unsigned get_max_samples(); + /** Allocates multisample storage for the renderbuffer. All attachments in a framebuffer must have the same number of samples. To transfer the contents to a texture for furter processing, use the framebuffer blit -- 2.43.0