96
97
return strb->data != NULL;
99
struct pipe_texture template;
100
unsigned surface_usage;
100
struct pipe_resource template;
102
102
/* Free the old surface and texture
104
104
pipe_surface_reference( &strb->surface, NULL );
105
pipe_texture_reference( &strb->texture, NULL );
105
pipe_resource_reference( &strb->texture, NULL );
106
pipe_sampler_view_reference(&strb->sampler_view, NULL);
107
108
/* Setup new texture template.
109
110
memset(&template, 0, sizeof(template));
110
template.target = PIPE_TEXTURE_2D;
111
template.target = st->internal_target;
111
112
template.format = format;
112
113
template.width0 = width;
113
114
template.height0 = height;
115
116
template.last_level = 0;
116
117
template.nr_samples = rb->NumSamples;
117
118
if (util_format_is_depth_or_stencil(format)) {
118
template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
119
template.bind = PIPE_BIND_DEPTH_STENCIL;
121
template.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
122
PIPE_TEXTURE_USAGE_RENDER_TARGET);
122
template.bind = (PIPE_BIND_DISPLAY_TARGET |
123
PIPE_BIND_RENDER_TARGET);
125
/* Probably need dedicated flags for surface usage too:
127
surface_usage = (PIPE_BUFFER_USAGE_GPU_READ |
128
PIPE_BUFFER_USAGE_GPU_WRITE);
130
PIPE_BUFFER_USAGE_CPU_READ |
131
PIPE_BUFFER_USAGE_CPU_WRITE);
134
strb->texture = screen->texture_create(screen, &template);
126
strb->texture = screen->resource_create(screen, &template);
136
128
if (!strb->texture)
318
313
struct gl_framebuffer *fb,
319
314
struct gl_renderbuffer_attachment *att)
321
struct pipe_screen *screen = ctx->st->pipe->screen;
316
struct st_context *st = st_context(ctx);
317
struct pipe_context *pipe = st->pipe;
318
struct pipe_screen *screen = pipe->screen;
322
319
struct st_renderbuffer *strb;
323
320
struct gl_renderbuffer *rb;
324
struct pipe_texture *pt = st_get_texobj_texture(att->Texture);
321
struct pipe_resource *pt = st_get_texobj_resource(att->Texture);
325
322
struct st_texture_object *stObj;
326
323
const struct gl_texture_image *texImage;
329
325
/* When would this fail? Perhaps assert? */
333
/* The first gallium texture level = Mesa BaseLevel */
334
pt_level = MAX2(0, (GLint) att->TextureLevel - att->Texture->BaseLevel);
335
texImage = att->Texture->Image[att->CubeMapFace][pt_level];
329
/* get pointer to texture image we're rendeing to */
330
texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
337
332
/* create new renderbuffer which wraps the texture image */
338
333
rb = st_new_renderbuffer(ctx, 0);
425
* Validate a renderbuffer attachment for a particular usage.
425
* Validate a renderbuffer attachment for a particular set of bindings.
429
428
st_validate_attachment(struct pipe_screen *screen,
430
429
const struct gl_renderbuffer_attachment *att,
433
const struct st_texture_object *stObj =
434
st_texture_object(att->Texture);
432
const struct st_texture_object *stObj = st_texture_object(att->Texture);
437
* Only validate texture attachments for now, since
434
/* Only validate texture attachments for now, since
438
435
* st_renderbuffer_alloc_storage makes sure that
439
436
* the format is supported.
442
438
if (att->Type != GL_TEXTURE)
448
444
return screen->is_format_supported(screen, stObj->pt->format,
446
stObj->pt->nr_samples, bindings, 0);
451
* Check if two renderbuffer attachments name a combined depth/stencil
455
st_is_depth_stencil_combined(const struct gl_renderbuffer_attachment *depth,
456
const struct gl_renderbuffer_attachment *stencil)
458
assert(depth && stencil);
460
if (depth->Type == stencil->Type) {
461
if (depth->Type == GL_RENDERBUFFER_EXT &&
462
depth->Renderbuffer == stencil->Renderbuffer)
465
if (depth->Type == GL_TEXTURE &&
466
depth->Texture == stencil->Texture)
454
475
* Check that the framebuffer configuration is valid in terms of what
460
481
st_validate_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb)
462
struct pipe_screen *screen = ctx->st->pipe->screen;
463
const struct gl_renderbuffer *depthRb =
464
fb->Attachment[BUFFER_DEPTH].Renderbuffer;
465
const struct gl_renderbuffer *stencilRb =
466
fb->Attachment[BUFFER_STENCIL].Renderbuffer;
483
struct st_context *st = st_context(ctx);
484
struct pipe_screen *screen = st->pipe->screen;
485
const struct gl_renderbuffer_attachment *depth =
486
&fb->Attachment[BUFFER_DEPTH];
487
const struct gl_renderbuffer_attachment *stencil =
488
&fb->Attachment[BUFFER_STENCIL];
469
if (stencilRb && depthRb && stencilRb != depthRb) {
491
if (depth->Type && stencil->Type && depth->Type != stencil->Type) {
492
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
495
if (depth->Type == GL_RENDERBUFFER_EXT &&
496
stencil->Type == GL_RENDERBUFFER_EXT &&
497
depth->Renderbuffer != stencil->Renderbuffer) {
498
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
501
if (depth->Type == GL_TEXTURE &&
502
stencil->Type == GL_TEXTURE &&
503
depth->Texture != stencil->Texture) {
470
504
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
474
508
if (!st_validate_attachment(screen,
475
&fb->Attachment[BUFFER_DEPTH],
476
PIPE_TEXTURE_USAGE_DEPTH_STENCIL)) {
510
PIPE_BIND_DEPTH_STENCIL)) {
477
511
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
480
514
if (!st_validate_attachment(screen,
481
&fb->Attachment[BUFFER_STENCIL],
482
PIPE_TEXTURE_USAGE_DEPTH_STENCIL)) {
516
PIPE_BIND_DEPTH_STENCIL)) {
483
517
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
486
520
for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
487
521
if (!st_validate_attachment(screen,
488
522
&fb->Attachment[BUFFER_COLOR0 + i],
489
PIPE_TEXTURE_USAGE_RENDER_TARGET)) {
523
PIPE_BIND_RENDER_TARGET)) {
490
524
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
498
* Copy back color buffer to front color buffer.
501
copy_back_to_front(struct st_context *st,
502
struct gl_framebuffer *fb,
503
gl_buffer_index frontIndex,
504
gl_buffer_index backIndex)
507
struct st_framebuffer *stfb = (struct st_framebuffer *) fb;
508
struct pipe_surface *surf_front, *surf_back;
510
(void) st_get_framebuffer_surface(stfb, frontIndex, &surf_front);
511
(void) st_get_framebuffer_surface(stfb, backIndex, &surf_back);
513
if (surf_front && surf_back) {
514
if (st->pipe->surface_copy) {
515
st->pipe->surface_copy(st->pipe,
516
surf_front, 0, 0, /* dest */
517
surf_back, 0, 0, /* src */
518
fb->Width, fb->Height);
520
util_surface_copy(st->pipe, FALSE,
523
fb->Width, fb->Height);
530
* Check if we're drawing into, or read from, a front color buffer. If the
531
* front buffer is missing, create it now.
533
* The back color buffer must exist since we'll use its format/samples info
534
* for creating the front buffer.
536
* \param frontIndex either BUFFER_FRONT_LEFT or BUFFER_FRONT_RIGHT
537
* \param backIndex either BUFFER_BACK_LEFT or BUFFER_BACK_RIGHT
540
check_create_front_buffer(GLcontext *ctx, struct gl_framebuffer *fb,
541
gl_buffer_index frontIndex,
542
gl_buffer_index backIndex)
544
if (fb->Attachment[frontIndex].Renderbuffer == NULL) {
545
GLboolean create = GL_FALSE;
547
/* check if drawing to or reading from front buffer */
548
if (fb->_ColorReadBufferIndex == frontIndex) {
553
for (b = 0; b < fb->_NumColorDrawBuffers; b++) {
554
if (fb->_ColorDrawBufferIndexes[b] == frontIndex) {
562
struct st_renderbuffer *back;
563
struct gl_renderbuffer *front;
564
enum pipe_format colorFormat;
568
_mesa_debug(ctx, "Allocate new front buffer\n");
570
/* get back renderbuffer info */
571
back = st_renderbuffer(fb->Attachment[backIndex].Renderbuffer);
572
colorFormat = back->format;
573
samples = back->Base.NumSamples;
575
/* create front renderbuffer */
576
front = st_new_renderbuffer_fb(colorFormat, samples, FALSE);
577
_mesa_add_renderbuffer(fb, frontIndex, front);
579
/* alloc texture/surface for new front buffer */
580
front->AllocStorage(ctx, front, front->InternalFormat,
581
fb->Width, fb->Height);
583
/* initialize the front color buffer contents by copying
586
copy_back_to_front(ctx->st, fb, frontIndex, backIndex);
593
* If front left/right color buffers are missing, create them now.
596
check_create_front_buffers(GLcontext *ctx, struct gl_framebuffer *fb)
598
/* check if we need to create the front left buffer now */
599
check_create_front_buffer(ctx, fb, BUFFER_FRONT_LEFT, BUFFER_BACK_LEFT);
601
if (fb->Visual.stereoMode) {
602
check_create_front_buffer(ctx, fb, BUFFER_FRONT_RIGHT, BUFFER_BACK_RIGHT);
605
st_invalidate_state(ctx, _NEW_BUFFERS);
610
532
* Called via glDrawBuffer.
613
535
st_DrawBuffers(GLcontext *ctx, GLsizei count, const GLenum *buffers)
537
struct st_context *st = st_context(ctx);
538
GLframebuffer *fb = ctx->DrawBuffer;
617
check_create_front_buffers(ctx, ctx->DrawBuffer);
544
/* add the renderbuffers on demand */
545
for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
546
gl_buffer_index idx = fb->_ColorDrawBufferIndexes[i];
547
st_manager_add_color_renderbuffer(st, fb, idx);