r4493@vps: verhaegs | 2007-04-19 14:44:00 -0400
[AROS.git] / rom / graphics / getgbuffers.c
blob0131cb374649449b4e592d01f70e79c96f685ba6
1 /*
2 Copyright © 1995-2001, 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
75 AROS_LIBBASE_EXT_DECL(struct GfxBase *,GfxBase)
77 struct AnimComp * CurAnimComp = anOb -> HeadComp;
79 /* visit all the components of this AnimOb */
80 while (NULL != CurAnimComp)
82 /* visit all the sequences of a component
83 the sequences are connected like a ring!! */
84 struct AnimComp * CurSeqAnimComp = CurAnimComp;
87 struct Bob * CurBob = CurSeqAnimComp -> AnimBob;
88 struct VSprite * CurVSprite = CurBob -> BobVSprite;
89 long memsize;
91 /* Attention: width of a Bob/VSprite is the number of *words* it
92 uses for it's width */
95 /* allocate height*(width*2) bytes of Chip-Ram for the ImageShadow */
96 memsize = (CurVSprite -> Height) *
97 (CurVSprite -> Width) * 2;
98 if (NULL ==(CurBob -> ImageShadow = AllocMem(memsize, MEMF_CHIP|MEMF_CLEAR)))
99 return FALSE;
101 /* CollMask points to the same memory as ImageShadow */
102 CurVSprite -> CollMask = CurBob -> ImageShadow;
104 /* allocate height*(width*2)*depth bytes of Chip-Ram for
105 the SaveBuffer */
106 memsize *= (CurVSprite -> Depth);
107 if (NULL ==(CurBob -> SaveBuffer = AllocMem(memsize, MEMF_CHIP|MEMF_CLEAR)))
108 return FALSE;
111 /* allocate width*2 bytes = width words for BorderLine
112 * !!! this is more than enough for VSprites as for a real VSprite
113 * its size in pixels is given in CurVSprite->Width
115 if (NULL ==(CurVSprite -> BorderLine = AllocMem(CurVSprite -> Width * 2,
116 MEMF_CHIP|MEMF_CLEAR)))
117 return FALSE;
119 /* are we using double buffering for this AnimOb? */
120 if (TRUE == db)
122 /* allocate a DBufPacket structure */
123 if (NULL ==(CurBob -> DBuffer = AllocMem(sizeof(struct DBufPacket),
124 MEMF_CLEAR)))
125 return FALSE;
127 /* BufBuffer needs as much memory as SaveBuffer */
128 /* memsize still contains the size of memory required for SaveBuffer */
129 if (NULL ==(CurBob -> DBuffer -> BufBuffer =
130 AllocMem(memsize, MEMF_CHIP|MEMF_CLEAR)))
131 return FALSE;
134 /* go to the next sequence of this component */
135 CurSeqAnimComp = CurSeqAnimComp -> NextSeq;
137 while (CurAnimComp != CurSeqAnimComp);
139 /* go to next component */
140 CurAnimComp = CurAnimComp -> NextComp;
142 /* all allocations went OK */
143 return TRUE;
145 AROS_LIBFUNC_EXIT
146 } /* GetGBuffers */