Merge remote branch 'origin/master' into radeon-rewrite
[mesa.git] / src / mesa / drivers / dri / r300 / r300_context.c
index 9ab7e3ae881cf333a84923d6a79b6d78be7ecc38..6d68309d3f038ba5f89cded1660dfa377db09bbc 100644 (file)
@@ -44,6 +44,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/extensions.h"
 #include "main/state.h"
 #include "main/bufferobj.h"
+#include "main/texobj.h"
 
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
@@ -55,16 +56,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "drivers/common/driverfuncs.h"
 
-#include "radeon_ioctl.h"
-#include "radeon_span.h"
 #include "r300_context.h"
+#include "radeon_context.h"
+#include "radeon_span.h"
 #include "r300_cmdbuf.h"
 #include "r300_state.h"
 #include "r300_ioctl.h"
 #include "r300_tex.h"
 #include "r300_emit.h"
 #include "r300_swtcl.h"
-#include "radeon_bo_legacy.h"
+#include "radeon_bocs_wrapper.h"
 
 
 #include "vblank.h"
@@ -75,19 +76,17 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 int future_hw_tcl_on = 1;
 int hw_tcl_on = 1;
 
-#define need_GL_EXT_stencil_two_side
-#define need_GL_ARB_multisample
+#define need_GL_VERSION_2_0
 #define need_GL_ARB_point_parameters
-#define need_GL_ARB_texture_compression
-#define need_GL_ARB_vertex_buffer_object
 #define need_GL_ARB_vertex_program
-#define need_GL_EXT_blend_minmax
-//#define need_GL_EXT_fog_coord
-#define need_GL_EXT_multi_draw_arrays
-#define need_GL_EXT_secondary_color
 #define need_GL_EXT_blend_equation_separate
 #define need_GL_EXT_blend_func_separate
+#define need_GL_EXT_blend_minmax
+//#define need_GL_EXT_fog_coord
 #define need_GL_EXT_gpu_program_parameters
+#define need_GL_EXT_secondary_color
+#define need_GL_EXT_stencil_two_side
+#define need_GL_ATI_separate_stencil
 #define need_GL_NV_vertex_program
 #include "extension_helper.h"
 
@@ -95,27 +94,23 @@ const struct dri_extension card_extensions[] = {
   /* *INDENT-OFF* */
   {"GL_ARB_depth_texture",             NULL},
   {"GL_ARB_fragment_program",          NULL},
-  {"GL_ARB_multisample",               GL_ARB_multisample_functions},
   {"GL_ARB_multitexture",              NULL},
   {"GL_ARB_point_parameters",          GL_ARB_point_parameters_functions},
   {"GL_ARB_shadow",                    NULL},
   {"GL_ARB_shadow_ambient",            NULL},
   {"GL_ARB_texture_border_clamp",      NULL},
-  {"GL_ARB_texture_compression",       GL_ARB_texture_compression_functions},
   {"GL_ARB_texture_cube_map",          NULL},
   {"GL_ARB_texture_env_add",           NULL},
   {"GL_ARB_texture_env_combine",       NULL},
   {"GL_ARB_texture_env_crossbar",      NULL},
   {"GL_ARB_texture_env_dot3",          NULL},
   {"GL_ARB_texture_mirrored_repeat",   NULL},
-  {"GL_ARB_vertex_buffer_object",      GL_ARB_vertex_buffer_object_functions},
   {"GL_ARB_vertex_program",            GL_ARB_vertex_program_functions},
   {"GL_EXT_blend_equation_separate",   GL_EXT_blend_equation_separate_functions},
   {"GL_EXT_blend_func_separate",       GL_EXT_blend_func_separate_functions},
   {"GL_EXT_blend_minmax",              GL_EXT_blend_minmax_functions},
   {"GL_EXT_blend_subtract",            NULL},
 //  {"GL_EXT_fog_coord",                       GL_EXT_fog_coord_functions },
-  {"GL_EXT_multi_draw_arrays",         GL_EXT_multi_draw_arrays_functions},
   {"GL_EXT_gpu_program_parameters",     GL_EXT_gpu_program_parameters_functions},
   {"GL_EXT_secondary_color",           GL_EXT_secondary_color_functions},
   {"GL_EXT_shadow_funcs",              NULL},
@@ -128,6 +123,7 @@ const struct dri_extension card_extensions[] = {
   {"GL_EXT_texture_lod_bias",          NULL},
   {"GL_EXT_texture_mirror_clamp",      NULL},
   {"GL_EXT_texture_rectangle",         NULL},
+  {"GL_ATI_separate_stencil",          GL_ATI_separate_stencil_functions},
   {"GL_ATI_texture_env_combine3",      NULL},
   {"GL_ATI_texture_mirror_once",       NULL},
   {"GL_MESA_pack_invert",              NULL},
@@ -140,6 +136,16 @@ const struct dri_extension card_extensions[] = {
   /* *INDENT-ON* */
 };
 
+
+/**
+ * The GL 2.0 functions are needed to make display lists work with
+ * functions added by GL_ATI_separate_stencil.
+ */
+const struct dri_extension gl_20_extension[] = {
+  {"GL_VERSION_2_0",                   GL_VERSION_2_0_functions },
+};
+
+
 extern struct tnl_pipeline_stage _r300_render_stage;
 extern const struct tnl_pipeline_stage _r300_tcl_stage;
 
@@ -198,22 +204,6 @@ static void r300_get_lock(radeonContextPtr rmesa)
        }
 }                
 
-static void r300_vtbl_flush(GLcontext *ctx)
-{
-       r300Flush(ctx);
-}
-
-static void r300_vtbl_set_all_dirty(GLcontext *ctx)
-{
-       r300ContextPtr rmesa = R300_CONTEXT(ctx);
-       rmesa->hw.all_dirty = GL_TRUE;
-}
-
-static void r300_vtbl_emit_state(radeonContextPtr rmesa)
-{
-       r300EmitState((r300ContextPtr)rmesa);
-}
-
 static void r300_vtbl_emit_cs_header(struct radeon_cs *cs, radeonContextPtr rmesa)
 {
     /* please flush pipe do all pending work */
@@ -243,22 +233,25 @@ static void r300_vtbl_emit_cs_header(struct radeon_cs *cs, radeonContextPtr rmes
                                R300_WAIT_3D | R300_WAIT_3D_CLEAN));
 }
 
-static void r300_vtbl_flush_vertices(radeonContextPtr rmesa)
+static void r300_vtbl_pre_emit_atoms(radeonContextPtr radeon)
 {
-   R300_FIREVERTICES(((r300ContextPtr)rmesa));
+   BATCH_LOCALS(radeon);
+   cp_wait(radeon, R300_WAIT_3D | R300_WAIT_3D_CLEAN);
+   BEGIN_BATCH_NO_AUTOSTATE(2);
+   OUT_BATCH(cmdpacket0(radeon->radeonScreen, R300_TX_INVALTAGS, 1));
+   OUT_BATCH(R300_TX_FLUSH);
+   END_BATCH();
+   end_3d(radeon);
 }
 
 static void r300_init_vtbl(radeonContextPtr radeon)
 {
    radeon->vtbl.get_lock = r300_get_lock;
    radeon->vtbl.update_viewport_offset = r300UpdateViewportOffset;
-   radeon->vtbl.flush = r300_vtbl_flush;
-   radeon->vtbl.set_all_dirty = r300_vtbl_set_all_dirty;
    radeon->vtbl.update_draw_buffer = r300UpdateDrawBuffer;
    radeon->vtbl.emit_cs_header = r300_vtbl_emit_cs_header;
-   radeon->vtbl.emit_state = r300_vtbl_emit_state;
-   radeon->vtbl.flush_vertices = r300_vtbl_flush_vertices;
    radeon->vtbl.swtcl_flush = r300_swtcl_flush;
+   radeon->vtbl.pre_emit_atoms = r300_vtbl_pre_emit_atoms;
 }
 
 
@@ -358,6 +351,8 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
            ( /*512 */ RADEON_BUFFER_SIZE * 16 * 1024) / (4 * 4);
 #endif
 
+       ctx->Const.MaxDrawBuffers = 1;
+
        /* Initialize the software rasterizer and helper modules.
         */
        _swrast_CreateContext(ctx);
@@ -487,15 +482,17 @@ void r300DestroyContext(__DRIcontextPrivate * driContextPriv)
                _swrast_DestroyContext(r300->radeon.glCtx);
 
                rcommonFlushCmdBuf(&r300->radeon, __FUNCTION__);
-               r300DestroyCmdBuf(r300);
 
                if (radeon->state.scissor.pClipRects) {
                        FREE(radeon->state.scissor.pClipRects);
                        radeon->state.scissor.pClipRects = NULL;
                }
 
+               r300DestroyCmdBuf(r300);
+
                radeonCleanupContext(&r300->radeon);
 
+
                /* the memory manager might be accessed when Mesa frees the shared
                 * state, so don't destroy it earlier
                 */