Add portaudio and glfw for static linking
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// odplot productions is a trademarked name. Project Yugh is a copyrighted property. This code, however, is free to be copy and extended as you see fit.
|
||||
|
||||
#include "thirdpersonfollow.h"
|
||||
#include "3pfollow.h"
|
||||
#include <math.h>
|
||||
|
||||
// void ThirdPersonFollow::_ready() {
|
||||
@@ -347,7 +347,7 @@ static void edit_input_cb(GLFWwindow *w, int key, int scancode, int action, int
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F8:
|
||||
NEGATE(editor.debug.show);
|
||||
//NEGATE(editor.debug.show);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F9:
|
||||
@@ -424,7 +424,7 @@ static void edit_mouse_cb(GLFWwindow *w, int button, int action, int mods) {
|
||||
}
|
||||
}
|
||||
|
||||
void editor_init(struct mSDLWindow *window) {
|
||||
void editor_init(struct window *window) {
|
||||
levels = vec_make(MAXPATH, 10);
|
||||
get_levels();
|
||||
editor_load_projects();
|
||||
|
||||
@@ -72,12 +72,12 @@ extern struct vec *projects;
|
||||
|
||||
|
||||
struct Texture;
|
||||
struct mSDLWindow;
|
||||
struct window;
|
||||
|
||||
void pickGameObject(int pickID);
|
||||
int is_allowed_extension(const char *ext);
|
||||
|
||||
void editor_init(struct mSDLWindow *window);
|
||||
void editor_init(struct window *window);
|
||||
void editor_input();
|
||||
void editor_render();
|
||||
int editor_wantkeyboard();
|
||||
|
||||
@@ -43,7 +43,7 @@ void font_init(struct mShader *textshader) {
|
||||
font = MakeFont("teenytinypixels.ttf", 300);
|
||||
}
|
||||
|
||||
void font_frame(struct mSDLWindow *w) {
|
||||
void font_frame(struct window *w) {
|
||||
shader_use(shader);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "mathc.h"
|
||||
|
||||
struct mShader;
|
||||
struct mSDLWindow;
|
||||
struct window;
|
||||
|
||||
/// Holds all state information relevant to a character as loaded using FreeType
|
||||
struct Character {
|
||||
@@ -23,7 +23,7 @@ struct sFont {
|
||||
|
||||
|
||||
void font_init(struct mShader *s);
|
||||
void font_frame(struct mSDLWindow *w);
|
||||
void font_frame(struct window *w);
|
||||
struct sFont *MakeFont(const char *fontfile, int height);
|
||||
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct mShader *shader, float color[3]);
|
||||
void text_settype(struct sFont *font);
|
||||
|
||||
@@ -96,14 +96,14 @@ mrb_value mrb_c_reload(mrb_state *mrb, mrb_value self) {
|
||||
|
||||
mrb_value mrb_win_make(mrb_state *mrb, mrb_value self) {
|
||||
char name[50] = "New Window";
|
||||
struct mSDLWindow *new = MakeSDLWindow(name, 500, 500, 0);
|
||||
struct window *new = MakeSDLWindow(name, 500, 500, 0);
|
||||
return mrb_float_value(mrb, new->id);
|
||||
}
|
||||
|
||||
mrb_value mrb_win_cmd(mrb_state *mrb, mrb_value self) {
|
||||
mrb_float win, cmd;
|
||||
mrb_get_args(mrb, "ff", &win, &cmd);
|
||||
struct mSDLWindow *new = window_i(win);
|
||||
struct window *new = window_i(win);
|
||||
|
||||
switch ((int)cmd)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ struct nk_context *ctx;
|
||||
static struct nk_glfw nkglfw = {0};
|
||||
|
||||
|
||||
void nuke_init(struct mSDLWindow *win) {
|
||||
void nuke_init(struct window *win) {
|
||||
window_makecurrent(win);
|
||||
|
||||
ctx = nk_glfw3_init(&nkglfw, win->window, NK_GLFW3_INSTALL_CALLBACKS);
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
extern struct nk_context *ctx;
|
||||
|
||||
struct mSDLWindow;
|
||||
struct window;
|
||||
|
||||
void nuke_init(struct mSDLWindow *win);
|
||||
void nuke_init(struct window *win);
|
||||
void nuke_start();
|
||||
void nuke_end();
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ void openglInit()
|
||||
|
||||
|
||||
static struct mCamera mcamera = {0};
|
||||
void openglRender(struct mSDLWindow *window)
|
||||
void openglRender(struct window *window)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glClearColor(0.3f, 0.3f, 0.3f, 1.f);
|
||||
@@ -215,7 +215,7 @@ void openglRender(struct mSDLWindow *window)
|
||||
|
||||
|
||||
|
||||
void openglInit3d(struct mSDLWindow *window)
|
||||
void openglInit3d(struct window *window)
|
||||
{
|
||||
/* TODO: IMG init doesn't work in C++
|
||||
int init =(0x00000001 | 0x00000002);
|
||||
@@ -385,7 +385,7 @@ void openglInit3d(struct mSDLWindow *window)
|
||||
|
||||
}
|
||||
|
||||
void openglRender3d(struct mSDLWindow *window, struct mCamera *mcamera)
|
||||
void openglRender3d(struct window *window, struct mCamera *mcamera)
|
||||
{
|
||||
//////// SET NEW PROJECTION
|
||||
// TODO: Make this not happen every frame
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "render.h"
|
||||
|
||||
struct mCamera;
|
||||
struct mSDLWindow;
|
||||
struct window;
|
||||
|
||||
extern struct mShader *spriteShader;
|
||||
extern struct mShader *animSpriteShader;
|
||||
@@ -43,10 +43,10 @@ enum RenderMode {
|
||||
};
|
||||
|
||||
void openglInit();
|
||||
void openglRender(struct mSDLWindow *window);
|
||||
void openglRender(struct window *window);
|
||||
|
||||
void openglInit3d(struct mSDLWindow *window);
|
||||
void openglRender3d(struct mSDLWindow *window, struct mCamera *camera);
|
||||
void openglInit3d(struct window *window);
|
||||
void openglRender3d(struct window *window, struct mCamera *camera);
|
||||
|
||||
void BindUniformBlock(GLuint shaderID, const char *bufferName,
|
||||
GLuint bufferBind);
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
#include "music.h"
|
||||
#include "stb_vorbis.h"
|
||||
|
||||
|
||||
#include "SDL2/SDL.h"
|
||||
|
||||
#include "mix.h"
|
||||
#include "dsp.h"
|
||||
|
||||
@@ -35,10 +32,12 @@ const char *audioDriver;
|
||||
|
||||
void new_samplerate(short *in, short *out, int n, int ch, int sr_in, int sr_out)
|
||||
{
|
||||
/*
|
||||
SDL_AudioStream *stream = SDL_NewAudioStream(AUDIO_S16, ch, sr_in, AUDIO_S16, ch, sr_out);
|
||||
SDL_AudioStreamPut(stream, in, n * ch * sizeof(short));
|
||||
SDL_AudioStreamGet(stream, out, n * ch * sizeof(short));
|
||||
SDL_FreeAudioStream(stream);
|
||||
*/
|
||||
}
|
||||
|
||||
struct wav change_samplerate(struct wav w, int rate)
|
||||
@@ -49,19 +48,19 @@ struct wav change_samplerate(struct wav w, int rate)
|
||||
|
||||
|
||||
|
||||
SDL_AudioStream *stream = SDL_NewAudioStream(AUDIO_S16, w.ch, w.samplerate, AUDIO_S16, w.ch, rate);
|
||||
SDL_AudioStreamPut(stream, w.data, w.frames*w.ch*sizeof(short));
|
||||
//SDL_AudioStream *stream = SDL_NewAudioStream(AUDIO_S16, w.ch, w.samplerate, AUDIO_S16, w.ch, rate);
|
||||
//SDL_AudioStreamPut(stream, w.data, w.frames*w.ch*sizeof(short));
|
||||
|
||||
int oldframes = w.frames;
|
||||
w.frames *= (float)rate/w.samplerate;
|
||||
int samples = sizeof(short) * w.ch * w.frames;
|
||||
w.samplerate = rate;
|
||||
short *new = malloc(samples);
|
||||
SDL_AudioStreamGet(stream, new, samples);
|
||||
//SDL_AudioStreamGet(stream, new, samples);
|
||||
|
||||
free(w.data);
|
||||
w.data = new;
|
||||
SDL_FreeAudioStream(stream);
|
||||
//SDL_FreeAudioStream(stream);
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
6397
source/engine/thirdparty/GLFW/glfw3.h
vendored
6397
source/engine/thirdparty/GLFW/glfw3.h
vendored
File diff suppressed because it is too large
Load Diff
628
source/engine/thirdparty/GLFW/glfw3native.h
vendored
628
source/engine/thirdparty/GLFW/glfw3native.h
vendored
@@ -1,628 +0,0 @@
|
||||
/*************************************************************************
|
||||
* GLFW 3.4 - www.glfw.org
|
||||
* A library for OpenGL, window and input
|
||||
*------------------------------------------------------------------------
|
||||
* Copyright (c) 2002-2006 Marcus Geelnard
|
||||
* Copyright (c) 2006-2018 Camilla Löwy <elmindreda@glfw.org>
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would
|
||||
* be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not
|
||||
* be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef _glfw3_native_h_
|
||||
#define _glfw3_native_h_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Doxygen documentation
|
||||
*************************************************************************/
|
||||
|
||||
/*! @file glfw3native.h
|
||||
* @brief The header of the native access functions.
|
||||
*
|
||||
* This is the header file of the native access functions. See @ref native for
|
||||
* more information.
|
||||
*/
|
||||
/*! @defgroup native Native access
|
||||
* @brief Functions related to accessing native handles.
|
||||
*
|
||||
* **By using the native access functions you assert that you know what you're
|
||||
* doing and how to fix problems caused by using them. If you don't, you
|
||||
* shouldn't be using them.**
|
||||
*
|
||||
* Before the inclusion of @ref glfw3native.h, you may define zero or more
|
||||
* window system API macro and zero or more context creation API macros.
|
||||
*
|
||||
* The chosen backends must match those the library was compiled for. Failure
|
||||
* to do this will cause a link-time error.
|
||||
*
|
||||
* The available window API macros are:
|
||||
* * `GLFW_EXPOSE_NATIVE_WIN32`
|
||||
* * `GLFW_EXPOSE_NATIVE_COCOA`
|
||||
* * `GLFW_EXPOSE_NATIVE_X11`
|
||||
* * `GLFW_EXPOSE_NATIVE_WAYLAND`
|
||||
*
|
||||
* The available context API macros are:
|
||||
* * `GLFW_EXPOSE_NATIVE_WGL`
|
||||
* * `GLFW_EXPOSE_NATIVE_NSGL`
|
||||
* * `GLFW_EXPOSE_NATIVE_GLX`
|
||||
* * `GLFW_EXPOSE_NATIVE_EGL`
|
||||
* * `GLFW_EXPOSE_NATIVE_OSMESA`
|
||||
*
|
||||
* These macros select which of the native access functions that are declared
|
||||
* and which platform-specific headers to include. It is then up your (by
|
||||
* definition platform-specific) code to handle which of these should be
|
||||
* defined.
|
||||
*
|
||||
* If you do not want the platform-specific headers to be included, define
|
||||
* `GLFW_NATIVE_INCLUDE_NONE` before including the @ref glfw3native.h header.
|
||||
*
|
||||
* @code
|
||||
* #define GLFW_EXPOSE_NATIVE_WIN32
|
||||
* #define GLFW_EXPOSE_NATIVE_WGL
|
||||
* #define GLFW_NATIVE_INCLUDE_NONE
|
||||
* #include <GLFW/glfw3native.h>
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* System headers and types
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(GLFW_NATIVE_INCLUDE_NONE)
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_WIN32) || defined(GLFW_EXPOSE_NATIVE_WGL)
|
||||
/* This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
|
||||
* example to allow applications to correctly declare a GL_KHR_debug callback)
|
||||
* but windows.h assumes no one will define APIENTRY before it does
|
||||
*/
|
||||
#if defined(GLFW_APIENTRY_DEFINED)
|
||||
#undef APIENTRY
|
||||
#undef GLFW_APIENTRY_DEFINED
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#elif defined(GLFW_EXPOSE_NATIVE_COCOA) || defined(GLFW_EXPOSE_NATIVE_NSGL)
|
||||
#if defined(__OBJC__)
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#else
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <objc/objc.h>
|
||||
#endif
|
||||
#elif defined(GLFW_EXPOSE_NATIVE_X11) || defined(GLFW_EXPOSE_NATIVE_GLX)
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#elif defined(GLFW_EXPOSE_NATIVE_WAYLAND)
|
||||
#include <wayland-client.h>
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_WGL)
|
||||
/* WGL is declared by windows.h */
|
||||
#endif
|
||||
#if defined(GLFW_EXPOSE_NATIVE_NSGL)
|
||||
/* NSGL is declared by Cocoa.h */
|
||||
#endif
|
||||
#if defined(GLFW_EXPOSE_NATIVE_GLX)
|
||||
/* This is a workaround for the fact that glfw3.h defines GLAPIENTRY because by
|
||||
* default it also acts as an OpenGL header
|
||||
* However, glx.h will include gl.h, which will define it unconditionally
|
||||
*/
|
||||
#if defined(GLFW_GLAPIENTRY_DEFINED)
|
||||
#undef GLAPIENTRY
|
||||
#undef GLFW_GLAPIENTRY_DEFINED
|
||||
#endif
|
||||
#include <GL/glx.h>
|
||||
#endif
|
||||
#if defined(GLFW_EXPOSE_NATIVE_EGL)
|
||||
#include <EGL/egl.h>
|
||||
#endif
|
||||
#if defined(GLFW_EXPOSE_NATIVE_OSMESA)
|
||||
/* This is a workaround for the fact that glfw3.h defines GLAPIENTRY because by
|
||||
* default it also acts as an OpenGL header
|
||||
* However, osmesa.h will include gl.h, which will define it unconditionally
|
||||
*/
|
||||
#if defined(GLFW_GLAPIENTRY_DEFINED)
|
||||
#undef GLAPIENTRY
|
||||
#undef GLFW_GLAPIENTRY_DEFINED
|
||||
#endif
|
||||
#include <GL/osmesa.h>
|
||||
#endif
|
||||
|
||||
#endif /*GLFW_NATIVE_INCLUDE_NONE*/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Functions
|
||||
*************************************************************************/
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_WIN32)
|
||||
/*! @brief Returns the adapter device name of the specified monitor.
|
||||
*
|
||||
* @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`)
|
||||
* of the specified monitor, or `NULL` if an [error](@ref error_handling)
|
||||
* occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.1.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor);
|
||||
|
||||
/*! @brief Returns the display device name of the specified monitor.
|
||||
*
|
||||
* @return The UTF-8 encoded display device name (for example
|
||||
* `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.1.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor);
|
||||
|
||||
/*! @brief Returns the `HWND` of the specified window.
|
||||
*
|
||||
* @return The `HWND` of the specified window, or `NULL` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @remark The `HDC` associated with the window can be queried with the
|
||||
* [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc)
|
||||
* function.
|
||||
* @code
|
||||
* HDC dc = GetDC(glfwGetWin32Window(window));
|
||||
* @endcode
|
||||
* This DC is private and does not need to be released.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.0.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window);
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_WGL)
|
||||
/*! @brief Returns the `HGLRC` of the specified window.
|
||||
*
|
||||
* @return The `HGLRC` of the specified window, or `NULL` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref
|
||||
* GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @remark The `HDC` associated with the window can be queried with the
|
||||
* [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc)
|
||||
* function.
|
||||
* @code
|
||||
* HDC dc = GetDC(glfwGetWin32Window(window));
|
||||
* @endcode
|
||||
* This DC is private and does not need to be released.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.0.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window);
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_COCOA)
|
||||
/*! @brief Returns the `CGDirectDisplayID` of the specified monitor.
|
||||
*
|
||||
* @return The `CGDirectDisplayID` of the specified monitor, or
|
||||
* `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.1.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
|
||||
|
||||
/*! @brief Returns the `NSWindow` of the specified window.
|
||||
*
|
||||
* @return The `NSWindow` of the specified window, or `nil` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.0.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_NSGL)
|
||||
/*! @brief Returns the `NSOpenGLContext` of the specified window.
|
||||
*
|
||||
* @return The `NSOpenGLContext` of the specified window, or `nil` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref
|
||||
* GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.0.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI id glfwGetNSGLContext(GLFWwindow* window);
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_X11)
|
||||
/*! @brief Returns the `Display` used by GLFW.
|
||||
*
|
||||
* @return The `Display` used by GLFW, or `NULL` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.0.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI Display* glfwGetX11Display(void);
|
||||
|
||||
/*! @brief Returns the `RRCrtc` of the specified monitor.
|
||||
*
|
||||
* @return The `RRCrtc` of the specified monitor, or `None` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.1.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor);
|
||||
|
||||
/*! @brief Returns the `RROutput` of the specified monitor.
|
||||
*
|
||||
* @return The `RROutput` of the specified monitor, or `None` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.1.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor);
|
||||
|
||||
/*! @brief Returns the `Window` of the specified window.
|
||||
*
|
||||
* @return The `Window` of the specified window, or `None` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.0.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI Window glfwGetX11Window(GLFWwindow* window);
|
||||
|
||||
/*! @brief Sets the current primary selection to the specified string.
|
||||
*
|
||||
* @param[in] string A UTF-8 encoded string.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
|
||||
* GLFW_PLATFORM_ERROR.
|
||||
*
|
||||
* @pointer_lifetime The specified string is copied before this function
|
||||
* returns.
|
||||
*
|
||||
* @thread_safety This function must only be called from the main thread.
|
||||
*
|
||||
* @sa @ref clipboard
|
||||
* @sa glfwGetX11SelectionString
|
||||
* @sa glfwSetClipboardString
|
||||
*
|
||||
* @since Added in version 3.3.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI void glfwSetX11SelectionString(const char* string);
|
||||
|
||||
/*! @brief Returns the contents of the current primary selection as a string.
|
||||
*
|
||||
* If the selection is empty or if its contents cannot be converted, `NULL`
|
||||
* is returned and a @ref GLFW_FORMAT_UNAVAILABLE error is generated.
|
||||
*
|
||||
* @return The contents of the selection as a UTF-8 encoded string, or `NULL`
|
||||
* if an [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
|
||||
* GLFW_PLATFORM_ERROR.
|
||||
*
|
||||
* @pointer_lifetime The returned string is allocated and freed by GLFW. You
|
||||
* should not free it yourself. It is valid until the next call to @ref
|
||||
* glfwGetX11SelectionString or @ref glfwSetX11SelectionString, or until the
|
||||
* library is terminated.
|
||||
*
|
||||
* @thread_safety This function must only be called from the main thread.
|
||||
*
|
||||
* @sa @ref clipboard
|
||||
* @sa glfwSetX11SelectionString
|
||||
* @sa glfwGetClipboardString
|
||||
*
|
||||
* @since Added in version 3.3.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI const char* glfwGetX11SelectionString(void);
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_GLX)
|
||||
/*! @brief Returns the `GLXContext` of the specified window.
|
||||
*
|
||||
* @return The `GLXContext` of the specified window, or `NULL` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref
|
||||
* GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.0.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window);
|
||||
|
||||
/*! @brief Returns the `GLXWindow` of the specified window.
|
||||
*
|
||||
* @return The `GLXWindow` of the specified window, or `None` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref
|
||||
* GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.2.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window);
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
|
||||
/*! @brief Returns the `struct wl_display*` used by GLFW.
|
||||
*
|
||||
* @return The `struct wl_display*` used by GLFW, or `NULL` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.2.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI struct wl_display* glfwGetWaylandDisplay(void);
|
||||
|
||||
/*! @brief Returns the `struct wl_output*` of the specified monitor.
|
||||
*
|
||||
* @return The `struct wl_output*` of the specified monitor, or `NULL` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.2.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor);
|
||||
|
||||
/*! @brief Returns the main `struct wl_surface*` of the specified window.
|
||||
*
|
||||
* @return The main `struct wl_surface*` of the specified window, or `NULL` if
|
||||
* an [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.2.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window);
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_EGL)
|
||||
/*! @brief Returns the `EGLDisplay` used by GLFW.
|
||||
*
|
||||
* @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @remark Because EGL is initialized on demand, this function will return
|
||||
* `EGL_NO_DISPLAY` until the first context has been created via EGL.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.0.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI EGLDisplay glfwGetEGLDisplay(void);
|
||||
|
||||
/*! @brief Returns the `EGLContext` of the specified window.
|
||||
*
|
||||
* @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref
|
||||
* GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.0.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window);
|
||||
|
||||
/*! @brief Returns the `EGLSurface` of the specified window.
|
||||
*
|
||||
* @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref
|
||||
* GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.0.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window);
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_OSMESA)
|
||||
/*! @brief Retrieves the color buffer associated with the specified window.
|
||||
*
|
||||
* @param[in] window The window whose color buffer to retrieve.
|
||||
* @param[out] width Where to store the width of the color buffer, or `NULL`.
|
||||
* @param[out] height Where to store the height of the color buffer, or `NULL`.
|
||||
* @param[out] format Where to store the OSMesa pixel format of the color
|
||||
* buffer, or `NULL`.
|
||||
* @param[out] buffer Where to store the address of the color buffer, or
|
||||
* `NULL`.
|
||||
* @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref
|
||||
* GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.3.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* window, int* width, int* height, int* format, void** buffer);
|
||||
|
||||
/*! @brief Retrieves the depth buffer associated with the specified window.
|
||||
*
|
||||
* @param[in] window The window whose depth buffer to retrieve.
|
||||
* @param[out] width Where to store the width of the depth buffer, or `NULL`.
|
||||
* @param[out] height Where to store the height of the depth buffer, or `NULL`.
|
||||
* @param[out] bytesPerValue Where to store the number of bytes per depth
|
||||
* buffer element, or `NULL`.
|
||||
* @param[out] buffer Where to store the address of the depth buffer, or
|
||||
* `NULL`.
|
||||
* @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref
|
||||
* GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.3.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height, int* bytesPerValue, void** buffer);
|
||||
|
||||
/*! @brief Returns the `OSMesaContext` of the specified window.
|
||||
*
|
||||
* @return The `OSMesaContext` of the specified window, or `NULL` if an
|
||||
* [error](@ref error_handling) occurred.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref
|
||||
* GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. Access is not
|
||||
* synchronized.
|
||||
*
|
||||
* @since Added in version 3.3.
|
||||
*
|
||||
* @ingroup native
|
||||
*/
|
||||
GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* window);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _glfw3_native_h_ */
|
||||
|
||||
439
source/engine/thirdparty/pl_mpeg/pl_mpeg_player.c
vendored
439
source/engine/thirdparty/pl_mpeg/pl_mpeg_player.c
vendored
@@ -1,439 +0,0 @@
|
||||
/*
|
||||
PL_MPEG Example - Video player using SDL2/OpenGL for rendering
|
||||
|
||||
Dominic Szablewski - https://phoboslab.org
|
||||
|
||||
|
||||
-- LICENSE: The MIT License(MIT)
|
||||
|
||||
Copyright(c) 2019 Dominic Szablewski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files(the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions :
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
-- Usage
|
||||
|
||||
plmpeg-player <video-file.mpg>
|
||||
|
||||
Use the arrow keys to seek forward/backward by 3 seconds. Click anywhere on the
|
||||
window to seek to seek through the whole file.
|
||||
|
||||
|
||||
-- About
|
||||
|
||||
This program demonstrates a simple video/audio player using plmpeg for decoding
|
||||
and SDL2 with OpenGL for rendering and sound output. It was tested on Windows
|
||||
using Microsoft Visual Studio 2015 and on macOS using XCode 10.2
|
||||
|
||||
This program can be configured to either convert the raw YCrCb data to RGB on
|
||||
the GPU (default), or to do it on CPU. Just pass APP_TEXTURE_MODE_RGB to
|
||||
app_create() to switch to do the conversion on the CPU.
|
||||
|
||||
YCrCb->RGB conversion on the CPU is a very costly operation and should be
|
||||
avoided if possible. It easily takes as much time as all other mpeg1 decoding
|
||||
steps combined.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
// OSX
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glext.h>
|
||||
|
||||
void glCreateTextures(GLuint ignored, GLsizei n, GLuint *name) {
|
||||
glGenTextures(1, name);
|
||||
}
|
||||
#elif defined(__unix__)
|
||||
// Linux
|
||||
#include <SDL2/SDL.h>
|
||||
#include <GL/glew.h>
|
||||
#else
|
||||
// WINDOWS
|
||||
#include <windows.h>
|
||||
|
||||
#define GL3_PROTOTYPES 1
|
||||
#include <GL/glew.h>
|
||||
#pragma comment(lib, "glew32.lib")
|
||||
|
||||
#include <gl/GL.h>
|
||||
#pragma comment(lib, "opengl32.lib")
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_opengl.h>
|
||||
#pragma comment(lib, "SDL2.lib")
|
||||
#pragma comment(lib, "SDL2main.lib")
|
||||
#endif
|
||||
|
||||
#define PL_MPEG_IMPLEMENTATION
|
||||
#include "pl_mpeg.h"
|
||||
|
||||
|
||||
#define APP_SHADER_SOURCE(...) #__VA_ARGS__
|
||||
|
||||
const char * const APP_VERTEX_SHADER = APP_SHADER_SOURCE(
|
||||
attribute vec2 vertex;
|
||||
varying vec2 tex_coord;
|
||||
|
||||
void main() {
|
||||
tex_coord = vertex;
|
||||
gl_Position = vec4((vertex * 2.0 - 1.0) * vec2(1, -1), 0.0, 1.0);
|
||||
}
|
||||
);
|
||||
|
||||
const char * const APP_FRAGMENT_SHADER_YCRCB = APP_SHADER_SOURCE(
|
||||
uniform sampler2D texture_y;
|
||||
uniform sampler2D texture_cb;
|
||||
uniform sampler2D texture_cr;
|
||||
varying vec2 tex_coord;
|
||||
|
||||
mat4 rec601 = mat4(
|
||||
1.16438, 0.00000, 1.59603, -0.87079,
|
||||
1.16438, -0.39176, -0.81297, 0.52959,
|
||||
1.16438, 2.01723, 0.00000, -1.08139,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
|
||||
void main() {
|
||||
float y = texture2D(texture_y, tex_coord).r;
|
||||
float cb = texture2D(texture_cb, tex_coord).r;
|
||||
float cr = texture2D(texture_cr, tex_coord).r;
|
||||
|
||||
gl_FragColor = vec4(y, cb, cr, 1.0) * rec601;
|
||||
}
|
||||
);
|
||||
|
||||
const char * const APP_FRAGMENT_SHADER_RGB = APP_SHADER_SOURCE(
|
||||
uniform sampler2D texture_rgb;
|
||||
varying vec2 tex_coord;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = vec4(texture2D(texture_rgb, tex_coord).rgb, 1.0);
|
||||
}
|
||||
);
|
||||
|
||||
#undef APP_SHADER_SOURCE
|
||||
|
||||
#define APP_TEXTURE_MODE_YCRCB 1
|
||||
#define APP_TEXTURE_MODE_RGB 2
|
||||
|
||||
typedef struct {
|
||||
plm_t *plm;
|
||||
double last_time;
|
||||
int wants_to_quit;
|
||||
|
||||
SDL_Window *window;
|
||||
SDL_AudioDeviceID audio_device;
|
||||
|
||||
SDL_GLContext gl;
|
||||
|
||||
GLuint shader_program;
|
||||
GLuint vertex_shader;
|
||||
GLuint fragment_shader;
|
||||
|
||||
int texture_mode;
|
||||
GLuint texture_y;
|
||||
GLuint texture_cb;
|
||||
GLuint texture_cr;
|
||||
|
||||
GLuint texture_rgb;
|
||||
uint8_t *rgb_data;
|
||||
} app_t;
|
||||
|
||||
app_t * app_create(const char *filename, int texture_mode);
|
||||
void app_update(app_t *self);
|
||||
void app_destroy(app_t *self);
|
||||
|
||||
GLuint app_compile_shader(app_t *self, GLenum type, const char *source);
|
||||
GLuint app_create_texture(app_t *self, GLuint index, const char *name);
|
||||
void app_update_texture(app_t *self, GLuint unit, GLuint texture, plm_plane_t *plane);
|
||||
|
||||
void app_on_video(plm_t *player, plm_frame_t *frame, void *user);
|
||||
void app_on_audio(plm_t *player, plm_samples_t *samples, void *user);
|
||||
|
||||
|
||||
|
||||
app_t * app_create(const char *filename, int texture_mode) {
|
||||
app_t *self = (app_t *)malloc(sizeof(app_t));
|
||||
memset(self, 0, sizeof(app_t));
|
||||
|
||||
self->texture_mode = texture_mode;
|
||||
|
||||
// Initialize plmpeg, load the video file, install decode callbacks
|
||||
self->plm = plm_create_with_filename(filename);
|
||||
if (!self->plm) {
|
||||
SDL_Log("Couldn't open %s", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int samplerate = plm_get_samplerate(self->plm);
|
||||
|
||||
SDL_Log(
|
||||
"Opened %s - framerate: %f, samplerate: %d, duration: %f",
|
||||
filename,
|
||||
plm_get_framerate(self->plm),
|
||||
plm_get_samplerate(self->plm),
|
||||
plm_get_duration(self->plm)
|
||||
);
|
||||
|
||||
plm_set_video_decode_callback(self->plm, app_on_video, self);
|
||||
plm_set_audio_decode_callback(self->plm, app_on_audio, self);
|
||||
|
||||
plm_set_loop(self->plm, TRUE);
|
||||
plm_set_audio_enabled(self->plm, TRUE);
|
||||
plm_set_audio_stream(self->plm, 0);
|
||||
|
||||
if (plm_get_num_audio_streams(self->plm) > 0) {
|
||||
// Initialize SDL Audio
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
||||
SDL_AudioSpec audio_spec;
|
||||
SDL_memset(&audio_spec, 0, sizeof(audio_spec));
|
||||
audio_spec.freq = samplerate;
|
||||
audio_spec.format = AUDIO_F32;
|
||||
audio_spec.channels = 2;
|
||||
audio_spec.samples = 4096;
|
||||
|
||||
self->audio_device = SDL_OpenAudioDevice(NULL, 0, &audio_spec, NULL, 0);
|
||||
if (self->audio_device == 0) {
|
||||
SDL_Log("Failed to open audio device: %s", SDL_GetError());
|
||||
}
|
||||
SDL_PauseAudioDevice(self->audio_device, 0);
|
||||
|
||||
// Adjust the audio lead time according to the audio_spec buffer size
|
||||
plm_set_audio_lead_time(self->plm, (double)audio_spec.samples / (double)samplerate);
|
||||
}
|
||||
|
||||
// Create SDL Window
|
||||
self->window = SDL_CreateWindow(
|
||||
"pl_mpeg",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
plm_get_width(self->plm), plm_get_height(self->plm),
|
||||
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE
|
||||
);
|
||||
self->gl = SDL_GL_CreateContext(self->window);
|
||||
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
// OSX
|
||||
// (nothing to do here)
|
||||
#else
|
||||
// Windows, Linux
|
||||
glewExperimental = GL_TRUE;
|
||||
glewInit();
|
||||
#endif
|
||||
|
||||
|
||||
// Setup OpenGL shaders and textures
|
||||
const char * fsh = self->texture_mode == APP_TEXTURE_MODE_YCRCB
|
||||
? APP_FRAGMENT_SHADER_YCRCB
|
||||
: APP_FRAGMENT_SHADER_RGB;
|
||||
|
||||
self->fragment_shader = app_compile_shader(self, GL_FRAGMENT_SHADER, fsh);
|
||||
self->vertex_shader = app_compile_shader(self, GL_VERTEX_SHADER, APP_VERTEX_SHADER);
|
||||
|
||||
self->shader_program = glCreateProgram();
|
||||
glAttachShader(self->shader_program, self->vertex_shader);
|
||||
glAttachShader(self->shader_program, self->fragment_shader);
|
||||
glLinkProgram(self->shader_program);
|
||||
glUseProgram(self->shader_program);
|
||||
|
||||
// Create textures for YCrCb or RGB rendering
|
||||
if (self->texture_mode == APP_TEXTURE_MODE_YCRCB) {
|
||||
self->texture_y = app_create_texture(self, 0, "texture_y");
|
||||
self->texture_cb = app_create_texture(self, 1, "texture_cb");
|
||||
self->texture_cr = app_create_texture(self, 2, "texture_cr");
|
||||
}
|
||||
else {
|
||||
self->texture_rgb = app_create_texture(self, 0, "texture_rgb");
|
||||
int num_pixels = plm_get_width(self->plm) * plm_get_height(self->plm);
|
||||
self->rgb_data = (uint8_t*)malloc(num_pixels * 3);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
void app_destroy(app_t *self) {
|
||||
plm_destroy(self->plm);
|
||||
|
||||
if (self->texture_mode == APP_TEXTURE_MODE_RGB) {
|
||||
free(self->rgb_data);
|
||||
}
|
||||
|
||||
if (self->audio_device) {
|
||||
SDL_CloseAudioDevice(self->audio_device);
|
||||
}
|
||||
|
||||
SDL_GL_DeleteContext(self->gl);
|
||||
SDL_Quit();
|
||||
|
||||
free(self);
|
||||
}
|
||||
|
||||
void app_update(app_t *self) {
|
||||
double seek_to = -1;
|
||||
|
||||
SDL_Event ev;
|
||||
while (SDL_PollEvent(&ev)) {
|
||||
if (
|
||||
ev.type == SDL_QUIT ||
|
||||
(ev.type == SDL_KEYUP && ev.key.keysym.sym == SDLK_ESCAPE)
|
||||
) {
|
||||
self->wants_to_quit = TRUE;
|
||||
}
|
||||
|
||||
if (
|
||||
ev.type == SDL_WINDOWEVENT &&
|
||||
ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED
|
||||
) {
|
||||
glViewport(0, 0, ev.window.data1, ev.window.data2);
|
||||
}
|
||||
|
||||
// Seek 3sec forward/backward using arrow keys
|
||||
if (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_RIGHT) {
|
||||
seek_to = plm_get_time(self->plm) + 3;
|
||||
}
|
||||
else if (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_LEFT) {
|
||||
seek_to = plm_get_time(self->plm) - 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Compute the delta time since the last app_update(), limit max step to
|
||||
// 1/30th of a second
|
||||
double current_time = (double)SDL_GetTicks() / 1000.0;
|
||||
double elapsed_time = current_time - self->last_time;
|
||||
if (elapsed_time > 1.0 / 30.0) {
|
||||
elapsed_time = 1.0 / 30.0;
|
||||
}
|
||||
self->last_time = current_time;
|
||||
|
||||
// Seek using mouse position
|
||||
int mouse_x, mouse_y;
|
||||
if (SDL_GetMouseState(&mouse_x, &mouse_y) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
|
||||
int sx, sy;
|
||||
SDL_GetWindowSize(self->window, &sx, &sy);
|
||||
seek_to = plm_get_duration(self->plm) * ((float)mouse_x / (float)sx);
|
||||
}
|
||||
|
||||
// Seek or advance decode
|
||||
if (seek_to != -1) {
|
||||
SDL_ClearQueuedAudio(self->audio_device);
|
||||
plm_seek(self->plm, seek_to, FALSE);
|
||||
}
|
||||
else {
|
||||
plm_decode(self->plm, elapsed_time);
|
||||
}
|
||||
|
||||
if (plm_has_ended(self->plm)) {
|
||||
self->wants_to_quit = TRUE;
|
||||
}
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glRectf(0.0, 0.0, 1.0, 1.0);
|
||||
SDL_GL_SwapWindow(self->window);
|
||||
}
|
||||
|
||||
GLuint app_compile_shader(app_t *self, GLenum type, const char *source) {
|
||||
GLuint shader = glCreateShader(type);
|
||||
glShaderSource(shader, 1, &source, NULL);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint success;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
int log_written;
|
||||
char log[256];
|
||||
glGetShaderInfoLog(shader, 256, &log_written, log);
|
||||
SDL_Log("Error compiling shader: %s.\n", log);
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
GLuint app_create_texture(app_t *self, GLuint index, const char *name) {
|
||||
GLuint texture;
|
||||
glCreateTextures(GL_TEXTURE_2D, 1, &texture);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glUniform1i(glGetUniformLocation(self->shader_program, name), index);
|
||||
return texture;
|
||||
}
|
||||
|
||||
void app_update_texture(app_t *self, GLuint unit, GLuint texture, plm_plane_t *plane) {
|
||||
glActiveTexture(unit);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_LUMINANCE, plane->width, plane->height, 0,
|
||||
GL_LUMINANCE, GL_UNSIGNED_BYTE, plane->data
|
||||
);
|
||||
}
|
||||
|
||||
void app_on_video(plm_t *mpeg, plm_frame_t *frame, void *user) {
|
||||
app_t *self = (app_t *)user;
|
||||
|
||||
// Hand the decoded data over to OpenGL. For the RGB texture mode, the
|
||||
// YCrCb->RGB conversion is done on the CPU.
|
||||
|
||||
if (self->texture_mode == APP_TEXTURE_MODE_YCRCB) {
|
||||
app_update_texture(self, GL_TEXTURE0, self->texture_y, &frame->y);
|
||||
app_update_texture(self, GL_TEXTURE1, self->texture_cb, &frame->cb);
|
||||
app_update_texture(self, GL_TEXTURE2, self->texture_cr, &frame->cr);
|
||||
}
|
||||
else {
|
||||
plm_frame_to_rgb(frame, self->rgb_data, frame->width * 3);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, self->texture_rgb);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_RGB, frame->width, frame->height, 0,
|
||||
GL_RGB, GL_UNSIGNED_BYTE, self->rgb_data
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void app_on_audio(plm_t *mpeg, plm_samples_t *samples, void *user) {
|
||||
app_t *self = (app_t *)user;
|
||||
|
||||
// Hand the decoded samples over to SDL
|
||||
|
||||
int size = sizeof(float) * samples->count * 2;
|
||||
SDL_QueueAudio(self->audio_device, samples->interleaved, size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) {
|
||||
SDL_Log("Usage: pl_mpeg_player <file.mpg>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
app_t *app = app_create(argv[1], APP_TEXTURE_MODE_YCRCB);
|
||||
while (!app->wants_to_quit) {
|
||||
app_update(app);
|
||||
}
|
||||
app_destroy(app);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -10,13 +10,13 @@
|
||||
|
||||
#include "stb_ds.h"
|
||||
|
||||
struct mSDLWindow *mainwin;
|
||||
struct window *mainwin;
|
||||
|
||||
static struct mSDLWindow *windows = NULL;
|
||||
static struct window *windows = NULL;
|
||||
|
||||
struct Texture *icon = NULL;
|
||||
|
||||
int is_win(struct mSDLWindow *s, GLFWwindow *w)
|
||||
int is_win(struct window *s, GLFWwindow *w)
|
||||
{
|
||||
return s->window == w;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ void window_size_callback(GLFWwindow *w)
|
||||
|
||||
}
|
||||
|
||||
struct mSDLWindow *winfind(GLFWwindow *w)
|
||||
struct window *winfind(GLFWwindow *w)
|
||||
{
|
||||
for (int i = 0; i < arrlen(windows); i++) {
|
||||
if (windows[i].window == w)
|
||||
@@ -38,24 +38,24 @@ struct mSDLWindow *winfind(GLFWwindow *w)
|
||||
|
||||
void window_iconify_callback(GLFWwindow *w, int iconified)
|
||||
{
|
||||
struct mSDLWindow *win = winfind(w);
|
||||
struct window *win = winfind(w);
|
||||
win->iconified = iconified;
|
||||
}
|
||||
|
||||
void window_focus_callback(GLFWwindow *w, int focused)
|
||||
{
|
||||
struct mSDLWindow *win = winfind(w);
|
||||
struct window *win = winfind(w);
|
||||
}
|
||||
|
||||
void window_maximize_callback(GLFWwindow *w, int maximized)
|
||||
{
|
||||
struct mSDLWindow *win = winfind(w);
|
||||
struct window *win = winfind(w);
|
||||
win->minimized = !maximized;
|
||||
}
|
||||
|
||||
void window_framebuffer_size_cb(GLFWwindow *w, int width, int height)
|
||||
{
|
||||
struct mSDLWindow *win = winfind(w);
|
||||
struct window *win = winfind(w);
|
||||
win->width = width;
|
||||
win->height = height;
|
||||
window_makecurrent(win);
|
||||
@@ -69,14 +69,14 @@ void window_close_callback(GLFWwindow *w)
|
||||
|
||||
|
||||
|
||||
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height, uint32_t flags)
|
||||
struct window *MakeSDLWindow(const char *name, int width, int height, uint32_t flags)
|
||||
{
|
||||
if (arrcap(windows) == 0)
|
||||
arrsetcap(windows, 5);
|
||||
|
||||
GLFWwindow *sharewin = mainwin == NULL ? NULL : mainwin->window;
|
||||
|
||||
struct mSDLWindow w = {
|
||||
struct window w = {
|
||||
.width = width,
|
||||
.height = height,
|
||||
.id = arrlen(windows),
|
||||
@@ -88,10 +88,6 @@ struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height, uint32
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (icon) window_seticon(&w, icon);
|
||||
|
||||
glfwMakeContextCurrent(w.window);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
@@ -118,17 +114,17 @@ void window_set_icon(const char *png)
|
||||
icon = texture_pullfromfile(png);
|
||||
}
|
||||
|
||||
void window_destroy(struct mSDLWindow *w)
|
||||
void window_destroy(struct window *w)
|
||||
{
|
||||
glfwDestroyWindow(w->window);
|
||||
arrdelswap(windows, w->id);
|
||||
}
|
||||
|
||||
struct mSDLWindow *window_i(int index) {
|
||||
struct window *window_i(int index) {
|
||||
return &windows[index];
|
||||
}
|
||||
|
||||
void window_handle_event(struct mSDLWindow *w)
|
||||
void window_handle_event(struct window *w)
|
||||
{
|
||||
/*
|
||||
if (e->type == SDL_WINDOWEVENT && e->window.windowID == w->id) { // TODO: Check ptr direct?
|
||||
@@ -216,19 +212,19 @@ void window_all_handle_events()
|
||||
arrwalk(windows, window_handle_event);
|
||||
}
|
||||
|
||||
void window_makefullscreen(struct mSDLWindow *w)
|
||||
void window_makefullscreen(struct window *w)
|
||||
{
|
||||
if (!w->fullscreen)
|
||||
window_togglefullscreen(w);
|
||||
}
|
||||
|
||||
void window_unfullscreen(struct mSDLWindow *w)
|
||||
void window_unfullscreen(struct window *w)
|
||||
{
|
||||
if (w->fullscreen)
|
||||
window_togglefullscreen(w);
|
||||
}
|
||||
|
||||
void window_togglefullscreen(struct mSDLWindow *w)
|
||||
void window_togglefullscreen(struct window *w)
|
||||
{
|
||||
w->fullscreen = !w->fullscreen;
|
||||
|
||||
@@ -240,7 +236,7 @@ void window_togglefullscreen(struct mSDLWindow *w)
|
||||
|
||||
}
|
||||
|
||||
void window_makecurrent(struct mSDLWindow *w)
|
||||
void window_makecurrent(struct window *w)
|
||||
{
|
||||
|
||||
if (w->window != glfwGetCurrentContext())
|
||||
@@ -251,12 +247,12 @@ void window_makecurrent(struct mSDLWindow *w)
|
||||
|
||||
|
||||
|
||||
void window_swap(struct mSDLWindow *w)
|
||||
void window_swap(struct window *w)
|
||||
{
|
||||
glfwSwapBuffers(w->window);
|
||||
}
|
||||
|
||||
void window_seticon(struct mSDLWindow *w, struct Texture *icon)
|
||||
void window_seticon(struct window *w, struct Texture *icon)
|
||||
{
|
||||
|
||||
static GLFWimage images[1];
|
||||
@@ -267,12 +263,12 @@ void window_seticon(struct mSDLWindow *w, struct Texture *icon)
|
||||
|
||||
}
|
||||
|
||||
int window_hasfocus(struct mSDLWindow *w)
|
||||
int window_hasfocus(struct window *w)
|
||||
{
|
||||
return glfwGetWindowAttrib(w->window, GLFW_FOCUSED);
|
||||
}
|
||||
|
||||
void window_render(struct mSDLWindow *w) {
|
||||
void window_render(struct window *w) {
|
||||
window_makecurrent(w);
|
||||
openglRender(w);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "mruby.h"
|
||||
|
||||
struct mSDLWindow {
|
||||
struct window {
|
||||
GLFWwindow *window;
|
||||
int id;
|
||||
int width;
|
||||
@@ -28,24 +28,24 @@ struct mSDLWindow {
|
||||
|
||||
struct Texture;
|
||||
|
||||
extern struct mSDLWindow *mainwin;
|
||||
extern struct window *mainwin;
|
||||
|
||||
|
||||
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height, uint32_t flags);
|
||||
struct window *MakeSDLWindow(const char *name, int width, int height, uint32_t flags);
|
||||
void window_set_icon(const char *png);
|
||||
void window_destroy(struct mSDLWindow *w);
|
||||
void window_handle_event(struct mSDLWindow *w);
|
||||
void window_destroy(struct window *w);
|
||||
void window_handle_event(struct window *w);
|
||||
void window_all_handle_events();
|
||||
void window_makecurrent(struct mSDLWindow *w);
|
||||
void window_makefullscreen(struct mSDLWindow *w);
|
||||
void window_togglefullscreen(struct mSDLWindow *w);
|
||||
void window_unfullscreen(struct mSDLWindow *w);
|
||||
void window_swap(struct mSDLWindow *w);
|
||||
void window_seticon(struct mSDLWindow *w, struct Texture *icon);
|
||||
int window_hasfocus(struct mSDLWindow *w);
|
||||
struct mSDLWindow *window_i(int index);
|
||||
void window_makecurrent(struct window *w);
|
||||
void window_makefullscreen(struct window *w);
|
||||
void window_togglefullscreen(struct window *w);
|
||||
void window_unfullscreen(struct window *w);
|
||||
void window_swap(struct window *w);
|
||||
void window_seticon(struct window *w, struct Texture *icon);
|
||||
int window_hasfocus(struct window *w);
|
||||
struct window *window_i(int index);
|
||||
|
||||
void window_render(struct mSDLWindow *w);
|
||||
void window_render(struct window *w);
|
||||
void window_renderall();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -63,7 +63,7 @@ int main(int argc, char **args) {
|
||||
elapsed = glfwGetTime() - lastTick;
|
||||
lastTick = glfwGetTime();
|
||||
|
||||
timer_update(lastTick);
|
||||
//timer_update(lastTick);
|
||||
|
||||
//renderlag += elapsed;
|
||||
//physlag += elapsed;
|
||||
@@ -79,4 +79,6 @@ int main(int argc, char **args) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user