Windows: Why is SDL not using hardware for surfaces in window mode?

Hi there,

This might be related to the messages with the subject ‘problems with
fullscreen mode in windows’.

I have started on a small game using SDL and there the window version is
running around 70+ fps and the fullscreen ONLY 52. This might be because of
locking and unlocking… (I tried to place a locking before the rendering and
then unlocking after, resulted in lots of flashes).

Anyway, I assumed that SDL would allow me to use DirectX when using window
mode ! As far as I can see it is not possible !

The below test should result in the same FPS in window and fullscreen mode
to my knowledge. But since it does not allow surfaces to be placed in video
memory it is slower in windows mode.
So no support for accelerated hardware blits or filling.

I tried to disable ALL DirectX in SDL, and the DIB version runs same speed
(give or take) as the windowed version of DirectX !!!

The test code used is pasted at the end of this email. Code was 100%
compiled using release build (including SDL and SGE). The code is running on
Windows 2000 on a AMD 1.4 MHZ with a Radeon 8500, and to be honest, I
expected much higher frame rates.

and oh yeah, fullscreen version runs same speed in debug and release mode…
Makes sense as the hardware does all the work…

The fullscreen might lock itself to 76 frames pr second because it waits for
vertical retrace (anyone got any idea how to avoid this…)

Anyone have any comments to this, and why the frame rate is so slow ? and if
I’m far out, then let me know… and if more info is needed then also let me
know.

Best,

Sam

DirectX window fps: 52
DirectX fullscreen fps: 76
Windib window fps: 55
Windib fullscreen fps: 55

Fullscreen Direct X:
Driver : directx
Screen flags : c0000001
Format:
BitsPerPixel 32
BytesPerPixel 4
Shifts 16, 8, 0, 0
Mask 00ff0000,0000ff00,000000ff,00000000
Offscreen flags: 00000101
Format:
BitsPerPixel 32
BytesPerPixel 4
Shifts 16, 8, 0, 0
Mask 00ff0000,0000ff00,000000ff,00000000
Current mode information
hw_available 1 wm_available 1 blit_hw 1 blit_hw_CC 1 blit_hw_A 0
blit_sw 1 blit_sw_CC 1 blit_sw_A 0 blit_fill 1 videm_mem
64144 KBytes
Format:
BitsPerPixel 32
BytesPerPixel 4
Shifts 16, 8, 0, 0
Mask 00ff0000,0000ff00,000000ff,00000000

Window DirectX:
Driver : directx
Screen flags : 00000000
Format:
BitsPerPixel 32
BytesPerPixel 4
Shifts 16, 8, 0, 0
Mask 00ff0000,0000ff00,000000ff,00000000
Offscreen flags: 00000000
Format:
BitsPerPixel 32
BytesPerPixel 4
Shifts 16, 8, 0, 0
Mask 00ff0000,0000ff00,000000ff,00000000
Current mode information
hw_available 1 wm_available 1 blit_hw 1 blit_hw_CC 1 blit_hw_A 0
blit_sw 1 blit_sw_CC 1 blit_sw_A 0 blit_fill 1 videm_mem
62272 KBytes Format:
BitsPerPixel 32
BytesPerPixel 4
Shifts 16, 8, 0, 0
Mask 00ff0000,0000ff00,000000ff,00000000

Fullscreen windib:
Driver : windib
Screen flags : 80000000
Format:
BitsPerPixel 32
BytesPerPixel 4
Shifts 16, 8, 0, 0
Mask 00ff0000,0000ff00,000000ff,00000000
Offscreen flags: 00000000
Format:
BitsPerPixel 32
BytesPerPixel 4
Shifts 16, 8, 0, 0
Mask 00ff0000,0000ff00,000000ff,00000000
Current mode information
hw_available 0 wm_available 1 blit_hw 0 blit_hw_CC 0 blit_hw_A 0
blit_sw 0 blit_sw_CC 0 blit_sw_A 0 blit_fill 0 videm_mem 0
KBytes
Format:
BitsPerPixel 32
BytesPerPixel 4
Shifts 16, 8, 0, 0
Mask 00ff0000,0000ff00,000000ff,00000000

Window windib:
Same as fullscreen except the flags was 00000000 (No surprise)

// Test code

#include “stdafx.h”
#include <stdlib.h>
#include “sdl.h”
#include “sge.h”

sge_bmpFont *font;
SDL_VideoInfo info;

void DumpFormat(SDL_PixelFormat *format)
{
printf("\tFormat:\n");
printf("\t\tBitsPerPixel %d\n", format->BitsPerPixel);
printf("\t\tBytesPerPixel %d\n", format->BytesPerPixel);
printf("\t\tShifts %2d,%2d,%2d,%2d\n", format->Rshift,
format->Gshift, format->Bshift, format->Ashift);
printf("\t\tMask %08x,%08x,%08x,%08x\n", format->Rmask, format->Gmask,
format->Bmask, format->Amask);
}

int main( int argc, char* argv[] )
{
if((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER )==-1)) {
char str[256];

	sprintf(str, "Could not initialize SDL: %s", SDL_GetError());
	MessageBox(NULL, str, "Error", MB_OK | MB_ICONINFORMATION);

    exit(-1);
}

// Clean up on exit
atexit(SDL_Quit);

// Initialize the display
SDL_Surface *screen, *offScreen;

//screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_FULLSCREEN |

SDL_DOUBLEBUF);

offScreen = SDL_CreateRGBSurface(SDL_HWSURFACE, screen->w, screen->h,
		screen->format->BitsPerPixel,
		screen->format->Rmask,
		screen->format->Gmask,
		screen->format->Bmask,
		screen->format->Amask);

sge_ClearSurface(offScreen, 0xf7f007f);

font=sge_BF_OpenFont("14P_Arial_Puffy_Red.png",SGE_BFSFONT);
if(font==NULL)
{
	char str[256];
	sprintf(str, "%s", SDL_GetError());
	MessageBox(NULL, str, "Error", MB_OK | MB_ICONINFORMATION);
	exit(1);
}

SDL_Event event;

// Main loop
int oldTime = SDL_GetTicks();
int f = 0;
do
{
	sge_Update_OFF();

	sge_ClearSurface(screen, 0);

	SDL_BlitSurface(offScreen, NULL,screen, NULL);

	int time = SDL_GetTicks();
	int fps = (time - oldTime) ;
	oldTime = time;
	sge_BF_textoutf(screen, font, 500, 10, "FPS: %d", 1000 / fps);

	f++;

	SDL_Flip(screen);

	/* Check events */
	if(SDL_PollEvent(&event)==1){
		// Handle key DOWN
		if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_ESCAPE)
			break;
		if(event.type==SDL_QUIT)
			break;
	}
}while(true);

const SDL_VideoInfo *info = SDL_GetVideoInfo();
char driver[256];
SDL_VideoDriverName(driver, 255);

printf("Driver : %s\n", driver);
printf("Screen flags : %08x\n", screen->flags);
DumpFormat(screen->format);

printf("Offscreen flags: %08x\n", offScreen->flags);
DumpFormat(offScreen->format);

printf("Current mode information\n");
printf("\thw_available %d\n",  info->hw_available );
printf("\twm_available %d\n",  info->wm_available );
printf("\tblit_hw      %d\n",  info->blit_hw);
printf("\tblit_hw_CC   %d\n",  info->blit_hw_CC);
printf("\tblit_hw_A    %d\n",  info->blit_hw_A);
printf("\tblit_sw      %d\n",  info->blit_sw);
printf("\tblit_sw_CC   %d\n",  info->blit_sw_CC);
printf("\tblit_sw_A    %d\n",  info->blit_sw_A);
printf("\tblit_fill    %d\n",  info->blit_fill);
printf("\tvidem_mem    %d KBytes\n",  info->video_mem);
DumpFormat(info->vfmt);
SDL_Quit();

return 0;

}