2 Copyright 2009-2015, The AROS Development Team. All rights reserved.
6 #include <proto/utility.h>
7 #include <proto/exec.h>
8 #include <proto/gallium.h>
10 #include <gallium/pipe/p_screen.h>
11 #include <gallium/util/u_inlines.h>
13 #include "main/context.h"
16 #include <aros/debug.h>
18 #include "mesa3dgl_support.h"
19 #include "mesa3dgl_gallium.h"
21 static BOOL
MESA3DGLSelectColorFormat(enum pipe_format
* colorFormat
,
22 struct pipe_screen
* screen
, GLint bpp
)
24 *colorFormat
= PIPE_FORMAT_NONE
;
28 /* Try PIPE_FORMAT_B5G6R5_UNORM */
29 if (screen
->is_format_supported(screen
, PIPE_FORMAT_B5G6R5_UNORM
,
30 PIPE_TEXTURE_2D
, 0, PIPE_BIND_RENDER_TARGET
))
32 *colorFormat
= PIPE_FORMAT_B5G6R5_UNORM
;
39 /* Try PIPE_FORMAT_B8G8R8A8_UNORM */
40 if (screen
->is_format_supported(screen
, PIPE_FORMAT_B8G8R8A8_UNORM
,
41 PIPE_TEXTURE_2D
, 0, PIPE_BIND_RENDER_TARGET
))
43 *colorFormat
= PIPE_FORMAT_B8G8R8A8_UNORM
;
51 static BOOL
MESA3DGLSelectDepthStencilFormat(enum pipe_format
* depthStencilFormat
,
52 struct pipe_screen
* screen
, BOOL noDepth
, BOOL noStencil
)
55 *depthStencilFormat
= PIPE_FORMAT_NONE
;
60 /* Try PIPE_FORMAT_S8_USCALED_Z24_UNORM */
61 if(!noStencil
&& (screen
->is_format_supported(screen
, PIPE_FORMAT_S8_USCALED_Z24_UNORM
,
62 PIPE_TEXTURE_2D
, 0, PIPE_BIND_DEPTH_STENCIL
)))
64 *depthStencilFormat
= PIPE_FORMAT_S8_USCALED_Z24_UNORM
;
68 /* Try PIPE_FORMAT_X8Z24_UNORM */
69 if(noStencil
&& (screen
->is_format_supported(screen
, PIPE_FORMAT_X8Z24_UNORM
,
70 PIPE_TEXTURE_2D
, 0, PIPE_BIND_DEPTH_STENCIL
)))
72 *depthStencilFormat
= PIPE_FORMAT_X8Z24_UNORM
;
76 /* Try PIPE_FORMAT_Z24X8_UNORM */
77 if(noStencil
&& (screen
->is_format_supported(screen
, PIPE_FORMAT_Z24X8_UNORM
,
78 PIPE_TEXTURE_2D
, 0, PIPE_BIND_DEPTH_STENCIL
)))
80 *depthStencilFormat
= PIPE_FORMAT_Z24X8_UNORM
;
84 /* Try PIPE_FORMAT_Z16_UNORM */
85 if(screen
->is_format_supported(screen
, PIPE_FORMAT_Z16_UNORM
,
86 PIPE_TEXTURE_2D
, 0, PIPE_BIND_DEPTH_STENCIL
))
88 *depthStencilFormat
= PIPE_FORMAT_Z16_UNORM
;
95 BOOL
MESA3DGLFillVisual(struct st_visual
* stvis
, struct pipe_screen
* screen
, int bpp
, struct TagItem
*tagList
)
97 BOOL noDepth
, noStencil
, noAccum
;
99 D(bug("[MESA3DGL] MESA3DGLFillVisual\n"));
101 noStencil
= GetTagData(GLA_NoStencil
, GL_FALSE
, tagList
);
102 noAccum
= GetTagData(GLA_NoAccum
, GL_FALSE
, tagList
);
103 noDepth
= GetTagData(GLA_NoDepth
, GL_FALSE
, tagList
);
105 stvis
->color_format
= PIPE_FORMAT_NONE
;
106 stvis
->depth_stencil_format
= PIPE_FORMAT_NONE
;
107 stvis
->accum_format
= PIPE_FORMAT_NONE
;
108 stvis
->render_buffer
= ST_ATTACHMENT_INVALID
;
110 stvis
->buffer_mask
= 0;
113 if (!MESA3DGLSelectColorFormat(&stvis
->color_format
, screen
, bpp
))
115 D(bug("[MESA3DGL] MESA3DGLFillVisual - ERROR - No supported color format found\n"));
119 /* Z-buffer / Stencil buffer */
120 if (!MESA3DGLSelectDepthStencilFormat(&stvis
->depth_stencil_format
, screen
, noDepth
, noStencil
))
122 D(bug("[MESA3DGL] MESA3DGLFillVisual - ERROR - No supported depth/stencil format found\n"));
128 stvis
->accum_format
= PIPE_FORMAT_NONE
;
130 stvis
->accum_format
= PIPE_FORMAT_R16G16B16A16_SNORM
;
132 /* Buffers */ /* MESA3DGL uses front buffer as back buffer */
133 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_LEFT_MASK
;
134 if (!noDepth
|| !noStencil
)
135 stvis
->buffer_mask
|= ST_ATTACHMENT_DEPTH_STENCIL_MASK
;
140 static VOID
MESA3DGLFrameBufferCreateResource(struct mesa3dgl_framebuffer
* amfb
,
141 const enum st_attachment_type statt
)
143 struct pipe_resource templ
;
145 memset(&templ
, 0, sizeof(templ
));
147 if(amfb
->screen
->get_param(amfb
->screen
, PIPE_CAP_NPOT_TEXTURES
))
148 templ
.target
= PIPE_TEXTURE_2D
;
150 templ
.target
= PIPE_TEXTURE_RECT
;
151 templ
.width0
= amfb
->width
;
152 templ
.height0
= amfb
->height
;
154 templ
.last_level
= 0;
155 templ
.array_size
= 1;
158 case ST_ATTACHMENT_FRONT_LEFT
:
159 case ST_ATTACHMENT_BACK_LEFT
:
160 case ST_ATTACHMENT_FRONT_RIGHT
:
161 case ST_ATTACHMENT_BACK_RIGHT
:
162 templ
.format
= amfb
->stvis
.color_format
;
163 templ
.bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
165 case ST_ATTACHMENT_DEPTH_STENCIL
:
166 templ
.format
= amfb
->stvis
.depth_stencil_format
;
167 templ
.bind
= PIPE_BIND_DEPTH_STENCIL
;
170 return; /* Failure */
173 /* Create resource */
174 amfb
->textures
[statt
] = amfb
->screen
->resource_create(amfb
->screen
, &templ
);
177 static boolean
MESA3DGLFrameBufferValidate(struct st_framebuffer_iface
*stfbi
,
178 const enum st_attachment_type
*statts
, unsigned count
, struct pipe_resource
**out
)
180 struct mesa3dgl_framebuffer
* amfb
= (struct mesa3dgl_framebuffer
*)stfbi
;
183 /* Check for resize */
186 amfb
->resized
= FALSE
;
187 /* Detach "front surface" */
188 pipe_resource_reference(&amfb
->render_resource
, NULL
);
190 /* Detach all resources */
191 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++)
192 pipe_resource_reference(&amfb
->textures
[i
], NULL
);
195 /* Create new resources */
196 for (i
= 0; i
< count
; i
++)
198 if (amfb
->textures
[statts
[i
]] == NULL
)
200 MESA3DGLFrameBufferCreateResource(amfb
, statts
[i
]);
201 if (statts
[i
] == ST_ATTACHMENT_FRONT_LEFT
)
203 pipe_resource_reference(&amfb
->render_resource
, amfb
->textures
[ST_ATTACHMENT_FRONT_LEFT
]);
211 for (i
= 0; i
< count
; i
++)
214 pipe_resource_reference(&out
[i
], amfb
->textures
[statts
[i
]]);
220 static boolean
MESA3DGLFrameBufferFlushFront(struct st_framebuffer_iface
*stfbi
,
221 enum st_attachment_type statt
)
227 struct mesa3dgl_framebuffer
* MESA3DGLNewFrameBuffer(struct mesa3dgl_context
* ctx
, struct st_visual
* stvis
)
229 struct mesa3dgl_framebuffer
* framebuffer
=
230 AllocVec(sizeof(struct mesa3dgl_framebuffer
), MEMF_PUBLIC
| MEMF_CLEAR
);
235 framebuffer
->stvis
= *stvis
;
236 framebuffer
->base
.visual
= &framebuffer
->stvis
;
237 framebuffer
->base
.flush_front
= MESA3DGLFrameBufferFlushFront
;
238 framebuffer
->base
.validate
= MESA3DGLFrameBufferValidate
;
239 framebuffer
->screen
= ctx
->stmanager
->screen
;
244 VOID
MESA3DGLFreeFrameBuffer(struct mesa3dgl_framebuffer
* framebuffer
)
250 pipe_resource_reference(&framebuffer
->render_resource
, NULL
);
252 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++)
253 pipe_resource_reference(&framebuffer
->textures
[i
], NULL
);
255 FreeVec(framebuffer
);
259 VOID
MESA3DGLCheckAndUpdateBufferSize(struct mesa3dgl_context
* ctx
)
261 MESA3DGLRecalculateBufferWidthHeight(ctx
);
262 if (ctx
->framebuffer
->resized
)
263 ctx
->st
->notify_invalid_framebuffer(ctx
->st
,
264 (struct st_framebuffer_iface
*) ctx
->framebuffer
);
267 static int MESA3DGLStManagerGetParam(struct st_manager
*smapi
,
268 enum st_manager_param param
)
273 struct st_manager
* MESA3DGLNewStManager(struct pipe_screen
* pscreen
)
275 struct st_manager
* stmanager
=
276 (struct st_manager
*)AllocVec(sizeof(struct st_manager
), MEMF_PUBLIC
| MEMF_CLEAR
);
280 stmanager
->screen
= pscreen
;
281 stmanager
->get_param
= MESA3DGLStManagerGetParam
;
287 VOID
MESA3DGLFreeStManager(struct st_manager
* stmanager
)
291 if (stmanager
->screen
)
292 DestroyPipeScreen(stmanager
->screen
);