5548286a73ee8bbf0b44a1bcf52b9c580dfad245
[mesa.git] / src / mesa / drivers / dri / nouveau / nv04_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 "nv04_driver.h"
33
34 struct nouveau_grobj *
35 nv04_context_engine(GLcontext *ctx)
36 {
37 struct nv04_context *nctx = to_nv04_context(ctx);
38 struct nouveau_screen *screen = nctx->base.screen;
39 struct nouveau_grobj *fahrenheit;
40
41 if (ctx->Texture.Unit[0].EnvMode == GL_COMBINE ||
42 ctx->Texture.Unit[0].EnvMode == GL_BLEND ||
43 ctx->Texture.Unit[1]._ReallyEnabled ||
44 ctx->Stencil.Enabled)
45 fahrenheit = screen->eng3dm;
46 else
47 fahrenheit = screen->eng3d;
48
49 if (fahrenheit != nctx->eng3d) {
50 nctx->eng3d = fahrenheit;
51
52 if (nv04_mtex_engine(fahrenheit)) {
53 context_dirty_i(ctx, TEX_ENV, 0);
54 context_dirty_i(ctx, TEX_ENV, 1);
55 context_dirty_i(ctx, TEX_OBJ, 0);
56 context_dirty_i(ctx, TEX_OBJ, 1);
57 context_dirty(ctx, CONTROL);
58 context_dirty(ctx, BLEND);
59 } else {
60 context_bctx_i(ctx, TEXTURE, 1);
61 context_dirty_i(ctx, TEX_ENV, 0);
62 context_dirty_i(ctx, TEX_OBJ, 0);
63 context_dirty(ctx, CONTROL);
64 context_dirty(ctx, BLEND);
65 }
66 }
67
68 return fahrenheit;
69 }
70
71 static void
72 init_dummy_texture(GLcontext *ctx)
73 {
74 struct nouveau_surface *s = &to_nv04_context(ctx)->dummy_texture;
75
76 nouveau_surface_alloc(ctx, s, SWIZZLED,
77 NOUVEAU_BO_MAP | NOUVEAU_BO_VRAM,
78 MESA_FORMAT_ARGB8888, 1, 1);
79
80 nouveau_bo_map(s->bo, NOUVEAU_BO_WR);
81 *(uint32_t *)s->bo->map = 0xffffffff;
82 nouveau_bo_unmap(s->bo);
83 }
84
85 GLcontext *
86 nv04_context_create(struct nouveau_screen *screen, const GLvisual *visual,
87 GLcontext *share_ctx)
88 {
89 struct nv04_context *nctx;
90 GLcontext *ctx;
91
92 nctx = CALLOC_STRUCT(nv04_context);
93 if (!nctx)
94 return NULL;
95
96 ctx = &nctx->base.base;
97 nouveau_context_init(ctx, screen, visual, share_ctx);
98
99 ctx->Const.MaxTextureCoordUnits = NV04_TEXTURE_UNITS;
100 ctx->Const.MaxTextureImageUnits = NV04_TEXTURE_UNITS;
101 ctx->Const.MaxTextureUnits = NV04_TEXTURE_UNITS;
102 ctx->Const.MaxTextureMaxAnisotropy = 2;
103 ctx->Const.MaxTextureLodBias = 15;
104
105 init_dummy_texture(ctx);
106 nv04_render_init(ctx);
107
108 return ctx;
109 }
110
111 void
112 nv04_context_destroy(GLcontext *ctx)
113 {
114 nv04_render_destroy(ctx);
115 nouveau_surface_ref(NULL, &to_nv04_context(ctx)->dummy_texture);
116
117 FREE(ctx);
118 }