#ifndef STIM_GL_TEXTURE_H #define STIM_GL_TEXTURE_H /* includes not necessary (yet) #include #include */ #include #include #include #include "../grids/image_stack.h" #include //#include #include "./error.h" namespace stim{ /* class gl_texture Uses image_stack class in order to create a texture object. */ template class gl_texture : public virtual image_stack { private: ///Method: setTextureType /// Sets the internal texture_type, based on the data /// size. Either 3D, 2D, 1D textures. void setTextureType() { if (R[3] > 1) texture_type = GL_TEXTURE_3D; else if (R[3] == 1 && R[2] == 0) texture_type = GL_TEXTURE_1D; else if (R[3] == 1) texture_type = GL_TEXTURE_2D; } protected: std::string path; GLuint texID; //OpenGL object GLenum texture_type; //1D, 2D, 3D using image_stack::R; using image_stack::S; using image_stack::ptr; using image_stack::samples; public: ///Method: Basic Constructor /// Creates an instance of the gl_texture object. gl_texture() { } ///Method: Path Constructor ///@param string file_path path to the directory with the files. /// Creates an instance of the gl_texture object with a path to the data. gl_texture(std::string file_path) { path = file_path; image_stack::load_images(path.append("/*.jpg")); setTextureType(); } ///Method:setDims ///@param x size of the voxel in x direction ///@param y size of the voxel in y direction ///@param z size of the voxel in z direction /// Sets the dimenstions of the voxels. void setDims(float x, float y, float z) { S[1] = x; S[2] = y; S[3] = z; } ///Method:getDims /// get the dimenstions of the voxels. vec getDims() { vec dims(S[1], S[2], S[3]); return dims; } ///Method:setPath ///@param file_Path location of the directory with the files /// Sets the path and calls the loader on that path. void setPath(std::string file_path) { path = file_path; image_stack::load_images(path.append("/*.jpg")); setTextureType(); } ///Method: getPath ///Outputs: string path /// Returns the path associated with an instance of the gl_texture class. std::string getPath() { return path; } ///Method: getTexture ///Outputs: GLuint texID /// Returns the id of the texture create by/associated with the /// instance of the gl_texture class. GLuint getTexture() { return texID; } ///Method: createTexture /// Creates a texture and from the loaded data and /// assigns that texture to texID //TO DO :::: 1D textures //TO DO:::add methods for handling the cases of T // and convert them to GL equivalent. // i.e. an overloaded function that handles paramenter conversion. void createTexture() { glPixelStorei(GL_UNPACK_ALIGNMENT,1); glGenTextures(1, &texID); glBindTexture(texture_type, texID); glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR); switch(texture_type) { case GL_TEXTURE_3D: glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(texture_type, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glTexImage3D(texture_type, 0, // GL_RGB16, 1, R[1], R[2], R[3], 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, ptr); //GL_UNSIGNED_BYTE can be TYPES, convert to GL equivalents glPixelStorei(GL_PACK_ALIGNMENT,1); break; case GL_TEXTURE_2D: glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(texture_type, 0, 1, R[1], R[2], 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, ptr); break; } } ///Temporary methods for debugging and testing are below. ///Self-explanatory. T* getData() { return ptr; } }; } #endif