@@ -31,11 +31,28 @@ WindowScene::~WindowScene() {}
31
31
32
32
void _createTexture (const String& name, Mat image)
33
33
{
34
+ PixelFormat format;
35
+ switch (image.type ())
36
+ {
37
+ case CV_8UC4:
38
+ format = PF_BYTE_BGRA;
39
+ break ;
40
+ case CV_8UC3:
41
+ format = PF_BYTE_BGR;
42
+ break ;
43
+ case CV_8UC1:
44
+ format = PF_BYTE_L;
45
+ break ;
46
+ default :
47
+ CV_Error (Error::StsBadArg, " currently only CV_8UC1, CV_8UC3, CV_8UC4 textures are supported" );
48
+ break ;
49
+ }
50
+
34
51
TextureManager& texMgr = TextureManager::getSingleton ();
35
52
TexturePtr tex = texMgr.getByName (name, RESOURCEGROUP_NAME);
36
53
37
54
Image im;
38
- im.loadDynamicImage (image.ptr (), image.cols , image.rows , 1 , PF_BYTE_BGR );
55
+ im.loadDynamicImage (image.ptr (), image.cols , image.rows , 1 , format );
39
56
40
57
if (tex)
41
58
{
@@ -323,7 +340,7 @@ class WindowSceneImpl : public WindowScene
323
340
324
341
void setBackground (InputArray image)
325
342
{
326
- CV_Assert (image. type () == CV_8UC3, bgplane);
343
+ CV_Assert (bgplane);
327
344
328
345
String name = sceneMgr->getName () + " _Background" ;
329
346
@@ -700,20 +717,23 @@ void setMaterialProperty(const String& name, int prop, const Scalar& val)
700
717
701
718
void setMaterialProperty (const String& name, int prop, const String& value)
702
719
{
703
- CV_Assert (prop == MATERIAL_TEXTURE , _app);
720
+ CV_Assert (prop >= MATERIAL_TEXTURE0, prop <= MATERIAL_TEXTURE3 , _app);
704
721
705
722
MaterialPtr mat = MaterialManager::getSingleton ().getByName (name, RESOURCEGROUP_NAME);
706
723
CV_Assert (mat);
707
724
708
725
Pass* rpass = mat->getTechniques ()[0 ]->getPasses ()[0 ];
709
726
710
- if (rpass->getTextureUnitStates ().empty ())
727
+ size_t texUnit = prop - MATERIAL_TEXTURE0;
728
+ CV_Assert (texUnit <= rpass->getTextureUnitStates ().size ());
729
+
730
+ if (rpass->getTextureUnitStates ().size () <= texUnit)
711
731
{
712
732
rpass->createTextureUnitState (value);
713
733
return ;
714
734
}
715
735
716
- rpass->getTextureUnitStates ()[0 ]->setTextureName (value);
736
+ rpass->getTextureUnitStates ()[texUnit ]->setTextureName (value);
717
737
}
718
738
719
739
static bool setShaderProperty (const GpuProgramParametersSharedPtr& params, const String& prop,
@@ -770,5 +790,13 @@ void setMaterialProperty(const String& name, const String& prop, const Scalar& v
770
790
if (!set)
771
791
CV_Error_ (Error::StsBadArg, (" shader parameter named '%s' not found" , prop.c_str ()));
772
792
}
793
+
794
+ void updateTexture (const String& name, InputArray image)
795
+ {
796
+ CV_Assert (_app);
797
+ TexturePtr tex = TextureManager::getSingleton ().getByName (name, RESOURCEGROUP_NAME);
798
+ CV_Assert (tex);
799
+ _createTexture (name, image.getMat ());
800
+ }
773
801
}
774
802
}
0 commit comments