libobs: Add additional gs_effect_get_ functions

Adds api functions to extract gs_eparam_t values, including
gs_effect_get_val(), gs_effect_get_val_size(),
gs_effect_get_default_val() and gs_effect_get_default_val_size()
This commit is contained in:
Alex Anderson 2018-06-19 00:11:06 -07:00
parent af67086912
commit e0cd45be9b
2 changed files with 91 additions and 0 deletions

View File

@ -389,6 +389,45 @@ static inline void effect_setval_inline(gs_eparam_t *param,
}
}
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
static inline void effect_getval_inline(gs_eparam_t *param, void *data,
size_t size)
{
if (!param) {
blog(LOG_ERROR, "effect_getval_inline: invalid param");
return;
}
if (!data) {
blog(LOG_ERROR, "effect_getval_inline: invalid data");
return;
}
size_t bytes = min(size, param->cur_val.num);
memcpy(data, param->cur_val.array, bytes);
}
static inline void effect_getdefaultval_inline(gs_eparam_t *param, void *data,
size_t size)
{
if (!param) {
blog(LOG_ERROR, "effect_getdefaultval_inline: invalid param");
return;
}
if (!data) {
blog(LOG_ERROR, "effect_getdefaultval_inline: invalid data");
return;
}
size_t bytes = min(size, param->default_val.num);
memcpy(data, param->default_val.array, bytes);
}
void gs_effect_set_bool(gs_eparam_t *param, bool val)
{
int b_val = (int)val;
@ -442,6 +481,54 @@ void gs_effect_set_val(gs_eparam_t *param, const void *val, size_t size)
effect_setval_inline(param, val, size);
}
void *gs_effect_get_val(gs_eparam_t *param)
{
if (!param) {
blog(LOG_ERROR, "gs_effect_get_val: invalid param");
return NULL;
}
size_t size = param->cur_val.num;
void *data;
if (size)
data = (void*)bzalloc(size);
else
return NULL;
effect_getval_inline(param, data, size);
return data;
}
size_t gs_effect_get_val_size(gs_eparam_t *param)
{
return param ? param->cur_val.num : 0;
}
void *gs_effect_get_default_val(gs_eparam_t *param)
{
if (!param) {
blog(LOG_ERROR, "gs_effect_get_default_val: invalid param");
return NULL;
}
size_t size = param->default_val.num;
void *data;
if (size)
data = (void*)bzalloc(size);
else
return NULL;
effect_getdefaultval_inline(param, data, size);
return data;
}
size_t gs_effect_get_default_val_size(gs_eparam_t *param)
{
return param ? param->default_val.num : 0;
}
void gs_effect_set_default(gs_eparam_t *param)
{
effect_setval_inline(param, param->default_val.array,

View File

@ -412,6 +412,10 @@ EXPORT void gs_effect_set_vec4(gs_eparam_t *param, const struct vec4 *val);
EXPORT void gs_effect_set_texture(gs_eparam_t *param, gs_texture_t *val);
EXPORT void gs_effect_set_val(gs_eparam_t *param, const void *val, size_t size);
EXPORT void gs_effect_set_default(gs_eparam_t *param);
EXPORT size_t gs_effect_get_val_size(gs_eparam_t *param);
EXPORT void *gs_effect_get_val(gs_eparam_t *param);
EXPORT size_t gs_effect_get_default_val_size(gs_eparam_t *param);
EXPORT void *gs_effect_get_default_val(gs_eparam_t *param);
EXPORT void gs_effect_set_next_sampler(gs_eparam_t *param,
gs_samplerstate_t *sampler);