// // texture.h // J // // Created by Joshua Moerman on 6/23/12. // Copyright (c) 2012 Vadovas. All rights reserved. // #ifndef J_texture_h #define J_texture_h #include "basic.h" #include #include namespace J { struct no_texture {}; template struct gl_type {}; template <> struct gl_type { static constexpr GLenum value = GL_UNSIGNED_BYTE; }; template struct rgba { typedef typename std::vector::iterator iterator; typedef typename std::vector::iterator const_iterator; typedef typename std::vector::size_type size_type; static constexpr GLenum gl_type = J::gl_type::value; static constexpr GLenum gl_format = GL_RGBA; rgba(size_type w, size_type h, T const * data = nullptr) : width_(w) , height_(h) , pixels(w*h*4){ if(data) std::copy_n(data, w*h*4, pixels.begin()); } size_type size() const { return pixels.size(); } size_type width() const { return width; } size_type height() const { return height; } struct row_proxy { row_proxy(T* data) : data(data) {} T& operator[](size_type x){ return data[x]; } T operator[](size_type x) const { return data[x]; } T* data; }; row_proxy operator[](size_type y){ return &pixels[y*width()]; } struct const_row_proxy { const_row_proxy(T const * data) : data(data) {} T operator[](size_type x) const { return data[x]; } T const * data; }; const_row_proxy operator[](size_type y) const { return &pixels[y*width()]; } T * data() { return pixels.data(); } T const * data() const { return pixels.data(); } iterator begin() { return pixels.begin(); } iterator end() { return pixels.begin(); } const_iterator begin() const { return pixels.begin(); } const_iterator end() const { return pixels.begin(); } private: size_type width_; size_type height_; std::vector pixels; }; } #endif