Fix build errors.
This commit is contained in:
parent
f68d894b8b
commit
504ecc8e10
@ -1,385 +1,385 @@
|
|||||||
// This code is in the public domain -- Ignacio Castaño <castano@gmail.com>
|
// This code is in the public domain -- Ignacio Castaño <castano@gmail.com>
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef NV_CORE_H
|
#ifndef NV_CORE_H
|
||||||
#define NV_CORE_H
|
#define NV_CORE_H
|
||||||
|
|
||||||
// Function linkage
|
// Function linkage
|
||||||
#if NVCORE_SHARED
|
#if NVCORE_SHARED
|
||||||
#ifdef NVCORE_EXPORTS
|
#ifdef NVCORE_EXPORTS
|
||||||
#define NVCORE_API DLL_EXPORT
|
#define NVCORE_API DLL_EXPORT
|
||||||
#define NVCORE_CLASS DLL_EXPORT_CLASS
|
#define NVCORE_CLASS DLL_EXPORT_CLASS
|
||||||
#else
|
#else
|
||||||
#define NVCORE_API DLL_IMPORT
|
#define NVCORE_API DLL_IMPORT
|
||||||
#define NVCORE_CLASS DLL_IMPORT
|
#define NVCORE_CLASS DLL_IMPORT
|
||||||
#endif
|
#endif
|
||||||
#else // NVCORE_SHARED
|
#else // NVCORE_SHARED
|
||||||
#define NVCORE_API
|
#define NVCORE_API
|
||||||
#define NVCORE_CLASS
|
#define NVCORE_CLASS
|
||||||
#endif // NVCORE_SHARED
|
#endif // NVCORE_SHARED
|
||||||
|
|
||||||
|
|
||||||
// Platform definitions
|
// Platform definitions
|
||||||
#include <posh.h>
|
#include <posh.h>
|
||||||
|
|
||||||
// OS:
|
// OS:
|
||||||
// NV_OS_WIN32
|
// NV_OS_WIN32
|
||||||
// NV_OS_WIN64
|
// NV_OS_WIN64
|
||||||
// NV_OS_MINGW
|
// NV_OS_MINGW
|
||||||
// NV_OS_CYGWIN
|
// NV_OS_CYGWIN
|
||||||
// NV_OS_LINUX
|
// NV_OS_LINUX
|
||||||
// NV_OS_UNIX
|
// NV_OS_UNIX
|
||||||
// NV_OS_DARWIN
|
// NV_OS_DARWIN
|
||||||
// NV_OS_XBOX
|
// NV_OS_XBOX
|
||||||
// NV_OS_ORBIS
|
// NV_OS_ORBIS
|
||||||
// NV_OS_IOS
|
// NV_OS_IOS
|
||||||
|
|
||||||
#define NV_OS_STRING POSH_OS_STRING
|
#define NV_OS_STRING POSH_OS_STRING
|
||||||
|
|
||||||
#if defined POSH_OS_LINUX
|
#if defined POSH_OS_LINUX
|
||||||
# define NV_OS_LINUX 1
|
# define NV_OS_LINUX 1
|
||||||
# define NV_OS_UNIX 1
|
# define NV_OS_UNIX 1
|
||||||
#elif defined POSH_OS_ORBIS
|
#elif defined POSH_OS_ORBIS
|
||||||
# define NV_OS_ORBIS 1
|
# define NV_OS_ORBIS 1
|
||||||
#elif defined POSH_OS_FREEBSD
|
#elif defined POSH_OS_FREEBSD
|
||||||
# define NV_OS_FREEBSD 1
|
# define NV_OS_FREEBSD 1
|
||||||
# define NV_OS_UNIX 1
|
# define NV_OS_UNIX 1
|
||||||
#elif defined POSH_OS_NETBSD
|
#elif defined POSH_OS_NETBSD
|
||||||
# define NV_OS_NETBSD 1
|
# define NV_OS_NETBSD 1
|
||||||
# define NV_OS_UNIX 1
|
# define NV_OS_UNIX 1
|
||||||
#elif defined POSH_OS_OPENBSD
|
#elif defined POSH_OS_OPENBSD
|
||||||
# define NV_OS_OPENBSD 1
|
# define NV_OS_OPENBSD 1
|
||||||
# define NV_OS_UNIX 1
|
# define NV_OS_UNIX 1
|
||||||
#elif defined POSH_OS_CYGWIN32
|
#elif defined POSH_OS_CYGWIN32
|
||||||
# define NV_OS_CYGWIN 1
|
# define NV_OS_CYGWIN 1
|
||||||
#elif defined POSH_OS_MINGW
|
#elif defined POSH_OS_MINGW
|
||||||
# define NV_OS_MINGW 1
|
# define NV_OS_MINGW 1
|
||||||
# define NV_OS_WIN32 1
|
# define NV_OS_WIN32 1
|
||||||
#elif defined POSH_OS_OSX
|
#elif defined POSH_OS_OSX
|
||||||
# define NV_OS_OSX 1 // IC: Adding this, because iOS defines NV_OS_DARWIN too.
|
# define NV_OS_OSX 1 // IC: Adding this, because iOS defines NV_OS_DARWIN too.
|
||||||
# define NV_OS_DARWIN 1
|
# define NV_OS_DARWIN 1
|
||||||
# define NV_OS_UNIX 1
|
# define NV_OS_UNIX 1
|
||||||
#elif defined POSH_OS_IOS
|
#elif defined POSH_OS_IOS
|
||||||
# define NV_OS_DARWIN 1 //ACS should we keep this on IOS?
|
# define NV_OS_DARWIN 1 //ACS should we keep this on IOS?
|
||||||
# define NV_OS_UNIX 1
|
# define NV_OS_UNIX 1
|
||||||
# define NV_OS_IOS 1
|
# define NV_OS_IOS 1
|
||||||
#elif defined POSH_OS_UNIX
|
#elif defined POSH_OS_UNIX
|
||||||
# define NV_OS_UNIX 1
|
# define NV_OS_UNIX 1
|
||||||
#elif defined POSH_OS_WIN64
|
#elif defined POSH_OS_WIN64
|
||||||
# define NV_OS_WIN32 1
|
# define NV_OS_WIN32 1
|
||||||
# define NV_OS_WIN64 1
|
# define NV_OS_WIN64 1
|
||||||
#elif defined POSH_OS_WIN32
|
#elif defined POSH_OS_WIN32
|
||||||
# define NV_OS_WIN32 1
|
# define NV_OS_WIN32 1
|
||||||
#elif defined POSH_OS_XBOX
|
#elif defined POSH_OS_XBOX
|
||||||
# define NV_OS_XBOX 1
|
# define NV_OS_XBOX 1
|
||||||
#else
|
#else
|
||||||
# error "Unsupported OS"
|
# error "Unsupported OS"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Threading:
|
// Threading:
|
||||||
// some platforms don't implement __thread or similar for thread-local-storage
|
// some platforms don't implement __thread or similar for thread-local-storage
|
||||||
#if NV_OS_UNIX || NV_OS_ORBIS || NV_OS_IOS
|
#if NV_OS_UNIX || NV_OS_ORBIS || NV_OS_IOS
|
||||||
# define NV_OS_USE_PTHREAD 1
|
# define NV_OS_USE_PTHREAD 1
|
||||||
# if 0 //Apple finally added TLS support to iOS!// NV_OS_IOS
|
# if 0 //Apple finally added TLS support to iOS!// NV_OS_IOS
|
||||||
# define NV_OS_HAS_TLS_QUALIFIER 0
|
# define NV_OS_HAS_TLS_QUALIFIER 0
|
||||||
# else
|
# else
|
||||||
# define NV_OS_HAS_TLS_QUALIFIER 1
|
# define NV_OS_HAS_TLS_QUALIFIER 1
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
# define NV_OS_USE_PTHREAD 0
|
# define NV_OS_USE_PTHREAD 0
|
||||||
# define NV_OS_HAS_TLS_QUALIFIER 1
|
# define NV_OS_HAS_TLS_QUALIFIER 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// CPUs:
|
// CPUs:
|
||||||
// NV_CPU_X86
|
// NV_CPU_X86
|
||||||
// NV_CPU_X86_64
|
// NV_CPU_X86_64
|
||||||
// NV_CPU_PPC
|
// NV_CPU_PPC
|
||||||
// NV_CPU_ARM
|
// NV_CPU_ARM
|
||||||
// NV_CPU_ARM_64
|
// NV_CPU_ARM_64
|
||||||
// NV_CPU_E2K
|
// NV_CPU_E2K
|
||||||
|
|
||||||
#define NV_CPU_STRING POSH_CPU_STRING
|
#define NV_CPU_STRING POSH_CPU_STRING
|
||||||
|
|
||||||
#if defined POSH_CPU_X86_64
|
#if defined POSH_CPU_X86_64
|
||||||
//# define NV_CPU_X86 1
|
//# define NV_CPU_X86 1
|
||||||
# define NV_CPU_X86_64 1
|
# define NV_CPU_X86_64 1
|
||||||
#elif defined POSH_CPU_X86
|
#elif defined POSH_CPU_X86
|
||||||
# define NV_CPU_X86 1
|
# define NV_CPU_X86 1
|
||||||
#elif defined POSH_CPU_PPC
|
#elif defined POSH_CPU_PPC
|
||||||
# define NV_CPU_PPC 1
|
# define NV_CPU_PPC 1
|
||||||
#elif defined POSH_CPU_STRONGARM
|
#elif defined POSH_CPU_STRONGARM
|
||||||
# define NV_CPU_ARM 1
|
# define NV_CPU_ARM 1
|
||||||
#elif defined POSH_CPU_AARCH64
|
#elif defined POSH_CPU_AARCH64
|
||||||
# define NV_CPU_ARM_64 1
|
# define NV_CPU_ARM_64 1
|
||||||
#elif defined POSH_CPU_E2K
|
#elif defined POSH_CPU_E2K
|
||||||
# define NV_CPU_E2K 1
|
# define NV_CPU_E2K 1
|
||||||
#else
|
#else
|
||||||
# error "Unsupported CPU"
|
# error "Unsupported CPU"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Compiler:
|
// Compiler:
|
||||||
// NV_CC_GNUC
|
// NV_CC_GNUC
|
||||||
// NV_CC_MSVC
|
// NV_CC_MSVC
|
||||||
// NV_CC_CLANG
|
// NV_CC_CLANG
|
||||||
|
|
||||||
#if defined POSH_COMPILER_CLANG
|
#if defined POSH_COMPILER_CLANG
|
||||||
# define NV_CC_CLANG 1
|
# define NV_CC_CLANG 1
|
||||||
# define NV_CC_GNUC 1 // Clang is compatible with GCC.
|
# define NV_CC_GNUC 1 // Clang is compatible with GCC.
|
||||||
# define NV_CC_STRING "clang"
|
# define NV_CC_STRING "clang"
|
||||||
#elif defined POSH_COMPILER_GCC
|
#elif defined POSH_COMPILER_GCC
|
||||||
# define NV_CC_GNUC 1
|
# define NV_CC_GNUC 1
|
||||||
# define NV_CC_STRING "gcc"
|
# define NV_CC_STRING "gcc"
|
||||||
#elif defined POSH_COMPILER_MSVC
|
#elif defined POSH_COMPILER_MSVC
|
||||||
# define NV_CC_MSVC 1
|
# define NV_CC_MSVC 1
|
||||||
# define NV_CC_STRING "msvc"
|
# define NV_CC_STRING "msvc"
|
||||||
#else
|
#else
|
||||||
# error "Unsupported compiler"
|
# error "Unsupported compiler"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NV_CC_MSVC
|
#if NV_CC_MSVC
|
||||||
#define NV_CC_CPP11 (__cplusplus > 199711L || _MSC_VER >= 1800) // Visual Studio 2013 has all the features we use, but doesn't advertise full C++11 support yet.
|
#define NV_CC_CPP11 (__cplusplus > 199711L || _MSC_VER >= 1800) // Visual Studio 2013 has all the features we use, but doesn't advertise full C++11 support yet.
|
||||||
#else
|
#else
|
||||||
// @@ IC: This works in CLANG, about GCC?
|
// @@ IC: This works in CLANG, about GCC?
|
||||||
// @@ ES: Doesn't work in gcc. These 3 features are available in GCC >= 4.4.
|
// @@ ES: Doesn't work in gcc. These 3 features are available in GCC >= 4.4.
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#define NV_CC_CPP11 (__has_feature(cxx_deleted_functions) && __has_feature(cxx_rvalue_references) && __has_feature(cxx_static_assert))
|
#define NV_CC_CPP11 (__has_feature(cxx_deleted_functions) && __has_feature(cxx_rvalue_references) && __has_feature(cxx_static_assert))
|
||||||
#elif defined __GNUC__
|
#elif defined __GNUC__
|
||||||
#define NV_CC_CPP11 ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
|
#define NV_CC_CPP11 ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Endiannes:
|
// Endiannes:
|
||||||
// @@ POSH endian detection is broken for arm64 on iOS. They are bi-endian and iOS sets all their processors to little endian by default.
|
// @@ POSH endian detection is broken for arm64 on iOS. They are bi-endian and iOS sets all their processors to little endian by default.
|
||||||
#if NV_OS_IOS
|
#if NV_OS_IOS
|
||||||
# define NV_LITTLE_ENDIAN 1
|
# define NV_LITTLE_ENDIAN 1
|
||||||
# define NV_BIG_ENDIAN 0
|
# define NV_BIG_ENDIAN 0
|
||||||
# define NV_ENDIAN_STRING "little"
|
# define NV_ENDIAN_STRING "little"
|
||||||
#else
|
#else
|
||||||
# define NV_LITTLE_ENDIAN POSH_LITTLE_ENDIAN
|
# define NV_LITTLE_ENDIAN POSH_LITTLE_ENDIAN
|
||||||
# define NV_BIG_ENDIAN POSH_BIG_ENDIAN
|
# define NV_BIG_ENDIAN POSH_BIG_ENDIAN
|
||||||
# define NV_ENDIAN_STRING POSH_ENDIAN_STRING
|
# define NV_ENDIAN_STRING POSH_ENDIAN_STRING
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Define the right printf prefix for size_t arguments:
|
// Define the right printf prefix for size_t arguments:
|
||||||
#if POSH_64BIT_POINTER
|
#if POSH_64BIT_POINTER
|
||||||
# define NV_SIZET_PRINTF_PREFIX POSH_I64_PRINTF_PREFIX
|
# define NV_SIZET_PRINTF_PREFIX POSH_I64_PRINTF_PREFIX
|
||||||
#else
|
#else
|
||||||
# define NV_SIZET_PRINTF_PREFIX
|
# define NV_SIZET_PRINTF_PREFIX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// cmake config
|
// cmake config
|
||||||
#include "nvconfig.h"
|
#include "nvconfig.h"
|
||||||
|
|
||||||
#if NV_OS_DARWIN
|
#if NV_OS_DARWIN
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
//#include <inttypes.h>
|
//#include <inttypes.h>
|
||||||
|
|
||||||
// Type definitions:
|
// Type definitions:
|
||||||
typedef uint8_t uint8;
|
typedef uint8_t uint8;
|
||||||
typedef int8_t int8;
|
typedef int8_t int8;
|
||||||
|
|
||||||
typedef uint16_t uint16;
|
typedef uint16_t uint16;
|
||||||
typedef int16_t int16;
|
typedef int16_t int16;
|
||||||
|
|
||||||
typedef uint32_t uint32;
|
typedef uint32_t uint32;
|
||||||
typedef int32_t int32;
|
typedef int32_t int32;
|
||||||
|
|
||||||
typedef uint64_t uint64;
|
typedef uint64_t uint64;
|
||||||
typedef int64_t int64;
|
typedef int64_t int64;
|
||||||
|
|
||||||
// POSH gets this wrong due to __LP64__
|
// POSH gets this wrong due to __LP64__
|
||||||
#undef POSH_I64_PRINTF_PREFIX
|
#undef POSH_I64_PRINTF_PREFIX
|
||||||
#define POSH_I64_PRINTF_PREFIX "ll"
|
#define POSH_I64_PRINTF_PREFIX "ll"
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Type definitions:
|
// Type definitions:
|
||||||
typedef posh_u8_t uint8;
|
typedef posh_u8_t uint8;
|
||||||
typedef posh_i8_t int8;
|
typedef posh_i8_t int8;
|
||||||
|
|
||||||
typedef posh_u16_t uint16;
|
typedef posh_u16_t uint16;
|
||||||
typedef posh_i16_t int16;
|
typedef posh_i16_t int16;
|
||||||
|
|
||||||
typedef posh_u32_t uint32;
|
typedef posh_u32_t uint32;
|
||||||
typedef posh_i32_t int32;
|
typedef posh_i32_t int32;
|
||||||
|
|
||||||
//#if NV_OS_DARWIN
|
//#if NV_OS_DARWIN
|
||||||
// OSX-64 is supposed to be LP64 (longs and pointers are 64 bits), thus uint64 is defined as
|
// OSX-64 is supposed to be LP64 (longs and pointers are 64 bits), thus uint64 is defined as
|
||||||
// unsigned long. However, some OSX headers define it as unsigned long long, producing errors,
|
// unsigned long. However, some OSX headers define it as unsigned long long, producing errors,
|
||||||
// even though both types are 64 bit. Ideally posh should handle that, but it has not been
|
// even though both types are 64 bit. Ideally posh should handle that, but it has not been
|
||||||
// updated in ages, so here I'm just falling back to the standard C99 types defined in inttypes.h
|
// updated in ages, so here I'm just falling back to the standard C99 types defined in inttypes.h
|
||||||
//#include <inttypes.h>
|
//#include <inttypes.h>
|
||||||
//typedef posh_u64_t uint64_t;
|
//typedef posh_u64_t uint64_t;
|
||||||
//typedef posh_i64_t int64_t;
|
//typedef posh_i64_t int64_t;
|
||||||
//#else
|
//#else
|
||||||
typedef posh_u64_t uint64;
|
typedef posh_u64_t uint64;
|
||||||
typedef posh_i64_t int64;
|
typedef posh_i64_t int64;
|
||||||
//#endif
|
//#endif
|
||||||
#if NV_OS_DARWIN
|
#if NV_OS_DARWIN
|
||||||
// To avoid duplicate definitions.
|
// To avoid duplicate definitions.
|
||||||
#define _UINT64
|
#define _UINT64
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Aliases
|
// Aliases
|
||||||
typedef uint32 uint;
|
typedef uint32 uint;
|
||||||
|
|
||||||
|
|
||||||
// Version string:
|
// Version string:
|
||||||
#define NV_VERSION_STRING \
|
#define NV_VERSION_STRING \
|
||||||
NV_OS_STRING "/" NV_CC_STRING "/" NV_CPU_STRING"/" \
|
NV_OS_STRING "/" NV_CC_STRING "/" NV_CPU_STRING"/" \
|
||||||
NV_ENDIAN_STRING"-endian - " __DATE__ "-" __TIME__
|
NV_ENDIAN_STRING"-endian - " __DATE__ "-" __TIME__
|
||||||
|
|
||||||
|
|
||||||
// Disable copy constructor and assignment operator.
|
// Disable copy constructor and assignment operator.
|
||||||
#if NV_CC_CPP11
|
#if NV_CC_CPP11
|
||||||
#define NV_FORBID_COPY(C) \
|
#define NV_FORBID_COPY(C) \
|
||||||
C( const C & ) = delete; \
|
C( const C & ) = delete; \
|
||||||
C &operator=( const C & ) = delete
|
C &operator=( const C & ) = delete
|
||||||
#else
|
#else
|
||||||
#define NV_FORBID_COPY(C) \
|
#define NV_FORBID_COPY(C) \
|
||||||
private: \
|
private: \
|
||||||
C( const C & ); \
|
C( const C & ); \
|
||||||
C &operator=( const C & )
|
C &operator=( const C & )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Disable dynamic allocation on the heap.
|
// Disable dynamic allocation on the heap.
|
||||||
// See Prohibiting Heap-Based Objects in More Effective C++.
|
// See Prohibiting Heap-Based Objects in More Effective C++.
|
||||||
#define NV_FORBID_HEAPALLOC() \
|
#define NV_FORBID_HEAPALLOC() \
|
||||||
private: \
|
private: \
|
||||||
void *operator new(size_t size); \
|
void *operator new(size_t size); \
|
||||||
void *operator new[](size_t size)
|
void *operator new[](size_t size)
|
||||||
//static void *operator new(size_t size); \
|
//static void *operator new(size_t size); \
|
||||||
//static void *operator new[](size_t size);
|
//static void *operator new[](size_t size);
|
||||||
|
|
||||||
// String concatenation macros.
|
// String concatenation macros.
|
||||||
#define NV_STRING_JOIN2(arg1, arg2) NV_DO_STRING_JOIN2(arg1, arg2)
|
#define NV_STRING_JOIN2(arg1, arg2) NV_DO_STRING_JOIN2(arg1, arg2)
|
||||||
#define NV_DO_STRING_JOIN2(arg1, arg2) arg1 ## arg2
|
#define NV_DO_STRING_JOIN2(arg1, arg2) arg1 ## arg2
|
||||||
#define NV_STRING_JOIN3(arg1, arg2, arg3) NV_DO_STRING_JOIN3(arg1, arg2, arg3)
|
#define NV_STRING_JOIN3(arg1, arg2, arg3) NV_DO_STRING_JOIN3(arg1, arg2, arg3)
|
||||||
#define NV_DO_STRING_JOIN3(arg1, arg2, arg3) arg1 ## arg2 ## arg3
|
#define NV_DO_STRING_JOIN3(arg1, arg2, arg3) arg1 ## arg2 ## arg3
|
||||||
#define NV_STRING2(x) #x
|
#define NV_STRING2(x) #x
|
||||||
#define NV_STRING(x) NV_STRING2(x)
|
#define NV_STRING(x) NV_STRING2(x)
|
||||||
|
|
||||||
#if NV_CC_MSVC
|
#if NV_CC_MSVC
|
||||||
#define NV_MULTI_LINE_MACRO_BEGIN do {
|
#define NV_MULTI_LINE_MACRO_BEGIN do {
|
||||||
#define NV_MULTI_LINE_MACRO_END \
|
#define NV_MULTI_LINE_MACRO_END \
|
||||||
__pragma(warning(push)) \
|
__pragma(warning(push)) \
|
||||||
__pragma(warning(disable:4127)) \
|
__pragma(warning(disable:4127)) \
|
||||||
} while(false) \
|
} while(false) \
|
||||||
__pragma(warning(pop))
|
__pragma(warning(pop))
|
||||||
#else
|
#else
|
||||||
#define NV_MULTI_LINE_MACRO_BEGIN do {
|
#define NV_MULTI_LINE_MACRO_BEGIN do {
|
||||||
#define NV_MULTI_LINE_MACRO_END } while(false)
|
#define NV_MULTI_LINE_MACRO_END } while(false)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NV_CC_CPP11
|
#if NV_CC_CPP11
|
||||||
#define nvStaticCheck(x) static_assert((x), "Static assert "#x" failed")
|
#define nvStaticCheck(x) static_assert((x), "Static assert "#x" failed")
|
||||||
#else
|
#else
|
||||||
#define nvStaticCheck(x) typedef char NV_STRING_JOIN2(__static_assert_,__LINE__)[(x)]
|
#define nvStaticCheck(x) typedef char NV_STRING_JOIN2(__static_assert_,__LINE__)[(x)]
|
||||||
#endif
|
#endif
|
||||||
#define NV_COMPILER_CHECK(x) nvStaticCheck(x) // I like this name best.
|
#define NV_COMPILER_CHECK(x) nvStaticCheck(x) // I like this name best.
|
||||||
|
|
||||||
// Make sure type definitions are fine.
|
// Make sure type definitions are fine.
|
||||||
NV_COMPILER_CHECK(sizeof(int8) == 1);
|
NV_COMPILER_CHECK(sizeof(int8) == 1);
|
||||||
NV_COMPILER_CHECK(sizeof(uint8) == 1);
|
NV_COMPILER_CHECK(sizeof(uint8) == 1);
|
||||||
NV_COMPILER_CHECK(sizeof(int16) == 2);
|
NV_COMPILER_CHECK(sizeof(int16) == 2);
|
||||||
NV_COMPILER_CHECK(sizeof(uint16) == 2);
|
NV_COMPILER_CHECK(sizeof(uint16) == 2);
|
||||||
NV_COMPILER_CHECK(sizeof(int32) == 4);
|
NV_COMPILER_CHECK(sizeof(int32) == 4);
|
||||||
NV_COMPILER_CHECK(sizeof(uint32) == 4);
|
NV_COMPILER_CHECK(sizeof(uint32) == 4);
|
||||||
NV_COMPILER_CHECK(sizeof(int32) == 4);
|
NV_COMPILER_CHECK(sizeof(int32) == 4);
|
||||||
NV_COMPILER_CHECK(sizeof(uint32) == 4);
|
NV_COMPILER_CHECK(sizeof(uint32) == 4);
|
||||||
|
|
||||||
#include <stddef.h> // for size_t
|
#include <stddef.h> // for size_t
|
||||||
template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N];
|
template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N];
|
||||||
#define NV_ARRAY_SIZE(x) sizeof(ArraySizeHelper(x))
|
#define NV_ARRAY_SIZE(x) sizeof(ArraySizeHelper(x))
|
||||||
//#define NV_ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
|
//#define NV_ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
|
||||||
|
|
||||||
#if 0 // Disabled in The Witness.
|
#if 0 // Disabled in The Witness.
|
||||||
#if NV_CC_MSVC
|
#if NV_CC_MSVC
|
||||||
#define NV_MESSAGE(x) message(__FILE__ "(" NV_STRING(__LINE__) ") : " x)
|
#define NV_MESSAGE(x) message(__FILE__ "(" NV_STRING(__LINE__) ") : " x)
|
||||||
#else
|
#else
|
||||||
#define NV_MESSAGE(x) message(x)
|
#define NV_MESSAGE(x) message(x)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define NV_MESSAGE(x)
|
#define NV_MESSAGE(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Startup initialization macro.
|
// Startup initialization macro.
|
||||||
#define NV_AT_STARTUP(some_code) \
|
#define NV_AT_STARTUP(some_code) \
|
||||||
namespace { \
|
namespace { \
|
||||||
static struct NV_STRING_JOIN2(AtStartup_, __LINE__) { \
|
static struct NV_STRING_JOIN2(AtStartup_, __LINE__) { \
|
||||||
NV_STRING_JOIN2(AtStartup_, __LINE__)() { some_code; } \
|
NV_STRING_JOIN2(AtStartup_, __LINE__)() { some_code; } \
|
||||||
} \
|
} \
|
||||||
NV_STRING_JOIN3(AtStartup_, __LINE__, Instance); \
|
NV_STRING_JOIN3(AtStartup_, __LINE__, Instance); \
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace nv {
|
namespace nv {
|
||||||
template <typename F>
|
template <typename F>
|
||||||
struct ScopeExit {
|
struct ScopeExit {
|
||||||
ScopeExit(F f) : f(f) {}
|
ScopeExit(F f) : f(f) {}
|
||||||
~ScopeExit() { f(); }
|
~ScopeExit() { f(); }
|
||||||
F f;
|
F f;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExitScopeHelp {
|
struct ExitScopeHelp {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ScopeExit<T> operator+(T t) { return t; }
|
ScopeExit<T> operator+(T t) { return t; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#define defer const auto& __attribute__((unused)) NV_STRING_JOIN2(defer__, __LINE__) = nv::ExitScopeHelp() + [&]()
|
#define defer const auto& __attribute__((unused)) NV_STRING_JOIN2(defer__, __LINE__) = nv::ExitScopeHelp() + [&]()
|
||||||
|
|
||||||
|
|
||||||
// Indicate the compiler that the parameter is not used to suppress compier warnings.
|
// Indicate the compiler that the parameter is not used to suppress compier warnings.
|
||||||
#if NV_CC_MSVC
|
#if NV_CC_MSVC
|
||||||
#define NV_UNUSED(a) ((a)=(a))
|
#define NV_UNUSED(a) ((a)=(a))
|
||||||
#else
|
#else
|
||||||
#define NV_UNUSED(a) _Pragma(NV_STRING(unused(a)))
|
#define NV_UNUSED(a) _Pragma(NV_STRING(unused(a)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NV_CC_GNUC || NV_CC_CLANG
|
#if NV_CC_GNUC || NV_CC_CLANG
|
||||||
#define NV_LIKELY(x) __builtin_expect(!!(x), 1)
|
#define NV_LIKELY(x) __builtin_expect(!!(x), 1)
|
||||||
#define NV_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
#define NV_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||||
#else
|
#else
|
||||||
#define NV_LIKELY(x) x
|
#define NV_LIKELY(x) x
|
||||||
#define NV_UNLIKELY(x) x
|
#define NV_UNLIKELY(x) x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Null index. @@ Move this somewhere else... it's only used by nvmesh.
|
// Null index. @@ Move this somewhere else... it's only used by nvmesh.
|
||||||
//const unsigned int NIL = unsigned int(~0);
|
//const unsigned int NIL = unsigned int(~0);
|
||||||
//#define NIL uint(~0)
|
//#define NIL uint(~0)
|
||||||
|
|
||||||
// Null pointer.
|
// Null pointer.
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Platform includes
|
// Platform includes
|
||||||
#if NV_CC_MSVC
|
#if NV_CC_MSVC
|
||||||
# if NV_OS_WIN32
|
# if NV_OS_WIN32
|
||||||
# include "DefsVcWin32.h"
|
# include "DefsVcWin32.h"
|
||||||
# elif NV_OS_XBOX
|
# elif NV_OS_XBOX
|
||||||
# include "DefsVcXBox.h"
|
# include "DefsVcXBox.h"
|
||||||
# else
|
# else
|
||||||
# error "MSVC: Platform not supported"
|
# error "MSVC: Platform not supported"
|
||||||
# endif
|
# endif
|
||||||
#elif NV_CC_GNUC
|
#elif NV_CC_GNUC
|
||||||
# if NV_OS_LINUX
|
# if NV_OS_LINUX
|
||||||
# include "DefsGnucLinux.h"
|
# include "DefsGnucLinux.h"
|
||||||
# elif NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_NETBSD || NV_OS_OPENBSD
|
# elif NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_NETBSD || NV_OS_OPENBSD
|
||||||
# include "DefsGnucDarwin.h"
|
# include "DefsGnucDarwin.h"
|
||||||
# elif NV_OS_MINGW
|
# elif NV_OS_MINGW
|
||||||
# include "DefsGnucWin32.h"
|
# include "DefsGnucWin32.h"
|
||||||
# elif NV_OS_CYGWIN
|
# elif NV_OS_CYGWIN
|
||||||
# error "GCC: Cygwin not supported"
|
# error "GCC: Cygwin not supported"
|
||||||
# else
|
# else
|
||||||
# error "GCC: Platform not supported"
|
# error "GCC: Platform not supported"
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // NV_CORE_H
|
#endif // NV_CORE_H
|
||||||
|
@ -143,16 +143,16 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
w = images[i].width();
|
w = images[i].width;
|
||||||
h = images[i].height();
|
h = images[i].height;
|
||||||
}
|
}
|
||||||
else if (images[i].width() != w || images[i].height() != h)
|
else if (images[i].width != w || images[i].height != h)
|
||||||
{
|
{
|
||||||
printf("*** error, size of image '%s' does not match\n", files[i].str());
|
printf("*** error, size of image '%s' does not match\n", files[i].str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (images[i].format() == nv::Image::Format_ARGB)
|
if (images[i].format == nv::Image::Format_ARGB)
|
||||||
{
|
{
|
||||||
hasAlpha = true;
|
hasAlpha = true;
|
||||||
}
|
}
|
||||||
|
@ -506,8 +506,8 @@ int main(int argc, char *argv[])
|
|||||||
if (nv::strCaseDiff(input.extension(), ".dds") == 0)
|
if (nv::strCaseDiff(input.extension(), ".dds") == 0)
|
||||||
{
|
{
|
||||||
// Load surface.
|
// Load surface.
|
||||||
nv::DirectDrawSurface dds(input.str());
|
nv::DirectDrawSurface dds;
|
||||||
if (!dds.isValid())
|
if (!dds.load(input.str()) || !dds.isValid())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "The file '%s' is not a valid DDS file.\n", input.str());
|
fprintf(stderr, "The file '%s' is not a valid DDS file.\n", input.str());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -550,9 +550,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
for (uint m = 0; m < mipmapCount; m++)
|
for (uint m = 0; m < mipmapCount; m++)
|
||||||
{
|
{
|
||||||
dds.mipmap(&mipmap, f, m); // @@ Load as float.
|
if (imageFromDDS(&mipmap, dds, f, m)) // @@ Load as float.
|
||||||
|
inputOptions.setMipmapData(mipmap.pixels(), mipmap.width, mipmap.height, mipmap.depth, f, m);
|
||||||
inputOptions.setMipmapData(mipmap.pixels(), mipmap.width(), mipmap.height(), mipmap.depth(), f, m);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -591,8 +590,8 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputOptions.setTextureLayout(nvtt::TextureType_2D, image.width(), image.height());
|
inputOptions.setTextureLayout(nvtt::TextureType_2D, image.width, image.height);
|
||||||
inputOptions.setMipmapData(image.pixels(), image.width(), image.height());
|
inputOptions.setMipmapData(image.pixels(), image.width, image.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load surface.
|
// Load surface.
|
||||||
nv::DirectDrawSurface dds(argv[1]);
|
nv::DirectDrawSurface dds;
|
||||||
if (!dds.isValid())
|
if (!dds.load(argv[1]) || !dds.isValid())
|
||||||
{
|
{
|
||||||
printf("The file '%s' is not a valid DDS file.\n", argv[1]);
|
printf("The file '%s' is not a valid DDS file.\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -166,8 +166,8 @@ int main(int argc, char *argv[])
|
|||||||
// Load surface.
|
// Load surface.
|
||||||
// !!! DirectDrawSurface API doesn't support float images, so BC6 will be converted to 8-bit on load.
|
// !!! DirectDrawSurface API doesn't support float images, so BC6 will be converted to 8-bit on load.
|
||||||
// Should use nvtt::Surface instead.
|
// Should use nvtt::Surface instead.
|
||||||
nv::DirectDrawSurface dds(input.str());
|
nv::DirectDrawSurface dds;
|
||||||
if (!dds.isValid())
|
if (!dds.load(input.str()) || !dds.isValid())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "The file '%s' is not a valid DDS file.\n", input.str());
|
fprintf(stderr, "The file '%s' is not a valid DDS file.\n", input.str());
|
||||||
return 1;
|
return 1;
|
||||||
@ -219,7 +219,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
for (uint m = 0; m < mipmapCount; m++)
|
for (uint m = 0; m < mipmapCount; m++)
|
||||||
{
|
{
|
||||||
dds.mipmap(&mipmap, f, m);
|
if (!imageFromDDS(&mipmap, dds, f, m))
|
||||||
|
continue;
|
||||||
|
|
||||||
// set output filename, if we are doing faces and/or mipmaps
|
// set output filename, if we are doing faces and/or mipmaps
|
||||||
name.copy(output);
|
name.copy(output);
|
||||||
|
@ -42,14 +42,14 @@ static bool loadImage(nv::Image & image, const char * fileName)
|
|||||||
{
|
{
|
||||||
if (nv::strCaseDiff(nv::Path::extension(fileName), ".dds") == 0)
|
if (nv::strCaseDiff(nv::Path::extension(fileName), ".dds") == 0)
|
||||||
{
|
{
|
||||||
nv::DirectDrawSurface dds(fileName);
|
nv::DirectDrawSurface dds;
|
||||||
if (!dds.isValid())
|
if (!dds.load(fileName) || !dds.isValid())
|
||||||
{
|
{
|
||||||
printf("The file '%s' is not a valid DDS file.\n", fileName);
|
printf("The file '%s' is not a valid DDS file.\n", fileName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dds.mipmap(&image, 0, 0); // get first image
|
return imageFromDDS(&image, dds, 0, 0); // get first image
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -59,9 +59,9 @@ static bool loadImage(nv::Image & image, const char * fileName)
|
|||||||
printf("The file '%s' is not a supported image type.\n", fileName);
|
printf("The file '%s' is not a supported image type.\n", fileName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -174,10 +174,10 @@ int main(int argc, char *argv[])
|
|||||||
fimage.toLinear(0, 3, gamma);
|
fimage.toLinear(0, 3, gamma);
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
nv::AutoPtr<nv::FloatImage> fresult(fimage.resize(*filter, uint(image.width() * scale), uint(image.height() * scale), wrapMode));
|
nv::AutoPtr<nv::FloatImage> fresult(fimage.resize(*filter, uint(image.width * scale), uint(image.height * scale), wrapMode));
|
||||||
|
|
||||||
nv::AutoPtr<nv::Image> result(fresult->createImageGammaCorrect(gamma));
|
nv::AutoPtr<nv::Image> result(fresult->createImageGammaCorrect(gamma));
|
||||||
result->setFormat(nv::Image::Format_ARGB);
|
result->format = nv::Image::Format_ARGB;
|
||||||
|
|
||||||
nv::StdOutputStream stream(output.str());
|
nv::StdOutputStream stream(output.str());
|
||||||
nv::ImageIO::save(output.str(), stream, result.ptr());
|
nv::ImageIO::save(output.str(), stream, result.ptr());
|
||||||
|
@ -43,14 +43,14 @@ static bool loadImage(nv::Image & image, const char * fileName)
|
|||||||
{
|
{
|
||||||
if (nv::strCaseDiff(nv::Path::extension(fileName), ".dds") == 0)
|
if (nv::strCaseDiff(nv::Path::extension(fileName), ".dds") == 0)
|
||||||
{
|
{
|
||||||
nv::DirectDrawSurface dds(fileName);
|
nv::DirectDrawSurface dds;
|
||||||
if (!dds.isValid())
|
if (!dds.load(fileName) || !dds.isValid())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "The file '%s' is not a valid DDS file.\n", fileName);
|
fprintf(stderr, "The file '%s' is not a valid DDS file.\n", fileName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dds.mipmap(&image, 0, 0); // get first image
|
return imageFromDDS(&image, dds, 0, 0); // get first image
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -60,9 +60,9 @@ static bool loadImage(nv::Image & image, const char * fileName)
|
|||||||
fprintf(stderr, "The file '%s' is not a supported image type.\n", fileName);
|
fprintf(stderr, "The file '%s' is not a supported image type.\n", fileName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -119,9 +119,9 @@ int main(int argc, char *argv[])
|
|||||||
if (!loadImage(image, input.str())) return 1;
|
if (!loadImage(image, input.str())) return 1;
|
||||||
|
|
||||||
nv::StringBuilder widthString;
|
nv::StringBuilder widthString;
|
||||||
widthString.number(image.width());
|
widthString.number(image.width);
|
||||||
nv::StringBuilder heightString;
|
nv::StringBuilder heightString;
|
||||||
heightString.number(image.height());
|
heightString.number(image.height);
|
||||||
|
|
||||||
nv::Array<const char *> metaData;
|
nv::Array<const char *> metaData;
|
||||||
metaData.append("Thumb::Image::Width");
|
metaData.append("Thumb::Image::Width");
|
||||||
@ -131,26 +131,26 @@ int main(int argc, char *argv[])
|
|||||||
metaData.append(NULL);
|
metaData.append(NULL);
|
||||||
metaData.append(NULL);
|
metaData.append(NULL);
|
||||||
|
|
||||||
if ((image.width() > size) || (image.height() > size))
|
if ((image.width > size) || (image.height > size))
|
||||||
{
|
{
|
||||||
nv::FloatImage fimage(&image);
|
nv::FloatImage fimage(&image);
|
||||||
fimage.toLinear(0, 3, gamma);
|
fimage.toLinear(0, 3, gamma);
|
||||||
|
|
||||||
uint thumbW, thumbH;
|
uint thumbW, thumbH;
|
||||||
if (image.width() > image.height())
|
if (image.width > image.height)
|
||||||
{
|
{
|
||||||
thumbW = size;
|
thumbW = size;
|
||||||
thumbH = uint ((float (image.height()) / float (image.width())) * size);
|
thumbH = uint ((float (image.height) / float (image.width)) * size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
thumbW = uint ((float (image.width()) / float (image.height())) * size);
|
thumbW = uint ((float (image.width) / float (image.height)) * size);
|
||||||
thumbH = size;
|
thumbH = size;
|
||||||
}
|
}
|
||||||
nv::AutoPtr<nv::FloatImage> fresult(fimage.resize(nv::BoxFilter(), thumbW, thumbH, nv::FloatImage::WrapMode_Clamp));
|
nv::AutoPtr<nv::FloatImage> fresult(fimage.resize(nv::BoxFilter(), thumbW, thumbH, nv::FloatImage::WrapMode_Clamp));
|
||||||
|
|
||||||
nv::AutoPtr<nv::Image> result(fresult->createImageGammaCorrect(gamma));
|
nv::AutoPtr<nv::Image> result(fresult->createImageGammaCorrect(gamma));
|
||||||
result->setFormat(nv::Image::Format_ARGB);
|
result->format = nv::Image::Format_ARGB;
|
||||||
|
|
||||||
nv::StdOutputStream stream(output.str());
|
nv::StdOutputStream stream(output.str());
|
||||||
nv::ImageIO::save(output.str(), stream, result.ptr(), metaData.buffer());
|
nv::ImageIO::save(output.str(), stream, result.ptr(), metaData.buffer());
|
||||||
|
Loading…
Reference in New Issue
Block a user