Mercurial > mplayer.hg
comparison libvo/gl_common.c @ 27621:53b5cf466361
Change glCreateClearTex to use the same host data format as later uploads.
This fixes at least some of the massive performance problems the ATI drivers have.
author | reimar |
---|---|
date | Sat, 20 Sep 2008 17:48:01 +0000 |
parents | d97a607821f1 |
children | 524f6a87cd23 |
comparison
equal
deleted
inserted
replaced
27620:ed0ea697cf40 | 27621:53b5cf466361 |
---|---|
347 | 347 |
348 /** | 348 /** |
349 * \brief create a texture and set some defaults | 349 * \brief create a texture and set some defaults |
350 * \param target texture taget, usually GL_TEXTURE_2D | 350 * \param target texture taget, usually GL_TEXTURE_2D |
351 * \param fmt internal texture format | 351 * \param fmt internal texture format |
352 * \param format texture host data format | |
353 * \param type texture host data type | |
352 * \param filter filter used for scaling, e.g. GL_LINEAR | 354 * \param filter filter used for scaling, e.g. GL_LINEAR |
353 * \param w texture width | 355 * \param w texture width |
354 * \param h texture height | 356 * \param h texture height |
355 * \param val luminance value to fill texture with | 357 * \param val luminance value to fill texture with |
356 * \ingroup gltexture | 358 * \ingroup gltexture |
357 */ | 359 */ |
358 void glCreateClearTex(GLenum target, GLenum fmt, GLint filter, | 360 void glCreateClearTex(GLenum target, GLenum fmt, GLenum format, GLenum type, GLint filter, |
359 int w, int h, unsigned char val) { | 361 int w, int h, unsigned char val) { |
360 GLfloat fval = (GLfloat)val / 255.0; | 362 GLfloat fval = (GLfloat)val / 255.0; |
361 GLfloat border[4] = {fval, fval, fval, fval}; | 363 GLfloat border[4] = {fval, fval, fval, fval}; |
362 GLenum clrfmt = (fmt == GL_ALPHA) ? GL_ALPHA : GL_LUMINANCE; | 364 int stride = w * glFmt2bpp(format, type); |
363 char *init = malloc(w * h); | 365 char *init; |
364 memset(init, val, w * h); | 366 if (!stride) return; |
367 init = malloc(stride * h); | |
368 memset(init, val, stride * h); | |
365 glAdjustAlignment(w); | 369 glAdjustAlignment(w); |
366 glPixelStorei(GL_UNPACK_ROW_LENGTH, w); | 370 glPixelStorei(GL_UNPACK_ROW_LENGTH, w); |
367 glTexImage2D(target, 0, fmt, w, h, 0, clrfmt, GL_UNSIGNED_BYTE, init); | 371 glTexImage2D(target, 0, fmt, w, h, 0, format, type, init); |
368 glTexParameterf(target, GL_TEXTURE_PRIORITY, 1.0); | 372 glTexParameterf(target, GL_TEXTURE_PRIORITY, 1.0); |
369 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filter); | 373 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filter); |
370 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filter); | 374 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filter); |
371 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 375 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
372 glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 376 glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
409 */ | 413 */ |
410 int glCreatePPMTex(GLenum target, GLenum fmt, GLint filter, | 414 int glCreatePPMTex(GLenum target, GLenum fmt, GLint filter, |
411 FILE *f, int *width, int *height, int *maxval) { | 415 FILE *f, int *width, int *height, int *maxval) { |
412 unsigned w, h, m, val, bpp; | 416 unsigned w, h, m, val, bpp; |
413 char *data; | 417 char *data; |
418 GLenum type; | |
414 ppm_skip(f); | 419 ppm_skip(f); |
415 if (fgetc(f) != 'P' || fgetc(f) != '6') | 420 if (fgetc(f) != 'P' || fgetc(f) != '6') |
416 return 0; | 421 return 0; |
417 ppm_skip(f); | 422 ppm_skip(f); |
418 if (fscanf(f, "%u", &w) != 1) | 423 if (fscanf(f, "%u", &w) != 1) |
435 if (!fmt) { | 440 if (!fmt) { |
436 fmt = (m > 255) ? hqtexfmt : 3; | 441 fmt = (m > 255) ? hqtexfmt : 3; |
437 if (fmt == GL_FLOAT_RGB32_NV && target != GL_TEXTURE_RECTANGLE) | 442 if (fmt == GL_FLOAT_RGB32_NV && target != GL_TEXTURE_RECTANGLE) |
438 fmt = GL_RGB16; | 443 fmt = GL_RGB16; |
439 } | 444 } |
440 glCreateClearTex(target, fmt, filter, w, h, 0); | 445 type = m > 255 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE; |
441 glUploadTex(target, GL_RGB, (m > 255) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE, | 446 glCreateClearTex(target, fmt, GL_RGB, type, filter, w, h, 0); |
447 glUploadTex(target, GL_RGB, type, | |
442 data, w * bpp, 0, 0, w, h, 0); | 448 data, w * bpp, 0, 0, w, h, 0); |
443 free(data); | 449 free(data); |
444 if (width) *width = w; | 450 if (width) *width = w; |
445 if (height) *height = h; | 451 if (height) *height = h; |
446 if (maxval) *maxval = m; | 452 if (maxval) *maxval = m; |
978 ActiveTexture(GL_TEXTURE0 + texs[0]); | 984 ActiveTexture(GL_TEXTURE0 + texs[0]); |
979 lookup_data = malloc(4 * LOOKUP_RES); | 985 lookup_data = malloc(4 * LOOKUP_RES); |
980 gen_gamma_map(lookup_data, LOOKUP_RES, params->rgamma); | 986 gen_gamma_map(lookup_data, LOOKUP_RES, params->rgamma); |
981 gen_gamma_map(&lookup_data[LOOKUP_RES], LOOKUP_RES, params->ggamma); | 987 gen_gamma_map(&lookup_data[LOOKUP_RES], LOOKUP_RES, params->ggamma); |
982 gen_gamma_map(&lookup_data[2 * LOOKUP_RES], LOOKUP_RES, params->bgamma); | 988 gen_gamma_map(&lookup_data[2 * LOOKUP_RES], LOOKUP_RES, params->bgamma); |
983 glCreateClearTex(GL_TEXTURE_2D, GL_LUMINANCE8, GL_LINEAR, | 989 glCreateClearTex(GL_TEXTURE_2D, GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LINEAR, |
984 LOOKUP_RES, 4, 0); | 990 LOOKUP_RES, 4, 0); |
985 glUploadTex(GL_TEXTURE_2D, GL_LUMINANCE, GL_UNSIGNED_BYTE, lookup_data, | 991 glUploadTex(GL_TEXTURE_2D, GL_LUMINANCE, GL_UNSIGNED_BYTE, lookup_data, |
986 LOOKUP_RES, 0, 0, LOOKUP_RES, 4, 0); | 992 LOOKUP_RES, 0, 0, LOOKUP_RES, 4, 0); |
987 ActiveTexture(GL_TEXTURE0); | 993 ActiveTexture(GL_TEXTURE0); |
988 texs[0] += '0'; | 994 texs[0] += '0'; |