Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <type_traits>
- #include "Mipmapable.h"
- template <typename T>
- struct isMipmapable : std::conditional<std::is_base_of<Mipmapable<T>,T>::value,
- std::true_type, std::false_type>::type {};
- template <typename T, typename = void> class MipMap;
- template <typename T>
- class MipMap<T, typename std::enable_if<isMipmapable<T>::value, void>::type>
- {
- public:
- MipMap::MipMap(T* topMap, const int levels) {
- if (levels < 1)
- THROW("There must be at least 1 mipmap level.");
- mipMapLevels = levels;
- mipMaps = (T**) malloc(sizeof(T*) * mipMapLevels);
- mipMaps[0] = topMap;
- for (int i = 1; i < mipMapLevels; i++) {
- mipMaps[i] = NULL;
- }
- }
- MipMap::~MipMap(void) {
- for (int i = 1; i < mipMapLevels; i++) {
- delete mipMaps[i];
- }
- delete mipMaps;
- }
- void assertMipMaps() {
- for (int i = 1; i < mipMapLevels; i++) {
- if (mipMaps[i] == NULL) {
- mipMaps[i] = mipMaps[i - 1]->makeMipMap();
- }
- }
- }
- int getMipMapCount() {
- return mipMapLevels;
- }
- void setMipMap(T* mipMap, int level) {
- if (level < 0 || level >= mipMapLevels)
- THROW("Level must be between 0 and " << (mipMapLevels - 1) << " for this mipmap.");
- if (mipMaps[level] != NULL)
- delete mipMaps[level];
- mipMaps[level] = mipMap;
- }
- private:
- T** mipMaps;
- int mipMapLevels;
- };
Advertisement
Add Comment
Please, Sign In to add comment