Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9114abb2d | |||
| 734cab010e | |||
| 20986a8947 | |||
| 4c0eabcc5c | |||
| a45cb95030 | |||
| 4016118375 | |||
| eea4a67542 | |||
| 752a065246 | |||
| 916f0a458e | |||
| 669090238a | |||
| 7ada99f766 | |||
| 27c122f5bb | |||
| a77a4bd364 | |||
| bee9b2e489 |
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
x=0
|
x=0
|
||||||
rot=0
|
rot=0
|
||||||
|
music_states = { "INVALID", "PLAYING", "PAUSED", "STOPPED", "DISABLED" }
|
||||||
|
music_pos = 0
|
||||||
|
|
||||||
function mini.init()
|
function mini.init()
|
||||||
s = surf.load("gfx/logo.gif")
|
s = surf.load("gfx/logo.gif")
|
||||||
@@ -18,6 +20,7 @@ function mini.init()
|
|||||||
print("========================")
|
print("========================")
|
||||||
|
|
||||||
f = font.load("font.fnt")
|
f = font.load("font.fnt")
|
||||||
|
--music.play("mus_menu.ogg")
|
||||||
end
|
end
|
||||||
|
|
||||||
function mini.update()
|
function mini.update()
|
||||||
@@ -50,4 +53,30 @@ function mini.update()
|
|||||||
draw.text("0146",100,50,28)
|
draw.text("0146",100,50,28)
|
||||||
font.current(font.DEFAULT)
|
font.current(font.DEFAULT)
|
||||||
rot=rot+1
|
rot=rot+1
|
||||||
|
|
||||||
|
-- MUSICA
|
||||||
|
draw.text("music:", 1, 20, 22)
|
||||||
|
draw.text("duration:" .. music.duration(), 1, 28, 28)
|
||||||
|
draw.text("position:" .. music.pos(), 1, 36, 28)
|
||||||
|
draw.text("state: " .. music_states[music.state()+1], 1, 44, 28)
|
||||||
|
|
||||||
|
if key.press(key.P) then
|
||||||
|
if music.state() == music.PLAYING then
|
||||||
|
music.pause()
|
||||||
|
elseif music.state() == music.PAUSED then
|
||||||
|
music.resume()
|
||||||
|
else
|
||||||
|
music.play("mus_menu.ogg")
|
||||||
|
end
|
||||||
|
elseif key.press(key.S) then
|
||||||
|
music.stop()
|
||||||
|
elseif key.press(key.C) then
|
||||||
|
if music.state() == music.PLAYING then
|
||||||
|
music_pos = music.pos()
|
||||||
|
music.stop()
|
||||||
|
else
|
||||||
|
music.play("mus_menu.ogg")
|
||||||
|
music.pos(music_pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Binary file not shown.
@@ -25,3 +25,19 @@ libs = -lmingw32 -lSDL3 -lopengl32
|
|||||||
executable = mini_debug.exe
|
executable = mini_debug.exe
|
||||||
sourcepath = source+
|
sourcepath = source+
|
||||||
buildpath = build
|
buildpath = build
|
||||||
|
|
||||||
|
[macos]
|
||||||
|
compiler = clang++
|
||||||
|
cppflags = -Wall -Os -Wno-deprecated -ffunction-sections -fdata-sections -std=c++20 -Isource
|
||||||
|
libs = -lSDL3 -framework OpenGL
|
||||||
|
executable = mini
|
||||||
|
sourcepath = source+
|
||||||
|
buildpath = build
|
||||||
|
|
||||||
|
[macos_debug]
|
||||||
|
compiler = clang++
|
||||||
|
cppflags = -D DEBUG -g -Wall -Wno-deprecated -std=c++20 -Isource
|
||||||
|
libs = -lSDL3 -framework OpenGL
|
||||||
|
executable = mini_debug
|
||||||
|
sourcepath = source+
|
||||||
|
buildpath = build
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#ifndef JA_USESDLMIXER
|
#if BACKEND == SDL3
|
||||||
#include "jail_audio.h"
|
|
||||||
|
#include "backends/backend.h"
|
||||||
|
#include "state.h"
|
||||||
#include "external/stb_vorbis.h"
|
#include "external/stb_vorbis.h"
|
||||||
#include "other/log.h"
|
#include "other/log.h"
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// structs i variables
|
// structs i variables
|
||||||
// =============================
|
// =============================
|
||||||
namespace jail
|
namespace backend
|
||||||
{
|
{
|
||||||
namespace audio
|
namespace audio
|
||||||
{
|
{
|
||||||
@@ -22,14 +22,17 @@ namespace jail
|
|||||||
{
|
{
|
||||||
struct music_t
|
struct music_t
|
||||||
{
|
{
|
||||||
SDL_AudioSpec spec { SDL_AUDIO_S16, 2, 48000 };
|
SDL_AudioSpec spec { SDL_AUDIO_S16, 2, 48000 };
|
||||||
Uint32 length { 0 };
|
SDL_AudioStream* stream { nullptr };
|
||||||
Uint8 *buffer { nullptr };
|
|
||||||
|
|
||||||
int pos { 0 };
|
const uint8_t* ogg_data { nullptr };
|
||||||
int times { 0 };
|
uint32_t ogg_length { 0 };
|
||||||
SDL_AudioStream *stream { nullptr };
|
|
||||||
music::state state { music::state::invalid };
|
stb_vorbis* vorbis { nullptr };
|
||||||
|
stb_vorbis_info info {};
|
||||||
|
|
||||||
|
int times { 0 };
|
||||||
|
music::state state { music::state::invalid };
|
||||||
};
|
};
|
||||||
|
|
||||||
static int current { -1 };
|
static int current { -1 };
|
||||||
@@ -79,17 +82,19 @@ namespace jail
|
|||||||
|
|
||||||
// Funcions
|
// Funcions
|
||||||
// ==================
|
// ==================
|
||||||
namespace jail
|
namespace backend
|
||||||
{
|
{
|
||||||
namespace audio
|
namespace audio
|
||||||
{
|
{
|
||||||
static void updateMusic()
|
static void updateMusic()
|
||||||
{
|
{
|
||||||
if (!music::enabled) return;
|
if (!music::enabled) return;
|
||||||
if (music::current < 0 || music::current > static_cast<int>(music::musics.size())) return;
|
if (music::current < 0) return;
|
||||||
auto &m = music::musics[music::current];
|
|
||||||
|
auto& m = music::musics[music::current];
|
||||||
if (m.state != music::state::playing) return;
|
if (m.state != music::state::playing) return;
|
||||||
|
|
||||||
|
// Fade-out
|
||||||
if (music::fade::fading) {
|
if (music::fade::fading) {
|
||||||
int time = SDL_GetTicks();
|
int time = SDL_GetTicks();
|
||||||
if (time > (music::fade::start_time + music::fade::duration)) {
|
if (time > (music::fade::start_time + music::fade::duration)) {
|
||||||
@@ -97,23 +102,37 @@ namespace jail
|
|||||||
music::stop();
|
music::stop();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const int time_passed = time - music::fade::start_time;
|
float percent = float(time - music::fade::start_time) / float(music::fade::duration);
|
||||||
const float percent = (float)time_passed / (float)music::fade::duration;
|
SDL_SetAudioStreamGain(m.stream, 1.0f - percent);
|
||||||
SDL_SetAudioStreamGain(m.stream, 1.0 - percent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m.times != 0)
|
// ¿Hay suficiente audio en el stream?
|
||||||
{
|
if (SDL_GetAudioStreamAvailable(m.stream) > 48000) return; // 1 segundo
|
||||||
if (SDL_GetAudioStreamAvailable(m.stream) < static_cast<int>(m.length/2)) {
|
|
||||||
SDL_PutAudioStreamData(m.stream, m.buffer, m.length);
|
// Decodificar un bloque
|
||||||
|
const int SAMPLES = 4096;
|
||||||
|
static int16_t temp[SAMPLES * 2];
|
||||||
|
|
||||||
|
int n = stb_vorbis_get_samples_short_interleaved(
|
||||||
|
m.vorbis,
|
||||||
|
m.info.channels,
|
||||||
|
temp,
|
||||||
|
SAMPLES
|
||||||
|
);
|
||||||
|
|
||||||
|
if (n == 0) {
|
||||||
|
if (m.times != 0) {
|
||||||
|
stb_vorbis_seek_start(m.vorbis);
|
||||||
|
if (m.times > 0) m.times--;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
music::stop();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (m.times>0) m.times--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (SDL_GetAudioStreamAvailable(m.stream) == 0) music::stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_PutAudioStreamData(m.stream, temp, n * m.info.channels * sizeof(int16_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateSound()
|
static void updateSound()
|
||||||
@@ -193,26 +212,31 @@ namespace jail
|
|||||||
{
|
{
|
||||||
int load(const uint8_t* buffer, uint32_t length)
|
int load(const uint8_t* buffer, uint32_t length)
|
||||||
{
|
{
|
||||||
int music = 0;
|
int idx = 0;
|
||||||
while (music < static_cast<int>(musics.size()) && musics[music].state != state::invalid) { music++; }
|
while (idx < (int)musics.size() && musics[idx].state != state::invalid) idx++;
|
||||||
if (music == static_cast<int>(musics.size())) musics.emplace_back();
|
if (idx == (int)musics.size()) musics.emplace_back();
|
||||||
|
|
||||||
auto &m = musics[music];
|
auto& m = musics[idx];
|
||||||
|
|
||||||
int chan, samplerate;
|
m.ogg_data = buffer;
|
||||||
short *output;
|
m.ogg_length = length;
|
||||||
m.length = stb_vorbis_decode_memory(buffer, length, &chan, &samplerate, &output) * chan * 2;
|
|
||||||
|
|
||||||
m.spec.channels = chan;
|
int error;
|
||||||
m.spec.freq = samplerate;
|
m.vorbis = stb_vorbis_open_memory(buffer, length, &error, nullptr);
|
||||||
|
if (!m.vorbis) {
|
||||||
|
log_msg(LOG_FAIL, "stb_vorbis_open_memory failed: %d\n", error);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
m.info = stb_vorbis_get_info(m.vorbis);
|
||||||
|
|
||||||
|
m.spec.channels = m.info.channels;
|
||||||
|
m.spec.freq = m.info.sample_rate;
|
||||||
m.spec.format = SDL_AUDIO_S16;
|
m.spec.format = SDL_AUDIO_S16;
|
||||||
m.buffer = (uint8_t*)SDL_malloc(m.length);
|
|
||||||
SDL_memcpy(m.buffer, output, m.length);
|
|
||||||
free(output);
|
|
||||||
m.pos = 0;
|
|
||||||
m.state = state::stopped;
|
m.state = state::stopped;
|
||||||
|
|
||||||
return music;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
int load(const char* filename)
|
int load(const char* filename)
|
||||||
@@ -235,23 +259,19 @@ namespace jail
|
|||||||
|
|
||||||
void play(int mus, int loop)
|
void play(int mus, int loop)
|
||||||
{
|
{
|
||||||
if (!music::enabled) return;
|
|
||||||
stop();
|
stop();
|
||||||
if (mus < 0 || mus >= static_cast<int>(musics.size())) {
|
|
||||||
log_msg(LOG_FAIL, "music::play: Illegal music handle: %i\n", mus);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
current = mus;
|
current = mus;
|
||||||
auto &m = musics[current];
|
auto& m = musics[mus];
|
||||||
m.pos = 0;
|
|
||||||
m.state = state::playing;
|
|
||||||
m.times = loop;
|
m.times = loop;
|
||||||
|
m.state = state::playing;
|
||||||
|
|
||||||
|
stb_vorbis_seek_start(m.vorbis);
|
||||||
|
|
||||||
m.stream = SDL_CreateAudioStream(&m.spec, &audioSpec);
|
m.stream = SDL_CreateAudioStream(&m.spec, &audioSpec);
|
||||||
if (!SDL_PutAudioStreamData(m.stream, m.buffer, m.length)) log_msg(LOG_FAIL, "SDL_PutAudioStreamData failed!\n");
|
|
||||||
SDL_SetAudioStreamGain(m.stream, volume);
|
SDL_SetAudioStreamGain(m.stream, volume);
|
||||||
if (!SDL_BindAudioStream(sdlAudioDevice, m.stream)) log_msg(LOG_FAIL, "SDL_BindAudioStream failed!\n");
|
SDL_BindAudioStream(sdlAudioDevice, m.stream);
|
||||||
//SDL_ResumeAudioStreamDevice(current->stream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pause()
|
void pause()
|
||||||
@@ -292,22 +312,15 @@ namespace jail
|
|||||||
|
|
||||||
void stop()
|
void stop()
|
||||||
{
|
{
|
||||||
if (!music::enabled || (current<0)) return;
|
if (current < 0) return;
|
||||||
if (current>static_cast<int>(musics.size())) {
|
|
||||||
log_msg(LOG_FAIL, "music::stop: Illegal music handle: %i\n", current);
|
auto& m = musics[current];
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto &m = musics[current];
|
|
||||||
if (m.state == state::invalid) {
|
|
||||||
log_msg(LOG_FAIL, "music::stop: Invalidated music handle: %i\n", current);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m.pos = 0;
|
|
||||||
m.state = state::stopped;
|
m.state = state::stopped;
|
||||||
//SDL_PauseAudioStreamDevice(current->stream);
|
|
||||||
SDL_DestroyAudioStream(m.stream);
|
if (m.stream) SDL_DestroyAudioStream(m.stream);
|
||||||
m.stream = nullptr;
|
m.stream = nullptr;
|
||||||
|
current = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fadeOut(int milliseconds)
|
void fadeOut(int milliseconds)
|
||||||
@@ -338,16 +351,16 @@ namespace jail
|
|||||||
|
|
||||||
void destroy(int mus)
|
void destroy(int mus)
|
||||||
{
|
{
|
||||||
if (current == mus) current = -1;
|
if (mus < 0 || mus >= (int)musics.size()) return;
|
||||||
if (mus<0 || mus>static_cast<int>(musics.size())) {
|
|
||||||
log_msg(LOG_FAIL, "music::destroy: Illegal music handle: %i\n", mus);
|
auto& m = musics[mus];
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto &m = musics[mus];
|
|
||||||
SDL_free(m.buffer);
|
|
||||||
m.buffer = nullptr;
|
|
||||||
if (m.stream) SDL_DestroyAudioStream(m.stream);
|
if (m.stream) SDL_DestroyAudioStream(m.stream);
|
||||||
|
if (m.vorbis) stb_vorbis_close(m.vorbis);
|
||||||
|
|
||||||
m.stream = nullptr;
|
m.stream = nullptr;
|
||||||
|
m.vorbis = nullptr;
|
||||||
|
|
||||||
m.state = state::invalid;
|
m.state = state::invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,34 +378,50 @@ namespace jail
|
|||||||
|
|
||||||
void setPosition(float value)
|
void setPosition(float value)
|
||||||
{
|
{
|
||||||
if (!music::enabled) return;
|
auto& m = musics[current];
|
||||||
if (current<0 || current>static_cast<int>(musics.size())) {
|
|
||||||
log_msg(LOG_FAIL, "music::setPosition: Illegal music handle: %i\n", current);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto &m = musics[current];
|
|
||||||
if (m.state == state::invalid) {
|
|
||||||
log_msg(LOG_FAIL, "music::setPosition: Invalidated music handle: %i\n", current);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m.pos = value * m.spec.freq;
|
int sample = int(value * m.info.sample_rate);
|
||||||
|
|
||||||
|
if (stb_vorbis_seek(m.vorbis, sample)) {
|
||||||
|
SDL_ClearAudioStream(m.stream); // importante
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float getPosition()
|
float getPosition()
|
||||||
{
|
{
|
||||||
if (!music::enabled) return 0;
|
if (!music::enabled) return 0;
|
||||||
if (current<0 || current>static_cast<int>(musics.size())) {
|
if (current<0 || current>static_cast<int>(musics.size())) {
|
||||||
log_msg(LOG_FAIL, "music::getPosition: Illegal music handle: %i\n", current);
|
//log_msg(LOG_FAIL, "music::getPosition: Illegal music handle: %i\n", current);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto &m = musics[current];
|
auto &m = musics[current];
|
||||||
if (m.state == state::invalid) {
|
if (m.state == state::invalid) {
|
||||||
log_msg(LOG_FAIL, "music::getPosition: Invalidated music handle: %i\n", current);
|
//log_msg(LOG_FAIL, "music::getPosition: Invalidated music handle: %i\n", current);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int sample = stb_vorbis_get_sample_offset(m.vorbis);
|
||||||
|
return float(sample) / float(m.info.sample_rate);
|
||||||
|
}
|
||||||
|
|
||||||
|
float getDuration()
|
||||||
|
{
|
||||||
|
if (!music::enabled) return 0;
|
||||||
|
if (current < 0 || current > static_cast<int>(musics.size())) {
|
||||||
|
//log_msg(LOG_FAIL, "music::getDuration: Illegal music handle: %i\n", current);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return float(m.pos)/float(m.spec.freq);
|
auto &m = musics[current];
|
||||||
|
if (m.state == state::invalid) {
|
||||||
|
//log_msg(LOG_FAIL, "music::getDuration: Invalidated music handle: %i\n", current);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Total de muestras del stream
|
||||||
|
int total_samples = stb_vorbis_stream_length_in_samples(m.vorbis);
|
||||||
|
|
||||||
|
// Convertir a segundos
|
||||||
|
return float(total_samples) / float(m.info.sample_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void enable(bool value)
|
void enable(bool value)
|
||||||
@@ -0,0 +1,246 @@
|
|||||||
|
#if BACKEND == SDL3
|
||||||
|
|
||||||
|
#include "backends/backend.h"
|
||||||
|
#include "state.h"
|
||||||
|
#include "mini/file/file.h"
|
||||||
|
#include "mini/win/win.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
#include <OpenGL/OpenGL.h>
|
||||||
|
|
||||||
|
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||||
|
#include <OpenGL/gl3.h>
|
||||||
|
#else
|
||||||
|
#include <OpenGL/gl.h>
|
||||||
|
#endif //!ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||||
|
#else
|
||||||
|
#include <SDL3/SDL_opengl.h>
|
||||||
|
#include <SDL3/SDL_opengl_glext.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace backend
|
||||||
|
{
|
||||||
|
namespace shader
|
||||||
|
{
|
||||||
|
GLuint programId = 0;
|
||||||
|
SDL_Point win_size = {640, 480};
|
||||||
|
SDL_FPoint tex_size = {320, 240};
|
||||||
|
bool can_use_opengl = false;
|
||||||
|
bool using_opengl = false;
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
|
||||||
|
// I'm avoiding the use of GLEW or some extensions handler, but that
|
||||||
|
// doesn't mean you should...
|
||||||
|
PFNGLCREATESHADERPROC glCreateShader;
|
||||||
|
PFNGLSHADERSOURCEPROC glShaderSource;
|
||||||
|
PFNGLCOMPILESHADERPROC glCompileShader;
|
||||||
|
PFNGLGETSHADERIVPROC glGetShaderiv;
|
||||||
|
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
|
||||||
|
PFNGLDELETESHADERPROC glDeleteShader;
|
||||||
|
PFNGLATTACHSHADERPROC glAttachShader;
|
||||||
|
PFNGLCREATEPROGRAMPROC glCreateProgram;
|
||||||
|
PFNGLDELETEPROGRAMPROC glDeleteProgram;
|
||||||
|
PFNGLLINKPROGRAMPROC glLinkProgram;
|
||||||
|
PFNGLVALIDATEPROGRAMPROC glValidateProgram;
|
||||||
|
PFNGLGETPROGRAMIVPROC glGetProgramiv;
|
||||||
|
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
|
||||||
|
PFNGLUSEPROGRAMPROC glUseProgram;
|
||||||
|
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
|
||||||
|
PFNGLACTIVETEXTUREPROC glActiveTexture;
|
||||||
|
|
||||||
|
|
||||||
|
bool initGLExtensions() {
|
||||||
|
glCreateShader = (PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader");
|
||||||
|
glShaderSource = (PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource");
|
||||||
|
glCompileShader = (PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader");
|
||||||
|
glGetShaderiv = (PFNGLGETSHADERIVPROC)SDL_GL_GetProcAddress("glGetShaderiv");
|
||||||
|
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)SDL_GL_GetProcAddress("glGetShaderInfoLog");
|
||||||
|
glDeleteShader = (PFNGLDELETESHADERPROC)SDL_GL_GetProcAddress("glDeleteShader");
|
||||||
|
glAttachShader = (PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader");
|
||||||
|
glCreateProgram = (PFNGLCREATEPROGRAMPROC)SDL_GL_GetProcAddress("glCreateProgram");
|
||||||
|
glDeleteProgram = (PFNGLDELETEPROGRAMPROC)SDL_GL_GetProcAddress("glDeleteProgram");
|
||||||
|
glLinkProgram = (PFNGLLINKPROGRAMPROC)SDL_GL_GetProcAddress("glLinkProgram");
|
||||||
|
glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)SDL_GL_GetProcAddress("glValidateProgram");
|
||||||
|
glGetProgramiv = (PFNGLGETPROGRAMIVPROC)SDL_GL_GetProcAddress("glGetProgramiv");
|
||||||
|
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)SDL_GL_GetProcAddress("glGetProgramInfoLog");
|
||||||
|
glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram");
|
||||||
|
glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)SDL_GL_GetProcAddress("glGetUniformLocation");
|
||||||
|
glActiveTexture = (PFNGLACTIVETEXTUREPROC)SDL_GL_GetProcAddress("glActiveTexture");
|
||||||
|
|
||||||
|
return glCreateShader && glShaderSource && glCompileShader && glGetShaderiv &&
|
||||||
|
glGetShaderInfoLog && glDeleteShader && glAttachShader && glCreateProgram &&
|
||||||
|
glDeleteProgram && glLinkProgram && glValidateProgram && glGetProgramiv &&
|
||||||
|
glGetProgramInfoLog && glUseProgram && glGetUniformLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
GLuint compileShader(const char* source, GLuint shaderType) {
|
||||||
|
// Create ID for shader
|
||||||
|
GLuint result = glCreateShader(shaderType);
|
||||||
|
// Add define depending on shader type
|
||||||
|
const char *sources[2] = { shaderType==GL_VERTEX_SHADER?"#define VERTEX\n":"#define FRAGMENT\n", source };
|
||||||
|
// Define shader text
|
||||||
|
glShaderSource(result, 2, sources, NULL);
|
||||||
|
// Compile shader
|
||||||
|
glCompileShader(result);
|
||||||
|
|
||||||
|
//Check vertex shader for errors
|
||||||
|
GLint shaderCompiled = GL_FALSE;
|
||||||
|
glGetShaderiv( result, GL_COMPILE_STATUS, &shaderCompiled );
|
||||||
|
if (shaderCompiled != GL_TRUE)
|
||||||
|
{
|
||||||
|
std::cout << "Error en la compilación: " << result << "!" << std::endl;
|
||||||
|
GLint logLength;
|
||||||
|
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &logLength);
|
||||||
|
if (logLength > 0)
|
||||||
|
{
|
||||||
|
GLchar *log = (GLchar*)malloc(logLength);
|
||||||
|
glGetShaderInfoLog(result, logLength, &logLength, log);
|
||||||
|
std::cout << "Shader compile log:" << log << std::endl;
|
||||||
|
//std::cout << source << std::endl;
|
||||||
|
free(log);
|
||||||
|
}
|
||||||
|
glDeleteShader(result);
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint compileProgram(const char* vertexShaderSource, const char* fragmentShaderSource)
|
||||||
|
{
|
||||||
|
GLuint programId = 0;
|
||||||
|
GLuint vtxShaderId, fragShaderId;
|
||||||
|
|
||||||
|
if (programId != 0) glDeleteProgram(programId);
|
||||||
|
programId = glCreateProgram();
|
||||||
|
|
||||||
|
|
||||||
|
vtxShaderId = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
||||||
|
fragShaderId = compileShader(fragmentShaderSource?fragmentShaderSource:vertexShaderSource, GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
if(vtxShaderId && fragShaderId)
|
||||||
|
{
|
||||||
|
// Associate shader with program
|
||||||
|
glAttachShader(programId, vtxShaderId);
|
||||||
|
glAttachShader(programId, fragShaderId);
|
||||||
|
glLinkProgram(programId);
|
||||||
|
glValidateProgram(programId);
|
||||||
|
|
||||||
|
// Check the status of the compile/link
|
||||||
|
GLint logLen;
|
||||||
|
glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen);
|
||||||
|
if (logLen > 0)
|
||||||
|
{
|
||||||
|
char* log = (char*) malloc(logLen * sizeof(char));
|
||||||
|
// Show any errors as appropriate
|
||||||
|
glGetProgramInfoLog(programId, logLen, &logLen, log);
|
||||||
|
std::cout << "Prog Info Log: " << std::endl << log << std::endl;
|
||||||
|
free(log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vtxShaderId) glDeleteShader(vtxShaderId);
|
||||||
|
if (fragShaderId) glDeleteShader(fragShaderId);
|
||||||
|
return programId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init(const char* vshader, const char* fshader)
|
||||||
|
{
|
||||||
|
int filesize;
|
||||||
|
char *vshaderfile = mini::file::getfilebuffer(vshader, filesize, true);
|
||||||
|
|
||||||
|
char *fshaderfile = nullptr;
|
||||||
|
if (fshader) { fshaderfile = mini::file::getfilebuffer(fshader, filesize, true); }
|
||||||
|
|
||||||
|
SDL_GetWindowSize(video::window, &win_size.x, &win_size.y);
|
||||||
|
SDL_GetTextureSize(video::tex_shader, &tex_size.x, &tex_size.y);
|
||||||
|
|
||||||
|
SDL_PropertiesID props = SDL_GetTextureProperties(video::tex_shader);
|
||||||
|
int access = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, -1);
|
||||||
|
if (access != SDL_TEXTUREACCESS_TARGET) {
|
||||||
|
std::cout << "ERROR FATAL: La textura per al render ha de tindre SDL_TEXTUREACCESS_TARGET definit." << std::endl;
|
||||||
|
::exit(1);
|
||||||
|
}
|
||||||
|
const char * renderer_name = SDL_GetRendererName(backend::video::renderer);
|
||||||
|
if(!strncmp(renderer_name, "opengl", 6)) {
|
||||||
|
#ifndef __APPLE__
|
||||||
|
static bool gl_extensions_initialized = false;
|
||||||
|
if (!gl_extensions_initialized) {
|
||||||
|
if (!initGLExtensions()) {
|
||||||
|
std::cout << "WARNING: No s'han pogut inicialitzar les extensions d'OpenGL!" << std::endl;
|
||||||
|
can_use_opengl = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gl_extensions_initialized = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// Compilar el shader y dejarlo listo para usar.
|
||||||
|
if (!vshaderfile) {
|
||||||
|
can_use_opengl = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
programId = compileProgram(vshaderfile, fshaderfile);
|
||||||
|
} else {
|
||||||
|
std::cout << "WARNING: El driver del renderer no es OpenGL." << std::endl;
|
||||||
|
can_use_opengl = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
can_use_opengl = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void enable() { if (can_use_opengl) using_opengl = true; }
|
||||||
|
void disable() { using_opengl = false; }
|
||||||
|
|
||||||
|
void render()
|
||||||
|
{
|
||||||
|
SDL_FlushRenderer(backend::video::renderer);
|
||||||
|
SDL_SetRenderTarget(backend::video::renderer, NULL);
|
||||||
|
SDL_SetRenderDrawColor(backend::video::renderer, 0, 0, 0, 255);
|
||||||
|
SDL_RenderClear(backend::video::renderer);
|
||||||
|
SDL_FlushRenderer(backend::video::renderer);
|
||||||
|
|
||||||
|
if (using_opengl)
|
||||||
|
{
|
||||||
|
GLint oldProgramId;
|
||||||
|
if (programId != 0)
|
||||||
|
{
|
||||||
|
glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId);
|
||||||
|
glUseProgram(programId);
|
||||||
|
}
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 1);
|
||||||
|
glViewport(0, 0, win_size.x, win_size.y);
|
||||||
|
|
||||||
|
glBegin(GL_TRIANGLE_STRIP);
|
||||||
|
glTexCoord2f(0.0f, 0.0f);
|
||||||
|
glVertex2f(-1.0f, -1.0f);
|
||||||
|
glTexCoord2f(tex_size.x, 0.0f);
|
||||||
|
glVertex2f(1.0f, -1.0f);
|
||||||
|
glTexCoord2f(0.0f, tex_size.y);
|
||||||
|
glVertex2f(-1.0f, 1.0f);
|
||||||
|
glTexCoord2f(tex_size.x, tex_size.y);
|
||||||
|
glVertex2f(1.0f, 1.0f);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
SDL_GL_SwapWindow(backend::video::window);
|
||||||
|
|
||||||
|
if (programId != 0) glUseProgram(oldProgramId);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SDL_RenderTexture(backend::video::renderer, backend::video::tex_shader, NULL, NULL);
|
||||||
|
SDL_RenderPresent(backend::video::renderer);
|
||||||
|
}
|
||||||
|
if (glGetError()) { printf("GLERROR!\n"); ::exit(1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -43,11 +43,6 @@ namespace backend
|
|||||||
// Crear textura shaders i inicialitzar shaders
|
// Crear textura shaders i inicialitzar shaders
|
||||||
tex_shader = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width*zoom, height*zoom);
|
tex_shader = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width*zoom, height*zoom);
|
||||||
SDL_SetTextureScaleMode(tex_shader, SDL_SCALEMODE_NEAREST);
|
SDL_SetTextureScaleMode(tex_shader, SDL_SCALEMODE_NEAREST);
|
||||||
|
|
||||||
mini::shader::init(window, tex_shader, nullptr);
|
|
||||||
|
|
||||||
// [TODO]
|
|
||||||
//log_msg(LOG_OK, "Graphics subsystem initialized\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void quit() {
|
void quit() {
|
||||||
@@ -72,7 +67,7 @@ namespace backend
|
|||||||
SDL_UnlockTexture(tex_back);
|
SDL_UnlockTexture(tex_back);
|
||||||
SDL_RenderTexture(renderer, tex_back, NULL, NULL); //NEW
|
SDL_RenderTexture(renderer, tex_back, NULL, NULL); //NEW
|
||||||
|
|
||||||
mini::shader::render();
|
backend::shader::render();
|
||||||
|
|
||||||
//SDL_RenderTexture(mini_ren, mini_bak, NULL, NULL);
|
//SDL_RenderTexture(mini_ren, mini_bak, NULL, NULL);
|
||||||
//SDL_RenderPresent(mini_ren);
|
//SDL_RenderPresent(mini_ren);
|
||||||
|
|||||||
@@ -33,10 +33,11 @@ namespace backend
|
|||||||
void cursor(const bool value);
|
void cursor(const bool value);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace audio
|
namespace shader
|
||||||
{
|
{
|
||||||
void init();
|
void init(const char* vshader, const char* fshader);
|
||||||
void quit();
|
void enable();
|
||||||
|
void disable();
|
||||||
void render();
|
void render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,4 +75,54 @@ namespace backend
|
|||||||
int press();
|
int press();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace audio
|
||||||
|
{
|
||||||
|
void init();
|
||||||
|
void quit();
|
||||||
|
|
||||||
|
namespace music
|
||||||
|
{
|
||||||
|
enum state { invalid=0, playing=1, paused=2, stopped=3, disabled=4 };
|
||||||
|
|
||||||
|
int load(const char* filename);
|
||||||
|
int load(const uint8_t* buffer, uint32_t length);
|
||||||
|
void play(int mus, int loop = -1);
|
||||||
|
void pause();
|
||||||
|
void resume();
|
||||||
|
void stop();
|
||||||
|
void fadeOut(int milliseconds);
|
||||||
|
state getState();
|
||||||
|
void destroy(int mus);
|
||||||
|
float setVolume(float vol);
|
||||||
|
void setPosition(float value);
|
||||||
|
float getPosition();
|
||||||
|
float getDuration();
|
||||||
|
void enable(bool value);
|
||||||
|
bool isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace sound
|
||||||
|
{
|
||||||
|
int create(uint8_t* buffer, uint32_t length);
|
||||||
|
int load(uint8_t* buffer, uint32_t length);
|
||||||
|
int load(const char* filename);
|
||||||
|
int play(int snd, int loop = 0);
|
||||||
|
int playOnChannel(int snd, int chan, int loop = 0);
|
||||||
|
void destroy(int snd);
|
||||||
|
float setVolume(float vol);
|
||||||
|
void enable(bool value);
|
||||||
|
bool isEnabled();
|
||||||
|
|
||||||
|
namespace channel
|
||||||
|
{
|
||||||
|
enum state { invalid, free, playing, paused, disabled };
|
||||||
|
void pause(int chan);
|
||||||
|
void resume(int chan);
|
||||||
|
void stop(int chan);
|
||||||
|
state getState(int chan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+3
-2
@@ -1401,12 +1401,13 @@ static int set_file_offset(stb_vorbis *f, unsigned int loc)
|
|||||||
#endif
|
#endif
|
||||||
f->eof = 0;
|
f->eof = 0;
|
||||||
if (USE_MEMORY(f)) {
|
if (USE_MEMORY(f)) {
|
||||||
if (f->stream_start + loc >= f->stream_end || f->stream_start + loc < f->stream_start) {
|
uint8_t *pos = f->stream_start + loc;
|
||||||
|
if (pos >= f->stream_end || pos < f->stream_start) {
|
||||||
f->stream = f->stream_end;
|
f->stream = f->stream_end;
|
||||||
f->eof = 1;
|
f->eof = 1;
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
f->stream = f->stream_start + loc;
|
f->stream = pos;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-24
@@ -1,5 +1,5 @@
|
|||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "jail_audio.h"
|
#include "backends/backend.h"
|
||||||
#include "mini/file/file.h"
|
#include "mini/file/file.h"
|
||||||
|
|
||||||
namespace mini
|
namespace mini
|
||||||
@@ -7,18 +7,13 @@ namespace mini
|
|||||||
namespace audio
|
namespace audio
|
||||||
{
|
{
|
||||||
int current_music = -1;
|
int current_music = -1;
|
||||||
//#define MAX_SOUNDS 50
|
|
||||||
//JA_Sound_t *sounds[MAX_SOUNDS];
|
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
jail::audio::init();
|
backend::audio::init();
|
||||||
//for (int i=0;i<MAX_SOUNDS;++i) sounds[i] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void quit() {
|
void quit() {
|
||||||
//if (current_music != NULL) JA_DeleteMusic(current_music);
|
backend::audio::quit();
|
||||||
//for (int i=0;i<MAX_SOUNDS;++i) if (sounds[i]!=NULL) JA_DeleteSound(sounds[i]);
|
|
||||||
jail::audio::quit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace music
|
namespace music
|
||||||
@@ -26,45 +21,53 @@ namespace mini
|
|||||||
void play(const char *filename, const int loop) {
|
void play(const char *filename, const int loop) {
|
||||||
int size;
|
int size;
|
||||||
char *buffer = file::getfilebuffer(filename, size);
|
char *buffer = file::getfilebuffer(filename, size);
|
||||||
if (current_music != -1) jail::audio::music::destroy(current_music);
|
if (current_music != -1) backend::audio::music::destroy(current_music);
|
||||||
current_music = jail::audio::music::load((uint8_t*)buffer, size);
|
current_music = backend::audio::music::load((uint8_t*)buffer, size);
|
||||||
jail::audio::music::play(current_music, loop);
|
backend::audio::music::play(current_music, loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pause() {
|
void pause() {
|
||||||
jail::audio::music::pause();
|
backend::audio::music::pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
void resume() {
|
void resume() {
|
||||||
jail::audio::music::resume();
|
backend::audio::music::resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop(const int t) {
|
void stop(const int t) {
|
||||||
jail::audio::music::stop();
|
backend::audio::music::stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
float duration() {
|
||||||
|
return backend::audio::music::getDuration();
|
||||||
|
}
|
||||||
|
|
||||||
|
int state() {
|
||||||
|
return backend::audio::music::getState();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace pos {
|
namespace pos {
|
||||||
void set(float value)
|
void set(float value)
|
||||||
{
|
{
|
||||||
jail::audio::music::setPosition(value);
|
backend::audio::music::setPosition(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
float get()
|
float get()
|
||||||
{
|
{
|
||||||
return jail::audio::music::getPosition();
|
return backend::audio::music::getPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace enable {
|
namespace enable {
|
||||||
void set(const bool value)
|
void set(const bool value)
|
||||||
{
|
{
|
||||||
jail::audio::music::enable(value);
|
backend::audio::music::enable(value);
|
||||||
file::setconfigvalue("music", value?"true":"false");
|
file::setconfigvalue("music", value?"true":"false");
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool get()
|
const bool get()
|
||||||
{
|
{
|
||||||
return jail::audio::music::isEnabled();
|
return backend::audio::music::isEnabled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,32 +77,32 @@ namespace mini
|
|||||||
int load(const char *filename) {
|
int load(const char *filename) {
|
||||||
int size;
|
int size;
|
||||||
char *buffer = file::getfilebuffer(filename, size);
|
char *buffer = file::getfilebuffer(filename, size);
|
||||||
return jail::audio::sound::load((uint8_t*)buffer, size);
|
return backend::audio::sound::load((uint8_t*)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(int soundfile) {
|
void free(int soundfile) {
|
||||||
return jail::audio::sound::destroy(soundfile);
|
return backend::audio::sound::destroy(soundfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
int play(int soundfile, const int volume) {
|
int play(int soundfile, const int volume) {
|
||||||
// [TODO] Ficar el volumen
|
// [TODO] Ficar el volumen
|
||||||
return jail::audio::sound::play(soundfile, 0);
|
return backend::audio::sound::play(soundfile, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop(int soundchannel) {
|
void stop(int soundchannel) {
|
||||||
return jail::audio::sound::channel::stop(soundchannel);
|
return backend::audio::sound::channel::stop(soundchannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace enable {
|
namespace enable {
|
||||||
void set(const bool value)
|
void set(const bool value)
|
||||||
{
|
{
|
||||||
return jail::audio::sound::enable(value);
|
return backend::audio::sound::enable(value);
|
||||||
file::setconfigvalue("sound", value?"true":"false");
|
file::setconfigvalue("sound", value?"true":"false");
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool get()
|
const bool get()
|
||||||
{
|
{
|
||||||
return jail::audio::sound::isEnabled();
|
return backend::audio::sound::isEnabled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ namespace mini
|
|||||||
void set(float value);
|
void set(float value);
|
||||||
float get();
|
float get();
|
||||||
}
|
}
|
||||||
|
float duration();
|
||||||
|
int state();
|
||||||
namespace enable {
|
namespace enable {
|
||||||
void set(const bool value);
|
void set(const bool value);
|
||||||
const bool get();
|
const bool get();
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
namespace jail
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
void init(/*const int freq, const SDL_AudioFormat format, const int channels*/);
|
|
||||||
void quit();
|
|
||||||
|
|
||||||
namespace music
|
|
||||||
{
|
|
||||||
//struct JA_Music_t;
|
|
||||||
enum state { invalid, playing, paused, stopped, disabled };
|
|
||||||
|
|
||||||
int load(const char* filename);
|
|
||||||
int load(const uint8_t* buffer, uint32_t length);
|
|
||||||
void play(int mus, int loop = -1);
|
|
||||||
void pause();
|
|
||||||
void resume();
|
|
||||||
void stop();
|
|
||||||
void fadeOut(int milliseconds);
|
|
||||||
state getState();
|
|
||||||
void destroy(int mus);
|
|
||||||
float setVolume(float vol);
|
|
||||||
void setPosition(float value);
|
|
||||||
float getPosition();
|
|
||||||
void enable(bool value);
|
|
||||||
bool isEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace sound
|
|
||||||
{
|
|
||||||
//struct JA_Sound_t;
|
|
||||||
int create(uint8_t* buffer, uint32_t length);
|
|
||||||
int load(uint8_t* buffer, uint32_t length);
|
|
||||||
int load(const char* filename);
|
|
||||||
int play(int snd, int loop = 0);
|
|
||||||
int playOnChannel(int snd, int chan, int loop = 0);
|
|
||||||
void destroy(int snd);
|
|
||||||
float setVolume(float vol);
|
|
||||||
void enable(bool value);
|
|
||||||
bool isEnabled();
|
|
||||||
|
|
||||||
namespace channel
|
|
||||||
{
|
|
||||||
enum state { invalid, free, playing, paused, disabled };
|
|
||||||
void pause(int chan);
|
|
||||||
void resume(int chan);
|
|
||||||
void stop(int chan);
|
|
||||||
state getState(int chan);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -154,12 +154,12 @@ namespace mini
|
|||||||
static int target(lua_State *L) {
|
static int target(lua_State *L) {
|
||||||
const int numargs = lua_gettop(L);
|
const int numargs = lua_gettop(L);
|
||||||
switch (numargs) {
|
switch (numargs) {
|
||||||
case 0: {
|
case 1: {
|
||||||
lua_pushinteger(L, mini::surf::target::get());
|
lua_pushinteger(L, mini::surf::target::get());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 2: {
|
||||||
uint8_t surface = luaL_checkinteger(L, 1);
|
uint8_t surface = luaL_checkinteger(L, 2);
|
||||||
mini::surf::target::set(surface);
|
mini::surf::target::set(surface);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -168,15 +168,31 @@ namespace mini
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int target_push(lua_State *L) {
|
||||||
|
const int numargs = lua_gettop(L);
|
||||||
|
if (numargs==1) {
|
||||||
|
uint8_t surface = luaL_checkinteger(L, 1);
|
||||||
|
mini::surf::target::push(surface);
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return luaL_error(L, "Function 'surface.target.push' Unexpected number of parameters.");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static int target_pop(lua_State *L) {
|
||||||
|
mini::surf::target::pop();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int source(lua_State *L) {
|
static int source(lua_State *L) {
|
||||||
const int numargs = lua_gettop(L);
|
const int numargs = lua_gettop(L);
|
||||||
switch (numargs) {
|
switch (numargs) {
|
||||||
case 0: {
|
case 1: {
|
||||||
lua_pushinteger(L, mini::surf::source::get());
|
lua_pushinteger(L, mini::surf::source::get());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 2: {
|
||||||
uint8_t surface = luaL_checkinteger(L, 1);
|
uint8_t surface = luaL_checkinteger(L, 2);
|
||||||
mini::surf::source::set(surface);
|
mini::surf::source::set(surface);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -185,6 +201,22 @@ namespace mini
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int source_push(lua_State *L) {
|
||||||
|
const int numargs = lua_gettop(L);
|
||||||
|
if (numargs==1) {
|
||||||
|
uint8_t surface = luaL_checkinteger(L, 1);
|
||||||
|
mini::surf::source::push(surface);
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return luaL_error(L, "Function 'surface.source.push' Unexpected number of parameters.");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static int source_pop(lua_State *L) {
|
||||||
|
mini::surf::source::pop();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int cls(lua_State *L) {
|
static int cls(lua_State *L) {
|
||||||
uint8_t color = luaL_optinteger(L, 1, 0);
|
uint8_t color = luaL_optinteger(L, 1, 0);
|
||||||
mini::surf::cls(color);
|
mini::surf::cls(color);
|
||||||
@@ -629,6 +661,16 @@ namespace mini
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int duration(lua_State *L) {
|
||||||
|
lua_pushnumber(L, mini::audio::music::duration());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int state(lua_State *L) {
|
||||||
|
lua_pushinteger(L, mini::audio::music::state());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int enable(lua_State *L) {
|
static int enable(lua_State *L) {
|
||||||
if (lua_gettop(L) == 0) {
|
if (lua_gettop(L) == 0) {
|
||||||
lua_pushboolean(L, mini::audio::music::enable::get());
|
lua_pushboolean(L, mini::audio::music::enable::get());
|
||||||
@@ -1036,8 +1078,23 @@ namespace mini
|
|||||||
lua_pushcfunction(L,wrappers::surf::save); lua_setfield(L, -2, "save");
|
lua_pushcfunction(L,wrappers::surf::save); lua_setfield(L, -2, "save");
|
||||||
lua_pushcfunction(L,wrappers::surf::free); lua_setfield(L, -2, "free");
|
lua_pushcfunction(L,wrappers::surf::free); lua_setfield(L, -2, "free");
|
||||||
lua_pushcfunction(L,wrappers::surf::size); lua_setfield(L, -2, "size");
|
lua_pushcfunction(L,wrappers::surf::size); lua_setfield(L, -2, "size");
|
||||||
lua_pushcfunction(L,wrappers::surf::target); lua_setfield(L, -2, "target");
|
|
||||||
lua_pushcfunction(L,wrappers::surf::source); lua_setfield(L, -2, "source");
|
lua_newtable(L);
|
||||||
|
lua_pushcfunction(L, wrappers::surf::target_push);lua_setfield(L, -2, "push");
|
||||||
|
lua_pushcfunction(L, wrappers::surf::target_pop); lua_setfield(L, -2, "pop");
|
||||||
|
lua_newtable(L);
|
||||||
|
lua_pushcfunction(L, wrappers::surf::target); lua_setfield(L, -2, "__call");
|
||||||
|
lua_setmetatable(L, -2);
|
||||||
|
lua_setfield(L, -2, "target");
|
||||||
|
|
||||||
|
lua_newtable(L);
|
||||||
|
lua_pushcfunction(L, wrappers::surf::source_push);lua_setfield(L, -2, "push");
|
||||||
|
lua_pushcfunction(L, wrappers::surf::source_pop); lua_setfield(L, -2, "pop");
|
||||||
|
lua_newtable(L);
|
||||||
|
lua_pushcfunction(L, wrappers::surf::source); lua_setfield(L, -2, "__call");
|
||||||
|
lua_setmetatable(L, -2);
|
||||||
|
lua_setfield(L, -2, "source");
|
||||||
|
|
||||||
lua_pushcfunction(L,wrappers::surf::cls); lua_setfield(L, -2, "cls");
|
lua_pushcfunction(L,wrappers::surf::cls); lua_setfield(L, -2, "cls");
|
||||||
lua_pushcfunction(L,wrappers::surf::clip); lua_setfield(L, -2, "clip");
|
lua_pushcfunction(L,wrappers::surf::clip); lua_setfield(L, -2, "clip");
|
||||||
|
|
||||||
@@ -1104,7 +1161,16 @@ namespace mini
|
|||||||
lua_pushcfunction(L,wrappers::music::resume); lua_setfield(L, -2, "resume");
|
lua_pushcfunction(L,wrappers::music::resume); lua_setfield(L, -2, "resume");
|
||||||
lua_pushcfunction(L,wrappers::music::stop); lua_setfield(L, -2, "stop");
|
lua_pushcfunction(L,wrappers::music::stop); lua_setfield(L, -2, "stop");
|
||||||
lua_pushcfunction(L,wrappers::music::pos); lua_setfield(L, -2, "pos");
|
lua_pushcfunction(L,wrappers::music::pos); lua_setfield(L, -2, "pos");
|
||||||
|
lua_pushcfunction(L,wrappers::music::duration); lua_setfield(L, -2, "duration");
|
||||||
|
lua_pushcfunction(L,wrappers::music::state); lua_setfield(L, -2, "state");
|
||||||
lua_pushcfunction(L,wrappers::music::enable); lua_setfield(L, -2, "enabled");
|
lua_pushcfunction(L,wrappers::music::enable); lua_setfield(L, -2, "enabled");
|
||||||
|
|
||||||
|
lua_pushinteger(L, 0); lua_setfield(L, -2, "INVALID");
|
||||||
|
lua_pushinteger(L, 1); lua_setfield(L, -2, "PLAYING");
|
||||||
|
lua_pushinteger(L, 2); lua_setfield(L, -2, "PAUSED");
|
||||||
|
lua_pushinteger(L, 3); lua_setfield(L, -2, "STOPPED");
|
||||||
|
lua_pushinteger(L, 4); lua_setfield(L, -2, "DISABLED");
|
||||||
|
|
||||||
lua_setglobal(L, "music");
|
lua_setglobal(L, "music");
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|||||||
@@ -1,268 +1,20 @@
|
|||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "mini/file/file.h"
|
#include "backends/backend.h"
|
||||||
#include "mini/win/win.h"
|
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include "CoreFoundation/CoreFoundation.h"
|
|
||||||
#include <OpenGL/OpenGL.h>
|
|
||||||
|
|
||||||
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
|
||||||
#include <OpenGL/gl3.h>
|
|
||||||
#else
|
|
||||||
#include <OpenGL/gl.h>
|
|
||||||
#endif //!ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
|
||||||
#else
|
|
||||||
#include <SDL3/SDL_opengl.h>
|
|
||||||
#include <SDL3/SDL_opengl_glext.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace mini
|
namespace mini
|
||||||
{
|
{
|
||||||
namespace shader
|
namespace shader
|
||||||
{
|
{
|
||||||
SDL_Window *win = nullptr;
|
void init(const char* vshader, const char* fshader) {
|
||||||
SDL_Renderer *renderer = nullptr;
|
backend::shader::init(vshader, fshader);
|
||||||
GLuint programId = 0;
|
|
||||||
SDL_Texture* backBuffer = nullptr;
|
|
||||||
SDL_Point win_size = {640, 480};
|
|
||||||
SDL_FPoint tex_size = {320, 240};
|
|
||||||
bool can_use_opengl = false;
|
|
||||||
bool using_opengl = false;
|
|
||||||
GLuint texture_number;
|
|
||||||
GLuint nose;
|
|
||||||
|
|
||||||
#ifndef __APPLE__
|
|
||||||
|
|
||||||
// I'm avoiding the use of GLEW or some extensions handler, but that
|
|
||||||
// doesn't mean you should...
|
|
||||||
PFNGLCREATESHADERPROC glCreateShader;
|
|
||||||
PFNGLSHADERSOURCEPROC glShaderSource;
|
|
||||||
PFNGLCOMPILESHADERPROC glCompileShader;
|
|
||||||
PFNGLGETSHADERIVPROC glGetShaderiv;
|
|
||||||
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
|
|
||||||
PFNGLDELETESHADERPROC glDeleteShader;
|
|
||||||
PFNGLATTACHSHADERPROC glAttachShader;
|
|
||||||
PFNGLCREATEPROGRAMPROC glCreateProgram;
|
|
||||||
PFNGLDELETEPROGRAMPROC glDeleteProgram;
|
|
||||||
PFNGLLINKPROGRAMPROC glLinkProgram;
|
|
||||||
PFNGLVALIDATEPROGRAMPROC glValidateProgram;
|
|
||||||
PFNGLGETPROGRAMIVPROC glGetProgramiv;
|
|
||||||
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
|
|
||||||
PFNGLUSEPROGRAMPROC glUseProgram;
|
|
||||||
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
|
|
||||||
PFNGLACTIVETEXTUREPROC glActiveTexture;
|
|
||||||
|
|
||||||
|
|
||||||
bool initGLExtensions() {
|
|
||||||
glCreateShader = (PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader");
|
|
||||||
glShaderSource = (PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource");
|
|
||||||
glCompileShader = (PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader");
|
|
||||||
glGetShaderiv = (PFNGLGETSHADERIVPROC)SDL_GL_GetProcAddress("glGetShaderiv");
|
|
||||||
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)SDL_GL_GetProcAddress("glGetShaderInfoLog");
|
|
||||||
glDeleteShader = (PFNGLDELETESHADERPROC)SDL_GL_GetProcAddress("glDeleteShader");
|
|
||||||
glAttachShader = (PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader");
|
|
||||||
glCreateProgram = (PFNGLCREATEPROGRAMPROC)SDL_GL_GetProcAddress("glCreateProgram");
|
|
||||||
glDeleteProgram = (PFNGLDELETEPROGRAMPROC)SDL_GL_GetProcAddress("glDeleteProgram");
|
|
||||||
glLinkProgram = (PFNGLLINKPROGRAMPROC)SDL_GL_GetProcAddress("glLinkProgram");
|
|
||||||
glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)SDL_GL_GetProcAddress("glValidateProgram");
|
|
||||||
glGetProgramiv = (PFNGLGETPROGRAMIVPROC)SDL_GL_GetProcAddress("glGetProgramiv");
|
|
||||||
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)SDL_GL_GetProcAddress("glGetProgramInfoLog");
|
|
||||||
glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram");
|
|
||||||
glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)SDL_GL_GetProcAddress("glGetUniformLocation");
|
|
||||||
glActiveTexture = (PFNGLACTIVETEXTUREPROC)SDL_GL_GetProcAddress("glActiveTexture");
|
|
||||||
|
|
||||||
return glCreateShader && glShaderSource && glCompileShader && glGetShaderiv &&
|
|
||||||
glGetShaderInfoLog && glDeleteShader && glAttachShader && glCreateProgram &&
|
|
||||||
glDeleteProgram && glLinkProgram && glValidateProgram && glGetProgramiv &&
|
|
||||||
glGetProgramInfoLog && glUseProgram && glGetUniformLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
state_t state;
|
|
||||||
|
|
||||||
void init(const char* vshader, const char* fshader)
|
|
||||||
{
|
|
||||||
// [TODO]
|
|
||||||
//int filesize;
|
|
||||||
//char *vshaderfile = file::getfilebuffer(vshader, filesize, true);
|
|
||||||
//
|
|
||||||
//char *fshaderfile = nullptr;
|
|
||||||
//if (fshader) { fshaderfile = file::getfilebuffer(fshader, filesize, true); }
|
|
||||||
//init(win::state.window, win::state.tex_shader, vshaderfile, fshaderfile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enable() {
|
||||||
GLuint compileShader(const char* source, GLuint shaderType) {
|
backend::shader::enable();
|
||||||
// Create ID for shader
|
|
||||||
GLuint result = glCreateShader(shaderType);
|
|
||||||
// Add define depending on shader type
|
|
||||||
const char *sources[2] = { shaderType==GL_VERTEX_SHADER?"#define VERTEX\n":"#define FRAGMENT\n", source };
|
|
||||||
// Define shader text
|
|
||||||
glShaderSource(result, 2, sources, NULL);
|
|
||||||
// Compile shader
|
|
||||||
glCompileShader(result);
|
|
||||||
|
|
||||||
//Check vertex shader for errors
|
|
||||||
GLint shaderCompiled = GL_FALSE;
|
|
||||||
glGetShaderiv( result, GL_COMPILE_STATUS, &shaderCompiled );
|
|
||||||
if (shaderCompiled != GL_TRUE)
|
|
||||||
{
|
|
||||||
std::cout << "Error en la compilación: " << result << "!" << std::endl;
|
|
||||||
GLint logLength;
|
|
||||||
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &logLength);
|
|
||||||
if (logLength > 0)
|
|
||||||
{
|
|
||||||
GLchar *log = (GLchar*)malloc(logLength);
|
|
||||||
glGetShaderInfoLog(result, logLength, &logLength, log);
|
|
||||||
std::cout << "Shader compile log:" << log << std::endl;
|
|
||||||
//std::cout << source << std::endl;
|
|
||||||
free(log);
|
|
||||||
}
|
|
||||||
glDeleteShader(result);
|
|
||||||
result = 0;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint compileProgram(const char* vertexShaderSource, const char* fragmentShaderSource)
|
void disable() {
|
||||||
{
|
backend::shader::disable();
|
||||||
GLuint programId = 0;
|
|
||||||
GLuint vtxShaderId, fragShaderId;
|
|
||||||
|
|
||||||
if (programId != 0) glDeleteProgram(programId);
|
|
||||||
programId = glCreateProgram();
|
|
||||||
|
|
||||||
|
|
||||||
vtxShaderId = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
|
||||||
fragShaderId = compileShader(fragmentShaderSource?fragmentShaderSource:vertexShaderSource, GL_FRAGMENT_SHADER);
|
|
||||||
|
|
||||||
if(vtxShaderId && fragShaderId)
|
|
||||||
{
|
|
||||||
// Associate shader with program
|
|
||||||
glAttachShader(programId, vtxShaderId);
|
|
||||||
glAttachShader(programId, fragShaderId);
|
|
||||||
glLinkProgram(programId);
|
|
||||||
glValidateProgram(programId);
|
|
||||||
|
|
||||||
// Check the status of the compile/link
|
|
||||||
GLint logLen;
|
|
||||||
glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen);
|
|
||||||
if (logLen > 0)
|
|
||||||
{
|
|
||||||
char* log = (char*) malloc(logLen * sizeof(char));
|
|
||||||
// Show any errors as appropriate
|
|
||||||
glGetProgramInfoLog(programId, logLen, &logLen, log);
|
|
||||||
std::cout << "Prog Info Log: " << std::endl << log << std::endl;
|
|
||||||
free(log);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (vtxShaderId) glDeleteShader(vtxShaderId);
|
|
||||||
if (fragShaderId) glDeleteShader(fragShaderId);
|
|
||||||
return programId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool init(SDL_Window* win, SDL_Texture* backBuffer, const char* vertexShader, const char* fragmentShader)
|
|
||||||
{
|
|
||||||
shader::win = win;
|
|
||||||
shader::renderer = SDL_GetRenderer(win);
|
|
||||||
shader::backBuffer = backBuffer;
|
|
||||||
SDL_GetWindowSize(win, &win_size.x, &win_size.y);
|
|
||||||
SDL_GetTextureSize(backBuffer, &tex_size.x, &tex_size.y);
|
|
||||||
//printf("tex size: %fx%f\n", tex_size.x, tex_size.y);
|
|
||||||
SDL_PropertiesID props = SDL_GetTextureProperties(backBuffer);
|
|
||||||
texture_number = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER, -1);
|
|
||||||
//printf("texture number: %i\n", texture_number);
|
|
||||||
int access = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, -1);
|
|
||||||
nose = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER, -1);
|
|
||||||
//printf("texture target number: %i\n", nose);
|
|
||||||
|
|
||||||
if (access != SDL_TEXTUREACCESS_TARGET)
|
|
||||||
{
|
|
||||||
std::cout << "ERROR FATAL: La textura per al render ha de tindre SDL_TEXTUREACCESS_TARGET definit." << std::endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char * renderer_name = SDL_GetRendererName(renderer);
|
|
||||||
//printf("rendererInfo.name: %s\n", renderer_name);
|
|
||||||
|
|
||||||
if(!strncmp(renderer_name, "opengl", 6)) {
|
|
||||||
#ifndef __APPLE__
|
|
||||||
static bool gl_extensions_initialized = false;
|
|
||||||
if (!gl_extensions_initialized) {
|
|
||||||
if (!initGLExtensions()) {
|
|
||||||
std::cout << "WARNING: No s'han pogut inicialitzar les extensions d'OpenGL!" << std::endl;
|
|
||||||
can_use_opengl = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
gl_extensions_initialized = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// Compilar el shader y dejarlo listo para usar.
|
|
||||||
if (!vertexShader) {
|
|
||||||
can_use_opengl = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
programId = compileProgram(vertexShader, fragmentShader);
|
|
||||||
} else {
|
|
||||||
std::cout << "WARNING: El driver del renderer no es OpenGL." << std::endl;
|
|
||||||
can_use_opengl = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
can_use_opengl = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void enable() { if (can_use_opengl) using_opengl = true; }
|
|
||||||
void disable() { using_opengl = false; }
|
|
||||||
|
|
||||||
void render()
|
|
||||||
{
|
|
||||||
SDL_FlushRenderer(renderer);
|
|
||||||
SDL_SetRenderTarget(renderer, NULL);
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
SDL_FlushRenderer(renderer);
|
|
||||||
|
|
||||||
if (using_opengl)
|
|
||||||
{
|
|
||||||
GLint oldProgramId;
|
|
||||||
if (programId != 0)
|
|
||||||
{
|
|
||||||
glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId);
|
|
||||||
glUseProgram(programId);
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 1);
|
|
||||||
glViewport(0, 0, win_size.x, win_size.y);
|
|
||||||
|
|
||||||
glBegin(GL_TRIANGLE_STRIP);
|
|
||||||
glTexCoord2f(0.0f, 0.0f);
|
|
||||||
glVertex2f(-1.0f, -1.0f);
|
|
||||||
glTexCoord2f(tex_size.x, 0.0f);
|
|
||||||
glVertex2f(1.0f, -1.0f);
|
|
||||||
glTexCoord2f(0.0f, tex_size.y);
|
|
||||||
glVertex2f(-1.0f, 1.0f);
|
|
||||||
glTexCoord2f(tex_size.x, tex_size.y);
|
|
||||||
glVertex2f(1.0f, 1.0f);
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
SDL_GL_SwapWindow(win);
|
|
||||||
|
|
||||||
if (programId != 0) glUseProgram(oldProgramId);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
SDL_RenderTexture(renderer, backBuffer, NULL, NULL);
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
}
|
|
||||||
if (glGetError()) { printf("GLERROR!\n"); exit(1); }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct SDL_Window;
|
|
||||||
struct SDL_Texture;
|
|
||||||
|
|
||||||
namespace mini
|
namespace mini
|
||||||
{
|
{
|
||||||
namespace shader
|
namespace shader
|
||||||
{
|
{
|
||||||
struct state_t {
|
|
||||||
const bool *keys;
|
|
||||||
uint8_t just_pressed = 0;
|
|
||||||
char text_input_buffer[10];
|
|
||||||
bool has_text_input = false;
|
|
||||||
};
|
|
||||||
extern state_t state;
|
|
||||||
|
|
||||||
const bool init(SDL_Window* win, SDL_Texture* backBuffer, const char* vertexShader, const char* fragmentShader=nullptr);
|
|
||||||
void init(const char* vshader, const char* fshader);
|
void init(const char* vshader, const char* fshader);
|
||||||
|
|
||||||
void enable();
|
void enable();
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
void render();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,6 +176,16 @@ namespace mini
|
|||||||
uint8_t get() {
|
uint8_t get() {
|
||||||
return state.dest_surface;
|
return state.dest_surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void push(uint8_t surface) {
|
||||||
|
state.dest_stack.push(state.dest_surface);
|
||||||
|
state.dest_surface = surface;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop() {
|
||||||
|
state.dest_surface = state.dest_stack.top();
|
||||||
|
state.dest_stack.pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace source {
|
namespace source {
|
||||||
@@ -186,6 +196,16 @@ namespace mini
|
|||||||
uint8_t get() {
|
uint8_t get() {
|
||||||
return state.source_surface;
|
return state.source_surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void push(uint8_t surface) {
|
||||||
|
state.source_stack.push(state.source_surface);
|
||||||
|
state.source_surface = surface;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop() {
|
||||||
|
state.source_surface = state.source_stack.top();
|
||||||
|
state.source_stack.pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace clip {
|
namespace clip {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
namespace mini
|
namespace mini
|
||||||
{
|
{
|
||||||
@@ -27,6 +28,8 @@ namespace mini
|
|||||||
std::vector<surface_t> surfaces;
|
std::vector<surface_t> surfaces;
|
||||||
int dest_surface = -1;
|
int dest_surface = -1;
|
||||||
int source_surface = -1;
|
int source_surface = -1;
|
||||||
|
std::stack<int> dest_stack;
|
||||||
|
std::stack<int> source_stack;
|
||||||
};
|
};
|
||||||
extern state_t state;
|
extern state_t state;
|
||||||
|
|
||||||
@@ -46,11 +49,15 @@ namespace mini
|
|||||||
namespace target {
|
namespace target {
|
||||||
void set(uint8_t surface);
|
void set(uint8_t surface);
|
||||||
uint8_t get();
|
uint8_t get();
|
||||||
|
void push(uint8_t surface);
|
||||||
|
void pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace source {
|
namespace source {
|
||||||
void set(uint8_t surface);
|
void set(uint8_t surface);
|
||||||
uint8_t get();
|
uint8_t get();
|
||||||
|
void push(uint8_t surface);
|
||||||
|
void pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace clip {
|
namespace clip {
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define MINI_VERSION "1.5.6"
|
#define MINI_VERSION "1.5.13"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "other/log.h"
|
#include "other/log.h"
|
||||||
#include "mini/file/file.h"
|
#include "mini/file/file.h"
|
||||||
#include "mini/shader/shader.h"
|
#include "mini/shader/shader.h"
|
||||||
#include <backends/backend.h>
|
#include "backends/backend.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|||||||
+36
-2
@@ -38,6 +38,8 @@ function surf.free(surface) end
|
|||||||
---Retrieve width and height of surface
|
---Retrieve width and height of surface
|
||||||
function surf.size(surface) end
|
function surf.size(surface) end
|
||||||
|
|
||||||
|
surf.target = {}
|
||||||
|
|
||||||
---@return number surface
|
---@return number surface
|
||||||
---Get current target surface
|
---Get current target surface
|
||||||
function surf.target() end
|
function surf.target() end
|
||||||
@@ -46,6 +48,15 @@ function surf.target() end
|
|||||||
---Set surface as target
|
---Set surface as target
|
||||||
function surf.target(surface) end
|
function surf.target(surface) end
|
||||||
|
|
||||||
|
---@param surface number
|
||||||
|
---push current target to the stack and set surface as target
|
||||||
|
function surf.target.push(surface) end
|
||||||
|
|
||||||
|
---pop surface on the stack as current target
|
||||||
|
function surf.target.pop() end
|
||||||
|
|
||||||
|
surf.source = {}
|
||||||
|
|
||||||
---@return number surface
|
---@return number surface
|
||||||
---Get current source surface
|
---Get current source surface
|
||||||
function surf.source() end
|
function surf.source() end
|
||||||
@@ -54,6 +65,13 @@ function surf.source() end
|
|||||||
---Set surface as source
|
---Set surface as source
|
||||||
function surf.source(surface) end
|
function surf.source(surface) end
|
||||||
|
|
||||||
|
---@param surface number
|
||||||
|
---push current source to the stack and set surface as source
|
||||||
|
function surf.source.push(surface) end
|
||||||
|
|
||||||
|
---pop surface on the stack and set it as current source
|
||||||
|
function surf.source.pop() end
|
||||||
|
|
||||||
---Erase the current target surface with color 0.
|
---Erase the current target surface with color 0.
|
||||||
function surf.cls() end
|
function surf.cls() end
|
||||||
|
|
||||||
@@ -399,6 +417,14 @@ function music.pos() end
|
|||||||
---Set the playing position of the currently loaded song
|
---Set the playing position of the currently loaded song
|
||||||
function music.pos(pos) end
|
function music.pos(pos) end
|
||||||
|
|
||||||
|
---@return number time
|
||||||
|
---Get the duration of the currently loaded song
|
||||||
|
function music.duration() end
|
||||||
|
|
||||||
|
---@return integer value
|
||||||
|
---Get the state of the music
|
||||||
|
function music.state() end
|
||||||
|
|
||||||
---@return boolean value
|
---@return boolean value
|
||||||
---Get if music is enabled
|
---Get if music is enabled
|
||||||
function music.enabled() end
|
function music.enabled() end
|
||||||
@@ -407,6 +433,12 @@ function music.enabled() end
|
|||||||
---Set if music is enabled or not
|
---Set if music is enabled or not
|
||||||
function music.enabled(value) end
|
function music.enabled(value) end
|
||||||
|
|
||||||
|
music.INVALID = 0
|
||||||
|
music.PLAYING = 1
|
||||||
|
music.PAUSED = 2
|
||||||
|
music.STOPPED = 3
|
||||||
|
music.DISABLED = 4
|
||||||
|
|
||||||
|
|
||||||
---@class sound
|
---@class sound
|
||||||
sound = {}
|
sound = {}
|
||||||
@@ -446,9 +478,11 @@ function sound.enabled(value) end
|
|||||||
---@class sys
|
---@class sys
|
||||||
sys = {}
|
sys = {}
|
||||||
|
|
||||||
|
---@return number delta
|
||||||
---Get delta time from last update in seconds (with decimals)
|
---Get delta time from last update in seconds (with decimals)
|
||||||
function sys.delta() end
|
function sys.delta() end
|
||||||
|
|
||||||
|
---@return number time
|
||||||
---Get current system timer in seconds (with decimals)
|
---Get current system timer in seconds (with decimals)
|
||||||
function sys.time() end
|
function sys.time() end
|
||||||
|
|
||||||
@@ -456,8 +490,8 @@ function sys.time() end
|
|||||||
---Reset chrono time (with offset in seconds) (with decimals)
|
---Reset chrono time (with offset in seconds) (with decimals)
|
||||||
function sys.chrono(offset) end
|
function sys.chrono(offset) end
|
||||||
|
|
||||||
---@return number
|
---@return number seconds
|
||||||
---@---Get chrono time since last chrono reset in seconds (with decimals)
|
---Get chrono time since last chrono reset in seconds (with decimals)
|
||||||
function sys.chrono() end
|
function sys.chrono() end
|
||||||
|
|
||||||
---@return boolean
|
---@return boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user