Browse Source

video: get rid of Video::GetWidth() and Video::GetHeight().

legacy
Sam Hocevar sam 14 years ago
parent
commit
cc05a63bb7
6 changed files with 28 additions and 43 deletions
  1. +9
    -11
      src/debugrecord.cpp
  2. +1
    -1
      src/eglapp.cpp
  3. +1
    -1
      src/sdlapp.cpp
  4. +1
    -1
      src/sdlinput.cpp
  5. +15
    -26
      src/video.cpp
  6. +1
    -3
      src/video.h

+ 9
- 11
src/debugrecord.cpp View File

@@ -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


+ 1
- 1
src/eglapp.cpp View File

@@ -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
}


+ 1
- 1
src/sdlapp.cpp View File

@@ -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
}


+ 1
- 1
src/sdlinput.cpp View File

@@ -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;


+ 15
- 26
src/video.cpp View File

@@ -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 */


+ 1
- 3
src/video.h View File

@@ -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 */


Loading…
Cancel
Save