diff --git a/src/nvimage/FloatImage.cpp b/src/nvimage/FloatImage.cpp index f61c9e7..0265a2a 100644 --- a/src/nvimage/FloatImage.cpp +++ b/src/nvimage/FloatImage.cpp @@ -169,6 +169,17 @@ void FloatImage::clear(uint c, float f/*= 0.0f*/) } } +void FloatImage::copyChannel(uint src, uint dst) +{ + nvCheck(src < m_componentCount); + nvCheck(dst < m_componentCount); + + const float * srcChannel = this->channel(src); + float * dstChannel = this->channel(dst); + + memcpy(dstChannel, srcChannel, sizeof(float)*m_pixelCount); +} + void FloatImage::normalize(uint baseComponent) { nvCheck(baseComponent + 3 <= m_componentCount); diff --git a/src/nvthread/Atomic.h b/src/nvthread/Atomic.h index 8315d81..f26f807 100644 --- a/src/nvthread/Atomic.h +++ b/src/nvthread/Atomic.h @@ -150,8 +150,8 @@ namespace nv { private: // don't provide operator = or == ; make the client write Store( Load() ) NV_FORBID_COPY(Atomic); - - NV_COMPILER_CHECK(sizeof(T) == sizeof(uint32) || sizeof(T) == sizeof(uint64)); + + NV_COMPILER_CHECK(sizeof(T) == sizeof(uint32) || sizeof(T) == sizeof(uint64)); T m_value; }; diff --git a/src/nvthread/Event.cpp b/src/nvthread/Event.cpp index a86893d..b9f8c9b 100644 --- a/src/nvthread/Event.cpp +++ b/src/nvthread/Event.cpp @@ -48,6 +48,6 @@ void Event::wait() { } #elif NV_OS_UNIX - // @@ TODO +// @@ TODO #pragma NV_MESSAGE("Implement event using pthreads!") #endif diff --git a/src/nvthread/Event.h b/src/nvthread/Event.h index 1e738a8..9076677 100644 --- a/src/nvthread/Event.h +++ b/src/nvthread/Event.h @@ -18,8 +18,8 @@ namespace nv Event(); ~Event(); - void post(); - void wait(); // Wait resets the event. + void post(); + void wait(); // Wait resets the event. static void post(Event * events, uint count); static void wait(Event * events, uint count); diff --git a/src/nvthread/Mutex.h b/src/nvthread/Mutex.h index 13e34e0..53aeb60 100644 --- a/src/nvthread/Mutex.h +++ b/src/nvthread/Mutex.h @@ -18,14 +18,14 @@ namespace nv Mutex (); ~Mutex (); - void lock(); - bool tryLock(); - void unlock(); + void lock(); + bool tryLock(); + void unlock(); private: struct Private; AutoPtr m; -}; + }; // Templated lock that can be used with any mutex. @@ -35,8 +35,8 @@ namespace nv NV_FORBID_COPY(Lock); public: - Lock (M & m) : m_mutex (m) { m_mutex.lock(); } - ~Lock () { m_mutex.unlock(); } + Lock (M & m) : m_mutex (m) { m_mutex.lock(); } + ~Lock () { m_mutex.unlock(); } private: M & m_mutex; diff --git a/src/nvthread/Thread.h b/src/nvthread/Thread.h index 0e46564..133472e 100644 --- a/src/nvthread/Thread.h +++ b/src/nvthread/Thread.h @@ -19,21 +19,21 @@ namespace nv Thread(); ~Thread(); - void start(ThreadFunc * func, void * arg); - void wait(); + void start(ThreadFunc * func, void * arg); + void wait(); - bool isRunning() const; + bool isRunning() const; - static void spinWait(uint count); - static void yield(); - static void sleep(uint ms); + static void spinWait(uint count); + static void yield(); + static void sleep(uint ms); - static void wait(Thread * threads, uint count); + static void wait(Thread * threads, uint count); private: - struct Private; - AutoPtr p; + struct Private; + AutoPtr p; public: // @@ Why public? Also in private?! ThreadFunc * func; diff --git a/src/nvthread/ThreadPool.h b/src/nvthread/ThreadPool.h index 84fc41e..147a607 100644 --- a/src/nvthread/ThreadPool.h +++ b/src/nvthread/ThreadPool.h @@ -1,8 +1,8 @@ -// This code is in the public domain -- castano@gmail.com - -#pragma once -#ifndef NV_THREAD_THREADPOOL_H -#define NV_THREAD_THREADPOOL_H +// This code is in the public domain -- castano@gmail.com + +#pragma once +#ifndef NV_THREAD_THREADPOOL_H +#define NV_THREAD_THREADPOOL_H #include "nvthread.h" diff --git a/src/nvthread/nvthread.cpp b/src/nvthread/nvthread.cpp index db46927..463efb9 100644 --- a/src/nvthread/nvthread.cpp +++ b/src/nvthread/nvthread.cpp @@ -5,10 +5,10 @@ #include "Thread.h" #if NV_OS_WIN32 - #include "Win32.h" +#include "Win32.h" #elif NV_OS_UNIX - #include - #include +#include +#include #endif @@ -40,12 +40,12 @@ uint nv::hardwareThreadCount() { sysctl(mib, 2, &numCPU, &len, NULL, 0); if (numCPU < 1) { - mib[1] = HW_NCPU; - sysctl( mib, 2, &numCPU, &len, NULL, 0 ); + mib[1] = HW_NCPU; + sysctl( mib, 2, &numCPU, &len, NULL, 0 ); - if (numCPU < 1) { - return 1; // Assume single core. - } + if (numCPU < 1) { + return 1; // Assume single core. + } } return numCPU; diff --git a/src/nvtt/Context.cpp b/src/nvtt/Context.cpp index 8361b02..fef0120 100644 --- a/src/nvtt/Context.cpp +++ b/src/nvtt/Context.cpp @@ -152,6 +152,26 @@ int Compressor::estimateSize(const TexImage & tex, int mipmapCount, const Compre return estimateSize(w, h, d, mipmapCount, compressionOptions); } +bool Compressor::outputHeader(const CubeImage & cube, int mipmapCount, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const +{ + return m.outputHeader(TextureType_Cube, cube.size(), cube.size(), 1, mipmapCount, false, compressionOptions.m, outputOptions.m); +} + +bool Compressor::compress(const CubeImage & cube, int mipmap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const +{ + for (int i = 0; i < 6; i++) { + if(!m.compress(cube.face(i), i, mipmap, compressionOptions.m, outputOptions.m)) { + return false; + } + } + return true; +} + +int Compressor::estimateSize(const CubeImage & cube, int mipmapCount, const CompressionOptions & compressionOptions) const +{ + return 6 * estimateSize(cube.size(), cube.size(), 1, mipmapCount, compressionOptions); +} + // Raw API. bool Compressor::outputHeader(TextureType type, int w, int h, int d, int mipmapCount, bool isNormalMap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const diff --git a/src/nvtt/CubeImage.cpp b/src/nvtt/CubeImage.cpp index 668f4a1..e71e0fe 100644 --- a/src/nvtt/CubeImage.cpp +++ b/src/nvtt/CubeImage.cpp @@ -87,32 +87,57 @@ TexImage & CubeImage::face(int f) return m->face[f]; } +const TexImage & CubeImage::face(int f) const +{ + nvDebugCheck(f >= 0 && f < 6); + return m->face[f]; +} + bool CubeImage::load(const char * fileName) { + // @@ TODO return false; } bool CubeImage::save(const char * fileName) const { + // @@ TODO return false; } void CubeImage::fold(const TexImage & tex, CubeLayout layout) { - + // @@ TODO } -TexImage CubeImage::unfold(CubeLayout layout) +TexImage CubeImage::unfold(CubeLayout layout) const { - + // @@ TODO + return TexImage(); } +CubeImage CubeImage::irradianceFilter(int size) const +{ + // @@ TODO + return CubeImage(); +} + +CubeImage CubeImage::cosinePowerFilter(int size, float cosinePower) const +{ + // @@ TODO + return CubeImage(); +} + void CubeImage::toLinear(float gamma) { + if (isNull()) return; + + detach(); + for (int i = 0; i < 6; i++) { m->face[i].toLinear(gamma); } @@ -120,6 +145,10 @@ void CubeImage::toLinear(float gamma) void CubeImage::toGamma(float gamma) { + if (isNull()) return; + + detach(); + for (int i = 0; i < 6; i++) { m->face[i].toGamma(gamma); } diff --git a/src/nvtt/TexImage.cpp b/src/nvtt/TexImage.cpp index 884f9c4..356e81f 100644 --- a/src/nvtt/TexImage.cpp +++ b/src/nvtt/TexImage.cpp @@ -1224,8 +1224,7 @@ void TexImage::toRGBM(float range/*= 1*/, float threshold/*= 0.25*/) detach(); - //threshold = clamp(threshold, 1e-6f, 1.0f); - threshold = 1e-6f; + threshold = ::clamp(threshold, 1e-6f, 1.0f); float irange = 1.0f / range; FloatImage * img = m->image; diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index 709bf48..295e71e 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -68,6 +68,7 @@ namespace nvtt { // Forward declarations. struct TexImage; + struct CubeImage; /// Supported compression formats. enum Format @@ -382,6 +383,11 @@ namespace nvtt NVTT_API bool compress(const TexImage & tex, int face, int mipmap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const; NVTT_API int estimateSize(const TexImage & tex, int mipmapCount, const CompressionOptions & compressionOptions) const; + // CubeImage API. + NVTT_API bool outputHeader(const CubeImage & cube, int mipmapCount, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const; + NVTT_API bool compress(const CubeImage & cube, int mipmap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const; + NVTT_API int estimateSize(const CubeImage & cube, int mipmapCount, const CompressionOptions & compressionOptions) const; + // Raw API. NVTT_API bool outputHeader(TextureType type, int w, int h, int d, int mipmapCount, bool isNormalMap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const; NVTT_API bool compress(int w, int h, int d, int face, int mipmap, const float * rgba, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const; @@ -541,17 +547,20 @@ namespace nvtt NVTT_API bool save(const char * fileName) const; TexImage & face(int face); + const TexImage & face(int face) const; // Layout conversion. void fold(const TexImage & img, CubeLayout layout); - TexImage unfold(CubeLayout layout); + TexImage unfold(CubeLayout layout) const; // @@ Angular extent filtering. // @@ Add resizing methods. - // @@ Irradiance cubemaps. - CubeImage irradiance(int size); + // Filtering. + CubeImage irradianceFilter(int size) const; + CubeImage cosinePowerFilter(int size, float cosinePower) const; + /* NVTT_API void resize(int w, int h, ResizeFilter filter);