d1afa87c8aade047d59dded292b5c1b983f3af42
[mesa.git] / src / mesa / drivers / dri / nouveau / nv10_context.c
1 /*
2 * Copyright (C) 2009 Francisco Jerez.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
29 #include "nouveau_fbo.h"
30 #include "nouveau_util.h"
31 #include "nouveau_class.h"
32 #include "nv10_driver.h"
33
34 static void
35 nv10_clear(GLcontext *ctx, GLbitfield buffers)
36 {
37 struct nouveau_channel *chan = context_chan(ctx);
38 struct nouveau_grobj *celsius = context_eng3d(ctx);
39 struct nouveau_framebuffer *nfb = to_nouveau_framebuffer(
40 ctx->DrawBuffer);
41
42 nouveau_validate_framebuffer(ctx);
43
44 /* Clear the LMA depth buffer, if present. */
45 if ((buffers & BUFFER_BIT_DEPTH) && ctx->Depth.Mask &&
46 nfb->lma_bo) {
47 struct nouveau_surface *s = &to_nouveau_renderbuffer(
48 nfb->base._DepthBuffer->Wrapped)->surface;
49
50 BEGIN_RING(chan, celsius, NV17TCL_LMA_DEPTH_FILL_VALUE, 1);
51 OUT_RING(chan, pack_zs_f(s->format, ctx->Depth.Clear, 0));
52 BEGIN_RING(chan, celsius, NV17TCL_LMA_DEPTH_BUFFER_CLEAR, 1);
53 OUT_RING(chan, 1);
54 }
55
56 nouveau_clear(ctx, buffers);
57 }
58
59 GLcontext *
60 nv10_context_create(struct nouveau_screen *screen, const GLvisual *visual,
61 GLcontext *share_ctx)
62 {
63 struct nouveau_context *nctx;
64 GLcontext *ctx;
65
66 nctx = CALLOC_STRUCT(nouveau_context);
67 if (!nctx)
68 return NULL;
69
70 ctx = &nctx->base;
71 nouveau_context_init(ctx, screen, visual, share_ctx);
72
73 ctx->Const.MaxTextureLevels = 12;
74 ctx->Const.MaxTextureCoordUnits = NV10_TEXTURE_UNITS;
75 ctx->Const.MaxTextureImageUnits = NV10_TEXTURE_UNITS;
76 ctx->Const.MaxTextureUnits = NV10_TEXTURE_UNITS;
77 ctx->Const.MaxTextureMaxAnisotropy = 2;
78 ctx->Const.MaxTextureLodBias = 15;
79 ctx->Driver.Clear = nv10_clear;
80
81 nv10_render_init(ctx);
82
83 return ctx;
84 }
85
86 void
87 nv10_context_destroy(GLcontext *ctx)
88 {
89 nv10_render_destroy(ctx);
90 FREE(ctx);
91 }