From a5797c9babd17673285b3b15c7572c2d8fe1595c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 17 Aug 2008 22:16:15 +0000 Subject: [PATCH] Move Image to mspgbase Do not define GL_GLEXT_PROTOTYPES in blend.cpp since glBlendEquation is to be used through the extension mechanism Update svn:ignore --- Build | 10 ---- source/blend.cpp | 1 - source/ilwrap.cpp | 114 ----------------------------------------- source/ilwrap.h | 36 ------------- source/pixelformat.cpp | 16 ++++++ source/pixelformat.h | 3 ++ source/texture2d.cpp | 11 ++-- source/texture2d.h | 5 +- source/texture3d.cpp | 6 +-- 9 files changed, 29 insertions(+), 173 deletions(-) delete mode 100644 source/ilwrap.cpp delete mode 100644 source/ilwrap.h diff --git a/Build b/Build index 829b15f5..06505b58 100644 --- a/Build +++ b/Build @@ -8,16 +8,6 @@ package "mspgl" require "mspdatafile"; require "opengl"; - feature "devil" "Include DevIL support for loading image files"; - if "with_devil" - { - require "devil"; - build_info - { - library "ILU"; - }; - }; - library "mspgl" { source "source"; diff --git a/source/blend.cpp b/source/blend.cpp index 899ccf59..841d88b8 100644 --- a/source/blend.cpp +++ b/source/blend.cpp @@ -5,7 +5,6 @@ Copyright © 2008 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#define GL_GLEXT_PROTOTYPES #include "blend.h" #include "extension.h" #include "version_1_2.h" diff --git a/source/ilwrap.cpp b/source/ilwrap.cpp deleted file mode 100644 index b9fb4998..00000000 --- a/source/ilwrap.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#ifdef WITH_DEVIL -#include -#endif -#include -#include "ilwrap.h" - -using namespace std; - -namespace Msp { -namespace GL { - -Image::Image() -{ -#ifdef WITH_DEVIL - static bool init_done=false; - - if(!init_done) - { - ilInit(); - ilEnable(IL_ORIGIN_SET); - ilOriginFunc(IL_ORIGIN_LOWER_LEFT); - init_done=true; - } - - ilGenImages(1, &id); -#else - throw Exception("DevIL support not compiled in"); -#endif -} - -Image::~Image() -{ -#ifdef WITH_DEVIL - ilDeleteImages(1, &id); -#endif -} - -void Image::load_file(const string &fn) -{ -#ifdef WITH_DEVIL - ilBindImage(id); - if(!ilLoadImage(const_cast(fn.c_str()))) - throw Exception("Error loading image "+fn); -#else - (void)fn; -#endif -} - -void Image::load_lump(const void *data, unsigned size) -{ -#ifdef WITH_DEVIL - ilBindImage(id); - if(!ilLoadL(IL_TYPE_UNKNOWN, const_cast(data), size)) - throw Exception("Error loading image from lump"); -#else - (void)data; (void)size; -#endif -} - -PixelFormat Image::get_format() const -{ -#ifdef WITH_DEVIL - switch(ilGetInteger(IL_IMAGE_FORMAT)) - { - case IL_COLOR_INDEX: return COLOR_INDEX; - case IL_LUMINANCE: return LUMINANCE; - case IL_LUMINANCE_ALPHA: return LUMINANCE_ALPHA; - case IL_RGB: return RGB; - case IL_RGBA: return RGBA; - case IL_BGR: return BGR; - case IL_BGRA: return BGRA; - default: throw InvalidParameterValue("Unknown pixel format in image"); - } -#else - return RGB; -#endif -} - -unsigned Image::get_width() const -{ -#ifdef WITH_DEVIL - return ilGetInteger(IL_IMAGE_WIDTH); -#else - return 0; -#endif -} - -unsigned Image::get_height() const -{ -#ifdef WITH_DEVIL - return ilGetInteger(IL_IMAGE_HEIGHT); -#else - return 0; -#endif -} - -const void *Image::get_data() const -{ -#ifdef WITH_DEVIL - return ilGetData(); -#else - return 0; -#endif -} - -} // namespace GL -} // namespace Msp diff --git a/source/ilwrap.h b/source/ilwrap.h deleted file mode 100644 index 331cfd32..00000000 --- a/source/ilwrap.h +++ /dev/null @@ -1,36 +0,0 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#ifndef MSP_GL_ILWRAP_H_ -#define MSP_GL_ILWRAP_H_ - -#include "pixelformat.h" - -namespace Msp { -namespace GL { - -class Image -{ -private: - unsigned id; - -public: - Image(); - ~Image(); - - void load_file(const std::string &); - void load_lump(const void *, unsigned); - PixelFormat get_format() const; - unsigned get_width() const; - unsigned get_height() const; - const void *get_data() const; -}; - -} // namespace GL -} // namespace Msp - -#endif diff --git a/source/pixelformat.cpp b/source/pixelformat.cpp index 738b796c..d968917b 100644 --- a/source/pixelformat.cpp +++ b/source/pixelformat.cpp @@ -5,6 +5,7 @@ Copyright © 2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include "except.h" #include "pixelformat.h" using namespace std; @@ -49,5 +50,20 @@ istream &operator>>(istream &in, PixelFormat &fmt) return in; } +PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf) +{ + switch(pf) + { + case Graphics::COLOR_INDEX: return COLOR_INDEX; + case Graphics::LUMINANCE: return LUMINANCE; + case Graphics::LUMINANCE_ALPHA: return LUMINANCE_ALPHA; + case Graphics::RGB: return RGB; + case Graphics::RGBA: return RGBA; + case Graphics::BGR: return BGR; + case Graphics::BGRA: return BGRA; + default: throw InvalidParameterValue("Unknown Graphics::PixelFormat"); + } +} + } // namespace GL } // namespace Msp diff --git a/source/pixelformat.h b/source/pixelformat.h index 6980ec8a..d61788a6 100644 --- a/source/pixelformat.h +++ b/source/pixelformat.h @@ -9,6 +9,7 @@ Distributed under the LGPL #define MSP_GL_PIXELFORMAT_H_ #include +#include #include "gl.h" namespace Msp { @@ -33,6 +34,8 @@ enum PixelFormat std::istream &operator>>(std::istream &, PixelFormat &); +PixelFormat pixelformat_from_graphics(Graphics::PixelFormat); + } // namespace GL } // namespace Msp diff --git a/source/texture2d.cpp b/source/texture2d.cpp index baee22ee..b8f2f26b 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -6,7 +6,6 @@ Distributed under the LGPL */ #include "except.h" -#include "ilwrap.h" #include "texture2d.h" using namespace std; @@ -57,17 +56,17 @@ void Texture2D::sub_image(int level, int x, int y, sizei wd, sizei ht, PixelForm void Texture2D::load_image(const string &fn) { - Image img; + Graphics::Image img; img.load_file(fn); image(img); } -void Texture2D::image(const Image &img) +void Texture2D::image(const Graphics::Image &img) { unsigned w=img.get_width(); unsigned h=img.get_height(); - PixelFormat fmt=img.get_format(); + PixelFormat fmt=pixelformat_from_graphics(img.get_format()); if(width==0) storage(fmt, w, h, 0); else if(w!=width || h!=height) @@ -87,8 +86,8 @@ Texture2D::Loader::Loader(Texture2D &t): void Texture2D::Loader::image_data(const string &data) { - Image img; - img.load_lump(data.data(), data.size()); + Graphics::Image img; + img.load_memory(data.data(), data.size()); static_cast(tex).image(img); } diff --git a/source/texture2d.h b/source/texture2d.h index 13073a2d..f1b76783 100644 --- a/source/texture2d.h +++ b/source/texture2d.h @@ -10,14 +10,13 @@ Distributed under the LGPL #include #include +#include #include "pixelformat.h" #include "texture.h" namespace Msp { namespace GL { -class Image; - /** Two-dimensional texture class. This is the most common type of texture. */ @@ -72,7 +71,7 @@ public: sizei get_height() const { return height; } private: - void image(const Image &); + void image(const Graphics::Image &); }; } // namespace GL diff --git a/source/texture3d.cpp b/source/texture3d.cpp index a2d371e7..2fc4f997 100644 --- a/source/texture3d.cpp +++ b/source/texture3d.cpp @@ -6,9 +6,9 @@ Distributed under the LGPL */ #include +#include #include "except.h" #include "extension.h" -#include "ilwrap.h" #include "texture3d.h" #include "version_1_2.h" @@ -52,7 +52,7 @@ void Texture3D::image(int level, PixelFormat fmt, DataType type, const void *dat void Texture3D::load_image(const string &fn, int dp) { - Image img; + Graphics::Image img; img.load_file(fn); unsigned w=img.get_width(); @@ -77,7 +77,7 @@ void Texture3D::load_image(const string &fn, int dp) else if(dp>0) d=dp; - PixelFormat fmt=img.get_format(); + PixelFormat fmt=pixelformat_from_graphics(img.get_format()); if(width==0) storage(fmt, w, h, d, 0); else if(w!=width || h!=height || d!=depth) -- 2.43.0