Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_photon_render.h @ 3485:e77a69aae239
Mason Wheeler to sdl
I updated SDL, and suddenly my SDL frames stopped working. They'd "initialize" full of gibberish, and I couldn't render anything to them. After a bit of digging, I found a problem: the renderer initialization routine in my SDL frame code wasn't getting called anymore.
procedure TSdlFrame.Paint;
begin
if SDL_SelectRenderer(FWindowID) = -1 then
CreateRenderer;
SDL_RenderPresent;
end;
function TSdlFrame.CreateRenderer: boolean;
const
pf: tagPIXELFORMATDESCRIPTOR = (nSize: sizeof(pf); nVersion: 1;
dwFlags: PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
iPixelType: PFD_TYPE_RGBA; cColorBits: 24; cAlphaBits: 8;
iLayerType: PFD_MAIN_PLANE);
RENDERERS: array[TRendererType] of AnsiString = ('software', 'gdi', 'opengl', 'd3d');
var
pFormat: integer;
begin
if (SDL_SelectRenderer(FWindowID) = 0) then
begin
result := true;
Exit;
end;
if FRendererType = rtOpenGL then
begin
pFormat := ChoosePixelFormat(canvas.Handle, @pf);
if not SetPixelFormat(canvas.Handle, pFormat, @pf) then
outputDebugString(PChar(SysErrorMessage(GetLastError)));
if wglCreateContext(canvas.Handle) = 0 then
outputDebugString(PChar(SysErrorMessage(GetLastError)));
end;
if (SDL_CreateRenderer(FWindowID, SDL_RendererIndex(RENDERERS[FRendererType]), [sdlrPresentFlip3, sdlrAccelerated]) = 0) then
begin
SDL_ShowWindow(FWindowID);
assert(SDL_SetRenderDrawColor(0, 0, 0, 255) = 0);
FFlags := SDL_GetWindowFlags(FWindowID);
if assigned(FOnAvailable) then
FOnAvailable(self);
end
else outputDebugString(pChar(format('SDL_CreateRenderer failed: %s', [sdl_GetError])));
result := SDL_SelectRenderer(FWindowID) = 0;
end;
This is a critical issue. The Paint method gets called when the control receives a WM_PAINT message from Windows. I can't create the renderer before then, or it will fail and cause trouble. And when I do create it, it needs to be created with certain parameters. So imagine my surprise when I started debugging into the DLL and found that SDL_SelectRenderer was trying to be "helpful" by creating the renderer for me if it didn't already exist! Now not only does my initialization code not get called, I end up with the wrong renderer and so things don't render as expected when I try to use the window.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 24 Nov 2009 04:48:12 +0000 |
parents | d6b79fc83362 |
children | f7b03b6838cb |
rev | line source |
---|---|
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2009 Sam Lantinga |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 QNX Photon GUI SDL driver |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 Copyright (C) 2009 Mike Gorchak |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 (mike@malva.ua, lestat@i.com.ua) |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 */ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 #ifndef __SDL_PHOTON_RENDER_H__ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 #define __SDL_PHOTON_RENDER_H__ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #include "../SDL_sysvideo.h" |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 #include <Ph.h> |
3375
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
33 #include <photon/PhRender.h> |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 #define SDL_PHOTON_MAX_SURFACES 3 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
3375
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
37 #define SDL_PHOTON_SURFTYPE_UNKNOWN 0x00000000 |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
38 #define SDL_PHOTON_SURFTYPE_OFFSCREEN 0x00000001 |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
39 #define SDL_PHOTON_SURFTYPE_PHIMAGE 0x00000002 |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
40 |
3396
d6b79fc83362
All 2D operations in Photon driver have been finished. The driver is ready to use. There fullscreen modes and YUV textures are rest only.
Mike Gorchak <lestat@i.com.ua>
parents:
3387
diff
changeset
|
41 #define SDL_PHOTON_UNKNOWN_BLEND 0x00000000 |
d6b79fc83362
All 2D operations in Photon driver have been finished. The driver is ready to use. There fullscreen modes and YUV textures are rest only.
Mike Gorchak <lestat@i.com.ua>
parents:
3387
diff
changeset
|
42 #define SDL_PHOTON_DRAW_BLEND 0x00000001 |
d6b79fc83362
All 2D operations in Photon driver have been finished. The driver is ready to use. There fullscreen modes and YUV textures are rest only.
Mike Gorchak <lestat@i.com.ua>
parents:
3387
diff
changeset
|
43 #define SDL_PHOTON_TEXTURE_BLEND 0x00000002 |
d6b79fc83362
All 2D operations in Photon driver have been finished. The driver is ready to use. There fullscreen modes and YUV textures are rest only.
Mike Gorchak <lestat@i.com.ua>
parents:
3387
diff
changeset
|
44 |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 typedef struct SDL_RenderData |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 { |
3375
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
47 SDL_bool enable_vsync; /* VSYNC flip synchronization enable */ |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
48 uint32_t surface_visible_idx; /* Index of visible surface */ |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
49 uint32_t surface_render_idx; /* Index of render surface */ |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
50 uint32_t surfaces_count; /* Amount of allocated surfaces */ |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
51 uint32_t surfaces_type; /* Type of allocated surfaces */ |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
52 uint32_t window_width; /* Last active window width */ |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
53 uint32_t window_height; /* Last active window height */ |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
54 PhGC_t* gc; /* Graphics context */ |
3387
05499ec8c022
Initial support for fullscreen application modes.
Mike Gorchak <lestat@i.com.ua>
parents:
3383
diff
changeset
|
55 SDL_bool direct_mode; /* Direct Mode state */ |
3375
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
56 PdOffscreenContext_t* osurfaces[SDL_PHOTON_MAX_SURFACES]; |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
57 PhImage_t* psurfaces[SDL_PHOTON_MAX_SURFACES]; |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
58 PmMemoryContext_t* pcontexts[SDL_PHOTON_MAX_SURFACES]; |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 } SDL_RenderData; |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 typedef struct SDL_TextureData |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 { |
3383
90935231e9b6
Continue working on 2D support in Photon
Mike Gorchak <lestat@i.com.ua>
parents:
3375
diff
changeset
|
63 uint32_t surface_type; |
90935231e9b6
Continue working on 2D support in Photon
Mike Gorchak <lestat@i.com.ua>
parents:
3375
diff
changeset
|
64 PdOffscreenContext_t* osurface; |
90935231e9b6
Continue working on 2D support in Photon
Mike Gorchak <lestat@i.com.ua>
parents:
3375
diff
changeset
|
65 PhImage_t* psurface; |
90935231e9b6
Continue working on 2D support in Photon
Mike Gorchak <lestat@i.com.ua>
parents:
3375
diff
changeset
|
66 PmMemoryContext_t* pcontext; |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 } SDL_TextureData; |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 extern void photon_addrenderdriver(_THIS); |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
3375
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
71 /* Helper function, which redraws the backbuffer */ |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
72 int _photon_update_rectangles(SDL_Renderer* renderer, PhRect_t* rect); |
dd105b317335
Continue working on 2D support for Photon/QNX.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
73 |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 #endif /* __SDL_PHOTON_RENDER_H__ */ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 /* vi: set ts=4 sw=4 expandtab: */ |