Remove animvpx's dependency on GLSL; adds in-place YUV420 to RGB888 conversion.

git-svn-id: https://svn.eduke32.com/eduke32@4998 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2015-02-11 05:22:52 +00:00
parent 27e8fcbe57
commit 8cc7f240d8
2 changed files with 123 additions and 96 deletions

View file

@ -96,7 +96,7 @@ int32_t G_PlayAnim(const char *fn)
I_ClearAllInput();
#ifdef USE_LIBVPX
while (getrendermode() >= REND_POLYMOST && glinfo.glsl) // if, really
while (getrendermode() >= REND_POLYMOST) // if, really
{
char vpxfn[BMAX_PATH];
Bstrncpyz(vpxfn, fn, BMAX_PATH);

View file

@ -295,18 +295,18 @@ read_ivf_frame:
t[1] = getticks();
/*** 3 planes --> packed conversion ***/
{
uint8_t *const dstpic = codec->pic;
const uint8_t *const yplane = img->planes[VPX_PLANE_Y];
const uint8_t *const uplane = img->planes[VPX_PLANE_U];
const uint8_t *const vplane = img->planes[VPX_PLANE_V];
uint8_t const *const yplane = img->planes[VPX_PLANE_Y];
uint8_t const *const uplane = img->planes[VPX_PLANE_U];
uint8_t const *const vplane = img->planes[VPX_PLANE_V];
int32_t ystride = img->stride[VPX_PLANE_Y];
int32_t ustride = img->stride[VPX_PLANE_U];
int32_t vstride = img->stride[VPX_PLANE_V];
const int32_t ystride = img->stride[VPX_PLANE_Y];
const int32_t ustride = img->stride[VPX_PLANE_U];
const int32_t vstride = img->stride[VPX_PLANE_V];
if (glinfo.glsl) /*** 3 planes --> packed conversion ***/
{
int32_t x, y;
const int32_t width = img->d_w, height = img->d_h;
@ -334,6 +334,31 @@ read_ivf_frame:
}
}
}
else /*** 3 planes --> packed conversion (RGB) ***/
{
int i = 0;
for (unsigned int imgY = 0; imgY < img->d_h; imgY++)
{
for (unsigned int imgX = 0; imgX < img->d_w; imgX++)
{
uint8_t const y = yplane[imgY * ystride + imgX];
uint8_t const u = uplane[(imgY >> 1) * ustride + (imgX >> 1)];
uint8_t const v = vplane[(imgY >> 1) * vstride + (imgX >> 1)];
int const c = y - 16;
int const d = (u + -128);
int const e = (v + -128);
int const c298 = c * 298;
dstpic[i + 0] = (uint8_t)clamp((c298 + 409 * e - -128) >> 8, 0, 255);
dstpic[i + 1] = (uint8_t)clamp((c298 - 100 * d - 208 * e - -128) >> 8, 0, 255);
dstpic[i + 2] = (uint8_t)clamp((c298 + 516 * d - -128) >> 8, 0, 255);
i += 3;
}
}
}
t[2] = getticks();
@ -382,6 +407,8 @@ static char *fragprog_src =
"}\n";
void animvpx_setup_glstate(void)
{
if (glinfo.glsl)
{
GLint gli;
GLhandleARB FSHandle, PHandle;
@ -413,6 +440,7 @@ void animvpx_setup_glstate(void)
/* Finally, use the program. */
bglUseProgramObjectARB(PHandle);
}
////////// GL STATE //////////
@ -425,26 +453,18 @@ void animvpx_setup_glstate(void)
bglMatrixMode(GL_PROJECTION);
bglLoadIdentity();
bglMatrixMode(GL_COLOR);
bglLoadIdentity();
bglMatrixMode(GL_TEXTURE);
bglLoadIdentity();
bglPushAttrib(GL_ENABLE_BIT);
// bglPushAttrib(GL_ENABLE_BIT);
bglDisable(GL_ALPHA_TEST);
// bglDisable(GL_LIGHTING);
bglDisable(GL_DEPTH_TEST);
bglDisable(GL_BLEND);
bglDisable(GL_CULL_FACE);
// bglDisable(GL_SCISSOR_TEST);
bglEnable(GL_TEXTURE_2D);
bglActiveTextureARB(GL_TEXTURE0_ARB);
bglGenTextures(1, &texname);
// gli = bglGetUniformLocationARB(PHandle,"tex");
// bglUniform1iARB(gli,0); // 0: texture unit
bglBindTexture(GL_TEXTURE_2D, texname);
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
@ -461,9 +481,10 @@ void animvpx_setup_glstate(void)
void animvpx_restore_glstate(void)
{
if (glinfo.glsl)
bglUseProgramObjectARB(0);
bglPopAttrib();
// bglPopAttrib();
bglDeleteTextures(1, &texname);
texname = 0;
@ -480,19 +501,20 @@ int32_t animvpx_render_frame(animvpx_codec_ctx *codec)
if (codec->pic == NULL)
return 2; // shouldn't happen
int fmt = glinfo.glsl ? GL_RGBA : GL_RGB;
if (!texuploaded)
{
bglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, codec->width,codec->height,
0, GL_RGBA, GL_UNSIGNED_BYTE, codec->pic);
bglTexImage2D(GL_TEXTURE_2D, 0, fmt, codec->width,codec->height,
0, fmt, GL_UNSIGNED_BYTE, codec->pic);
texuploaded = 1;
}
else
{
bglTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, codec->width,codec->height,
GL_RGBA, GL_UNSIGNED_BYTE, codec->pic);
fmt, GL_UNSIGNED_BYTE, codec->pic);
}
{
float vid_wbyh = ((float)codec->width)/codec->height;
float scr_wbyh = ((float)xdim)/ydim;
@ -510,6 +532,9 @@ int32_t animvpx_render_frame(animvpx_codec_ctx *codec)
#endif
bglBegin(GL_QUADS);
if (!glinfo.glsl)
bglColor3f(1.0, 1.0, 1.0);
bglTexCoord2f(0.0,1.0);
bglVertex3f(-x, -y, 0.0);
@ -523,7 +548,6 @@ int32_t animvpx_render_frame(animvpx_codec_ctx *codec)
bglVertex3f(x, -y, 0.0);
bglEnd();
}
t = getticks()-t;
codec->sumtimes[2] += t;
@ -541,6 +565,9 @@ void animvpx_print_stats(const animvpx_codec_ctx *codec)
const int32_t *m = codec->maxtimes;
int32_t n = codec->numframes;
if (glinfo.glsl)
initprintf("animvpx: GLSL mode\n");
initprintf("VP8 timing stats (mean, max) [ms] for %d frames:\n"
" read and decode frame: %.02f, %d\n"
" 3 planes -> packed conversion: %.02f, %d\n"