From adb02a8f4509cb6c57924cbbaec24760999559b8 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 6 Apr 2015 13:24:45 +0200 Subject: [PATCH] Compile out things irrelevant for target build, like ShaderGenerator when !HAVE_CG --- panda/src/display/graphicsEngine.cxx | 2 ++ panda/src/display/standardMunger.cxx | 2 ++ panda/src/pgraphnodes/shaderGenerator.cxx | 5 ++++ panda/src/pgraphnodes/shaderGenerator.h | 30 ++++++++++++++++++++++- panda/src/pnmimage/convert_srgb.cxx | 8 ------ panda/src/pnmimage/convert_srgb.h | 6 +++++ panda/src/pnmimage/convert_srgb_sse2.cxx | 9 ++++--- panda/src/putil/bitMask.I | 6 ++--- panda/src/putil/bitMask.h | 2 +- panda/src/putil/config_util.cxx | 6 ++--- 10 files changed, 55 insertions(+), 21 deletions(-) diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index 22b2b876f8..2cac310b0c 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -2001,9 +2001,11 @@ setup_scene(GraphicsStateGuardian *gsg, DisplayRegionPipelineReader *dr) { // to use. We have to do this here because the ShaderGenerator // needs a host window pointer. Hopefully we'll be able to // eliminate that requirement in the future. +#ifdef HAVE_CG if (gsg->get_shader_generator() == NULL) { gsg->set_shader_generator(new ShaderGenerator(gsg, window)); } +#endif return scene_setup; } diff --git a/panda/src/display/standardMunger.cxx b/panda/src/display/standardMunger.cxx index 922150a114..45fcc7feb1 100644 --- a/panda/src/display/standardMunger.cxx +++ b/panda/src/display/standardMunger.cxx @@ -365,6 +365,7 @@ munge_state_impl(const RenderState *state) { munged_state = munged_state->remove_attrib(ColorScaleAttrib::get_class_slot()); } +#ifdef HAVE_CG if (_auto_shader) { CPT(RenderState) shader_state = munged_state->get_auto_shader_state(); ShaderGenerator *shader_generator = get_gsg()->get_shader_generator(); @@ -379,6 +380,7 @@ munge_state_impl(const RenderState *state) { } munged_state = munged_state->set_attrib(shader_state->_generated_shader); } +#endif return munged_state; } diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index 9e76063177..da3232692e 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/panda/src/pgraphnodes/shaderGenerator.cxx @@ -17,6 +17,7 @@ //////////////////////////////////////////////////////////////////// #include "shaderGenerator.h" + #include "renderState.h" #include "shaderAttrib.h" #include "auxBitplaneAttrib.h" @@ -44,6 +45,8 @@ TypeHandle ShaderGenerator::_type_handle; +#ifdef HAVE_CG + //////////////////////////////////////////////////////////////////// // Function: ShaderGenerator::Constructor // Access: Published @@ -1636,3 +1639,5 @@ texture_type_as_string(Texture::TextureType ttype) { return "2D"; } } + +#endif // HAVE_CG diff --git a/panda/src/pgraphnodes/shaderGenerator.h b/panda/src/pgraphnodes/shaderGenerator.h index 9a4aa05857..1e1daa581d 100644 --- a/panda/src/pgraphnodes/shaderGenerator.h +++ b/panda/src/pgraphnodes/shaderGenerator.h @@ -17,6 +17,10 @@ #define SHADERGENERATOR_H #include "pandabase.h" +#include "typedReferenceCount.h" + +#ifdef HAVE_CG + #include "graphicsStateGuardianBase.h" #include "graphicsOutputBase.h" #include "nodePath.h" @@ -169,10 +173,34 @@ public: } virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - private: +private: + static TypeHandle _type_handle; +}; + +#else + +// If we don't have Cg, let's replace this with a stub. +class EXPCL_PANDA_PGRAPHNODES ShaderGenerator : public TypedReferenceCount { +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + TypedObject::init_type(); + register_type(_type_handle, "ShaderGenerator", + TypedObject::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +private: static TypeHandle _type_handle; }; #include "shaderGenerator.I" +#endif // HAVE_CG + #endif // SHADERGENERATOR_H diff --git a/panda/src/pnmimage/convert_srgb.cxx b/panda/src/pnmimage/convert_srgb.cxx index ac46aa50f4..426e9818c5 100644 --- a/panda/src/pnmimage/convert_srgb.cxx +++ b/panda/src/pnmimage/convert_srgb.cxx @@ -162,12 +162,4 @@ has_sse2_sRGB_encode() { return has_support; } -#else -// Other architectures don't support SSE2 at all. - -bool -has_sse2_sRGB_encode() { - return false; -} - #endif // __SSE2__ diff --git a/panda/src/pnmimage/convert_srgb.h b/panda/src/pnmimage/convert_srgb.h index a28c126402..c27d3dcbf4 100644 --- a/panda/src/pnmimage/convert_srgb.h +++ b/panda/src/pnmimage/convert_srgb.h @@ -45,6 +45,7 @@ EXPCL_PANDA_PNMIMAGE INLINE void encode_sRGB_uchar(const LColorf &from, // Use these functions if you know that SSE2 support is available. // Otherwise, they will crash! +#if defined(__SSE2__) || defined(__i386__) || defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) EXPCL_PANDA_PNMIMAGE unsigned char encode_sRGB_uchar_sse2(float val); EXPCL_PANDA_PNMIMAGE void encode_sRGB_uchar_sse2(const LColorf &from, xel &into); @@ -53,6 +54,11 @@ EXPCL_PANDA_PNMIMAGE void encode_sRGB_uchar_sse2(const LColorf &from, // Use the following to find out if you can call either of the above. EXPCL_PANDA_PNMIMAGE bool has_sse2_sRGB_encode(); +#else +// The target architecture can't support the SSE2 extension at all. +#define encode_sRGB_uchar_sse2 encode_sRGB_uchar +#define has_sse2_sRGB_encode() (false) +#endif #include "convert_srgb.I" diff --git a/panda/src/pnmimage/convert_srgb_sse2.cxx b/panda/src/pnmimage/convert_srgb_sse2.cxx index 8121eccc8d..6de58d9584 100644 --- a/panda/src/pnmimage/convert_srgb_sse2.cxx +++ b/panda/src/pnmimage/convert_srgb_sse2.cxx @@ -127,10 +127,11 @@ encode_sRGB_uchar_sse2(const LColorf &color, xel &into, xelval &into_alpha) { into_alpha = _mm_extract_epi16(vals, 6); } -#else -// Somehow we're still compiling this without SSE2 support. We'll -// still have to define these functions, but emit a warning that the -// build system isn't configured properly. +#elif defined(__i386__) || defined(_M_IX86) +// Somehow we're still compiling this without SSE2 support, even though the +// target architecture could (in theory) support SSE2. We still have to +// define these functions, but emit a warning that the build system isn't +// configured properly. #warning convert_srgb_sse2.cxx is being compiled without SSE2 support! unsigned char diff --git a/panda/src/putil/bitMask.I b/panda/src/putil/bitMask.I index 19a603e7e8..5f4321e213 100644 --- a/panda/src/putil/bitMask.I +++ b/panda/src/putil/bitMask.I @@ -862,10 +862,8 @@ generate_hash(ChecksumHashGenerator &hashgen) const { //////////////////////////////////////////////////////////////////// template void BitMask:: -init_type() { - ostringstream str; - str << "BitMask" << num_bits; - register_type(_type_handle, str.str()); +init_type(const string &name) { + register_type(_type_handle, name); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/putil/bitMask.h b/panda/src/putil/bitMask.h index 64fcdedff0..05b9f7ddae 100644 --- a/panda/src/putil/bitMask.h +++ b/panda/src/putil/bitMask.h @@ -144,7 +144,7 @@ public: static TypeHandle get_class_type() { return _type_handle; } - static void init_type(); + static void init_type(const string &name); private: static TypeHandle _type_handle; diff --git a/panda/src/putil/config_util.cxx b/panda/src/putil/config_util.cxx index ea690e423b..44ac7bd6a4 100644 --- a/panda/src/putil/config_util.cxx +++ b/panda/src/putil/config_util.cxx @@ -181,9 +181,9 @@ init_libputil() { BamReaderAuxData::init_type(); BamReaderParam::init_type(); BitArray::init_type(); - BitMask16::init_type(); - BitMask32::init_type(); - BitMask64::init_type(); + BitMask16::init_type("BitMask16"); + BitMask32::init_type("BitMask32"); + BitMask64::init_type("BitMask64"); ButtonHandle::init_type(); ButtonMap::init_type(); CPointerCallbackObject::init_type();