Merge commit 'origin/gallium-0.1' into gallium-tex-surfaces
[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 #include "sp_screen.h"
37
38
39 static const char *
40 softpipe_get_vendor(struct pipe_screen *screen)
41 {
42 return "Tungsten Graphics, Inc.";
43 }
44
45
46 static const char *
47 softpipe_get_name(struct pipe_screen *screen)
48 {
49 return "softpipe";
50 }
51
52
53 static int
54 softpipe_get_param(struct pipe_screen *screen, int param)
55 {
56 switch (param) {
57 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
58 return 8;
59 case PIPE_CAP_NPOT_TEXTURES:
60 return 1;
61 case PIPE_CAP_TWO_SIDED_STENCIL:
62 return 1;
63 case PIPE_CAP_GLSL:
64 return 1;
65 case PIPE_CAP_S3TC:
66 return 0;
67 case PIPE_CAP_ANISOTROPIC_FILTER:
68 return 0;
69 case PIPE_CAP_POINT_SPRITE:
70 return 1;
71 case PIPE_CAP_MAX_RENDER_TARGETS:
72 return PIPE_MAX_COLOR_BUFS;
73 case PIPE_CAP_OCCLUSION_QUERY:
74 return 1;
75 case PIPE_CAP_TEXTURE_SHADOW_MAP:
76 return 1;
77 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
78 return 12; /* max 2Kx2K */
79 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
80 return 8; /* max 128x128x128 */
81 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
82 return 12; /* max 2Kx2K */
83 default:
84 return 0;
85 }
86 }
87
88
89 static float
90 softpipe_get_paramf(struct pipe_screen *screen, int param)
91 {
92 switch (param) {
93 case PIPE_CAP_MAX_LINE_WIDTH:
94 /* fall-through */
95 case PIPE_CAP_MAX_LINE_WIDTH_AA:
96 return 255.0; /* arbitrary */
97 case PIPE_CAP_MAX_POINT_WIDTH:
98 /* fall-through */
99 case PIPE_CAP_MAX_POINT_WIDTH_AA:
100 return 255.0; /* arbitrary */
101 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
102 return 0.0;
103 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
104 return 16.0; /* arbitrary */
105 default:
106 return 0;
107 }
108 }
109
110
111 /**
112 * Query format support for creating a texture, drawing surface, etc.
113 * \param format the format to test
114 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
115 */
116 static boolean
117 softpipe_is_format_supported( struct pipe_screen *screen,
118 enum pipe_format format, uint type )
119 {
120 switch (type) {
121 case PIPE_TEXTURE:
122 /* softpipe supports all texture formats */
123 return TRUE;
124 case PIPE_SURFACE:
125 /* softpipe supports all (off-screen) surface formats */
126 return TRUE;
127 default:
128 assert(0);
129 return FALSE;
130 }
131 }
132
133
134 static void
135 softpipe_destroy_screen( struct pipe_screen *screen )
136 {
137 FREE(screen);
138 }
139
140
141
142 /**
143 * Create a new pipe_screen object
144 * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
145 */
146 struct pipe_screen *
147 softpipe_create_screen(struct pipe_winsys *winsys)
148 {
149 struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
150
151 if (!screen)
152 return NULL;
153
154 screen->base.winsys = winsys;
155
156 screen->base.destroy = softpipe_destroy_screen;
157
158 screen->base.get_name = softpipe_get_name;
159 screen->base.get_vendor = softpipe_get_vendor;
160 screen->base.get_param = softpipe_get_param;
161 screen->base.get_paramf = softpipe_get_paramf;
162 screen->base.is_format_supported = softpipe_is_format_supported;
163
164 softpipe_init_screen_texture_funcs(&screen->base);
165
166 return &screen->base;
167 }