- allow application to load palette-less textures

- handle palette change of loaded textures
- some changes in the ExecuteBuffer
This commit is contained in:
Lionel Ulmer 2003-01-02 19:59:49 +00:00 committed by Alexandre Julliard
parent bb9837d2a4
commit b07df8a198
4 changed files with 84 additions and 54 deletions

View File

@ -217,12 +217,12 @@ static void execute(IDirect3DExecuteBufferImpl *This,
switch (current->bOpcode) {
case D3DOP_POINT: {
TRACE("POINT-s (%d)\n", count);
WARN("POINT-s (%d)\n", count);
instr += count * size;
} break;
case D3DOP_LINE: {
TRACE("LINE-s (%d)\n", count);
WARN("LINE-s (%d)\n", count);
instr += count * size;
} break;
@ -278,37 +278,31 @@ static void execute(IDirect3DExecuteBufferImpl *This,
break;
case D3DVT_TLVERTEX: {
GLdouble height, width, minZ, maxZ;
GLdouble height, width;
GLfloat trans_mat[16];
/* First, disable lighting */
glDisable(GL_LIGHTING);
/* Then do not put any transformation matrixes */
width = lpDevice->surface->surface_desc.dwWidth;
height = lpDevice->surface->surface_desc.dwHeight;
/* The X axis is straighforward.. For the Y axis, we need to convert 'D3D' screen coordinates
to OpenGL screen coordinates (ie the upper left corner is not the same).
For Z, the mystery is what should it be mapped to ? Ie should the resulting range be between
-1.0 and 1.0 (as the X and Y coordinates) or between 0.0 and 1.0 ? */
trans_mat[ 0] = 2.0 / width; trans_mat[ 4] = 0.0; trans_mat[ 8] = 0.0; trans_mat[12] = -1.0;
trans_mat[ 1] = 0.0; trans_mat[ 5] = -2.0 / height; trans_mat[ 9] = 0.0; trans_mat[13] = 1.0;
trans_mat[ 2] = 0.0; trans_mat[ 6] = 0.0; trans_mat[10] = 1.0; trans_mat[14] = -1.0;
trans_mat[ 3] = 0.0; trans_mat[ 7] = 0.0; trans_mat[11] = 0.0; trans_mat[15] = 1.0;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glLoadMatrixf(trans_mat);
if (lpViewport == NULL) {
ERR("No current viewport !\n");
/* Using standard values */
height = 640.0;
width = 480.0;
minZ = -10.0;
maxZ = 10.0;
} else {
height = (GLdouble) lpViewport->viewports.vp1.dwHeight;
width = (GLdouble) lpViewport->viewports.vp1.dwWidth;
minZ = (GLdouble) lpViewport->viewports.vp1.dvMinZ;
maxZ = (GLdouble) lpViewport->viewports.vp1.dvMaxZ;
if (minZ == maxZ) {
/* I do not know why, but many Dx 3.0 games have minZ = maxZ = 0.0 */
minZ = 0.0;
maxZ = 1.0;
}
}
glOrtho(0.0, width, height, 0.0, -minZ, -maxZ);
/* Remove also fogging... */
glDisable(GL_FOG);
} break;
default:
@ -335,7 +329,7 @@ static void execute(IDirect3DExecuteBufferImpl *This,
} break;
case D3DOP_MATRIXLOAD:
TRACE("MATRIXLOAD-s (%d)\n", count);
WARN("MATRIXLOAD-s (%d)\n", count);
instr += count * size;
break;
@ -440,23 +434,23 @@ static void execute(IDirect3DExecuteBufferImpl *This,
} break ;
case D3DLIGHTSTATE_COLORMODEL: {
TRACE(" COLORMODEL\n");
WARN(" COLORMODEL\n");
} break ;
case D3DLIGHTSTATE_FOGMODE: {
TRACE(" FOGMODE\n");
WARN(" FOGMODE\n");
} break ;
case D3DLIGHTSTATE_FOGSTART: {
TRACE(" FOGSTART\n");
WARN(" FOGSTART\n");
} break ;
case D3DLIGHTSTATE_FOGEND: {
TRACE(" FOGEND\n");
WARN(" FOGEND\n");
} break ;
case D3DLIGHTSTATE_FOGDENSITY: {
TRACE(" FOGDENSITY\n");
WARN(" FOGDENSITY\n");
} break ;
default:
@ -605,7 +599,7 @@ static void execute(IDirect3DExecuteBufferImpl *This,
} break;
case D3DOP_TEXTURELOAD: {
TRACE("TEXTURELOAD-s (%d)\n", count);
WARN("TEXTURELOAD-s (%d)\n", count);
instr += count * size;
} break;
@ -640,7 +634,7 @@ static void execute(IDirect3DExecuteBufferImpl *This,
} break;
case D3DOP_SPAN: {
TRACE("SPAN-s (%d)\n", count);
WARN("SPAN-s (%d)\n", count);
instr += count * size;
} break;
@ -737,7 +731,7 @@ Main_IDirect3DExecuteBufferImpl_1_Lock(LPDIRECT3DEXECUTEBUFFER iface,
{
ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
DWORD dwSize;
TRACE("(%p/%p)->(%p): stub!\n", This, iface, lpDesc);
TRACE("(%p/%p)->(%p)\n", This, iface, lpDesc);
dwSize = lpDesc->dwSize;
memset(lpDesc, 0, dwSize);

View File

@ -177,10 +177,10 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
#endif
if (pal == NULL) {
ERR("Palettized texture Loading with a NULL palette !\n");
glBindTexture(GL_TEXTURE_2D, current_texture);
return D3DERR_INVALIDPALETTE;
}
/* Upload a black texture. The real one will be uploaded on palette change */
WARN("Palettized texture Loading with a NULL palette !\n");
memset(table, 0, 256 * 4);
} else {
/* Get the surface's palette */
for (i = 0; i < 256; i++) {
table[i][0] = pal->palents[i].peRed;
@ -193,6 +193,7 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
else
table[i][3] = 0xFF;
}
}
if (ptr_ColorTableEXT != NULL) {
/* use Paletted Texture Extension */
@ -373,6 +374,19 @@ Main_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface,
return DD_OK;
}
static void gltex_set_palette(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal)
{
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
/* First call the previous set_palette function */
glThis->set_palette(This, pal);
/* Then re-upload the texture to OpenGL */
ENTER_GL();
gltex_upload_texture(This, glThis->first_unlock);
LEAVE_GL();
}
static void
gltex_final_release(IDirectDrawSurfaceImpl *This)
{
@ -415,12 +429,12 @@ gltex_unlock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect)
{
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
glThis->unlock_update(This, pRect);
ENTER_GL();
gltex_upload_texture(This, glThis->first_unlock);
LEAVE_GL();
glThis->first_unlock = FALSE;
glThis->unlock_update(This, pRect);
}
HRESULT WINAPI
@ -490,7 +504,22 @@ GL_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface,
/* Suppress the ALLOCONLOAD flag */
This->surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_ALLOCONLOAD;
/* After seeing some logs, not sure at all about this... */
if (This->palette == NULL) {
This->palette = lpD3DTextureImpl->palette;
if (lpD3DTextureImpl->palette != NULL) IDirectDrawPalette_AddRef(ICOM_INTERFACE(lpD3DTextureImpl->palette,
IDirectDrawPalette));
} else {
if (lpD3DTextureImpl->palette != NULL) {
PALETTEENTRY palent[256];
IDirectDrawPalette *pal_int = ICOM_INTERFACE(lpD3DTextureImpl->palette, IDirectDrawPalette);
IDirectDrawPalette_AddRef(pal_int);
IDirectDrawPalette_GetEntries(pal_int, 0, 0, 256, palent);
IDirectDrawPalette_SetEntries(ICOM_INTERFACE(This->palette, IDirectDrawPalette),
0, 0, 256, palent);
}
}
/* Copy one surface on the other */
dst_d = (DDSURFACEDESC *)&(This->surface_desc);
@ -676,6 +705,7 @@ HRESULT d3dtexture_create(IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOL
private->final_release = surf->final_release;
private->lock_update = surf->lock_update;
private->unlock_update = surf->unlock_update;
private->set_palette = surf->set_palette;
/* If at creation, we can optimize stuff and wait the first 'unlock' to upload a valid stuff to OpenGL.
Otherwise, it will be uploaded here (and may be invalid). */
@ -688,6 +718,7 @@ HRESULT d3dtexture_create(IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOL
surf->unlock_update = gltex_unlock_update;
surf->tex_private = private;
surf->aux_setcolorkey_cb = gltex_setcolorkey_cb;
surf->set_palette = gltex_set_palette;
ENTER_GL();
if (surf->mipmap_level == 0) {

View File

@ -100,6 +100,10 @@ HRESULT Main_DirectDrawSurface_late_allocate(IDirectDrawSurfaceImpl* This)
static void Main_DirectDrawSurface_Destroy(IDirectDrawSurfaceImpl* This)
{
if (This->palette) {
IDirectDrawPalette_Release(ICOM_INTERFACE(This->palette, IDirectDrawPalette));
This->palette = NULL;
}
This->final_release(This);
if (This->private != This+1) HeapFree(GetProcessHeap(), 0, This->private);
if (This->tex_private) HeapFree(GetProcessHeap(), 0, This->tex_private);

View File

@ -100,6 +100,7 @@ typedef struct IDirect3DTextureGLImpl
void (*final_release)(struct IDirectDrawSurfaceImpl *This);
void (*lock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
void (*unlock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
void (*set_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal);
} IDirect3DTextureGLImpl;
typedef struct IDirect3DDeviceGLImpl