void Texture::Generate(const Dim& dim, std::function<vec4(unsigned int, unsigned int)> generator, const GLenum type) { ILuint image; ilGenImages(1, &image); ilBindImage(image); const unsigned int numBytes = dim.GetWidth() * dim.GetHeight(); vec4* pixels = new vec4[numBytes]; for(unsigned int y=0; y<dim.GetHeight(); y++) { for(unsigned int x=0; x<dim.GetWidth(); x++) { pixels[y*dim.GetWidth() + x] = generator(x, y); } } ilTexImage(dim.GetWidth(), dim.GetHeight(), 1, 4, IL_RGBA, IL_FLOAT, reinterpret_cast<void*>(pixels)); delete[] pixels; if(type == GL_UNSIGNED_BYTE) { this->iformat = GL_RGBA8; this->type = GL_UNSIGNED_BYTE; ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); } else { this->iformat = GL_RGBA32F; this->type = GL_FLOAT; } this->format = GL_RGBA; size.Width = ilGetInteger(IL_IMAGE_WIDTH); size.Height = ilGetInteger(IL_IMAGE_HEIGHT); size.Depth = ilGetInteger(IL_IMAGE_DEPTH); InitResource(4, false, ilGetData()); ilDeleteImages(1, &image); }
Texture::Texture(const Dim& dim, const int samples, const GLenum iformat, const GLenum format, const GLenum type) : size(dim), samples(samples), iformat(iformat), format(format), type(type) { assert(samples > 0); assert(samples == 1 || (dim.GetHeight() >= 1 && dim.GetDepth() == 1)); InitResource(0, false, nullptr); }
Texture::Texture(const Dim& dim, const int samples, const GLenum autoformat) : size(dim), samples(samples), iformat(autoformat) { assert(samples > 0); assert(samples == 1 || (dim.GetHeight() >= 1 && dim.GetDepth() == 1)); assert(DetectFormat()); InitResource(0, false, nullptr); }