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
This commit is contained in:
@@ -31,7 +31,7 @@ unsigned int PrimitiveSet::getNumPrimitives() const
|
||||
case(TRIANGLE_FAN):
|
||||
case(QUAD_STRIP):
|
||||
case(PATCHES):
|
||||
case(POLYGON): return 1;
|
||||
case(POLYGON): return (getNumIndices()>0) ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -595,8 +595,7 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string&
|
||||
GLenum value;
|
||||
if (_pi.getProperty(object, propertyName, value))
|
||||
{
|
||||
osgDB::ObjectWrapperManager* ow = osgDB::Registry::instance()->getObjectWrapperManager();
|
||||
std::string enumString = ow->getString("GL",value);
|
||||
std::string enumString = lookUpGLenumString(value);
|
||||
lua_pushstring(_lua, enumString.c_str());
|
||||
return 1;
|
||||
}
|
||||
@@ -812,6 +811,52 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string&
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string LuaScriptEngine::lookUpGLenumString(GLenum value) const
|
||||
{
|
||||
osgDB::ObjectWrapperManager* ow = osgDB::Registry::instance()->getObjectWrapperManager();
|
||||
|
||||
{
|
||||
const osgDB::IntLookup& lookup = ow->getLookupMap()["GL"];
|
||||
const osgDB::IntLookup::ValueToString& vts = lookup.getValueToString();
|
||||
osgDB::IntLookup::ValueToString::const_iterator itr = vts.find(value);
|
||||
if (itr!=vts.end()) return itr->second;
|
||||
}
|
||||
|
||||
{
|
||||
const osgDB::IntLookup& lookup = ow->getLookupMap()["PrimitiveType"];
|
||||
const osgDB::IntLookup::ValueToString& vts = lookup.getValueToString();
|
||||
osgDB::IntLookup::ValueToString::const_iterator itr = vts.find(value);
|
||||
if (itr!=vts.end()) return itr->second;
|
||||
}
|
||||
|
||||
OSG_NOTICE<<"Warning: LuaScriptEngine did not find valid GL enum value for GLenum value: "<<value<<std::endl;
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
GLenum LuaScriptEngine::lookUpGLenumValue(const std::string& str) const
|
||||
{
|
||||
osgDB::ObjectWrapperManager* ow = osgDB::Registry::instance()->getObjectWrapperManager();
|
||||
|
||||
{
|
||||
const osgDB::IntLookup& lookup = ow->getLookupMap()["GL"];
|
||||
const osgDB::IntLookup::StringToValue& stv = lookup.getStringToValue();
|
||||
osgDB::IntLookup::StringToValue::const_iterator itr = stv.find(str);
|
||||
if (itr!=stv.end()) return itr->second;
|
||||
}
|
||||
|
||||
{
|
||||
const osgDB::IntLookup& lookup = ow->getLookupMap()["PrimitiveType"];
|
||||
const osgDB::IntLookup::StringToValue& stv = lookup.getStringToValue();
|
||||
osgDB::IntLookup::StringToValue::const_iterator itr = stv.find(str);
|
||||
if (itr!=stv.end()) return itr->second;
|
||||
}
|
||||
|
||||
OSG_NOTICE<<"Warning: LuaScriptEngine did not find valid GL enum value for string value: "<<str<<std::endl;
|
||||
|
||||
return GL_NONE;
|
||||
}
|
||||
|
||||
int LuaScriptEngine::setPropertyFromStack(osg::Object* object, const std::string& propertyName) const
|
||||
{
|
||||
osgDB::BaseSerializer::Type type;
|
||||
@@ -856,19 +901,23 @@ int LuaScriptEngine::setPropertyFromStack(osg::Object* object, const std::string
|
||||
}
|
||||
case(osgDB::BaseSerializer::RW_GLENUM):
|
||||
{
|
||||
OSG_NOTICE<<"LuaScriptEngine::setPropertyFromStack("<<propertyName<<") osgDB::BaseSerializer::RW_GLENUM"<<std::endl;
|
||||
if (lua_isnumber(_lua, -1))
|
||||
{
|
||||
_pi.setProperty(object, propertyName, static_cast<int>(lua_tonumber(_lua, -1)));
|
||||
_pi.setProperty(object, propertyName, static_cast<GLenum>(lua_tonumber(_lua, -1)));
|
||||
return 0;
|
||||
}
|
||||
else if (lua_isstring(_lua, -1))
|
||||
{
|
||||
const char* enumString = lua_tostring(_lua, -1);
|
||||
osgDB::ObjectWrapperManager* ow = osgDB::Registry::instance()->getObjectWrapperManager();
|
||||
GLenum value = lookUpGLenumValue(enumString); //getValue("GL",enumString);
|
||||
|
||||
OSG_NOTICE<<"Checking enumString="<<enumString<<", got back value ="<<value<<std::endl;
|
||||
|
||||
int value = ow->getValue("GL",enumString);
|
||||
_pi.setProperty(object, propertyName, value);
|
||||
return 0;
|
||||
}
|
||||
OSG_NOTICE<<"LuaScriptEngine::setPropertyFromStack("<<propertyName<<") osgDB::BaseSerializer::RW_GLENUM Failed"<<std::endl;
|
||||
break;
|
||||
}
|
||||
case(osgDB::BaseSerializer::RW_ENUM):
|
||||
|
||||
@@ -156,6 +156,9 @@ class LuaScriptEngine : public osg::ScriptEngine
|
||||
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)); }
|
||||
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)); }
|
||||
|
||||
std::string lookUpGLenumString(GLenum value) const;
|
||||
GLenum lookUpGLenumValue(const std::string& str) const;
|
||||
|
||||
protected:
|
||||
|
||||
void initialize();
|
||||
|
||||
@@ -21,10 +21,13 @@ REGISTER_OBJECT_WRAPPER( PrimitiveSet,
|
||||
ADD_ENUM_VALUE( DrawElementsUIntPrimitiveType );
|
||||
END_ENUM_SERIALIZER();
|
||||
|
||||
ADD_INT_SERIALIZER( NumInstances, 0);
|
||||
ADD_GLENUM_SERIALIZER( Mode, GLenum, GL_NONE );
|
||||
|
||||
ADD_UINT_SERIALIZER_NO_SET( TotalDataSize, 0);
|
||||
ADD_UINT_SERIALIZER_NO_SET( NumPrimitives, 0);
|
||||
ADD_UINT_SERIALIZER_NO_SET( NumIndices, 0);
|
||||
|
||||
|
||||
wrapper->addSerializer(
|
||||
new osgDB::PropByValSerializer< osg::PrimitiveSet, bool > ("supportsBufferObject", false, &osg::PrimitiveSet::supportsBufferObject, 0, osgDB::BaseSerializer::RW_BOOL )
|
||||
|
||||
Reference in New Issue
Block a user