2 Copyright © 2009-2019, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
8 #include "util/os_misc.h"
9 #include "pipe/p_defines.h"
10 #include "pipe/p_screen.h"
11 #include "pipe/p_state.h"
13 #include "util/u_inlines.h"
15 #include <gallium/gallium.h>
17 #include <proto/exec.h>
18 #include <proto/gallium.h>
20 #include "mesa3dgl_support.h"
21 #include "mesa3dgl_gallium.h"
23 /*****************************************************************************
27 GLAContext
glACreateContext(
30 struct TagItem
*tagList
)
34 Crates a GL rendering context that can be later used in subsequent
39 tagList - a pointer to tags to be used during creation.
43 GLA_Left - specifies the left rendering offset on the rastport.
44 Typically equals to window->BorderLeft.
46 GLA_Top - specifies the top rendering offset on the rastport.
47 Typically equals to window->BorderTop.
49 GLA_Right - specifies the right rendering offset on the rastport.
50 Typically equals to window->BorderRight.
52 GLA_Bottom - specifies the bottom rendering offset on the rastport.
53 Typically equals to window->BorderBottom.
55 GLA_Width - specifies the width of the rendering area.
56 GLA_Width + GLA_Left + GLA_Right should equal the width of
57 the rastport. The GLA_Width is interchangable at cration
58 time with GLA_Right. Later durring window resizing, width
59 is calculated from scalled left, righ and window width.
61 GLA_Height - specifies the height of the rendering area.
62 GLA_Height + GLA_Top + GLA_Bottom should equal the height
63 of the rastport. The GLA_Height is interchangable at
64 cration time with GLA_Bottom. Later durring window resizing
65 , height is calculated from scalled top, bottom and window
68 GLA_Screen - pointer to Screen onto which scene is to be rendered. When
69 selecting RastPort has lower priority than GLA_Window.
71 GLA_Window - pointer to Window onto which scene is to be rendered. Must
74 GLA_RastPort - ignored. Use GLA_Window.
76 GLA_DoubleBuf - ignored. All rendering is always double buffered.
78 GLA_RGBMode - ignored. All rendering is done in RGB. Indexed modes are
81 GLA_AlphaFlag - ignored. All rendering is done with alpha channel.
83 GLA_NoDepth - disables the depth/Z buffer. Depth buffer is enabled by
84 default and is 16 or 24 bit based on rendering
87 GLA_NoStencil - disables the stencil buffer. Stencil buffer is enabled
90 GLA_NoAccum - disables the accumulation buffer. Accumulation buffer is
95 A valid GL context or NULL of creation was not succesfull.
103 *****************************************************************************/
105 struct mesa3dgl_context
* ctx
= NULL
;
106 struct TagItem pscreen_tags
[] =
108 { CPS_PipeFriendBitMap
, 0 },
109 { CPS_PipeScreenDriver
, 0 },
112 struct pipe_screen
* pscreen
= NULL
;
113 struct st_context_attribs attribs
= {0};
114 enum st_context_error st_error
= 0;
116 D(bug("[MESA3DGL] %s()\n", __func__
));
118 /* Allocate MESA3DGL context */
119 if (!(ctx
= (struct mesa3dgl_context
*)AllocVec(sizeof(struct mesa3dgl_context
), MEMF_PUBLIC
| MEMF_CLEAR
)))
121 bug("%s: ERROR - failed to allocate GLAContext\n", __func__
);
124 pscreen_tags
[1].ti_Data
= (IPTR
)&ctx
->driver
;
126 D(bug("[MESA3DGL] %s: ctx @ 0x%p\n", __func__
, ctx
));
128 MESA3DGLSelectRastPort(ctx
, tagList
);
129 if (!ctx
->visible_rp
)
131 bug("%s: ERROR - failed to select visible rastport\n", __func__
);
135 D(bug("[MESA3DGL] %s: visible_rp @ 0x%p\n", __func__
, ctx
->visible_rp
));
136 pscreen_tags
[0].ti_Data
= (IPTR
)ctx
->visible_rp
->BitMap
;
137 D(bug("[MESA3DGL] %s: _bmap @ 0x%p\n", __func__
, pscreen_tags
[0].ti_Data
));
139 MESA3DGLStandardInit(ctx
, tagList
);
141 if (CreatePipeV(pscreen_tags
))
143 pscreen
= CreatePipeScreen(ctx
->driver
);
146 bug("%s: ERROR - failed to create gallium pipe screen\n", __func__
);
152 bug("%s: ERROR - failed to create gallium pipe\n", __func__
);
156 D(bug("[MESA3DGL] %s: pipe screen @ 0x%p\n", __func__
, pscreen
));
157 D(bug("[MESA3DGL] %s: pipe driver @ 0x%p\n", __func__
, ctx
->driver
));
159 if (!(ctx
->stmanager
= MESA3DGLNewStManager(pscreen
)))
161 bug("%s: ERROR - failed to create ST Manager\n");
162 DestroyPipeScreen(ctx
->driver
, pscreen
);
164 DestroyPipe(ctx
->driver
);
169 D(bug("[MESA3DGL] %s: ST Manager @ 0x%p \n", __func__
, ctx
->stmanager
));
171 if (!MESA3DGLFillVisual(&ctx
->stvis
, ctx
->stmanager
->screen
, ctx
->BitsPerPixel
, tagList
))
173 bug("%s: ERROR - failed to fill ST Visual\n", __func__
);
177 attribs
.profile
= ST_PROFILE_DEFAULT
;
178 attribs
.visual
= ctx
->stvis
;
180 ctx
->st
= glstapi
->create_context(glstapi
, ctx
->stmanager
, &attribs
, &st_error
, NULL
);
183 bug("%s: ERROR - failed to create mesa state tracker context\n", __func__
);
187 ctx
->framebuffer
= MESA3DGLNewFrameBuffer(ctx
, &ctx
->stvis
);
189 if (!ctx
->framebuffer
)
191 bug("%s: ERROR - failed to create frame buffer\n", __func__
);
195 return (GLAContext
)ctx
;
198 if (ctx
->stmanager
) MESA3DGLFreeStManager(ctx
->driver
, ctx
->stmanager
);
199 if (ctx
) MESA3DGLFreeContext(ctx
);
200 return (GLAContext
)NULL
;