Merge pull request #2651 from paroj:ovis_tex

pull/2658/head
Alexander Alekhin 5 years ago
commit e502f3053d
  1. 20
      modules/ovis/include/opencv2/ovis.hpp
  2. 32
      modules/ovis/src/ovis.cpp

@ -86,8 +86,6 @@ public:
/**
* set window background to custom image
*
* creates a texture named "<title>_Background"
* @param image
*/
CV_WRAP virtual void setBackground(InputArray image) = 0;
@ -354,6 +352,14 @@ CV_EXPORTS_W void setMaterialProperty(const String& name, int prop, const Scalar
/// @overload
CV_EXPORTS_W void setMaterialProperty(const String& name, int prop, const String& value);
/**
* set the texture of a material to the given value
* @param name material name
* @param prop @ref MaterialProperty
* @param value the texture data
*/
CV_EXPORTS_AS(setMaterialTexture) void setMaterialProperty(const String& name, int prop, InputArray value);
/**
* set the shader property of a material to the given value
* @param name material name
@ -365,7 +371,7 @@ CV_EXPORTS_W void setMaterialProperty(const String& name, const String& prop, co
/**
* create a 2D plane, X right, Y down, Z up
*
* creates a material and a texture with the same name
* creates a material with the same name
* @param name name of the mesh
* @param size size in world units
* @param image optional texture
@ -403,13 +409,7 @@ CV_EXPORTS_W void createGridMesh(const String& name, const Size2f& size, const S
*/
CV_EXPORTS_W void createTriangleMesh(const String& name, InputArray vertices, InputArray normals = noArray(), InputArray indices = noArray());
/**
* updates an existing texture
*
* A new texture can be created with @ref createPlaneMesh
* @param name name of the texture
* @param image the image data
*/
/// @deprecated use setMaterialProperty
CV_EXPORTS_W void updateTexture(const String& name, InputArray image);
//! @}
}

@ -1016,11 +1016,12 @@ void setMaterialProperty(const String& name, int prop, const Scalar& val)
RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, name, RESOURCEGROUP_NAME);
}
void setMaterialProperty(const String& name, int prop, const String& value)
static TextureUnitState* _getTextureUnitForUpdate(const String& material, int prop)
{
CV_Assert_N(prop >= MATERIAL_TEXTURE0, prop <= MATERIAL_TEXTURE3, _app);
MaterialPtr mat = MaterialManager::getSingleton().getByName(name, RESOURCEGROUP_NAME);
CV_Assert(_app);
auto mat = MaterialManager::getSingleton().getByName(material, RESOURCEGROUP_NAME);
CV_Assert(mat);
Pass* rpass = mat->getTechniques()[0]->getPasses()[0];
@ -1028,15 +1029,32 @@ void setMaterialProperty(const String& name, int prop, const String& value)
size_t texUnit = prop - MATERIAL_TEXTURE0;
CV_Assert(texUnit <= rpass->getTextureUnitStates().size());
RTShader::ShaderGenerator::getSingleton().invalidateMaterial(
RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, material, RESOURCEGROUP_NAME);
if (rpass->getTextureUnitStates().size() <= texUnit)
{
rpass->createTextureUnitState(value);
return;
return rpass->createTextureUnitState();
}
rpass->getTextureUnitStates()[texUnit]->setTextureName(value);
RTShader::ShaderGenerator::getSingleton().invalidateMaterial(
RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, name, RESOURCEGROUP_NAME);
return rpass->getTextureUnitStates()[texUnit];
}
void setMaterialProperty(const String& name, int prop, const String& value)
{
auto tu = _getTextureUnitForUpdate(name, prop);
tu->setTextureName(value);
}
void setMaterialProperty(const String& name, int prop, InputArray value)
{
auto tu = _getTextureUnitForUpdate(name, prop);
auto texName = tu->getTextureName();
if(texName.empty()) texName = name;
_createTexture(texName, value.getMat());
tu->setTextureName(texName);
}
static bool setShaderProperty(const GpuProgramParametersSharedPtr& params, const String& prop,

Loading…
Cancel
Save