#pragma once
#include "../../stdafx.h"
#include "../glLibLocals.h"
#include "../glLibError.h"
#include "glLibTexture.h"

namespace glLib { namespace Texture {

class texture_3D : public glLibInternal_texture {
	//Update reference(...) when changing attributes
	public:
		unsigned long x, width;
		unsigned long y, height;
		unsigned long z, depth;
		unsigned long size[3];
		glLibFlagTextureEdge edge_x, edge_y, edge_z;
		unsigned long num_texels;
	private:
		SDL_Surface* surf1;
		GLint data_type;

	public:
		//Constructors
		#if 1
		texture_3D(void);
		#endif
		~texture_3D(void);
		texture_3D& reference(const texture_3D* ref_tex) {
			glLibInternal_reference_base_data(ref_tex);

			x = ref_tex->x;
			y = ref_tex->y;
			z = ref_tex->z;
			width  = ref_tex->width;
			height = ref_tex->height;
			depth  = ref_tex->depth;
			for (char i=0;i<3;++i) size[i] = ref_tex->size[i];
			edge_x = ref_tex->edge_x;
			edge_y = ref_tex->edge_y;
			edge_z = ref_tex->edge_z;
			num_texels = ref_tex->num_texels;
			//we won't update the surface's reference count, because we keep track of it with our own counter
			surf1 = ref_tex->surf1;
			data_type = ref_tex->data_type;

			return *this;
		}

		void fastest(void) {
			set_filtering(GLLIB_FILTER_NEAREST,GLLIB_FILTER_NEAREST);
		}
		void nicest(void) {
			set_filtering(GLLIB_FILTER_BILINEAR_MIPMAP_BILINEAR,GLLIB_FILTER_BILINEAR);
		}

		void set_edge(int value) {
			glBindTexture(GL_TEXTURE_3D,texture_id);
			glTexParameteri(texture_type,GL_TEXTURE_WRAP_S,value);
			glTexParameteri(texture_type,GL_TEXTURE_WRAP_T,value);
			glTexParameteri(texture_type,GL_TEXTURE_WRAP_R,value);
		}
		void set_edge(const int* value) {
			glBindTexture(GL_TEXTURE_3D,texture_id);
			glTexParameteri(texture_type,GL_TEXTURE_WRAP_S,value[0]);
			glTexParameteri(texture_type,GL_TEXTURE_WRAP_T,value[1]);
			glTexParameteri(texture_type,GL_TEXTURE_WRAP_R,value[2]);
		}

	private:
		void glLibInternal_make_init(void) {
			texture_type = GLLIB_TEXTURE_3D;
			enum_texture_type = GL_TEXTURE_3D;
			surf1 = NULL;
		}
};

};};