]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture2d.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / texture2d.cpp
diff --git a/source/texture2d.cpp b/source/texture2d.cpp
deleted file mode 100644 (file)
index e8c18bb..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-#include <png.h>
-#include <msp/core/error.h>
-#include "texture2d.h"
-
-using namespace std;
-
-namespace Msp {
-namespace GL {
-
-Texture2D::Texture2D()
-{
-       target=GL_TEXTURE_2D;
-}
-
-/**
-Uploads an image into the texture.  Direct wrapper for glTexImage2D.
-*/
-void Texture2D::image(int level, int ifmt, sizei wd, sizei ht, int border, GLenum fmt, GLenum type, void *data)
-{
-       maybe_bind();
-
-       glTexImage2D(target, level, ifmt, wd, ht, border, fmt, type, data);
-       width_=wd;
-       height_=ht;
-}
-
-/**
-Uploads an image into the texture, with a simpler interface.
-*/
-void Texture2D::image(int level, sizei wd, sizei ht, TextureFormat tfmt, void *data)
-{
-       int ifmt;
-       int fmt;
-       int type;
-
-       switch(tfmt)
-       {
-       case LUMINANCE8:        ifmt=GL_LUMINANCE;       fmt=GL_LUMINANCE;       type=GL_UNSIGNED_BYTE; break;
-       case LUMINANCE8_ALPHA8: ifmt=GL_LUMINANCE_ALPHA; fmt=GL_LUMINANCE_ALPHA; type=GL_UNSIGNED_BYTE; break;
-       case RGB8:  ifmt=GL_RGB;  fmt=GL_RGB;  type=GL_UNSIGNED_BYTE;        break;
-       case RGBA8: ifmt=GL_RGBA; fmt=GL_RGBA; type=GL_UNSIGNED_INT_8_8_8_8_REV; break;
-       case BGR8:  ifmt=GL_RGB;  fmt=GL_BGR;  type=GL_UNSIGNED_BYTE;        break;
-       case BGRA8: ifmt=GL_RGBA; fmt=GL_BGRA; type=GL_UNSIGNED_INT_8_8_8_8_REV; break;
-       default: throw InvalidParameterValue("Invalid texture format");
-       }
-
-       image(level, ifmt, wd, ht, 0, fmt, type, data);
-}
-
-/**
-Loads an image from a file and uploads it into the texture.  Currently assumes
-the file to be a PNG image.
-*/
-void Texture2D::image(const string &fn)
-{
-       FILE *file=fopen(fn.c_str(), "r");
-       if(!file) throw Exception("Couldn't open "+fn);
-
-       char sig[8];
-       fread(sig, 8, 1, file);
-       if(png_sig_cmp((png_byte *)sig, 0, 8))
-                throw Exception("Not a PNG image");
-
-       png_struct *pngs=png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
-       png_info   *pngi=png_create_info_struct(pngs);
-
-       if(setjmp(png_jmpbuf(pngs)))
-       {
-               png_destroy_read_struct(&pngs, &pngi, 0);
-               fclose(file);
-               throw Exception("PNG error");
-       }
-       png_init_io(pngs, file);
-       png_set_sig_bytes(pngs, 8);
-
-       png_read_info(pngs, pngi);
-
-       unsigned wd=png_get_image_width(pngs, pngi);
-       unsigned ht=png_get_image_height(pngs, pngi);
-       unsigned depth=png_get_bit_depth(pngs, pngi);
-       unsigned ctype=png_get_color_type(pngs, pngi);
-
-       if(ctype==PNG_COLOR_TYPE_PALETTE || depth<8)
-       {
-               png_destroy_read_struct(&pngs, &pngi, 0);
-               fclose(file);
-               throw Exception("Invalid color type or bit depth");
-       }
-
-       if(depth==16)
-               png_set_strip_16(pngs);
-
-       TextureFormat fmt;
-       unsigned planes;
-
-       switch(ctype)
-       {
-       case PNG_COLOR_TYPE_GRAY: fmt=LUMINANCE8; planes=1; break;
-       case PNG_COLOR_TYPE_GRAY_ALPHA: fmt=LUMINANCE8_ALPHA8; planes=2; break;
-       case PNG_COLOR_TYPE_RGB: fmt=RGB8; planes=3; break;
-       case PNG_COLOR_TYPE_RGB_ALPHA: fmt=RGBA8; planes=4; break;
-       default: throw Exception("Invalid color type");
-       }
-
-       png_byte *data=new png_byte[wd*ht*planes];
-       png_byte *row_ptrs[ht];
-       for(unsigned i=0; i<ht; ++i)
-               row_ptrs[i]=data+(ht-1-i)*wd*planes;
-
-       png_read_image(pngs, row_ptrs);
-
-       image(0, wd, ht, fmt, data);
-       delete[] data;
-
-       png_destroy_read_struct(&pngs, &pngi, 0);
-       fclose(file);
-}
-
-} // namespace GL
-} // namespace Msp