Commit 62d4f41e authored by Lionel Ulmer's avatar Lionel Ulmer Committed by Alexandre Julliard

Factorize some code in the texture uploading function.

parent da66dad0
...@@ -146,6 +146,10 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { ...@@ -146,6 +146,10 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
#endif #endif
void (*ptr_ColorTableEXT) (GLenum target, GLenum internalformat, void (*ptr_ColorTableEXT) (GLenum target, GLenum internalformat,
GLsizei width, GLenum format, GLenum type, const GLvoid *table) = NULL; GLsizei width, GLenum format, GLenum type, const GLvoid *table) = NULL;
BOOL upload_done = FALSE;
BOOL error = FALSE;
GLenum format, pixel_format;
VOID *surface = NULL;
DDSURFACEDESC *src_d = (DDSURFACEDESC *)&(This->surface_desc); DDSURFACEDESC *src_d = (DDSURFACEDESC *)&(This->surface_desc);
...@@ -174,6 +178,7 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { ...@@ -174,6 +178,7 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
if (pal == NULL) { if (pal == NULL) {
ERR("Palettized texture Loading with a NULL palette !\n"); ERR("Palettized texture Loading with a NULL palette !\n");
glBindTexture(GL_TEXTURE_2D, current_texture);
return; return;
} }
/* Get the surface's palette */ /* Get the surface's palette */
...@@ -206,10 +211,14 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { ...@@ -206,10 +211,14 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
GL_COLOR_INDEX, /* texture format */ GL_COLOR_INDEX, /* texture format */
GL_UNSIGNED_BYTE, /* texture type */ GL_UNSIGNED_BYTE, /* texture type */
src_d->lpSurface); /* the texture */ src_d->lpSurface); /* the texture */
upload_done = TRUE;
} else { } else {
DWORD *surface = (DWORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(DWORD));
DWORD i; DWORD i;
BYTE *src = (BYTE *) src_d->lpSurface, *dst = (BYTE *) surface; BYTE *src = (BYTE *) src_d->lpSurface, *dst;
surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(DWORD));
dst = (BYTE *) surface;
for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) { for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
BYTE color = *src++; BYTE color = *src++;
...@@ -219,25 +228,8 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { ...@@ -219,25 +228,8 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
*dst++ = table[color][3]; *dst++ = table[color][3];
} }
if (init_upload) format = GL_RGBA;
glTexImage2D(GL_TEXTURE_2D, pixel_format = GL_UNSIGNED_BYTE;
This->mipmap_level,
GL_RGBA,
src_d->dwWidth, src_d->dwHeight,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
surface);
else
glTexSubImage2D(GL_TEXTURE_2D,
This->mipmap_level,
0, 0,
src_d->dwWidth, src_d->dwHeight,
GL_RGBA,
GL_UNSIGNED_BYTE,
surface);
HeapFree(GetProcessHeap(), 0, surface);
} }
} else if (src_d->ddpfPixelFormat.dwFlags & DDPF_RGB) { } else if (src_d->ddpfPixelFormat.dwFlags & DDPF_RGB) {
/* ************ /* ************
...@@ -247,84 +239,25 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { ...@@ -247,84 +239,25 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
/* ********************** /* **********************
GL_UNSIGNED_BYTE_3_3_2 GL_UNSIGNED_BYTE_3_3_2
********************** */ ********************** */
if (init_upload) format = GL_RGB;
glTexImage2D(GL_TEXTURE_2D, pixel_format = GL_UNSIGNED_BYTE_3_3_2;
This->mipmap_level,
GL_RGB,
src_d->dwWidth, src_d->dwHeight,
0,
GL_RGB,
GL_UNSIGNED_BYTE_3_3_2,
src_d->lpSurface);
else
glTexSubImage2D(GL_TEXTURE_2D,
This->mipmap_level,
0, 0,
src_d->dwWidth, src_d->dwHeight,
GL_RGB,
GL_UNSIGNED_BYTE_3_3_2,
src_d->lpSurface);
} else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 16) { } else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 16) {
if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000000) { if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000000) {
if (init_upload) format = GL_RGB;
glTexImage2D(GL_TEXTURE_2D, pixel_format = GL_UNSIGNED_SHORT_5_6_5;
This->mipmap_level,
GL_RGB,
src_d->dwWidth, src_d->dwHeight,
0,
GL_RGB,
GL_UNSIGNED_SHORT_5_6_5,
src_d->lpSurface);
else
glTexSubImage2D(GL_TEXTURE_2D,
This->mipmap_level,
0, 0,
src_d->dwWidth, src_d->dwHeight,
GL_RGB,
GL_UNSIGNED_SHORT_5_6_5,
src_d->lpSurface);
} else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000001) { } else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000001) {
if (init_upload) format = GL_RGBA;
glTexImage2D(GL_TEXTURE_2D, pixel_format = GL_UNSIGNED_SHORT_5_5_5_1;
This->mipmap_level,
GL_RGBA,
src_d->dwWidth, src_d->dwHeight,
0,
GL_RGBA,
GL_UNSIGNED_SHORT_5_5_5_1,
src_d->lpSurface);
else
glTexSubImage2D(GL_TEXTURE_2D,
This->mipmap_level,
0, 0,
src_d->dwWidth, src_d->dwHeight,
GL_RGBA,
GL_UNSIGNED_SHORT_5_5_5_1,
src_d->lpSurface);
} else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x0000000F) { } else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x0000000F) {
if (init_upload) format = GL_RGBA;
glTexImage2D(GL_TEXTURE_2D, pixel_format = GL_UNSIGNED_SHORT_4_4_4_4;
This->mipmap_level,
GL_RGBA,
src_d->dwWidth, src_d->dwHeight,
0,
GL_RGBA,
GL_UNSIGNED_SHORT_4_4_4_4,
src_d->lpSurface);
else
glTexSubImage2D(GL_TEXTURE_2D,
This->mipmap_level,
0, 0,
src_d->dwWidth, src_d->dwHeight,
GL_RGBA,
GL_UNSIGNED_SHORT_4_4_4_4,
src_d->lpSurface);
} else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x0000F000) { } else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x0000F000) {
/* Move the four Alpha bits... */ /* Move the four Alpha bits... */
WORD *surface = (WORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
DWORD i; DWORD i;
WORD *src = (WORD *) src_d->lpSurface, *dst = surface; WORD *src = (WORD *) src_d->lpSurface, *dst;
surface = (WORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
dst = surface;
for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) { for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
*dst++ = (((*src & 0xFFF0) >> 4) | *dst++ = (((*src & 0xFFF0) >> 4) |
...@@ -332,101 +265,63 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { ...@@ -332,101 +265,63 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
src++; src++;
} }
if (init_upload) format = GL_RGBA;
glTexImage2D(GL_TEXTURE_2D, pixel_format = GL_UNSIGNED_SHORT_4_4_4_4;
This->mipmap_level,
GL_RGBA,
src_d->dwWidth, src_d->dwHeight,
0,
GL_RGBA,
GL_UNSIGNED_SHORT_4_4_4_4,
surface);
else
glTexSubImage2D(GL_TEXTURE_2D,
This->mipmap_level,
0, 0,
src_d->dwWidth, src_d->dwHeight,
GL_RGBA,
GL_UNSIGNED_SHORT_4_4_4_4,
surface);
HeapFree(GetProcessHeap(), 0, surface);
} else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00008000) { } else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00008000) {
/* Converting the 1555 format in 5551 packed */ /* Converting the 1555 format in 5551 packed */
WORD *surface = (WORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
DWORD i; DWORD i;
WORD *src = (WORD *) src_d->lpSurface, *dst = surface; WORD *src = (WORD *) src_d->lpSurface, *dst;
surface = (WORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
dst = (WORD *) surface;
for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) { for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
*dst++ = (((*src & 0x8000) >> 15) | *dst++ = (((*src & 0x8000) >> 15) |
((*src & 0x7FFF) << 1)); ((*src & 0x7FFF) << 1));
src++; src++;
} }
if (init_upload) format = GL_RGBA;
glTexImage2D(GL_TEXTURE_2D, pixel_format = GL_UNSIGNED_SHORT_5_5_5_1;
This->mipmap_level,
GL_RGBA,
src_d->dwWidth, src_d->dwHeight,
0,
GL_RGBA,
GL_UNSIGNED_SHORT_5_5_5_1,
surface);
else
glTexSubImage2D(GL_TEXTURE_2D,
This->mipmap_level,
0, 0,
src_d->dwWidth, src_d->dwHeight,
GL_RGBA,
GL_UNSIGNED_SHORT_5_5_5_1,
surface);
HeapFree(GetProcessHeap(), 0, surface);
} else { } else {
ERR("Unhandled texture format (bad Aplha channel for a 16 bit texture)\n"); ERR("Unhandled texture format (bad Aplha channel for a 16 bit texture)\n");
error = TRUE;
} }
} else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 24) { } else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 24) {
if (init_upload) format = GL_RGB;
glTexImage2D(GL_TEXTURE_2D, pixel_format = GL_UNSIGNED_BYTE;
This->mipmap_level,
GL_RGB,
src_d->dwWidth, src_d->dwHeight,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
src_d->lpSurface);
else
glTexSubImage2D(GL_TEXTURE_2D,
This->mipmap_level,
0, 0,
src_d->dwWidth, src_d->dwHeight,
GL_RGB,
GL_UNSIGNED_BYTE,
src_d->lpSurface);
} else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 32) { } else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 32) {
format = GL_RGBA;
pixel_format = GL_UNSIGNED_BYTE;
} else {
ERR("Unhandled texture format (bad RGB count)\n");
error = TRUE;
}
} else {
ERR("Unhandled texture format (neither RGB nor INDEX)\n");
error = TRUE;
}
if ((upload_done == FALSE) && (error == FALSE)) {
if (init_upload) if (init_upload)
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
This->mipmap_level, This->mipmap_level,
GL_RGBA, format,
src_d->dwWidth, src_d->dwHeight, src_d->dwWidth, src_d->dwHeight,
0, 0,
GL_RGBA, format,
GL_UNSIGNED_BYTE, pixel_format,
src_d->lpSurface); surface == NULL ? src_d->lpSurface : surface);
else else
glTexSubImage2D(GL_TEXTURE_2D, glTexSubImage2D(GL_TEXTURE_2D,
This->mipmap_level, This->mipmap_level,
0, 0, 0, 0,
src_d->dwWidth, src_d->dwHeight, src_d->dwWidth, src_d->dwHeight,
GL_RGBA, format,
GL_UNSIGNED_BYTE, pixel_format,
src_d->lpSurface); surface == NULL ? src_d->lpSurface : surface);
} else { if (surface) HeapFree(GetProcessHeap(), 0, surface);
ERR("Unhandled texture format (bad RGB count)\n");
}
} else {
ERR("Unhandled texture format (neither RGB nor INDEX)\n");
} }
glBindTexture(GL_TEXTURE_2D, current_texture); glBindTexture(GL_TEXTURE_2D, current_texture);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment