@@ -34,7 +34,8 @@ class DebugRecordData | |||||
private: | private: | ||||
char const *path; | char const *path; | ||||
int width, height, fps; | |||||
vec2i size; | |||||
int fps; | |||||
#if defined USE_PIPI | #if defined USE_PIPI | ||||
pipi_sequence_t *sequence; | pipi_sequence_t *sequence; | ||||
#endif | #endif | ||||
@@ -50,8 +51,7 @@ DebugRecord::DebugRecord(char const *path, float fps) | |||||
Ticker::StartRecording(); | Ticker::StartRecording(); | ||||
data->path = strdup(path); | data->path = strdup(path); | ||||
data->width = 0; | |||||
data->height = 0; | |||||
data->size = 0; | |||||
data->fps = (int)(fps + 0.5f); | data->fps = (int)(fps + 0.5f); | ||||
#if defined USE_PIPI | #if defined USE_PIPI | ||||
data->sequence = NULL; | data->sequence = NULL; | ||||
@@ -69,19 +69,17 @@ void DebugRecord::TickDraw(float deltams) | |||||
{ | { | ||||
Entity::TickDraw(deltams); | Entity::TickDraw(deltams); | ||||
int width = Video::GetWidth(); | |||||
int height = Video::GetHeight(); | |||||
vec2i size = Video::GetSize(); | |||||
if (data->width != width || data->height != height) | |||||
if (data->size != size) | |||||
{ | { | ||||
data->width = width; | |||||
data->height = height; | |||||
data->size = size; | |||||
#if defined USE_PIPI | #if defined USE_PIPI | ||||
if (data->sequence) | if (data->sequence) | ||||
pipi_close_sequence(data->sequence); | pipi_close_sequence(data->sequence); | ||||
data->sequence = pipi_open_sequence(data->path, width, height, | |||||
data->sequence = pipi_open_sequence(data->path, size.x, size.y, | |||||
1 /* RGB */, data->fps, | 1 /* RGB */, data->fps, | ||||
1, 1, 60 * 1024 * 1024); | 1, 1, 60 * 1024 * 1024); | ||||
#endif | #endif | ||||
@@ -90,9 +88,9 @@ void DebugRecord::TickDraw(float deltams) | |||||
#if defined USE_PIPI | #if defined USE_PIPI | ||||
if (data->sequence) | if (data->sequence) | ||||
{ | { | ||||
uint32_t *buffer = new uint32_t[width * height]; | |||||
uint32_t *buffer = new uint32_t[size.x * size.y]; | |||||
Video::Capture(buffer); | Video::Capture(buffer); | ||||
pipi_feed_sequence(data->sequence, (uint8_t *)buffer, width, height); | |||||
pipi_feed_sequence(data->sequence, (uint8_t *)buffer, size.x, size.y); | |||||
delete[] buffer; | delete[] buffer; | ||||
} | } | ||||
#endif | #endif | ||||
@@ -149,7 +149,7 @@ EglApp::EglApp(char const *title, vec2i res, float fps) : | |||||
/* Initialise everything */ | /* Initialise everything */ | ||||
Ticker::Setup(fps); | Ticker::Setup(fps); | ||||
Video::Setup(gwa.width, gwa.height); | |||||
Video::Setup(vec2i(gwa.width, gwa.height)); | |||||
Audio::Setup(2); | Audio::Setup(2); | ||||
#endif | #endif | ||||
} | } | ||||
@@ -64,7 +64,7 @@ SdlApp::SdlApp(char const *title, vec2i res, float fps) : | |||||
/* Initialise everything */ | /* Initialise everything */ | ||||
Ticker::Setup(fps); | Ticker::Setup(fps); | ||||
Video::Setup(video->w, video->h); | |||||
Video::Setup(vec2i(video->w, video->h)); | |||||
Audio::Setup(2); | Audio::Setup(2); | ||||
#endif | #endif | ||||
} | } | ||||
@@ -55,7 +55,7 @@ void SdlInput::TickGame(float deltams) | |||||
if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) | if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) | ||||
{ | { | ||||
SDL_GetMouseState(&mouse.x, &mouse.y); | SDL_GetMouseState(&mouse.x, &mouse.y); | ||||
mouse.y = Video::GetHeight() - 1 - mouse.y; | |||||
mouse.y = Video::GetSize().y - 1 - mouse.y; | |||||
} | } | ||||
else | else | ||||
mouse.x = mouse.y = -1; | mouse.x = mouse.y = -1; | ||||
@@ -96,8 +96,8 @@ static char const *fragmentshader = | |||||
" float dy3 = mod(floor(gl_FragCoord.y * 0.25), 2.0);\n" | " float dy3 = mod(floor(gl_FragCoord.y * 0.25), 2.0);\n" | ||||
" float t3 = mod(3.0 * dx3 + 2.0 * dy3, 4.0);\n" | " float t3 = mod(3.0 * dx3 + 2.0 * dy3, 4.0);\n" | ||||
" float t1 = (1.0 + 16.0 * t1 + 4.0 * t2 + t3) / 65.0;\n" | " float t1 = (1.0 + 16.0 * t1 + 4.0 * t2 + t3) / 65.0;\n" | ||||
" float t2 = t1; | |||||
" float t3 = t1; | |||||
" float t2 = t1;\n" | |||||
" float t3 = t1;\n" | |||||
#else | #else | ||||
" float rand = sin(gl_FragCoord.x * 1.23456) * 123.456\n" | " float rand = sin(gl_FragCoord.x * 1.23456) * 123.456\n" | ||||
" + cos(gl_FragCoord.y * 2.34567) * 789.012;\n" | " + cos(gl_FragCoord.y * 2.34567) * 789.012;\n" | ||||
@@ -122,13 +122,13 @@ static char const *fragmentshader = | |||||
* Public Video class | * Public Video class | ||||
*/ | */ | ||||
void Video::Setup(int width, int height) | |||||
void Video::Setup(vec2i size) | |||||
{ | { | ||||
/* Initialise OpenGL */ | /* Initialise OpenGL */ | ||||
glViewport(0, 0, width, height); | |||||
glViewport(0, 0, size.x, size.y); | |||||
#if defined ANDROID_NDK | #if defined ANDROID_NDK | ||||
saved_viewport = vec2i(width, height); | |||||
saved_viewport = vec2i(size.x, size.y); | |||||
#endif | #endif | ||||
glClearColor(0.1f, 0.2f, 0.3f, 0.0f); | glClearColor(0.1f, 0.2f, 0.3f, 0.0f); | ||||
@@ -148,21 +148,19 @@ void Video::SetFov(float theta) | |||||
#undef far /* Fuck Microsoft again */ | #undef far /* Fuck Microsoft again */ | ||||
mat4 proj; | mat4 proj; | ||||
float width = GetWidth(); | |||||
float height = GetHeight(); | |||||
float near = -width - height; | |||||
float far = width + height; | |||||
vec2 size = GetSize(); | |||||
float near = -size.x - size.y; | |||||
float far = size.x + size.y; | |||||
#if defined ANDROID_NDK | #if defined ANDROID_NDK | ||||
width = 640.0f; | |||||
height = 480.0f; | |||||
size = vec(640.0f, 480.0f); | |||||
#endif | #endif | ||||
/* Set the projection matrix */ | /* Set the projection matrix */ | ||||
if (theta < 1e-4f) | if (theta < 1e-4f) | ||||
{ | { | ||||
/* The easy way: purely orthogonal projection. */ | /* The easy way: purely orthogonal projection. */ | ||||
proj_matrix = mat4::ortho(0, width, 0, height, near, far); | |||||
proj_matrix = mat4::ortho(0, size.x, 0, size.y, near, far); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -170,8 +168,8 @@ void Video::SetFov(float theta) | |||||
* approaches zero. This view ensures that the z=0 plane fills | * approaches zero. This view ensures that the z=0 plane fills | ||||
* the screen. */ | * the screen. */ | ||||
float t1 = tanf(theta / 2); | float t1 = tanf(theta / 2); | ||||
float t2 = t1 * height / width; | |||||
float dist = (float)width / (2.0f * t1); | |||||
float t2 = t1 * size.y / size.y; | |||||
float dist = size.x / (2.0f * t1); | |||||
near += dist; | near += dist; | ||||
far += dist; | far += dist; | ||||
@@ -184,7 +182,7 @@ void Video::SetFov(float theta) | |||||
proj_matrix = mat4::frustum(-near * t1, near * t1, | proj_matrix = mat4::frustum(-near * t1, near * t1, | ||||
-near * t2, near * t2, near, far) | -near * t2, near * t2, near, far) | ||||
* mat4::translate(-0.5f * width, -0.5f * height, -dist); | |||||
* mat4::translate(-0.5f * size.x, -0.5f * size.y, -dist); | |||||
} | } | ||||
view_matrix = mat4(1.0f); | view_matrix = mat4(1.0f); | ||||
@@ -207,7 +205,8 @@ void Video::SetDepth(bool set) | |||||
void Video::Clear() | void Video::Clear() | ||||
{ | { | ||||
glViewport(0, 0, GetWidth(), GetHeight()); | |||||
vec2i size = GetSize(); | |||||
glViewport(0, 0, size.x, size.y); | |||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | ||||
SetFov(0.0f); | SetFov(0.0f); | ||||
@@ -255,15 +254,5 @@ vec2i Video::GetSize() | |||||
#endif | #endif | ||||
} | } | ||||
int Video::GetWidth() | |||||
{ | |||||
return GetSize().x; | |||||
} | |||||
int Video::GetHeight() | |||||
{ | |||||
return GetSize().y; | |||||
} | |||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -25,15 +25,13 @@ namespace lol | |||||
class Video | class Video | ||||
{ | { | ||||
public: | public: | ||||
static void Setup(int width, int height); | |||||
static void Setup(vec2i size); | |||||
static void Destroy(); | static void Destroy(); | ||||
static void SetFov(float theta); | static void SetFov(float theta); | ||||
static void SetDepth(bool set); | static void SetDepth(bool set); | ||||
static void Clear(); | static void Clear(); | ||||
static void Capture(uint32_t *buffer); | static void Capture(uint32_t *buffer); | ||||
static vec2i GetSize(); | static vec2i GetSize(); | ||||
static int GetWidth(); | |||||
static int GetHeight(); | |||||
}; | }; | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||