mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-29 11:01:23 +00:00
gs-vertexbuffer: Slight Refactor to unify code style
This commit is contained in:
parent
3a05c08daf
commit
fe3186220c
4 changed files with 38 additions and 38 deletions
|
@ -256,7 +256,7 @@ Filter::Shape::Instance::Instance(obs_data_t *data, obs_source_t *context)
|
|||
: context(context) {
|
||||
obs_enter_graphics();
|
||||
m_vertexHelper = new GS::VertexBuffer(maximumPoints);
|
||||
m_vertexHelper->set_uv_layers(1);
|
||||
m_vertexHelper->SetUVLayers(1);
|
||||
m_texRender = gs_texrender_create(GS_RGBA, GS_Z32F);
|
||||
obs_leave_graphics();
|
||||
|
||||
|
@ -271,9 +271,9 @@ Filter::Shape::Instance::~Instance() {
|
|||
|
||||
void Filter::Shape::Instance::update(obs_data_t *data) {
|
||||
uint32_t points = (uint32_t)obs_data_get_int(data, P_SHAPE_POINTS);
|
||||
m_vertexHelper->resize(points);
|
||||
m_vertexHelper->Resize(points);
|
||||
for (uint32_t point = 0; point < points; point++) {
|
||||
GS::Vertex v = m_vertexHelper->at(point);
|
||||
GS::Vertex v = m_vertexHelper->At(point);
|
||||
{
|
||||
auto strings = cache.find(std::make_pair(point,
|
||||
P_SHAPE_POINT_X));
|
||||
|
@ -311,7 +311,7 @@ void Filter::Shape::Instance::update(obs_data_t *data) {
|
|||
}
|
||||
drawmode = (gs_draw_mode)obs_data_get_int(data, P_SHAPE_MODE);
|
||||
obs_enter_graphics();
|
||||
m_vertexBuffer = m_vertexHelper->get();
|
||||
m_vertexBuffer = m_vertexHelper->Update();
|
||||
obs_leave_graphics();
|
||||
}
|
||||
|
||||
|
@ -386,7 +386,7 @@ void Filter::Shape::Instance::video_render(gs_effect_t *effect) {
|
|||
tex);
|
||||
gs_load_vertexbuffer(m_vertexBuffer);
|
||||
gs_load_indexbuffer(nullptr);
|
||||
gs_draw(drawmode, 0, (uint32_t)m_vertexHelper->size());
|
||||
gs_draw(drawmode, 0, (uint32_t)m_vertexHelper->Size());
|
||||
}
|
||||
|
||||
gs_matrix_pop();
|
||||
|
|
|
@ -305,8 +305,8 @@ Filter::Transform::Instance::Instance(obs_data_t *data, obs_source_t *context) :
|
|||
m_texRender = gs_texrender_create(GS_RGBA, GS_ZS_NONE);
|
||||
m_shapeRender = gs_texrender_create(GS_RGBA, GS_ZS_NONE);
|
||||
m_vertexHelper = new GS::VertexBuffer(4);
|
||||
m_vertexHelper->set_uv_layers(1);
|
||||
m_vertexHelper->resize(4);
|
||||
m_vertexHelper->SetUVLayers(1);
|
||||
m_vertexHelper->Resize(4);
|
||||
obs_leave_graphics();
|
||||
|
||||
update(data);
|
||||
|
@ -465,7 +465,7 @@ void Filter::Transform::Instance::video_render(gs_effect_t *paramEffect) {
|
|||
|
||||
/// Generate mesh
|
||||
{
|
||||
GS::Vertex vtx = m_vertexHelper->at(0);
|
||||
GS::Vertex vtx = m_vertexHelper->At(0);
|
||||
*vtx.color = 0xFFFFFFFF;
|
||||
vec4_set(vtx.uv[0], 0, 0, 0, 0);
|
||||
vec3_set(vtx.position,
|
||||
|
@ -474,7 +474,7 @@ void Filter::Transform::Instance::video_render(gs_effect_t *paramEffect) {
|
|||
vec3_transform(vtx.position, vtx.position, &ident);
|
||||
}
|
||||
{
|
||||
GS::Vertex vtx = m_vertexHelper->at(1);
|
||||
GS::Vertex vtx = m_vertexHelper->At(1);
|
||||
*vtx.color = 0xFFFFFFFF;
|
||||
vec4_set(vtx.uv[0], 1, 0, 0, 0);
|
||||
vec3_set(vtx.position,
|
||||
|
@ -483,7 +483,7 @@ void Filter::Transform::Instance::video_render(gs_effect_t *paramEffect) {
|
|||
vec3_transform(vtx.position, vtx.position, &ident);
|
||||
}
|
||||
{
|
||||
GS::Vertex vtx = m_vertexHelper->at(2);
|
||||
GS::Vertex vtx = m_vertexHelper->At(2);
|
||||
*vtx.color = 0xFFFFFFFF;
|
||||
vec4_set(vtx.uv[0], 0, 1, 0, 0);
|
||||
vec3_set(vtx.position,
|
||||
|
@ -492,7 +492,7 @@ void Filter::Transform::Instance::video_render(gs_effect_t *paramEffect) {
|
|||
vec3_transform(vtx.position, vtx.position, &ident);
|
||||
}
|
||||
{
|
||||
GS::Vertex vtx = m_vertexHelper->at(3);
|
||||
GS::Vertex vtx = m_vertexHelper->At(3);
|
||||
*vtx.color = 0xFFFFFFFF;
|
||||
vec4_set(vtx.uv[0], 1, 1, 0, 0);
|
||||
vec3_set(vtx.position,
|
||||
|
@ -501,7 +501,7 @@ void Filter::Transform::Instance::video_render(gs_effect_t *paramEffect) {
|
|||
vec3_transform(vtx.position, vtx.position, &ident);
|
||||
}
|
||||
|
||||
m_vertexBuffer = m_vertexHelper->get();
|
||||
m_vertexBuffer = m_vertexHelper->Update();
|
||||
if (!m_vertexBuffer) {
|
||||
obs_source_skip_video_filter(m_sourceContext);
|
||||
return;
|
||||
|
|
|
@ -112,7 +112,7 @@ GS::VertexBuffer::VertexBuffer(uint32_t maximumVertices) {
|
|||
GS::VertexBuffer::VertexBuffer(gs_vertbuffer_t* vb) {
|
||||
gs_vb_data* vbd = gs_vertexbuffer_get_data(vb);
|
||||
VertexBuffer((uint32_t)vbd->num);
|
||||
this->set_uv_layers((uint32_t)vbd->num_tex);
|
||||
this->SetUVLayers((uint32_t)vbd->num_tex);
|
||||
|
||||
if (vbd->points != nullptr)
|
||||
std::memcpy(m_positions, vbd->points, vbd->num * sizeof(vec3));
|
||||
|
@ -226,51 +226,47 @@ void GS::VertexBuffer::operator=(VertexBuffer const&& other) {
|
|||
m_layerdata = other.m_layerdata;
|
||||
}
|
||||
|
||||
void GS::VertexBuffer::resize(size_t new_size) {
|
||||
void GS::VertexBuffer::Resize(uint32_t new_size) {
|
||||
if (new_size > m_capacity) {
|
||||
throw std::out_of_range("new_size out of range");
|
||||
}
|
||||
m_size = new_size;
|
||||
}
|
||||
|
||||
size_t GS::VertexBuffer::size() {
|
||||
uint32_t GS::VertexBuffer::Size() {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
bool GS::VertexBuffer::empty() {
|
||||
bool GS::VertexBuffer::Empty() {
|
||||
return m_size == 0;
|
||||
}
|
||||
|
||||
const GS::Vertex GS::VertexBuffer::at(size_t idx) {
|
||||
const GS::Vertex GS::VertexBuffer::At(uint32_t idx) {
|
||||
if ((idx < 0) || (idx >= m_size)) {
|
||||
throw std::out_of_range("idx out of range");
|
||||
}
|
||||
|
||||
GS::Vertex vtx;
|
||||
vtx.position = &m_positions[idx];
|
||||
vtx.normal = &m_normals[idx];
|
||||
vtx.tangent = &m_tangents[idx];
|
||||
vtx.color = &m_colors[idx];
|
||||
GS::Vertex vtx(&m_positions[idx], &m_normals[idx], &m_tangents[idx], &m_colors[idx], nullptr);
|
||||
for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) {
|
||||
vtx.uv[n] = &m_uvs[n][idx];
|
||||
}
|
||||
return vtx;
|
||||
}
|
||||
|
||||
const GS::Vertex GS::VertexBuffer::operator[](const size_t pos) {
|
||||
return at(pos);
|
||||
const GS::Vertex GS::VertexBuffer::operator[](uint32_t const pos) {
|
||||
return At(pos);
|
||||
}
|
||||
|
||||
void GS::VertexBuffer::set_uv_layers(uint32_t layers) {
|
||||
void GS::VertexBuffer::SetUVLayers(uint32_t layers) {
|
||||
m_layers = layers;
|
||||
}
|
||||
|
||||
uint32_t GS::VertexBuffer::uv_layers() {
|
||||
uint32_t GS::VertexBuffer::GetUVLayers() {
|
||||
return m_layers;
|
||||
}
|
||||
|
||||
|
||||
gs_vertbuffer_t* GS::VertexBuffer::get(bool refreshGPU) {
|
||||
gs_vertbuffer_t* GS::VertexBuffer::Update(bool refreshGPU) {
|
||||
if (!refreshGPU)
|
||||
return m_vertexbuffer;
|
||||
|
||||
|
@ -308,6 +304,6 @@ gs_vertbuffer_t* GS::VertexBuffer::get(bool refreshGPU) {
|
|||
return m_vertexbuffer;
|
||||
}
|
||||
|
||||
gs_vertbuffer_t* GS::VertexBuffer::get() {
|
||||
return get(true);
|
||||
gs_vertbuffer_t* GS::VertexBuffer::Update() {
|
||||
return Update(true);
|
||||
}
|
||||
|
|
|
@ -98,23 +98,27 @@ namespace GS {
|
|||
void operator=(VertexBuffer const&& other);
|
||||
#pragma endregion Copy/Move Constructors
|
||||
|
||||
void resize(size_t new_size);
|
||||
|
||||
size_t size();
|
||||
|
||||
bool empty();
|
||||
void Resize(uint32_t new_size);
|
||||
|
||||
const GS::Vertex at(size_t idx);
|
||||
uint32_t Size();
|
||||
|
||||
const GS::Vertex operator[](const size_t pos);
|
||||
bool Empty();
|
||||
|
||||
void set_uv_layers(uint32_t layers);
|
||||
const GS::Vertex At(uint32_t idx);
|
||||
|
||||
uint32_t uv_layers();
|
||||
const GS::Vertex operator[](uint32_t const pos);
|
||||
|
||||
gs_vertbuffer_t* get();
|
||||
void SetUVLayers(uint32_t layers);
|
||||
|
||||
gs_vertbuffer_t* get(bool refreshGPU);
|
||||
uint32_t GetUVLayers();
|
||||
|
||||
#pragma region Update / Grab GS object
|
||||
gs_vertbuffer_t* Update();
|
||||
|
||||
gs_vertbuffer_t* Update(bool refreshGPU);
|
||||
#pragma endregion Update / Grab GS object
|
||||
|
||||
private:
|
||||
uint32_t m_size;
|
||||
|
|
Loading…
Reference in a new issue