#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 Inputs: Outputs: 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::ptr; using image_stack::samples; public: /* Method: Basic Constructor Inputs: Outputs: Creates an instance of the gl_texture object. */ gl_texture() { } /* Method: Path Constructor Inputs: string file_path Outputs: 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: setPath Inputs:string file_Path Outputs: sets the protected path variable of an instance of the gl_texture class to the method input. */ void setPath(std::string file_path) { path = file_path; image_stack::load_images(path.append("/*.jpg")); setTextureType(); } /* Method: getPath Inputs: Outputs: string path Returns the path associated with an instance of the gl_texture class. */ std::string getPath() { return path; } /* Method: getTexture Inputs: 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 Inputs: Outputs: Creates a texture and from the data located at 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_REPEAT); glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(texture_type, GL_TEXTURE_WRAP_R, GL_REPEAT); 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. */ stim::vec getDims() { return R; } T* getData() { return ptr; } }; } #endif