From 1a6e70c9a0dd497a16fca627ae587343154742cb Mon Sep 17 00:00:00 2001 From: Ignacio Date: Sun, 5 Apr 2020 12:20:35 -0700 Subject: [PATCH] Cleanup. Assume static linking. --- src/nvimage/BlockDXT.cpp | 15 ++++++--------- src/nvimage/Filter.cpp | 2 ++ src/nvmath/CMakeLists.txt | 10 +--------- src/nvmath/Color.h | 8 ++++---- src/nvmath/Fitting.h | 1 + src/nvmath/Matrix.h | 10 +++------- src/nvmath/Matrix.inl | 6 +----- src/nvmath/Plane.h | 7 +------ src/nvmath/SimdVector.h | 1 + src/nvmath/SimdVector_SSE.h | 4 ++-- src/nvmath/SphericalHarmonic.h | 18 +++++++++--------- src/nvmath/Vector.h | 20 ++++---------------- src/nvmath/Vector.inl | 20 ++++---------------- src/nvmath/ftoi.h | 8 ++++---- src/nvmath/nvmath.h | 23 ----------------------- 15 files changed, 43 insertions(+), 110 deletions(-) diff --git a/src/nvimage/BlockDXT.cpp b/src/nvimage/BlockDXT.cpp index d35bd3a..b72873d 100644 --- a/src/nvimage/BlockDXT.cpp +++ b/src/nvimage/BlockDXT.cpp @@ -67,18 +67,15 @@ uint BlockDXT1::evaluatePalette(Color32 color_array[4], bool d3d9/*= false*/) co // color_array[1].u = c.u; if( col0.u > col1.u ) { - int bias = 0; - if (d3d9) bias = 1; - // Four-color block: derive the other two colors. - color_array[2].r = (2 * color_array[0].r + color_array[1].r + bias) / 3; - color_array[2].g = (2 * color_array[0].g + color_array[1].g + bias) / 3; - color_array[2].b = (2 * color_array[0].b + color_array[1].b + bias) / 3; + color_array[2].r = (2 * color_array[0].r + color_array[1].r + d3d9) / 3; + color_array[2].g = (2 * color_array[0].g + color_array[1].g + d3d9) / 3; + color_array[2].b = (2 * color_array[0].b + color_array[1].b + d3d9) / 3; color_array[2].a = 0xFF; - color_array[3].r = (2 * color_array[1].r + color_array[0].r + bias) / 3; - color_array[3].g = (2 * color_array[1].g + color_array[0].g + bias) / 3; - color_array[3].b = (2 * color_array[1].b + color_array[0].b + bias) / 3; + color_array[3].r = (2 * color_array[1].r + color_array[0].r + d3d9) / 3; + color_array[3].g = (2 * color_array[1].g + color_array[0].g + d3d9) / 3; + color_array[3].b = (2 * color_array[1].b + color_array[0].b + d3d9) / 3; color_array[3].a = 0xFF; return 4; diff --git a/src/nvimage/Filter.cpp b/src/nvimage/Filter.cpp index e30fefe..da92ba4 100644 --- a/src/nvimage/Filter.cpp +++ b/src/nvimage/Filter.cpp @@ -35,7 +35,9 @@ #include "Filter.h" +#include "nvmath/nvmath.h" #include "nvmath/Vector.h" // Vector4 + #include "nvcore/Utils.h" // swap #include // memset diff --git a/src/nvmath/CMakeLists.txt b/src/nvmath/CMakeLists.txt index c59cfeb..00db0f1 100644 --- a/src/nvmath/CMakeLists.txt +++ b/src/nvmath/CMakeLists.txt @@ -15,15 +15,7 @@ SET(MATH_SRCS INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) -# targets -ADD_DEFINITIONS(-DNVMATH_EXPORTS) - -IF(NVMATH_SHARED) - ADD_DEFINITIONS(-DNVMATH_SHARED=1) - ADD_LIBRARY(nvmath SHARED ${MATH_SRCS}) -ELSE(NVMATH_SHARED) - ADD_LIBRARY(nvmath ${MATH_SRCS}) -ENDIF(NVMATH_SHARED) +ADD_LIBRARY(nvmath ${MATH_SRCS}) TARGET_LINK_LIBRARIES(nvmath ${LIBS} nvcore) diff --git a/src/nvmath/Color.h b/src/nvmath/Color.h index 178c765..bdb9a8d 100644 --- a/src/nvmath/Color.h +++ b/src/nvmath/Color.h @@ -10,7 +10,7 @@ namespace nv { /// 64 bit color stored as BGRA. - class NVMATH_CLASS Color64 + class Color64 { public: Color64() { } @@ -46,7 +46,7 @@ namespace nv }; /// 32 bit color stored as BGRA. - class NVMATH_CLASS Color32 + class Color32 { public: Color32() { } @@ -96,7 +96,7 @@ namespace nv /// 16 bit 565 BGR color. - struct NVMATH_CLASS Color16 + struct Color16 { Color16() { } Color16(const Color16 & c) : u(c.u) { } @@ -120,7 +120,7 @@ namespace nv }; /// 16 bit 4444 BGRA color. - class NVMATH_CLASS Color16_4444 + class Color16_4444 { public: Color16_4444() { } diff --git a/src/nvmath/Fitting.h b/src/nvmath/Fitting.h index 7728f10..4c5ee59 100644 --- a/src/nvmath/Fitting.h +++ b/src/nvmath/Fitting.h @@ -1,6 +1,7 @@ // This code is in the public domain -- Ignacio Castaño #pragma once +#include "nvmath.h" // NV_EPSILON #include "Vector.h" #include "Plane.h" diff --git a/src/nvmath/Matrix.h b/src/nvmath/Matrix.h index d1171a1..6bf0bf3 100644 --- a/src/nvmath/Matrix.h +++ b/src/nvmath/Matrix.h @@ -1,8 +1,6 @@ // This code is in the public domain -- castanyo@yahoo.es #pragma once -#ifndef NV_MATH_MATRIX_H -#define NV_MATH_MATRIX_H #include "Vector.h" @@ -15,7 +13,7 @@ namespace nv enum identity_t { identity }; // 2x2 matrix. - class NVMATH_CLASS Matrix2 + class Matrix2 { public: Matrix2(); @@ -55,7 +53,7 @@ namespace nv // 3x3 matrix. - class NVMATH_CLASS Matrix3 + class Matrix3 { public: Matrix3(); @@ -96,7 +94,7 @@ namespace nv // 4x4 matrix. - class NVMATH_CLASS Matrix + class Matrix { public: typedef Matrix const & Arg; @@ -150,5 +148,3 @@ namespace nv extern Matrix inverse(const Matrix & m); } // nv namespace - -#endif // NV_MATH_MATRIX_H diff --git a/src/nvmath/Matrix.inl b/src/nvmath/Matrix.inl index 54c998f..6f025c3 100644 --- a/src/nvmath/Matrix.inl +++ b/src/nvmath/Matrix.inl @@ -1,10 +1,9 @@ // This code is in the public domain -- castanyo@yahoo.es #pragma once -#ifndef NV_MATH_MATRIX_INL -#define NV_MATH_MATRIX_INL #include "Matrix.h" +#include "nvmath.h" namespace nv { @@ -1462,6 +1461,3 @@ public: }; #endif - - -#endif // NV_MATH_MATRIX_INL diff --git a/src/nvmath/Plane.h b/src/nvmath/Plane.h index dc468b2..a4dff24 100644 --- a/src/nvmath/Plane.h +++ b/src/nvmath/Plane.h @@ -1,17 +1,14 @@ // This code is in the public domain -- Ignacio Castaño #pragma once -#ifndef NV_MATH_PLANE_H -#define NV_MATH_PLANE_H -#include "nvmath.h" #include "Vector.h" namespace nv { class Matrix; - class NVMATH_CLASS Plane + class Plane { public: Plane(); @@ -38,5 +35,3 @@ namespace nv } // nv namespace - -#endif // NV_MATH_PLANE_H diff --git a/src/nvmath/SimdVector.h b/src/nvmath/SimdVector.h index 38a06ef..e20b7a9 100644 --- a/src/nvmath/SimdVector.h +++ b/src/nvmath/SimdVector.h @@ -1,6 +1,7 @@ // This code is in the public domain -- Ignacio Castaño #pragma once +#include "nvmath.h" #include "Vector.h" // Vector3, Vector4 #if NV_USE_ALTIVEC diff --git a/src/nvmath/SimdVector_SSE.h b/src/nvmath/SimdVector_SSE.h index dc900c8..1f5249a 100644 --- a/src/nvmath/SimdVector_SSE.h +++ b/src/nvmath/SimdVector_SSE.h @@ -87,12 +87,12 @@ namespace nv { return Vector3( c[0], c[1], c[2] ); } - NV_SIMD_INLINE Vector4 toVector4() const + /*NV_SIMD_INLINE Vector4 toVector4() const { NV_ALIGN_16 float c[4]; _mm_store_ps( c, vec ); return Vector4( c[0], c[1], c[2], c[3] ); - } + }*/ #define SSE_SPLAT( a ) ((a) | ((a) << 2) | ((a) << 4) | ((a) << 6)) NV_SIMD_NATIVE SimdVector splatX() const { return SimdVector( _mm_shuffle_ps( vec, vec, SSE_SPLAT( 0 ) ) ); } diff --git a/src/nvmath/SphericalHarmonic.h b/src/nvmath/SphericalHarmonic.h index f2eb741..962588f 100644 --- a/src/nvmath/SphericalHarmonic.h +++ b/src/nvmath/SphericalHarmonic.h @@ -14,11 +14,11 @@ namespace nv class Vector3; class Matrix; - NVMATH_API float legendrePolynomial( int l, int m, float x ) NV_CONST; - NVMATH_API float shBasis( int l, int m, float theta, float phi ) NV_CONST; - NVMATH_API float shBasis( int l, int m, const Vector3 & v ) NV_CONST; - NVMATH_API float hshBasis( int l, int m, float theta, float phi ) NV_CONST; - NVMATH_API float hshBasis( int l, int m, const Vector3 & v ) NV_CONST; + float legendrePolynomial( int l, int m, float x ) NV_CONST; + float shBasis( int l, int m, float theta, float phi ) NV_CONST; + float shBasis( int l, int m, const Vector3 & v ) NV_CONST; + float hshBasis( int l, int m, float theta, float phi ) NV_CONST; + float hshBasis( int l, int m, const Vector3 & v ) NV_CONST; class Sh; float dot(const Sh & a, const Sh & b) NV_CONST; @@ -395,10 +395,10 @@ namespace nv }*/ - NVMATH_API void multiply( const ShMatrix &A, const ShMatrix &B ); - NVMATH_API void rotation( const Matrix & m ); - NVMATH_API void rotation( int axis, float angles ); - NVMATH_API void print(); + void multiply( const ShMatrix &A, const ShMatrix &B ); + void rotation( const Matrix & m ); + void rotation( int axis, float angles ); + void print(); private: diff --git a/src/nvmath/Vector.h b/src/nvmath/Vector.h index ad18672..f525ef5 100644 --- a/src/nvmath/Vector.h +++ b/src/nvmath/Vector.h @@ -1,14 +1,12 @@ // This code is in the public domain -- castanyo@yahoo.es #pragma once -#ifndef NV_MATH_VECTOR_H -#define NV_MATH_VECTOR_H -#include "nvmath.h" +#include "nvcore/nvcore.h" namespace nv { - class NVMATH_CLASS Vector2 + class Vector2 { public: typedef Vector2 const & Arg; @@ -33,9 +31,6 @@ namespace nv void operator*=(float s); void operator*=(Vector2::Arg v); - friend bool operator==(Vector2::Arg a, Vector2::Arg b); - friend bool operator!=(Vector2::Arg a, Vector2::Arg b); - union { struct { float x, y; @@ -44,7 +39,7 @@ namespace nv }; }; - class NVMATH_CLASS Vector3 + class Vector3 { public: typedef Vector3 const & Arg; @@ -75,9 +70,6 @@ namespace nv void operator*=(Vector3::Arg v); void operator/=(Vector3::Arg v); - friend bool operator==(Vector3::Arg a, Vector3::Arg b); - friend bool operator!=(Vector3::Arg a, Vector3::Arg b); - union { struct { float x, y, z; @@ -86,7 +78,7 @@ namespace nv }; }; - class NVMATH_CLASS Vector4 + class Vector4 { public: typedef Vector4 const & Arg; @@ -121,9 +113,6 @@ namespace nv void operator*=(Vector4::Arg v); void operator/=(Vector4::Arg v); - friend bool operator==(Vector4::Arg a, Vector4::Arg b); - friend bool operator!=(Vector4::Arg a, Vector4::Arg b); - union { struct { float x, y, z, w; @@ -146,4 +135,3 @@ template T to(const nv::Vector2 & v) { NV_COMPILER_CHECK(sizeof(T) template T to(const nv::Vector3 & v) { NV_COMPILER_CHECK(sizeof(T) == sizeof(nv::Vector3)); return T(v.x, v.y, v.z); } template T to(const nv::Vector4 & v) { NV_COMPILER_CHECK(sizeof(T) == sizeof(nv::Vector4)); return T(v.x, v.y, v.z, v.w); } -#endif // NV_MATH_VECTOR_H diff --git a/src/nvmath/Vector.inl b/src/nvmath/Vector.inl index 5807912..1d87eb3 100644 --- a/src/nvmath/Vector.inl +++ b/src/nvmath/Vector.inl @@ -1,26 +1,15 @@ // This code is in the public domain -- castanyo@yahoo.es #pragma once -#ifndef NV_MATH_VECTOR_INL -#define NV_MATH_VECTOR_INL #include "Vector.h" +#include "nvmath.h" + #include "nvcore/Utils.h" // min, max #include "nvcore/Hash.h" // hash namespace nv { - - // Helpers to convert vector types. Assume T has x,y members and 2 argument constructor. - //template T to(Vector2::Arg v) { return T(v.x, v.y); } - - // Helpers to convert vector types. Assume T has x,y,z members and 3 argument constructor. - //template T to(Vector3::Arg v) { return T(v.x, v.y, v.z); } - - // Helpers to convert vector types. Assume T has x,y,z members and 3 argument constructor. - //template T to(Vector4::Arg v) { return T(v.x, v.y, v.z, v.w); } - - // Vector2 inline Vector2::Vector2() {} inline Vector2::Vector2(float f) : x(f), y(f) {} @@ -537,7 +526,8 @@ namespace nv inline Vector3 operator/(Vector3::Arg v, float s) { - return scale(v, 1.0f/s); + //return scale(v, 1.0f/s); + return Vector3(v.x / s, v.y / s, v.z / s); } /*inline Vector3 add_scaled(Vector3::Arg a, Vector3::Arg b, float s) @@ -915,5 +905,3 @@ namespace nv #endif //NV_OS_IOS } // nv namespace - -#endif // NV_MATH_VECTOR_INL diff --git a/src/nvmath/ftoi.h b/src/nvmath/ftoi.h index ffc6889..a99af8e 100755 --- a/src/nvmath/ftoi.h +++ b/src/nvmath/ftoi.h @@ -1,11 +1,13 @@ // This code is in the public domain -- castano@gmail.com #pragma once -#ifndef NV_MATH_FTOI_H -#define NV_MATH_FTOI_H #include "nvmath/nvmath.h" +#if NV_USE_SSE + #include +#endif + #include namespace nv @@ -246,5 +248,3 @@ namespace nv } // nv - -#endif // NV_MATH_FTOI_H diff --git a/src/nvmath/nvmath.h b/src/nvmath/nvmath.h index 259ab63..a3143c5 100644 --- a/src/nvmath/nvmath.h +++ b/src/nvmath/nvmath.h @@ -1,8 +1,6 @@ // This code is in the public domain -- castanyo@yahoo.es #pragma once -#ifndef NV_MATH_H -#define NV_MATH_H #include "nvcore/nvcore.h" #include "nvcore/Debug.h" // nvDebugCheck @@ -14,21 +12,6 @@ #include // finite, isnan #endif - -// Function linkage -#if NVMATH_SHARED -#ifdef NVMATH_EXPORTS -#define NVMATH_API DLL_EXPORT -#define NVMATH_CLASS DLL_EXPORT_CLASS -#else -#define NVMATH_API DLL_IMPORT -#define NVMATH_CLASS DLL_IMPORT -#endif -#else // NVMATH_SHARED -#define NVMATH_API -#define NVMATH_CLASS -#endif // NVMATH_SHARED - // Set some reasonable defaults. #ifndef NV_USE_ALTIVEC # define NV_USE_ALTIVEC NV_CPU_PPC @@ -53,10 +36,6 @@ # endif #endif -#if NV_USE_SSE - #include -#endif - // Internally set NV_USE_SIMD when either altivec or sse is available. #if NV_USE_ALTIVEC && NV_USE_SSE # error "Cannot enable both altivec and sse!" @@ -331,5 +310,3 @@ namespace nv } // nv - -#endif // NV_MATH_H