Start implementing experimental interface.

This commit is contained in:
castano
2009-01-05 10:17:06 +00:00
parent e965b0e4a9
commit 508f9fbdc2
7 changed files with 329 additions and 15 deletions

View File

@ -1,16 +1,16 @@
#include "nvtt_experimental.h"
struct NvttImage
struct NvttTexture
{
NvttImage() :
NvttTexture() :
m_constant(false),
m_image(NULL),
m_floatImage(NULL)
{
}
~NvttImage()
~NvttTexture()
{
if (m_constant && m_image) m_image->unwrap();
delete m_image;
@ -22,14 +22,14 @@ struct NvttImage
FloatImage * m_floatImage;
};
NvttImage * nvttCreateImage()
NvttTexture * nvttCreateTexture()
{
return new NvttImage();
return new NvttTexture();
}
void nvttDestroyImage(NvttImage * img)
void nvttDestroyTexture(NvttTexture * tex)
{
delete img;
delete tex;
}
void nvttSetImageData(NvttImage * img, NvttInputFormat format, uint w, uint h, void * data)

View File

@ -4,14 +4,30 @@
#include <nvtt/nvtt.h>
typedef struct NvttImage NvttImage;
typedef struct NvttTexture NvttTexture;
typedef struct NvttOutputOptions NvttOutputOptions;
// Global functions
void nvttInitialize(...);
unsigned int nvttGetVersion();
const char * nvttGetErrorString(unsigned int error);
// Texture functions
NvttTexture * nvttCreateTexture();
void nvttDestroyTexture(NvttTexture * tex);
void nvttSetTexture2D(NvttTexture * tex, NvttInputFormat format, uint w, uint h, uint idx, void * data);
void nvttResize(NvttTexture * img, uint w, uint h);
unsigned int nvttDownsample(NvttTexture * img);
void nvttOutputCompressed(NvttTexture * img, NvttOutputFormat format);
void nvttOutputPixelFormat(NvttTexture * img, NvttOutputFormat format);
NvttImage * nvttCreateImage();
void nvttDestroyImage(NvttImage * img);
void nvttSetImageData(NvttImage * img, NvttInputFormat format, uint w, uint h, void * data);
void nvttCompressImage(NvttImage * img, NvttFormat format);
// How to control the compression parameters?
@ -50,6 +66,7 @@ void nvttCompressImage(NvttImage * img, NvttFormat format);
// - Return it explicitely from nvttCompressImage.
// - Store it along the image, retrieve later explicitely with 'nvttGetCompressedData(img, ...)'
/*
// Global functions
void nvttInitialize(...);
@ -80,7 +97,7 @@ void nvttResizeImage(NvttImage * image, unsigned int w, unsigned int h);
void nvttQuantizeImage(NvttImage * image, bool dither, unsigned int rbits, unsigned int gbits, unsigned int bbits, unsigned int abits);
void nvttCompressImage(NvttImage * image, void * buffer, int size);
*/
#endif // NVTT_EXPERIMENTAL_H

View File

@ -0,0 +1,61 @@
#include "nvtt_experimental.h"
/*
Errors in the original API:
- Too many memory copies.
- Implementation too complicated.
- Error output should not be in output options.
- Data driven interface. Follows the dialog model. Provide all the data upfront.
*/
// Output texture with mipmaps
void example0()
{
CompressionOptions compressionOptions;
OutputOptions outputOptions;
Texture img;
img.setTexture2D(format, w, h, 0, data);
Compressor context;
context.outputHeader(outputOptions);
context.outputCompressed(img, compressionOptions, outputOptions);
img.toLinear(2.2);
while (img.downsample(NVTT_FILTER_BOX))
{
img.toGamma(2.2);
outputCompressed(img, compressionOptions, outputOptions);
}
}
// Output texture with colored mipmaps
void example1()
{
CompressionOptions compressionOptions;
OutputOptions outputOptions;
Texture img;
img.setTexture2D(format, w, h, 0, data);
Compressor context;
context.outputHeader(outputOptions);
context.outputCompressed(img, compressionOptions, outputOptions);
img.toLinear(2.2);
while (img.downsample(NVTT_FILTER_BOX))
{
img.toGamma(2.2);
Texture mipmap = img;
mipmap.blend(color[i].r, color[i].g, color[i].b, 0.5f);
context.outputCompressed(mipmap, compressionOptions, outputOptions);
}
}