]> git.tdb.fi Git - libs/gl.git/commitdiff
Rework exceptions
authorMikko Rasa <tdb@tdb.fi>
Tue, 6 Sep 2011 20:46:52 +0000 (23:46 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 6 Sep 2011 20:48:53 +0000 (23:48 +0300)
30 files changed:
source/batch.cpp
source/bloom.cpp
source/buffer.cpp
source/error.h [new file with mode: 0644]
source/except.h [deleted file]
source/extension.cpp
source/extension.h
source/font.cpp
source/framebuffer.cpp
source/immediate.cpp
source/light.cpp
source/matrix.cpp
source/object.cpp
source/pixelformat.cpp
source/primitivebuilder.cpp
source/program.cpp
source/renderable.cpp
source/renderer.cpp
source/renderpass.cpp
source/shader.cpp
source/texture.cpp
source/texture2d.cpp
source/texture2d.h
source/texture3d.cpp
source/texture3d.h
source/texturing.cpp
source/texunit.cpp
source/vertexarray.cpp
source/vertexformat.cpp
source/windingtest.cpp

index 1260c6abe5e995203af5ff3a70d10ce9fc1d8d63..b4b88176559a744ffa602fed13951ebd8a65b669 100644 (file)
@@ -1,6 +1,7 @@
 #include "batch.h"
 #include "bindable.h"
 #include "buffer.h"
+#include "error.h"
 #include "extension.h"
 #include "nv_primitive_restart.h"
 #include "vertexarray.h"
@@ -33,11 +34,11 @@ Batch::~Batch()
 void Batch::set_data_type(DataType t)
 {
        if(t!=UNSIGNED_BYTE && t!=UNSIGNED_SHORT && t!=UNSIGNED_INT)
-               throw InvalidParameterValue("Batch data type must be an unsigned integer");
+               throw invalid_argument("Batch::set_data_type");
        if(t==UNSIGNED_BYTE && max_index>0xFE)
-               throw InvalidState("UNSIGNED_BYTE can't hold all indices in Batch");
+               throw invalid_operation("Batch::set_data_type");
        else if(t==UNSIGNED_SHORT && max_index>0xFFFE)
-               throw InvalidState("UNSIGNED_SHORT can't hold all indices in Batch");
+               throw invalid_operation("Batch::set_data_type");
 
        if(data_type==UNSIGNED_BYTE && t==UNSIGNED_SHORT)
                expand_data<unsigned char, unsigned short>();
@@ -60,7 +61,7 @@ void Batch::set_data_type(DataType t)
 void Batch::use_index_buffer(Buffer *buf, Batch *prev)
 {
        if(buf && prev && prev->ibuf!=buf)
-               throw InvalidParameterValue("Previous batch is not in the same buffer");
+               throw invalid_argument("Batch::use_index_buffer");
 
        if(!buf)
        {
@@ -153,11 +154,11 @@ void Batch::append(const vector<unsigned> &ind)
 void Batch::append(const Batch &other)
 {
        if(other.prim_type!=prim_type)
-               throw InvalidParameterValue("Can't concatenate batches with different primitive types");
+               throw invalid_argument("Batch::append");
        if(prim_type==LINE_STRIP || prim_type==LINE_LOOP)
-               throw InvalidState("Can't concatenate line strips or loops");
+               throw incompatible_data("Batch::append");
        else if(prim_type==POLYGON)
-               throw InvalidState("Can't concatenate polygons");
+               throw incompatible_data("Batch::append");
        else if(prim_type==TRIANGLE_FAN)
                static RequireExtension _ext("GL_NV_primitive_restart");
 
index f1b570bfb7205e395f139d4a90941192a3e4d2e6..76460b993885cb7f71162d22fe32b306ad650495 100644 (file)
@@ -95,7 +95,7 @@ Bloom::Bloom(unsigned w, unsigned h):
 void Bloom::set_radius(float r)
 {
        if(r<=0.0f)
-               throw InvalidParameterValue("Radius must be positive");
+               throw out_of_range("Bloom::set_radius");
 
        int size = min(static_cast<int>(r*3.0f), 9);
        blur_shdata_common.uniform("size", size);
@@ -113,7 +113,7 @@ void Bloom::set_radius(float r)
 void Bloom::set_strength(float s)
 {
        if(s<0.0f || s>1.0f)
-               throw InvalidParameterValue("Strength must be in the range [0.0, 1.0]");
+               throw out_of_range("Bloom::set_strength");
        combine_shdata.uniform("strength", s);
 }
 
index 395057cd90ff4bf61e95a7be7c833fefaa20515f..fbb1e159ee564df8b2d7816e459adda6312cfc20 100644 (file)
@@ -1,7 +1,10 @@
+#include <stdexcept>
 #include "arb_vertex_buffer_object.h"
 #include "extension.h"
 #include "buffer.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GL {
 
@@ -70,7 +73,7 @@ const Buffer *&Buffer::binding(BufferType type)
        case ELEMENT_ARRAY_BUFFER: return bound[1];
        case PIXEL_PACK_BUFFER:    return bound[2];
        case PIXEL_UNPACK_BUFFER:  return bound[3];
-       default: throw InvalidParameterValue("Invalid buffer type");
+       default: throw invalid_argument("Buffer::binding");
        }
 }
 
diff --git a/source/error.h b/source/error.h
new file mode 100644 (file)
index 0000000..bb71450
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef MSP_GL_ERROR_H_
+#define MSP_GL_ERROR_H_
+
+#include <stdexcept>
+
+namespace Msp {
+namespace GL {
+
+class unsupported_extension: public std::runtime_error
+{
+public:
+       unsupported_extension(const std::string &w): std::runtime_error(w) { }
+       virtual ~unsupported_extension() throw() { }
+};
+
+class invalid_operation: public std::logic_error
+{
+public:
+       invalid_operation(const std::string &w): std::logic_error(w) { }
+       virtual ~invalid_operation() throw() { }
+};
+
+class stack_underflow: public std::logic_error
+{
+public:
+       stack_underflow(const std::string &w): std::logic_error(w) { }
+       virtual ~stack_underflow() throw() { }
+};
+
+class incompatible_data: public std::logic_error
+{
+public:
+       incompatible_data(const std::string &w): std::logic_error(w) { }
+       virtual ~incompatible_data() throw() { }
+};
+
+class compile_error: public std::runtime_error
+{
+public:
+       compile_error(const std::string &w): std::runtime_error(w) { }
+       virtual ~compile_error() throw() { }
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif
diff --git a/source/except.h b/source/except.h
deleted file mode 100644 (file)
index 74467e4..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef MSP_GL_EXCEPT_H_
-#define MSP_GL_EXCEPT_H_
-
-#include <msp/core/except.h>
-
-namespace Msp {
-namespace GL {
-
-class IncompatibleData: public Exception
-{
-public:
-       IncompatibleData(const std::string &w_): Exception(w_) { }
-       ~IncompatibleData() throw() { }
-};
-
-class UnsupportedExtension: public Exception
-{
-public:
-       UnsupportedExtension(const std::string &w_): Exception(w_+" is not supported") { }
-       ~UnsupportedExtension() throw() { }
-};
-
-class CompileError: public Exception
-{
-public:
-       CompileError(const std::string &w_): Exception(w_) { }
-       ~CompileError() throw() { }
-};
-
-} // namespace GL
-} // namespace Msp
-
-#endif
index e47bbe197c5e7d924e3e7da49799beba76a26867..ef05e39bfca79705841ecf4a96ce682a8942a322 100644 (file)
@@ -9,10 +9,10 @@
 #include "arb_vertex_buffer_object.h"
 #include "arb_vertex_program.h"
 #include "arb_vertex_shader.h"
+#include "error.h"
 #include "ext_framebuffer_blit.h"
 #include "ext_framebuffer_multisample.h"
 #include "ext_framebuffer_object.h"
-#include "except.h"
 #include "extension.h"
 #include "gl.h"
 #include "nv_primitive_restart.h"
@@ -65,7 +65,7 @@ bool is_supported(const string &ext)
 void require_extension(const string &ext)
 {
        if(!is_supported(ext))
-               throw UnsupportedExtension(ext);
+               throw unsupported_extension(ext);
 }
 
 const Version &get_gl_version()
@@ -101,7 +101,7 @@ bool is_version_at_least(unsigned a, unsigned b)
 void require_version(unsigned a, unsigned b)
 {
        if(!is_version_at_least(a, b))
-               throw UnsupportedExtension(format("OpenGL %d.%d", a, b));
+               throw unsupported_extension(format("OpenGL %d.%d", a, b));
 }
 
 ExtFunc *get_proc_address(const string &name)
index 69308241d96e3bd16867ff9d0f2c68d2defcaa12..4072869cc25662d8c76fe2d4ab94c5700515f2a3 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef MSP_GL_EXTENSION_H_
 #define MSP_GL_EXTENSION_H_
 
-#include <msp/core/except.h>
+#include <string>
 
 namespace Msp {
 namespace GL {
index 88780331fd10b8144dd6f9cbbce562df4c191634..33c1584b53ab4ed5712b9ee876b101ecc8d581c4 100644 (file)
@@ -26,7 +26,7 @@ void Font::set_texture(const Texture2D &t)
 const Texture2D &Font::get_texture() const
 {
        if(!texture)
-               throw InvalidState("No texture");
+               throw logic_error("No texture");
        return *texture;
 }
 
index 3ac742bd209fd0e89c05d723c082524b4799c02c..6877f4808b7402c7f1660097c3860bb7fcbbe5bc 100644 (file)
@@ -1,3 +1,4 @@
+#include "error.h"
 #include "extension.h"
 #include "ext_framebuffer_blit.h"
 #include "ext_framebuffer_object.h"
@@ -16,7 +17,7 @@ Framebuffer::Framebuffer(unsigned i):
        dirty(0)
 {
        if(id)
-               throw InvalidParameterValue("System framebuffer must have id 0");
+               throw invalid_argument("System framebuffer must have id 0");
 
        int viewport[4];
        glGetIntegerv(GL_VIEWPORT, viewport);
@@ -98,7 +99,7 @@ void Framebuffer::check_size()
 void Framebuffer::attach(FramebufferAttachment attch, Renderbuffer &rbuf)
 {
        if(!id)
-               throw InvalidState("Can't attach to system framebuffer");
+               throw invalid_operation("Framebuffer::attach");
 
        unsigned i = get_attachment_index(attch);
        attachments[i].set(rbuf);
@@ -109,7 +110,7 @@ void Framebuffer::attach(FramebufferAttachment attch, Renderbuffer &rbuf)
 void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned level)
 {
        if(!id)
-               throw InvalidState("Can't attach to system framebuffer");
+               throw invalid_operation("Framebuffer::attach");
 
        unsigned i = get_attachment_index(attch);
        attachments[i].set(tex, level);
@@ -120,7 +121,7 @@ void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned l
 void Framebuffer::detach(FramebufferAttachment attch)
 {
        if(!id)
-               throw InvalidState("Can't detach from system framebuffer");
+               throw invalid_operation("Framebuffer::detach");
 
        unsigned i = get_attachment_index(attch);
        attachments[i].clear();
index 252eed335895e21f3dd5087f03a97f1cfcadac00..cbcc37b9e7d17490f355ec5ca2c2601cce27a811 100644 (file)
@@ -1,4 +1,5 @@
 #include "batch.h"
+#include "error.h"
 #include "immediate.h"
 
 namespace Msp {
@@ -14,7 +15,7 @@ Immediate::Immediate(VertexFormat f):
 void Immediate::reset()
 {
        if(in_batch)
-               throw InvalidState("Can't reset Immediate between begin() and end()");
+               throw invalid_operation("Immediate::reset");
 
        array.clear();
 }
index 39693c4091a6b1579885bf79104ef60e38ca0426..067cc3d1fee1416cce0451e37a90c6482f7cc2e9 100644 (file)
@@ -1,4 +1,4 @@
-#include "except.h"
+#include <stdexcept>
 #include "light.h"
 #include "misc.h"
 
@@ -94,7 +94,7 @@ void Light::activate(unsigned i)
        static unsigned max_lights = get_i(GL_MAX_LIGHTS);
 
        if(i>=max_lights)
-               throw InvalidParameterValue("Light unit index out of range");
+               throw out_of_range("Light::activate");
 
        if(i>=current_lights.size())
                current_lights.resize(i+1);
index f5089285d63295458698e1c392511348fc34a696..549fe8b61578ecf94958e2650519aea7579a8e00 100644 (file)
@@ -1,6 +1,6 @@
 #include <algorithm>
 #include <cmath>
-#include <msp/core/except.h>
+#include "error.h"
 #include "matrix.h"
 
 using namespace std;
@@ -149,7 +149,7 @@ Vector4 Matrix::operator*(const Vector4 &vec) const
 double Matrix::operator[](unsigned i) const
 {
        if(i>=16)
-               throw InvalidParameterValue("Matrix element index out of range");
+               throw out_of_range("Matrix::operator[]");
        return matrix[i];
 }
 
@@ -215,7 +215,7 @@ Matrix Matrix::scaling(double x, double y, double z)
 Matrix Matrix::ortho(double l, double r, double b, double t, double n, double f)
 {
        if(l==r || b==t || n==f)
-               throw InvalidParameterValue("Orthogonal projection can't have zero dimension");
+               throw invalid_argument("Matrix::ortho");
 
        Matrix result;
        result.matrix[0] = 2/(r-l);
@@ -246,7 +246,7 @@ Matrix Matrix::ortho_topleft(double w, double h)
 Matrix Matrix::frustum(double l, double r, double b, double t, double n, double f)
 {
        if(l==r || b==t || n<=0 || f<=n)
-               throw InvalidParameterValue("Invalid frustum parameters");
+               throw invalid_argument("Matrix::frustum");
 
        Matrix result;
        result.matrix[0] = 2*n/(r-l);
@@ -312,7 +312,7 @@ void MatrixStack::push()
 void MatrixStack::pop()
 {
        if(matrices.size()==1)
-               throw InvalidState("Can't pop the last matrix");
+               throw stack_underflow("MatrixStack::pop()");
 
        matrices.pop_back();
        update();
@@ -368,7 +368,7 @@ void matrix_mode(MatrixMode m)
        else if(m==PROJECTION)
                active_stack = &MatrixStack::projection();
        else
-               throw InvalidParameterValue("Texture matrices are not supported");
+               throw invalid_argument("matrix_mode");
 }
 
 void load_identity()
index 70c2aeeec8b616dbda605255f7463f87fd795add..1e94d7ccf96b741c2c0b4c1d3efec60ff86a773f 100644 (file)
@@ -1,6 +1,5 @@
 #include <msp/datafile/collection.h>
 #include <msp/strings/format.h>
-#include "except.h"
 #include "material.h"
 #include "mesh.h"
 #include "object.h"
@@ -27,7 +26,7 @@ Object::~Object()
 void Object::set_mesh(unsigned i, const Mesh *m)
 {
        if(i>meshes.size())
-               throw InvalidParameterValue("LODs must be continuous");
+               throw invalid_argument("Object::set_mesh");
 
        if(i==meshes.size())
                meshes.push_back(m);
@@ -141,7 +140,7 @@ void Object::Loader::mesh_inline()
 void Object::Loader::mesh_inline_lod(unsigned l)
 {
        if(l>obj.meshes.size())
-               throw InvalidParameterValue("LODs must be continuous");
+               throw invalid_argument("Object::Loader::mesh_inline_lod");
 
        RefPtr<Mesh> msh = new Mesh;
        load_sub(*msh);
index 4744ebbdfbad3a61c209be9085a01e15c8e4b1bc..8f742d83c38fcd012e0a46068eb96a0a350820aa 100644 (file)
@@ -1,4 +1,4 @@
-#include "except.h"
+#include <msp/strings/format.h>
 #include "pixelformat.h"
 
 using namespace std;
@@ -54,7 +54,7 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
        case Graphics::RGBA: return RGBA;
        case Graphics::BGR: return BGR;
        case Graphics::BGRA: return BGRA;
-       default: throw InvalidParameterValue("Unknown Graphics::PixelFormat");
+       default: throw invalid_argument("pixelformat_from_graphics");
        }
 }
 
index 046cc5b248c12874ab889c1c09358d9946795880..dd869908d9240df76b2f48a2308a0396613a35ad 100644 (file)
@@ -1,5 +1,8 @@
+#include "error.h"
 #include "primitivebuilder.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GL {
 
@@ -13,7 +16,7 @@ PrimitiveBuilder::PrimitiveBuilder(VertexArray &a):
 void PrimitiveBuilder::begin(PrimitiveType t)
 {
        if(in_batch)
-               throw InvalidState("begin() already called");
+               throw invalid_operation("PrimitiveBuilder::begin");
 
        type = t;
        in_batch = true;
@@ -24,7 +27,7 @@ void PrimitiveBuilder::begin(PrimitiveType t)
 void PrimitiveBuilder::end()
 {
        if(!in_batch)
-               throw InvalidState("end() called without begin()");
+               throw invalid_operation("PrimitiveBuilder::end");
 
        in_batch = false;
 
@@ -34,23 +37,23 @@ void PrimitiveBuilder::end()
 void PrimitiveBuilder::offset(unsigned o)
 {
        if(o>array.size())
-               throw InvalidParameterValue("Element offset out of range");
+               throw out_of_range("PrimitiveBuilder::offset");
        offs = o;
 }
 
 void PrimitiveBuilder::element(unsigned i)
 {
        if(!in_batch)
-               throw InvalidState("Element specification not between begin() and end()");
+               throw invalid_operation("PrimitiveBuilder::element");
        if(offs+i>=array.size())
-               throw InvalidParameterValue("Element index out of range");
+               throw out_of_range("PrimitiveBuilder::element");
        element_(offs+i);
 }
 
 PrimitiveType PrimitiveBuilder::get_type() const
 {
        if(!in_batch)
-               throw InvalidState("Not between begin() and end()");
+               throw invalid_operation("PrimitiveBuilder::get_type");
        return type;
 }
 
index 3c3a78b7c298a15bb6e55f8b9e75268fd788c4c7..6fa1495387fb3280452b099dcc38dcb1ff561b38 100644 (file)
@@ -1,7 +1,7 @@
 #include <algorithm>
 #include "arb_shader_objects.h"
 #include "arb_vertex_shader.h"
-#include "except.h"
+#include "error.h"
 #include "extension.h"
 #include "program.h"
 #include "shader.h"
@@ -214,7 +214,7 @@ void Program::link()
        int value;
        glGetObjectParameterivARB(id, GL_OBJECT_LINK_STATUS_ARB, &value);
        if(!(linked = value))
-               throw CompileError(get_info_log());
+               throw compile_error(get_info_log());
 
        glGetObjectParameterivARB(id, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &value);
        for(int i=0; i<value; ++i)
@@ -244,7 +244,7 @@ string Program::get_info_log() const
 void Program::bind() const
 {
        if(!linked)
-               throw InvalidState("Program is not linked");
+               throw invalid_operation("Program::bind");
 
        if(!set_current(this))
                return;
index 44b34b0b6225deb92dc177b6473ad0e8932e16a4..a41794c6561d8a54947c20d38990db7914f876ad 100644 (file)
@@ -1,4 +1,4 @@
-#include <msp/core/except.h>
+#include "error.h"
 #include "renderable.h"
 #include "renderer.h"
 
@@ -7,7 +7,7 @@ namespace GL {
 
 void Renderable::render(const Tag &) const
 {
-       throw Exception("This Renderable doesn't support rendering without a Renderer");
+       throw invalid_operation("Renderable::render");
 }
 
 void Renderable::render(Renderer &renderer, const Tag &tag) const
index 72043cd153f1d669b7f69011f97981d1a4793aea..03042e67c12f80ac95904ca4c66e8f4e80e6baee 100644 (file)
@@ -1,7 +1,7 @@
-#include <msp/core/except.h>
 #include "batch.h"
 #include "buffer.h"
 #include "camera.h"
+#include "error.h"
 #include "material.h"
 #include "program.h"
 #include "programdata.h"
@@ -80,7 +80,7 @@ void Renderer::set_shader(const Program *p, const ProgramData *d)
 void Renderer::add_shader_data(const ProgramData *d)
 {
        if(!state->shprog)
-               throw InvalidState("No shader program");
+               throw invalid_operation("Renderer::add_shader_data");
 
        state->shdata.push_back(d);
 }
@@ -111,7 +111,7 @@ void Renderer::push_state()
 void Renderer::pop_state()
 {
        if(state_stack.size()==1)
-               throw InvalidState("Can't pop the last state");
+               throw stack_underflow("Renderer::pop_state");
 
        state_stack.pop_back();
        state = &state_stack.back();
@@ -128,7 +128,7 @@ void Renderer::escape()
 void Renderer::draw(const Batch &batch)
 {
        if(!vertex_array)
-               throw InvalidState("Can't draw without a vertex array");
+               throw invalid_operation("Renderer::draw");
 
        apply_state();
 
index 82ca7a3972f28e1d11bd1fde2a4ffb5bf19cbd28..93538d48d64e013f948c33cee22eee989adc0c3b 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/core/refptr.h>
 #include <msp/datafile/collection.h>
 #include <msp/strings/format.h>
+#include "error.h"
 #include "material.h"
 #include "renderpass.h"
 #include "program.h"
@@ -113,7 +114,7 @@ void RenderPass::Loader::texunit_named(unsigned i, const string &n)
 void RenderPass::Loader::uniforms()
 {
        if(!obj.shprog)
-               throw InvalidState("Can't load uniforms without a shader program");
+               throw invalid_operation("RenderPass::Loader::uniforms");
        if(!obj.shdata)
                obj.shdata = new ProgramData(*obj.shprog);
        load_sub(*obj.shdata);
@@ -143,7 +144,7 @@ void RenderPass::TextureLoader::finish()
 
 void RenderPass::TextureLoader::texenv()
 {
-       throw Exception("TexEnvs can't be loaded yet");
+       throw runtime_error("TexEnvs can't be loaded yet");
        /*env = new TexEnv;
        load_sub(*env);*/
 }
index 967ac8a624dc63f92248dc7f604b99c44fe73c79..0f60edcd6195324db4201dac50feda4fa98b6489 100644 (file)
@@ -1,5 +1,5 @@
 #include "arb_shader_objects.h"
-#include "except.h"
+#include "error.h"
 #include "extension.h"
 #include "shader.h"
 
@@ -59,7 +59,7 @@ void Shader::compile()
        int value = 0;
        glGetObjectParameterivARB(id, GL_OBJECT_COMPILE_STATUS_ARB, &value);
        if(!(compiled = value))
-               throw CompileError(get_info_log());
+               throw compile_error(get_info_log());
 }
 
 string Shader::get_info_log() const
index c2ea8ff7b854c95cf6bee17e5bfd43aed772f710..d22f189bdcad4cc0a3c0e2f7edb0d55f30c5adaf 100644 (file)
@@ -1,4 +1,5 @@
-#include "except.h"
+#include <msp/strings/format.h>
+#include "error.h"
 #include "texture.h"
 #include "texunit.h"
 
@@ -40,7 +41,7 @@ void operator>>(const LexicalConverter &c, TextureWrap &tw)
        else if(c.get()=="MIRRORED_REPEAT")
                tw = MIRRORED_REPEAT;
        else
-               throw LexicalError("Invalid input in TextureWrap conversion");
+               throw lexical_error(format("conversion of '%s' to TextureWrap", c.get()));
 }
 
 
@@ -146,9 +147,6 @@ void Texture::set_compare_func(Predicate f)
 
 void Texture::bind() const
 {
-       if(!target)
-               throw InvalidState("Attempt to bind a texture without target (should never happen)");
-
        const Texture *cur = TexUnit::current().get_texture();
        if(cur!=this)
        {
index b6b5954837c2e8b2ca4d35a801bd28f199e75757..be4e1a112d08e8c02f189fbcd951dce4dfcdcf2c 100644 (file)
@@ -1,5 +1,5 @@
 #include "bindable.h"
-#include "except.h"
+#include "error.h"
 #include "texture2d.h"
 
 using namespace std;
@@ -17,9 +17,9 @@ Texture2D::Texture2D():
 void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht)
 {
        if(width>0)
-               throw InvalidState("Texture storage may only be specified once");
+               throw invalid_operation("Texture2D::storage");
        if(wd==0 || ht==0)
-               throw InvalidParameterValue("Invalid texture dimensions");
+               throw invalid_argument("Texture2D::storage");
 
        ifmt = fmt;
        width = wd;
@@ -36,7 +36,8 @@ void Texture2D::allocate(unsigned level)
 
 void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
 {
-       require_storage();
+       if(width==0 || height==0)
+               throw invalid_operation("Texture2D::image");
 
        unsigned w = width;
        unsigned h = height;
@@ -55,7 +56,9 @@ void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void
 
 void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, PixelFormat fmt, DataType type, const void *data)
 {
-       require_storage();
+       if(width==0 || height==0)
+               throw invalid_operation("Texture2D::sub_image");
+
        allocate(level);
 
        Bind _bind(this, true);
@@ -78,17 +81,11 @@ void Texture2D::image(const Graphics::Image &img)
        if(width==0)
                storage(fmt, w, h);
        else if(w!=width || h!=height)
-               throw IncompatibleData("Image does not match texture storage");
+               throw incompatible_data("Texture2D::image");
 
        image(0, fmt, UNSIGNED_BYTE, img.get_data());
 }
 
-void Texture2D::require_storage()
-{
-       if(width==0 || height==0)
-               throw InvalidState("Texture storage has not been specified");
-}
-
 void Texture2D::get_level_size(unsigned level, unsigned &w, unsigned &h)
 {
        w >>= level;
index 05fbbce2e80b6362e576077ca4fe019311576f46..5f4a7f9293e49f90781dbeaa50322cd6cc90747c 100644 (file)
@@ -68,7 +68,6 @@ public:
 
 private:
        void image(const Graphics::Image &);
-       void require_storage();
        void get_level_size(unsigned, unsigned &, unsigned &);
 };
 
index e716c901b53f408820123130dec62fc3db109eea..4aac49edfaf82f27eaf4c3eef8c7021596d5033e 100644 (file)
@@ -1,7 +1,7 @@
 #include <cmath>
 #include <msp/graphics/image.h>
 #include "bindable.h"
-#include "except.h"
+#include "error.h"
 #include "extension.h"
 #include "texture3d.h"
 #include "version_1_2.h"
@@ -24,9 +24,9 @@ Texture3D::Texture3D():
 void Texture3D::storage(PixelFormat f, unsigned w, unsigned h, unsigned d)
 {
        if(width>0)
-               throw InvalidState("Textures storage may only be specified once");
+               throw invalid_operation("Texture3D::storage");
        if(w==0 || h==0 || d==0)
-               throw InvalidParameterValue("Invalid texture dimensions");
+               throw invalid_argument("Texture3D::storage");
 
        width = w;
        height = h;
@@ -44,7 +44,8 @@ void Texture3D::allocate(unsigned level)
 
 void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
 {
-       require_storage();
+       if(width==0 || height==0 || depth==0)
+               throw invalid_operation("Texture3D::image");
 
        unsigned w = width;
        unsigned h = height;
@@ -64,7 +65,9 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
 
 void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, PixelFormat fmt, DataType type, const void *data)
 {
-       require_storage();
+       if(width==0 || height==0 || depth==0)
+               throw invalid_operation("Texture3D::image");
+
        allocate(level);
 
        Bind _bind(this, true);
@@ -83,7 +86,7 @@ void Texture3D::load_image(const string &fn, int dp)
        if(dp==-1)
        {
                if(h%w)
-                       throw IncompatibleData("Image height is not divisible by its width");
+                       throw incompatible_data("Texture3D::load_image");
                d = h/w;
                h = w;
        }
@@ -92,7 +95,7 @@ void Texture3D::load_image(const string &fn, int dp)
                for(d=h; d*d>h; d>>=2) ;
                for(; d*d<h; ++d) ;
                if(d*d!=h)
-                       throw IncompatibleData("Could not find a square root of texture height");
+                       throw incompatible_data("Texture3D::load_image");
                h = d;
        }
        else if(dp>0)
@@ -102,17 +105,11 @@ void Texture3D::load_image(const string &fn, int dp)
        if(width==0)
                storage(fmt, w, h, d);
        else if(w!=width || h!=height || d!=depth)
-               throw IncompatibleData("Image does not match texture storage");
+               throw incompatible_data("Texture3D::load_image");
 
        image(0, fmt, UNSIGNED_INT, img.get_data());
 }
 
-void Texture3D::require_storage()
-{
-       if(width==0 || height==0 || depth==0)
-               throw InvalidState("Texture storage has not been specified");
-}
-
 void Texture3D::get_level_size(unsigned level, unsigned &w, unsigned &h, unsigned &d)
 {
        w >>= level;
index a0e96f4247aa7a90507aa39f9ebb86f94deb2f40..12bd4a4b8c223f640e3f4fadcda96d54dc449e74 100644 (file)
@@ -29,7 +29,6 @@ public:
        unsigned get_height() const { return height; }
        unsigned get_depth() const { return depth; }
 private:
-       void require_storage();
        void get_level_size(unsigned, unsigned &, unsigned &, unsigned &);
 };
 
index 425c710ca4d1357d2627995b02f0fc8040f21d86..880f3f0751a40df642d4b7d713d3497c94476da2 100644 (file)
@@ -3,6 +3,8 @@
 #include "texturing.h"
 #include "texunit.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GL {
 
@@ -30,7 +32,7 @@ void Texturing::detach(unsigned attch)
 void Texturing::set_attachment(unsigned attch, const Texture *tex, const TexEnv *env)
 {
        if(attch>=TexUnit::get_n_units())
-               throw InvalidParameterValue("Invalid texture attachment");
+               throw out_of_range("Texturing::set_attachment");
 
        if(attachments.size()<=attch)
                attachments.resize(attch+1);
index dde3d406ca71fcbb5cfa034805a91a9784da6fe7..4d71e3b9492674a3a3e0f1712d6d45d526c679bb 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdexcept>
 #include "extension.h"
 #include "gl.h"
 #include "texunit.h"
@@ -48,7 +49,7 @@ unsigned TexUnit::get_n_units()
 TexUnit &TexUnit::activate(unsigned n)
 {
        if(n>=get_n_units())
-               throw InvalidParameterValue("Invalid texture unit number");
+               throw out_of_range("TexUnit::activate");
 
        if(units.size()<=n)
                units.resize(n+1);
index f3476268b8c5c30071ba70a7c14c9e349d6a9359..7716c5b2e4c68f30fcee9ada52213532dec53e29 100644 (file)
@@ -1,5 +1,6 @@
 #include "arb_vertex_program.h"
 #include "buffer.h"
+#include "error.h"
 #include "extension.h"
 #include "gl.h"
 #include "version_1_2.h"
@@ -75,7 +76,7 @@ void VertexArray::reset(const VertexFormat &f)
 void VertexArray::apply() const
 {
        if(format.empty())
-               throw InvalidState("Trying to apply a vertex array with no data");
+               throw invalid_operation("VertexArray::apply");
 
        if(vbuf)
        {
index f5e175714187a9eb5a853abc9ba84aa3728864a9..ed2b04b8dbd0784c2bf6bc67c7a10698000a8464 100644 (file)
@@ -1,7 +1,8 @@
 #include <cstring>
+#include <msp/strings/format.h>
 #include <msp/strings/lexicalcast.h>
 #include <msp/strings/utils.h>
-#include "except.h"
+#include "error.h"
 #include "vertexformat.h"
 
 using namespace std;
@@ -60,7 +61,7 @@ unsigned VertexFormat::stride() const
 int VertexFormat::offset(VertexComponent comp, unsigned index) const
 {
        if((comp<TEXCOORD1 && index>0) || (comp<ATTRIB1 && index>=8) || index>=53)
-               throw InvalidParameterValue("Vertex component index out of range");
+               throw out_of_range("VertexFormat::offset");
 
        unsigned type = (comp>>2)+index;
        unsigned size = comp&3;
@@ -109,11 +110,11 @@ VertexFormat operator,(const VertexFormat &f, VertexComponent c)
 VertexFormat operator,(const VertexFormat &f, unsigned i)
 {
        if(!f.data)
-               throw InvalidState("VertexFormat has no components");
+               throw invalid_operation("VertexFormat::operator,");
        VertexFormat r = f;
        unsigned char *c = r.data+r.data[0];
        if((*c<TEXCOORD1 && i>0) || (*c<ATTRIB1 && i>=8) || i>=53)
-               throw InvalidParameterValue("Vertex component index out of range");
+               throw out_of_range("VertexFormat::operator,");
        *c += i*4;
 
        return r;
@@ -137,7 +138,7 @@ void operator>>(const LexicalConverter &conv, VertexComponent &c)
                else if(str.size()==11 && str[9]=='_' && str[10]>='0' && str[10]<='7')
                        c = static_cast<VertexComponent>(TEXCOORD1+(str[8]-'1')+(str[10]-'0')*4);
                else
-                       throw LexicalError("Invalid texture unit in VertexComponent conversion");
+                       throw lexical_error(format("conversion of '%s' to VertexComponent", str));
        }
        else if(str.size()>=9 && !str.compare(0, 6, "ATTRIB") && str[6]>='1' && str[6]<='4' && str[7]=='_')
        {
@@ -146,14 +147,14 @@ void operator>>(const LexicalConverter &conv, VertexComponent &c)
                {
                        n = lexical_cast<unsigned>(str.substr(8));
                }
-               catch(const LexicalError &)
+               catch(const lexical_error &)
                {
-                       throw LexicalError("Invalid attribute in VertexComponent conversion");
+                       throw lexical_error(format("conversion of '%s' to VertexComponent", str));
                }
                c = static_cast<VertexComponent>(ATTRIB1+(str[6]-'1')+n*4);
        }
        else
-               throw LexicalError("Invalid input in VertexComponent conversion");
+               throw lexical_error(format("conversion of '%s' to VertexComponent", str));
 }
 
 // XXX This will go away eventually
index 401d68035af46703e8496b6eaff9e452026b8ae2..de9e0a2530562a33deb9e84a61e5d691dafa8bd8 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/strings/format.h>
 #include "windingtest.h"
 
 namespace Msp {
@@ -10,7 +11,7 @@ void operator>>(const LexicalConverter &conv, FaceWinding &winding)
        else if(conv.get()=="COUNTERCLOCKWISE")
                winding = COUNTERCLOCKWISE;
        else
-               throw InvalidParameterValue("Invalid FaceWinding");
+               throw lexical_error(format("conversion of '%s' to FaceWinding", conv.get()));
 }
 
 WindingTest::WindingTest():