gs-effect: Provide parameter count and index access

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2017-11-05 16:46:28 +01:00
parent f766a23019
commit a9b13787be
2 changed files with 20 additions and 9 deletions

View file

@ -62,17 +62,27 @@ gs_effect_t* GS::Effect::GetObject() {
return m_effect; return m_effect;
} }
std::vector<GS::EffectParameter> GS::Effect::GetParameters() { size_t GS::Effect::CountParameters() {
return (size_t)gs_effect_get_num_params(m_effect);
}
std::list<GS::EffectParameter> GS::Effect::GetParameters() {
size_t num = gs_effect_get_num_params(m_effect); size_t num = gs_effect_get_num_params(m_effect);
std::vector<GS::EffectParameter> ps; std::list<GS::EffectParameter> ps;
ps.reserve(num);
for (size_t idx = 0; idx < num; idx++) { for (size_t idx = 0; idx < num; idx++) {
ps.emplace_back(EffectParameter(gs_effect_get_param_by_idx(m_effect, idx))); ps.emplace_back(GetParameter(idx));
} }
return ps; return ps;
} }
GS::EffectParameter GS::Effect::GetParameterByName(std::string name) { GS::EffectParameter GS::Effect::GetParameter(size_t idx) {
gs_eparam_t* param = gs_effect_get_param_by_idx(m_effect, idx);
if (!param)
throw std::invalid_argument("parameter with index not found");
return EffectParameter(param);
}
GS::EffectParameter GS::Effect::GetParameter(std::string name) {
gs_eparam_t* param = gs_effect_get_param_by_name(m_effect, name.c_str()); gs_eparam_t* param = gs_effect_get_param_by_name(m_effect, name.c_str());
if (!param) if (!param)
throw std::invalid_argument("parameter with name not found"); throw std::invalid_argument("parameter with name not found");

View file

@ -22,7 +22,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <list>
extern "C" { extern "C" {
#pragma warning( push ) #pragma warning( push )
#pragma warning( disable: 4201 ) #pragma warning( disable: 4201 )
@ -90,9 +90,10 @@ namespace GS {
gs_effect_t* GetObject(); gs_effect_t* GetObject();
std::vector<EffectParameter> GetParameters(); size_t CountParameters();
EffectParameter GetParameterByName(std::string name); std::list<EffectParameter> GetParameters();
EffectParameter GetParameter(size_t idx);
EffectParameter GetParameter(std::string name);
protected: protected:
gs_effect_t* m_effect; gs_effect_t* m_effect;