revert between 56095 -> 55830 in arch
[AROS.git] / rom / graphics / getgbuffers.c
blob06bf1153ef2a4a452514e4fb4db89e93b699da1a
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function GetGBuffers()
6 Lang: english
7 */
8 #include <graphics/gels.h>
9 #include <graphics/rastport.h>
10 #include "graphics_intern.h"
12 /*****************************************************************************
14 NAME */
15 #include <proto/graphics.h>
17 AROS_LH3(BOOL, GetGBuffers,
19 /* SYNOPSIS */
20 AROS_LHA(struct AnimOb *, anOb, A0),
21 AROS_LHA(struct RastPort *, rp, A1),
22 AROS_LHA(BOOL , db, D0),
24 /* LOCATION */
25 struct GfxBase *, GfxBase, 28, Graphics)
27 /* FUNCTION
28 Allocate all buffers for a whole AnimOb. In particular this
29 means getting buffers for
30 - BorderLine
31 - SaveBuffer
32 - CollMask
33 - ImageShadow (points to the same memory as CollMask does)
34 - if db is set to TRUE the user wants double-buffering, so we need
35 - DBufPacket
36 - BufBuffer
38 INPUTS
39 anOb = pointer to AnimOb structure to be added to list of
40 AnimObs
41 rp = pointer to a valid RastPort with initialized GelsInfo
42 structure
43 db = TRUE when double-buffering is wanted
45 RESULT
46 TRUE, if all the memory allocations were successful, otherwise
47 FALSE
49 NOTES
50 If an AnimOb is passed to GetGBuffers twice new buffers will
51 be allocated and therefore old pointers to buffers will be
52 lost in space.
54 EXAMPLE
56 BUGS
58 SEE ALSO
59 FreeGBuffers(), graphics/gels.h
61 INTERNALS
62 Are real VSprites possible as a part of an AnimOb?
63 If yes, then different sizes of memory would have to be
64 allocated for BorderLine and CollMask. Currently the
65 sizes of memory allocated for this are most of the time
66 too large as they are just allocated for a Bob. If this
67 code is changed then the code of FreeGBuffers() will
68 have to be changed, too, and this text can be erased :-))
70 HISTORY
72 *****************************************************************************/
74 AROS_LIBFUNC_INIT
76 struct AnimComp * CurAnimComp = anOb -> HeadComp;
78 /* visit all the components of this AnimOb */
79 while (NULL != CurAnimComp)
81 /* visit all the sequences of a component
82 the sequences are connected like a ring!! */
83 struct AnimComp * CurSeqAnimComp = CurAnimComp;
86 struct Bob * CurBob = CurSeqAnimComp -> AnimBob;
87 struct VSprite * CurVSprite = CurBob -> BobVSprite;
88 long memsize;
90 /* Attention: width of a Bob/VSprite is the number of *words* it
91 uses for it's width */
94 /* allocate height*(width*2) bytes of Chip-Ram for the ImageShadow */
95 memsize = (CurVSprite -> Height) *
96 (CurVSprite -> Width) * 2;
97 if (NULL ==(CurBob -> ImageShadow = AllocMem(memsize, MEMF_CHIP|MEMF_CLEAR)))
98 return FALSE;
100 /* CollMask points to the same memory as ImageShadow */
101 CurVSprite -> CollMask = CurBob -> ImageShadow;
103 /* allocate height*(width*2)*depth bytes of Chip-Ram for
104 the SaveBuffer */
105 memsize *= (CurVSprite -> Depth);
106 if (NULL ==(CurBob -> SaveBuffer = AllocMem(memsize, MEMF_CHIP|MEMF_CLEAR)))
107 return FALSE;
110 /* allocate width*2 bytes = width words for BorderLine
111 * !!! this is more than enough for VSprites as for a real VSprite
112 * its size in pixels is given in CurVSprite->Width
114 if (NULL ==(CurVSprite -> BorderLine = AllocMem(CurVSprite -> Width * 2,
115 MEMF_CHIP|MEMF_CLEAR)))
116 return FALSE;
118 /* are we using double buffering for this AnimOb? */
119 if (db)
121 /* allocate a DBufPacket structure */
122 if (NULL ==(CurBob -> DBuffer = AllocMem(sizeof(struct DBufPacket),
123 MEMF_CLEAR)))
124 return FALSE;
126 /* BufBuffer needs as much memory as SaveBuffer */
127 /* memsize still contains the size of memory required for SaveBuffer */
128 if (NULL ==(CurBob -> DBuffer -> BufBuffer =
129 AllocMem(memsize, MEMF_CHIP|MEMF_CLEAR)))
130 return FALSE;
133 /* go to the next sequence of this component */
134 CurSeqAnimComp = CurSeqAnimComp -> NextSeq;
136 while (CurAnimComp != CurSeqAnimComp);
138 /* go to next component */
139 CurAnimComp = CurAnimComp -> NextComp;
141 /* all allocations went OK */
142 return TRUE;
144 AROS_LIBFUNC_EXIT
145 } /* GetGBuffers */