Some more progress in the imperative API.

This commit is contained in:
castano 2009-03-05 05:34:28 +00:00
parent 8f0b129a52
commit 0f5a5e5d24
4 changed files with 51 additions and 28 deletions

View File

@ -26,23 +26,24 @@
using namespace nvtt; using namespace nvtt;
Texture::Texture() : m(*new Texture::Private()) Texture::Texture() : m(NULL)
{
}
Texture::Texture(const Texture & tex) : m(tex.m)
{ {
} }
Texture::~Texture() Texture::~Texture()
{ {
delete &m; delete m;
}
Texture::Texture(const Texture & tex) : m(*new Texture::Private())
{
// @@ Not implemented.
} }
void Texture::operator=(const Texture & tex) void Texture::operator=(const Texture & tex)
{ {
// @@ Not implemented. tex.m->addRef();
m = tex.m;
m->release();
} }
bool Texture::load(const char * fileName) bool Texture::load(const char * fileName)
@ -53,7 +54,7 @@ bool Texture::load(const char * fileName)
void Texture::setType(TextureType type) void Texture::setType(TextureType type)
{ {
m.type = type; m->type = type;
} }
void Texture::setTexture2D(InputFormat format, int w, int h, int idx, void * data) 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. // @@ Not implemented.
} }
bool Texture::buildMipmap(MipmapFilter filter) bool Texture::buildNextMipmap(MipmapFilter filter)
{ {
// @@ Not implemented. // @@ Not implemented.
} }
@ -75,17 +76,17 @@ bool Texture::buildMipmap(MipmapFilter filter)
// Color transforms. // Color transforms.
void Texture::toLinear(float gamma) 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) 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) 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) 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() void Texture::normalize()
{ {
foreach(i, m.imageArray) foreach(i, m->imageArray)
{ {
m.imageArray[i].normalize(0); m->imageArray[i].normalize(0);
} }
} }

View File

@ -27,6 +27,7 @@
#include "nvtt.h" #include "nvtt.h"
#include <nvcore/Containers.h> #include <nvcore/Containers.h>
#include <nvcore/RefCounted.h>
#include <nvimage/Image.h> #include <nvimage/Image.h>
#include <nvimage/FloatImage.h> #include <nvimage/FloatImage.h>
@ -34,7 +35,7 @@
namespace nvtt namespace nvtt
{ {
struct Texture::Private struct Texture::Private : public nv::RefCounted
{ {
TextureType type; TextureType type;
nv::Array<nv::FloatImage> imageArray; nv::Array<nv::FloatImage> imageArray;

View File

@ -53,7 +53,7 @@
private: \ private: \
Class(const Class &); \ Class(const Class &); \
void operator=(const Class &); \ void operator=(const Class &); \
public: \ public:
#define NVTT_DECLARE_PIMPL(Class) \ #define NVTT_DECLARE_PIMPL(Class) \
public: \ public: \
@ -358,6 +358,8 @@ namespace nvtt
NVTT_API int estimateSize(const InputOptions & inputOptions, const CompressionOptions & compressionOptions) const; NVTT_API int estimateSize(const InputOptions & inputOptions, const CompressionOptions & compressionOptions) const;
NVTT_API void outputCompressed(const Texture & tex, const OutputOptions & outputOptions); NVTT_API void outputCompressed(const Texture & tex, const OutputOptions & outputOptions);
NVTT_API Texture createTexture();
}; };
// "Compressor" is deprecated. This should have been called "Context" // "Compressor" is deprecated. This should have been called "Context"
@ -367,13 +369,11 @@ namespace nvtt
/// Texture data. /// Texture data.
struct Texture struct Texture
{ {
NVTT_DECLARE_PIMPL(Texture);
NVTT_API Texture(); NVTT_API Texture();
NVTT_API Texture(const Texture & tex);
NVTT_API ~Texture(); NVTT_API ~Texture();
Texture(const Texture & tex); NVTT_API void operator=(const Texture & tex);
void operator=(const Texture & tex);
NVTT_API bool load(const char * fileName); // @@ Input callbacks? NVTT_API bool load(const char * fileName); // @@ Input callbacks?
@ -382,7 +382,7 @@ namespace nvtt
// Resizing // Resizing
NVTT_API void resize(int w, int h, ResizeFilter filter); NVTT_API void resize(int w, int h, ResizeFilter filter);
NVTT_API bool buildMipmap(MipmapFilter filter); NVTT_API bool buildNextMipmap(MipmapFilter filter);
// Color transforms. // Color transforms.
NVTT_API void toLinear(float gamma); NVTT_API void toLinear(float gamma);
@ -393,6 +393,10 @@ namespace nvtt
NVTT_API void normalize(); NVTT_API void normalize();
NVTT_API void blend(float r, float g, float b, float a); NVTT_API void blend(float r, float g, float b, float a);
NVTT_API void premultiplyAlpha(); NVTT_API void premultiplyAlpha();
private:
struct Private;
Private * m;
}; };

View File

@ -25,10 +25,27 @@
#include <stdlib.h> #include <stdlib.h>
//using namespace nv;
int main(int argc, char *argv[]) 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; return EXIT_SUCCESS;
} }