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
,
62 assert(format
== GL_RGBA
||
65 format
== GL_DEPTH_COMPONENT16
||
66 format
== GL_DEPTH_COMPONENT24
||
67 format
== GL_DEPTH_COMPONENT32
||
68 format
== GL_STENCIL_INDEX8_EXT
);
73 drb
= calloc(1, sizeof(driRenderbuffer
));
75 const GLuint name
= 0;
77 _mesa_init_renderbuffer(&drb
->Base
, name
);
79 /* Make sure we're using a null-valued GetPointer routine */
80 assert(drb
->Base
.GetPointer(NULL
, &drb
->Base
, 0, 0) == NULL
);
83 case MESA_FORMAT_ARGB8888
:
86 format
= MESA_FORMAT_RGB565
;
88 drb
->Base
.DataType
= GL_UNSIGNED_BYTE
;
92 /* we always Get/Put 32-bit Z values */
93 drb
->Base
.DataType
= GL_UNSIGNED_INT
;
98 /* we always Get/Put 32-bit Z values */
99 drb
->Base
.DataType
= GL_UNSIGNED_INT
;
102 case MESA_FORMAT_Z24_S8
:
103 drb
->Base
.DataType
= GL_UNSIGNED_INT_24_8_EXT
;
106 case MESA_FORMAT_S8_Z24
:
107 drb
->Base
.DataType
= GL_UNSIGNED_INT_24_8_EXT
;
112 drb
->Base
.DataType
= GL_UNSIGNED_BYTE
;
115 _mesa_problem(NULL
, "Bad format 0x%x in driNewRenderbuffer", format
);
119 drb
->Base
.Format
= format
;
121 drb
->Base
.InternalFormat
=
122 drb
->Base
._BaseFormat
= _mesa_get_format_base_format(format
);
124 drb
->Base
.AllocStorage
= driRenderbufferStorage
;
125 drb
->Base
.Delete
= driDeleteRenderbuffer
;
127 drb
->Base
.Data
= addr
;
129 /* DRI renderbuffer-specific fields: */
131 drb
->offset
= offset
;
135 /* may be changed if page flipping is active: */
136 drb
->flippedOffset
= offset
;
137 drb
->flippedPitch
= pitch
;
138 drb
->flippedData
= addr
;
145 * Update the front and back renderbuffers' flippedPitch/Offset/Data fields.
146 * If stereo, flip both the left and right pairs.
147 * This is used when we do double buffering via page flipping.
148 * \param fb the framebuffer we're page flipping
149 * \param flipped if true, set flipped values, else set non-flipped values
152 driFlipRenderbuffers(struct gl_framebuffer
*fb
, GLboolean flipped
)
154 const GLuint count
= fb
->Visual
.stereoMode
? 2 : 1;
155 GLuint lr
; /* left or right */
157 /* we shouldn't really call this function if single-buffered, but
160 if (!fb
->Visual
.doubleBufferMode
)
163 for (lr
= 0; lr
< count
; lr
++) {
164 GLuint frontBuf
= (lr
== 0) ? BUFFER_FRONT_LEFT
: BUFFER_FRONT_RIGHT
;
165 GLuint backBuf
= (lr
== 0) ? BUFFER_BACK_LEFT
: BUFFER_BACK_RIGHT
;
166 driRenderbuffer
*front_drb
167 = (driRenderbuffer
*) fb
->Attachment
[frontBuf
].Renderbuffer
;
168 driRenderbuffer
*back_drb
169 = (driRenderbuffer
*) fb
->Attachment
[backBuf
].Renderbuffer
;
172 front_drb
->flippedOffset
= back_drb
->offset
;
173 front_drb
->flippedPitch
= back_drb
->pitch
;
174 front_drb
->flippedData
= back_drb
->Base
.Data
;
175 back_drb
->flippedOffset
= front_drb
->offset
;
176 back_drb
->flippedPitch
= front_drb
->pitch
;
177 back_drb
->flippedData
= front_drb
->Base
.Data
;
180 front_drb
->flippedOffset
= front_drb
->offset
;
181 front_drb
->flippedPitch
= front_drb
->pitch
;
182 front_drb
->flippedData
= front_drb
->Base
.Data
;
183 back_drb
->flippedOffset
= back_drb
->offset
;
184 back_drb
->flippedPitch
= back_drb
->pitch
;
185 back_drb
->flippedData
= back_drb
->Base
.Data
;
192 * Check that the gl_framebuffer associated with dPriv is the right size.
193 * Resize the gl_framebuffer if needed.
194 * It's expected that the dPriv->driverPrivate member points to a
195 * gl_framebuffer object.
198 driUpdateFramebufferSize(GLcontext
*ctx
, const __DRIdrawable
*dPriv
)
200 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) dPriv
->driverPrivate
;
201 if (fb
&& (dPriv
->w
!= fb
->Width
|| dPriv
->h
!= fb
->Height
)) {
202 ctx
->Driver
.ResizeBuffers(ctx
, fb
, dPriv
->w
, dPriv
->h
);
203 /* if the driver needs the hw lock for ResizeBuffers, the drawable
204 might have changed again by now */
205 assert(fb
->Width
== dPriv
->w
);
206 assert(fb
->Height
== dPriv
->h
);