2 #include "main/mtypes.h"
3 #include "main/formats.h"
4 #include "main/renderbuffer.h"
5 #include "main/imports.h"
6 #include "drirenderbuffer.h"
10 * This will get called when a window (gl_framebuffer) is resized (probably
11 * via driUpdateFramebufferSize(), below).
12 * Just update width, height and internal format fields for now.
13 * There's usually no memory allocation above because the present
14 * DRI drivers use statically-allocated full-screen buffers. If that's not
15 * the case for a DRI driver, a different AllocStorage method should
19 driRenderbufferStorage(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
20 GLenum internalFormat
, GLuint width
, GLuint height
)
24 rb
->InternalFormat
= internalFormat
;
30 driDeleteRenderbuffer(struct gl_renderbuffer
*rb
)
32 /* don't free rb->Data Chances are it's a memory mapped region for
40 * Allocate a new driRenderbuffer object.
41 * Individual drivers are free to implement different versions of
44 * At this time, this function can only be used for window-system
45 * renderbuffers, not user-created RBOs.
47 * \param format Either GL_RGBA, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24,
48 * GL_DEPTH_COMPONENT32, or GL_STENCIL_INDEX8_EXT (for now).
49 * \param addr address in main memory of the buffer. Probably a memory
51 * \param cpp chars or bytes per pixel
52 * \param offset start of renderbuffer with respect to start of framebuffer
53 * \param pitch pixels per row
56 driNewRenderbuffer(gl_format format
, GLvoid
*addr
,
57 GLint cpp
, GLint offset
, GLint pitch
,
65 drb
= calloc(1, sizeof(driRenderbuffer
));
67 const GLuint name
= 0;
69 _mesa_init_renderbuffer(&drb
->Base
, name
);
71 /* Make sure we're using a null-valued GetPointer routine */
72 assert(drb
->Base
.GetPointer(NULL
, &drb
->Base
, 0, 0) == NULL
);
75 case MESA_FORMAT_ARGB8888
:
78 format
= MESA_FORMAT_RGB565
;
80 drb
->Base
.DataType
= GL_UNSIGNED_BYTE
;
84 /* we always Get/Put 32-bit Z values */
85 drb
->Base
.DataType
= GL_UNSIGNED_INT
;
90 /* we always Get/Put 32-bit Z values */
91 drb
->Base
.DataType
= GL_UNSIGNED_INT
;
94 case MESA_FORMAT_Z24_S8
:
95 drb
->Base
.DataType
= GL_UNSIGNED_INT_24_8_EXT
;
98 case MESA_FORMAT_S8_Z24
:
99 drb
->Base
.DataType
= GL_UNSIGNED_INT_24_8_EXT
;
104 drb
->Base
.DataType
= GL_UNSIGNED_BYTE
;
107 _mesa_problem(NULL
, "Bad format 0x%x in driNewRenderbuffer", format
);
111 drb
->Base
.Format
= format
;
113 drb
->Base
.InternalFormat
=
114 drb
->Base
._BaseFormat
= _mesa_get_format_base_format(format
);
116 drb
->Base
.AllocStorage
= driRenderbufferStorage
;
117 drb
->Base
.Delete
= driDeleteRenderbuffer
;
119 drb
->Base
.Data
= addr
;
121 /* DRI renderbuffer-specific fields: */
123 drb
->offset
= offset
;
127 /* may be changed if page flipping is active: */
128 drb
->flippedOffset
= offset
;
129 drb
->flippedPitch
= pitch
;
130 drb
->flippedData
= addr
;
137 * Update the front and back renderbuffers' flippedPitch/Offset/Data fields.
138 * If stereo, flip both the left and right pairs.
139 * This is used when we do double buffering via page flipping.
140 * \param fb the framebuffer we're page flipping
141 * \param flipped if true, set flipped values, else set non-flipped values
144 driFlipRenderbuffers(struct gl_framebuffer
*fb
, GLboolean flipped
)
146 const GLuint count
= fb
->Visual
.stereoMode
? 2 : 1;
147 GLuint lr
; /* left or right */
149 /* we shouldn't really call this function if single-buffered, but
152 if (!fb
->Visual
.doubleBufferMode
)
155 for (lr
= 0; lr
< count
; lr
++) {
156 GLuint frontBuf
= (lr
== 0) ? BUFFER_FRONT_LEFT
: BUFFER_FRONT_RIGHT
;
157 GLuint backBuf
= (lr
== 0) ? BUFFER_BACK_LEFT
: BUFFER_BACK_RIGHT
;
158 driRenderbuffer
*front_drb
159 = (driRenderbuffer
*) fb
->Attachment
[frontBuf
].Renderbuffer
;
160 driRenderbuffer
*back_drb
161 = (driRenderbuffer
*) fb
->Attachment
[backBuf
].Renderbuffer
;
164 front_drb
->flippedOffset
= back_drb
->offset
;
165 front_drb
->flippedPitch
= back_drb
->pitch
;
166 front_drb
->flippedData
= back_drb
->Base
.Data
;
167 back_drb
->flippedOffset
= front_drb
->offset
;
168 back_drb
->flippedPitch
= front_drb
->pitch
;
169 back_drb
->flippedData
= front_drb
->Base
.Data
;
172 front_drb
->flippedOffset
= front_drb
->offset
;
173 front_drb
->flippedPitch
= front_drb
->pitch
;
174 front_drb
->flippedData
= front_drb
->Base
.Data
;
175 back_drb
->flippedOffset
= back_drb
->offset
;
176 back_drb
->flippedPitch
= back_drb
->pitch
;
177 back_drb
->flippedData
= back_drb
->Base
.Data
;
184 * Check that the gl_framebuffer associated with dPriv is the right size.
185 * Resize the gl_framebuffer if needed.
186 * It's expected that the dPriv->driverPrivate member points to a
187 * gl_framebuffer object.
190 driUpdateFramebufferSize(GLcontext
*ctx
, const __DRIdrawable
*dPriv
)
192 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) dPriv
->driverPrivate
;
193 if (fb
&& (dPriv
->w
!= fb
->Width
|| dPriv
->h
!= fb
->Height
)) {
194 ctx
->Driver
.ResizeBuffers(ctx
, fb
, dPriv
->w
, dPriv
->h
);
195 /* if the driver needs the hw lock for ResizeBuffers, the drawable
196 might have changed again by now */
197 assert(fb
->Width
== dPriv
->w
);
198 assert(fb
->Height
== dPriv
->h
);