Merge changes from the witness.

pull/216/head
castano 14 years ago
parent 30b9545d75
commit 9094756997

@ -275,12 +275,14 @@ namespace nv
} }
/// Remove the first instance of the given element. /// Remove the first instance of the given element.
void remove(const T & element) bool remove(const T & element)
{ {
for (uint i = 0; i < m_size; i++) { uint index;
removeAt(i); if (find(element, &index)) {
break; removeAt(index);
return true;
} }
return false;
} }
/// Insert the given element at the given index shifting all the elements up. /// Insert the given element at the given index shifting all the elements up.
@ -342,7 +344,7 @@ namespace nv
} }
if( m_size == 0 ) { if( m_size == 0 ) {
//Allocate(0); // Don't shrink automatically. //allocate(0); // Don't shrink automatically.
} }
else if( m_size <= m_buffer_size/* && m_size > m_buffer_size >> 1*/) { else if( m_size <= m_buffer_size/* && m_size > m_buffer_size >> 1*/) {
// don't compact yet. // don't compact yet.
@ -382,7 +384,7 @@ namespace nv
} }
if( m_size == 0 ) { if( m_size == 0 ) {
//Allocate(0); // Don't shrink automatically. //allocate(0); // Don't shrink automatically.
} }
else if( m_size <= m_buffer_size && m_size > m_buffer_size >> 1 ) { else if( m_size <= m_buffer_size && m_size > m_buffer_size >> 1 ) {
// don't compact yet. // don't compact yet.

@ -48,9 +48,6 @@
# endif # endif
#endif #endif
#include <stdexcept> // std::runtime_error
#undef assert // defined on mingw
using namespace nv; using namespace nv;
namespace namespace
@ -356,7 +353,7 @@ namespace
if( ret == NV_ABORT_EXIT ) { if( ret == NV_ABORT_EXIT ) {
// Exit cleanly. // Exit cleanly.
throw std::runtime_error("Assertion failed"); throw "Assertion failed";
} }
return ret; return ret;

@ -24,7 +24,6 @@
#if _MSC_VER < 1500 #if _MSC_VER < 1500
# define vsnprintf _vsnprintf # define vsnprintf _vsnprintf
#endif #endif
#define vsscanf _vsscanf
#define chdir _chdir #define chdir _chdir
#define getcwd _getcwd #define getcwd _getcwd

@ -5,12 +5,13 @@
#include "nvcore.h" #include "nvcore.h"
#include "Debug.h" #include "Debug.h"
#include "RefCounted.h" // WeakProxy
namespace nv namespace nv
{ {
class WeakProxy;
/** Simple auto pointer template class. /** Simple auto pointer template class.
* *
* This is very similar to the standard auto_ptr class, but with some * This is very similar to the standard auto_ptr class, but with some
@ -273,7 +274,7 @@ namespace nv
void operator=(T * p) void operator=(T * p)
{ {
if (p != NULL) { if (p) {
m_proxy = p->getWeakProxy(); m_proxy = p->getWeakProxy();
nvDebugCheck(m_proxy != NULL); nvDebugCheck(m_proxy != NULL);
nvDebugCheck(m_proxy->ptr() == p); nvDebugCheck(m_proxy->ptr() == p);

@ -9,12 +9,6 @@
#include <stdarg.h> // vsnprintf #include <stdarg.h> // vsnprintf
#endif #endif
#if NV_OS_WIN32
#define NV_PATH_SEPARATOR '\\'
#else
#define NV_PATH_SEPARATOR '/'
#endif
using namespace nv; using namespace nv;
namespace namespace
@ -230,7 +224,7 @@ StringBuilder & StringBuilder::format( const char * fmt, ... )
va_list arg; va_list arg;
va_start( arg, fmt ); va_start( arg, fmt );
format( fmt, arg ); formatList( fmt, arg );
va_end( arg ); va_end( arg );
@ -239,7 +233,7 @@ StringBuilder & StringBuilder::format( const char * fmt, ... )
/** Format a string safely. */ /** Format a string safely. */
StringBuilder & StringBuilder::format( const char * fmt, va_list arg ) StringBuilder & StringBuilder::formatList( const char * fmt, va_list arg )
{ {
nvDebugCheck(fmt != NULL); nvDebugCheck(fmt != NULL);
@ -315,14 +309,14 @@ StringBuilder & StringBuilder::append( const char * s )
/** Append a formatted string. */ /** Append a formatted string. */
StringBuilder & StringBuilder::appendFormat( const char * format, ... ) StringBuilder & StringBuilder::appendFormat( const char * fmt, ... )
{ {
nvDebugCheck( format != NULL ); nvDebugCheck( fmt != NULL );
va_list arg; va_list arg;
va_start( arg, format ); va_start( arg, fmt );
appendFormat( format, arg ); appendFormatList( fmt, arg );
va_end( arg ); va_end( arg );
@ -331,16 +325,21 @@ StringBuilder & StringBuilder::appendFormat( const char * format, ... )
/** Append a formatted string. */ /** Append a formatted string. */
StringBuilder & StringBuilder::appendFormat( const char * format, va_list arg ) StringBuilder & StringBuilder::appendFormatList( const char * fmt, va_list arg )
{ {
nvDebugCheck( format != NULL ); nvDebugCheck( fmt != NULL );
va_list tmp; va_list tmp;
va_copy(tmp, arg); va_copy(tmp, arg);
if (m_size == 0) {
formatList(fmt, arg);
}
else {
StringBuilder tmp_str; StringBuilder tmp_str;
tmp_str.format( format, tmp ); tmp_str.formatList( fmt, tmp );
append( tmp_str ); append( tmp_str );
}
va_end(tmp); va_end(tmp);
@ -459,17 +458,13 @@ const char * Path::extension() const
/// Toggles path separators (ie. \\ into /). /// Toggles path separators (ie. \\ into /).
void Path::translatePath() void Path::translatePath(char pathSeparator /*= NV_PATH_SEPARATOR*/)
{ {
nvCheck( m_str != NULL ); nvCheck( m_str != NULL );
for (int i = 0; ; i++) { for (int i = 0; ; i++) {
if (m_str[i] == '\0') break; if (m_str[i] == '\0') break;
#if NV_PATH_SEPARATOR == '/' if (m_str[i] == '\\' || m_str[i] == '/') m_str[i] = pathSeparator;
if( m_str[i] == '\\' ) m_str[i] = NV_PATH_SEPARATOR;
#else
if( m_str[i] == '/' ) m_str[i] = NV_PATH_SEPARATOR;
#endif
} }
} }
@ -507,7 +502,7 @@ void Path::stripExtension()
return; // no extension return; // no extension
} }
} }
if( length ) { if (length > 0) {
m_str[length] = 0; m_str[length] = 0;
} }
} }

@ -10,6 +10,11 @@
#include <string.h> // strlen, strcmp, etc. #include <string.h> // strlen, strcmp, etc.
#if NV_OS_WIN32
#define NV_PATH_SEPARATOR '\\'
#else
#define NV_PATH_SEPARATOR '/'
#endif
namespace nv namespace nv
{ {
@ -32,6 +37,7 @@ namespace nv
}; };
NVCORE_API int strCaseCmp(const char * s1, const char * s2) NV_PURE; NVCORE_API int strCaseCmp(const char * s1, const char * s2) NV_PURE;
NVCORE_API int strCmp(const char * s1, const char * s2) NV_PURE; NVCORE_API int strCmp(const char * s1, const char * s2) NV_PURE;
@ -60,11 +66,11 @@ namespace nv
~StringBuilder(); ~StringBuilder();
StringBuilder & format( const char * format, ... ) __attribute__((format (printf, 2, 3))); StringBuilder & format( const char * format, ... ) __attribute__((format (printf, 2, 3)));
StringBuilder & format( const char * format, va_list arg ); StringBuilder & formatList( const char * format, va_list arg );
StringBuilder & append( const char * str ); StringBuilder & append( const char * str );
StringBuilder & appendFormat( const char * format, ... ) __attribute__((format (printf, 2, 3))); StringBuilder & appendFormat( const char * format, ... ) __attribute__((format (printf, 2, 3)));
StringBuilder & appendFormat( const char * format, va_list arg ); StringBuilder & appendFormatList( const char * format, va_list arg );
StringBuilder & number( int i, int base = 10 ); StringBuilder & number( int i, int base = 10 );
StringBuilder & number( uint i, int base = 10 ); StringBuilder & number( uint i, int base = 10 );
@ -142,7 +148,7 @@ namespace nv
const char * fileName() const; const char * fileName() const;
const char * extension() const; const char * extension() const;
void translatePath(); void translatePath(char pathSeparator = NV_PATH_SEPARATOR);
void stripFileName(); void stripFileName();
void stripExtension(); void stripExtension();
@ -361,6 +367,10 @@ namespace nv
}; };
template <> struct Hash<String> {
uint operator()(const String & str) const { return str.hash(); }
};
} // nv namespace } // nv namespace
#endif // NV_CORE_STRING_H #endif // NV_CORE_STRING_H

@ -151,8 +151,8 @@
/// @hideinitializer /// @hideinitializer
#define NV_UNUSED(a) ((a)=(a)) #define NV_UNUSED(a) ((a)=(a))
/// Null index. @@ Move this somewhere else... This could have collisions with other definitions! /// Null index. @@ Move this somewhere else... it's only used by nvmesh.
#define NIL uint(~0) const unsigned int NIL = unsigned int(~0);
/// Null pointer. /// Null pointer.
#ifndef NULL #ifndef NULL

@ -22,7 +22,6 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#include "BlockDXT.h" #include "BlockDXT.h"
#include "ColorBlock.h" #include "ColorBlock.h"
#include "nvcore/Stream.h" #include "nvcore/Stream.h"
@ -39,9 +38,9 @@ using namespace nv;
uint BlockDXT1::evaluatePalette(Color32 color_array[4]) const uint BlockDXT1::evaluatePalette(Color32 color_array[4]) const
{ {
// Does bit expansion before interpolation. // Does bit expansion before interpolation.
color_array[0].r = (col0.r << 3) | (col0.r >> 2);
color_array[0].g = (col0.g << 2) | (col0.g >> 4);
color_array[0].b = (col0.b << 3) | (col0.b >> 2); color_array[0].b = (col0.b << 3) | (col0.b >> 2);
color_array[0].g = (col0.g << 2) | (col0.g >> 4);
color_array[0].r = (col0.r << 3) | (col0.r >> 2);
color_array[0].a = 0xFF; color_array[0].a = 0xFF;
// @@ Same as above, but faster? // @@ Same as above, but faster?
@ -97,14 +96,14 @@ uint BlockDXT1::evaluatePalette(Color32 color_array[4]) const
uint BlockDXT1::evaluatePaletteNV5x(Color32 color_array[4]) const uint BlockDXT1::evaluatePaletteNV5x(Color32 color_array[4]) const
{ {
// Does bit expansion before interpolation. // Does bit expansion before interpolation.
color_array[0].r = (3 * col0.r * 22) / 8; color_array[0].b = col0.b * 22 / 8;
color_array[0].g = (col0.g << 2) | (col0.g >> 4); color_array[0].g = (col0.g << 2) | (col0.g >> 4);
color_array[0].b = (3 * col0.b * 22) / 8; color_array[0].r = col0.r * 22 / 8;
color_array[0].a = 0xFF; color_array[0].a = 0xFF;
color_array[1].r = (3 * col1.r * 22) / 8; color_array[1].r = col1.r * 22 / 8;
color_array[1].g = (col1.g << 2) | (col1.g >> 4); color_array[1].g = (col1.g << 2) | (col1.g >> 4);
color_array[1].b = (3 * col1.b * 22) / 8; color_array[1].b = col1.b * 22 / 8;
color_array[1].a = 0xFF; color_array[1].a = 0xFF;
if( col0.u > col1.u ) { if( col0.u > col1.u ) {
@ -117,8 +116,8 @@ uint BlockDXT1::evaluatePaletteNV5x(Color32 color_array[4]) const
color_array[3].r = (2 * col1.r + col0.r) * 22 / 8; color_array[3].r = (2 * col1.r + col0.r) * 22 / 8;
color_array[3].g = (256 * color_array[1].g + (color_array[0].g - color_array[1].g)/4 + 128 + (color_array[0].g - color_array[1].g) * 80) / 256; color_array[3].g = (256 * color_array[1].g + (color_array[0].g - color_array[1].g)/4 + 128 + (color_array[0].g - color_array[1].g) * 80) / 256;
color_array[3].b = (2 * col1.b + col0.b) * 22 / 8; color_array[3].b = (2 * col1.b + col0.b) * 22 / 8;
color_array[3].a = 0xFF; color_array[3].a = 0xFF;
return 4; return 4;
} }
else { else {
@ -224,7 +223,6 @@ void BlockDXT1::decodeBlockNV5x(ColorBlock * block) const
} }
} }
void BlockDXT1::setIndices(int * idx) void BlockDXT1::setIndices(int * idx)
{ {
indices = 0; indices = 0;

@ -21,12 +21,13 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#pragma once
#ifndef NV_IMAGE_BLOCKDXT_H #ifndef NV_IMAGE_BLOCKDXT_H
#define NV_IMAGE_BLOCKDXT_H #define NV_IMAGE_BLOCKDXT_H
#include <nvmath/Color.h> #include "nvimage.h"
#include <nvimage/nvimage.h> #include "nvmath/Color.h"
namespace nv namespace nv
{ {

@ -165,10 +165,7 @@ Color32 c;
int i; int i;
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
{ {
if (m_color[i].a != 0) { if (m_color[i].a != 0) c = m_color[i];
c = m_color[i];
break;
}
} }
Color32 mask(0xFF, 0xFF, 0xFF, 0x00); Color32 mask(0xFF, 0xFF, 0xFF, 0x00);
@ -483,10 +480,10 @@ void FloatColorBlock::init(const Image * img, uint x, uint y)
const uint bx = e % w; const uint bx = e % w;
Color32 c = img->pixel(x+bx, y+by); Color32 c = img->pixel(x+bx, y+by);
Vector4 & v = color(e, i); Vector4 & v = color(e, i);
v.x = c.r / 255; v.x = c.r / 255.0f;
v.y = c.g / 255; v.y = c.g / 255.0f;
v.z = c.b / 255; v.z = c.b / 255.0f;
v.w = c.a / 255; v.w = c.a / 255.0f;
} }
} }
} }

@ -1,5 +1,6 @@
// This code is in the public domain -- jim@tilander.org // This code is in the public domain -- jim@tilander.org
#pragma once
#ifndef NV_IMAGE_COLORSPACE_H #ifndef NV_IMAGE_COLORSPACE_H
#define NV_IMAGE_COLORSPACE_H #define NV_IMAGE_COLORSPACE_H

@ -25,7 +25,7 @@
#ifndef NV_IMAGE_DIRECTDRAWSURFACE_H #ifndef NV_IMAGE_DIRECTDRAWSURFACE_H
#define NV_IMAGE_DIRECTDRAWSURFACE_H #define NV_IMAGE_DIRECTDRAWSURFACE_H
#include <nvimage/nvimage.h> #include "nvimage.h"
namespace nv namespace nv
{ {

@ -39,6 +39,7 @@ const Image & Image::operator=(const Image & img)
void Image::allocate(uint w, uint h) void Image::allocate(uint w, uint h)
{ {
free();
m_width = w; m_width = w;
m_height = h; m_height = h;
m_data = (Color32 *)nv::mem::realloc(m_data, w * h * sizeof(Color32)); m_data = (Color32 *)nv::mem::realloc(m_data, w * h * sizeof(Color32));

@ -21,14 +21,14 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#include <nvimage/NormalMap.h> #include "NormalMap.h"
#include <nvimage/Filter.h> #include "Filter.h"
#include <nvimage/FloatImage.h> #include "FloatImage.h"
#include <nvimage/Image.h> #include "Image.h"
#include <nvmath/Color.h> #include "nvmath/Color.h"
#include <nvcore/Ptr.h> #include "nvcore/Ptr.h"
using namespace nv; using namespace nv;

@ -21,12 +21,14 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#pragma once
#ifndef NV_IMAGE_NORMALMAP_H #ifndef NV_IMAGE_NORMALMAP_H
#define NV_IMAGE_NORMALMAP_H #define NV_IMAGE_NORMALMAP_H
#include <nvmath/Vector.h> #include "nvimage.h"
#include <nvimage/nvimage.h> #include "FloatImage.h"
#include <nvimage/FloatImage.h>
#include "nvmath/Vector.h"
namespace nv namespace nv

@ -21,10 +21,11 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#pragma once
#ifndef NV_IMAGE_PIXELFORMAT_H #ifndef NV_IMAGE_PIXELFORMAT_H
#define NV_IMAGE_PIXELFORMAT_H #define NV_IMAGE_PIXELFORMAT_H
#include <nvimage/nvimage.h> #include "nvimage.h"
namespace nv namespace nv

@ -1,9 +1,10 @@
// This code is in the public domain -- castanyo@yahoo.es // This code is in the public domain -- castanyo@yahoo.es
#pragma once
#ifndef NV_IMAGE_PSDFILE_H #ifndef NV_IMAGE_PSDFILE_H
#define NV_IMAGE_PSDFILE_H #define NV_IMAGE_PSDFILE_H
#include <nvcore/Stream.h> #include "nvcore/Stream.h"
namespace nv namespace nv
{ {

@ -1,9 +1,10 @@
// This code is in the public domain -- castanyo@yahoo.es // This code is in the public domain -- castanyo@yahoo.es
#pragma once
#ifndef NV_IMAGE_QUANTIZE_H #ifndef NV_IMAGE_QUANTIZE_H
#define NV_IMAGE_QUANTIZE_H #define NV_IMAGE_QUANTIZE_H
#include <nvimage/nvimage.h> #include "nvimage.h"
namespace nv namespace nv

@ -1,9 +1,10 @@
// This code is in the public domain -- castanyo@yahoo.es // This code is in the public domain -- castanyo@yahoo.es
#pragma once
#ifndef NV_IMAGE_TGAFILE_H #ifndef NV_IMAGE_TGAFILE_H
#define NV_IMAGE_TGAFILE_H #define NV_IMAGE_TGAFILE_H
#include <nvcore/Stream.h> #include "nvcore/Stream.h"
namespace nv namespace nv
{ {

@ -1,5 +1,6 @@
// This code is in the public domain -- castanyo@yahoo.es // This code is in the public domain -- castanyo@yahoo.es
#pragma once
#ifndef NV_IMAGE_H #ifndef NV_IMAGE_H
#define NV_IMAGE_H #define NV_IMAGE_H

@ -26,7 +26,7 @@
#include "Compressor.h" #include "Compressor.h"
struct Tile; class Tile;
namespace nv namespace nv
{ {

@ -69,7 +69,7 @@ int main(int argc, char *argv[])
float gamma = 2.2f; float gamma = 2.2f;
image.toLinear(gamma); image.toLinear(gamma);
float alphaRef = 0.95; float alphaRef = 0.95f;
float coverage = image.alphaTestCoverage(alphaRef); float coverage = image.alphaTestCoverage(alphaRef);
// Build mimaps. // Build mimaps.

Loading…
Cancel
Save