remove the XFree86 ID line
[mesa.git] / src / mesa / drivers / dri / common / drirenderbuffer.c
1
2 #include "mtypes.h"
3 #include "drirenderbuffer.h"
4 #include "renderbuffer.h"
5 #include "imports.h"
6
7
8 /**
9 * This will get called when a window is resized.
10 * Just update width, height and internal format fields for now.
11 */
12 static GLboolean
13 driRenderbufferStorage(GLcontext *ctx, struct gl_renderbuffer *rb,
14 GLenum internalFormat, GLuint width, GLuint height)
15 {
16 rb->Width = width;
17 rb->Height = height;
18 rb->InternalFormat = internalFormat;
19 return GL_TRUE;
20 }
21
22
23 /**
24 * Allocate a new driRenderbuffer object.
25 * Individual drivers are free to implement different versions of
26 * this function.
27 * \param format Either GL_RGBA, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24,
28 * GL_DEPTH_COMPONENT32, or GL_STENCIL_INDEX8_EXT (for now).
29 * \param cpp chars or bytes per pixel
30 * \param offset start of buffer with respect to framebuffer address
31 * \param pitch pixels per row
32 */
33 driRenderbuffer *
34 driNewRenderbuffer(GLenum format, GLint cpp, GLint offset, GLint pitch)
35 {
36 driRenderbuffer *drb;
37
38 assert(format == GL_RGBA ||
39 format == GL_DEPTH_COMPONENT16 ||
40 format == GL_DEPTH_COMPONENT24 ||
41 format == GL_DEPTH_COMPONENT32 ||
42 format == GL_STENCIL_INDEX8_EXT);
43
44 assert(cpp > 0);
45 assert(pitch > 0);
46
47 drb = _mesa_calloc(sizeof(driRenderbuffer));
48 if (drb) {
49 const GLuint name = 0;
50
51 _mesa_init_renderbuffer(&drb->Base, name);
52
53 /* Make sure we're using a null-valued GetPointer routine */
54 assert(drb->Base.GetPointer(NULL, &drb->Base, 0, 0) == NULL);
55
56 drb->Base.InternalFormat = format;
57
58 if (format == GL_RGBA) {
59 /* Color */
60 drb->Base._BaseFormat = GL_RGBA;
61 drb->Base.DataType = GL_UNSIGNED_BYTE;
62 }
63 else if (format == GL_DEPTH_COMPONENT16) {
64 /* Depth */
65 drb->Base._BaseFormat = GL_DEPTH_COMPONENT;
66 /* we always Get/Put 32-bit Z values */
67 drb->Base.DataType = GL_UNSIGNED_INT;
68 }
69 else if (format == GL_DEPTH_COMPONENT24) {
70 /* Depth */
71 drb->Base._BaseFormat = GL_DEPTH_COMPONENT;
72 /* we always Get/Put 32-bit Z values */
73 drb->Base.DataType = GL_UNSIGNED_INT;
74 }
75 else {
76 /* Stencil */
77 ASSERT(format == GL_STENCIL_INDEX8);
78 drb->Base._BaseFormat = GL_STENCIL_INDEX;
79 drb->Base.DataType = GL_UNSIGNED_BYTE;
80 }
81
82 /* XXX if we were allocating a user-created renderbuffer, we'd have
83 * to fill in the ComponentSizes[] array too.
84 */
85
86 drb->Base.AllocStorage = driRenderbufferStorage;
87 /* using default Delete function */
88
89
90 /* DRI renderbuffer-specific fields: */
91 drb->offset = offset;
92 drb->pitch = pitch;
93 drb->cpp = cpp;
94 }
95 return drb;
96 }