i915_context.c revision a57f84251926045a3358822d0fd92ca95a4f0fde
1/************************************************************************** 2 * 3 * Copyright 2003 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#include "i915_context.h" 29#include "i915_state.h" 30#include "i915_screen.h" 31#include "i915_surface.h" 32#include "i915_batch.h" 33#include "i915_resource.h" 34 35#include "draw/draw_context.h" 36#include "pipe/p_defines.h" 37#include "util/u_inlines.h" 38#include "util/u_memory.h" 39#include "pipe/p_screen.h" 40 41 42/* 43 * Draw functions 44 */ 45 46 47static void 48i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) 49{ 50 struct i915_context *i915 = i915_context(pipe); 51 struct draw_context *draw = i915->draw; 52 void *mapped_indices = NULL; 53 unsigned i; 54 55 if (i915->dirty) 56 i915_update_derived(i915); 57 58 /* 59 * Map vertex buffers 60 */ 61 for (i = 0; i < i915->num_vertex_buffers; i++) { 62 void *buf = i915_buffer(i915->vertex_buffer[i].buffer)->data; 63 draw_set_mapped_vertex_buffer(draw, i, buf); 64 } 65 66 /* 67 * Map index buffer, if present 68 */ 69 if (info->indexed && i915->index_buffer.buffer) { 70 mapped_indices = i915_buffer(i915->index_buffer.buffer)->data; 71 mapped_indices += i915->index_buffer.offset; 72 } 73 74 draw_set_mapped_element_buffer_range(draw, (mapped_indices) ? 75 i915->index_buffer.index_size : 0, 76 info->index_bias, 77 info->min_index, 78 info->max_index, 79 mapped_indices); 80 81 82 draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0, 83 i915->current.constants[PIPE_SHADER_VERTEX], 84 (i915->current.num_user_constants[PIPE_SHADER_VERTEX] * 85 4 * sizeof(float))); 86 87 /* 88 * Do the drawing 89 */ 90 draw_arrays(i915->draw, info->mode, info->start, info->count); 91 92 /* 93 * unmap vertex/index buffers 94 */ 95 for (i = 0; i < i915->num_vertex_buffers; i++) { 96 draw_set_mapped_vertex_buffer(draw, i, NULL); 97 } 98 99 if (mapped_indices) { 100 draw_set_mapped_element_buffer(draw, 0, 0, NULL); 101 } 102} 103 104 105/* 106 * Generic context functions 107 */ 108 109 110static void i915_destroy(struct pipe_context *pipe) 111{ 112 struct i915_context *i915 = i915_context(pipe); 113 int i; 114 115 draw_destroy(i915->draw); 116 117 if(i915->batch) 118 i915->iws->batchbuffer_destroy(i915->batch); 119 120 /* unbind framebuffer */ 121 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { 122 pipe_surface_reference(&i915->framebuffer.cbufs[i], NULL); 123 } 124 pipe_surface_reference(&i915->framebuffer.zsbuf, NULL); 125 126 FREE(i915); 127} 128 129struct pipe_context * 130i915_create_context(struct pipe_screen *screen, void *priv) 131{ 132 struct i915_context *i915; 133 134 i915 = CALLOC_STRUCT(i915_context); 135 if (i915 == NULL) 136 return NULL; 137 138 i915->iws = i915_screen(screen)->iws; 139 i915->base.winsys = NULL; 140 i915->base.screen = screen; 141 i915->base.priv = priv; 142 143 i915->base.destroy = i915_destroy; 144 145 i915->base.clear = i915_clear; 146 147 i915->base.draw_vbo = i915_draw_vbo; 148 149 /* 150 * Create drawing context and plug our rendering stage into it. 151 */ 152 i915->draw = draw_create(&i915->base); 153 assert(i915->draw); 154 if (!debug_get_bool_option("I915_NO_VBUF", FALSE)) { 155 draw_set_rasterize_stage(i915->draw, i915_draw_vbuf_stage(i915)); 156 } else { 157 draw_set_rasterize_stage(i915->draw, i915_draw_render_stage(i915)); 158 } 159 160 i915_init_surface_functions(i915); 161 i915_init_state_functions(i915); 162 i915_init_flush_functions(i915); 163 i915_init_resource_functions(i915); 164 165 draw_install_aaline_stage(i915->draw, &i915->base); 166 draw_install_aapoint_stage(i915->draw, &i915->base); 167 168 i915->dirty = ~0; 169 i915->hardware_dirty = ~0; 170 171 /* Batch stream debugging is a bit hacked up at the moment: 172 */ 173 i915->batch = i915->iws->batchbuffer_create(i915->iws); 174 175 return &i915->base; 176} 177