Use STB image by default.
Add buffer object, try to reduce binary size.
This commit is contained in:
parent
ad7a618222
commit
43b16d85f4
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
INCLUDE_DIRECTORIES(${NV_SOURCE_DIR}/extern/poshlib)
|
INCLUDE_DIRECTORIES(${NV_SOURCE_DIR}/extern/poshlib)
|
||||||
|
INCLUDE_DIRECTORIES(${NV_SOURCE_DIR}/extern/stb)
|
||||||
|
|
||||||
SUBDIRS(nvcore)
|
SUBDIRS(nvcore)
|
||||||
SUBDIRS(nvmath)
|
SUBDIRS(nvmath)
|
||||||
@ -81,7 +82,7 @@ ELSE(FREEIMAGE_FOUND)
|
|||||||
ENDIF(FREEIMAGE_FOUND)
|
ENDIF(FREEIMAGE_FOUND)
|
||||||
|
|
||||||
# JPEG
|
# JPEG
|
||||||
INCLUDE(FindJPEG)
|
#INCLUDE(FindJPEG)
|
||||||
IF(JPEG_FOUND)
|
IF(JPEG_FOUND)
|
||||||
SET(HAVE_JPEG ${JPEG_FOUND} CACHE BOOL "Set to TRUE if JPEG is found, FALSE otherwise")
|
SET(HAVE_JPEG ${JPEG_FOUND} CACHE BOOL "Set to TRUE if JPEG is found, FALSE otherwise")
|
||||||
MESSAGE(STATUS "Looking for JPEG - found")
|
MESSAGE(STATUS "Looking for JPEG - found")
|
||||||
@ -90,7 +91,7 @@ ELSE(JPEG_FOUND)
|
|||||||
ENDIF(JPEG_FOUND)
|
ENDIF(JPEG_FOUND)
|
||||||
|
|
||||||
# PNG
|
# PNG
|
||||||
INCLUDE(FindPNG)
|
#INCLUDE(FindPNG)
|
||||||
IF(PNG_FOUND)
|
IF(PNG_FOUND)
|
||||||
SET(HAVE_PNG ${PNG_FOUND} CACHE BOOL "Set to TRUE if PNG is found, FALSE otherwise")
|
SET(HAVE_PNG ${PNG_FOUND} CACHE BOOL "Set to TRUE if PNG is found, FALSE otherwise")
|
||||||
MESSAGE(STATUS "Looking for PNG - found")
|
MESSAGE(STATUS "Looking for PNG - found")
|
||||||
@ -99,7 +100,7 @@ ELSE(PNG_FOUND)
|
|||||||
ENDIF(PNG_FOUND)
|
ENDIF(PNG_FOUND)
|
||||||
|
|
||||||
# TIFF
|
# TIFF
|
||||||
SET(TIFF_NAMES libtiff)
|
#SET(TIFF_NAMES libtiff)
|
||||||
INCLUDE(FindTIFF)
|
INCLUDE(FindTIFF)
|
||||||
IF(TIFF_FOUND)
|
IF(TIFF_FOUND)
|
||||||
SET(HAVE_TIFF ${TIFF_FOUND} CACHE BOOL "Set to TRUE if TIFF is found, FALSE otherwise")
|
SET(HAVE_TIFF ${TIFF_FOUND} CACHE BOOL "Set to TRUE if TIFF is found, FALSE otherwise")
|
||||||
@ -109,7 +110,7 @@ ELSE(TIFF_FOUND)
|
|||||||
ENDIF(TIFF_FOUND)
|
ENDIF(TIFF_FOUND)
|
||||||
|
|
||||||
# OpenEXR
|
# OpenEXR
|
||||||
INCLUDE(${NV_CMAKE_DIR}/FindOpenEXR.cmake)
|
#INCLUDE(${NV_CMAKE_DIR}/FindOpenEXR.cmake)
|
||||||
IF(OPENEXR_FOUND)
|
IF(OPENEXR_FOUND)
|
||||||
SET(HAVE_OPENEXR ${OPENEXR_FOUND} CACHE BOOL "Set to TRUE if OpenEXR is found, FALSE otherwise")
|
SET(HAVE_OPENEXR ${OPENEXR_FOUND} CACHE BOOL "Set to TRUE if OpenEXR is found, FALSE otherwise")
|
||||||
MESSAGE(STATUS "Looking for OpenEXR - found")
|
MESSAGE(STATUS "Looking for OpenEXR - found")
|
||||||
|
@ -10,11 +10,12 @@
|
|||||||
#cmakedefine HAVE_OPENMP
|
#cmakedefine HAVE_OPENMP
|
||||||
#cmakedefine HAVE_DISPATCH_H
|
#cmakedefine HAVE_DISPATCH_H
|
||||||
|
|
||||||
#cmakedefine HAVE_PNG
|
#define HAVE_STBIMAGE
|
||||||
#cmakedefine HAVE_JPEG
|
//#cmakedefine HAVE_PNG
|
||||||
#cmakedefine HAVE_TIFF
|
//#cmakedefine HAVE_JPEG
|
||||||
#cmakedefine HAVE_OPENEXR
|
//#cmakedefine HAVE_TIFF
|
||||||
#cmakedefine HAVE_FREEIMAGE
|
//#cmakedefine HAVE_OPENEXR
|
||||||
|
//#cmakedefine HAVE_FREEIMAGE
|
||||||
|
|
||||||
#cmakedefine HAVE_MAYA
|
#cmakedefine HAVE_MAYA
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
This array class requires the elements to be relocable; it uses memmove and realloc. Ideally I should be
|
This array class requires the elements to be relocable; it uses memmove and realloc. Ideally I should be
|
||||||
using swap, but I honestly don't care.
|
using swap, but I honestly don't care. The only thing that you should be aware of is that internal pointers
|
||||||
|
are not supported.
|
||||||
|
|
||||||
The foreach macros that I use are very non-standard and somewhat confusing. It would be nice to have
|
The foreach macros that I use are very non-standard and somewhat confusing. It would be nice to have
|
||||||
standard foreach as in Qt.
|
standard foreach as in Qt.
|
||||||
@ -37,6 +38,94 @@ namespace nv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void construct(T * ptr, uint count) {
|
||||||
|
for (uint i = 0; i < count; i++) {
|
||||||
|
new(ptr+i) T; // placement new
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void destroy(T * ptr, uint count) {
|
||||||
|
for (uint i = 0; i < count; i++) {
|
||||||
|
(ptr+i)->~T();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void fill(T * restrict dst, const T & value, uint count) {
|
||||||
|
for (uint i = 0; i < count; i++) {
|
||||||
|
dst[i] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void copy(T * restrict dst, const T * restrict src, uint count) {
|
||||||
|
for (uint i = 0; i < count; i++) {
|
||||||
|
dst[i] = src[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Buffer
|
||||||
|
{
|
||||||
|
NV_FORBID_COPY(Buffer)
|
||||||
|
public:
|
||||||
|
// Ctor.
|
||||||
|
Buffer() : m_buffer(NULL), m_buffer_size(0), m_size(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dtor.
|
||||||
|
~Buffer() {
|
||||||
|
allocate(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Get vector size.
|
||||||
|
NV_FORCEINLINE uint size() const { return m_size; }
|
||||||
|
|
||||||
|
// Get vector size.
|
||||||
|
NV_FORCEINLINE uint count() const { return m_size; }
|
||||||
|
|
||||||
|
// Is a null vector.
|
||||||
|
NV_FORCEINLINE bool isNull() const { return m_buffer == NULL; }
|
||||||
|
|
||||||
|
|
||||||
|
// Swap the members of this vector and the given vector.
|
||||||
|
friend void swap(Buffer & a, Buffer & b)
|
||||||
|
{
|
||||||
|
swap(a.m_buffer, b.m_buffer);
|
||||||
|
swap(a.m_buffer_size, b.m_buffer_size);
|
||||||
|
swap(a.m_size, b.m_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/// Change buffer size.
|
||||||
|
NV_NOINLINE void allocate(uint count, uint size)
|
||||||
|
{
|
||||||
|
if (count == 0) {
|
||||||
|
// free the buffer.
|
||||||
|
if (m_buffer != NULL) {
|
||||||
|
::free(m_buffer);
|
||||||
|
m_buffer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// realloc the buffer
|
||||||
|
m_buffer = ::realloc(m_buffer, count * size);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_buffer_size = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void * m_buffer;
|
||||||
|
uint m_buffer_size;
|
||||||
|
uint m_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,38 +133,30 @@ namespace nv
|
|||||||
* some nice foreach enumerators.
|
* some nice foreach enumerators.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class NVCORE_CLASS Array {
|
class NVCORE_CLASS Array : public Buffer {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Ctor.
|
// Default constructor.
|
||||||
Array() : m_buffer(NULL), m_size(0), m_buffer_size(0)
|
NV_FORCEINLINE Array() : Buffer() {}
|
||||||
{
|
|
||||||
|
// Copy constructor.
|
||||||
|
NV_FORCEINLINE Array(const Array & a) : Buffer() {
|
||||||
|
copy(a.buffer(), a.m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copy ctor.
|
// Constructor that initializes the vector with the given elements.
|
||||||
Array( const Array & a ) : m_buffer(NULL), m_size(0), m_buffer_size(0)
|
NV_FORCEINLINE Array(const T * ptr, int num) : Buffer() {
|
||||||
{
|
|
||||||
copy(a.m_buffer, a.m_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ctor that initializes the vector with the given elements.
|
|
||||||
Array( const T * ptr, int num ) : m_buffer(NULL), m_size(0), m_buffer_size(0)
|
|
||||||
{
|
|
||||||
copy(ptr, num);
|
copy(ptr, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocate array.
|
// Allocate array.
|
||||||
explicit Array(uint capacity) : m_buffer(NULL), m_size(0), m_buffer_size(0)
|
NV_FORCEINLINE explicit Array(uint capacity) : Buffer() {
|
||||||
{
|
|
||||||
allocate(capacity);
|
allocate(capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destructor.
|
||||||
/// Dtor.
|
NV_FORCEINLINE ~Array() {
|
||||||
~Array()
|
|
||||||
{
|
|
||||||
clear();
|
clear();
|
||||||
allocate(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -83,24 +164,24 @@ namespace nv
|
|||||||
NV_FORCEINLINE const T & operator[]( uint index ) const
|
NV_FORCEINLINE const T & operator[]( uint index ) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(index < m_size);
|
nvDebugCheck(index < m_size);
|
||||||
return m_buffer[index];
|
return buffer()[index];
|
||||||
}
|
}
|
||||||
NV_FORCEINLINE const T & at( uint index ) const
|
NV_FORCEINLINE const T & at( uint index ) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(index < m_size);
|
nvDebugCheck(index < m_size);
|
||||||
return m_buffer[index];
|
return buffer()[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Element access.
|
/// Element access.
|
||||||
NV_FORCEINLINE T & operator[] ( uint index )
|
NV_FORCEINLINE T & operator[] ( uint index )
|
||||||
{
|
{
|
||||||
nvDebugCheck(index < m_size);
|
nvDebugCheck(index < m_size);
|
||||||
return m_buffer[index];
|
return buffer()[index];
|
||||||
}
|
}
|
||||||
NV_FORCEINLINE T & at( uint index )
|
NV_FORCEINLINE T & at( uint index )
|
||||||
{
|
{
|
||||||
nvDebugCheck(index < m_size);
|
nvDebugCheck(index < m_size);
|
||||||
return m_buffer[index];
|
return buffer()[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get vector size.
|
/// Get vector size.
|
||||||
@ -110,16 +191,16 @@ namespace nv
|
|||||||
NV_FORCEINLINE uint count() const { return m_size; }
|
NV_FORCEINLINE uint count() const { return m_size; }
|
||||||
|
|
||||||
/// Get const vector pointer.
|
/// Get const vector pointer.
|
||||||
NV_FORCEINLINE const T * buffer() const { return m_buffer; }
|
NV_FORCEINLINE const T * buffer() const { return (const T *)m_buffer; }
|
||||||
|
|
||||||
/// Get vector pointer.
|
/// Get vector pointer.
|
||||||
NV_FORCEINLINE T * mutableBuffer() { return m_buffer; }
|
NV_FORCEINLINE T * buffer() { return (T *)m_buffer; }
|
||||||
|
|
||||||
/// Is vector empty.
|
/// Is vector empty.
|
||||||
NV_FORCEINLINE bool isEmpty() const { return m_size == 0; }
|
NV_FORCEINLINE bool isEmpty() const { return m_size == 0; }
|
||||||
|
|
||||||
/// Is a null vector.
|
/// Is a null vector.
|
||||||
NV_FORCEINLINE bool isNull() const { return m_buffer == NULL; }
|
NV_FORCEINLINE bool isNull() const { return m_buffer == NULL; }
|
||||||
|
|
||||||
|
|
||||||
/// Push an element at the end of the vector.
|
/// Push an element at the end of the vector.
|
||||||
@ -131,12 +212,12 @@ namespace nv
|
|||||||
{
|
{
|
||||||
const T copy(val); // create a copy in case value is inside of this array.
|
const T copy(val); // create a copy in case value is inside of this array.
|
||||||
resize(new_size);
|
resize(new_size);
|
||||||
m_buffer[new_size-1] = copy;
|
buffer()[new_size-1] = copy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_size = new_size;
|
m_size = new_size;
|
||||||
new(m_buffer+new_size-1) T(val);
|
new(buffer()+new_size-1) T(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NV_FORCEINLINE void pushBack( const T & val )
|
NV_FORCEINLINE void pushBack( const T & val )
|
||||||
@ -155,8 +236,8 @@ namespace nv
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pop and return element at the end of the vector.
|
/// Pop the element at the end of the vector.
|
||||||
void pop_back()
|
NV_FORCEINLINE void pop_back()
|
||||||
{
|
{
|
||||||
nvDebugCheck( m_size > 0 );
|
nvDebugCheck( m_size > 0 );
|
||||||
resize( m_size - 1 );
|
resize( m_size - 1 );
|
||||||
@ -170,28 +251,28 @@ namespace nv
|
|||||||
NV_FORCEINLINE const T & back() const
|
NV_FORCEINLINE const T & back() const
|
||||||
{
|
{
|
||||||
nvDebugCheck( m_size > 0 );
|
nvDebugCheck( m_size > 0 );
|
||||||
return m_buffer[m_size-1];
|
return buffer()[m_size-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get back element.
|
/// Get back element.
|
||||||
NV_FORCEINLINE T & back()
|
NV_FORCEINLINE T & back()
|
||||||
{
|
{
|
||||||
nvDebugCheck( m_size > 0 );
|
nvDebugCheck( m_size > 0 );
|
||||||
return m_buffer[m_size-1];
|
return buffer()[m_size-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get front element.
|
/// Get front element.
|
||||||
NV_FORCEINLINE const T & front() const
|
NV_FORCEINLINE const T & front() const
|
||||||
{
|
{
|
||||||
nvDebugCheck( m_size > 0 );
|
nvDebugCheck( m_size > 0 );
|
||||||
return m_buffer[0];
|
return buffer()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get front element.
|
/// Get front element.
|
||||||
NV_FORCEINLINE T & front()
|
NV_FORCEINLINE T & front()
|
||||||
{
|
{
|
||||||
nvDebugCheck( m_size > 0 );
|
nvDebugCheck( m_size > 0 );
|
||||||
return m_buffer[0];
|
return buffer()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if element found.
|
/// Return true if element found.
|
||||||
@ -204,7 +285,7 @@ namespace nv
|
|||||||
bool find(const T & element, uint first, uint count, uint * index) const
|
bool find(const T & element, uint first, uint count, uint * index) const
|
||||||
{
|
{
|
||||||
for (uint i = first; i < first+count; i++) {
|
for (uint i = first; i < first+count; i++) {
|
||||||
if (m_buffer[i] == element) {
|
if (buffer()[i] == element) {
|
||||||
if (index != NULL) *index = i;
|
if (index != NULL) *index = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -219,17 +300,17 @@ namespace nv
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the element at the given index. This is an expensive operation!
|
/// Remove the element at the given index. This is an expensive operation!
|
||||||
void removeAt( uint index )
|
void removeAt(uint index)
|
||||||
{
|
{
|
||||||
nvCheck(index >= 0 && index < m_size);
|
nvCheck(index >= 0 && index < m_size);
|
||||||
|
|
||||||
if( m_size == 1 ) {
|
if (m_size == 1) {
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_buffer[index].~T();
|
buffer()[index].~T();
|
||||||
|
|
||||||
memmove( m_buffer+index, m_buffer+index+1, sizeof(T) * (m_size - 1 - index) );
|
memmove(buffer()+index, buffer()+index+1, sizeof(T) * (m_size - 1 - index));
|
||||||
m_size--;
|
m_size--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,35 +327,35 @@ namespace nv
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
void insertAt( uint index, const T & val = T() )
|
void insertAt(uint index, const T & val = T())
|
||||||
{
|
{
|
||||||
nvCheck( index >= 0 && index <= m_size );
|
nvCheck( index >= 0 && index <= m_size );
|
||||||
|
|
||||||
resize( m_size + 1 );
|
resize( m_size + 1 );
|
||||||
|
|
||||||
if( index < m_size - 1 ) {
|
if (index < m_size - 1) {
|
||||||
memmove( m_buffer+index+1, m_buffer+index, sizeof(T) * (m_size - 1 - index) );
|
memmove(buffer()+index+1, buffer()+index, sizeof(T) * (m_size - 1 - index));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy-construct into the newly opened slot.
|
// Copy-construct into the newly opened slot.
|
||||||
new(m_buffer+index) T(val);
|
new(buffer()+index) T(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append the given data to our vector.
|
/// Append the given data to our vector.
|
||||||
NV_FORCEINLINE void append(const Array<T> & other)
|
NV_FORCEINLINE void append(const Array<T> & other)
|
||||||
{
|
{
|
||||||
append(other.m_buffer, other.m_size);
|
append(other.buffer(), other.m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append the given data to our vector.
|
/// Append the given data to our vector.
|
||||||
void append(const T other[], uint count)
|
void append(const T other[], uint count)
|
||||||
{
|
{
|
||||||
if( count > 0 ) {
|
if (count > 0) {
|
||||||
const uint old_size = m_size;
|
const uint old_size = m_size;
|
||||||
resize(m_size + count);
|
resize(m_size + count);
|
||||||
// Must use operator=() to copy elements, in case of side effects (e.g. ref-counting).
|
// Must use operator=() to copy elements, in case of side effects (e.g. ref-counting).
|
||||||
for( uint i = 0; i < count; i++ ) {
|
for (uint i = 0; i < count; i++ ) {
|
||||||
m_buffer[old_size + i] = other[i];
|
buffer()[old_size + i] = other[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,9 +365,8 @@ namespace nv
|
|||||||
void replaceWithLast(uint index)
|
void replaceWithLast(uint index)
|
||||||
{
|
{
|
||||||
nvDebugCheck( index < m_size );
|
nvDebugCheck( index < m_size );
|
||||||
nv::swap(m_buffer[index], back());
|
nv::swap(buffer()[index], back());
|
||||||
//m_buffer[index] = back();
|
(buffer()+m_size-1)->~T();
|
||||||
(m_buffer+m_size-1)->~T();
|
|
||||||
m_size--;
|
m_size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,38 +374,33 @@ namespace nv
|
|||||||
/// Resize the vector preserving existing elements.
|
/// Resize the vector preserving existing elements.
|
||||||
NV_NOINLINE void resize(uint new_size)
|
NV_NOINLINE void resize(uint new_size)
|
||||||
{
|
{
|
||||||
uint i;
|
|
||||||
uint old_size = m_size;
|
uint old_size = m_size;
|
||||||
m_size = new_size;
|
m_size = new_size;
|
||||||
|
|
||||||
|
// @@ Use nv::destruct(...)
|
||||||
// Destruct old elements (if we're shrinking).
|
// Destruct old elements (if we're shrinking).
|
||||||
for( i = new_size; i < old_size; i++ ) {
|
for (uint i = new_size; i < old_size; i++) {
|
||||||
(m_buffer+i)->~T(); // Explicit call to the destructor
|
(buffer()+i)->~T(); // Explicit call to the destructor
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_size == 0 ) {
|
// @@ Move allocation logic to Buffer::allocate
|
||||||
//allocate(0); // Don't shrink automatically.
|
if (new_size > m_buffer_size) {
|
||||||
}
|
|
||||||
else if( m_size <= m_buffer_size/* && m_size > m_buffer_size >> 1*/) {
|
|
||||||
// don't compact yet.
|
|
||||||
nvDebugCheck(m_buffer != NULL);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uint new_buffer_size;
|
uint new_buffer_size;
|
||||||
if( m_buffer_size == 0 ) {
|
if (m_buffer_size == 0) {
|
||||||
// first allocation
|
// first allocation
|
||||||
new_buffer_size = m_size;
|
new_buffer_size = new_size;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// growing
|
// growing
|
||||||
new_buffer_size = m_size + (m_size >> 2);
|
new_buffer_size = new_size + (new_size >> 2);
|
||||||
}
|
}
|
||||||
allocate( new_buffer_size );
|
allocate( new_buffer_size );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @@ Use nv::construct(...)
|
||||||
// Call default constructors
|
// Call default constructors
|
||||||
for( i = old_size; i < new_size; i++ ) {
|
for (uint i = old_size; i < new_size; i++) {
|
||||||
new(m_buffer+i) T; // placement new
|
new(buffer()+i) T; // placement new
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,24 +409,19 @@ namespace nv
|
|||||||
/// new ones with the given value.
|
/// new ones with the given value.
|
||||||
NV_NOINLINE void resize( uint new_size, const T &elem )
|
NV_NOINLINE void resize( uint new_size, const T &elem )
|
||||||
{
|
{
|
||||||
uint i;
|
|
||||||
uint old_size = m_size;
|
uint old_size = m_size;
|
||||||
m_size = new_size;
|
m_size = new_size;
|
||||||
|
|
||||||
|
// @@ Use nv::destruct(...)
|
||||||
// Destruct old elements (if we're shrinking).
|
// Destruct old elements (if we're shrinking).
|
||||||
for( i = new_size; i < old_size; i++ ) {
|
for (uint i = new_size; i < old_size; i++ ) {
|
||||||
(m_buffer+i)->~T(); // Explicit call to the destructor
|
(buffer()+i)->~T(); // Explicit call to the destructor
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_size == 0 ) {
|
// @@ Move allocation logic to Buffer::allocate
|
||||||
//allocate(0); // Don't shrink automatically.
|
if (new_size > m_buffer_size) {
|
||||||
}
|
|
||||||
else if( m_size <= m_buffer_size && m_size > m_buffer_size >> 1 ) {
|
|
||||||
// don't compact yet.
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uint new_buffer_size;
|
uint new_buffer_size;
|
||||||
if( m_buffer_size == 0 ) {
|
if (m_buffer_size == 0) {
|
||||||
// first allocation
|
// first allocation
|
||||||
new_buffer_size = m_size;
|
new_buffer_size = m_size;
|
||||||
}
|
}
|
||||||
@ -362,9 +432,10 @@ namespace nv
|
|||||||
allocate( new_buffer_size );
|
allocate( new_buffer_size );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @@ Use nv::fill(...)
|
||||||
// Call copy constructors
|
// Call copy constructors
|
||||||
for( i = old_size; i < new_size; i++ ) {
|
for (uint i = old_size; i < new_size; i++ ) {
|
||||||
new(m_buffer+i) T( elem ); // placement new
|
new(buffer()+i) T( elem ); // placement new
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,39 +457,37 @@ namespace nv
|
|||||||
NV_FORCEINLINE void reserve(uint desired_size)
|
NV_FORCEINLINE void reserve(uint desired_size)
|
||||||
{
|
{
|
||||||
if (desired_size > m_buffer_size) {
|
if (desired_size > m_buffer_size) {
|
||||||
allocate( desired_size );
|
allocate(desired_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copy elements to this array. Resizes it if needed.
|
/// Copy elements to this array. Resizes it if needed.
|
||||||
void copy(const T * ptr, uint num)
|
NV_FORCEINLINE void copy(const T * ptr, uint num)
|
||||||
{
|
{
|
||||||
resize( num );
|
resize( num );
|
||||||
for (uint i = 0; i < m_size; i++) {
|
::nv::copy(buffer(), ptr, num);
|
||||||
m_buffer[i] = ptr[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assignment operator.
|
/// Assignment operator.
|
||||||
NV_FORCEINLINE Array<T> & operator=( const Array<T> & a )
|
NV_FORCEINLINE Array<T> & operator=( const Array<T> & a )
|
||||||
{
|
{
|
||||||
copy(a.m_buffer, a.m_size);
|
copy(a.buffer(), a.m_size);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release ownership of allocated memory and returns pointer to it.
|
// Release ownership of allocated memory and returns pointer to it.
|
||||||
T * release() {
|
T * release() {
|
||||||
T * tmp = m_buffer;
|
T * tmp = buffer();
|
||||||
m_buffer = NULL;
|
m_buffer = NULL;
|
||||||
m_size = 0;
|
|
||||||
m_buffer_size = 0;
|
m_buffer_size = 0;
|
||||||
|
m_size = 0;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Array serialization.
|
/// Array serialization.
|
||||||
friend Stream & operator<< ( Stream & s, Array<T> & p )
|
friend Stream & operator<< ( Stream & s, Array<T> & p )
|
||||||
{
|
{
|
||||||
if( s.isLoading() ) {
|
if (s.isLoading()) {
|
||||||
uint size;
|
uint size;
|
||||||
s << size;
|
s << size;
|
||||||
p.resize( size );
|
p.resize( size );
|
||||||
@ -427,8 +496,8 @@ namespace nv
|
|||||||
s << p.m_size;
|
s << p.m_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( uint i = 0; i < p.m_size; i++ ) {
|
for (uint i = 0; i < p.m_size; i++) {
|
||||||
s << p.m_buffer[i];
|
s << buffer()[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@ -439,54 +508,24 @@ namespace nv
|
|||||||
typedef uint PseudoIndex;
|
typedef uint PseudoIndex;
|
||||||
|
|
||||||
NV_FORCEINLINE PseudoIndex start() const { return 0; }
|
NV_FORCEINLINE PseudoIndex start() const { return 0; }
|
||||||
NV_FORCEINLINE bool isDone(const PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); return i == this->m_size; };
|
NV_FORCEINLINE bool isDone(const PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); return i == this->m_size; }
|
||||||
NV_FORCEINLINE void advance(PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); i++; }
|
NV_FORCEINLINE void advance(PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); i++; }
|
||||||
|
|
||||||
#if NV_CC_MSVC
|
#if NV_CC_MSVC
|
||||||
NV_FORCEINLINE T & operator[]( const PseudoIndexWrapper & i ) {
|
NV_FORCEINLINE T & operator[]( const PseudoIndexWrapper & i ) {
|
||||||
return m_buffer[i(this)];
|
return at(i(this));
|
||||||
}
|
}
|
||||||
NV_FORCEINLINE const T & operator[]( const PseudoIndexWrapper & i ) const {
|
NV_FORCEINLINE const T & operator[]( const PseudoIndexWrapper & i ) const {
|
||||||
return m_buffer[i(this)];
|
return at(i(this));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
/// Swap the members of this vector and the given vector.
|
NV_FORCEINLINE void allocate(uint count) {
|
||||||
friend void swap(Array<T> & a, Array<T> & b)
|
Buffer::allocate(count, sizeof(T));
|
||||||
{
|
|
||||||
swap(a.m_buffer, b.m_buffer);
|
|
||||||
swap(a.m_size, b.m_size);
|
|
||||||
swap(a.m_buffer_size, b.m_buffer_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
/// Change buffer size.
|
|
||||||
NV_NOINLINE void allocate( uint rsize )
|
|
||||||
{
|
|
||||||
m_buffer_size = rsize;
|
|
||||||
|
|
||||||
// free the buffer.
|
|
||||||
if (m_buffer_size == 0) {
|
|
||||||
if (m_buffer) {
|
|
||||||
free( m_buffer );
|
|
||||||
m_buffer = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// realloc the buffer
|
|
||||||
else {
|
|
||||||
m_buffer = realloc<T>(m_buffer, m_buffer_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
T * m_buffer;
|
|
||||||
uint m_size;
|
|
||||||
uint m_buffer_size;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // nv namespace
|
} // nv namespace
|
||||||
|
@ -9,8 +9,8 @@ SET(CORE_SRCS
|
|||||||
DefsGnucWin32.h
|
DefsGnucWin32.h
|
||||||
DefsVcWin32.h
|
DefsVcWin32.h
|
||||||
FileSystem.h FileSystem.cpp
|
FileSystem.h FileSystem.cpp
|
||||||
ForEach.h
|
ForEach.h
|
||||||
HashMap.h
|
HashMap.h
|
||||||
Library.h Library.cpp
|
Library.h Library.cpp
|
||||||
Memory.h Memory.cpp
|
Memory.h Memory.cpp
|
||||||
Ptr.h
|
Ptr.h
|
||||||
|
@ -48,7 +48,7 @@ const char * TextReader::readToEnd()
|
|||||||
m_text.reserve(size + 1);
|
m_text.reserve(size + 1);
|
||||||
m_text.resize(size);
|
m_text.resize(size);
|
||||||
|
|
||||||
m_stream->serialize(m_text.mutableBuffer(), size);
|
m_stream->serialize(m_text.buffer(), size);
|
||||||
m_text.pushBack('\0');
|
m_text.pushBack('\0');
|
||||||
|
|
||||||
return m_text.buffer();
|
return m_text.buffer();
|
||||||
|
@ -667,7 +667,7 @@ FloatImage * FloatImage::resize(const Filter & filter, uint w, uint h, WrapMode
|
|||||||
float * dst_channel = dst_image->channel(c);
|
float * dst_channel = dst_image->channel(c);
|
||||||
|
|
||||||
for (uint x = 0; x < w; x++) {
|
for (uint x = 0; x < w; x++) {
|
||||||
tmp_image->applyKernelVertical(ykernel, x, c, wm, tmp_column.mutableBuffer());
|
tmp_image->applyKernelVertical(ykernel, x, c, wm, tmp_column.buffer());
|
||||||
|
|
||||||
for (uint y = 0; y < h; y++) {
|
for (uint y = 0; y < h; y++) {
|
||||||
dst_channel[y * w + x] = tmp_column[y];
|
dst_channel[y * w + x] = tmp_column[y];
|
||||||
@ -741,7 +741,7 @@ FloatImage * FloatImage::resize(const Filter & filter, uint w, uint h, WrapMode
|
|||||||
float * dst_channel = dst_image->channel(c);
|
float * dst_channel = dst_image->channel(c);
|
||||||
|
|
||||||
for (uint x = 0; x < w; x++) {
|
for (uint x = 0; x < w; x++) {
|
||||||
tmp_image->applyKernelVertical(ykernel, x, c, wm, tmp_column.mutableBuffer());
|
tmp_image->applyKernelVertical(ykernel, x, c, wm, tmp_column.buffer());
|
||||||
|
|
||||||
for (uint y = 0; y < h; y++) {
|
for (uint y = 0; y < h; y++) {
|
||||||
dst_channel[y * w + x] = tmp_column[y];
|
dst_channel[y * w + x] = tmp_column[y];
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user