Very small OpenGL wrapper (before moggle was there)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

86 lines
1.8 KiB

//
// 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 <vector>
#include <algorithm>
namespace J {
struct no_texture {};
template <typename T>
struct gl_type {};
template <>
struct gl_type<uint8_t> {
static constexpr GLenum value = GL_UNSIGNED_BYTE;
};
template <typename T = uint8_t>
struct rgba {
typedef typename std::vector<T>::iterator iterator;
typedef typename std::vector<T>::iterator const_iterator;
typedef typename std::vector<T>::size_type size_type;
static constexpr GLenum gl_type = J::gl_type<T>::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<T> pixels;
};
}
#endif