static HRESULT create_surface(dd_info *dd, DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type) { HRESULT result; // create the surface as requested result = IDirectDraw7_CreateSurface(dd->ddraw, desc, surface, NULL); if (result != DD_OK) { mame_printf_verbose("DirectDraw: Error %08X creating %s surface\n", (int)result, type); return result; } // get a description of the primary surface result = IDirectDrawSurface7_GetSurfaceDesc(*surface, desc); if (result != DD_OK) { mame_printf_verbose("DirectDraw: Error %08X getting %s surface desciption\n", (int)result, type); IDirectDrawSurface7_Release(*surface); *surface = NULL; return result; } // print out the good stuff mame_printf_verbose("DirectDraw: %s surface created: %dx%dx%d (R=%08X G=%08X B=%08X)\n", type, (int)desc->dwWidth, (int)desc->dwHeight, (int)desc->ddpfPixelFormat.dwRGBBitCount, (UINT32)desc->ddpfPixelFormat.dwRBitMask, (UINT32)desc->ddpfPixelFormat.dwGBitMask, (UINT32)desc->ddpfPixelFormat.dwBBitMask); return result; }
int test_video_resolution ( int width, int height, int depth ) { unsigned int ddrval; DDSURFACEDESC2 ddsd; DDSCAPS2 caps; // // Set the video mode // { int parms[3]; parms[0] = width; parms[1] = height; parms[2] = depth; ddrval = system_thread_function ( ddraw_internal_set_display_mode, parms ); } if ( ddrval != DD_OK ) { debug_log ( "Unable to set display resolution: %d, %d, %d: %s", width, height, depth, get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } // // Release any previous pointers // release_ddraw_surface_pointers (); // // Create the primary surface // memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof (ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE; if ( ddraw.use_double_buffer ) { ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; ddsd.dwBackBufferCount = 1; ddsd.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX; } #ifdef _WIN32 ddrval = IDirectDraw7_CreateSurface ( ddraw.ddraw, &ddsd, &ddraw.lpFrontBuffer, NULL); if ( ddrval != DD_OK ) { debug_log ( "Unable to create primary surface: %s", get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } #endif if ( ddraw.use_double_buffer ) { // // Get the back screen from this surface. // memset ( &caps, 0, sizeof ( caps ) ); caps.dwCaps = DDSCAPS_BACKBUFFER; #ifdef _WIN32 ddrval = IDirectDrawSurface7_GetAttachedSurface ( ddraw.lpFrontBuffer, &caps, &ddraw.lpBackBuffer ); if ( ddrval != DD_OK ) { debug_log ( "Unable to get backbuffer: %s", get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } #endif } if ( ddraw.use_system_memory ) { // // Create the system memory surface // memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); #ifdef _WIN32 ddrval = IDirectDrawSurface7_GetSurfaceDesc ( ddraw.lpFrontBuffer, &ddsd ); #endif ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_SYSTEMMEMORY; ddsd.dwHeight = height; ddsd.dwWidth = width; #ifdef _WIN32 ddrval = IDirectDraw7_CreateSurface ( ddraw.ddraw , &ddsd, &ddraw.lpRenderBuffer, NULL ); if ( ddrval != DD_OK ) { debug_log ( "Unable to create system memory surface: %s", get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } #endif } else { // // Set the render buffer // if ( ddraw.use_double_buffer ) { ddraw.lpRenderBuffer = ddraw.lpBackBuffer; ddraw.lpRenderBuffer = ddraw.lpBackBuffer; } else { ddraw.lpRenderBuffer = ddraw.lpFrontBuffer; ddraw.lpRenderBuffer = ddraw.lpFrontBuffer; } } if ( ddraw.use_z_buffer ) { // // Create the zbuffer and attach it to the render buffer. // memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof ( ddsd ); #ifdef _WIN32 ddrval = IDirectDrawSurface7_GetSurfaceDesc ( ddraw.lpFrontBuffer, &ddsd ); #endif ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY; ddsd.dwHeight = height; ddsd.dwWidth = width; get_ddraw_zbuffer_pixel_format ( &ddsd.ddpfPixelFormat ); #ifdef _WIN32 ddrval = IDirectDraw7_CreateSurface ( ddraw.ddraw, &ddsd, &ddraw.lpZBuffer, NULL ); if ( ddrval != DD_OK ) { debug_log ( "Unable to create Zbuffer surface: %s", get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } ddrval = IDirectDrawSurface7_AddAttachedSurface ( ddraw.lpRenderBuffer, ddraw.lpZBuffer ); if ( ddrval != DD_OK ) { debug_log ( "Unable to attach Zbuffer surface: %s", get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } #endif } application_video_width = width; application_video_height = height; return ( TRUE ); }
void create_texture_screen_data ( screen *texture, int width, int height, int type, int number_of_mipmaps, int renderto ) { DDSURFACEDESC2 ddsd; unsigned int ret; debug_log ( "Creating user texture screen: %d, %d ( %d mipmaps ) ( %d render to ) ", width, height, number_of_mipmaps, renderto ); #ifdef _WIN32 memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof ( ddsd ); // // Allocate a d3d managed texture // memcpy ( &ddsd.ddpfPixelFormat, &texture_formats[type].format, sizeof ( DDPIXELFORMAT ) ); ddsd.dwMipMapCount = 0; ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.dwHeight = height; ddsd.dwWidth = width; ddsd.ddsCaps.dwCaps3 = 0; ddsd.ddsCaps.dwCaps4 = 0; ddsd.ddsCaps.dwCaps2 = DDSCAPS2_HINTDYNAMIC | DDSCAPS2_TEXTUREMANAGE; if ( ( d3d_mipmap_textures ) && ( number_of_mipmaps > 1 ) ) { ddsd.dwFlags |= DDSD_MIPMAPCOUNT; ddsd.ddsCaps.dwCaps |= DDSCAPS_COMPLEX | DDSCAPS_MIPMAP; ddsd.dwMipMapCount = number_of_mipmaps; } ret = IDirectDraw7_CreateSurface ( ddraw.ddraw, &ddsd, &texture->surface, NULL ); if ( ret != DD_OK ) { debug_fatal ( "Unable to create texture surface: %s ( %d, %d )", get_ddraw_error_message ( ret ), width, height ); } #endif texture->surface = SDL_CreateRGBSurface(0,width,height,texture_formats[type].format.BitsPerPixel,texture_formats[type].format.Rmask, texture_formats[type].format.Gmask,texture_formats[type].format.Bmask,texture_formats[type].format.Amask); glGenTextures(1, &texture->texName); glBindTexture(GL_TEXTURE_2D, texture->texName); // // Texture doesn't have a colour table // texture->type = type; texture->palette = NULL; texture->colour_table = NULL; texture->pixel_length = texture_formats[type].bpp_red + texture_formats[type].bpp_green + texture_formats[type].bpp_blue + texture_formats[type].bpp_alpha; texture->clone_screen = FALSE; texture->do_not_destroy = FALSE; // // Setup render surface // if ( renderto ) { #ifdef _WIN32 memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof ( ddsd ); memcpy ( &ddsd.ddpfPixelFormat, &texture_formats[type].format, sizeof ( DDPIXELFORMAT ) ); ddsd.dwSize = sizeof ( ddsd ); ddsd.dwMipMapCount = 0; ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_3DDEVICE; ddsd.dwHeight = height; ddsd.dwWidth = width; ddsd.ddsCaps.dwCaps3 = 0; ddsd.ddsCaps.dwCaps4 = 0; ddsd.ddsCaps.dwCaps2 = 0; ddsd.ddsCaps.dwCaps |= ( d3d_use_rgb_device ) ? ( DDSCAPS_SYSTEMMEMORY ) : ( DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM ); ret = IDirectDraw7_CreateSurface ( ddraw.ddraw, &ddsd, &texture->render_texture_surface, NULL ); if ( ret != DD_OK ) { debug_fatal ( "Unable to create texture render surface: %s ( %d, %d )", get_ddraw_error_message ( ret ), width, height ); } memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof ( ddsd ); ret = IDirectDrawSurface7_GetSurfaceDesc ( ddraw.lpFrontBuffer, &ddsd ); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER; ddsd.ddsCaps.dwCaps |= ( d3d_use_rgb_device ) ? ( DDSCAPS_SYSTEMMEMORY ) : ( DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM ); ddsd.dwWidth = width; ddsd.dwHeight = height; #endif get_ddraw_zbuffer_pixel_format ( &ddsd.ddpfPixelFormat ); // ddsd.ddpfPixelFormat.dwSize = sizeof ( ddsd.ddpfPixelFormat ); // ddsd.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER; // ddsd.ddpfPixelFormat.dwZBufferBitDepth = 16; #ifdef _WIN32 ret = IDirectDraw7_CreateSurface ( ddraw.ddraw, &ddsd, &texture->zbuffer_surface, NULL ); if ( ret != DD_OK ) { debug_fatal ( "Unable to create Zbuffer surface: %s", get_ddraw_error_message ( ret ) ); } ret = IDirectDrawSurface7_AddAttachedSurface ( texture->render_texture_surface, texture->zbuffer_surface ); if ( ret != DD_OK ) { debug_fatal ( "Unable to attach Zbuffer surface: %s", get_ddraw_error_message ( ret ) ); } #endif } }
// create surface from DDSURFACEDESC2 CSURFACE *DDrawCreateFromDesc(const DDSURFACEDESC2 *desc, HRESULT *hr) { LPDIRECTDRAWSURFACE7 lpDDS; DDSURFACEDESC2 ddsd; CSURFACE *surface; HRESULT result; if (lpDirectDraw7 == NULL) { if (DDrawInit() != 0) return NULL; } surface = (CSURFACE*)malloc(sizeof(CSURFACE)); assert(surface); ddsd = *desc; result = IDirectDraw7_CreateSurface(lpDirectDraw7, &ddsd, &lpDDS, NULL); if (hr) *hr = result; if (result != DD_OK) { free(surface); return NULL; } result = IDirectDrawSurface7_GetSurfaceDesc(lpDDS, &ddsd); if (hr) *hr = result; if (result != DD_OK) { IDirectDrawSurface7_Release(lpDDS); free(surface); return NULL; } surface->lpDDS = lpDDS; surface->ddsd = ddsd; surface->w = ddsd.dwWidth; surface->h = ddsd.dwHeight; surface->bpp = ddsd.ddpfPixelFormat.dwRGBBitCount; if (surface->bpp == 8) surface->pixfmt = PIXFMT_8; else if (surface->bpp == 15) surface->pixfmt = PIXFMT_RGB15; else if (surface->bpp == 16) surface->pixfmt = PIXFMT_RGB16; else if (surface->bpp == 24) surface->pixfmt = PIXFMT_RGB24; else if (surface->bpp == 32) { if (ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS) { surface->pixfmt = PIXFMT_ARGB32; } else { surface->pixfmt = PIXFMT_RGB32; } } surface->pitch = ddsd.dwLinearSize; surface->bits = (unsigned char*)ddsd.lpSurface; surface->mask = 0; surface->lock = 0; surface->clip = NULL; surface->primary = 0; surface->hWnd = NULL; hSurfaceCounter++; return surface; }