From cc05a63bb7c78e19490d11df422c4162ea16605b Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 4 Apr 2011 00:05:59 +0000 Subject: [PATCH] video: get rid of Video::GetWidth() and Video::GetHeight(). --- src/debugrecord.cpp | 20 +++++++++----------- src/eglapp.cpp | 2 +- src/sdlapp.cpp | 2 +- src/sdlinput.cpp | 2 +- src/video.cpp | 41 +++++++++++++++-------------------------- src/video.h | 4 +--- 6 files changed, 28 insertions(+), 43 deletions(-) diff --git a/src/debugrecord.cpp b/src/debugrecord.cpp index eeb72173..cdc6e5bd 100644 --- a/src/debugrecord.cpp +++ b/src/debugrecord.cpp @@ -34,7 +34,8 @@ class DebugRecordData private: char const *path; - int width, height, fps; + vec2i size; + int fps; #if defined USE_PIPI pipi_sequence_t *sequence; #endif @@ -50,8 +51,7 @@ DebugRecord::DebugRecord(char const *path, float fps) Ticker::StartRecording(); data->path = strdup(path); - data->width = 0; - data->height = 0; + data->size = 0; data->fps = (int)(fps + 0.5f); #if defined USE_PIPI data->sequence = NULL; @@ -69,19 +69,17 @@ void DebugRecord::TickDraw(float 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 (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, 1, 60 * 1024 * 1024); #endif @@ -90,9 +88,9 @@ void DebugRecord::TickDraw(float deltams) #if defined USE_PIPI if (data->sequence) { - uint32_t *buffer = new uint32_t[width * height]; + uint32_t *buffer = new uint32_t[size.x * size.y]; 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; } #endif diff --git a/src/eglapp.cpp b/src/eglapp.cpp index 78056fa6..961e0bf5 100644 --- a/src/eglapp.cpp +++ b/src/eglapp.cpp @@ -149,7 +149,7 @@ EglApp::EglApp(char const *title, vec2i res, float fps) : /* Initialise everything */ Ticker::Setup(fps); - Video::Setup(gwa.width, gwa.height); + Video::Setup(vec2i(gwa.width, gwa.height)); Audio::Setup(2); #endif } diff --git a/src/sdlapp.cpp b/src/sdlapp.cpp index 352f19e4..9c6ce404 100644 --- a/src/sdlapp.cpp +++ b/src/sdlapp.cpp @@ -64,7 +64,7 @@ SdlApp::SdlApp(char const *title, vec2i res, float fps) : /* Initialise everything */ Ticker::Setup(fps); - Video::Setup(video->w, video->h); + Video::Setup(vec2i(video->w, video->h)); Audio::Setup(2); #endif } diff --git a/src/sdlinput.cpp b/src/sdlinput.cpp index 663bd8cc..0818ac0c 100644 --- a/src/sdlinput.cpp +++ b/src/sdlinput.cpp @@ -55,7 +55,7 @@ void SdlInput::TickGame(float deltams) if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) { SDL_GetMouseState(&mouse.x, &mouse.y); - mouse.y = Video::GetHeight() - 1 - mouse.y; + mouse.y = Video::GetSize().y - 1 - mouse.y; } else mouse.x = mouse.y = -1; diff --git a/src/video.cpp b/src/video.cpp index 4679bb25..51dd69d3 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -96,8 +96,8 @@ static char const *fragmentshader = " 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 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 " float rand = sin(gl_FragCoord.x * 1.23456) * 123.456\n" " + cos(gl_FragCoord.y * 2.34567) * 789.012;\n" @@ -122,13 +122,13 @@ static char const *fragmentshader = * Public Video class */ -void Video::Setup(int width, int height) +void Video::Setup(vec2i size) { /* Initialise OpenGL */ - glViewport(0, 0, width, height); + glViewport(0, 0, size.x, size.y); #if defined ANDROID_NDK - saved_viewport = vec2i(width, height); + saved_viewport = vec2i(size.x, size.y); #endif glClearColor(0.1f, 0.2f, 0.3f, 0.0f); @@ -148,21 +148,19 @@ void Video::SetFov(float theta) #undef far /* Fuck Microsoft again */ 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 - width = 640.0f; - height = 480.0f; + size = vec(640.0f, 480.0f); #endif /* Set the projection matrix */ if (theta < 1e-4f) { /* 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 { @@ -170,8 +168,8 @@ void Video::SetFov(float theta) * approaches zero. This view ensures that the z=0 plane fills * the screen. */ 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; far += dist; @@ -184,7 +182,7 @@ void Video::SetFov(float theta) proj_matrix = mat4::frustum(-near * t1, near * t1, -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); @@ -207,7 +205,8 @@ void Video::SetDepth(bool set) 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); SetFov(0.0f); @@ -255,15 +254,5 @@ vec2i Video::GetSize() #endif } -int Video::GetWidth() -{ - return GetSize().x; -} - -int Video::GetHeight() -{ - return GetSize().y; -} - } /* namespace lol */ diff --git a/src/video.h b/src/video.h index 11062540..59f6d9bb 100644 --- a/src/video.h +++ b/src/video.h @@ -25,15 +25,13 @@ namespace lol class Video { public: - static void Setup(int width, int height); + static void Setup(vec2i size); static void Destroy(); static void SetFov(float theta); static void SetDepth(bool set); static void Clear(); static void Capture(uint32_t *buffer); static vec2i GetSize(); - static int GetWidth(); - static int GetHeight(); }; } /* namespace lol */