Пример #1
0
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;
}
Пример #2
0
static HRESULT WINAPI
IDirectDraw3Impl_CreateSurface(LPDIRECTDRAW3 This, LPDDSURFACEDESC pSDesc,
			       LPDIRECTDRAWSURFACE *ppSurface,
			       IUnknown *pUnkOuter)
{
    LPDIRECTDRAWSURFACE7 pSurface7;
    IDirectDrawSurfaceImpl *impl;
    HRESULT hr;

    hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw3(This),
            (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
    if (FAILED(hr))
    {
        *ppSurface = NULL;
        return hr;
    }

    impl = (IDirectDrawSurfaceImpl *)pSurface7;
    *ppSurface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl;
    set_surf_version(impl, 3);
    IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw3(This));
    IDirectDraw3_AddRef(This);
    impl->ifaceToRelease = (IUnknown *) This;

    return hr;
}
Пример #3
0
static HRESULT WINAPI
IDirectDrawImpl_CreateSurface(LPDIRECTDRAW This, LPDDSURFACEDESC pSDesc,
			      LPDIRECTDRAWSURFACE *ppSurface,
			      IUnknown *pUnkOuter)
{
    LPDIRECTDRAWSURFACE7 pSurface7;
    IDirectDrawSurfaceImpl *impl;
    HRESULT hr;

    /* Remove front buffer flag, this causes failure in v7, and its added to normal
     * primaries anyway
     */
    pSDesc->ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;
    /* the LPDDSURFACEDESC -> LPDDSURFACEDESC2 conversion should be ok,
     * since the data layout is the same */
    hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw1(This),
            (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
    if (FAILED(hr))
    {
        *ppSurface = NULL;
        return hr;
    }

    impl = (IDirectDrawSurfaceImpl *)pSurface7;
    *ppSurface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl;
    set_surf_version(impl, 1);
    IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw1(This));
    impl->ifaceToRelease = NULL;

    return hr;
}
Пример #4
0
LPDIRECTDRAWSURFACE7 CreateBMP( win32_driver_t * win32_driver, int resource )
{
	LPDIRECTDRAWSURFACE7	bmp_surf;
    DDSURFACEDESC2			bmp_ddsd;
	HBITMAP					bmp_hndl;
	BITMAP					bmp_head;
	HDC						hdc_dds;
	HDC						hdc_mem;

	// load our bitmap from a resource

	if( !( bmp_hndl = LoadBitmap( win32_driver->win32_visual->HInst, MAKEINTRESOURCE( resource ) ) ) )
	{
		Error( 0, "CreateBitmap : could not load bmp resource" );
		return 0;
	}

	// create an off screen surface with
	// the same dimentions as our bitmap

	GetObject( bmp_hndl, sizeof( bmp_head ), &bmp_head );

    memset( &bmp_ddsd, 0, sizeof( bmp_ddsd ) );
    bmp_ddsd.dwSize         = sizeof( bmp_ddsd );
    bmp_ddsd.dwFlags        = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
    bmp_ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
    bmp_ddsd.dwWidth        = bmp_head.bmWidth;
    bmp_ddsd.dwHeight       = bmp_head.bmHeight;

	if( IDirectDraw7_CreateSurface( win32_driver->ddobj, &bmp_ddsd, &bmp_surf, 0 ) != DD_OK )
	{
		Error( 0, "CreateSurface ( bitmap ) : could not create dd surface" );
		return 0;
	}
	
	// get a handle to our surface dc,
	// create a compat dc and load
	// our bitmap into the compat dc

	IDirectDrawSurface7_GetDC( bmp_surf, &hdc_dds );
	hdc_mem = CreateCompatibleDC( hdc_dds );
	SelectObject( hdc_mem, bmp_hndl );

	// copy our bmp from the compat dc
	// into our dd surface

	BitBlt( hdc_dds, 0, 0, bmp_head.bmWidth, bmp_head.bmHeight,
			hdc_mem, 0, 0, SRCCOPY );

	// clean up

	DeleteDC( hdc_mem );
	DeleteObject( bmp_hndl );
	IDirectDrawSurface7_ReleaseDC( bmp_surf, hdc_dds );

	return bmp_surf;
}
Пример #5
0
static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
{
    IDirect3DDevice7 *device = NULL;
    IDirectDrawSurface7 *surface;
    DDSURFACEDESC2 surface_desc;
    IDirectDraw7 *ddraw;
    IDirect3D7 *d3d7;
    HRESULT hr;

    if (!(ddraw = create_ddraw()))
        return NULL;

    hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, coop_level);
    ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);

    memset(&surface_desc, 0, sizeof(surface_desc));
    surface_desc.dwSize = sizeof(surface_desc);
    surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
    surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
    surface_desc.dwWidth = 640;
    surface_desc.dwHeight = 480;

    hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);

    if (coop_level & DDSCL_NORMAL)
    {
        IDirectDrawClipper *clipper;

        hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
        ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
        hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
        ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
        hr = IDirectDrawSurface7_SetClipper(surface, clipper);
        ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
        IDirectDrawClipper_Release(clipper);
    }

    hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d7);
    IDirectDraw7_Release(ddraw);
    if (FAILED(hr))
    {
        IDirectDrawSurface7_Release(surface);
        return NULL;
    }

    hr = IDirect3D7_CreateDevice(d3d7, &IID_IDirect3DTnLHalDevice, surface, &device);
    IDirect3D7_Release(d3d7);
    IDirectDrawSurface7_Release(surface);
    if (FAILED(hr))
        return NULL;

    return device;
}
Пример #6
0
static BOOL CreateDirectDraw(void)
{
    HRESULT hr;
    DDSURFACEDESC2 ddsd;
    IDirectDrawSurface7 *overlay = NULL;
    HMODULE hmod = GetModuleHandleA("ddraw.dll");

    pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
    if (!pDirectDrawCreateEx) {
        win_skip("DirectDrawCreateEx is not available\n");
        return FALSE;
    }

    hr = pDirectDrawCreateEx(NULL, (void**)&ddraw, &IID_IDirectDraw7, NULL);
    ok(hr == DD_OK || hr == DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
    if (!ddraw) {
        trace("DirectDrawCreateEx() failed with an error %x\n", hr);
        return FALSE;
    }

    hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
    ok(hr == DD_OK, "SetCooperativeLevel returned: %x\n", hr );

    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
    hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
    if (FAILED(hr)) {
        IDirectDraw7_Release(ddraw);
        trace("IDirectDraw7_CreateSurface() failed with an error %x\n", hr);
        return FALSE;
    }

    overlay = create_overlay(64, 64, MAKEFOURCC('U','Y','V','Y'));
    if (!overlay) {
        IDirectDrawSurface7_Release(primary);
        IDirectDraw7_Release(ddraw);
        skip("Failed to create an overlay - assuming not supported\n");
        return FALSE;
    }
    IDirectDraw7_Release(overlay);

    return TRUE;
}
Пример #7
0
static IDirectDrawSurface7 *create_overlay(DWORD width, DWORD height, DWORD format) {
    DDSURFACEDESC2 ddsd;
    HRESULT hr;
    IDirectDrawSurface7 *ret;

    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
    ddsd.dwWidth = width;
    ddsd.dwHeight = height;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY;
    U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
    U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
    U4(ddsd).ddpfPixelFormat.dwFourCC = format;
    hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &ret, NULL);
    if(FAILED(hr)) return NULL;
    else return ret;
}
Пример #8
0
static HRESULT WINAPI
IDirectDraw4Impl_CreateSurface(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pSDesc,
			       LPDIRECTDRAWSURFACE4 *ppSurface,
			       IUnknown *pUnkOuter)
{
    HRESULT hr;
    IDirectDrawSurfaceImpl *impl;

    hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw4(This),
            pSDesc, (LPDIRECTDRAWSURFACE7 *)ppSurface, pUnkOuter);
    impl = (IDirectDrawSurfaceImpl *)*ppSurface;
    if(SUCCEEDED(hr) && impl)
    {
        set_surf_version(impl, 4);
        IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw4(This));
        IDirectDraw4_AddRef(This);
        impl->ifaceToRelease = (IUnknown *) This;
    }
    return hr;
}
Пример #9
0
static void offscreen_test(void) {
    IDirectDrawSurface7 *overlay = create_overlay(64, 64, MAKEFOURCC('U','Y','V','Y')), *offscreen = NULL;
    HRESULT hr;
    DDSURFACEDESC2 ddsd;

    /* Try to overlay a NULL surface */
    hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_SHOW, NULL);
    ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr);
    hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_HIDE, NULL);
    ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr);

    /* Try to overlay an offscreen surface */
    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
    ddsd.dwWidth = 64;
    ddsd.dwHeight = 64;
    U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
    U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
    U4(ddsd).ddpfPixelFormat.dwFourCC = 0;
    U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
    U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
    U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07e0;
    U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
    hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &offscreen, NULL);
    ok(hr == DD_OK, "IDirectDraw7_CreateSurface failed with hr=0x%08x\n", hr);

    hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, offscreen, NULL, DDOVER_SHOW, NULL);
    ok(hr == DD_OK || broken(hr == E_NOTIMPL),
       "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr);

    /* Try to overlay the primary with a non-overlay surface */
    hr = IDirectDrawSurface7_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_SHOW, NULL);
    ok(hr == DDERR_NOTAOVERLAYSURFACE, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr);

    IDirectDrawSurface7_Release(offscreen);
    IDirectDrawSurface7_Release(overlay);
}
Пример #10
0
static int create_directdraw(void)
{
    HRESULT hr;
    IDirectDraw* pdd = NULL;
    DDSURFACEDESC2 ddsd;

    hr = DirectDrawCreate(NULL, &pdd, NULL);
    ok(hr==DD_OK, "DirectDrawCreate returned: %x\n", hr);
    if (hr != DD_OK)
       goto error;

    hr = IDirectDraw_QueryInterface(pdd, &IID_IDirectDraw7, (LPVOID*)&pdd7);
    ok(hr==DD_OK, "QueryInterface returned: %x\n", hr);
    if (hr != DD_OK) goto error;

    hr = IDirectDraw7_SetCooperativeLevel(pdd7, GetDesktopWindow(), DDSCL_NORMAL);
    ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);

    ZeroMemory(&ddsd, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
    hr = IDirectDraw7_CreateSurface(pdd7, &ddsd, &pdds7, NULL);
    ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);

    return TRUE;

error:
    if (pdds7)
        IDirectDrawSurface7_Release(pdds7);
    if (pdd7)
        IDirectDraw7_Release(pdd7);
    if (pdd)
        IDirectDraw_Release(pdd);

    return FALSE;
}
Пример #11
0
// 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;
}
Пример #12
0
boolean CreateSecondary( win32_driver_t * win32_driver, int width, int height, int format )
{
    DDSURFACEDESC2			ddsd;

	if( format == XINE_IMGFMT_YV12 )
		printf( "vo_out_directx : switching to YV12 overlay type\n" );

	if( format == XINE_IMGFMT_YUY2 )
		printf( "vo_out_directx : switching to YUY2 overlay type\n" );

#if RGB_SUPPORT
	if( format == IMGFMT_RGB )
		printf( "vo_out_directx : switching to RGB overlay type\n" );
#endif

	if( !win32_driver->ddobj )
		return FALSE;

	// store our reqested format,
	// width and height

	win32_driver->req_format	= format;
	win32_driver->width			= width;
	win32_driver->height		= height;

	// if we already have a secondary
	// surface then release it

	if( win32_driver->secondary )
		IDirectDrawSurface7_Release( win32_driver->secondary );

    memset( &ddsd, 0, sizeof( ddsd ) );
    ddsd.dwSize         = sizeof( ddsd );
    ddsd.dwWidth        = width;
    ddsd.dwHeight       = height;

	if( format == XINE_IMGFMT_YV12 )
	{
		// the requested format is XINE_IMGFMT_YV12

	    ddsd.dwFlags        = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
		ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY; 
		ddsd.ddpfPixelFormat.dwSize =			sizeof(DDPIXELFORMAT);
		ddsd.ddpfPixelFormat.dwFlags =			DDPF_FOURCC;
		ddsd.ddpfPixelFormat.dwYUVBitCount =	16;
		ddsd.ddpfPixelFormat.dwFourCC =			mmioFOURCC( 'Y', 'V', '1', '2' );

#ifdef LOG
		printf("CreateSecondary() - act_format = (YV12) %d\n", XINE_IMGFMT_YV12);
#endif

		win32_driver->act_format = XINE_IMGFMT_YV12;
	}

	if( format == XINE_IMGFMT_YUY2 )
	{
		// the requested format is XINE_IMGFMT_YUY2

	    ddsd.dwFlags        = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
	    ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY; 
		ddsd.ddpfPixelFormat.dwSize =			sizeof(DDPIXELFORMAT);
		ddsd.ddpfPixelFormat.dwFlags =			DDPF_FOURCC;
		ddsd.ddpfPixelFormat.dwYUVBitCount =	16;
		ddsd.ddpfPixelFormat.dwFourCC =			mmioFOURCC( 'Y', 'U', 'Y', '2' );

#ifdef LOG
		printf("CreateSecondary() - act_format = (YUY2) %d\n", XINE_IMGFMT_YUY2);
#endif

		win32_driver->act_format = XINE_IMGFMT_YUY2;
	}

#if RGB_SUPPORT
	if( format == IMGFMT_RGB )
	{
		// the requested format is IMGFMT_RGB

	    ddsd.dwFlags        = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
	    ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY; 
		ddsd.ddpfPixelFormat.dwSize =			sizeof(DDPIXELFORMAT);
		ddsd.ddpfPixelFormat.dwFlags =			DDPF_RGB;
		ddsd.ddpfPixelFormat.dwYUVBitCount =	24;
		ddsd.ddpfPixelFormat.dwRBitMask =		0xff0000;
		ddsd.ddpfPixelFormat.dwGBitMask =		0x00ff00;
		ddsd.ddpfPixelFormat.dwBBitMask =		0x0000ff;

#ifdef LOG
		printf("CreateSecondary() - act_format = (RGB) %d\n", IMGFMT_RGB);
#endif

		win32_driver->act_format = IMGFMT_RGB;
	} 
#endif /* RGB_SUPPORT */

#ifdef LOG
	printf("CreateSecondary() - IDirectDraw7_CreateSurface()\n");
#endif

	if( IDirectDraw7_CreateSurface( win32_driver->ddobj, &ddsd, &win32_driver->secondary, 0 ) == DD_OK )
		return TRUE;

	// Our fallback method is to create a back buffer
	// with the same image format as the primary surface

#ifdef LOG
	printf("CreateSecondary() - Falling back to back buffer same as primary\n");
#endif

    ddsd.dwFlags        = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;

#ifdef LOG
	printf("CreateSecondary() - act_format = (NATIVE) %d\n", IMGFMT_NATIVE);
#endif

	win32_driver->act_format = IMGFMT_NATIVE;

	if( IDirectDraw7_CreateSurface( win32_driver->ddobj, &ddsd, &win32_driver->secondary, 0 ) == DD_OK )
		return TRUE;

	// This is bad. We cant even create a surface with
	// the same format as the primary surface.

	Error( 0, "CreateSurface ( Secondary ) : unable to create a suitable rendering surface" );

	return FALSE;
}
Пример #13
0
static void test_clipper_blt(void)
{
    IDirectDrawSurface7 *src_surface, *dst_surface;
    RECT client_rect, src_rect, *rect;
    IDirectDrawClipper *clipper;
    DDSURFACEDESC2 surface_desc;
    unsigned int i, j, x, y;
    IDirectDraw7 *ddraw;
    RGNDATA *rgn_data;
    D3DCOLOR color;
    HRGN r1, r2;
    HWND window;
    DDBLTFX fx;
    HRESULT hr;
    DWORD ret;

    static const D3DCOLOR expected1[] =
    {
        0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
        0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
        0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
        0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
    };
    static const D3DCOLOR expected2[] =
    {
        0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
        0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
        0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
        0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
    };

    window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
            10, 10, 640, 480, 0, 0, 0, 0);
    ShowWindow(window, SW_SHOW);
    if (!(ddraw = create_ddraw()))
    {
        skip("Failed to create a ddraw object, skipping test.\n");
        DestroyWindow(window);
        return;
    }

    ret = GetClientRect(window, &client_rect);
    ok(ret, "Failed to get client rect.\n");
    ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
    ok(ret, "Failed to map client rect.\n");

    hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
    ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);

    hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
    ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
    hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
    ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
    hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
    ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
    hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
    ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
    rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
    hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
    ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
    ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
    ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
    ok(rgn_data->rdh.nCount == 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
    ok(rgn_data->rdh.nRgnSize == 16, "Got unexpected region size %u.\n", rgn_data->rdh.nRgnSize);
    ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
            "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
            rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
            rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
            client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
    rect = (RECT *)&rgn_data->Buffer[0];
    ok(EqualRect(rect, &client_rect),
            "Got unexpected clip rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
            rect->left, rect->top, rect->right, rect->bottom,
            client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
    HeapFree(GetProcessHeap(), 0, rgn_data);

    r1 = CreateRectRgn(0, 0, 320, 240);
    ok(!!r1, "Failed to create region.\n");
    r2 = CreateRectRgn(320, 240, 640, 480);
    ok(!!r2, "Failed to create region.\n");
    CombineRgn(r1, r1, r2, RGN_OR);
    ret = GetRegionData(r1, 0, NULL);
    rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
    ret = GetRegionData(r1, ret, rgn_data);
    ok(!!ret, "Failed to get region data.\n");

    DeleteObject(r2);
    DeleteObject(r1);

    hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
    ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
    hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
    ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
    hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
    ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);

    HeapFree(GetProcessHeap(), 0, rgn_data);

    memset(&surface_desc, 0, sizeof(surface_desc));
    surface_desc.dwSize = sizeof(surface_desc);
    surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
    surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
    surface_desc.dwWidth = 640;
    surface_desc.dwHeight = 480;
    U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
    U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
    U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
    U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
    U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
    U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;

    hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
    ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
    hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
    ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);

    memset(&fx, 0, sizeof(fx));
    fx.dwSize = sizeof(fx);
    hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
    ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
    hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
    ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);

    hr = IDirectDrawSurface7_Lock(src_surface, NULL, &surface_desc, 0, NULL);
    ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
    ((DWORD *)surface_desc.lpSurface)[0] = 0xff0000ff;
    ((DWORD *)surface_desc.lpSurface)[1] = 0xff00ff00;
    ((DWORD *)surface_desc.lpSurface)[2] = 0xffff0000;
    ((DWORD *)surface_desc.lpSurface)[3] = 0xffffffff;
    hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
    ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);

    hr = IDirectDrawSurface7_SetClipper(dst_surface, clipper);
    ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);

    SetRect(&src_rect, 0, 0, 4, 1);
    hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
    ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
    for (i = 0; i < 4; ++i)
    {
        for (j = 0; j < 4; ++j)
        {
            x = 80 * ((2 * j) + 1);
            y = 60 * ((2 * i) + 1);
            color = get_surface_color(dst_surface, x, y);
            ok(compare_color(color, expected1[i * 4 + j], 1),
                    "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
        }
    }

    U5(fx).dwFillColor = 0xff0000ff;
    hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
    ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
    for (i = 0; i < 4; ++i)
    {
        for (j = 0; j < 4; ++j)
        {
            x = 80 * ((2 * j) + 1);
            y = 60 * ((2 * i) + 1);
            color = get_surface_color(dst_surface, x, y);
            ok(compare_color(color, expected2[i * 4 + j], 1),
                    "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
        }
    }

    hr = IDirectDrawSurface7_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
    ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);

    hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
    ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
    hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
    ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
    DestroyWindow(window);
    hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
    ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
    hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
    ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
    hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
    ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
    hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
    ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
    hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
    ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
    hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
    ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);

    IDirectDrawSurface7_Release(dst_surface);
    IDirectDrawSurface7_Release(src_surface);
    IDirectDrawClipper_Release(clipper);
    IDirectDraw7_Release(ddraw);
}
Пример #14
0
boolean CreatePrimary( win32_driver_t * win32_driver )
{
	LPDIRECTDRAW			ddobj;
    DDSURFACEDESC2			ddsd;
    HRESULT					result;

	// create direct draw object

	result = DirectDrawCreate( 0, &ddobj, 0 );
	if( result != DD_OK )
	{
		Error( 0, "DirectDrawCreate : error %i", result );
		printf( "vo_out_directx : DirectDrawCreate : error %i\n", result );
		return 0;
	}

	// set cooperative level

    result = IDirectDraw_SetCooperativeLevel( ddobj, win32_driver->win32_visual->WndHnd, DDSCL_NORMAL );
	if( result != DD_OK )
	{
		Error( 0, "SetCooperativeLevel : error %i", result );
		return 0;
	}

	// try to get new interface

	result = IDirectDraw_QueryInterface( ddobj, &IID_IDirectDraw7, (LPVOID *) &win32_driver->ddobj );
	if( result != DD_OK )
	{
		Error( 0, "ddobj->QueryInterface : DirectX 7 or higher required" );
		return 0;
	}

	// release our old interface

	IDirectDraw_Release( ddobj );

    // create primary_surface

    memset( &ddsd, 0, sizeof( ddsd ) );
    ddsd.dwSize         = sizeof( ddsd );
    ddsd.dwFlags        = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

	result = IDirectDraw7_CreateSurface( win32_driver->ddobj, &ddsd, &win32_driver->primary, 0 );
	if( result != DD_OK )
	{
		Error( 0, "CreateSurface ( primary ) : error %i ", result );
		return 0;
	}

    // create our clipper object

	result = IDirectDraw7_CreateClipper( win32_driver->ddobj, 0, &win32_driver->ddclipper, 0 );
	if( result != DD_OK )
	{
		Error( 0, "CreateClipper : error %i", result );
		return 0;
	}

    // associate our clipper with our window

    result = IDirectDrawClipper_SetHWnd( win32_driver->ddclipper, 0, win32_driver->win32_visual->WndHnd );
	if( result != DD_OK )
	{
		Error( 0, "ddclipper->SetHWnd : error %i", result );
		return 0;
	}

    // associate our primary surface with our clipper

    result = IDirectDrawSurface7_SetClipper( win32_driver->primary, win32_driver->ddclipper );
	if( result != DD_OK )
	{
		Error( 0, "ddclipper->SetHWnd : error %i", result );
		return 0;
	}

	// store our objects in our visual struct

	UpdateRect( win32_driver->win32_visual );

    return 1;
}
Пример #15
0
static void test_ddraw_objects(void)
{
    HRESULT hr;
    unsigned long ref;
    IDirectDraw7 *DDraw7;
    IDirectDraw4 *DDraw4;
    IDirectDraw2 *DDraw2;
    IDirectDraw  *DDraw1;
    IDirectDrawPalette *palette;
    IDirectDrawSurface7 *surface;
    IDirectDrawSurface *surface1;
    IDirectDrawSurface4 *surface4;
    PALETTEENTRY Table[256];
    DDSURFACEDESC2 ddsd;

    hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL);
    ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
    if(!DDraw7)
    {
        trace("Couldn't create DDraw interface, skipping tests\n");
        return;
    }

    hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw4, (void **) &DDraw4);
    ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
    hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw2, (void **) &DDraw2);
    ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
    hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw, (void **) &DDraw1);
    ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);

    ref = getRefcount( (IUnknown *) DDraw7);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    /* Fails without a cooplevel */
    hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
    ok(hr == DDERR_NOCOOPERATIVELEVELSET, "CreatePalette returned %08x\n", hr);

    /* This check is before the cooplevel check */
    hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, (void *) 0xdeadbeef);
    ok(hr == CLASS_E_NOAGGREGATION, "CreatePalette returned %08x\n", hr);

    hr = IDirectDraw7_SetCooperativeLevel(DDraw7, 0, DDSCL_NORMAL);
    ok(hr == DD_OK, "SetCooperativeLevel failed with %08x\n", hr);

    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
    ddsd.dwWidth = 64;
    ddsd.dwHeight = 64;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
    U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
    U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
    U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8;

    hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd, &surface, NULL);
    ok(hr == DD_OK, "CreateSurface failed with %08x\n", hr);

    /* DDraw refcount increased by 1 */
    ref = getRefcount( (IUnknown *) DDraw7);
    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);

    /* Surface refcount starts with 1 */
    ref = getRefcount( (IUnknown *) surface);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
    ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);

    /* DDraw refcount increased by 1 */
    ref = getRefcount( (IUnknown *) DDraw7);
    ok(ref == 3, "Got refcount %ld, expected 3\n", ref);

    /* Palette starts with 1 */
    ref = getRefcount( (IUnknown *) palette);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    /* Test attaching a palette to a surface */
    hr = IDirectDrawSurface7_SetPalette(surface, palette);
    ok(hr == DD_OK, "IDirectDrawSurface_SetPalette failed with %08x\n", hr);

    /* Palette refcount increased, surface stays the same */
    ref = getRefcount( (IUnknown *) palette);
    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
    ref = getRefcount( (IUnknown *) surface);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    IDirectDrawSurface7_Release(surface);
    /* Increased before - decrease now */
    ref = getRefcount( (IUnknown *) DDraw7);
    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);

    /* Releasing the surface detaches the palette */
    ref = getRefcount( (IUnknown *) palette);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    IDirectDrawPalette_Release(palette);

    /* Increased before - decrease now */
    ref = getRefcount( (IUnknown *) DDraw7);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);

    /* Not all interfaces are AddRefed when a palette is created */
    hr = IDirectDraw4_CreatePalette(DDraw4, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
    ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw4);
    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
    IDirectDrawPalette_Release(palette);

    /* No addref here */
    hr = IDirectDraw2_CreatePalette(DDraw2, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
    ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw2);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
    IDirectDrawPalette_Release(palette);

    /* No addref here */
    hr = IDirectDraw_CreatePalette(DDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
    ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw1);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
    IDirectDrawPalette_Release(palette);

    /* Similar for surfaces */
    hr = IDirectDraw4_CreateSurface(DDraw4, &ddsd, &surface4, NULL);
    ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw4);
    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
    IDirectDrawSurface4_Release(surface4);

    ddsd.dwSize = sizeof(DDSURFACEDESC);
    hr = IDirectDraw2_CreateSurface(DDraw2, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
    ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw2);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
    IDirectDrawSurface_Release(surface1);

    hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
    ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
    ref = getRefcount( (IUnknown *) DDraw1);
    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
    IDirectDrawSurface_Release(surface1);

    IDirectDraw7_Release(DDraw7);
    IDirectDraw4_Release(DDraw4);
    IDirectDraw2_Release(DDraw2);
    IDirectDraw_Release(DDraw1);
}
Пример #16
0
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
	}
}
Пример #17
0
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 );
}
Пример #18
0
static int
_directdraw_init (HWND                 window,
		  LPDIRECTDRAW        *object,
		  LPDIRECTDRAWSURFACE *surface_primary,
		  LPDIRECTDRAWSURFACE *surface_back,
		  int                 *depth,
		  int width,
		  int height)
{
   DDSURFACEDESC2      surface_desc;
   DDPIXELFORMAT       pixel_format;
   LPDIRECTDRAWCLIPPER clipper;
   LPDIRECTDRAW        o;
   DDSURFACEDESC2     *sd;
   HRESULT             res;

   res = DirectDrawCreateEx (NULL, (void **)&o, &IID_IDirectDraw7, NULL);
   if (FAILED(res))
     return 0;

   res = IDirectDraw7_SetCooperativeLevel (o, window, DDSCL_NORMAL);
   if (FAILED(res))
     {
	IDirectDraw7_Release (o);
	return 0;
     }

   res = IDirectDraw7_CreateClipper (o, 0, &clipper, NULL);
   if (FAILED(res))
     {
	IDirectDraw7_Release (o);
	return 0;
     }

   res = IDirectDrawClipper_SetHWnd (clipper, 0, window);
   if (FAILED(res))
     {
	IDirectDrawClipper_Release (clipper);
	IDirectDraw7_Release (o);
	return 0;
     }

   memset(&surface_desc, 0, sizeof(surface_desc));
   surface_desc.dwSize = sizeof(surface_desc);
   surface_desc.dwFlags = DDSD_CAPS;
   surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

   sd=&surface_desc;
   res = IDirectDraw7_CreateSurface (o, &surface_desc,
				     surface_primary, NULL);
   if (FAILED(res))
     {
	IDirectDrawClipper_Release (clipper);
	IDirectDraw7_Release (o);
	return 0;
     }

   res = IDirectDrawSurface7_SetClipper (*surface_primary, clipper);
   if (FAILED(res))
     {
	IDirectDrawClipper_Release (clipper);
	IDirectDrawSurface7_Release (*surface_primary);
	IDirectDraw7_Release (o);
	return 0;
     }

   memset (&surface_desc, 0, sizeof(surface_desc));
   surface_desc.dwSize = sizeof(surface_desc);
   surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
   surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
   surface_desc.dwWidth = width;
   surface_desc.dwHeight = height;

   sd=&surface_desc;
   res = IDirectDraw7_CreateSurface (o, (DDSURFACEDESC *)sd,
				     surface_back, NULL);
   if (FAILED(res))
     {
	IDirectDrawClipper_Release (clipper);
	IDirectDrawSurface7_Release (*surface_primary);
	IDirectDraw7_Release (o);
	return 0;
     }

   ZeroMemory(&pixel_format, sizeof(pixel_format));
   pixel_format.dwSize = sizeof(pixel_format);
   IDirectDrawSurface7_GetPixelFormat(*surface_primary, &pixel_format);

   *object = o;
   *depth = pixel_format.dwRGBBitCount;

   return 1;
}