10#include "galaxy/core/ServiceLocator.hpp"
13#include "galaxy/utils/Globals.hpp"
19thread_local const float vertices[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f};
21thread_local const unsigned int indices[] = {0, 1, 2, 0, 2, 3};
27 void data_callback(ma_device* pDevice,
void* pOutput,
const void* pInput, ma_uint32 frameCount)
29 auto buffer =
static_cast<RingBuffer*
>(pDevice->pUserData);
31 const int frames_needed = frameCount * 2;
32 if (buffer->available_bytes() >= frames_needed)
34 const float* read = buffer->direct_read_pointer(frames_needed);
35 auto output =
static_cast<float*
>(pOutput);
37 for (
auto i = 0; i < frames_needed; i++)
39 output[i] = read[i] * buffer->get_volume();
44 std::memset(pOutput, 0, frames_needed *
sizeof(
float));
51 , m_audio_buffer {nullptr}
63 glDeleteVertexArrays(1, &
m_vao);
64 glDeleteBuffers(1, &
m_vbo);
65 glDeleteBuffers(1, &
m_ibo);
105 auto& fs = core::ServiceLocator<fs::VirtualFileSystem>::ref();
112 plm_set_video_decode_callback(
114 [](plm_t* self, plm_frame_t* frame,
void* user) {
115 auto video =
static_cast<Video*
>(user);
117 video->
update_texture(GL_TEXTURE0, video->m_texture_y, &frame->y);
118 video->update_texture(GL_TEXTURE1, video->m_texture_cb, &frame->cb);
119 video->update_texture(GL_TEXTURE2, video->m_texture_cr, &frame->cr);
124 plm_set_audio_decode_callback(
126 [](plm_t* self, plm_samples_t* samples,
void* user) {
127 auto buffer =
static_cast<RingBuffer*
>(user);
128 buffer->write(samples->interleaved, samples->count * 2);
133 if (plm_get_num_audio_streams(
m_plm) > 0)
137 ma_device_config config = ma_device_config_init(ma_device_type_playback);
138 config.playback.format = ma_format_f32;
139 config.playback.channels = 2;
140 config.sampleRate = plm_get_samplerate(
m_plm);
144 if (ma_device_init(
nullptr, &config,
m_audio) != MA_SUCCESS)
146 plm_set_audio_enabled(
m_plm,
false);
147 plm_set_loop(
m_plm,
false);
148 plm_set_audio_stream(
m_plm, 0);
149 plm_set_audio_enabled(
m_plm,
true);
160 plm_set_audio_enabled(
m_plm,
false);
180 glCreateVertexArrays(1, &
m_vao);
181 glCreateBuffers(1, &
m_vbo);
182 glCreateBuffers(1, &
m_ibo);
187 glVertexArrayVertexBuffer(
m_vao, 0,
m_vbo, 0, 2 *
sizeof(
float));
190 glEnableVertexArrayAttrib(
m_vao, 0);
191 glVertexArrayAttribFormat(
m_vao, 0, 2, GL_FLOAT, GL_FALSE, 0);
192 glVertexArrayAttribBinding(
m_vao, 0, 0);
203 if (!ma_device_is_started(
m_audio))
208 plm_decode(
m_plm, GALAXY_DT);
215 glBindVertexArray(
m_vao);
216 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT,
nullptr);
217 glBindVertexArray(0);
225 return plm_has_ended(
m_plm);
235 return plm_get_time(
m_plm);
245 return plm_get_framerate(
m_plm);
255 return plm_get_samplerate(
m_plm);
265 return plm_get_duration(
m_plm);
273 unsigned int texture = 0;
274 glCreateTextures(GL_TEXTURE_2D, 1, &texture);
276 glBindTexture(GL_TEXTURE_2D, texture);
277 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
278 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
279 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
280 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
282 constexpr const int swizzleMask[] = {GL_ZERO, GL_ZERO, GL_ZERO, GL_RED};
283 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
285 glBindTexture(GL_TEXTURE_2D, 0);
294 glActiveTexture(unit);
295 glBindTexture(GL_TEXTURE_2D, texture);
296 glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, plane->width, plane->height, 0, GL_RED, GL_UNSIGNED_BYTE, plane->data);
#define GALAXY_LOG(level, msg,...)
thread_local const float vertices[]
Video.cpp galaxy.
thread_local const unsigned int indices[]
bool parse(const std::string &src)
Loads a combined raw shader.
void set_uniform(const std::string &name, const Uniforms &... args)
Specialized variadic template for setting shader uniforms.
void bind() const
Make active shader.
constexpr const auto video_vert_shader
Video vertex shader.
constexpr const auto video_frag_shader
Video frag shader.