Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv_contrib
Commits
faf82d88
Commit
faf82d88
authored
Feb 07, 2018
by
Pavel Rojtberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ovis: setMaterialProperty - add overload for setting shader uniforms
parent
9e899785
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
+63
-0
ovis.hpp
modules/ovis/include/opencv2/ovis.hpp
+8
-0
ovis.cpp
modules/ovis/src/ovis.cpp
+55
-0
No files found.
modules/ovis/include/opencv2/ovis.hpp
View file @
faf82d88
...
...
@@ -204,6 +204,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 shader property of a material to the given value
* @param name material name
* @param prop property name
* @param value the value
*/
CV_EXPORTS_W
void
setMaterialProperty
(
const
String
&
name
,
const
String
&
prop
,
const
Scalar
&
value
);
/**
* create a 2D plane, X right, Y down, Z up
*
...
...
modules/ovis/src/ovis.cpp
View file @
faf82d88
...
...
@@ -615,5 +615,60 @@ void setMaterialProperty(const String& name, int prop, const String& value)
rpass
->
getTextureUnitStates
()[
0
]
->
setTextureName
(
value
);
}
static
bool
setShaderProperty
(
const
GpuProgramParametersSharedPtr
&
params
,
const
String
&
prop
,
const
Scalar
&
value
)
{
const
GpuConstantDefinition
*
def
=
params
->
_findNamedConstantDefinition
(
prop
,
false
);
if
(
!
def
)
return
false
;
Vec4f
valf
=
value
;
switch
(
def
->
constType
)
{
case
GCT_FLOAT1
:
params
->
setNamedConstant
(
prop
,
valf
[
0
]);
return
true
;
case
GCT_FLOAT2
:
params
->
setNamedConstant
(
prop
,
Vector2
(
valf
.
val
));
return
true
;
case
GCT_FLOAT3
:
params
->
setNamedConstant
(
prop
,
Vector3
(
valf
.
val
));
return
true
;
case
GCT_FLOAT4
:
params
->
setNamedConstant
(
prop
,
Vector4
(
valf
.
val
));
return
true
;
default
:
CV_Error
(
Error
::
StsBadArg
,
"currently only float[1-4] uniforms are supported"
);
return
false
;
}
}
void
setMaterialProperty
(
const
String
&
name
,
const
String
&
prop
,
const
Scalar
&
value
)
{
CV_Assert
(
_app
);
MaterialPtr
mat
=
MaterialManager
::
getSingleton
().
getByName
(
name
,
RESOURCEGROUP_NAME
);
CV_Assert
(
mat
);
Pass
*
rpass
=
mat
->
getTechniques
()[
0
]
->
getPasses
()[
0
];
bool
set
=
false
;
if
(
rpass
->
hasGpuProgram
(
GPT_VERTEX_PROGRAM
))
{
GpuProgramParametersSharedPtr
params
=
rpass
->
getVertexProgramParameters
();
set
=
setShaderProperty
(
params
,
prop
,
value
);
}
if
(
rpass
->
hasGpuProgram
(
GPT_FRAGMENT_PROGRAM
))
{
GpuProgramParametersSharedPtr
params
=
rpass
->
getFragmentProgramParameters
();
set
=
set
||
setShaderProperty
(
params
,
prop
,
value
);
}
if
(
!
set
)
CV_Error_
(
Error
::
StsBadArg
,
(
"shader parameter named '%s' not found"
,
prop
.
c_str
()));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment