Merge branch 'gallium-i915-current' into gallium-0.1
[mesa.git] / src / gallium / drivers / softpipe / sp_screen.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "pipe/p_util.h"
30 #include "pipe/p_winsys.h"
31 #include "pipe/p_defines.h"
32 #include "pipe/p_screen.h"
33
34 #include "sp_texture.h"
35 #include "sp_winsys.h"
36
37
38 static const char *
39 softpipe_get_vendor(struct pipe_screen *screen)
40 {
41 return "Tungsten Graphics, Inc.";
42 }
43
44
45 static const char *
46 softpipe_get_name(struct pipe_screen *screen)
47 {
48 return "softpipe";
49 }
50
51
52 static int
53 softpipe_get_param(struct pipe_screen *screen, int param)
54 {
55 switch (param) {
56 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
57 return 8;
58 case PIPE_CAP_NPOT_TEXTURES:
59 return 1;
60 case PIPE_CAP_TWO_SIDED_STENCIL:
61 return 1;
62 case PIPE_CAP_GLSL:
63 return 1;
64 case PIPE_CAP_S3TC:
65 return 0;
66 case PIPE_CAP_ANISOTROPIC_FILTER:
67 return 0;
68 case PIPE_CAP_POINT_SPRITE:
69 return 1;
70 case PIPE_CAP_MAX_RENDER_TARGETS:
71 return PIPE_MAX_COLOR_BUFS;
72 case PIPE_CAP_OCCLUSION_QUERY:
73 return 1;
74 case PIPE_CAP_TEXTURE_SHADOW_MAP:
75 return 1;
76 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
77 return 12; /* max 2Kx2K */
78 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
79 return 8; /* max 128x128x128 */
80 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
81 return 12; /* max 2Kx2K */
82 default:
83 return 0;
84 }
85 }
86
87
88 static float
89 softpipe_get_paramf(struct pipe_screen *screen, int param)
90 {
91 switch (param) {
92 case PIPE_CAP_MAX_LINE_WIDTH:
93 /* fall-through */
94 case PIPE_CAP_MAX_LINE_WIDTH_AA:
95 return 255.0; /* arbitrary */
96 case PIPE_CAP_MAX_POINT_WIDTH:
97 /* fall-through */
98 case PIPE_CAP_MAX_POINT_WIDTH_AA:
99 return 255.0; /* arbitrary */
100 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
101 return 0.0;
102 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
103 return 16.0; /* arbitrary */
104 default:
105 return 0;
106 }
107 }
108
109
110 /**
111 * Query format support for creating a texture, drawing surface, etc.
112 * \param format the format to test
113 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
114 */
115 static boolean
116 softpipe_is_format_supported( struct pipe_screen *screen,
117 enum pipe_format format, uint type )
118 {
119 switch (type) {
120 case PIPE_TEXTURE:
121 /* softpipe supports all texture formats */
122 return TRUE;
123 case PIPE_SURFACE:
124 /* softpipe supports all (off-screen) surface formats */
125 return TRUE;
126 default:
127 assert(0);
128 return FALSE;
129 }
130 }
131
132
133 static void
134 softpipe_destroy_screen( struct pipe_screen *screen )
135 {
136 FREE(screen);
137 }
138
139
140 /**
141 * Create a new pipe_screen object
142 * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
143 */
144 struct pipe_screen *
145 softpipe_create_screen(struct pipe_winsys *winsys)
146 {
147 struct pipe_screen *screen = CALLOC_STRUCT(pipe_screen);
148
149 if (!screen)
150 return NULL;
151
152 screen->winsys = winsys;
153
154 screen->destroy = softpipe_destroy_screen;
155
156 screen->get_name = softpipe_get_name;
157 screen->get_vendor = softpipe_get_vendor;
158 screen->get_param = softpipe_get_param;
159 screen->get_paramf = softpipe_get_paramf;
160 screen->is_format_supported = softpipe_is_format_supported;
161
162 softpipe_init_screen_texture_funcs(screen);
163
164 return screen;
165 }