This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Which method of drawing is faster....


Re: Which method of drawing is faster....

Postby MirekCz » Dec 20, 2001 @ 7:44pm

well, it's still a great loss to give away 25% of PPC power to make a backbuffer->frontbuffer copy. And more advance games will gladly accept some additional cpu time. Blitting something to backbuffer is used only in the simplest games. Once a lot of sprites appears and you use effects like alpha-blending or even more complicated it all starts to work slow and every ms is precious
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Re: Which method of drawing is faster....

Postby voided » Dec 22, 2001 @ 1:04pm

Hi guys! I have juz finished the code but there is something very strange. My GAPI is very slow. I can only hit a framerate of 49FPS even when I only do a memcopy of a blank screen. I hope that someone out there can alighten me. If u want to see my code, I will be more that happy to send. Thanks alot.
voided
pm Member
 
Posts: 3
Joined: Dec 16, 2001 @ 11:40pm


Re: Which method of drawing is faster....

Postby Dan East » Dec 22, 2001 @ 6:33pm

What are you doing in your main loop? Are you Sleeping at all? Are you building a debug or release build?<br><br>Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Re: Which method of drawing is faster....

Postby voided » Dec 22, 2001 @ 9:53pm

Well I used peekmessage(). I'm currently using a Debug build but I have also tried the Release Build. The following is the code of my main file.<br><br>#include "stdafx.h"<br>#include <commctrl.h><br>#include <aygshell.h><br>#include "XSprite.h"<br>#include "XConsole.h"<br><br>//Menu Bar Height<br>#define MENU_HEIGHT 26<br>#define MAX_LOADSTRING 100<br>#define APP_TITLE TEXT("XConsole")<br>#define WINDOW_CLASS TEXT("MainWindow")<br><br>// Global Variables:<br>HINSTANCE                  hInst;                  // The current instance<br>HWND                        hwndCB;                  // The command bar handle<br><br>// Foward declarations of functions included in this code module:<br>ATOM                        MyRegisterClass      (HINSTANCE hInstance, LPTSTR szWindowClass);<br>BOOL                        InitInstance      (HINSTANCE, int);<br>LRESULT CALLBACK      WndProc                  (HWND, UINT, WPARAM, LPARAM);<br><br><br>  //Global variables for XConsoles <br>DWORD presentTickValue, startTickValue, nextSecondTickValue;<br>int fps = 0, frameCounter = 0;<br>HWND XConsolehWnd;<br><br>HDC XConsoleBackBufferHDC;<br>HBITMAP XConsoleBackBufferHANDLER;<br>BITMAP XConsoleBackBufferBITMAP;<br>void* pXConsoleOffScreen;<br>int sizeofBackBuffer;<br><br>GXDisplayProperties g_gxdp;<br>void* pFrameBuffer;<br><br><br>XSprite *testSprite = new XSprite(TEXT("..\\Test.bmp"));<br><br><br><br>int WINAPI WinMain(      HINSTANCE hInstance,<br>                   HINSTANCE hPrevInstance,<br>                   LPTSTR    lpCmdLine,<br>                   int       nCmdShow)<br>{<br>  MSG msg;<br>  <br>  // Look for running instance of application<br>  if (FindWindow(WINDOW_CLASS, APP_TITLE)){<br>    SetForegroundWindow(FindWindow(WINDOW_CLASS, APP_TITLE));<br>    return FALSE;<br>  }<br>  // Perform application initialization:<br>  if (!InitInstance (hInstance, nCmdShow)) <br>  {<br>    return FALSE;<br>  }<br>    <br>  // Main message loop:<br>  BOOL endLoop = FALSE;<br>  while (!endLoop) <br>  {<br>    if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))<br>    {<br>      if(msg.message == WM_QUIT)<br>       endLoop = TRUE;<br>        // Dispatch the message<br>      TranslateMessage(&msg);<br>      DispatchMessage(&msg);<br>    }<br>    else<br>    {<br>      presentTickValue = GetTickCount();<br>      if(nextSecondTickValue < presentTickValue)<br>      {<br>        fps = frameCounter;<br>        frameCounter = 0;<br>        nextSecondTickValue = presentTickValue + 1000;<br>      }<br>      else<br>        frameCounter++;<br>      <br>      testSprite->draw(0, 0);<br>      updateConsole();<br>    }<br>  }<br><br>  return msg.wParam;<br>}<br><br>//<br>//  FUNCTION: MyRegisterClass()<br>//<br>//  PURPOSE: Registers the window class.<br>//<br>//  COMMENTS:<br>//<br>//    This function and its usage is only necessary if you want this code<br>//    to be compatible with Win32 systems prior to the 'RegisterClassEx'<br>//    function that was added to Windows 95. It is important to call this function<br>//    so that the application will get 'well formed' small icons associated<br>//    with it.<br>//<br>ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)<br>{<br>  WNDCLASS      wc;<br>  <br>  wc.style                  = CS_HREDRAW | CS_VREDRAW;<br>  wc.lpfnWndProc            = (WNDPROC) WndProc;<br>  wc.cbClsExtra            = 0;<br>  wc.cbWndExtra            = 0;<br>  wc.hInstance            = hInstance;<br>  wc.hIcon                  = LoadIcon(hInstance, MAKEINTRESOURCE(WINDOW_CLASS));<br>  wc.hCursor                  = 0;<br>  wc.hbrBackground      = (HBRUSH) GetStockObject(WHITE_BRUSH);<br>  wc.lpszMenuName            = 0;<br>  wc.lpszClassName      = szWindowClass;<br>  <br>  return RegisterClass(&wc);<br>}<br><br>//<br>//  FUNCTION: InitInstance(HANDLE, int)<br>//<br>//  PURPOSE: Saves instance handle and creates main window<br>//<br>//  COMMENTS:<br>//<br>//    In this function, we save the instance handle in a global variable and<br>//    create and display the main program window.<br>//<br>BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)<br>{<br>  HWND      hWnd;<br>  <br>  hInst = hInstance;            // Store instance handle in our global variable<br>  // Initialize global strings<br>  MyRegisterClass(hInstance, WINDOW_CLASS);<br>  <br>  XConsolehWnd = hWnd = CreateWindow(WINDOW_CLASS, APP_TITLE, WS_VISIBLE,<br>    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);<br>  <br>  if (!hWnd)<br>  {      <br>      SetForegroundWindow ((HWND)(((DWORD)hWnd) | 0x01));    <br>      return FALSE;<br>  }<br>  //When the main window is created using CW_USEDEFAULT the height of the menubar (if one<br>  // is created is not taken into account). So we resize the window after creating it<br>  // if a menubar is present<br>  {<br>    <br>      RECT      rect;<br>      GetClientRect(hWnd, &rect);        <br>      <br>      RECT rc;<br>    GetWindowRect(hWnd, &rc);<br>    rc.bottom -= MENU_HEIGHT;<br>    if (hwndCB)<br>      MoveWindow(hWnd, rc.left, rc.top, rc.right, rc.bottom, FALSE);<br>  }<br>  <br>  <br>  ShowWindow(hWnd, nCmdShow);<br>  UpdateWindow(hWnd);<br><br>  return TRUE;<br>}<br><br>//<br>//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)<br>//<br>//  PURPOSE:  Processes messages for the main window.<br>//<br>//  WM_COMMAND      - process the application menu<br>//  WM_PAINT      - Paint the main window<br>//  WM_DESTROY      - post a quit message and return<br>//<br>//<br>LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)<br>{<br><br>      PAINTSTRUCT ps;<br><br>  switch (message) <br>  {<br>        case WM_COMMAND:<br>      break;<br><br>    case WM_CREATE:<br>              SHFullScreen(hWnd, SHFS_HIDETASKBAR);<br>              HDC winDC;<br>              winDC = GetDC(hWnd);<br>              RECT rcMain;<br>              rcMain.left            = 0; <br>              rcMain.top            = 0;<br>              rcMain.right      = GetDeviceCaps(winDC, HORZRES);<br>              rcMain.bottom = GetDeviceCaps(winDC, VERTRES);<br>              MoveWindow(hWnd, rcMain.left, rcMain.top, rcMain.right, rcMain.bottom, TRUE); <br>              ShowWindow(hWnd, SW_SHOW);<br>              ReleaseDC(hWnd, winDC);        <br>        // Setting up the XConsole<br>      intializeXConsole();<br>      break;<br>  <br>        case WM_LBUTTONDOWN:<br>              SendMessage(hWnd,WM_CLOSE,0,0);<br>              break;<br><br>    case WM_PAINT:<br>                  BeginPaint(hWnd, &ps);<br>                  EndPaint(hWnd, &ps);<br>    <br>                  break; <br>      case WM_HIBERNATE:<br>        //Release any large memory resources here<br>       break;<br><br>    case WM_ACTIVATE:<br>      break;<br><br>    case WM_DESTROY:<br>        // Freeing up all the resources used by XConsole<br>      destroyXConsole();<br>      DestroyWindow(hwndCB);<br>      PostQuitMessage(0);<br><br>      break;<br><br>    default:<br>      return DefWindowProc(hWnd, message, wParam, lParam);<br><br>  }<br>  return 0;<br>}<br><br>void intializeXConsole(void)<br>{<br><br>    // Initial the GAPI and get the framebuffer<br>  GXOpenDisplay(XConsolehWnd, GX_FULLSCREEN);<br>  g_gxdp = GXGetDisplayProperties();<br><br>    // Creates the off screen buffer<br>  HDC hScreenDC;<br>  hScreenDC = GetDC(0);<br>  XConsoleBackBufferHDC = CreateCompatibleDC(hScreenDC);<br><br>    //Initialize the DIB header for the backbuffer<br>  BYTE buffer[sizeof(BITMAPINFOHEADER) + 3 * sizeof(RGBQUAD)];<br><br>    // Handy pointers<br>  BITMAPINFO*       pBMI    = (BITMAPINFO*) buffer;<br>  BITMAPINFOHEADER* pHeader = &pBMI->bmiHeader;<br>  DWORD*            pColors = (DWORD*)&pBMI->bmiColors;   <br><br>    // DIB Header<br>  pHeader->biSize            = sizeof(BITMAPINFOHEADER);<br>  pHeader->biWidth           = g_gxdp.cxWidth;<br>  pHeader->biHeight          = -(long)g_gxdp.cyHeight;<br>  pHeader->biPlanes          = 1;<br>  pHeader->biBitCount        = (WORD)g_gxdp.cBPP;<br>  pHeader->biCompression     = BI_BITFIELDS;<br>  pHeader->biSizeImage       = sizeofBackBuffer <br>                             = (g_gxdp.cxWidth * g_gxdp.cyHeight * g_gxdp.cBPP) / 8;<br>  pHeader->biXPelsPerMeter   = 0;<br>  pHeader->biYPelsPerMeter   = 0;<br>  pHeader->biClrUsed         = 0;<br>  pHeader->biClrImportant    = 0;<br><br>    // Color masks<br>  if (g_gxdp.ffFormat & kfDirect555)<br>  {<br>    pColors[0] = 0x1F << 10;<br>    pColors[1] = 0x1F << 5;<br>    pColors[2] = 0x1F;<br>  }<br>  else if (g_gxdp.ffFormat & kfDirect565)<br>  {<br>    pColors[0] = 0x1F << 11;<br>    pColors[1] = 0x3F << 5;<br>    pColors[2] = 0x1F;<br>  }<br>  else if (g_gxdp.ffFormat & kfDirect888)<br>  {<br>    pColors[0] = 0x00FF0000;<br>    pColors[1] = 0x0000FF00;<br>    pColors[2] = 0x000000FF;<br>  }<br>  else if (g_gxdp.ffFormat & kfDirect444)<br>  {<br>    pColors[0] = 0x0F00;<br>    pColors[1] = 0x00F0;<br>    pColors[2] = 0x000F;<br>  }<br>  <br>  XConsoleBackBufferHANDLER = CreateDIBSection( hScreenDC, pBMI, DIB_RGB_COLORS, &pXConsoleOffScreen,<br>                                                  0, 0 );<br>  GetObject(XConsoleBackBufferHANDLER, sizeof(BITMAP), &XConsoleBackBufferBITMAP);<br><br>  SelectObject(XConsoleBackBufferHDC, XConsoleBackBufferHANDLER);<br>    // Initialize the ticker<br>  nextSecondTickValue = GetTickCount() + 1000;<br><br>  ReleaseDC(0,hScreenDC);<br>  pFrameBuffer = GXBeginDraw();<br>}<br><br><br><br>void destroyXConsole(void)<br>{<br>  DeleteDC(XConsoleBackBufferHDC);<br>  DeleteObject(XConsoleBackBufferHDC);<br>  GXEndDraw();<br>  GXCloseDisplay();<br>}<br><br><br><br>void updateConsole(void)<br>{<br>  RECT rt;<br>  GetClientRect(XConsolehWnd, &rt);<br>  unsigned short strBuffer[10];<br><br>  swprintf(strBuffer,L"FPS: %ld", fps);<br>                    // Draws to the back buffer<br>  DrawText(XConsoleBackBufferHDC, strBuffer, _tcslen(strBuffer), &rt,<br>      DT_SINGLELINE);<br><br>  <br><br>  memcpy(pFrameBuffer, pXConsoleOffScreen, sizeofBackBuffer);<br><br>}
voided
pm Member
 
Posts: 3
Joined: Dec 16, 2001 @ 11:40pm


Re: Which method of drawing is faster....

Postby Dan East » Dec 22, 2001 @ 10:58pm

You're calling printf and using the Windows API to render a true-type font every frame. Those are two very expensive functions (relatively). If you take those calls out things should speed up significantly (for example, at least only call those routines once every second, use itoa instead of printf, and I would also recommend using a custom bitmap font you draw manually, like Jacco does in EasyCE). Also, there is a large difference in speed between debug and release builds. Release builds usually run at least twice as fast for me, be it a game, DEXplor ,etc. Also make sure you have the optimizations for the release build set for Maximize Speed.<br><br>Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Previous

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron