1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 #include "pipe/p_util.h"
30 #include "pipe/p_winsys.h"
31 #include "pipe/p_context.h"
32 #include "pipe/p_shader_tokens.h"
33 #include "pipe/p_inlines.h"
34 #include "cso_cache/cso_context.h"
35 #include "util/u_simple_shaders.h"
36 #include "st_device.h"
37 #include "st_winsys.h"
41 st_device_really_destroy(struct st_device
*st_dev
)
44 st_dev
->st_ws
->screen_destroy(st_dev
->screen
);
51 st_device_destroy(struct st_device
*st_dev
)
53 if(!--st_dev
->refcount
)
54 st_device_really_destroy(st_dev
);
58 static struct st_device
*
59 st_device_create_from_st_winsys(const struct st_winsys
*st_ws
)
61 struct st_device
*st_dev
;
63 if(!st_ws
->screen_create
||
64 !st_ws
->screen_destroy
||
65 !st_ws
->context_create
||
66 !st_ws
->context_destroy
)
69 st_dev
= CALLOC_STRUCT(st_device
);
73 st_dev
->st_ws
= st_ws
;
75 st_dev
->screen
= st_ws
->screen_create();
77 st_device_destroy(st_dev
);
84 st_device_create(boolean hardware
) {
87 return st_device_create_from_st_winsys(&st_hardware_winsys
);
90 return st_device_create_from_st_winsys(&st_software_winsys
);
95 st_context_destroy(struct st_context
*st_ctx
)
100 struct st_device
*st_dev
= st_ctx
->st_dev
;
103 st_ctx
->pipe
->bind_vs_state(st_ctx
->pipe
, NULL
);
104 st_ctx
->pipe
->delete_vs_state(st_ctx
->pipe
, st_ctx
->vs
);
108 st_ctx
->pipe
->bind_fs_state(st_ctx
->pipe
, NULL
);
109 st_ctx
->pipe
->delete_fs_state(st_ctx
->pipe
, st_ctx
->fs
);
113 cso_destroy_context(st_ctx
->cso
);
116 st_ctx
->st_dev
->st_ws
->context_destroy(st_ctx
->pipe
);
118 for(i
= 0; i
< PIPE_MAX_SAMPLERS
; ++i
)
119 pipe_texture_reference(&st_ctx
->sampler_textures
[i
], NULL
);
123 if(!--st_dev
->refcount
)
124 st_device_really_destroy(st_dev
);
130 st_context_create(struct st_device
*st_dev
)
132 struct st_context
*st_ctx
;
134 st_ctx
= CALLOC_STRUCT(st_context
);
138 st_ctx
->st_dev
= st_dev
;
141 st_ctx
->pipe
= st_dev
->st_ws
->context_create(st_dev
->screen
);
143 st_context_destroy(st_ctx
);
145 st_ctx
->cso
= cso_create_context(st_ctx
->pipe
);
147 st_context_destroy(st_ctx
);
151 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
152 TGSI_SEMANTIC_GENERIC
};
153 const uint semantic_indexes
[] = { 0, 0 };
154 st_ctx
->vs
= util_make_vertex_passthrough_shader(st_ctx
->pipe
,
158 &st_ctx
->vert_shader
);
161 /* fragment shader */
162 st_ctx
->fs
= util_make_fragment_passthrough_shader(st_ctx
->pipe
,
163 &st_ctx
->frag_shader
);
165 st_ctx
->pipe
->bind_fs_state(st_ctx
->pipe
, st_ctx
->fs
);
166 st_ctx
->pipe
->bind_vs_state(st_ctx
->pipe
, st_ctx
->vs
);