diff --git a/src/nvtt/Texture.cpp b/src/nvtt/Texture.cpp index 86b6b59..1bfb2a3 100644 --- a/src/nvtt/Texture.cpp +++ b/src/nvtt/Texture.cpp @@ -26,23 +26,24 @@ using namespace nvtt; -Texture::Texture() : m(*new Texture::Private()) +Texture::Texture() : m(NULL) +{ +} + +Texture::Texture(const Texture & tex) : m(tex.m) { } Texture::~Texture() { - delete &m; -} - -Texture::Texture(const Texture & tex) : m(*new Texture::Private()) -{ - // @@ Not implemented. + delete m; } void Texture::operator=(const Texture & tex) { - // @@ Not implemented. + tex.m->addRef(); + m = tex.m; + m->release(); } bool Texture::load(const char * fileName) @@ -53,7 +54,7 @@ bool Texture::load(const char * fileName) void Texture::setType(TextureType type) { - m.type = type; + m->type = type; } void Texture::setTexture2D(InputFormat format, int w, int h, int idx, void * data) @@ -67,7 +68,7 @@ void Texture::resize(int w, int h, ResizeFilter filter) // @@ Not implemented. } -bool Texture::buildMipmap(MipmapFilter filter) +bool Texture::buildNextMipmap(MipmapFilter filter) { // @@ Not implemented. } @@ -75,17 +76,17 @@ bool Texture::buildMipmap(MipmapFilter filter) // Color transforms. void Texture::toLinear(float gamma) { - foreach(i, m.imageArray) + foreach(i, m->imageArray) { - m.imageArray[i].toLinear(0, 3, gamma); + m->imageArray[i].toLinear(0, 3, gamma); } } void Texture::toGamma(float gamma) { - foreach(i, m.imageArray) + foreach(i, m->imageArray) { - m.imageArray[i].toGamma(0, 3, gamma); + m->imageArray[i].toGamma(0, 3, gamma); } } @@ -96,25 +97,25 @@ void Texture::transform(const float w0[4], const float w1[4], const float w2[4], void Texture::swizzle(int r, int g, int b, int a) { - foreach(i, m.imageArray) + foreach(i, m->imageArray) { - m.imageArray[i].swizzle(0, r, g, b, a); + m->imageArray[i].swizzle(0, r, g, b, a); } } void Texture::scaleBias(int channel, float scale, float bias) { - foreach(i, m.imageArray) + foreach(i, m->imageArray) { - m.imageArray[i].scaleBias(channel, 1, scale, bias); + m->imageArray[i].scaleBias(channel, 1, scale, bias); } } void Texture::normalize() { - foreach(i, m.imageArray) + foreach(i, m->imageArray) { - m.imageArray[i].normalize(0); + m->imageArray[i].normalize(0); } } diff --git a/src/nvtt/Texture.h b/src/nvtt/Texture.h index 5b129f3..ff8ee99 100644 --- a/src/nvtt/Texture.h +++ b/src/nvtt/Texture.h @@ -27,6 +27,7 @@ #include "nvtt.h" #include +#include #include #include @@ -34,7 +35,7 @@ namespace nvtt { - struct Texture::Private + struct Texture::Private : public nv::RefCounted { TextureType type; nv::Array imageArray; diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index 247091c..86fe48b 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -53,7 +53,7 @@ private: \ Class(const Class &); \ void operator=(const Class &); \ - public: \ + public: #define NVTT_DECLARE_PIMPL(Class) \ public: \ @@ -358,6 +358,8 @@ namespace nvtt NVTT_API int estimateSize(const InputOptions & inputOptions, const CompressionOptions & compressionOptions) const; NVTT_API void outputCompressed(const Texture & tex, const OutputOptions & outputOptions); + + NVTT_API Texture createTexture(); }; // "Compressor" is deprecated. This should have been called "Context" @@ -367,13 +369,11 @@ namespace nvtt /// Texture data. struct Texture { - NVTT_DECLARE_PIMPL(Texture); - NVTT_API Texture(); + NVTT_API Texture(const Texture & tex); NVTT_API ~Texture(); - Texture(const Texture & tex); - void operator=(const Texture & tex); + NVTT_API void operator=(const Texture & tex); NVTT_API bool load(const char * fileName); // @@ Input callbacks? @@ -382,7 +382,7 @@ namespace nvtt // Resizing NVTT_API void resize(int w, int h, ResizeFilter filter); - NVTT_API bool buildMipmap(MipmapFilter filter); + NVTT_API bool buildNextMipmap(MipmapFilter filter); // Color transforms. NVTT_API void toLinear(float gamma); @@ -393,6 +393,10 @@ namespace nvtt NVTT_API void normalize(); NVTT_API void blend(float r, float g, float b, float a); NVTT_API void premultiplyAlpha(); + + private: + struct Private; + Private * m; }; diff --git a/src/nvtt/tests/imperativeapi.cpp b/src/nvtt/tests/imperativeapi.cpp index 889ef18..4872bc4 100644 --- a/src/nvtt/tests/imperativeapi.cpp +++ b/src/nvtt/tests/imperativeapi.cpp @@ -25,10 +25,27 @@ #include -//using namespace nv; int main(int argc, char *argv[]) { + nvtt::CompressionOptions compressionOptions; + nvtt::OutputOptions outputOptions; + + nvtt::Context context; + nvtt::Texture texture = context.createTexture(); + + texture.load("kodim01.png"); + + float gamma = 2.2; + texture.toLinear(gamma); + + while (texture.buildNextMipmap(nvtt::MipmapFilter_Box)) + { + nvtt::Texture tmp = texture; + tmp.toGamma(gamma); + //tmp.compress(compressionOptions, outputOptions); + } + return EXIT_SUCCESS; }