Skip to content
This repository
Browse code

Fixed handling of enums in Lua plugin.

Fixed computation of getNumPrimitives() so that it returns 0 when PrimitiveSet is zero.

Added missing properties to PrimitiveSet serializers
  • Loading branch information...
commit 02e173e94726116cd47bd1358bbe6f6a516afaf9 1 parent 1679edc
authored February 13, 2014
2  src/osg/PrimitiveSet.cpp
@@ -31,7 +31,7 @@ unsigned int PrimitiveSet::getNumPrimitives() const
31 31
         case(TRIANGLE_FAN):
32 32
         case(QUAD_STRIP):
33 33
         case(PATCHES):
34  
-        case(POLYGON): return 1;
  34
+        case(POLYGON): return (getNumIndices()>0) ? 1 : 0;
35 35
     }
36 36
     return 0;
37 37
 }
59  src/osgPlugins/lua/LuaScriptEngine.cpp
@@ -595,8 +595,7 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string&
595 595
             GLenum value;
596 596
             if (_pi.getProperty(object, propertyName, value))
597 597
             {
598  
-                osgDB::ObjectWrapperManager* ow = osgDB::Registry::instance()->getObjectWrapperManager();
599  
-                std::string enumString = ow->getString("GL",value);
  598
+                std::string enumString = lookUpGLenumString(value);
600 599
                 lua_pushstring(_lua, enumString.c_str());
601 600
                 return 1;
602 601
             }
@@ -812,6 +811,52 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string&
812 811
     return 0;
813 812
 }
814 813
 
  814
+std::string LuaScriptEngine::lookUpGLenumString(GLenum value) const
  815
+{
  816
+    osgDB::ObjectWrapperManager* ow = osgDB::Registry::instance()->getObjectWrapperManager();
  817
+
  818
+    {
  819
+        const osgDB::IntLookup& lookup = ow->getLookupMap()["GL"];
  820
+        const osgDB::IntLookup::ValueToString& vts = lookup.getValueToString();
  821
+        osgDB::IntLookup::ValueToString::const_iterator itr = vts.find(value);
  822
+        if (itr!=vts.end()) return itr->second;
  823
+    }
  824
+
  825
+    {
  826
+        const osgDB::IntLookup& lookup = ow->getLookupMap()["PrimitiveType"];
  827
+        const osgDB::IntLookup::ValueToString& vts = lookup.getValueToString();
  828
+        osgDB::IntLookup::ValueToString::const_iterator itr = vts.find(value);
  829
+        if (itr!=vts.end()) return itr->second;
  830
+    }
  831
+
  832
+    OSG_NOTICE<<"Warning: LuaScriptEngine did not find valid GL enum value for GLenum value: "<<value<<std::endl;
  833
+
  834
+    return std::string();
  835
+}
  836
+
  837
+GLenum LuaScriptEngine::lookUpGLenumValue(const std::string& str) const
  838
+{
  839
+    osgDB::ObjectWrapperManager* ow = osgDB::Registry::instance()->getObjectWrapperManager();
  840
+
  841
+    {
  842
+        const osgDB::IntLookup& lookup = ow->getLookupMap()["GL"];
  843
+        const osgDB::IntLookup::StringToValue& stv = lookup.getStringToValue();
  844
+        osgDB::IntLookup::StringToValue::const_iterator itr = stv.find(str);
  845
+        if (itr!=stv.end()) return itr->second;
  846
+    }
  847
+
  848
+    {
  849
+        const osgDB::IntLookup& lookup = ow->getLookupMap()["PrimitiveType"];
  850
+        const osgDB::IntLookup::StringToValue& stv = lookup.getStringToValue();
  851
+        osgDB::IntLookup::StringToValue::const_iterator itr = stv.find(str);
  852
+        if (itr!=stv.end()) return itr->second;
  853
+    }
  854
+
  855
+    OSG_NOTICE<<"Warning: LuaScriptEngine did not find valid GL enum value for string value: "<<str<<std::endl;
  856
+
  857
+    return GL_NONE;
  858
+}
  859
+
815 860
 int LuaScriptEngine::setPropertyFromStack(osg::Object* object, const std::string& propertyName) const
816 861
 {
817 862
     osgDB::BaseSerializer::Type type;
@@ -856,19 +901,23 @@ int LuaScriptEngine::setPropertyFromStack(osg::Object* object, const std::string
856 901
         }
857 902
         case(osgDB::BaseSerializer::RW_GLENUM):
858 903
         {
  904
+            OSG_NOTICE<<"LuaScriptEngine::setPropertyFromStack("<<propertyName<<") osgDB::BaseSerializer::RW_GLENUM"<<std::endl;
859 905
             if (lua_isnumber(_lua, -1))
860 906
             {
861  
-                _pi.setProperty(object, propertyName, static_cast<int>(lua_tonumber(_lua, -1)));
  907
+                _pi.setProperty(object, propertyName, static_cast<GLenum>(lua_tonumber(_lua, -1)));
862 908
                 return 0;
863 909
             }
864 910
             else if (lua_isstring(_lua, -1))
865 911
             {
866 912
                 const char* enumString = lua_tostring(_lua, -1);
867  
-                osgDB::ObjectWrapperManager* ow = osgDB::Registry::instance()->getObjectWrapperManager();
  913
+                GLenum value = lookUpGLenumValue(enumString); //getValue("GL",enumString);
  914
+
  915
+                OSG_NOTICE<<"Checking enumString="<<enumString<<", got back value ="<<value<<std::endl;
868 916
 
869  
-                int value = ow->getValue("GL",enumString);
870 917
                 _pi.setProperty(object, propertyName, value);
  918
+                return 0;
871 919
             }
  920
+            OSG_NOTICE<<"LuaScriptEngine::setPropertyFromStack("<<propertyName<<") osgDB::BaseSerializer::RW_GLENUM Failed"<<std::endl;
872 921
             break;
873 922
         }
874 923
         case(osgDB::BaseSerializer::RW_ENUM):
3  src/osgPlugins/lua/LuaScriptEngine.h
@@ -156,6 +156,9 @@ class LuaScriptEngine : public osg::ScriptEngine
156 156
         bool matchLuaParameters(int luaType1, int luaType2, int luaType3) const { return ((lua_gettop(_lua)==3) && (lua_type(_lua, 1)==luaType1) && (lua_type(_lua, 2)==luaType2) && (lua_type(_lua, 3)==luaType3)); }
157 157
         bool matchLuaParameters(int luaType1, int luaType2, int luaType3, int luaType4) const { return ((lua_gettop(_lua)==4) && (lua_type(_lua, 1)==luaType1) && (lua_type(_lua, 2)==luaType2) && (lua_type(_lua, 3)==luaType3) && (lua_type(_lua, 4)==luaType4)); }
158 158
 
  159
+        std::string lookUpGLenumString(GLenum value) const;
  160
+        GLenum lookUpGLenumValue(const std::string& str) const;
  161
+
159 162
     protected:
160 163
 
161 164
         void initialize();
3  src/osgWrappers/serializers/osg/PrimitiveSet.cpp
@@ -21,10 +21,13 @@ REGISTER_OBJECT_WRAPPER( PrimitiveSet,
21 21
             ADD_ENUM_VALUE( DrawElementsUIntPrimitiveType );
22 22
     END_ENUM_SERIALIZER();
23 23
 
  24
+    ADD_INT_SERIALIZER( NumInstances, 0);
24 25
     ADD_GLENUM_SERIALIZER( Mode, GLenum, GL_NONE );
25 26
 
26 27
     ADD_UINT_SERIALIZER_NO_SET( TotalDataSize, 0);
27 28
     ADD_UINT_SERIALIZER_NO_SET( NumPrimitives, 0);
  29
+    ADD_UINT_SERIALIZER_NO_SET( NumIndices, 0);
  30
+
28 31
 
29 32
     wrapper->addSerializer(
30 33
         new osgDB::PropByValSerializer< osg::PrimitiveSet, bool > ("supportsBufferObject", false, &osg::PrimitiveSet::supportsBufferObject, 0, osgDB::BaseSerializer::RW_BOOL )

0 notes on commit 02e173e

Please sign in to comment.
Something went wrong with that request. Please try again.