1 /*
2 * Modern effects for a modern Streamer
3 * Copyright (C) 2017 Michael Fabian Dirks
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include "gs-indexbuffer.hpp"
21 #include <stdexcept>
22 #include "gs-limits.hpp"
23 #include "obs/gs/gs-helper.hpp"
24
index_buffer(uint32_t maximumVertices)25 gs::index_buffer::index_buffer(uint32_t maximumVertices)
26 {
27 this->reserve(maximumVertices);
28 auto gctx = gs::context();
29 _index_buffer = gs_indexbuffer_create(gs_index_type::GS_UNSIGNED_LONG, this->data(), maximumVertices, GS_DYNAMIC);
30 }
31
index_buffer()32 gs::index_buffer::index_buffer() : index_buffer(MAXIMUM_VERTICES) {}
33
index_buffer(index_buffer & other)34 gs::index_buffer::index_buffer(index_buffer& other) : index_buffer(static_cast<uint32_t>(other.size()))
35 {
36 std::copy(other.begin(), other.end(), this->end());
37 }
38
index_buffer(std::vector<uint32_t> & other)39 gs::index_buffer::index_buffer(std::vector<uint32_t>& other) : index_buffer(static_cast<uint32_t>(other.size()))
40 {
41 std::copy(other.begin(), other.end(), this->end());
42 }
43
~index_buffer()44 gs::index_buffer::~index_buffer()
45 {
46 auto gctx = gs::context();
47 gs_indexbuffer_destroy(_index_buffer);
48 }
49
get()50 gs_indexbuffer_t* gs::index_buffer::get()
51 {
52 return get(true);
53 }
54
get(bool refreshGPU)55 gs_indexbuffer_t* gs::index_buffer::get(bool refreshGPU)
56 {
57 if (refreshGPU) {
58 auto gctx = gs::context();
59 gs_indexbuffer_flush(_index_buffer);
60 }
61 return _index_buffer;
62 }
63