GLFB: add video aspect ratio handling

This commit is contained in:
Stefan Seyfried
2013-05-04 17:24:39 +02:00
parent 8a8849f28e
commit 9c1419c25b
2 changed files with 11 additions and 4 deletions

View File

@@ -62,6 +62,7 @@ GLFramebuffer::GLFramebuffer(int x, int y): mReInit(true), mShutDown(false), mIn
mState.height = y; mState.height = y;
mX = y * 16 / 9; /* hard coded 16:9 initial aspect ratio for now */ mX = y * 16 / 9; /* hard coded 16:9 initial aspect ratio for now */
mY = y; mY = y;
mVA = 1.0;
mState.blit = true; mState.blit = true;
last_apts = 0; last_apts = 0;
@@ -345,7 +346,7 @@ void GLFramebuffer::render()
#endif #endif
{ {
glBindTexture(GL_TEXTURE_2D, mState.displaytex); glBindTexture(GL_TEXTURE_2D, mState.displaytex);
drawSquare(1.0); drawSquare(1.0, mVA / (16.0/9));
glBindTexture(GL_TEXTURE_2D, mState.osdtex); glBindTexture(GL_TEXTURE_2D, mState.osdtex);
drawSquare(1.0); drawSquare(1.0);
} }
@@ -420,7 +421,7 @@ void GLFramebuffer::drawCube(float size)
} }
#endif #endif
void GLFramebuffer::drawSquare(float size) void GLFramebuffer::drawSquare(float size, float x_factor)
{ {
GLfloat vertices[] = { GLfloat vertices[] = {
1.0f, 1.0f, 1.0f, 1.0f,
@@ -439,7 +440,7 @@ void GLFramebuffer::drawSquare(float size)
}; };
glPushMatrix(); glPushMatrix();
glScalef(size, size, size); glScalef(size * x_factor, size, size);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices); glVertexPointer(2, GL_FLOAT, 0, vertices);
@@ -480,6 +481,10 @@ void GLFramebuffer::bltDisplayBuffer()
if (w == 0 || h == 0) if (w == 0 || h == 0)
return; return;
AVRational a = buf->AR();
if (a.den != 0)
mVA = static_cast<float>(w * a.num) / h / a.den;
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mState.displaypbo); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mState.displaypbo);
glBufferData(GL_PIXEL_UNPACK_BUFFER, buf->size(), &(*buf)[0], GL_STREAM_DRAW_ARB); glBufferData(GL_PIXEL_UNPACK_BUFFER, buf->size(), &(*buf)[0], GL_STREAM_DRAW_ARB);

View File

@@ -46,6 +46,8 @@ private:
fb_var_screeninfo screeninfo; fb_var_screeninfo screeninfo;
int mX; /* window size */ int mX; /* window size */
int mY; int mY;
float mVA; /* video aspect ratio */;
bool mReInit; /* setup things for GL */ bool mReInit; /* setup things for GL */
bool mShutDown; /* if set main loop is left */ bool mShutDown; /* if set main loop is left */
bool mInitDone; /* condition predicate */ bool mInitDone; /* condition predicate */
@@ -71,7 +73,7 @@ private:
void setupGLObjects(); /* PBOs, textures and stuff */ void setupGLObjects(); /* PBOs, textures and stuff */
void releaseGLObjects(); void releaseGLObjects();
// void drawCube(float size); /* cubes are the building blocks of our society */ // void drawCube(float size); /* cubes are the building blocks of our society */
void drawSquare(float size); /* do not be square */ void drawSquare(float size, float x_factor = 1); /* do not be square */
struct { struct {
int width; /* width and height, fixed for a framebuffer instance */ int width; /* width and height, fixed for a framebuffer instance */