aboutsummaryrefslogtreecommitdiff
path: root/mesalib
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib')
-rw-r--r--mesalib/Makefile996
-rw-r--r--mesalib/common.py184
-rw-r--r--mesalib/configure.ac3820
-rw-r--r--mesalib/docs/GL3.txt234
-rw-r--r--mesalib/docs/relnotes-7.11.html124
-rw-r--r--mesalib/include/EGL/eglext.h796
-rw-r--r--mesalib/include/GL/internal/dri_interface.h1776
-rw-r--r--mesalib/include/getopt.h128
-rw-r--r--mesalib/scons/gallium.py1246
-rw-r--r--mesalib/src/glsl/Makefile426
-rw-r--r--mesalib/src/glsl/SConscript312
-rw-r--r--mesalib/src/glsl/ast.h4
-rw-r--r--mesalib/src/glsl/ast_expr.cpp190
-rw-r--r--mesalib/src/glsl/ast_to_hir.cpp6922
-rw-r--r--mesalib/src/glsl/ast_type.cpp276
-rw-r--r--mesalib/src/glsl/builtin_types.h604
-rw-r--r--mesalib/src/glsl/doflex.bat17
-rw-r--r--mesalib/src/glsl/getopt.cpp552
-rw-r--r--mesalib/src/glsl/glcpp/glcpp.c8
-rw-r--r--mesalib/src/glsl/glsl_parser_extras.cpp1662
-rw-r--r--mesalib/src/glsl/glsl_parser_extras.h562
-rw-r--r--mesalib/src/glsl/glsl_symbol_table.cpp4
-rw-r--r--mesalib/src/glsl/glsl_symbol_table.h5
-rw-r--r--mesalib/src/glsl/glsl_types.cpp1018
-rw-r--r--mesalib/src/glsl/glsl_types.h956
-rw-r--r--mesalib/src/glsl/hir_field_selection.cpp204
-rw-r--r--mesalib/src/glsl/ir.h3280
-rw-r--r--mesalib/src/glsl/ir_constant_expression.cpp2744
-rw-r--r--mesalib/src/glsl/ir_import_prototypes.cpp244
-rw-r--r--mesalib/src/glsl/ir_print_visitor.cpp942
-rw-r--r--mesalib/src/glsl/ir_validate.cpp1058
-rw-r--r--mesalib/src/glsl/link_functions.cpp532
-rw-r--r--mesalib/src/glsl/linker.cpp3418
-rw-r--r--mesalib/src/glsl/list.h8
-rw-r--r--mesalib/src/glsl/loop_controls.cpp608
-rw-r--r--mesalib/src/glsl/lower_mat_op_to_vec.cpp980
-rw-r--r--mesalib/src/glsl/main.cpp679
-rw-r--r--mesalib/src/glsl/opt_constant_propagation.cpp868
-rw-r--r--mesalib/src/glsl/opt_constant_variable.cpp390
-rw-r--r--mesalib/src/glsl/opt_dead_code.cpp284
-rw-r--r--mesalib/src/glsl/opt_dead_code_local.cpp444
-rw-r--r--mesalib/src/glsl/opt_dead_functions.cpp306
-rw-r--r--mesalib/src/glsl/opt_structure_splitting.cpp722
-rw-r--r--mesalib/src/glsl/opt_swizzle_swizzle.cpp186
-rw-r--r--mesalib/src/glsl/opt_tree_grafting.cpp736
-rw-r--r--mesalib/src/glsl/s_expression.cpp366
-rw-r--r--mesalib/src/mapi/glapi/gen/gen.bat20
-rw-r--r--mesalib/src/mapi/glapi/gen/gl_API.xml596
-rw-r--r--mesalib/src/mapi/glapi/glapi.h31
-rw-r--r--mesalib/src/mapi/glapi/glapi_getproc.c11
-rw-r--r--mesalib/src/mapi/glapi/glapi_nop.c4
-rw-r--r--mesalib/src/mapi/glapi/glthread.c2
-rw-r--r--mesalib/src/mesa/Makefile460
-rw-r--r--mesalib/src/mesa/SConscript794
-rw-r--r--mesalib/src/mesa/drivers/common/meta.c5704
-rw-r--r--mesalib/src/mesa/drivers/dri/Makefile.template222
-rw-r--r--mesalib/src/mesa/drivers/dri/common/dri_util.c2060
-rw-r--r--mesalib/src/mesa/drivers/dri/common/dri_util.h1126
-rw-r--r--mesalib/src/mesa/drivers/dri/common/utils.c2
-rw-r--r--mesalib/src/mesa/drivers/dri/swrast/swrast.c1617
-rw-r--r--mesalib/src/mesa/drivers/dri/swrast/swrast_priv.h7
-rw-r--r--mesalib/src/mesa/drivers/windows/gdi/wmesa.c3324
-rw-r--r--mesalib/src/mesa/drivers/windows/gldirect/dglcontext.c4424
-rw-r--r--mesalib/src/mesa/main/api_arrayelt.c2
-rw-r--r--mesalib/src/mesa/main/api_exec.c1
-rw-r--r--mesalib/src/mesa/main/attrib.c3110
-rw-r--r--mesalib/src/mesa/main/blend.c1644
-rw-r--r--mesalib/src/mesa/main/bufferobj.c3832
-rw-r--r--mesalib/src/mesa/main/bufferobj.h298
-rw-r--r--mesalib/src/mesa/main/colortab.c1642
-rw-r--r--mesalib/src/mesa/main/compiler.h24
-rw-r--r--mesalib/src/mesa/main/context.c3764
-rw-r--r--mesalib/src/mesa/main/context.h626
-rw-r--r--mesalib/src/mesa/main/depth.c348
-rw-r--r--mesalib/src/mesa/main/dlist.c20666
-rw-r--r--mesalib/src/mesa/main/dlopen.c6
-rw-r--r--mesalib/src/mesa/main/drawpix.c608
-rw-r--r--mesalib/src/mesa/main/enable.c2974
-rw-r--r--mesalib/src/mesa/main/extensions.c1826
-rw-r--r--mesalib/src/mesa/main/fbobject.c4876
-rw-r--r--mesalib/src/mesa/main/formats.c3316
-rw-r--r--mesalib/src/mesa/main/formats.h486
-rw-r--r--mesalib/src/mesa/main/framebuffer.c2166
-rw-r--r--mesalib/src/mesa/main/get.c5054
-rw-r--r--mesalib/src/mesa/main/hint.c294
-rw-r--r--mesalib/src/mesa/main/imports.c2056
-rw-r--r--mesalib/src/mesa/main/imports.h1242
-rw-r--r--mesalib/src/mesa/main/lines.c234
-rw-r--r--mesalib/src/mesa/main/mipmap.c4044
-rw-r--r--mesalib/src/mesa/main/mtypes.h6710
-rw-r--r--mesalib/src/mesa/main/pixel.c1398
-rw-r--r--mesalib/src/mesa/main/polygon.c644
-rw-r--r--mesalib/src/mesa/main/queryobj.c1246
-rw-r--r--mesalib/src/mesa/main/readpix.c488
-rw-r--r--mesalib/src/mesa/main/shaderapi.c3884
-rw-r--r--mesalib/src/mesa/main/state.c1468
-rw-r--r--mesalib/src/mesa/main/stencil.c1228
-rw-r--r--mesalib/src/mesa/main/syncobj.c12
-rw-r--r--mesalib/src/mesa/main/syncobj.h12
-rw-r--r--mesalib/src/mesa/main/texcompress.c538
-rw-r--r--mesalib/src/mesa/main/texcompress_rgtc.c800
-rw-r--r--mesalib/src/mesa/main/texcompress_rgtc_tmp.h836
-rw-r--r--mesalib/src/mesa/main/texcompress_s3tc.c4
-rw-r--r--mesalib/src/mesa/main/texfetch.c1844
-rw-r--r--mesalib/src/mesa/main/texformat.c1254
-rw-r--r--mesalib/src/mesa/main/texgetimage.c1836
-rw-r--r--mesalib/src/mesa/main/teximage.c7008
-rw-r--r--mesalib/src/mesa/main/texstate.c1682
-rw-r--r--mesalib/src/mesa/main/texstore.c9404
-rw-r--r--mesalib/src/mesa/main/texstore.h418
-rw-r--r--mesalib/src/mesa/program/dobison.bat13
-rw-r--r--mesalib/src/mesa/program/doflex.bat18
-rw-r--r--mesalib/src/mesa/program/sampler.cpp274
-rw-r--r--mesalib/src/mesa/sources.mak740
-rw-r--r--mesalib/src/mesa/state_tracker/st_atom_blend.c604
-rw-r--r--mesalib/src/mesa/state_tracker/st_atom_framebuffer.c364
-rw-r--r--mesalib/src/mesa/state_tracker/st_atom_sampler.c456
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_bitmap.c1788
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c936
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_clear.c1158
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_drawpixels.c2976
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_drawtex.c614
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_readpixels.c1122
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_texture.c3862
-rw-r--r--mesalib/src/mesa/state_tracker/st_context.c594
-rw-r--r--mesalib/src/mesa/state_tracker/st_context.h540
-rw-r--r--mesalib/src/mesa/state_tracker/st_draw.c1550
-rw-r--r--mesalib/src/mesa/state_tracker/st_draw_feedback.c554
-rw-r--r--mesalib/src/mesa/state_tracker/st_extensions.c996
-rw-r--r--mesalib/src/mesa/state_tracker/st_format.c2344
-rw-r--r--mesalib/src/mesa/state_tracker/st_format.h172
-rw-r--r--mesalib/src/mesa/state_tracker/st_gen_mipmap.c906
-rw-r--r--mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c2498
-rw-r--r--mesalib/src/mesa/state_tracker/st_program.c2330
-rw-r--r--mesalib/src/mesa/swrast/s_bitmap.c446
-rw-r--r--mesalib/src/mesa/swrast/s_drawpix.c1506
-rw-r--r--mesalib/src/mesa/swrast/s_readpix.c1016
-rw-r--r--mesalib/src/mesa/swrast/s_texcombine.c1474
-rw-r--r--mesalib/src/mesa/tnl/t_draw.c1068
-rw-r--r--mesalib/src/mesa/vbo/vbo.h352
-rw-r--r--mesalib/src/mesa/vbo/vbo_attrib_tmp.h1480
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec.h408
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec_api.c2242
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec_array.c2650
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec_draw.c852
-rw-r--r--mesalib/src/mesa/vbo/vbo_save_api.c2620
-rw-r--r--mesalib/src/mesa/vbo/vbo_save_draw.c610
-rw-r--r--mesalib/windows/VC8/mesa/gdi/gdi.vcproj445
-rw-r--r--mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcproj13
-rw-r--r--mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcxproj187
-rw-r--r--mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcxproj.filters245
-rw-r--r--mesalib/windows/VC8/mesa/glu/glu.vcproj1202
-rw-r--r--mesalib/windows/VC8/mesa/makefile58
-rw-r--r--mesalib/windows/VC8/mesa/mesa.sln42
-rw-r--r--mesalib/windows/VC8/mesa/mesa/mesa.vcproj74
-rw-r--r--mesalib/windows/VC8/mesa/mesa/mesa.vcxproj355
-rw-r--r--mesalib/windows/VC8/mesa/mesa/mesa.vcxproj.filters679
-rw-r--r--mesalib/windows/VC8/mesa/mesavc10.sln31
-rw-r--r--mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcproj (renamed from mesalib/windows/VC8/mesa/osmesa/osmesa.vcproj)169
-rw-r--r--mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcxproj178
-rw-r--r--mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcxproj.filters129
161 files changed, 109542 insertions, 108476 deletions
diff --git a/mesalib/Makefile b/mesalib/Makefile
index a1ab65ef0..814d20eb2 100644
--- a/mesalib/Makefile
+++ b/mesalib/Makefile
@@ -1,498 +1,498 @@
-# Top-level Mesa makefile
-
-TOP = .
-
-SUBDIRS = src
-
-
-default: $(TOP)/configs/current
- @for dir in $(SUBDIRS) ; do \
- if [ -d $$dir ] ; then \
- (cd $$dir && $(MAKE)) || exit 1 ; \
- fi \
- done
-
-all: default
-
-
-doxygen:
- cd doxygen && $(MAKE)
-
-clean:
- -@touch $(TOP)/configs/current
- -@for dir in $(SUBDIRS) ; do \
- if [ -d $$dir ] ; then \
- (cd $$dir && $(MAKE) clean) ; \
- fi \
- done
- -@test -s $(TOP)/configs/current || rm -f $(TOP)/configs/current
-
-
-realclean: clean
- -rm -rf lib*
- -rm -f $(TOP)/configs/current
- -rm -f $(TOP)/configs/autoconf
- -rm -rf autom4te.cache
- -find . '(' -name '*.o' -o -name '*.a' -o -name '*.so' -o \
- -name depend -o -name depend.bak ')' -exec rm -f '{}' ';'
-
-
-distclean: realclean
-
-
-install:
- @for dir in $(SUBDIRS) ; do \
- if [ -d $$dir ] ; then \
- (cd $$dir && $(MAKE) install) || exit 1 ; \
- fi \
- done
-
-
-.PHONY: default doxygen clean realclean distclean install
-
-# If there's no current configuration file
-$(TOP)/configs/current:
- @echo
- @echo
- @echo "Please choose a configuration from the following list:"
- @ls -1 $(TOP)/configs | grep -v "current\|default\|CVS\|autoconf.*"
- @echo
- @echo "Then type 'make <config>' (ex: 'make linux-x86')"
- @echo
- @echo "Or, run './configure' then 'make'"
- @echo "See './configure --help' for details"
- @echo
- @echo "(ignore the following error message)"
- @exit 1
-
-
-# Rules to set/install a specific build configuration
-aix \
-aix-64 \
-aix-64-static \
-aix-gcc \
-aix-static \
-autoconf \
-bluegene-osmesa \
-bluegene-xlc-osmesa \
-beos \
-catamount-osmesa-pgi \
-darwin \
-darwin-fat-32bit \
-darwin-fat-all \
-freebsd \
-freebsd-dri \
-freebsd-dri-amd64 \
-freebsd-dri-x86 \
-hpux10 \
-hpux10-gcc \
-hpux10-static \
-hpux11-32 \
-hpux11-32-static \
-hpux11-32-static-nothreads \
-hpux11-64 \
-hpux11-64-static \
-hpux11-ia64 \
-hpux11-ia64-static \
-hpux9 \
-hpux9-gcc \
-irix6-64 \
-irix6-64-static \
-irix6-n32 \
-irix6-n32-static \
-irix6-o32 \
-irix6-o32-static \
-linux \
-linux-i965 \
-linux-alpha \
-linux-alpha-static \
-linux-cell \
-linux-cell-debug \
-linux-debug \
-linux-dri \
-linux-dri-debug \
-linux-dri-x86 \
-linux-dri-x86-64 \
-linux-dri-ppc \
-linux-dri-xcb \
-linux-egl \
-linux-indirect \
-linux-fbdev \
-linux-ia64-icc \
-linux-ia64-icc-static \
-linux-icc \
-linux-icc-static \
-linux-llvm \
-linux-llvm-debug \
-linux-opengl-es \
-linux-osmesa \
-linux-osmesa-static \
-linux-osmesa16 \
-linux-osmesa16-static \
-linux-osmesa32 \
-linux-ppc \
-linux-ppc-static \
-linux-profile \
-linux-sparc \
-linux-sparc5 \
-linux-static \
-linux-ultrasparc \
-linux-tcc \
-linux-x86 \
-linux-x86-debug \
-linux-x86-32 \
-linux-x86-64 \
-linux-x86-64-debug \
-linux-x86-64-profile \
-linux-x86-64-static \
-linux-x86-profile \
-linux-x86-static \
-netbsd \
-openbsd \
-osf1 \
-osf1-static \
-solaris-x86 \
-solaris-x86-gcc \
-solaris-x86-gcc-static \
-sunos4 \
-sunos4-gcc \
-sunos4-static \
-sunos5 \
-sunos5-gcc \
-sunos5-64-gcc \
-sunos5-smp \
-sunos5-v8 \
-sunos5-v8-static \
-sunos5-v9 \
-sunos5-v9-static \
-sunos5-v9-cc-g++ \
-ultrix-gcc:
- @ if test -f configs/current -o -L configs/current; then \
- if ! cmp configs/$@ configs/current > /dev/null; then \
- echo "Please run 'make realclean' before changing configs" ; \
- exit 1 ; \
- fi ; \
- else \
- cd configs && rm -f current && ln -s $@ current ; \
- fi
- $(MAKE) default
-
-
-# Rules for making release tarballs
-
-VERSION=7.11-devel
-DIRECTORY = Mesa-$(VERSION)
-LIB_NAME = MesaLib-$(VERSION)
-GLUT_NAME = MesaGLUT-$(VERSION)
-
-# This is part of MAIN_FILES
-MAIN_ES_FILES = \
- $(DIRECTORY)/src/mesa/main/*.xml \
- $(DIRECTORY)/src/mesa/main/*.py \
- $(DIRECTORY)/src/mesa/main/*.dtd
-
-MAIN_FILES = \
- $(DIRECTORY)/Makefile* \
- $(DIRECTORY)/configure \
- $(DIRECTORY)/configure.ac \
- $(DIRECTORY)/acinclude.m4 \
- $(DIRECTORY)/aclocal.m4 \
- $(DIRECTORY)/bin/config.guess \
- $(DIRECTORY)/bin/config.sub \
- $(DIRECTORY)/bin/install-sh \
- $(DIRECTORY)/bin/mklib \
- $(DIRECTORY)/bin/minstall \
- $(DIRECTORY)/bin/version.mk \
- $(DIRECTORY)/configs/[a-z]* \
- $(DIRECTORY)/docs/*.html \
- $(DIRECTORY)/docs/COPYING \
- $(DIRECTORY)/docs/README.* \
- $(DIRECTORY)/docs/RELNOTES* \
- $(DIRECTORY)/docs/*.spec \
- $(DIRECTORY)/include/GL/gl.h \
- $(DIRECTORY)/include/GL/glext.h \
- $(DIRECTORY)/include/GL/gl_mangle.h \
- $(DIRECTORY)/include/GL/glu.h \
- $(DIRECTORY)/include/GL/glu_mangle.h \
- $(DIRECTORY)/include/GL/glx.h \
- $(DIRECTORY)/include/GL/glxext.h \
- $(DIRECTORY)/include/GL/glx_mangle.h \
- $(DIRECTORY)/include/GL/glfbdev.h \
- $(DIRECTORY)/include/GL/mesa_wgl.h \
- $(DIRECTORY)/include/GL/osmesa.h \
- $(DIRECTORY)/include/GL/vms_x_fix.h \
- $(DIRECTORY)/include/GL/wglext.h \
- $(DIRECTORY)/include/GL/wmesa.h \
- $(DIRECTORY)/src/glsl/Makefile \
- $(DIRECTORY)/src/glsl/Makefile.template \
- $(DIRECTORY)/src/glsl/SConscript \
- $(DIRECTORY)/src/glsl/*.[ch] \
- $(DIRECTORY)/src/glsl/*.[cly]pp \
- $(DIRECTORY)/src/glsl/README \
- $(DIRECTORY)/src/glsl/glcpp/*.[chly] \
- $(DIRECTORY)/src/glsl/glcpp/README \
- $(DIRECTORY)/src/glsl/builtins \
- $(DIRECTORY)/src/Makefile \
- $(DIRECTORY)/src/mesa/Makefile* \
- $(DIRECTORY)/src/mesa/sources.mak \
- $(DIRECTORY)/src/mesa/descrip.mms \
- $(DIRECTORY)/src/mesa/gl.pc.in \
- $(DIRECTORY)/src/mesa/osmesa.pc.in \
- $(DIRECTORY)/src/mesa/depend \
- $(MAIN_ES_FILES) \
- $(DIRECTORY)/src/mesa/main/*.[chS] \
- $(DIRECTORY)/src/mesa/main/descrip.mms \
- $(DIRECTORY)/src/mesa/math/*.[ch] \
- $(DIRECTORY)/src/mesa/math/descrip.mms \
- $(DIRECTORY)/src/mesa/program/*.[chly] \
- $(DIRECTORY)/src/mesa/program/*.cpp \
- $(DIRECTORY)/src/mesa/program/Makefile \
- $(DIRECTORY)/src/mesa/program/descrip.mms \
- $(DIRECTORY)/src/mesa/swrast/*.[ch] \
- $(DIRECTORY)/src/mesa/swrast/descrip.mms \
- $(DIRECTORY)/src/mesa/swrast_setup/*.[ch] \
- $(DIRECTORY)/src/mesa/swrast_setup/descrip.mms \
- $(DIRECTORY)/src/mesa/vbo/*.[chS] \
- $(DIRECTORY)/src/mesa/vbo/descrip.mms \
- $(DIRECTORY)/src/mesa/tnl/*.[chS] \
- $(DIRECTORY)/src/mesa/tnl/descrip.mms \
- $(DIRECTORY)/src/mesa/tnl_dd/*.[ch] \
- $(DIRECTORY)/src/mesa/tnl_dd/imm/*.[ch] \
- $(DIRECTORY)/src/mesa/tnl_dd/imm/NOTES.imm \
- $(DIRECTORY)/src/mesa/drivers/Makefile \
- $(DIRECTORY)/src/mesa/drivers/beos/*.cpp \
- $(DIRECTORY)/src/mesa/drivers/beos/Makefile \
- $(DIRECTORY)/src/mesa/drivers/common/*.[ch] \
- $(DIRECTORY)/src/mesa/drivers/common/descrip.mms \
- $(DIRECTORY)/src/mesa/drivers/fbdev/Makefile \
- $(DIRECTORY)/src/mesa/drivers/fbdev/glfbdev.c \
- $(DIRECTORY)/src/mesa/drivers/osmesa/Makefile \
- $(DIRECTORY)/src/mesa/drivers/osmesa/Makefile.win \
- $(DIRECTORY)/src/mesa/drivers/osmesa/descrip.mms \
- $(DIRECTORY)/src/mesa/drivers/osmesa/osmesa.def \
- $(DIRECTORY)/src/mesa/drivers/osmesa/*.[ch] \
- $(DIRECTORY)/src/mesa/drivers/windows/*/*.[ch] \
- $(DIRECTORY)/src/mesa/drivers/windows/*/*.def \
- $(DIRECTORY)/src/mesa/drivers/x11/Makefile \
- $(DIRECTORY)/src/mesa/drivers/x11/descrip.mms \
- $(DIRECTORY)/src/mesa/drivers/x11/*.[ch] \
- $(DIRECTORY)/src/mesa/ppc/*.[ch] \
- $(DIRECTORY)/src/mesa/sparc/*.[chS] \
- $(DIRECTORY)/src/mesa/x86/Makefile \
- $(DIRECTORY)/src/mesa/x86/*.[ch] \
- $(DIRECTORY)/src/mesa/x86/*.S \
- $(DIRECTORY)/src/mesa/x86/rtasm/*.[ch] \
- $(DIRECTORY)/src/mesa/x86-64/*.[chS] \
- $(DIRECTORY)/src/mesa/x86-64/Makefile
-
-MAPI_FILES = \
- $(DIRECTORY)/include/GLES/*.h \
- $(DIRECTORY)/include/GLES2/*.h \
- $(DIRECTORY)/include/VG/*.h \
- $(DIRECTORY)/src/mapi/es?api/Makefile \
- $(DIRECTORY)/src/mapi/es?api/*.pc.in \
- $(DIRECTORY)/src/mapi/glapi/gen/Makefile \
- $(DIRECTORY)/src/mapi/glapi/gen/*.xml \
- $(DIRECTORY)/src/mapi/glapi/gen/*.py \
- $(DIRECTORY)/src/mapi/glapi/gen/*.dtd \
- $(DIRECTORY)/src/mapi/glapi/gen-es/Makefile \
- $(DIRECTORY)/src/mapi/glapi/gen-es/*.xml \
- $(DIRECTORY)/src/mapi/glapi/gen-es/*.py \
- $(DIRECTORY)/src/mapi/glapi/Makefile \
- $(DIRECTORY)/src/mapi/glapi/SConscript \
- $(DIRECTORY)/src/mapi/glapi/sources.mak \
- $(DIRECTORY)/src/mapi/glapi/*.[chS] \
- $(DIRECTORY)/src/mapi/mapi/mapi_abi.py \
- $(DIRECTORY)/src/mapi/mapi/sources.mak \
- $(DIRECTORY)/src/mapi/mapi/*.[ch] \
- $(DIRECTORY)/src/mapi/vgapi/Makefile \
- $(DIRECTORY)/src/mapi/vgapi/vgapi.csv \
- $(DIRECTORY)/src/mapi/vgapi/vg.pc.in
-
-EGL_FILES = \
- $(DIRECTORY)/include/KHR/*.h \
- $(DIRECTORY)/include/EGL/*.h \
- $(DIRECTORY)/src/egl/Makefile \
- $(DIRECTORY)/src/egl/*/Makefile \
- $(DIRECTORY)/src/egl/*/Makefile.template \
- $(DIRECTORY)/src/egl/*/*.[ch] \
- $(DIRECTORY)/src/egl/*/*/Makefile \
- $(DIRECTORY)/src/egl/*/*/*.[ch] \
- $(DIRECTORY)/src/egl/main/*.pc.in \
- $(DIRECTORY)/src/egl/main/*.def
-
-GALLIUM_FILES = \
- $(DIRECTORY)/src/mesa/state_tracker/*[ch] \
- $(DIRECTORY)/src/gallium/Makefile \
- $(DIRECTORY)/src/gallium/Makefile.template \
- $(DIRECTORY)/src/gallium/SConscript \
- $(DIRECTORY)/src/gallium/targets/Makefile.dri \
- $(DIRECTORY)/src/gallium/targets/Makefile.xorg \
- $(DIRECTORY)/src/gallium/targets/SConscript.dri \
- $(DIRECTORY)/src/gallium/*/Makefile \
- $(DIRECTORY)/src/gallium/*/SConscript \
- $(DIRECTORY)/src/gallium/*/*/Makefile \
- $(DIRECTORY)/src/gallium/*/*/SConscript \
- $(DIRECTORY)/src/gallium/*/*/*.[ch] \
- $(DIRECTORY)/src/gallium/auxiliary/gallivm/*.cpp \
- $(DIRECTORY)/src/gallium/*/*/*.py \
- $(DIRECTORY)/src/gallium/*/*/*.csv \
- $(DIRECTORY)/src/gallium/*/*/*/Makefile \
- $(DIRECTORY)/src/gallium/*/*/*/SConscript \
- $(DIRECTORY)/src/gallium/*/*/*/*.[ch] \
- $(DIRECTORY)/src/gallium/*/*/*/*.py
-
-
-DRI_FILES = \
- $(DIRECTORY)/include/GL/internal/dri_interface.h \
- $(DIRECTORY)/include/GL/internal/sarea.h \
- $(DIRECTORY)/src/glx/Makefile \
- $(DIRECTORY)/src/glx/*.[ch] \
- $(DIRECTORY)/src/mesa/drivers/dri/Makefile \
- $(DIRECTORY)/src/mesa/drivers/dri/Makefile.template \
- $(DIRECTORY)/src/mesa/drivers/dri/dri.pc.in \
- $(DIRECTORY)/src/mesa/drivers/dri/common/xmlpool/*.po \
- $(DIRECTORY)/src/mesa/drivers/dri/*/*.[chS] \
- $(DIRECTORY)/src/mesa/drivers/dri/*/*.cpp \
- $(DIRECTORY)/src/mesa/drivers/dri/*/*/*.[chS] \
- $(DIRECTORY)/src/mesa/drivers/dri/*/Makefile \
- $(DIRECTORY)/src/mesa/drivers/dri/*/*/Makefile \
- $(DIRECTORY)/src/mesa/drivers/dri/*/Doxyfile
-
-SGI_GLU_FILES = \
- $(DIRECTORY)/src/glu/Makefile \
- $(DIRECTORY)/src/glu/glu.pc.in \
- $(DIRECTORY)/src/glu/sgi/Makefile \
- $(DIRECTORY)/src/glu/sgi/Makefile.mgw \
- $(DIRECTORY)/src/glu/sgi/Makefile.win \
- $(DIRECTORY)/src/glu/sgi/glu.def \
- $(DIRECTORY)/src/glu/sgi/dummy.cc \
- $(DIRECTORY)/src/glu/sgi/glu.exports \
- $(DIRECTORY)/src/glu/sgi/glu.exports.darwin \
- $(DIRECTORY)/src/glu/sgi/mesaglu.opt \
- $(DIRECTORY)/src/glu/sgi/include/gluos.h \
- $(DIRECTORY)/src/glu/sgi/libnurbs/interface/*.h \
- $(DIRECTORY)/src/glu/sgi/libnurbs/interface/*.cc \
- $(DIRECTORY)/src/glu/sgi/libnurbs/internals/*.h \
- $(DIRECTORY)/src/glu/sgi/libnurbs/internals/*.cc \
- $(DIRECTORY)/src/glu/sgi/libnurbs/nurbtess/*.h \
- $(DIRECTORY)/src/glu/sgi/libnurbs/nurbtess/*.cc \
- $(DIRECTORY)/src/glu/sgi/libtess/README \
- $(DIRECTORY)/src/glu/sgi/libtess/alg-outline \
- $(DIRECTORY)/src/glu/sgi/libtess/*.[ch] \
- $(DIRECTORY)/src/glu/sgi/libutil/*.[ch]
-
-GLW_FILES = \
- $(DIRECTORY)/src/glw/*.[ch] \
- $(DIRECTORY)/src/glw/Makefile* \
- $(DIRECTORY)/src/glw/README \
- $(DIRECTORY)/src/glw/glw.pc.in \
- $(DIRECTORY)/src/glw/depend
-
-GLUT_FILES = \
- $(DIRECTORY)/include/GL/glut.h \
- $(DIRECTORY)/include/GL/glutf90.h \
- $(DIRECTORY)/src/glut/glx/Makefile* \
- $(DIRECTORY)/src/glut/glx/depend \
- $(DIRECTORY)/src/glut/glx/glut.pc.in \
- $(DIRECTORY)/src/glut/glx/*def \
- $(DIRECTORY)/src/glut/glx/*.[ch] \
- $(DIRECTORY)/src/glut/beos/*.[ch] \
- $(DIRECTORY)/src/glut/beos/*.cpp \
- $(DIRECTORY)/src/glut/beos/Makefile
-
-DEPEND_FILES = \
- $(TOP)/src/mesa/depend \
- $(TOP)/src/glx/depend \
- $(TOP)/src/glw/depend \
- $(TOP)/src/glut/glx/depend \
- $(TOP)/src/glu/sgi/depend
-
-
-LIB_FILES = \
- $(MAIN_FILES) \
- $(MAPI_FILES) \
- $(ES_FILES) \
- $(EGL_FILES) \
- $(GALLIUM_FILES) \
- $(DRI_FILES) \
- $(SGI_GLU_FILES) \
- $(GLW_FILES)
-
-
-parsers: configure
- -@touch $(TOP)/configs/current
- $(MAKE) -C src/glsl glsl_parser.cpp glsl_parser.h glsl_lexer.cpp
- $(MAKE) -C src/glsl/glcpp glcpp-lex.c glcpp-parse.c glcpp-parse.h
- $(MAKE) -C src/mesa/program lex.yy.c program_parse.tab.c program_parse.tab.h
-
-# Everything for new a Mesa release:
-ARCHIVES = $(LIB_NAME).tar.gz \
- $(LIB_NAME).tar.bz2 \
- $(LIB_NAME).zip \
- $(GLUT_NAME).tar.gz \
- $(GLUT_NAME).tar.bz2 \
- $(GLUT_NAME).zip
-
-tarballs: md5
- rm -f ../$(LIB_NAME).tar
-
-# Helper for autoconf builds
-ACLOCAL = aclocal
-ACLOCAL_FLAGS =
-AUTOCONF = autoconf
-AC_FLAGS =
-aclocal.m4: configure.ac acinclude.m4
- $(ACLOCAL) $(ACLOCAL_FLAGS)
-configure: rm_depend configure.ac aclocal.m4 acinclude.m4
- $(AUTOCONF) $(AC_FLAGS)
-
-rm_depend:
- @for dep in $(DEPEND_FILES) ; do \
- rm -f $$dep ; \
- touch $$dep ; \
- done
-
-rm_config: parsers
- rm -f configs/current
- rm -f configs/autoconf
-
-$(LIB_NAME).tar: rm_config
- cd .. ; tar -cf $(DIRECTORY)/$(LIB_NAME).tar $(LIB_FILES)
-
-$(LIB_NAME).tar.gz: $(LIB_NAME).tar
- gzip --stdout --best $(LIB_NAME).tar > $(LIB_NAME).tar.gz
-
-$(GLUT_NAME).tar: rm_depend
- cd .. ; tar -cf $(DIRECTORY)/$(GLUT_NAME).tar $(GLUT_FILES)
-
-$(GLUT_NAME).tar.gz: $(GLUT_NAME).tar
- gzip --stdout --best $(GLUT_NAME).tar > $(GLUT_NAME).tar.gz
-
-$(LIB_NAME).tar.bz2: $(LIB_NAME).tar
- bzip2 --stdout --best $(LIB_NAME).tar > $(LIB_NAME).tar.bz2
-
-$(GLUT_NAME).tar.bz2: $(GLUT_NAME).tar
- bzip2 --stdout --best $(GLUT_NAME).tar > $(GLUT_NAME).tar.bz2
-
-$(LIB_NAME).zip: rm_config
- rm -f $(LIB_NAME).zip ; \
- cd .. ; \
- zip -qr $(LIB_NAME).zip $(LIB_FILES) ; \
- mv $(LIB_NAME).zip $(DIRECTORY)
-
-$(GLUT_NAME).zip:
- rm -f $(GLUT_NAME).zip ; \
- cd .. ; \
- zip -qr $(GLUT_NAME).zip $(GLUT_FILES) ; \
- mv $(GLUT_NAME).zip $(DIRECTORY)
-
-md5: $(ARCHIVES)
- @-md5sum $(LIB_NAME).tar.gz
- @-md5sum $(LIB_NAME).tar.bz2
- @-md5sum $(LIB_NAME).zip
- @-md5sum $(GLUT_NAME).tar.gz
- @-md5sum $(GLUT_NAME).tar.bz2
- @-md5sum $(GLUT_NAME).zip
-
-.PHONY: tarballs rm_depend rm_config md5
+# Top-level Mesa makefile
+
+TOP = .
+
+SUBDIRS = src
+
+
+default: $(TOP)/configs/current
+ @for dir in $(SUBDIRS) ; do \
+ if [ -d $$dir ] ; then \
+ (cd $$dir && $(MAKE)) || exit 1 ; \
+ fi \
+ done
+
+all: default
+
+
+doxygen:
+ cd doxygen && $(MAKE)
+
+clean:
+ -@touch $(TOP)/configs/current
+ -@for dir in $(SUBDIRS) ; do \
+ if [ -d $$dir ] ; then \
+ (cd $$dir && $(MAKE) clean) ; \
+ fi \
+ done
+ -@test -s $(TOP)/configs/current || rm -f $(TOP)/configs/current
+
+
+realclean: clean
+ -rm -rf lib*
+ -rm -f $(TOP)/configs/current
+ -rm -f $(TOP)/configs/autoconf
+ -rm -rf autom4te.cache
+ -find . '(' -name '*.o' -o -name '*.a' -o -name '*.so' -o \
+ -name depend -o -name depend.bak ')' -exec rm -f '{}' ';'
+
+
+distclean: realclean
+
+
+install:
+ @for dir in $(SUBDIRS) ; do \
+ if [ -d $$dir ] ; then \
+ (cd $$dir && $(MAKE) install) || exit 1 ; \
+ fi \
+ done
+
+
+.PHONY: default doxygen clean realclean distclean install
+
+# If there's no current configuration file
+$(TOP)/configs/current:
+ @echo
+ @echo
+ @echo "Please choose a configuration from the following list:"
+ @ls -1 $(TOP)/configs | grep -v "current\|default\|CVS\|autoconf.*"
+ @echo
+ @echo "Then type 'make <config>' (ex: 'make linux-x86')"
+ @echo
+ @echo "Or, run './configure' then 'make'"
+ @echo "See './configure --help' for details"
+ @echo
+ @echo "(ignore the following error message)"
+ @exit 1
+
+
+# Rules to set/install a specific build configuration
+aix \
+aix-64 \
+aix-64-static \
+aix-gcc \
+aix-static \
+autoconf \
+bluegene-osmesa \
+bluegene-xlc-osmesa \
+beos \
+catamount-osmesa-pgi \
+darwin \
+darwin-fat-32bit \
+darwin-fat-all \
+freebsd \
+freebsd-dri \
+freebsd-dri-amd64 \
+freebsd-dri-x86 \
+hpux10 \
+hpux10-gcc \
+hpux10-static \
+hpux11-32 \
+hpux11-32-static \
+hpux11-32-static-nothreads \
+hpux11-64 \
+hpux11-64-static \
+hpux11-ia64 \
+hpux11-ia64-static \
+hpux9 \
+hpux9-gcc \
+irix6-64 \
+irix6-64-static \
+irix6-n32 \
+irix6-n32-static \
+irix6-o32 \
+irix6-o32-static \
+linux \
+linux-i965 \
+linux-alpha \
+linux-alpha-static \
+linux-cell \
+linux-cell-debug \
+linux-debug \
+linux-dri \
+linux-dri-debug \
+linux-dri-x86 \
+linux-dri-x86-64 \
+linux-dri-ppc \
+linux-dri-xcb \
+linux-egl \
+linux-indirect \
+linux-fbdev \
+linux-ia64-icc \
+linux-ia64-icc-static \
+linux-icc \
+linux-icc-static \
+linux-llvm \
+linux-llvm-debug \
+linux-opengl-es \
+linux-osmesa \
+linux-osmesa-static \
+linux-osmesa16 \
+linux-osmesa16-static \
+linux-osmesa32 \
+linux-ppc \
+linux-ppc-static \
+linux-profile \
+linux-sparc \
+linux-sparc5 \
+linux-static \
+linux-ultrasparc \
+linux-tcc \
+linux-x86 \
+linux-x86-debug \
+linux-x86-32 \
+linux-x86-64 \
+linux-x86-64-debug \
+linux-x86-64-profile \
+linux-x86-64-static \
+linux-x86-profile \
+linux-x86-static \
+netbsd \
+openbsd \
+osf1 \
+osf1-static \
+solaris-x86 \
+solaris-x86-gcc \
+solaris-x86-gcc-static \
+sunos4 \
+sunos4-gcc \
+sunos4-static \
+sunos5 \
+sunos5-gcc \
+sunos5-64-gcc \
+sunos5-smp \
+sunos5-v8 \
+sunos5-v8-static \
+sunos5-v9 \
+sunos5-v9-static \
+sunos5-v9-cc-g++ \
+ultrix-gcc:
+ @ if test -f configs/current -o -L configs/current; then \
+ if ! cmp configs/$@ configs/current > /dev/null; then \
+ echo "Please run 'make realclean' before changing configs" ; \
+ exit 1 ; \
+ fi ; \
+ else \
+ cd configs && rm -f current && ln -s $@ current ; \
+ fi
+ $(MAKE) default
+
+
+# Rules for making release tarballs
+
+VERSION=7.11-devel
+DIRECTORY = Mesa-$(VERSION)
+LIB_NAME = MesaLib-$(VERSION)
+GLUT_NAME = MesaGLUT-$(VERSION)
+
+# This is part of MAIN_FILES
+MAIN_ES_FILES = \
+ $(DIRECTORY)/src/mesa/main/*.xml \
+ $(DIRECTORY)/src/mesa/main/*.py \
+ $(DIRECTORY)/src/mesa/main/*.dtd
+
+MAIN_FILES = \
+ $(DIRECTORY)/Makefile* \
+ $(DIRECTORY)/configure \
+ $(DIRECTORY)/configure.ac \
+ $(DIRECTORY)/acinclude.m4 \
+ $(DIRECTORY)/aclocal.m4 \
+ $(DIRECTORY)/bin/config.guess \
+ $(DIRECTORY)/bin/config.sub \
+ $(DIRECTORY)/bin/install-sh \
+ $(DIRECTORY)/bin/mklib \
+ $(DIRECTORY)/bin/minstall \
+ $(DIRECTORY)/bin/version.mk \
+ $(DIRECTORY)/configs/[a-z]* \
+ $(DIRECTORY)/docs/*.html \
+ $(DIRECTORY)/docs/COPYING \
+ $(DIRECTORY)/docs/README.* \
+ $(DIRECTORY)/docs/RELNOTES* \
+ $(DIRECTORY)/docs/*.spec \
+ $(DIRECTORY)/include/GL/gl.h \
+ $(DIRECTORY)/include/GL/glext.h \
+ $(DIRECTORY)/include/GL/gl_mangle.h \
+ $(DIRECTORY)/include/GL/glu.h \
+ $(DIRECTORY)/include/GL/glu_mangle.h \
+ $(DIRECTORY)/include/GL/glx.h \
+ $(DIRECTORY)/include/GL/glxext.h \
+ $(DIRECTORY)/include/GL/glx_mangle.h \
+ $(DIRECTORY)/include/GL/glfbdev.h \
+ $(DIRECTORY)/include/GL/mesa_wgl.h \
+ $(DIRECTORY)/include/GL/osmesa.h \
+ $(DIRECTORY)/include/GL/vms_x_fix.h \
+ $(DIRECTORY)/include/GL/wglext.h \
+ $(DIRECTORY)/include/GL/wmesa.h \
+ $(DIRECTORY)/src/glsl/Makefile \
+ $(DIRECTORY)/src/glsl/Makefile.template \
+ $(DIRECTORY)/src/glsl/SConscript \
+ $(DIRECTORY)/src/glsl/*.[ch] \
+ $(DIRECTORY)/src/glsl/*.[cly]pp \
+ $(DIRECTORY)/src/glsl/README \
+ $(DIRECTORY)/src/glsl/glcpp/*.[chly] \
+ $(DIRECTORY)/src/glsl/glcpp/README \
+ $(DIRECTORY)/src/glsl/builtins \
+ $(DIRECTORY)/src/Makefile \
+ $(DIRECTORY)/src/mesa/Makefile* \
+ $(DIRECTORY)/src/mesa/sources.mak \
+ $(DIRECTORY)/src/mesa/descrip.mms \
+ $(DIRECTORY)/src/mesa/gl.pc.in \
+ $(DIRECTORY)/src/mesa/osmesa.pc.in \
+ $(DIRECTORY)/src/mesa/depend \
+ $(MAIN_ES_FILES) \
+ $(DIRECTORY)/src/mesa/main/*.[chS] \
+ $(DIRECTORY)/src/mesa/main/descrip.mms \
+ $(DIRECTORY)/src/mesa/math/*.[ch] \
+ $(DIRECTORY)/src/mesa/math/descrip.mms \
+ $(DIRECTORY)/src/mesa/program/*.[chly] \
+ $(DIRECTORY)/src/mesa/program/*.cpp \
+ $(DIRECTORY)/src/mesa/program/Makefile \
+ $(DIRECTORY)/src/mesa/program/descrip.mms \
+ $(DIRECTORY)/src/mesa/swrast/*.[ch] \
+ $(DIRECTORY)/src/mesa/swrast/descrip.mms \
+ $(DIRECTORY)/src/mesa/swrast_setup/*.[ch] \
+ $(DIRECTORY)/src/mesa/swrast_setup/descrip.mms \
+ $(DIRECTORY)/src/mesa/vbo/*.[chS] \
+ $(DIRECTORY)/src/mesa/vbo/descrip.mms \
+ $(DIRECTORY)/src/mesa/tnl/*.[chS] \
+ $(DIRECTORY)/src/mesa/tnl/descrip.mms \
+ $(DIRECTORY)/src/mesa/tnl_dd/*.[ch] \
+ $(DIRECTORY)/src/mesa/tnl_dd/imm/*.[ch] \
+ $(DIRECTORY)/src/mesa/tnl_dd/imm/NOTES.imm \
+ $(DIRECTORY)/src/mesa/drivers/Makefile \
+ $(DIRECTORY)/src/mesa/drivers/beos/*.cpp \
+ $(DIRECTORY)/src/mesa/drivers/beos/Makefile \
+ $(DIRECTORY)/src/mesa/drivers/common/*.[ch] \
+ $(DIRECTORY)/src/mesa/drivers/common/descrip.mms \
+ $(DIRECTORY)/src/mesa/drivers/fbdev/Makefile \
+ $(DIRECTORY)/src/mesa/drivers/fbdev/glfbdev.c \
+ $(DIRECTORY)/src/mesa/drivers/osmesa/Makefile \
+ $(DIRECTORY)/src/mesa/drivers/osmesa/Makefile.win \
+ $(DIRECTORY)/src/mesa/drivers/osmesa/descrip.mms \
+ $(DIRECTORY)/src/mesa/drivers/osmesa/osmesa.def \
+ $(DIRECTORY)/src/mesa/drivers/osmesa/*.[ch] \
+ $(DIRECTORY)/src/mesa/drivers/windows/*/*.[ch] \
+ $(DIRECTORY)/src/mesa/drivers/windows/*/*.def \
+ $(DIRECTORY)/src/mesa/drivers/x11/Makefile \
+ $(DIRECTORY)/src/mesa/drivers/x11/descrip.mms \
+ $(DIRECTORY)/src/mesa/drivers/x11/*.[ch] \
+ $(DIRECTORY)/src/mesa/ppc/*.[ch] \
+ $(DIRECTORY)/src/mesa/sparc/*.[chS] \
+ $(DIRECTORY)/src/mesa/x86/Makefile \
+ $(DIRECTORY)/src/mesa/x86/*.[ch] \
+ $(DIRECTORY)/src/mesa/x86/*.S \
+ $(DIRECTORY)/src/mesa/x86/rtasm/*.[ch] \
+ $(DIRECTORY)/src/mesa/x86-64/*.[chS] \
+ $(DIRECTORY)/src/mesa/x86-64/Makefile
+
+MAPI_FILES = \
+ $(DIRECTORY)/include/GLES/*.h \
+ $(DIRECTORY)/include/GLES2/*.h \
+ $(DIRECTORY)/include/VG/*.h \
+ $(DIRECTORY)/src/mapi/es?api/Makefile \
+ $(DIRECTORY)/src/mapi/es?api/*.pc.in \
+ $(DIRECTORY)/src/mapi/glapi/gen/Makefile \
+ $(DIRECTORY)/src/mapi/glapi/gen/*.xml \
+ $(DIRECTORY)/src/mapi/glapi/gen/*.py \
+ $(DIRECTORY)/src/mapi/glapi/gen/*.dtd \
+ $(DIRECTORY)/src/mapi/glapi/gen-es/Makefile \
+ $(DIRECTORY)/src/mapi/glapi/gen-es/*.xml \
+ $(DIRECTORY)/src/mapi/glapi/gen-es/*.py \
+ $(DIRECTORY)/src/mapi/glapi/Makefile \
+ $(DIRECTORY)/src/mapi/glapi/SConscript \
+ $(DIRECTORY)/src/mapi/glapi/sources.mak \
+ $(DIRECTORY)/src/mapi/glapi/*.[chS] \
+ $(DIRECTORY)/src/mapi/mapi/mapi_abi.py \
+ $(DIRECTORY)/src/mapi/mapi/sources.mak \
+ $(DIRECTORY)/src/mapi/mapi/*.[ch] \
+ $(DIRECTORY)/src/mapi/vgapi/Makefile \
+ $(DIRECTORY)/src/mapi/vgapi/vgapi.csv \
+ $(DIRECTORY)/src/mapi/vgapi/vg.pc.in
+
+EGL_FILES = \
+ $(DIRECTORY)/include/KHR/*.h \
+ $(DIRECTORY)/include/EGL/*.h \
+ $(DIRECTORY)/src/egl/Makefile \
+ $(DIRECTORY)/src/egl/*/Makefile \
+ $(DIRECTORY)/src/egl/*/Makefile.template \
+ $(DIRECTORY)/src/egl/*/*.[ch] \
+ $(DIRECTORY)/src/egl/*/*/Makefile \
+ $(DIRECTORY)/src/egl/*/*/*.[ch] \
+ $(DIRECTORY)/src/egl/main/*.pc.in \
+ $(DIRECTORY)/src/egl/main/*.def
+
+GALLIUM_FILES = \
+ $(DIRECTORY)/src/mesa/state_tracker/*[ch] \
+ $(DIRECTORY)/src/gallium/Makefile \
+ $(DIRECTORY)/src/gallium/Makefile.template \
+ $(DIRECTORY)/src/gallium/SConscript \
+ $(DIRECTORY)/src/gallium/targets/Makefile.dri \
+ $(DIRECTORY)/src/gallium/targets/Makefile.xorg \
+ $(DIRECTORY)/src/gallium/targets/SConscript.dri \
+ $(DIRECTORY)/src/gallium/*/Makefile \
+ $(DIRECTORY)/src/gallium/*/SConscript \
+ $(DIRECTORY)/src/gallium/*/*/Makefile \
+ $(DIRECTORY)/src/gallium/*/*/SConscript \
+ $(DIRECTORY)/src/gallium/*/*/*.[ch] \
+ $(DIRECTORY)/src/gallium/auxiliary/gallivm/*.cpp \
+ $(DIRECTORY)/src/gallium/*/*/*.py \
+ $(DIRECTORY)/src/gallium/*/*/*.csv \
+ $(DIRECTORY)/src/gallium/*/*/*/Makefile \
+ $(DIRECTORY)/src/gallium/*/*/*/SConscript \
+ $(DIRECTORY)/src/gallium/*/*/*/*.[ch] \
+ $(DIRECTORY)/src/gallium/*/*/*/*.py
+
+
+DRI_FILES = \
+ $(DIRECTORY)/include/GL/internal/dri_interface.h \
+ $(DIRECTORY)/include/GL/internal/sarea.h \
+ $(DIRECTORY)/src/glx/Makefile \
+ $(DIRECTORY)/src/glx/*.[ch] \
+ $(DIRECTORY)/src/mesa/drivers/dri/Makefile \
+ $(DIRECTORY)/src/mesa/drivers/dri/Makefile.template \
+ $(DIRECTORY)/src/mesa/drivers/dri/dri.pc.in \
+ $(DIRECTORY)/src/mesa/drivers/dri/common/xmlpool/*.po \
+ $(DIRECTORY)/src/mesa/drivers/dri/*/*.[chS] \
+ $(DIRECTORY)/src/mesa/drivers/dri/*/*.cpp \
+ $(DIRECTORY)/src/mesa/drivers/dri/*/*/*.[chS] \
+ $(DIRECTORY)/src/mesa/drivers/dri/*/Makefile \
+ $(DIRECTORY)/src/mesa/drivers/dri/*/*/Makefile \
+ $(DIRECTORY)/src/mesa/drivers/dri/*/Doxyfile
+
+SGI_GLU_FILES = \
+ $(DIRECTORY)/src/glu/Makefile \
+ $(DIRECTORY)/src/glu/glu.pc.in \
+ $(DIRECTORY)/src/glu/sgi/Makefile \
+ $(DIRECTORY)/src/glu/sgi/Makefile.mgw \
+ $(DIRECTORY)/src/glu/sgi/Makefile.win \
+ $(DIRECTORY)/src/glu/sgi/glu.def \
+ $(DIRECTORY)/src/glu/sgi/dummy.cc \
+ $(DIRECTORY)/src/glu/sgi/glu.exports \
+ $(DIRECTORY)/src/glu/sgi/glu.exports.darwin \
+ $(DIRECTORY)/src/glu/sgi/mesaglu.opt \
+ $(DIRECTORY)/src/glu/sgi/include/gluos.h \
+ $(DIRECTORY)/src/glu/sgi/libnurbs/interface/*.h \
+ $(DIRECTORY)/src/glu/sgi/libnurbs/interface/*.cc \
+ $(DIRECTORY)/src/glu/sgi/libnurbs/internals/*.h \
+ $(DIRECTORY)/src/glu/sgi/libnurbs/internals/*.cc \
+ $(DIRECTORY)/src/glu/sgi/libnurbs/nurbtess/*.h \
+ $(DIRECTORY)/src/glu/sgi/libnurbs/nurbtess/*.cc \
+ $(DIRECTORY)/src/glu/sgi/libtess/README \
+ $(DIRECTORY)/src/glu/sgi/libtess/alg-outline \
+ $(DIRECTORY)/src/glu/sgi/libtess/*.[ch] \
+ $(DIRECTORY)/src/glu/sgi/libutil/*.[ch]
+
+GLW_FILES = \
+ $(DIRECTORY)/src/glw/*.[ch] \
+ $(DIRECTORY)/src/glw/Makefile* \
+ $(DIRECTORY)/src/glw/README \
+ $(DIRECTORY)/src/glw/glw.pc.in \
+ $(DIRECTORY)/src/glw/depend
+
+GLUT_FILES = \
+ $(DIRECTORY)/include/GL/glut.h \
+ $(DIRECTORY)/include/GL/glutf90.h \
+ $(DIRECTORY)/src/glut/glx/Makefile* \
+ $(DIRECTORY)/src/glut/glx/depend \
+ $(DIRECTORY)/src/glut/glx/glut.pc.in \
+ $(DIRECTORY)/src/glut/glx/*def \
+ $(DIRECTORY)/src/glut/glx/*.[ch] \
+ $(DIRECTORY)/src/glut/beos/*.[ch] \
+ $(DIRECTORY)/src/glut/beos/*.cpp \
+ $(DIRECTORY)/src/glut/beos/Makefile
+
+DEPEND_FILES = \
+ $(TOP)/src/mesa/depend \
+ $(TOP)/src/glx/depend \
+ $(TOP)/src/glw/depend \
+ $(TOP)/src/glut/glx/depend \
+ $(TOP)/src/glu/sgi/depend
+
+
+LIB_FILES = \
+ $(MAIN_FILES) \
+ $(MAPI_FILES) \
+ $(ES_FILES) \
+ $(EGL_FILES) \
+ $(GALLIUM_FILES) \
+ $(DRI_FILES) \
+ $(SGI_GLU_FILES) \
+ $(GLW_FILES)
+
+
+parsers: configure
+ -@touch $(TOP)/configs/current
+ $(MAKE) -C src/glsl glsl_parser.cpp glsl_parser.h glsl_lexer.cpp
+ $(MAKE) -C src/glsl/glcpp glcpp-lex.c glcpp-parse.c glcpp-parse.h
+ $(MAKE) -C src/mesa/program lex.yy.c program_parse.tab.c program_parse.tab.h
+
+# Everything for new a Mesa release:
+ARCHIVES = $(LIB_NAME).tar.gz \
+ $(LIB_NAME).tar.bz2 \
+ $(LIB_NAME).zip \
+ $(GLUT_NAME).tar.gz \
+ $(GLUT_NAME).tar.bz2 \
+ $(GLUT_NAME).zip
+
+tarballs: md5
+ rm -f ../$(LIB_NAME).tar
+
+# Helper for autoconf builds
+ACLOCAL = aclocal
+ACLOCAL_FLAGS =
+AUTOCONF = autoconf
+AC_FLAGS =
+aclocal.m4: configure.ac acinclude.m4
+ $(ACLOCAL) $(ACLOCAL_FLAGS)
+configure: rm_depend configure.ac aclocal.m4 acinclude.m4
+ $(AUTOCONF) $(AC_FLAGS)
+
+rm_depend:
+ @for dep in $(DEPEND_FILES) ; do \
+ rm -f $$dep ; \
+ touch $$dep ; \
+ done
+
+rm_config: parsers
+ rm -f configs/current
+ rm -f configs/autoconf
+
+$(LIB_NAME).tar: rm_config
+ cd .. ; tar -cf $(DIRECTORY)/$(LIB_NAME).tar $(LIB_FILES)
+
+$(LIB_NAME).tar.gz: $(LIB_NAME).tar
+ gzip --stdout --best $(LIB_NAME).tar > $(LIB_NAME).tar.gz
+
+$(GLUT_NAME).tar: rm_depend
+ cd .. ; tar -cf $(DIRECTORY)/$(GLUT_NAME).tar $(GLUT_FILES)
+
+$(GLUT_NAME).tar.gz: $(GLUT_NAME).tar
+ gzip --stdout --best $(GLUT_NAME).tar > $(GLUT_NAME).tar.gz
+
+$(LIB_NAME).tar.bz2: $(LIB_NAME).tar
+ bzip2 --stdout --best $(LIB_NAME).tar > $(LIB_NAME).tar.bz2
+
+$(GLUT_NAME).tar.bz2: $(GLUT_NAME).tar
+ bzip2 --stdout --best $(GLUT_NAME).tar > $(GLUT_NAME).tar.bz2
+
+$(LIB_NAME).zip: rm_config
+ rm -f $(LIB_NAME).zip ; \
+ cd .. ; \
+ zip -qr $(LIB_NAME).zip $(LIB_FILES) ; \
+ mv $(LIB_NAME).zip $(DIRECTORY)
+
+$(GLUT_NAME).zip:
+ rm -f $(GLUT_NAME).zip ; \
+ cd .. ; \
+ zip -qr $(GLUT_NAME).zip $(GLUT_FILES) ; \
+ mv $(GLUT_NAME).zip $(DIRECTORY)
+
+md5: $(ARCHIVES)
+ @-md5sum $(LIB_NAME).tar.gz
+ @-md5sum $(LIB_NAME).tar.bz2
+ @-md5sum $(LIB_NAME).zip
+ @-md5sum $(GLUT_NAME).tar.gz
+ @-md5sum $(GLUT_NAME).tar.bz2
+ @-md5sum $(GLUT_NAME).zip
+
+.PHONY: tarballs rm_depend rm_config md5
diff --git a/mesalib/common.py b/mesalib/common.py
index 1d0c6a71f..157873f66 100644
--- a/mesalib/common.py
+++ b/mesalib/common.py
@@ -1,92 +1,92 @@
-#######################################################################
-# Common SCons code
-
-import os
-import os.path
-import re
-import subprocess
-import sys
-import platform as _platform
-
-import SCons.Script.SConscript
-
-
-#######################################################################
-# Defaults
-
-host_platform = _platform.system().lower()
-if host_platform.startswith('cygwin'):
- host_platform = 'cygwin'
-
-# Search sys.argv[] for a "platform=foo" argument since we don't have
-# an 'env' variable at this point.
-if 'platform' in SCons.Script.ARGUMENTS:
- target_platform = SCons.Script.ARGUMENTS['platform']
-else:
- target_platform = host_platform
-
-_machine_map = {
- 'x86': 'x86',
- 'i386': 'x86',
- 'i486': 'x86',
- 'i586': 'x86',
- 'i686': 'x86',
- 'ppc' : 'ppc',
- 'AMD64': 'x86_64',
- 'x86_64': 'x86_64',
-}
-
-
-# find host_machine value
-if 'PROCESSOR_ARCHITECTURE' in os.environ:
- host_machine = os.environ['PROCESSOR_ARCHITECTURE']
-else:
- host_machine = _platform.machine()
-host_machine = _machine_map.get(host_machine, 'generic')
-
-default_machine = host_machine
-default_toolchain = 'default'
-
-if target_platform == 'windows' and host_platform != 'windows':
- default_machine = 'x86'
- default_toolchain = 'crossmingw'
-
-
-# find default_llvm value
-if 'LLVM' in os.environ:
- default_llvm = 'yes'
-else:
- default_llvm = 'no'
- try:
- if target_platform != 'windows' and \
- subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
- default_llvm = 'yes'
- except:
- pass
-
-
-#######################################################################
-# Common options
-
-def AddOptions(opts):
- try:
- from SCons.Variables.BoolVariable import BoolVariable as BoolOption
- except ImportError:
- from SCons.Options.BoolOption import BoolOption
- try:
- from SCons.Variables.EnumVariable import EnumVariable as EnumOption
- except ImportError:
- from SCons.Options.EnumOption import EnumOption
- opts.Add(EnumOption('build', 'build type', 'debug',
- allowed_values=('debug', 'checked', 'profile', 'release')))
- opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
- opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
- allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
- opts.Add(EnumOption('platform', 'target platform', host_platform,
- allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8')))
- opts.Add('toolchain', 'compiler toolchain', default_toolchain)
- opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no'))
- opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
- opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
- opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
- opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))
+#######################################################################
+# Common SCons code
+
+import os
+import os.path
+import re
+import subprocess
+import sys
+import platform as _platform
+
+import SCons.Script.SConscript
+
+
+#######################################################################
+# Defaults
+
+host_platform = _platform.system().lower()
+if host_platform.startswith('cygwin'):
+ host_platform = 'cygwin'
+
+# Search sys.argv[] for a "platform=foo" argument since we don't have
+# an 'env' variable at this point.
+if 'platform' in SCons.Script.ARGUMENTS:
+ target_platform = SCons.Script.ARGUMENTS['platform']
+else:
+ target_platform = host_platform
+
+_machine_map = {
+ 'x86': 'x86',
+ 'i386': 'x86',
+ 'i486': 'x86',
+ 'i586': 'x86',
+ 'i686': 'x86',
+ 'ppc' : 'ppc',
+ 'AMD64': 'x86_64',
+ 'x86_64': 'x86_64',
+}
+
+
+# find host_machine value
+if 'PROCESSOR_ARCHITECTURE' in os.environ:
+ host_machine = os.environ['PROCESSOR_ARCHITECTURE']
+else:
+ host_machine = _platform.machine()
+host_machine = _machine_map.get(host_machine, 'generic')
+
+default_machine = host_machine
+default_toolchain = 'default'
+
+if target_platform == 'windows' and host_platform != 'windows':
+ default_machine = 'x86'
+ default_toolchain = 'crossmingw'
+
+
+# find default_llvm value
+if 'LLVM' in os.environ:
+ default_llvm = 'yes'
+else:
+ default_llvm = 'no'
+ try:
+ if target_platform != 'windows' and \
+ subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
+ default_llvm = 'yes'
+ except:
+ pass
+
+
+#######################################################################
+# Common options
+
+def AddOptions(opts):
+ try:
+ from SCons.Variables.BoolVariable import BoolVariable as BoolOption
+ except ImportError:
+ from SCons.Options.BoolOption import BoolOption
+ try:
+ from SCons.Variables.EnumVariable import EnumVariable as EnumOption
+ except ImportError:
+ from SCons.Options.EnumOption import EnumOption
+ opts.Add(EnumOption('build', 'build type', 'debug',
+ allowed_values=('debug', 'checked', 'profile', 'release')))
+ opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
+ opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
+ allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
+ opts.Add(EnumOption('platform', 'target platform', host_platform,
+ allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8')))
+ opts.Add('toolchain', 'compiler toolchain', default_toolchain)
+ opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no'))
+ opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
+ opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
+ opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
+ opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))
diff --git a/mesalib/configure.ac b/mesalib/configure.ac
index 9fa5eeea1..2dee7a7da 100644
--- a/mesalib/configure.ac
+++ b/mesalib/configure.ac
@@ -1,1910 +1,1910 @@
-dnl Process this file with autoconf to create configure.
-
-AC_PREREQ([2.59])
-
-dnl Versioning - scrape the version from configs/default
-m4_define([mesa_version],
- [m4_esyscmd([${MAKE-make} -s -f bin/version.mk version | tr -d '\n' | tr -d '\r'])])
-m4_ifval(mesa_version,,
- [m4_fatal([Failed to get the Mesa version from `make -f bin/version.mk version`])])
-
-dnl Tell the user about autoconf.html in the --help output
-m4_divert_once([HELP_END], [
-See docs/autoconf.html for more details on the options for Mesa.])
-
-AC_INIT([Mesa],[mesa_version],
- [https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa])
-AC_CONFIG_AUX_DIR([bin])
-AC_CANONICAL_HOST
-
-dnl Versions for external dependencies
-LIBDRM_REQUIRED=2.4.24
-LIBDRM_RADEON_REQUIRED=2.4.24
-LIBDRM_INTEL_REQUIRED=2.4.24
-DRI2PROTO_REQUIRED=2.1
-GLPROTO_REQUIRED=1.4.11
-LIBDRM_XORG_REQUIRED=2.4.24
-LIBKMS_XORG_REQUIRED=1.0.0
-
-dnl Check for progs
-AC_PROG_CPP
-AC_PROG_CC
-AC_PROG_CXX
-AC_CHECK_PROGS([MAKE], [gmake make])
-AC_CHECK_PROGS([PYTHON2], [python2 python])
-AC_PATH_PROG([MKDEP], [makedepend])
-AC_PATH_PROG([SED], [sed])
-
-if test "x$MKDEP" = "x"; then
- AC_MSG_ERROR([makedepend is required to build Mesa])
-fi
-
-dnl Our fallback install-sh is a symlink to minstall. Use the existing
-dnl configuration in that case.
-AC_PROG_INSTALL
-test "x$INSTALL" = "x$ac_install_sh" && INSTALL='$(MINSTALL)'
-
-dnl We need a POSIX shell for parts of the build. Assume we have one
-dnl in most cases.
-case "$host_os" in
-solaris*)
- # Solaris /bin/sh is too old/non-POSIX compliant
- AC_PATH_PROGS(POSIX_SHELL, [ksh93 ksh sh])
- SHELL="$POSIX_SHELL"
- ;;
-esac
-
-dnl clang is mostly GCC-compatible, but its version is much lower,
-dnl so we have to check for it.
-AC_MSG_CHECKING([if compiling with clang])
-
-AC_COMPILE_IFELSE(
-[AC_LANG_PROGRAM([], [[
-#ifndef __clang__
- not clang
-#endif
-]])],
-[CLANG=yes], [CLANG=no])
-
-AC_MSG_RESULT([$CLANG])
-
-dnl If we're using GCC, make sure that it is at least version 3.3.0. Older
-dnl versions are explictly not supported.
-if test "x$GCC" = xyes -a "x$CLANG" = xno; then
- AC_MSG_CHECKING([whether gcc version is sufficient])
- major=0
- minor=0
-
- GCC_VERSION=`$CC -dumpversion`
- if test $? -eq 0; then
- major=`echo $GCC_VERSION | cut -d. -f1`
- minor=`echo $GCC_VERSION | cut -d. -f1`
- fi
-
- if test $major -lt 3 -o $major -eq 3 -a $minor -lt 3 ; then
- AC_MSG_RESULT([no])
- AC_MSG_ERROR([If using GCC, version 3.3.0 or later is required.])
- else
- AC_MSG_RESULT([yes])
- fi
-fi
-
-
-MKDEP_OPTIONS=-fdepend
-dnl Ask gcc where it's keeping its secret headers
-if test "x$GCC" = xyes; then
- for dir in include include-fixed; do
- GCC_INCLUDES=`$CC -print-file-name=$dir`
- if test "x$GCC_INCLUDES" != x && \
- test "$GCC_INCLUDES" != "$dir" && \
- test -d "$GCC_INCLUDES"; then
- MKDEP_OPTIONS="$MKDEP_OPTIONS -I$GCC_INCLUDES"
- fi
- done
-fi
-AC_SUBST([MKDEP_OPTIONS])
-
-dnl Make sure the pkg-config macros are defined
-m4_ifndef([PKG_PROG_PKG_CONFIG],
- [m4_fatal([Could not locate the pkg-config autoconf macros.
- These are usually located in /usr/share/aclocal/pkg.m4. If your macros
- are in a different location, try setting the environment variable
- ACLOCAL="aclocal -I/other/macro/dir" before running autoreconf.])])
-PKG_PROG_PKG_CONFIG()
-
-dnl LIB_DIR - library basename
-LIB_DIR=`echo $libdir | $SED 's%.*/%%'`
-AC_SUBST([LIB_DIR])
-
-dnl Cache LDFLAGS so we can add EXTRA_LIB_PATH and restore it later
-_SAVE_LDFLAGS="$LDFLAGS"
-AC_ARG_VAR([EXTRA_LIB_PATH],[Extra -L paths for the linker])
-AC_SUBST([EXTRA_LIB_PATH])
-
-dnl Cache CPPFLAGS so we can add *_INCLUDES and restore it later
-_SAVE_CPPFLAGS="$CPPFLAGS"
-AC_ARG_VAR([X11_INCLUDES],[Extra -I paths for X11 headers])
-AC_SUBST([X11_INCLUDES])
-
-dnl Compiler macros
-DEFINES=""
-AC_SUBST([DEFINES])
-case "$host_os" in
-linux*|*-gnu*|gnu*)
- DEFINES="$DEFINES -D_GNU_SOURCE -DPTHREADS"
- ;;
-solaris*)
- DEFINES="$DEFINES -DPTHREADS -DSVR4"
- ;;
-cygwin*)
- DEFINES="$DEFINES -DPTHREADS"
- ;;
-esac
-
-dnl Add flags for gcc and g++
-if test "x$GCC" = xyes; then
- CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -std=c99"
- if test "x$CLANG" = "xno"; then
- CFLAGS="$CFLAGS -ffast-math"
- fi
-
- # Enable -fvisibility=hidden if using a gcc that supports it
- save_CFLAGS="$CFLAGS"
- AC_MSG_CHECKING([whether $CC supports -fvisibility=hidden])
- VISIBILITY_CFLAGS="-fvisibility=hidden"
- CFLAGS="$CFLAGS $VISIBILITY_CFLAGS"
- AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]),
- [VISIBILITY_CFLAGS=""; AC_MSG_RESULT([no])]);
-
- # Restore CFLAGS; VISIBILITY_CFLAGS are added to it where needed.
- CFLAGS=$save_CFLAGS
-
- # Work around aliasing bugs - developers should comment this out
- CFLAGS="$CFLAGS -fno-strict-aliasing"
-fi
-if test "x$GXX" = xyes; then
- CXXFLAGS="$CXXFLAGS -Wall"
-
- # Enable -fvisibility=hidden if using a gcc that supports it
- save_CXXFLAGS="$CXXFLAGS"
- AC_MSG_CHECKING([whether $CXX supports -fvisibility=hidden])
- VISIBILITY_CXXFLAGS="-fvisibility=hidden"
- CXXFLAGS="$CXXFLAGS $VISIBILITY_CXXFLAGS"
- AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]),
- [VISIBILITY_CXXFLAGS="" ; AC_MSG_RESULT([no])]);
-
- # Restore CXXFLAGS; VISIBILITY_CXXFLAGS are added to it where needed.
- CXXFLAGS=$save_CXXFLAGS
-
- # Work around aliasing bugs - developers should comment this out
- CXXFLAGS="$CXXFLAGS -fno-strict-aliasing"
-fi
-
-AC_SUBST([VISIBILITY_CFLAGS])
-AC_SUBST([VISIBILITY_CXXFLAGS])
-
-dnl These should be unnecessary, but let the user set them if they want
-AC_ARG_VAR([OPT_FLAGS], [Additional optimization flags for the compiler.
- Default is to use CFLAGS.])
-AC_ARG_VAR([ARCH_FLAGS], [Additional architecture specific flags for the
- compiler. Default is to use CFLAGS.])
-AC_SUBST([OPT_FLAGS])
-AC_SUBST([ARCH_FLAGS])
-
-dnl
-dnl Hacks to enable 32 or 64 bit build
-dnl
-AC_ARG_ENABLE([32-bit],
- [AS_HELP_STRING([--enable-32-bit],
- [build 32-bit libraries @<:@default=auto@:>@])],
- [enable_32bit="$enableval"],
- [enable_32bit=auto]
-)
-if test "x$enable_32bit" = xyes; then
- if test "x$GCC" = xyes; then
- CFLAGS="$CFLAGS -m32"
- ARCH_FLAGS="$ARCH_FLAGS -m32"
- fi
- if test "x$GXX" = xyes; then
- CXXFLAGS="$CXXFLAGS -m32"
- fi
-fi
-AC_ARG_ENABLE([64-bit],
- [AS_HELP_STRING([--enable-64-bit],
- [build 64-bit libraries @<:@default=auto@:>@])],
- [enable_64bit="$enableval"],
- [enable_64bit=auto]
-)
-if test "x$enable_64bit" = xyes; then
- if test "x$GCC" = xyes; then
- CFLAGS="$CFLAGS -m64"
- fi
- if test "x$GXX" = xyes; then
- CXXFLAGS="$CXXFLAGS -m64"
- fi
-fi
-
-dnl
-dnl shared/static libraries, mimic libtool options
-dnl
-AC_ARG_ENABLE([static],
- [AS_HELP_STRING([--enable-static],
- [build static libraries @<:@default=disabled@:>@])],
- [enable_static="$enableval"],
- [enable_static=no]
-)
-case "x$enable_static" in
-xyes|xno ) ;;
-x ) enable_static=no ;;
-* )
- AC_MSG_ERROR([Static library option '$enable_static' is not a valid])
- ;;
-esac
-AC_ARG_ENABLE([shared],
- [AS_HELP_STRING([--disable-shared],
- [build shared libraries @<:@default=enabled@:>@])],
- [enable_shared="$enableval"],
- [enable_shared=yes]
-)
-case "x$enable_shared" in
-xyes|xno ) ;;
-x ) enable_shared=yes ;;
-* )
- AC_MSG_ERROR([Shared library option '$enable_shared' is not a valid])
- ;;
-esac
-
-dnl Can't have static and shared libraries, default to static if user
-dnl explicitly requested. If both disabled, set to static since shared
-dnl was explicitly requirested.
-case "x$enable_static$enable_shared" in
-xyesyes )
- AC_MSG_WARN([Can't build static and shared libraries, disabling shared])
- enable_shared=no
- ;;
-xnono )
- AC_MSG_WARN([Can't disable both static and shared libraries, enabling static])
- enable_static=yes
- ;;
-esac
-
-dnl
-dnl mklib options
-dnl
-AC_ARG_VAR([MKLIB_OPTIONS],[Options for the Mesa library script, mklib])
-if test "$enable_static" = yes; then
- MKLIB_OPTIONS="$MKLIB_OPTIONS -static"
-fi
-AC_SUBST([MKLIB_OPTIONS])
-
-dnl
-dnl other compiler options
-dnl
-AC_ARG_ENABLE([debug],
- [AS_HELP_STRING([--enable-debug],
- [use debug compiler flags and macros @<:@default=disabled@:>@])],
- [enable_debug="$enableval"],
- [enable_debug=no]
-)
-if test "x$enable_debug" = xyes; then
- DEFINES="$DEFINES -DDEBUG"
- if test "x$GCC" = xyes; then
- CFLAGS="$CFLAGS -g"
- fi
- if test "x$GXX" = xyes; then
- CXXFLAGS="$CXXFLAGS -g"
- fi
-fi
-
-dnl
-dnl library names
-dnl
-LIB_PREFIX_GLOB='lib'
-LIB_VERSION_SEPARATOR='.'
-if test "$enable_static" = yes; then
- LIB_EXTENSION='a'
-else
- case "$host_os" in
- darwin* )
- LIB_EXTENSION='dylib' ;;
- cygwin* )
- dnl prefix can be 'cyg' or 'lib'
- LIB_PREFIX_GLOB='???'
- LIB_VERSION_SEPARATOR='-'
- LIB_EXTENSION='dll' ;;
- aix* )
- LIB_EXTENSION='a' ;;
- * )
- LIB_EXTENSION='so' ;;
- esac
-fi
-
-GL_LIB_NAME='lib$(GL_LIB).'${LIB_EXTENSION}
-GLU_LIB_NAME='lib$(GLU_LIB).'${LIB_EXTENSION}
-GLUT_LIB_NAME='lib$(GLUT_LIB).'${LIB_EXTENSION}
-GLW_LIB_NAME='lib$(GLW_LIB).'${LIB_EXTENSION}
-OSMESA_LIB_NAME='lib$(OSMESA_LIB).'${LIB_EXTENSION}
-EGL_LIB_NAME='lib$(EGL_LIB).'${LIB_EXTENSION}
-GLESv1_CM_LIB_NAME='lib$(GLESv1_CM_LIB).'${LIB_EXTENSION}
-GLESv2_LIB_NAME='lib$(GLESv2_LIB).'${LIB_EXTENSION}
-VG_LIB_NAME='lib$(VG_LIB).'${LIB_EXTENSION}
-GLAPI_LIB_NAME='lib$(GLAPI_LIB).'${LIB_EXTENSION}
-WAYLAND_EGL_LIB_NAME='lib$(WAYLAND_EGL_LIB).'${LIB_EXTENSION}
-
-GL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-GLU_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLU_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-GLUT_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLUT_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-GLW_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLW_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-OSMESA_LIB_GLOB=${LIB_PREFIX_GLOB}'$(OSMESA_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-EGL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(EGL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-EGL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(EGL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-GLESv1_CM_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLESv1_CM_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-GLESv2_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLESv2_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-VG_LIB_GLOB=${LIB_PREFIX_GLOB}'$(VG_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-GLAPI_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLAPI_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-WAYLAND_EGL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(WAYLAND_EGL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
-
-AC_SUBST([GL_LIB_NAME])
-AC_SUBST([GLU_LIB_NAME])
-AC_SUBST([GLUT_LIB_NAME])
-AC_SUBST([GLW_LIB_NAME])
-AC_SUBST([OSMESA_LIB_NAME])
-AC_SUBST([EGL_LIB_NAME])
-AC_SUBST([GLESv1_CM_LIB_NAME])
-AC_SUBST([GLESv2_LIB_NAME])
-AC_SUBST([VG_LIB_NAME])
-AC_SUBST([GLAPI_LIB_NAME])
-AC_SUBST([WAYLAND_EGL_LIB_NAME])
-
-AC_SUBST([GL_LIB_GLOB])
-AC_SUBST([GLU_LIB_GLOB])
-AC_SUBST([GLUT_LIB_GLOB])
-AC_SUBST([GLW_LIB_GLOB])
-AC_SUBST([OSMESA_LIB_GLOB])
-AC_SUBST([EGL_LIB_GLOB])
-AC_SUBST([GLESv1_CM_LIB_GLOB])
-AC_SUBST([GLESv2_LIB_GLOB])
-AC_SUBST([VG_LIB_GLOB])
-AC_SUBST([GLAPI_LIB_GLOB])
-AC_SUBST([WAYLAND_EGL_LIB_GLOB])
-
-dnl
-dnl Arch/platform-specific settings
-dnl
-AC_ARG_ENABLE([asm],
- [AS_HELP_STRING([--disable-asm],
- [disable assembly usage @<:@default=enabled on supported plaforms@:>@])],
- [enable_asm="$enableval"],
- [enable_asm=yes]
-)
-asm_arch=""
-ASM_FLAGS=""
-MESA_ASM_SOURCES=""
-GLAPI_ASM_SOURCES=""
-AC_MSG_CHECKING([whether to enable assembly])
-test "x$enable_asm" = xno && AC_MSG_RESULT([no])
-# disable if cross compiling on x86/x86_64 since we must run gen_matypes
-if test "x$enable_asm" = xyes && test "x$cross_compiling" = xyes; then
- case "$host_cpu" in
- i?86 | x86_64)
- enable_asm=no
- AC_MSG_RESULT([no, cross compiling])
- ;;
- esac
-fi
-# check for supported arches
-if test "x$enable_asm" = xyes; then
- case "$host_cpu" in
- i?86)
- case "$host_os" in
- linux* | *freebsd* | dragonfly* | *netbsd*)
- test "x$enable_64bit" = xyes && asm_arch=x86_64 || asm_arch=x86
- ;;
- esac
- ;;
- x86_64)
- case "$host_os" in
- linux* | *freebsd* | dragonfly* | *netbsd*)
- test "x$enable_32bit" = xyes && asm_arch=x86 || asm_arch=x86_64
- ;;
- esac
- ;;
- powerpc)
- case "$host_os" in
- linux*)
- asm_arch=ppc
- ;;
- esac
- ;;
- sparc*)
- case "$host_os" in
- linux*)
- asm_arch=sparc
- ;;
- esac
- ;;
- esac
-
- case "$asm_arch" in
- x86)
- ASM_FLAGS="-DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM"
- MESA_ASM_SOURCES='$(X86_SOURCES)'
- GLAPI_ASM_SOURCES='$(X86_API)'
- AC_MSG_RESULT([yes, x86])
- ;;
- x86_64)
- ASM_FLAGS="-DUSE_X86_64_ASM"
- MESA_ASM_SOURCES='$(X86-64_SOURCES)'
- GLAPI_ASM_SOURCES='$(X86-64_API)'
- AC_MSG_RESULT([yes, x86_64])
- ;;
- ppc)
- ASM_FLAGS="-DUSE_PPC_ASM -DUSE_VMX_ASM"
- MESA_ASM_SOURCES='$(PPC_SOURCES)'
- AC_MSG_RESULT([yes, ppc])
- ;;
- sparc)
- ASM_FLAGS="-DUSE_SPARC_ASM"
- MESA_ASM_SOURCES='$(SPARC_SOURCES)'
- GLAPI_ASM_SOURCES='$(SPARC_API)'
- AC_MSG_RESULT([yes, sparc])
- ;;
- *)
- AC_MSG_RESULT([no, platform not supported])
- ;;
- esac
-fi
-AC_SUBST([ASM_FLAGS])
-AC_SUBST([MESA_ASM_SOURCES])
-AC_SUBST([GLAPI_ASM_SOURCES])
-
-dnl PIC code macro
-MESA_PIC_FLAGS
-
-dnl Check to see if dlopen is in default libraries (like Solaris, which
-dnl has it in libc), or if libdl is needed to get it.
-AC_CHECK_FUNC([dlopen], [],
- [AC_CHECK_LIB([dl], [dlopen], [DLOPEN_LIBS="-ldl"])])
-AC_SUBST([DLOPEN_LIBS])
-
-dnl See if posix_memalign is available
-AC_CHECK_FUNC([posix_memalign], [DEFINES="$DEFINES -DHAVE_POSIX_MEMALIGN"])
-
-dnl SELinux awareness.
-AC_ARG_ENABLE([selinux],
- [AS_HELP_STRING([--enable-selinux],
- [Build SELinux-aware Mesa @<:@default=disabled@:>@])],
- [MESA_SELINUX="$enableval"],
- [MESA_SELINUX=no])
-if test "x$enable_selinux" = "xyes"; then
- AC_CHECK_HEADER([selinux/selinux.h],[],
- [AC_MSG_ERROR([SELinux headers not found])])
- AC_CHECK_LIB([selinux],[is_selinux_enabled],[],
- [AC_MSG_ERROR([SELinux library not found])])
- SELINUX_LIBS="-lselinux"
- DEFINES="$DEFINES -DMESA_SELINUX"
-fi
-
-dnl Determine which APIs to support
-AC_ARG_ENABLE([opengl],
- [AS_HELP_STRING([--disable-opengl],
- [disable support for standard OpenGL API @<:@default=no@:>@])],
- [enable_opengl="$enableval"],
- [enable_opengl=yes])
-AC_ARG_ENABLE([gles1],
- [AS_HELP_STRING([--enable-gles1],
- [enable support for OpenGL ES 1.x API @<:@default=no@:>@])],
- [enable_gles1="$enableval"],
- [enable_gles1=no])
-AC_ARG_ENABLE([gles2],
- [AS_HELP_STRING([--enable-gles2],
- [enable support for OpenGL ES 2.x API @<:@default=no@:>@])],
- [enable_gles2="$enableval"],
- [enable_gles2=no])
-AC_ARG_ENABLE([gles-overlay],
- [AS_HELP_STRING([--enable-gles-overlay],
- [DEPRECATED. Same as --enable-gles1 and --enable-gles2])],
- [enable_gles1="$enableval"; enable_gles2="$enableval"],
- [])
-
-AC_ARG_ENABLE([openvg],
- [AS_HELP_STRING([--enable-openvg],
- [enable support for OpenVG API @<:@default=no@:>@])],
- [enable_openvg="$enableval"],
- [enable_openvg=no])
-
-dnl smooth the transition; should be removed eventually
-if test "x$enable_openvg" = xno; then
- case "x$with_state_trackers" in
- x*vega*)
- AC_MSG_WARN([vega state tracker is enabled without --enable-openvg])
- enable_openvg=yes
- ;;
- esac
-fi
-
-if test "x$enable_opengl" = xno -a \
- "x$enable_gles1" = xno -a \
- "x$enable_gles2" = xno -a \
- "x$enable_openvg" = xno; then
- AC_MSG_ERROR([at least one API should be enabled])
-fi
-
-API_DEFINES=""
-if test "x$enable_opengl" = xno; then
- API_DEFINES="$API_DEFINES -DFEATURE_GL=0"
-else
- API_DEFINES="$API_DEFINES -DFEATURE_GL=1"
-fi
-if test "x$enable_gles1" = xyes; then
- API_DEFINES="$API_DEFINES -DFEATURE_ES1=1"
-fi
-if test "x$enable_gles2" = xyes; then
- API_DEFINES="$API_DEFINES -DFEATURE_ES2=1"
-fi
-AC_SUBST([API_DEFINES])
-
-AC_ARG_ENABLE([shared-glapi],
- [AS_HELP_STRING([--enable-shared-glapi],
- [EXPERIMENTAL. Enable shared glapi for OpenGL @<:@default=no@:>@])],
- [enable_shared_glapi="$enableval"],
- [enable_shared_glapi=no])
-
-SHARED_GLAPI="0"
-if test "x$enable_shared_glapi" = xyes; then
- SHARED_GLAPI="1"
-fi
-AC_SUBST([SHARED_GLAPI])
-
-dnl
-dnl Driver configuration. Options are xlib, dri and osmesa right now.
-dnl More later: fbdev, ...
-dnl
-default_driver="xlib"
-
-case "$host_os" in
-linux*)
- case "$host_cpu" in
- i*86|x86_64|powerpc*|sparc*) default_driver="dri";;
- esac
- ;;
-*freebsd* | dragonfly* | *netbsd*)
- case "$host_cpu" in
- i*86|x86_64|powerpc*|sparc*) default_driver="dri";;
- esac
- ;;
-esac
-
-if test "x$enable_opengl" = xno; then
- default_driver="no"
-fi
-
-AC_ARG_WITH([driver],
- [AS_HELP_STRING([--with-driver=DRIVER],
- [driver for Mesa: xlib,dri,osmesa @<:@default=dri when available, or xlib@:>@])],
- [mesa_driver="$withval"],
- [mesa_driver="$default_driver"])
-dnl Check for valid option
-case "x$mesa_driver" in
-xxlib|xdri|xosmesa)
- if test "x$enable_opengl" = xno; then
- AC_MSG_ERROR([Driver '$mesa_driver' requires OpenGL enabled])
- fi
- ;;
-xno)
- ;;
-*)
- AC_MSG_ERROR([Driver '$mesa_driver' is not a valid option])
- ;;
-esac
-
-dnl
-dnl Driver specific build directories
-dnl
-
-dnl this variable will be prepended to SRC_DIRS and is not exported
-CORE_DIRS=""
-
-SRC_DIRS=""
-GLU_DIRS="sgi"
-GALLIUM_DIRS="auxiliary drivers state_trackers"
-GALLIUM_TARGET_DIRS=""
-GALLIUM_WINSYS_DIRS="sw"
-GALLIUM_DRIVERS_DIRS="softpipe failover galahad trace rbug noop identity"
-GALLIUM_STATE_TRACKERS_DIRS=""
-
-# build shared-glapi if enabled for OpenGL or if OpenGL ES is enabled
-case "x$enable_shared_glapi$enable_gles1$enable_gles2" in
-x*yes*)
- CORE_DIRS="$CORE_DIRS mapi/shared-glapi"
- ;;
-esac
-
-# build glapi if OpenGL is enabled
-if test "x$enable_opengl" = xyes; then
- CORE_DIRS="$CORE_DIRS mapi/glapi"
-fi
-
-# build es1api if OpenGL ES 1.x is enabled
-if test "x$enable_gles1" = xyes; then
- CORE_DIRS="$CORE_DIRS mapi/es1api"
-fi
-
-# build es2api if OpenGL ES 2.x is enabled
-if test "x$enable_gles2" = xyes; then
- CORE_DIRS="$CORE_DIRS mapi/es2api"
-fi
-
-# build vgapi if OpenVG is enabled
-if test "x$enable_openvg" = xyes; then
- CORE_DIRS="$CORE_DIRS mapi/vgapi"
-fi
-
-# build glsl and mesa if OpenGL or OpenGL ES is enabled
-case "x$enable_opengl$enable_gles1$enable_gles2" in
-x*yes*)
- CORE_DIRS="$CORE_DIRS glsl mesa"
- ;;
-esac
-
-case "$mesa_driver" in
-xlib)
- DRIVER_DIRS="x11"
- GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib"
- GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS libgl-xlib"
- ;;
-dri)
- SRC_DIRS="$SRC_DIRS glx"
- DRIVER_DIRS="dri"
- GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/dri"
- ;;
-osmesa)
- DRIVER_DIRS="osmesa"
- ;;
-no)
- DRIVER_DRIS=""
- ;;
-esac
-AC_SUBST([SRC_DIRS])
-AC_SUBST([GLU_DIRS])
-AC_SUBST([DRIVER_DIRS])
-AC_SUBST([GALLIUM_DIRS])
-AC_SUBST([GALLIUM_TARGET_DIRS])
-AC_SUBST([GALLIUM_WINSYS_DIRS])
-AC_SUBST([GALLIUM_DRIVERS_DIRS])
-AC_SUBST([GALLIUM_STATE_TRACKERS_DIRS])
-AC_SUBST([MESA_LLVM])
-
-dnl
-dnl Find out if X is available. The variable have_x is set if libX11 is
-dnl found to mimic AC_PATH_XTRA.
-dnl
-if test -n "$PKG_CONFIG"; then
- AC_MSG_CHECKING([pkg-config files for X11 are available])
- PKG_CHECK_EXISTS([x11],[
- x11_pkgconfig=yes
- have_x=yes
- ],[
- x11_pkgconfig=no
- ])
- AC_MSG_RESULT([$x11_pkgconfig])
-else
- x11_pkgconfig=no
-fi
-dnl Use the autoconf macro if no pkg-config files
-if test "$x11_pkgconfig" = yes; then
- PKG_CHECK_MODULES([X11], [x11])
-else
- AC_PATH_XTRA
- test -z "$X11_CFLAGS" && X11_CFLAGS="$X_CFLAGS"
- test -z "$X11_LIBS" && X11_LIBS="$X_LIBS -lX11"
- AC_SUBST([X11_CFLAGS])
- AC_SUBST([X11_LIBS])
-fi
-
-dnl Try to tell the user that the --x-* options are only used when
-dnl pkg-config is not available. This must be right after AC_PATH_XTRA.
-m4_divert_once([HELP_BEGIN],
-[These options are only used when the X libraries cannot be found by the
-pkg-config utility.])
-
-dnl We need X for xlib and dri, so bomb now if it's not found
-case "$mesa_driver" in
-xlib|dri)
- if test "$no_x" = yes; then
- AC_MSG_ERROR([X11 development libraries needed for $mesa_driver driver])
- fi
- ;;
-esac
-
-dnl XCB - this is only used for GLX right now
-AC_ARG_ENABLE([xcb],
- [AS_HELP_STRING([--enable-xcb],
- [use XCB for GLX @<:@default=disabled@:>@])],
- [enable_xcb="$enableval"],
- [enable_xcb=no])
-if test "x$enable_xcb" = xyes; then
- DEFINES="$DEFINES -DUSE_XCB"
-else
- enable_xcb=no
-fi
-
-dnl
-dnl libGL configuration per driver
-dnl
-case "$mesa_driver" in
-xlib)
- if test "$x11_pkgconfig" = yes; then
- PKG_CHECK_MODULES([XLIBGL], [x11 xext])
- GL_PC_REQ_PRIV="x11 xext"
- X11_INCLUDES="$X11_INCLUDES $XLIBGL_CFLAGS"
- GL_LIB_DEPS="$XLIBGL_LIBS"
- else
- # should check these...
- X11_INCLUDES="$X11_INCLUDES $X_CFLAGS"
- GL_LIB_DEPS="$X_LIBS -lX11 -lXext"
- GL_PC_LIB_PRIV="$GL_LIB_DEPS"
- GL_PC_CFLAGS="$X11_INCLUDES"
- fi
- GL_LIB_DEPS="$GL_LIB_DEPS $SELINUX_LIBS -lm -lpthread"
- GL_PC_LIB_PRIV="$GL_PC_LIB_PRIV $SELINUX_LIBS -lm -lpthread"
-
- # if static, move the external libraries to the programs
- # and empty the libraries for libGL
- if test "$enable_static" = yes; then
- APP_LIB_DEPS="$APP_LIB_DEPS $GL_LIB_DEPS"
- GL_LIB_DEPS=""
- fi
- ;;
-dri|no) # these checks are still desired when there is no mesa_driver
- # DRI must be shared, I think
- if test "$enable_static" = yes; then
- AC_MSG_ERROR([Can't use static libraries for DRI drivers])
- fi
-
- # Check for libdrm
- PKG_CHECK_MODULES([LIBDRM], [libdrm >= $LIBDRM_REQUIRED])
- PKG_CHECK_MODULES([DRI2PROTO], [dri2proto >= $DRI2PROTO_REQUIRED])
- PKG_CHECK_MODULES([GLPROTO], [glproto >= $GLPROTO_REQUIRED])
- GL_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED dri2proto >= $DRI2PROTO_REQUIRED glproto >= $GLPROTO_REQUIRED"
- DRI_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED"
-
- # find the DRI deps for libGL
- if test "$x11_pkgconfig" = yes; then
- dri_modules="x11 xext xdamage xfixes"
-
- # add xf86vidmode if available
- PKG_CHECK_MODULES([XF86VIDMODE], [xxf86vm], HAVE_XF86VIDMODE=yes, HAVE_XF86VIDMODE=no)
- if test "$HAVE_XF86VIDMODE" = yes ; then
- dri_modules="$dri_modules xxf86vm"
- fi
-
- # add xcb modules if necessary
- if test "$enable_xcb" = yes; then
- dri_modules="$dri_modules x11-xcb xcb-glx"
- fi
-
- PKG_CHECK_MODULES([DRIGL], [$dri_modules])
- GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV $dri_modules"
- X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS"
- GL_LIB_DEPS="$DRIGL_LIBS"
- else
- # should check these...
- X11_INCLUDES="$X11_INCLUDES $X_CFLAGS"
- GL_LIB_DEPS="$X_LIBS -lX11 -lXext -lXxf86vm -lXdamage -lXfixes"
- GL_PC_LIB_PRIV="$GL_LIB_DEPS"
- GL_PC_CFLAGS="$X11_INCLUDES"
-
- # XCB can only be used from pkg-config
- if test "$enable_xcb" = yes; then
- PKG_CHECK_MODULES([XCB],[x11-xcb xcb-glx])
- GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV x11-xcb xcb-glx"
- X11_INCLUDES="$X11_INCLUDES $XCB_CFLAGS"
- GL_LIB_DEPS="$GL_LIB_DEPS $XCB_LIBS"
- fi
- fi
-
- # need DRM libs, -lpthread, etc.
- GL_LIB_DEPS="$GL_LIB_DEPS $LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS"
- GL_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS"
- GLESv1_CM_LIB_DEPS="$LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS"
- GLESv1_CM_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS"
- GLESv2_LIB_DEPS="$LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS"
- GLESv2_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS"
- ;;
-osmesa)
- # No libGL for osmesa
- GL_LIB_DEPS=""
- ;;
-esac
-AC_SUBST([GL_LIB_DEPS])
-AC_SUBST([GL_PC_REQ_PRIV])
-AC_SUBST([GL_PC_LIB_PRIV])
-AC_SUBST([GL_PC_CFLAGS])
-AC_SUBST([DRI_PC_REQ_PRIV])
-AC_SUBST([GLESv1_CM_LIB_DEPS])
-AC_SUBST([GLESv1_CM_PC_LIB_PRIV])
-AC_SUBST([GLESv2_LIB_DEPS])
-AC_SUBST([GLESv2_PC_LIB_PRIV])
-
-GLAPI_LIB_DEPS="-lpthread"
-AC_SUBST([GLAPI_LIB_DEPS])
-
-
-dnl Setup default DRI CFLAGS
-DRI_CFLAGS='$(CFLAGS)'
-DRI_CXXFLAGS='$(CXXFLAGS)'
-DRI_LIB_DEPS='$(TOP)/src/mesa/libmesa.a'
-MESA_MODULES='$(TOP)/src/mesa/libmesa.a'
-
-AC_ARG_ENABLE([shared-dricore],
- [AS_HELP_STRING([--enable-shared-dricore],
- [link DRI modules with shared core DRI routines @<:@default=disabled@:>@])],
- [enable_dricore="$enableval"],
- [enable_dricore=no])
-if test "$mesa_driver" = dri ; then
- if test "$enable_dricore" = yes ; then
- if test "$GCC$GXX" != yesyes ; then
- AC_MSG_WARN([Shared dricore requires GCC-compatible rpath handling. Disabling shared dricore])
- enable_dricore=no
- else
- DRICORE_GLSL_LIBS='$(TOP)/$(LIB_DIR)/libglsl.so'
- DRICORE_LIBS='$(TOP)/$(LIB_DIR)/libdricore.so'
- DRICORE_LIB_DEPS='-L$(TOP)/$(LIB_DIR) -Wl,-R$(DRI_DRIVER_INSTALL_DIR) -lglsl'
- DRI_LIB_DEPS='-L$(TOP)/$(LIB_DIR) -Wl,-R$(DRI_DRIVER_INSTALL_DIR) -ldricore -lglsl'
- DRI_CFLAGS='$(CFLAGS_NOVISIBILITY) -DUSE_DRICORE'
- DRI_CXXFLAGS='$(CXXFLAGS_NOVISIBILITY) -DUSE_DRICORE'
- MESA_MODULES='$(DRICORE_LIBS) $(DRICORE_GLSL_LIBS)'
- fi
- fi
-fi
-AC_SUBST([DRICORE_LIBS])
-AC_SUBST([DRICORE_GLSL_LIBS])
-AC_SUBST([DRICORE_LIB_DEPS])
-AC_SUBST([DRI_CXXFLAGS])
-AC_SUBST([DRI_CFLAGS])
-AC_SUBST([MESA_MODULES])
-
-AC_SUBST([HAVE_XF86VIDMODE])
-
-PKG_CHECK_MODULES([LIBDRM_RADEON],
- [libdrm_radeon >= $LIBDRM_RADEON_REQUIRED],
- HAVE_LIBDRM_RADEON=yes,
- HAVE_LIBDRM_RADEON=no)
-
-dnl
-dnl More X11 setup
-dnl
-if test "$mesa_driver" = xlib; then
- DEFINES="$DEFINES -DUSE_XSHM"
-fi
-
-dnl
-dnl TLS detection
-dnl
-
-AC_ARG_ENABLE([glx-tls],
- [AS_HELP_STRING([--enable-glx-tls],
- [enable TLS support in GLX @<:@default=disabled@:>@])],
- [GLX_USE_TLS="$enableval"],
- [GLX_USE_TLS=no])
-AC_SUBST(GLX_TLS, ${GLX_USE_TLS})
-
-AS_IF([test "x$GLX_USE_TLS" = xyes],
- [DEFINES="${DEFINES} -DGLX_USE_TLS -DPTHREADS"])
-
-dnl
-dnl More DRI setup
-dnl
-dnl Directory for DRI drivers
-AC_ARG_WITH([dri-driverdir],
- [AS_HELP_STRING([--with-dri-driverdir=DIR],
- [directory for the DRI drivers @<:@${libdir}/dri@:>@])],
- [DRI_DRIVER_INSTALL_DIR="$withval"],
- [DRI_DRIVER_INSTALL_DIR='${libdir}/dri'])
-AC_SUBST([DRI_DRIVER_INSTALL_DIR])
-dnl Extra search path for DRI drivers
-AC_ARG_WITH([dri-searchpath],
- [AS_HELP_STRING([--with-dri-searchpath=DIRS...],
- [semicolon delimited DRI driver search directories @<:@${libdir}/dri@:>@])],
- [DRI_DRIVER_SEARCH_DIR="$withval"],
- [DRI_DRIVER_SEARCH_DIR='${DRI_DRIVER_INSTALL_DIR}'])
-AC_SUBST([DRI_DRIVER_SEARCH_DIR])
-dnl Direct rendering or just indirect rendering
-AC_ARG_ENABLE([driglx-direct],
- [AS_HELP_STRING([--disable-driglx-direct],
- [enable direct rendering in GLX and EGL for DRI @<:@default=enabled@:>@])],
- [driglx_direct="$enableval"],
- [driglx_direct="yes"])
-dnl Which drivers to build - default is chosen by platform
-AC_ARG_WITH([dri-drivers],
- [AS_HELP_STRING([--with-dri-drivers@<:@=DIRS...@:>@],
- [comma delimited DRI drivers list, e.g.
- "swrast,i965,radeon" @<:@default=auto@:>@])],
- [with_dri_drivers="$withval"],
- [with_dri_drivers=yes])
-if test "x$with_dri_drivers" = x; then
- with_dri_drivers=no
-fi
-
-dnl If $with_dri_drivers is yes, directories will be added through
-dnl platform checks
-DRI_DIRS=""
-case "$with_dri_drivers" in
-no) ;;
-yes)
- DRI_DIRS="yes"
- ;;
-*)
- # verify the requested driver directories exist
- dri_drivers=`IFS=', '; echo $with_dri_drivers`
- for driver in $dri_drivers; do
- test -d "$srcdir/src/mesa/drivers/dri/$driver" || \
- AC_MSG_ERROR([DRI driver directory '$driver' doesn't exist])
- done
- DRI_DIRS="$dri_drivers"
- ;;
-esac
-
-dnl Set DRI_DIRS, DEFINES and LIB_DEPS
-if test "$mesa_driver" = dri -o "$mesa_driver" = no; then
- # Platform specific settings and drivers to build
- case "$host_os" in
- linux*)
- DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER"
- if test "x$driglx_direct" = xyes; then
- DEFINES="$DEFINES -DGLX_DIRECT_RENDERING"
- fi
- DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS"
-
- case "$host_cpu" in
- x86_64)
- # sis is missing because they have not be converted to use
- # the new interface. i810 are missing because there is no
- # x86-64 system where they could *ever* be used.
- if test "x$DRI_DIRS" = "xyes"; then
- DRI_DIRS="i915 i965 mach64 mga r128 r200 r300 r600 radeon \
- savage tdfx unichrome swrast"
- fi
- ;;
- powerpc*)
- # Build only the drivers for cards that exist on PowerPC.
- # At some point MGA will be added, but not yet.
- if test "x$DRI_DIRS" = "xyes"; then
- DRI_DIRS="mach64 r128 r200 r300 r600 radeon tdfx swrast"
- fi
- ;;
- sparc*)
- # Build only the drivers for cards that exist on sparc`
- if test "x$DRI_DIRS" = "xyes"; then
- DRI_DIRS="mach64 r128 r200 r300 r600 radeon swrast"
- fi
- ;;
- esac
- ;;
- freebsd* | dragonfly* | *netbsd*)
- DEFINES="$DEFINES -DPTHREADS -DUSE_EXTERNAL_DXTN_LIB=1"
- DEFINES="$DEFINES -DIN_DRI_DRIVER -DHAVE_ALIAS"
- DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING"
- if test "x$driglx_direct" = xyes; then
- DEFINES="$DEFINES -DGLX_DIRECT_RENDERING"
- fi
-
- if test "x$DRI_DIRS" = "xyes"; then
- DRI_DIRS="i810 i915 i965 mach64 mga r128 r200 r300 r600 radeon tdfx \
- unichrome savage sis swrast"
- fi
- ;;
- gnu*)
- DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER"
- DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS"
- ;;
- solaris*)
- DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER"
- DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING"
- if test "x$driglx_direct" = xyes; then
- DEFINES="$DEFINES -DGLX_DIRECT_RENDERING"
- fi
- ;;
- esac
-
- # default drivers
- if test "x$DRI_DIRS" = "xyes"; then
- DRI_DIRS="i810 i915 i965 mach64 mga r128 r200 r300 r600 radeon \
- savage sis tdfx unichrome swrast"
- fi
-
- DRI_DIRS=`echo "$DRI_DIRS" | $SED 's/ */ /g'`
-
- # Check for expat
- if test "$mesa_driver" = dri; then
- EXPAT_INCLUDES=""
- EXPAT_LIB=-lexpat
- AC_ARG_WITH([expat],
- [AS_HELP_STRING([--with-expat=DIR],
- [expat install directory])],[
- EXPAT_INCLUDES="-I$withval/include"
- CPPFLAGS="$CPPFLAGS $EXPAT_INCLUDES"
- LDFLAGS="$LDFLAGS -L$withval/$LIB_DIR"
- EXPAT_LIB="-L$withval/$LIB_DIR -lexpat"
- ])
- AC_CHECK_HEADER([expat.h],[],[AC_MSG_ERROR([Expat required for DRI.])])
- AC_CHECK_LIB([expat],[XML_ParserCreate],[],
- [AC_MSG_ERROR([Expat required for DRI.])])
- fi
-
- # put all the necessary libs together, including possibly libdricore
- DRI_LIB_DEPS="$DRI_LIB_DEPS $SELINUX_LIBS $LIBDRM_LIBS $EXPAT_LIB -lm -lpthread $DLOPEN_LIBS"
-fi
-AC_SUBST([DRI_DIRS])
-AC_SUBST([EXPAT_INCLUDES])
-AC_SUBST([DRI_LIB_DEPS])
-
-case $DRI_DIRS in
-*i915*|*i965*)
- PKG_CHECK_MODULES([INTEL], [libdrm_intel >= $LIBDRM_INTEL_REQUIRED])
- ;;
-esac
-
-case $DRI_DIRS in
-*radeon*|*r200*|*r300*|*r600*)
- if test "x$HAVE_LIBDRM_RADEON" = xyes; then
- RADEON_CFLAGS="-DHAVE_LIBDRM_RADEON=1 $LIBDRM_RADEON_CFLAGS"
- RADEON_LDFLAGS=$LIBDRM_RADEON_LIBS
- fi
- ;;
-esac
-AC_SUBST([RADEON_CFLAGS])
-AC_SUBST([RADEON_LDFLAGS])
-
-
-dnl
-dnl OSMesa configuration
-dnl
-if test "$mesa_driver" = xlib; then
- default_gl_osmesa=yes
-else
- default_gl_osmesa=no
-fi
-AC_ARG_ENABLE([gl-osmesa],
- [AS_HELP_STRING([--enable-gl-osmesa],
- [enable OSMesa with libGL @<:@default=enabled for xlib driver@:>@])],
- [gl_osmesa="$enableval"],
- [gl_osmesa="$default_gl_osmesa"])
-if test "x$gl_osmesa" = xyes; then
- if test "x$enable_opengl" = xno; then
- AC_MSG_ERROR([OpenGL is not available for OSMesa driver])
- fi
- if test "$mesa_driver" = osmesa; then
- AC_MSG_ERROR([libGL is not available for OSMesa driver])
- else
- DRIVER_DIRS="$DRIVER_DIRS osmesa"
- fi
-fi
-
-dnl Configure the channel bits for OSMesa (libOSMesa, libOSMesa16, ...)
-AC_ARG_WITH([osmesa-bits],
- [AS_HELP_STRING([--with-osmesa-bits=BITS],
- [OSMesa channel bits and library name: 8, 16, 32 @<:@default=8@:>@])],
- [osmesa_bits="$withval"],
- [osmesa_bits=8])
-if test "$mesa_driver" != osmesa && test "x$osmesa_bits" != x8; then
- AC_MSG_WARN([Ignoring OSMesa channel bits for non-OSMesa driver])
- osmesa_bits=8
-fi
-case "x$osmesa_bits" in
-x8)
- OSMESA_LIB=OSMesa
- ;;
-x16|x32)
- OSMESA_LIB="OSMesa$osmesa_bits"
- DEFINES="$DEFINES -DCHAN_BITS=$osmesa_bits -DDEFAULT_SOFTWARE_DEPTH_BITS=31"
- ;;
-*)
- AC_MSG_ERROR([OSMesa bits '$osmesa_bits' is not a valid option])
- ;;
-esac
-AC_SUBST([OSMESA_LIB])
-
-case "$DRIVER_DIRS" in
-*osmesa*)
- # only link libraries with osmesa if shared
- if test "$enable_static" = no; then
- OSMESA_LIB_DEPS="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS"
- else
- OSMESA_LIB_DEPS=""
- fi
- OSMESA_MESA_DEPS=""
- OSMESA_PC_LIB_PRIV="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS"
- ;;
-esac
-AC_SUBST([OSMESA_LIB_DEPS])
-AC_SUBST([OSMESA_MESA_DEPS])
-AC_SUBST([OSMESA_PC_REQ])
-AC_SUBST([OSMESA_PC_LIB_PRIV])
-
-dnl
-dnl EGL configuration
-dnl
-AC_ARG_ENABLE([egl],
- [AS_HELP_STRING([--disable-egl],
- [disable EGL library @<:@default=enabled@:>@])],
- [enable_egl="$enableval"],
- [enable_egl=yes])
-if test "x$enable_egl" = xno; then
- if test "x$mesa_driver" = xno; then
- AC_MSG_ERROR([cannot disable EGL when there is no mesa driver])
- fi
- if test "x$enable_openvg" = xyes; then
- AC_MSG_ERROR([cannot enable OpenVG without EGL])
- fi
-fi
-if test "x$enable_egl" = xyes; then
- SRC_DIRS="$SRC_DIRS egl"
- EGL_LIB_DEPS="$DLOPEN_LIBS -lpthread"
- EGL_DRIVERS_DIRS=""
- if test "$enable_static" != yes; then
- # build egl_glx when libGL is built
- if test "$mesa_driver" = xlib -o "$mesa_driver" = dri; then
- EGL_DRIVERS_DIRS="glx"
- fi
-
- if test "$mesa_driver" = dri; then
- # build egl_dri2 when xcb-dri2 is available
- PKG_CHECK_MODULES([XCB_DRI2], [x11-xcb xcb-dri2 xcb-xfixes],
- [have_xcb_dri2=yes],[have_xcb_dri2=no])
- PKG_CHECK_MODULES([LIBUDEV], [libudev > 150],
- [have_libudev=yes],[have_libudev=no])
-
- if test "$have_xcb_dri2" = yes; then
- EGL_DRIVER_DRI2=dri2
- DEFINES="$DEFINES -DHAVE_XCB_DRI2"
- if test "$have_libudev" = yes; then
- DEFINES="$DEFINES -DHAVE_LIBUDEV"
- fi
- fi
- fi
-
- EGL_DRIVERS_DIRS="$EGL_DRIVERS_DIRS $EGL_DRIVER_DRI2"
- fi
-fi
-AC_SUBST([EGL_LIB_DEPS])
-AC_SUBST([EGL_DRIVERS_DIRS])
-
-dnl
-dnl GLU configuration
-dnl
-AC_ARG_ENABLE([glu],
- [AS_HELP_STRING([--disable-glu],
- [enable OpenGL Utility library @<:@default=enabled@:>@])],
- [enable_glu="$enableval"],
- [enable_glu=yes])
-
-if test "x$enable_glu" = xyes -a "x$mesa_driver" = xno; then
- AC_MSG_NOTICE([Disabling GLU since there is no OpenGL driver])
- enable_glu=no
-fi
-
-if test "x$enable_glu" = xyes; then
- SRC_DIRS="$SRC_DIRS glu"
-
- case "$mesa_driver" in
- osmesa)
- # Link libGLU to libOSMesa instead of libGL
- GLU_LIB_DEPS=""
- GLU_PC_REQ="osmesa"
- if test "$enable_static" = no; then
- GLU_MESA_DEPS='-l$(OSMESA_LIB)'
- else
- GLU_MESA_DEPS=""
- fi
- ;;
- *)
- # If static, empty GLU_LIB_DEPS and add libs for programs to link
- GLU_PC_REQ="gl"
- GLU_PC_LIB_PRIV="-lm"
- if test "$enable_static" = no; then
- GLU_LIB_DEPS="-lm"
- GLU_MESA_DEPS='-l$(GL_LIB)'
- else
- GLU_LIB_DEPS=""
- GLU_MESA_DEPS=""
- APP_LIB_DEPS="$APP_LIB_DEPS -lstdc++"
- fi
- ;;
- esac
-fi
-if test "$enable_static" = no; then
- GLU_LIB_DEPS="$GLU_LIB_DEPS $OS_CPLUSPLUS_LIBS"
-fi
-GLU_PC_LIB_PRIV="$GLU_PC_LIB_PRIV $OS_CPLUSPLUS_LIBS"
-AC_SUBST([GLU_LIB_DEPS])
-AC_SUBST([GLU_MESA_DEPS])
-AC_SUBST([GLU_PC_REQ])
-AC_SUBST([GLU_PC_REQ_PRIV])
-AC_SUBST([GLU_PC_LIB_PRIV])
-AC_SUBST([GLU_PC_CFLAGS])
-
-dnl
-dnl GLw configuration
-dnl
-AC_ARG_ENABLE([glw],
- [AS_HELP_STRING([--disable-glw],
- [enable Xt/Motif widget library @<:@default=enabled@:>@])],
- [enable_glw="$enableval"],
- [enable_glw=yes])
-dnl Don't build GLw on osmesa
-if test "x$enable_glw" = xyes; then
- case "$mesa_driver" in
- osmesa|no)
- AC_MSG_NOTICE([Disabling GLw since there is no OpenGL driver])
- enable_glw=no
- ;;
- esac
-fi
-AC_ARG_ENABLE([motif],
- [AS_HELP_STRING([--enable-motif],
- [use Motif widgets in GLw @<:@default=disabled@:>@])],
- [enable_motif="$enableval"],
- [enable_motif=no])
-
-if test "x$enable_glw" = xyes; then
- SRC_DIRS="$SRC_DIRS glw"
- if test "$x11_pkgconfig" = yes; then
- PKG_CHECK_MODULES([GLW],[x11 xt])
- GLW_PC_REQ_PRIV="x11 xt"
- GLW_LIB_DEPS="$GLW_LIBS"
- else
- # should check these...
- GLW_LIB_DEPS="$X_LIBS -lXt -lX11"
- GLW_PC_LIB_PRIV="$GLW_LIB_DEPS"
- GLW_PC_CFLAGS="$X11_INCLUDES"
- fi
-
- GLW_SOURCES="GLwDrawA.c"
- MOTIF_CFLAGS=
- if test "x$enable_motif" = xyes; then
- GLW_SOURCES="$GLW_SOURCES GLwMDrawA.c"
- AC_PATH_PROG([MOTIF_CONFIG], [motif-config], [no])
- if test "x$MOTIF_CONFIG" != xno; then
- MOTIF_CFLAGS=`$MOTIF_CONFIG --cflags`
- MOTIF_LIBS=`$MOTIF_CONFIG --libs`
- else
- AC_CHECK_HEADER([Xm/PrimitiveP.h], [],
- [AC_MSG_ERROR([Can't locate Motif headers])])
- AC_CHECK_LIB([Xm], [XmGetPixmap], [MOTIF_LIBS="-lXm"],
- [AC_MSG_ERROR([Can't locate Motif Xm library])])
- fi
- # MOTIF_LIBS is prepended to GLW_LIB_DEPS since Xm needs Xt/X11
- GLW_LIB_DEPS="$MOTIF_LIBS $GLW_LIB_DEPS"
- GLW_PC_LIB_PRIV="$MOTIF_LIBS $GLW_PC_LIB_PRIV"
- GLW_PC_CFLAGS="$MOTIF_CFLAGS $GLW_PC_CFLAGS"
- fi
-
- # If static, empty GLW_LIB_DEPS and add libs for programs to link
- GLW_PC_LIB_PRIV="$GLW_PC_LIB_PRIV"
- if test "$enable_static" = no; then
- GLW_MESA_DEPS='-l$(GL_LIB)'
- GLW_LIB_DEPS="$GLW_LIB_DEPS"
- else
- APP_LIB_DEPS="$APP_LIB_DEPS $GLW_LIB_DEPS"
- GLW_LIB_DEPS=""
- GLW_MESA_DEPS=""
- fi
-fi
-AC_SUBST([GLW_LIB_DEPS])
-AC_SUBST([GLW_MESA_DEPS])
-AC_SUBST([GLW_SOURCES])
-AC_SUBST([MOTIF_CFLAGS])
-AC_SUBST([GLW_PC_REQ_PRIV])
-AC_SUBST([GLW_PC_LIB_PRIV])
-AC_SUBST([GLW_PC_CFLAGS])
-
-dnl
-dnl GLUT configuration
-dnl
-if test -f "$srcdir/include/GL/glut.h"; then
- default_glut=yes
-else
- default_glut=no
-fi
-AC_ARG_ENABLE([glut],
- [AS_HELP_STRING([--disable-glut],
- [enable GLUT library @<:@default=enabled if source available@:>@])],
- [enable_glut="$enableval"],
- [enable_glut="$default_glut"])
-
-dnl Don't build glut on osmesa
-if test "x$enable_glut" = xyes; then
- case "$mesa_driver" in
- osmesa|no)
- AC_MSG_NOTICE([Disabling glut since there is no OpenGL driver])
- enable_glut=no
- ;;
- esac
-fi
-dnl Can't build glut if GLU not available
-if test "x$enable_glu$enable_glut" = xnoyes; then
- AC_MSG_WARN([Disabling glut since GLU is disabled])
- enable_glut=no
-fi
-
-if test "x$enable_glut" = xyes; then
- SRC_DIRS="$SRC_DIRS glut/glx"
- if test "$x11_pkgconfig" = yes; then
- PKG_CHECK_MODULES([GLUT],[x11 xmu xi])
- GLUT_PC_REQ_PRIV="x11 xmu xi"
- GLUT_LIB_DEPS="$GLUT_LIBS"
- else
- # should check these...
- GLUT_LIB_DEPS="$X_LIBS -lX11 -lXmu -lXi"
- GLUT_PC_LIB_PRIV="$GLUT_LIB_DEPS"
- GLUT_PC_CFLAGS="$X11_INCLUDES"
- fi
- if test "x$GCC" = xyes; then
- GLUT_CFLAGS="$GLUT_CFLAGS -fexceptions"
- fi
- GLUT_LIB_DEPS="$GLUT_LIB_DEPS -lm"
- GLUT_PC_LIB_PRIV="$GLUT_PC_LIB_PRIV -lm"
-
- # If static, empty GLUT_LIB_DEPS and add libs for programs to link
- if test "$enable_static" = no; then
- GLUT_MESA_DEPS='-l$(GLU_LIB) -l$(GL_LIB)'
- else
- APP_LIB_DEPS="$APP_LIB_DEPS $GLUT_LIB_DEPS"
- GLUT_LIB_DEPS=""
- GLUT_MESA_DEPS=""
- fi
-fi
-AC_SUBST([GLUT_LIB_DEPS])
-AC_SUBST([GLUT_MESA_DEPS])
-AC_SUBST([GLUT_CFLAGS])
-AC_SUBST([GLUT_PC_REQ_PRIV])
-AC_SUBST([GLUT_PC_LIB_PRIV])
-AC_SUBST([GLUT_PC_CFLAGS])
-
-dnl
-dnl Program library dependencies
-dnl Only libm is added here if necessary as the libraries should
-dnl be pulled in by the linker
-dnl
-if test "x$APP_LIB_DEPS" = x; then
- case "$host_os" in
- solaris*)
- APP_LIB_DEPS="-lX11 -lsocket -lnsl -lm"
- ;;
- cygwin*)
- APP_LIB_DEPS="-lX11"
- ;;
- *)
- APP_LIB_DEPS="-lm"
- ;;
- esac
-fi
-AC_SUBST([APP_LIB_DEPS])
-AC_SUBST([PROGRAM_DIRS])
-
-dnl
-dnl Gallium configuration
-dnl
-AC_ARG_ENABLE([gallium],
- [AS_HELP_STRING([--disable-gallium],
- [build gallium @<:@default=enabled@:>@])],
- [enable_gallium="$enableval"],
- [enable_gallium=yes])
-if test "x$enable_gallium" = xno -a "x$enable_openvg" = xyes; then
- AC_MSG_ERROR([cannot enable OpenVG without Gallium])
-fi
-if test "x$enable_gallium" = xyes; then
- SRC_DIRS="$SRC_DIRS gallium gallium/winsys gallium/targets"
- AC_CHECK_HEADER([udis86.h], [HAS_UDIS86="yes"],
- [HAS_UDIS86="no"])
- AC_PATH_PROG([LLVM_CONFIG], [llvm-config], [no])
-fi
-
-AC_SUBST([LLVM_CFLAGS])
-AC_SUBST([LLVM_LIBS])
-AC_SUBST([LLVM_LDFLAGS])
-AC_SUBST([LLVM_VERSION])
-
-dnl
-dnl Gallium state trackers configuration
-dnl
-
-AC_ARG_ENABLE([gallium-egl],
- [AS_HELP_STRING([--enable-gallium-egl],
- [enable gallium EGL state tracker @<:@default=auto@:>@])],
- [enable_gallium_egl="$enableval"],
- [enable_gallium_egl=auto])
-if test "x$enable_gallium_egl" = xauto; then
- case "$mesa_driver" in
- dri|no)
- enable_gallium_egl=$enable_egl
- ;;
- *)
- enable_gallium_egl=$enable_openvg
- ;;
- esac
-fi
-case "x$enable_egl$enable_gallium_egl" in
-xnoyes)
- AC_MSG_ERROR([cannot build Gallium EGL state tracker without EGL])
-esac
-
-AC_ARG_WITH([state-trackers],
- [AS_HELP_STRING([--with-state-trackers@<:@=DIRS...@:>@],
- [comma delimited state_trackers list, e.g.
- "egl,glx" @<:@default=auto@:>@])],
- [with_state_trackers="$withval"],
- [with_state_trackers=yes])
-
-case "$with_state_trackers" in
-no)
- GALLIUM_STATE_TRACKERS_DIRS=""
- ;;
-yes)
- # look at what else is built
- case "$mesa_driver" in
- xlib)
- GALLIUM_STATE_TRACKERS_DIRS=glx
- ;;
- dri)
- GALLIUM_STATE_TRACKERS_DIRS="dri"
- HAVE_ST_DRI="yes"
- # Have only tested st/xorg on 1.6.0 servers
- PKG_CHECK_MODULES(XORG, [xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED],
- HAVE_ST_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg",
- HAVE_ST_XORG="no")
- ;;
- esac
-
- if test "x$enable_egl" = xyes; then
- if test "$enable_openvg" = yes; then
- GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS vega"
- st_egl="yes"
- fi
-
- if test "$enable_gallium_egl" = yes; then
- GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl"
- HAVE_ST_EGL="yes"
- fi
- fi
- ;;
-*)
- # verify the requested state tracker exist
- state_trackers=""
- _state_trackers=`IFS=', '; echo $with_state_trackers`
- for tracker in $_state_trackers; do
- case "$tracker" in
- dri)
- if test "x$mesa_driver" != xdri; then
- AC_MSG_ERROR([cannot build dri state tracker without mesa driver set to dri])
- fi
- HAVE_ST_DRI="yes"
- ;;
- egl)
- if test "x$enable_egl" != xyes; then
- AC_MSG_ERROR([cannot build egl state tracker without EGL library])
- fi
- HAVE_ST_EGL="yes"
- ;;
- xorg)
- PKG_CHECK_MODULES([XORG], [xorg-server >= 1.6.0])
- PKG_CHECK_MODULES([LIBDRM_XORG], [libdrm >= $LIBDRM_XORG_REQUIRED])
- PKG_CHECK_MODULES([LIBKMS_XORG], [libkms >= $LIBKMS_XORG_REQUIRED])
- HAVE_ST_XORG="yes"
- ;;
- vega)
- if test "x$enable_openvg" != xyes; then
- AC_MSG_ERROR([cannot build vega state tracker without --enable-openvg])
- fi
- have_st_vega="yes"
- ;;
- esac
-
- if test -n "$tracker"; then
- test -d "$srcdir/src/gallium/state_trackers/$tracker" || \
- AC_MSG_ERROR([state tracker '$tracker' doesn't exist])
- if test -n "$state_trackers"; then
- state_trackers="$state_trackers $tracker"
- else
- state_trackers="$tracker"
- fi
- fi
- done
- GALLIUM_STATE_TRACKERS_DIRS="$state_trackers"
-
- # append --enable-openvg/--enable-gallium-egl to --with-state-trackers
- if test "x$have_st_vega" != xyes -a "x$enable_openvg" = xyes; then
- AC_MSG_ERROR([--with-state-trackers specified but vega is missing])
- fi
- if test "x$HAVE_ST_EGL" != xyes -a "x$enable_gallium_egl" = xyes; then
- AC_MSG_ERROR([--with-state-trackers specified but egl is missing])
- fi
- ;;
-esac
-
-
-EGL_CLIENT_APIS=""
-VG_LIB_DEPS=""
-
-case "x$enable_opengl$enable_gles1$enable_gles2" in
-x*yes*)
- EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(GL_LIB)'
- ;;
-esac
-if test "x$enable_openvg" = xyes; then
- EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(VG_LIB)'
- VG_LIB_DEPS="$VG_LIB_DEPS -lpthread"
-fi
-
-AC_SUBST([VG_LIB_DEPS])
-AC_SUBST([EGL_CLIENT_APIS])
-
-if test "x$HAVE_ST_EGL" = xyes; then
- GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl"
-fi
-
-if test "x$HAVE_ST_XORG" = xyes; then
- PKG_CHECK_MODULES(XEXT, [xextproto >= 7.0.99.1],
- HAVE_XEXTPROTO_71="yes"; DEFINES="$DEFINES -DHAVE_XEXTPROTO_71",
- HAVE_XEXTPROTO_71="no")
-fi
-
-AC_ARG_WITH([egl-platforms],
- [AS_HELP_STRING([--with-egl-platforms@<:@=DIRS...@:>@],
- [comma delimited native platforms libEGL supports, e.g.
- "x11,drm" @<:@default=auto@:>@])],
- [with_egl_platforms="$withval"],
- [with_egl_platforms=yes])
-AC_ARG_WITH([egl-displays],
- [AS_HELP_STRING([--with-egl-displays@<:@=DIRS...@:>@],
- [DEPRECATED. Use --with-egl-platforms instead])],
- [with_egl_platforms="$withval"])
-
-EGL_PLATFORMS=""
-WAYLAND_EGL_LIB_DEPS=""
-
-case "$with_egl_platforms" in
-yes)
- if test "x$enable_egl" = xyes && test "x$mesa_driver" != xosmesa; then
- EGL_PLATFORMS="x11"
- if test "$mesa_driver" = dri; then
- EGL_PLATFORMS="$EGL_PLATFORMS drm"
- fi
- fi
- ;;
-*)
- if test "x$enable_egl" != xyes; then
- AC_MSG_ERROR([cannot build egl state tracker without EGL library])
- fi
- # verify the requested driver directories exist
- egl_platforms=`IFS=', '; echo $with_egl_platforms`
- for plat in $egl_platforms; do
- test -d "$srcdir/src/gallium/state_trackers/egl/$plat" || \
- AC_MSG_ERROR([EGL platform '$plat' doesn't exist])
- if test "$plat" = "fbdev"; then
- GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/fbdev"
- fi
- if test "$plat" = "wayland"; then
- PKG_CHECK_MODULES([WAYLAND], [wayland-client wayland-server],, \
- [AC_MSG_ERROR([cannot find libwayland-client])])
- WAYLAND_EGL_LIB_DEPS="$WAYLAND_LIBS $LIBDRM_LIBS"
- fi
- done
- EGL_PLATFORMS="$egl_platforms"
- ;;
-esac
-AC_SUBST([EGL_PLATFORMS])
-
-AC_SUBST([WAYLAND_EGL_LIB_DEPS])
-WAYLAND_EGL_PC_REQ_PRIV="wayland-client libdrm"
-WAYLAND_EGL_PC_LIB_PRIV=
-WAYLAND_EGL_PC_CFLAGS=
-
-AC_SUBST([WAYLAND_EGL_PC_REQ_PRIV])
-AC_SUBST([WAYLAND_EGL_PC_LIB_PRIV])
-AC_SUBST([WAYLAND_EGL_PC_CFLAGS])
-
-
-AC_ARG_WITH([egl-driver-dir],
- [AS_HELP_STRING([--with-egl-driver-dir=DIR],
- [directory for EGL drivers [[default=${libdir}/egl]]])],
- [EGL_DRIVER_INSTALL_DIR="$withval"],
- [EGL_DRIVER_INSTALL_DIR='${libdir}/egl'])
-AC_SUBST([EGL_DRIVER_INSTALL_DIR])
-
-AC_ARG_WITH([xorg-driver-dir],
- [AS_HELP_STRING([--with-xorg-driver-dir=DIR],
- [Default xorg driver directory[[default=${libdir}/xorg/modules/drivers]]])],
- [XORG_DRIVER_INSTALL_DIR="$withval"],
- [XORG_DRIVER_INSTALL_DIR="${libdir}/xorg/modules/drivers"])
-AC_SUBST([XORG_DRIVER_INSTALL_DIR])
-
-AC_ARG_WITH([max-width],
- [AS_HELP_STRING([--with-max-width=N],
- [Maximum framebuffer width (4096)])],
- [DEFINES="${DEFINES} -DMAX_WIDTH=${withval}";
- AS_IF([test "${withval}" -gt "4096"],
- [AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])]
-)
-AC_ARG_WITH([max-height],
- [AS_HELP_STRING([--with-max-height=N],
- [Maximum framebuffer height (4096)])],
- [DEFINES="${DEFINES} -DMAX_HEIGHT=${withval}";
- AS_IF([test "${withval}" -gt "4096"],
- [AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])]
-)
-
-dnl
-dnl Gallium LLVM
-dnl
-AC_ARG_ENABLE([gallium-llvm],
- [AS_HELP_STRING([--enable-gallium-llvm],
- [build gallium LLVM support @<:@default=disabled@:>@])],
- [enable_gallium_llvm="$enableval"],
- [enable_gallium_llvm=auto])
-if test "x$enable_gallium_llvm" = xyes; then
- if test "x$LLVM_CONFIG" != xno; then
- LLVM_VERSION=`$LLVM_CONFIG --version`
- LLVM_CFLAGS=`$LLVM_CONFIG --cppflags`
- LLVM_LIBS="`$LLVM_CONFIG --libs jit interpreter nativecodegen bitwriter` -lstdc++"
-
- if test "x$HAS_UDIS86" != xno; then
- LLVM_LIBS="$LLVM_LIBS -ludis86"
- DEFINES="$DEFINES -DHAVE_UDIS86"
- fi
- LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags`
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe"
- DEFINES="$DEFINES -DGALLIUM_LLVMPIPE -D__STDC_CONSTANT_MACROS"
- MESA_LLVM=1
- else
- MESA_LLVM=0
- fi
-else
- MESA_LLVM=0
-fi
-
-dnl
-dnl Gallium helper functions
-dnl
-gallium_check_st() {
- if test "x$HAVE_ST_DRI" = xyes || test "x$HAVE_ST_XORG" = xyes; then
- GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS $1"
- fi
- if test "x$HAVE_ST_DRI" = xyes && test "x$2" != x; then
- GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $2"
- fi
- if test "x$HAVE_ST_XORG" = xyes && test "x$3" != x; then
- GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $3"
- fi
-}
-
-
-dnl
-dnl Gallium SVGA configuration
-dnl
-AC_ARG_ENABLE([gallium-svga],
- [AS_HELP_STRING([--enable-gallium-svga],
- [build gallium SVGA @<:@default=disabled@:>@])],
- [enable_gallium_svga="$enableval"],
- [enable_gallium_svga=auto])
-if test "x$enable_gallium_svga" = xyes; then
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga"
- gallium_check_st "svga/drm" "dri-vmwgfx" "xorg-vmwgfx"
-elif test "x$enable_gallium_svga" = xauto; then
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga"
-fi
-
-dnl
-dnl Gallium i915 configuration
-dnl
-AC_ARG_ENABLE([gallium-i915],
- [AS_HELP_STRING([--enable-gallium-i915],
- [build gallium i915 @<:@default=disabled@:>@])],
- [enable_gallium_i915="$enableval"],
- [enable_gallium_i915=auto])
-if test "x$enable_gallium_i915" = xyes; then
- GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw"
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915"
- gallium_check_st "i915/drm" "dri-i915" "xorg-i915"
-elif test "x$enable_gallium_i915" = xauto; then
- GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw"
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915"
-fi
-
-dnl
-dnl Gallium i965 configuration
-dnl
-AC_ARG_ENABLE([gallium-i965],
- [AS_HELP_STRING([--enable-gallium-i965],
- [build gallium i965 @<:@default=disabled@:>@])],
- [enable_gallium_i965="$enableval"],
- [enable_gallium_i965=auto])
-if test "x$enable_gallium_i965" = xyes; then
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965"
- gallium_check_st "i965/drm" "dri-i965" "xorg-i965"
-elif test "x$enable_gallium_i965" = xauto; then
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965"
-fi
-
-dnl
-dnl Gallium Radeon r300g configuration
-dnl
-AC_ARG_ENABLE([gallium-radeon],
- [AS_HELP_STRING([--enable-gallium-radeon],
- [build gallium radeon @<:@default=disabled@:>@])],
- [enable_gallium_radeon="$enableval"],
- [enable_gallium_radeon=auto])
-if test "x$enable_gallium_radeon" = xauto; then
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
- gallium_check_st "radeon/drm" "dri-r300"
-fi
-if test "x$enable_gallium_radeon" = xyes; then
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
- gallium_check_st "radeon/drm" "dri-r300" "xorg-radeon"
-fi
-
-dnl
-dnl Gallium Radeon r600g configuration
-dnl
-AC_ARG_ENABLE([gallium-r600],
- [AS_HELP_STRING([--enable-gallium-r600],
- [build gallium radeon @<:@default=disabled@:>@])],
- [enable_gallium_r600="$enableval"],
- [enable_gallium_r600=auto])
-if test "x$enable_gallium_r600" = xyes; then
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r600"
- gallium_check_st "r600/drm" "dri-r600"
-fi
-
-dnl
-dnl Gallium Nouveau configuration
-dnl
-AC_ARG_ENABLE([gallium-nouveau],
- [AS_HELP_STRING([--enable-gallium-nouveau],
- [build gallium nouveau @<:@default=disabled@:>@])],
- [enable_gallium_nouveau="$enableval"],
- [enable_gallium_nouveau=no])
-if test "x$enable_gallium_nouveau" = xyes; then
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50 nvc0"
- gallium_check_st "nouveau/drm" "dri-nouveau" "xorg-nouveau"
-fi
-
-dnl
-dnl Gallium swrast configuration
-dnl
-AC_ARG_ENABLE([gallium-swrast],
- [AS_HELP_STRING([--enable-gallium-swrast],
- [build gallium swrast @<:@default=auto@:>@])],
- [enable_gallium_swrast="$enableval"],
- [enable_gallium_swrast=auto])
-if test "x$enable_gallium_swrast" = xyes || test "x$enable_gallium_swrast" = xauto; then
- if test "x$HAVE_ST_DRI" = xyes; then
- GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast"
- fi
-fi
-
-dnl prepend CORE_DIRS to SRC_DIRS
-SRC_DIRS="$CORE_DIRS $SRC_DIRS"
-
-dnl Restore LDFLAGS and CPPFLAGS
-LDFLAGS="$_SAVE_LDFLAGS"
-CPPFLAGS="$_SAVE_CPPFLAGS"
-
-dnl Substitute the config
-AC_CONFIG_FILES([configs/autoconf])
-
-dnl Replace the configs/current symlink
-AC_CONFIG_COMMANDS([configs],[
-if test -f configs/current || test -L configs/current; then
- rm -f configs/current
-fi
-ln -s autoconf configs/current
-])
-
-AC_OUTPUT
-
-dnl
-dnl Output some configuration info for the user
-dnl
-echo ""
-echo " prefix: $prefix"
-echo " exec_prefix: $exec_prefix"
-echo " libdir: $libdir"
-echo " includedir: $includedir"
-
-dnl API info
-echo ""
-echo " OpenGL: $enable_opengl (ES1: $enable_gles1 ES2: $enable_gles2)"
-echo " OpenVG: $enable_openvg"
-
-dnl Driver info
-echo ""
-echo " Driver: $mesa_driver"
-if test "$mesa_driver" != no; then
- if echo "$DRIVER_DIRS" | grep 'osmesa' >/dev/null 2>&1; then
- echo " OSMesa: lib$OSMESA_LIB"
- else
- echo " OSMesa: no"
- fi
- if test "$mesa_driver" = dri; then
- # cleanup the drivers var
- dri_dirs=`echo $DRI_DIRS | $SED 's/^ *//;s/ */ /;s/ *$//'`
- if test "x$DRI_DIRS" = x; then
- echo " DRI drivers: no"
- else
- echo " DRI drivers: $dri_dirs"
- fi
- echo " DRI driver dir: $DRI_DRIVER_INSTALL_DIR"
- echo " Use XCB: $enable_xcb"
- echo " Shared dricore: $enable_dricore"
- fi
-fi
-echo ""
-echo " GLU: $enable_glu"
-echo " GLw: $enable_glw (Motif: $enable_motif)"
-echo " glut: $enable_glut"
-
-dnl EGL
-echo ""
-echo " EGL: $enable_egl"
-if test "$enable_egl" = yes; then
- echo " EGL platforms: $EGL_PLATFORMS"
-
- egl_drivers=""
- for d in $EGL_DRIVERS_DIRS; do
- egl_drivers="$egl_drivers builtin:egl_$d"
- done
-
- if test "$enable_gallium" = yes -a "$HAVE_ST_EGL" = yes; then
- echo " EGL drivers: ${egl_drivers} egl_gallium"
- echo " EGL Gallium STs:$EGL_CLIENT_APIS"
- else
- echo " EGL drivers: $egl_drivers"
- fi
-fi
-
-echo ""
-if test "x$MESA_LLVM" = x1; then
- echo " llvm: yes"
- echo " llvm-config: $LLVM_CONFIG"
- echo " llvm-version: $LLVM_VERSION"
-else
- echo " llvm: no"
-fi
-
-echo ""
-if echo "$SRC_DIRS" | grep 'gallium' >/dev/null 2>&1; then
- echo " Gallium: yes"
- echo " Gallium dirs: $GALLIUM_DIRS"
- echo " Target dirs: $GALLIUM_TARGET_DIRS"
- echo " Winsys dirs: $GALLIUM_WINSYS_DIRS"
- echo " Driver dirs: $GALLIUM_DRIVERS_DIRS"
- echo " Trackers dirs: $GALLIUM_STATE_TRACKERS_DIRS"
-else
- echo " Gallium: no"
-fi
-
-dnl Libraries
-echo ""
-echo " Shared libs: $enable_shared"
-echo " Static libs: $enable_static"
-
-dnl Compiler options
-# cleanup the CFLAGS/CXXFLAGS/DEFINES vars
-cflags=`echo $CFLAGS $OPT_FLAGS $PIC_FLAGS $ARCH_FLAGS | \
- $SED 's/^ *//;s/ */ /;s/ *$//'`
-cxxflags=`echo $CXXFLAGS $OPT_FLAGS $PIC_FLAGS $ARCH_FLAGS | \
- $SED 's/^ *//;s/ */ /;s/ *$//'`
-defines=`echo $DEFINES $ASM_FLAGS | $SED 's/^ *//;s/ */ /;s/ *$//'`
-echo ""
-echo " CFLAGS: $cflags"
-echo " CXXFLAGS: $cxxflags"
-echo " Macros: $defines"
-echo ""
-echo " PYTHON2: $PYTHON2"
-
-echo ""
-echo " Run '${MAKE-make}' to build Mesa"
-echo ""
+dnl Process this file with autoconf to create configure.
+
+AC_PREREQ([2.59])
+
+dnl Versioning - scrape the version from configs/default
+m4_define([mesa_version],
+ [m4_esyscmd([${MAKE-make} -s -f bin/version.mk version | tr -d '\n' | tr -d '\r'])])
+m4_ifval(mesa_version,,
+ [m4_fatal([Failed to get the Mesa version from `make -f bin/version.mk version`])])
+
+dnl Tell the user about autoconf.html in the --help output
+m4_divert_once([HELP_END], [
+See docs/autoconf.html for more details on the options for Mesa.])
+
+AC_INIT([Mesa],[mesa_version],
+ [https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa])
+AC_CONFIG_AUX_DIR([bin])
+AC_CANONICAL_HOST
+
+dnl Versions for external dependencies
+LIBDRM_REQUIRED=2.4.24
+LIBDRM_RADEON_REQUIRED=2.4.24
+LIBDRM_INTEL_REQUIRED=2.4.24
+DRI2PROTO_REQUIRED=2.1
+GLPROTO_REQUIRED=1.4.11
+LIBDRM_XORG_REQUIRED=2.4.24
+LIBKMS_XORG_REQUIRED=1.0.0
+
+dnl Check for progs
+AC_PROG_CPP
+AC_PROG_CC
+AC_PROG_CXX
+AC_CHECK_PROGS([MAKE], [gmake make])
+AC_CHECK_PROGS([PYTHON2], [python2 python])
+AC_PATH_PROG([MKDEP], [makedepend])
+AC_PATH_PROG([SED], [sed])
+
+if test "x$MKDEP" = "x"; then
+ AC_MSG_ERROR([makedepend is required to build Mesa])
+fi
+
+dnl Our fallback install-sh is a symlink to minstall. Use the existing
+dnl configuration in that case.
+AC_PROG_INSTALL
+test "x$INSTALL" = "x$ac_install_sh" && INSTALL='$(MINSTALL)'
+
+dnl We need a POSIX shell for parts of the build. Assume we have one
+dnl in most cases.
+case "$host_os" in
+solaris*)
+ # Solaris /bin/sh is too old/non-POSIX compliant
+ AC_PATH_PROGS(POSIX_SHELL, [ksh93 ksh sh])
+ SHELL="$POSIX_SHELL"
+ ;;
+esac
+
+dnl clang is mostly GCC-compatible, but its version is much lower,
+dnl so we have to check for it.
+AC_MSG_CHECKING([if compiling with clang])
+
+AC_COMPILE_IFELSE(
+[AC_LANG_PROGRAM([], [[
+#ifndef __clang__
+ not clang
+#endif
+]])],
+[CLANG=yes], [CLANG=no])
+
+AC_MSG_RESULT([$CLANG])
+
+dnl If we're using GCC, make sure that it is at least version 3.3.0. Older
+dnl versions are explictly not supported.
+if test "x$GCC" = xyes -a "x$CLANG" = xno; then
+ AC_MSG_CHECKING([whether gcc version is sufficient])
+ major=0
+ minor=0
+
+ GCC_VERSION=`$CC -dumpversion`
+ if test $? -eq 0; then
+ major=`echo $GCC_VERSION | cut -d. -f1`
+ minor=`echo $GCC_VERSION | cut -d. -f1`
+ fi
+
+ if test $major -lt 3 -o $major -eq 3 -a $minor -lt 3 ; then
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([If using GCC, version 3.3.0 or later is required.])
+ else
+ AC_MSG_RESULT([yes])
+ fi
+fi
+
+
+MKDEP_OPTIONS=-fdepend
+dnl Ask gcc where it's keeping its secret headers
+if test "x$GCC" = xyes; then
+ for dir in include include-fixed; do
+ GCC_INCLUDES=`$CC -print-file-name=$dir`
+ if test "x$GCC_INCLUDES" != x && \
+ test "$GCC_INCLUDES" != "$dir" && \
+ test -d "$GCC_INCLUDES"; then
+ MKDEP_OPTIONS="$MKDEP_OPTIONS -I$GCC_INCLUDES"
+ fi
+ done
+fi
+AC_SUBST([MKDEP_OPTIONS])
+
+dnl Make sure the pkg-config macros are defined
+m4_ifndef([PKG_PROG_PKG_CONFIG],
+ [m4_fatal([Could not locate the pkg-config autoconf macros.
+ These are usually located in /usr/share/aclocal/pkg.m4. If your macros
+ are in a different location, try setting the environment variable
+ ACLOCAL="aclocal -I/other/macro/dir" before running autoreconf.])])
+PKG_PROG_PKG_CONFIG()
+
+dnl LIB_DIR - library basename
+LIB_DIR=`echo $libdir | $SED 's%.*/%%'`
+AC_SUBST([LIB_DIR])
+
+dnl Cache LDFLAGS so we can add EXTRA_LIB_PATH and restore it later
+_SAVE_LDFLAGS="$LDFLAGS"
+AC_ARG_VAR([EXTRA_LIB_PATH],[Extra -L paths for the linker])
+AC_SUBST([EXTRA_LIB_PATH])
+
+dnl Cache CPPFLAGS so we can add *_INCLUDES and restore it later
+_SAVE_CPPFLAGS="$CPPFLAGS"
+AC_ARG_VAR([X11_INCLUDES],[Extra -I paths for X11 headers])
+AC_SUBST([X11_INCLUDES])
+
+dnl Compiler macros
+DEFINES=""
+AC_SUBST([DEFINES])
+case "$host_os" in
+linux*|*-gnu*|gnu*)
+ DEFINES="$DEFINES -D_GNU_SOURCE -DPTHREADS"
+ ;;
+solaris*)
+ DEFINES="$DEFINES -DPTHREADS -DSVR4"
+ ;;
+cygwin*)
+ DEFINES="$DEFINES -DPTHREADS"
+ ;;
+esac
+
+dnl Add flags for gcc and g++
+if test "x$GCC" = xyes; then
+ CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -std=c99"
+ if test "x$CLANG" = "xno"; then
+ CFLAGS="$CFLAGS -ffast-math"
+ fi
+
+ # Enable -fvisibility=hidden if using a gcc that supports it
+ save_CFLAGS="$CFLAGS"
+ AC_MSG_CHECKING([whether $CC supports -fvisibility=hidden])
+ VISIBILITY_CFLAGS="-fvisibility=hidden"
+ CFLAGS="$CFLAGS $VISIBILITY_CFLAGS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]),
+ [VISIBILITY_CFLAGS=""; AC_MSG_RESULT([no])]);
+
+ # Restore CFLAGS; VISIBILITY_CFLAGS are added to it where needed.
+ CFLAGS=$save_CFLAGS
+
+ # Work around aliasing bugs - developers should comment this out
+ CFLAGS="$CFLAGS -fno-strict-aliasing"
+fi
+if test "x$GXX" = xyes; then
+ CXXFLAGS="$CXXFLAGS -Wall"
+
+ # Enable -fvisibility=hidden if using a gcc that supports it
+ save_CXXFLAGS="$CXXFLAGS"
+ AC_MSG_CHECKING([whether $CXX supports -fvisibility=hidden])
+ VISIBILITY_CXXFLAGS="-fvisibility=hidden"
+ CXXFLAGS="$CXXFLAGS $VISIBILITY_CXXFLAGS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]),
+ [VISIBILITY_CXXFLAGS="" ; AC_MSG_RESULT([no])]);
+
+ # Restore CXXFLAGS; VISIBILITY_CXXFLAGS are added to it where needed.
+ CXXFLAGS=$save_CXXFLAGS
+
+ # Work around aliasing bugs - developers should comment this out
+ CXXFLAGS="$CXXFLAGS -fno-strict-aliasing"
+fi
+
+AC_SUBST([VISIBILITY_CFLAGS])
+AC_SUBST([VISIBILITY_CXXFLAGS])
+
+dnl These should be unnecessary, but let the user set them if they want
+AC_ARG_VAR([OPT_FLAGS], [Additional optimization flags for the compiler.
+ Default is to use CFLAGS.])
+AC_ARG_VAR([ARCH_FLAGS], [Additional architecture specific flags for the
+ compiler. Default is to use CFLAGS.])
+AC_SUBST([OPT_FLAGS])
+AC_SUBST([ARCH_FLAGS])
+
+dnl
+dnl Hacks to enable 32 or 64 bit build
+dnl
+AC_ARG_ENABLE([32-bit],
+ [AS_HELP_STRING([--enable-32-bit],
+ [build 32-bit libraries @<:@default=auto@:>@])],
+ [enable_32bit="$enableval"],
+ [enable_32bit=auto]
+)
+if test "x$enable_32bit" = xyes; then
+ if test "x$GCC" = xyes; then
+ CFLAGS="$CFLAGS -m32"
+ ARCH_FLAGS="$ARCH_FLAGS -m32"
+ fi
+ if test "x$GXX" = xyes; then
+ CXXFLAGS="$CXXFLAGS -m32"
+ fi
+fi
+AC_ARG_ENABLE([64-bit],
+ [AS_HELP_STRING([--enable-64-bit],
+ [build 64-bit libraries @<:@default=auto@:>@])],
+ [enable_64bit="$enableval"],
+ [enable_64bit=auto]
+)
+if test "x$enable_64bit" = xyes; then
+ if test "x$GCC" = xyes; then
+ CFLAGS="$CFLAGS -m64"
+ fi
+ if test "x$GXX" = xyes; then
+ CXXFLAGS="$CXXFLAGS -m64"
+ fi
+fi
+
+dnl
+dnl shared/static libraries, mimic libtool options
+dnl
+AC_ARG_ENABLE([static],
+ [AS_HELP_STRING([--enable-static],
+ [build static libraries @<:@default=disabled@:>@])],
+ [enable_static="$enableval"],
+ [enable_static=no]
+)
+case "x$enable_static" in
+xyes|xno ) ;;
+x ) enable_static=no ;;
+* )
+ AC_MSG_ERROR([Static library option '$enable_static' is not a valid])
+ ;;
+esac
+AC_ARG_ENABLE([shared],
+ [AS_HELP_STRING([--disable-shared],
+ [build shared libraries @<:@default=enabled@:>@])],
+ [enable_shared="$enableval"],
+ [enable_shared=yes]
+)
+case "x$enable_shared" in
+xyes|xno ) ;;
+x ) enable_shared=yes ;;
+* )
+ AC_MSG_ERROR([Shared library option '$enable_shared' is not a valid])
+ ;;
+esac
+
+dnl Can't have static and shared libraries, default to static if user
+dnl explicitly requested. If both disabled, set to static since shared
+dnl was explicitly requirested.
+case "x$enable_static$enable_shared" in
+xyesyes )
+ AC_MSG_WARN([Can't build static and shared libraries, disabling shared])
+ enable_shared=no
+ ;;
+xnono )
+ AC_MSG_WARN([Can't disable both static and shared libraries, enabling static])
+ enable_static=yes
+ ;;
+esac
+
+dnl
+dnl mklib options
+dnl
+AC_ARG_VAR([MKLIB_OPTIONS],[Options for the Mesa library script, mklib])
+if test "$enable_static" = yes; then
+ MKLIB_OPTIONS="$MKLIB_OPTIONS -static"
+fi
+AC_SUBST([MKLIB_OPTIONS])
+
+dnl
+dnl other compiler options
+dnl
+AC_ARG_ENABLE([debug],
+ [AS_HELP_STRING([--enable-debug],
+ [use debug compiler flags and macros @<:@default=disabled@:>@])],
+ [enable_debug="$enableval"],
+ [enable_debug=no]
+)
+if test "x$enable_debug" = xyes; then
+ DEFINES="$DEFINES -DDEBUG"
+ if test "x$GCC" = xyes; then
+ CFLAGS="$CFLAGS -g"
+ fi
+ if test "x$GXX" = xyes; then
+ CXXFLAGS="$CXXFLAGS -g"
+ fi
+fi
+
+dnl
+dnl library names
+dnl
+LIB_PREFIX_GLOB='lib'
+LIB_VERSION_SEPARATOR='.'
+if test "$enable_static" = yes; then
+ LIB_EXTENSION='a'
+else
+ case "$host_os" in
+ darwin* )
+ LIB_EXTENSION='dylib' ;;
+ cygwin* )
+ dnl prefix can be 'cyg' or 'lib'
+ LIB_PREFIX_GLOB='???'
+ LIB_VERSION_SEPARATOR='-'
+ LIB_EXTENSION='dll' ;;
+ aix* )
+ LIB_EXTENSION='a' ;;
+ * )
+ LIB_EXTENSION='so' ;;
+ esac
+fi
+
+GL_LIB_NAME='lib$(GL_LIB).'${LIB_EXTENSION}
+GLU_LIB_NAME='lib$(GLU_LIB).'${LIB_EXTENSION}
+GLUT_LIB_NAME='lib$(GLUT_LIB).'${LIB_EXTENSION}
+GLW_LIB_NAME='lib$(GLW_LIB).'${LIB_EXTENSION}
+OSMESA_LIB_NAME='lib$(OSMESA_LIB).'${LIB_EXTENSION}
+EGL_LIB_NAME='lib$(EGL_LIB).'${LIB_EXTENSION}
+GLESv1_CM_LIB_NAME='lib$(GLESv1_CM_LIB).'${LIB_EXTENSION}
+GLESv2_LIB_NAME='lib$(GLESv2_LIB).'${LIB_EXTENSION}
+VG_LIB_NAME='lib$(VG_LIB).'${LIB_EXTENSION}
+GLAPI_LIB_NAME='lib$(GLAPI_LIB).'${LIB_EXTENSION}
+WAYLAND_EGL_LIB_NAME='lib$(WAYLAND_EGL_LIB).'${LIB_EXTENSION}
+
+GL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+GLU_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLU_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+GLUT_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLUT_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+GLW_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLW_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+OSMESA_LIB_GLOB=${LIB_PREFIX_GLOB}'$(OSMESA_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+EGL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(EGL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+EGL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(EGL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+GLESv1_CM_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLESv1_CM_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+GLESv2_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLESv2_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+VG_LIB_GLOB=${LIB_PREFIX_GLOB}'$(VG_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+GLAPI_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLAPI_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+WAYLAND_EGL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(WAYLAND_EGL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*'
+
+AC_SUBST([GL_LIB_NAME])
+AC_SUBST([GLU_LIB_NAME])
+AC_SUBST([GLUT_LIB_NAME])
+AC_SUBST([GLW_LIB_NAME])
+AC_SUBST([OSMESA_LIB_NAME])
+AC_SUBST([EGL_LIB_NAME])
+AC_SUBST([GLESv1_CM_LIB_NAME])
+AC_SUBST([GLESv2_LIB_NAME])
+AC_SUBST([VG_LIB_NAME])
+AC_SUBST([GLAPI_LIB_NAME])
+AC_SUBST([WAYLAND_EGL_LIB_NAME])
+
+AC_SUBST([GL_LIB_GLOB])
+AC_SUBST([GLU_LIB_GLOB])
+AC_SUBST([GLUT_LIB_GLOB])
+AC_SUBST([GLW_LIB_GLOB])
+AC_SUBST([OSMESA_LIB_GLOB])
+AC_SUBST([EGL_LIB_GLOB])
+AC_SUBST([GLESv1_CM_LIB_GLOB])
+AC_SUBST([GLESv2_LIB_GLOB])
+AC_SUBST([VG_LIB_GLOB])
+AC_SUBST([GLAPI_LIB_GLOB])
+AC_SUBST([WAYLAND_EGL_LIB_GLOB])
+
+dnl
+dnl Arch/platform-specific settings
+dnl
+AC_ARG_ENABLE([asm],
+ [AS_HELP_STRING([--disable-asm],
+ [disable assembly usage @<:@default=enabled on supported plaforms@:>@])],
+ [enable_asm="$enableval"],
+ [enable_asm=yes]
+)
+asm_arch=""
+ASM_FLAGS=""
+MESA_ASM_SOURCES=""
+GLAPI_ASM_SOURCES=""
+AC_MSG_CHECKING([whether to enable assembly])
+test "x$enable_asm" = xno && AC_MSG_RESULT([no])
+# disable if cross compiling on x86/x86_64 since we must run gen_matypes
+if test "x$enable_asm" = xyes && test "x$cross_compiling" = xyes; then
+ case "$host_cpu" in
+ i?86 | x86_64)
+ enable_asm=no
+ AC_MSG_RESULT([no, cross compiling])
+ ;;
+ esac
+fi
+# check for supported arches
+if test "x$enable_asm" = xyes; then
+ case "$host_cpu" in
+ i?86)
+ case "$host_os" in
+ linux* | *freebsd* | dragonfly* | *netbsd*)
+ test "x$enable_64bit" = xyes && asm_arch=x86_64 || asm_arch=x86
+ ;;
+ esac
+ ;;
+ x86_64)
+ case "$host_os" in
+ linux* | *freebsd* | dragonfly* | *netbsd*)
+ test "x$enable_32bit" = xyes && asm_arch=x86 || asm_arch=x86_64
+ ;;
+ esac
+ ;;
+ powerpc)
+ case "$host_os" in
+ linux*)
+ asm_arch=ppc
+ ;;
+ esac
+ ;;
+ sparc*)
+ case "$host_os" in
+ linux*)
+ asm_arch=sparc
+ ;;
+ esac
+ ;;
+ esac
+
+ case "$asm_arch" in
+ x86)
+ ASM_FLAGS="-DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM"
+ MESA_ASM_SOURCES='$(X86_SOURCES)'
+ GLAPI_ASM_SOURCES='$(X86_API)'
+ AC_MSG_RESULT([yes, x86])
+ ;;
+ x86_64)
+ ASM_FLAGS="-DUSE_X86_64_ASM"
+ MESA_ASM_SOURCES='$(X86-64_SOURCES)'
+ GLAPI_ASM_SOURCES='$(X86-64_API)'
+ AC_MSG_RESULT([yes, x86_64])
+ ;;
+ ppc)
+ ASM_FLAGS="-DUSE_PPC_ASM -DUSE_VMX_ASM"
+ MESA_ASM_SOURCES='$(PPC_SOURCES)'
+ AC_MSG_RESULT([yes, ppc])
+ ;;
+ sparc)
+ ASM_FLAGS="-DUSE_SPARC_ASM"
+ MESA_ASM_SOURCES='$(SPARC_SOURCES)'
+ GLAPI_ASM_SOURCES='$(SPARC_API)'
+ AC_MSG_RESULT([yes, sparc])
+ ;;
+ *)
+ AC_MSG_RESULT([no, platform not supported])
+ ;;
+ esac
+fi
+AC_SUBST([ASM_FLAGS])
+AC_SUBST([MESA_ASM_SOURCES])
+AC_SUBST([GLAPI_ASM_SOURCES])
+
+dnl PIC code macro
+MESA_PIC_FLAGS
+
+dnl Check to see if dlopen is in default libraries (like Solaris, which
+dnl has it in libc), or if libdl is needed to get it.
+AC_CHECK_FUNC([dlopen], [],
+ [AC_CHECK_LIB([dl], [dlopen], [DLOPEN_LIBS="-ldl"])])
+AC_SUBST([DLOPEN_LIBS])
+
+dnl See if posix_memalign is available
+AC_CHECK_FUNC([posix_memalign], [DEFINES="$DEFINES -DHAVE_POSIX_MEMALIGN"])
+
+dnl SELinux awareness.
+AC_ARG_ENABLE([selinux],
+ [AS_HELP_STRING([--enable-selinux],
+ [Build SELinux-aware Mesa @<:@default=disabled@:>@])],
+ [MESA_SELINUX="$enableval"],
+ [MESA_SELINUX=no])
+if test "x$enable_selinux" = "xyes"; then
+ AC_CHECK_HEADER([selinux/selinux.h],[],
+ [AC_MSG_ERROR([SELinux headers not found])])
+ AC_CHECK_LIB([selinux],[is_selinux_enabled],[],
+ [AC_MSG_ERROR([SELinux library not found])])
+ SELINUX_LIBS="-lselinux"
+ DEFINES="$DEFINES -DMESA_SELINUX"
+fi
+
+dnl Determine which APIs to support
+AC_ARG_ENABLE([opengl],
+ [AS_HELP_STRING([--disable-opengl],
+ [disable support for standard OpenGL API @<:@default=no@:>@])],
+ [enable_opengl="$enableval"],
+ [enable_opengl=yes])
+AC_ARG_ENABLE([gles1],
+ [AS_HELP_STRING([--enable-gles1],
+ [enable support for OpenGL ES 1.x API @<:@default=no@:>@])],
+ [enable_gles1="$enableval"],
+ [enable_gles1=no])
+AC_ARG_ENABLE([gles2],
+ [AS_HELP_STRING([--enable-gles2],
+ [enable support for OpenGL ES 2.x API @<:@default=no@:>@])],
+ [enable_gles2="$enableval"],
+ [enable_gles2=no])
+AC_ARG_ENABLE([gles-overlay],
+ [AS_HELP_STRING([--enable-gles-overlay],
+ [DEPRECATED. Same as --enable-gles1 and --enable-gles2])],
+ [enable_gles1="$enableval"; enable_gles2="$enableval"],
+ [])
+
+AC_ARG_ENABLE([openvg],
+ [AS_HELP_STRING([--enable-openvg],
+ [enable support for OpenVG API @<:@default=no@:>@])],
+ [enable_openvg="$enableval"],
+ [enable_openvg=no])
+
+dnl smooth the transition; should be removed eventually
+if test "x$enable_openvg" = xno; then
+ case "x$with_state_trackers" in
+ x*vega*)
+ AC_MSG_WARN([vega state tracker is enabled without --enable-openvg])
+ enable_openvg=yes
+ ;;
+ esac
+fi
+
+if test "x$enable_opengl" = xno -a \
+ "x$enable_gles1" = xno -a \
+ "x$enable_gles2" = xno -a \
+ "x$enable_openvg" = xno; then
+ AC_MSG_ERROR([at least one API should be enabled])
+fi
+
+API_DEFINES=""
+if test "x$enable_opengl" = xno; then
+ API_DEFINES="$API_DEFINES -DFEATURE_GL=0"
+else
+ API_DEFINES="$API_DEFINES -DFEATURE_GL=1"
+fi
+if test "x$enable_gles1" = xyes; then
+ API_DEFINES="$API_DEFINES -DFEATURE_ES1=1"
+fi
+if test "x$enable_gles2" = xyes; then
+ API_DEFINES="$API_DEFINES -DFEATURE_ES2=1"
+fi
+AC_SUBST([API_DEFINES])
+
+AC_ARG_ENABLE([shared-glapi],
+ [AS_HELP_STRING([--enable-shared-glapi],
+ [EXPERIMENTAL. Enable shared glapi for OpenGL @<:@default=no@:>@])],
+ [enable_shared_glapi="$enableval"],
+ [enable_shared_glapi=no])
+
+SHARED_GLAPI="0"
+if test "x$enable_shared_glapi" = xyes; then
+ SHARED_GLAPI="1"
+fi
+AC_SUBST([SHARED_GLAPI])
+
+dnl
+dnl Driver configuration. Options are xlib, dri and osmesa right now.
+dnl More later: fbdev, ...
+dnl
+default_driver="xlib"
+
+case "$host_os" in
+linux*)
+ case "$host_cpu" in
+ i*86|x86_64|powerpc*|sparc*) default_driver="dri";;
+ esac
+ ;;
+*freebsd* | dragonfly* | *netbsd*)
+ case "$host_cpu" in
+ i*86|x86_64|powerpc*|sparc*) default_driver="dri";;
+ esac
+ ;;
+esac
+
+if test "x$enable_opengl" = xno; then
+ default_driver="no"
+fi
+
+AC_ARG_WITH([driver],
+ [AS_HELP_STRING([--with-driver=DRIVER],
+ [driver for Mesa: xlib,dri,osmesa @<:@default=dri when available, or xlib@:>@])],
+ [mesa_driver="$withval"],
+ [mesa_driver="$default_driver"])
+dnl Check for valid option
+case "x$mesa_driver" in
+xxlib|xdri|xosmesa)
+ if test "x$enable_opengl" = xno; then
+ AC_MSG_ERROR([Driver '$mesa_driver' requires OpenGL enabled])
+ fi
+ ;;
+xno)
+ ;;
+*)
+ AC_MSG_ERROR([Driver '$mesa_driver' is not a valid option])
+ ;;
+esac
+
+dnl
+dnl Driver specific build directories
+dnl
+
+dnl this variable will be prepended to SRC_DIRS and is not exported
+CORE_DIRS=""
+
+SRC_DIRS=""
+GLU_DIRS="sgi"
+GALLIUM_DIRS="auxiliary drivers state_trackers"
+GALLIUM_TARGET_DIRS=""
+GALLIUM_WINSYS_DIRS="sw"
+GALLIUM_DRIVERS_DIRS="softpipe failover galahad trace rbug noop identity"
+GALLIUM_STATE_TRACKERS_DIRS=""
+
+# build shared-glapi if enabled for OpenGL or if OpenGL ES is enabled
+case "x$enable_shared_glapi$enable_gles1$enable_gles2" in
+x*yes*)
+ CORE_DIRS="$CORE_DIRS mapi/shared-glapi"
+ ;;
+esac
+
+# build glapi if OpenGL is enabled
+if test "x$enable_opengl" = xyes; then
+ CORE_DIRS="$CORE_DIRS mapi/glapi"
+fi
+
+# build es1api if OpenGL ES 1.x is enabled
+if test "x$enable_gles1" = xyes; then
+ CORE_DIRS="$CORE_DIRS mapi/es1api"
+fi
+
+# build es2api if OpenGL ES 2.x is enabled
+if test "x$enable_gles2" = xyes; then
+ CORE_DIRS="$CORE_DIRS mapi/es2api"
+fi
+
+# build vgapi if OpenVG is enabled
+if test "x$enable_openvg" = xyes; then
+ CORE_DIRS="$CORE_DIRS mapi/vgapi"
+fi
+
+# build glsl and mesa if OpenGL or OpenGL ES is enabled
+case "x$enable_opengl$enable_gles1$enable_gles2" in
+x*yes*)
+ CORE_DIRS="$CORE_DIRS glsl mesa"
+ ;;
+esac
+
+case "$mesa_driver" in
+xlib)
+ DRIVER_DIRS="x11"
+ GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib"
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS libgl-xlib"
+ ;;
+dri)
+ SRC_DIRS="$SRC_DIRS glx"
+ DRIVER_DIRS="dri"
+ GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/dri"
+ ;;
+osmesa)
+ DRIVER_DIRS="osmesa"
+ ;;
+no)
+ DRIVER_DRIS=""
+ ;;
+esac
+AC_SUBST([SRC_DIRS])
+AC_SUBST([GLU_DIRS])
+AC_SUBST([DRIVER_DIRS])
+AC_SUBST([GALLIUM_DIRS])
+AC_SUBST([GALLIUM_TARGET_DIRS])
+AC_SUBST([GALLIUM_WINSYS_DIRS])
+AC_SUBST([GALLIUM_DRIVERS_DIRS])
+AC_SUBST([GALLIUM_STATE_TRACKERS_DIRS])
+AC_SUBST([MESA_LLVM])
+
+dnl
+dnl Find out if X is available. The variable have_x is set if libX11 is
+dnl found to mimic AC_PATH_XTRA.
+dnl
+if test -n "$PKG_CONFIG"; then
+ AC_MSG_CHECKING([pkg-config files for X11 are available])
+ PKG_CHECK_EXISTS([x11],[
+ x11_pkgconfig=yes
+ have_x=yes
+ ],[
+ x11_pkgconfig=no
+ ])
+ AC_MSG_RESULT([$x11_pkgconfig])
+else
+ x11_pkgconfig=no
+fi
+dnl Use the autoconf macro if no pkg-config files
+if test "$x11_pkgconfig" = yes; then
+ PKG_CHECK_MODULES([X11], [x11])
+else
+ AC_PATH_XTRA
+ test -z "$X11_CFLAGS" && X11_CFLAGS="$X_CFLAGS"
+ test -z "$X11_LIBS" && X11_LIBS="$X_LIBS -lX11"
+ AC_SUBST([X11_CFLAGS])
+ AC_SUBST([X11_LIBS])
+fi
+
+dnl Try to tell the user that the --x-* options are only used when
+dnl pkg-config is not available. This must be right after AC_PATH_XTRA.
+m4_divert_once([HELP_BEGIN],
+[These options are only used when the X libraries cannot be found by the
+pkg-config utility.])
+
+dnl We need X for xlib and dri, so bomb now if it's not found
+case "$mesa_driver" in
+xlib|dri)
+ if test "$no_x" = yes; then
+ AC_MSG_ERROR([X11 development libraries needed for $mesa_driver driver])
+ fi
+ ;;
+esac
+
+dnl XCB - this is only used for GLX right now
+AC_ARG_ENABLE([xcb],
+ [AS_HELP_STRING([--enable-xcb],
+ [use XCB for GLX @<:@default=disabled@:>@])],
+ [enable_xcb="$enableval"],
+ [enable_xcb=no])
+if test "x$enable_xcb" = xyes; then
+ DEFINES="$DEFINES -DUSE_XCB"
+else
+ enable_xcb=no
+fi
+
+dnl
+dnl libGL configuration per driver
+dnl
+case "$mesa_driver" in
+xlib)
+ if test "$x11_pkgconfig" = yes; then
+ PKG_CHECK_MODULES([XLIBGL], [x11 xext])
+ GL_PC_REQ_PRIV="x11 xext"
+ X11_INCLUDES="$X11_INCLUDES $XLIBGL_CFLAGS"
+ GL_LIB_DEPS="$XLIBGL_LIBS"
+ else
+ # should check these...
+ X11_INCLUDES="$X11_INCLUDES $X_CFLAGS"
+ GL_LIB_DEPS="$X_LIBS -lX11 -lXext"
+ GL_PC_LIB_PRIV="$GL_LIB_DEPS"
+ GL_PC_CFLAGS="$X11_INCLUDES"
+ fi
+ GL_LIB_DEPS="$GL_LIB_DEPS $SELINUX_LIBS -lm -lpthread"
+ GL_PC_LIB_PRIV="$GL_PC_LIB_PRIV $SELINUX_LIBS -lm -lpthread"
+
+ # if static, move the external libraries to the programs
+ # and empty the libraries for libGL
+ if test "$enable_static" = yes; then
+ APP_LIB_DEPS="$APP_LIB_DEPS $GL_LIB_DEPS"
+ GL_LIB_DEPS=""
+ fi
+ ;;
+dri|no) # these checks are still desired when there is no mesa_driver
+ # DRI must be shared, I think
+ if test "$enable_static" = yes; then
+ AC_MSG_ERROR([Can't use static libraries for DRI drivers])
+ fi
+
+ # Check for libdrm
+ PKG_CHECK_MODULES([LIBDRM], [libdrm >= $LIBDRM_REQUIRED])
+ PKG_CHECK_MODULES([DRI2PROTO], [dri2proto >= $DRI2PROTO_REQUIRED])
+ PKG_CHECK_MODULES([GLPROTO], [glproto >= $GLPROTO_REQUIRED])
+ GL_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED dri2proto >= $DRI2PROTO_REQUIRED glproto >= $GLPROTO_REQUIRED"
+ DRI_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED"
+
+ # find the DRI deps for libGL
+ if test "$x11_pkgconfig" = yes; then
+ dri_modules="x11 xext xdamage xfixes"
+
+ # add xf86vidmode if available
+ PKG_CHECK_MODULES([XF86VIDMODE], [xxf86vm], HAVE_XF86VIDMODE=yes, HAVE_XF86VIDMODE=no)
+ if test "$HAVE_XF86VIDMODE" = yes ; then
+ dri_modules="$dri_modules xxf86vm"
+ fi
+
+ # add xcb modules if necessary
+ if test "$enable_xcb" = yes; then
+ dri_modules="$dri_modules x11-xcb xcb-glx"
+ fi
+
+ PKG_CHECK_MODULES([DRIGL], [$dri_modules])
+ GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV $dri_modules"
+ X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS"
+ GL_LIB_DEPS="$DRIGL_LIBS"
+ else
+ # should check these...
+ X11_INCLUDES="$X11_INCLUDES $X_CFLAGS"
+ GL_LIB_DEPS="$X_LIBS -lX11 -lXext -lXxf86vm -lXdamage -lXfixes"
+ GL_PC_LIB_PRIV="$GL_LIB_DEPS"
+ GL_PC_CFLAGS="$X11_INCLUDES"
+
+ # XCB can only be used from pkg-config
+ if test "$enable_xcb" = yes; then
+ PKG_CHECK_MODULES([XCB],[x11-xcb xcb-glx])
+ GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV x11-xcb xcb-glx"
+ X11_INCLUDES="$X11_INCLUDES $XCB_CFLAGS"
+ GL_LIB_DEPS="$GL_LIB_DEPS $XCB_LIBS"
+ fi
+ fi
+
+ # need DRM libs, -lpthread, etc.
+ GL_LIB_DEPS="$GL_LIB_DEPS $LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS"
+ GL_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS"
+ GLESv1_CM_LIB_DEPS="$LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS"
+ GLESv1_CM_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS"
+ GLESv2_LIB_DEPS="$LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS"
+ GLESv2_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS"
+ ;;
+osmesa)
+ # No libGL for osmesa
+ GL_LIB_DEPS=""
+ ;;
+esac
+AC_SUBST([GL_LIB_DEPS])
+AC_SUBST([GL_PC_REQ_PRIV])
+AC_SUBST([GL_PC_LIB_PRIV])
+AC_SUBST([GL_PC_CFLAGS])
+AC_SUBST([DRI_PC_REQ_PRIV])
+AC_SUBST([GLESv1_CM_LIB_DEPS])
+AC_SUBST([GLESv1_CM_PC_LIB_PRIV])
+AC_SUBST([GLESv2_LIB_DEPS])
+AC_SUBST([GLESv2_PC_LIB_PRIV])
+
+GLAPI_LIB_DEPS="-lpthread"
+AC_SUBST([GLAPI_LIB_DEPS])
+
+
+dnl Setup default DRI CFLAGS
+DRI_CFLAGS='$(CFLAGS)'
+DRI_CXXFLAGS='$(CXXFLAGS)'
+DRI_LIB_DEPS='$(TOP)/src/mesa/libmesa.a'
+MESA_MODULES='$(TOP)/src/mesa/libmesa.a'
+
+AC_ARG_ENABLE([shared-dricore],
+ [AS_HELP_STRING([--enable-shared-dricore],
+ [link DRI modules with shared core DRI routines @<:@default=disabled@:>@])],
+ [enable_dricore="$enableval"],
+ [enable_dricore=no])
+if test "$mesa_driver" = dri ; then
+ if test "$enable_dricore" = yes ; then
+ if test "$GCC$GXX" != yesyes ; then
+ AC_MSG_WARN([Shared dricore requires GCC-compatible rpath handling. Disabling shared dricore])
+ enable_dricore=no
+ else
+ DRICORE_GLSL_LIBS='$(TOP)/$(LIB_DIR)/libglsl.so'
+ DRICORE_LIBS='$(TOP)/$(LIB_DIR)/libdricore.so'
+ DRICORE_LIB_DEPS='-L$(TOP)/$(LIB_DIR) -Wl,-R$(DRI_DRIVER_INSTALL_DIR) -lglsl'
+ DRI_LIB_DEPS='-L$(TOP)/$(LIB_DIR) -Wl,-R$(DRI_DRIVER_INSTALL_DIR) -ldricore -lglsl'
+ DRI_CFLAGS='$(CFLAGS_NOVISIBILITY) -DUSE_DRICORE'
+ DRI_CXXFLAGS='$(CXXFLAGS_NOVISIBILITY) -DUSE_DRICORE'
+ MESA_MODULES='$(DRICORE_LIBS) $(DRICORE_GLSL_LIBS)'
+ fi
+ fi
+fi
+AC_SUBST([DRICORE_LIBS])
+AC_SUBST([DRICORE_GLSL_LIBS])
+AC_SUBST([DRICORE_LIB_DEPS])
+AC_SUBST([DRI_CXXFLAGS])
+AC_SUBST([DRI_CFLAGS])
+AC_SUBST([MESA_MODULES])
+
+AC_SUBST([HAVE_XF86VIDMODE])
+
+PKG_CHECK_MODULES([LIBDRM_RADEON],
+ [libdrm_radeon >= $LIBDRM_RADEON_REQUIRED],
+ HAVE_LIBDRM_RADEON=yes,
+ HAVE_LIBDRM_RADEON=no)
+
+dnl
+dnl More X11 setup
+dnl
+if test "$mesa_driver" = xlib; then
+ DEFINES="$DEFINES -DUSE_XSHM"
+fi
+
+dnl
+dnl TLS detection
+dnl
+
+AC_ARG_ENABLE([glx-tls],
+ [AS_HELP_STRING([--enable-glx-tls],
+ [enable TLS support in GLX @<:@default=disabled@:>@])],
+ [GLX_USE_TLS="$enableval"],
+ [GLX_USE_TLS=no])
+AC_SUBST(GLX_TLS, ${GLX_USE_TLS})
+
+AS_IF([test "x$GLX_USE_TLS" = xyes],
+ [DEFINES="${DEFINES} -DGLX_USE_TLS -DPTHREADS"])
+
+dnl
+dnl More DRI setup
+dnl
+dnl Directory for DRI drivers
+AC_ARG_WITH([dri-driverdir],
+ [AS_HELP_STRING([--with-dri-driverdir=DIR],
+ [directory for the DRI drivers @<:@${libdir}/dri@:>@])],
+ [DRI_DRIVER_INSTALL_DIR="$withval"],
+ [DRI_DRIVER_INSTALL_DIR='${libdir}/dri'])
+AC_SUBST([DRI_DRIVER_INSTALL_DIR])
+dnl Extra search path for DRI drivers
+AC_ARG_WITH([dri-searchpath],
+ [AS_HELP_STRING([--with-dri-searchpath=DIRS...],
+ [semicolon delimited DRI driver search directories @<:@${libdir}/dri@:>@])],
+ [DRI_DRIVER_SEARCH_DIR="$withval"],
+ [DRI_DRIVER_SEARCH_DIR='${DRI_DRIVER_INSTALL_DIR}'])
+AC_SUBST([DRI_DRIVER_SEARCH_DIR])
+dnl Direct rendering or just indirect rendering
+AC_ARG_ENABLE([driglx-direct],
+ [AS_HELP_STRING([--disable-driglx-direct],
+ [enable direct rendering in GLX and EGL for DRI @<:@default=enabled@:>@])],
+ [driglx_direct="$enableval"],
+ [driglx_direct="yes"])
+dnl Which drivers to build - default is chosen by platform
+AC_ARG_WITH([dri-drivers],
+ [AS_HELP_STRING([--with-dri-drivers@<:@=DIRS...@:>@],
+ [comma delimited DRI drivers list, e.g.
+ "swrast,i965,radeon" @<:@default=auto@:>@])],
+ [with_dri_drivers="$withval"],
+ [with_dri_drivers=yes])
+if test "x$with_dri_drivers" = x; then
+ with_dri_drivers=no
+fi
+
+dnl If $with_dri_drivers is yes, directories will be added through
+dnl platform checks
+DRI_DIRS=""
+case "$with_dri_drivers" in
+no) ;;
+yes)
+ DRI_DIRS="yes"
+ ;;
+*)
+ # verify the requested driver directories exist
+ dri_drivers=`IFS=', '; echo $with_dri_drivers`
+ for driver in $dri_drivers; do
+ test -d "$srcdir/src/mesa/drivers/dri/$driver" || \
+ AC_MSG_ERROR([DRI driver directory '$driver' doesn't exist])
+ done
+ DRI_DIRS="$dri_drivers"
+ ;;
+esac
+
+dnl Set DRI_DIRS, DEFINES and LIB_DEPS
+if test "$mesa_driver" = dri -o "$mesa_driver" = no; then
+ # Platform specific settings and drivers to build
+ case "$host_os" in
+ linux*)
+ DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER"
+ if test "x$driglx_direct" = xyes; then
+ DEFINES="$DEFINES -DGLX_DIRECT_RENDERING"
+ fi
+ DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS"
+
+ case "$host_cpu" in
+ x86_64)
+ # sis is missing because they have not be converted to use
+ # the new interface. i810 are missing because there is no
+ # x86-64 system where they could *ever* be used.
+ if test "x$DRI_DIRS" = "xyes"; then
+ DRI_DIRS="i915 i965 mach64 mga r128 r200 r300 r600 radeon \
+ savage tdfx unichrome swrast"
+ fi
+ ;;
+ powerpc*)
+ # Build only the drivers for cards that exist on PowerPC.
+ # At some point MGA will be added, but not yet.
+ if test "x$DRI_DIRS" = "xyes"; then
+ DRI_DIRS="mach64 r128 r200 r300 r600 radeon tdfx swrast"
+ fi
+ ;;
+ sparc*)
+ # Build only the drivers for cards that exist on sparc`
+ if test "x$DRI_DIRS" = "xyes"; then
+ DRI_DIRS="mach64 r128 r200 r300 r600 radeon swrast"
+ fi
+ ;;
+ esac
+ ;;
+ freebsd* | dragonfly* | *netbsd*)
+ DEFINES="$DEFINES -DPTHREADS -DUSE_EXTERNAL_DXTN_LIB=1"
+ DEFINES="$DEFINES -DIN_DRI_DRIVER -DHAVE_ALIAS"
+ DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING"
+ if test "x$driglx_direct" = xyes; then
+ DEFINES="$DEFINES -DGLX_DIRECT_RENDERING"
+ fi
+
+ if test "x$DRI_DIRS" = "xyes"; then
+ DRI_DIRS="i810 i915 i965 mach64 mga r128 r200 r300 r600 radeon tdfx \
+ unichrome savage sis swrast"
+ fi
+ ;;
+ gnu*)
+ DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER"
+ DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS"
+ ;;
+ solaris*)
+ DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER"
+ DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING"
+ if test "x$driglx_direct" = xyes; then
+ DEFINES="$DEFINES -DGLX_DIRECT_RENDERING"
+ fi
+ ;;
+ esac
+
+ # default drivers
+ if test "x$DRI_DIRS" = "xyes"; then
+ DRI_DIRS="i810 i915 i965 mach64 mga r128 r200 r300 r600 radeon \
+ savage sis tdfx unichrome swrast"
+ fi
+
+ DRI_DIRS=`echo "$DRI_DIRS" | $SED 's/ */ /g'`
+
+ # Check for expat
+ if test "$mesa_driver" = dri; then
+ EXPAT_INCLUDES=""
+ EXPAT_LIB=-lexpat
+ AC_ARG_WITH([expat],
+ [AS_HELP_STRING([--with-expat=DIR],
+ [expat install directory])],[
+ EXPAT_INCLUDES="-I$withval/include"
+ CPPFLAGS="$CPPFLAGS $EXPAT_INCLUDES"
+ LDFLAGS="$LDFLAGS -L$withval/$LIB_DIR"
+ EXPAT_LIB="-L$withval/$LIB_DIR -lexpat"
+ ])
+ AC_CHECK_HEADER([expat.h],[],[AC_MSG_ERROR([Expat required for DRI.])])
+ AC_CHECK_LIB([expat],[XML_ParserCreate],[],
+ [AC_MSG_ERROR([Expat required for DRI.])])
+ fi
+
+ # put all the necessary libs together, including possibly libdricore
+ DRI_LIB_DEPS="$DRI_LIB_DEPS $SELINUX_LIBS $LIBDRM_LIBS $EXPAT_LIB -lm -lpthread $DLOPEN_LIBS"
+fi
+AC_SUBST([DRI_DIRS])
+AC_SUBST([EXPAT_INCLUDES])
+AC_SUBST([DRI_LIB_DEPS])
+
+case $DRI_DIRS in
+*i915*|*i965*)
+ PKG_CHECK_MODULES([INTEL], [libdrm_intel >= $LIBDRM_INTEL_REQUIRED])
+ ;;
+esac
+
+case $DRI_DIRS in
+*radeon*|*r200*|*r300*|*r600*)
+ if test "x$HAVE_LIBDRM_RADEON" = xyes; then
+ RADEON_CFLAGS="-DHAVE_LIBDRM_RADEON=1 $LIBDRM_RADEON_CFLAGS"
+ RADEON_LDFLAGS=$LIBDRM_RADEON_LIBS
+ fi
+ ;;
+esac
+AC_SUBST([RADEON_CFLAGS])
+AC_SUBST([RADEON_LDFLAGS])
+
+
+dnl
+dnl OSMesa configuration
+dnl
+if test "$mesa_driver" = xlib; then
+ default_gl_osmesa=yes
+else
+ default_gl_osmesa=no
+fi
+AC_ARG_ENABLE([gl-osmesa],
+ [AS_HELP_STRING([--enable-gl-osmesa],
+ [enable OSMesa with libGL @<:@default=enabled for xlib driver@:>@])],
+ [gl_osmesa="$enableval"],
+ [gl_osmesa="$default_gl_osmesa"])
+if test "x$gl_osmesa" = xyes; then
+ if test "x$enable_opengl" = xno; then
+ AC_MSG_ERROR([OpenGL is not available for OSMesa driver])
+ fi
+ if test "$mesa_driver" = osmesa; then
+ AC_MSG_ERROR([libGL is not available for OSMesa driver])
+ else
+ DRIVER_DIRS="$DRIVER_DIRS osmesa"
+ fi
+fi
+
+dnl Configure the channel bits for OSMesa (libOSMesa, libOSMesa16, ...)
+AC_ARG_WITH([osmesa-bits],
+ [AS_HELP_STRING([--with-osmesa-bits=BITS],
+ [OSMesa channel bits and library name: 8, 16, 32 @<:@default=8@:>@])],
+ [osmesa_bits="$withval"],
+ [osmesa_bits=8])
+if test "$mesa_driver" != osmesa && test "x$osmesa_bits" != x8; then
+ AC_MSG_WARN([Ignoring OSMesa channel bits for non-OSMesa driver])
+ osmesa_bits=8
+fi
+case "x$osmesa_bits" in
+x8)
+ OSMESA_LIB=OSMesa
+ ;;
+x16|x32)
+ OSMESA_LIB="OSMesa$osmesa_bits"
+ DEFINES="$DEFINES -DCHAN_BITS=$osmesa_bits -DDEFAULT_SOFTWARE_DEPTH_BITS=31"
+ ;;
+*)
+ AC_MSG_ERROR([OSMesa bits '$osmesa_bits' is not a valid option])
+ ;;
+esac
+AC_SUBST([OSMESA_LIB])
+
+case "$DRIVER_DIRS" in
+*osmesa*)
+ # only link libraries with osmesa if shared
+ if test "$enable_static" = no; then
+ OSMESA_LIB_DEPS="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS"
+ else
+ OSMESA_LIB_DEPS=""
+ fi
+ OSMESA_MESA_DEPS=""
+ OSMESA_PC_LIB_PRIV="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS"
+ ;;
+esac
+AC_SUBST([OSMESA_LIB_DEPS])
+AC_SUBST([OSMESA_MESA_DEPS])
+AC_SUBST([OSMESA_PC_REQ])
+AC_SUBST([OSMESA_PC_LIB_PRIV])
+
+dnl
+dnl EGL configuration
+dnl
+AC_ARG_ENABLE([egl],
+ [AS_HELP_STRING([--disable-egl],
+ [disable EGL library @<:@default=enabled@:>@])],
+ [enable_egl="$enableval"],
+ [enable_egl=yes])
+if test "x$enable_egl" = xno; then
+ if test "x$mesa_driver" = xno; then
+ AC_MSG_ERROR([cannot disable EGL when there is no mesa driver])
+ fi
+ if test "x$enable_openvg" = xyes; then
+ AC_MSG_ERROR([cannot enable OpenVG without EGL])
+ fi
+fi
+if test "x$enable_egl" = xyes; then
+ SRC_DIRS="$SRC_DIRS egl"
+ EGL_LIB_DEPS="$DLOPEN_LIBS -lpthread"
+ EGL_DRIVERS_DIRS=""
+ if test "$enable_static" != yes; then
+ # build egl_glx when libGL is built
+ if test "$mesa_driver" = xlib -o "$mesa_driver" = dri; then
+ EGL_DRIVERS_DIRS="glx"
+ fi
+
+ if test "$mesa_driver" = dri; then
+ # build egl_dri2 when xcb-dri2 is available
+ PKG_CHECK_MODULES([XCB_DRI2], [x11-xcb xcb-dri2 xcb-xfixes],
+ [have_xcb_dri2=yes],[have_xcb_dri2=no])
+ PKG_CHECK_MODULES([LIBUDEV], [libudev > 150],
+ [have_libudev=yes],[have_libudev=no])
+
+ if test "$have_xcb_dri2" = yes; then
+ EGL_DRIVER_DRI2=dri2
+ DEFINES="$DEFINES -DHAVE_XCB_DRI2"
+ if test "$have_libudev" = yes; then
+ DEFINES="$DEFINES -DHAVE_LIBUDEV"
+ fi
+ fi
+ fi
+
+ EGL_DRIVERS_DIRS="$EGL_DRIVERS_DIRS $EGL_DRIVER_DRI2"
+ fi
+fi
+AC_SUBST([EGL_LIB_DEPS])
+AC_SUBST([EGL_DRIVERS_DIRS])
+
+dnl
+dnl GLU configuration
+dnl
+AC_ARG_ENABLE([glu],
+ [AS_HELP_STRING([--disable-glu],
+ [enable OpenGL Utility library @<:@default=enabled@:>@])],
+ [enable_glu="$enableval"],
+ [enable_glu=yes])
+
+if test "x$enable_glu" = xyes -a "x$mesa_driver" = xno; then
+ AC_MSG_NOTICE([Disabling GLU since there is no OpenGL driver])
+ enable_glu=no
+fi
+
+if test "x$enable_glu" = xyes; then
+ SRC_DIRS="$SRC_DIRS glu"
+
+ case "$mesa_driver" in
+ osmesa)
+ # Link libGLU to libOSMesa instead of libGL
+ GLU_LIB_DEPS=""
+ GLU_PC_REQ="osmesa"
+ if test "$enable_static" = no; then
+ GLU_MESA_DEPS='-l$(OSMESA_LIB)'
+ else
+ GLU_MESA_DEPS=""
+ fi
+ ;;
+ *)
+ # If static, empty GLU_LIB_DEPS and add libs for programs to link
+ GLU_PC_REQ="gl"
+ GLU_PC_LIB_PRIV="-lm"
+ if test "$enable_static" = no; then
+ GLU_LIB_DEPS="-lm"
+ GLU_MESA_DEPS='-l$(GL_LIB)'
+ else
+ GLU_LIB_DEPS=""
+ GLU_MESA_DEPS=""
+ APP_LIB_DEPS="$APP_LIB_DEPS -lstdc++"
+ fi
+ ;;
+ esac
+fi
+if test "$enable_static" = no; then
+ GLU_LIB_DEPS="$GLU_LIB_DEPS $OS_CPLUSPLUS_LIBS"
+fi
+GLU_PC_LIB_PRIV="$GLU_PC_LIB_PRIV $OS_CPLUSPLUS_LIBS"
+AC_SUBST([GLU_LIB_DEPS])
+AC_SUBST([GLU_MESA_DEPS])
+AC_SUBST([GLU_PC_REQ])
+AC_SUBST([GLU_PC_REQ_PRIV])
+AC_SUBST([GLU_PC_LIB_PRIV])
+AC_SUBST([GLU_PC_CFLAGS])
+
+dnl
+dnl GLw configuration
+dnl
+AC_ARG_ENABLE([glw],
+ [AS_HELP_STRING([--disable-glw],
+ [enable Xt/Motif widget library @<:@default=enabled@:>@])],
+ [enable_glw="$enableval"],
+ [enable_glw=yes])
+dnl Don't build GLw on osmesa
+if test "x$enable_glw" = xyes; then
+ case "$mesa_driver" in
+ osmesa|no)
+ AC_MSG_NOTICE([Disabling GLw since there is no OpenGL driver])
+ enable_glw=no
+ ;;
+ esac
+fi
+AC_ARG_ENABLE([motif],
+ [AS_HELP_STRING([--enable-motif],
+ [use Motif widgets in GLw @<:@default=disabled@:>@])],
+ [enable_motif="$enableval"],
+ [enable_motif=no])
+
+if test "x$enable_glw" = xyes; then
+ SRC_DIRS="$SRC_DIRS glw"
+ if test "$x11_pkgconfig" = yes; then
+ PKG_CHECK_MODULES([GLW],[x11 xt])
+ GLW_PC_REQ_PRIV="x11 xt"
+ GLW_LIB_DEPS="$GLW_LIBS"
+ else
+ # should check these...
+ GLW_LIB_DEPS="$X_LIBS -lXt -lX11"
+ GLW_PC_LIB_PRIV="$GLW_LIB_DEPS"
+ GLW_PC_CFLAGS="$X11_INCLUDES"
+ fi
+
+ GLW_SOURCES="GLwDrawA.c"
+ MOTIF_CFLAGS=
+ if test "x$enable_motif" = xyes; then
+ GLW_SOURCES="$GLW_SOURCES GLwMDrawA.c"
+ AC_PATH_PROG([MOTIF_CONFIG], [motif-config], [no])
+ if test "x$MOTIF_CONFIG" != xno; then
+ MOTIF_CFLAGS=`$MOTIF_CONFIG --cflags`
+ MOTIF_LIBS=`$MOTIF_CONFIG --libs`
+ else
+ AC_CHECK_HEADER([Xm/PrimitiveP.h], [],
+ [AC_MSG_ERROR([Can't locate Motif headers])])
+ AC_CHECK_LIB([Xm], [XmGetPixmap], [MOTIF_LIBS="-lXm"],
+ [AC_MSG_ERROR([Can't locate Motif Xm library])])
+ fi
+ # MOTIF_LIBS is prepended to GLW_LIB_DEPS since Xm needs Xt/X11
+ GLW_LIB_DEPS="$MOTIF_LIBS $GLW_LIB_DEPS"
+ GLW_PC_LIB_PRIV="$MOTIF_LIBS $GLW_PC_LIB_PRIV"
+ GLW_PC_CFLAGS="$MOTIF_CFLAGS $GLW_PC_CFLAGS"
+ fi
+
+ # If static, empty GLW_LIB_DEPS and add libs for programs to link
+ GLW_PC_LIB_PRIV="$GLW_PC_LIB_PRIV"
+ if test "$enable_static" = no; then
+ GLW_MESA_DEPS='-l$(GL_LIB)'
+ GLW_LIB_DEPS="$GLW_LIB_DEPS"
+ else
+ APP_LIB_DEPS="$APP_LIB_DEPS $GLW_LIB_DEPS"
+ GLW_LIB_DEPS=""
+ GLW_MESA_DEPS=""
+ fi
+fi
+AC_SUBST([GLW_LIB_DEPS])
+AC_SUBST([GLW_MESA_DEPS])
+AC_SUBST([GLW_SOURCES])
+AC_SUBST([MOTIF_CFLAGS])
+AC_SUBST([GLW_PC_REQ_PRIV])
+AC_SUBST([GLW_PC_LIB_PRIV])
+AC_SUBST([GLW_PC_CFLAGS])
+
+dnl
+dnl GLUT configuration
+dnl
+if test -f "$srcdir/include/GL/glut.h"; then
+ default_glut=yes
+else
+ default_glut=no
+fi
+AC_ARG_ENABLE([glut],
+ [AS_HELP_STRING([--disable-glut],
+ [enable GLUT library @<:@default=enabled if source available@:>@])],
+ [enable_glut="$enableval"],
+ [enable_glut="$default_glut"])
+
+dnl Don't build glut on osmesa
+if test "x$enable_glut" = xyes; then
+ case "$mesa_driver" in
+ osmesa|no)
+ AC_MSG_NOTICE([Disabling glut since there is no OpenGL driver])
+ enable_glut=no
+ ;;
+ esac
+fi
+dnl Can't build glut if GLU not available
+if test "x$enable_glu$enable_glut" = xnoyes; then
+ AC_MSG_WARN([Disabling glut since GLU is disabled])
+ enable_glut=no
+fi
+
+if test "x$enable_glut" = xyes; then
+ SRC_DIRS="$SRC_DIRS glut/glx"
+ if test "$x11_pkgconfig" = yes; then
+ PKG_CHECK_MODULES([GLUT],[x11 xmu xi])
+ GLUT_PC_REQ_PRIV="x11 xmu xi"
+ GLUT_LIB_DEPS="$GLUT_LIBS"
+ else
+ # should check these...
+ GLUT_LIB_DEPS="$X_LIBS -lX11 -lXmu -lXi"
+ GLUT_PC_LIB_PRIV="$GLUT_LIB_DEPS"
+ GLUT_PC_CFLAGS="$X11_INCLUDES"
+ fi
+ if test "x$GCC" = xyes; then
+ GLUT_CFLAGS="$GLUT_CFLAGS -fexceptions"
+ fi
+ GLUT_LIB_DEPS="$GLUT_LIB_DEPS -lm"
+ GLUT_PC_LIB_PRIV="$GLUT_PC_LIB_PRIV -lm"
+
+ # If static, empty GLUT_LIB_DEPS and add libs for programs to link
+ if test "$enable_static" = no; then
+ GLUT_MESA_DEPS='-l$(GLU_LIB) -l$(GL_LIB)'
+ else
+ APP_LIB_DEPS="$APP_LIB_DEPS $GLUT_LIB_DEPS"
+ GLUT_LIB_DEPS=""
+ GLUT_MESA_DEPS=""
+ fi
+fi
+AC_SUBST([GLUT_LIB_DEPS])
+AC_SUBST([GLUT_MESA_DEPS])
+AC_SUBST([GLUT_CFLAGS])
+AC_SUBST([GLUT_PC_REQ_PRIV])
+AC_SUBST([GLUT_PC_LIB_PRIV])
+AC_SUBST([GLUT_PC_CFLAGS])
+
+dnl
+dnl Program library dependencies
+dnl Only libm is added here if necessary as the libraries should
+dnl be pulled in by the linker
+dnl
+if test "x$APP_LIB_DEPS" = x; then
+ case "$host_os" in
+ solaris*)
+ APP_LIB_DEPS="-lX11 -lsocket -lnsl -lm"
+ ;;
+ cygwin*)
+ APP_LIB_DEPS="-lX11"
+ ;;
+ *)
+ APP_LIB_DEPS="-lm"
+ ;;
+ esac
+fi
+AC_SUBST([APP_LIB_DEPS])
+AC_SUBST([PROGRAM_DIRS])
+
+dnl
+dnl Gallium configuration
+dnl
+AC_ARG_ENABLE([gallium],
+ [AS_HELP_STRING([--disable-gallium],
+ [build gallium @<:@default=enabled@:>@])],
+ [enable_gallium="$enableval"],
+ [enable_gallium=yes])
+if test "x$enable_gallium" = xno -a "x$enable_openvg" = xyes; then
+ AC_MSG_ERROR([cannot enable OpenVG without Gallium])
+fi
+if test "x$enable_gallium" = xyes; then
+ SRC_DIRS="$SRC_DIRS gallium gallium/winsys gallium/targets"
+ AC_CHECK_HEADER([udis86.h], [HAS_UDIS86="yes"],
+ [HAS_UDIS86="no"])
+ AC_PATH_PROG([LLVM_CONFIG], [llvm-config], [no])
+fi
+
+AC_SUBST([LLVM_CFLAGS])
+AC_SUBST([LLVM_LIBS])
+AC_SUBST([LLVM_LDFLAGS])
+AC_SUBST([LLVM_VERSION])
+
+dnl
+dnl Gallium state trackers configuration
+dnl
+
+AC_ARG_ENABLE([gallium-egl],
+ [AS_HELP_STRING([--enable-gallium-egl],
+ [enable gallium EGL state tracker @<:@default=auto@:>@])],
+ [enable_gallium_egl="$enableval"],
+ [enable_gallium_egl=auto])
+if test "x$enable_gallium_egl" = xauto; then
+ case "$mesa_driver" in
+ dri|no)
+ enable_gallium_egl=$enable_egl
+ ;;
+ *)
+ enable_gallium_egl=$enable_openvg
+ ;;
+ esac
+fi
+case "x$enable_egl$enable_gallium_egl" in
+xnoyes)
+ AC_MSG_ERROR([cannot build Gallium EGL state tracker without EGL])
+esac
+
+AC_ARG_WITH([state-trackers],
+ [AS_HELP_STRING([--with-state-trackers@<:@=DIRS...@:>@],
+ [comma delimited state_trackers list, e.g.
+ "egl,glx" @<:@default=auto@:>@])],
+ [with_state_trackers="$withval"],
+ [with_state_trackers=yes])
+
+case "$with_state_trackers" in
+no)
+ GALLIUM_STATE_TRACKERS_DIRS=""
+ ;;
+yes)
+ # look at what else is built
+ case "$mesa_driver" in
+ xlib)
+ GALLIUM_STATE_TRACKERS_DIRS=glx
+ ;;
+ dri)
+ GALLIUM_STATE_TRACKERS_DIRS="dri"
+ HAVE_ST_DRI="yes"
+ # Have only tested st/xorg on 1.6.0 servers
+ PKG_CHECK_MODULES(XORG, [xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED],
+ HAVE_ST_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg",
+ HAVE_ST_XORG="no")
+ ;;
+ esac
+
+ if test "x$enable_egl" = xyes; then
+ if test "$enable_openvg" = yes; then
+ GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS vega"
+ st_egl="yes"
+ fi
+
+ if test "$enable_gallium_egl" = yes; then
+ GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl"
+ HAVE_ST_EGL="yes"
+ fi
+ fi
+ ;;
+*)
+ # verify the requested state tracker exist
+ state_trackers=""
+ _state_trackers=`IFS=', '; echo $with_state_trackers`
+ for tracker in $_state_trackers; do
+ case "$tracker" in
+ dri)
+ if test "x$mesa_driver" != xdri; then
+ AC_MSG_ERROR([cannot build dri state tracker without mesa driver set to dri])
+ fi
+ HAVE_ST_DRI="yes"
+ ;;
+ egl)
+ if test "x$enable_egl" != xyes; then
+ AC_MSG_ERROR([cannot build egl state tracker without EGL library])
+ fi
+ HAVE_ST_EGL="yes"
+ ;;
+ xorg)
+ PKG_CHECK_MODULES([XORG], [xorg-server >= 1.6.0])
+ PKG_CHECK_MODULES([LIBDRM_XORG], [libdrm >= $LIBDRM_XORG_REQUIRED])
+ PKG_CHECK_MODULES([LIBKMS_XORG], [libkms >= $LIBKMS_XORG_REQUIRED])
+ HAVE_ST_XORG="yes"
+ ;;
+ vega)
+ if test "x$enable_openvg" != xyes; then
+ AC_MSG_ERROR([cannot build vega state tracker without --enable-openvg])
+ fi
+ have_st_vega="yes"
+ ;;
+ esac
+
+ if test -n "$tracker"; then
+ test -d "$srcdir/src/gallium/state_trackers/$tracker" || \
+ AC_MSG_ERROR([state tracker '$tracker' doesn't exist])
+ if test -n "$state_trackers"; then
+ state_trackers="$state_trackers $tracker"
+ else
+ state_trackers="$tracker"
+ fi
+ fi
+ done
+ GALLIUM_STATE_TRACKERS_DIRS="$state_trackers"
+
+ # append --enable-openvg/--enable-gallium-egl to --with-state-trackers
+ if test "x$have_st_vega" != xyes -a "x$enable_openvg" = xyes; then
+ AC_MSG_ERROR([--with-state-trackers specified but vega is missing])
+ fi
+ if test "x$HAVE_ST_EGL" != xyes -a "x$enable_gallium_egl" = xyes; then
+ AC_MSG_ERROR([--with-state-trackers specified but egl is missing])
+ fi
+ ;;
+esac
+
+
+EGL_CLIENT_APIS=""
+VG_LIB_DEPS=""
+
+case "x$enable_opengl$enable_gles1$enable_gles2" in
+x*yes*)
+ EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(GL_LIB)'
+ ;;
+esac
+if test "x$enable_openvg" = xyes; then
+ EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(VG_LIB)'
+ VG_LIB_DEPS="$VG_LIB_DEPS -lpthread"
+fi
+
+AC_SUBST([VG_LIB_DEPS])
+AC_SUBST([EGL_CLIENT_APIS])
+
+if test "x$HAVE_ST_EGL" = xyes; then
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl"
+fi
+
+if test "x$HAVE_ST_XORG" = xyes; then
+ PKG_CHECK_MODULES(XEXT, [xextproto >= 7.0.99.1],
+ HAVE_XEXTPROTO_71="yes"; DEFINES="$DEFINES -DHAVE_XEXTPROTO_71",
+ HAVE_XEXTPROTO_71="no")
+fi
+
+AC_ARG_WITH([egl-platforms],
+ [AS_HELP_STRING([--with-egl-platforms@<:@=DIRS...@:>@],
+ [comma delimited native platforms libEGL supports, e.g.
+ "x11,drm" @<:@default=auto@:>@])],
+ [with_egl_platforms="$withval"],
+ [with_egl_platforms=yes])
+AC_ARG_WITH([egl-displays],
+ [AS_HELP_STRING([--with-egl-displays@<:@=DIRS...@:>@],
+ [DEPRECATED. Use --with-egl-platforms instead])],
+ [with_egl_platforms="$withval"])
+
+EGL_PLATFORMS=""
+WAYLAND_EGL_LIB_DEPS=""
+
+case "$with_egl_platforms" in
+yes)
+ if test "x$enable_egl" = xyes && test "x$mesa_driver" != xosmesa; then
+ EGL_PLATFORMS="x11"
+ if test "$mesa_driver" = dri; then
+ EGL_PLATFORMS="$EGL_PLATFORMS drm"
+ fi
+ fi
+ ;;
+*)
+ if test "x$enable_egl" != xyes; then
+ AC_MSG_ERROR([cannot build egl state tracker without EGL library])
+ fi
+ # verify the requested driver directories exist
+ egl_platforms=`IFS=', '; echo $with_egl_platforms`
+ for plat in $egl_platforms; do
+ test -d "$srcdir/src/gallium/state_trackers/egl/$plat" || \
+ AC_MSG_ERROR([EGL platform '$plat' doesn't exist])
+ if test "$plat" = "fbdev"; then
+ GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/fbdev"
+ fi
+ if test "$plat" = "wayland"; then
+ PKG_CHECK_MODULES([WAYLAND], [wayland-client wayland-server],, \
+ [AC_MSG_ERROR([cannot find libwayland-client])])
+ WAYLAND_EGL_LIB_DEPS="$WAYLAND_LIBS $LIBDRM_LIBS"
+ fi
+ done
+ EGL_PLATFORMS="$egl_platforms"
+ ;;
+esac
+AC_SUBST([EGL_PLATFORMS])
+
+AC_SUBST([WAYLAND_EGL_LIB_DEPS])
+WAYLAND_EGL_PC_REQ_PRIV="wayland-client libdrm"
+WAYLAND_EGL_PC_LIB_PRIV=
+WAYLAND_EGL_PC_CFLAGS=
+
+AC_SUBST([WAYLAND_EGL_PC_REQ_PRIV])
+AC_SUBST([WAYLAND_EGL_PC_LIB_PRIV])
+AC_SUBST([WAYLAND_EGL_PC_CFLAGS])
+
+
+AC_ARG_WITH([egl-driver-dir],
+ [AS_HELP_STRING([--with-egl-driver-dir=DIR],
+ [directory for EGL drivers [[default=${libdir}/egl]]])],
+ [EGL_DRIVER_INSTALL_DIR="$withval"],
+ [EGL_DRIVER_INSTALL_DIR='${libdir}/egl'])
+AC_SUBST([EGL_DRIVER_INSTALL_DIR])
+
+AC_ARG_WITH([xorg-driver-dir],
+ [AS_HELP_STRING([--with-xorg-driver-dir=DIR],
+ [Default xorg driver directory[[default=${libdir}/xorg/modules/drivers]]])],
+ [XORG_DRIVER_INSTALL_DIR="$withval"],
+ [XORG_DRIVER_INSTALL_DIR="${libdir}/xorg/modules/drivers"])
+AC_SUBST([XORG_DRIVER_INSTALL_DIR])
+
+AC_ARG_WITH([max-width],
+ [AS_HELP_STRING([--with-max-width=N],
+ [Maximum framebuffer width (4096)])],
+ [DEFINES="${DEFINES} -DMAX_WIDTH=${withval}";
+ AS_IF([test "${withval}" -gt "4096"],
+ [AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])]
+)
+AC_ARG_WITH([max-height],
+ [AS_HELP_STRING([--with-max-height=N],
+ [Maximum framebuffer height (4096)])],
+ [DEFINES="${DEFINES} -DMAX_HEIGHT=${withval}";
+ AS_IF([test "${withval}" -gt "4096"],
+ [AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])]
+)
+
+dnl
+dnl Gallium LLVM
+dnl
+AC_ARG_ENABLE([gallium-llvm],
+ [AS_HELP_STRING([--enable-gallium-llvm],
+ [build gallium LLVM support @<:@default=disabled@:>@])],
+ [enable_gallium_llvm="$enableval"],
+ [enable_gallium_llvm=auto])
+if test "x$enable_gallium_llvm" = xyes; then
+ if test "x$LLVM_CONFIG" != xno; then
+ LLVM_VERSION=`$LLVM_CONFIG --version`
+ LLVM_CFLAGS=`$LLVM_CONFIG --cppflags`
+ LLVM_LIBS="`$LLVM_CONFIG --libs jit interpreter nativecodegen bitwriter` -lstdc++"
+
+ if test "x$HAS_UDIS86" != xno; then
+ LLVM_LIBS="$LLVM_LIBS -ludis86"
+ DEFINES="$DEFINES -DHAVE_UDIS86"
+ fi
+ LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags`
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe"
+ DEFINES="$DEFINES -DGALLIUM_LLVMPIPE -D__STDC_CONSTANT_MACROS"
+ MESA_LLVM=1
+ else
+ MESA_LLVM=0
+ fi
+else
+ MESA_LLVM=0
+fi
+
+dnl
+dnl Gallium helper functions
+dnl
+gallium_check_st() {
+ if test "x$HAVE_ST_DRI" = xyes || test "x$HAVE_ST_XORG" = xyes; then
+ GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS $1"
+ fi
+ if test "x$HAVE_ST_DRI" = xyes && test "x$2" != x; then
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $2"
+ fi
+ if test "x$HAVE_ST_XORG" = xyes && test "x$3" != x; then
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $3"
+ fi
+}
+
+
+dnl
+dnl Gallium SVGA configuration
+dnl
+AC_ARG_ENABLE([gallium-svga],
+ [AS_HELP_STRING([--enable-gallium-svga],
+ [build gallium SVGA @<:@default=disabled@:>@])],
+ [enable_gallium_svga="$enableval"],
+ [enable_gallium_svga=auto])
+if test "x$enable_gallium_svga" = xyes; then
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga"
+ gallium_check_st "svga/drm" "dri-vmwgfx" "xorg-vmwgfx"
+elif test "x$enable_gallium_svga" = xauto; then
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga"
+fi
+
+dnl
+dnl Gallium i915 configuration
+dnl
+AC_ARG_ENABLE([gallium-i915],
+ [AS_HELP_STRING([--enable-gallium-i915],
+ [build gallium i915 @<:@default=disabled@:>@])],
+ [enable_gallium_i915="$enableval"],
+ [enable_gallium_i915=auto])
+if test "x$enable_gallium_i915" = xyes; then
+ GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw"
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915"
+ gallium_check_st "i915/drm" "dri-i915" "xorg-i915"
+elif test "x$enable_gallium_i915" = xauto; then
+ GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw"
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915"
+fi
+
+dnl
+dnl Gallium i965 configuration
+dnl
+AC_ARG_ENABLE([gallium-i965],
+ [AS_HELP_STRING([--enable-gallium-i965],
+ [build gallium i965 @<:@default=disabled@:>@])],
+ [enable_gallium_i965="$enableval"],
+ [enable_gallium_i965=auto])
+if test "x$enable_gallium_i965" = xyes; then
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965"
+ gallium_check_st "i965/drm" "dri-i965" "xorg-i965"
+elif test "x$enable_gallium_i965" = xauto; then
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965"
+fi
+
+dnl
+dnl Gallium Radeon r300g configuration
+dnl
+AC_ARG_ENABLE([gallium-radeon],
+ [AS_HELP_STRING([--enable-gallium-radeon],
+ [build gallium radeon @<:@default=disabled@:>@])],
+ [enable_gallium_radeon="$enableval"],
+ [enable_gallium_radeon=auto])
+if test "x$enable_gallium_radeon" = xauto; then
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
+ gallium_check_st "radeon/drm" "dri-r300"
+fi
+if test "x$enable_gallium_radeon" = xyes; then
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
+ gallium_check_st "radeon/drm" "dri-r300" "xorg-radeon"
+fi
+
+dnl
+dnl Gallium Radeon r600g configuration
+dnl
+AC_ARG_ENABLE([gallium-r600],
+ [AS_HELP_STRING([--enable-gallium-r600],
+ [build gallium radeon @<:@default=disabled@:>@])],
+ [enable_gallium_r600="$enableval"],
+ [enable_gallium_r600=auto])
+if test "x$enable_gallium_r600" = xyes; then
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r600"
+ gallium_check_st "r600/drm" "dri-r600"
+fi
+
+dnl
+dnl Gallium Nouveau configuration
+dnl
+AC_ARG_ENABLE([gallium-nouveau],
+ [AS_HELP_STRING([--enable-gallium-nouveau],
+ [build gallium nouveau @<:@default=disabled@:>@])],
+ [enable_gallium_nouveau="$enableval"],
+ [enable_gallium_nouveau=no])
+if test "x$enable_gallium_nouveau" = xyes; then
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50 nvc0"
+ gallium_check_st "nouveau/drm" "dri-nouveau" "xorg-nouveau"
+fi
+
+dnl
+dnl Gallium swrast configuration
+dnl
+AC_ARG_ENABLE([gallium-swrast],
+ [AS_HELP_STRING([--enable-gallium-swrast],
+ [build gallium swrast @<:@default=auto@:>@])],
+ [enable_gallium_swrast="$enableval"],
+ [enable_gallium_swrast=auto])
+if test "x$enable_gallium_swrast" = xyes || test "x$enable_gallium_swrast" = xauto; then
+ if test "x$HAVE_ST_DRI" = xyes; then
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast"
+ fi
+fi
+
+dnl prepend CORE_DIRS to SRC_DIRS
+SRC_DIRS="$CORE_DIRS $SRC_DIRS"
+
+dnl Restore LDFLAGS and CPPFLAGS
+LDFLAGS="$_SAVE_LDFLAGS"
+CPPFLAGS="$_SAVE_CPPFLAGS"
+
+dnl Substitute the config
+AC_CONFIG_FILES([configs/autoconf])
+
+dnl Replace the configs/current symlink
+AC_CONFIG_COMMANDS([configs],[
+if test -f configs/current || test -L configs/current; then
+ rm -f configs/current
+fi
+ln -s autoconf configs/current
+])
+
+AC_OUTPUT
+
+dnl
+dnl Output some configuration info for the user
+dnl
+echo ""
+echo " prefix: $prefix"
+echo " exec_prefix: $exec_prefix"
+echo " libdir: $libdir"
+echo " includedir: $includedir"
+
+dnl API info
+echo ""
+echo " OpenGL: $enable_opengl (ES1: $enable_gles1 ES2: $enable_gles2)"
+echo " OpenVG: $enable_openvg"
+
+dnl Driver info
+echo ""
+echo " Driver: $mesa_driver"
+if test "$mesa_driver" != no; then
+ if echo "$DRIVER_DIRS" | grep 'osmesa' >/dev/null 2>&1; then
+ echo " OSMesa: lib$OSMESA_LIB"
+ else
+ echo " OSMesa: no"
+ fi
+ if test "$mesa_driver" = dri; then
+ # cleanup the drivers var
+ dri_dirs=`echo $DRI_DIRS | $SED 's/^ *//;s/ */ /;s/ *$//'`
+ if test "x$DRI_DIRS" = x; then
+ echo " DRI drivers: no"
+ else
+ echo " DRI drivers: $dri_dirs"
+ fi
+ echo " DRI driver dir: $DRI_DRIVER_INSTALL_DIR"
+ echo " Use XCB: $enable_xcb"
+ echo " Shared dricore: $enable_dricore"
+ fi
+fi
+echo ""
+echo " GLU: $enable_glu"
+echo " GLw: $enable_glw (Motif: $enable_motif)"
+echo " glut: $enable_glut"
+
+dnl EGL
+echo ""
+echo " EGL: $enable_egl"
+if test "$enable_egl" = yes; then
+ echo " EGL platforms: $EGL_PLATFORMS"
+
+ egl_drivers=""
+ for d in $EGL_DRIVERS_DIRS; do
+ egl_drivers="$egl_drivers builtin:egl_$d"
+ done
+
+ if test "$enable_gallium" = yes -a "$HAVE_ST_EGL" = yes; then
+ echo " EGL drivers: ${egl_drivers} egl_gallium"
+ echo " EGL Gallium STs:$EGL_CLIENT_APIS"
+ else
+ echo " EGL drivers: $egl_drivers"
+ fi
+fi
+
+echo ""
+if test "x$MESA_LLVM" = x1; then
+ echo " llvm: yes"
+ echo " llvm-config: $LLVM_CONFIG"
+ echo " llvm-version: $LLVM_VERSION"
+else
+ echo " llvm: no"
+fi
+
+echo ""
+if echo "$SRC_DIRS" | grep 'gallium' >/dev/null 2>&1; then
+ echo " Gallium: yes"
+ echo " Gallium dirs: $GALLIUM_DIRS"
+ echo " Target dirs: $GALLIUM_TARGET_DIRS"
+ echo " Winsys dirs: $GALLIUM_WINSYS_DIRS"
+ echo " Driver dirs: $GALLIUM_DRIVERS_DIRS"
+ echo " Trackers dirs: $GALLIUM_STATE_TRACKERS_DIRS"
+else
+ echo " Gallium: no"
+fi
+
+dnl Libraries
+echo ""
+echo " Shared libs: $enable_shared"
+echo " Static libs: $enable_static"
+
+dnl Compiler options
+# cleanup the CFLAGS/CXXFLAGS/DEFINES vars
+cflags=`echo $CFLAGS $OPT_FLAGS $PIC_FLAGS $ARCH_FLAGS | \
+ $SED 's/^ *//;s/ */ /;s/ *$//'`
+cxxflags=`echo $CXXFLAGS $OPT_FLAGS $PIC_FLAGS $ARCH_FLAGS | \
+ $SED 's/^ *//;s/ */ /;s/ *$//'`
+defines=`echo $DEFINES $ASM_FLAGS | $SED 's/^ *//;s/ */ /;s/ *$//'`
+echo ""
+echo " CFLAGS: $cflags"
+echo " CXXFLAGS: $cxxflags"
+echo " Macros: $defines"
+echo ""
+echo " PYTHON2: $PYTHON2"
+
+echo ""
+echo " Run '${MAKE-make}' to build Mesa"
+echo ""
diff --git a/mesalib/docs/GL3.txt b/mesalib/docs/GL3.txt
index 0c53bc42d..fc3c853d4 100644
--- a/mesalib/docs/GL3.txt
+++ b/mesalib/docs/GL3.txt
@@ -1,117 +1,117 @@
-
-Status of OpenGL 3.x features in Mesa
-
-
-Note: when an item is marked as "DONE" it means all the core Mesa
-infrastructure is complete but it may be the case that few (if any) drivers
-implement the features.
-
-
-Feature Status
------------------------------------------------------ ------------------------
-
-GL 3.0:
-
-GLSL changes (GL_EXT_gpu_shader4, etc) not started
-Conditional rendering (GL_NV_conditional_render) DONE (swrast & softpipe)
-Map buffer subranges (GL_ARB_map_buffer_range) DONE
-Clamping controls (GL_ARB_color_buffer_float) BRANCH ~mareko/mesa floating2
-Float textures, renderbuffers (GL_ARB_texture_float) BRANCH ~mareko/mesa floating2
-GL_EXT_packed_float not started
-GL_EXT_texture_shared_exponent not started
-Float depth buffers (GL_ARB_depth_buffer_float) not started
-Framebuffer objects (GL_EXT_framebuffer_object) DONE
-Half-float DONE
-Multisample blit DONE
-Non-normalized Integer texture/framebuffer formats ~50% done
-1D/2D Texture arrays core Mesa, swrast done
-Packed depth/stencil formats DONE
-Per-buffer blend and masks (GL_EXT_draw_buffers2) DONE
-GL_EXT_texture_compression_rgtc DONE (swrast, gallium r600)
-Red and red/green texture formats DONE (swrast, i965, gallium)
-Transform feedback (GL_EXT_transform_feedback) ~50% done
- glBindFragDataLocation, glGetFragDataLocation,
- glBindBufferRange, glBindBufferBase commands
-Vertex array objects (GL_APPLE_vertex_array_object) DONE
-sRGB framebuffer format (GL_EXT_framebuffer_sRGB) core GL done (i965, gallium), GLX todo
-glClearBuffer commands DONE
-glGetStringi command DONE
-glTexParameterI, glGetTexParameterI commands DONE
-glVertexAttribI commands DONE (but converts int
- values to floats)
-
-
-GL 3.1:
-
-GLSL 1.30 and 1.40 not started
-Instanced drawing (GL_ARB_draw_instanced) DONE (gallium, swrast)
-Buffer copying (GL_ARB_copy_buffer) DONE
-Primitive restart (GL_NV_primitive_restart) DONE (gallium)
-16 vertex texture image units not started
-Texture buffer objs (GL_ARB_texture_buffer_object) not started
-Rectangular textures (GL_ARB_texture_rectangle) DONE
-Uniform buffer objs (GL_ARB_uniform_buffer_object) not started
-Signed normalized textures (GL_EXT_texture_snorm) ~50% done
-
-
-GL 3.2:
-
-Core/compatibility profiles not started
-GLSL 1.50 not started
-Geometry shaders (GL_ARB_geometry_shader4) partially done (Zack)
-BGRA vertex order (GL_ARB_vertex_array_bgra) DONE
-Base vertex offset(GL_ARB_draw_elements_base_vertex) DONE
-Frag shader coord (GL_ARB_fragment_coord_conventions) DONE (swrast, gallium)
-Provoking vertex (GL_ARB_provoking_vertex) DONE
-Seamless cubemaps (GL_ARB_seamless_cube_map) DONE, mostly?
-Multisample textures (GL_ARB_texture_multisample) not started
-Frag depth clamp (GL_ARB_depth_clamp) DONE
-Fence objects (GL_ARB_sync) DONE
-
-
-GL 3.3:
-
-GLSL 3.30 not started
-GL_ARB_blend_func_extended not started
-GL_ARB_explicit_attrib_location DONE (swrast, i915, i965)
-GL_ARB_occlusion_query2 DONE (swrast, gallium)
-GL_ARB_sampler_objects not started
-GL_ARB_texture_rgb10_a2ui not started
-GL_ARB_texture_swizzle DONE (same as EXT version)
-GL_ARB_timer_query DONE (only Xlib sw driver)
-GL_ARB_instanced_arrays DONE (gallium)
-GL_ARB_vertex_type_2_10_10_10_rev not started
-
-
-GL 4.0:
-
-GLSL 4.0 not started
-GL_ARB_texture_query_lod not started
-GL_ARB_draw_buffers_blend DONE (gallium softpipe)
-GL_ARB_draw_indirect not started
-GL_ARB_gpu_shader_fp64 not started
-GL_ARB_sample_shading not started
-GL_ARB_shader_subroutine not started
-GL_ARB_tessellation_shader not started
-GL_ARB_texture_buffer_object_rgb32 not started
-GL_ARB_texture_cube_map_array not started
-GL_ARB_texture_gather not started
-GL_ARB_transform_feedback2 not started
-GL_ARB_transform_feedback3 not started
-
-
-GL 4.1:
-
-GLSL 4.1 not started
-GL_ARB_ES2_compatibility not started
-GL_ARB_get_program_binary not started
-GL_ARB_separate_shader_objects some infrastructure done
-GL_ARB_shader_precision not started
-GL_ARB_vertex_attrib_64bit not started
-GL_ARB_viewport_array not started
-
-
-
-
-More info about these features and the work involved can be found at
-http://dri.freedesktop.org/wiki/MissingFunctionality
+
+Status of OpenGL 3.x features in Mesa
+
+
+Note: when an item is marked as "DONE" it means all the core Mesa
+infrastructure is complete but it may be the case that few (if any) drivers
+implement the features.
+
+
+Feature Status
+----------------------------------------------------- ------------------------
+
+GL 3.0:
+
+GLSL changes (GL_EXT_gpu_shader4, etc) not started
+Conditional rendering (GL_NV_conditional_render) DONE (swrast & softpipe)
+Map buffer subranges (GL_ARB_map_buffer_range) DONE
+Clamping controls (GL_ARB_color_buffer_float) BRANCH ~mareko/mesa floating2
+Float textures, renderbuffers (GL_ARB_texture_float) BRANCH ~mareko/mesa floating2
+GL_EXT_packed_float not started
+GL_EXT_texture_shared_exponent not started
+Float depth buffers (GL_ARB_depth_buffer_float) not started
+Framebuffer objects (GL_EXT_framebuffer_object) DONE
+Half-float DONE
+Multisample blit DONE
+Non-normalized Integer texture/framebuffer formats ~50% done
+1D/2D Texture arrays core Mesa, swrast done
+Packed depth/stencil formats DONE
+Per-buffer blend and masks (GL_EXT_draw_buffers2) DONE
+GL_EXT_texture_compression_rgtc DONE (swrast, gallium r600)
+Red and red/green texture formats DONE (swrast, i965, gallium)
+Transform feedback (GL_EXT_transform_feedback) ~50% done
+ glBindFragDataLocation, glGetFragDataLocation,
+ glBindBufferRange, glBindBufferBase commands
+Vertex array objects (GL_APPLE_vertex_array_object) DONE
+sRGB framebuffer format (GL_EXT_framebuffer_sRGB) core GL done (i965, gallium), GLX todo
+glClearBuffer commands DONE
+glGetStringi command DONE
+glTexParameterI, glGetTexParameterI commands DONE
+glVertexAttribI commands DONE (but converts int
+ values to floats)
+
+
+GL 3.1:
+
+GLSL 1.30 and 1.40 not started
+Instanced drawing (GL_ARB_draw_instanced) DONE (gallium, swrast)
+Buffer copying (GL_ARB_copy_buffer) DONE
+Primitive restart (GL_NV_primitive_restart) DONE (gallium)
+16 vertex texture image units not started
+Texture buffer objs (GL_ARB_texture_buffer_object) not started
+Rectangular textures (GL_ARB_texture_rectangle) DONE
+Uniform buffer objs (GL_ARB_uniform_buffer_object) not started
+Signed normalized textures (GL_EXT_texture_snorm) ~50% done
+
+
+GL 3.2:
+
+Core/compatibility profiles not started
+GLSL 1.50 not started
+Geometry shaders (GL_ARB_geometry_shader4) partially done (Zack)
+BGRA vertex order (GL_ARB_vertex_array_bgra) DONE
+Base vertex offset(GL_ARB_draw_elements_base_vertex) DONE
+Frag shader coord (GL_ARB_fragment_coord_conventions) DONE (swrast, gallium)
+Provoking vertex (GL_ARB_provoking_vertex) DONE
+Seamless cubemaps (GL_ARB_seamless_cube_map) DONE, mostly?
+Multisample textures (GL_ARB_texture_multisample) not started
+Frag depth clamp (GL_ARB_depth_clamp) DONE
+Fence objects (GL_ARB_sync) DONE
+
+
+GL 3.3:
+
+GLSL 3.30 not started
+GL_ARB_blend_func_extended not started
+GL_ARB_explicit_attrib_location DONE (swrast, i915, i965)
+GL_ARB_occlusion_query2 DONE (swrast, gallium)
+GL_ARB_sampler_objects not started
+GL_ARB_texture_rgb10_a2ui not started
+GL_ARB_texture_swizzle DONE (same as EXT version)
+GL_ARB_timer_query DONE (only Xlib sw driver)
+GL_ARB_instanced_arrays DONE (gallium)
+GL_ARB_vertex_type_2_10_10_10_rev not started
+
+
+GL 4.0:
+
+GLSL 4.0 not started
+GL_ARB_texture_query_lod not started
+GL_ARB_draw_buffers_blend DONE (gallium softpipe)
+GL_ARB_draw_indirect not started
+GL_ARB_gpu_shader_fp64 not started
+GL_ARB_sample_shading not started
+GL_ARB_shader_subroutine not started
+GL_ARB_tessellation_shader not started
+GL_ARB_texture_buffer_object_rgb32 not started
+GL_ARB_texture_cube_map_array not started
+GL_ARB_texture_gather not started
+GL_ARB_transform_feedback2 not started
+GL_ARB_transform_feedback3 not started
+
+
+GL 4.1:
+
+GLSL 4.1 not started
+GL_ARB_ES2_compatibility not started
+GL_ARB_get_program_binary not started
+GL_ARB_separate_shader_objects some infrastructure done
+GL_ARB_shader_precision not started
+GL_ARB_vertex_attrib_64bit not started
+GL_ARB_viewport_array not started
+
+
+
+
+More info about these features and the work involved can be found at
+http://dri.freedesktop.org/wiki/MissingFunctionality
diff --git a/mesalib/docs/relnotes-7.11.html b/mesalib/docs/relnotes-7.11.html
index 277339bc4..9c34775c2 100644
--- a/mesalib/docs/relnotes-7.11.html
+++ b/mesalib/docs/relnotes-7.11.html
@@ -1,62 +1,62 @@
-<HTML>
-
-<head>
-<TITLE>Mesa Release Notes</TITLE>
-<link rel="stylesheet" type="text/css" href="mesa.css">
-<meta http-equiv="content-type" content="text/html; charset=utf-8" />
-</head>
-
-<BODY>
-
-<body bgcolor="#eeeeee">
-
-<H1>Mesa 7.11 Release Notes / (release date TBD)</H1>
-
-<p>
-Mesa 7.11 is a new development release.
-People who are concerned with stability and reliability should stick
-with a previous release or wait for Mesa 7.11.1.
-</p>
-<p>
-Mesa 7.11 implements the OpenGL 2.1 API, but the version reported by
-glGetString(GL_VERSION) depends on the particular driver being used.
-Some drivers don't support all the features required in OpenGL 2.1.
-</p>
-<p>
-See the <a href="install.html">Compiling/Installing page</a> for prerequisites
-for DRI hardware acceleration.
-</p>
-
-
-<h2>MD5 checksums</h2>
-<pre>
-tbd
-</pre>
-
-
-<h2>New features</h2>
-<ul>
-<li>GL_ARB_draw_instanced extension (gallium drivers, swrast)
-<li>GL_ARB_instanced_arrays extension (gallium drivers)
-<li>GL_ARB_texture_compression_rgtc (gallium r600, swrast)
-<li>GL_ARB_draw_buffers_blend (gallium)
-<li>GL_EXT_texture_sRGB_decode (gallium drivers, swrast, i965)
-</ul>
-
-
-<h2>Bug fixes</h2>
-<ul>
-</ul>
-
-
-<h2>Changes</h2>
-<ul>
-<li>The Windows MSVC project files have been removed. They haven't been maintained
-in quite a while. Building with SCons is an alterantive.
-<li>Removed GL_SGI_texture_color_table support from swrast driver - the only
-driver that implemented it.
-</ul>
-
-
-</body>
-</html>
+<HTML>
+
+<head>
+<TITLE>Mesa Release Notes</TITLE>
+<link rel="stylesheet" type="text/css" href="mesa.css">
+<meta http-equiv="content-type" content="text/html; charset=utf-8" />
+</head>
+
+<BODY>
+
+<body bgcolor="#eeeeee">
+
+<H1>Mesa 7.11 Release Notes / (release date TBD)</H1>
+
+<p>
+Mesa 7.11 is a new development release.
+People who are concerned with stability and reliability should stick
+with a previous release or wait for Mesa 7.11.1.
+</p>
+<p>
+Mesa 7.11 implements the OpenGL 2.1 API, but the version reported by
+glGetString(GL_VERSION) depends on the particular driver being used.
+Some drivers don't support all the features required in OpenGL 2.1.
+</p>
+<p>
+See the <a href="install.html">Compiling/Installing page</a> for prerequisites
+for DRI hardware acceleration.
+</p>
+
+
+<h2>MD5 checksums</h2>
+<pre>
+tbd
+</pre>
+
+
+<h2>New features</h2>
+<ul>
+<li>GL_ARB_draw_instanced extension (gallium drivers, swrast)
+<li>GL_ARB_instanced_arrays extension (gallium drivers)
+<li>GL_ARB_texture_compression_rgtc (gallium r600, swrast)
+<li>GL_ARB_draw_buffers_blend (gallium)
+<li>GL_EXT_texture_sRGB_decode (gallium drivers, swrast, i965)
+</ul>
+
+
+<h2>Bug fixes</h2>
+<ul>
+</ul>
+
+
+<h2>Changes</h2>
+<ul>
+<li>The Windows MSVC project files have been removed. They haven't been maintained
+in quite a while. Building with SCons is an alterantive.
+<li>Removed GL_SGI_texture_color_table support from swrast driver - the only
+driver that implemented it.
+</ul>
+
+
+</body>
+</html>
diff --git a/mesalib/include/EGL/eglext.h b/mesalib/include/EGL/eglext.h
index bae966f1e..4a789c607 100644
--- a/mesalib/include/EGL/eglext.h
+++ b/mesalib/include/EGL/eglext.h
@@ -1,398 +1,398 @@
-#ifndef __eglext_h_
-#define __eglext_h_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
-** Copyright (c) 2007-2010 The Khronos Group Inc.
-**
-** Permission is hereby granted, free of charge, to any person obtaining a
-** copy of this software and/or associated documentation files (the
-** "Materials"), to deal in the Materials without restriction, including
-** without limitation the rights to use, copy, modify, merge, publish,
-** distribute, sublicense, and/or sell copies of the Materials, and to
-** permit persons to whom the Materials are furnished to do so, subject to
-** the following conditions:
-**
-** The above copyright notice and this permission notice shall be included
-** in all copies or substantial portions of the Materials.
-**
-** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
-*/
-
-#include <EGL/eglplatform.h>
-
-/*************************************************************/
-
-/* Header file version number */
-/* Current version at http://www.khronos.org/registry/egl/ */
-/* $Revision$ on $Date: 2010-07-27 20:12:35 -0700 (Tue, 27 Jul 2010) $ */
-#define EGL_EGLEXT_VERSION 7
-
-#ifndef EGL_KHR_config_attribs
-#define EGL_KHR_config_attribs 1
-#define EGL_CONFORMANT_KHR 0x3042 /* EGLConfig attribute */
-#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020 /* EGL_SURFACE_TYPE bitfield */
-#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040 /* EGL_SURFACE_TYPE bitfield */
-#endif
-
-#ifndef EGL_KHR_lock_surface
-#define EGL_KHR_lock_surface 1
-#define EGL_READ_SURFACE_BIT_KHR 0x0001 /* EGL_LOCK_USAGE_HINT_KHR bitfield */
-#define EGL_WRITE_SURFACE_BIT_KHR 0x0002 /* EGL_LOCK_USAGE_HINT_KHR bitfield */
-#define EGL_LOCK_SURFACE_BIT_KHR 0x0080 /* EGL_SURFACE_TYPE bitfield */
-#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100 /* EGL_SURFACE_TYPE bitfield */
-#define EGL_MATCH_FORMAT_KHR 0x3043 /* EGLConfig attribute */
-#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0 /* EGL_MATCH_FORMAT_KHR value */
-#define EGL_FORMAT_RGB_565_KHR 0x30C1 /* EGL_MATCH_FORMAT_KHR value */
-#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2 /* EGL_MATCH_FORMAT_KHR value */
-#define EGL_FORMAT_RGBA_8888_KHR 0x30C3 /* EGL_MATCH_FORMAT_KHR value */
-#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4 /* eglLockSurfaceKHR attribute */
-#define EGL_LOCK_USAGE_HINT_KHR 0x30C5 /* eglLockSurfaceKHR attribute */
-#define EGL_BITMAP_POINTER_KHR 0x30C6 /* eglQuerySurface attribute */
-#define EGL_BITMAP_PITCH_KHR 0x30C7 /* eglQuerySurface attribute */
-#define EGL_BITMAP_ORIGIN_KHR 0x30C8 /* eglQuerySurface attribute */
-#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9 /* eglQuerySurface attribute */
-#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA /* eglQuerySurface attribute */
-#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB /* eglQuerySurface attribute */
-#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC /* eglQuerySurface attribute */
-#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD /* eglQuerySurface attribute */
-#define EGL_LOWER_LEFT_KHR 0x30CE /* EGL_BITMAP_ORIGIN_KHR value */
-#define EGL_UPPER_LEFT_KHR 0x30CF /* EGL_BITMAP_ORIGIN_KHR value */
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list);
-EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay display, EGLSurface surface);
-#endif /* EGL_EGLEXT_PROTOTYPES */
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface);
-#endif
-
-#ifndef EGL_KHR_image
-#define EGL_KHR_image 1
-#define EGL_NATIVE_PIXMAP_KHR 0x30B0 /* eglCreateImageKHR target */
-typedef void *EGLImageKHR;
-#define EGL_NO_IMAGE_KHR ((EGLImageKHR)0)
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
-EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image);
-#endif /* EGL_EGLEXT_PROTOTYPES */
-typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
-#endif
-
-#ifndef EGL_KHR_vg_parent_image
-#define EGL_KHR_vg_parent_image 1
-#define EGL_VG_PARENT_IMAGE_KHR 0x30BA /* eglCreateImageKHR target */
-#endif
-
-#ifndef EGL_KHR_gl_texture_2D_image
-#define EGL_KHR_gl_texture_2D_image 1
-#define EGL_GL_TEXTURE_2D_KHR 0x30B1 /* eglCreateImageKHR target */
-#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC /* eglCreateImageKHR attribute */
-#endif
-
-#ifndef EGL_KHR_gl_texture_cubemap_image
-#define EGL_KHR_gl_texture_cubemap_image 1
-#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3 /* eglCreateImageKHR target */
-#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4 /* eglCreateImageKHR target */
-#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5 /* eglCreateImageKHR target */
-#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6 /* eglCreateImageKHR target */
-#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7 /* eglCreateImageKHR target */
-#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8 /* eglCreateImageKHR target */
-#endif
-
-#ifndef EGL_KHR_gl_texture_3D_image
-#define EGL_KHR_gl_texture_3D_image 1
-#define EGL_GL_TEXTURE_3D_KHR 0x30B2 /* eglCreateImageKHR target */
-#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD /* eglCreateImageKHR attribute */
-#endif
-
-#ifndef EGL_KHR_gl_renderbuffer_image
-#define EGL_KHR_gl_renderbuffer_image 1
-#define EGL_GL_RENDERBUFFER_KHR 0x30B9 /* eglCreateImageKHR target */
-#endif
-
-#ifndef EGL_MESA_drm_image
-#define EGL_MESA_drm_image 1
-#define EGL_DRM_BUFFER_FORMAT_MESA 0x31D0 /* eglCreateImageKHR attribute */
-#define EGL_DRM_BUFFER_USE_MESA 0x31D1
-
-/* EGL_DRM_BUFFER_FORMAT_MESA tokens */
-#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2
-
-/* EGL_DRM_BUFFER_USE_MESA bits */
-#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x0001
-#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x0002
-
-#define EGL_DRM_BUFFER_MESA 0x31D3 /* eglCreateImageKHR target */
-#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4 /* eglCreateImageKHR attribute */
-
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLImageKHR EGLAPIENTRY eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attrib_list);
-EGLAPI EGLBoolean EGLAPIENTRY eglExportDRMImageMESA(EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
-#endif
-typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESA) (EGLDisplay dpy, const EGLint *attrib_list);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESA) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
-#endif
-
-#ifndef EGL_WL_bind_wayland_display
-#define EGL_WL_bind_wayland_display 1
-
-#define EGL_WAYLAND_BUFFER_WL 0x31D5 /* eglCreateImageKHR target */
-struct wl_display;
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLBoolean EGLAPIENTRY eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display);
-EGLAPI EGLBoolean EGLAPIENTRY eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display);
-#else
-typedef EGLBoolean (EGLAPIENTRY PFNEGLBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
-typedef EGLBoolean (EGLAPIENTRY PFNEGLUNBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
-#endif
-#endif
-
-#if KHRONOS_SUPPORT_INT64 /* EGLTimeKHR requires 64-bit uint support */
-#ifndef EGL_KHR_reusable_sync
-#define EGL_KHR_reusable_sync 1
-
-typedef void* EGLSyncKHR;
-typedef khronos_utime_nanoseconds_t EGLTimeKHR;
-
-#define EGL_SYNC_STATUS_KHR 0x30F1
-#define EGL_SIGNALED_KHR 0x30F2
-#define EGL_UNSIGNALED_KHR 0x30F3
-#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5
-#define EGL_CONDITION_SATISFIED_KHR 0x30F6
-#define EGL_SYNC_TYPE_KHR 0x30F7
-#define EGL_SYNC_REUSABLE_KHR 0x30FA
-#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001 /* eglClientWaitSyncKHR <flags> bitfield */
-#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull
-#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0)
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
-EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync);
-EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
-EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
-EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
-#endif /* EGL_EGLEXT_PROTOTYPES */
-typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync);
-typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
-#endif
-#endif
-
-/* EGL_MESA_screen extension >>> PRELIMINARY <<< */
-#ifndef EGL_MESA_screen_surface
-#define EGL_MESA_screen_surface 1
-
-#define EGL_BAD_SCREEN_MESA 0x4000
-#define EGL_BAD_MODE_MESA 0x4001
-#define EGL_SCREEN_COUNT_MESA 0x4002
-#define EGL_SCREEN_POSITION_MESA 0x4003
-#define EGL_SCREEN_POSITION_GRANULARITY_MESA 0x4004
-#define EGL_MODE_ID_MESA 0x4005
-#define EGL_REFRESH_RATE_MESA 0x4006
-#define EGL_OPTIMAL_MESA 0x4007
-#define EGL_INTERLACED_MESA 0x4008
-#define EGL_SCREEN_BIT_MESA 0x08
-
-typedef khronos_uint32_t EGLScreenMESA;
-typedef khronos_uint32_t EGLModeMESA;
-
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLBoolean EGLAPIENTRY eglChooseModeMESA(EGLDisplay dpy, EGLScreenMESA screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes);
-EGLAPI EGLBoolean EGLAPIENTRY eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes);
-EGLAPI EGLBoolean EGLAPIENTRY eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value);
-EGLAPI EGLBoolean EGLAPIENTRY eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens);
-EGLAPI EGLSurface EGLAPIENTRY eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
-EGLAPI EGLBoolean EGLAPIENTRY eglShowScreenSurfaceMESA(EGLDisplay dpy, EGLint screen, EGLSurface surface, EGLModeMESA mode);
-EGLAPI EGLBoolean EGLAPIENTRY eglScreenPositionMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y);
-EGLAPI EGLBoolean EGLAPIENTRY eglQueryScreenMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value);
-EGLAPI EGLBoolean EGLAPIENTRY eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface);
-EGLAPI EGLBoolean EGLAPIENTRY eglQueryScreenModeMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode);
-EGLAPI const char * EGLAPIENTRY eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode);
-#endif /* EGL_EGLEXT_PROTOTYPES */
-
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLCHOOSEMODEMESA) (EGLDisplay dpy, EGLScreenMESA screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETMODESMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLGetModeATTRIBMESA) (EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSCRREENSMESA) (EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens);
-typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATESCREENSURFACEMESA) (EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLSHOWSCREENSURFACEMESA) (EGLDisplay dpy, EGLint screen, EGLSurface surface, EGLModeMESA mode);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLSCREENPOSIITONMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSCREENMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSCREENSURFACEMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSCREENMODEMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode);
-typedef const char * (EGLAPIENTRYP PFNEGLQUERYMODESTRINGMESA) (EGLDisplay dpy, EGLModeMESA mode);
-
-#endif /* EGL_MESA_screen_surface */
-
-
-#ifndef EGL_MESA_copy_context
-#define EGL_MESA_copy_context 1
-
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLBoolean EGLAPIENTRY eglCopyContextMESA(EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask);
-#endif /* EGL_EGLEXT_PROTOTYPES */
-
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOPYCONTEXTMESA) (EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask);
-
-#endif /* EGL_MESA_copy_context */
-
-#ifndef EGL_MESA_drm_display
-#define EGL_MESA_drm_display 1
-
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLDisplay EGLAPIENTRY eglGetDRMDisplayMESA(int fd);
-#endif /* EGL_EGLEXT_PROTOTYPES */
-
-typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETDRMDISPLAYMESA) (int fd);
-
-#endif /* EGL_MESA_drm_display */
-
-#ifndef EGL_KHR_image_base
-#define EGL_KHR_image_base 1
-/* Most interfaces defined by EGL_KHR_image_pixmap above */
-#define EGL_IMAGE_PRESERVED_KHR 0x30D2 /* eglCreateImageKHR attribute */
-#endif
-
-#ifndef EGL_KHR_image_pixmap
-#define EGL_KHR_image_pixmap 1
-/* Interfaces defined by EGL_KHR_image above */
-#endif
-
-#ifndef EGL_IMG_context_priority
-#define EGL_IMG_context_priority 1
-#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100
-#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101
-#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102
-#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103
-#endif
-
-#ifndef EGL_KHR_lock_surface2
-#define EGL_KHR_lock_surface2 1
-#define EGL_BITMAP_PIXEL_SIZE_KHR 0x3110
-#endif
-
-#ifndef EGL_NV_coverage_sample
-#define EGL_NV_coverage_sample 1
-#define EGL_COVERAGE_BUFFERS_NV 0x30E0
-#define EGL_COVERAGE_SAMPLES_NV 0x30E1
-#endif
-
-#ifndef EGL_NV_depth_nonlinear
-#define EGL_NV_depth_nonlinear 1
-#define EGL_DEPTH_ENCODING_NV 0x30E2
-#define EGL_DEPTH_ENCODING_NONE_NV 0
-#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3
-#endif
-
-#if KHRONOS_SUPPORT_INT64 /* EGLTimeNV requires 64-bit uint support */
-#ifndef EGL_NV_sync
-#define EGL_NV_sync 1
-#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6
-#define EGL_SYNC_STATUS_NV 0x30E7
-#define EGL_SIGNALED_NV 0x30E8
-#define EGL_UNSIGNALED_NV 0x30E9
-#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001
-#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull
-#define EGL_ALREADY_SIGNALED_NV 0x30EA
-#define EGL_TIMEOUT_EXPIRED_NV 0x30EB
-#define EGL_CONDITION_SATISFIED_NV 0x30EC
-#define EGL_SYNC_TYPE_NV 0x30ED
-#define EGL_SYNC_CONDITION_NV 0x30EE
-#define EGL_SYNC_FENCE_NV 0x30EF
-#define EGL_NO_SYNC_NV ((EGLSyncNV)0)
-typedef void* EGLSyncNV;
-typedef khronos_utime_nanoseconds_t EGLTimeNV;
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLSyncNV eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
-EGLBoolean eglDestroySyncNV (EGLSyncNV sync);
-EGLBoolean eglFenceNV (EGLSyncNV sync);
-EGLint eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
-EGLBoolean eglSignalSyncNV (EGLSyncNV sync, EGLenum mode);
-EGLBoolean eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value);
-#endif /* EGL_EGLEXT_PROTOTYPES */
-typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync);
-typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value);
-#endif
-#endif
-
-#if KHRONOS_SUPPORT_INT64 /* Dependent on EGL_KHR_reusable_sync which requires 64-bit uint support */
-#ifndef EGL_KHR_fence_sync
-#define EGL_KHR_fence_sync 1
-/* Reuses most tokens and entry points from EGL_KHR_reusable_sync */
-#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0
-#define EGL_SYNC_CONDITION_KHR 0x30F8
-#define EGL_SYNC_FENCE_KHR 0x30F9
-#endif
-#endif
-
-#ifndef EGL_HI_clientpixmap
-#define EGL_HI_clientpixmap 1
-
-/* Surface Attribute */
-#define EGL_CLIENT_PIXMAP_POINTER_HI 0x8F74
-/*
- * Structure representing a client pixmap
- * (pixmap's data is in client-space memory).
- */
-struct EGLClientPixmapHI
-{
- void* pData;
- EGLint iWidth;
- EGLint iHeight;
- EGLint iStride;
-};
-
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI(EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap);
-#endif /* EGL_EGLEXT_PROTOTYPES */
-typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap);
-#endif /* EGL_HI_clientpixmap */
-
-#ifndef EGL_HI_colorformats
-#define EGL_HI_colorformats 1
-/* Config Attribute */
-#define EGL_COLOR_FORMAT_HI 0x8F70
-/* Color Formats */
-#define EGL_COLOR_RGB_HI 0x8F71
-#define EGL_COLOR_RGBA_HI 0x8F72
-#define EGL_COLOR_ARGB_HI 0x8F73
-#endif /* EGL_HI_colorformats */
-
-#ifndef EGL_NOK_swap_region
-#define EGL_NOK_swap_region 1
-
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects);
-#endif
-
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects);
-#endif
-
-
-#ifndef EGL_NOK_texture_from_pixmap
-#define EGL_NOK_texture_from_pixmap 1
-
-#define EGL_Y_INVERTED_NOK 0x307F
-#endif /* EGL_NOK_texture_from_pixmap */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+#ifndef __eglext_h_
+#define __eglext_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2007-2010 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+#include <EGL/eglplatform.h>
+
+/*************************************************************/
+
+/* Header file version number */
+/* Current version at http://www.khronos.org/registry/egl/ */
+/* $Revision$ on $Date: 2010-07-27 20:12:35 -0700 (Tue, 27 Jul 2010) $ */
+#define EGL_EGLEXT_VERSION 7
+
+#ifndef EGL_KHR_config_attribs
+#define EGL_KHR_config_attribs 1
+#define EGL_CONFORMANT_KHR 0x3042 /* EGLConfig attribute */
+#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020 /* EGL_SURFACE_TYPE bitfield */
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040 /* EGL_SURFACE_TYPE bitfield */
+#endif
+
+#ifndef EGL_KHR_lock_surface
+#define EGL_KHR_lock_surface 1
+#define EGL_READ_SURFACE_BIT_KHR 0x0001 /* EGL_LOCK_USAGE_HINT_KHR bitfield */
+#define EGL_WRITE_SURFACE_BIT_KHR 0x0002 /* EGL_LOCK_USAGE_HINT_KHR bitfield */
+#define EGL_LOCK_SURFACE_BIT_KHR 0x0080 /* EGL_SURFACE_TYPE bitfield */
+#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100 /* EGL_SURFACE_TYPE bitfield */
+#define EGL_MATCH_FORMAT_KHR 0x3043 /* EGLConfig attribute */
+#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0 /* EGL_MATCH_FORMAT_KHR value */
+#define EGL_FORMAT_RGB_565_KHR 0x30C1 /* EGL_MATCH_FORMAT_KHR value */
+#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2 /* EGL_MATCH_FORMAT_KHR value */
+#define EGL_FORMAT_RGBA_8888_KHR 0x30C3 /* EGL_MATCH_FORMAT_KHR value */
+#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4 /* eglLockSurfaceKHR attribute */
+#define EGL_LOCK_USAGE_HINT_KHR 0x30C5 /* eglLockSurfaceKHR attribute */
+#define EGL_BITMAP_POINTER_KHR 0x30C6 /* eglQuerySurface attribute */
+#define EGL_BITMAP_PITCH_KHR 0x30C7 /* eglQuerySurface attribute */
+#define EGL_BITMAP_ORIGIN_KHR 0x30C8 /* eglQuerySurface attribute */
+#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9 /* eglQuerySurface attribute */
+#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA /* eglQuerySurface attribute */
+#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB /* eglQuerySurface attribute */
+#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC /* eglQuerySurface attribute */
+#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD /* eglQuerySurface attribute */
+#define EGL_LOWER_LEFT_KHR 0x30CE /* EGL_BITMAP_ORIGIN_KHR value */
+#define EGL_UPPER_LEFT_KHR 0x30CF /* EGL_BITMAP_ORIGIN_KHR value */
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay display, EGLSurface surface);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface);
+#endif
+
+#ifndef EGL_KHR_image
+#define EGL_KHR_image 1
+#define EGL_NATIVE_PIXMAP_KHR 0x30B0 /* eglCreateImageKHR target */
+typedef void *EGLImageKHR;
+#define EGL_NO_IMAGE_KHR ((EGLImageKHR)0)
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
+#endif
+
+#ifndef EGL_KHR_vg_parent_image
+#define EGL_KHR_vg_parent_image 1
+#define EGL_VG_PARENT_IMAGE_KHR 0x30BA /* eglCreateImageKHR target */
+#endif
+
+#ifndef EGL_KHR_gl_texture_2D_image
+#define EGL_KHR_gl_texture_2D_image 1
+#define EGL_GL_TEXTURE_2D_KHR 0x30B1 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC /* eglCreateImageKHR attribute */
+#endif
+
+#ifndef EGL_KHR_gl_texture_cubemap_image
+#define EGL_KHR_gl_texture_cubemap_image 1
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8 /* eglCreateImageKHR target */
+#endif
+
+#ifndef EGL_KHR_gl_texture_3D_image
+#define EGL_KHR_gl_texture_3D_image 1
+#define EGL_GL_TEXTURE_3D_KHR 0x30B2 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD /* eglCreateImageKHR attribute */
+#endif
+
+#ifndef EGL_KHR_gl_renderbuffer_image
+#define EGL_KHR_gl_renderbuffer_image 1
+#define EGL_GL_RENDERBUFFER_KHR 0x30B9 /* eglCreateImageKHR target */
+#endif
+
+#ifndef EGL_MESA_drm_image
+#define EGL_MESA_drm_image 1
+#define EGL_DRM_BUFFER_FORMAT_MESA 0x31D0 /* eglCreateImageKHR attribute */
+#define EGL_DRM_BUFFER_USE_MESA 0x31D1
+
+/* EGL_DRM_BUFFER_FORMAT_MESA tokens */
+#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2
+
+/* EGL_DRM_BUFFER_USE_MESA bits */
+#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x0001
+#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x0002
+
+#define EGL_DRM_BUFFER_MESA 0x31D3 /* eglCreateImageKHR target */
+#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4 /* eglCreateImageKHR attribute */
+
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLImageKHR EGLAPIENTRY eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDRMImageMESA(EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#endif
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESA) (EGLDisplay dpy, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESA) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#endif
+
+#ifndef EGL_WL_bind_wayland_display
+#define EGL_WL_bind_wayland_display 1
+
+#define EGL_WAYLAND_BUFFER_WL 0x31D5 /* eglCreateImageKHR target */
+struct wl_display;
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display);
+EGLAPI EGLBoolean EGLAPIENTRY eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display);
+#else
+typedef EGLBoolean (EGLAPIENTRY PFNEGLBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
+typedef EGLBoolean (EGLAPIENTRY PFNEGLUNBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
+#endif
+#endif
+
+#if KHRONOS_SUPPORT_INT64 /* EGLTimeKHR requires 64-bit uint support */
+#ifndef EGL_KHR_reusable_sync
+#define EGL_KHR_reusable_sync 1
+
+typedef void* EGLSyncKHR;
+typedef khronos_utime_nanoseconds_t EGLTimeKHR;
+
+#define EGL_SYNC_STATUS_KHR 0x30F1
+#define EGL_SIGNALED_KHR 0x30F2
+#define EGL_UNSIGNALED_KHR 0x30F3
+#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5
+#define EGL_CONDITION_SATISFIED_KHR 0x30F6
+#define EGL_SYNC_TYPE_KHR 0x30F7
+#define EGL_SYNC_REUSABLE_KHR 0x30FA
+#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001 /* eglClientWaitSyncKHR <flags> bitfield */
+#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull
+#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0)
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync);
+typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
+#endif
+#endif
+
+/* EGL_MESA_screen extension >>> PRELIMINARY <<< */
+#ifndef EGL_MESA_screen_surface
+#define EGL_MESA_screen_surface 1
+
+#define EGL_BAD_SCREEN_MESA 0x4000
+#define EGL_BAD_MODE_MESA 0x4001
+#define EGL_SCREEN_COUNT_MESA 0x4002
+#define EGL_SCREEN_POSITION_MESA 0x4003
+#define EGL_SCREEN_POSITION_GRANULARITY_MESA 0x4004
+#define EGL_MODE_ID_MESA 0x4005
+#define EGL_REFRESH_RATE_MESA 0x4006
+#define EGL_OPTIMAL_MESA 0x4007
+#define EGL_INTERLACED_MESA 0x4008
+#define EGL_SCREEN_BIT_MESA 0x08
+
+typedef khronos_uint32_t EGLScreenMESA;
+typedef khronos_uint32_t EGLModeMESA;
+
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglChooseModeMESA(EGLDisplay dpy, EGLScreenMESA screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens);
+EGLAPI EGLSurface EGLAPIENTRY eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglShowScreenSurfaceMESA(EGLDisplay dpy, EGLint screen, EGLSurface surface, EGLModeMESA mode);
+EGLAPI EGLBoolean EGLAPIENTRY eglScreenPositionMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryScreenMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryScreenModeMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode);
+EGLAPI const char * EGLAPIENTRY eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCHOOSEMODEMESA) (EGLDisplay dpy, EGLScreenMESA screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETMODESMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGetModeATTRIBMESA) (EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSCRREENSMESA) (EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens);
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATESCREENSURFACEMESA) (EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSHOWSCREENSURFACEMESA) (EGLDisplay dpy, EGLint screen, EGLSurface surface, EGLModeMESA mode);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSCREENPOSIITONMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSCREENMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSCREENSURFACEMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSCREENMODEMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode);
+typedef const char * (EGLAPIENTRYP PFNEGLQUERYMODESTRINGMESA) (EGLDisplay dpy, EGLModeMESA mode);
+
+#endif /* EGL_MESA_screen_surface */
+
+
+#ifndef EGL_MESA_copy_context
+#define EGL_MESA_copy_context 1
+
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglCopyContextMESA(EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOPYCONTEXTMESA) (EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask);
+
+#endif /* EGL_MESA_copy_context */
+
+#ifndef EGL_MESA_drm_display
+#define EGL_MESA_drm_display 1
+
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLDisplay EGLAPIENTRY eglGetDRMDisplayMESA(int fd);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+
+typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETDRMDISPLAYMESA) (int fd);
+
+#endif /* EGL_MESA_drm_display */
+
+#ifndef EGL_KHR_image_base
+#define EGL_KHR_image_base 1
+/* Most interfaces defined by EGL_KHR_image_pixmap above */
+#define EGL_IMAGE_PRESERVED_KHR 0x30D2 /* eglCreateImageKHR attribute */
+#endif
+
+#ifndef EGL_KHR_image_pixmap
+#define EGL_KHR_image_pixmap 1
+/* Interfaces defined by EGL_KHR_image above */
+#endif
+
+#ifndef EGL_IMG_context_priority
+#define EGL_IMG_context_priority 1
+#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100
+#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101
+#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102
+#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103
+#endif
+
+#ifndef EGL_KHR_lock_surface2
+#define EGL_KHR_lock_surface2 1
+#define EGL_BITMAP_PIXEL_SIZE_KHR 0x3110
+#endif
+
+#ifndef EGL_NV_coverage_sample
+#define EGL_NV_coverage_sample 1
+#define EGL_COVERAGE_BUFFERS_NV 0x30E0
+#define EGL_COVERAGE_SAMPLES_NV 0x30E1
+#endif
+
+#ifndef EGL_NV_depth_nonlinear
+#define EGL_NV_depth_nonlinear 1
+#define EGL_DEPTH_ENCODING_NV 0x30E2
+#define EGL_DEPTH_ENCODING_NONE_NV 0
+#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3
+#endif
+
+#if KHRONOS_SUPPORT_INT64 /* EGLTimeNV requires 64-bit uint support */
+#ifndef EGL_NV_sync
+#define EGL_NV_sync 1
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6
+#define EGL_SYNC_STATUS_NV 0x30E7
+#define EGL_SIGNALED_NV 0x30E8
+#define EGL_UNSIGNALED_NV 0x30E9
+#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001
+#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull
+#define EGL_ALREADY_SIGNALED_NV 0x30EA
+#define EGL_TIMEOUT_EXPIRED_NV 0x30EB
+#define EGL_CONDITION_SATISFIED_NV 0x30EC
+#define EGL_SYNC_TYPE_NV 0x30ED
+#define EGL_SYNC_CONDITION_NV 0x30EE
+#define EGL_SYNC_FENCE_NV 0x30EF
+#define EGL_NO_SYNC_NV ((EGLSyncNV)0)
+typedef void* EGLSyncNV;
+typedef khronos_utime_nanoseconds_t EGLTimeNV;
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLSyncNV eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
+EGLBoolean eglDestroySyncNV (EGLSyncNV sync);
+EGLBoolean eglFenceNV (EGLSyncNV sync);
+EGLint eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
+EGLBoolean eglSignalSyncNV (EGLSyncNV sync, EGLenum mode);
+EGLBoolean eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync);
+typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value);
+#endif
+#endif
+
+#if KHRONOS_SUPPORT_INT64 /* Dependent on EGL_KHR_reusable_sync which requires 64-bit uint support */
+#ifndef EGL_KHR_fence_sync
+#define EGL_KHR_fence_sync 1
+/* Reuses most tokens and entry points from EGL_KHR_reusable_sync */
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0
+#define EGL_SYNC_CONDITION_KHR 0x30F8
+#define EGL_SYNC_FENCE_KHR 0x30F9
+#endif
+#endif
+
+#ifndef EGL_HI_clientpixmap
+#define EGL_HI_clientpixmap 1
+
+/* Surface Attribute */
+#define EGL_CLIENT_PIXMAP_POINTER_HI 0x8F74
+/*
+ * Structure representing a client pixmap
+ * (pixmap's data is in client-space memory).
+ */
+struct EGLClientPixmapHI
+{
+ void* pData;
+ EGLint iWidth;
+ EGLint iHeight;
+ EGLint iStride;
+};
+
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI(EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap);
+#endif /* EGL_HI_clientpixmap */
+
+#ifndef EGL_HI_colorformats
+#define EGL_HI_colorformats 1
+/* Config Attribute */
+#define EGL_COLOR_FORMAT_HI 0x8F70
+/* Color Formats */
+#define EGL_COLOR_RGB_HI 0x8F71
+#define EGL_COLOR_RGBA_HI 0x8F72
+#define EGL_COLOR_ARGB_HI 0x8F73
+#endif /* EGL_HI_colorformats */
+
+#ifndef EGL_NOK_swap_region
+#define EGL_NOK_swap_region 1
+
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects);
+#endif
+
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects);
+#endif
+
+
+#ifndef EGL_NOK_texture_from_pixmap
+#define EGL_NOK_texture_from_pixmap 1
+
+#define EGL_Y_INVERTED_NOK 0x307F
+#endif /* EGL_NOK_texture_from_pixmap */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/mesalib/include/GL/internal/dri_interface.h b/mesalib/include/GL/internal/dri_interface.h
index 2fb729afc..8098a2eb9 100644
--- a/mesalib/include/GL/internal/dri_interface.h
+++ b/mesalib/include/GL/internal/dri_interface.h
@@ -1,887 +1,889 @@
-/*
- * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2007-2008 Red Hat, Inc.
- * (C) Copyright IBM Corporation 2004
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * on the rights to use, copy, modify, merge, publish, distribute, sub
- * license, and/or sell copies of the Software, and to permit persons to whom
- * the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file dri_interface.h
- *
- * This file contains all the types and functions that define the interface
- * between a DRI driver and driver loader. Currently, the most common driver
- * loader is the XFree86 libGL.so. However, other loaders do exist, and in
- * the future the server-side libglx.a will also be a loader.
- *
- * \author Kevin E. Martin <kevin@precisioninsight.com>
- * \author Ian Romanick <idr@us.ibm.com>
- * \author Kristian Høgsberg <krh@redhat.com>
- */
-
-#ifndef DRI_INTERFACE_H
-#define DRI_INTERFACE_H
-
-/* For archs with no drm.h */
-#if defined(__APPLE__) || defined(__CYGWIN__) || defined(__GNU__)
-#ifndef __NOT_HAVE_DRM_H
-#define __NOT_HAVE_DRM_H
-#endif
-#endif
-
-#ifndef __NOT_HAVE_DRM_H
-#include <drm.h>
-#else
-typedef unsigned int drm_context_t;
-typedef unsigned int drm_drawable_t;
-typedef struct drm_clip_rect drm_clip_rect_t;
-#endif
-
-/**
- * \name DRI interface structures
- *
- * The following structures define the interface between the GLX client
- * side library and the DRI (direct rendering infrastructure).
- */
-/*@{*/
-typedef struct __DRIdisplayRec __DRIdisplay;
-typedef struct __DRIscreenRec __DRIscreen;
-typedef struct __DRIcontextRec __DRIcontext;
-typedef struct __DRIdrawableRec __DRIdrawable;
-typedef struct __DRIconfigRec __DRIconfig;
-typedef struct __DRIframebufferRec __DRIframebuffer;
-typedef struct __DRIversionRec __DRIversion;
-
-typedef struct __DRIcoreExtensionRec __DRIcoreExtension;
-typedef struct __DRIextensionRec __DRIextension;
-typedef struct __DRIcopySubBufferExtensionRec __DRIcopySubBufferExtension;
-typedef struct __DRIswapControlExtensionRec __DRIswapControlExtension;
-typedef struct __DRIframeTrackingExtensionRec __DRIframeTrackingExtension;
-typedef struct __DRImediaStreamCounterExtensionRec __DRImediaStreamCounterExtension;
-typedef struct __DRItexOffsetExtensionRec __DRItexOffsetExtension;
-typedef struct __DRItexBufferExtensionRec __DRItexBufferExtension;
-typedef struct __DRIlegacyExtensionRec __DRIlegacyExtension;
-typedef struct __DRIswrastExtensionRec __DRIswrastExtension;
-typedef struct __DRIbufferRec __DRIbuffer;
-typedef struct __DRIdri2ExtensionRec __DRIdri2Extension;
-typedef struct __DRIdri2LoaderExtensionRec __DRIdri2LoaderExtension;
-typedef struct __DRI2flushExtensionRec __DRI2flushExtension;
-
-/*@}*/
-
-
-/**
- * Extension struct. Drivers 'inherit' from this struct by embedding
- * it as the first element in the extension struct.
- *
- * We never break API in for a DRI extension. If we need to change
- * the way things work in a non-backwards compatible manner, we
- * introduce a new extension. During a transition period, we can
- * leave both the old and the new extension in the driver, which
- * allows us to move to the new interface without having to update the
- * loader(s) in lock step.
- *
- * However, we can add entry points to an extension over time as long
- * as we don't break the old ones. As we add entry points to an
- * extension, we increase the version number. The corresponding
- * #define can be used to guard code that accesses the new entry
- * points at compile time and the version field in the extension
- * struct can be used at run-time to determine how to use the
- * extension.
- */
-struct __DRIextensionRec {
- const char *name;
- int version;
-};
-
-/**
- * The first set of extension are the screen extensions, returned by
- * __DRIcore::getExtensions(). This entry point will return a list of
- * extensions and the loader can use the ones it knows about by
- * casting them to more specific extensions and advertising any GLX
- * extensions the DRI extensions enables.
- */
-
-/**
- * Used by drivers to indicate support for setting the read drawable.
- */
-#define __DRI_READ_DRAWABLE "DRI_ReadDrawable"
-#define __DRI_READ_DRAWABLE_VERSION 1
-
-/**
- * Used by drivers that implement the GLX_MESA_copy_sub_buffer extension.
- */
-#define __DRI_COPY_SUB_BUFFER "DRI_CopySubBuffer"
-#define __DRI_COPY_SUB_BUFFER_VERSION 1
-struct __DRIcopySubBufferExtensionRec {
- __DRIextension base;
- void (*copySubBuffer)(__DRIdrawable *drawable, int x, int y, int w, int h);
-};
-
-/**
- * Used by drivers that implement the GLX_SGI_swap_control or
- * GLX_MESA_swap_control extension.
- */
-#define __DRI_SWAP_CONTROL "DRI_SwapControl"
-#define __DRI_SWAP_CONTROL_VERSION 1
-struct __DRIswapControlExtensionRec {
- __DRIextension base;
- void (*setSwapInterval)(__DRIdrawable *drawable, unsigned int inteval);
- unsigned int (*getSwapInterval)(__DRIdrawable *drawable);
-};
-
-/**
- * Used by drivers that implement the GLX_MESA_swap_frame_usage extension.
- */
-#define __DRI_FRAME_TRACKING "DRI_FrameTracking"
-#define __DRI_FRAME_TRACKING_VERSION 1
-struct __DRIframeTrackingExtensionRec {
- __DRIextension base;
-
- /**
- * Enable or disable frame usage tracking.
- *
- * \since Internal API version 20030317.
- */
- int (*frameTracking)(__DRIdrawable *drawable, GLboolean enable);
-
- /**
- * Retrieve frame usage information.
- *
- * \since Internal API version 20030317.
- */
- int (*queryFrameTracking)(__DRIdrawable *drawable,
- int64_t * sbc, int64_t * missedFrames,
- float * lastMissedUsage, float * usage);
-};
-
-
-/**
- * Used by drivers that implement the GLX_SGI_video_sync extension.
- */
-#define __DRI_MEDIA_STREAM_COUNTER "DRI_MediaStreamCounter"
-#define __DRI_MEDIA_STREAM_COUNTER_VERSION 1
-struct __DRImediaStreamCounterExtensionRec {
- __DRIextension base;
-
- /**
- * Wait for the MSC to equal target_msc, or, if that has already passed,
- * the next time (MSC % divisor) is equal to remainder. If divisor is
- * zero, the function will return as soon as MSC is greater than or equal
- * to target_msc.
- */
- int (*waitForMSC)(__DRIdrawable *drawable,
- int64_t target_msc, int64_t divisor, int64_t remainder,
- int64_t * msc, int64_t * sbc);
-
- /**
- * Get the number of vertical refreshes since some point in time before
- * this function was first called (i.e., system start up).
- */
- int (*getDrawableMSC)(__DRIscreen *screen, __DRIdrawable *drawable,
- int64_t *msc);
-};
-
-
-#define __DRI_TEX_OFFSET "DRI_TexOffset"
-#define __DRI_TEX_OFFSET_VERSION 1
-struct __DRItexOffsetExtensionRec {
- __DRIextension base;
-
- /**
- * Method to override base texture image with a driver specific 'offset'.
- * The depth passed in allows e.g. to ignore the alpha channel of texture
- * images where the non-alpha components don't occupy a whole texel.
- *
- * For GLX_EXT_texture_from_pixmap with AIGLX.
- */
- void (*setTexOffset)(__DRIcontext *pDRICtx, GLint texname,
- unsigned long long offset, GLint depth, GLuint pitch);
-};
-
-
-/* Valid values for format in the setTexBuffer2 function below. These
- * values match the GLX tokens for compatibility reasons, but we
- * define them here since the DRI interface can't depend on GLX. */
-#define __DRI_TEXTURE_FORMAT_NONE 0x20D8
-#define __DRI_TEXTURE_FORMAT_RGB 0x20D9
-#define __DRI_TEXTURE_FORMAT_RGBA 0x20DA
-
-#define __DRI_TEX_BUFFER "DRI_TexBuffer"
-#define __DRI_TEX_BUFFER_VERSION 2
-struct __DRItexBufferExtensionRec {
- __DRIextension base;
-
- /**
- * Method to override base texture image with the contents of a
- * __DRIdrawable.
- *
- * For GLX_EXT_texture_from_pixmap with AIGLX. Deprecated in favor of
- * setTexBuffer2 in version 2 of this interface
- */
- void (*setTexBuffer)(__DRIcontext *pDRICtx,
- GLint target,
- __DRIdrawable *pDraw);
-
- /**
- * Method to override base texture image with the contents of a
- * __DRIdrawable, including the required texture format attribute.
- *
- * For GLX_EXT_texture_from_pixmap with AIGLX.
- */
- void (*setTexBuffer2)(__DRIcontext *pDRICtx,
- GLint target,
- GLint format,
- __DRIdrawable *pDraw);
- /**
- * Method to release texture buffer in case some special platform
- * need this.
- *
- * For GLX_EXT_texture_from_pixmap with AIGLX.
- */
- void (*releaseTexBuffer)(__DRIcontext *pDRICtx,
- GLint target,
- __DRIdrawable *pDraw);
-};
-
-/**
- * Used by drivers that implement DRI2
- */
-#define __DRI2_FLUSH "DRI2_Flush"
-#define __DRI2_FLUSH_VERSION 3
-struct __DRI2flushExtensionRec {
- __DRIextension base;
- void (*flush)(__DRIdrawable *drawable);
-
- /**
- * Ask the driver to call getBuffers/getBuffersWithFormat before
- * it starts rendering again.
- *
- * \param drawable the drawable to invalidate
- *
- * \since 3
- */
- void (*invalidate)(__DRIdrawable *drawable);
-};
-
-
-/**
- * XML document describing the configuration options supported by the
- * driver.
- */
-extern const char __driConfigOptions[];
-
-/*@}*/
-
-/**
- * The following extensions describe loader features that the DRI
- * driver can make use of. Some of these are mandatory, such as the
- * getDrawableInfo extension for DRI and the DRI Loader extensions for
- * DRI2, while others are optional, and if present allow the driver to
- * expose certain features. The loader pass in a NULL terminated
- * array of these extensions to the driver in the createNewScreen
- * constructor.
- */
-
-typedef struct __DRIgetDrawableInfoExtensionRec __DRIgetDrawableInfoExtension;
-typedef struct __DRIsystemTimeExtensionRec __DRIsystemTimeExtension;
-typedef struct __DRIdamageExtensionRec __DRIdamageExtension;
-typedef struct __DRIloaderExtensionRec __DRIloaderExtension;
-typedef struct __DRIswrastLoaderExtensionRec __DRIswrastLoaderExtension;
-
-
-/**
- * Callback to getDrawableInfo protocol
- */
-#define __DRI_GET_DRAWABLE_INFO "DRI_GetDrawableInfo"
-#define __DRI_GET_DRAWABLE_INFO_VERSION 1
-struct __DRIgetDrawableInfoExtensionRec {
- __DRIextension base;
-
- /**
- * This function is used to get information about the position, size, and
- * clip rects of a drawable.
- */
- GLboolean (* getDrawableInfo) ( __DRIdrawable *drawable,
- unsigned int * index, unsigned int * stamp,
- int * x, int * y, int * width, int * height,
- int * numClipRects, drm_clip_rect_t ** pClipRects,
- int * backX, int * backY,
- int * numBackClipRects, drm_clip_rect_t ** pBackClipRects,
- void *loaderPrivate);
-};
-
-/**
- * Callback to get system time for media stream counter extensions.
- */
-#define __DRI_SYSTEM_TIME "DRI_SystemTime"
-#define __DRI_SYSTEM_TIME_VERSION 1
-struct __DRIsystemTimeExtensionRec {
- __DRIextension base;
-
- /**
- * Get the 64-bit unadjusted system time (UST).
- */
- int (*getUST)(int64_t * ust);
-
- /**
- * Get the media stream counter (MSC) rate.
- *
- * Matching the definition in GLX_OML_sync_control, this function returns
- * the rate of the "media stream counter". In practical terms, this is
- * the frame refresh rate of the display.
- */
- GLboolean (*getMSCRate)(__DRIdrawable *draw,
- int32_t * numerator, int32_t * denominator,
- void *loaderPrivate);
-};
-
-/**
- * Damage reporting
- */
-#define __DRI_DAMAGE "DRI_Damage"
-#define __DRI_DAMAGE_VERSION 1
-struct __DRIdamageExtensionRec {
- __DRIextension base;
-
- /**
- * Reports areas of the given drawable which have been modified by the
- * driver.
- *
- * \param drawable which the drawing was done to.
- * \param rects rectangles affected, with the drawable origin as the
- * origin.
- * \param x X offset of the drawable within the screen (used in the
- * front_buffer case)
- * \param y Y offset of the drawable within the screen.
- * \param front_buffer boolean flag for whether the drawing to the
- * drawable was actually done directly to the front buffer (instead
- * of backing storage, for example)
- * \param loaderPrivate the data passed in at createNewDrawable time
- */
- void (*reportDamage)(__DRIdrawable *draw,
- int x, int y,
- drm_clip_rect_t *rects, int num_rects,
- GLboolean front_buffer,
- void *loaderPrivate);
-};
-
-#define __DRI_SWRAST_IMAGE_OP_DRAW 1
-#define __DRI_SWRAST_IMAGE_OP_CLEAR 2
-#define __DRI_SWRAST_IMAGE_OP_SWAP 3
-
-/**
- * SWRast Loader extension.
- */
-#define __DRI_SWRAST_LOADER "DRI_SWRastLoader"
-#define __DRI_SWRAST_LOADER_VERSION 1
-struct __DRIswrastLoaderExtensionRec {
- __DRIextension base;
-
- /*
- * Drawable position and size
- */
- void (*getDrawableInfo)(__DRIdrawable *drawable,
- int *x, int *y, int *width, int *height,
- void *loaderPrivate);
-
- /**
- * Put image to drawable
- */
- void (*putImage)(__DRIdrawable *drawable, int op,
- int x, int y, int width, int height,
- char *data, void *loaderPrivate);
-
- /**
- * Get image from readable
- */
- void (*getImage)(__DRIdrawable *readable,
- int x, int y, int width, int height,
- char *data, void *loaderPrivate);
-};
-
-/**
- * Invalidate loader extension. The presence of this extension
- * indicates to the DRI driver that the loader will call invalidate in
- * the __DRI2_FLUSH extension, whenever the needs to query for new
- * buffers. This means that the DRI driver can drop the polling in
- * glViewport().
- *
- * The extension doesn't provide any functionality, it's only use to
- * indicate to the driver that it can use the new semantics. A DRI
- * driver can use this to switch between the different semantics or
- * just refuse to initialize if this extension isn't present.
- */
-#define __DRI_USE_INVALIDATE "DRI_UseInvalidate"
-#define __DRI_USE_INVALIDATE_VERSION 1
-
-typedef struct __DRIuseInvalidateExtensionRec __DRIuseInvalidateExtension;
-struct __DRIuseInvalidateExtensionRec {
- __DRIextension base;
-};
-
-/**
- * The remaining extensions describe driver extensions, immediately
- * available interfaces provided by the driver. To start using the
- * driver, dlsym() for the __DRI_DRIVER_EXTENSIONS symbol and look for
- * the extension you need in the array.
- */
-#define __DRI_DRIVER_EXTENSIONS "__driDriverExtensions"
-
-/**
- * Tokens for __DRIconfig attribs. A number of attributes defined by
- * GLX or EGL standards are not in the table, as they must be provided
- * by the loader. For example, FBConfig ID or visual ID, drawable type.
- */
-
-#define __DRI_ATTRIB_BUFFER_SIZE 1
-#define __DRI_ATTRIB_LEVEL 2
-#define __DRI_ATTRIB_RED_SIZE 3
-#define __DRI_ATTRIB_GREEN_SIZE 4
-#define __DRI_ATTRIB_BLUE_SIZE 5
-#define __DRI_ATTRIB_LUMINANCE_SIZE 6
-#define __DRI_ATTRIB_ALPHA_SIZE 7
-#define __DRI_ATTRIB_ALPHA_MASK_SIZE 8
-#define __DRI_ATTRIB_DEPTH_SIZE 9
-#define __DRI_ATTRIB_STENCIL_SIZE 10
-#define __DRI_ATTRIB_ACCUM_RED_SIZE 11
-#define __DRI_ATTRIB_ACCUM_GREEN_SIZE 12
-#define __DRI_ATTRIB_ACCUM_BLUE_SIZE 13
-#define __DRI_ATTRIB_ACCUM_ALPHA_SIZE 14
-#define __DRI_ATTRIB_SAMPLE_BUFFERS 15
-#define __DRI_ATTRIB_SAMPLES 16
-#define __DRI_ATTRIB_RENDER_TYPE 17
-#define __DRI_ATTRIB_CONFIG_CAVEAT 18
-#define __DRI_ATTRIB_CONFORMANT 19
-#define __DRI_ATTRIB_DOUBLE_BUFFER 20
-#define __DRI_ATTRIB_STEREO 21
-#define __DRI_ATTRIB_AUX_BUFFERS 22
-#define __DRI_ATTRIB_TRANSPARENT_TYPE 23
-#define __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE 24
-#define __DRI_ATTRIB_TRANSPARENT_RED_VALUE 25
-#define __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE 26
-#define __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE 27
-#define __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE 28
-#define __DRI_ATTRIB_FLOAT_MODE 29
-#define __DRI_ATTRIB_RED_MASK 30
-#define __DRI_ATTRIB_GREEN_MASK 31
-#define __DRI_ATTRIB_BLUE_MASK 32
-#define __DRI_ATTRIB_ALPHA_MASK 33
-#define __DRI_ATTRIB_MAX_PBUFFER_WIDTH 34
-#define __DRI_ATTRIB_MAX_PBUFFER_HEIGHT 35
-#define __DRI_ATTRIB_MAX_PBUFFER_PIXELS 36
-#define __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH 37
-#define __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT 38
-#define __DRI_ATTRIB_VISUAL_SELECT_GROUP 39
-#define __DRI_ATTRIB_SWAP_METHOD 40
-#define __DRI_ATTRIB_MAX_SWAP_INTERVAL 41
-#define __DRI_ATTRIB_MIN_SWAP_INTERVAL 42
-#define __DRI_ATTRIB_BIND_TO_TEXTURE_RGB 43
-#define __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA 44
-#define __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE 45
-#define __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS 46
-#define __DRI_ATTRIB_YINVERTED 47
-#define __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE 48
-
-/* __DRI_ATTRIB_RENDER_TYPE */
-#define __DRI_ATTRIB_RGBA_BIT 0x01
-#define __DRI_ATTRIB_COLOR_INDEX_BIT 0x02
-#define __DRI_ATTRIB_LUMINANCE_BIT 0x04
-
-/* __DRI_ATTRIB_CONFIG_CAVEAT */
-#define __DRI_ATTRIB_SLOW_BIT 0x01
-#define __DRI_ATTRIB_NON_CONFORMANT_CONFIG 0x02
-
-/* __DRI_ATTRIB_TRANSPARENT_TYPE */
-#define __DRI_ATTRIB_TRANSPARENT_RGB 0x00
-#define __DRI_ATTRIB_TRANSPARENT_INDEX 0x01
-
-/* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */
-#define __DRI_ATTRIB_TEXTURE_1D_BIT 0x01
-#define __DRI_ATTRIB_TEXTURE_2D_BIT 0x02
-#define __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT 0x04
-
-/**
- * This extension defines the core DRI functionality.
- */
-#define __DRI_CORE "DRI_Core"
-#define __DRI_CORE_VERSION 1
-
-struct __DRIcoreExtensionRec {
- __DRIextension base;
-
- __DRIscreen *(*createNewScreen)(int screen, int fd,
- unsigned int sarea_handle,
- const __DRIextension **extensions,
- const __DRIconfig ***driverConfigs,
- void *loaderPrivate);
-
- void (*destroyScreen)(__DRIscreen *screen);
-
- const __DRIextension **(*getExtensions)(__DRIscreen *screen);
-
- int (*getConfigAttrib)(const __DRIconfig *config,
- unsigned int attrib,
- unsigned int *value);
-
- int (*indexConfigAttrib)(const __DRIconfig *config, int index,
- unsigned int *attrib, unsigned int *value);
-
- __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
- const __DRIconfig *config,
- unsigned int drawable_id,
- unsigned int head,
- void *loaderPrivate);
-
- void (*destroyDrawable)(__DRIdrawable *drawable);
-
- void (*swapBuffers)(__DRIdrawable *drawable);
-
- __DRIcontext *(*createNewContext)(__DRIscreen *screen,
- const __DRIconfig *config,
- __DRIcontext *shared,
- void *loaderPrivate);
-
- int (*copyContext)(__DRIcontext *dest,
- __DRIcontext *src,
- unsigned long mask);
-
- void (*destroyContext)(__DRIcontext *context);
-
- int (*bindContext)(__DRIcontext *ctx,
- __DRIdrawable *pdraw,
- __DRIdrawable *pread);
-
- int (*unbindContext)(__DRIcontext *ctx);
-};
-
-/**
- * Stored version of some component (i.e., server-side DRI module, kernel-side
- * DRM, etc.).
- *
- * \todo
- * There are several data structures that explicitly store a major version,
- * minor version, and patch level. These structures should be modified to
- * have a \c __DRIversionRec instead.
- */
-struct __DRIversionRec {
- int major; /**< Major version number. */
- int minor; /**< Minor version number. */
- int patch; /**< Patch-level. */
-};
-
-/**
- * Framebuffer information record. Used by libGL to communicate information
- * about the framebuffer to the driver's \c __driCreateNewScreen function.
- *
- * In XFree86, most of this information is derrived from data returned by
- * calling \c XF86DRIGetDeviceInfo.
- *
- * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
- * __driUtilCreateNewScreen CallCreateNewScreen
- *
- * \bug This structure could be better named.
- */
-struct __DRIframebufferRec {
- unsigned char *base; /**< Framebuffer base address in the CPU's
- * address space. This value is calculated by
- * calling \c drmMap on the framebuffer handle
- * returned by \c XF86DRIGetDeviceInfo (or a
- * similar function).
- */
- int size; /**< Framebuffer size, in bytes. */
- int stride; /**< Number of bytes from one line to the next. */
- int width; /**< Pixel width of the framebuffer. */
- int height; /**< Pixel height of the framebuffer. */
- int dev_priv_size; /**< Size of the driver's dev-priv structure. */
- void *dev_priv; /**< Pointer to the driver's dev-priv structure. */
-};
-
-
-/**
- * This extension provides alternative screen, drawable and context
- * constructors for legacy DRI functionality. This is used in
- * conjunction with the core extension.
- */
-#define __DRI_LEGACY "DRI_Legacy"
-#define __DRI_LEGACY_VERSION 1
-
-struct __DRIlegacyExtensionRec {
- __DRIextension base;
-
- __DRIscreen *(*createNewScreen)(int screen,
- const __DRIversion *ddx_version,
- const __DRIversion *dri_version,
- const __DRIversion *drm_version,
- const __DRIframebuffer *frame_buffer,
- void *pSAREA, int fd,
- const __DRIextension **extensions,
- const __DRIconfig ***driver_configs,
- void *loaderPrivate);
-
- __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
- const __DRIconfig *config,
- drm_drawable_t hwDrawable,
- int renderType, const int *attrs,
- void *loaderPrivate);
-
- __DRIcontext *(*createNewContext)(__DRIscreen *screen,
- const __DRIconfig *config,
- int render_type,
- __DRIcontext *shared,
- drm_context_t hwContext,
- void *loaderPrivate);
-};
-
-/**
- * This extension provides alternative screen, drawable and context
- * constructors for swrast DRI functionality. This is used in
- * conjunction with the core extension.
- */
-#define __DRI_SWRAST "DRI_SWRast"
-#define __DRI_SWRAST_VERSION 2
-
-struct __DRIswrastExtensionRec {
- __DRIextension base;
-
- __DRIscreen *(*createNewScreen)(int screen,
- const __DRIextension **extensions,
- const __DRIconfig ***driver_configs,
- void *loaderPrivate);
-
- __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
- const __DRIconfig *config,
- void *loaderPrivate);
-
- /* Since version 2 */
- __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen,
- int api,
- const __DRIconfig *config,
- __DRIcontext *shared,
- void *data);
-};
-
-/**
- * DRI2 Loader extension.
- */
-#define __DRI_BUFFER_FRONT_LEFT 0
-#define __DRI_BUFFER_BACK_LEFT 1
-#define __DRI_BUFFER_FRONT_RIGHT 2
-#define __DRI_BUFFER_BACK_RIGHT 3
-#define __DRI_BUFFER_DEPTH 4
-#define __DRI_BUFFER_STENCIL 5
-#define __DRI_BUFFER_ACCUM 6
-#define __DRI_BUFFER_FAKE_FRONT_LEFT 7
-#define __DRI_BUFFER_FAKE_FRONT_RIGHT 8
-#define __DRI_BUFFER_DEPTH_STENCIL 9 /**< Only available with DRI2 1.1 */
-
-struct __DRIbufferRec {
- unsigned int attachment;
- unsigned int name;
- unsigned int pitch;
- unsigned int cpp;
- unsigned int flags;
-};
-
-#define __DRI_DRI2_LOADER "DRI_DRI2Loader"
-#define __DRI_DRI2_LOADER_VERSION 3
-struct __DRIdri2LoaderExtensionRec {
- __DRIextension base;
-
- __DRIbuffer *(*getBuffers)(__DRIdrawable *driDrawable,
- int *width, int *height,
- unsigned int *attachments, int count,
- int *out_count, void *loaderPrivate);
-
- /**
- * Flush pending front-buffer rendering
- *
- * Any rendering that has been performed to the
- * \c __DRI_BUFFER_FAKE_FRONT_LEFT will be flushed to the
- * \c __DRI_BUFFER_FRONT_LEFT.
- *
- * \param driDrawable Drawable whose front-buffer is to be flushed
- * \param loaderPrivate Loader's private data that was previously passed
- * into __DRIdri2ExtensionRec::createNewDrawable
- */
- void (*flushFrontBuffer)(__DRIdrawable *driDrawable, void *loaderPrivate);
-
-
- /**
- * Get list of buffers from the server
- *
- * Gets a list of buffer for the specified set of attachments. Unlike
- * \c ::getBuffers, this function takes a list of attachments paired with
- * opaque \c unsigned \c int value describing the format of the buffer.
- * It is the responsibility of the caller to know what the service that
- * allocates the buffers will expect to receive for the format.
- *
- * \param driDrawable Drawable whose buffers are being queried.
- * \param width Output where the width of the buffers is stored.
- * \param height Output where the height of the buffers is stored.
- * \param attachments List of pairs of attachment ID and opaque format
- * requested for the drawable.
- * \param count Number of attachment / format pairs stored in
- * \c attachments.
- * \param loaderPrivate Loader's private data that was previously passed
- * into __DRIdri2ExtensionRec::createNewDrawable.
- */
- __DRIbuffer *(*getBuffersWithFormat)(__DRIdrawable *driDrawable,
- int *width, int *height,
- unsigned int *attachments, int count,
- int *out_count, void *loaderPrivate);
-};
-
-/**
- * This extension provides alternative screen, drawable and context
- * constructors for DRI2.
- */
-#define __DRI_DRI2 "DRI_DRI2"
-#define __DRI_DRI2_VERSION 2
-
-#define __DRI_API_OPENGL 0
-#define __DRI_API_GLES 1
-#define __DRI_API_GLES2 2
-
-struct __DRIdri2ExtensionRec {
- __DRIextension base;
-
- __DRIscreen *(*createNewScreen)(int screen, int fd,
- const __DRIextension **extensions,
- const __DRIconfig ***driver_configs,
- void *loaderPrivate);
-
- __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
- const __DRIconfig *config,
- void *loaderPrivate);
-
- __DRIcontext *(*createNewContext)(__DRIscreen *screen,
- const __DRIconfig *config,
- __DRIcontext *shared,
- void *loaderPrivate);
-
- /* Since version 2 */
- unsigned int (*getAPIMask)(__DRIscreen *screen);
-
- __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen,
- int api,
- const __DRIconfig *config,
- __DRIcontext *shared,
- void *data);
-
- __DRIbuffer *(*allocateBuffer)(__DRIscreen *screen,
- unsigned int attachment,
- unsigned int format,
- int width,
- int height);
- void (*releaseBuffer)(__DRIscreen *screen,
- __DRIbuffer *buffer);
-};
-
-
-/**
- * This extension provides functionality to enable various EGLImage
- * extensions.
- */
-#define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 1
-
-/**
- * These formats correspond to the similarly named MESA_FORMAT_*
- * tokens, except in the native endian of the CPU. For example, on
- * little endian __DRI_IMAGE_FORMAT_XRGB8888 corresponds to
- * MESA_FORMAT_XRGB8888, but MESA_FORMAT_XRGB8888_REV on big endian.
- */
-#define __DRI_IMAGE_FORMAT_RGB565 0x1001
-#define __DRI_IMAGE_FORMAT_XRGB8888 0x1002
-#define __DRI_IMAGE_FORMAT_ARGB8888 0x1003
-
-#define __DRI_IMAGE_USE_SHARE 0x0001
-#define __DRI_IMAGE_USE_SCANOUT 0x0002
-
-/**
- * queryImage attributes
- */
-
-#define __DRI_IMAGE_ATTRIB_STRIDE 0x2000
-#define __DRI_IMAGE_ATTRIB_HANDLE 0x2001
-#define __DRI_IMAGE_ATTRIB_NAME 0x2002
-
-typedef struct __DRIimageRec __DRIimage;
-typedef struct __DRIimageExtensionRec __DRIimageExtension;
-struct __DRIimageExtensionRec {
- __DRIextension base;
-
- __DRIimage *(*createImageFromName)(__DRIscreen *screen,
- int width, int height, int format,
- int name, int pitch,
- void *loaderPrivate);
-
- __DRIimage *(*createImageFromRenderbuffer)(__DRIcontext *context,
- int renderbuffer,
- void *loaderPrivate);
-
- void (*destroyImage)(__DRIimage *image);
-
- __DRIimage *(*createImage)(__DRIscreen *screen,
- int width, int height, int format,
- unsigned int use,
- void *loaderPrivate);
-
- GLboolean (*queryImage)(__DRIimage *image, int attrib, int *value);
-};
-
-
-/**
- * This extension must be implemented by the loader and passed to the
- * driver at screen creation time. The EGLImage entry points in the
- * various client APIs take opaque EGLImage handles and use this
- * extension to map them to a __DRIimage. At version 1, this
- * extensions allows mapping EGLImage pointers to __DRIimage pointers,
- * but future versions could support other EGLImage-like, opaque types
- * with new lookup functions.
- */
-#define __DRI_IMAGE_LOOKUP "DRI_IMAGE_LOOKUP"
-#define __DRI_IMAGE_LOOKUP_VERSION 1
-
-typedef struct __DRIimageLookupExtensionRec __DRIimageLookupExtension;
-struct __DRIimageLookupExtensionRec {
- __DRIextension base;
-
- __DRIimage *(*lookupEGLImage)(__DRIscreen *screen, void *image,
- void *loaderPrivate);
-};
-
-/**
- * This extension allows for common DRI2 options
- */
-#define __DRI2_CONFIG_QUERY "DRI_CONFIG_QUERY"
-#define __DRI2_CONFIG_QUERY_VERSION 1
-
-typedef struct __DRI2configQueryExtensionRec __DRI2configQueryExtension;
-struct __DRI2configQueryExtensionRec {
- __DRIextension base;
-
- int (*configQueryb)(__DRIscreen *screen, const char *var, GLboolean *val);
- int (*configQueryi)(__DRIscreen *screen, const char *var, GLint *val);
- int (*configQueryf)(__DRIscreen *screen, const char *var, GLfloat *val);
-};
-#endif
+/*
+ * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2007-2008 Red Hat, Inc.
+ * (C) Copyright IBM Corporation 2004
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file dri_interface.h
+ *
+ * This file contains all the types and functions that define the interface
+ * between a DRI driver and driver loader. Currently, the most common driver
+ * loader is the XFree86 libGL.so. However, other loaders do exist, and in
+ * the future the server-side libglx.a will also be a loader.
+ *
+ * \author Kevin E. Martin <kevin@precisioninsight.com>
+ * \author Ian Romanick <idr@us.ibm.com>
+ * \author Kristian Høgsberg <krh@redhat.com>
+ */
+
+#ifndef DRI_INTERFACE_H
+#define DRI_INTERFACE_H
+
+/* For archs with no drm.h */
+#if defined(__APPLE__) || defined(__CYGWIN__) || defined(__GNU__) || defined(_MSC_VER)
+#ifndef __NOT_HAVE_DRM_H
+#define __NOT_HAVE_DRM_H
+#endif
+#endif
+
+#ifndef __NOT_HAVE_DRM_H
+#include <drm.h>
+#else
+typedef unsigned int drm_context_t;
+typedef unsigned int drm_drawable_t;
+typedef struct drm_clip_rect drm_clip_rect_t;
+#endif
+
+/**
+ * \name DRI interface structures
+ *
+ * The following structures define the interface between the GLX client
+ * side library and the DRI (direct rendering infrastructure).
+ */
+/*@{*/
+typedef struct __DRIdisplayRec __DRIdisplay;
+typedef struct __DRIscreenRec __DRIscreen;
+typedef struct __DRIcontextRec __DRIcontext;
+typedef struct __DRIdrawableRec __DRIdrawable;
+typedef struct __DRIconfigRec __DRIconfig;
+typedef struct __DRIframebufferRec __DRIframebuffer;
+typedef struct __DRIversionRec __DRIversion;
+
+typedef struct __DRIcoreExtensionRec __DRIcoreExtension;
+typedef struct __DRIextensionRec __DRIextension;
+typedef struct __DRIcopySubBufferExtensionRec __DRIcopySubBufferExtension;
+typedef struct __DRIswapControlExtensionRec __DRIswapControlExtension;
+typedef struct __DRIframeTrackingExtensionRec __DRIframeTrackingExtension;
+typedef struct __DRImediaStreamCounterExtensionRec __DRImediaStreamCounterExtension;
+typedef struct __DRItexOffsetExtensionRec __DRItexOffsetExtension;
+typedef struct __DRItexBufferExtensionRec __DRItexBufferExtension;
+typedef struct __DRIlegacyExtensionRec __DRIlegacyExtension;
+typedef struct __DRIswrastExtensionRec __DRIswrastExtension;
+typedef struct __DRIbufferRec __DRIbuffer;
+typedef struct __DRIdri2ExtensionRec __DRIdri2Extension;
+typedef struct __DRIdri2LoaderExtensionRec __DRIdri2LoaderExtension;
+typedef struct __DRI2flushExtensionRec __DRI2flushExtension;
+
+/*@}*/
+
+
+/**
+ * Extension struct. Drivers 'inherit' from this struct by embedding
+ * it as the first element in the extension struct.
+ *
+ * We never break API in for a DRI extension. If we need to change
+ * the way things work in a non-backwards compatible manner, we
+ * introduce a new extension. During a transition period, we can
+ * leave both the old and the new extension in the driver, which
+ * allows us to move to the new interface without having to update the
+ * loader(s) in lock step.
+ *
+ * However, we can add entry points to an extension over time as long
+ * as we don't break the old ones. As we add entry points to an
+ * extension, we increase the version number. The corresponding
+ * #define can be used to guard code that accesses the new entry
+ * points at compile time and the version field in the extension
+ * struct can be used at run-time to determine how to use the
+ * extension.
+ */
+struct __DRIextensionRec {
+ const char *name;
+ int version;
+};
+
+/**
+ * The first set of extension are the screen extensions, returned by
+ * __DRIcore::getExtensions(). This entry point will return a list of
+ * extensions and the loader can use the ones it knows about by
+ * casting them to more specific extensions and advertising any GLX
+ * extensions the DRI extensions enables.
+ */
+
+/**
+ * Used by drivers to indicate support for setting the read drawable.
+ */
+#define __DRI_READ_DRAWABLE "DRI_ReadDrawable"
+#define __DRI_READ_DRAWABLE_VERSION 1
+
+/**
+ * Used by drivers that implement the GLX_MESA_copy_sub_buffer extension.
+ */
+#define __DRI_COPY_SUB_BUFFER "DRI_CopySubBuffer"
+#define __DRI_COPY_SUB_BUFFER_VERSION 1
+struct __DRIcopySubBufferExtensionRec {
+ __DRIextension base;
+ void (*copySubBuffer)(__DRIdrawable *drawable, int x, int y, int w, int h);
+};
+
+/**
+ * Used by drivers that implement the GLX_SGI_swap_control or
+ * GLX_MESA_swap_control extension.
+ */
+#define __DRI_SWAP_CONTROL "DRI_SwapControl"
+#define __DRI_SWAP_CONTROL_VERSION 1
+struct __DRIswapControlExtensionRec {
+ __DRIextension base;
+ void (*setSwapInterval)(__DRIdrawable *drawable, unsigned int inteval);
+ unsigned int (*getSwapInterval)(__DRIdrawable *drawable);
+};
+
+/**
+ * Used by drivers that implement the GLX_MESA_swap_frame_usage extension.
+ */
+#define __DRI_FRAME_TRACKING "DRI_FrameTracking"
+#define __DRI_FRAME_TRACKING_VERSION 1
+struct __DRIframeTrackingExtensionRec {
+ __DRIextension base;
+
+ /**
+ * Enable or disable frame usage tracking.
+ *
+ * \since Internal API version 20030317.
+ */
+ int (*frameTracking)(__DRIdrawable *drawable, GLboolean enable);
+
+ /**
+ * Retrieve frame usage information.
+ *
+ * \since Internal API version 20030317.
+ */
+ int (*queryFrameTracking)(__DRIdrawable *drawable,
+ int64_t * sbc, int64_t * missedFrames,
+ float * lastMissedUsage, float * usage);
+};
+
+
+/**
+ * Used by drivers that implement the GLX_SGI_video_sync extension.
+ */
+#define __DRI_MEDIA_STREAM_COUNTER "DRI_MediaStreamCounter"
+#define __DRI_MEDIA_STREAM_COUNTER_VERSION 1
+struct __DRImediaStreamCounterExtensionRec {
+ __DRIextension base;
+
+ /**
+ * Wait for the MSC to equal target_msc, or, if that has already passed,
+ * the next time (MSC % divisor) is equal to remainder. If divisor is
+ * zero, the function will return as soon as MSC is greater than or equal
+ * to target_msc.
+ */
+ int (*waitForMSC)(__DRIdrawable *drawable,
+ int64_t target_msc, int64_t divisor, int64_t remainder,
+ int64_t * msc, int64_t * sbc);
+
+ /**
+ * Get the number of vertical refreshes since some point in time before
+ * this function was first called (i.e., system start up).
+ */
+ int (*getDrawableMSC)(__DRIscreen *screen, __DRIdrawable *drawable,
+ int64_t *msc);
+};
+
+
+#define __DRI_TEX_OFFSET "DRI_TexOffset"
+#define __DRI_TEX_OFFSET_VERSION 1
+struct __DRItexOffsetExtensionRec {
+ __DRIextension base;
+
+ /**
+ * Method to override base texture image with a driver specific 'offset'.
+ * The depth passed in allows e.g. to ignore the alpha channel of texture
+ * images where the non-alpha components don't occupy a whole texel.
+ *
+ * For GLX_EXT_texture_from_pixmap with AIGLX.
+ */
+ void (*setTexOffset)(__DRIcontext *pDRICtx, GLint texname,
+ unsigned long long offset, GLint depth, GLuint pitch);
+};
+
+
+/* Valid values for format in the setTexBuffer2 function below. These
+ * values match the GLX tokens for compatibility reasons, but we
+ * define them here since the DRI interface can't depend on GLX. */
+#define __DRI_TEXTURE_FORMAT_NONE 0x20D8
+#define __DRI_TEXTURE_FORMAT_RGB 0x20D9
+#define __DRI_TEXTURE_FORMAT_RGBA 0x20DA
+
+#define __DRI_TEX_BUFFER "DRI_TexBuffer"
+#define __DRI_TEX_BUFFER_VERSION 2
+struct __DRItexBufferExtensionRec {
+ __DRIextension base;
+
+ /**
+ * Method to override base texture image with the contents of a
+ * __DRIdrawable.
+ *
+ * For GLX_EXT_texture_from_pixmap with AIGLX. Deprecated in favor of
+ * setTexBuffer2 in version 2 of this interface
+ */
+ void (*setTexBuffer)(__DRIcontext *pDRICtx,
+ GLint target,
+ __DRIdrawable *pDraw);
+
+ /**
+ * Method to override base texture image with the contents of a
+ * __DRIdrawable, including the required texture format attribute.
+ *
+ * For GLX_EXT_texture_from_pixmap with AIGLX.
+ */
+ void (*setTexBuffer2)(__DRIcontext *pDRICtx,
+ GLint target,
+ GLint format,
+ __DRIdrawable *pDraw);
+ /**
+ * Method to release texture buffer in case some special platform
+ * need this.
+ *
+ * For GLX_EXT_texture_from_pixmap with AIGLX.
+ */
+ void (*releaseTexBuffer)(__DRIcontext *pDRICtx,
+ GLint target,
+ __DRIdrawable *pDraw);
+};
+
+/**
+ * Used by drivers that implement DRI2
+ */
+#define __DRI2_FLUSH "DRI2_Flush"
+#define __DRI2_FLUSH_VERSION 3
+struct __DRI2flushExtensionRec {
+ __DRIextension base;
+ void (*flush)(__DRIdrawable *drawable);
+
+ /**
+ * Ask the driver to call getBuffers/getBuffersWithFormat before
+ * it starts rendering again.
+ *
+ * \param drawable the drawable to invalidate
+ *
+ * \since 3
+ */
+ void (*invalidate)(__DRIdrawable *drawable);
+};
+
+
+/**
+ * XML document describing the configuration options supported by the
+ * driver.
+ */
+extern const char __driConfigOptions[];
+
+/*@}*/
+
+/**
+ * The following extensions describe loader features that the DRI
+ * driver can make use of. Some of these are mandatory, such as the
+ * getDrawableInfo extension for DRI and the DRI Loader extensions for
+ * DRI2, while others are optional, and if present allow the driver to
+ * expose certain features. The loader pass in a NULL terminated
+ * array of these extensions to the driver in the createNewScreen
+ * constructor.
+ */
+
+typedef struct __DRIgetDrawableInfoExtensionRec __DRIgetDrawableInfoExtension;
+typedef struct __DRIsystemTimeExtensionRec __DRIsystemTimeExtension;
+typedef struct __DRIdamageExtensionRec __DRIdamageExtension;
+typedef struct __DRIloaderExtensionRec __DRIloaderExtension;
+typedef struct __DRIswrastLoaderExtensionRec __DRIswrastLoaderExtension;
+
+
+/**
+ * Callback to getDrawableInfo protocol
+ */
+#define __DRI_GET_DRAWABLE_INFO "DRI_GetDrawableInfo"
+#define __DRI_GET_DRAWABLE_INFO_VERSION 1
+struct __DRIgetDrawableInfoExtensionRec {
+ __DRIextension base;
+
+ /**
+ * This function is used to get information about the position, size, and
+ * clip rects of a drawable.
+ */
+ GLboolean (* getDrawableInfo) ( __DRIdrawable *drawable,
+ unsigned int * index, unsigned int * stamp,
+ int * x, int * y, int * width, int * height,
+ int * numClipRects, drm_clip_rect_t ** pClipRects,
+ int * backX, int * backY,
+ int * numBackClipRects, drm_clip_rect_t ** pBackClipRects,
+ void *loaderPrivate);
+};
+
+typedef int int32_t;
+
+/**
+ * Callback to get system time for media stream counter extensions.
+ */
+#define __DRI_SYSTEM_TIME "DRI_SystemTime"
+#define __DRI_SYSTEM_TIME_VERSION 1
+struct __DRIsystemTimeExtensionRec {
+ __DRIextension base;
+
+ /**
+ * Get the 64-bit unadjusted system time (UST).
+ */
+ int (*getUST)(int64_t * ust);
+
+ /**
+ * Get the media stream counter (MSC) rate.
+ *
+ * Matching the definition in GLX_OML_sync_control, this function returns
+ * the rate of the "media stream counter". In practical terms, this is
+ * the frame refresh rate of the display.
+ */
+ GLboolean (*getMSCRate)(__DRIdrawable *draw,
+ int32_t * numerator, int32_t * denominator,
+ void *loaderPrivate);
+};
+
+/**
+ * Damage reporting
+ */
+#define __DRI_DAMAGE "DRI_Damage"
+#define __DRI_DAMAGE_VERSION 1
+struct __DRIdamageExtensionRec {
+ __DRIextension base;
+
+ /**
+ * Reports areas of the given drawable which have been modified by the
+ * driver.
+ *
+ * \param drawable which the drawing was done to.
+ * \param rects rectangles affected, with the drawable origin as the
+ * origin.
+ * \param x X offset of the drawable within the screen (used in the
+ * front_buffer case)
+ * \param y Y offset of the drawable within the screen.
+ * \param front_buffer boolean flag for whether the drawing to the
+ * drawable was actually done directly to the front buffer (instead
+ * of backing storage, for example)
+ * \param loaderPrivate the data passed in at createNewDrawable time
+ */
+ void (*reportDamage)(__DRIdrawable *draw,
+ int x, int y,
+ drm_clip_rect_t *rects, int num_rects,
+ GLboolean front_buffer,
+ void *loaderPrivate);
+};
+
+#define __DRI_SWRAST_IMAGE_OP_DRAW 1
+#define __DRI_SWRAST_IMAGE_OP_CLEAR 2
+#define __DRI_SWRAST_IMAGE_OP_SWAP 3
+
+/**
+ * SWRast Loader extension.
+ */
+#define __DRI_SWRAST_LOADER "DRI_SWRastLoader"
+#define __DRI_SWRAST_LOADER_VERSION 1
+struct __DRIswrastLoaderExtensionRec {
+ __DRIextension base;
+
+ /*
+ * Drawable position and size
+ */
+ void (*getDrawableInfo)(__DRIdrawable *drawable,
+ int *x, int *y, int *width, int *height,
+ void *loaderPrivate);
+
+ /**
+ * Put image to drawable
+ */
+ void (*putImage)(__DRIdrawable *drawable, int op,
+ int x, int y, int width, int height,
+ char *data, void *loaderPrivate);
+
+ /**
+ * Get image from readable
+ */
+ void (*getImage)(__DRIdrawable *readable,
+ int x, int y, int width, int height,
+ char *data, void *loaderPrivate);
+};
+
+/**
+ * Invalidate loader extension. The presence of this extension
+ * indicates to the DRI driver that the loader will call invalidate in
+ * the __DRI2_FLUSH extension, whenever the needs to query for new
+ * buffers. This means that the DRI driver can drop the polling in
+ * glViewport().
+ *
+ * The extension doesn't provide any functionality, it's only use to
+ * indicate to the driver that it can use the new semantics. A DRI
+ * driver can use this to switch between the different semantics or
+ * just refuse to initialize if this extension isn't present.
+ */
+#define __DRI_USE_INVALIDATE "DRI_UseInvalidate"
+#define __DRI_USE_INVALIDATE_VERSION 1
+
+typedef struct __DRIuseInvalidateExtensionRec __DRIuseInvalidateExtension;
+struct __DRIuseInvalidateExtensionRec {
+ __DRIextension base;
+};
+
+/**
+ * The remaining extensions describe driver extensions, immediately
+ * available interfaces provided by the driver. To start using the
+ * driver, dlsym() for the __DRI_DRIVER_EXTENSIONS symbol and look for
+ * the extension you need in the array.
+ */
+#define __DRI_DRIVER_EXTENSIONS "__driDriverExtensions"
+
+/**
+ * Tokens for __DRIconfig attribs. A number of attributes defined by
+ * GLX or EGL standards are not in the table, as they must be provided
+ * by the loader. For example, FBConfig ID or visual ID, drawable type.
+ */
+
+#define __DRI_ATTRIB_BUFFER_SIZE 1
+#define __DRI_ATTRIB_LEVEL 2
+#define __DRI_ATTRIB_RED_SIZE 3
+#define __DRI_ATTRIB_GREEN_SIZE 4
+#define __DRI_ATTRIB_BLUE_SIZE 5
+#define __DRI_ATTRIB_LUMINANCE_SIZE 6
+#define __DRI_ATTRIB_ALPHA_SIZE 7
+#define __DRI_ATTRIB_ALPHA_MASK_SIZE 8
+#define __DRI_ATTRIB_DEPTH_SIZE 9
+#define __DRI_ATTRIB_STENCIL_SIZE 10
+#define __DRI_ATTRIB_ACCUM_RED_SIZE 11
+#define __DRI_ATTRIB_ACCUM_GREEN_SIZE 12
+#define __DRI_ATTRIB_ACCUM_BLUE_SIZE 13
+#define __DRI_ATTRIB_ACCUM_ALPHA_SIZE 14
+#define __DRI_ATTRIB_SAMPLE_BUFFERS 15
+#define __DRI_ATTRIB_SAMPLES 16
+#define __DRI_ATTRIB_RENDER_TYPE 17
+#define __DRI_ATTRIB_CONFIG_CAVEAT 18
+#define __DRI_ATTRIB_CONFORMANT 19
+#define __DRI_ATTRIB_DOUBLE_BUFFER 20
+#define __DRI_ATTRIB_STEREO 21
+#define __DRI_ATTRIB_AUX_BUFFERS 22
+#define __DRI_ATTRIB_TRANSPARENT_TYPE 23
+#define __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE 24
+#define __DRI_ATTRIB_TRANSPARENT_RED_VALUE 25
+#define __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE 26
+#define __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE 27
+#define __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE 28
+#define __DRI_ATTRIB_FLOAT_MODE 29
+#define __DRI_ATTRIB_RED_MASK 30
+#define __DRI_ATTRIB_GREEN_MASK 31
+#define __DRI_ATTRIB_BLUE_MASK 32
+#define __DRI_ATTRIB_ALPHA_MASK 33
+#define __DRI_ATTRIB_MAX_PBUFFER_WIDTH 34
+#define __DRI_ATTRIB_MAX_PBUFFER_HEIGHT 35
+#define __DRI_ATTRIB_MAX_PBUFFER_PIXELS 36
+#define __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH 37
+#define __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT 38
+#define __DRI_ATTRIB_VISUAL_SELECT_GROUP 39
+#define __DRI_ATTRIB_SWAP_METHOD 40
+#define __DRI_ATTRIB_MAX_SWAP_INTERVAL 41
+#define __DRI_ATTRIB_MIN_SWAP_INTERVAL 42
+#define __DRI_ATTRIB_BIND_TO_TEXTURE_RGB 43
+#define __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA 44
+#define __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE 45
+#define __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS 46
+#define __DRI_ATTRIB_YINVERTED 47
+#define __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE 48
+
+/* __DRI_ATTRIB_RENDER_TYPE */
+#define __DRI_ATTRIB_RGBA_BIT 0x01
+#define __DRI_ATTRIB_COLOR_INDEX_BIT 0x02
+#define __DRI_ATTRIB_LUMINANCE_BIT 0x04
+
+/* __DRI_ATTRIB_CONFIG_CAVEAT */
+#define __DRI_ATTRIB_SLOW_BIT 0x01
+#define __DRI_ATTRIB_NON_CONFORMANT_CONFIG 0x02
+
+/* __DRI_ATTRIB_TRANSPARENT_TYPE */
+#define __DRI_ATTRIB_TRANSPARENT_RGB 0x00
+#define __DRI_ATTRIB_TRANSPARENT_INDEX 0x01
+
+/* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */
+#define __DRI_ATTRIB_TEXTURE_1D_BIT 0x01
+#define __DRI_ATTRIB_TEXTURE_2D_BIT 0x02
+#define __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT 0x04
+
+/**
+ * This extension defines the core DRI functionality.
+ */
+#define __DRI_CORE "DRI_Core"
+#define __DRI_CORE_VERSION 1
+
+struct __DRIcoreExtensionRec {
+ __DRIextension base;
+
+ __DRIscreen *(*createNewScreen)(int screen, int fd,
+ unsigned int sarea_handle,
+ const __DRIextension **extensions,
+ const __DRIconfig ***driverConfigs,
+ void *loaderPrivate);
+
+ void (*destroyScreen)(__DRIscreen *screen);
+
+ const __DRIextension **(*getExtensions)(__DRIscreen *screen);
+
+ int (*getConfigAttrib)(const __DRIconfig *config,
+ unsigned int attrib,
+ unsigned int *value);
+
+ int (*indexConfigAttrib)(const __DRIconfig *config, int index,
+ unsigned int *attrib, unsigned int *value);
+
+ __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
+ const __DRIconfig *config,
+ unsigned int drawable_id,
+ unsigned int head,
+ void *loaderPrivate);
+
+ void (*destroyDrawable)(__DRIdrawable *drawable);
+
+ void (*swapBuffers)(__DRIdrawable *drawable);
+
+ __DRIcontext *(*createNewContext)(__DRIscreen *screen,
+ const __DRIconfig *config,
+ __DRIcontext *shared,
+ void *loaderPrivate);
+
+ int (*copyContext)(__DRIcontext *dest,
+ __DRIcontext *src,
+ unsigned long mask);
+
+ void (*destroyContext)(__DRIcontext *context);
+
+ int (*bindContext)(__DRIcontext *ctx,
+ __DRIdrawable *pdraw,
+ __DRIdrawable *pread);
+
+ int (*unbindContext)(__DRIcontext *ctx);
+};
+
+/**
+ * Stored version of some component (i.e., server-side DRI module, kernel-side
+ * DRM, etc.).
+ *
+ * \todo
+ * There are several data structures that explicitly store a major version,
+ * minor version, and patch level. These structures should be modified to
+ * have a \c __DRIversionRec instead.
+ */
+struct __DRIversionRec {
+ int major; /**< Major version number. */
+ int minor; /**< Minor version number. */
+ int patch; /**< Patch-level. */
+};
+
+/**
+ * Framebuffer information record. Used by libGL to communicate information
+ * about the framebuffer to the driver's \c __driCreateNewScreen function.
+ *
+ * In XFree86, most of this information is derrived from data returned by
+ * calling \c XF86DRIGetDeviceInfo.
+ *
+ * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
+ * __driUtilCreateNewScreen CallCreateNewScreen
+ *
+ * \bug This structure could be better named.
+ */
+struct __DRIframebufferRec {
+ unsigned char *base; /**< Framebuffer base address in the CPU's
+ * address space. This value is calculated by
+ * calling \c drmMap on the framebuffer handle
+ * returned by \c XF86DRIGetDeviceInfo (or a
+ * similar function).
+ */
+ int size; /**< Framebuffer size, in bytes. */
+ int stride; /**< Number of bytes from one line to the next. */
+ int width; /**< Pixel width of the framebuffer. */
+ int height; /**< Pixel height of the framebuffer. */
+ int dev_priv_size; /**< Size of the driver's dev-priv structure. */
+ void *dev_priv; /**< Pointer to the driver's dev-priv structure. */
+};
+
+
+/**
+ * This extension provides alternative screen, drawable and context
+ * constructors for legacy DRI functionality. This is used in
+ * conjunction with the core extension.
+ */
+#define __DRI_LEGACY "DRI_Legacy"
+#define __DRI_LEGACY_VERSION 1
+
+struct __DRIlegacyExtensionRec {
+ __DRIextension base;
+
+ __DRIscreen *(*createNewScreen)(int screen,
+ const __DRIversion *ddx_version,
+ const __DRIversion *dri_version,
+ const __DRIversion *drm_version,
+ const __DRIframebuffer *frame_buffer,
+ void *pSAREA, int fd,
+ const __DRIextension **extensions,
+ const __DRIconfig ***driver_configs,
+ void *loaderPrivate);
+
+ __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
+ const __DRIconfig *config,
+ drm_drawable_t hwDrawable,
+ int renderType, const int *attrs,
+ void *loaderPrivate);
+
+ __DRIcontext *(*createNewContext)(__DRIscreen *screen,
+ const __DRIconfig *config,
+ int render_type,
+ __DRIcontext *shared,
+ drm_context_t hwContext,
+ void *loaderPrivate);
+};
+
+/**
+ * This extension provides alternative screen, drawable and context
+ * constructors for swrast DRI functionality. This is used in
+ * conjunction with the core extension.
+ */
+#define __DRI_SWRAST "DRI_SWRast"
+#define __DRI_SWRAST_VERSION 2
+
+struct __DRIswrastExtensionRec {
+ __DRIextension base;
+
+ __DRIscreen *(*createNewScreen)(int screen,
+ const __DRIextension **extensions,
+ const __DRIconfig ***driver_configs,
+ void *loaderPrivate);
+
+ __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
+ const __DRIconfig *config,
+ void *loaderPrivate);
+
+ /* Since version 2 */
+ __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen,
+ int api,
+ const __DRIconfig *config,
+ __DRIcontext *shared,
+ void *data);
+};
+
+/**
+ * DRI2 Loader extension.
+ */
+#define __DRI_BUFFER_FRONT_LEFT 0
+#define __DRI_BUFFER_BACK_LEFT 1
+#define __DRI_BUFFER_FRONT_RIGHT 2
+#define __DRI_BUFFER_BACK_RIGHT 3
+#define __DRI_BUFFER_DEPTH 4
+#define __DRI_BUFFER_STENCIL 5
+#define __DRI_BUFFER_ACCUM 6
+#define __DRI_BUFFER_FAKE_FRONT_LEFT 7
+#define __DRI_BUFFER_FAKE_FRONT_RIGHT 8
+#define __DRI_BUFFER_DEPTH_STENCIL 9 /**< Only available with DRI2 1.1 */
+
+struct __DRIbufferRec {
+ unsigned int attachment;
+ unsigned int name;
+ unsigned int pitch;
+ unsigned int cpp;
+ unsigned int flags;
+};
+
+#define __DRI_DRI2_LOADER "DRI_DRI2Loader"
+#define __DRI_DRI2_LOADER_VERSION 3
+struct __DRIdri2LoaderExtensionRec {
+ __DRIextension base;
+
+ __DRIbuffer *(*getBuffers)(__DRIdrawable *driDrawable,
+ int *width, int *height,
+ unsigned int *attachments, int count,
+ int *out_count, void *loaderPrivate);
+
+ /**
+ * Flush pending front-buffer rendering
+ *
+ * Any rendering that has been performed to the
+ * \c __DRI_BUFFER_FAKE_FRONT_LEFT will be flushed to the
+ * \c __DRI_BUFFER_FRONT_LEFT.
+ *
+ * \param driDrawable Drawable whose front-buffer is to be flushed
+ * \param loaderPrivate Loader's private data that was previously passed
+ * into __DRIdri2ExtensionRec::createNewDrawable
+ */
+ void (*flushFrontBuffer)(__DRIdrawable *driDrawable, void *loaderPrivate);
+
+
+ /**
+ * Get list of buffers from the server
+ *
+ * Gets a list of buffer for the specified set of attachments. Unlike
+ * \c ::getBuffers, this function takes a list of attachments paired with
+ * opaque \c unsigned \c int value describing the format of the buffer.
+ * It is the responsibility of the caller to know what the service that
+ * allocates the buffers will expect to receive for the format.
+ *
+ * \param driDrawable Drawable whose buffers are being queried.
+ * \param width Output where the width of the buffers is stored.
+ * \param height Output where the height of the buffers is stored.
+ * \param attachments List of pairs of attachment ID and opaque format
+ * requested for the drawable.
+ * \param count Number of attachment / format pairs stored in
+ * \c attachments.
+ * \param loaderPrivate Loader's private data that was previously passed
+ * into __DRIdri2ExtensionRec::createNewDrawable.
+ */
+ __DRIbuffer *(*getBuffersWithFormat)(__DRIdrawable *driDrawable,
+ int *width, int *height,
+ unsigned int *attachments, int count,
+ int *out_count, void *loaderPrivate);
+};
+
+/**
+ * This extension provides alternative screen, drawable and context
+ * constructors for DRI2.
+ */
+#define __DRI_DRI2 "DRI_DRI2"
+#define __DRI_DRI2_VERSION 2
+
+#define __DRI_API_OPENGL 0
+#define __DRI_API_GLES 1
+#define __DRI_API_GLES2 2
+
+struct __DRIdri2ExtensionRec {
+ __DRIextension base;
+
+ __DRIscreen *(*createNewScreen)(int screen, int fd,
+ const __DRIextension **extensions,
+ const __DRIconfig ***driver_configs,
+ void *loaderPrivate);
+
+ __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
+ const __DRIconfig *config,
+ void *loaderPrivate);
+
+ __DRIcontext *(*createNewContext)(__DRIscreen *screen,
+ const __DRIconfig *config,
+ __DRIcontext *shared,
+ void *loaderPrivate);
+
+ /* Since version 2 */
+ unsigned int (*getAPIMask)(__DRIscreen *screen);
+
+ __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen,
+ int api,
+ const __DRIconfig *config,
+ __DRIcontext *shared,
+ void *data);
+
+ __DRIbuffer *(*allocateBuffer)(__DRIscreen *screen,
+ unsigned int attachment,
+ unsigned int format,
+ int width,
+ int height);
+ void (*releaseBuffer)(__DRIscreen *screen,
+ __DRIbuffer *buffer);
+};
+
+
+/**
+ * This extension provides functionality to enable various EGLImage
+ * extensions.
+ */
+#define __DRI_IMAGE "DRI_IMAGE"
+#define __DRI_IMAGE_VERSION 1
+
+/**
+ * These formats correspond to the similarly named MESA_FORMAT_*
+ * tokens, except in the native endian of the CPU. For example, on
+ * little endian __DRI_IMAGE_FORMAT_XRGB8888 corresponds to
+ * MESA_FORMAT_XRGB8888, but MESA_FORMAT_XRGB8888_REV on big endian.
+ */
+#define __DRI_IMAGE_FORMAT_RGB565 0x1001
+#define __DRI_IMAGE_FORMAT_XRGB8888 0x1002
+#define __DRI_IMAGE_FORMAT_ARGB8888 0x1003
+
+#define __DRI_IMAGE_USE_SHARE 0x0001
+#define __DRI_IMAGE_USE_SCANOUT 0x0002
+
+/**
+ * queryImage attributes
+ */
+
+#define __DRI_IMAGE_ATTRIB_STRIDE 0x2000
+#define __DRI_IMAGE_ATTRIB_HANDLE 0x2001
+#define __DRI_IMAGE_ATTRIB_NAME 0x2002
+
+typedef struct __DRIimageRec __DRIimage;
+typedef struct __DRIimageExtensionRec __DRIimageExtension;
+struct __DRIimageExtensionRec {
+ __DRIextension base;
+
+ __DRIimage *(*createImageFromName)(__DRIscreen *screen,
+ int width, int height, int format,
+ int name, int pitch,
+ void *loaderPrivate);
+
+ __DRIimage *(*createImageFromRenderbuffer)(__DRIcontext *context,
+ int renderbuffer,
+ void *loaderPrivate);
+
+ void (*destroyImage)(__DRIimage *image);
+
+ __DRIimage *(*createImage)(__DRIscreen *screen,
+ int width, int height, int format,
+ unsigned int use,
+ void *loaderPrivate);
+
+ GLboolean (*queryImage)(__DRIimage *image, int attrib, int *value);
+};
+
+
+/**
+ * This extension must be implemented by the loader and passed to the
+ * driver at screen creation time. The EGLImage entry points in the
+ * various client APIs take opaque EGLImage handles and use this
+ * extension to map them to a __DRIimage. At version 1, this
+ * extensions allows mapping EGLImage pointers to __DRIimage pointers,
+ * but future versions could support other EGLImage-like, opaque types
+ * with new lookup functions.
+ */
+#define __DRI_IMAGE_LOOKUP "DRI_IMAGE_LOOKUP"
+#define __DRI_IMAGE_LOOKUP_VERSION 1
+
+typedef struct __DRIimageLookupExtensionRec __DRIimageLookupExtension;
+struct __DRIimageLookupExtensionRec {
+ __DRIextension base;
+
+ __DRIimage *(*lookupEGLImage)(__DRIscreen *screen, void *image,
+ void *loaderPrivate);
+};
+
+/**
+ * This extension allows for common DRI2 options
+ */
+#define __DRI2_CONFIG_QUERY "DRI_CONFIG_QUERY"
+#define __DRI2_CONFIG_QUERY_VERSION 1
+
+typedef struct __DRI2configQueryExtensionRec __DRI2configQueryExtension;
+struct __DRI2configQueryExtensionRec {
+ __DRIextension base;
+
+ int (*configQueryb)(__DRIscreen *screen, const char *var, GLboolean *val);
+ int (*configQueryi)(__DRIscreen *screen, const char *var, GLint *val);
+ int (*configQueryf)(__DRIscreen *screen, const char *var, GLfloat *val);
+};
+#endif
diff --git a/mesalib/include/getopt.h b/mesalib/include/getopt.h
new file mode 100644
index 000000000..695f89061
--- /dev/null
+++ b/mesalib/include/getopt.h
@@ -0,0 +1,128 @@
+/* Declarations for getopt.
+ Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#ifndef _GETOPT_H
+#define _GETOPT_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* For communication from `getopt' to the caller.
+ When `getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when `ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+extern char *optarg;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to `getopt'.
+
+ On entry to `getopt', zero means this is the first call; initialize.
+
+ When `getopt' returns EOF, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, `optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+extern int optind;
+
+/* Callers store zero here to inhibit the error message `getopt' prints
+ for unrecognized options. */
+
+extern int opterr;
+
+ /* Set to an option character which was unrecognized. */
+
+ extern int optopt;
+
+/* Describe the long-named options requested by the application.
+ The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+ of `struct option' terminated by an element containing a name which is
+ zero.
+
+ The field `has_arg' is:
+ no_argument (or 0) if the option does not take an argument,
+ required_argument (or 1) if the option requires an argument,
+ optional_argument (or 2) if the option takes an optional argument.
+
+ If the field `flag' is not NULL, it points to a variable that is set
+ to the value given in the field `val' when the option is found, but
+ left unchanged if the option is not found.
+
+ To have a long-named option do something other than set an `int' to
+ a compiled-in constant, such as set a value from `optarg', set the
+ option's `flag' field to zero and its `val' field to a nonzero
+ value (the equivalent single-letter option character, if there is
+ one). For long options that have a zero `flag' field, `getopt'
+ returns the contents of the `val' field. */
+
+struct option
+{
+#if __STDC__
+ const char *name;
+#else
+ char *name;
+#endif
+ /* has_arg can't be an enum because some compilers complain about
+ type mismatches in all the code that assumes it is an int. */
+ int has_arg;
+ int *flag;
+ int val;
+};
+
+/* Names for the values of the `has_arg' field of `struct option'. */
+
+#define no_argument 0
+#define required_argument 1
+#define optional_argument 2
+
+#if __STDC__
+#if defined(__GNU_LIBRARY__)
+/* Many other libraries have conflicting prototypes for getopt, with
+ differences in the consts, in stdlib.h. To avoid compilation
+ errors, only prototype getopt for the GNU C library. */
+extern int getopt (int argc, char *const *argv, const char *shortopts);
+#else /* not __GNU_LIBRARY__ */
+extern int getopt ();
+#endif /* not __GNU_LIBRARY__ */
+extern int getopt_long (int argc, char *const *argv, const char *shortopts,
+ const struct option *longopts, int *longind);
+extern int getopt_long_only (int argc, char *const *argv,
+ const char *shortopts,
+ const struct option *longopts, int *longind);
+
+/* Internal only. Users should not call this directly. */
+extern int _getopt_internal (int argc, char *const *argv,
+ const char *shortopts,
+ const struct option *longopts, int *longind,
+ int long_only);
+#else /* not __STDC__ */
+extern int getopt ();
+extern int getopt_long ();
+extern int getopt_long_only ();
+
+extern int _getopt_internal ();
+#endif /* not __STDC__ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GETOPT_H */
diff --git a/mesalib/scons/gallium.py b/mesalib/scons/gallium.py
index 112f6c89d..c9c8856b2 100644
--- a/mesalib/scons/gallium.py
+++ b/mesalib/scons/gallium.py
@@ -1,623 +1,623 @@
-"""gallium
-
-Frontend-tool for Gallium3D architecture.
-
-"""
-
-#
-# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-
-
-import distutils.version
-import os
-import os.path
-import re
-import subprocess
-import platform as _platform
-
-import SCons.Action
-import SCons.Builder
-import SCons.Scanner
-
-
-def symlink(target, source, env):
- target = str(target[0])
- source = str(source[0])
- if os.path.islink(target) or os.path.exists(target):
- os.remove(target)
- os.symlink(os.path.basename(source), target)
-
-def install(env, source, subdir):
- target_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build_dir'], subdir)
- return env.Install(target_dir, source)
-
-def install_program(env, source):
- return install(env, source, 'bin')
-
-def install_shared_library(env, sources, version = ()):
- targets = []
- install_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build_dir'])
- version = tuple(map(str, version))
- if env['SHLIBSUFFIX'] == '.dll':
- dlls = env.FindIxes(sources, 'SHLIBPREFIX', 'SHLIBSUFFIX')
- targets += install(env, dlls, 'bin')
- libs = env.FindIxes(sources, 'LIBPREFIX', 'LIBSUFFIX')
- targets += install(env, libs, 'lib')
- else:
- for source in sources:
- target_dir = os.path.join(install_dir, 'lib')
- target_name = '.'.join((str(source),) + version)
- last = env.InstallAs(os.path.join(target_dir, target_name), source)
- targets += last
- while len(version):
- version = version[:-1]
- target_name = '.'.join((str(source),) + version)
- action = SCons.Action.Action(symlink, "$TARGET -> $SOURCE")
- last = env.Command(os.path.join(target_dir, target_name), last, action)
- targets += last
- return targets
-
-
-def createInstallMethods(env):
- env.AddMethod(install_program, 'InstallProgram')
- env.AddMethod(install_shared_library, 'InstallSharedLibrary')
-
-
-def num_jobs():
- try:
- return int(os.environ['NUMBER_OF_PROCESSORS'])
- except (ValueError, KeyError):
- pass
-
- try:
- return os.sysconf('SC_NPROCESSORS_ONLN')
- except (ValueError, OSError, AttributeError):
- pass
-
- try:
- return int(os.popen2("sysctl -n hw.ncpu")[1].read())
- except ValueError:
- pass
-
- return 1
-
-
-def pkg_config_modules(env, name, modules):
- '''Simple wrapper for pkg-config.'''
-
- env[name] = False
-
- if env['platform'] == 'windows':
- return
-
- if not env.Detect('pkg-config'):
- return
-
- if subprocess.call(["pkg-config", "--exists", ' '.join(modules)]) != 0:
- return
-
- # Put -I and -L flags directly into the environment, as these don't affect
- # the compilation of targets that do not use them
- try:
- env.ParseConfig('pkg-config --cflags-only-I --libs-only-L ' + ' '.join(modules))
- except OSError:
- return
-
- # Other flags may affect the compilation of unrelated targets, so store
- # them with a prefix, (e.g., XXX_CFLAGS, XXX_LIBS, etc)
- try:
- flags = env.ParseFlags('!pkg-config --cflags-only-other --libs-only-l --libs-only-other ' + ' '.join(modules))
- except OSError:
- return
- prefix = name.upper() + '_'
- for flag_name, flag_value in flags.iteritems():
- env[prefix + flag_name] = flag_value
-
- env[name] = True
-
-
-
-def generate(env):
- """Common environment generation code"""
-
- # Tell tools which machine to compile for
- env['TARGET_ARCH'] = env['machine']
- env['MSVS_ARCH'] = env['machine']
-
- # Toolchain
- platform = env['platform']
- if env['toolchain'] == 'default':
- if platform == 'winddk':
- env['toolchain'] = 'winddk'
- elif platform == 'wince':
- env['toolchain'] = 'wcesdk'
- env.Tool(env['toolchain'])
-
- # Allow override compiler and specify additional flags from environment
- if os.environ.has_key('CC'):
- env['CC'] = os.environ['CC']
- # Update CCVERSION to match
- pipe = SCons.Action._subproc(env, [env['CC'], '--version'],
- stdin = 'devnull',
- stderr = 'devnull',
- stdout = subprocess.PIPE)
- if pipe.wait() == 0:
- line = pipe.stdout.readline()
- match = re.search(r'[0-9]+(\.[0-9]+)+', line)
- if match:
- env['CCVERSION'] = match.group(0)
- if os.environ.has_key('CFLAGS'):
- env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
- if os.environ.has_key('CXX'):
- env['CXX'] = os.environ['CXX']
- if os.environ.has_key('CXXFLAGS'):
- env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
- if os.environ.has_key('LDFLAGS'):
- env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
-
- env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
- env['msvc'] = env['CC'] == 'cl'
-
- if env['msvc'] and env['toolchain'] == 'default' and env['machine'] == 'x86_64':
- # MSVC x64 support is broken in earlier versions of scons
- env.EnsurePythonVersion(2, 0)
-
- # shortcuts
- machine = env['machine']
- platform = env['platform']
- x86 = env['machine'] == 'x86'
- ppc = env['machine'] == 'ppc'
- gcc = env['gcc']
- msvc = env['msvc']
-
- # Determine whether we are cross compiling; in particular, whether we need
- # to compile code generators with a different compiler as the target code.
- host_platform = _platform.system().lower()
- if host_platform.startswith('cygwin'):
- host_platform = 'cygwin'
- host_machine = os.environ.get('PROCESSOR_ARCHITEW6432', os.environ.get('PROCESSOR_ARCHITECTURE', _platform.machine()))
- host_machine = {
- 'x86': 'x86',
- 'i386': 'x86',
- 'i486': 'x86',
- 'i586': 'x86',
- 'i686': 'x86',
- 'ppc' : 'ppc',
- 'AMD64': 'x86_64',
- 'x86_64': 'x86_64',
- }.get(host_machine, 'generic')
- env['crosscompile'] = platform != host_platform
- if machine == 'x86_64' and host_machine != 'x86_64':
- env['crosscompile'] = True
- env['hostonly'] = False
-
- # Backwards compatability with the debug= profile= options
- if env['build'] == 'debug':
- if not env['debug']:
- print 'scons: warning: debug option is deprecated and will be removed eventually; use instead'
- print
- print ' scons build=release'
- print
- env['build'] = 'release'
- if env['profile']:
- print 'scons: warning: profile option is deprecated and will be removed eventually; use instead'
- print
- print ' scons build=profile'
- print
- env['build'] = 'profile'
- if False:
- # Enforce SConscripts to use the new build variable
- env.popitem('debug')
- env.popitem('profile')
- else:
- # Backwards portability with older sconscripts
- if env['build'] in ('debug', 'checked'):
- env['debug'] = True
- env['profile'] = False
- if env['build'] == 'profile':
- env['debug'] = False
- env['profile'] = True
- if env['build'] == 'release':
- env['debug'] = False
- env['profile'] = False
-
- # Put build output in a separate dir, which depends on the current
- # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
- build_topdir = 'build'
- build_subdir = env['platform']
- if env['machine'] != 'generic':
- build_subdir += '-' + env['machine']
- if env['build'] != 'release':
- build_subdir += '-' + env['build']
- build_dir = os.path.join(build_topdir, build_subdir)
- # Place the .sconsign file in the build dir too, to avoid issues with
- # different scons versions building the same source file
- env['build_dir'] = build_dir
- env.SConsignFile(os.path.join(build_dir, '.sconsign'))
- if 'SCONS_CACHE_DIR' in os.environ:
- print 'scons: Using build cache in %s.' % (os.environ['SCONS_CACHE_DIR'],)
- env.CacheDir(os.environ['SCONS_CACHE_DIR'])
- env['CONFIGUREDIR'] = os.path.join(build_dir, 'conf')
- env['CONFIGURELOG'] = os.path.join(os.path.abspath(build_dir), 'config.log')
-
- # Parallel build
- if env.GetOption('num_jobs') <= 1:
- env.SetOption('num_jobs', num_jobs())
-
- env.Decider('MD5-timestamp')
- env.SetOption('max_drift', 60)
-
- # C preprocessor options
- cppdefines = []
- if env['build'] in ('debug', 'checked'):
- cppdefines += ['DEBUG']
- else:
- cppdefines += ['NDEBUG']
- if env['build'] == 'profile':
- cppdefines += ['PROFILE']
- if platform == 'windows':
- cppdefines += [
- 'WIN32',
- '_WINDOWS',
- #'_UNICODE',
- #'UNICODE',
- # http://msdn.microsoft.com/en-us/library/aa383745.aspx
- ('_WIN32_WINNT', '0x0601'),
- ('WINVER', '0x0601'),
- ]
- if msvc and env['toolchain'] != 'winddk':
- cppdefines += [
- 'VC_EXTRALEAN',
- '_USE_MATH_DEFINES',
- '_CRT_SECURE_NO_WARNINGS',
- '_CRT_SECURE_NO_DEPRECATE',
- '_SCL_SECURE_NO_WARNINGS',
- '_SCL_SECURE_NO_DEPRECATE',
- ]
- if env['build'] in ('debug', 'checked'):
- cppdefines += ['_DEBUG']
- if env['toolchain'] == 'winddk':
- # Mimic WINDDK's builtin flags. See also:
- # - WINDDK's bin/makefile.new i386mk.inc for more info.
- # - buildchk_wxp_x86.log files, generated by the WINDDK's build
- # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
- if machine == 'x86':
- cppdefines += ['_X86_', 'i386']
- if machine == 'x86_64':
- cppdefines += ['_AMD64_', 'AMD64']
- if platform == 'winddk':
- cppdefines += [
- 'STD_CALL',
- ('CONDITION_HANDLING', '1'),
- ('NT_INST', '0'),
- ('WIN32', '100'),
- ('_NT1X_', '100'),
- ('WINNT', '1'),
- ('_WIN32_WINNT', '0x0501'), # minimum required OS version
- ('WINVER', '0x0501'),
- ('_WIN32_IE', '0x0603'),
- ('WIN32_LEAN_AND_MEAN', '1'),
- ('DEVL', '1'),
- ('__BUILDMACHINE__', 'WinDDK'),
- ('FPO', '0'),
- ]
- if env['build'] in ('debug', 'checked'):
- cppdefines += [('DBG', 1)]
- if platform == 'wince':
- cppdefines += [
- '_CRT_SECURE_NO_DEPRECATE',
- '_USE_32BIT_TIME_T',
- 'UNICODE',
- '_UNICODE',
- ('UNDER_CE', '600'),
- ('_WIN32_WCE', '0x600'),
- 'WINCEOEM',
- 'WINCEINTERNAL',
- 'WIN32',
- 'STRICT',
- 'x86',
- '_X86_',
- 'INTERNATIONAL',
- ('INTLMSG_CODEPAGE', '1252'),
- ]
- if platform == 'windows':
- cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
- if platform == 'winddk':
- cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
- if platform == 'wince':
- cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
- cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
- if platform == 'embedded':
- cppdefines += ['PIPE_OS_EMBEDDED']
- env.Append(CPPDEFINES = cppdefines)
-
- # C compiler options
- cflags = [] # C
- cxxflags = [] # C++
- ccflags = [] # C & C++
- if gcc:
- ccversion = env['CCVERSION']
- if env['build'] == 'debug':
- ccflags += ['-O0']
- elif ccversion.startswith('4.2.'):
- # gcc 4.2.x optimizer is broken
- print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
- ccflags += ['-O0']
- else:
- ccflags += ['-O3']
- ccflags += ['-g3']
- if env['build'] in ('checked', 'profile'):
- # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
- ccflags += [
- '-fno-omit-frame-pointer',
- '-fno-optimize-sibling-calls',
- ]
- if env['machine'] == 'x86':
- ccflags += [
- '-m32',
- #'-march=pentium4',
- ]
- if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.2') \
- and (platform != 'windows' or env['build'] == 'debug' or True):
- # NOTE: We need to ensure stack is realigned given that we
- # produce shared objects, and have no control over the stack
- # alignment policy of the application. Therefore we need
- # -mstackrealign ore -mincoming-stack-boundary=2.
- #
- # XXX: -O and -mstackrealign causes stack corruption on MinGW
- #
- # XXX: We could have SSE without -mstackrealign if we always used
- # __attribute__((force_align_arg_pointer)), but that's not
- # always the case.
- ccflags += [
- '-mstackrealign', # ensure stack is aligned
- '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
- #'-mfpmath=sse',
- ]
- if platform in ['windows', 'darwin']:
- # Workaround http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37216
- ccflags += ['-fno-common']
- if env['machine'] == 'x86_64':
- ccflags += ['-m64']
- if platform == 'darwin':
- ccflags += ['-fno-common']
- # See also:
- # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
- ccflags += [
- '-Wall',
- '-Wno-long-long',
- '-ffast-math',
- '-fmessage-length=0', # be nice to Eclipse
- ]
- cflags += [
- '-Wmissing-prototypes',
- '-std=gnu99',
- ]
- if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.0'):
- ccflags += [
- '-Wmissing-field-initializers',
- ]
- if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.2'):
- ccflags += [
- '-Werror=pointer-arith',
- ]
- cflags += [
- '-Werror=declaration-after-statement',
- ]
- if msvc:
- # See also:
- # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
- # - cl /?
- if env['build'] == 'debug':
- ccflags += [
- '/Od', # disable optimizations
- '/Oi', # enable intrinsic functions
- '/Oy-', # disable frame pointer omission
- ]
- else:
- ccflags += [
- '/O2', # optimize for speed
- ]
- if env['build'] == 'release':
- ccflags += [
- '/GL', # enable whole program optimization
- ]
- else:
- ccflags += [
- '/GL-', # disable whole program optimization
- ]
- ccflags += [
- '/fp:fast', # fast floating point
- '/W3', # warning level
- #'/Wp64', # enable 64 bit porting warnings
- ]
- if env['machine'] == 'x86':
- ccflags += [
- #'/arch:SSE2', # use the SSE2 instructions
- ]
- if platform == 'windows':
- ccflags += [
- # TODO
- ]
- if platform == 'winddk':
- ccflags += [
- '/Zl', # omit default library name in .OBJ
- '/Zp8', # 8bytes struct member alignment
- '/Gy', # separate functions for linker
- '/Gm-', # disable minimal rebuild
- '/WX', # treat warnings as errors
- '/Gz', # __stdcall Calling convention
- '/GX-', # disable C++ EH
- '/GR-', # disable C++ RTTI
- '/GF', # enable read-only string pooling
- '/G6', # optimize for PPro, P-II, P-III
- '/Ze', # enable extensions
- '/Gi-', # disable incremental compilation
- '/QIfdiv-', # disable Pentium FDIV fix
- '/hotpatch', # prepares an image for hotpatching.
- #'/Z7', #enable old-style debug info
- ]
- if platform == 'wince':
- # See also C:\WINCE600\public\common\oak\misc\makefile.def
- ccflags += [
- '/Zl', # omit default library name in .OBJ
- '/GF', # enable read-only string pooling
- '/GR-', # disable C++ RTTI
- '/GS', # enable security checks
- # Allow disabling language conformance to maintain backward compat
- #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
- #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
- #'/wd4867',
- #'/wd4430',
- #'/MT',
- #'/U_MT',
- ]
- # Automatic pdb generation
- # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
- env.EnsureSConsVersion(0, 98, 0)
- env['PDB'] = '${TARGET.base}.pdb'
- env.Append(CCFLAGS = ccflags)
- env.Append(CFLAGS = cflags)
- env.Append(CXXFLAGS = cxxflags)
-
- if env['platform'] == 'windows' and msvc:
- # Choose the appropriate MSVC CRT
- # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
- if env['build'] in ('debug', 'checked'):
- env.Append(CCFLAGS = ['/MTd'])
- env.Append(SHCCFLAGS = ['/LDd'])
- else:
- env.Append(CCFLAGS = ['/MT'])
- env.Append(SHCCFLAGS = ['/LD'])
-
- # Assembler options
- if gcc:
- if env['machine'] == 'x86':
- env.Append(ASFLAGS = ['-m32'])
- if env['machine'] == 'x86_64':
- env.Append(ASFLAGS = ['-m64'])
-
- # Linker options
- linkflags = []
- shlinkflags = []
- if gcc:
- if env['machine'] == 'x86':
- linkflags += ['-m32']
- if env['machine'] == 'x86_64':
- linkflags += ['-m64']
- if env['platform'] not in ('darwin'):
- shlinkflags += [
- '-Wl,-Bsymbolic',
- ]
- # Handle circular dependencies in the libraries
- if env['platform'] in ('darwin'):
- pass
- else:
- env['_LIBFLAGS'] = '-Wl,--start-group ' + env['_LIBFLAGS'] + ' -Wl,--end-group'
- if msvc:
- if env['build'] == 'release':
- # enable Link-time Code Generation
- linkflags += ['/LTCG']
- env.Append(ARFLAGS = ['/LTCG'])
- if platform == 'windows' and msvc:
- # See also:
- # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
- linkflags += [
- '/fixed:no',
- '/incremental:no',
- ]
- if platform == 'winddk':
- linkflags += [
- '/merge:_PAGE=PAGE',
- '/merge:_TEXT=.text',
- '/section:INIT,d',
- '/opt:ref',
- '/opt:icf',
- '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
- '/incremental:no',
- '/fullbuild',
- '/release',
- '/nodefaultlib',
- '/wx',
- '/debug',
- '/debugtype:cv',
- '/version:5.1',
- '/osversion:5.1',
- '/functionpadmin:5',
- '/safeseh',
- '/pdbcompress',
- '/stack:0x40000,0x1000',
- '/driver',
- '/align:0x80',
- '/subsystem:native,5.01',
- '/base:0x10000',
-
- '/entry:DrvEnableDriver',
- ]
- if env['build'] != 'release':
- linkflags += [
- '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
- ]
- if platform == 'wince':
- linkflags += [
- '/nodefaultlib',
- #'/incremental:no',
- #'/fullbuild',
- '/entry:_DllMainCRTStartup',
- ]
- env.Append(LINKFLAGS = linkflags)
- env.Append(SHLINKFLAGS = shlinkflags)
-
- # We have C++ in several libraries, so always link with the C++ compiler
- if env['gcc']:
- env['LINK'] = env['CXX']
-
- # Default libs
- env.Append(LIBS = [])
-
- # Load tools
- if env['llvm']:
- env.Tool('llvm')
- env.Tool('udis86')
-
- pkg_config_modules(env, 'x11', ['x11', 'xext'])
- pkg_config_modules(env, 'drm', ['libdrm'])
- pkg_config_modules(env, 'drm_intel', ['libdrm_intel'])
- pkg_config_modules(env, 'drm_radeon', ['libdrm_radeon'])
- pkg_config_modules(env, 'xorg', ['xorg-server'])
- pkg_config_modules(env, 'kms', ['libkms'])
-
- env['dri'] = env['x11'] and env['drm']
-
- # Custom builders and methods
- env.Tool('custom')
- createInstallMethods(env)
-
- # for debugging
- #print env.Dump()
-
-
-def exists(env):
- return 1
+"""gallium
+
+Frontend-tool for Gallium3D architecture.
+
+"""
+
+#
+# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+# All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sub license, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice (including the
+# next paragraph) shall be included in all copies or substantial portions
+# of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+
+import distutils.version
+import os
+import os.path
+import re
+import subprocess
+import platform as _platform
+
+import SCons.Action
+import SCons.Builder
+import SCons.Scanner
+
+
+def symlink(target, source, env):
+ target = str(target[0])
+ source = str(source[0])
+ if os.path.islink(target) or os.path.exists(target):
+ os.remove(target)
+ os.symlink(os.path.basename(source), target)
+
+def install(env, source, subdir):
+ target_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build_dir'], subdir)
+ return env.Install(target_dir, source)
+
+def install_program(env, source):
+ return install(env, source, 'bin')
+
+def install_shared_library(env, sources, version = ()):
+ targets = []
+ install_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build_dir'])
+ version = tuple(map(str, version))
+ if env['SHLIBSUFFIX'] == '.dll':
+ dlls = env.FindIxes(sources, 'SHLIBPREFIX', 'SHLIBSUFFIX')
+ targets += install(env, dlls, 'bin')
+ libs = env.FindIxes(sources, 'LIBPREFIX', 'LIBSUFFIX')
+ targets += install(env, libs, 'lib')
+ else:
+ for source in sources:
+ target_dir = os.path.join(install_dir, 'lib')
+ target_name = '.'.join((str(source),) + version)
+ last = env.InstallAs(os.path.join(target_dir, target_name), source)
+ targets += last
+ while len(version):
+ version = version[:-1]
+ target_name = '.'.join((str(source),) + version)
+ action = SCons.Action.Action(symlink, "$TARGET -> $SOURCE")
+ last = env.Command(os.path.join(target_dir, target_name), last, action)
+ targets += last
+ return targets
+
+
+def createInstallMethods(env):
+ env.AddMethod(install_program, 'InstallProgram')
+ env.AddMethod(install_shared_library, 'InstallSharedLibrary')
+
+
+def num_jobs():
+ try:
+ return int(os.environ['NUMBER_OF_PROCESSORS'])
+ except (ValueError, KeyError):
+ pass
+
+ try:
+ return os.sysconf('SC_NPROCESSORS_ONLN')
+ except (ValueError, OSError, AttributeError):
+ pass
+
+ try:
+ return int(os.popen2("sysctl -n hw.ncpu")[1].read())
+ except ValueError:
+ pass
+
+ return 1
+
+
+def pkg_config_modules(env, name, modules):
+ '''Simple wrapper for pkg-config.'''
+
+ env[name] = False
+
+ if env['platform'] == 'windows':
+ return
+
+ if not env.Detect('pkg-config'):
+ return
+
+ if subprocess.call(["pkg-config", "--exists", ' '.join(modules)]) != 0:
+ return
+
+ # Put -I and -L flags directly into the environment, as these don't affect
+ # the compilation of targets that do not use them
+ try:
+ env.ParseConfig('pkg-config --cflags-only-I --libs-only-L ' + ' '.join(modules))
+ except OSError:
+ return
+
+ # Other flags may affect the compilation of unrelated targets, so store
+ # them with a prefix, (e.g., XXX_CFLAGS, XXX_LIBS, etc)
+ try:
+ flags = env.ParseFlags('!pkg-config --cflags-only-other --libs-only-l --libs-only-other ' + ' '.join(modules))
+ except OSError:
+ return
+ prefix = name.upper() + '_'
+ for flag_name, flag_value in flags.iteritems():
+ env[prefix + flag_name] = flag_value
+
+ env[name] = True
+
+
+
+def generate(env):
+ """Common environment generation code"""
+
+ # Tell tools which machine to compile for
+ env['TARGET_ARCH'] = env['machine']
+ env['MSVS_ARCH'] = env['machine']
+
+ # Toolchain
+ platform = env['platform']
+ if env['toolchain'] == 'default':
+ if platform == 'winddk':
+ env['toolchain'] = 'winddk'
+ elif platform == 'wince':
+ env['toolchain'] = 'wcesdk'
+ env.Tool(env['toolchain'])
+
+ # Allow override compiler and specify additional flags from environment
+ if os.environ.has_key('CC'):
+ env['CC'] = os.environ['CC']
+ # Update CCVERSION to match
+ pipe = SCons.Action._subproc(env, [env['CC'], '--version'],
+ stdin = 'devnull',
+ stderr = 'devnull',
+ stdout = subprocess.PIPE)
+ if pipe.wait() == 0:
+ line = pipe.stdout.readline()
+ match = re.search(r'[0-9]+(\.[0-9]+)+', line)
+ if match:
+ env['CCVERSION'] = match.group(0)
+ if os.environ.has_key('CFLAGS'):
+ env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
+ if os.environ.has_key('CXX'):
+ env['CXX'] = os.environ['CXX']
+ if os.environ.has_key('CXXFLAGS'):
+ env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
+ if os.environ.has_key('LDFLAGS'):
+ env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
+
+ env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
+ env['msvc'] = env['CC'] == 'cl'
+
+ if env['msvc'] and env['toolchain'] == 'default' and env['machine'] == 'x86_64':
+ # MSVC x64 support is broken in earlier versions of scons
+ env.EnsurePythonVersion(2, 0)
+
+ # shortcuts
+ machine = env['machine']
+ platform = env['platform']
+ x86 = env['machine'] == 'x86'
+ ppc = env['machine'] == 'ppc'
+ gcc = env['gcc']
+ msvc = env['msvc']
+
+ # Determine whether we are cross compiling; in particular, whether we need
+ # to compile code generators with a different compiler as the target code.
+ host_platform = _platform.system().lower()
+ if host_platform.startswith('cygwin'):
+ host_platform = 'cygwin'
+ host_machine = os.environ.get('PROCESSOR_ARCHITEW6432', os.environ.get('PROCESSOR_ARCHITECTURE', _platform.machine()))
+ host_machine = {
+ 'x86': 'x86',
+ 'i386': 'x86',
+ 'i486': 'x86',
+ 'i586': 'x86',
+ 'i686': 'x86',
+ 'ppc' : 'ppc',
+ 'AMD64': 'x86_64',
+ 'x86_64': 'x86_64',
+ }.get(host_machine, 'generic')
+ env['crosscompile'] = platform != host_platform
+ if machine == 'x86_64' and host_machine != 'x86_64':
+ env['crosscompile'] = True
+ env['hostonly'] = False
+
+ # Backwards compatability with the debug= profile= options
+ if env['build'] == 'debug':
+ if not env['debug']:
+ print 'scons: warning: debug option is deprecated and will be removed eventually; use instead'
+ print
+ print ' scons build=release'
+ print
+ env['build'] = 'release'
+ if env['profile']:
+ print 'scons: warning: profile option is deprecated and will be removed eventually; use instead'
+ print
+ print ' scons build=profile'
+ print
+ env['build'] = 'profile'
+ if False:
+ # Enforce SConscripts to use the new build variable
+ env.popitem('debug')
+ env.popitem('profile')
+ else:
+ # Backwards portability with older sconscripts
+ if env['build'] in ('debug', 'checked'):
+ env['debug'] = True
+ env['profile'] = False
+ if env['build'] == 'profile':
+ env['debug'] = False
+ env['profile'] = True
+ if env['build'] == 'release':
+ env['debug'] = False
+ env['profile'] = False
+
+ # Put build output in a separate dir, which depends on the current
+ # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
+ build_topdir = 'build'
+ build_subdir = env['platform']
+ if env['machine'] != 'generic':
+ build_subdir += '-' + env['machine']
+ if env['build'] != 'release':
+ build_subdir += '-' + env['build']
+ build_dir = os.path.join(build_topdir, build_subdir)
+ # Place the .sconsign file in the build dir too, to avoid issues with
+ # different scons versions building the same source file
+ env['build_dir'] = build_dir
+ env.SConsignFile(os.path.join(build_dir, '.sconsign'))
+ if 'SCONS_CACHE_DIR' in os.environ:
+ print 'scons: Using build cache in %s.' % (os.environ['SCONS_CACHE_DIR'],)
+ env.CacheDir(os.environ['SCONS_CACHE_DIR'])
+ env['CONFIGUREDIR'] = os.path.join(build_dir, 'conf')
+ env['CONFIGURELOG'] = os.path.join(os.path.abspath(build_dir), 'config.log')
+
+ # Parallel build
+ if env.GetOption('num_jobs') <= 1:
+ env.SetOption('num_jobs', num_jobs())
+
+ env.Decider('MD5-timestamp')
+ env.SetOption('max_drift', 60)
+
+ # C preprocessor options
+ cppdefines = []
+ if env['build'] in ('debug', 'checked'):
+ cppdefines += ['DEBUG']
+ else:
+ cppdefines += ['NDEBUG']
+ if env['build'] == 'profile':
+ cppdefines += ['PROFILE']
+ if platform == 'windows':
+ cppdefines += [
+ 'WIN32',
+ '_WINDOWS',
+ #'_UNICODE',
+ #'UNICODE',
+ # http://msdn.microsoft.com/en-us/library/aa383745.aspx
+ ('_WIN32_WINNT', '0x0601'),
+ ('WINVER', '0x0601'),
+ ]
+ if msvc and env['toolchain'] != 'winddk':
+ cppdefines += [
+ 'VC_EXTRALEAN',
+ '_USE_MATH_DEFINES',
+ '_CRT_SECURE_NO_WARNINGS',
+ '_CRT_SECURE_NO_DEPRECATE',
+ '_SCL_SECURE_NO_WARNINGS',
+ '_SCL_SECURE_NO_DEPRECATE',
+ ]
+ if env['build'] in ('debug', 'checked'):
+ cppdefines += ['_DEBUG']
+ if env['toolchain'] == 'winddk':
+ # Mimic WINDDK's builtin flags. See also:
+ # - WINDDK's bin/makefile.new i386mk.inc for more info.
+ # - buildchk_wxp_x86.log files, generated by the WINDDK's build
+ # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
+ if machine == 'x86':
+ cppdefines += ['_X86_', 'i386']
+ if machine == 'x86_64':
+ cppdefines += ['_AMD64_', 'AMD64']
+ if platform == 'winddk':
+ cppdefines += [
+ 'STD_CALL',
+ ('CONDITION_HANDLING', '1'),
+ ('NT_INST', '0'),
+ ('WIN32', '100'),
+ ('_NT1X_', '100'),
+ ('WINNT', '1'),
+ ('_WIN32_WINNT', '0x0501'), # minimum required OS version
+ ('WINVER', '0x0501'),
+ ('_WIN32_IE', '0x0603'),
+ ('WIN32_LEAN_AND_MEAN', '1'),
+ ('DEVL', '1'),
+ ('__BUILDMACHINE__', 'WinDDK'),
+ ('FPO', '0'),
+ ]
+ if env['build'] in ('debug', 'checked'):
+ cppdefines += [('DBG', 1)]
+ if platform == 'wince':
+ cppdefines += [
+ '_CRT_SECURE_NO_DEPRECATE',
+ '_USE_32BIT_TIME_T',
+ 'UNICODE',
+ '_UNICODE',
+ ('UNDER_CE', '600'),
+ ('_WIN32_WCE', '0x600'),
+ 'WINCEOEM',
+ 'WINCEINTERNAL',
+ 'WIN32',
+ 'STRICT',
+ 'x86',
+ '_X86_',
+ 'INTERNATIONAL',
+ ('INTLMSG_CODEPAGE', '1252'),
+ ]
+ if platform == 'windows':
+ cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
+ if platform == 'winddk':
+ cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
+ if platform == 'wince':
+ cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
+ cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
+ if platform == 'embedded':
+ cppdefines += ['PIPE_OS_EMBEDDED']
+ env.Append(CPPDEFINES = cppdefines)
+
+ # C compiler options
+ cflags = [] # C
+ cxxflags = [] # C++
+ ccflags = [] # C & C++
+ if gcc:
+ ccversion = env['CCVERSION']
+ if env['build'] == 'debug':
+ ccflags += ['-O0']
+ elif ccversion.startswith('4.2.'):
+ # gcc 4.2.x optimizer is broken
+ print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
+ ccflags += ['-O0']
+ else:
+ ccflags += ['-O3']
+ ccflags += ['-g3']
+ if env['build'] in ('checked', 'profile'):
+ # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
+ ccflags += [
+ '-fno-omit-frame-pointer',
+ '-fno-optimize-sibling-calls',
+ ]
+ if env['machine'] == 'x86':
+ ccflags += [
+ '-m32',
+ #'-march=pentium4',
+ ]
+ if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.2') \
+ and (platform != 'windows' or env['build'] == 'debug' or True):
+ # NOTE: We need to ensure stack is realigned given that we
+ # produce shared objects, and have no control over the stack
+ # alignment policy of the application. Therefore we need
+ # -mstackrealign ore -mincoming-stack-boundary=2.
+ #
+ # XXX: -O and -mstackrealign causes stack corruption on MinGW
+ #
+ # XXX: We could have SSE without -mstackrealign if we always used
+ # __attribute__((force_align_arg_pointer)), but that's not
+ # always the case.
+ ccflags += [
+ '-mstackrealign', # ensure stack is aligned
+ '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
+ #'-mfpmath=sse',
+ ]
+ if platform in ['windows', 'darwin']:
+ # Workaround http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37216
+ ccflags += ['-fno-common']
+ if env['machine'] == 'x86_64':
+ ccflags += ['-m64']
+ if platform == 'darwin':
+ ccflags += ['-fno-common']
+ # See also:
+ # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
+ ccflags += [
+ '-Wall',
+ '-Wno-long-long',
+ '-ffast-math',
+ '-fmessage-length=0', # be nice to Eclipse
+ ]
+ cflags += [
+ '-Wmissing-prototypes',
+ '-std=gnu99',
+ ]
+ if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.0'):
+ ccflags += [
+ '-Wmissing-field-initializers',
+ ]
+ if distutils.version.LooseVersion(ccversion) >= distutils.version.LooseVersion('4.2'):
+ ccflags += [
+ '-Werror=pointer-arith',
+ ]
+ cflags += [
+ '-Werror=declaration-after-statement',
+ ]
+ if msvc:
+ # See also:
+ # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
+ # - cl /?
+ if env['build'] == 'debug':
+ ccflags += [
+ '/Od', # disable optimizations
+ '/Oi', # enable intrinsic functions
+ '/Oy-', # disable frame pointer omission
+ ]
+ else:
+ ccflags += [
+ '/O2', # optimize for speed
+ ]
+ if env['build'] == 'release':
+ ccflags += [
+ '/GL', # enable whole program optimization
+ ]
+ else:
+ ccflags += [
+ '/GL-', # disable whole program optimization
+ ]
+ ccflags += [
+ '/fp:fast', # fast floating point
+ '/W3', # warning level
+ #'/Wp64', # enable 64 bit porting warnings
+ ]
+ if env['machine'] == 'x86':
+ ccflags += [
+ #'/arch:SSE2', # use the SSE2 instructions
+ ]
+ if platform == 'windows':
+ ccflags += [
+ # TODO
+ ]
+ if platform == 'winddk':
+ ccflags += [
+ '/Zl', # omit default library name in .OBJ
+ '/Zp8', # 8bytes struct member alignment
+ '/Gy', # separate functions for linker
+ '/Gm-', # disable minimal rebuild
+ '/WX', # treat warnings as errors
+ '/Gz', # __stdcall Calling convention
+ '/GX-', # disable C++ EH
+ '/GR-', # disable C++ RTTI
+ '/GF', # enable read-only string pooling
+ '/G6', # optimize for PPro, P-II, P-III
+ '/Ze', # enable extensions
+ '/Gi-', # disable incremental compilation
+ '/QIfdiv-', # disable Pentium FDIV fix
+ '/hotpatch', # prepares an image for hotpatching.
+ #'/Z7', #enable old-style debug info
+ ]
+ if platform == 'wince':
+ # See also C:\WINCE600\public\common\oak\misc\makefile.def
+ ccflags += [
+ '/Zl', # omit default library name in .OBJ
+ '/GF', # enable read-only string pooling
+ '/GR-', # disable C++ RTTI
+ '/GS', # enable security checks
+ # Allow disabling language conformance to maintain backward compat
+ #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
+ #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
+ #'/wd4867',
+ #'/wd4430',
+ #'/MT',
+ #'/U_MT',
+ ]
+ # Automatic pdb generation
+ # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
+ env.EnsureSConsVersion(0, 98, 0)
+ env['PDB'] = '${TARGET.base}.pdb'
+ env.Append(CCFLAGS = ccflags)
+ env.Append(CFLAGS = cflags)
+ env.Append(CXXFLAGS = cxxflags)
+
+ if env['platform'] == 'windows' and msvc:
+ # Choose the appropriate MSVC CRT
+ # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
+ if env['build'] in ('debug', 'checked'):
+ env.Append(CCFLAGS = ['/MTd'])
+ env.Append(SHCCFLAGS = ['/LDd'])
+ else:
+ env.Append(CCFLAGS = ['/MT'])
+ env.Append(SHCCFLAGS = ['/LD'])
+
+ # Assembler options
+ if gcc:
+ if env['machine'] == 'x86':
+ env.Append(ASFLAGS = ['-m32'])
+ if env['machine'] == 'x86_64':
+ env.Append(ASFLAGS = ['-m64'])
+
+ # Linker options
+ linkflags = []
+ shlinkflags = []
+ if gcc:
+ if env['machine'] == 'x86':
+ linkflags += ['-m32']
+ if env['machine'] == 'x86_64':
+ linkflags += ['-m64']
+ if env['platform'] not in ('darwin'):
+ shlinkflags += [
+ '-Wl,-Bsymbolic',
+ ]
+ # Handle circular dependencies in the libraries
+ if env['platform'] in ('darwin'):
+ pass
+ else:
+ env['_LIBFLAGS'] = '-Wl,--start-group ' + env['_LIBFLAGS'] + ' -Wl,--end-group'
+ if msvc:
+ if env['build'] == 'release':
+ # enable Link-time Code Generation
+ linkflags += ['/LTCG']
+ env.Append(ARFLAGS = ['/LTCG'])
+ if platform == 'windows' and msvc:
+ # See also:
+ # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
+ linkflags += [
+ '/fixed:no',
+ '/incremental:no',
+ ]
+ if platform == 'winddk':
+ linkflags += [
+ '/merge:_PAGE=PAGE',
+ '/merge:_TEXT=.text',
+ '/section:INIT,d',
+ '/opt:ref',
+ '/opt:icf',
+ '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
+ '/incremental:no',
+ '/fullbuild',
+ '/release',
+ '/nodefaultlib',
+ '/wx',
+ '/debug',
+ '/debugtype:cv',
+ '/version:5.1',
+ '/osversion:5.1',
+ '/functionpadmin:5',
+ '/safeseh',
+ '/pdbcompress',
+ '/stack:0x40000,0x1000',
+ '/driver',
+ '/align:0x80',
+ '/subsystem:native,5.01',
+ '/base:0x10000',
+
+ '/entry:DrvEnableDriver',
+ ]
+ if env['build'] != 'release':
+ linkflags += [
+ '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
+ ]
+ if platform == 'wince':
+ linkflags += [
+ '/nodefaultlib',
+ #'/incremental:no',
+ #'/fullbuild',
+ '/entry:_DllMainCRTStartup',
+ ]
+ env.Append(LINKFLAGS = linkflags)
+ env.Append(SHLINKFLAGS = shlinkflags)
+
+ # We have C++ in several libraries, so always link with the C++ compiler
+ if env['gcc']:
+ env['LINK'] = env['CXX']
+
+ # Default libs
+ env.Append(LIBS = [])
+
+ # Load tools
+ if env['llvm']:
+ env.Tool('llvm')
+ env.Tool('udis86')
+
+ pkg_config_modules(env, 'x11', ['x11', 'xext'])
+ pkg_config_modules(env, 'drm', ['libdrm'])
+ pkg_config_modules(env, 'drm_intel', ['libdrm_intel'])
+ pkg_config_modules(env, 'drm_radeon', ['libdrm_radeon'])
+ pkg_config_modules(env, 'xorg', ['xorg-server'])
+ pkg_config_modules(env, 'kms', ['libkms'])
+
+ env['dri'] = env['x11'] and env['drm']
+
+ # Custom builders and methods
+ env.Tool('custom')
+ createInstallMethods(env)
+
+ # for debugging
+ #print env.Dump()
+
+
+def exists(env):
+ return 1
diff --git a/mesalib/src/glsl/Makefile b/mesalib/src/glsl/Makefile
index cd7c41a2a..8059bb472 100644
--- a/mesalib/src/glsl/Makefile
+++ b/mesalib/src/glsl/Makefile
@@ -1,213 +1,213 @@
-
-#src/glsl/pp/Makefile
-
-TOP = ../..
-
-include $(TOP)/configs/current
-
-LIBNAME = glsl
-
-LIBGLCPP_SOURCES = \
- glcpp/glcpp-lex.c \
- glcpp/glcpp-parse.c \
- glcpp/pp.c
-
-GLCPP_SOURCES = \
- $(LIBGLCPP_SOURCES) \
- ralloc.c \
- glcpp/glcpp.c
-
-C_SOURCES = \
- strtod.c \
- ralloc.c \
- $(LIBGLCPP_SOURCES)
-
-CXX_SOURCES = \
- ast_expr.cpp \
- ast_function.cpp \
- ast_to_hir.cpp \
- ast_type.cpp \
- glsl_lexer.cpp \
- glsl_parser.cpp \
- glsl_parser_extras.cpp \
- glsl_types.cpp \
- glsl_symbol_table.cpp \
- hir_field_selection.cpp \
- ir_basic_block.cpp \
- ir_clone.cpp \
- ir_constant_expression.cpp \
- ir.cpp \
- ir_expression_flattening.cpp \
- ir_function_can_inline.cpp \
- ir_function.cpp \
- ir_hierarchical_visitor.cpp \
- ir_hv_accept.cpp \
- ir_import_prototypes.cpp \
- ir_print_visitor.cpp \
- ir_reader.cpp \
- ir_rvalue_visitor.cpp \
- ir_set_program_inouts.cpp \
- ir_validate.cpp \
- ir_variable.cpp \
- ir_variable_refcount.cpp \
- linker.cpp \
- link_functions.cpp \
- loop_analysis.cpp \
- loop_controls.cpp \
- loop_unroll.cpp \
- lower_discard.cpp \
- lower_if_to_cond_assign.cpp \
- lower_instructions.cpp \
- lower_jumps.cpp \
- lower_mat_op_to_vec.cpp \
- lower_noise.cpp \
- lower_texture_projection.cpp \
- lower_variable_index_to_cond_assign.cpp \
- lower_vec_index_to_cond_assign.cpp \
- lower_vec_index_to_swizzle.cpp \
- lower_vector.cpp \
- opt_algebraic.cpp \
- opt_constant_folding.cpp \
- opt_constant_propagation.cpp \
- opt_constant_variable.cpp \
- opt_copy_propagation.cpp \
- opt_copy_propagation_elements.cpp \
- opt_dead_code.cpp \
- opt_dead_code_local.cpp \
- opt_dead_functions.cpp \
- opt_discard_simplification.cpp \
- opt_function_inlining.cpp \
- opt_if_simplification.cpp \
- opt_noop_swizzle.cpp \
- opt_redundant_jumps.cpp \
- opt_structure_splitting.cpp \
- opt_swizzle_swizzle.cpp \
- opt_tree_grafting.cpp \
- s_expression.cpp
-
-LIBS = \
- $(TOP)/src/glsl/libglsl.a
-
-APPS = glsl_compiler glcpp/glcpp
-
-GLSL2_C_SOURCES = \
- ../mesa/program/hash_table.c \
- ../mesa/program/symbol_table.c
-GLSL2_CXX_SOURCES = \
- main.cpp
-
-GLSL2_OBJECTS = \
- $(GLSL2_C_SOURCES:.c=.o) \
- $(GLSL2_CXX_SOURCES:.cpp=.o)
-
-### Basic defines ###
-
-DEFINES += \
- $(LIBRARY_DEFINES) \
- $(API_DEFINES)
-
-GLCPP_OBJECTS = \
- $(GLCPP_SOURCES:.c=.o) \
- ../mesa/program/hash_table.o
-
-OBJECTS = \
- $(C_SOURCES:.c=.o) \
- $(CXX_SOURCES:.cpp=.o)
-
-DRICORE_OBJ_DIR = obj-visible
-OBJECTS_DRICORE = $(addprefix $(DRICORE_OBJ_DIR)/,$(OBJECTS))
-
-INCLUDES = \
- -I. \
- -I../mesa \
- -I../mapi \
- -I../../include \
- $(LIBRARY_INCLUDES)
-
-ALL_SOURCES = \
- $(C_SOURCES) \
- $(CXX_SOURCES) \
- $(GLSL2_CXX_SOURCES) \
- $(GLSL2_C_SOURCES)
-
-##### TARGETS #####
-
-default: depend lib$(LIBNAME).a $(APPS) $(DRICORE_GLSL_LIBS)
-
-$(TOP)/$(LIB_DIR)/libglsl.so: $(OBJECTS_DRICORE) builtin_function.o Makefile $(TOP)/src/glsl/Makefile.template
- $(MKLIB) -o $@ -linker '$(CXX)' -ldflags '$(LDFLAGS)' \
- -cplusplus -noprefix \
- -install $(TOP)/$(LIB_DIR) -id $(INSTALL_LIB_DIR)/$@.dylib \
- $(OBJECTS_DRICORE) builtin_function.o
-
-lib$(LIBNAME).a: $(OBJECTS) builtin_function.o Makefile $(TOP)/src/glsl/Makefile.template
- $(MKLIB) -cplusplus -o $(LIBNAME) -static $(OBJECTS) builtin_function.o
-
-depend: $(ALL_SOURCES) Makefile
- rm -f depend
- touch depend
- $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(ALL_SOURCES) 2> /dev/null
-
-# Remove .o and backup files
-clean: clean-dricore
- rm -f $(GLCPP_OBJECTS) $(GLSL2_OBJECTS) $(OBJECTS) lib$(LIBNAME).a depend depend.bak builtin_function.cpp builtin_function.o builtin_stubs.o builtin_compiler
- -rm -f $(APPS)
-
-clean-dricore:
- -rm -f $(DRICORE_OBJ_DIR) $(TOP)/$(LIB_DIR)/libglsl.so libglsl.so
-
-ifneq (,$(DRICORE_GLSL_LIBS))
-DRICORE_INSTALL_TARGET = install-dricore
-endif
-
-# Dummy target
-install: $(DRICORE_INSTALL_TARGET)
- @echo -n ""
-
-install-dricore: default
- $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
- $(INSTALL) -m 755 $(DRICORE_GLSL_LIBS) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
-
-##### RULES #####
-
-glsl_compiler: $(GLSL2_OBJECTS) libglsl.a builtin_stubs.o
- $(APP_CXX) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(GLSL2_OBJECTS) builtin_stubs.o $(LIBS) -o $@
-
-glcpp: glcpp/glcpp
-glcpp/glcpp: $(GLCPP_OBJECTS)
- $(APP_CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(GLCPP_OBJECTS) -o $@
-
-.cpp.o:
- $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DEFINES) $< -o $@
-
-.c.o:
- $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
-
-$(DRICORE_OBJ_DIR)/%.o : %.cpp
- @mkdir -p $(dir $@)
- $(CXX) -c $(INCLUDES) $(DRI_CXXFLAGS) $(DEFINES) $< -o $@
-
-$(DRICORE_OBJ_DIR)/%.o : %.c
- @mkdir -p $(dir $@)
- $(CC) -c $(INCLUDES) $(DRI_CFLAGS) $(DEFINES) $< -o $@
-
-glsl_lexer.cpp: glsl_lexer.ll
- flex --nounistd -o$@ $<
-
-glsl_parser.cpp: glsl_parser.yy
- bison -v -o "$@" -p "_mesa_glsl_" --defines=glsl_parser.h $<
-
-glcpp/glcpp-lex.c: glcpp/glcpp-lex.l
- flex --nounistd -o$@ $<
-
-glcpp/glcpp-parse.c: glcpp/glcpp-parse.y
- bison -v -o "$@" --defines=glcpp/glcpp-parse.h $<
-
-builtin_compiler: $(GLSL2_OBJECTS) $(OBJECTS) builtin_stubs.o
- $(APP_CXX) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(GLSL2_OBJECTS) builtin_stubs.o -o $@
-
-builtin_function.cpp: builtins/profiles/* builtins/ir/* builtins/tools/generate_builtins.py builtins/tools/texture_builtins.py builtin_compiler
- @echo Regenerating builtin_function.cpp...
- $(PYTHON2) $(PYTHON_FLAGS) builtins/tools/generate_builtins.py ./builtin_compiler > builtin_function.cpp || rm -f builtin_function.cpp
-
--include depend
+
+#src/glsl/pp/Makefile
+
+TOP = ../..
+
+include $(TOP)/configs/current
+
+LIBNAME = glsl
+
+LIBGLCPP_SOURCES = \
+ glcpp/glcpp-lex.c \
+ glcpp/glcpp-parse.c \
+ glcpp/pp.c
+
+GLCPP_SOURCES = \
+ $(LIBGLCPP_SOURCES) \
+ ralloc.c \
+ glcpp/glcpp.c
+
+C_SOURCES = \
+ strtod.c \
+ ralloc.c \
+ $(LIBGLCPP_SOURCES)
+
+CXX_SOURCES = \
+ ast_expr.cpp \
+ ast_function.cpp \
+ ast_to_hir.cpp \
+ ast_type.cpp \
+ glsl_lexer.cpp \
+ glsl_parser.cpp \
+ glsl_parser_extras.cpp \
+ glsl_types.cpp \
+ glsl_symbol_table.cpp \
+ hir_field_selection.cpp \
+ ir_basic_block.cpp \
+ ir_clone.cpp \
+ ir_constant_expression.cpp \
+ ir.cpp \
+ ir_expression_flattening.cpp \
+ ir_function_can_inline.cpp \
+ ir_function.cpp \
+ ir_hierarchical_visitor.cpp \
+ ir_hv_accept.cpp \
+ ir_import_prototypes.cpp \
+ ir_print_visitor.cpp \
+ ir_reader.cpp \
+ ir_rvalue_visitor.cpp \
+ ir_set_program_inouts.cpp \
+ ir_validate.cpp \
+ ir_variable.cpp \
+ ir_variable_refcount.cpp \
+ linker.cpp \
+ link_functions.cpp \
+ loop_analysis.cpp \
+ loop_controls.cpp \
+ loop_unroll.cpp \
+ lower_discard.cpp \
+ lower_if_to_cond_assign.cpp \
+ lower_instructions.cpp \
+ lower_jumps.cpp \
+ lower_mat_op_to_vec.cpp \
+ lower_noise.cpp \
+ lower_texture_projection.cpp \
+ lower_variable_index_to_cond_assign.cpp \
+ lower_vec_index_to_cond_assign.cpp \
+ lower_vec_index_to_swizzle.cpp \
+ lower_vector.cpp \
+ opt_algebraic.cpp \
+ opt_constant_folding.cpp \
+ opt_constant_propagation.cpp \
+ opt_constant_variable.cpp \
+ opt_copy_propagation.cpp \
+ opt_copy_propagation_elements.cpp \
+ opt_dead_code.cpp \
+ opt_dead_code_local.cpp \
+ opt_dead_functions.cpp \
+ opt_discard_simplification.cpp \
+ opt_function_inlining.cpp \
+ opt_if_simplification.cpp \
+ opt_noop_swizzle.cpp \
+ opt_redundant_jumps.cpp \
+ opt_structure_splitting.cpp \
+ opt_swizzle_swizzle.cpp \
+ opt_tree_grafting.cpp \
+ s_expression.cpp
+
+LIBS = \
+ $(TOP)/src/glsl/libglsl.a
+
+APPS = glsl_compiler glcpp/glcpp
+
+GLSL2_C_SOURCES = \
+ ../mesa/program/hash_table.c \
+ ../mesa/program/symbol_table.c
+GLSL2_CXX_SOURCES = \
+ main.cpp
+
+GLSL2_OBJECTS = \
+ $(GLSL2_C_SOURCES:.c=.o) \
+ $(GLSL2_CXX_SOURCES:.cpp=.o)
+
+### Basic defines ###
+
+DEFINES += \
+ $(LIBRARY_DEFINES) \
+ $(API_DEFINES)
+
+GLCPP_OBJECTS = \
+ $(GLCPP_SOURCES:.c=.o) \
+ ../mesa/program/hash_table.o
+
+OBJECTS = \
+ $(C_SOURCES:.c=.o) \
+ $(CXX_SOURCES:.cpp=.o)
+
+DRICORE_OBJ_DIR = obj-visible
+OBJECTS_DRICORE = $(addprefix $(DRICORE_OBJ_DIR)/,$(OBJECTS))
+
+INCLUDES = \
+ -I. \
+ -I../mesa \
+ -I../mapi \
+ -I../../include \
+ $(LIBRARY_INCLUDES)
+
+ALL_SOURCES = \
+ $(C_SOURCES) \
+ $(CXX_SOURCES) \
+ $(GLSL2_CXX_SOURCES) \
+ $(GLSL2_C_SOURCES)
+
+##### TARGETS #####
+
+default: depend lib$(LIBNAME).a $(APPS) $(DRICORE_GLSL_LIBS)
+
+$(TOP)/$(LIB_DIR)/libglsl.so: $(OBJECTS_DRICORE) builtin_function.o Makefile $(TOP)/src/glsl/Makefile.template
+ $(MKLIB) -o $@ -linker '$(CXX)' -ldflags '$(LDFLAGS)' \
+ -cplusplus -noprefix \
+ -install $(TOP)/$(LIB_DIR) -id $(INSTALL_LIB_DIR)/$@.dylib \
+ $(OBJECTS_DRICORE) builtin_function.o
+
+lib$(LIBNAME).a: $(OBJECTS) builtin_function.o Makefile $(TOP)/src/glsl/Makefile.template
+ $(MKLIB) -cplusplus -o $(LIBNAME) -static $(OBJECTS) builtin_function.o
+
+depend: $(ALL_SOURCES) Makefile
+ rm -f depend
+ touch depend
+ $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(ALL_SOURCES) 2> /dev/null
+
+# Remove .o and backup files
+clean: clean-dricore
+ rm -f $(GLCPP_OBJECTS) $(GLSL2_OBJECTS) $(OBJECTS) lib$(LIBNAME).a depend depend.bak builtin_function.cpp builtin_function.o builtin_stubs.o builtin_compiler
+ -rm -f $(APPS)
+
+clean-dricore:
+ -rm -f $(DRICORE_OBJ_DIR) $(TOP)/$(LIB_DIR)/libglsl.so libglsl.so
+
+ifneq (,$(DRICORE_GLSL_LIBS))
+DRICORE_INSTALL_TARGET = install-dricore
+endif
+
+# Dummy target
+install: $(DRICORE_INSTALL_TARGET)
+ @echo -n ""
+
+install-dricore: default
+ $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
+ $(INSTALL) -m 755 $(DRICORE_GLSL_LIBS) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
+
+##### RULES #####
+
+glsl_compiler: $(GLSL2_OBJECTS) libglsl.a builtin_stubs.o
+ $(APP_CXX) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(GLSL2_OBJECTS) builtin_stubs.o $(LIBS) -o $@
+
+glcpp: glcpp/glcpp
+glcpp/glcpp: $(GLCPP_OBJECTS)
+ $(APP_CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(GLCPP_OBJECTS) -o $@
+
+.cpp.o:
+ $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DEFINES) $< -o $@
+
+.c.o:
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+
+$(DRICORE_OBJ_DIR)/%.o : %.cpp
+ @mkdir -p $(dir $@)
+ $(CXX) -c $(INCLUDES) $(DRI_CXXFLAGS) $(DEFINES) $< -o $@
+
+$(DRICORE_OBJ_DIR)/%.o : %.c
+ @mkdir -p $(dir $@)
+ $(CC) -c $(INCLUDES) $(DRI_CFLAGS) $(DEFINES) $< -o $@
+
+glsl_lexer.cpp: glsl_lexer.ll
+ flex --nounistd -o$@ $<
+
+glsl_parser.cpp: glsl_parser.yy
+ bison -v -o "$@" -p "_mesa_glsl_" --defines=glsl_parser.h $<
+
+glcpp/glcpp-lex.c: glcpp/glcpp-lex.l
+ flex --nounistd -o$@ $<
+
+glcpp/glcpp-parse.c: glcpp/glcpp-parse.y
+ bison -v -o "$@" --defines=glcpp/glcpp-parse.h $<
+
+builtin_compiler: $(GLSL2_OBJECTS) $(OBJECTS) builtin_stubs.o
+ $(APP_CXX) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(GLSL2_OBJECTS) builtin_stubs.o -o $@
+
+builtin_function.cpp: builtins/profiles/* builtins/ir/* builtins/tools/generate_builtins.py builtins/tools/texture_builtins.py builtin_compiler
+ @echo Regenerating builtin_function.cpp...
+ $(PYTHON2) $(PYTHON_FLAGS) builtins/tools/generate_builtins.py ./builtin_compiler > builtin_function.cpp || rm -f builtin_function.cpp
+
+-include depend
diff --git a/mesalib/src/glsl/SConscript b/mesalib/src/glsl/SConscript
index 10abab6f9..930148ee8 100644
--- a/mesalib/src/glsl/SConscript
+++ b/mesalib/src/glsl/SConscript
@@ -1,156 +1,156 @@
-import common
-
-Import('*')
-
-from sys import executable as python_cmd
-
-env = env.Clone()
-
-env.Prepend(CPPPATH = [
- '#include',
- '#src/mapi',
- '#src/mesa',
- '#src/glsl',
- '#src/glsl/glcpp',
-])
-
-env.Append(YACCFLAGS = '-d')
-
-parser_env = env.Clone();
-parser_env.Append(YACCFLAGS = ['--defines=src/glsl/glsl_parser.h', '-p', '_mesa_glsl_'])
-
-glcpp_lexer = env.CFile('glcpp/glcpp-lex.c', 'glcpp/glcpp-lex.l')
-glcpp_parser = env.CFile('glcpp/glcpp-parse.c', 'glcpp/glcpp-parse.y')
-glsl_lexer = parser_env.CXXFile('glsl_lexer.cpp', 'glsl_lexer.ll')
-glsl_parser = parser_env.CXXFile('glsl_parser.cpp', 'glsl_parser.yy')
-
-sources = [
- glcpp_lexer,
- glcpp_parser[0],
- 'glcpp/pp.c',
- 'ast_expr.cpp',
- 'ast_function.cpp',
- 'ast_to_hir.cpp',
- 'ast_type.cpp',
- glsl_lexer,
- glsl_parser[0],
- 'glsl_parser_extras.cpp',
- 'glsl_types.cpp',
- 'glsl_symbol_table.cpp',
- 'hir_field_selection.cpp',
- 'ir_basic_block.cpp',
- 'ir_clone.cpp',
- 'ir_constant_expression.cpp',
- 'ir.cpp',
- 'ir_expression_flattening.cpp',
- 'ir_function_can_inline.cpp',
- 'ir_function.cpp',
- 'ir_hierarchical_visitor.cpp',
- 'ir_hv_accept.cpp',
- 'ir_import_prototypes.cpp',
- 'ir_print_visitor.cpp',
- 'ir_reader.cpp',
- 'ir_rvalue_visitor.cpp',
- 'ir_set_program_inouts.cpp',
- 'ir_validate.cpp',
- 'ir_variable.cpp',
- 'ir_variable_refcount.cpp',
- 'linker.cpp',
- 'link_functions.cpp',
- 'loop_analysis.cpp',
- 'loop_controls.cpp',
- 'loop_unroll.cpp',
- 'lower_discard.cpp',
- 'lower_if_to_cond_assign.cpp',
- 'lower_instructions.cpp',
- 'lower_jumps.cpp',
- 'lower_mat_op_to_vec.cpp',
- 'lower_noise.cpp',
- 'lower_variable_index_to_cond_assign.cpp',
- 'lower_vec_index_to_cond_assign.cpp',
- 'lower_vec_index_to_swizzle.cpp',
- 'lower_vector.cpp',
- 'opt_algebraic.cpp',
- 'opt_constant_folding.cpp',
- 'opt_constant_propagation.cpp',
- 'opt_constant_variable.cpp',
- 'opt_copy_propagation.cpp',
- 'opt_copy_propagation_elements.cpp',
- 'opt_dead_code.cpp',
- 'opt_dead_code_local.cpp',
- 'opt_dead_functions.cpp',
- 'opt_discard_simplification.cpp',
- 'opt_function_inlining.cpp',
- 'opt_if_simplification.cpp',
- 'opt_noop_swizzle.cpp',
- 'opt_redundant_jumps.cpp',
- 'opt_structure_splitting.cpp',
- 'opt_swizzle_swizzle.cpp',
- 'opt_tree_grafting.cpp',
- 'ralloc.c',
- 's_expression.cpp',
- 'strtod.c',
-]
-
-
-if env['crosscompile'] and env['platform'] != 'embedded':
- Import('builtin_glsl_function')
-else:
- if env['msvc']:
- env.Prepend(CPPPATH = ['#/src/getopt'])
- env.PrependUnique(LIBS = [getopt])
-
- builtin_compiler = env.Program(
- target = 'builtin_compiler',
- source = sources + ['main.cpp', 'builtin_stubs.cpp',
- '#src/mesa/program/hash_table.c',
- '#src/mesa/program/symbol_table.c'],
- )
-
- builtin_glsl_function = env.CodeGenerate(
- target = 'builtin_function.cpp',
- script = 'builtins/tools/generate_builtins.py',
- source = builtin_compiler,
- command = python_cmd + ' $SCRIPT $SOURCE > $TARGET'
- )
-
- env.Depends(builtin_glsl_function, ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*'))
-
- Export('builtin_glsl_function')
-
- if env['hostonly']:
- Return()
-
-
-sources += builtin_glsl_function
-
-glsl = env.ConvenienceLibrary(
- target = 'glsl',
- source = sources,
-)
-
-Export('glsl')
-
-# FIXME: We can't build the programs because there's a cyclic dependency between tis directory and src/mesa
-Return()
-
-env = env.Clone()
-
-if env['platform'] == 'windows':
- env.PrependUnique(LIBS = [
- 'user32',
- ])
-
-env.Prepend(LIBS = [glsl])
-
-env.Program(
- target = 'glsl2',
- source = [
- 'main.cpp',
- ]
-)
-
-env.Program(
- target = 'glcpp',
- source = ['glcpp/glcpp.c'],
-)
+import common
+
+Import('*')
+
+from sys import executable as python_cmd
+
+env = env.Clone()
+
+env.Prepend(CPPPATH = [
+ '#include',
+ '#src/mapi',
+ '#src/mesa',
+ '#src/glsl',
+ '#src/glsl/glcpp',
+])
+
+env.Append(YACCFLAGS = '-d')
+
+parser_env = env.Clone();
+parser_env.Append(YACCFLAGS = ['--defines=src/glsl/glsl_parser.h', '-p', '_mesa_glsl_'])
+
+glcpp_lexer = env.CFile('glcpp/glcpp-lex.c', 'glcpp/glcpp-lex.l')
+glcpp_parser = env.CFile('glcpp/glcpp-parse.c', 'glcpp/glcpp-parse.y')
+glsl_lexer = parser_env.CXXFile('glsl_lexer.cpp', 'glsl_lexer.ll')
+glsl_parser = parser_env.CXXFile('glsl_parser.cpp', 'glsl_parser.yy')
+
+sources = [
+ glcpp_lexer,
+ glcpp_parser[0],
+ 'glcpp/pp.c',
+ 'ast_expr.cpp',
+ 'ast_function.cpp',
+ 'ast_to_hir.cpp',
+ 'ast_type.cpp',
+ glsl_lexer,
+ glsl_parser[0],
+ 'glsl_parser_extras.cpp',
+ 'glsl_types.cpp',
+ 'glsl_symbol_table.cpp',
+ 'hir_field_selection.cpp',
+ 'ir_basic_block.cpp',
+ 'ir_clone.cpp',
+ 'ir_constant_expression.cpp',
+ 'ir.cpp',
+ 'ir_expression_flattening.cpp',
+ 'ir_function_can_inline.cpp',
+ 'ir_function.cpp',
+ 'ir_hierarchical_visitor.cpp',
+ 'ir_hv_accept.cpp',
+ 'ir_import_prototypes.cpp',
+ 'ir_print_visitor.cpp',
+ 'ir_reader.cpp',
+ 'ir_rvalue_visitor.cpp',
+ 'ir_set_program_inouts.cpp',
+ 'ir_validate.cpp',
+ 'ir_variable.cpp',
+ 'ir_variable_refcount.cpp',
+ 'linker.cpp',
+ 'link_functions.cpp',
+ 'loop_analysis.cpp',
+ 'loop_controls.cpp',
+ 'loop_unroll.cpp',
+ 'lower_discard.cpp',
+ 'lower_if_to_cond_assign.cpp',
+ 'lower_instructions.cpp',
+ 'lower_jumps.cpp',
+ 'lower_mat_op_to_vec.cpp',
+ 'lower_noise.cpp',
+ 'lower_variable_index_to_cond_assign.cpp',
+ 'lower_vec_index_to_cond_assign.cpp',
+ 'lower_vec_index_to_swizzle.cpp',
+ 'lower_vector.cpp',
+ 'opt_algebraic.cpp',
+ 'opt_constant_folding.cpp',
+ 'opt_constant_propagation.cpp',
+ 'opt_constant_variable.cpp',
+ 'opt_copy_propagation.cpp',
+ 'opt_copy_propagation_elements.cpp',
+ 'opt_dead_code.cpp',
+ 'opt_dead_code_local.cpp',
+ 'opt_dead_functions.cpp',
+ 'opt_discard_simplification.cpp',
+ 'opt_function_inlining.cpp',
+ 'opt_if_simplification.cpp',
+ 'opt_noop_swizzle.cpp',
+ 'opt_redundant_jumps.cpp',
+ 'opt_structure_splitting.cpp',
+ 'opt_swizzle_swizzle.cpp',
+ 'opt_tree_grafting.cpp',
+ 'ralloc.c',
+ 's_expression.cpp',
+ 'strtod.c',
+]
+
+
+if env['crosscompile'] and env['platform'] != 'embedded':
+ Import('builtin_glsl_function')
+else:
+ if env['msvc']:
+ env.Prepend(CPPPATH = ['#/src/getopt'])
+ env.PrependUnique(LIBS = [getopt])
+
+ builtin_compiler = env.Program(
+ target = 'builtin_compiler',
+ source = sources + ['main.cpp', 'builtin_stubs.cpp',
+ '#src/mesa/program/hash_table.c',
+ '#src/mesa/program/symbol_table.c'],
+ )
+
+ builtin_glsl_function = env.CodeGenerate(
+ target = 'builtin_function.cpp',
+ script = 'builtins/tools/generate_builtins.py',
+ source = builtin_compiler,
+ command = python_cmd + ' $SCRIPT $SOURCE > $TARGET'
+ )
+
+ env.Depends(builtin_glsl_function, ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*'))
+
+ Export('builtin_glsl_function')
+
+ if env['hostonly']:
+ Return()
+
+
+sources += builtin_glsl_function
+
+glsl = env.ConvenienceLibrary(
+ target = 'glsl',
+ source = sources,
+)
+
+Export('glsl')
+
+# FIXME: We can't build the programs because there's a cyclic dependency between tis directory and src/mesa
+Return()
+
+env = env.Clone()
+
+if env['platform'] == 'windows':
+ env.PrependUnique(LIBS = [
+ 'user32',
+ ])
+
+env.Prepend(LIBS = [glsl])
+
+env.Program(
+ target = 'glsl2',
+ source = [
+ 'main.cpp',
+ ]
+)
+
+env.Program(
+ target = 'glcpp',
+ source = ['glcpp/glcpp.c'],
+)
diff --git a/mesalib/src/glsl/ast.h b/mesalib/src/glsl/ast.h
index 878f48b20..6963b83af 100644
--- a/mesalib/src/glsl/ast.h
+++ b/mesalib/src/glsl/ast.h
@@ -63,6 +63,10 @@ public:
/* If the user *does* call delete, that's OK, we will just
* ralloc_free in that case. */
+ static void operator delete(void *table, void *ctx)
+ {
+ ralloc_free(table);
+ }
static void operator delete(void *table)
{
ralloc_free(table);
diff --git a/mesalib/src/glsl/ast_expr.cpp b/mesalib/src/glsl/ast_expr.cpp
index e624d11cf..e8812e7a1 100644
--- a/mesalib/src/glsl/ast_expr.cpp
+++ b/mesalib/src/glsl/ast_expr.cpp
@@ -1,95 +1,95 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-#include <assert.h>
-#include "ast.h"
-
-const char *
-ast_expression::operator_string(enum ast_operators op)
-{
- static const char *const operators[] = {
- "=",
- "+",
- "-",
- "+",
- "-",
- "*",
- "/",
- "%",
- "<<",
- ">>",
- "<",
- ">",
- "<=",
- ">=",
- "==",
- "!=",
- "&",
- "^",
- "|",
- "~",
- "&&",
- "^^",
- "||",
- "!",
-
- "*=",
- "/=",
- "%=",
- "+=",
- "-=",
- "<<=",
- ">>=",
- "&=",
- "^=",
- "|=",
-
- "?:",
-
- "++",
- "--",
- "++",
- "--",
- ".",
- };
-
- assert((unsigned int)op < sizeof(operators) / sizeof(operators[0]));
-
- return operators[op];
-}
-
-
-ast_expression_bin::ast_expression_bin(int oper, ast_expression *ex0,
- ast_expression *ex1) :
- ast_expression(oper, ex0, ex1, NULL)
-{
- assert((oper >= ast_plus) && (oper <= ast_logic_not));
-}
-
-
-void
-ast_expression_bin::print(void) const
-{
- subexpressions[0]->print();
- printf("%s ", operator_string(oper));
- subexpressions[1]->print();
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include <assert.h>
+#include "ast.h"
+
+const char *
+ast_expression::operator_string(enum ast_operators op)
+{
+ static const char *const operators[] = {
+ "=",
+ "+",
+ "-",
+ "+",
+ "-",
+ "*",
+ "/",
+ "%",
+ "<<",
+ ">>",
+ "<",
+ ">",
+ "<=",
+ ">=",
+ "==",
+ "!=",
+ "&",
+ "^",
+ "|",
+ "~",
+ "&&",
+ "^^",
+ "||",
+ "!",
+
+ "*=",
+ "/=",
+ "%=",
+ "+=",
+ "-=",
+ "<<=",
+ ">>=",
+ "&=",
+ "^=",
+ "|=",
+
+ "?:",
+
+ "++",
+ "--",
+ "++",
+ "--",
+ ".",
+ };
+
+ assert((unsigned int)op < sizeof(operators) / sizeof(operators[0]));
+
+ return operators[op];
+}
+
+
+ast_expression_bin::ast_expression_bin(int oper, ast_expression *ex0,
+ ast_expression *ex1) :
+ ast_expression(oper, ex0, ex1, NULL)
+{
+ assert((oper >= ast_plus) && (oper <= ast_logic_not));
+}
+
+
+void
+ast_expression_bin::print(void) const
+{
+ subexpressions[0]->print();
+ printf("%s ", operator_string(oper));
+ subexpressions[1]->print();
+}
diff --git a/mesalib/src/glsl/ast_to_hir.cpp b/mesalib/src/glsl/ast_to_hir.cpp
index fd1f0b49f..9aad84615 100644
--- a/mesalib/src/glsl/ast_to_hir.cpp
+++ b/mesalib/src/glsl/ast_to_hir.cpp
@@ -1,3461 +1,3461 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file ast_to_hir.c
- * Convert abstract syntax to to high-level intermediate reprensentation (HIR).
- *
- * During the conversion to HIR, the majority of the symantic checking is
- * preformed on the program. This includes:
- *
- * * Symbol table management
- * * Type checking
- * * Function binding
- *
- * The majority of this work could be done during parsing, and the parser could
- * probably generate HIR directly. However, this results in frequent changes
- * to the parser code. Since we do not assume that every system this complier
- * is built on will have Flex and Bison installed, we have to store the code
- * generated by these tools in our version control system. In other parts of
- * the system we've seen problems where a parser was changed but the generated
- * code was not committed, merge conflicts where created because two developers
- * had slightly different versions of Bison installed, etc.
- *
- * I have also noticed that running Bison generated parsers in GDB is very
- * irritating. When you get a segfault on '$$ = $1->foo', you can't very
- * well 'print $1' in GDB.
- *
- * As a result, my preference is to put as little C code as possible in the
- * parser (and lexer) sources.
- */
-
-#include "main/core.h" /* for struct gl_extensions */
-#include "glsl_symbol_table.h"
-#include "glsl_parser_extras.h"
-#include "ast.h"
-#include "glsl_types.h"
-#include "ir.h"
-
-void
-_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
-{
- _mesa_glsl_initialize_variables(instructions, state);
- _mesa_glsl_initialize_functions(state);
-
- state->symbols->language_version = state->language_version;
-
- state->current_function = NULL;
-
- /* Section 4.2 of the GLSL 1.20 specification states:
- * "The built-in functions are scoped in a scope outside the global scope
- * users declare global variables in. That is, a shader's global scope,
- * available for user-defined functions and global variables, is nested
- * inside the scope containing the built-in functions."
- *
- * Since built-in functions like ftransform() access built-in variables,
- * it follows that those must be in the outer scope as well.
- *
- * We push scope here to create this nesting effect...but don't pop.
- * This way, a shader's globals are still in the symbol table for use
- * by the linker.
- */
- state->symbols->push_scope();
-
- foreach_list_typed (ast_node, ast, link, & state->translation_unit)
- ast->hir(instructions, state);
-}
-
-
-/**
- * If a conversion is available, convert one operand to a different type
- *
- * The \c from \c ir_rvalue is converted "in place".
- *
- * \param to Type that the operand it to be converted to
- * \param from Operand that is being converted
- * \param state GLSL compiler state
- *
- * \return
- * If a conversion is possible (or unnecessary), \c true is returned.
- * Otherwise \c false is returned.
- */
-bool
-apply_implicit_conversion(const glsl_type *to, ir_rvalue * &from,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
- if (to->base_type == from->type->base_type)
- return true;
-
- /* This conversion was added in GLSL 1.20. If the compilation mode is
- * GLSL 1.10, the conversion is skipped.
- */
- if (state->language_version < 120)
- return false;
-
- /* From page 27 (page 33 of the PDF) of the GLSL 1.50 spec:
- *
- * "There are no implicit array or structure conversions. For
- * example, an array of int cannot be implicitly converted to an
- * array of float. There are no implicit conversions between
- * signed and unsigned integers."
- */
- /* FINISHME: The above comment is partially a lie. There is int/uint
- * FINISHME: conversion for immediate constants.
- */
- if (!to->is_float() || !from->type->is_numeric())
- return false;
-
- /* Convert to a floating point type with the same number of components
- * as the original type - i.e. int to float, not int to vec4.
- */
- to = glsl_type::get_instance(GLSL_TYPE_FLOAT, from->type->vector_elements,
- from->type->matrix_columns);
-
- switch (from->type->base_type) {
- case GLSL_TYPE_INT:
- from = new(ctx) ir_expression(ir_unop_i2f, to, from, NULL);
- break;
- case GLSL_TYPE_UINT:
- from = new(ctx) ir_expression(ir_unop_u2f, to, from, NULL);
- break;
- case GLSL_TYPE_BOOL:
- from = new(ctx) ir_expression(ir_unop_b2f, to, from, NULL);
- break;
- default:
- assert(0);
- }
-
- return true;
-}
-
-
-static const struct glsl_type *
-arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
- bool multiply,
- struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
-{
- const glsl_type *type_a = value_a->type;
- const glsl_type *type_b = value_b->type;
-
- /* From GLSL 1.50 spec, page 56:
- *
- * "The arithmetic binary operators add (+), subtract (-),
- * multiply (*), and divide (/) operate on integer and
- * floating-point scalars, vectors, and matrices."
- */
- if (!type_a->is_numeric() || !type_b->is_numeric()) {
- _mesa_glsl_error(loc, state,
- "Operands to arithmetic operators must be numeric");
- return glsl_type::error_type;
- }
-
-
- /* "If one operand is floating-point based and the other is
- * not, then the conversions from Section 4.1.10 "Implicit
- * Conversions" are applied to the non-floating-point-based operand."
- */
- if (!apply_implicit_conversion(type_a, value_b, state)
- && !apply_implicit_conversion(type_b, value_a, state)) {
- _mesa_glsl_error(loc, state,
- "Could not implicitly convert operands to "
- "arithmetic operator");
- return glsl_type::error_type;
- }
- type_a = value_a->type;
- type_b = value_b->type;
-
- /* "If the operands are integer types, they must both be signed or
- * both be unsigned."
- *
- * From this rule and the preceeding conversion it can be inferred that
- * both types must be GLSL_TYPE_FLOAT, or GLSL_TYPE_UINT, or GLSL_TYPE_INT.
- * The is_numeric check above already filtered out the case where either
- * type is not one of these, so now the base types need only be tested for
- * equality.
- */
- if (type_a->base_type != type_b->base_type) {
- _mesa_glsl_error(loc, state,
- "base type mismatch for arithmetic operator");
- return glsl_type::error_type;
- }
-
- /* "All arithmetic binary operators result in the same fundamental type
- * (signed integer, unsigned integer, or floating-point) as the
- * operands they operate on, after operand type conversion. After
- * conversion, the following cases are valid
- *
- * * The two operands are scalars. In this case the operation is
- * applied, resulting in a scalar."
- */
- if (type_a->is_scalar() && type_b->is_scalar())
- return type_a;
-
- /* "* One operand is a scalar, and the other is a vector or matrix.
- * In this case, the scalar operation is applied independently to each
- * component of the vector or matrix, resulting in the same size
- * vector or matrix."
- */
- if (type_a->is_scalar()) {
- if (!type_b->is_scalar())
- return type_b;
- } else if (type_b->is_scalar()) {
- return type_a;
- }
-
- /* All of the combinations of <scalar, scalar>, <vector, scalar>,
- * <scalar, vector>, <scalar, matrix>, and <matrix, scalar> have been
- * handled.
- */
- assert(!type_a->is_scalar());
- assert(!type_b->is_scalar());
-
- /* "* The two operands are vectors of the same size. In this case, the
- * operation is done component-wise resulting in the same size
- * vector."
- */
- if (type_a->is_vector() && type_b->is_vector()) {
- if (type_a == type_b) {
- return type_a;
- } else {
- _mesa_glsl_error(loc, state,
- "vector size mismatch for arithmetic operator");
- return glsl_type::error_type;
- }
- }
-
- /* All of the combinations of <scalar, scalar>, <vector, scalar>,
- * <scalar, vector>, <scalar, matrix>, <matrix, scalar>, and
- * <vector, vector> have been handled. At least one of the operands must
- * be matrix. Further, since there are no integer matrix types, the base
- * type of both operands must be float.
- */
- assert(type_a->is_matrix() || type_b->is_matrix());
- assert(type_a->base_type == GLSL_TYPE_FLOAT);
- assert(type_b->base_type == GLSL_TYPE_FLOAT);
-
- /* "* The operator is add (+), subtract (-), or divide (/), and the
- * operands are matrices with the same number of rows and the same
- * number of columns. In this case, the operation is done component-
- * wise resulting in the same size matrix."
- * * The operator is multiply (*), where both operands are matrices or
- * one operand is a vector and the other a matrix. A right vector
- * operand is treated as a column vector and a left vector operand as a
- * row vector. In all these cases, it is required that the number of
- * columns of the left operand is equal to the number of rows of the
- * right operand. Then, the multiply (*) operation does a linear
- * algebraic multiply, yielding an object that has the same number of
- * rows as the left operand and the same number of columns as the right
- * operand. Section 5.10 "Vector and Matrix Operations" explains in
- * more detail how vectors and matrices are operated on."
- */
- if (! multiply) {
- if (type_a == type_b)
- return type_a;
- } else {
- if (type_a->is_matrix() && type_b->is_matrix()) {
- /* Matrix multiply. The columns of A must match the rows of B. Given
- * the other previously tested constraints, this means the vector type
- * of a row from A must be the same as the vector type of a column from
- * B.
- */
- if (type_a->row_type() == type_b->column_type()) {
- /* The resulting matrix has the number of columns of matrix B and
- * the number of rows of matrix A. We get the row count of A by
- * looking at the size of a vector that makes up a column. The
- * transpose (size of a row) is done for B.
- */
- const glsl_type *const type =
- glsl_type::get_instance(type_a->base_type,
- type_a->column_type()->vector_elements,
- type_b->row_type()->vector_elements);
- assert(type != glsl_type::error_type);
-
- return type;
- }
- } else if (type_a->is_matrix()) {
- /* A is a matrix and B is a column vector. Columns of A must match
- * rows of B. Given the other previously tested constraints, this
- * means the vector type of a row from A must be the same as the
- * vector the type of B.
- */
- if (type_a->row_type() == type_b) {
- /* The resulting vector has a number of elements equal to
- * the number of rows of matrix A. */
- const glsl_type *const type =
- glsl_type::get_instance(type_a->base_type,
- type_a->column_type()->vector_elements,
- 1);
- assert(type != glsl_type::error_type);
-
- return type;
- }
- } else {
- assert(type_b->is_matrix());
-
- /* A is a row vector and B is a matrix. Columns of A must match rows
- * of B. Given the other previously tested constraints, this means
- * the type of A must be the same as the vector type of a column from
- * B.
- */
- if (type_a == type_b->column_type()) {
- /* The resulting vector has a number of elements equal to
- * the number of columns of matrix B. */
- const glsl_type *const type =
- glsl_type::get_instance(type_a->base_type,
- type_b->row_type()->vector_elements,
- 1);
- assert(type != glsl_type::error_type);
-
- return type;
- }
- }
-
- _mesa_glsl_error(loc, state, "size mismatch for matrix multiplication");
- return glsl_type::error_type;
- }
-
-
- /* "All other cases are illegal."
- */
- _mesa_glsl_error(loc, state, "type mismatch");
- return glsl_type::error_type;
-}
-
-
-static const struct glsl_type *
-unary_arithmetic_result_type(const struct glsl_type *type,
- struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
-{
- /* From GLSL 1.50 spec, page 57:
- *
- * "The arithmetic unary operators negate (-), post- and pre-increment
- * and decrement (-- and ++) operate on integer or floating-point
- * values (including vectors and matrices). All unary operators work
- * component-wise on their operands. These result with the same type
- * they operated on."
- */
- if (!type->is_numeric()) {
- _mesa_glsl_error(loc, state,
- "Operands to arithmetic operators must be numeric");
- return glsl_type::error_type;
- }
-
- return type;
-}
-
-/**
- * \brief Return the result type of a bit-logic operation.
- *
- * If the given types to the bit-logic operator are invalid, return
- * glsl_type::error_type.
- *
- * \param type_a Type of LHS of bit-logic op
- * \param type_b Type of RHS of bit-logic op
- */
-static const struct glsl_type *
-bit_logic_result_type(const struct glsl_type *type_a,
- const struct glsl_type *type_b,
- ast_operators op,
- struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
-{
- if (state->language_version < 130) {
- _mesa_glsl_error(loc, state, "bit operations require GLSL 1.30");
- return glsl_type::error_type;
- }
-
- /* From page 50 (page 56 of PDF) of GLSL 1.30 spec:
- *
- * "The bitwise operators and (&), exclusive-or (^), and inclusive-or
- * (|). The operands must be of type signed or unsigned integers or
- * integer vectors."
- */
- if (!type_a->is_integer()) {
- _mesa_glsl_error(loc, state, "LHS of `%s' must be an integer",
- ast_expression::operator_string(op));
- return glsl_type::error_type;
- }
- if (!type_b->is_integer()) {
- _mesa_glsl_error(loc, state, "RHS of `%s' must be an integer",
- ast_expression::operator_string(op));
- return glsl_type::error_type;
- }
-
- /* "The fundamental types of the operands (signed or unsigned) must
- * match,"
- */
- if (type_a->base_type != type_b->base_type) {
- _mesa_glsl_error(loc, state, "operands of `%s' must have the same "
- "base type", ast_expression::operator_string(op));
- return glsl_type::error_type;
- }
-
- /* "The operands cannot be vectors of differing size." */
- if (type_a->is_vector() &&
- type_b->is_vector() &&
- type_a->vector_elements != type_b->vector_elements) {
- _mesa_glsl_error(loc, state, "operands of `%s' cannot be vectors of "
- "different sizes", ast_expression::operator_string(op));
- return glsl_type::error_type;
- }
-
- /* "If one operand is a scalar and the other a vector, the scalar is
- * applied component-wise to the vector, resulting in the same type as
- * the vector. The fundamental types of the operands [...] will be the
- * resulting fundamental type."
- */
- if (type_a->is_scalar())
- return type_b;
- else
- return type_a;
-}
-
-static const struct glsl_type *
-modulus_result_type(const struct glsl_type *type_a,
- const struct glsl_type *type_b,
- struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
-{
- if (state->language_version < 130) {
- _mesa_glsl_error(loc, state,
- "operator '%%' is reserved in %s",
- state->version_string);
- return glsl_type::error_type;
- }
-
- /* From GLSL 1.50 spec, page 56:
- * "The operator modulus (%) operates on signed or unsigned integers or
- * integer vectors. The operand types must both be signed or both be
- * unsigned."
- */
- if (!type_a->is_integer() || !type_b->is_integer()
- || (type_a->base_type != type_b->base_type)) {
- _mesa_glsl_error(loc, state, "type mismatch");
- return glsl_type::error_type;
- }
-
- /* "The operands cannot be vectors of differing size. If one operand is
- * a scalar and the other vector, then the scalar is applied component-
- * wise to the vector, resulting in the same type as the vector. If both
- * are vectors of the same size, the result is computed component-wise."
- */
- if (type_a->is_vector()) {
- if (!type_b->is_vector()
- || (type_a->vector_elements == type_b->vector_elements))
- return type_a;
- } else
- return type_b;
-
- /* "The operator modulus (%) is not defined for any other data types
- * (non-integer types)."
- */
- _mesa_glsl_error(loc, state, "type mismatch");
- return glsl_type::error_type;
-}
-
-
-static const struct glsl_type *
-relational_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
- struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
-{
- const glsl_type *type_a = value_a->type;
- const glsl_type *type_b = value_b->type;
-
- /* From GLSL 1.50 spec, page 56:
- * "The relational operators greater than (>), less than (<), greater
- * than or equal (>=), and less than or equal (<=) operate only on
- * scalar integer and scalar floating-point expressions."
- */
- if (!type_a->is_numeric()
- || !type_b->is_numeric()
- || !type_a->is_scalar()
- || !type_b->is_scalar()) {
- _mesa_glsl_error(loc, state,
- "Operands to relational operators must be scalar and "
- "numeric");
- return glsl_type::error_type;
- }
-
- /* "Either the operands' types must match, or the conversions from
- * Section 4.1.10 "Implicit Conversions" will be applied to the integer
- * operand, after which the types must match."
- */
- if (!apply_implicit_conversion(type_a, value_b, state)
- && !apply_implicit_conversion(type_b, value_a, state)) {
- _mesa_glsl_error(loc, state,
- "Could not implicitly convert operands to "
- "relational operator");
- return glsl_type::error_type;
- }
- type_a = value_a->type;
- type_b = value_b->type;
-
- if (type_a->base_type != type_b->base_type) {
- _mesa_glsl_error(loc, state, "base type mismatch");
- return glsl_type::error_type;
- }
-
- /* "The result is scalar Boolean."
- */
- return glsl_type::bool_type;
-}
-
-/**
- * \brief Return the result type of a bit-shift operation.
- *
- * If the given types to the bit-shift operator are invalid, return
- * glsl_type::error_type.
- *
- * \param type_a Type of LHS of bit-shift op
- * \param type_b Type of RHS of bit-shift op
- */
-static const struct glsl_type *
-shift_result_type(const struct glsl_type *type_a,
- const struct glsl_type *type_b,
- ast_operators op,
- struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
-{
- if (state->language_version < 130) {
- _mesa_glsl_error(loc, state, "bit operations require GLSL 1.30");
- return glsl_type::error_type;
- }
-
- /* From page 50 (page 56 of the PDF) of the GLSL 1.30 spec:
- *
- * "The shift operators (<<) and (>>). For both operators, the operands
- * must be signed or unsigned integers or integer vectors. One operand
- * can be signed while the other is unsigned."
- */
- if (!type_a->is_integer()) {
- _mesa_glsl_error(loc, state, "LHS of operator %s must be an integer or "
- "integer vector", ast_expression::operator_string(op));
- return glsl_type::error_type;
-
- }
- if (!type_b->is_integer()) {
- _mesa_glsl_error(loc, state, "RHS of operator %s must be an integer or "
- "integer vector", ast_expression::operator_string(op));
- return glsl_type::error_type;
- }
-
- /* "If the first operand is a scalar, the second operand has to be
- * a scalar as well."
- */
- if (type_a->is_scalar() && !type_b->is_scalar()) {
- _mesa_glsl_error(loc, state, "If the first operand of %s is scalar, the "
- "second must be scalar as well",
- ast_expression::operator_string(op));
- return glsl_type::error_type;
- }
-
- /* If both operands are vectors, check that they have same number of
- * elements.
- */
- if (type_a->is_vector() &&
- type_b->is_vector() &&
- type_a->vector_elements != type_b->vector_elements) {
- _mesa_glsl_error(loc, state, "Vector operands to operator %s must "
- "have same number of elements",
- ast_expression::operator_string(op));
- return glsl_type::error_type;
- }
-
- /* "In all cases, the resulting type will be the same type as the left
- * operand."
- */
- return type_a;
-}
-
-/**
- * Validates that a value can be assigned to a location with a specified type
- *
- * Validates that \c rhs can be assigned to some location. If the types are
- * not an exact match but an automatic conversion is possible, \c rhs will be
- * converted.
- *
- * \return
- * \c NULL if \c rhs cannot be assigned to a location with type \c lhs_type.
- * Otherwise the actual RHS to be assigned will be returned. This may be
- * \c rhs, or it may be \c rhs after some type conversion.
- *
- * \note
- * In addition to being used for assignments, this function is used to
- * type-check return values.
- */
-ir_rvalue *
-validate_assignment(struct _mesa_glsl_parse_state *state,
- const glsl_type *lhs_type, ir_rvalue *rhs)
-{
- /* If there is already some error in the RHS, just return it. Anything
- * else will lead to an avalanche of error message back to the user.
- */
- if (rhs->type->is_error())
- return rhs;
-
- /* If the types are identical, the assignment can trivially proceed.
- */
- if (rhs->type == lhs_type)
- return rhs;
-
- /* If the array element types are the same and the size of the LHS is zero,
- * the assignment is okay.
- *
- * Note: Whole-array assignments are not permitted in GLSL 1.10, but this
- * is handled by ir_dereference::is_lvalue.
- */
- if (lhs_type->is_array() && rhs->type->is_array()
- && (lhs_type->element_type() == rhs->type->element_type())
- && (lhs_type->array_size() == 0)) {
- return rhs;
- }
-
- /* Check for implicit conversion in GLSL 1.20 */
- if (apply_implicit_conversion(lhs_type, rhs, state)) {
- if (rhs->type == lhs_type)
- return rhs;
- }
-
- return NULL;
-}
-
-ir_rvalue *
-do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
- ir_rvalue *lhs, ir_rvalue *rhs,
- YYLTYPE lhs_loc)
-{
- void *ctx = state;
- bool error_emitted = (lhs->type->is_error() || rhs->type->is_error());
-
- if (!error_emitted) {
- if (lhs->variable_referenced() != NULL
- && lhs->variable_referenced()->read_only) {
- _mesa_glsl_error(&lhs_loc, state,
- "assignment to read-only variable '%s'",
- lhs->variable_referenced()->name);
- error_emitted = true;
-
- } else if (!lhs->is_lvalue()) {
- _mesa_glsl_error(& lhs_loc, state, "non-lvalue in assignment");
- error_emitted = true;
- }
-
- if (state->es_shader && lhs->type->is_array()) {
- _mesa_glsl_error(&lhs_loc, state, "whole array assignment is not "
- "allowed in GLSL ES 1.00.");
- error_emitted = true;
- }
- }
-
- ir_rvalue *new_rhs = validate_assignment(state, lhs->type, rhs);
- if (new_rhs == NULL) {
- _mesa_glsl_error(& lhs_loc, state, "type mismatch");
- } else {
- rhs = new_rhs;
-
- /* If the LHS array was not declared with a size, it takes it size from
- * the RHS. If the LHS is an l-value and a whole array, it must be a
- * dereference of a variable. Any other case would require that the LHS
- * is either not an l-value or not a whole array.
- */
- if (lhs->type->array_size() == 0) {
- ir_dereference *const d = lhs->as_dereference();
-
- assert(d != NULL);
-
- ir_variable *const var = d->variable_referenced();
-
- assert(var != NULL);
-
- if (var->max_array_access >= unsigned(rhs->type->array_size())) {
- /* FINISHME: This should actually log the location of the RHS. */
- _mesa_glsl_error(& lhs_loc, state, "array size must be > %u due to "
- "previous access",
- var->max_array_access);
- }
-
- var->type = glsl_type::get_array_instance(lhs->type->element_type(),
- rhs->type->array_size());
- d->type = var->type;
- }
- }
-
- /* Most callers of do_assignment (assign, add_assign, pre_inc/dec,
- * but not post_inc) need the converted assigned value as an rvalue
- * to handle things like:
- *
- * i = j += 1;
- *
- * So we always just store the computed value being assigned to a
- * temporary and return a deref of that temporary. If the rvalue
- * ends up not being used, the temp will get copy-propagated out.
- */
- ir_variable *var = new(ctx) ir_variable(rhs->type, "assignment_tmp",
- ir_var_temporary);
- ir_dereference_variable *deref_var = new(ctx) ir_dereference_variable(var);
- instructions->push_tail(var);
- instructions->push_tail(new(ctx) ir_assignment(deref_var,
- rhs,
- NULL));
- deref_var = new(ctx) ir_dereference_variable(var);
-
- if (!error_emitted)
- instructions->push_tail(new(ctx) ir_assignment(lhs, deref_var, NULL));
-
- return new(ctx) ir_dereference_variable(var);
-}
-
-static ir_rvalue *
-get_lvalue_copy(exec_list *instructions, ir_rvalue *lvalue)
-{
- void *ctx = ralloc_parent(lvalue);
- ir_variable *var;
-
- var = new(ctx) ir_variable(lvalue->type, "_post_incdec_tmp",
- ir_var_temporary);
- instructions->push_tail(var);
- var->mode = ir_var_auto;
-
- instructions->push_tail(new(ctx) ir_assignment(new(ctx) ir_dereference_variable(var),
- lvalue, NULL));
-
- /* Once we've created this temporary, mark it read only so it's no
- * longer considered an lvalue.
- */
- var->read_only = true;
-
- return new(ctx) ir_dereference_variable(var);
-}
-
-
-ir_rvalue *
-ast_node::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- (void) instructions;
- (void) state;
-
- return NULL;
-}
-
-static void
-mark_whole_array_access(ir_rvalue *access)
-{
- ir_dereference_variable *deref = access->as_dereference_variable();
-
- if (deref) {
- deref->var->max_array_access = deref->type->length - 1;
- }
-}
-
-static ir_rvalue *
-do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
-{
- int join_op;
- ir_rvalue *cmp = NULL;
-
- if (operation == ir_binop_all_equal)
- join_op = ir_binop_logic_and;
- else
- join_op = ir_binop_logic_or;
-
- switch (op0->type->base_type) {
- case GLSL_TYPE_FLOAT:
- case GLSL_TYPE_UINT:
- case GLSL_TYPE_INT:
- case GLSL_TYPE_BOOL:
- return new(mem_ctx) ir_expression(operation, op0, op1);
-
- case GLSL_TYPE_ARRAY: {
- for (unsigned int i = 0; i < op0->type->length; i++) {
- ir_rvalue *e0, *e1, *result;
-
- e0 = new(mem_ctx) ir_dereference_array(op0->clone(mem_ctx, NULL),
- new(mem_ctx) ir_constant(i));
- e1 = new(mem_ctx) ir_dereference_array(op1->clone(mem_ctx, NULL),
- new(mem_ctx) ir_constant(i));
- result = do_comparison(mem_ctx, operation, e0, e1);
-
- if (cmp) {
- cmp = new(mem_ctx) ir_expression(join_op, cmp, result);
- } else {
- cmp = result;
- }
- }
-
- mark_whole_array_access(op0);
- mark_whole_array_access(op1);
- break;
- }
-
- case GLSL_TYPE_STRUCT: {
- for (unsigned int i = 0; i < op0->type->length; i++) {
- ir_rvalue *e0, *e1, *result;
- const char *field_name = op0->type->fields.structure[i].name;
-
- e0 = new(mem_ctx) ir_dereference_record(op0->clone(mem_ctx, NULL),
- field_name);
- e1 = new(mem_ctx) ir_dereference_record(op1->clone(mem_ctx, NULL),
- field_name);
- result = do_comparison(mem_ctx, operation, e0, e1);
-
- if (cmp) {
- cmp = new(mem_ctx) ir_expression(join_op, cmp, result);
- } else {
- cmp = result;
- }
- }
- break;
- }
-
- case GLSL_TYPE_ERROR:
- case GLSL_TYPE_VOID:
- case GLSL_TYPE_SAMPLER:
- /* I assume a comparison of a struct containing a sampler just
- * ignores the sampler present in the type.
- */
- break;
-
- default:
- assert(!"Should not get here.");
- break;
- }
-
- if (cmp == NULL)
- cmp = new(mem_ctx) ir_constant(true);
-
- return cmp;
-}
-
-ir_rvalue *
-ast_expression::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
- static const int operations[AST_NUM_OPERATORS] = {
- -1, /* ast_assign doesn't convert to ir_expression. */
- -1, /* ast_plus doesn't convert to ir_expression. */
- ir_unop_neg,
- ir_binop_add,
- ir_binop_sub,
- ir_binop_mul,
- ir_binop_div,
- ir_binop_mod,
- ir_binop_lshift,
- ir_binop_rshift,
- ir_binop_less,
- ir_binop_greater,
- ir_binop_lequal,
- ir_binop_gequal,
- ir_binop_all_equal,
- ir_binop_any_nequal,
- ir_binop_bit_and,
- ir_binop_bit_xor,
- ir_binop_bit_or,
- ir_unop_bit_not,
- ir_binop_logic_and,
- ir_binop_logic_xor,
- ir_binop_logic_or,
- ir_unop_logic_not,
-
- /* Note: The following block of expression types actually convert
- * to multiple IR instructions.
- */
- ir_binop_mul, /* ast_mul_assign */
- ir_binop_div, /* ast_div_assign */
- ir_binop_mod, /* ast_mod_assign */
- ir_binop_add, /* ast_add_assign */
- ir_binop_sub, /* ast_sub_assign */
- ir_binop_lshift, /* ast_ls_assign */
- ir_binop_rshift, /* ast_rs_assign */
- ir_binop_bit_and, /* ast_and_assign */
- ir_binop_bit_xor, /* ast_xor_assign */
- ir_binop_bit_or, /* ast_or_assign */
-
- -1, /* ast_conditional doesn't convert to ir_expression. */
- ir_binop_add, /* ast_pre_inc. */
- ir_binop_sub, /* ast_pre_dec. */
- ir_binop_add, /* ast_post_inc. */
- ir_binop_sub, /* ast_post_dec. */
- -1, /* ast_field_selection doesn't conv to ir_expression. */
- -1, /* ast_array_index doesn't convert to ir_expression. */
- -1, /* ast_function_call doesn't conv to ir_expression. */
- -1, /* ast_identifier doesn't convert to ir_expression. */
- -1, /* ast_int_constant doesn't convert to ir_expression. */
- -1, /* ast_uint_constant doesn't conv to ir_expression. */
- -1, /* ast_float_constant doesn't conv to ir_expression. */
- -1, /* ast_bool_constant doesn't conv to ir_expression. */
- -1, /* ast_sequence doesn't convert to ir_expression. */
- };
- ir_rvalue *result = NULL;
- ir_rvalue *op[3];
- const struct glsl_type *type = glsl_type::error_type;
- bool error_emitted = false;
- YYLTYPE loc;
-
- loc = this->get_location();
-
- switch (this->oper) {
- case ast_assign: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- result = do_assignment(instructions, state, op[0], op[1],
- this->subexpressions[0]->get_location());
- error_emitted = result->type->is_error();
- type = result->type;
- break;
- }
-
- case ast_plus:
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
- type = unary_arithmetic_result_type(op[0]->type, state, & loc);
-
- error_emitted = type->is_error();
-
- result = op[0];
- break;
-
- case ast_neg:
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
- type = unary_arithmetic_result_type(op[0]->type, state, & loc);
-
- error_emitted = type->is_error();
-
- result = new(ctx) ir_expression(operations[this->oper], type,
- op[0], NULL);
- break;
-
- case ast_add:
- case ast_sub:
- case ast_mul:
- case ast_div:
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- type = arithmetic_result_type(op[0], op[1],
- (this->oper == ast_mul),
- state, & loc);
- error_emitted = type->is_error();
-
- result = new(ctx) ir_expression(operations[this->oper], type,
- op[0], op[1]);
- break;
-
- case ast_mod:
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- type = modulus_result_type(op[0]->type, op[1]->type, state, & loc);
-
- assert(operations[this->oper] == ir_binop_mod);
-
- result = new(ctx) ir_expression(operations[this->oper], type,
- op[0], op[1]);
- error_emitted = type->is_error();
- break;
-
- case ast_lshift:
- case ast_rshift:
- if (state->language_version < 130) {
- _mesa_glsl_error(&loc, state, "operator %s requires GLSL 1.30",
- operator_string(this->oper));
- error_emitted = true;
- }
-
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
- type = shift_result_type(op[0]->type, op[1]->type, this->oper, state,
- &loc);
- result = new(ctx) ir_expression(operations[this->oper], type,
- op[0], op[1]);
- error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
- break;
-
- case ast_less:
- case ast_greater:
- case ast_lequal:
- case ast_gequal:
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- type = relational_result_type(op[0], op[1], state, & loc);
-
- /* The relational operators must either generate an error or result
- * in a scalar boolean. See page 57 of the GLSL 1.50 spec.
- */
- assert(type->is_error()
- || ((type->base_type == GLSL_TYPE_BOOL)
- && type->is_scalar()));
-
- result = new(ctx) ir_expression(operations[this->oper], type,
- op[0], op[1]);
- error_emitted = type->is_error();
- break;
-
- case ast_nequal:
- case ast_equal:
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- /* From page 58 (page 64 of the PDF) of the GLSL 1.50 spec:
- *
- * "The equality operators equal (==), and not equal (!=)
- * operate on all types. They result in a scalar Boolean. If
- * the operand types do not match, then there must be a
- * conversion from Section 4.1.10 "Implicit Conversions"
- * applied to one operand that can make them match, in which
- * case this conversion is done."
- */
- if ((!apply_implicit_conversion(op[0]->type, op[1], state)
- && !apply_implicit_conversion(op[1]->type, op[0], state))
- || (op[0]->type != op[1]->type)) {
- _mesa_glsl_error(& loc, state, "operands of `%s' must have the same "
- "type", (this->oper == ast_equal) ? "==" : "!=");
- error_emitted = true;
- } else if ((state->language_version <= 110)
- && (op[0]->type->is_array() || op[1]->type->is_array())) {
- _mesa_glsl_error(& loc, state, "array comparisons forbidden in "
- "GLSL 1.10");
- error_emitted = true;
- }
-
- result = do_comparison(ctx, operations[this->oper], op[0], op[1]);
- type = glsl_type::bool_type;
-
- assert(error_emitted || (result->type == glsl_type::bool_type));
- break;
-
- case ast_bit_and:
- case ast_bit_xor:
- case ast_bit_or:
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
- type = bit_logic_result_type(op[0]->type, op[1]->type, this->oper,
- state, &loc);
- result = new(ctx) ir_expression(operations[this->oper], type,
- op[0], op[1]);
- error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
- break;
-
- case ast_bit_not:
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
- if (state->language_version < 130) {
- _mesa_glsl_error(&loc, state, "bit-wise operations require GLSL 1.30");
- error_emitted = true;
- }
-
- if (!op[0]->type->is_integer()) {
- _mesa_glsl_error(&loc, state, "operand of `~' must be an integer");
- error_emitted = true;
- }
-
- type = op[0]->type;
- result = new(ctx) ir_expression(ir_unop_bit_not, type, op[0], NULL);
- break;
-
- case ast_logic_and: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
- if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[0]->get_location();
-
- _mesa_glsl_error(& loc, state, "LHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
-
- ir_constant *op0_const = op[0]->constant_expression_value();
- if (op0_const) {
- if (op0_const->value.b[0]) {
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[1]->get_location();
-
- _mesa_glsl_error(& loc, state,
- "RHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
- result = op[1];
- } else {
- result = op0_const;
- }
- type = glsl_type::bool_type;
- } else {
- ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type,
- "and_tmp",
- ir_var_temporary);
- instructions->push_tail(tmp);
-
- ir_if *const stmt = new(ctx) ir_if(op[0]);
- instructions->push_tail(stmt);
-
- op[1] = this->subexpressions[1]->hir(&stmt->then_instructions, state);
-
- if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[1]->get_location();
-
- _mesa_glsl_error(& loc, state,
- "RHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
-
- ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp);
- ir_assignment *const then_assign =
- new(ctx) ir_assignment(then_deref, op[1], NULL);
- stmt->then_instructions.push_tail(then_assign);
-
- ir_dereference *const else_deref = new(ctx) ir_dereference_variable(tmp);
- ir_assignment *const else_assign =
- new(ctx) ir_assignment(else_deref, new(ctx) ir_constant(false), NULL);
- stmt->else_instructions.push_tail(else_assign);
-
- result = new(ctx) ir_dereference_variable(tmp);
- type = tmp->type;
- }
- break;
- }
-
- case ast_logic_or: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
- if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[0]->get_location();
-
- _mesa_glsl_error(& loc, state, "LHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
-
- ir_constant *op0_const = op[0]->constant_expression_value();
- if (op0_const) {
- if (op0_const->value.b[0]) {
- result = op0_const;
- } else {
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[1]->get_location();
-
- _mesa_glsl_error(& loc, state,
- "RHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
- result = op[1];
- }
- type = glsl_type::bool_type;
- } else {
- ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type,
- "or_tmp",
- ir_var_temporary);
- instructions->push_tail(tmp);
-
- ir_if *const stmt = new(ctx) ir_if(op[0]);
- instructions->push_tail(stmt);
-
- op[1] = this->subexpressions[1]->hir(&stmt->else_instructions, state);
-
- if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[1]->get_location();
-
- _mesa_glsl_error(& loc, state, "RHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
-
- ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp);
- ir_assignment *const then_assign =
- new(ctx) ir_assignment(then_deref, new(ctx) ir_constant(true), NULL);
- stmt->then_instructions.push_tail(then_assign);
-
- ir_dereference *const else_deref = new(ctx) ir_dereference_variable(tmp);
- ir_assignment *const else_assign =
- new(ctx) ir_assignment(else_deref, op[1], NULL);
- stmt->else_instructions.push_tail(else_assign);
-
- result = new(ctx) ir_dereference_variable(tmp);
- type = tmp->type;
- }
- break;
- }
-
- case ast_logic_xor:
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
-
- result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type,
- op[0], op[1]);
- type = glsl_type::bool_type;
- break;
-
- case ast_logic_not:
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
- if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[0]->get_location();
-
- _mesa_glsl_error(& loc, state,
- "operand of `!' must be scalar boolean");
- error_emitted = true;
- }
-
- result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type,
- op[0], NULL);
- type = glsl_type::bool_type;
- break;
-
- case ast_mul_assign:
- case ast_div_assign:
- case ast_add_assign:
- case ast_sub_assign: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- type = arithmetic_result_type(op[0], op[1],
- (this->oper == ast_mul_assign),
- state, & loc);
-
- ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper], type,
- op[0], op[1]);
-
- result = do_assignment(instructions, state,
- op[0]->clone(ctx, NULL), temp_rhs,
- this->subexpressions[0]->get_location());
- type = result->type;
- error_emitted = (op[0]->type->is_error());
-
- /* GLSL 1.10 does not allow array assignment. However, we don't have to
- * explicitly test for this because none of the binary expression
- * operators allow array operands either.
- */
-
- break;
- }
-
- case ast_mod_assign: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- type = modulus_result_type(op[0]->type, op[1]->type, state, & loc);
-
- assert(operations[this->oper] == ir_binop_mod);
-
- ir_rvalue *temp_rhs;
- temp_rhs = new(ctx) ir_expression(operations[this->oper], type,
- op[0], op[1]);
-
- result = do_assignment(instructions, state,
- op[0]->clone(ctx, NULL), temp_rhs,
- this->subexpressions[0]->get_location());
- type = result->type;
- error_emitted = type->is_error();
- break;
- }
-
- case ast_ls_assign:
- case ast_rs_assign: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
- type = shift_result_type(op[0]->type, op[1]->type, this->oper, state,
- &loc);
- ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper],
- type, op[0], op[1]);
- result = do_assignment(instructions, state, op[0]->clone(ctx, NULL),
- temp_rhs,
- this->subexpressions[0]->get_location());
- error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
- break;
- }
-
- case ast_and_assign:
- case ast_xor_assign:
- case ast_or_assign: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
- type = bit_logic_result_type(op[0]->type, op[1]->type, this->oper,
- state, &loc);
- ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper],
- type, op[0], op[1]);
- result = do_assignment(instructions, state, op[0]->clone(ctx, NULL),
- temp_rhs,
- this->subexpressions[0]->get_location());
- error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
- break;
- }
-
- case ast_conditional: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
- /* From page 59 (page 65 of the PDF) of the GLSL 1.50 spec:
- *
- * "The ternary selection operator (?:). It operates on three
- * expressions (exp1 ? exp2 : exp3). This operator evaluates the
- * first expression, which must result in a scalar Boolean."
- */
- if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[0]->get_location();
-
- _mesa_glsl_error(& loc, state, "?: condition must be scalar boolean");
- error_emitted = true;
- }
-
- /* The :? operator is implemented by generating an anonymous temporary
- * followed by an if-statement. The last instruction in each branch of
- * the if-statement assigns a value to the anonymous temporary. This
- * temporary is the r-value of the expression.
- */
- exec_list then_instructions;
- exec_list else_instructions;
-
- op[1] = this->subexpressions[1]->hir(&then_instructions, state);
- op[2] = this->subexpressions[2]->hir(&else_instructions, state);
-
- /* From page 59 (page 65 of the PDF) of the GLSL 1.50 spec:
- *
- * "The second and third expressions can be any type, as
- * long their types match, or there is a conversion in
- * Section 4.1.10 "Implicit Conversions" that can be applied
- * to one of the expressions to make their types match. This
- * resulting matching type is the type of the entire
- * expression."
- */
- if ((!apply_implicit_conversion(op[1]->type, op[2], state)
- && !apply_implicit_conversion(op[2]->type, op[1], state))
- || (op[1]->type != op[2]->type)) {
- YYLTYPE loc = this->subexpressions[1]->get_location();
-
- _mesa_glsl_error(& loc, state, "Second and third operands of ?: "
- "operator must have matching types.");
- error_emitted = true;
- type = glsl_type::error_type;
- } else {
- type = op[1]->type;
- }
-
- /* From page 33 (page 39 of the PDF) of the GLSL 1.10 spec:
- *
- * "The second and third expressions must be the same type, but can
- * be of any type other than an array."
- */
- if ((state->language_version <= 110) && type->is_array()) {
- _mesa_glsl_error(& loc, state, "Second and third operands of ?: "
- "operator must not be arrays.");
- error_emitted = true;
- }
-
- ir_constant *cond_val = op[0]->constant_expression_value();
- ir_constant *then_val = op[1]->constant_expression_value();
- ir_constant *else_val = op[2]->constant_expression_value();
-
- if (then_instructions.is_empty()
- && else_instructions.is_empty()
- && (cond_val != NULL) && (then_val != NULL) && (else_val != NULL)) {
- result = (cond_val->value.b[0]) ? then_val : else_val;
- } else {
- ir_variable *const tmp =
- new(ctx) ir_variable(type, "conditional_tmp", ir_var_temporary);
- instructions->push_tail(tmp);
-
- ir_if *const stmt = new(ctx) ir_if(op[0]);
- instructions->push_tail(stmt);
-
- then_instructions.move_nodes_to(& stmt->then_instructions);
- ir_dereference *const then_deref =
- new(ctx) ir_dereference_variable(tmp);
- ir_assignment *const then_assign =
- new(ctx) ir_assignment(then_deref, op[1], NULL);
- stmt->then_instructions.push_tail(then_assign);
-
- else_instructions.move_nodes_to(& stmt->else_instructions);
- ir_dereference *const else_deref =
- new(ctx) ir_dereference_variable(tmp);
- ir_assignment *const else_assign =
- new(ctx) ir_assignment(else_deref, op[2], NULL);
- stmt->else_instructions.push_tail(else_assign);
-
- result = new(ctx) ir_dereference_variable(tmp);
- }
- break;
- }
-
- case ast_pre_inc:
- case ast_pre_dec: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
- if (op[0]->type->base_type == GLSL_TYPE_FLOAT)
- op[1] = new(ctx) ir_constant(1.0f);
- else
- op[1] = new(ctx) ir_constant(1);
-
- type = arithmetic_result_type(op[0], op[1], false, state, & loc);
-
- ir_rvalue *temp_rhs;
- temp_rhs = new(ctx) ir_expression(operations[this->oper], type,
- op[0], op[1]);
-
- result = do_assignment(instructions, state,
- op[0]->clone(ctx, NULL), temp_rhs,
- this->subexpressions[0]->get_location());
- type = result->type;
- error_emitted = op[0]->type->is_error();
- break;
- }
-
- case ast_post_inc:
- case ast_post_dec: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
- if (op[0]->type->base_type == GLSL_TYPE_FLOAT)
- op[1] = new(ctx) ir_constant(1.0f);
- else
- op[1] = new(ctx) ir_constant(1);
-
- error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
-
- type = arithmetic_result_type(op[0], op[1], false, state, & loc);
-
- ir_rvalue *temp_rhs;
- temp_rhs = new(ctx) ir_expression(operations[this->oper], type,
- op[0], op[1]);
-
- /* Get a temporary of a copy of the lvalue before it's modified.
- * This may get thrown away later.
- */
- result = get_lvalue_copy(instructions, op[0]->clone(ctx, NULL));
-
- (void)do_assignment(instructions, state,
- op[0]->clone(ctx, NULL), temp_rhs,
- this->subexpressions[0]->get_location());
-
- type = result->type;
- error_emitted = op[0]->type->is_error();
- break;
- }
-
- case ast_field_selection:
- result = _mesa_ast_field_selection_to_hir(this, instructions, state);
- type = result->type;
- break;
-
- case ast_array_index: {
- YYLTYPE index_loc = subexpressions[1]->get_location();
-
- op[0] = subexpressions[0]->hir(instructions, state);
- op[1] = subexpressions[1]->hir(instructions, state);
-
- error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
-
- ir_rvalue *const array = op[0];
-
- result = new(ctx) ir_dereference_array(op[0], op[1]);
-
- /* Do not use op[0] after this point. Use array.
- */
- op[0] = NULL;
-
-
- if (error_emitted)
- break;
-
- if (!array->type->is_array()
- && !array->type->is_matrix()
- && !array->type->is_vector()) {
- _mesa_glsl_error(& index_loc, state,
- "cannot dereference non-array / non-matrix / "
- "non-vector");
- error_emitted = true;
- }
-
- if (!op[1]->type->is_integer()) {
- _mesa_glsl_error(& index_loc, state,
- "array index must be integer type");
- error_emitted = true;
- } else if (!op[1]->type->is_scalar()) {
- _mesa_glsl_error(& index_loc, state,
- "array index must be scalar");
- error_emitted = true;
- }
-
- /* If the array index is a constant expression and the array has a
- * declared size, ensure that the access is in-bounds. If the array
- * index is not a constant expression, ensure that the array has a
- * declared size.
- */
- ir_constant *const const_index = op[1]->constant_expression_value();
- if (const_index != NULL) {
- const int idx = const_index->value.i[0];
- const char *type_name;
- unsigned bound = 0;
-
- if (array->type->is_matrix()) {
- type_name = "matrix";
- } else if (array->type->is_vector()) {
- type_name = "vector";
- } else {
- type_name = "array";
- }
-
- /* From page 24 (page 30 of the PDF) of the GLSL 1.50 spec:
- *
- * "It is illegal to declare an array with a size, and then
- * later (in the same shader) index the same array with an
- * integral constant expression greater than or equal to the
- * declared size. It is also illegal to index an array with a
- * negative constant expression."
- */
- if (array->type->is_matrix()) {
- if (array->type->row_type()->vector_elements <= idx) {
- bound = array->type->row_type()->vector_elements;
- }
- } else if (array->type->is_vector()) {
- if (array->type->vector_elements <= idx) {
- bound = array->type->vector_elements;
- }
- } else {
- if ((array->type->array_size() > 0)
- && (array->type->array_size() <= idx)) {
- bound = array->type->array_size();
- }
- }
-
- if (bound > 0) {
- _mesa_glsl_error(& loc, state, "%s index must be < %u",
- type_name, bound);
- error_emitted = true;
- } else if (idx < 0) {
- _mesa_glsl_error(& loc, state, "%s index must be >= 0",
- type_name);
- error_emitted = true;
- }
-
- if (array->type->is_array()) {
- /* If the array is a variable dereference, it dereferences the
- * whole array, by definition. Use this to get the variable.
- *
- * FINISHME: Should some methods for getting / setting / testing
- * FINISHME: array access limits be added to ir_dereference?
- */
- ir_variable *const v = array->whole_variable_referenced();
- if ((v != NULL) && (unsigned(idx) > v->max_array_access))
- v->max_array_access = idx;
- }
- } else if (array->type->array_size() == 0) {
- _mesa_glsl_error(&loc, state, "unsized array index must be constant");
- } else {
- if (array->type->is_array()) {
- /* whole_variable_referenced can return NULL if the array is a
- * member of a structure. In this case it is safe to not update
- * the max_array_access field because it is never used for fields
- * of structures.
- */
- ir_variable *v = array->whole_variable_referenced();
- if (v != NULL)
- v->max_array_access = array->type->array_size();
- }
- }
-
- /* From page 23 (29 of the PDF) of the GLSL 1.30 spec:
- *
- * "Samplers aggregated into arrays within a shader (using square
- * brackets [ ]) can only be indexed with integral constant
- * expressions [...]."
- *
- * This restriction was added in GLSL 1.30. Shaders using earlier version
- * of the language should not be rejected by the compiler front-end for
- * using this construct. This allows useful things such as using a loop
- * counter as the index to an array of samplers. If the loop in unrolled,
- * the code should compile correctly. Instead, emit a warning.
- */
- if (array->type->is_array() &&
- array->type->element_type()->is_sampler() &&
- const_index == NULL) {
-
- if (state->language_version == 100) {
- _mesa_glsl_warning(&loc, state,
- "sampler arrays indexed with non-constant "
- "expressions is optional in GLSL ES 1.00");
- } else if (state->language_version < 130) {
- _mesa_glsl_warning(&loc, state,
- "sampler arrays indexed with non-constant "
- "expressions is forbidden in GLSL 1.30 and "
- "later");
- } else {
- _mesa_glsl_error(&loc, state,
- "sampler arrays indexed with non-constant "
- "expressions is forbidden in GLSL 1.30 and "
- "later");
- error_emitted = true;
- }
- }
-
- if (error_emitted)
- result->type = glsl_type::error_type;
-
- type = result->type;
- break;
- }
-
- case ast_function_call:
- /* Should *NEVER* get here. ast_function_call should always be handled
- * by ast_function_expression::hir.
- */
- assert(0);
- break;
-
- case ast_identifier: {
- /* ast_identifier can appear several places in a full abstract syntax
- * tree. This particular use must be at location specified in the grammar
- * as 'variable_identifier'.
- */
- ir_variable *var =
- state->symbols->get_variable(this->primary_expression.identifier);
-
- result = new(ctx) ir_dereference_variable(var);
-
- if (var != NULL) {
- var->used = true;
- type = result->type;
- } else {
- _mesa_glsl_error(& loc, state, "`%s' undeclared",
- this->primary_expression.identifier);
-
- error_emitted = true;
- }
- break;
- }
-
- case ast_int_constant:
- type = glsl_type::int_type;
- result = new(ctx) ir_constant(this->primary_expression.int_constant);
- break;
-
- case ast_uint_constant:
- type = glsl_type::uint_type;
- result = new(ctx) ir_constant(this->primary_expression.uint_constant);
- break;
-
- case ast_float_constant:
- type = glsl_type::float_type;
- result = new(ctx) ir_constant(this->primary_expression.float_constant);
- break;
-
- case ast_bool_constant:
- type = glsl_type::bool_type;
- result = new(ctx) ir_constant(bool(this->primary_expression.bool_constant));
- break;
-
- case ast_sequence: {
- /* It should not be possible to generate a sequence in the AST without
- * any expressions in it.
- */
- assert(!this->expressions.is_empty());
-
- /* The r-value of a sequence is the last expression in the sequence. If
- * the other expressions in the sequence do not have side-effects (and
- * therefore add instructions to the instruction list), they get dropped
- * on the floor.
- */
- foreach_list_typed (ast_node, ast, link, &this->expressions)
- result = ast->hir(instructions, state);
-
- type = result->type;
-
- /* Any errors should have already been emitted in the loop above.
- */
- error_emitted = true;
- break;
- }
- }
-
- if (type->is_error() && !error_emitted)
- _mesa_glsl_error(& loc, state, "type mismatch");
-
- return result;
-}
-
-
-ir_rvalue *
-ast_expression_statement::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- /* It is possible to have expression statements that don't have an
- * expression. This is the solitary semicolon:
- *
- * for (i = 0; i < 5; i++)
- * ;
- *
- * In this case the expression will be NULL. Test for NULL and don't do
- * anything in that case.
- */
- if (expression != NULL)
- expression->hir(instructions, state);
-
- /* Statements do not have r-values.
- */
- return NULL;
-}
-
-
-ir_rvalue *
-ast_compound_statement::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- if (new_scope)
- state->symbols->push_scope();
-
- foreach_list_typed (ast_node, ast, link, &this->statements)
- ast->hir(instructions, state);
-
- if (new_scope)
- state->symbols->pop_scope();
-
- /* Compound statements do not have r-values.
- */
- return NULL;
-}
-
-
-static const glsl_type *
-process_array_type(YYLTYPE *loc, const glsl_type *base, ast_node *array_size,
- struct _mesa_glsl_parse_state *state)
-{
- unsigned length = 0;
-
- /* FINISHME: Reject delcarations of multidimensional arrays. */
-
- if (array_size != NULL) {
- exec_list dummy_instructions;
- ir_rvalue *const ir = array_size->hir(& dummy_instructions, state);
- YYLTYPE loc = array_size->get_location();
-
- /* FINISHME: Verify that the grammar forbids side-effects in array
- * FINISHME: sizes. i.e., 'vec4 [x = 12] data'
- */
- assert(dummy_instructions.is_empty());
-
- if (ir != NULL) {
- if (!ir->type->is_integer()) {
- _mesa_glsl_error(& loc, state, "array size must be integer type");
- } else if (!ir->type->is_scalar()) {
- _mesa_glsl_error(& loc, state, "array size must be scalar type");
- } else {
- ir_constant *const size = ir->constant_expression_value();
-
- if (size == NULL) {
- _mesa_glsl_error(& loc, state, "array size must be a "
- "constant valued expression");
- } else if (size->value.i[0] <= 0) {
- _mesa_glsl_error(& loc, state, "array size must be > 0");
- } else {
- assert(size->type == ir->type);
- length = size->value.u[0];
- }
- }
- }
- } else if (state->es_shader) {
- /* Section 10.17 of the GLSL ES 1.00 specification states that unsized
- * array declarations have been removed from the language.
- */
- _mesa_glsl_error(loc, state, "unsized array declarations are not "
- "allowed in GLSL ES 1.00.");
- }
-
- return glsl_type::get_array_instance(base, length);
-}
-
-
-const glsl_type *
-ast_type_specifier::glsl_type(const char **name,
- struct _mesa_glsl_parse_state *state) const
-{
- const struct glsl_type *type;
-
- type = state->symbols->get_type(this->type_name);
- *name = this->type_name;
-
- if (this->is_array) {
- YYLTYPE loc = this->get_location();
- type = process_array_type(&loc, type, this->array_size, state);
- }
-
- return type;
-}
-
-
-static void
-apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
- ir_variable *var,
- struct _mesa_glsl_parse_state *state,
- YYLTYPE *loc)
-{
- if (qual->flags.q.invariant) {
- if (var->used) {
- _mesa_glsl_error(loc, state,
- "variable `%s' may not be redeclared "
- "`invariant' after being used",
- var->name);
- } else {
- var->invariant = 1;
- }
- }
-
- if (qual->flags.q.constant || qual->flags.q.attribute
- || qual->flags.q.uniform
- || (qual->flags.q.varying && (state->target == fragment_shader)))
- var->read_only = 1;
-
- if (qual->flags.q.centroid)
- var->centroid = 1;
-
- if (qual->flags.q.attribute && state->target != vertex_shader) {
- var->type = glsl_type::error_type;
- _mesa_glsl_error(loc, state,
- "`attribute' variables may not be declared in the "
- "%s shader",
- _mesa_glsl_shader_target_name(state->target));
- }
-
- /* From page 25 (page 31 of the PDF) of the GLSL 1.10 spec:
- *
- * "The varying qualifier can be used only with the data types
- * float, vec2, vec3, vec4, mat2, mat3, and mat4, or arrays of
- * these."
- */
- if (qual->flags.q.varying) {
- const glsl_type *non_array_type;
-
- if (var->type && var->type->is_array())
- non_array_type = var->type->fields.array;
- else
- non_array_type = var->type;
-
- if (non_array_type && non_array_type->base_type != GLSL_TYPE_FLOAT) {
- var->type = glsl_type::error_type;
- _mesa_glsl_error(loc, state,
- "varying variables must be of base type float");
- }
- }
-
- /* If there is no qualifier that changes the mode of the variable, leave
- * the setting alone.
- */
- if (qual->flags.q.in && qual->flags.q.out)
- var->mode = ir_var_inout;
- else if (qual->flags.q.attribute || qual->flags.q.in
- || (qual->flags.q.varying && (state->target == fragment_shader)))
- var->mode = ir_var_in;
- else if (qual->flags.q.out
- || (qual->flags.q.varying && (state->target == vertex_shader)))
- var->mode = ir_var_out;
- else if (qual->flags.q.uniform)
- var->mode = ir_var_uniform;
-
- if (state->all_invariant && (state->current_function == NULL)) {
- switch (state->target) {
- case vertex_shader:
- if (var->mode == ir_var_out)
- var->invariant = true;
- break;
- case geometry_shader:
- if ((var->mode == ir_var_in) || (var->mode == ir_var_out))
- var->invariant = true;
- break;
- case fragment_shader:
- if (var->mode == ir_var_in)
- var->invariant = true;
- break;
- }
- }
-
- if (qual->flags.q.flat)
- var->interpolation = ir_var_flat;
- else if (qual->flags.q.noperspective)
- var->interpolation = ir_var_noperspective;
- else
- var->interpolation = ir_var_smooth;
-
- var->pixel_center_integer = qual->flags.q.pixel_center_integer;
- var->origin_upper_left = qual->flags.q.origin_upper_left;
- if ((qual->flags.q.origin_upper_left || qual->flags.q.pixel_center_integer)
- && (strcmp(var->name, "gl_FragCoord") != 0)) {
- const char *const qual_string = (qual->flags.q.origin_upper_left)
- ? "origin_upper_left" : "pixel_center_integer";
-
- _mesa_glsl_error(loc, state,
- "layout qualifier `%s' can only be applied to "
- "fragment shader input `gl_FragCoord'",
- qual_string);
- }
-
- if (qual->flags.q.explicit_location) {
- const bool global_scope = (state->current_function == NULL);
- bool fail = false;
- const char *string = "";
-
- /* In the vertex shader only shader inputs can be given explicit
- * locations.
- *
- * In the fragment shader only shader outputs can be given explicit
- * locations.
- */
- switch (state->target) {
- case vertex_shader:
- if (!global_scope || (var->mode != ir_var_in)) {
- fail = true;
- string = "input";
- }
- break;
-
- case geometry_shader:
- _mesa_glsl_error(loc, state,
- "geometry shader variables cannot be given "
- "explicit locations\n");
- break;
-
- case fragment_shader:
- if (!global_scope || (var->mode != ir_var_in)) {
- fail = true;
- string = "output";
- }
- break;
- };
-
- if (fail) {
- _mesa_glsl_error(loc, state,
- "only %s shader %s variables can be given an "
- "explicit location\n",
- _mesa_glsl_shader_target_name(state->target),
- string);
- } else {
- var->explicit_location = true;
-
- /* This bit of silliness is needed because invalid explicit locations
- * are supposed to be flagged during linking. Small negative values
- * biased by VERT_ATTRIB_GENERIC0 or FRAG_RESULT_DATA0 could alias
- * built-in values (e.g., -16+VERT_ATTRIB_GENERIC0 = VERT_ATTRIB_POS).
- * The linker needs to be able to differentiate these cases. This
- * ensures that negative values stay negative.
- */
- if (qual->location >= 0) {
- var->location = (state->target == vertex_shader)
- ? (qual->location + VERT_ATTRIB_GENERIC0)
- : (qual->location + FRAG_RESULT_DATA0);
- } else {
- var->location = qual->location;
- }
- }
- }
-
- /* Does the declaration use the 'layout' keyword?
- */
- const bool uses_layout = qual->flags.q.pixel_center_integer
- || qual->flags.q.origin_upper_left
- || qual->flags.q.explicit_location;
-
- /* Does the declaration use the deprecated 'attribute' or 'varying'
- * keywords?
- */
- const bool uses_deprecated_qualifier = qual->flags.q.attribute
- || qual->flags.q.varying;
-
- /* Is the 'layout' keyword used with parameters that allow relaxed checking.
- * Many implementations of GL_ARB_fragment_coord_conventions_enable and some
- * implementations (only Mesa?) GL_ARB_explicit_attrib_location_enable
- * allowed the layout qualifier to be used with 'varying' and 'attribute'.
- * These extensions and all following extensions that add the 'layout'
- * keyword have been modified to require the use of 'in' or 'out'.
- *
- * The following extension do not allow the deprecated keywords:
- *
- * GL_AMD_conservative_depth
- * GL_ARB_gpu_shader5
- * GL_ARB_separate_shader_objects
- * GL_ARB_tesselation_shader
- * GL_ARB_transform_feedback3
- * GL_ARB_uniform_buffer_object
- *
- * It is unknown whether GL_EXT_shader_image_load_store or GL_NV_gpu_shader5
- * allow layout with the deprecated keywords.
- */
- const bool relaxed_layout_qualifier_checking =
- state->ARB_fragment_coord_conventions_enable;
-
- if (uses_layout && uses_deprecated_qualifier) {
- if (relaxed_layout_qualifier_checking) {
- _mesa_glsl_warning(loc, state,
- "`layout' qualifier may not be used with "
- "`attribute' or `varying'");
- } else {
- _mesa_glsl_error(loc, state,
- "`layout' qualifier may not be used with "
- "`attribute' or `varying'");
- }
- }
-
- /* Layout qualifiers for gl_FragDepth, which are enabled by extension
- * AMD_conservative_depth.
- */
- int depth_layout_count = qual->flags.q.depth_any
- + qual->flags.q.depth_greater
- + qual->flags.q.depth_less
- + qual->flags.q.depth_unchanged;
- if (depth_layout_count > 0
- && !state->AMD_conservative_depth_enable) {
- _mesa_glsl_error(loc, state,
- "extension GL_AMD_conservative_depth must be enabled "
- "to use depth layout qualifiers");
- } else if (depth_layout_count > 0
- && strcmp(var->name, "gl_FragDepth") != 0) {
- _mesa_glsl_error(loc, state,
- "depth layout qualifiers can be applied only to "
- "gl_FragDepth");
- } else if (depth_layout_count > 1
- && strcmp(var->name, "gl_FragDepth") == 0) {
- _mesa_glsl_error(loc, state,
- "at most one depth layout qualifier can be applied to "
- "gl_FragDepth");
- }
- if (qual->flags.q.depth_any)
- var->depth_layout = ir_depth_layout_any;
- else if (qual->flags.q.depth_greater)
- var->depth_layout = ir_depth_layout_greater;
- else if (qual->flags.q.depth_less)
- var->depth_layout = ir_depth_layout_less;
- else if (qual->flags.q.depth_unchanged)
- var->depth_layout = ir_depth_layout_unchanged;
- else
- var->depth_layout = ir_depth_layout_none;
-
- if (var->type->is_array() && state->language_version != 110) {
- var->array_lvalue = true;
- }
-}
-
-
-ir_rvalue *
-ast_declarator_list::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
- const struct glsl_type *decl_type;
- const char *type_name = NULL;
- ir_rvalue *result = NULL;
- YYLTYPE loc = this->get_location();
-
- /* From page 46 (page 52 of the PDF) of the GLSL 1.50 spec:
- *
- * "To ensure that a particular output variable is invariant, it is
- * necessary to use the invariant qualifier. It can either be used to
- * qualify a previously declared variable as being invariant
- *
- * invariant gl_Position; // make existing gl_Position be invariant"
- *
- * In these cases the parser will set the 'invariant' flag in the declarator
- * list, and the type will be NULL.
- */
- if (this->invariant) {
- assert(this->type == NULL);
-
- if (state->current_function != NULL) {
- _mesa_glsl_error(& loc, state,
- "All uses of `invariant' keyword must be at global "
- "scope\n");
- }
-
- foreach_list_typed (ast_declaration, decl, link, &this->declarations) {
- assert(!decl->is_array);
- assert(decl->array_size == NULL);
- assert(decl->initializer == NULL);
-
- ir_variable *const earlier =
- state->symbols->get_variable(decl->identifier);
- if (earlier == NULL) {
- _mesa_glsl_error(& loc, state,
- "Undeclared variable `%s' cannot be marked "
- "invariant\n", decl->identifier);
- } else if ((state->target == vertex_shader)
- && (earlier->mode != ir_var_out)) {
- _mesa_glsl_error(& loc, state,
- "`%s' cannot be marked invariant, vertex shader "
- "outputs only\n", decl->identifier);
- } else if ((state->target == fragment_shader)
- && (earlier->mode != ir_var_in)) {
- _mesa_glsl_error(& loc, state,
- "`%s' cannot be marked invariant, fragment shader "
- "inputs only\n", decl->identifier);
- } else if (earlier->used) {
- _mesa_glsl_error(& loc, state,
- "variable `%s' may not be redeclared "
- "`invariant' after being used",
- earlier->name);
- } else {
- earlier->invariant = true;
- }
- }
-
- /* Invariant redeclarations do not have r-values.
- */
- return NULL;
- }
-
- assert(this->type != NULL);
- assert(!this->invariant);
-
- /* The type specifier may contain a structure definition. Process that
- * before any of the variable declarations.
- */
- (void) this->type->specifier->hir(instructions, state);
-
- decl_type = this->type->specifier->glsl_type(& type_name, state);
- if (this->declarations.is_empty()) {
- /* The only valid case where the declaration list can be empty is when
- * the declaration is setting the default precision of a built-in type
- * (e.g., 'precision highp vec4;').
- */
-
- if (decl_type != NULL) {
- } else {
- _mesa_glsl_error(& loc, state, "incomplete declaration");
- }
- }
-
- foreach_list_typed (ast_declaration, decl, link, &this->declarations) {
- const struct glsl_type *var_type;
- ir_variable *var;
-
- /* FINISHME: Emit a warning if a variable declaration shadows a
- * FINISHME: declaration at a higher scope.
- */
-
- if ((decl_type == NULL) || decl_type->is_void()) {
- if (type_name != NULL) {
- _mesa_glsl_error(& loc, state,
- "invalid type `%s' in declaration of `%s'",
- type_name, decl->identifier);
- } else {
- _mesa_glsl_error(& loc, state,
- "invalid type in declaration of `%s'",
- decl->identifier);
- }
- continue;
- }
-
- if (decl->is_array) {
- var_type = process_array_type(&loc, decl_type, decl->array_size,
- state);
- } else {
- var_type = decl_type;
- }
-
- var = new(ctx) ir_variable(var_type, decl->identifier, ir_var_auto);
-
- /* From page 22 (page 28 of the PDF) of the GLSL 1.10 specification;
- *
- * "Global variables can only use the qualifiers const,
- * attribute, uni form, or varying. Only one may be
- * specified.
- *
- * Local variables can only use the qualifier const."
- *
- * This is relaxed in GLSL 1.30. It is also relaxed by any extension
- * that adds the 'layout' keyword.
- */
- if ((state->language_version < 130)
- && !state->ARB_explicit_attrib_location_enable
- && !state->ARB_fragment_coord_conventions_enable) {
- if (this->type->qualifier.flags.q.out) {
- _mesa_glsl_error(& loc, state,
- "`out' qualifier in declaration of `%s' "
- "only valid for function parameters in %s.",
- decl->identifier, state->version_string);
- }
- if (this->type->qualifier.flags.q.in) {
- _mesa_glsl_error(& loc, state,
- "`in' qualifier in declaration of `%s' "
- "only valid for function parameters in %s.",
- decl->identifier, state->version_string);
- }
- /* FINISHME: Test for other invalid qualifiers. */
- }
-
- apply_type_qualifier_to_variable(& this->type->qualifier, var, state,
- & loc);
-
- if (this->type->qualifier.flags.q.invariant) {
- if ((state->target == vertex_shader) && !(var->mode == ir_var_out ||
- var->mode == ir_var_inout)) {
- /* FINISHME: Note that this doesn't work for invariant on
- * a function signature outval
- */
- _mesa_glsl_error(& loc, state,
- "`%s' cannot be marked invariant, vertex shader "
- "outputs only\n", var->name);
- } else if ((state->target == fragment_shader) &&
- !(var->mode == ir_var_in || var->mode == ir_var_inout)) {
- /* FINISHME: Note that this doesn't work for invariant on
- * a function signature inval
- */
- _mesa_glsl_error(& loc, state,
- "`%s' cannot be marked invariant, fragment shader "
- "inputs only\n", var->name);
- }
- }
-
- if (state->current_function != NULL) {
- const char *mode = NULL;
- const char *extra = "";
-
- /* There is no need to check for 'inout' here because the parser will
- * only allow that in function parameter lists.
- */
- if (this->type->qualifier.flags.q.attribute) {
- mode = "attribute";
- } else if (this->type->qualifier.flags.q.uniform) {
- mode = "uniform";
- } else if (this->type->qualifier.flags.q.varying) {
- mode = "varying";
- } else if (this->type->qualifier.flags.q.in) {
- mode = "in";
- extra = " or in function parameter list";
- } else if (this->type->qualifier.flags.q.out) {
- mode = "out";
- extra = " or in function parameter list";
- }
-
- if (mode) {
- _mesa_glsl_error(& loc, state,
- "%s variable `%s' must be declared at "
- "global scope%s",
- mode, var->name, extra);
- }
- } else if (var->mode == ir_var_in) {
- var->read_only = true;
-
- if (state->target == vertex_shader) {
- bool error_emitted = false;
-
- /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
- *
- * "Vertex shader inputs can only be float, floating-point
- * vectors, matrices, signed and unsigned integers and integer
- * vectors. Vertex shader inputs can also form arrays of these
- * types, but not structures."
- *
- * From page 31 (page 27 of the PDF) of the GLSL 1.30 spec:
- *
- * "Vertex shader inputs can only be float, floating-point
- * vectors, matrices, signed and unsigned integers and integer
- * vectors. They cannot be arrays or structures."
- *
- * From page 23 (page 29 of the PDF) of the GLSL 1.20 spec:
- *
- * "The attribute qualifier can be used only with float,
- * floating-point vectors, and matrices. Attribute variables
- * cannot be declared as arrays or structures."
- */
- const glsl_type *check_type = var->type->is_array()
- ? var->type->fields.array : var->type;
-
- switch (check_type->base_type) {
- case GLSL_TYPE_FLOAT:
- break;
- case GLSL_TYPE_UINT:
- case GLSL_TYPE_INT:
- if (state->language_version > 120)
- break;
- /* FALLTHROUGH */
- default:
- _mesa_glsl_error(& loc, state,
- "vertex shader input / attribute cannot have "
- "type %s`%s'",
- var->type->is_array() ? "array of " : "",
- check_type->name);
- error_emitted = true;
- }
-
- if (!error_emitted && (state->language_version <= 130)
- && var->type->is_array()) {
- _mesa_glsl_error(& loc, state,
- "vertex shader input / attribute cannot have "
- "array type");
- error_emitted = true;
- }
- }
- }
-
- /* Integer vertex outputs must be qualified with 'flat'.
- *
- * From section 4.3.6 of the GLSL 1.30 spec:
- * "If a vertex output is a signed or unsigned integer or integer
- * vector, then it must be qualified with the interpolation qualifier
- * flat."
- */
- if (state->language_version >= 130
- && state->target == vertex_shader
- && state->current_function == NULL
- && var->type->is_integer()
- && var->mode == ir_var_out
- && var->interpolation != ir_var_flat) {
-
- _mesa_glsl_error(&loc, state, "If a vertex output is an integer, "
- "then it must be qualified with 'flat'");
- }
-
-
- /* Interpolation qualifiers cannot be applied to 'centroid' and
- * 'centroid varying'.
- *
- * From page 29 (page 35 of the PDF) of the GLSL 1.30 spec:
- * "interpolation qualifiers may only precede the qualifiers in,
- * centroid in, out, or centroid out in a declaration. They do not apply
- * to the deprecated storage qualifiers varying or centroid varying."
- */
- if (state->language_version >= 130
- && this->type->qualifier.has_interpolation()
- && this->type->qualifier.flags.q.varying) {
-
- const char *i = this->type->qualifier.interpolation_string();
- assert(i != NULL);
- const char *s;
- if (this->type->qualifier.flags.q.centroid)
- s = "centroid varying";
- else
- s = "varying";
-
- _mesa_glsl_error(&loc, state,
- "qualifier '%s' cannot be applied to the "
- "deprecated storage qualifier '%s'", i, s);
- }
-
-
- /* Interpolation qualifiers can only apply to vertex shader outputs and
- * fragment shader inputs.
- *
- * From page 29 (page 35 of the PDF) of the GLSL 1.30 spec:
- * "Outputs from a vertex shader (out) and inputs to a fragment
- * shader (in) can be further qualified with one or more of these
- * interpolation qualifiers"
- */
- if (state->language_version >= 130
- && this->type->qualifier.has_interpolation()) {
-
- const char *i = this->type->qualifier.interpolation_string();
- assert(i != NULL);
-
- switch (state->target) {
- case vertex_shader:
- if (this->type->qualifier.flags.q.in) {
- _mesa_glsl_error(&loc, state,
- "qualifier '%s' cannot be applied to vertex "
- "shader inputs", i);
- }
- break;
- case fragment_shader:
- if (this->type->qualifier.flags.q.out) {
- _mesa_glsl_error(&loc, state,
- "qualifier '%s' cannot be applied to fragment "
- "shader outputs", i);
- }
- break;
- default:
- assert(0);
- }
- }
-
-
- /* From section 4.3.4 of the GLSL 1.30 spec:
- * "It is an error to use centroid in in a vertex shader."
- */
- if (state->language_version >= 130
- && this->type->qualifier.flags.q.centroid
- && this->type->qualifier.flags.q.in
- && state->target == vertex_shader) {
-
- _mesa_glsl_error(&loc, state,
- "'centroid in' cannot be used in a vertex shader");
- }
-
-
- /* Precision qualifiers exists only in GLSL versions 1.00 and >= 1.30.
- */
- if (this->type->specifier->precision != ast_precision_none
- && state->language_version != 100
- && state->language_version < 130) {
-
- _mesa_glsl_error(&loc, state,
- "precision qualifiers are supported only in GLSL ES "
- "1.00, and GLSL 1.30 and later");
- }
-
-
- /* Precision qualifiers only apply to floating point and integer types.
- *
- * From section 4.5.2 of the GLSL 1.30 spec:
- * "Any floating point or any integer declaration can have the type
- * preceded by one of these precision qualifiers [...] Literal
- * constants do not have precision qualifiers. Neither do Boolean
- * variables.
- */
- if (this->type->specifier->precision != ast_precision_none
- && !var->type->is_float()
- && !var->type->is_integer()
- && !(var->type->is_array()
- && (var->type->fields.array->is_float()
- || var->type->fields.array->is_integer()))) {
-
- _mesa_glsl_error(&loc, state,
- "precision qualifiers apply only to floating point "
- "and integer types");
- }
-
- /* Process the initializer and add its instructions to a temporary
- * list. This list will be added to the instruction stream (below) after
- * the declaration is added. This is done because in some cases (such as
- * redeclarations) the declaration may not actually be added to the
- * instruction stream.
- */
- exec_list initializer_instructions;
- if (decl->initializer != NULL) {
- YYLTYPE initializer_loc = decl->initializer->get_location();
-
- /* From page 24 (page 30 of the PDF) of the GLSL 1.10 spec:
- *
- * "All uniform variables are read-only and are initialized either
- * directly by an application via API commands, or indirectly by
- * OpenGL."
- */
- if ((state->language_version <= 110)
- && (var->mode == ir_var_uniform)) {
- _mesa_glsl_error(& initializer_loc, state,
- "cannot initialize uniforms in GLSL 1.10");
- }
-
- if (var->type->is_sampler()) {
- _mesa_glsl_error(& initializer_loc, state,
- "cannot initialize samplers");
- }
-
- if ((var->mode == ir_var_in) && (state->current_function == NULL)) {
- _mesa_glsl_error(& initializer_loc, state,
- "cannot initialize %s shader input / %s",
- _mesa_glsl_shader_target_name(state->target),
- (state->target == vertex_shader)
- ? "attribute" : "varying");
- }
-
- ir_dereference *const lhs = new(ctx) ir_dereference_variable(var);
- ir_rvalue *rhs = decl->initializer->hir(&initializer_instructions,
- state);
-
- /* Calculate the constant value if this is a const or uniform
- * declaration.
- */
- if (this->type->qualifier.flags.q.constant
- || this->type->qualifier.flags.q.uniform) {
- ir_rvalue *new_rhs = validate_assignment(state, var->type, rhs);
- if (new_rhs != NULL) {
- rhs = new_rhs;
-
- ir_constant *constant_value = rhs->constant_expression_value();
- if (!constant_value) {
- _mesa_glsl_error(& initializer_loc, state,
- "initializer of %s variable `%s' must be a "
- "constant expression",
- (this->type->qualifier.flags.q.constant)
- ? "const" : "uniform",
- decl->identifier);
- if (var->type->is_numeric()) {
- /* Reduce cascading errors. */
- var->constant_value = ir_constant::zero(ctx, var->type);
- }
- } else {
- rhs = constant_value;
- var->constant_value = constant_value;
- }
- } else {
- _mesa_glsl_error(&initializer_loc, state,
- "initializer of type %s cannot be assigned to "
- "variable of type %s",
- rhs->type->name, var->type->name);
- if (var->type->is_numeric()) {
- /* Reduce cascading errors. */
- var->constant_value = ir_constant::zero(ctx, var->type);
- }
- }
- }
-
- if (rhs && !rhs->type->is_error()) {
- bool temp = var->read_only;
- if (this->type->qualifier.flags.q.constant)
- var->read_only = false;
-
- /* Never emit code to initialize a uniform.
- */
- const glsl_type *initializer_type;
- if (!this->type->qualifier.flags.q.uniform) {
- result = do_assignment(&initializer_instructions, state,
- lhs, rhs,
- this->get_location());
- initializer_type = result->type;
- } else
- initializer_type = rhs->type;
-
- /* If the declared variable is an unsized array, it must inherrit
- * its full type from the initializer. A declaration such as
- *
- * uniform float a[] = float[](1.0, 2.0, 3.0, 3.0);
- *
- * becomes
- *
- * uniform float a[4] = float[](1.0, 2.0, 3.0, 3.0);
- *
- * The assignment generated in the if-statement (below) will also
- * automatically handle this case for non-uniforms.
- *
- * If the declared variable is not an array, the types must
- * already match exactly. As a result, the type assignment
- * here can be done unconditionally. For non-uniforms the call
- * to do_assignment can change the type of the initializer (via
- * the implicit conversion rules). For uniforms the initializer
- * must be a constant expression, and the type of that expression
- * was validated above.
- */
- var->type = initializer_type;
-
- var->read_only = temp;
- }
- }
-
- /* From page 23 (page 29 of the PDF) of the GLSL 1.10 spec:
- *
- * "It is an error to write to a const variable outside of
- * its declaration, so they must be initialized when
- * declared."
- */
- if (this->type->qualifier.flags.q.constant && decl->initializer == NULL) {
- _mesa_glsl_error(& loc, state,
- "const declaration of `%s' must be initialized",
- decl->identifier);
- }
-
- /* Check if this declaration is actually a re-declaration, either to
- * resize an array or add qualifiers to an existing variable.
- *
- * This is allowed for variables in the current scope, or when at
- * global scope (for built-ins in the implicit outer scope).
- */
- ir_variable *earlier = state->symbols->get_variable(decl->identifier);
- if (earlier != NULL && (state->current_function == NULL ||
- state->symbols->name_declared_this_scope(decl->identifier))) {
-
- /* From page 24 (page 30 of the PDF) of the GLSL 1.50 spec,
- *
- * "It is legal to declare an array without a size and then
- * later re-declare the same name as an array of the same
- * type and specify a size."
- */
- if ((earlier->type->array_size() == 0)
- && var->type->is_array()
- && (var->type->element_type() == earlier->type->element_type())) {
- /* FINISHME: This doesn't match the qualifiers on the two
- * FINISHME: declarations. It's not 100% clear whether this is
- * FINISHME: required or not.
- */
-
- /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
- *
- * "The size [of gl_TexCoord] can be at most
- * gl_MaxTextureCoords."
- */
- const unsigned size = unsigned(var->type->array_size());
- if ((strcmp("gl_TexCoord", var->name) == 0)
- && (size > state->Const.MaxTextureCoords)) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state, "`gl_TexCoord' array size cannot "
- "be larger than gl_MaxTextureCoords (%u)\n",
- state->Const.MaxTextureCoords);
- } else if ((size > 0) && (size <= earlier->max_array_access)) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state, "array size must be > %u due to "
- "previous access",
- earlier->max_array_access);
- }
-
- earlier->type = var->type;
- delete var;
- var = NULL;
- } else if (state->ARB_fragment_coord_conventions_enable
- && strcmp(var->name, "gl_FragCoord") == 0
- && earlier->type == var->type
- && earlier->mode == var->mode) {
- /* Allow redeclaration of gl_FragCoord for ARB_fcc layout
- * qualifiers.
- */
- earlier->origin_upper_left = var->origin_upper_left;
- earlier->pixel_center_integer = var->pixel_center_integer;
-
- /* According to section 4.3.7 of the GLSL 1.30 spec,
- * the following built-in varaibles can be redeclared with an
- * interpolation qualifier:
- * * gl_FrontColor
- * * gl_BackColor
- * * gl_FrontSecondaryColor
- * * gl_BackSecondaryColor
- * * gl_Color
- * * gl_SecondaryColor
- */
- } else if (state->language_version >= 130
- && (strcmp(var->name, "gl_FrontColor") == 0
- || strcmp(var->name, "gl_BackColor") == 0
- || strcmp(var->name, "gl_FrontSecondaryColor") == 0
- || strcmp(var->name, "gl_BackSecondaryColor") == 0
- || strcmp(var->name, "gl_Color") == 0
- || strcmp(var->name, "gl_SecondaryColor") == 0)
- && earlier->type == var->type
- && earlier->mode == var->mode) {
- earlier->interpolation = var->interpolation;
-
- /* Layout qualifiers for gl_FragDepth. */
- } else if (state->AMD_conservative_depth_enable
- && strcmp(var->name, "gl_FragDepth") == 0
- && earlier->type == var->type
- && earlier->mode == var->mode) {
-
- /** From the AMD_conservative_depth spec:
- * Within any shader, the first redeclarations of gl_FragDepth
- * must appear before any use of gl_FragDepth.
- */
- if (earlier->used) {
- _mesa_glsl_error(&loc, state,
- "the first redeclaration of gl_FragDepth "
- "must appear before any use of gl_FragDepth");
- }
-
- /* Prevent inconsistent redeclaration of depth layout qualifier. */
- if (earlier->depth_layout != ir_depth_layout_none
- && earlier->depth_layout != var->depth_layout) {
- _mesa_glsl_error(&loc, state,
- "gl_FragDepth: depth layout is declared here "
- "as '%s, but it was previously declared as "
- "'%s'",
- depth_layout_string(var->depth_layout),
- depth_layout_string(earlier->depth_layout));
- }
-
- earlier->depth_layout = var->depth_layout;
-
- } else {
- YYLTYPE loc = this->get_location();
- _mesa_glsl_error(&loc, state, "`%s' redeclared", decl->identifier);
- }
-
- continue;
- }
-
- /* By now, we know it's a new variable declaration (we didn't hit the
- * above "continue").
- *
- * From page 15 (page 21 of the PDF) of the GLSL 1.10 spec,
- *
- * "Identifiers starting with "gl_" are reserved for use by
- * OpenGL, and may not be declared in a shader as either a
- * variable or a function."
- */
- if (strncmp(decl->identifier, "gl_", 3) == 0)
- _mesa_glsl_error(& loc, state,
- "identifier `%s' uses reserved `gl_' prefix",
- decl->identifier);
-
- /* Add the variable to the symbol table. Note that the initializer's
- * IR was already processed earlier (though it hasn't been emitted yet),
- * without the variable in scope.
- *
- * This differs from most C-like languages, but it follows the GLSL
- * specification. From page 28 (page 34 of the PDF) of the GLSL 1.50
- * spec:
- *
- * "Within a declaration, the scope of a name starts immediately
- * after the initializer if present or immediately after the name
- * being declared if not."
- */
- if (!state->symbols->add_variable(var)) {
- YYLTYPE loc = this->get_location();
- _mesa_glsl_error(&loc, state, "name `%s' already taken in the "
- "current scope", decl->identifier);
- continue;
- }
-
- /* Push the variable declaration to the top. It means that all
- * the variable declarations will appear in a funny
- * last-to-first order, but otherwise we run into trouble if a
- * function is prototyped, a global var is decled, then the
- * function is defined with usage of the global var. See
- * glslparsertest's CorrectModule.frag.
- */
- instructions->push_head(var);
- instructions->append_list(&initializer_instructions);
- }
-
-
- /* Generally, variable declarations do not have r-values. However,
- * one is used for the declaration in
- *
- * while (bool b = some_condition()) {
- * ...
- * }
- *
- * so we return the rvalue from the last seen declaration here.
- */
- return result;
-}
-
-
-ir_rvalue *
-ast_parameter_declarator::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
- const struct glsl_type *type;
- const char *name = NULL;
- YYLTYPE loc = this->get_location();
-
- type = this->type->specifier->glsl_type(& name, state);
-
- if (type == NULL) {
- if (name != NULL) {
- _mesa_glsl_error(& loc, state,
- "invalid type `%s' in declaration of `%s'",
- name, this->identifier);
- } else {
- _mesa_glsl_error(& loc, state,
- "invalid type in declaration of `%s'",
- this->identifier);
- }
-
- type = glsl_type::error_type;
- }
-
- /* From page 62 (page 68 of the PDF) of the GLSL 1.50 spec:
- *
- * "Functions that accept no input arguments need not use void in the
- * argument list because prototypes (or definitions) are required and
- * therefore there is no ambiguity when an empty argument list "( )" is
- * declared. The idiom "(void)" as a parameter list is provided for
- * convenience."
- *
- * Placing this check here prevents a void parameter being set up
- * for a function, which avoids tripping up checks for main taking
- * parameters and lookups of an unnamed symbol.
- */
- if (type->is_void()) {
- if (this->identifier != NULL)
- _mesa_glsl_error(& loc, state,
- "named parameter cannot have type `void'");
-
- is_void = true;
- return NULL;
- }
-
- if (formal_parameter && (this->identifier == NULL)) {
- _mesa_glsl_error(& loc, state, "formal parameter lacks a name");
- return NULL;
- }
-
- /* This only handles "vec4 foo[..]". The earlier specifier->glsl_type(...)
- * call already handled the "vec4[..] foo" case.
- */
- if (this->is_array) {
- type = process_array_type(&loc, type, this->array_size, state);
- }
-
- if (type->array_size() == 0) {
- _mesa_glsl_error(&loc, state, "arrays passed as parameters must have "
- "a declared size.");
- type = glsl_type::error_type;
- }
-
- is_void = false;
- ir_variable *var = new(ctx) ir_variable(type, this->identifier, ir_var_in);
-
- /* Apply any specified qualifiers to the parameter declaration. Note that
- * for function parameters the default mode is 'in'.
- */
- apply_type_qualifier_to_variable(& this->type->qualifier, var, state, & loc);
-
- instructions->push_tail(var);
-
- /* Parameter declarations do not have r-values.
- */
- return NULL;
-}
-
-
-void
-ast_parameter_declarator::parameters_to_hir(exec_list *ast_parameters,
- bool formal,
- exec_list *ir_parameters,
- _mesa_glsl_parse_state *state)
-{
- ast_parameter_declarator *void_param = NULL;
- unsigned count = 0;
-
- foreach_list_typed (ast_parameter_declarator, param, link, ast_parameters) {
- param->formal_parameter = formal;
- param->hir(ir_parameters, state);
-
- if (param->is_void)
- void_param = param;
-
- count++;
- }
-
- if ((void_param != NULL) && (count > 1)) {
- YYLTYPE loc = void_param->get_location();
-
- _mesa_glsl_error(& loc, state,
- "`void' parameter must be only parameter");
- }
-}
-
-
-void
-emit_function(_mesa_glsl_parse_state *state, exec_list *instructions,
- ir_function *f)
-{
- /* Emit the new function header */
- if (state->current_function == NULL) {
- instructions->push_tail(f);
- } else {
- /* IR invariants disallow function declarations or definitions nested
- * within other function definitions. Insert the new ir_function
- * block in the instruction sequence before the ir_function block
- * containing the current ir_function_signature.
- */
- ir_function *const curr =
- const_cast<ir_function *>(state->current_function->function());
-
- curr->insert_before(f);
- }
-}
-
-
-ir_rvalue *
-ast_function::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
- ir_function *f = NULL;
- ir_function_signature *sig = NULL;
- exec_list hir_parameters;
-
- const char *const name = identifier;
-
- /* From page 21 (page 27 of the PDF) of the GLSL 1.20 spec,
- *
- * "Function declarations (prototypes) cannot occur inside of functions;
- * they must be at global scope, or for the built-in functions, outside
- * the global scope."
- *
- * From page 27 (page 33 of the PDF) of the GLSL ES 1.00.16 spec,
- *
- * "User defined functions may only be defined within the global scope."
- *
- * Note that this language does not appear in GLSL 1.10.
- */
- if ((state->current_function != NULL) && (state->language_version != 110)) {
- YYLTYPE loc = this->get_location();
- _mesa_glsl_error(&loc, state,
- "declaration of function `%s' not allowed within "
- "function body", name);
- }
-
- /* From page 15 (page 21 of the PDF) of the GLSL 1.10 spec,
- *
- * "Identifiers starting with "gl_" are reserved for use by
- * OpenGL, and may not be declared in a shader as either a
- * variable or a function."
- */
- if (strncmp(name, "gl_", 3) == 0) {
- YYLTYPE loc = this->get_location();
- _mesa_glsl_error(&loc, state,
- "identifier `%s' uses reserved `gl_' prefix", name);
- }
-
- /* Convert the list of function parameters to HIR now so that they can be
- * used below to compare this function's signature with previously seen
- * signatures for functions with the same name.
- */
- ast_parameter_declarator::parameters_to_hir(& this->parameters,
- is_definition,
- & hir_parameters, state);
-
- const char *return_type_name;
- const glsl_type *return_type =
- this->return_type->specifier->glsl_type(& return_type_name, state);
-
- if (!return_type) {
- YYLTYPE loc = this->get_location();
- _mesa_glsl_error(&loc, state,
- "function `%s' has undeclared return type `%s'",
- name, return_type_name);
- return_type = glsl_type::error_type;
- }
-
- /* From page 56 (page 62 of the PDF) of the GLSL 1.30 spec:
- * "No qualifier is allowed on the return type of a function."
- */
- if (this->return_type->has_qualifiers()) {
- YYLTYPE loc = this->get_location();
- _mesa_glsl_error(& loc, state,
- "function `%s' return type has qualifiers", name);
- }
-
- /* Verify that this function's signature either doesn't match a previously
- * seen signature for a function with the same name, or, if a match is found,
- * that the previously seen signature does not have an associated definition.
- */
- f = state->symbols->get_function(name);
- if (f != NULL && (state->es_shader || f->has_user_signature())) {
- sig = f->exact_matching_signature(&hir_parameters);
- if (sig != NULL) {
- const char *badvar = sig->qualifiers_match(&hir_parameters);
- if (badvar != NULL) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(&loc, state, "function `%s' parameter `%s' "
- "qualifiers don't match prototype", name, badvar);
- }
-
- if (sig->return_type != return_type) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(&loc, state, "function `%s' return type doesn't "
- "match prototype", name);
- }
-
- if (is_definition && sig->is_defined) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state, "function `%s' redefined", name);
- }
- }
- } else {
- f = new(ctx) ir_function(name);
- if (!state->symbols->add_function(f)) {
- /* This function name shadows a non-function use of the same name. */
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(&loc, state, "function name `%s' conflicts with "
- "non-function", name);
- return NULL;
- }
-
- emit_function(state, instructions, f);
- }
-
- /* Verify the return type of main() */
- if (strcmp(name, "main") == 0) {
- if (! return_type->is_void()) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state, "main() must return void");
- }
-
- if (!hir_parameters.is_empty()) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state, "main() must not take any parameters");
- }
- }
-
- /* Finish storing the information about this new function in its signature.
- */
- if (sig == NULL) {
- sig = new(ctx) ir_function_signature(return_type);
- f->add_signature(sig);
- }
-
- sig->replace_parameters(&hir_parameters);
- signature = sig;
-
- /* Function declarations (prototypes) do not have r-values.
- */
- return NULL;
-}
-
-
-ir_rvalue *
-ast_function_definition::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- prototype->is_definition = true;
- prototype->hir(instructions, state);
-
- ir_function_signature *signature = prototype->signature;
- if (signature == NULL)
- return NULL;
-
- assert(state->current_function == NULL);
- state->current_function = signature;
- state->found_return = false;
-
- /* Duplicate parameters declared in the prototype as concrete variables.
- * Add these to the symbol table.
- */
- state->symbols->push_scope();
- foreach_iter(exec_list_iterator, iter, signature->parameters) {
- ir_variable *const var = ((ir_instruction *) iter.get())->as_variable();
-
- assert(var != NULL);
-
- /* The only way a parameter would "exist" is if two parameters have
- * the same name.
- */
- if (state->symbols->name_declared_this_scope(var->name)) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state, "parameter `%s' redeclared", var->name);
- } else {
- state->symbols->add_variable(var);
- }
- }
-
- /* Convert the body of the function to HIR. */
- this->body->hir(&signature->body, state);
- signature->is_defined = true;
-
- state->symbols->pop_scope();
-
- assert(state->current_function == signature);
- state->current_function = NULL;
-
- if (!signature->return_type->is_void() && !state->found_return) {
- YYLTYPE loc = this->get_location();
- _mesa_glsl_error(& loc, state, "function `%s' has non-void return type "
- "%s, but no return statement",
- signature->function_name(),
- signature->return_type->name);
- }
-
- /* Function definitions do not have r-values.
- */
- return NULL;
-}
-
-
-ir_rvalue *
-ast_jump_statement::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
-
- switch (mode) {
- case ast_return: {
- ir_return *inst;
- assert(state->current_function);
-
- if (opt_return_value) {
- ir_rvalue *const ret = opt_return_value->hir(instructions, state);
-
- /* The value of the return type can be NULL if the shader says
- * 'return foo();' and foo() is a function that returns void.
- *
- * NOTE: The GLSL spec doesn't say that this is an error. The type
- * of the return value is void. If the return type of the function is
- * also void, then this should compile without error. Seriously.
- */
- const glsl_type *const ret_type =
- (ret == NULL) ? glsl_type::void_type : ret->type;
-
- /* Implicit conversions are not allowed for return values. */
- if (state->current_function->return_type != ret_type) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state,
- "`return' with wrong type %s, in function `%s' "
- "returning %s",
- ret_type->name,
- state->current_function->function_name(),
- state->current_function->return_type->name);
- }
-
- inst = new(ctx) ir_return(ret);
- } else {
- if (state->current_function->return_type->base_type !=
- GLSL_TYPE_VOID) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state,
- "`return' with no value, in function %s returning "
- "non-void",
- state->current_function->function_name());
- }
- inst = new(ctx) ir_return;
- }
-
- state->found_return = true;
- instructions->push_tail(inst);
- break;
- }
-
- case ast_discard:
- if (state->target != fragment_shader) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state,
- "`discard' may only appear in a fragment shader");
- }
- instructions->push_tail(new(ctx) ir_discard);
- break;
-
- case ast_break:
- case ast_continue:
- /* FINISHME: Handle switch-statements. They cannot contain 'continue',
- * FINISHME: and they use a different IR instruction for 'break'.
- */
- /* FINISHME: Correctly handle the nesting. If a switch-statement is
- * FINISHME: inside a loop, a 'continue' is valid and will bind to the
- * FINISHME: loop.
- */
- if (state->loop_or_switch_nesting == NULL) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state,
- "`%s' may only appear in a loop",
- (mode == ast_break) ? "break" : "continue");
- } else {
- ir_loop *const loop = state->loop_or_switch_nesting->as_loop();
-
- /* Inline the for loop expression again, since we don't know
- * where near the end of the loop body the normal copy of it
- * is going to be placed.
- */
- if (mode == ast_continue &&
- state->loop_or_switch_nesting_ast->rest_expression) {
- state->loop_or_switch_nesting_ast->rest_expression->hir(instructions,
- state);
- }
-
- if (loop != NULL) {
- ir_loop_jump *const jump =
- new(ctx) ir_loop_jump((mode == ast_break)
- ? ir_loop_jump::jump_break
- : ir_loop_jump::jump_continue);
- instructions->push_tail(jump);
- }
- }
-
- break;
- }
-
- /* Jump instructions do not have r-values.
- */
- return NULL;
-}
-
-
-ir_rvalue *
-ast_selection_statement::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
-
- ir_rvalue *const condition = this->condition->hir(instructions, state);
-
- /* From page 66 (page 72 of the PDF) of the GLSL 1.50 spec:
- *
- * "Any expression whose type evaluates to a Boolean can be used as the
- * conditional expression bool-expression. Vector types are not accepted
- * as the expression to if."
- *
- * The checks are separated so that higher quality diagnostics can be
- * generated for cases where both rules are violated.
- */
- if (!condition->type->is_boolean() || !condition->type->is_scalar()) {
- YYLTYPE loc = this->condition->get_location();
-
- _mesa_glsl_error(& loc, state, "if-statement condition must be scalar "
- "boolean");
- }
-
- ir_if *const stmt = new(ctx) ir_if(condition);
-
- if (then_statement != NULL) {
- state->symbols->push_scope();
- then_statement->hir(& stmt->then_instructions, state);
- state->symbols->pop_scope();
- }
-
- if (else_statement != NULL) {
- state->symbols->push_scope();
- else_statement->hir(& stmt->else_instructions, state);
- state->symbols->pop_scope();
- }
-
- instructions->push_tail(stmt);
-
- /* if-statements do not have r-values.
- */
- return NULL;
-}
-
-
-void
-ast_iteration_statement::condition_to_hir(ir_loop *stmt,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
-
- if (condition != NULL) {
- ir_rvalue *const cond =
- condition->hir(& stmt->body_instructions, state);
-
- if ((cond == NULL)
- || !cond->type->is_boolean() || !cond->type->is_scalar()) {
- YYLTYPE loc = condition->get_location();
-
- _mesa_glsl_error(& loc, state,
- "loop condition must be scalar boolean");
- } else {
- /* As the first code in the loop body, generate a block that looks
- * like 'if (!condition) break;' as the loop termination condition.
- */
- ir_rvalue *const not_cond =
- new(ctx) ir_expression(ir_unop_logic_not, glsl_type::bool_type, cond,
- NULL);
-
- ir_if *const if_stmt = new(ctx) ir_if(not_cond);
-
- ir_jump *const break_stmt =
- new(ctx) ir_loop_jump(ir_loop_jump::jump_break);
-
- if_stmt->then_instructions.push_tail(break_stmt);
- stmt->body_instructions.push_tail(if_stmt);
- }
- }
-}
-
-
-ir_rvalue *
-ast_iteration_statement::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
-
- /* For-loops and while-loops start a new scope, but do-while loops do not.
- */
- if (mode != ast_do_while)
- state->symbols->push_scope();
-
- if (init_statement != NULL)
- init_statement->hir(instructions, state);
-
- ir_loop *const stmt = new(ctx) ir_loop();
- instructions->push_tail(stmt);
-
- /* Track the current loop and / or switch-statement nesting.
- */
- ir_instruction *const nesting = state->loop_or_switch_nesting;
- ast_iteration_statement *nesting_ast = state->loop_or_switch_nesting_ast;
-
- state->loop_or_switch_nesting = stmt;
- state->loop_or_switch_nesting_ast = this;
-
- if (mode != ast_do_while)
- condition_to_hir(stmt, state);
-
- if (body != NULL)
- body->hir(& stmt->body_instructions, state);
-
- if (rest_expression != NULL)
- rest_expression->hir(& stmt->body_instructions, state);
-
- if (mode == ast_do_while)
- condition_to_hir(stmt, state);
-
- if (mode != ast_do_while)
- state->symbols->pop_scope();
-
- /* Restore previous nesting before returning.
- */
- state->loop_or_switch_nesting = nesting;
- state->loop_or_switch_nesting_ast = nesting_ast;
-
- /* Loops do not have r-values.
- */
- return NULL;
-}
-
-
-ir_rvalue *
-ast_type_specifier::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- if (!this->is_precision_statement && this->structure == NULL)
- return NULL;
-
- YYLTYPE loc = this->get_location();
-
- if (this->precision != ast_precision_none
- && state->language_version != 100
- && state->language_version < 130) {
- _mesa_glsl_error(&loc, state,
- "precision qualifiers exist only in "
- "GLSL ES 1.00, and GLSL 1.30 and later");
- return NULL;
- }
- if (this->precision != ast_precision_none
- && this->structure != NULL) {
- _mesa_glsl_error(&loc, state,
- "precision qualifiers do not apply to structures");
- return NULL;
- }
-
- /* If this is a precision statement, check that the type to which it is
- * applied is either float or int.
- *
- * From section 4.5.3 of the GLSL 1.30 spec:
- * "The precision statement
- * precision precision-qualifier type;
- * can be used to establish a default precision qualifier. The type
- * field can be either int or float [...]. Any other types or
- * qualifiers will result in an error.
- */
- if (this->is_precision_statement) {
- assert(this->precision != ast_precision_none);
- assert(this->structure == NULL); /* The check for structures was
- * performed above. */
- if (this->is_array) {
- _mesa_glsl_error(&loc, state,
- "default precision statements do not apply to "
- "arrays");
- return NULL;
- }
- if (this->type_specifier != ast_float
- && this->type_specifier != ast_int) {
- _mesa_glsl_error(&loc, state,
- "default precision statements apply only to types "
- "float and int");
- return NULL;
- }
-
- /* FINISHME: Translate precision statements into IR. */
- return NULL;
- }
-
- if (this->structure != NULL)
- return this->structure->hir(instructions, state);
-
- return NULL;
-}
-
-
-ir_rvalue *
-ast_struct_specifier::hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- unsigned decl_count = 0;
-
- /* Make an initial pass over the list of structure fields to determine how
- * many there are. Each element in this list is an ast_declarator_list.
- * This means that we actually need to count the number of elements in the
- * 'declarations' list in each of the elements.
- */
- foreach_list_typed (ast_declarator_list, decl_list, link,
- &this->declarations) {
- foreach_list_const (decl_ptr, & decl_list->declarations) {
- decl_count++;
- }
- }
-
- /* Allocate storage for the structure fields and process the field
- * declarations. As the declarations are processed, try to also convert
- * the types to HIR. This ensures that structure definitions embedded in
- * other structure definitions are processed.
- */
- glsl_struct_field *const fields = ralloc_array(state, glsl_struct_field,
- decl_count);
-
- unsigned i = 0;
- foreach_list_typed (ast_declarator_list, decl_list, link,
- &this->declarations) {
- const char *type_name;
-
- decl_list->type->specifier->hir(instructions, state);
-
- /* Section 10.9 of the GLSL ES 1.00 specification states that
- * embedded structure definitions have been removed from the language.
- */
- if (state->es_shader && decl_list->type->specifier->structure != NULL) {
- YYLTYPE loc = this->get_location();
- _mesa_glsl_error(&loc, state, "Embedded structure definitions are "
- "not allowed in GLSL ES 1.00.");
- }
-
- const glsl_type *decl_type =
- decl_list->type->specifier->glsl_type(& type_name, state);
-
- foreach_list_typed (ast_declaration, decl, link,
- &decl_list->declarations) {
- const struct glsl_type *field_type = decl_type;
- if (decl->is_array) {
- YYLTYPE loc = decl->get_location();
- field_type = process_array_type(&loc, decl_type, decl->array_size,
- state);
- }
- fields[i].type = (field_type != NULL)
- ? field_type : glsl_type::error_type;
- fields[i].name = decl->identifier;
- i++;
- }
- }
-
- assert(i == decl_count);
-
- const glsl_type *t =
- glsl_type::get_record_instance(fields, decl_count, this->name);
-
- YYLTYPE loc = this->get_location();
- if (!state->symbols->add_type(name, t)) {
- _mesa_glsl_error(& loc, state, "struct `%s' previously defined", name);
- } else {
- const glsl_type **s = reralloc(state, state->user_structures,
- const glsl_type *,
- state->num_user_structures + 1);
- if (s != NULL) {
- s[state->num_user_structures] = t;
- state->user_structures = s;
- state->num_user_structures++;
- }
- }
-
- /* Structure type definitions do not have r-values.
- */
- return NULL;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file ast_to_hir.c
+ * Convert abstract syntax to to high-level intermediate reprensentation (HIR).
+ *
+ * During the conversion to HIR, the majority of the symantic checking is
+ * preformed on the program. This includes:
+ *
+ * * Symbol table management
+ * * Type checking
+ * * Function binding
+ *
+ * The majority of this work could be done during parsing, and the parser could
+ * probably generate HIR directly. However, this results in frequent changes
+ * to the parser code. Since we do not assume that every system this complier
+ * is built on will have Flex and Bison installed, we have to store the code
+ * generated by these tools in our version control system. In other parts of
+ * the system we've seen problems where a parser was changed but the generated
+ * code was not committed, merge conflicts where created because two developers
+ * had slightly different versions of Bison installed, etc.
+ *
+ * I have also noticed that running Bison generated parsers in GDB is very
+ * irritating. When you get a segfault on '$$ = $1->foo', you can't very
+ * well 'print $1' in GDB.
+ *
+ * As a result, my preference is to put as little C code as possible in the
+ * parser (and lexer) sources.
+ */
+
+#include "main/core.h" /* for struct gl_extensions */
+#include "glsl_symbol_table.h"
+#include "glsl_parser_extras.h"
+#include "ast.h"
+#include "glsl_types.h"
+#include "ir.h"
+
+void
+_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
+{
+ _mesa_glsl_initialize_variables(instructions, state);
+ _mesa_glsl_initialize_functions(state);
+
+ state->symbols->language_version = state->language_version;
+
+ state->current_function = NULL;
+
+ /* Section 4.2 of the GLSL 1.20 specification states:
+ * "The built-in functions are scoped in a scope outside the global scope
+ * users declare global variables in. That is, a shader's global scope,
+ * available for user-defined functions and global variables, is nested
+ * inside the scope containing the built-in functions."
+ *
+ * Since built-in functions like ftransform() access built-in variables,
+ * it follows that those must be in the outer scope as well.
+ *
+ * We push scope here to create this nesting effect...but don't pop.
+ * This way, a shader's globals are still in the symbol table for use
+ * by the linker.
+ */
+ state->symbols->push_scope();
+
+ foreach_list_typed (ast_node, ast, link, & state->translation_unit)
+ ast->hir(instructions, state);
+}
+
+
+/**
+ * If a conversion is available, convert one operand to a different type
+ *
+ * The \c from \c ir_rvalue is converted "in place".
+ *
+ * \param to Type that the operand it to be converted to
+ * \param from Operand that is being converted
+ * \param state GLSL compiler state
+ *
+ * \return
+ * If a conversion is possible (or unnecessary), \c true is returned.
+ * Otherwise \c false is returned.
+ */
+bool
+apply_implicit_conversion(const glsl_type *to, ir_rvalue * &from,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+ if (to->base_type == from->type->base_type)
+ return true;
+
+ /* This conversion was added in GLSL 1.20. If the compilation mode is
+ * GLSL 1.10, the conversion is skipped.
+ */
+ if (state->language_version < 120)
+ return false;
+
+ /* From page 27 (page 33 of the PDF) of the GLSL 1.50 spec:
+ *
+ * "There are no implicit array or structure conversions. For
+ * example, an array of int cannot be implicitly converted to an
+ * array of float. There are no implicit conversions between
+ * signed and unsigned integers."
+ */
+ /* FINISHME: The above comment is partially a lie. There is int/uint
+ * FINISHME: conversion for immediate constants.
+ */
+ if (!to->is_float() || !from->type->is_numeric())
+ return false;
+
+ /* Convert to a floating point type with the same number of components
+ * as the original type - i.e. int to float, not int to vec4.
+ */
+ to = glsl_type::get_instance(GLSL_TYPE_FLOAT, from->type->vector_elements,
+ from->type->matrix_columns);
+
+ switch (from->type->base_type) {
+ case GLSL_TYPE_INT:
+ from = new(ctx) ir_expression(ir_unop_i2f, to, from, NULL);
+ break;
+ case GLSL_TYPE_UINT:
+ from = new(ctx) ir_expression(ir_unop_u2f, to, from, NULL);
+ break;
+ case GLSL_TYPE_BOOL:
+ from = new(ctx) ir_expression(ir_unop_b2f, to, from, NULL);
+ break;
+ default:
+ assert(0);
+ }
+
+ return true;
+}
+
+
+static const struct glsl_type *
+arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
+ bool multiply,
+ struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
+{
+ const glsl_type *type_a = value_a->type;
+ const glsl_type *type_b = value_b->type;
+
+ /* From GLSL 1.50 spec, page 56:
+ *
+ * "The arithmetic binary operators add (+), subtract (-),
+ * multiply (*), and divide (/) operate on integer and
+ * floating-point scalars, vectors, and matrices."
+ */
+ if (!type_a->is_numeric() || !type_b->is_numeric()) {
+ _mesa_glsl_error(loc, state,
+ "Operands to arithmetic operators must be numeric");
+ return glsl_type::error_type;
+ }
+
+
+ /* "If one operand is floating-point based and the other is
+ * not, then the conversions from Section 4.1.10 "Implicit
+ * Conversions" are applied to the non-floating-point-based operand."
+ */
+ if (!apply_implicit_conversion(type_a, value_b, state)
+ && !apply_implicit_conversion(type_b, value_a, state)) {
+ _mesa_glsl_error(loc, state,
+ "Could not implicitly convert operands to "
+ "arithmetic operator");
+ return glsl_type::error_type;
+ }
+ type_a = value_a->type;
+ type_b = value_b->type;
+
+ /* "If the operands are integer types, they must both be signed or
+ * both be unsigned."
+ *
+ * From this rule and the preceeding conversion it can be inferred that
+ * both types must be GLSL_TYPE_FLOAT, or GLSL_TYPE_UINT, or GLSL_TYPE_INT.
+ * The is_numeric check above already filtered out the case where either
+ * type is not one of these, so now the base types need only be tested for
+ * equality.
+ */
+ if (type_a->base_type != type_b->base_type) {
+ _mesa_glsl_error(loc, state,
+ "base type mismatch for arithmetic operator");
+ return glsl_type::error_type;
+ }
+
+ /* "All arithmetic binary operators result in the same fundamental type
+ * (signed integer, unsigned integer, or floating-point) as the
+ * operands they operate on, after operand type conversion. After
+ * conversion, the following cases are valid
+ *
+ * * The two operands are scalars. In this case the operation is
+ * applied, resulting in a scalar."
+ */
+ if (type_a->is_scalar() && type_b->is_scalar())
+ return type_a;
+
+ /* "* One operand is a scalar, and the other is a vector or matrix.
+ * In this case, the scalar operation is applied independently to each
+ * component of the vector or matrix, resulting in the same size
+ * vector or matrix."
+ */
+ if (type_a->is_scalar()) {
+ if (!type_b->is_scalar())
+ return type_b;
+ } else if (type_b->is_scalar()) {
+ return type_a;
+ }
+
+ /* All of the combinations of <scalar, scalar>, <vector, scalar>,
+ * <scalar, vector>, <scalar, matrix>, and <matrix, scalar> have been
+ * handled.
+ */
+ assert(!type_a->is_scalar());
+ assert(!type_b->is_scalar());
+
+ /* "* The two operands are vectors of the same size. In this case, the
+ * operation is done component-wise resulting in the same size
+ * vector."
+ */
+ if (type_a->is_vector() && type_b->is_vector()) {
+ if (type_a == type_b) {
+ return type_a;
+ } else {
+ _mesa_glsl_error(loc, state,
+ "vector size mismatch for arithmetic operator");
+ return glsl_type::error_type;
+ }
+ }
+
+ /* All of the combinations of <scalar, scalar>, <vector, scalar>,
+ * <scalar, vector>, <scalar, matrix>, <matrix, scalar>, and
+ * <vector, vector> have been handled. At least one of the operands must
+ * be matrix. Further, since there are no integer matrix types, the base
+ * type of both operands must be float.
+ */
+ assert(type_a->is_matrix() || type_b->is_matrix());
+ assert(type_a->base_type == GLSL_TYPE_FLOAT);
+ assert(type_b->base_type == GLSL_TYPE_FLOAT);
+
+ /* "* The operator is add (+), subtract (-), or divide (/), and the
+ * operands are matrices with the same number of rows and the same
+ * number of columns. In this case, the operation is done component-
+ * wise resulting in the same size matrix."
+ * * The operator is multiply (*), where both operands are matrices or
+ * one operand is a vector and the other a matrix. A right vector
+ * operand is treated as a column vector and a left vector operand as a
+ * row vector. In all these cases, it is required that the number of
+ * columns of the left operand is equal to the number of rows of the
+ * right operand. Then, the multiply (*) operation does a linear
+ * algebraic multiply, yielding an object that has the same number of
+ * rows as the left operand and the same number of columns as the right
+ * operand. Section 5.10 "Vector and Matrix Operations" explains in
+ * more detail how vectors and matrices are operated on."
+ */
+ if (! multiply) {
+ if (type_a == type_b)
+ return type_a;
+ } else {
+ if (type_a->is_matrix() && type_b->is_matrix()) {
+ /* Matrix multiply. The columns of A must match the rows of B. Given
+ * the other previously tested constraints, this means the vector type
+ * of a row from A must be the same as the vector type of a column from
+ * B.
+ */
+ if (type_a->row_type() == type_b->column_type()) {
+ /* The resulting matrix has the number of columns of matrix B and
+ * the number of rows of matrix A. We get the row count of A by
+ * looking at the size of a vector that makes up a column. The
+ * transpose (size of a row) is done for B.
+ */
+ const glsl_type *const type =
+ glsl_type::get_instance(type_a->base_type,
+ type_a->column_type()->vector_elements,
+ type_b->row_type()->vector_elements);
+ assert(type != glsl_type::error_type);
+
+ return type;
+ }
+ } else if (type_a->is_matrix()) {
+ /* A is a matrix and B is a column vector. Columns of A must match
+ * rows of B. Given the other previously tested constraints, this
+ * means the vector type of a row from A must be the same as the
+ * vector the type of B.
+ */
+ if (type_a->row_type() == type_b) {
+ /* The resulting vector has a number of elements equal to
+ * the number of rows of matrix A. */
+ const glsl_type *const type =
+ glsl_type::get_instance(type_a->base_type,
+ type_a->column_type()->vector_elements,
+ 1);
+ assert(type != glsl_type::error_type);
+
+ return type;
+ }
+ } else {
+ assert(type_b->is_matrix());
+
+ /* A is a row vector and B is a matrix. Columns of A must match rows
+ * of B. Given the other previously tested constraints, this means
+ * the type of A must be the same as the vector type of a column from
+ * B.
+ */
+ if (type_a == type_b->column_type()) {
+ /* The resulting vector has a number of elements equal to
+ * the number of columns of matrix B. */
+ const glsl_type *const type =
+ glsl_type::get_instance(type_a->base_type,
+ type_b->row_type()->vector_elements,
+ 1);
+ assert(type != glsl_type::error_type);
+
+ return type;
+ }
+ }
+
+ _mesa_glsl_error(loc, state, "size mismatch for matrix multiplication");
+ return glsl_type::error_type;
+ }
+
+
+ /* "All other cases are illegal."
+ */
+ _mesa_glsl_error(loc, state, "type mismatch");
+ return glsl_type::error_type;
+}
+
+
+static const struct glsl_type *
+unary_arithmetic_result_type(const struct glsl_type *type,
+ struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
+{
+ /* From GLSL 1.50 spec, page 57:
+ *
+ * "The arithmetic unary operators negate (-), post- and pre-increment
+ * and decrement (-- and ++) operate on integer or floating-point
+ * values (including vectors and matrices). All unary operators work
+ * component-wise on their operands. These result with the same type
+ * they operated on."
+ */
+ if (!type->is_numeric()) {
+ _mesa_glsl_error(loc, state,
+ "Operands to arithmetic operators must be numeric");
+ return glsl_type::error_type;
+ }
+
+ return type;
+}
+
+/**
+ * \brief Return the result type of a bit-logic operation.
+ *
+ * If the given types to the bit-logic operator are invalid, return
+ * glsl_type::error_type.
+ *
+ * \param type_a Type of LHS of bit-logic op
+ * \param type_b Type of RHS of bit-logic op
+ */
+static const struct glsl_type *
+bit_logic_result_type(const struct glsl_type *type_a,
+ const struct glsl_type *type_b,
+ ast_operators op,
+ struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
+{
+ if (state->language_version < 130) {
+ _mesa_glsl_error(loc, state, "bit operations require GLSL 1.30");
+ return glsl_type::error_type;
+ }
+
+ /* From page 50 (page 56 of PDF) of GLSL 1.30 spec:
+ *
+ * "The bitwise operators and (&), exclusive-or (^), and inclusive-or
+ * (|). The operands must be of type signed or unsigned integers or
+ * integer vectors."
+ */
+ if (!type_a->is_integer()) {
+ _mesa_glsl_error(loc, state, "LHS of `%s' must be an integer",
+ ast_expression::operator_string(op));
+ return glsl_type::error_type;
+ }
+ if (!type_b->is_integer()) {
+ _mesa_glsl_error(loc, state, "RHS of `%s' must be an integer",
+ ast_expression::operator_string(op));
+ return glsl_type::error_type;
+ }
+
+ /* "The fundamental types of the operands (signed or unsigned) must
+ * match,"
+ */
+ if (type_a->base_type != type_b->base_type) {
+ _mesa_glsl_error(loc, state, "operands of `%s' must have the same "
+ "base type", ast_expression::operator_string(op));
+ return glsl_type::error_type;
+ }
+
+ /* "The operands cannot be vectors of differing size." */
+ if (type_a->is_vector() &&
+ type_b->is_vector() &&
+ type_a->vector_elements != type_b->vector_elements) {
+ _mesa_glsl_error(loc, state, "operands of `%s' cannot be vectors of "
+ "different sizes", ast_expression::operator_string(op));
+ return glsl_type::error_type;
+ }
+
+ /* "If one operand is a scalar and the other a vector, the scalar is
+ * applied component-wise to the vector, resulting in the same type as
+ * the vector. The fundamental types of the operands [...] will be the
+ * resulting fundamental type."
+ */
+ if (type_a->is_scalar())
+ return type_b;
+ else
+ return type_a;
+}
+
+static const struct glsl_type *
+modulus_result_type(const struct glsl_type *type_a,
+ const struct glsl_type *type_b,
+ struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
+{
+ if (state->language_version < 130) {
+ _mesa_glsl_error(loc, state,
+ "operator '%%' is reserved in %s",
+ state->version_string);
+ return glsl_type::error_type;
+ }
+
+ /* From GLSL 1.50 spec, page 56:
+ * "The operator modulus (%) operates on signed or unsigned integers or
+ * integer vectors. The operand types must both be signed or both be
+ * unsigned."
+ */
+ if (!type_a->is_integer() || !type_b->is_integer()
+ || (type_a->base_type != type_b->base_type)) {
+ _mesa_glsl_error(loc, state, "type mismatch");
+ return glsl_type::error_type;
+ }
+
+ /* "The operands cannot be vectors of differing size. If one operand is
+ * a scalar and the other vector, then the scalar is applied component-
+ * wise to the vector, resulting in the same type as the vector. If both
+ * are vectors of the same size, the result is computed component-wise."
+ */
+ if (type_a->is_vector()) {
+ if (!type_b->is_vector()
+ || (type_a->vector_elements == type_b->vector_elements))
+ return type_a;
+ } else
+ return type_b;
+
+ /* "The operator modulus (%) is not defined for any other data types
+ * (non-integer types)."
+ */
+ _mesa_glsl_error(loc, state, "type mismatch");
+ return glsl_type::error_type;
+}
+
+
+static const struct glsl_type *
+relational_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
+ struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
+{
+ const glsl_type *type_a = value_a->type;
+ const glsl_type *type_b = value_b->type;
+
+ /* From GLSL 1.50 spec, page 56:
+ * "The relational operators greater than (>), less than (<), greater
+ * than or equal (>=), and less than or equal (<=) operate only on
+ * scalar integer and scalar floating-point expressions."
+ */
+ if (!type_a->is_numeric()
+ || !type_b->is_numeric()
+ || !type_a->is_scalar()
+ || !type_b->is_scalar()) {
+ _mesa_glsl_error(loc, state,
+ "Operands to relational operators must be scalar and "
+ "numeric");
+ return glsl_type::error_type;
+ }
+
+ /* "Either the operands' types must match, or the conversions from
+ * Section 4.1.10 "Implicit Conversions" will be applied to the integer
+ * operand, after which the types must match."
+ */
+ if (!apply_implicit_conversion(type_a, value_b, state)
+ && !apply_implicit_conversion(type_b, value_a, state)) {
+ _mesa_glsl_error(loc, state,
+ "Could not implicitly convert operands to "
+ "relational operator");
+ return glsl_type::error_type;
+ }
+ type_a = value_a->type;
+ type_b = value_b->type;
+
+ if (type_a->base_type != type_b->base_type) {
+ _mesa_glsl_error(loc, state, "base type mismatch");
+ return glsl_type::error_type;
+ }
+
+ /* "The result is scalar Boolean."
+ */
+ return glsl_type::bool_type;
+}
+
+/**
+ * \brief Return the result type of a bit-shift operation.
+ *
+ * If the given types to the bit-shift operator are invalid, return
+ * glsl_type::error_type.
+ *
+ * \param type_a Type of LHS of bit-shift op
+ * \param type_b Type of RHS of bit-shift op
+ */
+static const struct glsl_type *
+shift_result_type(const struct glsl_type *type_a,
+ const struct glsl_type *type_b,
+ ast_operators op,
+ struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
+{
+ if (state->language_version < 130) {
+ _mesa_glsl_error(loc, state, "bit operations require GLSL 1.30");
+ return glsl_type::error_type;
+ }
+
+ /* From page 50 (page 56 of the PDF) of the GLSL 1.30 spec:
+ *
+ * "The shift operators (<<) and (>>). For both operators, the operands
+ * must be signed or unsigned integers or integer vectors. One operand
+ * can be signed while the other is unsigned."
+ */
+ if (!type_a->is_integer()) {
+ _mesa_glsl_error(loc, state, "LHS of operator %s must be an integer or "
+ "integer vector", ast_expression::operator_string(op));
+ return glsl_type::error_type;
+
+ }
+ if (!type_b->is_integer()) {
+ _mesa_glsl_error(loc, state, "RHS of operator %s must be an integer or "
+ "integer vector", ast_expression::operator_string(op));
+ return glsl_type::error_type;
+ }
+
+ /* "If the first operand is a scalar, the second operand has to be
+ * a scalar as well."
+ */
+ if (type_a->is_scalar() && !type_b->is_scalar()) {
+ _mesa_glsl_error(loc, state, "If the first operand of %s is scalar, the "
+ "second must be scalar as well",
+ ast_expression::operator_string(op));
+ return glsl_type::error_type;
+ }
+
+ /* If both operands are vectors, check that they have same number of
+ * elements.
+ */
+ if (type_a->is_vector() &&
+ type_b->is_vector() &&
+ type_a->vector_elements != type_b->vector_elements) {
+ _mesa_glsl_error(loc, state, "Vector operands to operator %s must "
+ "have same number of elements",
+ ast_expression::operator_string(op));
+ return glsl_type::error_type;
+ }
+
+ /* "In all cases, the resulting type will be the same type as the left
+ * operand."
+ */
+ return type_a;
+}
+
+/**
+ * Validates that a value can be assigned to a location with a specified type
+ *
+ * Validates that \c rhs can be assigned to some location. If the types are
+ * not an exact match but an automatic conversion is possible, \c rhs will be
+ * converted.
+ *
+ * \return
+ * \c NULL if \c rhs cannot be assigned to a location with type \c lhs_type.
+ * Otherwise the actual RHS to be assigned will be returned. This may be
+ * \c rhs, or it may be \c rhs after some type conversion.
+ *
+ * \note
+ * In addition to being used for assignments, this function is used to
+ * type-check return values.
+ */
+ir_rvalue *
+validate_assignment(struct _mesa_glsl_parse_state *state,
+ const glsl_type *lhs_type, ir_rvalue *rhs)
+{
+ /* If there is already some error in the RHS, just return it. Anything
+ * else will lead to an avalanche of error message back to the user.
+ */
+ if (rhs->type->is_error())
+ return rhs;
+
+ /* If the types are identical, the assignment can trivially proceed.
+ */
+ if (rhs->type == lhs_type)
+ return rhs;
+
+ /* If the array element types are the same and the size of the LHS is zero,
+ * the assignment is okay.
+ *
+ * Note: Whole-array assignments are not permitted in GLSL 1.10, but this
+ * is handled by ir_dereference::is_lvalue.
+ */
+ if (lhs_type->is_array() && rhs->type->is_array()
+ && (lhs_type->element_type() == rhs->type->element_type())
+ && (lhs_type->array_size() == 0)) {
+ return rhs;
+ }
+
+ /* Check for implicit conversion in GLSL 1.20 */
+ if (apply_implicit_conversion(lhs_type, rhs, state)) {
+ if (rhs->type == lhs_type)
+ return rhs;
+ }
+
+ return NULL;
+}
+
+ir_rvalue *
+do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
+ ir_rvalue *lhs, ir_rvalue *rhs,
+ YYLTYPE lhs_loc)
+{
+ void *ctx = state;
+ bool error_emitted = (lhs->type->is_error() || rhs->type->is_error());
+
+ if (!error_emitted) {
+ if (lhs->variable_referenced() != NULL
+ && lhs->variable_referenced()->read_only) {
+ _mesa_glsl_error(&lhs_loc, state,
+ "assignment to read-only variable '%s'",
+ lhs->variable_referenced()->name);
+ error_emitted = true;
+
+ } else if (!lhs->is_lvalue()) {
+ _mesa_glsl_error(& lhs_loc, state, "non-lvalue in assignment");
+ error_emitted = true;
+ }
+
+ if (state->es_shader && lhs->type->is_array()) {
+ _mesa_glsl_error(&lhs_loc, state, "whole array assignment is not "
+ "allowed in GLSL ES 1.00.");
+ error_emitted = true;
+ }
+ }
+
+ ir_rvalue *new_rhs = validate_assignment(state, lhs->type, rhs);
+ if (new_rhs == NULL) {
+ _mesa_glsl_error(& lhs_loc, state, "type mismatch");
+ } else {
+ rhs = new_rhs;
+
+ /* If the LHS array was not declared with a size, it takes it size from
+ * the RHS. If the LHS is an l-value and a whole array, it must be a
+ * dereference of a variable. Any other case would require that the LHS
+ * is either not an l-value or not a whole array.
+ */
+ if (lhs->type->array_size() == 0) {
+ ir_dereference *const d = lhs->as_dereference();
+
+ assert(d != NULL);
+
+ ir_variable *const var = d->variable_referenced();
+
+ assert(var != NULL);
+
+ if (var->max_array_access >= unsigned(rhs->type->array_size())) {
+ /* FINISHME: This should actually log the location of the RHS. */
+ _mesa_glsl_error(& lhs_loc, state, "array size must be > %u due to "
+ "previous access",
+ var->max_array_access);
+ }
+
+ var->type = glsl_type::get_array_instance(lhs->type->element_type(),
+ rhs->type->array_size());
+ d->type = var->type;
+ }
+ }
+
+ /* Most callers of do_assignment (assign, add_assign, pre_inc/dec,
+ * but not post_inc) need the converted assigned value as an rvalue
+ * to handle things like:
+ *
+ * i = j += 1;
+ *
+ * So we always just store the computed value being assigned to a
+ * temporary and return a deref of that temporary. If the rvalue
+ * ends up not being used, the temp will get copy-propagated out.
+ */
+ ir_variable *var = new(ctx) ir_variable(rhs->type, "assignment_tmp",
+ ir_var_temporary);
+ ir_dereference_variable *deref_var = new(ctx) ir_dereference_variable(var);
+ instructions->push_tail(var);
+ instructions->push_tail(new(ctx) ir_assignment(deref_var,
+ rhs,
+ NULL));
+ deref_var = new(ctx) ir_dereference_variable(var);
+
+ if (!error_emitted)
+ instructions->push_tail(new(ctx) ir_assignment(lhs, deref_var, NULL));
+
+ return new(ctx) ir_dereference_variable(var);
+}
+
+static ir_rvalue *
+get_lvalue_copy(exec_list *instructions, ir_rvalue *lvalue)
+{
+ void *ctx = ralloc_parent(lvalue);
+ ir_variable *var;
+
+ var = new(ctx) ir_variable(lvalue->type, "_post_incdec_tmp",
+ ir_var_temporary);
+ instructions->push_tail(var);
+ var->mode = ir_var_auto;
+
+ instructions->push_tail(new(ctx) ir_assignment(new(ctx) ir_dereference_variable(var),
+ lvalue, NULL));
+
+ /* Once we've created this temporary, mark it read only so it's no
+ * longer considered an lvalue.
+ */
+ var->read_only = true;
+
+ return new(ctx) ir_dereference_variable(var);
+}
+
+
+ir_rvalue *
+ast_node::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ (void) instructions;
+ (void) state;
+
+ return NULL;
+}
+
+static void
+mark_whole_array_access(ir_rvalue *access)
+{
+ ir_dereference_variable *deref = access->as_dereference_variable();
+
+ if (deref) {
+ deref->var->max_array_access = deref->type->length - 1;
+ }
+}
+
+static ir_rvalue *
+do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
+{
+ int join_op;
+ ir_rvalue *cmp = NULL;
+
+ if (operation == ir_binop_all_equal)
+ join_op = ir_binop_logic_and;
+ else
+ join_op = ir_binop_logic_or;
+
+ switch (op0->type->base_type) {
+ case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT:
+ case GLSL_TYPE_BOOL:
+ return new(mem_ctx) ir_expression(operation, op0, op1);
+
+ case GLSL_TYPE_ARRAY: {
+ for (unsigned int i = 0; i < op0->type->length; i++) {
+ ir_rvalue *e0, *e1, *result;
+
+ e0 = new(mem_ctx) ir_dereference_array(op0->clone(mem_ctx, NULL),
+ new(mem_ctx) ir_constant(i));
+ e1 = new(mem_ctx) ir_dereference_array(op1->clone(mem_ctx, NULL),
+ new(mem_ctx) ir_constant(i));
+ result = do_comparison(mem_ctx, operation, e0, e1);
+
+ if (cmp) {
+ cmp = new(mem_ctx) ir_expression(join_op, cmp, result);
+ } else {
+ cmp = result;
+ }
+ }
+
+ mark_whole_array_access(op0);
+ mark_whole_array_access(op1);
+ break;
+ }
+
+ case GLSL_TYPE_STRUCT: {
+ for (unsigned int i = 0; i < op0->type->length; i++) {
+ ir_rvalue *e0, *e1, *result;
+ const char *field_name = op0->type->fields.structure[i].name;
+
+ e0 = new(mem_ctx) ir_dereference_record(op0->clone(mem_ctx, NULL),
+ field_name);
+ e1 = new(mem_ctx) ir_dereference_record(op1->clone(mem_ctx, NULL),
+ field_name);
+ result = do_comparison(mem_ctx, operation, e0, e1);
+
+ if (cmp) {
+ cmp = new(mem_ctx) ir_expression(join_op, cmp, result);
+ } else {
+ cmp = result;
+ }
+ }
+ break;
+ }
+
+ case GLSL_TYPE_ERROR:
+ case GLSL_TYPE_VOID:
+ case GLSL_TYPE_SAMPLER:
+ /* I assume a comparison of a struct containing a sampler just
+ * ignores the sampler present in the type.
+ */
+ break;
+
+ default:
+ assert(!"Should not get here.");
+ break;
+ }
+
+ if (cmp == NULL)
+ cmp = new(mem_ctx) ir_constant(true);
+
+ return cmp;
+}
+
+ir_rvalue *
+ast_expression::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+ static const int operations[AST_NUM_OPERATORS] = {
+ -1, /* ast_assign doesn't convert to ir_expression. */
+ -1, /* ast_plus doesn't convert to ir_expression. */
+ ir_unop_neg,
+ ir_binop_add,
+ ir_binop_sub,
+ ir_binop_mul,
+ ir_binop_div,
+ ir_binop_mod,
+ ir_binop_lshift,
+ ir_binop_rshift,
+ ir_binop_less,
+ ir_binop_greater,
+ ir_binop_lequal,
+ ir_binop_gequal,
+ ir_binop_all_equal,
+ ir_binop_any_nequal,
+ ir_binop_bit_and,
+ ir_binop_bit_xor,
+ ir_binop_bit_or,
+ ir_unop_bit_not,
+ ir_binop_logic_and,
+ ir_binop_logic_xor,
+ ir_binop_logic_or,
+ ir_unop_logic_not,
+
+ /* Note: The following block of expression types actually convert
+ * to multiple IR instructions.
+ */
+ ir_binop_mul, /* ast_mul_assign */
+ ir_binop_div, /* ast_div_assign */
+ ir_binop_mod, /* ast_mod_assign */
+ ir_binop_add, /* ast_add_assign */
+ ir_binop_sub, /* ast_sub_assign */
+ ir_binop_lshift, /* ast_ls_assign */
+ ir_binop_rshift, /* ast_rs_assign */
+ ir_binop_bit_and, /* ast_and_assign */
+ ir_binop_bit_xor, /* ast_xor_assign */
+ ir_binop_bit_or, /* ast_or_assign */
+
+ -1, /* ast_conditional doesn't convert to ir_expression. */
+ ir_binop_add, /* ast_pre_inc. */
+ ir_binop_sub, /* ast_pre_dec. */
+ ir_binop_add, /* ast_post_inc. */
+ ir_binop_sub, /* ast_post_dec. */
+ -1, /* ast_field_selection doesn't conv to ir_expression. */
+ -1, /* ast_array_index doesn't convert to ir_expression. */
+ -1, /* ast_function_call doesn't conv to ir_expression. */
+ -1, /* ast_identifier doesn't convert to ir_expression. */
+ -1, /* ast_int_constant doesn't convert to ir_expression. */
+ -1, /* ast_uint_constant doesn't conv to ir_expression. */
+ -1, /* ast_float_constant doesn't conv to ir_expression. */
+ -1, /* ast_bool_constant doesn't conv to ir_expression. */
+ -1, /* ast_sequence doesn't convert to ir_expression. */
+ };
+ ir_rvalue *result = NULL;
+ ir_rvalue *op[3];
+ const struct glsl_type *type = glsl_type::error_type;
+ bool error_emitted = false;
+ YYLTYPE loc;
+
+ loc = this->get_location();
+
+ switch (this->oper) {
+ case ast_assign: {
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+
+ result = do_assignment(instructions, state, op[0], op[1],
+ this->subexpressions[0]->get_location());
+ error_emitted = result->type->is_error();
+ type = result->type;
+ break;
+ }
+
+ case ast_plus:
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+
+ type = unary_arithmetic_result_type(op[0]->type, state, & loc);
+
+ error_emitted = type->is_error();
+
+ result = op[0];
+ break;
+
+ case ast_neg:
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+
+ type = unary_arithmetic_result_type(op[0]->type, state, & loc);
+
+ error_emitted = type->is_error();
+
+ result = new(ctx) ir_expression(operations[this->oper], type,
+ op[0], NULL);
+ break;
+
+ case ast_add:
+ case ast_sub:
+ case ast_mul:
+ case ast_div:
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+
+ type = arithmetic_result_type(op[0], op[1],
+ (this->oper == ast_mul),
+ state, & loc);
+ error_emitted = type->is_error();
+
+ result = new(ctx) ir_expression(operations[this->oper], type,
+ op[0], op[1]);
+ break;
+
+ case ast_mod:
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+
+ type = modulus_result_type(op[0]->type, op[1]->type, state, & loc);
+
+ assert(operations[this->oper] == ir_binop_mod);
+
+ result = new(ctx) ir_expression(operations[this->oper], type,
+ op[0], op[1]);
+ error_emitted = type->is_error();
+ break;
+
+ case ast_lshift:
+ case ast_rshift:
+ if (state->language_version < 130) {
+ _mesa_glsl_error(&loc, state, "operator %s requires GLSL 1.30",
+ operator_string(this->oper));
+ error_emitted = true;
+ }
+
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+ type = shift_result_type(op[0]->type, op[1]->type, this->oper, state,
+ &loc);
+ result = new(ctx) ir_expression(operations[this->oper], type,
+ op[0], op[1]);
+ error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
+ break;
+
+ case ast_less:
+ case ast_greater:
+ case ast_lequal:
+ case ast_gequal:
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+
+ type = relational_result_type(op[0], op[1], state, & loc);
+
+ /* The relational operators must either generate an error or result
+ * in a scalar boolean. See page 57 of the GLSL 1.50 spec.
+ */
+ assert(type->is_error()
+ || ((type->base_type == GLSL_TYPE_BOOL)
+ && type->is_scalar()));
+
+ result = new(ctx) ir_expression(operations[this->oper], type,
+ op[0], op[1]);
+ error_emitted = type->is_error();
+ break;
+
+ case ast_nequal:
+ case ast_equal:
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+
+ /* From page 58 (page 64 of the PDF) of the GLSL 1.50 spec:
+ *
+ * "The equality operators equal (==), and not equal (!=)
+ * operate on all types. They result in a scalar Boolean. If
+ * the operand types do not match, then there must be a
+ * conversion from Section 4.1.10 "Implicit Conversions"
+ * applied to one operand that can make them match, in which
+ * case this conversion is done."
+ */
+ if ((!apply_implicit_conversion(op[0]->type, op[1], state)
+ && !apply_implicit_conversion(op[1]->type, op[0], state))
+ || (op[0]->type != op[1]->type)) {
+ _mesa_glsl_error(& loc, state, "operands of `%s' must have the same "
+ "type", (this->oper == ast_equal) ? "==" : "!=");
+ error_emitted = true;
+ } else if ((state->language_version <= 110)
+ && (op[0]->type->is_array() || op[1]->type->is_array())) {
+ _mesa_glsl_error(& loc, state, "array comparisons forbidden in "
+ "GLSL 1.10");
+ error_emitted = true;
+ }
+
+ result = do_comparison(ctx, operations[this->oper], op[0], op[1]);
+ type = glsl_type::bool_type;
+
+ assert(error_emitted || (result->type == glsl_type::bool_type));
+ break;
+
+ case ast_bit_and:
+ case ast_bit_xor:
+ case ast_bit_or:
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+ type = bit_logic_result_type(op[0]->type, op[1]->type, this->oper,
+ state, &loc);
+ result = new(ctx) ir_expression(operations[this->oper], type,
+ op[0], op[1]);
+ error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
+ break;
+
+ case ast_bit_not:
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+
+ if (state->language_version < 130) {
+ _mesa_glsl_error(&loc, state, "bit-wise operations require GLSL 1.30");
+ error_emitted = true;
+ }
+
+ if (!op[0]->type->is_integer()) {
+ _mesa_glsl_error(&loc, state, "operand of `~' must be an integer");
+ error_emitted = true;
+ }
+
+ type = op[0]->type;
+ result = new(ctx) ir_expression(ir_unop_bit_not, type, op[0], NULL);
+ break;
+
+ case ast_logic_and: {
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+
+ if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
+ YYLTYPE loc = this->subexpressions[0]->get_location();
+
+ _mesa_glsl_error(& loc, state, "LHS of `%s' must be scalar boolean",
+ operator_string(this->oper));
+ error_emitted = true;
+ }
+
+ ir_constant *op0_const = op[0]->constant_expression_value();
+ if (op0_const) {
+ if (op0_const->value.b[0]) {
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+
+ if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
+ YYLTYPE loc = this->subexpressions[1]->get_location();
+
+ _mesa_glsl_error(& loc, state,
+ "RHS of `%s' must be scalar boolean",
+ operator_string(this->oper));
+ error_emitted = true;
+ }
+ result = op[1];
+ } else {
+ result = op0_const;
+ }
+ type = glsl_type::bool_type;
+ } else {
+ ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type,
+ "and_tmp",
+ ir_var_temporary);
+ instructions->push_tail(tmp);
+
+ ir_if *const stmt = new(ctx) ir_if(op[0]);
+ instructions->push_tail(stmt);
+
+ op[1] = this->subexpressions[1]->hir(&stmt->then_instructions, state);
+
+ if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
+ YYLTYPE loc = this->subexpressions[1]->get_location();
+
+ _mesa_glsl_error(& loc, state,
+ "RHS of `%s' must be scalar boolean",
+ operator_string(this->oper));
+ error_emitted = true;
+ }
+
+ ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp);
+ ir_assignment *const then_assign =
+ new(ctx) ir_assignment(then_deref, op[1], NULL);
+ stmt->then_instructions.push_tail(then_assign);
+
+ ir_dereference *const else_deref = new(ctx) ir_dereference_variable(tmp);
+ ir_assignment *const else_assign =
+ new(ctx) ir_assignment(else_deref, new(ctx) ir_constant(false), NULL);
+ stmt->else_instructions.push_tail(else_assign);
+
+ result = new(ctx) ir_dereference_variable(tmp);
+ type = tmp->type;
+ }
+ break;
+ }
+
+ case ast_logic_or: {
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+
+ if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
+ YYLTYPE loc = this->subexpressions[0]->get_location();
+
+ _mesa_glsl_error(& loc, state, "LHS of `%s' must be scalar boolean",
+ operator_string(this->oper));
+ error_emitted = true;
+ }
+
+ ir_constant *op0_const = op[0]->constant_expression_value();
+ if (op0_const) {
+ if (op0_const->value.b[0]) {
+ result = op0_const;
+ } else {
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+
+ if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
+ YYLTYPE loc = this->subexpressions[1]->get_location();
+
+ _mesa_glsl_error(& loc, state,
+ "RHS of `%s' must be scalar boolean",
+ operator_string(this->oper));
+ error_emitted = true;
+ }
+ result = op[1];
+ }
+ type = glsl_type::bool_type;
+ } else {
+ ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type,
+ "or_tmp",
+ ir_var_temporary);
+ instructions->push_tail(tmp);
+
+ ir_if *const stmt = new(ctx) ir_if(op[0]);
+ instructions->push_tail(stmt);
+
+ op[1] = this->subexpressions[1]->hir(&stmt->else_instructions, state);
+
+ if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
+ YYLTYPE loc = this->subexpressions[1]->get_location();
+
+ _mesa_glsl_error(& loc, state, "RHS of `%s' must be scalar boolean",
+ operator_string(this->oper));
+ error_emitted = true;
+ }
+
+ ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp);
+ ir_assignment *const then_assign =
+ new(ctx) ir_assignment(then_deref, new(ctx) ir_constant(true), NULL);
+ stmt->then_instructions.push_tail(then_assign);
+
+ ir_dereference *const else_deref = new(ctx) ir_dereference_variable(tmp);
+ ir_assignment *const else_assign =
+ new(ctx) ir_assignment(else_deref, op[1], NULL);
+ stmt->else_instructions.push_tail(else_assign);
+
+ result = new(ctx) ir_dereference_variable(tmp);
+ type = tmp->type;
+ }
+ break;
+ }
+
+ case ast_logic_xor:
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+
+
+ result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type,
+ op[0], op[1]);
+ type = glsl_type::bool_type;
+ break;
+
+ case ast_logic_not:
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+
+ if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
+ YYLTYPE loc = this->subexpressions[0]->get_location();
+
+ _mesa_glsl_error(& loc, state,
+ "operand of `!' must be scalar boolean");
+ error_emitted = true;
+ }
+
+ result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type,
+ op[0], NULL);
+ type = glsl_type::bool_type;
+ break;
+
+ case ast_mul_assign:
+ case ast_div_assign:
+ case ast_add_assign:
+ case ast_sub_assign: {
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+
+ type = arithmetic_result_type(op[0], op[1],
+ (this->oper == ast_mul_assign),
+ state, & loc);
+
+ ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper], type,
+ op[0], op[1]);
+
+ result = do_assignment(instructions, state,
+ op[0]->clone(ctx, NULL), temp_rhs,
+ this->subexpressions[0]->get_location());
+ type = result->type;
+ error_emitted = (op[0]->type->is_error());
+
+ /* GLSL 1.10 does not allow array assignment. However, we don't have to
+ * explicitly test for this because none of the binary expression
+ * operators allow array operands either.
+ */
+
+ break;
+ }
+
+ case ast_mod_assign: {
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+
+ type = modulus_result_type(op[0]->type, op[1]->type, state, & loc);
+
+ assert(operations[this->oper] == ir_binop_mod);
+
+ ir_rvalue *temp_rhs;
+ temp_rhs = new(ctx) ir_expression(operations[this->oper], type,
+ op[0], op[1]);
+
+ result = do_assignment(instructions, state,
+ op[0]->clone(ctx, NULL), temp_rhs,
+ this->subexpressions[0]->get_location());
+ type = result->type;
+ error_emitted = type->is_error();
+ break;
+ }
+
+ case ast_ls_assign:
+ case ast_rs_assign: {
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+ type = shift_result_type(op[0]->type, op[1]->type, this->oper, state,
+ &loc);
+ ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper],
+ type, op[0], op[1]);
+ result = do_assignment(instructions, state, op[0]->clone(ctx, NULL),
+ temp_rhs,
+ this->subexpressions[0]->get_location());
+ error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
+ break;
+ }
+
+ case ast_and_assign:
+ case ast_xor_assign:
+ case ast_or_assign: {
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ op[1] = this->subexpressions[1]->hir(instructions, state);
+ type = bit_logic_result_type(op[0]->type, op[1]->type, this->oper,
+ state, &loc);
+ ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper],
+ type, op[0], op[1]);
+ result = do_assignment(instructions, state, op[0]->clone(ctx, NULL),
+ temp_rhs,
+ this->subexpressions[0]->get_location());
+ error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
+ break;
+ }
+
+ case ast_conditional: {
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+
+ /* From page 59 (page 65 of the PDF) of the GLSL 1.50 spec:
+ *
+ * "The ternary selection operator (?:). It operates on three
+ * expressions (exp1 ? exp2 : exp3). This operator evaluates the
+ * first expression, which must result in a scalar Boolean."
+ */
+ if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
+ YYLTYPE loc = this->subexpressions[0]->get_location();
+
+ _mesa_glsl_error(& loc, state, "?: condition must be scalar boolean");
+ error_emitted = true;
+ }
+
+ /* The :? operator is implemented by generating an anonymous temporary
+ * followed by an if-statement. The last instruction in each branch of
+ * the if-statement assigns a value to the anonymous temporary. This
+ * temporary is the r-value of the expression.
+ */
+ exec_list then_instructions;
+ exec_list else_instructions;
+
+ op[1] = this->subexpressions[1]->hir(&then_instructions, state);
+ op[2] = this->subexpressions[2]->hir(&else_instructions, state);
+
+ /* From page 59 (page 65 of the PDF) of the GLSL 1.50 spec:
+ *
+ * "The second and third expressions can be any type, as
+ * long their types match, or there is a conversion in
+ * Section 4.1.10 "Implicit Conversions" that can be applied
+ * to one of the expressions to make their types match. This
+ * resulting matching type is the type of the entire
+ * expression."
+ */
+ if ((!apply_implicit_conversion(op[1]->type, op[2], state)
+ && !apply_implicit_conversion(op[2]->type, op[1], state))
+ || (op[1]->type != op[2]->type)) {
+ YYLTYPE loc = this->subexpressions[1]->get_location();
+
+ _mesa_glsl_error(& loc, state, "Second and third operands of ?: "
+ "operator must have matching types.");
+ error_emitted = true;
+ type = glsl_type::error_type;
+ } else {
+ type = op[1]->type;
+ }
+
+ /* From page 33 (page 39 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "The second and third expressions must be the same type, but can
+ * be of any type other than an array."
+ */
+ if ((state->language_version <= 110) && type->is_array()) {
+ _mesa_glsl_error(& loc, state, "Second and third operands of ?: "
+ "operator must not be arrays.");
+ error_emitted = true;
+ }
+
+ ir_constant *cond_val = op[0]->constant_expression_value();
+ ir_constant *then_val = op[1]->constant_expression_value();
+ ir_constant *else_val = op[2]->constant_expression_value();
+
+ if (then_instructions.is_empty()
+ && else_instructions.is_empty()
+ && (cond_val != NULL) && (then_val != NULL) && (else_val != NULL)) {
+ result = (cond_val->value.b[0]) ? then_val : else_val;
+ } else {
+ ir_variable *const tmp =
+ new(ctx) ir_variable(type, "conditional_tmp", ir_var_temporary);
+ instructions->push_tail(tmp);
+
+ ir_if *const stmt = new(ctx) ir_if(op[0]);
+ instructions->push_tail(stmt);
+
+ then_instructions.move_nodes_to(& stmt->then_instructions);
+ ir_dereference *const then_deref =
+ new(ctx) ir_dereference_variable(tmp);
+ ir_assignment *const then_assign =
+ new(ctx) ir_assignment(then_deref, op[1], NULL);
+ stmt->then_instructions.push_tail(then_assign);
+
+ else_instructions.move_nodes_to(& stmt->else_instructions);
+ ir_dereference *const else_deref =
+ new(ctx) ir_dereference_variable(tmp);
+ ir_assignment *const else_assign =
+ new(ctx) ir_assignment(else_deref, op[2], NULL);
+ stmt->else_instructions.push_tail(else_assign);
+
+ result = new(ctx) ir_dereference_variable(tmp);
+ }
+ break;
+ }
+
+ case ast_pre_inc:
+ case ast_pre_dec: {
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ if (op[0]->type->base_type == GLSL_TYPE_FLOAT)
+ op[1] = new(ctx) ir_constant(1.0f);
+ else
+ op[1] = new(ctx) ir_constant(1);
+
+ type = arithmetic_result_type(op[0], op[1], false, state, & loc);
+
+ ir_rvalue *temp_rhs;
+ temp_rhs = new(ctx) ir_expression(operations[this->oper], type,
+ op[0], op[1]);
+
+ result = do_assignment(instructions, state,
+ op[0]->clone(ctx, NULL), temp_rhs,
+ this->subexpressions[0]->get_location());
+ type = result->type;
+ error_emitted = op[0]->type->is_error();
+ break;
+ }
+
+ case ast_post_inc:
+ case ast_post_dec: {
+ op[0] = this->subexpressions[0]->hir(instructions, state);
+ if (op[0]->type->base_type == GLSL_TYPE_FLOAT)
+ op[1] = new(ctx) ir_constant(1.0f);
+ else
+ op[1] = new(ctx) ir_constant(1);
+
+ error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
+
+ type = arithmetic_result_type(op[0], op[1], false, state, & loc);
+
+ ir_rvalue *temp_rhs;
+ temp_rhs = new(ctx) ir_expression(operations[this->oper], type,
+ op[0], op[1]);
+
+ /* Get a temporary of a copy of the lvalue before it's modified.
+ * This may get thrown away later.
+ */
+ result = get_lvalue_copy(instructions, op[0]->clone(ctx, NULL));
+
+ (void)do_assignment(instructions, state,
+ op[0]->clone(ctx, NULL), temp_rhs,
+ this->subexpressions[0]->get_location());
+
+ type = result->type;
+ error_emitted = op[0]->type->is_error();
+ break;
+ }
+
+ case ast_field_selection:
+ result = _mesa_ast_field_selection_to_hir(this, instructions, state);
+ type = result->type;
+ break;
+
+ case ast_array_index: {
+ YYLTYPE index_loc = subexpressions[1]->get_location();
+
+ op[0] = subexpressions[0]->hir(instructions, state);
+ op[1] = subexpressions[1]->hir(instructions, state);
+
+ error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
+
+ ir_rvalue *const array = op[0];
+
+ result = new(ctx) ir_dereference_array(op[0], op[1]);
+
+ /* Do not use op[0] after this point. Use array.
+ */
+ op[0] = NULL;
+
+
+ if (error_emitted)
+ break;
+
+ if (!array->type->is_array()
+ && !array->type->is_matrix()
+ && !array->type->is_vector()) {
+ _mesa_glsl_error(& index_loc, state,
+ "cannot dereference non-array / non-matrix / "
+ "non-vector");
+ error_emitted = true;
+ }
+
+ if (!op[1]->type->is_integer()) {
+ _mesa_glsl_error(& index_loc, state,
+ "array index must be integer type");
+ error_emitted = true;
+ } else if (!op[1]->type->is_scalar()) {
+ _mesa_glsl_error(& index_loc, state,
+ "array index must be scalar");
+ error_emitted = true;
+ }
+
+ /* If the array index is a constant expression and the array has a
+ * declared size, ensure that the access is in-bounds. If the array
+ * index is not a constant expression, ensure that the array has a
+ * declared size.
+ */
+ ir_constant *const const_index = op[1]->constant_expression_value();
+ if (const_index != NULL) {
+ const int idx = const_index->value.i[0];
+ const char *type_name;
+ unsigned bound = 0;
+
+ if (array->type->is_matrix()) {
+ type_name = "matrix";
+ } else if (array->type->is_vector()) {
+ type_name = "vector";
+ } else {
+ type_name = "array";
+ }
+
+ /* From page 24 (page 30 of the PDF) of the GLSL 1.50 spec:
+ *
+ * "It is illegal to declare an array with a size, and then
+ * later (in the same shader) index the same array with an
+ * integral constant expression greater than or equal to the
+ * declared size. It is also illegal to index an array with a
+ * negative constant expression."
+ */
+ if (array->type->is_matrix()) {
+ if (array->type->row_type()->vector_elements <= idx) {
+ bound = array->type->row_type()->vector_elements;
+ }
+ } else if (array->type->is_vector()) {
+ if (array->type->vector_elements <= idx) {
+ bound = array->type->vector_elements;
+ }
+ } else {
+ if ((array->type->array_size() > 0)
+ && (array->type->array_size() <= idx)) {
+ bound = array->type->array_size();
+ }
+ }
+
+ if (bound > 0) {
+ _mesa_glsl_error(& loc, state, "%s index must be < %u",
+ type_name, bound);
+ error_emitted = true;
+ } else if (idx < 0) {
+ _mesa_glsl_error(& loc, state, "%s index must be >= 0",
+ type_name);
+ error_emitted = true;
+ }
+
+ if (array->type->is_array()) {
+ /* If the array is a variable dereference, it dereferences the
+ * whole array, by definition. Use this to get the variable.
+ *
+ * FINISHME: Should some methods for getting / setting / testing
+ * FINISHME: array access limits be added to ir_dereference?
+ */
+ ir_variable *const v = array->whole_variable_referenced();
+ if ((v != NULL) && (unsigned(idx) > v->max_array_access))
+ v->max_array_access = idx;
+ }
+ } else if (array->type->array_size() == 0) {
+ _mesa_glsl_error(&loc, state, "unsized array index must be constant");
+ } else {
+ if (array->type->is_array()) {
+ /* whole_variable_referenced can return NULL if the array is a
+ * member of a structure. In this case it is safe to not update
+ * the max_array_access field because it is never used for fields
+ * of structures.
+ */
+ ir_variable *v = array->whole_variable_referenced();
+ if (v != NULL)
+ v->max_array_access = array->type->array_size();
+ }
+ }
+
+ /* From page 23 (29 of the PDF) of the GLSL 1.30 spec:
+ *
+ * "Samplers aggregated into arrays within a shader (using square
+ * brackets [ ]) can only be indexed with integral constant
+ * expressions [...]."
+ *
+ * This restriction was added in GLSL 1.30. Shaders using earlier version
+ * of the language should not be rejected by the compiler front-end for
+ * using this construct. This allows useful things such as using a loop
+ * counter as the index to an array of samplers. If the loop in unrolled,
+ * the code should compile correctly. Instead, emit a warning.
+ */
+ if (array->type->is_array() &&
+ array->type->element_type()->is_sampler() &&
+ const_index == NULL) {
+
+ if (state->language_version == 100) {
+ _mesa_glsl_warning(&loc, state,
+ "sampler arrays indexed with non-constant "
+ "expressions is optional in GLSL ES 1.00");
+ } else if (state->language_version < 130) {
+ _mesa_glsl_warning(&loc, state,
+ "sampler arrays indexed with non-constant "
+ "expressions is forbidden in GLSL 1.30 and "
+ "later");
+ } else {
+ _mesa_glsl_error(&loc, state,
+ "sampler arrays indexed with non-constant "
+ "expressions is forbidden in GLSL 1.30 and "
+ "later");
+ error_emitted = true;
+ }
+ }
+
+ if (error_emitted)
+ result->type = glsl_type::error_type;
+
+ type = result->type;
+ break;
+ }
+
+ case ast_function_call:
+ /* Should *NEVER* get here. ast_function_call should always be handled
+ * by ast_function_expression::hir.
+ */
+ assert(0);
+ break;
+
+ case ast_identifier: {
+ /* ast_identifier can appear several places in a full abstract syntax
+ * tree. This particular use must be at location specified in the grammar
+ * as 'variable_identifier'.
+ */
+ ir_variable *var =
+ state->symbols->get_variable(this->primary_expression.identifier);
+
+ result = new(ctx) ir_dereference_variable(var);
+
+ if (var != NULL) {
+ var->used = true;
+ type = result->type;
+ } else {
+ _mesa_glsl_error(& loc, state, "`%s' undeclared",
+ this->primary_expression.identifier);
+
+ error_emitted = true;
+ }
+ break;
+ }
+
+ case ast_int_constant:
+ type = glsl_type::int_type;
+ result = new(ctx) ir_constant(this->primary_expression.int_constant);
+ break;
+
+ case ast_uint_constant:
+ type = glsl_type::uint_type;
+ result = new(ctx) ir_constant(this->primary_expression.uint_constant);
+ break;
+
+ case ast_float_constant:
+ type = glsl_type::float_type;
+ result = new(ctx) ir_constant(this->primary_expression.float_constant);
+ break;
+
+ case ast_bool_constant:
+ type = glsl_type::bool_type;
+ result = new(ctx) ir_constant(bool(this->primary_expression.bool_constant));
+ break;
+
+ case ast_sequence: {
+ /* It should not be possible to generate a sequence in the AST without
+ * any expressions in it.
+ */
+ assert(!this->expressions.is_empty());
+
+ /* The r-value of a sequence is the last expression in the sequence. If
+ * the other expressions in the sequence do not have side-effects (and
+ * therefore add instructions to the instruction list), they get dropped
+ * on the floor.
+ */
+ foreach_list_typed (ast_node, ast, link, &this->expressions)
+ result = ast->hir(instructions, state);
+
+ type = result->type;
+
+ /* Any errors should have already been emitted in the loop above.
+ */
+ error_emitted = true;
+ break;
+ }
+ }
+
+ if (type->is_error() && !error_emitted)
+ _mesa_glsl_error(& loc, state, "type mismatch");
+
+ return result;
+}
+
+
+ir_rvalue *
+ast_expression_statement::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ /* It is possible to have expression statements that don't have an
+ * expression. This is the solitary semicolon:
+ *
+ * for (i = 0; i < 5; i++)
+ * ;
+ *
+ * In this case the expression will be NULL. Test for NULL and don't do
+ * anything in that case.
+ */
+ if (expression != NULL)
+ expression->hir(instructions, state);
+
+ /* Statements do not have r-values.
+ */
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_compound_statement::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ if (new_scope)
+ state->symbols->push_scope();
+
+ foreach_list_typed (ast_node, ast, link, &this->statements)
+ ast->hir(instructions, state);
+
+ if (new_scope)
+ state->symbols->pop_scope();
+
+ /* Compound statements do not have r-values.
+ */
+ return NULL;
+}
+
+
+static const glsl_type *
+process_array_type(YYLTYPE *loc, const glsl_type *base, ast_node *array_size,
+ struct _mesa_glsl_parse_state *state)
+{
+ unsigned length = 0;
+
+ /* FINISHME: Reject delcarations of multidimensional arrays. */
+
+ if (array_size != NULL) {
+ exec_list dummy_instructions;
+ ir_rvalue *const ir = array_size->hir(& dummy_instructions, state);
+ YYLTYPE loc = array_size->get_location();
+
+ /* FINISHME: Verify that the grammar forbids side-effects in array
+ * FINISHME: sizes. i.e., 'vec4 [x = 12] data'
+ */
+ assert(dummy_instructions.is_empty());
+
+ if (ir != NULL) {
+ if (!ir->type->is_integer()) {
+ _mesa_glsl_error(& loc, state, "array size must be integer type");
+ } else if (!ir->type->is_scalar()) {
+ _mesa_glsl_error(& loc, state, "array size must be scalar type");
+ } else {
+ ir_constant *const size = ir->constant_expression_value();
+
+ if (size == NULL) {
+ _mesa_glsl_error(& loc, state, "array size must be a "
+ "constant valued expression");
+ } else if (size->value.i[0] <= 0) {
+ _mesa_glsl_error(& loc, state, "array size must be > 0");
+ } else {
+ assert(size->type == ir->type);
+ length = size->value.u[0];
+ }
+ }
+ }
+ } else if (state->es_shader) {
+ /* Section 10.17 of the GLSL ES 1.00 specification states that unsized
+ * array declarations have been removed from the language.
+ */
+ _mesa_glsl_error(loc, state, "unsized array declarations are not "
+ "allowed in GLSL ES 1.00.");
+ }
+
+ return glsl_type::get_array_instance(base, length);
+}
+
+
+const glsl_type *
+ast_type_specifier::glsl_type(const char **name,
+ struct _mesa_glsl_parse_state *state) const
+{
+ const struct glsl_type *type;
+
+ type = state->symbols->get_type(this->type_name);
+ *name = this->type_name;
+
+ if (this->is_array) {
+ YYLTYPE loc = this->get_location();
+ type = process_array_type(&loc, type, this->array_size, state);
+ }
+
+ return type;
+}
+
+
+static void
+apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
+ ir_variable *var,
+ struct _mesa_glsl_parse_state *state,
+ YYLTYPE *loc)
+{
+ if (qual->flags.q.invariant) {
+ if (var->used) {
+ _mesa_glsl_error(loc, state,
+ "variable `%s' may not be redeclared "
+ "`invariant' after being used",
+ var->name);
+ } else {
+ var->invariant = 1;
+ }
+ }
+
+ if (qual->flags.q.constant || qual->flags.q.attribute
+ || qual->flags.q.uniform
+ || (qual->flags.q.varying && (state->target == fragment_shader)))
+ var->read_only = 1;
+
+ if (qual->flags.q.centroid)
+ var->centroid = 1;
+
+ if (qual->flags.q.attribute && state->target != vertex_shader) {
+ var->type = glsl_type::error_type;
+ _mesa_glsl_error(loc, state,
+ "`attribute' variables may not be declared in the "
+ "%s shader",
+ _mesa_glsl_shader_target_name(state->target));
+ }
+
+ /* From page 25 (page 31 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "The varying qualifier can be used only with the data types
+ * float, vec2, vec3, vec4, mat2, mat3, and mat4, or arrays of
+ * these."
+ */
+ if (qual->flags.q.varying) {
+ const glsl_type *non_array_type;
+
+ if (var->type && var->type->is_array())
+ non_array_type = var->type->fields.array;
+ else
+ non_array_type = var->type;
+
+ if (non_array_type && non_array_type->base_type != GLSL_TYPE_FLOAT) {
+ var->type = glsl_type::error_type;
+ _mesa_glsl_error(loc, state,
+ "varying variables must be of base type float");
+ }
+ }
+
+ /* If there is no qualifier that changes the mode of the variable, leave
+ * the setting alone.
+ */
+ if (qual->flags.q.in && qual->flags.q.out)
+ var->mode = ir_var_inout;
+ else if (qual->flags.q.attribute || qual->flags.q.in
+ || (qual->flags.q.varying && (state->target == fragment_shader)))
+ var->mode = ir_var_in;
+ else if (qual->flags.q.out
+ || (qual->flags.q.varying && (state->target == vertex_shader)))
+ var->mode = ir_var_out;
+ else if (qual->flags.q.uniform)
+ var->mode = ir_var_uniform;
+
+ if (state->all_invariant && (state->current_function == NULL)) {
+ switch (state->target) {
+ case vertex_shader:
+ if (var->mode == ir_var_out)
+ var->invariant = true;
+ break;
+ case geometry_shader:
+ if ((var->mode == ir_var_in) || (var->mode == ir_var_out))
+ var->invariant = true;
+ break;
+ case fragment_shader:
+ if (var->mode == ir_var_in)
+ var->invariant = true;
+ break;
+ }
+ }
+
+ if (qual->flags.q.flat)
+ var->interpolation = ir_var_flat;
+ else if (qual->flags.q.noperspective)
+ var->interpolation = ir_var_noperspective;
+ else
+ var->interpolation = ir_var_smooth;
+
+ var->pixel_center_integer = qual->flags.q.pixel_center_integer;
+ var->origin_upper_left = qual->flags.q.origin_upper_left;
+ if ((qual->flags.q.origin_upper_left || qual->flags.q.pixel_center_integer)
+ && (strcmp(var->name, "gl_FragCoord") != 0)) {
+ const char *const qual_string = (qual->flags.q.origin_upper_left)
+ ? "origin_upper_left" : "pixel_center_integer";
+
+ _mesa_glsl_error(loc, state,
+ "layout qualifier `%s' can only be applied to "
+ "fragment shader input `gl_FragCoord'",
+ qual_string);
+ }
+
+ if (qual->flags.q.explicit_location) {
+ const bool global_scope = (state->current_function == NULL);
+ bool fail = false;
+ const char *string = "";
+
+ /* In the vertex shader only shader inputs can be given explicit
+ * locations.
+ *
+ * In the fragment shader only shader outputs can be given explicit
+ * locations.
+ */
+ switch (state->target) {
+ case vertex_shader:
+ if (!global_scope || (var->mode != ir_var_in)) {
+ fail = true;
+ string = "input";
+ }
+ break;
+
+ case geometry_shader:
+ _mesa_glsl_error(loc, state,
+ "geometry shader variables cannot be given "
+ "explicit locations\n");
+ break;
+
+ case fragment_shader:
+ if (!global_scope || (var->mode != ir_var_in)) {
+ fail = true;
+ string = "output";
+ }
+ break;
+ };
+
+ if (fail) {
+ _mesa_glsl_error(loc, state,
+ "only %s shader %s variables can be given an "
+ "explicit location\n",
+ _mesa_glsl_shader_target_name(state->target),
+ string);
+ } else {
+ var->explicit_location = true;
+
+ /* This bit of silliness is needed because invalid explicit locations
+ * are supposed to be flagged during linking. Small negative values
+ * biased by VERT_ATTRIB_GENERIC0 or FRAG_RESULT_DATA0 could alias
+ * built-in values (e.g., -16+VERT_ATTRIB_GENERIC0 = VERT_ATTRIB_POS).
+ * The linker needs to be able to differentiate these cases. This
+ * ensures that negative values stay negative.
+ */
+ if (qual->location >= 0) {
+ var->location = (state->target == vertex_shader)
+ ? (qual->location + VERT_ATTRIB_GENERIC0)
+ : (qual->location + FRAG_RESULT_DATA0);
+ } else {
+ var->location = qual->location;
+ }
+ }
+ }
+
+ /* Does the declaration use the 'layout' keyword?
+ */
+ const bool uses_layout = qual->flags.q.pixel_center_integer
+ || qual->flags.q.origin_upper_left
+ || qual->flags.q.explicit_location;
+
+ /* Does the declaration use the deprecated 'attribute' or 'varying'
+ * keywords?
+ */
+ const bool uses_deprecated_qualifier = qual->flags.q.attribute
+ || qual->flags.q.varying;
+
+ /* Is the 'layout' keyword used with parameters that allow relaxed checking.
+ * Many implementations of GL_ARB_fragment_coord_conventions_enable and some
+ * implementations (only Mesa?) GL_ARB_explicit_attrib_location_enable
+ * allowed the layout qualifier to be used with 'varying' and 'attribute'.
+ * These extensions and all following extensions that add the 'layout'
+ * keyword have been modified to require the use of 'in' or 'out'.
+ *
+ * The following extension do not allow the deprecated keywords:
+ *
+ * GL_AMD_conservative_depth
+ * GL_ARB_gpu_shader5
+ * GL_ARB_separate_shader_objects
+ * GL_ARB_tesselation_shader
+ * GL_ARB_transform_feedback3
+ * GL_ARB_uniform_buffer_object
+ *
+ * It is unknown whether GL_EXT_shader_image_load_store or GL_NV_gpu_shader5
+ * allow layout with the deprecated keywords.
+ */
+ const bool relaxed_layout_qualifier_checking =
+ state->ARB_fragment_coord_conventions_enable;
+
+ if (uses_layout && uses_deprecated_qualifier) {
+ if (relaxed_layout_qualifier_checking) {
+ _mesa_glsl_warning(loc, state,
+ "`layout' qualifier may not be used with "
+ "`attribute' or `varying'");
+ } else {
+ _mesa_glsl_error(loc, state,
+ "`layout' qualifier may not be used with "
+ "`attribute' or `varying'");
+ }
+ }
+
+ /* Layout qualifiers for gl_FragDepth, which are enabled by extension
+ * AMD_conservative_depth.
+ */
+ int depth_layout_count = qual->flags.q.depth_any
+ + qual->flags.q.depth_greater
+ + qual->flags.q.depth_less
+ + qual->flags.q.depth_unchanged;
+ if (depth_layout_count > 0
+ && !state->AMD_conservative_depth_enable) {
+ _mesa_glsl_error(loc, state,
+ "extension GL_AMD_conservative_depth must be enabled "
+ "to use depth layout qualifiers");
+ } else if (depth_layout_count > 0
+ && strcmp(var->name, "gl_FragDepth") != 0) {
+ _mesa_glsl_error(loc, state,
+ "depth layout qualifiers can be applied only to "
+ "gl_FragDepth");
+ } else if (depth_layout_count > 1
+ && strcmp(var->name, "gl_FragDepth") == 0) {
+ _mesa_glsl_error(loc, state,
+ "at most one depth layout qualifier can be applied to "
+ "gl_FragDepth");
+ }
+ if (qual->flags.q.depth_any)
+ var->depth_layout = ir_depth_layout_any;
+ else if (qual->flags.q.depth_greater)
+ var->depth_layout = ir_depth_layout_greater;
+ else if (qual->flags.q.depth_less)
+ var->depth_layout = ir_depth_layout_less;
+ else if (qual->flags.q.depth_unchanged)
+ var->depth_layout = ir_depth_layout_unchanged;
+ else
+ var->depth_layout = ir_depth_layout_none;
+
+ if (var->type->is_array() && state->language_version != 110) {
+ var->array_lvalue = true;
+ }
+}
+
+
+ir_rvalue *
+ast_declarator_list::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+ const struct glsl_type *decl_type;
+ const char *type_name = NULL;
+ ir_rvalue *result = NULL;
+ YYLTYPE loc = this->get_location();
+
+ /* From page 46 (page 52 of the PDF) of the GLSL 1.50 spec:
+ *
+ * "To ensure that a particular output variable is invariant, it is
+ * necessary to use the invariant qualifier. It can either be used to
+ * qualify a previously declared variable as being invariant
+ *
+ * invariant gl_Position; // make existing gl_Position be invariant"
+ *
+ * In these cases the parser will set the 'invariant' flag in the declarator
+ * list, and the type will be NULL.
+ */
+ if (this->invariant) {
+ assert(this->type == NULL);
+
+ if (state->current_function != NULL) {
+ _mesa_glsl_error(& loc, state,
+ "All uses of `invariant' keyword must be at global "
+ "scope\n");
+ }
+
+ foreach_list_typed (ast_declaration, decl, link, &this->declarations) {
+ assert(!decl->is_array);
+ assert(decl->array_size == NULL);
+ assert(decl->initializer == NULL);
+
+ ir_variable *const earlier =
+ state->symbols->get_variable(decl->identifier);
+ if (earlier == NULL) {
+ _mesa_glsl_error(& loc, state,
+ "Undeclared variable `%s' cannot be marked "
+ "invariant\n", decl->identifier);
+ } else if ((state->target == vertex_shader)
+ && (earlier->mode != ir_var_out)) {
+ _mesa_glsl_error(& loc, state,
+ "`%s' cannot be marked invariant, vertex shader "
+ "outputs only\n", decl->identifier);
+ } else if ((state->target == fragment_shader)
+ && (earlier->mode != ir_var_in)) {
+ _mesa_glsl_error(& loc, state,
+ "`%s' cannot be marked invariant, fragment shader "
+ "inputs only\n", decl->identifier);
+ } else if (earlier->used) {
+ _mesa_glsl_error(& loc, state,
+ "variable `%s' may not be redeclared "
+ "`invariant' after being used",
+ earlier->name);
+ } else {
+ earlier->invariant = true;
+ }
+ }
+
+ /* Invariant redeclarations do not have r-values.
+ */
+ return NULL;
+ }
+
+ assert(this->type != NULL);
+ assert(!this->invariant);
+
+ /* The type specifier may contain a structure definition. Process that
+ * before any of the variable declarations.
+ */
+ (void) this->type->specifier->hir(instructions, state);
+
+ decl_type = this->type->specifier->glsl_type(& type_name, state);
+ if (this->declarations.is_empty()) {
+ /* The only valid case where the declaration list can be empty is when
+ * the declaration is setting the default precision of a built-in type
+ * (e.g., 'precision highp vec4;').
+ */
+
+ if (decl_type != NULL) {
+ } else {
+ _mesa_glsl_error(& loc, state, "incomplete declaration");
+ }
+ }
+
+ foreach_list_typed (ast_declaration, decl, link, &this->declarations) {
+ const struct glsl_type *var_type;
+ ir_variable *var;
+
+ /* FINISHME: Emit a warning if a variable declaration shadows a
+ * FINISHME: declaration at a higher scope.
+ */
+
+ if ((decl_type == NULL) || decl_type->is_void()) {
+ if (type_name != NULL) {
+ _mesa_glsl_error(& loc, state,
+ "invalid type `%s' in declaration of `%s'",
+ type_name, decl->identifier);
+ } else {
+ _mesa_glsl_error(& loc, state,
+ "invalid type in declaration of `%s'",
+ decl->identifier);
+ }
+ continue;
+ }
+
+ if (decl->is_array) {
+ var_type = process_array_type(&loc, decl_type, decl->array_size,
+ state);
+ } else {
+ var_type = decl_type;
+ }
+
+ var = new(ctx) ir_variable(var_type, decl->identifier, ir_var_auto);
+
+ /* From page 22 (page 28 of the PDF) of the GLSL 1.10 specification;
+ *
+ * "Global variables can only use the qualifiers const,
+ * attribute, uni form, or varying. Only one may be
+ * specified.
+ *
+ * Local variables can only use the qualifier const."
+ *
+ * This is relaxed in GLSL 1.30. It is also relaxed by any extension
+ * that adds the 'layout' keyword.
+ */
+ if ((state->language_version < 130)
+ && !state->ARB_explicit_attrib_location_enable
+ && !state->ARB_fragment_coord_conventions_enable) {
+ if (this->type->qualifier.flags.q.out) {
+ _mesa_glsl_error(& loc, state,
+ "`out' qualifier in declaration of `%s' "
+ "only valid for function parameters in %s.",
+ decl->identifier, state->version_string);
+ }
+ if (this->type->qualifier.flags.q.in) {
+ _mesa_glsl_error(& loc, state,
+ "`in' qualifier in declaration of `%s' "
+ "only valid for function parameters in %s.",
+ decl->identifier, state->version_string);
+ }
+ /* FINISHME: Test for other invalid qualifiers. */
+ }
+
+ apply_type_qualifier_to_variable(& this->type->qualifier, var, state,
+ & loc);
+
+ if (this->type->qualifier.flags.q.invariant) {
+ if ((state->target == vertex_shader) && !(var->mode == ir_var_out ||
+ var->mode == ir_var_inout)) {
+ /* FINISHME: Note that this doesn't work for invariant on
+ * a function signature outval
+ */
+ _mesa_glsl_error(& loc, state,
+ "`%s' cannot be marked invariant, vertex shader "
+ "outputs only\n", var->name);
+ } else if ((state->target == fragment_shader) &&
+ !(var->mode == ir_var_in || var->mode == ir_var_inout)) {
+ /* FINISHME: Note that this doesn't work for invariant on
+ * a function signature inval
+ */
+ _mesa_glsl_error(& loc, state,
+ "`%s' cannot be marked invariant, fragment shader "
+ "inputs only\n", var->name);
+ }
+ }
+
+ if (state->current_function != NULL) {
+ const char *mode = NULL;
+ const char *extra = "";
+
+ /* There is no need to check for 'inout' here because the parser will
+ * only allow that in function parameter lists.
+ */
+ if (this->type->qualifier.flags.q.attribute) {
+ mode = "attribute";
+ } else if (this->type->qualifier.flags.q.uniform) {
+ mode = "uniform";
+ } else if (this->type->qualifier.flags.q.varying) {
+ mode = "varying";
+ } else if (this->type->qualifier.flags.q.in) {
+ mode = "in";
+ extra = " or in function parameter list";
+ } else if (this->type->qualifier.flags.q.out) {
+ mode = "out";
+ extra = " or in function parameter list";
+ }
+
+ if (mode) {
+ _mesa_glsl_error(& loc, state,
+ "%s variable `%s' must be declared at "
+ "global scope%s",
+ mode, var->name, extra);
+ }
+ } else if (var->mode == ir_var_in) {
+ var->read_only = true;
+
+ if (state->target == vertex_shader) {
+ bool error_emitted = false;
+
+ /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
+ *
+ * "Vertex shader inputs can only be float, floating-point
+ * vectors, matrices, signed and unsigned integers and integer
+ * vectors. Vertex shader inputs can also form arrays of these
+ * types, but not structures."
+ *
+ * From page 31 (page 27 of the PDF) of the GLSL 1.30 spec:
+ *
+ * "Vertex shader inputs can only be float, floating-point
+ * vectors, matrices, signed and unsigned integers and integer
+ * vectors. They cannot be arrays or structures."
+ *
+ * From page 23 (page 29 of the PDF) of the GLSL 1.20 spec:
+ *
+ * "The attribute qualifier can be used only with float,
+ * floating-point vectors, and matrices. Attribute variables
+ * cannot be declared as arrays or structures."
+ */
+ const glsl_type *check_type = var->type->is_array()
+ ? var->type->fields.array : var->type;
+
+ switch (check_type->base_type) {
+ case GLSL_TYPE_FLOAT:
+ break;
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT:
+ if (state->language_version > 120)
+ break;
+ /* FALLTHROUGH */
+ default:
+ _mesa_glsl_error(& loc, state,
+ "vertex shader input / attribute cannot have "
+ "type %s`%s'",
+ var->type->is_array() ? "array of " : "",
+ check_type->name);
+ error_emitted = true;
+ }
+
+ if (!error_emitted && (state->language_version <= 130)
+ && var->type->is_array()) {
+ _mesa_glsl_error(& loc, state,
+ "vertex shader input / attribute cannot have "
+ "array type");
+ error_emitted = true;
+ }
+ }
+ }
+
+ /* Integer vertex outputs must be qualified with 'flat'.
+ *
+ * From section 4.3.6 of the GLSL 1.30 spec:
+ * "If a vertex output is a signed or unsigned integer or integer
+ * vector, then it must be qualified with the interpolation qualifier
+ * flat."
+ */
+ if (state->language_version >= 130
+ && state->target == vertex_shader
+ && state->current_function == NULL
+ && var->type->is_integer()
+ && var->mode == ir_var_out
+ && var->interpolation != ir_var_flat) {
+
+ _mesa_glsl_error(&loc, state, "If a vertex output is an integer, "
+ "then it must be qualified with 'flat'");
+ }
+
+
+ /* Interpolation qualifiers cannot be applied to 'centroid' and
+ * 'centroid varying'.
+ *
+ * From page 29 (page 35 of the PDF) of the GLSL 1.30 spec:
+ * "interpolation qualifiers may only precede the qualifiers in,
+ * centroid in, out, or centroid out in a declaration. They do not apply
+ * to the deprecated storage qualifiers varying or centroid varying."
+ */
+ if (state->language_version >= 130
+ && this->type->qualifier.has_interpolation()
+ && this->type->qualifier.flags.q.varying) {
+
+ const char *i = this->type->qualifier.interpolation_string();
+ assert(i != NULL);
+ const char *s;
+ if (this->type->qualifier.flags.q.centroid)
+ s = "centroid varying";
+ else
+ s = "varying";
+
+ _mesa_glsl_error(&loc, state,
+ "qualifier '%s' cannot be applied to the "
+ "deprecated storage qualifier '%s'", i, s);
+ }
+
+
+ /* Interpolation qualifiers can only apply to vertex shader outputs and
+ * fragment shader inputs.
+ *
+ * From page 29 (page 35 of the PDF) of the GLSL 1.30 spec:
+ * "Outputs from a vertex shader (out) and inputs to a fragment
+ * shader (in) can be further qualified with one or more of these
+ * interpolation qualifiers"
+ */
+ if (state->language_version >= 130
+ && this->type->qualifier.has_interpolation()) {
+
+ const char *i = this->type->qualifier.interpolation_string();
+ assert(i != NULL);
+
+ switch (state->target) {
+ case vertex_shader:
+ if (this->type->qualifier.flags.q.in) {
+ _mesa_glsl_error(&loc, state,
+ "qualifier '%s' cannot be applied to vertex "
+ "shader inputs", i);
+ }
+ break;
+ case fragment_shader:
+ if (this->type->qualifier.flags.q.out) {
+ _mesa_glsl_error(&loc, state,
+ "qualifier '%s' cannot be applied to fragment "
+ "shader outputs", i);
+ }
+ break;
+ default:
+ assert(0);
+ }
+ }
+
+
+ /* From section 4.3.4 of the GLSL 1.30 spec:
+ * "It is an error to use centroid in in a vertex shader."
+ */
+ if (state->language_version >= 130
+ && this->type->qualifier.flags.q.centroid
+ && this->type->qualifier.flags.q.in
+ && state->target == vertex_shader) {
+
+ _mesa_glsl_error(&loc, state,
+ "'centroid in' cannot be used in a vertex shader");
+ }
+
+
+ /* Precision qualifiers exists only in GLSL versions 1.00 and >= 1.30.
+ */
+ if (this->type->specifier->precision != ast_precision_none
+ && state->language_version != 100
+ && state->language_version < 130) {
+
+ _mesa_glsl_error(&loc, state,
+ "precision qualifiers are supported only in GLSL ES "
+ "1.00, and GLSL 1.30 and later");
+ }
+
+
+ /* Precision qualifiers only apply to floating point and integer types.
+ *
+ * From section 4.5.2 of the GLSL 1.30 spec:
+ * "Any floating point or any integer declaration can have the type
+ * preceded by one of these precision qualifiers [...] Literal
+ * constants do not have precision qualifiers. Neither do Boolean
+ * variables.
+ */
+ if (this->type->specifier->precision != ast_precision_none
+ && !var->type->is_float()
+ && !var->type->is_integer()
+ && !(var->type->is_array()
+ && (var->type->fields.array->is_float()
+ || var->type->fields.array->is_integer()))) {
+
+ _mesa_glsl_error(&loc, state,
+ "precision qualifiers apply only to floating point "
+ "and integer types");
+ }
+
+ /* Process the initializer and add its instructions to a temporary
+ * list. This list will be added to the instruction stream (below) after
+ * the declaration is added. This is done because in some cases (such as
+ * redeclarations) the declaration may not actually be added to the
+ * instruction stream.
+ */
+ exec_list initializer_instructions;
+ if (decl->initializer != NULL) {
+ YYLTYPE initializer_loc = decl->initializer->get_location();
+
+ /* From page 24 (page 30 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "All uniform variables are read-only and are initialized either
+ * directly by an application via API commands, or indirectly by
+ * OpenGL."
+ */
+ if ((state->language_version <= 110)
+ && (var->mode == ir_var_uniform)) {
+ _mesa_glsl_error(& initializer_loc, state,
+ "cannot initialize uniforms in GLSL 1.10");
+ }
+
+ if (var->type->is_sampler()) {
+ _mesa_glsl_error(& initializer_loc, state,
+ "cannot initialize samplers");
+ }
+
+ if ((var->mode == ir_var_in) && (state->current_function == NULL)) {
+ _mesa_glsl_error(& initializer_loc, state,
+ "cannot initialize %s shader input / %s",
+ _mesa_glsl_shader_target_name(state->target),
+ (state->target == vertex_shader)
+ ? "attribute" : "varying");
+ }
+
+ ir_dereference *const lhs = new(ctx) ir_dereference_variable(var);
+ ir_rvalue *rhs = decl->initializer->hir(&initializer_instructions,
+ state);
+
+ /* Calculate the constant value if this is a const or uniform
+ * declaration.
+ */
+ if (this->type->qualifier.flags.q.constant
+ || this->type->qualifier.flags.q.uniform) {
+ ir_rvalue *new_rhs = validate_assignment(state, var->type, rhs);
+ if (new_rhs != NULL) {
+ rhs = new_rhs;
+
+ ir_constant *constant_value = rhs->constant_expression_value();
+ if (!constant_value) {
+ _mesa_glsl_error(& initializer_loc, state,
+ "initializer of %s variable `%s' must be a "
+ "constant expression",
+ (this->type->qualifier.flags.q.constant)
+ ? "const" : "uniform",
+ decl->identifier);
+ if (var->type->is_numeric()) {
+ /* Reduce cascading errors. */
+ var->constant_value = ir_constant::zero(ctx, var->type);
+ }
+ } else {
+ rhs = constant_value;
+ var->constant_value = constant_value;
+ }
+ } else {
+ _mesa_glsl_error(&initializer_loc, state,
+ "initializer of type %s cannot be assigned to "
+ "variable of type %s",
+ rhs->type->name, var->type->name);
+ if (var->type->is_numeric()) {
+ /* Reduce cascading errors. */
+ var->constant_value = ir_constant::zero(ctx, var->type);
+ }
+ }
+ }
+
+ if (rhs && !rhs->type->is_error()) {
+ bool temp = var->read_only;
+ if (this->type->qualifier.flags.q.constant)
+ var->read_only = false;
+
+ /* Never emit code to initialize a uniform.
+ */
+ const glsl_type *initializer_type;
+ if (!this->type->qualifier.flags.q.uniform) {
+ result = do_assignment(&initializer_instructions, state,
+ lhs, rhs,
+ this->get_location());
+ initializer_type = result->type;
+ } else
+ initializer_type = rhs->type;
+
+ /* If the declared variable is an unsized array, it must inherrit
+ * its full type from the initializer. A declaration such as
+ *
+ * uniform float a[] = float[](1.0, 2.0, 3.0, 3.0);
+ *
+ * becomes
+ *
+ * uniform float a[4] = float[](1.0, 2.0, 3.0, 3.0);
+ *
+ * The assignment generated in the if-statement (below) will also
+ * automatically handle this case for non-uniforms.
+ *
+ * If the declared variable is not an array, the types must
+ * already match exactly. As a result, the type assignment
+ * here can be done unconditionally. For non-uniforms the call
+ * to do_assignment can change the type of the initializer (via
+ * the implicit conversion rules). For uniforms the initializer
+ * must be a constant expression, and the type of that expression
+ * was validated above.
+ */
+ var->type = initializer_type;
+
+ var->read_only = temp;
+ }
+ }
+
+ /* From page 23 (page 29 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "It is an error to write to a const variable outside of
+ * its declaration, so they must be initialized when
+ * declared."
+ */
+ if (this->type->qualifier.flags.q.constant && decl->initializer == NULL) {
+ _mesa_glsl_error(& loc, state,
+ "const declaration of `%s' must be initialized",
+ decl->identifier);
+ }
+
+ /* Check if this declaration is actually a re-declaration, either to
+ * resize an array or add qualifiers to an existing variable.
+ *
+ * This is allowed for variables in the current scope, or when at
+ * global scope (for built-ins in the implicit outer scope).
+ */
+ ir_variable *earlier = state->symbols->get_variable(decl->identifier);
+ if (earlier != NULL && (state->current_function == NULL ||
+ state->symbols->name_declared_this_scope(decl->identifier))) {
+
+ /* From page 24 (page 30 of the PDF) of the GLSL 1.50 spec,
+ *
+ * "It is legal to declare an array without a size and then
+ * later re-declare the same name as an array of the same
+ * type and specify a size."
+ */
+ if ((earlier->type->array_size() == 0)
+ && var->type->is_array()
+ && (var->type->element_type() == earlier->type->element_type())) {
+ /* FINISHME: This doesn't match the qualifiers on the two
+ * FINISHME: declarations. It's not 100% clear whether this is
+ * FINISHME: required or not.
+ */
+
+ /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
+ *
+ * "The size [of gl_TexCoord] can be at most
+ * gl_MaxTextureCoords."
+ */
+ const unsigned size = unsigned(var->type->array_size());
+ if ((strcmp("gl_TexCoord", var->name) == 0)
+ && (size > state->Const.MaxTextureCoords)) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(& loc, state, "`gl_TexCoord' array size cannot "
+ "be larger than gl_MaxTextureCoords (%u)\n",
+ state->Const.MaxTextureCoords);
+ } else if ((size > 0) && (size <= earlier->max_array_access)) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(& loc, state, "array size must be > %u due to "
+ "previous access",
+ earlier->max_array_access);
+ }
+
+ earlier->type = var->type;
+ delete var;
+ var = NULL;
+ } else if (state->ARB_fragment_coord_conventions_enable
+ && strcmp(var->name, "gl_FragCoord") == 0
+ && earlier->type == var->type
+ && earlier->mode == var->mode) {
+ /* Allow redeclaration of gl_FragCoord for ARB_fcc layout
+ * qualifiers.
+ */
+ earlier->origin_upper_left = var->origin_upper_left;
+ earlier->pixel_center_integer = var->pixel_center_integer;
+
+ /* According to section 4.3.7 of the GLSL 1.30 spec,
+ * the following built-in varaibles can be redeclared with an
+ * interpolation qualifier:
+ * * gl_FrontColor
+ * * gl_BackColor
+ * * gl_FrontSecondaryColor
+ * * gl_BackSecondaryColor
+ * * gl_Color
+ * * gl_SecondaryColor
+ */
+ } else if (state->language_version >= 130
+ && (strcmp(var->name, "gl_FrontColor") == 0
+ || strcmp(var->name, "gl_BackColor") == 0
+ || strcmp(var->name, "gl_FrontSecondaryColor") == 0
+ || strcmp(var->name, "gl_BackSecondaryColor") == 0
+ || strcmp(var->name, "gl_Color") == 0
+ || strcmp(var->name, "gl_SecondaryColor") == 0)
+ && earlier->type == var->type
+ && earlier->mode == var->mode) {
+ earlier->interpolation = var->interpolation;
+
+ /* Layout qualifiers for gl_FragDepth. */
+ } else if (state->AMD_conservative_depth_enable
+ && strcmp(var->name, "gl_FragDepth") == 0
+ && earlier->type == var->type
+ && earlier->mode == var->mode) {
+
+ /** From the AMD_conservative_depth spec:
+ * Within any shader, the first redeclarations of gl_FragDepth
+ * must appear before any use of gl_FragDepth.
+ */
+ if (earlier->used) {
+ _mesa_glsl_error(&loc, state,
+ "the first redeclaration of gl_FragDepth "
+ "must appear before any use of gl_FragDepth");
+ }
+
+ /* Prevent inconsistent redeclaration of depth layout qualifier. */
+ if (earlier->depth_layout != ir_depth_layout_none
+ && earlier->depth_layout != var->depth_layout) {
+ _mesa_glsl_error(&loc, state,
+ "gl_FragDepth: depth layout is declared here "
+ "as '%s, but it was previously declared as "
+ "'%s'",
+ depth_layout_string(var->depth_layout),
+ depth_layout_string(earlier->depth_layout));
+ }
+
+ earlier->depth_layout = var->depth_layout;
+
+ } else {
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(&loc, state, "`%s' redeclared", decl->identifier);
+ }
+
+ continue;
+ }
+
+ /* By now, we know it's a new variable declaration (we didn't hit the
+ * above "continue").
+ *
+ * From page 15 (page 21 of the PDF) of the GLSL 1.10 spec,
+ *
+ * "Identifiers starting with "gl_" are reserved for use by
+ * OpenGL, and may not be declared in a shader as either a
+ * variable or a function."
+ */
+ if (strncmp(decl->identifier, "gl_", 3) == 0)
+ _mesa_glsl_error(& loc, state,
+ "identifier `%s' uses reserved `gl_' prefix",
+ decl->identifier);
+
+ /* Add the variable to the symbol table. Note that the initializer's
+ * IR was already processed earlier (though it hasn't been emitted yet),
+ * without the variable in scope.
+ *
+ * This differs from most C-like languages, but it follows the GLSL
+ * specification. From page 28 (page 34 of the PDF) of the GLSL 1.50
+ * spec:
+ *
+ * "Within a declaration, the scope of a name starts immediately
+ * after the initializer if present or immediately after the name
+ * being declared if not."
+ */
+ if (!state->symbols->add_variable(var)) {
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(&loc, state, "name `%s' already taken in the "
+ "current scope", decl->identifier);
+ continue;
+ }
+
+ /* Push the variable declaration to the top. It means that all
+ * the variable declarations will appear in a funny
+ * last-to-first order, but otherwise we run into trouble if a
+ * function is prototyped, a global var is decled, then the
+ * function is defined with usage of the global var. See
+ * glslparsertest's CorrectModule.frag.
+ */
+ instructions->push_head(var);
+ instructions->append_list(&initializer_instructions);
+ }
+
+
+ /* Generally, variable declarations do not have r-values. However,
+ * one is used for the declaration in
+ *
+ * while (bool b = some_condition()) {
+ * ...
+ * }
+ *
+ * so we return the rvalue from the last seen declaration here.
+ */
+ return result;
+}
+
+
+ir_rvalue *
+ast_parameter_declarator::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+ const struct glsl_type *type;
+ const char *name = NULL;
+ YYLTYPE loc = this->get_location();
+
+ type = this->type->specifier->glsl_type(& name, state);
+
+ if (type == NULL) {
+ if (name != NULL) {
+ _mesa_glsl_error(& loc, state,
+ "invalid type `%s' in declaration of `%s'",
+ name, this->identifier);
+ } else {
+ _mesa_glsl_error(& loc, state,
+ "invalid type in declaration of `%s'",
+ this->identifier);
+ }
+
+ type = glsl_type::error_type;
+ }
+
+ /* From page 62 (page 68 of the PDF) of the GLSL 1.50 spec:
+ *
+ * "Functions that accept no input arguments need not use void in the
+ * argument list because prototypes (or definitions) are required and
+ * therefore there is no ambiguity when an empty argument list "( )" is
+ * declared. The idiom "(void)" as a parameter list is provided for
+ * convenience."
+ *
+ * Placing this check here prevents a void parameter being set up
+ * for a function, which avoids tripping up checks for main taking
+ * parameters and lookups of an unnamed symbol.
+ */
+ if (type->is_void()) {
+ if (this->identifier != NULL)
+ _mesa_glsl_error(& loc, state,
+ "named parameter cannot have type `void'");
+
+ is_void = true;
+ return NULL;
+ }
+
+ if (formal_parameter && (this->identifier == NULL)) {
+ _mesa_glsl_error(& loc, state, "formal parameter lacks a name");
+ return NULL;
+ }
+
+ /* This only handles "vec4 foo[..]". The earlier specifier->glsl_type(...)
+ * call already handled the "vec4[..] foo" case.
+ */
+ if (this->is_array) {
+ type = process_array_type(&loc, type, this->array_size, state);
+ }
+
+ if (type->array_size() == 0) {
+ _mesa_glsl_error(&loc, state, "arrays passed as parameters must have "
+ "a declared size.");
+ type = glsl_type::error_type;
+ }
+
+ is_void = false;
+ ir_variable *var = new(ctx) ir_variable(type, this->identifier, ir_var_in);
+
+ /* Apply any specified qualifiers to the parameter declaration. Note that
+ * for function parameters the default mode is 'in'.
+ */
+ apply_type_qualifier_to_variable(& this->type->qualifier, var, state, & loc);
+
+ instructions->push_tail(var);
+
+ /* Parameter declarations do not have r-values.
+ */
+ return NULL;
+}
+
+
+void
+ast_parameter_declarator::parameters_to_hir(exec_list *ast_parameters,
+ bool formal,
+ exec_list *ir_parameters,
+ _mesa_glsl_parse_state *state)
+{
+ ast_parameter_declarator *void_param = NULL;
+ unsigned count = 0;
+
+ foreach_list_typed (ast_parameter_declarator, param, link, ast_parameters) {
+ param->formal_parameter = formal;
+ param->hir(ir_parameters, state);
+
+ if (param->is_void)
+ void_param = param;
+
+ count++;
+ }
+
+ if ((void_param != NULL) && (count > 1)) {
+ YYLTYPE loc = void_param->get_location();
+
+ _mesa_glsl_error(& loc, state,
+ "`void' parameter must be only parameter");
+ }
+}
+
+
+void
+emit_function(_mesa_glsl_parse_state *state, exec_list *instructions,
+ ir_function *f)
+{
+ /* Emit the new function header */
+ if (state->current_function == NULL) {
+ instructions->push_tail(f);
+ } else {
+ /* IR invariants disallow function declarations or definitions nested
+ * within other function definitions. Insert the new ir_function
+ * block in the instruction sequence before the ir_function block
+ * containing the current ir_function_signature.
+ */
+ ir_function *const curr =
+ const_cast<ir_function *>(state->current_function->function());
+
+ curr->insert_before(f);
+ }
+}
+
+
+ir_rvalue *
+ast_function::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+ ir_function *f = NULL;
+ ir_function_signature *sig = NULL;
+ exec_list hir_parameters;
+
+ const char *const name = identifier;
+
+ /* From page 21 (page 27 of the PDF) of the GLSL 1.20 spec,
+ *
+ * "Function declarations (prototypes) cannot occur inside of functions;
+ * they must be at global scope, or for the built-in functions, outside
+ * the global scope."
+ *
+ * From page 27 (page 33 of the PDF) of the GLSL ES 1.00.16 spec,
+ *
+ * "User defined functions may only be defined within the global scope."
+ *
+ * Note that this language does not appear in GLSL 1.10.
+ */
+ if ((state->current_function != NULL) && (state->language_version != 110)) {
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(&loc, state,
+ "declaration of function `%s' not allowed within "
+ "function body", name);
+ }
+
+ /* From page 15 (page 21 of the PDF) of the GLSL 1.10 spec,
+ *
+ * "Identifiers starting with "gl_" are reserved for use by
+ * OpenGL, and may not be declared in a shader as either a
+ * variable or a function."
+ */
+ if (strncmp(name, "gl_", 3) == 0) {
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(&loc, state,
+ "identifier `%s' uses reserved `gl_' prefix", name);
+ }
+
+ /* Convert the list of function parameters to HIR now so that they can be
+ * used below to compare this function's signature with previously seen
+ * signatures for functions with the same name.
+ */
+ ast_parameter_declarator::parameters_to_hir(& this->parameters,
+ is_definition,
+ & hir_parameters, state);
+
+ const char *return_type_name;
+ const glsl_type *return_type =
+ this->return_type->specifier->glsl_type(& return_type_name, state);
+
+ if (!return_type) {
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(&loc, state,
+ "function `%s' has undeclared return type `%s'",
+ name, return_type_name);
+ return_type = glsl_type::error_type;
+ }
+
+ /* From page 56 (page 62 of the PDF) of the GLSL 1.30 spec:
+ * "No qualifier is allowed on the return type of a function."
+ */
+ if (this->return_type->has_qualifiers()) {
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(& loc, state,
+ "function `%s' return type has qualifiers", name);
+ }
+
+ /* Verify that this function's signature either doesn't match a previously
+ * seen signature for a function with the same name, or, if a match is found,
+ * that the previously seen signature does not have an associated definition.
+ */
+ f = state->symbols->get_function(name);
+ if (f != NULL && (state->es_shader || f->has_user_signature())) {
+ sig = f->exact_matching_signature(&hir_parameters);
+ if (sig != NULL) {
+ const char *badvar = sig->qualifiers_match(&hir_parameters);
+ if (badvar != NULL) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(&loc, state, "function `%s' parameter `%s' "
+ "qualifiers don't match prototype", name, badvar);
+ }
+
+ if (sig->return_type != return_type) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(&loc, state, "function `%s' return type doesn't "
+ "match prototype", name);
+ }
+
+ if (is_definition && sig->is_defined) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(& loc, state, "function `%s' redefined", name);
+ }
+ }
+ } else {
+ f = new(ctx) ir_function(name);
+ if (!state->symbols->add_function(f)) {
+ /* This function name shadows a non-function use of the same name. */
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(&loc, state, "function name `%s' conflicts with "
+ "non-function", name);
+ return NULL;
+ }
+
+ emit_function(state, instructions, f);
+ }
+
+ /* Verify the return type of main() */
+ if (strcmp(name, "main") == 0) {
+ if (! return_type->is_void()) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(& loc, state, "main() must return void");
+ }
+
+ if (!hir_parameters.is_empty()) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(& loc, state, "main() must not take any parameters");
+ }
+ }
+
+ /* Finish storing the information about this new function in its signature.
+ */
+ if (sig == NULL) {
+ sig = new(ctx) ir_function_signature(return_type);
+ f->add_signature(sig);
+ }
+
+ sig->replace_parameters(&hir_parameters);
+ signature = sig;
+
+ /* Function declarations (prototypes) do not have r-values.
+ */
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_function_definition::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ prototype->is_definition = true;
+ prototype->hir(instructions, state);
+
+ ir_function_signature *signature = prototype->signature;
+ if (signature == NULL)
+ return NULL;
+
+ assert(state->current_function == NULL);
+ state->current_function = signature;
+ state->found_return = false;
+
+ /* Duplicate parameters declared in the prototype as concrete variables.
+ * Add these to the symbol table.
+ */
+ state->symbols->push_scope();
+ foreach_iter(exec_list_iterator, iter, signature->parameters) {
+ ir_variable *const var = ((ir_instruction *) iter.get())->as_variable();
+
+ assert(var != NULL);
+
+ /* The only way a parameter would "exist" is if two parameters have
+ * the same name.
+ */
+ if (state->symbols->name_declared_this_scope(var->name)) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(& loc, state, "parameter `%s' redeclared", var->name);
+ } else {
+ state->symbols->add_variable(var);
+ }
+ }
+
+ /* Convert the body of the function to HIR. */
+ this->body->hir(&signature->body, state);
+ signature->is_defined = true;
+
+ state->symbols->pop_scope();
+
+ assert(state->current_function == signature);
+ state->current_function = NULL;
+
+ if (!signature->return_type->is_void() && !state->found_return) {
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(& loc, state, "function `%s' has non-void return type "
+ "%s, but no return statement",
+ signature->function_name(),
+ signature->return_type->name);
+ }
+
+ /* Function definitions do not have r-values.
+ */
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_jump_statement::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+
+ switch (mode) {
+ case ast_return: {
+ ir_return *inst;
+ assert(state->current_function);
+
+ if (opt_return_value) {
+ ir_rvalue *const ret = opt_return_value->hir(instructions, state);
+
+ /* The value of the return type can be NULL if the shader says
+ * 'return foo();' and foo() is a function that returns void.
+ *
+ * NOTE: The GLSL spec doesn't say that this is an error. The type
+ * of the return value is void. If the return type of the function is
+ * also void, then this should compile without error. Seriously.
+ */
+ const glsl_type *const ret_type =
+ (ret == NULL) ? glsl_type::void_type : ret->type;
+
+ /* Implicit conversions are not allowed for return values. */
+ if (state->current_function->return_type != ret_type) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(& loc, state,
+ "`return' with wrong type %s, in function `%s' "
+ "returning %s",
+ ret_type->name,
+ state->current_function->function_name(),
+ state->current_function->return_type->name);
+ }
+
+ inst = new(ctx) ir_return(ret);
+ } else {
+ if (state->current_function->return_type->base_type !=
+ GLSL_TYPE_VOID) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(& loc, state,
+ "`return' with no value, in function %s returning "
+ "non-void",
+ state->current_function->function_name());
+ }
+ inst = new(ctx) ir_return;
+ }
+
+ state->found_return = true;
+ instructions->push_tail(inst);
+ break;
+ }
+
+ case ast_discard:
+ if (state->target != fragment_shader) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(& loc, state,
+ "`discard' may only appear in a fragment shader");
+ }
+ instructions->push_tail(new(ctx) ir_discard);
+ break;
+
+ case ast_break:
+ case ast_continue:
+ /* FINISHME: Handle switch-statements. They cannot contain 'continue',
+ * FINISHME: and they use a different IR instruction for 'break'.
+ */
+ /* FINISHME: Correctly handle the nesting. If a switch-statement is
+ * FINISHME: inside a loop, a 'continue' is valid and will bind to the
+ * FINISHME: loop.
+ */
+ if (state->loop_or_switch_nesting == NULL) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(& loc, state,
+ "`%s' may only appear in a loop",
+ (mode == ast_break) ? "break" : "continue");
+ } else {
+ ir_loop *const loop = state->loop_or_switch_nesting->as_loop();
+
+ /* Inline the for loop expression again, since we don't know
+ * where near the end of the loop body the normal copy of it
+ * is going to be placed.
+ */
+ if (mode == ast_continue &&
+ state->loop_or_switch_nesting_ast->rest_expression) {
+ state->loop_or_switch_nesting_ast->rest_expression->hir(instructions,
+ state);
+ }
+
+ if (loop != NULL) {
+ ir_loop_jump *const jump =
+ new(ctx) ir_loop_jump((mode == ast_break)
+ ? ir_loop_jump::jump_break
+ : ir_loop_jump::jump_continue);
+ instructions->push_tail(jump);
+ }
+ }
+
+ break;
+ }
+
+ /* Jump instructions do not have r-values.
+ */
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_selection_statement::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+
+ ir_rvalue *const condition = this->condition->hir(instructions, state);
+
+ /* From page 66 (page 72 of the PDF) of the GLSL 1.50 spec:
+ *
+ * "Any expression whose type evaluates to a Boolean can be used as the
+ * conditional expression bool-expression. Vector types are not accepted
+ * as the expression to if."
+ *
+ * The checks are separated so that higher quality diagnostics can be
+ * generated for cases where both rules are violated.
+ */
+ if (!condition->type->is_boolean() || !condition->type->is_scalar()) {
+ YYLTYPE loc = this->condition->get_location();
+
+ _mesa_glsl_error(& loc, state, "if-statement condition must be scalar "
+ "boolean");
+ }
+
+ ir_if *const stmt = new(ctx) ir_if(condition);
+
+ if (then_statement != NULL) {
+ state->symbols->push_scope();
+ then_statement->hir(& stmt->then_instructions, state);
+ state->symbols->pop_scope();
+ }
+
+ if (else_statement != NULL) {
+ state->symbols->push_scope();
+ else_statement->hir(& stmt->else_instructions, state);
+ state->symbols->pop_scope();
+ }
+
+ instructions->push_tail(stmt);
+
+ /* if-statements do not have r-values.
+ */
+ return NULL;
+}
+
+
+void
+ast_iteration_statement::condition_to_hir(ir_loop *stmt,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+
+ if (condition != NULL) {
+ ir_rvalue *const cond =
+ condition->hir(& stmt->body_instructions, state);
+
+ if ((cond == NULL)
+ || !cond->type->is_boolean() || !cond->type->is_scalar()) {
+ YYLTYPE loc = condition->get_location();
+
+ _mesa_glsl_error(& loc, state,
+ "loop condition must be scalar boolean");
+ } else {
+ /* As the first code in the loop body, generate a block that looks
+ * like 'if (!condition) break;' as the loop termination condition.
+ */
+ ir_rvalue *const not_cond =
+ new(ctx) ir_expression(ir_unop_logic_not, glsl_type::bool_type, cond,
+ NULL);
+
+ ir_if *const if_stmt = new(ctx) ir_if(not_cond);
+
+ ir_jump *const break_stmt =
+ new(ctx) ir_loop_jump(ir_loop_jump::jump_break);
+
+ if_stmt->then_instructions.push_tail(break_stmt);
+ stmt->body_instructions.push_tail(if_stmt);
+ }
+ }
+}
+
+
+ir_rvalue *
+ast_iteration_statement::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+
+ /* For-loops and while-loops start a new scope, but do-while loops do not.
+ */
+ if (mode != ast_do_while)
+ state->symbols->push_scope();
+
+ if (init_statement != NULL)
+ init_statement->hir(instructions, state);
+
+ ir_loop *const stmt = new(ctx) ir_loop();
+ instructions->push_tail(stmt);
+
+ /* Track the current loop and / or switch-statement nesting.
+ */
+ ir_instruction *const nesting = state->loop_or_switch_nesting;
+ ast_iteration_statement *nesting_ast = state->loop_or_switch_nesting_ast;
+
+ state->loop_or_switch_nesting = stmt;
+ state->loop_or_switch_nesting_ast = this;
+
+ if (mode != ast_do_while)
+ condition_to_hir(stmt, state);
+
+ if (body != NULL)
+ body->hir(& stmt->body_instructions, state);
+
+ if (rest_expression != NULL)
+ rest_expression->hir(& stmt->body_instructions, state);
+
+ if (mode == ast_do_while)
+ condition_to_hir(stmt, state);
+
+ if (mode != ast_do_while)
+ state->symbols->pop_scope();
+
+ /* Restore previous nesting before returning.
+ */
+ state->loop_or_switch_nesting = nesting;
+ state->loop_or_switch_nesting_ast = nesting_ast;
+
+ /* Loops do not have r-values.
+ */
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_type_specifier::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ if (!this->is_precision_statement && this->structure == NULL)
+ return NULL;
+
+ YYLTYPE loc = this->get_location();
+
+ if (this->precision != ast_precision_none
+ && state->language_version != 100
+ && state->language_version < 130) {
+ _mesa_glsl_error(&loc, state,
+ "precision qualifiers exist only in "
+ "GLSL ES 1.00, and GLSL 1.30 and later");
+ return NULL;
+ }
+ if (this->precision != ast_precision_none
+ && this->structure != NULL) {
+ _mesa_glsl_error(&loc, state,
+ "precision qualifiers do not apply to structures");
+ return NULL;
+ }
+
+ /* If this is a precision statement, check that the type to which it is
+ * applied is either float or int.
+ *
+ * From section 4.5.3 of the GLSL 1.30 spec:
+ * "The precision statement
+ * precision precision-qualifier type;
+ * can be used to establish a default precision qualifier. The type
+ * field can be either int or float [...]. Any other types or
+ * qualifiers will result in an error.
+ */
+ if (this->is_precision_statement) {
+ assert(this->precision != ast_precision_none);
+ assert(this->structure == NULL); /* The check for structures was
+ * performed above. */
+ if (this->is_array) {
+ _mesa_glsl_error(&loc, state,
+ "default precision statements do not apply to "
+ "arrays");
+ return NULL;
+ }
+ if (this->type_specifier != ast_float
+ && this->type_specifier != ast_int) {
+ _mesa_glsl_error(&loc, state,
+ "default precision statements apply only to types "
+ "float and int");
+ return NULL;
+ }
+
+ /* FINISHME: Translate precision statements into IR. */
+ return NULL;
+ }
+
+ if (this->structure != NULL)
+ return this->structure->hir(instructions, state);
+
+ return NULL;
+}
+
+
+ir_rvalue *
+ast_struct_specifier::hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ unsigned decl_count = 0;
+
+ /* Make an initial pass over the list of structure fields to determine how
+ * many there are. Each element in this list is an ast_declarator_list.
+ * This means that we actually need to count the number of elements in the
+ * 'declarations' list in each of the elements.
+ */
+ foreach_list_typed (ast_declarator_list, decl_list, link,
+ &this->declarations) {
+ foreach_list_const (decl_ptr, & decl_list->declarations) {
+ decl_count++;
+ }
+ }
+
+ /* Allocate storage for the structure fields and process the field
+ * declarations. As the declarations are processed, try to also convert
+ * the types to HIR. This ensures that structure definitions embedded in
+ * other structure definitions are processed.
+ */
+ glsl_struct_field *const fields = ralloc_array(state, glsl_struct_field,
+ decl_count);
+
+ unsigned i = 0;
+ foreach_list_typed (ast_declarator_list, decl_list, link,
+ &this->declarations) {
+ const char *type_name;
+
+ decl_list->type->specifier->hir(instructions, state);
+
+ /* Section 10.9 of the GLSL ES 1.00 specification states that
+ * embedded structure definitions have been removed from the language.
+ */
+ if (state->es_shader && decl_list->type->specifier->structure != NULL) {
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(&loc, state, "Embedded structure definitions are "
+ "not allowed in GLSL ES 1.00.");
+ }
+
+ const glsl_type *decl_type =
+ decl_list->type->specifier->glsl_type(& type_name, state);
+
+ foreach_list_typed (ast_declaration, decl, link,
+ &decl_list->declarations) {
+ const struct glsl_type *field_type = decl_type;
+ if (decl->is_array) {
+ YYLTYPE loc = decl->get_location();
+ field_type = process_array_type(&loc, decl_type, decl->array_size,
+ state);
+ }
+ fields[i].type = (field_type != NULL)
+ ? field_type : glsl_type::error_type;
+ fields[i].name = decl->identifier;
+ i++;
+ }
+ }
+
+ assert(i == decl_count);
+
+ const glsl_type *t =
+ glsl_type::get_record_instance(fields, decl_count, this->name);
+
+ YYLTYPE loc = this->get_location();
+ if (!state->symbols->add_type(name, t)) {
+ _mesa_glsl_error(& loc, state, "struct `%s' previously defined", name);
+ } else {
+ const glsl_type **s = reralloc(state, state->user_structures,
+ const glsl_type *,
+ state->num_user_structures + 1);
+ if (s != NULL) {
+ s[state->num_user_structures] = t;
+ state->user_structures = s;
+ state->num_user_structures++;
+ }
+ }
+
+ /* Structure type definitions do not have r-values.
+ */
+ return NULL;
+}
diff --git a/mesalib/src/glsl/ast_type.cpp b/mesalib/src/glsl/ast_type.cpp
index c680ae5f6..8e49bef8a 100644
--- a/mesalib/src/glsl/ast_type.cpp
+++ b/mesalib/src/glsl/ast_type.cpp
@@ -1,138 +1,138 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include "ast.h"
-extern "C" {
-#include "program/symbol_table.h"
-}
-
-void
-ast_type_specifier::print(void) const
-{
- if (type_specifier == ast_struct) {
- structure->print();
- } else {
- printf("%s ", type_name);
- }
-
- if (is_array) {
- printf("[ ");
-
- if (array_size) {
- array_size->print();
- }
-
- printf("] ");
- }
-}
-
-ast_type_specifier::ast_type_specifier(int specifier)
- : type_specifier(ast_types(specifier)), type_name(NULL), structure(NULL),
- is_array(false), array_size(NULL), precision(ast_precision_none),
- is_precision_statement(false)
-{
- static const char *const names[] = {
- "void",
- "float",
- "int",
- "uint",
- "bool",
- "vec2",
- "vec3",
- "vec4",
- "bvec2",
- "bvec3",
- "bvec4",
- "ivec2",
- "ivec3",
- "ivec4",
- "uvec2",
- "uvec3",
- "uvec4",
- "mat2",
- "mat2x3",
- "mat2x4",
- "mat3x2",
- "mat3",
- "mat3x4",
- "mat4x2",
- "mat4x3",
- "mat4",
- "sampler1D",
- "sampler2D",
- "sampler2DRect",
- "sampler3D",
- "samplerCube",
- "sampler1DShadow",
- "sampler2DShadow",
- "sampler2DRectShadow",
- "samplerCubeShadow",
- "sampler1DArray",
- "sampler2DArray",
- "sampler1DArrayShadow",
- "sampler2DArrayShadow",
- "isampler1D",
- "isampler2D",
- "isampler3D",
- "isamplerCube",
- "isampler1DArray",
- "isampler2DArray",
- "usampler1D",
- "usampler2D",
- "usampler3D",
- "usamplerCube",
- "usampler1DArray",
- "usampler2DArray",
-
- NULL, /* ast_struct */
- NULL /* ast_type_name */
- };
-
- type_name = names[specifier];
-}
-
-bool
-ast_fully_specified_type::has_qualifiers() const
-{
- return this->qualifier.flags.i != 0;
-}
-
-bool ast_type_qualifier::has_interpolation() const
-{
- return this->flags.q.smooth
- || this->flags.q.flat
- || this->flags.q.noperspective;
-}
-
-const char*
-ast_type_qualifier::interpolation_string() const
-{
- if (this->flags.q.smooth)
- return "smooth";
- else if (this->flags.q.flat)
- return "flat";
- else if (this->flags.q.noperspective)
- return "noperspective";
- else
- return NULL;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "ast.h"
+extern "C" {
+#include "program/symbol_table.h"
+}
+
+void
+ast_type_specifier::print(void) const
+{
+ if (type_specifier == ast_struct) {
+ structure->print();
+ } else {
+ printf("%s ", type_name);
+ }
+
+ if (is_array) {
+ printf("[ ");
+
+ if (array_size) {
+ array_size->print();
+ }
+
+ printf("] ");
+ }
+}
+
+ast_type_specifier::ast_type_specifier(int specifier)
+ : type_specifier(ast_types(specifier)), type_name(NULL), structure(NULL),
+ is_array(false), array_size(NULL), precision(ast_precision_none),
+ is_precision_statement(false)
+{
+ static const char *const names[] = {
+ "void",
+ "float",
+ "int",
+ "uint",
+ "bool",
+ "vec2",
+ "vec3",
+ "vec4",
+ "bvec2",
+ "bvec3",
+ "bvec4",
+ "ivec2",
+ "ivec3",
+ "ivec4",
+ "uvec2",
+ "uvec3",
+ "uvec4",
+ "mat2",
+ "mat2x3",
+ "mat2x4",
+ "mat3x2",
+ "mat3",
+ "mat3x4",
+ "mat4x2",
+ "mat4x3",
+ "mat4",
+ "sampler1D",
+ "sampler2D",
+ "sampler2DRect",
+ "sampler3D",
+ "samplerCube",
+ "sampler1DShadow",
+ "sampler2DShadow",
+ "sampler2DRectShadow",
+ "samplerCubeShadow",
+ "sampler1DArray",
+ "sampler2DArray",
+ "sampler1DArrayShadow",
+ "sampler2DArrayShadow",
+ "isampler1D",
+ "isampler2D",
+ "isampler3D",
+ "isamplerCube",
+ "isampler1DArray",
+ "isampler2DArray",
+ "usampler1D",
+ "usampler2D",
+ "usampler3D",
+ "usamplerCube",
+ "usampler1DArray",
+ "usampler2DArray",
+
+ NULL, /* ast_struct */
+ NULL /* ast_type_name */
+ };
+
+ type_name = names[specifier];
+}
+
+bool
+ast_fully_specified_type::has_qualifiers() const
+{
+ return this->qualifier.flags.i != 0;
+}
+
+bool ast_type_qualifier::has_interpolation() const
+{
+ return this->flags.q.smooth
+ || this->flags.q.flat
+ || this->flags.q.noperspective;
+}
+
+const char*
+ast_type_qualifier::interpolation_string() const
+{
+ if (this->flags.q.smooth)
+ return "smooth";
+ else if (this->flags.q.flat)
+ return "flat";
+ else if (this->flags.q.noperspective)
+ return "noperspective";
+ else
+ return NULL;
+}
diff --git a/mesalib/src/glsl/builtin_types.h b/mesalib/src/glsl/builtin_types.h
index 58b9a8127..6b98419ae 100644
--- a/mesalib/src/glsl/builtin_types.h
+++ b/mesalib/src/glsl/builtin_types.h
@@ -1,302 +1,302 @@
-/*
- * Copyright © 2009 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-const glsl_type glsl_type::_error_type =
- glsl_type(GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0, "");
-
-const glsl_type glsl_type::_void_type =
- glsl_type(GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0, "void");
-
-const glsl_type glsl_type::_sampler3D_type =
- glsl_type(GL_SAMPLER_3D, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT,
- "sampler3D");
-
-const glsl_type *const glsl_type::error_type = & glsl_type::_error_type;
-const glsl_type *const glsl_type::void_type = & glsl_type::_void_type;
-
-/** \name Core built-in types
- *
- * These types exist in all versions of GLSL.
- */
-/*@{*/
-
-const glsl_type glsl_type::builtin_core_types[] = {
- glsl_type(GL_BOOL, GLSL_TYPE_BOOL, 1, 1, "bool"),
- glsl_type(GL_BOOL_VEC2, GLSL_TYPE_BOOL, 2, 1, "bvec2"),
- glsl_type(GL_BOOL_VEC3, GLSL_TYPE_BOOL, 3, 1, "bvec3"),
- glsl_type(GL_BOOL_VEC4, GLSL_TYPE_BOOL, 4, 1, "bvec4"),
- glsl_type(GL_INT, GLSL_TYPE_INT, 1, 1, "int"),
- glsl_type(GL_INT_VEC2, GLSL_TYPE_INT, 2, 1, "ivec2"),
- glsl_type(GL_INT_VEC3, GLSL_TYPE_INT, 3, 1, "ivec3"),
- glsl_type(GL_INT_VEC4, GLSL_TYPE_INT, 4, 1, "ivec4"),
- glsl_type(GL_FLOAT, GLSL_TYPE_FLOAT, 1, 1, "float"),
- glsl_type(GL_FLOAT_VEC2, GLSL_TYPE_FLOAT, 2, 1, "vec2"),
- glsl_type(GL_FLOAT_VEC3, GLSL_TYPE_FLOAT, 3, 1, "vec3"),
- glsl_type(GL_FLOAT_VEC4, GLSL_TYPE_FLOAT, 4, 1, "vec4"),
- glsl_type(GL_FLOAT_MAT2, GLSL_TYPE_FLOAT, 2, 2, "mat2"),
- glsl_type(GL_FLOAT_MAT3, GLSL_TYPE_FLOAT, 3, 3, "mat3"),
- glsl_type(GL_FLOAT_MAT4, GLSL_TYPE_FLOAT, 4, 4, "mat4"),
- glsl_type(GL_SAMPLER_2D, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT,
- "sampler2D"),
- glsl_type(GL_SAMPLER_CUBE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_FLOAT,
- "samplerCube"),
-};
-
-const glsl_type *const glsl_type::bool_type = & builtin_core_types[0];
-const glsl_type *const glsl_type::int_type = & builtin_core_types[4];
-const glsl_type *const glsl_type::ivec4_type = & builtin_core_types[7];
-const glsl_type *const glsl_type::float_type = & builtin_core_types[8];
-const glsl_type *const glsl_type::vec2_type = & builtin_core_types[9];
-const glsl_type *const glsl_type::vec3_type = & builtin_core_types[10];
-const glsl_type *const glsl_type::vec4_type = & builtin_core_types[11];
-const glsl_type *const glsl_type::mat2_type = & builtin_core_types[12];
-const glsl_type *const glsl_type::mat3_type = & builtin_core_types[13];
-const glsl_type *const glsl_type::mat4_type = & builtin_core_types[14];
-/*@}*/
-
-/** \name GLSL structures that have not been deprecated.
- */
-/*@{*/
-
-static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = {
- { glsl_type::float_type, "near" },
- { glsl_type::float_type, "far" },
- { glsl_type::float_type, "diff" },
-};
-
-const glsl_type glsl_type::builtin_structure_types[] = {
- glsl_type(gl_DepthRangeParameters_fields,
- Elements(gl_DepthRangeParameters_fields),
- "gl_DepthRangeParameters"),
-};
-/*@}*/
-
-/** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30
- */
-/*@{*/
-
-static const struct glsl_struct_field gl_PointParameters_fields[] = {
- { glsl_type::float_type, "size" },
- { glsl_type::float_type, "sizeMin" },
- { glsl_type::float_type, "sizeMax" },
- { glsl_type::float_type, "fadeThresholdSize" },
- { glsl_type::float_type, "distanceConstantAttenuation" },
- { glsl_type::float_type, "distanceLinearAttenuation" },
- { glsl_type::float_type, "distanceQuadraticAttenuation" },
-};
-
-static const struct glsl_struct_field gl_MaterialParameters_fields[] = {
- { glsl_type::vec4_type, "emission" },
- { glsl_type::vec4_type, "ambient" },
- { glsl_type::vec4_type, "diffuse" },
- { glsl_type::vec4_type, "specular" },
- { glsl_type::float_type, "shininess" },
-};
-
-static const struct glsl_struct_field gl_LightSourceParameters_fields[] = {
- { glsl_type::vec4_type, "ambient" },
- { glsl_type::vec4_type, "diffuse" },
- { glsl_type::vec4_type, "specular" },
- { glsl_type::vec4_type, "position" },
- { glsl_type::vec4_type, "halfVector" },
- { glsl_type::vec3_type, "spotDirection" },
- { glsl_type::float_type, "spotExponent" },
- { glsl_type::float_type, "spotCutoff" },
- { glsl_type::float_type, "spotCosCutoff" },
- { glsl_type::float_type, "constantAttenuation" },
- { glsl_type::float_type, "linearAttenuation" },
- { glsl_type::float_type, "quadraticAttenuation" },
-};
-
-static const struct glsl_struct_field gl_LightModelParameters_fields[] = {
- { glsl_type::vec4_type, "ambient" },
-};
-
-static const struct glsl_struct_field gl_LightModelProducts_fields[] = {
- { glsl_type::vec4_type, "sceneColor" },
-};
-
-static const struct glsl_struct_field gl_LightProducts_fields[] = {
- { glsl_type::vec4_type, "ambient" },
- { glsl_type::vec4_type, "diffuse" },
- { glsl_type::vec4_type, "specular" },
-};
-
-static const struct glsl_struct_field gl_FogParameters_fields[] = {
- { glsl_type::vec4_type, "color" },
- { glsl_type::float_type, "density" },
- { glsl_type::float_type, "start" },
- { glsl_type::float_type, "end" },
- { glsl_type::float_type, "scale" },
-};
-
-const glsl_type glsl_type::builtin_110_deprecated_structure_types[] = {
- glsl_type(gl_PointParameters_fields,
- Elements(gl_PointParameters_fields),
- "gl_PointParameters"),
- glsl_type(gl_MaterialParameters_fields,
- Elements(gl_MaterialParameters_fields),
- "gl_MaterialParameters"),
- glsl_type(gl_LightSourceParameters_fields,
- Elements(gl_LightSourceParameters_fields),
- "gl_LightSourceParameters"),
- glsl_type(gl_LightModelParameters_fields,
- Elements(gl_LightModelParameters_fields),
- "gl_LightModelParameters"),
- glsl_type(gl_LightModelProducts_fields,
- Elements(gl_LightModelProducts_fields),
- "gl_LightModelProducts"),
- glsl_type(gl_LightProducts_fields,
- Elements(gl_LightProducts_fields),
- "gl_LightProducts"),
- glsl_type(gl_FogParameters_fields,
- Elements(gl_FogParameters_fields),
- "gl_FogParameters"),
-};
-/*@}*/
-
-/** \name Types in GLSL 1.10 (but not GLSL ES 1.00)
- */
-/*@{*/
-const glsl_type glsl_type::builtin_110_types[] = {
- glsl_type(GL_SAMPLER_1D, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT,
- "sampler1D"),
- glsl_type(GL_SAMPLER_1D_SHADOW, GLSL_SAMPLER_DIM_1D, 1, 0, GLSL_TYPE_FLOAT,
- "sampler1DShadow"),
- glsl_type(GL_SAMPLER_2D_SHADOW, GLSL_SAMPLER_DIM_2D, 1, 0, GLSL_TYPE_FLOAT,
- "sampler2DShadow"),
-};
-/*@}*/
-
-/** \name Types added in GLSL 1.20
- */
-/*@{*/
-
-const glsl_type glsl_type::builtin_120_types[] = {
- glsl_type(GL_FLOAT_MAT2x3, GLSL_TYPE_FLOAT, 3, 2, "mat2x3"),
- glsl_type(GL_FLOAT_MAT2x4, GLSL_TYPE_FLOAT, 4, 2, "mat2x4"),
- glsl_type(GL_FLOAT_MAT3x2, GLSL_TYPE_FLOAT, 2, 3, "mat3x2"),
- glsl_type(GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3, "mat3x4"),
- glsl_type(GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4, "mat4x2"),
- glsl_type(GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4, "mat4x3"),
-};
-const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0];
-const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1];
-const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2];
-const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3];
-const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4];
-const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5];
-/*@}*/
-
-/** \name Types added in GLSL 1.30
- */
-/*@{*/
-
-const glsl_type glsl_type::builtin_130_types[] = {
- glsl_type(GL_UNSIGNED_INT, GLSL_TYPE_UINT, 1, 1, "uint"),
- glsl_type(GL_UNSIGNED_INT_VEC2, GLSL_TYPE_UINT, 2, 1, "uvec2"),
- glsl_type(GL_UNSIGNED_INT_VEC3, GLSL_TYPE_UINT, 3, 1, "uvec3"),
- glsl_type(GL_UNSIGNED_INT_VEC4, GLSL_TYPE_UINT, 4, 1, "uvec4"),
-
- /* 1D and 2D texture arrays - several of these are included only in
- * builtin_EXT_texture_array_types.
- */
- glsl_type(GL_INT_SAMPLER_1D_ARRAY,
- GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_INT, "isampler1DArray"),
- glsl_type(GL_UNSIGNED_INT_SAMPLER_1D_ARRAY,
- GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_UINT, "usampler1DArray"),
- glsl_type(GL_INT_SAMPLER_2D_ARRAY,
- GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_INT, "isampler2DArray"),
- glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY,
- GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_UINT, "usampler2DArray"),
-
- /* cube shadow samplers */
- glsl_type(GL_SAMPLER_CUBE_SHADOW,
- GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT, "samplerCubeShadow"),
-
- /* signed and unsigned integer samplers */
- glsl_type(GL_INT_SAMPLER_1D,
- GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_INT, "isampler1D"),
- glsl_type(GL_UNSIGNED_INT_SAMPLER_1D,
- GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_UINT, "usampler1D"),
- glsl_type(GL_INT_SAMPLER_2D,
- GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_INT, "isampler2D"),
- glsl_type(GL_UNSIGNED_INT_SAMPLER_2D,
- GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_UINT, "usampler2D"),
- glsl_type(GL_INT_SAMPLER_3D,
- GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_INT, "isampler3D"),
- glsl_type(GL_UNSIGNED_INT_SAMPLER_3D,
- GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_UINT, "usampler3D"),
- glsl_type(GL_INT_SAMPLER_CUBE,
- GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_INT, "isamplerCube"),
- glsl_type(GL_INT_SAMPLER_CUBE,
- GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_UINT, "usamplerCube"),
-};
-
-const glsl_type *const glsl_type::uint_type = & builtin_130_types[0];
-const glsl_type *const glsl_type::uvec2_type = & builtin_130_types[1];
-const glsl_type *const glsl_type::uvec3_type = & builtin_130_types[2];
-const glsl_type *const glsl_type::uvec4_type = & builtin_130_types[3];
-/*@}*/
-
-/** \name Sampler types added by GL_ARB_texture_rectangle
- */
-/*@{*/
-
-const glsl_type glsl_type::builtin_ARB_texture_rectangle_types[] = {
- glsl_type(GL_SAMPLER_2D_RECT,
- GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_FLOAT, "sampler2DRect"),
- glsl_type(GL_SAMPLER_2D_RECT_SHADOW,
- GLSL_SAMPLER_DIM_RECT, 1, 0, GLSL_TYPE_FLOAT, "sampler2DRectShadow"),
-};
-/*@}*/
-
-/** \name Sampler types added by GL_EXT_texture_array
- */
-/*@{*/
-
-const glsl_type glsl_type::builtin_EXT_texture_array_types[] = {
- glsl_type(GL_SAMPLER_1D_ARRAY,
- GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT, "sampler1DArray"),
- glsl_type(GL_SAMPLER_2D_ARRAY,
- GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT, "sampler2DArray"),
- glsl_type(GL_SAMPLER_1D_ARRAY_SHADOW,
- GLSL_SAMPLER_DIM_1D, 1, 1, GLSL_TYPE_FLOAT, "sampler1DArrayShadow"),
- glsl_type(GL_SAMPLER_2D_ARRAY_SHADOW,
- GLSL_SAMPLER_DIM_2D, 1, 1, GLSL_TYPE_FLOAT, "sampler2DArrayShadow"),
-};
-/*@}*/
-
-/** \name Sampler types added by GL_EXT_texture_buffer_object
- */
-/*@{*/
-
-const glsl_type glsl_type::builtin_EXT_texture_buffer_object_types[] = {
- glsl_type(GL_SAMPLER_BUFFER,
- GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_FLOAT, "samplerBuffer"),
- glsl_type(GL_INT_SAMPLER_BUFFER,
- GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_INT, "isamplerBuffer"),
- glsl_type(GL_UNSIGNED_INT_SAMPLER_BUFFER,
- GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_UINT, "usamplerBuffer"),
-};
-/*@}*/
+/*
+ * Copyright © 2009 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+const glsl_type glsl_type::_error_type =
+ glsl_type(GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0, "");
+
+const glsl_type glsl_type::_void_type =
+ glsl_type(GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0, "void");
+
+const glsl_type glsl_type::_sampler3D_type =
+ glsl_type(GL_SAMPLER_3D, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT,
+ "sampler3D");
+
+const glsl_type *const glsl_type::error_type = & glsl_type::_error_type;
+const glsl_type *const glsl_type::void_type = & glsl_type::_void_type;
+
+/** \name Core built-in types
+ *
+ * These types exist in all versions of GLSL.
+ */
+/*@{*/
+
+const glsl_type glsl_type::builtin_core_types[] = {
+ glsl_type(GL_BOOL, GLSL_TYPE_BOOL, 1, 1, "bool"),
+ glsl_type(GL_BOOL_VEC2, GLSL_TYPE_BOOL, 2, 1, "bvec2"),
+ glsl_type(GL_BOOL_VEC3, GLSL_TYPE_BOOL, 3, 1, "bvec3"),
+ glsl_type(GL_BOOL_VEC4, GLSL_TYPE_BOOL, 4, 1, "bvec4"),
+ glsl_type(GL_INT, GLSL_TYPE_INT, 1, 1, "int"),
+ glsl_type(GL_INT_VEC2, GLSL_TYPE_INT, 2, 1, "ivec2"),
+ glsl_type(GL_INT_VEC3, GLSL_TYPE_INT, 3, 1, "ivec3"),
+ glsl_type(GL_INT_VEC4, GLSL_TYPE_INT, 4, 1, "ivec4"),
+ glsl_type(GL_FLOAT, GLSL_TYPE_FLOAT, 1, 1, "float"),
+ glsl_type(GL_FLOAT_VEC2, GLSL_TYPE_FLOAT, 2, 1, "vec2"),
+ glsl_type(GL_FLOAT_VEC3, GLSL_TYPE_FLOAT, 3, 1, "vec3"),
+ glsl_type(GL_FLOAT_VEC4, GLSL_TYPE_FLOAT, 4, 1, "vec4"),
+ glsl_type(GL_FLOAT_MAT2, GLSL_TYPE_FLOAT, 2, 2, "mat2"),
+ glsl_type(GL_FLOAT_MAT3, GLSL_TYPE_FLOAT, 3, 3, "mat3"),
+ glsl_type(GL_FLOAT_MAT4, GLSL_TYPE_FLOAT, 4, 4, "mat4"),
+ glsl_type(GL_SAMPLER_2D, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT,
+ "sampler2D"),
+ glsl_type(GL_SAMPLER_CUBE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_FLOAT,
+ "samplerCube"),
+};
+
+const glsl_type *const glsl_type::bool_type = & builtin_core_types[0];
+const glsl_type *const glsl_type::int_type = & builtin_core_types[4];
+const glsl_type *const glsl_type::ivec4_type = & builtin_core_types[7];
+const glsl_type *const glsl_type::float_type = & builtin_core_types[8];
+const glsl_type *const glsl_type::vec2_type = & builtin_core_types[9];
+const glsl_type *const glsl_type::vec3_type = & builtin_core_types[10];
+const glsl_type *const glsl_type::vec4_type = & builtin_core_types[11];
+const glsl_type *const glsl_type::mat2_type = & builtin_core_types[12];
+const glsl_type *const glsl_type::mat3_type = & builtin_core_types[13];
+const glsl_type *const glsl_type::mat4_type = & builtin_core_types[14];
+/*@}*/
+
+/** \name GLSL structures that have not been deprecated.
+ */
+/*@{*/
+
+static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = {
+ { glsl_type::float_type, "near" },
+ { glsl_type::float_type, "far" },
+ { glsl_type::float_type, "diff" },
+};
+
+const glsl_type glsl_type::builtin_structure_types[] = {
+ glsl_type(gl_DepthRangeParameters_fields,
+ Elements(gl_DepthRangeParameters_fields),
+ "gl_DepthRangeParameters"),
+};
+/*@}*/
+
+/** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30
+ */
+/*@{*/
+
+static const struct glsl_struct_field gl_PointParameters_fields[] = {
+ { glsl_type::float_type, "size" },
+ { glsl_type::float_type, "sizeMin" },
+ { glsl_type::float_type, "sizeMax" },
+ { glsl_type::float_type, "fadeThresholdSize" },
+ { glsl_type::float_type, "distanceConstantAttenuation" },
+ { glsl_type::float_type, "distanceLinearAttenuation" },
+ { glsl_type::float_type, "distanceQuadraticAttenuation" },
+};
+
+static const struct glsl_struct_field gl_MaterialParameters_fields[] = {
+ { glsl_type::vec4_type, "emission" },
+ { glsl_type::vec4_type, "ambient" },
+ { glsl_type::vec4_type, "diffuse" },
+ { glsl_type::vec4_type, "specular" },
+ { glsl_type::float_type, "shininess" },
+};
+
+static const struct glsl_struct_field gl_LightSourceParameters_fields[] = {
+ { glsl_type::vec4_type, "ambient" },
+ { glsl_type::vec4_type, "diffuse" },
+ { glsl_type::vec4_type, "specular" },
+ { glsl_type::vec4_type, "position" },
+ { glsl_type::vec4_type, "halfVector" },
+ { glsl_type::vec3_type, "spotDirection" },
+ { glsl_type::float_type, "spotExponent" },
+ { glsl_type::float_type, "spotCutoff" },
+ { glsl_type::float_type, "spotCosCutoff" },
+ { glsl_type::float_type, "constantAttenuation" },
+ { glsl_type::float_type, "linearAttenuation" },
+ { glsl_type::float_type, "quadraticAttenuation" },
+};
+
+static const struct glsl_struct_field gl_LightModelParameters_fields[] = {
+ { glsl_type::vec4_type, "ambient" },
+};
+
+static const struct glsl_struct_field gl_LightModelProducts_fields[] = {
+ { glsl_type::vec4_type, "sceneColor" },
+};
+
+static const struct glsl_struct_field gl_LightProducts_fields[] = {
+ { glsl_type::vec4_type, "ambient" },
+ { glsl_type::vec4_type, "diffuse" },
+ { glsl_type::vec4_type, "specular" },
+};
+
+static const struct glsl_struct_field gl_FogParameters_fields[] = {
+ { glsl_type::vec4_type, "color" },
+ { glsl_type::float_type, "density" },
+ { glsl_type::float_type, "start" },
+ { glsl_type::float_type, "end" },
+ { glsl_type::float_type, "scale" },
+};
+
+const glsl_type glsl_type::builtin_110_deprecated_structure_types[] = {
+ glsl_type(gl_PointParameters_fields,
+ Elements(gl_PointParameters_fields),
+ "gl_PointParameters"),
+ glsl_type(gl_MaterialParameters_fields,
+ Elements(gl_MaterialParameters_fields),
+ "gl_MaterialParameters"),
+ glsl_type(gl_LightSourceParameters_fields,
+ Elements(gl_LightSourceParameters_fields),
+ "gl_LightSourceParameters"),
+ glsl_type(gl_LightModelParameters_fields,
+ Elements(gl_LightModelParameters_fields),
+ "gl_LightModelParameters"),
+ glsl_type(gl_LightModelProducts_fields,
+ Elements(gl_LightModelProducts_fields),
+ "gl_LightModelProducts"),
+ glsl_type(gl_LightProducts_fields,
+ Elements(gl_LightProducts_fields),
+ "gl_LightProducts"),
+ glsl_type(gl_FogParameters_fields,
+ Elements(gl_FogParameters_fields),
+ "gl_FogParameters"),
+};
+/*@}*/
+
+/** \name Types in GLSL 1.10 (but not GLSL ES 1.00)
+ */
+/*@{*/
+const glsl_type glsl_type::builtin_110_types[] = {
+ glsl_type(GL_SAMPLER_1D, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT,
+ "sampler1D"),
+ glsl_type(GL_SAMPLER_1D_SHADOW, GLSL_SAMPLER_DIM_1D, 1, 0, GLSL_TYPE_FLOAT,
+ "sampler1DShadow"),
+ glsl_type(GL_SAMPLER_2D_SHADOW, GLSL_SAMPLER_DIM_2D, 1, 0, GLSL_TYPE_FLOAT,
+ "sampler2DShadow"),
+};
+/*@}*/
+
+/** \name Types added in GLSL 1.20
+ */
+/*@{*/
+
+const glsl_type glsl_type::builtin_120_types[] = {
+ glsl_type(GL_FLOAT_MAT2x3, GLSL_TYPE_FLOAT, 3, 2, "mat2x3"),
+ glsl_type(GL_FLOAT_MAT2x4, GLSL_TYPE_FLOAT, 4, 2, "mat2x4"),
+ glsl_type(GL_FLOAT_MAT3x2, GLSL_TYPE_FLOAT, 2, 3, "mat3x2"),
+ glsl_type(GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3, "mat3x4"),
+ glsl_type(GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4, "mat4x2"),
+ glsl_type(GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4, "mat4x3"),
+};
+const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0];
+const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1];
+const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2];
+const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3];
+const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4];
+const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5];
+/*@}*/
+
+/** \name Types added in GLSL 1.30
+ */
+/*@{*/
+
+const glsl_type glsl_type::builtin_130_types[] = {
+ glsl_type(GL_UNSIGNED_INT, GLSL_TYPE_UINT, 1, 1, "uint"),
+ glsl_type(GL_UNSIGNED_INT_VEC2, GLSL_TYPE_UINT, 2, 1, "uvec2"),
+ glsl_type(GL_UNSIGNED_INT_VEC3, GLSL_TYPE_UINT, 3, 1, "uvec3"),
+ glsl_type(GL_UNSIGNED_INT_VEC4, GLSL_TYPE_UINT, 4, 1, "uvec4"),
+
+ /* 1D and 2D texture arrays - several of these are included only in
+ * builtin_EXT_texture_array_types.
+ */
+ glsl_type(GL_INT_SAMPLER_1D_ARRAY,
+ GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_INT, "isampler1DArray"),
+ glsl_type(GL_UNSIGNED_INT_SAMPLER_1D_ARRAY,
+ GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_UINT, "usampler1DArray"),
+ glsl_type(GL_INT_SAMPLER_2D_ARRAY,
+ GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_INT, "isampler2DArray"),
+ glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY,
+ GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_UINT, "usampler2DArray"),
+
+ /* cube shadow samplers */
+ glsl_type(GL_SAMPLER_CUBE_SHADOW,
+ GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT, "samplerCubeShadow"),
+
+ /* signed and unsigned integer samplers */
+ glsl_type(GL_INT_SAMPLER_1D,
+ GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_INT, "isampler1D"),
+ glsl_type(GL_UNSIGNED_INT_SAMPLER_1D,
+ GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_UINT, "usampler1D"),
+ glsl_type(GL_INT_SAMPLER_2D,
+ GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_INT, "isampler2D"),
+ glsl_type(GL_UNSIGNED_INT_SAMPLER_2D,
+ GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_UINT, "usampler2D"),
+ glsl_type(GL_INT_SAMPLER_3D,
+ GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_INT, "isampler3D"),
+ glsl_type(GL_UNSIGNED_INT_SAMPLER_3D,
+ GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_UINT, "usampler3D"),
+ glsl_type(GL_INT_SAMPLER_CUBE,
+ GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_INT, "isamplerCube"),
+ glsl_type(GL_INT_SAMPLER_CUBE,
+ GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_UINT, "usamplerCube"),
+};
+
+const glsl_type *const glsl_type::uint_type = & builtin_130_types[0];
+const glsl_type *const glsl_type::uvec2_type = & builtin_130_types[1];
+const glsl_type *const glsl_type::uvec3_type = & builtin_130_types[2];
+const glsl_type *const glsl_type::uvec4_type = & builtin_130_types[3];
+/*@}*/
+
+/** \name Sampler types added by GL_ARB_texture_rectangle
+ */
+/*@{*/
+
+const glsl_type glsl_type::builtin_ARB_texture_rectangle_types[] = {
+ glsl_type(GL_SAMPLER_2D_RECT,
+ GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_FLOAT, "sampler2DRect"),
+ glsl_type(GL_SAMPLER_2D_RECT_SHADOW,
+ GLSL_SAMPLER_DIM_RECT, 1, 0, GLSL_TYPE_FLOAT, "sampler2DRectShadow"),
+};
+/*@}*/
+
+/** \name Sampler types added by GL_EXT_texture_array
+ */
+/*@{*/
+
+const glsl_type glsl_type::builtin_EXT_texture_array_types[] = {
+ glsl_type(GL_SAMPLER_1D_ARRAY,
+ GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT, "sampler1DArray"),
+ glsl_type(GL_SAMPLER_2D_ARRAY,
+ GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT, "sampler2DArray"),
+ glsl_type(GL_SAMPLER_1D_ARRAY_SHADOW,
+ GLSL_SAMPLER_DIM_1D, 1, 1, GLSL_TYPE_FLOAT, "sampler1DArrayShadow"),
+ glsl_type(GL_SAMPLER_2D_ARRAY_SHADOW,
+ GLSL_SAMPLER_DIM_2D, 1, 1, GLSL_TYPE_FLOAT, "sampler2DArrayShadow"),
+};
+/*@}*/
+
+/** \name Sampler types added by GL_EXT_texture_buffer_object
+ */
+/*@{*/
+
+const glsl_type glsl_type::builtin_EXT_texture_buffer_object_types[] = {
+ glsl_type(GL_SAMPLER_BUFFER,
+ GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_FLOAT, "samplerBuffer"),
+ glsl_type(GL_INT_SAMPLER_BUFFER,
+ GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_INT, "isamplerBuffer"),
+ glsl_type(GL_UNSIGNED_INT_SAMPLER_BUFFER,
+ GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_UINT, "usamplerBuffer"),
+};
+/*@}*/
diff --git a/mesalib/src/glsl/doflex.bat b/mesalib/src/glsl/doflex.bat
new file mode 100644
index 000000000..9a0c71200
--- /dev/null
+++ b/mesalib/src/glsl/doflex.bat
@@ -0,0 +1,17 @@
+@echo off
+setlocal
+
+cd "%~dp0"
+
+set M4=..\..\..\tools\mhmake\m4.exe
+
+set path=..\..\..\tools\mhmake;%path%
+
+copy "..\..\..\tools\mhmake\flex++.exe" flex.exe
+
+flex.exe --nounistd -oglsl_lexer.cpp glsl_lexer.ll
+flex.exe --nounistd -oglcpp/glcpp-lex.c glcpp/glcpp-lex.l
+del flex.exe
+
+endlocal
+
diff --git a/mesalib/src/glsl/getopt.cpp b/mesalib/src/glsl/getopt.cpp
new file mode 100644
index 000000000..ea5dd3927
--- /dev/null
+++ b/mesalib/src/glsl/getopt.cpp
@@ -0,0 +1,552 @@
+/* $OpenBSD: getopt_long.c,v 1.20 2005/10/25 15:49:37 jmc Exp $ */
+/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
+// Adapted for Box Backup by Chris Wilson <chris+boxbackup@qwirx.com>
+
+/*
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// #include "Box.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define __STDC__ 1
+
+#include "getopt.h"
+
+#if defined _MSC_VER || defined __MINGW32__
+#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
+
+#ifdef REPLACE_GETOPT
+int opterr = 1; /* if error message should be printed */
+int optind = 1; /* index into parent argv vector */
+int optopt = '?'; /* character checked for validity */
+int optreset; /* reset getopt */
+char *optarg; /* argument associated with option */
+#endif
+
+#define PRINT_ERROR ((opterr) && (*options != ':'))
+
+#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
+#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
+#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
+
+/* return values */
+#define BADCH (int)'?'
+#define BADARG ((*options == ':') ? (int)':' : (int)'?')
+#define INORDER (int)1
+
+#define EMSG ""
+
+static void warnx(const char* fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+ }
+
+ static int getopt_internal(int, char * const *, const char *,
+ const struct option *, int *, int);
+ static int parse_long_options(char * const *, const char *,
+ const struct option *, int *, int);
+ static int gcd(int, int);
+ static void permute_args(int, int, int, char * const *);
+
+ static char *place = EMSG; /* option letter processing */
+
+ /* XXX: set optreset to 1 rather than these two */
+ static int nonopt_start = -1; /* first non option argument (for permute) */
+ static int nonopt_end = -1; /* first option after non options (for permute) */
+
+ /* Error messages */
+ static const char recargchar[] = "option requires an argument -- %c";
+ static const char recargstring[] = "option requires an argument -- %s";
+ static const char ambig[] = "ambiguous option -- %.*s";
+ static const char noarg[] = "option doesn't take an argument -- %.*s";
+ static const char illoptchar[] = "unknown option -- %c";
+ static const char illoptstring[] = "unknown option -- %s";
+
+ /*
+ * Compute the greatest common divisor of a and b.
+ */
+ static int
+ gcd(int a, int b)
+ {
+ int c;
+
+ c = a % b;
+ while (c != 0) {
+ a = b;
+ b = c;
+ c = a % b;
+ }
+
+ return (b);
+ }
+
+ /*
+ * Exchange the block from nonopt_start to nonopt_end with the block
+ * from nonopt_end to opt_end (keeping the same order of arguments
+ * in each block).
+ */
+ static void
+ permute_args(int panonopt_start, int panonopt_end, int opt_end,
+ char * const *nargv)
+ {
+ int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+ char *swap;
+
+ /*
+ * compute lengths of blocks and number and size of cycles
+ */
+ nnonopts = panonopt_end - panonopt_start;
+ nopts = opt_end - panonopt_end;
+ ncycle = gcd(nnonopts, nopts);
+ cyclelen = (opt_end - panonopt_start) / ncycle;
+
+ for (i = 0; i < ncycle; i++) {
+ cstart = panonopt_end+i;
+ pos = cstart;
+ for (j = 0; j < cyclelen; j++) {
+ if (pos >= panonopt_end)
+ pos -= nnonopts;
+ else
+ pos += nopts;
+ swap = nargv[pos];
+ /* LINTED const cast */
+ ((char **) nargv)[pos] = nargv[cstart];
+ /* LINTED const cast */
+ ((char **)nargv)[cstart] = swap;
+ }
+ }
+ }
+
+ /*
+ * parse_long_options --
+ * Parse long options in argc/argv argument vector.
+ * Returns -1 if short_too is set and the option does not match long_options.
+ */
+ static int
+ parse_long_options(char * const *nargv, const char *options,
+ const struct option *long_options, int *idx, int short_too)
+ {
+ char *current_argv, *has_equal;
+ size_t current_argv_len;
+ int i, match;
+
+ current_argv = place;
+ match = -1;
+
+ optind++;
+
+ if ((has_equal = strchr(current_argv, '=')) != NULL) {
+ /* argument found (--option=arg) */
+ current_argv_len = has_equal - current_argv;
+ has_equal++;
+ } else
+ current_argv_len = strlen(current_argv);
+
+ for (i = 0; long_options[i].name; i++) {
+ /* find matching long option */
+ if (strncmp(current_argv, long_options[i].name,
+ current_argv_len))
+ continue;
+
+ if (strlen(long_options[i].name) == current_argv_len) {
+ /* exact match */
+ match = i;
+ break;
+ }
+ /*
+ * If this is a known short option, don't allow
+ * a partial match of a single character.
+ */
+ if (short_too && current_argv_len == 1)
+ continue;
+
+ if (match == -1) /* partial match */
+ match = i;
+ else {
+ /* ambiguous abbreviation */
+ if (PRINT_ERROR)
+ warnx(ambig, (int)current_argv_len,
+ current_argv);
+ optopt = 0;
+ return (BADCH);
+ }
+ }
+ if (match != -1) { /* option found */
+ if (long_options[match].has_arg == no_argument
+ && has_equal) {
+ if (PRINT_ERROR)
+ warnx(noarg, (int)current_argv_len,
+ current_argv);
+ /*
+ * XXX: GNU sets optopt to val regardless of flag
+ */
+ if (long_options[match].flag == NULL)
+ optopt = long_options[match].val;
+ else
+ optopt = 0;
+ return (BADARG);
+ }
+ if (long_options[match].has_arg == required_argument ||
+ long_options[match].has_arg == optional_argument) {
+ if (has_equal)
+ optarg = has_equal;
+ else if (long_options[match].has_arg ==
+ required_argument) {
+ /*
+ * optional argument doesn't use next nargv
+ */
+ optarg = nargv[optind++];
+ }
+ }
+ if ((long_options[match].has_arg == required_argument)
+ && (optarg == NULL)) {
+ /*
+ * Missing argument; leading ':' indicates no error
+ * should be generated.
+ */
+ if (PRINT_ERROR)
+ warnx(recargstring,
+ current_argv);
+ /*
+ * XXX: GNU sets optopt to val regardless of flag
+ */
+ if (long_options[match].flag == NULL)
+ optopt = long_options[match].val;
+ else
+ optopt = 0;
+ --optind;
+ return (BADARG);
+ }
+ } else { /* unknown option */
+ if (short_too) {
+ --optind;
+ return (-1);
+ }
+ if (PRINT_ERROR)
+ warnx(illoptstring, current_argv);
+ optopt = 0;
+ return (BADCH);
+ }
+ if (idx)
+ *idx = match;
+ if (long_options[match].flag) {
+ *long_options[match].flag = long_options[match].val;
+ return (0);
+ } else
+ return (long_options[match].val);
+ }
+
+ /*
+ * getopt_internal --
+ * Parse argc/argv argument vector. Called by user level routines.
+ */
+ static int
+ getopt_internal(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx, int flags)
+ {
+ const char * oli; /* option letter list index */
+ int optchar, short_too;
+ static int posixly_correct = -1;
+
+ if (options == NULL)
+ return (-1);
+
+ /*
+ * Disable GNU extensions if POSIXLY_CORRECT is set or options
+ * string begins with a '+'.
+ */
+ if (posixly_correct == -1)
+ posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
+ if (posixly_correct || *options == '+')
+ flags &= ~FLAG_PERMUTE;
+ else if (*options == '-')
+ flags |= FLAG_ALLARGS;
+ if (*options == '+' || *options == '-')
+ options++;
+
+ /*
+ * XXX Some GNU programs (like cvs) set optind to 0 instead of
+ * XXX using optreset. Work around this braindamage.
+ */
+ if (optind == 0)
+ optind = optreset = 1;
+
+ optarg = NULL;
+ if (optreset)
+ nonopt_start = nonopt_end = -1;
+ start:
+ if (optreset || !*place) { /* update scanning pointer */
+ optreset = 0;
+ if (optind >= nargc) { /* end of argument vector */
+ place = EMSG;
+ if (nonopt_end != -1) {
+ /* do permutation, if we have to */
+ permute_args(nonopt_start, nonopt_end,
+ optind, nargv);
+ optind -= nonopt_end - nonopt_start;
+ }
+ else if (nonopt_start != -1) {
+ /*
+ * If we skipped non-options, set optind
+ * to the first of them.
+ */
+ optind = nonopt_start;
+ }
+ nonopt_start = nonopt_end = -1;
+ return (-1);
+ }
+ if (*(place = nargv[optind]) != '-' ||
+ (place[1] == '\0' && strchr(options, '-') == NULL)) {
+ place = EMSG; /* found non-option */
+ if (flags & FLAG_ALLARGS) {
+ /*
+ * GNU extension:
+ * return non-option as argument to option 1
+ */
+ optarg = nargv[optind++];
+ return (INORDER);
+ }
+ if (!(flags & FLAG_PERMUTE)) {
+ /*
+ * If no permutation wanted, stop parsing
+ * at first non-option.
+ */
+ return (-1);
+ }
+ /* do permutation */
+ if (nonopt_start == -1)
+ nonopt_start = optind;
+ else if (nonopt_end != -1) {
+ permute_args(nonopt_start, nonopt_end,
+ optind, nargv);
+ nonopt_start = optind -
+ (nonopt_end - nonopt_start);
+ nonopt_end = -1;
+ }
+ optind++;
+ /* process next argument */
+ goto start;
+ }
+ if (nonopt_start != -1 && nonopt_end == -1)
+ nonopt_end = optind;
+
+ /*
+ * If we have "-" do nothing, if "--" we are done.
+ */
+ if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
+ optind++;
+ place = EMSG;
+ /*
+ * We found an option (--), so if we skipped
+ * non-options, we have to permute.
+ */
+ if (nonopt_end != -1) {
+ permute_args(nonopt_start, nonopt_end,
+ optind, nargv);
+ optind -= nonopt_end - nonopt_start;
+ }
+ nonopt_start = nonopt_end = -1;
+ return (-1);
+ }
+ }
+
+ /*
+ * Check long options if:
+ * 1) we were passed some
+ * 2) the arg is not just "-"
+ * 3) either the arg starts with -- we are getopt_long_only()
+ */
+ if (long_options != NULL && place != nargv[optind] &&
+ (*place == '-' || (flags & FLAG_LONGONLY))) {
+ short_too = 0;
+ if (*place == '-')
+ place++; /* --foo long option */
+ else if (*place != ':' && strchr(options, *place) != NULL)
+ short_too = 1; /* could be short option too */
+
+ optchar = parse_long_options(nargv, options, long_options,
+ idx, short_too);
+ if (optchar != -1) {
+ place = EMSG;
+ return (optchar);
+ }
+ }
+
+ if ((optchar = (int)*place++) == (int)':' ||
+ optchar == (int)'-' && *place != '\0' ||
+ (oli = strchr(options, optchar)) == NULL) {
+ /*
+ * If the user specified "-" and '-' isn't listed in
+ * options, return -1 (non-option) as per POSIX.
+ * Otherwise, it is an unknown option character (or ':').
+ */
+ if (optchar == (int)'-' && *place == '\0')
+ return (-1);
+ if (!*place)
+ ++optind;
+ if (PRINT_ERROR)
+ warnx(illoptchar, optchar);
+ optopt = optchar;
+ return (BADCH);
+ }
+ if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+ /* -W long-option */
+ if (*place) /* no space */
+ /* NOTHING */;
+ else if (++optind >= nargc) { /* no arg */
+ place = EMSG;
+ if (PRINT_ERROR)
+ warnx(recargchar, optchar);
+ optopt = optchar;
+ return (BADARG);
+ } else /* white space */
+ place = nargv[optind];
+ optchar = parse_long_options(nargv, options, long_options,
+ idx, 0);
+ place = EMSG;
+ return (optchar);
+ }
+ if (*++oli != ':') { /* doesn't take argument */
+ if (!*place)
+ ++optind;
+ } else { /* takes (optional) argument */
+ optarg = NULL;
+ if (*place) /* no white space */
+ optarg = place;
+ /* XXX: disable test for :: if PC? (GNU doesn't) */
+ else if (oli[1] != ':') { /* arg not optional */
+ if (++optind >= nargc) { /* no arg */
+ place = EMSG;
+ if (PRINT_ERROR)
+ warnx(recargchar, optchar);
+ optopt = optchar;
+ return (BADARG);
+ } else
+ optarg = nargv[optind];
+ } else if (!(flags & FLAG_PERMUTE)) {
+ /*
+ * If permutation is disabled, we can accept an
+ * optional arg separated by whitespace so long
+ * as it does not start with a dash (-).
+ */
+ if (optind + 1 < nargc && *nargv[optind + 1] != '-')
+ optarg = nargv[++optind];
+ }
+ place = EMSG;
+ ++optind;
+ }
+ /* dump back option letter */
+ return (optchar);
+ }
+
+ #ifdef REPLACE_GETOPT
+ /*
+ * getopt --
+ * Parse argc/argv argument vector.
+ *
+ * [eventually this will replace the BSD getopt]
+ */
+ int
+ getopt(int nargc, char * const *nargv, const char *options)
+ {
+
+ /*
+ * We don't pass FLAG_PERMUTE to getopt_internal() since
+ * the BSD getopt(3) (unlike GNU) has never done this.
+ *
+ * Furthermore, since many privileged programs call getopt()
+ * before dropping privileges it makes sense to keep things
+ * as simple (and bug-free) as possible.
+ */
+ return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
+ }
+ #endif /* REPLACE_GETOPT */
+
+ /*
+ * getopt_long --
+ * Parse argc/argv argument vector.
+ */
+ int
+ getopt_long(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx)
+ {
+
+ return (getopt_internal(nargc, nargv, options, long_options, idx,
+ FLAG_PERMUTE));
+ }
+
+ /*
+ * getopt_long_only --
+ * Parse argc/argv argument vector.
+ */
+ int
+ getopt_long_only(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx)
+ {
+
+ return (getopt_internal(nargc, nargv, options, long_options, idx,
+ FLAG_PERMUTE|FLAG_LONGONLY));
+ }
+
+#endif // defined _MSC_VER || defined __MINGW32__ \ No newline at end of file
diff --git a/mesalib/src/glsl/glcpp/glcpp.c b/mesalib/src/glsl/glcpp/glcpp.c
index 564194caa..62065481c 100644
--- a/mesalib/src/glsl/glcpp/glcpp.c
+++ b/mesalib/src/glsl/glcpp/glcpp.c
@@ -31,6 +31,14 @@
#include "main/mtypes.h"
#include "main/shaderobj.h"
+#ifdef _MSC_VER
+#include <io.h>
+#define STDIN_FILENO 0
+#define read _read
+#define open _open
+#define close _close
+#endif
+
extern int yydebug;
void
diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp
index e8c60936f..f18ec2ae2 100644
--- a/mesalib/src/glsl/glsl_parser_extras.cpp
+++ b/mesalib/src/glsl/glsl_parser_extras.cpp
@@ -1,831 +1,831 @@
-/*
- * Copyright © 2008, 2009 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <assert.h>
-
-extern "C" {
-#include "main/core.h" /* for struct gl_context */
-}
-
-#include "ralloc.h"
-#include "ast.h"
-#include "glsl_parser_extras.h"
-#include "glsl_parser.h"
-#include "ir_optimization.h"
-#include "loop_analysis.h"
-
-_mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *ctx,
- GLenum target, void *mem_ctx)
-{
- switch (target) {
- case GL_VERTEX_SHADER: this->target = vertex_shader; break;
- case GL_FRAGMENT_SHADER: this->target = fragment_shader; break;
- case GL_GEOMETRY_SHADER: this->target = geometry_shader; break;
- }
-
- this->scanner = NULL;
- this->translation_unit.make_empty();
- this->symbols = new(mem_ctx) glsl_symbol_table;
- this->info_log = ralloc_strdup(mem_ctx, "");
- this->error = false;
- this->loop_or_switch_nesting = NULL;
-
- /* Set default language version and extensions */
- this->language_version = 110;
- this->es_shader = false;
- this->ARB_texture_rectangle_enable = true;
-
- /* OpenGL ES 2.0 has different defaults from desktop GL. */
- if (ctx->API == API_OPENGLES2) {
- this->language_version = 100;
- this->es_shader = true;
- this->ARB_texture_rectangle_enable = false;
- }
-
- this->extensions = &ctx->Extensions;
-
- this->Const.MaxLights = ctx->Const.MaxLights;
- this->Const.MaxClipPlanes = ctx->Const.MaxClipPlanes;
- this->Const.MaxTextureUnits = ctx->Const.MaxTextureUnits;
- this->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
- this->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs;
- this->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents;
- this->Const.MaxVaryingFloats = ctx->Const.MaxVarying * 4;
- this->Const.MaxVertexTextureImageUnits = ctx->Const.MaxVertexTextureImageUnits;
- this->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits;
- this->Const.MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
- this->Const.MaxFragmentUniformComponents = ctx->Const.FragmentProgram.MaxUniformComponents;
-
- this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
-
- /* Note: Once the OpenGL 3.0 'forward compatible' context or the OpenGL 3.2
- * Core context is supported, this logic will need change. Older versions of
- * GLSL are no longer supported outside the compatibility contexts of 3.x.
- */
- this->Const.GLSL_100ES = (ctx->API == API_OPENGLES2)
- || ctx->Extensions.ARB_ES2_compatibility;
- this->Const.GLSL_110 = (ctx->API == API_OPENGL);
- this->Const.GLSL_120 = (ctx->API == API_OPENGL)
- && (ctx->Const.GLSLVersion >= 120);
- this->Const.GLSL_130 = (ctx->API == API_OPENGL)
- && (ctx->Const.GLSLVersion >= 130);
-
- const unsigned lowest_version =
- (ctx->API == API_OPENGLES2) || ctx->Extensions.ARB_ES2_compatibility
- ? 100 : 110;
- const unsigned highest_version =
- (ctx->API == API_OPENGL) ? ctx->Const.GLSLVersion : 100;
- char *supported = ralloc_strdup(this, "");
-
- for (unsigned ver = lowest_version; ver <= highest_version; ver += 10) {
- const char *const prefix = (ver == lowest_version)
- ? ""
- : ((ver == highest_version) ? ", and " : ", ");
-
- ralloc_asprintf_append(& supported, "%s%d.%02d%s",
- prefix,
- ver / 100, ver % 100,
- (ver == 100) ? " ES" : "");
- }
-
- this->supported_version_string = supported;
-}
-
-const char *
-_mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target)
-{
- switch (target) {
- case vertex_shader: return "vertex";
- case fragment_shader: return "fragment";
- case geometry_shader: return "geometry";
- }
-
- assert(!"Should not get here.");
- return "unknown";
-}
-
-
-void
-_mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
- const char *fmt, ...)
-{
- va_list ap;
-
- state->error = true;
-
- assert(state->info_log != NULL);
- ralloc_asprintf_append(&state->info_log, "%u:%u(%u): error: ",
- locp->source,
- locp->first_line,
- locp->first_column);
- va_start(ap, fmt);
- ralloc_vasprintf_append(&state->info_log, fmt, ap);
- va_end(ap);
- ralloc_strcat(&state->info_log, "\n");
-}
-
-
-void
-_mesa_glsl_warning(const YYLTYPE *locp, _mesa_glsl_parse_state *state,
- const char *fmt, ...)
-{
- va_list ap;
-
- assert(state->info_log != NULL);
- ralloc_asprintf_append(&state->info_log, "%u:%u(%u): warning: ",
- locp->source,
- locp->first_line,
- locp->first_column);
- va_start(ap, fmt);
- ralloc_vasprintf_append(&state->info_log, fmt, ap);
- va_end(ap);
- ralloc_strcat(&state->info_log, "\n");
-}
-
-
-bool
-_mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp,
- const char *behavior, YYLTYPE *behavior_locp,
- _mesa_glsl_parse_state *state)
-{
- enum {
- extension_disable,
- extension_enable,
- extension_require,
- extension_warn
- } ext_mode;
-
- if (strcmp(behavior, "warn") == 0) {
- ext_mode = extension_warn;
- } else if (strcmp(behavior, "require") == 0) {
- ext_mode = extension_require;
- } else if (strcmp(behavior, "enable") == 0) {
- ext_mode = extension_enable;
- } else if (strcmp(behavior, "disable") == 0) {
- ext_mode = extension_disable;
- } else {
- _mesa_glsl_error(behavior_locp, state,
- "Unknown extension behavior `%s'",
- behavior);
- return false;
- }
-
- bool unsupported = false;
-
- if (strcmp(name, "all") == 0) {
- if ((ext_mode == extension_enable) || (ext_mode == extension_require)) {
- _mesa_glsl_error(name_locp, state, "Cannot %s all extensions",
- (ext_mode == extension_enable)
- ? "enable" : "require");
- return false;
- }
- } else if (strcmp(name, "GL_ARB_draw_buffers") == 0) {
- /* This extension is only supported in fragment shaders.
- */
- if (state->target != fragment_shader) {
- unsupported = true;
- } else {
- state->ARB_draw_buffers_enable = (ext_mode != extension_disable);
- state->ARB_draw_buffers_warn = (ext_mode == extension_warn);
- }
- } else if (strcmp(name, "GL_ARB_draw_instanced") == 0) {
- /* This extension is only supported in vertex shaders.
- */
- if (state->target != vertex_shader) {
- unsupported = true;
- } else {
- state->ARB_draw_instanced_enable = (ext_mode != extension_disable);
- state->ARB_draw_instanced_warn = (ext_mode == extension_warn);
- }
- } else if (strcmp(name, "GL_ARB_explicit_attrib_location") == 0) {
- state->ARB_explicit_attrib_location_enable =
- (ext_mode != extension_disable);
- state->ARB_explicit_attrib_location_warn =
- (ext_mode == extension_warn);
-
- unsupported = !state->extensions->ARB_explicit_attrib_location;
- } else if (strcmp(name, "GL_ARB_fragment_coord_conventions") == 0) {
- state->ARB_fragment_coord_conventions_enable =
- (ext_mode != extension_disable);
- state->ARB_fragment_coord_conventions_warn =
- (ext_mode == extension_warn);
-
- unsupported = !state->extensions->ARB_fragment_coord_conventions;
- } else if (strcmp(name, "GL_ARB_texture_rectangle") == 0) {
- state->ARB_texture_rectangle_enable = (ext_mode != extension_disable);
- state->ARB_texture_rectangle_warn = (ext_mode == extension_warn);
- } else if (strcmp(name, "GL_EXT_texture_array") == 0) {
- state->EXT_texture_array_enable = (ext_mode != extension_disable);
- state->EXT_texture_array_warn = (ext_mode == extension_warn);
-
- unsupported = !state->extensions->EXT_texture_array;
- } else if (strcmp(name, "GL_ARB_shader_stencil_export") == 0) {
- if (state->target != fragment_shader) {
- unsupported = true;
- } else {
- state->ARB_shader_stencil_export_enable = (ext_mode != extension_disable);
- state->ARB_shader_stencil_export_warn = (ext_mode == extension_warn);
- unsupported = !state->extensions->ARB_shader_stencil_export;
- }
- } else if (strcmp(name, "GL_AMD_conservative_depth") == 0) {
- /* The AMD_conservative spec does not forbid requiring the extension in
- * the vertex shader.
- */
- state->AMD_conservative_depth_enable = (ext_mode != extension_disable);
- state->AMD_conservative_depth_warn = (ext_mode == extension_warn);
- unsupported = !state->extensions->AMD_conservative_depth;
- } else if (strcmp(name, "GL_OES_texture_3D") == 0 && state->es_shader) {
- state->OES_texture_3D_enable = (ext_mode != extension_disable);
- state->OES_texture_3D_warn = (ext_mode == extension_warn);
-
- unsupported = !state->extensions->EXT_texture3D;
- } else {
- unsupported = true;
- }
-
- if (unsupported) {
- static const char *const fmt = "extension `%s' unsupported in %s shader";
-
- if (ext_mode == extension_require) {
- _mesa_glsl_error(name_locp, state, fmt,
- name, _mesa_glsl_shader_target_name(state->target));
- return false;
- } else {
- _mesa_glsl_warning(name_locp, state, fmt,
- name, _mesa_glsl_shader_target_name(state->target));
- }
- }
-
- return true;
-}
-
-void
-_mesa_ast_type_qualifier_print(const struct ast_type_qualifier *q)
-{
- if (q->flags.q.constant)
- printf("const ");
-
- if (q->flags.q.invariant)
- printf("invariant ");
-
- if (q->flags.q.attribute)
- printf("attribute ");
-
- if (q->flags.q.varying)
- printf("varying ");
-
- if (q->flags.q.in && q->flags.q.out)
- printf("inout ");
- else {
- if (q->flags.q.in)
- printf("in ");
-
- if (q->flags.q.out)
- printf("out ");
- }
-
- if (q->flags.q.centroid)
- printf("centroid ");
- if (q->flags.q.uniform)
- printf("uniform ");
- if (q->flags.q.smooth)
- printf("smooth ");
- if (q->flags.q.flat)
- printf("flat ");
- if (q->flags.q.noperspective)
- printf("noperspective ");
-}
-
-
-void
-ast_node::print(void) const
-{
- printf("unhandled node ");
-}
-
-
-ast_node::ast_node(void)
-{
- this->location.source = 0;
- this->location.line = 0;
- this->location.column = 0;
-}
-
-
-static void
-ast_opt_array_size_print(bool is_array, const ast_expression *array_size)
-{
- if (is_array) {
- printf("[ ");
-
- if (array_size)
- array_size->print();
-
- printf("] ");
- }
-}
-
-
-void
-ast_compound_statement::print(void) const
-{
- printf("{\n");
-
- foreach_list_const(n, &this->statements) {
- ast_node *ast = exec_node_data(ast_node, n, link);
- ast->print();
- }
-
- printf("}\n");
-}
-
-
-ast_compound_statement::ast_compound_statement(int new_scope,
- ast_node *statements)
-{
- this->new_scope = new_scope;
-
- if (statements != NULL) {
- this->statements.push_degenerate_list_at_head(&statements->link);
- }
-}
-
-
-void
-ast_expression::print(void) const
-{
- switch (oper) {
- case ast_assign:
- case ast_mul_assign:
- case ast_div_assign:
- case ast_mod_assign:
- case ast_add_assign:
- case ast_sub_assign:
- case ast_ls_assign:
- case ast_rs_assign:
- case ast_and_assign:
- case ast_xor_assign:
- case ast_or_assign:
- subexpressions[0]->print();
- printf("%s ", operator_string(oper));
- subexpressions[1]->print();
- break;
-
- case ast_field_selection:
- subexpressions[0]->print();
- printf(". %s ", primary_expression.identifier);
- break;
-
- case ast_plus:
- case ast_neg:
- case ast_bit_not:
- case ast_logic_not:
- case ast_pre_inc:
- case ast_pre_dec:
- printf("%s ", operator_string(oper));
- subexpressions[0]->print();
- break;
-
- case ast_post_inc:
- case ast_post_dec:
- subexpressions[0]->print();
- printf("%s ", operator_string(oper));
- break;
-
- case ast_conditional:
- subexpressions[0]->print();
- printf("? ");
- subexpressions[1]->print();
- printf(": ");
- subexpressions[1]->print();
- break;
-
- case ast_array_index:
- subexpressions[0]->print();
- printf("[ ");
- subexpressions[1]->print();
- printf("] ");
- break;
-
- case ast_function_call: {
- subexpressions[0]->print();
- printf("( ");
-
- foreach_list_const (n, &this->expressions) {
- if (n != this->expressions.get_head())
- printf(", ");
-
- ast_node *ast = exec_node_data(ast_node, n, link);
- ast->print();
- }
-
- printf(") ");
- break;
- }
-
- case ast_identifier:
- printf("%s ", primary_expression.identifier);
- break;
-
- case ast_int_constant:
- printf("%d ", primary_expression.int_constant);
- break;
-
- case ast_uint_constant:
- printf("%u ", primary_expression.uint_constant);
- break;
-
- case ast_float_constant:
- printf("%f ", primary_expression.float_constant);
- break;
-
- case ast_bool_constant:
- printf("%s ",
- primary_expression.bool_constant
- ? "true" : "false");
- break;
-
- case ast_sequence: {
- printf("( ");
- foreach_list_const(n, & this->expressions) {
- if (n != this->expressions.get_head())
- printf(", ");
-
- ast_node *ast = exec_node_data(ast_node, n, link);
- ast->print();
- }
- printf(") ");
- break;
- }
-
- default:
- assert(0);
- break;
- }
-}
-
-ast_expression::ast_expression(int oper,
- ast_expression *ex0,
- ast_expression *ex1,
- ast_expression *ex2)
-{
- this->oper = ast_operators(oper);
- this->subexpressions[0] = ex0;
- this->subexpressions[1] = ex1;
- this->subexpressions[2] = ex2;
-}
-
-
-void
-ast_expression_statement::print(void) const
-{
- if (expression)
- expression->print();
-
- printf("; ");
-}
-
-
-ast_expression_statement::ast_expression_statement(ast_expression *ex) :
- expression(ex)
-{
- /* empty */
-}
-
-
-void
-ast_function::print(void) const
-{
- return_type->print();
- printf(" %s (", identifier);
-
- foreach_list_const(n, & this->parameters) {
- ast_node *ast = exec_node_data(ast_node, n, link);
- ast->print();
- }
-
- printf(")");
-}
-
-
-ast_function::ast_function(void)
- : is_definition(false), signature(NULL)
-{
- /* empty */
-}
-
-
-void
-ast_fully_specified_type::print(void) const
-{
- _mesa_ast_type_qualifier_print(& qualifier);
- specifier->print();
-}
-
-
-void
-ast_parameter_declarator::print(void) const
-{
- type->print();
- if (identifier)
- printf("%s ", identifier);
- ast_opt_array_size_print(is_array, array_size);
-}
-
-
-void
-ast_function_definition::print(void) const
-{
- prototype->print();
- body->print();
-}
-
-
-void
-ast_declaration::print(void) const
-{
- printf("%s ", identifier);
- ast_opt_array_size_print(is_array, array_size);
-
- if (initializer) {
- printf("= ");
- initializer->print();
- }
-}
-
-
-ast_declaration::ast_declaration(char *identifier, int is_array,
- ast_expression *array_size,
- ast_expression *initializer)
-{
- this->identifier = identifier;
- this->is_array = is_array;
- this->array_size = array_size;
- this->initializer = initializer;
-}
-
-
-void
-ast_declarator_list::print(void) const
-{
- assert(type || invariant);
-
- if (type)
- type->print();
- else
- printf("invariant ");
-
- foreach_list_const (ptr, & this->declarations) {
- if (ptr != this->declarations.get_head())
- printf(", ");
-
- ast_node *ast = exec_node_data(ast_node, ptr, link);
- ast->print();
- }
-
- printf("; ");
-}
-
-
-ast_declarator_list::ast_declarator_list(ast_fully_specified_type *type)
-{
- this->type = type;
- this->invariant = false;
-}
-
-void
-ast_jump_statement::print(void) const
-{
- switch (mode) {
- case ast_continue:
- printf("continue; ");
- break;
- case ast_break:
- printf("break; ");
- break;
- case ast_return:
- printf("return ");
- if (opt_return_value)
- opt_return_value->print();
-
- printf("; ");
- break;
- case ast_discard:
- printf("discard; ");
- break;
- }
-}
-
-
-ast_jump_statement::ast_jump_statement(int mode, ast_expression *return_value)
-{
- this->mode = ast_jump_modes(mode);
-
- if (mode == ast_return)
- opt_return_value = return_value;
-}
-
-
-void
-ast_selection_statement::print(void) const
-{
- printf("if ( ");
- condition->print();
- printf(") ");
-
- then_statement->print();
-
- if (else_statement) {
- printf("else ");
- else_statement->print();
- }
-
-}
-
-
-ast_selection_statement::ast_selection_statement(ast_expression *condition,
- ast_node *then_statement,
- ast_node *else_statement)
-{
- this->condition = condition;
- this->then_statement = then_statement;
- this->else_statement = else_statement;
-}
-
-
-void
-ast_iteration_statement::print(void) const
-{
- switch (mode) {
- case ast_for:
- printf("for( ");
- if (init_statement)
- init_statement->print();
- printf("; ");
-
- if (condition)
- condition->print();
- printf("; ");
-
- if (rest_expression)
- rest_expression->print();
- printf(") ");
-
- body->print();
- break;
-
- case ast_while:
- printf("while ( ");
- if (condition)
- condition->print();
- printf(") ");
- body->print();
- break;
-
- case ast_do_while:
- printf("do ");
- body->print();
- printf("while ( ");
- if (condition)
- condition->print();
- printf("); ");
- break;
- }
-}
-
-
-ast_iteration_statement::ast_iteration_statement(int mode,
- ast_node *init,
- ast_node *condition,
- ast_expression *rest_expression,
- ast_node *body)
-{
- this->mode = ast_iteration_modes(mode);
- this->init_statement = init;
- this->condition = condition;
- this->rest_expression = rest_expression;
- this->body = body;
-}
-
-
-void
-ast_struct_specifier::print(void) const
-{
- printf("struct %s { ", name);
- foreach_list_const(n, &this->declarations) {
- ast_node *ast = exec_node_data(ast_node, n, link);
- ast->print();
- }
- printf("} ");
-}
-
-
-ast_struct_specifier::ast_struct_specifier(char *identifier,
- ast_node *declarator_list)
-{
- if (identifier == NULL) {
- static unsigned anon_count = 1;
- identifier = ralloc_asprintf(this, "#anon_struct_%04x", anon_count);
- anon_count++;
- }
- name = identifier;
- this->declarations.push_degenerate_list_at_head(&declarator_list->link);
-}
-
-bool
-do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations)
-{
- GLboolean progress = GL_FALSE;
-
- progress = lower_instructions(ir, SUB_TO_ADD_NEG) || progress;
-
- if (linked) {
- progress = do_function_inlining(ir) || progress;
- progress = do_dead_functions(ir) || progress;
- }
- progress = do_structure_splitting(ir) || progress;
- progress = do_if_simplification(ir) || progress;
- progress = do_discard_simplification(ir) || progress;
- progress = do_copy_propagation(ir) || progress;
- /*progress = do_copy_propagation_elements(ir) || progress;*/
- if (linked)
- progress = do_dead_code(ir) || progress;
- else
- progress = do_dead_code_unlinked(ir) || progress;
- progress = do_dead_code_local(ir) || progress;
- progress = do_tree_grafting(ir) || progress;
- progress = do_constant_propagation(ir) || progress;
- if (linked)
- progress = do_constant_variable(ir) || progress;
- else
- progress = do_constant_variable_unlinked(ir) || progress;
- progress = do_constant_folding(ir) || progress;
- progress = do_algebraic(ir) || progress;
- progress = do_lower_jumps(ir) || progress;
- progress = do_vec_index_to_swizzle(ir) || progress;
- progress = do_swizzle_swizzle(ir) || progress;
- progress = do_noop_swizzle(ir) || progress;
-
- progress = optimize_redundant_jumps(ir) || progress;
-
- loop_state *ls = analyze_loop_variables(ir);
- if (ls->loop_found) {
- progress = set_loop_controls(ir, ls) || progress;
- progress = unroll_loops(ir, ls, max_unroll_iterations) || progress;
- }
- delete ls;
-
- return progress;
-}
-
-extern "C" {
-
-/**
- * To be called at GL teardown time, this frees compiler datastructures.
- *
- * After calling this, any previously compiled shaders and shader
- * programs would be invalid. So this should happen at approximately
- * program exit.
- */
-void
-_mesa_destroy_shader_compiler(void)
-{
- _mesa_destroy_shader_compiler_caches();
-
- _mesa_glsl_release_types();
-}
-
-/**
- * Releases compiler caches to trade off performance for memory.
- *
- * Intended to be used with glReleaseShaderCompiler().
- */
-void
-_mesa_destroy_shader_compiler_caches(void)
-{
- _mesa_glsl_release_functions();
-}
-
-}
+/*
+ * Copyright © 2008, 2009 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <assert.h>
+
+extern "C" {
+#include "main/core.h" /* for struct gl_context */
+}
+
+#include "ralloc.h"
+#include "ast.h"
+#include "glsl_parser_extras.h"
+#include "glsl_parser.h"
+#include "ir_optimization.h"
+#include "loop_analysis.h"
+
+_mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *ctx,
+ GLenum target, void *mem_ctx)
+{
+ switch (target) {
+ case GL_VERTEX_SHADER: this->target = vertex_shader; break;
+ case GL_FRAGMENT_SHADER: this->target = fragment_shader; break;
+ case GL_GEOMETRY_SHADER: this->target = geometry_shader; break;
+ }
+
+ this->scanner = NULL;
+ this->translation_unit.make_empty();
+ this->symbols = new(mem_ctx) glsl_symbol_table;
+ this->info_log = ralloc_strdup(mem_ctx, "");
+ this->error = false;
+ this->loop_or_switch_nesting = NULL;
+
+ /* Set default language version and extensions */
+ this->language_version = 110;
+ this->es_shader = false;
+ this->ARB_texture_rectangle_enable = true;
+
+ /* OpenGL ES 2.0 has different defaults from desktop GL. */
+ if (ctx->API == API_OPENGLES2) {
+ this->language_version = 100;
+ this->es_shader = true;
+ this->ARB_texture_rectangle_enable = false;
+ }
+
+ this->extensions = &ctx->Extensions;
+
+ this->Const.MaxLights = ctx->Const.MaxLights;
+ this->Const.MaxClipPlanes = ctx->Const.MaxClipPlanes;
+ this->Const.MaxTextureUnits = ctx->Const.MaxTextureUnits;
+ this->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
+ this->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs;
+ this->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents;
+ this->Const.MaxVaryingFloats = ctx->Const.MaxVarying * 4;
+ this->Const.MaxVertexTextureImageUnits = ctx->Const.MaxVertexTextureImageUnits;
+ this->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits;
+ this->Const.MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
+ this->Const.MaxFragmentUniformComponents = ctx->Const.FragmentProgram.MaxUniformComponents;
+
+ this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
+
+ /* Note: Once the OpenGL 3.0 'forward compatible' context or the OpenGL 3.2
+ * Core context is supported, this logic will need change. Older versions of
+ * GLSL are no longer supported outside the compatibility contexts of 3.x.
+ */
+ this->Const.GLSL_100ES = (ctx->API == API_OPENGLES2)
+ || ctx->Extensions.ARB_ES2_compatibility;
+ this->Const.GLSL_110 = (ctx->API == API_OPENGL);
+ this->Const.GLSL_120 = (ctx->API == API_OPENGL)
+ && (ctx->Const.GLSLVersion >= 120);
+ this->Const.GLSL_130 = (ctx->API == API_OPENGL)
+ && (ctx->Const.GLSLVersion >= 130);
+
+ const unsigned lowest_version =
+ (ctx->API == API_OPENGLES2) || ctx->Extensions.ARB_ES2_compatibility
+ ? 100 : 110;
+ const unsigned highest_version =
+ (ctx->API == API_OPENGL) ? ctx->Const.GLSLVersion : 100;
+ char *supported = ralloc_strdup(this, "");
+
+ for (unsigned ver = lowest_version; ver <= highest_version; ver += 10) {
+ const char *const prefix = (ver == lowest_version)
+ ? ""
+ : ((ver == highest_version) ? ", and " : ", ");
+
+ ralloc_asprintf_append(& supported, "%s%d.%02d%s",
+ prefix,
+ ver / 100, ver % 100,
+ (ver == 100) ? " ES" : "");
+ }
+
+ this->supported_version_string = supported;
+}
+
+const char *
+_mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target)
+{
+ switch (target) {
+ case vertex_shader: return "vertex";
+ case fragment_shader: return "fragment";
+ case geometry_shader: return "geometry";
+ }
+
+ assert(!"Should not get here.");
+ return "unknown";
+}
+
+
+void
+_mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
+ const char *fmt, ...)
+{
+ va_list ap;
+
+ state->error = true;
+
+ assert(state->info_log != NULL);
+ ralloc_asprintf_append(&state->info_log, "%u:%u(%u): error: ",
+ locp->source,
+ locp->first_line,
+ locp->first_column);
+ va_start(ap, fmt);
+ ralloc_vasprintf_append(&state->info_log, fmt, ap);
+ va_end(ap);
+ ralloc_strcat(&state->info_log, "\n");
+}
+
+
+void
+_mesa_glsl_warning(const YYLTYPE *locp, _mesa_glsl_parse_state *state,
+ const char *fmt, ...)
+{
+ va_list ap;
+
+ assert(state->info_log != NULL);
+ ralloc_asprintf_append(&state->info_log, "%u:%u(%u): warning: ",
+ locp->source,
+ locp->first_line,
+ locp->first_column);
+ va_start(ap, fmt);
+ ralloc_vasprintf_append(&state->info_log, fmt, ap);
+ va_end(ap);
+ ralloc_strcat(&state->info_log, "\n");
+}
+
+
+bool
+_mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp,
+ const char *behavior, YYLTYPE *behavior_locp,
+ _mesa_glsl_parse_state *state)
+{
+ enum {
+ extension_disable,
+ extension_enable,
+ extension_require,
+ extension_warn
+ } ext_mode;
+
+ if (strcmp(behavior, "warn") == 0) {
+ ext_mode = extension_warn;
+ } else if (strcmp(behavior, "require") == 0) {
+ ext_mode = extension_require;
+ } else if (strcmp(behavior, "enable") == 0) {
+ ext_mode = extension_enable;
+ } else if (strcmp(behavior, "disable") == 0) {
+ ext_mode = extension_disable;
+ } else {
+ _mesa_glsl_error(behavior_locp, state,
+ "Unknown extension behavior `%s'",
+ behavior);
+ return false;
+ }
+
+ bool unsupported = false;
+
+ if (strcmp(name, "all") == 0) {
+ if ((ext_mode == extension_enable) || (ext_mode == extension_require)) {
+ _mesa_glsl_error(name_locp, state, "Cannot %s all extensions",
+ (ext_mode == extension_enable)
+ ? "enable" : "require");
+ return false;
+ }
+ } else if (strcmp(name, "GL_ARB_draw_buffers") == 0) {
+ /* This extension is only supported in fragment shaders.
+ */
+ if (state->target != fragment_shader) {
+ unsupported = true;
+ } else {
+ state->ARB_draw_buffers_enable = (ext_mode != extension_disable);
+ state->ARB_draw_buffers_warn = (ext_mode == extension_warn);
+ }
+ } else if (strcmp(name, "GL_ARB_draw_instanced") == 0) {
+ /* This extension is only supported in vertex shaders.
+ */
+ if (state->target != vertex_shader) {
+ unsupported = true;
+ } else {
+ state->ARB_draw_instanced_enable = (ext_mode != extension_disable);
+ state->ARB_draw_instanced_warn = (ext_mode == extension_warn);
+ }
+ } else if (strcmp(name, "GL_ARB_explicit_attrib_location") == 0) {
+ state->ARB_explicit_attrib_location_enable =
+ (ext_mode != extension_disable);
+ state->ARB_explicit_attrib_location_warn =
+ (ext_mode == extension_warn);
+
+ unsupported = !state->extensions->ARB_explicit_attrib_location;
+ } else if (strcmp(name, "GL_ARB_fragment_coord_conventions") == 0) {
+ state->ARB_fragment_coord_conventions_enable =
+ (ext_mode != extension_disable);
+ state->ARB_fragment_coord_conventions_warn =
+ (ext_mode == extension_warn);
+
+ unsupported = !state->extensions->ARB_fragment_coord_conventions;
+ } else if (strcmp(name, "GL_ARB_texture_rectangle") == 0) {
+ state->ARB_texture_rectangle_enable = (ext_mode != extension_disable);
+ state->ARB_texture_rectangle_warn = (ext_mode == extension_warn);
+ } else if (strcmp(name, "GL_EXT_texture_array") == 0) {
+ state->EXT_texture_array_enable = (ext_mode != extension_disable);
+ state->EXT_texture_array_warn = (ext_mode == extension_warn);
+
+ unsupported = !state->extensions->EXT_texture_array;
+ } else if (strcmp(name, "GL_ARB_shader_stencil_export") == 0) {
+ if (state->target != fragment_shader) {
+ unsupported = true;
+ } else {
+ state->ARB_shader_stencil_export_enable = (ext_mode != extension_disable);
+ state->ARB_shader_stencil_export_warn = (ext_mode == extension_warn);
+ unsupported = !state->extensions->ARB_shader_stencil_export;
+ }
+ } else if (strcmp(name, "GL_AMD_conservative_depth") == 0) {
+ /* The AMD_conservative spec does not forbid requiring the extension in
+ * the vertex shader.
+ */
+ state->AMD_conservative_depth_enable = (ext_mode != extension_disable);
+ state->AMD_conservative_depth_warn = (ext_mode == extension_warn);
+ unsupported = !state->extensions->AMD_conservative_depth;
+ } else if (strcmp(name, "GL_OES_texture_3D") == 0 && state->es_shader) {
+ state->OES_texture_3D_enable = (ext_mode != extension_disable);
+ state->OES_texture_3D_warn = (ext_mode == extension_warn);
+
+ unsupported = !state->extensions->EXT_texture3D;
+ } else {
+ unsupported = true;
+ }
+
+ if (unsupported) {
+ static const char *const fmt = "extension `%s' unsupported in %s shader";
+
+ if (ext_mode == extension_require) {
+ _mesa_glsl_error(name_locp, state, fmt,
+ name, _mesa_glsl_shader_target_name(state->target));
+ return false;
+ } else {
+ _mesa_glsl_warning(name_locp, state, fmt,
+ name, _mesa_glsl_shader_target_name(state->target));
+ }
+ }
+
+ return true;
+}
+
+void
+_mesa_ast_type_qualifier_print(const struct ast_type_qualifier *q)
+{
+ if (q->flags.q.constant)
+ printf("const ");
+
+ if (q->flags.q.invariant)
+ printf("invariant ");
+
+ if (q->flags.q.attribute)
+ printf("attribute ");
+
+ if (q->flags.q.varying)
+ printf("varying ");
+
+ if (q->flags.q.in && q->flags.q.out)
+ printf("inout ");
+ else {
+ if (q->flags.q.in)
+ printf("in ");
+
+ if (q->flags.q.out)
+ printf("out ");
+ }
+
+ if (q->flags.q.centroid)
+ printf("centroid ");
+ if (q->flags.q.uniform)
+ printf("uniform ");
+ if (q->flags.q.smooth)
+ printf("smooth ");
+ if (q->flags.q.flat)
+ printf("flat ");
+ if (q->flags.q.noperspective)
+ printf("noperspective ");
+}
+
+
+void
+ast_node::print(void) const
+{
+ printf("unhandled node ");
+}
+
+
+ast_node::ast_node(void)
+{
+ this->location.source = 0;
+ this->location.line = 0;
+ this->location.column = 0;
+}
+
+
+static void
+ast_opt_array_size_print(bool is_array, const ast_expression *array_size)
+{
+ if (is_array) {
+ printf("[ ");
+
+ if (array_size)
+ array_size->print();
+
+ printf("] ");
+ }
+}
+
+
+void
+ast_compound_statement::print(void) const
+{
+ printf("{\n");
+
+ foreach_list_const(n, &this->statements) {
+ ast_node *ast = exec_node_data(ast_node, n, link);
+ ast->print();
+ }
+
+ printf("}\n");
+}
+
+
+ast_compound_statement::ast_compound_statement(int new_scope,
+ ast_node *statements)
+{
+ this->new_scope = new_scope;
+
+ if (statements != NULL) {
+ this->statements.push_degenerate_list_at_head(&statements->link);
+ }
+}
+
+
+void
+ast_expression::print(void) const
+{
+ switch (oper) {
+ case ast_assign:
+ case ast_mul_assign:
+ case ast_div_assign:
+ case ast_mod_assign:
+ case ast_add_assign:
+ case ast_sub_assign:
+ case ast_ls_assign:
+ case ast_rs_assign:
+ case ast_and_assign:
+ case ast_xor_assign:
+ case ast_or_assign:
+ subexpressions[0]->print();
+ printf("%s ", operator_string(oper));
+ subexpressions[1]->print();
+ break;
+
+ case ast_field_selection:
+ subexpressions[0]->print();
+ printf(". %s ", primary_expression.identifier);
+ break;
+
+ case ast_plus:
+ case ast_neg:
+ case ast_bit_not:
+ case ast_logic_not:
+ case ast_pre_inc:
+ case ast_pre_dec:
+ printf("%s ", operator_string(oper));
+ subexpressions[0]->print();
+ break;
+
+ case ast_post_inc:
+ case ast_post_dec:
+ subexpressions[0]->print();
+ printf("%s ", operator_string(oper));
+ break;
+
+ case ast_conditional:
+ subexpressions[0]->print();
+ printf("? ");
+ subexpressions[1]->print();
+ printf(": ");
+ subexpressions[1]->print();
+ break;
+
+ case ast_array_index:
+ subexpressions[0]->print();
+ printf("[ ");
+ subexpressions[1]->print();
+ printf("] ");
+ break;
+
+ case ast_function_call: {
+ subexpressions[0]->print();
+ printf("( ");
+
+ foreach_list_const (n, &this->expressions) {
+ if (n != this->expressions.get_head())
+ printf(", ");
+
+ ast_node *ast = exec_node_data(ast_node, n, link);
+ ast->print();
+ }
+
+ printf(") ");
+ break;
+ }
+
+ case ast_identifier:
+ printf("%s ", primary_expression.identifier);
+ break;
+
+ case ast_int_constant:
+ printf("%d ", primary_expression.int_constant);
+ break;
+
+ case ast_uint_constant:
+ printf("%u ", primary_expression.uint_constant);
+ break;
+
+ case ast_float_constant:
+ printf("%f ", primary_expression.float_constant);
+ break;
+
+ case ast_bool_constant:
+ printf("%s ",
+ primary_expression.bool_constant
+ ? "true" : "false");
+ break;
+
+ case ast_sequence: {
+ printf("( ");
+ foreach_list_const(n, & this->expressions) {
+ if (n != this->expressions.get_head())
+ printf(", ");
+
+ ast_node *ast = exec_node_data(ast_node, n, link);
+ ast->print();
+ }
+ printf(") ");
+ break;
+ }
+
+ default:
+ assert(0);
+ break;
+ }
+}
+
+ast_expression::ast_expression(int oper,
+ ast_expression *ex0,
+ ast_expression *ex1,
+ ast_expression *ex2)
+{
+ this->oper = ast_operators(oper);
+ this->subexpressions[0] = ex0;
+ this->subexpressions[1] = ex1;
+ this->subexpressions[2] = ex2;
+}
+
+
+void
+ast_expression_statement::print(void) const
+{
+ if (expression)
+ expression->print();
+
+ printf("; ");
+}
+
+
+ast_expression_statement::ast_expression_statement(ast_expression *ex) :
+ expression(ex)
+{
+ /* empty */
+}
+
+
+void
+ast_function::print(void) const
+{
+ return_type->print();
+ printf(" %s (", identifier);
+
+ foreach_list_const(n, & this->parameters) {
+ ast_node *ast = exec_node_data(ast_node, n, link);
+ ast->print();
+ }
+
+ printf(")");
+}
+
+
+ast_function::ast_function(void)
+ : is_definition(false), signature(NULL)
+{
+ /* empty */
+}
+
+
+void
+ast_fully_specified_type::print(void) const
+{
+ _mesa_ast_type_qualifier_print(& qualifier);
+ specifier->print();
+}
+
+
+void
+ast_parameter_declarator::print(void) const
+{
+ type->print();
+ if (identifier)
+ printf("%s ", identifier);
+ ast_opt_array_size_print(is_array, array_size);
+}
+
+
+void
+ast_function_definition::print(void) const
+{
+ prototype->print();
+ body->print();
+}
+
+
+void
+ast_declaration::print(void) const
+{
+ printf("%s ", identifier);
+ ast_opt_array_size_print(is_array, array_size);
+
+ if (initializer) {
+ printf("= ");
+ initializer->print();
+ }
+}
+
+
+ast_declaration::ast_declaration(char *identifier, int is_array,
+ ast_expression *array_size,
+ ast_expression *initializer)
+{
+ this->identifier = identifier;
+ this->is_array = is_array;
+ this->array_size = array_size;
+ this->initializer = initializer;
+}
+
+
+void
+ast_declarator_list::print(void) const
+{
+ assert(type || invariant);
+
+ if (type)
+ type->print();
+ else
+ printf("invariant ");
+
+ foreach_list_const (ptr, & this->declarations) {
+ if (ptr != this->declarations.get_head())
+ printf(", ");
+
+ ast_node *ast = exec_node_data(ast_node, ptr, link);
+ ast->print();
+ }
+
+ printf("; ");
+}
+
+
+ast_declarator_list::ast_declarator_list(ast_fully_specified_type *type)
+{
+ this->type = type;
+ this->invariant = false;
+}
+
+void
+ast_jump_statement::print(void) const
+{
+ switch (mode) {
+ case ast_continue:
+ printf("continue; ");
+ break;
+ case ast_break:
+ printf("break; ");
+ break;
+ case ast_return:
+ printf("return ");
+ if (opt_return_value)
+ opt_return_value->print();
+
+ printf("; ");
+ break;
+ case ast_discard:
+ printf("discard; ");
+ break;
+ }
+}
+
+
+ast_jump_statement::ast_jump_statement(int mode, ast_expression *return_value)
+{
+ this->mode = ast_jump_modes(mode);
+
+ if (mode == ast_return)
+ opt_return_value = return_value;
+}
+
+
+void
+ast_selection_statement::print(void) const
+{
+ printf("if ( ");
+ condition->print();
+ printf(") ");
+
+ then_statement->print();
+
+ if (else_statement) {
+ printf("else ");
+ else_statement->print();
+ }
+
+}
+
+
+ast_selection_statement::ast_selection_statement(ast_expression *condition,
+ ast_node *then_statement,
+ ast_node *else_statement)
+{
+ this->condition = condition;
+ this->then_statement = then_statement;
+ this->else_statement = else_statement;
+}
+
+
+void
+ast_iteration_statement::print(void) const
+{
+ switch (mode) {
+ case ast_for:
+ printf("for( ");
+ if (init_statement)
+ init_statement->print();
+ printf("; ");
+
+ if (condition)
+ condition->print();
+ printf("; ");
+
+ if (rest_expression)
+ rest_expression->print();
+ printf(") ");
+
+ body->print();
+ break;
+
+ case ast_while:
+ printf("while ( ");
+ if (condition)
+ condition->print();
+ printf(") ");
+ body->print();
+ break;
+
+ case ast_do_while:
+ printf("do ");
+ body->print();
+ printf("while ( ");
+ if (condition)
+ condition->print();
+ printf("); ");
+ break;
+ }
+}
+
+
+ast_iteration_statement::ast_iteration_statement(int mode,
+ ast_node *init,
+ ast_node *condition,
+ ast_expression *rest_expression,
+ ast_node *body)
+{
+ this->mode = ast_iteration_modes(mode);
+ this->init_statement = init;
+ this->condition = condition;
+ this->rest_expression = rest_expression;
+ this->body = body;
+}
+
+
+void
+ast_struct_specifier::print(void) const
+{
+ printf("struct %s { ", name);
+ foreach_list_const(n, &this->declarations) {
+ ast_node *ast = exec_node_data(ast_node, n, link);
+ ast->print();
+ }
+ printf("} ");
+}
+
+
+ast_struct_specifier::ast_struct_specifier(char *identifier,
+ ast_node *declarator_list)
+{
+ if (identifier == NULL) {
+ static unsigned anon_count = 1;
+ identifier = ralloc_asprintf(this, "#anon_struct_%04x", anon_count);
+ anon_count++;
+ }
+ name = identifier;
+ this->declarations.push_degenerate_list_at_head(&declarator_list->link);
+}
+
+bool
+do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations)
+{
+ GLboolean progress = GL_FALSE;
+
+ progress = lower_instructions(ir, SUB_TO_ADD_NEG) || progress;
+
+ if (linked) {
+ progress = do_function_inlining(ir) || progress;
+ progress = do_dead_functions(ir) || progress;
+ }
+ progress = do_structure_splitting(ir) || progress;
+ progress = do_if_simplification(ir) || progress;
+ progress = do_discard_simplification(ir) || progress;
+ progress = do_copy_propagation(ir) || progress;
+ /*progress = do_copy_propagation_elements(ir) || progress;*/
+ if (linked)
+ progress = do_dead_code(ir) || progress;
+ else
+ progress = do_dead_code_unlinked(ir) || progress;
+ progress = do_dead_code_local(ir) || progress;
+ progress = do_tree_grafting(ir) || progress;
+ progress = do_constant_propagation(ir) || progress;
+ if (linked)
+ progress = do_constant_variable(ir) || progress;
+ else
+ progress = do_constant_variable_unlinked(ir) || progress;
+ progress = do_constant_folding(ir) || progress;
+ progress = do_algebraic(ir) || progress;
+ progress = do_lower_jumps(ir) || progress;
+ progress = do_vec_index_to_swizzle(ir) || progress;
+ progress = do_swizzle_swizzle(ir) || progress;
+ progress = do_noop_swizzle(ir) || progress;
+
+ progress = optimize_redundant_jumps(ir) || progress;
+
+ loop_state *ls = analyze_loop_variables(ir);
+ if (ls->loop_found) {
+ progress = set_loop_controls(ir, ls) || progress;
+ progress = unroll_loops(ir, ls, max_unroll_iterations) || progress;
+ }
+ delete ls;
+
+ return progress;
+}
+
+extern "C" {
+
+/**
+ * To be called at GL teardown time, this frees compiler datastructures.
+ *
+ * After calling this, any previously compiled shaders and shader
+ * programs would be invalid. So this should happen at approximately
+ * program exit.
+ */
+void
+_mesa_destroy_shader_compiler(void)
+{
+ _mesa_destroy_shader_compiler_caches();
+
+ _mesa_glsl_release_types();
+}
+
+/**
+ * Releases compiler caches to trade off performance for memory.
+ *
+ * Intended to be used with glReleaseShaderCompiler().
+ */
+void
+_mesa_destroy_shader_compiler_caches(void)
+{
+ _mesa_glsl_release_functions();
+}
+
+}
diff --git a/mesalib/src/glsl/glsl_parser_extras.h b/mesalib/src/glsl/glsl_parser_extras.h
index b5c016fb3..6351413f1 100644
--- a/mesalib/src/glsl/glsl_parser_extras.h
+++ b/mesalib/src/glsl/glsl_parser_extras.h
@@ -1,279 +1,283 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#pragma once
-#ifndef GLSL_PARSER_EXTRAS_H
-#define GLSL_PARSER_EXTRAS_H
-
-/*
- * Most of the definitions here only apply to C++
- */
-#ifdef __cplusplus
-
-
-#include <stdlib.h>
-#include "glsl_symbol_table.h"
-
-enum _mesa_glsl_parser_targets {
- vertex_shader,
- geometry_shader,
- fragment_shader
-};
-
-struct gl_context;
-
-struct _mesa_glsl_parse_state {
- _mesa_glsl_parse_state(struct gl_context *ctx, GLenum target,
- void *mem_ctx);
-
- /* Callers of this ralloc-based new need not call delete. It's
- * easier to just ralloc_free 'ctx' (or any of its ancestors). */
- static void* operator new(size_t size, void *ctx)
- {
- void *mem = rzalloc_size(ctx, size);
- assert(mem != NULL);
-
- return mem;
- }
-
- /* If the user *does* call delete, that's OK, we will just
- * ralloc_free in that case. */
- static void operator delete(void *mem)
- {
- ralloc_free(mem);
- }
-
- void *scanner;
- exec_list translation_unit;
- glsl_symbol_table *symbols;
-
- bool es_shader;
- unsigned language_version;
- const char *version_string;
- enum _mesa_glsl_parser_targets target;
-
- /**
- * Printable list of GLSL versions supported by the current context
- *
- * \note
- * This string should probably be generated per-context instead of per
- * invokation of the compiler. This should be changed when the method of
- * tracking supported GLSL versions changes.
- */
- const char *supported_version_string;
-
- /**
- * Implementation defined limits that affect built-in variables, etc.
- *
- * \sa struct gl_constants (in mtypes.h)
- */
- struct {
- /* 1.10 */
- unsigned MaxLights;
- unsigned MaxClipPlanes;
- unsigned MaxTextureUnits;
- unsigned MaxTextureCoords;
- unsigned MaxVertexAttribs;
- unsigned MaxVertexUniformComponents;
- unsigned MaxVaryingFloats;
- unsigned MaxVertexTextureImageUnits;
- unsigned MaxCombinedTextureImageUnits;
- unsigned MaxTextureImageUnits;
- unsigned MaxFragmentUniformComponents;
-
- /* ARB_draw_buffers */
- unsigned MaxDrawBuffers;
-
- /**
- * Set of GLSL versions supported by the current context
- *
- * Knowing that version X is supported doesn't mean that versions before
- * X are also supported. Version 1.00 is only supported in an ES2
- * context or when GL_ARB_ES2_compatibility is supported. In an OpenGL
- * 3.0 "forward compatible" context, GLSL 1.10 and 1.20 are \b not
- * supported.
- */
- /*@{*/
- unsigned GLSL_100ES:1;
- unsigned GLSL_110:1;
- unsigned GLSL_120:1;
- unsigned GLSL_130:1;
- /*@}*/
- } Const;
-
- /**
- * During AST to IR conversion, pointer to current IR function
- *
- * Will be \c NULL whenever the AST to IR conversion is not inside a
- * function definition.
- */
- class ir_function_signature *current_function;
-
- /** Have we found a return statement in this function? */
- bool found_return;
-
- /** Was there an error during compilation? */
- bool error;
-
- /**
- * Are all shader inputs / outputs invariant?
- *
- * This is set when the 'STDGL invariant(all)' pragma is used.
- */
- bool all_invariant;
-
- /** Loop or switch statement containing the current instructions. */
- class ir_instruction *loop_or_switch_nesting;
- class ast_iteration_statement *loop_or_switch_nesting_ast;
-
- /** List of structures defined in user code. */
- const glsl_type **user_structures;
- unsigned num_user_structures;
-
- char *info_log;
-
- /**
- * \name Enable bits for GLSL extensions
- */
- /*@{*/
- unsigned ARB_draw_buffers_enable:1;
- unsigned ARB_draw_buffers_warn:1;
- unsigned ARB_draw_instanced_enable:1;
- unsigned ARB_draw_instanced_warn:1;
- unsigned ARB_explicit_attrib_location_enable:1;
- unsigned ARB_explicit_attrib_location_warn:1;
- unsigned ARB_fragment_coord_conventions_enable:1;
- unsigned ARB_fragment_coord_conventions_warn:1;
- unsigned ARB_texture_rectangle_enable:1;
- unsigned ARB_texture_rectangle_warn:1;
- unsigned EXT_texture_array_enable:1;
- unsigned EXT_texture_array_warn:1;
- unsigned ARB_shader_stencil_export_enable:1;
- unsigned ARB_shader_stencil_export_warn:1;
- unsigned AMD_conservative_depth_enable:1;
- unsigned AMD_conservative_depth_warn:1;
- unsigned OES_texture_3D_enable:1;
- unsigned OES_texture_3D_warn:1;
- /*@}*/
-
- /** Extensions supported by the OpenGL implementation. */
- const struct gl_extensions *extensions;
-
- /** Shaders containing built-in functions that are used for linking. */
- struct gl_shader *builtins_to_link[16];
- unsigned num_builtins_to_link;
-};
-
-typedef struct YYLTYPE {
- int first_line;
- int first_column;
- int last_line;
- int last_column;
- unsigned source;
-} YYLTYPE;
-# define YYLTYPE_IS_DECLARED 1
-# define YYLTYPE_IS_TRIVIAL 1
-
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
-do { \
- if (N) \
- { \
- (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
- (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
- (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
- (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
- } \
- else \
- { \
- (Current).first_line = (Current).last_line = \
- YYRHSLOC(Rhs, 0).last_line; \
- (Current).first_column = (Current).last_column = \
- YYRHSLOC(Rhs, 0).last_column; \
- } \
- (Current).source = 0; \
-} while (0)
-
-extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
- const char *fmt, ...);
-
-/**
- * Emit a warning to the shader log
- *
- * \sa _mesa_glsl_error
- */
-extern void _mesa_glsl_warning(const YYLTYPE *locp,
- _mesa_glsl_parse_state *state,
- const char *fmt, ...);
-
-extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,
- const char *string);
-
-extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state);
-
-union YYSTYPE;
-extern int _mesa_glsl_lex(union YYSTYPE *yylval, YYLTYPE *yylloc,
- void *scanner);
-
-extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state *);
-
-/**
- * Process elements of the #extension directive
- *
- * \return
- * If \c name and \c behavior are valid, \c true is returned. Otherwise
- * \c false is returned.
- */
-extern bool _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp,
- const char *behavior,
- YYLTYPE *behavior_locp,
- _mesa_glsl_parse_state *state);
-
-/**
- * Get the textual name of the specified shader target
- */
-extern const char *
-_mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target);
-
-
-#endif /* __cplusplus */
-
-
-/*
- * These definitions apply to C and C++
- */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern int preprocess(void *ctx, const char **shader, char **info_log,
- const struct gl_extensions *extensions, int api);
-
-extern void _mesa_destroy_shader_compiler();
-extern void _mesa_destroy_shader_compiler_caches();
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* GLSL_PARSER_EXTRAS_H */
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+#ifndef GLSL_PARSER_EXTRAS_H
+#define GLSL_PARSER_EXTRAS_H
+
+/*
+ * Most of the definitions here only apply to C++
+ */
+#ifdef __cplusplus
+
+
+#include <stdlib.h>
+#include "glsl_symbol_table.h"
+
+enum _mesa_glsl_parser_targets {
+ vertex_shader,
+ geometry_shader,
+ fragment_shader
+};
+
+struct gl_context;
+
+struct _mesa_glsl_parse_state {
+ _mesa_glsl_parse_state(struct gl_context *ctx, GLenum target,
+ void *mem_ctx);
+
+ /* Callers of this ralloc-based new need not call delete. It's
+ * easier to just ralloc_free 'ctx' (or any of its ancestors). */
+ static void* operator new(size_t size, void *ctx)
+ {
+ void *mem = rzalloc_size(ctx, size);
+ assert(mem != NULL);
+
+ return mem;
+ }
+
+ /* If the user *does* call delete, that's OK, we will just
+ * ralloc_free in that case. */
+ static void operator delete(void *mem, void *ctx)
+ {
+ ralloc_free(mem);
+ }
+ static void operator delete(void *mem)
+ {
+ ralloc_free(mem);
+ }
+
+ void *scanner;
+ exec_list translation_unit;
+ glsl_symbol_table *symbols;
+
+ bool es_shader;
+ unsigned language_version;
+ const char *version_string;
+ enum _mesa_glsl_parser_targets target;
+
+ /**
+ * Printable list of GLSL versions supported by the current context
+ *
+ * \note
+ * This string should probably be generated per-context instead of per
+ * invokation of the compiler. This should be changed when the method of
+ * tracking supported GLSL versions changes.
+ */
+ const char *supported_version_string;
+
+ /**
+ * Implementation defined limits that affect built-in variables, etc.
+ *
+ * \sa struct gl_constants (in mtypes.h)
+ */
+ struct {
+ /* 1.10 */
+ unsigned MaxLights;
+ unsigned MaxClipPlanes;
+ unsigned MaxTextureUnits;
+ unsigned MaxTextureCoords;
+ unsigned MaxVertexAttribs;
+ unsigned MaxVertexUniformComponents;
+ unsigned MaxVaryingFloats;
+ unsigned MaxVertexTextureImageUnits;
+ unsigned MaxCombinedTextureImageUnits;
+ unsigned MaxTextureImageUnits;
+ unsigned MaxFragmentUniformComponents;
+
+ /* ARB_draw_buffers */
+ unsigned MaxDrawBuffers;
+
+ /**
+ * Set of GLSL versions supported by the current context
+ *
+ * Knowing that version X is supported doesn't mean that versions before
+ * X are also supported. Version 1.00 is only supported in an ES2
+ * context or when GL_ARB_ES2_compatibility is supported. In an OpenGL
+ * 3.0 "forward compatible" context, GLSL 1.10 and 1.20 are \b not
+ * supported.
+ */
+ /*@{*/
+ unsigned GLSL_100ES:1;
+ unsigned GLSL_110:1;
+ unsigned GLSL_120:1;
+ unsigned GLSL_130:1;
+ /*@}*/
+ } Const;
+
+ /**
+ * During AST to IR conversion, pointer to current IR function
+ *
+ * Will be \c NULL whenever the AST to IR conversion is not inside a
+ * function definition.
+ */
+ class ir_function_signature *current_function;
+
+ /** Have we found a return statement in this function? */
+ bool found_return;
+
+ /** Was there an error during compilation? */
+ bool error;
+
+ /**
+ * Are all shader inputs / outputs invariant?
+ *
+ * This is set when the 'STDGL invariant(all)' pragma is used.
+ */
+ bool all_invariant;
+
+ /** Loop or switch statement containing the current instructions. */
+ class ir_instruction *loop_or_switch_nesting;
+ class ast_iteration_statement *loop_or_switch_nesting_ast;
+
+ /** List of structures defined in user code. */
+ const glsl_type **user_structures;
+ unsigned num_user_structures;
+
+ char *info_log;
+
+ /**
+ * \name Enable bits for GLSL extensions
+ */
+ /*@{*/
+ unsigned ARB_draw_buffers_enable:1;
+ unsigned ARB_draw_buffers_warn:1;
+ unsigned ARB_draw_instanced_enable:1;
+ unsigned ARB_draw_instanced_warn:1;
+ unsigned ARB_explicit_attrib_location_enable:1;
+ unsigned ARB_explicit_attrib_location_warn:1;
+ unsigned ARB_fragment_coord_conventions_enable:1;
+ unsigned ARB_fragment_coord_conventions_warn:1;
+ unsigned ARB_texture_rectangle_enable:1;
+ unsigned ARB_texture_rectangle_warn:1;
+ unsigned EXT_texture_array_enable:1;
+ unsigned EXT_texture_array_warn:1;
+ unsigned ARB_shader_stencil_export_enable:1;
+ unsigned ARB_shader_stencil_export_warn:1;
+ unsigned AMD_conservative_depth_enable:1;
+ unsigned AMD_conservative_depth_warn:1;
+ unsigned OES_texture_3D_enable:1;
+ unsigned OES_texture_3D_warn:1;
+ /*@}*/
+
+ /** Extensions supported by the OpenGL implementation. */
+ const struct gl_extensions *extensions;
+
+ /** Shaders containing built-in functions that are used for linking. */
+ struct gl_shader *builtins_to_link[16];
+ unsigned num_builtins_to_link;
+};
+
+typedef struct YYLTYPE {
+ int first_line;
+ int first_column;
+ int last_line;
+ int last_column;
+ unsigned source;
+} YYLTYPE;
+# define YYLTYPE_IS_DECLARED 1
+# define YYLTYPE_IS_TRIVIAL 1
+
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+do { \
+ if (N) \
+ { \
+ (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC(Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC(Rhs, 0).last_column; \
+ } \
+ (Current).source = 0; \
+} while (0)
+
+extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
+ const char *fmt, ...);
+
+/**
+ * Emit a warning to the shader log
+ *
+ * \sa _mesa_glsl_error
+ */
+extern void _mesa_glsl_warning(const YYLTYPE *locp,
+ _mesa_glsl_parse_state *state,
+ const char *fmt, ...);
+
+extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,
+ const char *string);
+
+extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state);
+
+union YYSTYPE;
+extern int _mesa_glsl_lex(union YYSTYPE *yylval, YYLTYPE *yylloc,
+ void *scanner);
+
+extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state *);
+
+/**
+ * Process elements of the #extension directive
+ *
+ * \return
+ * If \c name and \c behavior are valid, \c true is returned. Otherwise
+ * \c false is returned.
+ */
+extern bool _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp,
+ const char *behavior,
+ YYLTYPE *behavior_locp,
+ _mesa_glsl_parse_state *state);
+
+/**
+ * Get the textual name of the specified shader target
+ */
+extern const char *
+_mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target);
+
+
+#endif /* __cplusplus */
+
+
+/*
+ * These definitions apply to C and C++
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int preprocess(void *ctx, const char **shader, char **info_log,
+ const struct gl_extensions *extensions, int api);
+
+extern void _mesa_destroy_shader_compiler();
+extern void _mesa_destroy_shader_compiler_caches();
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* GLSL_PARSER_EXTRAS_H */
diff --git a/mesalib/src/glsl/glsl_symbol_table.cpp b/mesalib/src/glsl/glsl_symbol_table.cpp
index 2f291d4f9..9714384eb 100644
--- a/mesalib/src/glsl/glsl_symbol_table.cpp
+++ b/mesalib/src/glsl/glsl_symbol_table.cpp
@@ -36,6 +36,10 @@ public:
}
/* If the user *does* call delete, that's OK, we will just ralloc_free. */
+ static void operator delete(void *entry, void *ctx)
+ {
+ ralloc_free(entry);
+ }
static void operator delete(void *entry)
{
ralloc_free(entry);
diff --git a/mesalib/src/glsl/glsl_symbol_table.h b/mesalib/src/glsl/glsl_symbol_table.h
index 637bc033b..1afeddb33 100644
--- a/mesalib/src/glsl/glsl_symbol_table.h
+++ b/mesalib/src/glsl/glsl_symbol_table.h
@@ -68,6 +68,11 @@ public:
/* If the user *does* call delete, that's OK, we will just
* ralloc_free in that case. Here, C++ will have already called the
* destructor so tell ralloc not to do that again. */
+ static void operator delete(void *table, void *ctx)
+ {
+ ralloc_set_destructor(table, NULL);
+ ralloc_free(table);
+ }
static void operator delete(void *table)
{
ralloc_set_destructor(table, NULL);
diff --git a/mesalib/src/glsl/glsl_types.cpp b/mesalib/src/glsl/glsl_types.cpp
index 78d10bd93..ba862dfd6 100644
--- a/mesalib/src/glsl/glsl_types.cpp
+++ b/mesalib/src/glsl/glsl_types.cpp
@@ -1,509 +1,509 @@
-/*
- * Copyright © 2009 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "main/core.h" /* for Elements */
-#include "glsl_symbol_table.h"
-#include "glsl_parser_extras.h"
-#include "glsl_types.h"
-#include "builtin_types.h"
-extern "C" {
-#include "program/hash_table.h"
-}
-
-hash_table *glsl_type::array_types = NULL;
-hash_table *glsl_type::record_types = NULL;
-void *glsl_type::mem_ctx = NULL;
-
-void
-glsl_type::init_ralloc_type_ctx(void)
-{
- if (glsl_type::mem_ctx == NULL) {
- glsl_type::mem_ctx = ralloc_autofree_context();
- assert(glsl_type::mem_ctx != NULL);
- }
-}
-
-glsl_type::glsl_type(GLenum gl_type,
- glsl_base_type base_type, unsigned vector_elements,
- unsigned matrix_columns, const char *name) :
- gl_type(gl_type),
- base_type(base_type),
- sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- sampler_type(0),
- vector_elements(vector_elements), matrix_columns(matrix_columns),
- length(0)
-{
- init_ralloc_type_ctx();
- this->name = ralloc_strdup(this->mem_ctx, name);
- /* Neither dimension is zero or both dimensions are zero.
- */
- assert((vector_elements == 0) == (matrix_columns == 0));
- memset(& fields, 0, sizeof(fields));
-}
-
-glsl_type::glsl_type(GLenum gl_type,
- enum glsl_sampler_dim dim, bool shadow, bool array,
- unsigned type, const char *name) :
- gl_type(gl_type),
- base_type(GLSL_TYPE_SAMPLER),
- sampler_dimensionality(dim), sampler_shadow(shadow),
- sampler_array(array), sampler_type(type),
- vector_elements(0), matrix_columns(0),
- length(0)
-{
- init_ralloc_type_ctx();
- this->name = ralloc_strdup(this->mem_ctx, name);
- memset(& fields, 0, sizeof(fields));
-}
-
-glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
- const char *name) :
- base_type(GLSL_TYPE_STRUCT),
- sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- sampler_type(0),
- vector_elements(0), matrix_columns(0),
- length(num_fields)
-{
- unsigned int i;
-
- init_ralloc_type_ctx();
- this->name = ralloc_strdup(this->mem_ctx, name);
- this->fields.structure = ralloc_array(this->mem_ctx,
- glsl_struct_field, length);
- for (i = 0; i < length; i++) {
- this->fields.structure[i].type = fields[i].type;
- this->fields.structure[i].name = ralloc_strdup(this->fields.structure,
- fields[i].name);
- }
-}
-
-static void
-add_types_to_symbol_table(glsl_symbol_table *symtab,
- const struct glsl_type *types,
- unsigned num_types, bool warn)
-{
- (void) warn;
-
- for (unsigned i = 0; i < num_types; i++) {
- symtab->add_type(types[i].name, & types[i]);
- }
-}
-
-void
-glsl_type::generate_100ES_types(glsl_symbol_table *symtab)
-{
- add_types_to_symbol_table(symtab, builtin_core_types,
- Elements(builtin_core_types),
- false);
- add_types_to_symbol_table(symtab, builtin_structure_types,
- Elements(builtin_structure_types),
- false);
- add_types_to_symbol_table(symtab, void_type, 1, false);
-}
-
-void
-glsl_type::generate_110_types(glsl_symbol_table *symtab)
-{
- generate_100ES_types(symtab);
-
- add_types_to_symbol_table(symtab, builtin_110_types,
- Elements(builtin_110_types),
- false);
- add_types_to_symbol_table(symtab, &_sampler3D_type, 1, false);
- add_types_to_symbol_table(symtab, builtin_110_deprecated_structure_types,
- Elements(builtin_110_deprecated_structure_types),
- false);
-}
-
-
-void
-glsl_type::generate_120_types(glsl_symbol_table *symtab)
-{
- generate_110_types(symtab);
-
- add_types_to_symbol_table(symtab, builtin_120_types,
- Elements(builtin_120_types), false);
-}
-
-
-void
-glsl_type::generate_130_types(glsl_symbol_table *symtab)
-{
- generate_120_types(symtab);
-
- add_types_to_symbol_table(symtab, builtin_130_types,
- Elements(builtin_130_types), false);
- generate_EXT_texture_array_types(symtab, false);
-}
-
-
-void
-glsl_type::generate_ARB_texture_rectangle_types(glsl_symbol_table *symtab,
- bool warn)
-{
- add_types_to_symbol_table(symtab, builtin_ARB_texture_rectangle_types,
- Elements(builtin_ARB_texture_rectangle_types),
- warn);
-}
-
-
-void
-glsl_type::generate_EXT_texture_array_types(glsl_symbol_table *symtab,
- bool warn)
-{
- add_types_to_symbol_table(symtab, builtin_EXT_texture_array_types,
- Elements(builtin_EXT_texture_array_types),
- warn);
-}
-
-
-void
-glsl_type::generate_OES_texture_3D_types(glsl_symbol_table *symtab, bool warn)
-{
- add_types_to_symbol_table(symtab, &_sampler3D_type, 1, warn);
-}
-
-
-void
-_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
-{
- switch (state->language_version) {
- case 100:
- assert(state->es_shader);
- glsl_type::generate_100ES_types(state->symbols);
- break;
- case 110:
- glsl_type::generate_110_types(state->symbols);
- break;
- case 120:
- glsl_type::generate_120_types(state->symbols);
- break;
- case 130:
- glsl_type::generate_130_types(state->symbols);
- break;
- default:
- /* error */
- break;
- }
-
- if (state->ARB_texture_rectangle_enable) {
- glsl_type::generate_ARB_texture_rectangle_types(state->symbols,
- state->ARB_texture_rectangle_warn);
- }
- if (state->OES_texture_3D_enable && state->language_version == 100) {
- glsl_type::generate_OES_texture_3D_types(state->symbols,
- state->OES_texture_3D_warn);
- }
-
- if (state->EXT_texture_array_enable && state->language_version < 130) {
- // These are already included in 130; don't create twice.
- glsl_type::generate_EXT_texture_array_types(state->symbols,
- state->EXT_texture_array_warn);
- }
-}
-
-
-const glsl_type *glsl_type::get_base_type() const
-{
- switch (base_type) {
- case GLSL_TYPE_UINT:
- return uint_type;
- case GLSL_TYPE_INT:
- return int_type;
- case GLSL_TYPE_FLOAT:
- return float_type;
- case GLSL_TYPE_BOOL:
- return bool_type;
- default:
- return error_type;
- }
-}
-
-
-void
-_mesa_glsl_release_types(void)
-{
- if (glsl_type::array_types != NULL) {
- hash_table_dtor(glsl_type::array_types);
- glsl_type::array_types = NULL;
- }
-
- if (glsl_type::record_types != NULL) {
- hash_table_dtor(glsl_type::record_types);
- glsl_type::record_types = NULL;
- }
-}
-
-
-glsl_type::glsl_type(const glsl_type *array, unsigned length) :
- base_type(GLSL_TYPE_ARRAY),
- sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- sampler_type(0),
- vector_elements(0), matrix_columns(0),
- name(NULL), length(length)
-{
- this->fields.array = array;
- /* Inherit the gl type of the base. The GL type is used for
- * uniform/statevar handling in Mesa and the arrayness of the type
- * is represented by the size rather than the type.
- */
- this->gl_type = array->gl_type;
-
- /* Allow a maximum of 10 characters for the array size. This is enough
- * for 32-bits of ~0. The extra 3 are for the '[', ']', and terminating
- * NUL.
- */
- const unsigned name_length = strlen(array->name) + 10 + 3;
- char *const n = (char *) ralloc_size(this->mem_ctx, name_length);
-
- if (length == 0)
- snprintf(n, name_length, "%s[]", array->name);
- else
- snprintf(n, name_length, "%s[%u]", array->name, length);
-
- this->name = n;
-}
-
-
-const glsl_type *
-glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
-{
- if (base_type == GLSL_TYPE_VOID)
- return void_type;
-
- if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4))
- return error_type;
-
- /* Treat GLSL vectors as Nx1 matrices.
- */
- if (columns == 1) {
- switch (base_type) {
- case GLSL_TYPE_UINT:
- return uint_type + (rows - 1);
- case GLSL_TYPE_INT:
- return int_type + (rows - 1);
- case GLSL_TYPE_FLOAT:
- return float_type + (rows - 1);
- case GLSL_TYPE_BOOL:
- return bool_type + (rows - 1);
- default:
- return error_type;
- }
- } else {
- if ((base_type != GLSL_TYPE_FLOAT) || (rows == 1))
- return error_type;
-
- /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
- * combinations are valid:
- *
- * 1 2 3 4
- * 1
- * 2 x x x
- * 3 x x x
- * 4 x x x
- */
-#define IDX(c,r) (((c-1)*3) + (r-1))
-
- switch (IDX(columns, rows)) {
- case IDX(2,2): return mat2_type;
- case IDX(2,3): return mat2x3_type;
- case IDX(2,4): return mat2x4_type;
- case IDX(3,2): return mat3x2_type;
- case IDX(3,3): return mat3_type;
- case IDX(3,4): return mat3x4_type;
- case IDX(4,2): return mat4x2_type;
- case IDX(4,3): return mat4x3_type;
- case IDX(4,4): return mat4_type;
- default: return error_type;
- }
- }
-
- assert(!"Should not get here.");
- return error_type;
-}
-
-
-const glsl_type *
-glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
-{
-
- if (array_types == NULL) {
- array_types = hash_table_ctor(64, hash_table_string_hash,
- hash_table_string_compare);
- }
-
- /* Generate a name using the base type pointer in the key. This is
- * done because the name of the base type may not be unique across
- * shaders. For example, two shaders may have different record types
- * named 'foo'.
- */
- char key[128];
- snprintf(key, sizeof(key), "%p[%u]", (void *) base, array_size);
-
- const glsl_type *t = (glsl_type *) hash_table_find(array_types, key);
- if (t == NULL) {
- t = new glsl_type(base, array_size);
-
- hash_table_insert(array_types, (void *) t, ralloc_strdup(mem_ctx, key));
- }
-
- assert(t->base_type == GLSL_TYPE_ARRAY);
- assert(t->length == array_size);
- assert(t->fields.array == base);
-
- return t;
-}
-
-
-int
-glsl_type::record_key_compare(const void *a, const void *b)
-{
- const glsl_type *const key1 = (glsl_type *) a;
- const glsl_type *const key2 = (glsl_type *) b;
-
- /* Return zero is the types match (there is zero difference) or non-zero
- * otherwise.
- */
- if (strcmp(key1->name, key2->name) != 0)
- return 1;
-
- if (key1->length != key2->length)
- return 1;
-
- for (unsigned i = 0; i < key1->length; i++) {
- if (key1->fields.structure[i].type != key2->fields.structure[i].type)
- return 1;
- if (strcmp(key1->fields.structure[i].name,
- key2->fields.structure[i].name) != 0)
- return 1;
- }
-
- return 0;
-}
-
-
-unsigned
-glsl_type::record_key_hash(const void *a)
-{
- const glsl_type *const key = (glsl_type *) a;
- char hash_key[128];
- unsigned size = 0;
-
- size = snprintf(hash_key, sizeof(hash_key), "%08x", key->length);
-
- for (unsigned i = 0; i < key->length; i++) {
- if (size >= sizeof(hash_key))
- break;
-
- size += snprintf(& hash_key[size], sizeof(hash_key) - size,
- "%p", (void *) key->fields.structure[i].type);
- }
-
- return hash_table_string_hash(& hash_key);
-}
-
-
-const glsl_type *
-glsl_type::get_record_instance(const glsl_struct_field *fields,
- unsigned num_fields,
- const char *name)
-{
- const glsl_type key(fields, num_fields, name);
-
- if (record_types == NULL) {
- record_types = hash_table_ctor(64, record_key_hash, record_key_compare);
- }
-
- const glsl_type *t = (glsl_type *) hash_table_find(record_types, & key);
- if (t == NULL) {
- t = new glsl_type(fields, num_fields, name);
-
- hash_table_insert(record_types, (void *) t, t);
- }
-
- assert(t->base_type == GLSL_TYPE_STRUCT);
- assert(t->length == num_fields);
- assert(strcmp(t->name, name) == 0);
-
- return t;
-}
-
-
-const glsl_type *
-glsl_type::field_type(const char *name) const
-{
- if (this->base_type != GLSL_TYPE_STRUCT)
- return error_type;
-
- for (unsigned i = 0; i < this->length; i++) {
- if (strcmp(name, this->fields.structure[i].name) == 0)
- return this->fields.structure[i].type;
- }
-
- return error_type;
-}
-
-
-int
-glsl_type::field_index(const char *name) const
-{
- if (this->base_type != GLSL_TYPE_STRUCT)
- return -1;
-
- for (unsigned i = 0; i < this->length; i++) {
- if (strcmp(name, this->fields.structure[i].name) == 0)
- return i;
- }
-
- return -1;
-}
-
-
-unsigned
-glsl_type::component_slots() const
-{
- switch (this->base_type) {
- case GLSL_TYPE_UINT:
- case GLSL_TYPE_INT:
- case GLSL_TYPE_FLOAT:
- case GLSL_TYPE_BOOL:
- return this->components();
-
- case GLSL_TYPE_STRUCT: {
- unsigned size = 0;
-
- for (unsigned i = 0; i < this->length; i++)
- size += this->fields.structure[i].type->component_slots();
-
- return size;
- }
-
- case GLSL_TYPE_ARRAY:
- return this->length * this->fields.array->component_slots();
-
- default:
- return 0;
- }
-}
+/*
+ * Copyright © 2009 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "main/core.h" /* for Elements */
+#include "glsl_symbol_table.h"
+#include "glsl_parser_extras.h"
+#include "glsl_types.h"
+#include "builtin_types.h"
+extern "C" {
+#include "program/hash_table.h"
+}
+
+hash_table *glsl_type::array_types = NULL;
+hash_table *glsl_type::record_types = NULL;
+void *glsl_type::mem_ctx = NULL;
+
+void
+glsl_type::init_ralloc_type_ctx(void)
+{
+ if (glsl_type::mem_ctx == NULL) {
+ glsl_type::mem_ctx = ralloc_autofree_context();
+ assert(glsl_type::mem_ctx != NULL);
+ }
+}
+
+glsl_type::glsl_type(GLenum gl_type,
+ glsl_base_type base_type, unsigned vector_elements,
+ unsigned matrix_columns, const char *name) :
+ gl_type(gl_type),
+ base_type(base_type),
+ sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
+ sampler_type(0),
+ vector_elements(vector_elements), matrix_columns(matrix_columns),
+ length(0)
+{
+ init_ralloc_type_ctx();
+ this->name = ralloc_strdup(this->mem_ctx, name);
+ /* Neither dimension is zero or both dimensions are zero.
+ */
+ assert((vector_elements == 0) == (matrix_columns == 0));
+ memset(& fields, 0, sizeof(fields));
+}
+
+glsl_type::glsl_type(GLenum gl_type,
+ enum glsl_sampler_dim dim, bool shadow, bool array,
+ unsigned type, const char *name) :
+ gl_type(gl_type),
+ base_type(GLSL_TYPE_SAMPLER),
+ sampler_dimensionality(dim), sampler_shadow(shadow),
+ sampler_array(array), sampler_type(type),
+ vector_elements(0), matrix_columns(0),
+ length(0)
+{
+ init_ralloc_type_ctx();
+ this->name = ralloc_strdup(this->mem_ctx, name);
+ memset(& fields, 0, sizeof(fields));
+}
+
+glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
+ const char *name) :
+ base_type(GLSL_TYPE_STRUCT),
+ sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
+ sampler_type(0),
+ vector_elements(0), matrix_columns(0),
+ length(num_fields)
+{
+ unsigned int i;
+
+ init_ralloc_type_ctx();
+ this->name = ralloc_strdup(this->mem_ctx, name);
+ this->fields.structure = ralloc_array(this->mem_ctx,
+ glsl_struct_field, length);
+ for (i = 0; i < length; i++) {
+ this->fields.structure[i].type = fields[i].type;
+ this->fields.structure[i].name = ralloc_strdup(this->fields.structure,
+ fields[i].name);
+ }
+}
+
+static void
+add_types_to_symbol_table(glsl_symbol_table *symtab,
+ const struct glsl_type *types,
+ unsigned num_types, bool warn)
+{
+ (void) warn;
+
+ for (unsigned i = 0; i < num_types; i++) {
+ symtab->add_type(types[i].name, & types[i]);
+ }
+}
+
+void
+glsl_type::generate_100ES_types(glsl_symbol_table *symtab)
+{
+ add_types_to_symbol_table(symtab, builtin_core_types,
+ Elements(builtin_core_types),
+ false);
+ add_types_to_symbol_table(symtab, builtin_structure_types,
+ Elements(builtin_structure_types),
+ false);
+ add_types_to_symbol_table(symtab, void_type, 1, false);
+}
+
+void
+glsl_type::generate_110_types(glsl_symbol_table *symtab)
+{
+ generate_100ES_types(symtab);
+
+ add_types_to_symbol_table(symtab, builtin_110_types,
+ Elements(builtin_110_types),
+ false);
+ add_types_to_symbol_table(symtab, &_sampler3D_type, 1, false);
+ add_types_to_symbol_table(symtab, builtin_110_deprecated_structure_types,
+ Elements(builtin_110_deprecated_structure_types),
+ false);
+}
+
+
+void
+glsl_type::generate_120_types(glsl_symbol_table *symtab)
+{
+ generate_110_types(symtab);
+
+ add_types_to_symbol_table(symtab, builtin_120_types,
+ Elements(builtin_120_types), false);
+}
+
+
+void
+glsl_type::generate_130_types(glsl_symbol_table *symtab)
+{
+ generate_120_types(symtab);
+
+ add_types_to_symbol_table(symtab, builtin_130_types,
+ Elements(builtin_130_types), false);
+ generate_EXT_texture_array_types(symtab, false);
+}
+
+
+void
+glsl_type::generate_ARB_texture_rectangle_types(glsl_symbol_table *symtab,
+ bool warn)
+{
+ add_types_to_symbol_table(symtab, builtin_ARB_texture_rectangle_types,
+ Elements(builtin_ARB_texture_rectangle_types),
+ warn);
+}
+
+
+void
+glsl_type::generate_EXT_texture_array_types(glsl_symbol_table *symtab,
+ bool warn)
+{
+ add_types_to_symbol_table(symtab, builtin_EXT_texture_array_types,
+ Elements(builtin_EXT_texture_array_types),
+ warn);
+}
+
+
+void
+glsl_type::generate_OES_texture_3D_types(glsl_symbol_table *symtab, bool warn)
+{
+ add_types_to_symbol_table(symtab, &_sampler3D_type, 1, warn);
+}
+
+
+void
+_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
+{
+ switch (state->language_version) {
+ case 100:
+ assert(state->es_shader);
+ glsl_type::generate_100ES_types(state->symbols);
+ break;
+ case 110:
+ glsl_type::generate_110_types(state->symbols);
+ break;
+ case 120:
+ glsl_type::generate_120_types(state->symbols);
+ break;
+ case 130:
+ glsl_type::generate_130_types(state->symbols);
+ break;
+ default:
+ /* error */
+ break;
+ }
+
+ if (state->ARB_texture_rectangle_enable) {
+ glsl_type::generate_ARB_texture_rectangle_types(state->symbols,
+ state->ARB_texture_rectangle_warn);
+ }
+ if (state->OES_texture_3D_enable && state->language_version == 100) {
+ glsl_type::generate_OES_texture_3D_types(state->symbols,
+ state->OES_texture_3D_warn);
+ }
+
+ if (state->EXT_texture_array_enable && state->language_version < 130) {
+ // These are already included in 130; don't create twice.
+ glsl_type::generate_EXT_texture_array_types(state->symbols,
+ state->EXT_texture_array_warn);
+ }
+}
+
+
+const glsl_type *glsl_type::get_base_type() const
+{
+ switch (base_type) {
+ case GLSL_TYPE_UINT:
+ return uint_type;
+ case GLSL_TYPE_INT:
+ return int_type;
+ case GLSL_TYPE_FLOAT:
+ return float_type;
+ case GLSL_TYPE_BOOL:
+ return bool_type;
+ default:
+ return error_type;
+ }
+}
+
+
+void
+_mesa_glsl_release_types(void)
+{
+ if (glsl_type::array_types != NULL) {
+ hash_table_dtor(glsl_type::array_types);
+ glsl_type::array_types = NULL;
+ }
+
+ if (glsl_type::record_types != NULL) {
+ hash_table_dtor(glsl_type::record_types);
+ glsl_type::record_types = NULL;
+ }
+}
+
+
+glsl_type::glsl_type(const glsl_type *array, unsigned length) :
+ base_type(GLSL_TYPE_ARRAY),
+ sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
+ sampler_type(0),
+ vector_elements(0), matrix_columns(0),
+ name(NULL), length(length)
+{
+ this->fields.array = array;
+ /* Inherit the gl type of the base. The GL type is used for
+ * uniform/statevar handling in Mesa and the arrayness of the type
+ * is represented by the size rather than the type.
+ */
+ this->gl_type = array->gl_type;
+
+ /* Allow a maximum of 10 characters for the array size. This is enough
+ * for 32-bits of ~0. The extra 3 are for the '[', ']', and terminating
+ * NUL.
+ */
+ const unsigned name_length = strlen(array->name) + 10 + 3;
+ char *const n = (char *) ralloc_size(this->mem_ctx, name_length);
+
+ if (length == 0)
+ snprintf(n, name_length, "%s[]", array->name);
+ else
+ snprintf(n, name_length, "%s[%u]", array->name, length);
+
+ this->name = n;
+}
+
+
+const glsl_type *
+glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
+{
+ if (base_type == GLSL_TYPE_VOID)
+ return void_type;
+
+ if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4))
+ return error_type;
+
+ /* Treat GLSL vectors as Nx1 matrices.
+ */
+ if (columns == 1) {
+ switch (base_type) {
+ case GLSL_TYPE_UINT:
+ return uint_type + (rows - 1);
+ case GLSL_TYPE_INT:
+ return int_type + (rows - 1);
+ case GLSL_TYPE_FLOAT:
+ return float_type + (rows - 1);
+ case GLSL_TYPE_BOOL:
+ return bool_type + (rows - 1);
+ default:
+ return error_type;
+ }
+ } else {
+ if ((base_type != GLSL_TYPE_FLOAT) || (rows == 1))
+ return error_type;
+
+ /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
+ * combinations are valid:
+ *
+ * 1 2 3 4
+ * 1
+ * 2 x x x
+ * 3 x x x
+ * 4 x x x
+ */
+#define IDX(c,r) (((c-1)*3) + (r-1))
+
+ switch (IDX(columns, rows)) {
+ case IDX(2,2): return mat2_type;
+ case IDX(2,3): return mat2x3_type;
+ case IDX(2,4): return mat2x4_type;
+ case IDX(3,2): return mat3x2_type;
+ case IDX(3,3): return mat3_type;
+ case IDX(3,4): return mat3x4_type;
+ case IDX(4,2): return mat4x2_type;
+ case IDX(4,3): return mat4x3_type;
+ case IDX(4,4): return mat4_type;
+ default: return error_type;
+ }
+ }
+
+ assert(!"Should not get here.");
+ return error_type;
+}
+
+
+const glsl_type *
+glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
+{
+
+ if (array_types == NULL) {
+ array_types = hash_table_ctor(64, hash_table_string_hash,
+ hash_table_string_compare);
+ }
+
+ /* Generate a name using the base type pointer in the key. This is
+ * done because the name of the base type may not be unique across
+ * shaders. For example, two shaders may have different record types
+ * named 'foo'.
+ */
+ char key[128];
+ snprintf(key, sizeof(key), "%p[%u]", (void *) base, array_size);
+
+ const glsl_type *t = (glsl_type *) hash_table_find(array_types, key);
+ if (t == NULL) {
+ t = new glsl_type(base, array_size);
+
+ hash_table_insert(array_types, (void *) t, ralloc_strdup(mem_ctx, key));
+ }
+
+ assert(t->base_type == GLSL_TYPE_ARRAY);
+ assert(t->length == array_size);
+ assert(t->fields.array == base);
+
+ return t;
+}
+
+
+int
+glsl_type::record_key_compare(const void *a, const void *b)
+{
+ const glsl_type *const key1 = (glsl_type *) a;
+ const glsl_type *const key2 = (glsl_type *) b;
+
+ /* Return zero is the types match (there is zero difference) or non-zero
+ * otherwise.
+ */
+ if (strcmp(key1->name, key2->name) != 0)
+ return 1;
+
+ if (key1->length != key2->length)
+ return 1;
+
+ for (unsigned i = 0; i < key1->length; i++) {
+ if (key1->fields.structure[i].type != key2->fields.structure[i].type)
+ return 1;
+ if (strcmp(key1->fields.structure[i].name,
+ key2->fields.structure[i].name) != 0)
+ return 1;
+ }
+
+ return 0;
+}
+
+
+unsigned
+glsl_type::record_key_hash(const void *a)
+{
+ const glsl_type *const key = (glsl_type *) a;
+ char hash_key[128];
+ unsigned size = 0;
+
+ size = snprintf(hash_key, sizeof(hash_key), "%08x", key->length);
+
+ for (unsigned i = 0; i < key->length; i++) {
+ if (size >= sizeof(hash_key))
+ break;
+
+ size += snprintf(& hash_key[size], sizeof(hash_key) - size,
+ "%p", (void *) key->fields.structure[i].type);
+ }
+
+ return hash_table_string_hash(& hash_key);
+}
+
+
+const glsl_type *
+glsl_type::get_record_instance(const glsl_struct_field *fields,
+ unsigned num_fields,
+ const char *name)
+{
+ const glsl_type key(fields, num_fields, name);
+
+ if (record_types == NULL) {
+ record_types = hash_table_ctor(64, record_key_hash, record_key_compare);
+ }
+
+ const glsl_type *t = (glsl_type *) hash_table_find(record_types, & key);
+ if (t == NULL) {
+ t = new glsl_type(fields, num_fields, name);
+
+ hash_table_insert(record_types, (void *) t, t);
+ }
+
+ assert(t->base_type == GLSL_TYPE_STRUCT);
+ assert(t->length == num_fields);
+ assert(strcmp(t->name, name) == 0);
+
+ return t;
+}
+
+
+const glsl_type *
+glsl_type::field_type(const char *name) const
+{
+ if (this->base_type != GLSL_TYPE_STRUCT)
+ return error_type;
+
+ for (unsigned i = 0; i < this->length; i++) {
+ if (strcmp(name, this->fields.structure[i].name) == 0)
+ return this->fields.structure[i].type;
+ }
+
+ return error_type;
+}
+
+
+int
+glsl_type::field_index(const char *name) const
+{
+ if (this->base_type != GLSL_TYPE_STRUCT)
+ return -1;
+
+ for (unsigned i = 0; i < this->length; i++) {
+ if (strcmp(name, this->fields.structure[i].name) == 0)
+ return i;
+ }
+
+ return -1;
+}
+
+
+unsigned
+glsl_type::component_slots() const
+{
+ switch (this->base_type) {
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT:
+ case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_BOOL:
+ return this->components();
+
+ case GLSL_TYPE_STRUCT: {
+ unsigned size = 0;
+
+ for (unsigned i = 0; i < this->length; i++)
+ size += this->fields.structure[i].type->component_slots();
+
+ return size;
+ }
+
+ case GLSL_TYPE_ARRAY:
+ return this->length * this->fields.array->component_slots();
+
+ default:
+ return 0;
+ }
+}
diff --git a/mesalib/src/glsl/glsl_types.h b/mesalib/src/glsl/glsl_types.h
index 3c2672c01..8efe12a00 100644
--- a/mesalib/src/glsl/glsl_types.h
+++ b/mesalib/src/glsl/glsl_types.h
@@ -1,478 +1,478 @@
-/* -*- c++ -*- */
-/*
- * Copyright © 2009 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#pragma once
-#ifndef GLSL_TYPES_H
-#define GLSL_TYPES_H
-
-#include <string.h>
-#include <assert.h>
-
-extern "C" {
-#include "GL/gl.h"
-}
-
-#include "ralloc.h"
-
-struct _mesa_glsl_parse_state;
-struct glsl_symbol_table;
-
-extern "C" void
-_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state);
-
-extern "C" void
-_mesa_glsl_release_types(void);
-
-enum glsl_base_type {
- GLSL_TYPE_UINT = 0,
- GLSL_TYPE_INT,
- GLSL_TYPE_FLOAT,
- GLSL_TYPE_BOOL,
- GLSL_TYPE_SAMPLER,
- GLSL_TYPE_STRUCT,
- GLSL_TYPE_ARRAY,
- GLSL_TYPE_VOID,
- GLSL_TYPE_ERROR
-};
-
-enum glsl_sampler_dim {
- GLSL_SAMPLER_DIM_1D = 0,
- GLSL_SAMPLER_DIM_2D,
- GLSL_SAMPLER_DIM_3D,
- GLSL_SAMPLER_DIM_CUBE,
- GLSL_SAMPLER_DIM_RECT,
- GLSL_SAMPLER_DIM_BUF
-};
-
-
-struct glsl_type {
- GLenum gl_type;
- glsl_base_type base_type;
-
- unsigned sampler_dimensionality:3;
- unsigned sampler_shadow:1;
- unsigned sampler_array:1;
- unsigned sampler_type:2; /**< Type of data returned using this sampler.
- * only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
- * and \c GLSL_TYPE_UINT are valid.
- */
-
- /* Callers of this ralloc-based new need not call delete. It's
- * easier to just ralloc_free 'mem_ctx' (or any of its ancestors). */
- static void* operator new(size_t size)
- {
- if (glsl_type::mem_ctx == NULL) {
- glsl_type::mem_ctx = ralloc_context(NULL);
- assert(glsl_type::mem_ctx != NULL);
- }
-
- void *type;
-
- type = ralloc_size(glsl_type::mem_ctx, size);
- assert(type != NULL);
-
- return type;
- }
-
- /* If the user *does* call delete, that's OK, we will just
- * ralloc_free in that case. */
- static void operator delete(void *type)
- {
- ralloc_free(type);
- }
-
- /**
- * \name Vector and matrix element counts
- *
- * For scalars, each of these values will be 1. For non-numeric types
- * these will be 0.
- */
- /*@{*/
- unsigned vector_elements:3; /**< 1, 2, 3, or 4 vector elements. */
- unsigned matrix_columns:3; /**< 1, 2, 3, or 4 matrix columns. */
- /*@}*/
-
- /**
- * Name of the data type
- *
- * This may be \c NULL for anonymous structures, for arrays, or for
- * function types.
- */
- const char *name;
-
- /**
- * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
- * \c GLSL_TYPE_STRUCT, it is the number of elements in the structure and
- * the number of values pointed to by \c fields.structure (below).
- */
- unsigned length;
-
- /**
- * Subtype of composite data types.
- */
- union {
- const struct glsl_type *array; /**< Type of array elements. */
- const struct glsl_type *parameters; /**< Parameters to function. */
- struct glsl_struct_field *structure; /**< List of struct fields. */
- } fields;
-
-
- /**
- * \name Pointers to various public type singletons
- */
- /*@{*/
- static const glsl_type *const error_type;
- static const glsl_type *const void_type;
- static const glsl_type *const int_type;
- static const glsl_type *const ivec4_type;
- static const glsl_type *const uint_type;
- static const glsl_type *const uvec2_type;
- static const glsl_type *const uvec3_type;
- static const glsl_type *const uvec4_type;
- static const glsl_type *const float_type;
- static const glsl_type *const vec2_type;
- static const glsl_type *const vec3_type;
- static const glsl_type *const vec4_type;
- static const glsl_type *const bool_type;
- static const glsl_type *const mat2_type;
- static const glsl_type *const mat2x3_type;
- static const glsl_type *const mat2x4_type;
- static const glsl_type *const mat3x2_type;
- static const glsl_type *const mat3_type;
- static const glsl_type *const mat3x4_type;
- static const glsl_type *const mat4x2_type;
- static const glsl_type *const mat4x3_type;
- static const glsl_type *const mat4_type;
- /*@}*/
-
-
- /**
- * For numeric and boolean derrived types returns the basic scalar type
- *
- * If the type is a numeric or boolean scalar, vector, or matrix type,
- * this function gets the scalar type of the individual components. For
- * all other types, including arrays of numeric or boolean types, the
- * error type is returned.
- */
- const glsl_type *get_base_type() const;
-
- /**
- * Query the type of elements in an array
- *
- * \return
- * Pointer to the type of elements in the array for array types, or \c NULL
- * for non-array types.
- */
- const glsl_type *element_type() const
- {
- return is_array() ? fields.array : NULL;
- }
-
- /**
- * Get the instance of a built-in scalar, vector, or matrix type
- */
- static const glsl_type *get_instance(unsigned base_type, unsigned rows,
- unsigned columns);
-
- /**
- * Get the instance of an array type
- */
- static const glsl_type *get_array_instance(const glsl_type *base,
- unsigned elements);
-
- /**
- * Get the instance of a record type
- */
- static const glsl_type *get_record_instance(const glsl_struct_field *fields,
- unsigned num_fields,
- const char *name);
-
- /**
- * Query the total number of scalars that make up a scalar, vector or matrix
- */
- unsigned components() const
- {
- return vector_elements * matrix_columns;
- }
-
- /**
- * Calculate the number of components slots required to hold this type
- *
- * This is used to determine how many uniform or varying locations a type
- * might occupy.
- */
- unsigned component_slots() const;
-
-
- /**
- * Query whether or not a type is a scalar (non-vector and non-matrix).
- */
- bool is_scalar() const
- {
- return (vector_elements == 1)
- && (base_type >= GLSL_TYPE_UINT)
- && (base_type <= GLSL_TYPE_BOOL);
- }
-
- /**
- * Query whether or not a type is a vector
- */
- bool is_vector() const
- {
- return (vector_elements > 1)
- && (matrix_columns == 1)
- && (base_type >= GLSL_TYPE_UINT)
- && (base_type <= GLSL_TYPE_BOOL);
- }
-
- /**
- * Query whether or not a type is a matrix
- */
- bool is_matrix() const
- {
- /* GLSL only has float matrices. */
- return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT);
- }
-
- /**
- * Query whether or not a type is a non-array numeric type
- */
- bool is_numeric() const
- {
- return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_FLOAT);
- }
-
- /**
- * Query whether or not a type is an integral type
- */
- bool is_integer() const
- {
- return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT);
- }
-
- /**
- * Query whether or not a type is a float type
- */
- bool is_float() const
- {
- return base_type == GLSL_TYPE_FLOAT;
- }
-
- /**
- * Query whether or not a type is a non-array boolean type
- */
- bool is_boolean() const
- {
- return base_type == GLSL_TYPE_BOOL;
- }
-
- /**
- * Query whether or not a type is a sampler
- */
- bool is_sampler() const
- {
- return base_type == GLSL_TYPE_SAMPLER;
- }
-
- /**
- * Query whether or not a type is an array
- */
- bool is_array() const
- {
- return base_type == GLSL_TYPE_ARRAY;
- }
-
- /**
- * Query whether or not a type is a record
- */
- bool is_record() const
- {
- return base_type == GLSL_TYPE_STRUCT;
- }
-
- /**
- * Query whether or not a type is the void type singleton.
- */
- bool is_void() const
- {
- return base_type == GLSL_TYPE_VOID;
- }
-
- /**
- * Query whether or not a type is the error type singleton.
- */
- bool is_error() const
- {
- return base_type == GLSL_TYPE_ERROR;
- }
-
- /**
- * Query the full type of a matrix row
- *
- * \return
- * If the type is not a matrix, \c glsl_type::error_type is returned.
- * Otherwise a type matching the rows of the matrix is returned.
- */
- const glsl_type *row_type() const
- {
- return is_matrix()
- ? get_instance(base_type, matrix_columns, 1)
- : error_type;
- }
-
- /**
- * Query the full type of a matrix column
- *
- * \return
- * If the type is not a matrix, \c glsl_type::error_type is returned.
- * Otherwise a type matching the columns of the matrix is returned.
- */
- const glsl_type *column_type() const
- {
- return is_matrix()
- ? get_instance(base_type, vector_elements, 1)
- : error_type;
- }
-
-
- /**
- * Get the type of a structure field
- *
- * \return
- * Pointer to the type of the named field. If the type is not a structure
- * or the named field does not exist, \c glsl_type::error_type is returned.
- */
- const glsl_type *field_type(const char *name) const;
-
-
- /**
- * Get the location of a filed within a record type
- */
- int field_index(const char *name) const;
-
-
- /**
- * Query the number of elements in an array type
- *
- * \return
- * The number of elements in the array for array types or -1 for non-array
- * types. If the number of elements in the array has not yet been declared,
- * zero is returned.
- */
- int array_size() const
- {
- return is_array() ? length : -1;
- }
-
-private:
- /**
- * ralloc context for all glsl_type allocations
- *
- * Set on the first call to \c glsl_type::new.
- */
- static void *mem_ctx;
-
- void init_ralloc_type_ctx(void);
-
- /** Constructor for vector and matrix types */
- glsl_type(GLenum gl_type,
- glsl_base_type base_type, unsigned vector_elements,
- unsigned matrix_columns, const char *name);
-
- /** Constructor for sampler types */
- glsl_type(GLenum gl_type,
- enum glsl_sampler_dim dim, bool shadow, bool array,
- unsigned type, const char *name);
-
- /** Constructor for record types */
- glsl_type(const glsl_struct_field *fields, unsigned num_fields,
- const char *name);
-
- /** Constructor for array types */
- glsl_type(const glsl_type *array, unsigned length);
-
- /** Hash table containing the known array types. */
- static struct hash_table *array_types;
-
- /** Hash table containing the known record types. */
- static struct hash_table *record_types;
-
- static int record_key_compare(const void *a, const void *b);
- static unsigned record_key_hash(const void *key);
-
- /**
- * \name Pointers to various type singletons
- */
- /*@{*/
- static const glsl_type _error_type;
- static const glsl_type _void_type;
- static const glsl_type _sampler3D_type;
- static const glsl_type builtin_core_types[];
- static const glsl_type builtin_structure_types[];
- static const glsl_type builtin_110_deprecated_structure_types[];
- static const glsl_type builtin_110_types[];
- static const glsl_type builtin_120_types[];
- static const glsl_type builtin_130_types[];
- static const glsl_type builtin_ARB_texture_rectangle_types[];
- static const glsl_type builtin_EXT_texture_array_types[];
- static const glsl_type builtin_EXT_texture_buffer_object_types[];
- /*@}*/
-
- /**
- * \name Methods to populate a symbol table with built-in types.
- *
- * \internal
- * This is one of the truely annoying things about C++. Methods that are
- * completely internal and private to a type still have to be advertised to
- * the world in a public header file.
- */
- /*@{*/
- static void generate_100ES_types(glsl_symbol_table *);
- static void generate_110_types(glsl_symbol_table *);
- static void generate_120_types(glsl_symbol_table *);
- static void generate_130_types(glsl_symbol_table *);
- static void generate_ARB_texture_rectangle_types(glsl_symbol_table *, bool);
- static void generate_EXT_texture_array_types(glsl_symbol_table *, bool);
- static void generate_OES_texture_3D_types(glsl_symbol_table *, bool);
- /*@}*/
-
- /**
- * \name Friend functions.
- *
- * These functions are friends because they must have C linkage and the
- * need to call various private methods or access various private static
- * data.
- */
- /*@{*/
- friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *);
- friend void _mesa_glsl_release_types(void);
- /*@}*/
-};
-
-struct glsl_struct_field {
- const struct glsl_type *type;
- const char *name;
-};
-
-#endif /* GLSL_TYPES_H */
+/* -*- c++ -*- */
+/*
+ * Copyright © 2009 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+#ifndef GLSL_TYPES_H
+#define GLSL_TYPES_H
+
+#include <string.h>
+#include <assert.h>
+
+extern "C" {
+#include "GL/gl.h"
+}
+
+#include "ralloc.h"
+
+struct _mesa_glsl_parse_state;
+struct glsl_symbol_table;
+
+extern "C" void
+_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state);
+
+extern "C" void
+_mesa_glsl_release_types(void);
+
+enum glsl_base_type {
+ GLSL_TYPE_UINT = 0,
+ GLSL_TYPE_INT,
+ GLSL_TYPE_FLOAT,
+ GLSL_TYPE_BOOL,
+ GLSL_TYPE_SAMPLER,
+ GLSL_TYPE_STRUCT,
+ GLSL_TYPE_ARRAY,
+ GLSL_TYPE_VOID,
+ GLSL_TYPE_ERROR
+};
+
+enum glsl_sampler_dim {
+ GLSL_SAMPLER_DIM_1D = 0,
+ GLSL_SAMPLER_DIM_2D,
+ GLSL_SAMPLER_DIM_3D,
+ GLSL_SAMPLER_DIM_CUBE,
+ GLSL_SAMPLER_DIM_RECT,
+ GLSL_SAMPLER_DIM_BUF
+};
+
+
+struct glsl_type {
+ GLenum gl_type;
+ glsl_base_type base_type;
+
+ unsigned sampler_dimensionality:3;
+ unsigned sampler_shadow:1;
+ unsigned sampler_array:1;
+ unsigned sampler_type:2; /**< Type of data returned using this sampler.
+ * only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
+ * and \c GLSL_TYPE_UINT are valid.
+ */
+
+ /* Callers of this ralloc-based new need not call delete. It's
+ * easier to just ralloc_free 'mem_ctx' (or any of its ancestors). */
+ static void* operator new(size_t size)
+ {
+ if (glsl_type::mem_ctx == NULL) {
+ glsl_type::mem_ctx = ralloc_context(NULL);
+ assert(glsl_type::mem_ctx != NULL);
+ }
+
+ void *type;
+
+ type = ralloc_size(glsl_type::mem_ctx, size);
+ assert(type != NULL);
+
+ return type;
+ }
+
+ /* If the user *does* call delete, that's OK, we will just
+ * ralloc_free in that case. */
+ static void operator delete(void *type)
+ {
+ ralloc_free(type);
+ }
+
+ /**
+ * \name Vector and matrix element counts
+ *
+ * For scalars, each of these values will be 1. For non-numeric types
+ * these will be 0.
+ */
+ /*@{*/
+ unsigned vector_elements:3; /**< 1, 2, 3, or 4 vector elements. */
+ unsigned matrix_columns:3; /**< 1, 2, 3, or 4 matrix columns. */
+ /*@}*/
+
+ /**
+ * Name of the data type
+ *
+ * This may be \c NULL for anonymous structures, for arrays, or for
+ * function types.
+ */
+ const char *name;
+
+ /**
+ * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
+ * \c GLSL_TYPE_STRUCT, it is the number of elements in the structure and
+ * the number of values pointed to by \c fields.structure (below).
+ */
+ unsigned length;
+
+ /**
+ * Subtype of composite data types.
+ */
+ union {
+ const struct glsl_type *array; /**< Type of array elements. */
+ const struct glsl_type *parameters; /**< Parameters to function. */
+ struct glsl_struct_field *structure; /**< List of struct fields. */
+ } fields;
+
+
+ /**
+ * \name Pointers to various public type singletons
+ */
+ /*@{*/
+ static const glsl_type *const error_type;
+ static const glsl_type *const void_type;
+ static const glsl_type *const int_type;
+ static const glsl_type *const ivec4_type;
+ static const glsl_type *const uint_type;
+ static const glsl_type *const uvec2_type;
+ static const glsl_type *const uvec3_type;
+ static const glsl_type *const uvec4_type;
+ static const glsl_type *const float_type;
+ static const glsl_type *const vec2_type;
+ static const glsl_type *const vec3_type;
+ static const glsl_type *const vec4_type;
+ static const glsl_type *const bool_type;
+ static const glsl_type *const mat2_type;
+ static const glsl_type *const mat2x3_type;
+ static const glsl_type *const mat2x4_type;
+ static const glsl_type *const mat3x2_type;
+ static const glsl_type *const mat3_type;
+ static const glsl_type *const mat3x4_type;
+ static const glsl_type *const mat4x2_type;
+ static const glsl_type *const mat4x3_type;
+ static const glsl_type *const mat4_type;
+ /*@}*/
+
+
+ /**
+ * For numeric and boolean derrived types returns the basic scalar type
+ *
+ * If the type is a numeric or boolean scalar, vector, or matrix type,
+ * this function gets the scalar type of the individual components. For
+ * all other types, including arrays of numeric or boolean types, the
+ * error type is returned.
+ */
+ const glsl_type *get_base_type() const;
+
+ /**
+ * Query the type of elements in an array
+ *
+ * \return
+ * Pointer to the type of elements in the array for array types, or \c NULL
+ * for non-array types.
+ */
+ const glsl_type *element_type() const
+ {
+ return is_array() ? fields.array : NULL;
+ }
+
+ /**
+ * Get the instance of a built-in scalar, vector, or matrix type
+ */
+ static const glsl_type *get_instance(unsigned base_type, unsigned rows,
+ unsigned columns);
+
+ /**
+ * Get the instance of an array type
+ */
+ static const glsl_type *get_array_instance(const glsl_type *base,
+ unsigned elements);
+
+ /**
+ * Get the instance of a record type
+ */
+ static const glsl_type *get_record_instance(const glsl_struct_field *fields,
+ unsigned num_fields,
+ const char *name);
+
+ /**
+ * Query the total number of scalars that make up a scalar, vector or matrix
+ */
+ unsigned components() const
+ {
+ return vector_elements * matrix_columns;
+ }
+
+ /**
+ * Calculate the number of components slots required to hold this type
+ *
+ * This is used to determine how many uniform or varying locations a type
+ * might occupy.
+ */
+ unsigned component_slots() const;
+
+
+ /**
+ * Query whether or not a type is a scalar (non-vector and non-matrix).
+ */
+ bool is_scalar() const
+ {
+ return (vector_elements == 1)
+ && (base_type >= GLSL_TYPE_UINT)
+ && (base_type <= GLSL_TYPE_BOOL);
+ }
+
+ /**
+ * Query whether or not a type is a vector
+ */
+ bool is_vector() const
+ {
+ return (vector_elements > 1)
+ && (matrix_columns == 1)
+ && (base_type >= GLSL_TYPE_UINT)
+ && (base_type <= GLSL_TYPE_BOOL);
+ }
+
+ /**
+ * Query whether or not a type is a matrix
+ */
+ bool is_matrix() const
+ {
+ /* GLSL only has float matrices. */
+ return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT);
+ }
+
+ /**
+ * Query whether or not a type is a non-array numeric type
+ */
+ bool is_numeric() const
+ {
+ return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_FLOAT);
+ }
+
+ /**
+ * Query whether or not a type is an integral type
+ */
+ bool is_integer() const
+ {
+ return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT);
+ }
+
+ /**
+ * Query whether or not a type is a float type
+ */
+ bool is_float() const
+ {
+ return base_type == GLSL_TYPE_FLOAT;
+ }
+
+ /**
+ * Query whether or not a type is a non-array boolean type
+ */
+ bool is_boolean() const
+ {
+ return base_type == GLSL_TYPE_BOOL;
+ }
+
+ /**
+ * Query whether or not a type is a sampler
+ */
+ bool is_sampler() const
+ {
+ return base_type == GLSL_TYPE_SAMPLER;
+ }
+
+ /**
+ * Query whether or not a type is an array
+ */
+ bool is_array() const
+ {
+ return base_type == GLSL_TYPE_ARRAY;
+ }
+
+ /**
+ * Query whether or not a type is a record
+ */
+ bool is_record() const
+ {
+ return base_type == GLSL_TYPE_STRUCT;
+ }
+
+ /**
+ * Query whether or not a type is the void type singleton.
+ */
+ bool is_void() const
+ {
+ return base_type == GLSL_TYPE_VOID;
+ }
+
+ /**
+ * Query whether or not a type is the error type singleton.
+ */
+ bool is_error() const
+ {
+ return base_type == GLSL_TYPE_ERROR;
+ }
+
+ /**
+ * Query the full type of a matrix row
+ *
+ * \return
+ * If the type is not a matrix, \c glsl_type::error_type is returned.
+ * Otherwise a type matching the rows of the matrix is returned.
+ */
+ const glsl_type *row_type() const
+ {
+ return is_matrix()
+ ? get_instance(base_type, matrix_columns, 1)
+ : error_type;
+ }
+
+ /**
+ * Query the full type of a matrix column
+ *
+ * \return
+ * If the type is not a matrix, \c glsl_type::error_type is returned.
+ * Otherwise a type matching the columns of the matrix is returned.
+ */
+ const glsl_type *column_type() const
+ {
+ return is_matrix()
+ ? get_instance(base_type, vector_elements, 1)
+ : error_type;
+ }
+
+
+ /**
+ * Get the type of a structure field
+ *
+ * \return
+ * Pointer to the type of the named field. If the type is not a structure
+ * or the named field does not exist, \c glsl_type::error_type is returned.
+ */
+ const glsl_type *field_type(const char *name) const;
+
+
+ /**
+ * Get the location of a filed within a record type
+ */
+ int field_index(const char *name) const;
+
+
+ /**
+ * Query the number of elements in an array type
+ *
+ * \return
+ * The number of elements in the array for array types or -1 for non-array
+ * types. If the number of elements in the array has not yet been declared,
+ * zero is returned.
+ */
+ int array_size() const
+ {
+ return is_array() ? length : -1;
+ }
+
+private:
+ /**
+ * ralloc context for all glsl_type allocations
+ *
+ * Set on the first call to \c glsl_type::new.
+ */
+ static void *mem_ctx;
+
+ void init_ralloc_type_ctx(void);
+
+ /** Constructor for vector and matrix types */
+ glsl_type(GLenum gl_type,
+ glsl_base_type base_type, unsigned vector_elements,
+ unsigned matrix_columns, const char *name);
+
+ /** Constructor for sampler types */
+ glsl_type(GLenum gl_type,
+ enum glsl_sampler_dim dim, bool shadow, bool array,
+ unsigned type, const char *name);
+
+ /** Constructor for record types */
+ glsl_type(const glsl_struct_field *fields, unsigned num_fields,
+ const char *name);
+
+ /** Constructor for array types */
+ glsl_type(const glsl_type *array, unsigned length);
+
+ /** Hash table containing the known array types. */
+ static struct hash_table *array_types;
+
+ /** Hash table containing the known record types. */
+ static struct hash_table *record_types;
+
+ static int record_key_compare(const void *a, const void *b);
+ static unsigned record_key_hash(const void *key);
+
+ /**
+ * \name Pointers to various type singletons
+ */
+ /*@{*/
+ static const glsl_type _error_type;
+ static const glsl_type _void_type;
+ static const glsl_type _sampler3D_type;
+ static const glsl_type builtin_core_types[];
+ static const glsl_type builtin_structure_types[];
+ static const glsl_type builtin_110_deprecated_structure_types[];
+ static const glsl_type builtin_110_types[];
+ static const glsl_type builtin_120_types[];
+ static const glsl_type builtin_130_types[];
+ static const glsl_type builtin_ARB_texture_rectangle_types[];
+ static const glsl_type builtin_EXT_texture_array_types[];
+ static const glsl_type builtin_EXT_texture_buffer_object_types[];
+ /*@}*/
+
+ /**
+ * \name Methods to populate a symbol table with built-in types.
+ *
+ * \internal
+ * This is one of the truely annoying things about C++. Methods that are
+ * completely internal and private to a type still have to be advertised to
+ * the world in a public header file.
+ */
+ /*@{*/
+ static void generate_100ES_types(glsl_symbol_table *);
+ static void generate_110_types(glsl_symbol_table *);
+ static void generate_120_types(glsl_symbol_table *);
+ static void generate_130_types(glsl_symbol_table *);
+ static void generate_ARB_texture_rectangle_types(glsl_symbol_table *, bool);
+ static void generate_EXT_texture_array_types(glsl_symbol_table *, bool);
+ static void generate_OES_texture_3D_types(glsl_symbol_table *, bool);
+ /*@}*/
+
+ /**
+ * \name Friend functions.
+ *
+ * These functions are friends because they must have C linkage and the
+ * need to call various private methods or access various private static
+ * data.
+ */
+ /*@{*/
+ friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *);
+ friend void _mesa_glsl_release_types(void);
+ /*@}*/
+};
+
+struct glsl_struct_field {
+ const struct glsl_type *type;
+ const char *name;
+};
+
+#endif /* GLSL_TYPES_H */
diff --git a/mesalib/src/glsl/hir_field_selection.cpp b/mesalib/src/glsl/hir_field_selection.cpp
index 3c33127b5..21f107405 100644
--- a/mesalib/src/glsl/hir_field_selection.cpp
+++ b/mesalib/src/glsl/hir_field_selection.cpp
@@ -1,102 +1,102 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include "ir.h"
-#include "program/symbol_table.h"
-#include "glsl_parser_extras.h"
-#include "ast.h"
-#include "glsl_types.h"
-
-ir_rvalue *
-_mesa_ast_field_selection_to_hir(const ast_expression *expr,
- exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
- ir_rvalue *result = NULL;
- ir_rvalue *op;
-
- op = expr->subexpressions[0]->hir(instructions, state);
-
- /* There are two kinds of field selection. There is the selection of a
- * specific field from a structure, and there is the selection of a
- * swizzle / mask from a vector. Which is which is determined entirely
- * by the base type of the thing to which the field selection operator is
- * being applied.
- */
- YYLTYPE loc = expr->get_location();
- if (op->type->is_error()) {
- /* silently propagate the error */
- } else if (op->type->is_vector()) {
- ir_swizzle *swiz = ir_swizzle::create(op,
- expr->primary_expression.identifier,
- op->type->vector_elements);
- if (swiz != NULL) {
- result = swiz;
- } else {
- /* FINISHME: Logging of error messages should be moved into
- * FINISHME: ir_swizzle::create. This allows the generation of more
- * FINISHME: specific error messages.
- */
- _mesa_glsl_error(& loc, state, "Invalid swizzle / mask `%s'",
- expr->primary_expression.identifier);
- }
- } else if (op->type->base_type == GLSL_TYPE_STRUCT) {
- result = new(ctx) ir_dereference_record(op,
- expr->primary_expression.identifier);
-
- if (result->type->is_error()) {
- _mesa_glsl_error(& loc, state, "Cannot access field `%s' of "
- "structure",
- expr->primary_expression.identifier);
- }
- } else if (expr->subexpressions[1] != NULL) {
- /* Handle "method calls" in GLSL 1.20 - namely, array.length() */
- if (state->language_version < 120)
- _mesa_glsl_error(&loc, state, "Methods not supported in GLSL 1.10.");
-
- ast_expression *call = expr->subexpressions[1];
- assert(call->oper == ast_function_call);
-
- const char *method;
- method = call->subexpressions[0]->primary_expression.identifier;
-
- if (op->type->is_array() && strcmp(method, "length") == 0) {
- if (!call->expressions.is_empty())
- _mesa_glsl_error(&loc, state, "length method takes no arguments.");
-
- if (op->type->array_size() == 0)
- _mesa_glsl_error(&loc, state, "length called on unsized array.");
-
- result = new(ctx) ir_constant(op->type->array_size());
- } else {
- _mesa_glsl_error(&loc, state, "Unknown method: `%s'.", method);
- }
- } else {
- _mesa_glsl_error(& loc, state, "Cannot access field `%s' of "
- "non-structure / non-vector.",
- expr->primary_expression.identifier);
- }
-
- return result ? result : ir_call::get_error_instruction(ctx);
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "ir.h"
+#include "program/symbol_table.h"
+#include "glsl_parser_extras.h"
+#include "ast.h"
+#include "glsl_types.h"
+
+ir_rvalue *
+_mesa_ast_field_selection_to_hir(const ast_expression *expr,
+ exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ void *ctx = state;
+ ir_rvalue *result = NULL;
+ ir_rvalue *op;
+
+ op = expr->subexpressions[0]->hir(instructions, state);
+
+ /* There are two kinds of field selection. There is the selection of a
+ * specific field from a structure, and there is the selection of a
+ * swizzle / mask from a vector. Which is which is determined entirely
+ * by the base type of the thing to which the field selection operator is
+ * being applied.
+ */
+ YYLTYPE loc = expr->get_location();
+ if (op->type->is_error()) {
+ /* silently propagate the error */
+ } else if (op->type->is_vector()) {
+ ir_swizzle *swiz = ir_swizzle::create(op,
+ expr->primary_expression.identifier,
+ op->type->vector_elements);
+ if (swiz != NULL) {
+ result = swiz;
+ } else {
+ /* FINISHME: Logging of error messages should be moved into
+ * FINISHME: ir_swizzle::create. This allows the generation of more
+ * FINISHME: specific error messages.
+ */
+ _mesa_glsl_error(& loc, state, "Invalid swizzle / mask `%s'",
+ expr->primary_expression.identifier);
+ }
+ } else if (op->type->base_type == GLSL_TYPE_STRUCT) {
+ result = new(ctx) ir_dereference_record(op,
+ expr->primary_expression.identifier);
+
+ if (result->type->is_error()) {
+ _mesa_glsl_error(& loc, state, "Cannot access field `%s' of "
+ "structure",
+ expr->primary_expression.identifier);
+ }
+ } else if (expr->subexpressions[1] != NULL) {
+ /* Handle "method calls" in GLSL 1.20 - namely, array.length() */
+ if (state->language_version < 120)
+ _mesa_glsl_error(&loc, state, "Methods not supported in GLSL 1.10.");
+
+ ast_expression *call = expr->subexpressions[1];
+ assert(call->oper == ast_function_call);
+
+ const char *method;
+ method = call->subexpressions[0]->primary_expression.identifier;
+
+ if (op->type->is_array() && strcmp(method, "length") == 0) {
+ if (!call->expressions.is_empty())
+ _mesa_glsl_error(&loc, state, "length method takes no arguments.");
+
+ if (op->type->array_size() == 0)
+ _mesa_glsl_error(&loc, state, "length called on unsized array.");
+
+ result = new(ctx) ir_constant(op->type->array_size());
+ } else {
+ _mesa_glsl_error(&loc, state, "Unknown method: `%s'.", method);
+ }
+ } else {
+ _mesa_glsl_error(& loc, state, "Cannot access field `%s' of "
+ "non-structure / non-vector.",
+ expr->primary_expression.identifier);
+ }
+
+ return result ? result : ir_call::get_error_instruction(ctx);
+}
diff --git a/mesalib/src/glsl/ir.h b/mesalib/src/glsl/ir.h
index f2f902c0a..fcf1931ff 100644
--- a/mesalib/src/glsl/ir.h
+++ b/mesalib/src/glsl/ir.h
@@ -1,1640 +1,1640 @@
-/* -*- c++ -*- */
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#pragma once
-#ifndef IR_H
-#define IR_H
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "ralloc.h"
-#include "glsl_types.h"
-#include "list.h"
-#include "ir_visitor.h"
-#include "ir_hierarchical_visitor.h"
-
-/**
- * \defgroup IR Intermediate representation nodes
- *
- * @{
- */
-
-/**
- * Class tags
- *
- * Each concrete class derived from \c ir_instruction has a value in this
- * enumerant. The value for the type is stored in \c ir_instruction::ir_type
- * by the constructor. While using type tags is not very C++, it is extremely
- * convenient. For example, during debugging you can simply inspect
- * \c ir_instruction::ir_type to find out the actual type of the object.
- *
- * In addition, it is possible to use a switch-statement based on \c
- * \c ir_instruction::ir_type to select different behavior for different object
- * types. For functions that have only slight differences for several object
- * types, this allows writing very straightforward, readable code.
- */
-enum ir_node_type {
- /**
- * Zero is unused so that the IR validator can detect cases where
- * \c ir_instruction::ir_type has not been initialized.
- */
- ir_type_unset,
- ir_type_variable,
- ir_type_assignment,
- ir_type_call,
- ir_type_constant,
- ir_type_dereference_array,
- ir_type_dereference_record,
- ir_type_dereference_variable,
- ir_type_discard,
- ir_type_expression,
- ir_type_function,
- ir_type_function_signature,
- ir_type_if,
- ir_type_loop,
- ir_type_loop_jump,
- ir_type_return,
- ir_type_swizzle,
- ir_type_texture,
- ir_type_max /**< maximum ir_type enum number, for validation */
-};
-
-/**
- * Base class of all IR instructions
- */
-class ir_instruction : public exec_node {
-public:
- enum ir_node_type ir_type;
- const struct glsl_type *type;
-
- /** ir_print_visitor helper for debugging. */
- void print(void) const;
-
- virtual void accept(ir_visitor *) = 0;
- virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0;
- virtual ir_instruction *clone(void *mem_ctx,
- struct hash_table *ht) const = 0;
-
- /**
- * \name IR instruction downcast functions
- *
- * These functions either cast the object to a derived class or return
- * \c NULL if the object's type does not match the specified derived class.
- * Additional downcast functions will be added as needed.
- */
- /*@{*/
- virtual class ir_variable * as_variable() { return NULL; }
- virtual class ir_function * as_function() { return NULL; }
- virtual class ir_dereference * as_dereference() { return NULL; }
- virtual class ir_dereference_array * as_dereference_array() { return NULL; }
- virtual class ir_dereference_variable *as_dereference_variable() { return NULL; }
- virtual class ir_expression * as_expression() { return NULL; }
- virtual class ir_rvalue * as_rvalue() { return NULL; }
- virtual class ir_loop * as_loop() { return NULL; }
- virtual class ir_assignment * as_assignment() { return NULL; }
- virtual class ir_call * as_call() { return NULL; }
- virtual class ir_return * as_return() { return NULL; }
- virtual class ir_if * as_if() { return NULL; }
- virtual class ir_swizzle * as_swizzle() { return NULL; }
- virtual class ir_constant * as_constant() { return NULL; }
- virtual class ir_discard * as_discard() { return NULL; }
- /*@}*/
-
-protected:
- ir_instruction()
- {
- ir_type = ir_type_unset;
- type = NULL;
- }
-};
-
-
-class ir_rvalue : public ir_instruction {
-public:
- virtual ir_rvalue *clone(void *mem_ctx, struct hash_table *) const = 0;
-
- virtual ir_constant *constant_expression_value() = 0;
-
- virtual ir_rvalue * as_rvalue()
- {
- return this;
- }
-
- ir_rvalue *as_rvalue_to_saturate();
-
- virtual bool is_lvalue()
- {
- return false;
- }
-
- /**
- * Get the variable that is ultimately referenced by an r-value
- */
- virtual ir_variable *variable_referenced()
- {
- return NULL;
- }
-
-
- /**
- * If an r-value is a reference to a whole variable, get that variable
- *
- * \return
- * Pointer to a variable that is completely dereferenced by the r-value. If
- * the r-value is not a dereference or the dereference does not access the
- * entire variable (i.e., it's just one array element, struct field), \c NULL
- * is returned.
- */
- virtual ir_variable *whole_variable_referenced()
- {
- return NULL;
- }
-
- /**
- * Determine if an r-value has the value zero
- *
- * The base implementation of this function always returns \c false. The
- * \c ir_constant class over-rides this function to return \c true \b only
- * for vector and scalar types that have all elements set to the value
- * zero (or \c false for booleans).
- *
- * \sa ir_constant::has_value, ir_rvalue::is_one, ir_rvalue::is_negative_one
- */
- virtual bool is_zero() const;
-
- /**
- * Determine if an r-value has the value one
- *
- * The base implementation of this function always returns \c false. The
- * \c ir_constant class over-rides this function to return \c true \b only
- * for vector and scalar types that have all elements set to the value
- * one (or \c true for booleans).
- *
- * \sa ir_constant::has_value, ir_rvalue::is_zero, ir_rvalue::is_negative_one
- */
- virtual bool is_one() const;
-
- /**
- * Determine if an r-value has the value negative one
- *
- * The base implementation of this function always returns \c false. The
- * \c ir_constant class over-rides this function to return \c true \b only
- * for vector and scalar types that have all elements set to the value
- * negative one. For boolean times, the result is always \c false.
- *
- * \sa ir_constant::has_value, ir_rvalue::is_zero, ir_rvalue::is_one
- */
- virtual bool is_negative_one() const;
-
-protected:
- ir_rvalue();
-};
-
-
-/**
- * Variable storage classes
- */
-enum ir_variable_mode {
- ir_var_auto = 0, /**< Function local variables and globals. */
- ir_var_uniform, /**< Variable declared as a uniform. */
- ir_var_in,
- ir_var_out,
- ir_var_inout,
- ir_var_const_in, /**< "in" param that must be a constant expression */
- ir_var_system_value, /**< Ex: front-face, instance-id, etc. */
- ir_var_temporary /**< Temporary variable generated during compilation. */
-};
-
-enum ir_variable_interpolation {
- ir_var_smooth = 0,
- ir_var_flat,
- ir_var_noperspective
-};
-
-/**
- * \brief Layout qualifiers for gl_FragDepth.
- *
- * The AMD_conservative_depth extension allows gl_FragDepth to be redeclared
- * with a layout qualifier.
- */
-enum ir_depth_layout {
- ir_depth_layout_none, /**< No depth layout is specified. */
- ir_depth_layout_any,
- ir_depth_layout_greater,
- ir_depth_layout_less,
- ir_depth_layout_unchanged
-};
-
-/**
- * \brief Convert depth layout qualifier to string.
- */
-const char*
-depth_layout_string(ir_depth_layout layout);
-
-class ir_variable : public ir_instruction {
-public:
- ir_variable(const struct glsl_type *, const char *, ir_variable_mode);
-
- virtual ir_variable *clone(void *mem_ctx, struct hash_table *ht) const;
-
- virtual ir_variable *as_variable()
- {
- return this;
- }
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
-
- /**
- * Get the string value for the interpolation qualifier
- *
- * \return The string that would be used in a shader to specify \c
- * mode will be returned.
- *
- * This function should only be used on a shader input or output variable.
- */
- const char *interpolation_string() const;
-
- /**
- * Calculate the number of slots required to hold this variable
- *
- * This is used to determine how many uniform or varying locations a variable
- * occupies. The count is in units of floating point components.
- */
- unsigned component_slots() const;
-
- /**
- * Delcared name of the variable
- */
- const char *name;
-
- /**
- * Highest element accessed with a constant expression array index
- *
- * Not used for non-array variables.
- */
- unsigned max_array_access;
-
- /**
- * Is the variable read-only?
- *
- * This is set for variables declared as \c const, shader inputs,
- * and uniforms.
- */
- unsigned read_only:1;
- unsigned centroid:1;
- unsigned invariant:1;
-
- /**
- * Has this variable been used for reading or writing?
- *
- * Several GLSL semantic checks require knowledge of whether or not a
- * variable has been used. For example, it is an error to redeclare a
- * variable as invariant after it has been used.
- */
- unsigned used:1;
-
- /**
- * Storage class of the variable.
- *
- * \sa ir_variable_mode
- */
- unsigned mode:3;
-
- /**
- * Interpolation mode for shader inputs / outputs
- *
- * \sa ir_variable_interpolation
- */
- unsigned interpolation:2;
-
- /**
- * Flag that the whole array is assignable
- *
- * In GLSL 1.20 and later whole arrays are assignable (and comparable for
- * equality). This flag enables this behavior.
- */
- unsigned array_lvalue:1;
-
- /**
- * \name ARB_fragment_coord_conventions
- * @{
- */
- unsigned origin_upper_left:1;
- unsigned pixel_center_integer:1;
- /*@}*/
-
- /**
- * \brief Layout qualifier for gl_FragDepth.
- *
- * This is not equal to \c ir_depth_layout_none if and only if this
- * variable is \c gl_FragDepth and a layout qualifier is specified.
- */
- ir_depth_layout depth_layout;
-
- /**
- * Was the location explicitly set in the shader?
- *
- * If the location is explicitly set in the shader, it \b cannot be changed
- * by the linker or by the API (e.g., calls to \c glBindAttribLocation have
- * no effect).
- */
- unsigned explicit_location:1;
-
- /**
- * Storage location of the base of this variable
- *
- * The precise meaning of this field depends on the nature of the variable.
- *
- * - Vertex shader input: one of the values from \c gl_vert_attrib.
- * - Vertex shader output: one of the values from \c gl_vert_result.
- * - Fragment shader input: one of the values from \c gl_frag_attrib.
- * - Fragment shader output: one of the values from \c gl_frag_result.
- * - Uniforms: Per-stage uniform slot number.
- * - Other: This field is not currently used.
- *
- * If the variable is a uniform, shader input, or shader output, and the
- * slot has not been assigned, the value will be -1.
- */
- int location;
-
- /**
- * Emit a warning if this variable is accessed.
- */
- const char *warn_extension;
-
- /**
- * Value assigned in the initializer of a variable declared "const"
- */
- ir_constant *constant_value;
-};
-
-
-/*@{*/
-/**
- * The representation of a function instance; may be the full definition or
- * simply a prototype.
- */
-class ir_function_signature : public ir_instruction {
- /* An ir_function_signature will be part of the list of signatures in
- * an ir_function.
- */
-public:
- ir_function_signature(const glsl_type *return_type);
-
- virtual ir_function_signature *clone(void *mem_ctx,
- struct hash_table *ht) const;
- ir_function_signature *clone_prototype(void *mem_ctx,
- struct hash_table *ht) const;
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- /**
- * Get the name of the function for which this is a signature
- */
- const char *function_name() const;
-
- /**
- * Get a handle to the function for which this is a signature
- *
- * There is no setter function, this function returns a \c const pointer,
- * and \c ir_function_signature::_function is private for a reason. The
- * only way to make a connection between a function and function signature
- * is via \c ir_function::add_signature. This helps ensure that certain
- * invariants (i.e., a function signature is in the list of signatures for
- * its \c _function) are met.
- *
- * \sa ir_function::add_signature
- */
- inline const class ir_function *function() const
- {
- return this->_function;
- }
-
- /**
- * Check whether the qualifiers match between this signature's parameters
- * and the supplied parameter list. If not, returns the name of the first
- * parameter with mismatched qualifiers (for use in error messages).
- */
- const char *qualifiers_match(exec_list *params);
-
- /**
- * Replace the current parameter list with the given one. This is useful
- * if the current information came from a prototype, and either has invalid
- * or missing parameter names.
- */
- void replace_parameters(exec_list *new_params);
-
- /**
- * Function return type.
- *
- * \note This discards the optional precision qualifier.
- */
- const struct glsl_type *return_type;
-
- /**
- * List of ir_variable of function parameters.
- *
- * This represents the storage. The paramaters passed in a particular
- * call will be in ir_call::actual_paramaters.
- */
- struct exec_list parameters;
-
- /** Whether or not this function has a body (which may be empty). */
- unsigned is_defined:1;
-
- /** Whether or not this function signature is a built-in. */
- unsigned is_builtin:1;
-
- /** Body of instructions in the function. */
- struct exec_list body;
-
-private:
- /** Function of which this signature is one overload. */
- class ir_function *_function;
-
- friend class ir_function;
-};
-
-
-/**
- * Header for tracking multiple overloaded functions with the same name.
- * Contains a list of ir_function_signatures representing each of the
- * actual functions.
- */
-class ir_function : public ir_instruction {
-public:
- ir_function(const char *name);
-
- virtual ir_function *clone(void *mem_ctx, struct hash_table *ht) const;
-
- virtual ir_function *as_function()
- {
- return this;
- }
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- void add_signature(ir_function_signature *sig)
- {
- sig->_function = this;
- this->signatures.push_tail(sig);
- }
-
- /**
- * Get an iterator for the set of function signatures
- */
- exec_list_iterator iterator()
- {
- return signatures.iterator();
- }
-
- /**
- * Find a signature that matches a set of actual parameters, taking implicit
- * conversions into account.
- */
- ir_function_signature *matching_signature(const exec_list *actual_param);
-
- /**
- * Find a signature that exactly matches a set of actual parameters without
- * any implicit type conversions.
- */
- ir_function_signature *exact_matching_signature(const exec_list *actual_ps);
-
- /**
- * Name of the function.
- */
- const char *name;
-
- /** Whether or not this function has a signature that isn't a built-in. */
- bool has_user_signature();
-
- /**
- * List of ir_function_signature for each overloaded function with this name.
- */
- struct exec_list signatures;
-};
-
-inline const char *ir_function_signature::function_name() const
-{
- return this->_function->name;
-}
-/*@}*/
-
-
-/**
- * IR instruction representing high-level if-statements
- */
-class ir_if : public ir_instruction {
-public:
- ir_if(ir_rvalue *condition)
- : condition(condition)
- {
- ir_type = ir_type_if;
- }
-
- virtual ir_if *clone(void *mem_ctx, struct hash_table *ht) const;
-
- virtual ir_if *as_if()
- {
- return this;
- }
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- ir_rvalue *condition;
- /** List of ir_instruction for the body of the then branch */
- exec_list then_instructions;
- /** List of ir_instruction for the body of the else branch */
- exec_list else_instructions;
-};
-
-
-/**
- * IR instruction representing a high-level loop structure.
- */
-class ir_loop : public ir_instruction {
-public:
- ir_loop();
-
- virtual ir_loop *clone(void *mem_ctx, struct hash_table *ht) const;
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- virtual ir_loop *as_loop()
- {
- return this;
- }
-
- /**
- * Get an iterator for the instructions of the loop body
- */
- exec_list_iterator iterator()
- {
- return body_instructions.iterator();
- }
-
- /** List of ir_instruction that make up the body of the loop. */
- exec_list body_instructions;
-
- /**
- * \name Loop counter and controls
- *
- * Represents a loop like a FORTRAN \c do-loop.
- *
- * \note
- * If \c from and \c to are the same value, the loop will execute once.
- */
- /*@{*/
- ir_rvalue *from; /** Value of the loop counter on the first
- * iteration of the loop.
- */
- ir_rvalue *to; /** Value of the loop counter on the last
- * iteration of the loop.
- */
- ir_rvalue *increment;
- ir_variable *counter;
-
- /**
- * Comparison operation in the loop terminator.
- *
- * If any of the loop control fields are non-\c NULL, this field must be
- * one of \c ir_binop_less, \c ir_binop_greater, \c ir_binop_lequal,
- * \c ir_binop_gequal, \c ir_binop_equal, or \c ir_binop_nequal.
- */
- int cmp;
- /*@}*/
-};
-
-
-class ir_assignment : public ir_instruction {
-public:
- ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition);
-
- /**
- * Construct an assignment with an explicit write mask
- *
- * \note
- * Since a write mask is supplied, the LHS must already be a bare
- * \c ir_dereference. The cannot be any swizzles in the LHS.
- */
- ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, ir_rvalue *condition,
- unsigned write_mask);
-
- virtual ir_assignment *clone(void *mem_ctx, struct hash_table *ht) const;
-
- virtual ir_constant *constant_expression_value();
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- virtual ir_assignment * as_assignment()
- {
- return this;
- }
-
- /**
- * Get a whole variable written by an assignment
- *
- * If the LHS of the assignment writes a whole variable, the variable is
- * returned. Otherwise \c NULL is returned. Examples of whole-variable
- * assignment are:
- *
- * - Assigning to a scalar
- * - Assigning to all components of a vector
- * - Whole array (or matrix) assignment
- * - Whole structure assignment
- */
- ir_variable *whole_variable_written();
-
- /**
- * Set the LHS of an assignment
- */
- void set_lhs(ir_rvalue *lhs);
-
- /**
- * Left-hand side of the assignment.
- *
- * This should be treated as read only. If you need to set the LHS of an
- * assignment, use \c ir_assignment::set_lhs.
- */
- ir_dereference *lhs;
-
- /**
- * Value being assigned
- */
- ir_rvalue *rhs;
-
- /**
- * Optional condition for the assignment.
- */
- ir_rvalue *condition;
-
-
- /**
- * Component mask written
- *
- * For non-vector types in the LHS, this field will be zero. For vector
- * types, a bit will be set for each component that is written. Note that
- * for \c vec2 and \c vec3 types only the lower bits will ever be set.
- *
- * A partially-set write mask means that each enabled channel gets
- * the value from a consecutive channel of the rhs. For example,
- * to write just .xyw of gl_FrontColor with color:
- *
- * (assign (constant bool (1)) (xyw)
- * (var_ref gl_FragColor)
- * (swiz xyw (var_ref color)))
- */
- unsigned write_mask:4;
-};
-
-/* Update ir_expression::num_operands() and operator_strs when
- * updating this list.
- */
-enum ir_expression_operation {
- ir_unop_bit_not,
- ir_unop_logic_not,
- ir_unop_neg,
- ir_unop_abs,
- ir_unop_sign,
- ir_unop_rcp,
- ir_unop_rsq,
- ir_unop_sqrt,
- ir_unop_exp, /**< Log base e on gentype */
- ir_unop_log, /**< Natural log on gentype */
- ir_unop_exp2,
- ir_unop_log2,
- ir_unop_f2i, /**< Float-to-integer conversion. */
- ir_unop_i2f, /**< Integer-to-float conversion. */
- ir_unop_f2b, /**< Float-to-boolean conversion */
- ir_unop_b2f, /**< Boolean-to-float conversion */
- ir_unop_i2b, /**< int-to-boolean conversion */
- ir_unop_b2i, /**< Boolean-to-int conversion */
- ir_unop_u2f, /**< Unsigned-to-float conversion. */
- ir_unop_any,
-
- /**
- * \name Unary floating-point rounding operations.
- */
- /*@{*/
- ir_unop_trunc,
- ir_unop_ceil,
- ir_unop_floor,
- ir_unop_fract,
- ir_unop_round_even,
- /*@}*/
-
- /**
- * \name Trigonometric operations.
- */
- /*@{*/
- ir_unop_sin,
- ir_unop_cos,
- ir_unop_sin_reduced, /**< Reduced range sin. [-pi, pi] */
- ir_unop_cos_reduced, /**< Reduced range cos. [-pi, pi] */
- /*@}*/
-
- /**
- * \name Partial derivatives.
- */
- /*@{*/
- ir_unop_dFdx,
- ir_unop_dFdy,
- /*@}*/
-
- ir_unop_noise,
-
- /**
- * A sentinel marking the last of the unary operations.
- */
- ir_last_unop = ir_unop_noise,
-
- ir_binop_add,
- ir_binop_sub,
- ir_binop_mul,
- ir_binop_div,
-
- /**
- * Takes one of two combinations of arguments:
- *
- * - mod(vecN, vecN)
- * - mod(vecN, float)
- *
- * Does not take integer types.
- */
- ir_binop_mod,
-
- /**
- * \name Binary comparison operators which return a boolean vector.
- * The type of both operands must be equal.
- */
- /*@{*/
- ir_binop_less,
- ir_binop_greater,
- ir_binop_lequal,
- ir_binop_gequal,
- ir_binop_equal,
- ir_binop_nequal,
- /**
- * Returns single boolean for whether all components of operands[0]
- * equal the components of operands[1].
- */
- ir_binop_all_equal,
- /**
- * Returns single boolean for whether any component of operands[0]
- * is not equal to the corresponding component of operands[1].
- */
- ir_binop_any_nequal,
- /*@}*/
-
- /**
- * \name Bit-wise binary operations.
- */
- /*@{*/
- ir_binop_lshift,
- ir_binop_rshift,
- ir_binop_bit_and,
- ir_binop_bit_xor,
- ir_binop_bit_or,
- /*@}*/
-
- ir_binop_logic_and,
- ir_binop_logic_xor,
- ir_binop_logic_or,
-
- ir_binop_dot,
- ir_binop_min,
- ir_binop_max,
-
- ir_binop_pow,
-
- /**
- * A sentinel marking the last of the binary operations.
- */
- ir_last_binop = ir_binop_pow,
-
- ir_quadop_vector,
-
- /**
- * A sentinel marking the last of all operations.
- */
- ir_last_opcode = ir_last_binop
-};
-
-class ir_expression : public ir_rvalue {
-public:
- /**
- * Constructor for unary operation expressions
- */
- ir_expression(int op, const struct glsl_type *type, ir_rvalue *);
- ir_expression(int op, ir_rvalue *);
-
- /**
- * Constructor for binary operation expressions
- */
- ir_expression(int op, const struct glsl_type *type,
- ir_rvalue *, ir_rvalue *);
- ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1);
-
- /**
- * Constructor for quad operator expressions
- */
- ir_expression(int op, const struct glsl_type *type,
- ir_rvalue *, ir_rvalue *, ir_rvalue *, ir_rvalue *);
-
- virtual ir_expression *as_expression()
- {
- return this;
- }
-
- virtual ir_expression *clone(void *mem_ctx, struct hash_table *ht) const;
-
- /**
- * Attempt to constant-fold the expression
- *
- * If the expression cannot be constant folded, this method will return
- * \c NULL.
- */
- virtual ir_constant *constant_expression_value();
-
- /**
- * Determine the number of operands used by an expression
- */
- static unsigned int get_num_operands(ir_expression_operation);
-
- /**
- * Determine the number of operands used by an expression
- */
- unsigned int get_num_operands() const
- {
- return (this->operation == ir_quadop_vector)
- ? this->type->vector_elements : get_num_operands(operation);
- }
-
- /**
- * Return a string representing this expression's operator.
- */
- const char *operator_string();
-
- /**
- * Return a string representing this expression's operator.
- */
- static const char *operator_string(ir_expression_operation);
-
-
- /**
- * Do a reverse-lookup to translate the given string into an operator.
- */
- static ir_expression_operation get_operator(const char *);
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- ir_expression_operation operation;
- ir_rvalue *operands[4];
-};
-
-
-/**
- * IR instruction representing a function call
- */
-class ir_call : public ir_rvalue {
-public:
- ir_call(ir_function_signature *callee, exec_list *actual_parameters)
- : callee(callee)
- {
- ir_type = ir_type_call;
- assert(callee->return_type != NULL);
- type = callee->return_type;
- actual_parameters->move_nodes_to(& this->actual_parameters);
- }
-
- virtual ir_call *clone(void *mem_ctx, struct hash_table *ht) const;
-
- virtual ir_constant *constant_expression_value();
-
- virtual ir_call *as_call()
- {
- return this;
- }
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- /**
- * Get a generic ir_call object when an error occurs
- *
- * Any allocation will be performed with 'ctx' as ralloc owner.
- */
- static ir_call *get_error_instruction(void *ctx);
-
- /**
- * Get an iterator for the set of acutal parameters
- */
- exec_list_iterator iterator()
- {
- return actual_parameters.iterator();
- }
-
- /**
- * Get the name of the function being called.
- */
- const char *callee_name() const
- {
- return callee->function_name();
- }
-
- /**
- * Get the function signature bound to this function call
- */
- ir_function_signature *get_callee()
- {
- return callee;
- }
-
- /**
- * Set the function call target
- */
- void set_callee(ir_function_signature *sig);
-
- /**
- * Generates an inline version of the function before @ir,
- * returning the return value of the function.
- */
- ir_rvalue *generate_inline(ir_instruction *ir);
-
- /* List of ir_rvalue of paramaters passed in this call. */
- exec_list actual_parameters;
-
-private:
- ir_call()
- : callee(NULL)
- {
- this->ir_type = ir_type_call;
- }
-
- ir_function_signature *callee;
-};
-
-
-/**
- * \name Jump-like IR instructions.
- *
- * These include \c break, \c continue, \c return, and \c discard.
- */
-/*@{*/
-class ir_jump : public ir_instruction {
-protected:
- ir_jump()
- {
- ir_type = ir_type_unset;
- }
-};
-
-class ir_return : public ir_jump {
-public:
- ir_return()
- : value(NULL)
- {
- this->ir_type = ir_type_return;
- }
-
- ir_return(ir_rvalue *value)
- : value(value)
- {
- this->ir_type = ir_type_return;
- }
-
- virtual ir_return *clone(void *mem_ctx, struct hash_table *) const;
-
- virtual ir_return *as_return()
- {
- return this;
- }
-
- ir_rvalue *get_value() const
- {
- return value;
- }
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- ir_rvalue *value;
-};
-
-
-/**
- * Jump instructions used inside loops
- *
- * These include \c break and \c continue. The \c break within a loop is
- * different from the \c break within a switch-statement.
- *
- * \sa ir_switch_jump
- */
-class ir_loop_jump : public ir_jump {
-public:
- enum jump_mode {
- jump_break,
- jump_continue
- };
-
- ir_loop_jump(jump_mode mode)
- {
- this->ir_type = ir_type_loop_jump;
- this->mode = mode;
- this->loop = loop;
- }
-
- virtual ir_loop_jump *clone(void *mem_ctx, struct hash_table *) const;
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- bool is_break() const
- {
- return mode == jump_break;
- }
-
- bool is_continue() const
- {
- return mode == jump_continue;
- }
-
- /** Mode selector for the jump instruction. */
- enum jump_mode mode;
-private:
- /** Loop containing this break instruction. */
- ir_loop *loop;
-};
-
-/**
- * IR instruction representing discard statements.
- */
-class ir_discard : public ir_jump {
-public:
- ir_discard()
- {
- this->ir_type = ir_type_discard;
- this->condition = NULL;
- }
-
- ir_discard(ir_rvalue *cond)
- {
- this->ir_type = ir_type_discard;
- this->condition = cond;
- }
-
- virtual ir_discard *clone(void *mem_ctx, struct hash_table *ht) const;
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- virtual ir_discard *as_discard()
- {
- return this;
- }
-
- ir_rvalue *condition;
-};
-/*@}*/
-
-
-/**
- * Texture sampling opcodes used in ir_texture
- */
-enum ir_texture_opcode {
- ir_tex, /**< Regular texture look-up */
- ir_txb, /**< Texture look-up with LOD bias */
- ir_txl, /**< Texture look-up with explicit LOD */
- ir_txd, /**< Texture look-up with partial derivatvies */
- ir_txf /**< Texel fetch with explicit LOD */
-};
-
-
-/**
- * IR instruction to sample a texture
- *
- * The specific form of the IR instruction depends on the \c mode value
- * selected from \c ir_texture_opcodes. In the printed IR, these will
- * appear as:
- *
- * Texel offset (0 or an expression)
- * | Projection divisor
- * | | Shadow comparitor
- * | | |
- * v v v
- * (tex <sampler> <coordinate> 0 1 ( ))
- * (txb <sampler> <coordinate> 0 1 ( ) <bias>)
- * (txl <sampler> <coordinate> 0 1 ( ) <lod>)
- * (txd <sampler> <coordinate> 0 1 ( ) (dPdx dPdy))
- * (txf <sampler> <coordinate> 0 <lod>)
- */
-class ir_texture : public ir_rvalue {
-public:
- ir_texture(enum ir_texture_opcode op)
- : op(op), projector(NULL), shadow_comparitor(NULL), offset(NULL)
- {
- this->ir_type = ir_type_texture;
- }
-
- virtual ir_texture *clone(void *mem_ctx, struct hash_table *) const;
-
- virtual ir_constant *constant_expression_value();
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- /**
- * Return a string representing the ir_texture_opcode.
- */
- const char *opcode_string();
-
- /** Set the sampler and infer the type. */
- void set_sampler(ir_dereference *sampler);
-
- /**
- * Do a reverse-lookup to translate a string into an ir_texture_opcode.
- */
- static ir_texture_opcode get_opcode(const char *);
-
- enum ir_texture_opcode op;
-
- /** Sampler to use for the texture access. */
- ir_dereference *sampler;
-
- /** Texture coordinate to sample */
- ir_rvalue *coordinate;
-
- /**
- * Value used for projective divide.
- *
- * If there is no projective divide (the common case), this will be
- * \c NULL. Optimization passes should check for this to point to a constant
- * of 1.0 and replace that with \c NULL.
- */
- ir_rvalue *projector;
-
- /**
- * Coordinate used for comparison on shadow look-ups.
- *
- * If there is no shadow comparison, this will be \c NULL. For the
- * \c ir_txf opcode, this *must* be \c NULL.
- */
- ir_rvalue *shadow_comparitor;
-
- /** Texel offset. */
- ir_rvalue *offset;
-
- union {
- ir_rvalue *lod; /**< Floating point LOD */
- ir_rvalue *bias; /**< Floating point LOD bias */
- struct {
- ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */
- ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */
- } grad;
- } lod_info;
-};
-
-
-struct ir_swizzle_mask {
- unsigned x:2;
- unsigned y:2;
- unsigned z:2;
- unsigned w:2;
-
- /**
- * Number of components in the swizzle.
- */
- unsigned num_components:3;
-
- /**
- * Does the swizzle contain duplicate components?
- *
- * L-value swizzles cannot contain duplicate components.
- */
- unsigned has_duplicates:1;
-};
-
-
-class ir_swizzle : public ir_rvalue {
-public:
- ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w,
- unsigned count);
-
- ir_swizzle(ir_rvalue *val, const unsigned *components, unsigned count);
-
- ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask);
-
- virtual ir_swizzle *clone(void *mem_ctx, struct hash_table *) const;
-
- virtual ir_constant *constant_expression_value();
-
- virtual ir_swizzle *as_swizzle()
- {
- return this;
- }
-
- /**
- * Construct an ir_swizzle from the textual representation. Can fail.
- */
- static ir_swizzle *create(ir_rvalue *, const char *, unsigned vector_length);
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- bool is_lvalue()
- {
- return val->is_lvalue() && !mask.has_duplicates;
- }
-
- /**
- * Get the variable that is ultimately referenced by an r-value
- */
- virtual ir_variable *variable_referenced();
-
- ir_rvalue *val;
- ir_swizzle_mask mask;
-
-private:
- /**
- * Initialize the mask component of a swizzle
- *
- * This is used by the \c ir_swizzle constructors.
- */
- void init_mask(const unsigned *components, unsigned count);
-};
-
-
-class ir_dereference : public ir_rvalue {
-public:
- virtual ir_dereference *clone(void *mem_ctx, struct hash_table *) const = 0;
-
- virtual ir_dereference *as_dereference()
- {
- return this;
- }
-
- bool is_lvalue();
-
- /**
- * Get the variable that is ultimately referenced by an r-value
- */
- virtual ir_variable *variable_referenced() = 0;
-};
-
-
-class ir_dereference_variable : public ir_dereference {
-public:
- ir_dereference_variable(ir_variable *var);
-
- virtual ir_dereference_variable *clone(void *mem_ctx,
- struct hash_table *) const;
-
- virtual ir_constant *constant_expression_value();
-
- virtual ir_dereference_variable *as_dereference_variable()
- {
- return this;
- }
-
- /**
- * Get the variable that is ultimately referenced by an r-value
- */
- virtual ir_variable *variable_referenced()
- {
- return this->var;
- }
-
- virtual ir_variable *whole_variable_referenced()
- {
- /* ir_dereference_variable objects always dereference the entire
- * variable. However, if this dereference is dereferenced by anything
- * else, the complete deferefernce chain is not a whole-variable
- * dereference. This method should only be called on the top most
- * ir_rvalue in a dereference chain.
- */
- return this->var;
- }
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- /**
- * Object being dereferenced.
- */
- ir_variable *var;
-};
-
-
-class ir_dereference_array : public ir_dereference {
-public:
- ir_dereference_array(ir_rvalue *value, ir_rvalue *array_index);
-
- ir_dereference_array(ir_variable *var, ir_rvalue *array_index);
-
- virtual ir_dereference_array *clone(void *mem_ctx,
- struct hash_table *) const;
-
- virtual ir_constant *constant_expression_value();
-
- virtual ir_dereference_array *as_dereference_array()
- {
- return this;
- }
-
- /**
- * Get the variable that is ultimately referenced by an r-value
- */
- virtual ir_variable *variable_referenced()
- {
- return this->array->variable_referenced();
- }
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- ir_rvalue *array;
- ir_rvalue *array_index;
-
-private:
- void set_array(ir_rvalue *value);
-};
-
-
-class ir_dereference_record : public ir_dereference {
-public:
- ir_dereference_record(ir_rvalue *value, const char *field);
-
- ir_dereference_record(ir_variable *var, const char *field);
-
- virtual ir_dereference_record *clone(void *mem_ctx,
- struct hash_table *) const;
-
- virtual ir_constant *constant_expression_value();
-
- /**
- * Get the variable that is ultimately referenced by an r-value
- */
- virtual ir_variable *variable_referenced()
- {
- return this->record->variable_referenced();
- }
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- ir_rvalue *record;
- const char *field;
-};
-
-
-/**
- * Data stored in an ir_constant
- */
-union ir_constant_data {
- unsigned u[16];
- int i[16];
- float f[16];
- bool b[16];
-};
-
-
-class ir_constant : public ir_rvalue {
-public:
- ir_constant(const struct glsl_type *type, const ir_constant_data *data);
- ir_constant(bool b);
- ir_constant(unsigned int u);
- ir_constant(int i);
- ir_constant(float f);
-
- /**
- * Construct an ir_constant from a list of ir_constant values
- */
- ir_constant(const struct glsl_type *type, exec_list *values);
-
- /**
- * Construct an ir_constant from a scalar component of another ir_constant
- *
- * The new \c ir_constant inherits the type of the component from the
- * source constant.
- *
- * \note
- * In the case of a matrix constant, the new constant is a scalar, \b not
- * a vector.
- */
- ir_constant(const ir_constant *c, unsigned i);
-
- /**
- * Return a new ir_constant of the specified type containing all zeros.
- */
- static ir_constant *zero(void *mem_ctx, const glsl_type *type);
-
- virtual ir_constant *clone(void *mem_ctx, struct hash_table *) const;
-
- virtual ir_constant *constant_expression_value();
-
- virtual ir_constant *as_constant()
- {
- return this;
- }
-
- virtual void accept(ir_visitor *v)
- {
- v->visit(this);
- }
-
- virtual ir_visitor_status accept(ir_hierarchical_visitor *);
-
- /**
- * Get a particular component of a constant as a specific type
- *
- * This is useful, for example, to get a value from an integer constant
- * as a float or bool. This appears frequently when constructors are
- * called with all constant parameters.
- */
- /*@{*/
- bool get_bool_component(unsigned i) const;
- float get_float_component(unsigned i) const;
- int get_int_component(unsigned i) const;
- unsigned get_uint_component(unsigned i) const;
- /*@}*/
-
- ir_constant *get_array_element(unsigned i) const;
-
- ir_constant *get_record_field(const char *name);
-
- /**
- * Determine whether a constant has the same value as another constant
- *
- * \sa ir_constant::is_zero, ir_constant::is_one,
- * ir_constant::is_negative_one
- */
- bool has_value(const ir_constant *) const;
-
- virtual bool is_zero() const;
- virtual bool is_one() const;
- virtual bool is_negative_one() const;
-
- /**
- * Value of the constant.
- *
- * The field used to back the values supplied by the constant is determined
- * by the type associated with the \c ir_instruction. Constants may be
- * scalars, vectors, or matrices.
- */
- union ir_constant_data value;
-
- /* Array elements */
- ir_constant **array_elements;
-
- /* Structure fields */
- exec_list components;
-
-private:
- /**
- * Parameterless constructor only used by the clone method
- */
- ir_constant(void);
-};
-
-/*@}*/
-
-/**
- * Apply a visitor to each IR node in a list
- */
-void
-visit_exec_list(exec_list *list, ir_visitor *visitor);
-
-/**
- * Validate invariants on each IR node in a list
- */
-void validate_ir_tree(exec_list *instructions);
-
-/**
- * Make a clone of each IR instruction in a list
- *
- * \param in List of IR instructions that are to be cloned
- * \param out List to hold the cloned instructions
- */
-void
-clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in);
-
-extern void
-_mesa_glsl_initialize_variables(exec_list *instructions,
- struct _mesa_glsl_parse_state *state);
-
-extern void
-_mesa_glsl_initialize_functions(_mesa_glsl_parse_state *state);
-
-extern void
-_mesa_glsl_release_functions(void);
-
-extern void
-reparent_ir(exec_list *list, void *mem_ctx);
-
-struct glsl_symbol_table;
-
-extern void
-import_prototypes(const exec_list *source, exec_list *dest,
- struct glsl_symbol_table *symbols, void *mem_ctx);
-
-extern bool
-ir_has_call(ir_instruction *ir);
-
-extern void
-do_set_program_inouts(exec_list *instructions, struct gl_program *prog);
-
-#endif /* IR_H */
+/* -*- c++ -*- */
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+#ifndef IR_H
+#define IR_H
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "ralloc.h"
+#include "glsl_types.h"
+#include "list.h"
+#include "ir_visitor.h"
+#include "ir_hierarchical_visitor.h"
+
+/**
+ * \defgroup IR Intermediate representation nodes
+ *
+ * @{
+ */
+
+/**
+ * Class tags
+ *
+ * Each concrete class derived from \c ir_instruction has a value in this
+ * enumerant. The value for the type is stored in \c ir_instruction::ir_type
+ * by the constructor. While using type tags is not very C++, it is extremely
+ * convenient. For example, during debugging you can simply inspect
+ * \c ir_instruction::ir_type to find out the actual type of the object.
+ *
+ * In addition, it is possible to use a switch-statement based on \c
+ * \c ir_instruction::ir_type to select different behavior for different object
+ * types. For functions that have only slight differences for several object
+ * types, this allows writing very straightforward, readable code.
+ */
+enum ir_node_type {
+ /**
+ * Zero is unused so that the IR validator can detect cases where
+ * \c ir_instruction::ir_type has not been initialized.
+ */
+ ir_type_unset,
+ ir_type_variable,
+ ir_type_assignment,
+ ir_type_call,
+ ir_type_constant,
+ ir_type_dereference_array,
+ ir_type_dereference_record,
+ ir_type_dereference_variable,
+ ir_type_discard,
+ ir_type_expression,
+ ir_type_function,
+ ir_type_function_signature,
+ ir_type_if,
+ ir_type_loop,
+ ir_type_loop_jump,
+ ir_type_return,
+ ir_type_swizzle,
+ ir_type_texture,
+ ir_type_max /**< maximum ir_type enum number, for validation */
+};
+
+/**
+ * Base class of all IR instructions
+ */
+class ir_instruction : public exec_node {
+public:
+ enum ir_node_type ir_type;
+ const struct glsl_type *type;
+
+ /** ir_print_visitor helper for debugging. */
+ void print(void) const;
+
+ virtual void accept(ir_visitor *) = 0;
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0;
+ virtual ir_instruction *clone(void *mem_ctx,
+ struct hash_table *ht) const = 0;
+
+ /**
+ * \name IR instruction downcast functions
+ *
+ * These functions either cast the object to a derived class or return
+ * \c NULL if the object's type does not match the specified derived class.
+ * Additional downcast functions will be added as needed.
+ */
+ /*@{*/
+ virtual class ir_variable * as_variable() { return NULL; }
+ virtual class ir_function * as_function() { return NULL; }
+ virtual class ir_dereference * as_dereference() { return NULL; }
+ virtual class ir_dereference_array * as_dereference_array() { return NULL; }
+ virtual class ir_dereference_variable *as_dereference_variable() { return NULL; }
+ virtual class ir_expression * as_expression() { return NULL; }
+ virtual class ir_rvalue * as_rvalue() { return NULL; }
+ virtual class ir_loop * as_loop() { return NULL; }
+ virtual class ir_assignment * as_assignment() { return NULL; }
+ virtual class ir_call * as_call() { return NULL; }
+ virtual class ir_return * as_return() { return NULL; }
+ virtual class ir_if * as_if() { return NULL; }
+ virtual class ir_swizzle * as_swizzle() { return NULL; }
+ virtual class ir_constant * as_constant() { return NULL; }
+ virtual class ir_discard * as_discard() { return NULL; }
+ /*@}*/
+
+protected:
+ ir_instruction()
+ {
+ ir_type = ir_type_unset;
+ type = NULL;
+ }
+};
+
+
+class ir_rvalue : public ir_instruction {
+public:
+ virtual ir_rvalue *clone(void *mem_ctx, struct hash_table *) const = 0;
+
+ virtual ir_constant *constant_expression_value() = 0;
+
+ virtual ir_rvalue * as_rvalue()
+ {
+ return this;
+ }
+
+ ir_rvalue *as_rvalue_to_saturate();
+
+ virtual bool is_lvalue()
+ {
+ return false;
+ }
+
+ /**
+ * Get the variable that is ultimately referenced by an r-value
+ */
+ virtual ir_variable *variable_referenced()
+ {
+ return NULL;
+ }
+
+
+ /**
+ * If an r-value is a reference to a whole variable, get that variable
+ *
+ * \return
+ * Pointer to a variable that is completely dereferenced by the r-value. If
+ * the r-value is not a dereference or the dereference does not access the
+ * entire variable (i.e., it's just one array element, struct field), \c NULL
+ * is returned.
+ */
+ virtual ir_variable *whole_variable_referenced()
+ {
+ return NULL;
+ }
+
+ /**
+ * Determine if an r-value has the value zero
+ *
+ * The base implementation of this function always returns \c false. The
+ * \c ir_constant class over-rides this function to return \c true \b only
+ * for vector and scalar types that have all elements set to the value
+ * zero (or \c false for booleans).
+ *
+ * \sa ir_constant::has_value, ir_rvalue::is_one, ir_rvalue::is_negative_one
+ */
+ virtual bool is_zero() const;
+
+ /**
+ * Determine if an r-value has the value one
+ *
+ * The base implementation of this function always returns \c false. The
+ * \c ir_constant class over-rides this function to return \c true \b only
+ * for vector and scalar types that have all elements set to the value
+ * one (or \c true for booleans).
+ *
+ * \sa ir_constant::has_value, ir_rvalue::is_zero, ir_rvalue::is_negative_one
+ */
+ virtual bool is_one() const;
+
+ /**
+ * Determine if an r-value has the value negative one
+ *
+ * The base implementation of this function always returns \c false. The
+ * \c ir_constant class over-rides this function to return \c true \b only
+ * for vector and scalar types that have all elements set to the value
+ * negative one. For boolean times, the result is always \c false.
+ *
+ * \sa ir_constant::has_value, ir_rvalue::is_zero, ir_rvalue::is_one
+ */
+ virtual bool is_negative_one() const;
+
+protected:
+ ir_rvalue();
+};
+
+
+/**
+ * Variable storage classes
+ */
+enum ir_variable_mode {
+ ir_var_auto = 0, /**< Function local variables and globals. */
+ ir_var_uniform, /**< Variable declared as a uniform. */
+ ir_var_in,
+ ir_var_out,
+ ir_var_inout,
+ ir_var_const_in, /**< "in" param that must be a constant expression */
+ ir_var_system_value, /**< Ex: front-face, instance-id, etc. */
+ ir_var_temporary /**< Temporary variable generated during compilation. */
+};
+
+enum ir_variable_interpolation {
+ ir_var_smooth = 0,
+ ir_var_flat,
+ ir_var_noperspective
+};
+
+/**
+ * \brief Layout qualifiers for gl_FragDepth.
+ *
+ * The AMD_conservative_depth extension allows gl_FragDepth to be redeclared
+ * with a layout qualifier.
+ */
+enum ir_depth_layout {
+ ir_depth_layout_none, /**< No depth layout is specified. */
+ ir_depth_layout_any,
+ ir_depth_layout_greater,
+ ir_depth_layout_less,
+ ir_depth_layout_unchanged
+};
+
+/**
+ * \brief Convert depth layout qualifier to string.
+ */
+const char*
+depth_layout_string(ir_depth_layout layout);
+
+class ir_variable : public ir_instruction {
+public:
+ ir_variable(const struct glsl_type *, const char *, ir_variable_mode);
+
+ virtual ir_variable *clone(void *mem_ctx, struct hash_table *ht) const;
+
+ virtual ir_variable *as_variable()
+ {
+ return this;
+ }
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+
+ /**
+ * Get the string value for the interpolation qualifier
+ *
+ * \return The string that would be used in a shader to specify \c
+ * mode will be returned.
+ *
+ * This function should only be used on a shader input or output variable.
+ */
+ const char *interpolation_string() const;
+
+ /**
+ * Calculate the number of slots required to hold this variable
+ *
+ * This is used to determine how many uniform or varying locations a variable
+ * occupies. The count is in units of floating point components.
+ */
+ unsigned component_slots() const;
+
+ /**
+ * Delcared name of the variable
+ */
+ const char *name;
+
+ /**
+ * Highest element accessed with a constant expression array index
+ *
+ * Not used for non-array variables.
+ */
+ unsigned max_array_access;
+
+ /**
+ * Is the variable read-only?
+ *
+ * This is set for variables declared as \c const, shader inputs,
+ * and uniforms.
+ */
+ unsigned read_only:1;
+ unsigned centroid:1;
+ unsigned invariant:1;
+
+ /**
+ * Has this variable been used for reading or writing?
+ *
+ * Several GLSL semantic checks require knowledge of whether or not a
+ * variable has been used. For example, it is an error to redeclare a
+ * variable as invariant after it has been used.
+ */
+ unsigned used:1;
+
+ /**
+ * Storage class of the variable.
+ *
+ * \sa ir_variable_mode
+ */
+ unsigned mode:3;
+
+ /**
+ * Interpolation mode for shader inputs / outputs
+ *
+ * \sa ir_variable_interpolation
+ */
+ unsigned interpolation:2;
+
+ /**
+ * Flag that the whole array is assignable
+ *
+ * In GLSL 1.20 and later whole arrays are assignable (and comparable for
+ * equality). This flag enables this behavior.
+ */
+ unsigned array_lvalue:1;
+
+ /**
+ * \name ARB_fragment_coord_conventions
+ * @{
+ */
+ unsigned origin_upper_left:1;
+ unsigned pixel_center_integer:1;
+ /*@}*/
+
+ /**
+ * \brief Layout qualifier for gl_FragDepth.
+ *
+ * This is not equal to \c ir_depth_layout_none if and only if this
+ * variable is \c gl_FragDepth and a layout qualifier is specified.
+ */
+ ir_depth_layout depth_layout;
+
+ /**
+ * Was the location explicitly set in the shader?
+ *
+ * If the location is explicitly set in the shader, it \b cannot be changed
+ * by the linker or by the API (e.g., calls to \c glBindAttribLocation have
+ * no effect).
+ */
+ unsigned explicit_location:1;
+
+ /**
+ * Storage location of the base of this variable
+ *
+ * The precise meaning of this field depends on the nature of the variable.
+ *
+ * - Vertex shader input: one of the values from \c gl_vert_attrib.
+ * - Vertex shader output: one of the values from \c gl_vert_result.
+ * - Fragment shader input: one of the values from \c gl_frag_attrib.
+ * - Fragment shader output: one of the values from \c gl_frag_result.
+ * - Uniforms: Per-stage uniform slot number.
+ * - Other: This field is not currently used.
+ *
+ * If the variable is a uniform, shader input, or shader output, and the
+ * slot has not been assigned, the value will be -1.
+ */
+ int location;
+
+ /**
+ * Emit a warning if this variable is accessed.
+ */
+ const char *warn_extension;
+
+ /**
+ * Value assigned in the initializer of a variable declared "const"
+ */
+ ir_constant *constant_value;
+};
+
+
+/*@{*/
+/**
+ * The representation of a function instance; may be the full definition or
+ * simply a prototype.
+ */
+class ir_function_signature : public ir_instruction {
+ /* An ir_function_signature will be part of the list of signatures in
+ * an ir_function.
+ */
+public:
+ ir_function_signature(const glsl_type *return_type);
+
+ virtual ir_function_signature *clone(void *mem_ctx,
+ struct hash_table *ht) const;
+ ir_function_signature *clone_prototype(void *mem_ctx,
+ struct hash_table *ht) const;
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ /**
+ * Get the name of the function for which this is a signature
+ */
+ const char *function_name() const;
+
+ /**
+ * Get a handle to the function for which this is a signature
+ *
+ * There is no setter function, this function returns a \c const pointer,
+ * and \c ir_function_signature::_function is private for a reason. The
+ * only way to make a connection between a function and function signature
+ * is via \c ir_function::add_signature. This helps ensure that certain
+ * invariants (i.e., a function signature is in the list of signatures for
+ * its \c _function) are met.
+ *
+ * \sa ir_function::add_signature
+ */
+ inline const class ir_function *function() const
+ {
+ return this->_function;
+ }
+
+ /**
+ * Check whether the qualifiers match between this signature's parameters
+ * and the supplied parameter list. If not, returns the name of the first
+ * parameter with mismatched qualifiers (for use in error messages).
+ */
+ const char *qualifiers_match(exec_list *params);
+
+ /**
+ * Replace the current parameter list with the given one. This is useful
+ * if the current information came from a prototype, and either has invalid
+ * or missing parameter names.
+ */
+ void replace_parameters(exec_list *new_params);
+
+ /**
+ * Function return type.
+ *
+ * \note This discards the optional precision qualifier.
+ */
+ const struct glsl_type *return_type;
+
+ /**
+ * List of ir_variable of function parameters.
+ *
+ * This represents the storage. The paramaters passed in a particular
+ * call will be in ir_call::actual_paramaters.
+ */
+ struct exec_list parameters;
+
+ /** Whether or not this function has a body (which may be empty). */
+ unsigned is_defined:1;
+
+ /** Whether or not this function signature is a built-in. */
+ unsigned is_builtin:1;
+
+ /** Body of instructions in the function. */
+ struct exec_list body;
+
+private:
+ /** Function of which this signature is one overload. */
+ class ir_function *_function;
+
+ friend class ir_function;
+};
+
+
+/**
+ * Header for tracking multiple overloaded functions with the same name.
+ * Contains a list of ir_function_signatures representing each of the
+ * actual functions.
+ */
+class ir_function : public ir_instruction {
+public:
+ ir_function(const char *name);
+
+ virtual ir_function *clone(void *mem_ctx, struct hash_table *ht) const;
+
+ virtual ir_function *as_function()
+ {
+ return this;
+ }
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ void add_signature(ir_function_signature *sig)
+ {
+ sig->_function = this;
+ this->signatures.push_tail(sig);
+ }
+
+ /**
+ * Get an iterator for the set of function signatures
+ */
+ exec_list_iterator iterator()
+ {
+ return signatures.iterator();
+ }
+
+ /**
+ * Find a signature that matches a set of actual parameters, taking implicit
+ * conversions into account.
+ */
+ ir_function_signature *matching_signature(const exec_list *actual_param);
+
+ /**
+ * Find a signature that exactly matches a set of actual parameters without
+ * any implicit type conversions.
+ */
+ ir_function_signature *exact_matching_signature(const exec_list *actual_ps);
+
+ /**
+ * Name of the function.
+ */
+ const char *name;
+
+ /** Whether or not this function has a signature that isn't a built-in. */
+ bool has_user_signature();
+
+ /**
+ * List of ir_function_signature for each overloaded function with this name.
+ */
+ struct exec_list signatures;
+};
+
+inline const char *ir_function_signature::function_name() const
+{
+ return this->_function->name;
+}
+/*@}*/
+
+
+/**
+ * IR instruction representing high-level if-statements
+ */
+class ir_if : public ir_instruction {
+public:
+ ir_if(ir_rvalue *condition)
+ : condition(condition)
+ {
+ ir_type = ir_type_if;
+ }
+
+ virtual ir_if *clone(void *mem_ctx, struct hash_table *ht) const;
+
+ virtual ir_if *as_if()
+ {
+ return this;
+ }
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ ir_rvalue *condition;
+ /** List of ir_instruction for the body of the then branch */
+ exec_list then_instructions;
+ /** List of ir_instruction for the body of the else branch */
+ exec_list else_instructions;
+};
+
+
+/**
+ * IR instruction representing a high-level loop structure.
+ */
+class ir_loop : public ir_instruction {
+public:
+ ir_loop();
+
+ virtual ir_loop *clone(void *mem_ctx, struct hash_table *ht) const;
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ virtual ir_loop *as_loop()
+ {
+ return this;
+ }
+
+ /**
+ * Get an iterator for the instructions of the loop body
+ */
+ exec_list_iterator iterator()
+ {
+ return body_instructions.iterator();
+ }
+
+ /** List of ir_instruction that make up the body of the loop. */
+ exec_list body_instructions;
+
+ /**
+ * \name Loop counter and controls
+ *
+ * Represents a loop like a FORTRAN \c do-loop.
+ *
+ * \note
+ * If \c from and \c to are the same value, the loop will execute once.
+ */
+ /*@{*/
+ ir_rvalue *from; /** Value of the loop counter on the first
+ * iteration of the loop.
+ */
+ ir_rvalue *to; /** Value of the loop counter on the last
+ * iteration of the loop.
+ */
+ ir_rvalue *increment;
+ ir_variable *counter;
+
+ /**
+ * Comparison operation in the loop terminator.
+ *
+ * If any of the loop control fields are non-\c NULL, this field must be
+ * one of \c ir_binop_less, \c ir_binop_greater, \c ir_binop_lequal,
+ * \c ir_binop_gequal, \c ir_binop_equal, or \c ir_binop_nequal.
+ */
+ int cmp;
+ /*@}*/
+};
+
+
+class ir_assignment : public ir_instruction {
+public:
+ ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition);
+
+ /**
+ * Construct an assignment with an explicit write mask
+ *
+ * \note
+ * Since a write mask is supplied, the LHS must already be a bare
+ * \c ir_dereference. The cannot be any swizzles in the LHS.
+ */
+ ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, ir_rvalue *condition,
+ unsigned write_mask);
+
+ virtual ir_assignment *clone(void *mem_ctx, struct hash_table *ht) const;
+
+ virtual ir_constant *constant_expression_value();
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ virtual ir_assignment * as_assignment()
+ {
+ return this;
+ }
+
+ /**
+ * Get a whole variable written by an assignment
+ *
+ * If the LHS of the assignment writes a whole variable, the variable is
+ * returned. Otherwise \c NULL is returned. Examples of whole-variable
+ * assignment are:
+ *
+ * - Assigning to a scalar
+ * - Assigning to all components of a vector
+ * - Whole array (or matrix) assignment
+ * - Whole structure assignment
+ */
+ ir_variable *whole_variable_written();
+
+ /**
+ * Set the LHS of an assignment
+ */
+ void set_lhs(ir_rvalue *lhs);
+
+ /**
+ * Left-hand side of the assignment.
+ *
+ * This should be treated as read only. If you need to set the LHS of an
+ * assignment, use \c ir_assignment::set_lhs.
+ */
+ ir_dereference *lhs;
+
+ /**
+ * Value being assigned
+ */
+ ir_rvalue *rhs;
+
+ /**
+ * Optional condition for the assignment.
+ */
+ ir_rvalue *condition;
+
+
+ /**
+ * Component mask written
+ *
+ * For non-vector types in the LHS, this field will be zero. For vector
+ * types, a bit will be set for each component that is written. Note that
+ * for \c vec2 and \c vec3 types only the lower bits will ever be set.
+ *
+ * A partially-set write mask means that each enabled channel gets
+ * the value from a consecutive channel of the rhs. For example,
+ * to write just .xyw of gl_FrontColor with color:
+ *
+ * (assign (constant bool (1)) (xyw)
+ * (var_ref gl_FragColor)
+ * (swiz xyw (var_ref color)))
+ */
+ unsigned write_mask:4;
+};
+
+/* Update ir_expression::num_operands() and operator_strs when
+ * updating this list.
+ */
+enum ir_expression_operation {
+ ir_unop_bit_not,
+ ir_unop_logic_not,
+ ir_unop_neg,
+ ir_unop_abs,
+ ir_unop_sign,
+ ir_unop_rcp,
+ ir_unop_rsq,
+ ir_unop_sqrt,
+ ir_unop_exp, /**< Log base e on gentype */
+ ir_unop_log, /**< Natural log on gentype */
+ ir_unop_exp2,
+ ir_unop_log2,
+ ir_unop_f2i, /**< Float-to-integer conversion. */
+ ir_unop_i2f, /**< Integer-to-float conversion. */
+ ir_unop_f2b, /**< Float-to-boolean conversion */
+ ir_unop_b2f, /**< Boolean-to-float conversion */
+ ir_unop_i2b, /**< int-to-boolean conversion */
+ ir_unop_b2i, /**< Boolean-to-int conversion */
+ ir_unop_u2f, /**< Unsigned-to-float conversion. */
+ ir_unop_any,
+
+ /**
+ * \name Unary floating-point rounding operations.
+ */
+ /*@{*/
+ ir_unop_trunc,
+ ir_unop_ceil,
+ ir_unop_floor,
+ ir_unop_fract,
+ ir_unop_round_even,
+ /*@}*/
+
+ /**
+ * \name Trigonometric operations.
+ */
+ /*@{*/
+ ir_unop_sin,
+ ir_unop_cos,
+ ir_unop_sin_reduced, /**< Reduced range sin. [-pi, pi] */
+ ir_unop_cos_reduced, /**< Reduced range cos. [-pi, pi] */
+ /*@}*/
+
+ /**
+ * \name Partial derivatives.
+ */
+ /*@{*/
+ ir_unop_dFdx,
+ ir_unop_dFdy,
+ /*@}*/
+
+ ir_unop_noise,
+
+ /**
+ * A sentinel marking the last of the unary operations.
+ */
+ ir_last_unop = ir_unop_noise,
+
+ ir_binop_add,
+ ir_binop_sub,
+ ir_binop_mul,
+ ir_binop_div,
+
+ /**
+ * Takes one of two combinations of arguments:
+ *
+ * - mod(vecN, vecN)
+ * - mod(vecN, float)
+ *
+ * Does not take integer types.
+ */
+ ir_binop_mod,
+
+ /**
+ * \name Binary comparison operators which return a boolean vector.
+ * The type of both operands must be equal.
+ */
+ /*@{*/
+ ir_binop_less,
+ ir_binop_greater,
+ ir_binop_lequal,
+ ir_binop_gequal,
+ ir_binop_equal,
+ ir_binop_nequal,
+ /**
+ * Returns single boolean for whether all components of operands[0]
+ * equal the components of operands[1].
+ */
+ ir_binop_all_equal,
+ /**
+ * Returns single boolean for whether any component of operands[0]
+ * is not equal to the corresponding component of operands[1].
+ */
+ ir_binop_any_nequal,
+ /*@}*/
+
+ /**
+ * \name Bit-wise binary operations.
+ */
+ /*@{*/
+ ir_binop_lshift,
+ ir_binop_rshift,
+ ir_binop_bit_and,
+ ir_binop_bit_xor,
+ ir_binop_bit_or,
+ /*@}*/
+
+ ir_binop_logic_and,
+ ir_binop_logic_xor,
+ ir_binop_logic_or,
+
+ ir_binop_dot,
+ ir_binop_min,
+ ir_binop_max,
+
+ ir_binop_pow,
+
+ /**
+ * A sentinel marking the last of the binary operations.
+ */
+ ir_last_binop = ir_binop_pow,
+
+ ir_quadop_vector,
+
+ /**
+ * A sentinel marking the last of all operations.
+ */
+ ir_last_opcode = ir_last_binop
+};
+
+class ir_expression : public ir_rvalue {
+public:
+ /**
+ * Constructor for unary operation expressions
+ */
+ ir_expression(int op, const struct glsl_type *type, ir_rvalue *);
+ ir_expression(int op, ir_rvalue *);
+
+ /**
+ * Constructor for binary operation expressions
+ */
+ ir_expression(int op, const struct glsl_type *type,
+ ir_rvalue *, ir_rvalue *);
+ ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1);
+
+ /**
+ * Constructor for quad operator expressions
+ */
+ ir_expression(int op, const struct glsl_type *type,
+ ir_rvalue *, ir_rvalue *, ir_rvalue *, ir_rvalue *);
+
+ virtual ir_expression *as_expression()
+ {
+ return this;
+ }
+
+ virtual ir_expression *clone(void *mem_ctx, struct hash_table *ht) const;
+
+ /**
+ * Attempt to constant-fold the expression
+ *
+ * If the expression cannot be constant folded, this method will return
+ * \c NULL.
+ */
+ virtual ir_constant *constant_expression_value();
+
+ /**
+ * Determine the number of operands used by an expression
+ */
+ static unsigned int get_num_operands(ir_expression_operation);
+
+ /**
+ * Determine the number of operands used by an expression
+ */
+ unsigned int get_num_operands() const
+ {
+ return (this->operation == ir_quadop_vector)
+ ? this->type->vector_elements : get_num_operands(operation);
+ }
+
+ /**
+ * Return a string representing this expression's operator.
+ */
+ const char *operator_string();
+
+ /**
+ * Return a string representing this expression's operator.
+ */
+ static const char *operator_string(ir_expression_operation);
+
+
+ /**
+ * Do a reverse-lookup to translate the given string into an operator.
+ */
+ static ir_expression_operation get_operator(const char *);
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ ir_expression_operation operation;
+ ir_rvalue *operands[4];
+};
+
+
+/**
+ * IR instruction representing a function call
+ */
+class ir_call : public ir_rvalue {
+public:
+ ir_call(ir_function_signature *callee, exec_list *actual_parameters)
+ : callee(callee)
+ {
+ ir_type = ir_type_call;
+ assert(callee->return_type != NULL);
+ type = callee->return_type;
+ actual_parameters->move_nodes_to(& this->actual_parameters);
+ }
+
+ virtual ir_call *clone(void *mem_ctx, struct hash_table *ht) const;
+
+ virtual ir_constant *constant_expression_value();
+
+ virtual ir_call *as_call()
+ {
+ return this;
+ }
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ /**
+ * Get a generic ir_call object when an error occurs
+ *
+ * Any allocation will be performed with 'ctx' as ralloc owner.
+ */
+ static ir_call *get_error_instruction(void *ctx);
+
+ /**
+ * Get an iterator for the set of acutal parameters
+ */
+ exec_list_iterator iterator()
+ {
+ return actual_parameters.iterator();
+ }
+
+ /**
+ * Get the name of the function being called.
+ */
+ const char *callee_name() const
+ {
+ return callee->function_name();
+ }
+
+ /**
+ * Get the function signature bound to this function call
+ */
+ ir_function_signature *get_callee()
+ {
+ return callee;
+ }
+
+ /**
+ * Set the function call target
+ */
+ void set_callee(ir_function_signature *sig);
+
+ /**
+ * Generates an inline version of the function before @ir,
+ * returning the return value of the function.
+ */
+ ir_rvalue *generate_inline(ir_instruction *ir);
+
+ /* List of ir_rvalue of paramaters passed in this call. */
+ exec_list actual_parameters;
+
+private:
+ ir_call()
+ : callee(NULL)
+ {
+ this->ir_type = ir_type_call;
+ }
+
+ ir_function_signature *callee;
+};
+
+
+/**
+ * \name Jump-like IR instructions.
+ *
+ * These include \c break, \c continue, \c return, and \c discard.
+ */
+/*@{*/
+class ir_jump : public ir_instruction {
+protected:
+ ir_jump()
+ {
+ ir_type = ir_type_unset;
+ }
+};
+
+class ir_return : public ir_jump {
+public:
+ ir_return()
+ : value(NULL)
+ {
+ this->ir_type = ir_type_return;
+ }
+
+ ir_return(ir_rvalue *value)
+ : value(value)
+ {
+ this->ir_type = ir_type_return;
+ }
+
+ virtual ir_return *clone(void *mem_ctx, struct hash_table *) const;
+
+ virtual ir_return *as_return()
+ {
+ return this;
+ }
+
+ ir_rvalue *get_value() const
+ {
+ return value;
+ }
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ ir_rvalue *value;
+};
+
+
+/**
+ * Jump instructions used inside loops
+ *
+ * These include \c break and \c continue. The \c break within a loop is
+ * different from the \c break within a switch-statement.
+ *
+ * \sa ir_switch_jump
+ */
+class ir_loop_jump : public ir_jump {
+public:
+ enum jump_mode {
+ jump_break,
+ jump_continue
+ };
+
+ ir_loop_jump(jump_mode mode)
+ {
+ this->ir_type = ir_type_loop_jump;
+ this->mode = mode;
+ this->loop = loop;
+ }
+
+ virtual ir_loop_jump *clone(void *mem_ctx, struct hash_table *) const;
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ bool is_break() const
+ {
+ return mode == jump_break;
+ }
+
+ bool is_continue() const
+ {
+ return mode == jump_continue;
+ }
+
+ /** Mode selector for the jump instruction. */
+ enum jump_mode mode;
+private:
+ /** Loop containing this break instruction. */
+ ir_loop *loop;
+};
+
+/**
+ * IR instruction representing discard statements.
+ */
+class ir_discard : public ir_jump {
+public:
+ ir_discard()
+ {
+ this->ir_type = ir_type_discard;
+ this->condition = NULL;
+ }
+
+ ir_discard(ir_rvalue *cond)
+ {
+ this->ir_type = ir_type_discard;
+ this->condition = cond;
+ }
+
+ virtual ir_discard *clone(void *mem_ctx, struct hash_table *ht) const;
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ virtual ir_discard *as_discard()
+ {
+ return this;
+ }
+
+ ir_rvalue *condition;
+};
+/*@}*/
+
+
+/**
+ * Texture sampling opcodes used in ir_texture
+ */
+enum ir_texture_opcode {
+ ir_tex, /**< Regular texture look-up */
+ ir_txb, /**< Texture look-up with LOD bias */
+ ir_txl, /**< Texture look-up with explicit LOD */
+ ir_txd, /**< Texture look-up with partial derivatvies */
+ ir_txf /**< Texel fetch with explicit LOD */
+};
+
+
+/**
+ * IR instruction to sample a texture
+ *
+ * The specific form of the IR instruction depends on the \c mode value
+ * selected from \c ir_texture_opcodes. In the printed IR, these will
+ * appear as:
+ *
+ * Texel offset (0 or an expression)
+ * | Projection divisor
+ * | | Shadow comparitor
+ * | | |
+ * v v v
+ * (tex <sampler> <coordinate> 0 1 ( ))
+ * (txb <sampler> <coordinate> 0 1 ( ) <bias>)
+ * (txl <sampler> <coordinate> 0 1 ( ) <lod>)
+ * (txd <sampler> <coordinate> 0 1 ( ) (dPdx dPdy))
+ * (txf <sampler> <coordinate> 0 <lod>)
+ */
+class ir_texture : public ir_rvalue {
+public:
+ ir_texture(enum ir_texture_opcode op)
+ : op(op), projector(NULL), shadow_comparitor(NULL), offset(NULL)
+ {
+ this->ir_type = ir_type_texture;
+ }
+
+ virtual ir_texture *clone(void *mem_ctx, struct hash_table *) const;
+
+ virtual ir_constant *constant_expression_value();
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ /**
+ * Return a string representing the ir_texture_opcode.
+ */
+ const char *opcode_string();
+
+ /** Set the sampler and infer the type. */
+ void set_sampler(ir_dereference *sampler);
+
+ /**
+ * Do a reverse-lookup to translate a string into an ir_texture_opcode.
+ */
+ static ir_texture_opcode get_opcode(const char *);
+
+ enum ir_texture_opcode op;
+
+ /** Sampler to use for the texture access. */
+ ir_dereference *sampler;
+
+ /** Texture coordinate to sample */
+ ir_rvalue *coordinate;
+
+ /**
+ * Value used for projective divide.
+ *
+ * If there is no projective divide (the common case), this will be
+ * \c NULL. Optimization passes should check for this to point to a constant
+ * of 1.0 and replace that with \c NULL.
+ */
+ ir_rvalue *projector;
+
+ /**
+ * Coordinate used for comparison on shadow look-ups.
+ *
+ * If there is no shadow comparison, this will be \c NULL. For the
+ * \c ir_txf opcode, this *must* be \c NULL.
+ */
+ ir_rvalue *shadow_comparitor;
+
+ /** Texel offset. */
+ ir_rvalue *offset;
+
+ union {
+ ir_rvalue *lod; /**< Floating point LOD */
+ ir_rvalue *bias; /**< Floating point LOD bias */
+ struct {
+ ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */
+ ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */
+ } grad;
+ } lod_info;
+};
+
+
+struct ir_swizzle_mask {
+ unsigned x:2;
+ unsigned y:2;
+ unsigned z:2;
+ unsigned w:2;
+
+ /**
+ * Number of components in the swizzle.
+ */
+ unsigned num_components:3;
+
+ /**
+ * Does the swizzle contain duplicate components?
+ *
+ * L-value swizzles cannot contain duplicate components.
+ */
+ unsigned has_duplicates:1;
+};
+
+
+class ir_swizzle : public ir_rvalue {
+public:
+ ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w,
+ unsigned count);
+
+ ir_swizzle(ir_rvalue *val, const unsigned *components, unsigned count);
+
+ ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask);
+
+ virtual ir_swizzle *clone(void *mem_ctx, struct hash_table *) const;
+
+ virtual ir_constant *constant_expression_value();
+
+ virtual ir_swizzle *as_swizzle()
+ {
+ return this;
+ }
+
+ /**
+ * Construct an ir_swizzle from the textual representation. Can fail.
+ */
+ static ir_swizzle *create(ir_rvalue *, const char *, unsigned vector_length);
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ bool is_lvalue()
+ {
+ return val->is_lvalue() && !mask.has_duplicates;
+ }
+
+ /**
+ * Get the variable that is ultimately referenced by an r-value
+ */
+ virtual ir_variable *variable_referenced();
+
+ ir_rvalue *val;
+ ir_swizzle_mask mask;
+
+private:
+ /**
+ * Initialize the mask component of a swizzle
+ *
+ * This is used by the \c ir_swizzle constructors.
+ */
+ void init_mask(const unsigned *components, unsigned count);
+};
+
+
+class ir_dereference : public ir_rvalue {
+public:
+ virtual ir_dereference *clone(void *mem_ctx, struct hash_table *) const = 0;
+
+ virtual ir_dereference *as_dereference()
+ {
+ return this;
+ }
+
+ bool is_lvalue();
+
+ /**
+ * Get the variable that is ultimately referenced by an r-value
+ */
+ virtual ir_variable *variable_referenced() = 0;
+};
+
+
+class ir_dereference_variable : public ir_dereference {
+public:
+ ir_dereference_variable(ir_variable *var);
+
+ virtual ir_dereference_variable *clone(void *mem_ctx,
+ struct hash_table *) const;
+
+ virtual ir_constant *constant_expression_value();
+
+ virtual ir_dereference_variable *as_dereference_variable()
+ {
+ return this;
+ }
+
+ /**
+ * Get the variable that is ultimately referenced by an r-value
+ */
+ virtual ir_variable *variable_referenced()
+ {
+ return this->var;
+ }
+
+ virtual ir_variable *whole_variable_referenced()
+ {
+ /* ir_dereference_variable objects always dereference the entire
+ * variable. However, if this dereference is dereferenced by anything
+ * else, the complete deferefernce chain is not a whole-variable
+ * dereference. This method should only be called on the top most
+ * ir_rvalue in a dereference chain.
+ */
+ return this->var;
+ }
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ /**
+ * Object being dereferenced.
+ */
+ ir_variable *var;
+};
+
+
+class ir_dereference_array : public ir_dereference {
+public:
+ ir_dereference_array(ir_rvalue *value, ir_rvalue *array_index);
+
+ ir_dereference_array(ir_variable *var, ir_rvalue *array_index);
+
+ virtual ir_dereference_array *clone(void *mem_ctx,
+ struct hash_table *) const;
+
+ virtual ir_constant *constant_expression_value();
+
+ virtual ir_dereference_array *as_dereference_array()
+ {
+ return this;
+ }
+
+ /**
+ * Get the variable that is ultimately referenced by an r-value
+ */
+ virtual ir_variable *variable_referenced()
+ {
+ return this->array->variable_referenced();
+ }
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ ir_rvalue *array;
+ ir_rvalue *array_index;
+
+private:
+ void set_array(ir_rvalue *value);
+};
+
+
+class ir_dereference_record : public ir_dereference {
+public:
+ ir_dereference_record(ir_rvalue *value, const char *field);
+
+ ir_dereference_record(ir_variable *var, const char *field);
+
+ virtual ir_dereference_record *clone(void *mem_ctx,
+ struct hash_table *) const;
+
+ virtual ir_constant *constant_expression_value();
+
+ /**
+ * Get the variable that is ultimately referenced by an r-value
+ */
+ virtual ir_variable *variable_referenced()
+ {
+ return this->record->variable_referenced();
+ }
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ ir_rvalue *record;
+ const char *field;
+};
+
+
+/**
+ * Data stored in an ir_constant
+ */
+union ir_constant_data {
+ unsigned u[16];
+ int i[16];
+ float f[16];
+ bool b[16];
+};
+
+
+class ir_constant : public ir_rvalue {
+public:
+ ir_constant(const struct glsl_type *type, const ir_constant_data *data);
+ ir_constant(bool b);
+ ir_constant(unsigned int u);
+ ir_constant(int i);
+ ir_constant(float f);
+
+ /**
+ * Construct an ir_constant from a list of ir_constant values
+ */
+ ir_constant(const struct glsl_type *type, exec_list *values);
+
+ /**
+ * Construct an ir_constant from a scalar component of another ir_constant
+ *
+ * The new \c ir_constant inherits the type of the component from the
+ * source constant.
+ *
+ * \note
+ * In the case of a matrix constant, the new constant is a scalar, \b not
+ * a vector.
+ */
+ ir_constant(const ir_constant *c, unsigned i);
+
+ /**
+ * Return a new ir_constant of the specified type containing all zeros.
+ */
+ static ir_constant *zero(void *mem_ctx, const glsl_type *type);
+
+ virtual ir_constant *clone(void *mem_ctx, struct hash_table *) const;
+
+ virtual ir_constant *constant_expression_value();
+
+ virtual ir_constant *as_constant()
+ {
+ return this;
+ }
+
+ virtual void accept(ir_visitor *v)
+ {
+ v->visit(this);
+ }
+
+ virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+ /**
+ * Get a particular component of a constant as a specific type
+ *
+ * This is useful, for example, to get a value from an integer constant
+ * as a float or bool. This appears frequently when constructors are
+ * called with all constant parameters.
+ */
+ /*@{*/
+ bool get_bool_component(unsigned i) const;
+ float get_float_component(unsigned i) const;
+ int get_int_component(unsigned i) const;
+ unsigned get_uint_component(unsigned i) const;
+ /*@}*/
+
+ ir_constant *get_array_element(unsigned i) const;
+
+ ir_constant *get_record_field(const char *name);
+
+ /**
+ * Determine whether a constant has the same value as another constant
+ *
+ * \sa ir_constant::is_zero, ir_constant::is_one,
+ * ir_constant::is_negative_one
+ */
+ bool has_value(const ir_constant *) const;
+
+ virtual bool is_zero() const;
+ virtual bool is_one() const;
+ virtual bool is_negative_one() const;
+
+ /**
+ * Value of the constant.
+ *
+ * The field used to back the values supplied by the constant is determined
+ * by the type associated with the \c ir_instruction. Constants may be
+ * scalars, vectors, or matrices.
+ */
+ union ir_constant_data value;
+
+ /* Array elements */
+ ir_constant **array_elements;
+
+ /* Structure fields */
+ exec_list components;
+
+private:
+ /**
+ * Parameterless constructor only used by the clone method
+ */
+ ir_constant(void);
+};
+
+/*@}*/
+
+/**
+ * Apply a visitor to each IR node in a list
+ */
+void
+visit_exec_list(exec_list *list, ir_visitor *visitor);
+
+/**
+ * Validate invariants on each IR node in a list
+ */
+void validate_ir_tree(exec_list *instructions);
+
+/**
+ * Make a clone of each IR instruction in a list
+ *
+ * \param in List of IR instructions that are to be cloned
+ * \param out List to hold the cloned instructions
+ */
+void
+clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in);
+
+extern void
+_mesa_glsl_initialize_variables(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state);
+
+extern void
+_mesa_glsl_initialize_functions(_mesa_glsl_parse_state *state);
+
+extern void
+_mesa_glsl_release_functions(void);
+
+extern void
+reparent_ir(exec_list *list, void *mem_ctx);
+
+struct glsl_symbol_table;
+
+extern void
+import_prototypes(const exec_list *source, exec_list *dest,
+ struct glsl_symbol_table *symbols, void *mem_ctx);
+
+extern bool
+ir_has_call(ir_instruction *ir);
+
+extern void
+do_set_program_inouts(exec_list *instructions, struct gl_program *prog);
+
+#endif /* IR_H */
diff --git a/mesalib/src/glsl/ir_constant_expression.cpp b/mesalib/src/glsl/ir_constant_expression.cpp
index 2a3084896..1d39e31fa 100644
--- a/mesalib/src/glsl/ir_constant_expression.cpp
+++ b/mesalib/src/glsl/ir_constant_expression.cpp
@@ -1,1372 +1,1372 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file ir_constant_expression.cpp
- * Evaluate and process constant valued expressions
- *
- * In GLSL, constant valued expressions are used in several places. These
- * must be processed and evaluated very early in the compilation process.
- *
- * * Sizes of arrays
- * * Initializers for uniforms
- * * Initializers for \c const variables
- */
-
-#include <math.h>
-#include "main/core.h" /* for MAX2, MIN2, CLAMP */
-#include "ir.h"
-#include "ir_visitor.h"
-#include "glsl_types.h"
-
-static float
-dot(ir_constant *op0, ir_constant *op1)
-{
- assert(op0->type->is_float() && op1->type->is_float());
-
- float result = 0;
- for (unsigned c = 0; c < op0->type->components(); c++)
- result += op0->value.f[c] * op1->value.f[c];
-
- return result;
-}
-
-ir_constant *
-ir_expression::constant_expression_value()
-{
- if (this->type->is_error())
- return NULL;
-
- ir_constant *op[Elements(this->operands)] = { NULL, };
- ir_constant_data data;
-
- memset(&data, 0, sizeof(data));
-
- for (unsigned operand = 0; operand < this->get_num_operands(); operand++) {
- op[operand] = this->operands[operand]->constant_expression_value();
- if (!op[operand])
- return NULL;
- }
-
- if (op[1] != NULL)
- assert(op[0]->type->base_type == op[1]->type->base_type);
-
- bool op0_scalar = op[0]->type->is_scalar();
- bool op1_scalar = op[1] != NULL && op[1]->type->is_scalar();
-
- /* When iterating over a vector or matrix's components, we want to increase
- * the loop counter. However, for scalars, we want to stay at 0.
- */
- unsigned c0_inc = op0_scalar ? 0 : 1;
- unsigned c1_inc = op1_scalar ? 0 : 1;
- unsigned components;
- if (op1_scalar || !op[1]) {
- components = op[0]->type->components();
- } else {
- components = op[1]->type->components();
- }
-
- void *ctx = ralloc_parent(this);
-
- /* Handle array operations here, rather than below. */
- if (op[0]->type->is_array()) {
- assert(op[1] != NULL && op[1]->type->is_array());
- switch (this->operation) {
- case ir_binop_all_equal:
- return new(ctx) ir_constant(op[0]->has_value(op[1]));
- case ir_binop_any_nequal:
- return new(ctx) ir_constant(!op[0]->has_value(op[1]));
- default:
- break;
- }
- return NULL;
- }
-
- switch (this->operation) {
- case ir_unop_bit_not:
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_INT:
- for (unsigned c = 0; c < components; c++)
- data.i[c] = ~ op[0]->value.i[c];
- break;
- case GLSL_TYPE_UINT:
- for (unsigned c = 0; c < components; c++)
- data.u[c] = ~ op[0]->value.u[c];
- break;
- default:
- assert(0);
- }
- break;
-
- case ir_unop_logic_not:
- assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.b[c] = !op[0]->value.b[c];
- break;
-
- case ir_unop_f2i:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.i[c] = (int) op[0]->value.f[c];
- }
- break;
- case ir_unop_i2f:
- assert(op[0]->type->base_type == GLSL_TYPE_INT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = (float) op[0]->value.i[c];
- }
- break;
- case ir_unop_u2f:
- assert(op[0]->type->base_type == GLSL_TYPE_UINT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = (float) op[0]->value.u[c];
- }
- break;
- case ir_unop_b2f:
- assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = op[0]->value.b[c] ? 1.0F : 0.0F;
- }
- break;
- case ir_unop_f2b:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.b[c] = op[0]->value.f[c] != 0.0F ? true : false;
- }
- break;
- case ir_unop_b2i:
- assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.u[c] = op[0]->value.b[c] ? 1 : 0;
- }
- break;
- case ir_unop_i2b:
- assert(op[0]->type->is_integer());
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.b[c] = op[0]->value.u[c] ? true : false;
- }
- break;
-
- case ir_unop_any:
- assert(op[0]->type->is_boolean());
- data.b[0] = false;
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- if (op[0]->value.b[c])
- data.b[0] = true;
- }
- break;
-
- case ir_unop_trunc:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = truncf(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_ceil:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = ceilf(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_floor:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = floorf(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_fract:
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (this->type->base_type) {
- case GLSL_TYPE_UINT:
- data.u[c] = 0;
- break;
- case GLSL_TYPE_INT:
- data.i[c] = 0;
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = op[0]->value.f[c] - floor(op[0]->value.f[c]);
- break;
- default:
- assert(0);
- }
- }
- break;
-
- case ir_unop_sin:
- case ir_unop_sin_reduced:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = sinf(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_cos:
- case ir_unop_cos_reduced:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = cosf(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_neg:
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (this->type->base_type) {
- case GLSL_TYPE_UINT:
- data.u[c] = -((int) op[0]->value.u[c]);
- break;
- case GLSL_TYPE_INT:
- data.i[c] = -op[0]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = -op[0]->value.f[c];
- break;
- default:
- assert(0);
- }
- }
- break;
-
- case ir_unop_abs:
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (this->type->base_type) {
- case GLSL_TYPE_UINT:
- data.u[c] = op[0]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- data.i[c] = op[0]->value.i[c];
- if (data.i[c] < 0)
- data.i[c] = -data.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = fabs(op[0]->value.f[c]);
- break;
- default:
- assert(0);
- }
- }
- break;
-
- case ir_unop_sign:
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (this->type->base_type) {
- case GLSL_TYPE_UINT:
- data.u[c] = op[0]->value.i[c] > 0;
- break;
- case GLSL_TYPE_INT:
- data.i[c] = (op[0]->value.i[c] > 0) - (op[0]->value.i[c] < 0);
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = float((op[0]->value.f[c] > 0)-(op[0]->value.f[c] < 0));
- break;
- default:
- assert(0);
- }
- }
- break;
-
- case ir_unop_rcp:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (this->type->base_type) {
- case GLSL_TYPE_UINT:
- if (op[0]->value.u[c] != 0.0)
- data.u[c] = 1 / op[0]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- if (op[0]->value.i[c] != 0.0)
- data.i[c] = 1 / op[0]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- if (op[0]->value.f[c] != 0.0)
- data.f[c] = 1.0F / op[0]->value.f[c];
- break;
- default:
- assert(0);
- }
- }
- break;
-
- case ir_unop_rsq:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = 1.0F / sqrtf(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_sqrt:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = sqrtf(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_exp:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = expf(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_exp2:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = exp2f(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_log:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = logf(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_log2:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = log2f(op[0]->value.f[c]);
- }
- break;
-
- case ir_unop_dFdx:
- case ir_unop_dFdy:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = 0.0;
- }
- break;
-
- case ir_binop_pow:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = powf(op[0]->value.f[c], op[1]->value.f[c]);
- }
- break;
-
- case ir_binop_dot:
- data.f[0] = dot(op[0], op[1]);
- break;
-
- case ir_binop_min:
- assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.u[c] = MIN2(op[0]->value.u[c0], op[1]->value.u[c1]);
- break;
- case GLSL_TYPE_INT:
- data.i[c] = MIN2(op[0]->value.i[c0], op[1]->value.i[c1]);
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = MIN2(op[0]->value.f[c0], op[1]->value.f[c1]);
- break;
- default:
- assert(0);
- }
- }
-
- break;
- case ir_binop_max:
- assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.u[c] = MAX2(op[0]->value.u[c0], op[1]->value.u[c1]);
- break;
- case GLSL_TYPE_INT:
- data.i[c] = MAX2(op[0]->value.i[c0], op[1]->value.i[c1]);
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = MAX2(op[0]->value.f[c0], op[1]->value.f[c1]);
- break;
- default:
- assert(0);
- }
- }
- break;
-
- case ir_binop_add:
- assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.u[c] = op[0]->value.u[c0] + op[1]->value.u[c1];
- break;
- case GLSL_TYPE_INT:
- data.i[c] = op[0]->value.i[c0] + op[1]->value.i[c1];
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = op[0]->value.f[c0] + op[1]->value.f[c1];
- break;
- default:
- assert(0);
- }
- }
-
- break;
- case ir_binop_sub:
- assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.u[c] = op[0]->value.u[c0] - op[1]->value.u[c1];
- break;
- case GLSL_TYPE_INT:
- data.i[c] = op[0]->value.i[c0] - op[1]->value.i[c1];
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1];
- break;
- default:
- assert(0);
- }
- }
-
- break;
- case ir_binop_mul:
- /* Check for equal types, or unequal types involving scalars */
- if ((op[0]->type == op[1]->type && !op[0]->type->is_matrix())
- || op0_scalar || op1_scalar) {
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.u[c] = op[0]->value.u[c0] * op[1]->value.u[c1];
- break;
- case GLSL_TYPE_INT:
- data.i[c] = op[0]->value.i[c0] * op[1]->value.i[c1];
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = op[0]->value.f[c0] * op[1]->value.f[c1];
- break;
- default:
- assert(0);
- }
- }
- } else {
- assert(op[0]->type->is_matrix() || op[1]->type->is_matrix());
-
- /* Multiply an N-by-M matrix with an M-by-P matrix. Since either
- * matrix can be a GLSL vector, either N or P can be 1.
- *
- * For vec*mat, the vector is treated as a row vector. This
- * means the vector is a 1-row x M-column matrix.
- *
- * For mat*vec, the vector is treated as a column vector. Since
- * matrix_columns is 1 for vectors, this just works.
- */
- const unsigned n = op[0]->type->is_vector()
- ? 1 : op[0]->type->vector_elements;
- const unsigned m = op[1]->type->vector_elements;
- const unsigned p = op[1]->type->matrix_columns;
- for (unsigned j = 0; j < p; j++) {
- for (unsigned i = 0; i < n; i++) {
- for (unsigned k = 0; k < m; k++) {
- data.f[i+n*j] += op[0]->value.f[i+n*k]*op[1]->value.f[k+m*j];
- }
- }
- }
- }
-
- break;
- case ir_binop_div:
- /* FINISHME: Emit warning when division-by-zero is detected. */
- assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- if (op[1]->value.u[c1] == 0) {
- data.u[c] = 0;
- } else {
- data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1];
- }
- break;
- case GLSL_TYPE_INT:
- if (op[1]->value.i[c1] == 0) {
- data.i[c] = 0;
- } else {
- data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1];
- }
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1];
- break;
- default:
- assert(0);
- }
- }
-
- break;
- case ir_binop_mod:
- /* FINISHME: Emit warning when division-by-zero is detected. */
- assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- if (op[1]->value.u[c1] == 0) {
- data.u[c] = 0;
- } else {
- data.u[c] = op[0]->value.u[c0] % op[1]->value.u[c1];
- }
- break;
- case GLSL_TYPE_INT:
- if (op[1]->value.i[c1] == 0) {
- data.i[c] = 0;
- } else {
- data.i[c] = op[0]->value.i[c0] % op[1]->value.i[c1];
- }
- break;
- case GLSL_TYPE_FLOAT:
- /* We don't use fmod because it rounds toward zero; GLSL specifies
- * the use of floor.
- */
- data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1]
- * floorf(op[0]->value.f[c0] / op[1]->value.f[c1]);
- break;
- default:
- assert(0);
- }
- }
-
- break;
-
- case ir_binop_logic_and:
- assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.b[c] = op[0]->value.b[c] && op[1]->value.b[c];
- break;
- case ir_binop_logic_xor:
- assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.b[c] = op[0]->value.b[c] ^ op[1]->value.b[c];
- break;
- case ir_binop_logic_or:
- assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.b[c] = op[0]->value.b[c] || op[1]->value.b[c];
- break;
-
- case ir_binop_less:
- assert(op[0]->type == op[1]->type);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[0] = op[0]->value.u[0] < op[1]->value.u[0];
- break;
- case GLSL_TYPE_INT:
- data.b[0] = op[0]->value.i[0] < op[1]->value.i[0];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[0] = op[0]->value.f[0] < op[1]->value.f[0];
- break;
- default:
- assert(0);
- }
- }
- break;
- case ir_binop_greater:
- assert(op[0]->type == op[1]->type);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[c] = op[0]->value.u[c] > op[1]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- data.b[c] = op[0]->value.i[c] > op[1]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[c] = op[0]->value.f[c] > op[1]->value.f[c];
- break;
- default:
- assert(0);
- }
- }
- break;
- case ir_binop_lequal:
- assert(op[0]->type == op[1]->type);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[0] = op[0]->value.u[0] <= op[1]->value.u[0];
- break;
- case GLSL_TYPE_INT:
- data.b[0] = op[0]->value.i[0] <= op[1]->value.i[0];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[0] = op[0]->value.f[0] <= op[1]->value.f[0];
- break;
- default:
- assert(0);
- }
- }
- break;
- case ir_binop_gequal:
- assert(op[0]->type == op[1]->type);
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[0] = op[0]->value.u[0] >= op[1]->value.u[0];
- break;
- case GLSL_TYPE_INT:
- data.b[0] = op[0]->value.i[0] >= op[1]->value.i[0];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[0] = op[0]->value.f[0] >= op[1]->value.f[0];
- break;
- default:
- assert(0);
- }
- }
- break;
- case ir_binop_equal:
- assert(op[0]->type == op[1]->type);
- for (unsigned c = 0; c < components; c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[c] = op[0]->value.u[c] == op[1]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- data.b[c] = op[0]->value.i[c] == op[1]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[c] = op[0]->value.f[c] == op[1]->value.f[c];
- break;
- default:
- assert(0);
- }
- }
- break;
- case ir_binop_nequal:
- assert(op[0]->type != op[1]->type);
- for (unsigned c = 0; c < components; c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[c] = op[0]->value.u[c] != op[1]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- data.b[c] = op[0]->value.i[c] != op[1]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[c] = op[0]->value.f[c] != op[1]->value.f[c];
- break;
- default:
- assert(0);
- }
- }
- break;
- case ir_binop_all_equal:
- data.b[0] = op[0]->has_value(op[1]);
- break;
- case ir_binop_any_nequal:
- data.b[0] = !op[0]->has_value(op[1]);
- break;
-
- case ir_binop_lshift:
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- if (op[0]->type->base_type == GLSL_TYPE_INT &&
- op[1]->type->base_type == GLSL_TYPE_INT) {
- data.i[c] = op[0]->value.i[c0] << op[1]->value.i[c1];
-
- } else if (op[0]->type->base_type == GLSL_TYPE_INT &&
- op[1]->type->base_type == GLSL_TYPE_UINT) {
- data.i[c] = op[0]->value.i[c0] << op[1]->value.u[c1];
-
- } else if (op[0]->type->base_type == GLSL_TYPE_UINT &&
- op[1]->type->base_type == GLSL_TYPE_INT) {
- data.u[c] = op[0]->value.u[c0] << op[1]->value.i[c1];
-
- } else if (op[0]->type->base_type == GLSL_TYPE_UINT &&
- op[1]->type->base_type == GLSL_TYPE_UINT) {
- data.u[c] = op[0]->value.u[c0] << op[1]->value.u[c1];
- }
- }
- break;
-
- case ir_binop_rshift:
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- if (op[0]->type->base_type == GLSL_TYPE_INT &&
- op[1]->type->base_type == GLSL_TYPE_INT) {
- data.i[c] = op[0]->value.i[c0] >> op[1]->value.i[c1];
-
- } else if (op[0]->type->base_type == GLSL_TYPE_INT &&
- op[1]->type->base_type == GLSL_TYPE_UINT) {
- data.i[c] = op[0]->value.i[c0] >> op[1]->value.u[c1];
-
- } else if (op[0]->type->base_type == GLSL_TYPE_UINT &&
- op[1]->type->base_type == GLSL_TYPE_INT) {
- data.u[c] = op[0]->value.u[c0] >> op[1]->value.i[c1];
-
- } else if (op[0]->type->base_type == GLSL_TYPE_UINT &&
- op[1]->type->base_type == GLSL_TYPE_UINT) {
- data.u[c] = op[0]->value.u[c0] >> op[1]->value.u[c1];
- }
- }
- break;
-
- case ir_binop_bit_and:
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_INT:
- data.i[c] = op[0]->value.i[c0] & op[1]->value.i[c1];
- break;
- case GLSL_TYPE_UINT:
- data.u[c] = op[0]->value.u[c0] & op[1]->value.u[c1];
- break;
- default:
- assert(0);
- }
- }
- break;
-
- case ir_binop_bit_or:
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_INT:
- data.i[c] = op[0]->value.i[c0] | op[1]->value.i[c1];
- break;
- case GLSL_TYPE_UINT:
- data.u[c] = op[0]->value.u[c0] | op[1]->value.u[c1];
- break;
- default:
- assert(0);
- }
- }
- break;
-
- case ir_binop_bit_xor:
- for (unsigned c = 0, c0 = 0, c1 = 0;
- c < components;
- c0 += c0_inc, c1 += c1_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_INT:
- data.i[c] = op[0]->value.i[c0] ^ op[1]->value.i[c1];
- break;
- case GLSL_TYPE_UINT:
- data.u[c] = op[0]->value.u[c0] ^ op[1]->value.u[c1];
- break;
- default:
- assert(0);
- }
- }
- break;
-
- case ir_quadop_vector:
- for (unsigned c = 0; c < this->type->vector_elements; c++) {
- switch (this->type->base_type) {
- case GLSL_TYPE_INT:
- data.i[c] = op[c]->value.i[0];
- break;
- case GLSL_TYPE_UINT:
- data.u[c] = op[c]->value.u[0];
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = op[c]->value.f[0];
- break;
- default:
- assert(0);
- }
- }
- break;
-
- default:
- /* FINISHME: Should handle all expression types. */
- return NULL;
- }
-
- return new(ctx) ir_constant(this->type, &data);
-}
-
-
-ir_constant *
-ir_texture::constant_expression_value()
-{
- /* texture lookups aren't constant expressions */
- return NULL;
-}
-
-
-ir_constant *
-ir_swizzle::constant_expression_value()
-{
- ir_constant *v = this->val->constant_expression_value();
-
- if (v != NULL) {
- ir_constant_data data = { { 0 } };
-
- const unsigned swiz_idx[4] = {
- this->mask.x, this->mask.y, this->mask.z, this->mask.w
- };
-
- for (unsigned i = 0; i < this->mask.num_components; i++) {
- switch (v->type->base_type) {
- case GLSL_TYPE_UINT:
- case GLSL_TYPE_INT: data.u[i] = v->value.u[swiz_idx[i]]; break;
- case GLSL_TYPE_FLOAT: data.f[i] = v->value.f[swiz_idx[i]]; break;
- case GLSL_TYPE_BOOL: data.b[i] = v->value.b[swiz_idx[i]]; break;
- default: assert(!"Should not get here."); break;
- }
- }
-
- void *ctx = ralloc_parent(this);
- return new(ctx) ir_constant(this->type, &data);
- }
- return NULL;
-}
-
-
-ir_constant *
-ir_dereference_variable::constant_expression_value()
-{
- /* This may occur during compile and var->type is glsl_type::error_type */
- if (!var)
- return NULL;
-
- /* The constant_value of a uniform variable is its initializer,
- * not the lifetime constant value of the uniform.
- */
- if (var->mode == ir_var_uniform)
- return NULL;
-
- if (!var->constant_value)
- return NULL;
-
- return var->constant_value->clone(ralloc_parent(var), NULL);
-}
-
-
-ir_constant *
-ir_dereference_array::constant_expression_value()
-{
- ir_constant *array = this->array->constant_expression_value();
- ir_constant *idx = this->array_index->constant_expression_value();
-
- if ((array != NULL) && (idx != NULL)) {
- void *ctx = ralloc_parent(this);
- if (array->type->is_matrix()) {
- /* Array access of a matrix results in a vector.
- */
- const unsigned column = idx->value.u[0];
-
- const glsl_type *const column_type = array->type->column_type();
-
- /* Offset in the constant matrix to the first element of the column
- * to be extracted.
- */
- const unsigned mat_idx = column * column_type->vector_elements;
-
- ir_constant_data data = { { 0 } };
-
- switch (column_type->base_type) {
- case GLSL_TYPE_UINT:
- case GLSL_TYPE_INT:
- for (unsigned i = 0; i < column_type->vector_elements; i++)
- data.u[i] = array->value.u[mat_idx + i];
-
- break;
-
- case GLSL_TYPE_FLOAT:
- for (unsigned i = 0; i < column_type->vector_elements; i++)
- data.f[i] = array->value.f[mat_idx + i];
-
- break;
-
- default:
- assert(!"Should not get here.");
- break;
- }
-
- return new(ctx) ir_constant(column_type, &data);
- } else if (array->type->is_vector()) {
- const unsigned component = idx->value.u[0];
-
- return new(ctx) ir_constant(array, component);
- } else {
- const unsigned index = idx->value.u[0];
- return array->get_array_element(index)->clone(ctx, NULL);
- }
- }
- return NULL;
-}
-
-
-ir_constant *
-ir_dereference_record::constant_expression_value()
-{
- ir_constant *v = this->record->constant_expression_value();
-
- return (v != NULL) ? v->get_record_field(this->field) : NULL;
-}
-
-
-ir_constant *
-ir_assignment::constant_expression_value()
-{
- /* FINISHME: Handle CEs involving assignment (return RHS) */
- return NULL;
-}
-
-
-ir_constant *
-ir_constant::constant_expression_value()
-{
- return this;
-}
-
-
-ir_constant *
-ir_call::constant_expression_value()
-{
- if (this->type == glsl_type::error_type)
- return NULL;
-
- /* From the GLSL 1.20 spec, page 23:
- * "Function calls to user-defined functions (non-built-in functions)
- * cannot be used to form constant expressions."
- */
- if (!this->callee->is_builtin)
- return NULL;
-
- unsigned num_parameters = 0;
-
- /* Check if all parameters are constant */
- ir_constant *op[3];
- foreach_list(n, &this->actual_parameters) {
- ir_constant *constant = ((ir_rvalue *) n)->constant_expression_value();
- if (constant == NULL)
- return NULL;
-
- op[num_parameters] = constant;
-
- assert(num_parameters < 3);
- num_parameters++;
- }
-
- /* Individual cases below can either:
- * - Assign "expr" a new ir_expression to evaluate (for basic opcodes)
- * - Fill "data" with appopriate constant data
- * - Return an ir_constant directly.
- */
- void *mem_ctx = ralloc_parent(this);
- ir_expression *expr = NULL;
-
- ir_constant_data data;
- memset(&data, 0, sizeof(data));
-
- const char *callee = this->callee_name();
- if (strcmp(callee, "abs") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_abs, type, op[0], NULL);
- } else if (strcmp(callee, "all") == 0) {
- assert(op[0]->type->is_boolean());
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- if (!op[0]->value.b[c])
- return new(mem_ctx) ir_constant(false);
- }
- return new(mem_ctx) ir_constant(true);
- } else if (strcmp(callee, "any") == 0) {
- assert(op[0]->type->is_boolean());
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- if (op[0]->value.b[c])
- return new(mem_ctx) ir_constant(true);
- }
- return new(mem_ctx) ir_constant(false);
- } else if (strcmp(callee, "acos") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = acosf(op[0]->value.f[c]);
- } else if (strcmp(callee, "acosh") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = acoshf(op[0]->value.f[c]);
- } else if (strcmp(callee, "asin") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = asinf(op[0]->value.f[c]);
- } else if (strcmp(callee, "asinh") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = asinhf(op[0]->value.f[c]);
- } else if (strcmp(callee, "atan") == 0) {
- assert(op[0]->type->is_float());
- if (num_parameters == 2) {
- assert(op[1]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = atan2f(op[0]->value.f[c], op[1]->value.f[c]);
- } else {
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = atanf(op[0]->value.f[c]);
- }
- } else if (strcmp(callee, "atanh") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = atanhf(op[0]->value.f[c]);
- } else if (strcmp(callee, "dFdx") == 0 || strcmp(callee, "dFdy") == 0) {
- return ir_constant::zero(mem_ctx, this->type);
- } else if (strcmp(callee, "ceil") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_ceil, type, op[0], NULL);
- } else if (strcmp(callee, "clamp") == 0) {
- assert(num_parameters == 3);
- unsigned c1_inc = op[1]->type->is_scalar() ? 0 : 1;
- unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1;
- for (unsigned c = 0, c1 = 0, c2 = 0;
- c < op[0]->type->components();
- c1 += c1_inc, c2 += c2_inc, c++) {
-
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.u[c] = CLAMP(op[0]->value.u[c], op[1]->value.u[c1],
- op[2]->value.u[c2]);
- break;
- case GLSL_TYPE_INT:
- data.i[c] = CLAMP(op[0]->value.i[c], op[1]->value.i[c1],
- op[2]->value.i[c2]);
- break;
- case GLSL_TYPE_FLOAT:
- data.f[c] = CLAMP(op[0]->value.f[c], op[1]->value.f[c1],
- op[2]->value.f[c2]);
- break;
- default:
- assert(!"Should not get here.");
- }
- }
- } else if (strcmp(callee, "cos") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_cos, type, op[0], NULL);
- } else if (strcmp(callee, "cosh") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = coshf(op[0]->value.f[c]);
- } else if (strcmp(callee, "cross") == 0) {
- assert(op[0]->type == glsl_type::vec3_type);
- assert(op[1]->type == glsl_type::vec3_type);
- data.f[0] = (op[0]->value.f[1] * op[1]->value.f[2] -
- op[1]->value.f[1] * op[0]->value.f[2]);
- data.f[1] = (op[0]->value.f[2] * op[1]->value.f[0] -
- op[1]->value.f[2] * op[0]->value.f[0]);
- data.f[2] = (op[0]->value.f[0] * op[1]->value.f[1] -
- op[1]->value.f[0] * op[0]->value.f[1]);
- } else if (strcmp(callee, "degrees") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = 180.0F / M_PI * op[0]->value.f[c];
- } else if (strcmp(callee, "distance") == 0) {
- assert(op[0]->type->is_float() && op[1]->type->is_float());
- float length_squared = 0.0;
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- float t = op[0]->value.f[c] - op[1]->value.f[c];
- length_squared += t * t;
- }
- return new(mem_ctx) ir_constant(sqrtf(length_squared));
- } else if (strcmp(callee, "dot") == 0) {
- return new(mem_ctx) ir_constant(dot(op[0], op[1]));
- } else if (strcmp(callee, "equal") == 0) {
- assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[c] = op[0]->value.u[c] == op[1]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- data.b[c] = op[0]->value.i[c] == op[1]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[c] = op[0]->value.f[c] == op[1]->value.f[c];
- break;
- case GLSL_TYPE_BOOL:
- data.b[c] = op[0]->value.b[c] == op[1]->value.b[c];
- break;
- default:
- assert(!"Should not get here.");
- }
- }
- } else if (strcmp(callee, "exp") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_exp, type, op[0], NULL);
- } else if (strcmp(callee, "exp2") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_exp2, type, op[0], NULL);
- } else if (strcmp(callee, "faceforward") == 0) {
- if (dot(op[2], op[1]) < 0)
- return op[0];
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = -op[0]->value.f[c];
- } else if (strcmp(callee, "floor") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_floor, type, op[0], NULL);
- } else if (strcmp(callee, "fract") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_fract, type, op[0], NULL);
- } else if (strcmp(callee, "fwidth") == 0) {
- return ir_constant::zero(mem_ctx, this->type);
- } else if (strcmp(callee, "greaterThan") == 0) {
- assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[c] = op[0]->value.u[c] > op[1]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- data.b[c] = op[0]->value.i[c] > op[1]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[c] = op[0]->value.f[c] > op[1]->value.f[c];
- break;
- default:
- assert(!"Should not get here.");
- }
- }
- } else if (strcmp(callee, "greaterThanEqual") == 0) {
- assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[c] = op[0]->value.u[c] >= op[1]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- data.b[c] = op[0]->value.i[c] >= op[1]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[c] = op[0]->value.f[c] >= op[1]->value.f[c];
- break;
- default:
- assert(!"Should not get here.");
- }
- }
- } else if (strcmp(callee, "inversesqrt") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_rsq, type, op[0], NULL);
- } else if (strcmp(callee, "length") == 0) {
- return new(mem_ctx) ir_constant(sqrtf(dot(op[0], op[0])));
- } else if (strcmp(callee, "lessThan") == 0) {
- assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[c] = op[0]->value.u[c] < op[1]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- data.b[c] = op[0]->value.i[c] < op[1]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[c] = op[0]->value.f[c] < op[1]->value.f[c];
- break;
- default:
- assert(!"Should not get here.");
- }
- }
- } else if (strcmp(callee, "lessThanEqual") == 0) {
- assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[c] = op[0]->value.u[c] <= op[1]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- data.b[c] = op[0]->value.i[c] <= op[1]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[c] = op[0]->value.f[c] <= op[1]->value.f[c];
- break;
- default:
- assert(!"Should not get here.");
- }
- }
- } else if (strcmp(callee, "log") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_log, type, op[0], NULL);
- } else if (strcmp(callee, "log2") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_log2, type, op[0], NULL);
- } else if (strcmp(callee, "matrixCompMult") == 0) {
- assert(op[0]->type->is_float() && op[1]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = op[0]->value.f[c] * op[1]->value.f[c];
- } else if (strcmp(callee, "max") == 0) {
- expr = new(mem_ctx) ir_expression(ir_binop_max, type, op[0], op[1]);
- } else if (strcmp(callee, "min") == 0) {
- expr = new(mem_ctx) ir_expression(ir_binop_min, type, op[0], op[1]);
- } else if (strcmp(callee, "mix") == 0) {
- assert(op[0]->type->is_float() && op[1]->type->is_float());
- if (op[2]->type->is_float()) {
- unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1;
- unsigned components = op[0]->type->components();
- for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) {
- data.f[c] = op[0]->value.f[c] * (1 - op[2]->value.f[c2]) +
- op[1]->value.f[c] * op[2]->value.f[c2];
- }
- } else {
- assert(op[2]->type->is_boolean());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = op[op[2]->value.b[c] ? 1 : 0]->value.f[c];
- }
- } else if (strcmp(callee, "mod") == 0) {
- expr = new(mem_ctx) ir_expression(ir_binop_mod, type, op[0], op[1]);
- } else if (strcmp(callee, "normalize") == 0) {
- assert(op[0]->type->is_float());
- float length = sqrtf(dot(op[0], op[0]));
-
- if (length == 0)
- return ir_constant::zero(mem_ctx, this->type);
-
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = op[0]->value.f[c] / length;
- } else if (strcmp(callee, "not") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_logic_not, type, op[0], NULL);
- } else if (strcmp(callee, "notEqual") == 0) {
- assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- switch (op[0]->type->base_type) {
- case GLSL_TYPE_UINT:
- data.b[c] = op[0]->value.u[c] != op[1]->value.u[c];
- break;
- case GLSL_TYPE_INT:
- data.b[c] = op[0]->value.i[c] != op[1]->value.i[c];
- break;
- case GLSL_TYPE_FLOAT:
- data.b[c] = op[0]->value.f[c] != op[1]->value.f[c];
- break;
- case GLSL_TYPE_BOOL:
- data.b[c] = op[0]->value.b[c] != op[1]->value.b[c];
- break;
- default:
- assert(!"Should not get here.");
- }
- }
- } else if (strcmp(callee, "outerProduct") == 0) {
- assert(op[0]->type->is_vector() && op[1]->type->is_vector());
- const unsigned m = op[0]->type->vector_elements;
- const unsigned n = op[1]->type->vector_elements;
- for (unsigned j = 0; j < n; j++) {
- for (unsigned i = 0; i < m; i++) {
- data.f[i+m*j] = op[0]->value.f[i] * op[1]->value.f[j];
- }
- }
- } else if (strcmp(callee, "pow") == 0) {
- expr = new(mem_ctx) ir_expression(ir_binop_pow, type, op[0], op[1]);
- } else if (strcmp(callee, "radians") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = M_PI / 180.0F * op[0]->value.f[c];
- } else if (strcmp(callee, "reflect") == 0) {
- assert(op[0]->type->is_float());
- float dot_NI = dot(op[1], op[0]);
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = op[0]->value.f[c] - 2 * dot_NI * op[1]->value.f[c];
- } else if (strcmp(callee, "refract") == 0) {
- const float eta = op[2]->value.f[0];
- const float dot_NI = dot(op[1], op[0]);
- const float k = 1.0F - eta * eta * (1.0F - dot_NI * dot_NI);
- if (k < 0.0) {
- return ir_constant::zero(mem_ctx, this->type);
- } else {
- for (unsigned c = 0; c < type->components(); c++) {
- data.f[c] = eta * op[0]->value.f[c] - (eta * dot_NI + sqrtf(k))
- * op[1]->value.f[c];
- }
- }
- } else if (strcmp(callee, "sign") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_sign, type, op[0], NULL);
- } else if (strcmp(callee, "sin") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_sin, type, op[0], NULL);
- } else if (strcmp(callee, "sinh") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = sinhf(op[0]->value.f[c]);
- } else if (strcmp(callee, "smoothstep") == 0) {
- assert(num_parameters == 3);
- assert(op[1]->type == op[0]->type);
- unsigned edge_inc = op[0]->type->is_scalar() ? 0 : 1;
- for (unsigned c = 0, e = 0; c < type->components(); e += edge_inc, c++) {
- const float edge0 = op[0]->value.f[e];
- const float edge1 = op[1]->value.f[e];
- if (edge0 == edge1) {
- data.f[c] = 0.0; /* Avoid a crash - results are undefined anyway */
- } else {
- const float numerator = op[2]->value.f[c] - edge0;
- const float denominator = edge1 - edge0;
- const float t = CLAMP(numerator/denominator, 0, 1);
- data.f[c] = t * t * (3 - 2 * t);
- }
- }
- } else if (strcmp(callee, "sqrt") == 0) {
- expr = new(mem_ctx) ir_expression(ir_unop_sqrt, type, op[0], NULL);
- } else if (strcmp(callee, "step") == 0) {
- assert(op[0]->type->is_float() && op[1]->type->is_float());
- /* op[0] (edge) may be either a scalar or a vector */
- const unsigned c0_inc = op[0]->type->is_scalar() ? 0 : 1;
- for (unsigned c = 0, c0 = 0; c < type->components(); c0 += c0_inc, c++)
- data.f[c] = (op[1]->value.f[c] < op[0]->value.f[c0]) ? 0.0F : 1.0F;
- } else if (strcmp(callee, "tan") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = tanf(op[0]->value.f[c]);
- } else if (strcmp(callee, "tanh") == 0) {
- assert(op[0]->type->is_float());
- for (unsigned c = 0; c < op[0]->type->components(); c++)
- data.f[c] = tanhf(op[0]->value.f[c]);
- } else if (strcmp(callee, "transpose") == 0) {
- assert(op[0]->type->is_matrix());
- const unsigned n = op[0]->type->vector_elements;
- const unsigned m = op[0]->type->matrix_columns;
- for (unsigned j = 0; j < m; j++) {
- for (unsigned i = 0; i < n; i++) {
- data.f[m*i+j] += op[0]->value.f[i+n*j];
- }
- }
- } else {
- /* Unsupported builtin - some are not allowed in constant expressions. */
- return NULL;
- }
-
- if (expr != NULL)
- return expr->constant_expression_value();
-
- return new(mem_ctx) ir_constant(this->type, &data);
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file ir_constant_expression.cpp
+ * Evaluate and process constant valued expressions
+ *
+ * In GLSL, constant valued expressions are used in several places. These
+ * must be processed and evaluated very early in the compilation process.
+ *
+ * * Sizes of arrays
+ * * Initializers for uniforms
+ * * Initializers for \c const variables
+ */
+
+#include <math.h>
+#include "main/core.h" /* for MAX2, MIN2, CLAMP */
+#include "ir.h"
+#include "ir_visitor.h"
+#include "glsl_types.h"
+
+static float
+dot(ir_constant *op0, ir_constant *op1)
+{
+ assert(op0->type->is_float() && op1->type->is_float());
+
+ float result = 0;
+ for (unsigned c = 0; c < op0->type->components(); c++)
+ result += op0->value.f[c] * op1->value.f[c];
+
+ return result;
+}
+
+ir_constant *
+ir_expression::constant_expression_value()
+{
+ if (this->type->is_error())
+ return NULL;
+
+ ir_constant *op[Elements(this->operands)] = { NULL, };
+ ir_constant_data data;
+
+ memset(&data, 0, sizeof(data));
+
+ for (unsigned operand = 0; operand < this->get_num_operands(); operand++) {
+ op[operand] = this->operands[operand]->constant_expression_value();
+ if (!op[operand])
+ return NULL;
+ }
+
+ if (op[1] != NULL)
+ assert(op[0]->type->base_type == op[1]->type->base_type);
+
+ bool op0_scalar = op[0]->type->is_scalar();
+ bool op1_scalar = op[1] != NULL && op[1]->type->is_scalar();
+
+ /* When iterating over a vector or matrix's components, we want to increase
+ * the loop counter. However, for scalars, we want to stay at 0.
+ */
+ unsigned c0_inc = op0_scalar ? 0 : 1;
+ unsigned c1_inc = op1_scalar ? 0 : 1;
+ unsigned components;
+ if (op1_scalar || !op[1]) {
+ components = op[0]->type->components();
+ } else {
+ components = op[1]->type->components();
+ }
+
+ void *ctx = ralloc_parent(this);
+
+ /* Handle array operations here, rather than below. */
+ if (op[0]->type->is_array()) {
+ assert(op[1] != NULL && op[1]->type->is_array());
+ switch (this->operation) {
+ case ir_binop_all_equal:
+ return new(ctx) ir_constant(op[0]->has_value(op[1]));
+ case ir_binop_any_nequal:
+ return new(ctx) ir_constant(!op[0]->has_value(op[1]));
+ default:
+ break;
+ }
+ return NULL;
+ }
+
+ switch (this->operation) {
+ case ir_unop_bit_not:
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_INT:
+ for (unsigned c = 0; c < components; c++)
+ data.i[c] = ~ op[0]->value.i[c];
+ break;
+ case GLSL_TYPE_UINT:
+ for (unsigned c = 0; c < components; c++)
+ data.u[c] = ~ op[0]->value.u[c];
+ break;
+ default:
+ assert(0);
+ }
+ break;
+
+ case ir_unop_logic_not:
+ assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.b[c] = !op[0]->value.b[c];
+ break;
+
+ case ir_unop_f2i:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.i[c] = (int) op[0]->value.f[c];
+ }
+ break;
+ case ir_unop_i2f:
+ assert(op[0]->type->base_type == GLSL_TYPE_INT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = (float) op[0]->value.i[c];
+ }
+ break;
+ case ir_unop_u2f:
+ assert(op[0]->type->base_type == GLSL_TYPE_UINT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = (float) op[0]->value.u[c];
+ }
+ break;
+ case ir_unop_b2f:
+ assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = op[0]->value.b[c] ? 1.0F : 0.0F;
+ }
+ break;
+ case ir_unop_f2b:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.b[c] = op[0]->value.f[c] != 0.0F ? true : false;
+ }
+ break;
+ case ir_unop_b2i:
+ assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.u[c] = op[0]->value.b[c] ? 1 : 0;
+ }
+ break;
+ case ir_unop_i2b:
+ assert(op[0]->type->is_integer());
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.b[c] = op[0]->value.u[c] ? true : false;
+ }
+ break;
+
+ case ir_unop_any:
+ assert(op[0]->type->is_boolean());
+ data.b[0] = false;
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ if (op[0]->value.b[c])
+ data.b[0] = true;
+ }
+ break;
+
+ case ir_unop_trunc:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = truncf(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_ceil:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = ceilf(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_floor:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = floorf(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_fract:
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (this->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = 0;
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = 0;
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = op[0]->value.f[c] - floor(op[0]->value.f[c]);
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
+ case ir_unop_sin:
+ case ir_unop_sin_reduced:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = sinf(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_cos:
+ case ir_unop_cos_reduced:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = cosf(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_neg:
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (this->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = -((int) op[0]->value.u[c]);
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = -op[0]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = -op[0]->value.f[c];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
+ case ir_unop_abs:
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (this->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = op[0]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = op[0]->value.i[c];
+ if (data.i[c] < 0)
+ data.i[c] = -data.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = fabs(op[0]->value.f[c]);
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
+ case ir_unop_sign:
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (this->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = op[0]->value.i[c] > 0;
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = (op[0]->value.i[c] > 0) - (op[0]->value.i[c] < 0);
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = float((op[0]->value.f[c] > 0)-(op[0]->value.f[c] < 0));
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
+ case ir_unop_rcp:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (this->type->base_type) {
+ case GLSL_TYPE_UINT:
+ if (op[0]->value.u[c] != 0.0)
+ data.u[c] = 1 / op[0]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ if (op[0]->value.i[c] != 0.0)
+ data.i[c] = 1 / op[0]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ if (op[0]->value.f[c] != 0.0)
+ data.f[c] = 1.0F / op[0]->value.f[c];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
+ case ir_unop_rsq:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = 1.0F / sqrtf(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_sqrt:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = sqrtf(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_exp:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = expf(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_exp2:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = exp2f(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_log:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = logf(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_log2:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = log2f(op[0]->value.f[c]);
+ }
+ break;
+
+ case ir_unop_dFdx:
+ case ir_unop_dFdy:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = 0.0;
+ }
+ break;
+
+ case ir_binop_pow:
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = powf(op[0]->value.f[c], op[1]->value.f[c]);
+ }
+ break;
+
+ case ir_binop_dot:
+ data.f[0] = dot(op[0], op[1]);
+ break;
+
+ case ir_binop_min:
+ assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = MIN2(op[0]->value.u[c0], op[1]->value.u[c1]);
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = MIN2(op[0]->value.i[c0], op[1]->value.i[c1]);
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = MIN2(op[0]->value.f[c0], op[1]->value.f[c1]);
+ break;
+ default:
+ assert(0);
+ }
+ }
+
+ break;
+ case ir_binop_max:
+ assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = MAX2(op[0]->value.u[c0], op[1]->value.u[c1]);
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = MAX2(op[0]->value.i[c0], op[1]->value.i[c1]);
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = MAX2(op[0]->value.f[c0], op[1]->value.f[c1]);
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
+ case ir_binop_add:
+ assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = op[0]->value.u[c0] + op[1]->value.u[c1];
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = op[0]->value.i[c0] + op[1]->value.i[c1];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = op[0]->value.f[c0] + op[1]->value.f[c1];
+ break;
+ default:
+ assert(0);
+ }
+ }
+
+ break;
+ case ir_binop_sub:
+ assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = op[0]->value.u[c0] - op[1]->value.u[c1];
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = op[0]->value.i[c0] - op[1]->value.i[c1];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1];
+ break;
+ default:
+ assert(0);
+ }
+ }
+
+ break;
+ case ir_binop_mul:
+ /* Check for equal types, or unequal types involving scalars */
+ if ((op[0]->type == op[1]->type && !op[0]->type->is_matrix())
+ || op0_scalar || op1_scalar) {
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = op[0]->value.u[c0] * op[1]->value.u[c1];
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = op[0]->value.i[c0] * op[1]->value.i[c1];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = op[0]->value.f[c0] * op[1]->value.f[c1];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ } else {
+ assert(op[0]->type->is_matrix() || op[1]->type->is_matrix());
+
+ /* Multiply an N-by-M matrix with an M-by-P matrix. Since either
+ * matrix can be a GLSL vector, either N or P can be 1.
+ *
+ * For vec*mat, the vector is treated as a row vector. This
+ * means the vector is a 1-row x M-column matrix.
+ *
+ * For mat*vec, the vector is treated as a column vector. Since
+ * matrix_columns is 1 for vectors, this just works.
+ */
+ const unsigned n = op[0]->type->is_vector()
+ ? 1 : op[0]->type->vector_elements;
+ const unsigned m = op[1]->type->vector_elements;
+ const unsigned p = op[1]->type->matrix_columns;
+ for (unsigned j = 0; j < p; j++) {
+ for (unsigned i = 0; i < n; i++) {
+ for (unsigned k = 0; k < m; k++) {
+ data.f[i+n*j] += op[0]->value.f[i+n*k]*op[1]->value.f[k+m*j];
+ }
+ }
+ }
+ }
+
+ break;
+ case ir_binop_div:
+ /* FINISHME: Emit warning when division-by-zero is detected. */
+ assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ if (op[1]->value.u[c1] == 0) {
+ data.u[c] = 0;
+ } else {
+ data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1];
+ }
+ break;
+ case GLSL_TYPE_INT:
+ if (op[1]->value.i[c1] == 0) {
+ data.i[c] = 0;
+ } else {
+ data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1];
+ }
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1];
+ break;
+ default:
+ assert(0);
+ }
+ }
+
+ break;
+ case ir_binop_mod:
+ /* FINISHME: Emit warning when division-by-zero is detected. */
+ assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ if (op[1]->value.u[c1] == 0) {
+ data.u[c] = 0;
+ } else {
+ data.u[c] = op[0]->value.u[c0] % op[1]->value.u[c1];
+ }
+ break;
+ case GLSL_TYPE_INT:
+ if (op[1]->value.i[c1] == 0) {
+ data.i[c] = 0;
+ } else {
+ data.i[c] = op[0]->value.i[c0] % op[1]->value.i[c1];
+ }
+ break;
+ case GLSL_TYPE_FLOAT:
+ /* We don't use fmod because it rounds toward zero; GLSL specifies
+ * the use of floor.
+ */
+ data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1]
+ * floorf(op[0]->value.f[c0] / op[1]->value.f[c1]);
+ break;
+ default:
+ assert(0);
+ }
+ }
+
+ break;
+
+ case ir_binop_logic_and:
+ assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.b[c] = op[0]->value.b[c] && op[1]->value.b[c];
+ break;
+ case ir_binop_logic_xor:
+ assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.b[c] = op[0]->value.b[c] ^ op[1]->value.b[c];
+ break;
+ case ir_binop_logic_or:
+ assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.b[c] = op[0]->value.b[c] || op[1]->value.b[c];
+ break;
+
+ case ir_binop_less:
+ assert(op[0]->type == op[1]->type);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[0] = op[0]->value.u[0] < op[1]->value.u[0];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[0] = op[0]->value.i[0] < op[1]->value.i[0];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[0] = op[0]->value.f[0] < op[1]->value.f[0];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+ case ir_binop_greater:
+ assert(op[0]->type == op[1]->type);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[c] = op[0]->value.u[c] > op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[c] = op[0]->value.i[c] > op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[c] = op[0]->value.f[c] > op[1]->value.f[c];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+ case ir_binop_lequal:
+ assert(op[0]->type == op[1]->type);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[0] = op[0]->value.u[0] <= op[1]->value.u[0];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[0] = op[0]->value.i[0] <= op[1]->value.i[0];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[0] = op[0]->value.f[0] <= op[1]->value.f[0];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+ case ir_binop_gequal:
+ assert(op[0]->type == op[1]->type);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[0] = op[0]->value.u[0] >= op[1]->value.u[0];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[0] = op[0]->value.i[0] >= op[1]->value.i[0];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[0] = op[0]->value.f[0] >= op[1]->value.f[0];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+ case ir_binop_equal:
+ assert(op[0]->type == op[1]->type);
+ for (unsigned c = 0; c < components; c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[c] = op[0]->value.u[c] == op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[c] = op[0]->value.i[c] == op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[c] = op[0]->value.f[c] == op[1]->value.f[c];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+ case ir_binop_nequal:
+ assert(op[0]->type != op[1]->type);
+ for (unsigned c = 0; c < components; c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[c] = op[0]->value.u[c] != op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[c] = op[0]->value.i[c] != op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[c] = op[0]->value.f[c] != op[1]->value.f[c];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+ case ir_binop_all_equal:
+ data.b[0] = op[0]->has_value(op[1]);
+ break;
+ case ir_binop_any_nequal:
+ data.b[0] = !op[0]->has_value(op[1]);
+ break;
+
+ case ir_binop_lshift:
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ if (op[0]->type->base_type == GLSL_TYPE_INT &&
+ op[1]->type->base_type == GLSL_TYPE_INT) {
+ data.i[c] = op[0]->value.i[c0] << op[1]->value.i[c1];
+
+ } else if (op[0]->type->base_type == GLSL_TYPE_INT &&
+ op[1]->type->base_type == GLSL_TYPE_UINT) {
+ data.i[c] = op[0]->value.i[c0] << op[1]->value.u[c1];
+
+ } else if (op[0]->type->base_type == GLSL_TYPE_UINT &&
+ op[1]->type->base_type == GLSL_TYPE_INT) {
+ data.u[c] = op[0]->value.u[c0] << op[1]->value.i[c1];
+
+ } else if (op[0]->type->base_type == GLSL_TYPE_UINT &&
+ op[1]->type->base_type == GLSL_TYPE_UINT) {
+ data.u[c] = op[0]->value.u[c0] << op[1]->value.u[c1];
+ }
+ }
+ break;
+
+ case ir_binop_rshift:
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ if (op[0]->type->base_type == GLSL_TYPE_INT &&
+ op[1]->type->base_type == GLSL_TYPE_INT) {
+ data.i[c] = op[0]->value.i[c0] >> op[1]->value.i[c1];
+
+ } else if (op[0]->type->base_type == GLSL_TYPE_INT &&
+ op[1]->type->base_type == GLSL_TYPE_UINT) {
+ data.i[c] = op[0]->value.i[c0] >> op[1]->value.u[c1];
+
+ } else if (op[0]->type->base_type == GLSL_TYPE_UINT &&
+ op[1]->type->base_type == GLSL_TYPE_INT) {
+ data.u[c] = op[0]->value.u[c0] >> op[1]->value.i[c1];
+
+ } else if (op[0]->type->base_type == GLSL_TYPE_UINT &&
+ op[1]->type->base_type == GLSL_TYPE_UINT) {
+ data.u[c] = op[0]->value.u[c0] >> op[1]->value.u[c1];
+ }
+ }
+ break;
+
+ case ir_binop_bit_and:
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_INT:
+ data.i[c] = op[0]->value.i[c0] & op[1]->value.i[c1];
+ break;
+ case GLSL_TYPE_UINT:
+ data.u[c] = op[0]->value.u[c0] & op[1]->value.u[c1];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
+ case ir_binop_bit_or:
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_INT:
+ data.i[c] = op[0]->value.i[c0] | op[1]->value.i[c1];
+ break;
+ case GLSL_TYPE_UINT:
+ data.u[c] = op[0]->value.u[c0] | op[1]->value.u[c1];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
+ case ir_binop_bit_xor:
+ for (unsigned c = 0, c0 = 0, c1 = 0;
+ c < components;
+ c0 += c0_inc, c1 += c1_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_INT:
+ data.i[c] = op[0]->value.i[c0] ^ op[1]->value.i[c1];
+ break;
+ case GLSL_TYPE_UINT:
+ data.u[c] = op[0]->value.u[c0] ^ op[1]->value.u[c1];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
+ case ir_quadop_vector:
+ for (unsigned c = 0; c < this->type->vector_elements; c++) {
+ switch (this->type->base_type) {
+ case GLSL_TYPE_INT:
+ data.i[c] = op[c]->value.i[0];
+ break;
+ case GLSL_TYPE_UINT:
+ data.u[c] = op[c]->value.u[0];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = op[c]->value.f[0];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
+ default:
+ /* FINISHME: Should handle all expression types. */
+ return NULL;
+ }
+
+ return new(ctx) ir_constant(this->type, &data);
+}
+
+
+ir_constant *
+ir_texture::constant_expression_value()
+{
+ /* texture lookups aren't constant expressions */
+ return NULL;
+}
+
+
+ir_constant *
+ir_swizzle::constant_expression_value()
+{
+ ir_constant *v = this->val->constant_expression_value();
+
+ if (v != NULL) {
+ ir_constant_data data = { { 0 } };
+
+ const unsigned swiz_idx[4] = {
+ this->mask.x, this->mask.y, this->mask.z, this->mask.w
+ };
+
+ for (unsigned i = 0; i < this->mask.num_components; i++) {
+ switch (v->type->base_type) {
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT: data.u[i] = v->value.u[swiz_idx[i]]; break;
+ case GLSL_TYPE_FLOAT: data.f[i] = v->value.f[swiz_idx[i]]; break;
+ case GLSL_TYPE_BOOL: data.b[i] = v->value.b[swiz_idx[i]]; break;
+ default: assert(!"Should not get here."); break;
+ }
+ }
+
+ void *ctx = ralloc_parent(this);
+ return new(ctx) ir_constant(this->type, &data);
+ }
+ return NULL;
+}
+
+
+ir_constant *
+ir_dereference_variable::constant_expression_value()
+{
+ /* This may occur during compile and var->type is glsl_type::error_type */
+ if (!var)
+ return NULL;
+
+ /* The constant_value of a uniform variable is its initializer,
+ * not the lifetime constant value of the uniform.
+ */
+ if (var->mode == ir_var_uniform)
+ return NULL;
+
+ if (!var->constant_value)
+ return NULL;
+
+ return var->constant_value->clone(ralloc_parent(var), NULL);
+}
+
+
+ir_constant *
+ir_dereference_array::constant_expression_value()
+{
+ ir_constant *array = this->array->constant_expression_value();
+ ir_constant *idx = this->array_index->constant_expression_value();
+
+ if ((array != NULL) && (idx != NULL)) {
+ void *ctx = ralloc_parent(this);
+ if (array->type->is_matrix()) {
+ /* Array access of a matrix results in a vector.
+ */
+ const unsigned column = idx->value.u[0];
+
+ const glsl_type *const column_type = array->type->column_type();
+
+ /* Offset in the constant matrix to the first element of the column
+ * to be extracted.
+ */
+ const unsigned mat_idx = column * column_type->vector_elements;
+
+ ir_constant_data data = { { 0 } };
+
+ switch (column_type->base_type) {
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT:
+ for (unsigned i = 0; i < column_type->vector_elements; i++)
+ data.u[i] = array->value.u[mat_idx + i];
+
+ break;
+
+ case GLSL_TYPE_FLOAT:
+ for (unsigned i = 0; i < column_type->vector_elements; i++)
+ data.f[i] = array->value.f[mat_idx + i];
+
+ break;
+
+ default:
+ assert(!"Should not get here.");
+ break;
+ }
+
+ return new(ctx) ir_constant(column_type, &data);
+ } else if (array->type->is_vector()) {
+ const unsigned component = idx->value.u[0];
+
+ return new(ctx) ir_constant(array, component);
+ } else {
+ const unsigned index = idx->value.u[0];
+ return array->get_array_element(index)->clone(ctx, NULL);
+ }
+ }
+ return NULL;
+}
+
+
+ir_constant *
+ir_dereference_record::constant_expression_value()
+{
+ ir_constant *v = this->record->constant_expression_value();
+
+ return (v != NULL) ? v->get_record_field(this->field) : NULL;
+}
+
+
+ir_constant *
+ir_assignment::constant_expression_value()
+{
+ /* FINISHME: Handle CEs involving assignment (return RHS) */
+ return NULL;
+}
+
+
+ir_constant *
+ir_constant::constant_expression_value()
+{
+ return this;
+}
+
+
+ir_constant *
+ir_call::constant_expression_value()
+{
+ if (this->type == glsl_type::error_type)
+ return NULL;
+
+ /* From the GLSL 1.20 spec, page 23:
+ * "Function calls to user-defined functions (non-built-in functions)
+ * cannot be used to form constant expressions."
+ */
+ if (!this->callee->is_builtin)
+ return NULL;
+
+ unsigned num_parameters = 0;
+
+ /* Check if all parameters are constant */
+ ir_constant *op[3];
+ foreach_list(n, &this->actual_parameters) {
+ ir_constant *constant = ((ir_rvalue *) n)->constant_expression_value();
+ if (constant == NULL)
+ return NULL;
+
+ op[num_parameters] = constant;
+
+ assert(num_parameters < 3);
+ num_parameters++;
+ }
+
+ /* Individual cases below can either:
+ * - Assign "expr" a new ir_expression to evaluate (for basic opcodes)
+ * - Fill "data" with appopriate constant data
+ * - Return an ir_constant directly.
+ */
+ void *mem_ctx = ralloc_parent(this);
+ ir_expression *expr = NULL;
+
+ ir_constant_data data;
+ memset(&data, 0, sizeof(data));
+
+ const char *callee = this->callee_name();
+ if (strcmp(callee, "abs") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_abs, type, op[0], NULL);
+ } else if (strcmp(callee, "all") == 0) {
+ assert(op[0]->type->is_boolean());
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ if (!op[0]->value.b[c])
+ return new(mem_ctx) ir_constant(false);
+ }
+ return new(mem_ctx) ir_constant(true);
+ } else if (strcmp(callee, "any") == 0) {
+ assert(op[0]->type->is_boolean());
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ if (op[0]->value.b[c])
+ return new(mem_ctx) ir_constant(true);
+ }
+ return new(mem_ctx) ir_constant(false);
+ } else if (strcmp(callee, "acos") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = acosf(op[0]->value.f[c]);
+ } else if (strcmp(callee, "acosh") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = acoshf(op[0]->value.f[c]);
+ } else if (strcmp(callee, "asin") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = asinf(op[0]->value.f[c]);
+ } else if (strcmp(callee, "asinh") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = asinhf(op[0]->value.f[c]);
+ } else if (strcmp(callee, "atan") == 0) {
+ assert(op[0]->type->is_float());
+ if (num_parameters == 2) {
+ assert(op[1]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = atan2f(op[0]->value.f[c], op[1]->value.f[c]);
+ } else {
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = atanf(op[0]->value.f[c]);
+ }
+ } else if (strcmp(callee, "atanh") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = atanhf(op[0]->value.f[c]);
+ } else if (strcmp(callee, "dFdx") == 0 || strcmp(callee, "dFdy") == 0) {
+ return ir_constant::zero(mem_ctx, this->type);
+ } else if (strcmp(callee, "ceil") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_ceil, type, op[0], NULL);
+ } else if (strcmp(callee, "clamp") == 0) {
+ assert(num_parameters == 3);
+ unsigned c1_inc = op[1]->type->is_scalar() ? 0 : 1;
+ unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1;
+ for (unsigned c = 0, c1 = 0, c2 = 0;
+ c < op[0]->type->components();
+ c1 += c1_inc, c2 += c2_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = CLAMP(op[0]->value.u[c], op[1]->value.u[c1],
+ op[2]->value.u[c2]);
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = CLAMP(op[0]->value.i[c], op[1]->value.i[c1],
+ op[2]->value.i[c2]);
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = CLAMP(op[0]->value.f[c], op[1]->value.f[c1],
+ op[2]->value.f[c2]);
+ break;
+ default:
+ assert(!"Should not get here.");
+ }
+ }
+ } else if (strcmp(callee, "cos") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_cos, type, op[0], NULL);
+ } else if (strcmp(callee, "cosh") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = coshf(op[0]->value.f[c]);
+ } else if (strcmp(callee, "cross") == 0) {
+ assert(op[0]->type == glsl_type::vec3_type);
+ assert(op[1]->type == glsl_type::vec3_type);
+ data.f[0] = (op[0]->value.f[1] * op[1]->value.f[2] -
+ op[1]->value.f[1] * op[0]->value.f[2]);
+ data.f[1] = (op[0]->value.f[2] * op[1]->value.f[0] -
+ op[1]->value.f[2] * op[0]->value.f[0]);
+ data.f[2] = (op[0]->value.f[0] * op[1]->value.f[1] -
+ op[1]->value.f[0] * op[0]->value.f[1]);
+ } else if (strcmp(callee, "degrees") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = 180.0F / M_PI * op[0]->value.f[c];
+ } else if (strcmp(callee, "distance") == 0) {
+ assert(op[0]->type->is_float() && op[1]->type->is_float());
+ float length_squared = 0.0;
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ float t = op[0]->value.f[c] - op[1]->value.f[c];
+ length_squared += t * t;
+ }
+ return new(mem_ctx) ir_constant(sqrtf(length_squared));
+ } else if (strcmp(callee, "dot") == 0) {
+ return new(mem_ctx) ir_constant(dot(op[0], op[1]));
+ } else if (strcmp(callee, "equal") == 0) {
+ assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[c] = op[0]->value.u[c] == op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[c] = op[0]->value.i[c] == op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[c] = op[0]->value.f[c] == op[1]->value.f[c];
+ break;
+ case GLSL_TYPE_BOOL:
+ data.b[c] = op[0]->value.b[c] == op[1]->value.b[c];
+ break;
+ default:
+ assert(!"Should not get here.");
+ }
+ }
+ } else if (strcmp(callee, "exp") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_exp, type, op[0], NULL);
+ } else if (strcmp(callee, "exp2") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_exp2, type, op[0], NULL);
+ } else if (strcmp(callee, "faceforward") == 0) {
+ if (dot(op[2], op[1]) < 0)
+ return op[0];
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = -op[0]->value.f[c];
+ } else if (strcmp(callee, "floor") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_floor, type, op[0], NULL);
+ } else if (strcmp(callee, "fract") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_fract, type, op[0], NULL);
+ } else if (strcmp(callee, "fwidth") == 0) {
+ return ir_constant::zero(mem_ctx, this->type);
+ } else if (strcmp(callee, "greaterThan") == 0) {
+ assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[c] = op[0]->value.u[c] > op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[c] = op[0]->value.i[c] > op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[c] = op[0]->value.f[c] > op[1]->value.f[c];
+ break;
+ default:
+ assert(!"Should not get here.");
+ }
+ }
+ } else if (strcmp(callee, "greaterThanEqual") == 0) {
+ assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[c] = op[0]->value.u[c] >= op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[c] = op[0]->value.i[c] >= op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[c] = op[0]->value.f[c] >= op[1]->value.f[c];
+ break;
+ default:
+ assert(!"Should not get here.");
+ }
+ }
+ } else if (strcmp(callee, "inversesqrt") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_rsq, type, op[0], NULL);
+ } else if (strcmp(callee, "length") == 0) {
+ return new(mem_ctx) ir_constant(sqrtf(dot(op[0], op[0])));
+ } else if (strcmp(callee, "lessThan") == 0) {
+ assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[c] = op[0]->value.u[c] < op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[c] = op[0]->value.i[c] < op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[c] = op[0]->value.f[c] < op[1]->value.f[c];
+ break;
+ default:
+ assert(!"Should not get here.");
+ }
+ }
+ } else if (strcmp(callee, "lessThanEqual") == 0) {
+ assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[c] = op[0]->value.u[c] <= op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[c] = op[0]->value.i[c] <= op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[c] = op[0]->value.f[c] <= op[1]->value.f[c];
+ break;
+ default:
+ assert(!"Should not get here.");
+ }
+ }
+ } else if (strcmp(callee, "log") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_log, type, op[0], NULL);
+ } else if (strcmp(callee, "log2") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_log2, type, op[0], NULL);
+ } else if (strcmp(callee, "matrixCompMult") == 0) {
+ assert(op[0]->type->is_float() && op[1]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = op[0]->value.f[c] * op[1]->value.f[c];
+ } else if (strcmp(callee, "max") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_binop_max, type, op[0], op[1]);
+ } else if (strcmp(callee, "min") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_binop_min, type, op[0], op[1]);
+ } else if (strcmp(callee, "mix") == 0) {
+ assert(op[0]->type->is_float() && op[1]->type->is_float());
+ if (op[2]->type->is_float()) {
+ unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1;
+ unsigned components = op[0]->type->components();
+ for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) {
+ data.f[c] = op[0]->value.f[c] * (1 - op[2]->value.f[c2]) +
+ op[1]->value.f[c] * op[2]->value.f[c2];
+ }
+ } else {
+ assert(op[2]->type->is_boolean());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = op[op[2]->value.b[c] ? 1 : 0]->value.f[c];
+ }
+ } else if (strcmp(callee, "mod") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_binop_mod, type, op[0], op[1]);
+ } else if (strcmp(callee, "normalize") == 0) {
+ assert(op[0]->type->is_float());
+ float length = sqrtf(dot(op[0], op[0]));
+
+ if (length == 0)
+ return ir_constant::zero(mem_ctx, this->type);
+
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = op[0]->value.f[c] / length;
+ } else if (strcmp(callee, "not") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_logic_not, type, op[0], NULL);
+ } else if (strcmp(callee, "notEqual") == 0) {
+ assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector());
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.b[c] = op[0]->value.u[c] != op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ data.b[c] = op[0]->value.i[c] != op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.b[c] = op[0]->value.f[c] != op[1]->value.f[c];
+ break;
+ case GLSL_TYPE_BOOL:
+ data.b[c] = op[0]->value.b[c] != op[1]->value.b[c];
+ break;
+ default:
+ assert(!"Should not get here.");
+ }
+ }
+ } else if (strcmp(callee, "outerProduct") == 0) {
+ assert(op[0]->type->is_vector() && op[1]->type->is_vector());
+ const unsigned m = op[0]->type->vector_elements;
+ const unsigned n = op[1]->type->vector_elements;
+ for (unsigned j = 0; j < n; j++) {
+ for (unsigned i = 0; i < m; i++) {
+ data.f[i+m*j] = op[0]->value.f[i] * op[1]->value.f[j];
+ }
+ }
+ } else if (strcmp(callee, "pow") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_binop_pow, type, op[0], op[1]);
+ } else if (strcmp(callee, "radians") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = M_PI / 180.0F * op[0]->value.f[c];
+ } else if (strcmp(callee, "reflect") == 0) {
+ assert(op[0]->type->is_float());
+ float dot_NI = dot(op[1], op[0]);
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = op[0]->value.f[c] - 2 * dot_NI * op[1]->value.f[c];
+ } else if (strcmp(callee, "refract") == 0) {
+ const float eta = op[2]->value.f[0];
+ const float dot_NI = dot(op[1], op[0]);
+ const float k = 1.0F - eta * eta * (1.0F - dot_NI * dot_NI);
+ if (k < 0.0) {
+ return ir_constant::zero(mem_ctx, this->type);
+ } else {
+ for (unsigned c = 0; c < type->components(); c++) {
+ data.f[c] = eta * op[0]->value.f[c] - (eta * dot_NI + sqrtf(k))
+ * op[1]->value.f[c];
+ }
+ }
+ } else if (strcmp(callee, "sign") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_sign, type, op[0], NULL);
+ } else if (strcmp(callee, "sin") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_sin, type, op[0], NULL);
+ } else if (strcmp(callee, "sinh") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = sinhf(op[0]->value.f[c]);
+ } else if (strcmp(callee, "smoothstep") == 0) {
+ assert(num_parameters == 3);
+ assert(op[1]->type == op[0]->type);
+ unsigned edge_inc = op[0]->type->is_scalar() ? 0 : 1;
+ for (unsigned c = 0, e = 0; c < type->components(); e += edge_inc, c++) {
+ const float edge0 = op[0]->value.f[e];
+ const float edge1 = op[1]->value.f[e];
+ if (edge0 == edge1) {
+ data.f[c] = 0.0; /* Avoid a crash - results are undefined anyway */
+ } else {
+ const float numerator = op[2]->value.f[c] - edge0;
+ const float denominator = edge1 - edge0;
+ const float t = CLAMP(numerator/denominator, 0, 1);
+ data.f[c] = t * t * (3 - 2 * t);
+ }
+ }
+ } else if (strcmp(callee, "sqrt") == 0) {
+ expr = new(mem_ctx) ir_expression(ir_unop_sqrt, type, op[0], NULL);
+ } else if (strcmp(callee, "step") == 0) {
+ assert(op[0]->type->is_float() && op[1]->type->is_float());
+ /* op[0] (edge) may be either a scalar or a vector */
+ const unsigned c0_inc = op[0]->type->is_scalar() ? 0 : 1;
+ for (unsigned c = 0, c0 = 0; c < type->components(); c0 += c0_inc, c++)
+ data.f[c] = (op[1]->value.f[c] < op[0]->value.f[c0]) ? 0.0F : 1.0F;
+ } else if (strcmp(callee, "tan") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = tanf(op[0]->value.f[c]);
+ } else if (strcmp(callee, "tanh") == 0) {
+ assert(op[0]->type->is_float());
+ for (unsigned c = 0; c < op[0]->type->components(); c++)
+ data.f[c] = tanhf(op[0]->value.f[c]);
+ } else if (strcmp(callee, "transpose") == 0) {
+ assert(op[0]->type->is_matrix());
+ const unsigned n = op[0]->type->vector_elements;
+ const unsigned m = op[0]->type->matrix_columns;
+ for (unsigned j = 0; j < m; j++) {
+ for (unsigned i = 0; i < n; i++) {
+ data.f[m*i+j] += op[0]->value.f[i+n*j];
+ }
+ }
+ } else {
+ /* Unsupported builtin - some are not allowed in constant expressions. */
+ return NULL;
+ }
+
+ if (expr != NULL)
+ return expr->constant_expression_value();
+
+ return new(mem_ctx) ir_constant(this->type, &data);
+}
diff --git a/mesalib/src/glsl/ir_import_prototypes.cpp b/mesalib/src/glsl/ir_import_prototypes.cpp
index 3585bf6b2..03d40bb68 100644
--- a/mesalib/src/glsl/ir_import_prototypes.cpp
+++ b/mesalib/src/glsl/ir_import_prototypes.cpp
@@ -1,122 +1,122 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file ir_import_prototypes.cpp
- * Import function prototypes from one IR tree into another.
- *
- * \author Ian Romanick
- */
-#include "ir.h"
-#include "glsl_symbol_table.h"
-
-/**
- * Visitor used to import function prototypes
- *
- * Normally the \c clone method of either \c ir_function or
- * \c ir_function_signature could be used. However, we don't want a complete
- * clone of the \c ir_function_signature. We want everything \b except the
- * body of the function.
- */
-class import_prototype_visitor : public ir_hierarchical_visitor {
-public:
- /**
- */
- import_prototype_visitor(exec_list *list, glsl_symbol_table *symbols,
- void *mem_ctx)
- {
- this->mem_ctx = mem_ctx;
- this->list = list;
- this->symbols = symbols;
- this->function = NULL;
- }
-
- virtual ir_visitor_status visit_enter(ir_function *ir)
- {
- assert(this->function == NULL);
-
- this->function = this->symbols->get_function(ir->name);
- if (!this->function) {
- this->function = new(this->mem_ctx) ir_function(ir->name);
-
- list->push_tail(this->function);
-
- /* Add the new function to the symbol table.
- */
- this->symbols->add_function(this->function);
- }
- return visit_continue;
- }
-
- virtual ir_visitor_status visit_leave(ir_function *ir)
- {
- (void) ir;
- assert(this->function != NULL);
-
- this->function = NULL;
- return visit_continue;
- }
-
- ir_visitor_status visit_enter(ir_function_signature *ir)
- {
- assert(this->function != NULL);
-
- ir_function_signature *copy = ir->clone_prototype(mem_ctx, NULL);
-
- this->function->add_signature(copy);
-
- /* Do not process child nodes of the ir_function_signature. There can
- * never be any nodes inside the ir_function_signature that we care
- * about. Instead continue with the next sibling.
- */
- return visit_continue_with_parent;
- }
-
-private:
- exec_list *list;
- ir_function *function;
- glsl_symbol_table *symbols;
- void *mem_ctx;
-};
-
-
-/**
- * Import function prototypes from one IR tree into another
- *
- * \param source Source instruction stream containing functions whose
- * prototypes are to be imported
- * \param dest Destination instruction stream where new \c ir_function and
- * \c ir_function_signature nodes will be stored
- * \param symbols Symbol table where new functions will be stored
- * \param mem_ctx ralloc memory context used for new allocations
- */
-void
-import_prototypes(const exec_list *source, exec_list *dest,
- glsl_symbol_table *symbols, void *mem_ctx)
-{
- import_prototype_visitor v(dest, symbols, mem_ctx);
-
- /* Making source be const is just extra documentation.
- */
- v.run(const_cast<exec_list *>(source));
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file ir_import_prototypes.cpp
+ * Import function prototypes from one IR tree into another.
+ *
+ * \author Ian Romanick
+ */
+#include "ir.h"
+#include "glsl_symbol_table.h"
+
+/**
+ * Visitor used to import function prototypes
+ *
+ * Normally the \c clone method of either \c ir_function or
+ * \c ir_function_signature could be used. However, we don't want a complete
+ * clone of the \c ir_function_signature. We want everything \b except the
+ * body of the function.
+ */
+class import_prototype_visitor : public ir_hierarchical_visitor {
+public:
+ /**
+ */
+ import_prototype_visitor(exec_list *list, glsl_symbol_table *symbols,
+ void *mem_ctx)
+ {
+ this->mem_ctx = mem_ctx;
+ this->list = list;
+ this->symbols = symbols;
+ this->function = NULL;
+ }
+
+ virtual ir_visitor_status visit_enter(ir_function *ir)
+ {
+ assert(this->function == NULL);
+
+ this->function = this->symbols->get_function(ir->name);
+ if (!this->function) {
+ this->function = new(this->mem_ctx) ir_function(ir->name);
+
+ list->push_tail(this->function);
+
+ /* Add the new function to the symbol table.
+ */
+ this->symbols->add_function(this->function);
+ }
+ return visit_continue;
+ }
+
+ virtual ir_visitor_status visit_leave(ir_function *ir)
+ {
+ (void) ir;
+ assert(this->function != NULL);
+
+ this->function = NULL;
+ return visit_continue;
+ }
+
+ ir_visitor_status visit_enter(ir_function_signature *ir)
+ {
+ assert(this->function != NULL);
+
+ ir_function_signature *copy = ir->clone_prototype(mem_ctx, NULL);
+
+ this->function->add_signature(copy);
+
+ /* Do not process child nodes of the ir_function_signature. There can
+ * never be any nodes inside the ir_function_signature that we care
+ * about. Instead continue with the next sibling.
+ */
+ return visit_continue_with_parent;
+ }
+
+private:
+ exec_list *list;
+ ir_function *function;
+ glsl_symbol_table *symbols;
+ void *mem_ctx;
+};
+
+
+/**
+ * Import function prototypes from one IR tree into another
+ *
+ * \param source Source instruction stream containing functions whose
+ * prototypes are to be imported
+ * \param dest Destination instruction stream where new \c ir_function and
+ * \c ir_function_signature nodes will be stored
+ * \param symbols Symbol table where new functions will be stored
+ * \param mem_ctx ralloc memory context used for new allocations
+ */
+void
+import_prototypes(const exec_list *source, exec_list *dest,
+ glsl_symbol_table *symbols, void *mem_ctx)
+{
+ import_prototype_visitor v(dest, symbols, mem_ctx);
+
+ /* Making source be const is just extra documentation.
+ */
+ v.run(const_cast<exec_list *>(source));
+}
diff --git a/mesalib/src/glsl/ir_print_visitor.cpp b/mesalib/src/glsl/ir_print_visitor.cpp
index 82ccc722f..f7dc29689 100644
--- a/mesalib/src/glsl/ir_print_visitor.cpp
+++ b/mesalib/src/glsl/ir_print_visitor.cpp
@@ -1,471 +1,471 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include "ir_print_visitor.h"
-#include "glsl_types.h"
-#include "glsl_parser_extras.h"
-
-static void print_type(const glsl_type *t);
-
-void
-ir_instruction::print(void) const
-{
- ir_instruction *deconsted = const_cast<ir_instruction *>(this);
-
- ir_print_visitor v;
- deconsted->accept(&v);
-}
-
-void
-_mesa_print_ir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state)
-{
- if (state) {
- for (unsigned i = 0; i < state->num_user_structures; i++) {
- const glsl_type *const s = state->user_structures[i];
-
- printf("(structure (%s) (%s@%p) (%u) (\n",
- s->name, s->name, (void *) s, s->length);
-
- for (unsigned j = 0; j < s->length; j++) {
- printf("\t((");
- print_type(s->fields.structure[j].type);
- printf(")(%s))\n", s->fields.structure[j].name);
- }
-
- printf(")\n");
- }
- }
-
- printf("(\n");
- foreach_iter(exec_list_iterator, iter, *instructions) {
- ir_instruction *ir = (ir_instruction *)iter.get();
- ir->print();
- if (ir->ir_type != ir_type_function)
- printf("\n");
- }
- printf("\n)");
-}
-
-
-void ir_print_visitor::indent(void)
-{
- for (int i = 0; i < indentation; i++)
- printf(" ");
-}
-
-static void
-print_type(const glsl_type *t)
-{
- if (t->base_type == GLSL_TYPE_ARRAY) {
- printf("(array ");
- print_type(t->fields.array);
- printf(" %u)", t->length);
- } else if ((t->base_type == GLSL_TYPE_STRUCT)
- && (strncmp("gl_", t->name, 3) != 0)) {
- printf("%s@%p", t->name, (void *) t);
- } else {
- printf("%s", t->name);
- }
-}
-
-
-void ir_print_visitor::visit(ir_variable *ir)
-{
- printf("(declare ");
-
- const char *const cent = (ir->centroid) ? "centroid " : "";
- const char *const inv = (ir->invariant) ? "invariant " : "";
- const char *const mode[] = { "", "uniform ", "in ", "out ", "inout ",
- "const_in ", "sys ", "temporary " };
- const char *const interp[] = { "", "flat", "noperspective" };
-
- printf("(%s%s%s%s) ",
- cent, inv, mode[ir->mode], interp[ir->interpolation]);
-
- print_type(ir->type);
- printf(" %s@%p)", ir->name, (void *) ir);
-}
-
-
-void ir_print_visitor::visit(ir_function_signature *ir)
-{
- printf("(signature ");
- indentation++;
-
- print_type(ir->return_type);
- printf("\n");
- indent();
-
- printf("(parameters\n");
- indentation++;
-
- foreach_iter(exec_list_iterator, iter, ir->parameters) {
- ir_variable *const inst = (ir_variable *) iter.get();
-
- indent();
- inst->accept(this);
- printf("\n");
- }
- indentation--;
-
- indent();
- printf(")\n");
-
- indent();
-
- printf("(\n");
- indentation++;
-
- foreach_iter(exec_list_iterator, iter, ir->body) {
- ir_instruction *const inst = (ir_instruction *) iter.get();
-
- indent();
- inst->accept(this);
- printf("\n");
- }
- indentation--;
- indent();
- printf("))\n");
- indentation--;
-}
-
-
-void ir_print_visitor::visit(ir_function *ir)
-{
- printf("(function %s\n", ir->name);
- indentation++;
- foreach_iter(exec_list_iterator, iter, *ir) {
- ir_function_signature *const sig = (ir_function_signature *) iter.get();
- indent();
- sig->accept(this);
- printf("\n");
- }
- indentation--;
- indent();
- printf(")\n\n");
-}
-
-
-void ir_print_visitor::visit(ir_expression *ir)
-{
- printf("(expression ");
-
- print_type(ir->type);
-
- printf(" %s ", ir->operator_string());
-
- for (unsigned i = 0; i < ir->get_num_operands(); i++) {
- ir->operands[i]->accept(this);
- }
-
- printf(") ");
-}
-
-
-void ir_print_visitor::visit(ir_texture *ir)
-{
- printf("(%s ", ir->opcode_string());
-
- ir->sampler->accept(this);
- printf(" ");
-
- ir->coordinate->accept(this);
-
- printf(" ");
-
- if (ir->offset != NULL) {
- ir->offset->accept(this);
- } else {
- printf("0");
- }
-
- printf(" ");
-
- if (ir->op != ir_txf) {
- if (ir->projector)
- ir->projector->accept(this);
- else
- printf("1");
-
- if (ir->shadow_comparitor) {
- printf(" ");
- ir->shadow_comparitor->accept(this);
- } else {
- printf(" ()");
- }
- }
-
- printf(" ");
- switch (ir->op)
- {
- case ir_tex:
- break;
- case ir_txb:
- ir->lod_info.bias->accept(this);
- break;
- case ir_txl:
- case ir_txf:
- ir->lod_info.lod->accept(this);
- break;
- case ir_txd:
- printf("(");
- ir->lod_info.grad.dPdx->accept(this);
- printf(" ");
- ir->lod_info.grad.dPdy->accept(this);
- printf(")");
- break;
- };
- printf(")");
-}
-
-
-void ir_print_visitor::visit(ir_swizzle *ir)
-{
- const unsigned swiz[4] = {
- ir->mask.x,
- ir->mask.y,
- ir->mask.z,
- ir->mask.w,
- };
-
- printf("(swiz ");
- for (unsigned i = 0; i < ir->mask.num_components; i++) {
- printf("%c", "xyzw"[swiz[i]]);
- }
- printf(" ");
- ir->val->accept(this);
- printf(")");
-}
-
-
-void ir_print_visitor::visit(ir_dereference_variable *ir)
-{
- ir_variable *var = ir->variable_referenced();
- printf("(var_ref %s@%p) ", var->name, (void *) var);
-}
-
-
-void ir_print_visitor::visit(ir_dereference_array *ir)
-{
- printf("(array_ref ");
- ir->array->accept(this);
- ir->array_index->accept(this);
- printf(") ");
-}
-
-
-void ir_print_visitor::visit(ir_dereference_record *ir)
-{
- printf("(record_ref ");
- ir->record->accept(this);
- printf(" %s) ", ir->field);
-}
-
-
-void ir_print_visitor::visit(ir_assignment *ir)
-{
- printf("(assign ");
-
- if (ir->condition)
- ir->condition->accept(this);
-
- char mask[5];
- unsigned j = 0;
-
- for (unsigned i = 0; i < 4; i++) {
- if ((ir->write_mask & (1 << i)) != 0) {
- mask[j] = "xyzw"[i];
- j++;
- }
- }
- mask[j] = '\0';
-
- printf(" (%s) ", mask);
-
- ir->lhs->accept(this);
-
- printf(" ");
-
- ir->rhs->accept(this);
- printf(") ");
-}
-
-
-void ir_print_visitor::visit(ir_constant *ir)
-{
- const glsl_type *const base_type = ir->type->get_base_type();
-
- printf("(constant ");
- print_type(ir->type);
- printf(" (");
-
- if (ir->type->is_array()) {
- for (unsigned i = 0; i < ir->type->length; i++)
- ir->get_array_element(i)->accept(this);
- } else if (ir->type->is_record()) {
- ir_constant *value = (ir_constant *) ir->components.get_head();
- for (unsigned i = 0; i < ir->type->length; i++) {
- printf("(%s ", ir->type->fields.structure->name);
- value->accept(this);
- printf(")");
-
- value = (ir_constant *) value->next;
- }
- } else {
- for (unsigned i = 0; i < ir->type->components(); i++) {
- if (i != 0)
- printf(" ");
- switch (base_type->base_type) {
- case GLSL_TYPE_UINT: printf("%u", ir->value.u[i]); break;
- case GLSL_TYPE_INT: printf("%d", ir->value.i[i]); break;
- case GLSL_TYPE_FLOAT: printf("%f", ir->value.f[i]); break;
- case GLSL_TYPE_BOOL: printf("%d", ir->value.b[i]); break;
- default: assert(0);
- }
- }
- }
- printf(")) ");
-}
-
-
-void
-ir_print_visitor::visit(ir_call *ir)
-{
- printf("(call %s (", ir->callee_name());
- foreach_iter(exec_list_iterator, iter, *ir) {
- ir_instruction *const inst = (ir_instruction *) iter.get();
-
- inst->accept(this);
- }
- printf("))\n");
-}
-
-
-void
-ir_print_visitor::visit(ir_return *ir)
-{
- printf("(return");
-
- ir_rvalue *const value = ir->get_value();
- if (value) {
- printf(" ");
- value->accept(this);
- }
-
- printf(")");
-}
-
-
-void
-ir_print_visitor::visit(ir_discard *ir)
-{
- printf("(discard ");
-
- if (ir->condition != NULL) {
- printf(" ");
- ir->condition->accept(this);
- }
-
- printf(")");
-}
-
-
-void
-ir_print_visitor::visit(ir_if *ir)
-{
- printf("(if ");
- ir->condition->accept(this);
-
- printf("(\n");
- indentation++;
-
- foreach_iter(exec_list_iterator, iter, ir->then_instructions) {
- ir_instruction *const inst = (ir_instruction *) iter.get();
-
- indent();
- inst->accept(this);
- printf("\n");
- }
-
- indentation--;
- indent();
- printf(")\n");
-
- indent();
- if (!ir->else_instructions.is_empty()) {
- printf("(\n");
- indentation++;
-
- foreach_iter(exec_list_iterator, iter, ir->else_instructions) {
- ir_instruction *const inst = (ir_instruction *) iter.get();
-
- indent();
- inst->accept(this);
- printf("\n");
- }
- indentation--;
- indent();
- printf("))\n");
- } else {
- printf("())\n");
- }
-}
-
-
-void
-ir_print_visitor::visit(ir_loop *ir)
-{
- printf("(loop (");
- if (ir->counter != NULL)
- ir->counter->accept(this);
- printf(") (");
- if (ir->from != NULL)
- ir->from->accept(this);
- printf(") (");
- if (ir->to != NULL)
- ir->to->accept(this);
- printf(") (");
- if (ir->increment != NULL)
- ir->increment->accept(this);
- printf(") (\n");
- indentation++;
-
- foreach_iter(exec_list_iterator, iter, ir->body_instructions) {
- ir_instruction *const inst = (ir_instruction *) iter.get();
-
- indent();
- inst->accept(this);
- printf("\n");
- }
- indentation--;
- indent();
- printf("))\n");
-}
-
-
-void
-ir_print_visitor::visit(ir_loop_jump *ir)
-{
- printf("%s", ir->is_break() ? "break" : "continue");
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "ir_print_visitor.h"
+#include "glsl_types.h"
+#include "glsl_parser_extras.h"
+
+static void print_type(const glsl_type *t);
+
+void
+ir_instruction::print(void) const
+{
+ ir_instruction *deconsted = const_cast<ir_instruction *>(this);
+
+ ir_print_visitor v;
+ deconsted->accept(&v);
+}
+
+void
+_mesa_print_ir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ if (state) {
+ for (unsigned i = 0; i < state->num_user_structures; i++) {
+ const glsl_type *const s = state->user_structures[i];
+
+ printf("(structure (%s) (%s@%p) (%u) (\n",
+ s->name, s->name, (void *) s, s->length);
+
+ for (unsigned j = 0; j < s->length; j++) {
+ printf("\t((");
+ print_type(s->fields.structure[j].type);
+ printf(")(%s))\n", s->fields.structure[j].name);
+ }
+
+ printf(")\n");
+ }
+ }
+
+ printf("(\n");
+ foreach_iter(exec_list_iterator, iter, *instructions) {
+ ir_instruction *ir = (ir_instruction *)iter.get();
+ ir->print();
+ if (ir->ir_type != ir_type_function)
+ printf("\n");
+ }
+ printf("\n)");
+}
+
+
+void ir_print_visitor::indent(void)
+{
+ for (int i = 0; i < indentation; i++)
+ printf(" ");
+}
+
+static void
+print_type(const glsl_type *t)
+{
+ if (t->base_type == GLSL_TYPE_ARRAY) {
+ printf("(array ");
+ print_type(t->fields.array);
+ printf(" %u)", t->length);
+ } else if ((t->base_type == GLSL_TYPE_STRUCT)
+ && (strncmp("gl_", t->name, 3) != 0)) {
+ printf("%s@%p", t->name, (void *) t);
+ } else {
+ printf("%s", t->name);
+ }
+}
+
+
+void ir_print_visitor::visit(ir_variable *ir)
+{
+ printf("(declare ");
+
+ const char *const cent = (ir->centroid) ? "centroid " : "";
+ const char *const inv = (ir->invariant) ? "invariant " : "";
+ const char *const mode[] = { "", "uniform ", "in ", "out ", "inout ",
+ "const_in ", "sys ", "temporary " };
+ const char *const interp[] = { "", "flat", "noperspective" };
+
+ printf("(%s%s%s%s) ",
+ cent, inv, mode[ir->mode], interp[ir->interpolation]);
+
+ print_type(ir->type);
+ printf(" %s@%p)", ir->name, (void *) ir);
+}
+
+
+void ir_print_visitor::visit(ir_function_signature *ir)
+{
+ printf("(signature ");
+ indentation++;
+
+ print_type(ir->return_type);
+ printf("\n");
+ indent();
+
+ printf("(parameters\n");
+ indentation++;
+
+ foreach_iter(exec_list_iterator, iter, ir->parameters) {
+ ir_variable *const inst = (ir_variable *) iter.get();
+
+ indent();
+ inst->accept(this);
+ printf("\n");
+ }
+ indentation--;
+
+ indent();
+ printf(")\n");
+
+ indent();
+
+ printf("(\n");
+ indentation++;
+
+ foreach_iter(exec_list_iterator, iter, ir->body) {
+ ir_instruction *const inst = (ir_instruction *) iter.get();
+
+ indent();
+ inst->accept(this);
+ printf("\n");
+ }
+ indentation--;
+ indent();
+ printf("))\n");
+ indentation--;
+}
+
+
+void ir_print_visitor::visit(ir_function *ir)
+{
+ printf("(function %s\n", ir->name);
+ indentation++;
+ foreach_iter(exec_list_iterator, iter, *ir) {
+ ir_function_signature *const sig = (ir_function_signature *) iter.get();
+ indent();
+ sig->accept(this);
+ printf("\n");
+ }
+ indentation--;
+ indent();
+ printf(")\n\n");
+}
+
+
+void ir_print_visitor::visit(ir_expression *ir)
+{
+ printf("(expression ");
+
+ print_type(ir->type);
+
+ printf(" %s ", ir->operator_string());
+
+ for (unsigned i = 0; i < ir->get_num_operands(); i++) {
+ ir->operands[i]->accept(this);
+ }
+
+ printf(") ");
+}
+
+
+void ir_print_visitor::visit(ir_texture *ir)
+{
+ printf("(%s ", ir->opcode_string());
+
+ ir->sampler->accept(this);
+ printf(" ");
+
+ ir->coordinate->accept(this);
+
+ printf(" ");
+
+ if (ir->offset != NULL) {
+ ir->offset->accept(this);
+ } else {
+ printf("0");
+ }
+
+ printf(" ");
+
+ if (ir->op != ir_txf) {
+ if (ir->projector)
+ ir->projector->accept(this);
+ else
+ printf("1");
+
+ if (ir->shadow_comparitor) {
+ printf(" ");
+ ir->shadow_comparitor->accept(this);
+ } else {
+ printf(" ()");
+ }
+ }
+
+ printf(" ");
+ switch (ir->op)
+ {
+ case ir_tex:
+ break;
+ case ir_txb:
+ ir->lod_info.bias->accept(this);
+ break;
+ case ir_txl:
+ case ir_txf:
+ ir->lod_info.lod->accept(this);
+ break;
+ case ir_txd:
+ printf("(");
+ ir->lod_info.grad.dPdx->accept(this);
+ printf(" ");
+ ir->lod_info.grad.dPdy->accept(this);
+ printf(")");
+ break;
+ };
+ printf(")");
+}
+
+
+void ir_print_visitor::visit(ir_swizzle *ir)
+{
+ const unsigned swiz[4] = {
+ ir->mask.x,
+ ir->mask.y,
+ ir->mask.z,
+ ir->mask.w,
+ };
+
+ printf("(swiz ");
+ for (unsigned i = 0; i < ir->mask.num_components; i++) {
+ printf("%c", "xyzw"[swiz[i]]);
+ }
+ printf(" ");
+ ir->val->accept(this);
+ printf(")");
+}
+
+
+void ir_print_visitor::visit(ir_dereference_variable *ir)
+{
+ ir_variable *var = ir->variable_referenced();
+ printf("(var_ref %s@%p) ", var->name, (void *) var);
+}
+
+
+void ir_print_visitor::visit(ir_dereference_array *ir)
+{
+ printf("(array_ref ");
+ ir->array->accept(this);
+ ir->array_index->accept(this);
+ printf(") ");
+}
+
+
+void ir_print_visitor::visit(ir_dereference_record *ir)
+{
+ printf("(record_ref ");
+ ir->record->accept(this);
+ printf(" %s) ", ir->field);
+}
+
+
+void ir_print_visitor::visit(ir_assignment *ir)
+{
+ printf("(assign ");
+
+ if (ir->condition)
+ ir->condition->accept(this);
+
+ char mask[5];
+ unsigned j = 0;
+
+ for (unsigned i = 0; i < 4; i++) {
+ if ((ir->write_mask & (1 << i)) != 0) {
+ mask[j] = "xyzw"[i];
+ j++;
+ }
+ }
+ mask[j] = '\0';
+
+ printf(" (%s) ", mask);
+
+ ir->lhs->accept(this);
+
+ printf(" ");
+
+ ir->rhs->accept(this);
+ printf(") ");
+}
+
+
+void ir_print_visitor::visit(ir_constant *ir)
+{
+ const glsl_type *const base_type = ir->type->get_base_type();
+
+ printf("(constant ");
+ print_type(ir->type);
+ printf(" (");
+
+ if (ir->type->is_array()) {
+ for (unsigned i = 0; i < ir->type->length; i++)
+ ir->get_array_element(i)->accept(this);
+ } else if (ir->type->is_record()) {
+ ir_constant *value = (ir_constant *) ir->components.get_head();
+ for (unsigned i = 0; i < ir->type->length; i++) {
+ printf("(%s ", ir->type->fields.structure->name);
+ value->accept(this);
+ printf(")");
+
+ value = (ir_constant *) value->next;
+ }
+ } else {
+ for (unsigned i = 0; i < ir->type->components(); i++) {
+ if (i != 0)
+ printf(" ");
+ switch (base_type->base_type) {
+ case GLSL_TYPE_UINT: printf("%u", ir->value.u[i]); break;
+ case GLSL_TYPE_INT: printf("%d", ir->value.i[i]); break;
+ case GLSL_TYPE_FLOAT: printf("%f", ir->value.f[i]); break;
+ case GLSL_TYPE_BOOL: printf("%d", ir->value.b[i]); break;
+ default: assert(0);
+ }
+ }
+ }
+ printf(")) ");
+}
+
+
+void
+ir_print_visitor::visit(ir_call *ir)
+{
+ printf("(call %s (", ir->callee_name());
+ foreach_iter(exec_list_iterator, iter, *ir) {
+ ir_instruction *const inst = (ir_instruction *) iter.get();
+
+ inst->accept(this);
+ }
+ printf("))\n");
+}
+
+
+void
+ir_print_visitor::visit(ir_return *ir)
+{
+ printf("(return");
+
+ ir_rvalue *const value = ir->get_value();
+ if (value) {
+ printf(" ");
+ value->accept(this);
+ }
+
+ printf(")");
+}
+
+
+void
+ir_print_visitor::visit(ir_discard *ir)
+{
+ printf("(discard ");
+
+ if (ir->condition != NULL) {
+ printf(" ");
+ ir->condition->accept(this);
+ }
+
+ printf(")");
+}
+
+
+void
+ir_print_visitor::visit(ir_if *ir)
+{
+ printf("(if ");
+ ir->condition->accept(this);
+
+ printf("(\n");
+ indentation++;
+
+ foreach_iter(exec_list_iterator, iter, ir->then_instructions) {
+ ir_instruction *const inst = (ir_instruction *) iter.get();
+
+ indent();
+ inst->accept(this);
+ printf("\n");
+ }
+
+ indentation--;
+ indent();
+ printf(")\n");
+
+ indent();
+ if (!ir->else_instructions.is_empty()) {
+ printf("(\n");
+ indentation++;
+
+ foreach_iter(exec_list_iterator, iter, ir->else_instructions) {
+ ir_instruction *const inst = (ir_instruction *) iter.get();
+
+ indent();
+ inst->accept(this);
+ printf("\n");
+ }
+ indentation--;
+ indent();
+ printf("))\n");
+ } else {
+ printf("())\n");
+ }
+}
+
+
+void
+ir_print_visitor::visit(ir_loop *ir)
+{
+ printf("(loop (");
+ if (ir->counter != NULL)
+ ir->counter->accept(this);
+ printf(") (");
+ if (ir->from != NULL)
+ ir->from->accept(this);
+ printf(") (");
+ if (ir->to != NULL)
+ ir->to->accept(this);
+ printf(") (");
+ if (ir->increment != NULL)
+ ir->increment->accept(this);
+ printf(") (\n");
+ indentation++;
+
+ foreach_iter(exec_list_iterator, iter, ir->body_instructions) {
+ ir_instruction *const inst = (ir_instruction *) iter.get();
+
+ indent();
+ inst->accept(this);
+ printf("\n");
+ }
+ indentation--;
+ indent();
+ printf("))\n");
+}
+
+
+void
+ir_print_visitor::visit(ir_loop_jump *ir)
+{
+ printf("%s", ir->is_break() ? "break" : "continue");
+}
diff --git a/mesalib/src/glsl/ir_validate.cpp b/mesalib/src/glsl/ir_validate.cpp
index 44d7549ea..4d9d4562c 100644
--- a/mesalib/src/glsl/ir_validate.cpp
+++ b/mesalib/src/glsl/ir_validate.cpp
@@ -1,529 +1,529 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file ir_validate.cpp
- *
- * Attempts to verify that various invariants of the IR tree are true.
- *
- * In particular, at the moment it makes sure that no single
- * ir_instruction node except for ir_variable appears multiple times
- * in the ir tree. ir_variable does appear multiple times: Once as a
- * declaration in an exec_list, and multiple times as the endpoint of
- * a dereference chain.
- */
-
-#include <inttypes.h>
-#include "ir.h"
-#include "ir_hierarchical_visitor.h"
-#include "program/hash_table.h"
-#include "glsl_types.h"
-
-class ir_validate : public ir_hierarchical_visitor {
-public:
- ir_validate()
- {
- this->ht = hash_table_ctor(0, hash_table_pointer_hash,
- hash_table_pointer_compare);
-
- this->current_function = NULL;
-
- this->callback = ir_validate::validate_ir;
- this->data = ht;
- }
-
- ~ir_validate()
- {
- hash_table_dtor(this->ht);
- }
-
- virtual ir_visitor_status visit(ir_variable *v);
- virtual ir_visitor_status visit(ir_dereference_variable *ir);
- virtual ir_visitor_status visit(ir_if *ir);
-
- virtual ir_visitor_status visit_leave(ir_loop *ir);
- virtual ir_visitor_status visit_enter(ir_function *ir);
- virtual ir_visitor_status visit_leave(ir_function *ir);
- virtual ir_visitor_status visit_enter(ir_function_signature *ir);
-
- virtual ir_visitor_status visit_leave(ir_expression *ir);
- virtual ir_visitor_status visit_leave(ir_swizzle *ir);
-
- virtual ir_visitor_status visit_enter(ir_assignment *ir);
-
- static void validate_ir(ir_instruction *ir, void *data);
-
- ir_function *current_function;
-
- struct hash_table *ht;
-};
-
-
-ir_visitor_status
-ir_validate::visit(ir_dereference_variable *ir)
-{
- if ((ir->var == NULL) || (ir->var->as_variable() == NULL)) {
- printf("ir_dereference_variable @ %p does not specify a variable %p\n",
- (void *) ir, (void *) ir->var);
- abort();
- }
-
- if (hash_table_find(ht, ir->var) == NULL) {
- printf("ir_dereference_variable @ %p specifies undeclared variable "
- "`%s' @ %p\n",
- (void *) ir, ir->var->name, (void *) ir->var);
- abort();
- }
-
- this->validate_ir(ir, this->data);
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_validate::visit(ir_if *ir)
-{
- if (ir->condition->type != glsl_type::bool_type) {
- printf("ir_if condition %s type instead of bool.\n",
- ir->condition->type->name);
- ir->print();
- printf("\n");
- abort();
- }
-
- return visit_continue;
-}
-
-
-ir_visitor_status
-ir_validate::visit_leave(ir_loop *ir)
-{
- if (ir->counter != NULL) {
- if ((ir->from == NULL) || (ir->from == NULL) || (ir->increment == NULL)) {
- printf("ir_loop has invalid loop controls:\n"
- " counter: %p\n"
- " from: %p\n"
- " to: %p\n"
- " increment: %p\n",
- (void *) ir->counter, (void *) ir->from, (void *) ir->to,
- (void *) ir->increment);
- abort();
- }
-
- if ((ir->cmp < ir_binop_less) || (ir->cmp > ir_binop_nequal)) {
- printf("ir_loop has invalid comparitor %d\n", ir->cmp);
- abort();
- }
- } else {
- if ((ir->from != NULL) || (ir->from != NULL) || (ir->increment != NULL)) {
- printf("ir_loop has invalid loop controls:\n"
- " counter: %p\n"
- " from: %p\n"
- " to: %p\n"
- " increment: %p\n",
- (void *) ir->counter, (void *) ir->from, (void *) ir->to,
- (void *) ir->increment);
- abort();
- }
- }
-
- return visit_continue;
-}
-
-
-ir_visitor_status
-ir_validate::visit_enter(ir_function *ir)
-{
- /* Function definitions cannot be nested.
- */
- if (this->current_function != NULL) {
- printf("Function definition nested inside another function "
- "definition:\n");
- printf("%s %p inside %s %p\n",
- ir->name, (void *) ir,
- this->current_function->name, (void *) this->current_function);
- abort();
- }
-
- /* Store the current function hierarchy being traversed. This is used
- * by the function signature visitor to ensure that the signatures are
- * linked with the correct functions.
- */
- this->current_function = ir;
-
- this->validate_ir(ir, this->data);
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_validate::visit_leave(ir_function *ir)
-{
- assert(ralloc_parent(ir->name) == ir);
-
- this->current_function = NULL;
- return visit_continue;
-}
-
-ir_visitor_status
-ir_validate::visit_enter(ir_function_signature *ir)
-{
- if (this->current_function != ir->function()) {
- printf("Function signature nested inside wrong function "
- "definition:\n");
- printf("%p inside %s %p instead of %s %p\n",
- (void *) ir,
- this->current_function->name, (void *) this->current_function,
- ir->function_name(), (void *) ir->function());
- abort();
- }
-
- this->validate_ir(ir, this->data);
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_validate::visit_leave(ir_expression *ir)
-{
- switch (ir->operation) {
- case ir_unop_bit_not:
- assert(ir->operands[0]->type == ir->type);
- break;
- case ir_unop_logic_not:
- assert(ir->type->base_type == GLSL_TYPE_BOOL);
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
- break;
-
- case ir_unop_neg:
- case ir_unop_abs:
- case ir_unop_sign:
- case ir_unop_rcp:
- case ir_unop_rsq:
- case ir_unop_sqrt:
- assert(ir->type == ir->operands[0]->type);
- break;
-
- case ir_unop_exp:
- case ir_unop_log:
- case ir_unop_exp2:
- case ir_unop_log2:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
- assert(ir->type == ir->operands[0]->type);
- break;
-
- case ir_unop_f2i:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
- assert(ir->type->base_type == GLSL_TYPE_INT);
- break;
- case ir_unop_i2f:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
- assert(ir->type->base_type == GLSL_TYPE_FLOAT);
- break;
- case ir_unop_f2b:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
- assert(ir->type->base_type == GLSL_TYPE_BOOL);
- break;
- case ir_unop_b2f:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
- assert(ir->type->base_type == GLSL_TYPE_FLOAT);
- break;
- case ir_unop_i2b:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
- assert(ir->type->base_type == GLSL_TYPE_BOOL);
- break;
- case ir_unop_b2i:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
- assert(ir->type->base_type == GLSL_TYPE_INT);
- break;
- case ir_unop_u2f:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
- assert(ir->type->base_type == GLSL_TYPE_FLOAT);
- break;
-
- case ir_unop_any:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
- assert(ir->type == glsl_type::bool_type);
- break;
-
- case ir_unop_trunc:
- case ir_unop_round_even:
- case ir_unop_ceil:
- case ir_unop_floor:
- case ir_unop_fract:
- case ir_unop_sin:
- case ir_unop_cos:
- case ir_unop_sin_reduced:
- case ir_unop_cos_reduced:
- case ir_unop_dFdx:
- case ir_unop_dFdy:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
- assert(ir->operands[0]->type == ir->type);
- break;
-
- case ir_unop_noise:
- /* XXX what can we assert here? */
- break;
-
- case ir_binop_add:
- case ir_binop_sub:
- case ir_binop_mul:
- case ir_binop_div:
- case ir_binop_mod:
- case ir_binop_min:
- case ir_binop_max:
- case ir_binop_pow:
- if (ir->operands[0]->type->is_scalar())
- assert(ir->operands[1]->type == ir->type);
- else if (ir->operands[1]->type->is_scalar())
- assert(ir->operands[0]->type == ir->type);
- else if (ir->operands[0]->type->is_vector() &&
- ir->operands[1]->type->is_vector()) {
- assert(ir->operands[0]->type == ir->operands[1]->type);
- assert(ir->operands[0]->type == ir->type);
- }
- break;
-
- case ir_binop_less:
- case ir_binop_greater:
- case ir_binop_lequal:
- case ir_binop_gequal:
- case ir_binop_equal:
- case ir_binop_nequal:
- /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
- * ==, and != operators. The IR operators perform a component-wise
- * comparison on scalar or vector types and return a boolean scalar or
- * vector type of the same size.
- */
- assert(ir->type->base_type == GLSL_TYPE_BOOL);
- assert(ir->operands[0]->type == ir->operands[1]->type);
- assert(ir->operands[0]->type->is_vector()
- || ir->operands[0]->type->is_scalar());
- assert(ir->operands[0]->type->vector_elements
- == ir->type->vector_elements);
- break;
-
- case ir_binop_all_equal:
- case ir_binop_any_nequal:
- /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
- * return a scalar boolean. The IR matches that.
- */
- assert(ir->type == glsl_type::bool_type);
- assert(ir->operands[0]->type == ir->operands[1]->type);
- break;
-
- case ir_binop_lshift:
- case ir_binop_rshift:
- assert(ir->operands[0]->type->is_integer() &&
- ir->operands[1]->type->is_integer());
- if (ir->operands[0]->type->is_scalar()) {
- assert(ir->operands[1]->type->is_scalar());
- }
- if (ir->operands[0]->type->is_vector() &&
- ir->operands[1]->type->is_vector()) {
- assert(ir->operands[0]->type->components() ==
- ir->operands[1]->type->components());
- }
- assert(ir->type == ir->operands[0]->type);
- break;
-
- case ir_binop_bit_and:
- case ir_binop_bit_xor:
- case ir_binop_bit_or:
- assert(ir->operands[0]->type->base_type ==
- ir->operands[1]->type->base_type);
- assert(ir->type->is_integer());
- if (ir->operands[0]->type->is_vector() &&
- ir->operands[1]->type->is_vector()) {
- assert(ir->operands[0]->type->vector_elements ==
- ir->operands[1]->type->vector_elements);
- }
- break;
-
- case ir_binop_logic_and:
- case ir_binop_logic_xor:
- case ir_binop_logic_or:
- assert(ir->type == glsl_type::bool_type);
- assert(ir->operands[0]->type == glsl_type::bool_type);
- assert(ir->operands[1]->type == glsl_type::bool_type);
- break;
-
- case ir_binop_dot:
- assert(ir->type == glsl_type::float_type);
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
- assert(ir->operands[0]->type->is_vector());
- assert(ir->operands[0]->type == ir->operands[1]->type);
- break;
-
- case ir_quadop_vector:
- /* The vector operator collects some number of scalars and generates a
- * vector from them.
- *
- * - All of the operands must be scalar.
- * - Number of operands must matche the size of the resulting vector.
- * - Base type of the operands must match the base type of the result.
- */
- assert(ir->type->is_vector());
- switch (ir->type->vector_elements) {
- case 2:
- assert(ir->operands[0]->type->is_scalar());
- assert(ir->operands[0]->type->base_type == ir->type->base_type);
- assert(ir->operands[1]->type->is_scalar());
- assert(ir->operands[1]->type->base_type == ir->type->base_type);
- assert(ir->operands[2] == NULL);
- assert(ir->operands[3] == NULL);
- break;
- case 3:
- assert(ir->operands[0]->type->is_scalar());
- assert(ir->operands[0]->type->base_type == ir->type->base_type);
- assert(ir->operands[1]->type->is_scalar());
- assert(ir->operands[1]->type->base_type == ir->type->base_type);
- assert(ir->operands[2]->type->is_scalar());
- assert(ir->operands[2]->type->base_type == ir->type->base_type);
- assert(ir->operands[3] == NULL);
- break;
- case 4:
- assert(ir->operands[0]->type->is_scalar());
- assert(ir->operands[0]->type->base_type == ir->type->base_type);
- assert(ir->operands[1]->type->is_scalar());
- assert(ir->operands[1]->type->base_type == ir->type->base_type);
- assert(ir->operands[2]->type->is_scalar());
- assert(ir->operands[2]->type->base_type == ir->type->base_type);
- assert(ir->operands[3]->type->is_scalar());
- assert(ir->operands[3]->type->base_type == ir->type->base_type);
- break;
- default:
- /* The is_vector assertion above should prevent execution from ever
- * getting here.
- */
- assert(!"Should not get here.");
- break;
- }
- }
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_validate::visit_leave(ir_swizzle *ir)
-{
- int chans[4] = {ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w};
-
- for (unsigned int i = 0; i < ir->type->vector_elements; i++) {
- if (chans[i] >= ir->val->type->vector_elements) {
- printf("ir_swizzle @ %p specifies a channel not present "
- "in the value.\n", (void *) ir);
- ir->print();
- abort();
- }
- }
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_validate::visit(ir_variable *ir)
-{
- /* An ir_variable is the one thing that can (and will) appear multiple times
- * in an IR tree. It is added to the hashtable so that it can be used
- * in the ir_dereference_variable handler to ensure that a variable is
- * declared before it is dereferenced.
- */
- if (ir->name)
- assert(ralloc_parent(ir->name) == ir);
-
- hash_table_insert(ht, ir, ir);
- return visit_continue;
-}
-
-ir_visitor_status
-ir_validate::visit_enter(ir_assignment *ir)
-{
- const ir_dereference *const lhs = ir->lhs;
- if (lhs->type->is_scalar() || lhs->type->is_vector()) {
- if (ir->write_mask == 0) {
- printf("Assignment LHS is %s, but write mask is 0:\n",
- lhs->type->is_scalar() ? "scalar" : "vector");
- ir->print();
- abort();
- }
-
- int lhs_components = 0;
- for (int i = 0; i < 4; i++) {
- if (ir->write_mask & (1 << i))
- lhs_components++;
- }
-
- if (lhs_components != ir->rhs->type->vector_elements) {
- printf("Assignment count of LHS write mask channels enabled not\n"
- "matching RHS vector size (%d LHS, %d RHS).\n",
- lhs_components, ir->rhs->type->vector_elements);
- ir->print();
- abort();
- }
- }
-
- this->validate_ir(ir, this->data);
-
- return visit_continue;
-}
-
-void
-ir_validate::validate_ir(ir_instruction *ir, void *data)
-{
- struct hash_table *ht = (struct hash_table *) data;
-
- if (hash_table_find(ht, ir)) {
- printf("Instruction node present twice in ir tree:\n");
- ir->print();
- printf("\n");
- abort();
- }
- hash_table_insert(ht, ir, ir);
-}
-
-void
-check_node_type(ir_instruction *ir, void *data)
-{
- (void) data;
-
- if (ir->ir_type <= ir_type_unset || ir->ir_type >= ir_type_max) {
- printf("Instruction node with unset type\n");
- ir->print(); printf("\n");
- }
- assert(ir->type != glsl_type::error_type);
-}
-
-void
-validate_ir_tree(exec_list *instructions)
-{
- ir_validate v;
-
- v.run(instructions);
-
- foreach_iter(exec_list_iterator, iter, *instructions) {
- ir_instruction *ir = (ir_instruction *)iter.get();
-
- visit_tree(ir, check_node_type, NULL);
- }
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file ir_validate.cpp
+ *
+ * Attempts to verify that various invariants of the IR tree are true.
+ *
+ * In particular, at the moment it makes sure that no single
+ * ir_instruction node except for ir_variable appears multiple times
+ * in the ir tree. ir_variable does appear multiple times: Once as a
+ * declaration in an exec_list, and multiple times as the endpoint of
+ * a dereference chain.
+ */
+
+#include <inttypes.h>
+#include "ir.h"
+#include "ir_hierarchical_visitor.h"
+#include "program/hash_table.h"
+#include "glsl_types.h"
+
+class ir_validate : public ir_hierarchical_visitor {
+public:
+ ir_validate()
+ {
+ this->ht = hash_table_ctor(0, hash_table_pointer_hash,
+ hash_table_pointer_compare);
+
+ this->current_function = NULL;
+
+ this->callback = ir_validate::validate_ir;
+ this->data = ht;
+ }
+
+ ~ir_validate()
+ {
+ hash_table_dtor(this->ht);
+ }
+
+ virtual ir_visitor_status visit(ir_variable *v);
+ virtual ir_visitor_status visit(ir_dereference_variable *ir);
+ virtual ir_visitor_status visit(ir_if *ir);
+
+ virtual ir_visitor_status visit_leave(ir_loop *ir);
+ virtual ir_visitor_status visit_enter(ir_function *ir);
+ virtual ir_visitor_status visit_leave(ir_function *ir);
+ virtual ir_visitor_status visit_enter(ir_function_signature *ir);
+
+ virtual ir_visitor_status visit_leave(ir_expression *ir);
+ virtual ir_visitor_status visit_leave(ir_swizzle *ir);
+
+ virtual ir_visitor_status visit_enter(ir_assignment *ir);
+
+ static void validate_ir(ir_instruction *ir, void *data);
+
+ ir_function *current_function;
+
+ struct hash_table *ht;
+};
+
+
+ir_visitor_status
+ir_validate::visit(ir_dereference_variable *ir)
+{
+ if ((ir->var == NULL) || (ir->var->as_variable() == NULL)) {
+ printf("ir_dereference_variable @ %p does not specify a variable %p\n",
+ (void *) ir, (void *) ir->var);
+ abort();
+ }
+
+ if (hash_table_find(ht, ir->var) == NULL) {
+ printf("ir_dereference_variable @ %p specifies undeclared variable "
+ "`%s' @ %p\n",
+ (void *) ir, ir->var->name, (void *) ir->var);
+ abort();
+ }
+
+ this->validate_ir(ir, this->data);
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_validate::visit(ir_if *ir)
+{
+ if (ir->condition->type != glsl_type::bool_type) {
+ printf("ir_if condition %s type instead of bool.\n",
+ ir->condition->type->name);
+ ir->print();
+ printf("\n");
+ abort();
+ }
+
+ return visit_continue;
+}
+
+
+ir_visitor_status
+ir_validate::visit_leave(ir_loop *ir)
+{
+ if (ir->counter != NULL) {
+ if ((ir->from == NULL) || (ir->from == NULL) || (ir->increment == NULL)) {
+ printf("ir_loop has invalid loop controls:\n"
+ " counter: %p\n"
+ " from: %p\n"
+ " to: %p\n"
+ " increment: %p\n",
+ (void *) ir->counter, (void *) ir->from, (void *) ir->to,
+ (void *) ir->increment);
+ abort();
+ }
+
+ if ((ir->cmp < ir_binop_less) || (ir->cmp > ir_binop_nequal)) {
+ printf("ir_loop has invalid comparitor %d\n", ir->cmp);
+ abort();
+ }
+ } else {
+ if ((ir->from != NULL) || (ir->from != NULL) || (ir->increment != NULL)) {
+ printf("ir_loop has invalid loop controls:\n"
+ " counter: %p\n"
+ " from: %p\n"
+ " to: %p\n"
+ " increment: %p\n",
+ (void *) ir->counter, (void *) ir->from, (void *) ir->to,
+ (void *) ir->increment);
+ abort();
+ }
+ }
+
+ return visit_continue;
+}
+
+
+ir_visitor_status
+ir_validate::visit_enter(ir_function *ir)
+{
+ /* Function definitions cannot be nested.
+ */
+ if (this->current_function != NULL) {
+ printf("Function definition nested inside another function "
+ "definition:\n");
+ printf("%s %p inside %s %p\n",
+ ir->name, (void *) ir,
+ this->current_function->name, (void *) this->current_function);
+ abort();
+ }
+
+ /* Store the current function hierarchy being traversed. This is used
+ * by the function signature visitor to ensure that the signatures are
+ * linked with the correct functions.
+ */
+ this->current_function = ir;
+
+ this->validate_ir(ir, this->data);
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_validate::visit_leave(ir_function *ir)
+{
+ assert(ralloc_parent(ir->name) == ir);
+
+ this->current_function = NULL;
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_validate::visit_enter(ir_function_signature *ir)
+{
+ if (this->current_function != ir->function()) {
+ printf("Function signature nested inside wrong function "
+ "definition:\n");
+ printf("%p inside %s %p instead of %s %p\n",
+ (void *) ir,
+ this->current_function->name, (void *) this->current_function,
+ ir->function_name(), (void *) ir->function());
+ abort();
+ }
+
+ this->validate_ir(ir, this->data);
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_validate::visit_leave(ir_expression *ir)
+{
+ switch (ir->operation) {
+ case ir_unop_bit_not:
+ assert(ir->operands[0]->type == ir->type);
+ break;
+ case ir_unop_logic_not:
+ assert(ir->type->base_type == GLSL_TYPE_BOOL);
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
+ break;
+
+ case ir_unop_neg:
+ case ir_unop_abs:
+ case ir_unop_sign:
+ case ir_unop_rcp:
+ case ir_unop_rsq:
+ case ir_unop_sqrt:
+ assert(ir->type == ir->operands[0]->type);
+ break;
+
+ case ir_unop_exp:
+ case ir_unop_log:
+ case ir_unop_exp2:
+ case ir_unop_log2:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+ assert(ir->type == ir->operands[0]->type);
+ break;
+
+ case ir_unop_f2i:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+ assert(ir->type->base_type == GLSL_TYPE_INT);
+ break;
+ case ir_unop_i2f:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
+ assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+ break;
+ case ir_unop_f2b:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+ assert(ir->type->base_type == GLSL_TYPE_BOOL);
+ break;
+ case ir_unop_b2f:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
+ assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+ break;
+ case ir_unop_i2b:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
+ assert(ir->type->base_type == GLSL_TYPE_BOOL);
+ break;
+ case ir_unop_b2i:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
+ assert(ir->type->base_type == GLSL_TYPE_INT);
+ break;
+ case ir_unop_u2f:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
+ assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+ break;
+
+ case ir_unop_any:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
+ assert(ir->type == glsl_type::bool_type);
+ break;
+
+ case ir_unop_trunc:
+ case ir_unop_round_even:
+ case ir_unop_ceil:
+ case ir_unop_floor:
+ case ir_unop_fract:
+ case ir_unop_sin:
+ case ir_unop_cos:
+ case ir_unop_sin_reduced:
+ case ir_unop_cos_reduced:
+ case ir_unop_dFdx:
+ case ir_unop_dFdy:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+ assert(ir->operands[0]->type == ir->type);
+ break;
+
+ case ir_unop_noise:
+ /* XXX what can we assert here? */
+ break;
+
+ case ir_binop_add:
+ case ir_binop_sub:
+ case ir_binop_mul:
+ case ir_binop_div:
+ case ir_binop_mod:
+ case ir_binop_min:
+ case ir_binop_max:
+ case ir_binop_pow:
+ if (ir->operands[0]->type->is_scalar())
+ assert(ir->operands[1]->type == ir->type);
+ else if (ir->operands[1]->type->is_scalar())
+ assert(ir->operands[0]->type == ir->type);
+ else if (ir->operands[0]->type->is_vector() &&
+ ir->operands[1]->type->is_vector()) {
+ assert(ir->operands[0]->type == ir->operands[1]->type);
+ assert(ir->operands[0]->type == ir->type);
+ }
+ break;
+
+ case ir_binop_less:
+ case ir_binop_greater:
+ case ir_binop_lequal:
+ case ir_binop_gequal:
+ case ir_binop_equal:
+ case ir_binop_nequal:
+ /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
+ * ==, and != operators. The IR operators perform a component-wise
+ * comparison on scalar or vector types and return a boolean scalar or
+ * vector type of the same size.
+ */
+ assert(ir->type->base_type == GLSL_TYPE_BOOL);
+ assert(ir->operands[0]->type == ir->operands[1]->type);
+ assert(ir->operands[0]->type->is_vector()
+ || ir->operands[0]->type->is_scalar());
+ assert(ir->operands[0]->type->vector_elements
+ == ir->type->vector_elements);
+ break;
+
+ case ir_binop_all_equal:
+ case ir_binop_any_nequal:
+ /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
+ * return a scalar boolean. The IR matches that.
+ */
+ assert(ir->type == glsl_type::bool_type);
+ assert(ir->operands[0]->type == ir->operands[1]->type);
+ break;
+
+ case ir_binop_lshift:
+ case ir_binop_rshift:
+ assert(ir->operands[0]->type->is_integer() &&
+ ir->operands[1]->type->is_integer());
+ if (ir->operands[0]->type->is_scalar()) {
+ assert(ir->operands[1]->type->is_scalar());
+ }
+ if (ir->operands[0]->type->is_vector() &&
+ ir->operands[1]->type->is_vector()) {
+ assert(ir->operands[0]->type->components() ==
+ ir->operands[1]->type->components());
+ }
+ assert(ir->type == ir->operands[0]->type);
+ break;
+
+ case ir_binop_bit_and:
+ case ir_binop_bit_xor:
+ case ir_binop_bit_or:
+ assert(ir->operands[0]->type->base_type ==
+ ir->operands[1]->type->base_type);
+ assert(ir->type->is_integer());
+ if (ir->operands[0]->type->is_vector() &&
+ ir->operands[1]->type->is_vector()) {
+ assert(ir->operands[0]->type->vector_elements ==
+ ir->operands[1]->type->vector_elements);
+ }
+ break;
+
+ case ir_binop_logic_and:
+ case ir_binop_logic_xor:
+ case ir_binop_logic_or:
+ assert(ir->type == glsl_type::bool_type);
+ assert(ir->operands[0]->type == glsl_type::bool_type);
+ assert(ir->operands[1]->type == glsl_type::bool_type);
+ break;
+
+ case ir_binop_dot:
+ assert(ir->type == glsl_type::float_type);
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+ assert(ir->operands[0]->type->is_vector());
+ assert(ir->operands[0]->type == ir->operands[1]->type);
+ break;
+
+ case ir_quadop_vector:
+ /* The vector operator collects some number of scalars and generates a
+ * vector from them.
+ *
+ * - All of the operands must be scalar.
+ * - Number of operands must matche the size of the resulting vector.
+ * - Base type of the operands must match the base type of the result.
+ */
+ assert(ir->type->is_vector());
+ switch (ir->type->vector_elements) {
+ case 2:
+ assert(ir->operands[0]->type->is_scalar());
+ assert(ir->operands[0]->type->base_type == ir->type->base_type);
+ assert(ir->operands[1]->type->is_scalar());
+ assert(ir->operands[1]->type->base_type == ir->type->base_type);
+ assert(ir->operands[2] == NULL);
+ assert(ir->operands[3] == NULL);
+ break;
+ case 3:
+ assert(ir->operands[0]->type->is_scalar());
+ assert(ir->operands[0]->type->base_type == ir->type->base_type);
+ assert(ir->operands[1]->type->is_scalar());
+ assert(ir->operands[1]->type->base_type == ir->type->base_type);
+ assert(ir->operands[2]->type->is_scalar());
+ assert(ir->operands[2]->type->base_type == ir->type->base_type);
+ assert(ir->operands[3] == NULL);
+ break;
+ case 4:
+ assert(ir->operands[0]->type->is_scalar());
+ assert(ir->operands[0]->type->base_type == ir->type->base_type);
+ assert(ir->operands[1]->type->is_scalar());
+ assert(ir->operands[1]->type->base_type == ir->type->base_type);
+ assert(ir->operands[2]->type->is_scalar());
+ assert(ir->operands[2]->type->base_type == ir->type->base_type);
+ assert(ir->operands[3]->type->is_scalar());
+ assert(ir->operands[3]->type->base_type == ir->type->base_type);
+ break;
+ default:
+ /* The is_vector assertion above should prevent execution from ever
+ * getting here.
+ */
+ assert(!"Should not get here.");
+ break;
+ }
+ }
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_validate::visit_leave(ir_swizzle *ir)
+{
+ int chans[4] = {ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w};
+
+ for (unsigned int i = 0; i < ir->type->vector_elements; i++) {
+ if (chans[i] >= ir->val->type->vector_elements) {
+ printf("ir_swizzle @ %p specifies a channel not present "
+ "in the value.\n", (void *) ir);
+ ir->print();
+ abort();
+ }
+ }
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_validate::visit(ir_variable *ir)
+{
+ /* An ir_variable is the one thing that can (and will) appear multiple times
+ * in an IR tree. It is added to the hashtable so that it can be used
+ * in the ir_dereference_variable handler to ensure that a variable is
+ * declared before it is dereferenced.
+ */
+ if (ir->name)
+ assert(ralloc_parent(ir->name) == ir);
+
+ hash_table_insert(ht, ir, ir);
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_validate::visit_enter(ir_assignment *ir)
+{
+ const ir_dereference *const lhs = ir->lhs;
+ if (lhs->type->is_scalar() || lhs->type->is_vector()) {
+ if (ir->write_mask == 0) {
+ printf("Assignment LHS is %s, but write mask is 0:\n",
+ lhs->type->is_scalar() ? "scalar" : "vector");
+ ir->print();
+ abort();
+ }
+
+ int lhs_components = 0;
+ for (int i = 0; i < 4; i++) {
+ if (ir->write_mask & (1 << i))
+ lhs_components++;
+ }
+
+ if (lhs_components != ir->rhs->type->vector_elements) {
+ printf("Assignment count of LHS write mask channels enabled not\n"
+ "matching RHS vector size (%d LHS, %d RHS).\n",
+ lhs_components, ir->rhs->type->vector_elements);
+ ir->print();
+ abort();
+ }
+ }
+
+ this->validate_ir(ir, this->data);
+
+ return visit_continue;
+}
+
+void
+ir_validate::validate_ir(ir_instruction *ir, void *data)
+{
+ struct hash_table *ht = (struct hash_table *) data;
+
+ if (hash_table_find(ht, ir)) {
+ printf("Instruction node present twice in ir tree:\n");
+ ir->print();
+ printf("\n");
+ abort();
+ }
+ hash_table_insert(ht, ir, ir);
+}
+
+void
+check_node_type(ir_instruction *ir, void *data)
+{
+ (void) data;
+
+ if (ir->ir_type <= ir_type_unset || ir->ir_type >= ir_type_max) {
+ printf("Instruction node with unset type\n");
+ ir->print(); printf("\n");
+ }
+ assert(ir->type != glsl_type::error_type);
+}
+
+void
+validate_ir_tree(exec_list *instructions)
+{
+ ir_validate v;
+
+ v.run(instructions);
+
+ foreach_iter(exec_list_iterator, iter, *instructions) {
+ ir_instruction *ir = (ir_instruction *)iter.get();
+
+ visit_tree(ir, check_node_type, NULL);
+ }
+}
diff --git a/mesalib/src/glsl/link_functions.cpp b/mesalib/src/glsl/link_functions.cpp
index 5851c14d6..bc8758438 100644
--- a/mesalib/src/glsl/link_functions.cpp
+++ b/mesalib/src/glsl/link_functions.cpp
@@ -1,266 +1,266 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include "main/core.h"
-#include "glsl_symbol_table.h"
-#include "glsl_parser_extras.h"
-#include "ir.h"
-#include "program.h"
-#include "program/hash_table.h"
-#include "linker.h"
-
-static ir_function_signature *
-find_matching_signature(const char *name, const exec_list *actual_parameters,
- gl_shader **shader_list, unsigned num_shaders);
-
-class call_link_visitor : public ir_hierarchical_visitor {
-public:
- call_link_visitor(gl_shader_program *prog, gl_shader *linked,
- gl_shader **shader_list, unsigned num_shaders)
- {
- this->prog = prog;
- this->shader_list = shader_list;
- this->num_shaders = num_shaders;
- this->success = true;
- this->linked = linked;
-
- this->locals = hash_table_ctor(0, hash_table_pointer_hash,
- hash_table_pointer_compare);
- }
-
- ~call_link_visitor()
- {
- hash_table_dtor(this->locals);
- }
-
- virtual ir_visitor_status visit(ir_variable *ir)
- {
- hash_table_insert(locals, ir, ir);
- return visit_continue;
- }
-
- virtual ir_visitor_status visit_enter(ir_call *ir)
- {
- /* If ir is an ir_call from a function that was imported from another
- * shader callee will point to an ir_function_signature in the original
- * shader. In this case the function signature MUST NOT BE MODIFIED.
- * Doing so will modify the original shader. This may prevent that
- * shader from being linkable in other programs.
- */
- const ir_function_signature *const callee = ir->get_callee();
- assert(callee != NULL);
- const char *const name = callee->function_name();
-
- /* Determine if the requested function signature already exists in the
- * final linked shader. If it does, use it as the target of the call.
- */
- ir_function_signature *sig =
- find_matching_signature(name, &callee->parameters, &linked, 1);
- if (sig != NULL) {
- ir->set_callee(sig);
- return visit_continue;
- }
-
- /* Try to find the signature in one of the other shaders that is being
- * linked. If it's not found there, return an error.
- */
- sig = find_matching_signature(name, &ir->actual_parameters, shader_list,
- num_shaders);
- if (sig == NULL) {
- /* FINISHME: Log the full signature of unresolved function.
- */
- linker_error_printf(this->prog, "unresolved reference to function "
- "`%s'\n", name);
- this->success = false;
- return visit_stop;
- }
-
- /* Find the prototype information in the linked shader. Generate any
- * details that may be missing.
- */
- ir_function *f = linked->symbols->get_function(name);
- if (f == NULL)
- f = new(linked) ir_function(name);
-
- ir_function_signature *linked_sig =
- f->exact_matching_signature(&callee->parameters);
- if (linked_sig == NULL) {
- linked_sig = new(linked) ir_function_signature(callee->return_type);
- f->add_signature(linked_sig);
- }
-
- /* At this point linked_sig and called may be the same. If ir is an
- * ir_call from linked then linked_sig and callee will be
- * ir_function_signatures that have no definitions (is_defined is false).
- */
- assert(!linked_sig->is_defined);
- assert(linked_sig->body.is_empty());
-
- /* Create an in-place clone of the function definition. This multistep
- * process introduces some complexity here, but it has some advantages.
- * The parameter list and the and function body are cloned separately.
- * The clone of the parameter list is used to prime the hashtable used
- * to replace variable references in the cloned body.
- *
- * The big advantage is that the ir_function_signature does not change.
- * This means that we don't have to process the rest of the IR tree to
- * patch ir_call nodes. In addition, there is no way to remove or
- * replace signature stored in a function. One could easily be added,
- * but this avoids the need.
- */
- struct hash_table *ht = hash_table_ctor(0, hash_table_pointer_hash,
- hash_table_pointer_compare);
- exec_list formal_parameters;
- foreach_list_const(node, &sig->parameters) {
- const ir_instruction *const original = (ir_instruction *) node;
- assert(const_cast<ir_instruction *>(original)->as_variable());
-
- ir_instruction *copy = original->clone(linked, ht);
- formal_parameters.push_tail(copy);
- }
-
- linked_sig->replace_parameters(&formal_parameters);
-
- foreach_list_const(node, &sig->body) {
- const ir_instruction *const original = (ir_instruction *) node;
-
- ir_instruction *copy = original->clone(linked, ht);
- linked_sig->body.push_tail(copy);
- }
-
- linked_sig->is_defined = true;
- hash_table_dtor(ht);
-
- /* Patch references inside the function to things outside the function
- * (i.e., function calls and global variables).
- */
- linked_sig->accept(this);
-
- ir->set_callee(linked_sig);
-
- return visit_continue;
- }
-
- virtual ir_visitor_status visit(ir_dereference_variable *ir)
- {
- if (hash_table_find(locals, ir->var) == NULL) {
- /* The non-function variable must be a global, so try to find the
- * variable in the shader's symbol table. If the variable is not
- * found, then it's a global that *MUST* be defined in the original
- * shader.
- */
- ir_variable *var = linked->symbols->get_variable(ir->var->name);
- if (var == NULL) {
- /* Clone the ir_variable that the dereference already has and add
- * it to the linked shader.
- */
- var = ir->var->clone(linked, NULL);
- linked->symbols->add_variable(var);
- linked->ir->push_head(var);
- } else if (var->type->is_array()) {
- /* It is possible to have a global array declared in multiple
- * shaders without a size. The array is implicitly sized by the
- * maximal access to it in *any* shader. Because of this, we
- * need to track the maximal access to the array as linking pulls
- * more functions in that access the array.
- */
- var->max_array_access =
- MAX2(var->max_array_access, ir->var->max_array_access);
-
- if (var->type->length == 0 && ir->var->type->length != 0)
- var->type = ir->var->type;
- }
-
- ir->var = var;
- }
-
- return visit_continue;
- }
-
- /** Was function linking successful? */
- bool success;
-
-private:
- /**
- * Shader program being linked
- *
- * This is only used for logging error messages.
- */
- gl_shader_program *prog;
-
- /** List of shaders available for linking. */
- gl_shader **shader_list;
-
- /** Number of shaders available for linking. */
- unsigned num_shaders;
-
- /**
- * Final linked shader
- *
- * This is used two ways. It is used to find global variables in the
- * linked shader that are accessed by the function. It is also used to add
- * global variables from the shader where the function originated.
- */
- gl_shader *linked;
-
- /**
- * Table of variables local to the function.
- */
- hash_table *locals;
-};
-
-
-/**
- * Searches a list of shaders for a particular function definition
- */
-ir_function_signature *
-find_matching_signature(const char *name, const exec_list *actual_parameters,
- gl_shader **shader_list, unsigned num_shaders)
-{
- for (unsigned i = 0; i < num_shaders; i++) {
- ir_function *const f = shader_list[i]->symbols->get_function(name);
-
- if (f == NULL)
- continue;
-
- ir_function_signature *sig = f->matching_signature(actual_parameters);
-
- if ((sig == NULL) || !sig->is_defined)
- continue;
-
- return sig;
- }
-
- return NULL;
-}
-
-
-bool
-link_function_calls(gl_shader_program *prog, gl_shader *main,
- gl_shader **shader_list, unsigned num_shaders)
-{
- call_link_visitor v(prog, main, shader_list, num_shaders);
-
- v.run(main->ir);
- return v.success;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "main/core.h"
+#include "glsl_symbol_table.h"
+#include "glsl_parser_extras.h"
+#include "ir.h"
+#include "program.h"
+#include "program/hash_table.h"
+#include "linker.h"
+
+static ir_function_signature *
+find_matching_signature(const char *name, const exec_list *actual_parameters,
+ gl_shader **shader_list, unsigned num_shaders);
+
+class call_link_visitor : public ir_hierarchical_visitor {
+public:
+ call_link_visitor(gl_shader_program *prog, gl_shader *linked,
+ gl_shader **shader_list, unsigned num_shaders)
+ {
+ this->prog = prog;
+ this->shader_list = shader_list;
+ this->num_shaders = num_shaders;
+ this->success = true;
+ this->linked = linked;
+
+ this->locals = hash_table_ctor(0, hash_table_pointer_hash,
+ hash_table_pointer_compare);
+ }
+
+ ~call_link_visitor()
+ {
+ hash_table_dtor(this->locals);
+ }
+
+ virtual ir_visitor_status visit(ir_variable *ir)
+ {
+ hash_table_insert(locals, ir, ir);
+ return visit_continue;
+ }
+
+ virtual ir_visitor_status visit_enter(ir_call *ir)
+ {
+ /* If ir is an ir_call from a function that was imported from another
+ * shader callee will point to an ir_function_signature in the original
+ * shader. In this case the function signature MUST NOT BE MODIFIED.
+ * Doing so will modify the original shader. This may prevent that
+ * shader from being linkable in other programs.
+ */
+ const ir_function_signature *const callee = ir->get_callee();
+ assert(callee != NULL);
+ const char *const name = callee->function_name();
+
+ /* Determine if the requested function signature already exists in the
+ * final linked shader. If it does, use it as the target of the call.
+ */
+ ir_function_signature *sig =
+ find_matching_signature(name, &callee->parameters, &linked, 1);
+ if (sig != NULL) {
+ ir->set_callee(sig);
+ return visit_continue;
+ }
+
+ /* Try to find the signature in one of the other shaders that is being
+ * linked. If it's not found there, return an error.
+ */
+ sig = find_matching_signature(name, &ir->actual_parameters, shader_list,
+ num_shaders);
+ if (sig == NULL) {
+ /* FINISHME: Log the full signature of unresolved function.
+ */
+ linker_error_printf(this->prog, "unresolved reference to function "
+ "`%s'\n", name);
+ this->success = false;
+ return visit_stop;
+ }
+
+ /* Find the prototype information in the linked shader. Generate any
+ * details that may be missing.
+ */
+ ir_function *f = linked->symbols->get_function(name);
+ if (f == NULL)
+ f = new(linked) ir_function(name);
+
+ ir_function_signature *linked_sig =
+ f->exact_matching_signature(&callee->parameters);
+ if (linked_sig == NULL) {
+ linked_sig = new(linked) ir_function_signature(callee->return_type);
+ f->add_signature(linked_sig);
+ }
+
+ /* At this point linked_sig and called may be the same. If ir is an
+ * ir_call from linked then linked_sig and callee will be
+ * ir_function_signatures that have no definitions (is_defined is false).
+ */
+ assert(!linked_sig->is_defined);
+ assert(linked_sig->body.is_empty());
+
+ /* Create an in-place clone of the function definition. This multistep
+ * process introduces some complexity here, but it has some advantages.
+ * The parameter list and the and function body are cloned separately.
+ * The clone of the parameter list is used to prime the hashtable used
+ * to replace variable references in the cloned body.
+ *
+ * The big advantage is that the ir_function_signature does not change.
+ * This means that we don't have to process the rest of the IR tree to
+ * patch ir_call nodes. In addition, there is no way to remove or
+ * replace signature stored in a function. One could easily be added,
+ * but this avoids the need.
+ */
+ struct hash_table *ht = hash_table_ctor(0, hash_table_pointer_hash,
+ hash_table_pointer_compare);
+ exec_list formal_parameters;
+ foreach_list_const(node, &sig->parameters) {
+ const ir_instruction *const original = (ir_instruction *) node;
+ assert(const_cast<ir_instruction *>(original)->as_variable());
+
+ ir_instruction *copy = original->clone(linked, ht);
+ formal_parameters.push_tail(copy);
+ }
+
+ linked_sig->replace_parameters(&formal_parameters);
+
+ foreach_list_const(node, &sig->body) {
+ const ir_instruction *const original = (ir_instruction *) node;
+
+ ir_instruction *copy = original->clone(linked, ht);
+ linked_sig->body.push_tail(copy);
+ }
+
+ linked_sig->is_defined = true;
+ hash_table_dtor(ht);
+
+ /* Patch references inside the function to things outside the function
+ * (i.e., function calls and global variables).
+ */
+ linked_sig->accept(this);
+
+ ir->set_callee(linked_sig);
+
+ return visit_continue;
+ }
+
+ virtual ir_visitor_status visit(ir_dereference_variable *ir)
+ {
+ if (hash_table_find(locals, ir->var) == NULL) {
+ /* The non-function variable must be a global, so try to find the
+ * variable in the shader's symbol table. If the variable is not
+ * found, then it's a global that *MUST* be defined in the original
+ * shader.
+ */
+ ir_variable *var = linked->symbols->get_variable(ir->var->name);
+ if (var == NULL) {
+ /* Clone the ir_variable that the dereference already has and add
+ * it to the linked shader.
+ */
+ var = ir->var->clone(linked, NULL);
+ linked->symbols->add_variable(var);
+ linked->ir->push_head(var);
+ } else if (var->type->is_array()) {
+ /* It is possible to have a global array declared in multiple
+ * shaders without a size. The array is implicitly sized by the
+ * maximal access to it in *any* shader. Because of this, we
+ * need to track the maximal access to the array as linking pulls
+ * more functions in that access the array.
+ */
+ var->max_array_access =
+ MAX2(var->max_array_access, ir->var->max_array_access);
+
+ if (var->type->length == 0 && ir->var->type->length != 0)
+ var->type = ir->var->type;
+ }
+
+ ir->var = var;
+ }
+
+ return visit_continue;
+ }
+
+ /** Was function linking successful? */
+ bool success;
+
+private:
+ /**
+ * Shader program being linked
+ *
+ * This is only used for logging error messages.
+ */
+ gl_shader_program *prog;
+
+ /** List of shaders available for linking. */
+ gl_shader **shader_list;
+
+ /** Number of shaders available for linking. */
+ unsigned num_shaders;
+
+ /**
+ * Final linked shader
+ *
+ * This is used two ways. It is used to find global variables in the
+ * linked shader that are accessed by the function. It is also used to add
+ * global variables from the shader where the function originated.
+ */
+ gl_shader *linked;
+
+ /**
+ * Table of variables local to the function.
+ */
+ hash_table *locals;
+};
+
+
+/**
+ * Searches a list of shaders for a particular function definition
+ */
+ir_function_signature *
+find_matching_signature(const char *name, const exec_list *actual_parameters,
+ gl_shader **shader_list, unsigned num_shaders)
+{
+ for (unsigned i = 0; i < num_shaders; i++) {
+ ir_function *const f = shader_list[i]->symbols->get_function(name);
+
+ if (f == NULL)
+ continue;
+
+ ir_function_signature *sig = f->matching_signature(actual_parameters);
+
+ if ((sig == NULL) || !sig->is_defined)
+ continue;
+
+ return sig;
+ }
+
+ return NULL;
+}
+
+
+bool
+link_function_calls(gl_shader_program *prog, gl_shader *main,
+ gl_shader **shader_list, unsigned num_shaders)
+{
+ call_link_visitor v(prog, main, shader_list, num_shaders);
+
+ v.run(main->ir);
+ return v.success;
+}
diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp
index 7db5c5e8d..7760b4f2c 100644
--- a/mesalib/src/glsl/linker.cpp
+++ b/mesalib/src/glsl/linker.cpp
@@ -1,1709 +1,1709 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file linker.cpp
- * GLSL linker implementation
- *
- * Given a set of shaders that are to be linked to generate a final program,
- * there are three distinct stages.
- *
- * In the first stage shaders are partitioned into groups based on the shader
- * type. All shaders of a particular type (e.g., vertex shaders) are linked
- * together.
- *
- * - Undefined references in each shader are resolve to definitions in
- * another shader.
- * - Types and qualifiers of uniforms, outputs, and global variables defined
- * in multiple shaders with the same name are verified to be the same.
- * - Initializers for uniforms and global variables defined
- * in multiple shaders with the same name are verified to be the same.
- *
- * The result, in the terminology of the GLSL spec, is a set of shader
- * executables for each processing unit.
- *
- * After the first stage is complete, a series of semantic checks are performed
- * on each of the shader executables.
- *
- * - Each shader executable must define a \c main function.
- * - Each vertex shader executable must write to \c gl_Position.
- * - Each fragment shader executable must write to either \c gl_FragData or
- * \c gl_FragColor.
- *
- * In the final stage individual shader executables are linked to create a
- * complete exectuable.
- *
- * - Types of uniforms defined in multiple shader stages with the same name
- * are verified to be the same.
- * - Initializers for uniforms defined in multiple shader stages with the
- * same name are verified to be the same.
- * - Types and qualifiers of outputs defined in one stage are verified to
- * be the same as the types and qualifiers of inputs defined with the same
- * name in a later stage.
- *
- * \author Ian Romanick <ian.d.romanick@intel.com>
- */
-
-#include "main/core.h"
-#include "glsl_symbol_table.h"
-#include "ir.h"
-#include "program.h"
-#include "program/hash_table.h"
-#include "linker.h"
-#include "ir_optimization.h"
-
-extern "C" {
-#include "main/shaderobj.h"
-}
-
-/**
- * Visitor that determines whether or not a variable is ever written.
- */
-class find_assignment_visitor : public ir_hierarchical_visitor {
-public:
- find_assignment_visitor(const char *name)
- : name(name), found(false)
- {
- /* empty */
- }
-
- virtual ir_visitor_status visit_enter(ir_assignment *ir)
- {
- ir_variable *const var = ir->lhs->variable_referenced();
-
- if (strcmp(name, var->name) == 0) {
- found = true;
- return visit_stop;
- }
-
- return visit_continue_with_parent;
- }
-
- virtual ir_visitor_status visit_enter(ir_call *ir)
- {
- exec_list_iterator sig_iter = ir->get_callee()->parameters.iterator();
- foreach_iter(exec_list_iterator, iter, *ir) {
- ir_rvalue *param_rval = (ir_rvalue *)iter.get();
- ir_variable *sig_param = (ir_variable *)sig_iter.get();
-
- if (sig_param->mode == ir_var_out ||
- sig_param->mode == ir_var_inout) {
- ir_variable *var = param_rval->variable_referenced();
- if (var && strcmp(name, var->name) == 0) {
- found = true;
- return visit_stop;
- }
- }
- sig_iter.next();
- }
-
- return visit_continue_with_parent;
- }
-
- bool variable_found()
- {
- return found;
- }
-
-private:
- const char *name; /**< Find writes to a variable with this name. */
- bool found; /**< Was a write to the variable found? */
-};
-
-
-/**
- * Visitor that determines whether or not a variable is ever read.
- */
-class find_deref_visitor : public ir_hierarchical_visitor {
-public:
- find_deref_visitor(const char *name)
- : name(name), found(false)
- {
- /* empty */
- }
-
- virtual ir_visitor_status visit(ir_dereference_variable *ir)
- {
- if (strcmp(this->name, ir->var->name) == 0) {
- this->found = true;
- return visit_stop;
- }
-
- return visit_continue;
- }
-
- bool variable_found() const
- {
- return this->found;
- }
-
-private:
- const char *name; /**< Find writes to a variable with this name. */
- bool found; /**< Was a write to the variable found? */
-};
-
-
-void
-linker_error_printf(gl_shader_program *prog, const char *fmt, ...)
-{
- va_list ap;
-
- ralloc_strcat(&prog->InfoLog, "error: ");
- va_start(ap, fmt);
- ralloc_vasprintf_append(&prog->InfoLog, fmt, ap);
- va_end(ap);
-}
-
-
-void
-invalidate_variable_locations(gl_shader *sh, enum ir_variable_mode mode,
- int generic_base)
-{
- foreach_list(node, sh->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
- if ((var == NULL) || (var->mode != (unsigned) mode))
- continue;
-
- /* Only assign locations for generic attributes / varyings / etc.
- */
- if ((var->location >= generic_base) && !var->explicit_location)
- var->location = -1;
- }
-}
-
-
-/**
- * Determine the number of attribute slots required for a particular type
- *
- * This code is here because it implements the language rules of a specific
- * GLSL version. Since it's a property of the language and not a property of
- * types in general, it doesn't really belong in glsl_type.
- */
-unsigned
-count_attribute_slots(const glsl_type *t)
-{
- /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
- *
- * "A scalar input counts the same amount against this limit as a vec4,
- * so applications may want to consider packing groups of four
- * unrelated float inputs together into a vector to better utilize the
- * capabilities of the underlying hardware. A matrix input will use up
- * multiple locations. The number of locations used will equal the
- * number of columns in the matrix."
- *
- * The spec does not explicitly say how arrays are counted. However, it
- * should be safe to assume the total number of slots consumed by an array
- * is the number of entries in the array multiplied by the number of slots
- * consumed by a single element of the array.
- */
-
- if (t->is_array())
- return t->array_size() * count_attribute_slots(t->element_type());
-
- if (t->is_matrix())
- return t->matrix_columns;
-
- return 1;
-}
-
-
-/**
- * Verify that a vertex shader executable meets all semantic requirements
- *
- * \param shader Vertex shader executable to be verified
- */
-bool
-validate_vertex_shader_executable(struct gl_shader_program *prog,
- struct gl_shader *shader)
-{
- if (shader == NULL)
- return true;
-
- find_assignment_visitor find("gl_Position");
- find.run(shader->ir);
- if (!find.variable_found()) {
- linker_error_printf(prog,
- "vertex shader does not write to `gl_Position'\n");
- return false;
- }
-
- return true;
-}
-
-
-/**
- * Verify that a fragment shader executable meets all semantic requirements
- *
- * \param shader Fragment shader executable to be verified
- */
-bool
-validate_fragment_shader_executable(struct gl_shader_program *prog,
- struct gl_shader *shader)
-{
- if (shader == NULL)
- return true;
-
- find_assignment_visitor frag_color("gl_FragColor");
- find_assignment_visitor frag_data("gl_FragData");
-
- frag_color.run(shader->ir);
- frag_data.run(shader->ir);
-
- if (frag_color.variable_found() && frag_data.variable_found()) {
- linker_error_printf(prog, "fragment shader writes to both "
- "`gl_FragColor' and `gl_FragData'\n");
- return false;
- }
-
- return true;
-}
-
-
-/**
- * Generate a string describing the mode of a variable
- */
-static const char *
-mode_string(const ir_variable *var)
-{
- switch (var->mode) {
- case ir_var_auto:
- return (var->read_only) ? "global constant" : "global variable";
-
- case ir_var_uniform: return "uniform";
- case ir_var_in: return "shader input";
- case ir_var_out: return "shader output";
- case ir_var_inout: return "shader inout";
-
- case ir_var_const_in:
- case ir_var_temporary:
- default:
- assert(!"Should not get here.");
- return "invalid variable";
- }
-}
-
-
-/**
- * Perform validation of global variables used across multiple shaders
- */
-bool
-cross_validate_globals(struct gl_shader_program *prog,
- struct gl_shader **shader_list,
- unsigned num_shaders,
- bool uniforms_only)
-{
- /* Examine all of the uniforms in all of the shaders and cross validate
- * them.
- */
- glsl_symbol_table variables;
- for (unsigned i = 0; i < num_shaders; i++) {
- if (shader_list[i] == NULL)
- continue;
-
- foreach_list(node, shader_list[i]->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
- if (var == NULL)
- continue;
-
- if (uniforms_only && (var->mode != ir_var_uniform))
- continue;
-
- /* Don't cross validate temporaries that are at global scope. These
- * will eventually get pulled into the shaders 'main'.
- */
- if (var->mode == ir_var_temporary)
- continue;
-
- /* If a global with this name has already been seen, verify that the
- * new instance has the same type. In addition, if the globals have
- * initializers, the values of the initializers must be the same.
- */
- ir_variable *const existing = variables.get_variable(var->name);
- if (existing != NULL) {
- if (var->type != existing->type) {
- /* Consider the types to be "the same" if both types are arrays
- * of the same type and one of the arrays is implicitly sized.
- * In addition, set the type of the linked variable to the
- * explicitly sized array.
- */
- if (var->type->is_array()
- && existing->type->is_array()
- && (var->type->fields.array == existing->type->fields.array)
- && ((var->type->length == 0)
- || (existing->type->length == 0))) {
- if (var->type->length != 0) {
- existing->type = var->type;
- }
- } else {
- linker_error_printf(prog, "%s `%s' declared as type "
- "`%s' and type `%s'\n",
- mode_string(var),
- var->name, var->type->name,
- existing->type->name);
- return false;
- }
- }
-
- if (var->explicit_location) {
- if (existing->explicit_location
- && (var->location != existing->location)) {
- linker_error_printf(prog, "explicit locations for %s "
- "`%s' have differing values\n",
- mode_string(var), var->name);
- return false;
- }
-
- existing->location = var->location;
- existing->explicit_location = true;
- }
-
- /* Validate layout qualifiers for gl_FragDepth.
- *
- * From the AMD_conservative_depth spec:
- * "If gl_FragDepth is redeclared in any fragment shader in
- * a program, it must be redeclared in all fragment shaders in that
- * program that have static assignments to gl_FragDepth. All
- * redeclarations of gl_FragDepth in all fragment shaders in
- * a single program must have the same set of qualifiers."
- */
- if (strcmp(var->name, "gl_FragDepth") == 0) {
- bool layout_declared = var->depth_layout != ir_depth_layout_none;
- bool layout_differs = var->depth_layout != existing->depth_layout;
- if (layout_declared && layout_differs) {
- linker_error_printf(prog,
- "All redeclarations of gl_FragDepth in all fragment shaders "
- "in a single program must have the same set of qualifiers.");
- }
- if (var->used && layout_differs) {
- linker_error_printf(prog,
- "If gl_FragDepth is redeclared with a layout qualifier in"
- "any fragment shader, it must be redeclared with the same"
- "layout qualifier in all fragment shaders that have"
- "assignments to gl_FragDepth");
- }
- }
-
- /* FINISHME: Handle non-constant initializers.
- */
- if (var->constant_value != NULL) {
- if (existing->constant_value != NULL) {
- if (!var->constant_value->has_value(existing->constant_value)) {
- linker_error_printf(prog, "initializers for %s "
- "`%s' have differing values\n",
- mode_string(var), var->name);
- return false;
- }
- } else
- /* If the first-seen instance of a particular uniform did not
- * have an initializer but a later instance does, copy the
- * initializer to the version stored in the symbol table.
- */
- /* FINISHME: This is wrong. The constant_value field should
- * FINISHME: not be modified! Imagine a case where a shader
- * FINISHME: without an initializer is linked in two different
- * FINISHME: programs with shaders that have differing
- * FINISHME: initializers. Linking with the first will
- * FINISHME: modify the shader, and linking with the second
- * FINISHME: will fail.
- */
- existing->constant_value =
- var->constant_value->clone(ralloc_parent(existing), NULL);
- }
-
- if (existing->invariant != var->invariant) {
- linker_error_printf(prog, "declarations for %s `%s' have "
- "mismatching invariant qualifiers\n",
- mode_string(var), var->name);
- return false;
- }
- if (existing->centroid != var->centroid) {
- linker_error_printf(prog, "declarations for %s `%s' have "
- "mismatching centroid qualifiers\n",
- mode_string(var), var->name);
- return false;
- }
- } else
- variables.add_variable(var);
- }
- }
-
- return true;
-}
-
-
-/**
- * Perform validation of uniforms used across multiple shader stages
- */
-bool
-cross_validate_uniforms(struct gl_shader_program *prog)
-{
- return cross_validate_globals(prog, prog->_LinkedShaders,
- MESA_SHADER_TYPES, true);
-}
-
-
-/**
- * Validate that outputs from one stage match inputs of another
- */
-bool
-cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
- gl_shader *producer, gl_shader *consumer)
-{
- glsl_symbol_table parameters;
- /* FINISHME: Figure these out dynamically. */
- const char *const producer_stage = "vertex";
- const char *const consumer_stage = "fragment";
-
- /* Find all shader outputs in the "producer" stage.
- */
- foreach_list(node, producer->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
- /* FINISHME: For geometry shaders, this should also look for inout
- * FINISHME: variables.
- */
- if ((var == NULL) || (var->mode != ir_var_out))
- continue;
-
- parameters.add_variable(var);
- }
-
-
- /* Find all shader inputs in the "consumer" stage. Any variables that have
- * matching outputs already in the symbol table must have the same type and
- * qualifiers.
- */
- foreach_list(node, consumer->ir) {
- ir_variable *const input = ((ir_instruction *) node)->as_variable();
-
- /* FINISHME: For geometry shaders, this should also look for inout
- * FINISHME: variables.
- */
- if ((input == NULL) || (input->mode != ir_var_in))
- continue;
-
- ir_variable *const output = parameters.get_variable(input->name);
- if (output != NULL) {
- /* Check that the types match between stages.
- */
- if (input->type != output->type) {
- /* There is a bit of a special case for gl_TexCoord. This
- * built-in is unsized by default. Appliations that variable
- * access it must redeclare it with a size. There is some
- * language in the GLSL spec that implies the fragment shader
- * and vertex shader do not have to agree on this size. Other
- * driver behave this way, and one or two applications seem to
- * rely on it.
- *
- * Neither declaration needs to be modified here because the array
- * sizes are fixed later when update_array_sizes is called.
- *
- * From page 48 (page 54 of the PDF) of the GLSL 1.10 spec:
- *
- * "Unlike user-defined varying variables, the built-in
- * varying variables don't have a strict one-to-one
- * correspondence between the vertex language and the
- * fragment language."
- */
- if (!output->type->is_array()
- || (strncmp("gl_", output->name, 3) != 0)) {
- linker_error_printf(prog,
- "%s shader output `%s' declared as "
- "type `%s', but %s shader input declared "
- "as type `%s'\n",
- producer_stage, output->name,
- output->type->name,
- consumer_stage, input->type->name);
- return false;
- }
- }
-
- /* Check that all of the qualifiers match between stages.
- */
- if (input->centroid != output->centroid) {
- linker_error_printf(prog,
- "%s shader output `%s' %s centroid qualifier, "
- "but %s shader input %s centroid qualifier\n",
- producer_stage,
- output->name,
- (output->centroid) ? "has" : "lacks",
- consumer_stage,
- (input->centroid) ? "has" : "lacks");
- return false;
- }
-
- if (input->invariant != output->invariant) {
- linker_error_printf(prog,
- "%s shader output `%s' %s invariant qualifier, "
- "but %s shader input %s invariant qualifier\n",
- producer_stage,
- output->name,
- (output->invariant) ? "has" : "lacks",
- consumer_stage,
- (input->invariant) ? "has" : "lacks");
- return false;
- }
-
- if (input->interpolation != output->interpolation) {
- linker_error_printf(prog,
- "%s shader output `%s' specifies %s "
- "interpolation qualifier, "
- "but %s shader input specifies %s "
- "interpolation qualifier\n",
- producer_stage,
- output->name,
- output->interpolation_string(),
- consumer_stage,
- input->interpolation_string());
- return false;
- }
- }
- }
-
- return true;
-}
-
-
-/**
- * Populates a shaders symbol table with all global declarations
- */
-static void
-populate_symbol_table(gl_shader *sh)
-{
- sh->symbols = new(sh) glsl_symbol_table;
-
- foreach_list(node, sh->ir) {
- ir_instruction *const inst = (ir_instruction *) node;
- ir_variable *var;
- ir_function *func;
-
- if ((func = inst->as_function()) != NULL) {
- sh->symbols->add_function(func);
- } else if ((var = inst->as_variable()) != NULL) {
- sh->symbols->add_variable(var);
- }
- }
-}
-
-
-/**
- * Remap variables referenced in an instruction tree
- *
- * This is used when instruction trees are cloned from one shader and placed in
- * another. These trees will contain references to \c ir_variable nodes that
- * do not exist in the target shader. This function finds these \c ir_variable
- * references and replaces the references with matching variables in the target
- * shader.
- *
- * If there is no matching variable in the target shader, a clone of the
- * \c ir_variable is made and added to the target shader. The new variable is
- * added to \b both the instruction stream and the symbol table.
- *
- * \param inst IR tree that is to be processed.
- * \param symbols Symbol table containing global scope symbols in the
- * linked shader.
- * \param instructions Instruction stream where new variable declarations
- * should be added.
- */
-void
-remap_variables(ir_instruction *inst, struct gl_shader *target,
- hash_table *temps)
-{
- class remap_visitor : public ir_hierarchical_visitor {
- public:
- remap_visitor(struct gl_shader *target,
- hash_table *temps)
- {
- this->target = target;
- this->symbols = target->symbols;
- this->instructions = target->ir;
- this->temps = temps;
- }
-
- virtual ir_visitor_status visit(ir_dereference_variable *ir)
- {
- if (ir->var->mode == ir_var_temporary) {
- ir_variable *var = (ir_variable *) hash_table_find(temps, ir->var);
-
- assert(var != NULL);
- ir->var = var;
- return visit_continue;
- }
-
- ir_variable *const existing =
- this->symbols->get_variable(ir->var->name);
- if (existing != NULL)
- ir->var = existing;
- else {
- ir_variable *copy = ir->var->clone(this->target, NULL);
-
- this->symbols->add_variable(copy);
- this->instructions->push_head(copy);
- ir->var = copy;
- }
-
- return visit_continue;
- }
-
- private:
- struct gl_shader *target;
- glsl_symbol_table *symbols;
- exec_list *instructions;
- hash_table *temps;
- };
-
- remap_visitor v(target, temps);
-
- inst->accept(&v);
-}
-
-
-/**
- * Move non-declarations from one instruction stream to another
- *
- * The intended usage pattern of this function is to pass the pointer to the
- * head sentinel of a list (i.e., a pointer to the list cast to an \c exec_node
- * pointer) for \c last and \c false for \c make_copies on the first
- * call. Successive calls pass the return value of the previous call for
- * \c last and \c true for \c make_copies.
- *
- * \param instructions Source instruction stream
- * \param last Instruction after which new instructions should be
- * inserted in the target instruction stream
- * \param make_copies Flag selecting whether instructions in \c instructions
- * should be copied (via \c ir_instruction::clone) into the
- * target list or moved.
- *
- * \return
- * The new "last" instruction in the target instruction stream. This pointer
- * is suitable for use as the \c last parameter of a later call to this
- * function.
- */
-exec_node *
-move_non_declarations(exec_list *instructions, exec_node *last,
- bool make_copies, gl_shader *target)
-{
- hash_table *temps = NULL;
-
- if (make_copies)
- temps = hash_table_ctor(0, hash_table_pointer_hash,
- hash_table_pointer_compare);
-
- foreach_list_safe(node, instructions) {
- ir_instruction *inst = (ir_instruction *) node;
-
- if (inst->as_function())
- continue;
-
- ir_variable *var = inst->as_variable();
- if ((var != NULL) && (var->mode != ir_var_temporary))
- continue;
-
- assert(inst->as_assignment()
- || ((var != NULL) && (var->mode == ir_var_temporary)));
-
- if (make_copies) {
- inst = inst->clone(target, NULL);
-
- if (var != NULL)
- hash_table_insert(temps, inst, var);
- else
- remap_variables(inst, target, temps);
- } else {
- inst->remove();
- }
-
- last->insert_after(inst);
- last = inst;
- }
-
- if (make_copies)
- hash_table_dtor(temps);
-
- return last;
-}
-
-/**
- * Get the function signature for main from a shader
- */
-static ir_function_signature *
-get_main_function_signature(gl_shader *sh)
-{
- ir_function *const f = sh->symbols->get_function("main");
- if (f != NULL) {
- exec_list void_parameters;
-
- /* Look for the 'void main()' signature and ensure that it's defined.
- * This keeps the linker from accidentally pick a shader that just
- * contains a prototype for main.
- *
- * We don't have to check for multiple definitions of main (in multiple
- * shaders) because that would have already been caught above.
- */
- ir_function_signature *sig = f->matching_signature(&void_parameters);
- if ((sig != NULL) && sig->is_defined) {
- return sig;
- }
- }
-
- return NULL;
-}
-
-
-/**
- * Combine a group of shaders for a single stage to generate a linked shader
- *
- * \note
- * If this function is supplied a single shader, it is cloned, and the new
- * shader is returned.
- */
-static struct gl_shader *
-link_intrastage_shaders(void *mem_ctx,
- struct gl_context *ctx,
- struct gl_shader_program *prog,
- struct gl_shader **shader_list,
- unsigned num_shaders)
-{
- /* Check that global variables defined in multiple shaders are consistent.
- */
- if (!cross_validate_globals(prog, shader_list, num_shaders, false))
- return NULL;
-
- /* Check that there is only a single definition of each function signature
- * across all shaders.
- */
- for (unsigned i = 0; i < (num_shaders - 1); i++) {
- foreach_list(node, shader_list[i]->ir) {
- ir_function *const f = ((ir_instruction *) node)->as_function();
-
- if (f == NULL)
- continue;
-
- for (unsigned j = i + 1; j < num_shaders; j++) {
- ir_function *const other =
- shader_list[j]->symbols->get_function(f->name);
-
- /* If the other shader has no function (and therefore no function
- * signatures) with the same name, skip to the next shader.
- */
- if (other == NULL)
- continue;
-
- foreach_iter (exec_list_iterator, iter, *f) {
- ir_function_signature *sig =
- (ir_function_signature *) iter.get();
-
- if (!sig->is_defined || sig->is_builtin)
- continue;
-
- ir_function_signature *other_sig =
- other->exact_matching_signature(& sig->parameters);
-
- if ((other_sig != NULL) && other_sig->is_defined
- && !other_sig->is_builtin) {
- linker_error_printf(prog,
- "function `%s' is multiply defined",
- f->name);
- return NULL;
- }
- }
- }
- }
- }
-
- /* Find the shader that defines main, and make a clone of it.
- *
- * Starting with the clone, search for undefined references. If one is
- * found, find the shader that defines it. Clone the reference and add
- * it to the shader. Repeat until there are no undefined references or
- * until a reference cannot be resolved.
- */
- gl_shader *main = NULL;
- for (unsigned i = 0; i < num_shaders; i++) {
- if (get_main_function_signature(shader_list[i]) != NULL) {
- main = shader_list[i];
- break;
- }
- }
-
- if (main == NULL) {
- linker_error_printf(prog, "%s shader lacks `main'\n",
- (shader_list[0]->Type == GL_VERTEX_SHADER)
- ? "vertex" : "fragment");
- return NULL;
- }
-
- gl_shader *linked = ctx->Driver.NewShader(NULL, 0, main->Type);
- linked->ir = new(linked) exec_list;
- clone_ir_list(mem_ctx, linked->ir, main->ir);
-
- populate_symbol_table(linked);
-
- /* The a pointer to the main function in the final linked shader (i.e., the
- * copy of the original shader that contained the main function).
- */
- ir_function_signature *const main_sig = get_main_function_signature(linked);
-
- /* Move any instructions other than variable declarations or function
- * declarations into main.
- */
- exec_node *insertion_point =
- move_non_declarations(linked->ir, (exec_node *) &main_sig->body, false,
- linked);
-
- for (unsigned i = 0; i < num_shaders; i++) {
- if (shader_list[i] == main)
- continue;
-
- insertion_point = move_non_declarations(shader_list[i]->ir,
- insertion_point, true, linked);
- }
-
- /* Resolve initializers for global variables in the linked shader.
- */
- unsigned num_linking_shaders = num_shaders;
- for (unsigned i = 0; i < num_shaders; i++)
- num_linking_shaders += shader_list[i]->num_builtins_to_link;
-
- gl_shader **linking_shaders =
- (gl_shader **) calloc(num_linking_shaders, sizeof(gl_shader *));
-
- memcpy(linking_shaders, shader_list,
- sizeof(linking_shaders[0]) * num_shaders);
-
- unsigned idx = num_shaders;
- for (unsigned i = 0; i < num_shaders; i++) {
- memcpy(&linking_shaders[idx], shader_list[i]->builtins_to_link,
- sizeof(linking_shaders[0]) * shader_list[i]->num_builtins_to_link);
- idx += shader_list[i]->num_builtins_to_link;
- }
-
- assert(idx == num_linking_shaders);
-
- if (!link_function_calls(prog, linked, linking_shaders,
- num_linking_shaders)) {
- ctx->Driver.DeleteShader(ctx, linked);
- linked = NULL;
- }
-
- free(linking_shaders);
-
- /* Make a pass over all variable declarations to ensure that arrays with
- * unspecified sizes have a size specified. The size is inferred from the
- * max_array_access field.
- */
- if (linked != NULL) {
- class array_sizing_visitor : public ir_hierarchical_visitor {
- public:
- virtual ir_visitor_status visit(ir_variable *var)
- {
- if (var->type->is_array() && (var->type->length == 0)) {
- const glsl_type *type =
- glsl_type::get_array_instance(var->type->fields.array,
- var->max_array_access + 1);
-
- assert(type != NULL);
- var->type = type;
- }
-
- return visit_continue;
- }
- } v;
-
- v.run(linked->ir);
- }
-
- return linked;
-}
-
-
-struct uniform_node {
- exec_node link;
- struct gl_uniform *u;
- unsigned slots;
-};
-
-/**
- * Update the sizes of linked shader uniform arrays to the maximum
- * array index used.
- *
- * From page 81 (page 95 of the PDF) of the OpenGL 2.1 spec:
- *
- * If one or more elements of an array are active,
- * GetActiveUniform will return the name of the array in name,
- * subject to the restrictions listed above. The type of the array
- * is returned in type. The size parameter contains the highest
- * array element index used, plus one. The compiler or linker
- * determines the highest index used. There will be only one
- * active uniform reported by the GL per uniform array.
-
- */
-static void
-update_array_sizes(struct gl_shader_program *prog)
-{
- for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
- if (prog->_LinkedShaders[i] == NULL)
- continue;
-
- foreach_list(node, prog->_LinkedShaders[i]->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
- if ((var == NULL) || (var->mode != ir_var_uniform &&
- var->mode != ir_var_in &&
- var->mode != ir_var_out) ||
- !var->type->is_array())
- continue;
-
- unsigned int size = var->max_array_access;
- for (unsigned j = 0; j < MESA_SHADER_TYPES; j++) {
- if (prog->_LinkedShaders[j] == NULL)
- continue;
-
- foreach_list(node2, prog->_LinkedShaders[j]->ir) {
- ir_variable *other_var = ((ir_instruction *) node2)->as_variable();
- if (!other_var)
- continue;
-
- if (strcmp(var->name, other_var->name) == 0 &&
- other_var->max_array_access > size) {
- size = other_var->max_array_access;
- }
- }
- }
-
- if (size + 1 != var->type->fields.array->length) {
- var->type = glsl_type::get_array_instance(var->type->fields.array,
- size + 1);
- /* FINISHME: We should update the types of array
- * dereferences of this variable now.
- */
- }
- }
- }
-}
-
-static void
-add_uniform(void *mem_ctx, exec_list *uniforms, struct hash_table *ht,
- const char *name, const glsl_type *type, GLenum shader_type,
- unsigned *next_shader_pos, unsigned *total_uniforms)
-{
- if (type->is_record()) {
- for (unsigned int i = 0; i < type->length; i++) {
- const glsl_type *field_type = type->fields.structure[i].type;
- char *field_name = ralloc_asprintf(mem_ctx, "%s.%s", name,
- type->fields.structure[i].name);
-
- add_uniform(mem_ctx, uniforms, ht, field_name, field_type,
- shader_type, next_shader_pos, total_uniforms);
- }
- } else {
- uniform_node *n = (uniform_node *) hash_table_find(ht, name);
- unsigned int vec4_slots;
- const glsl_type *array_elem_type = NULL;
-
- if (type->is_array()) {
- array_elem_type = type->fields.array;
- /* Array of structures. */
- if (array_elem_type->is_record()) {
- for (unsigned int i = 0; i < type->length; i++) {
- char *elem_name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i);
- add_uniform(mem_ctx, uniforms, ht, elem_name, array_elem_type,
- shader_type, next_shader_pos, total_uniforms);
- }
- return;
- }
- }
-
- /* Fix the storage size of samplers at 1 vec4 each. Be sure to pad out
- * vectors to vec4 slots.
- */
- if (type->is_array()) {
- if (array_elem_type->is_sampler())
- vec4_slots = type->length;
- else
- vec4_slots = type->length * array_elem_type->matrix_columns;
- } else if (type->is_sampler()) {
- vec4_slots = 1;
- } else {
- vec4_slots = type->matrix_columns;
- }
-
- if (n == NULL) {
- n = (uniform_node *) calloc(1, sizeof(struct uniform_node));
- n->u = (gl_uniform *) calloc(1, sizeof(struct gl_uniform));
- n->slots = vec4_slots;
-
- n->u->Name = strdup(name);
- n->u->Type = type;
- n->u->VertPos = -1;
- n->u->FragPos = -1;
- n->u->GeomPos = -1;
- (*total_uniforms)++;
-
- hash_table_insert(ht, n, name);
- uniforms->push_tail(& n->link);
- }
-
- switch (shader_type) {
- case GL_VERTEX_SHADER:
- n->u->VertPos = *next_shader_pos;
- break;
- case GL_FRAGMENT_SHADER:
- n->u->FragPos = *next_shader_pos;
- break;
- case GL_GEOMETRY_SHADER:
- n->u->GeomPos = *next_shader_pos;
- break;
- }
-
- (*next_shader_pos) += vec4_slots;
- }
-}
-
-void
-assign_uniform_locations(struct gl_shader_program *prog)
-{
- /* */
- exec_list uniforms;
- unsigned total_uniforms = 0;
- hash_table *ht = hash_table_ctor(32, hash_table_string_hash,
- hash_table_string_compare);
- void *mem_ctx = ralloc_context(NULL);
-
- for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
- if (prog->_LinkedShaders[i] == NULL)
- continue;
-
- unsigned next_position = 0;
-
- foreach_list(node, prog->_LinkedShaders[i]->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
- if ((var == NULL) || (var->mode != ir_var_uniform))
- continue;
-
- if (strncmp(var->name, "gl_", 3) == 0) {
- /* At the moment, we don't allocate uniform locations for
- * builtin uniforms. It's permitted by spec, and we'll
- * likely switch to doing that at some point, but not yet.
- */
- continue;
- }
-
- var->location = next_position;
- add_uniform(mem_ctx, &uniforms, ht, var->name, var->type,
- prog->_LinkedShaders[i]->Type,
- &next_position, &total_uniforms);
- }
- }
-
- ralloc_free(mem_ctx);
-
- gl_uniform_list *ul = (gl_uniform_list *)
- calloc(1, sizeof(gl_uniform_list));
-
- ul->Size = total_uniforms;
- ul->NumUniforms = total_uniforms;
- ul->Uniforms = (gl_uniform *) calloc(total_uniforms, sizeof(gl_uniform));
-
- unsigned idx = 0;
- uniform_node *next;
- for (uniform_node *node = (uniform_node *) uniforms.head
- ; node->link.next != NULL
- ; node = next) {
- next = (uniform_node *) node->link.next;
-
- node->link.remove();
- memcpy(&ul->Uniforms[idx], node->u, sizeof(gl_uniform));
- idx++;
-
- free(node->u);
- free(node);
- }
-
- hash_table_dtor(ht);
-
- prog->Uniforms = ul;
-}
-
-
-/**
- * Find a contiguous set of available bits in a bitmask
- *
- * \param used_mask Bits representing used (1) and unused (0) locations
- * \param needed_count Number of contiguous bits needed.
- *
- * \return
- * Base location of the available bits on success or -1 on failure.
- */
-int
-find_available_slots(unsigned used_mask, unsigned needed_count)
-{
- unsigned needed_mask = (1 << needed_count) - 1;
- const int max_bit_to_test = (8 * sizeof(used_mask)) - needed_count;
-
- /* The comparison to 32 is redundant, but without it GCC emits "warning:
- * cannot optimize possibly infinite loops" for the loop below.
- */
- if ((needed_count == 0) || (max_bit_to_test < 0) || (max_bit_to_test > 32))
- return -1;
-
- for (int i = 0; i <= max_bit_to_test; i++) {
- if ((needed_mask & ~used_mask) == needed_mask)
- return i;
-
- needed_mask <<= 1;
- }
-
- return -1;
-}
-
-
-bool
-assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index)
-{
- /* Mark invalid attribute locations as being used.
- */
- unsigned used_locations = (max_attribute_index >= 32)
- ? ~0 : ~((1 << max_attribute_index) - 1);
-
- gl_shader *const sh = prog->_LinkedShaders[0];
- assert(sh->Type == GL_VERTEX_SHADER);
-
- /* Operate in a total of four passes.
- *
- * 1. Invalidate the location assignments for all vertex shader inputs.
- *
- * 2. Assign locations for inputs that have user-defined (via
- * glBindVertexAttribLocation) locatoins.
- *
- * 3. Sort the attributes without assigned locations by number of slots
- * required in decreasing order. Fragmentation caused by attribute
- * locations assigned by the application may prevent large attributes
- * from having enough contiguous space.
- *
- * 4. Assign locations to any inputs without assigned locations.
- */
-
- invalidate_variable_locations(sh, ir_var_in, VERT_ATTRIB_GENERIC0);
-
- if (prog->Attributes != NULL) {
- for (unsigned i = 0; i < prog->Attributes->NumParameters; i++) {
- ir_variable *const var =
- sh->symbols->get_variable(prog->Attributes->Parameters[i].Name);
-
- /* Note: attributes that occupy multiple slots, such as arrays or
- * matrices, may appear in the attrib array multiple times.
- */
- if ((var == NULL) || (var->location != -1))
- continue;
-
- /* From page 61 of the OpenGL 4.0 spec:
- *
- * "LinkProgram will fail if the attribute bindings assigned by
- * BindAttribLocation do not leave not enough space to assign a
- * location for an active matrix attribute or an active attribute
- * array, both of which require multiple contiguous generic
- * attributes."
- *
- * Previous versions of the spec contain similar language but omit the
- * bit about attribute arrays.
- *
- * Page 61 of the OpenGL 4.0 spec also says:
- *
- * "It is possible for an application to bind more than one
- * attribute name to the same location. This is referred to as
- * aliasing. This will only work if only one of the aliased
- * attributes is active in the executable program, or if no path
- * through the shader consumes more than one attribute of a set
- * of attributes aliased to the same location. A link error can
- * occur if the linker determines that every path through the
- * shader consumes multiple aliased attributes, but
- * implementations are not required to generate an error in this
- * case."
- *
- * These two paragraphs are either somewhat contradictory, or I don't
- * fully understand one or both of them.
- */
- /* FINISHME: The code as currently written does not support attribute
- * FINISHME: location aliasing (see comment above).
- */
- const int attr = prog->Attributes->Parameters[i].StateIndexes[0];
- const unsigned slots = count_attribute_slots(var->type);
-
- /* Mask representing the contiguous slots that will be used by this
- * attribute.
- */
- const unsigned use_mask = (1 << slots) - 1;
-
- /* Generate a link error if the set of bits requested for this
- * attribute overlaps any previously allocated bits.
- */
- if ((~(use_mask << attr) & used_locations) != used_locations) {
- linker_error_printf(prog,
- "insufficient contiguous attribute locations "
- "available for vertex shader input `%s'",
- var->name);
- return false;
- }
-
- var->location = VERT_ATTRIB_GENERIC0 + attr;
- used_locations |= (use_mask << attr);
- }
- }
-
- /* Temporary storage for the set of attributes that need locations assigned.
- */
- struct temp_attr {
- unsigned slots;
- ir_variable *var;
-
- /* Used below in the call to qsort. */
- static int compare(const void *a, const void *b)
- {
- const temp_attr *const l = (const temp_attr *) a;
- const temp_attr *const r = (const temp_attr *) b;
-
- /* Reversed because we want a descending order sort below. */
- return r->slots - l->slots;
- }
- } to_assign[16];
-
- unsigned num_attr = 0;
-
- foreach_list(node, sh->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
- if ((var == NULL) || (var->mode != ir_var_in))
- continue;
-
- if (var->explicit_location) {
- const unsigned slots = count_attribute_slots(var->type);
- const unsigned use_mask = (1 << slots) - 1;
- const int attr = var->location - VERT_ATTRIB_GENERIC0;
-
- if ((var->location >= (int)(max_attribute_index + VERT_ATTRIB_GENERIC0))
- || (var->location < 0)) {
- linker_error_printf(prog,
- "invalid explicit location %d specified for "
- "`%s'\n",
- (var->location < 0) ? var->location : attr,
- var->name);
- return false;
- } else if (var->location >= VERT_ATTRIB_GENERIC0) {
- used_locations |= (use_mask << attr);
- }
- }
-
- /* The location was explicitly assigned, nothing to do here.
- */
- if (var->location != -1)
- continue;
-
- to_assign[num_attr].slots = count_attribute_slots(var->type);
- to_assign[num_attr].var = var;
- num_attr++;
- }
-
- /* If all of the attributes were assigned locations by the application (or
- * are built-in attributes with fixed locations), return early. This should
- * be the common case.
- */
- if (num_attr == 0)
- return true;
-
- qsort(to_assign, num_attr, sizeof(to_assign[0]), temp_attr::compare);
-
- /* VERT_ATTRIB_GENERIC0 is a psdueo-alias for VERT_ATTRIB_POS. It can only
- * be explicitly assigned by via glBindAttribLocation. Mark it as reserved
- * to prevent it from being automatically allocated below.
- */
- find_deref_visitor find("gl_Vertex");
- find.run(sh->ir);
- if (find.variable_found())
- used_locations |= (1 << 0);
-
- for (unsigned i = 0; i < num_attr; i++) {
- /* Mask representing the contiguous slots that will be used by this
- * attribute.
- */
- const unsigned use_mask = (1 << to_assign[i].slots) - 1;
-
- int location = find_available_slots(used_locations, to_assign[i].slots);
-
- if (location < 0) {
- linker_error_printf(prog,
- "insufficient contiguous attribute locations "
- "available for vertex shader input `%s'",
- to_assign[i].var->name);
- return false;
- }
-
- to_assign[i].var->location = VERT_ATTRIB_GENERIC0 + location;
- used_locations |= (use_mask << location);
- }
-
- return true;
-}
-
-
-/**
- * Demote shader inputs and outputs that are not used in other stages
- */
-void
-demote_shader_inputs_and_outputs(gl_shader *sh, enum ir_variable_mode mode)
-{
- foreach_list(node, sh->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
- if ((var == NULL) || (var->mode != int(mode)))
- continue;
-
- /* A shader 'in' or 'out' variable is only really an input or output if
- * its value is used by other shader stages. This will cause the variable
- * to have a location assigned.
- */
- if (var->location == -1) {
- var->mode = ir_var_auto;
- }
- }
-}
-
-
-void
-assign_varying_locations(struct gl_shader_program *prog,
- gl_shader *producer, gl_shader *consumer)
-{
- /* FINISHME: Set dynamically when geometry shader support is added. */
- unsigned output_index = VERT_RESULT_VAR0;
- unsigned input_index = FRAG_ATTRIB_VAR0;
-
- /* Operate in a total of three passes.
- *
- * 1. Assign locations for any matching inputs and outputs.
- *
- * 2. Mark output variables in the producer that do not have locations as
- * not being outputs. This lets the optimizer eliminate them.
- *
- * 3. Mark input variables in the consumer that do not have locations as
- * not being inputs. This lets the optimizer eliminate them.
- */
-
- invalidate_variable_locations(producer, ir_var_out, VERT_RESULT_VAR0);
- invalidate_variable_locations(consumer, ir_var_in, FRAG_ATTRIB_VAR0);
-
- foreach_list(node, producer->ir) {
- ir_variable *const output_var = ((ir_instruction *) node)->as_variable();
-
- if ((output_var == NULL) || (output_var->mode != ir_var_out)
- || (output_var->location != -1))
- continue;
-
- ir_variable *const input_var =
- consumer->symbols->get_variable(output_var->name);
-
- if ((input_var == NULL) || (input_var->mode != ir_var_in))
- continue;
-
- assert(input_var->location == -1);
-
- output_var->location = output_index;
- input_var->location = input_index;
-
- /* FINISHME: Support for "varying" records in GLSL 1.50. */
- assert(!output_var->type->is_record());
-
- if (output_var->type->is_array()) {
- const unsigned slots = output_var->type->length
- * output_var->type->fields.array->matrix_columns;
-
- output_index += slots;
- input_index += slots;
- } else {
- const unsigned slots = output_var->type->matrix_columns;
-
- output_index += slots;
- input_index += slots;
- }
- }
-
- foreach_list(node, consumer->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
- if ((var == NULL) || (var->mode != ir_var_in))
- continue;
-
- if (var->location == -1) {
- if (prog->Version <= 120) {
- /* On page 25 (page 31 of the PDF) of the GLSL 1.20 spec:
- *
- * Only those varying variables used (i.e. read) in
- * the fragment shader executable must be written to
- * by the vertex shader executable; declaring
- * superfluous varying variables in a vertex shader is
- * permissible.
- *
- * We interpret this text as meaning that the VS must
- * write the variable for the FS to read it. See
- * "glsl1-varying read but not written" in piglit.
- */
-
- linker_error_printf(prog, "fragment shader varying %s not written "
- "by vertex shader\n.", var->name);
- prog->LinkStatus = false;
- }
-
- /* An 'in' variable is only really a shader input if its
- * value is written by the previous stage.
- */
- var->mode = ir_var_auto;
- }
- }
-}
-
-
-void
-link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
-{
- void *mem_ctx = ralloc_context(NULL); // temporary linker context
-
- prog->LinkStatus = false;
- prog->Validated = false;
- prog->_Used = false;
-
- if (prog->InfoLog != NULL)
- ralloc_free(prog->InfoLog);
-
- prog->InfoLog = ralloc_strdup(NULL, "");
-
- /* Separate the shaders into groups based on their type.
- */
- struct gl_shader **vert_shader_list;
- unsigned num_vert_shaders = 0;
- struct gl_shader **frag_shader_list;
- unsigned num_frag_shaders = 0;
-
- vert_shader_list = (struct gl_shader **)
- calloc(2 * prog->NumShaders, sizeof(struct gl_shader *));
- frag_shader_list = &vert_shader_list[prog->NumShaders];
-
- unsigned min_version = UINT_MAX;
- unsigned max_version = 0;
- for (unsigned i = 0; i < prog->NumShaders; i++) {
- min_version = MIN2(min_version, prog->Shaders[i]->Version);
- max_version = MAX2(max_version, prog->Shaders[i]->Version);
-
- switch (prog->Shaders[i]->Type) {
- case GL_VERTEX_SHADER:
- vert_shader_list[num_vert_shaders] = prog->Shaders[i];
- num_vert_shaders++;
- break;
- case GL_FRAGMENT_SHADER:
- frag_shader_list[num_frag_shaders] = prog->Shaders[i];
- num_frag_shaders++;
- break;
- case GL_GEOMETRY_SHADER:
- /* FINISHME: Support geometry shaders. */
- assert(prog->Shaders[i]->Type != GL_GEOMETRY_SHADER);
- break;
- }
- }
-
- /* Previous to GLSL version 1.30, different compilation units could mix and
- * match shading language versions. With GLSL 1.30 and later, the versions
- * of all shaders must match.
- */
- assert(min_version >= 100);
- assert(max_version <= 130);
- if ((max_version >= 130 || min_version == 100)
- && min_version != max_version) {
- linker_error_printf(prog, "all shaders must use same shading "
- "language version\n");
- goto done;
- }
-
- prog->Version = max_version;
-
- for (unsigned int i = 0; i < MESA_SHADER_TYPES; i++) {
- if (prog->_LinkedShaders[i] != NULL)
- ctx->Driver.DeleteShader(ctx, prog->_LinkedShaders[i]);
-
- prog->_LinkedShaders[i] = NULL;
- }
-
- /* Link all shaders for a particular stage and validate the result.
- */
- if (num_vert_shaders > 0) {
- gl_shader *const sh =
- link_intrastage_shaders(mem_ctx, ctx, prog, vert_shader_list,
- num_vert_shaders);
-
- if (sh == NULL)
- goto done;
-
- if (!validate_vertex_shader_executable(prog, sh))
- goto done;
-
- _mesa_reference_shader(ctx, &prog->_LinkedShaders[MESA_SHADER_VERTEX],
- sh);
- }
-
- if (num_frag_shaders > 0) {
- gl_shader *const sh =
- link_intrastage_shaders(mem_ctx, ctx, prog, frag_shader_list,
- num_frag_shaders);
-
- if (sh == NULL)
- goto done;
-
- if (!validate_fragment_shader_executable(prog, sh))
- goto done;
-
- _mesa_reference_shader(ctx, &prog->_LinkedShaders[MESA_SHADER_FRAGMENT],
- sh);
- }
-
- /* Here begins the inter-stage linking phase. Some initial validation is
- * performed, then locations are assigned for uniforms, attributes, and
- * varyings.
- */
- if (cross_validate_uniforms(prog)) {
- unsigned prev;
-
- for (prev = 0; prev < MESA_SHADER_TYPES; prev++) {
- if (prog->_LinkedShaders[prev] != NULL)
- break;
- }
-
- /* Validate the inputs of each stage with the output of the preceeding
- * stage.
- */
- for (unsigned i = prev + 1; i < MESA_SHADER_TYPES; i++) {
- if (prog->_LinkedShaders[i] == NULL)
- continue;
-
- if (!cross_validate_outputs_to_inputs(prog,
- prog->_LinkedShaders[prev],
- prog->_LinkedShaders[i]))
- goto done;
-
- prev = i;
- }
-
- prog->LinkStatus = true;
- }
-
- /* Do common optimization before assigning storage for attributes,
- * uniforms, and varyings. Later optimization could possibly make
- * some of that unused.
- */
- for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
- if (prog->_LinkedShaders[i] == NULL)
- continue;
-
- while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, 32))
- ;
- }
-
- update_array_sizes(prog);
-
- assign_uniform_locations(prog);
-
- if (prog->_LinkedShaders[MESA_SHADER_VERTEX] != NULL) {
- /* FINISHME: The value of the max_attribute_index parameter is
- * FINISHME: implementation dependent based on the value of
- * FINISHME: GL_MAX_VERTEX_ATTRIBS. GL_MAX_VERTEX_ATTRIBS must be
- * FINISHME: at least 16, so hardcode 16 for now.
- */
- if (!assign_attribute_locations(prog, 16)) {
- prog->LinkStatus = false;
- goto done;
- }
- }
-
- unsigned prev;
- for (prev = 0; prev < MESA_SHADER_TYPES; prev++) {
- if (prog->_LinkedShaders[prev] != NULL)
- break;
- }
-
- for (unsigned i = prev + 1; i < MESA_SHADER_TYPES; i++) {
- if (prog->_LinkedShaders[i] == NULL)
- continue;
-
- assign_varying_locations(prog,
- prog->_LinkedShaders[prev],
- prog->_LinkedShaders[i]);
- prev = i;
- }
-
- if (prog->_LinkedShaders[MESA_SHADER_VERTEX] != NULL) {
- demote_shader_inputs_and_outputs(prog->_LinkedShaders[MESA_SHADER_VERTEX],
- ir_var_out);
- }
-
- if (prog->_LinkedShaders[MESA_SHADER_GEOMETRY] != NULL) {
- gl_shader *const sh = prog->_LinkedShaders[MESA_SHADER_GEOMETRY];
-
- demote_shader_inputs_and_outputs(sh, ir_var_in);
- demote_shader_inputs_and_outputs(sh, ir_var_inout);
- demote_shader_inputs_and_outputs(sh, ir_var_out);
- }
-
- if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] != NULL) {
- gl_shader *const sh = prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
-
- demote_shader_inputs_and_outputs(sh, ir_var_in);
- }
-
- /* OpenGL ES requires that a vertex shader and a fragment shader both be
- * present in a linked program. By checking for use of shading language
- * version 1.00, we also catch the GL_ARB_ES2_compatibility case.
- */
- if (ctx->API == API_OPENGLES2 || prog->Version == 100) {
- if (prog->_LinkedShaders[MESA_SHADER_VERTEX] == NULL) {
- linker_error_printf(prog, "program lacks a vertex shader\n");
- prog->LinkStatus = false;
- } else if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL) {
- linker_error_printf(prog, "program lacks a fragment shader\n");
- prog->LinkStatus = false;
- }
- }
-
- /* FINISHME: Assign fragment shader output locations. */
-
-done:
- free(vert_shader_list);
-
- for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
- if (prog->_LinkedShaders[i] == NULL)
- continue;
-
- /* Retain any live IR, but trash the rest. */
- reparent_ir(prog->_LinkedShaders[i]->ir, prog->_LinkedShaders[i]->ir);
- }
-
- ralloc_free(mem_ctx);
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file linker.cpp
+ * GLSL linker implementation
+ *
+ * Given a set of shaders that are to be linked to generate a final program,
+ * there are three distinct stages.
+ *
+ * In the first stage shaders are partitioned into groups based on the shader
+ * type. All shaders of a particular type (e.g., vertex shaders) are linked
+ * together.
+ *
+ * - Undefined references in each shader are resolve to definitions in
+ * another shader.
+ * - Types and qualifiers of uniforms, outputs, and global variables defined
+ * in multiple shaders with the same name are verified to be the same.
+ * - Initializers for uniforms and global variables defined
+ * in multiple shaders with the same name are verified to be the same.
+ *
+ * The result, in the terminology of the GLSL spec, is a set of shader
+ * executables for each processing unit.
+ *
+ * After the first stage is complete, a series of semantic checks are performed
+ * on each of the shader executables.
+ *
+ * - Each shader executable must define a \c main function.
+ * - Each vertex shader executable must write to \c gl_Position.
+ * - Each fragment shader executable must write to either \c gl_FragData or
+ * \c gl_FragColor.
+ *
+ * In the final stage individual shader executables are linked to create a
+ * complete exectuable.
+ *
+ * - Types of uniforms defined in multiple shader stages with the same name
+ * are verified to be the same.
+ * - Initializers for uniforms defined in multiple shader stages with the
+ * same name are verified to be the same.
+ * - Types and qualifiers of outputs defined in one stage are verified to
+ * be the same as the types and qualifiers of inputs defined with the same
+ * name in a later stage.
+ *
+ * \author Ian Romanick <ian.d.romanick@intel.com>
+ */
+
+#include "main/core.h"
+#include "glsl_symbol_table.h"
+#include "ir.h"
+#include "program.h"
+#include "program/hash_table.h"
+#include "linker.h"
+#include "ir_optimization.h"
+
+extern "C" {
+#include "main/shaderobj.h"
+}
+
+/**
+ * Visitor that determines whether or not a variable is ever written.
+ */
+class find_assignment_visitor : public ir_hierarchical_visitor {
+public:
+ find_assignment_visitor(const char *name)
+ : name(name), found(false)
+ {
+ /* empty */
+ }
+
+ virtual ir_visitor_status visit_enter(ir_assignment *ir)
+ {
+ ir_variable *const var = ir->lhs->variable_referenced();
+
+ if (strcmp(name, var->name) == 0) {
+ found = true;
+ return visit_stop;
+ }
+
+ return visit_continue_with_parent;
+ }
+
+ virtual ir_visitor_status visit_enter(ir_call *ir)
+ {
+ exec_list_iterator sig_iter = ir->get_callee()->parameters.iterator();
+ foreach_iter(exec_list_iterator, iter, *ir) {
+ ir_rvalue *param_rval = (ir_rvalue *)iter.get();
+ ir_variable *sig_param = (ir_variable *)sig_iter.get();
+
+ if (sig_param->mode == ir_var_out ||
+ sig_param->mode == ir_var_inout) {
+ ir_variable *var = param_rval->variable_referenced();
+ if (var && strcmp(name, var->name) == 0) {
+ found = true;
+ return visit_stop;
+ }
+ }
+ sig_iter.next();
+ }
+
+ return visit_continue_with_parent;
+ }
+
+ bool variable_found()
+ {
+ return found;
+ }
+
+private:
+ const char *name; /**< Find writes to a variable with this name. */
+ bool found; /**< Was a write to the variable found? */
+};
+
+
+/**
+ * Visitor that determines whether or not a variable is ever read.
+ */
+class find_deref_visitor : public ir_hierarchical_visitor {
+public:
+ find_deref_visitor(const char *name)
+ : name(name), found(false)
+ {
+ /* empty */
+ }
+
+ virtual ir_visitor_status visit(ir_dereference_variable *ir)
+ {
+ if (strcmp(this->name, ir->var->name) == 0) {
+ this->found = true;
+ return visit_stop;
+ }
+
+ return visit_continue;
+ }
+
+ bool variable_found() const
+ {
+ return this->found;
+ }
+
+private:
+ const char *name; /**< Find writes to a variable with this name. */
+ bool found; /**< Was a write to the variable found? */
+};
+
+
+void
+linker_error_printf(gl_shader_program *prog, const char *fmt, ...)
+{
+ va_list ap;
+
+ ralloc_strcat(&prog->InfoLog, "error: ");
+ va_start(ap, fmt);
+ ralloc_vasprintf_append(&prog->InfoLog, fmt, ap);
+ va_end(ap);
+}
+
+
+void
+invalidate_variable_locations(gl_shader *sh, enum ir_variable_mode mode,
+ int generic_base)
+{
+ foreach_list(node, sh->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ if ((var == NULL) || (var->mode != (unsigned) mode))
+ continue;
+
+ /* Only assign locations for generic attributes / varyings / etc.
+ */
+ if ((var->location >= generic_base) && !var->explicit_location)
+ var->location = -1;
+ }
+}
+
+
+/**
+ * Determine the number of attribute slots required for a particular type
+ *
+ * This code is here because it implements the language rules of a specific
+ * GLSL version. Since it's a property of the language and not a property of
+ * types in general, it doesn't really belong in glsl_type.
+ */
+unsigned
+count_attribute_slots(const glsl_type *t)
+{
+ /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
+ *
+ * "A scalar input counts the same amount against this limit as a vec4,
+ * so applications may want to consider packing groups of four
+ * unrelated float inputs together into a vector to better utilize the
+ * capabilities of the underlying hardware. A matrix input will use up
+ * multiple locations. The number of locations used will equal the
+ * number of columns in the matrix."
+ *
+ * The spec does not explicitly say how arrays are counted. However, it
+ * should be safe to assume the total number of slots consumed by an array
+ * is the number of entries in the array multiplied by the number of slots
+ * consumed by a single element of the array.
+ */
+
+ if (t->is_array())
+ return t->array_size() * count_attribute_slots(t->element_type());
+
+ if (t->is_matrix())
+ return t->matrix_columns;
+
+ return 1;
+}
+
+
+/**
+ * Verify that a vertex shader executable meets all semantic requirements
+ *
+ * \param shader Vertex shader executable to be verified
+ */
+bool
+validate_vertex_shader_executable(struct gl_shader_program *prog,
+ struct gl_shader *shader)
+{
+ if (shader == NULL)
+ return true;
+
+ find_assignment_visitor find("gl_Position");
+ find.run(shader->ir);
+ if (!find.variable_found()) {
+ linker_error_printf(prog,
+ "vertex shader does not write to `gl_Position'\n");
+ return false;
+ }
+
+ return true;
+}
+
+
+/**
+ * Verify that a fragment shader executable meets all semantic requirements
+ *
+ * \param shader Fragment shader executable to be verified
+ */
+bool
+validate_fragment_shader_executable(struct gl_shader_program *prog,
+ struct gl_shader *shader)
+{
+ if (shader == NULL)
+ return true;
+
+ find_assignment_visitor frag_color("gl_FragColor");
+ find_assignment_visitor frag_data("gl_FragData");
+
+ frag_color.run(shader->ir);
+ frag_data.run(shader->ir);
+
+ if (frag_color.variable_found() && frag_data.variable_found()) {
+ linker_error_printf(prog, "fragment shader writes to both "
+ "`gl_FragColor' and `gl_FragData'\n");
+ return false;
+ }
+
+ return true;
+}
+
+
+/**
+ * Generate a string describing the mode of a variable
+ */
+static const char *
+mode_string(const ir_variable *var)
+{
+ switch (var->mode) {
+ case ir_var_auto:
+ return (var->read_only) ? "global constant" : "global variable";
+
+ case ir_var_uniform: return "uniform";
+ case ir_var_in: return "shader input";
+ case ir_var_out: return "shader output";
+ case ir_var_inout: return "shader inout";
+
+ case ir_var_const_in:
+ case ir_var_temporary:
+ default:
+ assert(!"Should not get here.");
+ return "invalid variable";
+ }
+}
+
+
+/**
+ * Perform validation of global variables used across multiple shaders
+ */
+bool
+cross_validate_globals(struct gl_shader_program *prog,
+ struct gl_shader **shader_list,
+ unsigned num_shaders,
+ bool uniforms_only)
+{
+ /* Examine all of the uniforms in all of the shaders and cross validate
+ * them.
+ */
+ glsl_symbol_table variables;
+ for (unsigned i = 0; i < num_shaders; i++) {
+ if (shader_list[i] == NULL)
+ continue;
+
+ foreach_list(node, shader_list[i]->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ if (var == NULL)
+ continue;
+
+ if (uniforms_only && (var->mode != ir_var_uniform))
+ continue;
+
+ /* Don't cross validate temporaries that are at global scope. These
+ * will eventually get pulled into the shaders 'main'.
+ */
+ if (var->mode == ir_var_temporary)
+ continue;
+
+ /* If a global with this name has already been seen, verify that the
+ * new instance has the same type. In addition, if the globals have
+ * initializers, the values of the initializers must be the same.
+ */
+ ir_variable *const existing = variables.get_variable(var->name);
+ if (existing != NULL) {
+ if (var->type != existing->type) {
+ /* Consider the types to be "the same" if both types are arrays
+ * of the same type and one of the arrays is implicitly sized.
+ * In addition, set the type of the linked variable to the
+ * explicitly sized array.
+ */
+ if (var->type->is_array()
+ && existing->type->is_array()
+ && (var->type->fields.array == existing->type->fields.array)
+ && ((var->type->length == 0)
+ || (existing->type->length == 0))) {
+ if (var->type->length != 0) {
+ existing->type = var->type;
+ }
+ } else {
+ linker_error_printf(prog, "%s `%s' declared as type "
+ "`%s' and type `%s'\n",
+ mode_string(var),
+ var->name, var->type->name,
+ existing->type->name);
+ return false;
+ }
+ }
+
+ if (var->explicit_location) {
+ if (existing->explicit_location
+ && (var->location != existing->location)) {
+ linker_error_printf(prog, "explicit locations for %s "
+ "`%s' have differing values\n",
+ mode_string(var), var->name);
+ return false;
+ }
+
+ existing->location = var->location;
+ existing->explicit_location = true;
+ }
+
+ /* Validate layout qualifiers for gl_FragDepth.
+ *
+ * From the AMD_conservative_depth spec:
+ * "If gl_FragDepth is redeclared in any fragment shader in
+ * a program, it must be redeclared in all fragment shaders in that
+ * program that have static assignments to gl_FragDepth. All
+ * redeclarations of gl_FragDepth in all fragment shaders in
+ * a single program must have the same set of qualifiers."
+ */
+ if (strcmp(var->name, "gl_FragDepth") == 0) {
+ bool layout_declared = var->depth_layout != ir_depth_layout_none;
+ bool layout_differs = var->depth_layout != existing->depth_layout;
+ if (layout_declared && layout_differs) {
+ linker_error_printf(prog,
+ "All redeclarations of gl_FragDepth in all fragment shaders "
+ "in a single program must have the same set of qualifiers.");
+ }
+ if (var->used && layout_differs) {
+ linker_error_printf(prog,
+ "If gl_FragDepth is redeclared with a layout qualifier in"
+ "any fragment shader, it must be redeclared with the same"
+ "layout qualifier in all fragment shaders that have"
+ "assignments to gl_FragDepth");
+ }
+ }
+
+ /* FINISHME: Handle non-constant initializers.
+ */
+ if (var->constant_value != NULL) {
+ if (existing->constant_value != NULL) {
+ if (!var->constant_value->has_value(existing->constant_value)) {
+ linker_error_printf(prog, "initializers for %s "
+ "`%s' have differing values\n",
+ mode_string(var), var->name);
+ return false;
+ }
+ } else
+ /* If the first-seen instance of a particular uniform did not
+ * have an initializer but a later instance does, copy the
+ * initializer to the version stored in the symbol table.
+ */
+ /* FINISHME: This is wrong. The constant_value field should
+ * FINISHME: not be modified! Imagine a case where a shader
+ * FINISHME: without an initializer is linked in two different
+ * FINISHME: programs with shaders that have differing
+ * FINISHME: initializers. Linking with the first will
+ * FINISHME: modify the shader, and linking with the second
+ * FINISHME: will fail.
+ */
+ existing->constant_value =
+ var->constant_value->clone(ralloc_parent(existing), NULL);
+ }
+
+ if (existing->invariant != var->invariant) {
+ linker_error_printf(prog, "declarations for %s `%s' have "
+ "mismatching invariant qualifiers\n",
+ mode_string(var), var->name);
+ return false;
+ }
+ if (existing->centroid != var->centroid) {
+ linker_error_printf(prog, "declarations for %s `%s' have "
+ "mismatching centroid qualifiers\n",
+ mode_string(var), var->name);
+ return false;
+ }
+ } else
+ variables.add_variable(var);
+ }
+ }
+
+ return true;
+}
+
+
+/**
+ * Perform validation of uniforms used across multiple shader stages
+ */
+bool
+cross_validate_uniforms(struct gl_shader_program *prog)
+{
+ return cross_validate_globals(prog, prog->_LinkedShaders,
+ MESA_SHADER_TYPES, true);
+}
+
+
+/**
+ * Validate that outputs from one stage match inputs of another
+ */
+bool
+cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
+ gl_shader *producer, gl_shader *consumer)
+{
+ glsl_symbol_table parameters;
+ /* FINISHME: Figure these out dynamically. */
+ const char *const producer_stage = "vertex";
+ const char *const consumer_stage = "fragment";
+
+ /* Find all shader outputs in the "producer" stage.
+ */
+ foreach_list(node, producer->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ /* FINISHME: For geometry shaders, this should also look for inout
+ * FINISHME: variables.
+ */
+ if ((var == NULL) || (var->mode != ir_var_out))
+ continue;
+
+ parameters.add_variable(var);
+ }
+
+
+ /* Find all shader inputs in the "consumer" stage. Any variables that have
+ * matching outputs already in the symbol table must have the same type and
+ * qualifiers.
+ */
+ foreach_list(node, consumer->ir) {
+ ir_variable *const input = ((ir_instruction *) node)->as_variable();
+
+ /* FINISHME: For geometry shaders, this should also look for inout
+ * FINISHME: variables.
+ */
+ if ((input == NULL) || (input->mode != ir_var_in))
+ continue;
+
+ ir_variable *const output = parameters.get_variable(input->name);
+ if (output != NULL) {
+ /* Check that the types match between stages.
+ */
+ if (input->type != output->type) {
+ /* There is a bit of a special case for gl_TexCoord. This
+ * built-in is unsized by default. Appliations that variable
+ * access it must redeclare it with a size. There is some
+ * language in the GLSL spec that implies the fragment shader
+ * and vertex shader do not have to agree on this size. Other
+ * driver behave this way, and one or two applications seem to
+ * rely on it.
+ *
+ * Neither declaration needs to be modified here because the array
+ * sizes are fixed later when update_array_sizes is called.
+ *
+ * From page 48 (page 54 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "Unlike user-defined varying variables, the built-in
+ * varying variables don't have a strict one-to-one
+ * correspondence between the vertex language and the
+ * fragment language."
+ */
+ if (!output->type->is_array()
+ || (strncmp("gl_", output->name, 3) != 0)) {
+ linker_error_printf(prog,
+ "%s shader output `%s' declared as "
+ "type `%s', but %s shader input declared "
+ "as type `%s'\n",
+ producer_stage, output->name,
+ output->type->name,
+ consumer_stage, input->type->name);
+ return false;
+ }
+ }
+
+ /* Check that all of the qualifiers match between stages.
+ */
+ if (input->centroid != output->centroid) {
+ linker_error_printf(prog,
+ "%s shader output `%s' %s centroid qualifier, "
+ "but %s shader input %s centroid qualifier\n",
+ producer_stage,
+ output->name,
+ (output->centroid) ? "has" : "lacks",
+ consumer_stage,
+ (input->centroid) ? "has" : "lacks");
+ return false;
+ }
+
+ if (input->invariant != output->invariant) {
+ linker_error_printf(prog,
+ "%s shader output `%s' %s invariant qualifier, "
+ "but %s shader input %s invariant qualifier\n",
+ producer_stage,
+ output->name,
+ (output->invariant) ? "has" : "lacks",
+ consumer_stage,
+ (input->invariant) ? "has" : "lacks");
+ return false;
+ }
+
+ if (input->interpolation != output->interpolation) {
+ linker_error_printf(prog,
+ "%s shader output `%s' specifies %s "
+ "interpolation qualifier, "
+ "but %s shader input specifies %s "
+ "interpolation qualifier\n",
+ producer_stage,
+ output->name,
+ output->interpolation_string(),
+ consumer_stage,
+ input->interpolation_string());
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+
+/**
+ * Populates a shaders symbol table with all global declarations
+ */
+static void
+populate_symbol_table(gl_shader *sh)
+{
+ sh->symbols = new(sh) glsl_symbol_table;
+
+ foreach_list(node, sh->ir) {
+ ir_instruction *const inst = (ir_instruction *) node;
+ ir_variable *var;
+ ir_function *func;
+
+ if ((func = inst->as_function()) != NULL) {
+ sh->symbols->add_function(func);
+ } else if ((var = inst->as_variable()) != NULL) {
+ sh->symbols->add_variable(var);
+ }
+ }
+}
+
+
+/**
+ * Remap variables referenced in an instruction tree
+ *
+ * This is used when instruction trees are cloned from one shader and placed in
+ * another. These trees will contain references to \c ir_variable nodes that
+ * do not exist in the target shader. This function finds these \c ir_variable
+ * references and replaces the references with matching variables in the target
+ * shader.
+ *
+ * If there is no matching variable in the target shader, a clone of the
+ * \c ir_variable is made and added to the target shader. The new variable is
+ * added to \b both the instruction stream and the symbol table.
+ *
+ * \param inst IR tree that is to be processed.
+ * \param symbols Symbol table containing global scope symbols in the
+ * linked shader.
+ * \param instructions Instruction stream where new variable declarations
+ * should be added.
+ */
+void
+remap_variables(ir_instruction *inst, struct gl_shader *target,
+ hash_table *temps)
+{
+ class remap_visitor : public ir_hierarchical_visitor {
+ public:
+ remap_visitor(struct gl_shader *target,
+ hash_table *temps)
+ {
+ this->target = target;
+ this->symbols = target->symbols;
+ this->instructions = target->ir;
+ this->temps = temps;
+ }
+
+ virtual ir_visitor_status visit(ir_dereference_variable *ir)
+ {
+ if (ir->var->mode == ir_var_temporary) {
+ ir_variable *var = (ir_variable *) hash_table_find(temps, ir->var);
+
+ assert(var != NULL);
+ ir->var = var;
+ return visit_continue;
+ }
+
+ ir_variable *const existing =
+ this->symbols->get_variable(ir->var->name);
+ if (existing != NULL)
+ ir->var = existing;
+ else {
+ ir_variable *copy = ir->var->clone(this->target, NULL);
+
+ this->symbols->add_variable(copy);
+ this->instructions->push_head(copy);
+ ir->var = copy;
+ }
+
+ return visit_continue;
+ }
+
+ private:
+ struct gl_shader *target;
+ glsl_symbol_table *symbols;
+ exec_list *instructions;
+ hash_table *temps;
+ };
+
+ remap_visitor v(target, temps);
+
+ inst->accept(&v);
+}
+
+
+/**
+ * Move non-declarations from one instruction stream to another
+ *
+ * The intended usage pattern of this function is to pass the pointer to the
+ * head sentinel of a list (i.e., a pointer to the list cast to an \c exec_node
+ * pointer) for \c last and \c false for \c make_copies on the first
+ * call. Successive calls pass the return value of the previous call for
+ * \c last and \c true for \c make_copies.
+ *
+ * \param instructions Source instruction stream
+ * \param last Instruction after which new instructions should be
+ * inserted in the target instruction stream
+ * \param make_copies Flag selecting whether instructions in \c instructions
+ * should be copied (via \c ir_instruction::clone) into the
+ * target list or moved.
+ *
+ * \return
+ * The new "last" instruction in the target instruction stream. This pointer
+ * is suitable for use as the \c last parameter of a later call to this
+ * function.
+ */
+exec_node *
+move_non_declarations(exec_list *instructions, exec_node *last,
+ bool make_copies, gl_shader *target)
+{
+ hash_table *temps = NULL;
+
+ if (make_copies)
+ temps = hash_table_ctor(0, hash_table_pointer_hash,
+ hash_table_pointer_compare);
+
+ foreach_list_safe(node, instructions) {
+ ir_instruction *inst = (ir_instruction *) node;
+
+ if (inst->as_function())
+ continue;
+
+ ir_variable *var = inst->as_variable();
+ if ((var != NULL) && (var->mode != ir_var_temporary))
+ continue;
+
+ assert(inst->as_assignment()
+ || ((var != NULL) && (var->mode == ir_var_temporary)));
+
+ if (make_copies) {
+ inst = inst->clone(target, NULL);
+
+ if (var != NULL)
+ hash_table_insert(temps, inst, var);
+ else
+ remap_variables(inst, target, temps);
+ } else {
+ inst->remove();
+ }
+
+ last->insert_after(inst);
+ last = inst;
+ }
+
+ if (make_copies)
+ hash_table_dtor(temps);
+
+ return last;
+}
+
+/**
+ * Get the function signature for main from a shader
+ */
+static ir_function_signature *
+get_main_function_signature(gl_shader *sh)
+{
+ ir_function *const f = sh->symbols->get_function("main");
+ if (f != NULL) {
+ exec_list void_parameters;
+
+ /* Look for the 'void main()' signature and ensure that it's defined.
+ * This keeps the linker from accidentally pick a shader that just
+ * contains a prototype for main.
+ *
+ * We don't have to check for multiple definitions of main (in multiple
+ * shaders) because that would have already been caught above.
+ */
+ ir_function_signature *sig = f->matching_signature(&void_parameters);
+ if ((sig != NULL) && sig->is_defined) {
+ return sig;
+ }
+ }
+
+ return NULL;
+}
+
+
+/**
+ * Combine a group of shaders for a single stage to generate a linked shader
+ *
+ * \note
+ * If this function is supplied a single shader, it is cloned, and the new
+ * shader is returned.
+ */
+static struct gl_shader *
+link_intrastage_shaders(void *mem_ctx,
+ struct gl_context *ctx,
+ struct gl_shader_program *prog,
+ struct gl_shader **shader_list,
+ unsigned num_shaders)
+{
+ /* Check that global variables defined in multiple shaders are consistent.
+ */
+ if (!cross_validate_globals(prog, shader_list, num_shaders, false))
+ return NULL;
+
+ /* Check that there is only a single definition of each function signature
+ * across all shaders.
+ */
+ for (unsigned i = 0; i < (num_shaders - 1); i++) {
+ foreach_list(node, shader_list[i]->ir) {
+ ir_function *const f = ((ir_instruction *) node)->as_function();
+
+ if (f == NULL)
+ continue;
+
+ for (unsigned j = i + 1; j < num_shaders; j++) {
+ ir_function *const other =
+ shader_list[j]->symbols->get_function(f->name);
+
+ /* If the other shader has no function (and therefore no function
+ * signatures) with the same name, skip to the next shader.
+ */
+ if (other == NULL)
+ continue;
+
+ foreach_iter (exec_list_iterator, iter, *f) {
+ ir_function_signature *sig =
+ (ir_function_signature *) iter.get();
+
+ if (!sig->is_defined || sig->is_builtin)
+ continue;
+
+ ir_function_signature *other_sig =
+ other->exact_matching_signature(& sig->parameters);
+
+ if ((other_sig != NULL) && other_sig->is_defined
+ && !other_sig->is_builtin) {
+ linker_error_printf(prog,
+ "function `%s' is multiply defined",
+ f->name);
+ return NULL;
+ }
+ }
+ }
+ }
+ }
+
+ /* Find the shader that defines main, and make a clone of it.
+ *
+ * Starting with the clone, search for undefined references. If one is
+ * found, find the shader that defines it. Clone the reference and add
+ * it to the shader. Repeat until there are no undefined references or
+ * until a reference cannot be resolved.
+ */
+ gl_shader *main = NULL;
+ for (unsigned i = 0; i < num_shaders; i++) {
+ if (get_main_function_signature(shader_list[i]) != NULL) {
+ main = shader_list[i];
+ break;
+ }
+ }
+
+ if (main == NULL) {
+ linker_error_printf(prog, "%s shader lacks `main'\n",
+ (shader_list[0]->Type == GL_VERTEX_SHADER)
+ ? "vertex" : "fragment");
+ return NULL;
+ }
+
+ gl_shader *linked = ctx->Driver.NewShader(NULL, 0, main->Type);
+ linked->ir = new(linked) exec_list;
+ clone_ir_list(mem_ctx, linked->ir, main->ir);
+
+ populate_symbol_table(linked);
+
+ /* The a pointer to the main function in the final linked shader (i.e., the
+ * copy of the original shader that contained the main function).
+ */
+ ir_function_signature *const main_sig = get_main_function_signature(linked);
+
+ /* Move any instructions other than variable declarations or function
+ * declarations into main.
+ */
+ exec_node *insertion_point =
+ move_non_declarations(linked->ir, (exec_node *) &main_sig->body, false,
+ linked);
+
+ for (unsigned i = 0; i < num_shaders; i++) {
+ if (shader_list[i] == main)
+ continue;
+
+ insertion_point = move_non_declarations(shader_list[i]->ir,
+ insertion_point, true, linked);
+ }
+
+ /* Resolve initializers for global variables in the linked shader.
+ */
+ unsigned num_linking_shaders = num_shaders;
+ for (unsigned i = 0; i < num_shaders; i++)
+ num_linking_shaders += shader_list[i]->num_builtins_to_link;
+
+ gl_shader **linking_shaders =
+ (gl_shader **) calloc(num_linking_shaders, sizeof(gl_shader *));
+
+ memcpy(linking_shaders, shader_list,
+ sizeof(linking_shaders[0]) * num_shaders);
+
+ unsigned idx = num_shaders;
+ for (unsigned i = 0; i < num_shaders; i++) {
+ memcpy(&linking_shaders[idx], shader_list[i]->builtins_to_link,
+ sizeof(linking_shaders[0]) * shader_list[i]->num_builtins_to_link);
+ idx += shader_list[i]->num_builtins_to_link;
+ }
+
+ assert(idx == num_linking_shaders);
+
+ if (!link_function_calls(prog, linked, linking_shaders,
+ num_linking_shaders)) {
+ ctx->Driver.DeleteShader(ctx, linked);
+ linked = NULL;
+ }
+
+ free(linking_shaders);
+
+ /* Make a pass over all variable declarations to ensure that arrays with
+ * unspecified sizes have a size specified. The size is inferred from the
+ * max_array_access field.
+ */
+ if (linked != NULL) {
+ class array_sizing_visitor : public ir_hierarchical_visitor {
+ public:
+ virtual ir_visitor_status visit(ir_variable *var)
+ {
+ if (var->type->is_array() && (var->type->length == 0)) {
+ const glsl_type *type =
+ glsl_type::get_array_instance(var->type->fields.array,
+ var->max_array_access + 1);
+
+ assert(type != NULL);
+ var->type = type;
+ }
+
+ return visit_continue;
+ }
+ } v;
+
+ v.run(linked->ir);
+ }
+
+ return linked;
+}
+
+
+struct uniform_node {
+ exec_node link;
+ struct gl_uniform *u;
+ unsigned slots;
+};
+
+/**
+ * Update the sizes of linked shader uniform arrays to the maximum
+ * array index used.
+ *
+ * From page 81 (page 95 of the PDF) of the OpenGL 2.1 spec:
+ *
+ * If one or more elements of an array are active,
+ * GetActiveUniform will return the name of the array in name,
+ * subject to the restrictions listed above. The type of the array
+ * is returned in type. The size parameter contains the highest
+ * array element index used, plus one. The compiler or linker
+ * determines the highest index used. There will be only one
+ * active uniform reported by the GL per uniform array.
+
+ */
+static void
+update_array_sizes(struct gl_shader_program *prog)
+{
+ for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
+ if (prog->_LinkedShaders[i] == NULL)
+ continue;
+
+ foreach_list(node, prog->_LinkedShaders[i]->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ if ((var == NULL) || (var->mode != ir_var_uniform &&
+ var->mode != ir_var_in &&
+ var->mode != ir_var_out) ||
+ !var->type->is_array())
+ continue;
+
+ unsigned int size = var->max_array_access;
+ for (unsigned j = 0; j < MESA_SHADER_TYPES; j++) {
+ if (prog->_LinkedShaders[j] == NULL)
+ continue;
+
+ foreach_list(node2, prog->_LinkedShaders[j]->ir) {
+ ir_variable *other_var = ((ir_instruction *) node2)->as_variable();
+ if (!other_var)
+ continue;
+
+ if (strcmp(var->name, other_var->name) == 0 &&
+ other_var->max_array_access > size) {
+ size = other_var->max_array_access;
+ }
+ }
+ }
+
+ if (size + 1 != var->type->fields.array->length) {
+ var->type = glsl_type::get_array_instance(var->type->fields.array,
+ size + 1);
+ /* FINISHME: We should update the types of array
+ * dereferences of this variable now.
+ */
+ }
+ }
+ }
+}
+
+static void
+add_uniform(void *mem_ctx, exec_list *uniforms, struct hash_table *ht,
+ const char *name, const glsl_type *type, GLenum shader_type,
+ unsigned *next_shader_pos, unsigned *total_uniforms)
+{
+ if (type->is_record()) {
+ for (unsigned int i = 0; i < type->length; i++) {
+ const glsl_type *field_type = type->fields.structure[i].type;
+ char *field_name = ralloc_asprintf(mem_ctx, "%s.%s", name,
+ type->fields.structure[i].name);
+
+ add_uniform(mem_ctx, uniforms, ht, field_name, field_type,
+ shader_type, next_shader_pos, total_uniforms);
+ }
+ } else {
+ uniform_node *n = (uniform_node *) hash_table_find(ht, name);
+ unsigned int vec4_slots;
+ const glsl_type *array_elem_type = NULL;
+
+ if (type->is_array()) {
+ array_elem_type = type->fields.array;
+ /* Array of structures. */
+ if (array_elem_type->is_record()) {
+ for (unsigned int i = 0; i < type->length; i++) {
+ char *elem_name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i);
+ add_uniform(mem_ctx, uniforms, ht, elem_name, array_elem_type,
+ shader_type, next_shader_pos, total_uniforms);
+ }
+ return;
+ }
+ }
+
+ /* Fix the storage size of samplers at 1 vec4 each. Be sure to pad out
+ * vectors to vec4 slots.
+ */
+ if (type->is_array()) {
+ if (array_elem_type->is_sampler())
+ vec4_slots = type->length;
+ else
+ vec4_slots = type->length * array_elem_type->matrix_columns;
+ } else if (type->is_sampler()) {
+ vec4_slots = 1;
+ } else {
+ vec4_slots = type->matrix_columns;
+ }
+
+ if (n == NULL) {
+ n = (uniform_node *) calloc(1, sizeof(struct uniform_node));
+ n->u = (gl_uniform *) calloc(1, sizeof(struct gl_uniform));
+ n->slots = vec4_slots;
+
+ n->u->Name = strdup(name);
+ n->u->Type = type;
+ n->u->VertPos = -1;
+ n->u->FragPos = -1;
+ n->u->GeomPos = -1;
+ (*total_uniforms)++;
+
+ hash_table_insert(ht, n, name);
+ uniforms->push_tail(& n->link);
+ }
+
+ switch (shader_type) {
+ case GL_VERTEX_SHADER:
+ n->u->VertPos = *next_shader_pos;
+ break;
+ case GL_FRAGMENT_SHADER:
+ n->u->FragPos = *next_shader_pos;
+ break;
+ case GL_GEOMETRY_SHADER:
+ n->u->GeomPos = *next_shader_pos;
+ break;
+ }
+
+ (*next_shader_pos) += vec4_slots;
+ }
+}
+
+void
+assign_uniform_locations(struct gl_shader_program *prog)
+{
+ /* */
+ exec_list uniforms;
+ unsigned total_uniforms = 0;
+ hash_table *ht = hash_table_ctor(32, hash_table_string_hash,
+ hash_table_string_compare);
+ void *mem_ctx = ralloc_context(NULL);
+
+ for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
+ if (prog->_LinkedShaders[i] == NULL)
+ continue;
+
+ unsigned next_position = 0;
+
+ foreach_list(node, prog->_LinkedShaders[i]->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ if ((var == NULL) || (var->mode != ir_var_uniform))
+ continue;
+
+ if (strncmp(var->name, "gl_", 3) == 0) {
+ /* At the moment, we don't allocate uniform locations for
+ * builtin uniforms. It's permitted by spec, and we'll
+ * likely switch to doing that at some point, but not yet.
+ */
+ continue;
+ }
+
+ var->location = next_position;
+ add_uniform(mem_ctx, &uniforms, ht, var->name, var->type,
+ prog->_LinkedShaders[i]->Type,
+ &next_position, &total_uniforms);
+ }
+ }
+
+ ralloc_free(mem_ctx);
+
+ gl_uniform_list *ul = (gl_uniform_list *)
+ calloc(1, sizeof(gl_uniform_list));
+
+ ul->Size = total_uniforms;
+ ul->NumUniforms = total_uniforms;
+ ul->Uniforms = (gl_uniform *) calloc(total_uniforms, sizeof(gl_uniform));
+
+ unsigned idx = 0;
+ uniform_node *next;
+ for (uniform_node *node = (uniform_node *) uniforms.head
+ ; node->link.next != NULL
+ ; node = next) {
+ next = (uniform_node *) node->link.next;
+
+ node->link.remove();
+ memcpy(&ul->Uniforms[idx], node->u, sizeof(gl_uniform));
+ idx++;
+
+ free(node->u);
+ free(node);
+ }
+
+ hash_table_dtor(ht);
+
+ prog->Uniforms = ul;
+}
+
+
+/**
+ * Find a contiguous set of available bits in a bitmask
+ *
+ * \param used_mask Bits representing used (1) and unused (0) locations
+ * \param needed_count Number of contiguous bits needed.
+ *
+ * \return
+ * Base location of the available bits on success or -1 on failure.
+ */
+int
+find_available_slots(unsigned used_mask, unsigned needed_count)
+{
+ unsigned needed_mask = (1 << needed_count) - 1;
+ const int max_bit_to_test = (8 * sizeof(used_mask)) - needed_count;
+
+ /* The comparison to 32 is redundant, but without it GCC emits "warning:
+ * cannot optimize possibly infinite loops" for the loop below.
+ */
+ if ((needed_count == 0) || (max_bit_to_test < 0) || (max_bit_to_test > 32))
+ return -1;
+
+ for (int i = 0; i <= max_bit_to_test; i++) {
+ if ((needed_mask & ~used_mask) == needed_mask)
+ return i;
+
+ needed_mask <<= 1;
+ }
+
+ return -1;
+}
+
+
+bool
+assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index)
+{
+ /* Mark invalid attribute locations as being used.
+ */
+ unsigned used_locations = (max_attribute_index >= 32)
+ ? ~0 : ~((1 << max_attribute_index) - 1);
+
+ gl_shader *const sh = prog->_LinkedShaders[0];
+ assert(sh->Type == GL_VERTEX_SHADER);
+
+ /* Operate in a total of four passes.
+ *
+ * 1. Invalidate the location assignments for all vertex shader inputs.
+ *
+ * 2. Assign locations for inputs that have user-defined (via
+ * glBindVertexAttribLocation) locatoins.
+ *
+ * 3. Sort the attributes without assigned locations by number of slots
+ * required in decreasing order. Fragmentation caused by attribute
+ * locations assigned by the application may prevent large attributes
+ * from having enough contiguous space.
+ *
+ * 4. Assign locations to any inputs without assigned locations.
+ */
+
+ invalidate_variable_locations(sh, ir_var_in, VERT_ATTRIB_GENERIC0);
+
+ if (prog->Attributes != NULL) {
+ for (unsigned i = 0; i < prog->Attributes->NumParameters; i++) {
+ ir_variable *const var =
+ sh->symbols->get_variable(prog->Attributes->Parameters[i].Name);
+
+ /* Note: attributes that occupy multiple slots, such as arrays or
+ * matrices, may appear in the attrib array multiple times.
+ */
+ if ((var == NULL) || (var->location != -1))
+ continue;
+
+ /* From page 61 of the OpenGL 4.0 spec:
+ *
+ * "LinkProgram will fail if the attribute bindings assigned by
+ * BindAttribLocation do not leave not enough space to assign a
+ * location for an active matrix attribute or an active attribute
+ * array, both of which require multiple contiguous generic
+ * attributes."
+ *
+ * Previous versions of the spec contain similar language but omit the
+ * bit about attribute arrays.
+ *
+ * Page 61 of the OpenGL 4.0 spec also says:
+ *
+ * "It is possible for an application to bind more than one
+ * attribute name to the same location. This is referred to as
+ * aliasing. This will only work if only one of the aliased
+ * attributes is active in the executable program, or if no path
+ * through the shader consumes more than one attribute of a set
+ * of attributes aliased to the same location. A link error can
+ * occur if the linker determines that every path through the
+ * shader consumes multiple aliased attributes, but
+ * implementations are not required to generate an error in this
+ * case."
+ *
+ * These two paragraphs are either somewhat contradictory, or I don't
+ * fully understand one or both of them.
+ */
+ /* FINISHME: The code as currently written does not support attribute
+ * FINISHME: location aliasing (see comment above).
+ */
+ const int attr = prog->Attributes->Parameters[i].StateIndexes[0];
+ const unsigned slots = count_attribute_slots(var->type);
+
+ /* Mask representing the contiguous slots that will be used by this
+ * attribute.
+ */
+ const unsigned use_mask = (1 << slots) - 1;
+
+ /* Generate a link error if the set of bits requested for this
+ * attribute overlaps any previously allocated bits.
+ */
+ if ((~(use_mask << attr) & used_locations) != used_locations) {
+ linker_error_printf(prog,
+ "insufficient contiguous attribute locations "
+ "available for vertex shader input `%s'",
+ var->name);
+ return false;
+ }
+
+ var->location = VERT_ATTRIB_GENERIC0 + attr;
+ used_locations |= (use_mask << attr);
+ }
+ }
+
+ /* Temporary storage for the set of attributes that need locations assigned.
+ */
+ struct temp_attr {
+ unsigned slots;
+ ir_variable *var;
+
+ /* Used below in the call to qsort. */
+ static int compare(const void *a, const void *b)
+ {
+ const temp_attr *const l = (const temp_attr *) a;
+ const temp_attr *const r = (const temp_attr *) b;
+
+ /* Reversed because we want a descending order sort below. */
+ return r->slots - l->slots;
+ }
+ } to_assign[16];
+
+ unsigned num_attr = 0;
+
+ foreach_list(node, sh->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ if ((var == NULL) || (var->mode != ir_var_in))
+ continue;
+
+ if (var->explicit_location) {
+ const unsigned slots = count_attribute_slots(var->type);
+ const unsigned use_mask = (1 << slots) - 1;
+ const int attr = var->location - VERT_ATTRIB_GENERIC0;
+
+ if ((var->location >= (int)(max_attribute_index + VERT_ATTRIB_GENERIC0))
+ || (var->location < 0)) {
+ linker_error_printf(prog,
+ "invalid explicit location %d specified for "
+ "`%s'\n",
+ (var->location < 0) ? var->location : attr,
+ var->name);
+ return false;
+ } else if (var->location >= VERT_ATTRIB_GENERIC0) {
+ used_locations |= (use_mask << attr);
+ }
+ }
+
+ /* The location was explicitly assigned, nothing to do here.
+ */
+ if (var->location != -1)
+ continue;
+
+ to_assign[num_attr].slots = count_attribute_slots(var->type);
+ to_assign[num_attr].var = var;
+ num_attr++;
+ }
+
+ /* If all of the attributes were assigned locations by the application (or
+ * are built-in attributes with fixed locations), return early. This should
+ * be the common case.
+ */
+ if (num_attr == 0)
+ return true;
+
+ qsort(to_assign, num_attr, sizeof(to_assign[0]), temp_attr::compare);
+
+ /* VERT_ATTRIB_GENERIC0 is a psdueo-alias for VERT_ATTRIB_POS. It can only
+ * be explicitly assigned by via glBindAttribLocation. Mark it as reserved
+ * to prevent it from being automatically allocated below.
+ */
+ find_deref_visitor find("gl_Vertex");
+ find.run(sh->ir);
+ if (find.variable_found())
+ used_locations |= (1 << 0);
+
+ for (unsigned i = 0; i < num_attr; i++) {
+ /* Mask representing the contiguous slots that will be used by this
+ * attribute.
+ */
+ const unsigned use_mask = (1 << to_assign[i].slots) - 1;
+
+ int location = find_available_slots(used_locations, to_assign[i].slots);
+
+ if (location < 0) {
+ linker_error_printf(prog,
+ "insufficient contiguous attribute locations "
+ "available for vertex shader input `%s'",
+ to_assign[i].var->name);
+ return false;
+ }
+
+ to_assign[i].var->location = VERT_ATTRIB_GENERIC0 + location;
+ used_locations |= (use_mask << location);
+ }
+
+ return true;
+}
+
+
+/**
+ * Demote shader inputs and outputs that are not used in other stages
+ */
+void
+demote_shader_inputs_and_outputs(gl_shader *sh, enum ir_variable_mode mode)
+{
+ foreach_list(node, sh->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ if ((var == NULL) || (var->mode != int(mode)))
+ continue;
+
+ /* A shader 'in' or 'out' variable is only really an input or output if
+ * its value is used by other shader stages. This will cause the variable
+ * to have a location assigned.
+ */
+ if (var->location == -1) {
+ var->mode = ir_var_auto;
+ }
+ }
+}
+
+
+void
+assign_varying_locations(struct gl_shader_program *prog,
+ gl_shader *producer, gl_shader *consumer)
+{
+ /* FINISHME: Set dynamically when geometry shader support is added. */
+ unsigned output_index = VERT_RESULT_VAR0;
+ unsigned input_index = FRAG_ATTRIB_VAR0;
+
+ /* Operate in a total of three passes.
+ *
+ * 1. Assign locations for any matching inputs and outputs.
+ *
+ * 2. Mark output variables in the producer that do not have locations as
+ * not being outputs. This lets the optimizer eliminate them.
+ *
+ * 3. Mark input variables in the consumer that do not have locations as
+ * not being inputs. This lets the optimizer eliminate them.
+ */
+
+ invalidate_variable_locations(producer, ir_var_out, VERT_RESULT_VAR0);
+ invalidate_variable_locations(consumer, ir_var_in, FRAG_ATTRIB_VAR0);
+
+ foreach_list(node, producer->ir) {
+ ir_variable *const output_var = ((ir_instruction *) node)->as_variable();
+
+ if ((output_var == NULL) || (output_var->mode != ir_var_out)
+ || (output_var->location != -1))
+ continue;
+
+ ir_variable *const input_var =
+ consumer->symbols->get_variable(output_var->name);
+
+ if ((input_var == NULL) || (input_var->mode != ir_var_in))
+ continue;
+
+ assert(input_var->location == -1);
+
+ output_var->location = output_index;
+ input_var->location = input_index;
+
+ /* FINISHME: Support for "varying" records in GLSL 1.50. */
+ assert(!output_var->type->is_record());
+
+ if (output_var->type->is_array()) {
+ const unsigned slots = output_var->type->length
+ * output_var->type->fields.array->matrix_columns;
+
+ output_index += slots;
+ input_index += slots;
+ } else {
+ const unsigned slots = output_var->type->matrix_columns;
+
+ output_index += slots;
+ input_index += slots;
+ }
+ }
+
+ foreach_list(node, consumer->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ if ((var == NULL) || (var->mode != ir_var_in))
+ continue;
+
+ if (var->location == -1) {
+ if (prog->Version <= 120) {
+ /* On page 25 (page 31 of the PDF) of the GLSL 1.20 spec:
+ *
+ * Only those varying variables used (i.e. read) in
+ * the fragment shader executable must be written to
+ * by the vertex shader executable; declaring
+ * superfluous varying variables in a vertex shader is
+ * permissible.
+ *
+ * We interpret this text as meaning that the VS must
+ * write the variable for the FS to read it. See
+ * "glsl1-varying read but not written" in piglit.
+ */
+
+ linker_error_printf(prog, "fragment shader varying %s not written "
+ "by vertex shader\n.", var->name);
+ prog->LinkStatus = false;
+ }
+
+ /* An 'in' variable is only really a shader input if its
+ * value is written by the previous stage.
+ */
+ var->mode = ir_var_auto;
+ }
+ }
+}
+
+
+void
+link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
+{
+ void *mem_ctx = ralloc_context(NULL); // temporary linker context
+
+ prog->LinkStatus = false;
+ prog->Validated = false;
+ prog->_Used = false;
+
+ if (prog->InfoLog != NULL)
+ ralloc_free(prog->InfoLog);
+
+ prog->InfoLog = ralloc_strdup(NULL, "");
+
+ /* Separate the shaders into groups based on their type.
+ */
+ struct gl_shader **vert_shader_list;
+ unsigned num_vert_shaders = 0;
+ struct gl_shader **frag_shader_list;
+ unsigned num_frag_shaders = 0;
+
+ vert_shader_list = (struct gl_shader **)
+ calloc(2 * prog->NumShaders, sizeof(struct gl_shader *));
+ frag_shader_list = &vert_shader_list[prog->NumShaders];
+
+ unsigned min_version = UINT_MAX;
+ unsigned max_version = 0;
+ for (unsigned i = 0; i < prog->NumShaders; i++) {
+ min_version = MIN2(min_version, prog->Shaders[i]->Version);
+ max_version = MAX2(max_version, prog->Shaders[i]->Version);
+
+ switch (prog->Shaders[i]->Type) {
+ case GL_VERTEX_SHADER:
+ vert_shader_list[num_vert_shaders] = prog->Shaders[i];
+ num_vert_shaders++;
+ break;
+ case GL_FRAGMENT_SHADER:
+ frag_shader_list[num_frag_shaders] = prog->Shaders[i];
+ num_frag_shaders++;
+ break;
+ case GL_GEOMETRY_SHADER:
+ /* FINISHME: Support geometry shaders. */
+ assert(prog->Shaders[i]->Type != GL_GEOMETRY_SHADER);
+ break;
+ }
+ }
+
+ /* Previous to GLSL version 1.30, different compilation units could mix and
+ * match shading language versions. With GLSL 1.30 and later, the versions
+ * of all shaders must match.
+ */
+ assert(min_version >= 100);
+ assert(max_version <= 130);
+ if ((max_version >= 130 || min_version == 100)
+ && min_version != max_version) {
+ linker_error_printf(prog, "all shaders must use same shading "
+ "language version\n");
+ goto done;
+ }
+
+ prog->Version = max_version;
+
+ for (unsigned int i = 0; i < MESA_SHADER_TYPES; i++) {
+ if (prog->_LinkedShaders[i] != NULL)
+ ctx->Driver.DeleteShader(ctx, prog->_LinkedShaders[i]);
+
+ prog->_LinkedShaders[i] = NULL;
+ }
+
+ /* Link all shaders for a particular stage and validate the result.
+ */
+ if (num_vert_shaders > 0) {
+ gl_shader *const sh =
+ link_intrastage_shaders(mem_ctx, ctx, prog, vert_shader_list,
+ num_vert_shaders);
+
+ if (sh == NULL)
+ goto done;
+
+ if (!validate_vertex_shader_executable(prog, sh))
+ goto done;
+
+ _mesa_reference_shader(ctx, &prog->_LinkedShaders[MESA_SHADER_VERTEX],
+ sh);
+ }
+
+ if (num_frag_shaders > 0) {
+ gl_shader *const sh =
+ link_intrastage_shaders(mem_ctx, ctx, prog, frag_shader_list,
+ num_frag_shaders);
+
+ if (sh == NULL)
+ goto done;
+
+ if (!validate_fragment_shader_executable(prog, sh))
+ goto done;
+
+ _mesa_reference_shader(ctx, &prog->_LinkedShaders[MESA_SHADER_FRAGMENT],
+ sh);
+ }
+
+ /* Here begins the inter-stage linking phase. Some initial validation is
+ * performed, then locations are assigned for uniforms, attributes, and
+ * varyings.
+ */
+ if (cross_validate_uniforms(prog)) {
+ unsigned prev;
+
+ for (prev = 0; prev < MESA_SHADER_TYPES; prev++) {
+ if (prog->_LinkedShaders[prev] != NULL)
+ break;
+ }
+
+ /* Validate the inputs of each stage with the output of the preceeding
+ * stage.
+ */
+ for (unsigned i = prev + 1; i < MESA_SHADER_TYPES; i++) {
+ if (prog->_LinkedShaders[i] == NULL)
+ continue;
+
+ if (!cross_validate_outputs_to_inputs(prog,
+ prog->_LinkedShaders[prev],
+ prog->_LinkedShaders[i]))
+ goto done;
+
+ prev = i;
+ }
+
+ prog->LinkStatus = true;
+ }
+
+ /* Do common optimization before assigning storage for attributes,
+ * uniforms, and varyings. Later optimization could possibly make
+ * some of that unused.
+ */
+ for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
+ if (prog->_LinkedShaders[i] == NULL)
+ continue;
+
+ while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, 32))
+ ;
+ }
+
+ update_array_sizes(prog);
+
+ assign_uniform_locations(prog);
+
+ if (prog->_LinkedShaders[MESA_SHADER_VERTEX] != NULL) {
+ /* FINISHME: The value of the max_attribute_index parameter is
+ * FINISHME: implementation dependent based on the value of
+ * FINISHME: GL_MAX_VERTEX_ATTRIBS. GL_MAX_VERTEX_ATTRIBS must be
+ * FINISHME: at least 16, so hardcode 16 for now.
+ */
+ if (!assign_attribute_locations(prog, 16)) {
+ prog->LinkStatus = false;
+ goto done;
+ }
+ }
+
+ unsigned prev;
+ for (prev = 0; prev < MESA_SHADER_TYPES; prev++) {
+ if (prog->_LinkedShaders[prev] != NULL)
+ break;
+ }
+
+ for (unsigned i = prev + 1; i < MESA_SHADER_TYPES; i++) {
+ if (prog->_LinkedShaders[i] == NULL)
+ continue;
+
+ assign_varying_locations(prog,
+ prog->_LinkedShaders[prev],
+ prog->_LinkedShaders[i]);
+ prev = i;
+ }
+
+ if (prog->_LinkedShaders[MESA_SHADER_VERTEX] != NULL) {
+ demote_shader_inputs_and_outputs(prog->_LinkedShaders[MESA_SHADER_VERTEX],
+ ir_var_out);
+ }
+
+ if (prog->_LinkedShaders[MESA_SHADER_GEOMETRY] != NULL) {
+ gl_shader *const sh = prog->_LinkedShaders[MESA_SHADER_GEOMETRY];
+
+ demote_shader_inputs_and_outputs(sh, ir_var_in);
+ demote_shader_inputs_and_outputs(sh, ir_var_inout);
+ demote_shader_inputs_and_outputs(sh, ir_var_out);
+ }
+
+ if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] != NULL) {
+ gl_shader *const sh = prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
+
+ demote_shader_inputs_and_outputs(sh, ir_var_in);
+ }
+
+ /* OpenGL ES requires that a vertex shader and a fragment shader both be
+ * present in a linked program. By checking for use of shading language
+ * version 1.00, we also catch the GL_ARB_ES2_compatibility case.
+ */
+ if (ctx->API == API_OPENGLES2 || prog->Version == 100) {
+ if (prog->_LinkedShaders[MESA_SHADER_VERTEX] == NULL) {
+ linker_error_printf(prog, "program lacks a vertex shader\n");
+ prog->LinkStatus = false;
+ } else if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL) {
+ linker_error_printf(prog, "program lacks a fragment shader\n");
+ prog->LinkStatus = false;
+ }
+ }
+
+ /* FINISHME: Assign fragment shader output locations. */
+
+done:
+ free(vert_shader_list);
+
+ for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
+ if (prog->_LinkedShaders[i] == NULL)
+ continue;
+
+ /* Retain any live IR, but trash the rest. */
+ reparent_ir(prog->_LinkedShaders[i]->ir, prog->_LinkedShaders[i]->ir);
+ }
+
+ ralloc_free(mem_ctx);
+}
diff --git a/mesalib/src/glsl/list.h b/mesalib/src/glsl/list.h
index 1d46365fa..fb6f0fbba 100644
--- a/mesalib/src/glsl/list.h
+++ b/mesalib/src/glsl/list.h
@@ -90,6 +90,10 @@ struct exec_node {
/* If the user *does* call delete, that's OK, we will just
* ralloc_free in that case. */
+ static void operator delete(void *node, void *ctx)
+ {
+ ralloc_free(node);
+ }
static void operator delete(void *node)
{
ralloc_free(node);
@@ -299,6 +303,10 @@ struct exec_list {
/* If the user *does* call delete, that's OK, we will just
* ralloc_free in that case. */
+ static void operator delete(void *node, void *ctx)
+ {
+ ralloc_free(node);
+ }
static void operator delete(void *node)
{
ralloc_free(node);
diff --git a/mesalib/src/glsl/loop_controls.cpp b/mesalib/src/glsl/loop_controls.cpp
index 9acbadc50..9b77ef460 100644
--- a/mesalib/src/glsl/loop_controls.cpp
+++ b/mesalib/src/glsl/loop_controls.cpp
@@ -1,304 +1,304 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include <limits.h>
-#include "main/compiler.h"
-#include "glsl_types.h"
-#include "loop_analysis.h"
-#include "ir_hierarchical_visitor.h"
-
-/**
- * Find an initializer of a variable outside a loop
- *
- * Works backwards from the loop to find the pre-loop value of the variable.
- * This is used, for example, to find the initial value of loop induction
- * variables.
- *
- * \param loop Loop where \c var is an induction variable
- * \param var Variable whose initializer is to be found
- *
- * \return
- * The \c ir_rvalue assigned to the variable outside the loop. May return
- * \c NULL if no initializer can be found.
- */
-ir_rvalue *
-find_initial_value(ir_loop *loop, ir_variable *var)
-{
- for (exec_node *node = loop->prev;
- !node->is_head_sentinel();
- node = node->prev) {
- ir_instruction *ir = (ir_instruction *) node;
-
- switch (ir->ir_type) {
- case ir_type_call:
- case ir_type_loop:
- case ir_type_loop_jump:
- case ir_type_return:
- case ir_type_if:
- return NULL;
-
- case ir_type_function:
- case ir_type_function_signature:
- assert(!"Should not get here.");
- return NULL;
-
- case ir_type_assignment: {
- ir_assignment *assign = ir->as_assignment();
- ir_variable *assignee = assign->lhs->whole_variable_referenced();
-
- if (assignee == var)
- return (assign->condition != NULL) ? NULL : assign->rhs;
-
- break;
- }
-
- default:
- break;
- }
- }
-
- return NULL;
-}
-
-
-int
-calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment,
- enum ir_expression_operation op)
-{
- if (from == NULL || to == NULL || increment == NULL)
- return -1;
-
- void *mem_ctx = ralloc_context(NULL);
-
- ir_expression *const sub =
- new(mem_ctx) ir_expression(ir_binop_sub, from->type, to, from);
-
- ir_expression *const div =
- new(mem_ctx) ir_expression(ir_binop_div, sub->type, sub, increment);
-
- ir_constant *iter = div->constant_expression_value();
-
- if (iter == NULL)
- return -1;
-
- if (!iter->type->is_integer()) {
- ir_rvalue *cast =
- new(mem_ctx) ir_expression(ir_unop_f2i, glsl_type::int_type, iter,
- NULL);
-
- iter = cast->constant_expression_value();
- }
-
- int iter_value = iter->get_int_component(0);
-
- /* Make sure that the calculated number of iterations satisfies the exit
- * condition. This is needed to catch off-by-one errors and some types of
- * ill-formed loops. For example, we need to detect that the following
- * loop does not have a maximum iteration count.
- *
- * for (float x = 0.0; x != 0.9; x += 0.2)
- * ;
- */
- const int bias[] = { -1, 0, 1 };
- bool valid_loop = false;
-
- for (unsigned i = 0; i < Elements(bias); i++) {
- iter = (increment->type->is_integer())
- ? new(mem_ctx) ir_constant(iter_value + bias[i])
- : new(mem_ctx) ir_constant(float(iter_value + bias[i]));
-
- ir_expression *const mul =
- new(mem_ctx) ir_expression(ir_binop_mul, increment->type, iter,
- increment);
-
- ir_expression *const add =
- new(mem_ctx) ir_expression(ir_binop_add, mul->type, mul, from);
-
- ir_expression *const cmp =
- new(mem_ctx) ir_expression(op, glsl_type::bool_type, add, to);
-
- ir_constant *const cmp_result = cmp->constant_expression_value();
-
- assert(cmp_result != NULL);
- if (cmp_result->get_bool_component(0)) {
- iter_value += bias[i];
- valid_loop = true;
- break;
- }
- }
-
- ralloc_free(mem_ctx);
- return (valid_loop) ? iter_value : -1;
-}
-
-
-class loop_control_visitor : public ir_hierarchical_visitor {
-public:
- loop_control_visitor(loop_state *state)
- {
- this->state = state;
- this->progress = false;
- }
-
- virtual ir_visitor_status visit_leave(ir_loop *ir);
-
- loop_state *state;
-
- bool progress;
-};
-
-
-ir_visitor_status
-loop_control_visitor::visit_leave(ir_loop *ir)
-{
- loop_variable_state *const ls = this->state->get(ir);
-
- /* If we've entered a loop that hasn't been analyzed, something really,
- * really bad has happened.
- */
- if (ls == NULL) {
- assert(ls != NULL);
- return visit_continue;
- }
-
- /* Search the loop terminating conditions for one of the form 'i < c' where
- * i is a loop induction variable, c is a constant, and < is any relative
- * operator.
- */
- int max_iterations = ls->max_iterations;
-
- if(ir->from && ir->to && ir->increment)
- max_iterations = calculate_iterations(ir->from, ir->to, ir->increment, (ir_expression_operation)ir->cmp);
-
- if(max_iterations < 0)
- max_iterations = INT_MAX;
-
- foreach_list(node, &ls->terminators) {
- loop_terminator *t = (loop_terminator *) node;
- ir_if *if_stmt = t->ir;
-
- /* If-statements can be either 'if (expr)' or 'if (deref)'. We only care
- * about the former here.
- */
- ir_expression *cond = if_stmt->condition->as_expression();
- if (cond == NULL)
- continue;
-
- switch (cond->operation) {
- case ir_binop_less:
- case ir_binop_greater:
- case ir_binop_lequal:
- case ir_binop_gequal: {
- /* The expressions that we care about will either be of the form
- * 'counter < limit' or 'limit < counter'. Figure out which is
- * which.
- */
- ir_rvalue *counter = cond->operands[0]->as_dereference_variable();
- ir_constant *limit = cond->operands[1]->as_constant();
- enum ir_expression_operation cmp = cond->operation;
-
- if (limit == NULL) {
- counter = cond->operands[1]->as_dereference_variable();
- limit = cond->operands[0]->as_constant();
-
- switch (cmp) {
- case ir_binop_less: cmp = ir_binop_gequal; break;
- case ir_binop_greater: cmp = ir_binop_lequal; break;
- case ir_binop_lequal: cmp = ir_binop_greater; break;
- case ir_binop_gequal: cmp = ir_binop_less; break;
- default: assert(!"Should not get here.");
- }
- }
-
- if ((counter == NULL) || (limit == NULL))
- break;
-
- ir_variable *var = counter->variable_referenced();
-
- ir_rvalue *init = find_initial_value(ir, var);
-
- foreach_list(iv_node, &ls->induction_variables) {
- loop_variable *lv = (loop_variable *) iv_node;
-
- if (lv->var == var) {
- const int iterations = calculate_iterations(init, limit,
- lv->increment,
- cmp);
- if (iterations >= 0) {
- /* If the new iteration count is lower than the previously
- * believed iteration count, update the loop control values.
- */
- if (iterations < max_iterations) {
- ir->from = init->clone(ir, NULL);
- ir->to = limit->clone(ir, NULL);
- ir->increment = lv->increment->clone(ir, NULL);
- ir->counter = lv->var;
- ir->cmp = cmp;
-
- max_iterations = iterations;
- }
-
- /* Remove the conditional break statement. The loop
- * controls are now set such that the exit condition will be
- * satisfied.
- */
- if_stmt->remove();
-
- assert(ls->num_loop_jumps > 0);
- ls->num_loop_jumps--;
-
- this->progress = true;
- }
-
- break;
- }
- }
- break;
- }
-
- default:
- break;
- }
- }
-
- /* If we have proven the one of the loop exit conditions is satisifed before
- * running the loop once, remove the loop.
- */
- if (max_iterations == 0)
- ir->remove();
- else
- ls->max_iterations = max_iterations;
-
- return visit_continue;
-}
-
-
-bool
-set_loop_controls(exec_list *instructions, loop_state *ls)
-{
- loop_control_visitor v(ls);
-
- v.run(instructions);
-
- return v.progress;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <limits.h>
+#include "main/compiler.h"
+#include "glsl_types.h"
+#include "loop_analysis.h"
+#include "ir_hierarchical_visitor.h"
+
+/**
+ * Find an initializer of a variable outside a loop
+ *
+ * Works backwards from the loop to find the pre-loop value of the variable.
+ * This is used, for example, to find the initial value of loop induction
+ * variables.
+ *
+ * \param loop Loop where \c var is an induction variable
+ * \param var Variable whose initializer is to be found
+ *
+ * \return
+ * The \c ir_rvalue assigned to the variable outside the loop. May return
+ * \c NULL if no initializer can be found.
+ */
+ir_rvalue *
+find_initial_value(ir_loop *loop, ir_variable *var)
+{
+ for (exec_node *node = loop->prev;
+ !node->is_head_sentinel();
+ node = node->prev) {
+ ir_instruction *ir = (ir_instruction *) node;
+
+ switch (ir->ir_type) {
+ case ir_type_call:
+ case ir_type_loop:
+ case ir_type_loop_jump:
+ case ir_type_return:
+ case ir_type_if:
+ return NULL;
+
+ case ir_type_function:
+ case ir_type_function_signature:
+ assert(!"Should not get here.");
+ return NULL;
+
+ case ir_type_assignment: {
+ ir_assignment *assign = ir->as_assignment();
+ ir_variable *assignee = assign->lhs->whole_variable_referenced();
+
+ if (assignee == var)
+ return (assign->condition != NULL) ? NULL : assign->rhs;
+
+ break;
+ }
+
+ default:
+ break;
+ }
+ }
+
+ return NULL;
+}
+
+
+int
+calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment,
+ enum ir_expression_operation op)
+{
+ if (from == NULL || to == NULL || increment == NULL)
+ return -1;
+
+ void *mem_ctx = ralloc_context(NULL);
+
+ ir_expression *const sub =
+ new(mem_ctx) ir_expression(ir_binop_sub, from->type, to, from);
+
+ ir_expression *const div =
+ new(mem_ctx) ir_expression(ir_binop_div, sub->type, sub, increment);
+
+ ir_constant *iter = div->constant_expression_value();
+
+ if (iter == NULL)
+ return -1;
+
+ if (!iter->type->is_integer()) {
+ ir_rvalue *cast =
+ new(mem_ctx) ir_expression(ir_unop_f2i, glsl_type::int_type, iter,
+ NULL);
+
+ iter = cast->constant_expression_value();
+ }
+
+ int iter_value = iter->get_int_component(0);
+
+ /* Make sure that the calculated number of iterations satisfies the exit
+ * condition. This is needed to catch off-by-one errors and some types of
+ * ill-formed loops. For example, we need to detect that the following
+ * loop does not have a maximum iteration count.
+ *
+ * for (float x = 0.0; x != 0.9; x += 0.2)
+ * ;
+ */
+ const int bias[] = { -1, 0, 1 };
+ bool valid_loop = false;
+
+ for (unsigned i = 0; i < Elements(bias); i++) {
+ iter = (increment->type->is_integer())
+ ? new(mem_ctx) ir_constant(iter_value + bias[i])
+ : new(mem_ctx) ir_constant(float(iter_value + bias[i]));
+
+ ir_expression *const mul =
+ new(mem_ctx) ir_expression(ir_binop_mul, increment->type, iter,
+ increment);
+
+ ir_expression *const add =
+ new(mem_ctx) ir_expression(ir_binop_add, mul->type, mul, from);
+
+ ir_expression *const cmp =
+ new(mem_ctx) ir_expression(op, glsl_type::bool_type, add, to);
+
+ ir_constant *const cmp_result = cmp->constant_expression_value();
+
+ assert(cmp_result != NULL);
+ if (cmp_result->get_bool_component(0)) {
+ iter_value += bias[i];
+ valid_loop = true;
+ break;
+ }
+ }
+
+ ralloc_free(mem_ctx);
+ return (valid_loop) ? iter_value : -1;
+}
+
+
+class loop_control_visitor : public ir_hierarchical_visitor {
+public:
+ loop_control_visitor(loop_state *state)
+ {
+ this->state = state;
+ this->progress = false;
+ }
+
+ virtual ir_visitor_status visit_leave(ir_loop *ir);
+
+ loop_state *state;
+
+ bool progress;
+};
+
+
+ir_visitor_status
+loop_control_visitor::visit_leave(ir_loop *ir)
+{
+ loop_variable_state *const ls = this->state->get(ir);
+
+ /* If we've entered a loop that hasn't been analyzed, something really,
+ * really bad has happened.
+ */
+ if (ls == NULL) {
+ assert(ls != NULL);
+ return visit_continue;
+ }
+
+ /* Search the loop terminating conditions for one of the form 'i < c' where
+ * i is a loop induction variable, c is a constant, and < is any relative
+ * operator.
+ */
+ int max_iterations = ls->max_iterations;
+
+ if(ir->from && ir->to && ir->increment)
+ max_iterations = calculate_iterations(ir->from, ir->to, ir->increment, (ir_expression_operation)ir->cmp);
+
+ if(max_iterations < 0)
+ max_iterations = INT_MAX;
+
+ foreach_list(node, &ls->terminators) {
+ loop_terminator *t = (loop_terminator *) node;
+ ir_if *if_stmt = t->ir;
+
+ /* If-statements can be either 'if (expr)' or 'if (deref)'. We only care
+ * about the former here.
+ */
+ ir_expression *cond = if_stmt->condition->as_expression();
+ if (cond == NULL)
+ continue;
+
+ switch (cond->operation) {
+ case ir_binop_less:
+ case ir_binop_greater:
+ case ir_binop_lequal:
+ case ir_binop_gequal: {
+ /* The expressions that we care about will either be of the form
+ * 'counter < limit' or 'limit < counter'. Figure out which is
+ * which.
+ */
+ ir_rvalue *counter = cond->operands[0]->as_dereference_variable();
+ ir_constant *limit = cond->operands[1]->as_constant();
+ enum ir_expression_operation cmp = cond->operation;
+
+ if (limit == NULL) {
+ counter = cond->operands[1]->as_dereference_variable();
+ limit = cond->operands[0]->as_constant();
+
+ switch (cmp) {
+ case ir_binop_less: cmp = ir_binop_gequal; break;
+ case ir_binop_greater: cmp = ir_binop_lequal; break;
+ case ir_binop_lequal: cmp = ir_binop_greater; break;
+ case ir_binop_gequal: cmp = ir_binop_less; break;
+ default: assert(!"Should not get here.");
+ }
+ }
+
+ if ((counter == NULL) || (limit == NULL))
+ break;
+
+ ir_variable *var = counter->variable_referenced();
+
+ ir_rvalue *init = find_initial_value(ir, var);
+
+ foreach_list(iv_node, &ls->induction_variables) {
+ loop_variable *lv = (loop_variable *) iv_node;
+
+ if (lv->var == var) {
+ const int iterations = calculate_iterations(init, limit,
+ lv->increment,
+ cmp);
+ if (iterations >= 0) {
+ /* If the new iteration count is lower than the previously
+ * believed iteration count, update the loop control values.
+ */
+ if (iterations < max_iterations) {
+ ir->from = init->clone(ir, NULL);
+ ir->to = limit->clone(ir, NULL);
+ ir->increment = lv->increment->clone(ir, NULL);
+ ir->counter = lv->var;
+ ir->cmp = cmp;
+
+ max_iterations = iterations;
+ }
+
+ /* Remove the conditional break statement. The loop
+ * controls are now set such that the exit condition will be
+ * satisfied.
+ */
+ if_stmt->remove();
+
+ assert(ls->num_loop_jumps > 0);
+ ls->num_loop_jumps--;
+
+ this->progress = true;
+ }
+
+ break;
+ }
+ }
+ break;
+ }
+
+ default:
+ break;
+ }
+ }
+
+ /* If we have proven the one of the loop exit conditions is satisifed before
+ * running the loop once, remove the loop.
+ */
+ if (max_iterations == 0)
+ ir->remove();
+ else
+ ls->max_iterations = max_iterations;
+
+ return visit_continue;
+}
+
+
+bool
+set_loop_controls(exec_list *instructions, loop_state *ls)
+{
+ loop_control_visitor v(ls);
+
+ v.run(instructions);
+
+ return v.progress;
+}
diff --git a/mesalib/src/glsl/lower_mat_op_to_vec.cpp b/mesalib/src/glsl/lower_mat_op_to_vec.cpp
index 8cbbfa713..dc46ed417 100644
--- a/mesalib/src/glsl/lower_mat_op_to_vec.cpp
+++ b/mesalib/src/glsl/lower_mat_op_to_vec.cpp
@@ -1,490 +1,490 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file lower_mat_op_to_vec.cpp
- *
- * Breaks matrix operation expressions down to a series of vector operations.
- *
- * Generally this is how we have to codegen matrix operations for a
- * GPU, so this gives us the chance to constant fold operations on a
- * column or row.
- */
-
-#include "ir.h"
-#include "ir_expression_flattening.h"
-#include "glsl_types.h"
-
-class ir_mat_op_to_vec_visitor : public ir_hierarchical_visitor {
-public:
- ir_mat_op_to_vec_visitor()
- {
- this->made_progress = false;
- this->mem_ctx = NULL;
- }
-
- ir_visitor_status visit_leave(ir_assignment *);
-
- ir_dereference *get_column(ir_variable *var, int col);
- ir_rvalue *get_element(ir_variable *var, int col, int row);
-
- void do_mul_mat_mat(ir_variable *result_var,
- ir_variable *a_var, ir_variable *b_var);
- void do_mul_mat_vec(ir_variable *result_var,
- ir_variable *a_var, ir_variable *b_var);
- void do_mul_vec_mat(ir_variable *result_var,
- ir_variable *a_var, ir_variable *b_var);
- void do_mul_mat_scalar(ir_variable *result_var,
- ir_variable *a_var, ir_variable *b_var);
- void do_equal_mat_mat(ir_variable *result_var, ir_variable *a_var,
- ir_variable *b_var, bool test_equal);
-
- void *mem_ctx;
- bool made_progress;
-};
-
-static bool
-mat_op_to_vec_predicate(ir_instruction *ir)
-{
- ir_expression *expr = ir->as_expression();
- unsigned int i;
-
- if (!expr)
- return false;
-
- for (i = 0; i < expr->get_num_operands(); i++) {
- if (expr->operands[i]->type->is_matrix())
- return true;
- }
-
- return false;
-}
-
-bool
-do_mat_op_to_vec(exec_list *instructions)
-{
- ir_mat_op_to_vec_visitor v;
-
- /* Pull out any matrix expression to a separate assignment to a
- * temp. This will make our handling of the breakdown to
- * operations on the matrix's vector components much easier.
- */
- do_expression_flattening(instructions, mat_op_to_vec_predicate);
-
- visit_list_elements(&v, instructions);
-
- return v.made_progress;
-}
-
-ir_rvalue *
-ir_mat_op_to_vec_visitor::get_element(ir_variable *var, int col, int row)
-{
- ir_dereference *deref;
-
- deref = new(mem_ctx) ir_dereference_variable(var);
-
- if (var->type->is_matrix()) {
- deref = new(mem_ctx) ir_dereference_array(var,
- new(mem_ctx) ir_constant(col));
- } else {
- assert(col == 0);
- }
-
- return new(mem_ctx) ir_swizzle(deref, row, 0, 0, 0, 1);
-}
-
-ir_dereference *
-ir_mat_op_to_vec_visitor::get_column(ir_variable *var, int row)
-{
- ir_dereference *deref;
-
- if (!var->type->is_matrix()) {
- deref = new(mem_ctx) ir_dereference_variable(var);
- } else {
- deref = new(mem_ctx) ir_dereference_variable(var);
- deref = new(mem_ctx) ir_dereference_array(deref,
- new(mem_ctx) ir_constant(row));
- }
-
- return deref;
-}
-
-void
-ir_mat_op_to_vec_visitor::do_mul_mat_mat(ir_variable *result_var,
- ir_variable *a_var,
- ir_variable *b_var)
-{
- int b_col, i;
- ir_assignment *assign;
- ir_expression *expr;
-
- for (b_col = 0; b_col < b_var->type->matrix_columns; b_col++) {
- ir_rvalue *a = get_column(a_var, 0);
- ir_rvalue *b = get_element(b_var, b_col, 0);
-
- /* first column */
- expr = new(mem_ctx) ir_expression(ir_binop_mul,
- a->type,
- a,
- b);
-
- /* following columns */
- for (i = 1; i < a_var->type->matrix_columns; i++) {
- ir_expression *mul_expr;
-
- a = get_column(a_var, i);
- b = get_element(b_var, b_col, i);
-
- mul_expr = new(mem_ctx) ir_expression(ir_binop_mul,
- a->type,
- a,
- b);
- expr = new(mem_ctx) ir_expression(ir_binop_add,
- a->type,
- expr,
- mul_expr);
- }
-
- ir_rvalue *result = get_column(result_var, b_col);
- assign = new(mem_ctx) ir_assignment(result,
- expr,
- NULL);
- base_ir->insert_before(assign);
- }
-}
-
-void
-ir_mat_op_to_vec_visitor::do_mul_mat_vec(ir_variable *result_var,
- ir_variable *a_var,
- ir_variable *b_var)
-{
- int i;
- ir_rvalue *a = get_column(a_var, 0);
- ir_rvalue *b = get_element(b_var, 0, 0);
- ir_assignment *assign;
- ir_expression *expr;
-
- /* first column */
- expr = new(mem_ctx) ir_expression(ir_binop_mul,
- result_var->type,
- a,
- b);
-
- /* following columns */
- for (i = 1; i < a_var->type->matrix_columns; i++) {
- ir_expression *mul_expr;
-
- a = get_column(a_var, i);
- b = get_element(b_var, 0, i);
-
- mul_expr = new(mem_ctx) ir_expression(ir_binop_mul,
- result_var->type,
- a,
- b);
- expr = new(mem_ctx) ir_expression(ir_binop_add,
- result_var->type,
- expr,
- mul_expr);
- }
-
- ir_rvalue *result = new(mem_ctx) ir_dereference_variable(result_var);
- assign = new(mem_ctx) ir_assignment(result,
- expr,
- NULL);
- base_ir->insert_before(assign);
-}
-
-void
-ir_mat_op_to_vec_visitor::do_mul_vec_mat(ir_variable *result_var,
- ir_variable *a_var,
- ir_variable *b_var)
-{
- int i;
-
- for (i = 0; i < b_var->type->matrix_columns; i++) {
- ir_rvalue *a = new(mem_ctx) ir_dereference_variable(a_var);
- ir_rvalue *b = get_column(b_var, i);
- ir_rvalue *result;
- ir_expression *column_expr;
- ir_assignment *column_assign;
-
- result = new(mem_ctx) ir_dereference_variable(result_var);
- result = new(mem_ctx) ir_swizzle(result, i, 0, 0, 0, 1);
-
- column_expr = new(mem_ctx) ir_expression(ir_binop_dot,
- result->type,
- a,
- b);
-
- column_assign = new(mem_ctx) ir_assignment(result,
- column_expr,
- NULL);
- base_ir->insert_before(column_assign);
- }
-}
-
-void
-ir_mat_op_to_vec_visitor::do_mul_mat_scalar(ir_variable *result_var,
- ir_variable *a_var,
- ir_variable *b_var)
-{
- int i;
-
- for (i = 0; i < a_var->type->matrix_columns; i++) {
- ir_rvalue *a = get_column(a_var, i);
- ir_rvalue *b = new(mem_ctx) ir_dereference_variable(b_var);
- ir_rvalue *result = get_column(result_var, i);
- ir_expression *column_expr;
- ir_assignment *column_assign;
-
- column_expr = new(mem_ctx) ir_expression(ir_binop_mul,
- result->type,
- a,
- b);
-
- column_assign = new(mem_ctx) ir_assignment(result,
- column_expr,
- NULL);
- base_ir->insert_before(column_assign);
- }
-}
-
-void
-ir_mat_op_to_vec_visitor::do_equal_mat_mat(ir_variable *result_var,
- ir_variable *a_var,
- ir_variable *b_var,
- bool test_equal)
-{
- /* This essentially implements the following GLSL:
- *
- * bool equal(mat4 a, mat4 b)
- * {
- * return !any(bvec4(a[0] != b[0],
- * a[1] != b[1],
- * a[2] != b[2],
- * a[3] != b[3]);
- * }
- *
- * bool nequal(mat4 a, mat4 b)
- * {
- * return any(bvec4(a[0] != b[0],
- * a[1] != b[1],
- * a[2] != b[2],
- * a[3] != b[3]);
- * }
- */
- const unsigned columns = a_var->type->matrix_columns;
- const glsl_type *const bvec_type =
- glsl_type::get_instance(GLSL_TYPE_BOOL, columns, 1);
-
- ir_variable *const tmp_bvec =
- new(this->mem_ctx) ir_variable(bvec_type, "mat_cmp_bvec",
- ir_var_temporary);
- this->base_ir->insert_before(tmp_bvec);
-
- for (unsigned i = 0; i < columns; i++) {
- ir_dereference *const op0 = get_column(a_var, i);
- ir_dereference *const op1 = get_column(b_var, i);
-
- ir_expression *const cmp =
- new(this->mem_ctx) ir_expression(ir_binop_any_nequal,
- glsl_type::bool_type, op0, op1);
-
- ir_dereference *const lhs =
- new(this->mem_ctx) ir_dereference_variable(tmp_bvec);
-
- ir_assignment *const assign =
- new(this->mem_ctx) ir_assignment(lhs, cmp, NULL, (1U << i));
-
- this->base_ir->insert_before(assign);
- }
-
- ir_rvalue *const val =
- new(this->mem_ctx) ir_dereference_variable(tmp_bvec);
-
- ir_expression *any =
- new(this->mem_ctx) ir_expression(ir_unop_any, glsl_type::bool_type,
- val, NULL);
-
- if (test_equal)
- any = new(this->mem_ctx) ir_expression(ir_unop_logic_not,
- glsl_type::bool_type,
- any, NULL);
-
- ir_rvalue *const result =
- new(this->mem_ctx) ir_dereference_variable(result_var);
-
- ir_assignment *const assign =
- new(mem_ctx) ir_assignment(result, any, NULL);
- base_ir->insert_before(assign);
-}
-
-static bool
-has_matrix_operand(const ir_expression *expr, unsigned &columns)
-{
- for (unsigned i = 0; i < expr->get_num_operands(); i++) {
- if (expr->operands[i]->type->is_matrix()) {
- columns = expr->operands[i]->type->matrix_columns;
- return true;
- }
- }
-
- return false;
-}
-
-
-ir_visitor_status
-ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
-{
- ir_expression *orig_expr = orig_assign->rhs->as_expression();
- unsigned int i, matrix_columns = 1;
- ir_variable *op_var[2];
-
- if (!orig_expr)
- return visit_continue;
-
- if (!has_matrix_operand(orig_expr, matrix_columns))
- return visit_continue;
-
- assert(orig_expr->get_num_operands() <= 2);
-
- mem_ctx = ralloc_parent(orig_assign);
-
- ir_dereference_variable *lhs_deref =
- orig_assign->lhs->as_dereference_variable();
- assert(lhs_deref);
-
- ir_variable *result_var = lhs_deref->var;
-
- /* Store the expression operands in temps so we can use them
- * multiple times.
- */
- for (i = 0; i < orig_expr->get_num_operands(); i++) {
- ir_assignment *assign;
-
- op_var[i] = new(mem_ctx) ir_variable(orig_expr->operands[i]->type,
- "mat_op_to_vec",
- ir_var_temporary);
- base_ir->insert_before(op_var[i]);
-
- lhs_deref = new(mem_ctx) ir_dereference_variable(op_var[i]);
- assign = new(mem_ctx) ir_assignment(lhs_deref,
- orig_expr->operands[i],
- NULL);
- base_ir->insert_before(assign);
- }
-
- /* OK, time to break down this matrix operation. */
- switch (orig_expr->operation) {
- case ir_unop_neg: {
- const unsigned mask = (1U << result_var->type->vector_elements) - 1;
-
- /* Apply the operation to each column.*/
- for (i = 0; i < matrix_columns; i++) {
- ir_rvalue *op0 = get_column(op_var[0], i);
- ir_dereference *result = get_column(result_var, i);
- ir_expression *column_expr;
- ir_assignment *column_assign;
-
- column_expr = new(mem_ctx) ir_expression(orig_expr->operation,
- result->type,
- op0,
- NULL);
-
- column_assign = new(mem_ctx) ir_assignment(result,
- column_expr,
- NULL,
- mask);
- assert(column_assign->write_mask != 0);
- base_ir->insert_before(column_assign);
- }
- break;
- }
- case ir_binop_add:
- case ir_binop_sub:
- case ir_binop_div:
- case ir_binop_mod: {
- const unsigned mask = (1U << result_var->type->vector_elements) - 1;
-
- /* For most operations, the matrix version is just going
- * column-wise through and applying the operation to each column
- * if available.
- */
- for (i = 0; i < matrix_columns; i++) {
- ir_rvalue *op0 = get_column(op_var[0], i);
- ir_rvalue *op1 = get_column(op_var[1], i);
- ir_dereference *result = get_column(result_var, i);
- ir_expression *column_expr;
- ir_assignment *column_assign;
-
- column_expr = new(mem_ctx) ir_expression(orig_expr->operation,
- result->type,
- op0,
- op1);
-
- column_assign = new(mem_ctx) ir_assignment(result,
- column_expr,
- NULL,
- mask);
- assert(column_assign->write_mask != 0);
- base_ir->insert_before(column_assign);
- }
- break;
- }
- case ir_binop_mul:
- if (op_var[0]->type->is_matrix()) {
- if (op_var[1]->type->is_matrix()) {
- do_mul_mat_mat(result_var, op_var[0], op_var[1]);
- } else if (op_var[1]->type->is_vector()) {
- do_mul_mat_vec(result_var, op_var[0], op_var[1]);
- } else {
- assert(op_var[1]->type->is_scalar());
- do_mul_mat_scalar(result_var, op_var[0], op_var[1]);
- }
- } else {
- assert(op_var[1]->type->is_matrix());
- if (op_var[0]->type->is_vector()) {
- do_mul_vec_mat(result_var, op_var[0], op_var[1]);
- } else {
- assert(op_var[0]->type->is_scalar());
- do_mul_mat_scalar(result_var, op_var[1], op_var[0]);
- }
- }
- break;
-
- case ir_binop_all_equal:
- case ir_binop_any_nequal:
- do_equal_mat_mat(result_var, op_var[1], op_var[0],
- (orig_expr->operation == ir_binop_all_equal));
- break;
-
- default:
- printf("FINISHME: Handle matrix operation for %s\n",
- orig_expr->operator_string());
- abort();
- }
- orig_assign->remove();
- this->made_progress = true;
-
- return visit_continue;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file lower_mat_op_to_vec.cpp
+ *
+ * Breaks matrix operation expressions down to a series of vector operations.
+ *
+ * Generally this is how we have to codegen matrix operations for a
+ * GPU, so this gives us the chance to constant fold operations on a
+ * column or row.
+ */
+
+#include "ir.h"
+#include "ir_expression_flattening.h"
+#include "glsl_types.h"
+
+class ir_mat_op_to_vec_visitor : public ir_hierarchical_visitor {
+public:
+ ir_mat_op_to_vec_visitor()
+ {
+ this->made_progress = false;
+ this->mem_ctx = NULL;
+ }
+
+ ir_visitor_status visit_leave(ir_assignment *);
+
+ ir_dereference *get_column(ir_variable *var, int col);
+ ir_rvalue *get_element(ir_variable *var, int col, int row);
+
+ void do_mul_mat_mat(ir_variable *result_var,
+ ir_variable *a_var, ir_variable *b_var);
+ void do_mul_mat_vec(ir_variable *result_var,
+ ir_variable *a_var, ir_variable *b_var);
+ void do_mul_vec_mat(ir_variable *result_var,
+ ir_variable *a_var, ir_variable *b_var);
+ void do_mul_mat_scalar(ir_variable *result_var,
+ ir_variable *a_var, ir_variable *b_var);
+ void do_equal_mat_mat(ir_variable *result_var, ir_variable *a_var,
+ ir_variable *b_var, bool test_equal);
+
+ void *mem_ctx;
+ bool made_progress;
+};
+
+static bool
+mat_op_to_vec_predicate(ir_instruction *ir)
+{
+ ir_expression *expr = ir->as_expression();
+ unsigned int i;
+
+ if (!expr)
+ return false;
+
+ for (i = 0; i < expr->get_num_operands(); i++) {
+ if (expr->operands[i]->type->is_matrix())
+ return true;
+ }
+
+ return false;
+}
+
+bool
+do_mat_op_to_vec(exec_list *instructions)
+{
+ ir_mat_op_to_vec_visitor v;
+
+ /* Pull out any matrix expression to a separate assignment to a
+ * temp. This will make our handling of the breakdown to
+ * operations on the matrix's vector components much easier.
+ */
+ do_expression_flattening(instructions, mat_op_to_vec_predicate);
+
+ visit_list_elements(&v, instructions);
+
+ return v.made_progress;
+}
+
+ir_rvalue *
+ir_mat_op_to_vec_visitor::get_element(ir_variable *var, int col, int row)
+{
+ ir_dereference *deref;
+
+ deref = new(mem_ctx) ir_dereference_variable(var);
+
+ if (var->type->is_matrix()) {
+ deref = new(mem_ctx) ir_dereference_array(var,
+ new(mem_ctx) ir_constant(col));
+ } else {
+ assert(col == 0);
+ }
+
+ return new(mem_ctx) ir_swizzle(deref, row, 0, 0, 0, 1);
+}
+
+ir_dereference *
+ir_mat_op_to_vec_visitor::get_column(ir_variable *var, int row)
+{
+ ir_dereference *deref;
+
+ if (!var->type->is_matrix()) {
+ deref = new(mem_ctx) ir_dereference_variable(var);
+ } else {
+ deref = new(mem_ctx) ir_dereference_variable(var);
+ deref = new(mem_ctx) ir_dereference_array(deref,
+ new(mem_ctx) ir_constant(row));
+ }
+
+ return deref;
+}
+
+void
+ir_mat_op_to_vec_visitor::do_mul_mat_mat(ir_variable *result_var,
+ ir_variable *a_var,
+ ir_variable *b_var)
+{
+ int b_col, i;
+ ir_assignment *assign;
+ ir_expression *expr;
+
+ for (b_col = 0; b_col < b_var->type->matrix_columns; b_col++) {
+ ir_rvalue *a = get_column(a_var, 0);
+ ir_rvalue *b = get_element(b_var, b_col, 0);
+
+ /* first column */
+ expr = new(mem_ctx) ir_expression(ir_binop_mul,
+ a->type,
+ a,
+ b);
+
+ /* following columns */
+ for (i = 1; i < a_var->type->matrix_columns; i++) {
+ ir_expression *mul_expr;
+
+ a = get_column(a_var, i);
+ b = get_element(b_var, b_col, i);
+
+ mul_expr = new(mem_ctx) ir_expression(ir_binop_mul,
+ a->type,
+ a,
+ b);
+ expr = new(mem_ctx) ir_expression(ir_binop_add,
+ a->type,
+ expr,
+ mul_expr);
+ }
+
+ ir_rvalue *result = get_column(result_var, b_col);
+ assign = new(mem_ctx) ir_assignment(result,
+ expr,
+ NULL);
+ base_ir->insert_before(assign);
+ }
+}
+
+void
+ir_mat_op_to_vec_visitor::do_mul_mat_vec(ir_variable *result_var,
+ ir_variable *a_var,
+ ir_variable *b_var)
+{
+ int i;
+ ir_rvalue *a = get_column(a_var, 0);
+ ir_rvalue *b = get_element(b_var, 0, 0);
+ ir_assignment *assign;
+ ir_expression *expr;
+
+ /* first column */
+ expr = new(mem_ctx) ir_expression(ir_binop_mul,
+ result_var->type,
+ a,
+ b);
+
+ /* following columns */
+ for (i = 1; i < a_var->type->matrix_columns; i++) {
+ ir_expression *mul_expr;
+
+ a = get_column(a_var, i);
+ b = get_element(b_var, 0, i);
+
+ mul_expr = new(mem_ctx) ir_expression(ir_binop_mul,
+ result_var->type,
+ a,
+ b);
+ expr = new(mem_ctx) ir_expression(ir_binop_add,
+ result_var->type,
+ expr,
+ mul_expr);
+ }
+
+ ir_rvalue *result = new(mem_ctx) ir_dereference_variable(result_var);
+ assign = new(mem_ctx) ir_assignment(result,
+ expr,
+ NULL);
+ base_ir->insert_before(assign);
+}
+
+void
+ir_mat_op_to_vec_visitor::do_mul_vec_mat(ir_variable *result_var,
+ ir_variable *a_var,
+ ir_variable *b_var)
+{
+ int i;
+
+ for (i = 0; i < b_var->type->matrix_columns; i++) {
+ ir_rvalue *a = new(mem_ctx) ir_dereference_variable(a_var);
+ ir_rvalue *b = get_column(b_var, i);
+ ir_rvalue *result;
+ ir_expression *column_expr;
+ ir_assignment *column_assign;
+
+ result = new(mem_ctx) ir_dereference_variable(result_var);
+ result = new(mem_ctx) ir_swizzle(result, i, 0, 0, 0, 1);
+
+ column_expr = new(mem_ctx) ir_expression(ir_binop_dot,
+ result->type,
+ a,
+ b);
+
+ column_assign = new(mem_ctx) ir_assignment(result,
+ column_expr,
+ NULL);
+ base_ir->insert_before(column_assign);
+ }
+}
+
+void
+ir_mat_op_to_vec_visitor::do_mul_mat_scalar(ir_variable *result_var,
+ ir_variable *a_var,
+ ir_variable *b_var)
+{
+ int i;
+
+ for (i = 0; i < a_var->type->matrix_columns; i++) {
+ ir_rvalue *a = get_column(a_var, i);
+ ir_rvalue *b = new(mem_ctx) ir_dereference_variable(b_var);
+ ir_rvalue *result = get_column(result_var, i);
+ ir_expression *column_expr;
+ ir_assignment *column_assign;
+
+ column_expr = new(mem_ctx) ir_expression(ir_binop_mul,
+ result->type,
+ a,
+ b);
+
+ column_assign = new(mem_ctx) ir_assignment(result,
+ column_expr,
+ NULL);
+ base_ir->insert_before(column_assign);
+ }
+}
+
+void
+ir_mat_op_to_vec_visitor::do_equal_mat_mat(ir_variable *result_var,
+ ir_variable *a_var,
+ ir_variable *b_var,
+ bool test_equal)
+{
+ /* This essentially implements the following GLSL:
+ *
+ * bool equal(mat4 a, mat4 b)
+ * {
+ * return !any(bvec4(a[0] != b[0],
+ * a[1] != b[1],
+ * a[2] != b[2],
+ * a[3] != b[3]);
+ * }
+ *
+ * bool nequal(mat4 a, mat4 b)
+ * {
+ * return any(bvec4(a[0] != b[0],
+ * a[1] != b[1],
+ * a[2] != b[2],
+ * a[3] != b[3]);
+ * }
+ */
+ const unsigned columns = a_var->type->matrix_columns;
+ const glsl_type *const bvec_type =
+ glsl_type::get_instance(GLSL_TYPE_BOOL, columns, 1);
+
+ ir_variable *const tmp_bvec =
+ new(this->mem_ctx) ir_variable(bvec_type, "mat_cmp_bvec",
+ ir_var_temporary);
+ this->base_ir->insert_before(tmp_bvec);
+
+ for (unsigned i = 0; i < columns; i++) {
+ ir_dereference *const op0 = get_column(a_var, i);
+ ir_dereference *const op1 = get_column(b_var, i);
+
+ ir_expression *const cmp =
+ new(this->mem_ctx) ir_expression(ir_binop_any_nequal,
+ glsl_type::bool_type, op0, op1);
+
+ ir_dereference *const lhs =
+ new(this->mem_ctx) ir_dereference_variable(tmp_bvec);
+
+ ir_assignment *const assign =
+ new(this->mem_ctx) ir_assignment(lhs, cmp, NULL, (1U << i));
+
+ this->base_ir->insert_before(assign);
+ }
+
+ ir_rvalue *const val =
+ new(this->mem_ctx) ir_dereference_variable(tmp_bvec);
+
+ ir_expression *any =
+ new(this->mem_ctx) ir_expression(ir_unop_any, glsl_type::bool_type,
+ val, NULL);
+
+ if (test_equal)
+ any = new(this->mem_ctx) ir_expression(ir_unop_logic_not,
+ glsl_type::bool_type,
+ any, NULL);
+
+ ir_rvalue *const result =
+ new(this->mem_ctx) ir_dereference_variable(result_var);
+
+ ir_assignment *const assign =
+ new(mem_ctx) ir_assignment(result, any, NULL);
+ base_ir->insert_before(assign);
+}
+
+static bool
+has_matrix_operand(const ir_expression *expr, unsigned &columns)
+{
+ for (unsigned i = 0; i < expr->get_num_operands(); i++) {
+ if (expr->operands[i]->type->is_matrix()) {
+ columns = expr->operands[i]->type->matrix_columns;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+ir_visitor_status
+ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
+{
+ ir_expression *orig_expr = orig_assign->rhs->as_expression();
+ unsigned int i, matrix_columns = 1;
+ ir_variable *op_var[2];
+
+ if (!orig_expr)
+ return visit_continue;
+
+ if (!has_matrix_operand(orig_expr, matrix_columns))
+ return visit_continue;
+
+ assert(orig_expr->get_num_operands() <= 2);
+
+ mem_ctx = ralloc_parent(orig_assign);
+
+ ir_dereference_variable *lhs_deref =
+ orig_assign->lhs->as_dereference_variable();
+ assert(lhs_deref);
+
+ ir_variable *result_var = lhs_deref->var;
+
+ /* Store the expression operands in temps so we can use them
+ * multiple times.
+ */
+ for (i = 0; i < orig_expr->get_num_operands(); i++) {
+ ir_assignment *assign;
+
+ op_var[i] = new(mem_ctx) ir_variable(orig_expr->operands[i]->type,
+ "mat_op_to_vec",
+ ir_var_temporary);
+ base_ir->insert_before(op_var[i]);
+
+ lhs_deref = new(mem_ctx) ir_dereference_variable(op_var[i]);
+ assign = new(mem_ctx) ir_assignment(lhs_deref,
+ orig_expr->operands[i],
+ NULL);
+ base_ir->insert_before(assign);
+ }
+
+ /* OK, time to break down this matrix operation. */
+ switch (orig_expr->operation) {
+ case ir_unop_neg: {
+ const unsigned mask = (1U << result_var->type->vector_elements) - 1;
+
+ /* Apply the operation to each column.*/
+ for (i = 0; i < matrix_columns; i++) {
+ ir_rvalue *op0 = get_column(op_var[0], i);
+ ir_dereference *result = get_column(result_var, i);
+ ir_expression *column_expr;
+ ir_assignment *column_assign;
+
+ column_expr = new(mem_ctx) ir_expression(orig_expr->operation,
+ result->type,
+ op0,
+ NULL);
+
+ column_assign = new(mem_ctx) ir_assignment(result,
+ column_expr,
+ NULL,
+ mask);
+ assert(column_assign->write_mask != 0);
+ base_ir->insert_before(column_assign);
+ }
+ break;
+ }
+ case ir_binop_add:
+ case ir_binop_sub:
+ case ir_binop_div:
+ case ir_binop_mod: {
+ const unsigned mask = (1U << result_var->type->vector_elements) - 1;
+
+ /* For most operations, the matrix version is just going
+ * column-wise through and applying the operation to each column
+ * if available.
+ */
+ for (i = 0; i < matrix_columns; i++) {
+ ir_rvalue *op0 = get_column(op_var[0], i);
+ ir_rvalue *op1 = get_column(op_var[1], i);
+ ir_dereference *result = get_column(result_var, i);
+ ir_expression *column_expr;
+ ir_assignment *column_assign;
+
+ column_expr = new(mem_ctx) ir_expression(orig_expr->operation,
+ result->type,
+ op0,
+ op1);
+
+ column_assign = new(mem_ctx) ir_assignment(result,
+ column_expr,
+ NULL,
+ mask);
+ assert(column_assign->write_mask != 0);
+ base_ir->insert_before(column_assign);
+ }
+ break;
+ }
+ case ir_binop_mul:
+ if (op_var[0]->type->is_matrix()) {
+ if (op_var[1]->type->is_matrix()) {
+ do_mul_mat_mat(result_var, op_var[0], op_var[1]);
+ } else if (op_var[1]->type->is_vector()) {
+ do_mul_mat_vec(result_var, op_var[0], op_var[1]);
+ } else {
+ assert(op_var[1]->type->is_scalar());
+ do_mul_mat_scalar(result_var, op_var[0], op_var[1]);
+ }
+ } else {
+ assert(op_var[1]->type->is_matrix());
+ if (op_var[0]->type->is_vector()) {
+ do_mul_vec_mat(result_var, op_var[0], op_var[1]);
+ } else {
+ assert(op_var[0]->type->is_scalar());
+ do_mul_mat_scalar(result_var, op_var[1], op_var[0]);
+ }
+ }
+ break;
+
+ case ir_binop_all_equal:
+ case ir_binop_any_nequal:
+ do_equal_mat_mat(result_var, op_var[1], op_var[0],
+ (orig_expr->operation == ir_binop_all_equal));
+ break;
+
+ default:
+ printf("FINISHME: Handle matrix operation for %s\n",
+ orig_expr->operator_string());
+ abort();
+ }
+ orig_assign->remove();
+ this->made_progress = true;
+
+ return visit_continue;
+}
diff --git a/mesalib/src/glsl/main.cpp b/mesalib/src/glsl/main.cpp
index 096da93dc..873a4fa16 100644
--- a/mesalib/src/glsl/main.cpp
+++ b/mesalib/src/glsl/main.cpp
@@ -1,334 +1,345 @@
-/*
- * Copyright © 2008, 2009 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-#include <getopt.h>
-
-#include "ast.h"
-#include "glsl_parser_extras.h"
-#include "glsl_parser.h"
-#include "ir_optimization.h"
-#include "ir_print_visitor.h"
-#include "program.h"
-#include "loop_analysis.h"
-
-extern "C" struct gl_shader *
-_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type);
-
-extern "C" void
-_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
- struct gl_shader *sh);
-
-/* Copied from shader_api.c for the stand-alone compiler.
- */
-void
-_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
- struct gl_shader *sh)
-{
- *ptr = sh;
-}
-
-struct gl_shader *
-_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type)
-{
- struct gl_shader *shader;
-
- (void) ctx;
-
- assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER);
- shader = rzalloc(NULL, struct gl_shader);
- if (shader) {
- shader->Type = type;
- shader->Name = name;
- shader->RefCount = 1;
- }
- return shader;
-}
-
-static void
-initialize_context(struct gl_context *ctx, gl_api api)
-{
- memset(ctx, 0, sizeof(*ctx));
-
- ctx->API = api;
-
- ctx->Extensions.ARB_ES2_compatibility = GL_TRUE;
- ctx->Extensions.ARB_draw_buffers = GL_TRUE;
- ctx->Extensions.ARB_draw_instanced = GL_TRUE;
- ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
- ctx->Extensions.EXT_texture_array = GL_TRUE;
- ctx->Extensions.NV_texture_rectangle = GL_TRUE;
-
- /* GLSL 1.30 isn't fully supported, but we need to advertise 1.30 so that
- * the built-in functions for 1.30 can be built.
- */
- ctx->Const.GLSLVersion = 130;
-
- /* 1.10 minimums. */
- ctx->Const.MaxLights = 8;
- ctx->Const.MaxClipPlanes = 8;
- ctx->Const.MaxTextureUnits = 2;
-
- /* More than the 1.10 minimum to appease parser tests taken from
- * apps that (hopefully) already checked the number of coords.
- */
- ctx->Const.MaxTextureCoordUnits = 4;
-
- ctx->Const.VertexProgram.MaxAttribs = 16;
- ctx->Const.VertexProgram.MaxUniformComponents = 512;
- ctx->Const.MaxVarying = 8;
- ctx->Const.MaxVertexTextureImageUnits = 0;
- ctx->Const.MaxCombinedTextureImageUnits = 2;
- ctx->Const.MaxTextureImageUnits = 2;
- ctx->Const.FragmentProgram.MaxUniformComponents = 64;
-
- ctx->Const.MaxDrawBuffers = 2;
-
- ctx->Driver.NewShader = _mesa_new_shader;
-}
-
-/* Returned string will have 'ctx' as its ralloc owner. */
-static char *
-load_text_file(void *ctx, const char *file_name)
-{
- char *text = NULL;
- size_t size;
- size_t total_read = 0;
- FILE *fp = fopen(file_name, "rb");
-
- if (!fp) {
- return NULL;
- }
-
- fseek(fp, 0L, SEEK_END);
- size = ftell(fp);
- fseek(fp, 0L, SEEK_SET);
-
- text = (char *) ralloc_size(ctx, size + 1);
- if (text != NULL) {
- do {
- size_t bytes = fread(text + total_read,
- 1, size - total_read, fp);
- if (bytes < size - total_read) {
- free(text);
- text = NULL;
- break;
- }
-
- if (bytes == 0) {
- break;
- }
-
- total_read += bytes;
- } while (total_read < size);
-
- text[total_read] = '\0';
- }
-
- fclose(fp);
-
- return text;
-}
-
-int glsl_es = 0;
-int dump_ast = 0;
-int dump_hir = 0;
-int dump_lir = 0;
-int do_link = 0;
-
-const struct option compiler_opts[] = {
- { "glsl-es", 0, &glsl_es, 1 },
- { "dump-ast", 0, &dump_ast, 1 },
- { "dump-hir", 0, &dump_hir, 1 },
- { "dump-lir", 0, &dump_lir, 1 },
- { "link", 0, &do_link, 1 },
- { NULL, 0, NULL, 0 }
-};
-
-/**
- * \brief Print proper usage and exit with failure.
- */
-void
-usage_fail(const char *name)
-{
-
- const char *header =
- "usage: %s [options] <file.vert | file.geom | file.frag>\n"
- "\n"
- "Possible options are:\n";
- printf(header, name, name);
- for (const struct option *o = compiler_opts; o->name != 0; ++o) {
- printf(" --%s\n", o->name);
- }
- exit(EXIT_FAILURE);
-}
-
-
-void
-compile_shader(struct gl_context *ctx, struct gl_shader *shader)
-{
- struct _mesa_glsl_parse_state *state =
- new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader);
-
- const char *source = shader->Source;
- state->error = preprocess(state, &source, &state->info_log,
- state->extensions, ctx->API) != 0;
-
- if (!state->error) {
- _mesa_glsl_lexer_ctor(state, source);
- _mesa_glsl_parse(state);
- _mesa_glsl_lexer_dtor(state);
- }
-
- if (dump_ast) {
- foreach_list_const(n, &state->translation_unit) {
- ast_node *ast = exec_node_data(ast_node, n, link);
- ast->print();
- }
- printf("\n\n");
- }
-
- shader->ir = new(shader) exec_list;
- if (!state->error && !state->translation_unit.is_empty())
- _mesa_ast_to_hir(shader->ir, state);
-
- /* Print out the unoptimized IR. */
- if (!state->error && dump_hir) {
- validate_ir_tree(shader->ir);
- _mesa_print_ir(shader->ir, state);
- }
-
- /* Optimization passes */
- if (!state->error && !shader->ir->is_empty()) {
- bool progress;
- do {
- progress = do_common_optimization(shader->ir, false, 32);
- } while (progress);
-
- validate_ir_tree(shader->ir);
- }
-
-
- /* Print out the resulting IR */
- if (!state->error && dump_lir) {
- _mesa_print_ir(shader->ir, state);
- }
-
- shader->symbols = state->symbols;
- shader->CompileStatus = !state->error;
- shader->Version = state->language_version;
- memcpy(shader->builtins_to_link, state->builtins_to_link,
- sizeof(shader->builtins_to_link[0]) * state->num_builtins_to_link);
- shader->num_builtins_to_link = state->num_builtins_to_link;
-
- if (shader->InfoLog)
- ralloc_free(shader->InfoLog);
-
- shader->InfoLog = state->info_log;
-
- /* Retain any live IR, but trash the rest. */
- reparent_ir(shader->ir, shader);
-
- ralloc_free(state);
-
- return;
-}
-
-int
-main(int argc, char **argv)
-{
- int status = EXIT_SUCCESS;
- struct gl_context local_ctx;
- struct gl_context *ctx = &local_ctx;
-
- int c;
- int idx = 0;
- while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1)
- /* empty */ ;
-
-
- if (argc <= optind)
- usage_fail(argv[0]);
-
- initialize_context(ctx, (glsl_es) ? API_OPENGLES2 : API_OPENGL);
-
- struct gl_shader_program *whole_program;
-
- whole_program = rzalloc (NULL, struct gl_shader_program);
- assert(whole_program != NULL);
-
- for (/* empty */; argc > optind; optind++) {
- whole_program->Shaders =
- reralloc(whole_program, whole_program->Shaders,
- struct gl_shader *, whole_program->NumShaders + 1);
- assert(whole_program->Shaders != NULL);
-
- struct gl_shader *shader = rzalloc(whole_program, gl_shader);
-
- whole_program->Shaders[whole_program->NumShaders] = shader;
- whole_program->NumShaders++;
-
- const unsigned len = strlen(argv[optind]);
- if (len < 6)
- usage_fail(argv[0]);
-
- const char *const ext = & argv[optind][len - 5];
- if (strncmp(".vert", ext, 5) == 0)
- shader->Type = GL_VERTEX_SHADER;
- else if (strncmp(".geom", ext, 5) == 0)
- shader->Type = GL_GEOMETRY_SHADER;
- else if (strncmp(".frag", ext, 5) == 0)
- shader->Type = GL_FRAGMENT_SHADER;
- else
- usage_fail(argv[0]);
-
- shader->Source = load_text_file(whole_program, argv[optind]);
- if (shader->Source == NULL) {
- printf("File \"%s\" does not exist.\n", argv[optind]);
- exit(EXIT_FAILURE);
- }
-
- compile_shader(ctx, shader);
-
- if (!shader->CompileStatus) {
- printf("Info log for %s:\n%s\n", argv[optind], shader->InfoLog);
- status = EXIT_FAILURE;
- break;
- }
- }
-
- if ((status == EXIT_SUCCESS) && do_link) {
- link_shaders(ctx, whole_program);
- status = (whole_program->LinkStatus) ? EXIT_SUCCESS : EXIT_FAILURE;
-
- if (strlen(whole_program->InfoLog) > 0)
- printf("Info log for linking:\n%s\n", whole_program->InfoLog);
- }
-
- for (unsigned i = 0; i < MESA_SHADER_TYPES; i++)
- ralloc_free(whole_program->_LinkedShaders[i]);
-
- ralloc_free(whole_program);
- _mesa_glsl_release_types();
- _mesa_glsl_release_functions();
-
- return status;
-}
+/*
+ * Copyright © 2008, 2009 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include <io.h>
+
+#ifdef _MSC_VER
+#define __STDC__ 1
+#include <getopt.h>
+#define open _open
+#define read _read
+#define fstat _fstat
+#define stat _stat
+#define close _close
+#define O_RDONLY _O_RDONLY
+#endif
+
+#include "ast.h"
+#include "glsl_parser_extras.h"
+#include "glsl_parser.h"
+#include "ir_optimization.h"
+#include "ir_print_visitor.h"
+#include "program.h"
+#include "loop_analysis.h"
+
+extern "C" struct gl_shader *
+_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type);
+
+extern "C" void
+_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
+ struct gl_shader *sh);
+
+/* Copied from shader_api.c for the stand-alone compiler.
+ */
+void
+_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
+ struct gl_shader *sh)
+{
+ *ptr = sh;
+}
+
+struct gl_shader *
+_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type)
+{
+ struct gl_shader *shader;
+
+ (void) ctx;
+
+ assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER);
+ shader = rzalloc(NULL, struct gl_shader);
+ if (shader) {
+ shader->Type = type;
+ shader->Name = name;
+ shader->RefCount = 1;
+ }
+ return shader;
+}
+
+static void
+initialize_context(struct gl_context *ctx, gl_api api)
+{
+ memset(ctx, 0, sizeof(*ctx));
+
+ ctx->API = api;
+
+ ctx->Extensions.ARB_ES2_compatibility = GL_TRUE;
+ ctx->Extensions.ARB_draw_buffers = GL_TRUE;
+ ctx->Extensions.ARB_draw_instanced = GL_TRUE;
+ ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
+ ctx->Extensions.EXT_texture_array = GL_TRUE;
+ ctx->Extensions.NV_texture_rectangle = GL_TRUE;
+
+ /* GLSL 1.30 isn't fully supported, but we need to advertise 1.30 so that
+ * the built-in functions for 1.30 can be built.
+ */
+ ctx->Const.GLSLVersion = 130;
+
+ /* 1.10 minimums. */
+ ctx->Const.MaxLights = 8;
+ ctx->Const.MaxClipPlanes = 8;
+ ctx->Const.MaxTextureUnits = 2;
+
+ /* More than the 1.10 minimum to appease parser tests taken from
+ * apps that (hopefully) already checked the number of coords.
+ */
+ ctx->Const.MaxTextureCoordUnits = 4;
+
+ ctx->Const.VertexProgram.MaxAttribs = 16;
+ ctx->Const.VertexProgram.MaxUniformComponents = 512;
+ ctx->Const.MaxVarying = 8;
+ ctx->Const.MaxVertexTextureImageUnits = 0;
+ ctx->Const.MaxCombinedTextureImageUnits = 2;
+ ctx->Const.MaxTextureImageUnits = 2;
+ ctx->Const.FragmentProgram.MaxUniformComponents = 64;
+
+ ctx->Const.MaxDrawBuffers = 2;
+
+ ctx->Driver.NewShader = _mesa_new_shader;
+}
+
+/* Returned string will have 'ctx' as its ralloc owner. */
+static char *
+load_text_file(void *ctx, const char *file_name)
+{
+ char *text = NULL;
+ size_t size;
+ size_t total_read = 0;
+ FILE *fp = fopen(file_name, "rb");
+
+ if (!fp) {
+ return NULL;
+ }
+
+ fseek(fp, 0L, SEEK_END);
+ size = ftell(fp);
+ fseek(fp, 0L, SEEK_SET);
+
+ text = (char *) ralloc_size(ctx, size + 1);
+ if (text != NULL) {
+ do {
+ size_t bytes = fread(text + total_read,
+ 1, size - total_read, fp);
+ if (bytes < size - total_read) {
+ free(text);
+ text = NULL;
+ break;
+ }
+
+ if (bytes == 0) {
+ break;
+ }
+
+ total_read += bytes;
+ } while (total_read < size);
+
+ text[total_read] = '\0';
+ }
+
+ fclose(fp);
+
+ return text;
+}
+
+int glsl_es = 0;
+int dump_ast = 0;
+int dump_hir = 0;
+int dump_lir = 0;
+int do_link = 0;
+
+const struct option compiler_opts[] = {
+ { "glsl-es", 0, &glsl_es, 1 },
+ { "dump-ast", 0, &dump_ast, 1 },
+ { "dump-hir", 0, &dump_hir, 1 },
+ { "dump-lir", 0, &dump_lir, 1 },
+ { "link", 0, &do_link, 1 },
+ { NULL, 0, NULL, 0 }
+};
+
+/**
+ * \brief Print proper usage and exit with failure.
+ */
+void
+usage_fail(const char *name)
+{
+
+ const char *header =
+ "usage: %s [options] <file.vert | file.geom | file.frag>\n"
+ "\n"
+ "Possible options are:\n";
+ printf(header, name, name);
+ for (const struct option *o = compiler_opts; o->name != 0; ++o) {
+ printf(" --%s\n", o->name);
+ }
+ exit(EXIT_FAILURE);
+}
+
+
+void
+compile_shader(struct gl_context *ctx, struct gl_shader *shader)
+{
+ struct _mesa_glsl_parse_state *state =
+ new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader);
+
+ const char *source = shader->Source;
+ state->error = preprocess(state, &source, &state->info_log,
+ state->extensions, ctx->API) != 0;
+
+ if (!state->error) {
+ _mesa_glsl_lexer_ctor(state, source);
+ _mesa_glsl_parse(state);
+ _mesa_glsl_lexer_dtor(state);
+ }
+
+ if (dump_ast) {
+ foreach_list_const(n, &state->translation_unit) {
+ ast_node *ast = exec_node_data(ast_node, n, link);
+ ast->print();
+ }
+ printf("\n\n");
+ }
+
+ shader->ir = new(shader) exec_list;
+ if (!state->error && !state->translation_unit.is_empty())
+ _mesa_ast_to_hir(shader->ir, state);
+
+ /* Print out the unoptimized IR. */
+ if (!state->error && dump_hir) {
+ validate_ir_tree(shader->ir);
+ _mesa_print_ir(shader->ir, state);
+ }
+
+ /* Optimization passes */
+ if (!state->error && !shader->ir->is_empty()) {
+ bool progress;
+ do {
+ progress = do_common_optimization(shader->ir, false, 32);
+ } while (progress);
+
+ validate_ir_tree(shader->ir);
+ }
+
+
+ /* Print out the resulting IR */
+ if (!state->error && dump_lir) {
+ _mesa_print_ir(shader->ir, state);
+ }
+
+ shader->symbols = state->symbols;
+ shader->CompileStatus = !state->error;
+ shader->Version = state->language_version;
+ memcpy(shader->builtins_to_link, state->builtins_to_link,
+ sizeof(shader->builtins_to_link[0]) * state->num_builtins_to_link);
+ shader->num_builtins_to_link = state->num_builtins_to_link;
+
+ if (shader->InfoLog)
+ ralloc_free(shader->InfoLog);
+
+ shader->InfoLog = state->info_log;
+
+ /* Retain any live IR, but trash the rest. */
+ reparent_ir(shader->ir, shader);
+
+ ralloc_free(state);
+
+ return;
+}
+
+int
+main(int argc, char **argv)
+{
+ int status = EXIT_SUCCESS;
+ struct gl_context local_ctx;
+ struct gl_context *ctx = &local_ctx;
+
+ int c;
+ int idx = 0;
+ while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1)
+ /* empty */ ;
+
+
+ if (argc <= optind)
+ usage_fail(argv[0]);
+
+ initialize_context(ctx, (glsl_es) ? API_OPENGLES2 : API_OPENGL);
+
+ struct gl_shader_program *whole_program;
+
+ whole_program = rzalloc (NULL, struct gl_shader_program);
+ assert(whole_program != NULL);
+
+ for (/* empty */; argc > optind; optind++) {
+ whole_program->Shaders =
+ reralloc(whole_program, whole_program->Shaders,
+ struct gl_shader *, whole_program->NumShaders + 1);
+ assert(whole_program->Shaders != NULL);
+
+ struct gl_shader *shader = rzalloc(whole_program, gl_shader);
+
+ whole_program->Shaders[whole_program->NumShaders] = shader;
+ whole_program->NumShaders++;
+
+ const unsigned len = strlen(argv[optind]);
+ if (len < 6)
+ usage_fail(argv[0]);
+
+ const char *const ext = & argv[optind][len - 5];
+ if (strncmp(".vert", ext, 5) == 0)
+ shader->Type = GL_VERTEX_SHADER;
+ else if (strncmp(".geom", ext, 5) == 0)
+ shader->Type = GL_GEOMETRY_SHADER;
+ else if (strncmp(".frag", ext, 5) == 0)
+ shader->Type = GL_FRAGMENT_SHADER;
+ else
+ usage_fail(argv[0]);
+
+ shader->Source = load_text_file(whole_program, argv[optind]);
+ if (shader->Source == NULL) {
+ printf("File \"%s\" does not exist.\n", argv[optind]);
+ exit(EXIT_FAILURE);
+ }
+
+ compile_shader(ctx, shader);
+
+ if (!shader->CompileStatus) {
+ printf("Info log for %s:\n%s\n", argv[optind], shader->InfoLog);
+ status = EXIT_FAILURE;
+ break;
+ }
+ }
+
+ if ((status == EXIT_SUCCESS) && do_link) {
+ link_shaders(ctx, whole_program);
+ status = (whole_program->LinkStatus) ? EXIT_SUCCESS : EXIT_FAILURE;
+
+ if (strlen(whole_program->InfoLog) > 0)
+ printf("Info log for linking:\n%s\n", whole_program->InfoLog);
+ }
+
+ for (unsigned i = 0; i < MESA_SHADER_TYPES; i++)
+ ralloc_free(whole_program->_LinkedShaders[i]);
+
+ ralloc_free(whole_program);
+ _mesa_glsl_release_types();
+ _mesa_glsl_release_functions();
+
+ return status;
+}
diff --git a/mesalib/src/glsl/opt_constant_propagation.cpp b/mesalib/src/glsl/opt_constant_propagation.cpp
index 4425f4211..55c271200 100644
--- a/mesalib/src/glsl/opt_constant_propagation.cpp
+++ b/mesalib/src/glsl/opt_constant_propagation.cpp
@@ -1,434 +1,434 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * constant of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, constant, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above constantright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR CONSTANTRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file opt_constant_propagation.cpp
- *
- * Tracks assignments of constants to channels of variables, and
- * usage of those constant channels with direct usage of the constants.
- *
- * This can lead to constant folding and algebraic optimizations in
- * those later expressions, while causing no increase in instruction
- * count (due to constants being generally free to load from a
- * constant push buffer or as instruction immediate values) and
- * possibly reducing register pressure.
- */
-
-#include "ir.h"
-#include "ir_visitor.h"
-#include "ir_rvalue_visitor.h"
-#include "ir_basic_block.h"
-#include "ir_optimization.h"
-#include "glsl_types.h"
-
-class acp_entry : public exec_node
-{
-public:
- acp_entry(ir_variable *var, unsigned write_mask, ir_constant *constant)
- {
- assert(var);
- assert(constant);
- this->var = var;
- this->write_mask = write_mask;
- this->constant = constant;
- }
-
- ir_variable *var;
- ir_constant *constant;
- unsigned write_mask;
-};
-
-
-class kill_entry : public exec_node
-{
-public:
- kill_entry(ir_variable *var, unsigned write_mask)
- {
- assert(var);
- this->var = var;
- this->write_mask = write_mask;
- }
-
- ir_variable *var;
- unsigned write_mask;
-};
-
-class ir_constant_propagation_visitor : public ir_rvalue_visitor {
-public:
- ir_constant_propagation_visitor()
- {
- progress = false;
- mem_ctx = ralloc_context(0);
- this->acp = new(mem_ctx) exec_list;
- this->kills = new(mem_ctx) exec_list;
- }
- ~ir_constant_propagation_visitor()
- {
- ralloc_free(mem_ctx);
- }
-
- virtual ir_visitor_status visit_enter(class ir_loop *);
- virtual ir_visitor_status visit_enter(class ir_function_signature *);
- virtual ir_visitor_status visit_enter(class ir_function *);
- virtual ir_visitor_status visit_leave(class ir_assignment *);
- virtual ir_visitor_status visit_enter(class ir_call *);
- virtual ir_visitor_status visit_enter(class ir_if *);
-
- void add_constant(ir_assignment *ir);
- void kill(ir_variable *ir, unsigned write_mask);
- void handle_if_block(exec_list *instructions);
- void handle_rvalue(ir_rvalue **rvalue);
-
- /** List of acp_entry: The available constants to propagate */
- exec_list *acp;
-
- /**
- * List of kill_entry: The masks of variables whose values were
- * killed in this block.
- */
- exec_list *kills;
-
- bool progress;
-
- bool killed_all;
-
- void *mem_ctx;
-};
-
-
-void
-ir_constant_propagation_visitor::handle_rvalue(ir_rvalue **rvalue)
-{
- if (this->in_assignee || !*rvalue)
- return;
-
- const glsl_type *type = (*rvalue)->type;
- if (!type->is_scalar() && !type->is_vector())
- return;
-
- ir_swizzle *swiz = NULL;
- ir_dereference_variable *deref = (*rvalue)->as_dereference_variable();
- if (!deref) {
- swiz = (*rvalue)->as_swizzle();
- if (!swiz)
- return;
-
- deref = swiz->val->as_dereference_variable();
- if (!deref)
- return;
- }
-
- ir_constant_data data;
- memset(&data, 0, sizeof(data));
-
- for (unsigned int i = 0; i < type->components(); i++) {
- int channel;
- acp_entry *found = NULL;
-
- if (swiz) {
- switch (i) {
- case 0: channel = swiz->mask.x; break;
- case 1: channel = swiz->mask.y; break;
- case 2: channel = swiz->mask.z; break;
- case 3: channel = swiz->mask.w; break;
- default: assert(!"shouldn't be reached"); channel = 0; break;
- }
- } else {
- channel = i;
- }
-
- foreach_iter(exec_list_iterator, iter, *this->acp) {
- acp_entry *entry = (acp_entry *)iter.get();
- if (entry->var == deref->var && entry->write_mask & (1 << channel)) {
- found = entry;
- break;
- }
- }
-
- if (!found)
- return;
-
- int rhs_channel = 0;
- for (int j = 0; j < 4; j++) {
- if (j == channel)
- break;
- if (found->write_mask & (1 << j))
- rhs_channel++;
- }
-
- switch (type->base_type) {
- case GLSL_TYPE_FLOAT:
- data.f[i] = found->constant->value.f[rhs_channel];
- break;
- case GLSL_TYPE_INT:
- data.i[i] = found->constant->value.i[rhs_channel];
- break;
- case GLSL_TYPE_UINT:
- data.u[i] = found->constant->value.u[rhs_channel];
- break;
- case GLSL_TYPE_BOOL:
- data.b[i] = found->constant->value.b[rhs_channel];
- break;
- default:
- assert(!"not reached");
- break;
- }
- }
-
- *rvalue = new(ralloc_parent(deref)) ir_constant(type, &data);
- this->progress = true;
-}
-
-ir_visitor_status
-ir_constant_propagation_visitor::visit_enter(ir_function_signature *ir)
-{
- /* Treat entry into a function signature as a completely separate
- * block. Any instructions at global scope will be shuffled into
- * main() at link time, so they're irrelevant to us.
- */
- exec_list *orig_acp = this->acp;
- exec_list *orig_kills = this->kills;
- bool orig_killed_all = this->killed_all;
-
- this->acp = new(mem_ctx) exec_list;
- this->kills = new(mem_ctx) exec_list;
- this->killed_all = false;
-
- visit_list_elements(this, &ir->body);
-
- this->kills = orig_kills;
- this->acp = orig_acp;
- this->killed_all = orig_killed_all;
-
- return visit_continue_with_parent;
-}
-
-ir_visitor_status
-ir_constant_propagation_visitor::visit_leave(ir_assignment *ir)
-{
- if (this->in_assignee)
- return visit_continue;
-
- kill(ir->lhs->variable_referenced(), ir->write_mask);
-
- add_constant(ir);
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_constant_propagation_visitor::visit_enter(ir_function *ir)
-{
- (void) ir;
- return visit_continue;
-}
-
-ir_visitor_status
-ir_constant_propagation_visitor::visit_enter(ir_call *ir)
-{
- /* Do constant propagation on call parameters, but skip any out params */
- exec_list_iterator sig_param_iter = ir->get_callee()->parameters.iterator();
- foreach_iter(exec_list_iterator, iter, ir->actual_parameters) {
- ir_variable *sig_param = (ir_variable *)sig_param_iter.get();
- ir_rvalue *param = (ir_rvalue *)iter.get();
- if (sig_param->mode != ir_var_out && sig_param->mode != ir_var_inout) {
- ir_rvalue *new_param = param;
- handle_rvalue(&new_param);
- if (new_param != param)
- param->replace_with(new_param);
- else
- param->accept(this);
- }
- sig_param_iter.next();
- }
-
- /* Since we're unlinked, we don't (necssarily) know the side effects of
- * this call. So kill all copies.
- */
- acp->make_empty();
- this->killed_all = true;
-
- return visit_continue_with_parent;
-}
-
-void
-ir_constant_propagation_visitor::handle_if_block(exec_list *instructions)
-{
- exec_list *orig_acp = this->acp;
- exec_list *orig_kills = this->kills;
- bool orig_killed_all = this->killed_all;
-
- this->acp = new(mem_ctx) exec_list;
- this->kills = new(mem_ctx) exec_list;
- this->killed_all = false;
-
- /* Populate the initial acp with a constant of the original */
- foreach_iter(exec_list_iterator, iter, *orig_acp) {
- acp_entry *a = (acp_entry *)iter.get();
- this->acp->push_tail(new(this->mem_ctx) acp_entry(a->var, a->write_mask,
- a->constant));
- }
-
- visit_list_elements(this, instructions);
-
- if (this->killed_all) {
- orig_acp->make_empty();
- }
-
- exec_list *new_kills = this->kills;
- this->kills = orig_kills;
- this->acp = orig_acp;
- this->killed_all = this->killed_all || orig_killed_all;
-
- foreach_iter(exec_list_iterator, iter, *new_kills) {
- kill_entry *k = (kill_entry *)iter.get();
- kill(k->var, k->write_mask);
- }
-}
-
-ir_visitor_status
-ir_constant_propagation_visitor::visit_enter(ir_if *ir)
-{
- ir->condition->accept(this);
- handle_rvalue(&ir->condition);
-
- handle_if_block(&ir->then_instructions);
- handle_if_block(&ir->else_instructions);
-
- /* handle_if_block() already descended into the children. */
- return visit_continue_with_parent;
-}
-
-ir_visitor_status
-ir_constant_propagation_visitor::visit_enter(ir_loop *ir)
-{
- exec_list *orig_acp = this->acp;
- exec_list *orig_kills = this->kills;
- bool orig_killed_all = this->killed_all;
-
- /* FINISHME: For now, the initial acp for loops is totally empty.
- * We could go through once, then go through again with the acp
- * cloned minus the killed entries after the first run through.
- */
- this->acp = new(mem_ctx) exec_list;
- this->kills = new(mem_ctx) exec_list;
- this->killed_all = false;
-
- visit_list_elements(this, &ir->body_instructions);
-
- if (this->killed_all) {
- orig_acp->make_empty();
- }
-
- exec_list *new_kills = this->kills;
- this->kills = orig_kills;
- this->acp = orig_acp;
- this->killed_all = this->killed_all || orig_killed_all;
-
- foreach_iter(exec_list_iterator, iter, *new_kills) {
- kill_entry *k = (kill_entry *)iter.get();
- kill(k->var, k->write_mask);
- }
-
- /* already descended into the children. */
- return visit_continue_with_parent;
-}
-
-void
-ir_constant_propagation_visitor::kill(ir_variable *var, unsigned write_mask)
-{
- assert(var != NULL);
-
- /* We don't track non-vectors. */
- if (!var->type->is_vector() && !var->type->is_scalar())
- return;
-
- /* Remove any entries currently in the ACP for this kill. */
- foreach_iter(exec_list_iterator, iter, *this->acp) {
- acp_entry *entry = (acp_entry *)iter.get();
-
- if (entry->var == var) {
- entry->write_mask &= ~write_mask;
- if (entry->write_mask == 0)
- entry->remove();
- }
- }
-
- /* Add this writemask of the variable to the list of killed
- * variables in this block.
- */
- foreach_iter(exec_list_iterator, iter, *this->kills) {
- kill_entry *entry = (kill_entry *)iter.get();
-
- if (entry->var == var) {
- entry->write_mask |= write_mask;
- return;
- }
- }
- /* Not already in the list. Make new entry. */
- this->kills->push_tail(new(this->mem_ctx) kill_entry(var, write_mask));
-}
-
-/**
- * Adds an entry to the available constant list if it's a plain assignment
- * of a variable to a variable.
- */
-void
-ir_constant_propagation_visitor::add_constant(ir_assignment *ir)
-{
- acp_entry *entry;
-
- if (ir->condition)
- return;
-
- if (!ir->write_mask)
- return;
-
- ir_dereference_variable *deref = ir->lhs->as_dereference_variable();
- ir_constant *constant = ir->rhs->as_constant();
-
- if (!deref || !constant)
- return;
-
- /* Only do constant propagation on vectors. Constant matrices,
- * arrays, or structures would require more work elsewhere.
- */
- if (!deref->var->type->is_vector() && !deref->var->type->is_scalar())
- return;
-
- entry = new(this->mem_ctx) acp_entry(deref->var, ir->write_mask, constant);
- this->acp->push_tail(entry);
-}
-
-/**
- * Does a constant propagation pass on the code present in the instruction stream.
- */
-bool
-do_constant_propagation(exec_list *instructions)
-{
- ir_constant_propagation_visitor v;
-
- visit_list_elements(&v, instructions);
-
- return v.progress;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * constant of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, constant, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above constantright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR CONSTANTRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file opt_constant_propagation.cpp
+ *
+ * Tracks assignments of constants to channels of variables, and
+ * usage of those constant channels with direct usage of the constants.
+ *
+ * This can lead to constant folding and algebraic optimizations in
+ * those later expressions, while causing no increase in instruction
+ * count (due to constants being generally free to load from a
+ * constant push buffer or as instruction immediate values) and
+ * possibly reducing register pressure.
+ */
+
+#include "ir.h"
+#include "ir_visitor.h"
+#include "ir_rvalue_visitor.h"
+#include "ir_basic_block.h"
+#include "ir_optimization.h"
+#include "glsl_types.h"
+
+class acp_entry : public exec_node
+{
+public:
+ acp_entry(ir_variable *var, unsigned write_mask, ir_constant *constant)
+ {
+ assert(var);
+ assert(constant);
+ this->var = var;
+ this->write_mask = write_mask;
+ this->constant = constant;
+ }
+
+ ir_variable *var;
+ ir_constant *constant;
+ unsigned write_mask;
+};
+
+
+class kill_entry : public exec_node
+{
+public:
+ kill_entry(ir_variable *var, unsigned write_mask)
+ {
+ assert(var);
+ this->var = var;
+ this->write_mask = write_mask;
+ }
+
+ ir_variable *var;
+ unsigned write_mask;
+};
+
+class ir_constant_propagation_visitor : public ir_rvalue_visitor {
+public:
+ ir_constant_propagation_visitor()
+ {
+ progress = false;
+ mem_ctx = ralloc_context(0);
+ this->acp = new(mem_ctx) exec_list;
+ this->kills = new(mem_ctx) exec_list;
+ }
+ ~ir_constant_propagation_visitor()
+ {
+ ralloc_free(mem_ctx);
+ }
+
+ virtual ir_visitor_status visit_enter(class ir_loop *);
+ virtual ir_visitor_status visit_enter(class ir_function_signature *);
+ virtual ir_visitor_status visit_enter(class ir_function *);
+ virtual ir_visitor_status visit_leave(class ir_assignment *);
+ virtual ir_visitor_status visit_enter(class ir_call *);
+ virtual ir_visitor_status visit_enter(class ir_if *);
+
+ void add_constant(ir_assignment *ir);
+ void kill(ir_variable *ir, unsigned write_mask);
+ void handle_if_block(exec_list *instructions);
+ void handle_rvalue(ir_rvalue **rvalue);
+
+ /** List of acp_entry: The available constants to propagate */
+ exec_list *acp;
+
+ /**
+ * List of kill_entry: The masks of variables whose values were
+ * killed in this block.
+ */
+ exec_list *kills;
+
+ bool progress;
+
+ bool killed_all;
+
+ void *mem_ctx;
+};
+
+
+void
+ir_constant_propagation_visitor::handle_rvalue(ir_rvalue **rvalue)
+{
+ if (this->in_assignee || !*rvalue)
+ return;
+
+ const glsl_type *type = (*rvalue)->type;
+ if (!type->is_scalar() && !type->is_vector())
+ return;
+
+ ir_swizzle *swiz = NULL;
+ ir_dereference_variable *deref = (*rvalue)->as_dereference_variable();
+ if (!deref) {
+ swiz = (*rvalue)->as_swizzle();
+ if (!swiz)
+ return;
+
+ deref = swiz->val->as_dereference_variable();
+ if (!deref)
+ return;
+ }
+
+ ir_constant_data data;
+ memset(&data, 0, sizeof(data));
+
+ for (unsigned int i = 0; i < type->components(); i++) {
+ int channel;
+ acp_entry *found = NULL;
+
+ if (swiz) {
+ switch (i) {
+ case 0: channel = swiz->mask.x; break;
+ case 1: channel = swiz->mask.y; break;
+ case 2: channel = swiz->mask.z; break;
+ case 3: channel = swiz->mask.w; break;
+ default: assert(!"shouldn't be reached"); channel = 0; break;
+ }
+ } else {
+ channel = i;
+ }
+
+ foreach_iter(exec_list_iterator, iter, *this->acp) {
+ acp_entry *entry = (acp_entry *)iter.get();
+ if (entry->var == deref->var && entry->write_mask & (1 << channel)) {
+ found = entry;
+ break;
+ }
+ }
+
+ if (!found)
+ return;
+
+ int rhs_channel = 0;
+ for (int j = 0; j < 4; j++) {
+ if (j == channel)
+ break;
+ if (found->write_mask & (1 << j))
+ rhs_channel++;
+ }
+
+ switch (type->base_type) {
+ case GLSL_TYPE_FLOAT:
+ data.f[i] = found->constant->value.f[rhs_channel];
+ break;
+ case GLSL_TYPE_INT:
+ data.i[i] = found->constant->value.i[rhs_channel];
+ break;
+ case GLSL_TYPE_UINT:
+ data.u[i] = found->constant->value.u[rhs_channel];
+ break;
+ case GLSL_TYPE_BOOL:
+ data.b[i] = found->constant->value.b[rhs_channel];
+ break;
+ default:
+ assert(!"not reached");
+ break;
+ }
+ }
+
+ *rvalue = new(ralloc_parent(deref)) ir_constant(type, &data);
+ this->progress = true;
+}
+
+ir_visitor_status
+ir_constant_propagation_visitor::visit_enter(ir_function_signature *ir)
+{
+ /* Treat entry into a function signature as a completely separate
+ * block. Any instructions at global scope will be shuffled into
+ * main() at link time, so they're irrelevant to us.
+ */
+ exec_list *orig_acp = this->acp;
+ exec_list *orig_kills = this->kills;
+ bool orig_killed_all = this->killed_all;
+
+ this->acp = new(mem_ctx) exec_list;
+ this->kills = new(mem_ctx) exec_list;
+ this->killed_all = false;
+
+ visit_list_elements(this, &ir->body);
+
+ this->kills = orig_kills;
+ this->acp = orig_acp;
+ this->killed_all = orig_killed_all;
+
+ return visit_continue_with_parent;
+}
+
+ir_visitor_status
+ir_constant_propagation_visitor::visit_leave(ir_assignment *ir)
+{
+ if (this->in_assignee)
+ return visit_continue;
+
+ kill(ir->lhs->variable_referenced(), ir->write_mask);
+
+ add_constant(ir);
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_constant_propagation_visitor::visit_enter(ir_function *ir)
+{
+ (void) ir;
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_constant_propagation_visitor::visit_enter(ir_call *ir)
+{
+ /* Do constant propagation on call parameters, but skip any out params */
+ exec_list_iterator sig_param_iter = ir->get_callee()->parameters.iterator();
+ foreach_iter(exec_list_iterator, iter, ir->actual_parameters) {
+ ir_variable *sig_param = (ir_variable *)sig_param_iter.get();
+ ir_rvalue *param = (ir_rvalue *)iter.get();
+ if (sig_param->mode != ir_var_out && sig_param->mode != ir_var_inout) {
+ ir_rvalue *new_param = param;
+ handle_rvalue(&new_param);
+ if (new_param != param)
+ param->replace_with(new_param);
+ else
+ param->accept(this);
+ }
+ sig_param_iter.next();
+ }
+
+ /* Since we're unlinked, we don't (necssarily) know the side effects of
+ * this call. So kill all copies.
+ */
+ acp->make_empty();
+ this->killed_all = true;
+
+ return visit_continue_with_parent;
+}
+
+void
+ir_constant_propagation_visitor::handle_if_block(exec_list *instructions)
+{
+ exec_list *orig_acp = this->acp;
+ exec_list *orig_kills = this->kills;
+ bool orig_killed_all = this->killed_all;
+
+ this->acp = new(mem_ctx) exec_list;
+ this->kills = new(mem_ctx) exec_list;
+ this->killed_all = false;
+
+ /* Populate the initial acp with a constant of the original */
+ foreach_iter(exec_list_iterator, iter, *orig_acp) {
+ acp_entry *a = (acp_entry *)iter.get();
+ this->acp->push_tail(new(this->mem_ctx) acp_entry(a->var, a->write_mask,
+ a->constant));
+ }
+
+ visit_list_elements(this, instructions);
+
+ if (this->killed_all) {
+ orig_acp->make_empty();
+ }
+
+ exec_list *new_kills = this->kills;
+ this->kills = orig_kills;
+ this->acp = orig_acp;
+ this->killed_all = this->killed_all || orig_killed_all;
+
+ foreach_iter(exec_list_iterator, iter, *new_kills) {
+ kill_entry *k = (kill_entry *)iter.get();
+ kill(k->var, k->write_mask);
+ }
+}
+
+ir_visitor_status
+ir_constant_propagation_visitor::visit_enter(ir_if *ir)
+{
+ ir->condition->accept(this);
+ handle_rvalue(&ir->condition);
+
+ handle_if_block(&ir->then_instructions);
+ handle_if_block(&ir->else_instructions);
+
+ /* handle_if_block() already descended into the children. */
+ return visit_continue_with_parent;
+}
+
+ir_visitor_status
+ir_constant_propagation_visitor::visit_enter(ir_loop *ir)
+{
+ exec_list *orig_acp = this->acp;
+ exec_list *orig_kills = this->kills;
+ bool orig_killed_all = this->killed_all;
+
+ /* FINISHME: For now, the initial acp for loops is totally empty.
+ * We could go through once, then go through again with the acp
+ * cloned minus the killed entries after the first run through.
+ */
+ this->acp = new(mem_ctx) exec_list;
+ this->kills = new(mem_ctx) exec_list;
+ this->killed_all = false;
+
+ visit_list_elements(this, &ir->body_instructions);
+
+ if (this->killed_all) {
+ orig_acp->make_empty();
+ }
+
+ exec_list *new_kills = this->kills;
+ this->kills = orig_kills;
+ this->acp = orig_acp;
+ this->killed_all = this->killed_all || orig_killed_all;
+
+ foreach_iter(exec_list_iterator, iter, *new_kills) {
+ kill_entry *k = (kill_entry *)iter.get();
+ kill(k->var, k->write_mask);
+ }
+
+ /* already descended into the children. */
+ return visit_continue_with_parent;
+}
+
+void
+ir_constant_propagation_visitor::kill(ir_variable *var, unsigned write_mask)
+{
+ assert(var != NULL);
+
+ /* We don't track non-vectors. */
+ if (!var->type->is_vector() && !var->type->is_scalar())
+ return;
+
+ /* Remove any entries currently in the ACP for this kill. */
+ foreach_iter(exec_list_iterator, iter, *this->acp) {
+ acp_entry *entry = (acp_entry *)iter.get();
+
+ if (entry->var == var) {
+ entry->write_mask &= ~write_mask;
+ if (entry->write_mask == 0)
+ entry->remove();
+ }
+ }
+
+ /* Add this writemask of the variable to the list of killed
+ * variables in this block.
+ */
+ foreach_iter(exec_list_iterator, iter, *this->kills) {
+ kill_entry *entry = (kill_entry *)iter.get();
+
+ if (entry->var == var) {
+ entry->write_mask |= write_mask;
+ return;
+ }
+ }
+ /* Not already in the list. Make new entry. */
+ this->kills->push_tail(new(this->mem_ctx) kill_entry(var, write_mask));
+}
+
+/**
+ * Adds an entry to the available constant list if it's a plain assignment
+ * of a variable to a variable.
+ */
+void
+ir_constant_propagation_visitor::add_constant(ir_assignment *ir)
+{
+ acp_entry *entry;
+
+ if (ir->condition)
+ return;
+
+ if (!ir->write_mask)
+ return;
+
+ ir_dereference_variable *deref = ir->lhs->as_dereference_variable();
+ ir_constant *constant = ir->rhs->as_constant();
+
+ if (!deref || !constant)
+ return;
+
+ /* Only do constant propagation on vectors. Constant matrices,
+ * arrays, or structures would require more work elsewhere.
+ */
+ if (!deref->var->type->is_vector() && !deref->var->type->is_scalar())
+ return;
+
+ entry = new(this->mem_ctx) acp_entry(deref->var, ir->write_mask, constant);
+ this->acp->push_tail(entry);
+}
+
+/**
+ * Does a constant propagation pass on the code present in the instruction stream.
+ */
+bool
+do_constant_propagation(exec_list *instructions)
+{
+ ir_constant_propagation_visitor v;
+
+ visit_list_elements(&v, instructions);
+
+ return v.progress;
+}
diff --git a/mesalib/src/glsl/opt_constant_variable.cpp b/mesalib/src/glsl/opt_constant_variable.cpp
index 3fa7c3bad..f1aeaa99a 100644
--- a/mesalib/src/glsl/opt_constant_variable.cpp
+++ b/mesalib/src/glsl/opt_constant_variable.cpp
@@ -1,195 +1,195 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file opt_constant_variable.cpp
- *
- * Marks variables assigned a single constant value over the course
- * of the program as constant.
- *
- * The goal here is to trigger further constant folding and then dead
- * code elimination. This is common with vector/matrix constructors
- * and calls to builtin functions.
- */
-
-#include "ir.h"
-#include "ir_visitor.h"
-#include "ir_optimization.h"
-#include "glsl_types.h"
-
-struct assignment_entry {
- exec_node link;
- int assignment_count;
- ir_variable *var;
- ir_constant *constval;
- bool our_scope;
-};
-
-class ir_constant_variable_visitor : public ir_hierarchical_visitor {
-public:
- virtual ir_visitor_status visit_enter(ir_dereference_variable *);
- virtual ir_visitor_status visit(ir_variable *);
- virtual ir_visitor_status visit_enter(ir_assignment *);
- virtual ir_visitor_status visit_enter(ir_call *);
-
- exec_list list;
-};
-
-static struct assignment_entry *
-get_assignment_entry(ir_variable *var, exec_list *list)
-{
- struct assignment_entry *entry;
-
- foreach_list_typed(struct assignment_entry, entry, link, list) {
- if (entry->var == var)
- return entry;
- }
-
- entry = (struct assignment_entry *)calloc(1, sizeof(*entry));
- entry->var = var;
- list->push_head(&entry->link);
- return entry;
-}
-
-ir_visitor_status
-ir_constant_variable_visitor::visit(ir_variable *ir)
-{
- struct assignment_entry *entry = get_assignment_entry(ir, &this->list);
- entry->our_scope = true;
- return visit_continue;
-}
-
-/* Skip derefs of variables so that we can detect declarations. */
-ir_visitor_status
-ir_constant_variable_visitor::visit_enter(ir_dereference_variable *ir)
-{
- (void)ir;
- return visit_continue_with_parent;
-}
-
-ir_visitor_status
-ir_constant_variable_visitor::visit_enter(ir_assignment *ir)
-{
- ir_constant *constval;
- struct assignment_entry *entry;
-
- entry = get_assignment_entry(ir->lhs->variable_referenced(), &this->list);
- assert(entry);
- entry->assignment_count++;
-
- /* If it's already constant, don't do the work. */
- if (entry->var->constant_value)
- return visit_continue;
-
- /* OK, now find if we actually have all the right conditions for
- * this to be a constant value assigned to the var.
- */
- if (ir->condition)
- return visit_continue;
-
- ir_variable *var = ir->whole_variable_written();
- if (!var)
- return visit_continue;
-
- constval = ir->rhs->constant_expression_value();
- if (!constval)
- return visit_continue;
-
- /* Mark this entry as having a constant assignment (if the
- * assignment count doesn't go >1). do_constant_variable will fix
- * up the variable with the constant value later.
- */
- entry->constval = constval;
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_constant_variable_visitor::visit_enter(ir_call *ir)
-{
- exec_list_iterator sig_iter = ir->get_callee()->parameters.iterator();
- foreach_iter(exec_list_iterator, iter, *ir) {
- ir_rvalue *param_rval = (ir_rvalue *)iter.get();
- ir_variable *param = (ir_variable *)sig_iter.get();
-
- if (param->mode == ir_var_out ||
- param->mode == ir_var_inout) {
- ir_variable *var = param_rval->variable_referenced();
- struct assignment_entry *entry;
-
- assert(var);
- entry = get_assignment_entry(var, &this->list);
- entry->assignment_count++;
- }
- sig_iter.next();
- }
- return visit_continue;
-}
-
-/**
- * Does a copy propagation pass on the code present in the instruction stream.
- */
-bool
-do_constant_variable(exec_list *instructions)
-{
- bool progress = false;
- ir_constant_variable_visitor v;
-
- v.run(instructions);
-
- while (!v.list.is_empty()) {
-
- struct assignment_entry *entry;
- entry = exec_node_data(struct assignment_entry, v.list.head, link);
-
- if (entry->assignment_count == 1 && entry->constval && entry->our_scope) {
- entry->var->constant_value = entry->constval;
- progress = true;
- }
- entry->link.remove();
- free(entry);
- }
-
- return progress;
-}
-
-bool
-do_constant_variable_unlinked(exec_list *instructions)
-{
- bool progress = false;
-
- foreach_iter(exec_list_iterator, iter, *instructions) {
- ir_instruction *ir = (ir_instruction *)iter.get();
- ir_function *f = ir->as_function();
- if (f) {
- foreach_iter(exec_list_iterator, sigiter, *f) {
- ir_function_signature *sig =
- (ir_function_signature *) sigiter.get();
- if (do_constant_variable(&sig->body))
- progress = true;
- }
- }
- }
-
- return progress;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file opt_constant_variable.cpp
+ *
+ * Marks variables assigned a single constant value over the course
+ * of the program as constant.
+ *
+ * The goal here is to trigger further constant folding and then dead
+ * code elimination. This is common with vector/matrix constructors
+ * and calls to builtin functions.
+ */
+
+#include "ir.h"
+#include "ir_visitor.h"
+#include "ir_optimization.h"
+#include "glsl_types.h"
+
+struct assignment_entry {
+ exec_node link;
+ int assignment_count;
+ ir_variable *var;
+ ir_constant *constval;
+ bool our_scope;
+};
+
+class ir_constant_variable_visitor : public ir_hierarchical_visitor {
+public:
+ virtual ir_visitor_status visit_enter(ir_dereference_variable *);
+ virtual ir_visitor_status visit(ir_variable *);
+ virtual ir_visitor_status visit_enter(ir_assignment *);
+ virtual ir_visitor_status visit_enter(ir_call *);
+
+ exec_list list;
+};
+
+static struct assignment_entry *
+get_assignment_entry(ir_variable *var, exec_list *list)
+{
+ struct assignment_entry *entry;
+
+ foreach_list_typed(struct assignment_entry, entry, link, list) {
+ if (entry->var == var)
+ return entry;
+ }
+
+ entry = (struct assignment_entry *)calloc(1, sizeof(*entry));
+ entry->var = var;
+ list->push_head(&entry->link);
+ return entry;
+}
+
+ir_visitor_status
+ir_constant_variable_visitor::visit(ir_variable *ir)
+{
+ struct assignment_entry *entry = get_assignment_entry(ir, &this->list);
+ entry->our_scope = true;
+ return visit_continue;
+}
+
+/* Skip derefs of variables so that we can detect declarations. */
+ir_visitor_status
+ir_constant_variable_visitor::visit_enter(ir_dereference_variable *ir)
+{
+ (void)ir;
+ return visit_continue_with_parent;
+}
+
+ir_visitor_status
+ir_constant_variable_visitor::visit_enter(ir_assignment *ir)
+{
+ ir_constant *constval;
+ struct assignment_entry *entry;
+
+ entry = get_assignment_entry(ir->lhs->variable_referenced(), &this->list);
+ assert(entry);
+ entry->assignment_count++;
+
+ /* If it's already constant, don't do the work. */
+ if (entry->var->constant_value)
+ return visit_continue;
+
+ /* OK, now find if we actually have all the right conditions for
+ * this to be a constant value assigned to the var.
+ */
+ if (ir->condition)
+ return visit_continue;
+
+ ir_variable *var = ir->whole_variable_written();
+ if (!var)
+ return visit_continue;
+
+ constval = ir->rhs->constant_expression_value();
+ if (!constval)
+ return visit_continue;
+
+ /* Mark this entry as having a constant assignment (if the
+ * assignment count doesn't go >1). do_constant_variable will fix
+ * up the variable with the constant value later.
+ */
+ entry->constval = constval;
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_constant_variable_visitor::visit_enter(ir_call *ir)
+{
+ exec_list_iterator sig_iter = ir->get_callee()->parameters.iterator();
+ foreach_iter(exec_list_iterator, iter, *ir) {
+ ir_rvalue *param_rval = (ir_rvalue *)iter.get();
+ ir_variable *param = (ir_variable *)sig_iter.get();
+
+ if (param->mode == ir_var_out ||
+ param->mode == ir_var_inout) {
+ ir_variable *var = param_rval->variable_referenced();
+ struct assignment_entry *entry;
+
+ assert(var);
+ entry = get_assignment_entry(var, &this->list);
+ entry->assignment_count++;
+ }
+ sig_iter.next();
+ }
+ return visit_continue;
+}
+
+/**
+ * Does a copy propagation pass on the code present in the instruction stream.
+ */
+bool
+do_constant_variable(exec_list *instructions)
+{
+ bool progress = false;
+ ir_constant_variable_visitor v;
+
+ v.run(instructions);
+
+ while (!v.list.is_empty()) {
+
+ struct assignment_entry *entry;
+ entry = exec_node_data(struct assignment_entry, v.list.head, link);
+
+ if (entry->assignment_count == 1 && entry->constval && entry->our_scope) {
+ entry->var->constant_value = entry->constval;
+ progress = true;
+ }
+ entry->link.remove();
+ free(entry);
+ }
+
+ return progress;
+}
+
+bool
+do_constant_variable_unlinked(exec_list *instructions)
+{
+ bool progress = false;
+
+ foreach_iter(exec_list_iterator, iter, *instructions) {
+ ir_instruction *ir = (ir_instruction *)iter.get();
+ ir_function *f = ir->as_function();
+ if (f) {
+ foreach_iter(exec_list_iterator, sigiter, *f) {
+ ir_function_signature *sig =
+ (ir_function_signature *) sigiter.get();
+ if (do_constant_variable(&sig->body))
+ progress = true;
+ }
+ }
+ }
+
+ return progress;
+}
diff --git a/mesalib/src/glsl/opt_dead_code.cpp b/mesalib/src/glsl/opt_dead_code.cpp
index cb500d2d1..492ba73a1 100644
--- a/mesalib/src/glsl/opt_dead_code.cpp
+++ b/mesalib/src/glsl/opt_dead_code.cpp
@@ -1,142 +1,142 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file opt_dead_code.cpp
- *
- * Eliminates dead assignments and variable declarations from the code.
- */
-
-#include "ir.h"
-#include "ir_visitor.h"
-#include "ir_variable_refcount.h"
-#include "glsl_types.h"
-
-static bool debug = false;
-
-/**
- * Do a dead code pass over instructions and everything that instructions
- * references.
- *
- * Note that this will remove assignments to globals, so it is not suitable
- * for usage on an unlinked instruction stream.
- */
-bool
-do_dead_code(exec_list *instructions)
-{
- ir_variable_refcount_visitor v;
- bool progress = false;
-
- v.run(instructions);
-
- foreach_iter(exec_list_iterator, iter, v.variable_list) {
- variable_entry *entry = (variable_entry *)iter.get();
-
- /* Since each assignment is a reference, the refereneced count must be
- * greater than or equal to the assignment count. If they are equal,
- * then all of the references are assignments, and the variable is
- * dead.
- *
- * Note that if the variable is neither assigned nor referenced, both
- * counts will be zero and will be caught by the equality test.
- */
- assert(entry->referenced_count >= entry->assigned_count);
-
- if (debug) {
- printf("%s@%p: %d refs, %d assigns, %sdeclared in our scope\n",
- entry->var->name, (void *) entry->var,
- entry->referenced_count, entry->assigned_count,
- entry->declaration ? "" : "not ");
- }
-
- if ((entry->referenced_count > entry->assigned_count)
- || !entry->declaration)
- continue;
-
- if (entry->assign) {
- /* Remove a single dead assignment to the variable we found.
- * Don't do so if it's a shader output, though.
- */
- if (entry->var->mode != ir_var_out &&
- entry->var->mode != ir_var_inout &&
- !ir_has_call(entry->assign)) {
- entry->assign->remove();
- progress = true;
-
- if (debug) {
- printf("Removed assignment to %s@%p\n",
- entry->var->name, (void *) entry->var);
- }
- }
- } else {
- /* If there are no assignments or references to the variable left,
- * then we can remove its declaration.
- */
-
- /* uniform initializers are precious, and could get used by another
- * stage.
- */
- if (entry->var->mode == ir_var_uniform &&
- entry->var->constant_value)
- continue;
-
- entry->var->remove();
- progress = true;
-
- if (debug) {
- printf("Removed declaration of %s@%p\n",
- entry->var->name, (void *) entry->var);
- }
- }
- }
-
- return progress;
-}
-
-/**
- * Does a dead code pass on the functions present in the instruction stream.
- *
- * This is suitable for use while the program is not linked, as it will
- * ignore variable declarations (and the assignments to them) for variables
- * with global scope.
- */
-bool
-do_dead_code_unlinked(exec_list *instructions)
-{
- bool progress = false;
-
- foreach_iter(exec_list_iterator, iter, *instructions) {
- ir_instruction *ir = (ir_instruction *)iter.get();
- ir_function *f = ir->as_function();
- if (f) {
- foreach_iter(exec_list_iterator, sigiter, *f) {
- ir_function_signature *sig =
- (ir_function_signature *) sigiter.get();
- if (do_dead_code(&sig->body))
- progress = true;
- }
- }
- }
-
- return progress;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file opt_dead_code.cpp
+ *
+ * Eliminates dead assignments and variable declarations from the code.
+ */
+
+#include "ir.h"
+#include "ir_visitor.h"
+#include "ir_variable_refcount.h"
+#include "glsl_types.h"
+
+static bool debug = false;
+
+/**
+ * Do a dead code pass over instructions and everything that instructions
+ * references.
+ *
+ * Note that this will remove assignments to globals, so it is not suitable
+ * for usage on an unlinked instruction stream.
+ */
+bool
+do_dead_code(exec_list *instructions)
+{
+ ir_variable_refcount_visitor v;
+ bool progress = false;
+
+ v.run(instructions);
+
+ foreach_iter(exec_list_iterator, iter, v.variable_list) {
+ variable_entry *entry = (variable_entry *)iter.get();
+
+ /* Since each assignment is a reference, the refereneced count must be
+ * greater than or equal to the assignment count. If they are equal,
+ * then all of the references are assignments, and the variable is
+ * dead.
+ *
+ * Note that if the variable is neither assigned nor referenced, both
+ * counts will be zero and will be caught by the equality test.
+ */
+ assert(entry->referenced_count >= entry->assigned_count);
+
+ if (debug) {
+ printf("%s@%p: %d refs, %d assigns, %sdeclared in our scope\n",
+ entry->var->name, (void *) entry->var,
+ entry->referenced_count, entry->assigned_count,
+ entry->declaration ? "" : "not ");
+ }
+
+ if ((entry->referenced_count > entry->assigned_count)
+ || !entry->declaration)
+ continue;
+
+ if (entry->assign) {
+ /* Remove a single dead assignment to the variable we found.
+ * Don't do so if it's a shader output, though.
+ */
+ if (entry->var->mode != ir_var_out &&
+ entry->var->mode != ir_var_inout &&
+ !ir_has_call(entry->assign)) {
+ entry->assign->remove();
+ progress = true;
+
+ if (debug) {
+ printf("Removed assignment to %s@%p\n",
+ entry->var->name, (void *) entry->var);
+ }
+ }
+ } else {
+ /* If there are no assignments or references to the variable left,
+ * then we can remove its declaration.
+ */
+
+ /* uniform initializers are precious, and could get used by another
+ * stage.
+ */
+ if (entry->var->mode == ir_var_uniform &&
+ entry->var->constant_value)
+ continue;
+
+ entry->var->remove();
+ progress = true;
+
+ if (debug) {
+ printf("Removed declaration of %s@%p\n",
+ entry->var->name, (void *) entry->var);
+ }
+ }
+ }
+
+ return progress;
+}
+
+/**
+ * Does a dead code pass on the functions present in the instruction stream.
+ *
+ * This is suitable for use while the program is not linked, as it will
+ * ignore variable declarations (and the assignments to them) for variables
+ * with global scope.
+ */
+bool
+do_dead_code_unlinked(exec_list *instructions)
+{
+ bool progress = false;
+
+ foreach_iter(exec_list_iterator, iter, *instructions) {
+ ir_instruction *ir = (ir_instruction *)iter.get();
+ ir_function *f = ir->as_function();
+ if (f) {
+ foreach_iter(exec_list_iterator, sigiter, *f) {
+ ir_function_signature *sig =
+ (ir_function_signature *) sigiter.get();
+ if (do_dead_code(&sig->body))
+ progress = true;
+ }
+ }
+ }
+
+ return progress;
+}
diff --git a/mesalib/src/glsl/opt_dead_code_local.cpp b/mesalib/src/glsl/opt_dead_code_local.cpp
index 39962bd60..42e5e94c8 100644
--- a/mesalib/src/glsl/opt_dead_code_local.cpp
+++ b/mesalib/src/glsl/opt_dead_code_local.cpp
@@ -1,222 +1,222 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file opt_dead_code_local.cpp
- *
- * Eliminates local dead assignments from the code.
- *
- * This operates on basic blocks, tracking assignments and finding if
- * they're used before the variable is completely reassigned.
- *
- * Compare this to ir_dead_code.cpp, which operates globally looking
- * for assignments to variables that are never read.
- */
-
-#include "ir.h"
-#include "ir_basic_block.h"
-#include "ir_optimization.h"
-#include "glsl_types.h"
-
-static bool debug = false;
-
-class assignment_entry : public exec_node
-{
-public:
- assignment_entry(ir_variable *lhs, ir_instruction *ir)
- {
- assert(lhs);
- assert(ir);
- this->lhs = lhs;
- this->ir = ir;
- }
-
- ir_variable *lhs;
- ir_instruction *ir;
-};
-
-class kill_for_derefs_visitor : public ir_hierarchical_visitor {
-public:
- kill_for_derefs_visitor(exec_list *assignments)
- {
- this->assignments = assignments;
- }
-
- virtual ir_visitor_status visit(ir_dereference_variable *ir)
- {
- ir_variable *const var = ir->variable_referenced();
-
- foreach_iter(exec_list_iterator, iter, *this->assignments) {
- assignment_entry *entry = (assignment_entry *)iter.get();
-
- if (entry->lhs == var) {
- if (debug)
- printf("kill %s\n", entry->lhs->name);
- entry->remove();
- }
- }
-
- return visit_continue;
- }
-
-private:
- exec_list *assignments;
-};
-
-class array_index_visit : public ir_hierarchical_visitor {
-public:
- array_index_visit(ir_hierarchical_visitor *v)
- {
- this->visitor = v;
- }
-
- virtual ir_visitor_status visit_enter(class ir_dereference_array *ir)
- {
- ir->array_index->accept(visitor);
- return visit_continue;
- }
-
- static void run(ir_instruction *ir, ir_hierarchical_visitor *v)
- {
- array_index_visit top_visit(v);
- ir->accept(& top_visit);
- }
-
- ir_hierarchical_visitor *visitor;
-};
-
-
-/**
- * Adds an entry to the available copy list if it's a plain assignment
- * of a variable to a variable.
- */
-static bool
-process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments)
-{
- ir_variable *var = NULL;
- bool progress = false;
- kill_for_derefs_visitor v(assignments);
-
- /* Kill assignment entries for things used to produce this assignment. */
- ir->rhs->accept(&v);
- if (ir->condition) {
- ir->condition->accept(&v);
- }
-
- /* Kill assignment enties used as array indices.
- */
- array_index_visit::run(ir->lhs, &v);
- var = ir->lhs->variable_referenced();
- assert(var);
-
- /* Now, check if we did a whole-variable assignment. */
- if (!ir->condition && (ir->whole_variable_written() != NULL)) {
- /* We did a whole-variable assignment. So, any instruction in
- * the assignment list with the same LHS is dead.
- */
- if (debug)
- printf("looking for %s to remove\n", var->name);
- foreach_iter(exec_list_iterator, iter, *assignments) {
- assignment_entry *entry = (assignment_entry *)iter.get();
-
- if (entry->lhs == var) {
- if (debug)
- printf("removing %s\n", var->name);
- entry->ir->remove();
- entry->remove();
- progress = true;
- }
- }
- }
-
- /* Add this instruction to the assignment list available to be removed.
- * But not if the assignment has other side effects.
- */
- if (ir_has_call(ir))
- return progress;
-
- assignment_entry *entry = new(ctx) assignment_entry(var, ir);
- assignments->push_tail(entry);
-
- if (debug) {
- printf("add %s\n", var->name);
-
- printf("current entries\n");
- foreach_iter(exec_list_iterator, iter, *assignments) {
- assignment_entry *entry = (assignment_entry *)iter.get();
-
- printf(" %s\n", entry->lhs->name);
- }
- }
-
- return progress;
-}
-
-static void
-dead_code_local_basic_block(ir_instruction *first,
- ir_instruction *last,
- void *data)
-{
- ir_instruction *ir, *ir_next;
- /* List of avaialble_copy */
- exec_list assignments;
- bool *out_progress = (bool *)data;
- bool progress = false;
-
- void *ctx = ralloc_context(NULL);
- /* Safe looping, since process_assignment */
- for (ir = first, ir_next = (ir_instruction *)first->next;;
- ir = ir_next, ir_next = (ir_instruction *)ir->next) {
- ir_assignment *ir_assign = ir->as_assignment();
-
- if (debug) {
- ir->print();
- printf("\n");
- }
-
- if (ir_assign) {
- progress = process_assignment(ctx, ir_assign, &assignments) || progress;
- } else {
- kill_for_derefs_visitor kill(&assignments);
- ir->accept(&kill);
- }
-
- if (ir == last)
- break;
- }
- *out_progress = progress;
- ralloc_free(ctx);
-}
-
-/**
- * Does a copy propagation pass on the code present in the instruction stream.
- */
-bool
-do_dead_code_local(exec_list *instructions)
-{
- bool progress = false;
-
- call_for_basic_blocks(instructions, dead_code_local_basic_block, &progress);
-
- return progress;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file opt_dead_code_local.cpp
+ *
+ * Eliminates local dead assignments from the code.
+ *
+ * This operates on basic blocks, tracking assignments and finding if
+ * they're used before the variable is completely reassigned.
+ *
+ * Compare this to ir_dead_code.cpp, which operates globally looking
+ * for assignments to variables that are never read.
+ */
+
+#include "ir.h"
+#include "ir_basic_block.h"
+#include "ir_optimization.h"
+#include "glsl_types.h"
+
+static bool debug = false;
+
+class assignment_entry : public exec_node
+{
+public:
+ assignment_entry(ir_variable *lhs, ir_instruction *ir)
+ {
+ assert(lhs);
+ assert(ir);
+ this->lhs = lhs;
+ this->ir = ir;
+ }
+
+ ir_variable *lhs;
+ ir_instruction *ir;
+};
+
+class kill_for_derefs_visitor : public ir_hierarchical_visitor {
+public:
+ kill_for_derefs_visitor(exec_list *assignments)
+ {
+ this->assignments = assignments;
+ }
+
+ virtual ir_visitor_status visit(ir_dereference_variable *ir)
+ {
+ ir_variable *const var = ir->variable_referenced();
+
+ foreach_iter(exec_list_iterator, iter, *this->assignments) {
+ assignment_entry *entry = (assignment_entry *)iter.get();
+
+ if (entry->lhs == var) {
+ if (debug)
+ printf("kill %s\n", entry->lhs->name);
+ entry->remove();
+ }
+ }
+
+ return visit_continue;
+ }
+
+private:
+ exec_list *assignments;
+};
+
+class array_index_visit : public ir_hierarchical_visitor {
+public:
+ array_index_visit(ir_hierarchical_visitor *v)
+ {
+ this->visitor = v;
+ }
+
+ virtual ir_visitor_status visit_enter(class ir_dereference_array *ir)
+ {
+ ir->array_index->accept(visitor);
+ return visit_continue;
+ }
+
+ static void run(ir_instruction *ir, ir_hierarchical_visitor *v)
+ {
+ array_index_visit top_visit(v);
+ ir->accept(& top_visit);
+ }
+
+ ir_hierarchical_visitor *visitor;
+};
+
+
+/**
+ * Adds an entry to the available copy list if it's a plain assignment
+ * of a variable to a variable.
+ */
+static bool
+process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments)
+{
+ ir_variable *var = NULL;
+ bool progress = false;
+ kill_for_derefs_visitor v(assignments);
+
+ /* Kill assignment entries for things used to produce this assignment. */
+ ir->rhs->accept(&v);
+ if (ir->condition) {
+ ir->condition->accept(&v);
+ }
+
+ /* Kill assignment enties used as array indices.
+ */
+ array_index_visit::run(ir->lhs, &v);
+ var = ir->lhs->variable_referenced();
+ assert(var);
+
+ /* Now, check if we did a whole-variable assignment. */
+ if (!ir->condition && (ir->whole_variable_written() != NULL)) {
+ /* We did a whole-variable assignment. So, any instruction in
+ * the assignment list with the same LHS is dead.
+ */
+ if (debug)
+ printf("looking for %s to remove\n", var->name);
+ foreach_iter(exec_list_iterator, iter, *assignments) {
+ assignment_entry *entry = (assignment_entry *)iter.get();
+
+ if (entry->lhs == var) {
+ if (debug)
+ printf("removing %s\n", var->name);
+ entry->ir->remove();
+ entry->remove();
+ progress = true;
+ }
+ }
+ }
+
+ /* Add this instruction to the assignment list available to be removed.
+ * But not if the assignment has other side effects.
+ */
+ if (ir_has_call(ir))
+ return progress;
+
+ assignment_entry *entry = new(ctx) assignment_entry(var, ir);
+ assignments->push_tail(entry);
+
+ if (debug) {
+ printf("add %s\n", var->name);
+
+ printf("current entries\n");
+ foreach_iter(exec_list_iterator, iter, *assignments) {
+ assignment_entry *entry = (assignment_entry *)iter.get();
+
+ printf(" %s\n", entry->lhs->name);
+ }
+ }
+
+ return progress;
+}
+
+static void
+dead_code_local_basic_block(ir_instruction *first,
+ ir_instruction *last,
+ void *data)
+{
+ ir_instruction *ir, *ir_next;
+ /* List of avaialble_copy */
+ exec_list assignments;
+ bool *out_progress = (bool *)data;
+ bool progress = false;
+
+ void *ctx = ralloc_context(NULL);
+ /* Safe looping, since process_assignment */
+ for (ir = first, ir_next = (ir_instruction *)first->next;;
+ ir = ir_next, ir_next = (ir_instruction *)ir->next) {
+ ir_assignment *ir_assign = ir->as_assignment();
+
+ if (debug) {
+ ir->print();
+ printf("\n");
+ }
+
+ if (ir_assign) {
+ progress = process_assignment(ctx, ir_assign, &assignments) || progress;
+ } else {
+ kill_for_derefs_visitor kill(&assignments);
+ ir->accept(&kill);
+ }
+
+ if (ir == last)
+ break;
+ }
+ *out_progress = progress;
+ ralloc_free(ctx);
+}
+
+/**
+ * Does a copy propagation pass on the code present in the instruction stream.
+ */
+bool
+do_dead_code_local(exec_list *instructions)
+{
+ bool progress = false;
+
+ call_for_basic_blocks(instructions, dead_code_local_basic_block, &progress);
+
+ return progress;
+}
diff --git a/mesalib/src/glsl/opt_dead_functions.cpp b/mesalib/src/glsl/opt_dead_functions.cpp
index ceb79080a..6d41af5c5 100644
--- a/mesalib/src/glsl/opt_dead_functions.cpp
+++ b/mesalib/src/glsl/opt_dead_functions.cpp
@@ -1,153 +1,153 @@
- /*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
- /**
- * \file opt_dead_functions.cpp
- *
- * Eliminates unused functions from the linked program.
- */
-
- #include "ir.h"
- #include "ir_visitor.h"
- #include "ir_expression_flattening.h"
- #include "glsl_types.h"
-
- class signature_entry : public exec_node
- {
- public:
- signature_entry(ir_function_signature *sig)
- {
- this->signature = sig;
- this->used = false;
- }
-
- ir_function_signature *signature;
- bool used;
- };
-
- class ir_dead_functions_visitor : public ir_hierarchical_visitor {
- public:
- ir_dead_functions_visitor()
- {
- this->mem_ctx = ralloc_context(NULL);
- }
-
- ~ir_dead_functions_visitor()
- {
- ralloc_free(this->mem_ctx);
- }
-
- virtual ir_visitor_status visit_enter(ir_function_signature *);
- virtual ir_visitor_status visit_enter(ir_call *);
-
- signature_entry *get_signature_entry(ir_function_signature *var);
-
- bool (*predicate)(ir_instruction *ir);
-
- /* List of signature_entry */
- exec_list signature_list;
- void *mem_ctx;
- };
-
-
- signature_entry *
- ir_dead_functions_visitor::get_signature_entry(ir_function_signature *sig)
- {
- foreach_iter(exec_list_iterator, iter, this->signature_list) {
- signature_entry *entry = (signature_entry *)iter.get();
- if (entry->signature == sig)
- return entry;
- }
-
- signature_entry *entry = new(mem_ctx) signature_entry(sig);
- this->signature_list.push_tail(entry);
- return entry;
- }
-
-
- ir_visitor_status
- ir_dead_functions_visitor::visit_enter(ir_function_signature *ir)
- {
- signature_entry *entry = this->get_signature_entry(ir);
-
- if (strcmp(ir->function_name(), "main") == 0) {
- entry->used = true;
- }
-
- return visit_continue;
- }
-
-
- ir_visitor_status
- ir_dead_functions_visitor::visit_enter(ir_call *ir)
- {
- signature_entry *entry = this->get_signature_entry(ir->get_callee());
-
- entry->used = true;
-
- return visit_continue;
-}
-
-bool
-do_dead_functions(exec_list *instructions)
-{
- ir_dead_functions_visitor v;
- bool progress = false;
-
- visit_list_elements(&v, instructions);
-
- /* Now that we've figured out which function signatures are used, remove
- * the unused ones, and remove function definitions that have no more
- * signatures.
- */
- foreach_iter(exec_list_iterator, iter, v.signature_list) {
- signature_entry *entry = (signature_entry *)iter.get();
-
- if (!entry->used) {
- entry->signature->remove();
- delete entry->signature;
- progress = true;
- }
- delete(entry);
- }
-
- /* We don't just do this above when we nuked a signature because of
- * const pointers.
- */
- foreach_iter(exec_list_iterator, iter, *instructions) {
- ir_instruction *ir = (ir_instruction *)iter.get();
- ir_function *func = ir->as_function();
-
- if (func && func->signatures.is_empty()) {
- /* At this point (post-linking), the symbol table is no
- * longer in use, so not removing the function from the
- * symbol table should be OK.
- */
- func->remove();
- delete func;
- progress = true;
- }
- }
-
- return progress;
-}
+ /*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+ /**
+ * \file opt_dead_functions.cpp
+ *
+ * Eliminates unused functions from the linked program.
+ */
+
+ #include "ir.h"
+ #include "ir_visitor.h"
+ #include "ir_expression_flattening.h"
+ #include "glsl_types.h"
+
+ class signature_entry : public exec_node
+ {
+ public:
+ signature_entry(ir_function_signature *sig)
+ {
+ this->signature = sig;
+ this->used = false;
+ }
+
+ ir_function_signature *signature;
+ bool used;
+ };
+
+ class ir_dead_functions_visitor : public ir_hierarchical_visitor {
+ public:
+ ir_dead_functions_visitor()
+ {
+ this->mem_ctx = ralloc_context(NULL);
+ }
+
+ ~ir_dead_functions_visitor()
+ {
+ ralloc_free(this->mem_ctx);
+ }
+
+ virtual ir_visitor_status visit_enter(ir_function_signature *);
+ virtual ir_visitor_status visit_enter(ir_call *);
+
+ signature_entry *get_signature_entry(ir_function_signature *var);
+
+ bool (*predicate)(ir_instruction *ir);
+
+ /* List of signature_entry */
+ exec_list signature_list;
+ void *mem_ctx;
+ };
+
+
+ signature_entry *
+ ir_dead_functions_visitor::get_signature_entry(ir_function_signature *sig)
+ {
+ foreach_iter(exec_list_iterator, iter, this->signature_list) {
+ signature_entry *entry = (signature_entry *)iter.get();
+ if (entry->signature == sig)
+ return entry;
+ }
+
+ signature_entry *entry = new(mem_ctx) signature_entry(sig);
+ this->signature_list.push_tail(entry);
+ return entry;
+ }
+
+
+ ir_visitor_status
+ ir_dead_functions_visitor::visit_enter(ir_function_signature *ir)
+ {
+ signature_entry *entry = this->get_signature_entry(ir);
+
+ if (strcmp(ir->function_name(), "main") == 0) {
+ entry->used = true;
+ }
+
+ return visit_continue;
+ }
+
+
+ ir_visitor_status
+ ir_dead_functions_visitor::visit_enter(ir_call *ir)
+ {
+ signature_entry *entry = this->get_signature_entry(ir->get_callee());
+
+ entry->used = true;
+
+ return visit_continue;
+}
+
+bool
+do_dead_functions(exec_list *instructions)
+{
+ ir_dead_functions_visitor v;
+ bool progress = false;
+
+ visit_list_elements(&v, instructions);
+
+ /* Now that we've figured out which function signatures are used, remove
+ * the unused ones, and remove function definitions that have no more
+ * signatures.
+ */
+ foreach_iter(exec_list_iterator, iter, v.signature_list) {
+ signature_entry *entry = (signature_entry *)iter.get();
+
+ if (!entry->used) {
+ entry->signature->remove();
+ delete entry->signature;
+ progress = true;
+ }
+ delete(entry);
+ }
+
+ /* We don't just do this above when we nuked a signature because of
+ * const pointers.
+ */
+ foreach_iter(exec_list_iterator, iter, *instructions) {
+ ir_instruction *ir = (ir_instruction *)iter.get();
+ ir_function *func = ir->as_function();
+
+ if (func && func->signatures.is_empty()) {
+ /* At this point (post-linking), the symbol table is no
+ * longer in use, so not removing the function from the
+ * symbol table should be OK.
+ */
+ func->remove();
+ delete func;
+ progress = true;
+ }
+ }
+
+ return progress;
+}
diff --git a/mesalib/src/glsl/opt_structure_splitting.cpp b/mesalib/src/glsl/opt_structure_splitting.cpp
index 014407c0b..ec2315499 100644
--- a/mesalib/src/glsl/opt_structure_splitting.cpp
+++ b/mesalib/src/glsl/opt_structure_splitting.cpp
@@ -1,361 +1,361 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file opt_structure_splitting.cpp
- *
- * If a structure is only ever referenced by its components, then
- * split those components out to individual variables so they can be
- * handled normally by other optimization passes.
- *
- * This skips structures like uniforms, which need to be accessible as
- * structures for their access by the GL.
- */
-
-#include "ir.h"
-#include "ir_visitor.h"
-#include "ir_print_visitor.h"
-#include "ir_rvalue_visitor.h"
-#include "glsl_types.h"
-
-static bool debug = false;
-
-// XXX using variable_entry2 here to avoid collision (MSVC multiply-defined
-// function) with the variable_entry class seen in ir_variable_refcount.h
-// Perhaps we can use the one in ir_variable_refcount.h and make this class
-// here go away?
-class variable_entry2 : public exec_node
-{
-public:
- variable_entry2(ir_variable *var)
- {
- this->var = var;
- this->whole_structure_access = 0;
- this->declaration = false;
- this->components = NULL;
- this->mem_ctx = NULL;
- }
-
- ir_variable *var; /* The key: the variable's pointer. */
-
- /** Number of times the variable is referenced, including assignments. */
- unsigned whole_structure_access;
-
- bool declaration; /* If the variable had a decl in the instruction stream */
-
- ir_variable **components;
-
- /** ralloc_parent(this->var) -- the shader's ralloc context. */
- void *mem_ctx;
-};
-
-
-class ir_structure_reference_visitor : public ir_hierarchical_visitor {
-public:
- ir_structure_reference_visitor(void)
- {
- this->mem_ctx = ralloc_context(NULL);
- this->variable_list.make_empty();
- }
-
- ~ir_structure_reference_visitor(void)
- {
- ralloc_free(mem_ctx);
- }
-
- virtual ir_visitor_status visit(ir_variable *);
- virtual ir_visitor_status visit(ir_dereference_variable *);
- virtual ir_visitor_status visit_enter(ir_dereference_record *);
- virtual ir_visitor_status visit_enter(ir_assignment *);
- virtual ir_visitor_status visit_enter(ir_function_signature *);
-
- variable_entry2 *get_variable_entry2(ir_variable *var);
-
- /* List of variable_entry */
- exec_list variable_list;
-
- void *mem_ctx;
-};
-
-variable_entry2 *
-ir_structure_reference_visitor::get_variable_entry2(ir_variable *var)
-{
- assert(var);
-
- if (!var->type->is_record() || var->mode == ir_var_uniform)
- return NULL;
-
- foreach_iter(exec_list_iterator, iter, this->variable_list) {
- variable_entry2 *entry = (variable_entry2 *)iter.get();
- if (entry->var == var)
- return entry;
- }
-
- variable_entry2 *entry = new(mem_ctx) variable_entry2(var);
- this->variable_list.push_tail(entry);
- return entry;
-}
-
-
-ir_visitor_status
-ir_structure_reference_visitor::visit(ir_variable *ir)
-{
- variable_entry2 *entry = this->get_variable_entry2(ir);
-
- if (entry)
- entry->declaration = true;
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_structure_reference_visitor::visit(ir_dereference_variable *ir)
-{
- ir_variable *const var = ir->variable_referenced();
- variable_entry2 *entry = this->get_variable_entry2(var);
-
- if (entry)
- entry->whole_structure_access++;
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_structure_reference_visitor::visit_enter(ir_dereference_record *ir)
-{
- (void) ir;
- /* Don't descend into the ir_dereference_variable below. */
- return visit_continue_with_parent;
-}
-
-ir_visitor_status
-ir_structure_reference_visitor::visit_enter(ir_assignment *ir)
-{
- if (ir->lhs->as_dereference_variable() &&
- ir->rhs->as_dereference_variable() &&
- !ir->condition) {
- /* We'll split copies of a structure to copies of components, so don't
- * descend to the ir_dereference_variables.
- */
- return visit_continue_with_parent;
- }
- return visit_continue;
-}
-
-ir_visitor_status
-ir_structure_reference_visitor::visit_enter(ir_function_signature *ir)
-{
- /* We don't want to descend into the function parameters and
- * dead-code eliminate them, so just accept the body here.
- */
- visit_list_elements(this, &ir->body);
- return visit_continue_with_parent;
-}
-
-class ir_structure_splitting_visitor : public ir_rvalue_visitor {
-public:
- ir_structure_splitting_visitor(exec_list *vars)
- {
- this->variable_list = vars;
- }
-
- virtual ~ir_structure_splitting_visitor()
- {
- }
-
- virtual ir_visitor_status visit_leave(ir_assignment *);
-
- void split_deref(ir_dereference **deref);
- void handle_rvalue(ir_rvalue **rvalue);
- variable_entry2 *get_splitting_entry(ir_variable *var);
-
- exec_list *variable_list;
- void *mem_ctx;
-};
-
-variable_entry2 *
-ir_structure_splitting_visitor::get_splitting_entry(ir_variable *var)
-{
- assert(var);
-
- if (!var->type->is_record())
- return NULL;
-
- foreach_iter(exec_list_iterator, iter, *this->variable_list) {
- variable_entry2 *entry = (variable_entry2 *)iter.get();
- if (entry->var == var) {
- return entry;
- }
- }
-
- return NULL;
-}
-
-void
-ir_structure_splitting_visitor::split_deref(ir_dereference **deref)
-{
- if ((*deref)->ir_type != ir_type_dereference_record)
- return;
-
- ir_dereference_record *deref_record = (ir_dereference_record *)*deref;
- ir_dereference_variable *deref_var = deref_record->record->as_dereference_variable();
- if (!deref_var)
- return;
-
- variable_entry2 *entry = get_splitting_entry(deref_var->var);
- if (!entry)
- return;
-
- unsigned int i;
- for (i = 0; i < entry->var->type->length; i++) {
- if (strcmp(deref_record->field,
- entry->var->type->fields.structure[i].name) == 0)
- break;
- }
- assert(i != entry->var->type->length);
-
- *deref = new(entry->mem_ctx) ir_dereference_variable(entry->components[i]);
-}
-
-void
-ir_structure_splitting_visitor::handle_rvalue(ir_rvalue **rvalue)
-{
- if (!*rvalue)
- return;
-
- ir_dereference *deref = (*rvalue)->as_dereference();
-
- if (!deref)
- return;
-
- split_deref(&deref);
- *rvalue = deref;
-}
-
-ir_visitor_status
-ir_structure_splitting_visitor::visit_leave(ir_assignment *ir)
-{
- ir_dereference_variable *lhs_deref = ir->lhs->as_dereference_variable();
- ir_dereference_variable *rhs_deref = ir->rhs->as_dereference_variable();
- variable_entry2 *lhs_entry = lhs_deref ? get_splitting_entry(lhs_deref->var) : NULL;
- variable_entry2 *rhs_entry = rhs_deref ? get_splitting_entry(rhs_deref->var) : NULL;
- const glsl_type *type = ir->rhs->type;
-
- if ((lhs_entry || rhs_entry) && !ir->condition) {
- for (unsigned int i = 0; i < type->length; i++) {
- ir_dereference *new_lhs, *new_rhs;
- void *mem_ctx = lhs_entry ? lhs_entry->mem_ctx : rhs_entry->mem_ctx;
-
- if (lhs_entry) {
- new_lhs = new(mem_ctx) ir_dereference_variable(lhs_entry->components[i]);
- } else {
- new_lhs = new(mem_ctx)
- ir_dereference_record(ir->lhs->clone(mem_ctx, NULL),
- type->fields.structure[i].name);
- }
-
- if (rhs_entry) {
- new_rhs = new(mem_ctx) ir_dereference_variable(rhs_entry->components[i]);
- } else {
- new_rhs = new(mem_ctx)
- ir_dereference_record(ir->rhs->clone(mem_ctx, NULL),
- type->fields.structure[i].name);
- }
-
- ir->insert_before(new(mem_ctx) ir_assignment(new_lhs,
- new_rhs,
- NULL));
- }
- ir->remove();
- } else {
- handle_rvalue(&ir->rhs);
- split_deref(&ir->lhs);
- }
-
- handle_rvalue(&ir->condition);
-
- return visit_continue;
-}
-
-bool
-do_structure_splitting(exec_list *instructions)
-{
- ir_structure_reference_visitor refs;
-
- visit_list_elements(&refs, instructions);
-
- /* Trim out variables we can't split. */
- foreach_iter(exec_list_iterator, iter, refs.variable_list) {
- variable_entry2 *entry = (variable_entry2 *)iter.get();
-
- if (debug) {
- printf("structure %s@%p: decl %d, whole_access %d\n",
- entry->var->name, (void *) entry->var, entry->declaration,
- entry->whole_structure_access);
- }
-
- if (!entry->declaration || entry->whole_structure_access) {
- entry->remove();
- }
- }
-
- if (refs.variable_list.is_empty())
- return false;
-
- void *mem_ctx = ralloc_context(NULL);
-
- /* Replace the decls of the structures to be split with their split
- * components.
- */
- foreach_iter(exec_list_iterator, iter, refs.variable_list) {
- variable_entry2 *entry = (variable_entry2 *)iter.get();
- const struct glsl_type *type = entry->var->type;
-
- entry->mem_ctx = ralloc_parent(entry->var);
-
- entry->components = ralloc_array(mem_ctx,
- ir_variable *,
- type->length);
-
- for (unsigned int i = 0; i < entry->var->type->length; i++) {
- const char *name = ralloc_asprintf(mem_ctx, "%s_%s",
- entry->var->name,
- type->fields.structure[i].name);
-
- entry->components[i] =
- new(entry->mem_ctx) ir_variable(type->fields.structure[i].type,
- name,
- ir_var_temporary);
- entry->var->insert_before(entry->components[i]);
- }
-
- entry->var->remove();
- }
-
- ir_structure_splitting_visitor split(&refs.variable_list);
- visit_list_elements(&split, instructions);
-
- ralloc_free(mem_ctx);
-
- return true;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file opt_structure_splitting.cpp
+ *
+ * If a structure is only ever referenced by its components, then
+ * split those components out to individual variables so they can be
+ * handled normally by other optimization passes.
+ *
+ * This skips structures like uniforms, which need to be accessible as
+ * structures for their access by the GL.
+ */
+
+#include "ir.h"
+#include "ir_visitor.h"
+#include "ir_print_visitor.h"
+#include "ir_rvalue_visitor.h"
+#include "glsl_types.h"
+
+static bool debug = false;
+
+// XXX using variable_entry2 here to avoid collision (MSVC multiply-defined
+// function) with the variable_entry class seen in ir_variable_refcount.h
+// Perhaps we can use the one in ir_variable_refcount.h and make this class
+// here go away?
+class variable_entry2 : public exec_node
+{
+public:
+ variable_entry2(ir_variable *var)
+ {
+ this->var = var;
+ this->whole_structure_access = 0;
+ this->declaration = false;
+ this->components = NULL;
+ this->mem_ctx = NULL;
+ }
+
+ ir_variable *var; /* The key: the variable's pointer. */
+
+ /** Number of times the variable is referenced, including assignments. */
+ unsigned whole_structure_access;
+
+ bool declaration; /* If the variable had a decl in the instruction stream */
+
+ ir_variable **components;
+
+ /** ralloc_parent(this->var) -- the shader's ralloc context. */
+ void *mem_ctx;
+};
+
+
+class ir_structure_reference_visitor : public ir_hierarchical_visitor {
+public:
+ ir_structure_reference_visitor(void)
+ {
+ this->mem_ctx = ralloc_context(NULL);
+ this->variable_list.make_empty();
+ }
+
+ ~ir_structure_reference_visitor(void)
+ {
+ ralloc_free(mem_ctx);
+ }
+
+ virtual ir_visitor_status visit(ir_variable *);
+ virtual ir_visitor_status visit(ir_dereference_variable *);
+ virtual ir_visitor_status visit_enter(ir_dereference_record *);
+ virtual ir_visitor_status visit_enter(ir_assignment *);
+ virtual ir_visitor_status visit_enter(ir_function_signature *);
+
+ variable_entry2 *get_variable_entry2(ir_variable *var);
+
+ /* List of variable_entry */
+ exec_list variable_list;
+
+ void *mem_ctx;
+};
+
+variable_entry2 *
+ir_structure_reference_visitor::get_variable_entry2(ir_variable *var)
+{
+ assert(var);
+
+ if (!var->type->is_record() || var->mode == ir_var_uniform)
+ return NULL;
+
+ foreach_iter(exec_list_iterator, iter, this->variable_list) {
+ variable_entry2 *entry = (variable_entry2 *)iter.get();
+ if (entry->var == var)
+ return entry;
+ }
+
+ variable_entry2 *entry = new(mem_ctx) variable_entry2(var);
+ this->variable_list.push_tail(entry);
+ return entry;
+}
+
+
+ir_visitor_status
+ir_structure_reference_visitor::visit(ir_variable *ir)
+{
+ variable_entry2 *entry = this->get_variable_entry2(ir);
+
+ if (entry)
+ entry->declaration = true;
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_structure_reference_visitor::visit(ir_dereference_variable *ir)
+{
+ ir_variable *const var = ir->variable_referenced();
+ variable_entry2 *entry = this->get_variable_entry2(var);
+
+ if (entry)
+ entry->whole_structure_access++;
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_structure_reference_visitor::visit_enter(ir_dereference_record *ir)
+{
+ (void) ir;
+ /* Don't descend into the ir_dereference_variable below. */
+ return visit_continue_with_parent;
+}
+
+ir_visitor_status
+ir_structure_reference_visitor::visit_enter(ir_assignment *ir)
+{
+ if (ir->lhs->as_dereference_variable() &&
+ ir->rhs->as_dereference_variable() &&
+ !ir->condition) {
+ /* We'll split copies of a structure to copies of components, so don't
+ * descend to the ir_dereference_variables.
+ */
+ return visit_continue_with_parent;
+ }
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_structure_reference_visitor::visit_enter(ir_function_signature *ir)
+{
+ /* We don't want to descend into the function parameters and
+ * dead-code eliminate them, so just accept the body here.
+ */
+ visit_list_elements(this, &ir->body);
+ return visit_continue_with_parent;
+}
+
+class ir_structure_splitting_visitor : public ir_rvalue_visitor {
+public:
+ ir_structure_splitting_visitor(exec_list *vars)
+ {
+ this->variable_list = vars;
+ }
+
+ virtual ~ir_structure_splitting_visitor()
+ {
+ }
+
+ virtual ir_visitor_status visit_leave(ir_assignment *);
+
+ void split_deref(ir_dereference **deref);
+ void handle_rvalue(ir_rvalue **rvalue);
+ variable_entry2 *get_splitting_entry(ir_variable *var);
+
+ exec_list *variable_list;
+ void *mem_ctx;
+};
+
+variable_entry2 *
+ir_structure_splitting_visitor::get_splitting_entry(ir_variable *var)
+{
+ assert(var);
+
+ if (!var->type->is_record())
+ return NULL;
+
+ foreach_iter(exec_list_iterator, iter, *this->variable_list) {
+ variable_entry2 *entry = (variable_entry2 *)iter.get();
+ if (entry->var == var) {
+ return entry;
+ }
+ }
+
+ return NULL;
+}
+
+void
+ir_structure_splitting_visitor::split_deref(ir_dereference **deref)
+{
+ if ((*deref)->ir_type != ir_type_dereference_record)
+ return;
+
+ ir_dereference_record *deref_record = (ir_dereference_record *)*deref;
+ ir_dereference_variable *deref_var = deref_record->record->as_dereference_variable();
+ if (!deref_var)
+ return;
+
+ variable_entry2 *entry = get_splitting_entry(deref_var->var);
+ if (!entry)
+ return;
+
+ unsigned int i;
+ for (i = 0; i < entry->var->type->length; i++) {
+ if (strcmp(deref_record->field,
+ entry->var->type->fields.structure[i].name) == 0)
+ break;
+ }
+ assert(i != entry->var->type->length);
+
+ *deref = new(entry->mem_ctx) ir_dereference_variable(entry->components[i]);
+}
+
+void
+ir_structure_splitting_visitor::handle_rvalue(ir_rvalue **rvalue)
+{
+ if (!*rvalue)
+ return;
+
+ ir_dereference *deref = (*rvalue)->as_dereference();
+
+ if (!deref)
+ return;
+
+ split_deref(&deref);
+ *rvalue = deref;
+}
+
+ir_visitor_status
+ir_structure_splitting_visitor::visit_leave(ir_assignment *ir)
+{
+ ir_dereference_variable *lhs_deref = ir->lhs->as_dereference_variable();
+ ir_dereference_variable *rhs_deref = ir->rhs->as_dereference_variable();
+ variable_entry2 *lhs_entry = lhs_deref ? get_splitting_entry(lhs_deref->var) : NULL;
+ variable_entry2 *rhs_entry = rhs_deref ? get_splitting_entry(rhs_deref->var) : NULL;
+ const glsl_type *type = ir->rhs->type;
+
+ if ((lhs_entry || rhs_entry) && !ir->condition) {
+ for (unsigned int i = 0; i < type->length; i++) {
+ ir_dereference *new_lhs, *new_rhs;
+ void *mem_ctx = lhs_entry ? lhs_entry->mem_ctx : rhs_entry->mem_ctx;
+
+ if (lhs_entry) {
+ new_lhs = new(mem_ctx) ir_dereference_variable(lhs_entry->components[i]);
+ } else {
+ new_lhs = new(mem_ctx)
+ ir_dereference_record(ir->lhs->clone(mem_ctx, NULL),
+ type->fields.structure[i].name);
+ }
+
+ if (rhs_entry) {
+ new_rhs = new(mem_ctx) ir_dereference_variable(rhs_entry->components[i]);
+ } else {
+ new_rhs = new(mem_ctx)
+ ir_dereference_record(ir->rhs->clone(mem_ctx, NULL),
+ type->fields.structure[i].name);
+ }
+
+ ir->insert_before(new(mem_ctx) ir_assignment(new_lhs,
+ new_rhs,
+ NULL));
+ }
+ ir->remove();
+ } else {
+ handle_rvalue(&ir->rhs);
+ split_deref(&ir->lhs);
+ }
+
+ handle_rvalue(&ir->condition);
+
+ return visit_continue;
+}
+
+bool
+do_structure_splitting(exec_list *instructions)
+{
+ ir_structure_reference_visitor refs;
+
+ visit_list_elements(&refs, instructions);
+
+ /* Trim out variables we can't split. */
+ foreach_iter(exec_list_iterator, iter, refs.variable_list) {
+ variable_entry2 *entry = (variable_entry2 *)iter.get();
+
+ if (debug) {
+ printf("structure %s@%p: decl %d, whole_access %d\n",
+ entry->var->name, (void *) entry->var, entry->declaration,
+ entry->whole_structure_access);
+ }
+
+ if (!entry->declaration || entry->whole_structure_access) {
+ entry->remove();
+ }
+ }
+
+ if (refs.variable_list.is_empty())
+ return false;
+
+ void *mem_ctx = ralloc_context(NULL);
+
+ /* Replace the decls of the structures to be split with their split
+ * components.
+ */
+ foreach_iter(exec_list_iterator, iter, refs.variable_list) {
+ variable_entry2 *entry = (variable_entry2 *)iter.get();
+ const struct glsl_type *type = entry->var->type;
+
+ entry->mem_ctx = ralloc_parent(entry->var);
+
+ entry->components = ralloc_array(mem_ctx,
+ ir_variable *,
+ type->length);
+
+ for (unsigned int i = 0; i < entry->var->type->length; i++) {
+ const char *name = ralloc_asprintf(mem_ctx, "%s_%s",
+ entry->var->name,
+ type->fields.structure[i].name);
+
+ entry->components[i] =
+ new(entry->mem_ctx) ir_variable(type->fields.structure[i].type,
+ name,
+ ir_var_temporary);
+ entry->var->insert_before(entry->components[i]);
+ }
+
+ entry->var->remove();
+ }
+
+ ir_structure_splitting_visitor split(&refs.variable_list);
+ visit_list_elements(&split, instructions);
+
+ ralloc_free(mem_ctx);
+
+ return true;
+}
diff --git a/mesalib/src/glsl/opt_swizzle_swizzle.cpp b/mesalib/src/glsl/opt_swizzle_swizzle.cpp
index bc442fa86..e23655240 100644
--- a/mesalib/src/glsl/opt_swizzle_swizzle.cpp
+++ b/mesalib/src/glsl/opt_swizzle_swizzle.cpp
@@ -1,93 +1,93 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file opt_swizzle_swizzle.cpp
- *
- * Eliminates the second swizzle in a swizzle chain.
- */
-
-#include "ir.h"
-#include "ir_visitor.h"
-#include "ir_optimization.h"
-#include "glsl_types.h"
-
-class ir_swizzle_swizzle_visitor : public ir_hierarchical_visitor {
-public:
- ir_swizzle_swizzle_visitor()
- {
- progress = false;
- }
-
- virtual ir_visitor_status visit_enter(ir_swizzle *);
-
- bool progress;
-};
-
-ir_visitor_status
-ir_swizzle_swizzle_visitor::visit_enter(ir_swizzle *ir)
-{
- int mask2[4];
-
- ir_swizzle *swiz2 = ir->val->as_swizzle();
- if (!swiz2)
- return visit_continue;
-
- memset(&mask2, 0, sizeof(mask2));
- if (swiz2->mask.num_components >= 1)
- mask2[0] = swiz2->mask.x;
- if (swiz2->mask.num_components >= 2)
- mask2[1] = swiz2->mask.y;
- if (swiz2->mask.num_components >= 3)
- mask2[2] = swiz2->mask.z;
- if (swiz2->mask.num_components >= 4)
- mask2[3] = swiz2->mask.w;
-
- if (ir->mask.num_components >= 1)
- ir->mask.x = mask2[ir->mask.x];
- if (ir->mask.num_components >= 2)
- ir->mask.y = mask2[ir->mask.y];
- if (ir->mask.num_components >= 3)
- ir->mask.z = mask2[ir->mask.z];
- if (ir->mask.num_components >= 4)
- ir->mask.w = mask2[ir->mask.w];
-
- ir->val = swiz2->val;
-
- this->progress = true;
-
- return visit_continue;
-}
-
-/**
- * Does a copy propagation pass on the code present in the instruction stream.
- */
-bool
-do_swizzle_swizzle(exec_list *instructions)
-{
- ir_swizzle_swizzle_visitor v;
-
- v.run(instructions);
-
- return v.progress;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file opt_swizzle_swizzle.cpp
+ *
+ * Eliminates the second swizzle in a swizzle chain.
+ */
+
+#include "ir.h"
+#include "ir_visitor.h"
+#include "ir_optimization.h"
+#include "glsl_types.h"
+
+class ir_swizzle_swizzle_visitor : public ir_hierarchical_visitor {
+public:
+ ir_swizzle_swizzle_visitor()
+ {
+ progress = false;
+ }
+
+ virtual ir_visitor_status visit_enter(ir_swizzle *);
+
+ bool progress;
+};
+
+ir_visitor_status
+ir_swizzle_swizzle_visitor::visit_enter(ir_swizzle *ir)
+{
+ int mask2[4];
+
+ ir_swizzle *swiz2 = ir->val->as_swizzle();
+ if (!swiz2)
+ return visit_continue;
+
+ memset(&mask2, 0, sizeof(mask2));
+ if (swiz2->mask.num_components >= 1)
+ mask2[0] = swiz2->mask.x;
+ if (swiz2->mask.num_components >= 2)
+ mask2[1] = swiz2->mask.y;
+ if (swiz2->mask.num_components >= 3)
+ mask2[2] = swiz2->mask.z;
+ if (swiz2->mask.num_components >= 4)
+ mask2[3] = swiz2->mask.w;
+
+ if (ir->mask.num_components >= 1)
+ ir->mask.x = mask2[ir->mask.x];
+ if (ir->mask.num_components >= 2)
+ ir->mask.y = mask2[ir->mask.y];
+ if (ir->mask.num_components >= 3)
+ ir->mask.z = mask2[ir->mask.z];
+ if (ir->mask.num_components >= 4)
+ ir->mask.w = mask2[ir->mask.w];
+
+ ir->val = swiz2->val;
+
+ this->progress = true;
+
+ return visit_continue;
+}
+
+/**
+ * Does a copy propagation pass on the code present in the instruction stream.
+ */
+bool
+do_swizzle_swizzle(exec_list *instructions)
+{
+ ir_swizzle_swizzle_visitor v;
+
+ v.run(instructions);
+
+ return v.progress;
+}
diff --git a/mesalib/src/glsl/opt_tree_grafting.cpp b/mesalib/src/glsl/opt_tree_grafting.cpp
index 1ef940f9c..75bd11c09 100644
--- a/mesalib/src/glsl/opt_tree_grafting.cpp
+++ b/mesalib/src/glsl/opt_tree_grafting.cpp
@@ -1,368 +1,368 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file opt_tree_grafting.cpp
- *
- * Takes assignments to variables that are dereferenced only once and
- * pastes the RHS expression into where the variable is dereferenced.
- *
- * In the process of various operations like function inlining and
- * tertiary op handling, we'll end up with our expression trees having
- * been chopped up into a series of assignments of short expressions
- * to temps. Other passes like ir_algebraic.cpp would prefer to see
- * the deepest expression trees they can to try to optimize them.
- *
- * This is a lot like copy propagaton. In comparison, copy
- * propagation only acts on plain copies, not arbitrary expressions on
- * the RHS. Generally, we wouldn't want to go pasting some
- * complicated expression everywhere it got used, though, so we don't
- * handle expressions in that pass.
- *
- * The hard part is making sure we don't move an expression across
- * some other assignments that would change the value of the
- * expression. So we split this into two passes: First, find the
- * variables in our scope which are written to once and read once, and
- * then go through basic blocks seeing if we find an opportunity to
- * move those expressions safely.
- */
-
-#include "ir.h"
-#include "ir_visitor.h"
-#include "ir_variable_refcount.h"
-#include "ir_basic_block.h"
-#include "ir_optimization.h"
-#include "glsl_types.h"
-
-static bool debug = false;
-
-class ir_tree_grafting_visitor : public ir_hierarchical_visitor {
-public:
- ir_tree_grafting_visitor(ir_assignment *graft_assign,
- ir_variable *graft_var)
- {
- this->progress = false;
- this->graft_assign = graft_assign;
- this->graft_var = graft_var;
- }
-
- virtual ir_visitor_status visit_leave(class ir_assignment *);
- virtual ir_visitor_status visit_enter(class ir_call *);
- virtual ir_visitor_status visit_enter(class ir_expression *);
- virtual ir_visitor_status visit_enter(class ir_function *);
- virtual ir_visitor_status visit_enter(class ir_function_signature *);
- virtual ir_visitor_status visit_enter(class ir_if *);
- virtual ir_visitor_status visit_enter(class ir_loop *);
- virtual ir_visitor_status visit_enter(class ir_swizzle *);
- virtual ir_visitor_status visit_enter(class ir_texture *);
-
- bool do_graft(ir_rvalue **rvalue);
-
- bool progress;
- ir_variable *graft_var;
- ir_assignment *graft_assign;
-};
-
-struct find_deref_info {
- ir_variable *var;
- bool found;
-};
-
-void
-dereferences_variable_callback(ir_instruction *ir, void *data)
-{
- struct find_deref_info *info = (struct find_deref_info *)data;
- ir_dereference_variable *deref = ir->as_dereference_variable();
-
- if (deref && deref->var == info->var)
- info->found = true;
-}
-
-static bool
-dereferences_variable(ir_instruction *ir, ir_variable *var)
-{
- struct find_deref_info info;
-
- info.var = var;
- info.found = false;
-
- visit_tree(ir, dereferences_variable_callback, &info);
-
- return info.found;
-}
-
-bool
-ir_tree_grafting_visitor::do_graft(ir_rvalue **rvalue)
-{
- if (!*rvalue)
- return false;
-
- ir_dereference_variable *deref = (*rvalue)->as_dereference_variable();
-
- if (!deref || deref->var != this->graft_var)
- return false;
-
- if (debug) {
- printf("GRAFTING:\n");
- this->graft_assign->print();
- printf("\n");
- printf("TO:\n");
- (*rvalue)->print();
- printf("\n");
- }
-
- this->graft_assign->remove();
- *rvalue = this->graft_assign->rhs;
-
- this->progress = true;
- return true;
-}
-
-ir_visitor_status
-ir_tree_grafting_visitor::visit_enter(ir_loop *ir)
-{
- (void)ir;
- /* Do not traverse into the body of the loop since that is a
- * different basic block.
- */
- return visit_stop;
-}
-
-ir_visitor_status
-ir_tree_grafting_visitor::visit_leave(ir_assignment *ir)
-{
- if (do_graft(&ir->rhs) ||
- do_graft(&ir->condition))
- return visit_stop;
-
- /* If this assignment updates a variable used in the assignment
- * we're trying to graft, then we're done.
- */
- if (dereferences_variable(this->graft_assign->rhs,
- ir->lhs->variable_referenced())) {
- if (debug) {
- printf("graft killed by: ");
- ir->print();
- printf("\n");
- }
- return visit_stop;
- }
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_tree_grafting_visitor::visit_enter(ir_function *ir)
-{
- (void) ir;
- return visit_continue_with_parent;
-}
-
-ir_visitor_status
-ir_tree_grafting_visitor::visit_enter(ir_function_signature *ir)
-{
- (void)ir;
- return visit_continue_with_parent;
-}
-
-ir_visitor_status
-ir_tree_grafting_visitor::visit_enter(ir_call *ir)
-{
- exec_list_iterator sig_iter = ir->get_callee()->parameters.iterator();
- /* Reminder: iterating ir_call iterates its parameters. */
- foreach_iter(exec_list_iterator, iter, *ir) {
- ir_variable *sig_param = (ir_variable *)sig_iter.get();
- ir_rvalue *ir = (ir_rvalue *)iter.get();
- ir_rvalue *new_ir = ir;
-
- if (sig_param->mode != ir_var_in && sig_param->mode != ir_var_const_in)
- continue;
-
- if (do_graft(&new_ir)) {
- ir->replace_with(new_ir);
- return visit_stop;
- }
- sig_iter.next();
- }
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_tree_grafting_visitor::visit_enter(ir_expression *ir)
-{
- for (unsigned int i = 0; i < ir->get_num_operands(); i++) {
- if (do_graft(&ir->operands[i]))
- return visit_stop;
- }
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_tree_grafting_visitor::visit_enter(ir_if *ir)
-{
- if (do_graft(&ir->condition))
- return visit_stop;
-
- /* Do not traverse into the body of the if-statement since that is a
- * different basic block.
- */
- return visit_continue_with_parent;
-}
-
-ir_visitor_status
-ir_tree_grafting_visitor::visit_enter(ir_swizzle *ir)
-{
- if (do_graft(&ir->val))
- return visit_stop;
-
- return visit_continue;
-}
-
-ir_visitor_status
-ir_tree_grafting_visitor::visit_enter(ir_texture *ir)
-{
- if (do_graft(&ir->coordinate) ||
- do_graft(&ir->projector) ||
- do_graft(&ir->offset) ||
- do_graft(&ir->shadow_comparitor))
- return visit_stop;
-
- switch (ir->op) {
- case ir_tex:
- break;
- case ir_txb:
- if (do_graft(&ir->lod_info.bias))
- return visit_stop;
- break;
- case ir_txf:
- case ir_txl:
- if (do_graft(&ir->lod_info.lod))
- return visit_stop;
- break;
- case ir_txd:
- if (do_graft(&ir->lod_info.grad.dPdx) ||
- do_graft(&ir->lod_info.grad.dPdy))
- return visit_stop;
- break;
- }
-
- return visit_continue;
-}
-
-struct tree_grafting_info {
- ir_variable_refcount_visitor *refs;
- bool progress;
-};
-
-static bool
-try_tree_grafting(ir_assignment *start,
- ir_variable *lhs_var,
- ir_instruction *bb_last)
-{
- ir_tree_grafting_visitor v(start, lhs_var);
-
- if (debug) {
- printf("trying to graft: ");
- lhs_var->print();
- printf("\n");
- }
-
- for (ir_instruction *ir = (ir_instruction *)start->next;
- ir != bb_last->next;
- ir = (ir_instruction *)ir->next) {
-
- if (debug) {
- printf("- ");
- ir->print();
- printf("\n");
- }
-
- ir_visitor_status s = ir->accept(&v);
- if (s == visit_stop)
- return v.progress;
- }
-
- return false;
-}
-
-static void
-tree_grafting_basic_block(ir_instruction *bb_first,
- ir_instruction *bb_last,
- void *data)
-{
- struct tree_grafting_info *info = (struct tree_grafting_info *)data;
- ir_instruction *ir, *next;
-
- for (ir = bb_first, next = (ir_instruction *)ir->next;
- ir != bb_last->next;
- ir = next, next = (ir_instruction *)ir->next) {
- ir_assignment *assign = ir->as_assignment();
-
- if (!assign)
- continue;
-
- ir_variable *lhs_var = assign->whole_variable_written();
- if (!lhs_var)
- continue;
-
- if (lhs_var->mode == ir_var_out ||
- lhs_var->mode == ir_var_inout)
- continue;
-
- variable_entry *entry = info->refs->get_variable_entry(lhs_var);
-
- if (!entry->declaration ||
- entry->assigned_count != 1 ||
- entry->referenced_count != 2)
- continue;
-
- assert(assign == entry->assign);
-
- /* Found a possibly graftable assignment. Now, walk through the
- * rest of the BB seeing if the deref is here, and if nothing interfered with
- * pasting its expression's values in between.
- */
- info->progress |= try_tree_grafting(assign, lhs_var, bb_last);
- }
-}
-
-/**
- * Does a copy propagation pass on the code present in the instruction stream.
- */
-bool
-do_tree_grafting(exec_list *instructions)
-{
- ir_variable_refcount_visitor refs;
- struct tree_grafting_info info;
-
- info.progress = false;
- info.refs = &refs;
-
- visit_list_elements(info.refs, instructions);
-
- call_for_basic_blocks(instructions, tree_grafting_basic_block, &info);
-
- return info.progress;
-}
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file opt_tree_grafting.cpp
+ *
+ * Takes assignments to variables that are dereferenced only once and
+ * pastes the RHS expression into where the variable is dereferenced.
+ *
+ * In the process of various operations like function inlining and
+ * tertiary op handling, we'll end up with our expression trees having
+ * been chopped up into a series of assignments of short expressions
+ * to temps. Other passes like ir_algebraic.cpp would prefer to see
+ * the deepest expression trees they can to try to optimize them.
+ *
+ * This is a lot like copy propagaton. In comparison, copy
+ * propagation only acts on plain copies, not arbitrary expressions on
+ * the RHS. Generally, we wouldn't want to go pasting some
+ * complicated expression everywhere it got used, though, so we don't
+ * handle expressions in that pass.
+ *
+ * The hard part is making sure we don't move an expression across
+ * some other assignments that would change the value of the
+ * expression. So we split this into two passes: First, find the
+ * variables in our scope which are written to once and read once, and
+ * then go through basic blocks seeing if we find an opportunity to
+ * move those expressions safely.
+ */
+
+#include "ir.h"
+#include "ir_visitor.h"
+#include "ir_variable_refcount.h"
+#include "ir_basic_block.h"
+#include "ir_optimization.h"
+#include "glsl_types.h"
+
+static bool debug = false;
+
+class ir_tree_grafting_visitor : public ir_hierarchical_visitor {
+public:
+ ir_tree_grafting_visitor(ir_assignment *graft_assign,
+ ir_variable *graft_var)
+ {
+ this->progress = false;
+ this->graft_assign = graft_assign;
+ this->graft_var = graft_var;
+ }
+
+ virtual ir_visitor_status visit_leave(class ir_assignment *);
+ virtual ir_visitor_status visit_enter(class ir_call *);
+ virtual ir_visitor_status visit_enter(class ir_expression *);
+ virtual ir_visitor_status visit_enter(class ir_function *);
+ virtual ir_visitor_status visit_enter(class ir_function_signature *);
+ virtual ir_visitor_status visit_enter(class ir_if *);
+ virtual ir_visitor_status visit_enter(class ir_loop *);
+ virtual ir_visitor_status visit_enter(class ir_swizzle *);
+ virtual ir_visitor_status visit_enter(class ir_texture *);
+
+ bool do_graft(ir_rvalue **rvalue);
+
+ bool progress;
+ ir_variable *graft_var;
+ ir_assignment *graft_assign;
+};
+
+struct find_deref_info {
+ ir_variable *var;
+ bool found;
+};
+
+void
+dereferences_variable_callback(ir_instruction *ir, void *data)
+{
+ struct find_deref_info *info = (struct find_deref_info *)data;
+ ir_dereference_variable *deref = ir->as_dereference_variable();
+
+ if (deref && deref->var == info->var)
+ info->found = true;
+}
+
+static bool
+dereferences_variable(ir_instruction *ir, ir_variable *var)
+{
+ struct find_deref_info info;
+
+ info.var = var;
+ info.found = false;
+
+ visit_tree(ir, dereferences_variable_callback, &info);
+
+ return info.found;
+}
+
+bool
+ir_tree_grafting_visitor::do_graft(ir_rvalue **rvalue)
+{
+ if (!*rvalue)
+ return false;
+
+ ir_dereference_variable *deref = (*rvalue)->as_dereference_variable();
+
+ if (!deref || deref->var != this->graft_var)
+ return false;
+
+ if (debug) {
+ printf("GRAFTING:\n");
+ this->graft_assign->print();
+ printf("\n");
+ printf("TO:\n");
+ (*rvalue)->print();
+ printf("\n");
+ }
+
+ this->graft_assign->remove();
+ *rvalue = this->graft_assign->rhs;
+
+ this->progress = true;
+ return true;
+}
+
+ir_visitor_status
+ir_tree_grafting_visitor::visit_enter(ir_loop *ir)
+{
+ (void)ir;
+ /* Do not traverse into the body of the loop since that is a
+ * different basic block.
+ */
+ return visit_stop;
+}
+
+ir_visitor_status
+ir_tree_grafting_visitor::visit_leave(ir_assignment *ir)
+{
+ if (do_graft(&ir->rhs) ||
+ do_graft(&ir->condition))
+ return visit_stop;
+
+ /* If this assignment updates a variable used in the assignment
+ * we're trying to graft, then we're done.
+ */
+ if (dereferences_variable(this->graft_assign->rhs,
+ ir->lhs->variable_referenced())) {
+ if (debug) {
+ printf("graft killed by: ");
+ ir->print();
+ printf("\n");
+ }
+ return visit_stop;
+ }
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_tree_grafting_visitor::visit_enter(ir_function *ir)
+{
+ (void) ir;
+ return visit_continue_with_parent;
+}
+
+ir_visitor_status
+ir_tree_grafting_visitor::visit_enter(ir_function_signature *ir)
+{
+ (void)ir;
+ return visit_continue_with_parent;
+}
+
+ir_visitor_status
+ir_tree_grafting_visitor::visit_enter(ir_call *ir)
+{
+ exec_list_iterator sig_iter = ir->get_callee()->parameters.iterator();
+ /* Reminder: iterating ir_call iterates its parameters. */
+ foreach_iter(exec_list_iterator, iter, *ir) {
+ ir_variable *sig_param = (ir_variable *)sig_iter.get();
+ ir_rvalue *ir = (ir_rvalue *)iter.get();
+ ir_rvalue *new_ir = ir;
+
+ if (sig_param->mode != ir_var_in && sig_param->mode != ir_var_const_in)
+ continue;
+
+ if (do_graft(&new_ir)) {
+ ir->replace_with(new_ir);
+ return visit_stop;
+ }
+ sig_iter.next();
+ }
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_tree_grafting_visitor::visit_enter(ir_expression *ir)
+{
+ for (unsigned int i = 0; i < ir->get_num_operands(); i++) {
+ if (do_graft(&ir->operands[i]))
+ return visit_stop;
+ }
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_tree_grafting_visitor::visit_enter(ir_if *ir)
+{
+ if (do_graft(&ir->condition))
+ return visit_stop;
+
+ /* Do not traverse into the body of the if-statement since that is a
+ * different basic block.
+ */
+ return visit_continue_with_parent;
+}
+
+ir_visitor_status
+ir_tree_grafting_visitor::visit_enter(ir_swizzle *ir)
+{
+ if (do_graft(&ir->val))
+ return visit_stop;
+
+ return visit_continue;
+}
+
+ir_visitor_status
+ir_tree_grafting_visitor::visit_enter(ir_texture *ir)
+{
+ if (do_graft(&ir->coordinate) ||
+ do_graft(&ir->projector) ||
+ do_graft(&ir->offset) ||
+ do_graft(&ir->shadow_comparitor))
+ return visit_stop;
+
+ switch (ir->op) {
+ case ir_tex:
+ break;
+ case ir_txb:
+ if (do_graft(&ir->lod_info.bias))
+ return visit_stop;
+ break;
+ case ir_txf:
+ case ir_txl:
+ if (do_graft(&ir->lod_info.lod))
+ return visit_stop;
+ break;
+ case ir_txd:
+ if (do_graft(&ir->lod_info.grad.dPdx) ||
+ do_graft(&ir->lod_info.grad.dPdy))
+ return visit_stop;
+ break;
+ }
+
+ return visit_continue;
+}
+
+struct tree_grafting_info {
+ ir_variable_refcount_visitor *refs;
+ bool progress;
+};
+
+static bool
+try_tree_grafting(ir_assignment *start,
+ ir_variable *lhs_var,
+ ir_instruction *bb_last)
+{
+ ir_tree_grafting_visitor v(start, lhs_var);
+
+ if (debug) {
+ printf("trying to graft: ");
+ lhs_var->print();
+ printf("\n");
+ }
+
+ for (ir_instruction *ir = (ir_instruction *)start->next;
+ ir != bb_last->next;
+ ir = (ir_instruction *)ir->next) {
+
+ if (debug) {
+ printf("- ");
+ ir->print();
+ printf("\n");
+ }
+
+ ir_visitor_status s = ir->accept(&v);
+ if (s == visit_stop)
+ return v.progress;
+ }
+
+ return false;
+}
+
+static void
+tree_grafting_basic_block(ir_instruction *bb_first,
+ ir_instruction *bb_last,
+ void *data)
+{
+ struct tree_grafting_info *info = (struct tree_grafting_info *)data;
+ ir_instruction *ir, *next;
+
+ for (ir = bb_first, next = (ir_instruction *)ir->next;
+ ir != bb_last->next;
+ ir = next, next = (ir_instruction *)ir->next) {
+ ir_assignment *assign = ir->as_assignment();
+
+ if (!assign)
+ continue;
+
+ ir_variable *lhs_var = assign->whole_variable_written();
+ if (!lhs_var)
+ continue;
+
+ if (lhs_var->mode == ir_var_out ||
+ lhs_var->mode == ir_var_inout)
+ continue;
+
+ variable_entry *entry = info->refs->get_variable_entry(lhs_var);
+
+ if (!entry->declaration ||
+ entry->assigned_count != 1 ||
+ entry->referenced_count != 2)
+ continue;
+
+ assert(assign == entry->assign);
+
+ /* Found a possibly graftable assignment. Now, walk through the
+ * rest of the BB seeing if the deref is here, and if nothing interfered with
+ * pasting its expression's values in between.
+ */
+ info->progress |= try_tree_grafting(assign, lhs_var, bb_last);
+ }
+}
+
+/**
+ * Does a copy propagation pass on the code present in the instruction stream.
+ */
+bool
+do_tree_grafting(exec_list *instructions)
+{
+ ir_variable_refcount_visitor refs;
+ struct tree_grafting_info info;
+
+ info.progress = false;
+ info.refs = &refs;
+
+ visit_list_elements(info.refs, instructions);
+
+ call_for_basic_blocks(instructions, tree_grafting_basic_block, &info);
+
+ return info.progress;
+}
diff --git a/mesalib/src/glsl/s_expression.cpp b/mesalib/src/glsl/s_expression.cpp
index a922a50d3..b47b014c6 100644
--- a/mesalib/src/glsl/s_expression.cpp
+++ b/mesalib/src/glsl/s_expression.cpp
@@ -1,183 +1,183 @@
-/* -*- c++ -*- */
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include <assert.h>
-#include "s_expression.h"
-
-s_symbol::s_symbol(const char *tmp, size_t n)
-{
- this->str = ralloc_strndup (this, tmp, n);
- assert(this->str != NULL);
-}
-
-s_list::s_list()
-{
-}
-
-static void
-skip_whitespace(const char *& src)
-{
- src += strspn(src, " \v\t\r\n");
- /* Also skip Scheme-style comments: semi-colon 'til end of line */
- if (src[0] == ';') {
- src += strcspn(src, "\n");
- skip_whitespace(src);
- }
-}
-
-static s_expression *
-read_atom(void *ctx, const char *& src)
-{
- s_expression *expr = NULL;
-
- skip_whitespace(src);
-
- size_t n = strcspn(src, "( \v\t\r\n);");
- if (n == 0)
- return NULL; // no atom
-
- // Check if the atom is a number.
- char *float_end = NULL;
- double f = glsl_strtod(src, &float_end);
- if (float_end != src) {
- char *int_end = NULL;
- int i = strtol(src, &int_end, 10);
- // If strtod matched more characters, it must have a decimal part
- if (float_end > int_end)
- expr = new(ctx) s_float(f);
- else
- expr = new(ctx) s_int(i);
- } else {
- // Not a number; return a symbol.
- expr = new(ctx) s_symbol(src, n);
- }
-
- src += n;
-
- return expr;
-}
-
-s_expression *
-s_expression::read_expression(void *ctx, const char *&src)
-{
- assert(src != NULL);
-
- s_expression *atom = read_atom(ctx, src);
- if (atom != NULL)
- return atom;
-
- skip_whitespace(src);
- if (src[0] == '(') {
- ++src;
-
- s_list *list = new(ctx) s_list;
- s_expression *expr;
-
- while ((expr = read_expression(ctx, src)) != NULL) {
- list->subexpressions.push_tail(expr);
- }
- skip_whitespace(src);
- if (src[0] != ')') {
- printf("Unclosed expression (check your parenthesis).\n");
- return NULL;
- }
- ++src;
- return list;
- }
- return NULL;
-}
-
-void s_int::print()
-{
- printf("%d", this->val);
-}
-
-void s_float::print()
-{
- printf("%f", this->val);
-}
-
-void s_symbol::print()
-{
- printf("%s", this->str);
-}
-
-void s_list::print()
-{
- printf("(");
- foreach_iter(exec_list_iterator, it, this->subexpressions) {
- s_expression *expr = (s_expression*) it.get();
- expr->print();
- if (!expr->next->is_tail_sentinel())
- printf(" ");
- }
- printf(")");
-}
-
-// --------------------------------------------------
-
-bool
-s_pattern::match(s_expression *expr)
-{
- switch (type)
- {
- case EXPR: *p_expr = expr; break;
- case LIST: if (expr->is_list()) *p_list = (s_list *) expr; break;
- case SYMBOL: if (expr->is_symbol()) *p_symbol = (s_symbol *) expr; break;
- case NUMBER: if (expr->is_number()) *p_number = (s_number *) expr; break;
- case INT: if (expr->is_int()) *p_int = (s_int *) expr; break;
- case STRING:
- s_symbol *sym = SX_AS_SYMBOL(expr);
- if (sym != NULL && strcmp(sym->value(), literal) == 0)
- return true;
- return false;
- };
-
- return *p_expr == expr;
-}
-
-bool
-s_match(s_expression *top, unsigned n, s_pattern *pattern, bool partial)
-{
- s_list *list = SX_AS_LIST(top);
- if (list == NULL)
- return false;
-
- unsigned i = 0;
- foreach_iter(exec_list_iterator, it, list->subexpressions) {
- if (i >= n)
- return partial; /* More actual items than the pattern expected */
-
- s_expression *expr = (s_expression *) it.get();
- if (expr == NULL || !pattern[i].match(expr))
- return false;
-
- i++;
- }
-
- if (i < n)
- return false; /* Less actual items than the pattern expected */
-
- return true;
-}
+/* -*- c++ -*- */
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <assert.h>
+#include "s_expression.h"
+
+s_symbol::s_symbol(const char *tmp, size_t n)
+{
+ this->str = ralloc_strndup (this, tmp, n);
+ assert(this->str != NULL);
+}
+
+s_list::s_list()
+{
+}
+
+static void
+skip_whitespace(const char *& src)
+{
+ src += strspn(src, " \v\t\r\n");
+ /* Also skip Scheme-style comments: semi-colon 'til end of line */
+ if (src[0] == ';') {
+ src += strcspn(src, "\n");
+ skip_whitespace(src);
+ }
+}
+
+static s_expression *
+read_atom(void *ctx, const char *& src)
+{
+ s_expression *expr = NULL;
+
+ skip_whitespace(src);
+
+ size_t n = strcspn(src, "( \v\t\r\n);");
+ if (n == 0)
+ return NULL; // no atom
+
+ // Check if the atom is a number.
+ char *float_end = NULL;
+ double f = glsl_strtod(src, &float_end);
+ if (float_end != src) {
+ char *int_end = NULL;
+ int i = strtol(src, &int_end, 10);
+ // If strtod matched more characters, it must have a decimal part
+ if (float_end > int_end)
+ expr = new(ctx) s_float(f);
+ else
+ expr = new(ctx) s_int(i);
+ } else {
+ // Not a number; return a symbol.
+ expr = new(ctx) s_symbol(src, n);
+ }
+
+ src += n;
+
+ return expr;
+}
+
+s_expression *
+s_expression::read_expression(void *ctx, const char *&src)
+{
+ assert(src != NULL);
+
+ s_expression *atom = read_atom(ctx, src);
+ if (atom != NULL)
+ return atom;
+
+ skip_whitespace(src);
+ if (src[0] == '(') {
+ ++src;
+
+ s_list *list = new(ctx) s_list;
+ s_expression *expr;
+
+ while ((expr = read_expression(ctx, src)) != NULL) {
+ list->subexpressions.push_tail(expr);
+ }
+ skip_whitespace(src);
+ if (src[0] != ')') {
+ printf("Unclosed expression (check your parenthesis).\n");
+ return NULL;
+ }
+ ++src;
+ return list;
+ }
+ return NULL;
+}
+
+void s_int::print()
+{
+ printf("%d", this->val);
+}
+
+void s_float::print()
+{
+ printf("%f", this->val);
+}
+
+void s_symbol::print()
+{
+ printf("%s", this->str);
+}
+
+void s_list::print()
+{
+ printf("(");
+ foreach_iter(exec_list_iterator, it, this->subexpressions) {
+ s_expression *expr = (s_expression*) it.get();
+ expr->print();
+ if (!expr->next->is_tail_sentinel())
+ printf(" ");
+ }
+ printf(")");
+}
+
+// --------------------------------------------------
+
+bool
+s_pattern::match(s_expression *expr)
+{
+ switch (type)
+ {
+ case EXPR: *p_expr = expr; break;
+ case LIST: if (expr->is_list()) *p_list = (s_list *) expr; break;
+ case SYMBOL: if (expr->is_symbol()) *p_symbol = (s_symbol *) expr; break;
+ case NUMBER: if (expr->is_number()) *p_number = (s_number *) expr; break;
+ case INT: if (expr->is_int()) *p_int = (s_int *) expr; break;
+ case STRING:
+ s_symbol *sym = SX_AS_SYMBOL(expr);
+ if (sym != NULL && strcmp(sym->value(), literal) == 0)
+ return true;
+ return false;
+ };
+
+ return *p_expr == expr;
+}
+
+bool
+s_match(s_expression *top, unsigned n, s_pattern *pattern, bool partial)
+{
+ s_list *list = SX_AS_LIST(top);
+ if (list == NULL)
+ return false;
+
+ unsigned i = 0;
+ foreach_iter(exec_list_iterator, it, list->subexpressions) {
+ if (i >= n)
+ return partial; /* More actual items than the pattern expected */
+
+ s_expression *expr = (s_expression *) it.get();
+ if (expr == NULL || !pattern[i].match(expr))
+ return false;
+
+ i++;
+ }
+
+ if (i < n)
+ return false; /* Less actual items than the pattern expected */
+
+ return true;
+}
diff --git a/mesalib/src/mapi/glapi/gen/gen.bat b/mesalib/src/mapi/glapi/gen/gen.bat
new file mode 100644
index 000000000..2b1826a81
--- /dev/null
+++ b/mesalib/src/mapi/glapi/gen/gen.bat
@@ -0,0 +1,20 @@
+echo on
+glx_server_table.py -f gl_and_glX_API.xml > indirect_table.c
+glx_proto_size.py -m size_h --only-set -h _INDIRECT_SIZE_H_ > indirect_size.h
+glx_proto_size.py -m size_c --only-set > indirect_size.c
+glx_proto_size.py -m size_h --only-get -h _INDIRECT_SIZE_GET_H_ > indirect_size_get.h
+glx_proto_size.py -m size_c --only-get > indirect_size_get.c
+glx_proto_size.py -m reqsize_c > indirect_reqsize.c
+glx_proto_size.py -m reqsize_h --only-get -h _INDIRECT_SIZE_GET_H_ > indirect_reqsize.h
+glx_proto_recv.py -m dispatch_c > indirect_dispatch.c
+glx_proto_recv.py -m dispatch_c -s > indirect_dispatch_swap.c
+glx_proto_recv.py -m dispatch_h -f gl_and_glX_API.xml -s > indirect_dispatch.h
+gl_table.py > glapitable.h
+gl_table.py -m remap_table > dispatch.h
+rem gl_offsets.py > glapioffsets.h
+gl_apitemp.py > glapitemp.h
+gl_procs.py > glprocs.h
+
+glX_proto_send.py -m proto > indirect.c
+glX_proto_send.py -m init_h > indirect.h
+glX_proto_send.py -m init_c > indirect_init.c
diff --git a/mesalib/src/mapi/glapi/gen/gl_API.xml b/mesalib/src/mapi/glapi/gen/gl_API.xml
index 1f12c4234..b792c7815 100644
--- a/mesalib/src/mapi/glapi/gen/gl_API.xml
+++ b/mesalib/src/mapi/glapi/gen/gl_API.xml
@@ -183,18 +183,18 @@
<size name="Get" mode="get"/>
</enum>
<enum name="LIGHT_MODEL_LOCAL_VIEWER" count="1" value="0x0B51">
- <size name="LightModelfv"/>
- <size name="LightModeliv"/>
+ <size name="LightModelfv" mode="get"/>
+ <size name="LightModeliv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="LIGHT_MODEL_TWO_SIDE" count="1" value="0x0B52">
- <size name="LightModelfv"/>
- <size name="LightModeliv"/>
+ <size name="LightModelfv" mode="get"/>
+ <size name="LightModeliv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="LIGHT_MODEL_AMBIENT" count="4" value="0x0B53">
- <size name="LightModelfv"/>
- <size name="LightModeliv"/>
+ <size name="LightModelfv" mode="get"/>
+ <size name="LightModeliv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="SHADE_MODEL" count="1" value="0x0B54">
@@ -213,33 +213,33 @@
<size name="Get" mode="get"/>
</enum>
<enum name="FOG_INDEX" count="1" value="0x0B61">
- <size name="Fogfv"/>
- <size name="Fogiv"/>
+ <size name="Fogfv" mode="get"/>
+ <size name="Fogiv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="FOG_DENSITY" count="1" value="0x0B62">
- <size name="Fogfv"/>
- <size name="Fogiv"/>
+ <size name="Fogfv" mode="get"/>
+ <size name="Fogiv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="FOG_START" count="1" value="0x0B63">
- <size name="Fogfv"/>
- <size name="Fogiv"/>
+ <size name="Fogfv" mode="get"/>
+ <size name="Fogiv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="FOG_END" count="1" value="0x0B64">
- <size name="Fogfv"/>
- <size name="Fogiv"/>
+ <size name="Fogfv" mode="get"/>
+ <size name="Fogiv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="FOG_MODE" count="1" value="0x0B65">
- <size name="Fogfv"/>
- <size name="Fogiv"/>
+ <size name="Fogfv" mode="get"/>
+ <size name="Fogiv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="FOG_COLOR" count="4" value="0x0B66">
- <size name="Fogfv"/>
- <size name="Fogiv"/>
+ <size name="Fogfv" mode="get"/>
+ <size name="Fogiv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="DEPTH_RANGE" count="2" value="0x0B70">
@@ -531,8 +531,8 @@
<size name="Get" mode="get"/>
</enum>
<enum name="ALPHA_SCALE" count="1" value="0x0D1C">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
<size name="Get" mode="get"/>
@@ -625,93 +625,93 @@
<size name="Get" mode="get"/>
</enum>
<enum name="MAP1_COLOR_4" count="4" value="0x0D90">
- <size name="Map1d"/>
- <size name="Map1f"/>
+ <size name="Map1d" mode="get"/>
+ <size name="Map1f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP1_INDEX" count="1" value="0x0D91">
- <size name="Map1d"/>
- <size name="Map1f"/>
+ <size name="Map1d" mode="get"/>
+ <size name="Map1f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP1_NORMAL" count="3" value="0x0D92">
- <size name="Map1d"/>
- <size name="Map1f"/>
+ <size name="Map1d" mode="get"/>
+ <size name="Map1f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP1_TEXTURE_COORD_1" count="1" value="0x0D93">
- <size name="Map1d"/>
- <size name="Map1f"/>
+ <size name="Map1d" mode="get"/>
+ <size name="Map1f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP1_TEXTURE_COORD_2" count="2" value="0x0D94">
- <size name="Map1d"/>
- <size name="Map1f"/>
+ <size name="Map1d" mode="get"/>
+ <size name="Map1f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP1_TEXTURE_COORD_3" count="3" value="0x0D95">
- <size name="Map1d"/>
- <size name="Map1f"/>
+ <size name="Map1d" mode="get"/>
+ <size name="Map1f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP1_TEXTURE_COORD_4" count="4" value="0x0D96">
- <size name="Map1d"/>
- <size name="Map1f"/>
+ <size name="Map1d" mode="get"/>
+ <size name="Map1f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP1_VERTEX_3" count="3" value="0x0D97">
- <size name="Map1d"/>
- <size name="Map1f"/>
+ <size name="Map1d" mode="get"/>
+ <size name="Map1f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP1_VERTEX_4" count="4" value="0x0D98">
- <size name="Map1d"/>
- <size name="Map1f"/>
+ <size name="Map1d" mode="get"/>
+ <size name="Map1f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP2_COLOR_4" count="4" value="0x0DB0">
- <size name="Map2d"/>
- <size name="Map2f"/>
+ <size name="Map2d" mode="get"/>
+ <size name="Map2f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP2_INDEX" count="1" value="0x0DB1">
- <size name="Map2d"/>
- <size name="Map2f"/>
+ <size name="Map2d" mode="get"/>
+ <size name="Map2f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP2_NORMAL" count="3" value="0x0DB2">
- <size name="Map2d"/>
- <size name="Map2f"/>
+ <size name="Map2d" mode="get"/>
+ <size name="Map2f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP2_TEXTURE_COORD_1" count="1" value="0x0DB3">
- <size name="Map2d"/>
- <size name="Map2f"/>
+ <size name="Map2d" mode="get"/>
+ <size name="Map2f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP2_TEXTURE_COORD_2" count="2" value="0x0DB4">
- <size name="Map2d"/>
- <size name="Map2f"/>
+ <size name="Map2d" mode="get"/>
+ <size name="Map2f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP2_TEXTURE_COORD_3" count="3" value="0x0DB5">
- <size name="Map2d"/>
- <size name="Map2f"/>
+ <size name="Map2d" mode="get"/>
+ <size name="Map2f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP2_TEXTURE_COORD_4" count="4" value="0x0DB6">
- <size name="Map2d"/>
- <size name="Map2f"/>
+ <size name="Map2d" mode="get"/>
+ <size name="Map2f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP2_VERTEX_3" count="3" value="0x0DB7">
- <size name="Map2d"/>
- <size name="Map2f"/>
+ <size name="Map2d" mode="get"/>
+ <size name="Map2f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP2_VERTEX_4" count="4" value="0x0DB8">
- <size name="Map2d"/>
- <size name="Map2f"/>
+ <size name="Map2d" mode="get"/>
+ <size name="Map2f" mode="get"/>
<size name="Get" count="1" mode="get"/>
</enum>
<enum name="MAP1_GRID_DOMAIN" count="2" value="0x0DD0">
@@ -754,8 +754,8 @@
<size name="GetTexLevelParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_BORDER_COLOR" count="4" value="0x1004">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -763,111 +763,111 @@
<enum name="FASTEST" value="0x1101"/>
<enum name="NICEST" value="0x1102"/>
<enum name="AMBIENT" count="4" value="0x1200">
- <size name="Materialfv"/>
- <size name="Materialiv"/>
- <size name="Lightfv"/>
- <size name="Lightiv"/>
+ <size name="Materialfv" mode="get"/>
+ <size name="Materialiv" mode="get"/>
+ <size name="Lightfv" mode="get"/>
+ <size name="Lightiv" mode="get"/>
<size name="GetMaterialfv" mode="get"/>
<size name="GetMaterialiv" mode="get"/>
<size name="GetLightfv" mode="get"/>
<size name="GetLightiv" mode="get"/>
</enum>
<enum name="DIFFUSE" count="4" value="0x1201">
- <size name="Materialfv"/>
- <size name="Materialiv"/>
- <size name="Lightfv"/>
- <size name="Lightiv"/>
+ <size name="Materialfv" mode="get"/>
+ <size name="Materialiv" mode="get"/>
+ <size name="Lightfv" mode="get"/>
+ <size name="Lightiv" mode="get"/>
<size name="GetMaterialfv" mode="get"/>
<size name="GetMaterialiv" mode="get"/>
<size name="GetLightfv" mode="get"/>
<size name="GetLightiv" mode="get"/>
</enum>
<enum name="SPECULAR" count="4" value="0x1202">
- <size name="Materialfv"/>
- <size name="Materialiv"/>
- <size name="Lightfv"/>
- <size name="Lightiv"/>
+ <size name="Materialfv" mode="get"/>
+ <size name="Materialiv" mode="get"/>
+ <size name="Lightfv" mode="get"/>
+ <size name="Lightiv" mode="get"/>
<size name="GetMaterialfv" mode="get"/>
<size name="GetMaterialiv" mode="get"/>
<size name="GetLightfv" mode="get"/>
<size name="GetLightiv" mode="get"/>
</enum>
<enum name="POSITION" count="4" value="0x1203">
- <size name="Lightfv"/>
- <size name="Lightiv"/>
+ <size name="Lightfv" mode="get"/>
+ <size name="Lightiv" mode="get"/>
<size name="GetLightfv" mode="get"/>
<size name="GetLightiv" mode="get"/>
</enum>
<enum name="SPOT_DIRECTION" count="3" value="0x1204">
- <size name="Lightfv"/>
- <size name="Lightiv"/>
+ <size name="Lightfv" mode="get"/>
+ <size name="Lightiv" mode="get"/>
<size name="GetLightfv" mode="get"/>
<size name="GetLightiv" mode="get"/>
</enum>
<enum name="SPOT_EXPONENT" count="1" value="0x1205">
- <size name="Lightfv"/>
- <size name="Lightiv"/>
+ <size name="Lightfv" mode="get"/>
+ <size name="Lightiv" mode="get"/>
<size name="GetLightfv" mode="get"/>
<size name="GetLightiv" mode="get"/>
</enum>
<enum name="SPOT_CUTOFF" count="1" value="0x1206">
- <size name="Lightfv"/>
- <size name="Lightiv"/>
+ <size name="Lightfv" mode="get"/>
+ <size name="Lightiv" mode="get"/>
<size name="GetLightfv" mode="get"/>
<size name="GetLightiv" mode="get"/>
</enum>
<enum name="CONSTANT_ATTENUATION" count="1" value="0x1207">
- <size name="Lightfv"/>
- <size name="Lightiv"/>
+ <size name="Lightfv" mode="get"/>
+ <size name="Lightiv" mode="get"/>
<size name="GetLightfv" mode="get"/>
<size name="GetLightiv" mode="get"/>
</enum>
<enum name="LINEAR_ATTENUATION" count="1" value="0x1208">
- <size name="Lightfv"/>
- <size name="Lightiv"/>
+ <size name="Lightfv" mode="get"/>
+ <size name="Lightiv" mode="get"/>
<size name="GetLightfv" mode="get"/>
<size name="GetLightiv" mode="get"/>
</enum>
<enum name="QUADRATIC_ATTENUATION" count="1" value="0x1209">
- <size name="Lightfv"/>
- <size name="Lightiv"/>
+ <size name="Lightfv" mode="get"/>
+ <size name="Lightiv" mode="get"/>
<size name="GetLightfv" mode="get"/>
<size name="GetLightiv" mode="get"/>
</enum>
<enum name="COMPILE" value="0x1300"/>
<enum name="COMPILE_AND_EXECUTE" value="0x1301"/>
<enum name="BYTE" count="1" value="0x1400">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="UNSIGNED_BYTE" count="1" value="0x1401">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="SHORT" count="2" value="0x1402">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="UNSIGNED_SHORT" count="2" value="0x1403">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="INT" count="4" value="0x1404">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="UNSIGNED_INT" count="4" value="0x1405">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="FLOAT" count="4" value="0x1406">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="2_BYTES" count="2" value="0x1407">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="3_BYTES" count="3" value="0x1408">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="4_BYTES" count="4" value="0x1409">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="HALF_FLOAT" count="2" value="0x140B">
- <size name="CallLists"/>
+ <size name="CallLists" mode="get"/>
</enum>
<enum name="CLEAR" value="0x1500"/>
<enum name="AND" value="0x1501"/>
@@ -886,26 +886,26 @@
<enum name="NAND" value="0x150E"/>
<enum name="SET" value="0x150F"/>
<enum name="EMISSION" count="4" value="0x1600">
- <size name="Materialfv"/>
- <size name="Materialiv"/>
+ <size name="Materialfv" mode="get"/>
+ <size name="Materialiv" mode="get"/>
<size name="GetMaterialfv" mode="get"/>
<size name="GetMaterialiv" mode="get"/>
</enum>
<enum name="SHININESS" count="1" value="0x1601">
- <size name="Materialfv"/>
- <size name="Materialiv"/>
+ <size name="Materialfv" mode="get"/>
+ <size name="Materialiv" mode="get"/>
<size name="GetMaterialfv" mode="get"/>
<size name="GetMaterialiv" mode="get"/>
</enum>
<enum name="AMBIENT_AND_DIFFUSE" count="4" value="0x1602">
- <size name="Materialfv"/>
- <size name="Materialiv"/>
+ <size name="Materialfv" mode="get"/>
+ <size name="Materialiv" mode="get"/>
<size name="GetMaterialfv" mode="get"/>
<size name="GetMaterialiv" mode="get"/>
</enum>
<enum name="COLOR_INDEXES" count="3" value="0x1603">
- <size name="Materialfv"/>
- <size name="Materialiv"/>
+ <size name="Materialfv" mode="get"/>
+ <size name="Materialiv" mode="get"/>
<size name="GetMaterialfv" mode="get"/>
<size name="GetMaterialiv" mode="get"/>
</enum>
@@ -950,14 +950,14 @@
<enum name="MODULATE" value="0x2100"/>
<enum name="DECAL" value="0x2101"/>
<enum name="TEXTURE_ENV_MODE" count="1" value="0x2200">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="TEXTURE_ENV_COLOR" count="4" value="0x2201">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
@@ -966,25 +966,25 @@
<enum name="OBJECT_LINEAR" value="0x2401"/>
<enum name="SPHERE_MAP" value="0x2402"/>
<enum name="TEXTURE_GEN_MODE" count="1" value="0x2500">
- <size name="TexGendv"/>
- <size name="TexGenfv"/>
- <size name="TexGeniv"/>
+ <size name="TexGendv" mode="get"/>
+ <size name="TexGenfv" mode="get"/>
+ <size name="TexGeniv" mode="get"/>
<size name="GetTexGendv" mode="get"/>
<size name="GetTexGenfv" mode="get"/>
<size name="GetTexGeniv" mode="get"/>
</enum>
<enum name="OBJECT_PLANE" count="4" value="0x2501">
- <size name="TexGendv"/>
- <size name="TexGenfv"/>
- <size name="TexGeniv"/>
+ <size name="TexGendv" mode="get"/>
+ <size name="TexGenfv" mode="get"/>
+ <size name="TexGeniv" mode="get"/>
<size name="GetTexGendv" mode="get"/>
<size name="GetTexGenfv" mode="get"/>
<size name="GetTexGeniv" mode="get"/>
</enum>
<enum name="EYE_PLANE" count="4" value="0x2502">
- <size name="TexGendv"/>
- <size name="TexGenfv"/>
- <size name="TexGeniv"/>
+ <size name="TexGendv" mode="get"/>
+ <size name="TexGenfv" mode="get"/>
+ <size name="TexGeniv" mode="get"/>
<size name="GetTexGendv" mode="get"/>
<size name="GetTexGenfv" mode="get"/>
<size name="GetTexGeniv" mode="get"/>
@@ -996,26 +996,26 @@
<enum name="NEAREST_MIPMAP_LINEAR" value="0x2702"/>
<enum name="LINEAR_MIPMAP_LINEAR" value="0x2703"/>
<enum name="TEXTURE_MAG_FILTER" count="1" value="0x2800">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_MIN_FILTER" count="1" value="0x2801">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_WRAP_S" count="1" value="0x2802">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_WRAP_T" count="1" value="0x2803">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -3039,8 +3039,8 @@
<enum name="PROXY_TEXTURE_1D" value="0x8063"/>
<enum name="PROXY_TEXTURE_2D" value="0x8064"/>
<enum name="TEXTURE_PRIORITY" count="1" value="0x8066">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -3380,8 +3380,8 @@
<size name="GetTexLevelParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_WRAP_R" count="1" value="0x8072">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -3405,32 +3405,32 @@
</enum>
<enum name="CLAMP_TO_EDGE" value="0x812F"/>
<enum name="TEXTURE_MIN_LOD" count="1" value="0x813A">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_MAX_LOD" count="1" value="0x813B">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_BASE_LEVEL" count="1" value="0x813C">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_MAX_LEVEL" count="1" value="0x813D">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="LIGHT_MODEL_COLOR_CONTROL" count="1" value="0x81F8">
- <size name="LightModelfv"/>
- <size name="LightModeliv"/>
+ <size name="LightModelfv" mode="get"/>
+ <size name="LightModeliv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="SINGLE_COLOR" value="0x81F9"/>
@@ -3482,26 +3482,26 @@
</enum>
<enum name="CONVOLUTION_BORDER_MODE" count="1" value="0x8013">
- <size name="ConvolutionParameterfv"/>
- <size name="ConvolutionParameteriv"/>
+ <size name="ConvolutionParameterfv" mode="get"/>
+ <size name="ConvolutionParameteriv" mode="get"/>
<size name="GetConvolutionParameterfv" mode="get"/>
<size name="GetConvolutionParameteriv" mode="get"/>
</enum>
<enum name="CONVOLUTION_BORDER_COLOR" count="4" value="0x8154">
- <size name="ConvolutionParameterfv"/>
- <size name="ConvolutionParameteriv"/>
+ <size name="ConvolutionParameterfv" mode="get"/>
+ <size name="ConvolutionParameteriv" mode="get"/>
<size name="GetConvolutionParameterfv" mode="get"/>
<size name="GetConvolutionParameteriv" mode="get"/>
</enum>
<enum name="CONVOLUTION_FILTER_SCALE" count="4" value="0x8014">
- <size name="ConvolutionParameterfv"/>
- <size name="ConvolutionParameteriv"/>
+ <size name="ConvolutionParameterfv" mode="get"/>
+ <size name="ConvolutionParameteriv" mode="get"/>
<size name="GetConvolutionParameterfv" mode="get"/>
<size name="GetConvolutionParameteriv" mode="get"/>
</enum>
<enum name="CONVOLUTION_FILTER_BIAS" count="4" value="0x8015">
- <size name="ConvolutionParameterfv"/>
- <size name="ConvolutionParameteriv"/>
+ <size name="ConvolutionParameterfv" mode="get"/>
+ <size name="ConvolutionParameteriv" mode="get"/>
<size name="GetConvolutionParameterfv" mode="get"/>
<size name="GetConvolutionParameteriv" mode="get"/>
</enum>
@@ -3649,14 +3649,14 @@
<enum name="PROXY_POST_COLOR_MATRIX_COLOR_TABLE" value="0x80D5"/>
<enum name="COLOR_TABLE_SCALE" count="4" value="0x80D6">
- <size name="ColorTableParameterfv"/>
- <size name="ColorTableParameteriv"/>
+ <size name="ColorTableParameterfv" mode="get"/>
+ <size name="ColorTableParameteriv" mode="get"/>
<size name="GetColorTableParameterfv" mode="get"/>
<size name="GetColorTableParameteriv" mode="get"/>
</enum>
<enum name="COLOR_TABLE_BIAS" count="4" value="0x80D7">
- <size name="ColorTableParameterfv"/>
- <size name="ColorTableParameteriv"/>
+ <size name="ColorTableParameterfv" mode="get"/>
+ <size name="ColorTableParameteriv" mode="get"/>
<size name="GetColorTableParameterfv" mode="get"/>
<size name="GetColorTableParameteriv" mode="get"/>
</enum>
@@ -4133,92 +4133,92 @@
<enum name="CLAMP_TO_BORDER" value="0x812D"/>
<enum name="COMBINE" value="0x8570"/>
<enum name="COMBINE_RGB" count="1" value="0x8571">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="COMBINE_ALPHA" count="1" value="0x8572">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="SOURCE0_RGB" count="1" value="0x8580">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="SOURCE1_RGB" count="1" value="0x8581">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="SOURCE2_RGB" count="1" value="0x8582">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="SOURCE0_ALPHA" count="1" value="0x8588">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="SOURCE1_ALPHA" count="1" value="0x8589">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="SOURCE2_ALPHA" count="1" value="0x858A">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="OPERAND0_RGB" count="1" value="0x8590">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="OPERAND1_RGB" count="1" value="0x8591">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="OPERAND2_RGB" count="1" value="0x8592">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="OPERAND0_ALPHA" count="1" value="0x8598">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="OPERAND1_ALPHA" count="1" value="0x8599">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="OPERAND2_ALPHA" count="1" value="0x859A">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="RGB_SCALE" count="1" value="0x8573">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
@@ -4534,24 +4534,24 @@
<size name="Get" mode="get"/>
</enum>
<enum name="POINT_SIZE_MIN" count="1" value="0x8126">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="POINT_SIZE_MAX" count="1" value="0x8127">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="POINT_FADE_THRESHOLD_SIZE" count="1" value="0x8128">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="POINT_DISTANCE_ATTENUATION" count="3" value="0x8129">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="GENERATE_MIPMAP" count="1" value="0x8191">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -4600,10 +4600,10 @@
</enum>
<enum name="TEXTURE_FILTER_CONTROL" value="0x8500"/>
<enum name="TEXTURE_LOD_BIAS" count="1" value="0x8501">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
@@ -4616,20 +4616,20 @@
<size name="GetTexLevelParameteriv" mode="get"/>
</enum>
<enum name="DEPTH_TEXTURE_MODE" count="1" value="0x884B">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_COMPARE_MODE" count="1" value="0x884C">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_COMPARE_FUNC" count="1" value="0x884D">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -5121,8 +5121,8 @@
<enum name="SHADING_LANGUAGE_VERSION" value="0x8B8C"/>
<enum name="CURRENT_PROGRAM" value="0x8B8D"/>
<enum name="POINT_SPRITE_COORD_ORIGIN" count="1" value="0x8CA0">
- <size name="PointParameterfvEXT"/>
- <size name="PointParameterivNV"/>
+ <size name="PointParameterfvEXT" mode="get"/>
+ <size name="PointParameterivNV" mode="get"/>
</enum>
<enum name="LOWER_LEFT" value="0x8CA1"/>
<enum name="UPPER_LEFT" value="0x8CA2"/>
@@ -6226,16 +6226,16 @@
<category name="GL_ARB_point_parameters" number="14">
<enum name="POINT_SIZE_MIN_ARB" count="1" value="0x8126">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<enum name="POINT_SIZE_MAX_ARB" count="1" value="0x8127">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<enum name="POINT_FADE_THRESHOLD_SIZE_ARB" count="1" value="0x8128">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<enum name="POINT_DISTANCE_ATTENUATION_ARB" count="3" value="0x8129">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<function name="PointParameterfARB" alias="PointParameterfEXT">
@@ -6541,8 +6541,8 @@
<size name="GetTexLevelParameteriv" mode="get"/>
</enum>
<enum name="DEPTH_TEXTURE_MODE_ARB" count="1" value="0x884B">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -6550,14 +6550,14 @@
<category name="GL_ARB_shadow" number="23">
<enum name="TEXTURE_COMPARE_MODE_ARB" count="1" value="0x884C">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_COMPARE_FUNC_ARB" count="1" value="0x884D">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -6566,8 +6566,8 @@
<category name="GL_ARB_shadow_ambient" number="24">
<enum name="TEXTURE_COMPARE_FAIL_VALUE_ARB" count="1" value="0x80BF">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -7865,8 +7865,8 @@
<size name="Get" mode="get"/>
</enum>
<enum name="COORD_REPLACE_ARB" count="1" value="0x8862">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
@@ -8317,20 +8317,20 @@
<category name="GL_EXT_convolution" number="12">
<enum name="CONVOLUTION_BORDER_MODE_EXT" count="1" value="0x8013">
- <size name="ConvolutionParameterfv"/>
- <size name="ConvolutionParameteriv"/>
+ <size name="ConvolutionParameterfv" mode="get"/>
+ <size name="ConvolutionParameteriv" mode="get"/>
<size name="GetConvolutionParameterfv" mode="get"/>
<size name="GetConvolutionParameteriv" mode="get"/>
</enum>
<enum name="CONVOLUTION_FILTER_SCALE_EXT" count="4" value="0x8014">
- <size name="ConvolutionParameterfv"/>
- <size name="ConvolutionParameteriv"/>
+ <size name="ConvolutionParameterfv" mode="get"/>
+ <size name="ConvolutionParameteriv" mode="get"/>
<size name="GetConvolutionParameterfv" mode="get"/>
<size name="GetConvolutionParameteriv" mode="get"/>
</enum>
<enum name="CONVOLUTION_FILTER_BIAS_EXT" count="4" value="0x8015">
- <size name="ConvolutionParameterfv"/>
- <size name="ConvolutionParameteriv"/>
+ <size name="ConvolutionParameterfv" mode="get"/>
+ <size name="ConvolutionParameteriv" mode="get"/>
<size name="GetConvolutionParameterfv" mode="get"/>
<size name="GetConvolutionParameteriv" mode="get"/>
</enum>
@@ -8840,8 +8840,8 @@
<category name="GL_SGIS_generate_mipmap" number="32">
<enum name="GENERATE_MIPMAP_SGIS" count="1" value="0x8191">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -8851,26 +8851,26 @@
<category name="GL_SGIX_clipmap" number="33">
<enum name="LINEAR_CLIPMAP_LINEAR_SGIX" value="0x8170"/>
<enum name="TEXTURE_CLIPMAP_CENTER_SGIX" count="2" value="0x8171">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_CLIPMAP_FRAME_SGIX" count="1" value="0x8172">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_CLIPMAP_OFFSET_SGIX" count="2" value="0x8173">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX" count="3" value="0x8174">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -8885,14 +8885,14 @@
<category name="GL_SGIX_shadow" number="34">
<enum name="TEXTURE_COMPARE_SGIX" count="1" value="0x819A">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_COMPARE_OPERATOR_SGIX" count="1" value="0x819B">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -8969,16 +8969,16 @@
<category name="GL_EXT_point_parameters" number="54">
<enum name="POINT_SIZE_MIN_EXT" count="1" value="0x8126">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<enum name="POINT_SIZE_MAX_EXT" count="1" value="0x8127">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<enum name="POINT_FADE_THRESHOLD_SIZE_EXT" count="1" value="0x8128">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<enum name="POINT_DISTANCE_ATTENUATION_EXT" count="3" value="0x8129">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<function name="PointParameterfEXT" offset="assign">
@@ -9029,14 +9029,14 @@
<category name="GL_SGIX_texture_scale_bias" number="56">
<enum name="POST_TEXTURE_FILTER_BIAS_SGIX" count="4" value="0x8179">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="POST_TEXTURE_FILTER_SCALE_SGIX" count="4" value="0x817A">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -9096,8 +9096,8 @@
<category name="GL_SGIX_fog_offset" number="65">
<enum name="FOG_OFFSET_SGIX" value="0x8198"/>
<enum name="FOG_OFFSET_VALUE_SGIX" count="1" value="0x8199">
- <size name="Fogfv"/>
- <size name="Fogiv"/>
+ <size name="Fogfv" mode="get"/>
+ <size name="Fogiv" mode="get"/>
</enum>
</category>
@@ -9144,8 +9144,8 @@
<enum name="CONSTANT_BORDER_HP" value="0x8151"/>
<enum name="REPLICATE_BORDER_HP" value="0x8153"/>
<enum name="CONVOLUTION_BORDER_COLOR_HP" count="4" value="0x8154">
- <size name="ConvolutionParameterfv"/>
- <size name="ConvolutionParameteriv"/>
+ <size name="ConvolutionParameterfv" mode="get"/>
+ <size name="ConvolutionParameteriv" mode="get"/>
<size name="GetConvolutionParameterfv" mode="get"/>
<size name="GetConvolutionParameteriv" mode="get"/>
</enum>
@@ -9311,20 +9311,20 @@
<category name="GL_SGIX_texture_lod_bias" number="84">
<enum name="TEXTURE_LOD_BIAS_S_SGIX" count="1" value="0x818E">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_LOD_BIAS_T_SGIX" count="1" value="0x818F">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_LOD_BIAS_R_SGIX" count="1" value="0x8190">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -9339,8 +9339,8 @@
<category name="GL_SGIX_shadow_ambient" number="90">
<enum name="SHADOW_AMBIENT_SGIX" count="1" value="0x80BF">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -9684,8 +9684,8 @@
<category name="GL_EXT_separate_specular_color" number="144">
<enum name="LIGHT_MODEL_COLOR_CONTROL_EXT" count="1" value="0x81F8">
- <size name="LightModelfv"/>
- <size name="LightModeliv"/>
+ <size name="LightModelfv" mode="get"/>
+ <size name="LightModeliv" mode="get"/>
</enum>
<enum name="SINGLE_COLOR_EXT" value="0x81F9"/>
<enum name="SEPARATE_SPECULAR_COLOR_EXT" value="0x81FA"/>
@@ -10458,8 +10458,8 @@
<category name="GL_EXT_texture_lod_bias" number="186">
<enum name="TEXTURE_LOD_BIAS_EXT" count="1" value="0x8501">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -10467,8 +10467,8 @@
<category name="GL_EXT_texture_filter_anisotropic" number="187">
<enum name="TEXTURE_MAX_ANISOTROPY_EXT" count="1" value="0x84FE">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -10626,8 +10626,8 @@
<category name="GL_NV_fog_distance" number="192">
<enum name="FOG_DISTANCE_MODE_NV" count="1" value="0x855A">
- <size name="Fogfv"/>
- <size name="Fogiv"/>
+ <size name="Fogfv" mode="get"/>
+ <size name="Fogiv" mode="get"/>
<size name="Get" mode="get"/>
</enum>
<enum name="EYE_RADIAL_NV" value="0x855B"/>
@@ -10641,26 +10641,26 @@
<category name="GL_NV_texture_env_combine4" number="195">
<enum name="COMBINE4" value="0x8503"/>
<enum name="SOURCE3_RGB_NV" count="1" value="0x8583">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="SOURCE3_ALPHA_NV" count="1" value="0x858B">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="OPERAND3_RGB_NV" count="1" value="0x8593">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="OPERAND3_ALPHA_NV" count="1" value="0x859B">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
@@ -11681,20 +11681,20 @@
<category name="GL_SGIX_texture_coordinate_clamp" number="235">
<enum name="TEXTURE_MAX_CLAMP_S_SGIX" count="1" value="0x8369">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_MAX_CLAMP_T_SGIX" count="1" value="0x836A">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
<enum name="TEXTURE_MAX_CLAMP_R_SGIX" count="1" value="0x836B">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -11733,8 +11733,8 @@
<enum name="DU8DV8_ATI" value="0x877A"/>
<enum name="BUMP_ENVMAP_ATI" value="0x877B"/>
<enum name="BUMP_TARGET_ATI" count="1" value="0x877C">
- <size name="TexEnviv"/>
- <size name="TexEnvfv"/>
+ <size name="TexEnviv" mode="get"/>
+ <size name="TexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
</enum>
@@ -11927,30 +11927,30 @@
added for this extension. -->
<enum name="POINT_SIZE_MIN_EXT" count="1" value="0x8126">
- <size name="PointParameterivNV"/>
+ <size name="PointParameterivNV" mode="get"/>
</enum>
<enum name="POINT_SIZE_MAX_EXT" count="1" value="0x8127">
- <size name="PointParameterivNV"/>
+ <size name="PointParameterivNV" mode="get"/>
</enum>
<enum name="POINT_FADE_THRESHOLD_SIZE_EXT" count="1" value="0x8128">
- <size name="PointParameterivNV"/>
+ <size name="PointParameterivNV" mode="get"/>
</enum>
<enum name="POINT_DISTANCE_ATTENUATION_EXT" count="3" value="0x8129">
- <size name="PointParameterivNV"/>
+ <size name="PointParameterivNV" mode="get"/>
</enum>
<enum name="POINT_SPRITE_NV" count="1" value="0x8861">
<size name="Get" mode="get"/>
</enum>
<enum name="COORD_REPLACE_NV" count="1" value="0x8862">
- <size name="TexEnvfv"/>
- <size name="TexEnviv"/>
+ <size name="TexEnvfv" mode="get"/>
+ <size name="TexEnviv" mode="get"/>
<size name="GetTexEnvfv" mode="get"/>
<size name="GetTexEnviv" mode="get"/>
</enum>
<enum name="POINT_SPRITE_R_MODE_NV" count="1" value="0x8863">
- <size name="PointParameterfvEXT"/>
- <size name="PointParameterivNV"/>
+ <size name="PointParameterfvEXT" mode="get"/>
+ <size name="PointParameterivNV" mode="get"/>
<size name="Get" mode="get"/>
</enum>
@@ -12129,8 +12129,8 @@
<category name="GL_NV_texture_expand_normal" number="286">
<enum name="TEXTURE_UNSIGNED_REMAP_MODE_NV" count="1" value="0x888F">
- <size name="TexParameterfv"/>
- <size name="TexParameteriv"/>
+ <size name="TexParameterfv" mode="get"/>
+ <size name="TexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
</enum>
@@ -12284,22 +12284,22 @@
<category name="GL_APPLE_texture_range" number="367">
<enum name="TEXTURE_STORAGE_HINT_APPLE" count="1" value="0x85BC">
- <size name="TexParameteriv"/>
- <size name="TexParameterfv"/>
+ <size name="TexParameteriv" mode="get"/>
+ <size name="TexParameterfv" mode="get"/>
<size name="GetTexParameteriv" mode="get"/>
<size name="GetTexParameterfv" mode="get"/>
</enum>
<enum name="STORAGE_PRIVATE_APPLE" count="1" value="0x85BD">
- <size name="TexParameteriv"/>
- <size name="TexParameterfv"/>
+ <size name="TexParameteriv" mode="get"/>
+ <size name="TexParameterfv" mode="get"/>
</enum>
<enum name="STORAGE_CACHED_APPLE" count="1" value="0x85BE">
- <size name="TexParameteriv"/>
- <size name="TexParameterfv"/>
+ <size name="TexParameteriv" mode="get"/>
+ <size name="TexParameterfv" mode="get"/>
</enum>
<enum name="STORAGE_SHARED_APPLE" count="1" value="0x85BF">
- <size name="TexParameteriv"/>
- <size name="TexParameterfv"/>
+ <size name="TexParameteriv" mode="get"/>
+ <size name="TexParameterfv" mode="get"/>
</enum>
<enum name="TEXTURE_RANGE_LENGTH_APPLE" count="1" value="0x85B7">
<size name="GetTexParameteriv" mode="get"/>
@@ -12442,16 +12442,16 @@
<category name="GL_SGIS_point_parameters">
<enum name="POINT_SIZE_MIN_SGIS" count="1" value="0x8126">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<enum name="POINT_SIZE_MAX_SGIS" count="1" value="0x8127">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<enum name="POINT_FADE_THRESHOLD_SIZE_SGIS" count="1" value="0x8128">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<enum name="POINT_DISTANCE_ATTENUATION_SGIS" count="3" value="0x8129">
- <size name="PointParameterfvEXT"/>
+ <size name="PointParameterfvEXT" mode="get"/>
</enum>
<function name="PointParameterfSGIS" alias="PointParameterfEXT" static_dispatch="false">
diff --git a/mesalib/src/mapi/glapi/glapi.h b/mesalib/src/mapi/glapi/glapi.h
index 1d4ac4674..a99317ad0 100644
--- a/mesalib/src/mapi/glapi/glapi.h
+++ b/mesalib/src/mapi/glapi/glapi.h
@@ -39,12 +39,9 @@
* This module is intended to be non-Mesa-specific so it can be used
* with the X/DRI libGL also.
*/
-
-
#ifndef _GLAPI_H
#define _GLAPI_H
-
#ifdef _GLAPI_NO_EXPORTS
# define _GLAPI_EXPORT
#else /* _GLAPI_NO_EXPORTS */
@@ -72,7 +69,7 @@
#define _glapi_Context _mglapi_Context
#endif
-#include "glapi/glthread.h"
+#include "glthread.h"
typedef void (*_glapi_proc)(void);
struct _glapi_table;
@@ -94,8 +91,14 @@ _GLAPI_EXPORT extern const void *_glapi_Context;
#else
-_GLAPI_EXPORT extern struct _glapi_table *_glapi_Dispatch;
-_GLAPI_EXPORT extern void *_glapi_Context;
+#ifdef INSERVER
+#define SERVEXTERN _declspec(dllimport)
+#else
+#define SERVEXTERN _declspec(dllexport)
+#endif
+
+SERVEXTERN struct _glapi_table *_glapi_Dispatch;
+SERVEXTERN void *_glapi_Context;
# ifdef THREADS
@@ -119,31 +122,31 @@ void
_glapi_destroy_multithread(void);
-_GLAPI_EXPORT void
+SERVEXTERN void
_glapi_check_multithread(void);
-_GLAPI_EXPORT void
+SERVEXTERN void
_glapi_set_context(void *context);
-_GLAPI_EXPORT void *
+SERVEXTERN void *
_glapi_get_context(void);
-_GLAPI_EXPORT void
+SERVEXTERN void
_glapi_set_dispatch(struct _glapi_table *dispatch);
-_GLAPI_EXPORT struct _glapi_table *
+SERVEXTERN struct _glapi_table *
_glapi_get_dispatch(void);
-_GLAPI_EXPORT unsigned int
+SERVEXTERN unsigned int
_glapi_get_dispatch_table_size(void);
-_GLAPI_EXPORT int
+SERVEXTERN int
_glapi_add_dispatch( const char * const * function_names,
const char * parameter_signature );
@@ -166,7 +169,7 @@ _glthread_GetID(void);
/*
* These stubs are kept so that the old DRI drivers still load.
*/
-_GLAPI_EXPORT void
+SERVEXTERN void
_glapi_noop_enable_warnings(unsigned char enable);
diff --git a/mesalib/src/mapi/glapi/glapi_getproc.c b/mesalib/src/mapi/glapi/glapi_getproc.c
index 21380ea41..d5c72f29b 100644
--- a/mesalib/src/mapi/glapi/glapi_getproc.c
+++ b/mesalib/src/mapi/glapi/glapi_getproc.c
@@ -369,6 +369,7 @@ set_entry_info( struct _glapi_function * entry, const char * signature, unsigned
* the parameter signature of a static function.
*/
+#ifndef INSERVER
int
_glapi_add_dispatch( const char * const * function_names,
const char * parameter_signature )
@@ -478,12 +479,12 @@ _glapi_add_dispatch( const char * const * function_names,
return offset;
}
-
+#endif
/**
* Return offset of entrypoint for named function within dispatch table.
*/
-GLint
+GLint _GLAPI_EXPORT
_glapi_get_proc_offset(const char *funcName)
{
GLint offset;
@@ -504,7 +505,7 @@ _glapi_get_proc_offset(const char *funcName)
* in the name of static functions, try generating a new API entrypoint on
* the fly with assembly language.
*/
-_glapi_proc
+_glapi_proc _GLAPI_EXPORT
_glapi_get_proc_address(const char *funcName)
{
_glapi_proc func;
@@ -545,7 +546,7 @@ _glapi_get_proc_address(const char *funcName)
* Return the name of the function at the given dispatch offset.
* This is only intended for debugging.
*/
-const char *
+const char * _GLAPI_EXPORT
_glapi_get_proc_name(GLuint offset)
{
const char * n;
@@ -571,7 +572,7 @@ _glapi_get_proc_name(GLuint offset)
* Return size of dispatch table struct as number of functions (or
* slots).
*/
-GLuint
+GLuint _GLAPI_EXPORT
_glapi_get_dispatch_table_size(void)
{
/*
diff --git a/mesalib/src/mapi/glapi/glapi_nop.c b/mesalib/src/mapi/glapi/glapi_nop.c
index 9b0929715..365a6e1c8 100644
--- a/mesalib/src/mapi/glapi/glapi_nop.c
+++ b/mesalib/src/mapi/glapi/glapi_nop.c
@@ -41,12 +41,12 @@
#include "glapi/glapi_priv.h"
-void
+void _GLAPI_EXPORT
_glapi_noop_enable_warnings(unsigned char enable)
{
}
-void
+void _GLAPI_EXPORT
_glapi_set_warning_func(_glapi_proc func)
{
}
diff --git a/mesalib/src/mapi/glapi/glthread.c b/mesalib/src/mapi/glapi/glthread.c
index 00915380f..239090ecf 100644
--- a/mesalib/src/mapi/glapi/glthread.c
+++ b/mesalib/src/mapi/glapi/glthread.c
@@ -1,6 +1,6 @@
#include "glapi/glapi.h"
-unsigned long
+unsigned long _GLAPI_EXPORT
_glthread_GetID(void)
{
return u_thread_self();
diff --git a/mesalib/src/mesa/Makefile b/mesalib/src/mesa/Makefile
index 10d73f000..2eb8a18c9 100644
--- a/mesalib/src/mesa/Makefile
+++ b/mesalib/src/mesa/Makefile
@@ -1,230 +1,230 @@
-# src/mesa/Makefile
-
-TOP = ../..
-include $(TOP)/configs/current
-
-MESA_LIBS := libmesa.a libmesagallium.a
-DEPENDS := depend
-
-MESA_OBJ_DIR := .
-DRICORE_OBJ_DIR := objs-dricore
-
-include sources.mak
-
-# adjust object dirs
-MESA_OBJECTS := $(addprefix $(MESA_OBJ_DIR)/, $(MESA_OBJECTS))
-MESA_GALLIUM_OBJECTS := $(addprefix $(MESA_OBJ_DIR)/, $(MESA_GALLIUM_OBJECTS))
-
-DRICORE_OBJECTS := $(addprefix $(DRICORE_OBJ_DIR)/, $(MESA_OBJECTS))
-
-# define preprocessor flags
-MESA_CPPFLAGS := $(API_DEFINES) $(DEFINES)
-
-# append include dirs
-MESA_CPPFLAGS += $(INCLUDE_DIRS)
-
-DRICORE_CPPFLAGS = $(MESA_CPPFLAGS)
-
-# tidy compiler flags
-CFLAGS := $(filter-out $(DEFINES), $(CFLAGS))
-CXXFLAGS := $(filter-out $(DEFINES), $(CXXFLAGS))
-
-# LLVM is needed for the state tracker
-MESA_CFLAGS := $(LLVM_CFLAGS) $(CFLAGS)
-DRICORE_CFLAGS := $(LLVM_CFLAGS) $(DRI_CFLAGS)
-
-MESA_CXXFLAGS := $(LLVM_CFLAGS) $(CXXFLAGS)
-DRICORE_CXXFLAGS := $(LLVM_CFLAGS) $(DRI_CXXFLAGS)
-
-define mesa-cc-c
- @mkdir -p $(dir $@)
- $(CC) -c -o $@ $< $($(1)_CPPFLAGS) $($(1)_CFLAGS)
-endef
-
-define mesa-cxx-c
- @mkdir -p $(dir $@)
- $(CXX) -c -o $@ $< $($(1)_CPPFLAGS) $($(1)_CFLAGS) $($(1)_CXXFLAGS)
-endef
-
-$(MESA_OBJ_DIR)/%.o: %.c
- $(call mesa-cc-c,MESA)
-
-$(MESA_OBJ_DIR)/%.o: %.cpp
- $(call mesa-cxx-c,MESA)
-
-$(MESA_OBJ_DIR)/%.o: %.S
- $(call mesa-cc-c,MESA)
-
-$(DRICORE_OBJ_DIR)/%.o: %.c
- $(call mesa-cc-c,DRICORE)
-
-$(DRICORE_OBJ_DIR)/%.o: %.cpp
- $(call mesa-cxx-c,DRICORE)
-
-$(DRICORE_OBJ_DIR)/%.o: %.S
- $(call mesa-cc-c,DRICORE)
-
-# Default: build dependencies, then asm_subdirs, GLSL built-in lib,
-# then convenience libs (.a) and finally the device drivers:
-default: $(DEPENDS) asm_subdirs $(MESA_LIBS) $(DRICORE_LIBS) driver_subdirs
-
-main/api_exec_es1.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py
- $(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES1.1 > $@
-
-main/api_exec_es2.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py
- $(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES2.0 > $@
-
-program/program_parse.tab.c program/program_parse.tab.h: program/program_parse.y
- bison -v -d --output=program/program_parse.tab.c $<
-
-program/lex.yy.c: program/program_lexer.l
- flex --never-interactive --outfile=$@ $<
-
-######################################################################
-# Helper libraries used by many drivers:
-
-# Make archive of core mesa object files
-libmesa.a: $(MESA_OBJECTS) $(GLSL_LIBS)
- @ $(MKLIB) -o mesa -static $(MESA_OBJECTS) $(GLSL_LIBS)
-
-# Shared dricore library for classic DRI drivers
-$(TOP)/$(LIB_DIR)/libdricore.so: $(DRICORE_OBJECTS) $(DRICORE_GLSL_LIBS)
- @$(MKLIB) -o $@ -linker '$(CXX)' -ldflags '$(LDFLAGS)' \
- -cplusplus -noprefix \
- -install $(TOP)/$(LIB_DIR) -id $(DRI_DRIVER_INSTALL_DIR)/$@.dylib \
- $(DRICORE_LIB_DEPS) $(DRICORE_OBJECTS)
-
-# Make archive of subset of core mesa object files for gallium
-libmesagallium.a: $(MESA_GALLIUM_OBJECTS) $(GLSL_LIBS)
- @ $(MKLIB) -o mesagallium -static $(MESA_GALLIUM_OBJECTS) $(GLSL_LIBS)
-
-######################################################################
-# Device drivers
-driver_subdirs: $(MESA_LIBS) $(DRICORE_LIBS)
- @ (cd drivers && $(MAKE))
-
-
-######################################################################
-# Assembly subdirs
-asm_subdirs:
- @ if echo "$(ASM_FLAGS)" | grep -q USE_X86_ASM ; then \
- (cd x86 && $(MAKE)) || exit 1 ; \
- fi
- @ if echo "$(ASM_FLAGS)" | grep -q USE_X86_64_ASM ; then \
- (cd x86 && $(MAKE)) || exit 1 ; \
- (cd x86-64 && $(MAKE)) || exit 1 ; \
- fi
-
-
-######################################################################
-# Dependency generation
-
-depend: $(ALL_SOURCES)
- @ echo "running $(MKDEP)"
- @ touch depend
- @$(MKDEP) $(MKDEP_OPTIONS) -p$(MESA_OBJ_DIR)/ $(MESA_CPPFLAGS) \
- $(ALL_SOURCES) > /dev/null 2>/dev/null
-
-######################################################################
-# Installation rules
-
-# this isn't fleshed out yet but is probably the way to go in the future
-new_install:
- (cd drivers && $(MAKE) install)
-
-ifneq (,$(DRICORE_LIBS))
-DRICORE_INSTALL_TARGET = install-dricore
-endif
-
-# XXX replace this with new_install above someday
-install: default $(DRICORE_INSTALL_TARGET)
- @for driver in $(DRIVER_DIRS) ; do \
- case "$$driver" in \
- osmesa) if [ "$(DRIVER_DIRS)" = osmesa ]; then \
- $(MAKE) install-headers install-osmesa || exit 1 ; \
- else \
- $(MAKE) install-osmesa || exit 1 ; \
- fi ;; \
- dri) $(MAKE) install-libgl install-dri || exit 1 ;; \
- *) $(MAKE) install-libgl || exit 1 ;; \
- esac ; \
- done
-
-pcedit = \
- -e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \
- -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \
- -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \
- -e 's,@VERSION@,$(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY),' \
-
-
-gl_pcedit = sed \
- $(pcedit) \
- -e 's,@GL_PC_REQ_PRIV@,$(GL_PC_REQ_PRIV),' \
- -e 's,@GL_PC_LIB_PRIV@,$(GL_PC_LIB_PRIV),' \
- -e 's,@GL_PC_CFLAGS@,$(GL_PC_CFLAGS),' \
- -e 's,@GLX_TLS@,$(GLX_TLS),' \
- -e 's,@GL_LIB@,$(GL_LIB),'
-
-gl.pc: gl.pc.in
- $(gl_pcedit) $< > $@
-
-osmesa_pcedit = sed \
- $(pcedit) \
- -e 's,@OSMESA_LIB@,$(OSMESA_LIB),' \
- -e 's,@OSMESA_PC_REQ@,$(OSMESA_PC_REQ),' \
- -e 's,@OSMESA_PC_LIB_PRIV@,$(OSMESA_PC_LIB_PRIV),'
-
-osmesa.pc: osmesa.pc.in
- $(osmesa_pcedit) $< > $@
-
-install-headers:
- $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/GL
- $(INSTALL) -m 644 $(TOP)/include/GL/*.h \
- $(DESTDIR)$(INSTALL_INC_DIR)/GL
-
-install-libgl: default gl.pc install-headers
- $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)
- $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig
- $(MINSTALL) $(TOP)/$(LIB_DIR)/$(GL_LIB_GLOB) \
- $(DESTDIR)$(INSTALL_LIB_DIR)
- $(INSTALL) -m 644 gl.pc $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig
-
-install-osmesa: default osmesa.pc
- $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)
- $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig
- $(MINSTALL) $(TOP)/$(LIB_DIR)/$(OSMESA_LIB_GLOB) \
- $(DESTDIR)$(INSTALL_LIB_DIR)
- $(INSTALL) -m 644 osmesa.pc $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig
-
-install-dri: default
- cd drivers/dri && $(MAKE) install
-
-# We don't need MINSTALL here because we're not installing symbolic links
-install-dricore: default
- $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
- $(INSTALL) -m 755 $(DRICORE_LIBS) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
-
-
-# Emacs tags
-tags:
- etags `find . -name \*.[ch]` $(TOP)/include/GL/*.h
-
-clean-dricore:
- -rm -f libdricore.so
- -rm -f $(DRICORE_LIBS)
- -rm -rf $(DRICORE_OBJ_DIR)
-
-clean: clean-dricore
- -rm -f */*.o
- -rm -f */*/*.o
- -rm -f depend depend.bak libmesa.a libmesagallium.a
- -rm -f drivers/*/*.o
- -rm -f *.pc
- -@cd drivers/dri && $(MAKE) clean
- -@cd drivers/x11 && $(MAKE) clean
- -@cd drivers/osmesa && $(MAKE) clean
- -@cd x86 && $(MAKE) clean
- -@cd x86-64 && $(MAKE) clean
-
-
--include $(DEPENDS)
+# src/mesa/Makefile
+
+TOP = ../..
+include $(TOP)/configs/current
+
+MESA_LIBS := libmesa.a libmesagallium.a
+DEPENDS := depend
+
+MESA_OBJ_DIR := .
+DRICORE_OBJ_DIR := objs-dricore
+
+include sources.mak
+
+# adjust object dirs
+MESA_OBJECTS := $(addprefix $(MESA_OBJ_DIR)/, $(MESA_OBJECTS))
+MESA_GALLIUM_OBJECTS := $(addprefix $(MESA_OBJ_DIR)/, $(MESA_GALLIUM_OBJECTS))
+
+DRICORE_OBJECTS := $(addprefix $(DRICORE_OBJ_DIR)/, $(MESA_OBJECTS))
+
+# define preprocessor flags
+MESA_CPPFLAGS := $(API_DEFINES) $(DEFINES)
+
+# append include dirs
+MESA_CPPFLAGS += $(INCLUDE_DIRS)
+
+DRICORE_CPPFLAGS = $(MESA_CPPFLAGS)
+
+# tidy compiler flags
+CFLAGS := $(filter-out $(DEFINES), $(CFLAGS))
+CXXFLAGS := $(filter-out $(DEFINES), $(CXXFLAGS))
+
+# LLVM is needed for the state tracker
+MESA_CFLAGS := $(LLVM_CFLAGS) $(CFLAGS)
+DRICORE_CFLAGS := $(LLVM_CFLAGS) $(DRI_CFLAGS)
+
+MESA_CXXFLAGS := $(LLVM_CFLAGS) $(CXXFLAGS)
+DRICORE_CXXFLAGS := $(LLVM_CFLAGS) $(DRI_CXXFLAGS)
+
+define mesa-cc-c
+ @mkdir -p $(dir $@)
+ $(CC) -c -o $@ $< $($(1)_CPPFLAGS) $($(1)_CFLAGS)
+endef
+
+define mesa-cxx-c
+ @mkdir -p $(dir $@)
+ $(CXX) -c -o $@ $< $($(1)_CPPFLAGS) $($(1)_CFLAGS) $($(1)_CXXFLAGS)
+endef
+
+$(MESA_OBJ_DIR)/%.o: %.c
+ $(call mesa-cc-c,MESA)
+
+$(MESA_OBJ_DIR)/%.o: %.cpp
+ $(call mesa-cxx-c,MESA)
+
+$(MESA_OBJ_DIR)/%.o: %.S
+ $(call mesa-cc-c,MESA)
+
+$(DRICORE_OBJ_DIR)/%.o: %.c
+ $(call mesa-cc-c,DRICORE)
+
+$(DRICORE_OBJ_DIR)/%.o: %.cpp
+ $(call mesa-cxx-c,DRICORE)
+
+$(DRICORE_OBJ_DIR)/%.o: %.S
+ $(call mesa-cc-c,DRICORE)
+
+# Default: build dependencies, then asm_subdirs, GLSL built-in lib,
+# then convenience libs (.a) and finally the device drivers:
+default: $(DEPENDS) asm_subdirs $(MESA_LIBS) $(DRICORE_LIBS) driver_subdirs
+
+main/api_exec_es1.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py
+ $(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES1.1 > $@
+
+main/api_exec_es2.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py
+ $(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES2.0 > $@
+
+program/program_parse.tab.c program/program_parse.tab.h: program/program_parse.y
+ bison -v -d --output=program/program_parse.tab.c $<
+
+program/lex.yy.c: program/program_lexer.l
+ flex --never-interactive --outfile=$@ $<
+
+######################################################################
+# Helper libraries used by many drivers:
+
+# Make archive of core mesa object files
+libmesa.a: $(MESA_OBJECTS) $(GLSL_LIBS)
+ @ $(MKLIB) -o mesa -static $(MESA_OBJECTS) $(GLSL_LIBS)
+
+# Shared dricore library for classic DRI drivers
+$(TOP)/$(LIB_DIR)/libdricore.so: $(DRICORE_OBJECTS) $(DRICORE_GLSL_LIBS)
+ @$(MKLIB) -o $@ -linker '$(CXX)' -ldflags '$(LDFLAGS)' \
+ -cplusplus -noprefix \
+ -install $(TOP)/$(LIB_DIR) -id $(DRI_DRIVER_INSTALL_DIR)/$@.dylib \
+ $(DRICORE_LIB_DEPS) $(DRICORE_OBJECTS)
+
+# Make archive of subset of core mesa object files for gallium
+libmesagallium.a: $(MESA_GALLIUM_OBJECTS) $(GLSL_LIBS)
+ @ $(MKLIB) -o mesagallium -static $(MESA_GALLIUM_OBJECTS) $(GLSL_LIBS)
+
+######################################################################
+# Device drivers
+driver_subdirs: $(MESA_LIBS) $(DRICORE_LIBS)
+ @ (cd drivers && $(MAKE))
+
+
+######################################################################
+# Assembly subdirs
+asm_subdirs:
+ @ if echo "$(ASM_FLAGS)" | grep -q USE_X86_ASM ; then \
+ (cd x86 && $(MAKE)) || exit 1 ; \
+ fi
+ @ if echo "$(ASM_FLAGS)" | grep -q USE_X86_64_ASM ; then \
+ (cd x86 && $(MAKE)) || exit 1 ; \
+ (cd x86-64 && $(MAKE)) || exit 1 ; \
+ fi
+
+
+######################################################################
+# Dependency generation
+
+depend: $(ALL_SOURCES)
+ @ echo "running $(MKDEP)"
+ @ touch depend
+ @$(MKDEP) $(MKDEP_OPTIONS) -p$(MESA_OBJ_DIR)/ $(MESA_CPPFLAGS) \
+ $(ALL_SOURCES) > /dev/null 2>/dev/null
+
+######################################################################
+# Installation rules
+
+# this isn't fleshed out yet but is probably the way to go in the future
+new_install:
+ (cd drivers && $(MAKE) install)
+
+ifneq (,$(DRICORE_LIBS))
+DRICORE_INSTALL_TARGET = install-dricore
+endif
+
+# XXX replace this with new_install above someday
+install: default $(DRICORE_INSTALL_TARGET)
+ @for driver in $(DRIVER_DIRS) ; do \
+ case "$$driver" in \
+ osmesa) if [ "$(DRIVER_DIRS)" = osmesa ]; then \
+ $(MAKE) install-headers install-osmesa || exit 1 ; \
+ else \
+ $(MAKE) install-osmesa || exit 1 ; \
+ fi ;; \
+ dri) $(MAKE) install-libgl install-dri || exit 1 ;; \
+ *) $(MAKE) install-libgl || exit 1 ;; \
+ esac ; \
+ done
+
+pcedit = \
+ -e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \
+ -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \
+ -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \
+ -e 's,@VERSION@,$(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY),' \
+
+
+gl_pcedit = sed \
+ $(pcedit) \
+ -e 's,@GL_PC_REQ_PRIV@,$(GL_PC_REQ_PRIV),' \
+ -e 's,@GL_PC_LIB_PRIV@,$(GL_PC_LIB_PRIV),' \
+ -e 's,@GL_PC_CFLAGS@,$(GL_PC_CFLAGS),' \
+ -e 's,@GLX_TLS@,$(GLX_TLS),' \
+ -e 's,@GL_LIB@,$(GL_LIB),'
+
+gl.pc: gl.pc.in
+ $(gl_pcedit) $< > $@
+
+osmesa_pcedit = sed \
+ $(pcedit) \
+ -e 's,@OSMESA_LIB@,$(OSMESA_LIB),' \
+ -e 's,@OSMESA_PC_REQ@,$(OSMESA_PC_REQ),' \
+ -e 's,@OSMESA_PC_LIB_PRIV@,$(OSMESA_PC_LIB_PRIV),'
+
+osmesa.pc: osmesa.pc.in
+ $(osmesa_pcedit) $< > $@
+
+install-headers:
+ $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/GL
+ $(INSTALL) -m 644 $(TOP)/include/GL/*.h \
+ $(DESTDIR)$(INSTALL_INC_DIR)/GL
+
+install-libgl: default gl.pc install-headers
+ $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)
+ $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig
+ $(MINSTALL) $(TOP)/$(LIB_DIR)/$(GL_LIB_GLOB) \
+ $(DESTDIR)$(INSTALL_LIB_DIR)
+ $(INSTALL) -m 644 gl.pc $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig
+
+install-osmesa: default osmesa.pc
+ $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)
+ $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig
+ $(MINSTALL) $(TOP)/$(LIB_DIR)/$(OSMESA_LIB_GLOB) \
+ $(DESTDIR)$(INSTALL_LIB_DIR)
+ $(INSTALL) -m 644 osmesa.pc $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig
+
+install-dri: default
+ cd drivers/dri && $(MAKE) install
+
+# We don't need MINSTALL here because we're not installing symbolic links
+install-dricore: default
+ $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
+ $(INSTALL) -m 755 $(DRICORE_LIBS) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
+
+
+# Emacs tags
+tags:
+ etags `find . -name \*.[ch]` $(TOP)/include/GL/*.h
+
+clean-dricore:
+ -rm -f libdricore.so
+ -rm -f $(DRICORE_LIBS)
+ -rm -rf $(DRICORE_OBJ_DIR)
+
+clean: clean-dricore
+ -rm -f */*.o
+ -rm -f */*/*.o
+ -rm -f depend depend.bak libmesa.a libmesagallium.a
+ -rm -f drivers/*/*.o
+ -rm -f *.pc
+ -@cd drivers/dri && $(MAKE) clean
+ -@cd drivers/x11 && $(MAKE) clean
+ -@cd drivers/osmesa && $(MAKE) clean
+ -@cd x86 && $(MAKE) clean
+ -@cd x86-64 && $(MAKE) clean
+
+
+-include $(DEPENDS)
diff --git a/mesalib/src/mesa/SConscript b/mesalib/src/mesa/SConscript
index acbf86ebd..55a28d746 100644
--- a/mesalib/src/mesa/SConscript
+++ b/mesalib/src/mesa/SConscript
@@ -1,397 +1,397 @@
-#######################################################################
-# SConscript for Mesa
-
-
-Import('*')
-
-env = env.Clone()
-
-env.Append(CPPPATH = [
- '#/src/mapi',
- '#/src/glsl',
- '#/src/mesa',
-])
-
-env.Append(CPPDEFINES = [
- 'FEATURE_GL=1',
-])
-
-if env['platform'] == 'windows':
- env.Append(CPPDEFINES = [
- '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
- 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
- ])
- if not env['gles']:
- # prevent _glapi_* from being declared __declspec(dllimport)
- env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
-else:
- env.Append(CPPDEFINES = [
- 'IN_DRI_DRIVER', # enable the remap table (for DRI drivers)
- ])
-
-#
-# Source files
-#
-
-main_sources = [
- 'main/api_arrayelt.c',
- 'main/api_exec.c',
- 'main/api_loopback.c',
- 'main/api_noop.c',
- 'main/api_validate.c',
- 'main/accum.c',
- 'main/arbprogram.c',
- 'main/atifragshader.c',
- 'main/attrib.c',
- 'main/arrayobj.c',
- 'main/blend.c',
- 'main/bufferobj.c',
- 'main/buffers.c',
- 'main/clear.c',
- 'main/clip.c',
- 'main/colortab.c',
- 'main/condrender.c',
- 'main/context.c',
- 'main/convolve.c',
- 'main/cpuinfo.c',
- 'main/debug.c',
- 'main/depth.c',
- 'main/depthstencil.c',
- 'main/dlist.c',
- 'main/dlopen.c',
- 'main/drawpix.c',
- 'main/drawtex.c',
- 'main/enable.c',
- 'main/enums.c',
- 'main/eval.c',
- 'main/execmem.c',
- 'main/extensions.c',
- 'main/fbobject.c',
- 'main/feedback.c',
- 'main/ffvertex_prog.c',
- 'main/fog.c',
- 'main/formats.c',
- 'main/framebuffer.c',
- 'main/get.c',
- 'main/getstring.c',
- 'main/hash.c',
- 'main/hint.c',
- 'main/histogram.c',
- 'main/image.c',
- 'main/imports.c',
- 'main/light.c',
- 'main/lines.c',
- 'main/matrix.c',
- 'main/mipmap.c',
- 'main/mm.c',
- 'main/multisample.c',
- 'main/nvprogram.c',
- 'main/pack.c',
- 'main/pbo.c',
- 'main/pixel.c',
- 'main/pixelstore.c',
- 'main/pixeltransfer.c',
- 'main/points.c',
- 'main/polygon.c',
- 'main/querymatrix.c',
- 'main/queryobj.c',
- 'main/rastpos.c',
- 'main/readpix.c',
- 'main/remap.c',
- 'main/renderbuffer.c',
- 'main/scissor.c',
- 'main/shaderapi.c',
- 'main/shaderobj.c',
- 'main/shared.c',
- 'main/state.c',
- 'main/stencil.c',
- 'main/syncobj.c',
- 'main/texcompress.c',
- 'main/texcompress_rgtc.c',
- 'main/texcompress_s3tc.c',
- 'main/texcompress_fxt1.c',
- 'main/texenv.c',
- 'main/texenvprogram.c',
- 'main/texfetch.c',
- 'main/texformat.c',
- 'main/texgen.c',
- 'main/texgetimage.c',
- 'main/teximage.c',
- 'main/texobj.c',
- 'main/texpal.c',
- 'main/texparam.c',
- 'main/texrender.c',
- 'main/texstate.c',
- 'main/texstore.c',
- 'main/transformfeedback.c',
- 'main/uniforms.c',
- 'main/varray.c',
- 'main/version.c',
- 'main/viewport.c',
- 'main/vtxfmt.c',
-]
-
-math_sources = [
- 'math/m_debug_clip.c',
- 'math/m_debug_norm.c',
- 'math/m_debug_xform.c',
- 'math/m_eval.c',
- 'math/m_matrix.c',
- 'math/m_translate.c',
- 'math/m_vector.c',
- 'math/m_xform.c',
-]
-
-vbo_sources = [
- 'vbo/vbo_context.c',
- 'vbo/vbo_exec.c',
- 'vbo/vbo_exec_api.c',
- 'vbo/vbo_exec_array.c',
- 'vbo/vbo_exec_draw.c',
- 'vbo/vbo_exec_eval.c',
- 'vbo/vbo_rebase.c',
- 'vbo/vbo_split.c',
- 'vbo/vbo_split_copy.c',
- 'vbo/vbo_split_inplace.c',
- 'vbo/vbo_save.c',
- 'vbo/vbo_save_api.c',
- 'vbo/vbo_save_draw.c',
- 'vbo/vbo_save_loopback.c',
-]
-
-vf_sources = [
- 'vf/vf.c',
- 'vf/vf_generic.c',
- 'vf/vf_sse.c',
-]
-
-statetracker_sources = [
- 'state_tracker/st_atom.c',
- 'state_tracker/st_atom_blend.c',
- 'state_tracker/st_atom_clip.c',
- 'state_tracker/st_atom_constbuf.c',
- 'state_tracker/st_atom_depth.c',
- 'state_tracker/st_atom_framebuffer.c',
- 'state_tracker/st_atom_msaa.c',
- 'state_tracker/st_atom_pixeltransfer.c',
- 'state_tracker/st_atom_sampler.c',
- 'state_tracker/st_atom_scissor.c',
- 'state_tracker/st_atom_shader.c',
- 'state_tracker/st_atom_rasterizer.c',
- 'state_tracker/st_atom_stipple.c',
- 'state_tracker/st_atom_texture.c',
- 'state_tracker/st_atom_viewport.c',
- 'state_tracker/st_cb_accum.c',
- 'state_tracker/st_cb_bitmap.c',
- 'state_tracker/st_cb_blit.c',
- 'state_tracker/st_cb_bufferobjects.c',
- 'state_tracker/st_cb_clear.c',
- 'state_tracker/st_cb_condrender.c',
- 'state_tracker/st_cb_flush.c',
- 'state_tracker/st_cb_drawpixels.c',
- 'state_tracker/st_cb_drawtex.c',
- 'state_tracker/st_cb_eglimage.c',
- 'state_tracker/st_cb_fbo.c',
- 'state_tracker/st_cb_feedback.c',
- 'state_tracker/st_cb_program.c',
- 'state_tracker/st_cb_queryobj.c',
- 'state_tracker/st_cb_rasterpos.c',
- 'state_tracker/st_cb_readpixels.c',
- 'state_tracker/st_cb_strings.c',
- 'state_tracker/st_cb_texture.c',
- 'state_tracker/st_cb_viewport.c',
- 'state_tracker/st_cb_xformfb.c',
- 'state_tracker/st_context.c',
- 'state_tracker/st_debug.c',
- 'state_tracker/st_draw.c',
- 'state_tracker/st_draw_feedback.c',
- 'state_tracker/st_extensions.c',
- 'state_tracker/st_format.c',
- 'state_tracker/st_gen_mipmap.c',
- 'state_tracker/st_manager.c',
- 'state_tracker/st_mesa_to_tgsi.c',
- 'state_tracker/st_program.c',
- 'state_tracker/st_texture.c',
-]
-
-env.Append(YACCFLAGS = '-d')
-program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
-program_parse = env.CFile('program/program_parse.tab.c',
- 'program/program_parse.y')
-program_sources = [
- 'program/arbprogparse.c',
- 'program/hash_table.c',
- 'program/ir_to_mesa.cpp',
- 'program/nvfragparse.c',
- 'program/nvvertparse.c',
- 'program/program.c',
- 'program/program_parse_extra.c',
- 'program/prog_cache.c',
- 'program/prog_execute.c',
- 'program/prog_instruction.c',
- 'program/prog_noise.c',
- 'program/prog_optimize.c',
- 'program/prog_parameter.c',
- 'program/prog_parameter_layout.c',
- 'program/prog_print.c',
- 'program/prog_statevars.c',
- 'program/prog_uniform.c',
- 'program/programopt.c',
- 'program/sampler.cpp',
- 'program/symbol_table.c',
- program_lex,
- program_parse[0],
-]
-
-mesa_sources = (
- main_sources +
- math_sources +
- program_sources +
- vbo_sources +
- vf_sources +
- statetracker_sources
-)
-
-if env['gles']:
- from sys import executable as python_cmd
-
- env.Append(CPPDEFINES = ['FEATURE_ES1=1', 'FEATURE_ES2=1'])
-
- # generate GLES sources
- gles_sources = []
- gles_sources += env.CodeGenerate(
- target = 'main/api_exec_es1.c',
- script = 'main/es_generator.py',
- source = 'main/APIspec.xml',
- command = python_cmd + ' $SCRIPT -S $SOURCE -V GLES1.1 > $TARGET'
- )
- gles_sources += env.CodeGenerate(
- target = 'main/api_exec_es2.c',
- script = 'main/es_generator.py',
- source = 'main/APIspec.xml',
- command = python_cmd + ' $SCRIPT -S $SOURCE -V GLES2.0 > $TARGET'
- )
-
- # generate GLES headers
- GLAPI = '#src/mapi/glapi/'
- gles_headers = []
- gles_headers += env.CodeGenerate(
- target = 'es1api/main/glapidispatch.h',
- script = GLAPI + 'gen/gl_table.py',
- source = GLAPI + 'gen-es/es1_API.xml',
- command = python_cmd + ' $SCRIPT -c -m remap_table -f $SOURCE > $TARGET',
- )
- gles_headers += env.CodeGenerate(
- target = 'es1api/main/remap_helper.h',
- script = GLAPI + 'gen/remap_helper.py',
- source = GLAPI + 'gen-es/es1_API.xml',
- command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET',
- )
- gles_headers += env.CodeGenerate(
- target = 'es2api/main/glapidispatch.h',
- script = GLAPI + 'gen/gl_table.py',
- source = GLAPI + 'gen-es/es2_API.xml',
- command = python_cmd + ' $SCRIPT -c -m remap_table -f $SOURCE > $TARGET',
- )
- gles_headers += env.CodeGenerate(
- target = 'es2api/main/remap_helper.h',
- script = GLAPI + 'gen/remap_helper.py',
- source = GLAPI + 'gen-es/es2_API.xml',
- command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET',
- )
-
- env.Depends(gles_sources, gles_headers)
-
- # gles_sources #include gles_headers with full path
- env.Append(CPPPATH = [gles_headers[0].dir.up().up()])
-
- mesa_sources += gles_sources
-
-#
-# Assembly sources
-#
-if env['gcc'] and env['platform'] != 'windows':
- if env['machine'] == 'x86':
- env.Append(CPPDEFINES = [
- 'USE_X86_ASM',
- 'USE_MMX_ASM',
- 'USE_3DNOW_ASM',
- 'USE_SSE_ASM',
- ])
- mesa_sources += [
- 'x86/common_x86.c',
- 'x86/x86_xform.c',
- 'x86/3dnow.c',
- 'x86/sse.c',
- 'x86/common_x86_asm.S',
- 'x86/x86_xform2.S',
- 'x86/x86_xform3.S',
- 'x86/x86_xform4.S',
- 'x86/x86_cliptest.S',
- 'x86/mmx_blend.S',
- 'x86/3dnow_xform1.S',
- 'x86/3dnow_xform2.S',
- 'x86/3dnow_xform3.S',
- 'x86/3dnow_xform4.S',
- 'x86/3dnow_normal.S',
- 'x86/sse_xform1.S',
- 'x86/sse_xform2.S',
- 'x86/sse_xform3.S',
- 'x86/sse_xform4.S',
- 'x86/sse_normal.S',
- 'x86/read_rgba_span_x86.S',
- ]
- elif env['machine'] == 'x86_64':
- env.Append(CPPDEFINES = [
- 'USE_X86_64_ASM',
- ])
- mesa_sources += [
- 'x86-64/x86-64.c',
- 'x86-64/xform4.S',
- ]
- elif env['machine'] == 'ppc':
- env.Append(CPPDEFINES = [
- 'USE_PPC_ASM',
- 'USE_VMX_ASM',
- ])
- mesa_sources += [
- 'ppc/common_ppc.c',
- ]
- elif env['machine'] == 'sparc':
- mesa_sources += [
- 'sparc/sparc.c',
- 'sparc/clip.S',
- 'sparc/norm.S',
- 'sparc/xform.S',
- ]
- else:
- pass
-
- # Generate matypes.h
- if env['machine'] in ('x86', 'x86_64'):
- # See http://www.scons.org/wiki/UsingCodeGenerators
- gen_matypes = env.Program(
- target = 'gen_matypes',
- source = 'x86/gen_matypes.c',
- )
- matypes = env.Command(
- 'matypes.h',
- gen_matypes,
- gen_matypes[0].abspath + ' > $TARGET',
- )
- # Add the dir containing the generated header (somewhere inside the
- # build dir) to the include path
- env.Append(CPPPATH = [matypes[0].dir])
-
-#
-# Libraries
-#
-
-mesa = env.ConvenienceLibrary(
- target = 'mesa',
- source = mesa_sources,
-)
-
-env.Alias('mesa', mesa)
-
-Export('mesa')
+#######################################################################
+# SConscript for Mesa
+
+
+Import('*')
+
+env = env.Clone()
+
+env.Append(CPPPATH = [
+ '#/src/mapi',
+ '#/src/glsl',
+ '#/src/mesa',
+])
+
+env.Append(CPPDEFINES = [
+ 'FEATURE_GL=1',
+])
+
+if env['platform'] == 'windows':
+ env.Append(CPPDEFINES = [
+ '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
+ 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
+ ])
+ if not env['gles']:
+ # prevent _glapi_* from being declared __declspec(dllimport)
+ env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
+else:
+ env.Append(CPPDEFINES = [
+ 'IN_DRI_DRIVER', # enable the remap table (for DRI drivers)
+ ])
+
+#
+# Source files
+#
+
+main_sources = [
+ 'main/api_arrayelt.c',
+ 'main/api_exec.c',
+ 'main/api_loopback.c',
+ 'main/api_noop.c',
+ 'main/api_validate.c',
+ 'main/accum.c',
+ 'main/arbprogram.c',
+ 'main/atifragshader.c',
+ 'main/attrib.c',
+ 'main/arrayobj.c',
+ 'main/blend.c',
+ 'main/bufferobj.c',
+ 'main/buffers.c',
+ 'main/clear.c',
+ 'main/clip.c',
+ 'main/colortab.c',
+ 'main/condrender.c',
+ 'main/context.c',
+ 'main/convolve.c',
+ 'main/cpuinfo.c',
+ 'main/debug.c',
+ 'main/depth.c',
+ 'main/depthstencil.c',
+ 'main/dlist.c',
+ 'main/dlopen.c',
+ 'main/drawpix.c',
+ 'main/drawtex.c',
+ 'main/enable.c',
+ 'main/enums.c',
+ 'main/eval.c',
+ 'main/execmem.c',
+ 'main/extensions.c',
+ 'main/fbobject.c',
+ 'main/feedback.c',
+ 'main/ffvertex_prog.c',
+ 'main/fog.c',
+ 'main/formats.c',
+ 'main/framebuffer.c',
+ 'main/get.c',
+ 'main/getstring.c',
+ 'main/hash.c',
+ 'main/hint.c',
+ 'main/histogram.c',
+ 'main/image.c',
+ 'main/imports.c',
+ 'main/light.c',
+ 'main/lines.c',
+ 'main/matrix.c',
+ 'main/mipmap.c',
+ 'main/mm.c',
+ 'main/multisample.c',
+ 'main/nvprogram.c',
+ 'main/pack.c',
+ 'main/pbo.c',
+ 'main/pixel.c',
+ 'main/pixelstore.c',
+ 'main/pixeltransfer.c',
+ 'main/points.c',
+ 'main/polygon.c',
+ 'main/querymatrix.c',
+ 'main/queryobj.c',
+ 'main/rastpos.c',
+ 'main/readpix.c',
+ 'main/remap.c',
+ 'main/renderbuffer.c',
+ 'main/scissor.c',
+ 'main/shaderapi.c',
+ 'main/shaderobj.c',
+ 'main/shared.c',
+ 'main/state.c',
+ 'main/stencil.c',
+ 'main/syncobj.c',
+ 'main/texcompress.c',
+ 'main/texcompress_rgtc.c',
+ 'main/texcompress_s3tc.c',
+ 'main/texcompress_fxt1.c',
+ 'main/texenv.c',
+ 'main/texenvprogram.c',
+ 'main/texfetch.c',
+ 'main/texformat.c',
+ 'main/texgen.c',
+ 'main/texgetimage.c',
+ 'main/teximage.c',
+ 'main/texobj.c',
+ 'main/texpal.c',
+ 'main/texparam.c',
+ 'main/texrender.c',
+ 'main/texstate.c',
+ 'main/texstore.c',
+ 'main/transformfeedback.c',
+ 'main/uniforms.c',
+ 'main/varray.c',
+ 'main/version.c',
+ 'main/viewport.c',
+ 'main/vtxfmt.c',
+]
+
+math_sources = [
+ 'math/m_debug_clip.c',
+ 'math/m_debug_norm.c',
+ 'math/m_debug_xform.c',
+ 'math/m_eval.c',
+ 'math/m_matrix.c',
+ 'math/m_translate.c',
+ 'math/m_vector.c',
+ 'math/m_xform.c',
+]
+
+vbo_sources = [
+ 'vbo/vbo_context.c',
+ 'vbo/vbo_exec.c',
+ 'vbo/vbo_exec_api.c',
+ 'vbo/vbo_exec_array.c',
+ 'vbo/vbo_exec_draw.c',
+ 'vbo/vbo_exec_eval.c',
+ 'vbo/vbo_rebase.c',
+ 'vbo/vbo_split.c',
+ 'vbo/vbo_split_copy.c',
+ 'vbo/vbo_split_inplace.c',
+ 'vbo/vbo_save.c',
+ 'vbo/vbo_save_api.c',
+ 'vbo/vbo_save_draw.c',
+ 'vbo/vbo_save_loopback.c',
+]
+
+vf_sources = [
+ 'vf/vf.c',
+ 'vf/vf_generic.c',
+ 'vf/vf_sse.c',
+]
+
+statetracker_sources = [
+ 'state_tracker/st_atom.c',
+ 'state_tracker/st_atom_blend.c',
+ 'state_tracker/st_atom_clip.c',
+ 'state_tracker/st_atom_constbuf.c',
+ 'state_tracker/st_atom_depth.c',
+ 'state_tracker/st_atom_framebuffer.c',
+ 'state_tracker/st_atom_msaa.c',
+ 'state_tracker/st_atom_pixeltransfer.c',
+ 'state_tracker/st_atom_sampler.c',
+ 'state_tracker/st_atom_scissor.c',
+ 'state_tracker/st_atom_shader.c',
+ 'state_tracker/st_atom_rasterizer.c',
+ 'state_tracker/st_atom_stipple.c',
+ 'state_tracker/st_atom_texture.c',
+ 'state_tracker/st_atom_viewport.c',
+ 'state_tracker/st_cb_accum.c',
+ 'state_tracker/st_cb_bitmap.c',
+ 'state_tracker/st_cb_blit.c',
+ 'state_tracker/st_cb_bufferobjects.c',
+ 'state_tracker/st_cb_clear.c',
+ 'state_tracker/st_cb_condrender.c',
+ 'state_tracker/st_cb_flush.c',
+ 'state_tracker/st_cb_drawpixels.c',
+ 'state_tracker/st_cb_drawtex.c',
+ 'state_tracker/st_cb_eglimage.c',
+ 'state_tracker/st_cb_fbo.c',
+ 'state_tracker/st_cb_feedback.c',
+ 'state_tracker/st_cb_program.c',
+ 'state_tracker/st_cb_queryobj.c',
+ 'state_tracker/st_cb_rasterpos.c',
+ 'state_tracker/st_cb_readpixels.c',
+ 'state_tracker/st_cb_strings.c',
+ 'state_tracker/st_cb_texture.c',
+ 'state_tracker/st_cb_viewport.c',
+ 'state_tracker/st_cb_xformfb.c',
+ 'state_tracker/st_context.c',
+ 'state_tracker/st_debug.c',
+ 'state_tracker/st_draw.c',
+ 'state_tracker/st_draw_feedback.c',
+ 'state_tracker/st_extensions.c',
+ 'state_tracker/st_format.c',
+ 'state_tracker/st_gen_mipmap.c',
+ 'state_tracker/st_manager.c',
+ 'state_tracker/st_mesa_to_tgsi.c',
+ 'state_tracker/st_program.c',
+ 'state_tracker/st_texture.c',
+]
+
+env.Append(YACCFLAGS = '-d')
+program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
+program_parse = env.CFile('program/program_parse.tab.c',
+ 'program/program_parse.y')
+program_sources = [
+ 'program/arbprogparse.c',
+ 'program/hash_table.c',
+ 'program/ir_to_mesa.cpp',
+ 'program/nvfragparse.c',
+ 'program/nvvertparse.c',
+ 'program/program.c',
+ 'program/program_parse_extra.c',
+ 'program/prog_cache.c',
+ 'program/prog_execute.c',
+ 'program/prog_instruction.c',
+ 'program/prog_noise.c',
+ 'program/prog_optimize.c',
+ 'program/prog_parameter.c',
+ 'program/prog_parameter_layout.c',
+ 'program/prog_print.c',
+ 'program/prog_statevars.c',
+ 'program/prog_uniform.c',
+ 'program/programopt.c',
+ 'program/sampler.cpp',
+ 'program/symbol_table.c',
+ program_lex,
+ program_parse[0],
+]
+
+mesa_sources = (
+ main_sources +
+ math_sources +
+ program_sources +
+ vbo_sources +
+ vf_sources +
+ statetracker_sources
+)
+
+if env['gles']:
+ from sys import executable as python_cmd
+
+ env.Append(CPPDEFINES = ['FEATURE_ES1=1', 'FEATURE_ES2=1'])
+
+ # generate GLES sources
+ gles_sources = []
+ gles_sources += env.CodeGenerate(
+ target = 'main/api_exec_es1.c',
+ script = 'main/es_generator.py',
+ source = 'main/APIspec.xml',
+ command = python_cmd + ' $SCRIPT -S $SOURCE -V GLES1.1 > $TARGET'
+ )
+ gles_sources += env.CodeGenerate(
+ target = 'main/api_exec_es2.c',
+ script = 'main/es_generator.py',
+ source = 'main/APIspec.xml',
+ command = python_cmd + ' $SCRIPT -S $SOURCE -V GLES2.0 > $TARGET'
+ )
+
+ # generate GLES headers
+ GLAPI = '#src/mapi/glapi/'
+ gles_headers = []
+ gles_headers += env.CodeGenerate(
+ target = 'es1api/main/glapidispatch.h',
+ script = GLAPI + 'gen/gl_table.py',
+ source = GLAPI + 'gen-es/es1_API.xml',
+ command = python_cmd + ' $SCRIPT -c -m remap_table -f $SOURCE > $TARGET',
+ )
+ gles_headers += env.CodeGenerate(
+ target = 'es1api/main/remap_helper.h',
+ script = GLAPI + 'gen/remap_helper.py',
+ source = GLAPI + 'gen-es/es1_API.xml',
+ command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET',
+ )
+ gles_headers += env.CodeGenerate(
+ target = 'es2api/main/glapidispatch.h',
+ script = GLAPI + 'gen/gl_table.py',
+ source = GLAPI + 'gen-es/es2_API.xml',
+ command = python_cmd + ' $SCRIPT -c -m remap_table -f $SOURCE > $TARGET',
+ )
+ gles_headers += env.CodeGenerate(
+ target = 'es2api/main/remap_helper.h',
+ script = GLAPI + 'gen/remap_helper.py',
+ source = GLAPI + 'gen-es/es2_API.xml',
+ command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET',
+ )
+
+ env.Depends(gles_sources, gles_headers)
+
+ # gles_sources #include gles_headers with full path
+ env.Append(CPPPATH = [gles_headers[0].dir.up().up()])
+
+ mesa_sources += gles_sources
+
+#
+# Assembly sources
+#
+if env['gcc'] and env['platform'] != 'windows':
+ if env['machine'] == 'x86':
+ env.Append(CPPDEFINES = [
+ 'USE_X86_ASM',
+ 'USE_MMX_ASM',
+ 'USE_3DNOW_ASM',
+ 'USE_SSE_ASM',
+ ])
+ mesa_sources += [
+ 'x86/common_x86.c',
+ 'x86/x86_xform.c',
+ 'x86/3dnow.c',
+ 'x86/sse.c',
+ 'x86/common_x86_asm.S',
+ 'x86/x86_xform2.S',
+ 'x86/x86_xform3.S',
+ 'x86/x86_xform4.S',
+ 'x86/x86_cliptest.S',
+ 'x86/mmx_blend.S',
+ 'x86/3dnow_xform1.S',
+ 'x86/3dnow_xform2.S',
+ 'x86/3dnow_xform3.S',
+ 'x86/3dnow_xform4.S',
+ 'x86/3dnow_normal.S',
+ 'x86/sse_xform1.S',
+ 'x86/sse_xform2.S',
+ 'x86/sse_xform3.S',
+ 'x86/sse_xform4.S',
+ 'x86/sse_normal.S',
+ 'x86/read_rgba_span_x86.S',
+ ]
+ elif env['machine'] == 'x86_64':
+ env.Append(CPPDEFINES = [
+ 'USE_X86_64_ASM',
+ ])
+ mesa_sources += [
+ 'x86-64/x86-64.c',
+ 'x86-64/xform4.S',
+ ]
+ elif env['machine'] == 'ppc':
+ env.Append(CPPDEFINES = [
+ 'USE_PPC_ASM',
+ 'USE_VMX_ASM',
+ ])
+ mesa_sources += [
+ 'ppc/common_ppc.c',
+ ]
+ elif env['machine'] == 'sparc':
+ mesa_sources += [
+ 'sparc/sparc.c',
+ 'sparc/clip.S',
+ 'sparc/norm.S',
+ 'sparc/xform.S',
+ ]
+ else:
+ pass
+
+ # Generate matypes.h
+ if env['machine'] in ('x86', 'x86_64'):
+ # See http://www.scons.org/wiki/UsingCodeGenerators
+ gen_matypes = env.Program(
+ target = 'gen_matypes',
+ source = 'x86/gen_matypes.c',
+ )
+ matypes = env.Command(
+ 'matypes.h',
+ gen_matypes,
+ gen_matypes[0].abspath + ' > $TARGET',
+ )
+ # Add the dir containing the generated header (somewhere inside the
+ # build dir) to the include path
+ env.Append(CPPPATH = [matypes[0].dir])
+
+#
+# Libraries
+#
+
+mesa = env.ConvenienceLibrary(
+ target = 'mesa',
+ source = mesa_sources,
+)
+
+env.Alias('mesa', mesa)
+
+Export('mesa')
diff --git a/mesalib/src/mesa/drivers/common/meta.c b/mesalib/src/mesa/drivers/common/meta.c
index 2b00e8979..a3720a24d 100644
--- a/mesalib/src/mesa/drivers/common/meta.c
+++ b/mesalib/src/mesa/drivers/common/meta.c
@@ -1,2852 +1,2852 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.6
- *
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * Meta operations. Some GL operations can be expressed in terms of
- * other GL operations. For example, glBlitFramebuffer() can be done
- * with texture mapping and glClear() can be done with polygon rendering.
- *
- * \author Brian Paul
- */
-
-
-#include "main/glheader.h"
-#include "main/mtypes.h"
-#include "main/imports.h"
-#include "main/arbprogram.h"
-#include "main/arrayobj.h"
-#include "main/blend.h"
-#include "main/bufferobj.h"
-#include "main/buffers.h"
-#include "main/colortab.h"
-#include "main/depth.h"
-#include "main/enable.h"
-#include "main/fbobject.h"
-#include "main/formats.h"
-#include "main/image.h"
-#include "main/macros.h"
-#include "main/matrix.h"
-#include "main/mipmap.h"
-#include "main/pbo.h"
-#include "main/polygon.h"
-#include "main/readpix.h"
-#include "main/scissor.h"
-#include "main/shaderapi.h"
-#include "main/shaderobj.h"
-#include "main/state.h"
-#include "main/stencil.h"
-#include "main/texobj.h"
-#include "main/texenv.h"
-#include "main/teximage.h"
-#include "main/texparam.h"
-#include "main/texstate.h"
-#include "main/varray.h"
-#include "main/viewport.h"
-#include "program/program.h"
-#include "swrast/swrast.h"
-#include "drivers/common/meta.h"
-
-
-/** Return offset in bytes of the field within a vertex struct */
-#define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD))
-
-
-/**
- * Flags passed to _mesa_meta_begin().
- */
-/*@{*/
-#define META_ALL ~0x0
-#define META_ALPHA_TEST 0x1
-#define META_BLEND 0x2 /**< includes logicop */
-#define META_COLOR_MASK 0x4
-#define META_DEPTH_TEST 0x8
-#define META_FOG 0x10
-#define META_PIXEL_STORE 0x20
-#define META_PIXEL_TRANSFER 0x40
-#define META_RASTERIZATION 0x80
-#define META_SCISSOR 0x100
-#define META_SHADER 0x200
-#define META_STENCIL_TEST 0x400
-#define META_TRANSFORM 0x800 /**< modelview, projection, clip planes */
-#define META_TEXTURE 0x1000
-#define META_VERTEX 0x2000
-#define META_VIEWPORT 0x4000
-/*@}*/
-
-
-/**
- * State which we may save/restore across meta ops.
- * XXX this may be incomplete...
- */
-struct save_state
-{
- GLbitfield SavedState; /**< bitmask of META_* flags */
-
- /** META_ALPHA_TEST */
- GLboolean AlphaEnabled;
- GLenum AlphaFunc;
- GLclampf AlphaRef;
-
- /** META_BLEND */
- GLbitfield BlendEnabled;
- GLboolean ColorLogicOpEnabled;
-
- /** META_COLOR_MASK */
- GLubyte ColorMask[MAX_DRAW_BUFFERS][4];
-
- /** META_DEPTH_TEST */
- struct gl_depthbuffer_attrib Depth;
-
- /** META_FOG */
- GLboolean Fog;
-
- /** META_PIXEL_STORE */
- struct gl_pixelstore_attrib Pack, Unpack;
-
- /** META_PIXEL_TRANSFER */
- GLfloat RedBias, RedScale;
- GLfloat GreenBias, GreenScale;
- GLfloat BlueBias, BlueScale;
- GLfloat AlphaBias, AlphaScale;
- GLfloat DepthBias, DepthScale;
- GLboolean MapColorFlag;
-
- /** META_RASTERIZATION */
- GLenum FrontPolygonMode, BackPolygonMode;
- GLboolean PolygonOffset;
- GLboolean PolygonSmooth;
- GLboolean PolygonStipple;
- GLboolean PolygonCull;
-
- /** META_SCISSOR */
- struct gl_scissor_attrib Scissor;
-
- /** META_SHADER */
- GLboolean VertexProgramEnabled;
- struct gl_vertex_program *VertexProgram;
- GLboolean FragmentProgramEnabled;
- struct gl_fragment_program *FragmentProgram;
- struct gl_shader_program *VertexShader;
- struct gl_shader_program *GeometryShader;
- struct gl_shader_program *FragmentShader;
- struct gl_shader_program *ActiveShader;
-
- /** META_STENCIL_TEST */
- struct gl_stencil_attrib Stencil;
-
- /** META_TRANSFORM */
- GLenum MatrixMode;
- GLfloat ModelviewMatrix[16];
- GLfloat ProjectionMatrix[16];
- GLfloat TextureMatrix[16];
- GLbitfield ClipPlanesEnabled;
-
- /** META_TEXTURE */
- GLuint ActiveUnit;
- GLuint ClientActiveUnit;
- /** for unit[0] only */
- struct gl_texture_object *CurrentTexture[NUM_TEXTURE_TARGETS];
- /** mask of TEXTURE_2D_BIT, etc */
- GLbitfield TexEnabled[MAX_TEXTURE_UNITS];
- GLbitfield TexGenEnabled[MAX_TEXTURE_UNITS];
- GLuint EnvMode; /* unit[0] only */
-
- /** META_VERTEX */
- struct gl_array_object *ArrayObj;
- struct gl_buffer_object *ArrayBufferObj;
-
- /** META_VIEWPORT */
- GLint ViewportX, ViewportY, ViewportW, ViewportH;
- GLclampd DepthNear, DepthFar;
-
- /** Miscellaneous (always disabled) */
- GLboolean Lighting;
-};
-
-
-/**
- * Temporary texture used for glBlitFramebuffer, glDrawPixels, etc.
- * This is currently shared by all the meta ops. But we could create a
- * separate one for each of glDrawPixel, glBlitFramebuffer, glCopyPixels, etc.
- */
-struct temp_texture
-{
- GLuint TexObj;
- GLenum Target; /**< GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE */
- GLsizei MinSize; /**< Min texture size to allocate */
- GLsizei MaxSize; /**< Max possible texture size */
- GLboolean NPOT; /**< Non-power of two size OK? */
- GLsizei Width, Height; /**< Current texture size */
- GLenum IntFormat;
- GLfloat Sright, Ttop; /**< right, top texcoords */
-};
-
-
-/**
- * State for glBlitFramebufer()
- */
-struct blit_state
-{
- GLuint ArrayObj;
- GLuint VBO;
- GLuint DepthFP;
-};
-
-
-/**
- * State for glClear()
- */
-struct clear_state
-{
- GLuint ArrayObj;
- GLuint VBO;
-};
-
-
-/**
- * State for glCopyPixels()
- */
-struct copypix_state
-{
- GLuint ArrayObj;
- GLuint VBO;
-};
-
-
-/**
- * State for glDrawPixels()
- */
-struct drawpix_state
-{
- GLuint ArrayObj;
-
- GLuint StencilFP; /**< Fragment program for drawing stencil images */
- GLuint DepthFP; /**< Fragment program for drawing depth images */
-};
-
-
-/**
- * State for glBitmap()
- */
-struct bitmap_state
-{
- GLuint ArrayObj;
- GLuint VBO;
- struct temp_texture Tex; /**< separate texture from other meta ops */
-};
-
-
-/**
- * State for _mesa_meta_generate_mipmap()
- */
-struct gen_mipmap_state
-{
- GLuint ArrayObj;
- GLuint VBO;
- GLuint FBO;
-};
-
-#define MAX_META_OPS_DEPTH 2
-/**
- * All per-context meta state.
- */
-struct gl_meta_state
-{
- /** Stack of state saved during meta-ops */
- struct save_state Save[MAX_META_OPS_DEPTH];
- /** Save stack depth */
- GLuint SaveStackDepth;
-
- struct temp_texture TempTex;
-
- struct blit_state Blit; /**< For _mesa_meta_BlitFramebuffer() */
- struct clear_state Clear; /**< For _mesa_meta_Clear() */
- struct copypix_state CopyPix; /**< For _mesa_meta_CopyPixels() */
- struct drawpix_state DrawPix; /**< For _mesa_meta_DrawPixels() */
- struct bitmap_state Bitmap; /**< For _mesa_meta_Bitmap() */
- struct gen_mipmap_state Mipmap; /**< For _mesa_meta_GenerateMipmap() */
-};
-
-
-/**
- * Initialize meta-ops for a context.
- * To be called once during context creation.
- */
-void
-_mesa_meta_init(struct gl_context *ctx)
-{
- ASSERT(!ctx->Meta);
-
- ctx->Meta = CALLOC_STRUCT(gl_meta_state);
-}
-
-
-/**
- * Free context meta-op state.
- * To be called once during context destruction.
- */
-void
-_mesa_meta_free(struct gl_context *ctx)
-{
- /* Note: Any textures, VBOs, etc, that we allocate should get
- * freed by the normal context destruction code. But this would be
- * the place to free other meta data someday.
- */
- free(ctx->Meta);
- ctx->Meta = NULL;
-}
-
-
-/**
- * Enter meta state. This is like a light-weight version of glPushAttrib
- * but it also resets most GL state back to default values.
- *
- * \param state bitmask of META_* flags indicating which attribute groups
- * to save and reset to their defaults
- */
-static void
-_mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
-{
- struct save_state *save;
-
- /* hope MAX_META_OPS_DEPTH is large enough */
- assert(ctx->Meta->SaveStackDepth < MAX_META_OPS_DEPTH);
-
- save = &ctx->Meta->Save[ctx->Meta->SaveStackDepth++];
- memset(save, 0, sizeof(*save));
- save->SavedState = state;
-
- if (state & META_ALPHA_TEST) {
- save->AlphaEnabled = ctx->Color.AlphaEnabled;
- save->AlphaFunc = ctx->Color.AlphaFunc;
- save->AlphaRef = ctx->Color.AlphaRef;
- if (ctx->Color.AlphaEnabled)
- _mesa_set_enable(ctx, GL_ALPHA_TEST, GL_FALSE);
- }
-
- if (state & META_BLEND) {
- save->BlendEnabled = ctx->Color.BlendEnabled;
- if (ctx->Color.BlendEnabled) {
- if (ctx->Extensions.EXT_draw_buffers2) {
- GLuint i;
- for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
- _mesa_set_enablei(ctx, GL_BLEND, i, GL_FALSE);
- }
- }
- else {
- _mesa_set_enable(ctx, GL_BLEND, GL_FALSE);
- }
- }
- save->ColorLogicOpEnabled = ctx->Color.ColorLogicOpEnabled;
- if (ctx->Color.ColorLogicOpEnabled)
- _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP, GL_FALSE);
- }
-
- if (state & META_COLOR_MASK) {
- memcpy(save->ColorMask, ctx->Color.ColorMask,
- sizeof(ctx->Color.ColorMask));
- if (!ctx->Color.ColorMask[0][0] ||
- !ctx->Color.ColorMask[0][1] ||
- !ctx->Color.ColorMask[0][2] ||
- !ctx->Color.ColorMask[0][3])
- _mesa_ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- }
-
- if (state & META_DEPTH_TEST) {
- save->Depth = ctx->Depth; /* struct copy */
- if (ctx->Depth.Test)
- _mesa_set_enable(ctx, GL_DEPTH_TEST, GL_FALSE);
- }
-
- if (state & META_FOG) {
- save->Fog = ctx->Fog.Enabled;
- if (ctx->Fog.Enabled)
- _mesa_set_enable(ctx, GL_FOG, GL_FALSE);
- }
-
- if (state & META_PIXEL_STORE) {
- save->Pack = ctx->Pack;
- save->Unpack = ctx->Unpack;
- ctx->Pack = ctx->DefaultPacking;
- ctx->Unpack = ctx->DefaultPacking;
- }
-
- if (state & META_PIXEL_TRANSFER) {
- save->RedScale = ctx->Pixel.RedScale;
- save->RedBias = ctx->Pixel.RedBias;
- save->GreenScale = ctx->Pixel.GreenScale;
- save->GreenBias = ctx->Pixel.GreenBias;
- save->BlueScale = ctx->Pixel.BlueScale;
- save->BlueBias = ctx->Pixel.BlueBias;
- save->AlphaScale = ctx->Pixel.AlphaScale;
- save->AlphaBias = ctx->Pixel.AlphaBias;
- save->MapColorFlag = ctx->Pixel.MapColorFlag;
- ctx->Pixel.RedScale = 1.0F;
- ctx->Pixel.RedBias = 0.0F;
- ctx->Pixel.GreenScale = 1.0F;
- ctx->Pixel.GreenBias = 0.0F;
- ctx->Pixel.BlueScale = 1.0F;
- ctx->Pixel.BlueBias = 0.0F;
- ctx->Pixel.AlphaScale = 1.0F;
- ctx->Pixel.AlphaBias = 0.0F;
- ctx->Pixel.MapColorFlag = GL_FALSE;
- /* XXX more state */
- ctx->NewState |=_NEW_PIXEL;
- }
-
- if (state & META_RASTERIZATION) {
- save->FrontPolygonMode = ctx->Polygon.FrontMode;
- save->BackPolygonMode = ctx->Polygon.BackMode;
- save->PolygonOffset = ctx->Polygon.OffsetFill;
- save->PolygonSmooth = ctx->Polygon.SmoothFlag;
- save->PolygonStipple = ctx->Polygon.StippleFlag;
- save->PolygonCull = ctx->Polygon.CullFlag;
- _mesa_PolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL, GL_FALSE);
- _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, GL_FALSE);
- _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, GL_FALSE);
- _mesa_set_enable(ctx, GL_CULL_FACE, GL_FALSE);
- }
-
- if (state & META_SCISSOR) {
- save->Scissor = ctx->Scissor; /* struct copy */
- _mesa_set_enable(ctx, GL_SCISSOR_TEST, GL_FALSE);
- }
-
- if (state & META_SHADER) {
- if (ctx->Extensions.ARB_vertex_program) {
- save->VertexProgramEnabled = ctx->VertexProgram.Enabled;
- _mesa_reference_vertprog(ctx, &save->VertexProgram,
- ctx->VertexProgram.Current);
- _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB, GL_FALSE);
- }
-
- if (ctx->Extensions.ARB_fragment_program) {
- save->FragmentProgramEnabled = ctx->FragmentProgram.Enabled;
- _mesa_reference_fragprog(ctx, &save->FragmentProgram,
- ctx->FragmentProgram.Current);
- _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_FALSE);
- }
-
- if (ctx->Extensions.ARB_shader_objects) {
- _mesa_reference_shader_program(ctx, &save->VertexShader,
- ctx->Shader.CurrentVertexProgram);
- _mesa_reference_shader_program(ctx, &save->GeometryShader,
- ctx->Shader.CurrentGeometryProgram);
- _mesa_reference_shader_program(ctx, &save->FragmentShader,
- ctx->Shader.CurrentFragmentProgram);
- _mesa_reference_shader_program(ctx, &save->ActiveShader,
- ctx->Shader.CurrentFragmentProgram);
-
- _mesa_UseProgramObjectARB(0);
- }
- }
-
- if (state & META_STENCIL_TEST) {
- save->Stencil = ctx->Stencil; /* struct copy */
- if (ctx->Stencil.Enabled)
- _mesa_set_enable(ctx, GL_STENCIL_TEST, GL_FALSE);
- /* NOTE: other stencil state not reset */
- }
-
- if (state & META_TEXTURE) {
- GLuint u, tgt;
-
- save->ActiveUnit = ctx->Texture.CurrentUnit;
- save->ClientActiveUnit = ctx->Array.ActiveTexture;
- save->EnvMode = ctx->Texture.Unit[0].EnvMode;
-
- /* Disable all texture units */
- for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
- save->TexEnabled[u] = ctx->Texture.Unit[u].Enabled;
- save->TexGenEnabled[u] = ctx->Texture.Unit[u].TexGenEnabled;
- if (ctx->Texture.Unit[u].Enabled ||
- ctx->Texture.Unit[u].TexGenEnabled) {
- _mesa_ActiveTextureARB(GL_TEXTURE0 + u);
- _mesa_set_enable(ctx, GL_TEXTURE_1D, GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_2D, GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_3D, GL_FALSE);
- if (ctx->Extensions.ARB_texture_cube_map)
- _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE, GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_R, GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
- }
- }
-
- /* save current texture objects for unit[0] only */
- for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
- _mesa_reference_texobj(&save->CurrentTexture[tgt],
- ctx->Texture.Unit[0].CurrentTex[tgt]);
- }
-
- /* set defaults for unit[0] */
- _mesa_ActiveTextureARB(GL_TEXTURE0);
- _mesa_ClientActiveTextureARB(GL_TEXTURE0);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- }
-
- if (state & META_TRANSFORM) {
- GLuint activeTexture = ctx->Texture.CurrentUnit;
- memcpy(save->ModelviewMatrix, ctx->ModelviewMatrixStack.Top->m,
- 16 * sizeof(GLfloat));
- memcpy(save->ProjectionMatrix, ctx->ProjectionMatrixStack.Top->m,
- 16 * sizeof(GLfloat));
- memcpy(save->TextureMatrix, ctx->TextureMatrixStack[0].Top->m,
- 16 * sizeof(GLfloat));
- save->MatrixMode = ctx->Transform.MatrixMode;
- /* set 1:1 vertex:pixel coordinate transform */
- _mesa_ActiveTextureARB(GL_TEXTURE0);
- _mesa_MatrixMode(GL_TEXTURE);
- _mesa_LoadIdentity();
- _mesa_ActiveTextureARB(GL_TEXTURE0 + activeTexture);
- _mesa_MatrixMode(GL_MODELVIEW);
- _mesa_LoadIdentity();
- _mesa_MatrixMode(GL_PROJECTION);
- _mesa_LoadIdentity();
- _mesa_Ortho(0.0, ctx->DrawBuffer->Width,
- 0.0, ctx->DrawBuffer->Height,
- -1.0, 1.0);
- save->ClipPlanesEnabled = ctx->Transform.ClipPlanesEnabled;
- if (ctx->Transform.ClipPlanesEnabled) {
- GLuint i;
- for (i = 0; i < ctx->Const.MaxClipPlanes; i++) {
- _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE);
- }
- }
- }
-
- if (state & META_VERTEX) {
- /* save vertex array object state */
- _mesa_reference_array_object(ctx, &save->ArrayObj,
- ctx->Array.ArrayObj);
- _mesa_reference_buffer_object(ctx, &save->ArrayBufferObj,
- ctx->Array.ArrayBufferObj);
- /* set some default state? */
- }
-
- if (state & META_VIEWPORT) {
- /* save viewport state */
- save->ViewportX = ctx->Viewport.X;
- save->ViewportY = ctx->Viewport.Y;
- save->ViewportW = ctx->Viewport.Width;
- save->ViewportH = ctx->Viewport.Height;
- /* set viewport to match window size */
- if (ctx->Viewport.X != 0 ||
- ctx->Viewport.Y != 0 ||
- ctx->Viewport.Width != ctx->DrawBuffer->Width ||
- ctx->Viewport.Height != ctx->DrawBuffer->Height) {
- _mesa_set_viewport(ctx, 0, 0,
- ctx->DrawBuffer->Width, ctx->DrawBuffer->Height);
- }
- /* save depth range state */
- save->DepthNear = ctx->Viewport.Near;
- save->DepthFar = ctx->Viewport.Far;
- /* set depth range to default */
- _mesa_DepthRange(0.0, 1.0);
- }
-
- /* misc */
- {
- save->Lighting = ctx->Light.Enabled;
- if (ctx->Light.Enabled)
- _mesa_set_enable(ctx, GL_LIGHTING, GL_FALSE);
- }
-}
-
-
-/**
- * Leave meta state. This is like a light-weight version of glPopAttrib().
- */
-static void
-_mesa_meta_end(struct gl_context *ctx)
-{
- struct save_state *save = &ctx->Meta->Save[--ctx->Meta->SaveStackDepth];
- const GLbitfield state = save->SavedState;
-
- if (state & META_ALPHA_TEST) {
- if (ctx->Color.AlphaEnabled != save->AlphaEnabled)
- _mesa_set_enable(ctx, GL_ALPHA_TEST, save->AlphaEnabled);
- _mesa_AlphaFunc(save->AlphaFunc, save->AlphaRef);
- }
-
- if (state & META_BLEND) {
- if (ctx->Color.BlendEnabled != save->BlendEnabled) {
- if (ctx->Extensions.EXT_draw_buffers2) {
- GLuint i;
- for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
- _mesa_set_enablei(ctx, GL_BLEND, i, (save->BlendEnabled >> i) & 1);
- }
- }
- else {
- _mesa_set_enable(ctx, GL_BLEND, (save->BlendEnabled & 1));
- }
- }
- if (ctx->Color.ColorLogicOpEnabled != save->ColorLogicOpEnabled)
- _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP, save->ColorLogicOpEnabled);
- }
-
- if (state & META_COLOR_MASK) {
- GLuint i;
- for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
- if (!TEST_EQ_4V(ctx->Color.ColorMask[i], save->ColorMask[i])) {
- if (i == 0) {
- _mesa_ColorMask(save->ColorMask[i][0], save->ColorMask[i][1],
- save->ColorMask[i][2], save->ColorMask[i][3]);
- }
- else {
- _mesa_ColorMaskIndexed(i,
- save->ColorMask[i][0],
- save->ColorMask[i][1],
- save->ColorMask[i][2],
- save->ColorMask[i][3]);
- }
- }
- }
- }
-
- if (state & META_DEPTH_TEST) {
- if (ctx->Depth.Test != save->Depth.Test)
- _mesa_set_enable(ctx, GL_DEPTH_TEST, save->Depth.Test);
- _mesa_DepthFunc(save->Depth.Func);
- _mesa_DepthMask(save->Depth.Mask);
- }
-
- if (state & META_FOG) {
- _mesa_set_enable(ctx, GL_FOG, save->Fog);
- }
-
- if (state & META_PIXEL_STORE) {
- ctx->Pack = save->Pack;
- ctx->Unpack = save->Unpack;
- }
-
- if (state & META_PIXEL_TRANSFER) {
- ctx->Pixel.RedScale = save->RedScale;
- ctx->Pixel.RedBias = save->RedBias;
- ctx->Pixel.GreenScale = save->GreenScale;
- ctx->Pixel.GreenBias = save->GreenBias;
- ctx->Pixel.BlueScale = save->BlueScale;
- ctx->Pixel.BlueBias = save->BlueBias;
- ctx->Pixel.AlphaScale = save->AlphaScale;
- ctx->Pixel.AlphaBias = save->AlphaBias;
- ctx->Pixel.MapColorFlag = save->MapColorFlag;
- /* XXX more state */
- ctx->NewState |=_NEW_PIXEL;
- }
-
- if (state & META_RASTERIZATION) {
- _mesa_PolygonMode(GL_FRONT, save->FrontPolygonMode);
- _mesa_PolygonMode(GL_BACK, save->BackPolygonMode);
- _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, save->PolygonStipple);
- _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL, save->PolygonOffset);
- _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, save->PolygonSmooth);
- _mesa_set_enable(ctx, GL_CULL_FACE, save->PolygonCull);
- }
-
- if (state & META_SCISSOR) {
- _mesa_set_enable(ctx, GL_SCISSOR_TEST, save->Scissor.Enabled);
- _mesa_Scissor(save->Scissor.X, save->Scissor.Y,
- save->Scissor.Width, save->Scissor.Height);
- }
-
- if (state & META_SHADER) {
- if (ctx->Extensions.ARB_vertex_program) {
- _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB,
- save->VertexProgramEnabled);
- _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current,
- save->VertexProgram);
- _mesa_reference_vertprog(ctx, &save->VertexProgram, NULL);
- }
-
- if (ctx->Extensions.ARB_fragment_program) {
- _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB,
- save->FragmentProgramEnabled);
- _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current,
- save->FragmentProgram);
- _mesa_reference_fragprog(ctx, &save->FragmentProgram, NULL);
- }
-
- if (ctx->Extensions.ARB_vertex_shader)
- _mesa_use_shader_program(ctx, GL_VERTEX_SHADER, save->VertexShader);
-
- if (ctx->Extensions.ARB_geometry_shader4)
- _mesa_use_shader_program(ctx, GL_GEOMETRY_SHADER_ARB,
- save->GeometryShader);
-
- if (ctx->Extensions.ARB_fragment_shader)
- _mesa_use_shader_program(ctx, GL_FRAGMENT_SHADER,
- save->FragmentShader);
-
- _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram,
- save->ActiveShader);
- }
-
- if (state & META_STENCIL_TEST) {
- const struct gl_stencil_attrib *stencil = &save->Stencil;
-
- _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled);
- _mesa_ClearStencil(stencil->Clear);
- if (ctx->Extensions.EXT_stencil_two_side) {
- _mesa_set_enable(ctx, GL_STENCIL_TEST_TWO_SIDE_EXT,
- stencil->TestTwoSide);
- _mesa_ActiveStencilFaceEXT(stencil->ActiveFace
- ? GL_BACK : GL_FRONT);
- }
- /* front state */
- _mesa_StencilFuncSeparate(GL_FRONT,
- stencil->Function[0],
- stencil->Ref[0],
- stencil->ValueMask[0]);
- _mesa_StencilMaskSeparate(GL_FRONT, stencil->WriteMask[0]);
- _mesa_StencilOpSeparate(GL_FRONT, stencil->FailFunc[0],
- stencil->ZFailFunc[0],
- stencil->ZPassFunc[0]);
- /* back state */
- _mesa_StencilFuncSeparate(GL_BACK,
- stencil->Function[1],
- stencil->Ref[1],
- stencil->ValueMask[1]);
- _mesa_StencilMaskSeparate(GL_BACK, stencil->WriteMask[1]);
- _mesa_StencilOpSeparate(GL_BACK, stencil->FailFunc[1],
- stencil->ZFailFunc[1],
- stencil->ZPassFunc[1]);
- }
-
- if (state & META_TEXTURE) {
- GLuint u, tgt;
-
- ASSERT(ctx->Texture.CurrentUnit == 0);
-
- /* restore texenv for unit[0] */
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, save->EnvMode);
-
- /* restore texture objects for unit[0] only */
- for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
- _mesa_reference_texobj(&ctx->Texture.Unit[0].CurrentTex[tgt],
- save->CurrentTexture[tgt]);
- _mesa_reference_texobj(&save->CurrentTexture[tgt], NULL);
- }
-
- /* Re-enable textures, texgen */
- for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
- if (save->TexEnabled[u]) {
- _mesa_ActiveTextureARB(GL_TEXTURE0 + u);
-
- if (save->TexEnabled[u] & TEXTURE_1D_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_1D, GL_TRUE);
- if (save->TexEnabled[u] & TEXTURE_2D_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_2D, GL_TRUE);
- if (save->TexEnabled[u] & TEXTURE_3D_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_3D, GL_TRUE);
- if (save->TexEnabled[u] & TEXTURE_CUBE_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_TRUE);
- if (save->TexEnabled[u] & TEXTURE_RECT_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE, GL_TRUE);
- }
-
- if (save->TexGenEnabled[u]) {
- _mesa_ActiveTextureARB(GL_TEXTURE0 + u);
-
- if (save->TexGenEnabled[u] & S_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, GL_TRUE);
- if (save->TexGenEnabled[u] & T_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, GL_TRUE);
- if (save->TexGenEnabled[u] & R_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_R, GL_TRUE);
- if (save->TexGenEnabled[u] & Q_BIT)
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
- }
- }
-
- /* restore current unit state */
- _mesa_ActiveTextureARB(GL_TEXTURE0 + save->ActiveUnit);
- _mesa_ClientActiveTextureARB(GL_TEXTURE0 + save->ClientActiveUnit);
- }
-
- if (state & META_TRANSFORM) {
- GLuint activeTexture = ctx->Texture.CurrentUnit;
- _mesa_ActiveTextureARB(GL_TEXTURE0);
- _mesa_MatrixMode(GL_TEXTURE);
- _mesa_LoadMatrixf(save->TextureMatrix);
- _mesa_ActiveTextureARB(GL_TEXTURE0 + activeTexture);
-
- _mesa_MatrixMode(GL_MODELVIEW);
- _mesa_LoadMatrixf(save->ModelviewMatrix);
-
- _mesa_MatrixMode(GL_PROJECTION);
- _mesa_LoadMatrixf(save->ProjectionMatrix);
-
- _mesa_MatrixMode(save->MatrixMode);
-
- if (save->ClipPlanesEnabled) {
- GLuint i;
- for (i = 0; i < ctx->Const.MaxClipPlanes; i++) {
- if (save->ClipPlanesEnabled & (1 << i)) {
- _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_TRUE);
- }
- }
- }
- }
-
- if (state & META_VERTEX) {
- /* restore vertex buffer object */
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, save->ArrayBufferObj->Name);
- _mesa_reference_buffer_object(ctx, &save->ArrayBufferObj, NULL);
-
- /* restore vertex array object */
- _mesa_BindVertexArray(save->ArrayObj->Name);
- _mesa_reference_array_object(ctx, &save->ArrayObj, NULL);
- }
-
- if (state & META_VIEWPORT) {
- if (save->ViewportX != ctx->Viewport.X ||
- save->ViewportY != ctx->Viewport.Y ||
- save->ViewportW != ctx->Viewport.Width ||
- save->ViewportH != ctx->Viewport.Height) {
- _mesa_set_viewport(ctx, save->ViewportX, save->ViewportY,
- save->ViewportW, save->ViewportH);
- }
- _mesa_DepthRange(save->DepthNear, save->DepthFar);
- }
-
- /* misc */
- if (save->Lighting) {
- _mesa_set_enable(ctx, GL_LIGHTING, GL_TRUE);
- }
-}
-
-
-/**
- * Convert Z from a normalized value in the range [0, 1] to an object-space
- * Z coordinate in [-1, +1] so that drawing at the new Z position with the
- * default/identity ortho projection results in the original Z value.
- * Used by the meta-Clear, Draw/CopyPixels and Bitmap functions where the Z
- * value comes from the clear value or raster position.
- */
-static INLINE GLfloat
-invert_z(GLfloat normZ)
-{
- GLfloat objZ = 1.0 - 2.0 * normZ;
- return objZ;
-}
-
-
-/**
- * One-time init for a temp_texture object.
- * Choose tex target, compute max tex size, etc.
- */
-static void
-init_temp_texture(struct gl_context *ctx, struct temp_texture *tex)
-{
- /* prefer texture rectangle */
- if (ctx->Extensions.NV_texture_rectangle) {
- tex->Target = GL_TEXTURE_RECTANGLE;
- tex->MaxSize = ctx->Const.MaxTextureRectSize;
- tex->NPOT = GL_TRUE;
- }
- else {
- /* use 2D texture, NPOT if possible */
- tex->Target = GL_TEXTURE_2D;
- tex->MaxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
- tex->NPOT = ctx->Extensions.ARB_texture_non_power_of_two;
- }
- tex->MinSize = 16; /* 16 x 16 at least */
- assert(tex->MaxSize > 0);
-
- _mesa_GenTextures(1, &tex->TexObj);
-}
-
-
-/**
- * Return pointer to temp_texture info for non-bitmap ops.
- * This does some one-time init if needed.
- */
-static struct temp_texture *
-get_temp_texture(struct gl_context *ctx)
-{
- struct temp_texture *tex = &ctx->Meta->TempTex;
-
- if (!tex->TexObj) {
- init_temp_texture(ctx, tex);
- }
-
- return tex;
-}
-
-
-/**
- * Return pointer to temp_texture info for _mesa_meta_bitmap().
- * We use a separate texture for bitmaps to reduce texture
- * allocation/deallocation.
- */
-static struct temp_texture *
-get_bitmap_temp_texture(struct gl_context *ctx)
-{
- struct temp_texture *tex = &ctx->Meta->Bitmap.Tex;
-
- if (!tex->TexObj) {
- init_temp_texture(ctx, tex);
- }
-
- return tex;
-}
-
-
-/**
- * Compute the width/height of texture needed to draw an image of the
- * given size. Return a flag indicating whether the current texture
- * can be re-used (glTexSubImage2D) or if a new texture needs to be
- * allocated (glTexImage2D).
- * Also, compute s/t texcoords for drawing.
- *
- * \return GL_TRUE if new texture is needed, GL_FALSE otherwise
- */
-static GLboolean
-alloc_texture(struct temp_texture *tex,
- GLsizei width, GLsizei height, GLenum intFormat)
-{
- GLboolean newTex = GL_FALSE;
-
- ASSERT(width <= tex->MaxSize);
- ASSERT(height <= tex->MaxSize);
-
- if (width > tex->Width ||
- height > tex->Height ||
- intFormat != tex->IntFormat) {
- /* alloc new texture (larger or different format) */
-
- if (tex->NPOT) {
- /* use non-power of two size */
- tex->Width = MAX2(tex->MinSize, width);
- tex->Height = MAX2(tex->MinSize, height);
- }
- else {
- /* find power of two size */
- GLsizei w, h;
- w = h = tex->MinSize;
- while (w < width)
- w *= 2;
- while (h < height)
- h *= 2;
- tex->Width = w;
- tex->Height = h;
- }
-
- tex->IntFormat = intFormat;
-
- newTex = GL_TRUE;
- }
-
- /* compute texcoords */
- if (tex->Target == GL_TEXTURE_RECTANGLE) {
- tex->Sright = (GLfloat) width;
- tex->Ttop = (GLfloat) height;
- }
- else {
- tex->Sright = (GLfloat) width / tex->Width;
- tex->Ttop = (GLfloat) height / tex->Height;
- }
-
- return newTex;
-}
-
-
-/**
- * Setup/load texture for glCopyPixels or glBlitFramebuffer.
- */
-static void
-setup_copypix_texture(struct temp_texture *tex,
- GLboolean newTex,
- GLint srcX, GLint srcY,
- GLsizei width, GLsizei height, GLenum intFormat,
- GLenum filter)
-{
- _mesa_BindTexture(tex->Target, tex->TexObj);
- _mesa_TexParameteri(tex->Target, GL_TEXTURE_MIN_FILTER, filter);
- _mesa_TexParameteri(tex->Target, GL_TEXTURE_MAG_FILTER, filter);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-
- /* copy framebuffer image to texture */
- if (newTex) {
- /* create new tex image */
- if (tex->Width == width && tex->Height == height) {
- /* create new tex with framebuffer data */
- _mesa_CopyTexImage2D(tex->Target, 0, tex->IntFormat,
- srcX, srcY, width, height, 0);
- }
- else {
- /* create empty texture */
- _mesa_TexImage2D(tex->Target, 0, tex->IntFormat,
- tex->Width, tex->Height, 0,
- intFormat, GL_UNSIGNED_BYTE, NULL);
- /* load image */
- _mesa_CopyTexSubImage2D(tex->Target, 0,
- 0, 0, srcX, srcY, width, height);
- }
- }
- else {
- /* replace existing tex image */
- _mesa_CopyTexSubImage2D(tex->Target, 0,
- 0, 0, srcX, srcY, width, height);
- }
-}
-
-
-/**
- * Setup/load texture for glDrawPixels.
- */
-static void
-setup_drawpix_texture(struct gl_context *ctx,
- struct temp_texture *tex,
- GLboolean newTex,
- GLenum texIntFormat,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const GLvoid *pixels)
-{
- _mesa_BindTexture(tex->Target, tex->TexObj);
- _mesa_TexParameteri(tex->Target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- _mesa_TexParameteri(tex->Target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-
- /* copy pixel data to texture */
- if (newTex) {
- /* create new tex image */
- if (tex->Width == width && tex->Height == height) {
- /* create new tex and load image data */
- _mesa_TexImage2D(tex->Target, 0, tex->IntFormat,
- tex->Width, tex->Height, 0, format, type, pixels);
- }
- else {
- struct gl_buffer_object *save_unpack_obj = NULL;
-
- _mesa_reference_buffer_object(ctx, &save_unpack_obj,
- ctx->Unpack.BufferObj);
- _mesa_BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
- /* create empty texture */
- _mesa_TexImage2D(tex->Target, 0, tex->IntFormat,
- tex->Width, tex->Height, 0, format, type, NULL);
- if (save_unpack_obj != NULL)
- _mesa_BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB,
- save_unpack_obj->Name);
- /* load image */
- _mesa_TexSubImage2D(tex->Target, 0,
- 0, 0, width, height, format, type, pixels);
- }
- }
- else {
- /* replace existing tex image */
- _mesa_TexSubImage2D(tex->Target, 0,
- 0, 0, width, height, format, type, pixels);
- }
-}
-
-
-
-/**
- * One-time init for drawing depth pixels.
- */
-static void
-init_blit_depth_pixels(struct gl_context *ctx)
-{
- static const char *program =
- "!!ARBfp1.0\n"
- "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n"
- "END \n";
- char program2[200];
- struct blit_state *blit = &ctx->Meta->Blit;
- struct temp_texture *tex = get_temp_texture(ctx);
- const char *texTarget;
-
- assert(blit->DepthFP == 0);
-
- /* replace %s with "RECT" or "2D" */
- assert(strlen(program) + 4 < sizeof(program2));
- if (tex->Target == GL_TEXTURE_RECTANGLE)
- texTarget = "RECT";
- else
- texTarget = "2D";
- _mesa_snprintf(program2, sizeof(program2), program, texTarget);
-
- _mesa_GenPrograms(1, &blit->DepthFP);
- _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, blit->DepthFP);
- _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
- strlen(program2), (const GLubyte *) program2);
-}
-
-
-/**
- * Try to do a glBlitFramebuffer using no-copy texturing.
- * We can do this when the src renderbuffer is actually a texture.
- * But if the src buffer == dst buffer we cannot do this.
- *
- * \return new buffer mask indicating the buffers left to blit using the
- * normal path.
- */
-static GLbitfield
-blitframebuffer_texture(struct gl_context *ctx,
- GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
- GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
- GLbitfield mask, GLenum filter)
-{
- if (mask & GL_COLOR_BUFFER_BIT) {
- const struct gl_framebuffer *drawFb = ctx->DrawBuffer;
- const struct gl_framebuffer *readFb = ctx->ReadBuffer;
- const struct gl_renderbuffer_attachment *drawAtt =
- &drawFb->Attachment[drawFb->_ColorDrawBufferIndexes[0]];
- const struct gl_renderbuffer_attachment *readAtt =
- &readFb->Attachment[readFb->_ColorReadBufferIndex];
-
- if (readAtt && readAtt->Texture) {
- const struct gl_texture_object *texObj = readAtt->Texture;
- const GLuint srcLevel = readAtt->TextureLevel;
- const GLenum minFilterSave = texObj->MinFilter;
- const GLenum magFilterSave = texObj->MagFilter;
- const GLint baseLevelSave = texObj->BaseLevel;
- const GLint maxLevelSave = texObj->MaxLevel;
- const GLenum wrapSSave = texObj->WrapS;
- const GLenum wrapTSave = texObj->WrapT;
- const GLenum target = texObj->Target;
-
- if (drawAtt->Texture == readAtt->Texture) {
- /* Can't use same texture as both the source and dest. We need
- * to handle overlapping blits and besides, some hw may not
- * support this.
- */
- return mask;
- }
-
- if (target != GL_TEXTURE_2D && target != GL_TEXTURE_RECTANGLE_ARB) {
- /* Can't handle other texture types at this time */
- return mask;
- }
-
- /*
- printf("Blit from texture!\n");
- printf(" srcAtt %p dstAtt %p\n", readAtt, drawAtt);
- printf(" srcTex %p dstText %p\n", texObj, drawAtt->Texture);
- */
-
- /* Prepare src texture state */
- _mesa_BindTexture(target, texObj->Name);
- _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter);
- _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter);
- if (target != GL_TEXTURE_RECTANGLE_ARB) {
- _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, srcLevel);
- _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, srcLevel);
- }
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- _mesa_set_enable(ctx, target, GL_TRUE);
-
- /* Prepare vertex data (the VBO was previously created and bound) */
- {
- struct vertex {
- GLfloat x, y, s, t;
- };
- struct vertex verts[4];
- GLfloat s0, t0, s1, t1;
-
- if (target == GL_TEXTURE_2D) {
- const struct gl_texture_image *texImage
- = _mesa_select_tex_image(ctx, texObj, target, srcLevel);
- s0 = srcX0 / (float) texImage->Width;
- s1 = srcX1 / (float) texImage->Width;
- t0 = srcY0 / (float) texImage->Height;
- t1 = srcY1 / (float) texImage->Height;
- }
- else {
- assert(target == GL_TEXTURE_RECTANGLE_ARB);
- s0 = srcX0;
- s1 = srcX1;
- t0 = srcY0;
- t1 = srcY1;
- }
-
- verts[0].x = (GLfloat) dstX0;
- verts[0].y = (GLfloat) dstY0;
- verts[1].x = (GLfloat) dstX1;
- verts[1].y = (GLfloat) dstY0;
- verts[2].x = (GLfloat) dstX1;
- verts[2].y = (GLfloat) dstY1;
- verts[3].x = (GLfloat) dstX0;
- verts[3].y = (GLfloat) dstY1;
-
- verts[0].s = s0;
- verts[0].t = t0;
- verts[1].s = s1;
- verts[1].t = t0;
- verts[2].s = s1;
- verts[2].t = t1;
- verts[3].s = s0;
- verts[3].t = t1;
-
- _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
- }
-
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
- /* Restore texture object state, the texture binding will
- * be restored by _mesa_meta_end().
- */
- _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilterSave);
- _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilterSave);
- if (target != GL_TEXTURE_RECTANGLE_ARB) {
- _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, baseLevelSave);
- _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
- }
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, wrapSSave);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, wrapTSave);
-
- /* Done with color buffer */
- mask &= ~GL_COLOR_BUFFER_BIT;
- }
- }
-
- return mask;
-}
-
-
-/**
- * Meta implementation of ctx->Driver.BlitFramebuffer() in terms
- * of texture mapping and polygon rendering.
- */
-void
-_mesa_meta_BlitFramebuffer(struct gl_context *ctx,
- GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
- GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
- GLbitfield mask, GLenum filter)
-{
- struct blit_state *blit = &ctx->Meta->Blit;
- struct temp_texture *tex = get_temp_texture(ctx);
- const GLsizei maxTexSize = tex->MaxSize;
- const GLint srcX = MIN2(srcX0, srcX1);
- const GLint srcY = MIN2(srcY0, srcY1);
- const GLint srcW = abs(srcX1 - srcX0);
- const GLint srcH = abs(srcY1 - srcY0);
- const GLboolean srcFlipX = srcX1 < srcX0;
- const GLboolean srcFlipY = srcY1 < srcY0;
- struct vertex {
- GLfloat x, y, s, t;
- };
- struct vertex verts[4];
- GLboolean newTex;
-
- if (srcW > maxTexSize || srcH > maxTexSize) {
- /* XXX avoid this fallback */
- _swrast_BlitFramebuffer(ctx, srcX0, srcY0, srcX1, srcY1,
- dstX0, dstY0, dstX1, dstY1, mask, filter);
- return;
- }
-
- if (srcFlipX) {
- GLint tmp = dstX0;
- dstX0 = dstX1;
- dstX1 = tmp;
- }
-
- if (srcFlipY) {
- GLint tmp = dstY0;
- dstY0 = dstY1;
- dstY1 = tmp;
- }
-
- /* only scissor effects blit so save/clear all other relevant state */
- _mesa_meta_begin(ctx, ~META_SCISSOR);
-
- if (blit->ArrayObj == 0) {
- /* one-time setup */
-
- /* create vertex array object */
- _mesa_GenVertexArrays(1, &blit->ArrayObj);
- _mesa_BindVertexArray(blit->ArrayObj);
-
- /* create vertex array buffer */
- _mesa_GenBuffersARB(1, &blit->VBO);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, blit->VBO);
- _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
- NULL, GL_DYNAMIC_DRAW_ARB);
-
- /* setup vertex arrays */
- _mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
- _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
- _mesa_EnableClientState(GL_VERTEX_ARRAY);
- _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
- }
- else {
- _mesa_BindVertexArray(blit->ArrayObj);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, blit->VBO);
- }
-
- /* Try faster, direct texture approach first */
- mask = blitframebuffer_texture(ctx, srcX0, srcY0, srcX1, srcY1,
- dstX0, dstY0, dstX1, dstY1, mask, filter);
- if (mask == 0x0) {
- _mesa_meta_end(ctx);
- return;
- }
-
- /* Continue with "normal" approach which involves copying the src rect
- * into a temporary texture and is "blitted" by drawing a textured quad.
- */
-
- newTex = alloc_texture(tex, srcW, srcH, GL_RGBA);
-
- /* vertex positions/texcoords (after texture allocation!) */
- {
- verts[0].x = (GLfloat) dstX0;
- verts[0].y = (GLfloat) dstY0;
- verts[1].x = (GLfloat) dstX1;
- verts[1].y = (GLfloat) dstY0;
- verts[2].x = (GLfloat) dstX1;
- verts[2].y = (GLfloat) dstY1;
- verts[3].x = (GLfloat) dstX0;
- verts[3].y = (GLfloat) dstY1;
-
- verts[0].s = 0.0F;
- verts[0].t = 0.0F;
- verts[1].s = tex->Sright;
- verts[1].t = 0.0F;
- verts[2].s = tex->Sright;
- verts[2].t = tex->Ttop;
- verts[3].s = 0.0F;
- verts[3].t = tex->Ttop;
-
- /* upload new vertex data */
- _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
- }
-
- _mesa_set_enable(ctx, tex->Target, GL_TRUE);
-
- if (mask & GL_COLOR_BUFFER_BIT) {
- setup_copypix_texture(tex, newTex, srcX, srcY, srcW, srcH,
- GL_RGBA, filter);
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
- mask &= ~GL_COLOR_BUFFER_BIT;
- }
-
- if (mask & GL_DEPTH_BUFFER_BIT) {
- GLuint *tmp = (GLuint *) malloc(srcW * srcH * sizeof(GLuint));
- if (tmp) {
- if (!blit->DepthFP)
- init_blit_depth_pixels(ctx);
-
- /* maybe change tex format here */
- newTex = alloc_texture(tex, srcW, srcH, GL_DEPTH_COMPONENT);
-
- _mesa_ReadPixels(srcX, srcY, srcW, srcH,
- GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, tmp);
-
- setup_drawpix_texture(ctx, tex, newTex, GL_DEPTH_COMPONENT, srcW, srcH,
- GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, tmp);
-
- _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, blit->DepthFP);
- _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_TRUE);
- _mesa_ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
- _mesa_set_enable(ctx, GL_DEPTH_TEST, GL_TRUE);
- _mesa_DepthFunc(GL_ALWAYS);
- _mesa_DepthMask(GL_TRUE);
-
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
- mask &= ~GL_DEPTH_BUFFER_BIT;
-
- free(tmp);
- }
- }
-
- if (mask & GL_STENCIL_BUFFER_BIT) {
- /* XXX can't easily do stencil */
- }
-
- _mesa_set_enable(ctx, tex->Target, GL_FALSE);
-
- _mesa_meta_end(ctx);
-
- if (mask) {
- _swrast_BlitFramebuffer(ctx, srcX0, srcY0, srcX1, srcY1,
- dstX0, dstY0, dstX1, dstY1, mask, filter);
- }
-}
-
-
-/**
- * Meta implementation of ctx->Driver.Clear() in terms of polygon rendering.
- */
-void
-_mesa_meta_Clear(struct gl_context *ctx, GLbitfield buffers)
-{
- struct clear_state *clear = &ctx->Meta->Clear;
- struct vertex {
- GLfloat x, y, z, r, g, b, a;
- };
- struct vertex verts[4];
- /* save all state but scissor, pixel pack/unpack */
- GLbitfield metaSave = META_ALL - META_SCISSOR - META_PIXEL_STORE;
- const GLuint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
-
- if (buffers & BUFFER_BITS_COLOR) {
- /* if clearing color buffers, don't save/restore colormask */
- metaSave -= META_COLOR_MASK;
- }
-
- _mesa_meta_begin(ctx, metaSave);
-
- if (clear->ArrayObj == 0) {
- /* one-time setup */
-
- /* create vertex array object */
- _mesa_GenVertexArrays(1, &clear->ArrayObj);
- _mesa_BindVertexArray(clear->ArrayObj);
-
- /* create vertex array buffer */
- _mesa_GenBuffersARB(1, &clear->VBO);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, clear->VBO);
-
- /* setup vertex arrays */
- _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
- _mesa_ColorPointer(4, GL_FLOAT, sizeof(struct vertex), OFFSET(r));
- _mesa_EnableClientState(GL_VERTEX_ARRAY);
- _mesa_EnableClientState(GL_COLOR_ARRAY);
- }
- else {
- _mesa_BindVertexArray(clear->ArrayObj);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, clear->VBO);
- }
-
- /* GL_COLOR_BUFFER_BIT */
- if (buffers & BUFFER_BITS_COLOR) {
- /* leave colormask, glDrawBuffer state as-is */
- }
- else {
- ASSERT(metaSave & META_COLOR_MASK);
- _mesa_ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
- }
-
- /* GL_DEPTH_BUFFER_BIT */
- if (buffers & BUFFER_BIT_DEPTH) {
- _mesa_set_enable(ctx, GL_DEPTH_TEST, GL_TRUE);
- _mesa_DepthFunc(GL_ALWAYS);
- _mesa_DepthMask(GL_TRUE);
- }
- else {
- assert(!ctx->Depth.Test);
- }
-
- /* GL_STENCIL_BUFFER_BIT */
- if (buffers & BUFFER_BIT_STENCIL) {
- _mesa_set_enable(ctx, GL_STENCIL_TEST, GL_TRUE);
- _mesa_StencilOpSeparate(GL_FRONT_AND_BACK,
- GL_REPLACE, GL_REPLACE, GL_REPLACE);
- _mesa_StencilFuncSeparate(GL_FRONT_AND_BACK, GL_ALWAYS,
- ctx->Stencil.Clear & stencilMax,
- ctx->Stencil.WriteMask[0]);
- }
- else {
- assert(!ctx->Stencil.Enabled);
- }
-
- /* vertex positions/colors */
- {
- const GLfloat x0 = (GLfloat) ctx->DrawBuffer->_Xmin;
- const GLfloat y0 = (GLfloat) ctx->DrawBuffer->_Ymin;
- const GLfloat x1 = (GLfloat) ctx->DrawBuffer->_Xmax;
- const GLfloat y1 = (GLfloat) ctx->DrawBuffer->_Ymax;
- const GLfloat z = invert_z(ctx->Depth.Clear);
- GLuint i;
-
- verts[0].x = x0;
- verts[0].y = y0;
- verts[0].z = z;
- verts[1].x = x1;
- verts[1].y = y0;
- verts[1].z = z;
- verts[2].x = x1;
- verts[2].y = y1;
- verts[2].z = z;
- verts[3].x = x0;
- verts[3].y = y1;
- verts[3].z = z;
-
- /* vertex colors */
- for (i = 0; i < 4; i++) {
- verts[i].r = ctx->Color.ClearColor[0];
- verts[i].g = ctx->Color.ClearColor[1];
- verts[i].b = ctx->Color.ClearColor[2];
- verts[i].a = ctx->Color.ClearColor[3];
- }
-
- /* upload new vertex data */
- _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts,
- GL_DYNAMIC_DRAW_ARB);
- }
-
- /* draw quad */
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
- _mesa_meta_end(ctx);
-}
-
-
-/**
- * Meta implementation of ctx->Driver.CopyPixels() in terms
- * of texture mapping and polygon rendering.
- */
-void
-_mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcX, GLint srcY,
- GLsizei width, GLsizei height,
- GLint dstX, GLint dstY, GLenum type)
-{
- struct copypix_state *copypix = &ctx->Meta->CopyPix;
- struct temp_texture *tex = get_temp_texture(ctx);
- struct vertex {
- GLfloat x, y, z, s, t;
- };
- struct vertex verts[4];
- GLboolean newTex;
- GLenum intFormat = GL_RGBA;
-
- if (type != GL_COLOR ||
- ctx->_ImageTransferState ||
- ctx->Fog.Enabled ||
- width > tex->MaxSize ||
- height > tex->MaxSize) {
- /* XXX avoid this fallback */
- _swrast_CopyPixels(ctx, srcX, srcY, width, height, dstX, dstY, type);
- return;
- }
-
- /* Most GL state applies to glCopyPixels, but a there's a few things
- * we need to override:
- */
- _mesa_meta_begin(ctx, (META_RASTERIZATION |
- META_SHADER |
- META_TEXTURE |
- META_TRANSFORM |
- META_VERTEX |
- META_VIEWPORT));
-
- if (copypix->ArrayObj == 0) {
- /* one-time setup */
-
- /* create vertex array object */
- _mesa_GenVertexArrays(1, &copypix->ArrayObj);
- _mesa_BindVertexArray(copypix->ArrayObj);
-
- /* create vertex array buffer */
- _mesa_GenBuffersARB(1, &copypix->VBO);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, copypix->VBO);
- _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
- NULL, GL_DYNAMIC_DRAW_ARB);
-
- /* setup vertex arrays */
- _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
- _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
- _mesa_EnableClientState(GL_VERTEX_ARRAY);
- _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
- }
- else {
- _mesa_BindVertexArray(copypix->ArrayObj);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, copypix->VBO);
- }
-
- newTex = alloc_texture(tex, width, height, intFormat);
-
- /* vertex positions, texcoords (after texture allocation!) */
- {
- const GLfloat dstX0 = (GLfloat) dstX;
- const GLfloat dstY0 = (GLfloat) dstY;
- const GLfloat dstX1 = dstX + width * ctx->Pixel.ZoomX;
- const GLfloat dstY1 = dstY + height * ctx->Pixel.ZoomY;
- const GLfloat z = invert_z(ctx->Current.RasterPos[2]);
-
- verts[0].x = dstX0;
- verts[0].y = dstY0;
- verts[0].z = z;
- verts[0].s = 0.0F;
- verts[0].t = 0.0F;
- verts[1].x = dstX1;
- verts[1].y = dstY0;
- verts[1].z = z;
- verts[1].s = tex->Sright;
- verts[1].t = 0.0F;
- verts[2].x = dstX1;
- verts[2].y = dstY1;
- verts[2].z = z;
- verts[2].s = tex->Sright;
- verts[2].t = tex->Ttop;
- verts[3].x = dstX0;
- verts[3].y = dstY1;
- verts[3].z = z;
- verts[3].s = 0.0F;
- verts[3].t = tex->Ttop;
-
- /* upload new vertex data */
- _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
- }
-
- /* Alloc/setup texture */
- setup_copypix_texture(tex, newTex, srcX, srcY, width, height,
- GL_RGBA, GL_NEAREST);
-
- _mesa_set_enable(ctx, tex->Target, GL_TRUE);
-
- /* draw textured quad */
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
- _mesa_set_enable(ctx, tex->Target, GL_FALSE);
-
- _mesa_meta_end(ctx);
-}
-
-
-
-/**
- * When the glDrawPixels() image size is greater than the max rectangle
- * texture size we use this function to break the glDrawPixels() image
- * into tiles which fit into the max texture size.
- */
-static void
-tiled_draw_pixels(struct gl_context *ctx,
- GLint tileSize,
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels)
-{
- struct gl_pixelstore_attrib tileUnpack = *unpack;
- GLint i, j;
-
- if (tileUnpack.RowLength == 0)
- tileUnpack.RowLength = width;
-
- for (i = 0; i < width; i += tileSize) {
- const GLint tileWidth = MIN2(tileSize, width - i);
- const GLint tileX = (GLint) (x + i * ctx->Pixel.ZoomX);
-
- tileUnpack.SkipPixels = unpack->SkipPixels + i;
-
- for (j = 0; j < height; j += tileSize) {
- const GLint tileHeight = MIN2(tileSize, height - j);
- const GLint tileY = (GLint) (y + j * ctx->Pixel.ZoomY);
-
- tileUnpack.SkipRows = unpack->SkipRows + j;
-
- _mesa_meta_DrawPixels(ctx, tileX, tileY, tileWidth, tileHeight,
- format, type, &tileUnpack, pixels);
- }
- }
-}
-
-
-/**
- * One-time init for drawing stencil pixels.
- */
-static void
-init_draw_stencil_pixels(struct gl_context *ctx)
-{
- /* This program is run eight times, once for each stencil bit.
- * The stencil values to draw are found in an 8-bit alpha texture.
- * We read the texture/stencil value and test if bit 'b' is set.
- * If the bit is not set, use KIL to kill the fragment.
- * Finally, we use the stencil test to update the stencil buffer.
- *
- * The basic algorithm for checking if a bit is set is:
- * if (is_odd(value / (1 << bit)))
- * result is one (or non-zero).
- * else
- * result is zero.
- * The program parameter contains three values:
- * parm.x = 255 / (1 << bit)
- * parm.y = 0.5
- * parm.z = 0.0
- */
- static const char *program =
- "!!ARBfp1.0\n"
- "PARAM parm = program.local[0]; \n"
- "TEMP t; \n"
- "TEX t, fragment.texcoord[0], texture[0], %s; \n" /* NOTE %s here! */
- "# t = t * 255 / bit \n"
- "MUL t.x, t.a, parm.x; \n"
- "# t = (int) t \n"
- "FRC t.y, t.x; \n"
- "SUB t.x, t.x, t.y; \n"
- "# t = t * 0.5 \n"
- "MUL t.x, t.x, parm.y; \n"
- "# t = fract(t.x) \n"
- "FRC t.x, t.x; # if t.x != 0, then the bit is set \n"
- "# t.x = (t.x == 0 ? 1 : 0) \n"
- "SGE t.x, -t.x, parm.z; \n"
- "KIL -t.x; \n"
- "# for debug only \n"
- "#MOV result.color, t.x; \n"
- "END \n";
- char program2[1000];
- struct drawpix_state *drawpix = &ctx->Meta->DrawPix;
- struct temp_texture *tex = get_temp_texture(ctx);
- const char *texTarget;
-
- assert(drawpix->StencilFP == 0);
-
- /* replace %s with "RECT" or "2D" */
- assert(strlen(program) + 4 < sizeof(program2));
- if (tex->Target == GL_TEXTURE_RECTANGLE)
- texTarget = "RECT";
- else
- texTarget = "2D";
- _mesa_snprintf(program2, sizeof(program2), program, texTarget);
-
- _mesa_GenPrograms(1, &drawpix->StencilFP);
- _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->StencilFP);
- _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
- strlen(program2), (const GLubyte *) program2);
-}
-
-
-/**
- * One-time init for drawing depth pixels.
- */
-static void
-init_draw_depth_pixels(struct gl_context *ctx)
-{
- static const char *program =
- "!!ARBfp1.0\n"
- "PARAM color = program.local[0]; \n"
- "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n"
- "MOV result.color, color; \n"
- "END \n";
- char program2[200];
- struct drawpix_state *drawpix = &ctx->Meta->DrawPix;
- struct temp_texture *tex = get_temp_texture(ctx);
- const char *texTarget;
-
- assert(drawpix->DepthFP == 0);
-
- /* replace %s with "RECT" or "2D" */
- assert(strlen(program) + 4 < sizeof(program2));
- if (tex->Target == GL_TEXTURE_RECTANGLE)
- texTarget = "RECT";
- else
- texTarget = "2D";
- _mesa_snprintf(program2, sizeof(program2), program, texTarget);
-
- _mesa_GenPrograms(1, &drawpix->DepthFP);
- _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->DepthFP);
- _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
- strlen(program2), (const GLubyte *) program2);
-}
-
-
-/**
- * Meta implementation of ctx->Driver.DrawPixels() in terms
- * of texture mapping and polygon rendering.
- */
-void
-_mesa_meta_DrawPixels(struct gl_context *ctx,
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels)
-{
- struct drawpix_state *drawpix = &ctx->Meta->DrawPix;
- struct temp_texture *tex = get_temp_texture(ctx);
- const struct gl_pixelstore_attrib unpackSave = ctx->Unpack;
- const GLuint origStencilMask = ctx->Stencil.WriteMask[0];
- struct vertex {
- GLfloat x, y, z, s, t;
- };
- struct vertex verts[4];
- GLenum texIntFormat;
- GLboolean fallback, newTex;
- GLbitfield metaExtraSave = 0x0;
- GLuint vbo;
-
- /*
- * Determine if we can do the glDrawPixels with texture mapping.
- */
- fallback = GL_FALSE;
- if (ctx->_ImageTransferState ||
- ctx->Fog.Enabled) {
- fallback = GL_TRUE;
- }
-
- if (_mesa_is_color_format(format)) {
- /* use more compact format when possible */
- /* XXX disable special case for GL_LUMINANCE for now to work around
- * apparent i965 driver bug (see bug #23670).
- */
- if (/*format == GL_LUMINANCE ||*/ format == GL_LUMINANCE_ALPHA)
- texIntFormat = format;
- else
- texIntFormat = GL_RGBA;
- }
- else if (_mesa_is_stencil_format(format)) {
- if (ctx->Extensions.ARB_fragment_program &&
- ctx->Pixel.IndexShift == 0 &&
- ctx->Pixel.IndexOffset == 0 &&
- type == GL_UNSIGNED_BYTE) {
- /* We'll store stencil as alpha. This only works for GLubyte
- * image data because of how incoming values are mapped to alpha
- * in [0,1].
- */
- texIntFormat = GL_ALPHA;
- metaExtraSave = (META_COLOR_MASK |
- META_DEPTH_TEST |
- META_SHADER |
- META_STENCIL_TEST);
- }
- else {
- fallback = GL_TRUE;
- }
- }
- else if (_mesa_is_depth_format(format)) {
- if (ctx->Extensions.ARB_depth_texture &&
- ctx->Extensions.ARB_fragment_program) {
- texIntFormat = GL_DEPTH_COMPONENT;
- metaExtraSave = (META_SHADER);
- }
- else {
- fallback = GL_TRUE;
- }
- }
- else {
- fallback = GL_TRUE;
- }
-
- if (fallback) {
- _swrast_DrawPixels(ctx, x, y, width, height,
- format, type, unpack, pixels);
- return;
- }
-
- /*
- * Check image size against max texture size, draw as tiles if needed.
- */
- if (width > tex->MaxSize || height > tex->MaxSize) {
- tiled_draw_pixels(ctx, tex->MaxSize, x, y, width, height,
- format, type, unpack, pixels);
- return;
- }
-
- /* Most GL state applies to glDrawPixels (like blending, stencil, etc),
- * but a there's a few things we need to override:
- */
- _mesa_meta_begin(ctx, (META_RASTERIZATION |
- META_SHADER |
- META_TEXTURE |
- META_TRANSFORM |
- META_VERTEX |
- META_VIEWPORT |
- metaExtraSave));
-
- newTex = alloc_texture(tex, width, height, texIntFormat);
-
- /* vertex positions, texcoords (after texture allocation!) */
- {
- const GLfloat x0 = (GLfloat) x;
- const GLfloat y0 = (GLfloat) y;
- const GLfloat x1 = x + width * ctx->Pixel.ZoomX;
- const GLfloat y1 = y + height * ctx->Pixel.ZoomY;
- const GLfloat z = invert_z(ctx->Current.RasterPos[2]);
-
- verts[0].x = x0;
- verts[0].y = y0;
- verts[0].z = z;
- verts[0].s = 0.0F;
- verts[0].t = 0.0F;
- verts[1].x = x1;
- verts[1].y = y0;
- verts[1].z = z;
- verts[1].s = tex->Sright;
- verts[1].t = 0.0F;
- verts[2].x = x1;
- verts[2].y = y1;
- verts[2].z = z;
- verts[2].s = tex->Sright;
- verts[2].t = tex->Ttop;
- verts[3].x = x0;
- verts[3].y = y1;
- verts[3].z = z;
- verts[3].s = 0.0F;
- verts[3].t = tex->Ttop;
- }
-
- if (drawpix->ArrayObj == 0) {
- /* one-time setup: create vertex array object */
- _mesa_GenVertexArrays(1, &drawpix->ArrayObj);
- }
- _mesa_BindVertexArray(drawpix->ArrayObj);
-
- /* create vertex array buffer */
- _mesa_GenBuffersARB(1, &vbo);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
- _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
- verts, GL_DYNAMIC_DRAW_ARB);
-
- /* setup vertex arrays */
- _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
- _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
- _mesa_EnableClientState(GL_VERTEX_ARRAY);
- _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- /* set given unpack params */
- ctx->Unpack = *unpack;
-
- _mesa_set_enable(ctx, tex->Target, GL_TRUE);
-
- if (_mesa_is_stencil_format(format)) {
- /* Drawing stencil */
- GLint bit;
-
- if (!drawpix->StencilFP)
- init_draw_stencil_pixels(ctx);
-
- setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height,
- GL_ALPHA, type, pixels);
-
- _mesa_ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-
- _mesa_set_enable(ctx, GL_STENCIL_TEST, GL_TRUE);
-
- /* set all stencil bits to 0 */
- _mesa_StencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
- _mesa_StencilFunc(GL_ALWAYS, 0, 255);
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
- /* set stencil bits to 1 where needed */
- _mesa_StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
-
- _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->StencilFP);
- _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_TRUE);
-
- for (bit = 0; bit < ctx->DrawBuffer->Visual.stencilBits; bit++) {
- const GLuint mask = 1 << bit;
- if (mask & origStencilMask) {
- _mesa_StencilFunc(GL_ALWAYS, mask, mask);
- _mesa_StencilMask(mask);
-
- _mesa_ProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0,
- 255.0 / mask, 0.5, 0.0, 0.0);
-
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
- }
- }
- }
- else if (_mesa_is_depth_format(format)) {
- /* Drawing depth */
- if (!drawpix->DepthFP)
- init_draw_depth_pixels(ctx);
-
- _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->DepthFP);
- _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_TRUE);
-
- /* polygon color = current raster color */
- _mesa_ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0,
- ctx->Current.RasterColor);
-
- setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height,
- format, type, pixels);
-
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
- }
- else {
- /* Drawing RGBA */
- setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height,
- format, type, pixels);
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
- }
-
- _mesa_set_enable(ctx, tex->Target, GL_FALSE);
-
- _mesa_DeleteBuffersARB(1, &vbo);
-
- /* restore unpack params */
- ctx->Unpack = unpackSave;
-
- _mesa_meta_end(ctx);
-}
-
-static GLboolean
-alpha_test_raster_color(struct gl_context *ctx)
-{
- GLfloat alpha = ctx->Current.RasterColor[ACOMP];
- GLfloat ref = ctx->Color.AlphaRef;
-
- switch (ctx->Color.AlphaFunc) {
- case GL_NEVER:
- return GL_FALSE;
- case GL_LESS:
- return alpha < ref;
- case GL_EQUAL:
- return alpha == ref;
- case GL_LEQUAL:
- return alpha <= ref;
- case GL_GREATER:
- return alpha > ref;
- case GL_NOTEQUAL:
- return alpha != ref;
- case GL_GEQUAL:
- return alpha >= ref;
- case GL_ALWAYS:
- return GL_TRUE;
- default:
- assert(0);
- return GL_FALSE;
- }
-}
-
-/**
- * Do glBitmap with a alpha texture quad. Use the alpha test to cull
- * the 'off' bits. A bitmap cache as in the gallium/mesa state
- * tracker would improve performance a lot.
- */
-void
-_mesa_meta_Bitmap(struct gl_context *ctx,
- GLint x, GLint y, GLsizei width, GLsizei height,
- const struct gl_pixelstore_attrib *unpack,
- const GLubyte *bitmap1)
-{
- struct bitmap_state *bitmap = &ctx->Meta->Bitmap;
- struct temp_texture *tex = get_bitmap_temp_texture(ctx);
- const GLenum texIntFormat = GL_ALPHA;
- const struct gl_pixelstore_attrib unpackSave = *unpack;
- GLubyte fg, bg;
- struct vertex {
- GLfloat x, y, z, s, t, r, g, b, a;
- };
- struct vertex verts[4];
- GLboolean newTex;
- GLubyte *bitmap8;
-
- /*
- * Check if swrast fallback is needed.
- */
- if (ctx->_ImageTransferState ||
- ctx->FragmentProgram._Enabled ||
- ctx->Fog.Enabled ||
- ctx->Texture._EnabledUnits ||
- width > tex->MaxSize ||
- height > tex->MaxSize) {
- _swrast_Bitmap(ctx, x, y, width, height, unpack, bitmap1);
- return;
- }
-
- if (ctx->Color.AlphaEnabled && !alpha_test_raster_color(ctx))
- return;
-
- /* Most GL state applies to glBitmap (like blending, stencil, etc),
- * but a there's a few things we need to override:
- */
- _mesa_meta_begin(ctx, (META_ALPHA_TEST |
- META_PIXEL_STORE |
- META_RASTERIZATION |
- META_SHADER |
- META_TEXTURE |
- META_TRANSFORM |
- META_VERTEX |
- META_VIEWPORT));
-
- if (bitmap->ArrayObj == 0) {
- /* one-time setup */
-
- /* create vertex array object */
- _mesa_GenVertexArraysAPPLE(1, &bitmap->ArrayObj);
- _mesa_BindVertexArrayAPPLE(bitmap->ArrayObj);
-
- /* create vertex array buffer */
- _mesa_GenBuffersARB(1, &bitmap->VBO);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, bitmap->VBO);
- _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
- NULL, GL_DYNAMIC_DRAW_ARB);
-
- /* setup vertex arrays */
- _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
- _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
- _mesa_ColorPointer(4, GL_FLOAT, sizeof(struct vertex), OFFSET(r));
- _mesa_EnableClientState(GL_VERTEX_ARRAY);
- _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
- _mesa_EnableClientState(GL_COLOR_ARRAY);
- }
- else {
- _mesa_BindVertexArray(bitmap->ArrayObj);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, bitmap->VBO);
- }
-
- newTex = alloc_texture(tex, width, height, texIntFormat);
-
- /* vertex positions, texcoords, colors (after texture allocation!) */
- {
- const GLfloat x0 = (GLfloat) x;
- const GLfloat y0 = (GLfloat) y;
- const GLfloat x1 = (GLfloat) (x + width);
- const GLfloat y1 = (GLfloat) (y + height);
- const GLfloat z = invert_z(ctx->Current.RasterPos[2]);
- GLuint i;
-
- verts[0].x = x0;
- verts[0].y = y0;
- verts[0].z = z;
- verts[0].s = 0.0F;
- verts[0].t = 0.0F;
- verts[1].x = x1;
- verts[1].y = y0;
- verts[1].z = z;
- verts[1].s = tex->Sright;
- verts[1].t = 0.0F;
- verts[2].x = x1;
- verts[2].y = y1;
- verts[2].z = z;
- verts[2].s = tex->Sright;
- verts[2].t = tex->Ttop;
- verts[3].x = x0;
- verts[3].y = y1;
- verts[3].z = z;
- verts[3].s = 0.0F;
- verts[3].t = tex->Ttop;
-
- for (i = 0; i < 4; i++) {
- verts[i].r = ctx->Current.RasterColor[0];
- verts[i].g = ctx->Current.RasterColor[1];
- verts[i].b = ctx->Current.RasterColor[2];
- verts[i].a = ctx->Current.RasterColor[3];
- }
-
- /* upload new vertex data */
- _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
- }
-
- /* choose different foreground/background alpha values */
- CLAMPED_FLOAT_TO_UBYTE(fg, ctx->Current.RasterColor[ACOMP]);
- bg = (fg > 127 ? 0 : 255);
-
- bitmap1 = _mesa_map_pbo_source(ctx, &unpackSave, bitmap1);
- if (!bitmap1) {
- _mesa_meta_end(ctx);
- return;
- }
-
- bitmap8 = (GLubyte *) malloc(width * height);
- if (bitmap8) {
- memset(bitmap8, bg, width * height);
- _mesa_expand_bitmap(width, height, &unpackSave, bitmap1,
- bitmap8, width, fg);
-
- _mesa_set_enable(ctx, tex->Target, GL_TRUE);
-
- _mesa_set_enable(ctx, GL_ALPHA_TEST, GL_TRUE);
- _mesa_AlphaFunc(GL_NOTEQUAL, UBYTE_TO_FLOAT(bg));
-
- setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height,
- GL_ALPHA, GL_UNSIGNED_BYTE, bitmap8);
-
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
- _mesa_set_enable(ctx, tex->Target, GL_FALSE);
-
- free(bitmap8);
- }
-
- _mesa_unmap_pbo_source(ctx, &unpackSave);
-
- _mesa_meta_end(ctx);
-}
-
-
-/**
- * Check if the call to _mesa_meta_GenerateMipmap() will require a
- * software fallback. The fallback path will require that the texture
- * images are mapped.
- * \return GL_TRUE if a fallback is needed, GL_FALSE otherwise
- */
-GLboolean
-_mesa_meta_check_generate_mipmap_fallback(struct gl_context *ctx, GLenum target,
- struct gl_texture_object *texObj)
-{
- const GLuint fboSave = ctx->DrawBuffer->Name;
- struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap;
- struct gl_texture_image *baseImage;
- GLuint srcLevel;
- GLenum status;
-
- /* check for fallbacks */
- if (!ctx->Extensions.EXT_framebuffer_object ||
- target == GL_TEXTURE_3D) {
- return GL_TRUE;
- }
-
- srcLevel = texObj->BaseLevel;
- baseImage = _mesa_select_tex_image(ctx, texObj, target, srcLevel);
- if (!baseImage || _mesa_is_format_compressed(baseImage->TexFormat)) {
- return GL_TRUE;
- }
-
- /*
- * Test that we can actually render in the texture's format.
- */
- if (!mipmap->FBO)
- _mesa_GenFramebuffersEXT(1, &mipmap->FBO);
- _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mipmap->FBO);
-
- if (target == GL_TEXTURE_1D) {
- _mesa_FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT,
- GL_COLOR_ATTACHMENT0_EXT,
- target, texObj->Name, srcLevel);
- }
-#if 0
- /* other work is needed to enable 3D mipmap generation */
- else if (target == GL_TEXTURE_3D) {
- GLint zoffset = 0;
- _mesa_FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT,
- GL_COLOR_ATTACHMENT0_EXT,
- target, texObj->Name, srcLevel, zoffset);
- }
-#endif
- else {
- /* 2D / cube */
- _mesa_FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
- GL_COLOR_ATTACHMENT0_EXT,
- target, texObj->Name, srcLevel);
- }
-
- status = _mesa_CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
-
- _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSave);
-
- if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-
-/**
- * Called via ctx->Driver.GenerateMipmap()
- * Note: texture borders and 3D texture support not yet complete.
- */
-void
-_mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
- struct gl_texture_object *texObj)
-{
- struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap;
- struct vertex {
- GLfloat x, y, s, t, r;
- };
- struct vertex verts[4];
- const GLuint baseLevel = texObj->BaseLevel;
- const GLuint maxLevel = texObj->MaxLevel;
- const GLenum minFilterSave = texObj->MinFilter;
- const GLenum magFilterSave = texObj->MagFilter;
- const GLint maxLevelSave = texObj->MaxLevel;
- const GLboolean genMipmapSave = texObj->GenerateMipmap;
- const GLenum wrapSSave = texObj->WrapS;
- const GLenum wrapTSave = texObj->WrapT;
- const GLenum wrapRSave = texObj->WrapR;
- const GLuint fboSave = ctx->DrawBuffer->Name;
- const GLuint original_active_unit = ctx->Texture.CurrentUnit;
- GLenum faceTarget;
- GLuint dstLevel;
- GLuint border = 0;
-
- if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, texObj)) {
- _mesa_generate_mipmap(ctx, target, texObj);
- return;
- }
-
- if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
- target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) {
- faceTarget = target;
- target = GL_TEXTURE_CUBE_MAP;
- }
- else {
- faceTarget = target;
- }
-
- _mesa_meta_begin(ctx, META_ALL);
-
- if (original_active_unit != 0)
- _mesa_BindTexture(target, texObj->Name);
-
- if (mipmap->ArrayObj == 0) {
- /* one-time setup */
-
- /* create vertex array object */
- _mesa_GenVertexArraysAPPLE(1, &mipmap->ArrayObj);
- _mesa_BindVertexArrayAPPLE(mipmap->ArrayObj);
-
- /* create vertex array buffer */
- _mesa_GenBuffersARB(1, &mipmap->VBO);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, mipmap->VBO);
- _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
- NULL, GL_DYNAMIC_DRAW_ARB);
-
- /* setup vertex arrays */
- _mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
- _mesa_TexCoordPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
- _mesa_EnableClientState(GL_VERTEX_ARRAY);
- _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
- }
- else {
- _mesa_BindVertexArray(mipmap->ArrayObj);
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, mipmap->VBO);
- }
-
- if (!mipmap->FBO) {
- _mesa_GenFramebuffersEXT(1, &mipmap->FBO);
- }
- _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mipmap->FBO);
-
- _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- _mesa_TexParameteri(target, GL_GENERATE_MIPMAP, GL_FALSE);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
-
- _mesa_set_enable(ctx, target, GL_TRUE);
-
- /* setup texcoords once (XXX what about border?) */
- switch (faceTarget) {
- case GL_TEXTURE_1D:
- case GL_TEXTURE_2D:
- verts[0].s = 0.0F;
- verts[0].t = 0.0F;
- verts[0].r = 0.0F;
- verts[1].s = 1.0F;
- verts[1].t = 0.0F;
- verts[1].r = 0.0F;
- verts[2].s = 1.0F;
- verts[2].t = 1.0F;
- verts[2].r = 0.0F;
- verts[3].s = 0.0F;
- verts[3].t = 1.0F;
- verts[3].r = 0.0F;
- break;
- case GL_TEXTURE_3D:
- abort();
- break;
- default:
- /* cube face */
- {
- static const GLfloat st[4][2] = {
- {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}
- };
- GLuint i;
-
- /* loop over quad verts */
- for (i = 0; i < 4; i++) {
- /* Compute sc = +/-scale and tc = +/-scale.
- * Not +/-1 to avoid cube face selection ambiguity near the edges,
- * though that can still sometimes happen with this scale factor...
- */
- const GLfloat scale = 0.9999f;
- const GLfloat sc = (2.0f * st[i][0] - 1.0f) * scale;
- const GLfloat tc = (2.0f * st[i][1] - 1.0f) * scale;
-
- switch (faceTarget) {
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- verts[i].s = 1.0f;
- verts[i].t = -tc;
- verts[i].r = -sc;
- break;
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- verts[i].s = -1.0f;
- verts[i].t = -tc;
- verts[i].r = sc;
- break;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- verts[i].s = sc;
- verts[i].t = 1.0f;
- verts[i].r = tc;
- break;
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- verts[i].s = sc;
- verts[i].t = -1.0f;
- verts[i].r = -tc;
- break;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- verts[i].s = sc;
- verts[i].t = -tc;
- verts[i].r = 1.0f;
- break;
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- verts[i].s = -sc;
- verts[i].t = -tc;
- verts[i].r = -1.0f;
- break;
- default:
- assert(0);
- }
- }
- }
- }
-
- _mesa_set_enable(ctx, target, GL_TRUE);
-
- /* setup vertex positions */
- {
- verts[0].x = 0.0F;
- verts[0].y = 0.0F;
- verts[1].x = 1.0F;
- verts[1].y = 0.0F;
- verts[2].x = 1.0F;
- verts[2].y = 1.0F;
- verts[3].x = 0.0F;
- verts[3].y = 1.0F;
-
- /* upload new vertex data */
- _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
- }
-
- /* setup projection matrix */
- _mesa_MatrixMode(GL_PROJECTION);
- _mesa_LoadIdentity();
- _mesa_Ortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
-
- /* texture is already locked, unlock now */
- _mesa_unlock_texture(ctx, texObj);
-
- for (dstLevel = baseLevel + 1; dstLevel <= maxLevel; dstLevel++) {
- const struct gl_texture_image *srcImage;
- const GLuint srcLevel = dstLevel - 1;
- GLsizei srcWidth, srcHeight, srcDepth;
- GLsizei dstWidth, dstHeight, dstDepth;
- GLenum status;
-
- srcImage = _mesa_select_tex_image(ctx, texObj, faceTarget, srcLevel);
- assert(srcImage->Border == 0); /* XXX we can fix this */
-
- /* src size w/out border */
- srcWidth = srcImage->Width - 2 * border;
- srcHeight = srcImage->Height - 2 * border;
- srcDepth = srcImage->Depth - 2 * border;
-
- /* new dst size w/ border */
- dstWidth = MAX2(1, srcWidth / 2) + 2 * border;
- dstHeight = MAX2(1, srcHeight / 2) + 2 * border;
- dstDepth = MAX2(1, srcDepth / 2) + 2 * border;
-
- if (dstWidth == srcImage->Width &&
- dstHeight == srcImage->Height &&
- dstDepth == srcImage->Depth) {
- /* all done */
- break;
- }
-
- /* Set MaxLevel large enough to hold the new level when we allocate it */
- _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, dstLevel);
-
- /* Create empty dest image */
- if (target == GL_TEXTURE_1D) {
- _mesa_TexImage1D(target, dstLevel, srcImage->InternalFormat,
- dstWidth, border,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- }
- else if (target == GL_TEXTURE_3D) {
- _mesa_TexImage3D(target, dstLevel, srcImage->InternalFormat,
- dstWidth, dstHeight, dstDepth, border,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- }
- else {
- /* 2D or cube */
- _mesa_TexImage2D(faceTarget, dstLevel, srcImage->InternalFormat,
- dstWidth, dstHeight, border,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-
- if (target == GL_TEXTURE_CUBE_MAP) {
- /* If texturing from a cube, we need to make sure all src faces
- * have been defined (even if we're not sampling from them.)
- * Otherwise the texture object will be 'incomplete' and
- * texturing from it will not be allowed.
- */
- GLuint face;
- for (face = 0; face < 6; face++) {
- if (!texObj->Image[face][srcLevel] ||
- texObj->Image[face][srcLevel]->Width != srcWidth) {
- _mesa_TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face,
- srcLevel, srcImage->InternalFormat,
- srcWidth, srcHeight, border,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- }
- }
- }
- }
-
- /* limit minification to src level */
- _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, srcLevel);
-
- /* Set to draw into the current dstLevel */
- if (target == GL_TEXTURE_1D) {
- _mesa_FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT,
- GL_COLOR_ATTACHMENT0_EXT,
- target,
- texObj->Name,
- dstLevel);
- }
- else if (target == GL_TEXTURE_3D) {
- GLint zoffset = 0; /* XXX unfinished */
- _mesa_FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT,
- GL_COLOR_ATTACHMENT0_EXT,
- target,
- texObj->Name,
- dstLevel, zoffset);
- }
- else {
- /* 2D / cube */
- _mesa_FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
- GL_COLOR_ATTACHMENT0_EXT,
- faceTarget,
- texObj->Name,
- dstLevel);
- }
-
- _mesa_DrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
-
- /* sanity check */
- status = _mesa_CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
- if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- abort();
- break;
- }
-
- assert(dstWidth == ctx->DrawBuffer->Width);
- assert(dstHeight == ctx->DrawBuffer->Height);
-
- /* setup viewport */
- _mesa_set_viewport(ctx, 0, 0, dstWidth, dstHeight);
-
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
- }
-
- _mesa_lock_texture(ctx, texObj); /* relock */
-
- _mesa_meta_end(ctx);
-
- _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilterSave);
- _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilterSave);
- _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
- _mesa_TexParameteri(target, GL_GENERATE_MIPMAP, genMipmapSave);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, wrapSSave);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, wrapTSave);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, wrapRSave);
-
- _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSave);
-}
-
-
-/**
- * Determine the GL data type to use for the temporary image read with
- * ReadPixels() and passed to Tex[Sub]Image().
- */
-static GLenum
-get_temp_image_type(struct gl_context *ctx, GLenum baseFormat)
-{
- switch (baseFormat) {
- case GL_RGBA:
- case GL_RGB:
- case GL_ALPHA:
- case GL_LUMINANCE:
- case GL_LUMINANCE_ALPHA:
- case GL_INTENSITY:
- if (ctx->DrawBuffer->Visual.redBits <= 8)
- return GL_UNSIGNED_BYTE;
- else if (ctx->DrawBuffer->Visual.redBits <= 8)
- return GL_UNSIGNED_SHORT;
- else
- return GL_FLOAT;
- case GL_DEPTH_COMPONENT:
- return GL_UNSIGNED_INT;
- case GL_DEPTH_STENCIL:
- return GL_UNSIGNED_INT_24_8;
- default:
- _mesa_problem(ctx, "Unexpected format in get_temp_image_type()");
- return 0;
- }
-}
-
-
-/**
- * Helper for _mesa_meta_CopyTexImage1/2D() functions.
- * Have to be careful with locking and meta state for pixel transfer.
- */
-static void
-copy_tex_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
- GLenum internalFormat, GLint x, GLint y,
- GLsizei width, GLsizei height, GLint border)
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- GLenum format, type;
- GLint bpp;
- void *buf;
-
- texObj = _mesa_get_current_tex_object(ctx, target);
- texImage = _mesa_get_tex_image(ctx, texObj, target, level);
-
- /* Choose format/type for temporary image buffer */
- format = _mesa_base_tex_format(ctx, internalFormat);
- type = get_temp_image_type(ctx, format);
- bpp = _mesa_bytes_per_pixel(format, type);
- if (bpp <= 0) {
- _mesa_problem(ctx, "Bad bpp in meta copy_tex_image()");
- return;
- }
-
- /*
- * Alloc image buffer (XXX could use a PBO)
- */
- buf = malloc(width * height * bpp);
- if (!buf) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims);
- return;
- }
-
- _mesa_unlock_texture(ctx, texObj); /* need to unlock first */
-
- /*
- * Read image from framebuffer (disable pixel transfer ops)
- */
- _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER);
- ctx->Driver.ReadPixels(ctx, x, y, width, height,
- format, type, &ctx->Pack, buf);
- _mesa_meta_end(ctx);
-
- if (texImage->Data) {
- ctx->Driver.FreeTexImageData(ctx, texImage);
- }
-
- /* The texture's format was already chosen in _mesa_CopyTexImage() */
- ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
-
- /*
- * Store texture data (with pixel transfer ops)
- */
- _mesa_meta_begin(ctx, META_PIXEL_STORE);
-
- _mesa_update_state(ctx); /* to update pixel transfer state */
-
- if (target == GL_TEXTURE_1D) {
- ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
- width, border, format, type,
- buf, &ctx->Unpack, texObj, texImage);
- }
- else {
- ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
- width, height, border, format, type,
- buf, &ctx->Unpack, texObj, texImage);
- }
- _mesa_meta_end(ctx);
-
- _mesa_lock_texture(ctx, texObj); /* re-lock */
-
- free(buf);
-}
-
-
-void
-_mesa_meta_CopyTexImage1D(struct gl_context *ctx, GLenum target, GLint level,
- GLenum internalFormat, GLint x, GLint y,
- GLsizei width, GLint border)
-{
- copy_tex_image(ctx, 1, target, level, internalFormat, x, y,
- width, 1, border);
-}
-
-
-void
-_mesa_meta_CopyTexImage2D(struct gl_context *ctx, GLenum target, GLint level,
- GLenum internalFormat, GLint x, GLint y,
- GLsizei width, GLsizei height, GLint border)
-{
- copy_tex_image(ctx, 2, target, level, internalFormat, x, y,
- width, height, border);
-}
-
-
-
-/**
- * Helper for _mesa_meta_CopyTexSubImage1/2/3D() functions.
- * Have to be careful with locking and meta state for pixel transfer.
- */
-static void
-copy_tex_sub_image(struct gl_context *ctx,
- GLuint dims, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint x, GLint y,
- GLsizei width, GLsizei height)
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- GLenum format, type;
- GLint bpp;
- void *buf;
-
- texObj = _mesa_get_current_tex_object(ctx, target);
- texImage = _mesa_select_tex_image(ctx, texObj, target, level);
-
- /* Choose format/type for temporary image buffer */
- format = _mesa_get_format_base_format(texImage->TexFormat);
- type = get_temp_image_type(ctx, format);
- bpp = _mesa_bytes_per_pixel(format, type);
- if (bpp <= 0) {
- _mesa_problem(ctx, "Bad bpp in meta copy_tex_sub_image()");
- return;
- }
-
- /*
- * Alloc image buffer (XXX could use a PBO)
- */
- buf = malloc(width * height * bpp);
- if (!buf) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage%uD", dims);
- return;
- }
-
- _mesa_unlock_texture(ctx, texObj); /* need to unlock first */
-
- /*
- * Read image from framebuffer (disable pixel transfer ops)
- */
- _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER);
- ctx->Driver.ReadPixels(ctx, x, y, width, height,
- format, type, &ctx->Pack, buf);
- _mesa_meta_end(ctx);
-
- _mesa_update_state(ctx); /* to update pixel transfer state */
-
- /*
- * Store texture data (with pixel transfer ops)
- */
- _mesa_meta_begin(ctx, META_PIXEL_STORE);
- if (target == GL_TEXTURE_1D) {
- ctx->Driver.TexSubImage1D(ctx, target, level, xoffset,
- width, format, type, buf,
- &ctx->Unpack, texObj, texImage);
- }
- else if (target == GL_TEXTURE_3D) {
- ctx->Driver.TexSubImage3D(ctx, target, level, xoffset, yoffset, zoffset,
- width, height, 1, format, type, buf,
- &ctx->Unpack, texObj, texImage);
- }
- else {
- ctx->Driver.TexSubImage2D(ctx, target, level, xoffset, yoffset,
- width, height, format, type, buf,
- &ctx->Unpack, texObj, texImage);
- }
- _mesa_meta_end(ctx);
-
- _mesa_lock_texture(ctx, texObj); /* re-lock */
-
- free(buf);
-}
-
-
-void
-_mesa_meta_CopyTexSubImage1D(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset,
- GLint x, GLint y, GLsizei width)
-{
- copy_tex_sub_image(ctx, 1, target, level, xoffset, 0, 0,
- x, y, width, 1);
-}
-
-
-void
-_mesa_meta_CopyTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLint x, GLint y,
- GLsizei width, GLsizei height)
-{
- copy_tex_sub_image(ctx, 2, target, level, xoffset, yoffset, 0,
- x, y, width, height);
-}
-
-
-void
-_mesa_meta_CopyTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint x, GLint y,
- GLsizei width, GLsizei height)
-{
- copy_tex_sub_image(ctx, 3, target, level, xoffset, yoffset, zoffset,
- x, y, width, height);
-}
-
-
-void
-_mesa_meta_CopyColorTable(struct gl_context *ctx,
- GLenum target, GLenum internalformat,
- GLint x, GLint y, GLsizei width)
-{
- GLfloat *buf;
-
- buf = (GLfloat *) malloc(width * 4 * sizeof(GLfloat));
- if (!buf) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyColorTable");
- return;
- }
-
- /*
- * Read image from framebuffer (disable pixel transfer ops)
- */
- _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER);
- ctx->Driver.ReadPixels(ctx, x, y, width, 1,
- GL_RGBA, GL_FLOAT, &ctx->Pack, buf);
-
- _mesa_ColorTable(target, internalformat, width, GL_RGBA, GL_FLOAT, buf);
-
- _mesa_meta_end(ctx);
-
- free(buf);
-}
-
-
-void
-_mesa_meta_CopyColorSubTable(struct gl_context *ctx,GLenum target, GLsizei start,
- GLint x, GLint y, GLsizei width)
-{
- GLfloat *buf;
-
- buf = (GLfloat *) malloc(width * 4 * sizeof(GLfloat));
- if (!buf) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyColorSubTable");
- return;
- }
-
- /*
- * Read image from framebuffer (disable pixel transfer ops)
- */
- _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER);
- ctx->Driver.ReadPixels(ctx, x, y, width, 1,
- GL_RGBA, GL_FLOAT, &ctx->Pack, buf);
-
- _mesa_ColorSubTable(target, start, width, GL_RGBA, GL_FLOAT, buf);
-
- _mesa_meta_end(ctx);
-
- free(buf);
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.6
+ *
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Meta operations. Some GL operations can be expressed in terms of
+ * other GL operations. For example, glBlitFramebuffer() can be done
+ * with texture mapping and glClear() can be done with polygon rendering.
+ *
+ * \author Brian Paul
+ */
+
+
+#include "main/glheader.h"
+#include "main/mtypes.h"
+#include "main/imports.h"
+#include "main/arbprogram.h"
+#include "main/arrayobj.h"
+#include "main/blend.h"
+#include "main/bufferobj.h"
+#include "main/buffers.h"
+#include "main/colortab.h"
+#include "main/depth.h"
+#include "main/enable.h"
+#include "main/fbobject.h"
+#include "main/formats.h"
+#include "main/image.h"
+#include "main/macros.h"
+#include "main/matrix.h"
+#include "main/mipmap.h"
+#include "main/pbo.h"
+#include "main/polygon.h"
+#include "main/readpix.h"
+#include "main/scissor.h"
+#include "main/shaderapi.h"
+#include "main/shaderobj.h"
+#include "main/state.h"
+#include "main/stencil.h"
+#include "main/texobj.h"
+#include "main/texenv.h"
+#include "main/teximage.h"
+#include "main/texparam.h"
+#include "main/texstate.h"
+#include "main/varray.h"
+#include "main/viewport.h"
+#include "program/program.h"
+#include "swrast/swrast.h"
+#include "drivers/common/meta.h"
+
+
+/** Return offset in bytes of the field within a vertex struct */
+#define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD))
+
+
+/**
+ * Flags passed to _mesa_meta_begin().
+ */
+/*@{*/
+#define META_ALL ~0x0
+#define META_ALPHA_TEST 0x1
+#define META_BLEND 0x2 /**< includes logicop */
+#define META_COLOR_MASK 0x4
+#define META_DEPTH_TEST 0x8
+#define META_FOG 0x10
+#define META_PIXEL_STORE 0x20
+#define META_PIXEL_TRANSFER 0x40
+#define META_RASTERIZATION 0x80
+#define META_SCISSOR 0x100
+#define META_SHADER 0x200
+#define META_STENCIL_TEST 0x400
+#define META_TRANSFORM 0x800 /**< modelview, projection, clip planes */
+#define META_TEXTURE 0x1000
+#define META_VERTEX 0x2000
+#define META_VIEWPORT 0x4000
+/*@}*/
+
+
+/**
+ * State which we may save/restore across meta ops.
+ * XXX this may be incomplete...
+ */
+struct save_state
+{
+ GLbitfield SavedState; /**< bitmask of META_* flags */
+
+ /** META_ALPHA_TEST */
+ GLboolean AlphaEnabled;
+ GLenum AlphaFunc;
+ GLclampf AlphaRef;
+
+ /** META_BLEND */
+ GLbitfield BlendEnabled;
+ GLboolean ColorLogicOpEnabled;
+
+ /** META_COLOR_MASK */
+ GLubyte ColorMask[MAX_DRAW_BUFFERS][4];
+
+ /** META_DEPTH_TEST */
+ struct gl_depthbuffer_attrib Depth;
+
+ /** META_FOG */
+ GLboolean Fog;
+
+ /** META_PIXEL_STORE */
+ struct gl_pixelstore_attrib Pack, Unpack;
+
+ /** META_PIXEL_TRANSFER */
+ GLfloat RedBias, RedScale;
+ GLfloat GreenBias, GreenScale;
+ GLfloat BlueBias, BlueScale;
+ GLfloat AlphaBias, AlphaScale;
+ GLfloat DepthBias, DepthScale;
+ GLboolean MapColorFlag;
+
+ /** META_RASTERIZATION */
+ GLenum FrontPolygonMode, BackPolygonMode;
+ GLboolean PolygonOffset;
+ GLboolean PolygonSmooth;
+ GLboolean PolygonStipple;
+ GLboolean PolygonCull;
+
+ /** META_SCISSOR */
+ struct gl_scissor_attrib Scissor;
+
+ /** META_SHADER */
+ GLboolean VertexProgramEnabled;
+ struct gl_vertex_program *VertexProgram;
+ GLboolean FragmentProgramEnabled;
+ struct gl_fragment_program *FragmentProgram;
+ struct gl_shader_program *VertexShader;
+ struct gl_shader_program *GeometryShader;
+ struct gl_shader_program *FragmentShader;
+ struct gl_shader_program *ActiveShader;
+
+ /** META_STENCIL_TEST */
+ struct gl_stencil_attrib Stencil;
+
+ /** META_TRANSFORM */
+ GLenum MatrixMode;
+ GLfloat ModelviewMatrix[16];
+ GLfloat ProjectionMatrix[16];
+ GLfloat TextureMatrix[16];
+ GLbitfield ClipPlanesEnabled;
+
+ /** META_TEXTURE */
+ GLuint ActiveUnit;
+ GLuint ClientActiveUnit;
+ /** for unit[0] only */
+ struct gl_texture_object *CurrentTexture[NUM_TEXTURE_TARGETS];
+ /** mask of TEXTURE_2D_BIT, etc */
+ GLbitfield TexEnabled[MAX_TEXTURE_UNITS];
+ GLbitfield TexGenEnabled[MAX_TEXTURE_UNITS];
+ GLuint EnvMode; /* unit[0] only */
+
+ /** META_VERTEX */
+ struct gl_array_object *ArrayObj;
+ struct gl_buffer_object *ArrayBufferObj;
+
+ /** META_VIEWPORT */
+ GLint ViewportX, ViewportY, ViewportW, ViewportH;
+ GLclampd DepthNear, DepthFar;
+
+ /** Miscellaneous (always disabled) */
+ GLboolean Lighting;
+};
+
+
+/**
+ * Temporary texture used for glBlitFramebuffer, glDrawPixels, etc.
+ * This is currently shared by all the meta ops. But we could create a
+ * separate one for each of glDrawPixel, glBlitFramebuffer, glCopyPixels, etc.
+ */
+struct temp_texture
+{
+ GLuint TexObj;
+ GLenum Target; /**< GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE */
+ GLsizei MinSize; /**< Min texture size to allocate */
+ GLsizei MaxSize; /**< Max possible texture size */
+ GLboolean NPOT; /**< Non-power of two size OK? */
+ GLsizei Width, Height; /**< Current texture size */
+ GLenum IntFormat;
+ GLfloat Sright, Ttop; /**< right, top texcoords */
+};
+
+
+/**
+ * State for glBlitFramebufer()
+ */
+struct blit_state
+{
+ GLuint ArrayObj;
+ GLuint VBO;
+ GLuint DepthFP;
+};
+
+
+/**
+ * State for glClear()
+ */
+struct clear_state
+{
+ GLuint ArrayObj;
+ GLuint VBO;
+};
+
+
+/**
+ * State for glCopyPixels()
+ */
+struct copypix_state
+{
+ GLuint ArrayObj;
+ GLuint VBO;
+};
+
+
+/**
+ * State for glDrawPixels()
+ */
+struct drawpix_state
+{
+ GLuint ArrayObj;
+
+ GLuint StencilFP; /**< Fragment program for drawing stencil images */
+ GLuint DepthFP; /**< Fragment program for drawing depth images */
+};
+
+
+/**
+ * State for glBitmap()
+ */
+struct bitmap_state
+{
+ GLuint ArrayObj;
+ GLuint VBO;
+ struct temp_texture Tex; /**< separate texture from other meta ops */
+};
+
+
+/**
+ * State for _mesa_meta_generate_mipmap()
+ */
+struct gen_mipmap_state
+{
+ GLuint ArrayObj;
+ GLuint VBO;
+ GLuint FBO;
+};
+
+#define MAX_META_OPS_DEPTH 2
+/**
+ * All per-context meta state.
+ */
+struct gl_meta_state
+{
+ /** Stack of state saved during meta-ops */
+ struct save_state Save[MAX_META_OPS_DEPTH];
+ /** Save stack depth */
+ GLuint SaveStackDepth;
+
+ struct temp_texture TempTex;
+
+ struct blit_state Blit; /**< For _mesa_meta_BlitFramebuffer() */
+ struct clear_state Clear; /**< For _mesa_meta_Clear() */
+ struct copypix_state CopyPix; /**< For _mesa_meta_CopyPixels() */
+ struct drawpix_state DrawPix; /**< For _mesa_meta_DrawPixels() */
+ struct bitmap_state Bitmap; /**< For _mesa_meta_Bitmap() */
+ struct gen_mipmap_state Mipmap; /**< For _mesa_meta_GenerateMipmap() */
+};
+
+
+/**
+ * Initialize meta-ops for a context.
+ * To be called once during context creation.
+ */
+void
+_mesa_meta_init(struct gl_context *ctx)
+{
+ ASSERT(!ctx->Meta);
+
+ ctx->Meta = CALLOC_STRUCT(gl_meta_state);
+}
+
+
+/**
+ * Free context meta-op state.
+ * To be called once during context destruction.
+ */
+void
+_mesa_meta_free(struct gl_context *ctx)
+{
+ /* Note: Any textures, VBOs, etc, that we allocate should get
+ * freed by the normal context destruction code. But this would be
+ * the place to free other meta data someday.
+ */
+ free(ctx->Meta);
+ ctx->Meta = NULL;
+}
+
+
+/**
+ * Enter meta state. This is like a light-weight version of glPushAttrib
+ * but it also resets most GL state back to default values.
+ *
+ * \param state bitmask of META_* flags indicating which attribute groups
+ * to save and reset to their defaults
+ */
+static void
+_mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
+{
+ struct save_state *save;
+
+ /* hope MAX_META_OPS_DEPTH is large enough */
+ assert(ctx->Meta->SaveStackDepth < MAX_META_OPS_DEPTH);
+
+ save = &ctx->Meta->Save[ctx->Meta->SaveStackDepth++];
+ memset(save, 0, sizeof(*save));
+ save->SavedState = state;
+
+ if (state & META_ALPHA_TEST) {
+ save->AlphaEnabled = ctx->Color.AlphaEnabled;
+ save->AlphaFunc = ctx->Color.AlphaFunc;
+ save->AlphaRef = ctx->Color.AlphaRef;
+ if (ctx->Color.AlphaEnabled)
+ _mesa_set_enable(ctx, GL_ALPHA_TEST, GL_FALSE);
+ }
+
+ if (state & META_BLEND) {
+ save->BlendEnabled = ctx->Color.BlendEnabled;
+ if (ctx->Color.BlendEnabled) {
+ if (ctx->Extensions.EXT_draw_buffers2) {
+ GLuint i;
+ for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
+ _mesa_set_enablei(ctx, GL_BLEND, i, GL_FALSE);
+ }
+ }
+ else {
+ _mesa_set_enable(ctx, GL_BLEND, GL_FALSE);
+ }
+ }
+ save->ColorLogicOpEnabled = ctx->Color.ColorLogicOpEnabled;
+ if (ctx->Color.ColorLogicOpEnabled)
+ _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP, GL_FALSE);
+ }
+
+ if (state & META_COLOR_MASK) {
+ memcpy(save->ColorMask, ctx->Color.ColorMask,
+ sizeof(ctx->Color.ColorMask));
+ if (!ctx->Color.ColorMask[0][0] ||
+ !ctx->Color.ColorMask[0][1] ||
+ !ctx->Color.ColorMask[0][2] ||
+ !ctx->Color.ColorMask[0][3])
+ _mesa_ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ }
+
+ if (state & META_DEPTH_TEST) {
+ save->Depth = ctx->Depth; /* struct copy */
+ if (ctx->Depth.Test)
+ _mesa_set_enable(ctx, GL_DEPTH_TEST, GL_FALSE);
+ }
+
+ if (state & META_FOG) {
+ save->Fog = ctx->Fog.Enabled;
+ if (ctx->Fog.Enabled)
+ _mesa_set_enable(ctx, GL_FOG, GL_FALSE);
+ }
+
+ if (state & META_PIXEL_STORE) {
+ save->Pack = ctx->Pack;
+ save->Unpack = ctx->Unpack;
+ ctx->Pack = ctx->DefaultPacking;
+ ctx->Unpack = ctx->DefaultPacking;
+ }
+
+ if (state & META_PIXEL_TRANSFER) {
+ save->RedScale = ctx->Pixel.RedScale;
+ save->RedBias = ctx->Pixel.RedBias;
+ save->GreenScale = ctx->Pixel.GreenScale;
+ save->GreenBias = ctx->Pixel.GreenBias;
+ save->BlueScale = ctx->Pixel.BlueScale;
+ save->BlueBias = ctx->Pixel.BlueBias;
+ save->AlphaScale = ctx->Pixel.AlphaScale;
+ save->AlphaBias = ctx->Pixel.AlphaBias;
+ save->MapColorFlag = ctx->Pixel.MapColorFlag;
+ ctx->Pixel.RedScale = 1.0F;
+ ctx->Pixel.RedBias = 0.0F;
+ ctx->Pixel.GreenScale = 1.0F;
+ ctx->Pixel.GreenBias = 0.0F;
+ ctx->Pixel.BlueScale = 1.0F;
+ ctx->Pixel.BlueBias = 0.0F;
+ ctx->Pixel.AlphaScale = 1.0F;
+ ctx->Pixel.AlphaBias = 0.0F;
+ ctx->Pixel.MapColorFlag = GL_FALSE;
+ /* XXX more state */
+ ctx->NewState |=_NEW_PIXEL;
+ }
+
+ if (state & META_RASTERIZATION) {
+ save->FrontPolygonMode = ctx->Polygon.FrontMode;
+ save->BackPolygonMode = ctx->Polygon.BackMode;
+ save->PolygonOffset = ctx->Polygon.OffsetFill;
+ save->PolygonSmooth = ctx->Polygon.SmoothFlag;
+ save->PolygonStipple = ctx->Polygon.StippleFlag;
+ save->PolygonCull = ctx->Polygon.CullFlag;
+ _mesa_PolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL, GL_FALSE);
+ _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, GL_FALSE);
+ _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, GL_FALSE);
+ _mesa_set_enable(ctx, GL_CULL_FACE, GL_FALSE);
+ }
+
+ if (state & META_SCISSOR) {
+ save->Scissor = ctx->Scissor; /* struct copy */
+ _mesa_set_enable(ctx, GL_SCISSOR_TEST, GL_FALSE);
+ }
+
+ if (state & META_SHADER) {
+ if (ctx->Extensions.ARB_vertex_program) {
+ save->VertexProgramEnabled = ctx->VertexProgram.Enabled;
+ _mesa_reference_vertprog(ctx, &save->VertexProgram,
+ ctx->VertexProgram.Current);
+ _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB, GL_FALSE);
+ }
+
+ if (ctx->Extensions.ARB_fragment_program) {
+ save->FragmentProgramEnabled = ctx->FragmentProgram.Enabled;
+ _mesa_reference_fragprog(ctx, &save->FragmentProgram,
+ ctx->FragmentProgram.Current);
+ _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_FALSE);
+ }
+
+ if (ctx->Extensions.ARB_shader_objects) {
+ _mesa_reference_shader_program(ctx, &save->VertexShader,
+ ctx->Shader.CurrentVertexProgram);
+ _mesa_reference_shader_program(ctx, &save->GeometryShader,
+ ctx->Shader.CurrentGeometryProgram);
+ _mesa_reference_shader_program(ctx, &save->FragmentShader,
+ ctx->Shader.CurrentFragmentProgram);
+ _mesa_reference_shader_program(ctx, &save->ActiveShader,
+ ctx->Shader.CurrentFragmentProgram);
+
+ _mesa_UseProgramObjectARB(0);
+ }
+ }
+
+ if (state & META_STENCIL_TEST) {
+ save->Stencil = ctx->Stencil; /* struct copy */
+ if (ctx->Stencil.Enabled)
+ _mesa_set_enable(ctx, GL_STENCIL_TEST, GL_FALSE);
+ /* NOTE: other stencil state not reset */
+ }
+
+ if (state & META_TEXTURE) {
+ GLuint u, tgt;
+
+ save->ActiveUnit = ctx->Texture.CurrentUnit;
+ save->ClientActiveUnit = ctx->Array.ActiveTexture;
+ save->EnvMode = ctx->Texture.Unit[0].EnvMode;
+
+ /* Disable all texture units */
+ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+ save->TexEnabled[u] = ctx->Texture.Unit[u].Enabled;
+ save->TexGenEnabled[u] = ctx->Texture.Unit[u].TexGenEnabled;
+ if (ctx->Texture.Unit[u].Enabled ||
+ ctx->Texture.Unit[u].TexGenEnabled) {
+ _mesa_ActiveTextureARB(GL_TEXTURE0 + u);
+ _mesa_set_enable(ctx, GL_TEXTURE_1D, GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_2D, GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_3D, GL_FALSE);
+ if (ctx->Extensions.ARB_texture_cube_map)
+ _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE, GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_R, GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
+ }
+ }
+
+ /* save current texture objects for unit[0] only */
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+ _mesa_reference_texobj(&save->CurrentTexture[tgt],
+ ctx->Texture.Unit[0].CurrentTex[tgt]);
+ }
+
+ /* set defaults for unit[0] */
+ _mesa_ActiveTextureARB(GL_TEXTURE0);
+ _mesa_ClientActiveTextureARB(GL_TEXTURE0);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ }
+
+ if (state & META_TRANSFORM) {
+ GLuint activeTexture = ctx->Texture.CurrentUnit;
+ memcpy(save->ModelviewMatrix, ctx->ModelviewMatrixStack.Top->m,
+ 16 * sizeof(GLfloat));
+ memcpy(save->ProjectionMatrix, ctx->ProjectionMatrixStack.Top->m,
+ 16 * sizeof(GLfloat));
+ memcpy(save->TextureMatrix, ctx->TextureMatrixStack[0].Top->m,
+ 16 * sizeof(GLfloat));
+ save->MatrixMode = ctx->Transform.MatrixMode;
+ /* set 1:1 vertex:pixel coordinate transform */
+ _mesa_ActiveTextureARB(GL_TEXTURE0);
+ _mesa_MatrixMode(GL_TEXTURE);
+ _mesa_LoadIdentity();
+ _mesa_ActiveTextureARB(GL_TEXTURE0 + activeTexture);
+ _mesa_MatrixMode(GL_MODELVIEW);
+ _mesa_LoadIdentity();
+ _mesa_MatrixMode(GL_PROJECTION);
+ _mesa_LoadIdentity();
+ _mesa_Ortho(0.0, ctx->DrawBuffer->Width,
+ 0.0, ctx->DrawBuffer->Height,
+ -1.0, 1.0);
+ save->ClipPlanesEnabled = ctx->Transform.ClipPlanesEnabled;
+ if (ctx->Transform.ClipPlanesEnabled) {
+ GLuint i;
+ for (i = 0; i < ctx->Const.MaxClipPlanes; i++) {
+ _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE);
+ }
+ }
+ }
+
+ if (state & META_VERTEX) {
+ /* save vertex array object state */
+ _mesa_reference_array_object(ctx, &save->ArrayObj,
+ ctx->Array.ArrayObj);
+ _mesa_reference_buffer_object(ctx, &save->ArrayBufferObj,
+ ctx->Array.ArrayBufferObj);
+ /* set some default state? */
+ }
+
+ if (state & META_VIEWPORT) {
+ /* save viewport state */
+ save->ViewportX = ctx->Viewport.X;
+ save->ViewportY = ctx->Viewport.Y;
+ save->ViewportW = ctx->Viewport.Width;
+ save->ViewportH = ctx->Viewport.Height;
+ /* set viewport to match window size */
+ if (ctx->Viewport.X != 0 ||
+ ctx->Viewport.Y != 0 ||
+ ctx->Viewport.Width != ctx->DrawBuffer->Width ||
+ ctx->Viewport.Height != ctx->DrawBuffer->Height) {
+ _mesa_set_viewport(ctx, 0, 0,
+ ctx->DrawBuffer->Width, ctx->DrawBuffer->Height);
+ }
+ /* save depth range state */
+ save->DepthNear = ctx->Viewport.Near;
+ save->DepthFar = ctx->Viewport.Far;
+ /* set depth range to default */
+ _mesa_DepthRange(0.0, 1.0);
+ }
+
+ /* misc */
+ {
+ save->Lighting = ctx->Light.Enabled;
+ if (ctx->Light.Enabled)
+ _mesa_set_enable(ctx, GL_LIGHTING, GL_FALSE);
+ }
+}
+
+
+/**
+ * Leave meta state. This is like a light-weight version of glPopAttrib().
+ */
+static void
+_mesa_meta_end(struct gl_context *ctx)
+{
+ struct save_state *save = &ctx->Meta->Save[--ctx->Meta->SaveStackDepth];
+ const GLbitfield state = save->SavedState;
+
+ if (state & META_ALPHA_TEST) {
+ if (ctx->Color.AlphaEnabled != save->AlphaEnabled)
+ _mesa_set_enable(ctx, GL_ALPHA_TEST, save->AlphaEnabled);
+ _mesa_AlphaFunc(save->AlphaFunc, save->AlphaRef);
+ }
+
+ if (state & META_BLEND) {
+ if (ctx->Color.BlendEnabled != save->BlendEnabled) {
+ if (ctx->Extensions.EXT_draw_buffers2) {
+ GLuint i;
+ for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
+ _mesa_set_enablei(ctx, GL_BLEND, i, (save->BlendEnabled >> i) & 1);
+ }
+ }
+ else {
+ _mesa_set_enable(ctx, GL_BLEND, (save->BlendEnabled & 1));
+ }
+ }
+ if (ctx->Color.ColorLogicOpEnabled != save->ColorLogicOpEnabled)
+ _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP, save->ColorLogicOpEnabled);
+ }
+
+ if (state & META_COLOR_MASK) {
+ GLuint i;
+ for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
+ if (!TEST_EQ_4V(ctx->Color.ColorMask[i], save->ColorMask[i])) {
+ if (i == 0) {
+ _mesa_ColorMask(save->ColorMask[i][0], save->ColorMask[i][1],
+ save->ColorMask[i][2], save->ColorMask[i][3]);
+ }
+ else {
+ _mesa_ColorMaskIndexed(i,
+ save->ColorMask[i][0],
+ save->ColorMask[i][1],
+ save->ColorMask[i][2],
+ save->ColorMask[i][3]);
+ }
+ }
+ }
+ }
+
+ if (state & META_DEPTH_TEST) {
+ if (ctx->Depth.Test != save->Depth.Test)
+ _mesa_set_enable(ctx, GL_DEPTH_TEST, save->Depth.Test);
+ _mesa_DepthFunc(save->Depth.Func);
+ _mesa_DepthMask(save->Depth.Mask);
+ }
+
+ if (state & META_FOG) {
+ _mesa_set_enable(ctx, GL_FOG, save->Fog);
+ }
+
+ if (state & META_PIXEL_STORE) {
+ ctx->Pack = save->Pack;
+ ctx->Unpack = save->Unpack;
+ }
+
+ if (state & META_PIXEL_TRANSFER) {
+ ctx->Pixel.RedScale = save->RedScale;
+ ctx->Pixel.RedBias = save->RedBias;
+ ctx->Pixel.GreenScale = save->GreenScale;
+ ctx->Pixel.GreenBias = save->GreenBias;
+ ctx->Pixel.BlueScale = save->BlueScale;
+ ctx->Pixel.BlueBias = save->BlueBias;
+ ctx->Pixel.AlphaScale = save->AlphaScale;
+ ctx->Pixel.AlphaBias = save->AlphaBias;
+ ctx->Pixel.MapColorFlag = save->MapColorFlag;
+ /* XXX more state */
+ ctx->NewState |=_NEW_PIXEL;
+ }
+
+ if (state & META_RASTERIZATION) {
+ _mesa_PolygonMode(GL_FRONT, save->FrontPolygonMode);
+ _mesa_PolygonMode(GL_BACK, save->BackPolygonMode);
+ _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, save->PolygonStipple);
+ _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL, save->PolygonOffset);
+ _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, save->PolygonSmooth);
+ _mesa_set_enable(ctx, GL_CULL_FACE, save->PolygonCull);
+ }
+
+ if (state & META_SCISSOR) {
+ _mesa_set_enable(ctx, GL_SCISSOR_TEST, save->Scissor.Enabled);
+ _mesa_Scissor(save->Scissor.X, save->Scissor.Y,
+ save->Scissor.Width, save->Scissor.Height);
+ }
+
+ if (state & META_SHADER) {
+ if (ctx->Extensions.ARB_vertex_program) {
+ _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB,
+ save->VertexProgramEnabled);
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current,
+ save->VertexProgram);
+ _mesa_reference_vertprog(ctx, &save->VertexProgram, NULL);
+ }
+
+ if (ctx->Extensions.ARB_fragment_program) {
+ _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB,
+ save->FragmentProgramEnabled);
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current,
+ save->FragmentProgram);
+ _mesa_reference_fragprog(ctx, &save->FragmentProgram, NULL);
+ }
+
+ if (ctx->Extensions.ARB_vertex_shader)
+ _mesa_use_shader_program(ctx, GL_VERTEX_SHADER, save->VertexShader);
+
+ if (ctx->Extensions.ARB_geometry_shader4)
+ _mesa_use_shader_program(ctx, GL_GEOMETRY_SHADER_ARB,
+ save->GeometryShader);
+
+ if (ctx->Extensions.ARB_fragment_shader)
+ _mesa_use_shader_program(ctx, GL_FRAGMENT_SHADER,
+ save->FragmentShader);
+
+ _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram,
+ save->ActiveShader);
+ }
+
+ if (state & META_STENCIL_TEST) {
+ const struct gl_stencil_attrib *stencil = &save->Stencil;
+
+ _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled);
+ _mesa_ClearStencil(stencil->Clear);
+ if (ctx->Extensions.EXT_stencil_two_side) {
+ _mesa_set_enable(ctx, GL_STENCIL_TEST_TWO_SIDE_EXT,
+ stencil->TestTwoSide);
+ _mesa_ActiveStencilFaceEXT(stencil->ActiveFace
+ ? GL_BACK : GL_FRONT);
+ }
+ /* front state */
+ _mesa_StencilFuncSeparate(GL_FRONT,
+ stencil->Function[0],
+ stencil->Ref[0],
+ stencil->ValueMask[0]);
+ _mesa_StencilMaskSeparate(GL_FRONT, stencil->WriteMask[0]);
+ _mesa_StencilOpSeparate(GL_FRONT, stencil->FailFunc[0],
+ stencil->ZFailFunc[0],
+ stencil->ZPassFunc[0]);
+ /* back state */
+ _mesa_StencilFuncSeparate(GL_BACK,
+ stencil->Function[1],
+ stencil->Ref[1],
+ stencil->ValueMask[1]);
+ _mesa_StencilMaskSeparate(GL_BACK, stencil->WriteMask[1]);
+ _mesa_StencilOpSeparate(GL_BACK, stencil->FailFunc[1],
+ stencil->ZFailFunc[1],
+ stencil->ZPassFunc[1]);
+ }
+
+ if (state & META_TEXTURE) {
+ GLuint u, tgt;
+
+ ASSERT(ctx->Texture.CurrentUnit == 0);
+
+ /* restore texenv for unit[0] */
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, save->EnvMode);
+
+ /* restore texture objects for unit[0] only */
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+ _mesa_reference_texobj(&ctx->Texture.Unit[0].CurrentTex[tgt],
+ save->CurrentTexture[tgt]);
+ _mesa_reference_texobj(&save->CurrentTexture[tgt], NULL);
+ }
+
+ /* Re-enable textures, texgen */
+ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+ if (save->TexEnabled[u]) {
+ _mesa_ActiveTextureARB(GL_TEXTURE0 + u);
+
+ if (save->TexEnabled[u] & TEXTURE_1D_BIT)
+ _mesa_set_enable(ctx, GL_TEXTURE_1D, GL_TRUE);
+ if (save->TexEnabled[u] & TEXTURE_2D_BIT)
+ _mesa_set_enable(ctx, GL_TEXTURE_2D, GL_TRUE);
+ if (save->TexEnabled[u] & TEXTURE_3D_BIT)
+ _mesa_set_enable(ctx, GL_TEXTURE_3D, GL_TRUE);
+ if (save->TexEnabled[u] & TEXTURE_CUBE_BIT)
+ _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_TRUE);
+ if (save->TexEnabled[u] & TEXTURE_RECT_BIT)
+ _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE, GL_TRUE);
+ }
+
+ if (save->TexGenEnabled[u]) {
+ _mesa_ActiveTextureARB(GL_TEXTURE0 + u);
+
+ if (save->TexGenEnabled[u] & S_BIT)
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, GL_TRUE);
+ if (save->TexGenEnabled[u] & T_BIT)
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, GL_TRUE);
+ if (save->TexGenEnabled[u] & R_BIT)
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_R, GL_TRUE);
+ if (save->TexGenEnabled[u] & Q_BIT)
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
+ }
+ }
+
+ /* restore current unit state */
+ _mesa_ActiveTextureARB(GL_TEXTURE0 + save->ActiveUnit);
+ _mesa_ClientActiveTextureARB(GL_TEXTURE0 + save->ClientActiveUnit);
+ }
+
+ if (state & META_TRANSFORM) {
+ GLuint activeTexture = ctx->Texture.CurrentUnit;
+ _mesa_ActiveTextureARB(GL_TEXTURE0);
+ _mesa_MatrixMode(GL_TEXTURE);
+ _mesa_LoadMatrixf(save->TextureMatrix);
+ _mesa_ActiveTextureARB(GL_TEXTURE0 + activeTexture);
+
+ _mesa_MatrixMode(GL_MODELVIEW);
+ _mesa_LoadMatrixf(save->ModelviewMatrix);
+
+ _mesa_MatrixMode(GL_PROJECTION);
+ _mesa_LoadMatrixf(save->ProjectionMatrix);
+
+ _mesa_MatrixMode(save->MatrixMode);
+
+ if (save->ClipPlanesEnabled) {
+ GLuint i;
+ for (i = 0; i < ctx->Const.MaxClipPlanes; i++) {
+ if (save->ClipPlanesEnabled & (1 << i)) {
+ _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_TRUE);
+ }
+ }
+ }
+ }
+
+ if (state & META_VERTEX) {
+ /* restore vertex buffer object */
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, save->ArrayBufferObj->Name);
+ _mesa_reference_buffer_object(ctx, &save->ArrayBufferObj, NULL);
+
+ /* restore vertex array object */
+ _mesa_BindVertexArray(save->ArrayObj->Name);
+ _mesa_reference_array_object(ctx, &save->ArrayObj, NULL);
+ }
+
+ if (state & META_VIEWPORT) {
+ if (save->ViewportX != ctx->Viewport.X ||
+ save->ViewportY != ctx->Viewport.Y ||
+ save->ViewportW != ctx->Viewport.Width ||
+ save->ViewportH != ctx->Viewport.Height) {
+ _mesa_set_viewport(ctx, save->ViewportX, save->ViewportY,
+ save->ViewportW, save->ViewportH);
+ }
+ _mesa_DepthRange(save->DepthNear, save->DepthFar);
+ }
+
+ /* misc */
+ if (save->Lighting) {
+ _mesa_set_enable(ctx, GL_LIGHTING, GL_TRUE);
+ }
+}
+
+
+/**
+ * Convert Z from a normalized value in the range [0, 1] to an object-space
+ * Z coordinate in [-1, +1] so that drawing at the new Z position with the
+ * default/identity ortho projection results in the original Z value.
+ * Used by the meta-Clear, Draw/CopyPixels and Bitmap functions where the Z
+ * value comes from the clear value or raster position.
+ */
+static INLINE GLfloat
+invert_z(GLfloat normZ)
+{
+ GLfloat objZ = 1.0 - 2.0 * normZ;
+ return objZ;
+}
+
+
+/**
+ * One-time init for a temp_texture object.
+ * Choose tex target, compute max tex size, etc.
+ */
+static void
+init_temp_texture(struct gl_context *ctx, struct temp_texture *tex)
+{
+ /* prefer texture rectangle */
+ if (ctx->Extensions.NV_texture_rectangle) {
+ tex->Target = GL_TEXTURE_RECTANGLE;
+ tex->MaxSize = ctx->Const.MaxTextureRectSize;
+ tex->NPOT = GL_TRUE;
+ }
+ else {
+ /* use 2D texture, NPOT if possible */
+ tex->Target = GL_TEXTURE_2D;
+ tex->MaxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
+ tex->NPOT = ctx->Extensions.ARB_texture_non_power_of_two;
+ }
+ tex->MinSize = 16; /* 16 x 16 at least */
+ assert(tex->MaxSize > 0);
+
+ _mesa_GenTextures(1, &tex->TexObj);
+}
+
+
+/**
+ * Return pointer to temp_texture info for non-bitmap ops.
+ * This does some one-time init if needed.
+ */
+static struct temp_texture *
+get_temp_texture(struct gl_context *ctx)
+{
+ struct temp_texture *tex = &ctx->Meta->TempTex;
+
+ if (!tex->TexObj) {
+ init_temp_texture(ctx, tex);
+ }
+
+ return tex;
+}
+
+
+/**
+ * Return pointer to temp_texture info for _mesa_meta_bitmap().
+ * We use a separate texture for bitmaps to reduce texture
+ * allocation/deallocation.
+ */
+static struct temp_texture *
+get_bitmap_temp_texture(struct gl_context *ctx)
+{
+ struct temp_texture *tex = &ctx->Meta->Bitmap.Tex;
+
+ if (!tex->TexObj) {
+ init_temp_texture(ctx, tex);
+ }
+
+ return tex;
+}
+
+
+/**
+ * Compute the width/height of texture needed to draw an image of the
+ * given size. Return a flag indicating whether the current texture
+ * can be re-used (glTexSubImage2D) or if a new texture needs to be
+ * allocated (glTexImage2D).
+ * Also, compute s/t texcoords for drawing.
+ *
+ * \return GL_TRUE if new texture is needed, GL_FALSE otherwise
+ */
+static GLboolean
+alloc_texture(struct temp_texture *tex,
+ GLsizei width, GLsizei height, GLenum intFormat)
+{
+ GLboolean newTex = GL_FALSE;
+
+ ASSERT(width <= tex->MaxSize);
+ ASSERT(height <= tex->MaxSize);
+
+ if (width > tex->Width ||
+ height > tex->Height ||
+ intFormat != tex->IntFormat) {
+ /* alloc new texture (larger or different format) */
+
+ if (tex->NPOT) {
+ /* use non-power of two size */
+ tex->Width = MAX2(tex->MinSize, width);
+ tex->Height = MAX2(tex->MinSize, height);
+ }
+ else {
+ /* find power of two size */
+ GLsizei w, h;
+ w = h = tex->MinSize;
+ while (w < width)
+ w *= 2;
+ while (h < height)
+ h *= 2;
+ tex->Width = w;
+ tex->Height = h;
+ }
+
+ tex->IntFormat = intFormat;
+
+ newTex = GL_TRUE;
+ }
+
+ /* compute texcoords */
+ if (tex->Target == GL_TEXTURE_RECTANGLE) {
+ tex->Sright = (GLfloat) width;
+ tex->Ttop = (GLfloat) height;
+ }
+ else {
+ tex->Sright = (GLfloat) width / tex->Width;
+ tex->Ttop = (GLfloat) height / tex->Height;
+ }
+
+ return newTex;
+}
+
+
+/**
+ * Setup/load texture for glCopyPixels or glBlitFramebuffer.
+ */
+static void
+setup_copypix_texture(struct temp_texture *tex,
+ GLboolean newTex,
+ GLint srcX, GLint srcY,
+ GLsizei width, GLsizei height, GLenum intFormat,
+ GLenum filter)
+{
+ _mesa_BindTexture(tex->Target, tex->TexObj);
+ _mesa_TexParameteri(tex->Target, GL_TEXTURE_MIN_FILTER, filter);
+ _mesa_TexParameteri(tex->Target, GL_TEXTURE_MAG_FILTER, filter);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+ /* copy framebuffer image to texture */
+ if (newTex) {
+ /* create new tex image */
+ if (tex->Width == width && tex->Height == height) {
+ /* create new tex with framebuffer data */
+ _mesa_CopyTexImage2D(tex->Target, 0, tex->IntFormat,
+ srcX, srcY, width, height, 0);
+ }
+ else {
+ /* create empty texture */
+ _mesa_TexImage2D(tex->Target, 0, tex->IntFormat,
+ tex->Width, tex->Height, 0,
+ intFormat, GL_UNSIGNED_BYTE, NULL);
+ /* load image */
+ _mesa_CopyTexSubImage2D(tex->Target, 0,
+ 0, 0, srcX, srcY, width, height);
+ }
+ }
+ else {
+ /* replace existing tex image */
+ _mesa_CopyTexSubImage2D(tex->Target, 0,
+ 0, 0, srcX, srcY, width, height);
+ }
+}
+
+
+/**
+ * Setup/load texture for glDrawPixels.
+ */
+static void
+setup_drawpix_texture(struct gl_context *ctx,
+ struct temp_texture *tex,
+ GLboolean newTex,
+ GLenum texIntFormat,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const GLvoid *pixels)
+{
+ _mesa_BindTexture(tex->Target, tex->TexObj);
+ _mesa_TexParameteri(tex->Target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ _mesa_TexParameteri(tex->Target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+ /* copy pixel data to texture */
+ if (newTex) {
+ /* create new tex image */
+ if (tex->Width == width && tex->Height == height) {
+ /* create new tex and load image data */
+ _mesa_TexImage2D(tex->Target, 0, tex->IntFormat,
+ tex->Width, tex->Height, 0, format, type, pixels);
+ }
+ else {
+ struct gl_buffer_object *save_unpack_obj = NULL;
+
+ _mesa_reference_buffer_object(ctx, &save_unpack_obj,
+ ctx->Unpack.BufferObj);
+ _mesa_BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ /* create empty texture */
+ _mesa_TexImage2D(tex->Target, 0, tex->IntFormat,
+ tex->Width, tex->Height, 0, format, type, NULL);
+ if (save_unpack_obj != NULL)
+ _mesa_BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB,
+ save_unpack_obj->Name);
+ /* load image */
+ _mesa_TexSubImage2D(tex->Target, 0,
+ 0, 0, width, height, format, type, pixels);
+ }
+ }
+ else {
+ /* replace existing tex image */
+ _mesa_TexSubImage2D(tex->Target, 0,
+ 0, 0, width, height, format, type, pixels);
+ }
+}
+
+
+
+/**
+ * One-time init for drawing depth pixels.
+ */
+static void
+init_blit_depth_pixels(struct gl_context *ctx)
+{
+ static const char *program =
+ "!!ARBfp1.0\n"
+ "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n"
+ "END \n";
+ char program2[200];
+ struct blit_state *blit = &ctx->Meta->Blit;
+ struct temp_texture *tex = get_temp_texture(ctx);
+ const char *texTarget;
+
+ assert(blit->DepthFP == 0);
+
+ /* replace %s with "RECT" or "2D" */
+ assert(strlen(program) + 4 < sizeof(program2));
+ if (tex->Target == GL_TEXTURE_RECTANGLE)
+ texTarget = "RECT";
+ else
+ texTarget = "2D";
+ _mesa_snprintf(program2, sizeof(program2), program, texTarget);
+
+ _mesa_GenPrograms(1, &blit->DepthFP);
+ _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, blit->DepthFP);
+ _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+ strlen(program2), (const GLubyte *) program2);
+}
+
+
+/**
+ * Try to do a glBlitFramebuffer using no-copy texturing.
+ * We can do this when the src renderbuffer is actually a texture.
+ * But if the src buffer == dst buffer we cannot do this.
+ *
+ * \return new buffer mask indicating the buffers left to blit using the
+ * normal path.
+ */
+static GLbitfield
+blitframebuffer_texture(struct gl_context *ctx,
+ GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
+ GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
+ GLbitfield mask, GLenum filter)
+{
+ if (mask & GL_COLOR_BUFFER_BIT) {
+ const struct gl_framebuffer *drawFb = ctx->DrawBuffer;
+ const struct gl_framebuffer *readFb = ctx->ReadBuffer;
+ const struct gl_renderbuffer_attachment *drawAtt =
+ &drawFb->Attachment[drawFb->_ColorDrawBufferIndexes[0]];
+ const struct gl_renderbuffer_attachment *readAtt =
+ &readFb->Attachment[readFb->_ColorReadBufferIndex];
+
+ if (readAtt && readAtt->Texture) {
+ const struct gl_texture_object *texObj = readAtt->Texture;
+ const GLuint srcLevel = readAtt->TextureLevel;
+ const GLenum minFilterSave = texObj->MinFilter;
+ const GLenum magFilterSave = texObj->MagFilter;
+ const GLint baseLevelSave = texObj->BaseLevel;
+ const GLint maxLevelSave = texObj->MaxLevel;
+ const GLenum wrapSSave = texObj->WrapS;
+ const GLenum wrapTSave = texObj->WrapT;
+ const GLenum target = texObj->Target;
+
+ if (drawAtt->Texture == readAtt->Texture) {
+ /* Can't use same texture as both the source and dest. We need
+ * to handle overlapping blits and besides, some hw may not
+ * support this.
+ */
+ return mask;
+ }
+
+ if (target != GL_TEXTURE_2D && target != GL_TEXTURE_RECTANGLE_ARB) {
+ /* Can't handle other texture types at this time */
+ return mask;
+ }
+
+ /*
+ printf("Blit from texture!\n");
+ printf(" srcAtt %p dstAtt %p\n", readAtt, drawAtt);
+ printf(" srcTex %p dstText %p\n", texObj, drawAtt->Texture);
+ */
+
+ /* Prepare src texture state */
+ _mesa_BindTexture(target, texObj->Name);
+ _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter);
+ if (target != GL_TEXTURE_RECTANGLE_ARB) {
+ _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, srcLevel);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, srcLevel);
+ }
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ _mesa_set_enable(ctx, target, GL_TRUE);
+
+ /* Prepare vertex data (the VBO was previously created and bound) */
+ {
+ struct vertex {
+ GLfloat x, y, s, t;
+ };
+ struct vertex verts[4];
+ GLfloat s0, t0, s1, t1;
+
+ if (target == GL_TEXTURE_2D) {
+ const struct gl_texture_image *texImage
+ = _mesa_select_tex_image(ctx, texObj, target, srcLevel);
+ s0 = srcX0 / (float) texImage->Width;
+ s1 = srcX1 / (float) texImage->Width;
+ t0 = srcY0 / (float) texImage->Height;
+ t1 = srcY1 / (float) texImage->Height;
+ }
+ else {
+ assert(target == GL_TEXTURE_RECTANGLE_ARB);
+ s0 = srcX0;
+ s1 = srcX1;
+ t0 = srcY0;
+ t1 = srcY1;
+ }
+
+ verts[0].x = (GLfloat) dstX0;
+ verts[0].y = (GLfloat) dstY0;
+ verts[1].x = (GLfloat) dstX1;
+ verts[1].y = (GLfloat) dstY0;
+ verts[2].x = (GLfloat) dstX1;
+ verts[2].y = (GLfloat) dstY1;
+ verts[3].x = (GLfloat) dstX0;
+ verts[3].y = (GLfloat) dstY1;
+
+ verts[0].s = s0;
+ verts[0].t = t0;
+ verts[1].s = s1;
+ verts[1].t = t0;
+ verts[2].s = s1;
+ verts[2].t = t1;
+ verts[3].s = s0;
+ verts[3].t = t1;
+
+ _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
+ }
+
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ /* Restore texture object state, the texture binding will
+ * be restored by _mesa_meta_end().
+ */
+ _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilterSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilterSave);
+ if (target != GL_TEXTURE_RECTANGLE_ARB) {
+ _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, baseLevelSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
+ }
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, wrapSSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, wrapTSave);
+
+ /* Done with color buffer */
+ mask &= ~GL_COLOR_BUFFER_BIT;
+ }
+ }
+
+ return mask;
+}
+
+
+/**
+ * Meta implementation of ctx->Driver.BlitFramebuffer() in terms
+ * of texture mapping and polygon rendering.
+ */
+void
+_mesa_meta_BlitFramebuffer(struct gl_context *ctx,
+ GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
+ GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
+ GLbitfield mask, GLenum filter)
+{
+ struct blit_state *blit = &ctx->Meta->Blit;
+ struct temp_texture *tex = get_temp_texture(ctx);
+ const GLsizei maxTexSize = tex->MaxSize;
+ const GLint srcX = MIN2(srcX0, srcX1);
+ const GLint srcY = MIN2(srcY0, srcY1);
+ const GLint srcW = abs(srcX1 - srcX0);
+ const GLint srcH = abs(srcY1 - srcY0);
+ const GLboolean srcFlipX = srcX1 < srcX0;
+ const GLboolean srcFlipY = srcY1 < srcY0;
+ struct vertex {
+ GLfloat x, y, s, t;
+ };
+ struct vertex verts[4];
+ GLboolean newTex;
+
+ if (srcW > maxTexSize || srcH > maxTexSize) {
+ /* XXX avoid this fallback */
+ _swrast_BlitFramebuffer(ctx, srcX0, srcY0, srcX1, srcY1,
+ dstX0, dstY0, dstX1, dstY1, mask, filter);
+ return;
+ }
+
+ if (srcFlipX) {
+ GLint tmp = dstX0;
+ dstX0 = dstX1;
+ dstX1 = tmp;
+ }
+
+ if (srcFlipY) {
+ GLint tmp = dstY0;
+ dstY0 = dstY1;
+ dstY1 = tmp;
+ }
+
+ /* only scissor effects blit so save/clear all other relevant state */
+ _mesa_meta_begin(ctx, ~META_SCISSOR);
+
+ if (blit->ArrayObj == 0) {
+ /* one-time setup */
+
+ /* create vertex array object */
+ _mesa_GenVertexArrays(1, &blit->ArrayObj);
+ _mesa_BindVertexArray(blit->ArrayObj);
+
+ /* create vertex array buffer */
+ _mesa_GenBuffersARB(1, &blit->VBO);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, blit->VBO);
+ _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
+ NULL, GL_DYNAMIC_DRAW_ARB);
+
+ /* setup vertex arrays */
+ _mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
+ _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
+ _mesa_EnableClientState(GL_VERTEX_ARRAY);
+ _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ else {
+ _mesa_BindVertexArray(blit->ArrayObj);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, blit->VBO);
+ }
+
+ /* Try faster, direct texture approach first */
+ mask = blitframebuffer_texture(ctx, srcX0, srcY0, srcX1, srcY1,
+ dstX0, dstY0, dstX1, dstY1, mask, filter);
+ if (mask == 0x0) {
+ _mesa_meta_end(ctx);
+ return;
+ }
+
+ /* Continue with "normal" approach which involves copying the src rect
+ * into a temporary texture and is "blitted" by drawing a textured quad.
+ */
+
+ newTex = alloc_texture(tex, srcW, srcH, GL_RGBA);
+
+ /* vertex positions/texcoords (after texture allocation!) */
+ {
+ verts[0].x = (GLfloat) dstX0;
+ verts[0].y = (GLfloat) dstY0;
+ verts[1].x = (GLfloat) dstX1;
+ verts[1].y = (GLfloat) dstY0;
+ verts[2].x = (GLfloat) dstX1;
+ verts[2].y = (GLfloat) dstY1;
+ verts[3].x = (GLfloat) dstX0;
+ verts[3].y = (GLfloat) dstY1;
+
+ verts[0].s = 0.0F;
+ verts[0].t = 0.0F;
+ verts[1].s = tex->Sright;
+ verts[1].t = 0.0F;
+ verts[2].s = tex->Sright;
+ verts[2].t = tex->Ttop;
+ verts[3].s = 0.0F;
+ verts[3].t = tex->Ttop;
+
+ /* upload new vertex data */
+ _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
+ }
+
+ _mesa_set_enable(ctx, tex->Target, GL_TRUE);
+
+ if (mask & GL_COLOR_BUFFER_BIT) {
+ setup_copypix_texture(tex, newTex, srcX, srcY, srcW, srcH,
+ GL_RGBA, filter);
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ mask &= ~GL_COLOR_BUFFER_BIT;
+ }
+
+ if (mask & GL_DEPTH_BUFFER_BIT) {
+ GLuint *tmp = (GLuint *) malloc(srcW * srcH * sizeof(GLuint));
+ if (tmp) {
+ if (!blit->DepthFP)
+ init_blit_depth_pixels(ctx);
+
+ /* maybe change tex format here */
+ newTex = alloc_texture(tex, srcW, srcH, GL_DEPTH_COMPONENT);
+
+ _mesa_ReadPixels(srcX, srcY, srcW, srcH,
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, tmp);
+
+ setup_drawpix_texture(ctx, tex, newTex, GL_DEPTH_COMPONENT, srcW, srcH,
+ GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, tmp);
+
+ _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, blit->DepthFP);
+ _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_TRUE);
+ _mesa_ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+ _mesa_set_enable(ctx, GL_DEPTH_TEST, GL_TRUE);
+ _mesa_DepthFunc(GL_ALWAYS);
+ _mesa_DepthMask(GL_TRUE);
+
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ mask &= ~GL_DEPTH_BUFFER_BIT;
+
+ free(tmp);
+ }
+ }
+
+ if (mask & GL_STENCIL_BUFFER_BIT) {
+ /* XXX can't easily do stencil */
+ }
+
+ _mesa_set_enable(ctx, tex->Target, GL_FALSE);
+
+ _mesa_meta_end(ctx);
+
+ if (mask) {
+ _swrast_BlitFramebuffer(ctx, srcX0, srcY0, srcX1, srcY1,
+ dstX0, dstY0, dstX1, dstY1, mask, filter);
+ }
+}
+
+
+/**
+ * Meta implementation of ctx->Driver.Clear() in terms of polygon rendering.
+ */
+void
+_mesa_meta_Clear(struct gl_context *ctx, GLbitfield buffers)
+{
+ struct clear_state *clear = &ctx->Meta->Clear;
+ struct vertex {
+ GLfloat x, y, z, r, g, b, a;
+ };
+ struct vertex verts[4];
+ /* save all state but scissor, pixel pack/unpack */
+ GLbitfield metaSave = META_ALL - META_SCISSOR - META_PIXEL_STORE;
+ const GLuint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
+
+ if (buffers & BUFFER_BITS_COLOR) {
+ /* if clearing color buffers, don't save/restore colormask */
+ metaSave -= META_COLOR_MASK;
+ }
+
+ _mesa_meta_begin(ctx, metaSave);
+
+ if (clear->ArrayObj == 0) {
+ /* one-time setup */
+
+ /* create vertex array object */
+ _mesa_GenVertexArrays(1, &clear->ArrayObj);
+ _mesa_BindVertexArray(clear->ArrayObj);
+
+ /* create vertex array buffer */
+ _mesa_GenBuffersARB(1, &clear->VBO);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, clear->VBO);
+
+ /* setup vertex arrays */
+ _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
+ _mesa_ColorPointer(4, GL_FLOAT, sizeof(struct vertex), OFFSET(r));
+ _mesa_EnableClientState(GL_VERTEX_ARRAY);
+ _mesa_EnableClientState(GL_COLOR_ARRAY);
+ }
+ else {
+ _mesa_BindVertexArray(clear->ArrayObj);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, clear->VBO);
+ }
+
+ /* GL_COLOR_BUFFER_BIT */
+ if (buffers & BUFFER_BITS_COLOR) {
+ /* leave colormask, glDrawBuffer state as-is */
+ }
+ else {
+ ASSERT(metaSave & META_COLOR_MASK);
+ _mesa_ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+ }
+
+ /* GL_DEPTH_BUFFER_BIT */
+ if (buffers & BUFFER_BIT_DEPTH) {
+ _mesa_set_enable(ctx, GL_DEPTH_TEST, GL_TRUE);
+ _mesa_DepthFunc(GL_ALWAYS);
+ _mesa_DepthMask(GL_TRUE);
+ }
+ else {
+ assert(!ctx->Depth.Test);
+ }
+
+ /* GL_STENCIL_BUFFER_BIT */
+ if (buffers & BUFFER_BIT_STENCIL) {
+ _mesa_set_enable(ctx, GL_STENCIL_TEST, GL_TRUE);
+ _mesa_StencilOpSeparate(GL_FRONT_AND_BACK,
+ GL_REPLACE, GL_REPLACE, GL_REPLACE);
+ _mesa_StencilFuncSeparate(GL_FRONT_AND_BACK, GL_ALWAYS,
+ ctx->Stencil.Clear & stencilMax,
+ ctx->Stencil.WriteMask[0]);
+ }
+ else {
+ assert(!ctx->Stencil.Enabled);
+ }
+
+ /* vertex positions/colors */
+ {
+ const GLfloat x0 = (GLfloat) ctx->DrawBuffer->_Xmin;
+ const GLfloat y0 = (GLfloat) ctx->DrawBuffer->_Ymin;
+ const GLfloat x1 = (GLfloat) ctx->DrawBuffer->_Xmax;
+ const GLfloat y1 = (GLfloat) ctx->DrawBuffer->_Ymax;
+ const GLfloat z = invert_z(ctx->Depth.Clear);
+ GLuint i;
+
+ verts[0].x = x0;
+ verts[0].y = y0;
+ verts[0].z = z;
+ verts[1].x = x1;
+ verts[1].y = y0;
+ verts[1].z = z;
+ verts[2].x = x1;
+ verts[2].y = y1;
+ verts[2].z = z;
+ verts[3].x = x0;
+ verts[3].y = y1;
+ verts[3].z = z;
+
+ /* vertex colors */
+ for (i = 0; i < 4; i++) {
+ verts[i].r = ctx->Color.ClearColor[0];
+ verts[i].g = ctx->Color.ClearColor[1];
+ verts[i].b = ctx->Color.ClearColor[2];
+ verts[i].a = ctx->Color.ClearColor[3];
+ }
+
+ /* upload new vertex data */
+ _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts,
+ GL_DYNAMIC_DRAW_ARB);
+ }
+
+ /* draw quad */
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ _mesa_meta_end(ctx);
+}
+
+
+/**
+ * Meta implementation of ctx->Driver.CopyPixels() in terms
+ * of texture mapping and polygon rendering.
+ */
+void
+_mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcX, GLint srcY,
+ GLsizei width, GLsizei height,
+ GLint dstX, GLint dstY, GLenum type)
+{
+ struct copypix_state *copypix = &ctx->Meta->CopyPix;
+ struct temp_texture *tex = get_temp_texture(ctx);
+ struct vertex {
+ GLfloat x, y, z, s, t;
+ };
+ struct vertex verts[4];
+ GLboolean newTex;
+ GLenum intFormat = GL_RGBA;
+
+ if (type != GL_COLOR ||
+ ctx->_ImageTransferState ||
+ ctx->Fog.Enabled ||
+ width > tex->MaxSize ||
+ height > tex->MaxSize) {
+ /* XXX avoid this fallback */
+ _swrast_CopyPixels(ctx, srcX, srcY, width, height, dstX, dstY, type);
+ return;
+ }
+
+ /* Most GL state applies to glCopyPixels, but a there's a few things
+ * we need to override:
+ */
+ _mesa_meta_begin(ctx, (META_RASTERIZATION |
+ META_SHADER |
+ META_TEXTURE |
+ META_TRANSFORM |
+ META_VERTEX |
+ META_VIEWPORT));
+
+ if (copypix->ArrayObj == 0) {
+ /* one-time setup */
+
+ /* create vertex array object */
+ _mesa_GenVertexArrays(1, &copypix->ArrayObj);
+ _mesa_BindVertexArray(copypix->ArrayObj);
+
+ /* create vertex array buffer */
+ _mesa_GenBuffersARB(1, &copypix->VBO);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, copypix->VBO);
+ _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
+ NULL, GL_DYNAMIC_DRAW_ARB);
+
+ /* setup vertex arrays */
+ _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
+ _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
+ _mesa_EnableClientState(GL_VERTEX_ARRAY);
+ _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ else {
+ _mesa_BindVertexArray(copypix->ArrayObj);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, copypix->VBO);
+ }
+
+ newTex = alloc_texture(tex, width, height, intFormat);
+
+ /* vertex positions, texcoords (after texture allocation!) */
+ {
+ const GLfloat dstX0 = (GLfloat) dstX;
+ const GLfloat dstY0 = (GLfloat) dstY;
+ const GLfloat dstX1 = dstX + width * ctx->Pixel.ZoomX;
+ const GLfloat dstY1 = dstY + height * ctx->Pixel.ZoomY;
+ const GLfloat z = invert_z(ctx->Current.RasterPos[2]);
+
+ verts[0].x = dstX0;
+ verts[0].y = dstY0;
+ verts[0].z = z;
+ verts[0].s = 0.0F;
+ verts[0].t = 0.0F;
+ verts[1].x = dstX1;
+ verts[1].y = dstY0;
+ verts[1].z = z;
+ verts[1].s = tex->Sright;
+ verts[1].t = 0.0F;
+ verts[2].x = dstX1;
+ verts[2].y = dstY1;
+ verts[2].z = z;
+ verts[2].s = tex->Sright;
+ verts[2].t = tex->Ttop;
+ verts[3].x = dstX0;
+ verts[3].y = dstY1;
+ verts[3].z = z;
+ verts[3].s = 0.0F;
+ verts[3].t = tex->Ttop;
+
+ /* upload new vertex data */
+ _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
+ }
+
+ /* Alloc/setup texture */
+ setup_copypix_texture(tex, newTex, srcX, srcY, width, height,
+ GL_RGBA, GL_NEAREST);
+
+ _mesa_set_enable(ctx, tex->Target, GL_TRUE);
+
+ /* draw textured quad */
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ _mesa_set_enable(ctx, tex->Target, GL_FALSE);
+
+ _mesa_meta_end(ctx);
+}
+
+
+
+/**
+ * When the glDrawPixels() image size is greater than the max rectangle
+ * texture size we use this function to break the glDrawPixels() image
+ * into tiles which fit into the max texture size.
+ */
+static void
+tiled_draw_pixels(struct gl_context *ctx,
+ GLint tileSize,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels)
+{
+ struct gl_pixelstore_attrib tileUnpack = *unpack;
+ GLint i, j;
+
+ if (tileUnpack.RowLength == 0)
+ tileUnpack.RowLength = width;
+
+ for (i = 0; i < width; i += tileSize) {
+ const GLint tileWidth = MIN2(tileSize, width - i);
+ const GLint tileX = (GLint) (x + i * ctx->Pixel.ZoomX);
+
+ tileUnpack.SkipPixels = unpack->SkipPixels + i;
+
+ for (j = 0; j < height; j += tileSize) {
+ const GLint tileHeight = MIN2(tileSize, height - j);
+ const GLint tileY = (GLint) (y + j * ctx->Pixel.ZoomY);
+
+ tileUnpack.SkipRows = unpack->SkipRows + j;
+
+ _mesa_meta_DrawPixels(ctx, tileX, tileY, tileWidth, tileHeight,
+ format, type, &tileUnpack, pixels);
+ }
+ }
+}
+
+
+/**
+ * One-time init for drawing stencil pixels.
+ */
+static void
+init_draw_stencil_pixels(struct gl_context *ctx)
+{
+ /* This program is run eight times, once for each stencil bit.
+ * The stencil values to draw are found in an 8-bit alpha texture.
+ * We read the texture/stencil value and test if bit 'b' is set.
+ * If the bit is not set, use KIL to kill the fragment.
+ * Finally, we use the stencil test to update the stencil buffer.
+ *
+ * The basic algorithm for checking if a bit is set is:
+ * if (is_odd(value / (1 << bit)))
+ * result is one (or non-zero).
+ * else
+ * result is zero.
+ * The program parameter contains three values:
+ * parm.x = 255 / (1 << bit)
+ * parm.y = 0.5
+ * parm.z = 0.0
+ */
+ static const char *program =
+ "!!ARBfp1.0\n"
+ "PARAM parm = program.local[0]; \n"
+ "TEMP t; \n"
+ "TEX t, fragment.texcoord[0], texture[0], %s; \n" /* NOTE %s here! */
+ "# t = t * 255 / bit \n"
+ "MUL t.x, t.a, parm.x; \n"
+ "# t = (int) t \n"
+ "FRC t.y, t.x; \n"
+ "SUB t.x, t.x, t.y; \n"
+ "# t = t * 0.5 \n"
+ "MUL t.x, t.x, parm.y; \n"
+ "# t = fract(t.x) \n"
+ "FRC t.x, t.x; # if t.x != 0, then the bit is set \n"
+ "# t.x = (t.x == 0 ? 1 : 0) \n"
+ "SGE t.x, -t.x, parm.z; \n"
+ "KIL -t.x; \n"
+ "# for debug only \n"
+ "#MOV result.color, t.x; \n"
+ "END \n";
+ char program2[1000];
+ struct drawpix_state *drawpix = &ctx->Meta->DrawPix;
+ struct temp_texture *tex = get_temp_texture(ctx);
+ const char *texTarget;
+
+ assert(drawpix->StencilFP == 0);
+
+ /* replace %s with "RECT" or "2D" */
+ assert(strlen(program) + 4 < sizeof(program2));
+ if (tex->Target == GL_TEXTURE_RECTANGLE)
+ texTarget = "RECT";
+ else
+ texTarget = "2D";
+ _mesa_snprintf(program2, sizeof(program2), program, texTarget);
+
+ _mesa_GenPrograms(1, &drawpix->StencilFP);
+ _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->StencilFP);
+ _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+ strlen(program2), (const GLubyte *) program2);
+}
+
+
+/**
+ * One-time init for drawing depth pixels.
+ */
+static void
+init_draw_depth_pixels(struct gl_context *ctx)
+{
+ static const char *program =
+ "!!ARBfp1.0\n"
+ "PARAM color = program.local[0]; \n"
+ "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n"
+ "MOV result.color, color; \n"
+ "END \n";
+ char program2[200];
+ struct drawpix_state *drawpix = &ctx->Meta->DrawPix;
+ struct temp_texture *tex = get_temp_texture(ctx);
+ const char *texTarget;
+
+ assert(drawpix->DepthFP == 0);
+
+ /* replace %s with "RECT" or "2D" */
+ assert(strlen(program) + 4 < sizeof(program2));
+ if (tex->Target == GL_TEXTURE_RECTANGLE)
+ texTarget = "RECT";
+ else
+ texTarget = "2D";
+ _mesa_snprintf(program2, sizeof(program2), program, texTarget);
+
+ _mesa_GenPrograms(1, &drawpix->DepthFP);
+ _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->DepthFP);
+ _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+ strlen(program2), (const GLubyte *) program2);
+}
+
+
+/**
+ * Meta implementation of ctx->Driver.DrawPixels() in terms
+ * of texture mapping and polygon rendering.
+ */
+void
+_mesa_meta_DrawPixels(struct gl_context *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels)
+{
+ struct drawpix_state *drawpix = &ctx->Meta->DrawPix;
+ struct temp_texture *tex = get_temp_texture(ctx);
+ const struct gl_pixelstore_attrib unpackSave = ctx->Unpack;
+ const GLuint origStencilMask = ctx->Stencil.WriteMask[0];
+ struct vertex {
+ GLfloat x, y, z, s, t;
+ };
+ struct vertex verts[4];
+ GLenum texIntFormat;
+ GLboolean fallback, newTex;
+ GLbitfield metaExtraSave = 0x0;
+ GLuint vbo;
+
+ /*
+ * Determine if we can do the glDrawPixels with texture mapping.
+ */
+ fallback = GL_FALSE;
+ if (ctx->_ImageTransferState ||
+ ctx->Fog.Enabled) {
+ fallback = GL_TRUE;
+ }
+
+ if (_mesa_is_color_format(format)) {
+ /* use more compact format when possible */
+ /* XXX disable special case for GL_LUMINANCE for now to work around
+ * apparent i965 driver bug (see bug #23670).
+ */
+ if (/*format == GL_LUMINANCE ||*/ format == GL_LUMINANCE_ALPHA)
+ texIntFormat = format;
+ else
+ texIntFormat = GL_RGBA;
+ }
+ else if (_mesa_is_stencil_format(format)) {
+ if (ctx->Extensions.ARB_fragment_program &&
+ ctx->Pixel.IndexShift == 0 &&
+ ctx->Pixel.IndexOffset == 0 &&
+ type == GL_UNSIGNED_BYTE) {
+ /* We'll store stencil as alpha. This only works for GLubyte
+ * image data because of how incoming values are mapped to alpha
+ * in [0,1].
+ */
+ texIntFormat = GL_ALPHA;
+ metaExtraSave = (META_COLOR_MASK |
+ META_DEPTH_TEST |
+ META_SHADER |
+ META_STENCIL_TEST);
+ }
+ else {
+ fallback = GL_TRUE;
+ }
+ }
+ else if (_mesa_is_depth_format(format)) {
+ if (ctx->Extensions.ARB_depth_texture &&
+ ctx->Extensions.ARB_fragment_program) {
+ texIntFormat = GL_DEPTH_COMPONENT;
+ metaExtraSave = (META_SHADER);
+ }
+ else {
+ fallback = GL_TRUE;
+ }
+ }
+ else {
+ fallback = GL_TRUE;
+ }
+
+ if (fallback) {
+ _swrast_DrawPixels(ctx, x, y, width, height,
+ format, type, unpack, pixels);
+ return;
+ }
+
+ /*
+ * Check image size against max texture size, draw as tiles if needed.
+ */
+ if (width > tex->MaxSize || height > tex->MaxSize) {
+ tiled_draw_pixels(ctx, tex->MaxSize, x, y, width, height,
+ format, type, unpack, pixels);
+ return;
+ }
+
+ /* Most GL state applies to glDrawPixels (like blending, stencil, etc),
+ * but a there's a few things we need to override:
+ */
+ _mesa_meta_begin(ctx, (META_RASTERIZATION |
+ META_SHADER |
+ META_TEXTURE |
+ META_TRANSFORM |
+ META_VERTEX |
+ META_VIEWPORT |
+ metaExtraSave));
+
+ newTex = alloc_texture(tex, width, height, texIntFormat);
+
+ /* vertex positions, texcoords (after texture allocation!) */
+ {
+ const GLfloat x0 = (GLfloat) x;
+ const GLfloat y0 = (GLfloat) y;
+ const GLfloat x1 = x + width * ctx->Pixel.ZoomX;
+ const GLfloat y1 = y + height * ctx->Pixel.ZoomY;
+ const GLfloat z = invert_z(ctx->Current.RasterPos[2]);
+
+ verts[0].x = x0;
+ verts[0].y = y0;
+ verts[0].z = z;
+ verts[0].s = 0.0F;
+ verts[0].t = 0.0F;
+ verts[1].x = x1;
+ verts[1].y = y0;
+ verts[1].z = z;
+ verts[1].s = tex->Sright;
+ verts[1].t = 0.0F;
+ verts[2].x = x1;
+ verts[2].y = y1;
+ verts[2].z = z;
+ verts[2].s = tex->Sright;
+ verts[2].t = tex->Ttop;
+ verts[3].x = x0;
+ verts[3].y = y1;
+ verts[3].z = z;
+ verts[3].s = 0.0F;
+ verts[3].t = tex->Ttop;
+ }
+
+ if (drawpix->ArrayObj == 0) {
+ /* one-time setup: create vertex array object */
+ _mesa_GenVertexArrays(1, &drawpix->ArrayObj);
+ }
+ _mesa_BindVertexArray(drawpix->ArrayObj);
+
+ /* create vertex array buffer */
+ _mesa_GenBuffersARB(1, &vbo);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
+ _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
+ verts, GL_DYNAMIC_DRAW_ARB);
+
+ /* setup vertex arrays */
+ _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
+ _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
+ _mesa_EnableClientState(GL_VERTEX_ARRAY);
+ _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ /* set given unpack params */
+ ctx->Unpack = *unpack;
+
+ _mesa_set_enable(ctx, tex->Target, GL_TRUE);
+
+ if (_mesa_is_stencil_format(format)) {
+ /* Drawing stencil */
+ GLint bit;
+
+ if (!drawpix->StencilFP)
+ init_draw_stencil_pixels(ctx);
+
+ setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height,
+ GL_ALPHA, type, pixels);
+
+ _mesa_ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+
+ _mesa_set_enable(ctx, GL_STENCIL_TEST, GL_TRUE);
+
+ /* set all stencil bits to 0 */
+ _mesa_StencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
+ _mesa_StencilFunc(GL_ALWAYS, 0, 255);
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ /* set stencil bits to 1 where needed */
+ _mesa_StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
+
+ _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->StencilFP);
+ _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_TRUE);
+
+ for (bit = 0; bit < ctx->DrawBuffer->Visual.stencilBits; bit++) {
+ const GLuint mask = 1 << bit;
+ if (mask & origStencilMask) {
+ _mesa_StencilFunc(GL_ALWAYS, mask, mask);
+ _mesa_StencilMask(mask);
+
+ _mesa_ProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0,
+ 255.0 / mask, 0.5, 0.0, 0.0);
+
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ }
+ }
+ }
+ else if (_mesa_is_depth_format(format)) {
+ /* Drawing depth */
+ if (!drawpix->DepthFP)
+ init_draw_depth_pixels(ctx);
+
+ _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->DepthFP);
+ _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_TRUE);
+
+ /* polygon color = current raster color */
+ _mesa_ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0,
+ ctx->Current.RasterColor);
+
+ setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height,
+ format, type, pixels);
+
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ }
+ else {
+ /* Drawing RGBA */
+ setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height,
+ format, type, pixels);
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ }
+
+ _mesa_set_enable(ctx, tex->Target, GL_FALSE);
+
+ _mesa_DeleteBuffersARB(1, &vbo);
+
+ /* restore unpack params */
+ ctx->Unpack = unpackSave;
+
+ _mesa_meta_end(ctx);
+}
+
+static GLboolean
+alpha_test_raster_color(struct gl_context *ctx)
+{
+ GLfloat alpha = ctx->Current.RasterColor[ACOMP];
+ GLfloat ref = ctx->Color.AlphaRef;
+
+ switch (ctx->Color.AlphaFunc) {
+ case GL_NEVER:
+ return GL_FALSE;
+ case GL_LESS:
+ return alpha < ref;
+ case GL_EQUAL:
+ return alpha == ref;
+ case GL_LEQUAL:
+ return alpha <= ref;
+ case GL_GREATER:
+ return alpha > ref;
+ case GL_NOTEQUAL:
+ return alpha != ref;
+ case GL_GEQUAL:
+ return alpha >= ref;
+ case GL_ALWAYS:
+ return GL_TRUE;
+ default:
+ assert(0);
+ return GL_FALSE;
+ }
+}
+
+/**
+ * Do glBitmap with a alpha texture quad. Use the alpha test to cull
+ * the 'off' bits. A bitmap cache as in the gallium/mesa state
+ * tracker would improve performance a lot.
+ */
+void
+_mesa_meta_Bitmap(struct gl_context *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLubyte *bitmap1)
+{
+ struct bitmap_state *bitmap = &ctx->Meta->Bitmap;
+ struct temp_texture *tex = get_bitmap_temp_texture(ctx);
+ const GLenum texIntFormat = GL_ALPHA;
+ const struct gl_pixelstore_attrib unpackSave = *unpack;
+ GLubyte fg, bg;
+ struct vertex {
+ GLfloat x, y, z, s, t, r, g, b, a;
+ };
+ struct vertex verts[4];
+ GLboolean newTex;
+ GLubyte *bitmap8;
+
+ /*
+ * Check if swrast fallback is needed.
+ */
+ if (ctx->_ImageTransferState ||
+ ctx->FragmentProgram._Enabled ||
+ ctx->Fog.Enabled ||
+ ctx->Texture._EnabledUnits ||
+ width > tex->MaxSize ||
+ height > tex->MaxSize) {
+ _swrast_Bitmap(ctx, x, y, width, height, unpack, bitmap1);
+ return;
+ }
+
+ if (ctx->Color.AlphaEnabled && !alpha_test_raster_color(ctx))
+ return;
+
+ /* Most GL state applies to glBitmap (like blending, stencil, etc),
+ * but a there's a few things we need to override:
+ */
+ _mesa_meta_begin(ctx, (META_ALPHA_TEST |
+ META_PIXEL_STORE |
+ META_RASTERIZATION |
+ META_SHADER |
+ META_TEXTURE |
+ META_TRANSFORM |
+ META_VERTEX |
+ META_VIEWPORT));
+
+ if (bitmap->ArrayObj == 0) {
+ /* one-time setup */
+
+ /* create vertex array object */
+ _mesa_GenVertexArraysAPPLE(1, &bitmap->ArrayObj);
+ _mesa_BindVertexArrayAPPLE(bitmap->ArrayObj);
+
+ /* create vertex array buffer */
+ _mesa_GenBuffersARB(1, &bitmap->VBO);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, bitmap->VBO);
+ _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
+ NULL, GL_DYNAMIC_DRAW_ARB);
+
+ /* setup vertex arrays */
+ _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
+ _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
+ _mesa_ColorPointer(4, GL_FLOAT, sizeof(struct vertex), OFFSET(r));
+ _mesa_EnableClientState(GL_VERTEX_ARRAY);
+ _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
+ _mesa_EnableClientState(GL_COLOR_ARRAY);
+ }
+ else {
+ _mesa_BindVertexArray(bitmap->ArrayObj);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, bitmap->VBO);
+ }
+
+ newTex = alloc_texture(tex, width, height, texIntFormat);
+
+ /* vertex positions, texcoords, colors (after texture allocation!) */
+ {
+ const GLfloat x0 = (GLfloat) x;
+ const GLfloat y0 = (GLfloat) y;
+ const GLfloat x1 = (GLfloat) (x + width);
+ const GLfloat y1 = (GLfloat) (y + height);
+ const GLfloat z = invert_z(ctx->Current.RasterPos[2]);
+ GLuint i;
+
+ verts[0].x = x0;
+ verts[0].y = y0;
+ verts[0].z = z;
+ verts[0].s = 0.0F;
+ verts[0].t = 0.0F;
+ verts[1].x = x1;
+ verts[1].y = y0;
+ verts[1].z = z;
+ verts[1].s = tex->Sright;
+ verts[1].t = 0.0F;
+ verts[2].x = x1;
+ verts[2].y = y1;
+ verts[2].z = z;
+ verts[2].s = tex->Sright;
+ verts[2].t = tex->Ttop;
+ verts[3].x = x0;
+ verts[3].y = y1;
+ verts[3].z = z;
+ verts[3].s = 0.0F;
+ verts[3].t = tex->Ttop;
+
+ for (i = 0; i < 4; i++) {
+ verts[i].r = ctx->Current.RasterColor[0];
+ verts[i].g = ctx->Current.RasterColor[1];
+ verts[i].b = ctx->Current.RasterColor[2];
+ verts[i].a = ctx->Current.RasterColor[3];
+ }
+
+ /* upload new vertex data */
+ _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
+ }
+
+ /* choose different foreground/background alpha values */
+ CLAMPED_FLOAT_TO_UBYTE(fg, ctx->Current.RasterColor[ACOMP]);
+ bg = (fg > 127 ? 0 : 255);
+
+ bitmap1 = _mesa_map_pbo_source(ctx, &unpackSave, bitmap1);
+ if (!bitmap1) {
+ _mesa_meta_end(ctx);
+ return;
+ }
+
+ bitmap8 = (GLubyte *) malloc(width * height);
+ if (bitmap8) {
+ memset(bitmap8, bg, width * height);
+ _mesa_expand_bitmap(width, height, &unpackSave, bitmap1,
+ bitmap8, width, fg);
+
+ _mesa_set_enable(ctx, tex->Target, GL_TRUE);
+
+ _mesa_set_enable(ctx, GL_ALPHA_TEST, GL_TRUE);
+ _mesa_AlphaFunc(GL_NOTEQUAL, UBYTE_TO_FLOAT(bg));
+
+ setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height,
+ GL_ALPHA, GL_UNSIGNED_BYTE, bitmap8);
+
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ _mesa_set_enable(ctx, tex->Target, GL_FALSE);
+
+ free(bitmap8);
+ }
+
+ _mesa_unmap_pbo_source(ctx, &unpackSave);
+
+ _mesa_meta_end(ctx);
+}
+
+
+/**
+ * Check if the call to _mesa_meta_GenerateMipmap() will require a
+ * software fallback. The fallback path will require that the texture
+ * images are mapped.
+ * \return GL_TRUE if a fallback is needed, GL_FALSE otherwise
+ */
+GLboolean
+_mesa_meta_check_generate_mipmap_fallback(struct gl_context *ctx, GLenum target,
+ struct gl_texture_object *texObj)
+{
+ const GLuint fboSave = ctx->DrawBuffer->Name;
+ struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap;
+ struct gl_texture_image *baseImage;
+ GLuint srcLevel;
+ GLenum status;
+
+ /* check for fallbacks */
+ if (!ctx->Extensions.EXT_framebuffer_object ||
+ target == GL_TEXTURE_3D) {
+ return GL_TRUE;
+ }
+
+ srcLevel = texObj->BaseLevel;
+ baseImage = _mesa_select_tex_image(ctx, texObj, target, srcLevel);
+ if (!baseImage || _mesa_is_format_compressed(baseImage->TexFormat)) {
+ return GL_TRUE;
+ }
+
+ /*
+ * Test that we can actually render in the texture's format.
+ */
+ if (!mipmap->FBO)
+ _mesa_GenFramebuffersEXT(1, &mipmap->FBO);
+ _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mipmap->FBO);
+
+ if (target == GL_TEXTURE_1D) {
+ _mesa_FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ target, texObj->Name, srcLevel);
+ }
+#if 0
+ /* other work is needed to enable 3D mipmap generation */
+ else if (target == GL_TEXTURE_3D) {
+ GLint zoffset = 0;
+ _mesa_FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ target, texObj->Name, srcLevel, zoffset);
+ }
+#endif
+ else {
+ /* 2D / cube */
+ _mesa_FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ target, texObj->Name, srcLevel);
+ }
+
+ status = _mesa_CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+
+ _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSave);
+
+ if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+
+/**
+ * Called via ctx->Driver.GenerateMipmap()
+ * Note: texture borders and 3D texture support not yet complete.
+ */
+void
+_mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
+ struct gl_texture_object *texObj)
+{
+ struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap;
+ struct vertex {
+ GLfloat x, y, s, t, r;
+ };
+ struct vertex verts[4];
+ const GLuint baseLevel = texObj->BaseLevel;
+ const GLuint maxLevel = texObj->MaxLevel;
+ const GLenum minFilterSave = texObj->MinFilter;
+ const GLenum magFilterSave = texObj->MagFilter;
+ const GLint maxLevelSave = texObj->MaxLevel;
+ const GLboolean genMipmapSave = texObj->GenerateMipmap;
+ const GLenum wrapSSave = texObj->WrapS;
+ const GLenum wrapTSave = texObj->WrapT;
+ const GLenum wrapRSave = texObj->WrapR;
+ const GLuint fboSave = ctx->DrawBuffer->Name;
+ const GLuint original_active_unit = ctx->Texture.CurrentUnit;
+ GLenum faceTarget;
+ GLuint dstLevel;
+ GLuint border = 0;
+
+ if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, texObj)) {
+ _mesa_generate_mipmap(ctx, target, texObj);
+ return;
+ }
+
+ if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
+ target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) {
+ faceTarget = target;
+ target = GL_TEXTURE_CUBE_MAP;
+ }
+ else {
+ faceTarget = target;
+ }
+
+ _mesa_meta_begin(ctx, META_ALL);
+
+ if (original_active_unit != 0)
+ _mesa_BindTexture(target, texObj->Name);
+
+ if (mipmap->ArrayObj == 0) {
+ /* one-time setup */
+
+ /* create vertex array object */
+ _mesa_GenVertexArraysAPPLE(1, &mipmap->ArrayObj);
+ _mesa_BindVertexArrayAPPLE(mipmap->ArrayObj);
+
+ /* create vertex array buffer */
+ _mesa_GenBuffersARB(1, &mipmap->VBO);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, mipmap->VBO);
+ _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts),
+ NULL, GL_DYNAMIC_DRAW_ARB);
+
+ /* setup vertex arrays */
+ _mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
+ _mesa_TexCoordPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(s));
+ _mesa_EnableClientState(GL_VERTEX_ARRAY);
+ _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ else {
+ _mesa_BindVertexArray(mipmap->ArrayObj);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, mipmap->VBO);
+ }
+
+ if (!mipmap->FBO) {
+ _mesa_GenFramebuffersEXT(1, &mipmap->FBO);
+ }
+ _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mipmap->FBO);
+
+ _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ _mesa_TexParameteri(target, GL_GENERATE_MIPMAP, GL_FALSE);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+
+ _mesa_set_enable(ctx, target, GL_TRUE);
+
+ /* setup texcoords once (XXX what about border?) */
+ switch (faceTarget) {
+ case GL_TEXTURE_1D:
+ case GL_TEXTURE_2D:
+ verts[0].s = 0.0F;
+ verts[0].t = 0.0F;
+ verts[0].r = 0.0F;
+ verts[1].s = 1.0F;
+ verts[1].t = 0.0F;
+ verts[1].r = 0.0F;
+ verts[2].s = 1.0F;
+ verts[2].t = 1.0F;
+ verts[2].r = 0.0F;
+ verts[3].s = 0.0F;
+ verts[3].t = 1.0F;
+ verts[3].r = 0.0F;
+ break;
+ case GL_TEXTURE_3D:
+ abort();
+ break;
+ default:
+ /* cube face */
+ {
+ static const GLfloat st[4][2] = {
+ {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}
+ };
+ GLuint i;
+
+ /* loop over quad verts */
+ for (i = 0; i < 4; i++) {
+ /* Compute sc = +/-scale and tc = +/-scale.
+ * Not +/-1 to avoid cube face selection ambiguity near the edges,
+ * though that can still sometimes happen with this scale factor...
+ */
+ const GLfloat scale = 0.9999f;
+ const GLfloat sc = (2.0f * st[i][0] - 1.0f) * scale;
+ const GLfloat tc = (2.0f * st[i][1] - 1.0f) * scale;
+
+ switch (faceTarget) {
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ verts[i].s = 1.0f;
+ verts[i].t = -tc;
+ verts[i].r = -sc;
+ break;
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ verts[i].s = -1.0f;
+ verts[i].t = -tc;
+ verts[i].r = sc;
+ break;
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ verts[i].s = sc;
+ verts[i].t = 1.0f;
+ verts[i].r = tc;
+ break;
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ verts[i].s = sc;
+ verts[i].t = -1.0f;
+ verts[i].r = -tc;
+ break;
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ verts[i].s = sc;
+ verts[i].t = -tc;
+ verts[i].r = 1.0f;
+ break;
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ verts[i].s = -sc;
+ verts[i].t = -tc;
+ verts[i].r = -1.0f;
+ break;
+ default:
+ assert(0);
+ }
+ }
+ }
+ }
+
+ _mesa_set_enable(ctx, target, GL_TRUE);
+
+ /* setup vertex positions */
+ {
+ verts[0].x = 0.0F;
+ verts[0].y = 0.0F;
+ verts[1].x = 1.0F;
+ verts[1].y = 0.0F;
+ verts[2].x = 1.0F;
+ verts[2].y = 1.0F;
+ verts[3].x = 0.0F;
+ verts[3].y = 1.0F;
+
+ /* upload new vertex data */
+ _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
+ }
+
+ /* setup projection matrix */
+ _mesa_MatrixMode(GL_PROJECTION);
+ _mesa_LoadIdentity();
+ _mesa_Ortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
+
+ /* texture is already locked, unlock now */
+ _mesa_unlock_texture(ctx, texObj);
+
+ for (dstLevel = baseLevel + 1; dstLevel <= maxLevel; dstLevel++) {
+ const struct gl_texture_image *srcImage;
+ const GLuint srcLevel = dstLevel - 1;
+ GLsizei srcWidth, srcHeight, srcDepth;
+ GLsizei dstWidth, dstHeight, dstDepth;
+ GLenum status;
+
+ srcImage = _mesa_select_tex_image(ctx, texObj, faceTarget, srcLevel);
+ assert(srcImage->Border == 0); /* XXX we can fix this */
+
+ /* src size w/out border */
+ srcWidth = srcImage->Width - 2 * border;
+ srcHeight = srcImage->Height - 2 * border;
+ srcDepth = srcImage->Depth - 2 * border;
+
+ /* new dst size w/ border */
+ dstWidth = MAX2(1, srcWidth / 2) + 2 * border;
+ dstHeight = MAX2(1, srcHeight / 2) + 2 * border;
+ dstDepth = MAX2(1, srcDepth / 2) + 2 * border;
+
+ if (dstWidth == srcImage->Width &&
+ dstHeight == srcImage->Height &&
+ dstDepth == srcImage->Depth) {
+ /* all done */
+ break;
+ }
+
+ /* Set MaxLevel large enough to hold the new level when we allocate it */
+ _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, dstLevel);
+
+ /* Create empty dest image */
+ if (target == GL_TEXTURE_1D) {
+ _mesa_TexImage1D(target, dstLevel, srcImage->InternalFormat,
+ dstWidth, border,
+ GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ }
+ else if (target == GL_TEXTURE_3D) {
+ _mesa_TexImage3D(target, dstLevel, srcImage->InternalFormat,
+ dstWidth, dstHeight, dstDepth, border,
+ GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ }
+ else {
+ /* 2D or cube */
+ _mesa_TexImage2D(faceTarget, dstLevel, srcImage->InternalFormat,
+ dstWidth, dstHeight, border,
+ GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+
+ if (target == GL_TEXTURE_CUBE_MAP) {
+ /* If texturing from a cube, we need to make sure all src faces
+ * have been defined (even if we're not sampling from them.)
+ * Otherwise the texture object will be 'incomplete' and
+ * texturing from it will not be allowed.
+ */
+ GLuint face;
+ for (face = 0; face < 6; face++) {
+ if (!texObj->Image[face][srcLevel] ||
+ texObj->Image[face][srcLevel]->Width != srcWidth) {
+ _mesa_TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face,
+ srcLevel, srcImage->InternalFormat,
+ srcWidth, srcHeight, border,
+ GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ }
+ }
+ }
+ }
+
+ /* limit minification to src level */
+ _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, srcLevel);
+
+ /* Set to draw into the current dstLevel */
+ if (target == GL_TEXTURE_1D) {
+ _mesa_FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ target,
+ texObj->Name,
+ dstLevel);
+ }
+ else if (target == GL_TEXTURE_3D) {
+ GLint zoffset = 0; /* XXX unfinished */
+ _mesa_FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ target,
+ texObj->Name,
+ dstLevel, zoffset);
+ }
+ else {
+ /* 2D / cube */
+ _mesa_FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ faceTarget,
+ texObj->Name,
+ dstLevel);
+ }
+
+ _mesa_DrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+
+ /* sanity check */
+ status = _mesa_CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+ if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ abort();
+ break;
+ }
+
+ assert(dstWidth == ctx->DrawBuffer->Width);
+ assert(dstHeight == ctx->DrawBuffer->Height);
+
+ /* setup viewport */
+ _mesa_set_viewport(ctx, 0, 0, dstWidth, dstHeight);
+
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ }
+
+ _mesa_lock_texture(ctx, texObj); /* relock */
+
+ _mesa_meta_end(ctx);
+
+ _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilterSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilterSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
+ _mesa_TexParameteri(target, GL_GENERATE_MIPMAP, genMipmapSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, wrapSSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, wrapTSave);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, wrapRSave);
+
+ _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSave);
+}
+
+
+/**
+ * Determine the GL data type to use for the temporary image read with
+ * ReadPixels() and passed to Tex[Sub]Image().
+ */
+static GLenum
+get_temp_image_type(struct gl_context *ctx, GLenum baseFormat)
+{
+ switch (baseFormat) {
+ case GL_RGBA:
+ case GL_RGB:
+ case GL_ALPHA:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE_ALPHA:
+ case GL_INTENSITY:
+ if (ctx->DrawBuffer->Visual.redBits <= 8)
+ return GL_UNSIGNED_BYTE;
+ else if (ctx->DrawBuffer->Visual.redBits <= 8)
+ return GL_UNSIGNED_SHORT;
+ else
+ return GL_FLOAT;
+ case GL_DEPTH_COMPONENT:
+ return GL_UNSIGNED_INT;
+ case GL_DEPTH_STENCIL:
+ return GL_UNSIGNED_INT_24_8;
+ default:
+ _mesa_problem(ctx, "Unexpected format in get_temp_image_type()");
+ return 0;
+ }
+}
+
+
+/**
+ * Helper for _mesa_meta_CopyTexImage1/2D() functions.
+ * Have to be careful with locking and meta state for pixel transfer.
+ */
+static void
+copy_tex_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
+ GLenum internalFormat, GLint x, GLint y,
+ GLsizei width, GLsizei height, GLint border)
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ GLenum format, type;
+ GLint bpp;
+ void *buf;
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+ texImage = _mesa_get_tex_image(ctx, texObj, target, level);
+
+ /* Choose format/type for temporary image buffer */
+ format = _mesa_base_tex_format(ctx, internalFormat);
+ type = get_temp_image_type(ctx, format);
+ bpp = _mesa_bytes_per_pixel(format, type);
+ if (bpp <= 0) {
+ _mesa_problem(ctx, "Bad bpp in meta copy_tex_image()");
+ return;
+ }
+
+ /*
+ * Alloc image buffer (XXX could use a PBO)
+ */
+ buf = malloc(width * height * bpp);
+ if (!buf) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims);
+ return;
+ }
+
+ _mesa_unlock_texture(ctx, texObj); /* need to unlock first */
+
+ /*
+ * Read image from framebuffer (disable pixel transfer ops)
+ */
+ _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER);
+ ctx->Driver.ReadPixels(ctx, x, y, width, height,
+ format, type, &ctx->Pack, buf);
+ _mesa_meta_end(ctx);
+
+ if (texImage->Data) {
+ ctx->Driver.FreeTexImageData(ctx, texImage);
+ }
+
+ /* The texture's format was already chosen in _mesa_CopyTexImage() */
+ ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
+
+ /*
+ * Store texture data (with pixel transfer ops)
+ */
+ _mesa_meta_begin(ctx, META_PIXEL_STORE);
+
+ _mesa_update_state(ctx); /* to update pixel transfer state */
+
+ if (target == GL_TEXTURE_1D) {
+ ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
+ width, border, format, type,
+ buf, &ctx->Unpack, texObj, texImage);
+ }
+ else {
+ ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
+ width, height, border, format, type,
+ buf, &ctx->Unpack, texObj, texImage);
+ }
+ _mesa_meta_end(ctx);
+
+ _mesa_lock_texture(ctx, texObj); /* re-lock */
+
+ free(buf);
+}
+
+
+void
+_mesa_meta_CopyTexImage1D(struct gl_context *ctx, GLenum target, GLint level,
+ GLenum internalFormat, GLint x, GLint y,
+ GLsizei width, GLint border)
+{
+ copy_tex_image(ctx, 1, target, level, internalFormat, x, y,
+ width, 1, border);
+}
+
+
+void
+_mesa_meta_CopyTexImage2D(struct gl_context *ctx, GLenum target, GLint level,
+ GLenum internalFormat, GLint x, GLint y,
+ GLsizei width, GLsizei height, GLint border)
+{
+ copy_tex_image(ctx, 2, target, level, internalFormat, x, y,
+ width, height, border);
+}
+
+
+
+/**
+ * Helper for _mesa_meta_CopyTexSubImage1/2/3D() functions.
+ * Have to be careful with locking and meta state for pixel transfer.
+ */
+static void
+copy_tex_sub_image(struct gl_context *ctx,
+ GLuint dims, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height)
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ GLenum format, type;
+ GLint bpp;
+ void *buf;
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+ texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+
+ /* Choose format/type for temporary image buffer */
+ format = _mesa_get_format_base_format(texImage->TexFormat);
+ type = get_temp_image_type(ctx, format);
+ bpp = _mesa_bytes_per_pixel(format, type);
+ if (bpp <= 0) {
+ _mesa_problem(ctx, "Bad bpp in meta copy_tex_sub_image()");
+ return;
+ }
+
+ /*
+ * Alloc image buffer (XXX could use a PBO)
+ */
+ buf = malloc(width * height * bpp);
+ if (!buf) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage%uD", dims);
+ return;
+ }
+
+ _mesa_unlock_texture(ctx, texObj); /* need to unlock first */
+
+ /*
+ * Read image from framebuffer (disable pixel transfer ops)
+ */
+ _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER);
+ ctx->Driver.ReadPixels(ctx, x, y, width, height,
+ format, type, &ctx->Pack, buf);
+ _mesa_meta_end(ctx);
+
+ _mesa_update_state(ctx); /* to update pixel transfer state */
+
+ /*
+ * Store texture data (with pixel transfer ops)
+ */
+ _mesa_meta_begin(ctx, META_PIXEL_STORE);
+ if (target == GL_TEXTURE_1D) {
+ ctx->Driver.TexSubImage1D(ctx, target, level, xoffset,
+ width, format, type, buf,
+ &ctx->Unpack, texObj, texImage);
+ }
+ else if (target == GL_TEXTURE_3D) {
+ ctx->Driver.TexSubImage3D(ctx, target, level, xoffset, yoffset, zoffset,
+ width, height, 1, format, type, buf,
+ &ctx->Unpack, texObj, texImage);
+ }
+ else {
+ ctx->Driver.TexSubImage2D(ctx, target, level, xoffset, yoffset,
+ width, height, format, type, buf,
+ &ctx->Unpack, texObj, texImage);
+ }
+ _mesa_meta_end(ctx);
+
+ _mesa_lock_texture(ctx, texObj); /* re-lock */
+
+ free(buf);
+}
+
+
+void
+_mesa_meta_CopyTexSubImage1D(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset,
+ GLint x, GLint y, GLsizei width)
+{
+ copy_tex_sub_image(ctx, 1, target, level, xoffset, 0, 0,
+ x, y, width, 1);
+}
+
+
+void
+_mesa_meta_CopyTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height)
+{
+ copy_tex_sub_image(ctx, 2, target, level, xoffset, yoffset, 0,
+ x, y, width, height);
+}
+
+
+void
+_mesa_meta_CopyTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height)
+{
+ copy_tex_sub_image(ctx, 3, target, level, xoffset, yoffset, zoffset,
+ x, y, width, height);
+}
+
+
+void
+_mesa_meta_CopyColorTable(struct gl_context *ctx,
+ GLenum target, GLenum internalformat,
+ GLint x, GLint y, GLsizei width)
+{
+ GLfloat *buf;
+
+ buf = (GLfloat *) malloc(width * 4 * sizeof(GLfloat));
+ if (!buf) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyColorTable");
+ return;
+ }
+
+ /*
+ * Read image from framebuffer (disable pixel transfer ops)
+ */
+ _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER);
+ ctx->Driver.ReadPixels(ctx, x, y, width, 1,
+ GL_RGBA, GL_FLOAT, &ctx->Pack, buf);
+
+ _mesa_ColorTable(target, internalformat, width, GL_RGBA, GL_FLOAT, buf);
+
+ _mesa_meta_end(ctx);
+
+ free(buf);
+}
+
+
+void
+_mesa_meta_CopyColorSubTable(struct gl_context *ctx,GLenum target, GLsizei start,
+ GLint x, GLint y, GLsizei width)
+{
+ GLfloat *buf;
+
+ buf = (GLfloat *) malloc(width * 4 * sizeof(GLfloat));
+ if (!buf) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyColorSubTable");
+ return;
+ }
+
+ /*
+ * Read image from framebuffer (disable pixel transfer ops)
+ */
+ _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER);
+ ctx->Driver.ReadPixels(ctx, x, y, width, 1,
+ GL_RGBA, GL_FLOAT, &ctx->Pack, buf);
+
+ _mesa_ColorSubTable(target, start, width, GL_RGBA, GL_FLOAT, buf);
+
+ _mesa_meta_end(ctx);
+
+ free(buf);
+}
diff --git a/mesalib/src/mesa/drivers/dri/Makefile.template b/mesalib/src/mesa/drivers/dri/Makefile.template
index d1a119379..195d60a9c 100644
--- a/mesalib/src/mesa/drivers/dri/Makefile.template
+++ b/mesalib/src/mesa/drivers/dri/Makefile.template
@@ -1,111 +1,111 @@
-# -*-makefile-*-
-
-COMMON_GALLIUM_SOURCES = \
- ../common/utils.c \
- ../common/vblank.c \
- ../common/dri_util.c \
- ../common/xmlconfig.c
-
-COMMON_SOURCES = $(COMMON_GALLIUM_SOURCES) \
- ../../common/driverfuncs.c \
- ../common/texmem.c \
- ../common/drirenderbuffer.c
-
-INCLUDES = $(SHARED_INCLUDES) $(EXPAT_INCLUDES)
-
-OBJECTS = $(C_SOURCES:.c=.o) \
- $(CXX_SOURCES:.cpp=.o) \
- $(ASM_SOURCES:.S=.o)
-
-
-### Include directories
-SHARED_INCLUDES = \
- -I. \
- -I$(TOP)/src/mesa/drivers/dri/common \
- -Iserver \
- -I$(TOP)/include \
- -I$(TOP)/src/mapi \
- -I$(TOP)/src/mesa \
- -I$(TOP)/src/egl/main \
- -I$(TOP)/src/egl/drivers/dri \
- $(LIBDRM_CFLAGS)
-
-CFLAGS += $(API_DEFINES)
-CXXFLAGS += $(API_DEFINES)
-
-##### RULES #####
-
-.c.o:
- $(CC) -c $(INCLUDES) $(DRI_CFLAGS) $(DRIVER_DEFINES) $< -o $@
-
-.cpp.o:
- $(CC) -c $(INCLUDES) $(DRI_CXXFLAGS) $(DRIVER_DEFINES) $< -o $@
-
-.S.o:
- $(CC) -c $(INCLUDES) $(DRI_CFLAGS) $(DRIVER_DEFINES) $< -o $@
-
-
-##### TARGETS #####
-
-default: subdirs lib
-
-
-.PHONY: lib
-lib: symlinks subdirs depend
- @$(MAKE) $(LIBNAME) $(TOP)/$(LIB_DIR)/$(LIBNAME)
-
-$(LIBNAME): $(OBJECTS) $(EXTRA_MODULES) $(MESA_MODULES) Makefile \
- $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o
- $(MKLIB) -o $@.tmp -noprefix -linker '$(CXX)' -ldflags '$(LDFLAGS)' \
- $(OBJECTS) $(EXTRA_MODULES) $(DRI_LIB_DEPS)
- $(CXX) $(CFLAGS) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS)
- @rm -f $@.test
- mv -f $@.tmp $@
-
-
-$(TOP)/$(LIB_DIR)/$(LIBNAME): $(LIBNAME)
- $(INSTALL) $(LIBNAME) $(TOP)/$(LIB_DIR)
-
-
-# If the Makefile defined SUBDIRS, run make in each
-.PHONY: subdirs
-subdirs:
- @if test -n "$(SUBDIRS)" ; then \
- for dir in $(SUBDIRS) ; do \
- if [ -d $$dir ] ; then \
- (cd $$dir && $(MAKE)) || exit 1; \
- fi \
- done \
- fi
-
-
-.PHONY: symlinks
-symlinks:
-
-
-depend: $(C_SOURCES) $(CXX_SOURCES) $(ASM_SOURCES) $(SYMLINKS)
- @ echo "running $(MKDEP)"
- @ rm -f depend
- @ touch depend
- @ $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) \
- $(C_SOURCES) $(CXX_SOURCES) \
- $(ASM_SOURCES) > /dev/null 2>/dev/null
-
-
-# Emacs tags
-tags:
- etags `find . -name \*.[ch]` `find ../include`
-
-
-# Remove .o and backup files
-clean:
- -rm -f *.o */*.o *~ *.so *~ server/*.o $(SYMLINKS)
- -rm -f depend depend.bak
-
-
-install: $(LIBNAME)
- $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
- $(MINSTALL) -m 755 $(LIBNAME) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
-
-
--include depend
+# -*-makefile-*-
+
+COMMON_GALLIUM_SOURCES = \
+ ../common/utils.c \
+ ../common/vblank.c \
+ ../common/dri_util.c \
+ ../common/xmlconfig.c
+
+COMMON_SOURCES = $(COMMON_GALLIUM_SOURCES) \
+ ../../common/driverfuncs.c \
+ ../common/texmem.c \
+ ../common/drirenderbuffer.c
+
+INCLUDES = $(SHARED_INCLUDES) $(EXPAT_INCLUDES)
+
+OBJECTS = $(C_SOURCES:.c=.o) \
+ $(CXX_SOURCES:.cpp=.o) \
+ $(ASM_SOURCES:.S=.o)
+
+
+### Include directories
+SHARED_INCLUDES = \
+ -I. \
+ -I$(TOP)/src/mesa/drivers/dri/common \
+ -Iserver \
+ -I$(TOP)/include \
+ -I$(TOP)/src/mapi \
+ -I$(TOP)/src/mesa \
+ -I$(TOP)/src/egl/main \
+ -I$(TOP)/src/egl/drivers/dri \
+ $(LIBDRM_CFLAGS)
+
+CFLAGS += $(API_DEFINES)
+CXXFLAGS += $(API_DEFINES)
+
+##### RULES #####
+
+.c.o:
+ $(CC) -c $(INCLUDES) $(DRI_CFLAGS) $(DRIVER_DEFINES) $< -o $@
+
+.cpp.o:
+ $(CC) -c $(INCLUDES) $(DRI_CXXFLAGS) $(DRIVER_DEFINES) $< -o $@
+
+.S.o:
+ $(CC) -c $(INCLUDES) $(DRI_CFLAGS) $(DRIVER_DEFINES) $< -o $@
+
+
+##### TARGETS #####
+
+default: subdirs lib
+
+
+.PHONY: lib
+lib: symlinks subdirs depend
+ @$(MAKE) $(LIBNAME) $(TOP)/$(LIB_DIR)/$(LIBNAME)
+
+$(LIBNAME): $(OBJECTS) $(EXTRA_MODULES) $(MESA_MODULES) Makefile \
+ $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o
+ $(MKLIB) -o $@.tmp -noprefix -linker '$(CXX)' -ldflags '$(LDFLAGS)' \
+ $(OBJECTS) $(EXTRA_MODULES) $(DRI_LIB_DEPS)
+ $(CXX) $(CFLAGS) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS)
+ @rm -f $@.test
+ mv -f $@.tmp $@
+
+
+$(TOP)/$(LIB_DIR)/$(LIBNAME): $(LIBNAME)
+ $(INSTALL) $(LIBNAME) $(TOP)/$(LIB_DIR)
+
+
+# If the Makefile defined SUBDIRS, run make in each
+.PHONY: subdirs
+subdirs:
+ @if test -n "$(SUBDIRS)" ; then \
+ for dir in $(SUBDIRS) ; do \
+ if [ -d $$dir ] ; then \
+ (cd $$dir && $(MAKE)) || exit 1; \
+ fi \
+ done \
+ fi
+
+
+.PHONY: symlinks
+symlinks:
+
+
+depend: $(C_SOURCES) $(CXX_SOURCES) $(ASM_SOURCES) $(SYMLINKS)
+ @ echo "running $(MKDEP)"
+ @ rm -f depend
+ @ touch depend
+ @ $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) \
+ $(C_SOURCES) $(CXX_SOURCES) \
+ $(ASM_SOURCES) > /dev/null 2>/dev/null
+
+
+# Emacs tags
+tags:
+ etags `find . -name \*.[ch]` `find ../include`
+
+
+# Remove .o and backup files
+clean:
+ -rm -f *.o */*.o *~ *.so *~ server/*.o $(SYMLINKS)
+ -rm -f depend depend.bak
+
+
+install: $(LIBNAME)
+ $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
+ $(MINSTALL) -m 755 $(LIBNAME) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
+
+
+-include depend
diff --git a/mesalib/src/mesa/drivers/dri/common/dri_util.c b/mesalib/src/mesa/drivers/dri/common/dri_util.c
index 82638fa72..6d3dd0a2c 100644
--- a/mesalib/src/mesa/drivers/dri/common/dri_util.c
+++ b/mesalib/src/mesa/drivers/dri/common/dri_util.c
@@ -1,1030 +1,1030 @@
-/**
- * \file dri_util.c
- * DRI utility functions.
- *
- * This module acts as glue between GLX and the actual hardware driver. A DRI
- * driver doesn't really \e have to use any of this - it's optional. But, some
- * useful stuff is done here that otherwise would have to be duplicated in most
- * drivers.
- *
- * Basically, these utility functions take care of some of the dirty details of
- * screen initialization, context creation, context binding, DRM setup, etc.
- *
- * These functions are compiled into each DRI driver so libGL.so knows nothing
- * about them.
- */
-
-
-#include <assert.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <stdio.h>
-
-#ifndef MAP_FAILED
-#define MAP_FAILED ((void *)-1)
-#endif
-
-#include "main/imports.h"
-#define None 0
-
-#include "dri_util.h"
-#include "drm_sarea.h"
-#include "utils.h"
-#include "xmlpool.h"
-#include "../glsl/glsl_parser_extras.h"
-
-PUBLIC const char __dri2ConfigOptions[] =
- DRI_CONF_BEGIN
- DRI_CONF_SECTION_PERFORMANCE
- DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_1)
- DRI_CONF_SECTION_END
- DRI_CONF_END;
-
-static const uint __dri2NConfigOptions = 1;
-
-#ifndef GLX_OML_sync_control
-typedef GLboolean ( * PFNGLXGETMSCRATEOMLPROC) (__DRIdrawable *drawable, int32_t *numerator, int32_t *denominator);
-#endif
-
-static void dri_get_drawable(__DRIdrawable *pdp);
-static void dri_put_drawable(__DRIdrawable *pdp);
-
-/**
- * This is just a token extension used to signal that the driver
- * supports setting a read drawable.
- */
-const __DRIextension driReadDrawableExtension = {
- __DRI_READ_DRAWABLE, __DRI_READ_DRAWABLE_VERSION
-};
-
-GLint
-driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 )
-{
- if (rect2.x1 > rect1.x1) rect1.x1 = rect2.x1;
- if (rect2.x2 < rect1.x2) rect1.x2 = rect2.x2;
- if (rect2.y1 > rect1.y1) rect1.y1 = rect2.y1;
- if (rect2.y2 < rect1.y2) rect1.y2 = rect2.y2;
-
- if (rect1.x1 > rect1.x2 || rect1.y1 > rect1.y2) return 0;
-
- return (rect1.x2 - rect1.x1) * (rect1.y2 - rect1.y1);
-}
-
-/*****************************************************************/
-/** \name Context (un)binding functions */
-/*****************************************************************/
-/*@{*/
-
-/**
- * Unbind context.
- *
- * \param scrn the screen.
- * \param gc context.
- *
- * \return \c GL_TRUE on success, or \c GL_FALSE on failure.
- *
- * \internal
- * This function calls __DriverAPIRec::UnbindContext, and then decrements
- * __DRIdrawableRec::refcount which must be non-zero for a successful
- * return.
- *
- * While casting the opaque private pointers associated with the parameters
- * into their respective real types it also assures they are not \c NULL.
- */
-static int driUnbindContext(__DRIcontext *pcp)
-{
- __DRIscreen *psp;
- __DRIdrawable *pdp;
- __DRIdrawable *prp;
-
- /*
- ** Assume error checking is done properly in glXMakeCurrent before
- ** calling driUnbindContext.
- */
-
- if (pcp == NULL)
- return GL_FALSE;
-
- psp = pcp->driScreenPriv;
- pdp = pcp->driDrawablePriv;
- prp = pcp->driReadablePriv;
-
- /* already unbound */
- if (!pdp && !prp)
- return GL_TRUE;
- /* Let driver unbind drawable from context */
- (*psp->DriverAPI.UnbindContext)(pcp);
-
- assert(pdp);
- if (pdp->refcount == 0) {
- /* ERROR!!! */
- return GL_FALSE;
- }
-
- dri_put_drawable(pdp);
-
- if (prp != pdp) {
- if (prp->refcount == 0) {
- /* ERROR!!! */
- return GL_FALSE;
- }
-
- dri_put_drawable(prp);
- }
-
-
- /* XXX this is disabled so that if we call SwapBuffers on an unbound
- * window we can determine the last context bound to the window and
- * use that context's lock. (BrianP, 2-Dec-2000)
- */
- pcp->driDrawablePriv = pcp->driReadablePriv = NULL;
-
- return GL_TRUE;
-}
-
-/**
- * This function takes both a read buffer and a draw buffer. This is needed
- * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent
- * function.
- */
-static int driBindContext(__DRIcontext *pcp,
- __DRIdrawable *pdp,
- __DRIdrawable *prp)
-{
- __DRIscreen *psp = NULL;
-
- /*
- ** Assume error checking is done properly in glXMakeCurrent before
- ** calling driUnbindContext.
- */
-
- if (!pcp)
- return GL_FALSE;
-
- /* Bind the drawable to the context */
- psp = pcp->driScreenPriv;
- pcp->driDrawablePriv = pdp;
- pcp->driReadablePriv = prp;
- if (pdp) {
- pdp->driContextPriv = pcp;
- dri_get_drawable(pdp);
- }
- if (prp && pdp != prp) {
- dri_get_drawable(prp);
- }
-
- /*
- ** Now that we have a context associated with this drawable, we can
- ** initialize the drawable information if has not been done before.
- */
-
- if (!psp->dri2.enabled) {
- if (pdp && !pdp->pStamp) {
- DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
- __driUtilUpdateDrawableInfo(pdp);
- DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
- }
- if (prp && pdp != prp && !prp->pStamp) {
- DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
- __driUtilUpdateDrawableInfo(prp);
- DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
- }
- }
-
- /* Call device-specific MakeCurrent */
- return (*psp->DriverAPI.MakeCurrent)(pcp, pdp, prp);
-}
-
-/*@}*/
-
-
-/*****************************************************************/
-/** \name Drawable handling functions */
-/*****************************************************************/
-/*@{*/
-
-/**
- * Update private drawable information.
- *
- * \param pdp pointer to the private drawable information to update.
- *
- * This function basically updates the __DRIdrawable struct's
- * cliprect information by calling \c __DRIinterfaceMethods::getDrawableInfo.
- * This is usually called by the DRI_VALIDATE_DRAWABLE_INFO macro which
- * compares the __DRIdrwablePrivate pStamp and lastStamp values. If
- * the values are different that means we have to update the clipping
- * info.
- */
-void
-__driUtilUpdateDrawableInfo(__DRIdrawable *pdp)
-{
- __DRIscreen *psp = pdp->driScreenPriv;
- __DRIcontext *pcp = pdp->driContextPriv;
-
- if (!pcp
- || ((pdp != pcp->driDrawablePriv) && (pdp != pcp->driReadablePriv))) {
- /* ERROR!!!
- * ...but we must ignore it. There can be many contexts bound to a
- * drawable.
- */
- }
-
- if (pdp->pClipRects) {
- free(pdp->pClipRects);
- pdp->pClipRects = NULL;
- }
-
- if (pdp->pBackClipRects) {
- free(pdp->pBackClipRects);
- pdp->pBackClipRects = NULL;
- }
-
- DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
-
- if (! (*psp->getDrawableInfo->getDrawableInfo)(pdp,
- &pdp->index, &pdp->lastStamp,
- &pdp->x, &pdp->y, &pdp->w, &pdp->h,
- &pdp->numClipRects, &pdp->pClipRects,
- &pdp->backX,
- &pdp->backY,
- &pdp->numBackClipRects,
- &pdp->pBackClipRects,
- pdp->loaderPrivate)) {
- /* Error -- eg the window may have been destroyed. Keep going
- * with no cliprects.
- */
- pdp->pStamp = &pdp->lastStamp; /* prevent endless loop */
- pdp->numClipRects = 0;
- pdp->pClipRects = NULL;
- pdp->numBackClipRects = 0;
- pdp->pBackClipRects = NULL;
- }
- else
- pdp->pStamp = &(psp->pSAREA->drawableTable[pdp->index].stamp);
-
- DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
-}
-
-/*@}*/
-
-/*****************************************************************/
-/** \name GLX callbacks */
-/*****************************************************************/
-/*@{*/
-
-static void driReportDamage(__DRIdrawable *pdp,
- struct drm_clip_rect *pClipRects, int numClipRects)
-{
- __DRIscreen *psp = pdp->driScreenPriv;
-
- /* Check that we actually have the new damage report method */
- if (psp->damage) {
- /* Report the damage. Currently, all our drivers draw
- * directly to the front buffer, so we report the damage there
- * rather than to the backing storein (if any).
- */
- (*psp->damage->reportDamage)(pdp,
- pdp->x, pdp->y,
- pClipRects, numClipRects,
- GL_TRUE, pdp->loaderPrivate);
- }
-}
-
-
-/**
- * Swap buffers.
- *
- * \param drawablePrivate opaque pointer to the per-drawable private info.
- *
- * \internal
- * This function calls __DRIdrawable::swapBuffers.
- *
- * Is called directly from glXSwapBuffers().
- */
-static void driSwapBuffers(__DRIdrawable *dPriv)
-{
- __DRIscreen *psp = dPriv->driScreenPriv;
- drm_clip_rect_t *rects;
- int i;
-
- psp->DriverAPI.SwapBuffers(dPriv);
-
- if (!dPriv->numClipRects)
- return;
-
- rects = malloc(sizeof(*rects) * dPriv->numClipRects);
-
- if (!rects)
- return;
-
- for (i = 0; i < dPriv->numClipRects; i++) {
- rects[i].x1 = dPriv->pClipRects[i].x1 - dPriv->x;
- rects[i].y1 = dPriv->pClipRects[i].y1 - dPriv->y;
- rects[i].x2 = dPriv->pClipRects[i].x2 - dPriv->x;
- rects[i].y2 = dPriv->pClipRects[i].y2 - dPriv->y;
- }
-
- driReportDamage(dPriv, rects, dPriv->numClipRects);
- free(rects);
-}
-
-static int driDrawableGetMSC( __DRIscreen *sPriv, __DRIdrawable *dPriv,
- int64_t *msc )
-{
- return sPriv->DriverAPI.GetDrawableMSC(sPriv, dPriv, msc);
-}
-
-
-static int driWaitForMSC(__DRIdrawable *dPriv, int64_t target_msc,
- int64_t divisor, int64_t remainder,
- int64_t * msc, int64_t * sbc)
-{
- __DRIswapInfo sInfo;
- int status;
-
- status = dPriv->driScreenPriv->DriverAPI.WaitForMSC( dPriv, target_msc,
- divisor, remainder,
- msc );
-
- /* GetSwapInfo() may not be provided by the driver if GLX_SGI_video_sync
- * is supported but GLX_OML_sync_control is not. Therefore, don't return
- * an error value if GetSwapInfo() is not implemented.
- */
- if ( status == 0
- && dPriv->driScreenPriv->DriverAPI.GetSwapInfo ) {
- status = dPriv->driScreenPriv->DriverAPI.GetSwapInfo( dPriv, & sInfo );
- *sbc = sInfo.swap_count;
- }
-
- return status;
-}
-
-
-const __DRImediaStreamCounterExtension driMediaStreamCounterExtension = {
- { __DRI_MEDIA_STREAM_COUNTER, __DRI_MEDIA_STREAM_COUNTER_VERSION },
- driWaitForMSC,
- driDrawableGetMSC,
-};
-
-
-static void driCopySubBuffer(__DRIdrawable *dPriv,
- int x, int y, int w, int h)
-{
- drm_clip_rect_t rect;
-
- rect.x1 = x;
- rect.y1 = dPriv->h - y - h;
- rect.x2 = x + w;
- rect.y2 = rect.y1 + h;
- driReportDamage(dPriv, &rect, 1);
-
- dPriv->driScreenPriv->DriverAPI.CopySubBuffer(dPriv, x, y, w, h);
-}
-
-const __DRIcopySubBufferExtension driCopySubBufferExtension = {
- { __DRI_COPY_SUB_BUFFER, __DRI_COPY_SUB_BUFFER_VERSION },
- driCopySubBuffer
-};
-
-static void driSetSwapInterval(__DRIdrawable *dPriv, unsigned int interval)
-{
- dPriv->swap_interval = interval;
-}
-
-static unsigned int driGetSwapInterval(__DRIdrawable *dPriv)
-{
- return dPriv->swap_interval;
-}
-
-const __DRIswapControlExtension driSwapControlExtension = {
- { __DRI_SWAP_CONTROL, __DRI_SWAP_CONTROL_VERSION },
- driSetSwapInterval,
- driGetSwapInterval
-};
-
-
-/**
- * This is called via __DRIscreenRec's createNewDrawable pointer.
- */
-static __DRIdrawable *
-driCreateNewDrawable(__DRIscreen *psp, const __DRIconfig *config,
- drm_drawable_t hwDrawable, int renderType,
- const int *attrs, void *data)
-{
- __DRIdrawable *pdp;
-
- /* Since pbuffers are not yet supported, no drawable attributes are
- * supported either.
- */
- (void) attrs;
-
- pdp = malloc(sizeof *pdp);
- if (!pdp) {
- return NULL;
- }
-
- pdp->driContextPriv = NULL;
- pdp->loaderPrivate = data;
- pdp->hHWDrawable = hwDrawable;
- pdp->refcount = 1;
- pdp->pStamp = NULL;
- pdp->lastStamp = 0;
- pdp->index = 0;
- pdp->x = 0;
- pdp->y = 0;
- pdp->w = 0;
- pdp->h = 0;
- pdp->numClipRects = 0;
- pdp->numBackClipRects = 0;
- pdp->pClipRects = NULL;
- pdp->pBackClipRects = NULL;
- pdp->vblSeq = 0;
- pdp->vblFlags = 0;
-
- pdp->driScreenPriv = psp;
-
- if (!(*psp->DriverAPI.CreateBuffer)(psp, pdp, &config->modes, 0)) {
- free(pdp);
- return NULL;
- }
-
- pdp->msc_base = 0;
-
- /* This special default value is replaced with the configured
- * default value when the drawable is first bound to a direct
- * rendering context.
- */
- pdp->swap_interval = (unsigned)-1;
-
- return pdp;
-}
-
-
-static __DRIdrawable *
-dri2CreateNewDrawable(__DRIscreen *screen,
- const __DRIconfig *config,
- void *loaderPrivate)
-{
- __DRIdrawable *pdraw;
-
- pdraw = driCreateNewDrawable(screen, config, 0, 0, NULL, loaderPrivate);
- if (!pdraw)
- return NULL;
-
- pdraw->pClipRects = &pdraw->dri2.clipRect;
- pdraw->pBackClipRects = &pdraw->dri2.clipRect;
-
- pdraw->pStamp = &pdraw->dri2.stamp;
- *pdraw->pStamp = pdraw->lastStamp + 1;
-
- return pdraw;
-}
-
-static __DRIbuffer *
-dri2AllocateBuffer(__DRIscreen *screen,
- unsigned int attachment, unsigned int format,
- int width, int height)
-{
- return (*screen->DriverAPI.AllocateBuffer)(screen, attachment, format,
- width, height);
-}
-
-static void
-dri2ReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
-{
- (*screen->DriverAPI.ReleaseBuffer)(screen, buffer);
-}
-
-
-static int
-dri2ConfigQueryb(__DRIscreen *screen, const char *var, GLboolean *val)
-{
- if (!driCheckOption(&screen->optionCache, var, DRI_BOOL))
- return -1;
-
- *val = driQueryOptionb(&screen->optionCache, var);
-
- return 0;
-}
-
-static int
-dri2ConfigQueryi(__DRIscreen *screen, const char *var, GLint *val)
-{
- if (!driCheckOption(&screen->optionCache, var, DRI_INT) &&
- !driCheckOption(&screen->optionCache, var, DRI_ENUM))
- return -1;
-
- *val = driQueryOptioni(&screen->optionCache, var);
-
- return 0;
-}
-
-static int
-dri2ConfigQueryf(__DRIscreen *screen, const char *var, GLfloat *val)
-{
- if (!driCheckOption(&screen->optionCache, var, DRI_FLOAT))
- return -1;
-
- *val = driQueryOptionf(&screen->optionCache, var);
-
- return 0;
-}
-
-
-static void dri_get_drawable(__DRIdrawable *pdp)
-{
- pdp->refcount++;
-}
-
-static void dri_put_drawable(__DRIdrawable *pdp)
-{
- __DRIscreen *psp;
-
- if (pdp) {
- pdp->refcount--;
- if (pdp->refcount)
- return;
-
- psp = pdp->driScreenPriv;
- (*psp->DriverAPI.DestroyBuffer)(pdp);
- if (pdp->pClipRects && pdp->pClipRects != &pdp->dri2.clipRect) {
- free(pdp->pClipRects);
- pdp->pClipRects = NULL;
- }
- if (pdp->pBackClipRects && pdp->pClipRects != &pdp->dri2.clipRect) {
- free(pdp->pBackClipRects);
- pdp->pBackClipRects = NULL;
- }
- free(pdp);
- }
-}
-
-static void
-driDestroyDrawable(__DRIdrawable *pdp)
-{
- dri_put_drawable(pdp);
-}
-
-/*@}*/
-
-
-/*****************************************************************/
-/** \name Context handling functions */
-/*****************************************************************/
-/*@{*/
-
-/**
- * Destroy the per-context private information.
- *
- * \internal
- * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
- * drmDestroyContext(), and finally frees \p contextPrivate.
- */
-static void
-driDestroyContext(__DRIcontext *pcp)
-{
- if (pcp) {
- (*pcp->driScreenPriv->DriverAPI.DestroyContext)(pcp);
- free(pcp);
- }
-}
-
-
-/**
- * Create the per-drawable private driver information.
- *
- * \param render_type Type of rendering target. \c GLX_RGBA is the only
- * type likely to ever be supported for direct-rendering.
- * \param shared Context with which to share textures, etc. or NULL
- *
- * \returns An opaque pointer to the per-context private information on
- * success, or \c NULL on failure.
- *
- * \internal
- * This function allocates and fills a __DRIcontextRec structure. It
- * performs some device independent initialization and passes all the
- * relevent information to __DriverAPIRec::CreateContext to create the
- * context.
- *
- */
-static __DRIcontext *
-driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config,
- int render_type, __DRIcontext *shared,
- drm_context_t hwContext, void *data)
-{
- __DRIcontext *pcp;
- void * const shareCtx = (shared != NULL) ? shared->driverPrivate : NULL;
-
- pcp = malloc(sizeof *pcp);
- if (!pcp)
- return NULL;
-
- pcp->driScreenPriv = psp;
- pcp->driDrawablePriv = NULL;
- pcp->loaderPrivate = data;
-
- pcp->dri2.draw_stamp = 0;
- pcp->dri2.read_stamp = 0;
-
- pcp->hHWContext = hwContext;
-
- if ( !(*psp->DriverAPI.CreateContext)(API_OPENGL,
- &config->modes, pcp, shareCtx) ) {
- free(pcp);
- return NULL;
- }
-
- return pcp;
-}
-
-static unsigned int
-dri2GetAPIMask(__DRIscreen *screen)
-{
- return screen->api_mask;
-}
-
-static __DRIcontext *
-dri2CreateNewContextForAPI(__DRIscreen *screen, int api,
- const __DRIconfig *config,
- __DRIcontext *shared, void *data)
-{
- __DRIcontext *context;
- const struct gl_config *modes = (config != NULL) ? &config->modes : NULL;
- void *shareCtx = (shared != NULL) ? shared->driverPrivate : NULL;
- gl_api mesa_api;
-
- if (!(screen->api_mask & (1 << api)))
- return NULL;
-
- switch (api) {
- case __DRI_API_OPENGL:
- mesa_api = API_OPENGL;
- break;
- case __DRI_API_GLES:
- mesa_api = API_OPENGLES;
- break;
- case __DRI_API_GLES2:
- mesa_api = API_OPENGLES2;
- break;
- default:
- return NULL;
- }
-
- context = malloc(sizeof *context);
- if (!context)
- return NULL;
-
- context->driScreenPriv = screen;
- context->driDrawablePriv = NULL;
- context->loaderPrivate = data;
-
- if (!(*screen->DriverAPI.CreateContext)(mesa_api, modes,
- context, shareCtx) ) {
- free(context);
- return NULL;
- }
-
- return context;
-}
-
-
-static __DRIcontext *
-dri2CreateNewContext(__DRIscreen *screen, const __DRIconfig *config,
- __DRIcontext *shared, void *data)
-{
- return dri2CreateNewContextForAPI(screen, __DRI_API_OPENGL,
- config, shared, data);
-}
-
-static int
-driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask)
-{
- return GL_FALSE;
-}
-
-/*@}*/
-
-
-/*****************************************************************/
-/** \name Screen handling functions */
-/*****************************************************************/
-/*@{*/
-
-/**
- * Destroy the per-screen private information.
- *
- * \internal
- * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
- * drmClose(), and finally frees \p screenPrivate.
- */
-static void driDestroyScreen(__DRIscreen *psp)
-{
- if (psp) {
- /* No interaction with the X-server is possible at this point. This
- * routine is called after XCloseDisplay, so there is no protocol
- * stream open to the X-server anymore.
- */
-
- _mesa_destroy_shader_compiler();
-
- if (psp->DriverAPI.DestroyScreen)
- (*psp->DriverAPI.DestroyScreen)(psp);
-
- if (!psp->dri2.enabled) {
- (void)drmUnmap((drmAddress)psp->pSAREA, SAREA_MAX);
- (void)drmUnmap((drmAddress)psp->pFB, psp->fbSize);
- (void)drmCloseOnce(psp->fd);
- } else {
- driDestroyOptionCache(&psp->optionCache);
- driDestroyOptionInfo(&psp->optionInfo);
- }
-
- free(psp);
- }
-}
-
-static void
-setupLoaderExtensions(__DRIscreen *psp,
- const __DRIextension **extensions)
-{
- int i;
-
- for (i = 0; extensions[i]; i++) {
- if (strcmp(extensions[i]->name, __DRI_GET_DRAWABLE_INFO) == 0)
- psp->getDrawableInfo = (__DRIgetDrawableInfoExtension *) extensions[i];
- if (strcmp(extensions[i]->name, __DRI_DAMAGE) == 0)
- psp->damage = (__DRIdamageExtension *) extensions[i];
- if (strcmp(extensions[i]->name, __DRI_SYSTEM_TIME) == 0)
- psp->systemTime = (__DRIsystemTimeExtension *) extensions[i];
- if (strcmp(extensions[i]->name, __DRI_DRI2_LOADER) == 0)
- psp->dri2.loader = (__DRIdri2LoaderExtension *) extensions[i];
- if (strcmp(extensions[i]->name, __DRI_IMAGE_LOOKUP) == 0)
- psp->dri2.image = (__DRIimageLookupExtension *) extensions[i];
- if (strcmp(extensions[i]->name, __DRI_USE_INVALIDATE) == 0)
- psp->dri2.useInvalidate = (__DRIuseInvalidateExtension *) extensions[i];
- }
-}
-
-/**
- * This is the bootstrap function for the driver. libGL supplies all of the
- * requisite information about the system, and the driver initializes itself.
- * This routine also fills in the linked list pointed to by \c driver_modes
- * with the \c struct gl_config that the driver can support for windows or
- * pbuffers.
- *
- * For legacy DRI.
- *
- * \param scrn Index of the screen
- * \param ddx_version Version of the 2D DDX. This may not be meaningful for
- * all drivers.
- * \param dri_version Version of the "server-side" DRI.
- * \param drm_version Version of the kernel DRM.
- * \param frame_buffer Data describing the location and layout of the
- * framebuffer.
- * \param pSAREA Pointer to the SAREA.
- * \param fd Device handle for the DRM.
- * \param extensions ??
- * \param driver_modes Returns modes suppoted by the driver
- * \param loaderPrivate ??
- *
- * \note There is no need to check the minimum API version in this
- * function. Since the name of this function is versioned, it is
- * impossible for a loader that is too old to even load this driver.
- */
-static __DRIscreen *
-driCreateNewScreen(int scrn,
- const __DRIversion *ddx_version,
- const __DRIversion *dri_version,
- const __DRIversion *drm_version,
- const __DRIframebuffer *frame_buffer,
- drmAddress pSAREA, int fd,
- const __DRIextension **extensions,
- const __DRIconfig ***driver_modes,
- void *loaderPrivate)
-{
- static const __DRIextension *emptyExtensionList[] = { NULL };
- __DRIscreen *psp;
-
- if (driDriverAPI.InitScreen == NULL)
- return NULL;
-
- psp = calloc(1, sizeof *psp);
- if (!psp)
- return NULL;
-
- setupLoaderExtensions(psp, extensions);
-
- /*
- ** NOT_DONE: This is used by the X server to detect when the client
- ** has died while holding the drawable lock. The client sets the
- ** drawable lock to this value.
- */
- psp->drawLockID = 1;
-
- psp->drm_version = *drm_version;
- psp->ddx_version = *ddx_version;
- psp->dri_version = *dri_version;
-
- psp->pSAREA = pSAREA;
- psp->lock = (drmLock *) &psp->pSAREA->lock;
-
- psp->pFB = frame_buffer->base;
- psp->fbSize = frame_buffer->size;
- psp->fbStride = frame_buffer->stride;
- psp->fbWidth = frame_buffer->width;
- psp->fbHeight = frame_buffer->height;
- psp->devPrivSize = frame_buffer->dev_priv_size;
- psp->pDevPriv = frame_buffer->dev_priv;
- psp->fbBPP = psp->fbStride * 8 / frame_buffer->width;
-
- psp->extensions = emptyExtensionList;
- psp->fd = fd;
- psp->myNum = scrn;
- psp->dri2.enabled = GL_FALSE;
-
- psp->DriverAPI = driDriverAPI;
- psp->api_mask = (1 << __DRI_API_OPENGL);
-
- *driver_modes = driDriverAPI.InitScreen(psp);
- if (*driver_modes == NULL) {
- free(psp);
- return NULL;
- }
-
- return psp;
-}
-
-/**
- * DRI2
- */
-static __DRIscreen *
-dri2CreateNewScreen(int scrn, int fd,
- const __DRIextension **extensions,
- const __DRIconfig ***driver_configs, void *data)
-{
- static const __DRIextension *emptyExtensionList[] = { NULL };
- __DRIscreen *psp;
- drmVersionPtr version;
-
- if (driDriverAPI.InitScreen2 == NULL)
- return NULL;
-
- psp = calloc(1, sizeof(*psp));
- if (!psp)
- return NULL;
-
- setupLoaderExtensions(psp, extensions);
-
- version = drmGetVersion(fd);
- if (version) {
- psp->drm_version.major = version->version_major;
- psp->drm_version.minor = version->version_minor;
- psp->drm_version.patch = version->version_patchlevel;
- drmFreeVersion(version);
- }
-
- psp->extensions = emptyExtensionList;
- psp->fd = fd;
- psp->myNum = scrn;
- psp->dri2.enabled = GL_TRUE;
-
- psp->DriverAPI = driDriverAPI;
- psp->api_mask = (1 << __DRI_API_OPENGL);
- *driver_configs = driDriverAPI.InitScreen2(psp);
- if (*driver_configs == NULL) {
- free(psp);
- return NULL;
- }
-
- psp->DriverAPI = driDriverAPI;
- psp->loaderPrivate = data;
-
- driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions,
- __dri2NConfigOptions);
- driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum,
- "dri2");
-
- return psp;
-}
-
-static const __DRIextension **driGetExtensions(__DRIscreen *psp)
-{
- return psp->extensions;
-}
-
-/** Core interface */
-const __DRIcoreExtension driCoreExtension = {
- { __DRI_CORE, __DRI_CORE_VERSION },
- NULL,
- driDestroyScreen,
- driGetExtensions,
- driGetConfigAttrib,
- driIndexConfigAttrib,
- NULL,
- driDestroyDrawable,
- driSwapBuffers,
- NULL,
- driCopyContext,
- driDestroyContext,
- driBindContext,
- driUnbindContext
-};
-
-/** Legacy DRI interface */
-const __DRIlegacyExtension driLegacyExtension = {
- { __DRI_LEGACY, __DRI_LEGACY_VERSION },
- driCreateNewScreen,
- driCreateNewDrawable,
- driCreateNewContext,
-};
-
-/** DRI2 interface */
-const __DRIdri2Extension driDRI2Extension = {
- { __DRI_DRI2, __DRI_DRI2_VERSION },
- dri2CreateNewScreen,
- dri2CreateNewDrawable,
- dri2CreateNewContext,
- dri2GetAPIMask,
- dri2CreateNewContextForAPI,
- dri2AllocateBuffer,
- dri2ReleaseBuffer
-};
-
-const __DRI2configQueryExtension dri2ConfigQueryExtension = {
- { __DRI2_CONFIG_QUERY, __DRI2_CONFIG_QUERY_VERSION },
- dri2ConfigQueryb,
- dri2ConfigQueryi,
- dri2ConfigQueryf,
-};
-
-/**
- * Calculate amount of swap interval used between GLX buffer swaps.
- *
- * The usage value, on the range [0,max], is the fraction of total swap
- * interval time used between GLX buffer swaps is calculated.
- *
- * \f$p = t_d / (i * t_r)\f$
- *
- * Where \f$t_d\f$ is the time since the last GLX buffer swap, \f$i\f$ is the
- * swap interval (as set by \c glXSwapIntervalSGI), and \f$t_r\f$ time
- * required for a single vertical refresh period (as returned by \c
- * glXGetMscRateOML).
- *
- * See the documentation for the GLX_MESA_swap_frame_usage extension for more
- * details.
- *
- * \param dPriv Pointer to the private drawable structure.
- * \return If less than a single swap interval time period was required
- * between GLX buffer swaps, a number greater than 0 and less than
- * 1.0 is returned. If exactly one swap interval time period is
- * required, 1.0 is returned, and if more than one is required then
- * a number greater than 1.0 will be returned.
- *
- * \sa glXSwapIntervalSGI glXGetMscRateOML
- *
- * \todo Instead of caching the \c glXGetMscRateOML function pointer, would it
- * be possible to cache the sync rate?
- */
-float
-driCalculateSwapUsage( __DRIdrawable *dPriv, int64_t last_swap_ust,
- int64_t current_ust )
-{
- int32_t n;
- int32_t d;
- int interval;
- float usage = 1.0;
- __DRIscreen *psp = dPriv->driScreenPriv;
-
- if ( (*psp->systemTime->getMSCRate)(dPriv, &n, &d, dPriv->loaderPrivate) ) {
- interval = (dPriv->swap_interval != 0) ? dPriv->swap_interval : 1;
-
-
- /* We want to calculate
- * (current_UST - last_swap_UST) / (interval * us_per_refresh). We get
- * current_UST by calling __glXGetUST. last_swap_UST is stored in
- * dPriv->swap_ust. interval has already been calculated.
- *
- * The only tricky part is us_per_refresh. us_per_refresh is
- * 1000000 / MSC_rate. We know the MSC_rate is n / d. We can flip it
- * around and say us_per_refresh = 1000000 * d / n. Since this goes in
- * the denominator of the final calculation, we calculate
- * (interval * 1000000 * d) and move n into the numerator.
- */
-
- usage = (current_ust - last_swap_ust);
- usage *= n;
- usage /= (interval * d);
- usage /= 1000000.0;
- }
-
- return usage;
-}
-
-void
-dri2InvalidateDrawable(__DRIdrawable *drawable)
-{
- drawable->dri2.stamp++;
-}
-
-/*@}*/
+/**
+ * \file dri_util.c
+ * DRI utility functions.
+ *
+ * This module acts as glue between GLX and the actual hardware driver. A DRI
+ * driver doesn't really \e have to use any of this - it's optional. But, some
+ * useful stuff is done here that otherwise would have to be duplicated in most
+ * drivers.
+ *
+ * Basically, these utility functions take care of some of the dirty details of
+ * screen initialization, context creation, context binding, DRM setup, etc.
+ *
+ * These functions are compiled into each DRI driver so libGL.so knows nothing
+ * about them.
+ */
+
+
+#include <assert.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <stdio.h>
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+#include "main/imports.h"
+#define None 0
+
+#include "dri_util.h"
+#include "drm_sarea.h"
+#include "utils.h"
+#include "xmlpool.h"
+#include "../glsl/glsl_parser_extras.h"
+
+PUBLIC const char __dri2ConfigOptions[] =
+ DRI_CONF_BEGIN
+ DRI_CONF_SECTION_PERFORMANCE
+ DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_1)
+ DRI_CONF_SECTION_END
+ DRI_CONF_END;
+
+static const uint __dri2NConfigOptions = 1;
+
+#ifndef GLX_OML_sync_control
+typedef GLboolean ( * PFNGLXGETMSCRATEOMLPROC) (__DRIdrawable *drawable, int32_t *numerator, int32_t *denominator);
+#endif
+
+static void dri_get_drawable(__DRIdrawable *pdp);
+static void dri_put_drawable(__DRIdrawable *pdp);
+
+/**
+ * This is just a token extension used to signal that the driver
+ * supports setting a read drawable.
+ */
+const __DRIextension driReadDrawableExtension = {
+ __DRI_READ_DRAWABLE, __DRI_READ_DRAWABLE_VERSION
+};
+
+GLint
+driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 )
+{
+ if (rect2.x1 > rect1.x1) rect1.x1 = rect2.x1;
+ if (rect2.x2 < rect1.x2) rect1.x2 = rect2.x2;
+ if (rect2.y1 > rect1.y1) rect1.y1 = rect2.y1;
+ if (rect2.y2 < rect1.y2) rect1.y2 = rect2.y2;
+
+ if (rect1.x1 > rect1.x2 || rect1.y1 > rect1.y2) return 0;
+
+ return (rect1.x2 - rect1.x1) * (rect1.y2 - rect1.y1);
+}
+
+/*****************************************************************/
+/** \name Context (un)binding functions */
+/*****************************************************************/
+/*@{*/
+
+/**
+ * Unbind context.
+ *
+ * \param scrn the screen.
+ * \param gc context.
+ *
+ * \return \c GL_TRUE on success, or \c GL_FALSE on failure.
+ *
+ * \internal
+ * This function calls __DriverAPIRec::UnbindContext, and then decrements
+ * __DRIdrawableRec::refcount which must be non-zero for a successful
+ * return.
+ *
+ * While casting the opaque private pointers associated with the parameters
+ * into their respective real types it also assures they are not \c NULL.
+ */
+static int driUnbindContext(__DRIcontext *pcp)
+{
+ __DRIscreen *psp;
+ __DRIdrawable *pdp;
+ __DRIdrawable *prp;
+
+ /*
+ ** Assume error checking is done properly in glXMakeCurrent before
+ ** calling driUnbindContext.
+ */
+
+ if (pcp == NULL)
+ return GL_FALSE;
+
+ psp = pcp->driScreenPriv;
+ pdp = pcp->driDrawablePriv;
+ prp = pcp->driReadablePriv;
+
+ /* already unbound */
+ if (!pdp && !prp)
+ return GL_TRUE;
+ /* Let driver unbind drawable from context */
+ (*psp->DriverAPI.UnbindContext)(pcp);
+
+ assert(pdp);
+ if (pdp->refcount == 0) {
+ /* ERROR!!! */
+ return GL_FALSE;
+ }
+
+ dri_put_drawable(pdp);
+
+ if (prp != pdp) {
+ if (prp->refcount == 0) {
+ /* ERROR!!! */
+ return GL_FALSE;
+ }
+
+ dri_put_drawable(prp);
+ }
+
+
+ /* XXX this is disabled so that if we call SwapBuffers on an unbound
+ * window we can determine the last context bound to the window and
+ * use that context's lock. (BrianP, 2-Dec-2000)
+ */
+ pcp->driDrawablePriv = pcp->driReadablePriv = NULL;
+
+ return GL_TRUE;
+}
+
+/**
+ * This function takes both a read buffer and a draw buffer. This is needed
+ * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent
+ * function.
+ */
+static int driBindContext(__DRIcontext *pcp,
+ __DRIdrawable *pdp,
+ __DRIdrawable *prp)
+{
+ __DRIscreen *psp = NULL;
+
+ /*
+ ** Assume error checking is done properly in glXMakeCurrent before
+ ** calling driUnbindContext.
+ */
+
+ if (!pcp)
+ return GL_FALSE;
+
+ /* Bind the drawable to the context */
+ psp = pcp->driScreenPriv;
+ pcp->driDrawablePriv = pdp;
+ pcp->driReadablePriv = prp;
+ if (pdp) {
+ pdp->driContextPriv = pcp;
+ dri_get_drawable(pdp);
+ }
+ if (prp && pdp != prp) {
+ dri_get_drawable(prp);
+ }
+
+ /*
+ ** Now that we have a context associated with this drawable, we can
+ ** initialize the drawable information if has not been done before.
+ */
+
+ if (!psp->dri2.enabled) {
+ if (pdp && !pdp->pStamp) {
+ DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
+ __driUtilUpdateDrawableInfo(pdp);
+ DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
+ }
+ if (prp && pdp != prp && !prp->pStamp) {
+ DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
+ __driUtilUpdateDrawableInfo(prp);
+ DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
+ }
+ }
+
+ /* Call device-specific MakeCurrent */
+ return (*psp->DriverAPI.MakeCurrent)(pcp, pdp, prp);
+}
+
+/*@}*/
+
+
+/*****************************************************************/
+/** \name Drawable handling functions */
+/*****************************************************************/
+/*@{*/
+
+/**
+ * Update private drawable information.
+ *
+ * \param pdp pointer to the private drawable information to update.
+ *
+ * This function basically updates the __DRIdrawable struct's
+ * cliprect information by calling \c __DRIinterfaceMethods::getDrawableInfo.
+ * This is usually called by the DRI_VALIDATE_DRAWABLE_INFO macro which
+ * compares the __DRIdrwablePrivate pStamp and lastStamp values. If
+ * the values are different that means we have to update the clipping
+ * info.
+ */
+void
+__driUtilUpdateDrawableInfo(__DRIdrawable *pdp)
+{
+ __DRIscreen *psp = pdp->driScreenPriv;
+ __DRIcontext *pcp = pdp->driContextPriv;
+
+ if (!pcp
+ || ((pdp != pcp->driDrawablePriv) && (pdp != pcp->driReadablePriv))) {
+ /* ERROR!!!
+ * ...but we must ignore it. There can be many contexts bound to a
+ * drawable.
+ */
+ }
+
+ if (pdp->pClipRects) {
+ free(pdp->pClipRects);
+ pdp->pClipRects = NULL;
+ }
+
+ if (pdp->pBackClipRects) {
+ free(pdp->pBackClipRects);
+ pdp->pBackClipRects = NULL;
+ }
+
+ DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
+
+ if (! (*psp->getDrawableInfo->getDrawableInfo)(pdp,
+ &pdp->index, &pdp->lastStamp,
+ &pdp->x, &pdp->y, &pdp->w, &pdp->h,
+ &pdp->numClipRects, &pdp->pClipRects,
+ &pdp->backX,
+ &pdp->backY,
+ &pdp->numBackClipRects,
+ &pdp->pBackClipRects,
+ pdp->loaderPrivate)) {
+ /* Error -- eg the window may have been destroyed. Keep going
+ * with no cliprects.
+ */
+ pdp->pStamp = &pdp->lastStamp; /* prevent endless loop */
+ pdp->numClipRects = 0;
+ pdp->pClipRects = NULL;
+ pdp->numBackClipRects = 0;
+ pdp->pBackClipRects = NULL;
+ }
+ else
+ pdp->pStamp = &(psp->pSAREA->drawableTable[pdp->index].stamp);
+
+ DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
+}
+
+/*@}*/
+
+/*****************************************************************/
+/** \name GLX callbacks */
+/*****************************************************************/
+/*@{*/
+
+static void driReportDamage(__DRIdrawable *pdp,
+ struct drm_clip_rect *pClipRects, int numClipRects)
+{
+ __DRIscreen *psp = pdp->driScreenPriv;
+
+ /* Check that we actually have the new damage report method */
+ if (psp->damage) {
+ /* Report the damage. Currently, all our drivers draw
+ * directly to the front buffer, so we report the damage there
+ * rather than to the backing storein (if any).
+ */
+ (*psp->damage->reportDamage)(pdp,
+ pdp->x, pdp->y,
+ pClipRects, numClipRects,
+ GL_TRUE, pdp->loaderPrivate);
+ }
+}
+
+
+/**
+ * Swap buffers.
+ *
+ * \param drawablePrivate opaque pointer to the per-drawable private info.
+ *
+ * \internal
+ * This function calls __DRIdrawable::swapBuffers.
+ *
+ * Is called directly from glXSwapBuffers().
+ */
+static void driSwapBuffers(__DRIdrawable *dPriv)
+{
+ __DRIscreen *psp = dPriv->driScreenPriv;
+ drm_clip_rect_t *rects;
+ int i;
+
+ psp->DriverAPI.SwapBuffers(dPriv);
+
+ if (!dPriv->numClipRects)
+ return;
+
+ rects = malloc(sizeof(*rects) * dPriv->numClipRects);
+
+ if (!rects)
+ return;
+
+ for (i = 0; i < dPriv->numClipRects; i++) {
+ rects[i].x1 = dPriv->pClipRects[i].x1 - dPriv->x;
+ rects[i].y1 = dPriv->pClipRects[i].y1 - dPriv->y;
+ rects[i].x2 = dPriv->pClipRects[i].x2 - dPriv->x;
+ rects[i].y2 = dPriv->pClipRects[i].y2 - dPriv->y;
+ }
+
+ driReportDamage(dPriv, rects, dPriv->numClipRects);
+ free(rects);
+}
+
+static int driDrawableGetMSC( __DRIscreen *sPriv, __DRIdrawable *dPriv,
+ int64_t *msc )
+{
+ return sPriv->DriverAPI.GetDrawableMSC(sPriv, dPriv, msc);
+}
+
+
+static int driWaitForMSC(__DRIdrawable *dPriv, int64_t target_msc,
+ int64_t divisor, int64_t remainder,
+ int64_t * msc, int64_t * sbc)
+{
+ __DRIswapInfo sInfo;
+ int status;
+
+ status = dPriv->driScreenPriv->DriverAPI.WaitForMSC( dPriv, target_msc,
+ divisor, remainder,
+ msc );
+
+ /* GetSwapInfo() may not be provided by the driver if GLX_SGI_video_sync
+ * is supported but GLX_OML_sync_control is not. Therefore, don't return
+ * an error value if GetSwapInfo() is not implemented.
+ */
+ if ( status == 0
+ && dPriv->driScreenPriv->DriverAPI.GetSwapInfo ) {
+ status = dPriv->driScreenPriv->DriverAPI.GetSwapInfo( dPriv, & sInfo );
+ *sbc = sInfo.swap_count;
+ }
+
+ return status;
+}
+
+
+const __DRImediaStreamCounterExtension driMediaStreamCounterExtension = {
+ { __DRI_MEDIA_STREAM_COUNTER, __DRI_MEDIA_STREAM_COUNTER_VERSION },
+ driWaitForMSC,
+ driDrawableGetMSC,
+};
+
+
+static void driCopySubBuffer(__DRIdrawable *dPriv,
+ int x, int y, int w, int h)
+{
+ drm_clip_rect_t rect;
+
+ rect.x1 = x;
+ rect.y1 = dPriv->h - y - h;
+ rect.x2 = x + w;
+ rect.y2 = rect.y1 + h;
+ driReportDamage(dPriv, &rect, 1);
+
+ dPriv->driScreenPriv->DriverAPI.CopySubBuffer(dPriv, x, y, w, h);
+}
+
+const __DRIcopySubBufferExtension driCopySubBufferExtension = {
+ { __DRI_COPY_SUB_BUFFER, __DRI_COPY_SUB_BUFFER_VERSION },
+ driCopySubBuffer
+};
+
+static void driSetSwapInterval(__DRIdrawable *dPriv, unsigned int interval)
+{
+ dPriv->swap_interval = interval;
+}
+
+static unsigned int driGetSwapInterval(__DRIdrawable *dPriv)
+{
+ return dPriv->swap_interval;
+}
+
+const __DRIswapControlExtension driSwapControlExtension = {
+ { __DRI_SWAP_CONTROL, __DRI_SWAP_CONTROL_VERSION },
+ driSetSwapInterval,
+ driGetSwapInterval
+};
+
+
+/**
+ * This is called via __DRIscreenRec's createNewDrawable pointer.
+ */
+static __DRIdrawable *
+driCreateNewDrawable(__DRIscreen *psp, const __DRIconfig *config,
+ drm_drawable_t hwDrawable, int renderType,
+ const int *attrs, void *data)
+{
+ __DRIdrawable *pdp;
+
+ /* Since pbuffers are not yet supported, no drawable attributes are
+ * supported either.
+ */
+ (void) attrs;
+
+ pdp = malloc(sizeof *pdp);
+ if (!pdp) {
+ return NULL;
+ }
+
+ pdp->driContextPriv = NULL;
+ pdp->loaderPrivate = data;
+ pdp->hHWDrawable = hwDrawable;
+ pdp->refcount = 1;
+ pdp->pStamp = NULL;
+ pdp->lastStamp = 0;
+ pdp->index = 0;
+ pdp->x = 0;
+ pdp->y = 0;
+ pdp->w = 0;
+ pdp->h = 0;
+ pdp->numClipRects = 0;
+ pdp->numBackClipRects = 0;
+ pdp->pClipRects = NULL;
+ pdp->pBackClipRects = NULL;
+ pdp->vblSeq = 0;
+ pdp->vblFlags = 0;
+
+ pdp->driScreenPriv = psp;
+
+ if (!(*psp->DriverAPI.CreateBuffer)(psp, pdp, &config->modes, 0)) {
+ free(pdp);
+ return NULL;
+ }
+
+ pdp->msc_base = 0;
+
+ /* This special default value is replaced with the configured
+ * default value when the drawable is first bound to a direct
+ * rendering context.
+ */
+ pdp->swap_interval = (unsigned)-1;
+
+ return pdp;
+}
+
+
+static __DRIdrawable *
+dri2CreateNewDrawable(__DRIscreen *screen,
+ const __DRIconfig *config,
+ void *loaderPrivate)
+{
+ __DRIdrawable *pdraw;
+
+ pdraw = driCreateNewDrawable(screen, config, 0, 0, NULL, loaderPrivate);
+ if (!pdraw)
+ return NULL;
+
+ pdraw->pClipRects = &pdraw->dri2.clipRect;
+ pdraw->pBackClipRects = &pdraw->dri2.clipRect;
+
+ pdraw->pStamp = &pdraw->dri2.stamp;
+ *pdraw->pStamp = pdraw->lastStamp + 1;
+
+ return pdraw;
+}
+
+static __DRIbuffer *
+dri2AllocateBuffer(__DRIscreen *screen,
+ unsigned int attachment, unsigned int format,
+ int width, int height)
+{
+ return (*screen->DriverAPI.AllocateBuffer)(screen, attachment, format,
+ width, height);
+}
+
+static void
+dri2ReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
+{
+ (*screen->DriverAPI.ReleaseBuffer)(screen, buffer);
+}
+
+
+static int
+dri2ConfigQueryb(__DRIscreen *screen, const char *var, GLboolean *val)
+{
+ if (!driCheckOption(&screen->optionCache, var, DRI_BOOL))
+ return -1;
+
+ *val = driQueryOptionb(&screen->optionCache, var);
+
+ return 0;
+}
+
+static int
+dri2ConfigQueryi(__DRIscreen *screen, const char *var, GLint *val)
+{
+ if (!driCheckOption(&screen->optionCache, var, DRI_INT) &&
+ !driCheckOption(&screen->optionCache, var, DRI_ENUM))
+ return -1;
+
+ *val = driQueryOptioni(&screen->optionCache, var);
+
+ return 0;
+}
+
+static int
+dri2ConfigQueryf(__DRIscreen *screen, const char *var, GLfloat *val)
+{
+ if (!driCheckOption(&screen->optionCache, var, DRI_FLOAT))
+ return -1;
+
+ *val = driQueryOptionf(&screen->optionCache, var);
+
+ return 0;
+}
+
+
+static void dri_get_drawable(__DRIdrawable *pdp)
+{
+ pdp->refcount++;
+}
+
+static void dri_put_drawable(__DRIdrawable *pdp)
+{
+ __DRIscreen *psp;
+
+ if (pdp) {
+ pdp->refcount--;
+ if (pdp->refcount)
+ return;
+
+ psp = pdp->driScreenPriv;
+ (*psp->DriverAPI.DestroyBuffer)(pdp);
+ if (pdp->pClipRects && pdp->pClipRects != &pdp->dri2.clipRect) {
+ free(pdp->pClipRects);
+ pdp->pClipRects = NULL;
+ }
+ if (pdp->pBackClipRects && pdp->pClipRects != &pdp->dri2.clipRect) {
+ free(pdp->pBackClipRects);
+ pdp->pBackClipRects = NULL;
+ }
+ free(pdp);
+ }
+}
+
+static void
+driDestroyDrawable(__DRIdrawable *pdp)
+{
+ dri_put_drawable(pdp);
+}
+
+/*@}*/
+
+
+/*****************************************************************/
+/** \name Context handling functions */
+/*****************************************************************/
+/*@{*/
+
+/**
+ * Destroy the per-context private information.
+ *
+ * \internal
+ * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
+ * drmDestroyContext(), and finally frees \p contextPrivate.
+ */
+static void
+driDestroyContext(__DRIcontext *pcp)
+{
+ if (pcp) {
+ (*pcp->driScreenPriv->DriverAPI.DestroyContext)(pcp);
+ free(pcp);
+ }
+}
+
+
+/**
+ * Create the per-drawable private driver information.
+ *
+ * \param render_type Type of rendering target. \c GLX_RGBA is the only
+ * type likely to ever be supported for direct-rendering.
+ * \param shared Context with which to share textures, etc. or NULL
+ *
+ * \returns An opaque pointer to the per-context private information on
+ * success, or \c NULL on failure.
+ *
+ * \internal
+ * This function allocates and fills a __DRIcontextRec structure. It
+ * performs some device independent initialization and passes all the
+ * relevent information to __DriverAPIRec::CreateContext to create the
+ * context.
+ *
+ */
+static __DRIcontext *
+driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config,
+ int render_type, __DRIcontext *shared,
+ drm_context_t hwContext, void *data)
+{
+ __DRIcontext *pcp;
+ void * const shareCtx = (shared != NULL) ? shared->driverPrivate : NULL;
+
+ pcp = malloc(sizeof *pcp);
+ if (!pcp)
+ return NULL;
+
+ pcp->driScreenPriv = psp;
+ pcp->driDrawablePriv = NULL;
+ pcp->loaderPrivate = data;
+
+ pcp->dri2.draw_stamp = 0;
+ pcp->dri2.read_stamp = 0;
+
+ pcp->hHWContext = hwContext;
+
+ if ( !(*psp->DriverAPI.CreateContext)(API_OPENGL,
+ &config->modes, pcp, shareCtx) ) {
+ free(pcp);
+ return NULL;
+ }
+
+ return pcp;
+}
+
+static unsigned int
+dri2GetAPIMask(__DRIscreen *screen)
+{
+ return screen->api_mask;
+}
+
+static __DRIcontext *
+dri2CreateNewContextForAPI(__DRIscreen *screen, int api,
+ const __DRIconfig *config,
+ __DRIcontext *shared, void *data)
+{
+ __DRIcontext *context;
+ const struct gl_config *modes = (config != NULL) ? &config->modes : NULL;
+ void *shareCtx = (shared != NULL) ? shared->driverPrivate : NULL;
+ gl_api mesa_api;
+
+ if (!(screen->api_mask & (1 << api)))
+ return NULL;
+
+ switch (api) {
+ case __DRI_API_OPENGL:
+ mesa_api = API_OPENGL;
+ break;
+ case __DRI_API_GLES:
+ mesa_api = API_OPENGLES;
+ break;
+ case __DRI_API_GLES2:
+ mesa_api = API_OPENGLES2;
+ break;
+ default:
+ return NULL;
+ }
+
+ context = malloc(sizeof *context);
+ if (!context)
+ return NULL;
+
+ context->driScreenPriv = screen;
+ context->driDrawablePriv = NULL;
+ context->loaderPrivate = data;
+
+ if (!(*screen->DriverAPI.CreateContext)(mesa_api, modes,
+ context, shareCtx) ) {
+ free(context);
+ return NULL;
+ }
+
+ return context;
+}
+
+
+static __DRIcontext *
+dri2CreateNewContext(__DRIscreen *screen, const __DRIconfig *config,
+ __DRIcontext *shared, void *data)
+{
+ return dri2CreateNewContextForAPI(screen, __DRI_API_OPENGL,
+ config, shared, data);
+}
+
+static int
+driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask)
+{
+ return GL_FALSE;
+}
+
+/*@}*/
+
+
+/*****************************************************************/
+/** \name Screen handling functions */
+/*****************************************************************/
+/*@{*/
+
+/**
+ * Destroy the per-screen private information.
+ *
+ * \internal
+ * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
+ * drmClose(), and finally frees \p screenPrivate.
+ */
+static void driDestroyScreen(__DRIscreen *psp)
+{
+ if (psp) {
+ /* No interaction with the X-server is possible at this point. This
+ * routine is called after XCloseDisplay, so there is no protocol
+ * stream open to the X-server anymore.
+ */
+
+ _mesa_destroy_shader_compiler();
+
+ if (psp->DriverAPI.DestroyScreen)
+ (*psp->DriverAPI.DestroyScreen)(psp);
+
+ if (!psp->dri2.enabled) {
+ (void)drmUnmap((drmAddress)psp->pSAREA, SAREA_MAX);
+ (void)drmUnmap((drmAddress)psp->pFB, psp->fbSize);
+ (void)drmCloseOnce(psp->fd);
+ } else {
+ driDestroyOptionCache(&psp->optionCache);
+ driDestroyOptionInfo(&psp->optionInfo);
+ }
+
+ free(psp);
+ }
+}
+
+static void
+setupLoaderExtensions(__DRIscreen *psp,
+ const __DRIextension **extensions)
+{
+ int i;
+
+ for (i = 0; extensions[i]; i++) {
+ if (strcmp(extensions[i]->name, __DRI_GET_DRAWABLE_INFO) == 0)
+ psp->getDrawableInfo = (__DRIgetDrawableInfoExtension *) extensions[i];
+ if (strcmp(extensions[i]->name, __DRI_DAMAGE) == 0)
+ psp->damage = (__DRIdamageExtension *) extensions[i];
+ if (strcmp(extensions[i]->name, __DRI_SYSTEM_TIME) == 0)
+ psp->systemTime = (__DRIsystemTimeExtension *) extensions[i];
+ if (strcmp(extensions[i]->name, __DRI_DRI2_LOADER) == 0)
+ psp->dri2.loader = (__DRIdri2LoaderExtension *) extensions[i];
+ if (strcmp(extensions[i]->name, __DRI_IMAGE_LOOKUP) == 0)
+ psp->dri2.image = (__DRIimageLookupExtension *) extensions[i];
+ if (strcmp(extensions[i]->name, __DRI_USE_INVALIDATE) == 0)
+ psp->dri2.useInvalidate = (__DRIuseInvalidateExtension *) extensions[i];
+ }
+}
+
+/**
+ * This is the bootstrap function for the driver. libGL supplies all of the
+ * requisite information about the system, and the driver initializes itself.
+ * This routine also fills in the linked list pointed to by \c driver_modes
+ * with the \c struct gl_config that the driver can support for windows or
+ * pbuffers.
+ *
+ * For legacy DRI.
+ *
+ * \param scrn Index of the screen
+ * \param ddx_version Version of the 2D DDX. This may not be meaningful for
+ * all drivers.
+ * \param dri_version Version of the "server-side" DRI.
+ * \param drm_version Version of the kernel DRM.
+ * \param frame_buffer Data describing the location and layout of the
+ * framebuffer.
+ * \param pSAREA Pointer to the SAREA.
+ * \param fd Device handle for the DRM.
+ * \param extensions ??
+ * \param driver_modes Returns modes suppoted by the driver
+ * \param loaderPrivate ??
+ *
+ * \note There is no need to check the minimum API version in this
+ * function. Since the name of this function is versioned, it is
+ * impossible for a loader that is too old to even load this driver.
+ */
+static __DRIscreen *
+driCreateNewScreen(int scrn,
+ const __DRIversion *ddx_version,
+ const __DRIversion *dri_version,
+ const __DRIversion *drm_version,
+ const __DRIframebuffer *frame_buffer,
+ drmAddress pSAREA, int fd,
+ const __DRIextension **extensions,
+ const __DRIconfig ***driver_modes,
+ void *loaderPrivate)
+{
+ static const __DRIextension *emptyExtensionList[] = { NULL };
+ __DRIscreen *psp;
+
+ if (driDriverAPI.InitScreen == NULL)
+ return NULL;
+
+ psp = calloc(1, sizeof *psp);
+ if (!psp)
+ return NULL;
+
+ setupLoaderExtensions(psp, extensions);
+
+ /*
+ ** NOT_DONE: This is used by the X server to detect when the client
+ ** has died while holding the drawable lock. The client sets the
+ ** drawable lock to this value.
+ */
+ psp->drawLockID = 1;
+
+ psp->drm_version = *drm_version;
+ psp->ddx_version = *ddx_version;
+ psp->dri_version = *dri_version;
+
+ psp->pSAREA = pSAREA;
+ psp->lock = (drmLock *) &psp->pSAREA->lock;
+
+ psp->pFB = frame_buffer->base;
+ psp->fbSize = frame_buffer->size;
+ psp->fbStride = frame_buffer->stride;
+ psp->fbWidth = frame_buffer->width;
+ psp->fbHeight = frame_buffer->height;
+ psp->devPrivSize = frame_buffer->dev_priv_size;
+ psp->pDevPriv = frame_buffer->dev_priv;
+ psp->fbBPP = psp->fbStride * 8 / frame_buffer->width;
+
+ psp->extensions = emptyExtensionList;
+ psp->fd = fd;
+ psp->myNum = scrn;
+ psp->dri2.enabled = GL_FALSE;
+
+ psp->DriverAPI = driDriverAPI;
+ psp->api_mask = (1 << __DRI_API_OPENGL);
+
+ *driver_modes = driDriverAPI.InitScreen(psp);
+ if (*driver_modes == NULL) {
+ free(psp);
+ return NULL;
+ }
+
+ return psp;
+}
+
+/**
+ * DRI2
+ */
+static __DRIscreen *
+dri2CreateNewScreen(int scrn, int fd,
+ const __DRIextension **extensions,
+ const __DRIconfig ***driver_configs, void *data)
+{
+ static const __DRIextension *emptyExtensionList[] = { NULL };
+ __DRIscreen *psp;
+ drmVersionPtr version;
+
+ if (driDriverAPI.InitScreen2 == NULL)
+ return NULL;
+
+ psp = calloc(1, sizeof(*psp));
+ if (!psp)
+ return NULL;
+
+ setupLoaderExtensions(psp, extensions);
+
+ version = drmGetVersion(fd);
+ if (version) {
+ psp->drm_version.major = version->version_major;
+ psp->drm_version.minor = version->version_minor;
+ psp->drm_version.patch = version->version_patchlevel;
+ drmFreeVersion(version);
+ }
+
+ psp->extensions = emptyExtensionList;
+ psp->fd = fd;
+ psp->myNum = scrn;
+ psp->dri2.enabled = GL_TRUE;
+
+ psp->DriverAPI = driDriverAPI;
+ psp->api_mask = (1 << __DRI_API_OPENGL);
+ *driver_configs = driDriverAPI.InitScreen2(psp);
+ if (*driver_configs == NULL) {
+ free(psp);
+ return NULL;
+ }
+
+ psp->DriverAPI = driDriverAPI;
+ psp->loaderPrivate = data;
+
+ driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions,
+ __dri2NConfigOptions);
+ driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum,
+ "dri2");
+
+ return psp;
+}
+
+static const __DRIextension **driGetExtensions(__DRIscreen *psp)
+{
+ return psp->extensions;
+}
+
+/** Core interface */
+const __DRIcoreExtension driCoreExtension = {
+ { __DRI_CORE, __DRI_CORE_VERSION },
+ NULL,
+ driDestroyScreen,
+ driGetExtensions,
+ driGetConfigAttrib,
+ driIndexConfigAttrib,
+ NULL,
+ driDestroyDrawable,
+ driSwapBuffers,
+ NULL,
+ driCopyContext,
+ driDestroyContext,
+ driBindContext,
+ driUnbindContext
+};
+
+/** Legacy DRI interface */
+const __DRIlegacyExtension driLegacyExtension = {
+ { __DRI_LEGACY, __DRI_LEGACY_VERSION },
+ driCreateNewScreen,
+ driCreateNewDrawable,
+ driCreateNewContext,
+};
+
+/** DRI2 interface */
+const __DRIdri2Extension driDRI2Extension = {
+ { __DRI_DRI2, __DRI_DRI2_VERSION },
+ dri2CreateNewScreen,
+ dri2CreateNewDrawable,
+ dri2CreateNewContext,
+ dri2GetAPIMask,
+ dri2CreateNewContextForAPI,
+ dri2AllocateBuffer,
+ dri2ReleaseBuffer
+};
+
+const __DRI2configQueryExtension dri2ConfigQueryExtension = {
+ { __DRI2_CONFIG_QUERY, __DRI2_CONFIG_QUERY_VERSION },
+ dri2ConfigQueryb,
+ dri2ConfigQueryi,
+ dri2ConfigQueryf,
+};
+
+/**
+ * Calculate amount of swap interval used between GLX buffer swaps.
+ *
+ * The usage value, on the range [0,max], is the fraction of total swap
+ * interval time used between GLX buffer swaps is calculated.
+ *
+ * \f$p = t_d / (i * t_r)\f$
+ *
+ * Where \f$t_d\f$ is the time since the last GLX buffer swap, \f$i\f$ is the
+ * swap interval (as set by \c glXSwapIntervalSGI), and \f$t_r\f$ time
+ * required for a single vertical refresh period (as returned by \c
+ * glXGetMscRateOML).
+ *
+ * See the documentation for the GLX_MESA_swap_frame_usage extension for more
+ * details.
+ *
+ * \param dPriv Pointer to the private drawable structure.
+ * \return If less than a single swap interval time period was required
+ * between GLX buffer swaps, a number greater than 0 and less than
+ * 1.0 is returned. If exactly one swap interval time period is
+ * required, 1.0 is returned, and if more than one is required then
+ * a number greater than 1.0 will be returned.
+ *
+ * \sa glXSwapIntervalSGI glXGetMscRateOML
+ *
+ * \todo Instead of caching the \c glXGetMscRateOML function pointer, would it
+ * be possible to cache the sync rate?
+ */
+float
+driCalculateSwapUsage( __DRIdrawable *dPriv, int64_t last_swap_ust,
+ int64_t current_ust )
+{
+ int32_t n;
+ int32_t d;
+ int interval;
+ float usage = 1.0;
+ __DRIscreen *psp = dPriv->driScreenPriv;
+
+ if ( (*psp->systemTime->getMSCRate)(dPriv, &n, &d, dPriv->loaderPrivate) ) {
+ interval = (dPriv->swap_interval != 0) ? dPriv->swap_interval : 1;
+
+
+ /* We want to calculate
+ * (current_UST - last_swap_UST) / (interval * us_per_refresh). We get
+ * current_UST by calling __glXGetUST. last_swap_UST is stored in
+ * dPriv->swap_ust. interval has already been calculated.
+ *
+ * The only tricky part is us_per_refresh. us_per_refresh is
+ * 1000000 / MSC_rate. We know the MSC_rate is n / d. We can flip it
+ * around and say us_per_refresh = 1000000 * d / n. Since this goes in
+ * the denominator of the final calculation, we calculate
+ * (interval * 1000000 * d) and move n into the numerator.
+ */
+
+ usage = (current_ust - last_swap_ust);
+ usage *= n;
+ usage /= (interval * d);
+ usage /= 1000000.0;
+ }
+
+ return usage;
+}
+
+void
+dri2InvalidateDrawable(__DRIdrawable *drawable)
+{
+ drawable->dri2.stamp++;
+}
+
+/*@}*/
diff --git a/mesalib/src/mesa/drivers/dri/common/dri_util.h b/mesalib/src/mesa/drivers/dri/common/dri_util.h
index 3d3d5c9cd..8d2a38524 100644
--- a/mesalib/src/mesa/drivers/dri/common/dri_util.h
+++ b/mesalib/src/mesa/drivers/dri/common/dri_util.h
@@ -1,563 +1,563 @@
-/*
- * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file dri_util.h
- * DRI utility functions definitions.
- *
- * This module acts as glue between GLX and the actual hardware driver. A DRI
- * driver doesn't really \e have to use any of this - it's optional. But, some
- * useful stuff is done here that otherwise would have to be duplicated in most
- * drivers.
- *
- * Basically, these utility functions take care of some of the dirty details of
- * screen initialization, context creation, context binding, DRM setup, etc.
- *
- * These functions are compiled into each DRI driver so libGL.so knows nothing
- * about them.
- *
- * \sa dri_util.c.
- *
- * \author Kevin E. Martin <kevin@precisioninsight.com>
- * \author Brian Paul <brian@precisioninsight.com>
- */
-
-#ifndef _DRI_UTIL_H_
-#define _DRI_UTIL_H_
-
-#include <GL/gl.h>
-#include <drm.h>
-#include <drm_sarea.h>
-#include <xf86drm.h>
-#include "xmlconfig.h"
-#include "main/glheader.h"
-#include "main/mtypes.h"
-#include "GL/internal/dri_interface.h"
-
-#define GLX_BAD_CONTEXT 5
-
-typedef struct __DRIswapInfoRec __DRIswapInfo;
-
-/**
- * Extensions.
- */
-extern const __DRIlegacyExtension driLegacyExtension;
-extern const __DRIcoreExtension driCoreExtension;
-extern const __DRIdri2Extension driDRI2Extension;
-extern const __DRIextension driReadDrawableExtension;
-extern const __DRIcopySubBufferExtension driCopySubBufferExtension;
-extern const __DRIswapControlExtension driSwapControlExtension;
-extern const __DRImediaStreamCounterExtension driMediaStreamCounterExtension;
-extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
-
-/**
- * Used by DRI_VALIDATE_DRAWABLE_INFO
- */
-#define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
- do { \
- if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
- __driUtilUpdateDrawableInfo(pDrawPriv); \
- } \
- } while (0)
-
-
-/**
- * Utility macro to validate the drawable information.
- *
- * See __DRIdrawable::pStamp and __DRIdrawable::lastStamp.
- */
-#define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
-do { \
- while (*(pdp->pStamp) != pdp->lastStamp) { \
- register unsigned int hwContext = psp->pSAREA->lock.lock & \
- ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
- DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
- \
- DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
- DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
- DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
- \
- DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
- } \
-} while (0)
-
-/**
- * Same as above, but for two drawables simultaneously.
- *
- */
-
-#define DRI_VALIDATE_TWO_DRAWABLES_INFO(psp, pdp, prp) \
-do { \
- while (*((pdp)->pStamp) != (pdp)->lastStamp || \
- *((prp)->pStamp) != (prp)->lastStamp) { \
- register unsigned int hwContext = (psp)->pSAREA->lock.lock & \
- ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
- DRM_UNLOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
- \
- DRM_SPINLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
- DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
- DRI_VALIDATE_DRAWABLE_INFO_ONCE(prp); \
- DRM_SPINUNLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
- \
- DRM_LIGHT_LOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
- } \
-} while (0)
-
-
-/**
- * Driver callback functions.
- *
- * Each DRI driver must have one of these structures with all the pointers set
- * to appropriate functions within the driver.
- *
- * When glXCreateContext() is called, for example, it'll call a helper function
- * dri_util.c which in turn will jump through the \a CreateContext pointer in
- * this structure.
- */
-struct __DriverAPIRec {
- const __DRIconfig **(*InitScreen) (__DRIscreen * priv);
-
- /**
- * Screen destruction callback
- */
- void (*DestroyScreen)(__DRIscreen *driScrnPriv);
-
- /**
- * Context creation callback
- */
- GLboolean (*CreateContext)(gl_api api,
- const struct gl_config *glVis,
- __DRIcontext *driContextPriv,
- void *sharedContextPrivate);
-
- /**
- * Context destruction callback
- */
- void (*DestroyContext)(__DRIcontext *driContextPriv);
-
- /**
- * Buffer (drawable) creation callback
- */
- GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv,
- __DRIdrawable *driDrawPriv,
- const struct gl_config *glVis,
- GLboolean pixmapBuffer);
-
- /**
- * Buffer (drawable) destruction callback
- */
- void (*DestroyBuffer)(__DRIdrawable *driDrawPriv);
-
- /**
- * Buffer swapping callback
- */
- void (*SwapBuffers)(__DRIdrawable *driDrawPriv);
-
- /**
- * Context activation callback
- */
- GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv,
- __DRIdrawable *driDrawPriv,
- __DRIdrawable *driReadPriv);
-
- /**
- * Context unbinding callback
- */
- GLboolean (*UnbindContext)(__DRIcontext *driContextPriv);
-
- /**
- * Retrieves statistics about buffer swap operations. Required if
- * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
- */
- int (*GetSwapInfo)( __DRIdrawable *dPriv, __DRIswapInfo * sInfo );
-
-
- /**
- * These are required if GLX_OML_sync_control is supported.
- */
- /*@{*/
- int (*WaitForMSC)( __DRIdrawable *priv, int64_t target_msc,
- int64_t divisor, int64_t remainder,
- int64_t * msc );
- int (*WaitForSBC)( __DRIdrawable *priv, int64_t target_sbc,
- int64_t * msc, int64_t * sbc );
-
- int64_t (*SwapBuffersMSC)( __DRIdrawable *priv, int64_t target_msc,
- int64_t divisor, int64_t remainder );
- /*@}*/
- void (*CopySubBuffer)(__DRIdrawable *driDrawPriv,
- int x, int y, int w, int h);
-
- /**
- * New version of GetMSC so we can pass drawable data to the low
- * level DRM driver (e.g. pipe info). Required if
- * GLX_SGI_video_sync or GLX_OML_sync_control is supported.
- */
- int (*GetDrawableMSC) ( __DRIscreen * priv,
- __DRIdrawable *drawablePrivate,
- int64_t *count);
-
-
-
- /* DRI2 Entry point */
- const __DRIconfig **(*InitScreen2) (__DRIscreen * priv);
-
- __DRIbuffer *(*AllocateBuffer) (__DRIscreen *screenPrivate,
- unsigned int attachment,
- unsigned int format,
- int width, int height);
- void (*ReleaseBuffer) (__DRIscreen *screenPrivate, __DRIbuffer *buffer);
-};
-
-extern const struct __DriverAPIRec driDriverAPI;
-
-
-struct __DRIswapInfoRec {
- /**
- * Number of swapBuffers operations that have been *completed*.
- */
- uint64_t swap_count;
-
- /**
- * Unadjusted system time of the last buffer swap. This is the time
- * when the swap completed, not the time when swapBuffers was called.
- */
- int64_t swap_ust;
-
- /**
- * Number of swap operations that occurred after the swap deadline. That
- * is if a swap happens more than swap_interval frames after the previous
- * swap, it has missed its deadline. If swap_interval is 0, then the
- * swap deadline is 1 frame after the previous swap.
- */
- uint64_t swap_missed_count;
-
- /**
- * Amount of time used by the last swap that missed its deadline. This
- * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
- * time_for_single_vrefresh)). If the actual value of swap_interval is
- * 0, then 1 is used instead. If swap_missed_count is non-zero, this
- * should be greater-than 1.0.
- */
- float swap_missed_usage;
-};
-
-
-/**
- * Per-drawable private DRI driver information.
- */
-struct __DRIdrawableRec {
- /**
- * Kernel drawable handle
- */
- drm_drawable_t hHWDrawable;
-
- /**
- * Driver's private drawable information.
- *
- * This structure is opaque.
- */
- void *driverPrivate;
-
- /**
- * Private data from the loader. We just hold on to it and pass
- * it back when calling into loader provided functions.
- */
- void *loaderPrivate;
-
- /**
- * Reference count for number of context's currently bound to this
- * drawable.
- *
- * Once it reaches zero, the drawable can be destroyed.
- *
- * \note This behavior will change with GLX 1.3.
- */
- int refcount;
-
- /**
- * Index of this drawable information in the SAREA.
- */
- unsigned int index;
-
- /**
- * Pointer to the "drawable has changed ID" stamp in the SAREA (or
- * to dri2.stamp if DRI2 is being used).
- */
- unsigned int *pStamp;
-
- /**
- * Last value of the stamp.
- *
- * If this differs from the value stored at __DRIdrawable::pStamp,
- * then the drawable information has been modified by the X server, and the
- * drawable information (below) should be retrieved from the X server.
- */
- unsigned int lastStamp;
-
- /**
- * \name Drawable
- *
- * Drawable information used in software fallbacks.
- */
- /*@{*/
- int x;
- int y;
- int w;
- int h;
- int numClipRects;
- drm_clip_rect_t *pClipRects;
- /*@}*/
-
- /**
- * \name Back and depthbuffer
- *
- * Information about the back and depthbuffer where different from above.
- */
- /*@{*/
- int backX;
- int backY;
- int backClipRectType;
- int numBackClipRects;
- drm_clip_rect_t *pBackClipRects;
- /*@}*/
-
- /**
- * \name Vertical blank tracking information
- * Used for waiting on vertical blank events.
- */
- /*@{*/
- unsigned int vblSeq;
- unsigned int vblFlags;
- /*@}*/
-
- /**
- * \name Monotonic MSC tracking
- *
- * Low level driver is responsible for updating msc_base and
- * vblSeq values so that higher level code can calculate
- * a new msc value or msc target for a WaitMSC call. The new value
- * will be:
- * msc = msc_base + get_vblank_count() - vblank_base;
- *
- * And for waiting on a value, core code will use:
- * actual_target = target_msc - msc_base + vblank_base;
- */
- /*@{*/
- int64_t vblank_base;
- int64_t msc_base;
- /*@}*/
-
- /**
- * Pointer to context to which this drawable is currently bound.
- */
- __DRIcontext *driContextPriv;
-
- /**
- * Pointer to screen on which this drawable was created.
- */
- __DRIscreen *driScreenPriv;
-
- /**
- * Controls swap interval as used by GLX_SGI_swap_control and
- * GLX_MESA_swap_control.
- */
- unsigned int swap_interval;
-
- struct {
- unsigned int stamp;
- drm_clip_rect_t clipRect;
- } dri2;
-};
-
-/**
- * Per-context private driver information.
- */
-struct __DRIcontextRec {
- /**
- * Kernel context handle used to access the device lock.
- */
- drm_context_t hHWContext;
-
- /**
- * Device driver's private context data. This structure is opaque.
- */
- void *driverPrivate;
-
- /**
- * Pointer to drawable currently bound to this context for drawing.
- */
- __DRIdrawable *driDrawablePriv;
-
- /**
- * Pointer to drawable currently bound to this context for reading.
- */
- __DRIdrawable *driReadablePriv;
-
- /**
- * Pointer to screen on which this context was created.
- */
- __DRIscreen *driScreenPriv;
-
- /**
- * The loaders's private context data. This structure is opaque.
- */
- void *loaderPrivate;
-
- struct {
- int draw_stamp;
- int read_stamp;
- } dri2;
-};
-
-/**
- * Per-screen private driver information.
- */
-struct __DRIscreenRec {
- /**
- * Current screen's number
- */
- int myNum;
-
- /**
- * Callback functions into the hardware-specific DRI driver code.
- */
- struct __DriverAPIRec DriverAPI;
-
- const __DRIextension **extensions;
- /**
- * DDX / 2D driver version information.
- */
- __DRIversion ddx_version;
-
- /**
- * DRI X extension version information.
- */
- __DRIversion dri_version;
-
- /**
- * DRM (kernel module) version information.
- */
- __DRIversion drm_version;
-
- /**
- * ID used when the client sets the drawable lock.
- *
- * The X server uses this value to detect if the client has died while
- * holding the drawable lock.
- */
- int drawLockID;
-
- /**
- * File descriptor returned when the kernel device driver is opened.
- *
- * Used to:
- * - authenticate client to kernel
- * - map the frame buffer, SAREA, etc.
- * - close the kernel device driver
- */
- int fd;
-
- /**
- * SAREA pointer
- *
- * Used to access:
- * - the device lock
- * - the device-independent per-drawable and per-context(?) information
- */
- drm_sarea_t *pSAREA;
-
- /**
- * \name Direct frame buffer access information
- * Used for software fallbacks.
- */
- /*@{*/
- unsigned char *pFB;
- int fbSize;
- int fbOrigin;
- int fbStride;
- int fbWidth;
- int fbHeight;
- int fbBPP;
- /*@}*/
-
- /**
- * \name Device-dependent private information (stored in the SAREA).
- *
- * This data is accessed by the client driver only.
- */
- /*@{*/
- void *pDevPriv;
- int devPrivSize;
- /*@}*/
-
- /**
- * Device-dependent private information (not stored in the SAREA).
- *
- * This pointer is never touched by the DRI layer.
- */
-#ifdef __cplusplus
- void *priv;
-#else
- void *private;
-#endif
-
- /* Extensions provided by the loader. */
- const __DRIgetDrawableInfoExtension *getDrawableInfo;
- const __DRIsystemTimeExtension *systemTime;
- const __DRIdamageExtension *damage;
-
- struct {
- /* Flag to indicate that this is a DRI2 screen. Many of the above
- * fields will not be valid or initializaed in that case. */
- int enabled;
- __DRIdri2LoaderExtension *loader;
- __DRIimageLookupExtension *image;
- __DRIuseInvalidateExtension *useInvalidate;
- } dri2;
-
- /* The lock actually in use, old sarea or DRI2 */
- drmLock *lock;
-
- driOptionCache optionInfo;
- driOptionCache optionCache;
- unsigned int api_mask;
- void *loaderPrivate;
-};
-
-extern void
-__driUtilUpdateDrawableInfo(__DRIdrawable *pdp);
-
-extern float
-driCalculateSwapUsage( __DRIdrawable *dPriv,
- int64_t last_swap_ust, int64_t current_ust );
-
-extern GLint
-driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 );
-
-extern void
-dri2InvalidateDrawable(__DRIdrawable *drawable);
-
-#endif /* _DRI_UTIL_H_ */
+/*
+ * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file dri_util.h
+ * DRI utility functions definitions.
+ *
+ * This module acts as glue between GLX and the actual hardware driver. A DRI
+ * driver doesn't really \e have to use any of this - it's optional. But, some
+ * useful stuff is done here that otherwise would have to be duplicated in most
+ * drivers.
+ *
+ * Basically, these utility functions take care of some of the dirty details of
+ * screen initialization, context creation, context binding, DRM setup, etc.
+ *
+ * These functions are compiled into each DRI driver so libGL.so knows nothing
+ * about them.
+ *
+ * \sa dri_util.c.
+ *
+ * \author Kevin E. Martin <kevin@precisioninsight.com>
+ * \author Brian Paul <brian@precisioninsight.com>
+ */
+
+#ifndef _DRI_UTIL_H_
+#define _DRI_UTIL_H_
+
+#include <GL/gl.h>
+#include <drm.h>
+#include <drm_sarea.h>
+#include <xf86drm.h>
+#include "xmlconfig.h"
+#include "main/glheader.h"
+#include "main/mtypes.h"
+#include "GL/internal/dri_interface.h"
+
+#define GLX_BAD_CONTEXT 5
+
+typedef struct __DRIswapInfoRec __DRIswapInfo;
+
+/**
+ * Extensions.
+ */
+extern const __DRIlegacyExtension driLegacyExtension;
+extern const __DRIcoreExtension driCoreExtension;
+extern const __DRIdri2Extension driDRI2Extension;
+extern const __DRIextension driReadDrawableExtension;
+extern const __DRIcopySubBufferExtension driCopySubBufferExtension;
+extern const __DRIswapControlExtension driSwapControlExtension;
+extern const __DRImediaStreamCounterExtension driMediaStreamCounterExtension;
+extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
+
+/**
+ * Used by DRI_VALIDATE_DRAWABLE_INFO
+ */
+#define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
+ do { \
+ if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
+ __driUtilUpdateDrawableInfo(pDrawPriv); \
+ } \
+ } while (0)
+
+
+/**
+ * Utility macro to validate the drawable information.
+ *
+ * See __DRIdrawable::pStamp and __DRIdrawable::lastStamp.
+ */
+#define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
+do { \
+ while (*(pdp->pStamp) != pdp->lastStamp) { \
+ register unsigned int hwContext = psp->pSAREA->lock.lock & \
+ ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
+ DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
+ \
+ DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
+ DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
+ DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
+ \
+ DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
+ } \
+} while (0)
+
+/**
+ * Same as above, but for two drawables simultaneously.
+ *
+ */
+
+#define DRI_VALIDATE_TWO_DRAWABLES_INFO(psp, pdp, prp) \
+do { \
+ while (*((pdp)->pStamp) != (pdp)->lastStamp || \
+ *((prp)->pStamp) != (prp)->lastStamp) { \
+ register unsigned int hwContext = (psp)->pSAREA->lock.lock & \
+ ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
+ DRM_UNLOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
+ \
+ DRM_SPINLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
+ DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
+ DRI_VALIDATE_DRAWABLE_INFO_ONCE(prp); \
+ DRM_SPINUNLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
+ \
+ DRM_LIGHT_LOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
+ } \
+} while (0)
+
+
+/**
+ * Driver callback functions.
+ *
+ * Each DRI driver must have one of these structures with all the pointers set
+ * to appropriate functions within the driver.
+ *
+ * When glXCreateContext() is called, for example, it'll call a helper function
+ * dri_util.c which in turn will jump through the \a CreateContext pointer in
+ * this structure.
+ */
+struct __DriverAPIRec {
+ const __DRIconfig **(*InitScreen) (__DRIscreen * priv);
+
+ /**
+ * Screen destruction callback
+ */
+ void (*DestroyScreen)(__DRIscreen *driScrnPriv);
+
+ /**
+ * Context creation callback
+ */
+ GLboolean (*CreateContext)(gl_api api,
+ const struct gl_config *glVis,
+ __DRIcontext *driContextPriv,
+ void *sharedContextPrivate);
+
+ /**
+ * Context destruction callback
+ */
+ void (*DestroyContext)(__DRIcontext *driContextPriv);
+
+ /**
+ * Buffer (drawable) creation callback
+ */
+ GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv,
+ __DRIdrawable *driDrawPriv,
+ const struct gl_config *glVis,
+ GLboolean pixmapBuffer);
+
+ /**
+ * Buffer (drawable) destruction callback
+ */
+ void (*DestroyBuffer)(__DRIdrawable *driDrawPriv);
+
+ /**
+ * Buffer swapping callback
+ */
+ void (*SwapBuffers)(__DRIdrawable *driDrawPriv);
+
+ /**
+ * Context activation callback
+ */
+ GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv,
+ __DRIdrawable *driDrawPriv,
+ __DRIdrawable *driReadPriv);
+
+ /**
+ * Context unbinding callback
+ */
+ GLboolean (*UnbindContext)(__DRIcontext *driContextPriv);
+
+ /**
+ * Retrieves statistics about buffer swap operations. Required if
+ * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
+ */
+ int (*GetSwapInfo)( __DRIdrawable *dPriv, __DRIswapInfo * sInfo );
+
+
+ /**
+ * These are required if GLX_OML_sync_control is supported.
+ */
+ /*@{*/
+ int (*WaitForMSC)( __DRIdrawable *priv, int64_t target_msc,
+ int64_t divisor, int64_t remainder,
+ int64_t * msc );
+ int (*WaitForSBC)( __DRIdrawable *priv, int64_t target_sbc,
+ int64_t * msc, int64_t * sbc );
+
+ int64_t (*SwapBuffersMSC)( __DRIdrawable *priv, int64_t target_msc,
+ int64_t divisor, int64_t remainder );
+ /*@}*/
+ void (*CopySubBuffer)(__DRIdrawable *driDrawPriv,
+ int x, int y, int w, int h);
+
+ /**
+ * New version of GetMSC so we can pass drawable data to the low
+ * level DRM driver (e.g. pipe info). Required if
+ * GLX_SGI_video_sync or GLX_OML_sync_control is supported.
+ */
+ int (*GetDrawableMSC) ( __DRIscreen * priv,
+ __DRIdrawable *drawablePrivate,
+ int64_t *count);
+
+
+
+ /* DRI2 Entry point */
+ const __DRIconfig **(*InitScreen2) (__DRIscreen * priv);
+
+ __DRIbuffer *(*AllocateBuffer) (__DRIscreen *screenPrivate,
+ unsigned int attachment,
+ unsigned int format,
+ int width, int height);
+ void (*ReleaseBuffer) (__DRIscreen *screenPrivate, __DRIbuffer *buffer);
+};
+
+extern const struct __DriverAPIRec driDriverAPI;
+
+
+struct __DRIswapInfoRec {
+ /**
+ * Number of swapBuffers operations that have been *completed*.
+ */
+ uint64_t swap_count;
+
+ /**
+ * Unadjusted system time of the last buffer swap. This is the time
+ * when the swap completed, not the time when swapBuffers was called.
+ */
+ int64_t swap_ust;
+
+ /**
+ * Number of swap operations that occurred after the swap deadline. That
+ * is if a swap happens more than swap_interval frames after the previous
+ * swap, it has missed its deadline. If swap_interval is 0, then the
+ * swap deadline is 1 frame after the previous swap.
+ */
+ uint64_t swap_missed_count;
+
+ /**
+ * Amount of time used by the last swap that missed its deadline. This
+ * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
+ * time_for_single_vrefresh)). If the actual value of swap_interval is
+ * 0, then 1 is used instead. If swap_missed_count is non-zero, this
+ * should be greater-than 1.0.
+ */
+ float swap_missed_usage;
+};
+
+
+/**
+ * Per-drawable private DRI driver information.
+ */
+struct __DRIdrawableRec {
+ /**
+ * Kernel drawable handle
+ */
+ drm_drawable_t hHWDrawable;
+
+ /**
+ * Driver's private drawable information.
+ *
+ * This structure is opaque.
+ */
+ void *driverPrivate;
+
+ /**
+ * Private data from the loader. We just hold on to it and pass
+ * it back when calling into loader provided functions.
+ */
+ void *loaderPrivate;
+
+ /**
+ * Reference count for number of context's currently bound to this
+ * drawable.
+ *
+ * Once it reaches zero, the drawable can be destroyed.
+ *
+ * \note This behavior will change with GLX 1.3.
+ */
+ int refcount;
+
+ /**
+ * Index of this drawable information in the SAREA.
+ */
+ unsigned int index;
+
+ /**
+ * Pointer to the "drawable has changed ID" stamp in the SAREA (or
+ * to dri2.stamp if DRI2 is being used).
+ */
+ unsigned int *pStamp;
+
+ /**
+ * Last value of the stamp.
+ *
+ * If this differs from the value stored at __DRIdrawable::pStamp,
+ * then the drawable information has been modified by the X server, and the
+ * drawable information (below) should be retrieved from the X server.
+ */
+ unsigned int lastStamp;
+
+ /**
+ * \name Drawable
+ *
+ * Drawable information used in software fallbacks.
+ */
+ /*@{*/
+ int x;
+ int y;
+ int w;
+ int h;
+ int numClipRects;
+ drm_clip_rect_t *pClipRects;
+ /*@}*/
+
+ /**
+ * \name Back and depthbuffer
+ *
+ * Information about the back and depthbuffer where different from above.
+ */
+ /*@{*/
+ int backX;
+ int backY;
+ int backClipRectType;
+ int numBackClipRects;
+ drm_clip_rect_t *pBackClipRects;
+ /*@}*/
+
+ /**
+ * \name Vertical blank tracking information
+ * Used for waiting on vertical blank events.
+ */
+ /*@{*/
+ unsigned int vblSeq;
+ unsigned int vblFlags;
+ /*@}*/
+
+ /**
+ * \name Monotonic MSC tracking
+ *
+ * Low level driver is responsible for updating msc_base and
+ * vblSeq values so that higher level code can calculate
+ * a new msc value or msc target for a WaitMSC call. The new value
+ * will be:
+ * msc = msc_base + get_vblank_count() - vblank_base;
+ *
+ * And for waiting on a value, core code will use:
+ * actual_target = target_msc - msc_base + vblank_base;
+ */
+ /*@{*/
+ int64_t vblank_base;
+ int64_t msc_base;
+ /*@}*/
+
+ /**
+ * Pointer to context to which this drawable is currently bound.
+ */
+ __DRIcontext *driContextPriv;
+
+ /**
+ * Pointer to screen on which this drawable was created.
+ */
+ __DRIscreen *driScreenPriv;
+
+ /**
+ * Controls swap interval as used by GLX_SGI_swap_control and
+ * GLX_MESA_swap_control.
+ */
+ unsigned int swap_interval;
+
+ struct {
+ unsigned int stamp;
+ drm_clip_rect_t clipRect;
+ } dri2;
+};
+
+/**
+ * Per-context private driver information.
+ */
+struct __DRIcontextRec {
+ /**
+ * Kernel context handle used to access the device lock.
+ */
+ drm_context_t hHWContext;
+
+ /**
+ * Device driver's private context data. This structure is opaque.
+ */
+ void *driverPrivate;
+
+ /**
+ * Pointer to drawable currently bound to this context for drawing.
+ */
+ __DRIdrawable *driDrawablePriv;
+
+ /**
+ * Pointer to drawable currently bound to this context for reading.
+ */
+ __DRIdrawable *driReadablePriv;
+
+ /**
+ * Pointer to screen on which this context was created.
+ */
+ __DRIscreen *driScreenPriv;
+
+ /**
+ * The loaders's private context data. This structure is opaque.
+ */
+ void *loaderPrivate;
+
+ struct {
+ int draw_stamp;
+ int read_stamp;
+ } dri2;
+};
+
+/**
+ * Per-screen private driver information.
+ */
+struct __DRIscreenRec {
+ /**
+ * Current screen's number
+ */
+ int myNum;
+
+ /**
+ * Callback functions into the hardware-specific DRI driver code.
+ */
+ struct __DriverAPIRec DriverAPI;
+
+ const __DRIextension **extensions;
+ /**
+ * DDX / 2D driver version information.
+ */
+ __DRIversion ddx_version;
+
+ /**
+ * DRI X extension version information.
+ */
+ __DRIversion dri_version;
+
+ /**
+ * DRM (kernel module) version information.
+ */
+ __DRIversion drm_version;
+
+ /**
+ * ID used when the client sets the drawable lock.
+ *
+ * The X server uses this value to detect if the client has died while
+ * holding the drawable lock.
+ */
+ int drawLockID;
+
+ /**
+ * File descriptor returned when the kernel device driver is opened.
+ *
+ * Used to:
+ * - authenticate client to kernel
+ * - map the frame buffer, SAREA, etc.
+ * - close the kernel device driver
+ */
+ int fd;
+
+ /**
+ * SAREA pointer
+ *
+ * Used to access:
+ * - the device lock
+ * - the device-independent per-drawable and per-context(?) information
+ */
+ drm_sarea_t *pSAREA;
+
+ /**
+ * \name Direct frame buffer access information
+ * Used for software fallbacks.
+ */
+ /*@{*/
+ unsigned char *pFB;
+ int fbSize;
+ int fbOrigin;
+ int fbStride;
+ int fbWidth;
+ int fbHeight;
+ int fbBPP;
+ /*@}*/
+
+ /**
+ * \name Device-dependent private information (stored in the SAREA).
+ *
+ * This data is accessed by the client driver only.
+ */
+ /*@{*/
+ void *pDevPriv;
+ int devPrivSize;
+ /*@}*/
+
+ /**
+ * Device-dependent private information (not stored in the SAREA).
+ *
+ * This pointer is never touched by the DRI layer.
+ */
+#ifdef __cplusplus
+ void *priv;
+#else
+ void *private;
+#endif
+
+ /* Extensions provided by the loader. */
+ const __DRIgetDrawableInfoExtension *getDrawableInfo;
+ const __DRIsystemTimeExtension *systemTime;
+ const __DRIdamageExtension *damage;
+
+ struct {
+ /* Flag to indicate that this is a DRI2 screen. Many of the above
+ * fields will not be valid or initializaed in that case. */
+ int enabled;
+ __DRIdri2LoaderExtension *loader;
+ __DRIimageLookupExtension *image;
+ __DRIuseInvalidateExtension *useInvalidate;
+ } dri2;
+
+ /* The lock actually in use, old sarea or DRI2 */
+ drmLock *lock;
+
+ driOptionCache optionInfo;
+ driOptionCache optionCache;
+ unsigned int api_mask;
+ void *loaderPrivate;
+};
+
+extern void
+__driUtilUpdateDrawableInfo(__DRIdrawable *pdp);
+
+extern float
+driCalculateSwapUsage( __DRIdrawable *dPriv,
+ int64_t last_swap_ust, int64_t current_ust );
+
+extern GLint
+driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 );
+
+extern void
+dri2InvalidateDrawable(__DRIdrawable *drawable);
+
+#endif /* _DRI_UTIL_H_ */
diff --git a/mesalib/src/mesa/drivers/dri/common/utils.c b/mesalib/src/mesa/drivers/dri/common/utils.c
index a2b0b4e94..02c8cc6f5 100644
--- a/mesalib/src/mesa/drivers/dri/common/utils.c
+++ b/mesalib/src/mesa/drivers/dri/common/utils.c
@@ -219,7 +219,9 @@ void driInitExtensions( struct gl_context * ctx,
/* Map the static functions. Together with those mapped by remap
* table, this should cover everything mesa core knows.
*/
+#ifdef _GLAPI_USE_REMAP_TABLE
_mesa_map_static_functions();
+#endif
return;
}
diff --git a/mesalib/src/mesa/drivers/dri/swrast/swrast.c b/mesalib/src/mesa/drivers/dri/swrast/swrast.c
index 719b406ec..e6d1ab741 100644
--- a/mesalib/src/mesa/drivers/dri/swrast/swrast.c
+++ b/mesalib/src/mesa/drivers/dri/swrast/swrast.c
@@ -1,806 +1,811 @@
-/*
- * Copyright 2008, 2010 George Sapountzis <gsapountzis@gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DRI software rasterizer
- *
- * This is the mesa swrast module packaged into a DRI driver structure.
- *
- * The front-buffer is allocated by the loader. The loader provides read/write
- * callbacks for access to the front-buffer. The driver uses a scratch row for
- * front-buffer rendering to avoid repeated calls to the loader.
- *
- * The back-buffer is allocated by the driver and is private.
- */
-
-#include "main/context.h"
-#include "main/extensions.h"
-#include "main/formats.h"
-#include "main/framebuffer.h"
-#include "main/imports.h"
-#include "main/renderbuffer.h"
-#include "swrast/swrast.h"
-#include "swrast_setup/swrast_setup.h"
-#include "tnl/tnl.h"
-#include "tnl/t_context.h"
-#include "tnl/t_pipeline.h"
-#include "vbo/vbo.h"
-#include "drivers/common/driverfuncs.h"
-#include "drivers/common/meta.h"
-#include "utils.h"
-
-#include "main/teximage.h"
-#include "main/texformat.h"
-#include "main/texstate.h"
-
-#include "swrast_priv.h"
-
-
-/**
- * Screen and config-related functions
- */
-
-static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
- GLint texture_format, __DRIdrawable *dPriv)
-{
- struct dri_context *dri_ctx;
- int x, y, w, h;
- __DRIscreen *sPriv = dPriv->driScreenPriv;
- struct gl_texture_unit *texUnit;
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- uint32_t internalFormat;
- gl_format texFormat;
-
- dri_ctx = pDRICtx->driverPrivate;
-
- internalFormat = (texture_format == __DRI_TEXTURE_FORMAT_RGB ? 3 : 4);
-
- texUnit = _mesa_get_current_tex_unit(&dri_ctx->Base);
- texObj = _mesa_select_tex_object(&dri_ctx->Base, texUnit, target);
- texImage = _mesa_get_tex_image(&dri_ctx->Base, texObj, target, 0);
-
- _mesa_lock_texture(&dri_ctx->Base, texObj);
-
- sPriv->swrast_loader->getDrawableInfo(dPriv, &x, &y, &w, &h, dPriv->loaderPrivate);
-
- if (texture_format == __DRI_TEXTURE_FORMAT_RGB)
- texFormat = MESA_FORMAT_XRGB8888;
- else
- texFormat = MESA_FORMAT_ARGB8888;
-
- _mesa_init_teximage_fields(&dri_ctx->Base, target, texImage,
- w, h, 1, 0, internalFormat, texFormat);
-
- sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)texImage->Data,
- dPriv->loaderPrivate);
-
- _mesa_unlock_texture(&dri_ctx->Base, texObj);
-}
-
-static void swrastSetTexBuffer(__DRIcontext *pDRICtx, GLint target,
- __DRIdrawable *dPriv)
-{
- swrastSetTexBuffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv);
-}
-
-static const __DRItexBufferExtension swrastTexBufferExtension = {
- { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
- swrastSetTexBuffer,
- swrastSetTexBuffer2,
-};
-
-static const __DRIextension *dri_screen_extensions[] = {
- &swrastTexBufferExtension.base,
- NULL
-};
-
-static __DRIconfig **
-swrastFillInModes(__DRIscreen *psp,
- unsigned pixel_bits, unsigned depth_bits,
- unsigned stencil_bits, GLboolean have_back_buffer)
-{
- __DRIconfig **configs;
- unsigned depth_buffer_factor;
- unsigned back_buffer_factor;
- GLenum fb_format;
- GLenum fb_type;
-
- /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
- * support pageflipping at all.
- */
- static const GLenum back_buffer_modes[] = {
- GLX_NONE, GLX_SWAP_UNDEFINED_OML
- };
-
- uint8_t depth_bits_array[4];
- uint8_t stencil_bits_array[4];
- uint8_t msaa_samples_array[1];
-
- depth_bits_array[0] = 0;
- depth_bits_array[1] = 0;
- depth_bits_array[2] = depth_bits;
- depth_bits_array[3] = depth_bits;
-
- /* Just like with the accumulation buffer, always provide some modes
- * with a stencil buffer.
- */
- stencil_bits_array[0] = 0;
- stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
- stencil_bits_array[2] = 0;
- stencil_bits_array[3] = (stencil_bits == 0) ? 8 : stencil_bits;
-
- msaa_samples_array[0] = 0;
-
- depth_buffer_factor = 4;
- back_buffer_factor = 2;
-
- switch (pixel_bits) {
- case 8:
- fb_format = GL_RGB;
- fb_type = GL_UNSIGNED_BYTE_2_3_3_REV;
- break;
- case 16:
- fb_format = GL_RGB;
- fb_type = GL_UNSIGNED_SHORT_5_6_5;
- break;
- case 24:
- fb_format = GL_BGR;
- fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
- break;
- case 32:
- fb_format = GL_BGRA;
- fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
- break;
- default:
- fprintf(stderr, "[%s:%u] bad depth %d\n", __func__, __LINE__,
- pixel_bits);
- return NULL;
- }
-
- configs = driCreateConfigs(fb_format, fb_type,
- depth_bits_array, stencil_bits_array,
- depth_buffer_factor, back_buffer_modes,
- back_buffer_factor, msaa_samples_array, 1,
- GL_TRUE);
- if (configs == NULL) {
- fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
- __LINE__);
- return NULL;
- }
-
- return configs;
-}
-
-static const __DRIconfig **
-dri_init_screen(__DRIscreen * psp)
-{
- __DRIconfig **configs8, **configs16, **configs24, **configs32;
-
- TRACE;
-
- psp->extensions = dri_screen_extensions;
-
- configs8 = swrastFillInModes(psp, 8, 8, 0, 1);
- configs16 = swrastFillInModes(psp, 16, 16, 0, 1);
- configs24 = swrastFillInModes(psp, 24, 24, 8, 1);
- configs32 = swrastFillInModes(psp, 32, 24, 8, 1);
-
- configs16 = driConcatConfigs(configs8, configs16);
- configs24 = driConcatConfigs(configs16, configs24);
- configs32 = driConcatConfigs(configs24, configs32);
-
- return (const __DRIconfig **)configs32;
-}
-
-static void
-dri_destroy_screen(__DRIscreen * sPriv)
-{
- TRACE;
-}
-
-
-/**
- * Framebuffer and renderbuffer-related functions.
- */
-
-static GLuint
-choose_pixel_format(const struct gl_config *v)
-{
- int depth = v->rgbBits;
-
- if (depth == 32
- && v->redMask == 0xff0000
- && v->greenMask == 0x00ff00
- && v->blueMask == 0x0000ff)
- return PF_A8R8G8B8;
- else if (depth == 24
- && v->redMask == 0xff0000
- && v->greenMask == 0x00ff00
- && v->blueMask == 0x0000ff)
- return PF_X8R8G8B8;
- else if (depth == 16
- && v->redMask == 0xf800
- && v->greenMask == 0x07e0
- && v->blueMask == 0x001f)
- return PF_R5G6B5;
- else if (depth == 8
- && v->redMask == 0x07
- && v->greenMask == 0x38
- && v->blueMask == 0xc0)
- return PF_R3G3B2;
-
- _mesa_problem( NULL, "unexpected format in %s", __FUNCTION__ );
- return 0;
-}
-
-static void
-swrast_delete_renderbuffer(struct gl_renderbuffer *rb)
-{
- TRACE;
-
- free(rb->Data);
- free(rb);
-}
-
-/* see bytes_per_line in libGL */
-static INLINE int
-bytes_per_line(unsigned pitch_bits, unsigned mul)
-{
- unsigned mask = mul - 1;
-
- return ((pitch_bits + mask) & ~mask) / 8;
-}
-
-static GLboolean
-swrast_alloc_front_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLenum internalFormat, GLuint width, GLuint height)
-{
- struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-
- TRACE;
-
- rb->Data = NULL;
- rb->Width = width;
- rb->Height = height;
-
- xrb->pitch = bytes_per_line(width * xrb->bpp, 32);
-
- return GL_TRUE;
-}
-
-static GLboolean
-swrast_alloc_back_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLenum internalFormat, GLuint width, GLuint height)
-{
- struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-
- TRACE;
-
- free(rb->Data);
-
- swrast_alloc_front_storage(ctx, rb, internalFormat, width, height);
-
- rb->Data = malloc(height * xrb->pitch);
-
- return GL_TRUE;
-}
-
-static struct swrast_renderbuffer *
-swrast_new_renderbuffer(const struct gl_config *visual, GLboolean front)
-{
- struct swrast_renderbuffer *xrb = calloc(1, sizeof *xrb);
- GLuint pixel_format;
-
- TRACE;
-
- if (!xrb)
- return NULL;
-
- _mesa_init_renderbuffer(&xrb->Base, 0);
-
- pixel_format = choose_pixel_format(visual);
-
- xrb->Base.Delete = swrast_delete_renderbuffer;
- if (front) {
- xrb->Base.AllocStorage = swrast_alloc_front_storage;
- swrast_set_span_funcs_front(xrb, pixel_format);
- }
- else {
- xrb->Base.AllocStorage = swrast_alloc_back_storage;
- swrast_set_span_funcs_back(xrb, pixel_format);
- }
-
- switch (pixel_format) {
- case PF_A8R8G8B8:
- xrb->Base.Format = MESA_FORMAT_ARGB8888;
- xrb->Base.InternalFormat = GL_RGBA;
- xrb->Base._BaseFormat = GL_RGBA;
- xrb->Base.DataType = GL_UNSIGNED_BYTE;
- xrb->bpp = 32;
- break;
- case PF_X8R8G8B8:
- xrb->Base.Format = MESA_FORMAT_ARGB8888; /* XXX */
- xrb->Base.InternalFormat = GL_RGB;
- xrb->Base._BaseFormat = GL_RGB;
- xrb->Base.DataType = GL_UNSIGNED_BYTE;
- xrb->bpp = 32;
- break;
- case PF_R5G6B5:
- xrb->Base.Format = MESA_FORMAT_RGB565;
- xrb->Base.InternalFormat = GL_RGB;
- xrb->Base._BaseFormat = GL_RGB;
- xrb->Base.DataType = GL_UNSIGNED_BYTE;
- xrb->bpp = 16;
- break;
- case PF_R3G3B2:
- xrb->Base.Format = MESA_FORMAT_RGB332;
- xrb->Base.InternalFormat = GL_RGB;
- xrb->Base._BaseFormat = GL_RGB;
- xrb->Base.DataType = GL_UNSIGNED_BYTE;
- xrb->bpp = 8;
- break;
- default:
- return NULL;
- }
-
- return xrb;
-}
-
-static GLboolean
-dri_create_buffer(__DRIscreen * sPriv,
- __DRIdrawable * dPriv,
- const struct gl_config * visual, GLboolean isPixmap)
-{
- struct dri_drawable *drawable = NULL;
- struct gl_framebuffer *fb;
- struct swrast_renderbuffer *frontrb, *backrb;
-
- TRACE;
-
- drawable = CALLOC_STRUCT(dri_drawable);
- if (drawable == NULL)
- goto drawable_fail;
-
- dPriv->driverPrivate = drawable;
- drawable->dPriv = dPriv;
-
- drawable->row = malloc(MAX_WIDTH * 4);
- if (drawable->row == NULL)
- goto drawable_fail;
-
- fb = &drawable->Base;
-
- /* basic framebuffer setup */
- _mesa_initialize_window_framebuffer(fb, visual);
-
- /* add front renderbuffer */
- frontrb = swrast_new_renderbuffer(visual, GL_TRUE);
- _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontrb->Base);
-
- /* add back renderbuffer */
- if (visual->doubleBufferMode) {
- backrb = swrast_new_renderbuffer(visual, GL_FALSE);
- _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backrb->Base);
- }
-
- /* add software renderbuffers */
- _mesa_add_soft_renderbuffers(fb,
- GL_FALSE, /* color */
- visual->haveDepthBuffer,
- visual->haveStencilBuffer,
- visual->haveAccumBuffer,
- GL_FALSE, /* alpha */
- GL_FALSE /* aux bufs */);
-
- return GL_TRUE;
-
-drawable_fail:
-
- if (drawable)
- free(drawable->row);
-
- FREE(drawable);
-
- return GL_FALSE;
-}
-
-static void
-dri_destroy_buffer(__DRIdrawable * dPriv)
-{
- TRACE;
-
- if (dPriv) {
- struct dri_drawable *drawable = dri_drawable(dPriv);
- struct gl_framebuffer *fb;
-
- free(drawable->row);
-
- fb = &drawable->Base;
-
- fb->DeletePending = GL_TRUE;
- _mesa_reference_framebuffer(&fb, NULL);
- }
-}
-
-static void
-dri_swap_buffers(__DRIdrawable * dPriv)
-{
- __DRIscreen *sPriv = dPriv->driScreenPriv;
-
- GET_CURRENT_CONTEXT(ctx);
-
- struct dri_drawable *drawable = dri_drawable(dPriv);
- struct gl_framebuffer *fb;
- struct swrast_renderbuffer *frontrb, *backrb;
-
- TRACE;
-
- fb = &drawable->Base;
-
- frontrb =
- swrast_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
- backrb =
- swrast_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer);
-
- /* check for signle-buffered */
- if (backrb == NULL)
- return;
-
- /* check if swapping currently bound buffer */
- if (ctx && ctx->DrawBuffer == fb) {
- /* flush pending rendering */
- _mesa_notifySwapBuffers(ctx);
- }
-
- sPriv->swrast_loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
- 0, 0,
- frontrb->Base.Width,
- frontrb->Base.Height,
- backrb->Base.Data,
- dPriv->loaderPrivate);
-}
-
-
-/**
- * General device driver functions.
- */
-
-static void
-get_window_size( struct gl_framebuffer *fb, GLsizei *w, GLsizei *h )
-{
- __DRIdrawable *dPriv = swrast_drawable(fb)->dPriv;
- __DRIscreen *sPriv = dPriv->driScreenPriv;
- int x, y;
-
- sPriv->swrast_loader->getDrawableInfo(dPriv,
- &x, &y, w, h,
- dPriv->loaderPrivate);
-}
-
-static void
-swrast_check_and_update_window_size( struct gl_context *ctx, struct gl_framebuffer *fb )
-{
- GLsizei width, height;
-
- get_window_size(fb, &width, &height);
- if (fb->Width != width || fb->Height != height) {
- _mesa_resize_framebuffer(ctx, fb, width, height);
- }
-}
-
-static const GLubyte *
-get_string(struct gl_context *ctx, GLenum pname)
-{
- (void) ctx;
- switch (pname) {
- case GL_VENDOR:
- return (const GLubyte *) "Mesa Project";
- case GL_RENDERER:
- return (const GLubyte *) "Software Rasterizer";
- default:
- return NULL;
- }
-}
-
-static void
-update_state( struct gl_context *ctx, GLuint new_state )
-{
- /* not much to do here - pass it on */
- _swrast_InvalidateState( ctx, new_state );
- _swsetup_InvalidateState( ctx, new_state );
- _vbo_InvalidateState( ctx, new_state );
- _tnl_InvalidateState( ctx, new_state );
-}
-
-static void
-viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
-{
- struct gl_framebuffer *draw = ctx->WinSysDrawBuffer;
- struct gl_framebuffer *read = ctx->WinSysReadBuffer;
-
- swrast_check_and_update_window_size(ctx, draw);
- swrast_check_and_update_window_size(ctx, read);
-}
-
-static gl_format swrastChooseTextureFormat(struct gl_context * ctx,
- GLint internalFormat,
- GLenum format,
- GLenum type)
-{
- if (internalFormat == GL_RGB)
- return MESA_FORMAT_XRGB8888;
- return _mesa_choose_tex_format(ctx, internalFormat, format, type);
-}
-
-static void
-swrast_init_driver_functions(struct dd_function_table *driver)
-{
- driver->GetString = get_string;
- driver->UpdateState = update_state;
- driver->GetBufferSize = NULL;
- driver->Viewport = viewport;
- driver->ChooseTextureFormat = swrastChooseTextureFormat;
-}
-
-static const char *es2_extensions[] = {
- /* Used by mesa internally (cf all_mesa_extensions in ../common/utils.c) */
- "GL_ARB_draw_buffers",
- "GL_ARB_multisample",
- "GL_ARB_texture_compression",
- "GL_ARB_transpose_matrix",
- "GL_ARB_vertex_buffer_object",
- "GL_ARB_window_pos",
- "GL_EXT_blend_func_separate",
- "GL_EXT_compiled_vertex_array",
- "GL_EXT_framebuffer_blit",
- "GL_EXT_multi_draw_arrays",
- "GL_EXT_polygon_offset",
- "GL_EXT_texture_object",
- "GL_EXT_vertex_array",
- "GL_IBM_multimode_draw_arrays",
- "GL_MESA_window_pos",
- "GL_NV_vertex_program",
-
- /* Required by GLES2 */
- "GL_ARB_fragment_program",
- "GL_ARB_fragment_shader",
- "GL_ARB_multitexture",
- "GL_ARB_shader_objects",
- "GL_ARB_texture_cube_map",
- "GL_ARB_texture_mirrored_repeat",
- "GL_ARB_texture_non_power_of_two",
- "GL_ARB_vertex_shader",
- "GL_EXT_blend_color",
- "GL_EXT_blend_equation_separate",
- "GL_EXT_blend_minmax",
- "GL_EXT_blend_subtract",
- "GL_EXT_stencil_wrap",
-
- /* Optional GLES2 */
- "GL_ARB_framebuffer_object",
- "GL_EXT_texture_filter_anisotropic",
- "GL_ARB_depth_texture",
- "GL_EXT_packed_depth_stencil",
- "GL_EXT_framebuffer_object",
- NULL,
-};
-
-static void
-InitExtensionsES2(struct gl_context *ctx)
-{
- int i;
-
- /* Can't use driInitExtensions() since it uses extensions from
- * main/remap_helper.h when called the first time. */
-
- for (i = 0; es2_extensions[i]; i++)
- _mesa_enable_extension(ctx, es2_extensions[i]);
-}
-
-/**
- * Context-related functions.
- */
-
-static GLboolean
-dri_create_context(gl_api api,
- const struct gl_config * visual,
- __DRIcontext * cPriv, void *sharedContextPrivate)
-{
- struct dri_context *ctx = NULL;
- struct dri_context *share = (struct dri_context *)sharedContextPrivate;
- struct gl_context *mesaCtx = NULL;
- struct gl_context *sharedCtx = NULL;
- struct dd_function_table functions;
-
- TRACE;
-
- ctx = CALLOC_STRUCT(dri_context);
- if (ctx == NULL)
- goto context_fail;
-
- cPriv->driverPrivate = ctx;
- ctx->cPriv = cPriv;
-
- /* build table of device driver functions */
- _mesa_init_driver_functions(&functions);
- swrast_init_driver_functions(&functions);
-
- if (share) {
- sharedCtx = &share->Base;
- }
-
- mesaCtx = &ctx->Base;
-
- /* basic context setup */
- if (!_mesa_initialize_context(mesaCtx, api, visual, sharedCtx, &functions, (void *) cPriv)) {
- goto context_fail;
- }
-
- /* do bounds checking to prevent segfaults and server crashes! */
- mesaCtx->Const.CheckArrayBounds = GL_TRUE;
-
- /* create module contexts */
- _swrast_CreateContext( mesaCtx );
- _vbo_CreateContext( mesaCtx );
- _tnl_CreateContext( mesaCtx );
- _swsetup_CreateContext( mesaCtx );
- _swsetup_Wakeup( mesaCtx );
-
- /* use default TCL pipeline */
- {
- TNLcontext *tnl = TNL_CONTEXT(mesaCtx);
- tnl->Driver.RunPipeline = _tnl_run_pipeline;
- }
-
- _mesa_meta_init(mesaCtx);
- _mesa_enable_sw_extensions(mesaCtx);
-
- switch (api) {
- case API_OPENGL:
- _mesa_enable_1_3_extensions(mesaCtx);
- _mesa_enable_1_4_extensions(mesaCtx);
- _mesa_enable_1_5_extensions(mesaCtx);
- _mesa_enable_2_0_extensions(mesaCtx);
- _mesa_enable_2_1_extensions(mesaCtx);
-
- driInitExtensions( mesaCtx, NULL, GL_FALSE );
- break;
- case API_OPENGLES:
- _mesa_enable_1_3_extensions(mesaCtx);
- _mesa_enable_1_4_extensions(mesaCtx);
- _mesa_enable_1_5_extensions(mesaCtx);
-
- break;
- case API_OPENGLES2:
- InitExtensionsES2( mesaCtx);
- break;
- }
-
- return GL_TRUE;
-
-context_fail:
-
- FREE(ctx);
-
- return GL_FALSE;
-}
-
-static void
-dri_destroy_context(__DRIcontext * cPriv)
-{
- TRACE;
-
- if (cPriv) {
- struct dri_context *ctx = dri_context(cPriv);
- struct gl_context *mesaCtx;
-
- mesaCtx = &ctx->Base;
-
- _mesa_meta_free(mesaCtx);
- _swsetup_DestroyContext( mesaCtx );
- _swrast_DestroyContext( mesaCtx );
- _tnl_DestroyContext( mesaCtx );
- _vbo_DestroyContext( mesaCtx );
- _mesa_destroy_context( mesaCtx );
- }
-}
-
-static GLboolean
-dri_make_current(__DRIcontext * cPriv,
- __DRIdrawable * driDrawPriv,
- __DRIdrawable * driReadPriv)
-{
- struct gl_context *mesaCtx;
- struct gl_framebuffer *mesaDraw;
- struct gl_framebuffer *mesaRead;
- TRACE;
-
- if (cPriv) {
- struct dri_context *ctx = dri_context(cPriv);
- struct dri_drawable *draw;
- struct dri_drawable *read;
-
- if (!driDrawPriv || !driReadPriv)
- return GL_FALSE;
-
- draw = dri_drawable(driDrawPriv);
- read = dri_drawable(driReadPriv);
- mesaCtx = &ctx->Base;
- mesaDraw = &draw->Base;
- mesaRead = &read->Base;
-
- /* check for same context and buffer */
- if (mesaCtx == _mesa_get_current_context()
- && mesaCtx->DrawBuffer == mesaDraw
- && mesaCtx->ReadBuffer == mesaRead) {
- return GL_TRUE;
- }
-
- _glapi_check_multithread();
-
- swrast_check_and_update_window_size(mesaCtx, mesaDraw);
- if (mesaRead != mesaDraw)
- swrast_check_and_update_window_size(mesaCtx, mesaRead);
-
- _mesa_make_current( mesaCtx,
- mesaDraw,
- mesaRead );
- }
- else {
- /* unbind */
- _mesa_make_current( NULL, NULL, NULL );
- }
-
- return GL_TRUE;
-}
-
-static GLboolean
-dri_unbind_context(__DRIcontext * cPriv)
-{
- TRACE;
- (void) cPriv;
-
- /* Unset current context and dispath table */
- _mesa_make_current(NULL, NULL, NULL);
-
- return GL_TRUE;
-}
-
-
-const struct __DriverAPIRec driDriverAPI = {
- .InitScreen = dri_init_screen,
- .DestroyScreen = dri_destroy_screen,
- .CreateContext = dri_create_context,
- .DestroyContext = dri_destroy_context,
- .CreateBuffer = dri_create_buffer,
- .DestroyBuffer = dri_destroy_buffer,
- .SwapBuffers = dri_swap_buffers,
- .MakeCurrent = dri_make_current,
- .UnbindContext = dri_unbind_context,
-};
-
-/* This is the table of extensions that the loader will dlsym() for. */
-PUBLIC const __DRIextension *__driDriverExtensions[] = {
- &driCoreExtension.base,
- &driSWRastExtension.base,
- NULL
-};
+/*
+ * Copyright 2008, 2010 George Sapountzis <gsapountzis@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DRI software rasterizer
+ *
+ * This is the mesa swrast module packaged into a DRI driver structure.
+ *
+ * The front-buffer is allocated by the loader. The loader provides read/write
+ * callbacks for access to the front-buffer. The driver uses a scratch row for
+ * front-buffer rendering to avoid repeated calls to the loader.
+ *
+ * The back-buffer is allocated by the driver and is private.
+ */
+
+#ifdef _MSC_VER
+#define WIN32_LEAN_AND_MEAN 1
+#include <windows.h>
+#endif
+
+#include "main/context.h"
+#include "main/extensions.h"
+#include "main/formats.h"
+#include "main/framebuffer.h"
+#include "main/imports.h"
+#include "main/renderbuffer.h"
+#include "swrast/swrast.h"
+#include "swrast_setup/swrast_setup.h"
+#include "tnl/tnl.h"
+#include "tnl/t_context.h"
+#include "tnl/t_pipeline.h"
+#include "vbo/vbo.h"
+#include "drivers/common/driverfuncs.h"
+#include "drivers/common/meta.h"
+#include "utils.h"
+
+#include "main/teximage.h"
+#include "main/texformat.h"
+#include "main/texstate.h"
+
+#include "swrast_priv.h"
+
+
+/**
+ * Screen and config-related functions
+ */
+
+static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
+ GLint texture_format, __DRIdrawable *dPriv)
+{
+ struct dri_context *dri_ctx;
+ int x, y, w, h;
+ __DRIscreen *sPriv = dPriv->driScreenPriv;
+ struct gl_texture_unit *texUnit;
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ uint32_t internalFormat;
+ gl_format texFormat;
+
+ dri_ctx = pDRICtx->driverPrivate;
+
+ internalFormat = (texture_format == __DRI_TEXTURE_FORMAT_RGB ? 3 : 4);
+
+ texUnit = _mesa_get_current_tex_unit(&dri_ctx->Base);
+ texObj = _mesa_select_tex_object(&dri_ctx->Base, texUnit, target);
+ texImage = _mesa_get_tex_image(&dri_ctx->Base, texObj, target, 0);
+
+ _mesa_lock_texture(&dri_ctx->Base, texObj);
+
+ sPriv->swrast_loader->getDrawableInfo(dPriv, &x, &y, &w, &h, dPriv->loaderPrivate);
+
+ if (texture_format == __DRI_TEXTURE_FORMAT_RGB)
+ texFormat = MESA_FORMAT_XRGB8888;
+ else
+ texFormat = MESA_FORMAT_ARGB8888;
+
+ _mesa_init_teximage_fields(&dri_ctx->Base, target, texImage,
+ w, h, 1, 0, internalFormat, texFormat);
+
+ sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)texImage->Data,
+ dPriv->loaderPrivate);
+
+ _mesa_unlock_texture(&dri_ctx->Base, texObj);
+}
+
+static void swrastSetTexBuffer(__DRIcontext *pDRICtx, GLint target,
+ __DRIdrawable *dPriv)
+{
+ swrastSetTexBuffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv);
+}
+
+static const __DRItexBufferExtension swrastTexBufferExtension = {
+ { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
+ swrastSetTexBuffer,
+ swrastSetTexBuffer2,
+};
+
+static const __DRIextension *dri_screen_extensions[] = {
+ &swrastTexBufferExtension.base,
+ NULL
+};
+
+static __DRIconfig **
+swrastFillInModes(__DRIscreen *psp,
+ unsigned pixel_bits, unsigned depth_bits,
+ unsigned stencil_bits, GLboolean have_back_buffer)
+{
+ __DRIconfig **configs;
+ unsigned depth_buffer_factor;
+ unsigned back_buffer_factor;
+ GLenum fb_format;
+ GLenum fb_type;
+
+ /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
+ * support pageflipping at all.
+ */
+ static const GLenum back_buffer_modes[] = {
+ GLX_NONE, GLX_SWAP_UNDEFINED_OML
+ };
+
+ uint8_t depth_bits_array[4];
+ uint8_t stencil_bits_array[4];
+ uint8_t msaa_samples_array[1];
+
+ depth_bits_array[0] = 0;
+ depth_bits_array[1] = 0;
+ depth_bits_array[2] = depth_bits;
+ depth_bits_array[3] = depth_bits;
+
+ /* Just like with the accumulation buffer, always provide some modes
+ * with a stencil buffer.
+ */
+ stencil_bits_array[0] = 0;
+ stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
+ stencil_bits_array[2] = 0;
+ stencil_bits_array[3] = (stencil_bits == 0) ? 8 : stencil_bits;
+
+ msaa_samples_array[0] = 0;
+
+ depth_buffer_factor = 4;
+ back_buffer_factor = 2;
+
+ switch (pixel_bits) {
+ case 8:
+ fb_format = GL_RGB;
+ fb_type = GL_UNSIGNED_BYTE_2_3_3_REV;
+ break;
+ case 16:
+ fb_format = GL_RGB;
+ fb_type = GL_UNSIGNED_SHORT_5_6_5;
+ break;
+ case 24:
+ fb_format = GL_BGR;
+ fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+ break;
+ case 32:
+ fb_format = GL_BGRA;
+ fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+ break;
+ default:
+ fprintf(stderr, "[%s:%u] bad depth %d\n", __FUNCTION__, __LINE__,
+ pixel_bits);
+ return NULL;
+ }
+
+ configs = driCreateConfigs(fb_format, fb_type,
+ depth_bits_array, stencil_bits_array,
+ depth_buffer_factor, back_buffer_modes,
+ back_buffer_factor, msaa_samples_array, 1,
+ GL_TRUE);
+ if (configs == NULL) {
+ fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __FUNCTION__,
+ __LINE__);
+ return NULL;
+ }
+
+ return configs;
+}
+
+static const __DRIconfig **
+dri_init_screen(__DRIscreen * psp)
+{
+ __DRIconfig **configs8, **configs16, **configs24, **configs32;
+
+ TRACE;
+
+ psp->extensions = dri_screen_extensions;
+
+ configs8 = swrastFillInModes(psp, 8, 8, 0, 1);
+ configs16 = swrastFillInModes(psp, 16, 16, 0, 1);
+ configs24 = swrastFillInModes(psp, 24, 24, 8, 1);
+ configs32 = swrastFillInModes(psp, 32, 24, 8, 1);
+
+ configs16 = driConcatConfigs(configs8, configs16);
+ configs24 = driConcatConfigs(configs16, configs24);
+ configs32 = driConcatConfigs(configs24, configs32);
+
+ return (const __DRIconfig **)configs32;
+}
+
+static void
+dri_destroy_screen(__DRIscreen * sPriv)
+{
+ TRACE;
+}
+
+
+/**
+ * Framebuffer and renderbuffer-related functions.
+ */
+
+static GLuint
+choose_pixel_format(const struct gl_config *v)
+{
+ int depth = v->rgbBits;
+
+ if (depth == 32
+ && v->redMask == 0xff0000
+ && v->greenMask == 0x00ff00
+ && v->blueMask == 0x0000ff)
+ return PF_A8R8G8B8;
+ else if (depth == 24
+ && v->redMask == 0xff0000
+ && v->greenMask == 0x00ff00
+ && v->blueMask == 0x0000ff)
+ return PF_X8R8G8B8;
+ else if (depth == 16
+ && v->redMask == 0xf800
+ && v->greenMask == 0x07e0
+ && v->blueMask == 0x001f)
+ return PF_R5G6B5;
+ else if (depth == 8
+ && v->redMask == 0x07
+ && v->greenMask == 0x38
+ && v->blueMask == 0xc0)
+ return PF_R3G3B2;
+
+ _mesa_problem( NULL, "unexpected format in %s", __FUNCTION__ );
+ return 0;
+}
+
+static void
+swrast_delete_renderbuffer(struct gl_renderbuffer *rb)
+{
+ TRACE;
+
+ free(rb->Data);
+ free(rb);
+}
+
+/* see bytes_per_line in libGL */
+static INLINE int
+bytes_per_line(unsigned pitch_bits, unsigned mul)
+{
+ unsigned mask = mul - 1;
+
+ return ((pitch_bits + mask) & ~mask) / 8;
+}
+
+static GLboolean
+swrast_alloc_front_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLenum internalFormat, GLuint width, GLuint height)
+{
+ struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
+
+ TRACE;
+
+ rb->Data = NULL;
+ rb->Width = width;
+ rb->Height = height;
+
+ xrb->pitch = bytes_per_line(width * xrb->bpp, 32);
+
+ return GL_TRUE;
+}
+
+static GLboolean
+swrast_alloc_back_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLenum internalFormat, GLuint width, GLuint height)
+{
+ struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
+
+ TRACE;
+
+ free(rb->Data);
+
+ swrast_alloc_front_storage(ctx, rb, internalFormat, width, height);
+
+ rb->Data = malloc(height * xrb->pitch);
+
+ return GL_TRUE;
+}
+
+static struct swrast_renderbuffer *
+swrast_new_renderbuffer(const struct gl_config *visual, GLboolean front)
+{
+ struct swrast_renderbuffer *xrb = calloc(1, sizeof *xrb);
+ GLuint pixel_format;
+
+ TRACE;
+
+ if (!xrb)
+ return NULL;
+
+ _mesa_init_renderbuffer(&xrb->Base, 0);
+
+ pixel_format = choose_pixel_format(visual);
+
+ xrb->Base.Delete = swrast_delete_renderbuffer;
+ if (front) {
+ xrb->Base.AllocStorage = swrast_alloc_front_storage;
+ swrast_set_span_funcs_front(xrb, pixel_format);
+ }
+ else {
+ xrb->Base.AllocStorage = swrast_alloc_back_storage;
+ swrast_set_span_funcs_back(xrb, pixel_format);
+ }
+
+ switch (pixel_format) {
+ case PF_A8R8G8B8:
+ xrb->Base.Format = MESA_FORMAT_ARGB8888;
+ xrb->Base.InternalFormat = GL_RGBA;
+ xrb->Base._BaseFormat = GL_RGBA;
+ xrb->Base.DataType = GL_UNSIGNED_BYTE;
+ xrb->bpp = 32;
+ break;
+ case PF_X8R8G8B8:
+ xrb->Base.Format = MESA_FORMAT_ARGB8888; /* XXX */
+ xrb->Base.InternalFormat = GL_RGB;
+ xrb->Base._BaseFormat = GL_RGB;
+ xrb->Base.DataType = GL_UNSIGNED_BYTE;
+ xrb->bpp = 32;
+ break;
+ case PF_R5G6B5:
+ xrb->Base.Format = MESA_FORMAT_RGB565;
+ xrb->Base.InternalFormat = GL_RGB;
+ xrb->Base._BaseFormat = GL_RGB;
+ xrb->Base.DataType = GL_UNSIGNED_BYTE;
+ xrb->bpp = 16;
+ break;
+ case PF_R3G3B2:
+ xrb->Base.Format = MESA_FORMAT_RGB332;
+ xrb->Base.InternalFormat = GL_RGB;
+ xrb->Base._BaseFormat = GL_RGB;
+ xrb->Base.DataType = GL_UNSIGNED_BYTE;
+ xrb->bpp = 8;
+ break;
+ default:
+ return NULL;
+ }
+
+ return xrb;
+}
+
+static GLboolean
+dri_create_buffer(__DRIscreen * sPriv,
+ __DRIdrawable * dPriv,
+ const struct gl_config * visual, GLboolean isPixmap)
+{
+ struct dri_drawable *drawable = NULL;
+ struct gl_framebuffer *fb;
+ struct swrast_renderbuffer *frontrb, *backrb;
+
+ TRACE;
+
+ drawable = CALLOC_STRUCT(dri_drawable);
+ if (drawable == NULL)
+ goto drawable_fail;
+
+ dPriv->driverPrivate = drawable;
+ drawable->dPriv = dPriv;
+
+ drawable->row = malloc(MAX_WIDTH * 4);
+ if (drawable->row == NULL)
+ goto drawable_fail;
+
+ fb = &drawable->Base;
+
+ /* basic framebuffer setup */
+ _mesa_initialize_window_framebuffer(fb, visual);
+
+ /* add front renderbuffer */
+ frontrb = swrast_new_renderbuffer(visual, GL_TRUE);
+ _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontrb->Base);
+
+ /* add back renderbuffer */
+ if (visual->doubleBufferMode) {
+ backrb = swrast_new_renderbuffer(visual, GL_FALSE);
+ _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backrb->Base);
+ }
+
+ /* add software renderbuffers */
+ _mesa_add_soft_renderbuffers(fb,
+ GL_FALSE, /* color */
+ visual->haveDepthBuffer,
+ visual->haveStencilBuffer,
+ visual->haveAccumBuffer,
+ GL_FALSE, /* alpha */
+ GL_FALSE /* aux bufs */);
+
+ return GL_TRUE;
+
+drawable_fail:
+
+ if (drawable)
+ free(drawable->row);
+
+ FREE(drawable);
+
+ return GL_FALSE;
+}
+
+static void
+dri_destroy_buffer(__DRIdrawable * dPriv)
+{
+ TRACE;
+
+ if (dPriv) {
+ struct dri_drawable *drawable = dri_drawable(dPriv);
+ struct gl_framebuffer *fb;
+
+ free(drawable->row);
+
+ fb = &drawable->Base;
+
+ fb->DeletePending = GL_TRUE;
+ _mesa_reference_framebuffer(&fb, NULL);
+ }
+}
+
+static void
+dri_swap_buffers(__DRIdrawable * dPriv)
+{
+ __DRIscreen *sPriv = dPriv->driScreenPriv;
+
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct dri_drawable *drawable = dri_drawable(dPriv);
+ struct gl_framebuffer *fb;
+ struct swrast_renderbuffer *frontrb, *backrb;
+
+ TRACE;
+
+ fb = &drawable->Base;
+
+ frontrb =
+ swrast_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
+ backrb =
+ swrast_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer);
+
+ /* check for signle-buffered */
+ if (backrb == NULL)
+ return;
+
+ /* check if swapping currently bound buffer */
+ if (ctx && ctx->DrawBuffer == fb) {
+ /* flush pending rendering */
+ _mesa_notifySwapBuffers(ctx);
+ }
+
+ sPriv->swrast_loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
+ 0, 0,
+ frontrb->Base.Width,
+ frontrb->Base.Height,
+ backrb->Base.Data,
+ dPriv->loaderPrivate);
+}
+
+
+/**
+ * General device driver functions.
+ */
+
+static void
+get_window_size( struct gl_framebuffer *fb, GLsizei *w, GLsizei *h )
+{
+ __DRIdrawable *dPriv = swrast_drawable(fb)->dPriv;
+ __DRIscreen *sPriv = dPriv->driScreenPriv;
+ int x, y;
+
+ sPriv->swrast_loader->getDrawableInfo(dPriv,
+ &x, &y, w, h,
+ dPriv->loaderPrivate);
+}
+
+static void
+swrast_check_and_update_window_size( struct gl_context *ctx, struct gl_framebuffer *fb )
+{
+ GLsizei width, height;
+
+ get_window_size(fb, &width, &height);
+ if (fb->Width != width || fb->Height != height) {
+ _mesa_resize_framebuffer(ctx, fb, width, height);
+ }
+}
+
+static const GLubyte *
+get_string(struct gl_context *ctx, GLenum pname)
+{
+ (void) ctx;
+ switch (pname) {
+ case GL_VENDOR:
+ return (const GLubyte *) "Mesa Project";
+ case GL_RENDERER:
+ return (const GLubyte *) "Software Rasterizer";
+ default:
+ return NULL;
+ }
+}
+
+static void
+update_state( struct gl_context *ctx, GLuint new_state )
+{
+ /* not much to do here - pass it on */
+ _swrast_InvalidateState( ctx, new_state );
+ _swsetup_InvalidateState( ctx, new_state );
+ _vbo_InvalidateState( ctx, new_state );
+ _tnl_InvalidateState( ctx, new_state );
+}
+
+static void
+viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
+{
+ struct gl_framebuffer *draw = ctx->WinSysDrawBuffer;
+ struct gl_framebuffer *read = ctx->WinSysReadBuffer;
+
+ swrast_check_and_update_window_size(ctx, draw);
+ swrast_check_and_update_window_size(ctx, read);
+}
+
+static gl_format swrastChooseTextureFormat(struct gl_context * ctx,
+ GLint internalFormat,
+ GLenum format,
+ GLenum type)
+{
+ if (internalFormat == GL_RGB)
+ return MESA_FORMAT_XRGB8888;
+ return _mesa_choose_tex_format(ctx, internalFormat, format, type);
+}
+
+static void
+swrast_init_driver_functions(struct dd_function_table *driver)
+{
+ driver->GetString = get_string;
+ driver->UpdateState = update_state;
+ driver->GetBufferSize = NULL;
+ driver->Viewport = viewport;
+ driver->ChooseTextureFormat = swrastChooseTextureFormat;
+}
+
+static const char *es2_extensions[] = {
+ /* Used by mesa internally (cf all_mesa_extensions in ../common/utils.c) */
+ "GL_ARB_draw_buffers",
+ "GL_ARB_multisample",
+ "GL_ARB_texture_compression",
+ "GL_ARB_transpose_matrix",
+ "GL_ARB_vertex_buffer_object",
+ "GL_ARB_window_pos",
+ "GL_EXT_blend_func_separate",
+ "GL_EXT_compiled_vertex_array",
+ "GL_EXT_framebuffer_blit",
+ "GL_EXT_multi_draw_arrays",
+ "GL_EXT_polygon_offset",
+ "GL_EXT_texture_object",
+ "GL_EXT_vertex_array",
+ "GL_IBM_multimode_draw_arrays",
+ "GL_MESA_window_pos",
+ "GL_NV_vertex_program",
+
+ /* Required by GLES2 */
+ "GL_ARB_fragment_program",
+ "GL_ARB_fragment_shader",
+ "GL_ARB_multitexture",
+ "GL_ARB_shader_objects",
+ "GL_ARB_texture_cube_map",
+ "GL_ARB_texture_mirrored_repeat",
+ "GL_ARB_texture_non_power_of_two",
+ "GL_ARB_vertex_shader",
+ "GL_EXT_blend_color",
+ "GL_EXT_blend_equation_separate",
+ "GL_EXT_blend_minmax",
+ "GL_EXT_blend_subtract",
+ "GL_EXT_stencil_wrap",
+
+ /* Optional GLES2 */
+ "GL_ARB_framebuffer_object",
+ "GL_EXT_texture_filter_anisotropic",
+ "GL_ARB_depth_texture",
+ "GL_EXT_packed_depth_stencil",
+ "GL_EXT_framebuffer_object",
+ NULL,
+};
+
+static void
+InitExtensionsES2(struct gl_context *ctx)
+{
+ int i;
+
+ /* Can't use driInitExtensions() since it uses extensions from
+ * main/remap_helper.h when called the first time. */
+
+ for (i = 0; es2_extensions[i]; i++)
+ _mesa_enable_extension(ctx, es2_extensions[i]);
+}
+
+/**
+ * Context-related functions.
+ */
+
+static GLboolean
+dri_create_context(gl_api api,
+ const struct gl_config * visual,
+ __DRIcontext * cPriv, void *sharedContextPrivate)
+{
+ struct dri_context *ctx = NULL;
+ struct dri_context *share = (struct dri_context *)sharedContextPrivate;
+ struct gl_context *mesaCtx = NULL;
+ struct gl_context *sharedCtx = NULL;
+ struct dd_function_table functions;
+
+ TRACE;
+
+ ctx = CALLOC_STRUCT(dri_context);
+ if (ctx == NULL)
+ goto context_fail;
+
+ cPriv->driverPrivate = ctx;
+ ctx->cPriv = cPriv;
+
+ /* build table of device driver functions */
+ _mesa_init_driver_functions(&functions);
+ swrast_init_driver_functions(&functions);
+
+ if (share) {
+ sharedCtx = &share->Base;
+ }
+
+ mesaCtx = &ctx->Base;
+
+ /* basic context setup */
+ if (!_mesa_initialize_context(mesaCtx, api, visual, sharedCtx, &functions, (void *) cPriv)) {
+ goto context_fail;
+ }
+
+ /* do bounds checking to prevent segfaults and server crashes! */
+ mesaCtx->Const.CheckArrayBounds = GL_TRUE;
+
+ /* create module contexts */
+ _swrast_CreateContext( mesaCtx );
+ _vbo_CreateContext( mesaCtx );
+ _tnl_CreateContext( mesaCtx );
+ _swsetup_CreateContext( mesaCtx );
+ _swsetup_Wakeup( mesaCtx );
+
+ /* use default TCL pipeline */
+ {
+ TNLcontext *tnl = TNL_CONTEXT(mesaCtx);
+ tnl->Driver.RunPipeline = _tnl_run_pipeline;
+ }
+
+ _mesa_meta_init(mesaCtx);
+ _mesa_enable_sw_extensions(mesaCtx);
+
+ switch (api) {
+ case API_OPENGL:
+ _mesa_enable_1_3_extensions(mesaCtx);
+ _mesa_enable_1_4_extensions(mesaCtx);
+ _mesa_enable_1_5_extensions(mesaCtx);
+ _mesa_enable_2_0_extensions(mesaCtx);
+ _mesa_enable_2_1_extensions(mesaCtx);
+
+ driInitExtensions( mesaCtx, NULL, GL_FALSE );
+ break;
+ case API_OPENGLES:
+ _mesa_enable_1_3_extensions(mesaCtx);
+ _mesa_enable_1_4_extensions(mesaCtx);
+ _mesa_enable_1_5_extensions(mesaCtx);
+
+ break;
+ case API_OPENGLES2:
+ InitExtensionsES2( mesaCtx);
+ break;
+ }
+
+ return GL_TRUE;
+
+context_fail:
+
+ FREE(ctx);
+
+ return GL_FALSE;
+}
+
+static void
+dri_destroy_context(__DRIcontext * cPriv)
+{
+ TRACE;
+
+ if (cPriv) {
+ struct dri_context *ctx = dri_context(cPriv);
+ struct gl_context *mesaCtx;
+
+ mesaCtx = &ctx->Base;
+
+ _mesa_meta_free(mesaCtx);
+ _swsetup_DestroyContext( mesaCtx );
+ _swrast_DestroyContext( mesaCtx );
+ _tnl_DestroyContext( mesaCtx );
+ _vbo_DestroyContext( mesaCtx );
+ _mesa_destroy_context( mesaCtx );
+ }
+}
+
+static GLboolean
+dri_make_current(__DRIcontext * cPriv,
+ __DRIdrawable * driDrawPriv,
+ __DRIdrawable * driReadPriv)
+{
+ struct gl_context *mesaCtx;
+ struct gl_framebuffer *mesaDraw;
+ struct gl_framebuffer *mesaRead;
+ TRACE;
+
+ if (cPriv) {
+ struct dri_context *ctx = dri_context(cPriv);
+ struct dri_drawable *draw;
+ struct dri_drawable *read;
+
+ if (!driDrawPriv || !driReadPriv)
+ return GL_FALSE;
+
+ draw = dri_drawable(driDrawPriv);
+ read = dri_drawable(driReadPriv);
+ mesaCtx = &ctx->Base;
+ mesaDraw = &draw->Base;
+ mesaRead = &read->Base;
+
+ /* check for same context and buffer */
+ if (mesaCtx == _mesa_get_current_context()
+ && mesaCtx->DrawBuffer == mesaDraw
+ && mesaCtx->ReadBuffer == mesaRead) {
+ return GL_TRUE;
+ }
+
+ _glapi_check_multithread();
+
+ swrast_check_and_update_window_size(mesaCtx, mesaDraw);
+ if (mesaRead != mesaDraw)
+ swrast_check_and_update_window_size(mesaCtx, mesaRead);
+
+ _mesa_make_current( mesaCtx,
+ mesaDraw,
+ mesaRead );
+ }
+ else {
+ /* unbind */
+ _mesa_make_current( NULL, NULL, NULL );
+ }
+
+ return GL_TRUE;
+}
+
+static GLboolean
+dri_unbind_context(__DRIcontext * cPriv)
+{
+ TRACE;
+ (void) cPriv;
+
+ /* Unset current context and dispath table */
+ _mesa_make_current(NULL, NULL, NULL);
+
+ return GL_TRUE;
+}
+
+
+const struct __DriverAPIRec driDriverAPI = {
+ /*.InitScreen = */dri_init_screen,
+ /*.DestroyScreen = */dri_destroy_screen,
+ /*.CreateContext = */dri_create_context,
+ /*.DestroyContext = */dri_destroy_context,
+ /*.CreateBuffer = */dri_create_buffer,
+ /*.DestroyBuffer = */dri_destroy_buffer,
+ /*.SwapBuffers = */dri_swap_buffers,
+ /*.MakeCurrent = */dri_make_current,
+ /*.UnbindContext = */dri_unbind_context,
+};
+
+/* This is the table of extensions that the loader will dlsym() for. */
+PUBLIC const __DRIextension *__driDriverExtensions[] = {
+ &driCoreExtension.base,
+ &driSWRastExtension.base,
+ NULL
+};
diff --git a/mesalib/src/mesa/drivers/dri/swrast/swrast_priv.h b/mesalib/src/mesa/drivers/dri/swrast/swrast_priv.h
index 4c3c9830f..e61965147 100644
--- a/mesalib/src/mesa/drivers/dri/swrast/swrast_priv.h
+++ b/mesalib/src/mesa/drivers/dri/swrast/swrast_priv.h
@@ -32,6 +32,13 @@
#include "main/mtypes.h"
#include "drisw_util.h"
+#ifdef _MSC_VER
+#ifdef PUBLIC
+#undef PUBLIC
+#endif
+#define PUBLIC __declspec(dllexport)
+#endif
+
/**
* Debugging
diff --git a/mesalib/src/mesa/drivers/windows/gdi/wmesa.c b/mesalib/src/mesa/drivers/windows/gdi/wmesa.c
index 4a8b1b283..1a13e9f5c 100644
--- a/mesalib/src/mesa/drivers/windows/gdi/wmesa.c
+++ b/mesalib/src/mesa/drivers/windows/gdi/wmesa.c
@@ -1,1662 +1,1662 @@
-/*
- * Windows (Win32/Win64) device driver for Mesa
- *
- */
-
-#include "wmesadef.h"
-#include "colors.h"
-#include <GL/wmesa.h>
-#include <winuser.h>
-#include "context.h"
-#include "extensions.h"
-#include "framebuffer.h"
-#include "renderbuffer.h"
-#include "drivers/common/driverfuncs.h"
-#include "drivers/common/meta.h"
-#include "vbo/vbo.h"
-#include "swrast/swrast.h"
-#include "swrast_setup/swrast_setup.h"
-#include "tnl/tnl.h"
-#include "tnl/t_context.h"
-#include "tnl/t_pipeline.h"
-
-
-/* linked list of our Framebuffers (windows) */
-static WMesaFramebuffer FirstFramebuffer = NULL;
-
-
-/**
- * Create a new WMesaFramebuffer object which will correspond to the
- * given HDC (Window handle).
- */
-WMesaFramebuffer
-wmesa_new_framebuffer(HDC hdc, struct gl_config *visual)
-{
- WMesaFramebuffer pwfb
- = (WMesaFramebuffer) malloc(sizeof(struct wmesa_framebuffer));
- if (pwfb) {
- _mesa_initialize_window_framebuffer(&pwfb->Base, visual);
- pwfb->hDC = hdc;
- /* insert at head of list */
- pwfb->next = FirstFramebuffer;
- FirstFramebuffer = pwfb;
- }
- return pwfb;
-}
-
-/**
- * Given an hdc, free the corresponding WMesaFramebuffer
- */
-void
-wmesa_free_framebuffer(HDC hdc)
-{
- WMesaFramebuffer pwfb, prev;
- for (pwfb = FirstFramebuffer; pwfb; pwfb = pwfb->next) {
- if (pwfb->hDC == hdc)
- break;
- prev = pwfb;
- }
- if (pwfb) {
- struct gl_framebuffer *fb;
- if (pwfb == FirstFramebuffer)
- FirstFramebuffer = pwfb->next;
- else
- prev->next = pwfb->next;
- fb = &pwfb->Base;
- _mesa_reference_framebuffer(&fb, NULL);
- }
-}
-
-/**
- * Given an hdc, return the corresponding WMesaFramebuffer
- */
-WMesaFramebuffer
-wmesa_lookup_framebuffer(HDC hdc)
-{
- WMesaFramebuffer pwfb;
- for (pwfb = FirstFramebuffer; pwfb; pwfb = pwfb->next) {
- if (pwfb->hDC == hdc)
- return pwfb;
- }
- return NULL;
-}
-
-
-/**
- * Given a struct gl_framebuffer, return the corresponding WMesaFramebuffer.
- */
-static WMesaFramebuffer wmesa_framebuffer(struct gl_framebuffer *fb)
-{
- return (WMesaFramebuffer) fb;
-}
-
-
-/**
- * Given a struct gl_context, return the corresponding WMesaContext.
- */
-static WMesaContext wmesa_context(const struct gl_context *ctx)
-{
- return (WMesaContext) ctx;
-}
-
-
-/*
- * Every driver should implement a GetString function in order to
- * return a meaningful GL_RENDERER string.
- */
-static const GLubyte *wmesa_get_string(struct gl_context *ctx, GLenum name)
-{
- return (name == GL_RENDERER) ?
- (GLubyte *) "Mesa Windows GDI Driver" : NULL;
-}
-
-
-/*
- * Determine the pixel format based on the pixel size.
- */
-static void wmSetPixelFormat(WMesaFramebuffer pwfb, HDC hDC)
-{
- pwfb->cColorBits = GetDeviceCaps(hDC, BITSPIXEL);
-
- /* Only 16 and 32 bit targets are supported now */
- assert(pwfb->cColorBits == 0 ||
- pwfb->cColorBits == 16 ||
- pwfb->cColorBits == 24 ||
- pwfb->cColorBits == 32);
-
- switch(pwfb->cColorBits){
- case 8:
- pwfb->pixelformat = PF_INDEX8;
- break;
- case 16:
- pwfb->pixelformat = PF_5R6G5B;
- break;
- case 24:
- case 32:
- pwfb->pixelformat = PF_8R8G8B;
- break;
- default:
- pwfb->pixelformat = PF_BADFORMAT;
- }
-}
-
-
-/**
- * Create DIB for back buffer.
- * We write into this memory with the span routines and then blit it
- * to the window on a buffer swap.
- */
-BOOL wmCreateBackingStore(WMesaFramebuffer pwfb, long lxSize, long lySize)
-{
- HDC hdc = pwfb->hDC;
- LPBITMAPINFO pbmi = &(pwfb->bmi);
- HDC hic;
-
- pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- pbmi->bmiHeader.biWidth = lxSize;
- pbmi->bmiHeader.biHeight= -lySize;
- pbmi->bmiHeader.biPlanes = 1;
- pbmi->bmiHeader.biBitCount = GetDeviceCaps(pwfb->hDC, BITSPIXEL);
- pbmi->bmiHeader.biCompression = BI_RGB;
- pbmi->bmiHeader.biSizeImage = 0;
- pbmi->bmiHeader.biXPelsPerMeter = 0;
- pbmi->bmiHeader.biYPelsPerMeter = 0;
- pbmi->bmiHeader.biClrUsed = 0;
- pbmi->bmiHeader.biClrImportant = 0;
-
- pwfb->cColorBits = pbmi->bmiHeader.biBitCount;
- pwfb->ScanWidth = (lxSize * (pwfb->cColorBits / 8) + 3) & ~3;
-
- hic = CreateIC("display", NULL, NULL, NULL);
- pwfb->dib_hDC = CreateCompatibleDC(hic);
-
- pwfb->hbmDIB = CreateDIBSection(hic,
- &pwfb->bmi,
- DIB_RGB_COLORS,
- (void **)&(pwfb->pbPixels),
- 0,
- 0);
- pwfb->hOldBitmap = SelectObject(pwfb->dib_hDC, pwfb->hbmDIB);
-
- DeleteDC(hic);
-
- wmSetPixelFormat(pwfb, pwfb->hDC);
- return TRUE;
-}
-
-
-static wmDeleteBackingStore(WMesaFramebuffer pwfb)
-{
- if (pwfb->hbmDIB) {
- SelectObject(pwfb->dib_hDC, pwfb->hOldBitmap);
- DeleteDC(pwfb->dib_hDC);
- DeleteObject(pwfb->hbmDIB);
- }
-}
-
-
-/**
- * Find the width and height of the window named by hdc.
- */
-static void
-get_window_size(HDC hdc, GLuint *width, GLuint *height)
-{
- if (WindowFromDC(hdc)) {
- RECT rect;
- GetClientRect(WindowFromDC(hdc), &rect);
- *width = rect.right - rect.left;
- *height = rect.bottom - rect.top;
- }
- else { /* Memory context */
- /* From contributed code - use the size of the desktop
- * for the size of a memory context (?) */
- *width = GetDeviceCaps(hdc, HORZRES);
- *height = GetDeviceCaps(hdc, VERTRES);
- }
-}
-
-
-static void
-wmesa_get_buffer_size(struct gl_framebuffer *buffer, GLuint *width, GLuint *height)
-{
- WMesaFramebuffer pwfb = wmesa_framebuffer(buffer);
- get_window_size(pwfb->hDC, width, height);
-}
-
-
-static void wmesa_flush(struct gl_context *ctx)
-{
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->WinSysDrawBuffer);
-
- if (ctx->Visual.doubleBufferMode == 1) {
- BitBlt(pwfb->hDC, 0, 0, pwfb->Base.Width, pwfb->Base.Height,
- pwfb->dib_hDC, 0, 0, SRCCOPY);
- }
- else {
- /* Do nothing for single buffer */
- }
-}
-
-
-/**********************************************************************/
-/***** CLEAR Functions *****/
-/**********************************************************************/
-
-/* If we do not implement these, Mesa clears the buffers via the pixel
- * span writing interface, which is very slow for a clear operation.
- */
-
-/*
- * Set the color used to clear the color buffer.
- */
-static void clear_color(struct gl_context *ctx, const GLfloat color[4])
-{
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- GLubyte col[3];
- UINT bytesPerPixel = pwfb->cColorBits / 8;
-
- CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
- CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
- CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
- pwc->clearColorRef = RGB(col[0], col[1], col[2]);
- DeleteObject(pwc->clearPen);
- DeleteObject(pwc->clearBrush);
- pwc->clearPen = CreatePen(PS_SOLID, 1, pwc->clearColorRef);
- pwc->clearBrush = CreateSolidBrush(pwc->clearColorRef);
-}
-
-
-/*
- * Clear the specified region of the color buffer using the clear color
- * or index as specified by one of the two functions above.
- *
- * This procedure clears either the front and/or the back COLOR buffers.
- * Only the "left" buffer is cleared since we are not stereo.
- * Clearing of the other non-color buffers is left to the swrast.
- */
-
-static void clear(struct gl_context *ctx, GLbitfield mask)
-{
-#define FLIP(Y) (ctx->DrawBuffer->Height - (Y) - 1)
- const GLint x = ctx->DrawBuffer->_Xmin;
- const GLint y = ctx->DrawBuffer->_Ymin;
- const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
- const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
-
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- int done = 0;
-
- /* Let swrast do all the work if the masks are not set to
- * clear all channels. */
- if (!ctx->Color.ColorMask[0][0] ||
- !ctx->Color.ColorMask[0][1] ||
- !ctx->Color.ColorMask[0][2] ||
- !ctx->Color.ColorMask[0][3]) {
- _swrast_Clear(ctx, mask);
- return;
- }
-
- /* Back buffer */
- if (mask & BUFFER_BIT_BACK_LEFT) {
-
- int i, rowSize;
- UINT bytesPerPixel = pwfb->cColorBits / 8;
- LPBYTE lpb, clearRow;
- LPWORD lpw;
- BYTE bColor;
- WORD wColor;
- BYTE r, g, b;
- DWORD dwColor;
- LPDWORD lpdw;
-
- /* Try for a fast clear - clearing entire buffer with a single
- * byte value. */
- if (width == ctx->DrawBuffer->Width &&
- height == ctx->DrawBuffer->Height) { /* entire buffer */
- /* Now check for an easy clear value */
- switch (bytesPerPixel) {
- case 1:
- bColor = BGR8(GetRValue(pwc->clearColorRef),
- GetGValue(pwc->clearColorRef),
- GetBValue(pwc->clearColorRef));
- memset(pwfb->pbPixels, bColor,
- pwfb->ScanWidth * height);
- done = 1;
- break;
- case 2:
- wColor = BGR16(GetRValue(pwc->clearColorRef),
- GetGValue(pwc->clearColorRef),
- GetBValue(pwc->clearColorRef));
- if (((wColor >> 8) & 0xff) == (wColor & 0xff)) {
- memset(pwfb->pbPixels, wColor & 0xff,
- pwfb->ScanWidth * height);
- done = 1;
- }
- break;
- case 3:
- /* fall through */
- case 4:
- if (GetRValue(pwc->clearColorRef) ==
- GetGValue(pwc->clearColorRef) &&
- GetRValue(pwc->clearColorRef) ==
- GetBValue(pwc->clearColorRef)) {
- memset(pwfb->pbPixels,
- GetRValue(pwc->clearColorRef),
- pwfb->ScanWidth * height);
- done = 1;
- }
- break;
- default:
- break;
- }
- } /* all */
-
- if (!done) {
- /* Need to clear a row at a time. Begin by setting the first
- * row in the area to be cleared to the clear color. */
-
- clearRow = pwfb->pbPixels +
- pwfb->ScanWidth * FLIP(y) +
- bytesPerPixel * x;
- switch (bytesPerPixel) {
- case 1:
- lpb = clearRow;
- bColor = BGR8(GetRValue(pwc->clearColorRef),
- GetGValue(pwc->clearColorRef),
- GetBValue(pwc->clearColorRef));
- memset(lpb, bColor, width);
- break;
- case 2:
- lpw = (LPWORD)clearRow;
- wColor = BGR16(GetRValue(pwc->clearColorRef),
- GetGValue(pwc->clearColorRef),
- GetBValue(pwc->clearColorRef));
- for (i=0; i<width; i++)
- *lpw++ = wColor;
- break;
- case 3:
- lpb = clearRow;
- r = GetRValue(pwc->clearColorRef);
- g = GetGValue(pwc->clearColorRef);
- b = GetBValue(pwc->clearColorRef);
- for (i=0; i<width; i++) {
- *lpb++ = b;
- *lpb++ = g;
- *lpb++ = r;
- }
- break;
- case 4:
- lpdw = (LPDWORD)clearRow;
- dwColor = BGR32(GetRValue(pwc->clearColorRef),
- GetGValue(pwc->clearColorRef),
- GetBValue(pwc->clearColorRef));
- for (i=0; i<width; i++)
- *lpdw++ = dwColor;
- break;
- default:
- break;
- } /* switch */
-
- /* copy cleared row to other rows in buffer */
- lpb = clearRow - pwfb->ScanWidth;
- rowSize = width * bytesPerPixel;
- for (i=1; i<height; i++) {
- memcpy(lpb, clearRow, rowSize);
- lpb -= pwfb->ScanWidth;
- }
- } /* not done */
- mask &= ~BUFFER_BIT_BACK_LEFT;
- } /* back buffer */
-
- /* front buffer */
- if (mask & BUFFER_BIT_FRONT_LEFT) {
- HDC DC = pwc->hDC;
- HPEN Old_Pen = SelectObject(DC, pwc->clearPen);
- HBRUSH Old_Brush = SelectObject(DC, pwc->clearBrush);
- Rectangle(DC,
- x,
- FLIP(y) + 1,
- x + width + 1,
- FLIP(y) - height + 1);
- SelectObject(DC, Old_Pen);
- SelectObject(DC, Old_Brush);
- mask &= ~BUFFER_BIT_FRONT_LEFT;
- } /* front buffer */
-
- /* Call swrast if there is anything left to clear (like DEPTH) */
- if (mask)
- _swrast_Clear(ctx, mask);
-
-#undef FLIP
-}
-
-
-/**********************************************************************/
-/***** PIXEL Functions *****/
-/**********************************************************************/
-
-#define FLIP(Y) (rb->Height - (Y) - 1)
-
-
-/**
- ** Front Buffer reading/writing
- ** These are slow, but work with all non-indexed visual types.
- **/
-
-/* Write a horizontal span of RGBA color pixels with a boolean mask. */
-static void write_rgba_span_front(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLubyte rgba[][4],
- const GLubyte mask[] )
-{
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_lookup_framebuffer(pwc->hDC);
- CONST BITMAPINFO bmi=
- {
- {
- sizeof(BITMAPINFOHEADER),
- n, 1, 1, 32, BI_RGB, 0, 1, 1, 0, 0
- }
- };
- HBITMAP bmp=0;
- HDC mdc=0;
- typedef union
- {
- unsigned i;
- struct {
- unsigned b:8, g:8, r:8, a:8;
- };
- } BGRA;
- BGRA *bgra, c;
- GLuint i;
-
- if (n < 16) { // the value 16 is just guessed
- y=FLIP(y);
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i])
- SetPixel(pwc->hDC, x+i, y,
- RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
- }
- else {
- for (i=0; i<n; i++)
- SetPixel(pwc->hDC, x+i, y,
- RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
- }
- }
- else {
- if (!pwfb) {
- _mesa_problem(NULL, "wmesa: write_rgba_span_front on unknown hdc");
- return;
- }
- bgra=malloc(n*sizeof(BGRA));
- if (!bgra) {
- _mesa_problem(NULL, "wmesa: write_rgba_span_front: out of memory");
- return;
- }
- c.a=0;
- if (mask) {
- for (i=0; i<n; i++) {
- if (mask[i]) {
- c.r=rgba[i][RCOMP];
- c.g=rgba[i][GCOMP];
- c.b=rgba[i][BCOMP];
- c.a=rgba[i][ACOMP];
- bgra[i]=c;
- }
- else
- bgra[i].i=0;
- }
- }
- else {
- for (i=0; i<n; i++) {
- c.r=rgba[i][RCOMP];
- c.g=rgba[i][GCOMP];
- c.b=rgba[i][BCOMP];
- c.a=rgba[i][ACOMP];
- bgra[i]=c;
- }
- }
- bmp=CreateBitmap(n, 1, 1, 32, bgra);
- mdc=CreateCompatibleDC(pwfb->hDC);
- SelectObject(mdc, bmp);
- y=FLIP(y);
- BitBlt(pwfb->hDC, x, y, n, 1, mdc, 0, 0, SRCCOPY);
- SelectObject(mdc, 0);
- DeleteObject(bmp);
- DeleteDC(mdc);
- free(bgra);
- }
-}
-
-/* Write a horizontal span of RGB color pixels with a boolean mask. */
-static void write_rgb_span_front(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLubyte rgb[][3],
- const GLubyte mask[] )
-{
- WMesaContext pwc = wmesa_context(ctx);
- GLuint i;
-
- (void) ctx;
- y=FLIP(y);
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i])
- SetPixel(pwc->hDC, x+i, y, RGB(rgb[i][RCOMP], rgb[i][GCOMP],
- rgb[i][BCOMP]));
- }
- else {
- for (i=0; i<n; i++)
- SetPixel(pwc->hDC, x+i, y, RGB(rgb[i][RCOMP], rgb[i][GCOMP],
- rgb[i][BCOMP]));
- }
-
-}
-
-/*
- * Write a horizontal span of pixels with a boolean mask. The current color
- * is used for all pixels.
- */
-static void write_mono_rgba_span_front(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLchan color[4],
- const GLubyte mask[])
-{
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- COLORREF colorref;
-
- (void) ctx;
- colorref = RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
- y=FLIP(y);
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i])
- SetPixel(pwc->hDC, x+i, y, colorref);
- }
- else
- for (i=0; i<n; i++)
- SetPixel(pwc->hDC, x+i, y, colorref);
-
-}
-
-/* Write an array of RGBA pixels with a boolean mask. */
-static void write_rgba_pixels_front(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n,
- const GLint x[], const GLint y[],
- const GLubyte rgba[][4],
- const GLubyte mask[] )
-{
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- (void) ctx;
- for (i=0; i<n; i++)
- if (mask[i])
- SetPixel(pwc->hDC, x[i], FLIP(y[i]),
- RGB(rgba[i][RCOMP], rgba[i][GCOMP],
- rgba[i][BCOMP]));
-}
-
-
-
-/*
- * Write an array of pixels with a boolean mask. The current color
- * is used for all pixels.
- */
-static void write_mono_rgba_pixels_front(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n,
- const GLint x[], const GLint y[],
- const GLchan color[4],
- const GLubyte mask[] )
-{
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- COLORREF colorref;
- (void) ctx;
- colorref = RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
- for (i=0; i<n; i++)
- if (mask[i])
- SetPixel(pwc->hDC, x[i], FLIP(y[i]), colorref);
-}
-
-/* Read a horizontal span of color pixels. */
-static void read_rgba_span_front(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- GLubyte rgba[][4] )
-{
- WMesaContext pwc = wmesa_context(ctx);
- GLuint i;
- COLORREF Color;
- y = FLIP(y);
- for (i=0; i<n; i++) {
- Color = GetPixel(pwc->hDC, x+i, y);
- rgba[i][RCOMP] = GetRValue(Color);
- rgba[i][GCOMP] = GetGValue(Color);
- rgba[i][BCOMP] = GetBValue(Color);
- rgba[i][ACOMP] = 255;
- }
-}
-
-
-/* Read an array of color pixels. */
-static void read_rgba_pixels_front(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, const GLint x[], const GLint y[],
- GLubyte rgba[][4])
-{
- WMesaContext pwc = wmesa_context(ctx);
- GLuint i;
- COLORREF Color;
- for (i=0; i<n; i++) {
- GLint y2 = FLIP(y[i]);
- Color = GetPixel(pwc->hDC, x[i], y2);
- rgba[i][RCOMP] = GetRValue(Color);
- rgba[i][GCOMP] = GetGValue(Color);
- rgba[i][BCOMP] = GetBValue(Color);
- rgba[i][ACOMP] = 255;
- }
-}
-
-/*********************************************************************/
-
-/* DOUBLE BUFFER 32-bit */
-
-#define WMSETPIXEL32(pwc, y, x, r, g, b) { \
-LPDWORD lpdw = ((LPDWORD)((pwc)->pbPixels + (pwc)->ScanWidth * (y)) + (x)); \
-*lpdw = BGR32((r),(g),(b)); }
-
-
-
-/* Write a horizontal span of RGBA color pixels with a boolean mask. */
-static void write_rgba_span_32(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLubyte rgba[][4],
- const GLubyte mask[] )
-{
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- GLuint i;
- LPDWORD lpdw;
-
- (void) ctx;
-
- y=FLIP(y);
- lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i])
- lpdw[i] = BGR32(rgba[i][RCOMP], rgba[i][GCOMP],
- rgba[i][BCOMP]);
- }
- else {
- for (i=0; i<n; i++)
- *lpdw++ = BGR32(rgba[i][RCOMP], rgba[i][GCOMP],
- rgba[i][BCOMP]);
- }
-}
-
-
-/* Write a horizontal span of RGB color pixels with a boolean mask. */
-static void write_rgb_span_32(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLubyte rgb[][3],
- const GLubyte mask[] )
-{
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- GLuint i;
- LPDWORD lpdw;
-
- (void) ctx;
-
- y=FLIP(y);
- lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i])
- lpdw[i] = BGR32(rgb[i][RCOMP], rgb[i][GCOMP],
- rgb[i][BCOMP]);
- }
- else {
- for (i=0; i<n; i++)
- *lpdw++ = BGR32(rgb[i][RCOMP], rgb[i][GCOMP],
- rgb[i][BCOMP]);
- }
-}
-
-/*
- * Write a horizontal span of pixels with a boolean mask. The current color
- * is used for all pixels.
- */
-static void write_mono_rgba_span_32(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLchan color[4],
- const GLubyte mask[])
-{
- LPDWORD lpdw;
- DWORD pixel;
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
- y=FLIP(y);
- pixel = BGR32(color[RCOMP], color[GCOMP], color[BCOMP]);
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i])
- lpdw[i] = pixel;
- }
- else
- for (i=0; i<n; i++)
- *lpdw++ = pixel;
-
-}
-
-/* Write an array of RGBA pixels with a boolean mask. */
-static void write_rgba_pixels_32(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, const GLint x[], const GLint y[],
- const GLubyte rgba[][4],
- const GLubyte mask[])
-{
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- for (i=0; i<n; i++)
- if (mask[i])
- WMSETPIXEL32(pwfb, FLIP(y[i]), x[i],
- rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-}
-
-/*
- * Write an array of pixels with a boolean mask. The current color
- * is used for all pixels.
- */
-static void write_mono_rgba_pixels_32(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n,
- const GLint x[], const GLint y[],
- const GLchan color[4],
- const GLubyte mask[])
-{
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- for (i=0; i<n; i++)
- if (mask[i])
- WMSETPIXEL32(pwfb, FLIP(y[i]),x[i],color[RCOMP],
- color[GCOMP], color[BCOMP]);
-}
-
-/* Read a horizontal span of color pixels. */
-static void read_rgba_span_32(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- GLubyte rgba[][4] )
-{
- GLuint i;
- DWORD pixel;
- LPDWORD lpdw;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
-
- y = FLIP(y);
- lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
- for (i=0; i<n; i++) {
- pixel = lpdw[i];
- rgba[i][RCOMP] = (GLubyte)((pixel & 0x00ff0000) >> 16);
- rgba[i][GCOMP] = (GLubyte)((pixel & 0x0000ff00) >> 8);
- rgba[i][BCOMP] = (GLubyte)(pixel & 0x000000ff);
- rgba[i][ACOMP] = 255;
- }
-}
-
-
-/* Read an array of color pixels. */
-static void read_rgba_pixels_32(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, const GLint x[], const GLint y[],
- GLubyte rgba[][4])
-{
- GLuint i;
- DWORD pixel;
- LPDWORD lpdw;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
-
- for (i=0; i<n; i++) {
- GLint y2 = FLIP(y[i]);
- lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y2)) + x[i];
- pixel = *lpdw;
- rgba[i][RCOMP] = (GLubyte)((pixel & 0x00ff0000) >> 16);
- rgba[i][GCOMP] = (GLubyte)((pixel & 0x0000ff00) >> 8);
- rgba[i][BCOMP] = (GLubyte)(pixel & 0x000000ff);
- rgba[i][ACOMP] = 255;
- }
-}
-
-
-/*********************************************************************/
-
-/* DOUBLE BUFFER 24-bit */
-
-#define WMSETPIXEL24(pwc, y, x, r, g, b) { \
-LPBYTE lpb = ((LPBYTE)((pwc)->pbPixels + (pwc)->ScanWidth * (y)) + (3 * x)); \
-lpb[0] = (b); \
-lpb[1] = (g); \
-lpb[2] = (r); }
-
-/* Write a horizontal span of RGBA color pixels with a boolean mask. */
-static void write_rgba_span_24(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLubyte rgba[][4],
- const GLubyte mask[] )
-{
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- GLuint i;
- LPBYTE lpb;
-
- (void) ctx;
-
- y=FLIP(y);
- lpb = ((LPBYTE)(pwfb->pbPixels + pwfb->ScanWidth * y)) + (3 * x);
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i]) {
- lpb[3*i] = rgba[i][BCOMP];
- lpb[3*i+1] = rgba[i][GCOMP];
- lpb[3*i+2] = rgba[i][RCOMP];
- }
- }
- else {
- for (i=0; i<n; i++) {
- *lpb++ = rgba[i][BCOMP];
- *lpb++ = rgba[i][GCOMP];
- *lpb++ = rgba[i][RCOMP];
- }
- }
-}
-
-
-/* Write a horizontal span of RGB color pixels with a boolean mask. */
-static void write_rgb_span_24(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLubyte rgb[][3],
- const GLubyte mask[] )
-{
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- GLuint i;
- LPBYTE lpb;
-
- (void) ctx;
-
- y=FLIP(y);
- lpb = ((LPBYTE)(pwfb->pbPixels + pwfb->ScanWidth * y)) + (3 * x);
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i]) {
- lpb[3*i] = rgb[i][BCOMP];
- lpb[3*i+1] = rgb[i][GCOMP];
- lpb[3*i+2] = rgb[i][RCOMP];
- }
- }
- else {
- for (i=0; i<n; i++) {
- *lpb++ = rgb[i][BCOMP];
- *lpb++ = rgb[i][GCOMP];
- *lpb++ = rgb[i][RCOMP];
- }
- }
-}
-
-/*
- * Write a horizontal span of pixels with a boolean mask. The current color
- * is used for all pixels.
- */
-static void write_mono_rgba_span_24(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLchan color[4],
- const GLubyte mask[])
-{
- LPBYTE lpb;
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- lpb = ((LPBYTE)(pwfb->pbPixels + pwfb->ScanWidth * y)) + (3 * x);
- y=FLIP(y);
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i]) {
- lpb[3*i] = color[BCOMP];
- lpb[3*i+1] = color[GCOMP];
- lpb[3*i+2] = color[RCOMP];
- }
- }
- else
- for (i=0; i<n; i++) {
- *lpb++ = color[BCOMP];
- *lpb++ = color[GCOMP];
- *lpb++ = color[RCOMP];
- }
-}
-
-/* Write an array of RGBA pixels with a boolean mask. */
-static void write_rgba_pixels_24(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, const GLint x[], const GLint y[],
- const GLubyte rgba[][4],
- const GLubyte mask[])
-{
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- for (i=0; i<n; i++)
- if (mask[i])
- WMSETPIXEL24(pwfb, FLIP(y[i]), x[i],
- rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-}
-
-/*
- * Write an array of pixels with a boolean mask. The current color
- * is used for all pixels.
- */
-static void write_mono_rgba_pixels_24(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n,
- const GLint x[], const GLint y[],
- const GLchan color[4],
- const GLubyte mask[])
-{
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- for (i=0; i<n; i++)
- if (mask[i])
- WMSETPIXEL24(pwfb, FLIP(y[i]),x[i],color[RCOMP],
- color[GCOMP], color[BCOMP]);
-}
-
-/* Read a horizontal span of color pixels. */
-static void read_rgba_span_24(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- GLubyte rgba[][4] )
-{
- GLuint i;
- LPBYTE lpb;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
-
- y = FLIP(y);
- lpb = ((LPBYTE)(pwfb->pbPixels + pwfb->ScanWidth * y)) + (3 * x);
- for (i=0; i<n; i++) {
- rgba[i][RCOMP] = lpb[3*i+2];
- rgba[i][GCOMP] = lpb[3*i+1];
- rgba[i][BCOMP] = lpb[3*i];
- rgba[i][ACOMP] = 255;
- }
-}
-
-
-/* Read an array of color pixels. */
-static void read_rgba_pixels_24(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, const GLint x[], const GLint y[],
- GLubyte rgba[][4])
-{
- GLuint i;
- LPBYTE lpb;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
-
- for (i=0; i<n; i++) {
- GLint y2 = FLIP(y[i]);
- lpb = ((LPBYTE)(pwfb->pbPixels + pwfb->ScanWidth * y2)) + (3 * x[i]);
- rgba[i][RCOMP] = lpb[3*i+2];
- rgba[i][GCOMP] = lpb[3*i+1];
- rgba[i][BCOMP] = lpb[3*i];
- rgba[i][ACOMP] = 255;
- }
-}
-
-
-/*********************************************************************/
-
-/* DOUBLE BUFFER 16-bit */
-
-#define WMSETPIXEL16(pwc, y, x, r, g, b) { \
-LPWORD lpw = ((LPWORD)((pwc)->pbPixels + (pwc)->ScanWidth * (y)) + (x)); \
-*lpw = BGR16((r),(g),(b)); }
-
-
-
-/* Write a horizontal span of RGBA color pixels with a boolean mask. */
-static void write_rgba_span_16(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLubyte rgba[][4],
- const GLubyte mask[] )
-{
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- GLuint i;
- LPWORD lpw;
-
- (void) ctx;
-
- y=FLIP(y);
- lpw = ((LPWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i])
- lpw[i] = BGR16(rgba[i][RCOMP], rgba[i][GCOMP],
- rgba[i][BCOMP]);
- }
- else {
- for (i=0; i<n; i++)
- *lpw++ = BGR16(rgba[i][RCOMP], rgba[i][GCOMP],
- rgba[i][BCOMP]);
- }
-}
-
-
-/* Write a horizontal span of RGB color pixels with a boolean mask. */
-static void write_rgb_span_16(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLubyte rgb[][3],
- const GLubyte mask[] )
-{
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- GLuint i;
- LPWORD lpw;
-
- (void) ctx;
-
- y=FLIP(y);
- lpw = ((LPWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i])
- lpw[i] = BGR16(rgb[i][RCOMP], rgb[i][GCOMP],
- rgb[i][BCOMP]);
- }
- else {
- for (i=0; i<n; i++)
- *lpw++ = BGR16(rgb[i][RCOMP], rgb[i][GCOMP],
- rgb[i][BCOMP]);
- }
-}
-
-/*
- * Write a horizontal span of pixels with a boolean mask. The current color
- * is used for all pixels.
- */
-static void write_mono_rgba_span_16(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- const GLchan color[4],
- const GLubyte mask[])
-{
- LPWORD lpw;
- WORD pixel;
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- (void) ctx;
- lpw = ((LPWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
- y=FLIP(y);
- pixel = BGR16(color[RCOMP], color[GCOMP], color[BCOMP]);
- if (mask) {
- for (i=0; i<n; i++)
- if (mask[i])
- lpw[i] = pixel;
- }
- else
- for (i=0; i<n; i++)
- *lpw++ = pixel;
-
-}
-
-/* Write an array of RGBA pixels with a boolean mask. */
-static void write_rgba_pixels_16(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, const GLint x[], const GLint y[],
- const GLubyte rgba[][4],
- const GLubyte mask[])
-{
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- (void) ctx;
- for (i=0; i<n; i++)
- if (mask[i])
- WMSETPIXEL16(pwfb, FLIP(y[i]), x[i],
- rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-}
-
-/*
- * Write an array of pixels with a boolean mask. The current color
- * is used for all pixels.
- */
-static void write_mono_rgba_pixels_16(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n,
- const GLint x[], const GLint y[],
- const GLchan color[4],
- const GLubyte mask[])
-{
- GLuint i;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
- (void) ctx;
- for (i=0; i<n; i++)
- if (mask[i])
- WMSETPIXEL16(pwfb, FLIP(y[i]),x[i],color[RCOMP],
- color[GCOMP], color[BCOMP]);
-}
-
-/* Read a horizontal span of color pixels. */
-static void read_rgba_span_16(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, GLint x, GLint y,
- GLubyte rgba[][4] )
-{
- GLuint i, pixel;
- LPWORD lpw;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
-
- y = FLIP(y);
- lpw = ((LPWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
- for (i=0; i<n; i++) {
- pixel = lpw[i];
- /* Windows uses 5,5,5 for 16-bit */
- rgba[i][RCOMP] = (pixel & 0x7c00) >> 7;
- rgba[i][GCOMP] = (pixel & 0x03e0) >> 2;
- rgba[i][BCOMP] = (pixel & 0x001f) << 3;
- rgba[i][ACOMP] = 255;
- }
-}
-
-
-/* Read an array of color pixels. */
-static void read_rgba_pixels_16(const struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLuint n, const GLint x[], const GLint y[],
- GLubyte rgba[][4])
-{
- GLuint i, pixel;
- LPWORD lpw;
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
-
- for (i=0; i<n; i++) {
- GLint y2 = FLIP(y[i]);
- lpw = ((LPWORD)(pwfb->pbPixels + pwfb->ScanWidth * y2)) + x[i];
- pixel = *lpw;
- /* Windows uses 5,5,5 for 16-bit */
- rgba[i][RCOMP] = (pixel & 0x7c00) >> 7;
- rgba[i][GCOMP] = (pixel & 0x03e0) >> 2;
- rgba[i][BCOMP] = (pixel & 0x001f) << 3;
- rgba[i][ACOMP] = 255;
- }
-}
-
-
-
-
-/**********************************************************************/
-/***** BUFFER Functions *****/
-/**********************************************************************/
-
-
-
-
-static void
-wmesa_delete_renderbuffer(struct gl_renderbuffer *rb)
-{
- free(rb);
-}
-
-
-/**
- * This is called by Mesa whenever it determines that the window size
- * has changed. Do whatever's needed to cope with that.
- */
-static GLboolean
-wmesa_renderbuffer_storage(struct gl_context *ctx,
- struct gl_renderbuffer *rb,
- GLenum internalFormat,
- GLuint width,
- GLuint height)
-{
- rb->Width = width;
- rb->Height = height;
- return GL_TRUE;
-}
-
-
-/**
- * Plug in the Get/PutRow/Values functions for a renderbuffer depending
- * on if we're drawing to the front or back color buffer.
- */
-void wmesa_set_renderbuffer_funcs(struct gl_renderbuffer *rb, int pixelformat,
- int cColorBits, int double_buffer)
-{
- if (double_buffer) {
- /* back buffer */
- /* Picking the correct span functions is important because
- * the DIB was allocated with the indicated depth. */
- switch(pixelformat) {
- case PF_5R6G5B:
- rb->PutRow = write_rgba_span_16;
- rb->PutRowRGB = write_rgb_span_16;
- rb->PutMonoRow = write_mono_rgba_span_16;
- rb->PutValues = write_rgba_pixels_16;
- rb->PutMonoValues = write_mono_rgba_pixels_16;
- rb->GetRow = read_rgba_span_16;
- rb->GetValues = read_rgba_pixels_16;
- break;
- case PF_8R8G8B:
- if (cColorBits == 24)
- {
- rb->PutRow = write_rgba_span_24;
- rb->PutRowRGB = write_rgb_span_24;
- rb->PutMonoRow = write_mono_rgba_span_24;
- rb->PutValues = write_rgba_pixels_24;
- rb->PutMonoValues = write_mono_rgba_pixels_24;
- rb->GetRow = read_rgba_span_24;
- rb->GetValues = read_rgba_pixels_24;
- }
- else
- {
- rb->PutRow = write_rgba_span_32;
- rb->PutRowRGB = write_rgb_span_32;
- rb->PutMonoRow = write_mono_rgba_span_32;
- rb->PutValues = write_rgba_pixels_32;
- rb->PutMonoValues = write_mono_rgba_pixels_32;
- rb->GetRow = read_rgba_span_32;
- rb->GetValues = read_rgba_pixels_32;
- }
- break;
- default:
- break;
- }
- }
- else {
- /* front buffer (actual Windows window) */
- rb->PutRow = write_rgba_span_front;
- rb->PutRowRGB = write_rgb_span_front;
- rb->PutMonoRow = write_mono_rgba_span_front;
- rb->PutValues = write_rgba_pixels_front;
- rb->PutMonoValues = write_mono_rgba_pixels_front;
- rb->GetRow = read_rgba_span_front;
- rb->GetValues = read_rgba_pixels_front;
- }
-}
-
-/**
- * Called by ctx->Driver.ResizeBuffers()
- * Resize the front/back colorbuffers to match the latest window size.
- */
-static void
-wmesa_resize_buffers(struct gl_context *ctx, struct gl_framebuffer *buffer,
- GLuint width, GLuint height)
-{
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_framebuffer(buffer);
-
- if (pwfb->Base.Width != width || pwfb->Base.Height != height) {
- /* Realloc back buffer */
- if (ctx->Visual.doubleBufferMode == 1) {
- wmDeleteBackingStore(pwfb);
- wmCreateBackingStore(pwfb, width, height);
- }
- }
- _mesa_resize_framebuffer(ctx, buffer, width, height);
-}
-
-
-/**
- * Called by glViewport.
- * This is a good time for us to poll the current window size and adjust
- * our renderbuffers to match the current window size.
- * Remember, we have no opportunity to respond to conventional
- * resize events since the driver has no event loop.
- * Thus, we poll.
- * MakeCurrent also ends up making a call here, so that ensures
- * we get the viewport set correctly, even if the app does not call
- * glViewport and relies on the defaults.
- */
-static void wmesa_viewport(struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height)
-{
- WMesaContext pwc = wmesa_context(ctx);
- GLuint new_width, new_height;
-
- wmesa_get_buffer_size(ctx->WinSysDrawBuffer, &new_width, &new_height);
-
- /**
- * Resize buffers if the window size changed.
- */
- wmesa_resize_buffers(ctx, ctx->WinSysDrawBuffer, new_width, new_height);
- ctx->NewState |= _NEW_BUFFERS; /* to update scissor / window bounds */
-}
-
-
-
-
-/**
- * Called when the driver should update it's state, based on the new_state
- * flags.
- */
-static void wmesa_update_state(struct gl_context *ctx, GLuint new_state)
-{
- _swrast_InvalidateState(ctx, new_state);
- _swsetup_InvalidateState(ctx, new_state);
- _vbo_InvalidateState(ctx, new_state);
- _tnl_InvalidateState(ctx, new_state);
-
- /* TODO - This code is not complete yet because I
- * don't know what to do for all state updates.
- */
-
- if (new_state & _NEW_BUFFERS) {
- }
-}
-
-
-
-
-
-/**********************************************************************/
-/***** WMESA Functions *****/
-/**********************************************************************/
-
-WMesaContext WMesaCreateContext(HDC hDC,
- HPALETTE* Pal,
- GLboolean rgb_flag,
- GLboolean db_flag,
- GLboolean alpha_flag)
-{
- WMesaContext c;
- struct dd_function_table functions;
- GLint red_bits, green_bits, blue_bits, alpha_bits;
- struct gl_context *ctx;
- struct gl_config *visual;
-
- (void) Pal;
-
- /* Indexed mode not supported */
- if (!rgb_flag)
- return NULL;
-
- /* Allocate wmesa context */
- c = CALLOC_STRUCT(wmesa_context);
- if (!c)
- return NULL;
-
-#if 0
- /* I do not understand this contributed code */
- /* Support memory and device contexts */
- if(WindowFromDC(hDC) != NULL) {
- c->hDC = GetDC(WindowFromDC(hDC)); /* huh ???? */
- }
- else {
- c->hDC = hDC;
- }
-#else
- c->hDC = hDC;
-#endif
-
- /* Get data for visual */
- /* Dealing with this is actually a bit of overkill because Mesa will end
- * up treating all color component size requests less than 8 by using
- * a single byte per channel. In addition, the interface to the span
- * routines passes colors as an entire byte per channel anyway, so there
- * is nothing to be saved by telling the visual to be 16 bits if the device
- * is 16 bits. That is, Mesa is going to compute colors down to 8 bits per
- * channel anyway.
- * But we go through the motions here anyway.
- */
- switch (GetDeviceCaps(c->hDC, BITSPIXEL)) {
- case 16:
- red_bits = green_bits = blue_bits = 5;
- alpha_bits = 0;
- break;
- default:
- red_bits = green_bits = blue_bits = 8;
- alpha_bits = 8;
- break;
- }
- /* Create visual based on flags */
- visual = _mesa_create_visual(db_flag, /* db_flag */
- GL_FALSE, /* stereo */
- red_bits, green_bits, blue_bits, /* color RGB */
- alpha_flag ? alpha_bits : 0, /* color A */
- DEFAULT_SOFTWARE_DEPTH_BITS, /* depth_bits */
- 8, /* stencil_bits */
- 16,16,16, /* accum RGB */
- alpha_flag ? 16 : 0, /* accum A */
- 1); /* num samples */
-
- if (!visual) {
- free(c);
- return NULL;
- }
-
- /* Set up driver functions */
- _mesa_init_driver_functions(&functions);
- functions.GetString = wmesa_get_string;
- functions.UpdateState = wmesa_update_state;
- functions.GetBufferSize = wmesa_get_buffer_size;
- functions.Flush = wmesa_flush;
- functions.Clear = clear;
- functions.ClearColor = clear_color;
- functions.ResizeBuffers = wmesa_resize_buffers;
- functions.Viewport = wmesa_viewport;
-
- /* initialize the Mesa context data */
- ctx = &c->gl_ctx;
- _mesa_initialize_context(ctx, API_OPENGL, visual,
- NULL, &functions, (void *)c);
-
- /* visual no longer needed - it was copied by _mesa_initialize_context() */
- _mesa_destroy_visual(visual);
-
- _mesa_enable_sw_extensions(ctx);
- _mesa_enable_1_3_extensions(ctx);
- _mesa_enable_1_4_extensions(ctx);
- _mesa_enable_1_5_extensions(ctx);
- _mesa_enable_2_0_extensions(ctx);
- _mesa_enable_2_1_extensions(ctx);
-
- _mesa_meta_init(ctx);
-
- /* Initialize the software rasterizer and helper modules. */
- if (!_swrast_CreateContext(ctx) ||
- !_vbo_CreateContext(ctx) ||
- !_tnl_CreateContext(ctx) ||
- !_swsetup_CreateContext(ctx)) {
- _mesa_free_context_data(ctx);
- free(c);
- return NULL;
- }
- _swsetup_Wakeup(ctx);
- TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
-
- return c;
-}
-
-
-void WMesaDestroyContext( WMesaContext pwc )
-{
- struct gl_context *ctx = &pwc->gl_ctx;
- WMesaFramebuffer pwfb;
- GET_CURRENT_CONTEXT(cur_ctx);
-
- if (cur_ctx == ctx) {
- /* unbind current if deleting current context */
- WMesaMakeCurrent(NULL, NULL);
- }
-
- /* clean up frame buffer resources */
- pwfb = wmesa_lookup_framebuffer(pwc->hDC);
- if (pwfb) {
- if (ctx->Visual.doubleBufferMode == 1)
- wmDeleteBackingStore(pwfb);
- wmesa_free_framebuffer(pwc->hDC);
- }
-
- /* Release for device, not memory contexts */
- if (WindowFromDC(pwc->hDC) != NULL)
- {
- ReleaseDC(WindowFromDC(pwc->hDC), pwc->hDC);
- }
- DeleteObject(pwc->clearPen);
- DeleteObject(pwc->clearBrush);
-
- _mesa_meta_free(ctx);
-
- _swsetup_DestroyContext(ctx);
- _tnl_DestroyContext(ctx);
- _vbo_DestroyContext(ctx);
- _swrast_DestroyContext(ctx);
-
- _mesa_free_context_data(ctx);
- free(pwc);
-}
-
-
-/**
- * Create a new color renderbuffer.
- */
-struct gl_renderbuffer *
-wmesa_new_renderbuffer(void)
-{
- struct gl_renderbuffer *rb = CALLOC_STRUCT(gl_renderbuffer);
- if (!rb)
- return NULL;
-
- _mesa_init_renderbuffer(rb, (GLuint)0);
-
- rb->_BaseFormat = GL_RGBA;
- rb->InternalFormat = GL_RGBA;
- rb->DataType = CHAN_TYPE;
- rb->Delete = wmesa_delete_renderbuffer;
- rb->AllocStorage = wmesa_renderbuffer_storage;
- return rb;
-}
-
-
-void WMesaMakeCurrent(WMesaContext c, HDC hdc)
-{
- WMesaFramebuffer pwfb;
-
- {
- /* return if already current */
- GET_CURRENT_CONTEXT(ctx);
- WMesaContext pwc = wmesa_context(ctx);
- if (pwc && c == pwc && pwc->hDC == hdc)
- return;
- }
-
- pwfb = wmesa_lookup_framebuffer(hdc);
-
- /* Lazy creation of framebuffers */
- if (c && !pwfb && hdc) {
- struct gl_renderbuffer *rb;
- struct gl_config *visual = &c->gl_ctx.Visual;
- GLuint width, height;
-
- get_window_size(hdc, &width, &height);
-
- c->clearPen = CreatePen(PS_SOLID, 1, 0);
- c->clearBrush = CreateSolidBrush(0);
-
- pwfb = wmesa_new_framebuffer(hdc, visual);
-
- /* Create back buffer if double buffered */
- if (visual->doubleBufferMode == 1) {
- wmCreateBackingStore(pwfb, width, height);
- }
-
- /* make render buffers */
- if (visual->doubleBufferMode == 1) {
- rb = wmesa_new_renderbuffer();
- _mesa_add_renderbuffer(&pwfb->Base, BUFFER_BACK_LEFT, rb);
- wmesa_set_renderbuffer_funcs(rb, pwfb->pixelformat, pwfb->cColorBits, 1);
- }
- rb = wmesa_new_renderbuffer();
- _mesa_add_renderbuffer(&pwfb->Base, BUFFER_FRONT_LEFT, rb);
- wmesa_set_renderbuffer_funcs(rb, pwfb->pixelformat, pwfb->cColorBits, 0);
-
- /* Let Mesa own the Depth, Stencil, and Accum buffers */
- _mesa_add_soft_renderbuffers(&pwfb->Base,
- GL_FALSE, /* color */
- visual->depthBits > 0,
- visual->stencilBits > 0,
- visual->accumRedBits > 0,
- visual->alphaBits >0,
- GL_FALSE);
- }
-
- if (c && pwfb)
- _mesa_make_current(&c->gl_ctx, &pwfb->Base, &pwfb->Base);
- else
- _mesa_make_current(NULL, NULL, NULL);
-}
-
-
-void WMesaSwapBuffers( HDC hdc )
-{
- GET_CURRENT_CONTEXT(ctx);
- WMesaContext pwc = wmesa_context(ctx);
- WMesaFramebuffer pwfb = wmesa_lookup_framebuffer(hdc);
-
- if (!pwfb) {
- _mesa_problem(NULL, "wmesa: swapbuffers on unknown hdc");
- return;
- }
-
- /* If we're swapping the buffer associated with the current context
- * we have to flush any pending rendering commands first.
- */
- if (pwc->hDC == hdc) {
- _mesa_notifySwapBuffers(ctx);
-
- BitBlt(pwfb->hDC, 0, 0, pwfb->Base.Width, pwfb->Base.Height,
- pwfb->dib_hDC, 0, 0, SRCCOPY);
- }
- else {
- /* XXX for now only allow swapping current window */
- _mesa_problem(NULL, "wmesa: can't swap non-current window");
- }
-}
-
-void WMesaShareLists(WMesaContext ctx_to_share, WMesaContext ctx)
-{
- _mesa_share_state(&ctx->gl_ctx, &ctx_to_share->gl_ctx);
-}
-
+/*
+ * Windows (Win32/Win64) device driver for Mesa
+ *
+ */
+
+#include "wmesadef.h"
+#include "colors.h"
+#include <GL/wmesa.h>
+#include <winuser.h>
+#include "context.h"
+#include "extensions.h"
+#include "framebuffer.h"
+#include "renderbuffer.h"
+#include "drivers/common/driverfuncs.h"
+#include "drivers/common/meta.h"
+#include "vbo/vbo.h"
+#include "swrast/swrast.h"
+#include "swrast_setup/swrast_setup.h"
+#include "tnl/tnl.h"
+#include "tnl/t_context.h"
+#include "tnl/t_pipeline.h"
+
+
+/* linked list of our Framebuffers (windows) */
+static WMesaFramebuffer FirstFramebuffer = NULL;
+
+
+/**
+ * Create a new WMesaFramebuffer object which will correspond to the
+ * given HDC (Window handle).
+ */
+WMesaFramebuffer
+wmesa_new_framebuffer(HDC hdc, struct gl_config *visual)
+{
+ WMesaFramebuffer pwfb
+ = (WMesaFramebuffer) malloc(sizeof(struct wmesa_framebuffer));
+ if (pwfb) {
+ _mesa_initialize_window_framebuffer(&pwfb->Base, visual);
+ pwfb->hDC = hdc;
+ /* insert at head of list */
+ pwfb->next = FirstFramebuffer;
+ FirstFramebuffer = pwfb;
+ }
+ return pwfb;
+}
+
+/**
+ * Given an hdc, free the corresponding WMesaFramebuffer
+ */
+void
+wmesa_free_framebuffer(HDC hdc)
+{
+ WMesaFramebuffer pwfb, prev;
+ for (pwfb = FirstFramebuffer; pwfb; pwfb = pwfb->next) {
+ if (pwfb->hDC == hdc)
+ break;
+ prev = pwfb;
+ }
+ if (pwfb) {
+ struct gl_framebuffer *fb;
+ if (pwfb == FirstFramebuffer)
+ FirstFramebuffer = pwfb->next;
+ else
+ prev->next = pwfb->next;
+ fb = &pwfb->Base;
+ _mesa_reference_framebuffer(&fb, NULL);
+ }
+}
+
+/**
+ * Given an hdc, return the corresponding WMesaFramebuffer
+ */
+WMesaFramebuffer
+wmesa_lookup_framebuffer(HDC hdc)
+{
+ WMesaFramebuffer pwfb;
+ for (pwfb = FirstFramebuffer; pwfb; pwfb = pwfb->next) {
+ if (pwfb->hDC == hdc)
+ return pwfb;
+ }
+ return NULL;
+}
+
+
+/**
+ * Given a struct gl_framebuffer, return the corresponding WMesaFramebuffer.
+ */
+static WMesaFramebuffer wmesa_framebuffer(struct gl_framebuffer *fb)
+{
+ return (WMesaFramebuffer) fb;
+}
+
+
+/**
+ * Given a struct gl_context, return the corresponding WMesaContext.
+ */
+static WMesaContext wmesa_context(const struct gl_context *ctx)
+{
+ return (WMesaContext) ctx;
+}
+
+
+/*
+ * Every driver should implement a GetString function in order to
+ * return a meaningful GL_RENDERER string.
+ */
+static const GLubyte *wmesa_get_string(struct gl_context *ctx, GLenum name)
+{
+ return (name == GL_RENDERER) ?
+ (GLubyte *) "Mesa Windows GDI Driver" : NULL;
+}
+
+
+/*
+ * Determine the pixel format based on the pixel size.
+ */
+static void wmSetPixelFormat(WMesaFramebuffer pwfb, HDC hDC)
+{
+ pwfb->cColorBits = GetDeviceCaps(hDC, BITSPIXEL);
+
+ /* Only 16 and 32 bit targets are supported now */
+ assert(pwfb->cColorBits == 0 ||
+ pwfb->cColorBits == 16 ||
+ pwfb->cColorBits == 24 ||
+ pwfb->cColorBits == 32);
+
+ switch(pwfb->cColorBits){
+ case 8:
+ pwfb->pixelformat = PF_INDEX8;
+ break;
+ case 16:
+ pwfb->pixelformat = PF_5R6G5B;
+ break;
+ case 24:
+ case 32:
+ pwfb->pixelformat = PF_8R8G8B;
+ break;
+ default:
+ pwfb->pixelformat = PF_BADFORMAT;
+ }
+}
+
+
+/**
+ * Create DIB for back buffer.
+ * We write into this memory with the span routines and then blit it
+ * to the window on a buffer swap.
+ */
+BOOL wmCreateBackingStore(WMesaFramebuffer pwfb, long lxSize, long lySize)
+{
+ HDC hdc = pwfb->hDC;
+ LPBITMAPINFO pbmi = &(pwfb->bmi);
+ HDC hic;
+
+ pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ pbmi->bmiHeader.biWidth = lxSize;
+ pbmi->bmiHeader.biHeight= -lySize;
+ pbmi->bmiHeader.biPlanes = 1;
+ pbmi->bmiHeader.biBitCount = GetDeviceCaps(pwfb->hDC, BITSPIXEL);
+ pbmi->bmiHeader.biCompression = BI_RGB;
+ pbmi->bmiHeader.biSizeImage = 0;
+ pbmi->bmiHeader.biXPelsPerMeter = 0;
+ pbmi->bmiHeader.biYPelsPerMeter = 0;
+ pbmi->bmiHeader.biClrUsed = 0;
+ pbmi->bmiHeader.biClrImportant = 0;
+
+ pwfb->cColorBits = pbmi->bmiHeader.biBitCount;
+ pwfb->ScanWidth = (lxSize * (pwfb->cColorBits / 8) + 3) & ~3;
+
+ hic = CreateIC("display", NULL, NULL, NULL);
+ pwfb->dib_hDC = CreateCompatibleDC(hic);
+
+ pwfb->hbmDIB = CreateDIBSection(hic,
+ &pwfb->bmi,
+ DIB_RGB_COLORS,
+ (void **)&(pwfb->pbPixels),
+ 0,
+ 0);
+ pwfb->hOldBitmap = SelectObject(pwfb->dib_hDC, pwfb->hbmDIB);
+
+ DeleteDC(hic);
+
+ wmSetPixelFormat(pwfb, pwfb->hDC);
+ return TRUE;
+}
+
+
+static wmDeleteBackingStore(WMesaFramebuffer pwfb)
+{
+ if (pwfb->hbmDIB) {
+ SelectObject(pwfb->dib_hDC, pwfb->hOldBitmap);
+ DeleteDC(pwfb->dib_hDC);
+ DeleteObject(pwfb->hbmDIB);
+ }
+}
+
+
+/**
+ * Find the width and height of the window named by hdc.
+ */
+static void
+get_window_size(HDC hdc, GLuint *width, GLuint *height)
+{
+ if (WindowFromDC(hdc)) {
+ RECT rect;
+ GetClientRect(WindowFromDC(hdc), &rect);
+ *width = rect.right - rect.left;
+ *height = rect.bottom - rect.top;
+ }
+ else { /* Memory context */
+ /* From contributed code - use the size of the desktop
+ * for the size of a memory context (?) */
+ *width = GetDeviceCaps(hdc, HORZRES);
+ *height = GetDeviceCaps(hdc, VERTRES);
+ }
+}
+
+
+static void
+wmesa_get_buffer_size(struct gl_framebuffer *buffer, GLuint *width, GLuint *height)
+{
+ WMesaFramebuffer pwfb = wmesa_framebuffer(buffer);
+ get_window_size(pwfb->hDC, width, height);
+}
+
+
+static void wmesa_flush(struct gl_context *ctx)
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->WinSysDrawBuffer);
+
+ if (ctx->Visual.doubleBufferMode == 1) {
+ BitBlt(pwfb->hDC, 0, 0, pwfb->Base.Width, pwfb->Base.Height,
+ pwfb->dib_hDC, 0, 0, SRCCOPY);
+ }
+ else {
+ /* Do nothing for single buffer */
+ }
+}
+
+
+/**********************************************************************/
+/***** CLEAR Functions *****/
+/**********************************************************************/
+
+/* If we do not implement these, Mesa clears the buffers via the pixel
+ * span writing interface, which is very slow for a clear operation.
+ */
+
+/*
+ * Set the color used to clear the color buffer.
+ */
+static void clear_color(struct gl_context *ctx, const GLfloat color[4])
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ GLubyte col[3];
+ UINT bytesPerPixel = pwfb->cColorBits / 8;
+
+ CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
+ CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
+ CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
+ pwc->clearColorRef = RGB(col[0], col[1], col[2]);
+ DeleteObject(pwc->clearPen);
+ DeleteObject(pwc->clearBrush);
+ pwc->clearPen = CreatePen(PS_SOLID, 1, pwc->clearColorRef);
+ pwc->clearBrush = CreateSolidBrush(pwc->clearColorRef);
+}
+
+
+/*
+ * Clear the specified region of the color buffer using the clear color
+ * or index as specified by one of the two functions above.
+ *
+ * This procedure clears either the front and/or the back COLOR buffers.
+ * Only the "left" buffer is cleared since we are not stereo.
+ * Clearing of the other non-color buffers is left to the swrast.
+ */
+
+static void clear(struct gl_context *ctx, GLbitfield mask)
+{
+#define FLIP(Y) (ctx->DrawBuffer->Height - (Y) - 1)
+ const GLint x = ctx->DrawBuffer->_Xmin;
+ const GLint y = ctx->DrawBuffer->_Ymin;
+ const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
+ const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ int done = 0;
+
+ /* Let swrast do all the work if the masks are not set to
+ * clear all channels. */
+ if (!ctx->Color.ColorMask[0][0] ||
+ !ctx->Color.ColorMask[0][1] ||
+ !ctx->Color.ColorMask[0][2] ||
+ !ctx->Color.ColorMask[0][3]) {
+ _swrast_Clear(ctx, mask);
+ return;
+ }
+
+ /* Back buffer */
+ if (mask & BUFFER_BIT_BACK_LEFT) {
+
+ int i, rowSize;
+ UINT bytesPerPixel = pwfb->cColorBits / 8;
+ LPBYTE lpb, clearRow;
+ LPWORD lpw;
+ BYTE bColor;
+ WORD wColor;
+ BYTE r, g, b;
+ DWORD dwColor;
+ LPDWORD lpdw;
+
+ /* Try for a fast clear - clearing entire buffer with a single
+ * byte value. */
+ if (width == ctx->DrawBuffer->Width &&
+ height == ctx->DrawBuffer->Height) { /* entire buffer */
+ /* Now check for an easy clear value */
+ switch (bytesPerPixel) {
+ case 1:
+ bColor = BGR8(GetRValue(pwc->clearColorRef),
+ GetGValue(pwc->clearColorRef),
+ GetBValue(pwc->clearColorRef));
+ memset(pwfb->pbPixels, bColor,
+ pwfb->ScanWidth * height);
+ done = 1;
+ break;
+ case 2:
+ wColor = BGR16(GetRValue(pwc->clearColorRef),
+ GetGValue(pwc->clearColorRef),
+ GetBValue(pwc->clearColorRef));
+ if (((wColor >> 8) & 0xff) == (wColor & 0xff)) {
+ memset(pwfb->pbPixels, wColor & 0xff,
+ pwfb->ScanWidth * height);
+ done = 1;
+ }
+ break;
+ case 3:
+ /* fall through */
+ case 4:
+ if (GetRValue(pwc->clearColorRef) ==
+ GetGValue(pwc->clearColorRef) &&
+ GetRValue(pwc->clearColorRef) ==
+ GetBValue(pwc->clearColorRef)) {
+ memset(pwfb->pbPixels,
+ GetRValue(pwc->clearColorRef),
+ pwfb->ScanWidth * height);
+ done = 1;
+ }
+ break;
+ default:
+ break;
+ }
+ } /* all */
+
+ if (!done) {
+ /* Need to clear a row at a time. Begin by setting the first
+ * row in the area to be cleared to the clear color. */
+
+ clearRow = pwfb->pbPixels +
+ pwfb->ScanWidth * FLIP(y) +
+ bytesPerPixel * x;
+ switch (bytesPerPixel) {
+ case 1:
+ lpb = clearRow;
+ bColor = BGR8(GetRValue(pwc->clearColorRef),
+ GetGValue(pwc->clearColorRef),
+ GetBValue(pwc->clearColorRef));
+ memset(lpb, bColor, width);
+ break;
+ case 2:
+ lpw = (LPWORD)clearRow;
+ wColor = BGR16(GetRValue(pwc->clearColorRef),
+ GetGValue(pwc->clearColorRef),
+ GetBValue(pwc->clearColorRef));
+ for (i=0; i<width; i++)
+ *lpw++ = wColor;
+ break;
+ case 3:
+ lpb = clearRow;
+ r = GetRValue(pwc->clearColorRef);
+ g = GetGValue(pwc->clearColorRef);
+ b = GetBValue(pwc->clearColorRef);
+ for (i=0; i<width; i++) {
+ *lpb++ = b;
+ *lpb++ = g;
+ *lpb++ = r;
+ }
+ break;
+ case 4:
+ lpdw = (LPDWORD)clearRow;
+ dwColor = BGR32(GetRValue(pwc->clearColorRef),
+ GetGValue(pwc->clearColorRef),
+ GetBValue(pwc->clearColorRef));
+ for (i=0; i<width; i++)
+ *lpdw++ = dwColor;
+ break;
+ default:
+ break;
+ } /* switch */
+
+ /* copy cleared row to other rows in buffer */
+ lpb = clearRow - pwfb->ScanWidth;
+ rowSize = width * bytesPerPixel;
+ for (i=1; i<height; i++) {
+ memcpy(lpb, clearRow, rowSize);
+ lpb -= pwfb->ScanWidth;
+ }
+ } /* not done */
+ mask &= ~BUFFER_BIT_BACK_LEFT;
+ } /* back buffer */
+
+ /* front buffer */
+ if (mask & BUFFER_BIT_FRONT_LEFT) {
+ HDC DC = pwc->hDC;
+ HPEN Old_Pen = SelectObject(DC, pwc->clearPen);
+ HBRUSH Old_Brush = SelectObject(DC, pwc->clearBrush);
+ Rectangle(DC,
+ x,
+ FLIP(y) + 1,
+ x + width + 1,
+ FLIP(y) - height + 1);
+ SelectObject(DC, Old_Pen);
+ SelectObject(DC, Old_Brush);
+ mask &= ~BUFFER_BIT_FRONT_LEFT;
+ } /* front buffer */
+
+ /* Call swrast if there is anything left to clear (like DEPTH) */
+ if (mask)
+ _swrast_Clear(ctx, mask);
+
+#undef FLIP
+}
+
+
+/**********************************************************************/
+/***** PIXEL Functions *****/
+/**********************************************************************/
+
+#define FLIP(Y) (rb->Height - (Y) - 1)
+
+
+/**
+ ** Front Buffer reading/writing
+ ** These are slow, but work with all non-indexed visual types.
+ **/
+
+/* Write a horizontal span of RGBA color pixels with a boolean mask. */
+static void write_rgba_span_front(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLubyte rgba[][4],
+ const GLubyte mask[] )
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_lookup_framebuffer(pwc->hDC);
+ CONST BITMAPINFO bmi=
+ {
+ {
+ sizeof(BITMAPINFOHEADER),
+ n, 1, 1, 32, BI_RGB, 0, 1, 1, 0, 0
+ }
+ };
+ HBITMAP bmp=0;
+ HDC mdc=0;
+ typedef union
+ {
+ unsigned i;
+ struct {
+ unsigned b:8, g:8, r:8, a:8;
+ };
+ } BGRA;
+ BGRA *bgra, c;
+ GLuint i;
+
+ if (n < 16) { // the value 16 is just guessed
+ y=FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ SetPixel(pwc->hDC, x+i, y,
+ RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
+ }
+ else {
+ for (i=0; i<n; i++)
+ SetPixel(pwc->hDC, x+i, y,
+ RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
+ }
+ }
+ else {
+ if (!pwfb) {
+ _mesa_problem(NULL, "wmesa: write_rgba_span_front on unknown hdc");
+ return;
+ }
+ bgra=malloc(n*sizeof(BGRA));
+ if (!bgra) {
+ _mesa_problem(NULL, "wmesa: write_rgba_span_front: out of memory");
+ return;
+ }
+ c.a=0;
+ if (mask) {
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ c.r=rgba[i][RCOMP];
+ c.g=rgba[i][GCOMP];
+ c.b=rgba[i][BCOMP];
+ c.a=rgba[i][ACOMP];
+ bgra[i]=c;
+ }
+ else
+ bgra[i].i=0;
+ }
+ }
+ else {
+ for (i=0; i<n; i++) {
+ c.r=rgba[i][RCOMP];
+ c.g=rgba[i][GCOMP];
+ c.b=rgba[i][BCOMP];
+ c.a=rgba[i][ACOMP];
+ bgra[i]=c;
+ }
+ }
+ bmp=CreateBitmap(n, 1, 1, 32, bgra);
+ mdc=CreateCompatibleDC(pwfb->hDC);
+ SelectObject(mdc, bmp);
+ y=FLIP(y);
+ BitBlt(pwfb->hDC, x, y, n, 1, mdc, 0, 0, SRCCOPY);
+ SelectObject(mdc, 0);
+ DeleteObject(bmp);
+ DeleteDC(mdc);
+ free(bgra);
+ }
+}
+
+/* Write a horizontal span of RGB color pixels with a boolean mask. */
+static void write_rgb_span_front(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLubyte rgb[][3],
+ const GLubyte mask[] )
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ GLuint i;
+
+ (void) ctx;
+ y=FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ SetPixel(pwc->hDC, x+i, y, RGB(rgb[i][RCOMP], rgb[i][GCOMP],
+ rgb[i][BCOMP]));
+ }
+ else {
+ for (i=0; i<n; i++)
+ SetPixel(pwc->hDC, x+i, y, RGB(rgb[i][RCOMP], rgb[i][GCOMP],
+ rgb[i][BCOMP]));
+ }
+
+}
+
+/*
+ * Write a horizontal span of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_mono_rgba_span_front(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLchan color[4],
+ const GLubyte mask[])
+{
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ COLORREF colorref;
+
+ (void) ctx;
+ colorref = RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
+ y=FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ SetPixel(pwc->hDC, x+i, y, colorref);
+ }
+ else
+ for (i=0; i<n; i++)
+ SetPixel(pwc->hDC, x+i, y, colorref);
+
+}
+
+/* Write an array of RGBA pixels with a boolean mask. */
+static void write_rgba_pixels_front(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLubyte rgba[][4],
+ const GLubyte mask[] )
+{
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ (void) ctx;
+ for (i=0; i<n; i++)
+ if (mask[i])
+ SetPixel(pwc->hDC, x[i], FLIP(y[i]),
+ RGB(rgba[i][RCOMP], rgba[i][GCOMP],
+ rgba[i][BCOMP]));
+}
+
+
+
+/*
+ * Write an array of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_mono_rgba_pixels_front(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLchan color[4],
+ const GLubyte mask[] )
+{
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ COLORREF colorref;
+ (void) ctx;
+ colorref = RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ SetPixel(pwc->hDC, x[i], FLIP(y[i]), colorref);
+}
+
+/* Read a horizontal span of color pixels. */
+static void read_rgba_span_front(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ GLubyte rgba[][4] )
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ GLuint i;
+ COLORREF Color;
+ y = FLIP(y);
+ for (i=0; i<n; i++) {
+ Color = GetPixel(pwc->hDC, x+i, y);
+ rgba[i][RCOMP] = GetRValue(Color);
+ rgba[i][GCOMP] = GetGValue(Color);
+ rgba[i][BCOMP] = GetBValue(Color);
+ rgba[i][ACOMP] = 255;
+ }
+}
+
+
+/* Read an array of color pixels. */
+static void read_rgba_pixels_front(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, const GLint x[], const GLint y[],
+ GLubyte rgba[][4])
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ GLuint i;
+ COLORREF Color;
+ for (i=0; i<n; i++) {
+ GLint y2 = FLIP(y[i]);
+ Color = GetPixel(pwc->hDC, x[i], y2);
+ rgba[i][RCOMP] = GetRValue(Color);
+ rgba[i][GCOMP] = GetGValue(Color);
+ rgba[i][BCOMP] = GetBValue(Color);
+ rgba[i][ACOMP] = 255;
+ }
+}
+
+/*********************************************************************/
+
+/* DOUBLE BUFFER 32-bit */
+
+#define WMSETPIXEL32(pwc, y, x, r, g, b) { \
+LPDWORD lpdw = ((LPDWORD)((pwc)->pbPixels + (pwc)->ScanWidth * (y)) + (x)); \
+*lpdw = BGR32((r),(g),(b)); }
+
+
+
+/* Write a horizontal span of RGBA color pixels with a boolean mask. */
+static void write_rgba_span_32(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLubyte rgba[][4],
+ const GLubyte mask[] )
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ GLuint i;
+ LPDWORD lpdw;
+
+ (void) ctx;
+
+ y=FLIP(y);
+ lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ lpdw[i] = BGR32(rgba[i][RCOMP], rgba[i][GCOMP],
+ rgba[i][BCOMP]);
+ }
+ else {
+ for (i=0; i<n; i++)
+ *lpdw++ = BGR32(rgba[i][RCOMP], rgba[i][GCOMP],
+ rgba[i][BCOMP]);
+ }
+}
+
+
+/* Write a horizontal span of RGB color pixels with a boolean mask. */
+static void write_rgb_span_32(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLubyte rgb[][3],
+ const GLubyte mask[] )
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ GLuint i;
+ LPDWORD lpdw;
+
+ (void) ctx;
+
+ y=FLIP(y);
+ lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ lpdw[i] = BGR32(rgb[i][RCOMP], rgb[i][GCOMP],
+ rgb[i][BCOMP]);
+ }
+ else {
+ for (i=0; i<n; i++)
+ *lpdw++ = BGR32(rgb[i][RCOMP], rgb[i][GCOMP],
+ rgb[i][BCOMP]);
+ }
+}
+
+/*
+ * Write a horizontal span of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_mono_rgba_span_32(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLchan color[4],
+ const GLubyte mask[])
+{
+ LPDWORD lpdw;
+ DWORD pixel;
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
+ y=FLIP(y);
+ pixel = BGR32(color[RCOMP], color[GCOMP], color[BCOMP]);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ lpdw[i] = pixel;
+ }
+ else
+ for (i=0; i<n; i++)
+ *lpdw++ = pixel;
+
+}
+
+/* Write an array of RGBA pixels with a boolean mask. */
+static void write_rgba_pixels_32(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLubyte rgba[][4],
+ const GLubyte mask[])
+{
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ WMSETPIXEL32(pwfb, FLIP(y[i]), x[i],
+ rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
+}
+
+/*
+ * Write an array of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_mono_rgba_pixels_32(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLchan color[4],
+ const GLubyte mask[])
+{
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ WMSETPIXEL32(pwfb, FLIP(y[i]),x[i],color[RCOMP],
+ color[GCOMP], color[BCOMP]);
+}
+
+/* Read a horizontal span of color pixels. */
+static void read_rgba_span_32(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ GLubyte rgba[][4] )
+{
+ GLuint i;
+ DWORD pixel;
+ LPDWORD lpdw;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+
+ y = FLIP(y);
+ lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
+ for (i=0; i<n; i++) {
+ pixel = lpdw[i];
+ rgba[i][RCOMP] = (GLubyte)((pixel & 0x00ff0000) >> 16);
+ rgba[i][GCOMP] = (GLubyte)((pixel & 0x0000ff00) >> 8);
+ rgba[i][BCOMP] = (GLubyte)(pixel & 0x000000ff);
+ rgba[i][ACOMP] = 255;
+ }
+}
+
+
+/* Read an array of color pixels. */
+static void read_rgba_pixels_32(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, const GLint x[], const GLint y[],
+ GLubyte rgba[][4])
+{
+ GLuint i;
+ DWORD pixel;
+ LPDWORD lpdw;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+
+ for (i=0; i<n; i++) {
+ GLint y2 = FLIP(y[i]);
+ lpdw = ((LPDWORD)(pwfb->pbPixels + pwfb->ScanWidth * y2)) + x[i];
+ pixel = *lpdw;
+ rgba[i][RCOMP] = (GLubyte)((pixel & 0x00ff0000) >> 16);
+ rgba[i][GCOMP] = (GLubyte)((pixel & 0x0000ff00) >> 8);
+ rgba[i][BCOMP] = (GLubyte)(pixel & 0x000000ff);
+ rgba[i][ACOMP] = 255;
+ }
+}
+
+
+/*********************************************************************/
+
+/* DOUBLE BUFFER 24-bit */
+
+#define WMSETPIXEL24(pwc, y, x, r, g, b) { \
+LPBYTE lpb = ((LPBYTE)((pwc)->pbPixels + (pwc)->ScanWidth * (y)) + (3 * x)); \
+lpb[0] = (b); \
+lpb[1] = (g); \
+lpb[2] = (r); }
+
+/* Write a horizontal span of RGBA color pixels with a boolean mask. */
+static void write_rgba_span_24(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLubyte rgba[][4],
+ const GLubyte mask[] )
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ GLuint i;
+ LPBYTE lpb;
+
+ (void) ctx;
+
+ y=FLIP(y);
+ lpb = ((LPBYTE)(pwfb->pbPixels + pwfb->ScanWidth * y)) + (3 * x);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i]) {
+ lpb[3*i] = rgba[i][BCOMP];
+ lpb[3*i+1] = rgba[i][GCOMP];
+ lpb[3*i+2] = rgba[i][RCOMP];
+ }
+ }
+ else {
+ for (i=0; i<n; i++) {
+ *lpb++ = rgba[i][BCOMP];
+ *lpb++ = rgba[i][GCOMP];
+ *lpb++ = rgba[i][RCOMP];
+ }
+ }
+}
+
+
+/* Write a horizontal span of RGB color pixels with a boolean mask. */
+static void write_rgb_span_24(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLubyte rgb[][3],
+ const GLubyte mask[] )
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ GLuint i;
+ LPBYTE lpb;
+
+ (void) ctx;
+
+ y=FLIP(y);
+ lpb = ((LPBYTE)(pwfb->pbPixels + pwfb->ScanWidth * y)) + (3 * x);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i]) {
+ lpb[3*i] = rgb[i][BCOMP];
+ lpb[3*i+1] = rgb[i][GCOMP];
+ lpb[3*i+2] = rgb[i][RCOMP];
+ }
+ }
+ else {
+ for (i=0; i<n; i++) {
+ *lpb++ = rgb[i][BCOMP];
+ *lpb++ = rgb[i][GCOMP];
+ *lpb++ = rgb[i][RCOMP];
+ }
+ }
+}
+
+/*
+ * Write a horizontal span of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_mono_rgba_span_24(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLchan color[4],
+ const GLubyte mask[])
+{
+ LPBYTE lpb;
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ lpb = ((LPBYTE)(pwfb->pbPixels + pwfb->ScanWidth * y)) + (3 * x);
+ y=FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i]) {
+ lpb[3*i] = color[BCOMP];
+ lpb[3*i+1] = color[GCOMP];
+ lpb[3*i+2] = color[RCOMP];
+ }
+ }
+ else
+ for (i=0; i<n; i++) {
+ *lpb++ = color[BCOMP];
+ *lpb++ = color[GCOMP];
+ *lpb++ = color[RCOMP];
+ }
+}
+
+/* Write an array of RGBA pixels with a boolean mask. */
+static void write_rgba_pixels_24(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLubyte rgba[][4],
+ const GLubyte mask[])
+{
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ WMSETPIXEL24(pwfb, FLIP(y[i]), x[i],
+ rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
+}
+
+/*
+ * Write an array of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_mono_rgba_pixels_24(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLchan color[4],
+ const GLubyte mask[])
+{
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ WMSETPIXEL24(pwfb, FLIP(y[i]),x[i],color[RCOMP],
+ color[GCOMP], color[BCOMP]);
+}
+
+/* Read a horizontal span of color pixels. */
+static void read_rgba_span_24(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ GLubyte rgba[][4] )
+{
+ GLuint i;
+ LPBYTE lpb;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+
+ y = FLIP(y);
+ lpb = ((LPBYTE)(pwfb->pbPixels + pwfb->ScanWidth * y)) + (3 * x);
+ for (i=0; i<n; i++) {
+ rgba[i][RCOMP] = lpb[3*i+2];
+ rgba[i][GCOMP] = lpb[3*i+1];
+ rgba[i][BCOMP] = lpb[3*i];
+ rgba[i][ACOMP] = 255;
+ }
+}
+
+
+/* Read an array of color pixels. */
+static void read_rgba_pixels_24(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, const GLint x[], const GLint y[],
+ GLubyte rgba[][4])
+{
+ GLuint i;
+ LPBYTE lpb;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+
+ for (i=0; i<n; i++) {
+ GLint y2 = FLIP(y[i]);
+ lpb = ((LPBYTE)(pwfb->pbPixels + pwfb->ScanWidth * y2)) + (3 * x[i]);
+ rgba[i][RCOMP] = lpb[3*i+2];
+ rgba[i][GCOMP] = lpb[3*i+1];
+ rgba[i][BCOMP] = lpb[3*i];
+ rgba[i][ACOMP] = 255;
+ }
+}
+
+
+/*********************************************************************/
+
+/* DOUBLE BUFFER 16-bit */
+
+#define WMSETPIXEL16(pwc, y, x, r, g, b) { \
+LPWORD lpw = ((LPWORD)((pwc)->pbPixels + (pwc)->ScanWidth * (y)) + (x)); \
+*lpw = BGR16((r),(g),(b)); }
+
+
+
+/* Write a horizontal span of RGBA color pixels with a boolean mask. */
+static void write_rgba_span_16(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLubyte rgba[][4],
+ const GLubyte mask[] )
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ GLuint i;
+ LPWORD lpw;
+
+ (void) ctx;
+
+ y=FLIP(y);
+ lpw = ((LPWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ lpw[i] = BGR16(rgba[i][RCOMP], rgba[i][GCOMP],
+ rgba[i][BCOMP]);
+ }
+ else {
+ for (i=0; i<n; i++)
+ *lpw++ = BGR16(rgba[i][RCOMP], rgba[i][GCOMP],
+ rgba[i][BCOMP]);
+ }
+}
+
+
+/* Write a horizontal span of RGB color pixels with a boolean mask. */
+static void write_rgb_span_16(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLubyte rgb[][3],
+ const GLubyte mask[] )
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ GLuint i;
+ LPWORD lpw;
+
+ (void) ctx;
+
+ y=FLIP(y);
+ lpw = ((LPWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ lpw[i] = BGR16(rgb[i][RCOMP], rgb[i][GCOMP],
+ rgb[i][BCOMP]);
+ }
+ else {
+ for (i=0; i<n; i++)
+ *lpw++ = BGR16(rgb[i][RCOMP], rgb[i][GCOMP],
+ rgb[i][BCOMP]);
+ }
+}
+
+/*
+ * Write a horizontal span of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_mono_rgba_span_16(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ const GLchan color[4],
+ const GLubyte mask[])
+{
+ LPWORD lpw;
+ WORD pixel;
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ (void) ctx;
+ lpw = ((LPWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
+ y=FLIP(y);
+ pixel = BGR16(color[RCOMP], color[GCOMP], color[BCOMP]);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ lpw[i] = pixel;
+ }
+ else
+ for (i=0; i<n; i++)
+ *lpw++ = pixel;
+
+}
+
+/* Write an array of RGBA pixels with a boolean mask. */
+static void write_rgba_pixels_16(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLubyte rgba[][4],
+ const GLubyte mask[])
+{
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ (void) ctx;
+ for (i=0; i<n; i++)
+ if (mask[i])
+ WMSETPIXEL16(pwfb, FLIP(y[i]), x[i],
+ rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
+}
+
+/*
+ * Write an array of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_mono_rgba_pixels_16(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLchan color[4],
+ const GLubyte mask[])
+{
+ GLuint i;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+ (void) ctx;
+ for (i=0; i<n; i++)
+ if (mask[i])
+ WMSETPIXEL16(pwfb, FLIP(y[i]),x[i],color[RCOMP],
+ color[GCOMP], color[BCOMP]);
+}
+
+/* Read a horizontal span of color pixels. */
+static void read_rgba_span_16(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, GLint x, GLint y,
+ GLubyte rgba[][4] )
+{
+ GLuint i, pixel;
+ LPWORD lpw;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+
+ y = FLIP(y);
+ lpw = ((LPWORD)(pwfb->pbPixels + pwfb->ScanWidth * y)) + x;
+ for (i=0; i<n; i++) {
+ pixel = lpw[i];
+ /* Windows uses 5,5,5 for 16-bit */
+ rgba[i][RCOMP] = (pixel & 0x7c00) >> 7;
+ rgba[i][GCOMP] = (pixel & 0x03e0) >> 2;
+ rgba[i][BCOMP] = (pixel & 0x001f) << 3;
+ rgba[i][ACOMP] = 255;
+ }
+}
+
+
+/* Read an array of color pixels. */
+static void read_rgba_pixels_16(const struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint n, const GLint x[], const GLint y[],
+ GLubyte rgba[][4])
+{
+ GLuint i, pixel;
+ LPWORD lpw;
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(ctx->DrawBuffer);
+
+ for (i=0; i<n; i++) {
+ GLint y2 = FLIP(y[i]);
+ lpw = ((LPWORD)(pwfb->pbPixels + pwfb->ScanWidth * y2)) + x[i];
+ pixel = *lpw;
+ /* Windows uses 5,5,5 for 16-bit */
+ rgba[i][RCOMP] = (pixel & 0x7c00) >> 7;
+ rgba[i][GCOMP] = (pixel & 0x03e0) >> 2;
+ rgba[i][BCOMP] = (pixel & 0x001f) << 3;
+ rgba[i][ACOMP] = 255;
+ }
+}
+
+
+
+
+/**********************************************************************/
+/***** BUFFER Functions *****/
+/**********************************************************************/
+
+
+
+
+static void
+wmesa_delete_renderbuffer(struct gl_renderbuffer *rb)
+{
+ free(rb);
+}
+
+
+/**
+ * This is called by Mesa whenever it determines that the window size
+ * has changed. Do whatever's needed to cope with that.
+ */
+static GLboolean
+wmesa_renderbuffer_storage(struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLenum internalFormat,
+ GLuint width,
+ GLuint height)
+{
+ rb->Width = width;
+ rb->Height = height;
+ return GL_TRUE;
+}
+
+
+/**
+ * Plug in the Get/PutRow/Values functions for a renderbuffer depending
+ * on if we're drawing to the front or back color buffer.
+ */
+void wmesa_set_renderbuffer_funcs(struct gl_renderbuffer *rb, int pixelformat,
+ int cColorBits, int double_buffer)
+{
+ if (double_buffer) {
+ /* back buffer */
+ /* Picking the correct span functions is important because
+ * the DIB was allocated with the indicated depth. */
+ switch(pixelformat) {
+ case PF_5R6G5B:
+ rb->PutRow = write_rgba_span_16;
+ rb->PutRowRGB = write_rgb_span_16;
+ rb->PutMonoRow = write_mono_rgba_span_16;
+ rb->PutValues = write_rgba_pixels_16;
+ rb->PutMonoValues = write_mono_rgba_pixels_16;
+ rb->GetRow = read_rgba_span_16;
+ rb->GetValues = read_rgba_pixels_16;
+ break;
+ case PF_8R8G8B:
+ if (cColorBits == 24)
+ {
+ rb->PutRow = write_rgba_span_24;
+ rb->PutRowRGB = write_rgb_span_24;
+ rb->PutMonoRow = write_mono_rgba_span_24;
+ rb->PutValues = write_rgba_pixels_24;
+ rb->PutMonoValues = write_mono_rgba_pixels_24;
+ rb->GetRow = read_rgba_span_24;
+ rb->GetValues = read_rgba_pixels_24;
+ }
+ else
+ {
+ rb->PutRow = write_rgba_span_32;
+ rb->PutRowRGB = write_rgb_span_32;
+ rb->PutMonoRow = write_mono_rgba_span_32;
+ rb->PutValues = write_rgba_pixels_32;
+ rb->PutMonoValues = write_mono_rgba_pixels_32;
+ rb->GetRow = read_rgba_span_32;
+ rb->GetValues = read_rgba_pixels_32;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ else {
+ /* front buffer (actual Windows window) */
+ rb->PutRow = write_rgba_span_front;
+ rb->PutRowRGB = write_rgb_span_front;
+ rb->PutMonoRow = write_mono_rgba_span_front;
+ rb->PutValues = write_rgba_pixels_front;
+ rb->PutMonoValues = write_mono_rgba_pixels_front;
+ rb->GetRow = read_rgba_span_front;
+ rb->GetValues = read_rgba_pixels_front;
+ }
+}
+
+/**
+ * Called by ctx->Driver.ResizeBuffers()
+ * Resize the front/back colorbuffers to match the latest window size.
+ */
+static void
+wmesa_resize_buffers(struct gl_context *ctx, struct gl_framebuffer *buffer,
+ GLuint width, GLuint height)
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_framebuffer(buffer);
+
+ if (pwfb->Base.Width != width || pwfb->Base.Height != height) {
+ /* Realloc back buffer */
+ if (ctx->Visual.doubleBufferMode == 1) {
+ wmDeleteBackingStore(pwfb);
+ wmCreateBackingStore(pwfb, width, height);
+ }
+ }
+ _mesa_resize_framebuffer(ctx, buffer, width, height);
+}
+
+
+/**
+ * Called by glViewport.
+ * This is a good time for us to poll the current window size and adjust
+ * our renderbuffers to match the current window size.
+ * Remember, we have no opportunity to respond to conventional
+ * resize events since the driver has no event loop.
+ * Thus, we poll.
+ * MakeCurrent also ends up making a call here, so that ensures
+ * we get the viewport set correctly, even if the app does not call
+ * glViewport and relies on the defaults.
+ */
+static void wmesa_viewport(struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height)
+{
+ WMesaContext pwc = wmesa_context(ctx);
+ GLuint new_width, new_height;
+
+ wmesa_get_buffer_size(ctx->WinSysDrawBuffer, &new_width, &new_height);
+
+ /**
+ * Resize buffers if the window size changed.
+ */
+ wmesa_resize_buffers(ctx, ctx->WinSysDrawBuffer, new_width, new_height);
+ ctx->NewState |= _NEW_BUFFERS; /* to update scissor / window bounds */
+}
+
+
+
+
+/**
+ * Called when the driver should update it's state, based on the new_state
+ * flags.
+ */
+static void wmesa_update_state(struct gl_context *ctx, GLuint new_state)
+{
+ _swrast_InvalidateState(ctx, new_state);
+ _swsetup_InvalidateState(ctx, new_state);
+ _vbo_InvalidateState(ctx, new_state);
+ _tnl_InvalidateState(ctx, new_state);
+
+ /* TODO - This code is not complete yet because I
+ * don't know what to do for all state updates.
+ */
+
+ if (new_state & _NEW_BUFFERS) {
+ }
+}
+
+
+
+
+
+/**********************************************************************/
+/***** WMESA Functions *****/
+/**********************************************************************/
+
+WMesaContext WMesaCreateContext(HDC hDC,
+ HPALETTE* Pal,
+ GLboolean rgb_flag,
+ GLboolean db_flag,
+ GLboolean alpha_flag)
+{
+ WMesaContext c;
+ struct dd_function_table functions;
+ GLint red_bits, green_bits, blue_bits, alpha_bits;
+ struct gl_context *ctx;
+ struct gl_config *visual;
+
+ (void) Pal;
+
+ /* Indexed mode not supported */
+ if (!rgb_flag)
+ return NULL;
+
+ /* Allocate wmesa context */
+ c = CALLOC_STRUCT(wmesa_context);
+ if (!c)
+ return NULL;
+
+#if 0
+ /* I do not understand this contributed code */
+ /* Support memory and device contexts */
+ if(WindowFromDC(hDC) != NULL) {
+ c->hDC = GetDC(WindowFromDC(hDC)); /* huh ???? */
+ }
+ else {
+ c->hDC = hDC;
+ }
+#else
+ c->hDC = hDC;
+#endif
+
+ /* Get data for visual */
+ /* Dealing with this is actually a bit of overkill because Mesa will end
+ * up treating all color component size requests less than 8 by using
+ * a single byte per channel. In addition, the interface to the span
+ * routines passes colors as an entire byte per channel anyway, so there
+ * is nothing to be saved by telling the visual to be 16 bits if the device
+ * is 16 bits. That is, Mesa is going to compute colors down to 8 bits per
+ * channel anyway.
+ * But we go through the motions here anyway.
+ */
+ switch (GetDeviceCaps(c->hDC, BITSPIXEL)) {
+ case 16:
+ red_bits = green_bits = blue_bits = 5;
+ alpha_bits = 0;
+ break;
+ default:
+ red_bits = green_bits = blue_bits = 8;
+ alpha_bits = 8;
+ break;
+ }
+ /* Create visual based on flags */
+ visual = _mesa_create_visual(db_flag, /* db_flag */
+ GL_FALSE, /* stereo */
+ red_bits, green_bits, blue_bits, /* color RGB */
+ alpha_flag ? alpha_bits : 0, /* color A */
+ DEFAULT_SOFTWARE_DEPTH_BITS, /* depth_bits */
+ 8, /* stencil_bits */
+ 16,16,16, /* accum RGB */
+ alpha_flag ? 16 : 0, /* accum A */
+ 1); /* num samples */
+
+ if (!visual) {
+ free(c);
+ return NULL;
+ }
+
+ /* Set up driver functions */
+ _mesa_init_driver_functions(&functions);
+ functions.GetString = wmesa_get_string;
+ functions.UpdateState = wmesa_update_state;
+ functions.GetBufferSize = wmesa_get_buffer_size;
+ functions.Flush = wmesa_flush;
+ functions.Clear = clear;
+ functions.ClearColor = clear_color;
+ functions.ResizeBuffers = wmesa_resize_buffers;
+ functions.Viewport = wmesa_viewport;
+
+ /* initialize the Mesa context data */
+ ctx = &c->gl_ctx;
+ _mesa_initialize_context(ctx, API_OPENGL, visual,
+ NULL, &functions, (void *)c);
+
+ /* visual no longer needed - it was copied by _mesa_initialize_context() */
+ _mesa_destroy_visual(visual);
+
+ _mesa_enable_sw_extensions(ctx);
+ _mesa_enable_1_3_extensions(ctx);
+ _mesa_enable_1_4_extensions(ctx);
+ _mesa_enable_1_5_extensions(ctx);
+ _mesa_enable_2_0_extensions(ctx);
+ _mesa_enable_2_1_extensions(ctx);
+
+ _mesa_meta_init(ctx);
+
+ /* Initialize the software rasterizer and helper modules. */
+ if (!_swrast_CreateContext(ctx) ||
+ !_vbo_CreateContext(ctx) ||
+ !_tnl_CreateContext(ctx) ||
+ !_swsetup_CreateContext(ctx)) {
+ _mesa_free_context_data(ctx);
+ free(c);
+ return NULL;
+ }
+ _swsetup_Wakeup(ctx);
+ TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
+
+ return c;
+}
+
+
+void WMesaDestroyContext( WMesaContext pwc )
+{
+ struct gl_context *ctx = &pwc->gl_ctx;
+ WMesaFramebuffer pwfb;
+ GET_CURRENT_CONTEXT(cur_ctx);
+
+ if (cur_ctx == ctx) {
+ /* unbind current if deleting current context */
+ WMesaMakeCurrent(NULL, NULL);
+ }
+
+ /* clean up frame buffer resources */
+ pwfb = wmesa_lookup_framebuffer(pwc->hDC);
+ if (pwfb) {
+ if (ctx->Visual.doubleBufferMode == 1)
+ wmDeleteBackingStore(pwfb);
+ wmesa_free_framebuffer(pwc->hDC);
+ }
+
+ /* Release for device, not memory contexts */
+ if (WindowFromDC(pwc->hDC) != NULL)
+ {
+ ReleaseDC(WindowFromDC(pwc->hDC), pwc->hDC);
+ }
+ DeleteObject(pwc->clearPen);
+ DeleteObject(pwc->clearBrush);
+
+ _mesa_meta_free(ctx);
+
+ _swsetup_DestroyContext(ctx);
+ _tnl_DestroyContext(ctx);
+ _vbo_DestroyContext(ctx);
+ _swrast_DestroyContext(ctx);
+
+ _mesa_free_context_data(ctx);
+ free(pwc);
+}
+
+
+/**
+ * Create a new color renderbuffer.
+ */
+struct gl_renderbuffer *
+wmesa_new_renderbuffer(void)
+{
+ struct gl_renderbuffer *rb = CALLOC_STRUCT(gl_renderbuffer);
+ if (!rb)
+ return NULL;
+
+ _mesa_init_renderbuffer(rb, (GLuint)0);
+
+ rb->_BaseFormat = GL_RGBA;
+ rb->InternalFormat = GL_RGBA;
+ rb->DataType = CHAN_TYPE;
+ rb->Delete = wmesa_delete_renderbuffer;
+ rb->AllocStorage = wmesa_renderbuffer_storage;
+ return rb;
+}
+
+
+void WMesaMakeCurrent(WMesaContext c, HDC hdc)
+{
+ WMesaFramebuffer pwfb;
+
+ {
+ /* return if already current */
+ GET_CURRENT_CONTEXT(ctx);
+ WMesaContext pwc = wmesa_context(ctx);
+ if (pwc && c == pwc && pwc->hDC == hdc)
+ return;
+ }
+
+ pwfb = wmesa_lookup_framebuffer(hdc);
+
+ /* Lazy creation of framebuffers */
+ if (c && !pwfb && hdc) {
+ struct gl_renderbuffer *rb;
+ struct gl_config *visual = &c->gl_ctx.Visual;
+ GLuint width, height;
+
+ get_window_size(hdc, &width, &height);
+
+ c->clearPen = CreatePen(PS_SOLID, 1, 0);
+ c->clearBrush = CreateSolidBrush(0);
+
+ pwfb = wmesa_new_framebuffer(hdc, visual);
+
+ /* Create back buffer if double buffered */
+ if (visual->doubleBufferMode == 1) {
+ wmCreateBackingStore(pwfb, width, height);
+ }
+
+ /* make render buffers */
+ if (visual->doubleBufferMode == 1) {
+ rb = wmesa_new_renderbuffer();
+ _mesa_add_renderbuffer(&pwfb->Base, BUFFER_BACK_LEFT, rb);
+ wmesa_set_renderbuffer_funcs(rb, pwfb->pixelformat, pwfb->cColorBits, 1);
+ }
+ rb = wmesa_new_renderbuffer();
+ _mesa_add_renderbuffer(&pwfb->Base, BUFFER_FRONT_LEFT, rb);
+ wmesa_set_renderbuffer_funcs(rb, pwfb->pixelformat, pwfb->cColorBits, 0);
+
+ /* Let Mesa own the Depth, Stencil, and Accum buffers */
+ _mesa_add_soft_renderbuffers(&pwfb->Base,
+ GL_FALSE, /* color */
+ visual->depthBits > 0,
+ visual->stencilBits > 0,
+ visual->accumRedBits > 0,
+ visual->alphaBits >0,
+ GL_FALSE);
+ }
+
+ if (c && pwfb)
+ _mesa_make_current(&c->gl_ctx, &pwfb->Base, &pwfb->Base);
+ else
+ _mesa_make_current(NULL, NULL, NULL);
+}
+
+
+void WMesaSwapBuffers( HDC hdc )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ WMesaContext pwc = wmesa_context(ctx);
+ WMesaFramebuffer pwfb = wmesa_lookup_framebuffer(hdc);
+
+ if (!pwfb) {
+ _mesa_problem(NULL, "wmesa: swapbuffers on unknown hdc");
+ return;
+ }
+
+ /* If we're swapping the buffer associated with the current context
+ * we have to flush any pending rendering commands first.
+ */
+ if (pwc->hDC == hdc) {
+ _mesa_notifySwapBuffers(ctx);
+
+ BitBlt(pwfb->hDC, 0, 0, pwfb->Base.Width, pwfb->Base.Height,
+ pwfb->dib_hDC, 0, 0, SRCCOPY);
+ }
+ else {
+ /* XXX for now only allow swapping current window */
+ _mesa_problem(NULL, "wmesa: can't swap non-current window");
+ }
+}
+
+void WMesaShareLists(WMesaContext ctx_to_share, WMesaContext ctx)
+{
+ _mesa_share_state(&ctx->gl_ctx, &ctx_to_share->gl_ctx);
+}
+
diff --git a/mesalib/src/mesa/drivers/windows/gldirect/dglcontext.c b/mesalib/src/mesa/drivers/windows/gldirect/dglcontext.c
index 9aedd2e3c..bc4839cfe 100644
--- a/mesalib/src/mesa/drivers/windows/gldirect/dglcontext.c
+++ b/mesalib/src/mesa/drivers/windows/gldirect/dglcontext.c
@@ -1,2212 +1,2212 @@
-/****************************************************************************
-*
-* Mesa 3-D graphics library
-* Direct3D Driver Interface
-*
-* ========================================================================
-*
-* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
-*
-* Permission is hereby granted, free of charge, to any person obtaining a
-* copy of this software and associated documentation files (the "Software"),
-* to deal in the Software without restriction, including without limitation
-* the rights to use, copy, modify, merge, publish, distribute, sublicense,
-* and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included
-* in all copies or substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
-* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-* SOFTWARE.
-*
-* ======================================================================
-*
-* Language: ANSI C
-* Environment: Windows 9x (Win32)
-*
-* Description: Context handling.
-*
-****************************************************************************/
-
-#include "dglcontext.h"
-
-// Get compile errors without this. KeithH
-//#include "scitech.h" // ibool, etc.
-
-#ifdef _USE_GLD3_WGL
-#include "gld_driver.h"
-
-extern void _gld_mesa_warning(struct gl_context *, char *);
-extern void _gld_mesa_fatal(struct gl_context *, char *);
-#endif // _USE_GLD3_WGL
-
-// TODO: Clean out old DX6-specific code from GLD 2.x CAD driver
-// if it is no longer being built as part of GLDirect. (DaveM)
-
-// ***********************************************************************
-
-#define GLDERR_NONE 0
-#define GLDERR_MEM 1
-#define GLDERR_DDRAW 2
-#define GLDERR_D3D 3
-#define GLDERR_BPP 4
-
-char szResourceWarning[] =
-"GLDirect does not have enough video memory resources\n"
-"to support the requested OpenGL rendering context.\n\n"
-"You may have to reduce the current display resolution\n"
-"to obtain satisfactory OpenGL performance.\n";
-
-char szDDrawWarning[] =
-"GLDirect is unable to initialize DirectDraw for the\n"
-"requested OpenGL rendering context.\n\n"
-"You will have to check the DirectX control panel\n"
-"for further information.\n";
-
-char szD3DWarning[] =
-"GLDirect is unable to initialize Direct3D for the\n"
-"requested OpenGL rendering context.\n\n"
-"You may have to change the display mode resolution\n"
-"color depth or check the DirectX control panel for\n"
-"further information.\n";
-
-char szBPPWarning[] =
-"GLDirect is unable to use the selected color depth for\n"
-"the requested OpenGL rendering context.\n\n"
-"You will have to change the display mode resolution\n"
-"color depth with the Display Settings control panel.\n";
-
-int nContextError = GLDERR_NONE;
-
-// ***********************************************************************
-
-#define VENDORID_ATI 0x1002
-
-static DWORD devATIRagePro[] = {
- 0x4742, // 3D RAGE PRO BGA AGP 1X/2X
- 0x4744, // 3D RAGE PRO BGA AGP 1X only
- 0x4749, // 3D RAGE PRO BGA PCI 33 MHz
- 0x4750, // 3D RAGE PRO PQFP PCI 33 MHz
- 0x4751, // 3D RAGE PRO PQFP PCI 33 MHz limited 3D
- 0x4C42, // 3D RAGE LT PRO BGA-312 AGP 133 MHz
- 0x4C44, // 3D RAGE LT PRO BGA-312 AGP 66 MHz
- 0x4C49, // 3D RAGE LT PRO BGA-312 PCI 33 MHz
- 0x4C50, // 3D RAGE LT PRO BGA-256 PCI 33 MHz
- 0x4C51, // 3D RAGE LT PRO BGA-256 PCI 33 MHz limited 3D
-};
-
-static DWORD devATIRageIIplus[] = {
- 0x4755, // 3D RAGE II+
- 0x4756, // 3D RAGE IIC PQFP PCI
- 0x4757, // 3D RAGE IIC BGA AGP
- 0x475A, // 3D RAGE IIC PQFP AGP
- 0x4C47, // 3D RAGE LT-G
-};
-
-// ***********************************************************************
-
-#ifndef _USE_GLD3_WGL
-extern DGL_mesaFuncs mesaFuncs;
-#endif
-
-extern DWORD dwLogging;
-
-#ifdef GLD_THREADS
-#pragma message("compiling DGLCONTEXT.C vars for multi-threaded support")
-CRITICAL_SECTION CriticalSection; // for serialized access
-DWORD dwTLSCurrentContext = 0xFFFFFFFF; // TLS index for current context
-DWORD dwTLSPixelFormat = 0xFFFFFFFF; // TLS index for current pixel format
-#endif
-HGLRC iCurrentContext = 0; // Index of current context (static)
-BOOL bContextReady = FALSE; // Context state ready ?
-
-DGL_ctx ctxlist[DGL_MAX_CONTEXTS]; // Context list
-
-// ***********************************************************************
-
-static BOOL bHaveWin95 = FALSE;
-static BOOL bHaveWinNT = FALSE;
-static BOOL bHaveWin2K = FALSE;
-
-/****************************************************************************
-REMARKS:
-Detect the installed OS type.
-****************************************************************************/
-static void DetectOS(void)
-{
- OSVERSIONINFO VersionInformation;
- LPOSVERSIONINFO lpVersionInformation = &VersionInformation;
-
- VersionInformation.dwOSVersionInfoSize = sizeof(VersionInformation);
-
- GetVersionEx(lpVersionInformation);
-
- switch (VersionInformation.dwPlatformId) {
- case VER_PLATFORM_WIN32_WINDOWS:
- bHaveWin95 = TRUE;
- bHaveWinNT = FALSE;
- bHaveWin2K = FALSE;
- break;
- case VER_PLATFORM_WIN32_NT:
- bHaveWin95 = FALSE;
- if (VersionInformation.dwMajorVersion <= 4) {
- bHaveWinNT = TRUE;
- bHaveWin2K = FALSE;
- }
- else {
- bHaveWinNT = FALSE;
- bHaveWin2K = TRUE;
- }
- break;
- case VER_PLATFORM_WIN32s:
- bHaveWin95 = FALSE;
- bHaveWinNT = FALSE;
- bHaveWin2K = FALSE;
- break;
- }
-}
-
-// ***********************************************************************
-
-HWND hWndEvent = NULL; // event monitor window
-HWND hWndLastActive = NULL; // last active client window
-LONG __stdcall GLD_EventWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
-
-// ***********************************************************************
-
-// Checks if the HGLRC is valid in range of context list.
-BOOL dglIsValidContext(
- HGLRC a)
-{
- return ((int)a > 0 && (int)a <= DGL_MAX_CONTEXTS);
-}
-
-// ***********************************************************************
-
-// Convert a HGLRC to a pointer into the context list.
-DGL_ctx* dglGetContextAddress(
- const HGLRC a)
-{
- if (dglIsValidContext(a))
- return &ctxlist[(int)a-1];
- return NULL;
-}
-
-// ***********************************************************************
-
-// Return the current HGLRC (however it may be stored for multi-threading).
-HGLRC dglGetCurrentContext(void)
-{
-#ifdef GLD_THREADS
- HGLRC hGLRC;
- // load from thread-specific instance
- if (glb.bMultiThreaded) {
- // protect against calls from arbitrary threads
- __try {
- hGLRC = (HGLRC)TlsGetValue(dwTLSCurrentContext);
- }
- __except(EXCEPTION_EXECUTE_HANDLER) {
- hGLRC = iCurrentContext;
- }
- }
- // load from global static var
- else {
- hGLRC = iCurrentContext;
- }
- return hGLRC;
-#else
- return iCurrentContext;
-#endif
-}
-
-// ***********************************************************************
-
-// Set the current HGLRC (however it may be stored for multi-threading).
-void dglSetCurrentContext(HGLRC hGLRC)
-{
-#ifdef GLD_THREADS
- // store in thread-specific instance
- if (glb.bMultiThreaded) {
- // protect against calls from arbitrary threads
- __try {
- TlsSetValue(dwTLSCurrentContext, (LPVOID)hGLRC);
- }
- __except(EXCEPTION_EXECUTE_HANDLER) {
- iCurrentContext = hGLRC;
- }
- }
- // store in global static var
- else {
- iCurrentContext = hGLRC;
- }
-#else
- iCurrentContext = hGLRC;
-#endif
-}
-
-// ***********************************************************************
-
-// Return the current HDC only for a currently active HGLRC.
-HDC dglGetCurrentDC(void)
-{
- HGLRC hGLRC;
- DGL_ctx* lpCtx;
-
- hGLRC = dglGetCurrentContext();
- if (hGLRC) {
- lpCtx = dglGetContextAddress(hGLRC);
- return lpCtx->hDC;
- }
- return 0;
-}
-
-// ***********************************************************************
-
-void dglInitContextState()
-{
- int i;
- WNDCLASS wc;
-
-#ifdef GLD_THREADS
- // Allocate thread local storage indexes for current context and pixel format
- dwTLSCurrentContext = TlsAlloc();
- dwTLSPixelFormat = TlsAlloc();
-#endif
-
- dglSetCurrentContext(NULL); // No current rendering context
-
- // Clear all context data
- ZeroMemory(ctxlist, sizeof(ctxlist[0]) * DGL_MAX_CONTEXTS);
-
- for (i=0; i<DGL_MAX_CONTEXTS; i++)
- ctxlist[i].bAllocated = FALSE; // Flag context as unused
-
- // This section of code crashes the dll in circumstances where the app
- // creates and destroys contexts.
-/*
- // Register the class for our event monitor window
- wc.style = 0;
- wc.lpfnWndProc = GLD_EventWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = GetModuleHandle(NULL);
- wc.hIcon = LoadIcon(GetModuleHandle(NULL), IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "GLDIRECT";
- RegisterClass(&wc);
-
- // Create the non-visible window to monitor all broadcast messages
- hWndEvent = CreateWindowEx(
- WS_EX_TOOLWINDOW,"GLDIRECT","GLDIRECT",WS_POPUP,
- 0,0,0,0,
- NULL,NULL,GetModuleHandle(NULL),NULL);
-*/
-
-#ifdef GLD_THREADS
- // Create a critical section object for serializing access to
- // DirectDraw and DDStereo create/destroy functions in multiple threads
- if (glb.bMultiThreaded)
- InitializeCriticalSection(&CriticalSection);
-#endif
-
- // Context state is now initialized and ready
- bContextReady = TRUE;
-}
-
-// ***********************************************************************
-
-void dglDeleteContextState()
-{
- int i;
- static BOOL bOnceIsEnough = FALSE;
-
- // Only call once, from either DGL_exitDriver(), or DLL_PROCESS_DETACH
- if (bOnceIsEnough)
- return;
- bOnceIsEnough = TRUE;
-
- for (i=0; i<DGL_MAX_CONTEXTS; i++) {
- if (ctxlist[i].bAllocated == TRUE) {
- ddlogPrintf(DDLOG_WARN, "** Context %i not deleted - cleaning up.", (i+1));
- dglDeleteContext((HGLRC)(i+1));
- }
- }
-
- // Context state is no longer ready
- bContextReady = FALSE;
-
- // If executed when DLL unloads, DDraw objects may be invalid.
- // So catch any page faults with this exception handler.
-__try {
-
- // Release final DirectDraw interfaces
- if (glb.bDirectDrawPersistant) {
-// RELEASE(glb.lpGlobalPalette);
-// RELEASE(glb.lpDepth4);
-// RELEASE(glb.lpBack4);
-// RELEASE(glb.lpPrimary4);
-// RELEASE(glb.lpDD4);
- }
-}
-__except(EXCEPTION_EXECUTE_HANDLER) {
- ddlogPrintf(DDLOG_WARN, "Exception raised in dglDeleteContextState.");
-}
-
- // Destroy our event monitor window
- if (hWndEvent) {
- DestroyWindow(hWndEvent);
- hWndEvent = hWndLastActive = NULL;
- }
-
-#ifdef GLD_THREADS
- // Destroy the critical section object
- if (glb.bMultiThreaded)
- DeleteCriticalSection(&CriticalSection);
-
- // Release thread local storage indexes for current HGLRC and pixel format
- TlsFree(dwTLSPixelFormat);
- TlsFree(dwTLSCurrentContext);
-#endif
-}
-
-// ***********************************************************************
-
-// Application Window message handler interception
-static LONG __stdcall dglWndProc(
- HWND hwnd,
- UINT msg,
- WPARAM wParam,
- LPARAM lParam)
-{
- DGL_ctx* lpCtx = NULL;
- LONG lpfnWndProc = 0L;
- int i;
- HGLRC hGLRC;
- RECT rect;
- PAINTSTRUCT ps;
- BOOL bQuit = FALSE;
- BOOL bMain = FALSE;
- LONG rc;
-
- // Get the window's message handler *before* it is unhooked in WM_DESTROY
-
- // Is this the main window?
- if (hwnd == glb.hWndActive) {
- bMain = TRUE;
- lpfnWndProc = glb.lpfnWndProc;
- }
- // Search for DGL context matching window handle
- for (i=0; i<DGL_MAX_CONTEXTS; i++) {
- if (ctxlist[i].hWnd == hwnd) {
- lpCtx = &ctxlist[i];
- lpfnWndProc = lpCtx->lpfnWndProc;
- break;
- }
- }
- // Not one of ours...
- if (!lpfnWndProc)
- return DefWindowProc(hwnd, msg, wParam, lParam);
-
- // Intercept messages amd process *before* passing on to window
- switch (msg) {
-#ifdef _USE_GLD3_WGL
- case WM_DISPLAYCHANGE:
- glb.bPixelformatsDirty = TRUE;
- break;
-#endif
- case WM_ACTIVATEAPP:
- glb.bAppActive = (BOOL)wParam;
- ddlogPrintf(DDLOG_INFO, "Calling app has been %s", glb.bAppActive ? "activated" : "de-activated");
- break;
- case WM_ERASEBKGND:
- // Eat the GDI erase event for the GL window
- if (!lpCtx || !lpCtx->bHasBeenCurrent)
- break;
- lpCtx->bGDIEraseBkgnd = TRUE;
- return TRUE;
- case WM_PAINT:
- // Eat the invalidated update region if render scene is in progress
- if (!lpCtx || !lpCtx->bHasBeenCurrent)
- break;
- if (lpCtx->bFrameStarted) {
- if (GetUpdateRect(hwnd, &rect, FALSE)) {
- BeginPaint(hwnd, &ps);
- EndPaint(hwnd, &ps);
- ValidateRect(hwnd, &rect);
- return TRUE;
- }
- }
- break;
- }
- // Call the appropriate window message handler
- rc = CallWindowProc((WNDPROC)lpfnWndProc, hwnd, msg, wParam, lParam);
-
- // Intercept messages and process *after* passing on to window
- switch (msg) {
- case WM_QUIT:
- case WM_DESTROY:
- bQuit = TRUE;
- if (lpCtx && lpCtx->bAllocated) {
- ddlogPrintf(DDLOG_WARN, "WM_DESTROY detected for HWND=%X, HDC=%X, HGLRC=%d", hwnd, lpCtx->hDC, i+1);
- dglDeleteContext((HGLRC)(i+1));
- }
- break;
-#if 0
- case WM_SIZE:
- // Resize surfaces to fit window but not viewport (in case app did not bother)
- if (!lpCtx || !lpCtx->bHasBeenCurrent)
- break;
- w = LOWORD(lParam);
- h = HIWORD(lParam);
- if (lpCtx->dwWidth < w || lpCtx->dwHeight < h) {
- if (!dglWglResizeBuffers(lpCtx->glCtx, TRUE))
- dglWglResizeBuffers(lpCtx->glCtx, FALSE);
- }
- break;
-#endif
- }
-
- // If the main window is quitting, then so should we...
- if (bMain && bQuit) {
- ddlogPrintf(DDLOG_SYSTEM, "shutting down after WM_DESTROY detected for main HWND=%X", hwnd);
- dglDeleteContextState();
- dglExitDriver();
- }
-
- return rc;
-}
-
-// ***********************************************************************
-
-// Driver Window message handler
-static LONG __stdcall GLD_EventWndProc(
- HWND hwnd,
- UINT msg,
- WPARAM wParam,
- LPARAM lParam)
-{
- switch (msg) {
- // May be sent by splash screen dialog on exit
- case WM_ACTIVATE:
- if (LOWORD(wParam) == WA_ACTIVE && glb.hWndActive) {
- SetForegroundWindow(glb.hWndActive);
- return 0;
- }
- break;
- }
- return DefWindowProc(hwnd, msg, wParam, lParam);
-}
-
-// ***********************************************************************
-
-// Intercepted Keyboard handler for detecting hot keys.
-LRESULT CALLBACK dglKeyProc(
- int code,
- WPARAM wParam,
- LPARAM lParam)
-{
- HWND hWnd, hWndFrame;
- HGLRC hGLRC = NULL;
- DGL_ctx* lpCtx = NULL;
- int cmd = 0, dx1 = 0, dx2 = 0, i;
- static BOOL bAltPressed = FALSE;
- static BOOL bCtrlPressed = FALSE;
- static BOOL bShiftPressed = FALSE;
- RECT r, rf, rc;
- POINT pt;
- BOOL bForceReshape = FALSE;
-
- return CallNextHookEx(hKeyHook, code, wParam, lParam);
-}
-
-// ***********************************************************************
-
-HWND hWndMatch;
-
-// Window handle enumeration procedure.
-BOOL CALLBACK dglEnumChildProc(
- HWND hWnd,
- LPARAM lParam)
-{
- RECT rect;
-
- // Find window handle with matching client rect.
- GetClientRect(hWnd, &rect);
- if (EqualRect(&rect, (RECT*)lParam)) {
- hWndMatch = hWnd;
- return FALSE;
- }
- // Continue with next child window.
- return TRUE;
-}
-
-// ***********************************************************************
-
-// Find window handle with matching client rect.
-HWND dglFindWindowRect(
- RECT* pRect)
-{
- hWndMatch = NULL;
- EnumChildWindows(GetForegroundWindow(), dglEnumChildProc, (LPARAM)pRect);
- return hWndMatch;
-}
-
-// ***********************************************************************
-#ifndef _USE_GLD3_WGL
-void dglChooseDisplayMode(
- DGL_ctx *lpCtx)
-{
- // Note: Choose an exact match if possible.
-
- int i;
- DWORD area;
- DWORD bestarea;
- DDSURFACEDESC2 *lpDDSD = NULL; // Mode list pointer
- DDSURFACEDESC2 *lpBestDDSD = NULL; // Pointer to best
-
- lpDDSD = glb.lpDisplayModes;
- for (i=0; i<glb.nDisplayModeCount; i++, lpDDSD++) {
- if ((lpDDSD->dwWidth == lpCtx->dwWidth) &&
- (lpDDSD->dwHeight == lpCtx->dwHeight))
- goto matched; // Mode has been exactly matched
- // Choose modes that are larger in both dimensions than
- // the window, but smaller in area than the current best.
- if ( (lpDDSD->dwWidth >= lpCtx->dwWidth) &&
- (lpDDSD->dwHeight >= lpCtx->dwHeight))
- {
- if (lpBestDDSD == NULL) {
- lpBestDDSD = lpDDSD;
- bestarea = lpDDSD->dwWidth * lpDDSD->dwHeight;
- continue;
- }
- area = lpDDSD->dwWidth * lpDDSD->dwHeight;
- if (area < bestarea) {
- lpBestDDSD = lpDDSD;
- bestarea = area;
- }
- }
- }
-
- // Safety check
- if (lpBestDDSD == NULL) {
- ddlogMessage(DDLOG_CRITICAL, "dglChooseDisplayMode");
- return;
- }
-
- lpCtx->dwModeWidth = lpBestDDSD->dwWidth;
- lpCtx->dwModeHeight = lpBestDDSD->dwHeight;
-matched:
- ddlogPrintf(DDLOG_INFO, "Matched (%ldx%ld) to (%ldx%ld)",
- lpCtx->dwWidth, lpCtx->dwHeight, lpCtx->dwModeWidth, lpCtx->dwModeHeight);
-}
-#endif // _USE_GLD3_WGL
-// ***********************************************************************
-
-static BOOL IsDevice(
- DWORD *lpDeviceIdList,
- DWORD dwDeviceId,
- int count)
-{
- int i;
-
- for (i=0; i<count; i++)
- if (dwDeviceId == lpDeviceIdList[i])
- return TRUE;
-
- return FALSE;
-}
-
-// ***********************************************************************
-
-void dglTestForBrokenCards(
- DGL_ctx *lpCtx)
-{
-#ifndef _GLD3
- DDDEVICEIDENTIFIER dddi; // DX6 device identifier
-
- // Sanity check.
- if (lpCtx == NULL) {
- // Testing for broken cards is sensitive area, so we don't want
- // anything saying "broken cards" in the error message. ;)
- ddlogMessage(DDLOG_ERROR, "Null context passed to TFBC\n");
- return;
- }
-
- if (lpCtx->lpDD4 == NULL) {
- // Testing for broken cards is sensitive area, so we don't want
- // anything saying "broken cards" in the error message. ;)
- ddlogMessage(DDLOG_ERROR, "Null DD4 passed to TFBC\n");
- return;
- }
-
- // Microsoft really fucked up with the GetDeviceIdentifier function
- // on Windows 2000, since it locks up on stock driers on the CD. Updated
- // drivers from vendors appear to work, but we can't identify the drivers
- // without this function!!! For now we skip these tests on Windows 2000.
- if ((GetVersion() & 0x80000000UL) == 0)
- return;
-
- // Obtain device info
- if (FAILED(IDirectDraw4_GetDeviceIdentifier(lpCtx->lpDD4, &dddi, 0)))
- return;
-
- // Useful info. Log it.
- ddlogPrintf(DDLOG_INFO, "DirectDraw: VendorId=0x%x, DeviceId=0x%x", dddi.dwVendorId, dddi.dwDeviceId);
-
- // Vendor 1: ATI
- if (dddi.dwVendorId == VENDORID_ATI) {
- // Test A: ATI Rage PRO
- if (IsDevice(devATIRagePro, dddi.dwDeviceId, sizeof(devATIRagePro)))
- glb.bUseMipmaps = FALSE;
- // Test B: ATI Rage II+
- if (IsDevice(devATIRageIIplus, dddi.dwDeviceId, sizeof(devATIRageIIplus)))
- glb.bEmulateAlphaTest = TRUE;
- }
-
- // Vendor 2: Matrox
- if (dddi.dwVendorId == 0x102B) {
- // Test: Matrox G400 stencil buffer support does not work for AutoCAD
- if (dddi.dwDeviceId == 0x0525) {
- lpCtx->lpPF->pfd.cStencilBits = 0;
- if (lpCtx->lpPF->iZBufferPF != -1) {
- glb.lpZBufferPF[lpCtx->lpPF->iZBufferPF].dwStencilBitDepth = 0;
- glb.lpZBufferPF[lpCtx->lpPF->iZBufferPF].dwStencilBitMask = 0;
- glb.lpZBufferPF[lpCtx->lpPF->iZBufferPF].dwFlags &= ~DDPF_STENCILBUFFER;
- }
- }
- }
-#endif // _GLD3
-}
-
-// ***********************************************************************
-
-BOOL dglCreateContextBuffers(
- HDC a,
- DGL_ctx *lpCtx,
- BOOL bFallback)
-{
- HRESULT hResult;
-
- int i;
-// HGLRC hGLRC;
-// DGL_ctx* lpCtx;
-
-#ifndef _USE_GLD3_WGL
- DWORD dwFlags;
- DDSURFACEDESC2 ddsd2;
- DDSCAPS2 ddscaps2;
- LPDIRECTDRAWCLIPPER lpddClipper;
- D3DDEVICEDESC D3DHWDevDesc; // Direct3D Hardware description
- D3DDEVICEDESC D3DHELDevDesc; // Direct3D Hardware Emulation Layer
-#endif // _USE_GLD3_WGL
-
- float inv_aspect;
-
- GLenum bDoubleBuffer; // TRUE if double buffer required
- GLenum bDepthBuffer; // TRUE if depth buffer required
-
- const PIXELFORMATDESCRIPTOR *lpPFD = &lpCtx->lpPF->pfd;
-
- // Vars for Mesa visual
- DWORD dwDepthBits = 0;
- DWORD dwStencilBits = 0;
- DWORD dwAlphaBits = 0;
- DWORD bAlphaSW = GL_FALSE;
- DWORD bDouble = GL_FALSE;
-
- DDSURFACEDESC2 ddsd2DisplayMode;
- BOOL bFullScrnWin = FALSE; // fullscreen-size window ?
- DDBLTFX ddbltfx;
- DWORD dwMemoryType = (bFallback) ? DDSCAPS_SYSTEMMEMORY : glb.dwMemoryType;
- BOOL bBogusWindow = FALSE; // non-drawable window ?
- DWORD dwColorRef = 0; // GDI background color
- RECT rcDst; // GDI window rect
- POINT pt; // GDI window point
-
- // Palette used for creating default global palette
- PALETTEENTRY ppe[256];
-
-#ifndef _USE_GLD3_WGL
- // Vertex buffer description. Used for creation of vertex buffers
- D3DVERTEXBUFFERDESC vbufdesc;
-#endif // _USE_GLD3_WGL
-
-#define DDLOG_CRITICAL_OR_WARN (bFallback ? DDLOG_CRITICAL : DDLOG_WARN)
-
- ddlogPrintf(DDLOG_SYSTEM, "dglCreateContextBuffers for HDC=%X", a);
- nContextError = GLDERR_NONE;
-
-#ifdef GLD_THREADS
- // Serialize access to DirectDraw object creation or DDS start
- if (glb.bMultiThreaded)
- EnterCriticalSection(&CriticalSection);
-#endif
-
- // Check for back buffer
- bDoubleBuffer = GL_TRUE; //(lpPFD->dwFlags & PFD_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE;
- // Since we always do back buffering, check if we emulate front buffering
- lpCtx->EmulateSingle =
- (lpPFD->dwFlags & PFD_DOUBLEBUFFER) ? FALSE : TRUE;
-#if 0 // Don't have to mimic MS OpenGL behavior for front-buffering (DaveM)
- lpCtx->EmulateSingle |=
- (lpPFD->dwFlags & PFD_SUPPORT_GDI) ? TRUE : FALSE;
-#endif
-
- // Check for depth buffer
- bDepthBuffer = (lpPFD->cDepthBits) ? GL_TRUE : GL_FALSE;
-
- lpCtx->bDoubleBuffer = bDoubleBuffer;
- lpCtx->bDepthBuffer = bDepthBuffer;
-
- // Set the Fullscreen flag for the context.
-// lpCtx->bFullscreen = glb.bFullscreen;
-
- // Obtain the dimensions of the rendering window
- lpCtx->hDC = a; // Cache DC
- lpCtx->hWnd = WindowFromDC(lpCtx->hDC);
- // Check for non-window DC = memory DC ?
- if (lpCtx->hWnd == NULL) {
- // bitmap memory contexts are always single-buffered
- lpCtx->EmulateSingle = TRUE;
- bBogusWindow = TRUE;
- ddlogPrintf(DDLOG_INFO, "Non-Window Memory Device Context");
- if (GetClipBox(lpCtx->hDC, &lpCtx->rcScreenRect) == ERROR) {
- ddlogMessage(DDLOG_WARN, "GetClipBox failed in dglCreateContext\n");
- SetRect(&lpCtx->rcScreenRect, 0, 0, 0, 0);
- }
- }
- else if (!GetClientRect(lpCtx->hWnd, &lpCtx->rcScreenRect)) {
- bBogusWindow = TRUE;
- ddlogMessage(DDLOG_WARN, "GetClientRect failed in dglCreateContext\n");
- SetRect(&lpCtx->rcScreenRect, 0, 0, 0, 0);
- }
- lpCtx->dwWidth = lpCtx->rcScreenRect.right - lpCtx->rcScreenRect.left;
- lpCtx->dwHeight = lpCtx->rcScreenRect.bottom - lpCtx->rcScreenRect.top;
-
- ddlogPrintf(DDLOG_INFO, "Input window %X: w=%i, h=%i",
- lpCtx->hWnd, lpCtx->dwWidth, lpCtx->dwHeight);
-
- // What if app only zeroes one dimension instead of both? (DaveM)
- if ( (lpCtx->dwWidth == 0) || (lpCtx->dwHeight == 0) ) {
- // Make the buffer size something sensible
- lpCtx->dwWidth = 8;
- lpCtx->dwHeight = 8;
- }
-
- // Set defaults
- lpCtx->dwModeWidth = lpCtx->dwWidth;
- lpCtx->dwModeHeight = lpCtx->dwHeight;
-/*
- // Find best display mode for fullscreen
- if (glb.bFullscreen || !glb.bPrimary) {
- dglChooseDisplayMode(lpCtx);
- }
-*/
- // Misc initialisation
- lpCtx->bCanRender = FALSE; // No rendering allowed yet
- lpCtx->bSceneStarted = FALSE;
- lpCtx->bFrameStarted = FALSE;
-
- // Detect OS (specifically 'Windows 2000' or 'Windows XP')
- DetectOS();
-
- // NOTE: WinNT not supported
- ddlogPrintf(DDLOG_INFO, "OS: %s", bHaveWin95 ? "Win9x" : (bHaveWin2K ? "Win2000/XP" : "Unsupported") );
-
- // Test for Fullscreen
- if (bHaveWin95) { // Problems with fullscreen on Win2K/XP
- if ((GetSystemMetrics(SM_CXSCREEN) == lpCtx->dwWidth) &&
- (GetSystemMetrics(SM_CYSCREEN) == lpCtx->dwHeight))
- {
- // Workaround for some apps that crash when going fullscreen.
- //lpCtx->bFullscreen = TRUE;
- }
-
- }
-
-#ifdef _USE_GLD3_WGL
- _gldDriver.CreateDrawable(lpCtx, glb.bDirectDrawPersistant, glb.bPersistantBuffers);
-#else
- // Check if DirectDraw has already been created by original GLRC (DaveM)
- if (glb.bDirectDrawPersistant && glb.bDirectDraw) {
- lpCtx->lpDD4 = glb.lpDD4;
- IDirectDraw4_AddRef(lpCtx->lpDD4);
- goto SkipDirectDrawCreate;
- }
-
- // Create DirectDraw object
- if (glb.bPrimary)
- hResult = DirectDrawCreate(NULL, &lpCtx->lpDD1, NULL);
- else {
- // A non-primary device is to be used.
- // Force context to be Fullscreen, secondary adaptors can not
- // be used in a window.
- hResult = DirectDrawCreate(&glb.ddGuid, &lpCtx->lpDD1, NULL);
- lpCtx->bFullscreen = TRUE;
- }
- if (FAILED(hResult)) {
- MessageBox(NULL, "Unable to initialize DirectDraw", "GLDirect", MB_OK);
- ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to create DirectDraw interface", hResult);
- nContextError = GLDERR_DDRAW;
- goto return_with_error;
- }
-
- // Query for DX6 IDirectDraw4.
- hResult = IDirectDraw_QueryInterface(lpCtx->lpDD1,
- &IID_IDirectDraw4,
- (void**)&lpCtx->lpDD4);
- if (FAILED(hResult)) {
- MessageBox(NULL, "GLDirect requires DirectX 6.0 or above", "GLDirect", MB_OK);
- ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to create DirectDraw4 interface", hResult);
- nContextError = GLDERR_DDRAW;
- goto return_with_error;
- }
-
- // Cache DirectDraw interface for subsequent GLRCs
- if (glb.bDirectDrawPersistant && !glb.bDirectDraw) {
- glb.lpDD4 = lpCtx->lpDD4;
- IDirectDraw4_AddRef(glb.lpDD4);
- glb.bDirectDraw = TRUE;
- }
-SkipDirectDrawCreate:
-
- // Now we have a DD4 interface we can check for broken cards
- dglTestForBrokenCards(lpCtx);
-
- // Test if primary device can use flipping instead of blitting
- ZeroMemory(&ddsd2DisplayMode, sizeof(ddsd2DisplayMode));
- ddsd2DisplayMode.dwSize = sizeof(ddsd2DisplayMode);
- hResult = IDirectDraw4_GetDisplayMode(
- lpCtx->lpDD4,
- &ddsd2DisplayMode);
- if (SUCCEEDED(hResult)) {
- if ( (lpCtx->dwWidth == ddsd2DisplayMode.dwWidth) &&
- (lpCtx->dwHeight == ddsd2DisplayMode.dwHeight) ) {
- // We have a fullscreen-size window
- bFullScrnWin = TRUE;
- // OK to use DirectDraw fullscreen mode ?
- if (glb.bPrimary && !glb.bFullscreenBlit && !lpCtx->EmulateSingle && !glb.bDirectDrawPersistant) {
- lpCtx->bFullscreen = TRUE;
- ddlogMessage(DDLOG_INFO, "Primary upgraded to page flipping.\n");
- }
- }
- // Cache the display mode dimensions
- lpCtx->dwModeWidth = ddsd2DisplayMode.dwWidth;
- lpCtx->dwModeHeight = ddsd2DisplayMode.dwHeight;
- }
-
- // Clamp the effective window dimensions to primary surface.
- // We need to do this for D3D viewport dimensions even if wide
- // surfaces are supported. This also is a good idea for handling
- // whacked-out window dimensions passed for non-drawable windows
- // like Solid Edge. (DaveM)
- if (lpCtx->dwWidth > ddsd2DisplayMode.dwWidth)
- lpCtx->dwWidth = ddsd2DisplayMode.dwWidth;
- if (lpCtx->dwHeight > ddsd2DisplayMode.dwHeight)
- lpCtx->dwHeight = ddsd2DisplayMode.dwHeight;
-
- // Check for non-RGB desktop resolution
- if (!lpCtx->bFullscreen && ddsd2DisplayMode.ddpfPixelFormat.dwRGBBitCount <= 8) {
- ddlogPrintf(DDLOG_CRITICAL_OR_WARN, "Desktop color depth %d bpp not supported",
- ddsd2DisplayMode.ddpfPixelFormat.dwRGBBitCount);
- nContextError = GLDERR_BPP;
- goto return_with_error;
- }
-#endif // _USE_GLD3_WGL
-
- ddlogPrintf(DDLOG_INFO, "Window: w=%i, h=%i (%s)",
- lpCtx->dwWidth,
- lpCtx->dwHeight,
- lpCtx->bFullscreen ? "fullscreen" : "windowed");
-
-#ifndef _USE_GLD3_WGL
- // Obtain ddraw caps
- ZeroMemory(&lpCtx->ddCaps, sizeof(DDCAPS));
- lpCtx->ddCaps.dwSize = sizeof(DDCAPS);
- if (glb.bHardware) {
- // Get HAL caps
- IDirectDraw4_GetCaps(lpCtx->lpDD4, &lpCtx->ddCaps, NULL);
- } else {
- // Get HEL caps
- IDirectDraw4_GetCaps(lpCtx->lpDD4, NULL, &lpCtx->ddCaps);
- }
-
- // If this flag is present then we can't default to Mesa
- // SW rendering between BeginScene() and EndScene().
- if (lpCtx->ddCaps.dwCaps2 & DDCAPS2_NO2DDURING3DSCENE) {
- ddlogMessage(DDLOG_INFO,
- "Warning : No 2D allowed during 3D scene.\n");
- }
-
- // Query for DX6 Direct3D3 interface
- hResult = IDirectDraw4_QueryInterface(lpCtx->lpDD4,
- &IID_IDirect3D3,
- (void**)&lpCtx->lpD3D3);
- if (FAILED(hResult)) {
- MessageBox(NULL, "Unable to initialize Direct3D", "GLDirect", MB_OK);
- ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D interface", hResult);
- nContextError = GLDERR_D3D;
- goto return_with_error;
- }
-
- // Context creation
- if (lpCtx->bFullscreen) {
- // FULLSCREEN
-
- // Disable warning popups when in fullscreen mode
- ddlogWarnOption(FALSE);
-
- // Have to release persistant primary surface if fullscreen mode
- if (glb.bDirectDrawPersistant && glb.bDirectDrawPrimary) {
- RELEASE(glb.lpPrimary4);
- glb.bDirectDrawPrimary = FALSE;
- }
-
- dwFlags = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT;
- if (glb.bFastFPU)
- dwFlags |= DDSCL_FPUSETUP; // fast FPU setup optional (DaveM)
- hResult = IDirectDraw4_SetCooperativeLevel(lpCtx->lpDD4, lpCtx->hWnd, dwFlags);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to set Exclusive Fullscreen mode", hResult);
- goto return_with_error;
- }
-
- hResult = IDirectDraw4_SetDisplayMode(lpCtx->lpDD4,
- lpCtx->dwModeWidth,
- lpCtx->dwModeHeight,
- lpPFD->cColorBits,
- 0,
- 0);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "SetDisplayMode failed", hResult);
- goto return_with_error;
- }
-
- // ** The display mode has changed, so dont use MessageBox! **
-
- ZeroMemory(&ddsd2, sizeof(ddsd2));
- ddsd2.dwSize = sizeof(ddsd2);
-
- if (bDoubleBuffer) {
- // Double buffered
- // Primary surface
- ddsd2.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
- ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
- DDSCAPS_FLIP |
- DDSCAPS_COMPLEX |
- DDSCAPS_3DDEVICE |
- dwMemoryType;
- ddsd2.dwBackBufferCount = 1;
-
- hResult = IDirectDraw4_CreateSurface(lpCtx->lpDD4, &ddsd2, &lpCtx->lpFront4, NULL);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateSurface (primary) failed", hResult);
- nContextError = GLDERR_MEM;
- goto return_with_error;
- }
-
- // Render target surface
- ZeroMemory(&ddscaps2, sizeof(ddscaps2)); // Clear the entire struct.
- ddscaps2.dwCaps = DDSCAPS_BACKBUFFER;
- hResult = IDirectDrawSurface4_GetAttachedSurface(lpCtx->lpFront4, &ddscaps2, &lpCtx->lpBack4);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "GetAttachedSurface failed", hResult);
- nContextError = GLDERR_MEM;
- goto return_with_error;
- }
- } else {
- // Single buffered
- // Primary surface
- ddsd2.dwFlags = DDSD_CAPS;
- ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
- //DDSCAPS_3DDEVICE |
- dwMemoryType;
-
- hResult = IDirectDraw4_CreateSurface(lpCtx->lpDD4, &ddsd2, &lpCtx->lpFront4, NULL);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateSurface (primary) failed", hResult);
- nContextError = GLDERR_MEM;
- goto return_with_error;
- }
-
- lpCtx->lpBack4 = NULL;
- }
- } else {
- // WINDOWED
-
- // OK to enable warning popups in windowed mode
- ddlogWarnOption(glb.bMessageBoxWarnings);
-
- dwFlags = DDSCL_NORMAL;
- if (glb.bMultiThreaded)
- dwFlags |= DDSCL_MULTITHREADED;
- if (glb.bFastFPU)
- dwFlags |= DDSCL_FPUSETUP; // fast FPU setup optional (DaveM)
- hResult = IDirectDraw4_SetCooperativeLevel(lpCtx->lpDD4,
- lpCtx->hWnd,
- dwFlags);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to set Normal coop level", hResult);
- goto return_with_error;
- }
- // Has Primary surface already been created for original GLRC ?
- // Note this can only be applicable for windowed modes
- if (glb.bDirectDrawPersistant && glb.bDirectDrawPrimary) {
- lpCtx->lpFront4 = glb.lpPrimary4;
- IDirectDrawSurface4_AddRef(lpCtx->lpFront4);
- // Update the window on the default clipper
- IDirectDrawSurface4_GetClipper(lpCtx->lpFront4, &lpddClipper);
- IDirectDrawClipper_SetHWnd(lpddClipper, 0, lpCtx->hWnd);
- IDirectDrawClipper_Release(lpddClipper);
- goto SkipPrimaryCreate;
- }
-
- // Primary surface
- ZeroMemory(&ddsd2, sizeof(ddsd2));
- ddsd2.dwSize = sizeof(ddsd2);
- ddsd2.dwFlags = DDSD_CAPS;
- ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
- hResult = IDirectDraw4_CreateSurface(lpCtx->lpDD4, &ddsd2, &lpCtx->lpFront4, NULL);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateSurface (primary) failed", hResult);
- nContextError = GLDERR_MEM;
- goto return_with_error;
- }
-
- // Cache Primary surface for subsequent GLRCs
- // Note this can only be applicable to subsequent windowed modes
- if (glb.bDirectDrawPersistant && !glb.bDirectDrawPrimary) {
- glb.lpPrimary4 = lpCtx->lpFront4;
- IDirectDrawSurface4_AddRef(glb.lpPrimary4);
- glb.bDirectDrawPrimary = TRUE;
- }
-
- // Clipper object
- hResult = DirectDrawCreateClipper(0, &lpddClipper, NULL);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateClipper failed", hResult);
- goto return_with_error;
- }
- hResult = IDirectDrawClipper_SetHWnd(lpddClipper, 0, lpCtx->hWnd);
- if (FAILED(hResult)) {
- RELEASE(lpddClipper);
- ddlogError(DDLOG_CRITICAL_OR_WARN, "SetHWnd failed", hResult);
- goto return_with_error;
- }
- hResult = IDirectDrawSurface4_SetClipper(lpCtx->lpFront4, lpddClipper);
- RELEASE(lpddClipper); // We have finished with it.
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "SetClipper failed", hResult);
- goto return_with_error;
- }
-SkipPrimaryCreate:
-
- if (bDoubleBuffer) {
- // Render target surface
- ZeroMemory(&ddsd2, sizeof(ddsd2));
- ddsd2.dwSize = sizeof(ddsd2);
- ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
- ddsd2.dwWidth = lpCtx->dwWidth;
- ddsd2.dwHeight = lpCtx->dwHeight;
- ddsd2.ddsCaps.dwCaps = DDSCAPS_3DDEVICE |
- DDSCAPS_OFFSCREENPLAIN |
- dwMemoryType;
-
- // Reserve the entire desktop size for persistant buffers option
- if (glb.bDirectDrawPersistant && glb.bPersistantBuffers) {
- ddsd2.dwWidth = ddsd2DisplayMode.dwWidth;
- ddsd2.dwHeight = ddsd2DisplayMode.dwHeight;
- }
- // Re-use original back buffer if persistant buffers exist
- if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && glb.lpBack4)
- hResult = IDirectDrawSurface4_AddRef(lpCtx->lpBack4 = glb.lpBack4);
- else
- hResult = IDirectDraw4_CreateSurface(lpCtx->lpDD4, &ddsd2, &lpCtx->lpBack4, NULL);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "Create Backbuffer failed", hResult);
- nContextError = GLDERR_MEM;
- goto return_with_error;
- }
- if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && !glb.lpBack4)
- IDirectDrawSurface4_AddRef(glb.lpBack4 = lpCtx->lpBack4);
- } else {
- lpCtx->lpBack4 = NULL;
- }
- }
-
- //
- // Now create the Z-buffer
- //
- lpCtx->bStencil = FALSE; // Default to no stencil buffer
- if (bDepthBuffer && (lpCtx->lpPF->iZBufferPF != -1)) {
- // Get z-buffer dimensions from the render target
- // Setup the surface desc for the z-buffer.
- ZeroMemory(&ddsd2, sizeof(ddsd2));
- ddsd2.dwSize = sizeof(ddsd2);
- ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
- ddsd2.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | dwMemoryType;
- ddsd2.dwWidth = lpCtx->dwWidth;
- ddsd2.dwHeight = lpCtx->dwHeight;
- memcpy(&ddsd2.ddpfPixelFormat,
- &glb.lpZBufferPF[lpCtx->lpPF->iZBufferPF],
- sizeof(DDPIXELFORMAT) );
-
- // Reserve the entire desktop size for persistant buffers option
- if (glb.bDirectDrawPersistant && glb.bPersistantBuffers) {
- ddsd2.dwWidth = ddsd2DisplayMode.dwWidth;
- ddsd2.dwHeight = ddsd2DisplayMode.dwHeight;
- }
-
- // Create a z-buffer
- if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && glb.lpDepth4)
- hResult = IDirectDrawSurface4_AddRef(lpCtx->lpDepth4 = glb.lpDepth4);
- else
- hResult = IDirectDraw4_CreateSurface(lpCtx->lpDD4, &ddsd2, &lpCtx->lpDepth4, NULL);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateSurface (ZBuffer) failed", hResult);
- nContextError = GLDERR_MEM;
- goto return_with_error;
- }
- if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && !glb.lpDepth4)
- IDirectDrawSurface4_AddRef(glb.lpDepth4 = lpCtx->lpDepth4);
- else if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && glb.lpDepth4 && glb.lpBack4)
- IDirectDrawSurface4_DeleteAttachedSurface(glb.lpBack4, 0, glb.lpDepth4);
-
- // Attach Zbuffer to render target
- TRY(IDirectDrawSurface4_AddAttachedSurface(
- bDoubleBuffer ? lpCtx->lpBack4 : lpCtx->lpFront4,
- lpCtx->lpDepth4),
- "dglCreateContext: Attach Zbuffer");
- if (glb.lpZBufferPF[lpCtx->lpPF->iZBufferPF].dwFlags & DDPF_STENCILBUFFER) {
- lpCtx->bStencil = TRUE;
- ddlogMessage(DDLOG_INFO, "Depth buffer has stencil\n");
- }
- }
-
- // Clear all back buffers and Z-buffers in case of memory recycling.
- ZeroMemory(&ddbltfx, sizeof(ddbltfx));
- ddbltfx.dwSize = sizeof(ddbltfx);
- IDirectDrawSurface4_Blt(lpCtx->lpBack4, NULL, NULL, NULL,
- DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
- if (lpCtx->lpDepth4)
- IDirectDrawSurface4_Blt(lpCtx->lpDepth4, NULL, NULL, NULL,
- DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
-
- // Now that we have a Z-buffer we can create the 3D device
- hResult = IDirect3D3_CreateDevice(lpCtx->lpD3D3,
- &glb.d3dGuid,
- bDoubleBuffer ? lpCtx->lpBack4 : lpCtx->lpFront4,
- &lpCtx->lpDev3,
- NULL);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D device", hResult);
- nContextError = GLDERR_D3D;
- goto return_with_error;
- }
-
- // We must do this as soon as the device is created
- dglInitStateCaches(lpCtx);
-
- // Obtain the D3D Device Description
- D3DHWDevDesc.dwSize = D3DHELDevDesc.dwSize = sizeof(D3DDEVICEDESC);
- TRY(IDirect3DDevice3_GetCaps(lpCtx->lpDev3,
- &D3DHWDevDesc,
- &D3DHELDevDesc),
- "dglCreateContext: GetCaps failed");
-
- // Choose the relevant description and cache it in the context.
- // We will use this description later for caps checking
- memcpy( &lpCtx->D3DDevDesc,
- glb.bHardware ? &D3DHWDevDesc : &D3DHELDevDesc,
- sizeof(D3DDEVICEDESC));
-
- // Now we can examine the texture formats
- if (!dglBuildTextureFormatList(lpCtx->lpDev3)) {
- ddlogMessage(DDLOG_CRITICAL_OR_WARN, "dglBuildTextureFormatList failed\n");
- goto return_with_error;
- }
-
- // Get the pixel format of the back buffer
- lpCtx->ddpfRender.dwSize = sizeof(lpCtx->ddpfRender);
- if (bDoubleBuffer)
- hResult = IDirectDrawSurface4_GetPixelFormat(
- lpCtx->lpBack4,
- &lpCtx->ddpfRender);
- else
- hResult = IDirectDrawSurface4_GetPixelFormat(
- lpCtx->lpFront4,
- &lpCtx->ddpfRender);
-
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "GetPixelFormat failed", hResult);
- goto return_with_error;
- }
- // Find a pixel packing function suitable for this surface
- pxClassifyPixelFormat(&lpCtx->ddpfRender,
- &lpCtx->fnPackFunc,
- &lpCtx->fnUnpackFunc,
- &lpCtx->fnPackSpanFunc);
-
- // Viewport
- hResult = IDirect3D3_CreateViewport(lpCtx->lpD3D3, &lpCtx->lpViewport3, NULL);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateViewport failed", hResult);
- goto return_with_error;
- }
-
- hResult = IDirect3DDevice3_AddViewport(lpCtx->lpDev3, lpCtx->lpViewport3);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "AddViewport failed", hResult);
- goto return_with_error;
- }
-
- // Initialise the viewport
- // Note screen coordinates are used for viewport clipping since D3D
- // transform operations are not used in the GLD CAD driver. (DaveM)
- inv_aspect = (float)lpCtx->dwHeight/(float)lpCtx->dwWidth;
-
- lpCtx->d3dViewport.dwSize = sizeof(lpCtx->d3dViewport);
- lpCtx->d3dViewport.dwX = 0;
- lpCtx->d3dViewport.dwY = 0;
- lpCtx->d3dViewport.dwWidth = lpCtx->dwWidth;
- lpCtx->d3dViewport.dwHeight = lpCtx->dwHeight;
- lpCtx->d3dViewport.dvClipX = 0; // -1.0f;
- lpCtx->d3dViewport.dvClipY = 0; // inv_aspect;
- lpCtx->d3dViewport.dvClipWidth = lpCtx->dwWidth; // 2.0f;
- lpCtx->d3dViewport.dvClipHeight = lpCtx->dwHeight; // 2.0f * inv_aspect;
- lpCtx->d3dViewport.dvMinZ = 0.0f;
- lpCtx->d3dViewport.dvMaxZ = 1.0f;
- TRY(IDirect3DViewport3_SetViewport2(lpCtx->lpViewport3, &lpCtx->d3dViewport), "dglCreateContext: SetViewport2");
-
- hResult = IDirect3DDevice3_SetCurrentViewport(lpCtx->lpDev3, lpCtx->lpViewport3);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "SetCurrentViewport failed", hResult);
- goto return_with_error;
- }
-
- lpCtx->dwBPP = lpPFD->cColorBits;
- lpCtx->iZBufferPF = lpCtx->lpPF->iZBufferPF;
-
- // Set last texture to NULL
- for (i=0; i<MAX_TEXTURE_UNITS; i++) {
- lpCtx->ColorOp[i] = D3DTOP_DISABLE;
- lpCtx->AlphaOp[i] = D3DTOP_DISABLE;
- lpCtx->tObj[i] = NULL;
- }
-
- // Default to perspective correct texture mapping
- dglSetRenderState(lpCtx, D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE, "TexturePersp");
-
- // Set the default culling mode
- lpCtx->cullmode = D3DCULL_NONE;
- dglSetRenderState(lpCtx, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE, "CullMode");
-
- // Disable specular
- dglSetRenderState(lpCtx, D3DRENDERSTATE_SPECULARENABLE, FALSE, "SpecularEnable");
- // Disable subpixel correction
-// dglSetRenderState(lpCtx, D3DRENDERSTATE_SUBPIXEL, FALSE, "SubpixelEnable");
- // Disable dithering
- dglSetRenderState(lpCtx, D3DRENDERSTATE_DITHERENABLE, FALSE, "DitherEnable");
-
- // Initialise the primitive caches
-// lpCtx->dwNextLineVert = 0;
-// lpCtx->dwNextTriVert = 0;
-
- // Init the global texture palette
- lpCtx->lpGlobalPalette = NULL;
-
- // Init the HW/SW usage counters
-// lpCtx->dwHWUsageCount = lpCtx->dwSWUsageCount = 0L;
-
- //
- // Create two D3D vertex buffers.
- // One will hold the pre-transformed data with the other one
- // being used to hold the post-transformed & clipped verts.
- //
-#if 0 // never used (DaveM)
- vbufdesc.dwSize = sizeof(D3DVERTEXBUFFERDESC);
- vbufdesc.dwCaps = D3DVBCAPS_WRITEONLY;
- if (glb.bHardware == FALSE)
- vbufdesc.dwCaps = D3DVBCAPS_SYSTEMMEMORY;
- vbufdesc.dwNumVertices = 32768; // For the time being
-
- // Source vertex buffer
- vbufdesc.dwFVF = DGL_LVERTEX;
- hResult = IDirect3D3_CreateVertexBuffer(lpCtx->lpD3D3, &vbufdesc, &lpCtx->m_vbuf, 0, NULL);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateVertexBuffer(src) failed", hResult);
- goto return_with_error;
- }
-
- // Destination vertex buffer
- vbufdesc.dwFVF = (glb.bMultitexture == FALSE) ? D3DFVF_TLVERTEX : (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX2);
- hResult = IDirect3D3_CreateVertexBuffer(lpCtx->lpD3D3, &vbufdesc, &lpCtx->m_pvbuf, 0, NULL);
- if(FAILED(hResult)) {
- ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateVertexBuffer(dst) failed", hResult);
- goto return_with_error;
- }
-#endif
-
-#endif _USE_GLD3_WGL
-
- //
- // Now create the Mesa context
- //
-
- // Create the Mesa visual
- if (lpPFD->cDepthBits)
- dwDepthBits = 16;
- if (lpPFD->cStencilBits)
- dwStencilBits = 8;
- if (lpPFD->cAlphaBits) {
- dwAlphaBits = 8;
- bAlphaSW = GL_TRUE;
- }
- if (lpPFD->dwFlags & PFD_DOUBLEBUFFER)
- bDouble = GL_TRUE;
-// lpCtx->EmulateSingle =
-// (lpPFD->dwFlags & PFD_DOUBLEBUFFER) ? FALSE : TRUE;
-
-#ifdef _USE_GLD3_WGL
- lpCtx->glVis = _mesa_create_visual(
- bDouble, /* double buffer */
- GL_FALSE, // stereo
- lpPFD->cRedBits,
- lpPFD->cGreenBits,
- lpPFD->cBlueBits,
- dwAlphaBits,
- dwDepthBits,
- dwStencilBits,
- lpPFD->cAccumRedBits, // accum bits
- lpPFD->cAccumGreenBits, // accum bits
- lpPFD->cAccumBlueBits, // accum bits
- lpPFD->cAccumAlphaBits, // accum alpha bits
- 1 // num samples
- );
-#else // _USE_GLD3_WGL
- lpCtx->glVis = (*mesaFuncs.gl_create_visual)(
- GL_TRUE, // RGB mode
- bAlphaSW, // Is an alpha buffer required?
- bDouble, // Is an double-buffering required?
- GL_FALSE, // stereo
- dwDepthBits, // depth_size
- dwStencilBits, // stencil_size
- lpPFD->cAccumBits, // accum_size
- 0, // colour-index bits
- lpPFD->cRedBits, // Red bit count
- lpPFD->cGreenBits, // Green bit count
- lpPFD->cBlueBits, // Blue bit count
- dwAlphaBits // Alpha bit count
- );
-#endif // _USE_GLD3_WGL
-
- if (lpCtx->glVis == NULL) {
- ddlogMessage(DDLOG_CRITICAL_OR_WARN, "gl_create_visual failed\n");
- goto return_with_error;
- }
-
-#ifdef _USE_GLD3_WGL
- lpCtx->glCtx = _mesa_create_context(API_OPENGL, lpCtx->glVis, NULL, (void *)lpCtx, GL_TRUE);
-#else
- // Create the Mesa context
- lpCtx->glCtx = (*mesaFuncs.gl_create_context)(
- lpCtx->glVis, // Mesa visual
- NULL, // share list context
- (void *)lpCtx, // Pointer to our driver context
- GL_TRUE // Direct context flag
- );
-#endif // _USE_GLD3_WGL
-
- if (lpCtx->glCtx == NULL) {
- ddlogMessage(DDLOG_CRITICAL_OR_WARN, "gl_create_context failed\n");
- goto return_with_error;
- }
-
- // Create the Mesa framebuffer
-#ifdef _USE_GLD3_WGL
- lpCtx->glBuffer = _mesa_create_framebuffer(
- lpCtx->glVis,
- lpCtx->glVis->depthBits > 0,
- lpCtx->glVis->stencilBits > 0,
- lpCtx->glVis->accumRedBits > 0,
- GL_FALSE //swalpha
- );
-#else
- lpCtx->glBuffer = (*mesaFuncs.gl_create_framebuffer)(lpCtx->glVis);
-#endif // _USE_GLD3_WGL
-
- if (lpCtx->glBuffer == NULL) {
- ddlogMessage(DDLOG_CRITICAL_OR_WARN, "gl_create_framebuffer failed\n");
- goto return_with_error;
- }
-
-#ifdef _USE_GLD3_WGL
- // Init Mesa internals
- _swrast_CreateContext( lpCtx->glCtx );
- _vbo_CreateContext( lpCtx->glCtx );
- _tnl_CreateContext( lpCtx->glCtx );
- _swsetup_CreateContext( lpCtx->glCtx );
-
- _gldDriver.InitialiseMesa(lpCtx);
-
- lpCtx->glCtx->imports.warning = _gld_mesa_warning;
- lpCtx->glCtx->imports.fatal = _gld_mesa_fatal;
-
-#else
- // Tell Mesa how many texture stages we have
- glb.wMaxSimultaneousTextures = lpCtx->D3DDevDesc.wMaxSimultaneousTextures;
- // Only use as many Units as the spec requires
- if (glb.wMaxSimultaneousTextures > MAX_TEXTURE_UNITS)
- glb.wMaxSimultaneousTextures = MAX_TEXTURE_UNITS;
- lpCtx->glCtx->Const.MaxTextureUnits = glb.wMaxSimultaneousTextures;
- ddlogPrintf(DDLOG_INFO, "Texture stages : %d", glb.wMaxSimultaneousTextures);
-
- // Set the max texture size.
- // NOTE: clamped to a max of 1024 for extra performance!
- lpCtx->dwMaxTextureSize = (lpCtx->D3DDevDesc.dwMaxTextureWidth <= 1024) ? lpCtx->D3DDevDesc.dwMaxTextureWidth : 1024;
-
-// Texture resize takes place elsewhere. KH
-// NOTE: This was added to workaround an issue with the Intel app.
-#if 0
- lpCtx->glCtx->Const.MaxTextureSize = lpCtx->dwMaxTextureSize;
-#else
- lpCtx->glCtx->Const.MaxTextureSize = 1024;
-#endif
- lpCtx->glCtx->Const.MaxDrawBuffers = 1;
-
- // Setup the Display Driver pointers
- dglSetupDDPointers(lpCtx->glCtx);
-
- // Initialise all the Direct3D renderstates
- dglInitStateD3D(lpCtx->glCtx);
-
-#if 0
- // Signal a reload of texture state on next glBegin
- lpCtx->m_texHandleValid = FALSE;
- lpCtx->m_mtex = FALSE;
- lpCtx->m_texturing = FALSE;
-#else
- // Set default texture unit state
-// dglSetTexture(lpCtx, 0, NULL);
-// dglSetTexture(lpCtx, 1, NULL);
-#endif
-
- //
- // Set the global texture palette to default values.
- //
-
- // Clear the entire palette
- ZeroMemory(ppe, sizeof(PALETTEENTRY) * 256);
-
- // Fill the palette with a default colour.
- // A garish colour is used to catch bugs. Here Magenta is used.
- for (i=0; i < 256; i++) {
- ppe[i].peRed = 255;
- ppe[i].peGreen = 0;
- ppe[i].peBlue = 255;
- }
-
- RELEASE(lpCtx->lpGlobalPalette);
-
- if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && glb.lpGlobalPalette)
- hResult = IDirectDrawPalette_AddRef(lpCtx->lpGlobalPalette = glb.lpGlobalPalette);
- else
- hResult = IDirectDraw4_CreatePalette(
- lpCtx->lpDD4,
- DDPCAPS_INITIALIZE | DDPCAPS_8BIT | DDPCAPS_ALLOW256,
- ppe,
- &(lpCtx->lpGlobalPalette),
- NULL);
- if (FAILED(hResult)) {
- ddlogError(DDLOG_ERROR, "Default CreatePalette failed\n", hResult);
- lpCtx->lpGlobalPalette = NULL;
- goto return_with_error;
- }
- if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && !glb.lpGlobalPalette)
- IDirectDrawPalette_AddRef(glb.lpGlobalPalette = lpCtx->lpGlobalPalette);
-
-#endif // _USE_GLD3_WGL
-
- // ** If we have made it to here then we can enable rendering **
- lpCtx->bCanRender = TRUE;
-
-// ddlogMessage(DDLOG_SYSTEM, "dglCreateContextBuffers succeded\n");
-
-#ifdef GLD_THREADS
- // Release serialized access
- if (glb.bMultiThreaded)
- LeaveCriticalSection(&CriticalSection);
-#endif
-
- return TRUE;
-
-return_with_error:
- // Clean up before returning.
- // This is critical for secondary devices.
-
- lpCtx->bCanRender = FALSE;
-
-#ifdef _USE_GLD3_WGL
- // Destroy the Mesa context
- if (lpCtx->glBuffer)
- _mesa_destroy_framebuffer(lpCtx->glBuffer);
- if (lpCtx->glCtx)
- _mesa_destroy_context(lpCtx->glCtx);
- if (lpCtx->glVis)
- _mesa_destroy_visual(lpCtx->glVis);
-
- // Destroy driver data
- _gldDriver.DestroyDrawable(lpCtx);
-#else
- // Destroy the Mesa context
- if (lpCtx->glBuffer)
- (*mesaFuncs.gl_destroy_framebuffer)(lpCtx->glBuffer);
- if (lpCtx->glCtx)
- (*mesaFuncs.gl_destroy_context)(lpCtx->glCtx);
- if (lpCtx->glVis)
- (*mesaFuncs.gl_destroy_visual)(lpCtx->glVis);
-
- RELEASE(lpCtx->m_pvbuf); // Release D3D vertex buffer
- RELEASE(lpCtx->m_vbuf); // Release D3D vertex buffer
-
- if (lpCtx->lpViewport3) {
- if (lpCtx->lpDev3) IDirect3DDevice3_DeleteViewport(lpCtx->lpDev3, lpCtx->lpViewport3);
- RELEASE(lpCtx->lpViewport3);
- lpCtx->lpViewport3 = NULL;
- }
-
- RELEASE(lpCtx->lpDev3);
- if (lpCtx->lpDepth4) {
- if (lpCtx->lpBack4)
- IDirectDrawSurface4_DeleteAttachedSurface(lpCtx->lpBack4, 0L, lpCtx->lpDepth4);
- else
- IDirectDrawSurface4_DeleteAttachedSurface(lpCtx->lpFront4, 0L, lpCtx->lpDepth4);
- RELEASE(lpCtx->lpDepth4);
- lpCtx->lpDepth4 = NULL;
- }
- RELEASE(lpCtx->lpBack4);
- RELEASE(lpCtx->lpFront4);
- else
- if (lpCtx->bFullscreen) {
- IDirectDraw4_RestoreDisplayMode(lpCtx->lpDD4);
- IDirectDraw4_SetCooperativeLevel(lpCtx->lpDD4, NULL, DDSCL_NORMAL);
- }
- RELEASE(lpCtx->lpD3D3);
- RELEASE(lpCtx->lpDD4);
- RELEASE(lpCtx->lpDD1);
-#endif // _USE_GLD3_WGL
-
- lpCtx->bAllocated = FALSE;
-
-#ifdef GLD_THREADS
- // Release serialized access
- if (glb.bMultiThreaded)
- LeaveCriticalSection(&CriticalSection);
-#endif
-
- return FALSE;
-
-#undef DDLOG_CRITICAL_OR_WARN
-}
-
-// ***********************************************************************
-
-HGLRC dglCreateContext(
- HDC a,
- const DGL_pixelFormat *lpPF)
-{
- int i;
- HGLRC hGLRC;
- DGL_ctx* lpCtx;
- static BOOL bWarnOnce = TRUE;
- DWORD dwThreadId = GetCurrentThreadId();
- char szMsg[256];
- HWND hWnd;
- LONG lpfnWndProc;
-
- // Validate license
- if (!dglValidate())
- return NULL;
-
- // Is context state ready ?
- if (!bContextReady)
- return NULL;
-
- ddlogPrintf(DDLOG_SYSTEM, "dglCreateContext for HDC=%X, ThreadId=%X", a, dwThreadId);
-
- // Find next free context.
- // Also ensure that only one Fullscreen context is created at any one time.
- hGLRC = 0; // Default to Not Found
- for (i=0; i<DGL_MAX_CONTEXTS; i++) {
- if (ctxlist[i].bAllocated) {
- if (/*glb.bFullscreen && */ctxlist[i].bFullscreen)
- break;
- } else {
- hGLRC = (HGLRC)(i+1);
- break;
- }
- }
-
- // Bail if no GLRC was found
- if (!hGLRC)
- return NULL;
-
- // Set the context pointer
- lpCtx = dglGetContextAddress(hGLRC);
- // Make sure that context is zeroed before we do anything.
- // MFC and C++ apps call wglCreateContext() and wglDeleteContext() multiple times,
- // even though only one context is ever used by the app, so keep it clean. (DaveM)
- ZeroMemory(lpCtx, sizeof(DGL_ctx));
- lpCtx->bAllocated = TRUE;
- // Flag that buffers need creating on next wglMakeCurrent call.
- lpCtx->bHasBeenCurrent = FALSE;
- lpCtx->lpPF = (DGL_pixelFormat *)lpPF; // cache pixel format
- lpCtx->bCanRender = FALSE;
-
- // Create all the internal resources here, not in dglMakeCurrent().
- // We do a re-size check in dglMakeCurrent in case of re-allocations. (DaveM)
- // We now try context allocations twice, first with video memory,
- // then again with system memory. This is similar to technique
- // used for dglWglResizeBuffers(). (DaveM)
- if (lpCtx->bHasBeenCurrent == FALSE) {
- if (!dglCreateContextBuffers(a, lpCtx, FALSE)) {
- if (glb.bMessageBoxWarnings && bWarnOnce && dwLogging) {
- bWarnOnce = FALSE;
- switch (nContextError) {
- case GLDERR_DDRAW: strcpy(szMsg, szDDrawWarning); break;
- case GLDERR_D3D: strcpy(szMsg, szD3DWarning); break;
- case GLDERR_MEM: strcpy(szMsg, szResourceWarning); break;
- case GLDERR_BPP: strcpy(szMsg, szBPPWarning); break;
- default: strcpy(szMsg, "");
- }
- if (strlen(szMsg))
- MessageBox(NULL, szMsg, "GLDirect", MB_OK | MB_ICONWARNING);
- }
- // Only need to try again if memory error
- if (nContextError == GLDERR_MEM) {
- ddlogPrintf(DDLOG_WARN, "dglCreateContext failed 1st time with video memory");
- }
- else {
- ddlogPrintf(DDLOG_ERROR, "dglCreateContext failed");
- return NULL;
- }
- }
- }
-
- // Now that we have a hWnd, we can intercept the WindowProc.
- hWnd = lpCtx->hWnd;
- if (hWnd) {
- // Only hook individual window handler once if not hooked before.
- lpfnWndProc = GetWindowLong(hWnd, GWL_WNDPROC);
- if (lpfnWndProc != (LONG)dglWndProc) {
- lpCtx->lpfnWndProc = lpfnWndProc;
- SetWindowLong(hWnd, GWL_WNDPROC, (LONG)dglWndProc);
- }
- // Find the parent window of the app too.
- if (glb.hWndActive == NULL) {
- while (hWnd != NULL) {
- glb.hWndActive = hWnd;
- hWnd = GetParent(hWnd);
- }
- // Hook the parent window too.
- lpfnWndProc = GetWindowLong(glb.hWndActive, GWL_WNDPROC);
- if (glb.hWndActive == lpCtx->hWnd)
- glb.lpfnWndProc = lpCtx->lpfnWndProc;
- else if (lpfnWndProc != (LONG)dglWndProc)
- glb.lpfnWndProc = lpfnWndProc;
- if (glb.lpfnWndProc)
- SetWindowLong(glb.hWndActive, GWL_WNDPROC, (LONG)dglWndProc);
- }
- }
-
- ddlogPrintf(DDLOG_SYSTEM, "dglCreateContext succeeded for HGLRC=%d", (int)hGLRC);
-
- return hGLRC;
-}
-
-// ***********************************************************************
-// Make a DirectGL context current
-// Used by wgl functions and dgl functions
-BOOL dglMakeCurrent(
- HDC a,
- HGLRC b)
-{
- int context;
- DGL_ctx* lpCtx;
- HWND hWnd;
- BOOL bNeedResize = FALSE;
- BOOL bWindowChanged, bContextChanged;
- LPDIRECTDRAWCLIPPER lpddClipper;
- DWORD dwThreadId = GetCurrentThreadId();
- LONG lpfnWndProc;
-
- // Validate license
- if (!dglValidate())
- return FALSE;
-
- // Is context state ready ?
- if (!bContextReady)
- return FALSE;
-
- context = (int)b; // This is as a result of STRICT!
- ddlogPrintf(DDLOG_SYSTEM, "dglMakeCurrent: HDC=%X, HGLRC=%d, ThreadId=%X", a, context, dwThreadId);
-
- // If the HGLRC is NULL then make no context current;
- // Ditto if the HDC is NULL either. (DaveM)
- if (context == 0 || a == 0) {
- // Corresponding Mesa operation
-#ifdef _USE_GLD3_WGL
- _mesa_make_current(NULL, NULL);
-#else
- (*mesaFuncs.gl_make_current)(NULL, NULL);
-#endif
- dglSetCurrentContext(0);
- return TRUE;
- }
-
- // Make sure the HGLRC is in range
- if ((context > DGL_MAX_CONTEXTS) || (context < 0)) {
- ddlogMessage(DDLOG_ERROR, "dglMakeCurrent: HGLRC out of range\n");
- return FALSE;
- }
-
- // Find address of context and make sure that it has been allocated
- lpCtx = dglGetContextAddress(b);
- if (!lpCtx->bAllocated) {
- ddlogMessage(DDLOG_ERROR, "dglMakeCurrent: Context not allocated\n");
-// return FALSE;
- return TRUE; // HACK: Shuts up "WebLab Viewer Pro". KeithH
- }
-
-#ifdef GLD_THREADS
- // Serialize access to DirectDraw or DDS operations
- if (glb.bMultiThreaded)
- EnterCriticalSection(&CriticalSection);
-#endif
-
- // Check if window has changed
- hWnd = (a != lpCtx->hDC) ? WindowFromDC(a) : lpCtx->hWnd;
- bWindowChanged = (hWnd != lpCtx->hWnd) ? TRUE : FALSE;
- bContextChanged = (b != dglGetCurrentContext()) ? TRUE : FALSE;
-
- // If the window has changed, make sure the clipper is updated. (DaveM)
- if (glb.bDirectDrawPersistant && !lpCtx->bFullscreen && (bWindowChanged || bContextChanged)) {
- lpCtx->hWnd = hWnd;
-#ifndef _USE_GLD3_WGL
- IDirectDrawSurface4_GetClipper(lpCtx->lpFront4, &lpddClipper);
- IDirectDrawClipper_SetHWnd(lpddClipper, 0, lpCtx->hWnd);
- IDirectDrawClipper_Release(lpddClipper);
-#endif // _USE_GLD3_WGL
- }
-
- // Make sure hDC and hWnd is current. (DaveM)
- // Obtain the dimensions of the rendering window
- lpCtx->hDC = a; // Cache DC
- lpCtx->hWnd = hWnd;
- hWndLastActive = hWnd;
-
- // Check for non-window DC = memory DC ?
- if (hWnd == NULL) {
- if (GetClipBox(a, &lpCtx->rcScreenRect) == ERROR) {
- ddlogMessage(DDLOG_WARN, "GetClipBox failed in dglMakeCurrent\n");
- SetRect(&lpCtx->rcScreenRect, 0, 0, 0, 0);
- }
- }
- else if (!GetClientRect(lpCtx->hWnd, &lpCtx->rcScreenRect)) {
- ddlogMessage(DDLOG_WARN, "GetClientRect failed in dglMakeCurrent\n");
- SetRect(&lpCtx->rcScreenRect, 0, 0, 0, 0);
- }
- // Check if buffers need to be re-sized;
- // If so, wait until Mesa GL stuff is setup before re-sizing;
- if (lpCtx->dwWidth != lpCtx->rcScreenRect.right - lpCtx->rcScreenRect.left ||
- lpCtx->dwHeight != lpCtx->rcScreenRect.bottom - lpCtx->rcScreenRect.top)
- bNeedResize = TRUE;
-
- // Now we can update our globals
- dglSetCurrentContext(b);
-
- // Corresponding Mesa operation
-#ifdef _USE_GLD3_WGL
- _mesa_make_current(lpCtx->glCtx, lpCtx->glBuffer);
- lpCtx->glCtx->Driver.UpdateState(lpCtx->glCtx, _NEW_ALL);
- if (bNeedResize) {
- // Resize buffers (Note Mesa GL needs to be setup beforehand);
- // Resize Mesa internal buffer too via glViewport() command,
- // which subsequently calls dglWglResizeBuffers() too.
- lpCtx->glCtx->Driver.Viewport(lpCtx->glCtx, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
- lpCtx->bHasBeenCurrent = TRUE;
- }
-#else
- (*mesaFuncs.gl_make_current)(lpCtx->glCtx, lpCtx->glBuffer);
-
- dglSetupDDPointers(lpCtx->glCtx);
-
- // Insure DirectDraw surfaces fit current window DC
- if (bNeedResize) {
- // Resize buffers (Note Mesa GL needs to be setup beforehand);
- // Resize Mesa internal buffer too via glViewport() command,
- // which subsequently calls dglWglResizeBuffers() too.
- (*mesaFuncs.gl_Viewport)(lpCtx->glCtx, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
- lpCtx->bHasBeenCurrent = TRUE;
- }
-#endif // _USE_GLD3_WGL
- ddlogPrintf(DDLOG_SYSTEM, "dglMakeCurrent: width = %d, height = %d", lpCtx->dwWidth, lpCtx->dwHeight);
-
- // We have to clear D3D back buffer and render state if emulated front buffering
- // for different window (but not context) like in Solid Edge.
- if (glb.bDirectDrawPersistant && glb.bPersistantBuffers
- && (bWindowChanged /* || bContextChanged */) && lpCtx->EmulateSingle) {
-#ifdef _USE_GLD3_WGL
-// IDirect3DDevice8_EndScene(lpCtx->pDev);
-// lpCtx->bSceneStarted = FALSE;
- lpCtx->glCtx->Driver.Clear(lpCtx->glCtx, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
- GL_TRUE, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
-#else
- IDirect3DDevice3_EndScene(lpCtx->lpDev3);
- lpCtx->bSceneStarted = FALSE;
- dglClearD3D(lpCtx->glCtx, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
- GL_TRUE, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
-#endif // _USE_GLD3_WGL
- }
-
- // The first time we call MakeCurrent we set the initial viewport size
- if (lpCtx->bHasBeenCurrent == FALSE)
-#ifdef _USE_GLD3_WGL
- lpCtx->glCtx->Driver.Viewport(lpCtx->glCtx, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
-#else
- (*mesaFuncs.gl_Viewport)(lpCtx->glCtx, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
-#endif // _USE_GLD3_WGL
- lpCtx->bHasBeenCurrent = TRUE;
-
-#ifdef GLD_THREADS
- // Release serialized access
- if (glb.bMultiThreaded)
- LeaveCriticalSection(&CriticalSection);
-#endif
-
- return TRUE;
-}
-
-// ***********************************************************************
-
-BOOL dglDeleteContext(
- HGLRC a)
-{
- DGL_ctx* lpCtx;
- DWORD dwThreadId = GetCurrentThreadId();
- char argstr[256];
-
-#if 0 // We have enough trouble throwing exceptions as it is... (DaveM)
- // Validate license
- if (!dglValidate())
- return FALSE;
-#endif
-
- // Is context state ready ?
- if (!bContextReady)
- return FALSE;
-
- ddlogPrintf(DDLOG_SYSTEM, "dglDeleteContext: Deleting context HGLRC=%d, ThreadId=%X", (int)a, dwThreadId);
-
- // Make sure the HGLRC is in range
- if (((int) a> DGL_MAX_CONTEXTS) || ((int)a < 0)) {
- ddlogMessage(DDLOG_ERROR, "dglDeleteCurrent: HGLRC out of range\n");
- return FALSE;
- }
-
- // Make sure context is valid
- lpCtx = dglGetContextAddress(a);
- if (!lpCtx->bAllocated) {
- ddlogPrintf(DDLOG_WARN, "Tried to delete unallocated context HGLRC=%d", (int)a);
-// return FALSE;
- return TRUE; // HACK: Shuts up "WebLab Viewer Pro". KeithH
- }
-
- // Make sure context is de-activated
- if (a == dglGetCurrentContext()) {
- ddlogPrintf(DDLOG_WARN, "dglDeleteContext: context HGLRC=%d still active", (int)a);
- dglMakeCurrent(NULL, NULL);
- }
-
-#ifdef GLD_THREADS
- // Serialize access to DirectDraw or DDS operations
- if (glb.bMultiThreaded)
- EnterCriticalSection(&CriticalSection);
-#endif
-
- // We are about to destroy all Direct3D objects.
- // Therefore we must disable rendering
- lpCtx->bCanRender = FALSE;
-
- // This exception handler was installed to catch some
- // particularly nasty apps. Console apps that call exit()
- // fall into this catagory (i.e. Win32 Glut).
-
- // VC cannot successfully implement multiple exception handlers
- // if more than one exception occurs. Therefore reverting back to
- // single exception handler as Keith originally had it. (DaveM)
-
-#define WARN_MESSAGE(p) strcpy(argstr, (#p));
-#define SAFE_RELEASE(p) WARN_MESSAGE(p); RELEASE(p);
-
-__try {
-#ifdef _USE_GLD3_WGL
- WARN_MESSAGE(gl_destroy_framebuffer);
- if (lpCtx->glBuffer)
- _mesa_destroy_framebuffer(lpCtx->glBuffer);
- WARN_MESSAGE(gl_destroy_context);
- if (lpCtx->glCtx)
- _mesa_destroy_context(lpCtx->glCtx);
- WARN_MESSAGE(gl_destroy_visual);
- if (lpCtx->glVis)
- _mesa_destroy_visual(lpCtx->glVis);
-
- _gldDriver.DestroyDrawable(lpCtx);
-#else
- // Destroy the Mesa context
- WARN_MESSAGE(gl_destroy_framebuffer);
- if (lpCtx->glBuffer)
- (*mesaFuncs.gl_destroy_framebuffer)(lpCtx->glBuffer);
- WARN_MESSAGE(gl_destroy_context);
- if (lpCtx->glCtx)
- (*mesaFuncs.gl_destroy_context)(lpCtx->glCtx);
- WARN_MESSAGE(gl_destroy_visual);
- if (lpCtx->glVis)
- (*mesaFuncs.gl_destroy_visual)(lpCtx->glVis);
-
- SAFE_RELEASE(lpCtx->m_pvbuf); // release D3D vertex buffer
- SAFE_RELEASE(lpCtx->m_vbuf); // release D3D vertex buffer
-
- // Delete the global palette
- SAFE_RELEASE(lpCtx->lpGlobalPalette);
-
- // Clean up.
- if (lpCtx->lpViewport3) {
- if (lpCtx->lpDev3) IDirect3DDevice3_DeleteViewport(lpCtx->lpDev3, lpCtx->lpViewport3);
- SAFE_RELEASE(lpCtx->lpViewport3);
- lpCtx->lpViewport3 = NULL;
- }
-
- SAFE_RELEASE(lpCtx->lpDev3);
- if (lpCtx->lpDepth4) {
- if (lpCtx->lpBack4)
- IDirectDrawSurface4_DeleteAttachedSurface(lpCtx->lpBack4, 0L, lpCtx->lpDepth4);
- else
- IDirectDrawSurface4_DeleteAttachedSurface(lpCtx->lpFront4, 0L, lpCtx->lpDepth4);
- SAFE_RELEASE(lpCtx->lpDepth4);
- lpCtx->lpDepth4 = NULL;
- }
- SAFE_RELEASE(lpCtx->lpBack4);
- SAFE_RELEASE(lpCtx->lpFront4);
- if (lpCtx->bFullscreen) {
- IDirectDraw4_RestoreDisplayMode(lpCtx->lpDD4);
- IDirectDraw4_SetCooperativeLevel(lpCtx->lpDD4, NULL, DDSCL_NORMAL);
- }
- SAFE_RELEASE(lpCtx->lpD3D3);
- SAFE_RELEASE(lpCtx->lpDD4);
- SAFE_RELEASE(lpCtx->lpDD1);
-#endif // _ULSE_GLD3_WGL
-
-}
-__except(EXCEPTION_EXECUTE_HANDLER) {
- ddlogPrintf(DDLOG_WARN, "Exception raised in dglDeleteContext: %s", argstr);
-}
-
- // Restore the window message handler because this context may be used
- // again by another window with a *different* message handler. (DaveM)
- if (lpCtx->lpfnWndProc) {
- SetWindowLong(lpCtx->hWnd, GWL_WNDPROC, (LONG)lpCtx->lpfnWndProc);
- lpCtx->lpfnWndProc = (LONG)NULL;
- }
-
- lpCtx->bAllocated = FALSE; // This context is now free for use
-
-#ifdef GLD_THREADS
- // Release serialized access
- if (glb.bMultiThreaded)
- LeaveCriticalSection(&CriticalSection);
-#endif
-
- return TRUE;
-}
-
-// ***********************************************************************
-
-BOOL dglSwapBuffers(
- HDC hDC)
-{
- RECT rSrcRect; // Source rectangle
- RECT rDstRect; // Destination rectangle
- POINT pt;
- HRESULT hResult;
-
- DDBLTFX bltFX;
- DWORD dwBlitFlags;
- DDBLTFX *lpBltFX;
-
-// DWORD dwThreadId = GetCurrentThreadId();
- HGLRC hGLRC = dglGetCurrentContext();
- DGL_ctx *lpCtx = dglGetContextAddress(hGLRC);
- HWND hWnd;
-
- HDC hDCAux; // for memory DC
- int x,y,w,h; // for memory DC BitBlt
-
-#if 0 // Perhaps not a good idea. Called too often. KH
- // Validate license
- if (!dglValidate())
- return FALSE;
-#endif
-
- if (!lpCtx) {
- return TRUE; //FALSE; // No current context
- }
-
- if (!lpCtx->bCanRender) {
- // Don't return false else some apps will bail.
- return TRUE;
- }
-
- hWnd = lpCtx->hWnd;
- if (hDC != lpCtx->hDC) {
- ddlogPrintf(DDLOG_WARN, "dglSwapBuffers: HDC=%X does not match HDC=%X for HGLRC=%d", hDC, lpCtx->hDC, hGLRC);
- hWnd = WindowFromDC(hDC);
- }
-
-#ifndef _USE_GLD3_WGL
- // Ensure that the surfaces exist before we tell
- // the device to render to them.
- IDirectDraw4_RestoreAllSurfaces(lpCtx->lpDD4);
-
- // Make sure that the vertex caches have been emptied
-// dglStateChange(lpCtx);
-
- // Some OpenGL programs don't issue a glFinish - check for it here.
- if (lpCtx->bSceneStarted) {
- IDirect3DDevice3_EndScene(lpCtx->lpDev3);
- lpCtx->bSceneStarted = FALSE;
- }
-#endif
-
-#if 0
- // If the calling app is not active then we don't need to Blit/Flip.
- // We can therefore simply return TRUE.
- if (!glb.bAppActive)
- return TRUE;
- // Addendum: This is WRONG! We should bail if the app is *minimized*,
- // not merely if the app is just plain 'not active'.
- // KeithH, 27/May/2000.
-#endif
-
- // Check for non-window DC = memory DC ?
- if (hWnd == NULL) {
- if (GetClipBox(hDC, &rSrcRect) == ERROR)
- return TRUE;
- // Use GDI BitBlt instead from compatible DirectDraw DC
- x = rSrcRect.left;
- y = rSrcRect.top;
- w = rSrcRect.right - rSrcRect.left;
- h = rSrcRect.bottom - rSrcRect.top;
-
- // Ack. DX8 does not have a GetDC() function...
- // TODO: Defer to DX7 or DX9 drivers... (DaveM)
- return TRUE;
- }
-
- // Bail if window client region is not drawable, like in Solid Edge
- if (!IsWindow(hWnd) /* || !IsWindowVisible(hWnd) */ || !GetClientRect(hWnd, &rSrcRect))
- return TRUE;
-
-#ifdef GLD_THREADS
- // Serialize access to DirectDraw or DDS operations
- if (glb.bMultiThreaded)
- EnterCriticalSection(&CriticalSection);
-#endif
-
-#ifdef _USE_GLD3_WGL
- // Notify Mesa of impending swap, so Mesa can flush internal buffers.
- _mesa_notifySwapBuffers(lpCtx->glCtx);
- // Now perform driver buffer swap
- _gldDriver.SwapBuffers(lpCtx, hDC, hWnd);
-#else
- if (lpCtx->bFullscreen) {
- // Sync with retrace if required
- if (glb.bWaitForRetrace) {
- IDirectDraw4_WaitForVerticalBlank(
- lpCtx->lpDD4,
- DDWAITVB_BLOCKBEGIN,
- 0);
- }
-
- // Perform the fullscreen flip
- TRY(IDirectDrawSurface4_Flip(
- lpCtx->lpFront4,
- NULL,
- DDFLIP_WAIT),
- "dglSwapBuffers: Flip");
- } else {
- // Calculate current window position and size
- pt.x = pt.y = 0;
- ClientToScreen(hWnd, &pt);
- GetClientRect(hWnd, &rDstRect);
- if (rDstRect.right > lpCtx->dwModeWidth)
- rDstRect.right = lpCtx->dwModeWidth;
- if (rDstRect.bottom > lpCtx->dwModeHeight)
- rDstRect.bottom = lpCtx->dwModeHeight;
- OffsetRect(&rDstRect, pt.x, pt.y);
- rSrcRect.left = rSrcRect.top = 0;
- rSrcRect.right = lpCtx->dwWidth;
- rSrcRect.bottom = lpCtx->dwHeight;
- if (rSrcRect.right > lpCtx->dwModeWidth)
- rSrcRect.right = lpCtx->dwModeWidth;
- if (rSrcRect.bottom > lpCtx->dwModeHeight)
- rSrcRect.bottom = lpCtx->dwModeHeight;
-
- if (glb.bWaitForRetrace) {
- // Sync the blit to the vertical retrace
- ZeroMemory(&bltFX, sizeof(bltFX));
- bltFX.dwSize = sizeof(bltFX);
- bltFX.dwDDFX = DDBLTFX_NOTEARING;
- dwBlitFlags = DDBLT_WAIT | DDBLT_DDFX;
- lpBltFX = &bltFX;
- } else {
- dwBlitFlags = DDBLT_WAIT;
- lpBltFX = NULL;
- }
-
- // Perform the actual blit
- TRY(IDirectDrawSurface4_Blt(
- lpCtx->lpFront4,
- &rDstRect,
- lpCtx->lpBack4, // Blit source
- &rSrcRect,
- dwBlitFlags,
- lpBltFX),
- "dglSwapBuffers: Blt");
- }
-#endif // _USE_GLD3_WGL
-
-#ifdef GLD_THREADS
- // Release serialized access
- if (glb.bMultiThreaded)
- LeaveCriticalSection(&CriticalSection);
-#endif
-
- // TODO: Re-instate rendering bitmap snapshot feature??? (DaveM)
-
- // Render frame is completed
- ValidateRect(hWnd, NULL);
- lpCtx->bFrameStarted = FALSE;
-
- return TRUE;
-}
-
-// ***********************************************************************
+/****************************************************************************
+*
+* Mesa 3-D graphics library
+* Direct3D Driver Interface
+*
+* ========================================================================
+*
+* Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+* SOFTWARE.
+*
+* ======================================================================
+*
+* Language: ANSI C
+* Environment: Windows 9x (Win32)
+*
+* Description: Context handling.
+*
+****************************************************************************/
+
+#include "dglcontext.h"
+
+// Get compile errors without this. KeithH
+//#include "scitech.h" // ibool, etc.
+
+#ifdef _USE_GLD3_WGL
+#include "gld_driver.h"
+
+extern void _gld_mesa_warning(struct gl_context *, char *);
+extern void _gld_mesa_fatal(struct gl_context *, char *);
+#endif // _USE_GLD3_WGL
+
+// TODO: Clean out old DX6-specific code from GLD 2.x CAD driver
+// if it is no longer being built as part of GLDirect. (DaveM)
+
+// ***********************************************************************
+
+#define GLDERR_NONE 0
+#define GLDERR_MEM 1
+#define GLDERR_DDRAW 2
+#define GLDERR_D3D 3
+#define GLDERR_BPP 4
+
+char szResourceWarning[] =
+"GLDirect does not have enough video memory resources\n"
+"to support the requested OpenGL rendering context.\n\n"
+"You may have to reduce the current display resolution\n"
+"to obtain satisfactory OpenGL performance.\n";
+
+char szDDrawWarning[] =
+"GLDirect is unable to initialize DirectDraw for the\n"
+"requested OpenGL rendering context.\n\n"
+"You will have to check the DirectX control panel\n"
+"for further information.\n";
+
+char szD3DWarning[] =
+"GLDirect is unable to initialize Direct3D for the\n"
+"requested OpenGL rendering context.\n\n"
+"You may have to change the display mode resolution\n"
+"color depth or check the DirectX control panel for\n"
+"further information.\n";
+
+char szBPPWarning[] =
+"GLDirect is unable to use the selected color depth for\n"
+"the requested OpenGL rendering context.\n\n"
+"You will have to change the display mode resolution\n"
+"color depth with the Display Settings control panel.\n";
+
+int nContextError = GLDERR_NONE;
+
+// ***********************************************************************
+
+#define VENDORID_ATI 0x1002
+
+static DWORD devATIRagePro[] = {
+ 0x4742, // 3D RAGE PRO BGA AGP 1X/2X
+ 0x4744, // 3D RAGE PRO BGA AGP 1X only
+ 0x4749, // 3D RAGE PRO BGA PCI 33 MHz
+ 0x4750, // 3D RAGE PRO PQFP PCI 33 MHz
+ 0x4751, // 3D RAGE PRO PQFP PCI 33 MHz limited 3D
+ 0x4C42, // 3D RAGE LT PRO BGA-312 AGP 133 MHz
+ 0x4C44, // 3D RAGE LT PRO BGA-312 AGP 66 MHz
+ 0x4C49, // 3D RAGE LT PRO BGA-312 PCI 33 MHz
+ 0x4C50, // 3D RAGE LT PRO BGA-256 PCI 33 MHz
+ 0x4C51, // 3D RAGE LT PRO BGA-256 PCI 33 MHz limited 3D
+};
+
+static DWORD devATIRageIIplus[] = {
+ 0x4755, // 3D RAGE II+
+ 0x4756, // 3D RAGE IIC PQFP PCI
+ 0x4757, // 3D RAGE IIC BGA AGP
+ 0x475A, // 3D RAGE IIC PQFP AGP
+ 0x4C47, // 3D RAGE LT-G
+};
+
+// ***********************************************************************
+
+#ifndef _USE_GLD3_WGL
+extern DGL_mesaFuncs mesaFuncs;
+#endif
+
+extern DWORD dwLogging;
+
+#ifdef GLD_THREADS
+#pragma message("compiling DGLCONTEXT.C vars for multi-threaded support")
+CRITICAL_SECTION CriticalSection; // for serialized access
+DWORD dwTLSCurrentContext = 0xFFFFFFFF; // TLS index for current context
+DWORD dwTLSPixelFormat = 0xFFFFFFFF; // TLS index for current pixel format
+#endif
+HGLRC iCurrentContext = 0; // Index of current context (static)
+BOOL bContextReady = FALSE; // Context state ready ?
+
+DGL_ctx ctxlist[DGL_MAX_CONTEXTS]; // Context list
+
+// ***********************************************************************
+
+static BOOL bHaveWin95 = FALSE;
+static BOOL bHaveWinNT = FALSE;
+static BOOL bHaveWin2K = FALSE;
+
+/****************************************************************************
+REMARKS:
+Detect the installed OS type.
+****************************************************************************/
+static void DetectOS(void)
+{
+ OSVERSIONINFO VersionInformation;
+ LPOSVERSIONINFO lpVersionInformation = &VersionInformation;
+
+ VersionInformation.dwOSVersionInfoSize = sizeof(VersionInformation);
+
+ GetVersionEx(lpVersionInformation);
+
+ switch (VersionInformation.dwPlatformId) {
+ case VER_PLATFORM_WIN32_WINDOWS:
+ bHaveWin95 = TRUE;
+ bHaveWinNT = FALSE;
+ bHaveWin2K = FALSE;
+ break;
+ case VER_PLATFORM_WIN32_NT:
+ bHaveWin95 = FALSE;
+ if (VersionInformation.dwMajorVersion <= 4) {
+ bHaveWinNT = TRUE;
+ bHaveWin2K = FALSE;
+ }
+ else {
+ bHaveWinNT = FALSE;
+ bHaveWin2K = TRUE;
+ }
+ break;
+ case VER_PLATFORM_WIN32s:
+ bHaveWin95 = FALSE;
+ bHaveWinNT = FALSE;
+ bHaveWin2K = FALSE;
+ break;
+ }
+}
+
+// ***********************************************************************
+
+HWND hWndEvent = NULL; // event monitor window
+HWND hWndLastActive = NULL; // last active client window
+LONG __stdcall GLD_EventWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
+
+// ***********************************************************************
+
+// Checks if the HGLRC is valid in range of context list.
+BOOL dglIsValidContext(
+ HGLRC a)
+{
+ return ((int)a > 0 && (int)a <= DGL_MAX_CONTEXTS);
+}
+
+// ***********************************************************************
+
+// Convert a HGLRC to a pointer into the context list.
+DGL_ctx* dglGetContextAddress(
+ const HGLRC a)
+{
+ if (dglIsValidContext(a))
+ return &ctxlist[(int)a-1];
+ return NULL;
+}
+
+// ***********************************************************************
+
+// Return the current HGLRC (however it may be stored for multi-threading).
+HGLRC dglGetCurrentContext(void)
+{
+#ifdef GLD_THREADS
+ HGLRC hGLRC;
+ // load from thread-specific instance
+ if (glb.bMultiThreaded) {
+ // protect against calls from arbitrary threads
+ __try {
+ hGLRC = (HGLRC)TlsGetValue(dwTLSCurrentContext);
+ }
+ __except(EXCEPTION_EXECUTE_HANDLER) {
+ hGLRC = iCurrentContext;
+ }
+ }
+ // load from global static var
+ else {
+ hGLRC = iCurrentContext;
+ }
+ return hGLRC;
+#else
+ return iCurrentContext;
+#endif
+}
+
+// ***********************************************************************
+
+// Set the current HGLRC (however it may be stored for multi-threading).
+void dglSetCurrentContext(HGLRC hGLRC)
+{
+#ifdef GLD_THREADS
+ // store in thread-specific instance
+ if (glb.bMultiThreaded) {
+ // protect against calls from arbitrary threads
+ __try {
+ TlsSetValue(dwTLSCurrentContext, (LPVOID)hGLRC);
+ }
+ __except(EXCEPTION_EXECUTE_HANDLER) {
+ iCurrentContext = hGLRC;
+ }
+ }
+ // store in global static var
+ else {
+ iCurrentContext = hGLRC;
+ }
+#else
+ iCurrentContext = hGLRC;
+#endif
+}
+
+// ***********************************************************************
+
+// Return the current HDC only for a currently active HGLRC.
+HDC dglGetCurrentDC(void)
+{
+ HGLRC hGLRC;
+ DGL_ctx* lpCtx;
+
+ hGLRC = dglGetCurrentContext();
+ if (hGLRC) {
+ lpCtx = dglGetContextAddress(hGLRC);
+ return lpCtx->hDC;
+ }
+ return 0;
+}
+
+// ***********************************************************************
+
+void dglInitContextState()
+{
+ int i;
+ WNDCLASS wc;
+
+#ifdef GLD_THREADS
+ // Allocate thread local storage indexes for current context and pixel format
+ dwTLSCurrentContext = TlsAlloc();
+ dwTLSPixelFormat = TlsAlloc();
+#endif
+
+ dglSetCurrentContext(NULL); // No current rendering context
+
+ // Clear all context data
+ ZeroMemory(ctxlist, sizeof(ctxlist[0]) * DGL_MAX_CONTEXTS);
+
+ for (i=0; i<DGL_MAX_CONTEXTS; i++)
+ ctxlist[i].bAllocated = FALSE; // Flag context as unused
+
+ // This section of code crashes the dll in circumstances where the app
+ // creates and destroys contexts.
+/*
+ // Register the class for our event monitor window
+ wc.style = 0;
+ wc.lpfnWndProc = GLD_EventWndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = GetModuleHandle(NULL);
+ wc.hIcon = LoadIcon(GetModuleHandle(NULL), IDI_APPLICATION);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = "GLDIRECT";
+ RegisterClass(&wc);
+
+ // Create the non-visible window to monitor all broadcast messages
+ hWndEvent = CreateWindowEx(
+ WS_EX_TOOLWINDOW,"GLDIRECT","GLDIRECT",WS_POPUP,
+ 0,0,0,0,
+ NULL,NULL,GetModuleHandle(NULL),NULL);
+*/
+
+#ifdef GLD_THREADS
+ // Create a critical section object for serializing access to
+ // DirectDraw and DDStereo create/destroy functions in multiple threads
+ if (glb.bMultiThreaded)
+ InitializeCriticalSection(&CriticalSection);
+#endif
+
+ // Context state is now initialized and ready
+ bContextReady = TRUE;
+}
+
+// ***********************************************************************
+
+void dglDeleteContextState()
+{
+ int i;
+ static BOOL bOnceIsEnough = FALSE;
+
+ // Only call once, from either DGL_exitDriver(), or DLL_PROCESS_DETACH
+ if (bOnceIsEnough)
+ return;
+ bOnceIsEnough = TRUE;
+
+ for (i=0; i<DGL_MAX_CONTEXTS; i++) {
+ if (ctxlist[i].bAllocated == TRUE) {
+ ddlogPrintf(DDLOG_WARN, "** Context %i not deleted - cleaning up.", (i+1));
+ dglDeleteContext((HGLRC)(i+1));
+ }
+ }
+
+ // Context state is no longer ready
+ bContextReady = FALSE;
+
+ // If executed when DLL unloads, DDraw objects may be invalid.
+ // So catch any page faults with this exception handler.
+__try {
+
+ // Release final DirectDraw interfaces
+ if (glb.bDirectDrawPersistant) {
+// RELEASE(glb.lpGlobalPalette);
+// RELEASE(glb.lpDepth4);
+// RELEASE(glb.lpBack4);
+// RELEASE(glb.lpPrimary4);
+// RELEASE(glb.lpDD4);
+ }
+}
+__except(EXCEPTION_EXECUTE_HANDLER) {
+ ddlogPrintf(DDLOG_WARN, "Exception raised in dglDeleteContextState.");
+}
+
+ // Destroy our event monitor window
+ if (hWndEvent) {
+ DestroyWindow(hWndEvent);
+ hWndEvent = hWndLastActive = NULL;
+ }
+
+#ifdef GLD_THREADS
+ // Destroy the critical section object
+ if (glb.bMultiThreaded)
+ DeleteCriticalSection(&CriticalSection);
+
+ // Release thread local storage indexes for current HGLRC and pixel format
+ TlsFree(dwTLSPixelFormat);
+ TlsFree(dwTLSCurrentContext);
+#endif
+}
+
+// ***********************************************************************
+
+// Application Window message handler interception
+static LONG __stdcall dglWndProc(
+ HWND hwnd,
+ UINT msg,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ DGL_ctx* lpCtx = NULL;
+ LONG lpfnWndProc = 0L;
+ int i;
+ HGLRC hGLRC;
+ RECT rect;
+ PAINTSTRUCT ps;
+ BOOL bQuit = FALSE;
+ BOOL bMain = FALSE;
+ LONG rc;
+
+ // Get the window's message handler *before* it is unhooked in WM_DESTROY
+
+ // Is this the main window?
+ if (hwnd == glb.hWndActive) {
+ bMain = TRUE;
+ lpfnWndProc = glb.lpfnWndProc;
+ }
+ // Search for DGL context matching window handle
+ for (i=0; i<DGL_MAX_CONTEXTS; i++) {
+ if (ctxlist[i].hWnd == hwnd) {
+ lpCtx = &ctxlist[i];
+ lpfnWndProc = lpCtx->lpfnWndProc;
+ break;
+ }
+ }
+ // Not one of ours...
+ if (!lpfnWndProc)
+ return DefWindowProc(hwnd, msg, wParam, lParam);
+
+ // Intercept messages amd process *before* passing on to window
+ switch (msg) {
+#ifdef _USE_GLD3_WGL
+ case WM_DISPLAYCHANGE:
+ glb.bPixelformatsDirty = TRUE;
+ break;
+#endif
+ case WM_ACTIVATEAPP:
+ glb.bAppActive = (BOOL)wParam;
+ ddlogPrintf(DDLOG_INFO, "Calling app has been %s", glb.bAppActive ? "activated" : "de-activated");
+ break;
+ case WM_ERASEBKGND:
+ // Eat the GDI erase event for the GL window
+ if (!lpCtx || !lpCtx->bHasBeenCurrent)
+ break;
+ lpCtx->bGDIEraseBkgnd = TRUE;
+ return TRUE;
+ case WM_PAINT:
+ // Eat the invalidated update region if render scene is in progress
+ if (!lpCtx || !lpCtx->bHasBeenCurrent)
+ break;
+ if (lpCtx->bFrameStarted) {
+ if (GetUpdateRect(hwnd, &rect, FALSE)) {
+ BeginPaint(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+ ValidateRect(hwnd, &rect);
+ return TRUE;
+ }
+ }
+ break;
+ }
+ // Call the appropriate window message handler
+ rc = CallWindowProc((WNDPROC)lpfnWndProc, hwnd, msg, wParam, lParam);
+
+ // Intercept messages and process *after* passing on to window
+ switch (msg) {
+ case WM_QUIT:
+ case WM_DESTROY:
+ bQuit = TRUE;
+ if (lpCtx && lpCtx->bAllocated) {
+ ddlogPrintf(DDLOG_WARN, "WM_DESTROY detected for HWND=%X, HDC=%X, HGLRC=%d", hwnd, lpCtx->hDC, i+1);
+ dglDeleteContext((HGLRC)(i+1));
+ }
+ break;
+#if 0
+ case WM_SIZE:
+ // Resize surfaces to fit window but not viewport (in case app did not bother)
+ if (!lpCtx || !lpCtx->bHasBeenCurrent)
+ break;
+ w = LOWORD(lParam);
+ h = HIWORD(lParam);
+ if (lpCtx->dwWidth < w || lpCtx->dwHeight < h) {
+ if (!dglWglResizeBuffers(lpCtx->glCtx, TRUE))
+ dglWglResizeBuffers(lpCtx->glCtx, FALSE);
+ }
+ break;
+#endif
+ }
+
+ // If the main window is quitting, then so should we...
+ if (bMain && bQuit) {
+ ddlogPrintf(DDLOG_SYSTEM, "shutting down after WM_DESTROY detected for main HWND=%X", hwnd);
+ dglDeleteContextState();
+ dglExitDriver();
+ }
+
+ return rc;
+}
+
+// ***********************************************************************
+
+// Driver Window message handler
+static LONG __stdcall GLD_EventWndProc(
+ HWND hwnd,
+ UINT msg,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ switch (msg) {
+ // May be sent by splash screen dialog on exit
+ case WM_ACTIVATE:
+ if (LOWORD(wParam) == WA_ACTIVE && glb.hWndActive) {
+ SetForegroundWindow(glb.hWndActive);
+ return 0;
+ }
+ break;
+ }
+ return DefWindowProc(hwnd, msg, wParam, lParam);
+}
+
+// ***********************************************************************
+
+// Intercepted Keyboard handler for detecting hot keys.
+LRESULT CALLBACK dglKeyProc(
+ int code,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ HWND hWnd, hWndFrame;
+ HGLRC hGLRC = NULL;
+ DGL_ctx* lpCtx = NULL;
+ int cmd = 0, dx1 = 0, dx2 = 0, i;
+ static BOOL bAltPressed = FALSE;
+ static BOOL bCtrlPressed = FALSE;
+ static BOOL bShiftPressed = FALSE;
+ RECT r, rf, rc;
+ POINT pt;
+ BOOL bForceReshape = FALSE;
+
+ return CallNextHookEx(hKeyHook, code, wParam, lParam);
+}
+
+// ***********************************************************************
+
+HWND hWndMatch;
+
+// Window handle enumeration procedure.
+BOOL CALLBACK dglEnumChildProc(
+ HWND hWnd,
+ LPARAM lParam)
+{
+ RECT rect;
+
+ // Find window handle with matching client rect.
+ GetClientRect(hWnd, &rect);
+ if (EqualRect(&rect, (RECT*)lParam)) {
+ hWndMatch = hWnd;
+ return FALSE;
+ }
+ // Continue with next child window.
+ return TRUE;
+}
+
+// ***********************************************************************
+
+// Find window handle with matching client rect.
+HWND dglFindWindowRect(
+ RECT* pRect)
+{
+ hWndMatch = NULL;
+ EnumChildWindows(GetForegroundWindow(), dglEnumChildProc, (LPARAM)pRect);
+ return hWndMatch;
+}
+
+// ***********************************************************************
+#ifndef _USE_GLD3_WGL
+void dglChooseDisplayMode(
+ DGL_ctx *lpCtx)
+{
+ // Note: Choose an exact match if possible.
+
+ int i;
+ DWORD area;
+ DWORD bestarea;
+ DDSURFACEDESC2 *lpDDSD = NULL; // Mode list pointer
+ DDSURFACEDESC2 *lpBestDDSD = NULL; // Pointer to best
+
+ lpDDSD = glb.lpDisplayModes;
+ for (i=0; i<glb.nDisplayModeCount; i++, lpDDSD++) {
+ if ((lpDDSD->dwWidth == lpCtx->dwWidth) &&
+ (lpDDSD->dwHeight == lpCtx->dwHeight))
+ goto matched; // Mode has been exactly matched
+ // Choose modes that are larger in both dimensions than
+ // the window, but smaller in area than the current best.
+ if ( (lpDDSD->dwWidth >= lpCtx->dwWidth) &&
+ (lpDDSD->dwHeight >= lpCtx->dwHeight))
+ {
+ if (lpBestDDSD == NULL) {
+ lpBestDDSD = lpDDSD;
+ bestarea = lpDDSD->dwWidth * lpDDSD->dwHeight;
+ continue;
+ }
+ area = lpDDSD->dwWidth * lpDDSD->dwHeight;
+ if (area < bestarea) {
+ lpBestDDSD = lpDDSD;
+ bestarea = area;
+ }
+ }
+ }
+
+ // Safety check
+ if (lpBestDDSD == NULL) {
+ ddlogMessage(DDLOG_CRITICAL, "dglChooseDisplayMode");
+ return;
+ }
+
+ lpCtx->dwModeWidth = lpBestDDSD->dwWidth;
+ lpCtx->dwModeHeight = lpBestDDSD->dwHeight;
+matched:
+ ddlogPrintf(DDLOG_INFO, "Matched (%ldx%ld) to (%ldx%ld)",
+ lpCtx->dwWidth, lpCtx->dwHeight, lpCtx->dwModeWidth, lpCtx->dwModeHeight);
+}
+#endif // _USE_GLD3_WGL
+// ***********************************************************************
+
+static BOOL IsDevice(
+ DWORD *lpDeviceIdList,
+ DWORD dwDeviceId,
+ int count)
+{
+ int i;
+
+ for (i=0; i<count; i++)
+ if (dwDeviceId == lpDeviceIdList[i])
+ return TRUE;
+
+ return FALSE;
+}
+
+// ***********************************************************************
+
+void dglTestForBrokenCards(
+ DGL_ctx *lpCtx)
+{
+#ifndef _GLD3
+ DDDEVICEIDENTIFIER dddi; // DX6 device identifier
+
+ // Sanity check.
+ if (lpCtx == NULL) {
+ // Testing for broken cards is sensitive area, so we don't want
+ // anything saying "broken cards" in the error message. ;)
+ ddlogMessage(DDLOG_ERROR, "Null context passed to TFBC\n");
+ return;
+ }
+
+ if (lpCtx->lpDD4 == NULL) {
+ // Testing for broken cards is sensitive area, so we don't want
+ // anything saying "broken cards" in the error message. ;)
+ ddlogMessage(DDLOG_ERROR, "Null DD4 passed to TFBC\n");
+ return;
+ }
+
+ // Microsoft really fucked up with the GetDeviceIdentifier function
+ // on Windows 2000, since it locks up on stock driers on the CD. Updated
+ // drivers from vendors appear to work, but we can't identify the drivers
+ // without this function!!! For now we skip these tests on Windows 2000.
+ if ((GetVersion() & 0x80000000UL) == 0)
+ return;
+
+ // Obtain device info
+ if (FAILED(IDirectDraw4_GetDeviceIdentifier(lpCtx->lpDD4, &dddi, 0)))
+ return;
+
+ // Useful info. Log it.
+ ddlogPrintf(DDLOG_INFO, "DirectDraw: VendorId=0x%x, DeviceId=0x%x", dddi.dwVendorId, dddi.dwDeviceId);
+
+ // Vendor 1: ATI
+ if (dddi.dwVendorId == VENDORID_ATI) {
+ // Test A: ATI Rage PRO
+ if (IsDevice(devATIRagePro, dddi.dwDeviceId, sizeof(devATIRagePro)))
+ glb.bUseMipmaps = FALSE;
+ // Test B: ATI Rage II+
+ if (IsDevice(devATIRageIIplus, dddi.dwDeviceId, sizeof(devATIRageIIplus)))
+ glb.bEmulateAlphaTest = TRUE;
+ }
+
+ // Vendor 2: Matrox
+ if (dddi.dwVendorId == 0x102B) {
+ // Test: Matrox G400 stencil buffer support does not work for AutoCAD
+ if (dddi.dwDeviceId == 0x0525) {
+ lpCtx->lpPF->pfd.cStencilBits = 0;
+ if (lpCtx->lpPF->iZBufferPF != -1) {
+ glb.lpZBufferPF[lpCtx->lpPF->iZBufferPF].dwStencilBitDepth = 0;
+ glb.lpZBufferPF[lpCtx->lpPF->iZBufferPF].dwStencilBitMask = 0;
+ glb.lpZBufferPF[lpCtx->lpPF->iZBufferPF].dwFlags &= ~DDPF_STENCILBUFFER;
+ }
+ }
+ }
+#endif // _GLD3
+}
+
+// ***********************************************************************
+
+BOOL dglCreateContextBuffers(
+ HDC a,
+ DGL_ctx *lpCtx,
+ BOOL bFallback)
+{
+ HRESULT hResult;
+
+ int i;
+// HGLRC hGLRC;
+// DGL_ctx* lpCtx;
+
+#ifndef _USE_GLD3_WGL
+ DWORD dwFlags;
+ DDSURFACEDESC2 ddsd2;
+ DDSCAPS2 ddscaps2;
+ LPDIRECTDRAWCLIPPER lpddClipper;
+ D3DDEVICEDESC D3DHWDevDesc; // Direct3D Hardware description
+ D3DDEVICEDESC D3DHELDevDesc; // Direct3D Hardware Emulation Layer
+#endif // _USE_GLD3_WGL
+
+ float inv_aspect;
+
+ GLenum bDoubleBuffer; // TRUE if double buffer required
+ GLenum bDepthBuffer; // TRUE if depth buffer required
+
+ const PIXELFORMATDESCRIPTOR *lpPFD = &lpCtx->lpPF->pfd;
+
+ // Vars for Mesa visual
+ DWORD dwDepthBits = 0;
+ DWORD dwStencilBits = 0;
+ DWORD dwAlphaBits = 0;
+ DWORD bAlphaSW = GL_FALSE;
+ DWORD bDouble = GL_FALSE;
+
+ DDSURFACEDESC2 ddsd2DisplayMode;
+ BOOL bFullScrnWin = FALSE; // fullscreen-size window ?
+ DDBLTFX ddbltfx;
+ DWORD dwMemoryType = (bFallback) ? DDSCAPS_SYSTEMMEMORY : glb.dwMemoryType;
+ BOOL bBogusWindow = FALSE; // non-drawable window ?
+ DWORD dwColorRef = 0; // GDI background color
+ RECT rcDst; // GDI window rect
+ POINT pt; // GDI window point
+
+ // Palette used for creating default global palette
+ PALETTEENTRY ppe[256];
+
+#ifndef _USE_GLD3_WGL
+ // Vertex buffer description. Used for creation of vertex buffers
+ D3DVERTEXBUFFERDESC vbufdesc;
+#endif // _USE_GLD3_WGL
+
+#define DDLOG_CRITICAL_OR_WARN (bFallback ? DDLOG_CRITICAL : DDLOG_WARN)
+
+ ddlogPrintf(DDLOG_SYSTEM, "dglCreateContextBuffers for HDC=%X", a);
+ nContextError = GLDERR_NONE;
+
+#ifdef GLD_THREADS
+ // Serialize access to DirectDraw object creation or DDS start
+ if (glb.bMultiThreaded)
+ EnterCriticalSection(&CriticalSection);
+#endif
+
+ // Check for back buffer
+ bDoubleBuffer = GL_TRUE; //(lpPFD->dwFlags & PFD_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE;
+ // Since we always do back buffering, check if we emulate front buffering
+ lpCtx->EmulateSingle =
+ (lpPFD->dwFlags & PFD_DOUBLEBUFFER) ? FALSE : TRUE;
+#if 0 // Don't have to mimic MS OpenGL behavior for front-buffering (DaveM)
+ lpCtx->EmulateSingle |=
+ (lpPFD->dwFlags & PFD_SUPPORT_GDI) ? TRUE : FALSE;
+#endif
+
+ // Check for depth buffer
+ bDepthBuffer = (lpPFD->cDepthBits) ? GL_TRUE : GL_FALSE;
+
+ lpCtx->bDoubleBuffer = bDoubleBuffer;
+ lpCtx->bDepthBuffer = bDepthBuffer;
+
+ // Set the Fullscreen flag for the context.
+// lpCtx->bFullscreen = glb.bFullscreen;
+
+ // Obtain the dimensions of the rendering window
+ lpCtx->hDC = a; // Cache DC
+ lpCtx->hWnd = WindowFromDC(lpCtx->hDC);
+ // Check for non-window DC = memory DC ?
+ if (lpCtx->hWnd == NULL) {
+ // bitmap memory contexts are always single-buffered
+ lpCtx->EmulateSingle = TRUE;
+ bBogusWindow = TRUE;
+ ddlogPrintf(DDLOG_INFO, "Non-Window Memory Device Context");
+ if (GetClipBox(lpCtx->hDC, &lpCtx->rcScreenRect) == ERROR) {
+ ddlogMessage(DDLOG_WARN, "GetClipBox failed in dglCreateContext\n");
+ SetRect(&lpCtx->rcScreenRect, 0, 0, 0, 0);
+ }
+ }
+ else if (!GetClientRect(lpCtx->hWnd, &lpCtx->rcScreenRect)) {
+ bBogusWindow = TRUE;
+ ddlogMessage(DDLOG_WARN, "GetClientRect failed in dglCreateContext\n");
+ SetRect(&lpCtx->rcScreenRect, 0, 0, 0, 0);
+ }
+ lpCtx->dwWidth = lpCtx->rcScreenRect.right - lpCtx->rcScreenRect.left;
+ lpCtx->dwHeight = lpCtx->rcScreenRect.bottom - lpCtx->rcScreenRect.top;
+
+ ddlogPrintf(DDLOG_INFO, "Input window %X: w=%i, h=%i",
+ lpCtx->hWnd, lpCtx->dwWidth, lpCtx->dwHeight);
+
+ // What if app only zeroes one dimension instead of both? (DaveM)
+ if ( (lpCtx->dwWidth == 0) || (lpCtx->dwHeight == 0) ) {
+ // Make the buffer size something sensible
+ lpCtx->dwWidth = 8;
+ lpCtx->dwHeight = 8;
+ }
+
+ // Set defaults
+ lpCtx->dwModeWidth = lpCtx->dwWidth;
+ lpCtx->dwModeHeight = lpCtx->dwHeight;
+/*
+ // Find best display mode for fullscreen
+ if (glb.bFullscreen || !glb.bPrimary) {
+ dglChooseDisplayMode(lpCtx);
+ }
+*/
+ // Misc initialisation
+ lpCtx->bCanRender = FALSE; // No rendering allowed yet
+ lpCtx->bSceneStarted = FALSE;
+ lpCtx->bFrameStarted = FALSE;
+
+ // Detect OS (specifically 'Windows 2000' or 'Windows XP')
+ DetectOS();
+
+ // NOTE: WinNT not supported
+ ddlogPrintf(DDLOG_INFO, "OS: %s", bHaveWin95 ? "Win9x" : (bHaveWin2K ? "Win2000/XP" : "Unsupported") );
+
+ // Test for Fullscreen
+ if (bHaveWin95) { // Problems with fullscreen on Win2K/XP
+ if ((GetSystemMetrics(SM_CXSCREEN) == lpCtx->dwWidth) &&
+ (GetSystemMetrics(SM_CYSCREEN) == lpCtx->dwHeight))
+ {
+ // Workaround for some apps that crash when going fullscreen.
+ //lpCtx->bFullscreen = TRUE;
+ }
+
+ }
+
+#ifdef _USE_GLD3_WGL
+ _gldDriver.CreateDrawable(lpCtx, glb.bDirectDrawPersistant, glb.bPersistantBuffers);
+#else
+ // Check if DirectDraw has already been created by original GLRC (DaveM)
+ if (glb.bDirectDrawPersistant && glb.bDirectDraw) {
+ lpCtx->lpDD4 = glb.lpDD4;
+ IDirectDraw4_AddRef(lpCtx->lpDD4);
+ goto SkipDirectDrawCreate;
+ }
+
+ // Create DirectDraw object
+ if (glb.bPrimary)
+ hResult = DirectDrawCreate(NULL, &lpCtx->lpDD1, NULL);
+ else {
+ // A non-primary device is to be used.
+ // Force context to be Fullscreen, secondary adaptors can not
+ // be used in a window.
+ hResult = DirectDrawCreate(&glb.ddGuid, &lpCtx->lpDD1, NULL);
+ lpCtx->bFullscreen = TRUE;
+ }
+ if (FAILED(hResult)) {
+ MessageBox(NULL, "Unable to initialize DirectDraw", "GLDirect", MB_OK);
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to create DirectDraw interface", hResult);
+ nContextError = GLDERR_DDRAW;
+ goto return_with_error;
+ }
+
+ // Query for DX6 IDirectDraw4.
+ hResult = IDirectDraw_QueryInterface(lpCtx->lpDD1,
+ &IID_IDirectDraw4,
+ (void**)&lpCtx->lpDD4);
+ if (FAILED(hResult)) {
+ MessageBox(NULL, "GLDirect requires DirectX 6.0 or above", "GLDirect", MB_OK);
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to create DirectDraw4 interface", hResult);
+ nContextError = GLDERR_DDRAW;
+ goto return_with_error;
+ }
+
+ // Cache DirectDraw interface for subsequent GLRCs
+ if (glb.bDirectDrawPersistant && !glb.bDirectDraw) {
+ glb.lpDD4 = lpCtx->lpDD4;
+ IDirectDraw4_AddRef(glb.lpDD4);
+ glb.bDirectDraw = TRUE;
+ }
+SkipDirectDrawCreate:
+
+ // Now we have a DD4 interface we can check for broken cards
+ dglTestForBrokenCards(lpCtx);
+
+ // Test if primary device can use flipping instead of blitting
+ ZeroMemory(&ddsd2DisplayMode, sizeof(ddsd2DisplayMode));
+ ddsd2DisplayMode.dwSize = sizeof(ddsd2DisplayMode);
+ hResult = IDirectDraw4_GetDisplayMode(
+ lpCtx->lpDD4,
+ &ddsd2DisplayMode);
+ if (SUCCEEDED(hResult)) {
+ if ( (lpCtx->dwWidth == ddsd2DisplayMode.dwWidth) &&
+ (lpCtx->dwHeight == ddsd2DisplayMode.dwHeight) ) {
+ // We have a fullscreen-size window
+ bFullScrnWin = TRUE;
+ // OK to use DirectDraw fullscreen mode ?
+ if (glb.bPrimary && !glb.bFullscreenBlit && !lpCtx->EmulateSingle && !glb.bDirectDrawPersistant) {
+ lpCtx->bFullscreen = TRUE;
+ ddlogMessage(DDLOG_INFO, "Primary upgraded to page flipping.\n");
+ }
+ }
+ // Cache the display mode dimensions
+ lpCtx->dwModeWidth = ddsd2DisplayMode.dwWidth;
+ lpCtx->dwModeHeight = ddsd2DisplayMode.dwHeight;
+ }
+
+ // Clamp the effective window dimensions to primary surface.
+ // We need to do this for D3D viewport dimensions even if wide
+ // surfaces are supported. This also is a good idea for handling
+ // whacked-out window dimensions passed for non-drawable windows
+ // like Solid Edge. (DaveM)
+ if (lpCtx->dwWidth > ddsd2DisplayMode.dwWidth)
+ lpCtx->dwWidth = ddsd2DisplayMode.dwWidth;
+ if (lpCtx->dwHeight > ddsd2DisplayMode.dwHeight)
+ lpCtx->dwHeight = ddsd2DisplayMode.dwHeight;
+
+ // Check for non-RGB desktop resolution
+ if (!lpCtx->bFullscreen && ddsd2DisplayMode.ddpfPixelFormat.dwRGBBitCount <= 8) {
+ ddlogPrintf(DDLOG_CRITICAL_OR_WARN, "Desktop color depth %d bpp not supported",
+ ddsd2DisplayMode.ddpfPixelFormat.dwRGBBitCount);
+ nContextError = GLDERR_BPP;
+ goto return_with_error;
+ }
+#endif // _USE_GLD3_WGL
+
+ ddlogPrintf(DDLOG_INFO, "Window: w=%i, h=%i (%s)",
+ lpCtx->dwWidth,
+ lpCtx->dwHeight,
+ lpCtx->bFullscreen ? "fullscreen" : "windowed");
+
+#ifndef _USE_GLD3_WGL
+ // Obtain ddraw caps
+ ZeroMemory(&lpCtx->ddCaps, sizeof(DDCAPS));
+ lpCtx->ddCaps.dwSize = sizeof(DDCAPS);
+ if (glb.bHardware) {
+ // Get HAL caps
+ IDirectDraw4_GetCaps(lpCtx->lpDD4, &lpCtx->ddCaps, NULL);
+ } else {
+ // Get HEL caps
+ IDirectDraw4_GetCaps(lpCtx->lpDD4, NULL, &lpCtx->ddCaps);
+ }
+
+ // If this flag is present then we can't default to Mesa
+ // SW rendering between BeginScene() and EndScene().
+ if (lpCtx->ddCaps.dwCaps2 & DDCAPS2_NO2DDURING3DSCENE) {
+ ddlogMessage(DDLOG_INFO,
+ "Warning : No 2D allowed during 3D scene.\n");
+ }
+
+ // Query for DX6 Direct3D3 interface
+ hResult = IDirectDraw4_QueryInterface(lpCtx->lpDD4,
+ &IID_IDirect3D3,
+ (void**)&lpCtx->lpD3D3);
+ if (FAILED(hResult)) {
+ MessageBox(NULL, "Unable to initialize Direct3D", "GLDirect", MB_OK);
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D interface", hResult);
+ nContextError = GLDERR_D3D;
+ goto return_with_error;
+ }
+
+ // Context creation
+ if (lpCtx->bFullscreen) {
+ // FULLSCREEN
+
+ // Disable warning popups when in fullscreen mode
+ ddlogWarnOption(FALSE);
+
+ // Have to release persistant primary surface if fullscreen mode
+ if (glb.bDirectDrawPersistant && glb.bDirectDrawPrimary) {
+ RELEASE(glb.lpPrimary4);
+ glb.bDirectDrawPrimary = FALSE;
+ }
+
+ dwFlags = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT;
+ if (glb.bFastFPU)
+ dwFlags |= DDSCL_FPUSETUP; // fast FPU setup optional (DaveM)
+ hResult = IDirectDraw4_SetCooperativeLevel(lpCtx->lpDD4, lpCtx->hWnd, dwFlags);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to set Exclusive Fullscreen mode", hResult);
+ goto return_with_error;
+ }
+
+ hResult = IDirectDraw4_SetDisplayMode(lpCtx->lpDD4,
+ lpCtx->dwModeWidth,
+ lpCtx->dwModeHeight,
+ lpPFD->cColorBits,
+ 0,
+ 0);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "SetDisplayMode failed", hResult);
+ goto return_with_error;
+ }
+
+ // ** The display mode has changed, so dont use MessageBox! **
+
+ ZeroMemory(&ddsd2, sizeof(ddsd2));
+ ddsd2.dwSize = sizeof(ddsd2);
+
+ if (bDoubleBuffer) {
+ // Double buffered
+ // Primary surface
+ ddsd2.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
+ ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
+ DDSCAPS_FLIP |
+ DDSCAPS_COMPLEX |
+ DDSCAPS_3DDEVICE |
+ dwMemoryType;
+ ddsd2.dwBackBufferCount = 1;
+
+ hResult = IDirectDraw4_CreateSurface(lpCtx->lpDD4, &ddsd2, &lpCtx->lpFront4, NULL);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateSurface (primary) failed", hResult);
+ nContextError = GLDERR_MEM;
+ goto return_with_error;
+ }
+
+ // Render target surface
+ ZeroMemory(&ddscaps2, sizeof(ddscaps2)); // Clear the entire struct.
+ ddscaps2.dwCaps = DDSCAPS_BACKBUFFER;
+ hResult = IDirectDrawSurface4_GetAttachedSurface(lpCtx->lpFront4, &ddscaps2, &lpCtx->lpBack4);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "GetAttachedSurface failed", hResult);
+ nContextError = GLDERR_MEM;
+ goto return_with_error;
+ }
+ } else {
+ // Single buffered
+ // Primary surface
+ ddsd2.dwFlags = DDSD_CAPS;
+ ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
+ //DDSCAPS_3DDEVICE |
+ dwMemoryType;
+
+ hResult = IDirectDraw4_CreateSurface(lpCtx->lpDD4, &ddsd2, &lpCtx->lpFront4, NULL);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateSurface (primary) failed", hResult);
+ nContextError = GLDERR_MEM;
+ goto return_with_error;
+ }
+
+ lpCtx->lpBack4 = NULL;
+ }
+ } else {
+ // WINDOWED
+
+ // OK to enable warning popups in windowed mode
+ ddlogWarnOption(glb.bMessageBoxWarnings);
+
+ dwFlags = DDSCL_NORMAL;
+ if (glb.bMultiThreaded)
+ dwFlags |= DDSCL_MULTITHREADED;
+ if (glb.bFastFPU)
+ dwFlags |= DDSCL_FPUSETUP; // fast FPU setup optional (DaveM)
+ hResult = IDirectDraw4_SetCooperativeLevel(lpCtx->lpDD4,
+ lpCtx->hWnd,
+ dwFlags);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to set Normal coop level", hResult);
+ goto return_with_error;
+ }
+ // Has Primary surface already been created for original GLRC ?
+ // Note this can only be applicable for windowed modes
+ if (glb.bDirectDrawPersistant && glb.bDirectDrawPrimary) {
+ lpCtx->lpFront4 = glb.lpPrimary4;
+ IDirectDrawSurface4_AddRef(lpCtx->lpFront4);
+ // Update the window on the default clipper
+ IDirectDrawSurface4_GetClipper(lpCtx->lpFront4, &lpddClipper);
+ IDirectDrawClipper_SetHWnd(lpddClipper, 0, lpCtx->hWnd);
+ IDirectDrawClipper_Release(lpddClipper);
+ goto SkipPrimaryCreate;
+ }
+
+ // Primary surface
+ ZeroMemory(&ddsd2, sizeof(ddsd2));
+ ddsd2.dwSize = sizeof(ddsd2);
+ ddsd2.dwFlags = DDSD_CAPS;
+ ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+ hResult = IDirectDraw4_CreateSurface(lpCtx->lpDD4, &ddsd2, &lpCtx->lpFront4, NULL);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateSurface (primary) failed", hResult);
+ nContextError = GLDERR_MEM;
+ goto return_with_error;
+ }
+
+ // Cache Primary surface for subsequent GLRCs
+ // Note this can only be applicable to subsequent windowed modes
+ if (glb.bDirectDrawPersistant && !glb.bDirectDrawPrimary) {
+ glb.lpPrimary4 = lpCtx->lpFront4;
+ IDirectDrawSurface4_AddRef(glb.lpPrimary4);
+ glb.bDirectDrawPrimary = TRUE;
+ }
+
+ // Clipper object
+ hResult = DirectDrawCreateClipper(0, &lpddClipper, NULL);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateClipper failed", hResult);
+ goto return_with_error;
+ }
+ hResult = IDirectDrawClipper_SetHWnd(lpddClipper, 0, lpCtx->hWnd);
+ if (FAILED(hResult)) {
+ RELEASE(lpddClipper);
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "SetHWnd failed", hResult);
+ goto return_with_error;
+ }
+ hResult = IDirectDrawSurface4_SetClipper(lpCtx->lpFront4, lpddClipper);
+ RELEASE(lpddClipper); // We have finished with it.
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "SetClipper failed", hResult);
+ goto return_with_error;
+ }
+SkipPrimaryCreate:
+
+ if (bDoubleBuffer) {
+ // Render target surface
+ ZeroMemory(&ddsd2, sizeof(ddsd2));
+ ddsd2.dwSize = sizeof(ddsd2);
+ ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
+ ddsd2.dwWidth = lpCtx->dwWidth;
+ ddsd2.dwHeight = lpCtx->dwHeight;
+ ddsd2.ddsCaps.dwCaps = DDSCAPS_3DDEVICE |
+ DDSCAPS_OFFSCREENPLAIN |
+ dwMemoryType;
+
+ // Reserve the entire desktop size for persistant buffers option
+ if (glb.bDirectDrawPersistant && glb.bPersistantBuffers) {
+ ddsd2.dwWidth = ddsd2DisplayMode.dwWidth;
+ ddsd2.dwHeight = ddsd2DisplayMode.dwHeight;
+ }
+ // Re-use original back buffer if persistant buffers exist
+ if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && glb.lpBack4)
+ hResult = IDirectDrawSurface4_AddRef(lpCtx->lpBack4 = glb.lpBack4);
+ else
+ hResult = IDirectDraw4_CreateSurface(lpCtx->lpDD4, &ddsd2, &lpCtx->lpBack4, NULL);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "Create Backbuffer failed", hResult);
+ nContextError = GLDERR_MEM;
+ goto return_with_error;
+ }
+ if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && !glb.lpBack4)
+ IDirectDrawSurface4_AddRef(glb.lpBack4 = lpCtx->lpBack4);
+ } else {
+ lpCtx->lpBack4 = NULL;
+ }
+ }
+
+ //
+ // Now create the Z-buffer
+ //
+ lpCtx->bStencil = FALSE; // Default to no stencil buffer
+ if (bDepthBuffer && (lpCtx->lpPF->iZBufferPF != -1)) {
+ // Get z-buffer dimensions from the render target
+ // Setup the surface desc for the z-buffer.
+ ZeroMemory(&ddsd2, sizeof(ddsd2));
+ ddsd2.dwSize = sizeof(ddsd2);
+ ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
+ ddsd2.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | dwMemoryType;
+ ddsd2.dwWidth = lpCtx->dwWidth;
+ ddsd2.dwHeight = lpCtx->dwHeight;
+ memcpy(&ddsd2.ddpfPixelFormat,
+ &glb.lpZBufferPF[lpCtx->lpPF->iZBufferPF],
+ sizeof(DDPIXELFORMAT) );
+
+ // Reserve the entire desktop size for persistant buffers option
+ if (glb.bDirectDrawPersistant && glb.bPersistantBuffers) {
+ ddsd2.dwWidth = ddsd2DisplayMode.dwWidth;
+ ddsd2.dwHeight = ddsd2DisplayMode.dwHeight;
+ }
+
+ // Create a z-buffer
+ if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && glb.lpDepth4)
+ hResult = IDirectDrawSurface4_AddRef(lpCtx->lpDepth4 = glb.lpDepth4);
+ else
+ hResult = IDirectDraw4_CreateSurface(lpCtx->lpDD4, &ddsd2, &lpCtx->lpDepth4, NULL);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateSurface (ZBuffer) failed", hResult);
+ nContextError = GLDERR_MEM;
+ goto return_with_error;
+ }
+ if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && !glb.lpDepth4)
+ IDirectDrawSurface4_AddRef(glb.lpDepth4 = lpCtx->lpDepth4);
+ else if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && glb.lpDepth4 && glb.lpBack4)
+ IDirectDrawSurface4_DeleteAttachedSurface(glb.lpBack4, 0, glb.lpDepth4);
+
+ // Attach Zbuffer to render target
+ TRY(IDirectDrawSurface4_AddAttachedSurface(
+ bDoubleBuffer ? lpCtx->lpBack4 : lpCtx->lpFront4,
+ lpCtx->lpDepth4),
+ "dglCreateContext: Attach Zbuffer");
+ if (glb.lpZBufferPF[lpCtx->lpPF->iZBufferPF].dwFlags & DDPF_STENCILBUFFER) {
+ lpCtx->bStencil = TRUE;
+ ddlogMessage(DDLOG_INFO, "Depth buffer has stencil\n");
+ }
+ }
+
+ // Clear all back buffers and Z-buffers in case of memory recycling.
+ ZeroMemory(&ddbltfx, sizeof(ddbltfx));
+ ddbltfx.dwSize = sizeof(ddbltfx);
+ IDirectDrawSurface4_Blt(lpCtx->lpBack4, NULL, NULL, NULL,
+ DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
+ if (lpCtx->lpDepth4)
+ IDirectDrawSurface4_Blt(lpCtx->lpDepth4, NULL, NULL, NULL,
+ DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
+
+ // Now that we have a Z-buffer we can create the 3D device
+ hResult = IDirect3D3_CreateDevice(lpCtx->lpD3D3,
+ &glb.d3dGuid,
+ bDoubleBuffer ? lpCtx->lpBack4 : lpCtx->lpFront4,
+ &lpCtx->lpDev3,
+ NULL);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D device", hResult);
+ nContextError = GLDERR_D3D;
+ goto return_with_error;
+ }
+
+ // We must do this as soon as the device is created
+ dglInitStateCaches(lpCtx);
+
+ // Obtain the D3D Device Description
+ D3DHWDevDesc.dwSize = D3DHELDevDesc.dwSize = sizeof(D3DDEVICEDESC);
+ TRY(IDirect3DDevice3_GetCaps(lpCtx->lpDev3,
+ &D3DHWDevDesc,
+ &D3DHELDevDesc),
+ "dglCreateContext: GetCaps failed");
+
+ // Choose the relevant description and cache it in the context.
+ // We will use this description later for caps checking
+ memcpy( &lpCtx->D3DDevDesc,
+ glb.bHardware ? &D3DHWDevDesc : &D3DHELDevDesc,
+ sizeof(D3DDEVICEDESC));
+
+ // Now we can examine the texture formats
+ if (!dglBuildTextureFormatList(lpCtx->lpDev3)) {
+ ddlogMessage(DDLOG_CRITICAL_OR_WARN, "dglBuildTextureFormatList failed\n");
+ goto return_with_error;
+ }
+
+ // Get the pixel format of the back buffer
+ lpCtx->ddpfRender.dwSize = sizeof(lpCtx->ddpfRender);
+ if (bDoubleBuffer)
+ hResult = IDirectDrawSurface4_GetPixelFormat(
+ lpCtx->lpBack4,
+ &lpCtx->ddpfRender);
+ else
+ hResult = IDirectDrawSurface4_GetPixelFormat(
+ lpCtx->lpFront4,
+ &lpCtx->ddpfRender);
+
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "GetPixelFormat failed", hResult);
+ goto return_with_error;
+ }
+ // Find a pixel packing function suitable for this surface
+ pxClassifyPixelFormat(&lpCtx->ddpfRender,
+ &lpCtx->fnPackFunc,
+ &lpCtx->fnUnpackFunc,
+ &lpCtx->fnPackSpanFunc);
+
+ // Viewport
+ hResult = IDirect3D3_CreateViewport(lpCtx->lpD3D3, &lpCtx->lpViewport3, NULL);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateViewport failed", hResult);
+ goto return_with_error;
+ }
+
+ hResult = IDirect3DDevice3_AddViewport(lpCtx->lpDev3, lpCtx->lpViewport3);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "AddViewport failed", hResult);
+ goto return_with_error;
+ }
+
+ // Initialise the viewport
+ // Note screen coordinates are used for viewport clipping since D3D
+ // transform operations are not used in the GLD CAD driver. (DaveM)
+ inv_aspect = (float)lpCtx->dwHeight/(float)lpCtx->dwWidth;
+
+ lpCtx->d3dViewport.dwSize = sizeof(lpCtx->d3dViewport);
+ lpCtx->d3dViewport.dwX = 0;
+ lpCtx->d3dViewport.dwY = 0;
+ lpCtx->d3dViewport.dwWidth = lpCtx->dwWidth;
+ lpCtx->d3dViewport.dwHeight = lpCtx->dwHeight;
+ lpCtx->d3dViewport.dvClipX = 0; // -1.0f;
+ lpCtx->d3dViewport.dvClipY = 0; // inv_aspect;
+ lpCtx->d3dViewport.dvClipWidth = lpCtx->dwWidth; // 2.0f;
+ lpCtx->d3dViewport.dvClipHeight = lpCtx->dwHeight; // 2.0f * inv_aspect;
+ lpCtx->d3dViewport.dvMinZ = 0.0f;
+ lpCtx->d3dViewport.dvMaxZ = 1.0f;
+ TRY(IDirect3DViewport3_SetViewport2(lpCtx->lpViewport3, &lpCtx->d3dViewport), "dglCreateContext: SetViewport2");
+
+ hResult = IDirect3DDevice3_SetCurrentViewport(lpCtx->lpDev3, lpCtx->lpViewport3);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "SetCurrentViewport failed", hResult);
+ goto return_with_error;
+ }
+
+ lpCtx->dwBPP = lpPFD->cColorBits;
+ lpCtx->iZBufferPF = lpCtx->lpPF->iZBufferPF;
+
+ // Set last texture to NULL
+ for (i=0; i<MAX_TEXTURE_UNITS; i++) {
+ lpCtx->ColorOp[i] = D3DTOP_DISABLE;
+ lpCtx->AlphaOp[i] = D3DTOP_DISABLE;
+ lpCtx->tObj[i] = NULL;
+ }
+
+ // Default to perspective correct texture mapping
+ dglSetRenderState(lpCtx, D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE, "TexturePersp");
+
+ // Set the default culling mode
+ lpCtx->cullmode = D3DCULL_NONE;
+ dglSetRenderState(lpCtx, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE, "CullMode");
+
+ // Disable specular
+ dglSetRenderState(lpCtx, D3DRENDERSTATE_SPECULARENABLE, FALSE, "SpecularEnable");
+ // Disable subpixel correction
+// dglSetRenderState(lpCtx, D3DRENDERSTATE_SUBPIXEL, FALSE, "SubpixelEnable");
+ // Disable dithering
+ dglSetRenderState(lpCtx, D3DRENDERSTATE_DITHERENABLE, FALSE, "DitherEnable");
+
+ // Initialise the primitive caches
+// lpCtx->dwNextLineVert = 0;
+// lpCtx->dwNextTriVert = 0;
+
+ // Init the global texture palette
+ lpCtx->lpGlobalPalette = NULL;
+
+ // Init the HW/SW usage counters
+// lpCtx->dwHWUsageCount = lpCtx->dwSWUsageCount = 0L;
+
+ //
+ // Create two D3D vertex buffers.
+ // One will hold the pre-transformed data with the other one
+ // being used to hold the post-transformed & clipped verts.
+ //
+#if 0 // never used (DaveM)
+ vbufdesc.dwSize = sizeof(D3DVERTEXBUFFERDESC);
+ vbufdesc.dwCaps = D3DVBCAPS_WRITEONLY;
+ if (glb.bHardware == FALSE)
+ vbufdesc.dwCaps = D3DVBCAPS_SYSTEMMEMORY;
+ vbufdesc.dwNumVertices = 32768; // For the time being
+
+ // Source vertex buffer
+ vbufdesc.dwFVF = DGL_LVERTEX;
+ hResult = IDirect3D3_CreateVertexBuffer(lpCtx->lpD3D3, &vbufdesc, &lpCtx->m_vbuf, 0, NULL);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateVertexBuffer(src) failed", hResult);
+ goto return_with_error;
+ }
+
+ // Destination vertex buffer
+ vbufdesc.dwFVF = (glb.bMultitexture == FALSE) ? D3DFVF_TLVERTEX : (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX2);
+ hResult = IDirect3D3_CreateVertexBuffer(lpCtx->lpD3D3, &vbufdesc, &lpCtx->m_pvbuf, 0, NULL);
+ if(FAILED(hResult)) {
+ ddlogError(DDLOG_CRITICAL_OR_WARN, "CreateVertexBuffer(dst) failed", hResult);
+ goto return_with_error;
+ }
+#endif
+
+#endif _USE_GLD3_WGL
+
+ //
+ // Now create the Mesa context
+ //
+
+ // Create the Mesa visual
+ if (lpPFD->cDepthBits)
+ dwDepthBits = 16;
+ if (lpPFD->cStencilBits)
+ dwStencilBits = 8;
+ if (lpPFD->cAlphaBits) {
+ dwAlphaBits = 8;
+ bAlphaSW = GL_TRUE;
+ }
+ if (lpPFD->dwFlags & PFD_DOUBLEBUFFER)
+ bDouble = GL_TRUE;
+// lpCtx->EmulateSingle =
+// (lpPFD->dwFlags & PFD_DOUBLEBUFFER) ? FALSE : TRUE;
+
+#ifdef _USE_GLD3_WGL
+ lpCtx->glVis = _mesa_create_visual(
+ bDouble, /* double buffer */
+ GL_FALSE, // stereo
+ lpPFD->cRedBits,
+ lpPFD->cGreenBits,
+ lpPFD->cBlueBits,
+ dwAlphaBits,
+ dwDepthBits,
+ dwStencilBits,
+ lpPFD->cAccumRedBits, // accum bits
+ lpPFD->cAccumGreenBits, // accum bits
+ lpPFD->cAccumBlueBits, // accum bits
+ lpPFD->cAccumAlphaBits, // accum alpha bits
+ 1 // num samples
+ );
+#else // _USE_GLD3_WGL
+ lpCtx->glVis = (*mesaFuncs.gl_create_visual)(
+ GL_TRUE, // RGB mode
+ bAlphaSW, // Is an alpha buffer required?
+ bDouble, // Is an double-buffering required?
+ GL_FALSE, // stereo
+ dwDepthBits, // depth_size
+ dwStencilBits, // stencil_size
+ lpPFD->cAccumBits, // accum_size
+ 0, // colour-index bits
+ lpPFD->cRedBits, // Red bit count
+ lpPFD->cGreenBits, // Green bit count
+ lpPFD->cBlueBits, // Blue bit count
+ dwAlphaBits // Alpha bit count
+ );
+#endif // _USE_GLD3_WGL
+
+ if (lpCtx->glVis == NULL) {
+ ddlogMessage(DDLOG_CRITICAL_OR_WARN, "gl_create_visual failed\n");
+ goto return_with_error;
+ }
+
+#ifdef _USE_GLD3_WGL
+ lpCtx->glCtx = _mesa_create_context(API_OPENGL, lpCtx->glVis, NULL, (void *)lpCtx, GL_TRUE);
+#else
+ // Create the Mesa context
+ lpCtx->glCtx = (*mesaFuncs.gl_create_context)(
+ lpCtx->glVis, // Mesa visual
+ NULL, // share list context
+ (void *)lpCtx, // Pointer to our driver context
+ GL_TRUE // Direct context flag
+ );
+#endif // _USE_GLD3_WGL
+
+ if (lpCtx->glCtx == NULL) {
+ ddlogMessage(DDLOG_CRITICAL_OR_WARN, "gl_create_context failed\n");
+ goto return_with_error;
+ }
+
+ // Create the Mesa framebuffer
+#ifdef _USE_GLD3_WGL
+ lpCtx->glBuffer = _mesa_create_framebuffer(
+ lpCtx->glVis,
+ lpCtx->glVis->depthBits > 0,
+ lpCtx->glVis->stencilBits > 0,
+ lpCtx->glVis->accumRedBits > 0,
+ GL_FALSE //swalpha
+ );
+#else
+ lpCtx->glBuffer = (*mesaFuncs.gl_create_framebuffer)(lpCtx->glVis);
+#endif // _USE_GLD3_WGL
+
+ if (lpCtx->glBuffer == NULL) {
+ ddlogMessage(DDLOG_CRITICAL_OR_WARN, "gl_create_framebuffer failed\n");
+ goto return_with_error;
+ }
+
+#ifdef _USE_GLD3_WGL
+ // Init Mesa internals
+ _swrast_CreateContext( lpCtx->glCtx );
+ _vbo_CreateContext( lpCtx->glCtx );
+ _tnl_CreateContext( lpCtx->glCtx );
+ _swsetup_CreateContext( lpCtx->glCtx );
+
+ _gldDriver.InitialiseMesa(lpCtx);
+
+ lpCtx->glCtx->imports.warning = _gld_mesa_warning;
+ lpCtx->glCtx->imports.fatal = _gld_mesa_fatal;
+
+#else
+ // Tell Mesa how many texture stages we have
+ glb.wMaxSimultaneousTextures = lpCtx->D3DDevDesc.wMaxSimultaneousTextures;
+ // Only use as many Units as the spec requires
+ if (glb.wMaxSimultaneousTextures > MAX_TEXTURE_UNITS)
+ glb.wMaxSimultaneousTextures = MAX_TEXTURE_UNITS;
+ lpCtx->glCtx->Const.MaxTextureUnits = glb.wMaxSimultaneousTextures;
+ ddlogPrintf(DDLOG_INFO, "Texture stages : %d", glb.wMaxSimultaneousTextures);
+
+ // Set the max texture size.
+ // NOTE: clamped to a max of 1024 for extra performance!
+ lpCtx->dwMaxTextureSize = (lpCtx->D3DDevDesc.dwMaxTextureWidth <= 1024) ? lpCtx->D3DDevDesc.dwMaxTextureWidth : 1024;
+
+// Texture resize takes place elsewhere. KH
+// NOTE: This was added to workaround an issue with the Intel app.
+#if 0
+ lpCtx->glCtx->Const.MaxTextureSize = lpCtx->dwMaxTextureSize;
+#else
+ lpCtx->glCtx->Const.MaxTextureSize = 1024;
+#endif
+ lpCtx->glCtx->Const.MaxDrawBuffers = 1;
+
+ // Setup the Display Driver pointers
+ dglSetupDDPointers(lpCtx->glCtx);
+
+ // Initialise all the Direct3D renderstates
+ dglInitStateD3D(lpCtx->glCtx);
+
+#if 0
+ // Signal a reload of texture state on next glBegin
+ lpCtx->m_texHandleValid = FALSE;
+ lpCtx->m_mtex = FALSE;
+ lpCtx->m_texturing = FALSE;
+#else
+ // Set default texture unit state
+// dglSetTexture(lpCtx, 0, NULL);
+// dglSetTexture(lpCtx, 1, NULL);
+#endif
+
+ //
+ // Set the global texture palette to default values.
+ //
+
+ // Clear the entire palette
+ ZeroMemory(ppe, sizeof(PALETTEENTRY) * 256);
+
+ // Fill the palette with a default colour.
+ // A garish colour is used to catch bugs. Here Magenta is used.
+ for (i=0; i < 256; i++) {
+ ppe[i].peRed = 255;
+ ppe[i].peGreen = 0;
+ ppe[i].peBlue = 255;
+ }
+
+ RELEASE(lpCtx->lpGlobalPalette);
+
+ if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && glb.lpGlobalPalette)
+ hResult = IDirectDrawPalette_AddRef(lpCtx->lpGlobalPalette = glb.lpGlobalPalette);
+ else
+ hResult = IDirectDraw4_CreatePalette(
+ lpCtx->lpDD4,
+ DDPCAPS_INITIALIZE | DDPCAPS_8BIT | DDPCAPS_ALLOW256,
+ ppe,
+ &(lpCtx->lpGlobalPalette),
+ NULL);
+ if (FAILED(hResult)) {
+ ddlogError(DDLOG_ERROR, "Default CreatePalette failed\n", hResult);
+ lpCtx->lpGlobalPalette = NULL;
+ goto return_with_error;
+ }
+ if (glb.bDirectDrawPersistant && glb.bPersistantBuffers && !glb.lpGlobalPalette)
+ IDirectDrawPalette_AddRef(glb.lpGlobalPalette = lpCtx->lpGlobalPalette);
+
+#endif // _USE_GLD3_WGL
+
+ // ** If we have made it to here then we can enable rendering **
+ lpCtx->bCanRender = TRUE;
+
+// ddlogMessage(DDLOG_SYSTEM, "dglCreateContextBuffers succeded\n");
+
+#ifdef GLD_THREADS
+ // Release serialized access
+ if (glb.bMultiThreaded)
+ LeaveCriticalSection(&CriticalSection);
+#endif
+
+ return TRUE;
+
+return_with_error:
+ // Clean up before returning.
+ // This is critical for secondary devices.
+
+ lpCtx->bCanRender = FALSE;
+
+#ifdef _USE_GLD3_WGL
+ // Destroy the Mesa context
+ if (lpCtx->glBuffer)
+ _mesa_destroy_framebuffer(lpCtx->glBuffer);
+ if (lpCtx->glCtx)
+ _mesa_destroy_context(lpCtx->glCtx);
+ if (lpCtx->glVis)
+ _mesa_destroy_visual(lpCtx->glVis);
+
+ // Destroy driver data
+ _gldDriver.DestroyDrawable(lpCtx);
+#else
+ // Destroy the Mesa context
+ if (lpCtx->glBuffer)
+ (*mesaFuncs.gl_destroy_framebuffer)(lpCtx->glBuffer);
+ if (lpCtx->glCtx)
+ (*mesaFuncs.gl_destroy_context)(lpCtx->glCtx);
+ if (lpCtx->glVis)
+ (*mesaFuncs.gl_destroy_visual)(lpCtx->glVis);
+
+ RELEASE(lpCtx->m_pvbuf); // Release D3D vertex buffer
+ RELEASE(lpCtx->m_vbuf); // Release D3D vertex buffer
+
+ if (lpCtx->lpViewport3) {
+ if (lpCtx->lpDev3) IDirect3DDevice3_DeleteViewport(lpCtx->lpDev3, lpCtx->lpViewport3);
+ RELEASE(lpCtx->lpViewport3);
+ lpCtx->lpViewport3 = NULL;
+ }
+
+ RELEASE(lpCtx->lpDev3);
+ if (lpCtx->lpDepth4) {
+ if (lpCtx->lpBack4)
+ IDirectDrawSurface4_DeleteAttachedSurface(lpCtx->lpBack4, 0L, lpCtx->lpDepth4);
+ else
+ IDirectDrawSurface4_DeleteAttachedSurface(lpCtx->lpFront4, 0L, lpCtx->lpDepth4);
+ RELEASE(lpCtx->lpDepth4);
+ lpCtx->lpDepth4 = NULL;
+ }
+ RELEASE(lpCtx->lpBack4);
+ RELEASE(lpCtx->lpFront4);
+ else
+ if (lpCtx->bFullscreen) {
+ IDirectDraw4_RestoreDisplayMode(lpCtx->lpDD4);
+ IDirectDraw4_SetCooperativeLevel(lpCtx->lpDD4, NULL, DDSCL_NORMAL);
+ }
+ RELEASE(lpCtx->lpD3D3);
+ RELEASE(lpCtx->lpDD4);
+ RELEASE(lpCtx->lpDD1);
+#endif // _USE_GLD3_WGL
+
+ lpCtx->bAllocated = FALSE;
+
+#ifdef GLD_THREADS
+ // Release serialized access
+ if (glb.bMultiThreaded)
+ LeaveCriticalSection(&CriticalSection);
+#endif
+
+ return FALSE;
+
+#undef DDLOG_CRITICAL_OR_WARN
+}
+
+// ***********************************************************************
+
+HGLRC dglCreateContext(
+ HDC a,
+ const DGL_pixelFormat *lpPF)
+{
+ int i;
+ HGLRC hGLRC;
+ DGL_ctx* lpCtx;
+ static BOOL bWarnOnce = TRUE;
+ DWORD dwThreadId = GetCurrentThreadId();
+ char szMsg[256];
+ HWND hWnd;
+ LONG lpfnWndProc;
+
+ // Validate license
+ if (!dglValidate())
+ return NULL;
+
+ // Is context state ready ?
+ if (!bContextReady)
+ return NULL;
+
+ ddlogPrintf(DDLOG_SYSTEM, "dglCreateContext for HDC=%X, ThreadId=%X", a, dwThreadId);
+
+ // Find next free context.
+ // Also ensure that only one Fullscreen context is created at any one time.
+ hGLRC = 0; // Default to Not Found
+ for (i=0; i<DGL_MAX_CONTEXTS; i++) {
+ if (ctxlist[i].bAllocated) {
+ if (/*glb.bFullscreen && */ctxlist[i].bFullscreen)
+ break;
+ } else {
+ hGLRC = (HGLRC)(i+1);
+ break;
+ }
+ }
+
+ // Bail if no GLRC was found
+ if (!hGLRC)
+ return NULL;
+
+ // Set the context pointer
+ lpCtx = dglGetContextAddress(hGLRC);
+ // Make sure that context is zeroed before we do anything.
+ // MFC and C++ apps call wglCreateContext() and wglDeleteContext() multiple times,
+ // even though only one context is ever used by the app, so keep it clean. (DaveM)
+ ZeroMemory(lpCtx, sizeof(DGL_ctx));
+ lpCtx->bAllocated = TRUE;
+ // Flag that buffers need creating on next wglMakeCurrent call.
+ lpCtx->bHasBeenCurrent = FALSE;
+ lpCtx->lpPF = (DGL_pixelFormat *)lpPF; // cache pixel format
+ lpCtx->bCanRender = FALSE;
+
+ // Create all the internal resources here, not in dglMakeCurrent().
+ // We do a re-size check in dglMakeCurrent in case of re-allocations. (DaveM)
+ // We now try context allocations twice, first with video memory,
+ // then again with system memory. This is similar to technique
+ // used for dglWglResizeBuffers(). (DaveM)
+ if (lpCtx->bHasBeenCurrent == FALSE) {
+ if (!dglCreateContextBuffers(a, lpCtx, FALSE)) {
+ if (glb.bMessageBoxWarnings && bWarnOnce && dwLogging) {
+ bWarnOnce = FALSE;
+ switch (nContextError) {
+ case GLDERR_DDRAW: strcpy(szMsg, szDDrawWarning); break;
+ case GLDERR_D3D: strcpy(szMsg, szD3DWarning); break;
+ case GLDERR_MEM: strcpy(szMsg, szResourceWarning); break;
+ case GLDERR_BPP: strcpy(szMsg, szBPPWarning); break;
+ default: strcpy(szMsg, "");
+ }
+ if (strlen(szMsg))
+ MessageBox(NULL, szMsg, "GLDirect", MB_OK | MB_ICONWARNING);
+ }
+ // Only need to try again if memory error
+ if (nContextError == GLDERR_MEM) {
+ ddlogPrintf(DDLOG_WARN, "dglCreateContext failed 1st time with video memory");
+ }
+ else {
+ ddlogPrintf(DDLOG_ERROR, "dglCreateContext failed");
+ return NULL;
+ }
+ }
+ }
+
+ // Now that we have a hWnd, we can intercept the WindowProc.
+ hWnd = lpCtx->hWnd;
+ if (hWnd) {
+ // Only hook individual window handler once if not hooked before.
+ lpfnWndProc = GetWindowLong(hWnd, GWL_WNDPROC);
+ if (lpfnWndProc != (LONG)dglWndProc) {
+ lpCtx->lpfnWndProc = lpfnWndProc;
+ SetWindowLong(hWnd, GWL_WNDPROC, (LONG)dglWndProc);
+ }
+ // Find the parent window of the app too.
+ if (glb.hWndActive == NULL) {
+ while (hWnd != NULL) {
+ glb.hWndActive = hWnd;
+ hWnd = GetParent(hWnd);
+ }
+ // Hook the parent window too.
+ lpfnWndProc = GetWindowLong(glb.hWndActive, GWL_WNDPROC);
+ if (glb.hWndActive == lpCtx->hWnd)
+ glb.lpfnWndProc = lpCtx->lpfnWndProc;
+ else if (lpfnWndProc != (LONG)dglWndProc)
+ glb.lpfnWndProc = lpfnWndProc;
+ if (glb.lpfnWndProc)
+ SetWindowLong(glb.hWndActive, GWL_WNDPROC, (LONG)dglWndProc);
+ }
+ }
+
+ ddlogPrintf(DDLOG_SYSTEM, "dglCreateContext succeeded for HGLRC=%d", (int)hGLRC);
+
+ return hGLRC;
+}
+
+// ***********************************************************************
+// Make a DirectGL context current
+// Used by wgl functions and dgl functions
+BOOL dglMakeCurrent(
+ HDC a,
+ HGLRC b)
+{
+ int context;
+ DGL_ctx* lpCtx;
+ HWND hWnd;
+ BOOL bNeedResize = FALSE;
+ BOOL bWindowChanged, bContextChanged;
+ LPDIRECTDRAWCLIPPER lpddClipper;
+ DWORD dwThreadId = GetCurrentThreadId();
+ LONG lpfnWndProc;
+
+ // Validate license
+ if (!dglValidate())
+ return FALSE;
+
+ // Is context state ready ?
+ if (!bContextReady)
+ return FALSE;
+
+ context = (int)b; // This is as a result of STRICT!
+ ddlogPrintf(DDLOG_SYSTEM, "dglMakeCurrent: HDC=%X, HGLRC=%d, ThreadId=%X", a, context, dwThreadId);
+
+ // If the HGLRC is NULL then make no context current;
+ // Ditto if the HDC is NULL either. (DaveM)
+ if (context == 0 || a == 0) {
+ // Corresponding Mesa operation
+#ifdef _USE_GLD3_WGL
+ _mesa_make_current(NULL, NULL);
+#else
+ (*mesaFuncs.gl_make_current)(NULL, NULL);
+#endif
+ dglSetCurrentContext(0);
+ return TRUE;
+ }
+
+ // Make sure the HGLRC is in range
+ if ((context > DGL_MAX_CONTEXTS) || (context < 0)) {
+ ddlogMessage(DDLOG_ERROR, "dglMakeCurrent: HGLRC out of range\n");
+ return FALSE;
+ }
+
+ // Find address of context and make sure that it has been allocated
+ lpCtx = dglGetContextAddress(b);
+ if (!lpCtx->bAllocated) {
+ ddlogMessage(DDLOG_ERROR, "dglMakeCurrent: Context not allocated\n");
+// return FALSE;
+ return TRUE; // HACK: Shuts up "WebLab Viewer Pro". KeithH
+ }
+
+#ifdef GLD_THREADS
+ // Serialize access to DirectDraw or DDS operations
+ if (glb.bMultiThreaded)
+ EnterCriticalSection(&CriticalSection);
+#endif
+
+ // Check if window has changed
+ hWnd = (a != lpCtx->hDC) ? WindowFromDC(a) : lpCtx->hWnd;
+ bWindowChanged = (hWnd != lpCtx->hWnd) ? TRUE : FALSE;
+ bContextChanged = (b != dglGetCurrentContext()) ? TRUE : FALSE;
+
+ // If the window has changed, make sure the clipper is updated. (DaveM)
+ if (glb.bDirectDrawPersistant && !lpCtx->bFullscreen && (bWindowChanged || bContextChanged)) {
+ lpCtx->hWnd = hWnd;
+#ifndef _USE_GLD3_WGL
+ IDirectDrawSurface4_GetClipper(lpCtx->lpFront4, &lpddClipper);
+ IDirectDrawClipper_SetHWnd(lpddClipper, 0, lpCtx->hWnd);
+ IDirectDrawClipper_Release(lpddClipper);
+#endif // _USE_GLD3_WGL
+ }
+
+ // Make sure hDC and hWnd is current. (DaveM)
+ // Obtain the dimensions of the rendering window
+ lpCtx->hDC = a; // Cache DC
+ lpCtx->hWnd = hWnd;
+ hWndLastActive = hWnd;
+
+ // Check for non-window DC = memory DC ?
+ if (hWnd == NULL) {
+ if (GetClipBox(a, &lpCtx->rcScreenRect) == ERROR) {
+ ddlogMessage(DDLOG_WARN, "GetClipBox failed in dglMakeCurrent\n");
+ SetRect(&lpCtx->rcScreenRect, 0, 0, 0, 0);
+ }
+ }
+ else if (!GetClientRect(lpCtx->hWnd, &lpCtx->rcScreenRect)) {
+ ddlogMessage(DDLOG_WARN, "GetClientRect failed in dglMakeCurrent\n");
+ SetRect(&lpCtx->rcScreenRect, 0, 0, 0, 0);
+ }
+ // Check if buffers need to be re-sized;
+ // If so, wait until Mesa GL stuff is setup before re-sizing;
+ if (lpCtx->dwWidth != lpCtx->rcScreenRect.right - lpCtx->rcScreenRect.left ||
+ lpCtx->dwHeight != lpCtx->rcScreenRect.bottom - lpCtx->rcScreenRect.top)
+ bNeedResize = TRUE;
+
+ // Now we can update our globals
+ dglSetCurrentContext(b);
+
+ // Corresponding Mesa operation
+#ifdef _USE_GLD3_WGL
+ _mesa_make_current(lpCtx->glCtx, lpCtx->glBuffer);
+ lpCtx->glCtx->Driver.UpdateState(lpCtx->glCtx, _NEW_ALL);
+ if (bNeedResize) {
+ // Resize buffers (Note Mesa GL needs to be setup beforehand);
+ // Resize Mesa internal buffer too via glViewport() command,
+ // which subsequently calls dglWglResizeBuffers() too.
+ lpCtx->glCtx->Driver.Viewport(lpCtx->glCtx, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
+ lpCtx->bHasBeenCurrent = TRUE;
+ }
+#else
+ (*mesaFuncs.gl_make_current)(lpCtx->glCtx, lpCtx->glBuffer);
+
+ dglSetupDDPointers(lpCtx->glCtx);
+
+ // Insure DirectDraw surfaces fit current window DC
+ if (bNeedResize) {
+ // Resize buffers (Note Mesa GL needs to be setup beforehand);
+ // Resize Mesa internal buffer too via glViewport() command,
+ // which subsequently calls dglWglResizeBuffers() too.
+ (*mesaFuncs.gl_Viewport)(lpCtx->glCtx, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
+ lpCtx->bHasBeenCurrent = TRUE;
+ }
+#endif // _USE_GLD3_WGL
+ ddlogPrintf(DDLOG_SYSTEM, "dglMakeCurrent: width = %d, height = %d", lpCtx->dwWidth, lpCtx->dwHeight);
+
+ // We have to clear D3D back buffer and render state if emulated front buffering
+ // for different window (but not context) like in Solid Edge.
+ if (glb.bDirectDrawPersistant && glb.bPersistantBuffers
+ && (bWindowChanged /* || bContextChanged */) && lpCtx->EmulateSingle) {
+#ifdef _USE_GLD3_WGL
+// IDirect3DDevice8_EndScene(lpCtx->pDev);
+// lpCtx->bSceneStarted = FALSE;
+ lpCtx->glCtx->Driver.Clear(lpCtx->glCtx, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
+ GL_TRUE, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
+#else
+ IDirect3DDevice3_EndScene(lpCtx->lpDev3);
+ lpCtx->bSceneStarted = FALSE;
+ dglClearD3D(lpCtx->glCtx, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
+ GL_TRUE, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
+#endif // _USE_GLD3_WGL
+ }
+
+ // The first time we call MakeCurrent we set the initial viewport size
+ if (lpCtx->bHasBeenCurrent == FALSE)
+#ifdef _USE_GLD3_WGL
+ lpCtx->glCtx->Driver.Viewport(lpCtx->glCtx, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
+#else
+ (*mesaFuncs.gl_Viewport)(lpCtx->glCtx, 0, 0, lpCtx->dwWidth, lpCtx->dwHeight);
+#endif // _USE_GLD3_WGL
+ lpCtx->bHasBeenCurrent = TRUE;
+
+#ifdef GLD_THREADS
+ // Release serialized access
+ if (glb.bMultiThreaded)
+ LeaveCriticalSection(&CriticalSection);
+#endif
+
+ return TRUE;
+}
+
+// ***********************************************************************
+
+BOOL dglDeleteContext(
+ HGLRC a)
+{
+ DGL_ctx* lpCtx;
+ DWORD dwThreadId = GetCurrentThreadId();
+ char argstr[256];
+
+#if 0 // We have enough trouble throwing exceptions as it is... (DaveM)
+ // Validate license
+ if (!dglValidate())
+ return FALSE;
+#endif
+
+ // Is context state ready ?
+ if (!bContextReady)
+ return FALSE;
+
+ ddlogPrintf(DDLOG_SYSTEM, "dglDeleteContext: Deleting context HGLRC=%d, ThreadId=%X", (int)a, dwThreadId);
+
+ // Make sure the HGLRC is in range
+ if (((int) a> DGL_MAX_CONTEXTS) || ((int)a < 0)) {
+ ddlogMessage(DDLOG_ERROR, "dglDeleteCurrent: HGLRC out of range\n");
+ return FALSE;
+ }
+
+ // Make sure context is valid
+ lpCtx = dglGetContextAddress(a);
+ if (!lpCtx->bAllocated) {
+ ddlogPrintf(DDLOG_WARN, "Tried to delete unallocated context HGLRC=%d", (int)a);
+// return FALSE;
+ return TRUE; // HACK: Shuts up "WebLab Viewer Pro". KeithH
+ }
+
+ // Make sure context is de-activated
+ if (a == dglGetCurrentContext()) {
+ ddlogPrintf(DDLOG_WARN, "dglDeleteContext: context HGLRC=%d still active", (int)a);
+ dglMakeCurrent(NULL, NULL);
+ }
+
+#ifdef GLD_THREADS
+ // Serialize access to DirectDraw or DDS operations
+ if (glb.bMultiThreaded)
+ EnterCriticalSection(&CriticalSection);
+#endif
+
+ // We are about to destroy all Direct3D objects.
+ // Therefore we must disable rendering
+ lpCtx->bCanRender = FALSE;
+
+ // This exception handler was installed to catch some
+ // particularly nasty apps. Console apps that call exit()
+ // fall into this catagory (i.e. Win32 Glut).
+
+ // VC cannot successfully implement multiple exception handlers
+ // if more than one exception occurs. Therefore reverting back to
+ // single exception handler as Keith originally had it. (DaveM)
+
+#define WARN_MESSAGE(p) strcpy(argstr, (#p));
+#define SAFE_RELEASE(p) WARN_MESSAGE(p); RELEASE(p);
+
+__try {
+#ifdef _USE_GLD3_WGL
+ WARN_MESSAGE(gl_destroy_framebuffer);
+ if (lpCtx->glBuffer)
+ _mesa_destroy_framebuffer(lpCtx->glBuffer);
+ WARN_MESSAGE(gl_destroy_context);
+ if (lpCtx->glCtx)
+ _mesa_destroy_context(lpCtx->glCtx);
+ WARN_MESSAGE(gl_destroy_visual);
+ if (lpCtx->glVis)
+ _mesa_destroy_visual(lpCtx->glVis);
+
+ _gldDriver.DestroyDrawable(lpCtx);
+#else
+ // Destroy the Mesa context
+ WARN_MESSAGE(gl_destroy_framebuffer);
+ if (lpCtx->glBuffer)
+ (*mesaFuncs.gl_destroy_framebuffer)(lpCtx->glBuffer);
+ WARN_MESSAGE(gl_destroy_context);
+ if (lpCtx->glCtx)
+ (*mesaFuncs.gl_destroy_context)(lpCtx->glCtx);
+ WARN_MESSAGE(gl_destroy_visual);
+ if (lpCtx->glVis)
+ (*mesaFuncs.gl_destroy_visual)(lpCtx->glVis);
+
+ SAFE_RELEASE(lpCtx->m_pvbuf); // release D3D vertex buffer
+ SAFE_RELEASE(lpCtx->m_vbuf); // release D3D vertex buffer
+
+ // Delete the global palette
+ SAFE_RELEASE(lpCtx->lpGlobalPalette);
+
+ // Clean up.
+ if (lpCtx->lpViewport3) {
+ if (lpCtx->lpDev3) IDirect3DDevice3_DeleteViewport(lpCtx->lpDev3, lpCtx->lpViewport3);
+ SAFE_RELEASE(lpCtx->lpViewport3);
+ lpCtx->lpViewport3 = NULL;
+ }
+
+ SAFE_RELEASE(lpCtx->lpDev3);
+ if (lpCtx->lpDepth4) {
+ if (lpCtx->lpBack4)
+ IDirectDrawSurface4_DeleteAttachedSurface(lpCtx->lpBack4, 0L, lpCtx->lpDepth4);
+ else
+ IDirectDrawSurface4_DeleteAttachedSurface(lpCtx->lpFront4, 0L, lpCtx->lpDepth4);
+ SAFE_RELEASE(lpCtx->lpDepth4);
+ lpCtx->lpDepth4 = NULL;
+ }
+ SAFE_RELEASE(lpCtx->lpBack4);
+ SAFE_RELEASE(lpCtx->lpFront4);
+ if (lpCtx->bFullscreen) {
+ IDirectDraw4_RestoreDisplayMode(lpCtx->lpDD4);
+ IDirectDraw4_SetCooperativeLevel(lpCtx->lpDD4, NULL, DDSCL_NORMAL);
+ }
+ SAFE_RELEASE(lpCtx->lpD3D3);
+ SAFE_RELEASE(lpCtx->lpDD4);
+ SAFE_RELEASE(lpCtx->lpDD1);
+#endif // _ULSE_GLD3_WGL
+
+}
+__except(EXCEPTION_EXECUTE_HANDLER) {
+ ddlogPrintf(DDLOG_WARN, "Exception raised in dglDeleteContext: %s", argstr);
+}
+
+ // Restore the window message handler because this context may be used
+ // again by another window with a *different* message handler. (DaveM)
+ if (lpCtx->lpfnWndProc) {
+ SetWindowLong(lpCtx->hWnd, GWL_WNDPROC, (LONG)lpCtx->lpfnWndProc);
+ lpCtx->lpfnWndProc = (LONG)NULL;
+ }
+
+ lpCtx->bAllocated = FALSE; // This context is now free for use
+
+#ifdef GLD_THREADS
+ // Release serialized access
+ if (glb.bMultiThreaded)
+ LeaveCriticalSection(&CriticalSection);
+#endif
+
+ return TRUE;
+}
+
+// ***********************************************************************
+
+BOOL dglSwapBuffers(
+ HDC hDC)
+{
+ RECT rSrcRect; // Source rectangle
+ RECT rDstRect; // Destination rectangle
+ POINT pt;
+ HRESULT hResult;
+
+ DDBLTFX bltFX;
+ DWORD dwBlitFlags;
+ DDBLTFX *lpBltFX;
+
+// DWORD dwThreadId = GetCurrentThreadId();
+ HGLRC hGLRC = dglGetCurrentContext();
+ DGL_ctx *lpCtx = dglGetContextAddress(hGLRC);
+ HWND hWnd;
+
+ HDC hDCAux; // for memory DC
+ int x,y,w,h; // for memory DC BitBlt
+
+#if 0 // Perhaps not a good idea. Called too often. KH
+ // Validate license
+ if (!dglValidate())
+ return FALSE;
+#endif
+
+ if (!lpCtx) {
+ return TRUE; //FALSE; // No current context
+ }
+
+ if (!lpCtx->bCanRender) {
+ // Don't return false else some apps will bail.
+ return TRUE;
+ }
+
+ hWnd = lpCtx->hWnd;
+ if (hDC != lpCtx->hDC) {
+ ddlogPrintf(DDLOG_WARN, "dglSwapBuffers: HDC=%X does not match HDC=%X for HGLRC=%d", hDC, lpCtx->hDC, hGLRC);
+ hWnd = WindowFromDC(hDC);
+ }
+
+#ifndef _USE_GLD3_WGL
+ // Ensure that the surfaces exist before we tell
+ // the device to render to them.
+ IDirectDraw4_RestoreAllSurfaces(lpCtx->lpDD4);
+
+ // Make sure that the vertex caches have been emptied
+// dglStateChange(lpCtx);
+
+ // Some OpenGL programs don't issue a glFinish - check for it here.
+ if (lpCtx->bSceneStarted) {
+ IDirect3DDevice3_EndScene(lpCtx->lpDev3);
+ lpCtx->bSceneStarted = FALSE;
+ }
+#endif
+
+#if 0
+ // If the calling app is not active then we don't need to Blit/Flip.
+ // We can therefore simply return TRUE.
+ if (!glb.bAppActive)
+ return TRUE;
+ // Addendum: This is WRONG! We should bail if the app is *minimized*,
+ // not merely if the app is just plain 'not active'.
+ // KeithH, 27/May/2000.
+#endif
+
+ // Check for non-window DC = memory DC ?
+ if (hWnd == NULL) {
+ if (GetClipBox(hDC, &rSrcRect) == ERROR)
+ return TRUE;
+ // Use GDI BitBlt instead from compatible DirectDraw DC
+ x = rSrcRect.left;
+ y = rSrcRect.top;
+ w = rSrcRect.right - rSrcRect.left;
+ h = rSrcRect.bottom - rSrcRect.top;
+
+ // Ack. DX8 does not have a GetDC() function...
+ // TODO: Defer to DX7 or DX9 drivers... (DaveM)
+ return TRUE;
+ }
+
+ // Bail if window client region is not drawable, like in Solid Edge
+ if (!IsWindow(hWnd) /* || !IsWindowVisible(hWnd) */ || !GetClientRect(hWnd, &rSrcRect))
+ return TRUE;
+
+#ifdef GLD_THREADS
+ // Serialize access to DirectDraw or DDS operations
+ if (glb.bMultiThreaded)
+ EnterCriticalSection(&CriticalSection);
+#endif
+
+#ifdef _USE_GLD3_WGL
+ // Notify Mesa of impending swap, so Mesa can flush internal buffers.
+ _mesa_notifySwapBuffers(lpCtx->glCtx);
+ // Now perform driver buffer swap
+ _gldDriver.SwapBuffers(lpCtx, hDC, hWnd);
+#else
+ if (lpCtx->bFullscreen) {
+ // Sync with retrace if required
+ if (glb.bWaitForRetrace) {
+ IDirectDraw4_WaitForVerticalBlank(
+ lpCtx->lpDD4,
+ DDWAITVB_BLOCKBEGIN,
+ 0);
+ }
+
+ // Perform the fullscreen flip
+ TRY(IDirectDrawSurface4_Flip(
+ lpCtx->lpFront4,
+ NULL,
+ DDFLIP_WAIT),
+ "dglSwapBuffers: Flip");
+ } else {
+ // Calculate current window position and size
+ pt.x = pt.y = 0;
+ ClientToScreen(hWnd, &pt);
+ GetClientRect(hWnd, &rDstRect);
+ if (rDstRect.right > lpCtx->dwModeWidth)
+ rDstRect.right = lpCtx->dwModeWidth;
+ if (rDstRect.bottom > lpCtx->dwModeHeight)
+ rDstRect.bottom = lpCtx->dwModeHeight;
+ OffsetRect(&rDstRect, pt.x, pt.y);
+ rSrcRect.left = rSrcRect.top = 0;
+ rSrcRect.right = lpCtx->dwWidth;
+ rSrcRect.bottom = lpCtx->dwHeight;
+ if (rSrcRect.right > lpCtx->dwModeWidth)
+ rSrcRect.right = lpCtx->dwModeWidth;
+ if (rSrcRect.bottom > lpCtx->dwModeHeight)
+ rSrcRect.bottom = lpCtx->dwModeHeight;
+
+ if (glb.bWaitForRetrace) {
+ // Sync the blit to the vertical retrace
+ ZeroMemory(&bltFX, sizeof(bltFX));
+ bltFX.dwSize = sizeof(bltFX);
+ bltFX.dwDDFX = DDBLTFX_NOTEARING;
+ dwBlitFlags = DDBLT_WAIT | DDBLT_DDFX;
+ lpBltFX = &bltFX;
+ } else {
+ dwBlitFlags = DDBLT_WAIT;
+ lpBltFX = NULL;
+ }
+
+ // Perform the actual blit
+ TRY(IDirectDrawSurface4_Blt(
+ lpCtx->lpFront4,
+ &rDstRect,
+ lpCtx->lpBack4, // Blit source
+ &rSrcRect,
+ dwBlitFlags,
+ lpBltFX),
+ "dglSwapBuffers: Blt");
+ }
+#endif // _USE_GLD3_WGL
+
+#ifdef GLD_THREADS
+ // Release serialized access
+ if (glb.bMultiThreaded)
+ LeaveCriticalSection(&CriticalSection);
+#endif
+
+ // TODO: Re-instate rendering bitmap snapshot feature??? (DaveM)
+
+ // Render frame is completed
+ ValidateRect(hWnd, NULL);
+ lpCtx->bFrameStarted = FALSE;
+
+ return TRUE;
+}
+
+// ***********************************************************************
diff --git a/mesalib/src/mesa/main/api_arrayelt.c b/mesalib/src/mesa/main/api_arrayelt.c
index 080c20606..3c59e9be3 100644
--- a/mesalib/src/mesa/main/api_arrayelt.c
+++ b/mesalib/src/mesa/main/api_arrayelt.c
@@ -51,7 +51,7 @@ typedef struct {
int offset;
} AEarray;
-typedef void (GLAPIENTRY *attrib_func)( GLuint indx, const void *data );
+typedef void (*attrib_func)( GLuint indx, const void *data );
typedef struct {
const struct gl_client_array *array;
diff --git a/mesalib/src/mesa/main/api_exec.c b/mesalib/src/mesa/main/api_exec.c
index d7a4c90d7..02e39c189 100644
--- a/mesalib/src/mesa/main/api_exec.c
+++ b/mesalib/src/mesa/main/api_exec.c
@@ -104,7 +104,6 @@
#if FEATURE_GL
-
/**
* Initialize a dispatch table with pointers to Mesa's immediate-mode
* commands.
diff --git a/mesalib/src/mesa/main/attrib.c b/mesalib/src/mesa/main/attrib.c
index ae7f633b8..3a6239afd 100644
--- a/mesalib/src/mesa/main/attrib.c
+++ b/mesalib/src/mesa/main/attrib.c
@@ -1,1555 +1,1555 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.6
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "glheader.h"
-#include "imports.h"
-#include "accum.h"
-#include "arrayobj.h"
-#include "attrib.h"
-#include "blend.h"
-#include "buffers.h"
-#include "bufferobj.h"
-#include "clear.h"
-#include "colormac.h"
-#include "context.h"
-#include "depth.h"
-#include "enable.h"
-#include "enums.h"
-#include "fog.h"
-#include "hint.h"
-#include "light.h"
-#include "lines.h"
-#include "macros.h"
-#include "matrix.h"
-#include "mfeatures.h"
-#include "multisample.h"
-#include "points.h"
-#include "polygon.h"
-#include "scissor.h"
-#include "stencil.h"
-#include "texenv.h"
-#include "texgen.h"
-#include "texobj.h"
-#include "texparam.h"
-#include "texstate.h"
-#include "varray.h"
-#include "viewport.h"
-#include "mtypes.h"
-#include "main/dispatch.h"
-
-
-/**
- * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
- */
-struct gl_enable_attrib
-{
- GLboolean AlphaTest;
- GLboolean AutoNormal;
- GLboolean Blend;
- GLbitfield ClipPlanes;
- GLboolean ColorMaterial;
- GLboolean CullFace;
- GLboolean DepthClamp;
- GLboolean DepthTest;
- GLboolean Dither;
- GLboolean Fog;
- GLboolean Light[MAX_LIGHTS];
- GLboolean Lighting;
- GLboolean LineSmooth;
- GLboolean LineStipple;
- GLboolean IndexLogicOp;
- GLboolean ColorLogicOp;
-
- GLboolean Map1Color4;
- GLboolean Map1Index;
- GLboolean Map1Normal;
- GLboolean Map1TextureCoord1;
- GLboolean Map1TextureCoord2;
- GLboolean Map1TextureCoord3;
- GLboolean Map1TextureCoord4;
- GLboolean Map1Vertex3;
- GLboolean Map1Vertex4;
- GLboolean Map1Attrib[16]; /* GL_NV_vertex_program */
- GLboolean Map2Color4;
- GLboolean Map2Index;
- GLboolean Map2Normal;
- GLboolean Map2TextureCoord1;
- GLboolean Map2TextureCoord2;
- GLboolean Map2TextureCoord3;
- GLboolean Map2TextureCoord4;
- GLboolean Map2Vertex3;
- GLboolean Map2Vertex4;
- GLboolean Map2Attrib[16]; /* GL_NV_vertex_program */
-
- GLboolean Normalize;
- GLboolean PixelTexture;
- GLboolean PointSmooth;
- GLboolean PolygonOffsetPoint;
- GLboolean PolygonOffsetLine;
- GLboolean PolygonOffsetFill;
- GLboolean PolygonSmooth;
- GLboolean PolygonStipple;
- GLboolean RescaleNormals;
- GLboolean Scissor;
- GLboolean Stencil;
- GLboolean StencilTwoSide; /* GL_EXT_stencil_two_side */
- GLboolean MultisampleEnabled; /* GL_ARB_multisample */
- GLboolean SampleAlphaToCoverage; /* GL_ARB_multisample */
- GLboolean SampleAlphaToOne; /* GL_ARB_multisample */
- GLboolean SampleCoverage; /* GL_ARB_multisample */
- GLboolean SampleCoverageInvert; /* GL_ARB_multisample */
- GLboolean RasterPositionUnclipped; /* GL_IBM_rasterpos_clip */
-
- GLbitfield Texture[MAX_TEXTURE_UNITS];
- GLbitfield TexGen[MAX_TEXTURE_UNITS];
-
- /* GL_ARB_vertex_program / GL_NV_vertex_program */
- GLboolean VertexProgram;
- GLboolean VertexProgramPointSize;
- GLboolean VertexProgramTwoSide;
-
- /* GL_ARB_point_sprite / GL_NV_point_sprite */
- GLboolean PointSprite;
- GLboolean FragmentShaderATI;
-};
-
-
-/**
- * Node for the attribute stack.
- */
-struct gl_attrib_node
-{
- GLbitfield kind;
- void *data;
- struct gl_attrib_node *next;
-};
-
-
-
-/**
- * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
- */
-struct texture_state
-{
- struct gl_texture_attrib Texture; /**< The usual context state */
-
- /** to save per texture object state (wrap modes, filters, etc): */
- struct gl_texture_object SavedObj[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS];
-
- /**
- * To save references to texture objects (so they don't get accidentally
- * deleted while saved in the attribute stack).
- */
- struct gl_texture_object *SavedTexRef[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS];
-};
-
-
-#if FEATURE_attrib_stack
-
-
-/**
- * Allocate new attribute node of given type/kind. Attach payload data.
- * Insert it into the linked list named by 'head'.
- */
-static void
-save_attrib_data(struct gl_attrib_node **head,
- GLbitfield kind, void *payload)
-{
- struct gl_attrib_node *n = MALLOC_STRUCT(gl_attrib_node);
- if (n) {
- n->kind = kind;
- n->data = payload;
- /* insert at head */
- n->next = *head;
- *head = n;
- }
- else {
- /* out of memory! */
- }
-}
-
-
-void GLAPIENTRY
-_mesa_PushAttrib(GLbitfield mask)
-{
- struct gl_attrib_node *head;
-
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glPushAttrib %x\n", (int) mask);
-
- if (ctx->AttribStackDepth >= MAX_ATTRIB_STACK_DEPTH) {
- _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
- return;
- }
-
- /* Build linked list of attribute nodes which save all attribute */
- /* groups specified by the mask. */
- head = NULL;
-
- if (mask & GL_ACCUM_BUFFER_BIT) {
- struct gl_accum_attrib *attr;
- attr = MALLOC_STRUCT( gl_accum_attrib );
- memcpy( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
- save_attrib_data(&head, GL_ACCUM_BUFFER_BIT, attr);
- }
-
- if (mask & GL_COLOR_BUFFER_BIT) {
- GLuint i;
- struct gl_colorbuffer_attrib *attr;
- attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
- memcpy( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
- /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
- for (i = 0; i < ctx->Const.MaxDrawBuffers; i ++)
- attr->DrawBuffer[i] = ctx->DrawBuffer->ColorDrawBuffer[i];
- save_attrib_data(&head, GL_COLOR_BUFFER_BIT, attr);
- }
-
- if (mask & GL_CURRENT_BIT) {
- struct gl_current_attrib *attr;
- FLUSH_CURRENT( ctx, 0 );
- attr = MALLOC_STRUCT( gl_current_attrib );
- memcpy( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
- save_attrib_data(&head, GL_CURRENT_BIT, attr);
- }
-
- if (mask & GL_DEPTH_BUFFER_BIT) {
- struct gl_depthbuffer_attrib *attr;
- attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
- memcpy( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
- save_attrib_data(&head, GL_DEPTH_BUFFER_BIT, attr);
- }
-
- if (mask & GL_ENABLE_BIT) {
- struct gl_enable_attrib *attr;
- GLuint i;
- attr = MALLOC_STRUCT( gl_enable_attrib );
- /* Copy enable flags from all other attributes into the enable struct. */
- attr->AlphaTest = ctx->Color.AlphaEnabled;
- attr->AutoNormal = ctx->Eval.AutoNormal;
- attr->Blend = ctx->Color.BlendEnabled;
- attr->ClipPlanes = ctx->Transform.ClipPlanesEnabled;
- attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
- attr->CullFace = ctx->Polygon.CullFlag;
- attr->DepthClamp = ctx->Transform.DepthClamp;
- attr->DepthTest = ctx->Depth.Test;
- attr->Dither = ctx->Color.DitherFlag;
- attr->Fog = ctx->Fog.Enabled;
- for (i = 0; i < ctx->Const.MaxLights; i++) {
- attr->Light[i] = ctx->Light.Light[i].Enabled;
- }
- attr->Lighting = ctx->Light.Enabled;
- attr->LineSmooth = ctx->Line.SmoothFlag;
- attr->LineStipple = ctx->Line.StippleFlag;
- attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
- attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
- attr->Map1Color4 = ctx->Eval.Map1Color4;
- attr->Map1Index = ctx->Eval.Map1Index;
- attr->Map1Normal = ctx->Eval.Map1Normal;
- attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
- attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
- attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
- attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
- attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
- attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
- memcpy(attr->Map1Attrib, ctx->Eval.Map1Attrib, sizeof(ctx->Eval.Map1Attrib));
- attr->Map2Color4 = ctx->Eval.Map2Color4;
- attr->Map2Index = ctx->Eval.Map2Index;
- attr->Map2Normal = ctx->Eval.Map2Normal;
- attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
- attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
- attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
- attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
- attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
- attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
- memcpy(attr->Map2Attrib, ctx->Eval.Map2Attrib, sizeof(ctx->Eval.Map2Attrib));
- attr->Normalize = ctx->Transform.Normalize;
- attr->RasterPositionUnclipped = ctx->Transform.RasterPositionUnclipped;
- attr->PointSmooth = ctx->Point.SmoothFlag;
- attr->PointSprite = ctx->Point.PointSprite;
- attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
- attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
- attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
- attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
- attr->PolygonStipple = ctx->Polygon.StippleFlag;
- attr->RescaleNormals = ctx->Transform.RescaleNormals;
- attr->Scissor = ctx->Scissor.Enabled;
- attr->Stencil = ctx->Stencil.Enabled;
- attr->StencilTwoSide = ctx->Stencil.TestTwoSide;
- attr->MultisampleEnabled = ctx->Multisample.Enabled;
- attr->SampleAlphaToCoverage = ctx->Multisample.SampleAlphaToCoverage;
- attr->SampleAlphaToOne = ctx->Multisample.SampleAlphaToOne;
- attr->SampleCoverage = ctx->Multisample.SampleCoverage;
- attr->SampleCoverageInvert = ctx->Multisample.SampleCoverageInvert;
- for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
- attr->Texture[i] = ctx->Texture.Unit[i].Enabled;
- attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
- }
- /* GL_NV_vertex_program */
- attr->VertexProgram = ctx->VertexProgram.Enabled;
- attr->VertexProgramPointSize = ctx->VertexProgram.PointSizeEnabled;
- attr->VertexProgramTwoSide = ctx->VertexProgram.TwoSideEnabled;
- save_attrib_data(&head, GL_ENABLE_BIT, attr);
- }
-
- if (mask & GL_EVAL_BIT) {
- struct gl_eval_attrib *attr;
- attr = MALLOC_STRUCT( gl_eval_attrib );
- memcpy( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
- save_attrib_data(&head, GL_EVAL_BIT, attr);
- }
-
- if (mask & GL_FOG_BIT) {
- struct gl_fog_attrib *attr;
- attr = MALLOC_STRUCT( gl_fog_attrib );
- memcpy( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
- save_attrib_data(&head, GL_FOG_BIT, attr);
- }
-
- if (mask & GL_HINT_BIT) {
- struct gl_hint_attrib *attr;
- attr = MALLOC_STRUCT( gl_hint_attrib );
- memcpy( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
- save_attrib_data(&head, GL_HINT_BIT, attr);
- }
-
- if (mask & GL_LIGHTING_BIT) {
- struct gl_light_attrib *attr;
- FLUSH_CURRENT(ctx, 0); /* flush material changes */
- attr = MALLOC_STRUCT( gl_light_attrib );
- memcpy( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
- save_attrib_data(&head, GL_LIGHTING_BIT, attr);
- }
-
- if (mask & GL_LINE_BIT) {
- struct gl_line_attrib *attr;
- attr = MALLOC_STRUCT( gl_line_attrib );
- memcpy( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
- save_attrib_data(&head, GL_LINE_BIT, attr);
- }
-
- if (mask & GL_LIST_BIT) {
- struct gl_list_attrib *attr;
- attr = MALLOC_STRUCT( gl_list_attrib );
- memcpy( attr, &ctx->List, sizeof(struct gl_list_attrib) );
- save_attrib_data(&head, GL_LIST_BIT, attr);
- }
-
- if (mask & GL_PIXEL_MODE_BIT) {
- struct gl_pixel_attrib *attr;
- attr = MALLOC_STRUCT( gl_pixel_attrib );
- memcpy( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
- /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
- attr->ReadBuffer = ctx->ReadBuffer->ColorReadBuffer;
- save_attrib_data(&head, GL_PIXEL_MODE_BIT, attr);
- }
-
- if (mask & GL_POINT_BIT) {
- struct gl_point_attrib *attr;
- attr = MALLOC_STRUCT( gl_point_attrib );
- memcpy( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
- save_attrib_data(&head, GL_POINT_BIT, attr);
- }
-
- if (mask & GL_POLYGON_BIT) {
- struct gl_polygon_attrib *attr;
- attr = MALLOC_STRUCT( gl_polygon_attrib );
- memcpy( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
- save_attrib_data(&head, GL_POLYGON_BIT, attr);
- }
-
- if (mask & GL_POLYGON_STIPPLE_BIT) {
- GLuint *stipple;
- stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
- memcpy( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
- save_attrib_data(&head, GL_POLYGON_STIPPLE_BIT, stipple);
- }
-
- if (mask & GL_SCISSOR_BIT) {
- struct gl_scissor_attrib *attr;
- attr = MALLOC_STRUCT( gl_scissor_attrib );
- memcpy( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
- save_attrib_data(&head, GL_SCISSOR_BIT, attr);
- }
-
- if (mask & GL_STENCIL_BUFFER_BIT) {
- struct gl_stencil_attrib *attr;
- attr = MALLOC_STRUCT( gl_stencil_attrib );
- memcpy( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
- save_attrib_data(&head, GL_STENCIL_BUFFER_BIT, attr);
- }
-
- if (mask & GL_TEXTURE_BIT) {
- struct texture_state *texstate = CALLOC_STRUCT(texture_state);
- GLuint u, tex;
-
- if (!texstate) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib(GL_TEXTURE_BIT)");
- goto end;
- }
-
- _mesa_lock_context_textures(ctx);
-
- /* copy/save the bulk of texture state here */
- memcpy(&texstate->Texture, &ctx->Texture, sizeof(ctx->Texture));
-
- /* Save references to the currently bound texture objects so they don't
- * accidentally get deleted while referenced in the attribute stack.
- */
- for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
- for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
- _mesa_reference_texobj(&texstate->SavedTexRef[u][tex],
- ctx->Texture.Unit[u].CurrentTex[tex]);
- }
- }
-
- /* copy state/contents of the currently bound texture objects */
- for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
- for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
- _mesa_copy_texture_object(&texstate->SavedObj[u][tex],
- ctx->Texture.Unit[u].CurrentTex[tex]);
- }
- }
-
- _mesa_unlock_context_textures(ctx);
-
- save_attrib_data(&head, GL_TEXTURE_BIT, texstate);
- }
-
- if (mask & GL_TRANSFORM_BIT) {
- struct gl_transform_attrib *attr;
- attr = MALLOC_STRUCT( gl_transform_attrib );
- memcpy( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
- save_attrib_data(&head, GL_TRANSFORM_BIT, attr);
- }
-
- if (mask & GL_VIEWPORT_BIT) {
- struct gl_viewport_attrib *attr;
- attr = MALLOC_STRUCT( gl_viewport_attrib );
- memcpy( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
- save_attrib_data(&head, GL_VIEWPORT_BIT, attr);
- }
-
- /* GL_ARB_multisample */
- if (mask & GL_MULTISAMPLE_BIT_ARB) {
- struct gl_multisample_attrib *attr;
- attr = MALLOC_STRUCT( gl_multisample_attrib );
- memcpy( attr, &ctx->Multisample, sizeof(struct gl_multisample_attrib) );
- save_attrib_data(&head, GL_MULTISAMPLE_BIT_ARB, attr);
- }
-
-end:
- ctx->AttribStack[ctx->AttribStackDepth] = head;
- ctx->AttribStackDepth++;
-}
-
-
-
-static void
-pop_enable_group(struct gl_context *ctx, const struct gl_enable_attrib *enable)
-{
- const GLuint curTexUnitSave = ctx->Texture.CurrentUnit;
- GLuint i;
-
-#define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
- if ((VALUE) != (NEWVALUE)) { \
- _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
- }
-
- TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST);
- if (ctx->Color.BlendEnabled != enable->Blend) {
- if (ctx->Extensions.EXT_draw_buffers2) {
- GLuint i;
- for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
- _mesa_set_enablei(ctx, GL_BLEND, i, (enable->Blend >> i) & 1);
- }
- }
- else {
- _mesa_set_enable(ctx, GL_BLEND, (enable->Blend & 1));
- }
- }
-
- for (i=0;i<MAX_CLIP_PLANES;i++) {
- const GLuint mask = 1 << i;
- if ((ctx->Transform.ClipPlanesEnabled & mask) != (enable->ClipPlanes & mask))
- _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i),
- (GLboolean) ((enable->ClipPlanes & mask) ? GL_TRUE : GL_FALSE));
- }
-
- TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial,
- GL_COLOR_MATERIAL);
- TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
- TEST_AND_UPDATE(ctx->Transform.DepthClamp, enable->DepthClamp,
- GL_DEPTH_CLAMP);
- TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
- TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
- TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG);
- TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING);
- TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH);
- TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple,
- GL_LINE_STIPPLE);
- TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp,
- GL_INDEX_LOGIC_OP);
- TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp,
- GL_COLOR_LOGIC_OP);
-
- TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4);
- TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX);
- TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL);
- TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1,
- GL_MAP1_TEXTURE_COORD_1);
- TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2,
- GL_MAP1_TEXTURE_COORD_2);
- TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3,
- GL_MAP1_TEXTURE_COORD_3);
- TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4,
- GL_MAP1_TEXTURE_COORD_4);
- TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3,
- GL_MAP1_VERTEX_3);
- TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4,
- GL_MAP1_VERTEX_4);
- for (i = 0; i < 16; i++) {
- TEST_AND_UPDATE(ctx->Eval.Map1Attrib[i], enable->Map1Attrib[i],
- GL_MAP1_VERTEX_ATTRIB0_4_NV + i);
- }
-
- TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4);
- TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX);
- TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL);
- TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1,
- GL_MAP2_TEXTURE_COORD_1);
- TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2,
- GL_MAP2_TEXTURE_COORD_2);
- TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3,
- GL_MAP2_TEXTURE_COORD_3);
- TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4,
- GL_MAP2_TEXTURE_COORD_4);
- TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3,
- GL_MAP2_VERTEX_3);
- TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4,
- GL_MAP2_VERTEX_4);
- for (i = 0; i < 16; i++) {
- TEST_AND_UPDATE(ctx->Eval.Map2Attrib[i], enable->Map2Attrib[i],
- GL_MAP2_VERTEX_ATTRIB0_4_NV + i);
- }
-
- TEST_AND_UPDATE(ctx->Eval.AutoNormal, enable->AutoNormal, GL_AUTO_NORMAL);
- TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE);
- TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals,
- GL_RESCALE_NORMAL_EXT);
- TEST_AND_UPDATE(ctx->Transform.RasterPositionUnclipped,
- enable->RasterPositionUnclipped,
- GL_RASTER_POSITION_UNCLIPPED_IBM);
- TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth,
- GL_POINT_SMOOTH);
- if (ctx->Extensions.NV_point_sprite || ctx->Extensions.ARB_point_sprite) {
- TEST_AND_UPDATE(ctx->Point.PointSprite, enable->PointSprite,
- GL_POINT_SPRITE_NV);
- }
- TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint,
- GL_POLYGON_OFFSET_POINT);
- TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine,
- GL_POLYGON_OFFSET_LINE);
- TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill,
- GL_POLYGON_OFFSET_FILL);
- TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth,
- GL_POLYGON_SMOOTH);
- TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple,
- GL_POLYGON_STIPPLE);
- TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST);
- TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST);
- if (ctx->Extensions.EXT_stencil_two_side) {
- TEST_AND_UPDATE(ctx->Stencil.TestTwoSide, enable->StencilTwoSide, GL_STENCIL_TEST_TWO_SIDE_EXT);
- }
- TEST_AND_UPDATE(ctx->Multisample.Enabled, enable->MultisampleEnabled,
- GL_MULTISAMPLE_ARB);
- TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToCoverage,
- enable->SampleAlphaToCoverage,
- GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
- TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToOne,
- enable->SampleAlphaToOne,
- GL_SAMPLE_ALPHA_TO_ONE_ARB);
- TEST_AND_UPDATE(ctx->Multisample.SampleCoverage,
- enable->SampleCoverage,
- GL_SAMPLE_COVERAGE_ARB);
- TEST_AND_UPDATE(ctx->Multisample.SampleCoverageInvert,
- enable->SampleCoverageInvert,
- GL_SAMPLE_COVERAGE_INVERT_ARB);
- /* GL_ARB_vertex_program, GL_NV_vertex_program */
- TEST_AND_UPDATE(ctx->VertexProgram.Enabled,
- enable->VertexProgram,
- GL_VERTEX_PROGRAM_ARB);
- TEST_AND_UPDATE(ctx->VertexProgram.PointSizeEnabled,
- enable->VertexProgramPointSize,
- GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
- TEST_AND_UPDATE(ctx->VertexProgram.TwoSideEnabled,
- enable->VertexProgramTwoSide,
- GL_VERTEX_PROGRAM_TWO_SIDE_ARB);
-
-#undef TEST_AND_UPDATE
-
- /* texture unit enables */
- for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
- const GLbitfield enabled = enable->Texture[i];
- const GLbitfield genEnabled = enable->TexGen[i];
-
- if (ctx->Texture.Unit[i].Enabled != enabled) {
- _mesa_ActiveTextureARB(GL_TEXTURE0 + i);
-
- _mesa_set_enable(ctx, GL_TEXTURE_1D,
- (enabled & TEXTURE_1D_BIT) ? GL_TRUE : GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_2D,
- (enabled & TEXTURE_2D_BIT) ? GL_TRUE : GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_3D,
- (enabled & TEXTURE_3D_BIT) ? GL_TRUE : GL_FALSE);
- if (ctx->Extensions.NV_texture_rectangle) {
- _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_ARB,
- (enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE);
- }
- if (ctx->Extensions.ARB_texture_cube_map) {
- _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP,
- (enabled & TEXTURE_CUBE_BIT) ? GL_TRUE : GL_FALSE);
- }
- if (ctx->Extensions.MESA_texture_array) {
- _mesa_set_enable(ctx, GL_TEXTURE_1D_ARRAY_EXT,
- (enabled & TEXTURE_1D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_2D_ARRAY_EXT,
- (enabled & TEXTURE_2D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
- }
- }
-
- if (ctx->Texture.Unit[i].TexGenEnabled != genEnabled) {
- _mesa_ActiveTextureARB(GL_TEXTURE0 + i);
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_S,
- (genEnabled & S_BIT) ? GL_TRUE : GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_T,
- (genEnabled & T_BIT) ? GL_TRUE : GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_R,
- (genEnabled & R_BIT) ? GL_TRUE : GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q,
- (genEnabled & Q_BIT) ? GL_TRUE : GL_FALSE);
- }
- }
-
- _mesa_ActiveTextureARB(GL_TEXTURE0 + curTexUnitSave);
-}
-
-
-/**
- * Pop/restore texture attribute/group state.
- */
-static void
-pop_texture_group(struct gl_context *ctx, struct texture_state *texstate)
-{
- GLuint u;
-
- _mesa_lock_context_textures(ctx);
-
- for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
- const struct gl_texture_unit *unit = &texstate->Texture.Unit[u];
- GLuint tgt;
-
- _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + u);
- _mesa_set_enable(ctx, GL_TEXTURE_1D,
- (unit->Enabled & TEXTURE_1D_BIT) ? GL_TRUE : GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_2D,
- (unit->Enabled & TEXTURE_2D_BIT) ? GL_TRUE : GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_3D,
- (unit->Enabled & TEXTURE_3D_BIT) ? GL_TRUE : GL_FALSE);
- if (ctx->Extensions.ARB_texture_cube_map) {
- _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP_ARB,
- (unit->Enabled & TEXTURE_CUBE_BIT) ? GL_TRUE : GL_FALSE);
- }
- if (ctx->Extensions.NV_texture_rectangle) {
- _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_NV,
- (unit->Enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE);
- }
- if (ctx->Extensions.MESA_texture_array) {
- _mesa_set_enable(ctx, GL_TEXTURE_1D_ARRAY_EXT,
- (unit->Enabled & TEXTURE_1D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
- _mesa_set_enable(ctx, GL_TEXTURE_2D_ARRAY_EXT,
- (unit->Enabled & TEXTURE_2D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
- }
-
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->EnvMode);
- _mesa_TexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, unit->EnvColor);
- _mesa_TexGeni(GL_S, GL_TEXTURE_GEN_MODE, unit->GenS.Mode);
- _mesa_TexGeni(GL_T, GL_TEXTURE_GEN_MODE, unit->GenT.Mode);
- _mesa_TexGeni(GL_R, GL_TEXTURE_GEN_MODE, unit->GenR.Mode);
- _mesa_TexGeni(GL_Q, GL_TEXTURE_GEN_MODE, unit->GenQ.Mode);
- _mesa_TexGenfv(GL_S, GL_OBJECT_PLANE, unit->GenS.ObjectPlane);
- _mesa_TexGenfv(GL_T, GL_OBJECT_PLANE, unit->GenT.ObjectPlane);
- _mesa_TexGenfv(GL_R, GL_OBJECT_PLANE, unit->GenR.ObjectPlane);
- _mesa_TexGenfv(GL_Q, GL_OBJECT_PLANE, unit->GenQ.ObjectPlane);
- /* Eye plane done differently to avoid re-transformation */
- {
- struct gl_texture_unit *destUnit = &ctx->Texture.Unit[u];
- COPY_4FV(destUnit->GenS.EyePlane, unit->GenS.EyePlane);
- COPY_4FV(destUnit->GenT.EyePlane, unit->GenT.EyePlane);
- COPY_4FV(destUnit->GenR.EyePlane, unit->GenR.EyePlane);
- COPY_4FV(destUnit->GenQ.EyePlane, unit->GenQ.EyePlane);
- if (ctx->Driver.TexGen) {
- ctx->Driver.TexGen(ctx, GL_S, GL_EYE_PLANE, unit->GenS.EyePlane);
- ctx->Driver.TexGen(ctx, GL_T, GL_EYE_PLANE, unit->GenT.EyePlane);
- ctx->Driver.TexGen(ctx, GL_R, GL_EYE_PLANE, unit->GenR.EyePlane);
- ctx->Driver.TexGen(ctx, GL_Q, GL_EYE_PLANE, unit->GenQ.EyePlane);
- }
- }
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_S,
- ((unit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE));
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_T,
- ((unit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE));
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_R,
- ((unit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE));
- _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q,
- ((unit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE));
- if (ctx->Extensions.EXT_texture_lod_bias) {
- _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
- GL_TEXTURE_LOD_BIAS_EXT, unit->LodBias);
- }
- if (ctx->Extensions.EXT_texture_env_combine ||
- ctx->Extensions.ARB_texture_env_combine) {
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,
- unit->Combine.ModeRGB);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA,
- unit->Combine.ModeA);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB,
- unit->Combine.SourceRGB[0]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB,
- unit->Combine.SourceRGB[1]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB,
- unit->Combine.SourceRGB[2]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA,
- unit->Combine.SourceA[0]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA,
- unit->Combine.SourceA[1]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA,
- unit->Combine.SourceA[2]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB,
- unit->Combine.OperandRGB[0]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB,
- unit->Combine.OperandRGB[1]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB,
- unit->Combine.OperandRGB[2]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA,
- unit->Combine.OperandA[0]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA,
- unit->Combine.OperandA[1]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA,
- unit->Combine.OperandA[2]);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE,
- 1 << unit->Combine.ScaleShiftRGB);
- _mesa_TexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE,
- 1 << unit->Combine.ScaleShiftA);
- }
-
- /* Restore texture object state for each target */
- for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
- const struct gl_texture_object *obj = NULL;
- GLenum target;
-
- obj = &texstate->SavedObj[u][tgt];
-
- /* don't restore state for unsupported targets to prevent
- * raising GL errors.
- */
- if (obj->Target == GL_TEXTURE_CUBE_MAP_ARB &&
- !ctx->Extensions.ARB_texture_cube_map) {
- continue;
- }
- else if (obj->Target == GL_TEXTURE_RECTANGLE_NV &&
- !ctx->Extensions.NV_texture_rectangle) {
- continue;
- }
- else if ((obj->Target == GL_TEXTURE_1D_ARRAY_EXT ||
- obj->Target == GL_TEXTURE_2D_ARRAY_EXT) &&
- !ctx->Extensions.MESA_texture_array) {
- continue;
- }
-
- target = obj->Target;
-
- _mesa_BindTexture(target, obj->Name);
-
- _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, obj->BorderColor.f);
- _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, obj->WrapS);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, obj->WrapT);
- _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, obj->WrapR);
- _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, obj->MinFilter);
- _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, obj->MagFilter);
- _mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, obj->MinLod);
- _mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, obj->MaxLod);
- _mesa_TexParameterf(target, GL_TEXTURE_LOD_BIAS, obj->LodBias);
- _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, obj->BaseLevel);
- if (target != GL_TEXTURE_RECTANGLE_ARB)
- _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->MaxLevel);
- if (ctx->Extensions.EXT_texture_filter_anisotropic) {
- _mesa_TexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
- obj->MaxAnisotropy);
- }
- if (ctx->Extensions.ARB_shadow_ambient) {
- _mesa_TexParameterf(target, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB,
- obj->CompareFailValue);
- }
- }
-
- /* remove saved references to the texture objects */
- for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
- _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL);
- }
- }
-
- _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + texstate->Texture.CurrentUnit);
-
- _mesa_unlock_context_textures(ctx);
-}
-
-
-/*
- * This function is kind of long just because we have to call a lot
- * of device driver functions to update device driver state.
- *
- * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
- * in order to restore GL state. This isn't terribly efficient but it
- * ensures that dirty flags and any derived state gets updated correctly.
- * We could at least check if the value to restore equals the current value
- * and then skip the Mesa call.
- */
-void GLAPIENTRY
-_mesa_PopAttrib(void)
-{
- struct gl_attrib_node *attr, *next;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (ctx->AttribStackDepth == 0) {
- _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
- return;
- }
-
- ctx->AttribStackDepth--;
- attr = ctx->AttribStack[ctx->AttribStackDepth];
-
- while (attr) {
-
- if (MESA_VERBOSE & VERBOSE_API) {
- _mesa_debug(ctx, "glPopAttrib %s\n",
- _mesa_lookup_enum_by_nr(attr->kind));
- }
-
- switch (attr->kind) {
- case GL_ACCUM_BUFFER_BIT:
- {
- const struct gl_accum_attrib *accum;
- accum = (const struct gl_accum_attrib *) attr->data;
- _mesa_ClearAccum(accum->ClearColor[0],
- accum->ClearColor[1],
- accum->ClearColor[2],
- accum->ClearColor[3]);
- }
- break;
- case GL_COLOR_BUFFER_BIT:
- {
- const struct gl_colorbuffer_attrib *color;
-
- color = (const struct gl_colorbuffer_attrib *) attr->data;
- _mesa_ClearIndex((GLfloat) color->ClearIndex);
- _mesa_ClearColor(color->ClearColor[0],
- color->ClearColor[1],
- color->ClearColor[2],
- color->ClearColor[3]);
- _mesa_IndexMask(color->IndexMask);
- if (!ctx->Extensions.EXT_draw_buffers2) {
- _mesa_ColorMask((GLboolean) (color->ColorMask[0][0] != 0),
- (GLboolean) (color->ColorMask[0][1] != 0),
- (GLboolean) (color->ColorMask[0][2] != 0),
- (GLboolean) (color->ColorMask[0][3] != 0));
- }
- else {
- GLuint i;
- for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
- _mesa_ColorMaskIndexed(i,
- (GLboolean) (color->ColorMask[i][0] != 0),
- (GLboolean) (color->ColorMask[i][1] != 0),
- (GLboolean) (color->ColorMask[i][2] != 0),
- (GLboolean) (color->ColorMask[i][3] != 0));
- }
- }
- {
- /* Need to determine if more than one color output is
- * specified. If so, call glDrawBuffersARB, else call
- * glDrawBuffer(). This is a subtle, but essential point
- * since GL_FRONT (for example) is illegal for the former
- * function, but legal for the later.
- */
- GLboolean multipleBuffers = GL_FALSE;
- GLuint i;
-
- for (i = 1; i < ctx->Const.MaxDrawBuffers; i++) {
- if (color->DrawBuffer[i] != GL_NONE) {
- multipleBuffers = GL_TRUE;
- break;
- }
- }
- /* Call the API_level functions, not _mesa_drawbuffers()
- * since we need to do error checking on the pop'd
- * GL_DRAW_BUFFER.
- * Ex: if GL_FRONT were pushed, but we're popping with a
- * user FBO bound, GL_FRONT will be illegal and we'll need
- * to record that error. Per OpenGL ARB decision.
- */
- if (multipleBuffers)
- _mesa_DrawBuffersARB(ctx->Const.MaxDrawBuffers,
- color->DrawBuffer);
- else
- _mesa_DrawBuffer(color->DrawBuffer[0]);
- }
- _mesa_set_enable(ctx, GL_ALPHA_TEST, color->AlphaEnabled);
- _mesa_AlphaFunc(color->AlphaFunc, color->AlphaRef);
- if (ctx->Color.BlendEnabled != color->BlendEnabled) {
- if (ctx->Extensions.EXT_draw_buffers2) {
- GLuint i;
- for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
- _mesa_set_enablei(ctx, GL_BLEND, i,
- (color->BlendEnabled >> i) & 1);
- }
- }
- else {
- _mesa_set_enable(ctx, GL_BLEND, (color->BlendEnabled & 1));
- }
- }
- if (ctx->Color._BlendFuncPerBuffer ||
- ctx->Color._BlendEquationPerBuffer) {
- /* set blend per buffer */
- GLuint buf;
- for (buf = 0; buf < ctx->Const.MaxDrawBuffers; buf++) {
- _mesa_BlendFuncSeparatei(buf, color->Blend[buf].SrcRGB,
- color->Blend[buf].DstRGB,
- color->Blend[buf].SrcA,
- color->Blend[buf].DstA);
- _mesa_BlendEquationSeparatei(buf,
- color->Blend[buf].EquationRGB,
- color->Blend[buf].EquationA);
- }
- }
- else {
- /* set same blend modes for all buffers */
- _mesa_BlendFuncSeparateEXT(color->Blend[0].SrcRGB,
- color->Blend[0].DstRGB,
- color->Blend[0].SrcA,
- color->Blend[0].DstA);
- /* This special case is because glBlendEquationSeparateEXT
- * cannot take GL_LOGIC_OP as a parameter.
- */
- if (color->Blend[0].EquationRGB ==
- color->Blend[0].EquationA) {
- _mesa_BlendEquation(color->Blend[0].EquationRGB);
- }
- else {
- _mesa_BlendEquationSeparateEXT(
- color->Blend[0].EquationRGB,
- color->Blend[0].EquationA);
- }
- }
- _mesa_BlendColor(color->BlendColor[0],
- color->BlendColor[1],
- color->BlendColor[2],
- color->BlendColor[3]);
- _mesa_LogicOp(color->LogicOp);
- _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP,
- color->ColorLogicOpEnabled);
- _mesa_set_enable(ctx, GL_INDEX_LOGIC_OP,
- color->IndexLogicOpEnabled);
- _mesa_set_enable(ctx, GL_DITHER, color->DitherFlag);
- }
- break;
- case GL_CURRENT_BIT:
- FLUSH_CURRENT( ctx, 0 );
- memcpy( &ctx->Current, attr->data,
- sizeof(struct gl_current_attrib) );
- break;
- case GL_DEPTH_BUFFER_BIT:
- {
- const struct gl_depthbuffer_attrib *depth;
- depth = (const struct gl_depthbuffer_attrib *) attr->data;
- _mesa_DepthFunc(depth->Func);
- _mesa_ClearDepth(depth->Clear);
- _mesa_set_enable(ctx, GL_DEPTH_TEST, depth->Test);
- _mesa_DepthMask(depth->Mask);
- }
- break;
- case GL_ENABLE_BIT:
- {
- const struct gl_enable_attrib *enable;
- enable = (const struct gl_enable_attrib *) attr->data;
- pop_enable_group(ctx, enable);
- ctx->NewState |= _NEW_ALL;
- }
- break;
- case GL_EVAL_BIT:
- memcpy( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
- ctx->NewState |= _NEW_EVAL;
- break;
- case GL_FOG_BIT:
- {
- const struct gl_fog_attrib *fog;
- fog = (const struct gl_fog_attrib *) attr->data;
- _mesa_set_enable(ctx, GL_FOG, fog->Enabled);
- _mesa_Fogfv(GL_FOG_COLOR, fog->Color);
- _mesa_Fogf(GL_FOG_DENSITY, fog->Density);
- _mesa_Fogf(GL_FOG_START, fog->Start);
- _mesa_Fogf(GL_FOG_END, fog->End);
- _mesa_Fogf(GL_FOG_INDEX, fog->Index);
- _mesa_Fogi(GL_FOG_MODE, fog->Mode);
- }
- break;
- case GL_HINT_BIT:
- {
- const struct gl_hint_attrib *hint;
- hint = (const struct gl_hint_attrib *) attr->data;
- _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT,
- hint->PerspectiveCorrection );
- _mesa_Hint(GL_POINT_SMOOTH_HINT, hint->PointSmooth);
- _mesa_Hint(GL_LINE_SMOOTH_HINT, hint->LineSmooth);
- _mesa_Hint(GL_POLYGON_SMOOTH_HINT, hint->PolygonSmooth);
- _mesa_Hint(GL_FOG_HINT, hint->Fog);
- _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT,
- hint->ClipVolumeClipping);
- _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB,
- hint->TextureCompression);
- }
- break;
- case GL_LIGHTING_BIT:
- {
- GLuint i;
- const struct gl_light_attrib *light;
- light = (const struct gl_light_attrib *) attr->data;
- /* lighting enable */
- _mesa_set_enable(ctx, GL_LIGHTING, light->Enabled);
- /* per-light state */
- if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top))
- _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
-
- for (i = 0; i < ctx->Const.MaxLights; i++) {
- const struct gl_light *l = &light->Light[i];
- _mesa_set_enable(ctx, GL_LIGHT0 + i, l->Enabled);
- _mesa_light(ctx, i, GL_AMBIENT, l->Ambient);
- _mesa_light(ctx, i, GL_DIFFUSE, l->Diffuse);
- _mesa_light(ctx, i, GL_SPECULAR, l->Specular );
- _mesa_light(ctx, i, GL_POSITION, l->EyePosition);
- _mesa_light(ctx, i, GL_SPOT_DIRECTION, l->SpotDirection);
- {
- GLfloat p[4] = { 0 };
- p[0] = l->SpotExponent;
- _mesa_light(ctx, i, GL_SPOT_EXPONENT, p);
- }
- {
- GLfloat p[4] = { 0 };
- p[0] = l->SpotCutoff;
- _mesa_light(ctx, i, GL_SPOT_CUTOFF, p);
- }
- {
- GLfloat p[4] = { 0 };
- p[0] = l->ConstantAttenuation;
- _mesa_light(ctx, i, GL_CONSTANT_ATTENUATION, p);
- }
- {
- GLfloat p[4] = { 0 };
- p[0] = l->LinearAttenuation;
- _mesa_light(ctx, i, GL_LINEAR_ATTENUATION, p);
- }
- {
- GLfloat p[4] = { 0 };
- p[0] = l->QuadraticAttenuation;
- _mesa_light(ctx, i, GL_QUADRATIC_ATTENUATION, p);
- }
- }
- /* light model */
- _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT,
- light->Model.Ambient);
- _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER,
- (GLfloat) light->Model.LocalViewer);
- _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE,
- (GLfloat) light->Model.TwoSide);
- _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL,
- (GLfloat) light->Model.ColorControl);
- /* shade model */
- _mesa_ShadeModel(light->ShadeModel);
- /* color material */
- _mesa_ColorMaterial(light->ColorMaterialFace,
- light->ColorMaterialMode);
- _mesa_set_enable(ctx, GL_COLOR_MATERIAL,
- light->ColorMaterialEnabled);
- /* materials */
- memcpy(&ctx->Light.Material, &light->Material,
- sizeof(struct gl_material));
- }
- break;
- case GL_LINE_BIT:
- {
- const struct gl_line_attrib *line;
- line = (const struct gl_line_attrib *) attr->data;
- _mesa_set_enable(ctx, GL_LINE_SMOOTH, line->SmoothFlag);
- _mesa_set_enable(ctx, GL_LINE_STIPPLE, line->StippleFlag);
- _mesa_LineStipple(line->StippleFactor, line->StipplePattern);
- _mesa_LineWidth(line->Width);
- }
- break;
- case GL_LIST_BIT:
- memcpy( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
- break;
- case GL_PIXEL_MODE_BIT:
- memcpy( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
- /* XXX what other pixel state needs to be set by function calls? */
- _mesa_ReadBuffer(ctx->Pixel.ReadBuffer);
- ctx->NewState |= _NEW_PIXEL;
- break;
- case GL_POINT_BIT:
- {
- const struct gl_point_attrib *point;
- point = (const struct gl_point_attrib *) attr->data;
- _mesa_PointSize(point->Size);
- _mesa_set_enable(ctx, GL_POINT_SMOOTH, point->SmoothFlag);
- if (ctx->Extensions.EXT_point_parameters) {
- _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT,
- point->Params);
- _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT,
- point->MinSize);
- _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT,
- point->MaxSize);
- _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT,
- point->Threshold);
- }
- if (ctx->Extensions.NV_point_sprite
- || ctx->Extensions.ARB_point_sprite) {
- GLuint u;
- for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
- _mesa_TexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV,
- (GLint) point->CoordReplace[u]);
- }
- _mesa_set_enable(ctx, GL_POINT_SPRITE_NV,point->PointSprite);
- if (ctx->Extensions.NV_point_sprite)
- _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV,
- ctx->Point.SpriteRMode);
- _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN,
- (GLfloat)ctx->Point.SpriteOrigin);
- }
- }
- break;
- case GL_POLYGON_BIT:
- {
- const struct gl_polygon_attrib *polygon;
- polygon = (const struct gl_polygon_attrib *) attr->data;
- _mesa_CullFace(polygon->CullFaceMode);
- _mesa_FrontFace(polygon->FrontFace);
- _mesa_PolygonMode(GL_FRONT, polygon->FrontMode);
- _mesa_PolygonMode(GL_BACK, polygon->BackMode);
- _mesa_PolygonOffset(polygon->OffsetFactor,
- polygon->OffsetUnits);
- _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, polygon->SmoothFlag);
- _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, polygon->StippleFlag);
- _mesa_set_enable(ctx, GL_CULL_FACE, polygon->CullFlag);
- _mesa_set_enable(ctx, GL_POLYGON_OFFSET_POINT,
- polygon->OffsetPoint);
- _mesa_set_enable(ctx, GL_POLYGON_OFFSET_LINE,
- polygon->OffsetLine);
- _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL,
- polygon->OffsetFill);
- }
- break;
- case GL_POLYGON_STIPPLE_BIT:
- memcpy( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
- ctx->NewState |= _NEW_POLYGONSTIPPLE;
- if (ctx->Driver.PolygonStipple)
- ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data );
- break;
- case GL_SCISSOR_BIT:
- {
- const struct gl_scissor_attrib *scissor;
- scissor = (const struct gl_scissor_attrib *) attr->data;
- _mesa_Scissor(scissor->X, scissor->Y,
- scissor->Width, scissor->Height);
- _mesa_set_enable(ctx, GL_SCISSOR_TEST, scissor->Enabled);
- }
- break;
- case GL_STENCIL_BUFFER_BIT:
- {
- const struct gl_stencil_attrib *stencil;
- stencil = (const struct gl_stencil_attrib *) attr->data;
- _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled);
- _mesa_ClearStencil(stencil->Clear);
- if (ctx->Extensions.EXT_stencil_two_side) {
- _mesa_set_enable(ctx, GL_STENCIL_TEST_TWO_SIDE_EXT,
- stencil->TestTwoSide);
- _mesa_ActiveStencilFaceEXT(stencil->ActiveFace
- ? GL_BACK : GL_FRONT);
- }
- /* front state */
- _mesa_StencilFuncSeparate(GL_FRONT,
- stencil->Function[0],
- stencil->Ref[0],
- stencil->ValueMask[0]);
- _mesa_StencilMaskSeparate(GL_FRONT, stencil->WriteMask[0]);
- _mesa_StencilOpSeparate(GL_FRONT, stencil->FailFunc[0],
- stencil->ZFailFunc[0],
- stencil->ZPassFunc[0]);
- /* back state */
- _mesa_StencilFuncSeparate(GL_BACK,
- stencil->Function[1],
- stencil->Ref[1],
- stencil->ValueMask[1]);
- _mesa_StencilMaskSeparate(GL_BACK, stencil->WriteMask[1]);
- _mesa_StencilOpSeparate(GL_BACK, stencil->FailFunc[1],
- stencil->ZFailFunc[1],
- stencil->ZPassFunc[1]);
- }
- break;
- case GL_TRANSFORM_BIT:
- {
- GLuint i;
- const struct gl_transform_attrib *xform;
- xform = (const struct gl_transform_attrib *) attr->data;
- _mesa_MatrixMode(xform->MatrixMode);
- if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top))
- _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
-
- /* restore clip planes */
- for (i = 0; i < MAX_CLIP_PLANES; i++) {
- const GLuint mask = 1 << i;
- const GLfloat *eyePlane = xform->EyeUserPlane[i];
- COPY_4V(ctx->Transform.EyeUserPlane[i], eyePlane);
- if (xform->ClipPlanesEnabled & mask) {
- _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_TRUE);
- }
- else {
- _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE);
- }
- if (ctx->Driver.ClipPlane)
- ctx->Driver.ClipPlane( ctx, GL_CLIP_PLANE0 + i, eyePlane );
- }
-
- /* normalize/rescale */
- if (xform->Normalize != ctx->Transform.Normalize)
- _mesa_set_enable(ctx, GL_NORMALIZE,ctx->Transform.Normalize);
- if (xform->RescaleNormals != ctx->Transform.RescaleNormals)
- _mesa_set_enable(ctx, GL_RESCALE_NORMAL_EXT,
- ctx->Transform.RescaleNormals);
- if (xform->DepthClamp != ctx->Transform.DepthClamp)
- _mesa_set_enable(ctx, GL_DEPTH_CLAMP,
- ctx->Transform.DepthClamp);
- }
- break;
- case GL_TEXTURE_BIT:
- /* Take care of texture object reference counters */
- {
- struct texture_state *texstate
- = (struct texture_state *) attr->data;
- pop_texture_group(ctx, texstate);
- ctx->NewState |= _NEW_TEXTURE;
- }
- break;
- case GL_VIEWPORT_BIT:
- {
- const struct gl_viewport_attrib *vp;
- vp = (const struct gl_viewport_attrib *) attr->data;
- _mesa_Viewport(vp->X, vp->Y, vp->Width, vp->Height);
- _mesa_DepthRange(vp->Near, vp->Far);
- }
- break;
- case GL_MULTISAMPLE_BIT_ARB:
- {
- const struct gl_multisample_attrib *ms;
- ms = (const struct gl_multisample_attrib *) attr->data;
- _mesa_SampleCoverageARB(ms->SampleCoverageValue,
- ms->SampleCoverageInvert);
- }
- break;
-
- default:
- _mesa_problem( ctx, "Bad attrib flag in PopAttrib");
- break;
- }
-
- next = attr->next;
- FREE( attr->data );
- FREE( attr );
- attr = next;
- }
-}
-
-
-/**
- * Helper for incrementing/decrementing vertex buffer object reference
- * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
- */
-static void
-adjust_buffer_object_ref_counts(struct gl_array_object *arrayObj, GLint step)
-{
- GLuint i;
-
- arrayObj->Vertex.BufferObj->RefCount += step;
- arrayObj->Weight.BufferObj->RefCount += step;
- arrayObj->Normal.BufferObj->RefCount += step;
- arrayObj->Color.BufferObj->RefCount += step;
- arrayObj->SecondaryColor.BufferObj->RefCount += step;
- arrayObj->FogCoord.BufferObj->RefCount += step;
- arrayObj->Index.BufferObj->RefCount += step;
- arrayObj->EdgeFlag.BufferObj->RefCount += step;
- for (i = 0; i < Elements(arrayObj->TexCoord); i++)
- arrayObj->TexCoord[i].BufferObj->RefCount += step;
- for (i = 0; i < Elements(arrayObj->VertexAttrib); i++)
- arrayObj->VertexAttrib[i].BufferObj->RefCount += step;
-}
-
-
-/**
- * Copy gl_pixelstore_attrib from src to dst, updating buffer
- * object refcounts.
- */
-static void
-copy_pixelstore(struct gl_context *ctx,
- struct gl_pixelstore_attrib *dst,
- const struct gl_pixelstore_attrib *src)
-{
- dst->Alignment = src->Alignment;
- dst->RowLength = src->RowLength;
- dst->SkipPixels = src->SkipPixels;
- dst->SkipRows = src->SkipRows;
- dst->ImageHeight = src->ImageHeight;
- dst->SkipImages = src->SkipImages;
- dst->SwapBytes = src->SwapBytes;
- dst->LsbFirst = src->LsbFirst;
- dst->ClientStorage = src->ClientStorage;
- dst->Invert = src->Invert;
- _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
-}
-
-
-#define GL_CLIENT_PACK_BIT (1<<20)
-#define GL_CLIENT_UNPACK_BIT (1<<21)
-
-
-void GLAPIENTRY
-_mesa_PushClientAttrib(GLbitfield mask)
-{
- struct gl_attrib_node *head;
-
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (ctx->ClientAttribStackDepth >= MAX_CLIENT_ATTRIB_STACK_DEPTH) {
- _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
- return;
- }
-
- /* Build linked list of attribute nodes which save all attribute
- * groups specified by the mask.
- */
- head = NULL;
-
- if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
- struct gl_pixelstore_attrib *attr;
- /* packing attribs */
- attr = CALLOC_STRUCT( gl_pixelstore_attrib );
- copy_pixelstore(ctx, attr, &ctx->Pack);
- save_attrib_data(&head, GL_CLIENT_PACK_BIT, attr);
- /* unpacking attribs */
- attr = CALLOC_STRUCT( gl_pixelstore_attrib );
- copy_pixelstore(ctx, attr, &ctx->Unpack);
- save_attrib_data(&head, GL_CLIENT_UNPACK_BIT, attr);
- }
-
- if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
- struct gl_array_attrib *attr;
- struct gl_array_object *obj;
-
- attr = MALLOC_STRUCT( gl_array_attrib );
- obj = MALLOC_STRUCT( gl_array_object );
-
-#if FEATURE_ARB_vertex_buffer_object
- /* increment ref counts since we're copying pointers to these objects */
- ctx->Array.ArrayBufferObj->RefCount++;
- ctx->Array.ElementArrayBufferObj->RefCount++;
-#endif
-
- memcpy( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
- memcpy( obj, ctx->Array.ArrayObj, sizeof(struct gl_array_object) );
-
- attr->ArrayObj = obj;
-
- save_attrib_data(&head, GL_CLIENT_VERTEX_ARRAY_BIT, attr);
-
- /* bump reference counts on buffer objects */
- adjust_buffer_object_ref_counts(ctx->Array.ArrayObj, 1);
- }
-
- ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
- ctx->ClientAttribStackDepth++;
-}
-
-
-
-
-void GLAPIENTRY
-_mesa_PopClientAttrib(void)
-{
- struct gl_attrib_node *node, *next;
-
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (ctx->ClientAttribStackDepth == 0) {
- _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
- return;
- }
-
- ctx->ClientAttribStackDepth--;
- node = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
-
- while (node) {
- switch (node->kind) {
- case GL_CLIENT_PACK_BIT:
- {
- struct gl_pixelstore_attrib *store =
- (struct gl_pixelstore_attrib *) node->data;
- copy_pixelstore(ctx, &ctx->Pack, store);
- _mesa_reference_buffer_object(ctx, &store->BufferObj, NULL);
- }
- ctx->NewState |= _NEW_PACKUNPACK;
- break;
- case GL_CLIENT_UNPACK_BIT:
- {
- struct gl_pixelstore_attrib *store =
- (struct gl_pixelstore_attrib *) node->data;
- copy_pixelstore(ctx, &ctx->Unpack, store);
- _mesa_reference_buffer_object(ctx, &store->BufferObj, NULL);
- }
- ctx->NewState |= _NEW_PACKUNPACK;
- break;
- case GL_CLIENT_VERTEX_ARRAY_BIT: {
- struct gl_array_attrib * data =
- (struct gl_array_attrib *) node->data;
-
- adjust_buffer_object_ref_counts(ctx->Array.ArrayObj, -1);
-
- ctx->Array.ActiveTexture = data->ActiveTexture;
- if (data->LockCount != 0)
- _mesa_LockArraysEXT(data->LockFirst, data->LockCount);
- else if (ctx->Array.LockCount)
- _mesa_UnlockArraysEXT();
-
- _mesa_BindVertexArrayAPPLE( data->ArrayObj->Name );
-
-#if FEATURE_ARB_vertex_buffer_object
- _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB,
- data->ArrayBufferObj->Name);
- _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
- data->ElementArrayBufferObj->Name);
-#endif
-
- memcpy( ctx->Array.ArrayObj, data->ArrayObj,
- sizeof( struct gl_array_object ) );
-
- FREE( data->ArrayObj );
-
- /* FIXME: Should some bits in ctx->Array->NewState also be set
- * FIXME: here? It seems like it should be set to inclusive-or
- * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
- */
-
- ctx->NewState |= _NEW_ARRAY;
- break;
- }
- default:
- _mesa_problem( ctx, "Bad attrib flag in PopClientAttrib");
- break;
- }
-
- next = node->next;
- FREE( node->data );
- FREE( node );
- node = next;
- }
-}
-
-
-void
-_mesa_init_attrib_dispatch(struct _glapi_table *disp)
-{
- SET_PopAttrib(disp, _mesa_PopAttrib);
- SET_PushAttrib(disp, _mesa_PushAttrib);
- SET_PopClientAttrib(disp, _mesa_PopClientAttrib);
- SET_PushClientAttrib(disp, _mesa_PushClientAttrib);
-}
-
-
-#endif /* FEATURE_attrib_stack */
-
-
-/**
- * Free any attribute state data that might be attached to the context.
- */
-void
-_mesa_free_attrib_data(struct gl_context *ctx)
-{
- while (ctx->AttribStackDepth > 0) {
- struct gl_attrib_node *attr, *next;
-
- ctx->AttribStackDepth--;
- attr = ctx->AttribStack[ctx->AttribStackDepth];
-
- while (attr) {
- if (attr->kind == GL_TEXTURE_BIT) {
- struct texture_state *texstate = (struct texture_state*)attr->data;
- GLuint u, tgt;
- /* clear references to the saved texture objects */
- for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
- for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
- _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL);
- }
- }
- }
- else {
- /* any other chunks of state that requires special handling? */
- }
-
- next = attr->next;
- free(attr->data);
- free(attr);
- attr = next;
- }
- }
-}
-
-
-void _mesa_init_attrib( struct gl_context *ctx )
-{
- /* Renderer and client attribute stacks */
- ctx->AttribStackDepth = 0;
- ctx->ClientAttribStackDepth = 0;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.6
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "glheader.h"
+#include "imports.h"
+#include "accum.h"
+#include "arrayobj.h"
+#include "attrib.h"
+#include "blend.h"
+#include "buffers.h"
+#include "bufferobj.h"
+#include "clear.h"
+#include "colormac.h"
+#include "context.h"
+#include "depth.h"
+#include "enable.h"
+#include "enums.h"
+#include "fog.h"
+#include "hint.h"
+#include "light.h"
+#include "lines.h"
+#include "macros.h"
+#include "matrix.h"
+#include "mfeatures.h"
+#include "multisample.h"
+#include "points.h"
+#include "polygon.h"
+#include "scissor.h"
+#include "stencil.h"
+#include "texenv.h"
+#include "texgen.h"
+#include "texobj.h"
+#include "texparam.h"
+#include "texstate.h"
+#include "varray.h"
+#include "viewport.h"
+#include "mtypes.h"
+#include "main/dispatch.h"
+
+
+/**
+ * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
+ */
+struct gl_enable_attrib
+{
+ GLboolean AlphaTest;
+ GLboolean AutoNormal;
+ GLboolean Blend;
+ GLbitfield ClipPlanes;
+ GLboolean ColorMaterial;
+ GLboolean CullFace;
+ GLboolean DepthClamp;
+ GLboolean DepthTest;
+ GLboolean Dither;
+ GLboolean Fog;
+ GLboolean Light[MAX_LIGHTS];
+ GLboolean Lighting;
+ GLboolean LineSmooth;
+ GLboolean LineStipple;
+ GLboolean IndexLogicOp;
+ GLboolean ColorLogicOp;
+
+ GLboolean Map1Color4;
+ GLboolean Map1Index;
+ GLboolean Map1Normal;
+ GLboolean Map1TextureCoord1;
+ GLboolean Map1TextureCoord2;
+ GLboolean Map1TextureCoord3;
+ GLboolean Map1TextureCoord4;
+ GLboolean Map1Vertex3;
+ GLboolean Map1Vertex4;
+ GLboolean Map1Attrib[16]; /* GL_NV_vertex_program */
+ GLboolean Map2Color4;
+ GLboolean Map2Index;
+ GLboolean Map2Normal;
+ GLboolean Map2TextureCoord1;
+ GLboolean Map2TextureCoord2;
+ GLboolean Map2TextureCoord3;
+ GLboolean Map2TextureCoord4;
+ GLboolean Map2Vertex3;
+ GLboolean Map2Vertex4;
+ GLboolean Map2Attrib[16]; /* GL_NV_vertex_program */
+
+ GLboolean Normalize;
+ GLboolean PixelTexture;
+ GLboolean PointSmooth;
+ GLboolean PolygonOffsetPoint;
+ GLboolean PolygonOffsetLine;
+ GLboolean PolygonOffsetFill;
+ GLboolean PolygonSmooth;
+ GLboolean PolygonStipple;
+ GLboolean RescaleNormals;
+ GLboolean Scissor;
+ GLboolean Stencil;
+ GLboolean StencilTwoSide; /* GL_EXT_stencil_two_side */
+ GLboolean MultisampleEnabled; /* GL_ARB_multisample */
+ GLboolean SampleAlphaToCoverage; /* GL_ARB_multisample */
+ GLboolean SampleAlphaToOne; /* GL_ARB_multisample */
+ GLboolean SampleCoverage; /* GL_ARB_multisample */
+ GLboolean SampleCoverageInvert; /* GL_ARB_multisample */
+ GLboolean RasterPositionUnclipped; /* GL_IBM_rasterpos_clip */
+
+ GLbitfield Texture[MAX_TEXTURE_UNITS];
+ GLbitfield TexGen[MAX_TEXTURE_UNITS];
+
+ /* GL_ARB_vertex_program / GL_NV_vertex_program */
+ GLboolean VertexProgram;
+ GLboolean VertexProgramPointSize;
+ GLboolean VertexProgramTwoSide;
+
+ /* GL_ARB_point_sprite / GL_NV_point_sprite */
+ GLboolean PointSprite;
+ GLboolean FragmentShaderATI;
+};
+
+
+/**
+ * Node for the attribute stack.
+ */
+struct gl_attrib_node
+{
+ GLbitfield kind;
+ void *data;
+ struct gl_attrib_node *next;
+};
+
+
+
+/**
+ * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
+ */
+struct texture_state
+{
+ struct gl_texture_attrib Texture; /**< The usual context state */
+
+ /** to save per texture object state (wrap modes, filters, etc): */
+ struct gl_texture_object SavedObj[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS];
+
+ /**
+ * To save references to texture objects (so they don't get accidentally
+ * deleted while saved in the attribute stack).
+ */
+ struct gl_texture_object *SavedTexRef[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS];
+};
+
+
+#if FEATURE_attrib_stack
+
+
+/**
+ * Allocate new attribute node of given type/kind. Attach payload data.
+ * Insert it into the linked list named by 'head'.
+ */
+static void
+save_attrib_data(struct gl_attrib_node **head,
+ GLbitfield kind, void *payload)
+{
+ struct gl_attrib_node *n = MALLOC_STRUCT(gl_attrib_node);
+ if (n) {
+ n->kind = kind;
+ n->data = payload;
+ /* insert at head */
+ n->next = *head;
+ *head = n;
+ }
+ else {
+ /* out of memory! */
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_PushAttrib(GLbitfield mask)
+{
+ struct gl_attrib_node *head;
+
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glPushAttrib %x\n", (int) mask);
+
+ if (ctx->AttribStackDepth >= MAX_ATTRIB_STACK_DEPTH) {
+ _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
+ return;
+ }
+
+ /* Build linked list of attribute nodes which save all attribute */
+ /* groups specified by the mask. */
+ head = NULL;
+
+ if (mask & GL_ACCUM_BUFFER_BIT) {
+ struct gl_accum_attrib *attr;
+ attr = MALLOC_STRUCT( gl_accum_attrib );
+ memcpy( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
+ save_attrib_data(&head, GL_ACCUM_BUFFER_BIT, attr);
+ }
+
+ if (mask & GL_COLOR_BUFFER_BIT) {
+ GLuint i;
+ struct gl_colorbuffer_attrib *attr;
+ attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
+ memcpy( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
+ /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
+ for (i = 0; i < ctx->Const.MaxDrawBuffers; i ++)
+ attr->DrawBuffer[i] = ctx->DrawBuffer->ColorDrawBuffer[i];
+ save_attrib_data(&head, GL_COLOR_BUFFER_BIT, attr);
+ }
+
+ if (mask & GL_CURRENT_BIT) {
+ struct gl_current_attrib *attr;
+ FLUSH_CURRENT( ctx, 0 );
+ attr = MALLOC_STRUCT( gl_current_attrib );
+ memcpy( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
+ save_attrib_data(&head, GL_CURRENT_BIT, attr);
+ }
+
+ if (mask & GL_DEPTH_BUFFER_BIT) {
+ struct gl_depthbuffer_attrib *attr;
+ attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
+ memcpy( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
+ save_attrib_data(&head, GL_DEPTH_BUFFER_BIT, attr);
+ }
+
+ if (mask & GL_ENABLE_BIT) {
+ struct gl_enable_attrib *attr;
+ GLuint i;
+ attr = MALLOC_STRUCT( gl_enable_attrib );
+ /* Copy enable flags from all other attributes into the enable struct. */
+ attr->AlphaTest = ctx->Color.AlphaEnabled;
+ attr->AutoNormal = ctx->Eval.AutoNormal;
+ attr->Blend = ctx->Color.BlendEnabled;
+ attr->ClipPlanes = ctx->Transform.ClipPlanesEnabled;
+ attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
+ attr->CullFace = ctx->Polygon.CullFlag;
+ attr->DepthClamp = ctx->Transform.DepthClamp;
+ attr->DepthTest = ctx->Depth.Test;
+ attr->Dither = ctx->Color.DitherFlag;
+ attr->Fog = ctx->Fog.Enabled;
+ for (i = 0; i < ctx->Const.MaxLights; i++) {
+ attr->Light[i] = ctx->Light.Light[i].Enabled;
+ }
+ attr->Lighting = ctx->Light.Enabled;
+ attr->LineSmooth = ctx->Line.SmoothFlag;
+ attr->LineStipple = ctx->Line.StippleFlag;
+ attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
+ attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
+ attr->Map1Color4 = ctx->Eval.Map1Color4;
+ attr->Map1Index = ctx->Eval.Map1Index;
+ attr->Map1Normal = ctx->Eval.Map1Normal;
+ attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
+ attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
+ attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
+ attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
+ attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
+ attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
+ memcpy(attr->Map1Attrib, ctx->Eval.Map1Attrib, sizeof(ctx->Eval.Map1Attrib));
+ attr->Map2Color4 = ctx->Eval.Map2Color4;
+ attr->Map2Index = ctx->Eval.Map2Index;
+ attr->Map2Normal = ctx->Eval.Map2Normal;
+ attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
+ attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
+ attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
+ attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
+ attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
+ attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
+ memcpy(attr->Map2Attrib, ctx->Eval.Map2Attrib, sizeof(ctx->Eval.Map2Attrib));
+ attr->Normalize = ctx->Transform.Normalize;
+ attr->RasterPositionUnclipped = ctx->Transform.RasterPositionUnclipped;
+ attr->PointSmooth = ctx->Point.SmoothFlag;
+ attr->PointSprite = ctx->Point.PointSprite;
+ attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
+ attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
+ attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
+ attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
+ attr->PolygonStipple = ctx->Polygon.StippleFlag;
+ attr->RescaleNormals = ctx->Transform.RescaleNormals;
+ attr->Scissor = ctx->Scissor.Enabled;
+ attr->Stencil = ctx->Stencil.Enabled;
+ attr->StencilTwoSide = ctx->Stencil.TestTwoSide;
+ attr->MultisampleEnabled = ctx->Multisample.Enabled;
+ attr->SampleAlphaToCoverage = ctx->Multisample.SampleAlphaToCoverage;
+ attr->SampleAlphaToOne = ctx->Multisample.SampleAlphaToOne;
+ attr->SampleCoverage = ctx->Multisample.SampleCoverage;
+ attr->SampleCoverageInvert = ctx->Multisample.SampleCoverageInvert;
+ for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
+ attr->Texture[i] = ctx->Texture.Unit[i].Enabled;
+ attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
+ }
+ /* GL_NV_vertex_program */
+ attr->VertexProgram = ctx->VertexProgram.Enabled;
+ attr->VertexProgramPointSize = ctx->VertexProgram.PointSizeEnabled;
+ attr->VertexProgramTwoSide = ctx->VertexProgram.TwoSideEnabled;
+ save_attrib_data(&head, GL_ENABLE_BIT, attr);
+ }
+
+ if (mask & GL_EVAL_BIT) {
+ struct gl_eval_attrib *attr;
+ attr = MALLOC_STRUCT( gl_eval_attrib );
+ memcpy( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
+ save_attrib_data(&head, GL_EVAL_BIT, attr);
+ }
+
+ if (mask & GL_FOG_BIT) {
+ struct gl_fog_attrib *attr;
+ attr = MALLOC_STRUCT( gl_fog_attrib );
+ memcpy( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
+ save_attrib_data(&head, GL_FOG_BIT, attr);
+ }
+
+ if (mask & GL_HINT_BIT) {
+ struct gl_hint_attrib *attr;
+ attr = MALLOC_STRUCT( gl_hint_attrib );
+ memcpy( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
+ save_attrib_data(&head, GL_HINT_BIT, attr);
+ }
+
+ if (mask & GL_LIGHTING_BIT) {
+ struct gl_light_attrib *attr;
+ FLUSH_CURRENT(ctx, 0); /* flush material changes */
+ attr = MALLOC_STRUCT( gl_light_attrib );
+ memcpy( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
+ save_attrib_data(&head, GL_LIGHTING_BIT, attr);
+ }
+
+ if (mask & GL_LINE_BIT) {
+ struct gl_line_attrib *attr;
+ attr = MALLOC_STRUCT( gl_line_attrib );
+ memcpy( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
+ save_attrib_data(&head, GL_LINE_BIT, attr);
+ }
+
+ if (mask & GL_LIST_BIT) {
+ struct gl_list_attrib *attr;
+ attr = MALLOC_STRUCT( gl_list_attrib );
+ memcpy( attr, &ctx->List, sizeof(struct gl_list_attrib) );
+ save_attrib_data(&head, GL_LIST_BIT, attr);
+ }
+
+ if (mask & GL_PIXEL_MODE_BIT) {
+ struct gl_pixel_attrib *attr;
+ attr = MALLOC_STRUCT( gl_pixel_attrib );
+ memcpy( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
+ /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
+ attr->ReadBuffer = ctx->ReadBuffer->ColorReadBuffer;
+ save_attrib_data(&head, GL_PIXEL_MODE_BIT, attr);
+ }
+
+ if (mask & GL_POINT_BIT) {
+ struct gl_point_attrib *attr;
+ attr = MALLOC_STRUCT( gl_point_attrib );
+ memcpy( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
+ save_attrib_data(&head, GL_POINT_BIT, attr);
+ }
+
+ if (mask & GL_POLYGON_BIT) {
+ struct gl_polygon_attrib *attr;
+ attr = MALLOC_STRUCT( gl_polygon_attrib );
+ memcpy( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
+ save_attrib_data(&head, GL_POLYGON_BIT, attr);
+ }
+
+ if (mask & GL_POLYGON_STIPPLE_BIT) {
+ GLuint *stipple;
+ stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
+ memcpy( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
+ save_attrib_data(&head, GL_POLYGON_STIPPLE_BIT, stipple);
+ }
+
+ if (mask & GL_SCISSOR_BIT) {
+ struct gl_scissor_attrib *attr;
+ attr = MALLOC_STRUCT( gl_scissor_attrib );
+ memcpy( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
+ save_attrib_data(&head, GL_SCISSOR_BIT, attr);
+ }
+
+ if (mask & GL_STENCIL_BUFFER_BIT) {
+ struct gl_stencil_attrib *attr;
+ attr = MALLOC_STRUCT( gl_stencil_attrib );
+ memcpy( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
+ save_attrib_data(&head, GL_STENCIL_BUFFER_BIT, attr);
+ }
+
+ if (mask & GL_TEXTURE_BIT) {
+ struct texture_state *texstate = CALLOC_STRUCT(texture_state);
+ GLuint u, tex;
+
+ if (!texstate) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib(GL_TEXTURE_BIT)");
+ goto end;
+ }
+
+ _mesa_lock_context_textures(ctx);
+
+ /* copy/save the bulk of texture state here */
+ memcpy(&texstate->Texture, &ctx->Texture, sizeof(ctx->Texture));
+
+ /* Save references to the currently bound texture objects so they don't
+ * accidentally get deleted while referenced in the attribute stack.
+ */
+ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+ for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
+ _mesa_reference_texobj(&texstate->SavedTexRef[u][tex],
+ ctx->Texture.Unit[u].CurrentTex[tex]);
+ }
+ }
+
+ /* copy state/contents of the currently bound texture objects */
+ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+ for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
+ _mesa_copy_texture_object(&texstate->SavedObj[u][tex],
+ ctx->Texture.Unit[u].CurrentTex[tex]);
+ }
+ }
+
+ _mesa_unlock_context_textures(ctx);
+
+ save_attrib_data(&head, GL_TEXTURE_BIT, texstate);
+ }
+
+ if (mask & GL_TRANSFORM_BIT) {
+ struct gl_transform_attrib *attr;
+ attr = MALLOC_STRUCT( gl_transform_attrib );
+ memcpy( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
+ save_attrib_data(&head, GL_TRANSFORM_BIT, attr);
+ }
+
+ if (mask & GL_VIEWPORT_BIT) {
+ struct gl_viewport_attrib *attr;
+ attr = MALLOC_STRUCT( gl_viewport_attrib );
+ memcpy( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
+ save_attrib_data(&head, GL_VIEWPORT_BIT, attr);
+ }
+
+ /* GL_ARB_multisample */
+ if (mask & GL_MULTISAMPLE_BIT_ARB) {
+ struct gl_multisample_attrib *attr;
+ attr = MALLOC_STRUCT( gl_multisample_attrib );
+ memcpy( attr, &ctx->Multisample, sizeof(struct gl_multisample_attrib) );
+ save_attrib_data(&head, GL_MULTISAMPLE_BIT_ARB, attr);
+ }
+
+end:
+ ctx->AttribStack[ctx->AttribStackDepth] = head;
+ ctx->AttribStackDepth++;
+}
+
+
+
+static void
+pop_enable_group(struct gl_context *ctx, const struct gl_enable_attrib *enable)
+{
+ const GLuint curTexUnitSave = ctx->Texture.CurrentUnit;
+ GLuint i;
+
+#define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
+ if ((VALUE) != (NEWVALUE)) { \
+ _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
+ }
+
+ TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST);
+ if (ctx->Color.BlendEnabled != enable->Blend) {
+ if (ctx->Extensions.EXT_draw_buffers2) {
+ GLuint i;
+ for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
+ _mesa_set_enablei(ctx, GL_BLEND, i, (enable->Blend >> i) & 1);
+ }
+ }
+ else {
+ _mesa_set_enable(ctx, GL_BLEND, (enable->Blend & 1));
+ }
+ }
+
+ for (i=0;i<MAX_CLIP_PLANES;i++) {
+ const GLuint mask = 1 << i;
+ if ((ctx->Transform.ClipPlanesEnabled & mask) != (enable->ClipPlanes & mask))
+ _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i),
+ (GLboolean) ((enable->ClipPlanes & mask) ? GL_TRUE : GL_FALSE));
+ }
+
+ TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial,
+ GL_COLOR_MATERIAL);
+ TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
+ TEST_AND_UPDATE(ctx->Transform.DepthClamp, enable->DepthClamp,
+ GL_DEPTH_CLAMP);
+ TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
+ TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
+ TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG);
+ TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING);
+ TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH);
+ TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple,
+ GL_LINE_STIPPLE);
+ TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp,
+ GL_INDEX_LOGIC_OP);
+ TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp,
+ GL_COLOR_LOGIC_OP);
+
+ TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4);
+ TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX);
+ TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL);
+ TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1,
+ GL_MAP1_TEXTURE_COORD_1);
+ TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2,
+ GL_MAP1_TEXTURE_COORD_2);
+ TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3,
+ GL_MAP1_TEXTURE_COORD_3);
+ TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4,
+ GL_MAP1_TEXTURE_COORD_4);
+ TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3,
+ GL_MAP1_VERTEX_3);
+ TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4,
+ GL_MAP1_VERTEX_4);
+ for (i = 0; i < 16; i++) {
+ TEST_AND_UPDATE(ctx->Eval.Map1Attrib[i], enable->Map1Attrib[i],
+ GL_MAP1_VERTEX_ATTRIB0_4_NV + i);
+ }
+
+ TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4);
+ TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX);
+ TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL);
+ TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1,
+ GL_MAP2_TEXTURE_COORD_1);
+ TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2,
+ GL_MAP2_TEXTURE_COORD_2);
+ TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3,
+ GL_MAP2_TEXTURE_COORD_3);
+ TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4,
+ GL_MAP2_TEXTURE_COORD_4);
+ TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3,
+ GL_MAP2_VERTEX_3);
+ TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4,
+ GL_MAP2_VERTEX_4);
+ for (i = 0; i < 16; i++) {
+ TEST_AND_UPDATE(ctx->Eval.Map2Attrib[i], enable->Map2Attrib[i],
+ GL_MAP2_VERTEX_ATTRIB0_4_NV + i);
+ }
+
+ TEST_AND_UPDATE(ctx->Eval.AutoNormal, enable->AutoNormal, GL_AUTO_NORMAL);
+ TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE);
+ TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals,
+ GL_RESCALE_NORMAL_EXT);
+ TEST_AND_UPDATE(ctx->Transform.RasterPositionUnclipped,
+ enable->RasterPositionUnclipped,
+ GL_RASTER_POSITION_UNCLIPPED_IBM);
+ TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth,
+ GL_POINT_SMOOTH);
+ if (ctx->Extensions.NV_point_sprite || ctx->Extensions.ARB_point_sprite) {
+ TEST_AND_UPDATE(ctx->Point.PointSprite, enable->PointSprite,
+ GL_POINT_SPRITE_NV);
+ }
+ TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint,
+ GL_POLYGON_OFFSET_POINT);
+ TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine,
+ GL_POLYGON_OFFSET_LINE);
+ TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill,
+ GL_POLYGON_OFFSET_FILL);
+ TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth,
+ GL_POLYGON_SMOOTH);
+ TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple,
+ GL_POLYGON_STIPPLE);
+ TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST);
+ TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST);
+ if (ctx->Extensions.EXT_stencil_two_side) {
+ TEST_AND_UPDATE(ctx->Stencil.TestTwoSide, enable->StencilTwoSide, GL_STENCIL_TEST_TWO_SIDE_EXT);
+ }
+ TEST_AND_UPDATE(ctx->Multisample.Enabled, enable->MultisampleEnabled,
+ GL_MULTISAMPLE_ARB);
+ TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToCoverage,
+ enable->SampleAlphaToCoverage,
+ GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
+ TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToOne,
+ enable->SampleAlphaToOne,
+ GL_SAMPLE_ALPHA_TO_ONE_ARB);
+ TEST_AND_UPDATE(ctx->Multisample.SampleCoverage,
+ enable->SampleCoverage,
+ GL_SAMPLE_COVERAGE_ARB);
+ TEST_AND_UPDATE(ctx->Multisample.SampleCoverageInvert,
+ enable->SampleCoverageInvert,
+ GL_SAMPLE_COVERAGE_INVERT_ARB);
+ /* GL_ARB_vertex_program, GL_NV_vertex_program */
+ TEST_AND_UPDATE(ctx->VertexProgram.Enabled,
+ enable->VertexProgram,
+ GL_VERTEX_PROGRAM_ARB);
+ TEST_AND_UPDATE(ctx->VertexProgram.PointSizeEnabled,
+ enable->VertexProgramPointSize,
+ GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
+ TEST_AND_UPDATE(ctx->VertexProgram.TwoSideEnabled,
+ enable->VertexProgramTwoSide,
+ GL_VERTEX_PROGRAM_TWO_SIDE_ARB);
+
+#undef TEST_AND_UPDATE
+
+ /* texture unit enables */
+ for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
+ const GLbitfield enabled = enable->Texture[i];
+ const GLbitfield genEnabled = enable->TexGen[i];
+
+ if (ctx->Texture.Unit[i].Enabled != enabled) {
+ _mesa_ActiveTextureARB(GL_TEXTURE0 + i);
+
+ _mesa_set_enable(ctx, GL_TEXTURE_1D,
+ (enabled & TEXTURE_1D_BIT) ? GL_TRUE : GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_2D,
+ (enabled & TEXTURE_2D_BIT) ? GL_TRUE : GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_3D,
+ (enabled & TEXTURE_3D_BIT) ? GL_TRUE : GL_FALSE);
+ if (ctx->Extensions.NV_texture_rectangle) {
+ _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_ARB,
+ (enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE);
+ }
+ if (ctx->Extensions.ARB_texture_cube_map) {
+ _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP,
+ (enabled & TEXTURE_CUBE_BIT) ? GL_TRUE : GL_FALSE);
+ }
+ if (ctx->Extensions.MESA_texture_array) {
+ _mesa_set_enable(ctx, GL_TEXTURE_1D_ARRAY_EXT,
+ (enabled & TEXTURE_1D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_2D_ARRAY_EXT,
+ (enabled & TEXTURE_2D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
+ }
+ }
+
+ if (ctx->Texture.Unit[i].TexGenEnabled != genEnabled) {
+ _mesa_ActiveTextureARB(GL_TEXTURE0 + i);
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_S,
+ (genEnabled & S_BIT) ? GL_TRUE : GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_T,
+ (genEnabled & T_BIT) ? GL_TRUE : GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_R,
+ (genEnabled & R_BIT) ? GL_TRUE : GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q,
+ (genEnabled & Q_BIT) ? GL_TRUE : GL_FALSE);
+ }
+ }
+
+ _mesa_ActiveTextureARB(GL_TEXTURE0 + curTexUnitSave);
+}
+
+
+/**
+ * Pop/restore texture attribute/group state.
+ */
+static void
+pop_texture_group(struct gl_context *ctx, struct texture_state *texstate)
+{
+ GLuint u;
+
+ _mesa_lock_context_textures(ctx);
+
+ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+ const struct gl_texture_unit *unit = &texstate->Texture.Unit[u];
+ GLuint tgt;
+
+ _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + u);
+ _mesa_set_enable(ctx, GL_TEXTURE_1D,
+ (unit->Enabled & TEXTURE_1D_BIT) ? GL_TRUE : GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_2D,
+ (unit->Enabled & TEXTURE_2D_BIT) ? GL_TRUE : GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_3D,
+ (unit->Enabled & TEXTURE_3D_BIT) ? GL_TRUE : GL_FALSE);
+ if (ctx->Extensions.ARB_texture_cube_map) {
+ _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP_ARB,
+ (unit->Enabled & TEXTURE_CUBE_BIT) ? GL_TRUE : GL_FALSE);
+ }
+ if (ctx->Extensions.NV_texture_rectangle) {
+ _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_NV,
+ (unit->Enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE);
+ }
+ if (ctx->Extensions.MESA_texture_array) {
+ _mesa_set_enable(ctx, GL_TEXTURE_1D_ARRAY_EXT,
+ (unit->Enabled & TEXTURE_1D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
+ _mesa_set_enable(ctx, GL_TEXTURE_2D_ARRAY_EXT,
+ (unit->Enabled & TEXTURE_2D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
+ }
+
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->EnvMode);
+ _mesa_TexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, unit->EnvColor);
+ _mesa_TexGeni(GL_S, GL_TEXTURE_GEN_MODE, unit->GenS.Mode);
+ _mesa_TexGeni(GL_T, GL_TEXTURE_GEN_MODE, unit->GenT.Mode);
+ _mesa_TexGeni(GL_R, GL_TEXTURE_GEN_MODE, unit->GenR.Mode);
+ _mesa_TexGeni(GL_Q, GL_TEXTURE_GEN_MODE, unit->GenQ.Mode);
+ _mesa_TexGenfv(GL_S, GL_OBJECT_PLANE, unit->GenS.ObjectPlane);
+ _mesa_TexGenfv(GL_T, GL_OBJECT_PLANE, unit->GenT.ObjectPlane);
+ _mesa_TexGenfv(GL_R, GL_OBJECT_PLANE, unit->GenR.ObjectPlane);
+ _mesa_TexGenfv(GL_Q, GL_OBJECT_PLANE, unit->GenQ.ObjectPlane);
+ /* Eye plane done differently to avoid re-transformation */
+ {
+ struct gl_texture_unit *destUnit = &ctx->Texture.Unit[u];
+ COPY_4FV(destUnit->GenS.EyePlane, unit->GenS.EyePlane);
+ COPY_4FV(destUnit->GenT.EyePlane, unit->GenT.EyePlane);
+ COPY_4FV(destUnit->GenR.EyePlane, unit->GenR.EyePlane);
+ COPY_4FV(destUnit->GenQ.EyePlane, unit->GenQ.EyePlane);
+ if (ctx->Driver.TexGen) {
+ ctx->Driver.TexGen(ctx, GL_S, GL_EYE_PLANE, unit->GenS.EyePlane);
+ ctx->Driver.TexGen(ctx, GL_T, GL_EYE_PLANE, unit->GenT.EyePlane);
+ ctx->Driver.TexGen(ctx, GL_R, GL_EYE_PLANE, unit->GenR.EyePlane);
+ ctx->Driver.TexGen(ctx, GL_Q, GL_EYE_PLANE, unit->GenQ.EyePlane);
+ }
+ }
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_S,
+ ((unit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE));
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_T,
+ ((unit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE));
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_R,
+ ((unit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE));
+ _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q,
+ ((unit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE));
+ if (ctx->Extensions.EXT_texture_lod_bias) {
+ _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
+ GL_TEXTURE_LOD_BIAS_EXT, unit->LodBias);
+ }
+ if (ctx->Extensions.EXT_texture_env_combine ||
+ ctx->Extensions.ARB_texture_env_combine) {
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,
+ unit->Combine.ModeRGB);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA,
+ unit->Combine.ModeA);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB,
+ unit->Combine.SourceRGB[0]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB,
+ unit->Combine.SourceRGB[1]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB,
+ unit->Combine.SourceRGB[2]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA,
+ unit->Combine.SourceA[0]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA,
+ unit->Combine.SourceA[1]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA,
+ unit->Combine.SourceA[2]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB,
+ unit->Combine.OperandRGB[0]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB,
+ unit->Combine.OperandRGB[1]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB,
+ unit->Combine.OperandRGB[2]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA,
+ unit->Combine.OperandA[0]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA,
+ unit->Combine.OperandA[1]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA,
+ unit->Combine.OperandA[2]);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE,
+ 1 << unit->Combine.ScaleShiftRGB);
+ _mesa_TexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE,
+ 1 << unit->Combine.ScaleShiftA);
+ }
+
+ /* Restore texture object state for each target */
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+ const struct gl_texture_object *obj = NULL;
+ GLenum target;
+
+ obj = &texstate->SavedObj[u][tgt];
+
+ /* don't restore state for unsupported targets to prevent
+ * raising GL errors.
+ */
+ if (obj->Target == GL_TEXTURE_CUBE_MAP_ARB &&
+ !ctx->Extensions.ARB_texture_cube_map) {
+ continue;
+ }
+ else if (obj->Target == GL_TEXTURE_RECTANGLE_NV &&
+ !ctx->Extensions.NV_texture_rectangle) {
+ continue;
+ }
+ else if ((obj->Target == GL_TEXTURE_1D_ARRAY_EXT ||
+ obj->Target == GL_TEXTURE_2D_ARRAY_EXT) &&
+ !ctx->Extensions.MESA_texture_array) {
+ continue;
+ }
+
+ target = obj->Target;
+
+ _mesa_BindTexture(target, obj->Name);
+
+ _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, obj->BorderColor.f);
+ _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, obj->WrapS);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, obj->WrapT);
+ _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, obj->WrapR);
+ _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, obj->MinFilter);
+ _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, obj->MagFilter);
+ _mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, obj->MinLod);
+ _mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, obj->MaxLod);
+ _mesa_TexParameterf(target, GL_TEXTURE_LOD_BIAS, obj->LodBias);
+ _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, obj->BaseLevel);
+ if (target != GL_TEXTURE_RECTANGLE_ARB)
+ _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->MaxLevel);
+ if (ctx->Extensions.EXT_texture_filter_anisotropic) {
+ _mesa_TexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
+ obj->MaxAnisotropy);
+ }
+ if (ctx->Extensions.ARB_shadow_ambient) {
+ _mesa_TexParameterf(target, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB,
+ obj->CompareFailValue);
+ }
+ }
+
+ /* remove saved references to the texture objects */
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+ _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL);
+ }
+ }
+
+ _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + texstate->Texture.CurrentUnit);
+
+ _mesa_unlock_context_textures(ctx);
+}
+
+
+/*
+ * This function is kind of long just because we have to call a lot
+ * of device driver functions to update device driver state.
+ *
+ * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
+ * in order to restore GL state. This isn't terribly efficient but it
+ * ensures that dirty flags and any derived state gets updated correctly.
+ * We could at least check if the value to restore equals the current value
+ * and then skip the Mesa call.
+ */
+void GLAPIENTRY
+_mesa_PopAttrib(void)
+{
+ struct gl_attrib_node *attr, *next;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (ctx->AttribStackDepth == 0) {
+ _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
+ return;
+ }
+
+ ctx->AttribStackDepth--;
+ attr = ctx->AttribStack[ctx->AttribStackDepth];
+
+ while (attr) {
+
+ if (MESA_VERBOSE & VERBOSE_API) {
+ _mesa_debug(ctx, "glPopAttrib %s\n",
+ _mesa_lookup_enum_by_nr(attr->kind));
+ }
+
+ switch (attr->kind) {
+ case GL_ACCUM_BUFFER_BIT:
+ {
+ const struct gl_accum_attrib *accum;
+ accum = (const struct gl_accum_attrib *) attr->data;
+ _mesa_ClearAccum(accum->ClearColor[0],
+ accum->ClearColor[1],
+ accum->ClearColor[2],
+ accum->ClearColor[3]);
+ }
+ break;
+ case GL_COLOR_BUFFER_BIT:
+ {
+ const struct gl_colorbuffer_attrib *color;
+
+ color = (const struct gl_colorbuffer_attrib *) attr->data;
+ _mesa_ClearIndex((GLfloat) color->ClearIndex);
+ _mesa_ClearColor(color->ClearColor[0],
+ color->ClearColor[1],
+ color->ClearColor[2],
+ color->ClearColor[3]);
+ _mesa_IndexMask(color->IndexMask);
+ if (!ctx->Extensions.EXT_draw_buffers2) {
+ _mesa_ColorMask((GLboolean) (color->ColorMask[0][0] != 0),
+ (GLboolean) (color->ColorMask[0][1] != 0),
+ (GLboolean) (color->ColorMask[0][2] != 0),
+ (GLboolean) (color->ColorMask[0][3] != 0));
+ }
+ else {
+ GLuint i;
+ for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
+ _mesa_ColorMaskIndexed(i,
+ (GLboolean) (color->ColorMask[i][0] != 0),
+ (GLboolean) (color->ColorMask[i][1] != 0),
+ (GLboolean) (color->ColorMask[i][2] != 0),
+ (GLboolean) (color->ColorMask[i][3] != 0));
+ }
+ }
+ {
+ /* Need to determine if more than one color output is
+ * specified. If so, call glDrawBuffersARB, else call
+ * glDrawBuffer(). This is a subtle, but essential point
+ * since GL_FRONT (for example) is illegal for the former
+ * function, but legal for the later.
+ */
+ GLboolean multipleBuffers = GL_FALSE;
+ GLuint i;
+
+ for (i = 1; i < ctx->Const.MaxDrawBuffers; i++) {
+ if (color->DrawBuffer[i] != GL_NONE) {
+ multipleBuffers = GL_TRUE;
+ break;
+ }
+ }
+ /* Call the API_level functions, not _mesa_drawbuffers()
+ * since we need to do error checking on the pop'd
+ * GL_DRAW_BUFFER.
+ * Ex: if GL_FRONT were pushed, but we're popping with a
+ * user FBO bound, GL_FRONT will be illegal and we'll need
+ * to record that error. Per OpenGL ARB decision.
+ */
+ if (multipleBuffers)
+ _mesa_DrawBuffersARB(ctx->Const.MaxDrawBuffers,
+ color->DrawBuffer);
+ else
+ _mesa_DrawBuffer(color->DrawBuffer[0]);
+ }
+ _mesa_set_enable(ctx, GL_ALPHA_TEST, color->AlphaEnabled);
+ _mesa_AlphaFunc(color->AlphaFunc, color->AlphaRef);
+ if (ctx->Color.BlendEnabled != color->BlendEnabled) {
+ if (ctx->Extensions.EXT_draw_buffers2) {
+ GLuint i;
+ for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
+ _mesa_set_enablei(ctx, GL_BLEND, i,
+ (color->BlendEnabled >> i) & 1);
+ }
+ }
+ else {
+ _mesa_set_enable(ctx, GL_BLEND, (color->BlendEnabled & 1));
+ }
+ }
+ if (ctx->Color._BlendFuncPerBuffer ||
+ ctx->Color._BlendEquationPerBuffer) {
+ /* set blend per buffer */
+ GLuint buf;
+ for (buf = 0; buf < ctx->Const.MaxDrawBuffers; buf++) {
+ _mesa_BlendFuncSeparatei(buf, color->Blend[buf].SrcRGB,
+ color->Blend[buf].DstRGB,
+ color->Blend[buf].SrcA,
+ color->Blend[buf].DstA);
+ _mesa_BlendEquationSeparatei(buf,
+ color->Blend[buf].EquationRGB,
+ color->Blend[buf].EquationA);
+ }
+ }
+ else {
+ /* set same blend modes for all buffers */
+ _mesa_BlendFuncSeparateEXT(color->Blend[0].SrcRGB,
+ color->Blend[0].DstRGB,
+ color->Blend[0].SrcA,
+ color->Blend[0].DstA);
+ /* This special case is because glBlendEquationSeparateEXT
+ * cannot take GL_LOGIC_OP as a parameter.
+ */
+ if (color->Blend[0].EquationRGB ==
+ color->Blend[0].EquationA) {
+ _mesa_BlendEquation(color->Blend[0].EquationRGB);
+ }
+ else {
+ _mesa_BlendEquationSeparateEXT(
+ color->Blend[0].EquationRGB,
+ color->Blend[0].EquationA);
+ }
+ }
+ _mesa_BlendColor(color->BlendColor[0],
+ color->BlendColor[1],
+ color->BlendColor[2],
+ color->BlendColor[3]);
+ _mesa_LogicOp(color->LogicOp);
+ _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP,
+ color->ColorLogicOpEnabled);
+ _mesa_set_enable(ctx, GL_INDEX_LOGIC_OP,
+ color->IndexLogicOpEnabled);
+ _mesa_set_enable(ctx, GL_DITHER, color->DitherFlag);
+ }
+ break;
+ case GL_CURRENT_BIT:
+ FLUSH_CURRENT( ctx, 0 );
+ memcpy( &ctx->Current, attr->data,
+ sizeof(struct gl_current_attrib) );
+ break;
+ case GL_DEPTH_BUFFER_BIT:
+ {
+ const struct gl_depthbuffer_attrib *depth;
+ depth = (const struct gl_depthbuffer_attrib *) attr->data;
+ _mesa_DepthFunc(depth->Func);
+ _mesa_ClearDepth(depth->Clear);
+ _mesa_set_enable(ctx, GL_DEPTH_TEST, depth->Test);
+ _mesa_DepthMask(depth->Mask);
+ }
+ break;
+ case GL_ENABLE_BIT:
+ {
+ const struct gl_enable_attrib *enable;
+ enable = (const struct gl_enable_attrib *) attr->data;
+ pop_enable_group(ctx, enable);
+ ctx->NewState |= _NEW_ALL;
+ }
+ break;
+ case GL_EVAL_BIT:
+ memcpy( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
+ ctx->NewState |= _NEW_EVAL;
+ break;
+ case GL_FOG_BIT:
+ {
+ const struct gl_fog_attrib *fog;
+ fog = (const struct gl_fog_attrib *) attr->data;
+ _mesa_set_enable(ctx, GL_FOG, fog->Enabled);
+ _mesa_Fogfv(GL_FOG_COLOR, fog->Color);
+ _mesa_Fogf(GL_FOG_DENSITY, fog->Density);
+ _mesa_Fogf(GL_FOG_START, fog->Start);
+ _mesa_Fogf(GL_FOG_END, fog->End);
+ _mesa_Fogf(GL_FOG_INDEX, fog->Index);
+ _mesa_Fogi(GL_FOG_MODE, fog->Mode);
+ }
+ break;
+ case GL_HINT_BIT:
+ {
+ const struct gl_hint_attrib *hint;
+ hint = (const struct gl_hint_attrib *) attr->data;
+ _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT,
+ hint->PerspectiveCorrection );
+ _mesa_Hint(GL_POINT_SMOOTH_HINT, hint->PointSmooth);
+ _mesa_Hint(GL_LINE_SMOOTH_HINT, hint->LineSmooth);
+ _mesa_Hint(GL_POLYGON_SMOOTH_HINT, hint->PolygonSmooth);
+ _mesa_Hint(GL_FOG_HINT, hint->Fog);
+ _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT,
+ hint->ClipVolumeClipping);
+ _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB,
+ hint->TextureCompression);
+ }
+ break;
+ case GL_LIGHTING_BIT:
+ {
+ GLuint i;
+ const struct gl_light_attrib *light;
+ light = (const struct gl_light_attrib *) attr->data;
+ /* lighting enable */
+ _mesa_set_enable(ctx, GL_LIGHTING, light->Enabled);
+ /* per-light state */
+ if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top))
+ _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
+
+ for (i = 0; i < ctx->Const.MaxLights; i++) {
+ const struct gl_light *l = &light->Light[i];
+ _mesa_set_enable(ctx, GL_LIGHT0 + i, l->Enabled);
+ _mesa_light(ctx, i, GL_AMBIENT, l->Ambient);
+ _mesa_light(ctx, i, GL_DIFFUSE, l->Diffuse);
+ _mesa_light(ctx, i, GL_SPECULAR, l->Specular );
+ _mesa_light(ctx, i, GL_POSITION, l->EyePosition);
+ _mesa_light(ctx, i, GL_SPOT_DIRECTION, l->SpotDirection);
+ {
+ GLfloat p[4] = { 0 };
+ p[0] = l->SpotExponent;
+ _mesa_light(ctx, i, GL_SPOT_EXPONENT, p);
+ }
+ {
+ GLfloat p[4] = { 0 };
+ p[0] = l->SpotCutoff;
+ _mesa_light(ctx, i, GL_SPOT_CUTOFF, p);
+ }
+ {
+ GLfloat p[4] = { 0 };
+ p[0] = l->ConstantAttenuation;
+ _mesa_light(ctx, i, GL_CONSTANT_ATTENUATION, p);
+ }
+ {
+ GLfloat p[4] = { 0 };
+ p[0] = l->LinearAttenuation;
+ _mesa_light(ctx, i, GL_LINEAR_ATTENUATION, p);
+ }
+ {
+ GLfloat p[4] = { 0 };
+ p[0] = l->QuadraticAttenuation;
+ _mesa_light(ctx, i, GL_QUADRATIC_ATTENUATION, p);
+ }
+ }
+ /* light model */
+ _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT,
+ light->Model.Ambient);
+ _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER,
+ (GLfloat) light->Model.LocalViewer);
+ _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE,
+ (GLfloat) light->Model.TwoSide);
+ _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL,
+ (GLfloat) light->Model.ColorControl);
+ /* shade model */
+ _mesa_ShadeModel(light->ShadeModel);
+ /* color material */
+ _mesa_ColorMaterial(light->ColorMaterialFace,
+ light->ColorMaterialMode);
+ _mesa_set_enable(ctx, GL_COLOR_MATERIAL,
+ light->ColorMaterialEnabled);
+ /* materials */
+ memcpy(&ctx->Light.Material, &light->Material,
+ sizeof(struct gl_material));
+ }
+ break;
+ case GL_LINE_BIT:
+ {
+ const struct gl_line_attrib *line;
+ line = (const struct gl_line_attrib *) attr->data;
+ _mesa_set_enable(ctx, GL_LINE_SMOOTH, line->SmoothFlag);
+ _mesa_set_enable(ctx, GL_LINE_STIPPLE, line->StippleFlag);
+ _mesa_LineStipple(line->StippleFactor, line->StipplePattern);
+ _mesa_LineWidth(line->Width);
+ }
+ break;
+ case GL_LIST_BIT:
+ memcpy( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
+ break;
+ case GL_PIXEL_MODE_BIT:
+ memcpy( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
+ /* XXX what other pixel state needs to be set by function calls? */
+ _mesa_ReadBuffer(ctx->Pixel.ReadBuffer);
+ ctx->NewState |= _NEW_PIXEL;
+ break;
+ case GL_POINT_BIT:
+ {
+ const struct gl_point_attrib *point;
+ point = (const struct gl_point_attrib *) attr->data;
+ _mesa_PointSize(point->Size);
+ _mesa_set_enable(ctx, GL_POINT_SMOOTH, point->SmoothFlag);
+ if (ctx->Extensions.EXT_point_parameters) {
+ _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT,
+ point->Params);
+ _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT,
+ point->MinSize);
+ _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT,
+ point->MaxSize);
+ _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT,
+ point->Threshold);
+ }
+ if (ctx->Extensions.NV_point_sprite
+ || ctx->Extensions.ARB_point_sprite) {
+ GLuint u;
+ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+ _mesa_TexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV,
+ (GLint) point->CoordReplace[u]);
+ }
+ _mesa_set_enable(ctx, GL_POINT_SPRITE_NV,point->PointSprite);
+ if (ctx->Extensions.NV_point_sprite)
+ _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV,
+ ctx->Point.SpriteRMode);
+ _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN,
+ (GLfloat)ctx->Point.SpriteOrigin);
+ }
+ }
+ break;
+ case GL_POLYGON_BIT:
+ {
+ const struct gl_polygon_attrib *polygon;
+ polygon = (const struct gl_polygon_attrib *) attr->data;
+ _mesa_CullFace(polygon->CullFaceMode);
+ _mesa_FrontFace(polygon->FrontFace);
+ _mesa_PolygonMode(GL_FRONT, polygon->FrontMode);
+ _mesa_PolygonMode(GL_BACK, polygon->BackMode);
+ _mesa_PolygonOffset(polygon->OffsetFactor,
+ polygon->OffsetUnits);
+ _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, polygon->SmoothFlag);
+ _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, polygon->StippleFlag);
+ _mesa_set_enable(ctx, GL_CULL_FACE, polygon->CullFlag);
+ _mesa_set_enable(ctx, GL_POLYGON_OFFSET_POINT,
+ polygon->OffsetPoint);
+ _mesa_set_enable(ctx, GL_POLYGON_OFFSET_LINE,
+ polygon->OffsetLine);
+ _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL,
+ polygon->OffsetFill);
+ }
+ break;
+ case GL_POLYGON_STIPPLE_BIT:
+ memcpy( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
+ ctx->NewState |= _NEW_POLYGONSTIPPLE;
+ if (ctx->Driver.PolygonStipple)
+ ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data );
+ break;
+ case GL_SCISSOR_BIT:
+ {
+ const struct gl_scissor_attrib *scissor;
+ scissor = (const struct gl_scissor_attrib *) attr->data;
+ _mesa_Scissor(scissor->X, scissor->Y,
+ scissor->Width, scissor->Height);
+ _mesa_set_enable(ctx, GL_SCISSOR_TEST, scissor->Enabled);
+ }
+ break;
+ case GL_STENCIL_BUFFER_BIT:
+ {
+ const struct gl_stencil_attrib *stencil;
+ stencil = (const struct gl_stencil_attrib *) attr->data;
+ _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled);
+ _mesa_ClearStencil(stencil->Clear);
+ if (ctx->Extensions.EXT_stencil_two_side) {
+ _mesa_set_enable(ctx, GL_STENCIL_TEST_TWO_SIDE_EXT,
+ stencil->TestTwoSide);
+ _mesa_ActiveStencilFaceEXT(stencil->ActiveFace
+ ? GL_BACK : GL_FRONT);
+ }
+ /* front state */
+ _mesa_StencilFuncSeparate(GL_FRONT,
+ stencil->Function[0],
+ stencil->Ref[0],
+ stencil->ValueMask[0]);
+ _mesa_StencilMaskSeparate(GL_FRONT, stencil->WriteMask[0]);
+ _mesa_StencilOpSeparate(GL_FRONT, stencil->FailFunc[0],
+ stencil->ZFailFunc[0],
+ stencil->ZPassFunc[0]);
+ /* back state */
+ _mesa_StencilFuncSeparate(GL_BACK,
+ stencil->Function[1],
+ stencil->Ref[1],
+ stencil->ValueMask[1]);
+ _mesa_StencilMaskSeparate(GL_BACK, stencil->WriteMask[1]);
+ _mesa_StencilOpSeparate(GL_BACK, stencil->FailFunc[1],
+ stencil->ZFailFunc[1],
+ stencil->ZPassFunc[1]);
+ }
+ break;
+ case GL_TRANSFORM_BIT:
+ {
+ GLuint i;
+ const struct gl_transform_attrib *xform;
+ xform = (const struct gl_transform_attrib *) attr->data;
+ _mesa_MatrixMode(xform->MatrixMode);
+ if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top))
+ _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
+
+ /* restore clip planes */
+ for (i = 0; i < MAX_CLIP_PLANES; i++) {
+ const GLuint mask = 1 << i;
+ const GLfloat *eyePlane = xform->EyeUserPlane[i];
+ COPY_4V(ctx->Transform.EyeUserPlane[i], eyePlane);
+ if (xform->ClipPlanesEnabled & mask) {
+ _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_TRUE);
+ }
+ else {
+ _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE);
+ }
+ if (ctx->Driver.ClipPlane)
+ ctx->Driver.ClipPlane( ctx, GL_CLIP_PLANE0 + i, eyePlane );
+ }
+
+ /* normalize/rescale */
+ if (xform->Normalize != ctx->Transform.Normalize)
+ _mesa_set_enable(ctx, GL_NORMALIZE,ctx->Transform.Normalize);
+ if (xform->RescaleNormals != ctx->Transform.RescaleNormals)
+ _mesa_set_enable(ctx, GL_RESCALE_NORMAL_EXT,
+ ctx->Transform.RescaleNormals);
+ if (xform->DepthClamp != ctx->Transform.DepthClamp)
+ _mesa_set_enable(ctx, GL_DEPTH_CLAMP,
+ ctx->Transform.DepthClamp);
+ }
+ break;
+ case GL_TEXTURE_BIT:
+ /* Take care of texture object reference counters */
+ {
+ struct texture_state *texstate
+ = (struct texture_state *) attr->data;
+ pop_texture_group(ctx, texstate);
+ ctx->NewState |= _NEW_TEXTURE;
+ }
+ break;
+ case GL_VIEWPORT_BIT:
+ {
+ const struct gl_viewport_attrib *vp;
+ vp = (const struct gl_viewport_attrib *) attr->data;
+ _mesa_Viewport(vp->X, vp->Y, vp->Width, vp->Height);
+ _mesa_DepthRange(vp->Near, vp->Far);
+ }
+ break;
+ case GL_MULTISAMPLE_BIT_ARB:
+ {
+ const struct gl_multisample_attrib *ms;
+ ms = (const struct gl_multisample_attrib *) attr->data;
+ _mesa_SampleCoverageARB(ms->SampleCoverageValue,
+ ms->SampleCoverageInvert);
+ }
+ break;
+
+ default:
+ _mesa_problem( ctx, "Bad attrib flag in PopAttrib");
+ break;
+ }
+
+ next = attr->next;
+ FREE( attr->data );
+ FREE( attr );
+ attr = next;
+ }
+}
+
+
+/**
+ * Helper for incrementing/decrementing vertex buffer object reference
+ * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
+ */
+static void
+adjust_buffer_object_ref_counts(struct gl_array_object *arrayObj, GLint step)
+{
+ GLuint i;
+
+ arrayObj->Vertex.BufferObj->RefCount += step;
+ arrayObj->Weight.BufferObj->RefCount += step;
+ arrayObj->Normal.BufferObj->RefCount += step;
+ arrayObj->Color.BufferObj->RefCount += step;
+ arrayObj->SecondaryColor.BufferObj->RefCount += step;
+ arrayObj->FogCoord.BufferObj->RefCount += step;
+ arrayObj->Index.BufferObj->RefCount += step;
+ arrayObj->EdgeFlag.BufferObj->RefCount += step;
+ for (i = 0; i < Elements(arrayObj->TexCoord); i++)
+ arrayObj->TexCoord[i].BufferObj->RefCount += step;
+ for (i = 0; i < Elements(arrayObj->VertexAttrib); i++)
+ arrayObj->VertexAttrib[i].BufferObj->RefCount += step;
+}
+
+
+/**
+ * Copy gl_pixelstore_attrib from src to dst, updating buffer
+ * object refcounts.
+ */
+static void
+copy_pixelstore(struct gl_context *ctx,
+ struct gl_pixelstore_attrib *dst,
+ const struct gl_pixelstore_attrib *src)
+{
+ dst->Alignment = src->Alignment;
+ dst->RowLength = src->RowLength;
+ dst->SkipPixels = src->SkipPixels;
+ dst->SkipRows = src->SkipRows;
+ dst->ImageHeight = src->ImageHeight;
+ dst->SkipImages = src->SkipImages;
+ dst->SwapBytes = src->SwapBytes;
+ dst->LsbFirst = src->LsbFirst;
+ dst->ClientStorage = src->ClientStorage;
+ dst->Invert = src->Invert;
+ _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
+}
+
+
+#define GL_CLIENT_PACK_BIT (1<<20)
+#define GL_CLIENT_UNPACK_BIT (1<<21)
+
+
+void GLAPIENTRY
+_mesa_PushClientAttrib(GLbitfield mask)
+{
+ struct gl_attrib_node *head;
+
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (ctx->ClientAttribStackDepth >= MAX_CLIENT_ATTRIB_STACK_DEPTH) {
+ _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
+ return;
+ }
+
+ /* Build linked list of attribute nodes which save all attribute
+ * groups specified by the mask.
+ */
+ head = NULL;
+
+ if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
+ struct gl_pixelstore_attrib *attr;
+ /* packing attribs */
+ attr = CALLOC_STRUCT( gl_pixelstore_attrib );
+ copy_pixelstore(ctx, attr, &ctx->Pack);
+ save_attrib_data(&head, GL_CLIENT_PACK_BIT, attr);
+ /* unpacking attribs */
+ attr = CALLOC_STRUCT( gl_pixelstore_attrib );
+ copy_pixelstore(ctx, attr, &ctx->Unpack);
+ save_attrib_data(&head, GL_CLIENT_UNPACK_BIT, attr);
+ }
+
+ if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
+ struct gl_array_attrib *attr;
+ struct gl_array_object *obj;
+
+ attr = MALLOC_STRUCT( gl_array_attrib );
+ obj = MALLOC_STRUCT( gl_array_object );
+
+#if FEATURE_ARB_vertex_buffer_object
+ /* increment ref counts since we're copying pointers to these objects */
+ ctx->Array.ArrayBufferObj->RefCount++;
+ ctx->Array.ElementArrayBufferObj->RefCount++;
+#endif
+
+ memcpy( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
+ memcpy( obj, ctx->Array.ArrayObj, sizeof(struct gl_array_object) );
+
+ attr->ArrayObj = obj;
+
+ save_attrib_data(&head, GL_CLIENT_VERTEX_ARRAY_BIT, attr);
+
+ /* bump reference counts on buffer objects */
+ adjust_buffer_object_ref_counts(ctx->Array.ArrayObj, 1);
+ }
+
+ ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
+ ctx->ClientAttribStackDepth++;
+}
+
+
+
+
+void GLAPIENTRY
+_mesa_PopClientAttrib(void)
+{
+ struct gl_attrib_node *node, *next;
+
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (ctx->ClientAttribStackDepth == 0) {
+ _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
+ return;
+ }
+
+ ctx->ClientAttribStackDepth--;
+ node = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
+
+ while (node) {
+ switch (node->kind) {
+ case GL_CLIENT_PACK_BIT:
+ {
+ struct gl_pixelstore_attrib *store =
+ (struct gl_pixelstore_attrib *) node->data;
+ copy_pixelstore(ctx, &ctx->Pack, store);
+ _mesa_reference_buffer_object(ctx, &store->BufferObj, NULL);
+ }
+ ctx->NewState |= _NEW_PACKUNPACK;
+ break;
+ case GL_CLIENT_UNPACK_BIT:
+ {
+ struct gl_pixelstore_attrib *store =
+ (struct gl_pixelstore_attrib *) node->data;
+ copy_pixelstore(ctx, &ctx->Unpack, store);
+ _mesa_reference_buffer_object(ctx, &store->BufferObj, NULL);
+ }
+ ctx->NewState |= _NEW_PACKUNPACK;
+ break;
+ case GL_CLIENT_VERTEX_ARRAY_BIT: {
+ struct gl_array_attrib * data =
+ (struct gl_array_attrib *) node->data;
+
+ adjust_buffer_object_ref_counts(ctx->Array.ArrayObj, -1);
+
+ ctx->Array.ActiveTexture = data->ActiveTexture;
+ if (data->LockCount != 0)
+ _mesa_LockArraysEXT(data->LockFirst, data->LockCount);
+ else if (ctx->Array.LockCount)
+ _mesa_UnlockArraysEXT();
+
+ _mesa_BindVertexArrayAPPLE( data->ArrayObj->Name );
+
+#if FEATURE_ARB_vertex_buffer_object
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB,
+ data->ArrayBufferObj->Name);
+ _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
+ data->ElementArrayBufferObj->Name);
+#endif
+
+ memcpy( ctx->Array.ArrayObj, data->ArrayObj,
+ sizeof( struct gl_array_object ) );
+
+ FREE( data->ArrayObj );
+
+ /* FIXME: Should some bits in ctx->Array->NewState also be set
+ * FIXME: here? It seems like it should be set to inclusive-or
+ * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
+ */
+
+ ctx->NewState |= _NEW_ARRAY;
+ break;
+ }
+ default:
+ _mesa_problem( ctx, "Bad attrib flag in PopClientAttrib");
+ break;
+ }
+
+ next = node->next;
+ FREE( node->data );
+ FREE( node );
+ node = next;
+ }
+}
+
+
+void
+_mesa_init_attrib_dispatch(struct _glapi_table *disp)
+{
+ SET_PopAttrib(disp, _mesa_PopAttrib);
+ SET_PushAttrib(disp, _mesa_PushAttrib);
+ SET_PopClientAttrib(disp, _mesa_PopClientAttrib);
+ SET_PushClientAttrib(disp, _mesa_PushClientAttrib);
+}
+
+
+#endif /* FEATURE_attrib_stack */
+
+
+/**
+ * Free any attribute state data that might be attached to the context.
+ */
+void
+_mesa_free_attrib_data(struct gl_context *ctx)
+{
+ while (ctx->AttribStackDepth > 0) {
+ struct gl_attrib_node *attr, *next;
+
+ ctx->AttribStackDepth--;
+ attr = ctx->AttribStack[ctx->AttribStackDepth];
+
+ while (attr) {
+ if (attr->kind == GL_TEXTURE_BIT) {
+ struct texture_state *texstate = (struct texture_state*)attr->data;
+ GLuint u, tgt;
+ /* clear references to the saved texture objects */
+ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+ _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL);
+ }
+ }
+ }
+ else {
+ /* any other chunks of state that requires special handling? */
+ }
+
+ next = attr->next;
+ free(attr->data);
+ free(attr);
+ attr = next;
+ }
+ }
+}
+
+
+void _mesa_init_attrib( struct gl_context *ctx )
+{
+ /* Renderer and client attribute stacks */
+ ctx->AttribStackDepth = 0;
+ ctx->ClientAttribStackDepth = 0;
+}
diff --git a/mesalib/src/mesa/main/blend.c b/mesalib/src/mesa/main/blend.c
index c74a16803..22031fd2a 100644
--- a/mesalib/src/mesa/main/blend.c
+++ b/mesalib/src/mesa/main/blend.c
@@ -1,822 +1,822 @@
-/**
- * \file blend.c
- * Blending operations.
- */
-
-/*
- * Mesa 3-D graphics library
- * Version: 6.5.1
- *
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-
-#include "glheader.h"
-#include "blend.h"
-#include "context.h"
-#include "enums.h"
-#include "macros.h"
-#include "mtypes.h"
-
-
-
-/**
- * Check if given blend source factor is legal.
- * \return GL_TRUE if legal, GL_FALSE otherwise.
- */
-static GLboolean
-legal_src_factor(const struct gl_context *ctx, GLenum factor)
-{
- switch (factor) {
- case GL_SRC_COLOR:
- case GL_ONE_MINUS_SRC_COLOR:
- return ctx->Extensions.NV_blend_square;
- case GL_ZERO:
- case GL_ONE:
- case GL_DST_COLOR:
- case GL_ONE_MINUS_DST_COLOR:
- case GL_SRC_ALPHA:
- case GL_ONE_MINUS_SRC_ALPHA:
- case GL_DST_ALPHA:
- case GL_ONE_MINUS_DST_ALPHA:
- case GL_SRC_ALPHA_SATURATE:
- case GL_CONSTANT_COLOR:
- case GL_ONE_MINUS_CONSTANT_COLOR:
- case GL_CONSTANT_ALPHA:
- case GL_ONE_MINUS_CONSTANT_ALPHA:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Check if given blend destination factor is legal.
- * \return GL_TRUE if legal, GL_FALSE otherwise.
- */
-static GLboolean
-legal_dst_factor(const struct gl_context *ctx, GLenum factor)
-{
- switch (factor) {
- case GL_DST_COLOR:
- case GL_ONE_MINUS_DST_COLOR:
- return ctx->Extensions.NV_blend_square;
- case GL_ZERO:
- case GL_ONE:
- case GL_SRC_COLOR:
- case GL_ONE_MINUS_SRC_COLOR:
- case GL_SRC_ALPHA:
- case GL_ONE_MINUS_SRC_ALPHA:
- case GL_DST_ALPHA:
- case GL_ONE_MINUS_DST_ALPHA:
- case GL_CONSTANT_COLOR:
- case GL_ONE_MINUS_CONSTANT_COLOR:
- case GL_CONSTANT_ALPHA:
- case GL_ONE_MINUS_CONSTANT_ALPHA:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Check if src/dest RGB/A blend factors are legal. If not generate
- * a GL error.
- * \return GL_TRUE if factors are legal, GL_FALSE otherwise.
- */
-static GLboolean
-validate_blend_factors(struct gl_context *ctx, const char *func,
- GLenum sfactorRGB, GLenum dfactorRGB,
- GLenum sfactorA, GLenum dfactorA)
-{
- if (!legal_src_factor(ctx, sfactorRGB)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "%s(sfactorRGB = %s)", func,
- _mesa_lookup_enum_by_nr(sfactorRGB));
- return GL_FALSE;
- }
-
- if (!legal_dst_factor(ctx, dfactorRGB)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "%s(dfactorRGB = %s)", func,
- _mesa_lookup_enum_by_nr(dfactorRGB));
- return GL_FALSE;
- }
-
- if (sfactorA != sfactorRGB && !legal_src_factor(ctx, sfactorA)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "%s(sfactorA = %s)", func,
- _mesa_lookup_enum_by_nr(sfactorA));
- return GL_FALSE;
- }
-
- if (dfactorA != dfactorRGB && !legal_dst_factor(ctx, dfactorA)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "%s(dfactorA = %s)", func,
- _mesa_lookup_enum_by_nr(dfactorA));
- return GL_FALSE;
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Specify the blending operation.
- *
- * \param sfactor source factor operator.
- * \param dfactor destination factor operator.
- *
- * \sa glBlendFunc, glBlendFuncSeparateEXT
- */
-void GLAPIENTRY
-_mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
-{
- _mesa_BlendFuncSeparateEXT(sfactor, dfactor, sfactor, dfactor);
-}
-
-
-/**
- * Set the separate blend source/dest factors for all draw buffers.
- *
- * \param sfactorRGB RGB source factor operator.
- * \param dfactorRGB RGB destination factor operator.
- * \param sfactorA alpha source factor operator.
- * \param dfactorA alpha destination factor operator.
- */
-void GLAPIENTRY
-_mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
- GLenum sfactorA, GLenum dfactorA )
-{
- GLuint buf, numBuffers;
- GLboolean changed;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glBlendFuncSeparate %s %s %s %s\n",
- _mesa_lookup_enum_by_nr(sfactorRGB),
- _mesa_lookup_enum_by_nr(dfactorRGB),
- _mesa_lookup_enum_by_nr(sfactorA),
- _mesa_lookup_enum_by_nr(dfactorA));
-
- if (!validate_blend_factors(ctx, "glBlendFuncSeparate",
- sfactorRGB, dfactorRGB,
- sfactorA, dfactorA)) {
- return;
- }
-
- numBuffers = ctx->Extensions.ARB_draw_buffers_blend
- ? ctx->Const.MaxDrawBuffers : 1;
-
- changed = GL_FALSE;
- for (buf = 0; buf < numBuffers; buf++) {
- if (ctx->Color.Blend[buf].SrcRGB != sfactorRGB ||
- ctx->Color.Blend[buf].DstRGB != dfactorRGB ||
- ctx->Color.Blend[buf].SrcA != sfactorA ||
- ctx->Color.Blend[buf].DstA != dfactorA) {
- changed = GL_TRUE;
- break;
- }
- }
- if (!changed)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
-
- for (buf = 0; buf < numBuffers; buf++) {
- ctx->Color.Blend[buf].SrcRGB = sfactorRGB;
- ctx->Color.Blend[buf].DstRGB = dfactorRGB;
- ctx->Color.Blend[buf].SrcA = sfactorA;
- ctx->Color.Blend[buf].DstA = dfactorA;
- }
- ctx->Color._BlendFuncPerBuffer = GL_FALSE;
-
- if (ctx->Driver.BlendFuncSeparate) {
- ctx->Driver.BlendFuncSeparate(ctx, sfactorRGB, dfactorRGB,
- sfactorA, dfactorA);
- }
-}
-
-
-#if _HAVE_FULL_GL
-
-
-/**
- * Set blend source/dest factors for one color buffer/target.
- */
-void GLAPIENTRY
-_mesa_BlendFunci(GLuint buf, GLenum sfactor, GLenum dfactor)
-{
- _mesa_BlendFuncSeparatei(buf, sfactor, dfactor, sfactor, dfactor);
-}
-
-
-/**
- * Set separate blend source/dest factors for one color buffer/target.
- */
-void GLAPIENTRY
-_mesa_BlendFuncSeparatei(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB,
- GLenum sfactorA, GLenum dfactorA)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (!ctx->Extensions.ARB_draw_buffers_blend) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glBlendFunc[Separate]i()");
- return;
- }
-
- if (buf >= ctx->Const.MaxDrawBuffers) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glBlendFuncSeparatei(buffer=%u)",
- buf);
- return;
- }
-
- if (!validate_blend_factors(ctx, "glBlendFuncSeparatei",
- sfactorRGB, dfactorRGB,
- sfactorA, dfactorA)) {
- return;
- }
-
- if (ctx->Color.Blend[buf].SrcRGB == sfactorRGB &&
- ctx->Color.Blend[buf].DstRGB == dfactorRGB &&
- ctx->Color.Blend[buf].SrcA == sfactorA &&
- ctx->Color.Blend[buf].DstA == dfactorA)
- return; /* no change */
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
-
- ctx->Color.Blend[buf].SrcRGB = sfactorRGB;
- ctx->Color.Blend[buf].DstRGB = dfactorRGB;
- ctx->Color.Blend[buf].SrcA = sfactorA;
- ctx->Color.Blend[buf].DstA = dfactorA;
- ctx->Color._BlendFuncPerBuffer = GL_TRUE;
-
- if (ctx->Driver.BlendFuncSeparatei) {
- ctx->Driver.BlendFuncSeparatei(ctx, buf, sfactorRGB, dfactorRGB,
- sfactorA, dfactorA);
- }
-}
-
-
-/**
- * Check if given blend equation is legal.
- * \return GL_TRUE if legal, GL_FALSE otherwise.
- */
-static GLboolean
-legal_blend_equation(const struct gl_context *ctx,
- GLenum mode, GLboolean is_separate)
-{
- switch (mode) {
- case GL_FUNC_ADD:
- return GL_TRUE;
- case GL_MIN:
- case GL_MAX:
- return ctx->Extensions.EXT_blend_minmax;
- case GL_LOGIC_OP:
- /* glBlendEquationSeparate cannot take GL_LOGIC_OP as a parameter.
- */
- return ctx->Extensions.EXT_blend_logic_op && !is_separate;
- case GL_FUNC_SUBTRACT:
- case GL_FUNC_REVERSE_SUBTRACT:
- return ctx->Extensions.EXT_blend_subtract;
- default:
- return GL_FALSE;
- }
-}
-
-
-/* This is really an extension function! */
-void GLAPIENTRY
-_mesa_BlendEquation( GLenum mode )
-{
- GLuint buf, numBuffers;
- GLboolean changed;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glBlendEquation(%s)\n",
- _mesa_lookup_enum_by_nr(mode));
-
- if (!legal_blend_equation(ctx, mode, GL_FALSE)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquation");
- return;
- }
-
- numBuffers = ctx->Extensions.ARB_draw_buffers_blend
- ? ctx->Const.MaxDrawBuffers : 1;
-
- changed = GL_FALSE;
- for (buf = 0; buf < numBuffers; buf++) {
- if (ctx->Color.Blend[buf].EquationRGB != mode ||
- ctx->Color.Blend[buf].EquationA != mode) {
- changed = GL_TRUE;
- break;
- }
- }
- if (!changed)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- for (buf = 0; buf < numBuffers; buf++) {
- ctx->Color.Blend[buf].EquationRGB = mode;
- ctx->Color.Blend[buf].EquationA = mode;
- }
- ctx->Color._BlendEquationPerBuffer = GL_FALSE;
-
- if (ctx->Driver.BlendEquationSeparate)
- (*ctx->Driver.BlendEquationSeparate)( ctx, mode, mode );
-}
-
-
-/**
- * Set blend equation for one color buffer/target.
- */
-void GLAPIENTRY
-_mesa_BlendEquationi(GLuint buf, GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glBlendEquationi(%u, %s)\n",
- buf, _mesa_lookup_enum_by_nr(mode));
-
- if (buf >= ctx->Const.MaxDrawBuffers) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glBlendFuncSeparatei(buffer=%u)",
- buf);
- return;
- }
-
- if (!legal_blend_equation(ctx, mode, GL_FALSE)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationi");
- return;
- }
-
- if (ctx->Color.Blend[buf].EquationRGB == mode &&
- ctx->Color.Blend[buf].EquationA == mode)
- return; /* no change */
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- ctx->Color.Blend[buf].EquationRGB = mode;
- ctx->Color.Blend[buf].EquationA = mode;
- ctx->Color._BlendEquationPerBuffer = GL_TRUE;
-
- if (ctx->Driver.BlendEquationSeparatei)
- ctx->Driver.BlendEquationSeparatei(ctx, buf, mode, mode);
-}
-
-
-void GLAPIENTRY
-_mesa_BlendEquationSeparateEXT( GLenum modeRGB, GLenum modeA )
-{
- GLuint buf, numBuffers;
- GLboolean changed;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glBlendEquationSeparateEXT(%s %s)\n",
- _mesa_lookup_enum_by_nr(modeRGB),
- _mesa_lookup_enum_by_nr(modeA));
-
- if ( (modeRGB != modeA) && !ctx->Extensions.EXT_blend_equation_separate ) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBlendEquationSeparateEXT not supported by driver");
- return;
- }
-
- if (!legal_blend_equation(ctx, modeRGB, GL_TRUE)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeRGB)");
- return;
- }
-
- if (!legal_blend_equation(ctx, modeA, GL_TRUE)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeA)");
- return;
- }
-
- numBuffers = ctx->Extensions.ARB_draw_buffers_blend
- ? ctx->Const.MaxDrawBuffers : 1;
-
- changed = GL_FALSE;
- for (buf = 0; buf < numBuffers; buf++) {
- if (ctx->Color.Blend[buf].EquationRGB != modeRGB ||
- ctx->Color.Blend[buf].EquationA != modeA) {
- changed = GL_TRUE;
- break;
- }
- }
- if (!changed)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- for (buf = 0; buf < numBuffers; buf++) {
- ctx->Color.Blend[buf].EquationRGB = modeRGB;
- ctx->Color.Blend[buf].EquationA = modeA;
- }
- ctx->Color._BlendEquationPerBuffer = GL_FALSE;
-
- if (ctx->Driver.BlendEquationSeparate)
- ctx->Driver.BlendEquationSeparate(ctx, modeRGB, modeA);
-}
-
-
-/**
- * Set separate blend equations for one color buffer/target.
- */
-void
-_mesa_BlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeA)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glBlendEquationSeparatei(%u, %s %s)\n", buf,
- _mesa_lookup_enum_by_nr(modeRGB),
- _mesa_lookup_enum_by_nr(modeA));
-
- if (buf >= ctx->Const.MaxDrawBuffers) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glBlendEquationSeparatei(buffer=%u)",
- buf);
- return;
- }
-
- if (!legal_blend_equation(ctx, modeRGB, GL_TRUE)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparatei(modeRGB)");
- return;
- }
-
- if (!legal_blend_equation(ctx, modeA, GL_TRUE)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparatei(modeA)");
- return;
- }
-
- if (ctx->Color.Blend[buf].EquationRGB == modeRGB &&
- ctx->Color.Blend[buf].EquationA == modeA)
- return; /* no change */
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- ctx->Color.Blend[buf].EquationRGB = modeRGB;
- ctx->Color.Blend[buf].EquationA = modeA;
- ctx->Color._BlendEquationPerBuffer = GL_TRUE;
-
- if (ctx->Driver.BlendEquationSeparatei)
- ctx->Driver.BlendEquationSeparatei(ctx, buf, modeRGB, modeA);
-}
-
-
-
-#endif /* _HAVE_FULL_GL */
-
-
-/**
- * Set the blending color.
- *
- * \param red red color component.
- * \param green green color component.
- * \param blue blue color component.
- * \param alpha alpha color component.
- *
- * \sa glBlendColor().
- *
- * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
- * change, flushes the vertices and notifies the driver via
- * dd_function_table::BlendColor callback.
- */
-void GLAPIENTRY
-_mesa_BlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
-{
- GLfloat tmp[4];
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- tmp[0] = CLAMP( red, 0.0F, 1.0F );
- tmp[1] = CLAMP( green, 0.0F, 1.0F );
- tmp[2] = CLAMP( blue, 0.0F, 1.0F );
- tmp[3] = CLAMP( alpha, 0.0F, 1.0F );
-
- if (TEST_EQ_4V(tmp, ctx->Color.BlendColor))
- return;
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- COPY_4FV( ctx->Color.BlendColor, tmp );
-
- if (ctx->Driver.BlendColor)
- (*ctx->Driver.BlendColor)(ctx, tmp);
-}
-
-
-/**
- * Specify the alpha test function.
- *
- * \param func alpha comparison function.
- * \param ref reference value.
- *
- * Verifies the parameters and updates gl_colorbuffer_attrib.
- * On a change, flushes the vertices and notifies the driver via
- * dd_function_table::AlphaFunc callback.
- */
-void GLAPIENTRY
-_mesa_AlphaFunc( GLenum func, GLclampf ref )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glAlphaFunc(%s, %f)\n",
- _mesa_lookup_enum_by_nr(func), ref);
-
- switch (func) {
- case GL_NEVER:
- case GL_LESS:
- case GL_EQUAL:
- case GL_LEQUAL:
- case GL_GREATER:
- case GL_NOTEQUAL:
- case GL_GEQUAL:
- case GL_ALWAYS:
- ref = CLAMP(ref, 0.0F, 1.0F);
-
- if (ctx->Color.AlphaFunc == func && ctx->Color.AlphaRef == ref)
- return; /* no change */
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- ctx->Color.AlphaFunc = func;
- ctx->Color.AlphaRef = ref;
-
- if (ctx->Driver.AlphaFunc)
- ctx->Driver.AlphaFunc(ctx, func, ref);
- return;
-
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glAlphaFunc(func)" );
- return;
- }
-}
-
-
-/**
- * Specify a logic pixel operation for color index rendering.
- *
- * \param opcode operation.
- *
- * Verifies that \p opcode is a valid enum and updates
-gl_colorbuffer_attrib::LogicOp.
- * On a change, flushes the vertices and notifies the driver via the
- * dd_function_table::LogicOpcode callback.
- */
-void GLAPIENTRY
-_mesa_LogicOp( GLenum opcode )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glLogicOp(%s)\n", _mesa_lookup_enum_by_nr(opcode));
-
- switch (opcode) {
- case GL_CLEAR:
- case GL_SET:
- case GL_COPY:
- case GL_COPY_INVERTED:
- case GL_NOOP:
- case GL_INVERT:
- case GL_AND:
- case GL_NAND:
- case GL_OR:
- case GL_NOR:
- case GL_XOR:
- case GL_EQUIV:
- case GL_AND_REVERSE:
- case GL_AND_INVERTED:
- case GL_OR_REVERSE:
- case GL_OR_INVERTED:
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glLogicOp" );
- return;
- }
-
- if (ctx->Color.LogicOp == opcode)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- ctx->Color.LogicOp = opcode;
-
- if (ctx->Driver.LogicOpcode)
- ctx->Driver.LogicOpcode( ctx, opcode );
-}
-
-#if _HAVE_FULL_GL
-void GLAPIENTRY
-_mesa_IndexMask( GLuint mask )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (ctx->Color.IndexMask == mask)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- ctx->Color.IndexMask = mask;
-}
-#endif
-
-
-/**
- * Enable or disable writing of frame buffer color components.
- *
- * \param red whether to mask writing of the red color component.
- * \param green whether to mask writing of the green color component.
- * \param blue whether to mask writing of the blue color component.
- * \param alpha whether to mask writing of the alpha color component.
- *
- * \sa glColorMask().
- *
- * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
- * change, flushes the vertices and notifies the driver via the
- * dd_function_table::ColorMask callback.
- */
-void GLAPIENTRY
-_mesa_ColorMask( GLboolean red, GLboolean green,
- GLboolean blue, GLboolean alpha )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLubyte tmp[4];
- GLuint i;
- GLboolean flushed;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glColorMask(%d, %d, %d, %d)\n",
- red, green, blue, alpha);
-
- /* Shouldn't have any information about channel depth in core mesa
- * -- should probably store these as the native booleans:
- */
- tmp[RCOMP] = red ? 0xff : 0x0;
- tmp[GCOMP] = green ? 0xff : 0x0;
- tmp[BCOMP] = blue ? 0xff : 0x0;
- tmp[ACOMP] = alpha ? 0xff : 0x0;
-
- flushed = GL_FALSE;
- for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
- if (!TEST_EQ_4V(tmp, ctx->Color.ColorMask[i])) {
- if (!flushed) {
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- }
- flushed = GL_TRUE;
- COPY_4UBV(ctx->Color.ColorMask[i], tmp);
- }
- }
-
- if (ctx->Driver.ColorMask)
- ctx->Driver.ColorMask( ctx, red, green, blue, alpha );
-}
-
-
-/**
- * For GL_EXT_draw_buffers2 and GL3
- */
-void GLAPIENTRY
-_mesa_ColorMaskIndexed( GLuint buf, GLboolean red, GLboolean green,
- GLboolean blue, GLboolean alpha )
-{
- GLubyte tmp[4];
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glColorMaskIndexed %u %d %d %d %d\n",
- buf, red, green, blue, alpha);
-
- if (buf >= ctx->Const.MaxDrawBuffers) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glColorMaskIndexed(buf=%u)", buf);
- return;
- }
-
- /* Shouldn't have any information about channel depth in core mesa
- * -- should probably store these as the native booleans:
- */
- tmp[RCOMP] = red ? 0xff : 0x0;
- tmp[GCOMP] = green ? 0xff : 0x0;
- tmp[BCOMP] = blue ? 0xff : 0x0;
- tmp[ACOMP] = alpha ? 0xff : 0x0;
-
- if (TEST_EQ_4V(tmp, ctx->Color.ColorMask[buf]))
- return;
-
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- COPY_4UBV(ctx->Color.ColorMask[buf], tmp);
-
- if (ctx->Driver.ColorMaskIndexed)
- ctx->Driver.ColorMaskIndexed(ctx, buf, red, green, blue, alpha);
-}
-
-
-extern void GLAPIENTRY
-_mesa_ClampColorARB(GLenum target, GLenum clamp)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (clamp != GL_TRUE && clamp != GL_FALSE && clamp != GL_FIXED_ONLY_ARB) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(clamp)");
- return;
- }
-
- switch (target) {
- case GL_CLAMP_VERTEX_COLOR_ARB:
- ctx->Light.ClampVertexColor = clamp;
- break;
- case GL_CLAMP_FRAGMENT_COLOR_ARB:
- ctx->Color.ClampFragmentColor = clamp;
- break;
- case GL_CLAMP_READ_COLOR_ARB:
- ctx->Color.ClampReadColor = clamp;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(target)");
- return;
- }
-}
-
-
-
-
-/**********************************************************************/
-/** \name Initialization */
-/*@{*/
-
-/**
- * Initialization of the context's Color attribute group.
- *
- * \param ctx GL context.
- *
- * Initializes the related fields in the context color attribute group,
- * __struct gl_contextRec::Color.
- */
-void _mesa_init_color( struct gl_context * ctx )
-{
- GLuint i;
-
- /* Color buffer group */
- ctx->Color.IndexMask = ~0u;
- memset(ctx->Color.ColorMask, 0xff, sizeof(ctx->Color.ColorMask));
- ctx->Color.ClearIndex = 0;
- ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
- ctx->Color.AlphaEnabled = GL_FALSE;
- ctx->Color.AlphaFunc = GL_ALWAYS;
- ctx->Color.AlphaRef = 0;
- ctx->Color.BlendEnabled = 0x0;
- for (i = 0; i < Elements(ctx->Color.Blend); i++) {
- ctx->Color.Blend[i].SrcRGB = GL_ONE;
- ctx->Color.Blend[i].DstRGB = GL_ZERO;
- ctx->Color.Blend[i].SrcA = GL_ONE;
- ctx->Color.Blend[i].DstA = GL_ZERO;
- ctx->Color.Blend[i].EquationRGB = GL_FUNC_ADD;
- ctx->Color.Blend[i].EquationA = GL_FUNC_ADD;
- }
- ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
- ctx->Color.IndexLogicOpEnabled = GL_FALSE;
- ctx->Color.ColorLogicOpEnabled = GL_FALSE;
- ctx->Color._LogicOpEnabled = GL_FALSE;
- ctx->Color.LogicOp = GL_COPY;
- ctx->Color.DitherFlag = GL_TRUE;
-
- if (ctx->Visual.doubleBufferMode) {
- ctx->Color.DrawBuffer[0] = GL_BACK;
- }
- else {
- ctx->Color.DrawBuffer[0] = GL_FRONT;
- }
-
- ctx->Color.ClampFragmentColor = GL_FIXED_ONLY_ARB;
- ctx->Color.ClampReadColor = GL_FIXED_ONLY_ARB;
-}
-
-/*@}*/
+/**
+ * \file blend.c
+ * Blending operations.
+ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5.1
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+#include "glheader.h"
+#include "blend.h"
+#include "context.h"
+#include "enums.h"
+#include "macros.h"
+#include "mtypes.h"
+
+
+
+/**
+ * Check if given blend source factor is legal.
+ * \return GL_TRUE if legal, GL_FALSE otherwise.
+ */
+static GLboolean
+legal_src_factor(const struct gl_context *ctx, GLenum factor)
+{
+ switch (factor) {
+ case GL_SRC_COLOR:
+ case GL_ONE_MINUS_SRC_COLOR:
+ return ctx->Extensions.NV_blend_square;
+ case GL_ZERO:
+ case GL_ONE:
+ case GL_DST_COLOR:
+ case GL_ONE_MINUS_DST_COLOR:
+ case GL_SRC_ALPHA:
+ case GL_ONE_MINUS_SRC_ALPHA:
+ case GL_DST_ALPHA:
+ case GL_ONE_MINUS_DST_ALPHA:
+ case GL_SRC_ALPHA_SATURATE:
+ case GL_CONSTANT_COLOR:
+ case GL_ONE_MINUS_CONSTANT_COLOR:
+ case GL_CONSTANT_ALPHA:
+ case GL_ONE_MINUS_CONSTANT_ALPHA:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Check if given blend destination factor is legal.
+ * \return GL_TRUE if legal, GL_FALSE otherwise.
+ */
+static GLboolean
+legal_dst_factor(const struct gl_context *ctx, GLenum factor)
+{
+ switch (factor) {
+ case GL_DST_COLOR:
+ case GL_ONE_MINUS_DST_COLOR:
+ return ctx->Extensions.NV_blend_square;
+ case GL_ZERO:
+ case GL_ONE:
+ case GL_SRC_COLOR:
+ case GL_ONE_MINUS_SRC_COLOR:
+ case GL_SRC_ALPHA:
+ case GL_ONE_MINUS_SRC_ALPHA:
+ case GL_DST_ALPHA:
+ case GL_ONE_MINUS_DST_ALPHA:
+ case GL_CONSTANT_COLOR:
+ case GL_ONE_MINUS_CONSTANT_COLOR:
+ case GL_CONSTANT_ALPHA:
+ case GL_ONE_MINUS_CONSTANT_ALPHA:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Check if src/dest RGB/A blend factors are legal. If not generate
+ * a GL error.
+ * \return GL_TRUE if factors are legal, GL_FALSE otherwise.
+ */
+static GLboolean
+validate_blend_factors(struct gl_context *ctx, const char *func,
+ GLenum sfactorRGB, GLenum dfactorRGB,
+ GLenum sfactorA, GLenum dfactorA)
+{
+ if (!legal_src_factor(ctx, sfactorRGB)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "%s(sfactorRGB = %s)", func,
+ _mesa_lookup_enum_by_nr(sfactorRGB));
+ return GL_FALSE;
+ }
+
+ if (!legal_dst_factor(ctx, dfactorRGB)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "%s(dfactorRGB = %s)", func,
+ _mesa_lookup_enum_by_nr(dfactorRGB));
+ return GL_FALSE;
+ }
+
+ if (sfactorA != sfactorRGB && !legal_src_factor(ctx, sfactorA)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "%s(sfactorA = %s)", func,
+ _mesa_lookup_enum_by_nr(sfactorA));
+ return GL_FALSE;
+ }
+
+ if (dfactorA != dfactorRGB && !legal_dst_factor(ctx, dfactorA)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "%s(dfactorA = %s)", func,
+ _mesa_lookup_enum_by_nr(dfactorA));
+ return GL_FALSE;
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Specify the blending operation.
+ *
+ * \param sfactor source factor operator.
+ * \param dfactor destination factor operator.
+ *
+ * \sa glBlendFunc, glBlendFuncSeparateEXT
+ */
+void GLAPIENTRY
+_mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
+{
+ _mesa_BlendFuncSeparateEXT(sfactor, dfactor, sfactor, dfactor);
+}
+
+
+/**
+ * Set the separate blend source/dest factors for all draw buffers.
+ *
+ * \param sfactorRGB RGB source factor operator.
+ * \param dfactorRGB RGB destination factor operator.
+ * \param sfactorA alpha source factor operator.
+ * \param dfactorA alpha destination factor operator.
+ */
+void GLAPIENTRY
+_mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
+ GLenum sfactorA, GLenum dfactorA )
+{
+ GLuint buf, numBuffers;
+ GLboolean changed;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glBlendFuncSeparate %s %s %s %s\n",
+ _mesa_lookup_enum_by_nr(sfactorRGB),
+ _mesa_lookup_enum_by_nr(dfactorRGB),
+ _mesa_lookup_enum_by_nr(sfactorA),
+ _mesa_lookup_enum_by_nr(dfactorA));
+
+ if (!validate_blend_factors(ctx, "glBlendFuncSeparate",
+ sfactorRGB, dfactorRGB,
+ sfactorA, dfactorA)) {
+ return;
+ }
+
+ numBuffers = ctx->Extensions.ARB_draw_buffers_blend
+ ? ctx->Const.MaxDrawBuffers : 1;
+
+ changed = GL_FALSE;
+ for (buf = 0; buf < numBuffers; buf++) {
+ if (ctx->Color.Blend[buf].SrcRGB != sfactorRGB ||
+ ctx->Color.Blend[buf].DstRGB != dfactorRGB ||
+ ctx->Color.Blend[buf].SrcA != sfactorA ||
+ ctx->Color.Blend[buf].DstA != dfactorA) {
+ changed = GL_TRUE;
+ break;
+ }
+ }
+ if (!changed)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+
+ for (buf = 0; buf < numBuffers; buf++) {
+ ctx->Color.Blend[buf].SrcRGB = sfactorRGB;
+ ctx->Color.Blend[buf].DstRGB = dfactorRGB;
+ ctx->Color.Blend[buf].SrcA = sfactorA;
+ ctx->Color.Blend[buf].DstA = dfactorA;
+ }
+ ctx->Color._BlendFuncPerBuffer = GL_FALSE;
+
+ if (ctx->Driver.BlendFuncSeparate) {
+ ctx->Driver.BlendFuncSeparate(ctx, sfactorRGB, dfactorRGB,
+ sfactorA, dfactorA);
+ }
+}
+
+
+#if _HAVE_FULL_GL
+
+
+/**
+ * Set blend source/dest factors for one color buffer/target.
+ */
+void GLAPIENTRY
+_mesa_BlendFunci(GLuint buf, GLenum sfactor, GLenum dfactor)
+{
+ _mesa_BlendFuncSeparatei(buf, sfactor, dfactor, sfactor, dfactor);
+}
+
+
+/**
+ * Set separate blend source/dest factors for one color buffer/target.
+ */
+void GLAPIENTRY
+_mesa_BlendFuncSeparatei(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB,
+ GLenum sfactorA, GLenum dfactorA)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!ctx->Extensions.ARB_draw_buffers_blend) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBlendFunc[Separate]i()");
+ return;
+ }
+
+ if (buf >= ctx->Const.MaxDrawBuffers) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBlendFuncSeparatei(buffer=%u)",
+ buf);
+ return;
+ }
+
+ if (!validate_blend_factors(ctx, "glBlendFuncSeparatei",
+ sfactorRGB, dfactorRGB,
+ sfactorA, dfactorA)) {
+ return;
+ }
+
+ if (ctx->Color.Blend[buf].SrcRGB == sfactorRGB &&
+ ctx->Color.Blend[buf].DstRGB == dfactorRGB &&
+ ctx->Color.Blend[buf].SrcA == sfactorA &&
+ ctx->Color.Blend[buf].DstA == dfactorA)
+ return; /* no change */
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+
+ ctx->Color.Blend[buf].SrcRGB = sfactorRGB;
+ ctx->Color.Blend[buf].DstRGB = dfactorRGB;
+ ctx->Color.Blend[buf].SrcA = sfactorA;
+ ctx->Color.Blend[buf].DstA = dfactorA;
+ ctx->Color._BlendFuncPerBuffer = GL_TRUE;
+
+ if (ctx->Driver.BlendFuncSeparatei) {
+ ctx->Driver.BlendFuncSeparatei(ctx, buf, sfactorRGB, dfactorRGB,
+ sfactorA, dfactorA);
+ }
+}
+
+
+/**
+ * Check if given blend equation is legal.
+ * \return GL_TRUE if legal, GL_FALSE otherwise.
+ */
+static GLboolean
+legal_blend_equation(const struct gl_context *ctx,
+ GLenum mode, GLboolean is_separate)
+{
+ switch (mode) {
+ case GL_FUNC_ADD:
+ return GL_TRUE;
+ case GL_MIN:
+ case GL_MAX:
+ return ctx->Extensions.EXT_blend_minmax;
+ case GL_LOGIC_OP:
+ /* glBlendEquationSeparate cannot take GL_LOGIC_OP as a parameter.
+ */
+ return ctx->Extensions.EXT_blend_logic_op && !is_separate;
+ case GL_FUNC_SUBTRACT:
+ case GL_FUNC_REVERSE_SUBTRACT:
+ return ctx->Extensions.EXT_blend_subtract;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/* This is really an extension function! */
+void GLAPIENTRY
+_mesa_BlendEquation( GLenum mode )
+{
+ GLuint buf, numBuffers;
+ GLboolean changed;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glBlendEquation(%s)\n",
+ _mesa_lookup_enum_by_nr(mode));
+
+ if (!legal_blend_equation(ctx, mode, GL_FALSE)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquation");
+ return;
+ }
+
+ numBuffers = ctx->Extensions.ARB_draw_buffers_blend
+ ? ctx->Const.MaxDrawBuffers : 1;
+
+ changed = GL_FALSE;
+ for (buf = 0; buf < numBuffers; buf++) {
+ if (ctx->Color.Blend[buf].EquationRGB != mode ||
+ ctx->Color.Blend[buf].EquationA != mode) {
+ changed = GL_TRUE;
+ break;
+ }
+ }
+ if (!changed)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ for (buf = 0; buf < numBuffers; buf++) {
+ ctx->Color.Blend[buf].EquationRGB = mode;
+ ctx->Color.Blend[buf].EquationA = mode;
+ }
+ ctx->Color._BlendEquationPerBuffer = GL_FALSE;
+
+ if (ctx->Driver.BlendEquationSeparate)
+ (*ctx->Driver.BlendEquationSeparate)( ctx, mode, mode );
+}
+
+
+/**
+ * Set blend equation for one color buffer/target.
+ */
+void GLAPIENTRY
+_mesa_BlendEquationi(GLuint buf, GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glBlendEquationi(%u, %s)\n",
+ buf, _mesa_lookup_enum_by_nr(mode));
+
+ if (buf >= ctx->Const.MaxDrawBuffers) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBlendFuncSeparatei(buffer=%u)",
+ buf);
+ return;
+ }
+
+ if (!legal_blend_equation(ctx, mode, GL_FALSE)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationi");
+ return;
+ }
+
+ if (ctx->Color.Blend[buf].EquationRGB == mode &&
+ ctx->Color.Blend[buf].EquationA == mode)
+ return; /* no change */
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->Color.Blend[buf].EquationRGB = mode;
+ ctx->Color.Blend[buf].EquationA = mode;
+ ctx->Color._BlendEquationPerBuffer = GL_TRUE;
+
+ if (ctx->Driver.BlendEquationSeparatei)
+ ctx->Driver.BlendEquationSeparatei(ctx, buf, mode, mode);
+}
+
+
+void GLAPIENTRY
+_mesa_BlendEquationSeparateEXT( GLenum modeRGB, GLenum modeA )
+{
+ GLuint buf, numBuffers;
+ GLboolean changed;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glBlendEquationSeparateEXT(%s %s)\n",
+ _mesa_lookup_enum_by_nr(modeRGB),
+ _mesa_lookup_enum_by_nr(modeA));
+
+ if ( (modeRGB != modeA) && !ctx->Extensions.EXT_blend_equation_separate ) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBlendEquationSeparateEXT not supported by driver");
+ return;
+ }
+
+ if (!legal_blend_equation(ctx, modeRGB, GL_TRUE)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeRGB)");
+ return;
+ }
+
+ if (!legal_blend_equation(ctx, modeA, GL_TRUE)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeA)");
+ return;
+ }
+
+ numBuffers = ctx->Extensions.ARB_draw_buffers_blend
+ ? ctx->Const.MaxDrawBuffers : 1;
+
+ changed = GL_FALSE;
+ for (buf = 0; buf < numBuffers; buf++) {
+ if (ctx->Color.Blend[buf].EquationRGB != modeRGB ||
+ ctx->Color.Blend[buf].EquationA != modeA) {
+ changed = GL_TRUE;
+ break;
+ }
+ }
+ if (!changed)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ for (buf = 0; buf < numBuffers; buf++) {
+ ctx->Color.Blend[buf].EquationRGB = modeRGB;
+ ctx->Color.Blend[buf].EquationA = modeA;
+ }
+ ctx->Color._BlendEquationPerBuffer = GL_FALSE;
+
+ if (ctx->Driver.BlendEquationSeparate)
+ ctx->Driver.BlendEquationSeparate(ctx, modeRGB, modeA);
+}
+
+
+/**
+ * Set separate blend equations for one color buffer/target.
+ */
+void
+_mesa_BlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeA)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glBlendEquationSeparatei(%u, %s %s)\n", buf,
+ _mesa_lookup_enum_by_nr(modeRGB),
+ _mesa_lookup_enum_by_nr(modeA));
+
+ if (buf >= ctx->Const.MaxDrawBuffers) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBlendEquationSeparatei(buffer=%u)",
+ buf);
+ return;
+ }
+
+ if (!legal_blend_equation(ctx, modeRGB, GL_TRUE)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparatei(modeRGB)");
+ return;
+ }
+
+ if (!legal_blend_equation(ctx, modeA, GL_TRUE)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparatei(modeA)");
+ return;
+ }
+
+ if (ctx->Color.Blend[buf].EquationRGB == modeRGB &&
+ ctx->Color.Blend[buf].EquationA == modeA)
+ return; /* no change */
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->Color.Blend[buf].EquationRGB = modeRGB;
+ ctx->Color.Blend[buf].EquationA = modeA;
+ ctx->Color._BlendEquationPerBuffer = GL_TRUE;
+
+ if (ctx->Driver.BlendEquationSeparatei)
+ ctx->Driver.BlendEquationSeparatei(ctx, buf, modeRGB, modeA);
+}
+
+
+
+#endif /* _HAVE_FULL_GL */
+
+
+/**
+ * Set the blending color.
+ *
+ * \param red red color component.
+ * \param green green color component.
+ * \param blue blue color component.
+ * \param alpha alpha color component.
+ *
+ * \sa glBlendColor().
+ *
+ * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
+ * change, flushes the vertices and notifies the driver via
+ * dd_function_table::BlendColor callback.
+ */
+void GLAPIENTRY
+_mesa_BlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
+{
+ GLfloat tmp[4];
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ tmp[0] = CLAMP( red, 0.0F, 1.0F );
+ tmp[1] = CLAMP( green, 0.0F, 1.0F );
+ tmp[2] = CLAMP( blue, 0.0F, 1.0F );
+ tmp[3] = CLAMP( alpha, 0.0F, 1.0F );
+
+ if (TEST_EQ_4V(tmp, ctx->Color.BlendColor))
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ COPY_4FV( ctx->Color.BlendColor, tmp );
+
+ if (ctx->Driver.BlendColor)
+ (*ctx->Driver.BlendColor)(ctx, tmp);
+}
+
+
+/**
+ * Specify the alpha test function.
+ *
+ * \param func alpha comparison function.
+ * \param ref reference value.
+ *
+ * Verifies the parameters and updates gl_colorbuffer_attrib.
+ * On a change, flushes the vertices and notifies the driver via
+ * dd_function_table::AlphaFunc callback.
+ */
+void GLAPIENTRY
+_mesa_AlphaFunc( GLenum func, GLclampf ref )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glAlphaFunc(%s, %f)\n",
+ _mesa_lookup_enum_by_nr(func), ref);
+
+ switch (func) {
+ case GL_NEVER:
+ case GL_LESS:
+ case GL_EQUAL:
+ case GL_LEQUAL:
+ case GL_GREATER:
+ case GL_NOTEQUAL:
+ case GL_GEQUAL:
+ case GL_ALWAYS:
+ ref = CLAMP(ref, 0.0F, 1.0F);
+
+ if (ctx->Color.AlphaFunc == func && ctx->Color.AlphaRef == ref)
+ return; /* no change */
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->Color.AlphaFunc = func;
+ ctx->Color.AlphaRef = ref;
+
+ if (ctx->Driver.AlphaFunc)
+ ctx->Driver.AlphaFunc(ctx, func, ref);
+ return;
+
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glAlphaFunc(func)" );
+ return;
+ }
+}
+
+
+/**
+ * Specify a logic pixel operation for color index rendering.
+ *
+ * \param opcode operation.
+ *
+ * Verifies that \p opcode is a valid enum and updates
+gl_colorbuffer_attrib::LogicOp.
+ * On a change, flushes the vertices and notifies the driver via the
+ * dd_function_table::LogicOpcode callback.
+ */
+void GLAPIENTRY
+_mesa_LogicOp( GLenum opcode )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glLogicOp(%s)\n", _mesa_lookup_enum_by_nr(opcode));
+
+ switch (opcode) {
+ case GL_CLEAR:
+ case GL_SET:
+ case GL_COPY:
+ case GL_COPY_INVERTED:
+ case GL_NOOP:
+ case GL_INVERT:
+ case GL_AND:
+ case GL_NAND:
+ case GL_OR:
+ case GL_NOR:
+ case GL_XOR:
+ case GL_EQUIV:
+ case GL_AND_REVERSE:
+ case GL_AND_INVERTED:
+ case GL_OR_REVERSE:
+ case GL_OR_INVERTED:
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glLogicOp" );
+ return;
+ }
+
+ if (ctx->Color.LogicOp == opcode)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->Color.LogicOp = opcode;
+
+ if (ctx->Driver.LogicOpcode)
+ ctx->Driver.LogicOpcode( ctx, opcode );
+}
+
+#if _HAVE_FULL_GL
+void GLAPIENTRY
+_mesa_IndexMask( GLuint mask )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (ctx->Color.IndexMask == mask)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->Color.IndexMask = mask;
+}
+#endif
+
+
+/**
+ * Enable or disable writing of frame buffer color components.
+ *
+ * \param red whether to mask writing of the red color component.
+ * \param green whether to mask writing of the green color component.
+ * \param blue whether to mask writing of the blue color component.
+ * \param alpha whether to mask writing of the alpha color component.
+ *
+ * \sa glColorMask().
+ *
+ * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
+ * change, flushes the vertices and notifies the driver via the
+ * dd_function_table::ColorMask callback.
+ */
+void GLAPIENTRY
+_mesa_ColorMask( GLboolean red, GLboolean green,
+ GLboolean blue, GLboolean alpha )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLubyte tmp[4];
+ GLuint i;
+ GLboolean flushed;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glColorMask(%d, %d, %d, %d)\n",
+ red, green, blue, alpha);
+
+ /* Shouldn't have any information about channel depth in core mesa
+ * -- should probably store these as the native booleans:
+ */
+ tmp[RCOMP] = red ? 0xff : 0x0;
+ tmp[GCOMP] = green ? 0xff : 0x0;
+ tmp[BCOMP] = blue ? 0xff : 0x0;
+ tmp[ACOMP] = alpha ? 0xff : 0x0;
+
+ flushed = GL_FALSE;
+ for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
+ if (!TEST_EQ_4V(tmp, ctx->Color.ColorMask[i])) {
+ if (!flushed) {
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ }
+ flushed = GL_TRUE;
+ COPY_4UBV(ctx->Color.ColorMask[i], tmp);
+ }
+ }
+
+ if (ctx->Driver.ColorMask)
+ ctx->Driver.ColorMask( ctx, red, green, blue, alpha );
+}
+
+
+/**
+ * For GL_EXT_draw_buffers2 and GL3
+ */
+void GLAPIENTRY
+_mesa_ColorMaskIndexed( GLuint buf, GLboolean red, GLboolean green,
+ GLboolean blue, GLboolean alpha )
+{
+ GLubyte tmp[4];
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glColorMaskIndexed %u %d %d %d %d\n",
+ buf, red, green, blue, alpha);
+
+ if (buf >= ctx->Const.MaxDrawBuffers) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glColorMaskIndexed(buf=%u)", buf);
+ return;
+ }
+
+ /* Shouldn't have any information about channel depth in core mesa
+ * -- should probably store these as the native booleans:
+ */
+ tmp[RCOMP] = red ? 0xff : 0x0;
+ tmp[GCOMP] = green ? 0xff : 0x0;
+ tmp[BCOMP] = blue ? 0xff : 0x0;
+ tmp[ACOMP] = alpha ? 0xff : 0x0;
+
+ if (TEST_EQ_4V(tmp, ctx->Color.ColorMask[buf]))
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ COPY_4UBV(ctx->Color.ColorMask[buf], tmp);
+
+ if (ctx->Driver.ColorMaskIndexed)
+ ctx->Driver.ColorMaskIndexed(ctx, buf, red, green, blue, alpha);
+}
+
+
+extern void GLAPIENTRY
+_mesa_ClampColorARB(GLenum target, GLenum clamp)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (clamp != GL_TRUE && clamp != GL_FALSE && clamp != GL_FIXED_ONLY_ARB) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(clamp)");
+ return;
+ }
+
+ switch (target) {
+ case GL_CLAMP_VERTEX_COLOR_ARB:
+ ctx->Light.ClampVertexColor = clamp;
+ break;
+ case GL_CLAMP_FRAGMENT_COLOR_ARB:
+ ctx->Color.ClampFragmentColor = clamp;
+ break;
+ case GL_CLAMP_READ_COLOR_ARB:
+ ctx->Color.ClampReadColor = clamp;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(target)");
+ return;
+ }
+}
+
+
+
+
+/**********************************************************************/
+/** \name Initialization */
+/*@{*/
+
+/**
+ * Initialization of the context's Color attribute group.
+ *
+ * \param ctx GL context.
+ *
+ * Initializes the related fields in the context color attribute group,
+ * __struct gl_contextRec::Color.
+ */
+void _mesa_init_color( struct gl_context * ctx )
+{
+ GLuint i;
+
+ /* Color buffer group */
+ ctx->Color.IndexMask = ~0u;
+ memset(ctx->Color.ColorMask, 0xff, sizeof(ctx->Color.ColorMask));
+ ctx->Color.ClearIndex = 0;
+ ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
+ ctx->Color.AlphaEnabled = GL_FALSE;
+ ctx->Color.AlphaFunc = GL_ALWAYS;
+ ctx->Color.AlphaRef = 0;
+ ctx->Color.BlendEnabled = 0x0;
+ for (i = 0; i < Elements(ctx->Color.Blend); i++) {
+ ctx->Color.Blend[i].SrcRGB = GL_ONE;
+ ctx->Color.Blend[i].DstRGB = GL_ZERO;
+ ctx->Color.Blend[i].SrcA = GL_ONE;
+ ctx->Color.Blend[i].DstA = GL_ZERO;
+ ctx->Color.Blend[i].EquationRGB = GL_FUNC_ADD;
+ ctx->Color.Blend[i].EquationA = GL_FUNC_ADD;
+ }
+ ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
+ ctx->Color.IndexLogicOpEnabled = GL_FALSE;
+ ctx->Color.ColorLogicOpEnabled = GL_FALSE;
+ ctx->Color._LogicOpEnabled = GL_FALSE;
+ ctx->Color.LogicOp = GL_COPY;
+ ctx->Color.DitherFlag = GL_TRUE;
+
+ if (ctx->Visual.doubleBufferMode) {
+ ctx->Color.DrawBuffer[0] = GL_BACK;
+ }
+ else {
+ ctx->Color.DrawBuffer[0] = GL_FRONT;
+ }
+
+ ctx->Color.ClampFragmentColor = GL_FIXED_ONLY_ARB;
+ ctx->Color.ClampReadColor = GL_FIXED_ONLY_ARB;
+}
+
+/*@}*/
diff --git a/mesalib/src/mesa/main/bufferobj.c b/mesalib/src/mesa/main/bufferobj.c
index 35d92616f..8b5899918 100644
--- a/mesalib/src/mesa/main/bufferobj.c
+++ b/mesalib/src/mesa/main/bufferobj.c
@@ -1,1916 +1,1916 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.6
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file bufferobj.c
- * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
- * \author Brian Paul, Ian Romanick
- */
-
-
-#include "glheader.h"
-#include "enums.h"
-#include "hash.h"
-#include "imports.h"
-#include "image.h"
-#include "context.h"
-#include "bufferobj.h"
-#include "fbobject.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "texobj.h"
-
-
-/* Debug flags */
-/*#define VBO_DEBUG*/
-/*#define BOUNDS_CHECK*/
-
-
-#if FEATURE_OES_mapbuffer
-#define DEFAULT_ACCESS GL_MAP_WRITE_BIT
-#else
-#define DEFAULT_ACCESS (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)
-#endif
-
-
-/**
- * Used as a placeholder for buffer objects between glGenBuffers() and
- * glBindBuffer() so that glIsBuffer() can work correctly.
- */
-static struct gl_buffer_object DummyBufferObject;
-
-
-/**
- * Return pointer to address of a buffer object target.
- * \param ctx the GL context
- * \param target the buffer object target to be retrieved.
- * \return pointer to pointer to the buffer object bound to \c target in the
- * specified context or \c NULL if \c target is invalid.
- */
-static INLINE struct gl_buffer_object **
-get_buffer_target(struct gl_context *ctx, GLenum target)
-{
- switch (target) {
- case GL_ARRAY_BUFFER_ARB:
- return &ctx->Array.ArrayBufferObj;
- case GL_ELEMENT_ARRAY_BUFFER_ARB:
- return &ctx->Array.ElementArrayBufferObj;
- case GL_PIXEL_PACK_BUFFER_EXT:
- return &ctx->Pack.BufferObj;
- case GL_PIXEL_UNPACK_BUFFER_EXT:
- return &ctx->Unpack.BufferObj;
- case GL_COPY_READ_BUFFER:
- return &ctx->CopyReadBuffer;
- case GL_COPY_WRITE_BUFFER:
- return &ctx->CopyWriteBuffer;
-#if FEATURE_EXT_transform_feedback
- case GL_TRANSFORM_FEEDBACK_BUFFER:
- if (ctx->Extensions.EXT_transform_feedback) {
- return &ctx->TransformFeedback.CurrentBuffer;
- }
- break;
-#endif
- default:
- return NULL;
- }
- return NULL;
-}
-
-
-/**
- * Get the buffer object bound to the specified target in a GL context.
- * \param ctx the GL context
- * \param target the buffer object target to be retrieved.
- * \return pointer to the buffer object bound to \c target in the
- * specified context or \c NULL if \c target is invalid.
- */
-static INLINE struct gl_buffer_object *
-get_buffer(struct gl_context *ctx, GLenum target)
-{
- struct gl_buffer_object **bufObj = get_buffer_target(ctx, target);
- if (bufObj)
- return *bufObj;
- return NULL;
-}
-
-
-/**
- * Convert a GLbitfield describing the mapped buffer access flags
- * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
- */
-static GLenum
-simplified_access_mode(GLbitfield access)
-{
- const GLbitfield rwFlags = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
- if ((access & rwFlags) == rwFlags)
- return GL_READ_WRITE;
- if ((access & GL_MAP_READ_BIT) == GL_MAP_READ_BIT)
- return GL_READ_ONLY;
- if ((access & GL_MAP_WRITE_BIT) == GL_MAP_WRITE_BIT)
- return GL_WRITE_ONLY;
- return GL_READ_WRITE; /* this should never happen, but no big deal */
-}
-
-
-/**
- * Tests the subdata range parameters and sets the GL error code for
- * \c glBufferSubDataARB and \c glGetBufferSubDataARB.
- *
- * \param ctx GL context.
- * \param target Buffer object target on which to operate.
- * \param offset Offset of the first byte of the subdata range.
- * \param size Size, in bytes, of the subdata range.
- * \param caller Name of calling function for recording errors.
- * \return A pointer to the buffer object bound to \c target in the
- * specified context or \c NULL if any of the parameter or state
- * conditions for \c glBufferSubDataARB or \c glGetBufferSubDataARB
- * are invalid.
- *
- * \sa glBufferSubDataARB, glGetBufferSubDataARB
- */
-static struct gl_buffer_object *
-buffer_object_subdata_range_good( struct gl_context * ctx, GLenum target,
- GLintptrARB offset, GLsizeiptrARB size,
- const char *caller )
-{
- struct gl_buffer_object *bufObj;
-
- if (size < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(size < 0)", caller);
- return NULL;
- }
-
- if (offset < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset < 0)", caller);
- return NULL;
- }
-
- bufObj = get_buffer(ctx, target);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", caller);
- return NULL;
- }
- if (!_mesa_is_bufferobj(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
- return NULL;
- }
- if (offset + size > bufObj->Size) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "%s(size + offset > buffer size)", caller);
- return NULL;
- }
- if (_mesa_bufferobj_mapped(bufObj)) {
- /* Buffer is currently mapped */
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
- return NULL;
- }
-
- return bufObj;
-}
-
-
-/**
- * Allocate and initialize a new buffer object.
- *
- * Default callback for the \c dd_function_table::NewBufferObject() hook.
- */
-static struct gl_buffer_object *
-_mesa_new_buffer_object( struct gl_context *ctx, GLuint name, GLenum target )
-{
- struct gl_buffer_object *obj;
-
- (void) ctx;
-
- obj = MALLOC_STRUCT(gl_buffer_object);
- _mesa_initialize_buffer_object(obj, name, target);
- return obj;
-}
-
-
-/**
- * Delete a buffer object.
- *
- * Default callback for the \c dd_function_table::DeleteBuffer() hook.
- */
-static void
-_mesa_delete_buffer_object( struct gl_context *ctx, struct gl_buffer_object *bufObj )
-{
- (void) ctx;
-
- if (bufObj->Data)
- free(bufObj->Data);
-
- /* assign strange values here to help w/ debugging */
- bufObj->RefCount = -1000;
- bufObj->Name = ~0;
-
- _glthread_DESTROY_MUTEX(bufObj->Mutex);
- free(bufObj);
-}
-
-
-
-/**
- * Set ptr to bufObj w/ reference counting.
- */
-void
-_mesa_reference_buffer_object(struct gl_context *ctx,
- struct gl_buffer_object **ptr,
- struct gl_buffer_object *bufObj)
-{
- if (*ptr == bufObj)
- return;
-
- if (*ptr) {
- /* Unreference the old buffer */
- GLboolean deleteFlag = GL_FALSE;
- struct gl_buffer_object *oldObj = *ptr;
-
- _glthread_LOCK_MUTEX(oldObj->Mutex);
- ASSERT(oldObj->RefCount > 0);
- oldObj->RefCount--;
-#if 0
- printf("BufferObj %p %d DECR to %d\n",
- (void *) oldObj, oldObj->Name, oldObj->RefCount);
-#endif
- deleteFlag = (oldObj->RefCount == 0);
- _glthread_UNLOCK_MUTEX(oldObj->Mutex);
-
- if (deleteFlag) {
-
- /* some sanity checking: don't delete a buffer still in use */
-#if 0
- /* unfortunately, these tests are invalid during context tear-down */
- ASSERT(ctx->Array.ArrayBufferObj != bufObj);
- ASSERT(ctx->Array.ElementArrayBufferObj != bufObj);
- ASSERT(ctx->Array.ArrayObj->Vertex.BufferObj != bufObj);
-#endif
-
- ASSERT(ctx->Driver.DeleteBuffer);
- ctx->Driver.DeleteBuffer(ctx, oldObj);
- }
-
- *ptr = NULL;
- }
- ASSERT(!*ptr);
-
- if (bufObj) {
- /* reference new buffer */
- _glthread_LOCK_MUTEX(bufObj->Mutex);
- if (bufObj->RefCount == 0) {
- /* this buffer's being deleted (look just above) */
- /* Not sure this can every really happen. Warn if it does. */
- _mesa_problem(NULL, "referencing deleted buffer object");
- *ptr = NULL;
- }
- else {
- bufObj->RefCount++;
-#if 0
- printf("BufferObj %p %d INCR to %d\n",
- (void *) bufObj, bufObj->Name, bufObj->RefCount);
-#endif
- *ptr = bufObj;
- }
- _glthread_UNLOCK_MUTEX(bufObj->Mutex);
- }
-}
-
-
-/**
- * Initialize a buffer object to default values.
- */
-void
-_mesa_initialize_buffer_object( struct gl_buffer_object *obj,
- GLuint name, GLenum target )
-{
- (void) target;
-
- memset(obj, 0, sizeof(struct gl_buffer_object));
- _glthread_INIT_MUTEX(obj->Mutex);
- obj->RefCount = 1;
- obj->Name = name;
- obj->Usage = GL_STATIC_DRAW_ARB;
- obj->AccessFlags = DEFAULT_ACCESS;
-}
-
-
-/**
- * Allocate space for and store data in a buffer object. Any data that was
- * previously stored in the buffer object is lost. If \c data is \c NULL,
- * memory will be allocated, but no copy will occur.
- *
- * This is the default callback for \c dd_function_table::BufferData()
- * Note that all GL error checking will have been done already.
- *
- * \param ctx GL context.
- * \param target Buffer object target on which to operate.
- * \param size Size, in bytes, of the new data store.
- * \param data Pointer to the data to store in the buffer object. This
- * pointer may be \c NULL.
- * \param usage Hints about how the data will be used.
- * \param bufObj Object to be used.
- *
- * \return GL_TRUE for success, GL_FALSE for failure
- * \sa glBufferDataARB, dd_function_table::BufferData.
- */
-static GLboolean
-_mesa_buffer_data( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
- const GLvoid * data, GLenum usage,
- struct gl_buffer_object * bufObj )
-{
- void * new_data;
-
- (void) ctx; (void) target;
-
- new_data = _mesa_realloc( bufObj->Data, bufObj->Size, size );
- if (new_data) {
- bufObj->Data = (GLubyte *) new_data;
- bufObj->Size = size;
- bufObj->Usage = usage;
-
- if (data) {
- memcpy( bufObj->Data, data, size );
- }
-
- return GL_TRUE;
- }
- else {
- return GL_FALSE;
- }
-}
-
-
-/**
- * Replace data in a subrange of buffer object. If the data range
- * specified by \c size + \c offset extends beyond the end of the buffer or
- * if \c data is \c NULL, no copy is performed.
- *
- * This is the default callback for \c dd_function_table::BufferSubData()
- * Note that all GL error checking will have been done already.
- *
- * \param ctx GL context.
- * \param target Buffer object target on which to operate.
- * \param offset Offset of the first byte to be modified.
- * \param size Size, in bytes, of the data range.
- * \param data Pointer to the data to store in the buffer object.
- * \param bufObj Object to be used.
- *
- * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
- */
-static void
-_mesa_buffer_subdata( struct gl_context *ctx, GLenum target, GLintptrARB offset,
- GLsizeiptrARB size, const GLvoid * data,
- struct gl_buffer_object * bufObj )
-{
- (void) ctx; (void) target;
-
- /* this should have been caught in _mesa_BufferSubData() */
- ASSERT(size + offset <= bufObj->Size);
-
- if (bufObj->Data) {
- memcpy( (GLubyte *) bufObj->Data + offset, data, size );
- }
-}
-
-
-/**
- * Retrieve data from a subrange of buffer object. If the data range
- * specified by \c size + \c offset extends beyond the end of the buffer or
- * if \c data is \c NULL, no copy is performed.
- *
- * This is the default callback for \c dd_function_table::GetBufferSubData()
- * Note that all GL error checking will have been done already.
- *
- * \param ctx GL context.
- * \param target Buffer object target on which to operate.
- * \param offset Offset of the first byte to be fetched.
- * \param size Size, in bytes, of the data range.
- * \param data Destination for data
- * \param bufObj Object to be used.
- *
- * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
- */
-static void
-_mesa_buffer_get_subdata( struct gl_context *ctx, GLenum target, GLintptrARB offset,
- GLsizeiptrARB size, GLvoid * data,
- struct gl_buffer_object * bufObj )
-{
- (void) ctx; (void) target;
-
- if (bufObj->Data && ((GLsizeiptrARB) (size + offset) <= bufObj->Size)) {
- memcpy( data, (GLubyte *) bufObj->Data + offset, size );
- }
-}
-
-
-/**
- * Default callback for \c dd_function_tabel::MapBuffer().
- *
- * The function parameters will have been already tested for errors.
- *
- * \param ctx GL context.
- * \param target Buffer object target on which to operate.
- * \param access Information about how the buffer will be accessed.
- * \param bufObj Object to be mapped.
- * \return A pointer to the object's internal data store that can be accessed
- * by the processor
- *
- * \sa glMapBufferARB, dd_function_table::MapBuffer
- */
-static void *
-_mesa_buffer_map( struct gl_context *ctx, GLenum target, GLenum access,
- struct gl_buffer_object *bufObj )
-{
- (void) ctx;
- (void) target;
- (void) access;
- /* Just return a direct pointer to the data */
- if (_mesa_bufferobj_mapped(bufObj)) {
- /* already mapped! */
- return NULL;
- }
- bufObj->Pointer = bufObj->Data;
- bufObj->Length = bufObj->Size;
- bufObj->Offset = 0;
- return bufObj->Pointer;
-}
-
-
-/**
- * Default fallback for \c dd_function_table::MapBufferRange().
- * Called via glMapBufferRange().
- */
-static void *
-_mesa_buffer_map_range( struct gl_context *ctx, GLenum target, GLintptr offset,
- GLsizeiptr length, GLbitfield access,
- struct gl_buffer_object *bufObj )
-{
- (void) ctx;
- (void) target;
- assert(!_mesa_bufferobj_mapped(bufObj));
- /* Just return a direct pointer to the data */
- bufObj->Pointer = bufObj->Data + offset;
- bufObj->Length = length;
- bufObj->Offset = offset;
- bufObj->AccessFlags = access;
- return bufObj->Pointer;
-}
-
-
-/**
- * Default fallback for \c dd_function_table::FlushMappedBufferRange().
- * Called via glFlushMappedBufferRange().
- */
-static void
-_mesa_buffer_flush_mapped_range( struct gl_context *ctx, GLenum target,
- GLintptr offset, GLsizeiptr length,
- struct gl_buffer_object *obj )
-{
- (void) ctx;
- (void) target;
- (void) offset;
- (void) length;
- (void) obj;
- /* no-op */
-}
-
-
-/**
- * Default callback for \c dd_function_table::MapBuffer().
- *
- * The input parameters will have been already tested for errors.
- *
- * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
- */
-static GLboolean
-_mesa_buffer_unmap( struct gl_context *ctx, GLenum target,
- struct gl_buffer_object *bufObj )
-{
- (void) ctx;
- (void) target;
- /* XXX we might assert here that bufObj->Pointer is non-null */
- bufObj->Pointer = NULL;
- bufObj->Length = 0;
- bufObj->Offset = 0;
- bufObj->AccessFlags = 0x0;
- return GL_TRUE;
-}
-
-
-/**
- * Default fallback for \c dd_function_table::CopyBufferSubData().
- * Called via glCopyBuffserSubData().
- */
-static void
-_mesa_copy_buffer_subdata(struct gl_context *ctx,
- struct gl_buffer_object *src,
- struct gl_buffer_object *dst,
- GLintptr readOffset, GLintptr writeOffset,
- GLsizeiptr size)
-{
- GLubyte *srcPtr, *dstPtr;
-
- /* buffer should not already be mapped */
- assert(!_mesa_bufferobj_mapped(src));
- assert(!_mesa_bufferobj_mapped(dst));
-
- srcPtr = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_COPY_READ_BUFFER,
- GL_READ_ONLY, src);
- dstPtr = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_COPY_WRITE_BUFFER,
- GL_WRITE_ONLY, dst);
-
- if (srcPtr && dstPtr)
- memcpy(dstPtr + writeOffset, srcPtr + readOffset, size);
-
- ctx->Driver.UnmapBuffer(ctx, GL_COPY_READ_BUFFER, src);
- ctx->Driver.UnmapBuffer(ctx, GL_COPY_WRITE_BUFFER, dst);
-}
-
-
-
-/**
- * Initialize the state associated with buffer objects
- */
-void
-_mesa_init_buffer_objects( struct gl_context *ctx )
-{
- memset(&DummyBufferObject, 0, sizeof(DummyBufferObject));
- DummyBufferObject.RefCount = 1000*1000*1000; /* never delete */
-
- _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj,
- ctx->Shared->NullBufferObj);
- _mesa_reference_buffer_object(ctx, &ctx->Array.ElementArrayBufferObj,
- ctx->Shared->NullBufferObj);
-
- _mesa_reference_buffer_object(ctx, &ctx->CopyReadBuffer,
- ctx->Shared->NullBufferObj);
- _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer,
- ctx->Shared->NullBufferObj);
-}
-
-
-void
-_mesa_free_buffer_objects( struct gl_context *ctx )
-{
- _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, NULL);
- _mesa_reference_buffer_object(ctx, &ctx->Array.ElementArrayBufferObj, NULL);
-
- _mesa_reference_buffer_object(ctx, &ctx->CopyReadBuffer, NULL);
- _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer, NULL);
-}
-
-
-/**
- * Bind the specified target to buffer for the specified context.
- * Called by glBindBuffer() and other functions.
- */
-static void
-bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer)
-{
- struct gl_buffer_object *oldBufObj;
- struct gl_buffer_object *newBufObj = NULL;
- struct gl_buffer_object **bindTarget = NULL;
-
- bindTarget = get_buffer_target(ctx, target);
- if (!bindTarget) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target 0x%x)", target);
- return;
- }
-
- /* Get pointer to old buffer object (to be unbound) */
- oldBufObj = *bindTarget;
- if (oldBufObj && oldBufObj->Name == buffer)
- return; /* rebinding the same buffer object- no change */
-
- /*
- * Get pointer to new buffer object (newBufObj)
- */
- if (buffer == 0) {
- /* The spec says there's not a buffer object named 0, but we use
- * one internally because it simplifies things.
- */
- newBufObj = ctx->Shared->NullBufferObj;
- }
- else {
- /* non-default buffer object */
- newBufObj = _mesa_lookup_bufferobj(ctx, buffer);
- if (!newBufObj || newBufObj == &DummyBufferObject) {
- /* If this is a new buffer object id, or one which was generated but
- * never used before, allocate a buffer object now.
- */
- ASSERT(ctx->Driver.NewBufferObject);
- newBufObj = ctx->Driver.NewBufferObject(ctx, buffer, target);
- if (!newBufObj) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindBufferARB");
- return;
- }
- _mesa_HashInsert(ctx->Shared->BufferObjects, buffer, newBufObj);
- }
- }
-
- /* bind new buffer */
- _mesa_reference_buffer_object(ctx, bindTarget, newBufObj);
-
- /* Pass BindBuffer call to device driver */
- if (ctx->Driver.BindBuffer)
- ctx->Driver.BindBuffer( ctx, target, newBufObj );
-}
-
-
-/**
- * Update the default buffer objects in the given context to reference those
- * specified in the shared state and release those referencing the old
- * shared state.
- */
-void
-_mesa_update_default_objects_buffer_objects(struct gl_context *ctx)
-{
- /* Bind the NullBufferObj to remove references to those
- * in the shared context hash table.
- */
- bind_buffer_object( ctx, GL_ARRAY_BUFFER_ARB, 0);
- bind_buffer_object( ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
- bind_buffer_object( ctx, GL_PIXEL_PACK_BUFFER_ARB, 0);
- bind_buffer_object( ctx, GL_PIXEL_UNPACK_BUFFER_ARB, 0);
-}
-
-
-
-/**
- * Return the gl_buffer_object for the given ID.
- * Always return NULL for ID 0.
- */
-struct gl_buffer_object *
-_mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer)
-{
- if (buffer == 0)
- return NULL;
- else
- return (struct gl_buffer_object *)
- _mesa_HashLookup(ctx->Shared->BufferObjects, buffer);
-}
-
-
-/**
- * If *ptr points to obj, set ptr = the Null/default buffer object.
- * This is a helper for buffer object deletion.
- * The GL spec says that deleting a buffer object causes it to get
- * unbound from all arrays in the current context.
- */
-static void
-unbind(struct gl_context *ctx,
- struct gl_buffer_object **ptr,
- struct gl_buffer_object *obj)
-{
- if (*ptr == obj) {
- _mesa_reference_buffer_object(ctx, ptr, ctx->Shared->NullBufferObj);
- }
-}
-
-
-/**
- * Plug default/fallback buffer object functions into the device
- * driver hooks.
- */
-void
-_mesa_init_buffer_object_functions(struct dd_function_table *driver)
-{
- /* GL_ARB_vertex/pixel_buffer_object */
- driver->NewBufferObject = _mesa_new_buffer_object;
- driver->DeleteBuffer = _mesa_delete_buffer_object;
- driver->BindBuffer = NULL;
- driver->BufferData = _mesa_buffer_data;
- driver->BufferSubData = _mesa_buffer_subdata;
- driver->GetBufferSubData = _mesa_buffer_get_subdata;
- driver->MapBuffer = _mesa_buffer_map;
- driver->UnmapBuffer = _mesa_buffer_unmap;
-
- /* GL_ARB_map_buffer_range */
- driver->MapBufferRange = _mesa_buffer_map_range;
- driver->FlushMappedBufferRange = _mesa_buffer_flush_mapped_range;
-
- /* GL_ARB_copy_buffer */
- driver->CopyBufferSubData = _mesa_copy_buffer_subdata;
-}
-
-
-
-/**********************************************************************/
-/* API Functions */
-/**********************************************************************/
-
-void GLAPIENTRY
-_mesa_BindBufferARB(GLenum target, GLuint buffer)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glBindBuffer(%s, %u)\n",
- _mesa_lookup_enum_by_nr(target), buffer);
-
- bind_buffer_object(ctx, target, buffer);
-}
-
-
-/**
- * Delete a set of buffer objects.
- *
- * \param n Number of buffer objects to delete.
- * \param ids Array of \c n buffer object IDs.
- */
-void GLAPIENTRY
-_mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLsizei i;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (n < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteBuffersARB(n)");
- return;
- }
-
- _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
-
- for (i = 0; i < n; i++) {
- struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, ids[i]);
- if (bufObj) {
- struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
- GLuint j;
-
- ASSERT(bufObj->Name == ids[i] || bufObj == &DummyBufferObject);
-
- if (_mesa_bufferobj_mapped(bufObj)) {
- /* if mapped, unmap it now */
- ctx->Driver.UnmapBuffer(ctx, 0, bufObj);
- bufObj->AccessFlags = DEFAULT_ACCESS;
- bufObj->Pointer = NULL;
- }
-
- /* unbind any vertex pointers bound to this buffer */
- unbind(ctx, &arrayObj->Vertex.BufferObj, bufObj);
- unbind(ctx, &arrayObj->Weight.BufferObj, bufObj);
- unbind(ctx, &arrayObj->Normal.BufferObj, bufObj);
- unbind(ctx, &arrayObj->Color.BufferObj, bufObj);
- unbind(ctx, &arrayObj->SecondaryColor.BufferObj, bufObj);
- unbind(ctx, &arrayObj->FogCoord.BufferObj, bufObj);
- unbind(ctx, &arrayObj->Index.BufferObj, bufObj);
- unbind(ctx, &arrayObj->EdgeFlag.BufferObj, bufObj);
- for (j = 0; j < Elements(arrayObj->TexCoord); j++) {
- unbind(ctx, &arrayObj->TexCoord[j].BufferObj, bufObj);
- }
- for (j = 0; j < Elements(arrayObj->VertexAttrib); j++) {
- unbind(ctx, &arrayObj->VertexAttrib[j].BufferObj, bufObj);
- }
-
- if (ctx->Array.ArrayBufferObj == bufObj) {
- _mesa_BindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
- }
- if (ctx->Array.ElementArrayBufferObj == bufObj) {
- _mesa_BindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 );
- }
-
- /* unbind any pixel pack/unpack pointers bound to this buffer */
- if (ctx->Pack.BufferObj == bufObj) {
- _mesa_BindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );
- }
- if (ctx->Unpack.BufferObj == bufObj) {
- _mesa_BindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, 0 );
- }
-
- /* The ID is immediately freed for re-use */
- _mesa_HashRemove(ctx->Shared->BufferObjects, ids[i]);
- _mesa_reference_buffer_object(ctx, &bufObj, NULL);
- }
- }
-
- _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
-}
-
-
-/**
- * Generate a set of unique buffer object IDs and store them in \c buffer.
- *
- * \param n Number of IDs to generate.
- * \param buffer Array of \c n locations to store the IDs.
- */
-void GLAPIENTRY
-_mesa_GenBuffersARB(GLsizei n, GLuint *buffer)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint first;
- GLint i;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glGenBuffers(%d)\n", n);
-
- if (n < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGenBuffersARB");
- return;
- }
-
- if (!buffer) {
- return;
- }
-
- /*
- * This must be atomic (generation and allocation of buffer object IDs)
- */
- _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
-
- first = _mesa_HashFindFreeKeyBlock(ctx->Shared->BufferObjects, n);
-
- /* Insert the ID and pointer to dummy buffer object into hash table */
- for (i = 0; i < n; i++) {
- _mesa_HashInsert(ctx->Shared->BufferObjects, first + i,
- &DummyBufferObject);
- buffer[i] = first + i;
- }
-
- _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
-}
-
-
-/**
- * Determine if ID is the name of a buffer object.
- *
- * \param id ID of the potential buffer object.
- * \return \c GL_TRUE if \c id is the name of a buffer object,
- * \c GL_FALSE otherwise.
- */
-GLboolean GLAPIENTRY
-_mesa_IsBufferARB(GLuint id)
-{
- struct gl_buffer_object *bufObj;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
-
- _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
- bufObj = _mesa_lookup_bufferobj(ctx, id);
- _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
-
- return bufObj && bufObj != &DummyBufferObject;
-}
-
-
-void GLAPIENTRY
-_mesa_BufferDataARB(GLenum target, GLsizeiptrARB size,
- const GLvoid * data, GLenum usage)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glBufferData(%s, %ld, %p, %s)\n",
- _mesa_lookup_enum_by_nr(target),
- (long int) size, data,
- _mesa_lookup_enum_by_nr(usage));
-
- if (size < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glBufferDataARB(size < 0)");
- return;
- }
-
- switch (usage) {
- case GL_STREAM_DRAW_ARB:
- case GL_STREAM_READ_ARB:
- case GL_STREAM_COPY_ARB:
- case GL_STATIC_DRAW_ARB:
- case GL_STATIC_READ_ARB:
- case GL_STATIC_COPY_ARB:
- case GL_DYNAMIC_DRAW_ARB:
- case GL_DYNAMIC_READ_ARB:
- case GL_DYNAMIC_COPY_ARB:
- /* OK */
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glBufferDataARB(usage)");
- return;
- }
-
- bufObj = get_buffer(ctx, target);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBufferDataARB(target)" );
- return;
- }
- if (!_mesa_is_bufferobj(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glBufferDataARB(buffer 0)" );
- return;
- }
-
- if (_mesa_bufferobj_mapped(bufObj)) {
- /* Unmap the existing buffer. We'll replace it now. Not an error. */
- ctx->Driver.UnmapBuffer(ctx, target, bufObj);
- bufObj->AccessFlags = DEFAULT_ACCESS;
- ASSERT(bufObj->Pointer == NULL);
- }
-
- FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
-
- bufObj->Written = GL_TRUE;
-
-#ifdef VBO_DEBUG
- printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
- bufObj->Name, size, data, usage);
-#endif
-
-#ifdef BOUNDS_CHECK
- size += 100;
-#endif
-
- ASSERT(ctx->Driver.BufferData);
- if (!ctx->Driver.BufferData( ctx, target, size, data, usage, bufObj )) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBufferDataARB()");
- }
-}
-
-
-void GLAPIENTRY
-_mesa_BufferSubDataARB(GLenum target, GLintptrARB offset,
- GLsizeiptrARB size, const GLvoid * data)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,
- "glBufferSubDataARB" );
- if (!bufObj) {
- /* error already recorded */
- return;
- }
-
- if (size == 0)
- return;
-
- bufObj->Written = GL_TRUE;
-
- ASSERT(ctx->Driver.BufferSubData);
- ctx->Driver.BufferSubData( ctx, target, offset, size, data, bufObj );
-}
-
-
-void GLAPIENTRY
-_mesa_GetBufferSubDataARB(GLenum target, GLintptrARB offset,
- GLsizeiptrARB size, void * data)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,
- "glGetBufferSubDataARB" );
- if (!bufObj) {
- /* error already recorded */
- return;
- }
-
- ASSERT(ctx->Driver.GetBufferSubData);
- ctx->Driver.GetBufferSubData( ctx, target, offset, size, data, bufObj );
-}
-
-
-void * GLAPIENTRY
-_mesa_MapBufferARB(GLenum target, GLenum access)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object * bufObj;
- GLbitfield accessFlags;
- void *map;
-
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
-
- switch (access) {
- case GL_READ_ONLY_ARB:
- accessFlags = GL_MAP_READ_BIT;
- break;
- case GL_WRITE_ONLY_ARB:
- accessFlags = GL_MAP_WRITE_BIT;
- break;
- case GL_READ_WRITE_ARB:
- accessFlags = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glMapBufferARB(access)");
- return NULL;
- }
-
- bufObj = get_buffer(ctx, target);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glMapBufferARB(target)" );
- return NULL;
- }
- if (!_mesa_is_bufferobj(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glMapBufferARB(buffer 0)" );
- return NULL;
- }
- if (_mesa_bufferobj_mapped(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glMapBufferARB(already mapped)");
- return NULL;
- }
-
- ASSERT(ctx->Driver.MapBuffer);
- map = ctx->Driver.MapBuffer( ctx, target, access, bufObj );
- if (!map) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMapBufferARB(map failed)");
- return NULL;
- }
- else {
- /* The driver callback should have set these fields.
- * This is important because other modules (like VBO) might call
- * the driver function directly.
- */
- ASSERT(bufObj->Pointer == map);
- ASSERT(bufObj->Length == bufObj->Size);
- ASSERT(bufObj->Offset == 0);
- bufObj->AccessFlags = accessFlags;
- }
-
- if (access == GL_WRITE_ONLY_ARB || access == GL_READ_WRITE_ARB)
- bufObj->Written = GL_TRUE;
-
-#ifdef VBO_DEBUG
- printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
- bufObj->Name, bufObj->Size, access);
- if (access == GL_WRITE_ONLY_ARB) {
- GLuint i;
- GLubyte *b = (GLubyte *) bufObj->Pointer;
- for (i = 0; i < bufObj->Size; i++)
- b[i] = i & 0xff;
- }
-#endif
-
-#ifdef BOUNDS_CHECK
- {
- GLubyte *buf = (GLubyte *) bufObj->Pointer;
- GLuint i;
- /* buffer is 100 bytes larger than requested, fill with magic value */
- for (i = 0; i < 100; i++) {
- buf[bufObj->Size - i - 1] = 123;
- }
- }
-#endif
-
- return bufObj->Pointer;
-}
-
-
-GLboolean GLAPIENTRY
-_mesa_UnmapBufferARB(GLenum target)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
- GLboolean status = GL_TRUE;
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
-
- bufObj = get_buffer(ctx, target);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glUnmapBufferARB(target)" );
- return GL_FALSE;
- }
- if (!_mesa_is_bufferobj(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glUnmapBufferARB" );
- return GL_FALSE;
- }
- if (!_mesa_bufferobj_mapped(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glUnmapBufferARB");
- return GL_FALSE;
- }
-
-#ifdef BOUNDS_CHECK
- if (bufObj->Access != GL_READ_ONLY_ARB) {
- GLubyte *buf = (GLubyte *) bufObj->Pointer;
- GLuint i;
- /* check that last 100 bytes are still = magic value */
- for (i = 0; i < 100; i++) {
- GLuint pos = bufObj->Size - i - 1;
- if (buf[pos] != 123) {
- _mesa_warning(ctx, "Out of bounds buffer object write detected"
- " at position %d (value = %u)\n",
- pos, buf[pos]);
- }
- }
- }
-#endif
-
-#ifdef VBO_DEBUG
- if (bufObj->AccessFlags & GL_MAP_WRITE_BIT) {
- GLuint i, unchanged = 0;
- GLubyte *b = (GLubyte *) bufObj->Pointer;
- GLint pos = -1;
- /* check which bytes changed */
- for (i = 0; i < bufObj->Size - 1; i++) {
- if (b[i] == (i & 0xff) && b[i+1] == ((i+1) & 0xff)) {
- unchanged++;
- if (pos == -1)
- pos = i;
- }
- }
- if (unchanged) {
- printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
- bufObj->Name, unchanged, bufObj->Size, pos);
- }
- }
-#endif
-
- status = ctx->Driver.UnmapBuffer( ctx, target, bufObj );
- bufObj->AccessFlags = DEFAULT_ACCESS;
- ASSERT(bufObj->Pointer == NULL);
- ASSERT(bufObj->Offset == 0);
- ASSERT(bufObj->Length == 0);
-
- return status;
-}
-
-
-void GLAPIENTRY
-_mesa_GetBufferParameterivARB(GLenum target, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- bufObj = get_buffer(ctx, target);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameterivARB(target)" );
- return;
- }
- if (!_mesa_is_bufferobj(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferParameterivARB" );
- return;
- }
-
- switch (pname) {
- case GL_BUFFER_SIZE_ARB:
- *params = (GLint) bufObj->Size;
- return;
- case GL_BUFFER_USAGE_ARB:
- *params = bufObj->Usage;
- return;
- case GL_BUFFER_ACCESS_ARB:
- *params = simplified_access_mode(bufObj->AccessFlags);
- return;
- case GL_BUFFER_MAPPED_ARB:
- *params = _mesa_bufferobj_mapped(bufObj);
- return;
- case GL_BUFFER_ACCESS_FLAGS:
- if (ctx->VersionMajor < 3)
- goto invalid_pname;
- *params = bufObj->AccessFlags;
- return;
- case GL_BUFFER_MAP_OFFSET:
- if (ctx->VersionMajor < 3)
- goto invalid_pname;
- *params = (GLint) bufObj->Offset;
- return;
- case GL_BUFFER_MAP_LENGTH:
- if (ctx->VersionMajor < 3)
- goto invalid_pname;
- *params = (GLint) bufObj->Length;
- return;
- default:
- ; /* fall-through */
- }
-
-invalid_pname:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameterivARB(pname=%s)",
- _mesa_lookup_enum_by_nr(pname));
-}
-
-
-/**
- * New in GL 3.2
- * This is pretty much a duplicate of GetBufferParameteriv() but the
- * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
- */
-void GLAPIENTRY
-_mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- bufObj = get_buffer(ctx, target);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameteri64v(target)" );
- return;
- }
- if (!_mesa_is_bufferobj(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferParameteri64v" );
- return;
- }
-
- switch (pname) {
- case GL_BUFFER_SIZE_ARB:
- *params = bufObj->Size;
- return;
- case GL_BUFFER_USAGE_ARB:
- *params = bufObj->Usage;
- return;
- case GL_BUFFER_ACCESS_ARB:
- *params = simplified_access_mode(bufObj->AccessFlags);
- return;
- case GL_BUFFER_ACCESS_FLAGS:
- if (ctx->VersionMajor < 3)
- goto invalid_pname;
- *params = bufObj->AccessFlags;
- return;
- case GL_BUFFER_MAPPED_ARB:
- *params = _mesa_bufferobj_mapped(bufObj);
- return;
- case GL_BUFFER_MAP_OFFSET:
- if (ctx->VersionMajor < 3)
- goto invalid_pname;
- *params = bufObj->Offset;
- return;
- case GL_BUFFER_MAP_LENGTH:
- if (ctx->VersionMajor < 3)
- goto invalid_pname;
- *params = bufObj->Length;
- return;
- default:
- ; /* fall-through */
- }
-
-invalid_pname:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameteri64v(pname=%s)",
- _mesa_lookup_enum_by_nr(pname));
-}
-
-
-void GLAPIENTRY
-_mesa_GetBufferPointervARB(GLenum target, GLenum pname, GLvoid **params)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object * bufObj;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (pname != GL_BUFFER_MAP_POINTER_ARB) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferPointervARB(pname)");
- return;
- }
-
- bufObj = get_buffer(ctx, target);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferPointervARB(target)" );
- return;
- }
- if (!_mesa_is_bufferobj(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferPointervARB" );
- return;
- }
-
- *params = bufObj->Pointer;
-}
-
-
-void GLAPIENTRY
-_mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
- GLintptr readOffset, GLintptr writeOffset,
- GLsizeiptr size)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *src, *dst;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- src = get_buffer(ctx, readTarget);
- if (!src || !_mesa_is_bufferobj(src)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glCopyBuffserSubData(readTarget = 0x%x)", readTarget);
- return;
- }
-
- dst = get_buffer(ctx, writeTarget);
- if (!dst || !_mesa_is_bufferobj(dst)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glCopyBuffserSubData(writeTarget = 0x%x)", writeTarget);
- return;
- }
-
- if (_mesa_bufferobj_mapped(src)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyBuffserSubData(readBuffer is mapped)");
- return;
- }
-
- if (_mesa_bufferobj_mapped(dst)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyBuffserSubData(writeBuffer is mapped)");
- return;
- }
-
- if (readOffset < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyBuffserSubData(readOffset = %d)", (int) readOffset);
- return;
- }
-
- if (writeOffset < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyBuffserSubData(writeOffset = %d)", (int) writeOffset);
- return;
- }
-
- if (readOffset + size > src->Size) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyBuffserSubData(readOffset + size = %d)",
- (int) (readOffset + size));
- return;
- }
-
- if (writeOffset + size > dst->Size) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyBuffserSubData(writeOffset + size = %d)",
- (int) (writeOffset + size));
- return;
- }
-
- if (src == dst) {
- if (readOffset + size <= writeOffset) {
- /* OK */
- }
- else if (writeOffset + size <= readOffset) {
- /* OK */
- }
- else {
- /* overlapping src/dst is illegal */
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyBuffserSubData(overlapping src/dst)");
- return;
- }
- }
-
- ctx->Driver.CopyBufferSubData(ctx, src, dst, readOffset, writeOffset, size);
-}
-
-
-/**
- * See GL_ARB_map_buffer_range spec
- */
-void * GLAPIENTRY
-_mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
- GLbitfield access)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
- void *map;
-
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
-
- if (!ctx->Extensions.ARB_map_buffer_range) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glMapBufferRange(extension not supported)");
- return NULL;
- }
-
- if (offset < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glMapBufferRange(offset = %ld)", (long)offset);
- return NULL;
- }
-
- if (length < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glMapBufferRange(length = %ld)", (long)length);
- return NULL;
- }
-
- if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glMapBufferRange(access indicates neither read or write)");
- return NULL;
- }
-
- if (access & GL_MAP_READ_BIT) {
- if ((access & GL_MAP_INVALIDATE_RANGE_BIT) ||
- (access & GL_MAP_INVALIDATE_BUFFER_BIT) ||
- (access & GL_MAP_UNSYNCHRONIZED_BIT)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glMapBufferRange(invalid access flags)");
- return NULL;
- }
- }
-
- if ((access & GL_MAP_FLUSH_EXPLICIT_BIT) &&
- ((access & GL_MAP_WRITE_BIT) == 0)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glMapBufferRange(invalid access flags)");
- return NULL;
- }
-
- bufObj = get_buffer(ctx, target);
- if (!bufObj || !_mesa_is_bufferobj(bufObj)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glMapBufferRange(target = 0x%x)", target);
- return NULL;
- }
-
- if (offset + length > bufObj->Size) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glMapBufferRange(offset + length > size)");
- return NULL;
- }
-
- if (_mesa_bufferobj_mapped(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glMapBufferRange(buffer already mapped)");
- return NULL;
- }
-
- ASSERT(ctx->Driver.MapBufferRange);
- map = ctx->Driver.MapBufferRange(ctx, target, offset, length,
- access, bufObj);
- if (!map) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMapBufferARB(map failed)");
- }
- else {
- /* The driver callback should have set all these fields.
- * This is important because other modules (like VBO) might call
- * the driver function directly.
- */
- ASSERT(bufObj->Pointer == map);
- ASSERT(bufObj->Length == length);
- ASSERT(bufObj->Offset == offset);
- ASSERT(bufObj->AccessFlags == access);
- }
-
- return map;
-}
-
-
-/**
- * See GL_ARB_map_buffer_range spec
- */
-void GLAPIENTRY
-_mesa_FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (!ctx->Extensions.ARB_map_buffer_range) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glMapBufferRange(extension not supported)");
- return;
- }
-
- if (offset < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glMapBufferRange(offset = %ld)", (long)offset);
- return;
- }
-
- if (length < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glMapBufferRange(length = %ld)", (long)length);
- return;
- }
-
- bufObj = get_buffer(ctx, target);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glMapBufferRange(target = 0x%x)", target);
- return;
- }
-
- if (!_mesa_is_bufferobj(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glMapBufferRange(current buffer is 0)");
- return;
- }
-
- if (!_mesa_bufferobj_mapped(bufObj)) {
- /* buffer is not mapped */
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glMapBufferRange(buffer is not mapped)");
- return;
- }
-
- if ((bufObj->AccessFlags & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glMapBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
- return;
- }
-
- if (offset + length > bufObj->Length) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glMapBufferRange(offset %ld + length %ld > mapped length %ld)",
- (long)offset, (long)length, (long)bufObj->Length);
- return;
- }
-
- ASSERT(bufObj->AccessFlags & GL_MAP_WRITE_BIT);
-
- if (ctx->Driver.FlushMappedBufferRange)
- ctx->Driver.FlushMappedBufferRange(ctx, target, offset, length, bufObj);
-}
-
-
-#if FEATURE_APPLE_object_purgeable
-static GLenum
-_mesa_BufferObjectPurgeable(struct gl_context *ctx, GLuint name, GLenum option)
-{
- struct gl_buffer_object *bufObj;
- GLenum retval;
-
- bufObj = _mesa_lookup_bufferobj(ctx, name);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glObjectPurgeable(name = 0x%x)", name);
- return 0;
- }
- if (!_mesa_is_bufferobj(bufObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glObjectPurgeable(buffer 0)" );
- return 0;
- }
-
- if (bufObj->Purgeable) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glObjectPurgeable(name = 0x%x) is already purgeable", name);
- return GL_VOLATILE_APPLE;
- }
-
- bufObj->Purgeable = GL_TRUE;
-
- retval = GL_VOLATILE_APPLE;
- if (ctx->Driver.BufferObjectPurgeable)
- retval = ctx->Driver.BufferObjectPurgeable(ctx, bufObj, option);
-
- return retval;
-}
-
-
-static GLenum
-_mesa_RenderObjectPurgeable(struct gl_context *ctx, GLuint name, GLenum option)
-{
- struct gl_renderbuffer *bufObj;
- GLenum retval;
-
- bufObj = _mesa_lookup_renderbuffer(ctx, name);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glObjectUnpurgeable(name = 0x%x)", name);
- return 0;
- }
-
- if (bufObj->Purgeable) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glObjectPurgeable(name = 0x%x) is already purgeable", name);
- return GL_VOLATILE_APPLE;
- }
-
- bufObj->Purgeable = GL_TRUE;
-
- retval = GL_VOLATILE_APPLE;
- if (ctx->Driver.RenderObjectPurgeable)
- retval = ctx->Driver.RenderObjectPurgeable(ctx, bufObj, option);
-
- return retval;
-}
-
-
-static GLenum
-_mesa_TextureObjectPurgeable(struct gl_context *ctx, GLuint name, GLenum option)
-{
- struct gl_texture_object *bufObj;
- GLenum retval;
-
- bufObj = _mesa_lookup_texture(ctx, name);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glObjectPurgeable(name = 0x%x)", name);
- return 0;
- }
-
- if (bufObj->Purgeable) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glObjectPurgeable(name = 0x%x) is already purgeable", name);
- return GL_VOLATILE_APPLE;
- }
-
- bufObj->Purgeable = GL_TRUE;
-
- retval = GL_VOLATILE_APPLE;
- if (ctx->Driver.TextureObjectPurgeable)
- retval = ctx->Driver.TextureObjectPurgeable(ctx, bufObj, option);
-
- return retval;
-}
-
-
-GLenum GLAPIENTRY
-_mesa_ObjectPurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
-{
- GLenum retval;
-
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
-
- if (name == 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glObjectPurgeable(name = 0x%x)", name);
- return 0;
- }
-
- switch (option) {
- case GL_VOLATILE_APPLE:
- case GL_RELEASED_APPLE:
- /* legal */
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glObjectPurgeable(name = 0x%x) invalid option: %d",
- name, option);
- return 0;
- }
-
- switch (objectType) {
- case GL_TEXTURE:
- retval = _mesa_TextureObjectPurgeable (ctx, name, option);
- break;
- case GL_RENDERBUFFER_EXT:
- retval = _mesa_RenderObjectPurgeable (ctx, name, option);
- break;
- case GL_BUFFER_OBJECT_APPLE:
- retval = _mesa_BufferObjectPurgeable (ctx, name, option);
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glObjectPurgeable(name = 0x%x) invalid type: %d",
- name, objectType);
- return 0;
- }
-
- /* In strict conformance to the spec, we must only return VOLATILE when
- * when passed the VOLATILE option. Madness.
- *
- * XXX First fix the spec, then fix me.
- */
- return option == GL_VOLATILE_APPLE ? GL_VOLATILE_APPLE : retval;
-}
-
-
-static GLenum
-_mesa_BufferObjectUnpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
-{
- struct gl_buffer_object *bufObj;
- GLenum retval;
-
- bufObj = _mesa_lookup_bufferobj(ctx, name);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glObjectUnpurgeable(name = 0x%x)", name);
- return 0;
- }
-
- if (! bufObj->Purgeable) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glObjectUnpurgeable(name = 0x%x) object is "
- " already \"unpurged\"", name);
- return 0;
- }
-
- bufObj->Purgeable = GL_FALSE;
-
- retval = option;
- if (ctx->Driver.BufferObjectUnpurgeable)
- retval = ctx->Driver.BufferObjectUnpurgeable(ctx, bufObj, option);
-
- return retval;
-}
-
-
-static GLenum
-_mesa_RenderObjectUnpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
-{
- struct gl_renderbuffer *bufObj;
- GLenum retval;
-
- bufObj = _mesa_lookup_renderbuffer(ctx, name);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glObjectUnpurgeable(name = 0x%x)", name);
- return 0;
- }
-
- if (! bufObj->Purgeable) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glObjectUnpurgeable(name = 0x%x) object is "
- " already \"unpurged\"", name);
- return 0;
- }
-
- bufObj->Purgeable = GL_FALSE;
-
- retval = option;
- if (ctx->Driver.RenderObjectUnpurgeable)
- retval = ctx->Driver.RenderObjectUnpurgeable(ctx, bufObj, option);
-
- return retval;
-}
-
-
-static GLenum
-_mesa_TextureObjectUnpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
-{
- struct gl_texture_object *bufObj;
- GLenum retval;
-
- bufObj = _mesa_lookup_texture(ctx, name);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glObjectUnpurgeable(name = 0x%x)", name);
- return 0;
- }
-
- if (! bufObj->Purgeable) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glObjectUnpurgeable(name = 0x%x) object is"
- " already \"unpurged\"", name);
- return 0;
- }
-
- bufObj->Purgeable = GL_FALSE;
-
- retval = option;
- if (ctx->Driver.TextureObjectUnpurgeable)
- retval = ctx->Driver.TextureObjectUnpurgeable(ctx, bufObj, option);
-
- return retval;
-}
-
-
-GLenum GLAPIENTRY
-_mesa_ObjectUnpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
-
- if (name == 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glObjectUnpurgeable(name = 0x%x)", name);
- return 0;
- }
-
- switch (option) {
- case GL_RETAINED_APPLE:
- case GL_UNDEFINED_APPLE:
- /* legal */
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
- name, option);
- return 0;
- }
-
- switch (objectType) {
- case GL_BUFFER_OBJECT_APPLE:
- return _mesa_BufferObjectUnpurgeable(ctx, name, option);
- case GL_TEXTURE:
- return _mesa_TextureObjectUnpurgeable(ctx, name, option);
- case GL_RENDERBUFFER_EXT:
- return _mesa_RenderObjectUnpurgeable(ctx, name, option);
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
- name, objectType);
- return 0;
- }
-}
-
-
-static void
-_mesa_GetBufferObjectParameterivAPPLE(struct gl_context *ctx, GLuint name,
- GLenum pname, GLint* params)
-{
- struct gl_buffer_object *bufObj;
-
- bufObj = _mesa_lookup_bufferobj(ctx, name);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glGetObjectParameteriv(name = 0x%x) invalid object", name);
- return;
- }
-
- switch (pname) {
- case GL_PURGEABLE_APPLE:
- *params = bufObj->Purgeable;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
- name, pname);
- break;
- }
-}
-
-
-static void
-_mesa_GetRenderObjectParameterivAPPLE(struct gl_context *ctx, GLuint name,
- GLenum pname, GLint* params)
-{
- struct gl_renderbuffer *bufObj;
-
- bufObj = _mesa_lookup_renderbuffer(ctx, name);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glObjectUnpurgeable(name = 0x%x)", name);
- return;
- }
-
- switch (pname) {
- case GL_PURGEABLE_APPLE:
- *params = bufObj->Purgeable;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
- name, pname);
- break;
- }
-}
-
-
-static void
-_mesa_GetTextureObjectParameterivAPPLE(struct gl_context *ctx, GLuint name,
- GLenum pname, GLint* params)
-{
- struct gl_texture_object *bufObj;
-
- bufObj = _mesa_lookup_texture(ctx, name);
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glObjectUnpurgeable(name = 0x%x)", name);
- return;
- }
-
- switch (pname) {
- case GL_PURGEABLE_APPLE:
- *params = bufObj->Purgeable;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
- name, pname);
- break;
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum pname,
- GLint* params)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if (name == 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glGetObjectParameteriv(name = 0x%x)", name);
- return;
- }
-
- switch (objectType) {
- case GL_TEXTURE:
- _mesa_GetTextureObjectParameterivAPPLE (ctx, name, pname, params);
- break;
- case GL_BUFFER_OBJECT_APPLE:
- _mesa_GetBufferObjectParameterivAPPLE (ctx, name, pname, params);
- break;
- case GL_RENDERBUFFER_EXT:
- _mesa_GetRenderObjectParameterivAPPLE (ctx, name, pname, params);
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
- name, objectType);
- }
-}
-
-#endif /* FEATURE_APPLE_object_purgeable */
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.6
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file bufferobj.c
+ * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
+ * \author Brian Paul, Ian Romanick
+ */
+
+
+#include "glheader.h"
+#include "enums.h"
+#include "hash.h"
+#include "imports.h"
+#include "image.h"
+#include "context.h"
+#include "bufferobj.h"
+#include "fbobject.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "texobj.h"
+
+
+/* Debug flags */
+/*#define VBO_DEBUG*/
+/*#define BOUNDS_CHECK*/
+
+
+#if FEATURE_OES_mapbuffer
+#define DEFAULT_ACCESS GL_MAP_WRITE_BIT
+#else
+#define DEFAULT_ACCESS (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)
+#endif
+
+
+/**
+ * Used as a placeholder for buffer objects between glGenBuffers() and
+ * glBindBuffer() so that glIsBuffer() can work correctly.
+ */
+static struct gl_buffer_object DummyBufferObject;
+
+
+/**
+ * Return pointer to address of a buffer object target.
+ * \param ctx the GL context
+ * \param target the buffer object target to be retrieved.
+ * \return pointer to pointer to the buffer object bound to \c target in the
+ * specified context or \c NULL if \c target is invalid.
+ */
+static INLINE struct gl_buffer_object **
+get_buffer_target(struct gl_context *ctx, GLenum target)
+{
+ switch (target) {
+ case GL_ARRAY_BUFFER_ARB:
+ return &ctx->Array.ArrayBufferObj;
+ case GL_ELEMENT_ARRAY_BUFFER_ARB:
+ return &ctx->Array.ElementArrayBufferObj;
+ case GL_PIXEL_PACK_BUFFER_EXT:
+ return &ctx->Pack.BufferObj;
+ case GL_PIXEL_UNPACK_BUFFER_EXT:
+ return &ctx->Unpack.BufferObj;
+ case GL_COPY_READ_BUFFER:
+ return &ctx->CopyReadBuffer;
+ case GL_COPY_WRITE_BUFFER:
+ return &ctx->CopyWriteBuffer;
+#if FEATURE_EXT_transform_feedback
+ case GL_TRANSFORM_FEEDBACK_BUFFER:
+ if (ctx->Extensions.EXT_transform_feedback) {
+ return &ctx->TransformFeedback.CurrentBuffer;
+ }
+ break;
+#endif
+ default:
+ return NULL;
+ }
+ return NULL;
+}
+
+
+/**
+ * Get the buffer object bound to the specified target in a GL context.
+ * \param ctx the GL context
+ * \param target the buffer object target to be retrieved.
+ * \return pointer to the buffer object bound to \c target in the
+ * specified context or \c NULL if \c target is invalid.
+ */
+static INLINE struct gl_buffer_object *
+get_buffer(struct gl_context *ctx, GLenum target)
+{
+ struct gl_buffer_object **bufObj = get_buffer_target(ctx, target);
+ if (bufObj)
+ return *bufObj;
+ return NULL;
+}
+
+
+/**
+ * Convert a GLbitfield describing the mapped buffer access flags
+ * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
+ */
+static GLenum
+simplified_access_mode(GLbitfield access)
+{
+ const GLbitfield rwFlags = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
+ if ((access & rwFlags) == rwFlags)
+ return GL_READ_WRITE;
+ if ((access & GL_MAP_READ_BIT) == GL_MAP_READ_BIT)
+ return GL_READ_ONLY;
+ if ((access & GL_MAP_WRITE_BIT) == GL_MAP_WRITE_BIT)
+ return GL_WRITE_ONLY;
+ return GL_READ_WRITE; /* this should never happen, but no big deal */
+}
+
+
+/**
+ * Tests the subdata range parameters and sets the GL error code for
+ * \c glBufferSubDataARB and \c glGetBufferSubDataARB.
+ *
+ * \param ctx GL context.
+ * \param target Buffer object target on which to operate.
+ * \param offset Offset of the first byte of the subdata range.
+ * \param size Size, in bytes, of the subdata range.
+ * \param caller Name of calling function for recording errors.
+ * \return A pointer to the buffer object bound to \c target in the
+ * specified context or \c NULL if any of the parameter or state
+ * conditions for \c glBufferSubDataARB or \c glGetBufferSubDataARB
+ * are invalid.
+ *
+ * \sa glBufferSubDataARB, glGetBufferSubDataARB
+ */
+static struct gl_buffer_object *
+buffer_object_subdata_range_good( struct gl_context * ctx, GLenum target,
+ GLintptrARB offset, GLsizeiptrARB size,
+ const char *caller )
+{
+ struct gl_buffer_object *bufObj;
+
+ if (size < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(size < 0)", caller);
+ return NULL;
+ }
+
+ if (offset < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset < 0)", caller);
+ return NULL;
+ }
+
+ bufObj = get_buffer(ctx, target);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", caller);
+ return NULL;
+ }
+ if (!_mesa_is_bufferobj(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
+ return NULL;
+ }
+ if (offset + size > bufObj->Size) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(size + offset > buffer size)", caller);
+ return NULL;
+ }
+ if (_mesa_bufferobj_mapped(bufObj)) {
+ /* Buffer is currently mapped */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
+ return NULL;
+ }
+
+ return bufObj;
+}
+
+
+/**
+ * Allocate and initialize a new buffer object.
+ *
+ * Default callback for the \c dd_function_table::NewBufferObject() hook.
+ */
+struct gl_buffer_object *
+_mesa_new_buffer_object( struct gl_context *ctx, GLuint name, GLenum target )
+{
+ struct gl_buffer_object *obj;
+
+ (void) ctx;
+
+ obj = MALLOC_STRUCT(gl_buffer_object);
+ _mesa_initialize_buffer_object(obj, name, target);
+ return obj;
+}
+
+
+/**
+ * Delete a buffer object.
+ *
+ * Default callback for the \c dd_function_table::DeleteBuffer() hook.
+ */
+void
+_mesa_delete_buffer_object( struct gl_context *ctx, struct gl_buffer_object *bufObj )
+{
+ (void) ctx;
+
+ if (bufObj->Data)
+ free(bufObj->Data);
+
+ /* assign strange values here to help w/ debugging */
+ bufObj->RefCount = -1000;
+ bufObj->Name = ~0;
+
+ _glthread_DESTROY_MUTEX(bufObj->Mutex);
+ free(bufObj);
+}
+
+
+
+/**
+ * Set ptr to bufObj w/ reference counting.
+ */
+void
+_mesa_reference_buffer_object(struct gl_context *ctx,
+ struct gl_buffer_object **ptr,
+ struct gl_buffer_object *bufObj)
+{
+ if (*ptr == bufObj)
+ return;
+
+ if (*ptr) {
+ /* Unreference the old buffer */
+ GLboolean deleteFlag = GL_FALSE;
+ struct gl_buffer_object *oldObj = *ptr;
+
+ _glthread_LOCK_MUTEX(oldObj->Mutex);
+ ASSERT(oldObj->RefCount > 0);
+ oldObj->RefCount--;
+#if 0
+ printf("BufferObj %p %d DECR to %d\n",
+ (void *) oldObj, oldObj->Name, oldObj->RefCount);
+#endif
+ deleteFlag = (oldObj->RefCount == 0);
+ _glthread_UNLOCK_MUTEX(oldObj->Mutex);
+
+ if (deleteFlag) {
+
+ /* some sanity checking: don't delete a buffer still in use */
+#if 0
+ /* unfortunately, these tests are invalid during context tear-down */
+ ASSERT(ctx->Array.ArrayBufferObj != bufObj);
+ ASSERT(ctx->Array.ElementArrayBufferObj != bufObj);
+ ASSERT(ctx->Array.ArrayObj->Vertex.BufferObj != bufObj);
+#endif
+
+ ASSERT(ctx->Driver.DeleteBuffer);
+ ctx->Driver.DeleteBuffer(ctx, oldObj);
+ }
+
+ *ptr = NULL;
+ }
+ ASSERT(!*ptr);
+
+ if (bufObj) {
+ /* reference new buffer */
+ _glthread_LOCK_MUTEX(bufObj->Mutex);
+ if (bufObj->RefCount == 0) {
+ /* this buffer's being deleted (look just above) */
+ /* Not sure this can every really happen. Warn if it does. */
+ _mesa_problem(NULL, "referencing deleted buffer object");
+ *ptr = NULL;
+ }
+ else {
+ bufObj->RefCount++;
+#if 0
+ printf("BufferObj %p %d INCR to %d\n",
+ (void *) bufObj, bufObj->Name, bufObj->RefCount);
+#endif
+ *ptr = bufObj;
+ }
+ _glthread_UNLOCK_MUTEX(bufObj->Mutex);
+ }
+}
+
+
+/**
+ * Initialize a buffer object to default values.
+ */
+void
+_mesa_initialize_buffer_object( struct gl_buffer_object *obj,
+ GLuint name, GLenum target )
+{
+ (void) target;
+
+ memset(obj, 0, sizeof(struct gl_buffer_object));
+ _glthread_INIT_MUTEX(obj->Mutex);
+ obj->RefCount = 1;
+ obj->Name = name;
+ obj->Usage = GL_STATIC_DRAW_ARB;
+ obj->AccessFlags = DEFAULT_ACCESS;
+}
+
+
+/**
+ * Allocate space for and store data in a buffer object. Any data that was
+ * previously stored in the buffer object is lost. If \c data is \c NULL,
+ * memory will be allocated, but no copy will occur.
+ *
+ * This is the default callback for \c dd_function_table::BufferData()
+ * Note that all GL error checking will have been done already.
+ *
+ * \param ctx GL context.
+ * \param target Buffer object target on which to operate.
+ * \param size Size, in bytes, of the new data store.
+ * \param data Pointer to the data to store in the buffer object. This
+ * pointer may be \c NULL.
+ * \param usage Hints about how the data will be used.
+ * \param bufObj Object to be used.
+ *
+ * \return GL_TRUE for success, GL_FALSE for failure
+ * \sa glBufferDataARB, dd_function_table::BufferData.
+ */
+GLboolean
+_mesa_buffer_data( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
+ const GLvoid * data, GLenum usage,
+ struct gl_buffer_object * bufObj )
+{
+ void * new_data;
+
+ (void) ctx; (void) target;
+
+ new_data = _mesa_realloc( bufObj->Data, bufObj->Size, size );
+ if (new_data) {
+ bufObj->Data = (GLubyte *) new_data;
+ bufObj->Size = size;
+ bufObj->Usage = usage;
+
+ if (data) {
+ memcpy( bufObj->Data, data, size );
+ }
+
+ return GL_TRUE;
+ }
+ else {
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Replace data in a subrange of buffer object. If the data range
+ * specified by \c size + \c offset extends beyond the end of the buffer or
+ * if \c data is \c NULL, no copy is performed.
+ *
+ * This is the default callback for \c dd_function_table::BufferSubData()
+ * Note that all GL error checking will have been done already.
+ *
+ * \param ctx GL context.
+ * \param target Buffer object target on which to operate.
+ * \param offset Offset of the first byte to be modified.
+ * \param size Size, in bytes, of the data range.
+ * \param data Pointer to the data to store in the buffer object.
+ * \param bufObj Object to be used.
+ *
+ * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
+ */
+void
+_mesa_buffer_subdata( struct gl_context *ctx, GLenum target, GLintptrARB offset,
+ GLsizeiptrARB size, const GLvoid * data,
+ struct gl_buffer_object * bufObj )
+{
+ (void) ctx; (void) target;
+
+ /* this should have been caught in _mesa_BufferSubData() */
+ ASSERT(size + offset <= bufObj->Size);
+
+ if (bufObj->Data) {
+ memcpy( (GLubyte *) bufObj->Data + offset, data, size );
+ }
+}
+
+
+/**
+ * Retrieve data from a subrange of buffer object. If the data range
+ * specified by \c size + \c offset extends beyond the end of the buffer or
+ * if \c data is \c NULL, no copy is performed.
+ *
+ * This is the default callback for \c dd_function_table::GetBufferSubData()
+ * Note that all GL error checking will have been done already.
+ *
+ * \param ctx GL context.
+ * \param target Buffer object target on which to operate.
+ * \param offset Offset of the first byte to be fetched.
+ * \param size Size, in bytes, of the data range.
+ * \param data Destination for data
+ * \param bufObj Object to be used.
+ *
+ * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
+ */
+void
+_mesa_buffer_get_subdata( struct gl_context *ctx, GLenum target, GLintptrARB offset,
+ GLsizeiptrARB size, GLvoid * data,
+ struct gl_buffer_object * bufObj )
+{
+ (void) ctx; (void) target;
+
+ if (bufObj->Data && ((GLsizeiptrARB) (size + offset) <= bufObj->Size)) {
+ memcpy( data, (GLubyte *) bufObj->Data + offset, size );
+ }
+}
+
+
+/**
+ * Default callback for \c dd_function_tabel::MapBuffer().
+ *
+ * The function parameters will have been already tested for errors.
+ *
+ * \param ctx GL context.
+ * \param target Buffer object target on which to operate.
+ * \param access Information about how the buffer will be accessed.
+ * \param bufObj Object to be mapped.
+ * \return A pointer to the object's internal data store that can be accessed
+ * by the processor
+ *
+ * \sa glMapBufferARB, dd_function_table::MapBuffer
+ */
+void *
+_mesa_buffer_map( struct gl_context *ctx, GLenum target, GLenum access,
+ struct gl_buffer_object *bufObj )
+{
+ (void) ctx;
+ (void) target;
+ (void) access;
+ /* Just return a direct pointer to the data */
+ if (_mesa_bufferobj_mapped(bufObj)) {
+ /* already mapped! */
+ return NULL;
+ }
+ bufObj->Pointer = bufObj->Data;
+ bufObj->Length = bufObj->Size;
+ bufObj->Offset = 0;
+ return bufObj->Pointer;
+}
+
+
+/**
+ * Default fallback for \c dd_function_table::MapBufferRange().
+ * Called via glMapBufferRange().
+ */
+static void *
+_mesa_buffer_map_range( struct gl_context *ctx, GLenum target, GLintptr offset,
+ GLsizeiptr length, GLbitfield access,
+ struct gl_buffer_object *bufObj )
+{
+ (void) ctx;
+ (void) target;
+ assert(!_mesa_bufferobj_mapped(bufObj));
+ /* Just return a direct pointer to the data */
+ bufObj->Pointer = bufObj->Data + offset;
+ bufObj->Length = length;
+ bufObj->Offset = offset;
+ bufObj->AccessFlags = access;
+ return bufObj->Pointer;
+}
+
+
+/**
+ * Default fallback for \c dd_function_table::FlushMappedBufferRange().
+ * Called via glFlushMappedBufferRange().
+ */
+static void
+_mesa_buffer_flush_mapped_range( struct gl_context *ctx, GLenum target,
+ GLintptr offset, GLsizeiptr length,
+ struct gl_buffer_object *obj )
+{
+ (void) ctx;
+ (void) target;
+ (void) offset;
+ (void) length;
+ (void) obj;
+ /* no-op */
+}
+
+
+/**
+ * Default callback for \c dd_function_table::MapBuffer().
+ *
+ * The input parameters will have been already tested for errors.
+ *
+ * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
+ */
+GLboolean
+_mesa_buffer_unmap( struct gl_context *ctx, GLenum target,
+ struct gl_buffer_object *bufObj )
+{
+ (void) ctx;
+ (void) target;
+ /* XXX we might assert here that bufObj->Pointer is non-null */
+ bufObj->Pointer = NULL;
+ bufObj->Length = 0;
+ bufObj->Offset = 0;
+ bufObj->AccessFlags = 0x0;
+ return GL_TRUE;
+}
+
+
+/**
+ * Default fallback for \c dd_function_table::CopyBufferSubData().
+ * Called via glCopyBuffserSubData().
+ */
+static void
+_mesa_copy_buffer_subdata(struct gl_context *ctx,
+ struct gl_buffer_object *src,
+ struct gl_buffer_object *dst,
+ GLintptr readOffset, GLintptr writeOffset,
+ GLsizeiptr size)
+{
+ GLubyte *srcPtr, *dstPtr;
+
+ /* buffer should not already be mapped */
+ assert(!_mesa_bufferobj_mapped(src));
+ assert(!_mesa_bufferobj_mapped(dst));
+
+ srcPtr = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_COPY_READ_BUFFER,
+ GL_READ_ONLY, src);
+ dstPtr = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_COPY_WRITE_BUFFER,
+ GL_WRITE_ONLY, dst);
+
+ if (srcPtr && dstPtr)
+ memcpy(dstPtr + writeOffset, srcPtr + readOffset, size);
+
+ ctx->Driver.UnmapBuffer(ctx, GL_COPY_READ_BUFFER, src);
+ ctx->Driver.UnmapBuffer(ctx, GL_COPY_WRITE_BUFFER, dst);
+}
+
+
+
+/**
+ * Initialize the state associated with buffer objects
+ */
+void
+_mesa_init_buffer_objects( struct gl_context *ctx )
+{
+ memset(&DummyBufferObject, 0, sizeof(DummyBufferObject));
+ DummyBufferObject.RefCount = 1000*1000*1000; /* never delete */
+
+ _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj,
+ ctx->Shared->NullBufferObj);
+ _mesa_reference_buffer_object(ctx, &ctx->Array.ElementArrayBufferObj,
+ ctx->Shared->NullBufferObj);
+
+ _mesa_reference_buffer_object(ctx, &ctx->CopyReadBuffer,
+ ctx->Shared->NullBufferObj);
+ _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer,
+ ctx->Shared->NullBufferObj);
+}
+
+
+void
+_mesa_free_buffer_objects( struct gl_context *ctx )
+{
+ _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, NULL);
+ _mesa_reference_buffer_object(ctx, &ctx->Array.ElementArrayBufferObj, NULL);
+
+ _mesa_reference_buffer_object(ctx, &ctx->CopyReadBuffer, NULL);
+ _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer, NULL);
+}
+
+
+/**
+ * Bind the specified target to buffer for the specified context.
+ * Called by glBindBuffer() and other functions.
+ */
+static void
+bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer)
+{
+ struct gl_buffer_object *oldBufObj;
+ struct gl_buffer_object *newBufObj = NULL;
+ struct gl_buffer_object **bindTarget = NULL;
+
+ bindTarget = get_buffer_target(ctx, target);
+ if (!bindTarget) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target 0x%x)", target);
+ return;
+ }
+
+ /* Get pointer to old buffer object (to be unbound) */
+ oldBufObj = *bindTarget;
+ if (oldBufObj && oldBufObj->Name == buffer)
+ return; /* rebinding the same buffer object- no change */
+
+ /*
+ * Get pointer to new buffer object (newBufObj)
+ */
+ if (buffer == 0) {
+ /* The spec says there's not a buffer object named 0, but we use
+ * one internally because it simplifies things.
+ */
+ newBufObj = ctx->Shared->NullBufferObj;
+ }
+ else {
+ /* non-default buffer object */
+ newBufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!newBufObj || newBufObj == &DummyBufferObject) {
+ /* If this is a new buffer object id, or one which was generated but
+ * never used before, allocate a buffer object now.
+ */
+ ASSERT(ctx->Driver.NewBufferObject);
+ newBufObj = ctx->Driver.NewBufferObject(ctx, buffer, target);
+ if (!newBufObj) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindBufferARB");
+ return;
+ }
+ _mesa_HashInsert(ctx->Shared->BufferObjects, buffer, newBufObj);
+ }
+ }
+
+ /* bind new buffer */
+ _mesa_reference_buffer_object(ctx, bindTarget, newBufObj);
+
+ /* Pass BindBuffer call to device driver */
+ if (ctx->Driver.BindBuffer)
+ ctx->Driver.BindBuffer( ctx, target, newBufObj );
+}
+
+
+/**
+ * Update the default buffer objects in the given context to reference those
+ * specified in the shared state and release those referencing the old
+ * shared state.
+ */
+void
+_mesa_update_default_objects_buffer_objects(struct gl_context *ctx)
+{
+ /* Bind the NullBufferObj to remove references to those
+ * in the shared context hash table.
+ */
+ bind_buffer_object( ctx, GL_ARRAY_BUFFER_ARB, 0);
+ bind_buffer_object( ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+ bind_buffer_object( ctx, GL_PIXEL_PACK_BUFFER_ARB, 0);
+ bind_buffer_object( ctx, GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+}
+
+
+
+/**
+ * Return the gl_buffer_object for the given ID.
+ * Always return NULL for ID 0.
+ */
+struct gl_buffer_object *
+_mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer)
+{
+ if (buffer == 0)
+ return NULL;
+ else
+ return (struct gl_buffer_object *)
+ _mesa_HashLookup(ctx->Shared->BufferObjects, buffer);
+}
+
+
+/**
+ * If *ptr points to obj, set ptr = the Null/default buffer object.
+ * This is a helper for buffer object deletion.
+ * The GL spec says that deleting a buffer object causes it to get
+ * unbound from all arrays in the current context.
+ */
+static void
+unbind(struct gl_context *ctx,
+ struct gl_buffer_object **ptr,
+ struct gl_buffer_object *obj)
+{
+ if (*ptr == obj) {
+ _mesa_reference_buffer_object(ctx, ptr, ctx->Shared->NullBufferObj);
+ }
+}
+
+
+/**
+ * Plug default/fallback buffer object functions into the device
+ * driver hooks.
+ */
+void
+_mesa_init_buffer_object_functions(struct dd_function_table *driver)
+{
+ /* GL_ARB_vertex/pixel_buffer_object */
+ driver->NewBufferObject = _mesa_new_buffer_object;
+ driver->DeleteBuffer = _mesa_delete_buffer_object;
+ driver->BindBuffer = NULL;
+ driver->BufferData = _mesa_buffer_data;
+ driver->BufferSubData = _mesa_buffer_subdata;
+ driver->GetBufferSubData = _mesa_buffer_get_subdata;
+ driver->MapBuffer = _mesa_buffer_map;
+ driver->UnmapBuffer = _mesa_buffer_unmap;
+
+ /* GL_ARB_map_buffer_range */
+ driver->MapBufferRange = _mesa_buffer_map_range;
+ driver->FlushMappedBufferRange = _mesa_buffer_flush_mapped_range;
+
+ /* GL_ARB_copy_buffer */
+ driver->CopyBufferSubData = _mesa_copy_buffer_subdata;
+}
+
+
+
+/**********************************************************************/
+/* API Functions */
+/**********************************************************************/
+
+void GLAPIENTRY
+_mesa_BindBufferARB(GLenum target, GLuint buffer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glBindBuffer(%s, %u)\n",
+ _mesa_lookup_enum_by_nr(target), buffer);
+
+ bind_buffer_object(ctx, target, buffer);
+}
+
+
+/**
+ * Delete a set of buffer objects.
+ *
+ * \param n Number of buffer objects to delete.
+ * \param ids Array of \c n buffer object IDs.
+ */
+void GLAPIENTRY
+_mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLsizei i;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteBuffersARB(n)");
+ return;
+ }
+
+ _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+
+ for (i = 0; i < n; i++) {
+ struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, ids[i]);
+ if (bufObj) {
+ struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
+ GLuint j;
+
+ ASSERT(bufObj->Name == ids[i] || bufObj == &DummyBufferObject);
+
+ if (_mesa_bufferobj_mapped(bufObj)) {
+ /* if mapped, unmap it now */
+ ctx->Driver.UnmapBuffer(ctx, 0, bufObj);
+ bufObj->AccessFlags = DEFAULT_ACCESS;
+ bufObj->Pointer = NULL;
+ }
+
+ /* unbind any vertex pointers bound to this buffer */
+ unbind(ctx, &arrayObj->Vertex.BufferObj, bufObj);
+ unbind(ctx, &arrayObj->Weight.BufferObj, bufObj);
+ unbind(ctx, &arrayObj->Normal.BufferObj, bufObj);
+ unbind(ctx, &arrayObj->Color.BufferObj, bufObj);
+ unbind(ctx, &arrayObj->SecondaryColor.BufferObj, bufObj);
+ unbind(ctx, &arrayObj->FogCoord.BufferObj, bufObj);
+ unbind(ctx, &arrayObj->Index.BufferObj, bufObj);
+ unbind(ctx, &arrayObj->EdgeFlag.BufferObj, bufObj);
+ for (j = 0; j < Elements(arrayObj->TexCoord); j++) {
+ unbind(ctx, &arrayObj->TexCoord[j].BufferObj, bufObj);
+ }
+ for (j = 0; j < Elements(arrayObj->VertexAttrib); j++) {
+ unbind(ctx, &arrayObj->VertexAttrib[j].BufferObj, bufObj);
+ }
+
+ if (ctx->Array.ArrayBufferObj == bufObj) {
+ _mesa_BindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
+ }
+ if (ctx->Array.ElementArrayBufferObj == bufObj) {
+ _mesa_BindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 );
+ }
+
+ /* unbind any pixel pack/unpack pointers bound to this buffer */
+ if (ctx->Pack.BufferObj == bufObj) {
+ _mesa_BindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );
+ }
+ if (ctx->Unpack.BufferObj == bufObj) {
+ _mesa_BindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, 0 );
+ }
+
+ /* The ID is immediately freed for re-use */
+ _mesa_HashRemove(ctx->Shared->BufferObjects, ids[i]);
+ _mesa_reference_buffer_object(ctx, &bufObj, NULL);
+ }
+ }
+
+ _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+}
+
+
+/**
+ * Generate a set of unique buffer object IDs and store them in \c buffer.
+ *
+ * \param n Number of IDs to generate.
+ * \param buffer Array of \c n locations to store the IDs.
+ */
+void GLAPIENTRY
+_mesa_GenBuffersARB(GLsizei n, GLuint *buffer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint first;
+ GLint i;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glGenBuffers(%d)\n", n);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGenBuffersARB");
+ return;
+ }
+
+ if (!buffer) {
+ return;
+ }
+
+ /*
+ * This must be atomic (generation and allocation of buffer object IDs)
+ */
+ _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+
+ first = _mesa_HashFindFreeKeyBlock(ctx->Shared->BufferObjects, n);
+
+ /* Insert the ID and pointer to dummy buffer object into hash table */
+ for (i = 0; i < n; i++) {
+ _mesa_HashInsert(ctx->Shared->BufferObjects, first + i,
+ &DummyBufferObject);
+ buffer[i] = first + i;
+ }
+
+ _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+}
+
+
+/**
+ * Determine if ID is the name of a buffer object.
+ *
+ * \param id ID of the potential buffer object.
+ * \return \c GL_TRUE if \c id is the name of a buffer object,
+ * \c GL_FALSE otherwise.
+ */
+GLboolean GLAPIENTRY
+_mesa_IsBufferARB(GLuint id)
+{
+ struct gl_buffer_object *bufObj;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
+
+ _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+ bufObj = _mesa_lookup_bufferobj(ctx, id);
+ _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+
+ return bufObj && bufObj != &DummyBufferObject;
+}
+
+
+void GLAPIENTRY
+_mesa_BufferDataARB(GLenum target, GLsizeiptrARB size,
+ const GLvoid * data, GLenum usage)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glBufferData(%s, %ld, %p, %s)\n",
+ _mesa_lookup_enum_by_nr(target),
+ (long int) size, data,
+ _mesa_lookup_enum_by_nr(usage));
+
+ if (size < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBufferDataARB(size < 0)");
+ return;
+ }
+
+ switch (usage) {
+ case GL_STREAM_DRAW_ARB:
+ case GL_STREAM_READ_ARB:
+ case GL_STREAM_COPY_ARB:
+ case GL_STATIC_DRAW_ARB:
+ case GL_STATIC_READ_ARB:
+ case GL_STATIC_COPY_ARB:
+ case GL_DYNAMIC_DRAW_ARB:
+ case GL_DYNAMIC_READ_ARB:
+ case GL_DYNAMIC_COPY_ARB:
+ /* OK */
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBufferDataARB(usage)");
+ return;
+ }
+
+ bufObj = get_buffer(ctx, target);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBufferDataARB(target)" );
+ return;
+ }
+ if (!_mesa_is_bufferobj(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBufferDataARB(buffer 0)" );
+ return;
+ }
+
+ if (_mesa_bufferobj_mapped(bufObj)) {
+ /* Unmap the existing buffer. We'll replace it now. Not an error. */
+ ctx->Driver.UnmapBuffer(ctx, target, bufObj);
+ bufObj->AccessFlags = DEFAULT_ACCESS;
+ ASSERT(bufObj->Pointer == NULL);
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
+
+ bufObj->Written = GL_TRUE;
+
+#ifdef VBO_DEBUG
+ printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
+ bufObj->Name, size, data, usage);
+#endif
+
+#ifdef BOUNDS_CHECK
+ size += 100;
+#endif
+
+ ASSERT(ctx->Driver.BufferData);
+ if (!ctx->Driver.BufferData( ctx, target, size, data, usage, bufObj )) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBufferDataARB()");
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_BufferSubDataARB(GLenum target, GLintptrARB offset,
+ GLsizeiptrARB size, const GLvoid * data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,
+ "glBufferSubDataARB" );
+ if (!bufObj) {
+ /* error already recorded */
+ return;
+ }
+
+ if (size == 0)
+ return;
+
+ bufObj->Written = GL_TRUE;
+
+ ASSERT(ctx->Driver.BufferSubData);
+ ctx->Driver.BufferSubData( ctx, target, offset, size, data, bufObj );
+}
+
+
+void GLAPIENTRY
+_mesa_GetBufferSubDataARB(GLenum target, GLintptrARB offset,
+ GLsizeiptrARB size, void * data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,
+ "glGetBufferSubDataARB" );
+ if (!bufObj) {
+ /* error already recorded */
+ return;
+ }
+
+ ASSERT(ctx->Driver.GetBufferSubData);
+ ctx->Driver.GetBufferSubData( ctx, target, offset, size, data, bufObj );
+}
+
+
+void * GLAPIENTRY
+_mesa_MapBufferARB(GLenum target, GLenum access)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object * bufObj;
+ GLbitfield accessFlags;
+ void *map;
+
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
+
+ switch (access) {
+ case GL_READ_ONLY_ARB:
+ accessFlags = GL_MAP_READ_BIT;
+ break;
+ case GL_WRITE_ONLY_ARB:
+ accessFlags = GL_MAP_WRITE_BIT;
+ break;
+ case GL_READ_WRITE_ARB:
+ accessFlags = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glMapBufferARB(access)");
+ return NULL;
+ }
+
+ bufObj = get_buffer(ctx, target);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glMapBufferARB(target)" );
+ return NULL;
+ }
+ if (!_mesa_is_bufferobj(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glMapBufferARB(buffer 0)" );
+ return NULL;
+ }
+ if (_mesa_bufferobj_mapped(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glMapBufferARB(already mapped)");
+ return NULL;
+ }
+
+ ASSERT(ctx->Driver.MapBuffer);
+ map = ctx->Driver.MapBuffer( ctx, target, access, bufObj );
+ if (!map) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMapBufferARB(map failed)");
+ return NULL;
+ }
+ else {
+ /* The driver callback should have set these fields.
+ * This is important because other modules (like VBO) might call
+ * the driver function directly.
+ */
+ ASSERT(bufObj->Pointer == map);
+ ASSERT(bufObj->Length == bufObj->Size);
+ ASSERT(bufObj->Offset == 0);
+ bufObj->AccessFlags = accessFlags;
+ }
+
+ if (access == GL_WRITE_ONLY_ARB || access == GL_READ_WRITE_ARB)
+ bufObj->Written = GL_TRUE;
+
+#ifdef VBO_DEBUG
+ printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
+ bufObj->Name, bufObj->Size, access);
+ if (access == GL_WRITE_ONLY_ARB) {
+ GLuint i;
+ GLubyte *b = (GLubyte *) bufObj->Pointer;
+ for (i = 0; i < bufObj->Size; i++)
+ b[i] = i & 0xff;
+ }
+#endif
+
+#ifdef BOUNDS_CHECK
+ {
+ GLubyte *buf = (GLubyte *) bufObj->Pointer;
+ GLuint i;
+ /* buffer is 100 bytes larger than requested, fill with magic value */
+ for (i = 0; i < 100; i++) {
+ buf[bufObj->Size - i - 1] = 123;
+ }
+ }
+#endif
+
+ return bufObj->Pointer;
+}
+
+
+GLboolean GLAPIENTRY
+_mesa_UnmapBufferARB(GLenum target)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+ GLboolean status = GL_TRUE;
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
+
+ bufObj = get_buffer(ctx, target);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glUnmapBufferARB(target)" );
+ return GL_FALSE;
+ }
+ if (!_mesa_is_bufferobj(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glUnmapBufferARB" );
+ return GL_FALSE;
+ }
+ if (!_mesa_bufferobj_mapped(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glUnmapBufferARB");
+ return GL_FALSE;
+ }
+
+#ifdef BOUNDS_CHECK
+ if (bufObj->Access != GL_READ_ONLY_ARB) {
+ GLubyte *buf = (GLubyte *) bufObj->Pointer;
+ GLuint i;
+ /* check that last 100 bytes are still = magic value */
+ for (i = 0; i < 100; i++) {
+ GLuint pos = bufObj->Size - i - 1;
+ if (buf[pos] != 123) {
+ _mesa_warning(ctx, "Out of bounds buffer object write detected"
+ " at position %d (value = %u)\n",
+ pos, buf[pos]);
+ }
+ }
+ }
+#endif
+
+#ifdef VBO_DEBUG
+ if (bufObj->AccessFlags & GL_MAP_WRITE_BIT) {
+ GLuint i, unchanged = 0;
+ GLubyte *b = (GLubyte *) bufObj->Pointer;
+ GLint pos = -1;
+ /* check which bytes changed */
+ for (i = 0; i < bufObj->Size - 1; i++) {
+ if (b[i] == (i & 0xff) && b[i+1] == ((i+1) & 0xff)) {
+ unchanged++;
+ if (pos == -1)
+ pos = i;
+ }
+ }
+ if (unchanged) {
+ printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
+ bufObj->Name, unchanged, bufObj->Size, pos);
+ }
+ }
+#endif
+
+ status = ctx->Driver.UnmapBuffer( ctx, target, bufObj );
+ bufObj->AccessFlags = DEFAULT_ACCESS;
+ ASSERT(bufObj->Pointer == NULL);
+ ASSERT(bufObj->Offset == 0);
+ ASSERT(bufObj->Length == 0);
+
+ return status;
+}
+
+
+void GLAPIENTRY
+_mesa_GetBufferParameterivARB(GLenum target, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ bufObj = get_buffer(ctx, target);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameterivARB(target)" );
+ return;
+ }
+ if (!_mesa_is_bufferobj(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferParameterivARB" );
+ return;
+ }
+
+ switch (pname) {
+ case GL_BUFFER_SIZE_ARB:
+ *params = (GLint) bufObj->Size;
+ return;
+ case GL_BUFFER_USAGE_ARB:
+ *params = bufObj->Usage;
+ return;
+ case GL_BUFFER_ACCESS_ARB:
+ *params = simplified_access_mode(bufObj->AccessFlags);
+ return;
+ case GL_BUFFER_MAPPED_ARB:
+ *params = _mesa_bufferobj_mapped(bufObj);
+ return;
+ case GL_BUFFER_ACCESS_FLAGS:
+ if (ctx->VersionMajor < 3)
+ goto invalid_pname;
+ *params = bufObj->AccessFlags;
+ return;
+ case GL_BUFFER_MAP_OFFSET:
+ if (ctx->VersionMajor < 3)
+ goto invalid_pname;
+ *params = (GLint) bufObj->Offset;
+ return;
+ case GL_BUFFER_MAP_LENGTH:
+ if (ctx->VersionMajor < 3)
+ goto invalid_pname;
+ *params = (GLint) bufObj->Length;
+ return;
+ default:
+ ; /* fall-through */
+ }
+
+invalid_pname:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameterivARB(pname=%s)",
+ _mesa_lookup_enum_by_nr(pname));
+}
+
+
+/**
+ * New in GL 3.2
+ * This is pretty much a duplicate of GetBufferParameteriv() but the
+ * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
+ */
+void GLAPIENTRY
+_mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ bufObj = get_buffer(ctx, target);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameteri64v(target)" );
+ return;
+ }
+ if (!_mesa_is_bufferobj(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferParameteri64v" );
+ return;
+ }
+
+ switch (pname) {
+ case GL_BUFFER_SIZE_ARB:
+ *params = bufObj->Size;
+ return;
+ case GL_BUFFER_USAGE_ARB:
+ *params = bufObj->Usage;
+ return;
+ case GL_BUFFER_ACCESS_ARB:
+ *params = simplified_access_mode(bufObj->AccessFlags);
+ return;
+ case GL_BUFFER_ACCESS_FLAGS:
+ if (ctx->VersionMajor < 3)
+ goto invalid_pname;
+ *params = bufObj->AccessFlags;
+ return;
+ case GL_BUFFER_MAPPED_ARB:
+ *params = _mesa_bufferobj_mapped(bufObj);
+ return;
+ case GL_BUFFER_MAP_OFFSET:
+ if (ctx->VersionMajor < 3)
+ goto invalid_pname;
+ *params = bufObj->Offset;
+ return;
+ case GL_BUFFER_MAP_LENGTH:
+ if (ctx->VersionMajor < 3)
+ goto invalid_pname;
+ *params = bufObj->Length;
+ return;
+ default:
+ ; /* fall-through */
+ }
+
+invalid_pname:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameteri64v(pname=%s)",
+ _mesa_lookup_enum_by_nr(pname));
+}
+
+
+void GLAPIENTRY
+_mesa_GetBufferPointervARB(GLenum target, GLenum pname, GLvoid **params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object * bufObj;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (pname != GL_BUFFER_MAP_POINTER_ARB) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferPointervARB(pname)");
+ return;
+ }
+
+ bufObj = get_buffer(ctx, target);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferPointervARB(target)" );
+ return;
+ }
+ if (!_mesa_is_bufferobj(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferPointervARB" );
+ return;
+ }
+
+ *params = bufObj->Pointer;
+}
+
+
+void GLAPIENTRY
+_mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
+ GLintptr readOffset, GLintptr writeOffset,
+ GLsizeiptr size)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *src, *dst;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ src = get_buffer(ctx, readTarget);
+ if (!src || !_mesa_is_bufferobj(src)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glCopyBuffserSubData(readTarget = 0x%x)", readTarget);
+ return;
+ }
+
+ dst = get_buffer(ctx, writeTarget);
+ if (!dst || !_mesa_is_bufferobj(dst)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glCopyBuffserSubData(writeTarget = 0x%x)", writeTarget);
+ return;
+ }
+
+ if (_mesa_bufferobj_mapped(src)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyBuffserSubData(readBuffer is mapped)");
+ return;
+ }
+
+ if (_mesa_bufferobj_mapped(dst)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyBuffserSubData(writeBuffer is mapped)");
+ return;
+ }
+
+ if (readOffset < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyBuffserSubData(readOffset = %d)", (int) readOffset);
+ return;
+ }
+
+ if (writeOffset < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyBuffserSubData(writeOffset = %d)", (int) writeOffset);
+ return;
+ }
+
+ if (readOffset + size > src->Size) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyBuffserSubData(readOffset + size = %d)",
+ (int) (readOffset + size));
+ return;
+ }
+
+ if (writeOffset + size > dst->Size) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyBuffserSubData(writeOffset + size = %d)",
+ (int) (writeOffset + size));
+ return;
+ }
+
+ if (src == dst) {
+ if (readOffset + size <= writeOffset) {
+ /* OK */
+ }
+ else if (writeOffset + size <= readOffset) {
+ /* OK */
+ }
+ else {
+ /* overlapping src/dst is illegal */
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyBuffserSubData(overlapping src/dst)");
+ return;
+ }
+ }
+
+ ctx->Driver.CopyBufferSubData(ctx, src, dst, readOffset, writeOffset, size);
+}
+
+
+/**
+ * See GL_ARB_map_buffer_range spec
+ */
+void * GLAPIENTRY
+_mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
+ GLbitfield access)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+ void *map;
+
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
+
+ if (!ctx->Extensions.ARB_map_buffer_range) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(extension not supported)");
+ return NULL;
+ }
+
+ if (offset < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glMapBufferRange(offset = %ld)", (long)offset);
+ return NULL;
+ }
+
+ if (length < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glMapBufferRange(length = %ld)", (long)length);
+ return NULL;
+ }
+
+ if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(access indicates neither read or write)");
+ return NULL;
+ }
+
+ if (access & GL_MAP_READ_BIT) {
+ if ((access & GL_MAP_INVALIDATE_RANGE_BIT) ||
+ (access & GL_MAP_INVALIDATE_BUFFER_BIT) ||
+ (access & GL_MAP_UNSYNCHRONIZED_BIT)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(invalid access flags)");
+ return NULL;
+ }
+ }
+
+ if ((access & GL_MAP_FLUSH_EXPLICIT_BIT) &&
+ ((access & GL_MAP_WRITE_BIT) == 0)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(invalid access flags)");
+ return NULL;
+ }
+
+ bufObj = get_buffer(ctx, target);
+ if (!bufObj || !_mesa_is_bufferobj(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glMapBufferRange(target = 0x%x)", target);
+ return NULL;
+ }
+
+ if (offset + length > bufObj->Size) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glMapBufferRange(offset + length > size)");
+ return NULL;
+ }
+
+ if (_mesa_bufferobj_mapped(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(buffer already mapped)");
+ return NULL;
+ }
+
+ ASSERT(ctx->Driver.MapBufferRange);
+ map = ctx->Driver.MapBufferRange(ctx, target, offset, length,
+ access, bufObj);
+ if (!map) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMapBufferARB(map failed)");
+ }
+ else {
+ /* The driver callback should have set all these fields.
+ * This is important because other modules (like VBO) might call
+ * the driver function directly.
+ */
+ ASSERT(bufObj->Pointer == map);
+ ASSERT(bufObj->Length == length);
+ ASSERT(bufObj->Offset == offset);
+ ASSERT(bufObj->AccessFlags == access);
+ }
+
+ return map;
+}
+
+
+/**
+ * See GL_ARB_map_buffer_range spec
+ */
+void GLAPIENTRY
+_mesa_FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!ctx->Extensions.ARB_map_buffer_range) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(extension not supported)");
+ return;
+ }
+
+ if (offset < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glMapBufferRange(offset = %ld)", (long)offset);
+ return;
+ }
+
+ if (length < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glMapBufferRange(length = %ld)", (long)length);
+ return;
+ }
+
+ bufObj = get_buffer(ctx, target);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glMapBufferRange(target = 0x%x)", target);
+ return;
+ }
+
+ if (!_mesa_is_bufferobj(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(current buffer is 0)");
+ return;
+ }
+
+ if (!_mesa_bufferobj_mapped(bufObj)) {
+ /* buffer is not mapped */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(buffer is not mapped)");
+ return;
+ }
+
+ if ((bufObj->AccessFlags & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
+ return;
+ }
+
+ if (offset + length > bufObj->Length) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glMapBufferRange(offset %ld + length %ld > mapped length %ld)",
+ (long)offset, (long)length, (long)bufObj->Length);
+ return;
+ }
+
+ ASSERT(bufObj->AccessFlags & GL_MAP_WRITE_BIT);
+
+ if (ctx->Driver.FlushMappedBufferRange)
+ ctx->Driver.FlushMappedBufferRange(ctx, target, offset, length, bufObj);
+}
+
+
+#if FEATURE_APPLE_object_purgeable
+static GLenum
+_mesa_BufferObjectPurgeable(struct gl_context *ctx, GLuint name, GLenum option)
+{
+ struct gl_buffer_object *bufObj;
+ GLenum retval;
+
+ bufObj = _mesa_lookup_bufferobj(ctx, name);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glObjectPurgeable(name = 0x%x)", name);
+ return 0;
+ }
+ if (!_mesa_is_bufferobj(bufObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glObjectPurgeable(buffer 0)" );
+ return 0;
+ }
+
+ if (bufObj->Purgeable) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glObjectPurgeable(name = 0x%x) is already purgeable", name);
+ return GL_VOLATILE_APPLE;
+ }
+
+ bufObj->Purgeable = GL_TRUE;
+
+ retval = GL_VOLATILE_APPLE;
+ if (ctx->Driver.BufferObjectPurgeable)
+ retval = ctx->Driver.BufferObjectPurgeable(ctx, bufObj, option);
+
+ return retval;
+}
+
+
+static GLenum
+_mesa_RenderObjectPurgeable(struct gl_context *ctx, GLuint name, GLenum option)
+{
+ struct gl_renderbuffer *bufObj;
+ GLenum retval;
+
+ bufObj = _mesa_lookup_renderbuffer(ctx, name);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glObjectUnpurgeable(name = 0x%x)", name);
+ return 0;
+ }
+
+ if (bufObj->Purgeable) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glObjectPurgeable(name = 0x%x) is already purgeable", name);
+ return GL_VOLATILE_APPLE;
+ }
+
+ bufObj->Purgeable = GL_TRUE;
+
+ retval = GL_VOLATILE_APPLE;
+ if (ctx->Driver.RenderObjectPurgeable)
+ retval = ctx->Driver.RenderObjectPurgeable(ctx, bufObj, option);
+
+ return retval;
+}
+
+
+static GLenum
+_mesa_TextureObjectPurgeable(struct gl_context *ctx, GLuint name, GLenum option)
+{
+ struct gl_texture_object *bufObj;
+ GLenum retval;
+
+ bufObj = _mesa_lookup_texture(ctx, name);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glObjectPurgeable(name = 0x%x)", name);
+ return 0;
+ }
+
+ if (bufObj->Purgeable) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glObjectPurgeable(name = 0x%x) is already purgeable", name);
+ return GL_VOLATILE_APPLE;
+ }
+
+ bufObj->Purgeable = GL_TRUE;
+
+ retval = GL_VOLATILE_APPLE;
+ if (ctx->Driver.TextureObjectPurgeable)
+ retval = ctx->Driver.TextureObjectPurgeable(ctx, bufObj, option);
+
+ return retval;
+}
+
+
+GLenum GLAPIENTRY
+_mesa_ObjectPurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
+{
+ GLenum retval;
+
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
+
+ if (name == 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glObjectPurgeable(name = 0x%x)", name);
+ return 0;
+ }
+
+ switch (option) {
+ case GL_VOLATILE_APPLE:
+ case GL_RELEASED_APPLE:
+ /* legal */
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glObjectPurgeable(name = 0x%x) invalid option: %d",
+ name, option);
+ return 0;
+ }
+
+ switch (objectType) {
+ case GL_TEXTURE:
+ retval = _mesa_TextureObjectPurgeable (ctx, name, option);
+ break;
+ case GL_RENDERBUFFER_EXT:
+ retval = _mesa_RenderObjectPurgeable (ctx, name, option);
+ break;
+ case GL_BUFFER_OBJECT_APPLE:
+ retval = _mesa_BufferObjectPurgeable (ctx, name, option);
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glObjectPurgeable(name = 0x%x) invalid type: %d",
+ name, objectType);
+ return 0;
+ }
+
+ /* In strict conformance to the spec, we must only return VOLATILE when
+ * when passed the VOLATILE option. Madness.
+ *
+ * XXX First fix the spec, then fix me.
+ */
+ return option == GL_VOLATILE_APPLE ? GL_VOLATILE_APPLE : retval;
+}
+
+
+static GLenum
+_mesa_BufferObjectUnpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
+{
+ struct gl_buffer_object *bufObj;
+ GLenum retval;
+
+ bufObj = _mesa_lookup_bufferobj(ctx, name);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glObjectUnpurgeable(name = 0x%x)", name);
+ return 0;
+ }
+
+ if (! bufObj->Purgeable) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glObjectUnpurgeable(name = 0x%x) object is "
+ " already \"unpurged\"", name);
+ return 0;
+ }
+
+ bufObj->Purgeable = GL_FALSE;
+
+ retval = option;
+ if (ctx->Driver.BufferObjectUnpurgeable)
+ retval = ctx->Driver.BufferObjectUnpurgeable(ctx, bufObj, option);
+
+ return retval;
+}
+
+
+static GLenum
+_mesa_RenderObjectUnpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
+{
+ struct gl_renderbuffer *bufObj;
+ GLenum retval;
+
+ bufObj = _mesa_lookup_renderbuffer(ctx, name);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glObjectUnpurgeable(name = 0x%x)", name);
+ return 0;
+ }
+
+ if (! bufObj->Purgeable) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glObjectUnpurgeable(name = 0x%x) object is "
+ " already \"unpurged\"", name);
+ return 0;
+ }
+
+ bufObj->Purgeable = GL_FALSE;
+
+ retval = option;
+ if (ctx->Driver.RenderObjectUnpurgeable)
+ retval = ctx->Driver.RenderObjectUnpurgeable(ctx, bufObj, option);
+
+ return retval;
+}
+
+
+static GLenum
+_mesa_TextureObjectUnpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
+{
+ struct gl_texture_object *bufObj;
+ GLenum retval;
+
+ bufObj = _mesa_lookup_texture(ctx, name);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glObjectUnpurgeable(name = 0x%x)", name);
+ return 0;
+ }
+
+ if (! bufObj->Purgeable) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glObjectUnpurgeable(name = 0x%x) object is"
+ " already \"unpurged\"", name);
+ return 0;
+ }
+
+ bufObj->Purgeable = GL_FALSE;
+
+ retval = option;
+ if (ctx->Driver.TextureObjectUnpurgeable)
+ retval = ctx->Driver.TextureObjectUnpurgeable(ctx, bufObj, option);
+
+ return retval;
+}
+
+
+GLenum GLAPIENTRY
+_mesa_ObjectUnpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
+
+ if (name == 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glObjectUnpurgeable(name = 0x%x)", name);
+ return 0;
+ }
+
+ switch (option) {
+ case GL_RETAINED_APPLE:
+ case GL_UNDEFINED_APPLE:
+ /* legal */
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
+ name, option);
+ return 0;
+ }
+
+ switch (objectType) {
+ case GL_BUFFER_OBJECT_APPLE:
+ return _mesa_BufferObjectUnpurgeable(ctx, name, option);
+ case GL_TEXTURE:
+ return _mesa_TextureObjectUnpurgeable(ctx, name, option);
+ case GL_RENDERBUFFER_EXT:
+ return _mesa_RenderObjectUnpurgeable(ctx, name, option);
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
+ name, objectType);
+ return 0;
+ }
+}
+
+
+static void
+_mesa_GetBufferObjectParameterivAPPLE(struct gl_context *ctx, GLuint name,
+ GLenum pname, GLint* params)
+{
+ struct gl_buffer_object *bufObj;
+
+ bufObj = _mesa_lookup_bufferobj(ctx, name);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glGetObjectParameteriv(name = 0x%x) invalid object", name);
+ return;
+ }
+
+ switch (pname) {
+ case GL_PURGEABLE_APPLE:
+ *params = bufObj->Purgeable;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
+ name, pname);
+ break;
+ }
+}
+
+
+static void
+_mesa_GetRenderObjectParameterivAPPLE(struct gl_context *ctx, GLuint name,
+ GLenum pname, GLint* params)
+{
+ struct gl_renderbuffer *bufObj;
+
+ bufObj = _mesa_lookup_renderbuffer(ctx, name);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glObjectUnpurgeable(name = 0x%x)", name);
+ return;
+ }
+
+ switch (pname) {
+ case GL_PURGEABLE_APPLE:
+ *params = bufObj->Purgeable;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
+ name, pname);
+ break;
+ }
+}
+
+
+static void
+_mesa_GetTextureObjectParameterivAPPLE(struct gl_context *ctx, GLuint name,
+ GLenum pname, GLint* params)
+{
+ struct gl_texture_object *bufObj;
+
+ bufObj = _mesa_lookup_texture(ctx, name);
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glObjectUnpurgeable(name = 0x%x)", name);
+ return;
+ }
+
+ switch (pname) {
+ case GL_PURGEABLE_APPLE:
+ *params = bufObj->Purgeable;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
+ name, pname);
+ break;
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum pname,
+ GLint* params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (name == 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glGetObjectParameteriv(name = 0x%x)", name);
+ return;
+ }
+
+ switch (objectType) {
+ case GL_TEXTURE:
+ _mesa_GetTextureObjectParameterivAPPLE (ctx, name, pname, params);
+ break;
+ case GL_BUFFER_OBJECT_APPLE:
+ _mesa_GetBufferObjectParameterivAPPLE (ctx, name, pname, params);
+ break;
+ case GL_RENDERBUFFER_EXT:
+ _mesa_GetRenderObjectParameterivAPPLE (ctx, name, pname, params);
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
+ name, objectType);
+ }
+}
+
+#endif /* FEATURE_APPLE_object_purgeable */
diff --git a/mesalib/src/mesa/main/bufferobj.h b/mesalib/src/mesa/main/bufferobj.h
index 91fa073b6..f673f431f 100644
--- a/mesalib/src/mesa/main/bufferobj.h
+++ b/mesalib/src/mesa/main/bufferobj.h
@@ -1,149 +1,149 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.6
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-
-#ifndef BUFFEROBJ_H
-#define BUFFEROBJ_H
-
-
-#include "mfeatures.h"
-#include "mtypes.h"
-
-
-/*
- * Internal functions
- */
-
-
-/** Is the given buffer object currently mapped? */
-static INLINE GLboolean
-_mesa_bufferobj_mapped(const struct gl_buffer_object *obj)
-{
- return obj->Pointer != NULL;
-}
-
-/**
- * Is the given buffer object a user-created buffer object?
- * Mesa uses default buffer objects in several places. Default buffers
- * always have Name==0. User created buffers have Name!=0.
- */
-static INLINE GLboolean
-_mesa_is_bufferobj(const struct gl_buffer_object *obj)
-{
- return obj->Name != 0;
-}
-
-
-extern void
-_mesa_init_buffer_objects( struct gl_context *ctx );
-
-extern void
-_mesa_free_buffer_objects( struct gl_context *ctx );
-
-extern void
-_mesa_update_default_objects_buffer_objects(struct gl_context *ctx);
-
-
-extern struct gl_buffer_object *
-_mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer);
-
-extern void
-_mesa_initialize_buffer_object( struct gl_buffer_object *obj,
- GLuint name, GLenum target );
-
-extern void
-_mesa_reference_buffer_object(struct gl_context *ctx,
- struct gl_buffer_object **ptr,
- struct gl_buffer_object *bufObj);
-
-extern void
-_mesa_init_buffer_object_functions(struct dd_function_table *driver);
-
-
-/*
- * API functions
- */
-
-extern void GLAPIENTRY
-_mesa_BindBufferARB(GLenum target, GLuint buffer);
-
-extern void GLAPIENTRY
-_mesa_DeleteBuffersARB(GLsizei n, const GLuint * buffer);
-
-extern void GLAPIENTRY
-_mesa_GenBuffersARB(GLsizei n, GLuint * buffer);
-
-extern GLboolean GLAPIENTRY
-_mesa_IsBufferARB(GLuint buffer);
-
-extern void GLAPIENTRY
-_mesa_BufferDataARB(GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage);
-
-extern void GLAPIENTRY
-_mesa_BufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid * data);
-
-extern void GLAPIENTRY
-_mesa_GetBufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, void * data);
-
-extern void * GLAPIENTRY
-_mesa_MapBufferARB(GLenum target, GLenum access);
-
-extern GLboolean GLAPIENTRY
-_mesa_UnmapBufferARB(GLenum target);
-
-extern void GLAPIENTRY
-_mesa_GetBufferParameterivARB(GLenum target, GLenum pname, GLint *params);
-
-extern void GLAPIENTRY
-_mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params);
-
-extern void GLAPIENTRY
-_mesa_GetBufferPointervARB(GLenum target, GLenum pname, GLvoid **params);
-
-extern void GLAPIENTRY
-_mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
- GLintptr readOffset, GLintptr writeOffset,
- GLsizeiptr size);
-
-extern void * GLAPIENTRY
-_mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
- GLbitfield access);
-
-extern void GLAPIENTRY
-_mesa_FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length);
-
-#if FEATURE_APPLE_object_purgeable
-extern GLenum GLAPIENTRY
-_mesa_ObjectPurgeableAPPLE(GLenum objectType, GLuint name, GLenum option);
-
-extern GLenum GLAPIENTRY
-_mesa_ObjectUnpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option);
-
-extern void GLAPIENTRY
-_mesa_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum pname, GLint* params);
-#endif
-
-#endif
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.6
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+#ifndef BUFFEROBJ_H
+#define BUFFEROBJ_H
+
+
+#include "mfeatures.h"
+#include "mtypes.h"
+
+
+/*
+ * Internal functions
+ */
+
+
+/** Is the given buffer object currently mapped? */
+static INLINE GLboolean
+_mesa_bufferobj_mapped(const struct gl_buffer_object *obj)
+{
+ return obj->Pointer != NULL;
+}
+
+/**
+ * Is the given buffer object a user-created buffer object?
+ * Mesa uses default buffer objects in several places. Default buffers
+ * always have Name==0. User created buffers have Name!=0.
+ */
+static INLINE GLboolean
+_mesa_is_bufferobj(const struct gl_buffer_object *obj)
+{
+ return obj->Name != 0;
+}
+
+
+extern void
+_mesa_init_buffer_objects( struct gl_context *ctx );
+
+extern void
+_mesa_free_buffer_objects( struct gl_context *ctx );
+
+extern void
+_mesa_update_default_objects_buffer_objects(struct gl_context *ctx);
+
+
+extern struct gl_buffer_object *
+_mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer);
+
+extern void
+_mesa_initialize_buffer_object( struct gl_buffer_object *obj,
+ GLuint name, GLenum target );
+
+extern void
+_mesa_reference_buffer_object(struct gl_context *ctx,
+ struct gl_buffer_object **ptr,
+ struct gl_buffer_object *bufObj);
+
+extern void
+_mesa_init_buffer_object_functions(struct dd_function_table *driver);
+
+
+/*
+ * API functions
+ */
+
+extern void GLAPIENTRY
+_mesa_BindBufferARB(GLenum target, GLuint buffer);
+
+extern void GLAPIENTRY
+_mesa_DeleteBuffersARB(GLsizei n, const GLuint * buffer);
+
+extern void GLAPIENTRY
+_mesa_GenBuffersARB(GLsizei n, GLuint * buffer);
+
+extern GLboolean GLAPIENTRY
+_mesa_IsBufferARB(GLuint buffer);
+
+extern void GLAPIENTRY
+_mesa_BufferDataARB(GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage);
+
+extern void GLAPIENTRY
+_mesa_BufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid * data);
+
+extern void GLAPIENTRY
+_mesa_GetBufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, void * data);
+
+extern void * GLAPIENTRY
+_mesa_MapBufferARB(GLenum target, GLenum access);
+
+extern GLboolean GLAPIENTRY
+_mesa_UnmapBufferARB(GLenum target);
+
+extern void GLAPIENTRY
+_mesa_GetBufferParameterivARB(GLenum target, GLenum pname, GLint *params);
+
+extern void GLAPIENTRY
+_mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params);
+
+extern void GLAPIENTRY
+_mesa_GetBufferPointervARB(GLenum target, GLenum pname, GLvoid **params);
+
+extern void GLAPIENTRY
+_mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
+ GLintptr readOffset, GLintptr writeOffset,
+ GLsizeiptr size);
+
+extern void * GLAPIENTRY
+_mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
+ GLbitfield access);
+
+extern void GLAPIENTRY
+_mesa_FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length);
+
+#if FEATURE_APPLE_object_purgeable
+extern GLenum GLAPIENTRY
+_mesa_ObjectPurgeableAPPLE(GLenum objectType, GLuint name, GLenum option);
+
+extern GLenum GLAPIENTRY
+_mesa_ObjectUnpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option);
+
+extern void GLAPIENTRY
+_mesa_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum pname, GLint* params);
+#endif
+
+#endif
diff --git a/mesalib/src/mesa/main/colortab.c b/mesalib/src/mesa/main/colortab.c
index d0c865735..48318248e 100644
--- a/mesalib/src/mesa/main/colortab.c
+++ b/mesalib/src/mesa/main/colortab.c
@@ -1,821 +1,821 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "glheader.h"
-#include "bufferobj.h"
-#include "colortab.h"
-#include "context.h"
-#include "image.h"
-#include "macros.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "pack.h"
-#include "pbo.h"
-#include "state.h"
-#include "teximage.h"
-#include "texstate.h"
-#include "main/dispatch.h"
-
-
-#if FEATURE_colortable
-
-
-/**
- * Given an internalFormat token passed to glColorTable,
- * return the corresponding base format.
- * Return -1 if invalid token.
- */
-static GLint
-base_colortab_format( GLenum format )
-{
- switch (format) {
- case GL_ALPHA:
- case GL_ALPHA4:
- case GL_ALPHA8:
- case GL_ALPHA12:
- case GL_ALPHA16:
- return GL_ALPHA;
- case GL_LUMINANCE:
- case GL_LUMINANCE4:
- case GL_LUMINANCE8:
- case GL_LUMINANCE12:
- case GL_LUMINANCE16:
- return GL_LUMINANCE;
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE4_ALPHA4:
- case GL_LUMINANCE6_ALPHA2:
- case GL_LUMINANCE8_ALPHA8:
- case GL_LUMINANCE12_ALPHA4:
- case GL_LUMINANCE12_ALPHA12:
- case GL_LUMINANCE16_ALPHA16:
- return GL_LUMINANCE_ALPHA;
- case GL_INTENSITY:
- case GL_INTENSITY4:
- case GL_INTENSITY8:
- case GL_INTENSITY12:
- case GL_INTENSITY16:
- return GL_INTENSITY;
- case GL_RGB:
- case GL_R3_G3_B2:
- case GL_RGB4:
- case GL_RGB5:
- case GL_RGB8:
- case GL_RGB10:
- case GL_RGB12:
- case GL_RGB16:
- return GL_RGB;
- case GL_RGBA:
- case GL_RGBA2:
- case GL_RGBA4:
- case GL_RGB5_A1:
- case GL_RGBA8:
- case GL_RGB10_A2:
- case GL_RGBA12:
- case GL_RGBA16:
- return GL_RGBA;
- default:
- return -1; /* error */
- }
-}
-
-
-
-/**
- * Examine table's format and set the component sizes accordingly.
- */
-static void
-set_component_sizes( struct gl_color_table *table )
-{
- /* assuming the ubyte table */
- const GLubyte sz = 8;
-
- switch (table->_BaseFormat) {
- case GL_ALPHA:
- table->RedSize = 0;
- table->GreenSize = 0;
- table->BlueSize = 0;
- table->AlphaSize = sz;
- table->IntensitySize = 0;
- table->LuminanceSize = 0;
- break;
- case GL_LUMINANCE:
- table->RedSize = 0;
- table->GreenSize = 0;
- table->BlueSize = 0;
- table->AlphaSize = 0;
- table->IntensitySize = 0;
- table->LuminanceSize = sz;
- break;
- case GL_LUMINANCE_ALPHA:
- table->RedSize = 0;
- table->GreenSize = 0;
- table->BlueSize = 0;
- table->AlphaSize = sz;
- table->IntensitySize = 0;
- table->LuminanceSize = sz;
- break;
- case GL_INTENSITY:
- table->RedSize = 0;
- table->GreenSize = 0;
- table->BlueSize = 0;
- table->AlphaSize = 0;
- table->IntensitySize = sz;
- table->LuminanceSize = 0;
- break;
- case GL_RGB:
- table->RedSize = sz;
- table->GreenSize = sz;
- table->BlueSize = sz;
- table->AlphaSize = 0;
- table->IntensitySize = 0;
- table->LuminanceSize = 0;
- break;
- case GL_RGBA:
- table->RedSize = sz;
- table->GreenSize = sz;
- table->BlueSize = sz;
- table->AlphaSize = sz;
- table->IntensitySize = 0;
- table->LuminanceSize = 0;
- break;
- default:
- _mesa_problem(NULL, "unexpected format in set_component_sizes");
- }
-}
-
-
-
-/**
- * Update/replace all or part of a color table. Helper function
- * used by _mesa_ColorTable() and _mesa_ColorSubTable().
- * The table->Table buffer should already be allocated.
- * \param start first entry to update
- * \param count number of entries to update
- * \param format format of user-provided table data
- * \param type datatype of user-provided table data
- * \param data user-provided table data
- * \param [rgba]Scale - RGBA scale factors
- * \param [rgba]Bias - RGBA bias factors
- */
-static void
-store_colortable_entries(struct gl_context *ctx, struct gl_color_table *table,
- GLsizei start, GLsizei count,
- GLenum format, GLenum type, const GLvoid *data,
- GLfloat rScale, GLfloat rBias,
- GLfloat gScale, GLfloat gBias,
- GLfloat bScale, GLfloat bBias,
- GLfloat aScale, GLfloat aBias)
-{
- data = _mesa_map_validate_pbo_source(ctx,
- 1, &ctx->Unpack, count, 1, 1,
- format, type, data,
- "glColor[Sub]Table");
- if (!data)
- return;
-
- {
- /* convert user-provided data to GLfloat values */
- GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];
- GLfloat *tableF;
- GLint i;
-
- _mesa_unpack_color_span_float(ctx,
- count, /* number of pixels */
- table->_BaseFormat, /* dest format */
- tempTab, /* dest address */
- format, type, /* src format/type */
- data, /* src data */
- &ctx->Unpack,
- IMAGE_CLAMP_BIT); /* transfer ops */
-
- /* the destination */
- tableF = table->TableF;
-
- /* Apply scale & bias & clamp now */
- switch (table->_BaseFormat) {
- case GL_INTENSITY:
- for (i = 0; i < count; i++) {
- GLuint j = start + i;
- tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
- }
- break;
- case GL_LUMINANCE:
- for (i = 0; i < count; i++) {
- GLuint j = start + i;
- tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
- }
- break;
- case GL_ALPHA:
- for (i = 0; i < count; i++) {
- GLuint j = start + i;
- tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F);
- }
- break;
- case GL_LUMINANCE_ALPHA:
- for (i = 0; i < count; i++) {
- GLuint j = start + i;
- tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F);
- tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F);
- }
- break;
- case GL_RGB:
- for (i = 0; i < count; i++) {
- GLuint j = start + i;
- tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F);
- tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F);
- tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F);
- }
- break;
- case GL_RGBA:
- for (i = 0; i < count; i++) {
- GLuint j = start + i;
- tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F);
- tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F);
- tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F);
- tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F);
- }
- break;
- default:
- _mesa_problem(ctx, "Bad format in store_colortable_entries");
- return;
- }
- }
-
- /* update the ubyte table */
- {
- const GLint comps = _mesa_components_in_format(table->_BaseFormat);
- const GLfloat *tableF = table->TableF + start * comps;
- GLubyte *tableUB = table->TableUB + start * comps;
- GLint i;
- for (i = 0; i < count * comps; i++) {
- CLAMPED_FLOAT_TO_UBYTE(tableUB[i], tableF[i]);
- }
- }
-
- _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
-}
-
-
-
-void GLAPIENTRY
-_mesa_ColorTable( GLenum target, GLenum internalFormat,
- GLsizei width, GLenum format, GLenum type,
- const GLvoid *data )
-{
- static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 };
- static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 };
- GET_CURRENT_CONTEXT(ctx);
- struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
- struct gl_texture_object *texObj = NULL;
- struct gl_color_table *table = NULL;
- GLboolean proxy = GL_FALSE;
- GLint baseFormat;
- const GLfloat *scale = one, *bias = zero;
- GLint comps;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
-
- switch (target) {
- case GL_SHARED_TEXTURE_PALETTE_EXT:
- table = &ctx->Texture.Palette;
- break;
- default:
- /* try texture targets */
- {
- struct gl_texture_object *texobj
- = _mesa_select_tex_object(ctx, texUnit, target);
- if (texobj) {
- table = &texobj->Palette;
- proxy = _mesa_is_proxy_texture(target);
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
- return;
- }
- }
- }
-
- assert(table);
-
- if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
- format == GL_INTENSITY) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)");
- return;
- }
-
- baseFormat = base_colortab_format(internalFormat);
- if (baseFormat < 0) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)");
- return;
- }
-
- if (width < 0 || (width != 0 && !_mesa_is_pow_two(width))) {
- /* error */
- if (proxy) {
- table->Size = 0;
- table->InternalFormat = (GLenum) 0;
- table->_BaseFormat = (GLenum) 0;
- }
- else {
- _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width);
- }
- return;
- }
-
- if (width > (GLsizei) ctx->Const.MaxColorTableSize) {
- if (proxy) {
- table->Size = 0;
- table->InternalFormat = (GLenum) 0;
- table->_BaseFormat = (GLenum) 0;
- }
- else {
- _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)");
- }
- return;
- }
-
- table->Size = width;
- table->InternalFormat = internalFormat;
- table->_BaseFormat = (GLenum) baseFormat;
-
- comps = _mesa_components_in_format(table->_BaseFormat);
- assert(comps > 0); /* error should have been caught sooner */
-
- if (!proxy) {
- _mesa_free_colortable_data(table);
-
- if (width > 0) {
- table->TableF = (GLfloat *) malloc(comps * width * sizeof(GLfloat));
- table->TableUB = (GLubyte *) malloc(comps * width * sizeof(GLubyte));
-
- if (!table->TableF || !table->TableUB) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
- return;
- }
-
- store_colortable_entries(ctx, table,
- 0, width, /* start, count */
- format, type, data,
- scale[0], bias[0],
- scale[1], bias[1],
- scale[2], bias[2],
- scale[3], bias[3]);
- }
- } /* proxy */
-
- /* do this after the table's Type and Format are set */
- set_component_sizes(table);
-
- if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
- /* texture object palette, texObj==NULL means the shared palette */
- if (ctx->Driver.UpdateTexturePalette) {
- (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
- }
- }
-
- ctx->NewState |= _NEW_PIXEL;
-}
-
-
-
-void GLAPIENTRY
-_mesa_ColorSubTable( GLenum target, GLsizei start,
- GLsizei count, GLenum format, GLenum type,
- const GLvoid *data )
-{
- static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 };
- static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 };
- GET_CURRENT_CONTEXT(ctx);
- struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
- struct gl_texture_object *texObj = NULL;
- struct gl_color_table *table = NULL;
- const GLfloat *scale = one, *bias = zero;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- switch (target) {
- case GL_SHARED_TEXTURE_PALETTE_EXT:
- table = &ctx->Texture.Palette;
- break;
- default:
- /* try texture targets */
- texObj = _mesa_select_tex_object(ctx, texUnit, target);
- if (texObj && !_mesa_is_proxy_texture(target)) {
- table = &texObj->Palette;
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
- return;
- }
- }
-
- assert(table);
-
- if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
- format == GL_INTENSITY) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)");
- return;
- }
-
- if (count < 1) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
- return;
- }
-
- /* error should have been caught sooner */
- assert(_mesa_components_in_format(table->_BaseFormat) > 0);
-
- if (start + count > (GLint) table->Size) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
- return;
- }
-
- if (!table->TableF || !table->TableUB) {
- /* a GL_OUT_OF_MEMORY error would have been recorded previously */
- return;
- }
-
- store_colortable_entries(ctx, table, start, count,
- format, type, data,
- scale[0], bias[0],
- scale[1], bias[1],
- scale[2], bias[2],
- scale[3], bias[3]);
-
- if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
- /* per-texture object palette */
- if (ctx->Driver.UpdateTexturePalette) {
- (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
- }
- }
-
- ctx->NewState |= _NEW_PIXEL;
-}
-
-
-
-static void GLAPIENTRY
-_mesa_CopyColorTable(GLenum target, GLenum internalformat,
- GLint x, GLint y, GLsizei width)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (!ctx->ReadBuffer->_ColorReadBuffer) {
- return; /* no readbuffer - OK */
- }
-
- ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width );
-}
-
-
-
-static void GLAPIENTRY
-_mesa_CopyColorSubTable(GLenum target, GLsizei start,
- GLint x, GLint y, GLsizei width)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (!ctx->ReadBuffer->_ColorReadBuffer) {
- return; /* no readbuffer - OK */
- }
-
- ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width );
-}
-
-
-
-static void GLAPIENTRY
-_mesa_GetColorTable( GLenum target, GLenum format,
- GLenum type, GLvoid *data )
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
- struct gl_color_table *table = NULL;
- GLfloat rgba[MAX_COLOR_TABLE_SIZE][4];
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (ctx->NewState) {
- _mesa_update_state(ctx);
- }
-
- switch (target) {
- case GL_SHARED_TEXTURE_PALETTE_EXT:
- table = &ctx->Texture.Palette;
- break;
- default:
- /* try texture targets */
- {
- struct gl_texture_object *texobj
- = _mesa_select_tex_object(ctx, texUnit, target);
- if (texobj && !_mesa_is_proxy_texture(target)) {
- table = &texobj->Palette;
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
- return;
- }
- }
- }
-
- ASSERT(table);
-
- if (table->Size <= 0) {
- return;
- }
-
- switch (table->_BaseFormat) {
- case GL_ALPHA:
- {
- GLuint i;
- for (i = 0; i < table->Size; i++) {
- rgba[i][RCOMP] = 0;
- rgba[i][GCOMP] = 0;
- rgba[i][BCOMP] = 0;
- rgba[i][ACOMP] = table->TableF[i];
- }
- }
- break;
- case GL_LUMINANCE:
- {
- GLuint i;
- for (i = 0; i < table->Size; i++) {
- rgba[i][RCOMP] =
- rgba[i][GCOMP] =
- rgba[i][BCOMP] = table->TableF[i];
- rgba[i][ACOMP] = 1.0F;
- }
- }
- break;
- case GL_LUMINANCE_ALPHA:
- {
- GLuint i;
- for (i = 0; i < table->Size; i++) {
- rgba[i][RCOMP] =
- rgba[i][GCOMP] =
- rgba[i][BCOMP] = table->TableF[i*2+0];
- rgba[i][ACOMP] = table->TableF[i*2+1];
- }
- }
- break;
- case GL_INTENSITY:
- {
- GLuint i;
- for (i = 0; i < table->Size; i++) {
- rgba[i][RCOMP] =
- rgba[i][GCOMP] =
- rgba[i][BCOMP] =
- rgba[i][ACOMP] = table->TableF[i];
- }
- }
- break;
- case GL_RGB:
- {
- GLuint i;
- for (i = 0; i < table->Size; i++) {
- rgba[i][RCOMP] = table->TableF[i*3+0];
- rgba[i][GCOMP] = table->TableF[i*3+1];
- rgba[i][BCOMP] = table->TableF[i*3+2];
- rgba[i][ACOMP] = 1.0F;
- }
- }
- break;
- case GL_RGBA:
- memcpy(rgba, table->TableF, 4 * table->Size * sizeof(GLfloat));
- break;
- default:
- _mesa_problem(ctx, "bad table format in glGetColorTable");
- return;
- }
-
- data = _mesa_map_validate_pbo_dest(ctx,
- 1, &ctx->Pack, table->Size, 1, 1,
- format, type, data,
- "glGetColorTable");
- if (!data)
- return;
-
- _mesa_pack_rgba_span_float(ctx, table->Size, rgba,
- format, type, data, &ctx->Pack, 0x0);
-
- _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
-}
-
-
-
-static void GLAPIENTRY
-_mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
-{
- /* no extensions use this function */
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(target)");
-}
-
-
-
-static void GLAPIENTRY
-_mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
-{
- /* no extensions use this function */
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameteriv(target)");
-}
-
-
-
-static void GLAPIENTRY
-_mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
- struct gl_color_table *table = NULL;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- switch (target) {
- case GL_SHARED_TEXTURE_PALETTE_EXT:
- table = &ctx->Texture.Palette;
- break;
- default:
- /* try texture targets */
- {
- struct gl_texture_object *texobj
- = _mesa_select_tex_object(ctx, texUnit, target);
- if (texobj) {
- table = &texobj->Palette;
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetColorTableParameterfv(target)");
- return;
- }
- }
- }
-
- assert(table);
-
- switch (pname) {
- case GL_COLOR_TABLE_FORMAT:
- *params = (GLfloat) table->InternalFormat;
- break;
- case GL_COLOR_TABLE_WIDTH:
- *params = (GLfloat) table->Size;
- break;
- case GL_COLOR_TABLE_RED_SIZE:
- *params = (GLfloat) table->RedSize;
- break;
- case GL_COLOR_TABLE_GREEN_SIZE:
- *params = (GLfloat) table->GreenSize;
- break;
- case GL_COLOR_TABLE_BLUE_SIZE:
- *params = (GLfloat) table->BlueSize;
- break;
- case GL_COLOR_TABLE_ALPHA_SIZE:
- *params = (GLfloat) table->AlphaSize;
- break;
- case GL_COLOR_TABLE_LUMINANCE_SIZE:
- *params = (GLfloat) table->LuminanceSize;
- break;
- case GL_COLOR_TABLE_INTENSITY_SIZE:
- *params = (GLfloat) table->IntensitySize;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" );
- return;
- }
-}
-
-
-
-static void GLAPIENTRY
-_mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
- struct gl_color_table *table = NULL;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- switch (target) {
- case GL_SHARED_TEXTURE_PALETTE_EXT:
- table = &ctx->Texture.Palette;
- break;
- default:
- /* Try texture targets */
- {
- struct gl_texture_object *texobj
- = _mesa_select_tex_object(ctx, texUnit, target);
- if (texobj) {
- table = &texobj->Palette;
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetColorTableParameteriv(target)");
- return;
- }
- }
- }
-
- assert(table);
-
- switch (pname) {
- case GL_COLOR_TABLE_FORMAT:
- *params = table->InternalFormat;
- break;
- case GL_COLOR_TABLE_WIDTH:
- *params = table->Size;
- break;
- case GL_COLOR_TABLE_RED_SIZE:
- *params = table->RedSize;
- break;
- case GL_COLOR_TABLE_GREEN_SIZE:
- *params = table->GreenSize;
- break;
- case GL_COLOR_TABLE_BLUE_SIZE:
- *params = table->BlueSize;
- break;
- case GL_COLOR_TABLE_ALPHA_SIZE:
- *params = table->AlphaSize;
- break;
- case GL_COLOR_TABLE_LUMINANCE_SIZE:
- *params = table->LuminanceSize;
- break;
- case GL_COLOR_TABLE_INTENSITY_SIZE:
- *params = table->IntensitySize;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" );
- return;
- }
-}
-
-
-void
-_mesa_init_colortable_dispatch(struct _glapi_table *disp)
-{
- SET_ColorSubTable(disp, _mesa_ColorSubTable);
- SET_ColorTable(disp, _mesa_ColorTable);
- SET_ColorTableParameterfv(disp, _mesa_ColorTableParameterfv);
- SET_ColorTableParameteriv(disp, _mesa_ColorTableParameteriv);
- SET_CopyColorSubTable(disp, _mesa_CopyColorSubTable);
- SET_CopyColorTable(disp, _mesa_CopyColorTable);
- SET_GetColorTable(disp, _mesa_GetColorTable);
- SET_GetColorTableParameterfv(disp, _mesa_GetColorTableParameterfv);
- SET_GetColorTableParameteriv(disp, _mesa_GetColorTableParameteriv);
-}
-
-
-#endif /* FEATURE_colortable */
-
-
-/**********************************************************************/
-/***** Initialization *****/
-/**********************************************************************/
-
-
-void
-_mesa_init_colortable( struct gl_color_table *p )
-{
- p->TableF = NULL;
- p->TableUB = NULL;
- p->Size = 0;
- p->InternalFormat = GL_RGBA;
-}
-
-
-
-void
-_mesa_free_colortable_data( struct gl_color_table *p )
-{
- if (p->TableF) {
- free(p->TableF);
- p->TableF = NULL;
- }
- if (p->TableUB) {
- free(p->TableUB);
- p->TableUB = NULL;
- }
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "glheader.h"
+#include "bufferobj.h"
+#include "colortab.h"
+#include "context.h"
+#include "image.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "pack.h"
+#include "pbo.h"
+#include "state.h"
+#include "teximage.h"
+#include "texstate.h"
+#include "main/dispatch.h"
+
+
+#if FEATURE_colortable
+
+
+/**
+ * Given an internalFormat token passed to glColorTable,
+ * return the corresponding base format.
+ * Return -1 if invalid token.
+ */
+static GLint
+base_colortab_format( GLenum format )
+{
+ switch (format) {
+ case GL_ALPHA:
+ case GL_ALPHA4:
+ case GL_ALPHA8:
+ case GL_ALPHA12:
+ case GL_ALPHA16:
+ return GL_ALPHA;
+ case GL_LUMINANCE:
+ case GL_LUMINANCE4:
+ case GL_LUMINANCE8:
+ case GL_LUMINANCE12:
+ case GL_LUMINANCE16:
+ return GL_LUMINANCE;
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE4_ALPHA4:
+ case GL_LUMINANCE6_ALPHA2:
+ case GL_LUMINANCE8_ALPHA8:
+ case GL_LUMINANCE12_ALPHA4:
+ case GL_LUMINANCE12_ALPHA12:
+ case GL_LUMINANCE16_ALPHA16:
+ return GL_LUMINANCE_ALPHA;
+ case GL_INTENSITY:
+ case GL_INTENSITY4:
+ case GL_INTENSITY8:
+ case GL_INTENSITY12:
+ case GL_INTENSITY16:
+ return GL_INTENSITY;
+ case GL_RGB:
+ case GL_R3_G3_B2:
+ case GL_RGB4:
+ case GL_RGB5:
+ case GL_RGB8:
+ case GL_RGB10:
+ case GL_RGB12:
+ case GL_RGB16:
+ return GL_RGB;
+ case GL_RGBA:
+ case GL_RGBA2:
+ case GL_RGBA4:
+ case GL_RGB5_A1:
+ case GL_RGBA8:
+ case GL_RGB10_A2:
+ case GL_RGBA12:
+ case GL_RGBA16:
+ return GL_RGBA;
+ default:
+ return -1; /* error */
+ }
+}
+
+
+
+/**
+ * Examine table's format and set the component sizes accordingly.
+ */
+static void
+set_component_sizes( struct gl_color_table *table )
+{
+ /* assuming the ubyte table */
+ const GLubyte sz = 8;
+
+ switch (table->_BaseFormat) {
+ case GL_ALPHA:
+ table->RedSize = 0;
+ table->GreenSize = 0;
+ table->BlueSize = 0;
+ table->AlphaSize = sz;
+ table->IntensitySize = 0;
+ table->LuminanceSize = 0;
+ break;
+ case GL_LUMINANCE:
+ table->RedSize = 0;
+ table->GreenSize = 0;
+ table->BlueSize = 0;
+ table->AlphaSize = 0;
+ table->IntensitySize = 0;
+ table->LuminanceSize = sz;
+ break;
+ case GL_LUMINANCE_ALPHA:
+ table->RedSize = 0;
+ table->GreenSize = 0;
+ table->BlueSize = 0;
+ table->AlphaSize = sz;
+ table->IntensitySize = 0;
+ table->LuminanceSize = sz;
+ break;
+ case GL_INTENSITY:
+ table->RedSize = 0;
+ table->GreenSize = 0;
+ table->BlueSize = 0;
+ table->AlphaSize = 0;
+ table->IntensitySize = sz;
+ table->LuminanceSize = 0;
+ break;
+ case GL_RGB:
+ table->RedSize = sz;
+ table->GreenSize = sz;
+ table->BlueSize = sz;
+ table->AlphaSize = 0;
+ table->IntensitySize = 0;
+ table->LuminanceSize = 0;
+ break;
+ case GL_RGBA:
+ table->RedSize = sz;
+ table->GreenSize = sz;
+ table->BlueSize = sz;
+ table->AlphaSize = sz;
+ table->IntensitySize = 0;
+ table->LuminanceSize = 0;
+ break;
+ default:
+ _mesa_problem(NULL, "unexpected format in set_component_sizes");
+ }
+}
+
+
+
+/**
+ * Update/replace all or part of a color table. Helper function
+ * used by _mesa_ColorTable() and _mesa_ColorSubTable().
+ * The table->Table buffer should already be allocated.
+ * \param start first entry to update
+ * \param count number of entries to update
+ * \param format format of user-provided table data
+ * \param type datatype of user-provided table data
+ * \param data user-provided table data
+ * \param [rgba]Scale - RGBA scale factors
+ * \param [rgba]Bias - RGBA bias factors
+ */
+static void
+store_colortable_entries(struct gl_context *ctx, struct gl_color_table *table,
+ GLsizei start, GLsizei count,
+ GLenum format, GLenum type, const GLvoid *data,
+ GLfloat rScale, GLfloat rBias,
+ GLfloat gScale, GLfloat gBias,
+ GLfloat bScale, GLfloat bBias,
+ GLfloat aScale, GLfloat aBias)
+{
+ data = _mesa_map_validate_pbo_source(ctx,
+ 1, &ctx->Unpack, count, 1, 1,
+ format, type, data,
+ "glColor[Sub]Table");
+ if (!data)
+ return;
+
+ {
+ /* convert user-provided data to GLfloat values */
+ GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];
+ GLfloat *tableF;
+ GLint i;
+
+ _mesa_unpack_color_span_float(ctx,
+ count, /* number of pixels */
+ table->_BaseFormat, /* dest format */
+ tempTab, /* dest address */
+ format, type, /* src format/type */
+ data, /* src data */
+ &ctx->Unpack,
+ IMAGE_CLAMP_BIT); /* transfer ops */
+
+ /* the destination */
+ tableF = table->TableF;
+
+ /* Apply scale & bias & clamp now */
+ switch (table->_BaseFormat) {
+ case GL_INTENSITY:
+ for (i = 0; i < count; i++) {
+ GLuint j = start + i;
+ tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
+ }
+ break;
+ case GL_LUMINANCE:
+ for (i = 0; i < count; i++) {
+ GLuint j = start + i;
+ tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
+ }
+ break;
+ case GL_ALPHA:
+ for (i = 0; i < count; i++) {
+ GLuint j = start + i;
+ tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F);
+ }
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i = 0; i < count; i++) {
+ GLuint j = start + i;
+ tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F);
+ tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F);
+ }
+ break;
+ case GL_RGB:
+ for (i = 0; i < count; i++) {
+ GLuint j = start + i;
+ tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F);
+ tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F);
+ tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F);
+ }
+ break;
+ case GL_RGBA:
+ for (i = 0; i < count; i++) {
+ GLuint j = start + i;
+ tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F);
+ tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F);
+ tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F);
+ tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F);
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "Bad format in store_colortable_entries");
+ return;
+ }
+ }
+
+ /* update the ubyte table */
+ {
+ const GLint comps = _mesa_components_in_format(table->_BaseFormat);
+ const GLfloat *tableF = table->TableF + start * comps;
+ GLubyte *tableUB = table->TableUB + start * comps;
+ GLint i;
+ for (i = 0; i < count * comps; i++) {
+ CLAMPED_FLOAT_TO_UBYTE(tableUB[i], tableF[i]);
+ }
+ }
+
+ _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
+}
+
+
+
+void GLAPIENTRY
+_mesa_ColorTable( GLenum target, GLenum internalFormat,
+ GLsizei width, GLenum format, GLenum type,
+ const GLvoid *data )
+{
+ static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 };
+ static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 };
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+ struct gl_texture_object *texObj = NULL;
+ struct gl_color_table *table = NULL;
+ GLboolean proxy = GL_FALSE;
+ GLint baseFormat;
+ const GLfloat *scale = one, *bias = zero;
+ GLint comps;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
+
+ switch (target) {
+ case GL_SHARED_TEXTURE_PALETTE_EXT:
+ table = &ctx->Texture.Palette;
+ break;
+ default:
+ /* try texture targets */
+ {
+ struct gl_texture_object *texobj
+ = _mesa_select_tex_object(ctx, texUnit, target);
+ if (texobj) {
+ table = &texobj->Palette;
+ proxy = _mesa_is_proxy_texture(target);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
+ return;
+ }
+ }
+ }
+
+ assert(table);
+
+ if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
+ format == GL_INTENSITY) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)");
+ return;
+ }
+
+ baseFormat = base_colortab_format(internalFormat);
+ if (baseFormat < 0) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)");
+ return;
+ }
+
+ if (width < 0 || (width != 0 && !_mesa_is_pow_two(width))) {
+ /* error */
+ if (proxy) {
+ table->Size = 0;
+ table->InternalFormat = (GLenum) 0;
+ table->_BaseFormat = (GLenum) 0;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width);
+ }
+ return;
+ }
+
+ if (width > (GLsizei) ctx->Const.MaxColorTableSize) {
+ if (proxy) {
+ table->Size = 0;
+ table->InternalFormat = (GLenum) 0;
+ table->_BaseFormat = (GLenum) 0;
+ }
+ else {
+ _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)");
+ }
+ return;
+ }
+
+ table->Size = width;
+ table->InternalFormat = internalFormat;
+ table->_BaseFormat = (GLenum) baseFormat;
+
+ comps = _mesa_components_in_format(table->_BaseFormat);
+ assert(comps > 0); /* error should have been caught sooner */
+
+ if (!proxy) {
+ _mesa_free_colortable_data(table);
+
+ if (width > 0) {
+ table->TableF = (GLfloat *) malloc(comps * width * sizeof(GLfloat));
+ table->TableUB = (GLubyte *) malloc(comps * width * sizeof(GLubyte));
+
+ if (!table->TableF || !table->TableUB) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
+ return;
+ }
+
+ store_colortable_entries(ctx, table,
+ 0, width, /* start, count */
+ format, type, data,
+ scale[0], bias[0],
+ scale[1], bias[1],
+ scale[2], bias[2],
+ scale[3], bias[3]);
+ }
+ } /* proxy */
+
+ /* do this after the table's Type and Format are set */
+ set_component_sizes(table);
+
+ if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
+ /* texture object palette, texObj==NULL means the shared palette */
+ if (ctx->Driver.UpdateTexturePalette) {
+ (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
+ }
+ }
+
+ ctx->NewState |= _NEW_PIXEL;
+}
+
+
+
+void GLAPIENTRY
+_mesa_ColorSubTable( GLenum target, GLsizei start,
+ GLsizei count, GLenum format, GLenum type,
+ const GLvoid *data )
+{
+ static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 };
+ static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 };
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+ struct gl_texture_object *texObj = NULL;
+ struct gl_color_table *table = NULL;
+ const GLfloat *scale = one, *bias = zero;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ switch (target) {
+ case GL_SHARED_TEXTURE_PALETTE_EXT:
+ table = &ctx->Texture.Palette;
+ break;
+ default:
+ /* try texture targets */
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ if (texObj && !_mesa_is_proxy_texture(target)) {
+ table = &texObj->Palette;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
+ return;
+ }
+ }
+
+ assert(table);
+
+ if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
+ format == GL_INTENSITY) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)");
+ return;
+ }
+
+ if (count < 1) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
+ return;
+ }
+
+ /* error should have been caught sooner */
+ assert(_mesa_components_in_format(table->_BaseFormat) > 0);
+
+ if (start + count > (GLint) table->Size) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
+ return;
+ }
+
+ if (!table->TableF || !table->TableUB) {
+ /* a GL_OUT_OF_MEMORY error would have been recorded previously */
+ return;
+ }
+
+ store_colortable_entries(ctx, table, start, count,
+ format, type, data,
+ scale[0], bias[0],
+ scale[1], bias[1],
+ scale[2], bias[2],
+ scale[3], bias[3]);
+
+ if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
+ /* per-texture object palette */
+ if (ctx->Driver.UpdateTexturePalette) {
+ (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
+ }
+ }
+
+ ctx->NewState |= _NEW_PIXEL;
+}
+
+
+
+static void GLAPIENTRY
+_mesa_CopyColorTable(GLenum target, GLenum internalformat,
+ GLint x, GLint y, GLsizei width)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (!ctx->ReadBuffer->_ColorReadBuffer) {
+ return; /* no readbuffer - OK */
+ }
+
+ ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width );
+}
+
+
+
+static void GLAPIENTRY
+_mesa_CopyColorSubTable(GLenum target, GLsizei start,
+ GLint x, GLint y, GLsizei width)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (!ctx->ReadBuffer->_ColorReadBuffer) {
+ return; /* no readbuffer - OK */
+ }
+
+ ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width );
+}
+
+
+
+static void GLAPIENTRY
+_mesa_GetColorTable( GLenum target, GLenum format,
+ GLenum type, GLvoid *data )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+ struct gl_color_table *table = NULL;
+ GLfloat rgba[MAX_COLOR_TABLE_SIZE][4];
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (ctx->NewState) {
+ _mesa_update_state(ctx);
+ }
+
+ switch (target) {
+ case GL_SHARED_TEXTURE_PALETTE_EXT:
+ table = &ctx->Texture.Palette;
+ break;
+ default:
+ /* try texture targets */
+ {
+ struct gl_texture_object *texobj
+ = _mesa_select_tex_object(ctx, texUnit, target);
+ if (texobj && !_mesa_is_proxy_texture(target)) {
+ table = &texobj->Palette;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
+ return;
+ }
+ }
+ }
+
+ ASSERT(table);
+
+ if (table->Size <= 0) {
+ return;
+ }
+
+ switch (table->_BaseFormat) {
+ case GL_ALPHA:
+ {
+ GLuint i;
+ for (i = 0; i < table->Size; i++) {
+ rgba[i][RCOMP] = 0;
+ rgba[i][GCOMP] = 0;
+ rgba[i][BCOMP] = 0;
+ rgba[i][ACOMP] = table->TableF[i];
+ }
+ }
+ break;
+ case GL_LUMINANCE:
+ {
+ GLuint i;
+ for (i = 0; i < table->Size; i++) {
+ rgba[i][RCOMP] =
+ rgba[i][GCOMP] =
+ rgba[i][BCOMP] = table->TableF[i];
+ rgba[i][ACOMP] = 1.0F;
+ }
+ }
+ break;
+ case GL_LUMINANCE_ALPHA:
+ {
+ GLuint i;
+ for (i = 0; i < table->Size; i++) {
+ rgba[i][RCOMP] =
+ rgba[i][GCOMP] =
+ rgba[i][BCOMP] = table->TableF[i*2+0];
+ rgba[i][ACOMP] = table->TableF[i*2+1];
+ }
+ }
+ break;
+ case GL_INTENSITY:
+ {
+ GLuint i;
+ for (i = 0; i < table->Size; i++) {
+ rgba[i][RCOMP] =
+ rgba[i][GCOMP] =
+ rgba[i][BCOMP] =
+ rgba[i][ACOMP] = table->TableF[i];
+ }
+ }
+ break;
+ case GL_RGB:
+ {
+ GLuint i;
+ for (i = 0; i < table->Size; i++) {
+ rgba[i][RCOMP] = table->TableF[i*3+0];
+ rgba[i][GCOMP] = table->TableF[i*3+1];
+ rgba[i][BCOMP] = table->TableF[i*3+2];
+ rgba[i][ACOMP] = 1.0F;
+ }
+ }
+ break;
+ case GL_RGBA:
+ memcpy(rgba, table->TableF, 4 * table->Size * sizeof(GLfloat));
+ break;
+ default:
+ _mesa_problem(ctx, "bad table format in glGetColorTable");
+ return;
+ }
+
+ data = _mesa_map_validate_pbo_dest(ctx,
+ 1, &ctx->Pack, table->Size, 1, 1,
+ format, type, data,
+ "glGetColorTable");
+ if (!data)
+ return;
+
+ _mesa_pack_rgba_span_float(ctx, table->Size, rgba,
+ format, type, data, &ctx->Pack, 0x0);
+
+ _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
+}
+
+
+
+static void GLAPIENTRY
+_mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
+{
+ /* no extensions use this function */
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+ _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(target)");
+}
+
+
+
+static void GLAPIENTRY
+_mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
+{
+ /* no extensions use this function */
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+ _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameteriv(target)");
+}
+
+
+
+static void GLAPIENTRY
+_mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+ struct gl_color_table *table = NULL;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ switch (target) {
+ case GL_SHARED_TEXTURE_PALETTE_EXT:
+ table = &ctx->Texture.Palette;
+ break;
+ default:
+ /* try texture targets */
+ {
+ struct gl_texture_object *texobj
+ = _mesa_select_tex_object(ctx, texUnit, target);
+ if (texobj) {
+ table = &texobj->Palette;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetColorTableParameterfv(target)");
+ return;
+ }
+ }
+ }
+
+ assert(table);
+
+ switch (pname) {
+ case GL_COLOR_TABLE_FORMAT:
+ *params = (GLfloat) table->InternalFormat;
+ break;
+ case GL_COLOR_TABLE_WIDTH:
+ *params = (GLfloat) table->Size;
+ break;
+ case GL_COLOR_TABLE_RED_SIZE:
+ *params = (GLfloat) table->RedSize;
+ break;
+ case GL_COLOR_TABLE_GREEN_SIZE:
+ *params = (GLfloat) table->GreenSize;
+ break;
+ case GL_COLOR_TABLE_BLUE_SIZE:
+ *params = (GLfloat) table->BlueSize;
+ break;
+ case GL_COLOR_TABLE_ALPHA_SIZE:
+ *params = (GLfloat) table->AlphaSize;
+ break;
+ case GL_COLOR_TABLE_LUMINANCE_SIZE:
+ *params = (GLfloat) table->LuminanceSize;
+ break;
+ case GL_COLOR_TABLE_INTENSITY_SIZE:
+ *params = (GLfloat) table->IntensitySize;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" );
+ return;
+ }
+}
+
+
+
+static void GLAPIENTRY
+_mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+ struct gl_color_table *table = NULL;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ switch (target) {
+ case GL_SHARED_TEXTURE_PALETTE_EXT:
+ table = &ctx->Texture.Palette;
+ break;
+ default:
+ /* Try texture targets */
+ {
+ struct gl_texture_object *texobj
+ = _mesa_select_tex_object(ctx, texUnit, target);
+ if (texobj) {
+ table = &texobj->Palette;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetColorTableParameteriv(target)");
+ return;
+ }
+ }
+ }
+
+ assert(table);
+
+ switch (pname) {
+ case GL_COLOR_TABLE_FORMAT:
+ *params = table->InternalFormat;
+ break;
+ case GL_COLOR_TABLE_WIDTH:
+ *params = table->Size;
+ break;
+ case GL_COLOR_TABLE_RED_SIZE:
+ *params = table->RedSize;
+ break;
+ case GL_COLOR_TABLE_GREEN_SIZE:
+ *params = table->GreenSize;
+ break;
+ case GL_COLOR_TABLE_BLUE_SIZE:
+ *params = table->BlueSize;
+ break;
+ case GL_COLOR_TABLE_ALPHA_SIZE:
+ *params = table->AlphaSize;
+ break;
+ case GL_COLOR_TABLE_LUMINANCE_SIZE:
+ *params = table->LuminanceSize;
+ break;
+ case GL_COLOR_TABLE_INTENSITY_SIZE:
+ *params = table->IntensitySize;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" );
+ return;
+ }
+}
+
+
+void
+_mesa_init_colortable_dispatch(struct _glapi_table *disp)
+{
+ SET_ColorSubTable(disp, _mesa_ColorSubTable);
+ SET_ColorTable(disp, _mesa_ColorTable);
+ SET_ColorTableParameterfv(disp, _mesa_ColorTableParameterfv);
+ SET_ColorTableParameteriv(disp, _mesa_ColorTableParameteriv);
+ SET_CopyColorSubTable(disp, _mesa_CopyColorSubTable);
+ SET_CopyColorTable(disp, _mesa_CopyColorTable);
+ SET_GetColorTable(disp, _mesa_GetColorTable);
+ SET_GetColorTableParameterfv(disp, _mesa_GetColorTableParameterfv);
+ SET_GetColorTableParameteriv(disp, _mesa_GetColorTableParameteriv);
+}
+
+
+#endif /* FEATURE_colortable */
+
+
+/**********************************************************************/
+/***** Initialization *****/
+/**********************************************************************/
+
+
+void
+_mesa_init_colortable( struct gl_color_table *p )
+{
+ p->TableF = NULL;
+ p->TableUB = NULL;
+ p->Size = 0;
+ p->InternalFormat = GL_RGBA;
+}
+
+
+
+void
+_mesa_free_colortable_data( struct gl_color_table *p )
+{
+ if (p->TableF) {
+ free(p->TableF);
+ p->TableF = NULL;
+ }
+ if (p->TableUB) {
+ free(p->TableUB);
+ p->TableUB = NULL;
+ }
+}
diff --git a/mesalib/src/mesa/main/compiler.h b/mesalib/src/mesa/main/compiler.h
index 41cd48bc6..c1d773b18 100644
--- a/mesalib/src/mesa/main/compiler.h
+++ b/mesalib/src/mesa/main/compiler.h
@@ -60,29 +60,7 @@ extern "C" {
/**
* Get standard integer types
*/
-#if defined(_MSC_VER)
- typedef __int8 int8_t;
- typedef unsigned __int8 uint8_t;
- typedef __int16 int16_t;
- typedef unsigned __int16 uint16_t;
- typedef __int32 int32_t;
- typedef unsigned __int32 uint32_t;
- typedef __int64 int64_t;
- typedef unsigned __int64 uint64_t;
-
-# if defined(_WIN64)
- typedef __int64 intptr_t;
- typedef unsigned __int64 uintptr_t;
-# else
- typedef __int32 intptr_t;
- typedef unsigned __int32 uintptr_t;
-# endif
-
-# define INT64_C(__val) __val##i64
-# define UINT64_C(__val) __val##ui64
-#else
-# include <stdint.h>
-#endif
+#include <stdint.h>
/**
diff --git a/mesalib/src/mesa/main/context.c b/mesalib/src/mesa/main/context.c
index a94231455..cfb6b348b 100644
--- a/mesalib/src/mesa/main/context.c
+++ b/mesalib/src/mesa/main/context.c
@@ -1,1882 +1,1882 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.3
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file context.c
- * Mesa context/visual/framebuffer management functions.
- * \author Brian Paul
- */
-
-/**
- * \mainpage Mesa Main Module
- *
- * \section MainIntroduction Introduction
- *
- * The Mesa Main module consists of all the files in the main/ directory.
- * Among the features of this module are:
- * <UL>
- * <LI> Structures to represent most GL state </LI>
- * <LI> State set/get functions </LI>
- * <LI> Display lists </LI>
- * <LI> Texture unit, object and image handling </LI>
- * <LI> Matrix and attribute stacks </LI>
- * </UL>
- *
- * Other modules are responsible for API dispatch, vertex transformation,
- * point/line/triangle setup, rasterization, vertex array caching,
- * vertex/fragment programs/shaders, etc.
- *
- *
- * \section AboutDoxygen About Doxygen
- *
- * If you're viewing this information as Doxygen-generated HTML you'll
- * see the documentation index at the top of this page.
- *
- * The first line lists the Mesa source code modules.
- * The second line lists the indexes available for viewing the documentation
- * for each module.
- *
- * Selecting the <b>Main page</b> link will display a summary of the module
- * (this page).
- *
- * Selecting <b>Data Structures</b> will list all C structures.
- *
- * Selecting the <b>File List</b> link will list all the source files in
- * the module.
- * Selecting a filename will show a list of all functions defined in that file.
- *
- * Selecting the <b>Data Fields</b> link will display a list of all
- * documented structure members.
- *
- * Selecting the <b>Globals</b> link will display a list
- * of all functions, structures, global variables and macros in the module.
- *
- */
-
-
-#include "glheader.h"
-#include "mfeatures.h"
-#include "imports.h"
-#include "accum.h"
-#include "api_exec.h"
-#include "arrayobj.h"
-#include "attrib.h"
-#include "blend.h"
-#include "buffers.h"
-#include "bufferobj.h"
-#include "context.h"
-#include "cpuinfo.h"
-#include "debug.h"
-#include "depth.h"
-#include "dlist.h"
-#include "eval.h"
-#include "extensions.h"
-#include "fbobject.h"
-#include "feedback.h"
-#include "fog.h"
-#include "formats.h"
-#include "framebuffer.h"
-#include "hint.h"
-#include "hash.h"
-#include "light.h"
-#include "lines.h"
-#include "macros.h"
-#include "matrix.h"
-#include "multisample.h"
-#include "pixel.h"
-#include "pixelstore.h"
-#include "points.h"
-#include "polygon.h"
-#include "queryobj.h"
-#include "syncobj.h"
-#include "rastpos.h"
-#include "remap.h"
-#include "scissor.h"
-#include "shared.h"
-#include "shaderobj.h"
-#include "simple_list.h"
-#include "state.h"
-#include "stencil.h"
-#include "texcompress_s3tc.h"
-#include "texstate.h"
-#include "transformfeedback.h"
-#include "mtypes.h"
-#include "varray.h"
-#include "version.h"
-#include "viewport.h"
-#include "vtxfmt.h"
-#include "program/program.h"
-#include "program/prog_print.h"
-#if _HAVE_FULL_GL
-#include "math/m_matrix.h"
-#endif
-#include "main/dispatch.h" /* for _gloffset_COUNT */
-
-#ifdef USE_SPARC_ASM
-#include "sparc/sparc.h"
-#endif
-
-#include "glsl_parser_extras.h"
-#include <stdbool.h>
-
-
-#ifndef MESA_VERBOSE
-int MESA_VERBOSE = 0;
-#endif
-
-#ifndef MESA_DEBUG_FLAGS
-int MESA_DEBUG_FLAGS = 0;
-#endif
-
-
-/* ubyte -> float conversion */
-GLfloat _mesa_ubyte_to_float_color_tab[256];
-
-
-
-/**
- * Swap buffers notification callback.
- *
- * \param ctx GL context.
- *
- * Called by window system just before swapping buffers.
- * We have to finish any pending rendering.
- */
-void
-_mesa_notifySwapBuffers(struct gl_context *ctx)
-{
- if (MESA_VERBOSE & VERBOSE_SWAPBUFFERS)
- _mesa_debug(ctx, "SwapBuffers\n");
- FLUSH_CURRENT( ctx, 0 );
- if (ctx->Driver.Flush) {
- ctx->Driver.Flush(ctx);
- }
-}
-
-
-/**********************************************************************/
-/** \name GL Visual allocation/destruction */
-/**********************************************************************/
-/*@{*/
-
-/**
- * Allocates a struct gl_config structure and initializes it via
- * _mesa_initialize_visual().
- *
- * \param dbFlag double buffering
- * \param stereoFlag stereo buffer
- * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
- * is acceptable but the actual depth type will be GLushort or GLuint as
- * needed.
- * \param stencilBits requested minimum bits per stencil buffer value
- * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
- * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
- * \param redBits number of bits per color component in frame buffer for RGB(A)
- * mode. We always use 8 in core Mesa though.
- * \param greenBits same as above.
- * \param blueBits same as above.
- * \param alphaBits same as above.
- * \param numSamples not really used.
- *
- * \return pointer to new struct gl_config or NULL if requested parameters can't be
- * met.
- *
- * \note Need to add params for level and numAuxBuffers (at least)
- */
-struct gl_config *
-_mesa_create_visual( GLboolean dbFlag,
- GLboolean stereoFlag,
- GLint redBits,
- GLint greenBits,
- GLint blueBits,
- GLint alphaBits,
- GLint depthBits,
- GLint stencilBits,
- GLint accumRedBits,
- GLint accumGreenBits,
- GLint accumBlueBits,
- GLint accumAlphaBits,
- GLint numSamples )
-{
- struct gl_config *vis = CALLOC_STRUCT(gl_config);
- if (vis) {
- if (!_mesa_initialize_visual(vis, dbFlag, stereoFlag,
- redBits, greenBits, blueBits, alphaBits,
- depthBits, stencilBits,
- accumRedBits, accumGreenBits,
- accumBlueBits, accumAlphaBits,
- numSamples)) {
- free(vis);
- return NULL;
- }
- }
- return vis;
-}
-
-
-/**
- * Makes some sanity checks and fills in the fields of the struct
- * gl_config object with the given parameters. If the caller needs to
- * set additional fields, he should just probably init the whole
- * gl_config object himself.
- *
- * \return GL_TRUE on success, or GL_FALSE on failure.
- *
- * \sa _mesa_create_visual() above for the parameter description.
- */
-GLboolean
-_mesa_initialize_visual( struct gl_config *vis,
- GLboolean dbFlag,
- GLboolean stereoFlag,
- GLint redBits,
- GLint greenBits,
- GLint blueBits,
- GLint alphaBits,
- GLint depthBits,
- GLint stencilBits,
- GLint accumRedBits,
- GLint accumGreenBits,
- GLint accumBlueBits,
- GLint accumAlphaBits,
- GLint numSamples )
-{
- assert(vis);
-
- if (depthBits < 0 || depthBits > 32) {
- return GL_FALSE;
- }
- if (stencilBits < 0 || stencilBits > STENCIL_BITS) {
- return GL_FALSE;
- }
- assert(accumRedBits >= 0);
- assert(accumGreenBits >= 0);
- assert(accumBlueBits >= 0);
- assert(accumAlphaBits >= 0);
-
- vis->rgbMode = GL_TRUE;
- vis->doubleBufferMode = dbFlag;
- vis->stereoMode = stereoFlag;
-
- vis->redBits = redBits;
- vis->greenBits = greenBits;
- vis->blueBits = blueBits;
- vis->alphaBits = alphaBits;
- vis->rgbBits = redBits + greenBits + blueBits;
-
- vis->indexBits = 0;
- vis->depthBits = depthBits;
- vis->stencilBits = stencilBits;
-
- vis->accumRedBits = accumRedBits;
- vis->accumGreenBits = accumGreenBits;
- vis->accumBlueBits = accumBlueBits;
- vis->accumAlphaBits = accumAlphaBits;
-
- vis->haveAccumBuffer = accumRedBits > 0;
- vis->haveDepthBuffer = depthBits > 0;
- vis->haveStencilBuffer = stencilBits > 0;
-
- vis->numAuxBuffers = 0;
- vis->level = 0;
- vis->sampleBuffers = numSamples > 0 ? 1 : 0;
- vis->samples = numSamples;
-
- return GL_TRUE;
-}
-
-
-/**
- * Destroy a visual and free its memory.
- *
- * \param vis visual.
- *
- * Frees the visual structure.
- */
-void
-_mesa_destroy_visual( struct gl_config *vis )
-{
- free(vis);
-}
-
-/*@}*/
-
-
-/**********************************************************************/
-/** \name Context allocation, initialization, destroying
- *
- * The purpose of the most initialization functions here is to provide the
- * default state values according to the OpenGL specification.
- */
-/**********************************************************************/
-/*@{*/
-
-
-/**
- * This is lame. gdb only seems to recognize enum types that are
- * actually used somewhere. We want to be able to print/use enum
- * values such as TEXTURE_2D_INDEX in gdb. But we don't actually use
- * the gl_texture_index type anywhere. Thus, this lame function.
- */
-static void
-dummy_enum_func(void)
-{
- gl_buffer_index bi = BUFFER_FRONT_LEFT;
- gl_face_index fi = FACE_POS_X;
- gl_frag_attrib fa = FRAG_ATTRIB_WPOS;
- gl_frag_result fr = FRAG_RESULT_DEPTH;
- gl_texture_index ti = TEXTURE_2D_ARRAY_INDEX;
- gl_vert_attrib va = VERT_ATTRIB_POS;
- gl_vert_result vr = VERT_RESULT_HPOS;
- gl_geom_attrib ga = GEOM_ATTRIB_POSITION;
- gl_geom_result gr = GEOM_RESULT_POS;
-
- (void) bi;
- (void) fi;
- (void) fa;
- (void) fr;
- (void) ti;
- (void) va;
- (void) vr;
- (void) ga;
- (void) gr;
-}
-
-
-/**
- * One-time initialization mutex lock.
- *
- * \sa Used by one_time_init().
- */
-_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
-
-
-
-/**
- * Calls all the various one-time-init functions in Mesa.
- *
- * While holding a global mutex lock, calls several initialization functions,
- * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
- * defined.
- *
- * \sa _math_init().
- */
-static void
-one_time_init( struct gl_context *ctx )
-{
- static GLbitfield api_init_mask = 0x0;
-
- _glthread_LOCK_MUTEX(OneTimeLock);
-
- /* truly one-time init */
- if (!api_init_mask) {
- GLuint i;
-
- /* do some implementation tests */
- assert( sizeof(GLbyte) == 1 );
- assert( sizeof(GLubyte) == 1 );
- assert( sizeof(GLshort) == 2 );
- assert( sizeof(GLushort) == 2 );
- assert( sizeof(GLint) == 4 );
- assert( sizeof(GLuint) == 4 );
-
- _mesa_get_cpu_features();
-
- _mesa_init_sqrt_table();
-
- /* context dependence is never a one-time thing... */
- _mesa_init_get_hash(ctx);
-
- for (i = 0; i < 256; i++) {
- _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
- }
-
-#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
- if (MESA_VERBOSE != 0) {
- _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
- MESA_VERSION_STRING, __DATE__, __TIME__);
- }
-#endif
-
-#ifdef DEBUG
- _mesa_test_formats();
-#endif
- }
-
- /* per-API one-time init */
- if (!(api_init_mask & (1 << ctx->API))) {
- /*
- * This is fine as ES does not use the remap table, but it may not be
- * future-proof. We cannot always initialize the remap table because
- * when an app is linked to libGLES*, there are not enough dynamic
- * entries.
- */
- if (ctx->API == API_OPENGL)
- _mesa_init_remap_table();
- }
-
- api_init_mask |= 1 << ctx->API;
-
- _glthread_UNLOCK_MUTEX(OneTimeLock);
-
- /* Hopefully atexit() is widely available. If not, we may need some
- * #ifdef tests here.
- */
- atexit(_mesa_destroy_shader_compiler);
-
- dummy_enum_func();
-}
-
-
-/**
- * Initialize fields of gl_current_attrib (aka ctx->Current.*)
- */
-static void
-_mesa_init_current(struct gl_context *ctx)
-{
- GLuint i;
-
- /* Init all to (0,0,0,1) */
- for (i = 0; i < Elements(ctx->Current.Attrib); i++) {
- ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
- }
-
- /* redo special cases: */
- ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 0.0 );
- ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
- ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
- ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
- ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX], 1.0, 0.0, 0.0, 1.0 );
- ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG], 1.0, 0.0, 0.0, 1.0 );
-}
-
-
-/**
- * Init vertex/fragment/geometry program limits.
- * Important: drivers should override these with actual limits.
- */
-static void
-init_program_limits(GLenum type, struct gl_program_constants *prog)
-{
- prog->MaxInstructions = MAX_PROGRAM_INSTRUCTIONS;
- prog->MaxAluInstructions = MAX_PROGRAM_INSTRUCTIONS;
- prog->MaxTexInstructions = MAX_PROGRAM_INSTRUCTIONS;
- prog->MaxTexIndirections = MAX_PROGRAM_INSTRUCTIONS;
- prog->MaxTemps = MAX_PROGRAM_TEMPS;
- prog->MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
- prog->MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
- prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
-
- switch (type) {
- case GL_VERTEX_PROGRAM_ARB:
- prog->MaxParameters = MAX_VERTEX_PROGRAM_PARAMS;
- prog->MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
- prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
- break;
- case GL_FRAGMENT_PROGRAM_ARB:
- prog->MaxParameters = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
- prog->MaxAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
- prog->MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
- break;
- case MESA_GEOMETRY_PROGRAM:
- prog->MaxParameters = MAX_NV_VERTEX_PROGRAM_PARAMS;
- prog->MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
- prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
-
- prog->MaxGeometryTextureImageUnits = MAX_GEOMETRY_TEXTURE_IMAGE_UNITS;
- prog->MaxGeometryVaryingComponents = MAX_GEOMETRY_VARYING_COMPONENTS;
- prog->MaxVertexVaryingComponents = MAX_VERTEX_VARYING_COMPONENTS;
- prog->MaxGeometryUniformComponents = MAX_GEOMETRY_UNIFORM_COMPONENTS;
- prog->MaxGeometryOutputVertices = MAX_GEOMETRY_OUTPUT_VERTICES;
- prog->MaxGeometryTotalOutputComponents = MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS;
- break;
- default:
- assert(0 && "Bad program type in init_program_limits()");
- }
-
- /* Set the native limits to zero. This implies that there is no native
- * support for shaders. Let the drivers fill in the actual values.
- */
- prog->MaxNativeInstructions = 0;
- prog->MaxNativeAluInstructions = 0;
- prog->MaxNativeTexInstructions = 0;
- prog->MaxNativeTexIndirections = 0;
- prog->MaxNativeAttribs = 0;
- prog->MaxNativeTemps = 0;
- prog->MaxNativeAddressRegs = 0;
- prog->MaxNativeParameters = 0;
-
- /* Set GLSL datatype range/precision info assuming IEEE float values.
- * Drivers should override these defaults as needed.
- */
- prog->MediumFloat.RangeMin = 127;
- prog->MediumFloat.RangeMax = 127;
- prog->MediumFloat.Precision = 23;
- prog->LowFloat = prog->HighFloat = prog->MediumFloat;
-
- /* Assume ints are stored as floats for now, since this is the least-common
- * denominator. The OpenGL ES spec implies (page 132) that the precision
- * of integer types should be 0. Practically speaking, IEEE
- * single-precision floating point values can only store integers in the
- * range [-0x01000000, 0x01000000] without loss of precision.
- */
- prog->MediumInt.RangeMin = 24;
- prog->MediumInt.RangeMax = 24;
- prog->MediumInt.Precision = 0;
- prog->LowInt = prog->HighInt = prog->MediumInt;
-}
-
-
-/**
- * Initialize fields of gl_constants (aka ctx->Const.*).
- * Use defaults from config.h. The device drivers will often override
- * some of these values (such as number of texture units).
- */
-static void
-_mesa_init_constants(struct gl_context *ctx)
-{
- assert(ctx);
-
- /* Constants, may be overriden (usually only reduced) by device drivers */
- ctx->Const.MaxTextureMbytes = MAX_TEXTURE_MBYTES;
- ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
- ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
- ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
- ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
- ctx->Const.MaxArrayTextureLayers = MAX_ARRAY_TEXTURE_LAYERS;
- ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
- ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
- ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
- ctx->Const.MaxTextureImageUnits);
- ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
- ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
- ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
- ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
- ctx->Const.MinPointSize = MIN_POINT_SIZE;
- ctx->Const.MaxPointSize = MAX_POINT_SIZE;
- ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
- ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
- ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
- ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
- ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
- ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
- ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
- ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
- ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
- ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
- ctx->Const.MaxLights = MAX_LIGHTS;
- ctx->Const.MaxShininess = 128.0;
- ctx->Const.MaxSpotExponent = 128.0;
- ctx->Const.MaxViewportWidth = MAX_WIDTH;
- ctx->Const.MaxViewportHeight = MAX_HEIGHT;
-#if FEATURE_ARB_vertex_program
- init_program_limits(GL_VERTEX_PROGRAM_ARB, &ctx->Const.VertexProgram);
-#endif
-#if FEATURE_ARB_fragment_program
- init_program_limits(GL_FRAGMENT_PROGRAM_ARB, &ctx->Const.FragmentProgram);
-#endif
-#if FEATURE_ARB_geometry_shader4
- init_program_limits(MESA_GEOMETRY_PROGRAM, &ctx->Const.GeometryProgram);
-#endif
- ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
- ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
-
- /* CheckArrayBounds is overriden by drivers/x11 for X server */
- ctx->Const.CheckArrayBounds = GL_FALSE;
-
- /* GL_ARB_draw_buffers */
- ctx->Const.MaxDrawBuffers = MAX_DRAW_BUFFERS;
-
-#if FEATURE_EXT_framebuffer_object
- ctx->Const.MaxColorAttachments = MAX_COLOR_ATTACHMENTS;
- ctx->Const.MaxRenderbufferSize = MAX_WIDTH;
-#endif
-
-#if FEATURE_ARB_vertex_shader
- ctx->Const.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS;
- ctx->Const.MaxCombinedTextureImageUnits = MAX_COMBINED_TEXTURE_IMAGE_UNITS;
- ctx->Const.MaxVarying = MAX_VARYING;
-#endif
-
- /* Shading language version */
- if (ctx->API == API_OPENGL) {
- ctx->Const.GLSLVersion = 120;
- }
- else if (ctx->API == API_OPENGLES2) {
- ctx->Const.GLSLVersion = 100;
- }
- else if (ctx->API == API_OPENGLES) {
- ctx->Const.GLSLVersion = 0; /* GLSL not supported */
- }
-
- /* GL_ARB_framebuffer_object */
- ctx->Const.MaxSamples = 0;
-
- /* GL_ARB_sync */
- ctx->Const.MaxServerWaitTimeout = (GLuint64) ~0;
-
- /* GL_ATI_envmap_bumpmap */
- ctx->Const.SupportedBumpUnits = SUPPORTED_ATI_BUMP_UNITS;
-
- /* GL_EXT_provoking_vertex */
- ctx->Const.QuadsFollowProvokingVertexConvention = GL_TRUE;
-
- /* GL_EXT_transform_feedback */
- ctx->Const.MaxTransformFeedbackSeparateAttribs = MAX_FEEDBACK_ATTRIBS;
- ctx->Const.MaxTransformFeedbackSeparateComponents = 4 * MAX_FEEDBACK_ATTRIBS;
- ctx->Const.MaxTransformFeedbackInterleavedComponents = 4 * MAX_FEEDBACK_ATTRIBS;
-
- /* GL 3.2: hard-coded for now: */
- ctx->Const.ProfileMask = GL_CONTEXT_COMPATIBILITY_PROFILE_BIT;
-
- /** GL_EXT_gpu_shader4 */
- ctx->Const.MinProgramTexelOffset = -8;
- ctx->Const.MaxProgramTexelOffset = 7;
-}
-
-
-/**
- * Do some sanity checks on the limits/constants for the given context.
- * Only called the first time a context is bound.
- */
-static void
-check_context_limits(struct gl_context *ctx)
-{
- /* check that we don't exceed the size of various bitfields */
- assert(VERT_RESULT_MAX <=
- (8 * sizeof(ctx->VertexProgram._Current->Base.OutputsWritten)));
- assert(FRAG_ATTRIB_MAX <=
- (8 * sizeof(ctx->FragmentProgram._Current->Base.InputsRead)));
-
- assert(MAX_COMBINED_TEXTURE_IMAGE_UNITS <= 8 * sizeof(GLbitfield));
-
- /* shader-related checks */
- assert(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
- assert(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
-
- assert(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
- assert(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
- assert(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX);
- assert(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX);
-
- /* Texture unit checks */
- assert(ctx->Const.MaxTextureImageUnits > 0);
- assert(ctx->Const.MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS);
- assert(ctx->Const.MaxTextureCoordUnits > 0);
- assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS);
- assert(ctx->Const.MaxTextureUnits > 0);
- assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
- assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
- assert(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
- ctx->Const.MaxTextureCoordUnits));
- assert(ctx->Const.MaxCombinedTextureImageUnits > 0);
- assert(ctx->Const.MaxCombinedTextureImageUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
- assert(ctx->Const.MaxTextureCoordUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
- /* number of coord units cannot be greater than number of image units */
- assert(ctx->Const.MaxTextureCoordUnits <= ctx->Const.MaxTextureImageUnits);
-
-
- /* Texture size checks */
- assert(ctx->Const.MaxTextureLevels <= MAX_TEXTURE_LEVELS);
- assert(ctx->Const.Max3DTextureLevels <= MAX_3D_TEXTURE_LEVELS);
- assert(ctx->Const.MaxCubeTextureLevels <= MAX_CUBE_TEXTURE_LEVELS);
- assert(ctx->Const.MaxTextureRectSize <= MAX_TEXTURE_RECT_SIZE);
-
- /* make sure largest texture image is <= MAX_WIDTH in size */
- assert((1 << (ctx->Const.MaxTextureLevels - 1)) <= MAX_WIDTH);
- assert((1 << (ctx->Const.MaxCubeTextureLevels - 1)) <= MAX_WIDTH);
- assert((1 << (ctx->Const.Max3DTextureLevels - 1)) <= MAX_WIDTH);
-
- /* Texture level checks */
- assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
- assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
-
- /* Max texture size should be <= max viewport size (render to texture) */
- assert((1 << (MAX_TEXTURE_LEVELS - 1)) <= MAX_WIDTH);
-
- assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
- assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
-
- assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
-
- /* if this fails, add more enum values to gl_buffer_index */
- assert(BUFFER_COLOR0 + MAX_DRAW_BUFFERS <= BUFFER_COUNT);
-
- /* XXX probably add more tests */
-}
-
-
-/**
- * Initialize the attribute groups in a GL context.
- *
- * \param ctx GL context.
- *
- * Initializes all the attributes, calling the respective <tt>init*</tt>
- * functions for the more complex data structures.
- */
-static GLboolean
-init_attrib_groups(struct gl_context *ctx)
-{
- assert(ctx);
-
- /* Constants */
- _mesa_init_constants( ctx );
-
- /* Extensions */
- _mesa_init_extensions( ctx );
-
- /* Attribute Groups */
- _mesa_init_accum( ctx );
- _mesa_init_attrib( ctx );
- _mesa_init_buffer_objects( ctx );
- _mesa_init_color( ctx );
- _mesa_init_current( ctx );
- _mesa_init_depth( ctx );
- _mesa_init_debug( ctx );
- _mesa_init_display_list( ctx );
- _mesa_init_eval( ctx );
- _mesa_init_fbobjects( ctx );
- _mesa_init_feedback( ctx );
- _mesa_init_fog( ctx );
- _mesa_init_hint( ctx );
- _mesa_init_line( ctx );
- _mesa_init_lighting( ctx );
- _mesa_init_matrix( ctx );
- _mesa_init_multisample( ctx );
- _mesa_init_pixel( ctx );
- _mesa_init_pixelstore( ctx );
- _mesa_init_point( ctx );
- _mesa_init_polygon( ctx );
- _mesa_init_program( ctx );
- _mesa_init_queryobj( ctx );
- _mesa_init_sync( ctx );
- _mesa_init_rastpos( ctx );
- _mesa_init_scissor( ctx );
- _mesa_init_shader_state( ctx );
- _mesa_init_stencil( ctx );
- _mesa_init_transform( ctx );
- _mesa_init_transform_feedback( ctx );
- _mesa_init_varray( ctx );
- _mesa_init_viewport( ctx );
-
- if (!_mesa_init_texture( ctx ))
- return GL_FALSE;
-
- _mesa_init_texture_s3tc( ctx );
-
- /* Miscellaneous */
- ctx->NewState = _NEW_ALL;
- ctx->ErrorValue = (GLenum) GL_NO_ERROR;
- ctx->varying_vp_inputs = ~0;
-
- return GL_TRUE;
-}
-
-
-/**
- * Update default objects in a GL context with respect to shared state.
- *
- * \param ctx GL context.
- *
- * Removes references to old default objects, (texture objects, program
- * objects, etc.) and changes to reference those from the current shared
- * state.
- */
-static GLboolean
-update_default_objects(struct gl_context *ctx)
-{
- assert(ctx);
-
- _mesa_update_default_objects_program(ctx);
- _mesa_update_default_objects_texture(ctx);
- _mesa_update_default_objects_buffer_objects(ctx);
-
- return GL_TRUE;
-}
-
-
-/**
- * This is the default function we plug into all dispatch table slots
- * This helps prevents a segfault when someone calls a GL function without
- * first checking if the extension's supported.
- */
-static int
-generic_nop(void)
-{
- _mesa_warning(NULL, "User called no-op dispatch function (an unsupported extension function?)");
- return 0;
-}
-
-
-/**
- * Allocate and initialize a new dispatch table.
- */
-struct _glapi_table *
-_mesa_alloc_dispatch_table(int size)
-{
- /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
- * In practice, this'll be the same for stand-alone Mesa. But for DRI
- * Mesa we do this to accomodate different versions of libGL and various
- * DRI drivers.
- */
- GLint numEntries = MAX2(_glapi_get_dispatch_table_size(), _gloffset_COUNT);
- struct _glapi_table *table;
-
- /* should never happen, but just in case */
- numEntries = MAX2(numEntries, size);
-
- table = (struct _glapi_table *) malloc(numEntries * sizeof(_glapi_proc));
- if (table) {
- _glapi_proc *entry = (_glapi_proc *) table;
- GLint i;
- for (i = 0; i < numEntries; i++) {
- entry[i] = (_glapi_proc) generic_nop;
- }
- }
- return table;
-}
-
-
-/**
- * Initialize a struct gl_context struct (rendering context).
- *
- * This includes allocating all the other structs and arrays which hang off of
- * the context by pointers.
- * Note that the driver needs to pass in its dd_function_table here since
- * we need to at least call driverFunctions->NewTextureObject to create the
- * default texture objects.
- *
- * Called by _mesa_create_context().
- *
- * Performs the imports and exports callback tables initialization, and
- * miscellaneous one-time initializations. If no shared context is supplied one
- * is allocated, and increase its reference count. Setups the GL API dispatch
- * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
- * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
- * for debug flags.
- *
- * \param ctx the context to initialize
- * \param api the GL API type to create the context for
- * \param visual describes the visual attributes for this context
- * \param share_list points to context to share textures, display lists,
- * etc with, or NULL
- * \param driverFunctions table of device driver functions for this context
- * to use
- * \param driverContext pointer to driver-specific context data
- */
-GLboolean
-_mesa_initialize_context(struct gl_context *ctx,
- gl_api api,
- const struct gl_config *visual,
- struct gl_context *share_list,
- const struct dd_function_table *driverFunctions,
- void *driverContext)
-{
- struct gl_shared_state *shared;
- int i;
-
- /*ASSERT(driverContext);*/
- assert(driverFunctions->NewTextureObject);
- assert(driverFunctions->FreeTexImageData);
-
- ctx->API = api;
- ctx->Visual = *visual;
- ctx->DrawBuffer = NULL;
- ctx->ReadBuffer = NULL;
- ctx->WinSysDrawBuffer = NULL;
- ctx->WinSysReadBuffer = NULL;
-
- /* misc one-time initializations */
- one_time_init(ctx);
-
- /* Plug in driver functions and context pointer here.
- * This is important because when we call alloc_shared_state() below
- * we'll call ctx->Driver.NewTextureObject() to create the default
- * textures.
- */
- ctx->Driver = *driverFunctions;
- ctx->DriverCtx = driverContext;
-
- if (share_list) {
- /* share state with another context */
- shared = share_list->Shared;
- }
- else {
- /* allocate new, unshared state */
- shared = _mesa_alloc_shared_state(ctx);
- if (!shared)
- return GL_FALSE;
- }
-
- _glthread_LOCK_MUTEX(shared->Mutex);
- ctx->Shared = shared;
- shared->RefCount++;
- _glthread_UNLOCK_MUTEX(shared->Mutex);
-
- if (!init_attrib_groups( ctx )) {
- _mesa_release_shared_state(ctx, ctx->Shared);
- return GL_FALSE;
- }
-
-#if FEATURE_dispatch
- /* setup the API dispatch tables */
- switch (ctx->API) {
-#if FEATURE_GL
- case API_OPENGL:
- ctx->Exec = _mesa_create_exec_table();
- break;
-#endif
-#if FEATURE_ES1
- case API_OPENGLES:
- ctx->Exec = _mesa_create_exec_table_es1();
- break;
-#endif
-#if FEATURE_ES2
- case API_OPENGLES2:
- ctx->Exec = _mesa_create_exec_table_es2();
- break;
-#endif
- default:
- _mesa_problem(ctx, "unknown or unsupported API");
- break;
- }
-
- if (!ctx->Exec) {
- _mesa_release_shared_state(ctx, ctx->Shared);
- return GL_FALSE;
- }
-#endif
- ctx->CurrentDispatch = ctx->Exec;
-
- ctx->FragmentProgram._MaintainTexEnvProgram
- = (_mesa_getenv("MESA_TEX_PROG") != NULL);
-
- ctx->VertexProgram._MaintainTnlProgram
- = (_mesa_getenv("MESA_TNL_PROG") != NULL);
- if (ctx->VertexProgram._MaintainTnlProgram) {
- /* this is required... */
- ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
- }
-
- /* Mesa core handles all the formats that mesa core knows about.
- * Drivers will want to override this list with just the formats
- * they can handle, and confirm that appropriate fallbacks exist in
- * _mesa_choose_tex_format().
- */
- memset(&ctx->TextureFormatSupported, GL_TRUE,
- sizeof(ctx->TextureFormatSupported));
-
- switch (ctx->API) {
- case API_OPENGL:
-#if FEATURE_dlist
- ctx->Save = _mesa_create_save_table();
- if (!ctx->Save) {
- _mesa_release_shared_state(ctx, ctx->Shared);
- free(ctx->Exec);
- return GL_FALSE;
- }
-
- _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
-#endif
- break;
- case API_OPENGLES:
- /**
- * GL_OES_texture_cube_map says
- * "Initially all texture generation modes are set to REFLECTION_MAP_OES"
- */
- for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
- texUnit->GenS.Mode = GL_REFLECTION_MAP_NV;
- texUnit->GenT.Mode = GL_REFLECTION_MAP_NV;
- texUnit->GenR.Mode = GL_REFLECTION_MAP_NV;
- texUnit->GenS._ModeBit = TEXGEN_REFLECTION_MAP_NV;
- texUnit->GenT._ModeBit = TEXGEN_REFLECTION_MAP_NV;
- texUnit->GenR._ModeBit = TEXGEN_REFLECTION_MAP_NV;
- }
- break;
- case API_OPENGLES2:
- ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
- ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
- ctx->Point.PointSprite = GL_TRUE; /* always on for ES 2.x */
- break;
- }
-
- ctx->FirstTimeCurrent = GL_TRUE;
-
- return GL_TRUE;
-}
-
-
-/**
- * Allocate and initialize a struct gl_context structure.
- * Note that the driver needs to pass in its dd_function_table here since
- * we need to at least call driverFunctions->NewTextureObject to initialize
- * the rendering context.
- *
- * \param api the GL API type to create the context for
- * \param visual a struct gl_config pointer (we copy the struct contents)
- * \param share_list another context to share display lists with or NULL
- * \param driverFunctions points to the dd_function_table into which the
- * driver has plugged in all its special functions.
- * \param driverContext points to the device driver's private context state
- *
- * \return pointer to a new __struct gl_contextRec or NULL if error.
- */
-struct gl_context *
-_mesa_create_context(gl_api api,
- const struct gl_config *visual,
- struct gl_context *share_list,
- const struct dd_function_table *driverFunctions,
- void *driverContext)
-{
- struct gl_context *ctx;
-
- ASSERT(visual);
- /*ASSERT(driverContext);*/
-
- ctx = (struct gl_context *) calloc(1, sizeof(struct gl_context));
- if (!ctx)
- return NULL;
-
- if (_mesa_initialize_context(ctx, api, visual, share_list,
- driverFunctions, driverContext)) {
- return ctx;
- }
- else {
- free(ctx);
- return NULL;
- }
-}
-
-
-/**
- * Free the data associated with the given context.
- *
- * But doesn't free the struct gl_context struct itself.
- *
- * \sa _mesa_initialize_context() and init_attrib_groups().
- */
-void
-_mesa_free_context_data( struct gl_context *ctx )
-{
- if (!_mesa_get_current_context()){
- /* No current context, but we may need one in order to delete
- * texture objs, etc. So temporarily bind the context now.
- */
- _mesa_make_current(ctx, NULL, NULL);
- }
-
- /* unreference WinSysDraw/Read buffers */
- _mesa_reference_framebuffer(&ctx->WinSysDrawBuffer, NULL);
- _mesa_reference_framebuffer(&ctx->WinSysReadBuffer, NULL);
- _mesa_reference_framebuffer(&ctx->DrawBuffer, NULL);
- _mesa_reference_framebuffer(&ctx->ReadBuffer, NULL);
-
- _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
- _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
- _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
-
- _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL);
- _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
- _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
-
- _mesa_free_attrib_data(ctx);
- _mesa_free_buffer_objects(ctx);
- _mesa_free_lighting_data( ctx );
- _mesa_free_eval_data( ctx );
- _mesa_free_texture_data( ctx );
- _mesa_free_matrix_data( ctx );
- _mesa_free_viewport_data( ctx );
- _mesa_free_program_data(ctx);
- _mesa_free_shader_state(ctx);
- _mesa_free_queryobj_data(ctx);
- _mesa_free_sync_data(ctx);
- _mesa_free_varray_data(ctx);
- _mesa_free_transform_feedback(ctx);
-
- _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
-
-#if FEATURE_ARB_pixel_buffer_object
- _mesa_reference_buffer_object(ctx, &ctx->Pack.BufferObj, NULL);
- _mesa_reference_buffer_object(ctx, &ctx->Unpack.BufferObj, NULL);
- _mesa_reference_buffer_object(ctx, &ctx->DefaultPacking.BufferObj, NULL);
-#endif
-
-#if FEATURE_ARB_vertex_buffer_object
- _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, NULL);
- _mesa_reference_buffer_object(ctx, &ctx->Array.ElementArrayBufferObj, NULL);
-#endif
-
- /* free dispatch tables */
- free(ctx->Exec);
- free(ctx->Save);
-
- /* Shared context state (display lists, textures, etc) */
- _mesa_release_shared_state( ctx, ctx->Shared );
-
- /* needs to be after freeing shared state */
- _mesa_free_display_list_data(ctx);
-
- if (ctx->Extensions.String)
- free((void *) ctx->Extensions.String);
-
- if (ctx->VersionString)
- free(ctx->VersionString);
-
- /* unbind the context if it's currently bound */
- if (ctx == _mesa_get_current_context()) {
- _mesa_make_current(NULL, NULL, NULL);
- }
-}
-
-
-/**
- * Destroy a struct gl_context structure.
- *
- * \param ctx GL context.
- *
- * Calls _mesa_free_context_data() and frees the gl_context object itself.
- */
-void
-_mesa_destroy_context( struct gl_context *ctx )
-{
- if (ctx) {
- _mesa_free_context_data(ctx);
- free( (void *) ctx );
- }
-}
-
-
-#if _HAVE_FULL_GL
-/**
- * Copy attribute groups from one context to another.
- *
- * \param src source context
- * \param dst destination context
- * \param mask bitwise OR of GL_*_BIT flags
- *
- * According to the bits specified in \p mask, copies the corresponding
- * attributes from \p src into \p dst. For many of the attributes a simple \c
- * memcpy is not enough due to the existence of internal pointers in their data
- * structures.
- */
-void
-_mesa_copy_context( const struct gl_context *src, struct gl_context *dst, GLuint mask )
-{
- if (mask & GL_ACCUM_BUFFER_BIT) {
- /* OK to memcpy */
- dst->Accum = src->Accum;
- }
- if (mask & GL_COLOR_BUFFER_BIT) {
- /* OK to memcpy */
- dst->Color = src->Color;
- }
- if (mask & GL_CURRENT_BIT) {
- /* OK to memcpy */
- dst->Current = src->Current;
- }
- if (mask & GL_DEPTH_BUFFER_BIT) {
- /* OK to memcpy */
- dst->Depth = src->Depth;
- }
- if (mask & GL_ENABLE_BIT) {
- /* no op */
- }
- if (mask & GL_EVAL_BIT) {
- /* OK to memcpy */
- dst->Eval = src->Eval;
- }
- if (mask & GL_FOG_BIT) {
- /* OK to memcpy */
- dst->Fog = src->Fog;
- }
- if (mask & GL_HINT_BIT) {
- /* OK to memcpy */
- dst->Hint = src->Hint;
- }
- if (mask & GL_LIGHTING_BIT) {
- GLuint i;
- /* begin with memcpy */
- dst->Light = src->Light;
- /* fixup linked lists to prevent pointer insanity */
- make_empty_list( &(dst->Light.EnabledList) );
- for (i = 0; i < MAX_LIGHTS; i++) {
- if (dst->Light.Light[i].Enabled) {
- insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
- }
- }
- }
- if (mask & GL_LINE_BIT) {
- /* OK to memcpy */
- dst->Line = src->Line;
- }
- if (mask & GL_LIST_BIT) {
- /* OK to memcpy */
- dst->List = src->List;
- }
- if (mask & GL_PIXEL_MODE_BIT) {
- /* OK to memcpy */
- dst->Pixel = src->Pixel;
- }
- if (mask & GL_POINT_BIT) {
- /* OK to memcpy */
- dst->Point = src->Point;
- }
- if (mask & GL_POLYGON_BIT) {
- /* OK to memcpy */
- dst->Polygon = src->Polygon;
- }
- if (mask & GL_POLYGON_STIPPLE_BIT) {
- /* Use loop instead of memcpy due to problem with Portland Group's
- * C compiler. Reported by John Stone.
- */
- GLuint i;
- for (i = 0; i < 32; i++) {
- dst->PolygonStipple[i] = src->PolygonStipple[i];
- }
- }
- if (mask & GL_SCISSOR_BIT) {
- /* OK to memcpy */
- dst->Scissor = src->Scissor;
- }
- if (mask & GL_STENCIL_BUFFER_BIT) {
- /* OK to memcpy */
- dst->Stencil = src->Stencil;
- }
- if (mask & GL_TEXTURE_BIT) {
- /* Cannot memcpy because of pointers */
- _mesa_copy_texture_state(src, dst);
- }
- if (mask & GL_TRANSFORM_BIT) {
- /* OK to memcpy */
- dst->Transform = src->Transform;
- }
- if (mask & GL_VIEWPORT_BIT) {
- /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
- dst->Viewport.X = src->Viewport.X;
- dst->Viewport.Y = src->Viewport.Y;
- dst->Viewport.Width = src->Viewport.Width;
- dst->Viewport.Height = src->Viewport.Height;
- dst->Viewport.Near = src->Viewport.Near;
- dst->Viewport.Far = src->Viewport.Far;
- _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
- }
-
- /* XXX FIXME: Call callbacks?
- */
- dst->NewState = _NEW_ALL;
-}
-#endif
-
-
-/**
- * Check if the given context can render into the given framebuffer
- * by checking visual attributes.
- *
- * Most of these tests could go away because Mesa is now pretty flexible
- * in terms of mixing rendering contexts with framebuffers. As long
- * as RGB vs. CI mode agree, we're probably good.
- *
- * \return GL_TRUE if compatible, GL_FALSE otherwise.
- */
-static GLboolean
-check_compatible(const struct gl_context *ctx,
- const struct gl_framebuffer *buffer)
-{
- const struct gl_config *ctxvis = &ctx->Visual;
- const struct gl_config *bufvis = &buffer->Visual;
-
- if (buffer == _mesa_get_incomplete_framebuffer())
- return GL_TRUE;
-
-#if 0
- /* disabling this fixes the fgl_glxgears pbuffer demo */
- if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
- return GL_FALSE;
-#endif
- if (ctxvis->stereoMode && !bufvis->stereoMode)
- return GL_FALSE;
- if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
- return GL_FALSE;
- if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
- return GL_FALSE;
- if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
- return GL_FALSE;
- if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
- return GL_FALSE;
- if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
- return GL_FALSE;
- if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
- return GL_FALSE;
-#if 0
- /* disabled (see bug 11161) */
- if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
- return GL_FALSE;
-#endif
- if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
- return GL_FALSE;
-
- return GL_TRUE;
-}
-
-
-/**
- * Do one-time initialization for the given framebuffer. Specifically,
- * ask the driver for the window's current size and update the framebuffer
- * object to match.
- * Really, the device driver should totally take care of this.
- */
-static void
-initialize_framebuffer_size(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
- GLuint width, height;
- if (ctx->Driver.GetBufferSize) {
- ctx->Driver.GetBufferSize(fb, &width, &height);
- if (ctx->Driver.ResizeBuffers)
- ctx->Driver.ResizeBuffers(ctx, fb, width, height);
- fb->Initialized = GL_TRUE;
- }
-}
-
-
-/**
- * Check if the viewport/scissor size has not yet been initialized.
- * Initialize the size if the given width and height are non-zero.
- */
-void
-_mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height)
-{
- if (!ctx->ViewportInitialized && width > 0 && height > 0) {
- /* Note: set flag here, before calling _mesa_set_viewport(), to prevent
- * potential infinite recursion.
- */
- ctx->ViewportInitialized = GL_TRUE;
- _mesa_set_viewport(ctx, 0, 0, width, height);
- _mesa_set_scissor(ctx, 0, 0, width, height);
- }
-}
-
-
-/**
- * Bind the given context to the given drawBuffer and readBuffer and
- * make it the current context for the calling thread.
- * We'll render into the drawBuffer and read pixels from the
- * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc).
- *
- * We check that the context's and framebuffer's visuals are compatible
- * and return immediately if they're not.
- *
- * \param newCtx the new GL context. If NULL then there will be no current GL
- * context.
- * \param drawBuffer the drawing framebuffer
- * \param readBuffer the reading framebuffer
- */
-GLboolean
-_mesa_make_current( struct gl_context *newCtx,
- struct gl_framebuffer *drawBuffer,
- struct gl_framebuffer *readBuffer )
-{
- GET_CURRENT_CONTEXT(curCtx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(newCtx, "_mesa_make_current()\n");
-
- /* Check that the context's and framebuffer's visuals are compatible.
- */
- if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) {
- if (!check_compatible(newCtx, drawBuffer)) {
- _mesa_warning(newCtx,
- "MakeCurrent: incompatible visuals for context and drawbuffer");
- return GL_FALSE;
- }
- }
- if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) {
- if (!check_compatible(newCtx, readBuffer)) {
- _mesa_warning(newCtx,
- "MakeCurrent: incompatible visuals for context and readbuffer");
- return GL_FALSE;
- }
- }
-
- if (curCtx &&
- (curCtx->WinSysDrawBuffer || curCtx->WinSysReadBuffer) && /* make sure this context is valid for flushing */
- curCtx != newCtx)
- _mesa_flush(curCtx);
-
- /* We used to call _glapi_check_multithread() here. Now do it in drivers */
- _glapi_set_context((void *) newCtx);
- ASSERT(_mesa_get_current_context() == newCtx);
-
- if (!newCtx) {
- _glapi_set_dispatch(NULL); /* none current */
- }
- else {
- _glapi_set_dispatch(newCtx->CurrentDispatch);
-
- if (drawBuffer && readBuffer) {
- /* TODO: check if newCtx and buffer's visual match??? */
-
- ASSERT(drawBuffer->Name == 0);
- ASSERT(readBuffer->Name == 0);
- _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer);
- _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer);
-
- /*
- * Only set the context's Draw/ReadBuffer fields if they're NULL
- * or not bound to a user-created FBO.
- */
- if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
- /* KW: merge conflict here, revisit.
- */
- /* fix up the fb fields - these will end up wrong otherwise
- * if the DRIdrawable changes, and everything relies on them.
- * This is a bit messy (same as needed in _mesa_BindFramebufferEXT)
- */
- unsigned int i;
- GLenum buffers[MAX_DRAW_BUFFERS];
-
- _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer);
-
- for(i = 0; i < newCtx->Const.MaxDrawBuffers; i++) {
- buffers[i] = newCtx->Color.DrawBuffer[i];
- }
-
- _mesa_drawbuffers(newCtx, newCtx->Const.MaxDrawBuffers,
- buffers, NULL);
- }
- if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) {
- _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
- }
-
- /* XXX only set this flag if we're really changing the draw/read
- * framebuffer bindings.
- */
- newCtx->NewState |= _NEW_BUFFERS;
-
-#if 1
- /* We want to get rid of these lines: */
-
-#if _HAVE_FULL_GL
- if (!drawBuffer->Initialized) {
- initialize_framebuffer_size(newCtx, drawBuffer);
- }
- if (readBuffer != drawBuffer && !readBuffer->Initialized) {
- initialize_framebuffer_size(newCtx, readBuffer);
- }
-
- _mesa_resizebuffers(newCtx);
-#endif
-
-#else
- /* We want the drawBuffer and readBuffer to be initialized by
- * the driver.
- * This generally means the Width and Height match the actual
- * window size and the renderbuffers (both hardware and software
- * based) are allocated to match. The later can generally be
- * done with a call to _mesa_resize_framebuffer().
- *
- * It's theoretically possible for a buffer to have zero width
- * or height, but for now, assert check that the driver did what's
- * expected of it.
- */
- ASSERT(drawBuffer->Width > 0);
- ASSERT(drawBuffer->Height > 0);
-#endif
-
- if (drawBuffer) {
- _mesa_check_init_viewport(newCtx,
- drawBuffer->Width, drawBuffer->Height);
- }
- }
-
- if (newCtx->FirstTimeCurrent) {
- _mesa_compute_version(newCtx);
-
- newCtx->Extensions.String = _mesa_make_extension_string(newCtx);
-
- check_context_limits(newCtx);
-
- /* We can use this to help debug user's problems. Tell them to set
- * the MESA_INFO env variable before running their app. Then the
- * first time each context is made current we'll print some useful
- * information.
- */
- if (_mesa_getenv("MESA_INFO")) {
- _mesa_print_info();
- }
-
- newCtx->FirstTimeCurrent = GL_FALSE;
- }
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Make context 'ctx' share the display lists, textures and programs
- * that are associated with 'ctxToShare'.
- * Any display lists, textures or programs associated with 'ctx' will
- * be deleted if nobody else is sharing them.
- */
-GLboolean
-_mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare)
-{
- if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
- struct gl_shared_state *oldSharedState = ctx->Shared;
-
- ctx->Shared = ctxToShare->Shared;
-
- _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
- ctx->Shared->RefCount++;
- _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
-
- update_default_objects(ctx);
-
- _mesa_release_shared_state(ctx, oldSharedState);
-
- return GL_TRUE;
- }
- else {
- return GL_FALSE;
- }
-}
-
-
-
-/**
- * \return pointer to the current GL context for this thread.
- *
- * Calls _glapi_get_context(). This isn't the fastest way to get the current
- * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in
- * context.h.
- */
-struct gl_context *
-_mesa_get_current_context( void )
-{
- return (struct gl_context *) _glapi_get_context();
-}
-
-
-/**
- * Get context's current API dispatch table.
- *
- * It'll either be the immediate-mode execute dispatcher or the display list
- * compile dispatcher.
- *
- * \param ctx GL context.
- *
- * \return pointer to dispatch_table.
- *
- * Simply returns __struct gl_contextRec::CurrentDispatch.
- */
-struct _glapi_table *
-_mesa_get_dispatch(struct gl_context *ctx)
-{
- return ctx->CurrentDispatch;
-}
-
-/*@}*/
-
-
-/**********************************************************************/
-/** \name Miscellaneous functions */
-/**********************************************************************/
-/*@{*/
-
-/**
- * Record an error.
- *
- * \param ctx GL context.
- * \param error error code.
- *
- * Records the given error code and call the driver's dd_function_table::Error
- * function if defined.
- *
- * \sa
- * This is called via _mesa_error().
- */
-void
-_mesa_record_error(struct gl_context *ctx, GLenum error)
-{
- if (!ctx)
- return;
-
- if (ctx->ErrorValue == GL_NO_ERROR) {
- ctx->ErrorValue = error;
- }
-
- /* Call device driver's error handler, if any. This is used on the Mac. */
- if (ctx->Driver.Error) {
- ctx->Driver.Error(ctx);
- }
-}
-
-
-/**
- * Flush commands and wait for completion.
- */
-void
-_mesa_finish(struct gl_context *ctx)
-{
- FLUSH_CURRENT( ctx, 0 );
- if (ctx->Driver.Finish) {
- ctx->Driver.Finish(ctx);
- }
-}
-
-
-/**
- * Flush commands.
- */
-void
-_mesa_flush(struct gl_context *ctx)
-{
- FLUSH_CURRENT( ctx, 0 );
- if (ctx->Driver.Flush) {
- ctx->Driver.Flush(ctx);
- }
-}
-
-
-
-/**
- * Execute glFinish().
- *
- * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
- * dd_function_table::Finish driver callback, if not NULL.
- */
-void GLAPIENTRY
-_mesa_Finish(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- _mesa_finish(ctx);
-}
-
-
-/**
- * Execute glFlush().
- *
- * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
- * dd_function_table::Flush driver callback, if not NULL.
- */
-void GLAPIENTRY
-_mesa_Flush(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- _mesa_flush(ctx);
-}
-
-
-/**
- * Set mvp_with_dp4 flag. If a driver has a preference for DP4 over
- * MUL/MAD, or vice versa, call this function to register that.
- * Otherwise we default to MUL/MAD.
- */
-void
-_mesa_set_mvp_with_dp4( struct gl_context *ctx,
- GLboolean flag )
-{
- ctx->mvp_with_dp4 = flag;
-}
-
-
-
-/**
- * Prior to drawing anything with glBegin, glDrawArrays, etc. this function
- * is called to see if it's valid to render. This involves checking that
- * the current shader is valid and the framebuffer is complete.
- * If an error is detected it'll be recorded here.
- * \return GL_TRUE if OK to render, GL_FALSE if not
- */
-GLboolean
-_mesa_valid_to_render(struct gl_context *ctx, const char *where)
-{
- bool vert_from_glsl_shader = false;
- bool geom_from_glsl_shader = false;
- bool frag_from_glsl_shader = false;
-
- /* This depends on having up to date derived state (shaders) */
- if (ctx->NewState)
- _mesa_update_state(ctx);
-
- if (ctx->Shader.CurrentVertexProgram) {
- vert_from_glsl_shader = true;
-
- if (!ctx->Shader.CurrentVertexProgram->LinkStatus) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(shader not linked)", where);
- return GL_FALSE;
- }
-#if 0 /* not normally enabled */
- {
- char errMsg[100];
- if (!_mesa_validate_shader_program(ctx,
- ctx->Shader.CurrentVertexProgram,
- errMsg)) {
- _mesa_warning(ctx, "Shader program %u is invalid: %s",
- ctx->Shader.CurrentVertexProgram->Name, errMsg);
- }
- }
-#endif
- }
-
- if (ctx->Shader.CurrentGeometryProgram) {
- geom_from_glsl_shader = true;
-
- if (!ctx->Shader.CurrentGeometryProgram->LinkStatus) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(shader not linked)", where);
- return GL_FALSE;
- }
-#if 0 /* not normally enabled */
- {
- char errMsg[100];
- if (!_mesa_validate_shader_program(ctx,
- ctx->Shader.CurrentGeometryProgram,
- errMsg)) {
- _mesa_warning(ctx, "Shader program %u is invalid: %s",
- ctx->Shader.CurrentGeometryProgram->Name, errMsg);
- }
- }
-#endif
- }
-
- if (ctx->Shader.CurrentFragmentProgram) {
- frag_from_glsl_shader = true;
-
- if (!ctx->Shader.CurrentFragmentProgram->LinkStatus) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(shader not linked)", where);
- return GL_FALSE;
- }
-#if 0 /* not normally enabled */
- {
- char errMsg[100];
- if (!_mesa_validate_shader_program(ctx,
- ctx->Shader.CurrentFragmentProgram,
- errMsg)) {
- _mesa_warning(ctx, "Shader program %u is invalid: %s",
- ctx->Shader.CurrentFragmentProgram->Name, errMsg);
- }
- }
-#endif
- }
-
- /* Any shader stages that are not supplied by the GLSL shader and have
- * assembly shaders enabled must now be validated.
- */
- if (!vert_from_glsl_shader
- && ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(vertex program not valid)", where);
- return GL_FALSE;
- }
-
- /* FINISHME: If GL_NV_geometry_program4 is ever supported, the current
- * FINISHME: geometry program should validated here.
- */
- (void) geom_from_glsl_shader;
-
- if (!frag_from_glsl_shader) {
- if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(fragment program not valid)", where);
- return GL_FALSE;
- }
-
- /* If drawing to integer-valued color buffers, there must be an
- * active fragment shader (GL_EXT_texture_integer).
- */
- if (ctx->DrawBuffer && ctx->DrawBuffer->_IntegerColor) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(integer format but no fragment shader)", where);
- return GL_FALSE;
- }
- }
-
- if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
- "%s(incomplete framebuffer)", where);
- return GL_FALSE;
- }
-
-#ifdef DEBUG
- if (ctx->Shader.Flags & GLSL_LOG) {
- struct gl_shader_program *shProg[MESA_SHADER_TYPES];
- gl_shader_type i;
-
- shProg[MESA_SHADER_VERTEX] = ctx->Shader.CurrentVertexProgram;
- shProg[MESA_SHADER_GEOMETRY] = ctx->Shader.CurrentGeometryProgram;
- shProg[MESA_SHADER_FRAGMENT] = ctx->Shader.CurrentFragmentProgram;
-
- for (i = 0; i < MESA_SHADER_TYPES; i++) {
- struct gl_shader *sh;
-
- if (shProg[i] == NULL || shProg[i]->_Used
- || shProg[i]->_LinkedShaders[i] == NULL)
- continue;
-
- /* This is the first time this shader is being used.
- * Append shader's constants/uniforms to log file.
- *
- * The logic is a little odd here. We only want to log data for each
- * shader target that will actually be used, and we only want to log
- * it once. It's possible to have a program bound to the vertex
- * shader target that also supplied a fragment shader. If that
- * program isn't also bound to the fragment shader target we don't
- * want to log its fragment data.
- */
- sh = shProg[i]->_LinkedShaders[i];
- switch (sh->Type) {
- case GL_VERTEX_SHADER:
- _mesa_append_uniforms_to_file(sh, &shProg[i]->VertexProgram->Base);
- break;
-
- case GL_GEOMETRY_SHADER_ARB:
- _mesa_append_uniforms_to_file(sh,
- &shProg[i]->GeometryProgram->Base);
- break;
-
- case GL_FRAGMENT_SHADER:
- _mesa_append_uniforms_to_file(sh,
- &shProg[i]->FragmentProgram->Base);
- break;
- }
- }
-
- for (i = 0; i < MESA_SHADER_TYPES; i++) {
- if (shProg[i] != NULL)
- shProg[i]->_Used = GL_TRUE;
- }
- }
-#endif
-
- return GL_TRUE;
-}
-
-
-/*@}*/
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.3
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file context.c
+ * Mesa context/visual/framebuffer management functions.
+ * \author Brian Paul
+ */
+
+/**
+ * \mainpage Mesa Main Module
+ *
+ * \section MainIntroduction Introduction
+ *
+ * The Mesa Main module consists of all the files in the main/ directory.
+ * Among the features of this module are:
+ * <UL>
+ * <LI> Structures to represent most GL state </LI>
+ * <LI> State set/get functions </LI>
+ * <LI> Display lists </LI>
+ * <LI> Texture unit, object and image handling </LI>
+ * <LI> Matrix and attribute stacks </LI>
+ * </UL>
+ *
+ * Other modules are responsible for API dispatch, vertex transformation,
+ * point/line/triangle setup, rasterization, vertex array caching,
+ * vertex/fragment programs/shaders, etc.
+ *
+ *
+ * \section AboutDoxygen About Doxygen
+ *
+ * If you're viewing this information as Doxygen-generated HTML you'll
+ * see the documentation index at the top of this page.
+ *
+ * The first line lists the Mesa source code modules.
+ * The second line lists the indexes available for viewing the documentation
+ * for each module.
+ *
+ * Selecting the <b>Main page</b> link will display a summary of the module
+ * (this page).
+ *
+ * Selecting <b>Data Structures</b> will list all C structures.
+ *
+ * Selecting the <b>File List</b> link will list all the source files in
+ * the module.
+ * Selecting a filename will show a list of all functions defined in that file.
+ *
+ * Selecting the <b>Data Fields</b> link will display a list of all
+ * documented structure members.
+ *
+ * Selecting the <b>Globals</b> link will display a list
+ * of all functions, structures, global variables and macros in the module.
+ *
+ */
+
+
+#include "glheader.h"
+#include "mfeatures.h"
+#include "imports.h"
+#include "accum.h"
+#include "api_exec.h"
+#include "arrayobj.h"
+#include "attrib.h"
+#include "blend.h"
+#include "buffers.h"
+#include "bufferobj.h"
+#include "context.h"
+#include "cpuinfo.h"
+#include "debug.h"
+#include "depth.h"
+#include "dlist.h"
+#include "eval.h"
+#include "extensions.h"
+#include "fbobject.h"
+#include "feedback.h"
+#include "fog.h"
+#include "formats.h"
+#include "framebuffer.h"
+#include "hint.h"
+#include "hash.h"
+#include "light.h"
+#include "lines.h"
+#include "macros.h"
+#include "matrix.h"
+#include "multisample.h"
+#include "pixel.h"
+#include "pixelstore.h"
+#include "points.h"
+#include "polygon.h"
+#include "queryobj.h"
+#include "syncobj.h"
+#include "rastpos.h"
+#include "remap.h"
+#include "scissor.h"
+#include "shared.h"
+#include "shaderobj.h"
+#include "simple_list.h"
+#include "state.h"
+#include "stencil.h"
+#include "texcompress_s3tc.h"
+#include "texstate.h"
+#include "transformfeedback.h"
+#include "mtypes.h"
+#include "varray.h"
+#include "version.h"
+#include "viewport.h"
+#include "vtxfmt.h"
+#include "program/program.h"
+#include "program/prog_print.h"
+#if _HAVE_FULL_GL
+#include "math/m_matrix.h"
+#endif
+#include "main/dispatch.h" /* for _gloffset_COUNT */
+
+#ifdef USE_SPARC_ASM
+#include "sparc/sparc.h"
+#endif
+
+#include "glsl_parser_extras.h"
+#include <stdbool.h>
+
+
+#ifndef MESA_VERBOSE
+int MESA_VERBOSE = 0;
+#endif
+
+#ifndef MESA_DEBUG_FLAGS
+int MESA_DEBUG_FLAGS = 0;
+#endif
+
+
+/* ubyte -> float conversion */
+GLfloat _mesa_ubyte_to_float_color_tab[256];
+
+
+
+/**
+ * Swap buffers notification callback.
+ *
+ * \param ctx GL context.
+ *
+ * Called by window system just before swapping buffers.
+ * We have to finish any pending rendering.
+ */
+void
+_mesa_notifySwapBuffers(struct gl_context *ctx)
+{
+ if (MESA_VERBOSE & VERBOSE_SWAPBUFFERS)
+ _mesa_debug(ctx, "SwapBuffers\n");
+ FLUSH_CURRENT( ctx, 0 );
+ if (ctx->Driver.Flush) {
+ ctx->Driver.Flush(ctx);
+ }
+}
+
+
+/**********************************************************************/
+/** \name GL Visual allocation/destruction */
+/**********************************************************************/
+/*@{*/
+
+/**
+ * Allocates a struct gl_config structure and initializes it via
+ * _mesa_initialize_visual().
+ *
+ * \param dbFlag double buffering
+ * \param stereoFlag stereo buffer
+ * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
+ * is acceptable but the actual depth type will be GLushort or GLuint as
+ * needed.
+ * \param stencilBits requested minimum bits per stencil buffer value
+ * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
+ * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
+ * \param redBits number of bits per color component in frame buffer for RGB(A)
+ * mode. We always use 8 in core Mesa though.
+ * \param greenBits same as above.
+ * \param blueBits same as above.
+ * \param alphaBits same as above.
+ * \param numSamples not really used.
+ *
+ * \return pointer to new struct gl_config or NULL if requested parameters can't be
+ * met.
+ *
+ * \note Need to add params for level and numAuxBuffers (at least)
+ */
+struct gl_config *
+_mesa_create_visual( GLboolean dbFlag,
+ GLboolean stereoFlag,
+ GLint redBits,
+ GLint greenBits,
+ GLint blueBits,
+ GLint alphaBits,
+ GLint depthBits,
+ GLint stencilBits,
+ GLint accumRedBits,
+ GLint accumGreenBits,
+ GLint accumBlueBits,
+ GLint accumAlphaBits,
+ GLint numSamples )
+{
+ struct gl_config *vis = CALLOC_STRUCT(gl_config);
+ if (vis) {
+ if (!_mesa_initialize_visual(vis, dbFlag, stereoFlag,
+ redBits, greenBits, blueBits, alphaBits,
+ depthBits, stencilBits,
+ accumRedBits, accumGreenBits,
+ accumBlueBits, accumAlphaBits,
+ numSamples)) {
+ free(vis);
+ return NULL;
+ }
+ }
+ return vis;
+}
+
+
+/**
+ * Makes some sanity checks and fills in the fields of the struct
+ * gl_config object with the given parameters. If the caller needs to
+ * set additional fields, he should just probably init the whole
+ * gl_config object himself.
+ *
+ * \return GL_TRUE on success, or GL_FALSE on failure.
+ *
+ * \sa _mesa_create_visual() above for the parameter description.
+ */
+GLboolean
+_mesa_initialize_visual( struct gl_config *vis,
+ GLboolean dbFlag,
+ GLboolean stereoFlag,
+ GLint redBits,
+ GLint greenBits,
+ GLint blueBits,
+ GLint alphaBits,
+ GLint depthBits,
+ GLint stencilBits,
+ GLint accumRedBits,
+ GLint accumGreenBits,
+ GLint accumBlueBits,
+ GLint accumAlphaBits,
+ GLint numSamples )
+{
+ assert(vis);
+
+ if (depthBits < 0 || depthBits > 32) {
+ return GL_FALSE;
+ }
+ if (stencilBits < 0 || stencilBits > STENCIL_BITS) {
+ return GL_FALSE;
+ }
+ assert(accumRedBits >= 0);
+ assert(accumGreenBits >= 0);
+ assert(accumBlueBits >= 0);
+ assert(accumAlphaBits >= 0);
+
+ vis->rgbMode = GL_TRUE;
+ vis->doubleBufferMode = dbFlag;
+ vis->stereoMode = stereoFlag;
+
+ vis->redBits = redBits;
+ vis->greenBits = greenBits;
+ vis->blueBits = blueBits;
+ vis->alphaBits = alphaBits;
+ vis->rgbBits = redBits + greenBits + blueBits;
+
+ vis->indexBits = 0;
+ vis->depthBits = depthBits;
+ vis->stencilBits = stencilBits;
+
+ vis->accumRedBits = accumRedBits;
+ vis->accumGreenBits = accumGreenBits;
+ vis->accumBlueBits = accumBlueBits;
+ vis->accumAlphaBits = accumAlphaBits;
+
+ vis->haveAccumBuffer = accumRedBits > 0;
+ vis->haveDepthBuffer = depthBits > 0;
+ vis->haveStencilBuffer = stencilBits > 0;
+
+ vis->numAuxBuffers = 0;
+ vis->level = 0;
+ vis->sampleBuffers = numSamples > 0 ? 1 : 0;
+ vis->samples = numSamples;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Destroy a visual and free its memory.
+ *
+ * \param vis visual.
+ *
+ * Frees the visual structure.
+ */
+void
+_mesa_destroy_visual( struct gl_config *vis )
+{
+ free(vis);
+}
+
+/*@}*/
+
+
+/**********************************************************************/
+/** \name Context allocation, initialization, destroying
+ *
+ * The purpose of the most initialization functions here is to provide the
+ * default state values according to the OpenGL specification.
+ */
+/**********************************************************************/
+/*@{*/
+
+
+/**
+ * This is lame. gdb only seems to recognize enum types that are
+ * actually used somewhere. We want to be able to print/use enum
+ * values such as TEXTURE_2D_INDEX in gdb. But we don't actually use
+ * the gl_texture_index type anywhere. Thus, this lame function.
+ */
+static void
+dummy_enum_func(void)
+{
+ gl_buffer_index bi = BUFFER_FRONT_LEFT;
+ gl_face_index fi = FACE_POS_X;
+ gl_frag_attrib fa = FRAG_ATTRIB_WPOS;
+ gl_frag_result fr = FRAG_RESULT_DEPTH;
+ gl_texture_index ti = TEXTURE_2D_ARRAY_INDEX;
+ gl_vert_attrib va = VERT_ATTRIB_POS;
+ gl_vert_result vr = VERT_RESULT_HPOS;
+ gl_geom_attrib ga = GEOM_ATTRIB_POSITION;
+ gl_geom_result gr = GEOM_RESULT_POS;
+
+ (void) bi;
+ (void) fi;
+ (void) fa;
+ (void) fr;
+ (void) ti;
+ (void) va;
+ (void) vr;
+ (void) ga;
+ (void) gr;
+}
+
+
+/**
+ * One-time initialization mutex lock.
+ *
+ * \sa Used by one_time_init().
+ */
+_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
+
+
+
+/**
+ * Calls all the various one-time-init functions in Mesa.
+ *
+ * While holding a global mutex lock, calls several initialization functions,
+ * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
+ * defined.
+ *
+ * \sa _math_init().
+ */
+static void
+one_time_init( struct gl_context *ctx )
+{
+ static GLbitfield api_init_mask = 0x0;
+
+ _glthread_LOCK_MUTEX(OneTimeLock);
+
+ /* truly one-time init */
+ if (!api_init_mask) {
+ GLuint i;
+
+ /* do some implementation tests */
+ assert( sizeof(GLbyte) == 1 );
+ assert( sizeof(GLubyte) == 1 );
+ assert( sizeof(GLshort) == 2 );
+ assert( sizeof(GLushort) == 2 );
+ assert( sizeof(GLint) == 4 );
+ assert( sizeof(GLuint) == 4 );
+
+ _mesa_get_cpu_features();
+
+ _mesa_init_sqrt_table();
+
+ /* context dependence is never a one-time thing... */
+ _mesa_init_get_hash(ctx);
+
+ for (i = 0; i < 256; i++) {
+ _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
+ }
+
+#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
+ if (MESA_VERBOSE != 0) {
+ _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
+ MESA_VERSION_STRING, __DATE__, __TIME__);
+ }
+#endif
+
+#ifdef DEBUG
+ _mesa_test_formats();
+#endif
+ }
+
+ /* per-API one-time init */
+ if (!(api_init_mask & (1 << ctx->API))) {
+ /*
+ * This is fine as ES does not use the remap table, but it may not be
+ * future-proof. We cannot always initialize the remap table because
+ * when an app is linked to libGLES*, there are not enough dynamic
+ * entries.
+ */
+ if (ctx->API == API_OPENGL)
+ _mesa_init_remap_table();
+ }
+
+ api_init_mask |= 1 << ctx->API;
+
+ _glthread_UNLOCK_MUTEX(OneTimeLock);
+
+ /* Hopefully atexit() is widely available. If not, we may need some
+ * #ifdef tests here.
+ */
+ atexit(_mesa_destroy_shader_compiler);
+
+ dummy_enum_func();
+}
+
+
+/**
+ * Initialize fields of gl_current_attrib (aka ctx->Current.*)
+ */
+static void
+_mesa_init_current(struct gl_context *ctx)
+{
+ GLuint i;
+
+ /* Init all to (0,0,0,1) */
+ for (i = 0; i < Elements(ctx->Current.Attrib); i++) {
+ ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
+ }
+
+ /* redo special cases: */
+ ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 0.0 );
+ ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
+ ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
+ ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
+ ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX], 1.0, 0.0, 0.0, 1.0 );
+ ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG], 1.0, 0.0, 0.0, 1.0 );
+}
+
+
+/**
+ * Init vertex/fragment/geometry program limits.
+ * Important: drivers should override these with actual limits.
+ */
+static void
+init_program_limits(GLenum type, struct gl_program_constants *prog)
+{
+ prog->MaxInstructions = MAX_PROGRAM_INSTRUCTIONS;
+ prog->MaxAluInstructions = MAX_PROGRAM_INSTRUCTIONS;
+ prog->MaxTexInstructions = MAX_PROGRAM_INSTRUCTIONS;
+ prog->MaxTexIndirections = MAX_PROGRAM_INSTRUCTIONS;
+ prog->MaxTemps = MAX_PROGRAM_TEMPS;
+ prog->MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
+ prog->MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
+ prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
+
+ switch (type) {
+ case GL_VERTEX_PROGRAM_ARB:
+ prog->MaxParameters = MAX_VERTEX_PROGRAM_PARAMS;
+ prog->MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
+ prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
+ break;
+ case GL_FRAGMENT_PROGRAM_ARB:
+ prog->MaxParameters = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
+ prog->MaxAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
+ prog->MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
+ break;
+ case MESA_GEOMETRY_PROGRAM:
+ prog->MaxParameters = MAX_NV_VERTEX_PROGRAM_PARAMS;
+ prog->MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
+ prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
+
+ prog->MaxGeometryTextureImageUnits = MAX_GEOMETRY_TEXTURE_IMAGE_UNITS;
+ prog->MaxGeometryVaryingComponents = MAX_GEOMETRY_VARYING_COMPONENTS;
+ prog->MaxVertexVaryingComponents = MAX_VERTEX_VARYING_COMPONENTS;
+ prog->MaxGeometryUniformComponents = MAX_GEOMETRY_UNIFORM_COMPONENTS;
+ prog->MaxGeometryOutputVertices = MAX_GEOMETRY_OUTPUT_VERTICES;
+ prog->MaxGeometryTotalOutputComponents = MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS;
+ break;
+ default:
+ assert(0 && "Bad program type in init_program_limits()");
+ }
+
+ /* Set the native limits to zero. This implies that there is no native
+ * support for shaders. Let the drivers fill in the actual values.
+ */
+ prog->MaxNativeInstructions = 0;
+ prog->MaxNativeAluInstructions = 0;
+ prog->MaxNativeTexInstructions = 0;
+ prog->MaxNativeTexIndirections = 0;
+ prog->MaxNativeAttribs = 0;
+ prog->MaxNativeTemps = 0;
+ prog->MaxNativeAddressRegs = 0;
+ prog->MaxNativeParameters = 0;
+
+ /* Set GLSL datatype range/precision info assuming IEEE float values.
+ * Drivers should override these defaults as needed.
+ */
+ prog->MediumFloat.RangeMin = 127;
+ prog->MediumFloat.RangeMax = 127;
+ prog->MediumFloat.Precision = 23;
+ prog->LowFloat = prog->HighFloat = prog->MediumFloat;
+
+ /* Assume ints are stored as floats for now, since this is the least-common
+ * denominator. The OpenGL ES spec implies (page 132) that the precision
+ * of integer types should be 0. Practically speaking, IEEE
+ * single-precision floating point values can only store integers in the
+ * range [-0x01000000, 0x01000000] without loss of precision.
+ */
+ prog->MediumInt.RangeMin = 24;
+ prog->MediumInt.RangeMax = 24;
+ prog->MediumInt.Precision = 0;
+ prog->LowInt = prog->HighInt = prog->MediumInt;
+}
+
+
+/**
+ * Initialize fields of gl_constants (aka ctx->Const.*).
+ * Use defaults from config.h. The device drivers will often override
+ * some of these values (such as number of texture units).
+ */
+static void
+_mesa_init_constants(struct gl_context *ctx)
+{
+ assert(ctx);
+
+ /* Constants, may be overriden (usually only reduced) by device drivers */
+ ctx->Const.MaxTextureMbytes = MAX_TEXTURE_MBYTES;
+ ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
+ ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
+ ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
+ ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
+ ctx->Const.MaxArrayTextureLayers = MAX_ARRAY_TEXTURE_LAYERS;
+ ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
+ ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
+ ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
+ ctx->Const.MaxTextureImageUnits);
+ ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
+ ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
+ ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
+ ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
+ ctx->Const.MinPointSize = MIN_POINT_SIZE;
+ ctx->Const.MaxPointSize = MAX_POINT_SIZE;
+ ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
+ ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
+ ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
+ ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
+ ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
+ ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
+ ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
+ ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
+ ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
+ ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
+ ctx->Const.MaxLights = MAX_LIGHTS;
+ ctx->Const.MaxShininess = 128.0;
+ ctx->Const.MaxSpotExponent = 128.0;
+ ctx->Const.MaxViewportWidth = MAX_WIDTH;
+ ctx->Const.MaxViewportHeight = MAX_HEIGHT;
+#if FEATURE_ARB_vertex_program
+ init_program_limits(GL_VERTEX_PROGRAM_ARB, &ctx->Const.VertexProgram);
+#endif
+#if FEATURE_ARB_fragment_program
+ init_program_limits(GL_FRAGMENT_PROGRAM_ARB, &ctx->Const.FragmentProgram);
+#endif
+#if FEATURE_ARB_geometry_shader4
+ init_program_limits(MESA_GEOMETRY_PROGRAM, &ctx->Const.GeometryProgram);
+#endif
+ ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
+ ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
+
+ /* CheckArrayBounds is overriden by drivers/x11 for X server */
+ ctx->Const.CheckArrayBounds = GL_FALSE;
+
+ /* GL_ARB_draw_buffers */
+ ctx->Const.MaxDrawBuffers = MAX_DRAW_BUFFERS;
+
+#if FEATURE_EXT_framebuffer_object
+ ctx->Const.MaxColorAttachments = MAX_COLOR_ATTACHMENTS;
+ ctx->Const.MaxRenderbufferSize = MAX_WIDTH;
+#endif
+
+#if FEATURE_ARB_vertex_shader
+ ctx->Const.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS;
+ ctx->Const.MaxCombinedTextureImageUnits = MAX_COMBINED_TEXTURE_IMAGE_UNITS;
+ ctx->Const.MaxVarying = MAX_VARYING;
+#endif
+
+ /* Shading language version */
+ if (ctx->API == API_OPENGL) {
+ ctx->Const.GLSLVersion = 120;
+ }
+ else if (ctx->API == API_OPENGLES2) {
+ ctx->Const.GLSLVersion = 100;
+ }
+ else if (ctx->API == API_OPENGLES) {
+ ctx->Const.GLSLVersion = 0; /* GLSL not supported */
+ }
+
+ /* GL_ARB_framebuffer_object */
+ ctx->Const.MaxSamples = 0;
+
+ /* GL_ARB_sync */
+ ctx->Const.MaxServerWaitTimeout = (GLuint64) ~0;
+
+ /* GL_ATI_envmap_bumpmap */
+ ctx->Const.SupportedBumpUnits = SUPPORTED_ATI_BUMP_UNITS;
+
+ /* GL_EXT_provoking_vertex */
+ ctx->Const.QuadsFollowProvokingVertexConvention = GL_TRUE;
+
+ /* GL_EXT_transform_feedback */
+ ctx->Const.MaxTransformFeedbackSeparateAttribs = MAX_FEEDBACK_ATTRIBS;
+ ctx->Const.MaxTransformFeedbackSeparateComponents = 4 * MAX_FEEDBACK_ATTRIBS;
+ ctx->Const.MaxTransformFeedbackInterleavedComponents = 4 * MAX_FEEDBACK_ATTRIBS;
+
+ /* GL 3.2: hard-coded for now: */
+ ctx->Const.ProfileMask = GL_CONTEXT_COMPATIBILITY_PROFILE_BIT;
+
+ /** GL_EXT_gpu_shader4 */
+ ctx->Const.MinProgramTexelOffset = -8;
+ ctx->Const.MaxProgramTexelOffset = 7;
+}
+
+
+/**
+ * Do some sanity checks on the limits/constants for the given context.
+ * Only called the first time a context is bound.
+ */
+static void
+check_context_limits(struct gl_context *ctx)
+{
+ /* check that we don't exceed the size of various bitfields */
+ assert(VERT_RESULT_MAX <=
+ (8 * sizeof(ctx->VertexProgram._Current->Base.OutputsWritten)));
+ assert(FRAG_ATTRIB_MAX <=
+ (8 * sizeof(ctx->FragmentProgram._Current->Base.InputsRead)));
+
+ assert(MAX_COMBINED_TEXTURE_IMAGE_UNITS <= 8 * sizeof(GLbitfield));
+
+ /* shader-related checks */
+ assert(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
+ assert(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
+
+ assert(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
+ assert(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
+ assert(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX);
+ assert(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX);
+
+ /* Texture unit checks */
+ assert(ctx->Const.MaxTextureImageUnits > 0);
+ assert(ctx->Const.MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS);
+ assert(ctx->Const.MaxTextureCoordUnits > 0);
+ assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS);
+ assert(ctx->Const.MaxTextureUnits > 0);
+ assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
+ assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
+ assert(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
+ ctx->Const.MaxTextureCoordUnits));
+ assert(ctx->Const.MaxCombinedTextureImageUnits > 0);
+ assert(ctx->Const.MaxCombinedTextureImageUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
+ assert(ctx->Const.MaxTextureCoordUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
+ /* number of coord units cannot be greater than number of image units */
+ assert(ctx->Const.MaxTextureCoordUnits <= ctx->Const.MaxTextureImageUnits);
+
+
+ /* Texture size checks */
+ assert(ctx->Const.MaxTextureLevels <= MAX_TEXTURE_LEVELS);
+ assert(ctx->Const.Max3DTextureLevels <= MAX_3D_TEXTURE_LEVELS);
+ assert(ctx->Const.MaxCubeTextureLevels <= MAX_CUBE_TEXTURE_LEVELS);
+ assert(ctx->Const.MaxTextureRectSize <= MAX_TEXTURE_RECT_SIZE);
+
+ /* make sure largest texture image is <= MAX_WIDTH in size */
+ assert((1 << (ctx->Const.MaxTextureLevels - 1)) <= MAX_WIDTH);
+ assert((1 << (ctx->Const.MaxCubeTextureLevels - 1)) <= MAX_WIDTH);
+ assert((1 << (ctx->Const.Max3DTextureLevels - 1)) <= MAX_WIDTH);
+
+ /* Texture level checks */
+ assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
+ assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
+
+ /* Max texture size should be <= max viewport size (render to texture) */
+ assert((1 << (MAX_TEXTURE_LEVELS - 1)) <= MAX_WIDTH);
+
+ assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
+ assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
+
+ assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
+
+ /* if this fails, add more enum values to gl_buffer_index */
+ assert(BUFFER_COLOR0 + MAX_DRAW_BUFFERS <= BUFFER_COUNT);
+
+ /* XXX probably add more tests */
+}
+
+
+/**
+ * Initialize the attribute groups in a GL context.
+ *
+ * \param ctx GL context.
+ *
+ * Initializes all the attributes, calling the respective <tt>init*</tt>
+ * functions for the more complex data structures.
+ */
+static GLboolean
+init_attrib_groups(struct gl_context *ctx)
+{
+ assert(ctx);
+
+ /* Constants */
+ _mesa_init_constants( ctx );
+
+ /* Extensions */
+ _mesa_init_extensions( ctx );
+
+ /* Attribute Groups */
+ _mesa_init_accum( ctx );
+ _mesa_init_attrib( ctx );
+ _mesa_init_buffer_objects( ctx );
+ _mesa_init_color( ctx );
+ _mesa_init_current( ctx );
+ _mesa_init_depth( ctx );
+ _mesa_init_debug( ctx );
+ _mesa_init_display_list( ctx );
+ _mesa_init_eval( ctx );
+ _mesa_init_fbobjects( ctx );
+ _mesa_init_feedback( ctx );
+ _mesa_init_fog( ctx );
+ _mesa_init_hint( ctx );
+ _mesa_init_line( ctx );
+ _mesa_init_lighting( ctx );
+ _mesa_init_matrix( ctx );
+ _mesa_init_multisample( ctx );
+ _mesa_init_pixel( ctx );
+ _mesa_init_pixelstore( ctx );
+ _mesa_init_point( ctx );
+ _mesa_init_polygon( ctx );
+ _mesa_init_program( ctx );
+ _mesa_init_queryobj( ctx );
+ _mesa_init_sync( ctx );
+ _mesa_init_rastpos( ctx );
+ _mesa_init_scissor( ctx );
+ _mesa_init_shader_state( ctx );
+ _mesa_init_stencil( ctx );
+ _mesa_init_transform( ctx );
+ _mesa_init_transform_feedback( ctx );
+ _mesa_init_varray( ctx );
+ _mesa_init_viewport( ctx );
+
+ if (!_mesa_init_texture( ctx ))
+ return GL_FALSE;
+
+ _mesa_init_texture_s3tc( ctx );
+
+ /* Miscellaneous */
+ ctx->NewState = _NEW_ALL;
+ ctx->ErrorValue = (GLenum) GL_NO_ERROR;
+ ctx->varying_vp_inputs = ~0;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Update default objects in a GL context with respect to shared state.
+ *
+ * \param ctx GL context.
+ *
+ * Removes references to old default objects, (texture objects, program
+ * objects, etc.) and changes to reference those from the current shared
+ * state.
+ */
+static GLboolean
+update_default_objects(struct gl_context *ctx)
+{
+ assert(ctx);
+
+ _mesa_update_default_objects_program(ctx);
+ _mesa_update_default_objects_texture(ctx);
+ _mesa_update_default_objects_buffer_objects(ctx);
+
+ return GL_TRUE;
+}
+
+
+/**
+ * This is the default function we plug into all dispatch table slots
+ * This helps prevents a segfault when someone calls a GL function without
+ * first checking if the extension's supported.
+ */
+static int
+generic_nop(void)
+{
+ _mesa_warning(NULL, "User called no-op dispatch function (an unsupported extension function?)");
+ return 0;
+}
+
+
+/**
+ * Allocate and initialize a new dispatch table.
+ */
+struct _glapi_table *
+_mesa_alloc_dispatch_table(int size)
+{
+ /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
+ * In practice, this'll be the same for stand-alone Mesa. But for DRI
+ * Mesa we do this to accomodate different versions of libGL and various
+ * DRI drivers.
+ */
+ GLint numEntries = MAX2(_glapi_get_dispatch_table_size(), _gloffset_COUNT);
+ struct _glapi_table *table;
+
+ /* should never happen, but just in case */
+ numEntries = MAX2(numEntries, size);
+
+ table = (struct _glapi_table *) malloc(numEntries * sizeof(_glapi_proc));
+ if (table) {
+ _glapi_proc *entry = (_glapi_proc *) table;
+ GLint i;
+ for (i = 0; i < numEntries; i++) {
+ entry[i] = (_glapi_proc) generic_nop;
+ }
+ }
+ return table;
+}
+
+
+/**
+ * Initialize a struct gl_context struct (rendering context).
+ *
+ * This includes allocating all the other structs and arrays which hang off of
+ * the context by pointers.
+ * Note that the driver needs to pass in its dd_function_table here since
+ * we need to at least call driverFunctions->NewTextureObject to create the
+ * default texture objects.
+ *
+ * Called by _mesa_create_context().
+ *
+ * Performs the imports and exports callback tables initialization, and
+ * miscellaneous one-time initializations. If no shared context is supplied one
+ * is allocated, and increase its reference count. Setups the GL API dispatch
+ * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
+ * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
+ * for debug flags.
+ *
+ * \param ctx the context to initialize
+ * \param api the GL API type to create the context for
+ * \param visual describes the visual attributes for this context
+ * \param share_list points to context to share textures, display lists,
+ * etc with, or NULL
+ * \param driverFunctions table of device driver functions for this context
+ * to use
+ * \param driverContext pointer to driver-specific context data
+ */
+GLboolean
+_mesa_initialize_context(struct gl_context *ctx,
+ gl_api api,
+ const struct gl_config *visual,
+ struct gl_context *share_list,
+ const struct dd_function_table *driverFunctions,
+ void *driverContext)
+{
+ struct gl_shared_state *shared;
+ int i;
+
+ /*ASSERT(driverContext);*/
+ assert(driverFunctions->NewTextureObject);
+ assert(driverFunctions->FreeTexImageData);
+
+ ctx->API = api;
+ ctx->Visual = *visual;
+ ctx->DrawBuffer = NULL;
+ ctx->ReadBuffer = NULL;
+ ctx->WinSysDrawBuffer = NULL;
+ ctx->WinSysReadBuffer = NULL;
+
+ /* misc one-time initializations */
+ one_time_init(ctx);
+
+ /* Plug in driver functions and context pointer here.
+ * This is important because when we call alloc_shared_state() below
+ * we'll call ctx->Driver.NewTextureObject() to create the default
+ * textures.
+ */
+ ctx->Driver = *driverFunctions;
+ ctx->DriverCtx = driverContext;
+
+ if (share_list) {
+ /* share state with another context */
+ shared = share_list->Shared;
+ }
+ else {
+ /* allocate new, unshared state */
+ shared = _mesa_alloc_shared_state(ctx);
+ if (!shared)
+ return GL_FALSE;
+ }
+
+ _glthread_LOCK_MUTEX(shared->Mutex);
+ ctx->Shared = shared;
+ shared->RefCount++;
+ _glthread_UNLOCK_MUTEX(shared->Mutex);
+
+ if (!init_attrib_groups( ctx )) {
+ _mesa_release_shared_state(ctx, ctx->Shared);
+ return GL_FALSE;
+ }
+
+#if FEATURE_dispatch
+ /* setup the API dispatch tables */
+ switch (ctx->API) {
+#if FEATURE_GL
+ case API_OPENGL:
+ ctx->Exec = _mesa_create_exec_table();
+ break;
+#endif
+#if FEATURE_ES1
+ case API_OPENGLES:
+ ctx->Exec = _mesa_create_exec_table_es1();
+ break;
+#endif
+#if FEATURE_ES2
+ case API_OPENGLES2:
+ ctx->Exec = _mesa_create_exec_table_es2();
+ break;
+#endif
+ default:
+ _mesa_problem(ctx, "unknown or unsupported API");
+ break;
+ }
+
+ if (!ctx->Exec) {
+ _mesa_release_shared_state(ctx, ctx->Shared);
+ return GL_FALSE;
+ }
+#endif
+ ctx->CurrentDispatch = ctx->Exec;
+
+ ctx->FragmentProgram._MaintainTexEnvProgram
+ = (_mesa_getenv("MESA_TEX_PROG") != NULL);
+
+ ctx->VertexProgram._MaintainTnlProgram
+ = (_mesa_getenv("MESA_TNL_PROG") != NULL);
+ if (ctx->VertexProgram._MaintainTnlProgram) {
+ /* this is required... */
+ ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
+ }
+
+ /* Mesa core handles all the formats that mesa core knows about.
+ * Drivers will want to override this list with just the formats
+ * they can handle, and confirm that appropriate fallbacks exist in
+ * _mesa_choose_tex_format().
+ */
+ memset(&ctx->TextureFormatSupported, GL_TRUE,
+ sizeof(ctx->TextureFormatSupported));
+
+ switch (ctx->API) {
+ case API_OPENGL:
+#if FEATURE_dlist
+ ctx->Save = _mesa_create_save_table();
+ if (!ctx->Save) {
+ _mesa_release_shared_state(ctx, ctx->Shared);
+ free(ctx->Exec);
+ return GL_FALSE;
+ }
+
+ _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
+#endif
+ break;
+ case API_OPENGLES:
+ /**
+ * GL_OES_texture_cube_map says
+ * "Initially all texture generation modes are set to REFLECTION_MAP_OES"
+ */
+ for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
+ struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
+ texUnit->GenS.Mode = GL_REFLECTION_MAP_NV;
+ texUnit->GenT.Mode = GL_REFLECTION_MAP_NV;
+ texUnit->GenR.Mode = GL_REFLECTION_MAP_NV;
+ texUnit->GenS._ModeBit = TEXGEN_REFLECTION_MAP_NV;
+ texUnit->GenT._ModeBit = TEXGEN_REFLECTION_MAP_NV;
+ texUnit->GenR._ModeBit = TEXGEN_REFLECTION_MAP_NV;
+ }
+ break;
+ case API_OPENGLES2:
+ ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
+ ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
+ ctx->Point.PointSprite = GL_TRUE; /* always on for ES 2.x */
+ break;
+ }
+
+ ctx->FirstTimeCurrent = GL_TRUE;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Allocate and initialize a struct gl_context structure.
+ * Note that the driver needs to pass in its dd_function_table here since
+ * we need to at least call driverFunctions->NewTextureObject to initialize
+ * the rendering context.
+ *
+ * \param api the GL API type to create the context for
+ * \param visual a struct gl_config pointer (we copy the struct contents)
+ * \param share_list another context to share display lists with or NULL
+ * \param driverFunctions points to the dd_function_table into which the
+ * driver has plugged in all its special functions.
+ * \param driverContext points to the device driver's private context state
+ *
+ * \return pointer to a new __struct gl_contextRec or NULL if error.
+ */
+struct gl_context *
+_mesa_create_context(gl_api api,
+ const struct gl_config *visual,
+ struct gl_context *share_list,
+ const struct dd_function_table *driverFunctions,
+ void *driverContext)
+{
+ struct gl_context *ctx;
+
+ ASSERT(visual);
+ /*ASSERT(driverContext);*/
+
+ ctx = (struct gl_context *) calloc(1, sizeof(struct gl_context));
+ if (!ctx)
+ return NULL;
+
+ if (_mesa_initialize_context(ctx, api, visual, share_list,
+ driverFunctions, driverContext)) {
+ return ctx;
+ }
+ else {
+ free(ctx);
+ return NULL;
+ }
+}
+
+
+/**
+ * Free the data associated with the given context.
+ *
+ * But doesn't free the struct gl_context struct itself.
+ *
+ * \sa _mesa_initialize_context() and init_attrib_groups().
+ */
+void
+_mesa_free_context_data( struct gl_context *ctx )
+{
+ if (!_mesa_get_current_context()){
+ /* No current context, but we may need one in order to delete
+ * texture objs, etc. So temporarily bind the context now.
+ */
+ _mesa_make_current(ctx, NULL, NULL);
+ }
+
+ /* unreference WinSysDraw/Read buffers */
+ _mesa_reference_framebuffer(&ctx->WinSysDrawBuffer, NULL);
+ _mesa_reference_framebuffer(&ctx->WinSysReadBuffer, NULL);
+ _mesa_reference_framebuffer(&ctx->DrawBuffer, NULL);
+ _mesa_reference_framebuffer(&ctx->ReadBuffer, NULL);
+
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
+
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL);
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
+
+ _mesa_free_attrib_data(ctx);
+ _mesa_free_buffer_objects(ctx);
+ _mesa_free_lighting_data( ctx );
+ _mesa_free_eval_data( ctx );
+ _mesa_free_texture_data( ctx );
+ _mesa_free_matrix_data( ctx );
+ _mesa_free_viewport_data( ctx );
+ _mesa_free_program_data(ctx);
+ _mesa_free_shader_state(ctx);
+ _mesa_free_queryobj_data(ctx);
+ _mesa_free_sync_data(ctx);
+ _mesa_free_varray_data(ctx);
+ _mesa_free_transform_feedback(ctx);
+
+ _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
+
+#if FEATURE_ARB_pixel_buffer_object
+ _mesa_reference_buffer_object(ctx, &ctx->Pack.BufferObj, NULL);
+ _mesa_reference_buffer_object(ctx, &ctx->Unpack.BufferObj, NULL);
+ _mesa_reference_buffer_object(ctx, &ctx->DefaultPacking.BufferObj, NULL);
+#endif
+
+#if FEATURE_ARB_vertex_buffer_object
+ _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, NULL);
+ _mesa_reference_buffer_object(ctx, &ctx->Array.ElementArrayBufferObj, NULL);
+#endif
+
+ /* free dispatch tables */
+ free(ctx->Exec);
+ free(ctx->Save);
+
+ /* Shared context state (display lists, textures, etc) */
+ _mesa_release_shared_state( ctx, ctx->Shared );
+
+ /* needs to be after freeing shared state */
+ _mesa_free_display_list_data(ctx);
+
+ if (ctx->Extensions.String)
+ free((void *) ctx->Extensions.String);
+
+ if (ctx->VersionString)
+ free(ctx->VersionString);
+
+ /* unbind the context if it's currently bound */
+ if (ctx == _mesa_get_current_context()) {
+ _mesa_make_current(NULL, NULL, NULL);
+ }
+}
+
+
+/**
+ * Destroy a struct gl_context structure.
+ *
+ * \param ctx GL context.
+ *
+ * Calls _mesa_free_context_data() and frees the gl_context object itself.
+ */
+void
+_mesa_destroy_context( struct gl_context *ctx )
+{
+ if (ctx) {
+ _mesa_free_context_data(ctx);
+ free( (void *) ctx );
+ }
+}
+
+
+#if _HAVE_FULL_GL
+/**
+ * Copy attribute groups from one context to another.
+ *
+ * \param src source context
+ * \param dst destination context
+ * \param mask bitwise OR of GL_*_BIT flags
+ *
+ * According to the bits specified in \p mask, copies the corresponding
+ * attributes from \p src into \p dst. For many of the attributes a simple \c
+ * memcpy is not enough due to the existence of internal pointers in their data
+ * structures.
+ */
+void
+_mesa_copy_context( const struct gl_context *src, struct gl_context *dst, GLuint mask )
+{
+ if (mask & GL_ACCUM_BUFFER_BIT) {
+ /* OK to memcpy */
+ dst->Accum = src->Accum;
+ }
+ if (mask & GL_COLOR_BUFFER_BIT) {
+ /* OK to memcpy */
+ dst->Color = src->Color;
+ }
+ if (mask & GL_CURRENT_BIT) {
+ /* OK to memcpy */
+ dst->Current = src->Current;
+ }
+ if (mask & GL_DEPTH_BUFFER_BIT) {
+ /* OK to memcpy */
+ dst->Depth = src->Depth;
+ }
+ if (mask & GL_ENABLE_BIT) {
+ /* no op */
+ }
+ if (mask & GL_EVAL_BIT) {
+ /* OK to memcpy */
+ dst->Eval = src->Eval;
+ }
+ if (mask & GL_FOG_BIT) {
+ /* OK to memcpy */
+ dst->Fog = src->Fog;
+ }
+ if (mask & GL_HINT_BIT) {
+ /* OK to memcpy */
+ dst->Hint = src->Hint;
+ }
+ if (mask & GL_LIGHTING_BIT) {
+ GLuint i;
+ /* begin with memcpy */
+ dst->Light = src->Light;
+ /* fixup linked lists to prevent pointer insanity */
+ make_empty_list( &(dst->Light.EnabledList) );
+ for (i = 0; i < MAX_LIGHTS; i++) {
+ if (dst->Light.Light[i].Enabled) {
+ insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
+ }
+ }
+ }
+ if (mask & GL_LINE_BIT) {
+ /* OK to memcpy */
+ dst->Line = src->Line;
+ }
+ if (mask & GL_LIST_BIT) {
+ /* OK to memcpy */
+ dst->List = src->List;
+ }
+ if (mask & GL_PIXEL_MODE_BIT) {
+ /* OK to memcpy */
+ dst->Pixel = src->Pixel;
+ }
+ if (mask & GL_POINT_BIT) {
+ /* OK to memcpy */
+ dst->Point = src->Point;
+ }
+ if (mask & GL_POLYGON_BIT) {
+ /* OK to memcpy */
+ dst->Polygon = src->Polygon;
+ }
+ if (mask & GL_POLYGON_STIPPLE_BIT) {
+ /* Use loop instead of memcpy due to problem with Portland Group's
+ * C compiler. Reported by John Stone.
+ */
+ GLuint i;
+ for (i = 0; i < 32; i++) {
+ dst->PolygonStipple[i] = src->PolygonStipple[i];
+ }
+ }
+ if (mask & GL_SCISSOR_BIT) {
+ /* OK to memcpy */
+ dst->Scissor = src->Scissor;
+ }
+ if (mask & GL_STENCIL_BUFFER_BIT) {
+ /* OK to memcpy */
+ dst->Stencil = src->Stencil;
+ }
+ if (mask & GL_TEXTURE_BIT) {
+ /* Cannot memcpy because of pointers */
+ _mesa_copy_texture_state(src, dst);
+ }
+ if (mask & GL_TRANSFORM_BIT) {
+ /* OK to memcpy */
+ dst->Transform = src->Transform;
+ }
+ if (mask & GL_VIEWPORT_BIT) {
+ /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
+ dst->Viewport.X = src->Viewport.X;
+ dst->Viewport.Y = src->Viewport.Y;
+ dst->Viewport.Width = src->Viewport.Width;
+ dst->Viewport.Height = src->Viewport.Height;
+ dst->Viewport.Near = src->Viewport.Near;
+ dst->Viewport.Far = src->Viewport.Far;
+ _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
+ }
+
+ /* XXX FIXME: Call callbacks?
+ */
+ dst->NewState = _NEW_ALL;
+}
+#endif
+
+
+/**
+ * Check if the given context can render into the given framebuffer
+ * by checking visual attributes.
+ *
+ * Most of these tests could go away because Mesa is now pretty flexible
+ * in terms of mixing rendering contexts with framebuffers. As long
+ * as RGB vs. CI mode agree, we're probably good.
+ *
+ * \return GL_TRUE if compatible, GL_FALSE otherwise.
+ */
+static GLboolean
+check_compatible(const struct gl_context *ctx,
+ const struct gl_framebuffer *buffer)
+{
+ const struct gl_config *ctxvis = &ctx->Visual;
+ const struct gl_config *bufvis = &buffer->Visual;
+
+ if (buffer == _mesa_get_incomplete_framebuffer())
+ return GL_TRUE;
+
+#if 0
+ /* disabling this fixes the fgl_glxgears pbuffer demo */
+ if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
+ return GL_FALSE;
+#endif
+ if (ctxvis->stereoMode && !bufvis->stereoMode)
+ return GL_FALSE;
+ if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
+ return GL_FALSE;
+ if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
+ return GL_FALSE;
+ if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
+ return GL_FALSE;
+ if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
+ return GL_FALSE;
+ if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
+ return GL_FALSE;
+ if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
+ return GL_FALSE;
+#if 0
+ /* disabled (see bug 11161) */
+ if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
+ return GL_FALSE;
+#endif
+ if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
+ return GL_FALSE;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Do one-time initialization for the given framebuffer. Specifically,
+ * ask the driver for the window's current size and update the framebuffer
+ * object to match.
+ * Really, the device driver should totally take care of this.
+ */
+static void
+initialize_framebuffer_size(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+ GLuint width, height;
+ if (ctx->Driver.GetBufferSize) {
+ ctx->Driver.GetBufferSize(fb, &width, &height);
+ if (ctx->Driver.ResizeBuffers)
+ ctx->Driver.ResizeBuffers(ctx, fb, width, height);
+ fb->Initialized = GL_TRUE;
+ }
+}
+
+
+/**
+ * Check if the viewport/scissor size has not yet been initialized.
+ * Initialize the size if the given width and height are non-zero.
+ */
+void
+_mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height)
+{
+ if (!ctx->ViewportInitialized && width > 0 && height > 0) {
+ /* Note: set flag here, before calling _mesa_set_viewport(), to prevent
+ * potential infinite recursion.
+ */
+ ctx->ViewportInitialized = GL_TRUE;
+ _mesa_set_viewport(ctx, 0, 0, width, height);
+ _mesa_set_scissor(ctx, 0, 0, width, height);
+ }
+}
+
+
+/**
+ * Bind the given context to the given drawBuffer and readBuffer and
+ * make it the current context for the calling thread.
+ * We'll render into the drawBuffer and read pixels from the
+ * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc).
+ *
+ * We check that the context's and framebuffer's visuals are compatible
+ * and return immediately if they're not.
+ *
+ * \param newCtx the new GL context. If NULL then there will be no current GL
+ * context.
+ * \param drawBuffer the drawing framebuffer
+ * \param readBuffer the reading framebuffer
+ */
+GLboolean
+_mesa_make_current( struct gl_context *newCtx,
+ struct gl_framebuffer *drawBuffer,
+ struct gl_framebuffer *readBuffer )
+{
+ GET_CURRENT_CONTEXT(curCtx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(newCtx, "_mesa_make_current()\n");
+
+ /* Check that the context's and framebuffer's visuals are compatible.
+ */
+ if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) {
+ if (!check_compatible(newCtx, drawBuffer)) {
+ _mesa_warning(newCtx,
+ "MakeCurrent: incompatible visuals for context and drawbuffer");
+ return GL_FALSE;
+ }
+ }
+ if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) {
+ if (!check_compatible(newCtx, readBuffer)) {
+ _mesa_warning(newCtx,
+ "MakeCurrent: incompatible visuals for context and readbuffer");
+ return GL_FALSE;
+ }
+ }
+
+ if (curCtx &&
+ (curCtx->WinSysDrawBuffer || curCtx->WinSysReadBuffer) && /* make sure this context is valid for flushing */
+ curCtx != newCtx)
+ _mesa_flush(curCtx);
+
+ /* We used to call _glapi_check_multithread() here. Now do it in drivers */
+ _glapi_set_context((void *) newCtx);
+ ASSERT(_mesa_get_current_context() == newCtx);
+
+ if (!newCtx) {
+ _glapi_set_dispatch(NULL); /* none current */
+ }
+ else {
+ _glapi_set_dispatch(newCtx->CurrentDispatch);
+
+ if (drawBuffer && readBuffer) {
+ /* TODO: check if newCtx and buffer's visual match??? */
+
+ ASSERT(drawBuffer->Name == 0);
+ ASSERT(readBuffer->Name == 0);
+ _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer);
+ _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer);
+
+ /*
+ * Only set the context's Draw/ReadBuffer fields if they're NULL
+ * or not bound to a user-created FBO.
+ */
+ if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
+ /* KW: merge conflict here, revisit.
+ */
+ /* fix up the fb fields - these will end up wrong otherwise
+ * if the DRIdrawable changes, and everything relies on them.
+ * This is a bit messy (same as needed in _mesa_BindFramebufferEXT)
+ */
+ unsigned int i;
+ GLenum buffers[MAX_DRAW_BUFFERS];
+
+ _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer);
+
+ for(i = 0; i < newCtx->Const.MaxDrawBuffers; i++) {
+ buffers[i] = newCtx->Color.DrawBuffer[i];
+ }
+
+ _mesa_drawbuffers(newCtx, newCtx->Const.MaxDrawBuffers,
+ buffers, NULL);
+ }
+ if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) {
+ _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
+ }
+
+ /* XXX only set this flag if we're really changing the draw/read
+ * framebuffer bindings.
+ */
+ newCtx->NewState |= _NEW_BUFFERS;
+
+#if 1
+ /* We want to get rid of these lines: */
+
+#if _HAVE_FULL_GL
+ if (!drawBuffer->Initialized) {
+ initialize_framebuffer_size(newCtx, drawBuffer);
+ }
+ if (readBuffer != drawBuffer && !readBuffer->Initialized) {
+ initialize_framebuffer_size(newCtx, readBuffer);
+ }
+
+ _mesa_resizebuffers(newCtx);
+#endif
+
+#else
+ /* We want the drawBuffer and readBuffer to be initialized by
+ * the driver.
+ * This generally means the Width and Height match the actual
+ * window size and the renderbuffers (both hardware and software
+ * based) are allocated to match. The later can generally be
+ * done with a call to _mesa_resize_framebuffer().
+ *
+ * It's theoretically possible for a buffer to have zero width
+ * or height, but for now, assert check that the driver did what's
+ * expected of it.
+ */
+ ASSERT(drawBuffer->Width > 0);
+ ASSERT(drawBuffer->Height > 0);
+#endif
+
+ if (drawBuffer) {
+ _mesa_check_init_viewport(newCtx,
+ drawBuffer->Width, drawBuffer->Height);
+ }
+ }
+
+ if (newCtx->FirstTimeCurrent) {
+ _mesa_compute_version(newCtx);
+
+ newCtx->Extensions.String = _mesa_make_extension_string(newCtx);
+
+ check_context_limits(newCtx);
+
+ /* We can use this to help debug user's problems. Tell them to set
+ * the MESA_INFO env variable before running their app. Then the
+ * first time each context is made current we'll print some useful
+ * information.
+ */
+ if (_mesa_getenv("MESA_INFO")) {
+ _mesa_print_info();
+ }
+
+ newCtx->FirstTimeCurrent = GL_FALSE;
+ }
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Make context 'ctx' share the display lists, textures and programs
+ * that are associated with 'ctxToShare'.
+ * Any display lists, textures or programs associated with 'ctx' will
+ * be deleted if nobody else is sharing them.
+ */
+GLboolean
+_mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare)
+{
+ if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
+ struct gl_shared_state *oldSharedState = ctx->Shared;
+
+ ctx->Shared = ctxToShare->Shared;
+
+ _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+ ctx->Shared->RefCount++;
+ _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+
+ update_default_objects(ctx);
+
+ _mesa_release_shared_state(ctx, oldSharedState);
+
+ return GL_TRUE;
+ }
+ else {
+ return GL_FALSE;
+ }
+}
+
+
+
+/**
+ * \return pointer to the current GL context for this thread.
+ *
+ * Calls _glapi_get_context(). This isn't the fastest way to get the current
+ * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in
+ * context.h.
+ */
+struct gl_context *
+_mesa_get_current_context( void )
+{
+ return (struct gl_context *) _glapi_get_context();
+}
+
+
+/**
+ * Get context's current API dispatch table.
+ *
+ * It'll either be the immediate-mode execute dispatcher or the display list
+ * compile dispatcher.
+ *
+ * \param ctx GL context.
+ *
+ * \return pointer to dispatch_table.
+ *
+ * Simply returns __struct gl_contextRec::CurrentDispatch.
+ */
+struct _glapi_table *
+_mesa_get_dispatch(struct gl_context *ctx)
+{
+ return ctx->CurrentDispatch;
+}
+
+/*@}*/
+
+
+/**********************************************************************/
+/** \name Miscellaneous functions */
+/**********************************************************************/
+/*@{*/
+
+/**
+ * Record an error.
+ *
+ * \param ctx GL context.
+ * \param error error code.
+ *
+ * Records the given error code and call the driver's dd_function_table::Error
+ * function if defined.
+ *
+ * \sa
+ * This is called via _mesa_error().
+ */
+void
+_mesa_record_error(struct gl_context *ctx, GLenum error)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->ErrorValue == GL_NO_ERROR) {
+ ctx->ErrorValue = error;
+ }
+
+ /* Call device driver's error handler, if any. This is used on the Mac. */
+ if (ctx->Driver.Error) {
+ ctx->Driver.Error(ctx);
+ }
+}
+
+
+/**
+ * Flush commands and wait for completion.
+ */
+void
+_mesa_finish(struct gl_context *ctx)
+{
+ FLUSH_CURRENT( ctx, 0 );
+ if (ctx->Driver.Finish) {
+ ctx->Driver.Finish(ctx);
+ }
+}
+
+
+/**
+ * Flush commands.
+ */
+void
+_mesa_flush(struct gl_context *ctx)
+{
+ FLUSH_CURRENT( ctx, 0 );
+ if (ctx->Driver.Flush) {
+ ctx->Driver.Flush(ctx);
+ }
+}
+
+
+
+/**
+ * Execute glFinish().
+ *
+ * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
+ * dd_function_table::Finish driver callback, if not NULL.
+ */
+void GLAPIENTRY
+_mesa_Finish(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+ _mesa_finish(ctx);
+}
+
+
+/**
+ * Execute glFlush().
+ *
+ * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
+ * dd_function_table::Flush driver callback, if not NULL.
+ */
+void GLAPIENTRY
+_mesa_Flush(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+ _mesa_flush(ctx);
+}
+
+
+/**
+ * Set mvp_with_dp4 flag. If a driver has a preference for DP4 over
+ * MUL/MAD, or vice versa, call this function to register that.
+ * Otherwise we default to MUL/MAD.
+ */
+void
+_mesa_set_mvp_with_dp4( struct gl_context *ctx,
+ GLboolean flag )
+{
+ ctx->mvp_with_dp4 = flag;
+}
+
+
+
+/**
+ * Prior to drawing anything with glBegin, glDrawArrays, etc. this function
+ * is called to see if it's valid to render. This involves checking that
+ * the current shader is valid and the framebuffer is complete.
+ * If an error is detected it'll be recorded here.
+ * \return GL_TRUE if OK to render, GL_FALSE if not
+ */
+GLboolean
+_mesa_valid_to_render(struct gl_context *ctx, const char *where)
+{
+ bool vert_from_glsl_shader = false;
+ bool geom_from_glsl_shader = false;
+ bool frag_from_glsl_shader = false;
+
+ /* This depends on having up to date derived state (shaders) */
+ if (ctx->NewState)
+ _mesa_update_state(ctx);
+
+ if (ctx->Shader.CurrentVertexProgram) {
+ vert_from_glsl_shader = true;
+
+ if (!ctx->Shader.CurrentVertexProgram->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(shader not linked)", where);
+ return GL_FALSE;
+ }
+#if 0 /* not normally enabled */
+ {
+ char errMsg[100];
+ if (!_mesa_validate_shader_program(ctx,
+ ctx->Shader.CurrentVertexProgram,
+ errMsg)) {
+ _mesa_warning(ctx, "Shader program %u is invalid: %s",
+ ctx->Shader.CurrentVertexProgram->Name, errMsg);
+ }
+ }
+#endif
+ }
+
+ if (ctx->Shader.CurrentGeometryProgram) {
+ geom_from_glsl_shader = true;
+
+ if (!ctx->Shader.CurrentGeometryProgram->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(shader not linked)", where);
+ return GL_FALSE;
+ }
+#if 0 /* not normally enabled */
+ {
+ char errMsg[100];
+ if (!_mesa_validate_shader_program(ctx,
+ ctx->Shader.CurrentGeometryProgram,
+ errMsg)) {
+ _mesa_warning(ctx, "Shader program %u is invalid: %s",
+ ctx->Shader.CurrentGeometryProgram->Name, errMsg);
+ }
+ }
+#endif
+ }
+
+ if (ctx->Shader.CurrentFragmentProgram) {
+ frag_from_glsl_shader = true;
+
+ if (!ctx->Shader.CurrentFragmentProgram->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(shader not linked)", where);
+ return GL_FALSE;
+ }
+#if 0 /* not normally enabled */
+ {
+ char errMsg[100];
+ if (!_mesa_validate_shader_program(ctx,
+ ctx->Shader.CurrentFragmentProgram,
+ errMsg)) {
+ _mesa_warning(ctx, "Shader program %u is invalid: %s",
+ ctx->Shader.CurrentFragmentProgram->Name, errMsg);
+ }
+ }
+#endif
+ }
+
+ /* Any shader stages that are not supplied by the GLSL shader and have
+ * assembly shaders enabled must now be validated.
+ */
+ if (!vert_from_glsl_shader
+ && ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(vertex program not valid)", where);
+ return GL_FALSE;
+ }
+
+ /* FINISHME: If GL_NV_geometry_program4 is ever supported, the current
+ * FINISHME: geometry program should validated here.
+ */
+ (void) geom_from_glsl_shader;
+
+ if (!frag_from_glsl_shader) {
+ if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(fragment program not valid)", where);
+ return GL_FALSE;
+ }
+
+ /* If drawing to integer-valued color buffers, there must be an
+ * active fragment shader (GL_EXT_texture_integer).
+ */
+ if (ctx->DrawBuffer && ctx->DrawBuffer->_IntegerColor) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(integer format but no fragment shader)", where);
+ return GL_FALSE;
+ }
+ }
+
+ if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+ "%s(incomplete framebuffer)", where);
+ return GL_FALSE;
+ }
+
+#ifdef DEBUG
+ if (ctx->Shader.Flags & GLSL_LOG) {
+ struct gl_shader_program *shProg[MESA_SHADER_TYPES];
+ gl_shader_type i;
+
+ shProg[MESA_SHADER_VERTEX] = ctx->Shader.CurrentVertexProgram;
+ shProg[MESA_SHADER_GEOMETRY] = ctx->Shader.CurrentGeometryProgram;
+ shProg[MESA_SHADER_FRAGMENT] = ctx->Shader.CurrentFragmentProgram;
+
+ for (i = 0; i < MESA_SHADER_TYPES; i++) {
+ struct gl_shader *sh;
+
+ if (shProg[i] == NULL || shProg[i]->_Used
+ || shProg[i]->_LinkedShaders[i] == NULL)
+ continue;
+
+ /* This is the first time this shader is being used.
+ * Append shader's constants/uniforms to log file.
+ *
+ * The logic is a little odd here. We only want to log data for each
+ * shader target that will actually be used, and we only want to log
+ * it once. It's possible to have a program bound to the vertex
+ * shader target that also supplied a fragment shader. If that
+ * program isn't also bound to the fragment shader target we don't
+ * want to log its fragment data.
+ */
+ sh = shProg[i]->_LinkedShaders[i];
+ switch (sh->Type) {
+ case GL_VERTEX_SHADER:
+ _mesa_append_uniforms_to_file(sh, &shProg[i]->VertexProgram->Base);
+ break;
+
+ case GL_GEOMETRY_SHADER_ARB:
+ _mesa_append_uniforms_to_file(sh,
+ &shProg[i]->GeometryProgram->Base);
+ break;
+
+ case GL_FRAGMENT_SHADER:
+ _mesa_append_uniforms_to_file(sh,
+ &shProg[i]->FragmentProgram->Base);
+ break;
+ }
+ }
+
+ for (i = 0; i < MESA_SHADER_TYPES; i++) {
+ if (shProg[i] != NULL)
+ shProg[i]->_Used = GL_TRUE;
+ }
+ }
+#endif
+
+ return GL_TRUE;
+}
+
+
+/*@}*/
diff --git a/mesalib/src/mesa/main/context.h b/mesalib/src/mesa/main/context.h
index 4e391dde4..160e795f7 100644
--- a/mesalib/src/mesa/main/context.h
+++ b/mesalib/src/mesa/main/context.h
@@ -1,313 +1,313 @@
-/*
- * Mesa 3-D graphics library
- * Version: 6.5.1
- *
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file context.h
- * Mesa context and visual-related functions.
- *
- * There are three large Mesa data types/classes which are meant to be
- * used by device drivers:
- * - struct gl_context: this contains the Mesa rendering state
- * - struct gl_config: this describes the color buffer (RGB vs. ci), whether or not
- * there's a depth buffer, stencil buffer, etc.
- * - struct gl_framebuffer: contains pointers to the depth buffer, stencil buffer,
- * accum buffer and alpha buffers.
- *
- * These types should be encapsulated by corresponding device driver
- * data types. See xmesa.h and xmesaP.h for an example.
- *
- * In OOP terms, struct gl_context, struct gl_config, and struct gl_framebuffer are base classes
- * which the device driver must derive from.
- *
- * The following functions create and destroy these data types.
- */
-
-
-#ifndef CONTEXT_H
-#define CONTEXT_H
-
-
-#include "imports.h"
-#include "mtypes.h"
-
-
-struct _glapi_table;
-
-
-/** \name Visual-related functions */
-/*@{*/
-
-extern struct gl_config *
-_mesa_create_visual( GLboolean dbFlag,
- GLboolean stereoFlag,
- GLint redBits,
- GLint greenBits,
- GLint blueBits,
- GLint alphaBits,
- GLint depthBits,
- GLint stencilBits,
- GLint accumRedBits,
- GLint accumGreenBits,
- GLint accumBlueBits,
- GLint accumAlphaBits,
- GLint numSamples );
-
-extern GLboolean
-_mesa_initialize_visual( struct gl_config *v,
- GLboolean dbFlag,
- GLboolean stereoFlag,
- GLint redBits,
- GLint greenBits,
- GLint blueBits,
- GLint alphaBits,
- GLint depthBits,
- GLint stencilBits,
- GLint accumRedBits,
- GLint accumGreenBits,
- GLint accumBlueBits,
- GLint accumAlphaBits,
- GLint numSamples );
-
-extern void
-_mesa_destroy_visual( struct gl_config *vis );
-
-/*@}*/
-
-
-/** \name Context-related functions */
-/*@{*/
-
-extern GLboolean
-_mesa_initialize_context( struct gl_context *ctx,
- gl_api api,
- const struct gl_config *visual,
- struct gl_context *share_list,
- const struct dd_function_table *driverFunctions,
- void *driverContext );
-
-extern struct gl_context *
-_mesa_create_context(gl_api api,
- const struct gl_config *visual,
- struct gl_context *share_list,
- const struct dd_function_table *driverFunctions,
- void *driverContext);
-
-extern void
-_mesa_free_context_data( struct gl_context *ctx );
-
-extern void
-_mesa_destroy_context( struct gl_context *ctx );
-
-
-extern void
-_mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
-
-
-extern void
-_mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height);
-
-extern GLboolean
-_mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
- struct gl_framebuffer *readBuffer );
-
-extern GLboolean
-_mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
-
-extern struct gl_context *
-_mesa_get_current_context(void);
-
-/*@}*/
-
-extern void
-_mesa_init_get_hash(struct gl_context *ctx);
-
-extern void
-_mesa_notifySwapBuffers(struct gl_context *gc);
-
-
-extern struct _glapi_table *
-_mesa_get_dispatch(struct gl_context *ctx);
-
-
-void
-_mesa_set_mvp_with_dp4( struct gl_context *ctx,
- GLboolean flag );
-
-
-extern GLboolean
-_mesa_valid_to_render(struct gl_context *ctx, const char *where);
-
-
-
-/** \name Miscellaneous */
-/*@{*/
-
-extern void
-_mesa_record_error( struct gl_context *ctx, GLenum error );
-
-
-extern void
-_mesa_finish(struct gl_context *ctx);
-
-extern void
-_mesa_flush(struct gl_context *ctx);
-
-
-extern void GLAPIENTRY
-_mesa_Finish( void );
-
-extern void GLAPIENTRY
-_mesa_Flush( void );
-
-/*@}*/
-
-
-/**
- * \name Macros for flushing buffered rendering commands before state changes,
- * checking if inside glBegin/glEnd, etc.
- */
-/*@{*/
-
-/**
- * Flush vertices.
- *
- * \param ctx GL context.
- * \param newstate new state.
- *
- * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
- * and calls dd_function_table::FlushVertices if so. Marks
- * __struct gl_contextRec::NewState with \p newstate.
- */
-#define FLUSH_VERTICES(ctx, newstate) \
-do { \
- if (MESA_VERBOSE & VERBOSE_STATE) \
- _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
- if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
- ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \
- ctx->NewState |= newstate; \
-} while (0)
-
-/**
- * Flush current state.
- *
- * \param ctx GL context.
- * \param newstate new state.
- *
- * Checks if dd_function_table::NeedFlush is marked to flush current state,
- * and calls dd_function_table::FlushVertices if so. Marks
- * __struct gl_contextRec::NewState with \p newstate.
- */
-#define FLUSH_CURRENT(ctx, newstate) \
-do { \
- if (MESA_VERBOSE & VERBOSE_STATE) \
- _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
- if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
- ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
- ctx->NewState |= newstate; \
-} while (0)
-
-/**
- * Macro to assert that the API call was made outside the
- * glBegin()/glEnd() pair, with return value.
- *
- * \param ctx GL context.
- * \param retval value to return value in case the assertion fails.
- */
-#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
-do { \
- if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
- _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
- return retval; \
- } \
-} while (0)
-
-/**
- * Macro to assert that the API call was made outside the
- * glBegin()/glEnd() pair.
- *
- * \param ctx GL context.
- */
-#define ASSERT_OUTSIDE_BEGIN_END(ctx) \
-do { \
- if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
- _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
- return; \
- } \
-} while (0)
-
-/**
- * Macro to assert that the API call was made outside the
- * glBegin()/glEnd() pair and flush the vertices.
- *
- * \param ctx GL context.
- */
-#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx) \
-do { \
- ASSERT_OUTSIDE_BEGIN_END(ctx); \
- FLUSH_VERTICES(ctx, 0); \
-} while (0)
-
-/**
- * Macro to assert that the API call was made outside the
- * glBegin()/glEnd() pair and flush the vertices, with return value.
- *
- * \param ctx GL context.
- * \param retval value to return value in case the assertion fails.
- */
-#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval) \
-do { \
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval); \
- FLUSH_VERTICES(ctx, 0); \
-} while (0)
-
-/*@}*/
-
-
-
-/**
- * Is the secondary color needed?
- */
-#define NEED_SECONDARY_COLOR(CTX) \
- (((CTX)->Light.Enabled && \
- (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) \
- || (CTX)->Fog.ColorSumEnabled \
- || ((CTX)->VertexProgram._Current && \
- ((CTX)->VertexProgram._Current != (CTX)->VertexProgram._TnlProgram) && \
- ((CTX)->VertexProgram._Current->Base.InputsRead & VERT_BIT_COLOR1)) \
- || ((CTX)->FragmentProgram._Current && \
- ((CTX)->FragmentProgram._Current != (CTX)->FragmentProgram._TexEnvProgram) && \
- ((CTX)->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_COL1)) \
- )
-
-
-/**
- * Is RGBA LogicOp enabled?
- */
-#define RGBA_LOGICOP_ENABLED(CTX) \
- ((CTX)->Color.ColorLogicOpEnabled || \
- ((CTX)->Color.BlendEnabled && (CTX)->Color.Blend[0].EquationRGB == GL_LOGIC_OP))
-
-
-#endif /* CONTEXT_H */
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5.1
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file context.h
+ * Mesa context and visual-related functions.
+ *
+ * There are three large Mesa data types/classes which are meant to be
+ * used by device drivers:
+ * - struct gl_context: this contains the Mesa rendering state
+ * - struct gl_config: this describes the color buffer (RGB vs. ci), whether or not
+ * there's a depth buffer, stencil buffer, etc.
+ * - struct gl_framebuffer: contains pointers to the depth buffer, stencil buffer,
+ * accum buffer and alpha buffers.
+ *
+ * These types should be encapsulated by corresponding device driver
+ * data types. See xmesa.h and xmesaP.h for an example.
+ *
+ * In OOP terms, struct gl_context, struct gl_config, and struct gl_framebuffer are base classes
+ * which the device driver must derive from.
+ *
+ * The following functions create and destroy these data types.
+ */
+
+
+#ifndef CONTEXT_H
+#define CONTEXT_H
+
+
+#include "imports.h"
+#include "mtypes.h"
+
+
+struct _glapi_table;
+
+
+/** \name Visual-related functions */
+/*@{*/
+
+extern struct gl_config *
+_mesa_create_visual( GLboolean dbFlag,
+ GLboolean stereoFlag,
+ GLint redBits,
+ GLint greenBits,
+ GLint blueBits,
+ GLint alphaBits,
+ GLint depthBits,
+ GLint stencilBits,
+ GLint accumRedBits,
+ GLint accumGreenBits,
+ GLint accumBlueBits,
+ GLint accumAlphaBits,
+ GLint numSamples );
+
+extern GLboolean
+_mesa_initialize_visual( struct gl_config *v,
+ GLboolean dbFlag,
+ GLboolean stereoFlag,
+ GLint redBits,
+ GLint greenBits,
+ GLint blueBits,
+ GLint alphaBits,
+ GLint depthBits,
+ GLint stencilBits,
+ GLint accumRedBits,
+ GLint accumGreenBits,
+ GLint accumBlueBits,
+ GLint accumAlphaBits,
+ GLint numSamples );
+
+extern void
+_mesa_destroy_visual( struct gl_config *vis );
+
+/*@}*/
+
+
+/** \name Context-related functions */
+/*@{*/
+
+extern GLboolean
+_mesa_initialize_context( struct gl_context *ctx,
+ gl_api api,
+ const struct gl_config *visual,
+ struct gl_context *share_list,
+ const struct dd_function_table *driverFunctions,
+ void *driverContext );
+
+extern struct gl_context *
+_mesa_create_context(gl_api api,
+ const struct gl_config *visual,
+ struct gl_context *share_list,
+ const struct dd_function_table *driverFunctions,
+ void *driverContext);
+
+extern void
+_mesa_free_context_data( struct gl_context *ctx );
+
+extern void
+_mesa_destroy_context( struct gl_context *ctx );
+
+
+extern void
+_mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
+
+
+extern void
+_mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height);
+
+extern GLboolean
+_mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
+ struct gl_framebuffer *readBuffer );
+
+extern GLboolean
+_mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
+
+extern struct gl_context *
+_mesa_get_current_context(void);
+
+/*@}*/
+
+extern void
+_mesa_init_get_hash(struct gl_context *ctx);
+
+extern void
+_mesa_notifySwapBuffers(struct gl_context *gc);
+
+
+extern struct _glapi_table *
+_mesa_get_dispatch(struct gl_context *ctx);
+
+
+void
+_mesa_set_mvp_with_dp4( struct gl_context *ctx,
+ GLboolean flag );
+
+
+extern GLboolean
+_mesa_valid_to_render(struct gl_context *ctx, const char *where);
+
+
+
+/** \name Miscellaneous */
+/*@{*/
+
+extern void
+_mesa_record_error( struct gl_context *ctx, GLenum error );
+
+
+extern void
+_mesa_finish(struct gl_context *ctx);
+
+extern void
+_mesa_flush(struct gl_context *ctx);
+
+
+extern void GLAPIENTRY
+_mesa_Finish( void );
+
+extern void GLAPIENTRY
+_mesa_Flush( void );
+
+/*@}*/
+
+
+/**
+ * \name Macros for flushing buffered rendering commands before state changes,
+ * checking if inside glBegin/glEnd, etc.
+ */
+/*@{*/
+
+/**
+ * Flush vertices.
+ *
+ * \param ctx GL context.
+ * \param newstate new state.
+ *
+ * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
+ * and calls dd_function_table::FlushVertices if so. Marks
+ * __struct gl_contextRec::NewState with \p newstate.
+ */
+#define FLUSH_VERTICES(ctx, newstate) \
+do { \
+ if (MESA_VERBOSE & VERBOSE_STATE) \
+ _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
+ if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
+ ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \
+ ctx->NewState |= newstate; \
+} while (0)
+
+/**
+ * Flush current state.
+ *
+ * \param ctx GL context.
+ * \param newstate new state.
+ *
+ * Checks if dd_function_table::NeedFlush is marked to flush current state,
+ * and calls dd_function_table::FlushVertices if so. Marks
+ * __struct gl_contextRec::NewState with \p newstate.
+ */
+#define FLUSH_CURRENT(ctx, newstate) \
+do { \
+ if (MESA_VERBOSE & VERBOSE_STATE) \
+ _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
+ if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
+ ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
+ ctx->NewState |= newstate; \
+} while (0)
+
+/**
+ * Macro to assert that the API call was made outside the
+ * glBegin()/glEnd() pair, with return value.
+ *
+ * \param ctx GL context.
+ * \param retval value to return value in case the assertion fails.
+ */
+#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
+do { \
+ if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
+ _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
+ return retval; \
+ } \
+} while (0)
+
+/**
+ * Macro to assert that the API call was made outside the
+ * glBegin()/glEnd() pair.
+ *
+ * \param ctx GL context.
+ */
+#define ASSERT_OUTSIDE_BEGIN_END(ctx) \
+do { \
+ if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
+ _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
+ return; \
+ } \
+} while (0)
+
+/**
+ * Macro to assert that the API call was made outside the
+ * glBegin()/glEnd() pair and flush the vertices.
+ *
+ * \param ctx GL context.
+ */
+#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx) \
+do { \
+ ASSERT_OUTSIDE_BEGIN_END(ctx); \
+ FLUSH_VERTICES(ctx, 0); \
+} while (0)
+
+/**
+ * Macro to assert that the API call was made outside the
+ * glBegin()/glEnd() pair and flush the vertices, with return value.
+ *
+ * \param ctx GL context.
+ * \param retval value to return value in case the assertion fails.
+ */
+#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval) \
+do { \
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval); \
+ FLUSH_VERTICES(ctx, 0); \
+} while (0)
+
+/*@}*/
+
+
+
+/**
+ * Is the secondary color needed?
+ */
+#define NEED_SECONDARY_COLOR(CTX) \
+ (((CTX)->Light.Enabled && \
+ (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) \
+ || (CTX)->Fog.ColorSumEnabled \
+ || ((CTX)->VertexProgram._Current && \
+ ((CTX)->VertexProgram._Current != (CTX)->VertexProgram._TnlProgram) && \
+ ((CTX)->VertexProgram._Current->Base.InputsRead & VERT_BIT_COLOR1)) \
+ || ((CTX)->FragmentProgram._Current && \
+ ((CTX)->FragmentProgram._Current != (CTX)->FragmentProgram._TexEnvProgram) && \
+ ((CTX)->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_COL1)) \
+ )
+
+
+/**
+ * Is RGBA LogicOp enabled?
+ */
+#define RGBA_LOGICOP_ENABLED(CTX) \
+ ((CTX)->Color.ColorLogicOpEnabled || \
+ ((CTX)->Color.BlendEnabled && (CTX)->Color.Blend[0].EquationRGB == GL_LOGIC_OP))
+
+
+#endif /* CONTEXT_H */
diff --git a/mesalib/src/mesa/main/depth.c b/mesalib/src/mesa/main/depth.c
index 52c69a6bc..d666ed5fe 100644
--- a/mesalib/src/mesa/main/depth.c
+++ b/mesalib/src/mesa/main/depth.c
@@ -1,174 +1,174 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "glheader.h"
-#include "imports.h"
-#include "context.h"
-#include "depth.h"
-#include "enums.h"
-#include "macros.h"
-#include "mtypes.h"
-
-
-/**********************************************************************/
-/***** API Functions *****/
-/**********************************************************************/
-
-
-
-void GLAPIENTRY
-_mesa_ClearDepth( GLclampd depth )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glClearDepth(%f)\n", depth);
-
- depth = CLAMP( depth, 0.0, 1.0 );
-
- if (ctx->Depth.Clear == depth)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_DEPTH);
- ctx->Depth.Clear = depth;
- if (ctx->Driver.ClearDepth)
- (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear );
-}
-
-
-void GLAPIENTRY
-_mesa_ClearDepthf( GLclampf depth )
-{
- _mesa_ClearDepth(depth);
-}
-
-
-void GLAPIENTRY
-_mesa_DepthFunc( GLenum func )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glDepthFunc %s\n", _mesa_lookup_enum_by_nr(func));
-
- switch (func) {
- case GL_LESS: /* (default) pass if incoming z < stored z */
- case GL_GEQUAL:
- case GL_LEQUAL:
- case GL_GREATER:
- case GL_NOTEQUAL:
- case GL_EQUAL:
- case GL_ALWAYS:
- case GL_NEVER:
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glDepth.Func" );
- return;
- }
-
- if (ctx->Depth.Func == func)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_DEPTH);
- ctx->Depth.Func = func;
-
- if (ctx->Driver.DepthFunc)
- ctx->Driver.DepthFunc( ctx, func );
-}
-
-
-
-void GLAPIENTRY
-_mesa_DepthMask( GLboolean flag )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glDepthMask %d\n", flag);
-
- /*
- * GL_TRUE indicates depth buffer writing is enabled (default)
- * GL_FALSE indicates depth buffer writing is disabled
- */
- if (ctx->Depth.Mask == flag)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_DEPTH);
- ctx->Depth.Mask = flag;
-
- if (ctx->Driver.DepthMask)
- ctx->Driver.DepthMask( ctx, flag );
-}
-
-
-
-/**
- * Specified by the GL_EXT_depth_bounds_test extension.
- */
-void GLAPIENTRY
-_mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax);
-
- if (zmin > zmax) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)");
- return;
- }
-
- zmin = CLAMP(zmin, 0.0, 1.0);
- zmax = CLAMP(zmax, 0.0, 1.0);
-
- if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_DEPTH);
- ctx->Depth.BoundsMin = (GLfloat) zmin;
- ctx->Depth.BoundsMax = (GLfloat) zmax;
-}
-
-
-/**********************************************************************/
-/***** Initialization *****/
-/**********************************************************************/
-
-
-/**
- * Initialize the depth buffer attribute group in the given context.
- */
-void
-_mesa_init_depth(struct gl_context *ctx)
-{
- ctx->Depth.Test = GL_FALSE;
- ctx->Depth.Clear = 1.0;
- ctx->Depth.Func = GL_LESS;
- ctx->Depth.Mask = GL_TRUE;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "glheader.h"
+#include "imports.h"
+#include "context.h"
+#include "depth.h"
+#include "enums.h"
+#include "macros.h"
+#include "mtypes.h"
+
+
+/**********************************************************************/
+/***** API Functions *****/
+/**********************************************************************/
+
+
+
+void GLAPIENTRY
+_mesa_ClearDepth( GLclampd depth )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glClearDepth(%f)\n", depth);
+
+ depth = CLAMP( depth, 0.0, 1.0 );
+
+ if (ctx->Depth.Clear == depth)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_DEPTH);
+ ctx->Depth.Clear = depth;
+ if (ctx->Driver.ClearDepth)
+ (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear );
+}
+
+
+void GLAPIENTRY
+_mesa_ClearDepthf( GLclampf depth )
+{
+ _mesa_ClearDepth(depth);
+}
+
+
+void GLAPIENTRY
+_mesa_DepthFunc( GLenum func )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glDepthFunc %s\n", _mesa_lookup_enum_by_nr(func));
+
+ switch (func) {
+ case GL_LESS: /* (default) pass if incoming z < stored z */
+ case GL_GEQUAL:
+ case GL_LEQUAL:
+ case GL_GREATER:
+ case GL_NOTEQUAL:
+ case GL_EQUAL:
+ case GL_ALWAYS:
+ case GL_NEVER:
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glDepth.Func" );
+ return;
+ }
+
+ if (ctx->Depth.Func == func)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_DEPTH);
+ ctx->Depth.Func = func;
+
+ if (ctx->Driver.DepthFunc)
+ ctx->Driver.DepthFunc( ctx, func );
+}
+
+
+
+void GLAPIENTRY
+_mesa_DepthMask( GLboolean flag )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glDepthMask %d\n", flag);
+
+ /*
+ * GL_TRUE indicates depth buffer writing is enabled (default)
+ * GL_FALSE indicates depth buffer writing is disabled
+ */
+ if (ctx->Depth.Mask == flag)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_DEPTH);
+ ctx->Depth.Mask = flag;
+
+ if (ctx->Driver.DepthMask)
+ ctx->Driver.DepthMask( ctx, flag );
+}
+
+
+
+/**
+ * Specified by the GL_EXT_depth_bounds_test extension.
+ */
+void GLAPIENTRY
+_mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax);
+
+ if (zmin > zmax) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)");
+ return;
+ }
+
+ zmin = CLAMP(zmin, 0.0, 1.0);
+ zmax = CLAMP(zmax, 0.0, 1.0);
+
+ if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_DEPTH);
+ ctx->Depth.BoundsMin = (GLfloat) zmin;
+ ctx->Depth.BoundsMax = (GLfloat) zmax;
+}
+
+
+/**********************************************************************/
+/***** Initialization *****/
+/**********************************************************************/
+
+
+/**
+ * Initialize the depth buffer attribute group in the given context.
+ */
+void
+_mesa_init_depth(struct gl_context *ctx)
+{
+ ctx->Depth.Test = GL_FALSE;
+ ctx->Depth.Clear = 1.0;
+ ctx->Depth.Func = GL_LESS;
+ ctx->Depth.Mask = GL_TRUE;
+}
diff --git a/mesalib/src/mesa/main/dlist.c b/mesalib/src/mesa/main/dlist.c
index 4e463dd06..e910296ed 100644
--- a/mesalib/src/mesa/main/dlist.c
+++ b/mesalib/src/mesa/main/dlist.c
@@ -1,10333 +1,10333 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.7
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file dlist.c
- * Display lists management functions.
- */
-
-#include "glheader.h"
-#include "imports.h"
-#include "api_arrayelt.h"
-#include "api_exec.h"
-#include "api_loopback.h"
-#if FEATURE_ATI_fragment_shader
-#include "atifragshader.h"
-#endif
-#include "config.h"
-#include "mfeatures.h"
-#if FEATURE_ARB_vertex_buffer_object
-#include "bufferobj.h"
-#endif
-#include "arrayobj.h"
-#include "context.h"
-#include "dlist.h"
-#include "enums.h"
-#include "eval.h"
-#include "framebuffer.h"
-#include "glapi/glapi.h"
-#include "hash.h"
-#include "image.h"
-#include "light.h"
-#include "macros.h"
-#include "pack.h"
-#include "pbo.h"
-#include "queryobj.h"
-#include "teximage.h"
-#include "mtypes.h"
-#include "varray.h"
-#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
-#include "arbprogram.h"
-#endif
-#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
-#include "nvprogram.h"
-#endif
-
-#include "math/m_matrix.h"
-
-#include "main/dispatch.h"
-
-
-
-/**
- * Other parts of Mesa (such as the VBO module) can plug into the display
- * list system. This structure describes new display list instructions.
- */
-struct gl_list_instruction
-{
- GLuint Size;
- void (*Execute)( struct gl_context *ctx, void *data );
- void (*Destroy)( struct gl_context *ctx, void *data );
- void (*Print)( struct gl_context *ctx, void *data );
-};
-
-
-#define MAX_DLIST_EXT_OPCODES 16
-
-/**
- * Used by device drivers to hook new commands into display lists.
- */
-struct gl_list_extensions
-{
- struct gl_list_instruction Opcode[MAX_DLIST_EXT_OPCODES];
- GLuint NumOpcodes;
-};
-
-
-
-/**
- * Flush vertices.
- *
- * \param ctx GL context.
- *
- * Checks if dd_function_table::SaveNeedFlush is marked to flush
- * stored (save) vertices, and calls
- * dd_function_table::SaveFlushVertices if so.
- */
-#define SAVE_FLUSH_VERTICES(ctx) \
-do { \
- if (ctx->Driver.SaveNeedFlush) \
- ctx->Driver.SaveFlushVertices(ctx); \
-} while (0)
-
-
-/**
- * Macro to assert that the API call was made outside the
- * glBegin()/glEnd() pair, with return value.
- *
- * \param ctx GL context.
- * \param retval value to return value in case the assertion fails.
- */
-#define ASSERT_OUTSIDE_SAVE_BEGIN_END_WITH_RETVAL(ctx, retval) \
-do { \
- if (ctx->Driver.CurrentSavePrimitive <= GL_POLYGON || \
- ctx->Driver.CurrentSavePrimitive == PRIM_INSIDE_UNKNOWN_PRIM) { \
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
- return retval; \
- } \
-} while (0)
-
-/**
- * Macro to assert that the API call was made outside the
- * glBegin()/glEnd() pair.
- *
- * \param ctx GL context.
- */
-#define ASSERT_OUTSIDE_SAVE_BEGIN_END(ctx) \
-do { \
- if (ctx->Driver.CurrentSavePrimitive <= GL_POLYGON || \
- ctx->Driver.CurrentSavePrimitive == PRIM_INSIDE_UNKNOWN_PRIM) { \
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
- return; \
- } \
-} while (0)
-
-/**
- * Macro to assert that the API call was made outside the
- * glBegin()/glEnd() pair and flush the vertices.
- *
- * \param ctx GL context.
- */
-#define ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx) \
-do { \
- ASSERT_OUTSIDE_SAVE_BEGIN_END(ctx); \
- SAVE_FLUSH_VERTICES(ctx); \
-} while (0)
-
-/**
- * Macro to assert that the API call was made outside the
- * glBegin()/glEnd() pair and flush the vertices, with return value.
- *
- * \param ctx GL context.
- * \param retval value to return value in case the assertion fails.
- */
-#define ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval)\
-do { \
- ASSERT_OUTSIDE_SAVE_BEGIN_END_WITH_RETVAL(ctx, retval); \
- SAVE_FLUSH_VERTICES(ctx); \
-} while (0)
-
-
-
-/**
- * Display list opcodes.
- *
- * The fact that these identifiers are assigned consecutive
- * integer values starting at 0 is very important, see InstSize array usage)
- */
-typedef enum
-{
- OPCODE_INVALID = -1, /* Force signed enum */
- OPCODE_ACCUM,
- OPCODE_ALPHA_FUNC,
- OPCODE_BIND_TEXTURE,
- OPCODE_BITMAP,
- OPCODE_BLEND_COLOR,
- OPCODE_BLEND_EQUATION,
- OPCODE_BLEND_EQUATION_SEPARATE,
- OPCODE_BLEND_FUNC_SEPARATE,
-
- OPCODE_BLEND_EQUATION_I,
- OPCODE_BLEND_EQUATION_SEPARATE_I,
- OPCODE_BLEND_FUNC_I,
- OPCODE_BLEND_FUNC_SEPARATE_I,
-
- OPCODE_CALL_LIST,
- OPCODE_CALL_LIST_OFFSET,
- OPCODE_CLEAR,
- OPCODE_CLEAR_ACCUM,
- OPCODE_CLEAR_COLOR,
- OPCODE_CLEAR_DEPTH,
- OPCODE_CLEAR_INDEX,
- OPCODE_CLEAR_STENCIL,
- OPCODE_CLEAR_BUFFER_IV,
- OPCODE_CLEAR_BUFFER_UIV,
- OPCODE_CLEAR_BUFFER_FV,
- OPCODE_CLEAR_BUFFER_FI,
- OPCODE_CLIP_PLANE,
- OPCODE_COLOR_MASK,
- OPCODE_COLOR_MASK_INDEXED,
- OPCODE_COLOR_MATERIAL,
- OPCODE_COLOR_TABLE,
- OPCODE_COLOR_TABLE_PARAMETER_FV,
- OPCODE_COLOR_TABLE_PARAMETER_IV,
- OPCODE_COLOR_SUB_TABLE,
- OPCODE_CONVOLUTION_FILTER_1D,
- OPCODE_CONVOLUTION_FILTER_2D,
- OPCODE_CONVOLUTION_PARAMETER_I,
- OPCODE_CONVOLUTION_PARAMETER_IV,
- OPCODE_CONVOLUTION_PARAMETER_F,
- OPCODE_CONVOLUTION_PARAMETER_FV,
- OPCODE_COPY_COLOR_SUB_TABLE,
- OPCODE_COPY_COLOR_TABLE,
- OPCODE_COPY_PIXELS,
- OPCODE_COPY_TEX_IMAGE1D,
- OPCODE_COPY_TEX_IMAGE2D,
- OPCODE_COPY_TEX_SUB_IMAGE1D,
- OPCODE_COPY_TEX_SUB_IMAGE2D,
- OPCODE_COPY_TEX_SUB_IMAGE3D,
- OPCODE_CULL_FACE,
- OPCODE_DEPTH_FUNC,
- OPCODE_DEPTH_MASK,
- OPCODE_DEPTH_RANGE,
- OPCODE_DISABLE,
- OPCODE_DISABLE_INDEXED,
- OPCODE_DRAW_BUFFER,
- OPCODE_DRAW_PIXELS,
- OPCODE_ENABLE,
- OPCODE_ENABLE_INDEXED,
- OPCODE_EVALMESH1,
- OPCODE_EVALMESH2,
- OPCODE_FOG,
- OPCODE_FRONT_FACE,
- OPCODE_FRUSTUM,
- OPCODE_HINT,
- OPCODE_HISTOGRAM,
- OPCODE_INDEX_MASK,
- OPCODE_INIT_NAMES,
- OPCODE_LIGHT,
- OPCODE_LIGHT_MODEL,
- OPCODE_LINE_STIPPLE,
- OPCODE_LINE_WIDTH,
- OPCODE_LIST_BASE,
- OPCODE_LOAD_IDENTITY,
- OPCODE_LOAD_MATRIX,
- OPCODE_LOAD_NAME,
- OPCODE_LOGIC_OP,
- OPCODE_MAP1,
- OPCODE_MAP2,
- OPCODE_MAPGRID1,
- OPCODE_MAPGRID2,
- OPCODE_MATRIX_MODE,
- OPCODE_MIN_MAX,
- OPCODE_MULT_MATRIX,
- OPCODE_ORTHO,
- OPCODE_PASSTHROUGH,
- OPCODE_PIXEL_MAP,
- OPCODE_PIXEL_TRANSFER,
- OPCODE_PIXEL_ZOOM,
- OPCODE_POINT_SIZE,
- OPCODE_POINT_PARAMETERS,
- OPCODE_POLYGON_MODE,
- OPCODE_POLYGON_STIPPLE,
- OPCODE_POLYGON_OFFSET,
- OPCODE_POP_ATTRIB,
- OPCODE_POP_MATRIX,
- OPCODE_POP_NAME,
- OPCODE_PRIORITIZE_TEXTURE,
- OPCODE_PUSH_ATTRIB,
- OPCODE_PUSH_MATRIX,
- OPCODE_PUSH_NAME,
- OPCODE_RASTER_POS,
- OPCODE_READ_BUFFER,
- OPCODE_RESET_HISTOGRAM,
- OPCODE_RESET_MIN_MAX,
- OPCODE_ROTATE,
- OPCODE_SCALE,
- OPCODE_SCISSOR,
- OPCODE_SELECT_TEXTURE_SGIS,
- OPCODE_SELECT_TEXTURE_COORD_SET,
- OPCODE_SHADE_MODEL,
- OPCODE_STENCIL_FUNC,
- OPCODE_STENCIL_MASK,
- OPCODE_STENCIL_OP,
- OPCODE_TEXENV,
- OPCODE_TEXGEN,
- OPCODE_TEXPARAMETER,
- OPCODE_TEX_IMAGE1D,
- OPCODE_TEX_IMAGE2D,
- OPCODE_TEX_IMAGE3D,
- OPCODE_TEX_SUB_IMAGE1D,
- OPCODE_TEX_SUB_IMAGE2D,
- OPCODE_TEX_SUB_IMAGE3D,
- OPCODE_TRANSLATE,
- OPCODE_VIEWPORT,
- OPCODE_WINDOW_POS,
- /* GL_ARB_multitexture */
- OPCODE_ACTIVE_TEXTURE,
- /* GL_ARB_texture_compression */
- OPCODE_COMPRESSED_TEX_IMAGE_1D,
- OPCODE_COMPRESSED_TEX_IMAGE_2D,
- OPCODE_COMPRESSED_TEX_IMAGE_3D,
- OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D,
- OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D,
- OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D,
- /* GL_ARB_multisample */
- OPCODE_SAMPLE_COVERAGE,
- /* GL_ARB_window_pos */
- OPCODE_WINDOW_POS_ARB,
- /* GL_NV_vertex_program */
- OPCODE_BIND_PROGRAM_NV,
- OPCODE_EXECUTE_PROGRAM_NV,
- OPCODE_REQUEST_RESIDENT_PROGRAMS_NV,
- OPCODE_LOAD_PROGRAM_NV,
- OPCODE_TRACK_MATRIX_NV,
- /* GL_NV_fragment_program */
- OPCODE_PROGRAM_LOCAL_PARAMETER_ARB,
- OPCODE_PROGRAM_NAMED_PARAMETER_NV,
- /* GL_EXT_stencil_two_side */
- OPCODE_ACTIVE_STENCIL_FACE_EXT,
- /* GL_EXT_depth_bounds_test */
- OPCODE_DEPTH_BOUNDS_EXT,
- /* GL_ARB_vertex/fragment_program */
- OPCODE_PROGRAM_STRING_ARB,
- OPCODE_PROGRAM_ENV_PARAMETER_ARB,
- /* GL_ARB_occlusion_query */
- OPCODE_BEGIN_QUERY_ARB,
- OPCODE_END_QUERY_ARB,
- /* GL_ARB_draw_buffers */
- OPCODE_DRAW_BUFFERS_ARB,
- /* GL_ATI_fragment_shader */
- OPCODE_TEX_BUMP_PARAMETER_ATI,
- /* GL_ATI_fragment_shader */
- OPCODE_BIND_FRAGMENT_SHADER_ATI,
- OPCODE_SET_FRAGMENT_SHADER_CONSTANTS_ATI,
- /* OpenGL 2.0 */
- OPCODE_STENCIL_FUNC_SEPARATE,
- OPCODE_STENCIL_OP_SEPARATE,
- OPCODE_STENCIL_MASK_SEPARATE,
-
- /* GL_ARB_shader_objects */
- OPCODE_USE_PROGRAM,
- OPCODE_UNIFORM_1F,
- OPCODE_UNIFORM_2F,
- OPCODE_UNIFORM_3F,
- OPCODE_UNIFORM_4F,
- OPCODE_UNIFORM_1FV,
- OPCODE_UNIFORM_2FV,
- OPCODE_UNIFORM_3FV,
- OPCODE_UNIFORM_4FV,
- OPCODE_UNIFORM_1I,
- OPCODE_UNIFORM_2I,
- OPCODE_UNIFORM_3I,
- OPCODE_UNIFORM_4I,
- OPCODE_UNIFORM_1IV,
- OPCODE_UNIFORM_2IV,
- OPCODE_UNIFORM_3IV,
- OPCODE_UNIFORM_4IV,
- OPCODE_UNIFORM_MATRIX22,
- OPCODE_UNIFORM_MATRIX33,
- OPCODE_UNIFORM_MATRIX44,
- OPCODE_UNIFORM_MATRIX23,
- OPCODE_UNIFORM_MATRIX32,
- OPCODE_UNIFORM_MATRIX24,
- OPCODE_UNIFORM_MATRIX42,
- OPCODE_UNIFORM_MATRIX34,
- OPCODE_UNIFORM_MATRIX43,
-
- /* OpenGL 3.0 */
- OPCODE_UNIFORM_1UI,
- OPCODE_UNIFORM_2UI,
- OPCODE_UNIFORM_3UI,
- OPCODE_UNIFORM_4UI,
- OPCODE_UNIFORM_1UIV,
- OPCODE_UNIFORM_2UIV,
- OPCODE_UNIFORM_3UIV,
- OPCODE_UNIFORM_4UIV,
-
- /* GL_EXT_framebuffer_blit */
- OPCODE_BLIT_FRAMEBUFFER,
-
- /* Vertex attributes -- fallback for when optimized display
- * list build isn't active.
- */
- OPCODE_ATTR_1F_NV,
- OPCODE_ATTR_2F_NV,
- OPCODE_ATTR_3F_NV,
- OPCODE_ATTR_4F_NV,
- OPCODE_ATTR_1F_ARB,
- OPCODE_ATTR_2F_ARB,
- OPCODE_ATTR_3F_ARB,
- OPCODE_ATTR_4F_ARB,
- OPCODE_MATERIAL,
- OPCODE_BEGIN,
- OPCODE_END,
- OPCODE_RECTF,
- OPCODE_EVAL_C1,
- OPCODE_EVAL_C2,
- OPCODE_EVAL_P1,
- OPCODE_EVAL_P2,
-
- /* GL_EXT_provoking_vertex */
- OPCODE_PROVOKING_VERTEX,
-
- /* GL_EXT_transform_feedback */
- OPCODE_BEGIN_TRANSFORM_FEEDBACK,
- OPCODE_END_TRANSFORM_FEEDBACK,
-
- /* GL_EXT_texture_integer */
- OPCODE_CLEARCOLOR_I,
- OPCODE_CLEARCOLOR_UI,
- OPCODE_TEXPARAMETER_I,
- OPCODE_TEXPARAMETER_UI,
-
- /* GL_EXT_separate_shader_objects */
- OPCODE_ACTIVE_PROGRAM_EXT,
- OPCODE_USE_SHADER_PROGRAM_EXT,
-
- /* GL_ARB_instanced_arrays */
- OPCODE_VERTEX_ATTRIB_DIVISOR,
-
- /* The following three are meta instructions */
- OPCODE_ERROR, /* raise compiled-in error */
- OPCODE_CONTINUE,
- OPCODE_END_OF_LIST,
- OPCODE_EXT_0
-} OpCode;
-
-
-
-/**
- * Display list node.
- *
- * Display list instructions are stored as sequences of "nodes". Nodes
- * are allocated in blocks. Each block has BLOCK_SIZE nodes. Blocks
- * are linked together with a pointer.
- *
- * Each instruction in the display list is stored as a sequence of
- * contiguous nodes in memory.
- * Each node is the union of a variety of data types.
- */
-union gl_dlist_node
-{
- OpCode opcode;
- GLboolean b;
- GLbitfield bf;
- GLubyte ub;
- GLshort s;
- GLushort us;
- GLint i;
- GLuint ui;
- GLenum e;
- GLfloat f;
- GLvoid *data;
- void *next; /* If prev node's opcode==OPCODE_CONTINUE */
-};
-
-
-typedef union gl_dlist_node Node;
-
-
-/**
- * How many nodes to allocate at a time.
- *
- * \note Reduced now that we hold vertices etc. elsewhere.
- */
-#define BLOCK_SIZE 256
-
-
-
-/**
- * Number of nodes of storage needed for each instruction.
- * Sizes for dynamically allocated opcodes are stored in the context struct.
- */
-static GLuint InstSize[OPCODE_END_OF_LIST + 1];
-
-
-#if FEATURE_dlist
-
-
-void mesa_print_display_list(GLuint list);
-
-
-/**********************************************************************/
-/***** Private *****/
-/**********************************************************************/
-
-
-/**
- * Make an empty display list. This is used by glGenLists() to
- * reserve display list IDs.
- */
-static struct gl_display_list *
-make_list(GLuint name, GLuint count)
-{
- struct gl_display_list *dlist = CALLOC_STRUCT(gl_display_list);
- dlist->Name = name;
- dlist->Head = (Node *) malloc(sizeof(Node) * count);
- dlist->Head[0].opcode = OPCODE_END_OF_LIST;
- return dlist;
-}
-
-
-/**
- * Lookup function to just encapsulate casting.
- */
-static INLINE struct gl_display_list *
-lookup_list(struct gl_context *ctx, GLuint list)
-{
- return (struct gl_display_list *)
- _mesa_HashLookup(ctx->Shared->DisplayList, list);
-}
-
-
-/** Is the given opcode an extension code? */
-static INLINE GLboolean
-is_ext_opcode(OpCode opcode)
-{
- return (opcode >= OPCODE_EXT_0);
-}
-
-
-/** Destroy an extended opcode instruction */
-static GLint
-ext_opcode_destroy(struct gl_context *ctx, Node *node)
-{
- const GLint i = node[0].opcode - OPCODE_EXT_0;
- GLint step;
- ctx->ListExt->Opcode[i].Destroy(ctx, &node[1]);
- step = ctx->ListExt->Opcode[i].Size;
- return step;
-}
-
-
-/** Execute an extended opcode instruction */
-static GLint
-ext_opcode_execute(struct gl_context *ctx, Node *node)
-{
- const GLint i = node[0].opcode - OPCODE_EXT_0;
- GLint step;
- ctx->ListExt->Opcode[i].Execute(ctx, &node[1]);
- step = ctx->ListExt->Opcode[i].Size;
- return step;
-}
-
-
-/** Print an extended opcode instruction */
-static GLint
-ext_opcode_print(struct gl_context *ctx, Node *node)
-{
- const GLint i = node[0].opcode - OPCODE_EXT_0;
- GLint step;
- ctx->ListExt->Opcode[i].Print(ctx, &node[1]);
- step = ctx->ListExt->Opcode[i].Size;
- return step;
-}
-
-
-/**
- * Delete the named display list, but don't remove from hash table.
- * \param dlist - display list pointer
- */
-void
-_mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist)
-{
- Node *n, *block;
- GLboolean done;
-
- n = block = dlist->Head;
-
- done = block ? GL_FALSE : GL_TRUE;
- while (!done) {
- const OpCode opcode = n[0].opcode;
-
- /* check for extension opcodes first */
- if (is_ext_opcode(opcode)) {
- n += ext_opcode_destroy(ctx, n);
- }
- else {
- switch (opcode) {
- /* for some commands, we need to free malloc'd memory */
- case OPCODE_MAP1:
- free(n[6].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_MAP2:
- free(n[10].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_DRAW_PIXELS:
- free(n[5].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_BITMAP:
- free(n[7].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_COLOR_TABLE:
- free(n[6].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_COLOR_SUB_TABLE:
- free(n[6].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_CONVOLUTION_FILTER_1D:
- free(n[6].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_CONVOLUTION_FILTER_2D:
- free(n[7].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_POLYGON_STIPPLE:
- free(n[1].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_TEX_IMAGE1D:
- free(n[8].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_TEX_IMAGE2D:
- free(n[9].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_TEX_IMAGE3D:
- free(n[10].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_TEX_SUB_IMAGE1D:
- free(n[7].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_TEX_SUB_IMAGE2D:
- free(n[9].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_TEX_SUB_IMAGE3D:
- free(n[11].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_COMPRESSED_TEX_IMAGE_1D:
- free(n[7].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_COMPRESSED_TEX_IMAGE_2D:
- free(n[8].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_COMPRESSED_TEX_IMAGE_3D:
- free(n[9].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D:
- free(n[7].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D:
- free(n[9].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D:
- free(n[11].data);
- n += InstSize[n[0].opcode];
- break;
-#if FEATURE_NV_vertex_program
- case OPCODE_LOAD_PROGRAM_NV:
- free(n[4].data); /* program string */
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_REQUEST_RESIDENT_PROGRAMS_NV:
- free(n[2].data); /* array of program ids */
- n += InstSize[n[0].opcode];
- break;
-#endif
-#if FEATURE_NV_fragment_program
- case OPCODE_PROGRAM_NAMED_PARAMETER_NV:
- free(n[3].data); /* parameter name */
- n += InstSize[n[0].opcode];
- break;
-#endif
-#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
- case OPCODE_PROGRAM_STRING_ARB:
- free(n[4].data); /* program string */
- n += InstSize[n[0].opcode];
- break;
-#endif
- case OPCODE_UNIFORM_1FV:
- case OPCODE_UNIFORM_2FV:
- case OPCODE_UNIFORM_3FV:
- case OPCODE_UNIFORM_4FV:
- case OPCODE_UNIFORM_1IV:
- case OPCODE_UNIFORM_2IV:
- case OPCODE_UNIFORM_3IV:
- case OPCODE_UNIFORM_4IV:
- case OPCODE_UNIFORM_1UIV:
- case OPCODE_UNIFORM_2UIV:
- case OPCODE_UNIFORM_3UIV:
- case OPCODE_UNIFORM_4UIV:
- free(n[3].data);
- n += InstSize[n[0].opcode];
- break;
- case OPCODE_UNIFORM_MATRIX22:
- case OPCODE_UNIFORM_MATRIX33:
- case OPCODE_UNIFORM_MATRIX44:
- case OPCODE_UNIFORM_MATRIX24:
- case OPCODE_UNIFORM_MATRIX42:
- case OPCODE_UNIFORM_MATRIX23:
- case OPCODE_UNIFORM_MATRIX32:
- case OPCODE_UNIFORM_MATRIX34:
- case OPCODE_UNIFORM_MATRIX43:
- free(n[4].data);
- n += InstSize[n[0].opcode];
- break;
-
- case OPCODE_CONTINUE:
- n = (Node *) n[1].next;
- free(block);
- block = n;
- break;
- case OPCODE_END_OF_LIST:
- free(block);
- done = GL_TRUE;
- break;
- default:
- /* Most frequent case */
- n += InstSize[n[0].opcode];
- break;
- }
- }
- }
-
- free(dlist);
-}
-
-
-/**
- * Destroy a display list and remove from hash table.
- * \param list - display list number
- */
-static void
-destroy_list(struct gl_context *ctx, GLuint list)
-{
- struct gl_display_list *dlist;
-
- if (list == 0)
- return;
-
- dlist = lookup_list(ctx, list);
- if (!dlist)
- return;
-
- _mesa_delete_list(ctx, dlist);
- _mesa_HashRemove(ctx->Shared->DisplayList, list);
-}
-
-
-/*
- * Translate the nth element of list from <type> to GLint.
- */
-static GLint
-translate_id(GLsizei n, GLenum type, const GLvoid * list)
-{
- GLbyte *bptr;
- GLubyte *ubptr;
- GLshort *sptr;
- GLushort *usptr;
- GLint *iptr;
- GLuint *uiptr;
- GLfloat *fptr;
-
- switch (type) {
- case GL_BYTE:
- bptr = (GLbyte *) list;
- return (GLint) bptr[n];
- case GL_UNSIGNED_BYTE:
- ubptr = (GLubyte *) list;
- return (GLint) ubptr[n];
- case GL_SHORT:
- sptr = (GLshort *) list;
- return (GLint) sptr[n];
- case GL_UNSIGNED_SHORT:
- usptr = (GLushort *) list;
- return (GLint) usptr[n];
- case GL_INT:
- iptr = (GLint *) list;
- return iptr[n];
- case GL_UNSIGNED_INT:
- uiptr = (GLuint *) list;
- return (GLint) uiptr[n];
- case GL_FLOAT:
- fptr = (GLfloat *) list;
- return (GLint) FLOORF(fptr[n]);
- case GL_2_BYTES:
- ubptr = ((GLubyte *) list) + 2 * n;
- return (GLint) ubptr[0] * 256
- + (GLint) ubptr[1];
- case GL_3_BYTES:
- ubptr = ((GLubyte *) list) + 3 * n;
- return (GLint) ubptr[0] * 65536
- + (GLint) ubptr[1] * 256
- + (GLint) ubptr[2];
- case GL_4_BYTES:
- ubptr = ((GLubyte *) list) + 4 * n;
- return (GLint) ubptr[0] * 16777216
- + (GLint) ubptr[1] * 65536
- + (GLint) ubptr[2] * 256
- + (GLint) ubptr[3];
- default:
- return 0;
- }
-}
-
-
-
-
-/**********************************************************************/
-/***** Public *****/
-/**********************************************************************/
-
-/**
- * Wrapper for _mesa_unpack_image() that handles pixel buffer objects.
- * If we run out of memory, GL_OUT_OF_MEMORY will be recorded.
- */
-static GLvoid *
-unpack_image(struct gl_context *ctx, GLuint dimensions,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLenum type, const GLvoid * pixels,
- const struct gl_pixelstore_attrib *unpack)
-{
- if (!_mesa_is_bufferobj(unpack->BufferObj)) {
- /* no PBO */
- GLvoid *image = _mesa_unpack_image(dimensions, width, height, depth,
- format, type, pixels, unpack);
- if (pixels && !image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "display list construction");
- }
- return image;
- }
- else if (_mesa_validate_pbo_access(dimensions, unpack, width, height, depth,
- format, type, pixels)) {
- const GLubyte *map, *src;
- GLvoid *image;
-
- map = (GLubyte *)
- ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_READ_ONLY_ARB, unpack->BufferObj);
- if (!map) {
- /* unable to map src buffer! */
- _mesa_error(ctx, GL_INVALID_OPERATION, "unable to map PBO");
- return NULL;
- }
-
- src = ADD_POINTERS(map, pixels);
- image = _mesa_unpack_image(dimensions, width, height, depth,
- format, type, src, unpack);
-
- ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
- unpack->BufferObj);
-
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "display list construction");
- }
- return image;
- }
- /* bad access! */
- return NULL;
-}
-
-
-/**
- * Allocate space for a display list instruction (opcode + payload space).
- * \param opcode the instruction opcode (OPCODE_* value)
- * \param bytes instruction payload size (not counting opcode)
- * \return pointer to allocated memory (the opcode space)
- */
-static Node *
-dlist_alloc(struct gl_context *ctx, OpCode opcode, GLuint bytes)
-{
- const GLuint numNodes = 1 + (bytes + sizeof(Node) - 1) / sizeof(Node);
- Node *n;
-
- if (opcode < (GLuint) OPCODE_EXT_0) {
- if (InstSize[opcode] == 0) {
- /* save instruction size now */
- InstSize[opcode] = numNodes;
- }
- else {
- /* make sure instruction size agrees */
- ASSERT(numNodes == InstSize[opcode]);
- }
- }
-
- if (ctx->ListState.CurrentPos + numNodes + 2 > BLOCK_SIZE) {
- /* This block is full. Allocate a new block and chain to it */
- Node *newblock;
- n = ctx->ListState.CurrentBlock + ctx->ListState.CurrentPos;
- n[0].opcode = OPCODE_CONTINUE;
- newblock = (Node *) malloc(sizeof(Node) * BLOCK_SIZE);
- if (!newblock) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "Building display list");
- return NULL;
- }
- n[1].next = (Node *) newblock;
- ctx->ListState.CurrentBlock = newblock;
- ctx->ListState.CurrentPos = 0;
- }
-
- n = ctx->ListState.CurrentBlock + ctx->ListState.CurrentPos;
- ctx->ListState.CurrentPos += numNodes;
-
- n[0].opcode = opcode;
-
- return n;
-}
-
-
-
-/**
- * Allocate space for a display list instruction. Used by callers outside
- * this file for things like VBO vertex data.
- *
- * \param opcode the instruction opcode (OPCODE_* value)
- * \param bytes instruction size in bytes, not counting opcode.
- * \return pointer to the usable data area (not including the internal
- * opcode).
- */
-void *
-_mesa_dlist_alloc(struct gl_context *ctx, GLuint opcode, GLuint bytes)
-{
- Node *n = dlist_alloc(ctx, (OpCode) opcode, bytes);
- if (n)
- return n + 1; /* return pointer to payload area, after opcode */
- else
- return NULL;
-}
-
-
-/**
- * This function allows modules and drivers to get their own opcodes
- * for extending display list functionality.
- * \param ctx the rendering context
- * \param size number of bytes for storing the new display list command
- * \param execute function to execute the new display list command
- * \param destroy function to destroy the new display list command
- * \param print function to print the new display list command
- * \return the new opcode number or -1 if error
- */
-GLint
-_mesa_dlist_alloc_opcode(struct gl_context *ctx,
- GLuint size,
- void (*execute) (struct gl_context *, void *),
- void (*destroy) (struct gl_context *, void *),
- void (*print) (struct gl_context *, void *))
-{
- if (ctx->ListExt->NumOpcodes < MAX_DLIST_EXT_OPCODES) {
- const GLuint i = ctx->ListExt->NumOpcodes++;
- ctx->ListExt->Opcode[i].Size =
- 1 + (size + sizeof(Node) - 1) / sizeof(Node);
- ctx->ListExt->Opcode[i].Execute = execute;
- ctx->ListExt->Opcode[i].Destroy = destroy;
- ctx->ListExt->Opcode[i].Print = print;
- return i + OPCODE_EXT_0;
- }
- return -1;
-}
-
-
-/**
- * Allocate space for a display list instruction. The space is basically
- * an array of Nodes where node[0] holds the opcode, node[1] is the first
- * function parameter, node[2] is the second parameter, etc.
- *
- * \param opcode one of OPCODE_x
- * \param nparams number of function parameters
- * \return pointer to start of instruction space
- */
-static INLINE Node *
-alloc_instruction(struct gl_context *ctx, OpCode opcode, GLuint nparams)
-{
- return dlist_alloc(ctx, opcode, nparams * sizeof(Node));
-}
-
-
-
-/*
- * Display List compilation functions
- */
-static void GLAPIENTRY
-save_Accum(GLenum op, GLfloat value)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_ACCUM, 2);
- if (n) {
- n[1].e = op;
- n[2].f = value;
- }
- if (ctx->ExecuteFlag) {
- CALL_Accum(ctx->Exec, (op, value));
- }
-}
-
-
-static void GLAPIENTRY
-save_AlphaFunc(GLenum func, GLclampf ref)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_ALPHA_FUNC, 2);
- if (n) {
- n[1].e = func;
- n[2].f = (GLfloat) ref;
- }
- if (ctx->ExecuteFlag) {
- CALL_AlphaFunc(ctx->Exec, (func, ref));
- }
-}
-
-
-static void GLAPIENTRY
-save_BindTexture(GLenum target, GLuint texture)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BIND_TEXTURE, 2);
- if (n) {
- n[1].e = target;
- n[2].ui = texture;
- }
- if (ctx->ExecuteFlag) {
- CALL_BindTexture(ctx->Exec, (target, texture));
- }
-}
-
-
-static void GLAPIENTRY
-save_Bitmap(GLsizei width, GLsizei height,
- GLfloat xorig, GLfloat yorig,
- GLfloat xmove, GLfloat ymove, const GLubyte * pixels)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BITMAP, 7);
- if (n) {
- n[1].i = (GLint) width;
- n[2].i = (GLint) height;
- n[3].f = xorig;
- n[4].f = yorig;
- n[5].f = xmove;
- n[6].f = ymove;
- n[7].data = _mesa_unpack_bitmap(width, height, pixels, &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_Bitmap(ctx->Exec, (width, height,
- xorig, yorig, xmove, ymove, pixels));
- }
-}
-
-
-static void GLAPIENTRY
-save_BlendEquation(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION, 1);
- if (n) {
- n[1].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_BlendEquation(ctx->Exec, (mode));
- }
-}
-
-
-static void GLAPIENTRY
-save_BlendEquationSeparateEXT(GLenum modeRGB, GLenum modeA)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION_SEPARATE, 2);
- if (n) {
- n[1].e = modeRGB;
- n[2].e = modeA;
- }
- if (ctx->ExecuteFlag) {
- CALL_BlendEquationSeparateEXT(ctx->Exec, (modeRGB, modeA));
- }
-}
-
-
-static void GLAPIENTRY
-save_BlendFuncSeparateEXT(GLenum sfactorRGB, GLenum dfactorRGB,
- GLenum sfactorA, GLenum dfactorA)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BLEND_FUNC_SEPARATE, 4);
- if (n) {
- n[1].e = sfactorRGB;
- n[2].e = dfactorRGB;
- n[3].e = sfactorA;
- n[4].e = dfactorA;
- }
- if (ctx->ExecuteFlag) {
- CALL_BlendFuncSeparateEXT(ctx->Exec,
- (sfactorRGB, dfactorRGB, sfactorA, dfactorA));
- }
-}
-
-
-static void GLAPIENTRY
-save_BlendFunc(GLenum srcfactor, GLenum dstfactor)
-{
- save_BlendFuncSeparateEXT(srcfactor, dstfactor, srcfactor, dstfactor);
-}
-
-
-static void GLAPIENTRY
-save_BlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BLEND_COLOR, 4);
- if (n) {
- n[1].f = red;
- n[2].f = green;
- n[3].f = blue;
- n[4].f = alpha;
- }
- if (ctx->ExecuteFlag) {
- CALL_BlendColor(ctx->Exec, (red, green, blue, alpha));
- }
-}
-
-/* GL_ARB_draw_buffers_blend */
-static void GLAPIENTRY
-save_BlendFuncSeparatei(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB,
- GLenum sfactorA, GLenum dfactorA)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BLEND_FUNC_SEPARATE_I, 5);
- if (n) {
- n[1].ui = buf;
- n[2].e = sfactorRGB;
- n[3].e = dfactorRGB;
- n[4].e = sfactorA;
- n[5].e = dfactorA;
- }
- if (ctx->ExecuteFlag) {
- CALL_BlendFuncSeparateiARB(ctx->Exec, (buf, sfactorRGB, dfactorRGB,
- sfactorA, dfactorA));
- }
-}
-
-/* GL_ARB_draw_buffers_blend */
-static void GLAPIENTRY
-save_BlendFunci(GLuint buf, GLenum sfactor, GLenum dfactor)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BLEND_FUNC_SEPARATE_I, 3);
- if (n) {
- n[1].ui = buf;
- n[2].e = sfactor;
- n[3].e = dfactor;
- }
- if (ctx->ExecuteFlag) {
- CALL_BlendFunciARB(ctx->Exec, (buf, sfactor, dfactor));
- }
-}
-
-/* GL_ARB_draw_buffers_blend */
-static void GLAPIENTRY
-save_BlendEquationi(GLuint buf, GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION_I, 2);
- if (n) {
- n[1].ui = buf;
- n[2].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_BlendEquationiARB(ctx->Exec, (buf, mode));
- }
-}
-
-/* GL_ARB_draw_buffers_blend */
-static void GLAPIENTRY
-save_BlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeA)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION_SEPARATE_I, 3);
- if (n) {
- n[1].ui = buf;
- n[2].e = modeRGB;
- n[3].e = modeA;
- }
- if (ctx->ExecuteFlag) {
- CALL_BlendEquationSeparateiARB(ctx->Exec, (buf, modeRGB, modeA));
- }
-}
-
-
-static void invalidate_saved_current_state( struct gl_context *ctx )
-{
- GLint i;
-
- for (i = 0; i < VERT_ATTRIB_MAX; i++)
- ctx->ListState.ActiveAttribSize[i] = 0;
-
- for (i = 0; i < MAT_ATTRIB_MAX; i++)
- ctx->ListState.ActiveMaterialSize[i] = 0;
-
- memset(&ctx->ListState.Current, 0, sizeof ctx->ListState.Current);
-
- ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
-}
-
-static void GLAPIENTRY
-save_CallList(GLuint list)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
-
- n = alloc_instruction(ctx, OPCODE_CALL_LIST, 1);
- if (n) {
- n[1].ui = list;
- }
-
- /* After this, we don't know what state we're in. Invalidate all
- * cached information previously gathered:
- */
- invalidate_saved_current_state( ctx );
-
- if (ctx->ExecuteFlag) {
- _mesa_CallList(list);
- }
-}
-
-
-static void GLAPIENTRY
-save_CallLists(GLsizei num, GLenum type, const GLvoid * lists)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i;
- GLboolean typeErrorFlag;
-
- SAVE_FLUSH_VERTICES(ctx);
-
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- case GL_2_BYTES:
- case GL_3_BYTES:
- case GL_4_BYTES:
- typeErrorFlag = GL_FALSE;
- break;
- default:
- typeErrorFlag = GL_TRUE;
- }
-
- for (i = 0; i < num; i++) {
- GLint list = translate_id(i, type, lists);
- Node *n = alloc_instruction(ctx, OPCODE_CALL_LIST_OFFSET, 2);
- if (n) {
- n[1].i = list;
- n[2].b = typeErrorFlag;
- }
- }
-
- /* After this, we don't know what state we're in. Invalidate all
- * cached information previously gathered:
- */
- invalidate_saved_current_state( ctx );
-
- if (ctx->ExecuteFlag) {
- CALL_CallLists(ctx->Exec, (num, type, lists));
- }
-}
-
-
-static void GLAPIENTRY
-save_Clear(GLbitfield mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEAR, 1);
- if (n) {
- n[1].bf = mask;
- }
- if (ctx->ExecuteFlag) {
- CALL_Clear(ctx->Exec, (mask));
- }
-}
-
-
-static void GLAPIENTRY
-save_ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *value)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_IV, 6);
- if (n) {
- n[1].e = buffer;
- n[2].i = drawbuffer;
- n[3].i = value[0];
- if (buffer == GL_COLOR) {
- n[4].i = value[1];
- n[5].i = value[2];
- n[6].i = value[3];
- }
- else {
- n[4].i = 0;
- n[5].i = 0;
- n[6].i = 0;
- }
- }
- if (ctx->ExecuteFlag) {
- /*CALL_ClearBufferiv(ctx->Exec, (buffer, drawbuffer, value));*/
- }
-}
-
-
-static void GLAPIENTRY
-save_ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *value)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_UIV, 6);
- if (n) {
- n[1].e = buffer;
- n[2].i = drawbuffer;
- n[3].ui = value[0];
- if (buffer == GL_COLOR) {
- n[4].ui = value[1];
- n[5].ui = value[2];
- n[6].ui = value[3];
- }
- else {
- n[4].ui = 0;
- n[5].ui = 0;
- n[6].ui = 0;
- }
- }
- if (ctx->ExecuteFlag) {
- /*CALL_ClearBufferuiv(ctx->Exec, (buffer, drawbuffer, value));*/
- }
-}
-
-
-static void GLAPIENTRY
-save_ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *value)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_FV, 6);
- if (n) {
- n[1].e = buffer;
- n[2].i = drawbuffer;
- n[3].f = value[0];
- if (buffer == GL_COLOR) {
- n[4].f = value[1];
- n[5].f = value[2];
- n[6].f = value[3];
- }
- else {
- n[4].f = 0.0F;
- n[5].f = 0.0F;
- n[6].f = 0.0F;
- }
- }
- if (ctx->ExecuteFlag) {
- /*CALL_ClearBufferuiv(ctx->Exec, (buffer, drawbuffer, value));*/
- }
-}
-
-
-static void GLAPIENTRY
-save_ClearBufferfi(GLenum buffer, GLint drawbuffer,
- GLfloat depth, GLint stencil)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_FI, 4);
- if (n) {
- n[1].e = buffer;
- n[2].i = drawbuffer;
- n[3].f = depth;
- n[4].i = stencil;
- }
- if (ctx->ExecuteFlag) {
- /*CALL_ClearBufferfi(ctx->Exec, (buffer, drawbuffer, depth, stencil));*/
- }
-}
-
-
-static void GLAPIENTRY
-save_ClearAccum(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEAR_ACCUM, 4);
- if (n) {
- n[1].f = red;
- n[2].f = green;
- n[3].f = blue;
- n[4].f = alpha;
- }
- if (ctx->ExecuteFlag) {
- CALL_ClearAccum(ctx->Exec, (red, green, blue, alpha));
- }
-}
-
-
-static void GLAPIENTRY
-save_ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEAR_COLOR, 4);
- if (n) {
- n[1].f = red;
- n[2].f = green;
- n[3].f = blue;
- n[4].f = alpha;
- }
- if (ctx->ExecuteFlag) {
- CALL_ClearColor(ctx->Exec, (red, green, blue, alpha));
- }
-}
-
-
-static void GLAPIENTRY
-save_ClearDepth(GLclampd depth)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEAR_DEPTH, 1);
- if (n) {
- n[1].f = (GLfloat) depth;
- }
- if (ctx->ExecuteFlag) {
- CALL_ClearDepth(ctx->Exec, (depth));
- }
-}
-
-
-static void GLAPIENTRY
-save_ClearIndex(GLfloat c)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEAR_INDEX, 1);
- if (n) {
- n[1].f = c;
- }
- if (ctx->ExecuteFlag) {
- CALL_ClearIndex(ctx->Exec, (c));
- }
-}
-
-
-static void GLAPIENTRY
-save_ClearStencil(GLint s)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEAR_STENCIL, 1);
- if (n) {
- n[1].i = s;
- }
- if (ctx->ExecuteFlag) {
- CALL_ClearStencil(ctx->Exec, (s));
- }
-}
-
-
-static void GLAPIENTRY
-save_ClipPlane(GLenum plane, const GLdouble * equ)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLIP_PLANE, 5);
- if (n) {
- n[1].e = plane;
- n[2].f = (GLfloat) equ[0];
- n[3].f = (GLfloat) equ[1];
- n[4].f = (GLfloat) equ[2];
- n[5].f = (GLfloat) equ[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_ClipPlane(ctx->Exec, (plane, equ));
- }
-}
-
-
-
-static void GLAPIENTRY
-save_ColorMask(GLboolean red, GLboolean green,
- GLboolean blue, GLboolean alpha)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COLOR_MASK, 4);
- if (n) {
- n[1].b = red;
- n[2].b = green;
- n[3].b = blue;
- n[4].b = alpha;
- }
- if (ctx->ExecuteFlag) {
- CALL_ColorMask(ctx->Exec, (red, green, blue, alpha));
- }
-}
-
-
-static void GLAPIENTRY
-save_ColorMaskIndexed(GLuint buf, GLboolean red, GLboolean green,
- GLboolean blue, GLboolean alpha)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COLOR_MASK_INDEXED, 5);
- if (n) {
- n[1].ui = buf;
- n[2].b = red;
- n[3].b = green;
- n[4].b = blue;
- n[5].b = alpha;
- }
- if (ctx->ExecuteFlag) {
- /*CALL_ColorMaskIndexedEXT(ctx->Exec, (buf, red, green, blue, alpha));*/
- }
-}
-
-
-static void GLAPIENTRY
-save_ColorMaterial(GLenum face, GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_COLOR_MATERIAL, 2);
- if (n) {
- n[1].e = face;
- n[2].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_ColorMaterial(ctx->Exec, (face, mode));
- }
-}
-
-
-static void GLAPIENTRY
-save_ColorTable(GLenum target, GLenum internalFormat,
- GLsizei width, GLenum format, GLenum type,
- const GLvoid * table)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (_mesa_is_proxy_texture(target)) {
- /* execute immediately */
- CALL_ColorTable(ctx->Exec, (target, internalFormat, width,
- format, type, table));
- }
- else {
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COLOR_TABLE, 6);
- if (n) {
- n[1].e = target;
- n[2].e = internalFormat;
- n[3].i = width;
- n[4].e = format;
- n[5].e = type;
- n[6].data = unpack_image(ctx, 1, width, 1, 1, format, type, table,
- &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_ColorTable(ctx->Exec, (target, internalFormat, width,
- format, type, table));
- }
- }
-}
-
-
-
-static void GLAPIENTRY
-save_ColorTableParameterfv(GLenum target, GLenum pname,
- const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_COLOR_TABLE_PARAMETER_FV, 6);
- if (n) {
- n[1].e = target;
- n[2].e = pname;
- n[3].f = params[0];
- if (pname == GL_COLOR_TABLE_SGI ||
- pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
- pname == GL_TEXTURE_COLOR_TABLE_SGI) {
- n[4].f = params[1];
- n[5].f = params[2];
- n[6].f = params[3];
- }
- }
-
- if (ctx->ExecuteFlag) {
- CALL_ColorTableParameterfv(ctx->Exec, (target, pname, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_COLOR_TABLE_PARAMETER_IV, 6);
- if (n) {
- n[1].e = target;
- n[2].e = pname;
- n[3].i = params[0];
- if (pname == GL_COLOR_TABLE_SGI ||
- pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
- pname == GL_TEXTURE_COLOR_TABLE_SGI) {
- n[4].i = params[1];
- n[5].i = params[2];
- n[6].i = params[3];
- }
- }
-
- if (ctx->ExecuteFlag) {
- CALL_ColorTableParameteriv(ctx->Exec, (target, pname, params));
- }
-}
-
-
-
-static void GLAPIENTRY
-save_ColorSubTable(GLenum target, GLsizei start, GLsizei count,
- GLenum format, GLenum type, const GLvoid * table)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COLOR_SUB_TABLE, 6);
- if (n) {
- n[1].e = target;
- n[2].i = start;
- n[3].i = count;
- n[4].e = format;
- n[5].e = type;
- n[6].data = unpack_image(ctx, 1, count, 1, 1, format, type, table,
- &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_ColorSubTable(ctx->Exec,
- (target, start, count, format, type, table));
- }
-}
-
-
-static void GLAPIENTRY
-save_CopyColorSubTable(GLenum target, GLsizei start,
- GLint x, GLint y, GLsizei width)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COPY_COLOR_SUB_TABLE, 5);
- if (n) {
- n[1].e = target;
- n[2].i = start;
- n[3].i = x;
- n[4].i = y;
- n[5].i = width;
- }
- if (ctx->ExecuteFlag) {
- CALL_CopyColorSubTable(ctx->Exec, (target, start, x, y, width));
- }
-}
-
-
-static void GLAPIENTRY
-save_CopyColorTable(GLenum target, GLenum internalformat,
- GLint x, GLint y, GLsizei width)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COPY_COLOR_TABLE, 5);
- if (n) {
- n[1].e = target;
- n[2].e = internalformat;
- n[3].i = x;
- n[4].i = y;
- n[5].i = width;
- }
- if (ctx->ExecuteFlag) {
- CALL_CopyColorTable(ctx->Exec, (target, internalformat, x, y, width));
- }
-}
-
-
-static void GLAPIENTRY
-save_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width,
- GLenum format, GLenum type, const GLvoid * filter)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_CONVOLUTION_FILTER_1D, 6);
- if (n) {
- n[1].e = target;
- n[2].e = internalFormat;
- n[3].i = width;
- n[4].e = format;
- n[5].e = type;
- n[6].data = unpack_image(ctx, 1, width, 1, 1, format, type, filter,
- &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_ConvolutionFilter1D(ctx->Exec, (target, internalFormat, width,
- format, type, filter));
- }
-}
-
-
-static void GLAPIENTRY
-save_ConvolutionFilter2D(GLenum target, GLenum internalFormat,
- GLsizei width, GLsizei height, GLenum format,
- GLenum type, const GLvoid * filter)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_CONVOLUTION_FILTER_2D, 7);
- if (n) {
- n[1].e = target;
- n[2].e = internalFormat;
- n[3].i = width;
- n[4].i = height;
- n[5].e = format;
- n[6].e = type;
- n[7].data = unpack_image(ctx, 2, width, height, 1, format, type, filter,
- &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_ConvolutionFilter2D(ctx->Exec,
- (target, internalFormat, width, height, format,
- type, filter));
- }
-}
-
-
-static void GLAPIENTRY
-save_ConvolutionParameteri(GLenum target, GLenum pname, GLint param)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_I, 3);
- if (n) {
- n[1].e = target;
- n[2].e = pname;
- n[3].i = param;
- }
- if (ctx->ExecuteFlag) {
- CALL_ConvolutionParameteri(ctx->Exec, (target, pname, param));
- }
-}
-
-
-static void GLAPIENTRY
-save_ConvolutionParameteriv(GLenum target, GLenum pname, const GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_IV, 6);
- if (n) {
- n[1].e = target;
- n[2].e = pname;
- n[3].i = params[0];
- if (pname == GL_CONVOLUTION_BORDER_COLOR ||
- pname == GL_CONVOLUTION_FILTER_SCALE ||
- pname == GL_CONVOLUTION_FILTER_BIAS) {
- n[4].i = params[1];
- n[5].i = params[2];
- n[6].i = params[3];
- }
- else {
- n[4].i = n[5].i = n[6].i = 0;
- }
- }
- if (ctx->ExecuteFlag) {
- CALL_ConvolutionParameteriv(ctx->Exec, (target, pname, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_ConvolutionParameterf(GLenum target, GLenum pname, GLfloat param)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_F, 3);
- if (n) {
- n[1].e = target;
- n[2].e = pname;
- n[3].f = param;
- }
- if (ctx->ExecuteFlag) {
- CALL_ConvolutionParameterf(ctx->Exec, (target, pname, param));
- }
-}
-
-
-static void GLAPIENTRY
-save_ConvolutionParameterfv(GLenum target, GLenum pname,
- const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_FV, 6);
- if (n) {
- n[1].e = target;
- n[2].e = pname;
- n[3].f = params[0];
- if (pname == GL_CONVOLUTION_BORDER_COLOR ||
- pname == GL_CONVOLUTION_FILTER_SCALE ||
- pname == GL_CONVOLUTION_FILTER_BIAS) {
- n[4].f = params[1];
- n[5].f = params[2];
- n[6].f = params[3];
- }
- else {
- n[4].f = n[5].f = n[6].f = 0.0F;
- }
- }
- if (ctx->ExecuteFlag) {
- CALL_ConvolutionParameterfv(ctx->Exec, (target, pname, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_CopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COPY_PIXELS, 5);
- if (n) {
- n[1].i = x;
- n[2].i = y;
- n[3].i = (GLint) width;
- n[4].i = (GLint) height;
- n[5].e = type;
- }
- if (ctx->ExecuteFlag) {
- CALL_CopyPixels(ctx->Exec, (x, y, width, height, type));
- }
-}
-
-
-
-static void GLAPIENTRY
-save_CopyTexImage1D(GLenum target, GLint level, GLenum internalformat,
- GLint x, GLint y, GLsizei width, GLint border)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COPY_TEX_IMAGE1D, 7);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].e = internalformat;
- n[4].i = x;
- n[5].i = y;
- n[6].i = width;
- n[7].i = border;
- }
- if (ctx->ExecuteFlag) {
- CALL_CopyTexImage1D(ctx->Exec, (target, level, internalformat,
- x, y, width, border));
- }
-}
-
-
-static void GLAPIENTRY
-save_CopyTexImage2D(GLenum target, GLint level,
- GLenum internalformat,
- GLint x, GLint y, GLsizei width,
- GLsizei height, GLint border)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COPY_TEX_IMAGE2D, 8);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].e = internalformat;
- n[4].i = x;
- n[5].i = y;
- n[6].i = width;
- n[7].i = height;
- n[8].i = border;
- }
- if (ctx->ExecuteFlag) {
- CALL_CopyTexImage2D(ctx->Exec, (target, level, internalformat,
- x, y, width, height, border));
- }
-}
-
-
-
-static void GLAPIENTRY
-save_CopyTexSubImage1D(GLenum target, GLint level,
- GLint xoffset, GLint x, GLint y, GLsizei width)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COPY_TEX_SUB_IMAGE1D, 6);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = xoffset;
- n[4].i = x;
- n[5].i = y;
- n[6].i = width;
- }
- if (ctx->ExecuteFlag) {
- CALL_CopyTexSubImage1D(ctx->Exec,
- (target, level, xoffset, x, y, width));
- }
-}
-
-
-static void GLAPIENTRY
-save_CopyTexSubImage2D(GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLint x, GLint y, GLsizei width, GLint height)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COPY_TEX_SUB_IMAGE2D, 8);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = xoffset;
- n[4].i = yoffset;
- n[5].i = x;
- n[6].i = y;
- n[7].i = width;
- n[8].i = height;
- }
- if (ctx->ExecuteFlag) {
- CALL_CopyTexSubImage2D(ctx->Exec, (target, level, xoffset, yoffset,
- x, y, width, height));
- }
-}
-
-
-static void GLAPIENTRY
-save_CopyTexSubImage3D(GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint x, GLint y, GLsizei width, GLint height)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_COPY_TEX_SUB_IMAGE3D, 9);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = xoffset;
- n[4].i = yoffset;
- n[5].i = zoffset;
- n[6].i = x;
- n[7].i = y;
- n[8].i = width;
- n[9].i = height;
- }
- if (ctx->ExecuteFlag) {
- CALL_CopyTexSubImage3D(ctx->Exec, (target, level,
- xoffset, yoffset, zoffset,
- x, y, width, height));
- }
-}
-
-
-static void GLAPIENTRY
-save_CullFace(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CULL_FACE, 1);
- if (n) {
- n[1].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_CullFace(ctx->Exec, (mode));
- }
-}
-
-
-static void GLAPIENTRY
-save_DepthFunc(GLenum func)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_DEPTH_FUNC, 1);
- if (n) {
- n[1].e = func;
- }
- if (ctx->ExecuteFlag) {
- CALL_DepthFunc(ctx->Exec, (func));
- }
-}
-
-
-static void GLAPIENTRY
-save_DepthMask(GLboolean mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_DEPTH_MASK, 1);
- if (n) {
- n[1].b = mask;
- }
- if (ctx->ExecuteFlag) {
- CALL_DepthMask(ctx->Exec, (mask));
- }
-}
-
-
-static void GLAPIENTRY
-save_DepthRange(GLclampd nearval, GLclampd farval)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_DEPTH_RANGE, 2);
- if (n) {
- n[1].f = (GLfloat) nearval;
- n[2].f = (GLfloat) farval;
- }
- if (ctx->ExecuteFlag) {
- CALL_DepthRange(ctx->Exec, (nearval, farval));
- }
-}
-
-
-static void GLAPIENTRY
-save_Disable(GLenum cap)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_DISABLE, 1);
- if (n) {
- n[1].e = cap;
- }
- if (ctx->ExecuteFlag) {
- CALL_Disable(ctx->Exec, (cap));
- }
-}
-
-
-static void GLAPIENTRY
-save_DisableIndexed(GLuint index, GLenum cap)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_DISABLE_INDEXED, 2);
- if (n) {
- n[1].ui = index;
- n[2].e = cap;
- }
- if (ctx->ExecuteFlag) {
- CALL_DisableIndexedEXT(ctx->Exec, (index, cap));
- }
-}
-
-
-static void GLAPIENTRY
-save_DrawBuffer(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_DRAW_BUFFER, 1);
- if (n) {
- n[1].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_DrawBuffer(ctx->Exec, (mode));
- }
-}
-
-
-static void GLAPIENTRY
-save_DrawPixels(GLsizei width, GLsizei height,
- GLenum format, GLenum type, const GLvoid * pixels)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_DRAW_PIXELS, 5);
- if (n) {
- n[1].i = width;
- n[2].i = height;
- n[3].e = format;
- n[4].e = type;
- n[5].data = unpack_image(ctx, 2, width, height, 1, format, type,
- pixels, &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_DrawPixels(ctx->Exec, (width, height, format, type, pixels));
- }
-}
-
-
-
-static void GLAPIENTRY
-save_Enable(GLenum cap)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_ENABLE, 1);
- if (n) {
- n[1].e = cap;
- }
- if (ctx->ExecuteFlag) {
- CALL_Enable(ctx->Exec, (cap));
- }
-}
-
-
-
-static void GLAPIENTRY
-save_EnableIndexed(GLuint index, GLenum cap)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_ENABLE_INDEXED, 2);
- if (n) {
- n[1].ui = index;
- n[2].e = cap;
- }
- if (ctx->ExecuteFlag) {
- CALL_EnableIndexedEXT(ctx->Exec, (index, cap));
- }
-}
-
-
-
-static void GLAPIENTRY
-save_EvalMesh1(GLenum mode, GLint i1, GLint i2)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_EVALMESH1, 3);
- if (n) {
- n[1].e = mode;
- n[2].i = i1;
- n[3].i = i2;
- }
- if (ctx->ExecuteFlag) {
- CALL_EvalMesh1(ctx->Exec, (mode, i1, i2));
- }
-}
-
-
-static void GLAPIENTRY
-save_EvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_EVALMESH2, 5);
- if (n) {
- n[1].e = mode;
- n[2].i = i1;
- n[3].i = i2;
- n[4].i = j1;
- n[5].i = j2;
- }
- if (ctx->ExecuteFlag) {
- CALL_EvalMesh2(ctx->Exec, (mode, i1, i2, j1, j2));
- }
-}
-
-
-
-
-static void GLAPIENTRY
-save_Fogfv(GLenum pname, const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_FOG, 5);
- if (n) {
- n[1].e = pname;
- n[2].f = params[0];
- n[3].f = params[1];
- n[4].f = params[2];
- n[5].f = params[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_Fogfv(ctx->Exec, (pname, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_Fogf(GLenum pname, GLfloat param)
-{
- GLfloat parray[4];
- parray[0] = param;
- parray[1] = parray[2] = parray[3] = 0.0F;
- save_Fogfv(pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_Fogiv(GLenum pname, const GLint *params)
-{
- GLfloat p[4];
- switch (pname) {
- case GL_FOG_MODE:
- case GL_FOG_DENSITY:
- case GL_FOG_START:
- case GL_FOG_END:
- case GL_FOG_INDEX:
- p[0] = (GLfloat) *params;
- p[1] = 0.0f;
- p[2] = 0.0f;
- p[3] = 0.0f;
- break;
- case GL_FOG_COLOR:
- p[0] = INT_TO_FLOAT(params[0]);
- p[1] = INT_TO_FLOAT(params[1]);
- p[2] = INT_TO_FLOAT(params[2]);
- p[3] = INT_TO_FLOAT(params[3]);
- break;
- default:
- /* Error will be caught later in gl_Fogfv */
- ASSIGN_4V(p, 0.0F, 0.0F, 0.0F, 0.0F);
- }
- save_Fogfv(pname, p);
-}
-
-
-static void GLAPIENTRY
-save_Fogi(GLenum pname, GLint param)
-{
- GLint parray[4];
- parray[0] = param;
- parray[1] = parray[2] = parray[3] = 0;
- save_Fogiv(pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_FrontFace(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_FRONT_FACE, 1);
- if (n) {
- n[1].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_FrontFace(ctx->Exec, (mode));
- }
-}
-
-
-static void GLAPIENTRY
-save_Frustum(GLdouble left, GLdouble right,
- GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_FRUSTUM, 6);
- if (n) {
- n[1].f = (GLfloat) left;
- n[2].f = (GLfloat) right;
- n[3].f = (GLfloat) bottom;
- n[4].f = (GLfloat) top;
- n[5].f = (GLfloat) nearval;
- n[6].f = (GLfloat) farval;
- }
- if (ctx->ExecuteFlag) {
- CALL_Frustum(ctx->Exec, (left, right, bottom, top, nearval, farval));
- }
-}
-
-
-static void GLAPIENTRY
-save_Hint(GLenum target, GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_HINT, 2);
- if (n) {
- n[1].e = target;
- n[2].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_Hint(ctx->Exec, (target, mode));
- }
-}
-
-
-static void GLAPIENTRY
-save_Histogram(GLenum target, GLsizei width, GLenum internalFormat,
- GLboolean sink)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_HISTOGRAM, 4);
- if (n) {
- n[1].e = target;
- n[2].i = width;
- n[3].e = internalFormat;
- n[4].b = sink;
- }
- if (ctx->ExecuteFlag) {
- CALL_Histogram(ctx->Exec, (target, width, internalFormat, sink));
- }
-}
-
-
-static void GLAPIENTRY
-save_IndexMask(GLuint mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_INDEX_MASK, 1);
- if (n) {
- n[1].ui = mask;
- }
- if (ctx->ExecuteFlag) {
- CALL_IndexMask(ctx->Exec, (mask));
- }
-}
-
-
-static void GLAPIENTRY
-save_InitNames(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- (void) alloc_instruction(ctx, OPCODE_INIT_NAMES, 0);
- if (ctx->ExecuteFlag) {
- CALL_InitNames(ctx->Exec, ());
- }
-}
-
-
-static void GLAPIENTRY
-save_Lightfv(GLenum light, GLenum pname, const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_LIGHT, 6);
- if (n) {
- GLint i, nParams;
- n[1].e = light;
- n[2].e = pname;
- switch (pname) {
- case GL_AMBIENT:
- nParams = 4;
- break;
- case GL_DIFFUSE:
- nParams = 4;
- break;
- case GL_SPECULAR:
- nParams = 4;
- break;
- case GL_POSITION:
- nParams = 4;
- break;
- case GL_SPOT_DIRECTION:
- nParams = 3;
- break;
- case GL_SPOT_EXPONENT:
- nParams = 1;
- break;
- case GL_SPOT_CUTOFF:
- nParams = 1;
- break;
- case GL_CONSTANT_ATTENUATION:
- nParams = 1;
- break;
- case GL_LINEAR_ATTENUATION:
- nParams = 1;
- break;
- case GL_QUADRATIC_ATTENUATION:
- nParams = 1;
- break;
- default:
- nParams = 0;
- }
- for (i = 0; i < nParams; i++) {
- n[3 + i].f = params[i];
- }
- }
- if (ctx->ExecuteFlag) {
- CALL_Lightfv(ctx->Exec, (light, pname, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_Lightf(GLenum light, GLenum pname, GLfloat param)
-{
- GLfloat parray[4];
- parray[0] = param;
- parray[1] = parray[2] = parray[3] = 0.0F;
- save_Lightfv(light, pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_Lightiv(GLenum light, GLenum pname, const GLint *params)
-{
- GLfloat fparam[4];
- switch (pname) {
- case GL_AMBIENT:
- case GL_DIFFUSE:
- case GL_SPECULAR:
- fparam[0] = INT_TO_FLOAT(params[0]);
- fparam[1] = INT_TO_FLOAT(params[1]);
- fparam[2] = INT_TO_FLOAT(params[2]);
- fparam[3] = INT_TO_FLOAT(params[3]);
- break;
- case GL_POSITION:
- fparam[0] = (GLfloat) params[0];
- fparam[1] = (GLfloat) params[1];
- fparam[2] = (GLfloat) params[2];
- fparam[3] = (GLfloat) params[3];
- break;
- case GL_SPOT_DIRECTION:
- fparam[0] = (GLfloat) params[0];
- fparam[1] = (GLfloat) params[1];
- fparam[2] = (GLfloat) params[2];
- break;
- case GL_SPOT_EXPONENT:
- case GL_SPOT_CUTOFF:
- case GL_CONSTANT_ATTENUATION:
- case GL_LINEAR_ATTENUATION:
- case GL_QUADRATIC_ATTENUATION:
- fparam[0] = (GLfloat) params[0];
- break;
- default:
- /* error will be caught later in gl_Lightfv */
- ;
- }
- save_Lightfv(light, pname, fparam);
-}
-
-
-static void GLAPIENTRY
-save_Lighti(GLenum light, GLenum pname, GLint param)
-{
- GLint parray[4];
- parray[0] = param;
- parray[1] = parray[2] = parray[3] = 0;
- save_Lightiv(light, pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_LightModelfv(GLenum pname, const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_LIGHT_MODEL, 5);
- if (n) {
- n[1].e = pname;
- n[2].f = params[0];
- n[3].f = params[1];
- n[4].f = params[2];
- n[5].f = params[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_LightModelfv(ctx->Exec, (pname, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_LightModelf(GLenum pname, GLfloat param)
-{
- GLfloat parray[4];
- parray[0] = param;
- parray[1] = parray[2] = parray[3] = 0.0F;
- save_LightModelfv(pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_LightModeliv(GLenum pname, const GLint *params)
-{
- GLfloat fparam[4];
- switch (pname) {
- case GL_LIGHT_MODEL_AMBIENT:
- fparam[0] = INT_TO_FLOAT(params[0]);
- fparam[1] = INT_TO_FLOAT(params[1]);
- fparam[2] = INT_TO_FLOAT(params[2]);
- fparam[3] = INT_TO_FLOAT(params[3]);
- break;
- case GL_LIGHT_MODEL_LOCAL_VIEWER:
- case GL_LIGHT_MODEL_TWO_SIDE:
- case GL_LIGHT_MODEL_COLOR_CONTROL:
- fparam[0] = (GLfloat) params[0];
- fparam[1] = 0.0F;
- fparam[2] = 0.0F;
- fparam[3] = 0.0F;
- break;
- default:
- /* Error will be caught later in gl_LightModelfv */
- ASSIGN_4V(fparam, 0.0F, 0.0F, 0.0F, 0.0F);
- }
- save_LightModelfv(pname, fparam);
-}
-
-
-static void GLAPIENTRY
-save_LightModeli(GLenum pname, GLint param)
-{
- GLint parray[4];
- parray[0] = param;
- parray[1] = parray[2] = parray[3] = 0;
- save_LightModeliv(pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_LineStipple(GLint factor, GLushort pattern)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_LINE_STIPPLE, 2);
- if (n) {
- n[1].i = factor;
- n[2].us = pattern;
- }
- if (ctx->ExecuteFlag) {
- CALL_LineStipple(ctx->Exec, (factor, pattern));
- }
-}
-
-
-static void GLAPIENTRY
-save_LineWidth(GLfloat width)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_LINE_WIDTH, 1);
- if (n) {
- n[1].f = width;
- }
- if (ctx->ExecuteFlag) {
- CALL_LineWidth(ctx->Exec, (width));
- }
-}
-
-
-static void GLAPIENTRY
-save_ListBase(GLuint base)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_LIST_BASE, 1);
- if (n) {
- n[1].ui = base;
- }
- if (ctx->ExecuteFlag) {
- CALL_ListBase(ctx->Exec, (base));
- }
-}
-
-
-static void GLAPIENTRY
-save_LoadIdentity(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- (void) alloc_instruction(ctx, OPCODE_LOAD_IDENTITY, 0);
- if (ctx->ExecuteFlag) {
- CALL_LoadIdentity(ctx->Exec, ());
- }
-}
-
-
-static void GLAPIENTRY
-save_LoadMatrixf(const GLfloat * m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_LOAD_MATRIX, 16);
- if (n) {
- GLuint i;
- for (i = 0; i < 16; i++) {
- n[1 + i].f = m[i];
- }
- }
- if (ctx->ExecuteFlag) {
- CALL_LoadMatrixf(ctx->Exec, (m));
- }
-}
-
-
-static void GLAPIENTRY
-save_LoadMatrixd(const GLdouble * m)
-{
- GLfloat f[16];
- GLint i;
- for (i = 0; i < 16; i++) {
- f[i] = (GLfloat) m[i];
- }
- save_LoadMatrixf(f);
-}
-
-
-static void GLAPIENTRY
-save_LoadName(GLuint name)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_LOAD_NAME, 1);
- if (n) {
- n[1].ui = name;
- }
- if (ctx->ExecuteFlag) {
- CALL_LoadName(ctx->Exec, (name));
- }
-}
-
-
-static void GLAPIENTRY
-save_LogicOp(GLenum opcode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_LOGIC_OP, 1);
- if (n) {
- n[1].e = opcode;
- }
- if (ctx->ExecuteFlag) {
- CALL_LogicOp(ctx->Exec, (opcode));
- }
-}
-
-
-static void GLAPIENTRY
-save_Map1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
- GLint order, const GLdouble * points)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_MAP1, 6);
- if (n) {
- GLfloat *pnts = _mesa_copy_map_points1d(target, stride, order, points);
- n[1].e = target;
- n[2].f = (GLfloat) u1;
- n[3].f = (GLfloat) u2;
- n[4].i = _mesa_evaluator_components(target); /* stride */
- n[5].i = order;
- n[6].data = (void *) pnts;
- }
- if (ctx->ExecuteFlag) {
- CALL_Map1d(ctx->Exec, (target, u1, u2, stride, order, points));
- }
-}
-
-static void GLAPIENTRY
-save_Map1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
- GLint order, const GLfloat * points)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_MAP1, 6);
- if (n) {
- GLfloat *pnts = _mesa_copy_map_points1f(target, stride, order, points);
- n[1].e = target;
- n[2].f = u1;
- n[3].f = u2;
- n[4].i = _mesa_evaluator_components(target); /* stride */
- n[5].i = order;
- n[6].data = (void *) pnts;
- }
- if (ctx->ExecuteFlag) {
- CALL_Map1f(ctx->Exec, (target, u1, u2, stride, order, points));
- }
-}
-
-
-static void GLAPIENTRY
-save_Map2d(GLenum target,
- GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
- GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
- const GLdouble * points)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_MAP2, 10);
- if (n) {
- GLfloat *pnts = _mesa_copy_map_points2d(target, ustride, uorder,
- vstride, vorder, points);
- n[1].e = target;
- n[2].f = (GLfloat) u1;
- n[3].f = (GLfloat) u2;
- n[4].f = (GLfloat) v1;
- n[5].f = (GLfloat) v2;
- /* XXX verify these strides are correct */
- n[6].i = _mesa_evaluator_components(target) * vorder; /*ustride */
- n[7].i = _mesa_evaluator_components(target); /*vstride */
- n[8].i = uorder;
- n[9].i = vorder;
- n[10].data = (void *) pnts;
- }
- if (ctx->ExecuteFlag) {
- CALL_Map2d(ctx->Exec, (target,
- u1, u2, ustride, uorder,
- v1, v2, vstride, vorder, points));
- }
-}
-
-
-static void GLAPIENTRY
-save_Map2f(GLenum target,
- GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
- GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
- const GLfloat * points)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_MAP2, 10);
- if (n) {
- GLfloat *pnts = _mesa_copy_map_points2f(target, ustride, uorder,
- vstride, vorder, points);
- n[1].e = target;
- n[2].f = u1;
- n[3].f = u2;
- n[4].f = v1;
- n[5].f = v2;
- /* XXX verify these strides are correct */
- n[6].i = _mesa_evaluator_components(target) * vorder; /*ustride */
- n[7].i = _mesa_evaluator_components(target); /*vstride */
- n[8].i = uorder;
- n[9].i = vorder;
- n[10].data = (void *) pnts;
- }
- if (ctx->ExecuteFlag) {
- CALL_Map2f(ctx->Exec, (target, u1, u2, ustride, uorder,
- v1, v2, vstride, vorder, points));
- }
-}
-
-
-static void GLAPIENTRY
-save_MapGrid1f(GLint un, GLfloat u1, GLfloat u2)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_MAPGRID1, 3);
- if (n) {
- n[1].i = un;
- n[2].f = u1;
- n[3].f = u2;
- }
- if (ctx->ExecuteFlag) {
- CALL_MapGrid1f(ctx->Exec, (un, u1, u2));
- }
-}
-
-
-static void GLAPIENTRY
-save_MapGrid1d(GLint un, GLdouble u1, GLdouble u2)
-{
- save_MapGrid1f(un, (GLfloat) u1, (GLfloat) u2);
-}
-
-
-static void GLAPIENTRY
-save_MapGrid2f(GLint un, GLfloat u1, GLfloat u2,
- GLint vn, GLfloat v1, GLfloat v2)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_MAPGRID2, 6);
- if (n) {
- n[1].i = un;
- n[2].f = u1;
- n[3].f = u2;
- n[4].i = vn;
- n[5].f = v1;
- n[6].f = v2;
- }
- if (ctx->ExecuteFlag) {
- CALL_MapGrid2f(ctx->Exec, (un, u1, u2, vn, v1, v2));
- }
-}
-
-
-
-static void GLAPIENTRY
-save_MapGrid2d(GLint un, GLdouble u1, GLdouble u2,
- GLint vn, GLdouble v1, GLdouble v2)
-{
- save_MapGrid2f(un, (GLfloat) u1, (GLfloat) u2,
- vn, (GLfloat) v1, (GLfloat) v2);
-}
-
-
-static void GLAPIENTRY
-save_MatrixMode(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_MATRIX_MODE, 1);
- if (n) {
- n[1].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_MatrixMode(ctx->Exec, (mode));
- }
-}
-
-
-static void GLAPIENTRY
-save_Minmax(GLenum target, GLenum internalFormat, GLboolean sink)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_MIN_MAX, 3);
- if (n) {
- n[1].e = target;
- n[2].e = internalFormat;
- n[3].b = sink;
- }
- if (ctx->ExecuteFlag) {
- CALL_Minmax(ctx->Exec, (target, internalFormat, sink));
- }
-}
-
-
-static void GLAPIENTRY
-save_MultMatrixf(const GLfloat * m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_MULT_MATRIX, 16);
- if (n) {
- GLuint i;
- for (i = 0; i < 16; i++) {
- n[1 + i].f = m[i];
- }
- }
- if (ctx->ExecuteFlag) {
- CALL_MultMatrixf(ctx->Exec, (m));
- }
-}
-
-
-static void GLAPIENTRY
-save_MultMatrixd(const GLdouble * m)
-{
- GLfloat f[16];
- GLint i;
- for (i = 0; i < 16; i++) {
- f[i] = (GLfloat) m[i];
- }
- save_MultMatrixf(f);
-}
-
-
-static void GLAPIENTRY
-save_NewList(GLuint name, GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- /* It's an error to call this function while building a display list */
- _mesa_error(ctx, GL_INVALID_OPERATION, "glNewList");
- (void) name;
- (void) mode;
-}
-
-
-
-static void GLAPIENTRY
-save_Ortho(GLdouble left, GLdouble right,
- GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_ORTHO, 6);
- if (n) {
- n[1].f = (GLfloat) left;
- n[2].f = (GLfloat) right;
- n[3].f = (GLfloat) bottom;
- n[4].f = (GLfloat) top;
- n[5].f = (GLfloat) nearval;
- n[6].f = (GLfloat) farval;
- }
- if (ctx->ExecuteFlag) {
- CALL_Ortho(ctx->Exec, (left, right, bottom, top, nearval, farval));
- }
-}
-
-
-static void GLAPIENTRY
-save_PixelMapfv(GLenum map, GLint mapsize, const GLfloat *values)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PIXEL_MAP, 3);
- if (n) {
- n[1].e = map;
- n[2].i = mapsize;
- n[3].data = (void *) malloc(mapsize * sizeof(GLfloat));
- memcpy(n[3].data, (void *) values, mapsize * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_PixelMapfv(ctx->Exec, (map, mapsize, values));
- }
-}
-
-
-static void GLAPIENTRY
-save_PixelMapuiv(GLenum map, GLint mapsize, const GLuint *values)
-{
- GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
- GLint i;
- if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
- for (i = 0; i < mapsize; i++) {
- fvalues[i] = (GLfloat) values[i];
- }
- }
- else {
- for (i = 0; i < mapsize; i++) {
- fvalues[i] = UINT_TO_FLOAT(values[i]);
- }
- }
- save_PixelMapfv(map, mapsize, fvalues);
-}
-
-
-static void GLAPIENTRY
-save_PixelMapusv(GLenum map, GLint mapsize, const GLushort *values)
-{
- GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
- GLint i;
- if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
- for (i = 0; i < mapsize; i++) {
- fvalues[i] = (GLfloat) values[i];
- }
- }
- else {
- for (i = 0; i < mapsize; i++) {
- fvalues[i] = USHORT_TO_FLOAT(values[i]);
- }
- }
- save_PixelMapfv(map, mapsize, fvalues);
-}
-
-
-static void GLAPIENTRY
-save_PixelTransferf(GLenum pname, GLfloat param)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PIXEL_TRANSFER, 2);
- if (n) {
- n[1].e = pname;
- n[2].f = param;
- }
- if (ctx->ExecuteFlag) {
- CALL_PixelTransferf(ctx->Exec, (pname, param));
- }
-}
-
-
-static void GLAPIENTRY
-save_PixelTransferi(GLenum pname, GLint param)
-{
- save_PixelTransferf(pname, (GLfloat) param);
-}
-
-
-static void GLAPIENTRY
-save_PixelZoom(GLfloat xfactor, GLfloat yfactor)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PIXEL_ZOOM, 2);
- if (n) {
- n[1].f = xfactor;
- n[2].f = yfactor;
- }
- if (ctx->ExecuteFlag) {
- CALL_PixelZoom(ctx->Exec, (xfactor, yfactor));
- }
-}
-
-
-static void GLAPIENTRY
-save_PointParameterfvEXT(GLenum pname, const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_POINT_PARAMETERS, 4);
- if (n) {
- n[1].e = pname;
- n[2].f = params[0];
- n[3].f = params[1];
- n[4].f = params[2];
- }
- if (ctx->ExecuteFlag) {
- CALL_PointParameterfvEXT(ctx->Exec, (pname, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_PointParameterfEXT(GLenum pname, GLfloat param)
-{
- GLfloat parray[3];
- parray[0] = param;
- parray[1] = parray[2] = 0.0F;
- save_PointParameterfvEXT(pname, parray);
-}
-
-static void GLAPIENTRY
-save_PointParameteriNV(GLenum pname, GLint param)
-{
- GLfloat parray[3];
- parray[0] = (GLfloat) param;
- parray[1] = parray[2] = 0.0F;
- save_PointParameterfvEXT(pname, parray);
-}
-
-static void GLAPIENTRY
-save_PointParameterivNV(GLenum pname, const GLint * param)
-{
- GLfloat parray[3];
- parray[0] = (GLfloat) param[0];
- parray[1] = parray[2] = 0.0F;
- save_PointParameterfvEXT(pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_PointSize(GLfloat size)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_POINT_SIZE, 1);
- if (n) {
- n[1].f = size;
- }
- if (ctx->ExecuteFlag) {
- CALL_PointSize(ctx->Exec, (size));
- }
-}
-
-
-static void GLAPIENTRY
-save_PolygonMode(GLenum face, GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_POLYGON_MODE, 2);
- if (n) {
- n[1].e = face;
- n[2].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_PolygonMode(ctx->Exec, (face, mode));
- }
-}
-
-
-static void GLAPIENTRY
-save_PolygonStipple(const GLubyte * pattern)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_POLYGON_STIPPLE, 1);
- if (n) {
- n[1].data = unpack_image(ctx, 2, 32, 32, 1, GL_COLOR_INDEX, GL_BITMAP,
- pattern, &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_PolygonStipple(ctx->Exec, ((GLubyte *) pattern));
- }
-}
-
-
-static void GLAPIENTRY
-save_PolygonOffset(GLfloat factor, GLfloat units)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_POLYGON_OFFSET, 2);
- if (n) {
- n[1].f = factor;
- n[2].f = units;
- }
- if (ctx->ExecuteFlag) {
- CALL_PolygonOffset(ctx->Exec, (factor, units));
- }
-}
-
-
-static void GLAPIENTRY
-save_PolygonOffsetEXT(GLfloat factor, GLfloat bias)
-{
- GET_CURRENT_CONTEXT(ctx);
- /* XXX mult by DepthMaxF here??? */
- save_PolygonOffset(factor, ctx->DrawBuffer->_DepthMaxF * bias);
-}
-
-
-static void GLAPIENTRY
-save_PopAttrib(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- (void) alloc_instruction(ctx, OPCODE_POP_ATTRIB, 0);
- if (ctx->ExecuteFlag) {
- CALL_PopAttrib(ctx->Exec, ());
- }
-}
-
-
-static void GLAPIENTRY
-save_PopMatrix(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- (void) alloc_instruction(ctx, OPCODE_POP_MATRIX, 0);
- if (ctx->ExecuteFlag) {
- CALL_PopMatrix(ctx->Exec, ());
- }
-}
-
-
-static void GLAPIENTRY
-save_PopName(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- (void) alloc_instruction(ctx, OPCODE_POP_NAME, 0);
- if (ctx->ExecuteFlag) {
- CALL_PopName(ctx->Exec, ());
- }
-}
-
-
-static void GLAPIENTRY
-save_PrioritizeTextures(GLsizei num, const GLuint * textures,
- const GLclampf * priorities)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- for (i = 0; i < num; i++) {
- Node *n;
- n = alloc_instruction(ctx, OPCODE_PRIORITIZE_TEXTURE, 2);
- if (n) {
- n[1].ui = textures[i];
- n[2].f = priorities[i];
- }
- }
- if (ctx->ExecuteFlag) {
- CALL_PrioritizeTextures(ctx->Exec, (num, textures, priorities));
- }
-}
-
-
-static void GLAPIENTRY
-save_PushAttrib(GLbitfield mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PUSH_ATTRIB, 1);
- if (n) {
- n[1].bf = mask;
- }
- if (ctx->ExecuteFlag) {
- CALL_PushAttrib(ctx->Exec, (mask));
- }
-}
-
-
-static void GLAPIENTRY
-save_PushMatrix(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- (void) alloc_instruction(ctx, OPCODE_PUSH_MATRIX, 0);
- if (ctx->ExecuteFlag) {
- CALL_PushMatrix(ctx->Exec, ());
- }
-}
-
-
-static void GLAPIENTRY
-save_PushName(GLuint name)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PUSH_NAME, 1);
- if (n) {
- n[1].ui = name;
- }
- if (ctx->ExecuteFlag) {
- CALL_PushName(ctx->Exec, (name));
- }
-}
-
-
-static void GLAPIENTRY
-save_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_RASTER_POS, 4);
- if (n) {
- n[1].f = x;
- n[2].f = y;
- n[3].f = z;
- n[4].f = w;
- }
- if (ctx->ExecuteFlag) {
- CALL_RasterPos4f(ctx->Exec, (x, y, z, w));
- }
-}
-
-static void GLAPIENTRY
-save_RasterPos2d(GLdouble x, GLdouble y)
-{
- save_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos2f(GLfloat x, GLfloat y)
-{
- save_RasterPos4f(x, y, 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos2i(GLint x, GLint y)
-{
- save_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos2s(GLshort x, GLshort y)
-{
- save_RasterPos4f(x, y, 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
-{
- save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
-{
- save_RasterPos4f(x, y, z, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos3i(GLint x, GLint y, GLint z)
-{
- save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos3s(GLshort x, GLshort y, GLshort z)
-{
- save_RasterPos4f(x, y, z, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
-{
- save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
-}
-
-static void GLAPIENTRY
-save_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
-{
- save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
-}
-
-static void GLAPIENTRY
-save_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
-{
- save_RasterPos4f(x, y, z, w);
-}
-
-static void GLAPIENTRY
-save_RasterPos2dv(const GLdouble * v)
-{
- save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos2fv(const GLfloat * v)
-{
- save_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos2iv(const GLint * v)
-{
- save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos2sv(const GLshort * v)
-{
- save_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos3dv(const GLdouble * v)
-{
- save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos3fv(const GLfloat * v)
-{
- save_RasterPos4f(v[0], v[1], v[2], 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos3iv(const GLint * v)
-{
- save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos3sv(const GLshort * v)
-{
- save_RasterPos4f(v[0], v[1], v[2], 1.0F);
-}
-
-static void GLAPIENTRY
-save_RasterPos4dv(const GLdouble * v)
-{
- save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
- (GLfloat) v[2], (GLfloat) v[3]);
-}
-
-static void GLAPIENTRY
-save_RasterPos4fv(const GLfloat * v)
-{
- save_RasterPos4f(v[0], v[1], v[2], v[3]);
-}
-
-static void GLAPIENTRY
-save_RasterPos4iv(const GLint * v)
-{
- save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
- (GLfloat) v[2], (GLfloat) v[3]);
-}
-
-static void GLAPIENTRY
-save_RasterPos4sv(const GLshort * v)
-{
- save_RasterPos4f(v[0], v[1], v[2], v[3]);
-}
-
-
-static void GLAPIENTRY
-save_PassThrough(GLfloat token)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PASSTHROUGH, 1);
- if (n) {
- n[1].f = token;
- }
- if (ctx->ExecuteFlag) {
- CALL_PassThrough(ctx->Exec, (token));
- }
-}
-
-
-static void GLAPIENTRY
-save_ReadBuffer(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_READ_BUFFER, 1);
- if (n) {
- n[1].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_ReadBuffer(ctx->Exec, (mode));
- }
-}
-
-
-static void GLAPIENTRY
-save_ResetHistogram(GLenum target)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_RESET_HISTOGRAM, 1);
- if (n) {
- n[1].e = target;
- }
- if (ctx->ExecuteFlag) {
- CALL_ResetHistogram(ctx->Exec, (target));
- }
-}
-
-
-static void GLAPIENTRY
-save_ResetMinmax(GLenum target)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_RESET_MIN_MAX, 1);
- if (n) {
- n[1].e = target;
- }
- if (ctx->ExecuteFlag) {
- CALL_ResetMinmax(ctx->Exec, (target));
- }
-}
-
-
-static void GLAPIENTRY
-save_Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_ROTATE, 4);
- if (n) {
- n[1].f = angle;
- n[2].f = x;
- n[3].f = y;
- n[4].f = z;
- }
- if (ctx->ExecuteFlag) {
- CALL_Rotatef(ctx->Exec, (angle, x, y, z));
- }
-}
-
-
-static void GLAPIENTRY
-save_Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
-{
- save_Rotatef((GLfloat) angle, (GLfloat) x, (GLfloat) y, (GLfloat) z);
-}
-
-
-static void GLAPIENTRY
-save_Scalef(GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_SCALE, 3);
- if (n) {
- n[1].f = x;
- n[2].f = y;
- n[3].f = z;
- }
- if (ctx->ExecuteFlag) {
- CALL_Scalef(ctx->Exec, (x, y, z));
- }
-}
-
-
-static void GLAPIENTRY
-save_Scaled(GLdouble x, GLdouble y, GLdouble z)
-{
- save_Scalef((GLfloat) x, (GLfloat) y, (GLfloat) z);
-}
-
-
-static void GLAPIENTRY
-save_Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_SCISSOR, 4);
- if (n) {
- n[1].i = x;
- n[2].i = y;
- n[3].i = width;
- n[4].i = height;
- }
- if (ctx->ExecuteFlag) {
- CALL_Scissor(ctx->Exec, (x, y, width, height));
- }
-}
-
-
-static void GLAPIENTRY
-save_ShadeModel(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END(ctx);
-
- if (ctx->ExecuteFlag) {
- CALL_ShadeModel(ctx->Exec, (mode));
- }
-
- if (ctx->ListState.Current.ShadeModel == mode)
- return;
-
- SAVE_FLUSH_VERTICES(ctx);
-
- /* Only save the value if we know the statechange will take effect:
- */
- if (ctx->Driver.CurrentSavePrimitive == PRIM_OUTSIDE_BEGIN_END)
- ctx->ListState.Current.ShadeModel = mode;
-
- n = alloc_instruction(ctx, OPCODE_SHADE_MODEL, 1);
- if (n) {
- n[1].e = mode;
- }
-}
-
-
-static void GLAPIENTRY
-save_StencilFunc(GLenum func, GLint ref, GLuint mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC, 3);
- if (n) {
- n[1].e = func;
- n[2].i = ref;
- n[3].ui = mask;
- }
- if (ctx->ExecuteFlag) {
- CALL_StencilFunc(ctx->Exec, (func, ref, mask));
- }
-}
-
-
-static void GLAPIENTRY
-save_StencilMask(GLuint mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_STENCIL_MASK, 1);
- if (n) {
- n[1].ui = mask;
- }
- if (ctx->ExecuteFlag) {
- CALL_StencilMask(ctx->Exec, (mask));
- }
-}
-
-
-static void GLAPIENTRY
-save_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_STENCIL_OP, 3);
- if (n) {
- n[1].e = fail;
- n[2].e = zfail;
- n[3].e = zpass;
- }
- if (ctx->ExecuteFlag) {
- CALL_StencilOp(ctx->Exec, (fail, zfail, zpass));
- }
-}
-
-
-static void GLAPIENTRY
-save_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC_SEPARATE, 4);
- if (n) {
- n[1].e = face;
- n[2].e = func;
- n[3].i = ref;
- n[4].ui = mask;
- }
- if (ctx->ExecuteFlag) {
- CALL_StencilFuncSeparate(ctx->Exec, (face, func, ref, mask));
- }
-}
-
-
-static void GLAPIENTRY
-save_StencilFuncSeparateATI(GLenum frontfunc, GLenum backfunc, GLint ref,
- GLuint mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- /* GL_FRONT */
- n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC_SEPARATE, 4);
- if (n) {
- n[1].e = GL_FRONT;
- n[2].e = frontfunc;
- n[3].i = ref;
- n[4].ui = mask;
- }
- /* GL_BACK */
- n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC_SEPARATE, 4);
- if (n) {
- n[1].e = GL_BACK;
- n[2].e = backfunc;
- n[3].i = ref;
- n[4].ui = mask;
- }
- if (ctx->ExecuteFlag) {
- CALL_StencilFuncSeparate(ctx->Exec, (GL_FRONT, frontfunc, ref, mask));
- CALL_StencilFuncSeparate(ctx->Exec, (GL_BACK, backfunc, ref, mask));
- }
-}
-
-
-static void GLAPIENTRY
-save_StencilMaskSeparate(GLenum face, GLuint mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_STENCIL_MASK_SEPARATE, 2);
- if (n) {
- n[1].e = face;
- n[2].ui = mask;
- }
- if (ctx->ExecuteFlag) {
- CALL_StencilMaskSeparate(ctx->Exec, (face, mask));
- }
-}
-
-
-static void GLAPIENTRY
-save_StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_STENCIL_OP_SEPARATE, 4);
- if (n) {
- n[1].e = face;
- n[2].e = fail;
- n[3].e = zfail;
- n[4].e = zpass;
- }
- if (ctx->ExecuteFlag) {
- CALL_StencilOpSeparate(ctx->Exec, (face, fail, zfail, zpass));
- }
-}
-
-
-static void GLAPIENTRY
-save_TexEnvfv(GLenum target, GLenum pname, const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_TEXENV, 6);
- if (n) {
- n[1].e = target;
- n[2].e = pname;
- if (pname == GL_TEXTURE_ENV_COLOR) {
- n[3].f = params[0];
- n[4].f = params[1];
- n[5].f = params[2];
- n[6].f = params[3];
- }
- else {
- n[3].f = params[0];
- n[4].f = n[5].f = n[6].f = 0.0F;
- }
- }
- if (ctx->ExecuteFlag) {
- CALL_TexEnvfv(ctx->Exec, (target, pname, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_TexEnvf(GLenum target, GLenum pname, GLfloat param)
-{
- GLfloat parray[4];
- parray[0] = (GLfloat) param;
- parray[1] = parray[2] = parray[3] = 0.0F;
- save_TexEnvfv(target, pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_TexEnvi(GLenum target, GLenum pname, GLint param)
-{
- GLfloat p[4];
- p[0] = (GLfloat) param;
- p[1] = p[2] = p[3] = 0.0F;
- save_TexEnvfv(target, pname, p);
-}
-
-
-static void GLAPIENTRY
-save_TexEnviv(GLenum target, GLenum pname, const GLint * param)
-{
- GLfloat p[4];
- if (pname == GL_TEXTURE_ENV_COLOR) {
- p[0] = INT_TO_FLOAT(param[0]);
- p[1] = INT_TO_FLOAT(param[1]);
- p[2] = INT_TO_FLOAT(param[2]);
- p[3] = INT_TO_FLOAT(param[3]);
- }
- else {
- p[0] = (GLfloat) param[0];
- p[1] = p[2] = p[3] = 0.0F;
- }
- save_TexEnvfv(target, pname, p);
-}
-
-
-static void GLAPIENTRY
-save_TexGenfv(GLenum coord, GLenum pname, const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_TEXGEN, 6);
- if (n) {
- n[1].e = coord;
- n[2].e = pname;
- n[3].f = params[0];
- n[4].f = params[1];
- n[5].f = params[2];
- n[6].f = params[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_TexGenfv(ctx->Exec, (coord, pname, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_TexGeniv(GLenum coord, GLenum pname, const GLint *params)
-{
- GLfloat p[4];
- p[0] = (GLfloat) params[0];
- p[1] = (GLfloat) params[1];
- p[2] = (GLfloat) params[2];
- p[3] = (GLfloat) params[3];
- save_TexGenfv(coord, pname, p);
-}
-
-
-static void GLAPIENTRY
-save_TexGend(GLenum coord, GLenum pname, GLdouble param)
-{
- GLfloat parray[4];
- parray[0] = (GLfloat) param;
- parray[1] = parray[2] = parray[3] = 0.0F;
- save_TexGenfv(coord, pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_TexGendv(GLenum coord, GLenum pname, const GLdouble *params)
-{
- GLfloat p[4];
- p[0] = (GLfloat) params[0];
- p[1] = (GLfloat) params[1];
- p[2] = (GLfloat) params[2];
- p[3] = (GLfloat) params[3];
- save_TexGenfv(coord, pname, p);
-}
-
-
-static void GLAPIENTRY
-save_TexGenf(GLenum coord, GLenum pname, GLfloat param)
-{
- GLfloat parray[4];
- parray[0] = param;
- parray[1] = parray[2] = parray[3] = 0.0F;
- save_TexGenfv(coord, pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_TexGeni(GLenum coord, GLenum pname, GLint param)
-{
- GLint parray[4];
- parray[0] = param;
- parray[1] = parray[2] = parray[3] = 0;
- save_TexGeniv(coord, pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_TEXPARAMETER, 6);
- if (n) {
- n[1].e = target;
- n[2].e = pname;
- n[3].f = params[0];
- n[4].f = params[1];
- n[5].f = params[2];
- n[6].f = params[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_TexParameterfv(ctx->Exec, (target, pname, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_TexParameterf(GLenum target, GLenum pname, GLfloat param)
-{
- GLfloat parray[4];
- parray[0] = param;
- parray[1] = parray[2] = parray[3] = 0.0F;
- save_TexParameterfv(target, pname, parray);
-}
-
-
-static void GLAPIENTRY
-save_TexParameteri(GLenum target, GLenum pname, GLint param)
-{
- GLfloat fparam[4];
- fparam[0] = (GLfloat) param;
- fparam[1] = fparam[2] = fparam[3] = 0.0F;
- save_TexParameterfv(target, pname, fparam);
-}
-
-
-static void GLAPIENTRY
-save_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
-{
- GLfloat fparam[4];
- fparam[0] = (GLfloat) params[0];
- fparam[1] = fparam[2] = fparam[3] = 0.0F;
- save_TexParameterfv(target, pname, fparam);
-}
-
-
-static void GLAPIENTRY
-save_TexImage1D(GLenum target,
- GLint level, GLint components,
- GLsizei width, GLint border,
- GLenum format, GLenum type, const GLvoid * pixels)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (target == GL_PROXY_TEXTURE_1D) {
- /* don't compile, execute immediately */
- CALL_TexImage1D(ctx->Exec, (target, level, components, width,
- border, format, type, pixels));
- }
- else {
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_TEX_IMAGE1D, 8);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = components;
- n[4].i = (GLint) width;
- n[5].i = border;
- n[6].e = format;
- n[7].e = type;
- n[8].data = unpack_image(ctx, 1, width, 1, 1, format, type,
- pixels, &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_TexImage1D(ctx->Exec, (target, level, components, width,
- border, format, type, pixels));
- }
- }
-}
-
-
-static void GLAPIENTRY
-save_TexImage2D(GLenum target,
- GLint level, GLint components,
- GLsizei width, GLsizei height, GLint border,
- GLenum format, GLenum type, const GLvoid * pixels)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (target == GL_PROXY_TEXTURE_2D) {
- /* don't compile, execute immediately */
- CALL_TexImage2D(ctx->Exec, (target, level, components, width,
- height, border, format, type, pixels));
- }
- else {
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_TEX_IMAGE2D, 9);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = components;
- n[4].i = (GLint) width;
- n[5].i = (GLint) height;
- n[6].i = border;
- n[7].e = format;
- n[8].e = type;
- n[9].data = unpack_image(ctx, 2, width, height, 1, format, type,
- pixels, &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_TexImage2D(ctx->Exec, (target, level, components, width,
- height, border, format, type, pixels));
- }
- }
-}
-
-
-static void GLAPIENTRY
-save_TexImage3D(GLenum target,
- GLint level, GLint internalFormat,
- GLsizei width, GLsizei height, GLsizei depth,
- GLint border,
- GLenum format, GLenum type, const GLvoid * pixels)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (target == GL_PROXY_TEXTURE_3D) {
- /* don't compile, execute immediately */
- CALL_TexImage3D(ctx->Exec, (target, level, internalFormat, width,
- height, depth, border, format, type,
- pixels));
- }
- else {
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_TEX_IMAGE3D, 10);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = (GLint) internalFormat;
- n[4].i = (GLint) width;
- n[5].i = (GLint) height;
- n[6].i = (GLint) depth;
- n[7].i = border;
- n[8].e = format;
- n[9].e = type;
- n[10].data = unpack_image(ctx, 3, width, height, depth, format, type,
- pixels, &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_TexImage3D(ctx->Exec, (target, level, internalFormat, width,
- height, depth, border, format, type,
- pixels));
- }
- }
-}
-
-
-static void GLAPIENTRY
-save_TexSubImage1D(GLenum target, GLint level, GLint xoffset,
- GLsizei width, GLenum format, GLenum type,
- const GLvoid * pixels)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_TEX_SUB_IMAGE1D, 7);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = xoffset;
- n[4].i = (GLint) width;
- n[5].e = format;
- n[6].e = type;
- n[7].data = unpack_image(ctx, 1, width, 1, 1, format, type,
- pixels, &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_TexSubImage1D(ctx->Exec, (target, level, xoffset, width,
- format, type, pixels));
- }
-}
-
-
-static void GLAPIENTRY
-save_TexSubImage2D(GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type, const GLvoid * pixels)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_TEX_SUB_IMAGE2D, 9);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = xoffset;
- n[4].i = yoffset;
- n[5].i = (GLint) width;
- n[6].i = (GLint) height;
- n[7].e = format;
- n[8].e = type;
- n[9].data = unpack_image(ctx, 2, width, height, 1, format, type,
- pixels, &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_TexSubImage2D(ctx->Exec, (target, level, xoffset, yoffset,
- width, height, format, type, pixels));
- }
-}
-
-
-static void GLAPIENTRY
-save_TexSubImage3D(GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLenum type, const GLvoid * pixels)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_TEX_SUB_IMAGE3D, 11);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = xoffset;
- n[4].i = yoffset;
- n[5].i = zoffset;
- n[6].i = (GLint) width;
- n[7].i = (GLint) height;
- n[8].i = (GLint) depth;
- n[9].e = format;
- n[10].e = type;
- n[11].data = unpack_image(ctx, 3, width, height, depth, format, type,
- pixels, &ctx->Unpack);
- }
- if (ctx->ExecuteFlag) {
- CALL_TexSubImage3D(ctx->Exec, (target, level,
- xoffset, yoffset, zoffset,
- width, height, depth, format, type,
- pixels));
- }
-}
-
-
-static void GLAPIENTRY
-save_Translatef(GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_TRANSLATE, 3);
- if (n) {
- n[1].f = x;
- n[2].f = y;
- n[3].f = z;
- }
- if (ctx->ExecuteFlag) {
- CALL_Translatef(ctx->Exec, (x, y, z));
- }
-}
-
-
-static void GLAPIENTRY
-save_Translated(GLdouble x, GLdouble y, GLdouble z)
-{
- save_Translatef((GLfloat) x, (GLfloat) y, (GLfloat) z);
-}
-
-
-
-static void GLAPIENTRY
-save_Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_VIEWPORT, 4);
- if (n) {
- n[1].i = x;
- n[2].i = y;
- n[3].i = (GLint) width;
- n[4].i = (GLint) height;
- }
- if (ctx->ExecuteFlag) {
- CALL_Viewport(ctx->Exec, (x, y, width, height));
- }
-}
-
-
-static void GLAPIENTRY
-save_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_WINDOW_POS, 4);
- if (n) {
- n[1].f = x;
- n[2].f = y;
- n[3].f = z;
- n[4].f = w;
- }
- if (ctx->ExecuteFlag) {
- CALL_WindowPos4fMESA(ctx->Exec, (x, y, z, w));
- }
-}
-
-static void GLAPIENTRY
-save_WindowPos2dMESA(GLdouble x, GLdouble y)
-{
- save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos2fMESA(GLfloat x, GLfloat y)
-{
- save_WindowPos4fMESA(x, y, 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos2iMESA(GLint x, GLint y)
-{
- save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos2sMESA(GLshort x, GLshort y)
-{
- save_WindowPos4fMESA(x, y, 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
-{
- save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
-{
- save_WindowPos4fMESA(x, y, z, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos3iMESA(GLint x, GLint y, GLint z)
-{
- save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
-{
- save_WindowPos4fMESA(x, y, z, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
-{
- save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
-}
-
-static void GLAPIENTRY
-save_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
-{
- save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
-}
-
-static void GLAPIENTRY
-save_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
-{
- save_WindowPos4fMESA(x, y, z, w);
-}
-
-static void GLAPIENTRY
-save_WindowPos2dvMESA(const GLdouble * v)
-{
- save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos2fvMESA(const GLfloat * v)
-{
- save_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos2ivMESA(const GLint * v)
-{
- save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos2svMESA(const GLshort * v)
-{
- save_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos3dvMESA(const GLdouble * v)
-{
- save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos3fvMESA(const GLfloat * v)
-{
- save_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos3ivMESA(const GLint * v)
-{
- save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos3svMESA(const GLshort * v)
-{
- save_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
-}
-
-static void GLAPIENTRY
-save_WindowPos4dvMESA(const GLdouble * v)
-{
- save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1],
- (GLfloat) v[2], (GLfloat) v[3]);
-}
-
-static void GLAPIENTRY
-save_WindowPos4fvMESA(const GLfloat * v)
-{
- save_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
-}
-
-static void GLAPIENTRY
-save_WindowPos4ivMESA(const GLint * v)
-{
- save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1],
- (GLfloat) v[2], (GLfloat) v[3]);
-}
-
-static void GLAPIENTRY
-save_WindowPos4svMESA(const GLshort * v)
-{
- save_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
-}
-
-
-
-/* GL_ARB_multitexture */
-static void GLAPIENTRY
-save_ActiveTextureARB(GLenum target)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_ACTIVE_TEXTURE, 1);
- if (n) {
- n[1].e = target;
- }
- if (ctx->ExecuteFlag) {
- CALL_ActiveTextureARB(ctx->Exec, (target));
- }
-}
-
-
-/* GL_ARB_transpose_matrix */
-
-static void GLAPIENTRY
-save_LoadTransposeMatrixdARB(const GLdouble m[16])
-{
- GLfloat tm[16];
- _math_transposefd(tm, m);
- save_LoadMatrixf(tm);
-}
-
-
-static void GLAPIENTRY
-save_LoadTransposeMatrixfARB(const GLfloat m[16])
-{
- GLfloat tm[16];
- _math_transposef(tm, m);
- save_LoadMatrixf(tm);
-}
-
-
-static void GLAPIENTRY
-save_MultTransposeMatrixdARB(const GLdouble m[16])
-{
- GLfloat tm[16];
- _math_transposefd(tm, m);
- save_MultMatrixf(tm);
-}
-
-
-static void GLAPIENTRY
-save_MultTransposeMatrixfARB(const GLfloat m[16])
-{
- GLfloat tm[16];
- _math_transposef(tm, m);
- save_MultMatrixf(tm);
-}
-
-
-/* GL_ARB_texture_compression */
-static void GLAPIENTRY
-save_CompressedTexImage1DARB(GLenum target, GLint level,
- GLenum internalFormat, GLsizei width,
- GLint border, GLsizei imageSize,
- const GLvoid * data)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (target == GL_PROXY_TEXTURE_1D) {
- /* don't compile, execute immediately */
- CALL_CompressedTexImage1DARB(ctx->Exec, (target, level, internalFormat,
- width, border, imageSize,
- data));
- }
- else {
- Node *n;
- GLvoid *image;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB");
- return;
- }
- memcpy(image, data, imageSize);
- n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_1D, 7);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].e = internalFormat;
- n[4].i = (GLint) width;
- n[5].i = border;
- n[6].i = imageSize;
- n[7].data = image;
- }
- else if (image) {
- free(image);
- }
- if (ctx->ExecuteFlag) {
- CALL_CompressedTexImage1DARB(ctx->Exec,
- (target, level, internalFormat, width,
- border, imageSize, data));
- }
- }
-}
-
-
-static void GLAPIENTRY
-save_CompressedTexImage2DARB(GLenum target, GLint level,
- GLenum internalFormat, GLsizei width,
- GLsizei height, GLint border, GLsizei imageSize,
- const GLvoid * data)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (target == GL_PROXY_TEXTURE_2D) {
- /* don't compile, execute immediately */
- CALL_CompressedTexImage2DARB(ctx->Exec, (target, level, internalFormat,
- width, height, border,
- imageSize, data));
- }
- else {
- Node *n;
- GLvoid *image;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
- return;
- }
- memcpy(image, data, imageSize);
- n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_2D, 8);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].e = internalFormat;
- n[4].i = (GLint) width;
- n[5].i = (GLint) height;
- n[6].i = border;
- n[7].i = imageSize;
- n[8].data = image;
- }
- else if (image) {
- free(image);
- }
- if (ctx->ExecuteFlag) {
- CALL_CompressedTexImage2DARB(ctx->Exec,
- (target, level, internalFormat, width,
- height, border, imageSize, data));
- }
- }
-}
-
-
-static void GLAPIENTRY
-save_CompressedTexImage3DARB(GLenum target, GLint level,
- GLenum internalFormat, GLsizei width,
- GLsizei height, GLsizei depth, GLint border,
- GLsizei imageSize, const GLvoid * data)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (target == GL_PROXY_TEXTURE_3D) {
- /* don't compile, execute immediately */
- CALL_CompressedTexImage3DARB(ctx->Exec, (target, level, internalFormat,
- width, height, depth, border,
- imageSize, data));
- }
- else {
- Node *n;
- GLvoid *image;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB");
- return;
- }
- memcpy(image, data, imageSize);
- n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_3D, 9);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].e = internalFormat;
- n[4].i = (GLint) width;
- n[5].i = (GLint) height;
- n[6].i = (GLint) depth;
- n[7].i = border;
- n[8].i = imageSize;
- n[9].data = image;
- }
- else if (image) {
- free(image);
- }
- if (ctx->ExecuteFlag) {
- CALL_CompressedTexImage3DARB(ctx->Exec,
- (target, level, internalFormat, width,
- height, depth, border, imageSize,
- data));
- }
- }
-}
-
-
-static void GLAPIENTRY
-save_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
- GLsizei width, GLenum format,
- GLsizei imageSize, const GLvoid * data)
-{
- Node *n;
- GLvoid *image;
-
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage1DARB");
- return;
- }
- memcpy(image, data, imageSize);
- n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D, 7);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = xoffset;
- n[4].i = (GLint) width;
- n[5].e = format;
- n[6].i = imageSize;
- n[7].data = image;
- }
- else if (image) {
- free(image);
- }
- if (ctx->ExecuteFlag) {
- CALL_CompressedTexSubImage1DARB(ctx->Exec, (target, level, xoffset,
- width, format, imageSize,
- data));
- }
-}
-
-
-static void GLAPIENTRY
-save_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
- GLint yoffset, GLsizei width, GLsizei height,
- GLenum format, GLsizei imageSize,
- const GLvoid * data)
-{
- Node *n;
- GLvoid *image;
-
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage2DARB");
- return;
- }
- memcpy(image, data, imageSize);
- n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D, 9);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = xoffset;
- n[4].i = yoffset;
- n[5].i = (GLint) width;
- n[6].i = (GLint) height;
- n[7].e = format;
- n[8].i = imageSize;
- n[9].data = image;
- }
- else if (image) {
- free(image);
- }
- if (ctx->ExecuteFlag) {
- CALL_CompressedTexSubImage2DARB(ctx->Exec,
- (target, level, xoffset, yoffset, width,
- height, format, imageSize, data));
- }
-}
-
-
-static void GLAPIENTRY
-save_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
- GLint yoffset, GLint zoffset, GLsizei width,
- GLsizei height, GLsizei depth, GLenum format,
- GLsizei imageSize, const GLvoid * data)
-{
- Node *n;
- GLvoid *image;
-
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage3DARB");
- return;
- }
- memcpy(image, data, imageSize);
- n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D, 11);
- if (n) {
- n[1].e = target;
- n[2].i = level;
- n[3].i = xoffset;
- n[4].i = yoffset;
- n[5].i = zoffset;
- n[6].i = (GLint) width;
- n[7].i = (GLint) height;
- n[8].i = (GLint) depth;
- n[9].e = format;
- n[10].i = imageSize;
- n[11].data = image;
- }
- else if (image) {
- free(image);
- }
- if (ctx->ExecuteFlag) {
- CALL_CompressedTexSubImage3DARB(ctx->Exec,
- (target, level, xoffset, yoffset,
- zoffset, width, height, depth, format,
- imageSize, data));
- }
-}
-
-
-/* GL_ARB_multisample */
-static void GLAPIENTRY
-save_SampleCoverageARB(GLclampf value, GLboolean invert)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_SAMPLE_COVERAGE, 2);
- if (n) {
- n[1].f = value;
- n[2].b = invert;
- }
- if (ctx->ExecuteFlag) {
- CALL_SampleCoverageARB(ctx->Exec, (value, invert));
- }
-}
-
-
-/*
- * GL_NV_vertex_program
- */
-#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
-static void GLAPIENTRY
-save_BindProgramNV(GLenum target, GLuint id)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BIND_PROGRAM_NV, 2);
- if (n) {
- n[1].e = target;
- n[2].ui = id;
- }
- if (ctx->ExecuteFlag) {
- CALL_BindProgramNV(ctx->Exec, (target, id));
- }
-}
-
-static void GLAPIENTRY
-save_ProgramEnvParameter4fARB(GLenum target, GLuint index,
- GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PROGRAM_ENV_PARAMETER_ARB, 6);
- if (n) {
- n[1].e = target;
- n[2].ui = index;
- n[3].f = x;
- n[4].f = y;
- n[5].f = z;
- n[6].f = w;
- }
- if (ctx->ExecuteFlag) {
- CALL_ProgramEnvParameter4fARB(ctx->Exec, (target, index, x, y, z, w));
- }
-}
-
-
-static void GLAPIENTRY
-save_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
- const GLfloat *params)
-{
- save_ProgramEnvParameter4fARB(target, index, params[0], params[1],
- params[2], params[3]);
-}
-
-
-static void GLAPIENTRY
-save_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
- const GLfloat * params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- if (count > 0) {
- GLint i;
- const GLfloat * p = params;
-
- for (i = 0 ; i < count ; i++) {
- n = alloc_instruction(ctx, OPCODE_PROGRAM_ENV_PARAMETER_ARB, 6);
- if (n) {
- n[1].e = target;
- n[2].ui = index;
- n[3].f = p[0];
- n[4].f = p[1];
- n[5].f = p[2];
- n[6].f = p[3];
- p += 4;
- }
- }
- }
-
- if (ctx->ExecuteFlag) {
- CALL_ProgramEnvParameters4fvEXT(ctx->Exec, (target, index, count, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_ProgramEnvParameter4dARB(GLenum target, GLuint index,
- GLdouble x, GLdouble y, GLdouble z, GLdouble w)
-{
- save_ProgramEnvParameter4fARB(target, index,
- (GLfloat) x,
- (GLfloat) y, (GLfloat) z, (GLfloat) w);
-}
-
-
-static void GLAPIENTRY
-save_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
- const GLdouble *params)
-{
- save_ProgramEnvParameter4fARB(target, index,
- (GLfloat) params[0],
- (GLfloat) params[1],
- (GLfloat) params[2], (GLfloat) params[3]);
-}
-
-#endif /* FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program || FEATURE_NV_vertex_program */
-
-#if FEATURE_NV_vertex_program
-static void GLAPIENTRY
-save_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_EXECUTE_PROGRAM_NV, 6);
- if (n) {
- n[1].e = target;
- n[2].ui = id;
- n[3].f = params[0];
- n[4].f = params[1];
- n[5].f = params[2];
- n[6].f = params[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_ExecuteProgramNV(ctx->Exec, (target, id, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_ProgramParameters4dvNV(GLenum target, GLuint index,
- GLsizei num, const GLdouble *params)
-{
- GLint i;
- for (i = 0; i < num; i++) {
- save_ProgramEnvParameter4dvARB(target, index + i, params + 4 * i);
- }
-}
-
-
-static void GLAPIENTRY
-save_ProgramParameters4fvNV(GLenum target, GLuint index,
- GLsizei num, const GLfloat *params)
-{
- GLint i;
- for (i = 0; i < num; i++) {
- save_ProgramEnvParameter4fvARB(target, index + i, params + 4 * i);
- }
-}
-
-
-static void GLAPIENTRY
-save_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
- const GLubyte * program)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_LOAD_PROGRAM_NV, 4);
- if (n) {
- GLubyte *programCopy = (GLubyte *) malloc(len);
- if (!programCopy) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
- return;
- }
- memcpy(programCopy, program, len);
- n[1].e = target;
- n[2].ui = id;
- n[3].i = len;
- n[4].data = programCopy;
- }
- if (ctx->ExecuteFlag) {
- CALL_LoadProgramNV(ctx->Exec, (target, id, len, program));
- }
-}
-
-
-static void GLAPIENTRY
-save_RequestResidentProgramsNV(GLsizei num, const GLuint * ids)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_TRACK_MATRIX_NV, 2);
- if (n) {
- GLuint *idCopy = (GLuint *) malloc(num * sizeof(GLuint));
- if (!idCopy) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glRequestResidentProgramsNV");
- return;
- }
- memcpy(idCopy, ids, num * sizeof(GLuint));
- n[1].i = num;
- n[2].data = idCopy;
- }
- if (ctx->ExecuteFlag) {
- CALL_RequestResidentProgramsNV(ctx->Exec, (num, ids));
- }
-}
-
-
-static void GLAPIENTRY
-save_TrackMatrixNV(GLenum target, GLuint address,
- GLenum matrix, GLenum transform)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_TRACK_MATRIX_NV, 4);
- if (n) {
- n[1].e = target;
- n[2].ui = address;
- n[3].e = matrix;
- n[4].e = transform;
- }
- if (ctx->ExecuteFlag) {
- CALL_TrackMatrixNV(ctx->Exec, (target, address, matrix, transform));
- }
-}
-#endif /* FEATURE_NV_vertex_program */
-
-
-/*
- * GL_NV_fragment_program
- */
-#if FEATURE_NV_fragment_program
-static void GLAPIENTRY
-save_ProgramLocalParameter4fARB(GLenum target, GLuint index,
- GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
- if (n) {
- n[1].e = target;
- n[2].ui = index;
- n[3].f = x;
- n[4].f = y;
- n[5].f = z;
- n[6].f = w;
- }
- if (ctx->ExecuteFlag) {
- CALL_ProgramLocalParameter4fARB(ctx->Exec, (target, index, x, y, z, w));
- }
-}
-
-
-static void GLAPIENTRY
-save_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
- const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
- if (n) {
- n[1].e = target;
- n[2].ui = index;
- n[3].f = params[0];
- n[4].f = params[1];
- n[5].f = params[2];
- n[6].f = params[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_ProgramLocalParameter4fvARB(ctx->Exec, (target, index, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
- const GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- if (count > 0) {
- GLint i;
- const GLfloat * p = params;
-
- for (i = 0 ; i < count ; i++) {
- n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
- if (n) {
- n[1].e = target;
- n[2].ui = index;
- n[3].f = p[0];
- n[4].f = p[1];
- n[5].f = p[2];
- n[6].f = p[3];
- p += 4;
- }
- }
- }
-
- if (ctx->ExecuteFlag) {
- CALL_ProgramLocalParameters4fvEXT(ctx->Exec, (target, index, count, params));
- }
-}
-
-
-static void GLAPIENTRY
-save_ProgramLocalParameter4dARB(GLenum target, GLuint index,
- GLdouble x, GLdouble y,
- GLdouble z, GLdouble w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
- if (n) {
- n[1].e = target;
- n[2].ui = index;
- n[3].f = (GLfloat) x;
- n[4].f = (GLfloat) y;
- n[5].f = (GLfloat) z;
- n[6].f = (GLfloat) w;
- }
- if (ctx->ExecuteFlag) {
- CALL_ProgramLocalParameter4dARB(ctx->Exec, (target, index, x, y, z, w));
- }
-}
-
-
-static void GLAPIENTRY
-save_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
- const GLdouble *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
- if (n) {
- n[1].e = target;
- n[2].ui = index;
- n[3].f = (GLfloat) params[0];
- n[4].f = (GLfloat) params[1];
- n[5].f = (GLfloat) params[2];
- n[6].f = (GLfloat) params[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_ProgramLocalParameter4dvARB(ctx->Exec, (target, index, params));
- }
-}
-
-static void GLAPIENTRY
-save_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte * name,
- GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_PROGRAM_NAMED_PARAMETER_NV, 6);
- if (n) {
- GLubyte *nameCopy = (GLubyte *) malloc(len);
- if (!nameCopy) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramNamedParameter4fNV");
- return;
- }
- memcpy(nameCopy, name, len);
- n[1].ui = id;
- n[2].i = len;
- n[3].data = nameCopy;
- n[4].f = x;
- n[5].f = y;
- n[6].f = z;
- n[7].f = w;
- }
- if (ctx->ExecuteFlag) {
- CALL_ProgramNamedParameter4fNV(ctx->Exec, (id, len, name, x, y, z, w));
- }
-}
-
-
-static void GLAPIENTRY
-save_ProgramNamedParameter4fvNV(GLuint id, GLsizei len, const GLubyte * name,
- const float v[])
-{
- save_ProgramNamedParameter4fNV(id, len, name, v[0], v[1], v[2], v[3]);
-}
-
-
-static void GLAPIENTRY
-save_ProgramNamedParameter4dNV(GLuint id, GLsizei len, const GLubyte * name,
- GLdouble x, GLdouble y, GLdouble z, GLdouble w)
-{
- save_ProgramNamedParameter4fNV(id, len, name, (GLfloat) x, (GLfloat) y,
- (GLfloat) z, (GLfloat) w);
-}
-
-
-static void GLAPIENTRY
-save_ProgramNamedParameter4dvNV(GLuint id, GLsizei len, const GLubyte * name,
- const double v[])
-{
- save_ProgramNamedParameter4fNV(id, len, name, (GLfloat) v[0],
- (GLfloat) v[1], (GLfloat) v[2],
- (GLfloat) v[3]);
-}
-
-#endif /* FEATURE_NV_fragment_program */
-
-
-
-/* GL_EXT_stencil_two_side */
-static void GLAPIENTRY
-save_ActiveStencilFaceEXT(GLenum face)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_ACTIVE_STENCIL_FACE_EXT, 1);
- if (n) {
- n[1].e = face;
- }
- if (ctx->ExecuteFlag) {
- CALL_ActiveStencilFaceEXT(ctx->Exec, (face));
- }
-}
-
-
-/* GL_EXT_depth_bounds_test */
-static void GLAPIENTRY
-save_DepthBoundsEXT(GLclampd zmin, GLclampd zmax)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_DEPTH_BOUNDS_EXT, 2);
- if (n) {
- n[1].f = (GLfloat) zmin;
- n[2].f = (GLfloat) zmax;
- }
- if (ctx->ExecuteFlag) {
- CALL_DepthBoundsEXT(ctx->Exec, (zmin, zmax));
- }
-}
-
-
-
-#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
-
-static void GLAPIENTRY
-save_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
- const GLvoid * string)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
-
- n = alloc_instruction(ctx, OPCODE_PROGRAM_STRING_ARB, 4);
- if (n) {
- GLubyte *programCopy = (GLubyte *) malloc(len);
- if (!programCopy) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
- return;
- }
- memcpy(programCopy, string, len);
- n[1].e = target;
- n[2].e = format;
- n[3].i = len;
- n[4].data = programCopy;
- }
- if (ctx->ExecuteFlag) {
- CALL_ProgramStringARB(ctx->Exec, (target, format, len, string));
- }
-}
-
-#endif /* FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program */
-
-
-#if FEATURE_queryobj
-
-static void GLAPIENTRY
-save_BeginQueryARB(GLenum target, GLuint id)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BEGIN_QUERY_ARB, 2);
- if (n) {
- n[1].e = target;
- n[2].ui = id;
- }
- if (ctx->ExecuteFlag) {
- CALL_BeginQueryARB(ctx->Exec, (target, id));
- }
-}
-
-
-static void GLAPIENTRY
-save_EndQueryARB(GLenum target)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_END_QUERY_ARB, 1);
- if (n) {
- n[1].e = target;
- }
- if (ctx->ExecuteFlag) {
- CALL_EndQueryARB(ctx->Exec, (target));
- }
-}
-
-#endif /* FEATURE_queryobj */
-
-
-static void GLAPIENTRY
-save_DrawBuffersARB(GLsizei count, const GLenum * buffers)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_DRAW_BUFFERS_ARB, 1 + MAX_DRAW_BUFFERS);
- if (n) {
- GLint i;
- n[1].i = count;
- if (count > MAX_DRAW_BUFFERS)
- count = MAX_DRAW_BUFFERS;
- for (i = 0; i < count; i++) {
- n[2 + i].e = buffers[i];
- }
- }
- if (ctx->ExecuteFlag) {
- CALL_DrawBuffersARB(ctx->Exec, (count, buffers));
- }
-}
-
-static void GLAPIENTRY
-save_TexBumpParameterfvATI(GLenum pname, const GLfloat *param)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- n = alloc_instruction(ctx, OPCODE_TEX_BUMP_PARAMETER_ATI, 5);
- if (n) {
- n[1].ui = pname;
- n[2].f = param[0];
- n[3].f = param[1];
- n[4].f = param[2];
- n[5].f = param[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_TexBumpParameterfvATI(ctx->Exec, (pname, param));
- }
-}
-
-static void GLAPIENTRY
-save_TexBumpParameterivATI(GLenum pname, const GLint *param)
-{
- GLfloat p[4];
- p[0] = INT_TO_FLOAT(param[0]);
- p[1] = INT_TO_FLOAT(param[1]);
- p[2] = INT_TO_FLOAT(param[2]);
- p[3] = INT_TO_FLOAT(param[3]);
- save_TexBumpParameterfvATI(pname, p);
-}
-
-#if FEATURE_ATI_fragment_shader
-static void GLAPIENTRY
-save_BindFragmentShaderATI(GLuint id)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- n = alloc_instruction(ctx, OPCODE_BIND_FRAGMENT_SHADER_ATI, 1);
- if (n) {
- n[1].ui = id;
- }
- if (ctx->ExecuteFlag) {
- CALL_BindFragmentShaderATI(ctx->Exec, (id));
- }
-}
-
-static void GLAPIENTRY
-save_SetFragmentShaderConstantATI(GLuint dst, const GLfloat *value)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
-
- n = alloc_instruction(ctx, OPCODE_SET_FRAGMENT_SHADER_CONSTANTS_ATI, 5);
- if (n) {
- n[1].ui = dst;
- n[2].f = value[0];
- n[3].f = value[1];
- n[4].f = value[2];
- n[5].f = value[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_SetFragmentShaderConstantATI(ctx->Exec, (dst, value));
- }
-}
-#endif
-
-static void
-save_Attr1fNV(GLenum attr, GLfloat x)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_ATTR_1F_NV, 2);
- if (n) {
- n[1].e = attr;
- n[2].f = x;
- }
-
- ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
- ctx->ListState.ActiveAttribSize[attr] = 1;
- ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, 0, 0, 1);
-
- if (ctx->ExecuteFlag) {
- CALL_VertexAttrib1fNV(ctx->Exec, (attr, x));
- }
-}
-
-static void
-save_Attr2fNV(GLenum attr, GLfloat x, GLfloat y)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_ATTR_2F_NV, 3);
- if (n) {
- n[1].e = attr;
- n[2].f = x;
- n[3].f = y;
- }
-
- ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
- ctx->ListState.ActiveAttribSize[attr] = 2;
- ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, 0, 1);
-
- if (ctx->ExecuteFlag) {
- CALL_VertexAttrib2fNV(ctx->Exec, (attr, x, y));
- }
-}
-
-static void
-save_Attr3fNV(GLenum attr, GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_ATTR_3F_NV, 4);
- if (n) {
- n[1].e = attr;
- n[2].f = x;
- n[3].f = y;
- n[4].f = z;
- }
-
- ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
- ctx->ListState.ActiveAttribSize[attr] = 3;
- ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, 1);
-
- if (ctx->ExecuteFlag) {
- CALL_VertexAttrib3fNV(ctx->Exec, (attr, x, y, z));
- }
-}
-
-static void
-save_Attr4fNV(GLenum attr, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_ATTR_4F_NV, 5);
- if (n) {
- n[1].e = attr;
- n[2].f = x;
- n[3].f = y;
- n[4].f = z;
- n[5].f = w;
- }
-
- ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
- ctx->ListState.ActiveAttribSize[attr] = 4;
- ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, w);
-
- if (ctx->ExecuteFlag) {
- CALL_VertexAttrib4fNV(ctx->Exec, (attr, x, y, z, w));
- }
-}
-
-
-static void
-save_Attr1fARB(GLenum attr, GLfloat x)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_ATTR_1F_ARB, 2);
- if (n) {
- n[1].e = attr;
- n[2].f = x;
- }
-
- ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
- ctx->ListState.ActiveAttribSize[attr] = 1;
- ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, 0, 0, 1);
-
- if (ctx->ExecuteFlag) {
- CALL_VertexAttrib1fARB(ctx->Exec, (attr, x));
- }
-}
-
-static void
-save_Attr2fARB(GLenum attr, GLfloat x, GLfloat y)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_ATTR_2F_ARB, 3);
- if (n) {
- n[1].e = attr;
- n[2].f = x;
- n[3].f = y;
- }
-
- ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
- ctx->ListState.ActiveAttribSize[attr] = 2;
- ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, 0, 1);
-
- if (ctx->ExecuteFlag) {
- CALL_VertexAttrib2fARB(ctx->Exec, (attr, x, y));
- }
-}
-
-static void
-save_Attr3fARB(GLenum attr, GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_ATTR_3F_ARB, 4);
- if (n) {
- n[1].e = attr;
- n[2].f = x;
- n[3].f = y;
- n[4].f = z;
- }
-
- ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
- ctx->ListState.ActiveAttribSize[attr] = 3;
- ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, 1);
-
- if (ctx->ExecuteFlag) {
- CALL_VertexAttrib3fARB(ctx->Exec, (attr, x, y, z));
- }
-}
-
-static void
-save_Attr4fARB(GLenum attr, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_ATTR_4F_ARB, 5);
- if (n) {
- n[1].e = attr;
- n[2].f = x;
- n[3].f = y;
- n[4].f = z;
- n[5].f = w;
- }
-
- ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
- ctx->ListState.ActiveAttribSize[attr] = 4;
- ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, w);
-
- if (ctx->ExecuteFlag) {
- CALL_VertexAttrib4fARB(ctx->Exec, (attr, x, y, z, w));
- }
-}
-
-
-static void GLAPIENTRY
-save_EvalCoord1f(GLfloat x)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_EVAL_C1, 1);
- if (n) {
- n[1].f = x;
- }
- if (ctx->ExecuteFlag) {
- CALL_EvalCoord1f(ctx->Exec, (x));
- }
-}
-
-static void GLAPIENTRY
-save_EvalCoord1fv(const GLfloat * v)
-{
- save_EvalCoord1f(v[0]);
-}
-
-static void GLAPIENTRY
-save_EvalCoord2f(GLfloat x, GLfloat y)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_EVAL_C2, 2);
- if (n) {
- n[1].f = x;
- n[2].f = y;
- }
- if (ctx->ExecuteFlag) {
- CALL_EvalCoord2f(ctx->Exec, (x, y));
- }
-}
-
-static void GLAPIENTRY
-save_EvalCoord2fv(const GLfloat * v)
-{
- save_EvalCoord2f(v[0], v[1]);
-}
-
-
-static void GLAPIENTRY
-save_EvalPoint1(GLint x)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_EVAL_P1, 1);
- if (n) {
- n[1].i = x;
- }
- if (ctx->ExecuteFlag) {
- CALL_EvalPoint1(ctx->Exec, (x));
- }
-}
-
-static void GLAPIENTRY
-save_EvalPoint2(GLint x, GLint y)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_EVAL_P2, 2);
- if (n) {
- n[1].i = x;
- n[2].i = y;
- }
- if (ctx->ExecuteFlag) {
- CALL_EvalPoint2(ctx->Exec, (x, y));
- }
-}
-
-static void GLAPIENTRY
-save_Indexf(GLfloat x)
-{
- save_Attr1fNV(VERT_ATTRIB_COLOR_INDEX, x);
-}
-
-static void GLAPIENTRY
-save_Indexfv(const GLfloat * v)
-{
- save_Attr1fNV(VERT_ATTRIB_COLOR_INDEX, v[0]);
-}
-
-static void GLAPIENTRY
-save_EdgeFlag(GLboolean x)
-{
- save_Attr1fNV(VERT_ATTRIB_EDGEFLAG, x ? (GLfloat)1.0 : (GLfloat)0.0);
-}
-
-static INLINE GLboolean compare4fv( const GLfloat *a,
- const GLfloat *b,
- GLuint count )
-{
- return memcmp( a, b, count * sizeof(GLfloat) ) == 0;
-}
-
-
-static void GLAPIENTRY
-save_Materialfv(GLenum face, GLenum pname, const GLfloat * param)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- int args, i;
- GLuint bitmask;
-
- switch (face) {
- case GL_BACK:
- case GL_FRONT:
- case GL_FRONT_AND_BACK:
- break;
- default:
- _mesa_compile_error(ctx, GL_INVALID_ENUM, "material(face)");
- return;
- }
-
- switch (pname) {
- case GL_EMISSION:
- case GL_AMBIENT:
- case GL_DIFFUSE:
- case GL_SPECULAR:
- case GL_AMBIENT_AND_DIFFUSE:
- args = 4;
- break;
- case GL_SHININESS:
- args = 1;
- break;
- case GL_COLOR_INDEXES:
- args = 3;
- break;
- default:
- _mesa_compile_error(ctx, GL_INVALID_ENUM, "material(pname)");
- return;
- }
-
- if (ctx->ExecuteFlag) {
- CALL_Materialfv(ctx->Exec, (face, pname, param));
- }
-
- bitmask = _mesa_material_bitmask(ctx, face, pname, ~0, NULL);
-
- /* Try to eliminate redundant statechanges. Because it is legal to
- * call glMaterial even inside begin/end calls, don't need to worry
- * about ctx->Driver.CurrentSavePrimitive here.
- */
- for (i = 0; i < MAT_ATTRIB_MAX; i++) {
- if (bitmask & (1 << i)) {
- if (ctx->ListState.ActiveMaterialSize[i] == args &&
- compare4fv(ctx->ListState.CurrentMaterial[i], param, args)) {
- bitmask &= ~(1 << i);
- }
- else {
- ctx->ListState.ActiveMaterialSize[i] = args;
- COPY_SZ_4V(ctx->ListState.CurrentMaterial[i], args, param);
- }
- }
- }
-
- /* If this call has effect, return early:
- */
- if (bitmask == 0)
- return;
-
- SAVE_FLUSH_VERTICES(ctx);
-
- n = alloc_instruction(ctx, OPCODE_MATERIAL, 6);
- if (n) {
- n[1].e = face;
- n[2].e = pname;
- for (i = 0; i < args; i++)
- n[3 + i].f = param[i];
- }
-}
-
-static void GLAPIENTRY
-save_Begin(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- GLboolean error = GL_FALSE;
-
- if ( /*mode < GL_POINTS || */ mode > GL_POLYGON) {
- _mesa_compile_error(ctx, GL_INVALID_ENUM, "Begin (mode)");
- error = GL_TRUE;
- }
- else if (ctx->Driver.CurrentSavePrimitive == PRIM_UNKNOWN) {
- /* Typically the first begin. This may raise an error on
- * playback, depending on whether CallList is issued from inside
- * a begin/end or not.
- */
- ctx->Driver.CurrentSavePrimitive = PRIM_INSIDE_UNKNOWN_PRIM;
- }
- else if (ctx->Driver.CurrentSavePrimitive == PRIM_OUTSIDE_BEGIN_END) {
- ctx->Driver.CurrentSavePrimitive = mode;
- }
- else {
- _mesa_compile_error(ctx, GL_INVALID_OPERATION, "recursive begin");
- error = GL_TRUE;
- }
-
- if (!error) {
- /* Give the driver an opportunity to hook in an optimized
- * display list compiler.
- */
- if (ctx->Driver.NotifySaveBegin(ctx, mode))
- return;
-
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_BEGIN, 1);
- if (n) {
- n[1].e = mode;
- }
- }
-
- if (ctx->ExecuteFlag) {
- CALL_Begin(ctx->Exec, (mode));
- }
-}
-
-static void GLAPIENTRY
-save_End(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- SAVE_FLUSH_VERTICES(ctx);
- (void) alloc_instruction(ctx, OPCODE_END, 0);
- ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
- if (ctx->ExecuteFlag) {
- CALL_End(ctx->Exec, ());
- }
-}
-
-static void GLAPIENTRY
-save_Rectf(GLfloat a, GLfloat b, GLfloat c, GLfloat d)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- SAVE_FLUSH_VERTICES(ctx);
- n = alloc_instruction(ctx, OPCODE_RECTF, 4);
- if (n) {
- n[1].f = a;
- n[2].f = b;
- n[3].f = c;
- n[4].f = d;
- }
- if (ctx->ExecuteFlag) {
- CALL_Rectf(ctx->Exec, (a, b, c, d));
- }
-}
-
-
-static void GLAPIENTRY
-save_Vertex2f(GLfloat x, GLfloat y)
-{
- save_Attr2fNV(VERT_ATTRIB_POS, x, y);
-}
-
-static void GLAPIENTRY
-save_Vertex2fv(const GLfloat * v)
-{
- save_Attr2fNV(VERT_ATTRIB_POS, v[0], v[1]);
-}
-
-static void GLAPIENTRY
-save_Vertex3f(GLfloat x, GLfloat y, GLfloat z)
-{
- save_Attr3fNV(VERT_ATTRIB_POS, x, y, z);
-}
-
-static void GLAPIENTRY
-save_Vertex3fv(const GLfloat * v)
-{
- save_Attr3fNV(VERT_ATTRIB_POS, v[0], v[1], v[2]);
-}
-
-static void GLAPIENTRY
-save_Vertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- save_Attr4fNV(VERT_ATTRIB_POS, x, y, z, w);
-}
-
-static void GLAPIENTRY
-save_Vertex4fv(const GLfloat * v)
-{
- save_Attr4fNV(VERT_ATTRIB_POS, v[0], v[1], v[2], v[3]);
-}
-
-static void GLAPIENTRY
-save_TexCoord1f(GLfloat x)
-{
- save_Attr1fNV(VERT_ATTRIB_TEX0, x);
-}
-
-static void GLAPIENTRY
-save_TexCoord1fv(const GLfloat * v)
-{
- save_Attr1fNV(VERT_ATTRIB_TEX0, v[0]);
-}
-
-static void GLAPIENTRY
-save_TexCoord2f(GLfloat x, GLfloat y)
-{
- save_Attr2fNV(VERT_ATTRIB_TEX0, x, y);
-}
-
-static void GLAPIENTRY
-save_TexCoord2fv(const GLfloat * v)
-{
- save_Attr2fNV(VERT_ATTRIB_TEX0, v[0], v[1]);
-}
-
-static void GLAPIENTRY
-save_TexCoord3f(GLfloat x, GLfloat y, GLfloat z)
-{
- save_Attr3fNV(VERT_ATTRIB_TEX0, x, y, z);
-}
-
-static void GLAPIENTRY
-save_TexCoord3fv(const GLfloat * v)
-{
- save_Attr3fNV(VERT_ATTRIB_TEX0, v[0], v[1], v[2]);
-}
-
-static void GLAPIENTRY
-save_TexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- save_Attr4fNV(VERT_ATTRIB_TEX0, x, y, z, w);
-}
-
-static void GLAPIENTRY
-save_TexCoord4fv(const GLfloat * v)
-{
- save_Attr4fNV(VERT_ATTRIB_TEX0, v[0], v[1], v[2], v[3]);
-}
-
-static void GLAPIENTRY
-save_Normal3f(GLfloat x, GLfloat y, GLfloat z)
-{
- save_Attr3fNV(VERT_ATTRIB_NORMAL, x, y, z);
-}
-
-static void GLAPIENTRY
-save_Normal3fv(const GLfloat * v)
-{
- save_Attr3fNV(VERT_ATTRIB_NORMAL, v[0], v[1], v[2]);
-}
-
-static void GLAPIENTRY
-save_FogCoordfEXT(GLfloat x)
-{
- save_Attr1fNV(VERT_ATTRIB_FOG, x);
-}
-
-static void GLAPIENTRY
-save_FogCoordfvEXT(const GLfloat * v)
-{
- save_Attr1fNV(VERT_ATTRIB_FOG, v[0]);
-}
-
-static void GLAPIENTRY
-save_Color3f(GLfloat x, GLfloat y, GLfloat z)
-{
- save_Attr3fNV(VERT_ATTRIB_COLOR0, x, y, z);
-}
-
-static void GLAPIENTRY
-save_Color3fv(const GLfloat * v)
-{
- save_Attr3fNV(VERT_ATTRIB_COLOR0, v[0], v[1], v[2]);
-}
-
-static void GLAPIENTRY
-save_Color4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- save_Attr4fNV(VERT_ATTRIB_COLOR0, x, y, z, w);
-}
-
-static void GLAPIENTRY
-save_Color4fv(const GLfloat * v)
-{
- save_Attr4fNV(VERT_ATTRIB_COLOR0, v[0], v[1], v[2], v[3]);
-}
-
-static void GLAPIENTRY
-save_SecondaryColor3fEXT(GLfloat x, GLfloat y, GLfloat z)
-{
- save_Attr3fNV(VERT_ATTRIB_COLOR1, x, y, z);
-}
-
-static void GLAPIENTRY
-save_SecondaryColor3fvEXT(const GLfloat * v)
-{
- save_Attr3fNV(VERT_ATTRIB_COLOR1, v[0], v[1], v[2]);
-}
-
-
-/* Just call the respective ATTR for texcoord
- */
-static void GLAPIENTRY
-save_MultiTexCoord1f(GLenum target, GLfloat x)
-{
- GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
- save_Attr1fNV(attr, x);
-}
-
-static void GLAPIENTRY
-save_MultiTexCoord1fv(GLenum target, const GLfloat * v)
-{
- GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
- save_Attr1fNV(attr, v[0]);
-}
-
-static void GLAPIENTRY
-save_MultiTexCoord2f(GLenum target, GLfloat x, GLfloat y)
-{
- GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
- save_Attr2fNV(attr, x, y);
-}
-
-static void GLAPIENTRY
-save_MultiTexCoord2fv(GLenum target, const GLfloat * v)
-{
- GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
- save_Attr2fNV(attr, v[0], v[1]);
-}
-
-static void GLAPIENTRY
-save_MultiTexCoord3f(GLenum target, GLfloat x, GLfloat y, GLfloat z)
-{
- GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
- save_Attr3fNV(attr, x, y, z);
-}
-
-static void GLAPIENTRY
-save_MultiTexCoord3fv(GLenum target, const GLfloat * v)
-{
- GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
- save_Attr3fNV(attr, v[0], v[1], v[2]);
-}
-
-static void GLAPIENTRY
-save_MultiTexCoord4f(GLenum target, GLfloat x, GLfloat y,
- GLfloat z, GLfloat w)
-{
- GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
- save_Attr4fNV(attr, x, y, z, w);
-}
-
-static void GLAPIENTRY
-save_MultiTexCoord4fv(GLenum target, const GLfloat * v)
-{
- GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
- save_Attr4fNV(attr, v[0], v[1], v[2], v[3]);
-}
-
-
-/**
- * Record a GL_INVALID_VALUE error when a invalid vertex attribute
- * index is found.
- */
-static void
-index_error(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- _mesa_error(ctx, GL_INVALID_VALUE, "VertexAttribf(index)");
-}
-
-
-/* First level for NV_vertex_program:
- *
- * Check for errors at compile time?.
- */
-static void GLAPIENTRY
-save_VertexAttrib1fNV(GLuint index, GLfloat x)
-{
- if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
- save_Attr1fNV(index, x);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib1fvNV(GLuint index, const GLfloat * v)
-{
- if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
- save_Attr1fNV(index, v[0]);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib2fNV(GLuint index, GLfloat x, GLfloat y)
-{
- if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
- save_Attr2fNV(index, x, y);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib2fvNV(GLuint index, const GLfloat * v)
-{
- if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
- save_Attr2fNV(index, v[0], v[1]);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib3fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z)
-{
- if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
- save_Attr3fNV(index, x, y, z);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib3fvNV(GLuint index, const GLfloat * v)
-{
- if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
- save_Attr3fNV(index, v[0], v[1], v[2]);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib4fNV(GLuint index, GLfloat x, GLfloat y,
- GLfloat z, GLfloat w)
-{
- if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
- save_Attr4fNV(index, x, y, z, w);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib4fvNV(GLuint index, const GLfloat * v)
-{
- if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
- save_Attr4fNV(index, v[0], v[1], v[2], v[3]);
- else
- index_error();
-}
-
-
-
-
-static void GLAPIENTRY
-save_VertexAttrib1fARB(GLuint index, GLfloat x)
-{
- if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- save_Attr1fARB(index, x);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib1fvARB(GLuint index, const GLfloat * v)
-{
- if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- save_Attr1fARB(index, v[0]);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib2fARB(GLuint index, GLfloat x, GLfloat y)
-{
- if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- save_Attr2fARB(index, x, y);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib2fvARB(GLuint index, const GLfloat * v)
-{
- if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- save_Attr2fARB(index, v[0], v[1]);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib3fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z)
-{
- if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- save_Attr3fARB(index, x, y, z);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib3fvARB(GLuint index, const GLfloat * v)
-{
- if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- save_Attr3fARB(index, v[0], v[1], v[2]);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib4fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z,
- GLfloat w)
-{
- if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- save_Attr4fARB(index, x, y, z, w);
- else
- index_error();
-}
-
-static void GLAPIENTRY
-save_VertexAttrib4fvARB(GLuint index, const GLfloat * v)
-{
- if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- save_Attr4fARB(index, v[0], v[1], v[2], v[3]);
- else
- index_error();
-}
-
-
-/* GL_ARB_shader_objects, GL_ARB_vertex/fragment_shader */
-
-static void GLAPIENTRY
-exec_BindAttribLocationARB(GLuint program, GLuint index, const GLchar *name)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_BindAttribLocationARB(ctx->Exec, (program, index, name));
-}
-
-static GLint GLAPIENTRY
-exec_GetAttribLocationARB(GLuint program, const GLchar *name)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- return CALL_GetAttribLocationARB(ctx->Exec, (program, name));
-}
-
-static GLint GLAPIENTRY
-exec_GetUniformLocationARB(GLuint program, const GLchar *name)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- return CALL_GetUniformLocationARB(ctx->Exec, (program, name));
-}
-/* XXX more shader functions needed here */
-
-
-#if FEATURE_EXT_framebuffer_blit
-static void GLAPIENTRY
-save_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
- GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
- GLbitfield mask, GLenum filter)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BLIT_FRAMEBUFFER, 10);
- if (n) {
- n[1].i = srcX0;
- n[2].i = srcY0;
- n[3].i = srcX1;
- n[4].i = srcY1;
- n[5].i = dstX0;
- n[6].i = dstY0;
- n[7].i = dstX1;
- n[8].i = dstY1;
- n[9].i = mask;
- n[10].e = filter;
- }
- if (ctx->ExecuteFlag) {
- CALL_BlitFramebufferEXT(ctx->Exec, (srcX0, srcY0, srcX1, srcY1,
- dstX0, dstY0, dstX1, dstY1,
- mask, filter));
- }
-}
-#endif
-
-
-/** GL_EXT_provoking_vertex */
-static void GLAPIENTRY
-save_ProvokingVertexEXT(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_PROVOKING_VERTEX, 1);
- if (n) {
- n[1].e = mode;
- }
- if (ctx->ExecuteFlag) {
- /*CALL_ProvokingVertexEXT(ctx->Exec, (mode));*/
- _mesa_ProvokingVertexEXT(mode);
- }
-}
-
-
-/** GL_EXT_transform_feedback */
-static void GLAPIENTRY
-save_BeginTransformFeedback(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_BEGIN_TRANSFORM_FEEDBACK, 1);
- if (n) {
- n[1].e = mode;
- }
- if (ctx->ExecuteFlag) {
- CALL_BeginTransformFeedbackEXT(ctx->Exec, (mode));
- }
-}
-
-
-/** GL_EXT_transform_feedback */
-static void GLAPIENTRY
-save_EndTransformFeedback(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- (void) alloc_instruction(ctx, OPCODE_END_TRANSFORM_FEEDBACK, 0);
- if (ctx->ExecuteFlag) {
- CALL_EndTransformFeedbackEXT(ctx->Exec, ());
- }
-}
-
-
-/* aka UseProgram() */
-static void GLAPIENTRY
-save_UseProgramObjectARB(GLhandleARB program)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_USE_PROGRAM, 1);
- if (n) {
- n[1].ui = program;
- }
- if (ctx->ExecuteFlag) {
- CALL_UseProgramObjectARB(ctx->Exec, (program));
- }
-}
-
-
-static void GLAPIENTRY
-save_Uniform1fARB(GLint location, GLfloat x)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_1F, 2);
- if (n) {
- n[1].i = location;
- n[2].f = x;
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform1fARB(ctx->Exec, (location, x));
- }
-}
-
-
-static void GLAPIENTRY
-save_Uniform2fARB(GLint location, GLfloat x, GLfloat y)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_2F, 3);
- if (n) {
- n[1].i = location;
- n[2].f = x;
- n[3].f = y;
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform2fARB(ctx->Exec, (location, x, y));
- }
-}
-
-
-static void GLAPIENTRY
-save_Uniform3fARB(GLint location, GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_3F, 4);
- if (n) {
- n[1].i = location;
- n[2].f = x;
- n[3].f = y;
- n[4].f = z;
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform3fARB(ctx->Exec, (location, x, y, z));
- }
-}
-
-
-static void GLAPIENTRY
-save_Uniform4fARB(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_4F, 5);
- if (n) {
- n[1].i = location;
- n[2].f = x;
- n[3].f = y;
- n[4].f = z;
- n[5].f = w;
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform4fARB(ctx->Exec, (location, x, y, z, w));
- }
-}
-
-
-/** Return copy of memory */
-static void *
-memdup(const void *src, GLsizei bytes)
-{
- void *b = bytes >= 0 ? malloc(bytes) : NULL;
- if (b)
- memcpy(b, src, bytes);
- return b;
-}
-
-
-static void GLAPIENTRY
-save_Uniform1fvARB(GLint location, GLsizei count, const GLfloat *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_1FV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 1 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform1fvARB(ctx->Exec, (location, count, v));
- }
-}
-
-static void GLAPIENTRY
-save_Uniform2fvARB(GLint location, GLsizei count, const GLfloat *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_2FV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 2 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform2fvARB(ctx->Exec, (location, count, v));
- }
-}
-
-static void GLAPIENTRY
-save_Uniform3fvARB(GLint location, GLsizei count, const GLfloat *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_3FV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 3 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform3fvARB(ctx->Exec, (location, count, v));
- }
-}
-
-static void GLAPIENTRY
-save_Uniform4fvARB(GLint location, GLsizei count, const GLfloat *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_4FV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 4 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform4fvARB(ctx->Exec, (location, count, v));
- }
-}
-
-
-static void GLAPIENTRY
-save_Uniform1iARB(GLint location, GLint x)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_1I, 2);
- if (n) {
- n[1].i = location;
- n[2].i = x;
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform1iARB(ctx->Exec, (location, x));
- }
-}
-
-static void GLAPIENTRY
-save_Uniform2iARB(GLint location, GLint x, GLint y)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_2I, 3);
- if (n) {
- n[1].i = location;
- n[2].i = x;
- n[3].i = y;
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform2iARB(ctx->Exec, (location, x, y));
- }
-}
-
-static void GLAPIENTRY
-save_Uniform3iARB(GLint location, GLint x, GLint y, GLint z)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_3I, 4);
- if (n) {
- n[1].i = location;
- n[2].i = x;
- n[3].i = y;
- n[4].i = z;
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform3iARB(ctx->Exec, (location, x, y, z));
- }
-}
-
-static void GLAPIENTRY
-save_Uniform4iARB(GLint location, GLint x, GLint y, GLint z, GLint w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_4I, 5);
- if (n) {
- n[1].i = location;
- n[2].i = x;
- n[3].i = y;
- n[4].i = z;
- n[5].i = w;
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform4iARB(ctx->Exec, (location, x, y, z, w));
- }
-}
-
-
-
-static void GLAPIENTRY
-save_Uniform1ivARB(GLint location, GLsizei count, const GLint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_1IV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 1 * sizeof(GLint));
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform1ivARB(ctx->Exec, (location, count, v));
- }
-}
-
-static void GLAPIENTRY
-save_Uniform2ivARB(GLint location, GLsizei count, const GLint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_2IV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 2 * sizeof(GLint));
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform2ivARB(ctx->Exec, (location, count, v));
- }
-}
-
-static void GLAPIENTRY
-save_Uniform3ivARB(GLint location, GLsizei count, const GLint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_3IV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 3 * sizeof(GLint));
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform3ivARB(ctx->Exec, (location, count, v));
- }
-}
-
-static void GLAPIENTRY
-save_Uniform4ivARB(GLint location, GLsizei count, const GLint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_4IV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 4 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_Uniform4ivARB(ctx->Exec, (location, count, v));
- }
-}
-
-
-
-static void GLAPIENTRY
-save_Uniform1ui(GLint location, GLuint x)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_1UI, 2);
- if (n) {
- n[1].i = location;
- n[2].i = x;
- }
- if (ctx->ExecuteFlag) {
- /*CALL_Uniform1ui(ctx->Exec, (location, x));*/
- }
-}
-
-static void GLAPIENTRY
-save_Uniform2ui(GLint location, GLuint x, GLuint y)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_2UI, 3);
- if (n) {
- n[1].i = location;
- n[2].i = x;
- n[3].i = y;
- }
- if (ctx->ExecuteFlag) {
- /*CALL_Uniform2ui(ctx->Exec, (location, x, y));*/
- }
-}
-
-static void GLAPIENTRY
-save_Uniform3ui(GLint location, GLuint x, GLuint y, GLuint z)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_3UI, 4);
- if (n) {
- n[1].i = location;
- n[2].i = x;
- n[3].i = y;
- n[4].i = z;
- }
- if (ctx->ExecuteFlag) {
- /*CALL_Uniform3ui(ctx->Exec, (location, x, y, z));*/
- }
-}
-
-static void GLAPIENTRY
-save_Uniform4ui(GLint location, GLuint x, GLuint y, GLuint z, GLuint w)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_4UI, 5);
- if (n) {
- n[1].i = location;
- n[2].i = x;
- n[3].i = y;
- n[4].i = z;
- n[5].i = w;
- }
- if (ctx->ExecuteFlag) {
- /*CALL_Uniform4ui(ctx->Exec, (location, x, y, z, w));*/
- }
-}
-
-
-
-static void GLAPIENTRY
-save_Uniform1uiv(GLint location, GLsizei count, const GLuint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_1UIV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 1 * sizeof(*v));
- }
- if (ctx->ExecuteFlag) {
- /*CALL_Uniform1uiv(ctx->Exec, (location, count, v));*/
- }
-}
-
-static void GLAPIENTRY
-save_Uniform2uiv(GLint location, GLsizei count, const GLuint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_2UIV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 2 * sizeof(*v));
- }
- if (ctx->ExecuteFlag) {
- /*CALL_Uniform2uiv(ctx->Exec, (location, count, v));*/
- }
-}
-
-static void GLAPIENTRY
-save_Uniform3uiv(GLint location, GLsizei count, const GLuint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_3UIV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 3 * sizeof(*v));
- }
- if (ctx->ExecuteFlag) {
- /*CALL_Uniform3uiv(ctx->Exec, (location, count, v));*/
- }
-}
-
-static void GLAPIENTRY
-save_Uniform4uiv(GLint location, GLsizei count, const GLuint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_4UIV, 3);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].data = memdup(v, count * 4 * sizeof(*v));
- }
- if (ctx->ExecuteFlag) {
- /*CALL_Uniform4uiv(ctx->Exec, (location, count, v));*/
- }
-}
-
-
-
-static void GLAPIENTRY
-save_UniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose,
- const GLfloat *m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX22, 4);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].b = transpose;
- n[4].data = memdup(m, count * 2 * 2 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_UniformMatrix2fvARB(ctx->Exec, (location, count, transpose, m));
- }
-}
-
-static void GLAPIENTRY
-save_UniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose,
- const GLfloat *m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX33, 4);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].b = transpose;
- n[4].data = memdup(m, count * 3 * 3 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_UniformMatrix3fvARB(ctx->Exec, (location, count, transpose, m));
- }
-}
-
-static void GLAPIENTRY
-save_UniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose,
- const GLfloat *m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX44, 4);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].b = transpose;
- n[4].data = memdup(m, count * 4 * 4 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_UniformMatrix4fvARB(ctx->Exec, (location, count, transpose, m));
- }
-}
-
-
-static void GLAPIENTRY
-save_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
- const GLfloat *m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX23, 4);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].b = transpose;
- n[4].data = memdup(m, count * 2 * 3 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_UniformMatrix2x3fv(ctx->Exec, (location, count, transpose, m));
- }
-}
-
-static void GLAPIENTRY
-save_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
- const GLfloat *m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX32, 4);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].b = transpose;
- n[4].data = memdup(m, count * 3 * 2 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_UniformMatrix3x2fv(ctx->Exec, (location, count, transpose, m));
- }
-}
-
-
-static void GLAPIENTRY
-save_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
- const GLfloat *m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX24, 4);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].b = transpose;
- n[4].data = memdup(m, count * 2 * 4 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_UniformMatrix2x4fv(ctx->Exec, (location, count, transpose, m));
- }
-}
-
-static void GLAPIENTRY
-save_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
- const GLfloat *m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX42, 4);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].b = transpose;
- n[4].data = memdup(m, count * 4 * 2 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_UniformMatrix4x2fv(ctx->Exec, (location, count, transpose, m));
- }
-}
-
-
-static void GLAPIENTRY
-save_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
- const GLfloat *m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX34, 4);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].b = transpose;
- n[4].data = memdup(m, count * 3 * 4 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_UniformMatrix3x4fv(ctx->Exec, (location, count, transpose, m));
- }
-}
-
-static void GLAPIENTRY
-save_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
- const GLfloat *m)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX43, 4);
- if (n) {
- n[1].i = location;
- n[2].i = count;
- n[3].b = transpose;
- n[4].data = memdup(m, count * 4 * 3 * sizeof(GLfloat));
- }
- if (ctx->ExecuteFlag) {
- CALL_UniformMatrix4x3fv(ctx->Exec, (location, count, transpose, m));
- }
-}
-
-static void GLAPIENTRY
-save_UseShaderProgramEXT(GLenum type, GLuint program)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_USE_SHADER_PROGRAM_EXT, 2);
- if (n) {
- n[1].ui = type;
- n[2].ui = program;
- }
- if (ctx->ExecuteFlag) {
- CALL_UseShaderProgramEXT(ctx->Exec, (type, program));
- }
-}
-
-static void GLAPIENTRY
-save_ActiveProgramEXT(GLuint program)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_ACTIVE_PROGRAM_EXT, 1);
- if (n) {
- n[1].ui = program;
- }
- if (ctx->ExecuteFlag) {
- CALL_ActiveProgramEXT(ctx->Exec, (program));
- }
-}
-
-/** GL_EXT_texture_integer */
-static void GLAPIENTRY
-save_ClearColorIi(GLint red, GLint green, GLint blue, GLint alpha)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEARCOLOR_I, 4);
- if (n) {
- n[1].i = red;
- n[2].i = green;
- n[3].i = blue;
- n[4].i = alpha;
- }
- if (ctx->ExecuteFlag) {
- CALL_ClearColorIiEXT(ctx->Exec, (red, green, blue, alpha));
- }
-}
-
-/** GL_EXT_texture_integer */
-static void GLAPIENTRY
-save_ClearColorIui(GLuint red, GLuint green, GLuint blue, GLuint alpha)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_CLEARCOLOR_UI, 4);
- if (n) {
- n[1].ui = red;
- n[2].ui = green;
- n[3].ui = blue;
- n[4].ui = alpha;
- }
- if (ctx->ExecuteFlag) {
- CALL_ClearColorIuiEXT(ctx->Exec, (red, green, blue, alpha));
- }
-}
-
-/** GL_EXT_texture_integer */
-static void GLAPIENTRY
-save_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_TEXPARAMETER_I, 6);
- if (n) {
- n[1].e = target;
- n[2].e = pname;
- n[3].i = params[0];
- n[4].i = params[1];
- n[5].i = params[2];
- n[6].i = params[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_TexParameterIivEXT(ctx->Exec, (target, pname, params));
- }
-}
-
-/** GL_EXT_texture_integer */
-static void GLAPIENTRY
-save_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_TEXPARAMETER_UI, 6);
- if (n) {
- n[1].e = target;
- n[2].e = pname;
- n[3].ui = params[0];
- n[4].ui = params[1];
- n[5].ui = params[2];
- n[6].ui = params[3];
- }
- if (ctx->ExecuteFlag) {
- CALL_TexParameterIuivEXT(ctx->Exec, (target, pname, params));
- }
-}
-
-/** GL_EXT_texture_integer */
-static void GLAPIENTRY
-exec_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexParameterIivEXT(ctx->Exec, (target, pname, params));
-}
-
-/** GL_EXT_texture_integer */
-static void GLAPIENTRY
-exec_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexParameterIuivEXT(ctx->Exec, (target, pname, params));
-}
-
-
-/* GL_ARB_instanced_arrays */
-static void
-save_VertexAttribDivisor(GLuint index, GLuint divisor)
-{
- GET_CURRENT_CONTEXT(ctx);
- Node *n;
- ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- n = alloc_instruction(ctx, OPCODE_VERTEX_ATTRIB_DIVISOR, 2);
- if (n) {
- n[1].ui = index;
- n[2].ui = divisor;
- }
- if (ctx->ExecuteFlag) {
- CALL_VertexAttribDivisorARB(ctx->Exec, (index, divisor));
- }
-}
-
-
-
-/**
- * Save an error-generating command into display list.
- *
- * KW: Will appear in the list before the vertex buffer containing the
- * command that provoked the error. I don't see this as a problem.
- */
-static void
-save_error(struct gl_context *ctx, GLenum error, const char *s)
-{
- Node *n;
- n = alloc_instruction(ctx, OPCODE_ERROR, 2);
- if (n) {
- n[1].e = error;
- n[2].data = (void *) s;
- }
-}
-
-
-/**
- * Compile an error into current display list.
- */
-void
-_mesa_compile_error(struct gl_context *ctx, GLenum error, const char *s)
-{
- if (ctx->CompileFlag)
- save_error(ctx, error, s);
- if (ctx->ExecuteFlag)
- _mesa_error(ctx, error, "%s", s);
-}
-
-
-/**
- * Test if ID names a display list.
- */
-static GLboolean
-islist(struct gl_context *ctx, GLuint list)
-{
- if (list > 0 && lookup_list(ctx, list)) {
- return GL_TRUE;
- }
- else {
- return GL_FALSE;
- }
-}
-
-
-
-/**********************************************************************/
-/* Display list execution */
-/**********************************************************************/
-
-
-/*
- * Execute a display list. Note that the ListBase offset must have already
- * been added before calling this function. I.e. the list argument is
- * the absolute list number, not relative to ListBase.
- * \param list - display list number
- */
-static void
-execute_list(struct gl_context *ctx, GLuint list)
-{
- struct gl_display_list *dlist;
- Node *n;
- GLboolean done;
-
- if (list == 0 || !islist(ctx, list))
- return;
-
- if (ctx->ListState.CallDepth == MAX_LIST_NESTING) {
- /* raise an error? */
- return;
- }
-
- dlist = lookup_list(ctx, list);
- if (!dlist)
- return;
-
- ctx->ListState.CallDepth++;
-
- if (ctx->Driver.BeginCallList)
- ctx->Driver.BeginCallList(ctx, dlist);
-
- n = dlist->Head;
-
- done = GL_FALSE;
- while (!done) {
- const OpCode opcode = n[0].opcode;
-
- if (is_ext_opcode(opcode)) {
- n += ext_opcode_execute(ctx, n);
- }
- else {
- switch (opcode) {
- case OPCODE_ERROR:
- _mesa_error(ctx, n[1].e, "%s", (const char *) n[2].data);
- break;
- case OPCODE_ACCUM:
- CALL_Accum(ctx->Exec, (n[1].e, n[2].f));
- break;
- case OPCODE_ALPHA_FUNC:
- CALL_AlphaFunc(ctx->Exec, (n[1].e, n[2].f));
- break;
- case OPCODE_BIND_TEXTURE:
- CALL_BindTexture(ctx->Exec, (n[1].e, n[2].ui));
- break;
- case OPCODE_BITMAP:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_Bitmap(ctx->Exec, ((GLsizei) n[1].i, (GLsizei) n[2].i,
- n[3].f, n[4].f, n[5].f, n[6].f,
- (const GLubyte *) n[7].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_BLEND_COLOR:
- CALL_BlendColor(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
- break;
- case OPCODE_BLEND_EQUATION:
- CALL_BlendEquation(ctx->Exec, (n[1].e));
- break;
- case OPCODE_BLEND_EQUATION_SEPARATE:
- CALL_BlendEquationSeparateEXT(ctx->Exec, (n[1].e, n[2].e));
- break;
- case OPCODE_BLEND_FUNC_SEPARATE:
- CALL_BlendFuncSeparateEXT(ctx->Exec,
- (n[1].e, n[2].e, n[3].e, n[4].e));
- break;
-
- case OPCODE_BLEND_FUNC_I:
- /* GL_ARB_draw_buffers_blend */
- CALL_BlendFunciARB(ctx->Exec, (n[1].ui, n[2].e, n[3].e));
- break;
- case OPCODE_BLEND_FUNC_SEPARATE_I:
- /* GL_ARB_draw_buffers_blend */
- CALL_BlendFuncSeparateiARB(ctx->Exec, (n[1].ui, n[2].e, n[3].e,
- n[4].e, n[5].e));
- break;
- case OPCODE_BLEND_EQUATION_I:
- /* GL_ARB_draw_buffers_blend */
- CALL_BlendEquationiARB(ctx->Exec, (n[1].ui, n[2].e));
- break;
- case OPCODE_BLEND_EQUATION_SEPARATE_I:
- /* GL_ARB_draw_buffers_blend */
- CALL_BlendEquationSeparateiARB(ctx->Exec,
- (n[1].ui, n[2].e, n[3].e));
- break;
-
- case OPCODE_CALL_LIST:
- /* Generated by glCallList(), don't add ListBase */
- if (ctx->ListState.CallDepth < MAX_LIST_NESTING) {
- execute_list(ctx, n[1].ui);
- }
- break;
- case OPCODE_CALL_LIST_OFFSET:
- /* Generated by glCallLists() so we must add ListBase */
- if (n[2].b) {
- /* user specified a bad data type at compile time */
- _mesa_error(ctx, GL_INVALID_ENUM, "glCallLists(type)");
- }
- else if (ctx->ListState.CallDepth < MAX_LIST_NESTING) {
- GLuint list = (GLuint) (ctx->List.ListBase + n[1].i);
- execute_list(ctx, list);
- }
- break;
- case OPCODE_CLEAR:
- CALL_Clear(ctx->Exec, (n[1].bf));
- break;
- case OPCODE_CLEAR_BUFFER_IV:
- {
- GLint value[4];
- value[0] = n[3].i;
- value[1] = n[4].i;
- value[2] = n[5].i;
- value[3] = n[6].i;
- /*CALL_ClearBufferiv(ctx->Exec, (n[1].e, n[2].i, value));*/
- }
- break;
- case OPCODE_CLEAR_BUFFER_UIV:
- {
- GLuint value[4];
- value[0] = n[3].ui;
- value[1] = n[4].ui;
- value[2] = n[5].ui;
- value[3] = n[6].ui;
- /*CALL_ClearBufferiv(ctx->Exec, (n[1].e, n[2].i, value));*/
- }
- break;
- case OPCODE_CLEAR_BUFFER_FV:
- {
- GLfloat value[4];
- value[0] = n[3].f;
- value[1] = n[4].f;
- value[2] = n[5].f;
- value[3] = n[6].f;
- /*CALL_ClearBufferfv(ctx->Exec, (n[1].e, n[2].i, value));*/
- }
- break;
- case OPCODE_CLEAR_BUFFER_FI:
- /*CALL_ClearBufferfi(ctx->Exec, (n[1].e, n[2].i, n[3].f, n[4].i));*/
- break;
- case OPCODE_CLEAR_COLOR:
- CALL_ClearColor(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
- break;
- case OPCODE_CLEAR_ACCUM:
- CALL_ClearAccum(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
- break;
- case OPCODE_CLEAR_DEPTH:
- CALL_ClearDepth(ctx->Exec, ((GLclampd) n[1].f));
- break;
- case OPCODE_CLEAR_INDEX:
- CALL_ClearIndex(ctx->Exec, ((GLfloat) n[1].ui));
- break;
- case OPCODE_CLEAR_STENCIL:
- CALL_ClearStencil(ctx->Exec, (n[1].i));
- break;
- case OPCODE_CLIP_PLANE:
- {
- GLdouble eq[4];
- eq[0] = n[2].f;
- eq[1] = n[3].f;
- eq[2] = n[4].f;
- eq[3] = n[5].f;
- CALL_ClipPlane(ctx->Exec, (n[1].e, eq));
- }
- break;
- case OPCODE_COLOR_MASK:
- CALL_ColorMask(ctx->Exec, (n[1].b, n[2].b, n[3].b, n[4].b));
- break;
- case OPCODE_COLOR_MASK_INDEXED:
- CALL_ColorMaskIndexedEXT(ctx->Exec, (n[1].ui, n[2].b, n[3].b,
- n[4].b, n[5].b));
- break;
- case OPCODE_COLOR_MATERIAL:
- CALL_ColorMaterial(ctx->Exec, (n[1].e, n[2].e));
- break;
- case OPCODE_COLOR_TABLE:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_ColorTable(ctx->Exec, (n[1].e, n[2].e, n[3].i, n[4].e,
- n[5].e, n[6].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_COLOR_TABLE_PARAMETER_FV:
- {
- GLfloat params[4];
- params[0] = n[3].f;
- params[1] = n[4].f;
- params[2] = n[5].f;
- params[3] = n[6].f;
- CALL_ColorTableParameterfv(ctx->Exec,
- (n[1].e, n[2].e, params));
- }
- break;
- case OPCODE_COLOR_TABLE_PARAMETER_IV:
- {
- GLint params[4];
- params[0] = n[3].i;
- params[1] = n[4].i;
- params[2] = n[5].i;
- params[3] = n[6].i;
- CALL_ColorTableParameteriv(ctx->Exec,
- (n[1].e, n[2].e, params));
- }
- break;
- case OPCODE_COLOR_SUB_TABLE:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_ColorSubTable(ctx->Exec, (n[1].e, n[2].i, n[3].i,
- n[4].e, n[5].e, n[6].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_CONVOLUTION_FILTER_1D:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_ConvolutionFilter1D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
- n[4].e, n[5].e,
- n[6].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_CONVOLUTION_FILTER_2D:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_ConvolutionFilter2D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
- n[4].i, n[5].e, n[6].e,
- n[7].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_CONVOLUTION_PARAMETER_I:
- CALL_ConvolutionParameteri(ctx->Exec, (n[1].e, n[2].e, n[3].i));
- break;
- case OPCODE_CONVOLUTION_PARAMETER_IV:
- {
- GLint params[4];
- params[0] = n[3].i;
- params[1] = n[4].i;
- params[2] = n[5].i;
- params[3] = n[6].i;
- CALL_ConvolutionParameteriv(ctx->Exec,
- (n[1].e, n[2].e, params));
- }
- break;
- case OPCODE_CONVOLUTION_PARAMETER_F:
- CALL_ConvolutionParameterf(ctx->Exec, (n[1].e, n[2].e, n[3].f));
- break;
- case OPCODE_CONVOLUTION_PARAMETER_FV:
- {
- GLfloat params[4];
- params[0] = n[3].f;
- params[1] = n[4].f;
- params[2] = n[5].f;
- params[3] = n[6].f;
- CALL_ConvolutionParameterfv(ctx->Exec,
- (n[1].e, n[2].e, params));
- }
- break;
- case OPCODE_COPY_COLOR_SUB_TABLE:
- CALL_CopyColorSubTable(ctx->Exec, (n[1].e, n[2].i,
- n[3].i, n[4].i, n[5].i));
- break;
- case OPCODE_COPY_COLOR_TABLE:
- CALL_CopyColorSubTable(ctx->Exec, (n[1].e, n[2].i,
- n[3].i, n[4].i, n[5].i));
- break;
- case OPCODE_COPY_PIXELS:
- CALL_CopyPixels(ctx->Exec, (n[1].i, n[2].i,
- (GLsizei) n[3].i, (GLsizei) n[4].i,
- n[5].e));
- break;
- case OPCODE_COPY_TEX_IMAGE1D:
- CALL_CopyTexImage1D(ctx->Exec, (n[1].e, n[2].i, n[3].e, n[4].i,
- n[5].i, n[6].i, n[7].i));
- break;
- case OPCODE_COPY_TEX_IMAGE2D:
- CALL_CopyTexImage2D(ctx->Exec, (n[1].e, n[2].i, n[3].e, n[4].i,
- n[5].i, n[6].i, n[7].i, n[8].i));
- break;
- case OPCODE_COPY_TEX_SUB_IMAGE1D:
- CALL_CopyTexSubImage1D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
- n[4].i, n[5].i, n[6].i));
- break;
- case OPCODE_COPY_TEX_SUB_IMAGE2D:
- CALL_CopyTexSubImage2D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
- n[4].i, n[5].i, n[6].i, n[7].i,
- n[8].i));
- break;
- case OPCODE_COPY_TEX_SUB_IMAGE3D:
- CALL_CopyTexSubImage3D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
- n[4].i, n[5].i, n[6].i, n[7].i,
- n[8].i, n[9].i));
- break;
- case OPCODE_CULL_FACE:
- CALL_CullFace(ctx->Exec, (n[1].e));
- break;
- case OPCODE_DEPTH_FUNC:
- CALL_DepthFunc(ctx->Exec, (n[1].e));
- break;
- case OPCODE_DEPTH_MASK:
- CALL_DepthMask(ctx->Exec, (n[1].b));
- break;
- case OPCODE_DEPTH_RANGE:
- CALL_DepthRange(ctx->Exec,
- ((GLclampd) n[1].f, (GLclampd) n[2].f));
- break;
- case OPCODE_DISABLE:
- CALL_Disable(ctx->Exec, (n[1].e));
- break;
- case OPCODE_DISABLE_INDEXED:
- CALL_DisableIndexedEXT(ctx->Exec, (n[1].ui, n[2].e));
- break;
- case OPCODE_DRAW_BUFFER:
- CALL_DrawBuffer(ctx->Exec, (n[1].e));
- break;
- case OPCODE_DRAW_PIXELS:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_DrawPixels(ctx->Exec, (n[1].i, n[2].i, n[3].e, n[4].e,
- n[5].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_ENABLE:
- CALL_Enable(ctx->Exec, (n[1].e));
- break;
- case OPCODE_ENABLE_INDEXED:
- CALL_EnableIndexedEXT(ctx->Exec, (n[1].ui, n[2].e));
- break;
- case OPCODE_EVALMESH1:
- CALL_EvalMesh1(ctx->Exec, (n[1].e, n[2].i, n[3].i));
- break;
- case OPCODE_EVALMESH2:
- CALL_EvalMesh2(ctx->Exec,
- (n[1].e, n[2].i, n[3].i, n[4].i, n[5].i));
- break;
- case OPCODE_FOG:
- {
- GLfloat p[4];
- p[0] = n[2].f;
- p[1] = n[3].f;
- p[2] = n[4].f;
- p[3] = n[5].f;
- CALL_Fogfv(ctx->Exec, (n[1].e, p));
- }
- break;
- case OPCODE_FRONT_FACE:
- CALL_FrontFace(ctx->Exec, (n[1].e));
- break;
- case OPCODE_FRUSTUM:
- CALL_Frustum(ctx->Exec,
- (n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f));
- break;
- case OPCODE_HINT:
- CALL_Hint(ctx->Exec, (n[1].e, n[2].e));
- break;
- case OPCODE_HISTOGRAM:
- CALL_Histogram(ctx->Exec, (n[1].e, n[2].i, n[3].e, n[4].b));
- break;
- case OPCODE_INDEX_MASK:
- CALL_IndexMask(ctx->Exec, (n[1].ui));
- break;
- case OPCODE_INIT_NAMES:
- CALL_InitNames(ctx->Exec, ());
- break;
- case OPCODE_LIGHT:
- {
- GLfloat p[4];
- p[0] = n[3].f;
- p[1] = n[4].f;
- p[2] = n[5].f;
- p[3] = n[6].f;
- CALL_Lightfv(ctx->Exec, (n[1].e, n[2].e, p));
- }
- break;
- case OPCODE_LIGHT_MODEL:
- {
- GLfloat p[4];
- p[0] = n[2].f;
- p[1] = n[3].f;
- p[2] = n[4].f;
- p[3] = n[5].f;
- CALL_LightModelfv(ctx->Exec, (n[1].e, p));
- }
- break;
- case OPCODE_LINE_STIPPLE:
- CALL_LineStipple(ctx->Exec, (n[1].i, n[2].us));
- break;
- case OPCODE_LINE_WIDTH:
- CALL_LineWidth(ctx->Exec, (n[1].f));
- break;
- case OPCODE_LIST_BASE:
- CALL_ListBase(ctx->Exec, (n[1].ui));
- break;
- case OPCODE_LOAD_IDENTITY:
- CALL_LoadIdentity(ctx->Exec, ());
- break;
- case OPCODE_LOAD_MATRIX:
- if (sizeof(Node) == sizeof(GLfloat)) {
- CALL_LoadMatrixf(ctx->Exec, (&n[1].f));
- }
- else {
- GLfloat m[16];
- GLuint i;
- for (i = 0; i < 16; i++) {
- m[i] = n[1 + i].f;
- }
- CALL_LoadMatrixf(ctx->Exec, (m));
- }
- break;
- case OPCODE_LOAD_NAME:
- CALL_LoadName(ctx->Exec, (n[1].ui));
- break;
- case OPCODE_LOGIC_OP:
- CALL_LogicOp(ctx->Exec, (n[1].e));
- break;
- case OPCODE_MAP1:
- {
- GLenum target = n[1].e;
- GLint ustride = _mesa_evaluator_components(target);
- GLint uorder = n[5].i;
- GLfloat u1 = n[2].f;
- GLfloat u2 = n[3].f;
- CALL_Map1f(ctx->Exec, (target, u1, u2, ustride, uorder,
- (GLfloat *) n[6].data));
- }
- break;
- case OPCODE_MAP2:
- {
- GLenum target = n[1].e;
- GLfloat u1 = n[2].f;
- GLfloat u2 = n[3].f;
- GLfloat v1 = n[4].f;
- GLfloat v2 = n[5].f;
- GLint ustride = n[6].i;
- GLint vstride = n[7].i;
- GLint uorder = n[8].i;
- GLint vorder = n[9].i;
- CALL_Map2f(ctx->Exec, (target, u1, u2, ustride, uorder,
- v1, v2, vstride, vorder,
- (GLfloat *) n[10].data));
- }
- break;
- case OPCODE_MAPGRID1:
- CALL_MapGrid1f(ctx->Exec, (n[1].i, n[2].f, n[3].f));
- break;
- case OPCODE_MAPGRID2:
- CALL_MapGrid2f(ctx->Exec,
- (n[1].i, n[2].f, n[3].f, n[4].i, n[5].f, n[6].f));
- break;
- case OPCODE_MATRIX_MODE:
- CALL_MatrixMode(ctx->Exec, (n[1].e));
- break;
- case OPCODE_MIN_MAX:
- CALL_Minmax(ctx->Exec, (n[1].e, n[2].e, n[3].b));
- break;
- case OPCODE_MULT_MATRIX:
- if (sizeof(Node) == sizeof(GLfloat)) {
- CALL_MultMatrixf(ctx->Exec, (&n[1].f));
- }
- else {
- GLfloat m[16];
- GLuint i;
- for (i = 0; i < 16; i++) {
- m[i] = n[1 + i].f;
- }
- CALL_MultMatrixf(ctx->Exec, (m));
- }
- break;
- case OPCODE_ORTHO:
- CALL_Ortho(ctx->Exec,
- (n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f));
- break;
- case OPCODE_PASSTHROUGH:
- CALL_PassThrough(ctx->Exec, (n[1].f));
- break;
- case OPCODE_PIXEL_MAP:
- CALL_PixelMapfv(ctx->Exec,
- (n[1].e, n[2].i, (GLfloat *) n[3].data));
- break;
- case OPCODE_PIXEL_TRANSFER:
- CALL_PixelTransferf(ctx->Exec, (n[1].e, n[2].f));
- break;
- case OPCODE_PIXEL_ZOOM:
- CALL_PixelZoom(ctx->Exec, (n[1].f, n[2].f));
- break;
- case OPCODE_POINT_SIZE:
- CALL_PointSize(ctx->Exec, (n[1].f));
- break;
- case OPCODE_POINT_PARAMETERS:
- {
- GLfloat params[3];
- params[0] = n[2].f;
- params[1] = n[3].f;
- params[2] = n[4].f;
- CALL_PointParameterfvEXT(ctx->Exec, (n[1].e, params));
- }
- break;
- case OPCODE_POLYGON_MODE:
- CALL_PolygonMode(ctx->Exec, (n[1].e, n[2].e));
- break;
- case OPCODE_POLYGON_STIPPLE:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_PolygonStipple(ctx->Exec, ((GLubyte *) n[1].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_POLYGON_OFFSET:
- CALL_PolygonOffset(ctx->Exec, (n[1].f, n[2].f));
- break;
- case OPCODE_POP_ATTRIB:
- CALL_PopAttrib(ctx->Exec, ());
- break;
- case OPCODE_POP_MATRIX:
- CALL_PopMatrix(ctx->Exec, ());
- break;
- case OPCODE_POP_NAME:
- CALL_PopName(ctx->Exec, ());
- break;
- case OPCODE_PRIORITIZE_TEXTURE:
- CALL_PrioritizeTextures(ctx->Exec, (1, &n[1].ui, &n[2].f));
- break;
- case OPCODE_PUSH_ATTRIB:
- CALL_PushAttrib(ctx->Exec, (n[1].bf));
- break;
- case OPCODE_PUSH_MATRIX:
- CALL_PushMatrix(ctx->Exec, ());
- break;
- case OPCODE_PUSH_NAME:
- CALL_PushName(ctx->Exec, (n[1].ui));
- break;
- case OPCODE_RASTER_POS:
- CALL_RasterPos4f(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
- break;
- case OPCODE_READ_BUFFER:
- CALL_ReadBuffer(ctx->Exec, (n[1].e));
- break;
- case OPCODE_RESET_HISTOGRAM:
- CALL_ResetHistogram(ctx->Exec, (n[1].e));
- break;
- case OPCODE_RESET_MIN_MAX:
- CALL_ResetMinmax(ctx->Exec, (n[1].e));
- break;
- case OPCODE_ROTATE:
- CALL_Rotatef(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
- break;
- case OPCODE_SCALE:
- CALL_Scalef(ctx->Exec, (n[1].f, n[2].f, n[3].f));
- break;
- case OPCODE_SCISSOR:
- CALL_Scissor(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));
- break;
- case OPCODE_SHADE_MODEL:
- CALL_ShadeModel(ctx->Exec, (n[1].e));
- break;
- case OPCODE_PROVOKING_VERTEX:
- CALL_ProvokingVertexEXT(ctx->Exec, (n[1].e));
- break;
- case OPCODE_BEGIN_TRANSFORM_FEEDBACK:
- CALL_BeginTransformFeedbackEXT(ctx->Exec, (n[1].e));
- break;
- case OPCODE_END_TRANSFORM_FEEDBACK:
- CALL_EndTransformFeedbackEXT(ctx->Exec, ());
- break;
- case OPCODE_STENCIL_FUNC:
- CALL_StencilFunc(ctx->Exec, (n[1].e, n[2].i, n[3].ui));
- break;
- case OPCODE_STENCIL_MASK:
- CALL_StencilMask(ctx->Exec, (n[1].ui));
- break;
- case OPCODE_STENCIL_OP:
- CALL_StencilOp(ctx->Exec, (n[1].e, n[2].e, n[3].e));
- break;
- case OPCODE_STENCIL_FUNC_SEPARATE:
- CALL_StencilFuncSeparate(ctx->Exec,
- (n[1].e, n[2].e, n[3].i, n[4].ui));
- break;
- case OPCODE_STENCIL_MASK_SEPARATE:
- CALL_StencilMaskSeparate(ctx->Exec, (n[1].e, n[2].ui));
- break;
- case OPCODE_STENCIL_OP_SEPARATE:
- CALL_StencilOpSeparate(ctx->Exec,
- (n[1].e, n[2].e, n[3].e, n[4].e));
- break;
- case OPCODE_TEXENV:
- {
- GLfloat params[4];
- params[0] = n[3].f;
- params[1] = n[4].f;
- params[2] = n[5].f;
- params[3] = n[6].f;
- CALL_TexEnvfv(ctx->Exec, (n[1].e, n[2].e, params));
- }
- break;
- case OPCODE_TEXGEN:
- {
- GLfloat params[4];
- params[0] = n[3].f;
- params[1] = n[4].f;
- params[2] = n[5].f;
- params[3] = n[6].f;
- CALL_TexGenfv(ctx->Exec, (n[1].e, n[2].e, params));
- }
- break;
- case OPCODE_TEXPARAMETER:
- {
- GLfloat params[4];
- params[0] = n[3].f;
- params[1] = n[4].f;
- params[2] = n[5].f;
- params[3] = n[6].f;
- CALL_TexParameterfv(ctx->Exec, (n[1].e, n[2].e, params));
- }
- break;
- case OPCODE_TEX_IMAGE1D:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_TexImage1D(ctx->Exec, (n[1].e, /* target */
- n[2].i, /* level */
- n[3].i, /* components */
- n[4].i, /* width */
- n[5].e, /* border */
- n[6].e, /* format */
- n[7].e, /* type */
- n[8].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_TEX_IMAGE2D:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_TexImage2D(ctx->Exec, (n[1].e, /* target */
- n[2].i, /* level */
- n[3].i, /* components */
- n[4].i, /* width */
- n[5].i, /* height */
- n[6].e, /* border */
- n[7].e, /* format */
- n[8].e, /* type */
- n[9].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_TEX_IMAGE3D:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_TexImage3D(ctx->Exec, (n[1].e, /* target */
- n[2].i, /* level */
- n[3].i, /* components */
- n[4].i, /* width */
- n[5].i, /* height */
- n[6].i, /* depth */
- n[7].e, /* border */
- n[8].e, /* format */
- n[9].e, /* type */
- n[10].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_TEX_SUB_IMAGE1D:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_TexSubImage1D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
- n[4].i, n[5].e,
- n[6].e, n[7].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_TEX_SUB_IMAGE2D:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_TexSubImage2D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
- n[4].i, n[5].e,
- n[6].i, n[7].e, n[8].e,
- n[9].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_TEX_SUB_IMAGE3D:
- {
- const struct gl_pixelstore_attrib save = ctx->Unpack;
- ctx->Unpack = ctx->DefaultPacking;
- CALL_TexSubImage3D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
- n[4].i, n[5].i, n[6].i, n[7].i,
- n[8].i, n[9].e, n[10].e,
- n[11].data));
- ctx->Unpack = save; /* restore */
- }
- break;
- case OPCODE_TRANSLATE:
- CALL_Translatef(ctx->Exec, (n[1].f, n[2].f, n[3].f));
- break;
- case OPCODE_VIEWPORT:
- CALL_Viewport(ctx->Exec, (n[1].i, n[2].i,
- (GLsizei) n[3].i, (GLsizei) n[4].i));
- break;
- case OPCODE_WINDOW_POS:
- CALL_WindowPos4fMESA(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
- break;
- case OPCODE_ACTIVE_TEXTURE: /* GL_ARB_multitexture */
- CALL_ActiveTextureARB(ctx->Exec, (n[1].e));
- break;
- case OPCODE_COMPRESSED_TEX_IMAGE_1D: /* GL_ARB_texture_compression */
- CALL_CompressedTexImage1DARB(ctx->Exec, (n[1].e, n[2].i, n[3].e,
- n[4].i, n[5].i, n[6].i,
- n[7].data));
- break;
- case OPCODE_COMPRESSED_TEX_IMAGE_2D: /* GL_ARB_texture_compression */
- CALL_CompressedTexImage2DARB(ctx->Exec, (n[1].e, n[2].i, n[3].e,
- n[4].i, n[5].i, n[6].i,
- n[7].i, n[8].data));
- break;
- case OPCODE_COMPRESSED_TEX_IMAGE_3D: /* GL_ARB_texture_compression */
- CALL_CompressedTexImage3DARB(ctx->Exec, (n[1].e, n[2].i, n[3].e,
- n[4].i, n[5].i, n[6].i,
- n[7].i, n[8].i,
- n[9].data));
- break;
- case OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D: /* GL_ARB_texture_compress */
- CALL_CompressedTexSubImage1DARB(ctx->Exec,
- (n[1].e, n[2].i, n[3].i, n[4].i,
- n[5].e, n[6].i, n[7].data));
- break;
- case OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D: /* GL_ARB_texture_compress */
- CALL_CompressedTexSubImage2DARB(ctx->Exec,
- (n[1].e, n[2].i, n[3].i, n[4].i,
- n[5].i, n[6].i, n[7].e, n[8].i,
- n[9].data));
- break;
- case OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D: /* GL_ARB_texture_compress */
- CALL_CompressedTexSubImage3DARB(ctx->Exec,
- (n[1].e, n[2].i, n[3].i, n[4].i,
- n[5].i, n[6].i, n[7].i, n[8].i,
- n[9].e, n[10].i, n[11].data));
- break;
- case OPCODE_SAMPLE_COVERAGE: /* GL_ARB_multisample */
- CALL_SampleCoverageARB(ctx->Exec, (n[1].f, n[2].b));
- break;
- case OPCODE_WINDOW_POS_ARB: /* GL_ARB_window_pos */
- CALL_WindowPos3fMESA(ctx->Exec, (n[1].f, n[2].f, n[3].f));
- break;
-#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
- case OPCODE_BIND_PROGRAM_NV: /* GL_NV_vertex_program */
- CALL_BindProgramNV(ctx->Exec, (n[1].e, n[2].ui));
- break;
-#endif
-#if FEATURE_NV_vertex_program
- case OPCODE_EXECUTE_PROGRAM_NV:
- {
- GLfloat v[4];
- v[0] = n[3].f;
- v[1] = n[4].f;
- v[2] = n[5].f;
- v[3] = n[6].f;
- CALL_ExecuteProgramNV(ctx->Exec, (n[1].e, n[2].ui, v));
- }
- break;
- case OPCODE_REQUEST_RESIDENT_PROGRAMS_NV:
- CALL_RequestResidentProgramsNV(ctx->Exec, (n[1].ui,
- (GLuint *) n[2].data));
- break;
- case OPCODE_LOAD_PROGRAM_NV:
- CALL_LoadProgramNV(ctx->Exec, (n[1].e, n[2].ui, n[3].i,
- (const GLubyte *) n[4].data));
- break;
- case OPCODE_TRACK_MATRIX_NV:
- CALL_TrackMatrixNV(ctx->Exec, (n[1].e, n[2].ui, n[3].e, n[4].e));
- break;
-#endif
-
-#if FEATURE_NV_fragment_program
- case OPCODE_PROGRAM_LOCAL_PARAMETER_ARB:
- CALL_ProgramLocalParameter4fARB(ctx->Exec,
- (n[1].e, n[2].ui, n[3].f, n[4].f,
- n[5].f, n[6].f));
- break;
- case OPCODE_PROGRAM_NAMED_PARAMETER_NV:
- CALL_ProgramNamedParameter4fNV(ctx->Exec, (n[1].ui, n[2].i,
- (const GLubyte *) n[3].
- data, n[4].f, n[5].f,
- n[6].f, n[7].f));
- break;
-#endif
-
- case OPCODE_ACTIVE_STENCIL_FACE_EXT:
- CALL_ActiveStencilFaceEXT(ctx->Exec, (n[1].e));
- break;
- case OPCODE_DEPTH_BOUNDS_EXT:
- CALL_DepthBoundsEXT(ctx->Exec, (n[1].f, n[2].f));
- break;
-#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
- case OPCODE_PROGRAM_STRING_ARB:
- CALL_ProgramStringARB(ctx->Exec,
- (n[1].e, n[2].e, n[3].i, n[4].data));
- break;
-#endif
-#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program || FEATURE_NV_vertex_program
- case OPCODE_PROGRAM_ENV_PARAMETER_ARB:
- CALL_ProgramEnvParameter4fARB(ctx->Exec, (n[1].e, n[2].ui, n[3].f,
- n[4].f, n[5].f,
- n[6].f));
- break;
-#endif
-#if FEATURE_queryobj
- case OPCODE_BEGIN_QUERY_ARB:
- CALL_BeginQueryARB(ctx->Exec, (n[1].e, n[2].ui));
- break;
- case OPCODE_END_QUERY_ARB:
- CALL_EndQueryARB(ctx->Exec, (n[1].e));
- break;
-#endif
- case OPCODE_DRAW_BUFFERS_ARB:
- {
- GLenum buffers[MAX_DRAW_BUFFERS];
- GLint i, count = MIN2(n[1].i, MAX_DRAW_BUFFERS);
- for (i = 0; i < count; i++)
- buffers[i] = n[2 + i].e;
- CALL_DrawBuffersARB(ctx->Exec, (n[1].i, buffers));
- }
- break;
-#if FEATURE_EXT_framebuffer_blit
- case OPCODE_BLIT_FRAMEBUFFER:
- CALL_BlitFramebufferEXT(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i,
- n[5].i, n[6].i, n[7].i, n[8].i,
- n[9].i, n[10].e));
- break;
-#endif
-
- case OPCODE_USE_PROGRAM:
- CALL_UseProgramObjectARB(ctx->Exec, (n[1].ui));
- break;
- case OPCODE_USE_SHADER_PROGRAM_EXT:
- CALL_UseShaderProgramEXT(ctx->Exec, (n[1].ui, n[2].ui));
- break;
- case OPCODE_ACTIVE_PROGRAM_EXT:
- CALL_ActiveProgramEXT(ctx->Exec, (n[1].ui));
- break;
- case OPCODE_UNIFORM_1F:
- CALL_Uniform1fARB(ctx->Exec, (n[1].i, n[2].f));
- break;
- case OPCODE_UNIFORM_2F:
- CALL_Uniform2fARB(ctx->Exec, (n[1].i, n[2].f, n[3].f));
- break;
- case OPCODE_UNIFORM_3F:
- CALL_Uniform3fARB(ctx->Exec, (n[1].i, n[2].f, n[3].f, n[4].f));
- break;
- case OPCODE_UNIFORM_4F:
- CALL_Uniform4fARB(ctx->Exec,
- (n[1].i, n[2].f, n[3].f, n[4].f, n[5].f));
- break;
- case OPCODE_UNIFORM_1FV:
- CALL_Uniform1fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
- break;
- case OPCODE_UNIFORM_2FV:
- CALL_Uniform2fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
- break;
- case OPCODE_UNIFORM_3FV:
- CALL_Uniform3fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
- break;
- case OPCODE_UNIFORM_4FV:
- CALL_Uniform4fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
- break;
- case OPCODE_UNIFORM_1I:
- CALL_Uniform1iARB(ctx->Exec, (n[1].i, n[2].i));
- break;
- case OPCODE_UNIFORM_2I:
- CALL_Uniform2iARB(ctx->Exec, (n[1].i, n[2].i, n[3].i));
- break;
- case OPCODE_UNIFORM_3I:
- CALL_Uniform3iARB(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));
- break;
- case OPCODE_UNIFORM_4I:
- CALL_Uniform4iARB(ctx->Exec,
- (n[1].i, n[2].i, n[3].i, n[4].i, n[5].i));
- break;
- case OPCODE_UNIFORM_1IV:
- CALL_Uniform1ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
- break;
- case OPCODE_UNIFORM_2IV:
- CALL_Uniform2ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
- break;
- case OPCODE_UNIFORM_3IV:
- CALL_Uniform3ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
- break;
- case OPCODE_UNIFORM_4IV:
- CALL_Uniform4ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
- break;
- case OPCODE_UNIFORM_1UI:
- /*CALL_Uniform1uiARB(ctx->Exec, (n[1].i, n[2].i));*/
- break;
- case OPCODE_UNIFORM_2UI:
- /*CALL_Uniform2uiARB(ctx->Exec, (n[1].i, n[2].i, n[3].i));*/
- break;
- case OPCODE_UNIFORM_3UI:
- /*CALL_Uniform3uiARB(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));*/
- break;
- case OPCODE_UNIFORM_4UI:
- /*CALL_Uniform4uiARB(ctx->Exec,
- (n[1].i, n[2].i, n[3].i, n[4].i, n[5].i));
- */
- break;
- case OPCODE_UNIFORM_1UIV:
- /*CALL_Uniform1uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
- break;
- case OPCODE_UNIFORM_2UIV:
- /*CALL_Uniform2uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
- break;
- case OPCODE_UNIFORM_3UIV:
- /*CALL_Uniform3uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
- break;
- case OPCODE_UNIFORM_4UIV:
- /*CALL_Uniform4uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
- break;
- case OPCODE_UNIFORM_MATRIX22:
- CALL_UniformMatrix2fvARB(ctx->Exec,
- (n[1].i, n[2].i, n[3].b, n[4].data));
- break;
- case OPCODE_UNIFORM_MATRIX33:
- CALL_UniformMatrix3fvARB(ctx->Exec,
- (n[1].i, n[2].i, n[3].b, n[4].data));
- break;
- case OPCODE_UNIFORM_MATRIX44:
- CALL_UniformMatrix4fvARB(ctx->Exec,
- (n[1].i, n[2].i, n[3].b, n[4].data));
- break;
- case OPCODE_UNIFORM_MATRIX23:
- CALL_UniformMatrix2x3fv(ctx->Exec,
- (n[1].i, n[2].i, n[3].b, n[4].data));
- break;
- case OPCODE_UNIFORM_MATRIX32:
- CALL_UniformMatrix3x2fv(ctx->Exec,
- (n[1].i, n[2].i, n[3].b, n[4].data));
- break;
- case OPCODE_UNIFORM_MATRIX24:
- CALL_UniformMatrix2x4fv(ctx->Exec,
- (n[1].i, n[2].i, n[3].b, n[4].data));
- break;
- case OPCODE_UNIFORM_MATRIX42:
- CALL_UniformMatrix4x2fv(ctx->Exec,
- (n[1].i, n[2].i, n[3].b, n[4].data));
- break;
- case OPCODE_UNIFORM_MATRIX34:
- CALL_UniformMatrix3x4fv(ctx->Exec,
- (n[1].i, n[2].i, n[3].b, n[4].data));
- break;
- case OPCODE_UNIFORM_MATRIX43:
- CALL_UniformMatrix4x3fv(ctx->Exec,
- (n[1].i, n[2].i, n[3].b, n[4].data));
- break;
-
- case OPCODE_TEX_BUMP_PARAMETER_ATI:
- {
- GLfloat values[4];
- GLuint i, pname = n[1].ui;
-
- for (i = 0; i < 4; i++)
- values[i] = n[1 + i].f;
- CALL_TexBumpParameterfvATI(ctx->Exec, (pname, values));
- }
- break;
-#if FEATURE_ATI_fragment_shader
- case OPCODE_BIND_FRAGMENT_SHADER_ATI:
- CALL_BindFragmentShaderATI(ctx->Exec, (n[1].i));
- break;
- case OPCODE_SET_FRAGMENT_SHADER_CONSTANTS_ATI:
- {
- GLfloat values[4];
- GLuint i, dst = n[1].ui;
-
- for (i = 0; i < 4; i++)
- values[i] = n[1 + i].f;
- CALL_SetFragmentShaderConstantATI(ctx->Exec, (dst, values));
- }
- break;
-#endif
- case OPCODE_ATTR_1F_NV:
- CALL_VertexAttrib1fNV(ctx->Exec, (n[1].e, n[2].f));
- break;
- case OPCODE_ATTR_2F_NV:
- /* Really shouldn't have to do this - the Node structure
- * is convenient, but it would be better to store the data
- * packed appropriately so that it can be sent directly
- * on. With x86_64 becoming common, this will start to
- * matter more.
- */
- if (sizeof(Node) == sizeof(GLfloat))
- CALL_VertexAttrib2fvNV(ctx->Exec, (n[1].e, &n[2].f));
- else
- CALL_VertexAttrib2fNV(ctx->Exec, (n[1].e, n[2].f, n[3].f));
- break;
- case OPCODE_ATTR_3F_NV:
- if (sizeof(Node) == sizeof(GLfloat))
- CALL_VertexAttrib3fvNV(ctx->Exec, (n[1].e, &n[2].f));
- else
- CALL_VertexAttrib3fNV(ctx->Exec, (n[1].e, n[2].f, n[3].f,
- n[4].f));
- break;
- case OPCODE_ATTR_4F_NV:
- if (sizeof(Node) == sizeof(GLfloat))
- CALL_VertexAttrib4fvNV(ctx->Exec, (n[1].e, &n[2].f));
- else
- CALL_VertexAttrib4fNV(ctx->Exec, (n[1].e, n[2].f, n[3].f,
- n[4].f, n[5].f));
- break;
- case OPCODE_ATTR_1F_ARB:
- CALL_VertexAttrib1fARB(ctx->Exec, (n[1].e, n[2].f));
- break;
- case OPCODE_ATTR_2F_ARB:
- /* Really shouldn't have to do this - the Node structure
- * is convenient, but it would be better to store the data
- * packed appropriately so that it can be sent directly
- * on. With x86_64 becoming common, this will start to
- * matter more.
- */
- if (sizeof(Node) == sizeof(GLfloat))
- CALL_VertexAttrib2fvARB(ctx->Exec, (n[1].e, &n[2].f));
- else
- CALL_VertexAttrib2fARB(ctx->Exec, (n[1].e, n[2].f, n[3].f));
- break;
- case OPCODE_ATTR_3F_ARB:
- if (sizeof(Node) == sizeof(GLfloat))
- CALL_VertexAttrib3fvARB(ctx->Exec, (n[1].e, &n[2].f));
- else
- CALL_VertexAttrib3fARB(ctx->Exec, (n[1].e, n[2].f, n[3].f,
- n[4].f));
- break;
- case OPCODE_ATTR_4F_ARB:
- if (sizeof(Node) == sizeof(GLfloat))
- CALL_VertexAttrib4fvARB(ctx->Exec, (n[1].e, &n[2].f));
- else
- CALL_VertexAttrib4fARB(ctx->Exec, (n[1].e, n[2].f, n[3].f,
- n[4].f, n[5].f));
- break;
- case OPCODE_MATERIAL:
- if (sizeof(Node) == sizeof(GLfloat))
- CALL_Materialfv(ctx->Exec, (n[1].e, n[2].e, &n[3].f));
- else {
- GLfloat f[4];
- f[0] = n[3].f;
- f[1] = n[4].f;
- f[2] = n[5].f;
- f[3] = n[6].f;
- CALL_Materialfv(ctx->Exec, (n[1].e, n[2].e, f));
- }
- break;
- case OPCODE_BEGIN:
- CALL_Begin(ctx->Exec, (n[1].e));
- break;
- case OPCODE_END:
- CALL_End(ctx->Exec, ());
- break;
- case OPCODE_RECTF:
- CALL_Rectf(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
- break;
- case OPCODE_EVAL_C1:
- CALL_EvalCoord1f(ctx->Exec, (n[1].f));
- break;
- case OPCODE_EVAL_C2:
- CALL_EvalCoord2f(ctx->Exec, (n[1].f, n[2].f));
- break;
- case OPCODE_EVAL_P1:
- CALL_EvalPoint1(ctx->Exec, (n[1].i));
- break;
- case OPCODE_EVAL_P2:
- CALL_EvalPoint2(ctx->Exec, (n[1].i, n[2].i));
- break;
-
- /* GL_EXT_texture_integer */
- case OPCODE_CLEARCOLOR_I:
- CALL_ClearColorIiEXT(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));
- break;
- case OPCODE_CLEARCOLOR_UI:
- CALL_ClearColorIuiEXT(ctx->Exec,
- (n[1].ui, n[2].ui, n[3].ui, n[4].ui));
- break;
- case OPCODE_TEXPARAMETER_I:
- {
- GLint params[4];
- params[0] = n[3].i;
- params[1] = n[4].i;
- params[2] = n[5].i;
- params[3] = n[6].i;
- CALL_TexParameterIivEXT(ctx->Exec, (n[1].e, n[2].e, params));
- }
- break;
- case OPCODE_TEXPARAMETER_UI:
- {
- GLuint params[4];
- params[0] = n[3].ui;
- params[1] = n[4].ui;
- params[2] = n[5].ui;
- params[3] = n[6].ui;
- CALL_TexParameterIuivEXT(ctx->Exec, (n[1].e, n[2].e, params));
- }
- break;
-
- case OPCODE_VERTEX_ATTRIB_DIVISOR:
- /* GL_ARB_instanced_arrays */
- CALL_VertexAttribDivisorARB(ctx->Exec, (n[1].ui, n[2].ui));
- break;
-
- case OPCODE_CONTINUE:
- n = (Node *) n[1].next;
- break;
- case OPCODE_END_OF_LIST:
- done = GL_TRUE;
- break;
- default:
- {
- char msg[1000];
- _mesa_snprintf(msg, sizeof(msg), "Error in execute_list: opcode=%d",
- (int) opcode);
- _mesa_problem(ctx, "%s", msg);
- }
- done = GL_TRUE;
- }
-
- /* increment n to point to next compiled command */
- if (opcode != OPCODE_CONTINUE) {
- n += InstSize[opcode];
- }
- }
- }
-
- if (ctx->Driver.EndCallList)
- ctx->Driver.EndCallList(ctx);
-
- ctx->ListState.CallDepth--;
-}
-
-
-
-/**********************************************************************/
-/* GL functions */
-/**********************************************************************/
-
-/**
- * Test if a display list number is valid.
- */
-static GLboolean GLAPIENTRY
-_mesa_IsList(GLuint list)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0); /* must be called before assert */
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
- return islist(ctx, list);
-}
-
-
-/**
- * Delete a sequence of consecutive display lists.
- */
-static void GLAPIENTRY
-_mesa_DeleteLists(GLuint list, GLsizei range)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint i;
- FLUSH_VERTICES(ctx, 0); /* must be called before assert */
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (range < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteLists");
- return;
- }
- for (i = list; i < list + range; i++) {
- destroy_list(ctx, i);
- }
-}
-
-
-/**
- * Return a display list number, n, such that lists n through n+range-1
- * are free.
- */
-static GLuint GLAPIENTRY
-_mesa_GenLists(GLsizei range)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint base;
- FLUSH_VERTICES(ctx, 0); /* must be called before assert */
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
-
- if (range < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGenLists");
- return 0;
- }
- if (range == 0) {
- return 0;
- }
-
- /*
- * Make this an atomic operation
- */
- _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
-
- base = _mesa_HashFindFreeKeyBlock(ctx->Shared->DisplayList, range);
- if (base) {
- /* reserve the list IDs by with empty/dummy lists */
- GLint i;
- for (i = 0; i < range; i++) {
- _mesa_HashInsert(ctx->Shared->DisplayList, base + i,
- make_list(base + i, 1));
- }
- }
-
- _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
-
- return base;
-}
-
-
-/**
- * Begin a new display list.
- */
-static void GLAPIENTRY
-_mesa_NewList(GLuint name, GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- FLUSH_CURRENT(ctx, 0); /* must be called before assert */
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glNewList %u %s\n", name,
- _mesa_lookup_enum_by_nr(mode));
-
- if (name == 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glNewList");
- return;
- }
-
- if (mode != GL_COMPILE && mode != GL_COMPILE_AND_EXECUTE) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glNewList");
- return;
- }
-
- if (ctx->ListState.CurrentList) {
- /* already compiling a display list */
- _mesa_error(ctx, GL_INVALID_OPERATION, "glNewList");
- return;
- }
-
- ctx->CompileFlag = GL_TRUE;
- ctx->ExecuteFlag = (mode == GL_COMPILE_AND_EXECUTE);
-
- /* Reset acumulated list state:
- */
- invalidate_saved_current_state( ctx );
-
- /* Allocate new display list */
- ctx->ListState.CurrentList = make_list(name, BLOCK_SIZE);
- ctx->ListState.CurrentBlock = ctx->ListState.CurrentList->Head;
- ctx->ListState.CurrentPos = 0;
-
- ctx->Driver.NewList(ctx, name, mode);
-
- ctx->CurrentDispatch = ctx->Save;
- _glapi_set_dispatch(ctx->CurrentDispatch);
-}
-
-
-/**
- * End definition of current display list.
- */
-static void GLAPIENTRY
-_mesa_EndList(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- SAVE_FLUSH_VERTICES(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glEndList\n");
-
- /* Check that a list is under construction */
- if (!ctx->ListState.CurrentList) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glEndList");
- return;
- }
-
- /* Call before emitting END_OF_LIST, in case the driver wants to
- * emit opcodes itself.
- */
- ctx->Driver.EndList(ctx);
-
- (void) alloc_instruction(ctx, OPCODE_END_OF_LIST, 0);
-
- /* Destroy old list, if any */
- destroy_list(ctx, ctx->ListState.CurrentList->Name);
-
- /* Install the new list */
- _mesa_HashInsert(ctx->Shared->DisplayList,
- ctx->ListState.CurrentList->Name,
- ctx->ListState.CurrentList);
-
-
- if (MESA_VERBOSE & VERBOSE_DISPLAY_LIST)
- mesa_print_display_list(ctx->ListState.CurrentList->Name);
-
- ctx->ListState.CurrentList = NULL;
- ctx->ExecuteFlag = GL_TRUE;
- ctx->CompileFlag = GL_FALSE;
-
- ctx->CurrentDispatch = ctx->Exec;
- _glapi_set_dispatch(ctx->CurrentDispatch);
-}
-
-
-void GLAPIENTRY
-_mesa_CallList(GLuint list)
-{
- GLboolean save_compile_flag;
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_CURRENT(ctx, 0);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glCallList %d\n", list);
-
- if (list == 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glCallList(list==0)");
- return;
- }
-
- if (0)
- mesa_print_display_list( list );
-
- /* VERY IMPORTANT: Save the CompileFlag status, turn it off,
- * execute the display list, and restore the CompileFlag.
- */
- save_compile_flag = ctx->CompileFlag;
- if (save_compile_flag) {
- ctx->CompileFlag = GL_FALSE;
- }
-
- execute_list(ctx, list);
- ctx->CompileFlag = save_compile_flag;
-
- /* also restore API function pointers to point to "save" versions */
- if (save_compile_flag) {
- ctx->CurrentDispatch = ctx->Save;
- _glapi_set_dispatch(ctx->CurrentDispatch);
- }
-}
-
-
-/**
- * Execute glCallLists: call multiple display lists.
- */
-void GLAPIENTRY
-_mesa_CallLists(GLsizei n, GLenum type, const GLvoid * lists)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i;
- GLboolean save_compile_flag;
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glCallLists %d\n", n);
-
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- case GL_2_BYTES:
- case GL_3_BYTES:
- case GL_4_BYTES:
- /* OK */
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glCallLists(type)");
- return;
- }
-
- /* Save the CompileFlag status, turn it off, execute display list,
- * and restore the CompileFlag.
- */
- save_compile_flag = ctx->CompileFlag;
- ctx->CompileFlag = GL_FALSE;
-
- for (i = 0; i < n; i++) {
- GLuint list = (GLuint) (ctx->List.ListBase + translate_id(i, type, lists));
- execute_list(ctx, list);
- }
-
- ctx->CompileFlag = save_compile_flag;
-
- /* also restore API function pointers to point to "save" versions */
- if (save_compile_flag) {
- ctx->CurrentDispatch = ctx->Save;
- _glapi_set_dispatch(ctx->CurrentDispatch);
- }
-}
-
-
-/**
- * Set the offset added to list numbers in glCallLists.
- */
-static void GLAPIENTRY
-_mesa_ListBase(GLuint base)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0); /* must be called before assert */
- ASSERT_OUTSIDE_BEGIN_END(ctx);
- ctx->List.ListBase = base;
-}
-
-
-/* Can no longer assume ctx->Exec->Func is equal to _mesa_Func.
- */
-static void GLAPIENTRY
-exec_Finish(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_Finish(ctx->Exec, ());
-}
-
-static void GLAPIENTRY
-exec_Flush(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_Flush(ctx->Exec, ());
-}
-
-static void GLAPIENTRY
-exec_GetBooleanv(GLenum pname, GLboolean *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetBooleanv(ctx->Exec, (pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetClipPlane(GLenum plane, GLdouble * equation)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetClipPlane(ctx->Exec, (plane, equation));
-}
-
-static void GLAPIENTRY
-exec_GetDoublev(GLenum pname, GLdouble *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetDoublev(ctx->Exec, (pname, params));
-}
-
-static GLenum GLAPIENTRY
-exec_GetError(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- return CALL_GetError(ctx->Exec, ());
-}
-
-static void GLAPIENTRY
-exec_GetFloatv(GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetFloatv(ctx->Exec, (pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetIntegerv(GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetIntegerv(ctx->Exec, (pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetLightfv(GLenum light, GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetLightfv(ctx->Exec, (light, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetLightiv(GLenum light, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetLightiv(ctx->Exec, (light, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetMapdv(GLenum target, GLenum query, GLdouble * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetMapdv(ctx->Exec, (target, query, v));
-}
-
-static void GLAPIENTRY
-exec_GetMapfv(GLenum target, GLenum query, GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetMapfv(ctx->Exec, (target, query, v));
-}
-
-static void GLAPIENTRY
-exec_GetMapiv(GLenum target, GLenum query, GLint * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetMapiv(ctx->Exec, (target, query, v));
-}
-
-static void GLAPIENTRY
-exec_GetMaterialfv(GLenum face, GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetMaterialfv(ctx->Exec, (face, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetMaterialiv(GLenum face, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetMaterialiv(ctx->Exec, (face, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetPixelMapfv(GLenum map, GLfloat *values)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetPixelMapfv(ctx->Exec, (map, values));
-}
-
-static void GLAPIENTRY
-exec_GetPixelMapuiv(GLenum map, GLuint *values)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetPixelMapuiv(ctx->Exec, (map, values));
-}
-
-static void GLAPIENTRY
-exec_GetPixelMapusv(GLenum map, GLushort *values)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetPixelMapusv(ctx->Exec, (map, values));
-}
-
-static void GLAPIENTRY
-exec_GetPolygonStipple(GLubyte * dest)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetPolygonStipple(ctx->Exec, (dest));
-}
-
-static const GLubyte *GLAPIENTRY
-exec_GetString(GLenum name)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- return CALL_GetString(ctx->Exec, (name));
-}
-
-static void GLAPIENTRY
-exec_GetTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexEnvfv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetTexEnviv(GLenum target, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexEnviv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetTexGendv(GLenum coord, GLenum pname, GLdouble *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexGendv(ctx->Exec, (coord, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetTexGenfv(GLenum coord, GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexGenfv(ctx->Exec, (coord, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetTexGeniv(GLenum coord, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexGeniv(ctx->Exec, (coord, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetTexImage(GLenum target, GLint level, GLenum format,
- GLenum type, GLvoid * pixels)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexImage(ctx->Exec, (target, level, format, type, pixels));
-}
-
-static void GLAPIENTRY
-exec_GetTexLevelParameterfv(GLenum target, GLint level,
- GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexLevelParameterfv(ctx->Exec, (target, level, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetTexLevelParameteriv(GLenum target, GLint level,
- GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexLevelParameteriv(ctx->Exec, (target, level, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexParameterfv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetTexParameteriv(ctx->Exec, (target, pname, params));
-}
-
-static GLboolean GLAPIENTRY
-exec_IsEnabled(GLenum cap)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- return CALL_IsEnabled(ctx->Exec, (cap));
-}
-
-static void GLAPIENTRY
-exec_PixelStoref(GLenum pname, GLfloat param)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_PixelStoref(ctx->Exec, (pname, param));
-}
-
-static void GLAPIENTRY
-exec_PixelStorei(GLenum pname, GLint param)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_PixelStorei(ctx->Exec, (pname, param));
-}
-
-static void GLAPIENTRY
-exec_ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type, GLvoid * pixels)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_ReadPixels(ctx->Exec, (x, y, width, height, format, type, pixels));
-}
-
-static GLint GLAPIENTRY
-exec_RenderMode(GLenum mode)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- return CALL_RenderMode(ctx->Exec, (mode));
-}
-
-static void GLAPIENTRY
-exec_FeedbackBuffer(GLsizei size, GLenum type, GLfloat * buffer)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_FeedbackBuffer(ctx->Exec, (size, type, buffer));
-}
-
-static void GLAPIENTRY
-exec_SelectBuffer(GLsizei size, GLuint * buffer)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_SelectBuffer(ctx->Exec, (size, buffer));
-}
-
-static GLboolean GLAPIENTRY
-exec_AreTexturesResident(GLsizei n, const GLuint * texName,
- GLboolean * residences)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- return CALL_AreTexturesResident(ctx->Exec, (n, texName, residences));
-}
-
-static void GLAPIENTRY
-exec_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_ColorPointer(ctx->Exec, (size, type, stride, ptr));
-}
-
-static void GLAPIENTRY
-exec_DeleteTextures(GLsizei n, const GLuint * texName)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_DeleteTextures(ctx->Exec, (n, texName));
-}
-
-static void GLAPIENTRY
-exec_DisableClientState(GLenum cap)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_DisableClientState(ctx->Exec, (cap));
-}
-
-static void GLAPIENTRY
-exec_EdgeFlagPointer(GLsizei stride, const GLvoid * vptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_EdgeFlagPointer(ctx->Exec, (stride, vptr));
-}
-
-static void GLAPIENTRY
-exec_EnableClientState(GLenum cap)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_EnableClientState(ctx->Exec, (cap));
-}
-
-static void GLAPIENTRY
-exec_GenTextures(GLsizei n, GLuint * texName)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GenTextures(ctx->Exec, (n, texName));
-}
-
-static void GLAPIENTRY
-exec_GetPointerv(GLenum pname, GLvoid **params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetPointerv(ctx->Exec, (pname, params));
-}
-
-static void GLAPIENTRY
-exec_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_IndexPointer(ctx->Exec, (type, stride, ptr));
-}
-
-static void GLAPIENTRY
-exec_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid * pointer)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_InterleavedArrays(ctx->Exec, (format, stride, pointer));
-}
-
-static GLboolean GLAPIENTRY
-exec_IsTexture(GLuint texture)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- return CALL_IsTexture(ctx->Exec, (texture));
-}
-
-static void GLAPIENTRY
-exec_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_NormalPointer(ctx->Exec, (type, stride, ptr));
-}
-
-static void GLAPIENTRY
-exec_PopClientAttrib(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_PopClientAttrib(ctx->Exec, ());
-}
-
-static void GLAPIENTRY
-exec_PushClientAttrib(GLbitfield mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_PushClientAttrib(ctx->Exec, (mask));
-}
-
-static void GLAPIENTRY
-exec_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
- const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_TexCoordPointer(ctx->Exec, (size, type, stride, ptr));
-}
-
-static void GLAPIENTRY
-exec_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid * img)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetCompressedTexImageARB(ctx->Exec, (target, level, img));
-}
-
-static void GLAPIENTRY
-exec_VertexPointer(GLint size, GLenum type, GLsizei stride,
- const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_VertexPointer(ctx->Exec, (size, type, stride, ptr));
-}
-
-static void GLAPIENTRY
-exec_CopyConvolutionFilter1D(GLenum target, GLenum internalFormat,
- GLint x, GLint y, GLsizei width)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_CopyConvolutionFilter1D(ctx->Exec,
- (target, internalFormat, x, y, width));
-}
-
-static void GLAPIENTRY
-exec_CopyConvolutionFilter2D(GLenum target, GLenum internalFormat,
- GLint x, GLint y, GLsizei width, GLsizei height)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_CopyConvolutionFilter2D(ctx->Exec,
- (target, internalFormat, x, y, width,
- height));
-}
-
-static void GLAPIENTRY
-exec_GetColorTable(GLenum target, GLenum format, GLenum type, GLvoid * data)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetColorTable(ctx->Exec, (target, format, type, data));
-}
-
-static void GLAPIENTRY
-exec_GetColorTableParameterfv(GLenum target, GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetColorTableParameterfv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetColorTableParameteriv(GLenum target, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetColorTableParameteriv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetConvolutionFilter(GLenum target, GLenum format, GLenum type,
- GLvoid * image)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetConvolutionFilter(ctx->Exec, (target, format, type, image));
-}
-
-static void GLAPIENTRY
-exec_GetConvolutionParameterfv(GLenum target, GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetConvolutionParameterfv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetConvolutionParameteriv(GLenum target, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetConvolutionParameteriv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetHistogram(GLenum target, GLboolean reset, GLenum format,
- GLenum type, GLvoid *values)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetHistogram(ctx->Exec, (target, reset, format, type, values));
-}
-
-static void GLAPIENTRY
-exec_GetHistogramParameterfv(GLenum target, GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetHistogramParameterfv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetHistogramParameteriv(GLenum target, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetHistogramParameteriv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetMinmax(GLenum target, GLboolean reset, GLenum format,
- GLenum type, GLvoid *values)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetMinmax(ctx->Exec, (target, reset, format, type, values));
-}
-
-static void GLAPIENTRY
-exec_GetMinmaxParameterfv(GLenum target, GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetMinmaxParameterfv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetMinmaxParameteriv(GLenum target, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetMinmaxParameteriv(ctx->Exec, (target, pname, params));
-}
-
-static void GLAPIENTRY
-exec_GetSeparableFilter(GLenum target, GLenum format, GLenum type,
- GLvoid *row, GLvoid *column, GLvoid *span)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_GetSeparableFilter(ctx->Exec,
- (target, format, type, row, column, span));
-}
-
-static void GLAPIENTRY
-exec_SeparableFilter2D(GLenum target, GLenum internalFormat,
- GLsizei width, GLsizei height, GLenum format,
- GLenum type, const GLvoid *row, const GLvoid *column)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_SeparableFilter2D(ctx->Exec,
- (target, internalFormat, width, height, format,
- type, row, column));
-}
-
-static void GLAPIENTRY
-exec_ColorPointerEXT(GLint size, GLenum type, GLsizei stride,
- GLsizei count, const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_ColorPointerEXT(ctx->Exec, (size, type, stride, count, ptr));
-}
-
-static void GLAPIENTRY
-exec_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_EdgeFlagPointerEXT(ctx->Exec, (stride, count, ptr));
-}
-
-static void GLAPIENTRY
-exec_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
- const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_IndexPointerEXT(ctx->Exec, (type, stride, count, ptr));
-}
-
-static void GLAPIENTRY
-exec_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
- const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_NormalPointerEXT(ctx->Exec, (type, stride, count, ptr));
-}
-
-static void GLAPIENTRY
-exec_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
- GLsizei count, const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_TexCoordPointerEXT(ctx->Exec, (size, type, stride, count, ptr));
-}
-
-static void GLAPIENTRY
-exec_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
- GLsizei count, const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_VertexPointerEXT(ctx->Exec, (size, type, stride, count, ptr));
-}
-
-static void GLAPIENTRY
-exec_LockArraysEXT(GLint first, GLsizei count)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_LockArraysEXT(ctx->Exec, (first, count));
-}
-
-static void GLAPIENTRY
-exec_UnlockArraysEXT(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_UnlockArraysEXT(ctx->Exec, ());
-}
-
-static void GLAPIENTRY
-exec_ClientActiveTextureARB(GLenum target)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_ClientActiveTextureARB(ctx->Exec, (target));
-}
-
-static void GLAPIENTRY
-exec_SecondaryColorPointerEXT(GLint size, GLenum type,
- GLsizei stride, const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_SecondaryColorPointerEXT(ctx->Exec, (size, type, stride, ptr));
-}
-
-static void GLAPIENTRY
-exec_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_FogCoordPointerEXT(ctx->Exec, (type, stride, ptr));
-}
-
-/* GL_EXT_multi_draw_arrays */
-static void GLAPIENTRY
-exec_MultiDrawArraysEXT(GLenum mode, const GLint *first,
- const GLsizei *count, GLsizei primcount)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_MultiDrawArraysEXT(ctx->Exec, (mode, first, count, primcount));
-}
-
-/* GL_IBM_multimode_draw_arrays */
-static void GLAPIENTRY
-exec_MultiModeDrawArraysIBM(const GLenum * mode, const GLint * first,
- const GLsizei * count, GLsizei primcount,
- GLint modestride)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_MultiModeDrawArraysIBM(ctx->Exec,
- (mode, first, count, primcount, modestride));
-}
-
-/* GL_IBM_multimode_draw_arrays */
-static void GLAPIENTRY
-exec_MultiModeDrawElementsIBM(const GLenum * mode,
- const GLsizei * count,
- GLenum type,
- const GLvoid * const *indices,
- GLsizei primcount, GLint modestride)
-{
- GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, 0);
- CALL_MultiModeDrawElementsIBM(ctx->Exec,
- (mode, count, type, indices, primcount,
- modestride));
-}
-
-
-
-/**
- * Setup the given dispatch table to point to Mesa's display list
- * building functions.
- *
- * This does not include any of the tnl functions - they are
- * initialized from _mesa_init_api_defaults and from the active vtxfmt
- * struct.
- */
-struct _glapi_table *
-_mesa_create_save_table(void)
-{
- struct _glapi_table *table;
-
- table = _mesa_alloc_dispatch_table(_gloffset_COUNT);
- if (table == NULL)
- return NULL;
-
- _mesa_loopback_init_api_table(table);
-
- /* GL 1.0 */
- SET_Accum(table, save_Accum);
- SET_AlphaFunc(table, save_AlphaFunc);
- SET_Bitmap(table, save_Bitmap);
- SET_BlendFunc(table, save_BlendFunc);
- SET_CallList(table, save_CallList);
- SET_CallLists(table, save_CallLists);
- SET_Clear(table, save_Clear);
- SET_ClearAccum(table, save_ClearAccum);
- SET_ClearColor(table, save_ClearColor);
- SET_ClearDepth(table, save_ClearDepth);
- SET_ClearIndex(table, save_ClearIndex);
- SET_ClearStencil(table, save_ClearStencil);
- SET_ClipPlane(table, save_ClipPlane);
- SET_ColorMask(table, save_ColorMask);
- SET_ColorMaskIndexedEXT(table, save_ColorMaskIndexed);
- SET_ColorMaterial(table, save_ColorMaterial);
- SET_CopyPixels(table, save_CopyPixels);
- SET_CullFace(table, save_CullFace);
- SET_DeleteLists(table, _mesa_DeleteLists);
- SET_DepthFunc(table, save_DepthFunc);
- SET_DepthMask(table, save_DepthMask);
- SET_DepthRange(table, save_DepthRange);
- SET_Disable(table, save_Disable);
- SET_DisableIndexedEXT(table, save_DisableIndexed);
- SET_DrawBuffer(table, save_DrawBuffer);
- SET_DrawPixels(table, save_DrawPixels);
- SET_Enable(table, save_Enable);
- SET_EnableIndexedEXT(table, save_EnableIndexed);
- SET_EndList(table, _mesa_EndList);
- SET_EvalMesh1(table, save_EvalMesh1);
- SET_EvalMesh2(table, save_EvalMesh2);
- SET_Finish(table, exec_Finish);
- SET_Flush(table, exec_Flush);
- SET_Fogf(table, save_Fogf);
- SET_Fogfv(table, save_Fogfv);
- SET_Fogi(table, save_Fogi);
- SET_Fogiv(table, save_Fogiv);
- SET_FrontFace(table, save_FrontFace);
- SET_Frustum(table, save_Frustum);
- SET_GenLists(table, _mesa_GenLists);
- SET_GetBooleanv(table, exec_GetBooleanv);
- SET_GetClipPlane(table, exec_GetClipPlane);
- SET_GetDoublev(table, exec_GetDoublev);
- SET_GetError(table, exec_GetError);
- SET_GetFloatv(table, exec_GetFloatv);
- SET_GetIntegerv(table, exec_GetIntegerv);
- SET_GetLightfv(table, exec_GetLightfv);
- SET_GetLightiv(table, exec_GetLightiv);
- SET_GetMapdv(table, exec_GetMapdv);
- SET_GetMapfv(table, exec_GetMapfv);
- SET_GetMapiv(table, exec_GetMapiv);
- SET_GetMaterialfv(table, exec_GetMaterialfv);
- SET_GetMaterialiv(table, exec_GetMaterialiv);
- SET_GetPixelMapfv(table, exec_GetPixelMapfv);
- SET_GetPixelMapuiv(table, exec_GetPixelMapuiv);
- SET_GetPixelMapusv(table, exec_GetPixelMapusv);
- SET_GetPolygonStipple(table, exec_GetPolygonStipple);
- SET_GetString(table, exec_GetString);
- SET_GetTexEnvfv(table, exec_GetTexEnvfv);
- SET_GetTexEnviv(table, exec_GetTexEnviv);
- SET_GetTexGendv(table, exec_GetTexGendv);
- SET_GetTexGenfv(table, exec_GetTexGenfv);
- SET_GetTexGeniv(table, exec_GetTexGeniv);
- SET_GetTexImage(table, exec_GetTexImage);
- SET_GetTexLevelParameterfv(table, exec_GetTexLevelParameterfv);
- SET_GetTexLevelParameteriv(table, exec_GetTexLevelParameteriv);
- SET_GetTexParameterfv(table, exec_GetTexParameterfv);
- SET_GetTexParameteriv(table, exec_GetTexParameteriv);
- SET_Hint(table, save_Hint);
- SET_IndexMask(table, save_IndexMask);
- SET_InitNames(table, save_InitNames);
- SET_IsEnabled(table, exec_IsEnabled);
- SET_IsList(table, _mesa_IsList);
- SET_LightModelf(table, save_LightModelf);
- SET_LightModelfv(table, save_LightModelfv);
- SET_LightModeli(table, save_LightModeli);
- SET_LightModeliv(table, save_LightModeliv);
- SET_Lightf(table, save_Lightf);
- SET_Lightfv(table, save_Lightfv);
- SET_Lighti(table, save_Lighti);
- SET_Lightiv(table, save_Lightiv);
- SET_LineStipple(table, save_LineStipple);
- SET_LineWidth(table, save_LineWidth);
- SET_ListBase(table, save_ListBase);
- SET_LoadIdentity(table, save_LoadIdentity);
- SET_LoadMatrixd(table, save_LoadMatrixd);
- SET_LoadMatrixf(table, save_LoadMatrixf);
- SET_LoadName(table, save_LoadName);
- SET_LogicOp(table, save_LogicOp);
- SET_Map1d(table, save_Map1d);
- SET_Map1f(table, save_Map1f);
- SET_Map2d(table, save_Map2d);
- SET_Map2f(table, save_Map2f);
- SET_MapGrid1d(table, save_MapGrid1d);
- SET_MapGrid1f(table, save_MapGrid1f);
- SET_MapGrid2d(table, save_MapGrid2d);
- SET_MapGrid2f(table, save_MapGrid2f);
- SET_MatrixMode(table, save_MatrixMode);
- SET_MultMatrixd(table, save_MultMatrixd);
- SET_MultMatrixf(table, save_MultMatrixf);
- SET_NewList(table, save_NewList);
- SET_Ortho(table, save_Ortho);
- SET_PassThrough(table, save_PassThrough);
- SET_PixelMapfv(table, save_PixelMapfv);
- SET_PixelMapuiv(table, save_PixelMapuiv);
- SET_PixelMapusv(table, save_PixelMapusv);
- SET_PixelStoref(table, exec_PixelStoref);
- SET_PixelStorei(table, exec_PixelStorei);
- SET_PixelTransferf(table, save_PixelTransferf);
- SET_PixelTransferi(table, save_PixelTransferi);
- SET_PixelZoom(table, save_PixelZoom);
- SET_PointSize(table, save_PointSize);
- SET_PolygonMode(table, save_PolygonMode);
- SET_PolygonOffset(table, save_PolygonOffset);
- SET_PolygonStipple(table, save_PolygonStipple);
- SET_PopAttrib(table, save_PopAttrib);
- SET_PopMatrix(table, save_PopMatrix);
- SET_PopName(table, save_PopName);
- SET_PushAttrib(table, save_PushAttrib);
- SET_PushMatrix(table, save_PushMatrix);
- SET_PushName(table, save_PushName);
- SET_RasterPos2d(table, save_RasterPos2d);
- SET_RasterPos2dv(table, save_RasterPos2dv);
- SET_RasterPos2f(table, save_RasterPos2f);
- SET_RasterPos2fv(table, save_RasterPos2fv);
- SET_RasterPos2i(table, save_RasterPos2i);
- SET_RasterPos2iv(table, save_RasterPos2iv);
- SET_RasterPos2s(table, save_RasterPos2s);
- SET_RasterPos2sv(table, save_RasterPos2sv);
- SET_RasterPos3d(table, save_RasterPos3d);
- SET_RasterPos3dv(table, save_RasterPos3dv);
- SET_RasterPos3f(table, save_RasterPos3f);
- SET_RasterPos3fv(table, save_RasterPos3fv);
- SET_RasterPos3i(table, save_RasterPos3i);
- SET_RasterPos3iv(table, save_RasterPos3iv);
- SET_RasterPos3s(table, save_RasterPos3s);
- SET_RasterPos3sv(table, save_RasterPos3sv);
- SET_RasterPos4d(table, save_RasterPos4d);
- SET_RasterPos4dv(table, save_RasterPos4dv);
- SET_RasterPos4f(table, save_RasterPos4f);
- SET_RasterPos4fv(table, save_RasterPos4fv);
- SET_RasterPos4i(table, save_RasterPos4i);
- SET_RasterPos4iv(table, save_RasterPos4iv);
- SET_RasterPos4s(table, save_RasterPos4s);
- SET_RasterPos4sv(table, save_RasterPos4sv);
- SET_ReadBuffer(table, save_ReadBuffer);
- SET_ReadPixels(table, exec_ReadPixels);
- SET_RenderMode(table, exec_RenderMode);
- SET_Rotated(table, save_Rotated);
- SET_Rotatef(table, save_Rotatef);
- SET_Scaled(table, save_Scaled);
- SET_Scalef(table, save_Scalef);
- SET_Scissor(table, save_Scissor);
- SET_FeedbackBuffer(table, exec_FeedbackBuffer);
- SET_SelectBuffer(table, exec_SelectBuffer);
- SET_ShadeModel(table, save_ShadeModel);
- SET_StencilFunc(table, save_StencilFunc);
- SET_StencilMask(table, save_StencilMask);
- SET_StencilOp(table, save_StencilOp);
- SET_TexEnvf(table, save_TexEnvf);
- SET_TexEnvfv(table, save_TexEnvfv);
- SET_TexEnvi(table, save_TexEnvi);
- SET_TexEnviv(table, save_TexEnviv);
- SET_TexGend(table, save_TexGend);
- SET_TexGendv(table, save_TexGendv);
- SET_TexGenf(table, save_TexGenf);
- SET_TexGenfv(table, save_TexGenfv);
- SET_TexGeni(table, save_TexGeni);
- SET_TexGeniv(table, save_TexGeniv);
- SET_TexImage1D(table, save_TexImage1D);
- SET_TexImage2D(table, save_TexImage2D);
- SET_TexParameterf(table, save_TexParameterf);
- SET_TexParameterfv(table, save_TexParameterfv);
- SET_TexParameteri(table, save_TexParameteri);
- SET_TexParameteriv(table, save_TexParameteriv);
- SET_Translated(table, save_Translated);
- SET_Translatef(table, save_Translatef);
- SET_Viewport(table, save_Viewport);
-
- /* GL 1.1 */
- SET_AreTexturesResident(table, exec_AreTexturesResident);
- SET_BindTexture(table, save_BindTexture);
- SET_ColorPointer(table, exec_ColorPointer);
- SET_CopyTexImage1D(table, save_CopyTexImage1D);
- SET_CopyTexImage2D(table, save_CopyTexImage2D);
- SET_CopyTexSubImage1D(table, save_CopyTexSubImage1D);
- SET_CopyTexSubImage2D(table, save_CopyTexSubImage2D);
- SET_DeleteTextures(table, exec_DeleteTextures);
- SET_DisableClientState(table, exec_DisableClientState);
- SET_EdgeFlagPointer(table, exec_EdgeFlagPointer);
- SET_EnableClientState(table, exec_EnableClientState);
- SET_GenTextures(table, exec_GenTextures);
- SET_GetPointerv(table, exec_GetPointerv);
- SET_IndexPointer(table, exec_IndexPointer);
- SET_InterleavedArrays(table, exec_InterleavedArrays);
- SET_IsTexture(table, exec_IsTexture);
- SET_NormalPointer(table, exec_NormalPointer);
- SET_PopClientAttrib(table, exec_PopClientAttrib);
- SET_PrioritizeTextures(table, save_PrioritizeTextures);
- SET_PushClientAttrib(table, exec_PushClientAttrib);
- SET_TexCoordPointer(table, exec_TexCoordPointer);
- SET_TexSubImage1D(table, save_TexSubImage1D);
- SET_TexSubImage2D(table, save_TexSubImage2D);
- SET_VertexPointer(table, exec_VertexPointer);
-
- /* GL 1.2 */
- SET_CopyTexSubImage3D(table, save_CopyTexSubImage3D);
- SET_TexImage3D(table, save_TexImage3D);
- SET_TexSubImage3D(table, save_TexSubImage3D);
-
- /* GL 2.0 */
- SET_StencilFuncSeparate(table, save_StencilFuncSeparate);
- SET_StencilMaskSeparate(table, save_StencilMaskSeparate);
- SET_StencilOpSeparate(table, save_StencilOpSeparate);
-
- /* ATI_separate_stencil */
- SET_StencilFuncSeparateATI(table, save_StencilFuncSeparateATI);
-
- /* GL_ARB_imaging */
- /* Not all are supported */
- SET_BlendColor(table, save_BlendColor);
- SET_BlendEquation(table, save_BlendEquation);
- SET_ColorSubTable(table, save_ColorSubTable);
- SET_ColorTable(table, save_ColorTable);
- SET_ColorTableParameterfv(table, save_ColorTableParameterfv);
- SET_ColorTableParameteriv(table, save_ColorTableParameteriv);
- SET_ConvolutionFilter1D(table, save_ConvolutionFilter1D);
- SET_ConvolutionFilter2D(table, save_ConvolutionFilter2D);
- SET_ConvolutionParameterf(table, save_ConvolutionParameterf);
- SET_ConvolutionParameterfv(table, save_ConvolutionParameterfv);
- SET_ConvolutionParameteri(table, save_ConvolutionParameteri);
- SET_ConvolutionParameteriv(table, save_ConvolutionParameteriv);
- SET_CopyColorSubTable(table, save_CopyColorSubTable);
- SET_CopyColorTable(table, save_CopyColorTable);
- SET_CopyConvolutionFilter1D(table, exec_CopyConvolutionFilter1D);
- SET_CopyConvolutionFilter2D(table, exec_CopyConvolutionFilter2D);
- SET_GetColorTable(table, exec_GetColorTable);
- SET_GetColorTableParameterfv(table, exec_GetColorTableParameterfv);
- SET_GetColorTableParameteriv(table, exec_GetColorTableParameteriv);
- SET_GetConvolutionFilter(table, exec_GetConvolutionFilter);
- SET_GetConvolutionParameterfv(table, exec_GetConvolutionParameterfv);
- SET_GetConvolutionParameteriv(table, exec_GetConvolutionParameteriv);
- SET_GetHistogram(table, exec_GetHistogram);
- SET_GetHistogramParameterfv(table, exec_GetHistogramParameterfv);
- SET_GetHistogramParameteriv(table, exec_GetHistogramParameteriv);
- SET_GetMinmax(table, exec_GetMinmax);
- SET_GetMinmaxParameterfv(table, exec_GetMinmaxParameterfv);
- SET_GetMinmaxParameteriv(table, exec_GetMinmaxParameteriv);
- SET_GetSeparableFilter(table, exec_GetSeparableFilter);
- SET_Histogram(table, save_Histogram);
- SET_Minmax(table, save_Minmax);
- SET_ResetHistogram(table, save_ResetHistogram);
- SET_ResetMinmax(table, save_ResetMinmax);
- SET_SeparableFilter2D(table, exec_SeparableFilter2D);
-
- /* 2. GL_EXT_blend_color */
-#if 0
- SET_BlendColorEXT(table, save_BlendColorEXT);
-#endif
-
- /* 3. GL_EXT_polygon_offset */
- SET_PolygonOffsetEXT(table, save_PolygonOffsetEXT);
-
- /* 6. GL_EXT_texture3d */
-#if 0
- SET_CopyTexSubImage3DEXT(table, save_CopyTexSubImage3D);
- SET_TexImage3DEXT(table, save_TexImage3DEXT);
- SET_TexSubImage3DEXT(table, save_TexSubImage3D);
-#endif
-
- /* 14. GL_SGI_color_table */
-#if 0
- SET_ColorTableSGI(table, save_ColorTable);
- SET_ColorSubTableSGI(table, save_ColorSubTable);
- SET_GetColorTableSGI(table, exec_GetColorTable);
- SET_GetColorTableParameterfvSGI(table, exec_GetColorTableParameterfv);
- SET_GetColorTableParameterivSGI(table, exec_GetColorTableParameteriv);
-#endif
-
- /* 30. GL_EXT_vertex_array */
- SET_ColorPointerEXT(table, exec_ColorPointerEXT);
- SET_EdgeFlagPointerEXT(table, exec_EdgeFlagPointerEXT);
- SET_IndexPointerEXT(table, exec_IndexPointerEXT);
- SET_NormalPointerEXT(table, exec_NormalPointerEXT);
- SET_TexCoordPointerEXT(table, exec_TexCoordPointerEXT);
- SET_VertexPointerEXT(table, exec_VertexPointerEXT);
-
- /* 37. GL_EXT_blend_minmax */
-#if 0
- SET_BlendEquationEXT(table, save_BlendEquationEXT);
-#endif
-
- /* 54. GL_EXT_point_parameters */
- SET_PointParameterfEXT(table, save_PointParameterfEXT);
- SET_PointParameterfvEXT(table, save_PointParameterfvEXT);
-
- /* 97. GL_EXT_compiled_vertex_array */
- SET_LockArraysEXT(table, exec_LockArraysEXT);
- SET_UnlockArraysEXT(table, exec_UnlockArraysEXT);
-
- /* 145. GL_EXT_secondary_color */
- SET_SecondaryColorPointerEXT(table, exec_SecondaryColorPointerEXT);
-
- /* 148. GL_EXT_multi_draw_arrays */
- SET_MultiDrawArraysEXT(table, exec_MultiDrawArraysEXT);
-
- /* 149. GL_EXT_fog_coord */
- SET_FogCoordPointerEXT(table, exec_FogCoordPointerEXT);
-
- /* 173. GL_EXT_blend_func_separate */
- SET_BlendFuncSeparateEXT(table, save_BlendFuncSeparateEXT);
-
- /* 196. GL_MESA_resize_buffers */
- SET_ResizeBuffersMESA(table, _mesa_ResizeBuffersMESA);
-
- /* 197. GL_MESA_window_pos */
- SET_WindowPos2dMESA(table, save_WindowPos2dMESA);
- SET_WindowPos2dvMESA(table, save_WindowPos2dvMESA);
- SET_WindowPos2fMESA(table, save_WindowPos2fMESA);
- SET_WindowPos2fvMESA(table, save_WindowPos2fvMESA);
- SET_WindowPos2iMESA(table, save_WindowPos2iMESA);
- SET_WindowPos2ivMESA(table, save_WindowPos2ivMESA);
- SET_WindowPos2sMESA(table, save_WindowPos2sMESA);
- SET_WindowPos2svMESA(table, save_WindowPos2svMESA);
- SET_WindowPos3dMESA(table, save_WindowPos3dMESA);
- SET_WindowPos3dvMESA(table, save_WindowPos3dvMESA);
- SET_WindowPos3fMESA(table, save_WindowPos3fMESA);
- SET_WindowPos3fvMESA(table, save_WindowPos3fvMESA);
- SET_WindowPos3iMESA(table, save_WindowPos3iMESA);
- SET_WindowPos3ivMESA(table, save_WindowPos3ivMESA);
- SET_WindowPos3sMESA(table, save_WindowPos3sMESA);
- SET_WindowPos3svMESA(table, save_WindowPos3svMESA);
- SET_WindowPos4dMESA(table, save_WindowPos4dMESA);
- SET_WindowPos4dvMESA(table, save_WindowPos4dvMESA);
- SET_WindowPos4fMESA(table, save_WindowPos4fMESA);
- SET_WindowPos4fvMESA(table, save_WindowPos4fvMESA);
- SET_WindowPos4iMESA(table, save_WindowPos4iMESA);
- SET_WindowPos4ivMESA(table, save_WindowPos4ivMESA);
- SET_WindowPos4sMESA(table, save_WindowPos4sMESA);
- SET_WindowPos4svMESA(table, save_WindowPos4svMESA);
-
- /* 200. GL_IBM_multimode_draw_arrays */
- SET_MultiModeDrawArraysIBM(table, exec_MultiModeDrawArraysIBM);
- SET_MultiModeDrawElementsIBM(table, exec_MultiModeDrawElementsIBM);
-
-#if FEATURE_NV_vertex_program
- /* 233. GL_NV_vertex_program */
- /* The following commands DO NOT go into display lists:
- * AreProgramsResidentNV, IsProgramNV, GenProgramsNV, DeleteProgramsNV,
- * VertexAttribPointerNV, GetProgram*, GetVertexAttrib*
- */
- SET_BindProgramNV(table, save_BindProgramNV);
- SET_DeleteProgramsNV(table, _mesa_DeletePrograms);
- SET_ExecuteProgramNV(table, save_ExecuteProgramNV);
- SET_GenProgramsNV(table, _mesa_GenPrograms);
- SET_AreProgramsResidentNV(table, _mesa_AreProgramsResidentNV);
- SET_RequestResidentProgramsNV(table, save_RequestResidentProgramsNV);
- SET_GetProgramParameterfvNV(table, _mesa_GetProgramParameterfvNV);
- SET_GetProgramParameterdvNV(table, _mesa_GetProgramParameterdvNV);
- SET_GetProgramivNV(table, _mesa_GetProgramivNV);
- SET_GetProgramStringNV(table, _mesa_GetProgramStringNV);
- SET_GetTrackMatrixivNV(table, _mesa_GetTrackMatrixivNV);
- SET_GetVertexAttribdvNV(table, _mesa_GetVertexAttribdvNV);
- SET_GetVertexAttribfvNV(table, _mesa_GetVertexAttribfvNV);
- SET_GetVertexAttribivNV(table, _mesa_GetVertexAttribivNV);
- SET_GetVertexAttribPointervNV(table, _mesa_GetVertexAttribPointervNV);
- SET_IsProgramNV(table, _mesa_IsProgramARB);
- SET_LoadProgramNV(table, save_LoadProgramNV);
- SET_ProgramEnvParameter4dARB(table, save_ProgramEnvParameter4dARB);
- SET_ProgramEnvParameter4dvARB(table, save_ProgramEnvParameter4dvARB);
- SET_ProgramEnvParameter4fARB(table, save_ProgramEnvParameter4fARB);
- SET_ProgramEnvParameter4fvARB(table, save_ProgramEnvParameter4fvARB);
- SET_ProgramParameters4dvNV(table, save_ProgramParameters4dvNV);
- SET_ProgramParameters4fvNV(table, save_ProgramParameters4fvNV);
- SET_TrackMatrixNV(table, save_TrackMatrixNV);
- SET_VertexAttribPointerNV(table, _mesa_VertexAttribPointerNV);
-#endif
-
- /* 244. GL_ATI_envmap_bumpmap */
- SET_TexBumpParameterivATI(table, save_TexBumpParameterivATI);
- SET_TexBumpParameterfvATI(table, save_TexBumpParameterfvATI);
-
- /* 245. GL_ATI_fragment_shader */
-#if FEATURE_ATI_fragment_shader
- SET_BindFragmentShaderATI(table, save_BindFragmentShaderATI);
- SET_SetFragmentShaderConstantATI(table, save_SetFragmentShaderConstantATI);
-#endif
-
- /* 282. GL_NV_fragment_program */
-#if FEATURE_NV_fragment_program
- SET_ProgramNamedParameter4fNV(table, save_ProgramNamedParameter4fNV);
- SET_ProgramNamedParameter4dNV(table, save_ProgramNamedParameter4dNV);
- SET_ProgramNamedParameter4fvNV(table, save_ProgramNamedParameter4fvNV);
- SET_ProgramNamedParameter4dvNV(table, save_ProgramNamedParameter4dvNV);
- SET_GetProgramNamedParameterfvNV(table,
- _mesa_GetProgramNamedParameterfvNV);
- SET_GetProgramNamedParameterdvNV(table,
- _mesa_GetProgramNamedParameterdvNV);
- SET_ProgramLocalParameter4dARB(table, save_ProgramLocalParameter4dARB);
- SET_ProgramLocalParameter4dvARB(table, save_ProgramLocalParameter4dvARB);
- SET_ProgramLocalParameter4fARB(table, save_ProgramLocalParameter4fARB);
- SET_ProgramLocalParameter4fvARB(table, save_ProgramLocalParameter4fvARB);
- SET_GetProgramLocalParameterdvARB(table,
- _mesa_GetProgramLocalParameterdvARB);
- SET_GetProgramLocalParameterfvARB(table,
- _mesa_GetProgramLocalParameterfvARB);
-#endif
-
- /* 262. GL_NV_point_sprite */
- SET_PointParameteriNV(table, save_PointParameteriNV);
- SET_PointParameterivNV(table, save_PointParameterivNV);
-
- /* 268. GL_EXT_stencil_two_side */
- SET_ActiveStencilFaceEXT(table, save_ActiveStencilFaceEXT);
-
- /* 273. GL_APPLE_vertex_array_object */
- SET_BindVertexArrayAPPLE(table, _mesa_BindVertexArrayAPPLE);
- SET_DeleteVertexArraysAPPLE(table, _mesa_DeleteVertexArraysAPPLE);
- SET_GenVertexArraysAPPLE(table, _mesa_GenVertexArraysAPPLE);
- SET_IsVertexArrayAPPLE(table, _mesa_IsVertexArrayAPPLE);
-
- /* ???. GL_EXT_depth_bounds_test */
- SET_DepthBoundsEXT(table, save_DepthBoundsEXT);
-
- /* ARB 1. GL_ARB_multitexture */
- SET_ActiveTextureARB(table, save_ActiveTextureARB);
- SET_ClientActiveTextureARB(table, exec_ClientActiveTextureARB);
-
- /* ARB 3. GL_ARB_transpose_matrix */
- SET_LoadTransposeMatrixdARB(table, save_LoadTransposeMatrixdARB);
- SET_LoadTransposeMatrixfARB(table, save_LoadTransposeMatrixfARB);
- SET_MultTransposeMatrixdARB(table, save_MultTransposeMatrixdARB);
- SET_MultTransposeMatrixfARB(table, save_MultTransposeMatrixfARB);
-
- /* ARB 5. GL_ARB_multisample */
- SET_SampleCoverageARB(table, save_SampleCoverageARB);
-
- /* ARB 12. GL_ARB_texture_compression */
- SET_CompressedTexImage3DARB(table, save_CompressedTexImage3DARB);
- SET_CompressedTexImage2DARB(table, save_CompressedTexImage2DARB);
- SET_CompressedTexImage1DARB(table, save_CompressedTexImage1DARB);
- SET_CompressedTexSubImage3DARB(table, save_CompressedTexSubImage3DARB);
- SET_CompressedTexSubImage2DARB(table, save_CompressedTexSubImage2DARB);
- SET_CompressedTexSubImage1DARB(table, save_CompressedTexSubImage1DARB);
- SET_GetCompressedTexImageARB(table, exec_GetCompressedTexImageARB);
-
- /* ARB 14. GL_ARB_point_parameters */
- /* aliased with EXT_point_parameters functions */
-
- /* ARB 25. GL_ARB_window_pos */
- /* aliased with MESA_window_pos functions */
-
- /* ARB 26. GL_ARB_vertex_program */
- /* ARB 27. GL_ARB_fragment_program */
-#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
- /* glVertexAttrib* functions alias the NV ones, handled elsewhere */
- SET_VertexAttribPointerARB(table, _mesa_VertexAttribPointerARB);
- SET_EnableVertexAttribArrayARB(table, _mesa_EnableVertexAttribArrayARB);
- SET_DisableVertexAttribArrayARB(table, _mesa_DisableVertexAttribArrayARB);
- SET_ProgramStringARB(table, save_ProgramStringARB);
- SET_BindProgramNV(table, save_BindProgramNV);
- SET_DeleteProgramsNV(table, _mesa_DeletePrograms);
- SET_GenProgramsNV(table, _mesa_GenPrograms);
- SET_IsProgramNV(table, _mesa_IsProgramARB);
- SET_GetVertexAttribdvNV(table, _mesa_GetVertexAttribdvNV);
- SET_GetVertexAttribfvNV(table, _mesa_GetVertexAttribfvNV);
- SET_GetVertexAttribivNV(table, _mesa_GetVertexAttribivNV);
- SET_GetVertexAttribPointervNV(table, _mesa_GetVertexAttribPointervNV);
- SET_ProgramEnvParameter4dARB(table, save_ProgramEnvParameter4dARB);
- SET_ProgramEnvParameter4dvARB(table, save_ProgramEnvParameter4dvARB);
- SET_ProgramEnvParameter4fARB(table, save_ProgramEnvParameter4fARB);
- SET_ProgramEnvParameter4fvARB(table, save_ProgramEnvParameter4fvARB);
- SET_ProgramLocalParameter4dARB(table, save_ProgramLocalParameter4dARB);
- SET_ProgramLocalParameter4dvARB(table, save_ProgramLocalParameter4dvARB);
- SET_ProgramLocalParameter4fARB(table, save_ProgramLocalParameter4fARB);
- SET_ProgramLocalParameter4fvARB(table, save_ProgramLocalParameter4fvARB);
- SET_GetProgramEnvParameterdvARB(table, _mesa_GetProgramEnvParameterdvARB);
- SET_GetProgramEnvParameterfvARB(table, _mesa_GetProgramEnvParameterfvARB);
- SET_GetProgramLocalParameterdvARB(table,
- _mesa_GetProgramLocalParameterdvARB);
- SET_GetProgramLocalParameterfvARB(table,
- _mesa_GetProgramLocalParameterfvARB);
- SET_GetProgramivARB(table, _mesa_GetProgramivARB);
- SET_GetProgramStringARB(table, _mesa_GetProgramStringARB);
-#endif
-
- /* ARB 28. GL_ARB_vertex_buffer_object */
-#if FEATURE_ARB_vertex_buffer_object
- /* None of the extension's functions get compiled */
- SET_BindBufferARB(table, _mesa_BindBufferARB);
- SET_BufferDataARB(table, _mesa_BufferDataARB);
- SET_BufferSubDataARB(table, _mesa_BufferSubDataARB);
- SET_DeleteBuffersARB(table, _mesa_DeleteBuffersARB);
- SET_GenBuffersARB(table, _mesa_GenBuffersARB);
- SET_GetBufferParameterivARB(table, _mesa_GetBufferParameterivARB);
- SET_GetBufferPointervARB(table, _mesa_GetBufferPointervARB);
- SET_GetBufferSubDataARB(table, _mesa_GetBufferSubDataARB);
- SET_IsBufferARB(table, _mesa_IsBufferARB);
- SET_MapBufferARB(table, _mesa_MapBufferARB);
- SET_UnmapBufferARB(table, _mesa_UnmapBufferARB);
-#endif
-
-#if FEATURE_queryobj
- SET_BeginQueryARB(table, save_BeginQueryARB);
- SET_EndQueryARB(table, save_EndQueryARB);
- SET_GenQueriesARB(table, _mesa_GenQueriesARB);
- SET_DeleteQueriesARB(table, _mesa_DeleteQueriesARB);
- SET_IsQueryARB(table, _mesa_IsQueryARB);
- SET_GetQueryivARB(table, _mesa_GetQueryivARB);
- SET_GetQueryObjectivARB(table, _mesa_GetQueryObjectivARB);
- SET_GetQueryObjectuivARB(table, _mesa_GetQueryObjectuivARB);
-#endif
- SET_DrawBuffersARB(table, save_DrawBuffersARB);
-
-#if FEATURE_EXT_framebuffer_blit
- SET_BlitFramebufferEXT(table, save_BlitFramebufferEXT);
-#endif
-
- /* GL_ARB_shader_objects */
- SET_UseProgramObjectARB(table, save_UseProgramObjectARB);
- SET_Uniform1fARB(table, save_Uniform1fARB);
- SET_Uniform2fARB(table, save_Uniform2fARB);
- SET_Uniform3fARB(table, save_Uniform3fARB);
- SET_Uniform4fARB(table, save_Uniform4fARB);
- SET_Uniform1fvARB(table, save_Uniform1fvARB);
- SET_Uniform2fvARB(table, save_Uniform2fvARB);
- SET_Uniform3fvARB(table, save_Uniform3fvARB);
- SET_Uniform4fvARB(table, save_Uniform4fvARB);
- SET_Uniform1iARB(table, save_Uniform1iARB);
- SET_Uniform2iARB(table, save_Uniform2iARB);
- SET_Uniform3iARB(table, save_Uniform3iARB);
- SET_Uniform4iARB(table, save_Uniform4iARB);
- SET_Uniform1ivARB(table, save_Uniform1ivARB);
- SET_Uniform2ivARB(table, save_Uniform2ivARB);
- SET_Uniform3ivARB(table, save_Uniform3ivARB);
- SET_Uniform4ivARB(table, save_Uniform4ivARB);
- SET_UniformMatrix2fvARB(table, save_UniformMatrix2fvARB);
- SET_UniformMatrix3fvARB(table, save_UniformMatrix3fvARB);
- SET_UniformMatrix4fvARB(table, save_UniformMatrix4fvARB);
- SET_UniformMatrix2x3fv(table, save_UniformMatrix2x3fv);
- SET_UniformMatrix3x2fv(table, save_UniformMatrix3x2fv);
- SET_UniformMatrix2x4fv(table, save_UniformMatrix2x4fv);
- SET_UniformMatrix4x2fv(table, save_UniformMatrix4x2fv);
- SET_UniformMatrix3x4fv(table, save_UniformMatrix3x4fv);
- SET_UniformMatrix4x3fv(table, save_UniformMatrix4x3fv);
-
- /* ARB 30/31/32. GL_ARB_shader_objects, GL_ARB_vertex/fragment_shader */
- SET_BindAttribLocationARB(table, exec_BindAttribLocationARB);
- SET_GetAttribLocationARB(table, exec_GetAttribLocationARB);
- SET_GetUniformLocationARB(table, exec_GetUniformLocationARB);
- /* XXX additional functions need to be implemented here! */
-
- /* 299. GL_EXT_blend_equation_separate */
- SET_BlendEquationSeparateEXT(table, save_BlendEquationSeparateEXT);
-
- /* GL_EXT_gpu_program_parameters */
-#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
- SET_ProgramEnvParameters4fvEXT(table, save_ProgramEnvParameters4fvEXT);
- SET_ProgramLocalParameters4fvEXT(table, save_ProgramLocalParameters4fvEXT);
-#endif
-
- /* ARB 50. GL_ARB_map_buffer_range */
-#if FEATURE_ARB_map_buffer_range
- SET_MapBufferRange(table, _mesa_MapBufferRange); /* no dlist save */
- SET_FlushMappedBufferRange(table, _mesa_FlushMappedBufferRange); /* no dl */
-#endif
-
- /* ARB 59. GL_ARB_copy_buffer */
- SET_CopyBufferSubData(table, _mesa_CopyBufferSubData); /* no dlist save */
-
- /* 352. GL_EXT_transform_feedback */
-#if FEATURE_EXT_transform_feedback
- SET_BeginTransformFeedbackEXT(table, save_BeginTransformFeedback);
- SET_EndTransformFeedbackEXT(table, save_EndTransformFeedback);
-#endif
-
- /* 364. GL_EXT_provoking_vertex */
- SET_ProvokingVertexEXT(table, save_ProvokingVertexEXT);
-
- /* 371. GL_APPLE_object_purgeable */
-#if FEATURE_APPLE_object_purgeable
- SET_ObjectPurgeableAPPLE(table, _mesa_ObjectPurgeableAPPLE);
- SET_ObjectUnpurgeableAPPLE(table, _mesa_ObjectUnpurgeableAPPLE);
-#endif
-
- /* GL_EXT_texture_integer */
- SET_ClearColorIiEXT(table, save_ClearColorIi);
- SET_ClearColorIuiEXT(table, save_ClearColorIui);
- SET_TexParameterIivEXT(table, save_TexParameterIiv);
- SET_TexParameterIuivEXT(table, save_TexParameterIuiv);
- SET_GetTexParameterIivEXT(table, exec_GetTexParameterIiv);
- SET_GetTexParameterIuivEXT(table, exec_GetTexParameterIuiv);
-
- /* 377. GL_EXT_separate_shader_objects */
- SET_UseShaderProgramEXT(table, save_UseShaderProgramEXT);
- SET_ActiveProgramEXT(table, save_ActiveProgramEXT);
-
- /* GL 3.0 */
-#if 0
- SET_ClearBufferiv(table, save_ClearBufferiv);
- SET_ClearBufferuiv(table, save_ClearBufferuiv);
- SET_ClearBufferfv(table, save_ClearBufferfv);
- SET_ClearBufferfi(table, save_ClearBufferfi);
- SET_Uniform1ui(table, save_Uniform1ui);
- SET_Uniform2ui(table, save_Uniform2ui);
- SET_Uniform3ui(table, save_Uniform3ui);
- SET_Uniform4ui(table, save_Uniform4ui);
- SET_Uniform1uiv(table, save_Uniform1uiv);
- SET_Uniform2uiv(table, save_Uniform2uiv);
- SET_Uniform3uiv(table, save_Uniform3uiv);
- SET_Uniform4uiv(table, save_Uniform4uiv);
-#else
- (void) save_ClearBufferiv;
- (void) save_ClearBufferuiv;
- (void) save_ClearBufferfv;
- (void) save_ClearBufferfi;
- (void) save_Uniform1ui;
- (void) save_Uniform2ui;
- (void) save_Uniform3ui;
- (void) save_Uniform4ui;
- (void) save_Uniform1uiv;
- (void) save_Uniform2uiv;
- (void) save_Uniform3uiv;
- (void) save_Uniform4uiv;
-#endif
-
- /* GL_ARB_instanced_arrays */
- SET_VertexAttribDivisorARB(table, save_VertexAttribDivisor);
-
- /* GL_ARB_draw_buffer_blend */
- SET_BlendFunciARB(table, save_BlendFunci);
- SET_BlendFuncSeparateiARB(table, save_BlendFuncSeparatei);
- SET_BlendEquationiARB(table, save_BlendEquationi);
- SET_BlendEquationSeparateiARB(table, save_BlendEquationSeparatei);
-
- return table;
-}
-
-
-
-static const char *
-enum_string(GLenum k)
-{
- return _mesa_lookup_enum_by_nr(k);
-}
-
-
-/**
- * Print the commands in a display list. For debugging only.
- * TODO: many commands aren't handled yet.
- */
-static void GLAPIENTRY
-print_list(struct gl_context *ctx, GLuint list)
-{
- struct gl_display_list *dlist;
- Node *n;
- GLboolean done;
-
- if (!islist(ctx, list)) {
- printf("%u is not a display list ID\n", list);
- return;
- }
-
- dlist = lookup_list(ctx, list);
- if (!dlist)
- return;
-
- n = dlist->Head;
-
- printf("START-LIST %u, address %p\n", list, (void *) n);
-
- done = n ? GL_FALSE : GL_TRUE;
- while (!done) {
- const OpCode opcode = n[0].opcode;
-
- if (is_ext_opcode(opcode)) {
- n += ext_opcode_print(ctx, n);
- }
- else {
- switch (opcode) {
- case OPCODE_ACCUM:
- printf("Accum %s %g\n", enum_string(n[1].e), n[2].f);
- break;
- case OPCODE_BITMAP:
- printf("Bitmap %d %d %g %g %g %g %p\n", n[1].i, n[2].i,
- n[3].f, n[4].f, n[5].f, n[6].f, (void *) n[7].data);
- break;
- case OPCODE_CALL_LIST:
- printf("CallList %d\n", (int) n[1].ui);
- break;
- case OPCODE_CALL_LIST_OFFSET:
- printf("CallList %d + offset %u = %u\n", (int) n[1].ui,
- ctx->List.ListBase, ctx->List.ListBase + n[1].ui);
- break;
- case OPCODE_COLOR_TABLE_PARAMETER_FV:
- printf("ColorTableParameterfv %s %s %f %f %f %f\n",
- enum_string(n[1].e), enum_string(n[2].e),
- n[3].f, n[4].f, n[5].f, n[6].f);
- break;
- case OPCODE_COLOR_TABLE_PARAMETER_IV:
- printf("ColorTableParameteriv %s %s %d %d %d %d\n",
- enum_string(n[1].e), enum_string(n[2].e),
- n[3].i, n[4].i, n[5].i, n[6].i);
- break;
- case OPCODE_DISABLE:
- printf("Disable %s\n", enum_string(n[1].e));
- break;
- case OPCODE_ENABLE:
- printf("Enable %s\n", enum_string(n[1].e));
- break;
- case OPCODE_FRUSTUM:
- printf("Frustum %g %g %g %g %g %g\n",
- n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f);
- break;
- case OPCODE_LINE_STIPPLE:
- printf("LineStipple %d %x\n", n[1].i, (int) n[2].us);
- break;
- case OPCODE_LOAD_IDENTITY:
- printf("LoadIdentity\n");
- break;
- case OPCODE_LOAD_MATRIX:
- printf("LoadMatrix\n");
- printf(" %8f %8f %8f %8f\n",
- n[1].f, n[5].f, n[9].f, n[13].f);
- printf(" %8f %8f %8f %8f\n",
- n[2].f, n[6].f, n[10].f, n[14].f);
- printf(" %8f %8f %8f %8f\n",
- n[3].f, n[7].f, n[11].f, n[15].f);
- printf(" %8f %8f %8f %8f\n",
- n[4].f, n[8].f, n[12].f, n[16].f);
- break;
- case OPCODE_MULT_MATRIX:
- printf("MultMatrix (or Rotate)\n");
- printf(" %8f %8f %8f %8f\n",
- n[1].f, n[5].f, n[9].f, n[13].f);
- printf(" %8f %8f %8f %8f\n",
- n[2].f, n[6].f, n[10].f, n[14].f);
- printf(" %8f %8f %8f %8f\n",
- n[3].f, n[7].f, n[11].f, n[15].f);
- printf(" %8f %8f %8f %8f\n",
- n[4].f, n[8].f, n[12].f, n[16].f);
- break;
- case OPCODE_ORTHO:
- printf("Ortho %g %g %g %g %g %g\n",
- n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f);
- break;
- case OPCODE_POP_ATTRIB:
- printf("PopAttrib\n");
- break;
- case OPCODE_POP_MATRIX:
- printf("PopMatrix\n");
- break;
- case OPCODE_POP_NAME:
- printf("PopName\n");
- break;
- case OPCODE_PUSH_ATTRIB:
- printf("PushAttrib %x\n", n[1].bf);
- break;
- case OPCODE_PUSH_MATRIX:
- printf("PushMatrix\n");
- break;
- case OPCODE_PUSH_NAME:
- printf("PushName %d\n", (int) n[1].ui);
- break;
- case OPCODE_RASTER_POS:
- printf("RasterPos %g %g %g %g\n",
- n[1].f, n[2].f, n[3].f, n[4].f);
- break;
- case OPCODE_ROTATE:
- printf("Rotate %g %g %g %g\n",
- n[1].f, n[2].f, n[3].f, n[4].f);
- break;
- case OPCODE_SCALE:
- printf("Scale %g %g %g\n", n[1].f, n[2].f, n[3].f);
- break;
- case OPCODE_TRANSLATE:
- printf("Translate %g %g %g\n", n[1].f, n[2].f, n[3].f);
- break;
- case OPCODE_BIND_TEXTURE:
- printf("BindTexture %s %d\n",
- _mesa_lookup_enum_by_nr(n[1].ui), n[2].ui);
- break;
- case OPCODE_SHADE_MODEL:
- printf("ShadeModel %s\n", _mesa_lookup_enum_by_nr(n[1].ui));
- break;
- case OPCODE_MAP1:
- printf("Map1 %s %.3f %.3f %d %d\n",
- _mesa_lookup_enum_by_nr(n[1].ui),
- n[2].f, n[3].f, n[4].i, n[5].i);
- break;
- case OPCODE_MAP2:
- printf("Map2 %s %.3f %.3f %.3f %.3f %d %d %d %d\n",
- _mesa_lookup_enum_by_nr(n[1].ui),
- n[2].f, n[3].f, n[4].f, n[5].f,
- n[6].i, n[7].i, n[8].i, n[9].i);
- break;
- case OPCODE_MAPGRID1:
- printf("MapGrid1 %d %.3f %.3f\n", n[1].i, n[2].f, n[3].f);
- break;
- case OPCODE_MAPGRID2:
- printf("MapGrid2 %d %.3f %.3f, %d %.3f %.3f\n",
- n[1].i, n[2].f, n[3].f, n[4].i, n[5].f, n[6].f);
- break;
- case OPCODE_EVALMESH1:
- printf("EvalMesh1 %d %d\n", n[1].i, n[2].i);
- break;
- case OPCODE_EVALMESH2:
- printf("EvalMesh2 %d %d %d %d\n",
- n[1].i, n[2].i, n[3].i, n[4].i);
- break;
-
- case OPCODE_ATTR_1F_NV:
- printf("ATTR_1F_NV attr %d: %f\n", n[1].i, n[2].f);
- break;
- case OPCODE_ATTR_2F_NV:
- printf("ATTR_2F_NV attr %d: %f %f\n",
- n[1].i, n[2].f, n[3].f);
- break;
- case OPCODE_ATTR_3F_NV:
- printf("ATTR_3F_NV attr %d: %f %f %f\n",
- n[1].i, n[2].f, n[3].f, n[4].f);
- break;
- case OPCODE_ATTR_4F_NV:
- printf("ATTR_4F_NV attr %d: %f %f %f %f\n",
- n[1].i, n[2].f, n[3].f, n[4].f, n[5].f);
- break;
- case OPCODE_ATTR_1F_ARB:
- printf("ATTR_1F_ARB attr %d: %f\n", n[1].i, n[2].f);
- break;
- case OPCODE_ATTR_2F_ARB:
- printf("ATTR_2F_ARB attr %d: %f %f\n",
- n[1].i, n[2].f, n[3].f);
- break;
- case OPCODE_ATTR_3F_ARB:
- printf("ATTR_3F_ARB attr %d: %f %f %f\n",
- n[1].i, n[2].f, n[3].f, n[4].f);
- break;
- case OPCODE_ATTR_4F_ARB:
- printf("ATTR_4F_ARB attr %d: %f %f %f %f\n",
- n[1].i, n[2].f, n[3].f, n[4].f, n[5].f);
- break;
-
- case OPCODE_MATERIAL:
- printf("MATERIAL %x %x: %f %f %f %f\n",
- n[1].i, n[2].i, n[3].f, n[4].f, n[5].f, n[6].f);
- break;
- case OPCODE_BEGIN:
- printf("BEGIN %x\n", n[1].i);
- break;
- case OPCODE_END:
- printf("END\n");
- break;
- case OPCODE_RECTF:
- printf("RECTF %f %f %f %f\n", n[1].f, n[2].f, n[3].f,
- n[4].f);
- break;
- case OPCODE_EVAL_C1:
- printf("EVAL_C1 %f\n", n[1].f);
- break;
- case OPCODE_EVAL_C2:
- printf("EVAL_C2 %f %f\n", n[1].f, n[2].f);
- break;
- case OPCODE_EVAL_P1:
- printf("EVAL_P1 %d\n", n[1].i);
- break;
- case OPCODE_EVAL_P2:
- printf("EVAL_P2 %d %d\n", n[1].i, n[2].i);
- break;
-
- case OPCODE_PROVOKING_VERTEX:
- printf("ProvokingVertex %s\n",
- _mesa_lookup_enum_by_nr(n[1].ui));
- break;
-
- /*
- * meta opcodes/commands
- */
- case OPCODE_ERROR:
- printf("Error: %s %s\n",
- enum_string(n[1].e), (const char *) n[2].data);
- break;
- case OPCODE_CONTINUE:
- printf("DISPLAY-LIST-CONTINUE\n");
- n = (Node *) n[1].next;
- break;
- case OPCODE_END_OF_LIST:
- printf("END-LIST %u\n", list);
- done = GL_TRUE;
- break;
- default:
- if (opcode < 0 || opcode > OPCODE_END_OF_LIST) {
- printf
- ("ERROR IN DISPLAY LIST: opcode = %d, address = %p\n",
- opcode, (void *) n);
- return;
- }
- else {
- printf("command %d, %u operands\n", opcode,
- InstSize[opcode]);
- }
- }
- /* increment n to point to next compiled command */
- if (opcode != OPCODE_CONTINUE) {
- n += InstSize[opcode];
- }
- }
- }
-}
-
-
-
-/**
- * Clients may call this function to help debug display list problems.
- * This function is _ONLY_FOR_DEBUGGING_PURPOSES_. It may be removed,
- * changed, or break in the future without notice.
- */
-void
-mesa_print_display_list(GLuint list)
-{
- GET_CURRENT_CONTEXT(ctx);
- print_list(ctx, list);
-}
-
-
-/**********************************************************************/
-/***** Initialization *****/
-/**********************************************************************/
-
-void
-_mesa_save_vtxfmt_init(GLvertexformat * vfmt)
-{
- _MESA_INIT_ARRAYELT_VTXFMT(vfmt, _ae_);
-
- vfmt->Begin = save_Begin;
-
- _MESA_INIT_DLIST_VTXFMT(vfmt, save_);
-
- vfmt->Color3f = save_Color3f;
- vfmt->Color3fv = save_Color3fv;
- vfmt->Color4f = save_Color4f;
- vfmt->Color4fv = save_Color4fv;
- vfmt->EdgeFlag = save_EdgeFlag;
- vfmt->End = save_End;
-
- _MESA_INIT_EVAL_VTXFMT(vfmt, save_);
-
- vfmt->FogCoordfEXT = save_FogCoordfEXT;
- vfmt->FogCoordfvEXT = save_FogCoordfvEXT;
- vfmt->Indexf = save_Indexf;
- vfmt->Indexfv = save_Indexfv;
- vfmt->Materialfv = save_Materialfv;
- vfmt->MultiTexCoord1fARB = save_MultiTexCoord1f;
- vfmt->MultiTexCoord1fvARB = save_MultiTexCoord1fv;
- vfmt->MultiTexCoord2fARB = save_MultiTexCoord2f;
- vfmt->MultiTexCoord2fvARB = save_MultiTexCoord2fv;
- vfmt->MultiTexCoord3fARB = save_MultiTexCoord3f;
- vfmt->MultiTexCoord3fvARB = save_MultiTexCoord3fv;
- vfmt->MultiTexCoord4fARB = save_MultiTexCoord4f;
- vfmt->MultiTexCoord4fvARB = save_MultiTexCoord4fv;
- vfmt->Normal3f = save_Normal3f;
- vfmt->Normal3fv = save_Normal3fv;
- vfmt->SecondaryColor3fEXT = save_SecondaryColor3fEXT;
- vfmt->SecondaryColor3fvEXT = save_SecondaryColor3fvEXT;
- vfmt->TexCoord1f = save_TexCoord1f;
- vfmt->TexCoord1fv = save_TexCoord1fv;
- vfmt->TexCoord2f = save_TexCoord2f;
- vfmt->TexCoord2fv = save_TexCoord2fv;
- vfmt->TexCoord3f = save_TexCoord3f;
- vfmt->TexCoord3fv = save_TexCoord3fv;
- vfmt->TexCoord4f = save_TexCoord4f;
- vfmt->TexCoord4fv = save_TexCoord4fv;
- vfmt->Vertex2f = save_Vertex2f;
- vfmt->Vertex2fv = save_Vertex2fv;
- vfmt->Vertex3f = save_Vertex3f;
- vfmt->Vertex3fv = save_Vertex3fv;
- vfmt->Vertex4f = save_Vertex4f;
- vfmt->Vertex4fv = save_Vertex4fv;
- vfmt->VertexAttrib1fNV = save_VertexAttrib1fNV;
- vfmt->VertexAttrib1fvNV = save_VertexAttrib1fvNV;
- vfmt->VertexAttrib2fNV = save_VertexAttrib2fNV;
- vfmt->VertexAttrib2fvNV = save_VertexAttrib2fvNV;
- vfmt->VertexAttrib3fNV = save_VertexAttrib3fNV;
- vfmt->VertexAttrib3fvNV = save_VertexAttrib3fvNV;
- vfmt->VertexAttrib4fNV = save_VertexAttrib4fNV;
- vfmt->VertexAttrib4fvNV = save_VertexAttrib4fvNV;
- vfmt->VertexAttrib1fARB = save_VertexAttrib1fARB;
- vfmt->VertexAttrib1fvARB = save_VertexAttrib1fvARB;
- vfmt->VertexAttrib2fARB = save_VertexAttrib2fARB;
- vfmt->VertexAttrib2fvARB = save_VertexAttrib2fvARB;
- vfmt->VertexAttrib3fARB = save_VertexAttrib3fARB;
- vfmt->VertexAttrib3fvARB = save_VertexAttrib3fvARB;
- vfmt->VertexAttrib4fARB = save_VertexAttrib4fARB;
- vfmt->VertexAttrib4fvARB = save_VertexAttrib4fvARB;
-
- vfmt->Rectf = save_Rectf;
-
- /* The driver is required to implement these as
- * 1) They can probably do a better job.
- * 2) A lot of new mechanisms would have to be added to this module
- * to support it. That code would probably never get used,
- * because of (1).
- */
-#if 0
- vfmt->DrawArrays = 0;
- vfmt->DrawElements = 0;
- vfmt->DrawRangeElements = 0;
- vfmt->MultiDrawElemementsEXT = 0;
- vfmt->DrawElementsBaseVertex = 0;
- vfmt->DrawRangeElementsBaseVertex = 0;
- vfmt->MultiDrawElemementsBaseVertex = 0;
-#endif
-}
-
-
-void
-_mesa_install_dlist_vtxfmt(struct _glapi_table *disp,
- const GLvertexformat *vfmt)
-{
- SET_CallList(disp, vfmt->CallList);
- SET_CallLists(disp, vfmt->CallLists);
-}
-
-
-void _mesa_init_dlist_dispatch(struct _glapi_table *disp)
-{
- SET_CallList(disp, _mesa_CallList);
- SET_CallLists(disp, _mesa_CallLists);
-
- SET_DeleteLists(disp, _mesa_DeleteLists);
- SET_EndList(disp, _mesa_EndList);
- SET_GenLists(disp, _mesa_GenLists);
- SET_IsList(disp, _mesa_IsList);
- SET_ListBase(disp, _mesa_ListBase);
- SET_NewList(disp, _mesa_NewList);
-}
-
-
-#endif /* FEATURE_dlist */
-
-
-/**
- * Initialize display list state for given context.
- */
-void
-_mesa_init_display_list(struct gl_context *ctx)
-{
- static GLboolean tableInitialized = GL_FALSE;
-
- /* zero-out the instruction size table, just once */
- if (!tableInitialized) {
- memset(InstSize, 0, sizeof(InstSize));
- tableInitialized = GL_TRUE;
- }
-
- /* extension info */
- ctx->ListExt = CALLOC_STRUCT(gl_list_extensions);
-
- /* Display list */
- ctx->ListState.CallDepth = 0;
- ctx->ExecuteFlag = GL_TRUE;
- ctx->CompileFlag = GL_FALSE;
- ctx->ListState.CurrentBlock = NULL;
- ctx->ListState.CurrentPos = 0;
-
- /* Display List group */
- ctx->List.ListBase = 0;
-
-#if FEATURE_dlist
- _mesa_save_vtxfmt_init(&ctx->ListState.ListVtxfmt);
-#endif
-}
-
-
-void
-_mesa_free_display_list_data(struct gl_context *ctx)
-{
- free(ctx->ListExt);
- ctx->ListExt = NULL;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file dlist.c
+ * Display lists management functions.
+ */
+
+#include "glheader.h"
+#include "imports.h"
+#include "api_arrayelt.h"
+#include "api_exec.h"
+#include "api_loopback.h"
+#if FEATURE_ATI_fragment_shader
+#include "atifragshader.h"
+#endif
+#include "config.h"
+#include "mfeatures.h"
+#if FEATURE_ARB_vertex_buffer_object
+#include "bufferobj.h"
+#endif
+#include "arrayobj.h"
+#include "context.h"
+#include "dlist.h"
+#include "enums.h"
+#include "eval.h"
+#include "framebuffer.h"
+#include "glapi/glapi.h"
+#include "hash.h"
+#include "image.h"
+#include "light.h"
+#include "macros.h"
+#include "pack.h"
+#include "pbo.h"
+#include "queryobj.h"
+#include "teximage.h"
+#include "mtypes.h"
+#include "varray.h"
+#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+#include "arbprogram.h"
+#endif
+#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
+#include "nvprogram.h"
+#endif
+
+#include "math/m_matrix.h"
+
+#include "main/dispatch.h"
+
+
+
+/**
+ * Other parts of Mesa (such as the VBO module) can plug into the display
+ * list system. This structure describes new display list instructions.
+ */
+struct gl_list_instruction
+{
+ GLuint Size;
+ void (*Execute)( struct gl_context *ctx, void *data );
+ void (*Destroy)( struct gl_context *ctx, void *data );
+ void (*Print)( struct gl_context *ctx, void *data );
+};
+
+
+#define MAX_DLIST_EXT_OPCODES 16
+
+/**
+ * Used by device drivers to hook new commands into display lists.
+ */
+struct gl_list_extensions
+{
+ struct gl_list_instruction Opcode[MAX_DLIST_EXT_OPCODES];
+ GLuint NumOpcodes;
+};
+
+
+
+/**
+ * Flush vertices.
+ *
+ * \param ctx GL context.
+ *
+ * Checks if dd_function_table::SaveNeedFlush is marked to flush
+ * stored (save) vertices, and calls
+ * dd_function_table::SaveFlushVertices if so.
+ */
+#define SAVE_FLUSH_VERTICES(ctx) \
+do { \
+ if (ctx->Driver.SaveNeedFlush) \
+ ctx->Driver.SaveFlushVertices(ctx); \
+} while (0)
+
+
+/**
+ * Macro to assert that the API call was made outside the
+ * glBegin()/glEnd() pair, with return value.
+ *
+ * \param ctx GL context.
+ * \param retval value to return value in case the assertion fails.
+ */
+#define ASSERT_OUTSIDE_SAVE_BEGIN_END_WITH_RETVAL(ctx, retval) \
+do { \
+ if (ctx->Driver.CurrentSavePrimitive <= GL_POLYGON || \
+ ctx->Driver.CurrentSavePrimitive == PRIM_INSIDE_UNKNOWN_PRIM) { \
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
+ return retval; \
+ } \
+} while (0)
+
+/**
+ * Macro to assert that the API call was made outside the
+ * glBegin()/glEnd() pair.
+ *
+ * \param ctx GL context.
+ */
+#define ASSERT_OUTSIDE_SAVE_BEGIN_END(ctx) \
+do { \
+ if (ctx->Driver.CurrentSavePrimitive <= GL_POLYGON || \
+ ctx->Driver.CurrentSavePrimitive == PRIM_INSIDE_UNKNOWN_PRIM) { \
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
+ return; \
+ } \
+} while (0)
+
+/**
+ * Macro to assert that the API call was made outside the
+ * glBegin()/glEnd() pair and flush the vertices.
+ *
+ * \param ctx GL context.
+ */
+#define ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx) \
+do { \
+ ASSERT_OUTSIDE_SAVE_BEGIN_END(ctx); \
+ SAVE_FLUSH_VERTICES(ctx); \
+} while (0)
+
+/**
+ * Macro to assert that the API call was made outside the
+ * glBegin()/glEnd() pair and flush the vertices, with return value.
+ *
+ * \param ctx GL context.
+ * \param retval value to return value in case the assertion fails.
+ */
+#define ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval)\
+do { \
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_WITH_RETVAL(ctx, retval); \
+ SAVE_FLUSH_VERTICES(ctx); \
+} while (0)
+
+
+
+/**
+ * Display list opcodes.
+ *
+ * The fact that these identifiers are assigned consecutive
+ * integer values starting at 0 is very important, see InstSize array usage)
+ */
+typedef enum
+{
+ OPCODE_INVALID = -1, /* Force signed enum */
+ OPCODE_ACCUM,
+ OPCODE_ALPHA_FUNC,
+ OPCODE_BIND_TEXTURE,
+ OPCODE_BITMAP,
+ OPCODE_BLEND_COLOR,
+ OPCODE_BLEND_EQUATION,
+ OPCODE_BLEND_EQUATION_SEPARATE,
+ OPCODE_BLEND_FUNC_SEPARATE,
+
+ OPCODE_BLEND_EQUATION_I,
+ OPCODE_BLEND_EQUATION_SEPARATE_I,
+ OPCODE_BLEND_FUNC_I,
+ OPCODE_BLEND_FUNC_SEPARATE_I,
+
+ OPCODE_CALL_LIST,
+ OPCODE_CALL_LIST_OFFSET,
+ OPCODE_CLEAR,
+ OPCODE_CLEAR_ACCUM,
+ OPCODE_CLEAR_COLOR,
+ OPCODE_CLEAR_DEPTH,
+ OPCODE_CLEAR_INDEX,
+ OPCODE_CLEAR_STENCIL,
+ OPCODE_CLEAR_BUFFER_IV,
+ OPCODE_CLEAR_BUFFER_UIV,
+ OPCODE_CLEAR_BUFFER_FV,
+ OPCODE_CLEAR_BUFFER_FI,
+ OPCODE_CLIP_PLANE,
+ OPCODE_COLOR_MASK,
+ OPCODE_COLOR_MASK_INDEXED,
+ OPCODE_COLOR_MATERIAL,
+ OPCODE_COLOR_TABLE,
+ OPCODE_COLOR_TABLE_PARAMETER_FV,
+ OPCODE_COLOR_TABLE_PARAMETER_IV,
+ OPCODE_COLOR_SUB_TABLE,
+ OPCODE_CONVOLUTION_FILTER_1D,
+ OPCODE_CONVOLUTION_FILTER_2D,
+ OPCODE_CONVOLUTION_PARAMETER_I,
+ OPCODE_CONVOLUTION_PARAMETER_IV,
+ OPCODE_CONVOLUTION_PARAMETER_F,
+ OPCODE_CONVOLUTION_PARAMETER_FV,
+ OPCODE_COPY_COLOR_SUB_TABLE,
+ OPCODE_COPY_COLOR_TABLE,
+ OPCODE_COPY_PIXELS,
+ OPCODE_COPY_TEX_IMAGE1D,
+ OPCODE_COPY_TEX_IMAGE2D,
+ OPCODE_COPY_TEX_SUB_IMAGE1D,
+ OPCODE_COPY_TEX_SUB_IMAGE2D,
+ OPCODE_COPY_TEX_SUB_IMAGE3D,
+ OPCODE_CULL_FACE,
+ OPCODE_DEPTH_FUNC,
+ OPCODE_DEPTH_MASK,
+ OPCODE_DEPTH_RANGE,
+ OPCODE_DISABLE,
+ OPCODE_DISABLE_INDEXED,
+ OPCODE_DRAW_BUFFER,
+ OPCODE_DRAW_PIXELS,
+ OPCODE_ENABLE,
+ OPCODE_ENABLE_INDEXED,
+ OPCODE_EVALMESH1,
+ OPCODE_EVALMESH2,
+ OPCODE_FOG,
+ OPCODE_FRONT_FACE,
+ OPCODE_FRUSTUM,
+ OPCODE_HINT,
+ OPCODE_HISTOGRAM,
+ OPCODE_INDEX_MASK,
+ OPCODE_INIT_NAMES,
+ OPCODE_LIGHT,
+ OPCODE_LIGHT_MODEL,
+ OPCODE_LINE_STIPPLE,
+ OPCODE_LINE_WIDTH,
+ OPCODE_LIST_BASE,
+ OPCODE_LOAD_IDENTITY,
+ OPCODE_LOAD_MATRIX,
+ OPCODE_LOAD_NAME,
+ OPCODE_LOGIC_OP,
+ OPCODE_MAP1,
+ OPCODE_MAP2,
+ OPCODE_MAPGRID1,
+ OPCODE_MAPGRID2,
+ OPCODE_MATRIX_MODE,
+ OPCODE_MIN_MAX,
+ OPCODE_MULT_MATRIX,
+ OPCODE_ORTHO,
+ OPCODE_PASSTHROUGH,
+ OPCODE_PIXEL_MAP,
+ OPCODE_PIXEL_TRANSFER,
+ OPCODE_PIXEL_ZOOM,
+ OPCODE_POINT_SIZE,
+ OPCODE_POINT_PARAMETERS,
+ OPCODE_POLYGON_MODE,
+ OPCODE_POLYGON_STIPPLE,
+ OPCODE_POLYGON_OFFSET,
+ OPCODE_POP_ATTRIB,
+ OPCODE_POP_MATRIX,
+ OPCODE_POP_NAME,
+ OPCODE_PRIORITIZE_TEXTURE,
+ OPCODE_PUSH_ATTRIB,
+ OPCODE_PUSH_MATRIX,
+ OPCODE_PUSH_NAME,
+ OPCODE_RASTER_POS,
+ OPCODE_READ_BUFFER,
+ OPCODE_RESET_HISTOGRAM,
+ OPCODE_RESET_MIN_MAX,
+ OPCODE_ROTATE,
+ OPCODE_SCALE,
+ OPCODE_SCISSOR,
+ OPCODE_SELECT_TEXTURE_SGIS,
+ OPCODE_SELECT_TEXTURE_COORD_SET,
+ OPCODE_SHADE_MODEL,
+ OPCODE_STENCIL_FUNC,
+ OPCODE_STENCIL_MASK,
+ OPCODE_STENCIL_OP,
+ OPCODE_TEXENV,
+ OPCODE_TEXGEN,
+ OPCODE_TEXPARAMETER,
+ OPCODE_TEX_IMAGE1D,
+ OPCODE_TEX_IMAGE2D,
+ OPCODE_TEX_IMAGE3D,
+ OPCODE_TEX_SUB_IMAGE1D,
+ OPCODE_TEX_SUB_IMAGE2D,
+ OPCODE_TEX_SUB_IMAGE3D,
+ OPCODE_TRANSLATE,
+ OPCODE_VIEWPORT,
+ OPCODE_WINDOW_POS,
+ /* GL_ARB_multitexture */
+ OPCODE_ACTIVE_TEXTURE,
+ /* GL_ARB_texture_compression */
+ OPCODE_COMPRESSED_TEX_IMAGE_1D,
+ OPCODE_COMPRESSED_TEX_IMAGE_2D,
+ OPCODE_COMPRESSED_TEX_IMAGE_3D,
+ OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D,
+ OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D,
+ OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D,
+ /* GL_ARB_multisample */
+ OPCODE_SAMPLE_COVERAGE,
+ /* GL_ARB_window_pos */
+ OPCODE_WINDOW_POS_ARB,
+ /* GL_NV_vertex_program */
+ OPCODE_BIND_PROGRAM_NV,
+ OPCODE_EXECUTE_PROGRAM_NV,
+ OPCODE_REQUEST_RESIDENT_PROGRAMS_NV,
+ OPCODE_LOAD_PROGRAM_NV,
+ OPCODE_TRACK_MATRIX_NV,
+ /* GL_NV_fragment_program */
+ OPCODE_PROGRAM_LOCAL_PARAMETER_ARB,
+ OPCODE_PROGRAM_NAMED_PARAMETER_NV,
+ /* GL_EXT_stencil_two_side */
+ OPCODE_ACTIVE_STENCIL_FACE_EXT,
+ /* GL_EXT_depth_bounds_test */
+ OPCODE_DEPTH_BOUNDS_EXT,
+ /* GL_ARB_vertex/fragment_program */
+ OPCODE_PROGRAM_STRING_ARB,
+ OPCODE_PROGRAM_ENV_PARAMETER_ARB,
+ /* GL_ARB_occlusion_query */
+ OPCODE_BEGIN_QUERY_ARB,
+ OPCODE_END_QUERY_ARB,
+ /* GL_ARB_draw_buffers */
+ OPCODE_DRAW_BUFFERS_ARB,
+ /* GL_ATI_fragment_shader */
+ OPCODE_TEX_BUMP_PARAMETER_ATI,
+ /* GL_ATI_fragment_shader */
+ OPCODE_BIND_FRAGMENT_SHADER_ATI,
+ OPCODE_SET_FRAGMENT_SHADER_CONSTANTS_ATI,
+ /* OpenGL 2.0 */
+ OPCODE_STENCIL_FUNC_SEPARATE,
+ OPCODE_STENCIL_OP_SEPARATE,
+ OPCODE_STENCIL_MASK_SEPARATE,
+
+ /* GL_ARB_shader_objects */
+ OPCODE_USE_PROGRAM,
+ OPCODE_UNIFORM_1F,
+ OPCODE_UNIFORM_2F,
+ OPCODE_UNIFORM_3F,
+ OPCODE_UNIFORM_4F,
+ OPCODE_UNIFORM_1FV,
+ OPCODE_UNIFORM_2FV,
+ OPCODE_UNIFORM_3FV,
+ OPCODE_UNIFORM_4FV,
+ OPCODE_UNIFORM_1I,
+ OPCODE_UNIFORM_2I,
+ OPCODE_UNIFORM_3I,
+ OPCODE_UNIFORM_4I,
+ OPCODE_UNIFORM_1IV,
+ OPCODE_UNIFORM_2IV,
+ OPCODE_UNIFORM_3IV,
+ OPCODE_UNIFORM_4IV,
+ OPCODE_UNIFORM_MATRIX22,
+ OPCODE_UNIFORM_MATRIX33,
+ OPCODE_UNIFORM_MATRIX44,
+ OPCODE_UNIFORM_MATRIX23,
+ OPCODE_UNIFORM_MATRIX32,
+ OPCODE_UNIFORM_MATRIX24,
+ OPCODE_UNIFORM_MATRIX42,
+ OPCODE_UNIFORM_MATRIX34,
+ OPCODE_UNIFORM_MATRIX43,
+
+ /* OpenGL 3.0 */
+ OPCODE_UNIFORM_1UI,
+ OPCODE_UNIFORM_2UI,
+ OPCODE_UNIFORM_3UI,
+ OPCODE_UNIFORM_4UI,
+ OPCODE_UNIFORM_1UIV,
+ OPCODE_UNIFORM_2UIV,
+ OPCODE_UNIFORM_3UIV,
+ OPCODE_UNIFORM_4UIV,
+
+ /* GL_EXT_framebuffer_blit */
+ OPCODE_BLIT_FRAMEBUFFER,
+
+ /* Vertex attributes -- fallback for when optimized display
+ * list build isn't active.
+ */
+ OPCODE_ATTR_1F_NV,
+ OPCODE_ATTR_2F_NV,
+ OPCODE_ATTR_3F_NV,
+ OPCODE_ATTR_4F_NV,
+ OPCODE_ATTR_1F_ARB,
+ OPCODE_ATTR_2F_ARB,
+ OPCODE_ATTR_3F_ARB,
+ OPCODE_ATTR_4F_ARB,
+ OPCODE_MATERIAL,
+ OPCODE_BEGIN,
+ OPCODE_END,
+ OPCODE_RECTF,
+ OPCODE_EVAL_C1,
+ OPCODE_EVAL_C2,
+ OPCODE_EVAL_P1,
+ OPCODE_EVAL_P2,
+
+ /* GL_EXT_provoking_vertex */
+ OPCODE_PROVOKING_VERTEX,
+
+ /* GL_EXT_transform_feedback */
+ OPCODE_BEGIN_TRANSFORM_FEEDBACK,
+ OPCODE_END_TRANSFORM_FEEDBACK,
+
+ /* GL_EXT_texture_integer */
+ OPCODE_CLEARCOLOR_I,
+ OPCODE_CLEARCOLOR_UI,
+ OPCODE_TEXPARAMETER_I,
+ OPCODE_TEXPARAMETER_UI,
+
+ /* GL_EXT_separate_shader_objects */
+ OPCODE_ACTIVE_PROGRAM_EXT,
+ OPCODE_USE_SHADER_PROGRAM_EXT,
+
+ /* GL_ARB_instanced_arrays */
+ OPCODE_VERTEX_ATTRIB_DIVISOR,
+
+ /* The following three are meta instructions */
+ OPCODE_ERROR, /* raise compiled-in error */
+ OPCODE_CONTINUE,
+ OPCODE_END_OF_LIST,
+ OPCODE_EXT_0
+} OpCode;
+
+
+
+/**
+ * Display list node.
+ *
+ * Display list instructions are stored as sequences of "nodes". Nodes
+ * are allocated in blocks. Each block has BLOCK_SIZE nodes. Blocks
+ * are linked together with a pointer.
+ *
+ * Each instruction in the display list is stored as a sequence of
+ * contiguous nodes in memory.
+ * Each node is the union of a variety of data types.
+ */
+union gl_dlist_node
+{
+ OpCode opcode;
+ GLboolean b;
+ GLbitfield bf;
+ GLubyte ub;
+ GLshort s;
+ GLushort us;
+ GLint i;
+ GLuint ui;
+ GLenum e;
+ GLfloat f;
+ GLvoid *data;
+ void *next; /* If prev node's opcode==OPCODE_CONTINUE */
+};
+
+
+typedef union gl_dlist_node Node;
+
+
+/**
+ * How many nodes to allocate at a time.
+ *
+ * \note Reduced now that we hold vertices etc. elsewhere.
+ */
+#define BLOCK_SIZE 256
+
+
+
+/**
+ * Number of nodes of storage needed for each instruction.
+ * Sizes for dynamically allocated opcodes are stored in the context struct.
+ */
+static GLuint InstSize[OPCODE_END_OF_LIST + 1];
+
+
+#if FEATURE_dlist
+
+
+void mesa_print_display_list(GLuint list);
+
+
+/**********************************************************************/
+/***** Private *****/
+/**********************************************************************/
+
+
+/**
+ * Make an empty display list. This is used by glGenLists() to
+ * reserve display list IDs.
+ */
+static struct gl_display_list *
+make_list(GLuint name, GLuint count)
+{
+ struct gl_display_list *dlist = CALLOC_STRUCT(gl_display_list);
+ dlist->Name = name;
+ dlist->Head = (Node *) malloc(sizeof(Node) * count);
+ dlist->Head[0].opcode = OPCODE_END_OF_LIST;
+ return dlist;
+}
+
+
+/**
+ * Lookup function to just encapsulate casting.
+ */
+static INLINE struct gl_display_list *
+lookup_list(struct gl_context *ctx, GLuint list)
+{
+ return (struct gl_display_list *)
+ _mesa_HashLookup(ctx->Shared->DisplayList, list);
+}
+
+
+/** Is the given opcode an extension code? */
+static INLINE GLboolean
+is_ext_opcode(OpCode opcode)
+{
+ return (opcode >= OPCODE_EXT_0);
+}
+
+
+/** Destroy an extended opcode instruction */
+static GLint
+ext_opcode_destroy(struct gl_context *ctx, Node *node)
+{
+ const GLint i = node[0].opcode - OPCODE_EXT_0;
+ GLint step;
+ ctx->ListExt->Opcode[i].Destroy(ctx, &node[1]);
+ step = ctx->ListExt->Opcode[i].Size;
+ return step;
+}
+
+
+/** Execute an extended opcode instruction */
+static GLint
+ext_opcode_execute(struct gl_context *ctx, Node *node)
+{
+ const GLint i = node[0].opcode - OPCODE_EXT_0;
+ GLint step;
+ ctx->ListExt->Opcode[i].Execute(ctx, &node[1]);
+ step = ctx->ListExt->Opcode[i].Size;
+ return step;
+}
+
+
+/** Print an extended opcode instruction */
+static GLint
+ext_opcode_print(struct gl_context *ctx, Node *node)
+{
+ const GLint i = node[0].opcode - OPCODE_EXT_0;
+ GLint step;
+ ctx->ListExt->Opcode[i].Print(ctx, &node[1]);
+ step = ctx->ListExt->Opcode[i].Size;
+ return step;
+}
+
+
+/**
+ * Delete the named display list, but don't remove from hash table.
+ * \param dlist - display list pointer
+ */
+void
+_mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist)
+{
+ Node *n, *block;
+ GLboolean done;
+
+ n = block = dlist->Head;
+
+ done = block ? GL_FALSE : GL_TRUE;
+ while (!done) {
+ const OpCode opcode = n[0].opcode;
+
+ /* check for extension opcodes first */
+ if (is_ext_opcode(opcode)) {
+ n += ext_opcode_destroy(ctx, n);
+ }
+ else {
+ switch (opcode) {
+ /* for some commands, we need to free malloc'd memory */
+ case OPCODE_MAP1:
+ free(n[6].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_MAP2:
+ free(n[10].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_DRAW_PIXELS:
+ free(n[5].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_BITMAP:
+ free(n[7].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_COLOR_TABLE:
+ free(n[6].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_COLOR_SUB_TABLE:
+ free(n[6].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_CONVOLUTION_FILTER_1D:
+ free(n[6].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_CONVOLUTION_FILTER_2D:
+ free(n[7].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_POLYGON_STIPPLE:
+ free(n[1].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_TEX_IMAGE1D:
+ free(n[8].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_TEX_IMAGE2D:
+ free(n[9].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_TEX_IMAGE3D:
+ free(n[10].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_TEX_SUB_IMAGE1D:
+ free(n[7].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_TEX_SUB_IMAGE2D:
+ free(n[9].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_TEX_SUB_IMAGE3D:
+ free(n[11].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_COMPRESSED_TEX_IMAGE_1D:
+ free(n[7].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_COMPRESSED_TEX_IMAGE_2D:
+ free(n[8].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_COMPRESSED_TEX_IMAGE_3D:
+ free(n[9].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D:
+ free(n[7].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D:
+ free(n[9].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D:
+ free(n[11].data);
+ n += InstSize[n[0].opcode];
+ break;
+#if FEATURE_NV_vertex_program
+ case OPCODE_LOAD_PROGRAM_NV:
+ free(n[4].data); /* program string */
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_REQUEST_RESIDENT_PROGRAMS_NV:
+ free(n[2].data); /* array of program ids */
+ n += InstSize[n[0].opcode];
+ break;
+#endif
+#if FEATURE_NV_fragment_program
+ case OPCODE_PROGRAM_NAMED_PARAMETER_NV:
+ free(n[3].data); /* parameter name */
+ n += InstSize[n[0].opcode];
+ break;
+#endif
+#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+ case OPCODE_PROGRAM_STRING_ARB:
+ free(n[4].data); /* program string */
+ n += InstSize[n[0].opcode];
+ break;
+#endif
+ case OPCODE_UNIFORM_1FV:
+ case OPCODE_UNIFORM_2FV:
+ case OPCODE_UNIFORM_3FV:
+ case OPCODE_UNIFORM_4FV:
+ case OPCODE_UNIFORM_1IV:
+ case OPCODE_UNIFORM_2IV:
+ case OPCODE_UNIFORM_3IV:
+ case OPCODE_UNIFORM_4IV:
+ case OPCODE_UNIFORM_1UIV:
+ case OPCODE_UNIFORM_2UIV:
+ case OPCODE_UNIFORM_3UIV:
+ case OPCODE_UNIFORM_4UIV:
+ free(n[3].data);
+ n += InstSize[n[0].opcode];
+ break;
+ case OPCODE_UNIFORM_MATRIX22:
+ case OPCODE_UNIFORM_MATRIX33:
+ case OPCODE_UNIFORM_MATRIX44:
+ case OPCODE_UNIFORM_MATRIX24:
+ case OPCODE_UNIFORM_MATRIX42:
+ case OPCODE_UNIFORM_MATRIX23:
+ case OPCODE_UNIFORM_MATRIX32:
+ case OPCODE_UNIFORM_MATRIX34:
+ case OPCODE_UNIFORM_MATRIX43:
+ free(n[4].data);
+ n += InstSize[n[0].opcode];
+ break;
+
+ case OPCODE_CONTINUE:
+ n = (Node *) n[1].next;
+ free(block);
+ block = n;
+ break;
+ case OPCODE_END_OF_LIST:
+ free(block);
+ done = GL_TRUE;
+ break;
+ default:
+ /* Most frequent case */
+ n += InstSize[n[0].opcode];
+ break;
+ }
+ }
+ }
+
+ free(dlist);
+}
+
+
+/**
+ * Destroy a display list and remove from hash table.
+ * \param list - display list number
+ */
+static void
+destroy_list(struct gl_context *ctx, GLuint list)
+{
+ struct gl_display_list *dlist;
+
+ if (list == 0)
+ return;
+
+ dlist = lookup_list(ctx, list);
+ if (!dlist)
+ return;
+
+ _mesa_delete_list(ctx, dlist);
+ _mesa_HashRemove(ctx->Shared->DisplayList, list);
+}
+
+
+/*
+ * Translate the nth element of list from <type> to GLint.
+ */
+static GLint
+translate_id(GLsizei n, GLenum type, const GLvoid * list)
+{
+ GLbyte *bptr;
+ GLubyte *ubptr;
+ GLshort *sptr;
+ GLushort *usptr;
+ GLint *iptr;
+ GLuint *uiptr;
+ GLfloat *fptr;
+
+ switch (type) {
+ case GL_BYTE:
+ bptr = (GLbyte *) list;
+ return (GLint) bptr[n];
+ case GL_UNSIGNED_BYTE:
+ ubptr = (GLubyte *) list;
+ return (GLint) ubptr[n];
+ case GL_SHORT:
+ sptr = (GLshort *) list;
+ return (GLint) sptr[n];
+ case GL_UNSIGNED_SHORT:
+ usptr = (GLushort *) list;
+ return (GLint) usptr[n];
+ case GL_INT:
+ iptr = (GLint *) list;
+ return iptr[n];
+ case GL_UNSIGNED_INT:
+ uiptr = (GLuint *) list;
+ return (GLint) uiptr[n];
+ case GL_FLOAT:
+ fptr = (GLfloat *) list;
+ return (GLint) FLOORF(fptr[n]);
+ case GL_2_BYTES:
+ ubptr = ((GLubyte *) list) + 2 * n;
+ return (GLint) ubptr[0] * 256
+ + (GLint) ubptr[1];
+ case GL_3_BYTES:
+ ubptr = ((GLubyte *) list) + 3 * n;
+ return (GLint) ubptr[0] * 65536
+ + (GLint) ubptr[1] * 256
+ + (GLint) ubptr[2];
+ case GL_4_BYTES:
+ ubptr = ((GLubyte *) list) + 4 * n;
+ return (GLint) ubptr[0] * 16777216
+ + (GLint) ubptr[1] * 65536
+ + (GLint) ubptr[2] * 256
+ + (GLint) ubptr[3];
+ default:
+ return 0;
+ }
+}
+
+
+
+
+/**********************************************************************/
+/***** Public *****/
+/**********************************************************************/
+
+/**
+ * Wrapper for _mesa_unpack_image() that handles pixel buffer objects.
+ * If we run out of memory, GL_OUT_OF_MEMORY will be recorded.
+ */
+static GLvoid *
+unpack_image(struct gl_context *ctx, GLuint dimensions,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, const GLvoid * pixels,
+ const struct gl_pixelstore_attrib *unpack)
+{
+ if (!_mesa_is_bufferobj(unpack->BufferObj)) {
+ /* no PBO */
+ GLvoid *image = _mesa_unpack_image(dimensions, width, height, depth,
+ format, type, pixels, unpack);
+ if (pixels && !image) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "display list construction");
+ }
+ return image;
+ }
+ else if (_mesa_validate_pbo_access(dimensions, unpack, width, height, depth,
+ format, type, pixels)) {
+ const GLubyte *map, *src;
+ GLvoid *image;
+
+ map = (GLubyte *)
+ ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+ GL_READ_ONLY_ARB, unpack->BufferObj);
+ if (!map) {
+ /* unable to map src buffer! */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "unable to map PBO");
+ return NULL;
+ }
+
+ src = ADD_POINTERS(map, pixels);
+ image = _mesa_unpack_image(dimensions, width, height, depth,
+ format, type, src, unpack);
+
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+ unpack->BufferObj);
+
+ if (!image) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "display list construction");
+ }
+ return image;
+ }
+ /* bad access! */
+ return NULL;
+}
+
+
+/**
+ * Allocate space for a display list instruction (opcode + payload space).
+ * \param opcode the instruction opcode (OPCODE_* value)
+ * \param bytes instruction payload size (not counting opcode)
+ * \return pointer to allocated memory (the opcode space)
+ */
+static Node *
+dlist_alloc(struct gl_context *ctx, OpCode opcode, GLuint bytes)
+{
+ const GLuint numNodes = 1 + (bytes + sizeof(Node) - 1) / sizeof(Node);
+ Node *n;
+
+ if (opcode < (GLuint) OPCODE_EXT_0) {
+ if (InstSize[opcode] == 0) {
+ /* save instruction size now */
+ InstSize[opcode] = numNodes;
+ }
+ else {
+ /* make sure instruction size agrees */
+ ASSERT(numNodes == InstSize[opcode]);
+ }
+ }
+
+ if (ctx->ListState.CurrentPos + numNodes + 2 > BLOCK_SIZE) {
+ /* This block is full. Allocate a new block and chain to it */
+ Node *newblock;
+ n = ctx->ListState.CurrentBlock + ctx->ListState.CurrentPos;
+ n[0].opcode = OPCODE_CONTINUE;
+ newblock = (Node *) malloc(sizeof(Node) * BLOCK_SIZE);
+ if (!newblock) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "Building display list");
+ return NULL;
+ }
+ n[1].next = (Node *) newblock;
+ ctx->ListState.CurrentBlock = newblock;
+ ctx->ListState.CurrentPos = 0;
+ }
+
+ n = ctx->ListState.CurrentBlock + ctx->ListState.CurrentPos;
+ ctx->ListState.CurrentPos += numNodes;
+
+ n[0].opcode = opcode;
+
+ return n;
+}
+
+
+
+/**
+ * Allocate space for a display list instruction. Used by callers outside
+ * this file for things like VBO vertex data.
+ *
+ * \param opcode the instruction opcode (OPCODE_* value)
+ * \param bytes instruction size in bytes, not counting opcode.
+ * \return pointer to the usable data area (not including the internal
+ * opcode).
+ */
+void *
+_mesa_dlist_alloc(struct gl_context *ctx, GLuint opcode, GLuint bytes)
+{
+ Node *n = dlist_alloc(ctx, (OpCode) opcode, bytes);
+ if (n)
+ return n + 1; /* return pointer to payload area, after opcode */
+ else
+ return NULL;
+}
+
+
+/**
+ * This function allows modules and drivers to get their own opcodes
+ * for extending display list functionality.
+ * \param ctx the rendering context
+ * \param size number of bytes for storing the new display list command
+ * \param execute function to execute the new display list command
+ * \param destroy function to destroy the new display list command
+ * \param print function to print the new display list command
+ * \return the new opcode number or -1 if error
+ */
+GLint
+_mesa_dlist_alloc_opcode(struct gl_context *ctx,
+ GLuint size,
+ void (*execute) (struct gl_context *, void *),
+ void (*destroy) (struct gl_context *, void *),
+ void (*print) (struct gl_context *, void *))
+{
+ if (ctx->ListExt->NumOpcodes < MAX_DLIST_EXT_OPCODES) {
+ const GLuint i = ctx->ListExt->NumOpcodes++;
+ ctx->ListExt->Opcode[i].Size =
+ 1 + (size + sizeof(Node) - 1) / sizeof(Node);
+ ctx->ListExt->Opcode[i].Execute = execute;
+ ctx->ListExt->Opcode[i].Destroy = destroy;
+ ctx->ListExt->Opcode[i].Print = print;
+ return i + OPCODE_EXT_0;
+ }
+ return -1;
+}
+
+
+/**
+ * Allocate space for a display list instruction. The space is basically
+ * an array of Nodes where node[0] holds the opcode, node[1] is the first
+ * function parameter, node[2] is the second parameter, etc.
+ *
+ * \param opcode one of OPCODE_x
+ * \param nparams number of function parameters
+ * \return pointer to start of instruction space
+ */
+static INLINE Node *
+alloc_instruction(struct gl_context *ctx, OpCode opcode, GLuint nparams)
+{
+ return dlist_alloc(ctx, opcode, nparams * sizeof(Node));
+}
+
+
+
+/*
+ * Display List compilation functions
+ */
+static void GLAPIENTRY
+save_Accum(GLenum op, GLfloat value)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_ACCUM, 2);
+ if (n) {
+ n[1].e = op;
+ n[2].f = value;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Accum(ctx->Exec, (op, value));
+ }
+}
+
+
+static void GLAPIENTRY
+save_AlphaFunc(GLenum func, GLclampf ref)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_ALPHA_FUNC, 2);
+ if (n) {
+ n[1].e = func;
+ n[2].f = (GLfloat) ref;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_AlphaFunc(ctx->Exec, (func, ref));
+ }
+}
+
+
+static void GLAPIENTRY
+save_BindTexture(GLenum target, GLuint texture)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BIND_TEXTURE, 2);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = texture;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BindTexture(ctx->Exec, (target, texture));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Bitmap(GLsizei width, GLsizei height,
+ GLfloat xorig, GLfloat yorig,
+ GLfloat xmove, GLfloat ymove, const GLubyte * pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BITMAP, 7);
+ if (n) {
+ n[1].i = (GLint) width;
+ n[2].i = (GLint) height;
+ n[3].f = xorig;
+ n[4].f = yorig;
+ n[5].f = xmove;
+ n[6].f = ymove;
+ n[7].data = _mesa_unpack_bitmap(width, height, pixels, &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Bitmap(ctx->Exec, (width, height,
+ xorig, yorig, xmove, ymove, pixels));
+ }
+}
+
+
+static void GLAPIENTRY
+save_BlendEquation(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION, 1);
+ if (n) {
+ n[1].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BlendEquation(ctx->Exec, (mode));
+ }
+}
+
+
+static void GLAPIENTRY
+save_BlendEquationSeparateEXT(GLenum modeRGB, GLenum modeA)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION_SEPARATE, 2);
+ if (n) {
+ n[1].e = modeRGB;
+ n[2].e = modeA;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BlendEquationSeparateEXT(ctx->Exec, (modeRGB, modeA));
+ }
+}
+
+
+static void GLAPIENTRY
+save_BlendFuncSeparateEXT(GLenum sfactorRGB, GLenum dfactorRGB,
+ GLenum sfactorA, GLenum dfactorA)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BLEND_FUNC_SEPARATE, 4);
+ if (n) {
+ n[1].e = sfactorRGB;
+ n[2].e = dfactorRGB;
+ n[3].e = sfactorA;
+ n[4].e = dfactorA;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BlendFuncSeparateEXT(ctx->Exec,
+ (sfactorRGB, dfactorRGB, sfactorA, dfactorA));
+ }
+}
+
+
+static void GLAPIENTRY
+save_BlendFunc(GLenum srcfactor, GLenum dstfactor)
+{
+ save_BlendFuncSeparateEXT(srcfactor, dstfactor, srcfactor, dstfactor);
+}
+
+
+static void GLAPIENTRY
+save_BlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BLEND_COLOR, 4);
+ if (n) {
+ n[1].f = red;
+ n[2].f = green;
+ n[3].f = blue;
+ n[4].f = alpha;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BlendColor(ctx->Exec, (red, green, blue, alpha));
+ }
+}
+
+/* GL_ARB_draw_buffers_blend */
+static void GLAPIENTRY
+save_BlendFuncSeparatei(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB,
+ GLenum sfactorA, GLenum dfactorA)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BLEND_FUNC_SEPARATE_I, 5);
+ if (n) {
+ n[1].ui = buf;
+ n[2].e = sfactorRGB;
+ n[3].e = dfactorRGB;
+ n[4].e = sfactorA;
+ n[5].e = dfactorA;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BlendFuncSeparateiARB(ctx->Exec, (buf, sfactorRGB, dfactorRGB,
+ sfactorA, dfactorA));
+ }
+}
+
+/* GL_ARB_draw_buffers_blend */
+static void GLAPIENTRY
+save_BlendFunci(GLuint buf, GLenum sfactor, GLenum dfactor)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BLEND_FUNC_SEPARATE_I, 3);
+ if (n) {
+ n[1].ui = buf;
+ n[2].e = sfactor;
+ n[3].e = dfactor;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BlendFunciARB(ctx->Exec, (buf, sfactor, dfactor));
+ }
+}
+
+/* GL_ARB_draw_buffers_blend */
+static void GLAPIENTRY
+save_BlendEquationi(GLuint buf, GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION_I, 2);
+ if (n) {
+ n[1].ui = buf;
+ n[2].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BlendEquationiARB(ctx->Exec, (buf, mode));
+ }
+}
+
+/* GL_ARB_draw_buffers_blend */
+static void GLAPIENTRY
+save_BlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeA)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION_SEPARATE_I, 3);
+ if (n) {
+ n[1].ui = buf;
+ n[2].e = modeRGB;
+ n[3].e = modeA;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BlendEquationSeparateiARB(ctx->Exec, (buf, modeRGB, modeA));
+ }
+}
+
+
+static void invalidate_saved_current_state( struct gl_context *ctx )
+{
+ GLint i;
+
+ for (i = 0; i < VERT_ATTRIB_MAX; i++)
+ ctx->ListState.ActiveAttribSize[i] = 0;
+
+ for (i = 0; i < MAT_ATTRIB_MAX; i++)
+ ctx->ListState.ActiveMaterialSize[i] = 0;
+
+ memset(&ctx->ListState.Current, 0, sizeof ctx->ListState.Current);
+
+ ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
+}
+
+static void GLAPIENTRY
+save_CallList(GLuint list)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_CALL_LIST, 1);
+ if (n) {
+ n[1].ui = list;
+ }
+
+ /* After this, we don't know what state we're in. Invalidate all
+ * cached information previously gathered:
+ */
+ invalidate_saved_current_state( ctx );
+
+ if (ctx->ExecuteFlag) {
+ _mesa_CallList(list);
+ }
+}
+
+
+static void GLAPIENTRY
+save_CallLists(GLsizei num, GLenum type, const GLvoid * lists)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+ GLboolean typeErrorFlag;
+
+ SAVE_FLUSH_VERTICES(ctx);
+
+ switch (type) {
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ case GL_SHORT:
+ case GL_UNSIGNED_SHORT:
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ case GL_FLOAT:
+ case GL_2_BYTES:
+ case GL_3_BYTES:
+ case GL_4_BYTES:
+ typeErrorFlag = GL_FALSE;
+ break;
+ default:
+ typeErrorFlag = GL_TRUE;
+ }
+
+ for (i = 0; i < num; i++) {
+ GLint list = translate_id(i, type, lists);
+ Node *n = alloc_instruction(ctx, OPCODE_CALL_LIST_OFFSET, 2);
+ if (n) {
+ n[1].i = list;
+ n[2].b = typeErrorFlag;
+ }
+ }
+
+ /* After this, we don't know what state we're in. Invalidate all
+ * cached information previously gathered:
+ */
+ invalidate_saved_current_state( ctx );
+
+ if (ctx->ExecuteFlag) {
+ CALL_CallLists(ctx->Exec, (num, type, lists));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Clear(GLbitfield mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEAR, 1);
+ if (n) {
+ n[1].bf = mask;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Clear(ctx->Exec, (mask));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *value)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_IV, 6);
+ if (n) {
+ n[1].e = buffer;
+ n[2].i = drawbuffer;
+ n[3].i = value[0];
+ if (buffer == GL_COLOR) {
+ n[4].i = value[1];
+ n[5].i = value[2];
+ n[6].i = value[3];
+ }
+ else {
+ n[4].i = 0;
+ n[5].i = 0;
+ n[6].i = 0;
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_ClearBufferiv(ctx->Exec, (buffer, drawbuffer, value));*/
+ }
+}
+
+
+static void GLAPIENTRY
+save_ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *value)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_UIV, 6);
+ if (n) {
+ n[1].e = buffer;
+ n[2].i = drawbuffer;
+ n[3].ui = value[0];
+ if (buffer == GL_COLOR) {
+ n[4].ui = value[1];
+ n[5].ui = value[2];
+ n[6].ui = value[3];
+ }
+ else {
+ n[4].ui = 0;
+ n[5].ui = 0;
+ n[6].ui = 0;
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_ClearBufferuiv(ctx->Exec, (buffer, drawbuffer, value));*/
+ }
+}
+
+
+static void GLAPIENTRY
+save_ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *value)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_FV, 6);
+ if (n) {
+ n[1].e = buffer;
+ n[2].i = drawbuffer;
+ n[3].f = value[0];
+ if (buffer == GL_COLOR) {
+ n[4].f = value[1];
+ n[5].f = value[2];
+ n[6].f = value[3];
+ }
+ else {
+ n[4].f = 0.0F;
+ n[5].f = 0.0F;
+ n[6].f = 0.0F;
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_ClearBufferuiv(ctx->Exec, (buffer, drawbuffer, value));*/
+ }
+}
+
+
+static void GLAPIENTRY
+save_ClearBufferfi(GLenum buffer, GLint drawbuffer,
+ GLfloat depth, GLint stencil)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_FI, 4);
+ if (n) {
+ n[1].e = buffer;
+ n[2].i = drawbuffer;
+ n[3].f = depth;
+ n[4].i = stencil;
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_ClearBufferfi(ctx->Exec, (buffer, drawbuffer, depth, stencil));*/
+ }
+}
+
+
+static void GLAPIENTRY
+save_ClearAccum(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEAR_ACCUM, 4);
+ if (n) {
+ n[1].f = red;
+ n[2].f = green;
+ n[3].f = blue;
+ n[4].f = alpha;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ClearAccum(ctx->Exec, (red, green, blue, alpha));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEAR_COLOR, 4);
+ if (n) {
+ n[1].f = red;
+ n[2].f = green;
+ n[3].f = blue;
+ n[4].f = alpha;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ClearColor(ctx->Exec, (red, green, blue, alpha));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ClearDepth(GLclampd depth)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEAR_DEPTH, 1);
+ if (n) {
+ n[1].f = (GLfloat) depth;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ClearDepth(ctx->Exec, (depth));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ClearIndex(GLfloat c)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEAR_INDEX, 1);
+ if (n) {
+ n[1].f = c;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ClearIndex(ctx->Exec, (c));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ClearStencil(GLint s)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEAR_STENCIL, 1);
+ if (n) {
+ n[1].i = s;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ClearStencil(ctx->Exec, (s));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ClipPlane(GLenum plane, const GLdouble * equ)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLIP_PLANE, 5);
+ if (n) {
+ n[1].e = plane;
+ n[2].f = (GLfloat) equ[0];
+ n[3].f = (GLfloat) equ[1];
+ n[4].f = (GLfloat) equ[2];
+ n[5].f = (GLfloat) equ[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ClipPlane(ctx->Exec, (plane, equ));
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_ColorMask(GLboolean red, GLboolean green,
+ GLboolean blue, GLboolean alpha)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COLOR_MASK, 4);
+ if (n) {
+ n[1].b = red;
+ n[2].b = green;
+ n[3].b = blue;
+ n[4].b = alpha;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ColorMask(ctx->Exec, (red, green, blue, alpha));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ColorMaskIndexed(GLuint buf, GLboolean red, GLboolean green,
+ GLboolean blue, GLboolean alpha)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COLOR_MASK_INDEXED, 5);
+ if (n) {
+ n[1].ui = buf;
+ n[2].b = red;
+ n[3].b = green;
+ n[4].b = blue;
+ n[5].b = alpha;
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_ColorMaskIndexedEXT(ctx->Exec, (buf, red, green, blue, alpha));*/
+ }
+}
+
+
+static void GLAPIENTRY
+save_ColorMaterial(GLenum face, GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_COLOR_MATERIAL, 2);
+ if (n) {
+ n[1].e = face;
+ n[2].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ColorMaterial(ctx->Exec, (face, mode));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ColorTable(GLenum target, GLenum internalFormat,
+ GLsizei width, GLenum format, GLenum type,
+ const GLvoid * table)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (_mesa_is_proxy_texture(target)) {
+ /* execute immediately */
+ CALL_ColorTable(ctx->Exec, (target, internalFormat, width,
+ format, type, table));
+ }
+ else {
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COLOR_TABLE, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].e = internalFormat;
+ n[3].i = width;
+ n[4].e = format;
+ n[5].e = type;
+ n[6].data = unpack_image(ctx, 1, width, 1, 1, format, type, table,
+ &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ColorTable(ctx->Exec, (target, internalFormat, width,
+ format, type, table));
+ }
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_ColorTableParameterfv(GLenum target, GLenum pname,
+ const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_COLOR_TABLE_PARAMETER_FV, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].e = pname;
+ n[3].f = params[0];
+ if (pname == GL_COLOR_TABLE_SGI ||
+ pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
+ pname == GL_TEXTURE_COLOR_TABLE_SGI) {
+ n[4].f = params[1];
+ n[5].f = params[2];
+ n[6].f = params[3];
+ }
+ }
+
+ if (ctx->ExecuteFlag) {
+ CALL_ColorTableParameterfv(ctx->Exec, (target, pname, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_COLOR_TABLE_PARAMETER_IV, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].e = pname;
+ n[3].i = params[0];
+ if (pname == GL_COLOR_TABLE_SGI ||
+ pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
+ pname == GL_TEXTURE_COLOR_TABLE_SGI) {
+ n[4].i = params[1];
+ n[5].i = params[2];
+ n[6].i = params[3];
+ }
+ }
+
+ if (ctx->ExecuteFlag) {
+ CALL_ColorTableParameteriv(ctx->Exec, (target, pname, params));
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_ColorSubTable(GLenum target, GLsizei start, GLsizei count,
+ GLenum format, GLenum type, const GLvoid * table)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COLOR_SUB_TABLE, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].i = start;
+ n[3].i = count;
+ n[4].e = format;
+ n[5].e = type;
+ n[6].data = unpack_image(ctx, 1, count, 1, 1, format, type, table,
+ &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ColorSubTable(ctx->Exec,
+ (target, start, count, format, type, table));
+ }
+}
+
+
+static void GLAPIENTRY
+save_CopyColorSubTable(GLenum target, GLsizei start,
+ GLint x, GLint y, GLsizei width)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COPY_COLOR_SUB_TABLE, 5);
+ if (n) {
+ n[1].e = target;
+ n[2].i = start;
+ n[3].i = x;
+ n[4].i = y;
+ n[5].i = width;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CopyColorSubTable(ctx->Exec, (target, start, x, y, width));
+ }
+}
+
+
+static void GLAPIENTRY
+save_CopyColorTable(GLenum target, GLenum internalformat,
+ GLint x, GLint y, GLsizei width)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COPY_COLOR_TABLE, 5);
+ if (n) {
+ n[1].e = target;
+ n[2].e = internalformat;
+ n[3].i = x;
+ n[4].i = y;
+ n[5].i = width;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CopyColorTable(ctx->Exec, (target, internalformat, x, y, width));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width,
+ GLenum format, GLenum type, const GLvoid * filter)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_CONVOLUTION_FILTER_1D, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].e = internalFormat;
+ n[3].i = width;
+ n[4].e = format;
+ n[5].e = type;
+ n[6].data = unpack_image(ctx, 1, width, 1, 1, format, type, filter,
+ &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ConvolutionFilter1D(ctx->Exec, (target, internalFormat, width,
+ format, type, filter));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ConvolutionFilter2D(GLenum target, GLenum internalFormat,
+ GLsizei width, GLsizei height, GLenum format,
+ GLenum type, const GLvoid * filter)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_CONVOLUTION_FILTER_2D, 7);
+ if (n) {
+ n[1].e = target;
+ n[2].e = internalFormat;
+ n[3].i = width;
+ n[4].i = height;
+ n[5].e = format;
+ n[6].e = type;
+ n[7].data = unpack_image(ctx, 2, width, height, 1, format, type, filter,
+ &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ConvolutionFilter2D(ctx->Exec,
+ (target, internalFormat, width, height, format,
+ type, filter));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ConvolutionParameteri(GLenum target, GLenum pname, GLint param)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_I, 3);
+ if (n) {
+ n[1].e = target;
+ n[2].e = pname;
+ n[3].i = param;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ConvolutionParameteri(ctx->Exec, (target, pname, param));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ConvolutionParameteriv(GLenum target, GLenum pname, const GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_IV, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].e = pname;
+ n[3].i = params[0];
+ if (pname == GL_CONVOLUTION_BORDER_COLOR ||
+ pname == GL_CONVOLUTION_FILTER_SCALE ||
+ pname == GL_CONVOLUTION_FILTER_BIAS) {
+ n[4].i = params[1];
+ n[5].i = params[2];
+ n[6].i = params[3];
+ }
+ else {
+ n[4].i = n[5].i = n[6].i = 0;
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ConvolutionParameteriv(ctx->Exec, (target, pname, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ConvolutionParameterf(GLenum target, GLenum pname, GLfloat param)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_F, 3);
+ if (n) {
+ n[1].e = target;
+ n[2].e = pname;
+ n[3].f = param;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ConvolutionParameterf(ctx->Exec, (target, pname, param));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ConvolutionParameterfv(GLenum target, GLenum pname,
+ const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_FV, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].e = pname;
+ n[3].f = params[0];
+ if (pname == GL_CONVOLUTION_BORDER_COLOR ||
+ pname == GL_CONVOLUTION_FILTER_SCALE ||
+ pname == GL_CONVOLUTION_FILTER_BIAS) {
+ n[4].f = params[1];
+ n[5].f = params[2];
+ n[6].f = params[3];
+ }
+ else {
+ n[4].f = n[5].f = n[6].f = 0.0F;
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ConvolutionParameterfv(ctx->Exec, (target, pname, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_CopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COPY_PIXELS, 5);
+ if (n) {
+ n[1].i = x;
+ n[2].i = y;
+ n[3].i = (GLint) width;
+ n[4].i = (GLint) height;
+ n[5].e = type;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CopyPixels(ctx->Exec, (x, y, width, height, type));
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_CopyTexImage1D(GLenum target, GLint level, GLenum internalformat,
+ GLint x, GLint y, GLsizei width, GLint border)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COPY_TEX_IMAGE1D, 7);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].e = internalformat;
+ n[4].i = x;
+ n[5].i = y;
+ n[6].i = width;
+ n[7].i = border;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CopyTexImage1D(ctx->Exec, (target, level, internalformat,
+ x, y, width, border));
+ }
+}
+
+
+static void GLAPIENTRY
+save_CopyTexImage2D(GLenum target, GLint level,
+ GLenum internalformat,
+ GLint x, GLint y, GLsizei width,
+ GLsizei height, GLint border)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COPY_TEX_IMAGE2D, 8);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].e = internalformat;
+ n[4].i = x;
+ n[5].i = y;
+ n[6].i = width;
+ n[7].i = height;
+ n[8].i = border;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CopyTexImage2D(ctx->Exec, (target, level, internalformat,
+ x, y, width, height, border));
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_CopyTexSubImage1D(GLenum target, GLint level,
+ GLint xoffset, GLint x, GLint y, GLsizei width)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COPY_TEX_SUB_IMAGE1D, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = xoffset;
+ n[4].i = x;
+ n[5].i = y;
+ n[6].i = width;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CopyTexSubImage1D(ctx->Exec,
+ (target, level, xoffset, x, y, width));
+ }
+}
+
+
+static void GLAPIENTRY
+save_CopyTexSubImage2D(GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint x, GLint y, GLsizei width, GLint height)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COPY_TEX_SUB_IMAGE2D, 8);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = xoffset;
+ n[4].i = yoffset;
+ n[5].i = x;
+ n[6].i = y;
+ n[7].i = width;
+ n[8].i = height;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CopyTexSubImage2D(ctx->Exec, (target, level, xoffset, yoffset,
+ x, y, width, height));
+ }
+}
+
+
+static void GLAPIENTRY
+save_CopyTexSubImage3D(GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y, GLsizei width, GLint height)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_COPY_TEX_SUB_IMAGE3D, 9);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = xoffset;
+ n[4].i = yoffset;
+ n[5].i = zoffset;
+ n[6].i = x;
+ n[7].i = y;
+ n[8].i = width;
+ n[9].i = height;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CopyTexSubImage3D(ctx->Exec, (target, level,
+ xoffset, yoffset, zoffset,
+ x, y, width, height));
+ }
+}
+
+
+static void GLAPIENTRY
+save_CullFace(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CULL_FACE, 1);
+ if (n) {
+ n[1].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CullFace(ctx->Exec, (mode));
+ }
+}
+
+
+static void GLAPIENTRY
+save_DepthFunc(GLenum func)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_DEPTH_FUNC, 1);
+ if (n) {
+ n[1].e = func;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_DepthFunc(ctx->Exec, (func));
+ }
+}
+
+
+static void GLAPIENTRY
+save_DepthMask(GLboolean mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_DEPTH_MASK, 1);
+ if (n) {
+ n[1].b = mask;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_DepthMask(ctx->Exec, (mask));
+ }
+}
+
+
+static void GLAPIENTRY
+save_DepthRange(GLclampd nearval, GLclampd farval)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_DEPTH_RANGE, 2);
+ if (n) {
+ n[1].f = (GLfloat) nearval;
+ n[2].f = (GLfloat) farval;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_DepthRange(ctx->Exec, (nearval, farval));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Disable(GLenum cap)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_DISABLE, 1);
+ if (n) {
+ n[1].e = cap;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Disable(ctx->Exec, (cap));
+ }
+}
+
+
+static void GLAPIENTRY
+save_DisableIndexed(GLuint index, GLenum cap)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_DISABLE_INDEXED, 2);
+ if (n) {
+ n[1].ui = index;
+ n[2].e = cap;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_DisableIndexedEXT(ctx->Exec, (index, cap));
+ }
+}
+
+
+static void GLAPIENTRY
+save_DrawBuffer(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_DRAW_BUFFER, 1);
+ if (n) {
+ n[1].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_DrawBuffer(ctx->Exec, (mode));
+ }
+}
+
+
+static void GLAPIENTRY
+save_DrawPixels(GLsizei width, GLsizei height,
+ GLenum format, GLenum type, const GLvoid * pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_DRAW_PIXELS, 5);
+ if (n) {
+ n[1].i = width;
+ n[2].i = height;
+ n[3].e = format;
+ n[4].e = type;
+ n[5].data = unpack_image(ctx, 2, width, height, 1, format, type,
+ pixels, &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_DrawPixels(ctx->Exec, (width, height, format, type, pixels));
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_Enable(GLenum cap)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_ENABLE, 1);
+ if (n) {
+ n[1].e = cap;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Enable(ctx->Exec, (cap));
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_EnableIndexed(GLuint index, GLenum cap)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_ENABLE_INDEXED, 2);
+ if (n) {
+ n[1].ui = index;
+ n[2].e = cap;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_EnableIndexedEXT(ctx->Exec, (index, cap));
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_EvalMesh1(GLenum mode, GLint i1, GLint i2)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_EVALMESH1, 3);
+ if (n) {
+ n[1].e = mode;
+ n[2].i = i1;
+ n[3].i = i2;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_EvalMesh1(ctx->Exec, (mode, i1, i2));
+ }
+}
+
+
+static void GLAPIENTRY
+save_EvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_EVALMESH2, 5);
+ if (n) {
+ n[1].e = mode;
+ n[2].i = i1;
+ n[3].i = i2;
+ n[4].i = j1;
+ n[5].i = j2;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_EvalMesh2(ctx->Exec, (mode, i1, i2, j1, j2));
+ }
+}
+
+
+
+
+static void GLAPIENTRY
+save_Fogfv(GLenum pname, const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_FOG, 5);
+ if (n) {
+ n[1].e = pname;
+ n[2].f = params[0];
+ n[3].f = params[1];
+ n[4].f = params[2];
+ n[5].f = params[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Fogfv(ctx->Exec, (pname, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Fogf(GLenum pname, GLfloat param)
+{
+ GLfloat parray[4];
+ parray[0] = param;
+ parray[1] = parray[2] = parray[3] = 0.0F;
+ save_Fogfv(pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_Fogiv(GLenum pname, const GLint *params)
+{
+ GLfloat p[4];
+ switch (pname) {
+ case GL_FOG_MODE:
+ case GL_FOG_DENSITY:
+ case GL_FOG_START:
+ case GL_FOG_END:
+ case GL_FOG_INDEX:
+ p[0] = (GLfloat) *params;
+ p[1] = 0.0f;
+ p[2] = 0.0f;
+ p[3] = 0.0f;
+ break;
+ case GL_FOG_COLOR:
+ p[0] = INT_TO_FLOAT(params[0]);
+ p[1] = INT_TO_FLOAT(params[1]);
+ p[2] = INT_TO_FLOAT(params[2]);
+ p[3] = INT_TO_FLOAT(params[3]);
+ break;
+ default:
+ /* Error will be caught later in gl_Fogfv */
+ ASSIGN_4V(p, 0.0F, 0.0F, 0.0F, 0.0F);
+ }
+ save_Fogfv(pname, p);
+}
+
+
+static void GLAPIENTRY
+save_Fogi(GLenum pname, GLint param)
+{
+ GLint parray[4];
+ parray[0] = param;
+ parray[1] = parray[2] = parray[3] = 0;
+ save_Fogiv(pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_FrontFace(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_FRONT_FACE, 1);
+ if (n) {
+ n[1].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_FrontFace(ctx->Exec, (mode));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Frustum(GLdouble left, GLdouble right,
+ GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_FRUSTUM, 6);
+ if (n) {
+ n[1].f = (GLfloat) left;
+ n[2].f = (GLfloat) right;
+ n[3].f = (GLfloat) bottom;
+ n[4].f = (GLfloat) top;
+ n[5].f = (GLfloat) nearval;
+ n[6].f = (GLfloat) farval;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Frustum(ctx->Exec, (left, right, bottom, top, nearval, farval));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Hint(GLenum target, GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_HINT, 2);
+ if (n) {
+ n[1].e = target;
+ n[2].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Hint(ctx->Exec, (target, mode));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Histogram(GLenum target, GLsizei width, GLenum internalFormat,
+ GLboolean sink)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_HISTOGRAM, 4);
+ if (n) {
+ n[1].e = target;
+ n[2].i = width;
+ n[3].e = internalFormat;
+ n[4].b = sink;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Histogram(ctx->Exec, (target, width, internalFormat, sink));
+ }
+}
+
+
+static void GLAPIENTRY
+save_IndexMask(GLuint mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_INDEX_MASK, 1);
+ if (n) {
+ n[1].ui = mask;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_IndexMask(ctx->Exec, (mask));
+ }
+}
+
+
+static void GLAPIENTRY
+save_InitNames(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ (void) alloc_instruction(ctx, OPCODE_INIT_NAMES, 0);
+ if (ctx->ExecuteFlag) {
+ CALL_InitNames(ctx->Exec, ());
+ }
+}
+
+
+static void GLAPIENTRY
+save_Lightfv(GLenum light, GLenum pname, const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_LIGHT, 6);
+ if (n) {
+ GLint i, nParams;
+ n[1].e = light;
+ n[2].e = pname;
+ switch (pname) {
+ case GL_AMBIENT:
+ nParams = 4;
+ break;
+ case GL_DIFFUSE:
+ nParams = 4;
+ break;
+ case GL_SPECULAR:
+ nParams = 4;
+ break;
+ case GL_POSITION:
+ nParams = 4;
+ break;
+ case GL_SPOT_DIRECTION:
+ nParams = 3;
+ break;
+ case GL_SPOT_EXPONENT:
+ nParams = 1;
+ break;
+ case GL_SPOT_CUTOFF:
+ nParams = 1;
+ break;
+ case GL_CONSTANT_ATTENUATION:
+ nParams = 1;
+ break;
+ case GL_LINEAR_ATTENUATION:
+ nParams = 1;
+ break;
+ case GL_QUADRATIC_ATTENUATION:
+ nParams = 1;
+ break;
+ default:
+ nParams = 0;
+ }
+ for (i = 0; i < nParams; i++) {
+ n[3 + i].f = params[i];
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Lightfv(ctx->Exec, (light, pname, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Lightf(GLenum light, GLenum pname, GLfloat param)
+{
+ GLfloat parray[4];
+ parray[0] = param;
+ parray[1] = parray[2] = parray[3] = 0.0F;
+ save_Lightfv(light, pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_Lightiv(GLenum light, GLenum pname, const GLint *params)
+{
+ GLfloat fparam[4];
+ switch (pname) {
+ case GL_AMBIENT:
+ case GL_DIFFUSE:
+ case GL_SPECULAR:
+ fparam[0] = INT_TO_FLOAT(params[0]);
+ fparam[1] = INT_TO_FLOAT(params[1]);
+ fparam[2] = INT_TO_FLOAT(params[2]);
+ fparam[3] = INT_TO_FLOAT(params[3]);
+ break;
+ case GL_POSITION:
+ fparam[0] = (GLfloat) params[0];
+ fparam[1] = (GLfloat) params[1];
+ fparam[2] = (GLfloat) params[2];
+ fparam[3] = (GLfloat) params[3];
+ break;
+ case GL_SPOT_DIRECTION:
+ fparam[0] = (GLfloat) params[0];
+ fparam[1] = (GLfloat) params[1];
+ fparam[2] = (GLfloat) params[2];
+ break;
+ case GL_SPOT_EXPONENT:
+ case GL_SPOT_CUTOFF:
+ case GL_CONSTANT_ATTENUATION:
+ case GL_LINEAR_ATTENUATION:
+ case GL_QUADRATIC_ATTENUATION:
+ fparam[0] = (GLfloat) params[0];
+ break;
+ default:
+ /* error will be caught later in gl_Lightfv */
+ ;
+ }
+ save_Lightfv(light, pname, fparam);
+}
+
+
+static void GLAPIENTRY
+save_Lighti(GLenum light, GLenum pname, GLint param)
+{
+ GLint parray[4];
+ parray[0] = param;
+ parray[1] = parray[2] = parray[3] = 0;
+ save_Lightiv(light, pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_LightModelfv(GLenum pname, const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_LIGHT_MODEL, 5);
+ if (n) {
+ n[1].e = pname;
+ n[2].f = params[0];
+ n[3].f = params[1];
+ n[4].f = params[2];
+ n[5].f = params[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_LightModelfv(ctx->Exec, (pname, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_LightModelf(GLenum pname, GLfloat param)
+{
+ GLfloat parray[4];
+ parray[0] = param;
+ parray[1] = parray[2] = parray[3] = 0.0F;
+ save_LightModelfv(pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_LightModeliv(GLenum pname, const GLint *params)
+{
+ GLfloat fparam[4];
+ switch (pname) {
+ case GL_LIGHT_MODEL_AMBIENT:
+ fparam[0] = INT_TO_FLOAT(params[0]);
+ fparam[1] = INT_TO_FLOAT(params[1]);
+ fparam[2] = INT_TO_FLOAT(params[2]);
+ fparam[3] = INT_TO_FLOAT(params[3]);
+ break;
+ case GL_LIGHT_MODEL_LOCAL_VIEWER:
+ case GL_LIGHT_MODEL_TWO_SIDE:
+ case GL_LIGHT_MODEL_COLOR_CONTROL:
+ fparam[0] = (GLfloat) params[0];
+ fparam[1] = 0.0F;
+ fparam[2] = 0.0F;
+ fparam[3] = 0.0F;
+ break;
+ default:
+ /* Error will be caught later in gl_LightModelfv */
+ ASSIGN_4V(fparam, 0.0F, 0.0F, 0.0F, 0.0F);
+ }
+ save_LightModelfv(pname, fparam);
+}
+
+
+static void GLAPIENTRY
+save_LightModeli(GLenum pname, GLint param)
+{
+ GLint parray[4];
+ parray[0] = param;
+ parray[1] = parray[2] = parray[3] = 0;
+ save_LightModeliv(pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_LineStipple(GLint factor, GLushort pattern)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_LINE_STIPPLE, 2);
+ if (n) {
+ n[1].i = factor;
+ n[2].us = pattern;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_LineStipple(ctx->Exec, (factor, pattern));
+ }
+}
+
+
+static void GLAPIENTRY
+save_LineWidth(GLfloat width)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_LINE_WIDTH, 1);
+ if (n) {
+ n[1].f = width;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_LineWidth(ctx->Exec, (width));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ListBase(GLuint base)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_LIST_BASE, 1);
+ if (n) {
+ n[1].ui = base;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ListBase(ctx->Exec, (base));
+ }
+}
+
+
+static void GLAPIENTRY
+save_LoadIdentity(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ (void) alloc_instruction(ctx, OPCODE_LOAD_IDENTITY, 0);
+ if (ctx->ExecuteFlag) {
+ CALL_LoadIdentity(ctx->Exec, ());
+ }
+}
+
+
+static void GLAPIENTRY
+save_LoadMatrixf(const GLfloat * m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_LOAD_MATRIX, 16);
+ if (n) {
+ GLuint i;
+ for (i = 0; i < 16; i++) {
+ n[1 + i].f = m[i];
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_LoadMatrixf(ctx->Exec, (m));
+ }
+}
+
+
+static void GLAPIENTRY
+save_LoadMatrixd(const GLdouble * m)
+{
+ GLfloat f[16];
+ GLint i;
+ for (i = 0; i < 16; i++) {
+ f[i] = (GLfloat) m[i];
+ }
+ save_LoadMatrixf(f);
+}
+
+
+static void GLAPIENTRY
+save_LoadName(GLuint name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_LOAD_NAME, 1);
+ if (n) {
+ n[1].ui = name;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_LoadName(ctx->Exec, (name));
+ }
+}
+
+
+static void GLAPIENTRY
+save_LogicOp(GLenum opcode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_LOGIC_OP, 1);
+ if (n) {
+ n[1].e = opcode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_LogicOp(ctx->Exec, (opcode));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Map1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
+ GLint order, const GLdouble * points)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_MAP1, 6);
+ if (n) {
+ GLfloat *pnts = _mesa_copy_map_points1d(target, stride, order, points);
+ n[1].e = target;
+ n[2].f = (GLfloat) u1;
+ n[3].f = (GLfloat) u2;
+ n[4].i = _mesa_evaluator_components(target); /* stride */
+ n[5].i = order;
+ n[6].data = (void *) pnts;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Map1d(ctx->Exec, (target, u1, u2, stride, order, points));
+ }
+}
+
+static void GLAPIENTRY
+save_Map1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
+ GLint order, const GLfloat * points)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_MAP1, 6);
+ if (n) {
+ GLfloat *pnts = _mesa_copy_map_points1f(target, stride, order, points);
+ n[1].e = target;
+ n[2].f = u1;
+ n[3].f = u2;
+ n[4].i = _mesa_evaluator_components(target); /* stride */
+ n[5].i = order;
+ n[6].data = (void *) pnts;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Map1f(ctx->Exec, (target, u1, u2, stride, order, points));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Map2d(GLenum target,
+ GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
+ GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
+ const GLdouble * points)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_MAP2, 10);
+ if (n) {
+ GLfloat *pnts = _mesa_copy_map_points2d(target, ustride, uorder,
+ vstride, vorder, points);
+ n[1].e = target;
+ n[2].f = (GLfloat) u1;
+ n[3].f = (GLfloat) u2;
+ n[4].f = (GLfloat) v1;
+ n[5].f = (GLfloat) v2;
+ /* XXX verify these strides are correct */
+ n[6].i = _mesa_evaluator_components(target) * vorder; /*ustride */
+ n[7].i = _mesa_evaluator_components(target); /*vstride */
+ n[8].i = uorder;
+ n[9].i = vorder;
+ n[10].data = (void *) pnts;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Map2d(ctx->Exec, (target,
+ u1, u2, ustride, uorder,
+ v1, v2, vstride, vorder, points));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Map2f(GLenum target,
+ GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
+ GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
+ const GLfloat * points)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_MAP2, 10);
+ if (n) {
+ GLfloat *pnts = _mesa_copy_map_points2f(target, ustride, uorder,
+ vstride, vorder, points);
+ n[1].e = target;
+ n[2].f = u1;
+ n[3].f = u2;
+ n[4].f = v1;
+ n[5].f = v2;
+ /* XXX verify these strides are correct */
+ n[6].i = _mesa_evaluator_components(target) * vorder; /*ustride */
+ n[7].i = _mesa_evaluator_components(target); /*vstride */
+ n[8].i = uorder;
+ n[9].i = vorder;
+ n[10].data = (void *) pnts;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Map2f(ctx->Exec, (target, u1, u2, ustride, uorder,
+ v1, v2, vstride, vorder, points));
+ }
+}
+
+
+static void GLAPIENTRY
+save_MapGrid1f(GLint un, GLfloat u1, GLfloat u2)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_MAPGRID1, 3);
+ if (n) {
+ n[1].i = un;
+ n[2].f = u1;
+ n[3].f = u2;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_MapGrid1f(ctx->Exec, (un, u1, u2));
+ }
+}
+
+
+static void GLAPIENTRY
+save_MapGrid1d(GLint un, GLdouble u1, GLdouble u2)
+{
+ save_MapGrid1f(un, (GLfloat) u1, (GLfloat) u2);
+}
+
+
+static void GLAPIENTRY
+save_MapGrid2f(GLint un, GLfloat u1, GLfloat u2,
+ GLint vn, GLfloat v1, GLfloat v2)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_MAPGRID2, 6);
+ if (n) {
+ n[1].i = un;
+ n[2].f = u1;
+ n[3].f = u2;
+ n[4].i = vn;
+ n[5].f = v1;
+ n[6].f = v2;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_MapGrid2f(ctx->Exec, (un, u1, u2, vn, v1, v2));
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_MapGrid2d(GLint un, GLdouble u1, GLdouble u2,
+ GLint vn, GLdouble v1, GLdouble v2)
+{
+ save_MapGrid2f(un, (GLfloat) u1, (GLfloat) u2,
+ vn, (GLfloat) v1, (GLfloat) v2);
+}
+
+
+static void GLAPIENTRY
+save_MatrixMode(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_MATRIX_MODE, 1);
+ if (n) {
+ n[1].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_MatrixMode(ctx->Exec, (mode));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Minmax(GLenum target, GLenum internalFormat, GLboolean sink)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_MIN_MAX, 3);
+ if (n) {
+ n[1].e = target;
+ n[2].e = internalFormat;
+ n[3].b = sink;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Minmax(ctx->Exec, (target, internalFormat, sink));
+ }
+}
+
+
+static void GLAPIENTRY
+save_MultMatrixf(const GLfloat * m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_MULT_MATRIX, 16);
+ if (n) {
+ GLuint i;
+ for (i = 0; i < 16; i++) {
+ n[1 + i].f = m[i];
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_MultMatrixf(ctx->Exec, (m));
+ }
+}
+
+
+static void GLAPIENTRY
+save_MultMatrixd(const GLdouble * m)
+{
+ GLfloat f[16];
+ GLint i;
+ for (i = 0; i < 16; i++) {
+ f[i] = (GLfloat) m[i];
+ }
+ save_MultMatrixf(f);
+}
+
+
+static void GLAPIENTRY
+save_NewList(GLuint name, GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ /* It's an error to call this function while building a display list */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glNewList");
+ (void) name;
+ (void) mode;
+}
+
+
+
+static void GLAPIENTRY
+save_Ortho(GLdouble left, GLdouble right,
+ GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_ORTHO, 6);
+ if (n) {
+ n[1].f = (GLfloat) left;
+ n[2].f = (GLfloat) right;
+ n[3].f = (GLfloat) bottom;
+ n[4].f = (GLfloat) top;
+ n[5].f = (GLfloat) nearval;
+ n[6].f = (GLfloat) farval;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Ortho(ctx->Exec, (left, right, bottom, top, nearval, farval));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PixelMapfv(GLenum map, GLint mapsize, const GLfloat *values)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PIXEL_MAP, 3);
+ if (n) {
+ n[1].e = map;
+ n[2].i = mapsize;
+ n[3].data = (void *) malloc(mapsize * sizeof(GLfloat));
+ memcpy(n[3].data, (void *) values, mapsize * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PixelMapfv(ctx->Exec, (map, mapsize, values));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PixelMapuiv(GLenum map, GLint mapsize, const GLuint *values)
+{
+ GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
+ GLint i;
+ if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
+ for (i = 0; i < mapsize; i++) {
+ fvalues[i] = (GLfloat) values[i];
+ }
+ }
+ else {
+ for (i = 0; i < mapsize; i++) {
+ fvalues[i] = UINT_TO_FLOAT(values[i]);
+ }
+ }
+ save_PixelMapfv(map, mapsize, fvalues);
+}
+
+
+static void GLAPIENTRY
+save_PixelMapusv(GLenum map, GLint mapsize, const GLushort *values)
+{
+ GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
+ GLint i;
+ if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
+ for (i = 0; i < mapsize; i++) {
+ fvalues[i] = (GLfloat) values[i];
+ }
+ }
+ else {
+ for (i = 0; i < mapsize; i++) {
+ fvalues[i] = USHORT_TO_FLOAT(values[i]);
+ }
+ }
+ save_PixelMapfv(map, mapsize, fvalues);
+}
+
+
+static void GLAPIENTRY
+save_PixelTransferf(GLenum pname, GLfloat param)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PIXEL_TRANSFER, 2);
+ if (n) {
+ n[1].e = pname;
+ n[2].f = param;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PixelTransferf(ctx->Exec, (pname, param));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PixelTransferi(GLenum pname, GLint param)
+{
+ save_PixelTransferf(pname, (GLfloat) param);
+}
+
+
+static void GLAPIENTRY
+save_PixelZoom(GLfloat xfactor, GLfloat yfactor)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PIXEL_ZOOM, 2);
+ if (n) {
+ n[1].f = xfactor;
+ n[2].f = yfactor;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PixelZoom(ctx->Exec, (xfactor, yfactor));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PointParameterfvEXT(GLenum pname, const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_POINT_PARAMETERS, 4);
+ if (n) {
+ n[1].e = pname;
+ n[2].f = params[0];
+ n[3].f = params[1];
+ n[4].f = params[2];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PointParameterfvEXT(ctx->Exec, (pname, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PointParameterfEXT(GLenum pname, GLfloat param)
+{
+ GLfloat parray[3];
+ parray[0] = param;
+ parray[1] = parray[2] = 0.0F;
+ save_PointParameterfvEXT(pname, parray);
+}
+
+static void GLAPIENTRY
+save_PointParameteriNV(GLenum pname, GLint param)
+{
+ GLfloat parray[3];
+ parray[0] = (GLfloat) param;
+ parray[1] = parray[2] = 0.0F;
+ save_PointParameterfvEXT(pname, parray);
+}
+
+static void GLAPIENTRY
+save_PointParameterivNV(GLenum pname, const GLint * param)
+{
+ GLfloat parray[3];
+ parray[0] = (GLfloat) param[0];
+ parray[1] = parray[2] = 0.0F;
+ save_PointParameterfvEXT(pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_PointSize(GLfloat size)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_POINT_SIZE, 1);
+ if (n) {
+ n[1].f = size;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PointSize(ctx->Exec, (size));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PolygonMode(GLenum face, GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_POLYGON_MODE, 2);
+ if (n) {
+ n[1].e = face;
+ n[2].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PolygonMode(ctx->Exec, (face, mode));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PolygonStipple(const GLubyte * pattern)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_POLYGON_STIPPLE, 1);
+ if (n) {
+ n[1].data = unpack_image(ctx, 2, 32, 32, 1, GL_COLOR_INDEX, GL_BITMAP,
+ pattern, &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PolygonStipple(ctx->Exec, ((GLubyte *) pattern));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PolygonOffset(GLfloat factor, GLfloat units)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_POLYGON_OFFSET, 2);
+ if (n) {
+ n[1].f = factor;
+ n[2].f = units;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PolygonOffset(ctx->Exec, (factor, units));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PolygonOffsetEXT(GLfloat factor, GLfloat bias)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ /* XXX mult by DepthMaxF here??? */
+ save_PolygonOffset(factor, ctx->DrawBuffer->_DepthMaxF * bias);
+}
+
+
+static void GLAPIENTRY
+save_PopAttrib(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ (void) alloc_instruction(ctx, OPCODE_POP_ATTRIB, 0);
+ if (ctx->ExecuteFlag) {
+ CALL_PopAttrib(ctx->Exec, ());
+ }
+}
+
+
+static void GLAPIENTRY
+save_PopMatrix(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ (void) alloc_instruction(ctx, OPCODE_POP_MATRIX, 0);
+ if (ctx->ExecuteFlag) {
+ CALL_PopMatrix(ctx->Exec, ());
+ }
+}
+
+
+static void GLAPIENTRY
+save_PopName(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ (void) alloc_instruction(ctx, OPCODE_POP_NAME, 0);
+ if (ctx->ExecuteFlag) {
+ CALL_PopName(ctx->Exec, ());
+ }
+}
+
+
+static void GLAPIENTRY
+save_PrioritizeTextures(GLsizei num, const GLuint * textures,
+ const GLclampf * priorities)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ for (i = 0; i < num; i++) {
+ Node *n;
+ n = alloc_instruction(ctx, OPCODE_PRIORITIZE_TEXTURE, 2);
+ if (n) {
+ n[1].ui = textures[i];
+ n[2].f = priorities[i];
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PrioritizeTextures(ctx->Exec, (num, textures, priorities));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PushAttrib(GLbitfield mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PUSH_ATTRIB, 1);
+ if (n) {
+ n[1].bf = mask;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PushAttrib(ctx->Exec, (mask));
+ }
+}
+
+
+static void GLAPIENTRY
+save_PushMatrix(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ (void) alloc_instruction(ctx, OPCODE_PUSH_MATRIX, 0);
+ if (ctx->ExecuteFlag) {
+ CALL_PushMatrix(ctx->Exec, ());
+ }
+}
+
+
+static void GLAPIENTRY
+save_PushName(GLuint name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PUSH_NAME, 1);
+ if (n) {
+ n[1].ui = name;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PushName(ctx->Exec, (name));
+ }
+}
+
+
+static void GLAPIENTRY
+save_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_RASTER_POS, 4);
+ if (n) {
+ n[1].f = x;
+ n[2].f = y;
+ n[3].f = z;
+ n[4].f = w;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_RasterPos4f(ctx->Exec, (x, y, z, w));
+ }
+}
+
+static void GLAPIENTRY
+save_RasterPos2d(GLdouble x, GLdouble y)
+{
+ save_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos2f(GLfloat x, GLfloat y)
+{
+ save_RasterPos4f(x, y, 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos2i(GLint x, GLint y)
+{
+ save_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos2s(GLshort x, GLshort y)
+{
+ save_RasterPos4f(x, y, 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
+{
+ save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
+{
+ save_RasterPos4f(x, y, z, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos3i(GLint x, GLint y, GLint z)
+{
+ save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos3s(GLshort x, GLshort y, GLshort z)
+{
+ save_RasterPos4f(x, y, z, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
+{
+ save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
+}
+
+static void GLAPIENTRY
+save_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
+{
+ save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
+}
+
+static void GLAPIENTRY
+save_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
+{
+ save_RasterPos4f(x, y, z, w);
+}
+
+static void GLAPIENTRY
+save_RasterPos2dv(const GLdouble * v)
+{
+ save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos2fv(const GLfloat * v)
+{
+ save_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos2iv(const GLint * v)
+{
+ save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos2sv(const GLshort * v)
+{
+ save_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos3dv(const GLdouble * v)
+{
+ save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos3fv(const GLfloat * v)
+{
+ save_RasterPos4f(v[0], v[1], v[2], 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos3iv(const GLint * v)
+{
+ save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos3sv(const GLshort * v)
+{
+ save_RasterPos4f(v[0], v[1], v[2], 1.0F);
+}
+
+static void GLAPIENTRY
+save_RasterPos4dv(const GLdouble * v)
+{
+ save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
+ (GLfloat) v[2], (GLfloat) v[3]);
+}
+
+static void GLAPIENTRY
+save_RasterPos4fv(const GLfloat * v)
+{
+ save_RasterPos4f(v[0], v[1], v[2], v[3]);
+}
+
+static void GLAPIENTRY
+save_RasterPos4iv(const GLint * v)
+{
+ save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
+ (GLfloat) v[2], (GLfloat) v[3]);
+}
+
+static void GLAPIENTRY
+save_RasterPos4sv(const GLshort * v)
+{
+ save_RasterPos4f(v[0], v[1], v[2], v[3]);
+}
+
+
+static void GLAPIENTRY
+save_PassThrough(GLfloat token)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PASSTHROUGH, 1);
+ if (n) {
+ n[1].f = token;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_PassThrough(ctx->Exec, (token));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ReadBuffer(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_READ_BUFFER, 1);
+ if (n) {
+ n[1].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ReadBuffer(ctx->Exec, (mode));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ResetHistogram(GLenum target)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_RESET_HISTOGRAM, 1);
+ if (n) {
+ n[1].e = target;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ResetHistogram(ctx->Exec, (target));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ResetMinmax(GLenum target)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_RESET_MIN_MAX, 1);
+ if (n) {
+ n[1].e = target;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ResetMinmax(ctx->Exec, (target));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_ROTATE, 4);
+ if (n) {
+ n[1].f = angle;
+ n[2].f = x;
+ n[3].f = y;
+ n[4].f = z;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Rotatef(ctx->Exec, (angle, x, y, z));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
+{
+ save_Rotatef((GLfloat) angle, (GLfloat) x, (GLfloat) y, (GLfloat) z);
+}
+
+
+static void GLAPIENTRY
+save_Scalef(GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_SCALE, 3);
+ if (n) {
+ n[1].f = x;
+ n[2].f = y;
+ n[3].f = z;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Scalef(ctx->Exec, (x, y, z));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Scaled(GLdouble x, GLdouble y, GLdouble z)
+{
+ save_Scalef((GLfloat) x, (GLfloat) y, (GLfloat) z);
+}
+
+
+static void GLAPIENTRY
+save_Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_SCISSOR, 4);
+ if (n) {
+ n[1].i = x;
+ n[2].i = y;
+ n[3].i = width;
+ n[4].i = height;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Scissor(ctx->Exec, (x, y, width, height));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ShadeModel(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END(ctx);
+
+ if (ctx->ExecuteFlag) {
+ CALL_ShadeModel(ctx->Exec, (mode));
+ }
+
+ if (ctx->ListState.Current.ShadeModel == mode)
+ return;
+
+ SAVE_FLUSH_VERTICES(ctx);
+
+ /* Only save the value if we know the statechange will take effect:
+ */
+ if (ctx->Driver.CurrentSavePrimitive == PRIM_OUTSIDE_BEGIN_END)
+ ctx->ListState.Current.ShadeModel = mode;
+
+ n = alloc_instruction(ctx, OPCODE_SHADE_MODEL, 1);
+ if (n) {
+ n[1].e = mode;
+ }
+}
+
+
+static void GLAPIENTRY
+save_StencilFunc(GLenum func, GLint ref, GLuint mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC, 3);
+ if (n) {
+ n[1].e = func;
+ n[2].i = ref;
+ n[3].ui = mask;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_StencilFunc(ctx->Exec, (func, ref, mask));
+ }
+}
+
+
+static void GLAPIENTRY
+save_StencilMask(GLuint mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_STENCIL_MASK, 1);
+ if (n) {
+ n[1].ui = mask;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_StencilMask(ctx->Exec, (mask));
+ }
+}
+
+
+static void GLAPIENTRY
+save_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_STENCIL_OP, 3);
+ if (n) {
+ n[1].e = fail;
+ n[2].e = zfail;
+ n[3].e = zpass;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_StencilOp(ctx->Exec, (fail, zfail, zpass));
+ }
+}
+
+
+static void GLAPIENTRY
+save_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC_SEPARATE, 4);
+ if (n) {
+ n[1].e = face;
+ n[2].e = func;
+ n[3].i = ref;
+ n[4].ui = mask;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_StencilFuncSeparate(ctx->Exec, (face, func, ref, mask));
+ }
+}
+
+
+static void GLAPIENTRY
+save_StencilFuncSeparateATI(GLenum frontfunc, GLenum backfunc, GLint ref,
+ GLuint mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ /* GL_FRONT */
+ n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC_SEPARATE, 4);
+ if (n) {
+ n[1].e = GL_FRONT;
+ n[2].e = frontfunc;
+ n[3].i = ref;
+ n[4].ui = mask;
+ }
+ /* GL_BACK */
+ n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC_SEPARATE, 4);
+ if (n) {
+ n[1].e = GL_BACK;
+ n[2].e = backfunc;
+ n[3].i = ref;
+ n[4].ui = mask;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_StencilFuncSeparate(ctx->Exec, (GL_FRONT, frontfunc, ref, mask));
+ CALL_StencilFuncSeparate(ctx->Exec, (GL_BACK, backfunc, ref, mask));
+ }
+}
+
+
+static void GLAPIENTRY
+save_StencilMaskSeparate(GLenum face, GLuint mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_STENCIL_MASK_SEPARATE, 2);
+ if (n) {
+ n[1].e = face;
+ n[2].ui = mask;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_StencilMaskSeparate(ctx->Exec, (face, mask));
+ }
+}
+
+
+static void GLAPIENTRY
+save_StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_STENCIL_OP_SEPARATE, 4);
+ if (n) {
+ n[1].e = face;
+ n[2].e = fail;
+ n[3].e = zfail;
+ n[4].e = zpass;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_StencilOpSeparate(ctx->Exec, (face, fail, zfail, zpass));
+ }
+}
+
+
+static void GLAPIENTRY
+save_TexEnvfv(GLenum target, GLenum pname, const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_TEXENV, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].e = pname;
+ if (pname == GL_TEXTURE_ENV_COLOR) {
+ n[3].f = params[0];
+ n[4].f = params[1];
+ n[5].f = params[2];
+ n[6].f = params[3];
+ }
+ else {
+ n[3].f = params[0];
+ n[4].f = n[5].f = n[6].f = 0.0F;
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexEnvfv(ctx->Exec, (target, pname, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_TexEnvf(GLenum target, GLenum pname, GLfloat param)
+{
+ GLfloat parray[4];
+ parray[0] = (GLfloat) param;
+ parray[1] = parray[2] = parray[3] = 0.0F;
+ save_TexEnvfv(target, pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_TexEnvi(GLenum target, GLenum pname, GLint param)
+{
+ GLfloat p[4];
+ p[0] = (GLfloat) param;
+ p[1] = p[2] = p[3] = 0.0F;
+ save_TexEnvfv(target, pname, p);
+}
+
+
+static void GLAPIENTRY
+save_TexEnviv(GLenum target, GLenum pname, const GLint * param)
+{
+ GLfloat p[4];
+ if (pname == GL_TEXTURE_ENV_COLOR) {
+ p[0] = INT_TO_FLOAT(param[0]);
+ p[1] = INT_TO_FLOAT(param[1]);
+ p[2] = INT_TO_FLOAT(param[2]);
+ p[3] = INT_TO_FLOAT(param[3]);
+ }
+ else {
+ p[0] = (GLfloat) param[0];
+ p[1] = p[2] = p[3] = 0.0F;
+ }
+ save_TexEnvfv(target, pname, p);
+}
+
+
+static void GLAPIENTRY
+save_TexGenfv(GLenum coord, GLenum pname, const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_TEXGEN, 6);
+ if (n) {
+ n[1].e = coord;
+ n[2].e = pname;
+ n[3].f = params[0];
+ n[4].f = params[1];
+ n[5].f = params[2];
+ n[6].f = params[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexGenfv(ctx->Exec, (coord, pname, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_TexGeniv(GLenum coord, GLenum pname, const GLint *params)
+{
+ GLfloat p[4];
+ p[0] = (GLfloat) params[0];
+ p[1] = (GLfloat) params[1];
+ p[2] = (GLfloat) params[2];
+ p[3] = (GLfloat) params[3];
+ save_TexGenfv(coord, pname, p);
+}
+
+
+static void GLAPIENTRY
+save_TexGend(GLenum coord, GLenum pname, GLdouble param)
+{
+ GLfloat parray[4];
+ parray[0] = (GLfloat) param;
+ parray[1] = parray[2] = parray[3] = 0.0F;
+ save_TexGenfv(coord, pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_TexGendv(GLenum coord, GLenum pname, const GLdouble *params)
+{
+ GLfloat p[4];
+ p[0] = (GLfloat) params[0];
+ p[1] = (GLfloat) params[1];
+ p[2] = (GLfloat) params[2];
+ p[3] = (GLfloat) params[3];
+ save_TexGenfv(coord, pname, p);
+}
+
+
+static void GLAPIENTRY
+save_TexGenf(GLenum coord, GLenum pname, GLfloat param)
+{
+ GLfloat parray[4];
+ parray[0] = param;
+ parray[1] = parray[2] = parray[3] = 0.0F;
+ save_TexGenfv(coord, pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_TexGeni(GLenum coord, GLenum pname, GLint param)
+{
+ GLint parray[4];
+ parray[0] = param;
+ parray[1] = parray[2] = parray[3] = 0;
+ save_TexGeniv(coord, pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_TEXPARAMETER, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].e = pname;
+ n[3].f = params[0];
+ n[4].f = params[1];
+ n[5].f = params[2];
+ n[6].f = params[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexParameterfv(ctx->Exec, (target, pname, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_TexParameterf(GLenum target, GLenum pname, GLfloat param)
+{
+ GLfloat parray[4];
+ parray[0] = param;
+ parray[1] = parray[2] = parray[3] = 0.0F;
+ save_TexParameterfv(target, pname, parray);
+}
+
+
+static void GLAPIENTRY
+save_TexParameteri(GLenum target, GLenum pname, GLint param)
+{
+ GLfloat fparam[4];
+ fparam[0] = (GLfloat) param;
+ fparam[1] = fparam[2] = fparam[3] = 0.0F;
+ save_TexParameterfv(target, pname, fparam);
+}
+
+
+static void GLAPIENTRY
+save_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
+{
+ GLfloat fparam[4];
+ fparam[0] = (GLfloat) params[0];
+ fparam[1] = fparam[2] = fparam[3] = 0.0F;
+ save_TexParameterfv(target, pname, fparam);
+}
+
+
+static void GLAPIENTRY
+save_TexImage1D(GLenum target,
+ GLint level, GLint components,
+ GLsizei width, GLint border,
+ GLenum format, GLenum type, const GLvoid * pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (target == GL_PROXY_TEXTURE_1D) {
+ /* don't compile, execute immediately */
+ CALL_TexImage1D(ctx->Exec, (target, level, components, width,
+ border, format, type, pixels));
+ }
+ else {
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_TEX_IMAGE1D, 8);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = components;
+ n[4].i = (GLint) width;
+ n[5].i = border;
+ n[6].e = format;
+ n[7].e = type;
+ n[8].data = unpack_image(ctx, 1, width, 1, 1, format, type,
+ pixels, &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexImage1D(ctx->Exec, (target, level, components, width,
+ border, format, type, pixels));
+ }
+ }
+}
+
+
+static void GLAPIENTRY
+save_TexImage2D(GLenum target,
+ GLint level, GLint components,
+ GLsizei width, GLsizei height, GLint border,
+ GLenum format, GLenum type, const GLvoid * pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (target == GL_PROXY_TEXTURE_2D) {
+ /* don't compile, execute immediately */
+ CALL_TexImage2D(ctx->Exec, (target, level, components, width,
+ height, border, format, type, pixels));
+ }
+ else {
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_TEX_IMAGE2D, 9);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = components;
+ n[4].i = (GLint) width;
+ n[5].i = (GLint) height;
+ n[6].i = border;
+ n[7].e = format;
+ n[8].e = type;
+ n[9].data = unpack_image(ctx, 2, width, height, 1, format, type,
+ pixels, &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexImage2D(ctx->Exec, (target, level, components, width,
+ height, border, format, type, pixels));
+ }
+ }
+}
+
+
+static void GLAPIENTRY
+save_TexImage3D(GLenum target,
+ GLint level, GLint internalFormat,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLint border,
+ GLenum format, GLenum type, const GLvoid * pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (target == GL_PROXY_TEXTURE_3D) {
+ /* don't compile, execute immediately */
+ CALL_TexImage3D(ctx->Exec, (target, level, internalFormat, width,
+ height, depth, border, format, type,
+ pixels));
+ }
+ else {
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_TEX_IMAGE3D, 10);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = (GLint) internalFormat;
+ n[4].i = (GLint) width;
+ n[5].i = (GLint) height;
+ n[6].i = (GLint) depth;
+ n[7].i = border;
+ n[8].e = format;
+ n[9].e = type;
+ n[10].data = unpack_image(ctx, 3, width, height, depth, format, type,
+ pixels, &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexImage3D(ctx->Exec, (target, level, internalFormat, width,
+ height, depth, border, format, type,
+ pixels));
+ }
+ }
+}
+
+
+static void GLAPIENTRY
+save_TexSubImage1D(GLenum target, GLint level, GLint xoffset,
+ GLsizei width, GLenum format, GLenum type,
+ const GLvoid * pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_TEX_SUB_IMAGE1D, 7);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = xoffset;
+ n[4].i = (GLint) width;
+ n[5].e = format;
+ n[6].e = type;
+ n[7].data = unpack_image(ctx, 1, width, 1, 1, format, type,
+ pixels, &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexSubImage1D(ctx->Exec, (target, level, xoffset, width,
+ format, type, pixels));
+ }
+}
+
+
+static void GLAPIENTRY
+save_TexSubImage2D(GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type, const GLvoid * pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_TEX_SUB_IMAGE2D, 9);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = xoffset;
+ n[4].i = yoffset;
+ n[5].i = (GLint) width;
+ n[6].i = (GLint) height;
+ n[7].e = format;
+ n[8].e = type;
+ n[9].data = unpack_image(ctx, 2, width, height, 1, format, type,
+ pixels, &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexSubImage2D(ctx->Exec, (target, level, xoffset, yoffset,
+ width, height, format, type, pixels));
+ }
+}
+
+
+static void GLAPIENTRY
+save_TexSubImage3D(GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, const GLvoid * pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_TEX_SUB_IMAGE3D, 11);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = xoffset;
+ n[4].i = yoffset;
+ n[5].i = zoffset;
+ n[6].i = (GLint) width;
+ n[7].i = (GLint) height;
+ n[8].i = (GLint) depth;
+ n[9].e = format;
+ n[10].e = type;
+ n[11].data = unpack_image(ctx, 3, width, height, depth, format, type,
+ pixels, &ctx->Unpack);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexSubImage3D(ctx->Exec, (target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth, format, type,
+ pixels));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Translatef(GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_TRANSLATE, 3);
+ if (n) {
+ n[1].f = x;
+ n[2].f = y;
+ n[3].f = z;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Translatef(ctx->Exec, (x, y, z));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Translated(GLdouble x, GLdouble y, GLdouble z)
+{
+ save_Translatef((GLfloat) x, (GLfloat) y, (GLfloat) z);
+}
+
+
+
+static void GLAPIENTRY
+save_Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_VIEWPORT, 4);
+ if (n) {
+ n[1].i = x;
+ n[2].i = y;
+ n[3].i = (GLint) width;
+ n[4].i = (GLint) height;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Viewport(ctx->Exec, (x, y, width, height));
+ }
+}
+
+
+static void GLAPIENTRY
+save_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_WINDOW_POS, 4);
+ if (n) {
+ n[1].f = x;
+ n[2].f = y;
+ n[3].f = z;
+ n[4].f = w;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_WindowPos4fMESA(ctx->Exec, (x, y, z, w));
+ }
+}
+
+static void GLAPIENTRY
+save_WindowPos2dMESA(GLdouble x, GLdouble y)
+{
+ save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos2fMESA(GLfloat x, GLfloat y)
+{
+ save_WindowPos4fMESA(x, y, 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos2iMESA(GLint x, GLint y)
+{
+ save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos2sMESA(GLshort x, GLshort y)
+{
+ save_WindowPos4fMESA(x, y, 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
+{
+ save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
+{
+ save_WindowPos4fMESA(x, y, z, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos3iMESA(GLint x, GLint y, GLint z)
+{
+ save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
+{
+ save_WindowPos4fMESA(x, y, z, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
+{
+ save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
+}
+
+static void GLAPIENTRY
+save_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
+{
+ save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
+}
+
+static void GLAPIENTRY
+save_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
+{
+ save_WindowPos4fMESA(x, y, z, w);
+}
+
+static void GLAPIENTRY
+save_WindowPos2dvMESA(const GLdouble * v)
+{
+ save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos2fvMESA(const GLfloat * v)
+{
+ save_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos2ivMESA(const GLint * v)
+{
+ save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos2svMESA(const GLshort * v)
+{
+ save_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos3dvMESA(const GLdouble * v)
+{
+ save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos3fvMESA(const GLfloat * v)
+{
+ save_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos3ivMESA(const GLint * v)
+{
+ save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos3svMESA(const GLshort * v)
+{
+ save_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
+}
+
+static void GLAPIENTRY
+save_WindowPos4dvMESA(const GLdouble * v)
+{
+ save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1],
+ (GLfloat) v[2], (GLfloat) v[3]);
+}
+
+static void GLAPIENTRY
+save_WindowPos4fvMESA(const GLfloat * v)
+{
+ save_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
+}
+
+static void GLAPIENTRY
+save_WindowPos4ivMESA(const GLint * v)
+{
+ save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1],
+ (GLfloat) v[2], (GLfloat) v[3]);
+}
+
+static void GLAPIENTRY
+save_WindowPos4svMESA(const GLshort * v)
+{
+ save_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
+}
+
+
+
+/* GL_ARB_multitexture */
+static void GLAPIENTRY
+save_ActiveTextureARB(GLenum target)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_ACTIVE_TEXTURE, 1);
+ if (n) {
+ n[1].e = target;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ActiveTextureARB(ctx->Exec, (target));
+ }
+}
+
+
+/* GL_ARB_transpose_matrix */
+
+static void GLAPIENTRY
+save_LoadTransposeMatrixdARB(const GLdouble m[16])
+{
+ GLfloat tm[16];
+ _math_transposefd(tm, m);
+ save_LoadMatrixf(tm);
+}
+
+
+static void GLAPIENTRY
+save_LoadTransposeMatrixfARB(const GLfloat m[16])
+{
+ GLfloat tm[16];
+ _math_transposef(tm, m);
+ save_LoadMatrixf(tm);
+}
+
+
+static void GLAPIENTRY
+save_MultTransposeMatrixdARB(const GLdouble m[16])
+{
+ GLfloat tm[16];
+ _math_transposefd(tm, m);
+ save_MultMatrixf(tm);
+}
+
+
+static void GLAPIENTRY
+save_MultTransposeMatrixfARB(const GLfloat m[16])
+{
+ GLfloat tm[16];
+ _math_transposef(tm, m);
+ save_MultMatrixf(tm);
+}
+
+
+/* GL_ARB_texture_compression */
+static void GLAPIENTRY
+save_CompressedTexImage1DARB(GLenum target, GLint level,
+ GLenum internalFormat, GLsizei width,
+ GLint border, GLsizei imageSize,
+ const GLvoid * data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (target == GL_PROXY_TEXTURE_1D) {
+ /* don't compile, execute immediately */
+ CALL_CompressedTexImage1DARB(ctx->Exec, (target, level, internalFormat,
+ width, border, imageSize,
+ data));
+ }
+ else {
+ Node *n;
+ GLvoid *image;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ /* make copy of image */
+ image = malloc(imageSize);
+ if (!image) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB");
+ return;
+ }
+ memcpy(image, data, imageSize);
+ n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_1D, 7);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].e = internalFormat;
+ n[4].i = (GLint) width;
+ n[5].i = border;
+ n[6].i = imageSize;
+ n[7].data = image;
+ }
+ else if (image) {
+ free(image);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CompressedTexImage1DARB(ctx->Exec,
+ (target, level, internalFormat, width,
+ border, imageSize, data));
+ }
+ }
+}
+
+
+static void GLAPIENTRY
+save_CompressedTexImage2DARB(GLenum target, GLint level,
+ GLenum internalFormat, GLsizei width,
+ GLsizei height, GLint border, GLsizei imageSize,
+ const GLvoid * data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (target == GL_PROXY_TEXTURE_2D) {
+ /* don't compile, execute immediately */
+ CALL_CompressedTexImage2DARB(ctx->Exec, (target, level, internalFormat,
+ width, height, border,
+ imageSize, data));
+ }
+ else {
+ Node *n;
+ GLvoid *image;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ /* make copy of image */
+ image = malloc(imageSize);
+ if (!image) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
+ return;
+ }
+ memcpy(image, data, imageSize);
+ n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_2D, 8);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].e = internalFormat;
+ n[4].i = (GLint) width;
+ n[5].i = (GLint) height;
+ n[6].i = border;
+ n[7].i = imageSize;
+ n[8].data = image;
+ }
+ else if (image) {
+ free(image);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CompressedTexImage2DARB(ctx->Exec,
+ (target, level, internalFormat, width,
+ height, border, imageSize, data));
+ }
+ }
+}
+
+
+static void GLAPIENTRY
+save_CompressedTexImage3DARB(GLenum target, GLint level,
+ GLenum internalFormat, GLsizei width,
+ GLsizei height, GLsizei depth, GLint border,
+ GLsizei imageSize, const GLvoid * data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (target == GL_PROXY_TEXTURE_3D) {
+ /* don't compile, execute immediately */
+ CALL_CompressedTexImage3DARB(ctx->Exec, (target, level, internalFormat,
+ width, height, depth, border,
+ imageSize, data));
+ }
+ else {
+ Node *n;
+ GLvoid *image;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ /* make copy of image */
+ image = malloc(imageSize);
+ if (!image) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB");
+ return;
+ }
+ memcpy(image, data, imageSize);
+ n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_3D, 9);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].e = internalFormat;
+ n[4].i = (GLint) width;
+ n[5].i = (GLint) height;
+ n[6].i = (GLint) depth;
+ n[7].i = border;
+ n[8].i = imageSize;
+ n[9].data = image;
+ }
+ else if (image) {
+ free(image);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CompressedTexImage3DARB(ctx->Exec,
+ (target, level, internalFormat, width,
+ height, depth, border, imageSize,
+ data));
+ }
+ }
+}
+
+
+static void GLAPIENTRY
+save_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
+ GLsizei width, GLenum format,
+ GLsizei imageSize, const GLvoid * data)
+{
+ Node *n;
+ GLvoid *image;
+
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ /* make copy of image */
+ image = malloc(imageSize);
+ if (!image) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage1DARB");
+ return;
+ }
+ memcpy(image, data, imageSize);
+ n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D, 7);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = xoffset;
+ n[4].i = (GLint) width;
+ n[5].e = format;
+ n[6].i = imageSize;
+ n[7].data = image;
+ }
+ else if (image) {
+ free(image);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CompressedTexSubImage1DARB(ctx->Exec, (target, level, xoffset,
+ width, format, imageSize,
+ data));
+ }
+}
+
+
+static void GLAPIENTRY
+save_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
+ GLint yoffset, GLsizei width, GLsizei height,
+ GLenum format, GLsizei imageSize,
+ const GLvoid * data)
+{
+ Node *n;
+ GLvoid *image;
+
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ /* make copy of image */
+ image = malloc(imageSize);
+ if (!image) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage2DARB");
+ return;
+ }
+ memcpy(image, data, imageSize);
+ n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D, 9);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = xoffset;
+ n[4].i = yoffset;
+ n[5].i = (GLint) width;
+ n[6].i = (GLint) height;
+ n[7].e = format;
+ n[8].i = imageSize;
+ n[9].data = image;
+ }
+ else if (image) {
+ free(image);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CompressedTexSubImage2DARB(ctx->Exec,
+ (target, level, xoffset, yoffset, width,
+ height, format, imageSize, data));
+ }
+}
+
+
+static void GLAPIENTRY
+save_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
+ GLint yoffset, GLint zoffset, GLsizei width,
+ GLsizei height, GLsizei depth, GLenum format,
+ GLsizei imageSize, const GLvoid * data)
+{
+ Node *n;
+ GLvoid *image;
+
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ /* make copy of image */
+ image = malloc(imageSize);
+ if (!image) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage3DARB");
+ return;
+ }
+ memcpy(image, data, imageSize);
+ n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D, 11);
+ if (n) {
+ n[1].e = target;
+ n[2].i = level;
+ n[3].i = xoffset;
+ n[4].i = yoffset;
+ n[5].i = zoffset;
+ n[6].i = (GLint) width;
+ n[7].i = (GLint) height;
+ n[8].i = (GLint) depth;
+ n[9].e = format;
+ n[10].i = imageSize;
+ n[11].data = image;
+ }
+ else if (image) {
+ free(image);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_CompressedTexSubImage3DARB(ctx->Exec,
+ (target, level, xoffset, yoffset,
+ zoffset, width, height, depth, format,
+ imageSize, data));
+ }
+}
+
+
+/* GL_ARB_multisample */
+static void GLAPIENTRY
+save_SampleCoverageARB(GLclampf value, GLboolean invert)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_SAMPLE_COVERAGE, 2);
+ if (n) {
+ n[1].f = value;
+ n[2].b = invert;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_SampleCoverageARB(ctx->Exec, (value, invert));
+ }
+}
+
+
+/*
+ * GL_NV_vertex_program
+ */
+#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+static void GLAPIENTRY
+save_BindProgramNV(GLenum target, GLuint id)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BIND_PROGRAM_NV, 2);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = id;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BindProgramNV(ctx->Exec, (target, id));
+ }
+}
+
+static void GLAPIENTRY
+save_ProgramEnvParameter4fARB(GLenum target, GLuint index,
+ GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PROGRAM_ENV_PARAMETER_ARB, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = index;
+ n[3].f = x;
+ n[4].f = y;
+ n[5].f = z;
+ n[6].f = w;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ProgramEnvParameter4fARB(ctx->Exec, (target, index, x, y, z, w));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
+ const GLfloat *params)
+{
+ save_ProgramEnvParameter4fARB(target, index, params[0], params[1],
+ params[2], params[3]);
+}
+
+
+static void GLAPIENTRY
+save_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
+ const GLfloat * params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (count > 0) {
+ GLint i;
+ const GLfloat * p = params;
+
+ for (i = 0 ; i < count ; i++) {
+ n = alloc_instruction(ctx, OPCODE_PROGRAM_ENV_PARAMETER_ARB, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = index;
+ n[3].f = p[0];
+ n[4].f = p[1];
+ n[5].f = p[2];
+ n[6].f = p[3];
+ p += 4;
+ }
+ }
+ }
+
+ if (ctx->ExecuteFlag) {
+ CALL_ProgramEnvParameters4fvEXT(ctx->Exec, (target, index, count, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ProgramEnvParameter4dARB(GLenum target, GLuint index,
+ GLdouble x, GLdouble y, GLdouble z, GLdouble w)
+{
+ save_ProgramEnvParameter4fARB(target, index,
+ (GLfloat) x,
+ (GLfloat) y, (GLfloat) z, (GLfloat) w);
+}
+
+
+static void GLAPIENTRY
+save_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
+ const GLdouble *params)
+{
+ save_ProgramEnvParameter4fARB(target, index,
+ (GLfloat) params[0],
+ (GLfloat) params[1],
+ (GLfloat) params[2], (GLfloat) params[3]);
+}
+
+#endif /* FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program || FEATURE_NV_vertex_program */
+
+#if FEATURE_NV_vertex_program
+static void GLAPIENTRY
+save_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_EXECUTE_PROGRAM_NV, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = id;
+ n[3].f = params[0];
+ n[4].f = params[1];
+ n[5].f = params[2];
+ n[6].f = params[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ExecuteProgramNV(ctx->Exec, (target, id, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ProgramParameters4dvNV(GLenum target, GLuint index,
+ GLsizei num, const GLdouble *params)
+{
+ GLint i;
+ for (i = 0; i < num; i++) {
+ save_ProgramEnvParameter4dvARB(target, index + i, params + 4 * i);
+ }
+}
+
+
+static void GLAPIENTRY
+save_ProgramParameters4fvNV(GLenum target, GLuint index,
+ GLsizei num, const GLfloat *params)
+{
+ GLint i;
+ for (i = 0; i < num; i++) {
+ save_ProgramEnvParameter4fvARB(target, index + i, params + 4 * i);
+ }
+}
+
+
+static void GLAPIENTRY
+save_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
+ const GLubyte * program)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_LOAD_PROGRAM_NV, 4);
+ if (n) {
+ GLubyte *programCopy = (GLubyte *) malloc(len);
+ if (!programCopy) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
+ return;
+ }
+ memcpy(programCopy, program, len);
+ n[1].e = target;
+ n[2].ui = id;
+ n[3].i = len;
+ n[4].data = programCopy;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_LoadProgramNV(ctx->Exec, (target, id, len, program));
+ }
+}
+
+
+static void GLAPIENTRY
+save_RequestResidentProgramsNV(GLsizei num, const GLuint * ids)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_TRACK_MATRIX_NV, 2);
+ if (n) {
+ GLuint *idCopy = (GLuint *) malloc(num * sizeof(GLuint));
+ if (!idCopy) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glRequestResidentProgramsNV");
+ return;
+ }
+ memcpy(idCopy, ids, num * sizeof(GLuint));
+ n[1].i = num;
+ n[2].data = idCopy;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_RequestResidentProgramsNV(ctx->Exec, (num, ids));
+ }
+}
+
+
+static void GLAPIENTRY
+save_TrackMatrixNV(GLenum target, GLuint address,
+ GLenum matrix, GLenum transform)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_TRACK_MATRIX_NV, 4);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = address;
+ n[3].e = matrix;
+ n[4].e = transform;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TrackMatrixNV(ctx->Exec, (target, address, matrix, transform));
+ }
+}
+#endif /* FEATURE_NV_vertex_program */
+
+
+/*
+ * GL_NV_fragment_program
+ */
+#if FEATURE_NV_fragment_program
+static void GLAPIENTRY
+save_ProgramLocalParameter4fARB(GLenum target, GLuint index,
+ GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = index;
+ n[3].f = x;
+ n[4].f = y;
+ n[5].f = z;
+ n[6].f = w;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ProgramLocalParameter4fARB(ctx->Exec, (target, index, x, y, z, w));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
+ const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = index;
+ n[3].f = params[0];
+ n[4].f = params[1];
+ n[5].f = params[2];
+ n[6].f = params[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ProgramLocalParameter4fvARB(ctx->Exec, (target, index, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
+ const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (count > 0) {
+ GLint i;
+ const GLfloat * p = params;
+
+ for (i = 0 ; i < count ; i++) {
+ n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = index;
+ n[3].f = p[0];
+ n[4].f = p[1];
+ n[5].f = p[2];
+ n[6].f = p[3];
+ p += 4;
+ }
+ }
+ }
+
+ if (ctx->ExecuteFlag) {
+ CALL_ProgramLocalParameters4fvEXT(ctx->Exec, (target, index, count, params));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ProgramLocalParameter4dARB(GLenum target, GLuint index,
+ GLdouble x, GLdouble y,
+ GLdouble z, GLdouble w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = index;
+ n[3].f = (GLfloat) x;
+ n[4].f = (GLfloat) y;
+ n[5].f = (GLfloat) z;
+ n[6].f = (GLfloat) w;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ProgramLocalParameter4dARB(ctx->Exec, (target, index, x, y, z, w));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
+ const GLdouble *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = index;
+ n[3].f = (GLfloat) params[0];
+ n[4].f = (GLfloat) params[1];
+ n[5].f = (GLfloat) params[2];
+ n[6].f = (GLfloat) params[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ProgramLocalParameter4dvARB(ctx->Exec, (target, index, params));
+ }
+}
+
+static void GLAPIENTRY
+save_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte * name,
+ GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_PROGRAM_NAMED_PARAMETER_NV, 6);
+ if (n) {
+ GLubyte *nameCopy = (GLubyte *) malloc(len);
+ if (!nameCopy) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramNamedParameter4fNV");
+ return;
+ }
+ memcpy(nameCopy, name, len);
+ n[1].ui = id;
+ n[2].i = len;
+ n[3].data = nameCopy;
+ n[4].f = x;
+ n[5].f = y;
+ n[6].f = z;
+ n[7].f = w;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ProgramNamedParameter4fNV(ctx->Exec, (id, len, name, x, y, z, w));
+ }
+}
+
+
+static void GLAPIENTRY
+save_ProgramNamedParameter4fvNV(GLuint id, GLsizei len, const GLubyte * name,
+ const float v[])
+{
+ save_ProgramNamedParameter4fNV(id, len, name, v[0], v[1], v[2], v[3]);
+}
+
+
+static void GLAPIENTRY
+save_ProgramNamedParameter4dNV(GLuint id, GLsizei len, const GLubyte * name,
+ GLdouble x, GLdouble y, GLdouble z, GLdouble w)
+{
+ save_ProgramNamedParameter4fNV(id, len, name, (GLfloat) x, (GLfloat) y,
+ (GLfloat) z, (GLfloat) w);
+}
+
+
+static void GLAPIENTRY
+save_ProgramNamedParameter4dvNV(GLuint id, GLsizei len, const GLubyte * name,
+ const double v[])
+{
+ save_ProgramNamedParameter4fNV(id, len, name, (GLfloat) v[0],
+ (GLfloat) v[1], (GLfloat) v[2],
+ (GLfloat) v[3]);
+}
+
+#endif /* FEATURE_NV_fragment_program */
+
+
+
+/* GL_EXT_stencil_two_side */
+static void GLAPIENTRY
+save_ActiveStencilFaceEXT(GLenum face)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_ACTIVE_STENCIL_FACE_EXT, 1);
+ if (n) {
+ n[1].e = face;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ActiveStencilFaceEXT(ctx->Exec, (face));
+ }
+}
+
+
+/* GL_EXT_depth_bounds_test */
+static void GLAPIENTRY
+save_DepthBoundsEXT(GLclampd zmin, GLclampd zmax)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_DEPTH_BOUNDS_EXT, 2);
+ if (n) {
+ n[1].f = (GLfloat) zmin;
+ n[2].f = (GLfloat) zmax;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_DepthBoundsEXT(ctx->Exec, (zmin, zmax));
+ }
+}
+
+
+
+#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+
+static void GLAPIENTRY
+save_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
+ const GLvoid * string)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_PROGRAM_STRING_ARB, 4);
+ if (n) {
+ GLubyte *programCopy = (GLubyte *) malloc(len);
+ if (!programCopy) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
+ return;
+ }
+ memcpy(programCopy, string, len);
+ n[1].e = target;
+ n[2].e = format;
+ n[3].i = len;
+ n[4].data = programCopy;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ProgramStringARB(ctx->Exec, (target, format, len, string));
+ }
+}
+
+#endif /* FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program */
+
+
+#if FEATURE_queryobj
+
+static void GLAPIENTRY
+save_BeginQueryARB(GLenum target, GLuint id)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BEGIN_QUERY_ARB, 2);
+ if (n) {
+ n[1].e = target;
+ n[2].ui = id;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BeginQueryARB(ctx->Exec, (target, id));
+ }
+}
+
+
+static void GLAPIENTRY
+save_EndQueryARB(GLenum target)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_END_QUERY_ARB, 1);
+ if (n) {
+ n[1].e = target;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_EndQueryARB(ctx->Exec, (target));
+ }
+}
+
+#endif /* FEATURE_queryobj */
+
+
+static void GLAPIENTRY
+save_DrawBuffersARB(GLsizei count, const GLenum * buffers)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_DRAW_BUFFERS_ARB, 1 + MAX_DRAW_BUFFERS);
+ if (n) {
+ GLint i;
+ n[1].i = count;
+ if (count > MAX_DRAW_BUFFERS)
+ count = MAX_DRAW_BUFFERS;
+ for (i = 0; i < count; i++) {
+ n[2 + i].e = buffers[i];
+ }
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_DrawBuffersARB(ctx->Exec, (count, buffers));
+ }
+}
+
+static void GLAPIENTRY
+save_TexBumpParameterfvATI(GLenum pname, const GLfloat *param)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ n = alloc_instruction(ctx, OPCODE_TEX_BUMP_PARAMETER_ATI, 5);
+ if (n) {
+ n[1].ui = pname;
+ n[2].f = param[0];
+ n[3].f = param[1];
+ n[4].f = param[2];
+ n[5].f = param[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexBumpParameterfvATI(ctx->Exec, (pname, param));
+ }
+}
+
+static void GLAPIENTRY
+save_TexBumpParameterivATI(GLenum pname, const GLint *param)
+{
+ GLfloat p[4];
+ p[0] = INT_TO_FLOAT(param[0]);
+ p[1] = INT_TO_FLOAT(param[1]);
+ p[2] = INT_TO_FLOAT(param[2]);
+ p[3] = INT_TO_FLOAT(param[3]);
+ save_TexBumpParameterfvATI(pname, p);
+}
+
+#if FEATURE_ATI_fragment_shader
+static void GLAPIENTRY
+save_BindFragmentShaderATI(GLuint id)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ n = alloc_instruction(ctx, OPCODE_BIND_FRAGMENT_SHADER_ATI, 1);
+ if (n) {
+ n[1].ui = id;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BindFragmentShaderATI(ctx->Exec, (id));
+ }
+}
+
+static void GLAPIENTRY
+save_SetFragmentShaderConstantATI(GLuint dst, const GLfloat *value)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ n = alloc_instruction(ctx, OPCODE_SET_FRAGMENT_SHADER_CONSTANTS_ATI, 5);
+ if (n) {
+ n[1].ui = dst;
+ n[2].f = value[0];
+ n[3].f = value[1];
+ n[4].f = value[2];
+ n[5].f = value[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_SetFragmentShaderConstantATI(ctx->Exec, (dst, value));
+ }
+}
+#endif
+
+static void
+save_Attr1fNV(GLenum attr, GLfloat x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_ATTR_1F_NV, 2);
+ if (n) {
+ n[1].e = attr;
+ n[2].f = x;
+ }
+
+ ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
+ ctx->ListState.ActiveAttribSize[attr] = 1;
+ ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, 0, 0, 1);
+
+ if (ctx->ExecuteFlag) {
+ CALL_VertexAttrib1fNV(ctx->Exec, (attr, x));
+ }
+}
+
+static void
+save_Attr2fNV(GLenum attr, GLfloat x, GLfloat y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_ATTR_2F_NV, 3);
+ if (n) {
+ n[1].e = attr;
+ n[2].f = x;
+ n[3].f = y;
+ }
+
+ ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
+ ctx->ListState.ActiveAttribSize[attr] = 2;
+ ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, 0, 1);
+
+ if (ctx->ExecuteFlag) {
+ CALL_VertexAttrib2fNV(ctx->Exec, (attr, x, y));
+ }
+}
+
+static void
+save_Attr3fNV(GLenum attr, GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_ATTR_3F_NV, 4);
+ if (n) {
+ n[1].e = attr;
+ n[2].f = x;
+ n[3].f = y;
+ n[4].f = z;
+ }
+
+ ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
+ ctx->ListState.ActiveAttribSize[attr] = 3;
+ ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, 1);
+
+ if (ctx->ExecuteFlag) {
+ CALL_VertexAttrib3fNV(ctx->Exec, (attr, x, y, z));
+ }
+}
+
+static void
+save_Attr4fNV(GLenum attr, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_ATTR_4F_NV, 5);
+ if (n) {
+ n[1].e = attr;
+ n[2].f = x;
+ n[3].f = y;
+ n[4].f = z;
+ n[5].f = w;
+ }
+
+ ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
+ ctx->ListState.ActiveAttribSize[attr] = 4;
+ ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, w);
+
+ if (ctx->ExecuteFlag) {
+ CALL_VertexAttrib4fNV(ctx->Exec, (attr, x, y, z, w));
+ }
+}
+
+
+static void
+save_Attr1fARB(GLenum attr, GLfloat x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_ATTR_1F_ARB, 2);
+ if (n) {
+ n[1].e = attr;
+ n[2].f = x;
+ }
+
+ ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
+ ctx->ListState.ActiveAttribSize[attr] = 1;
+ ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, 0, 0, 1);
+
+ if (ctx->ExecuteFlag) {
+ CALL_VertexAttrib1fARB(ctx->Exec, (attr, x));
+ }
+}
+
+static void
+save_Attr2fARB(GLenum attr, GLfloat x, GLfloat y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_ATTR_2F_ARB, 3);
+ if (n) {
+ n[1].e = attr;
+ n[2].f = x;
+ n[3].f = y;
+ }
+
+ ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
+ ctx->ListState.ActiveAttribSize[attr] = 2;
+ ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, 0, 1);
+
+ if (ctx->ExecuteFlag) {
+ CALL_VertexAttrib2fARB(ctx->Exec, (attr, x, y));
+ }
+}
+
+static void
+save_Attr3fARB(GLenum attr, GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_ATTR_3F_ARB, 4);
+ if (n) {
+ n[1].e = attr;
+ n[2].f = x;
+ n[3].f = y;
+ n[4].f = z;
+ }
+
+ ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
+ ctx->ListState.ActiveAttribSize[attr] = 3;
+ ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, 1);
+
+ if (ctx->ExecuteFlag) {
+ CALL_VertexAttrib3fARB(ctx->Exec, (attr, x, y, z));
+ }
+}
+
+static void
+save_Attr4fARB(GLenum attr, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_ATTR_4F_ARB, 5);
+ if (n) {
+ n[1].e = attr;
+ n[2].f = x;
+ n[3].f = y;
+ n[4].f = z;
+ n[5].f = w;
+ }
+
+ ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
+ ctx->ListState.ActiveAttribSize[attr] = 4;
+ ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, w);
+
+ if (ctx->ExecuteFlag) {
+ CALL_VertexAttrib4fARB(ctx->Exec, (attr, x, y, z, w));
+ }
+}
+
+
+static void GLAPIENTRY
+save_EvalCoord1f(GLfloat x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_EVAL_C1, 1);
+ if (n) {
+ n[1].f = x;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_EvalCoord1f(ctx->Exec, (x));
+ }
+}
+
+static void GLAPIENTRY
+save_EvalCoord1fv(const GLfloat * v)
+{
+ save_EvalCoord1f(v[0]);
+}
+
+static void GLAPIENTRY
+save_EvalCoord2f(GLfloat x, GLfloat y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_EVAL_C2, 2);
+ if (n) {
+ n[1].f = x;
+ n[2].f = y;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_EvalCoord2f(ctx->Exec, (x, y));
+ }
+}
+
+static void GLAPIENTRY
+save_EvalCoord2fv(const GLfloat * v)
+{
+ save_EvalCoord2f(v[0], v[1]);
+}
+
+
+static void GLAPIENTRY
+save_EvalPoint1(GLint x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_EVAL_P1, 1);
+ if (n) {
+ n[1].i = x;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_EvalPoint1(ctx->Exec, (x));
+ }
+}
+
+static void GLAPIENTRY
+save_EvalPoint2(GLint x, GLint y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_EVAL_P2, 2);
+ if (n) {
+ n[1].i = x;
+ n[2].i = y;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_EvalPoint2(ctx->Exec, (x, y));
+ }
+}
+
+static void GLAPIENTRY
+save_Indexf(GLfloat x)
+{
+ save_Attr1fNV(VERT_ATTRIB_COLOR_INDEX, x);
+}
+
+static void GLAPIENTRY
+save_Indexfv(const GLfloat * v)
+{
+ save_Attr1fNV(VERT_ATTRIB_COLOR_INDEX, v[0]);
+}
+
+static void GLAPIENTRY
+save_EdgeFlag(GLboolean x)
+{
+ save_Attr1fNV(VERT_ATTRIB_EDGEFLAG, x ? (GLfloat)1.0 : (GLfloat)0.0);
+}
+
+static INLINE GLboolean compare4fv( const GLfloat *a,
+ const GLfloat *b,
+ GLuint count )
+{
+ return memcmp( a, b, count * sizeof(GLfloat) ) == 0;
+}
+
+
+static void GLAPIENTRY
+save_Materialfv(GLenum face, GLenum pname, const GLfloat * param)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ int args, i;
+ GLuint bitmask;
+
+ switch (face) {
+ case GL_BACK:
+ case GL_FRONT:
+ case GL_FRONT_AND_BACK:
+ break;
+ default:
+ _mesa_compile_error(ctx, GL_INVALID_ENUM, "material(face)");
+ return;
+ }
+
+ switch (pname) {
+ case GL_EMISSION:
+ case GL_AMBIENT:
+ case GL_DIFFUSE:
+ case GL_SPECULAR:
+ case GL_AMBIENT_AND_DIFFUSE:
+ args = 4;
+ break;
+ case GL_SHININESS:
+ args = 1;
+ break;
+ case GL_COLOR_INDEXES:
+ args = 3;
+ break;
+ default:
+ _mesa_compile_error(ctx, GL_INVALID_ENUM, "material(pname)");
+ return;
+ }
+
+ if (ctx->ExecuteFlag) {
+ CALL_Materialfv(ctx->Exec, (face, pname, param));
+ }
+
+ bitmask = _mesa_material_bitmask(ctx, face, pname, ~0, NULL);
+
+ /* Try to eliminate redundant statechanges. Because it is legal to
+ * call glMaterial even inside begin/end calls, don't need to worry
+ * about ctx->Driver.CurrentSavePrimitive here.
+ */
+ for (i = 0; i < MAT_ATTRIB_MAX; i++) {
+ if (bitmask & (1 << i)) {
+ if (ctx->ListState.ActiveMaterialSize[i] == args &&
+ compare4fv(ctx->ListState.CurrentMaterial[i], param, args)) {
+ bitmask &= ~(1 << i);
+ }
+ else {
+ ctx->ListState.ActiveMaterialSize[i] = args;
+ COPY_SZ_4V(ctx->ListState.CurrentMaterial[i], args, param);
+ }
+ }
+ }
+
+ /* If this call has effect, return early:
+ */
+ if (bitmask == 0)
+ return;
+
+ SAVE_FLUSH_VERTICES(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_MATERIAL, 6);
+ if (n) {
+ n[1].e = face;
+ n[2].e = pname;
+ for (i = 0; i < args; i++)
+ n[3 + i].f = param[i];
+ }
+}
+
+static void GLAPIENTRY
+save_Begin(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ GLboolean error = GL_FALSE;
+
+ if ( /*mode < GL_POINTS || */ mode > GL_POLYGON) {
+ _mesa_compile_error(ctx, GL_INVALID_ENUM, "Begin (mode)");
+ error = GL_TRUE;
+ }
+ else if (ctx->Driver.CurrentSavePrimitive == PRIM_UNKNOWN) {
+ /* Typically the first begin. This may raise an error on
+ * playback, depending on whether CallList is issued from inside
+ * a begin/end or not.
+ */
+ ctx->Driver.CurrentSavePrimitive = PRIM_INSIDE_UNKNOWN_PRIM;
+ }
+ else if (ctx->Driver.CurrentSavePrimitive == PRIM_OUTSIDE_BEGIN_END) {
+ ctx->Driver.CurrentSavePrimitive = mode;
+ }
+ else {
+ _mesa_compile_error(ctx, GL_INVALID_OPERATION, "recursive begin");
+ error = GL_TRUE;
+ }
+
+ if (!error) {
+ /* Give the driver an opportunity to hook in an optimized
+ * display list compiler.
+ */
+ if (ctx->Driver.NotifySaveBegin(ctx, mode))
+ return;
+
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_BEGIN, 1);
+ if (n) {
+ n[1].e = mode;
+ }
+ }
+
+ if (ctx->ExecuteFlag) {
+ CALL_Begin(ctx->Exec, (mode));
+ }
+}
+
+static void GLAPIENTRY
+save_End(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ SAVE_FLUSH_VERTICES(ctx);
+ (void) alloc_instruction(ctx, OPCODE_END, 0);
+ ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
+ if (ctx->ExecuteFlag) {
+ CALL_End(ctx->Exec, ());
+ }
+}
+
+static void GLAPIENTRY
+save_Rectf(GLfloat a, GLfloat b, GLfloat c, GLfloat d)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ SAVE_FLUSH_VERTICES(ctx);
+ n = alloc_instruction(ctx, OPCODE_RECTF, 4);
+ if (n) {
+ n[1].f = a;
+ n[2].f = b;
+ n[3].f = c;
+ n[4].f = d;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Rectf(ctx->Exec, (a, b, c, d));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Vertex2f(GLfloat x, GLfloat y)
+{
+ save_Attr2fNV(VERT_ATTRIB_POS, x, y);
+}
+
+static void GLAPIENTRY
+save_Vertex2fv(const GLfloat * v)
+{
+ save_Attr2fNV(VERT_ATTRIB_POS, v[0], v[1]);
+}
+
+static void GLAPIENTRY
+save_Vertex3f(GLfloat x, GLfloat y, GLfloat z)
+{
+ save_Attr3fNV(VERT_ATTRIB_POS, x, y, z);
+}
+
+static void GLAPIENTRY
+save_Vertex3fv(const GLfloat * v)
+{
+ save_Attr3fNV(VERT_ATTRIB_POS, v[0], v[1], v[2]);
+}
+
+static void GLAPIENTRY
+save_Vertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ save_Attr4fNV(VERT_ATTRIB_POS, x, y, z, w);
+}
+
+static void GLAPIENTRY
+save_Vertex4fv(const GLfloat * v)
+{
+ save_Attr4fNV(VERT_ATTRIB_POS, v[0], v[1], v[2], v[3]);
+}
+
+static void GLAPIENTRY
+save_TexCoord1f(GLfloat x)
+{
+ save_Attr1fNV(VERT_ATTRIB_TEX0, x);
+}
+
+static void GLAPIENTRY
+save_TexCoord1fv(const GLfloat * v)
+{
+ save_Attr1fNV(VERT_ATTRIB_TEX0, v[0]);
+}
+
+static void GLAPIENTRY
+save_TexCoord2f(GLfloat x, GLfloat y)
+{
+ save_Attr2fNV(VERT_ATTRIB_TEX0, x, y);
+}
+
+static void GLAPIENTRY
+save_TexCoord2fv(const GLfloat * v)
+{
+ save_Attr2fNV(VERT_ATTRIB_TEX0, v[0], v[1]);
+}
+
+static void GLAPIENTRY
+save_TexCoord3f(GLfloat x, GLfloat y, GLfloat z)
+{
+ save_Attr3fNV(VERT_ATTRIB_TEX0, x, y, z);
+}
+
+static void GLAPIENTRY
+save_TexCoord3fv(const GLfloat * v)
+{
+ save_Attr3fNV(VERT_ATTRIB_TEX0, v[0], v[1], v[2]);
+}
+
+static void GLAPIENTRY
+save_TexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ save_Attr4fNV(VERT_ATTRIB_TEX0, x, y, z, w);
+}
+
+static void GLAPIENTRY
+save_TexCoord4fv(const GLfloat * v)
+{
+ save_Attr4fNV(VERT_ATTRIB_TEX0, v[0], v[1], v[2], v[3]);
+}
+
+static void GLAPIENTRY
+save_Normal3f(GLfloat x, GLfloat y, GLfloat z)
+{
+ save_Attr3fNV(VERT_ATTRIB_NORMAL, x, y, z);
+}
+
+static void GLAPIENTRY
+save_Normal3fv(const GLfloat * v)
+{
+ save_Attr3fNV(VERT_ATTRIB_NORMAL, v[0], v[1], v[2]);
+}
+
+static void GLAPIENTRY
+save_FogCoordfEXT(GLfloat x)
+{
+ save_Attr1fNV(VERT_ATTRIB_FOG, x);
+}
+
+static void GLAPIENTRY
+save_FogCoordfvEXT(const GLfloat * v)
+{
+ save_Attr1fNV(VERT_ATTRIB_FOG, v[0]);
+}
+
+static void GLAPIENTRY
+save_Color3f(GLfloat x, GLfloat y, GLfloat z)
+{
+ save_Attr3fNV(VERT_ATTRIB_COLOR0, x, y, z);
+}
+
+static void GLAPIENTRY
+save_Color3fv(const GLfloat * v)
+{
+ save_Attr3fNV(VERT_ATTRIB_COLOR0, v[0], v[1], v[2]);
+}
+
+static void GLAPIENTRY
+save_Color4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ save_Attr4fNV(VERT_ATTRIB_COLOR0, x, y, z, w);
+}
+
+static void GLAPIENTRY
+save_Color4fv(const GLfloat * v)
+{
+ save_Attr4fNV(VERT_ATTRIB_COLOR0, v[0], v[1], v[2], v[3]);
+}
+
+static void GLAPIENTRY
+save_SecondaryColor3fEXT(GLfloat x, GLfloat y, GLfloat z)
+{
+ save_Attr3fNV(VERT_ATTRIB_COLOR1, x, y, z);
+}
+
+static void GLAPIENTRY
+save_SecondaryColor3fvEXT(const GLfloat * v)
+{
+ save_Attr3fNV(VERT_ATTRIB_COLOR1, v[0], v[1], v[2]);
+}
+
+
+/* Just call the respective ATTR for texcoord
+ */
+static void GLAPIENTRY
+save_MultiTexCoord1f(GLenum target, GLfloat x)
+{
+ GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
+ save_Attr1fNV(attr, x);
+}
+
+static void GLAPIENTRY
+save_MultiTexCoord1fv(GLenum target, const GLfloat * v)
+{
+ GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
+ save_Attr1fNV(attr, v[0]);
+}
+
+static void GLAPIENTRY
+save_MultiTexCoord2f(GLenum target, GLfloat x, GLfloat y)
+{
+ GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
+ save_Attr2fNV(attr, x, y);
+}
+
+static void GLAPIENTRY
+save_MultiTexCoord2fv(GLenum target, const GLfloat * v)
+{
+ GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
+ save_Attr2fNV(attr, v[0], v[1]);
+}
+
+static void GLAPIENTRY
+save_MultiTexCoord3f(GLenum target, GLfloat x, GLfloat y, GLfloat z)
+{
+ GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
+ save_Attr3fNV(attr, x, y, z);
+}
+
+static void GLAPIENTRY
+save_MultiTexCoord3fv(GLenum target, const GLfloat * v)
+{
+ GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
+ save_Attr3fNV(attr, v[0], v[1], v[2]);
+}
+
+static void GLAPIENTRY
+save_MultiTexCoord4f(GLenum target, GLfloat x, GLfloat y,
+ GLfloat z, GLfloat w)
+{
+ GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
+ save_Attr4fNV(attr, x, y, z, w);
+}
+
+static void GLAPIENTRY
+save_MultiTexCoord4fv(GLenum target, const GLfloat * v)
+{
+ GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
+ save_Attr4fNV(attr, v[0], v[1], v[2], v[3]);
+}
+
+
+/**
+ * Record a GL_INVALID_VALUE error when a invalid vertex attribute
+ * index is found.
+ */
+static void
+index_error(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ _mesa_error(ctx, GL_INVALID_VALUE, "VertexAttribf(index)");
+}
+
+
+/* First level for NV_vertex_program:
+ *
+ * Check for errors at compile time?.
+ */
+static void GLAPIENTRY
+save_VertexAttrib1fNV(GLuint index, GLfloat x)
+{
+ if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
+ save_Attr1fNV(index, x);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib1fvNV(GLuint index, const GLfloat * v)
+{
+ if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
+ save_Attr1fNV(index, v[0]);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib2fNV(GLuint index, GLfloat x, GLfloat y)
+{
+ if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
+ save_Attr2fNV(index, x, y);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib2fvNV(GLuint index, const GLfloat * v)
+{
+ if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
+ save_Attr2fNV(index, v[0], v[1]);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib3fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z)
+{
+ if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
+ save_Attr3fNV(index, x, y, z);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib3fvNV(GLuint index, const GLfloat * v)
+{
+ if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
+ save_Attr3fNV(index, v[0], v[1], v[2]);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib4fNV(GLuint index, GLfloat x, GLfloat y,
+ GLfloat z, GLfloat w)
+{
+ if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
+ save_Attr4fNV(index, x, y, z, w);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib4fvNV(GLuint index, const GLfloat * v)
+{
+ if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
+ save_Attr4fNV(index, v[0], v[1], v[2], v[3]);
+ else
+ index_error();
+}
+
+
+
+
+static void GLAPIENTRY
+save_VertexAttrib1fARB(GLuint index, GLfloat x)
+{
+ if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ save_Attr1fARB(index, x);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib1fvARB(GLuint index, const GLfloat * v)
+{
+ if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ save_Attr1fARB(index, v[0]);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib2fARB(GLuint index, GLfloat x, GLfloat y)
+{
+ if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ save_Attr2fARB(index, x, y);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib2fvARB(GLuint index, const GLfloat * v)
+{
+ if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ save_Attr2fARB(index, v[0], v[1]);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib3fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z)
+{
+ if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ save_Attr3fARB(index, x, y, z);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib3fvARB(GLuint index, const GLfloat * v)
+{
+ if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ save_Attr3fARB(index, v[0], v[1], v[2]);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib4fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z,
+ GLfloat w)
+{
+ if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ save_Attr4fARB(index, x, y, z, w);
+ else
+ index_error();
+}
+
+static void GLAPIENTRY
+save_VertexAttrib4fvARB(GLuint index, const GLfloat * v)
+{
+ if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ save_Attr4fARB(index, v[0], v[1], v[2], v[3]);
+ else
+ index_error();
+}
+
+
+/* GL_ARB_shader_objects, GL_ARB_vertex/fragment_shader */
+
+static void GLAPIENTRY
+exec_BindAttribLocationARB(GLuint program, GLuint index, const GLchar *name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_BindAttribLocationARB(ctx->Exec, (program, index, name));
+}
+
+static GLint GLAPIENTRY
+exec_GetAttribLocationARB(GLuint program, const GLchar *name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ return CALL_GetAttribLocationARB(ctx->Exec, (program, name));
+}
+
+static GLint GLAPIENTRY
+exec_GetUniformLocationARB(GLuint program, const GLchar *name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ return CALL_GetUniformLocationARB(ctx->Exec, (program, name));
+}
+/* XXX more shader functions needed here */
+
+
+#if FEATURE_EXT_framebuffer_blit
+static void GLAPIENTRY
+save_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
+ GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
+ GLbitfield mask, GLenum filter)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BLIT_FRAMEBUFFER, 10);
+ if (n) {
+ n[1].i = srcX0;
+ n[2].i = srcY0;
+ n[3].i = srcX1;
+ n[4].i = srcY1;
+ n[5].i = dstX0;
+ n[6].i = dstY0;
+ n[7].i = dstX1;
+ n[8].i = dstY1;
+ n[9].i = mask;
+ n[10].e = filter;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BlitFramebufferEXT(ctx->Exec, (srcX0, srcY0, srcX1, srcY1,
+ dstX0, dstY0, dstX1, dstY1,
+ mask, filter));
+ }
+}
+#endif
+
+
+/** GL_EXT_provoking_vertex */
+static void GLAPIENTRY
+save_ProvokingVertexEXT(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_PROVOKING_VERTEX, 1);
+ if (n) {
+ n[1].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_ProvokingVertexEXT(ctx->Exec, (mode));*/
+ _mesa_ProvokingVertexEXT(mode);
+ }
+}
+
+
+/** GL_EXT_transform_feedback */
+static void GLAPIENTRY
+save_BeginTransformFeedback(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_BEGIN_TRANSFORM_FEEDBACK, 1);
+ if (n) {
+ n[1].e = mode;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_BeginTransformFeedbackEXT(ctx->Exec, (mode));
+ }
+}
+
+
+/** GL_EXT_transform_feedback */
+static void GLAPIENTRY
+save_EndTransformFeedback(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ (void) alloc_instruction(ctx, OPCODE_END_TRANSFORM_FEEDBACK, 0);
+ if (ctx->ExecuteFlag) {
+ CALL_EndTransformFeedbackEXT(ctx->Exec, ());
+ }
+}
+
+
+/* aka UseProgram() */
+static void GLAPIENTRY
+save_UseProgramObjectARB(GLhandleARB program)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_USE_PROGRAM, 1);
+ if (n) {
+ n[1].ui = program;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UseProgramObjectARB(ctx->Exec, (program));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Uniform1fARB(GLint location, GLfloat x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_1F, 2);
+ if (n) {
+ n[1].i = location;
+ n[2].f = x;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform1fARB(ctx->Exec, (location, x));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Uniform2fARB(GLint location, GLfloat x, GLfloat y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_2F, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].f = x;
+ n[3].f = y;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform2fARB(ctx->Exec, (location, x, y));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Uniform3fARB(GLint location, GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_3F, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].f = x;
+ n[3].f = y;
+ n[4].f = z;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform3fARB(ctx->Exec, (location, x, y, z));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Uniform4fARB(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_4F, 5);
+ if (n) {
+ n[1].i = location;
+ n[2].f = x;
+ n[3].f = y;
+ n[4].f = z;
+ n[5].f = w;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform4fARB(ctx->Exec, (location, x, y, z, w));
+ }
+}
+
+
+/** Return copy of memory */
+static void *
+memdup(const void *src, GLsizei bytes)
+{
+ void *b = bytes >= 0 ? malloc(bytes) : NULL;
+ if (b)
+ memcpy(b, src, bytes);
+ return b;
+}
+
+
+static void GLAPIENTRY
+save_Uniform1fvARB(GLint location, GLsizei count, const GLfloat *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_1FV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 1 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform1fvARB(ctx->Exec, (location, count, v));
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform2fvARB(GLint location, GLsizei count, const GLfloat *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_2FV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 2 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform2fvARB(ctx->Exec, (location, count, v));
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform3fvARB(GLint location, GLsizei count, const GLfloat *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_3FV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 3 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform3fvARB(ctx->Exec, (location, count, v));
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform4fvARB(GLint location, GLsizei count, const GLfloat *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_4FV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 4 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform4fvARB(ctx->Exec, (location, count, v));
+ }
+}
+
+
+static void GLAPIENTRY
+save_Uniform1iARB(GLint location, GLint x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_1I, 2);
+ if (n) {
+ n[1].i = location;
+ n[2].i = x;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform1iARB(ctx->Exec, (location, x));
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform2iARB(GLint location, GLint x, GLint y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_2I, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = x;
+ n[3].i = y;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform2iARB(ctx->Exec, (location, x, y));
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform3iARB(GLint location, GLint x, GLint y, GLint z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_3I, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = x;
+ n[3].i = y;
+ n[4].i = z;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform3iARB(ctx->Exec, (location, x, y, z));
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform4iARB(GLint location, GLint x, GLint y, GLint z, GLint w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_4I, 5);
+ if (n) {
+ n[1].i = location;
+ n[2].i = x;
+ n[3].i = y;
+ n[4].i = z;
+ n[5].i = w;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform4iARB(ctx->Exec, (location, x, y, z, w));
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_Uniform1ivARB(GLint location, GLsizei count, const GLint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_1IV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 1 * sizeof(GLint));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform1ivARB(ctx->Exec, (location, count, v));
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform2ivARB(GLint location, GLsizei count, const GLint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_2IV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 2 * sizeof(GLint));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform2ivARB(ctx->Exec, (location, count, v));
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform3ivARB(GLint location, GLsizei count, const GLint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_3IV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 3 * sizeof(GLint));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform3ivARB(ctx->Exec, (location, count, v));
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform4ivARB(GLint location, GLsizei count, const GLint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_4IV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 4 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_Uniform4ivARB(ctx->Exec, (location, count, v));
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_Uniform1ui(GLint location, GLuint x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_1UI, 2);
+ if (n) {
+ n[1].i = location;
+ n[2].i = x;
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_Uniform1ui(ctx->Exec, (location, x));*/
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform2ui(GLint location, GLuint x, GLuint y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_2UI, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = x;
+ n[3].i = y;
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_Uniform2ui(ctx->Exec, (location, x, y));*/
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform3ui(GLint location, GLuint x, GLuint y, GLuint z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_3UI, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = x;
+ n[3].i = y;
+ n[4].i = z;
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_Uniform3ui(ctx->Exec, (location, x, y, z));*/
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform4ui(GLint location, GLuint x, GLuint y, GLuint z, GLuint w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_4UI, 5);
+ if (n) {
+ n[1].i = location;
+ n[2].i = x;
+ n[3].i = y;
+ n[4].i = z;
+ n[5].i = w;
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_Uniform4ui(ctx->Exec, (location, x, y, z, w));*/
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_Uniform1uiv(GLint location, GLsizei count, const GLuint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_1UIV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 1 * sizeof(*v));
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_Uniform1uiv(ctx->Exec, (location, count, v));*/
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform2uiv(GLint location, GLsizei count, const GLuint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_2UIV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 2 * sizeof(*v));
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_Uniform2uiv(ctx->Exec, (location, count, v));*/
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform3uiv(GLint location, GLsizei count, const GLuint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_3UIV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 3 * sizeof(*v));
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_Uniform3uiv(ctx->Exec, (location, count, v));*/
+ }
+}
+
+static void GLAPIENTRY
+save_Uniform4uiv(GLint location, GLsizei count, const GLuint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_4UIV, 3);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].data = memdup(v, count * 4 * sizeof(*v));
+ }
+ if (ctx->ExecuteFlag) {
+ /*CALL_Uniform4uiv(ctx->Exec, (location, count, v));*/
+ }
+}
+
+
+
+static void GLAPIENTRY
+save_UniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose,
+ const GLfloat *m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX22, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].b = transpose;
+ n[4].data = memdup(m, count * 2 * 2 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UniformMatrix2fvARB(ctx->Exec, (location, count, transpose, m));
+ }
+}
+
+static void GLAPIENTRY
+save_UniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose,
+ const GLfloat *m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX33, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].b = transpose;
+ n[4].data = memdup(m, count * 3 * 3 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UniformMatrix3fvARB(ctx->Exec, (location, count, transpose, m));
+ }
+}
+
+static void GLAPIENTRY
+save_UniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose,
+ const GLfloat *m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX44, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].b = transpose;
+ n[4].data = memdup(m, count * 4 * 4 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UniformMatrix4fvARB(ctx->Exec, (location, count, transpose, m));
+ }
+}
+
+
+static void GLAPIENTRY
+save_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
+ const GLfloat *m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX23, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].b = transpose;
+ n[4].data = memdup(m, count * 2 * 3 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UniformMatrix2x3fv(ctx->Exec, (location, count, transpose, m));
+ }
+}
+
+static void GLAPIENTRY
+save_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
+ const GLfloat *m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX32, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].b = transpose;
+ n[4].data = memdup(m, count * 3 * 2 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UniformMatrix3x2fv(ctx->Exec, (location, count, transpose, m));
+ }
+}
+
+
+static void GLAPIENTRY
+save_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
+ const GLfloat *m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX24, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].b = transpose;
+ n[4].data = memdup(m, count * 2 * 4 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UniformMatrix2x4fv(ctx->Exec, (location, count, transpose, m));
+ }
+}
+
+static void GLAPIENTRY
+save_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
+ const GLfloat *m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX42, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].b = transpose;
+ n[4].data = memdup(m, count * 4 * 2 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UniformMatrix4x2fv(ctx->Exec, (location, count, transpose, m));
+ }
+}
+
+
+static void GLAPIENTRY
+save_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
+ const GLfloat *m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX34, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].b = transpose;
+ n[4].data = memdup(m, count * 3 * 4 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UniformMatrix3x4fv(ctx->Exec, (location, count, transpose, m));
+ }
+}
+
+static void GLAPIENTRY
+save_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
+ const GLfloat *m)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX43, 4);
+ if (n) {
+ n[1].i = location;
+ n[2].i = count;
+ n[3].b = transpose;
+ n[4].data = memdup(m, count * 4 * 3 * sizeof(GLfloat));
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UniformMatrix4x3fv(ctx->Exec, (location, count, transpose, m));
+ }
+}
+
+static void GLAPIENTRY
+save_UseShaderProgramEXT(GLenum type, GLuint program)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_USE_SHADER_PROGRAM_EXT, 2);
+ if (n) {
+ n[1].ui = type;
+ n[2].ui = program;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_UseShaderProgramEXT(ctx->Exec, (type, program));
+ }
+}
+
+static void GLAPIENTRY
+save_ActiveProgramEXT(GLuint program)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_ACTIVE_PROGRAM_EXT, 1);
+ if (n) {
+ n[1].ui = program;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ActiveProgramEXT(ctx->Exec, (program));
+ }
+}
+
+/** GL_EXT_texture_integer */
+static void GLAPIENTRY
+save_ClearColorIi(GLint red, GLint green, GLint blue, GLint alpha)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEARCOLOR_I, 4);
+ if (n) {
+ n[1].i = red;
+ n[2].i = green;
+ n[3].i = blue;
+ n[4].i = alpha;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ClearColorIiEXT(ctx->Exec, (red, green, blue, alpha));
+ }
+}
+
+/** GL_EXT_texture_integer */
+static void GLAPIENTRY
+save_ClearColorIui(GLuint red, GLuint green, GLuint blue, GLuint alpha)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_CLEARCOLOR_UI, 4);
+ if (n) {
+ n[1].ui = red;
+ n[2].ui = green;
+ n[3].ui = blue;
+ n[4].ui = alpha;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_ClearColorIuiEXT(ctx->Exec, (red, green, blue, alpha));
+ }
+}
+
+/** GL_EXT_texture_integer */
+static void GLAPIENTRY
+save_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_TEXPARAMETER_I, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].e = pname;
+ n[3].i = params[0];
+ n[4].i = params[1];
+ n[5].i = params[2];
+ n[6].i = params[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexParameterIivEXT(ctx->Exec, (target, pname, params));
+ }
+}
+
+/** GL_EXT_texture_integer */
+static void GLAPIENTRY
+save_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_TEXPARAMETER_UI, 6);
+ if (n) {
+ n[1].e = target;
+ n[2].e = pname;
+ n[3].ui = params[0];
+ n[4].ui = params[1];
+ n[5].ui = params[2];
+ n[6].ui = params[3];
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_TexParameterIuivEXT(ctx->Exec, (target, pname, params));
+ }
+}
+
+/** GL_EXT_texture_integer */
+static void GLAPIENTRY
+exec_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexParameterIivEXT(ctx->Exec, (target, pname, params));
+}
+
+/** GL_EXT_texture_integer */
+static void GLAPIENTRY
+exec_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexParameterIuivEXT(ctx->Exec, (target, pname, params));
+}
+
+
+/* GL_ARB_instanced_arrays */
+static void
+save_VertexAttribDivisor(GLuint index, GLuint divisor)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_VERTEX_ATTRIB_DIVISOR, 2);
+ if (n) {
+ n[1].ui = index;
+ n[2].ui = divisor;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_VertexAttribDivisorARB(ctx->Exec, (index, divisor));
+ }
+}
+
+
+
+/**
+ * Save an error-generating command into display list.
+ *
+ * KW: Will appear in the list before the vertex buffer containing the
+ * command that provoked the error. I don't see this as a problem.
+ */
+static void
+save_error(struct gl_context *ctx, GLenum error, const char *s)
+{
+ Node *n;
+ n = alloc_instruction(ctx, OPCODE_ERROR, 2);
+ if (n) {
+ n[1].e = error;
+ n[2].data = (void *) s;
+ }
+}
+
+
+/**
+ * Compile an error into current display list.
+ */
+void
+_mesa_compile_error(struct gl_context *ctx, GLenum error, const char *s)
+{
+ if (ctx->CompileFlag)
+ save_error(ctx, error, s);
+ if (ctx->ExecuteFlag)
+ _mesa_error(ctx, error, "%s", s);
+}
+
+
+/**
+ * Test if ID names a display list.
+ */
+static GLboolean
+islist(struct gl_context *ctx, GLuint list)
+{
+ if (list > 0 && lookup_list(ctx, list)) {
+ return GL_TRUE;
+ }
+ else {
+ return GL_FALSE;
+ }
+}
+
+
+
+/**********************************************************************/
+/* Display list execution */
+/**********************************************************************/
+
+
+/*
+ * Execute a display list. Note that the ListBase offset must have already
+ * been added before calling this function. I.e. the list argument is
+ * the absolute list number, not relative to ListBase.
+ * \param list - display list number
+ */
+static void
+execute_list(struct gl_context *ctx, GLuint list)
+{
+ struct gl_display_list *dlist;
+ Node *n;
+ GLboolean done;
+
+ if (list == 0 || !islist(ctx, list))
+ return;
+
+ if (ctx->ListState.CallDepth == MAX_LIST_NESTING) {
+ /* raise an error? */
+ return;
+ }
+
+ dlist = lookup_list(ctx, list);
+ if (!dlist)
+ return;
+
+ ctx->ListState.CallDepth++;
+
+ if (ctx->Driver.BeginCallList)
+ ctx->Driver.BeginCallList(ctx, dlist);
+
+ n = dlist->Head;
+
+ done = GL_FALSE;
+ while (!done) {
+ const OpCode opcode = n[0].opcode;
+
+ if (is_ext_opcode(opcode)) {
+ n += ext_opcode_execute(ctx, n);
+ }
+ else {
+ switch (opcode) {
+ case OPCODE_ERROR:
+ _mesa_error(ctx, n[1].e, "%s", (const char *) n[2].data);
+ break;
+ case OPCODE_ACCUM:
+ CALL_Accum(ctx->Exec, (n[1].e, n[2].f));
+ break;
+ case OPCODE_ALPHA_FUNC:
+ CALL_AlphaFunc(ctx->Exec, (n[1].e, n[2].f));
+ break;
+ case OPCODE_BIND_TEXTURE:
+ CALL_BindTexture(ctx->Exec, (n[1].e, n[2].ui));
+ break;
+ case OPCODE_BITMAP:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_Bitmap(ctx->Exec, ((GLsizei) n[1].i, (GLsizei) n[2].i,
+ n[3].f, n[4].f, n[5].f, n[6].f,
+ (const GLubyte *) n[7].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_BLEND_COLOR:
+ CALL_BlendColor(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
+ break;
+ case OPCODE_BLEND_EQUATION:
+ CALL_BlendEquation(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_BLEND_EQUATION_SEPARATE:
+ CALL_BlendEquationSeparateEXT(ctx->Exec, (n[1].e, n[2].e));
+ break;
+ case OPCODE_BLEND_FUNC_SEPARATE:
+ CALL_BlendFuncSeparateEXT(ctx->Exec,
+ (n[1].e, n[2].e, n[3].e, n[4].e));
+ break;
+
+ case OPCODE_BLEND_FUNC_I:
+ /* GL_ARB_draw_buffers_blend */
+ CALL_BlendFunciARB(ctx->Exec, (n[1].ui, n[2].e, n[3].e));
+ break;
+ case OPCODE_BLEND_FUNC_SEPARATE_I:
+ /* GL_ARB_draw_buffers_blend */
+ CALL_BlendFuncSeparateiARB(ctx->Exec, (n[1].ui, n[2].e, n[3].e,
+ n[4].e, n[5].e));
+ break;
+ case OPCODE_BLEND_EQUATION_I:
+ /* GL_ARB_draw_buffers_blend */
+ CALL_BlendEquationiARB(ctx->Exec, (n[1].ui, n[2].e));
+ break;
+ case OPCODE_BLEND_EQUATION_SEPARATE_I:
+ /* GL_ARB_draw_buffers_blend */
+ CALL_BlendEquationSeparateiARB(ctx->Exec,
+ (n[1].ui, n[2].e, n[3].e));
+ break;
+
+ case OPCODE_CALL_LIST:
+ /* Generated by glCallList(), don't add ListBase */
+ if (ctx->ListState.CallDepth < MAX_LIST_NESTING) {
+ execute_list(ctx, n[1].ui);
+ }
+ break;
+ case OPCODE_CALL_LIST_OFFSET:
+ /* Generated by glCallLists() so we must add ListBase */
+ if (n[2].b) {
+ /* user specified a bad data type at compile time */
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCallLists(type)");
+ }
+ else if (ctx->ListState.CallDepth < MAX_LIST_NESTING) {
+ GLuint list = (GLuint) (ctx->List.ListBase + n[1].i);
+ execute_list(ctx, list);
+ }
+ break;
+ case OPCODE_CLEAR:
+ CALL_Clear(ctx->Exec, (n[1].bf));
+ break;
+ case OPCODE_CLEAR_BUFFER_IV:
+ {
+ GLint value[4];
+ value[0] = n[3].i;
+ value[1] = n[4].i;
+ value[2] = n[5].i;
+ value[3] = n[6].i;
+ /*CALL_ClearBufferiv(ctx->Exec, (n[1].e, n[2].i, value));*/
+ }
+ break;
+ case OPCODE_CLEAR_BUFFER_UIV:
+ {
+ GLuint value[4];
+ value[0] = n[3].ui;
+ value[1] = n[4].ui;
+ value[2] = n[5].ui;
+ value[3] = n[6].ui;
+ /*CALL_ClearBufferiv(ctx->Exec, (n[1].e, n[2].i, value));*/
+ }
+ break;
+ case OPCODE_CLEAR_BUFFER_FV:
+ {
+ GLfloat value[4];
+ value[0] = n[3].f;
+ value[1] = n[4].f;
+ value[2] = n[5].f;
+ value[3] = n[6].f;
+ /*CALL_ClearBufferfv(ctx->Exec, (n[1].e, n[2].i, value));*/
+ }
+ break;
+ case OPCODE_CLEAR_BUFFER_FI:
+ /*CALL_ClearBufferfi(ctx->Exec, (n[1].e, n[2].i, n[3].f, n[4].i));*/
+ break;
+ case OPCODE_CLEAR_COLOR:
+ CALL_ClearColor(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
+ break;
+ case OPCODE_CLEAR_ACCUM:
+ CALL_ClearAccum(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
+ break;
+ case OPCODE_CLEAR_DEPTH:
+ CALL_ClearDepth(ctx->Exec, ((GLclampd) n[1].f));
+ break;
+ case OPCODE_CLEAR_INDEX:
+ CALL_ClearIndex(ctx->Exec, ((GLfloat) n[1].ui));
+ break;
+ case OPCODE_CLEAR_STENCIL:
+ CALL_ClearStencil(ctx->Exec, (n[1].i));
+ break;
+ case OPCODE_CLIP_PLANE:
+ {
+ GLdouble eq[4];
+ eq[0] = n[2].f;
+ eq[1] = n[3].f;
+ eq[2] = n[4].f;
+ eq[3] = n[5].f;
+ CALL_ClipPlane(ctx->Exec, (n[1].e, eq));
+ }
+ break;
+ case OPCODE_COLOR_MASK:
+ CALL_ColorMask(ctx->Exec, (n[1].b, n[2].b, n[3].b, n[4].b));
+ break;
+ case OPCODE_COLOR_MASK_INDEXED:
+ CALL_ColorMaskIndexedEXT(ctx->Exec, (n[1].ui, n[2].b, n[3].b,
+ n[4].b, n[5].b));
+ break;
+ case OPCODE_COLOR_MATERIAL:
+ CALL_ColorMaterial(ctx->Exec, (n[1].e, n[2].e));
+ break;
+ case OPCODE_COLOR_TABLE:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_ColorTable(ctx->Exec, (n[1].e, n[2].e, n[3].i, n[4].e,
+ n[5].e, n[6].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_COLOR_TABLE_PARAMETER_FV:
+ {
+ GLfloat params[4];
+ params[0] = n[3].f;
+ params[1] = n[4].f;
+ params[2] = n[5].f;
+ params[3] = n[6].f;
+ CALL_ColorTableParameterfv(ctx->Exec,
+ (n[1].e, n[2].e, params));
+ }
+ break;
+ case OPCODE_COLOR_TABLE_PARAMETER_IV:
+ {
+ GLint params[4];
+ params[0] = n[3].i;
+ params[1] = n[4].i;
+ params[2] = n[5].i;
+ params[3] = n[6].i;
+ CALL_ColorTableParameteriv(ctx->Exec,
+ (n[1].e, n[2].e, params));
+ }
+ break;
+ case OPCODE_COLOR_SUB_TABLE:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_ColorSubTable(ctx->Exec, (n[1].e, n[2].i, n[3].i,
+ n[4].e, n[5].e, n[6].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_CONVOLUTION_FILTER_1D:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_ConvolutionFilter1D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
+ n[4].e, n[5].e,
+ n[6].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_CONVOLUTION_FILTER_2D:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_ConvolutionFilter2D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
+ n[4].i, n[5].e, n[6].e,
+ n[7].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_CONVOLUTION_PARAMETER_I:
+ CALL_ConvolutionParameteri(ctx->Exec, (n[1].e, n[2].e, n[3].i));
+ break;
+ case OPCODE_CONVOLUTION_PARAMETER_IV:
+ {
+ GLint params[4];
+ params[0] = n[3].i;
+ params[1] = n[4].i;
+ params[2] = n[5].i;
+ params[3] = n[6].i;
+ CALL_ConvolutionParameteriv(ctx->Exec,
+ (n[1].e, n[2].e, params));
+ }
+ break;
+ case OPCODE_CONVOLUTION_PARAMETER_F:
+ CALL_ConvolutionParameterf(ctx->Exec, (n[1].e, n[2].e, n[3].f));
+ break;
+ case OPCODE_CONVOLUTION_PARAMETER_FV:
+ {
+ GLfloat params[4];
+ params[0] = n[3].f;
+ params[1] = n[4].f;
+ params[2] = n[5].f;
+ params[3] = n[6].f;
+ CALL_ConvolutionParameterfv(ctx->Exec,
+ (n[1].e, n[2].e, params));
+ }
+ break;
+ case OPCODE_COPY_COLOR_SUB_TABLE:
+ CALL_CopyColorSubTable(ctx->Exec, (n[1].e, n[2].i,
+ n[3].i, n[4].i, n[5].i));
+ break;
+ case OPCODE_COPY_COLOR_TABLE:
+ CALL_CopyColorSubTable(ctx->Exec, (n[1].e, n[2].i,
+ n[3].i, n[4].i, n[5].i));
+ break;
+ case OPCODE_COPY_PIXELS:
+ CALL_CopyPixels(ctx->Exec, (n[1].i, n[2].i,
+ (GLsizei) n[3].i, (GLsizei) n[4].i,
+ n[5].e));
+ break;
+ case OPCODE_COPY_TEX_IMAGE1D:
+ CALL_CopyTexImage1D(ctx->Exec, (n[1].e, n[2].i, n[3].e, n[4].i,
+ n[5].i, n[6].i, n[7].i));
+ break;
+ case OPCODE_COPY_TEX_IMAGE2D:
+ CALL_CopyTexImage2D(ctx->Exec, (n[1].e, n[2].i, n[3].e, n[4].i,
+ n[5].i, n[6].i, n[7].i, n[8].i));
+ break;
+ case OPCODE_COPY_TEX_SUB_IMAGE1D:
+ CALL_CopyTexSubImage1D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
+ n[4].i, n[5].i, n[6].i));
+ break;
+ case OPCODE_COPY_TEX_SUB_IMAGE2D:
+ CALL_CopyTexSubImage2D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
+ n[4].i, n[5].i, n[6].i, n[7].i,
+ n[8].i));
+ break;
+ case OPCODE_COPY_TEX_SUB_IMAGE3D:
+ CALL_CopyTexSubImage3D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
+ n[4].i, n[5].i, n[6].i, n[7].i,
+ n[8].i, n[9].i));
+ break;
+ case OPCODE_CULL_FACE:
+ CALL_CullFace(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_DEPTH_FUNC:
+ CALL_DepthFunc(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_DEPTH_MASK:
+ CALL_DepthMask(ctx->Exec, (n[1].b));
+ break;
+ case OPCODE_DEPTH_RANGE:
+ CALL_DepthRange(ctx->Exec,
+ ((GLclampd) n[1].f, (GLclampd) n[2].f));
+ break;
+ case OPCODE_DISABLE:
+ CALL_Disable(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_DISABLE_INDEXED:
+ CALL_DisableIndexedEXT(ctx->Exec, (n[1].ui, n[2].e));
+ break;
+ case OPCODE_DRAW_BUFFER:
+ CALL_DrawBuffer(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_DRAW_PIXELS:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_DrawPixels(ctx->Exec, (n[1].i, n[2].i, n[3].e, n[4].e,
+ n[5].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_ENABLE:
+ CALL_Enable(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_ENABLE_INDEXED:
+ CALL_EnableIndexedEXT(ctx->Exec, (n[1].ui, n[2].e));
+ break;
+ case OPCODE_EVALMESH1:
+ CALL_EvalMesh1(ctx->Exec, (n[1].e, n[2].i, n[3].i));
+ break;
+ case OPCODE_EVALMESH2:
+ CALL_EvalMesh2(ctx->Exec,
+ (n[1].e, n[2].i, n[3].i, n[4].i, n[5].i));
+ break;
+ case OPCODE_FOG:
+ {
+ GLfloat p[4];
+ p[0] = n[2].f;
+ p[1] = n[3].f;
+ p[2] = n[4].f;
+ p[3] = n[5].f;
+ CALL_Fogfv(ctx->Exec, (n[1].e, p));
+ }
+ break;
+ case OPCODE_FRONT_FACE:
+ CALL_FrontFace(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_FRUSTUM:
+ CALL_Frustum(ctx->Exec,
+ (n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f));
+ break;
+ case OPCODE_HINT:
+ CALL_Hint(ctx->Exec, (n[1].e, n[2].e));
+ break;
+ case OPCODE_HISTOGRAM:
+ CALL_Histogram(ctx->Exec, (n[1].e, n[2].i, n[3].e, n[4].b));
+ break;
+ case OPCODE_INDEX_MASK:
+ CALL_IndexMask(ctx->Exec, (n[1].ui));
+ break;
+ case OPCODE_INIT_NAMES:
+ CALL_InitNames(ctx->Exec, ());
+ break;
+ case OPCODE_LIGHT:
+ {
+ GLfloat p[4];
+ p[0] = n[3].f;
+ p[1] = n[4].f;
+ p[2] = n[5].f;
+ p[3] = n[6].f;
+ CALL_Lightfv(ctx->Exec, (n[1].e, n[2].e, p));
+ }
+ break;
+ case OPCODE_LIGHT_MODEL:
+ {
+ GLfloat p[4];
+ p[0] = n[2].f;
+ p[1] = n[3].f;
+ p[2] = n[4].f;
+ p[3] = n[5].f;
+ CALL_LightModelfv(ctx->Exec, (n[1].e, p));
+ }
+ break;
+ case OPCODE_LINE_STIPPLE:
+ CALL_LineStipple(ctx->Exec, (n[1].i, n[2].us));
+ break;
+ case OPCODE_LINE_WIDTH:
+ CALL_LineWidth(ctx->Exec, (n[1].f));
+ break;
+ case OPCODE_LIST_BASE:
+ CALL_ListBase(ctx->Exec, (n[1].ui));
+ break;
+ case OPCODE_LOAD_IDENTITY:
+ CALL_LoadIdentity(ctx->Exec, ());
+ break;
+ case OPCODE_LOAD_MATRIX:
+ if (sizeof(Node) == sizeof(GLfloat)) {
+ CALL_LoadMatrixf(ctx->Exec, (&n[1].f));
+ }
+ else {
+ GLfloat m[16];
+ GLuint i;
+ for (i = 0; i < 16; i++) {
+ m[i] = n[1 + i].f;
+ }
+ CALL_LoadMatrixf(ctx->Exec, (m));
+ }
+ break;
+ case OPCODE_LOAD_NAME:
+ CALL_LoadName(ctx->Exec, (n[1].ui));
+ break;
+ case OPCODE_LOGIC_OP:
+ CALL_LogicOp(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_MAP1:
+ {
+ GLenum target = n[1].e;
+ GLint ustride = _mesa_evaluator_components(target);
+ GLint uorder = n[5].i;
+ GLfloat u1 = n[2].f;
+ GLfloat u2 = n[3].f;
+ CALL_Map1f(ctx->Exec, (target, u1, u2, ustride, uorder,
+ (GLfloat *) n[6].data));
+ }
+ break;
+ case OPCODE_MAP2:
+ {
+ GLenum target = n[1].e;
+ GLfloat u1 = n[2].f;
+ GLfloat u2 = n[3].f;
+ GLfloat v1 = n[4].f;
+ GLfloat v2 = n[5].f;
+ GLint ustride = n[6].i;
+ GLint vstride = n[7].i;
+ GLint uorder = n[8].i;
+ GLint vorder = n[9].i;
+ CALL_Map2f(ctx->Exec, (target, u1, u2, ustride, uorder,
+ v1, v2, vstride, vorder,
+ (GLfloat *) n[10].data));
+ }
+ break;
+ case OPCODE_MAPGRID1:
+ CALL_MapGrid1f(ctx->Exec, (n[1].i, n[2].f, n[3].f));
+ break;
+ case OPCODE_MAPGRID2:
+ CALL_MapGrid2f(ctx->Exec,
+ (n[1].i, n[2].f, n[3].f, n[4].i, n[5].f, n[6].f));
+ break;
+ case OPCODE_MATRIX_MODE:
+ CALL_MatrixMode(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_MIN_MAX:
+ CALL_Minmax(ctx->Exec, (n[1].e, n[2].e, n[3].b));
+ break;
+ case OPCODE_MULT_MATRIX:
+ if (sizeof(Node) == sizeof(GLfloat)) {
+ CALL_MultMatrixf(ctx->Exec, (&n[1].f));
+ }
+ else {
+ GLfloat m[16];
+ GLuint i;
+ for (i = 0; i < 16; i++) {
+ m[i] = n[1 + i].f;
+ }
+ CALL_MultMatrixf(ctx->Exec, (m));
+ }
+ break;
+ case OPCODE_ORTHO:
+ CALL_Ortho(ctx->Exec,
+ (n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f));
+ break;
+ case OPCODE_PASSTHROUGH:
+ CALL_PassThrough(ctx->Exec, (n[1].f));
+ break;
+ case OPCODE_PIXEL_MAP:
+ CALL_PixelMapfv(ctx->Exec,
+ (n[1].e, n[2].i, (GLfloat *) n[3].data));
+ break;
+ case OPCODE_PIXEL_TRANSFER:
+ CALL_PixelTransferf(ctx->Exec, (n[1].e, n[2].f));
+ break;
+ case OPCODE_PIXEL_ZOOM:
+ CALL_PixelZoom(ctx->Exec, (n[1].f, n[2].f));
+ break;
+ case OPCODE_POINT_SIZE:
+ CALL_PointSize(ctx->Exec, (n[1].f));
+ break;
+ case OPCODE_POINT_PARAMETERS:
+ {
+ GLfloat params[3];
+ params[0] = n[2].f;
+ params[1] = n[3].f;
+ params[2] = n[4].f;
+ CALL_PointParameterfvEXT(ctx->Exec, (n[1].e, params));
+ }
+ break;
+ case OPCODE_POLYGON_MODE:
+ CALL_PolygonMode(ctx->Exec, (n[1].e, n[2].e));
+ break;
+ case OPCODE_POLYGON_STIPPLE:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_PolygonStipple(ctx->Exec, ((GLubyte *) n[1].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_POLYGON_OFFSET:
+ CALL_PolygonOffset(ctx->Exec, (n[1].f, n[2].f));
+ break;
+ case OPCODE_POP_ATTRIB:
+ CALL_PopAttrib(ctx->Exec, ());
+ break;
+ case OPCODE_POP_MATRIX:
+ CALL_PopMatrix(ctx->Exec, ());
+ break;
+ case OPCODE_POP_NAME:
+ CALL_PopName(ctx->Exec, ());
+ break;
+ case OPCODE_PRIORITIZE_TEXTURE:
+ CALL_PrioritizeTextures(ctx->Exec, (1, &n[1].ui, &n[2].f));
+ break;
+ case OPCODE_PUSH_ATTRIB:
+ CALL_PushAttrib(ctx->Exec, (n[1].bf));
+ break;
+ case OPCODE_PUSH_MATRIX:
+ CALL_PushMatrix(ctx->Exec, ());
+ break;
+ case OPCODE_PUSH_NAME:
+ CALL_PushName(ctx->Exec, (n[1].ui));
+ break;
+ case OPCODE_RASTER_POS:
+ CALL_RasterPos4f(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
+ break;
+ case OPCODE_READ_BUFFER:
+ CALL_ReadBuffer(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_RESET_HISTOGRAM:
+ CALL_ResetHistogram(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_RESET_MIN_MAX:
+ CALL_ResetMinmax(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_ROTATE:
+ CALL_Rotatef(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
+ break;
+ case OPCODE_SCALE:
+ CALL_Scalef(ctx->Exec, (n[1].f, n[2].f, n[3].f));
+ break;
+ case OPCODE_SCISSOR:
+ CALL_Scissor(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));
+ break;
+ case OPCODE_SHADE_MODEL:
+ CALL_ShadeModel(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_PROVOKING_VERTEX:
+ CALL_ProvokingVertexEXT(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_BEGIN_TRANSFORM_FEEDBACK:
+ CALL_BeginTransformFeedbackEXT(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_END_TRANSFORM_FEEDBACK:
+ CALL_EndTransformFeedbackEXT(ctx->Exec, ());
+ break;
+ case OPCODE_STENCIL_FUNC:
+ CALL_StencilFunc(ctx->Exec, (n[1].e, n[2].i, n[3].ui));
+ break;
+ case OPCODE_STENCIL_MASK:
+ CALL_StencilMask(ctx->Exec, (n[1].ui));
+ break;
+ case OPCODE_STENCIL_OP:
+ CALL_StencilOp(ctx->Exec, (n[1].e, n[2].e, n[3].e));
+ break;
+ case OPCODE_STENCIL_FUNC_SEPARATE:
+ CALL_StencilFuncSeparate(ctx->Exec,
+ (n[1].e, n[2].e, n[3].i, n[4].ui));
+ break;
+ case OPCODE_STENCIL_MASK_SEPARATE:
+ CALL_StencilMaskSeparate(ctx->Exec, (n[1].e, n[2].ui));
+ break;
+ case OPCODE_STENCIL_OP_SEPARATE:
+ CALL_StencilOpSeparate(ctx->Exec,
+ (n[1].e, n[2].e, n[3].e, n[4].e));
+ break;
+ case OPCODE_TEXENV:
+ {
+ GLfloat params[4];
+ params[0] = n[3].f;
+ params[1] = n[4].f;
+ params[2] = n[5].f;
+ params[3] = n[6].f;
+ CALL_TexEnvfv(ctx->Exec, (n[1].e, n[2].e, params));
+ }
+ break;
+ case OPCODE_TEXGEN:
+ {
+ GLfloat params[4];
+ params[0] = n[3].f;
+ params[1] = n[4].f;
+ params[2] = n[5].f;
+ params[3] = n[6].f;
+ CALL_TexGenfv(ctx->Exec, (n[1].e, n[2].e, params));
+ }
+ break;
+ case OPCODE_TEXPARAMETER:
+ {
+ GLfloat params[4];
+ params[0] = n[3].f;
+ params[1] = n[4].f;
+ params[2] = n[5].f;
+ params[3] = n[6].f;
+ CALL_TexParameterfv(ctx->Exec, (n[1].e, n[2].e, params));
+ }
+ break;
+ case OPCODE_TEX_IMAGE1D:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_TexImage1D(ctx->Exec, (n[1].e, /* target */
+ n[2].i, /* level */
+ n[3].i, /* components */
+ n[4].i, /* width */
+ n[5].e, /* border */
+ n[6].e, /* format */
+ n[7].e, /* type */
+ n[8].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_TEX_IMAGE2D:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_TexImage2D(ctx->Exec, (n[1].e, /* target */
+ n[2].i, /* level */
+ n[3].i, /* components */
+ n[4].i, /* width */
+ n[5].i, /* height */
+ n[6].e, /* border */
+ n[7].e, /* format */
+ n[8].e, /* type */
+ n[9].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_TEX_IMAGE3D:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_TexImage3D(ctx->Exec, (n[1].e, /* target */
+ n[2].i, /* level */
+ n[3].i, /* components */
+ n[4].i, /* width */
+ n[5].i, /* height */
+ n[6].i, /* depth */
+ n[7].e, /* border */
+ n[8].e, /* format */
+ n[9].e, /* type */
+ n[10].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_TEX_SUB_IMAGE1D:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_TexSubImage1D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
+ n[4].i, n[5].e,
+ n[6].e, n[7].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_TEX_SUB_IMAGE2D:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_TexSubImage2D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
+ n[4].i, n[5].e,
+ n[6].i, n[7].e, n[8].e,
+ n[9].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_TEX_SUB_IMAGE3D:
+ {
+ const struct gl_pixelstore_attrib save = ctx->Unpack;
+ ctx->Unpack = ctx->DefaultPacking;
+ CALL_TexSubImage3D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
+ n[4].i, n[5].i, n[6].i, n[7].i,
+ n[8].i, n[9].e, n[10].e,
+ n[11].data));
+ ctx->Unpack = save; /* restore */
+ }
+ break;
+ case OPCODE_TRANSLATE:
+ CALL_Translatef(ctx->Exec, (n[1].f, n[2].f, n[3].f));
+ break;
+ case OPCODE_VIEWPORT:
+ CALL_Viewport(ctx->Exec, (n[1].i, n[2].i,
+ (GLsizei) n[3].i, (GLsizei) n[4].i));
+ break;
+ case OPCODE_WINDOW_POS:
+ CALL_WindowPos4fMESA(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
+ break;
+ case OPCODE_ACTIVE_TEXTURE: /* GL_ARB_multitexture */
+ CALL_ActiveTextureARB(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_COMPRESSED_TEX_IMAGE_1D: /* GL_ARB_texture_compression */
+ CALL_CompressedTexImage1DARB(ctx->Exec, (n[1].e, n[2].i, n[3].e,
+ n[4].i, n[5].i, n[6].i,
+ n[7].data));
+ break;
+ case OPCODE_COMPRESSED_TEX_IMAGE_2D: /* GL_ARB_texture_compression */
+ CALL_CompressedTexImage2DARB(ctx->Exec, (n[1].e, n[2].i, n[3].e,
+ n[4].i, n[5].i, n[6].i,
+ n[7].i, n[8].data));
+ break;
+ case OPCODE_COMPRESSED_TEX_IMAGE_3D: /* GL_ARB_texture_compression */
+ CALL_CompressedTexImage3DARB(ctx->Exec, (n[1].e, n[2].i, n[3].e,
+ n[4].i, n[5].i, n[6].i,
+ n[7].i, n[8].i,
+ n[9].data));
+ break;
+ case OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D: /* GL_ARB_texture_compress */
+ CALL_CompressedTexSubImage1DARB(ctx->Exec,
+ (n[1].e, n[2].i, n[3].i, n[4].i,
+ n[5].e, n[6].i, n[7].data));
+ break;
+ case OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D: /* GL_ARB_texture_compress */
+ CALL_CompressedTexSubImage2DARB(ctx->Exec,
+ (n[1].e, n[2].i, n[3].i, n[4].i,
+ n[5].i, n[6].i, n[7].e, n[8].i,
+ n[9].data));
+ break;
+ case OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D: /* GL_ARB_texture_compress */
+ CALL_CompressedTexSubImage3DARB(ctx->Exec,
+ (n[1].e, n[2].i, n[3].i, n[4].i,
+ n[5].i, n[6].i, n[7].i, n[8].i,
+ n[9].e, n[10].i, n[11].data));
+ break;
+ case OPCODE_SAMPLE_COVERAGE: /* GL_ARB_multisample */
+ CALL_SampleCoverageARB(ctx->Exec, (n[1].f, n[2].b));
+ break;
+ case OPCODE_WINDOW_POS_ARB: /* GL_ARB_window_pos */
+ CALL_WindowPos3fMESA(ctx->Exec, (n[1].f, n[2].f, n[3].f));
+ break;
+#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+ case OPCODE_BIND_PROGRAM_NV: /* GL_NV_vertex_program */
+ CALL_BindProgramNV(ctx->Exec, (n[1].e, n[2].ui));
+ break;
+#endif
+#if FEATURE_NV_vertex_program
+ case OPCODE_EXECUTE_PROGRAM_NV:
+ {
+ GLfloat v[4];
+ v[0] = n[3].f;
+ v[1] = n[4].f;
+ v[2] = n[5].f;
+ v[3] = n[6].f;
+ CALL_ExecuteProgramNV(ctx->Exec, (n[1].e, n[2].ui, v));
+ }
+ break;
+ case OPCODE_REQUEST_RESIDENT_PROGRAMS_NV:
+ CALL_RequestResidentProgramsNV(ctx->Exec, (n[1].ui,
+ (GLuint *) n[2].data));
+ break;
+ case OPCODE_LOAD_PROGRAM_NV:
+ CALL_LoadProgramNV(ctx->Exec, (n[1].e, n[2].ui, n[3].i,
+ (const GLubyte *) n[4].data));
+ break;
+ case OPCODE_TRACK_MATRIX_NV:
+ CALL_TrackMatrixNV(ctx->Exec, (n[1].e, n[2].ui, n[3].e, n[4].e));
+ break;
+#endif
+
+#if FEATURE_NV_fragment_program
+ case OPCODE_PROGRAM_LOCAL_PARAMETER_ARB:
+ CALL_ProgramLocalParameter4fARB(ctx->Exec,
+ (n[1].e, n[2].ui, n[3].f, n[4].f,
+ n[5].f, n[6].f));
+ break;
+ case OPCODE_PROGRAM_NAMED_PARAMETER_NV:
+ CALL_ProgramNamedParameter4fNV(ctx->Exec, (n[1].ui, n[2].i,
+ (const GLubyte *) n[3].
+ data, n[4].f, n[5].f,
+ n[6].f, n[7].f));
+ break;
+#endif
+
+ case OPCODE_ACTIVE_STENCIL_FACE_EXT:
+ CALL_ActiveStencilFaceEXT(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_DEPTH_BOUNDS_EXT:
+ CALL_DepthBoundsEXT(ctx->Exec, (n[1].f, n[2].f));
+ break;
+#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+ case OPCODE_PROGRAM_STRING_ARB:
+ CALL_ProgramStringARB(ctx->Exec,
+ (n[1].e, n[2].e, n[3].i, n[4].data));
+ break;
+#endif
+#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program || FEATURE_NV_vertex_program
+ case OPCODE_PROGRAM_ENV_PARAMETER_ARB:
+ CALL_ProgramEnvParameter4fARB(ctx->Exec, (n[1].e, n[2].ui, n[3].f,
+ n[4].f, n[5].f,
+ n[6].f));
+ break;
+#endif
+#if FEATURE_queryobj
+ case OPCODE_BEGIN_QUERY_ARB:
+ CALL_BeginQueryARB(ctx->Exec, (n[1].e, n[2].ui));
+ break;
+ case OPCODE_END_QUERY_ARB:
+ CALL_EndQueryARB(ctx->Exec, (n[1].e));
+ break;
+#endif
+ case OPCODE_DRAW_BUFFERS_ARB:
+ {
+ GLenum buffers[MAX_DRAW_BUFFERS];
+ GLint i, count = MIN2(n[1].i, MAX_DRAW_BUFFERS);
+ for (i = 0; i < count; i++)
+ buffers[i] = n[2 + i].e;
+ CALL_DrawBuffersARB(ctx->Exec, (n[1].i, buffers));
+ }
+ break;
+#if FEATURE_EXT_framebuffer_blit
+ case OPCODE_BLIT_FRAMEBUFFER:
+ CALL_BlitFramebufferEXT(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i,
+ n[5].i, n[6].i, n[7].i, n[8].i,
+ n[9].i, n[10].e));
+ break;
+#endif
+
+ case OPCODE_USE_PROGRAM:
+ CALL_UseProgramObjectARB(ctx->Exec, (n[1].ui));
+ break;
+ case OPCODE_USE_SHADER_PROGRAM_EXT:
+ CALL_UseShaderProgramEXT(ctx->Exec, (n[1].ui, n[2].ui));
+ break;
+ case OPCODE_ACTIVE_PROGRAM_EXT:
+ CALL_ActiveProgramEXT(ctx->Exec, (n[1].ui));
+ break;
+ case OPCODE_UNIFORM_1F:
+ CALL_Uniform1fARB(ctx->Exec, (n[1].i, n[2].f));
+ break;
+ case OPCODE_UNIFORM_2F:
+ CALL_Uniform2fARB(ctx->Exec, (n[1].i, n[2].f, n[3].f));
+ break;
+ case OPCODE_UNIFORM_3F:
+ CALL_Uniform3fARB(ctx->Exec, (n[1].i, n[2].f, n[3].f, n[4].f));
+ break;
+ case OPCODE_UNIFORM_4F:
+ CALL_Uniform4fARB(ctx->Exec,
+ (n[1].i, n[2].f, n[3].f, n[4].f, n[5].f));
+ break;
+ case OPCODE_UNIFORM_1FV:
+ CALL_Uniform1fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
+ break;
+ case OPCODE_UNIFORM_2FV:
+ CALL_Uniform2fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
+ break;
+ case OPCODE_UNIFORM_3FV:
+ CALL_Uniform3fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
+ break;
+ case OPCODE_UNIFORM_4FV:
+ CALL_Uniform4fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
+ break;
+ case OPCODE_UNIFORM_1I:
+ CALL_Uniform1iARB(ctx->Exec, (n[1].i, n[2].i));
+ break;
+ case OPCODE_UNIFORM_2I:
+ CALL_Uniform2iARB(ctx->Exec, (n[1].i, n[2].i, n[3].i));
+ break;
+ case OPCODE_UNIFORM_3I:
+ CALL_Uniform3iARB(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));
+ break;
+ case OPCODE_UNIFORM_4I:
+ CALL_Uniform4iARB(ctx->Exec,
+ (n[1].i, n[2].i, n[3].i, n[4].i, n[5].i));
+ break;
+ case OPCODE_UNIFORM_1IV:
+ CALL_Uniform1ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
+ break;
+ case OPCODE_UNIFORM_2IV:
+ CALL_Uniform2ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
+ break;
+ case OPCODE_UNIFORM_3IV:
+ CALL_Uniform3ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
+ break;
+ case OPCODE_UNIFORM_4IV:
+ CALL_Uniform4ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
+ break;
+ case OPCODE_UNIFORM_1UI:
+ /*CALL_Uniform1uiARB(ctx->Exec, (n[1].i, n[2].i));*/
+ break;
+ case OPCODE_UNIFORM_2UI:
+ /*CALL_Uniform2uiARB(ctx->Exec, (n[1].i, n[2].i, n[3].i));*/
+ break;
+ case OPCODE_UNIFORM_3UI:
+ /*CALL_Uniform3uiARB(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));*/
+ break;
+ case OPCODE_UNIFORM_4UI:
+ /*CALL_Uniform4uiARB(ctx->Exec,
+ (n[1].i, n[2].i, n[3].i, n[4].i, n[5].i));
+ */
+ break;
+ case OPCODE_UNIFORM_1UIV:
+ /*CALL_Uniform1uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
+ break;
+ case OPCODE_UNIFORM_2UIV:
+ /*CALL_Uniform2uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
+ break;
+ case OPCODE_UNIFORM_3UIV:
+ /*CALL_Uniform3uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
+ break;
+ case OPCODE_UNIFORM_4UIV:
+ /*CALL_Uniform4uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
+ break;
+ case OPCODE_UNIFORM_MATRIX22:
+ CALL_UniformMatrix2fvARB(ctx->Exec,
+ (n[1].i, n[2].i, n[3].b, n[4].data));
+ break;
+ case OPCODE_UNIFORM_MATRIX33:
+ CALL_UniformMatrix3fvARB(ctx->Exec,
+ (n[1].i, n[2].i, n[3].b, n[4].data));
+ break;
+ case OPCODE_UNIFORM_MATRIX44:
+ CALL_UniformMatrix4fvARB(ctx->Exec,
+ (n[1].i, n[2].i, n[3].b, n[4].data));
+ break;
+ case OPCODE_UNIFORM_MATRIX23:
+ CALL_UniformMatrix2x3fv(ctx->Exec,
+ (n[1].i, n[2].i, n[3].b, n[4].data));
+ break;
+ case OPCODE_UNIFORM_MATRIX32:
+ CALL_UniformMatrix3x2fv(ctx->Exec,
+ (n[1].i, n[2].i, n[3].b, n[4].data));
+ break;
+ case OPCODE_UNIFORM_MATRIX24:
+ CALL_UniformMatrix2x4fv(ctx->Exec,
+ (n[1].i, n[2].i, n[3].b, n[4].data));
+ break;
+ case OPCODE_UNIFORM_MATRIX42:
+ CALL_UniformMatrix4x2fv(ctx->Exec,
+ (n[1].i, n[2].i, n[3].b, n[4].data));
+ break;
+ case OPCODE_UNIFORM_MATRIX34:
+ CALL_UniformMatrix3x4fv(ctx->Exec,
+ (n[1].i, n[2].i, n[3].b, n[4].data));
+ break;
+ case OPCODE_UNIFORM_MATRIX43:
+ CALL_UniformMatrix4x3fv(ctx->Exec,
+ (n[1].i, n[2].i, n[3].b, n[4].data));
+ break;
+
+ case OPCODE_TEX_BUMP_PARAMETER_ATI:
+ {
+ GLfloat values[4];
+ GLuint i, pname = n[1].ui;
+
+ for (i = 0; i < 4; i++)
+ values[i] = n[1 + i].f;
+ CALL_TexBumpParameterfvATI(ctx->Exec, (pname, values));
+ }
+ break;
+#if FEATURE_ATI_fragment_shader
+ case OPCODE_BIND_FRAGMENT_SHADER_ATI:
+ CALL_BindFragmentShaderATI(ctx->Exec, (n[1].i));
+ break;
+ case OPCODE_SET_FRAGMENT_SHADER_CONSTANTS_ATI:
+ {
+ GLfloat values[4];
+ GLuint i, dst = n[1].ui;
+
+ for (i = 0; i < 4; i++)
+ values[i] = n[1 + i].f;
+ CALL_SetFragmentShaderConstantATI(ctx->Exec, (dst, values));
+ }
+ break;
+#endif
+ case OPCODE_ATTR_1F_NV:
+ CALL_VertexAttrib1fNV(ctx->Exec, (n[1].e, n[2].f));
+ break;
+ case OPCODE_ATTR_2F_NV:
+ /* Really shouldn't have to do this - the Node structure
+ * is convenient, but it would be better to store the data
+ * packed appropriately so that it can be sent directly
+ * on. With x86_64 becoming common, this will start to
+ * matter more.
+ */
+ if (sizeof(Node) == sizeof(GLfloat))
+ CALL_VertexAttrib2fvNV(ctx->Exec, (n[1].e, &n[2].f));
+ else
+ CALL_VertexAttrib2fNV(ctx->Exec, (n[1].e, n[2].f, n[3].f));
+ break;
+ case OPCODE_ATTR_3F_NV:
+ if (sizeof(Node) == sizeof(GLfloat))
+ CALL_VertexAttrib3fvNV(ctx->Exec, (n[1].e, &n[2].f));
+ else
+ CALL_VertexAttrib3fNV(ctx->Exec, (n[1].e, n[2].f, n[3].f,
+ n[4].f));
+ break;
+ case OPCODE_ATTR_4F_NV:
+ if (sizeof(Node) == sizeof(GLfloat))
+ CALL_VertexAttrib4fvNV(ctx->Exec, (n[1].e, &n[2].f));
+ else
+ CALL_VertexAttrib4fNV(ctx->Exec, (n[1].e, n[2].f, n[3].f,
+ n[4].f, n[5].f));
+ break;
+ case OPCODE_ATTR_1F_ARB:
+ CALL_VertexAttrib1fARB(ctx->Exec, (n[1].e, n[2].f));
+ break;
+ case OPCODE_ATTR_2F_ARB:
+ /* Really shouldn't have to do this - the Node structure
+ * is convenient, but it would be better to store the data
+ * packed appropriately so that it can be sent directly
+ * on. With x86_64 becoming common, this will start to
+ * matter more.
+ */
+ if (sizeof(Node) == sizeof(GLfloat))
+ CALL_VertexAttrib2fvARB(ctx->Exec, (n[1].e, &n[2].f));
+ else
+ CALL_VertexAttrib2fARB(ctx->Exec, (n[1].e, n[2].f, n[3].f));
+ break;
+ case OPCODE_ATTR_3F_ARB:
+ if (sizeof(Node) == sizeof(GLfloat))
+ CALL_VertexAttrib3fvARB(ctx->Exec, (n[1].e, &n[2].f));
+ else
+ CALL_VertexAttrib3fARB(ctx->Exec, (n[1].e, n[2].f, n[3].f,
+ n[4].f));
+ break;
+ case OPCODE_ATTR_4F_ARB:
+ if (sizeof(Node) == sizeof(GLfloat))
+ CALL_VertexAttrib4fvARB(ctx->Exec, (n[1].e, &n[2].f));
+ else
+ CALL_VertexAttrib4fARB(ctx->Exec, (n[1].e, n[2].f, n[3].f,
+ n[4].f, n[5].f));
+ break;
+ case OPCODE_MATERIAL:
+ if (sizeof(Node) == sizeof(GLfloat))
+ CALL_Materialfv(ctx->Exec, (n[1].e, n[2].e, &n[3].f));
+ else {
+ GLfloat f[4];
+ f[0] = n[3].f;
+ f[1] = n[4].f;
+ f[2] = n[5].f;
+ f[3] = n[6].f;
+ CALL_Materialfv(ctx->Exec, (n[1].e, n[2].e, f));
+ }
+ break;
+ case OPCODE_BEGIN:
+ CALL_Begin(ctx->Exec, (n[1].e));
+ break;
+ case OPCODE_END:
+ CALL_End(ctx->Exec, ());
+ break;
+ case OPCODE_RECTF:
+ CALL_Rectf(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
+ break;
+ case OPCODE_EVAL_C1:
+ CALL_EvalCoord1f(ctx->Exec, (n[1].f));
+ break;
+ case OPCODE_EVAL_C2:
+ CALL_EvalCoord2f(ctx->Exec, (n[1].f, n[2].f));
+ break;
+ case OPCODE_EVAL_P1:
+ CALL_EvalPoint1(ctx->Exec, (n[1].i));
+ break;
+ case OPCODE_EVAL_P2:
+ CALL_EvalPoint2(ctx->Exec, (n[1].i, n[2].i));
+ break;
+
+ /* GL_EXT_texture_integer */
+ case OPCODE_CLEARCOLOR_I:
+ CALL_ClearColorIiEXT(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));
+ break;
+ case OPCODE_CLEARCOLOR_UI:
+ CALL_ClearColorIuiEXT(ctx->Exec,
+ (n[1].ui, n[2].ui, n[3].ui, n[4].ui));
+ break;
+ case OPCODE_TEXPARAMETER_I:
+ {
+ GLint params[4];
+ params[0] = n[3].i;
+ params[1] = n[4].i;
+ params[2] = n[5].i;
+ params[3] = n[6].i;
+ CALL_TexParameterIivEXT(ctx->Exec, (n[1].e, n[2].e, params));
+ }
+ break;
+ case OPCODE_TEXPARAMETER_UI:
+ {
+ GLuint params[4];
+ params[0] = n[3].ui;
+ params[1] = n[4].ui;
+ params[2] = n[5].ui;
+ params[3] = n[6].ui;
+ CALL_TexParameterIuivEXT(ctx->Exec, (n[1].e, n[2].e, params));
+ }
+ break;
+
+ case OPCODE_VERTEX_ATTRIB_DIVISOR:
+ /* GL_ARB_instanced_arrays */
+ CALL_VertexAttribDivisorARB(ctx->Exec, (n[1].ui, n[2].ui));
+ break;
+
+ case OPCODE_CONTINUE:
+ n = (Node *) n[1].next;
+ break;
+ case OPCODE_END_OF_LIST:
+ done = GL_TRUE;
+ break;
+ default:
+ {
+ char msg[1000];
+ _mesa_snprintf(msg, sizeof(msg), "Error in execute_list: opcode=%d",
+ (int) opcode);
+ _mesa_problem(ctx, "%s", msg);
+ }
+ done = GL_TRUE;
+ }
+
+ /* increment n to point to next compiled command */
+ if (opcode != OPCODE_CONTINUE) {
+ n += InstSize[opcode];
+ }
+ }
+ }
+
+ if (ctx->Driver.EndCallList)
+ ctx->Driver.EndCallList(ctx);
+
+ ctx->ListState.CallDepth--;
+}
+
+
+
+/**********************************************************************/
+/* GL functions */
+/**********************************************************************/
+
+/**
+ * Test if a display list number is valid.
+ */
+static GLboolean GLAPIENTRY
+_mesa_IsList(GLuint list)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0); /* must be called before assert */
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
+ return islist(ctx, list);
+}
+
+
+/**
+ * Delete a sequence of consecutive display lists.
+ */
+static void GLAPIENTRY
+_mesa_DeleteLists(GLuint list, GLsizei range)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint i;
+ FLUSH_VERTICES(ctx, 0); /* must be called before assert */
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (range < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteLists");
+ return;
+ }
+ for (i = list; i < list + range; i++) {
+ destroy_list(ctx, i);
+ }
+}
+
+
+/**
+ * Return a display list number, n, such that lists n through n+range-1
+ * are free.
+ */
+static GLuint GLAPIENTRY
+_mesa_GenLists(GLsizei range)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint base;
+ FLUSH_VERTICES(ctx, 0); /* must be called before assert */
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
+
+ if (range < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGenLists");
+ return 0;
+ }
+ if (range == 0) {
+ return 0;
+ }
+
+ /*
+ * Make this an atomic operation
+ */
+ _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+
+ base = _mesa_HashFindFreeKeyBlock(ctx->Shared->DisplayList, range);
+ if (base) {
+ /* reserve the list IDs by with empty/dummy lists */
+ GLint i;
+ for (i = 0; i < range; i++) {
+ _mesa_HashInsert(ctx->Shared->DisplayList, base + i,
+ make_list(base + i, 1));
+ }
+ }
+
+ _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+
+ return base;
+}
+
+
+/**
+ * Begin a new display list.
+ */
+static void GLAPIENTRY
+_mesa_NewList(GLuint name, GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ FLUSH_CURRENT(ctx, 0); /* must be called before assert */
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glNewList %u %s\n", name,
+ _mesa_lookup_enum_by_nr(mode));
+
+ if (name == 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glNewList");
+ return;
+ }
+
+ if (mode != GL_COMPILE && mode != GL_COMPILE_AND_EXECUTE) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glNewList");
+ return;
+ }
+
+ if (ctx->ListState.CurrentList) {
+ /* already compiling a display list */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glNewList");
+ return;
+ }
+
+ ctx->CompileFlag = GL_TRUE;
+ ctx->ExecuteFlag = (mode == GL_COMPILE_AND_EXECUTE);
+
+ /* Reset acumulated list state:
+ */
+ invalidate_saved_current_state( ctx );
+
+ /* Allocate new display list */
+ ctx->ListState.CurrentList = make_list(name, BLOCK_SIZE);
+ ctx->ListState.CurrentBlock = ctx->ListState.CurrentList->Head;
+ ctx->ListState.CurrentPos = 0;
+
+ ctx->Driver.NewList(ctx, name, mode);
+
+ ctx->CurrentDispatch = ctx->Save;
+ _glapi_set_dispatch(ctx->CurrentDispatch);
+}
+
+
+/**
+ * End definition of current display list.
+ */
+static void GLAPIENTRY
+_mesa_EndList(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ SAVE_FLUSH_VERTICES(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glEndList\n");
+
+ /* Check that a list is under construction */
+ if (!ctx->ListState.CurrentList) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glEndList");
+ return;
+ }
+
+ /* Call before emitting END_OF_LIST, in case the driver wants to
+ * emit opcodes itself.
+ */
+ ctx->Driver.EndList(ctx);
+
+ (void) alloc_instruction(ctx, OPCODE_END_OF_LIST, 0);
+
+ /* Destroy old list, if any */
+ destroy_list(ctx, ctx->ListState.CurrentList->Name);
+
+ /* Install the new list */
+ _mesa_HashInsert(ctx->Shared->DisplayList,
+ ctx->ListState.CurrentList->Name,
+ ctx->ListState.CurrentList);
+
+
+ if (MESA_VERBOSE & VERBOSE_DISPLAY_LIST)
+ mesa_print_display_list(ctx->ListState.CurrentList->Name);
+
+ ctx->ListState.CurrentList = NULL;
+ ctx->ExecuteFlag = GL_TRUE;
+ ctx->CompileFlag = GL_FALSE;
+
+ ctx->CurrentDispatch = ctx->Exec;
+ _glapi_set_dispatch(ctx->CurrentDispatch);
+}
+
+
+void GLAPIENTRY
+_mesa_CallList(GLuint list)
+{
+ GLboolean save_compile_flag;
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_CURRENT(ctx, 0);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glCallList %d\n", list);
+
+ if (list == 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glCallList(list==0)");
+ return;
+ }
+
+ if (0)
+ mesa_print_display_list( list );
+
+ /* VERY IMPORTANT: Save the CompileFlag status, turn it off,
+ * execute the display list, and restore the CompileFlag.
+ */
+ save_compile_flag = ctx->CompileFlag;
+ if (save_compile_flag) {
+ ctx->CompileFlag = GL_FALSE;
+ }
+
+ execute_list(ctx, list);
+ ctx->CompileFlag = save_compile_flag;
+
+ /* also restore API function pointers to point to "save" versions */
+ if (save_compile_flag) {
+ ctx->CurrentDispatch = ctx->Save;
+ _glapi_set_dispatch(ctx->CurrentDispatch);
+ }
+}
+
+
+/**
+ * Execute glCallLists: call multiple display lists.
+ */
+void GLAPIENTRY
+_mesa_CallLists(GLsizei n, GLenum type, const GLvoid * lists)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+ GLboolean save_compile_flag;
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glCallLists %d\n", n);
+
+ switch (type) {
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ case GL_SHORT:
+ case GL_UNSIGNED_SHORT:
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ case GL_FLOAT:
+ case GL_2_BYTES:
+ case GL_3_BYTES:
+ case GL_4_BYTES:
+ /* OK */
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCallLists(type)");
+ return;
+ }
+
+ /* Save the CompileFlag status, turn it off, execute display list,
+ * and restore the CompileFlag.
+ */
+ save_compile_flag = ctx->CompileFlag;
+ ctx->CompileFlag = GL_FALSE;
+
+ for (i = 0; i < n; i++) {
+ GLuint list = (GLuint) (ctx->List.ListBase + translate_id(i, type, lists));
+ execute_list(ctx, list);
+ }
+
+ ctx->CompileFlag = save_compile_flag;
+
+ /* also restore API function pointers to point to "save" versions */
+ if (save_compile_flag) {
+ ctx->CurrentDispatch = ctx->Save;
+ _glapi_set_dispatch(ctx->CurrentDispatch);
+ }
+}
+
+
+/**
+ * Set the offset added to list numbers in glCallLists.
+ */
+static void GLAPIENTRY
+_mesa_ListBase(GLuint base)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0); /* must be called before assert */
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+ ctx->List.ListBase = base;
+}
+
+
+/* Can no longer assume ctx->Exec->Func is equal to _mesa_Func.
+ */
+static void GLAPIENTRY
+exec_Finish(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_Finish(ctx->Exec, ());
+}
+
+static void GLAPIENTRY
+exec_Flush(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_Flush(ctx->Exec, ());
+}
+
+static void GLAPIENTRY
+exec_GetBooleanv(GLenum pname, GLboolean *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetBooleanv(ctx->Exec, (pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetClipPlane(GLenum plane, GLdouble * equation)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetClipPlane(ctx->Exec, (plane, equation));
+}
+
+static void GLAPIENTRY
+exec_GetDoublev(GLenum pname, GLdouble *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetDoublev(ctx->Exec, (pname, params));
+}
+
+static GLenum GLAPIENTRY
+exec_GetError(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ return CALL_GetError(ctx->Exec, ());
+}
+
+static void GLAPIENTRY
+exec_GetFloatv(GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetFloatv(ctx->Exec, (pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetIntegerv(GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetIntegerv(ctx->Exec, (pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetLightfv(GLenum light, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetLightfv(ctx->Exec, (light, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetLightiv(GLenum light, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetLightiv(ctx->Exec, (light, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetMapdv(GLenum target, GLenum query, GLdouble * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetMapdv(ctx->Exec, (target, query, v));
+}
+
+static void GLAPIENTRY
+exec_GetMapfv(GLenum target, GLenum query, GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetMapfv(ctx->Exec, (target, query, v));
+}
+
+static void GLAPIENTRY
+exec_GetMapiv(GLenum target, GLenum query, GLint * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetMapiv(ctx->Exec, (target, query, v));
+}
+
+static void GLAPIENTRY
+exec_GetMaterialfv(GLenum face, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetMaterialfv(ctx->Exec, (face, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetMaterialiv(GLenum face, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetMaterialiv(ctx->Exec, (face, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetPixelMapfv(GLenum map, GLfloat *values)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetPixelMapfv(ctx->Exec, (map, values));
+}
+
+static void GLAPIENTRY
+exec_GetPixelMapuiv(GLenum map, GLuint *values)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetPixelMapuiv(ctx->Exec, (map, values));
+}
+
+static void GLAPIENTRY
+exec_GetPixelMapusv(GLenum map, GLushort *values)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetPixelMapusv(ctx->Exec, (map, values));
+}
+
+static void GLAPIENTRY
+exec_GetPolygonStipple(GLubyte * dest)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetPolygonStipple(ctx->Exec, (dest));
+}
+
+static const GLubyte *GLAPIENTRY
+exec_GetString(GLenum name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ return CALL_GetString(ctx->Exec, (name));
+}
+
+static void GLAPIENTRY
+exec_GetTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexEnvfv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetTexEnviv(GLenum target, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexEnviv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetTexGendv(GLenum coord, GLenum pname, GLdouble *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexGendv(ctx->Exec, (coord, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetTexGenfv(GLenum coord, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexGenfv(ctx->Exec, (coord, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetTexGeniv(GLenum coord, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexGeniv(ctx->Exec, (coord, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetTexImage(GLenum target, GLint level, GLenum format,
+ GLenum type, GLvoid * pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexImage(ctx->Exec, (target, level, format, type, pixels));
+}
+
+static void GLAPIENTRY
+exec_GetTexLevelParameterfv(GLenum target, GLint level,
+ GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexLevelParameterfv(ctx->Exec, (target, level, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetTexLevelParameteriv(GLenum target, GLint level,
+ GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexLevelParameteriv(ctx->Exec, (target, level, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexParameterfv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetTexParameteriv(ctx->Exec, (target, pname, params));
+}
+
+static GLboolean GLAPIENTRY
+exec_IsEnabled(GLenum cap)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ return CALL_IsEnabled(ctx->Exec, (cap));
+}
+
+static void GLAPIENTRY
+exec_PixelStoref(GLenum pname, GLfloat param)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_PixelStoref(ctx->Exec, (pname, param));
+}
+
+static void GLAPIENTRY
+exec_PixelStorei(GLenum pname, GLint param)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_PixelStorei(ctx->Exec, (pname, param));
+}
+
+static void GLAPIENTRY
+exec_ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type, GLvoid * pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_ReadPixels(ctx->Exec, (x, y, width, height, format, type, pixels));
+}
+
+static GLint GLAPIENTRY
+exec_RenderMode(GLenum mode)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ return CALL_RenderMode(ctx->Exec, (mode));
+}
+
+static void GLAPIENTRY
+exec_FeedbackBuffer(GLsizei size, GLenum type, GLfloat * buffer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_FeedbackBuffer(ctx->Exec, (size, type, buffer));
+}
+
+static void GLAPIENTRY
+exec_SelectBuffer(GLsizei size, GLuint * buffer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_SelectBuffer(ctx->Exec, (size, buffer));
+}
+
+static GLboolean GLAPIENTRY
+exec_AreTexturesResident(GLsizei n, const GLuint * texName,
+ GLboolean * residences)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ return CALL_AreTexturesResident(ctx->Exec, (n, texName, residences));
+}
+
+static void GLAPIENTRY
+exec_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_ColorPointer(ctx->Exec, (size, type, stride, ptr));
+}
+
+static void GLAPIENTRY
+exec_DeleteTextures(GLsizei n, const GLuint * texName)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_DeleteTextures(ctx->Exec, (n, texName));
+}
+
+static void GLAPIENTRY
+exec_DisableClientState(GLenum cap)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_DisableClientState(ctx->Exec, (cap));
+}
+
+static void GLAPIENTRY
+exec_EdgeFlagPointer(GLsizei stride, const GLvoid * vptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_EdgeFlagPointer(ctx->Exec, (stride, vptr));
+}
+
+static void GLAPIENTRY
+exec_EnableClientState(GLenum cap)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_EnableClientState(ctx->Exec, (cap));
+}
+
+static void GLAPIENTRY
+exec_GenTextures(GLsizei n, GLuint * texName)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GenTextures(ctx->Exec, (n, texName));
+}
+
+static void GLAPIENTRY
+exec_GetPointerv(GLenum pname, GLvoid **params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetPointerv(ctx->Exec, (pname, params));
+}
+
+static void GLAPIENTRY
+exec_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_IndexPointer(ctx->Exec, (type, stride, ptr));
+}
+
+static void GLAPIENTRY
+exec_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid * pointer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_InterleavedArrays(ctx->Exec, (format, stride, pointer));
+}
+
+static GLboolean GLAPIENTRY
+exec_IsTexture(GLuint texture)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ return CALL_IsTexture(ctx->Exec, (texture));
+}
+
+static void GLAPIENTRY
+exec_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_NormalPointer(ctx->Exec, (type, stride, ptr));
+}
+
+static void GLAPIENTRY
+exec_PopClientAttrib(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_PopClientAttrib(ctx->Exec, ());
+}
+
+static void GLAPIENTRY
+exec_PushClientAttrib(GLbitfield mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_PushClientAttrib(ctx->Exec, (mask));
+}
+
+static void GLAPIENTRY
+exec_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
+ const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_TexCoordPointer(ctx->Exec, (size, type, stride, ptr));
+}
+
+static void GLAPIENTRY
+exec_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid * img)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetCompressedTexImageARB(ctx->Exec, (target, level, img));
+}
+
+static void GLAPIENTRY
+exec_VertexPointer(GLint size, GLenum type, GLsizei stride,
+ const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_VertexPointer(ctx->Exec, (size, type, stride, ptr));
+}
+
+static void GLAPIENTRY
+exec_CopyConvolutionFilter1D(GLenum target, GLenum internalFormat,
+ GLint x, GLint y, GLsizei width)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_CopyConvolutionFilter1D(ctx->Exec,
+ (target, internalFormat, x, y, width));
+}
+
+static void GLAPIENTRY
+exec_CopyConvolutionFilter2D(GLenum target, GLenum internalFormat,
+ GLint x, GLint y, GLsizei width, GLsizei height)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_CopyConvolutionFilter2D(ctx->Exec,
+ (target, internalFormat, x, y, width,
+ height));
+}
+
+static void GLAPIENTRY
+exec_GetColorTable(GLenum target, GLenum format, GLenum type, GLvoid * data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetColorTable(ctx->Exec, (target, format, type, data));
+}
+
+static void GLAPIENTRY
+exec_GetColorTableParameterfv(GLenum target, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetColorTableParameterfv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetColorTableParameteriv(GLenum target, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetColorTableParameteriv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetConvolutionFilter(GLenum target, GLenum format, GLenum type,
+ GLvoid * image)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetConvolutionFilter(ctx->Exec, (target, format, type, image));
+}
+
+static void GLAPIENTRY
+exec_GetConvolutionParameterfv(GLenum target, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetConvolutionParameterfv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetConvolutionParameteriv(GLenum target, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetConvolutionParameteriv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetHistogram(GLenum target, GLboolean reset, GLenum format,
+ GLenum type, GLvoid *values)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetHistogram(ctx->Exec, (target, reset, format, type, values));
+}
+
+static void GLAPIENTRY
+exec_GetHistogramParameterfv(GLenum target, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetHistogramParameterfv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetHistogramParameteriv(GLenum target, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetHistogramParameteriv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetMinmax(GLenum target, GLboolean reset, GLenum format,
+ GLenum type, GLvoid *values)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetMinmax(ctx->Exec, (target, reset, format, type, values));
+}
+
+static void GLAPIENTRY
+exec_GetMinmaxParameterfv(GLenum target, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetMinmaxParameterfv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetMinmaxParameteriv(GLenum target, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetMinmaxParameteriv(ctx->Exec, (target, pname, params));
+}
+
+static void GLAPIENTRY
+exec_GetSeparableFilter(GLenum target, GLenum format, GLenum type,
+ GLvoid *row, GLvoid *column, GLvoid *span)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_GetSeparableFilter(ctx->Exec,
+ (target, format, type, row, column, span));
+}
+
+static void GLAPIENTRY
+exec_SeparableFilter2D(GLenum target, GLenum internalFormat,
+ GLsizei width, GLsizei height, GLenum format,
+ GLenum type, const GLvoid *row, const GLvoid *column)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_SeparableFilter2D(ctx->Exec,
+ (target, internalFormat, width, height, format,
+ type, row, column));
+}
+
+static void GLAPIENTRY
+exec_ColorPointerEXT(GLint size, GLenum type, GLsizei stride,
+ GLsizei count, const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_ColorPointerEXT(ctx->Exec, (size, type, stride, count, ptr));
+}
+
+static void GLAPIENTRY
+exec_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_EdgeFlagPointerEXT(ctx->Exec, (stride, count, ptr));
+}
+
+static void GLAPIENTRY
+exec_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
+ const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_IndexPointerEXT(ctx->Exec, (type, stride, count, ptr));
+}
+
+static void GLAPIENTRY
+exec_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
+ const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_NormalPointerEXT(ctx->Exec, (type, stride, count, ptr));
+}
+
+static void GLAPIENTRY
+exec_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
+ GLsizei count, const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_TexCoordPointerEXT(ctx->Exec, (size, type, stride, count, ptr));
+}
+
+static void GLAPIENTRY
+exec_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
+ GLsizei count, const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_VertexPointerEXT(ctx->Exec, (size, type, stride, count, ptr));
+}
+
+static void GLAPIENTRY
+exec_LockArraysEXT(GLint first, GLsizei count)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_LockArraysEXT(ctx->Exec, (first, count));
+}
+
+static void GLAPIENTRY
+exec_UnlockArraysEXT(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_UnlockArraysEXT(ctx->Exec, ());
+}
+
+static void GLAPIENTRY
+exec_ClientActiveTextureARB(GLenum target)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_ClientActiveTextureARB(ctx->Exec, (target));
+}
+
+static void GLAPIENTRY
+exec_SecondaryColorPointerEXT(GLint size, GLenum type,
+ GLsizei stride, const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_SecondaryColorPointerEXT(ctx->Exec, (size, type, stride, ptr));
+}
+
+static void GLAPIENTRY
+exec_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_FogCoordPointerEXT(ctx->Exec, (type, stride, ptr));
+}
+
+/* GL_EXT_multi_draw_arrays */
+static void GLAPIENTRY
+exec_MultiDrawArraysEXT(GLenum mode, const GLint *first,
+ const GLsizei *count, GLsizei primcount)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_MultiDrawArraysEXT(ctx->Exec, (mode, first, count, primcount));
+}
+
+/* GL_IBM_multimode_draw_arrays */
+static void GLAPIENTRY
+exec_MultiModeDrawArraysIBM(const GLenum * mode, const GLint * first,
+ const GLsizei * count, GLsizei primcount,
+ GLint modestride)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_MultiModeDrawArraysIBM(ctx->Exec,
+ (mode, first, count, primcount, modestride));
+}
+
+/* GL_IBM_multimode_draw_arrays */
+static void GLAPIENTRY
+exec_MultiModeDrawElementsIBM(const GLenum * mode,
+ const GLsizei * count,
+ GLenum type,
+ const GLvoid * const *indices,
+ GLsizei primcount, GLint modestride)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ FLUSH_VERTICES(ctx, 0);
+ CALL_MultiModeDrawElementsIBM(ctx->Exec,
+ (mode, count, type, indices, primcount,
+ modestride));
+}
+
+
+
+/**
+ * Setup the given dispatch table to point to Mesa's display list
+ * building functions.
+ *
+ * This does not include any of the tnl functions - they are
+ * initialized from _mesa_init_api_defaults and from the active vtxfmt
+ * struct.
+ */
+struct _glapi_table *
+_mesa_create_save_table(void)
+{
+ struct _glapi_table *table;
+
+ table = _mesa_alloc_dispatch_table(_gloffset_COUNT);
+ if (table == NULL)
+ return NULL;
+
+ _mesa_loopback_init_api_table(table);
+
+ /* GL 1.0 */
+ SET_Accum(table, save_Accum);
+ SET_AlphaFunc(table, save_AlphaFunc);
+ SET_Bitmap(table, save_Bitmap);
+ SET_BlendFunc(table, save_BlendFunc);
+ SET_CallList(table, save_CallList);
+ SET_CallLists(table, save_CallLists);
+ SET_Clear(table, save_Clear);
+ SET_ClearAccum(table, save_ClearAccum);
+ SET_ClearColor(table, save_ClearColor);
+ SET_ClearDepth(table, save_ClearDepth);
+ SET_ClearIndex(table, save_ClearIndex);
+ SET_ClearStencil(table, save_ClearStencil);
+ SET_ClipPlane(table, save_ClipPlane);
+ SET_ColorMask(table, save_ColorMask);
+ SET_ColorMaskIndexedEXT(table, save_ColorMaskIndexed);
+ SET_ColorMaterial(table, save_ColorMaterial);
+ SET_CopyPixels(table, save_CopyPixels);
+ SET_CullFace(table, save_CullFace);
+ SET_DeleteLists(table, _mesa_DeleteLists);
+ SET_DepthFunc(table, save_DepthFunc);
+ SET_DepthMask(table, save_DepthMask);
+ SET_DepthRange(table, save_DepthRange);
+ SET_Disable(table, save_Disable);
+ SET_DisableIndexedEXT(table, save_DisableIndexed);
+ SET_DrawBuffer(table, save_DrawBuffer);
+ SET_DrawPixels(table, save_DrawPixels);
+ SET_Enable(table, save_Enable);
+ SET_EnableIndexedEXT(table, save_EnableIndexed);
+ SET_EndList(table, _mesa_EndList);
+ SET_EvalMesh1(table, save_EvalMesh1);
+ SET_EvalMesh2(table, save_EvalMesh2);
+ SET_Finish(table, exec_Finish);
+ SET_Flush(table, exec_Flush);
+ SET_Fogf(table, save_Fogf);
+ SET_Fogfv(table, save_Fogfv);
+ SET_Fogi(table, save_Fogi);
+ SET_Fogiv(table, save_Fogiv);
+ SET_FrontFace(table, save_FrontFace);
+ SET_Frustum(table, save_Frustum);
+ SET_GenLists(table, _mesa_GenLists);
+ SET_GetBooleanv(table, exec_GetBooleanv);
+ SET_GetClipPlane(table, exec_GetClipPlane);
+ SET_GetDoublev(table, exec_GetDoublev);
+ SET_GetError(table, exec_GetError);
+ SET_GetFloatv(table, exec_GetFloatv);
+ SET_GetIntegerv(table, exec_GetIntegerv);
+ SET_GetLightfv(table, exec_GetLightfv);
+ SET_GetLightiv(table, exec_GetLightiv);
+ SET_GetMapdv(table, exec_GetMapdv);
+ SET_GetMapfv(table, exec_GetMapfv);
+ SET_GetMapiv(table, exec_GetMapiv);
+ SET_GetMaterialfv(table, exec_GetMaterialfv);
+ SET_GetMaterialiv(table, exec_GetMaterialiv);
+ SET_GetPixelMapfv(table, exec_GetPixelMapfv);
+ SET_GetPixelMapuiv(table, exec_GetPixelMapuiv);
+ SET_GetPixelMapusv(table, exec_GetPixelMapusv);
+ SET_GetPolygonStipple(table, exec_GetPolygonStipple);
+ SET_GetString(table, exec_GetString);
+ SET_GetTexEnvfv(table, exec_GetTexEnvfv);
+ SET_GetTexEnviv(table, exec_GetTexEnviv);
+ SET_GetTexGendv(table, exec_GetTexGendv);
+ SET_GetTexGenfv(table, exec_GetTexGenfv);
+ SET_GetTexGeniv(table, exec_GetTexGeniv);
+ SET_GetTexImage(table, exec_GetTexImage);
+ SET_GetTexLevelParameterfv(table, exec_GetTexLevelParameterfv);
+ SET_GetTexLevelParameteriv(table, exec_GetTexLevelParameteriv);
+ SET_GetTexParameterfv(table, exec_GetTexParameterfv);
+ SET_GetTexParameteriv(table, exec_GetTexParameteriv);
+ SET_Hint(table, save_Hint);
+ SET_IndexMask(table, save_IndexMask);
+ SET_InitNames(table, save_InitNames);
+ SET_IsEnabled(table, exec_IsEnabled);
+ SET_IsList(table, _mesa_IsList);
+ SET_LightModelf(table, save_LightModelf);
+ SET_LightModelfv(table, save_LightModelfv);
+ SET_LightModeli(table, save_LightModeli);
+ SET_LightModeliv(table, save_LightModeliv);
+ SET_Lightf(table, save_Lightf);
+ SET_Lightfv(table, save_Lightfv);
+ SET_Lighti(table, save_Lighti);
+ SET_Lightiv(table, save_Lightiv);
+ SET_LineStipple(table, save_LineStipple);
+ SET_LineWidth(table, save_LineWidth);
+ SET_ListBase(table, save_ListBase);
+ SET_LoadIdentity(table, save_LoadIdentity);
+ SET_LoadMatrixd(table, save_LoadMatrixd);
+ SET_LoadMatrixf(table, save_LoadMatrixf);
+ SET_LoadName(table, save_LoadName);
+ SET_LogicOp(table, save_LogicOp);
+ SET_Map1d(table, save_Map1d);
+ SET_Map1f(table, save_Map1f);
+ SET_Map2d(table, save_Map2d);
+ SET_Map2f(table, save_Map2f);
+ SET_MapGrid1d(table, save_MapGrid1d);
+ SET_MapGrid1f(table, save_MapGrid1f);
+ SET_MapGrid2d(table, save_MapGrid2d);
+ SET_MapGrid2f(table, save_MapGrid2f);
+ SET_MatrixMode(table, save_MatrixMode);
+ SET_MultMatrixd(table, save_MultMatrixd);
+ SET_MultMatrixf(table, save_MultMatrixf);
+ SET_NewList(table, save_NewList);
+ SET_Ortho(table, save_Ortho);
+ SET_PassThrough(table, save_PassThrough);
+ SET_PixelMapfv(table, save_PixelMapfv);
+ SET_PixelMapuiv(table, save_PixelMapuiv);
+ SET_PixelMapusv(table, save_PixelMapusv);
+ SET_PixelStoref(table, exec_PixelStoref);
+ SET_PixelStorei(table, exec_PixelStorei);
+ SET_PixelTransferf(table, save_PixelTransferf);
+ SET_PixelTransferi(table, save_PixelTransferi);
+ SET_PixelZoom(table, save_PixelZoom);
+ SET_PointSize(table, save_PointSize);
+ SET_PolygonMode(table, save_PolygonMode);
+ SET_PolygonOffset(table, save_PolygonOffset);
+ SET_PolygonStipple(table, save_PolygonStipple);
+ SET_PopAttrib(table, save_PopAttrib);
+ SET_PopMatrix(table, save_PopMatrix);
+ SET_PopName(table, save_PopName);
+ SET_PushAttrib(table, save_PushAttrib);
+ SET_PushMatrix(table, save_PushMatrix);
+ SET_PushName(table, save_PushName);
+ SET_RasterPos2d(table, save_RasterPos2d);
+ SET_RasterPos2dv(table, save_RasterPos2dv);
+ SET_RasterPos2f(table, save_RasterPos2f);
+ SET_RasterPos2fv(table, save_RasterPos2fv);
+ SET_RasterPos2i(table, save_RasterPos2i);
+ SET_RasterPos2iv(table, save_RasterPos2iv);
+ SET_RasterPos2s(table, save_RasterPos2s);
+ SET_RasterPos2sv(table, save_RasterPos2sv);
+ SET_RasterPos3d(table, save_RasterPos3d);
+ SET_RasterPos3dv(table, save_RasterPos3dv);
+ SET_RasterPos3f(table, save_RasterPos3f);
+ SET_RasterPos3fv(table, save_RasterPos3fv);
+ SET_RasterPos3i(table, save_RasterPos3i);
+ SET_RasterPos3iv(table, save_RasterPos3iv);
+ SET_RasterPos3s(table, save_RasterPos3s);
+ SET_RasterPos3sv(table, save_RasterPos3sv);
+ SET_RasterPos4d(table, save_RasterPos4d);
+ SET_RasterPos4dv(table, save_RasterPos4dv);
+ SET_RasterPos4f(table, save_RasterPos4f);
+ SET_RasterPos4fv(table, save_RasterPos4fv);
+ SET_RasterPos4i(table, save_RasterPos4i);
+ SET_RasterPos4iv(table, save_RasterPos4iv);
+ SET_RasterPos4s(table, save_RasterPos4s);
+ SET_RasterPos4sv(table, save_RasterPos4sv);
+ SET_ReadBuffer(table, save_ReadBuffer);
+ SET_ReadPixels(table, exec_ReadPixels);
+ SET_RenderMode(table, exec_RenderMode);
+ SET_Rotated(table, save_Rotated);
+ SET_Rotatef(table, save_Rotatef);
+ SET_Scaled(table, save_Scaled);
+ SET_Scalef(table, save_Scalef);
+ SET_Scissor(table, save_Scissor);
+ SET_FeedbackBuffer(table, exec_FeedbackBuffer);
+ SET_SelectBuffer(table, exec_SelectBuffer);
+ SET_ShadeModel(table, save_ShadeModel);
+ SET_StencilFunc(table, save_StencilFunc);
+ SET_StencilMask(table, save_StencilMask);
+ SET_StencilOp(table, save_StencilOp);
+ SET_TexEnvf(table, save_TexEnvf);
+ SET_TexEnvfv(table, save_TexEnvfv);
+ SET_TexEnvi(table, save_TexEnvi);
+ SET_TexEnviv(table, save_TexEnviv);
+ SET_TexGend(table, save_TexGend);
+ SET_TexGendv(table, save_TexGendv);
+ SET_TexGenf(table, save_TexGenf);
+ SET_TexGenfv(table, save_TexGenfv);
+ SET_TexGeni(table, save_TexGeni);
+ SET_TexGeniv(table, save_TexGeniv);
+ SET_TexImage1D(table, save_TexImage1D);
+ SET_TexImage2D(table, save_TexImage2D);
+ SET_TexParameterf(table, save_TexParameterf);
+ SET_TexParameterfv(table, save_TexParameterfv);
+ SET_TexParameteri(table, save_TexParameteri);
+ SET_TexParameteriv(table, save_TexParameteriv);
+ SET_Translated(table, save_Translated);
+ SET_Translatef(table, save_Translatef);
+ SET_Viewport(table, save_Viewport);
+
+ /* GL 1.1 */
+ SET_AreTexturesResident(table, exec_AreTexturesResident);
+ SET_BindTexture(table, save_BindTexture);
+ SET_ColorPointer(table, exec_ColorPointer);
+ SET_CopyTexImage1D(table, save_CopyTexImage1D);
+ SET_CopyTexImage2D(table, save_CopyTexImage2D);
+ SET_CopyTexSubImage1D(table, save_CopyTexSubImage1D);
+ SET_CopyTexSubImage2D(table, save_CopyTexSubImage2D);
+ SET_DeleteTextures(table, exec_DeleteTextures);
+ SET_DisableClientState(table, exec_DisableClientState);
+ SET_EdgeFlagPointer(table, exec_EdgeFlagPointer);
+ SET_EnableClientState(table, exec_EnableClientState);
+ SET_GenTextures(table, exec_GenTextures);
+ SET_GetPointerv(table, exec_GetPointerv);
+ SET_IndexPointer(table, exec_IndexPointer);
+ SET_InterleavedArrays(table, exec_InterleavedArrays);
+ SET_IsTexture(table, exec_IsTexture);
+ SET_NormalPointer(table, exec_NormalPointer);
+ SET_PopClientAttrib(table, exec_PopClientAttrib);
+ SET_PrioritizeTextures(table, save_PrioritizeTextures);
+ SET_PushClientAttrib(table, exec_PushClientAttrib);
+ SET_TexCoordPointer(table, exec_TexCoordPointer);
+ SET_TexSubImage1D(table, save_TexSubImage1D);
+ SET_TexSubImage2D(table, save_TexSubImage2D);
+ SET_VertexPointer(table, exec_VertexPointer);
+
+ /* GL 1.2 */
+ SET_CopyTexSubImage3D(table, save_CopyTexSubImage3D);
+ SET_TexImage3D(table, save_TexImage3D);
+ SET_TexSubImage3D(table, save_TexSubImage3D);
+
+ /* GL 2.0 */
+ SET_StencilFuncSeparate(table, save_StencilFuncSeparate);
+ SET_StencilMaskSeparate(table, save_StencilMaskSeparate);
+ SET_StencilOpSeparate(table, save_StencilOpSeparate);
+
+ /* ATI_separate_stencil */
+ SET_StencilFuncSeparateATI(table, save_StencilFuncSeparateATI);
+
+ /* GL_ARB_imaging */
+ /* Not all are supported */
+ SET_BlendColor(table, save_BlendColor);
+ SET_BlendEquation(table, save_BlendEquation);
+ SET_ColorSubTable(table, save_ColorSubTable);
+ SET_ColorTable(table, save_ColorTable);
+ SET_ColorTableParameterfv(table, save_ColorTableParameterfv);
+ SET_ColorTableParameteriv(table, save_ColorTableParameteriv);
+ SET_ConvolutionFilter1D(table, save_ConvolutionFilter1D);
+ SET_ConvolutionFilter2D(table, save_ConvolutionFilter2D);
+ SET_ConvolutionParameterf(table, save_ConvolutionParameterf);
+ SET_ConvolutionParameterfv(table, save_ConvolutionParameterfv);
+ SET_ConvolutionParameteri(table, save_ConvolutionParameteri);
+ SET_ConvolutionParameteriv(table, save_ConvolutionParameteriv);
+ SET_CopyColorSubTable(table, save_CopyColorSubTable);
+ SET_CopyColorTable(table, save_CopyColorTable);
+ SET_CopyConvolutionFilter1D(table, exec_CopyConvolutionFilter1D);
+ SET_CopyConvolutionFilter2D(table, exec_CopyConvolutionFilter2D);
+ SET_GetColorTable(table, exec_GetColorTable);
+ SET_GetColorTableParameterfv(table, exec_GetColorTableParameterfv);
+ SET_GetColorTableParameteriv(table, exec_GetColorTableParameteriv);
+ SET_GetConvolutionFilter(table, exec_GetConvolutionFilter);
+ SET_GetConvolutionParameterfv(table, exec_GetConvolutionParameterfv);
+ SET_GetConvolutionParameteriv(table, exec_GetConvolutionParameteriv);
+ SET_GetHistogram(table, exec_GetHistogram);
+ SET_GetHistogramParameterfv(table, exec_GetHistogramParameterfv);
+ SET_GetHistogramParameteriv(table, exec_GetHistogramParameteriv);
+ SET_GetMinmax(table, exec_GetMinmax);
+ SET_GetMinmaxParameterfv(table, exec_GetMinmaxParameterfv);
+ SET_GetMinmaxParameteriv(table, exec_GetMinmaxParameteriv);
+ SET_GetSeparableFilter(table, exec_GetSeparableFilter);
+ SET_Histogram(table, save_Histogram);
+ SET_Minmax(table, save_Minmax);
+ SET_ResetHistogram(table, save_ResetHistogram);
+ SET_ResetMinmax(table, save_ResetMinmax);
+ SET_SeparableFilter2D(table, exec_SeparableFilter2D);
+
+ /* 2. GL_EXT_blend_color */
+#if 0
+ SET_BlendColorEXT(table, save_BlendColorEXT);
+#endif
+
+ /* 3. GL_EXT_polygon_offset */
+ SET_PolygonOffsetEXT(table, save_PolygonOffsetEXT);
+
+ /* 6. GL_EXT_texture3d */
+#if 0
+ SET_CopyTexSubImage3DEXT(table, save_CopyTexSubImage3D);
+ SET_TexImage3DEXT(table, save_TexImage3DEXT);
+ SET_TexSubImage3DEXT(table, save_TexSubImage3D);
+#endif
+
+ /* 14. GL_SGI_color_table */
+#if 0
+ SET_ColorTableSGI(table, save_ColorTable);
+ SET_ColorSubTableSGI(table, save_ColorSubTable);
+ SET_GetColorTableSGI(table, exec_GetColorTable);
+ SET_GetColorTableParameterfvSGI(table, exec_GetColorTableParameterfv);
+ SET_GetColorTableParameterivSGI(table, exec_GetColorTableParameteriv);
+#endif
+
+ /* 30. GL_EXT_vertex_array */
+ SET_ColorPointerEXT(table, exec_ColorPointerEXT);
+ SET_EdgeFlagPointerEXT(table, exec_EdgeFlagPointerEXT);
+ SET_IndexPointerEXT(table, exec_IndexPointerEXT);
+ SET_NormalPointerEXT(table, exec_NormalPointerEXT);
+ SET_TexCoordPointerEXT(table, exec_TexCoordPointerEXT);
+ SET_VertexPointerEXT(table, exec_VertexPointerEXT);
+
+ /* 37. GL_EXT_blend_minmax */
+#if 0
+ SET_BlendEquationEXT(table, save_BlendEquationEXT);
+#endif
+
+ /* 54. GL_EXT_point_parameters */
+ SET_PointParameterfEXT(table, save_PointParameterfEXT);
+ SET_PointParameterfvEXT(table, save_PointParameterfvEXT);
+
+ /* 97. GL_EXT_compiled_vertex_array */
+ SET_LockArraysEXT(table, exec_LockArraysEXT);
+ SET_UnlockArraysEXT(table, exec_UnlockArraysEXT);
+
+ /* 145. GL_EXT_secondary_color */
+ SET_SecondaryColorPointerEXT(table, exec_SecondaryColorPointerEXT);
+
+ /* 148. GL_EXT_multi_draw_arrays */
+ SET_MultiDrawArraysEXT(table, exec_MultiDrawArraysEXT);
+
+ /* 149. GL_EXT_fog_coord */
+ SET_FogCoordPointerEXT(table, exec_FogCoordPointerEXT);
+
+ /* 173. GL_EXT_blend_func_separate */
+ SET_BlendFuncSeparateEXT(table, save_BlendFuncSeparateEXT);
+
+ /* 196. GL_MESA_resize_buffers */
+ SET_ResizeBuffersMESA(table, _mesa_ResizeBuffersMESA);
+
+ /* 197. GL_MESA_window_pos */
+ SET_WindowPos2dMESA(table, save_WindowPos2dMESA);
+ SET_WindowPos2dvMESA(table, save_WindowPos2dvMESA);
+ SET_WindowPos2fMESA(table, save_WindowPos2fMESA);
+ SET_WindowPos2fvMESA(table, save_WindowPos2fvMESA);
+ SET_WindowPos2iMESA(table, save_WindowPos2iMESA);
+ SET_WindowPos2ivMESA(table, save_WindowPos2ivMESA);
+ SET_WindowPos2sMESA(table, save_WindowPos2sMESA);
+ SET_WindowPos2svMESA(table, save_WindowPos2svMESA);
+ SET_WindowPos3dMESA(table, save_WindowPos3dMESA);
+ SET_WindowPos3dvMESA(table, save_WindowPos3dvMESA);
+ SET_WindowPos3fMESA(table, save_WindowPos3fMESA);
+ SET_WindowPos3fvMESA(table, save_WindowPos3fvMESA);
+ SET_WindowPos3iMESA(table, save_WindowPos3iMESA);
+ SET_WindowPos3ivMESA(table, save_WindowPos3ivMESA);
+ SET_WindowPos3sMESA(table, save_WindowPos3sMESA);
+ SET_WindowPos3svMESA(table, save_WindowPos3svMESA);
+ SET_WindowPos4dMESA(table, save_WindowPos4dMESA);
+ SET_WindowPos4dvMESA(table, save_WindowPos4dvMESA);
+ SET_WindowPos4fMESA(table, save_WindowPos4fMESA);
+ SET_WindowPos4fvMESA(table, save_WindowPos4fvMESA);
+ SET_WindowPos4iMESA(table, save_WindowPos4iMESA);
+ SET_WindowPos4ivMESA(table, save_WindowPos4ivMESA);
+ SET_WindowPos4sMESA(table, save_WindowPos4sMESA);
+ SET_WindowPos4svMESA(table, save_WindowPos4svMESA);
+
+ /* 200. GL_IBM_multimode_draw_arrays */
+ SET_MultiModeDrawArraysIBM(table, exec_MultiModeDrawArraysIBM);
+ SET_MultiModeDrawElementsIBM(table, exec_MultiModeDrawElementsIBM);
+
+#if FEATURE_NV_vertex_program
+ /* 233. GL_NV_vertex_program */
+ /* The following commands DO NOT go into display lists:
+ * AreProgramsResidentNV, IsProgramNV, GenProgramsNV, DeleteProgramsNV,
+ * VertexAttribPointerNV, GetProgram*, GetVertexAttrib*
+ */
+ SET_BindProgramNV(table, save_BindProgramNV);
+ SET_DeleteProgramsNV(table, _mesa_DeletePrograms);
+ SET_ExecuteProgramNV(table, save_ExecuteProgramNV);
+ SET_GenProgramsNV(table, _mesa_GenPrograms);
+ SET_AreProgramsResidentNV(table, _mesa_AreProgramsResidentNV);
+ SET_RequestResidentProgramsNV(table, save_RequestResidentProgramsNV);
+ SET_GetProgramParameterfvNV(table, _mesa_GetProgramParameterfvNV);
+ SET_GetProgramParameterdvNV(table, _mesa_GetProgramParameterdvNV);
+ SET_GetProgramivNV(table, _mesa_GetProgramivNV);
+ SET_GetProgramStringNV(table, _mesa_GetProgramStringNV);
+ SET_GetTrackMatrixivNV(table, _mesa_GetTrackMatrixivNV);
+ SET_GetVertexAttribdvNV(table, _mesa_GetVertexAttribdvNV);
+ SET_GetVertexAttribfvNV(table, _mesa_GetVertexAttribfvNV);
+ SET_GetVertexAttribivNV(table, _mesa_GetVertexAttribivNV);
+ SET_GetVertexAttribPointervNV(table, _mesa_GetVertexAttribPointervNV);
+ SET_IsProgramNV(table, _mesa_IsProgramARB);
+ SET_LoadProgramNV(table, save_LoadProgramNV);
+ SET_ProgramEnvParameter4dARB(table, save_ProgramEnvParameter4dARB);
+ SET_ProgramEnvParameter4dvARB(table, save_ProgramEnvParameter4dvARB);
+ SET_ProgramEnvParameter4fARB(table, save_ProgramEnvParameter4fARB);
+ SET_ProgramEnvParameter4fvARB(table, save_ProgramEnvParameter4fvARB);
+ SET_ProgramParameters4dvNV(table, save_ProgramParameters4dvNV);
+ SET_ProgramParameters4fvNV(table, save_ProgramParameters4fvNV);
+ SET_TrackMatrixNV(table, save_TrackMatrixNV);
+ SET_VertexAttribPointerNV(table, _mesa_VertexAttribPointerNV);
+#endif
+
+ /* 244. GL_ATI_envmap_bumpmap */
+ SET_TexBumpParameterivATI(table, save_TexBumpParameterivATI);
+ SET_TexBumpParameterfvATI(table, save_TexBumpParameterfvATI);
+
+ /* 245. GL_ATI_fragment_shader */
+#if FEATURE_ATI_fragment_shader
+ SET_BindFragmentShaderATI(table, save_BindFragmentShaderATI);
+ SET_SetFragmentShaderConstantATI(table, save_SetFragmentShaderConstantATI);
+#endif
+
+ /* 282. GL_NV_fragment_program */
+#if FEATURE_NV_fragment_program
+ SET_ProgramNamedParameter4fNV(table, save_ProgramNamedParameter4fNV);
+ SET_ProgramNamedParameter4dNV(table, save_ProgramNamedParameter4dNV);
+ SET_ProgramNamedParameter4fvNV(table, save_ProgramNamedParameter4fvNV);
+ SET_ProgramNamedParameter4dvNV(table, save_ProgramNamedParameter4dvNV);
+ SET_GetProgramNamedParameterfvNV(table,
+ _mesa_GetProgramNamedParameterfvNV);
+ SET_GetProgramNamedParameterdvNV(table,
+ _mesa_GetProgramNamedParameterdvNV);
+ SET_ProgramLocalParameter4dARB(table, save_ProgramLocalParameter4dARB);
+ SET_ProgramLocalParameter4dvARB(table, save_ProgramLocalParameter4dvARB);
+ SET_ProgramLocalParameter4fARB(table, save_ProgramLocalParameter4fARB);
+ SET_ProgramLocalParameter4fvARB(table, save_ProgramLocalParameter4fvARB);
+ SET_GetProgramLocalParameterdvARB(table,
+ _mesa_GetProgramLocalParameterdvARB);
+ SET_GetProgramLocalParameterfvARB(table,
+ _mesa_GetProgramLocalParameterfvARB);
+#endif
+
+ /* 262. GL_NV_point_sprite */
+ SET_PointParameteriNV(table, save_PointParameteriNV);
+ SET_PointParameterivNV(table, save_PointParameterivNV);
+
+ /* 268. GL_EXT_stencil_two_side */
+ SET_ActiveStencilFaceEXT(table, save_ActiveStencilFaceEXT);
+
+ /* 273. GL_APPLE_vertex_array_object */
+ SET_BindVertexArrayAPPLE(table, _mesa_BindVertexArrayAPPLE);
+ SET_DeleteVertexArraysAPPLE(table, _mesa_DeleteVertexArraysAPPLE);
+ SET_GenVertexArraysAPPLE(table, _mesa_GenVertexArraysAPPLE);
+ SET_IsVertexArrayAPPLE(table, _mesa_IsVertexArrayAPPLE);
+
+ /* ???. GL_EXT_depth_bounds_test */
+ SET_DepthBoundsEXT(table, save_DepthBoundsEXT);
+
+ /* ARB 1. GL_ARB_multitexture */
+ SET_ActiveTextureARB(table, save_ActiveTextureARB);
+ SET_ClientActiveTextureARB(table, exec_ClientActiveTextureARB);
+
+ /* ARB 3. GL_ARB_transpose_matrix */
+ SET_LoadTransposeMatrixdARB(table, save_LoadTransposeMatrixdARB);
+ SET_LoadTransposeMatrixfARB(table, save_LoadTransposeMatrixfARB);
+ SET_MultTransposeMatrixdARB(table, save_MultTransposeMatrixdARB);
+ SET_MultTransposeMatrixfARB(table, save_MultTransposeMatrixfARB);
+
+ /* ARB 5. GL_ARB_multisample */
+ SET_SampleCoverageARB(table, save_SampleCoverageARB);
+
+ /* ARB 12. GL_ARB_texture_compression */
+ SET_CompressedTexImage3DARB(table, save_CompressedTexImage3DARB);
+ SET_CompressedTexImage2DARB(table, save_CompressedTexImage2DARB);
+ SET_CompressedTexImage1DARB(table, save_CompressedTexImage1DARB);
+ SET_CompressedTexSubImage3DARB(table, save_CompressedTexSubImage3DARB);
+ SET_CompressedTexSubImage2DARB(table, save_CompressedTexSubImage2DARB);
+ SET_CompressedTexSubImage1DARB(table, save_CompressedTexSubImage1DARB);
+ SET_GetCompressedTexImageARB(table, exec_GetCompressedTexImageARB);
+
+ /* ARB 14. GL_ARB_point_parameters */
+ /* aliased with EXT_point_parameters functions */
+
+ /* ARB 25. GL_ARB_window_pos */
+ /* aliased with MESA_window_pos functions */
+
+ /* ARB 26. GL_ARB_vertex_program */
+ /* ARB 27. GL_ARB_fragment_program */
+#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+ /* glVertexAttrib* functions alias the NV ones, handled elsewhere */
+ SET_VertexAttribPointerARB(table, _mesa_VertexAttribPointerARB);
+ SET_EnableVertexAttribArrayARB(table, _mesa_EnableVertexAttribArrayARB);
+ SET_DisableVertexAttribArrayARB(table, _mesa_DisableVertexAttribArrayARB);
+ SET_ProgramStringARB(table, save_ProgramStringARB);
+ SET_BindProgramNV(table, save_BindProgramNV);
+ SET_DeleteProgramsNV(table, _mesa_DeletePrograms);
+ SET_GenProgramsNV(table, _mesa_GenPrograms);
+ SET_IsProgramNV(table, _mesa_IsProgramARB);
+ SET_GetVertexAttribdvNV(table, _mesa_GetVertexAttribdvNV);
+ SET_GetVertexAttribfvNV(table, _mesa_GetVertexAttribfvNV);
+ SET_GetVertexAttribivNV(table, _mesa_GetVertexAttribivNV);
+ SET_GetVertexAttribPointervNV(table, _mesa_GetVertexAttribPointervNV);
+ SET_ProgramEnvParameter4dARB(table, save_ProgramEnvParameter4dARB);
+ SET_ProgramEnvParameter4dvARB(table, save_ProgramEnvParameter4dvARB);
+ SET_ProgramEnvParameter4fARB(table, save_ProgramEnvParameter4fARB);
+ SET_ProgramEnvParameter4fvARB(table, save_ProgramEnvParameter4fvARB);
+ SET_ProgramLocalParameter4dARB(table, save_ProgramLocalParameter4dARB);
+ SET_ProgramLocalParameter4dvARB(table, save_ProgramLocalParameter4dvARB);
+ SET_ProgramLocalParameter4fARB(table, save_ProgramLocalParameter4fARB);
+ SET_ProgramLocalParameter4fvARB(table, save_ProgramLocalParameter4fvARB);
+ SET_GetProgramEnvParameterdvARB(table, _mesa_GetProgramEnvParameterdvARB);
+ SET_GetProgramEnvParameterfvARB(table, _mesa_GetProgramEnvParameterfvARB);
+ SET_GetProgramLocalParameterdvARB(table,
+ _mesa_GetProgramLocalParameterdvARB);
+ SET_GetProgramLocalParameterfvARB(table,
+ _mesa_GetProgramLocalParameterfvARB);
+ SET_GetProgramivARB(table, _mesa_GetProgramivARB);
+ SET_GetProgramStringARB(table, _mesa_GetProgramStringARB);
+#endif
+
+ /* ARB 28. GL_ARB_vertex_buffer_object */
+#if FEATURE_ARB_vertex_buffer_object
+ /* None of the extension's functions get compiled */
+ SET_BindBufferARB(table, _mesa_BindBufferARB);
+ SET_BufferDataARB(table, _mesa_BufferDataARB);
+ SET_BufferSubDataARB(table, _mesa_BufferSubDataARB);
+ SET_DeleteBuffersARB(table, _mesa_DeleteBuffersARB);
+ SET_GenBuffersARB(table, _mesa_GenBuffersARB);
+ SET_GetBufferParameterivARB(table, _mesa_GetBufferParameterivARB);
+ SET_GetBufferPointervARB(table, _mesa_GetBufferPointervARB);
+ SET_GetBufferSubDataARB(table, _mesa_GetBufferSubDataARB);
+ SET_IsBufferARB(table, _mesa_IsBufferARB);
+ SET_MapBufferARB(table, _mesa_MapBufferARB);
+ SET_UnmapBufferARB(table, _mesa_UnmapBufferARB);
+#endif
+
+#if FEATURE_queryobj
+ SET_BeginQueryARB(table, save_BeginQueryARB);
+ SET_EndQueryARB(table, save_EndQueryARB);
+ SET_GenQueriesARB(table, _mesa_GenQueriesARB);
+ SET_DeleteQueriesARB(table, _mesa_DeleteQueriesARB);
+ SET_IsQueryARB(table, _mesa_IsQueryARB);
+ SET_GetQueryivARB(table, _mesa_GetQueryivARB);
+ SET_GetQueryObjectivARB(table, _mesa_GetQueryObjectivARB);
+ SET_GetQueryObjectuivARB(table, _mesa_GetQueryObjectuivARB);
+#endif
+ SET_DrawBuffersARB(table, save_DrawBuffersARB);
+
+#if FEATURE_EXT_framebuffer_blit
+ SET_BlitFramebufferEXT(table, save_BlitFramebufferEXT);
+#endif
+
+ /* GL_ARB_shader_objects */
+ SET_UseProgramObjectARB(table, save_UseProgramObjectARB);
+ SET_Uniform1fARB(table, save_Uniform1fARB);
+ SET_Uniform2fARB(table, save_Uniform2fARB);
+ SET_Uniform3fARB(table, save_Uniform3fARB);
+ SET_Uniform4fARB(table, save_Uniform4fARB);
+ SET_Uniform1fvARB(table, save_Uniform1fvARB);
+ SET_Uniform2fvARB(table, save_Uniform2fvARB);
+ SET_Uniform3fvARB(table, save_Uniform3fvARB);
+ SET_Uniform4fvARB(table, save_Uniform4fvARB);
+ SET_Uniform1iARB(table, save_Uniform1iARB);
+ SET_Uniform2iARB(table, save_Uniform2iARB);
+ SET_Uniform3iARB(table, save_Uniform3iARB);
+ SET_Uniform4iARB(table, save_Uniform4iARB);
+ SET_Uniform1ivARB(table, save_Uniform1ivARB);
+ SET_Uniform2ivARB(table, save_Uniform2ivARB);
+ SET_Uniform3ivARB(table, save_Uniform3ivARB);
+ SET_Uniform4ivARB(table, save_Uniform4ivARB);
+ SET_UniformMatrix2fvARB(table, save_UniformMatrix2fvARB);
+ SET_UniformMatrix3fvARB(table, save_UniformMatrix3fvARB);
+ SET_UniformMatrix4fvARB(table, save_UniformMatrix4fvARB);
+ SET_UniformMatrix2x3fv(table, save_UniformMatrix2x3fv);
+ SET_UniformMatrix3x2fv(table, save_UniformMatrix3x2fv);
+ SET_UniformMatrix2x4fv(table, save_UniformMatrix2x4fv);
+ SET_UniformMatrix4x2fv(table, save_UniformMatrix4x2fv);
+ SET_UniformMatrix3x4fv(table, save_UniformMatrix3x4fv);
+ SET_UniformMatrix4x3fv(table, save_UniformMatrix4x3fv);
+
+ /* ARB 30/31/32. GL_ARB_shader_objects, GL_ARB_vertex/fragment_shader */
+ SET_BindAttribLocationARB(table, exec_BindAttribLocationARB);
+ SET_GetAttribLocationARB(table, exec_GetAttribLocationARB);
+ SET_GetUniformLocationARB(table, exec_GetUniformLocationARB);
+ /* XXX additional functions need to be implemented here! */
+
+ /* 299. GL_EXT_blend_equation_separate */
+ SET_BlendEquationSeparateEXT(table, save_BlendEquationSeparateEXT);
+
+ /* GL_EXT_gpu_program_parameters */
+#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+ SET_ProgramEnvParameters4fvEXT(table, save_ProgramEnvParameters4fvEXT);
+ SET_ProgramLocalParameters4fvEXT(table, save_ProgramLocalParameters4fvEXT);
+#endif
+
+ /* ARB 50. GL_ARB_map_buffer_range */
+#if FEATURE_ARB_map_buffer_range
+ SET_MapBufferRange(table, _mesa_MapBufferRange); /* no dlist save */
+ SET_FlushMappedBufferRange(table, _mesa_FlushMappedBufferRange); /* no dl */
+#endif
+
+ /* ARB 59. GL_ARB_copy_buffer */
+ SET_CopyBufferSubData(table, _mesa_CopyBufferSubData); /* no dlist save */
+
+ /* 352. GL_EXT_transform_feedback */
+#if FEATURE_EXT_transform_feedback
+ SET_BeginTransformFeedbackEXT(table, save_BeginTransformFeedback);
+ SET_EndTransformFeedbackEXT(table, save_EndTransformFeedback);
+#endif
+
+ /* 364. GL_EXT_provoking_vertex */
+ SET_ProvokingVertexEXT(table, save_ProvokingVertexEXT);
+
+ /* 371. GL_APPLE_object_purgeable */
+#if FEATURE_APPLE_object_purgeable
+ SET_ObjectPurgeableAPPLE(table, _mesa_ObjectPurgeableAPPLE);
+ SET_ObjectUnpurgeableAPPLE(table, _mesa_ObjectUnpurgeableAPPLE);
+#endif
+
+ /* GL_EXT_texture_integer */
+ SET_ClearColorIiEXT(table, save_ClearColorIi);
+ SET_ClearColorIuiEXT(table, save_ClearColorIui);
+ SET_TexParameterIivEXT(table, save_TexParameterIiv);
+ SET_TexParameterIuivEXT(table, save_TexParameterIuiv);
+ SET_GetTexParameterIivEXT(table, exec_GetTexParameterIiv);
+ SET_GetTexParameterIuivEXT(table, exec_GetTexParameterIuiv);
+
+ /* 377. GL_EXT_separate_shader_objects */
+ SET_UseShaderProgramEXT(table, save_UseShaderProgramEXT);
+ SET_ActiveProgramEXT(table, save_ActiveProgramEXT);
+
+ /* GL 3.0 */
+#if 0
+ SET_ClearBufferiv(table, save_ClearBufferiv);
+ SET_ClearBufferuiv(table, save_ClearBufferuiv);
+ SET_ClearBufferfv(table, save_ClearBufferfv);
+ SET_ClearBufferfi(table, save_ClearBufferfi);
+ SET_Uniform1ui(table, save_Uniform1ui);
+ SET_Uniform2ui(table, save_Uniform2ui);
+ SET_Uniform3ui(table, save_Uniform3ui);
+ SET_Uniform4ui(table, save_Uniform4ui);
+ SET_Uniform1uiv(table, save_Uniform1uiv);
+ SET_Uniform2uiv(table, save_Uniform2uiv);
+ SET_Uniform3uiv(table, save_Uniform3uiv);
+ SET_Uniform4uiv(table, save_Uniform4uiv);
+#else
+ (void) save_ClearBufferiv;
+ (void) save_ClearBufferuiv;
+ (void) save_ClearBufferfv;
+ (void) save_ClearBufferfi;
+ (void) save_Uniform1ui;
+ (void) save_Uniform2ui;
+ (void) save_Uniform3ui;
+ (void) save_Uniform4ui;
+ (void) save_Uniform1uiv;
+ (void) save_Uniform2uiv;
+ (void) save_Uniform3uiv;
+ (void) save_Uniform4uiv;
+#endif
+
+ /* GL_ARB_instanced_arrays */
+ SET_VertexAttribDivisorARB(table, save_VertexAttribDivisor);
+
+ /* GL_ARB_draw_buffer_blend */
+ SET_BlendFunciARB(table, save_BlendFunci);
+ SET_BlendFuncSeparateiARB(table, save_BlendFuncSeparatei);
+ SET_BlendEquationiARB(table, save_BlendEquationi);
+ SET_BlendEquationSeparateiARB(table, save_BlendEquationSeparatei);
+
+ return table;
+}
+
+
+
+static const char *
+enum_string(GLenum k)
+{
+ return _mesa_lookup_enum_by_nr(k);
+}
+
+
+/**
+ * Print the commands in a display list. For debugging only.
+ * TODO: many commands aren't handled yet.
+ */
+static void GLAPIENTRY
+print_list(struct gl_context *ctx, GLuint list)
+{
+ struct gl_display_list *dlist;
+ Node *n;
+ GLboolean done;
+
+ if (!islist(ctx, list)) {
+ printf("%u is not a display list ID\n", list);
+ return;
+ }
+
+ dlist = lookup_list(ctx, list);
+ if (!dlist)
+ return;
+
+ n = dlist->Head;
+
+ printf("START-LIST %u, address %p\n", list, (void *) n);
+
+ done = n ? GL_FALSE : GL_TRUE;
+ while (!done) {
+ const OpCode opcode = n[0].opcode;
+
+ if (is_ext_opcode(opcode)) {
+ n += ext_opcode_print(ctx, n);
+ }
+ else {
+ switch (opcode) {
+ case OPCODE_ACCUM:
+ printf("Accum %s %g\n", enum_string(n[1].e), n[2].f);
+ break;
+ case OPCODE_BITMAP:
+ printf("Bitmap %d %d %g %g %g %g %p\n", n[1].i, n[2].i,
+ n[3].f, n[4].f, n[5].f, n[6].f, (void *) n[7].data);
+ break;
+ case OPCODE_CALL_LIST:
+ printf("CallList %d\n", (int) n[1].ui);
+ break;
+ case OPCODE_CALL_LIST_OFFSET:
+ printf("CallList %d + offset %u = %u\n", (int) n[1].ui,
+ ctx->List.ListBase, ctx->List.ListBase + n[1].ui);
+ break;
+ case OPCODE_COLOR_TABLE_PARAMETER_FV:
+ printf("ColorTableParameterfv %s %s %f %f %f %f\n",
+ enum_string(n[1].e), enum_string(n[2].e),
+ n[3].f, n[4].f, n[5].f, n[6].f);
+ break;
+ case OPCODE_COLOR_TABLE_PARAMETER_IV:
+ printf("ColorTableParameteriv %s %s %d %d %d %d\n",
+ enum_string(n[1].e), enum_string(n[2].e),
+ n[3].i, n[4].i, n[5].i, n[6].i);
+ break;
+ case OPCODE_DISABLE:
+ printf("Disable %s\n", enum_string(n[1].e));
+ break;
+ case OPCODE_ENABLE:
+ printf("Enable %s\n", enum_string(n[1].e));
+ break;
+ case OPCODE_FRUSTUM:
+ printf("Frustum %g %g %g %g %g %g\n",
+ n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f);
+ break;
+ case OPCODE_LINE_STIPPLE:
+ printf("LineStipple %d %x\n", n[1].i, (int) n[2].us);
+ break;
+ case OPCODE_LOAD_IDENTITY:
+ printf("LoadIdentity\n");
+ break;
+ case OPCODE_LOAD_MATRIX:
+ printf("LoadMatrix\n");
+ printf(" %8f %8f %8f %8f\n",
+ n[1].f, n[5].f, n[9].f, n[13].f);
+ printf(" %8f %8f %8f %8f\n",
+ n[2].f, n[6].f, n[10].f, n[14].f);
+ printf(" %8f %8f %8f %8f\n",
+ n[3].f, n[7].f, n[11].f, n[15].f);
+ printf(" %8f %8f %8f %8f\n",
+ n[4].f, n[8].f, n[12].f, n[16].f);
+ break;
+ case OPCODE_MULT_MATRIX:
+ printf("MultMatrix (or Rotate)\n");
+ printf(" %8f %8f %8f %8f\n",
+ n[1].f, n[5].f, n[9].f, n[13].f);
+ printf(" %8f %8f %8f %8f\n",
+ n[2].f, n[6].f, n[10].f, n[14].f);
+ printf(" %8f %8f %8f %8f\n",
+ n[3].f, n[7].f, n[11].f, n[15].f);
+ printf(" %8f %8f %8f %8f\n",
+ n[4].f, n[8].f, n[12].f, n[16].f);
+ break;
+ case OPCODE_ORTHO:
+ printf("Ortho %g %g %g %g %g %g\n",
+ n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f);
+ break;
+ case OPCODE_POP_ATTRIB:
+ printf("PopAttrib\n");
+ break;
+ case OPCODE_POP_MATRIX:
+ printf("PopMatrix\n");
+ break;
+ case OPCODE_POP_NAME:
+ printf("PopName\n");
+ break;
+ case OPCODE_PUSH_ATTRIB:
+ printf("PushAttrib %x\n", n[1].bf);
+ break;
+ case OPCODE_PUSH_MATRIX:
+ printf("PushMatrix\n");
+ break;
+ case OPCODE_PUSH_NAME:
+ printf("PushName %d\n", (int) n[1].ui);
+ break;
+ case OPCODE_RASTER_POS:
+ printf("RasterPos %g %g %g %g\n",
+ n[1].f, n[2].f, n[3].f, n[4].f);
+ break;
+ case OPCODE_ROTATE:
+ printf("Rotate %g %g %g %g\n",
+ n[1].f, n[2].f, n[3].f, n[4].f);
+ break;
+ case OPCODE_SCALE:
+ printf("Scale %g %g %g\n", n[1].f, n[2].f, n[3].f);
+ break;
+ case OPCODE_TRANSLATE:
+ printf("Translate %g %g %g\n", n[1].f, n[2].f, n[3].f);
+ break;
+ case OPCODE_BIND_TEXTURE:
+ printf("BindTexture %s %d\n",
+ _mesa_lookup_enum_by_nr(n[1].ui), n[2].ui);
+ break;
+ case OPCODE_SHADE_MODEL:
+ printf("ShadeModel %s\n", _mesa_lookup_enum_by_nr(n[1].ui));
+ break;
+ case OPCODE_MAP1:
+ printf("Map1 %s %.3f %.3f %d %d\n",
+ _mesa_lookup_enum_by_nr(n[1].ui),
+ n[2].f, n[3].f, n[4].i, n[5].i);
+ break;
+ case OPCODE_MAP2:
+ printf("Map2 %s %.3f %.3f %.3f %.3f %d %d %d %d\n",
+ _mesa_lookup_enum_by_nr(n[1].ui),
+ n[2].f, n[3].f, n[4].f, n[5].f,
+ n[6].i, n[7].i, n[8].i, n[9].i);
+ break;
+ case OPCODE_MAPGRID1:
+ printf("MapGrid1 %d %.3f %.3f\n", n[1].i, n[2].f, n[3].f);
+ break;
+ case OPCODE_MAPGRID2:
+ printf("MapGrid2 %d %.3f %.3f, %d %.3f %.3f\n",
+ n[1].i, n[2].f, n[3].f, n[4].i, n[5].f, n[6].f);
+ break;
+ case OPCODE_EVALMESH1:
+ printf("EvalMesh1 %d %d\n", n[1].i, n[2].i);
+ break;
+ case OPCODE_EVALMESH2:
+ printf("EvalMesh2 %d %d %d %d\n",
+ n[1].i, n[2].i, n[3].i, n[4].i);
+ break;
+
+ case OPCODE_ATTR_1F_NV:
+ printf("ATTR_1F_NV attr %d: %f\n", n[1].i, n[2].f);
+ break;
+ case OPCODE_ATTR_2F_NV:
+ printf("ATTR_2F_NV attr %d: %f %f\n",
+ n[1].i, n[2].f, n[3].f);
+ break;
+ case OPCODE_ATTR_3F_NV:
+ printf("ATTR_3F_NV attr %d: %f %f %f\n",
+ n[1].i, n[2].f, n[3].f, n[4].f);
+ break;
+ case OPCODE_ATTR_4F_NV:
+ printf("ATTR_4F_NV attr %d: %f %f %f %f\n",
+ n[1].i, n[2].f, n[3].f, n[4].f, n[5].f);
+ break;
+ case OPCODE_ATTR_1F_ARB:
+ printf("ATTR_1F_ARB attr %d: %f\n", n[1].i, n[2].f);
+ break;
+ case OPCODE_ATTR_2F_ARB:
+ printf("ATTR_2F_ARB attr %d: %f %f\n",
+ n[1].i, n[2].f, n[3].f);
+ break;
+ case OPCODE_ATTR_3F_ARB:
+ printf("ATTR_3F_ARB attr %d: %f %f %f\n",
+ n[1].i, n[2].f, n[3].f, n[4].f);
+ break;
+ case OPCODE_ATTR_4F_ARB:
+ printf("ATTR_4F_ARB attr %d: %f %f %f %f\n",
+ n[1].i, n[2].f, n[3].f, n[4].f, n[5].f);
+ break;
+
+ case OPCODE_MATERIAL:
+ printf("MATERIAL %x %x: %f %f %f %f\n",
+ n[1].i, n[2].i, n[3].f, n[4].f, n[5].f, n[6].f);
+ break;
+ case OPCODE_BEGIN:
+ printf("BEGIN %x\n", n[1].i);
+ break;
+ case OPCODE_END:
+ printf("END\n");
+ break;
+ case OPCODE_RECTF:
+ printf("RECTF %f %f %f %f\n", n[1].f, n[2].f, n[3].f,
+ n[4].f);
+ break;
+ case OPCODE_EVAL_C1:
+ printf("EVAL_C1 %f\n", n[1].f);
+ break;
+ case OPCODE_EVAL_C2:
+ printf("EVAL_C2 %f %f\n", n[1].f, n[2].f);
+ break;
+ case OPCODE_EVAL_P1:
+ printf("EVAL_P1 %d\n", n[1].i);
+ break;
+ case OPCODE_EVAL_P2:
+ printf("EVAL_P2 %d %d\n", n[1].i, n[2].i);
+ break;
+
+ case OPCODE_PROVOKING_VERTEX:
+ printf("ProvokingVertex %s\n",
+ _mesa_lookup_enum_by_nr(n[1].ui));
+ break;
+
+ /*
+ * meta opcodes/commands
+ */
+ case OPCODE_ERROR:
+ printf("Error: %s %s\n",
+ enum_string(n[1].e), (const char *) n[2].data);
+ break;
+ case OPCODE_CONTINUE:
+ printf("DISPLAY-LIST-CONTINUE\n");
+ n = (Node *) n[1].next;
+ break;
+ case OPCODE_END_OF_LIST:
+ printf("END-LIST %u\n", list);
+ done = GL_TRUE;
+ break;
+ default:
+ if (opcode < 0 || opcode > OPCODE_END_OF_LIST) {
+ printf
+ ("ERROR IN DISPLAY LIST: opcode = %d, address = %p\n",
+ opcode, (void *) n);
+ return;
+ }
+ else {
+ printf("command %d, %u operands\n", opcode,
+ InstSize[opcode]);
+ }
+ }
+ /* increment n to point to next compiled command */
+ if (opcode != OPCODE_CONTINUE) {
+ n += InstSize[opcode];
+ }
+ }
+ }
+}
+
+
+
+/**
+ * Clients may call this function to help debug display list problems.
+ * This function is _ONLY_FOR_DEBUGGING_PURPOSES_. It may be removed,
+ * changed, or break in the future without notice.
+ */
+void
+mesa_print_display_list(GLuint list)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ print_list(ctx, list);
+}
+
+
+/**********************************************************************/
+/***** Initialization *****/
+/**********************************************************************/
+
+void
+_mesa_save_vtxfmt_init(GLvertexformat * vfmt)
+{
+ _MESA_INIT_ARRAYELT_VTXFMT(vfmt, _ae_);
+
+ vfmt->Begin = save_Begin;
+
+ _MESA_INIT_DLIST_VTXFMT(vfmt, save_);
+
+ vfmt->Color3f = save_Color3f;
+ vfmt->Color3fv = save_Color3fv;
+ vfmt->Color4f = save_Color4f;
+ vfmt->Color4fv = save_Color4fv;
+ vfmt->EdgeFlag = save_EdgeFlag;
+ vfmt->End = save_End;
+
+ _MESA_INIT_EVAL_VTXFMT(vfmt, save_);
+
+ vfmt->FogCoordfEXT = save_FogCoordfEXT;
+ vfmt->FogCoordfvEXT = save_FogCoordfvEXT;
+ vfmt->Indexf = save_Indexf;
+ vfmt->Indexfv = save_Indexfv;
+ vfmt->Materialfv = save_Materialfv;
+ vfmt->MultiTexCoord1fARB = save_MultiTexCoord1f;
+ vfmt->MultiTexCoord1fvARB = save_MultiTexCoord1fv;
+ vfmt->MultiTexCoord2fARB = save_MultiTexCoord2f;
+ vfmt->MultiTexCoord2fvARB = save_MultiTexCoord2fv;
+ vfmt->MultiTexCoord3fARB = save_MultiTexCoord3f;
+ vfmt->MultiTexCoord3fvARB = save_MultiTexCoord3fv;
+ vfmt->MultiTexCoord4fARB = save_MultiTexCoord4f;
+ vfmt->MultiTexCoord4fvARB = save_MultiTexCoord4fv;
+ vfmt->Normal3f = save_Normal3f;
+ vfmt->Normal3fv = save_Normal3fv;
+ vfmt->SecondaryColor3fEXT = save_SecondaryColor3fEXT;
+ vfmt->SecondaryColor3fvEXT = save_SecondaryColor3fvEXT;
+ vfmt->TexCoord1f = save_TexCoord1f;
+ vfmt->TexCoord1fv = save_TexCoord1fv;
+ vfmt->TexCoord2f = save_TexCoord2f;
+ vfmt->TexCoord2fv = save_TexCoord2fv;
+ vfmt->TexCoord3f = save_TexCoord3f;
+ vfmt->TexCoord3fv = save_TexCoord3fv;
+ vfmt->TexCoord4f = save_TexCoord4f;
+ vfmt->TexCoord4fv = save_TexCoord4fv;
+ vfmt->Vertex2f = save_Vertex2f;
+ vfmt->Vertex2fv = save_Vertex2fv;
+ vfmt->Vertex3f = save_Vertex3f;
+ vfmt->Vertex3fv = save_Vertex3fv;
+ vfmt->Vertex4f = save_Vertex4f;
+ vfmt->Vertex4fv = save_Vertex4fv;
+ vfmt->VertexAttrib1fNV = save_VertexAttrib1fNV;
+ vfmt->VertexAttrib1fvNV = save_VertexAttrib1fvNV;
+ vfmt->VertexAttrib2fNV = save_VertexAttrib2fNV;
+ vfmt->VertexAttrib2fvNV = save_VertexAttrib2fvNV;
+ vfmt->VertexAttrib3fNV = save_VertexAttrib3fNV;
+ vfmt->VertexAttrib3fvNV = save_VertexAttrib3fvNV;
+ vfmt->VertexAttrib4fNV = save_VertexAttrib4fNV;
+ vfmt->VertexAttrib4fvNV = save_VertexAttrib4fvNV;
+ vfmt->VertexAttrib1fARB = save_VertexAttrib1fARB;
+ vfmt->VertexAttrib1fvARB = save_VertexAttrib1fvARB;
+ vfmt->VertexAttrib2fARB = save_VertexAttrib2fARB;
+ vfmt->VertexAttrib2fvARB = save_VertexAttrib2fvARB;
+ vfmt->VertexAttrib3fARB = save_VertexAttrib3fARB;
+ vfmt->VertexAttrib3fvARB = save_VertexAttrib3fvARB;
+ vfmt->VertexAttrib4fARB = save_VertexAttrib4fARB;
+ vfmt->VertexAttrib4fvARB = save_VertexAttrib4fvARB;
+
+ vfmt->Rectf = save_Rectf;
+
+ /* The driver is required to implement these as
+ * 1) They can probably do a better job.
+ * 2) A lot of new mechanisms would have to be added to this module
+ * to support it. That code would probably never get used,
+ * because of (1).
+ */
+#if 0
+ vfmt->DrawArrays = 0;
+ vfmt->DrawElements = 0;
+ vfmt->DrawRangeElements = 0;
+ vfmt->MultiDrawElemementsEXT = 0;
+ vfmt->DrawElementsBaseVertex = 0;
+ vfmt->DrawRangeElementsBaseVertex = 0;
+ vfmt->MultiDrawElemementsBaseVertex = 0;
+#endif
+}
+
+
+void
+_mesa_install_dlist_vtxfmt(struct _glapi_table *disp,
+ const GLvertexformat *vfmt)
+{
+ SET_CallList(disp, vfmt->CallList);
+ SET_CallLists(disp, vfmt->CallLists);
+}
+
+
+void _mesa_init_dlist_dispatch(struct _glapi_table *disp)
+{
+ SET_CallList(disp, _mesa_CallList);
+ SET_CallLists(disp, _mesa_CallLists);
+
+ SET_DeleteLists(disp, _mesa_DeleteLists);
+ SET_EndList(disp, _mesa_EndList);
+ SET_GenLists(disp, _mesa_GenLists);
+ SET_IsList(disp, _mesa_IsList);
+ SET_ListBase(disp, _mesa_ListBase);
+ SET_NewList(disp, _mesa_NewList);
+}
+
+
+#endif /* FEATURE_dlist */
+
+
+/**
+ * Initialize display list state for given context.
+ */
+void
+_mesa_init_display_list(struct gl_context *ctx)
+{
+ static GLboolean tableInitialized = GL_FALSE;
+
+ /* zero-out the instruction size table, just once */
+ if (!tableInitialized) {
+ memset(InstSize, 0, sizeof(InstSize));
+ tableInitialized = GL_TRUE;
+ }
+
+ /* extension info */
+ ctx->ListExt = CALLOC_STRUCT(gl_list_extensions);
+
+ /* Display list */
+ ctx->ListState.CallDepth = 0;
+ ctx->ExecuteFlag = GL_TRUE;
+ ctx->CompileFlag = GL_FALSE;
+ ctx->ListState.CurrentBlock = NULL;
+ ctx->ListState.CurrentPos = 0;
+
+ /* Display List group */
+ ctx->List.ListBase = 0;
+
+#if FEATURE_dlist
+ _mesa_save_vtxfmt_init(&ctx->ListState.ListVtxfmt);
+#endif
+}
+
+
+void
+_mesa_free_display_list_data(struct gl_context *ctx)
+{
+ free(ctx->ListExt);
+ ctx->ListExt = NULL;
+}
diff --git a/mesalib/src/mesa/main/dlopen.c b/mesalib/src/mesa/main/dlopen.c
index 57a33292e..62d9023a9 100644
--- a/mesalib/src/mesa/main/dlopen.c
+++ b/mesalib/src/mesa/main/dlopen.c
@@ -51,7 +51,7 @@ _mesa_dlopen(const char *libname, int flags)
#elif defined(_GNU_SOURCE)
flags = RTLD_LAZY | RTLD_GLOBAL; /* Overriding flags at this time */
return dlopen(libname, flags);
-#elif defined(__MINGW32__)
+#elif defined(__MINGW32__) | defined(_MSC_VER)
return LoadLibraryA(libname);
#else
return NULL;
@@ -82,7 +82,7 @@ _mesa_dlsym(void *handle, const char *fname)
u.v = dlsym(handle, fname2);
#elif defined(_GNU_SOURCE)
u.v = dlsym(handle, fname);
-#elif defined(__MINGW32__)
+#elif defined(__MINGW32__) | defined(_MSC_VER)
u.v = (void *) GetProcAddress(handle, fname);
#else
u.v = NULL;
@@ -101,7 +101,7 @@ _mesa_dlclose(void *handle)
(void) handle;
#elif defined(_GNU_SOURCE)
dlclose(handle);
-#elif defined(__MINGW32__)
+#elif defined(__MINGW32__) | defined(_MSC_VER)
FreeLibrary(handle);
#else
(void) handle;
diff --git a/mesalib/src/mesa/main/drawpix.c b/mesalib/src/mesa/main/drawpix.c
index 98e82ef85..b6a6799fd 100644
--- a/mesalib/src/mesa/main/drawpix.c
+++ b/mesalib/src/mesa/main/drawpix.c
@@ -1,304 +1,304 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "glheader.h"
-#include "imports.h"
-#include "bufferobj.h"
-#include "context.h"
-#include "drawpix.h"
-#include "enums.h"
-#include "feedback.h"
-#include "framebuffer.h"
-#include "mfeatures.h"
-#include "pbo.h"
-#include "readpix.h"
-#include "state.h"
-#include "dispatch.h"
-
-
-#if FEATURE_drawpix
-
-
-/*
- * Execute glDrawPixels
- */
-static void GLAPIENTRY
-_mesa_DrawPixels( GLsizei width, GLsizei height,
- GLenum format, GLenum type, const GLvoid *pixels )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glDrawPixels(%d, %d, %s, %s, %p) // to %s at %d, %d\n",
- width, height,
- _mesa_lookup_enum_by_nr(format),
- _mesa_lookup_enum_by_nr(type),
- pixels,
- _mesa_lookup_enum_by_nr(ctx->DrawBuffer->ColorDrawBuffer[0]),
- IROUND(ctx->Current.RasterPos[0]),
- IROUND(ctx->Current.RasterPos[1]));
-
-
- if (width < 0 || height < 0) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glDrawPixels(width or height < 0" );
- return;
- }
-
- /* We're not using the current vertex program, and the driver may install
- * its own. Note: this may dirty some state.
- */
- _mesa_set_vp_override(ctx, GL_TRUE);
-
- /* Note: this call does state validation */
- if (!_mesa_valid_to_render(ctx, "glDrawPixels")) {
- goto end; /* the error code was recorded */
- }
-
- if (_mesa_error_check_format_type(ctx, format, type, GL_TRUE)) {
- goto end; /* the error code was recorded */
- }
-
- if (!ctx->Current.RasterPosValid) {
- goto end; /* no-op, not an error */
- }
-
- if (ctx->RenderMode == GL_RENDER) {
- if (width > 0 && height > 0) {
- /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
- GLint x = IROUND(ctx->Current.RasterPos[0]);
- GLint y = IROUND(ctx->Current.RasterPos[1]);
-
- if (ctx->Unpack.BufferObj->Name) {
- /* unpack from PBO */
- if (!_mesa_validate_pbo_access(2, &ctx->Unpack, width, height, 1,
- format, type, pixels)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glDrawPixels(invalid PBO access)");
- goto end;
- }
- if (_mesa_bufferobj_mapped(ctx->Unpack.BufferObj)) {
- /* buffer is mapped - that's an error */
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glDrawPixels(PBO is mapped)");
- goto end;
- }
- }
-
- ctx->Driver.DrawPixels(ctx, x, y, width, height, format, type,
- &ctx->Unpack, pixels);
- }
- }
- else if (ctx->RenderMode == GL_FEEDBACK) {
- /* Feedback the current raster pos info */
- FLUSH_CURRENT( ctx, 0 );
- _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_DRAW_PIXEL_TOKEN );
- _mesa_feedback_vertex( ctx,
- ctx->Current.RasterPos,
- ctx->Current.RasterColor,
- ctx->Current.RasterTexCoords[0] );
- }
- else {
- ASSERT(ctx->RenderMode == GL_SELECT);
- /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
- }
-
-end:
- _mesa_set_vp_override(ctx, GL_FALSE);
-}
-
-
-static void GLAPIENTRY
-_mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
- GLenum type )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- _mesa_finish(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx,
- "glCopyPixels(%d, %d, %d, %d, %s) // from %s to %s at %d, %d\n",
- srcx, srcy, width, height,
- _mesa_lookup_enum_by_nr(type),
- _mesa_lookup_enum_by_nr(ctx->ReadBuffer->ColorReadBuffer),
- _mesa_lookup_enum_by_nr(ctx->DrawBuffer->ColorDrawBuffer[0]),
- IROUND(ctx->Current.RasterPos[0]),
- IROUND(ctx->Current.RasterPos[1]));
-
- if (width < 0 || height < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glCopyPixels(width or height < 0)");
- return;
- }
-
- /* Note: more detailed 'type' checking is done by the
- * _mesa_source/dest_buffer_exists() calls below. That's where we
- * check if the stencil buffer exists, etc.
- */
- if (type != GL_COLOR &&
- type != GL_DEPTH &&
- type != GL_STENCIL &&
- type != GL_DEPTH_STENCIL) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glCopyPixels(type=%s)",
- _mesa_lookup_enum_by_nr(type));
- return;
- }
-
- /* We're not using the current vertex program, and the driver may install
- * it's own. Note: this may dirty some state.
- */
- _mesa_set_vp_override(ctx, GL_TRUE);
-
- /* Note: this call does state validation */
- if (!_mesa_valid_to_render(ctx, "glCopyPixels")) {
- goto end; /* the error code was recorded */
- }
-
- /* Check read buffer's status (draw buffer was already checked) */
- if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
- "glCopyPixels(incomplete framebuffer)" );
- goto end;
- }
-
- if (!_mesa_source_buffer_exists(ctx, type) ||
- !_mesa_dest_buffer_exists(ctx, type)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyPixels(missing source or dest buffer)");
- goto end;
- }
-
- if (!ctx->Current.RasterPosValid || width ==0 || height == 0) {
- goto end; /* no-op, not an error */
- }
-
- if (ctx->RenderMode == GL_RENDER) {
- /* Round to satisfy conformance tests (matches SGI's OpenGL) */
- if (width > 0 && height > 0) {
- GLint destx = IROUND(ctx->Current.RasterPos[0]);
- GLint desty = IROUND(ctx->Current.RasterPos[1]);
- ctx->Driver.CopyPixels( ctx, srcx, srcy, width, height, destx, desty,
- type );
- }
- }
- else if (ctx->RenderMode == GL_FEEDBACK) {
- FLUSH_CURRENT( ctx, 0 );
- _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_COPY_PIXEL_TOKEN );
- _mesa_feedback_vertex( ctx,
- ctx->Current.RasterPos,
- ctx->Current.RasterColor,
- ctx->Current.RasterTexCoords[0] );
- }
- else {
- ASSERT(ctx->RenderMode == GL_SELECT);
- /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
- }
-
-end:
- _mesa_set_vp_override(ctx, GL_FALSE);
-}
-
-
-static void GLAPIENTRY
-_mesa_Bitmap( GLsizei width, GLsizei height,
- GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
- const GLubyte *bitmap )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (width < 0 || height < 0) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glBitmap(width or height < 0)" );
- return;
- }
-
- if (!ctx->Current.RasterPosValid) {
- return; /* do nothing */
- }
-
- /* Note: this call does state validation */
- if (!_mesa_valid_to_render(ctx, "glBitmap")) {
- /* the error code was recorded */
- return;
- }
-
- if (ctx->RenderMode == GL_RENDER) {
- /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
- if (width > 0 && height > 0) {
- const GLfloat epsilon = 0.0001F;
- GLint x = IFLOOR(ctx->Current.RasterPos[0] + epsilon - xorig);
- GLint y = IFLOOR(ctx->Current.RasterPos[1] + epsilon - yorig);
-
- if (ctx->Unpack.BufferObj->Name) {
- /* unpack from PBO */
- if (!_mesa_validate_pbo_access(2, &ctx->Unpack, width, height, 1,
- GL_COLOR_INDEX, GL_BITMAP,
- (GLvoid *) bitmap)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBitmap(invalid PBO access)");
- return;
- }
- if (_mesa_bufferobj_mapped(ctx->Unpack.BufferObj)) {
- /* buffer is mapped - that's an error */
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBitmap(PBO is mapped)");
- return;
- }
- }
-
- ctx->Driver.Bitmap( ctx, x, y, width, height, &ctx->Unpack, bitmap );
- }
- }
-#if _HAVE_FULL_GL
- else if (ctx->RenderMode == GL_FEEDBACK) {
- FLUSH_CURRENT(ctx, 0);
- _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_BITMAP_TOKEN );
- _mesa_feedback_vertex( ctx,
- ctx->Current.RasterPos,
- ctx->Current.RasterColor,
- ctx->Current.RasterTexCoords[0] );
- }
- else {
- ASSERT(ctx->RenderMode == GL_SELECT);
- /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
- }
-#endif
-
- /* update raster position */
- ctx->Current.RasterPos[0] += xmove;
- ctx->Current.RasterPos[1] += ymove;
-}
-
-
-void
-_mesa_init_drawpix_dispatch(struct _glapi_table *disp)
-{
- SET_Bitmap(disp, _mesa_Bitmap);
- SET_CopyPixels(disp, _mesa_CopyPixels);
- SET_DrawPixels(disp, _mesa_DrawPixels);
-}
-
-
-#endif /* FEATURE_drawpix */
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "glheader.h"
+#include "imports.h"
+#include "bufferobj.h"
+#include "context.h"
+#include "drawpix.h"
+#include "enums.h"
+#include "feedback.h"
+#include "framebuffer.h"
+#include "mfeatures.h"
+#include "pbo.h"
+#include "readpix.h"
+#include "state.h"
+#include "dispatch.h"
+
+
+#if FEATURE_drawpix
+
+
+/*
+ * Execute glDrawPixels
+ */
+static void GLAPIENTRY
+_mesa_DrawPixels( GLsizei width, GLsizei height,
+ GLenum format, GLenum type, const GLvoid *pixels )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glDrawPixels(%d, %d, %s, %s, %p) // to %s at %d, %d\n",
+ width, height,
+ _mesa_lookup_enum_by_nr(format),
+ _mesa_lookup_enum_by_nr(type),
+ pixels,
+ _mesa_lookup_enum_by_nr(ctx->DrawBuffer->ColorDrawBuffer[0]),
+ IROUND(ctx->Current.RasterPos[0]),
+ IROUND(ctx->Current.RasterPos[1]));
+
+
+ if (width < 0 || height < 0) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glDrawPixels(width or height < 0" );
+ return;
+ }
+
+ /* We're not using the current vertex program, and the driver may install
+ * its own. Note: this may dirty some state.
+ */
+ _mesa_set_vp_override(ctx, GL_TRUE);
+
+ /* Note: this call does state validation */
+ if (!_mesa_valid_to_render(ctx, "glDrawPixels")) {
+ goto end; /* the error code was recorded */
+ }
+
+ if (_mesa_error_check_format_type(ctx, format, type, GL_TRUE)) {
+ goto end; /* the error code was recorded */
+ }
+
+ if (!ctx->Current.RasterPosValid) {
+ goto end; /* no-op, not an error */
+ }
+
+ if (ctx->RenderMode == GL_RENDER) {
+ if (width > 0 && height > 0) {
+ /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
+ GLint x = IROUND(ctx->Current.RasterPos[0]);
+ GLint y = IROUND(ctx->Current.RasterPos[1]);
+
+ if (ctx->Unpack.BufferObj->Name) {
+ /* unpack from PBO */
+ if (!_mesa_validate_pbo_access(2, &ctx->Unpack, width, height, 1,
+ format, type, pixels)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glDrawPixels(invalid PBO access)");
+ goto end;
+ }
+ if (_mesa_bufferobj_mapped(ctx->Unpack.BufferObj)) {
+ /* buffer is mapped - that's an error */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glDrawPixels(PBO is mapped)");
+ goto end;
+ }
+ }
+
+ ctx->Driver.DrawPixels(ctx, x, y, width, height, format, type,
+ &ctx->Unpack, pixels);
+ }
+ }
+ else if (ctx->RenderMode == GL_FEEDBACK) {
+ /* Feedback the current raster pos info */
+ FLUSH_CURRENT( ctx, 0 );
+ _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_DRAW_PIXEL_TOKEN );
+ _mesa_feedback_vertex( ctx,
+ ctx->Current.RasterPos,
+ ctx->Current.RasterColor,
+ ctx->Current.RasterTexCoords[0] );
+ }
+ else {
+ ASSERT(ctx->RenderMode == GL_SELECT);
+ /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
+ }
+
+end:
+ _mesa_set_vp_override(ctx, GL_FALSE);
+}
+
+
+static void GLAPIENTRY
+_mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
+ GLenum type )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ _mesa_finish(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx,
+ "glCopyPixels(%d, %d, %d, %d, %s) // from %s to %s at %d, %d\n",
+ srcx, srcy, width, height,
+ _mesa_lookup_enum_by_nr(type),
+ _mesa_lookup_enum_by_nr(ctx->ReadBuffer->ColorReadBuffer),
+ _mesa_lookup_enum_by_nr(ctx->DrawBuffer->ColorDrawBuffer[0]),
+ IROUND(ctx->Current.RasterPos[0]),
+ IROUND(ctx->Current.RasterPos[1]));
+
+ if (width < 0 || height < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glCopyPixels(width or height < 0)");
+ return;
+ }
+
+ /* Note: more detailed 'type' checking is done by the
+ * _mesa_source/dest_buffer_exists() calls below. That's where we
+ * check if the stencil buffer exists, etc.
+ */
+ if (type != GL_COLOR &&
+ type != GL_DEPTH &&
+ type != GL_STENCIL &&
+ type != GL_DEPTH_STENCIL) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCopyPixels(type=%s)",
+ _mesa_lookup_enum_by_nr(type));
+ return;
+ }
+
+ /* We're not using the current vertex program, and the driver may install
+ * it's own. Note: this may dirty some state.
+ */
+ _mesa_set_vp_override(ctx, GL_TRUE);
+
+ /* Note: this call does state validation */
+ if (!_mesa_valid_to_render(ctx, "glCopyPixels")) {
+ goto end; /* the error code was recorded */
+ }
+
+ /* Check read buffer's status (draw buffer was already checked) */
+ if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+ "glCopyPixels(incomplete framebuffer)" );
+ goto end;
+ }
+
+ if (!_mesa_source_buffer_exists(ctx, type) ||
+ !_mesa_dest_buffer_exists(ctx, type)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyPixels(missing source or dest buffer)");
+ goto end;
+ }
+
+ if (!ctx->Current.RasterPosValid || width ==0 || height == 0) {
+ goto end; /* no-op, not an error */
+ }
+
+ if (ctx->RenderMode == GL_RENDER) {
+ /* Round to satisfy conformance tests (matches SGI's OpenGL) */
+ if (width > 0 && height > 0) {
+ GLint destx = IROUND(ctx->Current.RasterPos[0]);
+ GLint desty = IROUND(ctx->Current.RasterPos[1]);
+ ctx->Driver.CopyPixels( ctx, srcx, srcy, width, height, destx, desty,
+ type );
+ }
+ }
+ else if (ctx->RenderMode == GL_FEEDBACK) {
+ FLUSH_CURRENT( ctx, 0 );
+ _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_COPY_PIXEL_TOKEN );
+ _mesa_feedback_vertex( ctx,
+ ctx->Current.RasterPos,
+ ctx->Current.RasterColor,
+ ctx->Current.RasterTexCoords[0] );
+ }
+ else {
+ ASSERT(ctx->RenderMode == GL_SELECT);
+ /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
+ }
+
+end:
+ _mesa_set_vp_override(ctx, GL_FALSE);
+}
+
+
+static void GLAPIENTRY
+_mesa_Bitmap( GLsizei width, GLsizei height,
+ GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
+ const GLubyte *bitmap )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (width < 0 || height < 0) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glBitmap(width or height < 0)" );
+ return;
+ }
+
+ if (!ctx->Current.RasterPosValid) {
+ return; /* do nothing */
+ }
+
+ /* Note: this call does state validation */
+ if (!_mesa_valid_to_render(ctx, "glBitmap")) {
+ /* the error code was recorded */
+ return;
+ }
+
+ if (ctx->RenderMode == GL_RENDER) {
+ /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
+ if (width > 0 && height > 0) {
+ const GLfloat epsilon = 0.0001F;
+ GLint x = IFLOOR(ctx->Current.RasterPos[0] + epsilon - xorig);
+ GLint y = IFLOOR(ctx->Current.RasterPos[1] + epsilon - yorig);
+
+ if (ctx->Unpack.BufferObj->Name) {
+ /* unpack from PBO */
+ if (!_mesa_validate_pbo_access(2, &ctx->Unpack, width, height, 1,
+ GL_COLOR_INDEX, GL_BITMAP,
+ (GLvoid *) bitmap)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBitmap(invalid PBO access)");
+ return;
+ }
+ if (_mesa_bufferobj_mapped(ctx->Unpack.BufferObj)) {
+ /* buffer is mapped - that's an error */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBitmap(PBO is mapped)");
+ return;
+ }
+ }
+
+ ctx->Driver.Bitmap( ctx, x, y, width, height, &ctx->Unpack, bitmap );
+ }
+ }
+#if _HAVE_FULL_GL
+ else if (ctx->RenderMode == GL_FEEDBACK) {
+ FLUSH_CURRENT(ctx, 0);
+ _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_BITMAP_TOKEN );
+ _mesa_feedback_vertex( ctx,
+ ctx->Current.RasterPos,
+ ctx->Current.RasterColor,
+ ctx->Current.RasterTexCoords[0] );
+ }
+ else {
+ ASSERT(ctx->RenderMode == GL_SELECT);
+ /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
+ }
+#endif
+
+ /* update raster position */
+ ctx->Current.RasterPos[0] += xmove;
+ ctx->Current.RasterPos[1] += ymove;
+}
+
+
+void
+_mesa_init_drawpix_dispatch(struct _glapi_table *disp)
+{
+ SET_Bitmap(disp, _mesa_Bitmap);
+ SET_CopyPixels(disp, _mesa_CopyPixels);
+ SET_DrawPixels(disp, _mesa_DrawPixels);
+}
+
+
+#endif /* FEATURE_drawpix */
diff --git a/mesalib/src/mesa/main/enable.c b/mesalib/src/mesa/main/enable.c
index f24709241..32c3c8713 100644
--- a/mesalib/src/mesa/main/enable.c
+++ b/mesalib/src/mesa/main/enable.c
@@ -1,1487 +1,1487 @@
-/**
- * \file enable.c
- * Enable/disable/query GL capabilities.
- */
-
-/*
- * Mesa 3-D graphics library
- * Version: 7.0.3
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "glheader.h"
-#include "context.h"
-#include "enable.h"
-#include "light.h"
-#include "simple_list.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "enums.h"
-#include "api_arrayelt.h"
-#include "texstate.h"
-
-
-
-#define CHECK_EXTENSION(EXTNAME, CAP) \
- if (!ctx->Extensions.EXTNAME) { \
- goto invalid_enum_error; \
- }
-
-
-/**
- * Helper to enable/disable client-side state.
- */
-static void
-client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
-{
- struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
- GLuint flag;
- GLboolean *var;
-
- switch (cap) {
- case GL_VERTEX_ARRAY:
- var = &arrayObj->Vertex.Enabled;
- flag = _NEW_ARRAY_VERTEX;
- break;
- case GL_NORMAL_ARRAY:
- var = &arrayObj->Normal.Enabled;
- flag = _NEW_ARRAY_NORMAL;
- break;
- case GL_COLOR_ARRAY:
- var = &arrayObj->Color.Enabled;
- flag = _NEW_ARRAY_COLOR0;
- break;
- case GL_INDEX_ARRAY:
- var = &arrayObj->Index.Enabled;
- flag = _NEW_ARRAY_INDEX;
- break;
- case GL_TEXTURE_COORD_ARRAY:
- var = &arrayObj->TexCoord[ctx->Array.ActiveTexture].Enabled;
- flag = _NEW_ARRAY_TEXCOORD(ctx->Array.ActiveTexture);
- break;
- case GL_EDGE_FLAG_ARRAY:
- var = &arrayObj->EdgeFlag.Enabled;
- flag = _NEW_ARRAY_EDGEFLAG;
- break;
- case GL_FOG_COORDINATE_ARRAY_EXT:
- var = &arrayObj->FogCoord.Enabled;
- flag = _NEW_ARRAY_FOGCOORD;
- break;
- case GL_SECONDARY_COLOR_ARRAY_EXT:
- var = &arrayObj->SecondaryColor.Enabled;
- flag = _NEW_ARRAY_COLOR1;
- break;
-
-#if FEATURE_point_size_array
- case GL_POINT_SIZE_ARRAY_OES:
- var = &arrayObj->PointSize.Enabled;
- flag = _NEW_ARRAY_POINT_SIZE;
- break;
-#endif
-
-#if FEATURE_NV_vertex_program
- case GL_VERTEX_ATTRIB_ARRAY0_NV:
- case GL_VERTEX_ATTRIB_ARRAY1_NV:
- case GL_VERTEX_ATTRIB_ARRAY2_NV:
- case GL_VERTEX_ATTRIB_ARRAY3_NV:
- case GL_VERTEX_ATTRIB_ARRAY4_NV:
- case GL_VERTEX_ATTRIB_ARRAY5_NV:
- case GL_VERTEX_ATTRIB_ARRAY6_NV:
- case GL_VERTEX_ATTRIB_ARRAY7_NV:
- case GL_VERTEX_ATTRIB_ARRAY8_NV:
- case GL_VERTEX_ATTRIB_ARRAY9_NV:
- case GL_VERTEX_ATTRIB_ARRAY10_NV:
- case GL_VERTEX_ATTRIB_ARRAY11_NV:
- case GL_VERTEX_ATTRIB_ARRAY12_NV:
- case GL_VERTEX_ATTRIB_ARRAY13_NV:
- case GL_VERTEX_ATTRIB_ARRAY14_NV:
- case GL_VERTEX_ATTRIB_ARRAY15_NV:
- CHECK_EXTENSION(NV_vertex_program, cap);
- {
- GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
- ASSERT(n < Elements(ctx->Array.ArrayObj->VertexAttrib));
- var = &arrayObj->VertexAttrib[n].Enabled;
- flag = _NEW_ARRAY_ATTRIB(n);
- }
- break;
-#endif /* FEATURE_NV_vertex_program */
-
- /* GL_NV_primitive_restart */
- case GL_PRIMITIVE_RESTART_NV:
- if (!ctx->Extensions.NV_primitive_restart) {
- goto invalid_enum_error;
- }
- var = &ctx->Array.PrimitiveRestart;
- flag = 0;
- break;
-
- default:
- goto invalid_enum_error;
- }
-
- if (*var == state)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_ARRAY);
- ctx->Array.NewState |= flag;
-
- _ae_invalidate_state(ctx, _NEW_ARRAY);
-
- *var = state;
-
- if (state)
- ctx->Array.ArrayObj->_Enabled |= flag;
- else
- ctx->Array.ArrayObj->_Enabled &= ~flag;
-
- if (ctx->Driver.Enable) {
- ctx->Driver.Enable( ctx, cap, state );
- }
-
- return;
-
-invalid_enum_error:
- _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(0x%x)",
- state ? "Enable" : "Disable", cap);
-}
-
-
-/**
- * Enable GL capability.
- * \param cap state to enable/disable.
- *
- * Get's the current context, assures that we're outside glBegin()/glEnd() and
- * calls client_state().
- */
-void GLAPIENTRY
-_mesa_EnableClientState( GLenum cap )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
- client_state( ctx, cap, GL_TRUE );
-}
-
-
-/**
- * Disable GL capability.
- * \param cap state to enable/disable.
- *
- * Get's the current context, assures that we're outside glBegin()/glEnd() and
- * calls client_state().
- */
-void GLAPIENTRY
-_mesa_DisableClientState( GLenum cap )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
- client_state( ctx, cap, GL_FALSE );
-}
-
-
-#undef CHECK_EXTENSION
-#define CHECK_EXTENSION(EXTNAME, CAP) \
- if (!ctx->Extensions.EXTNAME) { \
- goto invalid_enum_error; \
- }
-
-#define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
- if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
- goto invalid_enum_error; \
- }
-
-
-
-/**
- * Return pointer to current texture unit for setting/getting coordinate
- * state.
- * Note that we'll set GL_INVALID_OPERATION if the active texture unit is
- * higher than the number of supported coordinate units. And we'll return NULL.
- */
-static struct gl_texture_unit *
-get_texcoord_unit(struct gl_context *ctx)
-{
- if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
- return NULL;
- }
- else {
- return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- }
-}
-
-
-/**
- * Helper function to enable or disable a texture target.
- * \param bit one of the TEXTURE_x_BIT values
- * \return GL_TRUE if state is changing or GL_FALSE if no change
- */
-static GLboolean
-enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
-{
- struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
- const GLbitfield newenabled = state
- ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
-
- if (texUnit->Enabled == newenabled)
- return GL_FALSE;
-
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->Enabled = newenabled;
- return GL_TRUE;
-}
-
-
-/**
- * Helper function to enable or disable state.
- *
- * \param ctx GL context.
- * \param cap the state to enable/disable
- * \param state whether to enable or disable the specified capability.
- *
- * Updates the current context and flushes the vertices as needed. For
- * capabilities associated with extensions it verifies that those extensions
- * are effectivly present before updating. Notifies the driver via
- * dd_function_table::Enable.
- */
-void
-_mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
-{
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "%s %s (newstate is %x)\n",
- state ? "glEnable" : "glDisable",
- _mesa_lookup_enum_by_nr(cap),
- ctx->NewState);
-
- switch (cap) {
- case GL_ALPHA_TEST:
- if (ctx->Color.AlphaEnabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- ctx->Color.AlphaEnabled = state;
- break;
- case GL_AUTO_NORMAL:
- if (ctx->Eval.AutoNormal == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.AutoNormal = state;
- break;
- case GL_BLEND:
- {
- GLbitfield newEnabled = state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
- if (newEnabled != ctx->Color.BlendEnabled) {
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- ctx->Color.BlendEnabled = newEnabled;
- }
- }
- break;
-#if FEATURE_userclip
- case GL_CLIP_PLANE0:
- case GL_CLIP_PLANE1:
- case GL_CLIP_PLANE2:
- case GL_CLIP_PLANE3:
- case GL_CLIP_PLANE4:
- case GL_CLIP_PLANE5:
- {
- const GLuint p = cap - GL_CLIP_PLANE0;
-
- if ((ctx->Transform.ClipPlanesEnabled & (1 << p)) == ((GLuint) state << p))
- return;
-
- FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
-
- if (state) {
- ctx->Transform.ClipPlanesEnabled |= (1 << p);
-
- if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top))
- _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
-
- /* This derived state also calculated in clip.c and
- * from _mesa_update_state() on changes to EyeUserPlane
- * and ctx->ProjectionMatrix respectively.
- */
- _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
- ctx->Transform.EyeUserPlane[p],
- ctx->ProjectionMatrixStack.Top->inv );
- }
- else {
- ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
- }
- }
- break;
-#endif
- case GL_COLOR_MATERIAL:
- if (ctx->Light.ColorMaterialEnabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- FLUSH_CURRENT(ctx, 0);
- ctx->Light.ColorMaterialEnabled = state;
- if (state) {
- _mesa_update_color_material( ctx,
- ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
- }
- break;
- case GL_CULL_FACE:
- if (ctx->Polygon.CullFlag == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.CullFlag = state;
- break;
- case GL_DEPTH_TEST:
- if (ctx->Depth.Test == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_DEPTH);
- ctx->Depth.Test = state;
- break;
- case GL_DITHER:
- if (ctx->Color.DitherFlag == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- ctx->Color.DitherFlag = state;
- break;
- case GL_FOG:
- if (ctx->Fog.Enabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_FOG);
- ctx->Fog.Enabled = state;
- break;
- case GL_LIGHT0:
- case GL_LIGHT1:
- case GL_LIGHT2:
- case GL_LIGHT3:
- case GL_LIGHT4:
- case GL_LIGHT5:
- case GL_LIGHT6:
- case GL_LIGHT7:
- if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
- if (state) {
- insert_at_tail(&ctx->Light.EnabledList,
- &ctx->Light.Light[cap-GL_LIGHT0]);
- }
- else {
- remove_from_list(&ctx->Light.Light[cap-GL_LIGHT0]);
- }
- break;
- case GL_LIGHTING:
- if (ctx->Light.Enabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.Enabled = state;
- if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
- ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
- else
- ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
- break;
- case GL_LINE_SMOOTH:
- if (ctx->Line.SmoothFlag == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_LINE);
- ctx->Line.SmoothFlag = state;
- ctx->_TriangleCaps ^= DD_LINE_SMOOTH;
- break;
- case GL_LINE_STIPPLE:
- if (ctx->Line.StippleFlag == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_LINE);
- ctx->Line.StippleFlag = state;
- ctx->_TriangleCaps ^= DD_LINE_STIPPLE;
- break;
- case GL_INDEX_LOGIC_OP:
- if (ctx->Color.IndexLogicOpEnabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- ctx->Color.IndexLogicOpEnabled = state;
- break;
- case GL_COLOR_LOGIC_OP:
- if (ctx->Color.ColorLogicOpEnabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- ctx->Color.ColorLogicOpEnabled = state;
- break;
- case GL_MAP1_COLOR_4:
- if (ctx->Eval.Map1Color4 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map1Color4 = state;
- break;
- case GL_MAP1_INDEX:
- if (ctx->Eval.Map1Index == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map1Index = state;
- break;
- case GL_MAP1_NORMAL:
- if (ctx->Eval.Map1Normal == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map1Normal = state;
- break;
- case GL_MAP1_TEXTURE_COORD_1:
- if (ctx->Eval.Map1TextureCoord1 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map1TextureCoord1 = state;
- break;
- case GL_MAP1_TEXTURE_COORD_2:
- if (ctx->Eval.Map1TextureCoord2 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map1TextureCoord2 = state;
- break;
- case GL_MAP1_TEXTURE_COORD_3:
- if (ctx->Eval.Map1TextureCoord3 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map1TextureCoord3 = state;
- break;
- case GL_MAP1_TEXTURE_COORD_4:
- if (ctx->Eval.Map1TextureCoord4 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map1TextureCoord4 = state;
- break;
- case GL_MAP1_VERTEX_3:
- if (ctx->Eval.Map1Vertex3 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map1Vertex3 = state;
- break;
- case GL_MAP1_VERTEX_4:
- if (ctx->Eval.Map1Vertex4 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map1Vertex4 = state;
- break;
- case GL_MAP2_COLOR_4:
- if (ctx->Eval.Map2Color4 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map2Color4 = state;
- break;
- case GL_MAP2_INDEX:
- if (ctx->Eval.Map2Index == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map2Index = state;
- break;
- case GL_MAP2_NORMAL:
- if (ctx->Eval.Map2Normal == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map2Normal = state;
- break;
- case GL_MAP2_TEXTURE_COORD_1:
- if (ctx->Eval.Map2TextureCoord1 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map2TextureCoord1 = state;
- break;
- case GL_MAP2_TEXTURE_COORD_2:
- if (ctx->Eval.Map2TextureCoord2 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map2TextureCoord2 = state;
- break;
- case GL_MAP2_TEXTURE_COORD_3:
- if (ctx->Eval.Map2TextureCoord3 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map2TextureCoord3 = state;
- break;
- case GL_MAP2_TEXTURE_COORD_4:
- if (ctx->Eval.Map2TextureCoord4 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map2TextureCoord4 = state;
- break;
- case GL_MAP2_VERTEX_3:
- if (ctx->Eval.Map2Vertex3 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map2Vertex3 = state;
- break;
- case GL_MAP2_VERTEX_4:
- if (ctx->Eval.Map2Vertex4 == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map2Vertex4 = state;
- break;
- case GL_NORMALIZE:
- if (ctx->Transform.Normalize == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
- ctx->Transform.Normalize = state;
- break;
- case GL_POINT_SMOOTH:
- if (ctx->Point.SmoothFlag == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_POINT);
- ctx->Point.SmoothFlag = state;
- ctx->_TriangleCaps ^= DD_POINT_SMOOTH;
- break;
- case GL_POLYGON_SMOOTH:
- if (ctx->Polygon.SmoothFlag == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.SmoothFlag = state;
- ctx->_TriangleCaps ^= DD_TRI_SMOOTH;
- break;
- case GL_POLYGON_STIPPLE:
- if (ctx->Polygon.StippleFlag == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.StippleFlag = state;
- ctx->_TriangleCaps ^= DD_TRI_STIPPLE;
- break;
- case GL_POLYGON_OFFSET_POINT:
- if (ctx->Polygon.OffsetPoint == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.OffsetPoint = state;
- break;
- case GL_POLYGON_OFFSET_LINE:
- if (ctx->Polygon.OffsetLine == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.OffsetLine = state;
- break;
- case GL_POLYGON_OFFSET_FILL:
- /*case GL_POLYGON_OFFSET_EXT:*/
- if (ctx->Polygon.OffsetFill == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.OffsetFill = state;
- break;
- case GL_RESCALE_NORMAL_EXT:
- if (ctx->Transform.RescaleNormals == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
- ctx->Transform.RescaleNormals = state;
- break;
- case GL_SCISSOR_TEST:
- if (ctx->Scissor.Enabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_SCISSOR);
- ctx->Scissor.Enabled = state;
- break;
- case GL_SHARED_TEXTURE_PALETTE_EXT:
- if (ctx->Texture.SharedPalette == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- ctx->Texture.SharedPalette = state;
- break;
- case GL_STENCIL_TEST:
- if (ctx->Stencil.Enabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.Enabled = state;
- break;
- case GL_TEXTURE_1D:
- if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
- return;
- }
- break;
- case GL_TEXTURE_2D:
- if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
- return;
- }
- break;
- case GL_TEXTURE_3D:
- if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
- return;
- }
- break;
- case GL_TEXTURE_GEN_Q:
- {
- struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
- if (texUnit) {
- GLuint newenabled = texUnit->TexGenEnabled & ~Q_BIT;
- if (state)
- newenabled |= Q_BIT;
- if (texUnit->TexGenEnabled == newenabled)
- return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->TexGenEnabled = newenabled;
- }
- }
- break;
- case GL_TEXTURE_GEN_R:
- {
- struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
- if (texUnit) {
- GLuint newenabled = texUnit->TexGenEnabled & ~R_BIT;
- if (state)
- newenabled |= R_BIT;
- if (texUnit->TexGenEnabled == newenabled)
- return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->TexGenEnabled = newenabled;
- }
- }
- break;
- case GL_TEXTURE_GEN_S:
- {
- struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
- if (texUnit) {
- GLuint newenabled = texUnit->TexGenEnabled & ~S_BIT;
- if (state)
- newenabled |= S_BIT;
- if (texUnit->TexGenEnabled == newenabled)
- return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->TexGenEnabled = newenabled;
- }
- }
- break;
- case GL_TEXTURE_GEN_T:
- {
- struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
- if (texUnit) {
- GLuint newenabled = texUnit->TexGenEnabled & ~T_BIT;
- if (state)
- newenabled |= T_BIT;
- if (texUnit->TexGenEnabled == newenabled)
- return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->TexGenEnabled = newenabled;
- }
- }
- break;
-
-#if FEATURE_ES1
- case GL_TEXTURE_GEN_STR_OES:
- /* disable S, T, and R at the same time */
- {
- struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
- if (texUnit) {
- GLuint newenabled =
- texUnit->TexGenEnabled & ~STR_BITS;
- if (state)
- newenabled |= STR_BITS;
- if (texUnit->TexGenEnabled == newenabled)
- return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->TexGenEnabled = newenabled;
- }
- }
- break;
-#endif
-
- /*
- * CLIENT STATE!!!
- */
- case GL_VERTEX_ARRAY:
- case GL_NORMAL_ARRAY:
- case GL_COLOR_ARRAY:
- case GL_INDEX_ARRAY:
- case GL_TEXTURE_COORD_ARRAY:
- case GL_EDGE_FLAG_ARRAY:
- case GL_FOG_COORDINATE_ARRAY_EXT:
- case GL_SECONDARY_COLOR_ARRAY_EXT:
- case GL_POINT_SIZE_ARRAY_OES:
- client_state( ctx, cap, state );
- return;
-
- /* GL_ARB_texture_cube_map */
- case GL_TEXTURE_CUBE_MAP_ARB:
- CHECK_EXTENSION(ARB_texture_cube_map, cap);
- if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
- return;
- }
- break;
-
- /* GL_EXT_secondary_color */
- case GL_COLOR_SUM_EXT:
- CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program, cap);
- if (ctx->Fog.ColorSumEnabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_FOG);
- ctx->Fog.ColorSumEnabled = state;
- break;
-
- /* GL_ARB_multisample */
- case GL_MULTISAMPLE_ARB:
- if (ctx->Multisample.Enabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
- ctx->Multisample.Enabled = state;
- break;
- case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
- if (ctx->Multisample.SampleAlphaToCoverage == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
- ctx->Multisample.SampleAlphaToCoverage = state;
- break;
- case GL_SAMPLE_ALPHA_TO_ONE_ARB:
- if (ctx->Multisample.SampleAlphaToOne == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
- ctx->Multisample.SampleAlphaToOne = state;
- break;
- case GL_SAMPLE_COVERAGE_ARB:
- if (ctx->Multisample.SampleCoverage == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
- ctx->Multisample.SampleCoverage = state;
- break;
- case GL_SAMPLE_COVERAGE_INVERT_ARB:
- if (ctx->Multisample.SampleCoverageInvert == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
- ctx->Multisample.SampleCoverageInvert = state;
- break;
-
- /* GL_IBM_rasterpos_clip */
- case GL_RASTER_POSITION_UNCLIPPED_IBM:
- CHECK_EXTENSION(IBM_rasterpos_clip, cap);
- if (ctx->Transform.RasterPositionUnclipped == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
- ctx->Transform.RasterPositionUnclipped = state;
- break;
-
- /* GL_NV_point_sprite */
- case GL_POINT_SPRITE_NV:
- CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
- if (ctx->Point.PointSprite == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_POINT);
- ctx->Point.PointSprite = state;
- break;
-
-#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
- case GL_VERTEX_PROGRAM_ARB:
- CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
- if (ctx->VertexProgram.Enabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_PROGRAM);
- ctx->VertexProgram.Enabled = state;
- break;
- case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
- CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
- if (ctx->VertexProgram.PointSizeEnabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_PROGRAM);
- ctx->VertexProgram.PointSizeEnabled = state;
- break;
- case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
- CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
- if (ctx->VertexProgram.TwoSideEnabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_PROGRAM);
- ctx->VertexProgram.TwoSideEnabled = state;
- break;
-#endif
-#if FEATURE_NV_vertex_program
- case GL_MAP1_VERTEX_ATTRIB0_4_NV:
- case GL_MAP1_VERTEX_ATTRIB1_4_NV:
- case GL_MAP1_VERTEX_ATTRIB2_4_NV:
- case GL_MAP1_VERTEX_ATTRIB3_4_NV:
- case GL_MAP1_VERTEX_ATTRIB4_4_NV:
- case GL_MAP1_VERTEX_ATTRIB5_4_NV:
- case GL_MAP1_VERTEX_ATTRIB6_4_NV:
- case GL_MAP1_VERTEX_ATTRIB7_4_NV:
- case GL_MAP1_VERTEX_ATTRIB8_4_NV:
- case GL_MAP1_VERTEX_ATTRIB9_4_NV:
- case GL_MAP1_VERTEX_ATTRIB10_4_NV:
- case GL_MAP1_VERTEX_ATTRIB11_4_NV:
- case GL_MAP1_VERTEX_ATTRIB12_4_NV:
- case GL_MAP1_VERTEX_ATTRIB13_4_NV:
- case GL_MAP1_VERTEX_ATTRIB14_4_NV:
- case GL_MAP1_VERTEX_ATTRIB15_4_NV:
- CHECK_EXTENSION(NV_vertex_program, cap);
- {
- const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map1Attrib[map] = state;
- }
- break;
- case GL_MAP2_VERTEX_ATTRIB0_4_NV:
- case GL_MAP2_VERTEX_ATTRIB1_4_NV:
- case GL_MAP2_VERTEX_ATTRIB2_4_NV:
- case GL_MAP2_VERTEX_ATTRIB3_4_NV:
- case GL_MAP2_VERTEX_ATTRIB4_4_NV:
- case GL_MAP2_VERTEX_ATTRIB5_4_NV:
- case GL_MAP2_VERTEX_ATTRIB6_4_NV:
- case GL_MAP2_VERTEX_ATTRIB7_4_NV:
- case GL_MAP2_VERTEX_ATTRIB8_4_NV:
- case GL_MAP2_VERTEX_ATTRIB9_4_NV:
- case GL_MAP2_VERTEX_ATTRIB10_4_NV:
- case GL_MAP2_VERTEX_ATTRIB11_4_NV:
- case GL_MAP2_VERTEX_ATTRIB12_4_NV:
- case GL_MAP2_VERTEX_ATTRIB13_4_NV:
- case GL_MAP2_VERTEX_ATTRIB14_4_NV:
- case GL_MAP2_VERTEX_ATTRIB15_4_NV:
- CHECK_EXTENSION(NV_vertex_program, cap);
- {
- const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
- FLUSH_VERTICES(ctx, _NEW_EVAL);
- ctx->Eval.Map2Attrib[map] = state;
- }
- break;
-#endif /* FEATURE_NV_vertex_program */
-
-#if FEATURE_NV_fragment_program
- case GL_FRAGMENT_PROGRAM_NV:
- CHECK_EXTENSION(NV_fragment_program, cap);
- if (ctx->FragmentProgram.Enabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_PROGRAM);
- ctx->FragmentProgram.Enabled = state;
- break;
-#endif /* FEATURE_NV_fragment_program */
-
- /* GL_NV_texture_rectangle */
- case GL_TEXTURE_RECTANGLE_NV:
- CHECK_EXTENSION(NV_texture_rectangle, cap);
- if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
- return;
- }
- break;
-
- /* GL_EXT_stencil_two_side */
- case GL_STENCIL_TEST_TWO_SIDE_EXT:
- CHECK_EXTENSION(EXT_stencil_two_side, cap);
- if (ctx->Stencil.TestTwoSide == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.TestTwoSide = state;
- if (state) {
- ctx->Stencil._BackFace = 2;
- ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
- } else {
- ctx->Stencil._BackFace = 1;
- ctx->_TriangleCaps &= ~DD_TRI_TWOSTENCIL;
- }
- break;
-
-#if FEATURE_ARB_fragment_program
- case GL_FRAGMENT_PROGRAM_ARB:
- CHECK_EXTENSION(ARB_fragment_program, cap);
- if (ctx->FragmentProgram.Enabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_PROGRAM);
- ctx->FragmentProgram.Enabled = state;
- break;
-#endif /* FEATURE_ARB_fragment_program */
-
- /* GL_EXT_depth_bounds_test */
- case GL_DEPTH_BOUNDS_TEST_EXT:
- CHECK_EXTENSION(EXT_depth_bounds_test, cap);
- if (ctx->Depth.BoundsTest == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_DEPTH);
- ctx->Depth.BoundsTest = state;
- break;
-
- case GL_DEPTH_CLAMP:
- if (ctx->Transform.DepthClamp == state)
- return;
- CHECK_EXTENSION(ARB_depth_clamp, cap);
- FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
- ctx->Transform.DepthClamp = state;
- break;
-
-#if FEATURE_ATI_fragment_shader
- case GL_FRAGMENT_SHADER_ATI:
- CHECK_EXTENSION(ATI_fragment_shader, cap);
- if (ctx->ATIFragmentShader.Enabled == state)
- return;
- FLUSH_VERTICES(ctx, _NEW_PROGRAM);
- ctx->ATIFragmentShader.Enabled = state;
- break;
-#endif
-
- /* GL_MESA_texture_array */
- case GL_TEXTURE_1D_ARRAY_EXT:
- CHECK_EXTENSION(MESA_texture_array, cap);
- if (!enable_texture(ctx, state, TEXTURE_1D_ARRAY_BIT)) {
- return;
- }
- break;
-
- case GL_TEXTURE_2D_ARRAY_EXT:
- CHECK_EXTENSION(MESA_texture_array, cap);
- if (!enable_texture(ctx, state, TEXTURE_2D_ARRAY_BIT)) {
- return;
- }
- break;
-
- case GL_TEXTURE_CUBE_MAP_SEAMLESS:
- CHECK_EXTENSION(ARB_seamless_cube_map, cap);
- ctx->Texture.CubeMapSeamless = state;
- break;
-
-#if FEATURE_EXT_transform_feedback
- case GL_RASTERIZER_DISCARD:
- CHECK_EXTENSION(EXT_transform_feedback, cap);
- if (ctx->TransformFeedback.RasterDiscard != state) {
- ctx->TransformFeedback.RasterDiscard = state;
- FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
- }
- break;
-#endif
-
- /* GL 3.1 primitive restart. Note: this enum is different from
- * GL_PRIMITIVE_RESTART_NV (which is client state).
- */
- case GL_PRIMITIVE_RESTART:
- if (ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
- goto invalid_enum_error;
- }
- if (ctx->Array.PrimitiveRestart != state) {
- FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
- ctx->Array.PrimitiveRestart = state;
- }
- break;
-
- /* GL3.0 - GL_framebuffer_sRGB */
- case GL_FRAMEBUFFER_SRGB_EXT:
- CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
- ctx->Color.sRGBEnabled = state;
- break;
-
- default:
- goto invalid_enum_error;
- }
-
- if (ctx->Driver.Enable) {
- ctx->Driver.Enable( ctx, cap, state );
- }
-
- return;
-
-invalid_enum_error:
- _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)",
- state ? "Enable" : "Disable", cap);
-}
-
-
-/**
- * Enable GL capability. Called by glEnable()
- * \param cap state to enable.
- */
-void GLAPIENTRY
-_mesa_Enable( GLenum cap )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- _mesa_set_enable( ctx, cap, GL_TRUE );
-}
-
-
-/**
- * Disable GL capability. Called by glDisable()
- * \param cap state to disable.
- */
-void GLAPIENTRY
-_mesa_Disable( GLenum cap )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- _mesa_set_enable( ctx, cap, GL_FALSE );
-}
-
-
-
-/**
- * Enable/disable an indexed state var.
- */
-void
-_mesa_set_enablei(struct gl_context *ctx, GLenum cap, GLuint index, GLboolean state)
-{
- ASSERT(state == 0 || state == 1);
- switch (cap) {
- case GL_BLEND:
- if (!ctx->Extensions.EXT_draw_buffers2) {
- goto invalid_enum_error;
- }
- if (index >= ctx->Const.MaxDrawBuffers) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
- state ? "glEnableIndexed" : "glDisableIndexed", index);
- return;
- }
- if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
- FLUSH_VERTICES(ctx, _NEW_COLOR);
- if (state)
- ctx->Color.BlendEnabled |= (1 << index);
- else
- ctx->Color.BlendEnabled &= ~(1 << index);
- }
- break;
- default:
- goto invalid_enum_error;
- }
- return;
-
-invalid_enum_error:
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
- state ? "glEnablei" : "glDisablei",
- _mesa_lookup_enum_by_nr(cap));
-}
-
-
-void GLAPIENTRY
-_mesa_DisableIndexed( GLenum cap, GLuint index )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
- _mesa_set_enablei(ctx, cap, index, GL_FALSE);
-}
-
-
-void GLAPIENTRY
-_mesa_EnableIndexed( GLenum cap, GLuint index )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
- _mesa_set_enablei(ctx, cap, index, GL_TRUE);
-}
-
-
-GLboolean GLAPIENTRY
-_mesa_IsEnabledIndexed( GLenum cap, GLuint index )
-{
- GET_CURRENT_CONTEXT(ctx);
- switch (cap) {
- case GL_BLEND:
- if (index >= ctx->Const.MaxDrawBuffers) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
- index);
- return GL_FALSE;
- }
- return (ctx->Color.BlendEnabled >> index) & 1;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
- _mesa_lookup_enum_by_nr(cap));
- return GL_FALSE;
- }
-}
-
-
-
-
-#undef CHECK_EXTENSION
-#define CHECK_EXTENSION(EXTNAME) \
- if (!ctx->Extensions.EXTNAME) { \
- goto invalid_enum_error; \
- }
-
-#undef CHECK_EXTENSION2
-#define CHECK_EXTENSION2(EXT1, EXT2) \
- if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
- goto invalid_enum_error; \
- }
-
-
-/**
- * Helper function to determine whether a texture target is enabled.
- */
-static GLboolean
-is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
-{
- const struct gl_texture_unit *const texUnit =
- &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
-}
-
-
-/**
- * Return simple enable/disable state.
- *
- * \param cap state variable to query.
- *
- * Returns the state of the specified capability from the current GL context.
- * For the capabilities associated with extensions verifies that those
- * extensions are effectively present before reporting.
- */
-GLboolean GLAPIENTRY
-_mesa_IsEnabled( GLenum cap )
-{
- GET_CURRENT_CONTEXT(ctx);
- switch (cap) {
- case GL_ALPHA_TEST:
- return ctx->Color.AlphaEnabled;
- case GL_AUTO_NORMAL:
- return ctx->Eval.AutoNormal;
- case GL_BLEND:
- return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
- case GL_CLIP_PLANE0:
- case GL_CLIP_PLANE1:
- case GL_CLIP_PLANE2:
- case GL_CLIP_PLANE3:
- case GL_CLIP_PLANE4:
- case GL_CLIP_PLANE5:
- return (ctx->Transform.ClipPlanesEnabled >> (cap - GL_CLIP_PLANE0)) & 1;
- case GL_COLOR_MATERIAL:
- return ctx->Light.ColorMaterialEnabled;
- case GL_CULL_FACE:
- return ctx->Polygon.CullFlag;
- case GL_DEPTH_TEST:
- return ctx->Depth.Test;
- case GL_DITHER:
- return ctx->Color.DitherFlag;
- case GL_FOG:
- return ctx->Fog.Enabled;
- case GL_LIGHTING:
- return ctx->Light.Enabled;
- case GL_LIGHT0:
- case GL_LIGHT1:
- case GL_LIGHT2:
- case GL_LIGHT3:
- case GL_LIGHT4:
- case GL_LIGHT5:
- case GL_LIGHT6:
- case GL_LIGHT7:
- return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
- case GL_LINE_SMOOTH:
- return ctx->Line.SmoothFlag;
- case GL_LINE_STIPPLE:
- return ctx->Line.StippleFlag;
- case GL_INDEX_LOGIC_OP:
- return ctx->Color.IndexLogicOpEnabled;
- case GL_COLOR_LOGIC_OP:
- return ctx->Color.ColorLogicOpEnabled;
- case GL_MAP1_COLOR_4:
- return ctx->Eval.Map1Color4;
- case GL_MAP1_INDEX:
- return ctx->Eval.Map1Index;
- case GL_MAP1_NORMAL:
- return ctx->Eval.Map1Normal;
- case GL_MAP1_TEXTURE_COORD_1:
- return ctx->Eval.Map1TextureCoord1;
- case GL_MAP1_TEXTURE_COORD_2:
- return ctx->Eval.Map1TextureCoord2;
- case GL_MAP1_TEXTURE_COORD_3:
- return ctx->Eval.Map1TextureCoord3;
- case GL_MAP1_TEXTURE_COORD_4:
- return ctx->Eval.Map1TextureCoord4;
- case GL_MAP1_VERTEX_3:
- return ctx->Eval.Map1Vertex3;
- case GL_MAP1_VERTEX_4:
- return ctx->Eval.Map1Vertex4;
- case GL_MAP2_COLOR_4:
- return ctx->Eval.Map2Color4;
- case GL_MAP2_INDEX:
- return ctx->Eval.Map2Index;
- case GL_MAP2_NORMAL:
- return ctx->Eval.Map2Normal;
- case GL_MAP2_TEXTURE_COORD_1:
- return ctx->Eval.Map2TextureCoord1;
- case GL_MAP2_TEXTURE_COORD_2:
- return ctx->Eval.Map2TextureCoord2;
- case GL_MAP2_TEXTURE_COORD_3:
- return ctx->Eval.Map2TextureCoord3;
- case GL_MAP2_TEXTURE_COORD_4:
- return ctx->Eval.Map2TextureCoord4;
- case GL_MAP2_VERTEX_3:
- return ctx->Eval.Map2Vertex3;
- case GL_MAP2_VERTEX_4:
- return ctx->Eval.Map2Vertex4;
- case GL_NORMALIZE:
- return ctx->Transform.Normalize;
- case GL_POINT_SMOOTH:
- return ctx->Point.SmoothFlag;
- case GL_POLYGON_SMOOTH:
- return ctx->Polygon.SmoothFlag;
- case GL_POLYGON_STIPPLE:
- return ctx->Polygon.StippleFlag;
- case GL_POLYGON_OFFSET_POINT:
- return ctx->Polygon.OffsetPoint;
- case GL_POLYGON_OFFSET_LINE:
- return ctx->Polygon.OffsetLine;
- case GL_POLYGON_OFFSET_FILL:
- /*case GL_POLYGON_OFFSET_EXT:*/
- return ctx->Polygon.OffsetFill;
- case GL_RESCALE_NORMAL_EXT:
- return ctx->Transform.RescaleNormals;
- case GL_SCISSOR_TEST:
- return ctx->Scissor.Enabled;
- case GL_SHARED_TEXTURE_PALETTE_EXT:
- return ctx->Texture.SharedPalette;
- case GL_STENCIL_TEST:
- return ctx->Stencil.Enabled;
- case GL_TEXTURE_1D:
- return is_texture_enabled(ctx, TEXTURE_1D_BIT);
- case GL_TEXTURE_2D:
- return is_texture_enabled(ctx, TEXTURE_2D_BIT);
- case GL_TEXTURE_3D:
- return is_texture_enabled(ctx, TEXTURE_3D_BIT);
- case GL_TEXTURE_GEN_Q:
- {
- const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
- if (texUnit) {
- return (texUnit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE;
- }
- }
- return GL_FALSE;
- case GL_TEXTURE_GEN_R:
- {
- const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
- if (texUnit) {
- return (texUnit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE;
- }
- }
- return GL_FALSE;
- case GL_TEXTURE_GEN_S:
- {
- const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
- if (texUnit) {
- return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE;
- }
- }
- return GL_FALSE;
- case GL_TEXTURE_GEN_T:
- {
- const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
- if (texUnit) {
- return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE;
- }
- }
- return GL_FALSE;
-#if FEATURE_ES1
- case GL_TEXTURE_GEN_STR_OES:
- {
- const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
- if (texUnit) {
- return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS ? GL_TRUE : GL_FALSE;
- }
- }
-#endif
-
- /*
- * CLIENT STATE!!!
- */
- case GL_VERTEX_ARRAY:
- return (ctx->Array.ArrayObj->Vertex.Enabled != 0);
- case GL_NORMAL_ARRAY:
- return (ctx->Array.ArrayObj->Normal.Enabled != 0);
- case GL_COLOR_ARRAY:
- return (ctx->Array.ArrayObj->Color.Enabled != 0);
- case GL_INDEX_ARRAY:
- return (ctx->Array.ArrayObj->Index.Enabled != 0);
- case GL_TEXTURE_COORD_ARRAY:
- return (ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Enabled != 0);
- case GL_EDGE_FLAG_ARRAY:
- return (ctx->Array.ArrayObj->EdgeFlag.Enabled != 0);
- case GL_FOG_COORDINATE_ARRAY_EXT:
- CHECK_EXTENSION(EXT_fog_coord);
- return (ctx->Array.ArrayObj->FogCoord.Enabled != 0);
- case GL_SECONDARY_COLOR_ARRAY_EXT:
- CHECK_EXTENSION(EXT_secondary_color);
- return (ctx->Array.ArrayObj->SecondaryColor.Enabled != 0);
-#if FEATURE_point_size_array
- case GL_POINT_SIZE_ARRAY_OES:
- return (ctx->Array.ArrayObj->PointSize.Enabled != 0);
-#endif
-
- /* GL_ARB_texture_cube_map */
- case GL_TEXTURE_CUBE_MAP_ARB:
- CHECK_EXTENSION(ARB_texture_cube_map);
- return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
-
- /* GL_EXT_secondary_color */
- case GL_COLOR_SUM_EXT:
- CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program);
- return ctx->Fog.ColorSumEnabled;
-
- /* GL_ARB_multisample */
- case GL_MULTISAMPLE_ARB:
- return ctx->Multisample.Enabled;
- case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
- return ctx->Multisample.SampleAlphaToCoverage;
- case GL_SAMPLE_ALPHA_TO_ONE_ARB:
- return ctx->Multisample.SampleAlphaToOne;
- case GL_SAMPLE_COVERAGE_ARB:
- return ctx->Multisample.SampleCoverage;
- case GL_SAMPLE_COVERAGE_INVERT_ARB:
- return ctx->Multisample.SampleCoverageInvert;
-
- /* GL_IBM_rasterpos_clip */
- case GL_RASTER_POSITION_UNCLIPPED_IBM:
- CHECK_EXTENSION(IBM_rasterpos_clip);
- return ctx->Transform.RasterPositionUnclipped;
-
- /* GL_NV_point_sprite */
- case GL_POINT_SPRITE_NV:
- CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
- return ctx->Point.PointSprite;
-
-#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
- case GL_VERTEX_PROGRAM_ARB:
- CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
- return ctx->VertexProgram.Enabled;
- case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
- CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
- return ctx->VertexProgram.PointSizeEnabled;
- case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
- CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
- return ctx->VertexProgram.TwoSideEnabled;
-#endif
-#if FEATURE_NV_vertex_program
- case GL_VERTEX_ATTRIB_ARRAY0_NV:
- case GL_VERTEX_ATTRIB_ARRAY1_NV:
- case GL_VERTEX_ATTRIB_ARRAY2_NV:
- case GL_VERTEX_ATTRIB_ARRAY3_NV:
- case GL_VERTEX_ATTRIB_ARRAY4_NV:
- case GL_VERTEX_ATTRIB_ARRAY5_NV:
- case GL_VERTEX_ATTRIB_ARRAY6_NV:
- case GL_VERTEX_ATTRIB_ARRAY7_NV:
- case GL_VERTEX_ATTRIB_ARRAY8_NV:
- case GL_VERTEX_ATTRIB_ARRAY9_NV:
- case GL_VERTEX_ATTRIB_ARRAY10_NV:
- case GL_VERTEX_ATTRIB_ARRAY11_NV:
- case GL_VERTEX_ATTRIB_ARRAY12_NV:
- case GL_VERTEX_ATTRIB_ARRAY13_NV:
- case GL_VERTEX_ATTRIB_ARRAY14_NV:
- case GL_VERTEX_ATTRIB_ARRAY15_NV:
- CHECK_EXTENSION(NV_vertex_program);
- {
- GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
- ASSERT(n < Elements(ctx->Array.ArrayObj->VertexAttrib));
- return (ctx->Array.ArrayObj->VertexAttrib[n].Enabled != 0);
- }
- case GL_MAP1_VERTEX_ATTRIB0_4_NV:
- case GL_MAP1_VERTEX_ATTRIB1_4_NV:
- case GL_MAP1_VERTEX_ATTRIB2_4_NV:
- case GL_MAP1_VERTEX_ATTRIB3_4_NV:
- case GL_MAP1_VERTEX_ATTRIB4_4_NV:
- case GL_MAP1_VERTEX_ATTRIB5_4_NV:
- case GL_MAP1_VERTEX_ATTRIB6_4_NV:
- case GL_MAP1_VERTEX_ATTRIB7_4_NV:
- case GL_MAP1_VERTEX_ATTRIB8_4_NV:
- case GL_MAP1_VERTEX_ATTRIB9_4_NV:
- case GL_MAP1_VERTEX_ATTRIB10_4_NV:
- case GL_MAP1_VERTEX_ATTRIB11_4_NV:
- case GL_MAP1_VERTEX_ATTRIB12_4_NV:
- case GL_MAP1_VERTEX_ATTRIB13_4_NV:
- case GL_MAP1_VERTEX_ATTRIB14_4_NV:
- case GL_MAP1_VERTEX_ATTRIB15_4_NV:
- CHECK_EXTENSION(NV_vertex_program);
- {
- const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
- return ctx->Eval.Map1Attrib[map];
- }
- case GL_MAP2_VERTEX_ATTRIB0_4_NV:
- case GL_MAP2_VERTEX_ATTRIB1_4_NV:
- case GL_MAP2_VERTEX_ATTRIB2_4_NV:
- case GL_MAP2_VERTEX_ATTRIB3_4_NV:
- case GL_MAP2_VERTEX_ATTRIB4_4_NV:
- case GL_MAP2_VERTEX_ATTRIB5_4_NV:
- case GL_MAP2_VERTEX_ATTRIB6_4_NV:
- case GL_MAP2_VERTEX_ATTRIB7_4_NV:
- case GL_MAP2_VERTEX_ATTRIB8_4_NV:
- case GL_MAP2_VERTEX_ATTRIB9_4_NV:
- case GL_MAP2_VERTEX_ATTRIB10_4_NV:
- case GL_MAP2_VERTEX_ATTRIB11_4_NV:
- case GL_MAP2_VERTEX_ATTRIB12_4_NV:
- case GL_MAP2_VERTEX_ATTRIB13_4_NV:
- case GL_MAP2_VERTEX_ATTRIB14_4_NV:
- case GL_MAP2_VERTEX_ATTRIB15_4_NV:
- CHECK_EXTENSION(NV_vertex_program);
- {
- const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
- return ctx->Eval.Map2Attrib[map];
- }
-#endif /* FEATURE_NV_vertex_program */
-
-#if FEATURE_NV_fragment_program
- case GL_FRAGMENT_PROGRAM_NV:
- CHECK_EXTENSION(NV_fragment_program);
- return ctx->FragmentProgram.Enabled;
-#endif /* FEATURE_NV_fragment_program */
-
- /* GL_NV_texture_rectangle */
- case GL_TEXTURE_RECTANGLE_NV:
- CHECK_EXTENSION(NV_texture_rectangle);
- return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
-
- /* GL_EXT_stencil_two_side */
- case GL_STENCIL_TEST_TWO_SIDE_EXT:
- CHECK_EXTENSION(EXT_stencil_two_side);
- return ctx->Stencil.TestTwoSide;
-
-#if FEATURE_ARB_fragment_program
- case GL_FRAGMENT_PROGRAM_ARB:
- return ctx->FragmentProgram.Enabled;
-#endif /* FEATURE_ARB_fragment_program */
-
- /* GL_EXT_depth_bounds_test */
- case GL_DEPTH_BOUNDS_TEST_EXT:
- CHECK_EXTENSION(EXT_depth_bounds_test);
- return ctx->Depth.BoundsTest;
-
- /* GL_ARB_depth_clamp */
- case GL_DEPTH_CLAMP:
- CHECK_EXTENSION(ARB_depth_clamp);
- return ctx->Transform.DepthClamp;
-
-#if FEATURE_ATI_fragment_shader
- case GL_FRAGMENT_SHADER_ATI:
- CHECK_EXTENSION(ATI_fragment_shader);
- return ctx->ATIFragmentShader.Enabled;
-#endif /* FEATURE_ATI_fragment_shader */
-
- case GL_TEXTURE_CUBE_MAP_SEAMLESS:
- CHECK_EXTENSION(ARB_seamless_cube_map);
- return ctx->Texture.CubeMapSeamless;
-
-#if FEATURE_EXT_transform_feedback
- case GL_RASTERIZER_DISCARD:
- CHECK_EXTENSION(EXT_transform_feedback);
- return ctx->TransformFeedback.RasterDiscard;
-#endif
-
- /* GL_NV_primitive_restart */
- case GL_PRIMITIVE_RESTART_NV:
- if (!ctx->Extensions.NV_primitive_restart) {
- goto invalid_enum_error;
- }
- return ctx->Array.PrimitiveRestart;
-
- /* GL 3.1 primitive restart */
- case GL_PRIMITIVE_RESTART:
- if (ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
- goto invalid_enum_error;
- }
- return ctx->Array.PrimitiveRestart;
-
- /* GL3.0 - GL_framebuffer_sRGB */
- case GL_FRAMEBUFFER_SRGB_EXT:
- CHECK_EXTENSION(EXT_framebuffer_sRGB);
- return ctx->Color.sRGBEnabled;
-
- default:
- goto invalid_enum_error;
- }
-
- return GL_FALSE;
-
-invalid_enum_error:
- _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(0x%x)", (int) cap);
- return GL_FALSE;
-}
+/**
+ * \file enable.c
+ * Enable/disable/query GL capabilities.
+ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.0.3
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "glheader.h"
+#include "context.h"
+#include "enable.h"
+#include "light.h"
+#include "simple_list.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "enums.h"
+#include "api_arrayelt.h"
+#include "texstate.h"
+
+
+
+#define CHECK_EXTENSION(EXTNAME, CAP) \
+ if (!ctx->Extensions.EXTNAME) { \
+ goto invalid_enum_error; \
+ }
+
+
+/**
+ * Helper to enable/disable client-side state.
+ */
+static void
+client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
+{
+ struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
+ GLuint flag;
+ GLboolean *var;
+
+ switch (cap) {
+ case GL_VERTEX_ARRAY:
+ var = &arrayObj->Vertex.Enabled;
+ flag = _NEW_ARRAY_VERTEX;
+ break;
+ case GL_NORMAL_ARRAY:
+ var = &arrayObj->Normal.Enabled;
+ flag = _NEW_ARRAY_NORMAL;
+ break;
+ case GL_COLOR_ARRAY:
+ var = &arrayObj->Color.Enabled;
+ flag = _NEW_ARRAY_COLOR0;
+ break;
+ case GL_INDEX_ARRAY:
+ var = &arrayObj->Index.Enabled;
+ flag = _NEW_ARRAY_INDEX;
+ break;
+ case GL_TEXTURE_COORD_ARRAY:
+ var = &arrayObj->TexCoord[ctx->Array.ActiveTexture].Enabled;
+ flag = _NEW_ARRAY_TEXCOORD(ctx->Array.ActiveTexture);
+ break;
+ case GL_EDGE_FLAG_ARRAY:
+ var = &arrayObj->EdgeFlag.Enabled;
+ flag = _NEW_ARRAY_EDGEFLAG;
+ break;
+ case GL_FOG_COORDINATE_ARRAY_EXT:
+ var = &arrayObj->FogCoord.Enabled;
+ flag = _NEW_ARRAY_FOGCOORD;
+ break;
+ case GL_SECONDARY_COLOR_ARRAY_EXT:
+ var = &arrayObj->SecondaryColor.Enabled;
+ flag = _NEW_ARRAY_COLOR1;
+ break;
+
+#if FEATURE_point_size_array
+ case GL_POINT_SIZE_ARRAY_OES:
+ var = &arrayObj->PointSize.Enabled;
+ flag = _NEW_ARRAY_POINT_SIZE;
+ break;
+#endif
+
+#if FEATURE_NV_vertex_program
+ case GL_VERTEX_ATTRIB_ARRAY0_NV:
+ case GL_VERTEX_ATTRIB_ARRAY1_NV:
+ case GL_VERTEX_ATTRIB_ARRAY2_NV:
+ case GL_VERTEX_ATTRIB_ARRAY3_NV:
+ case GL_VERTEX_ATTRIB_ARRAY4_NV:
+ case GL_VERTEX_ATTRIB_ARRAY5_NV:
+ case GL_VERTEX_ATTRIB_ARRAY6_NV:
+ case GL_VERTEX_ATTRIB_ARRAY7_NV:
+ case GL_VERTEX_ATTRIB_ARRAY8_NV:
+ case GL_VERTEX_ATTRIB_ARRAY9_NV:
+ case GL_VERTEX_ATTRIB_ARRAY10_NV:
+ case GL_VERTEX_ATTRIB_ARRAY11_NV:
+ case GL_VERTEX_ATTRIB_ARRAY12_NV:
+ case GL_VERTEX_ATTRIB_ARRAY13_NV:
+ case GL_VERTEX_ATTRIB_ARRAY14_NV:
+ case GL_VERTEX_ATTRIB_ARRAY15_NV:
+ CHECK_EXTENSION(NV_vertex_program, cap);
+ {
+ GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
+ ASSERT(n < Elements(ctx->Array.ArrayObj->VertexAttrib));
+ var = &arrayObj->VertexAttrib[n].Enabled;
+ flag = _NEW_ARRAY_ATTRIB(n);
+ }
+ break;
+#endif /* FEATURE_NV_vertex_program */
+
+ /* GL_NV_primitive_restart */
+ case GL_PRIMITIVE_RESTART_NV:
+ if (!ctx->Extensions.NV_primitive_restart) {
+ goto invalid_enum_error;
+ }
+ var = &ctx->Array.PrimitiveRestart;
+ flag = 0;
+ break;
+
+ default:
+ goto invalid_enum_error;
+ }
+
+ if (*var == state)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_ARRAY);
+ ctx->Array.NewState |= flag;
+
+ _ae_invalidate_state(ctx, _NEW_ARRAY);
+
+ *var = state;
+
+ if (state)
+ ctx->Array.ArrayObj->_Enabled |= flag;
+ else
+ ctx->Array.ArrayObj->_Enabled &= ~flag;
+
+ if (ctx->Driver.Enable) {
+ ctx->Driver.Enable( ctx, cap, state );
+ }
+
+ return;
+
+invalid_enum_error:
+ _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(0x%x)",
+ state ? "Enable" : "Disable", cap);
+}
+
+
+/**
+ * Enable GL capability.
+ * \param cap state to enable/disable.
+ *
+ * Get's the current context, assures that we're outside glBegin()/glEnd() and
+ * calls client_state().
+ */
+void GLAPIENTRY
+_mesa_EnableClientState( GLenum cap )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+ client_state( ctx, cap, GL_TRUE );
+}
+
+
+/**
+ * Disable GL capability.
+ * \param cap state to enable/disable.
+ *
+ * Get's the current context, assures that we're outside glBegin()/glEnd() and
+ * calls client_state().
+ */
+void GLAPIENTRY
+_mesa_DisableClientState( GLenum cap )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+ client_state( ctx, cap, GL_FALSE );
+}
+
+
+#undef CHECK_EXTENSION
+#define CHECK_EXTENSION(EXTNAME, CAP) \
+ if (!ctx->Extensions.EXTNAME) { \
+ goto invalid_enum_error; \
+ }
+
+#define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
+ if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
+ goto invalid_enum_error; \
+ }
+
+
+
+/**
+ * Return pointer to current texture unit for setting/getting coordinate
+ * state.
+ * Note that we'll set GL_INVALID_OPERATION if the active texture unit is
+ * higher than the number of supported coordinate units. And we'll return NULL.
+ */
+static struct gl_texture_unit *
+get_texcoord_unit(struct gl_context *ctx)
+{
+ if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
+ return NULL;
+ }
+ else {
+ return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ }
+}
+
+
+/**
+ * Helper function to enable or disable a texture target.
+ * \param bit one of the TEXTURE_x_BIT values
+ * \return GL_TRUE if state is changing or GL_FALSE if no change
+ */
+static GLboolean
+enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
+{
+ struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+ const GLbitfield newenabled = state
+ ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
+
+ if (texUnit->Enabled == newenabled)
+ return GL_FALSE;
+
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ texUnit->Enabled = newenabled;
+ return GL_TRUE;
+}
+
+
+/**
+ * Helper function to enable or disable state.
+ *
+ * \param ctx GL context.
+ * \param cap the state to enable/disable
+ * \param state whether to enable or disable the specified capability.
+ *
+ * Updates the current context and flushes the vertices as needed. For
+ * capabilities associated with extensions it verifies that those extensions
+ * are effectivly present before updating. Notifies the driver via
+ * dd_function_table::Enable.
+ */
+void
+_mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
+{
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "%s %s (newstate is %x)\n",
+ state ? "glEnable" : "glDisable",
+ _mesa_lookup_enum_by_nr(cap),
+ ctx->NewState);
+
+ switch (cap) {
+ case GL_ALPHA_TEST:
+ if (ctx->Color.AlphaEnabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->Color.AlphaEnabled = state;
+ break;
+ case GL_AUTO_NORMAL:
+ if (ctx->Eval.AutoNormal == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.AutoNormal = state;
+ break;
+ case GL_BLEND:
+ {
+ GLbitfield newEnabled = state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
+ if (newEnabled != ctx->Color.BlendEnabled) {
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->Color.BlendEnabled = newEnabled;
+ }
+ }
+ break;
+#if FEATURE_userclip
+ case GL_CLIP_PLANE0:
+ case GL_CLIP_PLANE1:
+ case GL_CLIP_PLANE2:
+ case GL_CLIP_PLANE3:
+ case GL_CLIP_PLANE4:
+ case GL_CLIP_PLANE5:
+ {
+ const GLuint p = cap - GL_CLIP_PLANE0;
+
+ if ((ctx->Transform.ClipPlanesEnabled & (1 << p)) == ((GLuint) state << p))
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+
+ if (state) {
+ ctx->Transform.ClipPlanesEnabled |= (1 << p);
+
+ if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top))
+ _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
+
+ /* This derived state also calculated in clip.c and
+ * from _mesa_update_state() on changes to EyeUserPlane
+ * and ctx->ProjectionMatrix respectively.
+ */
+ _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
+ ctx->Transform.EyeUserPlane[p],
+ ctx->ProjectionMatrixStack.Top->inv );
+ }
+ else {
+ ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
+ }
+ }
+ break;
+#endif
+ case GL_COLOR_MATERIAL:
+ if (ctx->Light.ColorMaterialEnabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ FLUSH_CURRENT(ctx, 0);
+ ctx->Light.ColorMaterialEnabled = state;
+ if (state) {
+ _mesa_update_color_material( ctx,
+ ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
+ }
+ break;
+ case GL_CULL_FACE:
+ if (ctx->Polygon.CullFlag == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.CullFlag = state;
+ break;
+ case GL_DEPTH_TEST:
+ if (ctx->Depth.Test == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_DEPTH);
+ ctx->Depth.Test = state;
+ break;
+ case GL_DITHER:
+ if (ctx->Color.DitherFlag == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->Color.DitherFlag = state;
+ break;
+ case GL_FOG:
+ if (ctx->Fog.Enabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_FOG);
+ ctx->Fog.Enabled = state;
+ break;
+ case GL_LIGHT0:
+ case GL_LIGHT1:
+ case GL_LIGHT2:
+ case GL_LIGHT3:
+ case GL_LIGHT4:
+ case GL_LIGHT5:
+ case GL_LIGHT6:
+ case GL_LIGHT7:
+ if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
+ if (state) {
+ insert_at_tail(&ctx->Light.EnabledList,
+ &ctx->Light.Light[cap-GL_LIGHT0]);
+ }
+ else {
+ remove_from_list(&ctx->Light.Light[cap-GL_LIGHT0]);
+ }
+ break;
+ case GL_LIGHTING:
+ if (ctx->Light.Enabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ ctx->Light.Enabled = state;
+ if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
+ ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
+ else
+ ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
+ break;
+ case GL_LINE_SMOOTH:
+ if (ctx->Line.SmoothFlag == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LINE);
+ ctx->Line.SmoothFlag = state;
+ ctx->_TriangleCaps ^= DD_LINE_SMOOTH;
+ break;
+ case GL_LINE_STIPPLE:
+ if (ctx->Line.StippleFlag == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_LINE);
+ ctx->Line.StippleFlag = state;
+ ctx->_TriangleCaps ^= DD_LINE_STIPPLE;
+ break;
+ case GL_INDEX_LOGIC_OP:
+ if (ctx->Color.IndexLogicOpEnabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->Color.IndexLogicOpEnabled = state;
+ break;
+ case GL_COLOR_LOGIC_OP:
+ if (ctx->Color.ColorLogicOpEnabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ ctx->Color.ColorLogicOpEnabled = state;
+ break;
+ case GL_MAP1_COLOR_4:
+ if (ctx->Eval.Map1Color4 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map1Color4 = state;
+ break;
+ case GL_MAP1_INDEX:
+ if (ctx->Eval.Map1Index == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map1Index = state;
+ break;
+ case GL_MAP1_NORMAL:
+ if (ctx->Eval.Map1Normal == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map1Normal = state;
+ break;
+ case GL_MAP1_TEXTURE_COORD_1:
+ if (ctx->Eval.Map1TextureCoord1 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map1TextureCoord1 = state;
+ break;
+ case GL_MAP1_TEXTURE_COORD_2:
+ if (ctx->Eval.Map1TextureCoord2 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map1TextureCoord2 = state;
+ break;
+ case GL_MAP1_TEXTURE_COORD_3:
+ if (ctx->Eval.Map1TextureCoord3 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map1TextureCoord3 = state;
+ break;
+ case GL_MAP1_TEXTURE_COORD_4:
+ if (ctx->Eval.Map1TextureCoord4 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map1TextureCoord4 = state;
+ break;
+ case GL_MAP1_VERTEX_3:
+ if (ctx->Eval.Map1Vertex3 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map1Vertex3 = state;
+ break;
+ case GL_MAP1_VERTEX_4:
+ if (ctx->Eval.Map1Vertex4 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map1Vertex4 = state;
+ break;
+ case GL_MAP2_COLOR_4:
+ if (ctx->Eval.Map2Color4 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map2Color4 = state;
+ break;
+ case GL_MAP2_INDEX:
+ if (ctx->Eval.Map2Index == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map2Index = state;
+ break;
+ case GL_MAP2_NORMAL:
+ if (ctx->Eval.Map2Normal == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map2Normal = state;
+ break;
+ case GL_MAP2_TEXTURE_COORD_1:
+ if (ctx->Eval.Map2TextureCoord1 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map2TextureCoord1 = state;
+ break;
+ case GL_MAP2_TEXTURE_COORD_2:
+ if (ctx->Eval.Map2TextureCoord2 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map2TextureCoord2 = state;
+ break;
+ case GL_MAP2_TEXTURE_COORD_3:
+ if (ctx->Eval.Map2TextureCoord3 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map2TextureCoord3 = state;
+ break;
+ case GL_MAP2_TEXTURE_COORD_4:
+ if (ctx->Eval.Map2TextureCoord4 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map2TextureCoord4 = state;
+ break;
+ case GL_MAP2_VERTEX_3:
+ if (ctx->Eval.Map2Vertex3 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map2Vertex3 = state;
+ break;
+ case GL_MAP2_VERTEX_4:
+ if (ctx->Eval.Map2Vertex4 == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map2Vertex4 = state;
+ break;
+ case GL_NORMALIZE:
+ if (ctx->Transform.Normalize == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+ ctx->Transform.Normalize = state;
+ break;
+ case GL_POINT_SMOOTH:
+ if (ctx->Point.SmoothFlag == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POINT);
+ ctx->Point.SmoothFlag = state;
+ ctx->_TriangleCaps ^= DD_POINT_SMOOTH;
+ break;
+ case GL_POLYGON_SMOOTH:
+ if (ctx->Polygon.SmoothFlag == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.SmoothFlag = state;
+ ctx->_TriangleCaps ^= DD_TRI_SMOOTH;
+ break;
+ case GL_POLYGON_STIPPLE:
+ if (ctx->Polygon.StippleFlag == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.StippleFlag = state;
+ ctx->_TriangleCaps ^= DD_TRI_STIPPLE;
+ break;
+ case GL_POLYGON_OFFSET_POINT:
+ if (ctx->Polygon.OffsetPoint == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.OffsetPoint = state;
+ break;
+ case GL_POLYGON_OFFSET_LINE:
+ if (ctx->Polygon.OffsetLine == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.OffsetLine = state;
+ break;
+ case GL_POLYGON_OFFSET_FILL:
+ /*case GL_POLYGON_OFFSET_EXT:*/
+ if (ctx->Polygon.OffsetFill == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.OffsetFill = state;
+ break;
+ case GL_RESCALE_NORMAL_EXT:
+ if (ctx->Transform.RescaleNormals == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+ ctx->Transform.RescaleNormals = state;
+ break;
+ case GL_SCISSOR_TEST:
+ if (ctx->Scissor.Enabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_SCISSOR);
+ ctx->Scissor.Enabled = state;
+ break;
+ case GL_SHARED_TEXTURE_PALETTE_EXT:
+ if (ctx->Texture.SharedPalette == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ ctx->Texture.SharedPalette = state;
+ break;
+ case GL_STENCIL_TEST:
+ if (ctx->Stencil.Enabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.Enabled = state;
+ break;
+ case GL_TEXTURE_1D:
+ if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
+ return;
+ }
+ break;
+ case GL_TEXTURE_2D:
+ if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
+ return;
+ }
+ break;
+ case GL_TEXTURE_3D:
+ if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
+ return;
+ }
+ break;
+ case GL_TEXTURE_GEN_Q:
+ {
+ struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+ if (texUnit) {
+ GLuint newenabled = texUnit->TexGenEnabled & ~Q_BIT;
+ if (state)
+ newenabled |= Q_BIT;
+ if (texUnit->TexGenEnabled == newenabled)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ texUnit->TexGenEnabled = newenabled;
+ }
+ }
+ break;
+ case GL_TEXTURE_GEN_R:
+ {
+ struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+ if (texUnit) {
+ GLuint newenabled = texUnit->TexGenEnabled & ~R_BIT;
+ if (state)
+ newenabled |= R_BIT;
+ if (texUnit->TexGenEnabled == newenabled)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ texUnit->TexGenEnabled = newenabled;
+ }
+ }
+ break;
+ case GL_TEXTURE_GEN_S:
+ {
+ struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+ if (texUnit) {
+ GLuint newenabled = texUnit->TexGenEnabled & ~S_BIT;
+ if (state)
+ newenabled |= S_BIT;
+ if (texUnit->TexGenEnabled == newenabled)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ texUnit->TexGenEnabled = newenabled;
+ }
+ }
+ break;
+ case GL_TEXTURE_GEN_T:
+ {
+ struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+ if (texUnit) {
+ GLuint newenabled = texUnit->TexGenEnabled & ~T_BIT;
+ if (state)
+ newenabled |= T_BIT;
+ if (texUnit->TexGenEnabled == newenabled)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ texUnit->TexGenEnabled = newenabled;
+ }
+ }
+ break;
+
+#if FEATURE_ES1
+ case GL_TEXTURE_GEN_STR_OES:
+ /* disable S, T, and R at the same time */
+ {
+ struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+ if (texUnit) {
+ GLuint newenabled =
+ texUnit->TexGenEnabled & ~STR_BITS;
+ if (state)
+ newenabled |= STR_BITS;
+ if (texUnit->TexGenEnabled == newenabled)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ texUnit->TexGenEnabled = newenabled;
+ }
+ }
+ break;
+#endif
+
+ /*
+ * CLIENT STATE!!!
+ */
+ case GL_VERTEX_ARRAY:
+ case GL_NORMAL_ARRAY:
+ case GL_COLOR_ARRAY:
+ case GL_INDEX_ARRAY:
+ case GL_TEXTURE_COORD_ARRAY:
+ case GL_EDGE_FLAG_ARRAY:
+ case GL_FOG_COORDINATE_ARRAY_EXT:
+ case GL_SECONDARY_COLOR_ARRAY_EXT:
+ case GL_POINT_SIZE_ARRAY_OES:
+ client_state( ctx, cap, state );
+ return;
+
+ /* GL_ARB_texture_cube_map */
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ CHECK_EXTENSION(ARB_texture_cube_map, cap);
+ if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
+ return;
+ }
+ break;
+
+ /* GL_EXT_secondary_color */
+ case GL_COLOR_SUM_EXT:
+ CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program, cap);
+ if (ctx->Fog.ColorSumEnabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_FOG);
+ ctx->Fog.ColorSumEnabled = state;
+ break;
+
+ /* GL_ARB_multisample */
+ case GL_MULTISAMPLE_ARB:
+ if (ctx->Multisample.Enabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+ ctx->Multisample.Enabled = state;
+ break;
+ case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
+ if (ctx->Multisample.SampleAlphaToCoverage == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+ ctx->Multisample.SampleAlphaToCoverage = state;
+ break;
+ case GL_SAMPLE_ALPHA_TO_ONE_ARB:
+ if (ctx->Multisample.SampleAlphaToOne == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+ ctx->Multisample.SampleAlphaToOne = state;
+ break;
+ case GL_SAMPLE_COVERAGE_ARB:
+ if (ctx->Multisample.SampleCoverage == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+ ctx->Multisample.SampleCoverage = state;
+ break;
+ case GL_SAMPLE_COVERAGE_INVERT_ARB:
+ if (ctx->Multisample.SampleCoverageInvert == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+ ctx->Multisample.SampleCoverageInvert = state;
+ break;
+
+ /* GL_IBM_rasterpos_clip */
+ case GL_RASTER_POSITION_UNCLIPPED_IBM:
+ CHECK_EXTENSION(IBM_rasterpos_clip, cap);
+ if (ctx->Transform.RasterPositionUnclipped == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+ ctx->Transform.RasterPositionUnclipped = state;
+ break;
+
+ /* GL_NV_point_sprite */
+ case GL_POINT_SPRITE_NV:
+ CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
+ if (ctx->Point.PointSprite == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POINT);
+ ctx->Point.PointSprite = state;
+ break;
+
+#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
+ case GL_VERTEX_PROGRAM_ARB:
+ CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
+ if (ctx->VertexProgram.Enabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+ ctx->VertexProgram.Enabled = state;
+ break;
+ case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
+ CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
+ if (ctx->VertexProgram.PointSizeEnabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+ ctx->VertexProgram.PointSizeEnabled = state;
+ break;
+ case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
+ CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
+ if (ctx->VertexProgram.TwoSideEnabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+ ctx->VertexProgram.TwoSideEnabled = state;
+ break;
+#endif
+#if FEATURE_NV_vertex_program
+ case GL_MAP1_VERTEX_ATTRIB0_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB1_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB2_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB3_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB4_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB5_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB6_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB7_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB8_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB9_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB10_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB11_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB12_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB13_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB14_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB15_4_NV:
+ CHECK_EXTENSION(NV_vertex_program, cap);
+ {
+ const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map1Attrib[map] = state;
+ }
+ break;
+ case GL_MAP2_VERTEX_ATTRIB0_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB1_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB2_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB3_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB4_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB5_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB6_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB7_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB8_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB9_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB10_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB11_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB12_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB13_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB14_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB15_4_NV:
+ CHECK_EXTENSION(NV_vertex_program, cap);
+ {
+ const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
+ FLUSH_VERTICES(ctx, _NEW_EVAL);
+ ctx->Eval.Map2Attrib[map] = state;
+ }
+ break;
+#endif /* FEATURE_NV_vertex_program */
+
+#if FEATURE_NV_fragment_program
+ case GL_FRAGMENT_PROGRAM_NV:
+ CHECK_EXTENSION(NV_fragment_program, cap);
+ if (ctx->FragmentProgram.Enabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+ ctx->FragmentProgram.Enabled = state;
+ break;
+#endif /* FEATURE_NV_fragment_program */
+
+ /* GL_NV_texture_rectangle */
+ case GL_TEXTURE_RECTANGLE_NV:
+ CHECK_EXTENSION(NV_texture_rectangle, cap);
+ if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
+ return;
+ }
+ break;
+
+ /* GL_EXT_stencil_two_side */
+ case GL_STENCIL_TEST_TWO_SIDE_EXT:
+ CHECK_EXTENSION(EXT_stencil_two_side, cap);
+ if (ctx->Stencil.TestTwoSide == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.TestTwoSide = state;
+ if (state) {
+ ctx->Stencil._BackFace = 2;
+ ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
+ } else {
+ ctx->Stencil._BackFace = 1;
+ ctx->_TriangleCaps &= ~DD_TRI_TWOSTENCIL;
+ }
+ break;
+
+#if FEATURE_ARB_fragment_program
+ case GL_FRAGMENT_PROGRAM_ARB:
+ CHECK_EXTENSION(ARB_fragment_program, cap);
+ if (ctx->FragmentProgram.Enabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+ ctx->FragmentProgram.Enabled = state;
+ break;
+#endif /* FEATURE_ARB_fragment_program */
+
+ /* GL_EXT_depth_bounds_test */
+ case GL_DEPTH_BOUNDS_TEST_EXT:
+ CHECK_EXTENSION(EXT_depth_bounds_test, cap);
+ if (ctx->Depth.BoundsTest == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_DEPTH);
+ ctx->Depth.BoundsTest = state;
+ break;
+
+ case GL_DEPTH_CLAMP:
+ if (ctx->Transform.DepthClamp == state)
+ return;
+ CHECK_EXTENSION(ARB_depth_clamp, cap);
+ FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+ ctx->Transform.DepthClamp = state;
+ break;
+
+#if FEATURE_ATI_fragment_shader
+ case GL_FRAGMENT_SHADER_ATI:
+ CHECK_EXTENSION(ATI_fragment_shader, cap);
+ if (ctx->ATIFragmentShader.Enabled == state)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+ ctx->ATIFragmentShader.Enabled = state;
+ break;
+#endif
+
+ /* GL_MESA_texture_array */
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ CHECK_EXTENSION(MESA_texture_array, cap);
+ if (!enable_texture(ctx, state, TEXTURE_1D_ARRAY_BIT)) {
+ return;
+ }
+ break;
+
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ CHECK_EXTENSION(MESA_texture_array, cap);
+ if (!enable_texture(ctx, state, TEXTURE_2D_ARRAY_BIT)) {
+ return;
+ }
+ break;
+
+ case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+ CHECK_EXTENSION(ARB_seamless_cube_map, cap);
+ ctx->Texture.CubeMapSeamless = state;
+ break;
+
+#if FEATURE_EXT_transform_feedback
+ case GL_RASTERIZER_DISCARD:
+ CHECK_EXTENSION(EXT_transform_feedback, cap);
+ if (ctx->TransformFeedback.RasterDiscard != state) {
+ ctx->TransformFeedback.RasterDiscard = state;
+ FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+ }
+ break;
+#endif
+
+ /* GL 3.1 primitive restart. Note: this enum is different from
+ * GL_PRIMITIVE_RESTART_NV (which is client state).
+ */
+ case GL_PRIMITIVE_RESTART:
+ if (ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
+ goto invalid_enum_error;
+ }
+ if (ctx->Array.PrimitiveRestart != state) {
+ FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+ ctx->Array.PrimitiveRestart = state;
+ }
+ break;
+
+ /* GL3.0 - GL_framebuffer_sRGB */
+ case GL_FRAMEBUFFER_SRGB_EXT:
+ CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+ ctx->Color.sRGBEnabled = state;
+ break;
+
+ default:
+ goto invalid_enum_error;
+ }
+
+ if (ctx->Driver.Enable) {
+ ctx->Driver.Enable( ctx, cap, state );
+ }
+
+ return;
+
+invalid_enum_error:
+ _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)",
+ state ? "Enable" : "Disable", cap);
+}
+
+
+/**
+ * Enable GL capability. Called by glEnable()
+ * \param cap state to enable.
+ */
+void GLAPIENTRY
+_mesa_Enable( GLenum cap )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ _mesa_set_enable( ctx, cap, GL_TRUE );
+}
+
+
+/**
+ * Disable GL capability. Called by glDisable()
+ * \param cap state to disable.
+ */
+void GLAPIENTRY
+_mesa_Disable( GLenum cap )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ _mesa_set_enable( ctx, cap, GL_FALSE );
+}
+
+
+
+/**
+ * Enable/disable an indexed state var.
+ */
+void
+_mesa_set_enablei(struct gl_context *ctx, GLenum cap, GLuint index, GLboolean state)
+{
+ ASSERT(state == 0 || state == 1);
+ switch (cap) {
+ case GL_BLEND:
+ if (!ctx->Extensions.EXT_draw_buffers2) {
+ goto invalid_enum_error;
+ }
+ if (index >= ctx->Const.MaxDrawBuffers) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
+ state ? "glEnableIndexed" : "glDisableIndexed", index);
+ return;
+ }
+ if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
+ FLUSH_VERTICES(ctx, _NEW_COLOR);
+ if (state)
+ ctx->Color.BlendEnabled |= (1 << index);
+ else
+ ctx->Color.BlendEnabled &= ~(1 << index);
+ }
+ break;
+ default:
+ goto invalid_enum_error;
+ }
+ return;
+
+invalid_enum_error:
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
+ state ? "glEnablei" : "glDisablei",
+ _mesa_lookup_enum_by_nr(cap));
+}
+
+
+void GLAPIENTRY
+_mesa_DisableIndexed( GLenum cap, GLuint index )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+ _mesa_set_enablei(ctx, cap, index, GL_FALSE);
+}
+
+
+void GLAPIENTRY
+_mesa_EnableIndexed( GLenum cap, GLuint index )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+ _mesa_set_enablei(ctx, cap, index, GL_TRUE);
+}
+
+
+GLboolean GLAPIENTRY
+_mesa_IsEnabledIndexed( GLenum cap, GLuint index )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ switch (cap) {
+ case GL_BLEND:
+ if (index >= ctx->Const.MaxDrawBuffers) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
+ index);
+ return GL_FALSE;
+ }
+ return (ctx->Color.BlendEnabled >> index) & 1;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
+ _mesa_lookup_enum_by_nr(cap));
+ return GL_FALSE;
+ }
+}
+
+
+
+
+#undef CHECK_EXTENSION
+#define CHECK_EXTENSION(EXTNAME) \
+ if (!ctx->Extensions.EXTNAME) { \
+ goto invalid_enum_error; \
+ }
+
+#undef CHECK_EXTENSION2
+#define CHECK_EXTENSION2(EXT1, EXT2) \
+ if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
+ goto invalid_enum_error; \
+ }
+
+
+/**
+ * Helper function to determine whether a texture target is enabled.
+ */
+static GLboolean
+is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
+{
+ const struct gl_texture_unit *const texUnit =
+ &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
+}
+
+
+/**
+ * Return simple enable/disable state.
+ *
+ * \param cap state variable to query.
+ *
+ * Returns the state of the specified capability from the current GL context.
+ * For the capabilities associated with extensions verifies that those
+ * extensions are effectively present before reporting.
+ */
+GLboolean GLAPIENTRY
+_mesa_IsEnabled( GLenum cap )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ switch (cap) {
+ case GL_ALPHA_TEST:
+ return ctx->Color.AlphaEnabled;
+ case GL_AUTO_NORMAL:
+ return ctx->Eval.AutoNormal;
+ case GL_BLEND:
+ return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
+ case GL_CLIP_PLANE0:
+ case GL_CLIP_PLANE1:
+ case GL_CLIP_PLANE2:
+ case GL_CLIP_PLANE3:
+ case GL_CLIP_PLANE4:
+ case GL_CLIP_PLANE5:
+ return (ctx->Transform.ClipPlanesEnabled >> (cap - GL_CLIP_PLANE0)) & 1;
+ case GL_COLOR_MATERIAL:
+ return ctx->Light.ColorMaterialEnabled;
+ case GL_CULL_FACE:
+ return ctx->Polygon.CullFlag;
+ case GL_DEPTH_TEST:
+ return ctx->Depth.Test;
+ case GL_DITHER:
+ return ctx->Color.DitherFlag;
+ case GL_FOG:
+ return ctx->Fog.Enabled;
+ case GL_LIGHTING:
+ return ctx->Light.Enabled;
+ case GL_LIGHT0:
+ case GL_LIGHT1:
+ case GL_LIGHT2:
+ case GL_LIGHT3:
+ case GL_LIGHT4:
+ case GL_LIGHT5:
+ case GL_LIGHT6:
+ case GL_LIGHT7:
+ return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
+ case GL_LINE_SMOOTH:
+ return ctx->Line.SmoothFlag;
+ case GL_LINE_STIPPLE:
+ return ctx->Line.StippleFlag;
+ case GL_INDEX_LOGIC_OP:
+ return ctx->Color.IndexLogicOpEnabled;
+ case GL_COLOR_LOGIC_OP:
+ return ctx->Color.ColorLogicOpEnabled;
+ case GL_MAP1_COLOR_4:
+ return ctx->Eval.Map1Color4;
+ case GL_MAP1_INDEX:
+ return ctx->Eval.Map1Index;
+ case GL_MAP1_NORMAL:
+ return ctx->Eval.Map1Normal;
+ case GL_MAP1_TEXTURE_COORD_1:
+ return ctx->Eval.Map1TextureCoord1;
+ case GL_MAP1_TEXTURE_COORD_2:
+ return ctx->Eval.Map1TextureCoord2;
+ case GL_MAP1_TEXTURE_COORD_3:
+ return ctx->Eval.Map1TextureCoord3;
+ case GL_MAP1_TEXTURE_COORD_4:
+ return ctx->Eval.Map1TextureCoord4;
+ case GL_MAP1_VERTEX_3:
+ return ctx->Eval.Map1Vertex3;
+ case GL_MAP1_VERTEX_4:
+ return ctx->Eval.Map1Vertex4;
+ case GL_MAP2_COLOR_4:
+ return ctx->Eval.Map2Color4;
+ case GL_MAP2_INDEX:
+ return ctx->Eval.Map2Index;
+ case GL_MAP2_NORMAL:
+ return ctx->Eval.Map2Normal;
+ case GL_MAP2_TEXTURE_COORD_1:
+ return ctx->Eval.Map2TextureCoord1;
+ case GL_MAP2_TEXTURE_COORD_2:
+ return ctx->Eval.Map2TextureCoord2;
+ case GL_MAP2_TEXTURE_COORD_3:
+ return ctx->Eval.Map2TextureCoord3;
+ case GL_MAP2_TEXTURE_COORD_4:
+ return ctx->Eval.Map2TextureCoord4;
+ case GL_MAP2_VERTEX_3:
+ return ctx->Eval.Map2Vertex3;
+ case GL_MAP2_VERTEX_4:
+ return ctx->Eval.Map2Vertex4;
+ case GL_NORMALIZE:
+ return ctx->Transform.Normalize;
+ case GL_POINT_SMOOTH:
+ return ctx->Point.SmoothFlag;
+ case GL_POLYGON_SMOOTH:
+ return ctx->Polygon.SmoothFlag;
+ case GL_POLYGON_STIPPLE:
+ return ctx->Polygon.StippleFlag;
+ case GL_POLYGON_OFFSET_POINT:
+ return ctx->Polygon.OffsetPoint;
+ case GL_POLYGON_OFFSET_LINE:
+ return ctx->Polygon.OffsetLine;
+ case GL_POLYGON_OFFSET_FILL:
+ /*case GL_POLYGON_OFFSET_EXT:*/
+ return ctx->Polygon.OffsetFill;
+ case GL_RESCALE_NORMAL_EXT:
+ return ctx->Transform.RescaleNormals;
+ case GL_SCISSOR_TEST:
+ return ctx->Scissor.Enabled;
+ case GL_SHARED_TEXTURE_PALETTE_EXT:
+ return ctx->Texture.SharedPalette;
+ case GL_STENCIL_TEST:
+ return ctx->Stencil.Enabled;
+ case GL_TEXTURE_1D:
+ return is_texture_enabled(ctx, TEXTURE_1D_BIT);
+ case GL_TEXTURE_2D:
+ return is_texture_enabled(ctx, TEXTURE_2D_BIT);
+ case GL_TEXTURE_3D:
+ return is_texture_enabled(ctx, TEXTURE_3D_BIT);
+ case GL_TEXTURE_GEN_Q:
+ {
+ const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+ if (texUnit) {
+ return (texUnit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE;
+ }
+ }
+ return GL_FALSE;
+ case GL_TEXTURE_GEN_R:
+ {
+ const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+ if (texUnit) {
+ return (texUnit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE;
+ }
+ }
+ return GL_FALSE;
+ case GL_TEXTURE_GEN_S:
+ {
+ const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+ if (texUnit) {
+ return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE;
+ }
+ }
+ return GL_FALSE;
+ case GL_TEXTURE_GEN_T:
+ {
+ const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+ if (texUnit) {
+ return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE;
+ }
+ }
+ return GL_FALSE;
+#if FEATURE_ES1
+ case GL_TEXTURE_GEN_STR_OES:
+ {
+ const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+ if (texUnit) {
+ return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS ? GL_TRUE : GL_FALSE;
+ }
+ }
+#endif
+
+ /*
+ * CLIENT STATE!!!
+ */
+ case GL_VERTEX_ARRAY:
+ return (ctx->Array.ArrayObj->Vertex.Enabled != 0);
+ case GL_NORMAL_ARRAY:
+ return (ctx->Array.ArrayObj->Normal.Enabled != 0);
+ case GL_COLOR_ARRAY:
+ return (ctx->Array.ArrayObj->Color.Enabled != 0);
+ case GL_INDEX_ARRAY:
+ return (ctx->Array.ArrayObj->Index.Enabled != 0);
+ case GL_TEXTURE_COORD_ARRAY:
+ return (ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Enabled != 0);
+ case GL_EDGE_FLAG_ARRAY:
+ return (ctx->Array.ArrayObj->EdgeFlag.Enabled != 0);
+ case GL_FOG_COORDINATE_ARRAY_EXT:
+ CHECK_EXTENSION(EXT_fog_coord);
+ return (ctx->Array.ArrayObj->FogCoord.Enabled != 0);
+ case GL_SECONDARY_COLOR_ARRAY_EXT:
+ CHECK_EXTENSION(EXT_secondary_color);
+ return (ctx->Array.ArrayObj->SecondaryColor.Enabled != 0);
+#if FEATURE_point_size_array
+ case GL_POINT_SIZE_ARRAY_OES:
+ return (ctx->Array.ArrayObj->PointSize.Enabled != 0);
+#endif
+
+ /* GL_ARB_texture_cube_map */
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ CHECK_EXTENSION(ARB_texture_cube_map);
+ return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
+
+ /* GL_EXT_secondary_color */
+ case GL_COLOR_SUM_EXT:
+ CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program);
+ return ctx->Fog.ColorSumEnabled;
+
+ /* GL_ARB_multisample */
+ case GL_MULTISAMPLE_ARB:
+ return ctx->Multisample.Enabled;
+ case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
+ return ctx->Multisample.SampleAlphaToCoverage;
+ case GL_SAMPLE_ALPHA_TO_ONE_ARB:
+ return ctx->Multisample.SampleAlphaToOne;
+ case GL_SAMPLE_COVERAGE_ARB:
+ return ctx->Multisample.SampleCoverage;
+ case GL_SAMPLE_COVERAGE_INVERT_ARB:
+ return ctx->Multisample.SampleCoverageInvert;
+
+ /* GL_IBM_rasterpos_clip */
+ case GL_RASTER_POSITION_UNCLIPPED_IBM:
+ CHECK_EXTENSION(IBM_rasterpos_clip);
+ return ctx->Transform.RasterPositionUnclipped;
+
+ /* GL_NV_point_sprite */
+ case GL_POINT_SPRITE_NV:
+ CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
+ return ctx->Point.PointSprite;
+
+#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
+ case GL_VERTEX_PROGRAM_ARB:
+ CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
+ return ctx->VertexProgram.Enabled;
+ case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
+ CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
+ return ctx->VertexProgram.PointSizeEnabled;
+ case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
+ CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
+ return ctx->VertexProgram.TwoSideEnabled;
+#endif
+#if FEATURE_NV_vertex_program
+ case GL_VERTEX_ATTRIB_ARRAY0_NV:
+ case GL_VERTEX_ATTRIB_ARRAY1_NV:
+ case GL_VERTEX_ATTRIB_ARRAY2_NV:
+ case GL_VERTEX_ATTRIB_ARRAY3_NV:
+ case GL_VERTEX_ATTRIB_ARRAY4_NV:
+ case GL_VERTEX_ATTRIB_ARRAY5_NV:
+ case GL_VERTEX_ATTRIB_ARRAY6_NV:
+ case GL_VERTEX_ATTRIB_ARRAY7_NV:
+ case GL_VERTEX_ATTRIB_ARRAY8_NV:
+ case GL_VERTEX_ATTRIB_ARRAY9_NV:
+ case GL_VERTEX_ATTRIB_ARRAY10_NV:
+ case GL_VERTEX_ATTRIB_ARRAY11_NV:
+ case GL_VERTEX_ATTRIB_ARRAY12_NV:
+ case GL_VERTEX_ATTRIB_ARRAY13_NV:
+ case GL_VERTEX_ATTRIB_ARRAY14_NV:
+ case GL_VERTEX_ATTRIB_ARRAY15_NV:
+ CHECK_EXTENSION(NV_vertex_program);
+ {
+ GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
+ ASSERT(n < Elements(ctx->Array.ArrayObj->VertexAttrib));
+ return (ctx->Array.ArrayObj->VertexAttrib[n].Enabled != 0);
+ }
+ case GL_MAP1_VERTEX_ATTRIB0_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB1_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB2_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB3_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB4_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB5_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB6_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB7_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB8_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB9_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB10_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB11_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB12_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB13_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB14_4_NV:
+ case GL_MAP1_VERTEX_ATTRIB15_4_NV:
+ CHECK_EXTENSION(NV_vertex_program);
+ {
+ const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
+ return ctx->Eval.Map1Attrib[map];
+ }
+ case GL_MAP2_VERTEX_ATTRIB0_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB1_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB2_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB3_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB4_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB5_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB6_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB7_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB8_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB9_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB10_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB11_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB12_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB13_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB14_4_NV:
+ case GL_MAP2_VERTEX_ATTRIB15_4_NV:
+ CHECK_EXTENSION(NV_vertex_program);
+ {
+ const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
+ return ctx->Eval.Map2Attrib[map];
+ }
+#endif /* FEATURE_NV_vertex_program */
+
+#if FEATURE_NV_fragment_program
+ case GL_FRAGMENT_PROGRAM_NV:
+ CHECK_EXTENSION(NV_fragment_program);
+ return ctx->FragmentProgram.Enabled;
+#endif /* FEATURE_NV_fragment_program */
+
+ /* GL_NV_texture_rectangle */
+ case GL_TEXTURE_RECTANGLE_NV:
+ CHECK_EXTENSION(NV_texture_rectangle);
+ return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
+
+ /* GL_EXT_stencil_two_side */
+ case GL_STENCIL_TEST_TWO_SIDE_EXT:
+ CHECK_EXTENSION(EXT_stencil_two_side);
+ return ctx->Stencil.TestTwoSide;
+
+#if FEATURE_ARB_fragment_program
+ case GL_FRAGMENT_PROGRAM_ARB:
+ return ctx->FragmentProgram.Enabled;
+#endif /* FEATURE_ARB_fragment_program */
+
+ /* GL_EXT_depth_bounds_test */
+ case GL_DEPTH_BOUNDS_TEST_EXT:
+ CHECK_EXTENSION(EXT_depth_bounds_test);
+ return ctx->Depth.BoundsTest;
+
+ /* GL_ARB_depth_clamp */
+ case GL_DEPTH_CLAMP:
+ CHECK_EXTENSION(ARB_depth_clamp);
+ return ctx->Transform.DepthClamp;
+
+#if FEATURE_ATI_fragment_shader
+ case GL_FRAGMENT_SHADER_ATI:
+ CHECK_EXTENSION(ATI_fragment_shader);
+ return ctx->ATIFragmentShader.Enabled;
+#endif /* FEATURE_ATI_fragment_shader */
+
+ case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+ CHECK_EXTENSION(ARB_seamless_cube_map);
+ return ctx->Texture.CubeMapSeamless;
+
+#if FEATURE_EXT_transform_feedback
+ case GL_RASTERIZER_DISCARD:
+ CHECK_EXTENSION(EXT_transform_feedback);
+ return ctx->TransformFeedback.RasterDiscard;
+#endif
+
+ /* GL_NV_primitive_restart */
+ case GL_PRIMITIVE_RESTART_NV:
+ if (!ctx->Extensions.NV_primitive_restart) {
+ goto invalid_enum_error;
+ }
+ return ctx->Array.PrimitiveRestart;
+
+ /* GL 3.1 primitive restart */
+ case GL_PRIMITIVE_RESTART:
+ if (ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
+ goto invalid_enum_error;
+ }
+ return ctx->Array.PrimitiveRestart;
+
+ /* GL3.0 - GL_framebuffer_sRGB */
+ case GL_FRAMEBUFFER_SRGB_EXT:
+ CHECK_EXTENSION(EXT_framebuffer_sRGB);
+ return ctx->Color.sRGBEnabled;
+
+ default:
+ goto invalid_enum_error;
+ }
+
+ return GL_FALSE;
+
+invalid_enum_error:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(0x%x)", (int) cap);
+ return GL_FALSE;
+}
diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c
index 3840cdc5d..a4aa9847a 100644
--- a/mesalib/src/mesa/main/extensions.c
+++ b/mesalib/src/mesa/main/extensions.c
@@ -1,913 +1,913 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.6
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file
- * \brief Extension handling
- */
-
-
-#include "glheader.h"
-#include "imports.h"
-#include "context.h"
-#include "extensions.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-
-enum {
- DISABLE = 0,
- GL = 1 << API_OPENGL,
- ES1 = 1 << API_OPENGLES,
- ES2 = 1 << API_OPENGLES2,
-};
-
-/**
- * \brief An element of the \c extension_table.
- */
-struct extension {
- /** Name of extension, such as "GL_ARB_depth_clamp". */
- const char *name;
-
- /** Offset (in bytes) of the corresponding member in struct gl_extensions. */
- size_t offset;
-
- /** Set of API's in which the extension exists, as a bitset. */
- uint8_t api_set;
-};
-
-
-/**
- * Given a member \c x of struct gl_extensions, return offset of
- * \c x in bytes.
- */
-#define o(x) offsetof(struct gl_extensions, x)
-
-
-/**
- * \brief Table of supported OpenGL extensions for all API's.
- *
- * Note: The GL_MESAX_* extensions are placeholders for future ARB extensions.
- */
-static const struct extension extension_table[] = {
- /* ARB Extensions */
- { "GL_ARB_ES2_compatibility", o(ARB_ES2_compatibility), GL },
- { "GL_ARB_blend_func_extended", o(ARB_blend_func_extended), GL },
- { "GL_ARB_copy_buffer", o(ARB_copy_buffer), GL },
- { "GL_ARB_depth_buffer_float", o(ARB_depth_buffer_float), GL },
- { "GL_ARB_depth_clamp", o(ARB_depth_clamp), GL },
- { "GL_ARB_depth_texture", o(ARB_depth_texture), GL },
- { "GL_ARB_draw_buffers", o(ARB_draw_buffers), GL },
- { "GL_ARB_draw_buffers_blend", o(ARB_draw_buffers_blend), GL },
- { "GL_ARB_draw_elements_base_vertex", o(ARB_draw_elements_base_vertex), GL },
- { "GL_ARB_draw_instanced", o(ARB_draw_instanced), GL },
- { "GL_ARB_explicit_attrib_location", o(ARB_explicit_attrib_location), GL },
- { "GL_ARB_fragment_coord_conventions", o(ARB_fragment_coord_conventions), GL },
- { "GL_ARB_fragment_program", o(ARB_fragment_program), GL },
- { "GL_ARB_fragment_program_shadow", o(ARB_fragment_program_shadow), GL },
- { "GL_ARB_fragment_shader", o(ARB_fragment_shader), GL },
- { "GL_ARB_framebuffer_object", o(ARB_framebuffer_object), GL },
- { "GL_ARB_framebuffer_sRGB", o(EXT_framebuffer_sRGB), GL },
- { "GL_ARB_half_float_pixel", o(ARB_half_float_pixel), GL },
- { "GL_ARB_half_float_vertex", o(ARB_half_float_vertex), GL },
- { "GL_ARB_instanced_arrays", o(ARB_instanced_arrays), GL },
- { "GL_ARB_map_buffer_range", o(ARB_map_buffer_range), GL },
- { "GL_ARB_multisample", o(ARB_multisample), GL },
- { "GL_ARB_multitexture", o(ARB_multitexture), GL },
- { "GL_ARB_occlusion_query2", o(ARB_occlusion_query2), GL },
- { "GL_ARB_occlusion_query", o(ARB_occlusion_query), GL },
- { "GL_ARB_pixel_buffer_object", o(EXT_pixel_buffer_object), GL },
- { "GL_ARB_point_parameters", o(EXT_point_parameters), GL },
- { "GL_ARB_point_sprite", o(ARB_point_sprite), GL },
- { "GL_ARB_provoking_vertex", o(EXT_provoking_vertex), GL },
- { "GL_ARB_sampler_objects", o(ARB_sampler_objects), GL },
- { "GL_ARB_seamless_cube_map", o(ARB_seamless_cube_map), GL },
- { "GL_ARB_shader_objects", o(ARB_shader_objects), GL },
- { "GL_ARB_shader_stencil_export", o(ARB_shader_stencil_export), GL },
- { "GL_ARB_shading_language_100", o(ARB_shading_language_100), GL },
- { "GL_ARB_shadow_ambient", o(ARB_shadow_ambient), GL },
- { "GL_ARB_shadow", o(ARB_shadow), GL },
- { "GL_ARB_sync", o(ARB_sync), GL },
- { "GL_ARB_texture_border_clamp", o(ARB_texture_border_clamp), GL },
- { "GL_ARB_texture_buffer_object", o(ARB_texture_buffer_object), GL },
- { "GL_ARB_texture_compression", o(ARB_texture_compression), GL },
- { "GL_ARB_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL },
- { "GL_ARB_texture_cube_map", o(ARB_texture_cube_map), GL },
- { "GL_ARB_texture_env_add", o(EXT_texture_env_add), GL },
- { "GL_ARB_texture_env_combine", o(ARB_texture_env_combine), GL },
- { "GL_ARB_texture_env_crossbar", o(ARB_texture_env_crossbar), GL },
- { "GL_ARB_texture_env_dot3", o(ARB_texture_env_dot3), GL },
- { "GL_ARB_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL },
- { "GL_ARB_texture_multisample", o(ARB_texture_multisample), GL },
- { "GL_ARB_texture_non_power_of_two", o(ARB_texture_non_power_of_two), GL },
- { "GL_ARB_texture_rectangle", o(NV_texture_rectangle), GL },
- { "GL_ARB_texture_rgb10_a2ui", o(ARB_texture_rgb10_a2ui), GL },
- { "GL_ARB_texture_rg", o(ARB_texture_rg), GL },
- { "GL_ARB_texture_swizzle", o(EXT_texture_swizzle), GL },
- { "GL_ARB_transform_feedback2", o(ARB_transform_feedback2), GL },
- { "GL_ARB_transpose_matrix", o(ARB_transpose_matrix), GL },
- { "GL_ARB_uniform_buffer_object", o(ARB_uniform_buffer_object), GL },
- { "GL_ARB_vertex_array_bgra", o(EXT_vertex_array_bgra), GL },
- { "GL_ARB_vertex_array_object", o(ARB_vertex_array_object), GL },
- { "GL_ARB_vertex_buffer_object", o(ARB_vertex_buffer_object), GL },
- { "GL_ARB_vertex_program", o(ARB_vertex_program), GL },
- { "GL_ARB_vertex_shader", o(ARB_vertex_shader), GL },
- { "GL_ARB_vertex_type_2_10_10_10_rev", o(ARB_vertex_type_2_10_10_10_rev), GL },
- { "GL_ARB_window_pos", o(ARB_window_pos), GL },
-
- /* EXT extensions */
- { "GL_EXT_abgr", o(EXT_abgr), GL },
- { "GL_EXT_bgra", o(EXT_bgra), GL },
- { "GL_EXT_blend_color", o(EXT_blend_color), GL },
- { "GL_EXT_blend_equation_separate", o(EXT_blend_equation_separate), GL },
- { "GL_EXT_blend_func_separate", o(EXT_blend_func_separate), GL },
- { "GL_EXT_blend_logic_op", o(EXT_blend_logic_op), GL },
- { "GL_EXT_blend_minmax", o(EXT_blend_minmax), GL | ES1 | ES2 },
- { "GL_EXT_blend_subtract", o(EXT_blend_subtract), GL },
- { "GL_EXT_clip_volume_hint", o(EXT_clip_volume_hint), GL },
- { "GL_EXT_compiled_vertex_array", o(EXT_compiled_vertex_array), GL },
- { "GL_EXT_copy_texture", o(EXT_copy_texture), GL },
- { "GL_EXT_depth_bounds_test", o(EXT_depth_bounds_test), GL },
- { "GL_EXT_draw_buffers2", o(EXT_draw_buffers2), GL },
- { "GL_EXT_draw_instanced", o(ARB_draw_instanced), GL },
- { "GL_EXT_draw_range_elements", o(EXT_draw_range_elements), GL },
- { "GL_EXT_fog_coord", o(EXT_fog_coord), GL },
- { "GL_EXT_framebuffer_blit", o(EXT_framebuffer_blit), GL },
- { "GL_EXT_framebuffer_multisample", o(EXT_framebuffer_multisample), GL },
- { "GL_EXT_framebuffer_object", o(EXT_framebuffer_object), GL },
- { "GL_EXT_framebuffer_sRGB", o(EXT_framebuffer_sRGB), GL },
- { "GL_EXT_gpu_program_parameters", o(EXT_gpu_program_parameters), GL },
- { "GL_EXT_gpu_shader4", o(EXT_gpu_shader4), GL },
- { "GL_EXT_multi_draw_arrays", o(EXT_multi_draw_arrays), GL | ES1 | ES2 },
- { "GL_EXT_packed_depth_stencil", o(EXT_packed_depth_stencil), GL },
- { "GL_EXT_packed_float", o(EXT_packed_float), GL },
- { "GL_EXT_packed_pixels", o(EXT_packed_pixels), GL },
- { "GL_EXT_paletted_texture", o(EXT_paletted_texture), GL },
- { "GL_EXT_pixel_buffer_object", o(EXT_pixel_buffer_object), GL },
- { "GL_EXT_point_parameters", o(EXT_point_parameters), GL },
- { "GL_EXT_polygon_offset", o(EXT_polygon_offset), GL },
- { "GL_EXT_provoking_vertex", o(EXT_provoking_vertex), GL },
- { "GL_EXT_rescale_normal", o(EXT_rescale_normal), GL },
- { "GL_EXT_secondary_color", o(EXT_secondary_color), GL },
- { "GL_EXT_separate_shader_objects", o(EXT_separate_shader_objects), GL },
- { "GL_EXT_separate_specular_color", o(EXT_separate_specular_color), GL },
- { "GL_EXT_shadow_funcs", o(EXT_shadow_funcs), GL },
- { "GL_EXT_shared_texture_palette", o(EXT_shared_texture_palette), GL },
- { "GL_EXT_stencil_two_side", o(EXT_stencil_two_side), GL },
- { "GL_EXT_stencil_wrap", o(EXT_stencil_wrap), GL },
- { "GL_EXT_subtexture", o(EXT_subtexture), GL },
- { "GL_EXT_texture3D", o(EXT_texture3D), GL },
- { "GL_EXT_texture_array", o(EXT_texture_array), GL },
- { "GL_EXT_texture_compression_dxt1", o(EXT_texture_compression_s3tc), GL | ES1 | ES2 },
- { "GL_EXT_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL },
- { "GL_EXT_texture_compression_s3tc", o(EXT_texture_compression_s3tc), GL },
- { "GL_EXT_texture_cube_map", o(ARB_texture_cube_map), GL },
- { "GL_EXT_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL },
- { "GL_EXT_texture_env_add", o(EXT_texture_env_add), GL },
- { "GL_EXT_texture_env_combine", o(EXT_texture_env_combine), GL },
- { "GL_EXT_texture_env_dot3", o(EXT_texture_env_dot3), GL },
- { "GL_EXT_texture_filter_anisotropic", o(EXT_texture_filter_anisotropic), GL | ES1 | ES2 },
- { "GL_EXT_texture_format_BGRA8888", o(EXT_texture_format_BGRA8888), ES1 | ES2 },
- { "GL_EXT_texture_integer", o(EXT_texture_integer), GL },
- { "GL_EXT_texture_lod_bias", o(EXT_texture_lod_bias), GL | ES1 },
- { "GL_EXT_texture_mirror_clamp", o(EXT_texture_mirror_clamp), GL },
- { "GL_EXT_texture_object", o(EXT_texture_object), GL },
- { "GL_EXT_texture", o(EXT_texture), GL },
- { "GL_EXT_texture_rectangle", o(NV_texture_rectangle), GL },
- { "GL_EXT_texture_shared_exponent", o(EXT_texture_shared_exponent), GL },
- { "GL_EXT_texture_sRGB", o(EXT_texture_sRGB), GL },
- { "GL_EXT_texture_sRGB_decode", o(EXT_texture_sRGB_decode), GL },
- { "GL_EXT_texture_swizzle", o(EXT_texture_swizzle), GL },
- { "GL_EXT_texture_type_2_10_10_10_REV", o(dummy_true), ES2 },
- { "GL_EXT_timer_query", o(EXT_timer_query), GL },
- { "GL_EXT_transform_feedback", o(EXT_transform_feedback), GL },
- { "GL_EXT_vertex_array_bgra", o(EXT_vertex_array_bgra), GL },
- { "GL_EXT_vertex_array", o(EXT_vertex_array), GL },
- { "GL_EXT_vertex_array_set", o(EXT_vertex_array_set), GL },
-
- /* OES extensions */
- { "GL_OES_blend_equation_separate", o(EXT_blend_equation_separate), ES1 },
- { "GL_OES_blend_func_separate", o(EXT_blend_func_separate), ES1 },
- { "GL_OES_blend_subtract", o(EXT_blend_subtract), ES1 },
- { "GL_OES_byte_coordinates", o(dummy_true), ES1 },
- { "GL_OES_compressed_paletted_texture", o(dummy_false), DISABLE },
- { "GL_OES_depth24", o(EXT_framebuffer_object), ES1 | ES2 },
- { "GL_OES_depth32", o(dummy_false), DISABLE },
- { "GL_OES_depth_texture", o(ARB_depth_texture), ES2 },
-#if FEATURE_OES_draw_texture
- { "GL_OES_draw_texture", o(OES_draw_texture), ES1 | ES2 },
-#endif
-#if FEATURE_OES_EGL_image
- /* FIXME: Mesa expects GL_OES_EGL_image to be available in OpenGL contexts. */
- { "GL_OES_EGL_image", o(OES_EGL_image), GL | ES1 | ES2 },
-#endif
- { "GL_OES_element_index_uint", o(EXT_vertex_array), ES1 | ES2 },
- { "GL_OES_fbo_render_mipmap", o(EXT_framebuffer_object), ES1 | ES2 },
- { "GL_OES_fixed_point", o(dummy_true), ES1 },
- { "GL_OES_framebuffer_object", o(EXT_framebuffer_object), ES1 },
- { "GL_OES_mapbuffer", o(ARB_vertex_buffer_object), ES1 | ES2 },
- { "GL_OES_matrix_get", o(dummy_true), ES1 },
- { "GL_OES_packed_depth_stencil", o(EXT_packed_depth_stencil), ES1 | ES2 },
- { "GL_OES_point_size_array", o(dummy_true), ES1 },
- { "GL_OES_point_sprite", o(ARB_point_sprite), ES1 },
- { "GL_OES_query_matrix", o(dummy_true), ES1 },
- { "GL_OES_read_format", o(OES_read_format), GL | ES1 },
- { "GL_OES_rgb8_rgba8", o(EXT_framebuffer_object), ES1 | ES2 },
- { "GL_OES_single_precision", o(dummy_true), ES1 },
- { "GL_OES_standard_derivatives", o(OES_standard_derivatives), ES2 },
- { "GL_OES_stencil1", o(dummy_false), DISABLE },
- { "GL_OES_stencil4", o(dummy_false), DISABLE },
- { "GL_OES_stencil8", o(EXT_framebuffer_object), ES1 | ES2 },
- { "GL_OES_stencil_wrap", o(EXT_stencil_wrap), ES1 },
- { "GL_OES_texture_3D", o(EXT_texture3D), ES2 },
- { "GL_OES_texture_cube_map", o(ARB_texture_cube_map), ES1 },
- { "GL_OES_texture_env_crossbar", o(ARB_texture_env_crossbar), ES1 },
- { "GL_OES_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), ES1 },
- { "GL_OES_texture_npot", o(ARB_texture_non_power_of_two), ES2 },
-
- /* Vendor extensions */
- { "GL_3DFX_texture_compression_FXT1", o(TDFX_texture_compression_FXT1), GL },
- { "GL_AMD_conservative_depth", o(AMD_conservative_depth), GL },
- { "GL_APPLE_client_storage", o(APPLE_client_storage), GL },
- { "GL_APPLE_object_purgeable", o(APPLE_object_purgeable), GL },
- { "GL_APPLE_packed_pixels", o(APPLE_packed_pixels), GL },
- { "GL_APPLE_vertex_array_object", o(APPLE_vertex_array_object), GL },
- { "GL_ATI_blend_equation_separate", o(EXT_blend_equation_separate), GL },
- { "GL_ATI_envmap_bumpmap", o(ATI_envmap_bumpmap), GL },
- { "GL_ATI_fragment_shader", o(ATI_fragment_shader), GL },
- { "GL_ATI_separate_stencil", o(ATI_separate_stencil), GL },
- { "GL_ATI_texture_env_combine3", o(ATI_texture_env_combine3), GL },
- { "GL_ATI_texture_mirror_once", o(ATI_texture_mirror_once), GL },
- { "GL_IBM_multimode_draw_arrays", o(IBM_multimode_draw_arrays), GL },
- { "GL_IBM_rasterpos_clip", o(IBM_rasterpos_clip), GL },
- { "GL_IBM_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL },
- { "GL_INGR_blend_func_separate", o(EXT_blend_func_separate), GL },
- { "GL_MESA_pack_invert", o(MESA_pack_invert), GL },
- { "GL_MESA_resize_buffers", o(MESA_resize_buffers), GL },
- { "GL_MESA_texture_array", o(MESA_texture_array), GL },
- { "GL_MESA_texture_signed_rgba", o(MESA_texture_signed_rgba), GL },
- { "GL_MESA_window_pos", o(ARB_window_pos), GL },
- { "GL_MESAX_texture_float", o(ARB_texture_float), GL },
- { "GL_MESA_ycbcr_texture", o(MESA_ycbcr_texture), GL },
- { "GL_NV_blend_square", o(NV_blend_square), GL },
- { "GL_NV_conditional_render", o(NV_conditional_render), GL },
- { "GL_NV_depth_clamp", o(ARB_depth_clamp), GL },
- { "GL_NV_fragment_program", o(NV_fragment_program), GL },
- { "GL_NV_fragment_program_option", o(NV_fragment_program_option), GL },
- { "GL_NV_light_max_exponent", o(NV_light_max_exponent), GL },
- { "GL_NV_packed_depth_stencil", o(EXT_packed_depth_stencil), GL },
- { "GL_NV_point_sprite", o(NV_point_sprite), GL },
- { "GL_NV_primitive_restart", o(NV_primitive_restart), GL },
- { "GL_NV_texgen_reflection", o(NV_texgen_reflection), GL },
- { "GL_NV_texture_env_combine4", o(NV_texture_env_combine4), GL },
- { "GL_NV_texture_rectangle", o(NV_texture_rectangle), GL },
- { "GL_NV_vertex_program1_1", o(NV_vertex_program1_1), GL },
- { "GL_NV_vertex_program", o(NV_vertex_program), GL },
- { "GL_S3_s3tc", o(S3_s3tc), GL },
- { "GL_SGIS_generate_mipmap", o(SGIS_generate_mipmap), GL },
- { "GL_SGIS_texture_border_clamp", o(ARB_texture_border_clamp), GL },
- { "GL_SGIS_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL },
- { "GL_SGIS_texture_lod", o(SGIS_texture_lod), GL },
- { "GL_SUN_multi_draw_arrays", o(EXT_multi_draw_arrays), GL },
-
- { 0, 0, 0 },
-};
-
-
-/**
- * Given an extension name, lookup up the corresponding member of struct
- * gl_extensions and return that member's offset (in bytes). If the name is
- * not found in the \c extension_table, return 0.
- *
- * \param name Name of extension.
- * \return Offset of member in struct gl_extensions.
- */
-static size_t
-name_to_offset(const char* name)
-{
- const struct extension *i;
-
- if (name == 0)
- return 0;
-
- for (i = extension_table; i->name != 0; ++i) {
- if (strcmp(name, i->name) == 0)
- return i->offset;
- }
-
- return 0;
-}
-
-
-/**
- * \brief Extensions enabled by default.
- *
- * These extensions are enabled by _mesa_init_extensions().
- *
- * XXX: Should these defaults also apply to GLES?
- */
-static const size_t default_extensions[] = {
- o(ARB_copy_buffer),
- o(ARB_draw_buffers),
- o(ARB_multisample),
- o(ARB_texture_compression),
- o(ARB_transpose_matrix),
- o(ARB_vertex_buffer_object),
- o(ARB_window_pos),
-
- o(EXT_abgr),
- o(EXT_bgra),
- o(EXT_compiled_vertex_array),
- o(EXT_copy_texture),
- o(EXT_draw_range_elements),
- o(EXT_multi_draw_arrays),
- o(EXT_packed_pixels),
- o(EXT_polygon_offset),
- o(EXT_rescale_normal),
- o(EXT_separate_specular_color),
- o(EXT_subtexture),
- o(EXT_texture),
- o(EXT_texture3D),
- o(EXT_texture_object),
- o(EXT_vertex_array),
-
- o(OES_read_format),
- o(OES_standard_derivatives),
-
- /* Vendor Extensions */
- o(APPLE_packed_pixels),
- o(IBM_multimode_draw_arrays),
- o(IBM_rasterpos_clip),
- o(NV_light_max_exponent),
- o(NV_texgen_reflection),
- o(SGIS_generate_mipmap),
- o(SGIS_texture_edge_clamp),
- o(SGIS_texture_lod),
-
- 0,
-};
-
-
-/**
- * Enable all extensions suitable for a software-only renderer.
- * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
- */
-void
-_mesa_enable_sw_extensions(struct gl_context *ctx)
-{
- /*ctx->Extensions.ARB_copy_buffer = GL_TRUE;*/
- ctx->Extensions.ARB_depth_clamp = GL_TRUE;
- ctx->Extensions.ARB_depth_texture = GL_TRUE;
- /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
- ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
- ctx->Extensions.ARB_draw_instanced = GL_TRUE;
- ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
- ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
-#if FEATURE_ARB_fragment_program
- ctx->Extensions.ARB_fragment_program = GL_TRUE;
- ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
-#endif
-#if FEATURE_ARB_fragment_shader
- ctx->Extensions.ARB_fragment_shader = GL_TRUE;
-#endif
-#if FEATURE_ARB_framebuffer_object
- ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
-#endif
-#if FEATURE_ARB_geometry_shader4 && 0
- /* XXX re-enable when GLSL compiler again supports geometry shaders */
- ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
-#endif
- ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
- ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
- ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
- ctx->Extensions.ARB_multitexture = GL_TRUE;
-#if FEATURE_queryobj
- ctx->Extensions.ARB_occlusion_query = GL_TRUE;
- ctx->Extensions.ARB_occlusion_query2 = GL_TRUE;
-#endif
- ctx->Extensions.ARB_point_sprite = GL_TRUE;
-#if FEATURE_ARB_shader_objects
- ctx->Extensions.ARB_shader_objects = GL_TRUE;
- ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
-#endif
-#if FEATURE_ARB_shading_language_100
- ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
-#endif
- ctx->Extensions.ARB_shadow = GL_TRUE;
- ctx->Extensions.ARB_shadow_ambient = GL_TRUE;
- ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
- ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
- ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
- ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
- ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
- /*ctx->Extensions.ARB_texture_float = GL_TRUE;*/
- ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
- ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
- ctx->Extensions.ARB_texture_rg = GL_TRUE;
- ctx->Extensions.ARB_texture_compression_rgtc = GL_TRUE;
- ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
-#if FEATURE_ARB_vertex_program
- ctx->Extensions.ARB_vertex_program = GL_TRUE;
-#endif
-#if FEATURE_ARB_vertex_shader
- ctx->Extensions.ARB_vertex_shader = GL_TRUE;
-#endif
-#if FEATURE_ARB_vertex_buffer_object
- /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
-#endif
-#if FEATURE_ARB_sync
- ctx->Extensions.ARB_sync = GL_TRUE;
-#endif
- ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
-#if FEATURE_APPLE_object_purgeable
- ctx->Extensions.APPLE_object_purgeable = GL_TRUE;
-#endif
- ctx->Extensions.ATI_envmap_bumpmap = GL_TRUE;
-#if FEATURE_ATI_fragment_shader
- ctx->Extensions.ATI_fragment_shader = GL_TRUE;
-#endif
- ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
- ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
- ctx->Extensions.ATI_separate_stencil = GL_TRUE;
- ctx->Extensions.EXT_blend_color = GL_TRUE;
- ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
- ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
- ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
- ctx->Extensions.EXT_blend_minmax = GL_TRUE;
- ctx->Extensions.EXT_blend_subtract = GL_TRUE;
- ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
- ctx->Extensions.EXT_draw_buffers2 = GL_TRUE;
- ctx->Extensions.EXT_fog_coord = GL_TRUE;
-#if FEATURE_EXT_framebuffer_object
- ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
-#endif
-#if FEATURE_EXT_framebuffer_blit
- ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
-#endif
-#if FEATURE_ARB_framebuffer_object
- ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
-#endif
- /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
- ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
- ctx->Extensions.EXT_paletted_texture = GL_TRUE;
-#if FEATURE_EXT_pixel_buffer_object
- ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
-#endif
- ctx->Extensions.EXT_point_parameters = GL_TRUE;
- ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
- ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
- ctx->Extensions.EXT_secondary_color = GL_TRUE;
- ctx->Extensions.EXT_shared_texture_palette = GL_TRUE;
- ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
- ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
- ctx->Extensions.EXT_texture_array = GL_TRUE;
- ctx->Extensions.EXT_texture_env_add = GL_TRUE;
- ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
- ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
- ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
- ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
-#if FEATURE_EXT_texture_sRGB
- ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
- ctx->Extensions.EXT_texture_sRGB_decode = GL_TRUE;
-#endif
- ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
-#if FEATURE_EXT_transform_feedback
- /*ctx->Extensions.EXT_transform_feedback = GL_TRUE;*/
-#endif
- ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
- /*ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;*/
- ctx->Extensions.MESA_pack_invert = GL_TRUE;
- ctx->Extensions.MESA_resize_buffers = GL_TRUE;
- ctx->Extensions.MESA_texture_array = GL_TRUE;
- ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
- ctx->Extensions.NV_blend_square = GL_TRUE;
- ctx->Extensions.NV_conditional_render = GL_TRUE;
- /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
- ctx->Extensions.NV_point_sprite = GL_TRUE;
- ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
- ctx->Extensions.NV_texture_rectangle = GL_TRUE;
- /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
-#if FEATURE_NV_vertex_program
- ctx->Extensions.NV_vertex_program = GL_TRUE;
- ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
-#endif
-#if FEATURE_NV_fragment_program
- ctx->Extensions.NV_fragment_program = GL_TRUE;
-#endif
-#if FEATURE_NV_fragment_program && FEATURE_ARB_fragment_program
- ctx->Extensions.NV_fragment_program_option = GL_TRUE;
-#endif
- /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
- ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE;
-#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
- ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
-#endif
-#if FEATURE_texture_fxt1
- _mesa_enable_extension(ctx, "GL_3DFX_texture_compression_FXT1");
-#endif
-#if FEATURE_texture_s3tc
- if (ctx->Mesa_DXTn) {
- _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
- _mesa_enable_extension(ctx, "GL_S3_s3tc");
- }
-#endif
-}
-
-
-/**
- * Enable common EXT extensions in the ARB_imaging subset.
- */
-void
-_mesa_enable_imaging_extensions(struct gl_context *ctx)
-{
- ctx->Extensions.EXT_blend_color = GL_TRUE;
- ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
- ctx->Extensions.EXT_blend_minmax = GL_TRUE;
- ctx->Extensions.EXT_blend_subtract = GL_TRUE;
-}
-
-
-
-/**
- * Enable all OpenGL 1.3 features and extensions.
- * A convenience function to be called by drivers.
- */
-void
-_mesa_enable_1_3_extensions(struct gl_context *ctx)
-{
- /*ctx->Extensions.ARB_multisample = GL_TRUE;*/
- ctx->Extensions.ARB_multitexture = GL_TRUE;
- ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
- /*ctx->Extensions.ARB_texture_compression = GL_TRUE;*/
- ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
- ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
- ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
- ctx->Extensions.EXT_texture_env_add = GL_TRUE;
- /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
-}
-
-
-
-/**
- * Enable all OpenGL 1.4 features and extensions.
- * A convenience function to be called by drivers.
- */
-void
-_mesa_enable_1_4_extensions(struct gl_context *ctx)
-{
- ctx->Extensions.ARB_depth_texture = GL_TRUE;
- ctx->Extensions.ARB_shadow = GL_TRUE;
- ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
- ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
- ctx->Extensions.ARB_window_pos = GL_TRUE;
- ctx->Extensions.EXT_blend_color = GL_TRUE;
- ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
- ctx->Extensions.EXT_blend_minmax = GL_TRUE;
- ctx->Extensions.EXT_blend_subtract = GL_TRUE;
- ctx->Extensions.EXT_fog_coord = GL_TRUE;
- /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
- ctx->Extensions.EXT_point_parameters = GL_TRUE;
- ctx->Extensions.EXT_secondary_color = GL_TRUE;
- ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
- ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
- /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
-}
-
-
-/**
- * Enable all OpenGL 1.5 features and extensions.
- * A convenience function to be called by drivers.
- */
-void
-_mesa_enable_1_5_extensions(struct gl_context *ctx)
-{
- ctx->Extensions.ARB_occlusion_query = GL_TRUE;
- /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
- ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
-}
-
-
-/**
- * Enable all OpenGL 2.0 features and extensions.
- * A convenience function to be called by drivers.
- */
-void
-_mesa_enable_2_0_extensions(struct gl_context *ctx)
-{
- /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
-#if FEATURE_ARB_fragment_shader
- ctx->Extensions.ARB_fragment_shader = GL_TRUE;
-#endif
- ctx->Extensions.ARB_point_sprite = GL_TRUE;
- ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
- ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
-#if FEATURE_ARB_shader_objects
- ctx->Extensions.ARB_shader_objects = GL_TRUE;
-#endif
-#if FEATURE_ARB_shading_language_100
- ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
-#endif
- ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
-#if FEATURE_ARB_vertex_shader
- ctx->Extensions.ARB_vertex_shader = GL_TRUE;
-#endif
-}
-
-
-/**
- * Enable all OpenGL 2.1 features and extensions.
- * A convenience function to be called by drivers.
- */
-void
-_mesa_enable_2_1_extensions(struct gl_context *ctx)
-{
-#if FEATURE_EXT_pixel_buffer_object
- ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
-#endif
-#if FEATURE_EXT_texture_sRGB
- ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
-#endif
-}
-
-
-/**
- * Either enable or disable the named extension.
- * \return GL_TRUE for success, GL_FALSE if invalid extension name
- */
-static GLboolean
-set_extension( struct gl_context *ctx, const char *name, GLboolean state )
-{
- size_t offset;
-
- if (ctx->Extensions.String) {
- /* The string was already queried - can't change it now! */
- _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name);
- return GL_FALSE;
- }
-
- offset = name_to_offset(name);
- if (offset == 0) {
- _mesa_problem(ctx, "Trying to enable/disable unknown extension %s",
- name);
- return GL_FALSE;
- } else if (offset == o(dummy_true) && state == GL_FALSE) {
- _mesa_problem(ctx, "Trying to disable a permanently enabled extension: "
- "%s", name);
- return GL_FALSE;
- } else {
- GLboolean *base = (GLboolean *) &ctx->Extensions;
- base[offset] = state;
- return GL_TRUE;
- }
-}
-
-
-/**
- * Enable the named extension.
- * Typically called by drivers.
- */
-void
-_mesa_enable_extension( struct gl_context *ctx, const char *name )
-{
- if (!set_extension(ctx, name, GL_TRUE))
- _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
-}
-
-
-/**
- * Disable the named extension.
- * XXX is this really needed???
- */
-void
-_mesa_disable_extension( struct gl_context *ctx, const char *name )
-{
- if (!set_extension(ctx, name, GL_FALSE))
- _mesa_problem(ctx, "Trying to disable unknown extension: %s", name);
-}
-
-
-/**
- * Test if the named extension is enabled in this context.
- */
-GLboolean
-_mesa_extension_is_enabled( struct gl_context *ctx, const char *name )
-{
- size_t offset;
- GLboolean *base;
-
- if (name == 0)
- return GL_FALSE;
-
- offset = name_to_offset(name);
- if (offset == 0)
- return GL_FALSE;
- base = (GLboolean *) &ctx->Extensions;
- return base[offset];
-}
-
-
-/**
- * \brief Apply the \c MESA_EXTENSION_OVERRIDE environment variable.
- *
- * \c MESA_EXTENSION_OVERRIDE is a space-separated list of extensions to
- * enable or disable. The list is processed thus:
- * - Enable recognized extension names that are prefixed with '+'.
- * - Disable recognized extension names that are prefixed with '-'.
- * - Enable recognized extension names that are not prefixed.
- * - Collect unrecognized extension names in a new string.
- *
- * \return Space-separated list of unrecognized extension names (which must
- * be freed). Does not return \c NULL.
- */
-static char *
-get_extension_override( struct gl_context *ctx )
-{
- const char *env_const= _mesa_getenv("MESA_EXTENSION_OVERRIDE");
- char *env;
- char *ext;
- char *extra_exts;
- int len;
-
- if (env_const == NULL) {
- /* Return the empty string rather than NULL. This simplifies the logic
- * of client functions. */
- return calloc(1, sizeof(char));
- }
-
- /* extra_exts: List of unrecognized extensions. */
- extra_exts = calloc(strlen(env_const), sizeof(char));
-
- /* Copy env_const because strtok() is destructive. */
- env = strdup(env_const);
- for (ext = strtok(env, " "); ext != NULL; ext = strtok(NULL, " ")) {
- int enable;
- int recognized;
- switch (ext[0]) {
- case '+':
- enable = 1;
- ++ext;
- break;
- case '-':
- enable = 0;
- ++ext;
- break;
- default:
- enable = 1;
- break;
- }
- recognized = set_extension(ctx, ext, enable);
- if (!recognized) {
- strcat(extra_exts, ext);
- strcat(extra_exts, " ");
- }
- }
-
- /* Remove trailing space. */
- len = strlen(extra_exts);
- if (extra_exts[len - 1] == ' ')
- extra_exts[len - 1] = '\0';
-
- return extra_exts;
-}
-
-
-/**
- * \brief Initialize extension tables and enable default extensions.
- *
- * This should be called during context initialization.
- * Note: Sets gl_extensions.dummy_true to true.
- */
-void
-_mesa_init_extensions( struct gl_context *ctx )
-{
- GLboolean *base = (GLboolean *) &ctx->Extensions;
- GLboolean *sentinel = base + o(extension_sentinel);
- GLboolean *i;
- const size_t *j;
-
- /* First, turn all extensions off. */
- for (i = base; i != sentinel; ++i)
- *i = GL_FALSE;
-
- /* Then, selectively turn default extensions on. */
- ctx->Extensions.dummy_true = GL_TRUE;
- for (j = default_extensions; *j != 0; ++j)
- base[*j] = GL_TRUE;
-}
-
-
-/**
- * Construct the GL_EXTENSIONS string. Called the first time that
- * glGetString(GL_EXTENSIONS) is called.
- */
-GLubyte*
-_mesa_make_extension_string(struct gl_context *ctx)
-{
- /* The extension string. */
- char *exts = 0;
- /* Length of extension string. */
- size_t length = 0;
- /* String of extra extensions. */
- char *extra_extensions = get_extension_override(ctx);
- GLboolean *base = (GLboolean *) &ctx->Extensions;
- const struct extension *i;
-
- /* Compute length of the extension string. */
- for (i = extension_table; i->name != 0; ++i) {
- if (base[i->offset] && (i->api_set & (1 << ctx->API))) {
- length += strlen(i->name) + 1; /* +1 for space */
- }
- }
- if (extra_extensions != NULL)
- length += 1 + strlen(extra_extensions); /* +1 for space */
-
- exts = (char *) calloc(length + 1, sizeof(char));
- if (exts == NULL) {
- free(extra_extensions);
- return NULL;
- }
-
- /* Build the extension string.*/
- for (i = extension_table; i->name != 0; ++i) {
- if (base[i->offset] && (i->api_set & (1 << ctx->API))) {
- strcat(exts, i->name);
- strcat(exts, " ");
- }
- }
- if (extra_extensions != 0) {
- strcat(exts, extra_extensions);
- free(extra_extensions);
- }
-
- return (GLubyte *) exts;
-}
-
-/**
- * Return number of enabled extensions.
- */
-GLuint
-_mesa_get_extension_count(struct gl_context *ctx)
-{
- GLboolean *base;
- const struct extension *i;
-
- /* only count once */
- if (ctx->Extensions.Count != 0)
- return ctx->Extensions.Count;
-
- base = (GLboolean *) &ctx->Extensions;
- for (i = extension_table; i->name != 0; ++i) {
- if (base[i->offset]) {
- ctx->Extensions.Count++;
- }
- }
- return ctx->Extensions.Count;
-}
-
-/**
- * Return name of i-th enabled extension
- */
-const GLubyte *
-_mesa_get_enabled_extension(struct gl_context *ctx, GLuint index)
-{
- const GLboolean *base;
- size_t n;
- const struct extension *i;
-
- if (index < 0)
- return NULL;
-
- base = (GLboolean*) &ctx->Extensions;
- n = 0;
- for (i = extension_table; i->name != 0; ++i) {
- if (n == index && base[i->offset]) {
- return (GLubyte*) i->name;
- } else if (base[i->offset]) {
- ++n;
- }
- }
-
- return NULL;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.6
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file
+ * \brief Extension handling
+ */
+
+
+#include "glheader.h"
+#include "imports.h"
+#include "context.h"
+#include "extensions.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+
+enum {
+ DISABLE = 0,
+ GL = 1 << API_OPENGL,
+ ES1 = 1 << API_OPENGLES,
+ ES2 = 1 << API_OPENGLES2,
+};
+
+/**
+ * \brief An element of the \c extension_table.
+ */
+struct extension {
+ /** Name of extension, such as "GL_ARB_depth_clamp". */
+ const char *name;
+
+ /** Offset (in bytes) of the corresponding member in struct gl_extensions. */
+ size_t offset;
+
+ /** Set of API's in which the extension exists, as a bitset. */
+ uint8_t api_set;
+};
+
+
+/**
+ * Given a member \c x of struct gl_extensions, return offset of
+ * \c x in bytes.
+ */
+#define o(x) offsetof(struct gl_extensions, x)
+
+
+/**
+ * \brief Table of supported OpenGL extensions for all API's.
+ *
+ * Note: The GL_MESAX_* extensions are placeholders for future ARB extensions.
+ */
+static const struct extension extension_table[] = {
+ /* ARB Extensions */
+ { "GL_ARB_ES2_compatibility", o(ARB_ES2_compatibility), GL },
+ { "GL_ARB_blend_func_extended", o(ARB_blend_func_extended), GL },
+ { "GL_ARB_copy_buffer", o(ARB_copy_buffer), GL },
+ { "GL_ARB_depth_buffer_float", o(ARB_depth_buffer_float), GL },
+ { "GL_ARB_depth_clamp", o(ARB_depth_clamp), GL },
+ { "GL_ARB_depth_texture", o(ARB_depth_texture), GL },
+ { "GL_ARB_draw_buffers", o(ARB_draw_buffers), GL },
+ { "GL_ARB_draw_buffers_blend", o(ARB_draw_buffers_blend), GL },
+ { "GL_ARB_draw_elements_base_vertex", o(ARB_draw_elements_base_vertex), GL },
+ { "GL_ARB_draw_instanced", o(ARB_draw_instanced), GL },
+ { "GL_ARB_explicit_attrib_location", o(ARB_explicit_attrib_location), GL },
+ { "GL_ARB_fragment_coord_conventions", o(ARB_fragment_coord_conventions), GL },
+ { "GL_ARB_fragment_program", o(ARB_fragment_program), GL },
+ { "GL_ARB_fragment_program_shadow", o(ARB_fragment_program_shadow), GL },
+ { "GL_ARB_fragment_shader", o(ARB_fragment_shader), GL },
+ { "GL_ARB_framebuffer_object", o(ARB_framebuffer_object), GL },
+ { "GL_ARB_framebuffer_sRGB", o(EXT_framebuffer_sRGB), GL },
+ { "GL_ARB_half_float_pixel", o(ARB_half_float_pixel), GL },
+ { "GL_ARB_half_float_vertex", o(ARB_half_float_vertex), GL },
+ { "GL_ARB_instanced_arrays", o(ARB_instanced_arrays), GL },
+ { "GL_ARB_map_buffer_range", o(ARB_map_buffer_range), GL },
+ { "GL_ARB_multisample", o(ARB_multisample), GL },
+ { "GL_ARB_multitexture", o(ARB_multitexture), GL },
+ { "GL_ARB_occlusion_query2", o(ARB_occlusion_query2), GL },
+ { "GL_ARB_occlusion_query", o(ARB_occlusion_query), GL },
+ { "GL_ARB_pixel_buffer_object", o(EXT_pixel_buffer_object), GL },
+ { "GL_ARB_point_parameters", o(EXT_point_parameters), GL },
+ { "GL_ARB_point_sprite", o(ARB_point_sprite), GL },
+ { "GL_ARB_provoking_vertex", o(EXT_provoking_vertex), GL },
+ { "GL_ARB_sampler_objects", o(ARB_sampler_objects), GL },
+ { "GL_ARB_seamless_cube_map", o(ARB_seamless_cube_map), GL },
+ { "GL_ARB_shader_objects", o(ARB_shader_objects), GL },
+ { "GL_ARB_shader_stencil_export", o(ARB_shader_stencil_export), GL },
+ { "GL_ARB_shading_language_100", o(ARB_shading_language_100), GL },
+ { "GL_ARB_shadow_ambient", o(ARB_shadow_ambient), GL },
+ { "GL_ARB_shadow", o(ARB_shadow), GL },
+ { "GL_ARB_sync", o(ARB_sync), GL },
+ { "GL_ARB_texture_border_clamp", o(ARB_texture_border_clamp), GL },
+ { "GL_ARB_texture_buffer_object", o(ARB_texture_buffer_object), GL },
+ { "GL_ARB_texture_compression", o(ARB_texture_compression), GL },
+ { "GL_ARB_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL },
+ { "GL_ARB_texture_cube_map", o(ARB_texture_cube_map), GL },
+ { "GL_ARB_texture_env_add", o(EXT_texture_env_add), GL },
+ { "GL_ARB_texture_env_combine", o(ARB_texture_env_combine), GL },
+ { "GL_ARB_texture_env_crossbar", o(ARB_texture_env_crossbar), GL },
+ { "GL_ARB_texture_env_dot3", o(ARB_texture_env_dot3), GL },
+ { "GL_ARB_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL },
+ { "GL_ARB_texture_multisample", o(ARB_texture_multisample), GL },
+ { "GL_ARB_texture_non_power_of_two", o(ARB_texture_non_power_of_two), GL },
+ { "GL_ARB_texture_rectangle", o(NV_texture_rectangle), GL },
+ { "GL_ARB_texture_rgb10_a2ui", o(ARB_texture_rgb10_a2ui), GL },
+ { "GL_ARB_texture_rg", o(ARB_texture_rg), GL },
+ { "GL_ARB_texture_swizzle", o(EXT_texture_swizzle), GL },
+ { "GL_ARB_transform_feedback2", o(ARB_transform_feedback2), GL },
+ { "GL_ARB_transpose_matrix", o(ARB_transpose_matrix), GL },
+ { "GL_ARB_uniform_buffer_object", o(ARB_uniform_buffer_object), GL },
+ { "GL_ARB_vertex_array_bgra", o(EXT_vertex_array_bgra), GL },
+ { "GL_ARB_vertex_array_object", o(ARB_vertex_array_object), GL },
+ { "GL_ARB_vertex_buffer_object", o(ARB_vertex_buffer_object), GL },
+ { "GL_ARB_vertex_program", o(ARB_vertex_program), GL },
+ { "GL_ARB_vertex_shader", o(ARB_vertex_shader), GL },
+ { "GL_ARB_vertex_type_2_10_10_10_rev", o(ARB_vertex_type_2_10_10_10_rev), GL },
+ { "GL_ARB_window_pos", o(ARB_window_pos), GL },
+
+ /* EXT extensions */
+ { "GL_EXT_abgr", o(EXT_abgr), GL },
+ { "GL_EXT_bgra", o(EXT_bgra), GL },
+ { "GL_EXT_blend_color", o(EXT_blend_color), GL },
+ { "GL_EXT_blend_equation_separate", o(EXT_blend_equation_separate), GL },
+ { "GL_EXT_blend_func_separate", o(EXT_blend_func_separate), GL },
+ { "GL_EXT_blend_logic_op", o(EXT_blend_logic_op), GL },
+ { "GL_EXT_blend_minmax", o(EXT_blend_minmax), GL | ES1 | ES2 },
+ { "GL_EXT_blend_subtract", o(EXT_blend_subtract), GL },
+ { "GL_EXT_clip_volume_hint", o(EXT_clip_volume_hint), GL },
+ { "GL_EXT_compiled_vertex_array", o(EXT_compiled_vertex_array), GL },
+ { "GL_EXT_copy_texture", o(EXT_copy_texture), GL },
+ { "GL_EXT_depth_bounds_test", o(EXT_depth_bounds_test), GL },
+ { "GL_EXT_draw_buffers2", o(EXT_draw_buffers2), GL },
+ { "GL_EXT_draw_instanced", o(ARB_draw_instanced), GL },
+ { "GL_EXT_draw_range_elements", o(EXT_draw_range_elements), GL },
+ { "GL_EXT_fog_coord", o(EXT_fog_coord), GL },
+ { "GL_EXT_framebuffer_blit", o(EXT_framebuffer_blit), GL },
+ { "GL_EXT_framebuffer_multisample", o(EXT_framebuffer_multisample), GL },
+ { "GL_EXT_framebuffer_object", o(EXT_framebuffer_object), GL },
+ { "GL_EXT_framebuffer_sRGB", o(EXT_framebuffer_sRGB), GL },
+ { "GL_EXT_gpu_program_parameters", o(EXT_gpu_program_parameters), GL },
+ { "GL_EXT_gpu_shader4", o(EXT_gpu_shader4), GL },
+ { "GL_EXT_multi_draw_arrays", o(EXT_multi_draw_arrays), GL | ES1 | ES2 },
+ { "GL_EXT_packed_depth_stencil", o(EXT_packed_depth_stencil), GL },
+ { "GL_EXT_packed_float", o(EXT_packed_float), GL },
+ { "GL_EXT_packed_pixels", o(EXT_packed_pixels), GL },
+ { "GL_EXT_paletted_texture", o(EXT_paletted_texture), GL },
+ { "GL_EXT_pixel_buffer_object", o(EXT_pixel_buffer_object), GL },
+ { "GL_EXT_point_parameters", o(EXT_point_parameters), GL },
+ { "GL_EXT_polygon_offset", o(EXT_polygon_offset), GL },
+ { "GL_EXT_provoking_vertex", o(EXT_provoking_vertex), GL },
+ { "GL_EXT_rescale_normal", o(EXT_rescale_normal), GL },
+ { "GL_EXT_secondary_color", o(EXT_secondary_color), GL },
+ { "GL_EXT_separate_shader_objects", o(EXT_separate_shader_objects), GL },
+ { "GL_EXT_separate_specular_color", o(EXT_separate_specular_color), GL },
+ { "GL_EXT_shadow_funcs", o(EXT_shadow_funcs), GL },
+ { "GL_EXT_shared_texture_palette", o(EXT_shared_texture_palette), GL },
+ { "GL_EXT_stencil_two_side", o(EXT_stencil_two_side), GL },
+ { "GL_EXT_stencil_wrap", o(EXT_stencil_wrap), GL },
+ { "GL_EXT_subtexture", o(EXT_subtexture), GL },
+ { "GL_EXT_texture3D", o(EXT_texture3D), GL },
+ { "GL_EXT_texture_array", o(EXT_texture_array), GL },
+ { "GL_EXT_texture_compression_dxt1", o(EXT_texture_compression_s3tc), GL | ES1 | ES2 },
+ { "GL_EXT_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL },
+ { "GL_EXT_texture_compression_s3tc", o(EXT_texture_compression_s3tc), GL },
+ { "GL_EXT_texture_cube_map", o(ARB_texture_cube_map), GL },
+ { "GL_EXT_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL },
+ { "GL_EXT_texture_env_add", o(EXT_texture_env_add), GL },
+ { "GL_EXT_texture_env_combine", o(EXT_texture_env_combine), GL },
+ { "GL_EXT_texture_env_dot3", o(EXT_texture_env_dot3), GL },
+ { "GL_EXT_texture_filter_anisotropic", o(EXT_texture_filter_anisotropic), GL | ES1 | ES2 },
+ { "GL_EXT_texture_format_BGRA8888", o(EXT_texture_format_BGRA8888), ES1 | ES2 },
+ { "GL_EXT_texture_integer", o(EXT_texture_integer), GL },
+ { "GL_EXT_texture_lod_bias", o(EXT_texture_lod_bias), GL | ES1 },
+ { "GL_EXT_texture_mirror_clamp", o(EXT_texture_mirror_clamp), GL },
+ { "GL_EXT_texture_object", o(EXT_texture_object), GL },
+ { "GL_EXT_texture", o(EXT_texture), GL },
+ { "GL_EXT_texture_rectangle", o(NV_texture_rectangle), GL },
+ { "GL_EXT_texture_shared_exponent", o(EXT_texture_shared_exponent), GL },
+ { "GL_EXT_texture_sRGB", o(EXT_texture_sRGB), GL },
+ { "GL_EXT_texture_sRGB_decode", o(EXT_texture_sRGB_decode), GL },
+ { "GL_EXT_texture_swizzle", o(EXT_texture_swizzle), GL },
+ { "GL_EXT_texture_type_2_10_10_10_REV", o(dummy_true), ES2 },
+ { "GL_EXT_timer_query", o(EXT_timer_query), GL },
+ { "GL_EXT_transform_feedback", o(EXT_transform_feedback), GL },
+ { "GL_EXT_vertex_array_bgra", o(EXT_vertex_array_bgra), GL },
+ { "GL_EXT_vertex_array", o(EXT_vertex_array), GL },
+ { "GL_EXT_vertex_array_set", o(EXT_vertex_array_set), GL },
+
+ /* OES extensions */
+ { "GL_OES_blend_equation_separate", o(EXT_blend_equation_separate), ES1 },
+ { "GL_OES_blend_func_separate", o(EXT_blend_func_separate), ES1 },
+ { "GL_OES_blend_subtract", o(EXT_blend_subtract), ES1 },
+ { "GL_OES_byte_coordinates", o(dummy_true), ES1 },
+ { "GL_OES_compressed_paletted_texture", o(dummy_false), DISABLE },
+ { "GL_OES_depth24", o(EXT_framebuffer_object), ES1 | ES2 },
+ { "GL_OES_depth32", o(dummy_false), DISABLE },
+ { "GL_OES_depth_texture", o(ARB_depth_texture), ES2 },
+#if FEATURE_OES_draw_texture
+ { "GL_OES_draw_texture", o(OES_draw_texture), ES1 | ES2 },
+#endif
+#if FEATURE_OES_EGL_image
+ /* FIXME: Mesa expects GL_OES_EGL_image to be available in OpenGL contexts. */
+ { "GL_OES_EGL_image", o(OES_EGL_image), GL | ES1 | ES2 },
+#endif
+ { "GL_OES_element_index_uint", o(EXT_vertex_array), ES1 | ES2 },
+ { "GL_OES_fbo_render_mipmap", o(EXT_framebuffer_object), ES1 | ES2 },
+ { "GL_OES_fixed_point", o(dummy_true), ES1 },
+ { "GL_OES_framebuffer_object", o(EXT_framebuffer_object), ES1 },
+ { "GL_OES_mapbuffer", o(ARB_vertex_buffer_object), ES1 | ES2 },
+ { "GL_OES_matrix_get", o(dummy_true), ES1 },
+ { "GL_OES_packed_depth_stencil", o(EXT_packed_depth_stencil), ES1 | ES2 },
+ { "GL_OES_point_size_array", o(dummy_true), ES1 },
+ { "GL_OES_point_sprite", o(ARB_point_sprite), ES1 },
+ { "GL_OES_query_matrix", o(dummy_true), ES1 },
+ { "GL_OES_read_format", o(OES_read_format), GL | ES1 },
+ { "GL_OES_rgb8_rgba8", o(EXT_framebuffer_object), ES1 | ES2 },
+ { "GL_OES_single_precision", o(dummy_true), ES1 },
+ { "GL_OES_standard_derivatives", o(OES_standard_derivatives), ES2 },
+ { "GL_OES_stencil1", o(dummy_false), DISABLE },
+ { "GL_OES_stencil4", o(dummy_false), DISABLE },
+ { "GL_OES_stencil8", o(EXT_framebuffer_object), ES1 | ES2 },
+ { "GL_OES_stencil_wrap", o(EXT_stencil_wrap), ES1 },
+ { "GL_OES_texture_3D", o(EXT_texture3D), ES2 },
+ { "GL_OES_texture_cube_map", o(ARB_texture_cube_map), ES1 },
+ { "GL_OES_texture_env_crossbar", o(ARB_texture_env_crossbar), ES1 },
+ { "GL_OES_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), ES1 },
+ { "GL_OES_texture_npot", o(ARB_texture_non_power_of_two), ES2 },
+
+ /* Vendor extensions */
+ { "GL_3DFX_texture_compression_FXT1", o(TDFX_texture_compression_FXT1), GL },
+ { "GL_AMD_conservative_depth", o(AMD_conservative_depth), GL },
+ { "GL_APPLE_client_storage", o(APPLE_client_storage), GL },
+ { "GL_APPLE_object_purgeable", o(APPLE_object_purgeable), GL },
+ { "GL_APPLE_packed_pixels", o(APPLE_packed_pixels), GL },
+ { "GL_APPLE_vertex_array_object", o(APPLE_vertex_array_object), GL },
+ { "GL_ATI_blend_equation_separate", o(EXT_blend_equation_separate), GL },
+ { "GL_ATI_envmap_bumpmap", o(ATI_envmap_bumpmap), GL },
+ { "GL_ATI_fragment_shader", o(ATI_fragment_shader), GL },
+ { "GL_ATI_separate_stencil", o(ATI_separate_stencil), GL },
+ { "GL_ATI_texture_env_combine3", o(ATI_texture_env_combine3), GL },
+ { "GL_ATI_texture_mirror_once", o(ATI_texture_mirror_once), GL },
+ { "GL_IBM_multimode_draw_arrays", o(IBM_multimode_draw_arrays), GL },
+ { "GL_IBM_rasterpos_clip", o(IBM_rasterpos_clip), GL },
+ { "GL_IBM_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL },
+ { "GL_INGR_blend_func_separate", o(EXT_blend_func_separate), GL },
+ { "GL_MESA_pack_invert", o(MESA_pack_invert), GL },
+ { "GL_MESA_resize_buffers", o(MESA_resize_buffers), GL },
+ { "GL_MESA_texture_array", o(MESA_texture_array), GL },
+ { "GL_MESA_texture_signed_rgba", o(MESA_texture_signed_rgba), GL },
+ { "GL_MESA_window_pos", o(ARB_window_pos), GL },
+ { "GL_MESAX_texture_float", o(ARB_texture_float), GL },
+ { "GL_MESA_ycbcr_texture", o(MESA_ycbcr_texture), GL },
+ { "GL_NV_blend_square", o(NV_blend_square), GL },
+ { "GL_NV_conditional_render", o(NV_conditional_render), GL },
+ { "GL_NV_depth_clamp", o(ARB_depth_clamp), GL },
+ { "GL_NV_fragment_program", o(NV_fragment_program), GL },
+ { "GL_NV_fragment_program_option", o(NV_fragment_program_option), GL },
+ { "GL_NV_light_max_exponent", o(NV_light_max_exponent), GL },
+ { "GL_NV_packed_depth_stencil", o(EXT_packed_depth_stencil), GL },
+ { "GL_NV_point_sprite", o(NV_point_sprite), GL },
+ { "GL_NV_primitive_restart", o(NV_primitive_restart), GL },
+ { "GL_NV_texgen_reflection", o(NV_texgen_reflection), GL },
+ { "GL_NV_texture_env_combine4", o(NV_texture_env_combine4), GL },
+ { "GL_NV_texture_rectangle", o(NV_texture_rectangle), GL },
+ { "GL_NV_vertex_program1_1", o(NV_vertex_program1_1), GL },
+ { "GL_NV_vertex_program", o(NV_vertex_program), GL },
+ { "GL_S3_s3tc", o(S3_s3tc), GL },
+ { "GL_SGIS_generate_mipmap", o(SGIS_generate_mipmap), GL },
+ { "GL_SGIS_texture_border_clamp", o(ARB_texture_border_clamp), GL },
+ { "GL_SGIS_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL },
+ { "GL_SGIS_texture_lod", o(SGIS_texture_lod), GL },
+ { "GL_SUN_multi_draw_arrays", o(EXT_multi_draw_arrays), GL },
+
+ { 0, 0, 0 },
+};
+
+
+/**
+ * Given an extension name, lookup up the corresponding member of struct
+ * gl_extensions and return that member's offset (in bytes). If the name is
+ * not found in the \c extension_table, return 0.
+ *
+ * \param name Name of extension.
+ * \return Offset of member in struct gl_extensions.
+ */
+static size_t
+name_to_offset(const char* name)
+{
+ const struct extension *i;
+
+ if (name == 0)
+ return 0;
+
+ for (i = extension_table; i->name != 0; ++i) {
+ if (strcmp(name, i->name) == 0)
+ return i->offset;
+ }
+
+ return 0;
+}
+
+
+/**
+ * \brief Extensions enabled by default.
+ *
+ * These extensions are enabled by _mesa_init_extensions().
+ *
+ * XXX: Should these defaults also apply to GLES?
+ */
+static const size_t default_extensions[] = {
+ o(ARB_copy_buffer),
+ o(ARB_draw_buffers),
+ o(ARB_multisample),
+ o(ARB_texture_compression),
+ o(ARB_transpose_matrix),
+ o(ARB_vertex_buffer_object),
+ o(ARB_window_pos),
+
+ o(EXT_abgr),
+ o(EXT_bgra),
+ o(EXT_compiled_vertex_array),
+ o(EXT_copy_texture),
+ o(EXT_draw_range_elements),
+ o(EXT_multi_draw_arrays),
+ o(EXT_packed_pixels),
+ o(EXT_polygon_offset),
+ o(EXT_rescale_normal),
+ o(EXT_separate_specular_color),
+ o(EXT_subtexture),
+ o(EXT_texture),
+ o(EXT_texture3D),
+ o(EXT_texture_object),
+ o(EXT_vertex_array),
+
+ o(OES_read_format),
+ o(OES_standard_derivatives),
+
+ /* Vendor Extensions */
+ o(APPLE_packed_pixels),
+ o(IBM_multimode_draw_arrays),
+ o(IBM_rasterpos_clip),
+ o(NV_light_max_exponent),
+ o(NV_texgen_reflection),
+ o(SGIS_generate_mipmap),
+ o(SGIS_texture_edge_clamp),
+ o(SGIS_texture_lod),
+
+ 0,
+};
+
+
+/**
+ * Enable all extensions suitable for a software-only renderer.
+ * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
+ */
+void
+_mesa_enable_sw_extensions(struct gl_context *ctx)
+{
+ /*ctx->Extensions.ARB_copy_buffer = GL_TRUE;*/
+ ctx->Extensions.ARB_depth_clamp = GL_TRUE;
+ ctx->Extensions.ARB_depth_texture = GL_TRUE;
+ /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
+ ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
+ ctx->Extensions.ARB_draw_instanced = GL_TRUE;
+ ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
+ ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
+#if FEATURE_ARB_fragment_program
+ ctx->Extensions.ARB_fragment_program = GL_TRUE;
+ ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
+#endif
+#if FEATURE_ARB_fragment_shader
+ ctx->Extensions.ARB_fragment_shader = GL_TRUE;
+#endif
+#if FEATURE_ARB_framebuffer_object
+ ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
+#endif
+#if FEATURE_ARB_geometry_shader4 && 0
+ /* XXX re-enable when GLSL compiler again supports geometry shaders */
+ ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
+#endif
+ ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
+ ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
+ ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
+ ctx->Extensions.ARB_multitexture = GL_TRUE;
+#if FEATURE_queryobj
+ ctx->Extensions.ARB_occlusion_query = GL_TRUE;
+ ctx->Extensions.ARB_occlusion_query2 = GL_TRUE;
+#endif
+ ctx->Extensions.ARB_point_sprite = GL_TRUE;
+#if FEATURE_ARB_shader_objects
+ ctx->Extensions.ARB_shader_objects = GL_TRUE;
+ ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
+#endif
+#if FEATURE_ARB_shading_language_100
+ ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
+#endif
+ ctx->Extensions.ARB_shadow = GL_TRUE;
+ ctx->Extensions.ARB_shadow_ambient = GL_TRUE;
+ ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
+ ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
+ ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
+ ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
+ ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
+ /*ctx->Extensions.ARB_texture_float = GL_TRUE;*/
+ ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
+ ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
+ ctx->Extensions.ARB_texture_rg = GL_TRUE;
+ ctx->Extensions.ARB_texture_compression_rgtc = GL_TRUE;
+ ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
+#if FEATURE_ARB_vertex_program
+ ctx->Extensions.ARB_vertex_program = GL_TRUE;
+#endif
+#if FEATURE_ARB_vertex_shader
+ ctx->Extensions.ARB_vertex_shader = GL_TRUE;
+#endif
+#if FEATURE_ARB_vertex_buffer_object
+ /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
+#endif
+#if FEATURE_ARB_sync
+ ctx->Extensions.ARB_sync = GL_TRUE;
+#endif
+ ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
+#if FEATURE_APPLE_object_purgeable
+ ctx->Extensions.APPLE_object_purgeable = GL_TRUE;
+#endif
+ ctx->Extensions.ATI_envmap_bumpmap = GL_TRUE;
+#if FEATURE_ATI_fragment_shader
+ ctx->Extensions.ATI_fragment_shader = GL_TRUE;
+#endif
+ ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
+ ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
+ ctx->Extensions.ATI_separate_stencil = GL_TRUE;
+ ctx->Extensions.EXT_blend_color = GL_TRUE;
+ ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
+ ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
+ ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
+ ctx->Extensions.EXT_blend_minmax = GL_TRUE;
+ ctx->Extensions.EXT_blend_subtract = GL_TRUE;
+ ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
+ ctx->Extensions.EXT_draw_buffers2 = GL_TRUE;
+ ctx->Extensions.EXT_fog_coord = GL_TRUE;
+#if FEATURE_EXT_framebuffer_object
+ ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
+#endif
+#if FEATURE_EXT_framebuffer_blit
+ ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
+#endif
+#if FEATURE_ARB_framebuffer_object
+ ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
+#endif
+ /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
+ ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
+ ctx->Extensions.EXT_paletted_texture = GL_TRUE;
+#if FEATURE_EXT_pixel_buffer_object
+ ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
+#endif
+ ctx->Extensions.EXT_point_parameters = GL_TRUE;
+ ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
+ ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
+ ctx->Extensions.EXT_secondary_color = GL_TRUE;
+ ctx->Extensions.EXT_shared_texture_palette = GL_TRUE;
+ ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
+ ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
+ ctx->Extensions.EXT_texture_array = GL_TRUE;
+ ctx->Extensions.EXT_texture_env_add = GL_TRUE;
+ ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
+ ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
+ ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
+ ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
+#if FEATURE_EXT_texture_sRGB
+ ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
+ ctx->Extensions.EXT_texture_sRGB_decode = GL_TRUE;
+#endif
+ ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
+#if FEATURE_EXT_transform_feedback
+ /*ctx->Extensions.EXT_transform_feedback = GL_TRUE;*/
+#endif
+ ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
+ /*ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;*/
+ ctx->Extensions.MESA_pack_invert = GL_TRUE;
+ ctx->Extensions.MESA_resize_buffers = GL_TRUE;
+ ctx->Extensions.MESA_texture_array = GL_TRUE;
+ ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
+ ctx->Extensions.NV_blend_square = GL_TRUE;
+ ctx->Extensions.NV_conditional_render = GL_TRUE;
+ /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
+ ctx->Extensions.NV_point_sprite = GL_TRUE;
+ ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
+ ctx->Extensions.NV_texture_rectangle = GL_TRUE;
+ /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
+#if FEATURE_NV_vertex_program
+ ctx->Extensions.NV_vertex_program = GL_TRUE;
+ ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
+#endif
+#if FEATURE_NV_fragment_program
+ ctx->Extensions.NV_fragment_program = GL_TRUE;
+#endif
+#if FEATURE_NV_fragment_program && FEATURE_ARB_fragment_program
+ ctx->Extensions.NV_fragment_program_option = GL_TRUE;
+#endif
+ /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
+ ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE;
+#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+ ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
+#endif
+#if FEATURE_texture_fxt1
+ _mesa_enable_extension(ctx, "GL_3DFX_texture_compression_FXT1");
+#endif
+#if FEATURE_texture_s3tc
+ if (ctx->Mesa_DXTn) {
+ _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
+ _mesa_enable_extension(ctx, "GL_S3_s3tc");
+ }
+#endif
+}
+
+
+/**
+ * Enable common EXT extensions in the ARB_imaging subset.
+ */
+void
+_mesa_enable_imaging_extensions(struct gl_context *ctx)
+{
+ ctx->Extensions.EXT_blend_color = GL_TRUE;
+ ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
+ ctx->Extensions.EXT_blend_minmax = GL_TRUE;
+ ctx->Extensions.EXT_blend_subtract = GL_TRUE;
+}
+
+
+
+/**
+ * Enable all OpenGL 1.3 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_1_3_extensions(struct gl_context *ctx)
+{
+ /*ctx->Extensions.ARB_multisample = GL_TRUE;*/
+ ctx->Extensions.ARB_multitexture = GL_TRUE;
+ ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
+ /*ctx->Extensions.ARB_texture_compression = GL_TRUE;*/
+ ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
+ ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
+ ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
+ ctx->Extensions.EXT_texture_env_add = GL_TRUE;
+ /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
+}
+
+
+
+/**
+ * Enable all OpenGL 1.4 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_1_4_extensions(struct gl_context *ctx)
+{
+ ctx->Extensions.ARB_depth_texture = GL_TRUE;
+ ctx->Extensions.ARB_shadow = GL_TRUE;
+ ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
+ ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
+ ctx->Extensions.ARB_window_pos = GL_TRUE;
+ ctx->Extensions.EXT_blend_color = GL_TRUE;
+ ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
+ ctx->Extensions.EXT_blend_minmax = GL_TRUE;
+ ctx->Extensions.EXT_blend_subtract = GL_TRUE;
+ ctx->Extensions.EXT_fog_coord = GL_TRUE;
+ /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
+ ctx->Extensions.EXT_point_parameters = GL_TRUE;
+ ctx->Extensions.EXT_secondary_color = GL_TRUE;
+ ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
+ ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
+ /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
+}
+
+
+/**
+ * Enable all OpenGL 1.5 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_1_5_extensions(struct gl_context *ctx)
+{
+ ctx->Extensions.ARB_occlusion_query = GL_TRUE;
+ /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
+ ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
+}
+
+
+/**
+ * Enable all OpenGL 2.0 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_2_0_extensions(struct gl_context *ctx)
+{
+ /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
+#if FEATURE_ARB_fragment_shader
+ ctx->Extensions.ARB_fragment_shader = GL_TRUE;
+#endif
+ ctx->Extensions.ARB_point_sprite = GL_TRUE;
+ ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
+ ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
+#if FEATURE_ARB_shader_objects
+ ctx->Extensions.ARB_shader_objects = GL_TRUE;
+#endif
+#if FEATURE_ARB_shading_language_100
+ ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
+#endif
+ ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
+#if FEATURE_ARB_vertex_shader
+ ctx->Extensions.ARB_vertex_shader = GL_TRUE;
+#endif
+}
+
+
+/**
+ * Enable all OpenGL 2.1 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_2_1_extensions(struct gl_context *ctx)
+{
+#if FEATURE_EXT_pixel_buffer_object
+ ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
+#endif
+#if FEATURE_EXT_texture_sRGB
+ ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
+#endif
+}
+
+
+/**
+ * Either enable or disable the named extension.
+ * \return GL_TRUE for success, GL_FALSE if invalid extension name
+ */
+static GLboolean
+set_extension( struct gl_context *ctx, const char *name, GLboolean state )
+{
+ size_t offset;
+
+ if (ctx->Extensions.String) {
+ /* The string was already queried - can't change it now! */
+ _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name);
+ return GL_FALSE;
+ }
+
+ offset = name_to_offset(name);
+ if (offset == 0) {
+ _mesa_problem(ctx, "Trying to enable/disable unknown extension %s",
+ name);
+ return GL_FALSE;
+ } else if (offset == o(dummy_true) && state == GL_FALSE) {
+ _mesa_problem(ctx, "Trying to disable a permanently enabled extension: "
+ "%s", name);
+ return GL_FALSE;
+ } else {
+ GLboolean *base = (GLboolean *) &ctx->Extensions;
+ base[offset] = state;
+ return GL_TRUE;
+ }
+}
+
+
+/**
+ * Enable the named extension.
+ * Typically called by drivers.
+ */
+void
+_mesa_enable_extension( struct gl_context *ctx, const char *name )
+{
+ if (!set_extension(ctx, name, GL_TRUE))
+ _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
+}
+
+
+/**
+ * Disable the named extension.
+ * XXX is this really needed???
+ */
+void
+_mesa_disable_extension( struct gl_context *ctx, const char *name )
+{
+ if (!set_extension(ctx, name, GL_FALSE))
+ _mesa_problem(ctx, "Trying to disable unknown extension: %s", name);
+}
+
+
+/**
+ * Test if the named extension is enabled in this context.
+ */
+GLboolean
+_mesa_extension_is_enabled( struct gl_context *ctx, const char *name )
+{
+ size_t offset;
+ GLboolean *base;
+
+ if (name == 0)
+ return GL_FALSE;
+
+ offset = name_to_offset(name);
+ if (offset == 0)
+ return GL_FALSE;
+ base = (GLboolean *) &ctx->Extensions;
+ return base[offset];
+}
+
+
+/**
+ * \brief Apply the \c MESA_EXTENSION_OVERRIDE environment variable.
+ *
+ * \c MESA_EXTENSION_OVERRIDE is a space-separated list of extensions to
+ * enable or disable. The list is processed thus:
+ * - Enable recognized extension names that are prefixed with '+'.
+ * - Disable recognized extension names that are prefixed with '-'.
+ * - Enable recognized extension names that are not prefixed.
+ * - Collect unrecognized extension names in a new string.
+ *
+ * \return Space-separated list of unrecognized extension names (which must
+ * be freed). Does not return \c NULL.
+ */
+static char *
+get_extension_override( struct gl_context *ctx )
+{
+ const char *env_const= _mesa_getenv("MESA_EXTENSION_OVERRIDE");
+ char *env;
+ char *ext;
+ char *extra_exts;
+ int len;
+
+ if (env_const == NULL) {
+ /* Return the empty string rather than NULL. This simplifies the logic
+ * of client functions. */
+ return calloc(1, sizeof(char));
+ }
+
+ /* extra_exts: List of unrecognized extensions. */
+ extra_exts = calloc(strlen(env_const), sizeof(char));
+
+ /* Copy env_const because strtok() is destructive. */
+ env = strdup(env_const);
+ for (ext = strtok(env, " "); ext != NULL; ext = strtok(NULL, " ")) {
+ int enable;
+ int recognized;
+ switch (ext[0]) {
+ case '+':
+ enable = 1;
+ ++ext;
+ break;
+ case '-':
+ enable = 0;
+ ++ext;
+ break;
+ default:
+ enable = 1;
+ break;
+ }
+ recognized = set_extension(ctx, ext, enable);
+ if (!recognized) {
+ strcat(extra_exts, ext);
+ strcat(extra_exts, " ");
+ }
+ }
+
+ /* Remove trailing space. */
+ len = strlen(extra_exts);
+ if (extra_exts[len - 1] == ' ')
+ extra_exts[len - 1] = '\0';
+
+ return extra_exts;
+}
+
+
+/**
+ * \brief Initialize extension tables and enable default extensions.
+ *
+ * This should be called during context initialization.
+ * Note: Sets gl_extensions.dummy_true to true.
+ */
+void
+_mesa_init_extensions( struct gl_context *ctx )
+{
+ GLboolean *base = (GLboolean *) &ctx->Extensions;
+ GLboolean *sentinel = base + o(extension_sentinel);
+ GLboolean *i;
+ const size_t *j;
+
+ /* First, turn all extensions off. */
+ for (i = base; i != sentinel; ++i)
+ *i = GL_FALSE;
+
+ /* Then, selectively turn default extensions on. */
+ ctx->Extensions.dummy_true = GL_TRUE;
+ for (j = default_extensions; *j != 0; ++j)
+ base[*j] = GL_TRUE;
+}
+
+
+/**
+ * Construct the GL_EXTENSIONS string. Called the first time that
+ * glGetString(GL_EXTENSIONS) is called.
+ */
+GLubyte*
+_mesa_make_extension_string(struct gl_context *ctx)
+{
+ /* The extension string. */
+ char *exts = 0;
+ /* Length of extension string. */
+ size_t length = 0;
+ /* String of extra extensions. */
+ char *extra_extensions = get_extension_override(ctx);
+ GLboolean *base = (GLboolean *) &ctx->Extensions;
+ const struct extension *i;
+
+ /* Compute length of the extension string. */
+ for (i = extension_table; i->name != 0; ++i) {
+ if (base[i->offset] && (i->api_set & (1 << ctx->API))) {
+ length += strlen(i->name) + 1; /* +1 for space */
+ }
+ }
+ if (extra_extensions != NULL)
+ length += 1 + strlen(extra_extensions); /* +1 for space */
+
+ exts = (char *) calloc(length + 1, sizeof(char));
+ if (exts == NULL) {
+ free(extra_extensions);
+ return NULL;
+ }
+
+ /* Build the extension string.*/
+ for (i = extension_table; i->name != 0; ++i) {
+ if (base[i->offset] && (i->api_set & (1 << ctx->API))) {
+ strcat(exts, i->name);
+ strcat(exts, " ");
+ }
+ }
+ if (extra_extensions != 0) {
+ strcat(exts, extra_extensions);
+ free(extra_extensions);
+ }
+
+ return (GLubyte *) exts;
+}
+
+/**
+ * Return number of enabled extensions.
+ */
+GLuint
+_mesa_get_extension_count(struct gl_context *ctx)
+{
+ GLboolean *base;
+ const struct extension *i;
+
+ /* only count once */
+ if (ctx->Extensions.Count != 0)
+ return ctx->Extensions.Count;
+
+ base = (GLboolean *) &ctx->Extensions;
+ for (i = extension_table; i->name != 0; ++i) {
+ if (base[i->offset]) {
+ ctx->Extensions.Count++;
+ }
+ }
+ return ctx->Extensions.Count;
+}
+
+/**
+ * Return name of i-th enabled extension
+ */
+const GLubyte *
+_mesa_get_enabled_extension(struct gl_context *ctx, GLuint index)
+{
+ const GLboolean *base;
+ size_t n;
+ const struct extension *i;
+
+ if (index < 0)
+ return NULL;
+
+ base = (GLboolean*) &ctx->Extensions;
+ n = 0;
+ for (i = extension_table; i->name != 0; ++i) {
+ if (n == index && base[i->offset]) {
+ return (GLubyte*) i->name;
+ } else if (base[i->offset]) {
+ ++n;
+ }
+ }
+
+ return NULL;
+}
diff --git a/mesalib/src/mesa/main/fbobject.c b/mesalib/src/mesa/main/fbobject.c
index c242e568d..7f26e0f97 100644
--- a/mesalib/src/mesa/main/fbobject.c
+++ b/mesalib/src/mesa/main/fbobject.c
@@ -1,2438 +1,2438 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/*
- * GL_EXT/ARB_framebuffer_object extensions
- *
- * Authors:
- * Brian Paul
- */
-
-
-#include "buffers.h"
-#include "context.h"
-#include "enums.h"
-#include "fbobject.h"
-#include "formats.h"
-#include "framebuffer.h"
-#include "hash.h"
-#include "macros.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "renderbuffer.h"
-#include "state.h"
-#include "teximage.h"
-#include "texobj.h"
-
-
-/** Set this to 1 to help debug FBO incompleteness problems */
-#define DEBUG_FBO 0
-
-/** Set this to 1 to debug/log glBlitFramebuffer() calls */
-#define DEBUG_BLIT 0
-
-
-/**
- * Notes:
- *
- * None of the GL_EXT_framebuffer_object functions are compiled into
- * display lists.
- */
-
-
-
-/*
- * When glGenRender/FramebuffersEXT() is called we insert pointers to
- * these placeholder objects into the hash table.
- * Later, when the object ID is first bound, we replace the placeholder
- * with the real frame/renderbuffer.
- */
-static struct gl_framebuffer DummyFramebuffer;
-static struct gl_renderbuffer DummyRenderbuffer;
-
-/* We bind this framebuffer when applications pass a NULL
- * drawable/surface in make current. */
-static struct gl_framebuffer IncompleteFramebuffer;
-
-
-#define IS_CUBE_FACE(TARGET) \
- ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
- (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
-
-
-static void
-delete_dummy_renderbuffer(struct gl_renderbuffer *rb)
-{
- /* no op */
-}
-
-static void
-delete_dummy_framebuffer(struct gl_framebuffer *fb)
-{
- /* no op */
-}
-
-
-void
-_mesa_init_fbobjects(struct gl_context *ctx)
-{
- _glthread_INIT_MUTEX(DummyFramebuffer.Mutex);
- _glthread_INIT_MUTEX(DummyRenderbuffer.Mutex);
- _glthread_INIT_MUTEX(IncompleteFramebuffer.Mutex);
- DummyFramebuffer.Delete = delete_dummy_framebuffer;
- DummyRenderbuffer.Delete = delete_dummy_renderbuffer;
- IncompleteFramebuffer.Delete = delete_dummy_framebuffer;
-}
-
-struct gl_framebuffer *
-_mesa_get_incomplete_framebuffer(void)
-{
- return &IncompleteFramebuffer;
-}
-
-/**
- * Helper routine for getting a gl_renderbuffer.
- */
-struct gl_renderbuffer *
-_mesa_lookup_renderbuffer(struct gl_context *ctx, GLuint id)
-{
- struct gl_renderbuffer *rb;
-
- if (id == 0)
- return NULL;
-
- rb = (struct gl_renderbuffer *)
- _mesa_HashLookup(ctx->Shared->RenderBuffers, id);
- return rb;
-}
-
-
-/**
- * Helper routine for getting a gl_framebuffer.
- */
-struct gl_framebuffer *
-_mesa_lookup_framebuffer(struct gl_context *ctx, GLuint id)
-{
- struct gl_framebuffer *fb;
-
- if (id == 0)
- return NULL;
-
- fb = (struct gl_framebuffer *)
- _mesa_HashLookup(ctx->Shared->FrameBuffers, id);
- return fb;
-}
-
-
-/**
- * Mark the given framebuffer as invalid. This will force the
- * test for framebuffer completeness to be done before the framebuffer
- * is used.
- */
-static void
-invalidate_framebuffer(struct gl_framebuffer *fb)
-{
- fb->_Status = 0; /* "indeterminate" */
-}
-
-
-/**
- * Return the gl_framebuffer object which corresponds to the given
- * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
- * Check support for GL_EXT_framebuffer_blit to determine if certain
- * targets are legal.
- * \return gl_framebuffer pointer or NULL if target is illegal
- */
-static struct gl_framebuffer *
-get_framebuffer_target(struct gl_context *ctx, GLenum target)
-{
- switch (target) {
- case GL_DRAW_FRAMEBUFFER:
- return ctx->Extensions.EXT_framebuffer_blit ? ctx->DrawBuffer : NULL;
- case GL_READ_FRAMEBUFFER:
- return ctx->Extensions.EXT_framebuffer_blit ? ctx->ReadBuffer : NULL;
- case GL_FRAMEBUFFER_EXT:
- return ctx->DrawBuffer;
- default:
- return NULL;
- }
-}
-
-
-/**
- * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
- * gl_renderbuffer_attachment object.
- * This function is only used for user-created FB objects, not the
- * default / window-system FB object.
- * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
- * the depth buffer attachment point.
- */
-struct gl_renderbuffer_attachment *
-_mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLenum attachment)
-{
- GLuint i;
-
- assert(fb->Name > 0);
-
- switch (attachment) {
- case GL_COLOR_ATTACHMENT0_EXT:
- case GL_COLOR_ATTACHMENT1_EXT:
- case GL_COLOR_ATTACHMENT2_EXT:
- case GL_COLOR_ATTACHMENT3_EXT:
- case GL_COLOR_ATTACHMENT4_EXT:
- case GL_COLOR_ATTACHMENT5_EXT:
- case GL_COLOR_ATTACHMENT6_EXT:
- case GL_COLOR_ATTACHMENT7_EXT:
- case GL_COLOR_ATTACHMENT8_EXT:
- case GL_COLOR_ATTACHMENT9_EXT:
- case GL_COLOR_ATTACHMENT10_EXT:
- case GL_COLOR_ATTACHMENT11_EXT:
- case GL_COLOR_ATTACHMENT12_EXT:
- case GL_COLOR_ATTACHMENT13_EXT:
- case GL_COLOR_ATTACHMENT14_EXT:
- case GL_COLOR_ATTACHMENT15_EXT:
- i = attachment - GL_COLOR_ATTACHMENT0_EXT;
- if (i >= ctx->Const.MaxColorAttachments) {
- return NULL;
- }
- return &fb->Attachment[BUFFER_COLOR0 + i];
- case GL_DEPTH_STENCIL_ATTACHMENT:
- /* fall-through */
- case GL_DEPTH_BUFFER:
- /* fall-through / new in GL 3.0 */
- case GL_DEPTH_ATTACHMENT_EXT:
- return &fb->Attachment[BUFFER_DEPTH];
- case GL_STENCIL_BUFFER:
- /* fall-through / new in GL 3.0 */
- case GL_STENCIL_ATTACHMENT_EXT:
- return &fb->Attachment[BUFFER_STENCIL];
- default:
- return NULL;
- }
-}
-
-
-/**
- * As above, but only used for getting attachments of the default /
- * window-system framebuffer (not user-created framebuffer objects).
- */
-static struct gl_renderbuffer_attachment *
-_mesa_get_fb0_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLenum attachment)
-{
- assert(fb->Name == 0);
-
- switch (attachment) {
- case GL_FRONT_LEFT:
- return &fb->Attachment[BUFFER_FRONT_LEFT];
- case GL_FRONT_RIGHT:
- return &fb->Attachment[BUFFER_FRONT_RIGHT];
- case GL_BACK_LEFT:
- return &fb->Attachment[BUFFER_BACK_LEFT];
- case GL_BACK_RIGHT:
- return &fb->Attachment[BUFFER_BACK_RIGHT];
- case GL_AUX0:
- if (fb->Visual.numAuxBuffers == 1) {
- return &fb->Attachment[BUFFER_AUX0];
- }
- return NULL;
- case GL_DEPTH_BUFFER:
- /* fall-through / new in GL 3.0 */
- case GL_DEPTH_ATTACHMENT_EXT:
- return &fb->Attachment[BUFFER_DEPTH];
- case GL_STENCIL_BUFFER:
- /* fall-through / new in GL 3.0 */
- case GL_STENCIL_ATTACHMENT_EXT:
- return &fb->Attachment[BUFFER_STENCIL];
- default:
- return NULL;
- }
-}
-
-
-
-/**
- * Remove any texture or renderbuffer attached to the given attachment
- * point. Update reference counts, etc.
- */
-void
-_mesa_remove_attachment(struct gl_context *ctx,
- struct gl_renderbuffer_attachment *att)
-{
- if (att->Type == GL_TEXTURE) {
- ASSERT(att->Texture);
- if (ctx->Driver.FinishRenderTexture) {
- /* tell driver that we're done rendering to this texture. */
- ctx->Driver.FinishRenderTexture(ctx, att);
- }
- _mesa_reference_texobj(&att->Texture, NULL); /* unbind */
- ASSERT(!att->Texture);
- }
- if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) {
- ASSERT(!att->Texture);
- _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */
- ASSERT(!att->Renderbuffer);
- }
- att->Type = GL_NONE;
- att->Complete = GL_TRUE;
-}
-
-
-/**
- * Bind a texture object to an attachment point.
- * The previous binding, if any, will be removed first.
- */
-void
-_mesa_set_texture_attachment(struct gl_context *ctx,
- struct gl_framebuffer *fb,
- struct gl_renderbuffer_attachment *att,
- struct gl_texture_object *texObj,
- GLenum texTarget, GLuint level, GLuint zoffset)
-{
- if (att->Texture == texObj) {
- /* re-attaching same texture */
- ASSERT(att->Type == GL_TEXTURE);
- if (ctx->Driver.FinishRenderTexture)
- ctx->Driver.FinishRenderTexture(ctx, att);
- }
- else {
- /* new attachment */
- if (ctx->Driver.FinishRenderTexture && att->Texture)
- ctx->Driver.FinishRenderTexture(ctx, att);
- _mesa_remove_attachment(ctx, att);
- att->Type = GL_TEXTURE;
- assert(!att->Texture);
- _mesa_reference_texobj(&att->Texture, texObj);
- }
-
- /* always update these fields */
- att->TextureLevel = level;
- att->CubeMapFace = _mesa_tex_target_to_face(texTarget);
- att->Zoffset = zoffset;
- att->Complete = GL_FALSE;
-
- if (att->Texture->Image[att->CubeMapFace][att->TextureLevel]) {
- ctx->Driver.RenderTexture(ctx, fb, att);
- }
-
- invalidate_framebuffer(fb);
-}
-
-
-/**
- * Bind a renderbuffer to an attachment point.
- * The previous binding, if any, will be removed first.
- */
-void
-_mesa_set_renderbuffer_attachment(struct gl_context *ctx,
- struct gl_renderbuffer_attachment *att,
- struct gl_renderbuffer *rb)
-{
- /* XXX check if re-doing same attachment, exit early */
- _mesa_remove_attachment(ctx, att);
- att->Type = GL_RENDERBUFFER_EXT;
- att->Texture = NULL; /* just to be safe */
- att->Complete = GL_FALSE;
- _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
-}
-
-
-/**
- * Fallback for ctx->Driver.FramebufferRenderbuffer()
- * Attach a renderbuffer object to a framebuffer object.
- */
-void
-_mesa_framebuffer_renderbuffer(struct gl_context *ctx,
- struct gl_framebuffer *fb,
- GLenum attachment, struct gl_renderbuffer *rb)
-{
- struct gl_renderbuffer_attachment *att;
-
- _glthread_LOCK_MUTEX(fb->Mutex);
-
- att = _mesa_get_attachment(ctx, fb, attachment);
- ASSERT(att);
- if (rb) {
- _mesa_set_renderbuffer_attachment(ctx, att, rb);
- if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
- /* do stencil attachment here (depth already done above) */
- att = _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
- assert(att);
- _mesa_set_renderbuffer_attachment(ctx, att, rb);
- }
- }
- else {
- _mesa_remove_attachment(ctx, att);
- }
-
- invalidate_framebuffer(fb);
-
- _glthread_UNLOCK_MUTEX(fb->Mutex);
-}
-
-
-/**
- * Fallback for ctx->Driver.ValidateFramebuffer()
- * Check if the renderbuffer's formats are supported by the software
- * renderer.
- * Drivers should probably override this.
- */
-void
-_mesa_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
- gl_buffer_index buf;
- for (buf = 0; buf < BUFFER_COUNT; buf++) {
- const struct gl_renderbuffer *rb = fb->Attachment[buf].Renderbuffer;
- if (rb) {
- switch (rb->_BaseFormat) {
- case GL_ALPHA:
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE:
- case GL_INTENSITY:
- case GL_RED:
- case GL_RG:
- fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
- return;
- default:
- /* render buffer format is supported by software rendering */
- ;
- }
- }
- }
-}
-
-
-/**
- * For debug only.
- */
-static void
-att_incomplete(const char *msg)
-{
-#if DEBUG_FBO
- _mesa_debug(NULL, "attachment incomplete: %s\n", msg);
-#else
- (void) msg;
-#endif
-}
-
-
-/**
- * For debug only.
- */
-static void
-fbo_incomplete(const char *msg, int index)
-{
-#if DEBUG_FBO
- _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
-#else
- (void) msg;
- (void) index;
-#endif
-}
-
-
-/**
- * Is the given base format a legal format for a color renderbuffer?
- */
-GLboolean
-_mesa_is_legal_color_format(const struct gl_context *ctx, GLenum baseFormat)
-{
- switch (baseFormat) {
- case GL_RGB:
- case GL_RGBA:
- return GL_TRUE;
- case GL_LUMINANCE:
- case GL_LUMINANCE_ALPHA:
- case GL_INTENSITY:
- case GL_ALPHA:
- return ctx->Extensions.ARB_framebuffer_object;
- case GL_RED:
- case GL_RG:
- return ctx->Extensions.ARB_texture_rg;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Is the given base format a legal format for a depth/stencil renderbuffer?
- */
-static GLboolean
-is_legal_depth_format(const struct gl_context *ctx, GLenum baseFormat)
-{
- switch (baseFormat) {
- case GL_DEPTH_COMPONENT:
- case GL_DEPTH_STENCIL_EXT:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test if an attachment point is complete and update its Complete field.
- * \param format if GL_COLOR, this is a color attachment point,
- * if GL_DEPTH, this is a depth component attachment point,
- * if GL_STENCIL, this is a stencil component attachment point.
- */
-static void
-test_attachment_completeness(const struct gl_context *ctx, GLenum format,
- struct gl_renderbuffer_attachment *att)
-{
- assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL);
-
- /* assume complete */
- att->Complete = GL_TRUE;
-
- /* Look for reasons why the attachment might be incomplete */
- if (att->Type == GL_TEXTURE) {
- const struct gl_texture_object *texObj = att->Texture;
- struct gl_texture_image *texImage;
- GLenum baseFormat;
-
- if (!texObj) {
- att_incomplete("no texobj");
- att->Complete = GL_FALSE;
- return;
- }
-
- texImage = texObj->Image[att->CubeMapFace][att->TextureLevel];
- if (!texImage) {
- att_incomplete("no teximage");
- att->Complete = GL_FALSE;
- return;
- }
- if (texImage->Width < 1 || texImage->Height < 1) {
- att_incomplete("teximage width/height=0");
- printf("texobj = %u\n", texObj->Name);
- printf("level = %d\n", att->TextureLevel);
- att->Complete = GL_FALSE;
- return;
- }
- if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) {
- att_incomplete("bad z offset");
- att->Complete = GL_FALSE;
- return;
- }
-
- baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
-
- if (format == GL_COLOR) {
- if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
- att_incomplete("bad format");
- att->Complete = GL_FALSE;
- return;
- }
- if (_mesa_is_format_compressed(texImage->TexFormat)) {
- att_incomplete("compressed internalformat");
- att->Complete = GL_FALSE;
- return;
- }
- }
- else if (format == GL_DEPTH) {
- if (baseFormat == GL_DEPTH_COMPONENT) {
- /* OK */
- }
- else if (ctx->Extensions.EXT_packed_depth_stencil &&
- ctx->Extensions.ARB_depth_texture &&
- baseFormat == GL_DEPTH_STENCIL_EXT) {
- /* OK */
- }
- else {
- att->Complete = GL_FALSE;
- att_incomplete("bad depth format");
- return;
- }
- }
- else {
- ASSERT(format == GL_STENCIL);
- if (ctx->Extensions.EXT_packed_depth_stencil &&
- ctx->Extensions.ARB_depth_texture &&
- baseFormat == GL_DEPTH_STENCIL_EXT) {
- /* OK */
- }
- else {
- /* no such thing as stencil-only textures */
- att_incomplete("illegal stencil texture");
- att->Complete = GL_FALSE;
- return;
- }
- }
- }
- else if (att->Type == GL_RENDERBUFFER_EXT) {
- const GLenum baseFormat =
- _mesa_get_format_base_format(att->Renderbuffer->Format);
-
- ASSERT(att->Renderbuffer);
- if (!att->Renderbuffer->InternalFormat ||
- att->Renderbuffer->Width < 1 ||
- att->Renderbuffer->Height < 1) {
- att_incomplete("0x0 renderbuffer");
- att->Complete = GL_FALSE;
- return;
- }
- if (format == GL_COLOR) {
- if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
- att_incomplete("bad renderbuffer color format");
- att->Complete = GL_FALSE;
- return;
- }
- }
- else if (format == GL_DEPTH) {
- if (baseFormat == GL_DEPTH_COMPONENT) {
- /* OK */
- }
- else if (ctx->Extensions.EXT_packed_depth_stencil &&
- baseFormat == GL_DEPTH_STENCIL_EXT) {
- /* OK */
- }
- else {
- att_incomplete("bad renderbuffer depth format");
- att->Complete = GL_FALSE;
- return;
- }
- }
- else {
- assert(format == GL_STENCIL);
- if (baseFormat == GL_STENCIL_INDEX) {
- /* OK */
- }
- else if (ctx->Extensions.EXT_packed_depth_stencil &&
- baseFormat == GL_DEPTH_STENCIL_EXT) {
- /* OK */
- }
- else {
- att->Complete = GL_FALSE;
- att_incomplete("bad renderbuffer stencil format");
- return;
- }
- }
- }
- else {
- ASSERT(att->Type == GL_NONE);
- /* complete */
- return;
- }
-}
-
-
-/**
- * Test if the given framebuffer object is complete and update its
- * Status field with the results.
- * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
- * driver to make hardware-specific validation/completeness checks.
- * Also update the framebuffer's Width and Height fields if the
- * framebuffer is complete.
- */
-void
-_mesa_test_framebuffer_completeness(struct gl_context *ctx,
- struct gl_framebuffer *fb)
-{
- GLuint numImages;
- GLenum intFormat = GL_NONE; /* color buffers' internal format */
- GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0;
- GLint numSamples = -1;
- GLint i;
- GLuint j;
-
- assert(fb->Name != 0);
-
- numImages = 0;
- fb->Width = 0;
- fb->Height = 0;
-
- /* Start at -2 to more easily loop over all attachment points.
- * -2: depth buffer
- * -1: stencil buffer
- * >=0: color buffer
- */
- for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) {
- struct gl_renderbuffer_attachment *att;
- GLenum f;
- gl_format attFormat;
-
- /*
- * XXX for ARB_fbo, only check color buffers that are named by
- * GL_READ_BUFFER and GL_DRAW_BUFFERi.
- */
-
- /* check for attachment completeness
- */
- if (i == -2) {
- att = &fb->Attachment[BUFFER_DEPTH];
- test_attachment_completeness(ctx, GL_DEPTH, att);
- if (!att->Complete) {
- fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
- fbo_incomplete("depth attachment incomplete", -1);
- return;
- }
- }
- else if (i == -1) {
- att = &fb->Attachment[BUFFER_STENCIL];
- test_attachment_completeness(ctx, GL_STENCIL, att);
- if (!att->Complete) {
- fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
- fbo_incomplete("stencil attachment incomplete", -1);
- return;
- }
- }
- else {
- att = &fb->Attachment[BUFFER_COLOR0 + i];
- test_attachment_completeness(ctx, GL_COLOR, att);
- if (!att->Complete) {
- fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
- fbo_incomplete("color attachment incomplete", i);
- return;
- }
- }
-
- /* get width, height, format of the renderbuffer/texture
- */
- if (att->Type == GL_TEXTURE) {
- const struct gl_texture_image *texImg
- = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
- minWidth = MIN2(minWidth, texImg->Width);
- maxWidth = MAX2(maxWidth, texImg->Width);
- minHeight = MIN2(minHeight, texImg->Height);
- maxHeight = MAX2(maxHeight, texImg->Height);
- f = texImg->_BaseFormat;
- attFormat = texImg->TexFormat;
- numImages++;
- if (!_mesa_is_legal_color_format(ctx, f) &&
- !is_legal_depth_format(ctx, f)) {
- fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
- fbo_incomplete("texture attachment incomplete", -1);
- return;
- }
- }
- else if (att->Type == GL_RENDERBUFFER_EXT) {
- minWidth = MIN2(minWidth, att->Renderbuffer->Width);
- maxWidth = MAX2(minWidth, att->Renderbuffer->Width);
- minHeight = MIN2(minHeight, att->Renderbuffer->Height);
- maxHeight = MAX2(minHeight, att->Renderbuffer->Height);
- f = att->Renderbuffer->InternalFormat;
- attFormat = att->Renderbuffer->Format;
- numImages++;
- }
- else {
- assert(att->Type == GL_NONE);
- continue;
- }
-
- if (numSamples < 0) {
- /* first buffer */
- numSamples = att->Renderbuffer->NumSamples;
- }
-
- /* check if integer color */
- fb->_IntegerColor = _mesa_is_format_integer_color(attFormat);
-
- /* Error-check width, height, format, samples
- */
- if (numImages == 1) {
- /* save format, num samples */
- if (i >= 0) {
- intFormat = f;
- }
- }
- else {
- if (!ctx->Extensions.ARB_framebuffer_object) {
- /* check that width, height, format are same */
- if (minWidth != maxWidth || minHeight != maxHeight) {
- fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
- fbo_incomplete("width or height mismatch", -1);
- return;
- }
- /* check that all color buffer have same format */
- if (intFormat != GL_NONE && f != intFormat) {
- fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
- fbo_incomplete("format mismatch", -1);
- return;
- }
- }
- if (att->Renderbuffer &&
- att->Renderbuffer->NumSamples != numSamples) {
- fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
- fbo_incomplete("inconsistant number of samples", i);
- return;
- }
-
- }
- }
-
-#if FEATURE_GL
- if (ctx->API == API_OPENGL) {
- /* Check that all DrawBuffers are present */
- for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) {
- if (fb->ColorDrawBuffer[j] != GL_NONE) {
- const struct gl_renderbuffer_attachment *att
- = _mesa_get_attachment(ctx, fb, fb->ColorDrawBuffer[j]);
- assert(att);
- if (att->Type == GL_NONE) {
- fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT;
- fbo_incomplete("missing drawbuffer", j);
- return;
- }
- }
- }
-
- /* Check that the ReadBuffer is present */
- if (fb->ColorReadBuffer != GL_NONE) {
- const struct gl_renderbuffer_attachment *att
- = _mesa_get_attachment(ctx, fb, fb->ColorReadBuffer);
- assert(att);
- if (att->Type == GL_NONE) {
- fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT;
- fbo_incomplete("missing readbuffer", -1);
- return;
- }
- }
- }
-#else
- (void) j;
-#endif
-
- if (numImages == 0) {
- fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT;
- fbo_incomplete("no attachments", -1);
- return;
- }
-
- /* Provisionally set status = COMPLETE ... */
- fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
-
- /* ... but the driver may say the FB is incomplete.
- * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
- * if anything.
- */
- if (ctx->Driver.ValidateFramebuffer) {
- ctx->Driver.ValidateFramebuffer(ctx, fb);
- if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- fbo_incomplete("driver marked FBO as incomplete", -1);
- }
- }
-
- if (fb->_Status == GL_FRAMEBUFFER_COMPLETE_EXT) {
- /*
- * Note that if ARB_framebuffer_object is supported and the attached
- * renderbuffers/textures are different sizes, the framebuffer
- * width/height will be set to the smallest width/height.
- */
- fb->Width = minWidth;
- fb->Height = minHeight;
-
- /* finally, update the visual info for the framebuffer */
- _mesa_update_framebuffer_visual(ctx, fb);
- }
-}
-
-
-GLboolean GLAPIENTRY
-_mesa_IsRenderbufferEXT(GLuint renderbuffer)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
- if (renderbuffer) {
- struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
- if (rb != NULL && rb != &DummyRenderbuffer)
- return GL_TRUE;
- }
- return GL_FALSE;
-}
-
-
-void GLAPIENTRY
-_mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
-{
- struct gl_renderbuffer *newRb;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (target != GL_RENDERBUFFER_EXT) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)");
- return;
- }
-
- /* No need to flush here since the render buffer binding has no
- * effect on rendering state.
- */
-
- if (renderbuffer) {
- newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
- if (newRb == &DummyRenderbuffer) {
- /* ID was reserved, but no real renderbuffer object made yet */
- newRb = NULL;
- }
- else if (!newRb && ctx->Extensions.ARB_framebuffer_object) {
- /* All RB IDs must be Gen'd */
- _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)");
- return;
- }
-
- if (!newRb) {
- /* create new renderbuffer object */
- newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer);
- if (!newRb) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT");
- return;
- }
- ASSERT(newRb->AllocStorage);
- _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb);
- newRb->RefCount = 1; /* referenced by hash table */
- }
- }
- else {
- newRb = NULL;
- }
-
- ASSERT(newRb != &DummyRenderbuffer);
-
- _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb);
-}
-
-
-/**
- * If the given renderbuffer is anywhere attached to the framebuffer, detach
- * the renderbuffer.
- * This is used when a renderbuffer object is deleted.
- * The spec calls for unbinding.
- */
-static void
-detach_renderbuffer(struct gl_context *ctx,
- struct gl_framebuffer *fb,
- struct gl_renderbuffer *rb)
-{
- GLuint i;
- for (i = 0; i < BUFFER_COUNT; i++) {
- if (fb->Attachment[i].Renderbuffer == rb) {
- _mesa_remove_attachment(ctx, &fb->Attachment[i]);
- }
- }
- invalidate_framebuffer(fb);
-}
-
-
-void GLAPIENTRY
-_mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers)
-{
- GLint i;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
- for (i = 0; i < n; i++) {
- if (renderbuffers[i] > 0) {
- struct gl_renderbuffer *rb;
- rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]);
- if (rb) {
- /* check if deleting currently bound renderbuffer object */
- if (rb == ctx->CurrentRenderbuffer) {
- /* bind default */
- ASSERT(rb->RefCount >= 2);
- _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
- }
-
- if (ctx->DrawBuffer->Name) {
- detach_renderbuffer(ctx, ctx->DrawBuffer, rb);
- }
- if (ctx->ReadBuffer->Name && ctx->ReadBuffer != ctx->DrawBuffer) {
- detach_renderbuffer(ctx, ctx->ReadBuffer, rb);
- }
-
- /* Remove from hash table immediately, to free the ID.
- * But the object will not be freed until it's no longer
- * referenced anywhere else.
- */
- _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]);
-
- if (rb != &DummyRenderbuffer) {
- /* no longer referenced by hash table */
- _mesa_reference_renderbuffer(&rb, NULL);
- }
- }
- }
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint first;
- GLint i;
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (n < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGenRenderbuffersEXT(n)");
- return;
- }
-
- if (!renderbuffers)
- return;
-
- first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n);
-
- for (i = 0; i < n; i++) {
- GLuint name = first + i;
- renderbuffers[i] = name;
- /* insert dummy placeholder into hash table */
- _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
- _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer);
- _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
- }
-}
-
-
-/**
- * Given an internal format token for a render buffer, return the
- * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
- * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
- * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
- *
- * This is similar to _mesa_base_tex_format() but the set of valid
- * internal formats is different.
- *
- * Note that even if a format is determined to be legal here, validation
- * of the FBO may fail if the format is not supported by the driver/GPU.
- *
- * \param internalFormat as passed to glRenderbufferStorage()
- * \return the base internal format, or 0 if internalFormat is illegal
- */
-GLenum
-_mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat)
-{
- /*
- * Notes: some formats such as alpha, luminance, etc. were added
- * with GL_ARB_framebuffer_object.
- */
- switch (internalFormat) {
- case GL_ALPHA:
- case GL_ALPHA4:
- case GL_ALPHA8:
- case GL_ALPHA12:
- case GL_ALPHA16:
- return ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
- case GL_LUMINANCE:
- case GL_LUMINANCE4:
- case GL_LUMINANCE8:
- case GL_LUMINANCE12:
- case GL_LUMINANCE16:
- return ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE4_ALPHA4:
- case GL_LUMINANCE6_ALPHA2:
- case GL_LUMINANCE8_ALPHA8:
- case GL_LUMINANCE12_ALPHA4:
- case GL_LUMINANCE12_ALPHA12:
- case GL_LUMINANCE16_ALPHA16:
- return ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
- case GL_INTENSITY:
- case GL_INTENSITY4:
- case GL_INTENSITY8:
- case GL_INTENSITY12:
- case GL_INTENSITY16:
- return ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
- case GL_RGB:
- case GL_R3_G3_B2:
- case GL_RGB4:
- case GL_RGB5:
- case GL_RGB8:
- case GL_RGB10:
- case GL_RGB12:
- case GL_RGB16:
- case GL_SRGB8_EXT:
- return GL_RGB;
- case GL_RGBA:
- case GL_RGBA2:
- case GL_RGBA4:
- case GL_RGB5_A1:
- case GL_RGBA8:
- case GL_RGB10_A2:
- case GL_RGBA12:
- case GL_RGBA16:
- case GL_RGBA16_SNORM:
- case GL_SRGB8_ALPHA8_EXT:
- return GL_RGBA;
- case GL_STENCIL_INDEX:
- case GL_STENCIL_INDEX1_EXT:
- case GL_STENCIL_INDEX4_EXT:
- case GL_STENCIL_INDEX8_EXT:
- case GL_STENCIL_INDEX16_EXT:
- return GL_STENCIL_INDEX;
- case GL_DEPTH_COMPONENT:
- case GL_DEPTH_COMPONENT16:
- case GL_DEPTH_COMPONENT24:
- case GL_DEPTH_COMPONENT32:
- return GL_DEPTH_COMPONENT;
- case GL_DEPTH_STENCIL_EXT:
- case GL_DEPTH24_STENCIL8_EXT:
- if (ctx->Extensions.EXT_packed_depth_stencil)
- return GL_DEPTH_STENCIL_EXT;
- else
- return 0;
- case GL_RED:
- case GL_R8:
- case GL_R16:
- return ctx->Extensions.ARB_texture_rg ? GL_RED : 0;
- case GL_RG:
- case GL_RG8:
- case GL_RG16:
- return ctx->Extensions.ARB_texture_rg ? GL_RG : 0;
- /* XXX add floating point and integer formats eventually */
- default:
- return 0;
- }
-}
-
-
-/** sentinal value, see below */
-#define NO_SAMPLES 1000
-
-
-/**
- * Helper function used by _mesa_RenderbufferStorageEXT() and
- * _mesa_RenderbufferStorageMultisample().
- * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
- */
-static void
-renderbuffer_storage(GLenum target, GLenum internalFormat,
- GLsizei width, GLsizei height, GLsizei samples)
-{
- const char *func = samples == NO_SAMPLES ?
- "glRenderbufferStorage" : "RenderbufferStorageMultisample";
- struct gl_renderbuffer *rb;
- GLenum baseFormat;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (target != GL_RENDERBUFFER_EXT) {
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
- return;
- }
-
- baseFormat = _mesa_base_fbo_format(ctx, internalFormat);
- if (baseFormat == 0) {
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat)", func);
- return;
- }
-
- if (width < 1 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(width)", func);
- return;
- }
-
- if (height < 1 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(height)", func);
- return;
- }
-
- if (samples == NO_SAMPLES) {
- /* NumSamples == 0 indicates non-multisampling */
- samples = 0;
- }
- else if (samples > (GLsizei) ctx->Const.MaxSamples) {
- /* note: driver may choose to use more samples than what's requested */
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(samples)", func);
- return;
- }
-
- rb = ctx->CurrentRenderbuffer;
- if (!rb) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
- return;
- }
-
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
- if (rb->InternalFormat == internalFormat &&
- rb->Width == (GLuint) width &&
- rb->Height == (GLuint) height) {
- /* no change in allocation needed */
- return;
- }
-
- /* These MUST get set by the AllocStorage func */
- rb->Format = MESA_FORMAT_NONE;
- rb->NumSamples = samples;
-
- /* Now allocate the storage */
- ASSERT(rb->AllocStorage);
- if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) {
- /* No error - check/set fields now */
- assert(rb->Format != MESA_FORMAT_NONE);
- assert(rb->Width == (GLuint) width);
- assert(rb->Height == (GLuint) height);
- rb->InternalFormat = internalFormat;
- rb->_BaseFormat = baseFormat;
- assert(rb->_BaseFormat != 0);
- }
- else {
- /* Probably ran out of memory - clear the fields */
- rb->Width = 0;
- rb->Height = 0;
- rb->Format = MESA_FORMAT_NONE;
- rb->InternalFormat = GL_NONE;
- rb->_BaseFormat = GL_NONE;
- rb->NumSamples = 0;
- }
-
- /*
- test_framebuffer_completeness(ctx, fb);
- */
- /* XXX if this renderbuffer is attached anywhere, invalidate attachment
- * points???
- */
-}
-
-
-#if FEATURE_OES_EGL_image
-void GLAPIENTRY
-_mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
-{
- struct gl_renderbuffer *rb;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (!ctx->Extensions.OES_EGL_image) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glEGLImageTargetRenderbufferStorageOES(unsupported)");
- return;
- }
-
- if (target != GL_RENDERBUFFER) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "EGLImageTargetRenderbufferStorageOES");
- return;
- }
-
- rb = ctx->CurrentRenderbuffer;
- if (!rb) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "EGLImageTargetRenderbufferStorageOES");
- return;
- }
-
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
- ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image);
-}
-#endif
-
-
-/**
- * Helper function for _mesa_GetRenderbufferParameterivEXT() and
- * _mesa_GetFramebufferAttachmentParameterivEXT()
- * We have to be careful to respect the base format. For example, if a
- * renderbuffer/texture was created with internalFormat=GL_RGB but the
- * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
- * we need to return zero.
- */
-static GLint
-get_component_bits(GLenum pname, GLenum baseFormat, gl_format format)
-{
- switch (pname) {
- case GL_RENDERBUFFER_RED_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
- if (baseFormat == GL_RGB || baseFormat == GL_RGBA ||
- baseFormat == GL_RG || baseFormat == GL_RED)
- return _mesa_get_format_bits(format, pname);
- else
- return 0;
- case GL_RENDERBUFFER_GREEN_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
- if (baseFormat == GL_RGB || baseFormat == GL_RGBA || baseFormat == GL_RG)
- return _mesa_get_format_bits(format, pname);
- else
- return 0;
- case GL_RENDERBUFFER_BLUE_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
- if (baseFormat == GL_RGB || baseFormat == GL_RGBA)
- return _mesa_get_format_bits(format, pname);
- else
- return 0;
- case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
- if (baseFormat == GL_RGBA || baseFormat == GL_ALPHA ||
- baseFormat == GL_LUMINANCE_ALPHA)
- return _mesa_get_format_bits(format, pname);
- else
- return 0;
- case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
- if (baseFormat == GL_DEPTH_COMPONENT || baseFormat == GL_DEPTH_STENCIL)
- return _mesa_get_format_bits(format, pname);
- else
- return 0;
- case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
- if (baseFormat == GL_STENCIL_INDEX || baseFormat == GL_DEPTH_STENCIL)
- return _mesa_get_format_bits(format, pname);
- else
- return 0;
- default:
- return 0;
- }
-}
-
-
-
-void GLAPIENTRY
-_mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
- GLsizei width, GLsizei height)
-{
- /* GL_ARB_fbo says calling this function is equivalent to calling
- * glRenderbufferStorageMultisample() with samples=0. We pass in
- * a token value here just for error reporting purposes.
- */
- renderbuffer_storage(target, internalFormat, width, height, NO_SAMPLES);
-}
-
-
-void GLAPIENTRY
-_mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples,
- GLenum internalFormat,
- GLsizei width, GLsizei height)
-{
- renderbuffer_storage(target, internalFormat, width, height, samples);
-}
-
-
-/**
- * OpenGL ES version of glRenderBufferStorage.
- */
-void GLAPIENTRY
-_es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
- GLsizei width, GLsizei height)
-{
- switch (internalFormat) {
- case GL_RGB565:
- /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
- /* choose a closest format */
- internalFormat = GL_RGB5;
- break;
- default:
- break;
- }
-
- renderbuffer_storage(target, internalFormat, width, height, 0);
-}
-
-
-void GLAPIENTRY
-_mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params)
-{
- struct gl_renderbuffer *rb;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (target != GL_RENDERBUFFER_EXT) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetRenderbufferParameterivEXT(target)");
- return;
- }
-
- rb = ctx->CurrentRenderbuffer;
- if (!rb) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetRenderbufferParameterivEXT");
- return;
- }
-
- /* No need to flush here since we're just quering state which is
- * not effected by rendering.
- */
-
- switch (pname) {
- case GL_RENDERBUFFER_WIDTH_EXT:
- *params = rb->Width;
- return;
- case GL_RENDERBUFFER_HEIGHT_EXT:
- *params = rb->Height;
- return;
- case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT:
- *params = rb->InternalFormat;
- return;
- case GL_RENDERBUFFER_RED_SIZE_EXT:
- case GL_RENDERBUFFER_GREEN_SIZE_EXT:
- case GL_RENDERBUFFER_BLUE_SIZE_EXT:
- case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
- case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
- case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
- *params = get_component_bits(pname, rb->_BaseFormat, rb->Format);
- break;
- case GL_RENDERBUFFER_SAMPLES:
- if (ctx->Extensions.ARB_framebuffer_object) {
- *params = rb->NumSamples;
- break;
- }
- /* fallthrough */
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetRenderbufferParameterivEXT(target)");
- return;
- }
-}
-
-
-GLboolean GLAPIENTRY
-_mesa_IsFramebufferEXT(GLuint framebuffer)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
- if (framebuffer) {
- struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer);
- if (rb != NULL && rb != &DummyFramebuffer)
- return GL_TRUE;
- }
- return GL_FALSE;
-}
-
-
-/**
- * Check if any of the attachments of the given framebuffer are textures
- * (render to texture). Call ctx->Driver.RenderTexture() for such
- * attachments.
- */
-static void
-check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
- GLuint i;
- ASSERT(ctx->Driver.RenderTexture);
-
- if (fb->Name == 0)
- return; /* can't render to texture with winsys framebuffers */
-
- for (i = 0; i < BUFFER_COUNT; i++) {
- struct gl_renderbuffer_attachment *att = fb->Attachment + i;
- struct gl_texture_object *texObj = att->Texture;
- if (texObj
- && texObj->Image[att->CubeMapFace][att->TextureLevel]) {
- ctx->Driver.RenderTexture(ctx, fb, att);
- }
- }
-}
-
-
-/**
- * Examine all the framebuffer's attachments to see if any are textures.
- * If so, call ctx->Driver.FinishRenderTexture() for each texture to
- * notify the device driver that the texture image may have changed.
- */
-static void
-check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
- if (fb->Name == 0)
- return; /* can't render to texture with winsys framebuffers */
-
- if (ctx->Driver.FinishRenderTexture) {
- GLuint i;
- for (i = 0; i < BUFFER_COUNT; i++) {
- struct gl_renderbuffer_attachment *att = fb->Attachment + i;
- if (att->Texture && att->Renderbuffer) {
- ctx->Driver.FinishRenderTexture(ctx, att);
- }
- }
- }
-}
-
-
-void GLAPIENTRY
-_mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
-{
- struct gl_framebuffer *newDrawFb, *newReadFb;
- struct gl_framebuffer *oldDrawFb, *oldReadFb;
- GLboolean bindReadBuf, bindDrawBuf;
- GET_CURRENT_CONTEXT(ctx);
-
-#ifdef DEBUG
- if (ctx->Extensions.ARB_framebuffer_object) {
- ASSERT(ctx->Extensions.EXT_framebuffer_object);
- ASSERT(ctx->Extensions.EXT_framebuffer_blit);
- }
-#endif
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (!ctx->Extensions.EXT_framebuffer_object) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBindFramebufferEXT(unsupported)");
- return;
- }
-
- switch (target) {
-#if FEATURE_EXT_framebuffer_blit
- case GL_DRAW_FRAMEBUFFER_EXT:
- if (!ctx->Extensions.EXT_framebuffer_blit) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
- return;
- }
- bindDrawBuf = GL_TRUE;
- bindReadBuf = GL_FALSE;
- break;
- case GL_READ_FRAMEBUFFER_EXT:
- if (!ctx->Extensions.EXT_framebuffer_blit) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
- return;
- }
- bindDrawBuf = GL_FALSE;
- bindReadBuf = GL_TRUE;
- break;
-#endif
- case GL_FRAMEBUFFER_EXT:
- bindDrawBuf = GL_TRUE;
- bindReadBuf = GL_TRUE;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
- return;
- }
-
- if (framebuffer) {
- /* Binding a user-created framebuffer object */
- newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer);
- if (newDrawFb == &DummyFramebuffer) {
- /* ID was reserved, but no real framebuffer object made yet */
- newDrawFb = NULL;
- }
- else if (!newDrawFb && ctx->Extensions.ARB_framebuffer_object) {
- /* All FBO IDs must be Gen'd */
- _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)");
- return;
- }
-
- if (!newDrawFb) {
- /* create new framebuffer object */
- newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer);
- if (!newDrawFb) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT");
- return;
- }
- _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb);
- }
- newReadFb = newDrawFb;
- }
- else {
- /* Binding the window system framebuffer (which was originally set
- * with MakeCurrent).
- */
- newDrawFb = ctx->WinSysDrawBuffer;
- newReadFb = ctx->WinSysReadBuffer;
- }
-
- ASSERT(newDrawFb);
- ASSERT(newDrawFb != &DummyFramebuffer);
-
- /* save pointers to current/old framebuffers */
- oldDrawFb = ctx->DrawBuffer;
- oldReadFb = ctx->ReadBuffer;
-
- /* check if really changing bindings */
- if (oldDrawFb == newDrawFb)
- bindDrawBuf = GL_FALSE;
- if (oldReadFb == newReadFb)
- bindReadBuf = GL_FALSE;
-
- /*
- * OK, now bind the new Draw/Read framebuffers, if they're changing.
- *
- * We also check if we're beginning and/or ending render-to-texture.
- * When a framebuffer with texture attachments is unbound, call
- * ctx->Driver.FinishRenderTexture().
- * When a framebuffer with texture attachments is bound, call
- * ctx->Driver.RenderTexture().
- *
- * Note that if the ReadBuffer has texture attachments we don't consider
- * that a render-to-texture case.
- */
- if (bindReadBuf) {
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
- /* check if old readbuffer was render-to-texture */
- check_end_texture_render(ctx, oldReadFb);
-
- _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb);
- }
-
- if (bindDrawBuf) {
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
- /* check if old read/draw buffers were render-to-texture */
- if (!bindReadBuf)
- check_end_texture_render(ctx, oldReadFb);
-
- if (oldDrawFb != oldReadFb)
- check_end_texture_render(ctx, oldDrawFb);
-
- /* check if newly bound framebuffer has any texture attachments */
- check_begin_texture_render(ctx, newDrawFb);
-
- _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb);
- }
-
- if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) {
- ctx->Driver.BindFramebuffer(ctx, target, newDrawFb, newReadFb);
- }
-}
-
-
-void GLAPIENTRY
-_mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers)
-{
- GLint i;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
- for (i = 0; i < n; i++) {
- if (framebuffers[i] > 0) {
- struct gl_framebuffer *fb;
- fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]);
- if (fb) {
- ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]);
-
- /* check if deleting currently bound framebuffer object */
- if (ctx->Extensions.EXT_framebuffer_blit) {
- /* separate draw/read binding points */
- if (fb == ctx->DrawBuffer) {
- /* bind default */
- ASSERT(fb->RefCount >= 2);
- _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
- }
- if (fb == ctx->ReadBuffer) {
- /* bind default */
- ASSERT(fb->RefCount >= 2);
- _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
- }
- }
- else {
- /* only one binding point for read/draw buffers */
- if (fb == ctx->DrawBuffer || fb == ctx->ReadBuffer) {
- /* bind default */
- ASSERT(fb->RefCount >= 2);
- _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- }
- }
-
- /* remove from hash table immediately, to free the ID */
- _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]);
-
- if (fb != &DummyFramebuffer) {
- /* But the object will not be freed until it's no longer
- * bound in any context.
- */
- _mesa_reference_framebuffer(&fb, NULL);
- }
- }
- }
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GenFramebuffersEXT(GLsizei n, GLuint *framebuffers)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint first;
- GLint i;
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (n < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGenFramebuffersEXT(n)");
- return;
- }
-
- if (!framebuffers)
- return;
-
- first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n);
-
- for (i = 0; i < n; i++) {
- GLuint name = first + i;
- framebuffers[i] = name;
- /* insert dummy placeholder into hash table */
- _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
- _mesa_HashInsert(ctx->Shared->FrameBuffers, name, &DummyFramebuffer);
- _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
- }
-}
-
-
-
-GLenum GLAPIENTRY
-_mesa_CheckFramebufferStatusEXT(GLenum target)
-{
- struct gl_framebuffer *buffer;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
-
- buffer = get_framebuffer_target(ctx, target);
- if (!buffer) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
- return 0;
- }
-
- if (buffer->Name == 0) {
- /* The window system / default framebuffer is always complete */
- return GL_FRAMEBUFFER_COMPLETE_EXT;
- }
-
- /* No need to flush here */
-
- if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
- _mesa_test_framebuffer_completeness(ctx, buffer);
- }
-
- return buffer->_Status;
-}
-
-
-
-/**
- * Common code called by glFramebufferTexture1D/2D/3DEXT().
- */
-static void
-framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
- GLenum attachment, GLenum textarget, GLuint texture,
- GLint level, GLint zoffset)
-{
- struct gl_renderbuffer_attachment *att;
- struct gl_texture_object *texObj = NULL;
- struct gl_framebuffer *fb;
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- fb = get_framebuffer_target(ctx, target);
- if (!fb) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glFramebufferTexture%sEXT(target=0x%x)", caller, target);
- return;
- }
-
- /* check framebuffer binding */
- if (fb->Name == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glFramebufferTexture%sEXT", caller);
- return;
- }
-
-
- /* The textarget, level, and zoffset parameters are only validated if
- * texture is non-zero.
- */
- if (texture) {
- GLboolean err = GL_TRUE;
-
- texObj = _mesa_lookup_texture(ctx, texture);
- if (texObj != NULL) {
- if (textarget == 0) {
- /* XXX what's the purpose of this? */
- err = (texObj->Target != GL_TEXTURE_3D) &&
- (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT) &&
- (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT);
- }
- else {
- err = (texObj->Target == GL_TEXTURE_CUBE_MAP)
- ? !IS_CUBE_FACE(textarget)
- : (texObj->Target != textarget);
- }
- }
- else {
- /* can't render to a non-existant texture */
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glFramebufferTexture%sEXT(non existant texture)",
- caller);
- return;
- }
-
- if (err) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glFramebufferTexture%sEXT(texture target mismatch)",
- caller);
- return;
- }
-
- if (texObj->Target == GL_TEXTURE_3D) {
- const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
- if (zoffset < 0 || zoffset >= maxSize) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glFramebufferTexture%sEXT(zoffset)", caller);
- return;
- }
- }
- else if ((texObj->Target == GL_TEXTURE_1D_ARRAY_EXT) ||
- (texObj->Target == GL_TEXTURE_2D_ARRAY_EXT)) {
- if (zoffset < 0 || zoffset >= ctx->Const.MaxArrayTextureLayers) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glFramebufferTexture%sEXT(layer)", caller);
- return;
- }
- }
-
- if ((level < 0) ||
- (level >= _mesa_max_texture_levels(ctx, texObj->Target))) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glFramebufferTexture%sEXT(level)", caller);
- return;
- }
- }
-
- att = _mesa_get_attachment(ctx, fb, attachment);
- if (att == NULL) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glFramebufferTexture%sEXT(attachment)", caller);
- return;
- }
-
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
- _glthread_LOCK_MUTEX(fb->Mutex);
- if (texObj) {
- _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget,
- level, zoffset);
- /* Set the render-to-texture flag. We'll check this flag in
- * glTexImage() and friends to determine if we need to revalidate
- * any FBOs that might be rendering into this texture.
- * This flag never gets cleared since it's non-trivial to determine
- * when all FBOs might be done rendering to this texture. That's OK
- * though since it's uncommon to render to a texture then repeatedly
- * call glTexImage() to change images in the texture.
- */
- texObj->_RenderToTexture = GL_TRUE;
- }
- else {
- _mesa_remove_attachment(ctx, att);
- }
-
- invalidate_framebuffer(fb);
-
- _glthread_UNLOCK_MUTEX(fb->Mutex);
-}
-
-
-
-void GLAPIENTRY
-_mesa_FramebufferTexture1DEXT(GLenum target, GLenum attachment,
- GLenum textarget, GLuint texture, GLint level)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if ((texture != 0) && (textarget != GL_TEXTURE_1D)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glFramebufferTexture1DEXT(textarget)");
- return;
- }
-
- framebuffer_texture(ctx, "1D", target, attachment, textarget, texture,
- level, 0);
-}
-
-
-void GLAPIENTRY
-_mesa_FramebufferTexture2DEXT(GLenum target, GLenum attachment,
- GLenum textarget, GLuint texture, GLint level)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if ((texture != 0) &&
- (textarget != GL_TEXTURE_2D) &&
- (textarget != GL_TEXTURE_RECTANGLE_ARB) &&
- (!IS_CUBE_FACE(textarget))) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glFramebufferTexture2DEXT(textarget=0x%x)", textarget);
- return;
- }
-
- framebuffer_texture(ctx, "2D", target, attachment, textarget, texture,
- level, 0);
-}
-
-
-void GLAPIENTRY
-_mesa_FramebufferTexture3DEXT(GLenum target, GLenum attachment,
- GLenum textarget, GLuint texture,
- GLint level, GLint zoffset)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if ((texture != 0) && (textarget != GL_TEXTURE_3D)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glFramebufferTexture3DEXT(textarget)");
- return;
- }
-
- framebuffer_texture(ctx, "3D", target, attachment, textarget, texture,
- level, zoffset);
-}
-
-
-void GLAPIENTRY
-_mesa_FramebufferTextureLayerEXT(GLenum target, GLenum attachment,
- GLuint texture, GLint level, GLint layer)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
- level, layer);
-}
-
-
-void GLAPIENTRY
-_mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment,
- GLenum renderbufferTarget,
- GLuint renderbuffer)
-{
- struct gl_renderbuffer_attachment *att;
- struct gl_framebuffer *fb;
- struct gl_renderbuffer *rb;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- fb = get_framebuffer_target(ctx, target);
- if (!fb) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glFramebufferRenderbufferEXT(target)");
- return;
- }
-
- if (renderbufferTarget != GL_RENDERBUFFER_EXT) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glFramebufferRenderbufferEXT(renderbufferTarget)");
- return;
- }
-
- if (fb->Name == 0) {
- /* Can't attach new renderbuffers to a window system framebuffer */
- _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT");
- return;
- }
-
- att = _mesa_get_attachment(ctx, fb, attachment);
- if (att == NULL) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glFramebufferRenderbufferEXT(invalid attachment %s)",
- _mesa_lookup_enum_by_nr(attachment));
- return;
- }
-
- if (renderbuffer) {
- rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
- if (!rb) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glFramebufferRenderbufferEXT(non-existant"
- " renderbuffer %u)", renderbuffer);
- return;
- }
- else if (rb == &DummyRenderbuffer) {
- /* This is what NVIDIA does */
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glFramebufferRenderbufferEXT(renderbuffer %u)",
- renderbuffer);
- return;
- }
- }
- else {
- /* remove renderbuffer attachment */
- rb = NULL;
- }
-
- if (attachment == GL_DEPTH_STENCIL_ATTACHMENT &&
- rb && rb->Format != MESA_FORMAT_NONE) {
- /* make sure the renderbuffer is a depth/stencil format */
- const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
- if (baseFormat != GL_DEPTH_STENCIL) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glFramebufferRenderbufferEXT(renderbuffer"
- " is not DEPTH_STENCIL format)");
- return;
- }
- }
-
-
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
- assert(ctx->Driver.FramebufferRenderbuffer);
- ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb);
-
- /* Some subsequent GL commands may depend on the framebuffer's visual
- * after the binding is updated. Update visual info now.
- */
- _mesa_update_framebuffer_visual(ctx, fb);
-}
-
-
-void GLAPIENTRY
-_mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment,
- GLenum pname, GLint *params)
-{
- const struct gl_renderbuffer_attachment *att;
- struct gl_framebuffer *buffer;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- buffer = get_framebuffer_target(ctx, target);
- if (!buffer) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(target)");
- return;
- }
-
- if (buffer->Name == 0) {
- /* the default / window-system FBO */
- att = _mesa_get_fb0_attachment(ctx, buffer, attachment);
- }
- else {
- /* user-created framebuffer FBO */
- att = _mesa_get_attachment(ctx, buffer, attachment);
- }
-
- if (att == NULL) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(attachment)");
- return;
- }
-
- if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
- /* the depth and stencil attachments must point to the same buffer */
- const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt;
- depthAtt = _mesa_get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT);
- stencilAtt = _mesa_get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT);
- if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
- " attachments differ)");
- return;
- }
- }
-
- /* No need to flush here */
-
- switch (pname) {
- case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT:
- *params = buffer->Name == 0 ? GL_FRAMEBUFFER_DEFAULT : att->Type;
- return;
- case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT:
- if (att->Type == GL_RENDERBUFFER_EXT) {
- *params = att->Renderbuffer->Name;
- }
- else if (att->Type == GL_TEXTURE) {
- *params = att->Texture->Name;
- }
- else {
- assert(att->Type == GL_NONE);
- *params = 0;
- }
- return;
- case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT:
- if (att->Type == GL_TEXTURE) {
- *params = att->TextureLevel;
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- }
- return;
- case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT:
- if (att->Type == GL_TEXTURE) {
- if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) {
- *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace;
- }
- else {
- *params = 0;
- }
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- }
- return;
- case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT:
- if (att->Type == GL_TEXTURE) {
- if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) {
- *params = att->Zoffset;
- }
- else {
- *params = 0;
- }
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- }
- return;
- case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
- if (!ctx->Extensions.ARB_framebuffer_object) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- }
- else {
- if (ctx->Extensions.EXT_framebuffer_sRGB && ctx->Const.sRGBCapable) {
- *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format);
- }
- else {
- /* According to ARB_framebuffer_sRGB, we should return LINEAR
- * if the sRGB conversion is unsupported. */
- *params = GL_LINEAR;
- }
- }
- return;
- case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
- if (!ctx->Extensions.ARB_framebuffer_object) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- return;
- }
- else {
- gl_format format = att->Renderbuffer->Format;
- if (format == MESA_FORMAT_CI8 || format == MESA_FORMAT_S8) {
- /* special cases */
- *params = GL_INDEX;
- }
- else {
- *params = _mesa_get_format_datatype(format);
- }
- }
- return;
- case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
- case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
- case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
- case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
- case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
- case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
- if (!ctx->Extensions.ARB_framebuffer_object) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- }
- else if (att->Texture) {
- const struct gl_texture_image *texImage =
- _mesa_select_tex_image(ctx, att->Texture, att->Texture->Target,
- att->TextureLevel);
- if (texImage) {
- *params = get_component_bits(pname, texImage->_BaseFormat,
- texImage->TexFormat);
- }
- else {
- *params = 0;
- }
- }
- else if (att->Renderbuffer) {
- *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat,
- att->Renderbuffer->Format);
- }
- else {
- *params = 0;
- }
- return;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetFramebufferAttachmentParameterivEXT(pname)");
- return;
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GenerateMipmapEXT(GLenum target)
-{
- struct gl_texture_object *texObj;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
- switch (target) {
- case GL_TEXTURE_1D:
- case GL_TEXTURE_2D:
- case GL_TEXTURE_3D:
- case GL_TEXTURE_CUBE_MAP:
- /* OK, legal value */
- break;
- default:
- /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
- _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target)");
- return;
- }
-
- texObj = _mesa_get_current_tex_object(ctx, target);
-
- if (texObj->BaseLevel >= texObj->MaxLevel) {
- /* nothing to do */
- return;
- }
-
- if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
- !_mesa_cube_complete(texObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGenerateMipmap(incomplete cube map)");
- return;
- }
-
- _mesa_lock_texture(ctx, texObj);
- if (target == GL_TEXTURE_CUBE_MAP) {
- GLuint face;
- for (face = 0; face < 6; face++)
- ctx->Driver.GenerateMipmap(ctx,
- GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face,
- texObj);
- }
- else {
- ctx->Driver.GenerateMipmap(ctx, target, texObj);
- }
- _mesa_unlock_texture(ctx, texObj);
-}
-
-
-#if FEATURE_EXT_framebuffer_blit
-
-static const struct gl_renderbuffer_attachment *
-find_attachment(const struct gl_framebuffer *fb,
- const struct gl_renderbuffer *rb)
-{
- GLuint i;
- for (i = 0; i < Elements(fb->Attachment); i++) {
- if (fb->Attachment[i].Renderbuffer == rb)
- return &fb->Attachment[i];
- }
- return NULL;
-}
-
-
-
-/**
- * Blit rectangular region, optionally from one framebuffer to another.
- *
- * Note, if the src buffer is multisampled and the dest is not, this is
- * when the samples must be resolved to a single color.
- */
-void GLAPIENTRY
-_mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
- GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
- GLbitfield mask, GLenum filter)
-{
- const GLbitfield legalMaskBits = (GL_COLOR_BUFFER_BIT |
- GL_DEPTH_BUFFER_BIT |
- GL_STENCIL_BUFFER_BIT);
- const struct gl_framebuffer *readFb, *drawFb;
- const struct gl_renderbuffer *colorReadRb, *colorDrawRb;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
- FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx,
- "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
- srcX0, srcY0, srcX1, srcY1,
- dstX0, dstY0, dstX1, dstY1,
- mask, _mesa_lookup_enum_by_nr(filter));
-
- if (ctx->NewState) {
- _mesa_update_state(ctx);
- }
-
- readFb = ctx->ReadBuffer;
- drawFb = ctx->DrawBuffer;
-
- if (!readFb || !drawFb) {
- /* This will normally never happen but someday we may want to
- * support MakeCurrent() with no drawables.
- */
- return;
- }
-
- /* check for complete framebuffers */
- if (drawFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
- readFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
- "glBlitFramebufferEXT(incomplete draw/read buffers)");
- return;
- }
-
- if (filter != GL_NEAREST && filter != GL_LINEAR) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(filter)");
- return;
- }
-
- if (mask & ~legalMaskBits) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glBlitFramebufferEXT(mask)");
- return;
- }
-
- /* depth/stencil must be blitted with nearest filtering */
- if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
- && filter != GL_NEAREST) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
- return;
- }
-
- /* get color read/draw renderbuffers */
- if (mask & GL_COLOR_BUFFER_BIT) {
- colorReadRb = readFb->_ColorReadBuffer;
- colorDrawRb = drawFb->_ColorDrawBuffers[0];
- }
- else {
- colorReadRb = colorDrawRb = NULL;
- }
-
- if (mask & GL_STENCIL_BUFFER_BIT) {
- struct gl_renderbuffer *readRb = readFb->_StencilBuffer;
- struct gl_renderbuffer *drawRb = drawFb->_StencilBuffer;
- if (!readRb ||
- !drawRb ||
- _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) !=
- _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBlitFramebufferEXT(stencil buffer size mismatch");
- return;
- }
- }
-
- if (mask & GL_DEPTH_BUFFER_BIT) {
- struct gl_renderbuffer *readRb = readFb->_DepthBuffer;
- struct gl_renderbuffer *drawRb = drawFb->_DepthBuffer;
- if (!readRb ||
- !drawRb ||
- _mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) !=
- _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBlitFramebufferEXT(depth buffer size mismatch");
- return;
- }
- }
-
- if (readFb->Visual.samples > 0 &&
- drawFb->Visual.samples > 0 &&
- readFb->Visual.samples != drawFb->Visual.samples) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBlitFramebufferEXT(mismatched samples");
- return;
- }
-
- /* extra checks for multisample copies... */
- if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) {
- /* src and dest region sizes must be the same */
- if (srcX1 - srcX0 != dstX1 - dstX0 ||
- srcY1 - srcY0 != dstY1 - dstY0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBlitFramebufferEXT(bad src/dst multisample region sizes");
- return;
- }
-
- /* color formats must match */
- if (colorReadRb &&
- colorDrawRb &&
- colorReadRb->Format != colorDrawRb->Format) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
- return;
- }
- }
-
- if (!ctx->Extensions.EXT_framebuffer_blit) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT");
- return;
- }
-
- /* Debug code */
- if (DEBUG_BLIT) {
- printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
- " 0x%x, 0x%x)\n",
- srcX0, srcY0, srcX1, srcY1,
- dstX0, dstY0, dstX1, dstY1,
- mask, filter);
- if (colorReadRb) {
- const struct gl_renderbuffer_attachment *att;
-
- att = find_attachment(readFb, colorReadRb);
- printf(" Src FBO %u RB %u (%dx%d) ",
- readFb->Name, colorReadRb->Name,
- colorReadRb->Width, colorReadRb->Height);
- if (att && att->Texture) {
- printf("Tex %u tgt 0x%x level %u face %u",
- att->Texture->Name,
- att->Texture->Target,
- att->TextureLevel,
- att->CubeMapFace);
- }
- printf("\n");
-
- att = find_attachment(drawFb, colorDrawRb);
- printf(" Dst FBO %u RB %u (%dx%d) ",
- drawFb->Name, colorDrawRb->Name,
- colorDrawRb->Width, colorDrawRb->Height);
- if (att && att->Texture) {
- printf("Tex %u tgt 0x%x level %u face %u",
- att->Texture->Name,
- att->Texture->Target,
- att->TextureLevel,
- att->CubeMapFace);
- }
- printf("\n");
- }
- }
-
- ASSERT(ctx->Driver.BlitFramebuffer);
- ctx->Driver.BlitFramebuffer(ctx,
- srcX0, srcY0, srcX1, srcY1,
- dstX0, dstY0, dstX1, dstY1,
- mask, filter);
-}
-#endif /* FEATURE_EXT_framebuffer_blit */
-
-#if FEATURE_ARB_geometry_shader4
-void GLAPIENTRY
-_mesa_FramebufferTextureARB(GLenum target, GLenum attachment,
- GLuint texture, GLint level)
-{
- GET_CURRENT_CONTEXT(ctx);
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glFramebufferTextureARB "
- "not implemented!");
-}
-
-void GLAPIENTRY
-_mesa_FramebufferTextureFaceARB(GLenum target, GLenum attachment,
- GLuint texture, GLint level, GLenum face)
-{
- GET_CURRENT_CONTEXT(ctx);
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glFramebufferTextureFaceARB "
- "not implemented!");
-}
-#endif /* FEATURE_ARB_geometry_shader4 */
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/*
+ * GL_EXT/ARB_framebuffer_object extensions
+ *
+ * Authors:
+ * Brian Paul
+ */
+
+
+#include "buffers.h"
+#include "context.h"
+#include "enums.h"
+#include "fbobject.h"
+#include "formats.h"
+#include "framebuffer.h"
+#include "hash.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "renderbuffer.h"
+#include "state.h"
+#include "teximage.h"
+#include "texobj.h"
+
+
+/** Set this to 1 to help debug FBO incompleteness problems */
+#define DEBUG_FBO 0
+
+/** Set this to 1 to debug/log glBlitFramebuffer() calls */
+#define DEBUG_BLIT 0
+
+
+/**
+ * Notes:
+ *
+ * None of the GL_EXT_framebuffer_object functions are compiled into
+ * display lists.
+ */
+
+
+
+/*
+ * When glGenRender/FramebuffersEXT() is called we insert pointers to
+ * these placeholder objects into the hash table.
+ * Later, when the object ID is first bound, we replace the placeholder
+ * with the real frame/renderbuffer.
+ */
+static struct gl_framebuffer DummyFramebuffer;
+static struct gl_renderbuffer DummyRenderbuffer;
+
+/* We bind this framebuffer when applications pass a NULL
+ * drawable/surface in make current. */
+static struct gl_framebuffer IncompleteFramebuffer;
+
+
+#define IS_CUBE_FACE(TARGET) \
+ ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
+ (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
+
+
+static void
+delete_dummy_renderbuffer(struct gl_renderbuffer *rb)
+{
+ /* no op */
+}
+
+static void
+delete_dummy_framebuffer(struct gl_framebuffer *fb)
+{
+ /* no op */
+}
+
+
+void
+_mesa_init_fbobjects(struct gl_context *ctx)
+{
+ _glthread_INIT_MUTEX(DummyFramebuffer.Mutex);
+ _glthread_INIT_MUTEX(DummyRenderbuffer.Mutex);
+ _glthread_INIT_MUTEX(IncompleteFramebuffer.Mutex);
+ DummyFramebuffer.Delete = delete_dummy_framebuffer;
+ DummyRenderbuffer.Delete = delete_dummy_renderbuffer;
+ IncompleteFramebuffer.Delete = delete_dummy_framebuffer;
+}
+
+struct gl_framebuffer *
+_mesa_get_incomplete_framebuffer(void)
+{
+ return &IncompleteFramebuffer;
+}
+
+/**
+ * Helper routine for getting a gl_renderbuffer.
+ */
+struct gl_renderbuffer *
+_mesa_lookup_renderbuffer(struct gl_context *ctx, GLuint id)
+{
+ struct gl_renderbuffer *rb;
+
+ if (id == 0)
+ return NULL;
+
+ rb = (struct gl_renderbuffer *)
+ _mesa_HashLookup(ctx->Shared->RenderBuffers, id);
+ return rb;
+}
+
+
+/**
+ * Helper routine for getting a gl_framebuffer.
+ */
+struct gl_framebuffer *
+_mesa_lookup_framebuffer(struct gl_context *ctx, GLuint id)
+{
+ struct gl_framebuffer *fb;
+
+ if (id == 0)
+ return NULL;
+
+ fb = (struct gl_framebuffer *)
+ _mesa_HashLookup(ctx->Shared->FrameBuffers, id);
+ return fb;
+}
+
+
+/**
+ * Mark the given framebuffer as invalid. This will force the
+ * test for framebuffer completeness to be done before the framebuffer
+ * is used.
+ */
+static void
+invalidate_framebuffer(struct gl_framebuffer *fb)
+{
+ fb->_Status = 0; /* "indeterminate" */
+}
+
+
+/**
+ * Return the gl_framebuffer object which corresponds to the given
+ * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
+ * Check support for GL_EXT_framebuffer_blit to determine if certain
+ * targets are legal.
+ * \return gl_framebuffer pointer or NULL if target is illegal
+ */
+static struct gl_framebuffer *
+get_framebuffer_target(struct gl_context *ctx, GLenum target)
+{
+ switch (target) {
+ case GL_DRAW_FRAMEBUFFER:
+ return ctx->Extensions.EXT_framebuffer_blit ? ctx->DrawBuffer : NULL;
+ case GL_READ_FRAMEBUFFER:
+ return ctx->Extensions.EXT_framebuffer_blit ? ctx->ReadBuffer : NULL;
+ case GL_FRAMEBUFFER_EXT:
+ return ctx->DrawBuffer;
+ default:
+ return NULL;
+ }
+}
+
+
+/**
+ * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
+ * gl_renderbuffer_attachment object.
+ * This function is only used for user-created FB objects, not the
+ * default / window-system FB object.
+ * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
+ * the depth buffer attachment point.
+ */
+struct gl_renderbuffer_attachment *
+_mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
+ GLenum attachment)
+{
+ GLuint i;
+
+ assert(fb->Name > 0);
+
+ switch (attachment) {
+ case GL_COLOR_ATTACHMENT0_EXT:
+ case GL_COLOR_ATTACHMENT1_EXT:
+ case GL_COLOR_ATTACHMENT2_EXT:
+ case GL_COLOR_ATTACHMENT3_EXT:
+ case GL_COLOR_ATTACHMENT4_EXT:
+ case GL_COLOR_ATTACHMENT5_EXT:
+ case GL_COLOR_ATTACHMENT6_EXT:
+ case GL_COLOR_ATTACHMENT7_EXT:
+ case GL_COLOR_ATTACHMENT8_EXT:
+ case GL_COLOR_ATTACHMENT9_EXT:
+ case GL_COLOR_ATTACHMENT10_EXT:
+ case GL_COLOR_ATTACHMENT11_EXT:
+ case GL_COLOR_ATTACHMENT12_EXT:
+ case GL_COLOR_ATTACHMENT13_EXT:
+ case GL_COLOR_ATTACHMENT14_EXT:
+ case GL_COLOR_ATTACHMENT15_EXT:
+ i = attachment - GL_COLOR_ATTACHMENT0_EXT;
+ if (i >= ctx->Const.MaxColorAttachments) {
+ return NULL;
+ }
+ return &fb->Attachment[BUFFER_COLOR0 + i];
+ case GL_DEPTH_STENCIL_ATTACHMENT:
+ /* fall-through */
+ case GL_DEPTH_BUFFER:
+ /* fall-through / new in GL 3.0 */
+ case GL_DEPTH_ATTACHMENT_EXT:
+ return &fb->Attachment[BUFFER_DEPTH];
+ case GL_STENCIL_BUFFER:
+ /* fall-through / new in GL 3.0 */
+ case GL_STENCIL_ATTACHMENT_EXT:
+ return &fb->Attachment[BUFFER_STENCIL];
+ default:
+ return NULL;
+ }
+}
+
+
+/**
+ * As above, but only used for getting attachments of the default /
+ * window-system framebuffer (not user-created framebuffer objects).
+ */
+static struct gl_renderbuffer_attachment *
+_mesa_get_fb0_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
+ GLenum attachment)
+{
+ assert(fb->Name == 0);
+
+ switch (attachment) {
+ case GL_FRONT_LEFT:
+ return &fb->Attachment[BUFFER_FRONT_LEFT];
+ case GL_FRONT_RIGHT:
+ return &fb->Attachment[BUFFER_FRONT_RIGHT];
+ case GL_BACK_LEFT:
+ return &fb->Attachment[BUFFER_BACK_LEFT];
+ case GL_BACK_RIGHT:
+ return &fb->Attachment[BUFFER_BACK_RIGHT];
+ case GL_AUX0:
+ if (fb->Visual.numAuxBuffers == 1) {
+ return &fb->Attachment[BUFFER_AUX0];
+ }
+ return NULL;
+ case GL_DEPTH_BUFFER:
+ /* fall-through / new in GL 3.0 */
+ case GL_DEPTH_ATTACHMENT_EXT:
+ return &fb->Attachment[BUFFER_DEPTH];
+ case GL_STENCIL_BUFFER:
+ /* fall-through / new in GL 3.0 */
+ case GL_STENCIL_ATTACHMENT_EXT:
+ return &fb->Attachment[BUFFER_STENCIL];
+ default:
+ return NULL;
+ }
+}
+
+
+
+/**
+ * Remove any texture or renderbuffer attached to the given attachment
+ * point. Update reference counts, etc.
+ */
+void
+_mesa_remove_attachment(struct gl_context *ctx,
+ struct gl_renderbuffer_attachment *att)
+{
+ if (att->Type == GL_TEXTURE) {
+ ASSERT(att->Texture);
+ if (ctx->Driver.FinishRenderTexture) {
+ /* tell driver that we're done rendering to this texture. */
+ ctx->Driver.FinishRenderTexture(ctx, att);
+ }
+ _mesa_reference_texobj(&att->Texture, NULL); /* unbind */
+ ASSERT(!att->Texture);
+ }
+ if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) {
+ ASSERT(!att->Texture);
+ _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */
+ ASSERT(!att->Renderbuffer);
+ }
+ att->Type = GL_NONE;
+ att->Complete = GL_TRUE;
+}
+
+
+/**
+ * Bind a texture object to an attachment point.
+ * The previous binding, if any, will be removed first.
+ */
+void
+_mesa_set_texture_attachment(struct gl_context *ctx,
+ struct gl_framebuffer *fb,
+ struct gl_renderbuffer_attachment *att,
+ struct gl_texture_object *texObj,
+ GLenum texTarget, GLuint level, GLuint zoffset)
+{
+ if (att->Texture == texObj) {
+ /* re-attaching same texture */
+ ASSERT(att->Type == GL_TEXTURE);
+ if (ctx->Driver.FinishRenderTexture)
+ ctx->Driver.FinishRenderTexture(ctx, att);
+ }
+ else {
+ /* new attachment */
+ if (ctx->Driver.FinishRenderTexture && att->Texture)
+ ctx->Driver.FinishRenderTexture(ctx, att);
+ _mesa_remove_attachment(ctx, att);
+ att->Type = GL_TEXTURE;
+ assert(!att->Texture);
+ _mesa_reference_texobj(&att->Texture, texObj);
+ }
+
+ /* always update these fields */
+ att->TextureLevel = level;
+ att->CubeMapFace = _mesa_tex_target_to_face(texTarget);
+ att->Zoffset = zoffset;
+ att->Complete = GL_FALSE;
+
+ if (att->Texture->Image[att->CubeMapFace][att->TextureLevel]) {
+ ctx->Driver.RenderTexture(ctx, fb, att);
+ }
+
+ invalidate_framebuffer(fb);
+}
+
+
+/**
+ * Bind a renderbuffer to an attachment point.
+ * The previous binding, if any, will be removed first.
+ */
+void
+_mesa_set_renderbuffer_attachment(struct gl_context *ctx,
+ struct gl_renderbuffer_attachment *att,
+ struct gl_renderbuffer *rb)
+{
+ /* XXX check if re-doing same attachment, exit early */
+ _mesa_remove_attachment(ctx, att);
+ att->Type = GL_RENDERBUFFER_EXT;
+ att->Texture = NULL; /* just to be safe */
+ att->Complete = GL_FALSE;
+ _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
+}
+
+
+/**
+ * Fallback for ctx->Driver.FramebufferRenderbuffer()
+ * Attach a renderbuffer object to a framebuffer object.
+ */
+void
+_mesa_framebuffer_renderbuffer(struct gl_context *ctx,
+ struct gl_framebuffer *fb,
+ GLenum attachment, struct gl_renderbuffer *rb)
+{
+ struct gl_renderbuffer_attachment *att;
+
+ _glthread_LOCK_MUTEX(fb->Mutex);
+
+ att = _mesa_get_attachment(ctx, fb, attachment);
+ ASSERT(att);
+ if (rb) {
+ _mesa_set_renderbuffer_attachment(ctx, att, rb);
+ if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
+ /* do stencil attachment here (depth already done above) */
+ att = _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
+ assert(att);
+ _mesa_set_renderbuffer_attachment(ctx, att, rb);
+ }
+ }
+ else {
+ _mesa_remove_attachment(ctx, att);
+ }
+
+ invalidate_framebuffer(fb);
+
+ _glthread_UNLOCK_MUTEX(fb->Mutex);
+}
+
+
+/**
+ * Fallback for ctx->Driver.ValidateFramebuffer()
+ * Check if the renderbuffer's formats are supported by the software
+ * renderer.
+ * Drivers should probably override this.
+ */
+void
+_mesa_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+ gl_buffer_index buf;
+ for (buf = 0; buf < BUFFER_COUNT; buf++) {
+ const struct gl_renderbuffer *rb = fb->Attachment[buf].Renderbuffer;
+ if (rb) {
+ switch (rb->_BaseFormat) {
+ case GL_ALPHA:
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE:
+ case GL_INTENSITY:
+ case GL_RED:
+ case GL_RG:
+ fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
+ return;
+ default:
+ /* render buffer format is supported by software rendering */
+ ;
+ }
+ }
+ }
+}
+
+
+/**
+ * For debug only.
+ */
+static void
+att_incomplete(const char *msg)
+{
+#if DEBUG_FBO
+ _mesa_debug(NULL, "attachment incomplete: %s\n", msg);
+#else
+ (void) msg;
+#endif
+}
+
+
+/**
+ * For debug only.
+ */
+static void
+fbo_incomplete(const char *msg, int index)
+{
+#if DEBUG_FBO
+ _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
+#else
+ (void) msg;
+ (void) index;
+#endif
+}
+
+
+/**
+ * Is the given base format a legal format for a color renderbuffer?
+ */
+GLboolean
+_mesa_is_legal_color_format(const struct gl_context *ctx, GLenum baseFormat)
+{
+ switch (baseFormat) {
+ case GL_RGB:
+ case GL_RGBA:
+ return GL_TRUE;
+ case GL_LUMINANCE:
+ case GL_LUMINANCE_ALPHA:
+ case GL_INTENSITY:
+ case GL_ALPHA:
+ return ctx->Extensions.ARB_framebuffer_object;
+ case GL_RED:
+ case GL_RG:
+ return ctx->Extensions.ARB_texture_rg;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Is the given base format a legal format for a depth/stencil renderbuffer?
+ */
+static GLboolean
+is_legal_depth_format(const struct gl_context *ctx, GLenum baseFormat)
+{
+ switch (baseFormat) {
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_STENCIL_EXT:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test if an attachment point is complete and update its Complete field.
+ * \param format if GL_COLOR, this is a color attachment point,
+ * if GL_DEPTH, this is a depth component attachment point,
+ * if GL_STENCIL, this is a stencil component attachment point.
+ */
+static void
+test_attachment_completeness(const struct gl_context *ctx, GLenum format,
+ struct gl_renderbuffer_attachment *att)
+{
+ assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL);
+
+ /* assume complete */
+ att->Complete = GL_TRUE;
+
+ /* Look for reasons why the attachment might be incomplete */
+ if (att->Type == GL_TEXTURE) {
+ const struct gl_texture_object *texObj = att->Texture;
+ struct gl_texture_image *texImage;
+ GLenum baseFormat;
+
+ if (!texObj) {
+ att_incomplete("no texobj");
+ att->Complete = GL_FALSE;
+ return;
+ }
+
+ texImage = texObj->Image[att->CubeMapFace][att->TextureLevel];
+ if (!texImage) {
+ att_incomplete("no teximage");
+ att->Complete = GL_FALSE;
+ return;
+ }
+ if (texImage->Width < 1 || texImage->Height < 1) {
+ att_incomplete("teximage width/height=0");
+ printf("texobj = %u\n", texObj->Name);
+ printf("level = %d\n", att->TextureLevel);
+ att->Complete = GL_FALSE;
+ return;
+ }
+ if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) {
+ att_incomplete("bad z offset");
+ att->Complete = GL_FALSE;
+ return;
+ }
+
+ baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
+
+ if (format == GL_COLOR) {
+ if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
+ att_incomplete("bad format");
+ att->Complete = GL_FALSE;
+ return;
+ }
+ if (_mesa_is_format_compressed(texImage->TexFormat)) {
+ att_incomplete("compressed internalformat");
+ att->Complete = GL_FALSE;
+ return;
+ }
+ }
+ else if (format == GL_DEPTH) {
+ if (baseFormat == GL_DEPTH_COMPONENT) {
+ /* OK */
+ }
+ else if (ctx->Extensions.EXT_packed_depth_stencil &&
+ ctx->Extensions.ARB_depth_texture &&
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
+ /* OK */
+ }
+ else {
+ att->Complete = GL_FALSE;
+ att_incomplete("bad depth format");
+ return;
+ }
+ }
+ else {
+ ASSERT(format == GL_STENCIL);
+ if (ctx->Extensions.EXT_packed_depth_stencil &&
+ ctx->Extensions.ARB_depth_texture &&
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
+ /* OK */
+ }
+ else {
+ /* no such thing as stencil-only textures */
+ att_incomplete("illegal stencil texture");
+ att->Complete = GL_FALSE;
+ return;
+ }
+ }
+ }
+ else if (att->Type == GL_RENDERBUFFER_EXT) {
+ const GLenum baseFormat =
+ _mesa_get_format_base_format(att->Renderbuffer->Format);
+
+ ASSERT(att->Renderbuffer);
+ if (!att->Renderbuffer->InternalFormat ||
+ att->Renderbuffer->Width < 1 ||
+ att->Renderbuffer->Height < 1) {
+ att_incomplete("0x0 renderbuffer");
+ att->Complete = GL_FALSE;
+ return;
+ }
+ if (format == GL_COLOR) {
+ if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
+ att_incomplete("bad renderbuffer color format");
+ att->Complete = GL_FALSE;
+ return;
+ }
+ }
+ else if (format == GL_DEPTH) {
+ if (baseFormat == GL_DEPTH_COMPONENT) {
+ /* OK */
+ }
+ else if (ctx->Extensions.EXT_packed_depth_stencil &&
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
+ /* OK */
+ }
+ else {
+ att_incomplete("bad renderbuffer depth format");
+ att->Complete = GL_FALSE;
+ return;
+ }
+ }
+ else {
+ assert(format == GL_STENCIL);
+ if (baseFormat == GL_STENCIL_INDEX) {
+ /* OK */
+ }
+ else if (ctx->Extensions.EXT_packed_depth_stencil &&
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
+ /* OK */
+ }
+ else {
+ att->Complete = GL_FALSE;
+ att_incomplete("bad renderbuffer stencil format");
+ return;
+ }
+ }
+ }
+ else {
+ ASSERT(att->Type == GL_NONE);
+ /* complete */
+ return;
+ }
+}
+
+
+/**
+ * Test if the given framebuffer object is complete and update its
+ * Status field with the results.
+ * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
+ * driver to make hardware-specific validation/completeness checks.
+ * Also update the framebuffer's Width and Height fields if the
+ * framebuffer is complete.
+ */
+void
+_mesa_test_framebuffer_completeness(struct gl_context *ctx,
+ struct gl_framebuffer *fb)
+{
+ GLuint numImages;
+ GLenum intFormat = GL_NONE; /* color buffers' internal format */
+ GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0;
+ GLint numSamples = -1;
+ GLint i;
+ GLuint j;
+
+ assert(fb->Name != 0);
+
+ numImages = 0;
+ fb->Width = 0;
+ fb->Height = 0;
+
+ /* Start at -2 to more easily loop over all attachment points.
+ * -2: depth buffer
+ * -1: stencil buffer
+ * >=0: color buffer
+ */
+ for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) {
+ struct gl_renderbuffer_attachment *att;
+ GLenum f;
+ gl_format attFormat;
+
+ /*
+ * XXX for ARB_fbo, only check color buffers that are named by
+ * GL_READ_BUFFER and GL_DRAW_BUFFERi.
+ */
+
+ /* check for attachment completeness
+ */
+ if (i == -2) {
+ att = &fb->Attachment[BUFFER_DEPTH];
+ test_attachment_completeness(ctx, GL_DEPTH, att);
+ if (!att->Complete) {
+ fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
+ fbo_incomplete("depth attachment incomplete", -1);
+ return;
+ }
+ }
+ else if (i == -1) {
+ att = &fb->Attachment[BUFFER_STENCIL];
+ test_attachment_completeness(ctx, GL_STENCIL, att);
+ if (!att->Complete) {
+ fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
+ fbo_incomplete("stencil attachment incomplete", -1);
+ return;
+ }
+ }
+ else {
+ att = &fb->Attachment[BUFFER_COLOR0 + i];
+ test_attachment_completeness(ctx, GL_COLOR, att);
+ if (!att->Complete) {
+ fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
+ fbo_incomplete("color attachment incomplete", i);
+ return;
+ }
+ }
+
+ /* get width, height, format of the renderbuffer/texture
+ */
+ if (att->Type == GL_TEXTURE) {
+ const struct gl_texture_image *texImg
+ = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+ minWidth = MIN2(minWidth, texImg->Width);
+ maxWidth = MAX2(maxWidth, texImg->Width);
+ minHeight = MIN2(minHeight, texImg->Height);
+ maxHeight = MAX2(maxHeight, texImg->Height);
+ f = texImg->_BaseFormat;
+ attFormat = texImg->TexFormat;
+ numImages++;
+ if (!_mesa_is_legal_color_format(ctx, f) &&
+ !is_legal_depth_format(ctx, f)) {
+ fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
+ fbo_incomplete("texture attachment incomplete", -1);
+ return;
+ }
+ }
+ else if (att->Type == GL_RENDERBUFFER_EXT) {
+ minWidth = MIN2(minWidth, att->Renderbuffer->Width);
+ maxWidth = MAX2(minWidth, att->Renderbuffer->Width);
+ minHeight = MIN2(minHeight, att->Renderbuffer->Height);
+ maxHeight = MAX2(minHeight, att->Renderbuffer->Height);
+ f = att->Renderbuffer->InternalFormat;
+ attFormat = att->Renderbuffer->Format;
+ numImages++;
+ }
+ else {
+ assert(att->Type == GL_NONE);
+ continue;
+ }
+
+ if (numSamples < 0) {
+ /* first buffer */
+ numSamples = att->Renderbuffer->NumSamples;
+ }
+
+ /* check if integer color */
+ fb->_IntegerColor = _mesa_is_format_integer_color(attFormat);
+
+ /* Error-check width, height, format, samples
+ */
+ if (numImages == 1) {
+ /* save format, num samples */
+ if (i >= 0) {
+ intFormat = f;
+ }
+ }
+ else {
+ if (!ctx->Extensions.ARB_framebuffer_object) {
+ /* check that width, height, format are same */
+ if (minWidth != maxWidth || minHeight != maxHeight) {
+ fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
+ fbo_incomplete("width or height mismatch", -1);
+ return;
+ }
+ /* check that all color buffer have same format */
+ if (intFormat != GL_NONE && f != intFormat) {
+ fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
+ fbo_incomplete("format mismatch", -1);
+ return;
+ }
+ }
+ if (att->Renderbuffer &&
+ att->Renderbuffer->NumSamples != numSamples) {
+ fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
+ fbo_incomplete("inconsistant number of samples", i);
+ return;
+ }
+
+ }
+ }
+
+#if FEATURE_GL
+ if (ctx->API == API_OPENGL) {
+ /* Check that all DrawBuffers are present */
+ for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) {
+ if (fb->ColorDrawBuffer[j] != GL_NONE) {
+ const struct gl_renderbuffer_attachment *att
+ = _mesa_get_attachment(ctx, fb, fb->ColorDrawBuffer[j]);
+ assert(att);
+ if (att->Type == GL_NONE) {
+ fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT;
+ fbo_incomplete("missing drawbuffer", j);
+ return;
+ }
+ }
+ }
+
+ /* Check that the ReadBuffer is present */
+ if (fb->ColorReadBuffer != GL_NONE) {
+ const struct gl_renderbuffer_attachment *att
+ = _mesa_get_attachment(ctx, fb, fb->ColorReadBuffer);
+ assert(att);
+ if (att->Type == GL_NONE) {
+ fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT;
+ fbo_incomplete("missing readbuffer", -1);
+ return;
+ }
+ }
+ }
+#else
+ (void) j;
+#endif
+
+ if (numImages == 0) {
+ fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT;
+ fbo_incomplete("no attachments", -1);
+ return;
+ }
+
+ /* Provisionally set status = COMPLETE ... */
+ fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
+
+ /* ... but the driver may say the FB is incomplete.
+ * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
+ * if anything.
+ */
+ if (ctx->Driver.ValidateFramebuffer) {
+ ctx->Driver.ValidateFramebuffer(ctx, fb);
+ if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ fbo_incomplete("driver marked FBO as incomplete", -1);
+ }
+ }
+
+ if (fb->_Status == GL_FRAMEBUFFER_COMPLETE_EXT) {
+ /*
+ * Note that if ARB_framebuffer_object is supported and the attached
+ * renderbuffers/textures are different sizes, the framebuffer
+ * width/height will be set to the smallest width/height.
+ */
+ fb->Width = minWidth;
+ fb->Height = minHeight;
+
+ /* finally, update the visual info for the framebuffer */
+ _mesa_update_framebuffer_visual(ctx, fb);
+ }
+}
+
+
+GLboolean GLAPIENTRY
+_mesa_IsRenderbufferEXT(GLuint renderbuffer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
+ if (renderbuffer) {
+ struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
+ if (rb != NULL && rb != &DummyRenderbuffer)
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+}
+
+
+void GLAPIENTRY
+_mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
+{
+ struct gl_renderbuffer *newRb;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target != GL_RENDERBUFFER_EXT) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)");
+ return;
+ }
+
+ /* No need to flush here since the render buffer binding has no
+ * effect on rendering state.
+ */
+
+ if (renderbuffer) {
+ newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
+ if (newRb == &DummyRenderbuffer) {
+ /* ID was reserved, but no real renderbuffer object made yet */
+ newRb = NULL;
+ }
+ else if (!newRb && ctx->Extensions.ARB_framebuffer_object) {
+ /* All RB IDs must be Gen'd */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)");
+ return;
+ }
+
+ if (!newRb) {
+ /* create new renderbuffer object */
+ newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer);
+ if (!newRb) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT");
+ return;
+ }
+ ASSERT(newRb->AllocStorage);
+ _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb);
+ newRb->RefCount = 1; /* referenced by hash table */
+ }
+ }
+ else {
+ newRb = NULL;
+ }
+
+ ASSERT(newRb != &DummyRenderbuffer);
+
+ _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb);
+}
+
+
+/**
+ * If the given renderbuffer is anywhere attached to the framebuffer, detach
+ * the renderbuffer.
+ * This is used when a renderbuffer object is deleted.
+ * The spec calls for unbinding.
+ */
+static void
+detach_renderbuffer(struct gl_context *ctx,
+ struct gl_framebuffer *fb,
+ struct gl_renderbuffer *rb)
+{
+ GLuint i;
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ if (fb->Attachment[i].Renderbuffer == rb) {
+ _mesa_remove_attachment(ctx, &fb->Attachment[i]);
+ }
+ }
+ invalidate_framebuffer(fb);
+}
+
+
+void GLAPIENTRY
+_mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers)
+{
+ GLint i;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+ for (i = 0; i < n; i++) {
+ if (renderbuffers[i] > 0) {
+ struct gl_renderbuffer *rb;
+ rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]);
+ if (rb) {
+ /* check if deleting currently bound renderbuffer object */
+ if (rb == ctx->CurrentRenderbuffer) {
+ /* bind default */
+ ASSERT(rb->RefCount >= 2);
+ _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+ }
+
+ if (ctx->DrawBuffer->Name) {
+ detach_renderbuffer(ctx, ctx->DrawBuffer, rb);
+ }
+ if (ctx->ReadBuffer->Name && ctx->ReadBuffer != ctx->DrawBuffer) {
+ detach_renderbuffer(ctx, ctx->ReadBuffer, rb);
+ }
+
+ /* Remove from hash table immediately, to free the ID.
+ * But the object will not be freed until it's no longer
+ * referenced anywhere else.
+ */
+ _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]);
+
+ if (rb != &DummyRenderbuffer) {
+ /* no longer referenced by hash table */
+ _mesa_reference_renderbuffer(&rb, NULL);
+ }
+ }
+ }
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint first;
+ GLint i;
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGenRenderbuffersEXT(n)");
+ return;
+ }
+
+ if (!renderbuffers)
+ return;
+
+ first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n);
+
+ for (i = 0; i < n; i++) {
+ GLuint name = first + i;
+ renderbuffers[i] = name;
+ /* insert dummy placeholder into hash table */
+ _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+ _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer);
+ _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+ }
+}
+
+
+/**
+ * Given an internal format token for a render buffer, return the
+ * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
+ * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
+ * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
+ *
+ * This is similar to _mesa_base_tex_format() but the set of valid
+ * internal formats is different.
+ *
+ * Note that even if a format is determined to be legal here, validation
+ * of the FBO may fail if the format is not supported by the driver/GPU.
+ *
+ * \param internalFormat as passed to glRenderbufferStorage()
+ * \return the base internal format, or 0 if internalFormat is illegal
+ */
+GLenum
+_mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat)
+{
+ /*
+ * Notes: some formats such as alpha, luminance, etc. were added
+ * with GL_ARB_framebuffer_object.
+ */
+ switch (internalFormat) {
+ case GL_ALPHA:
+ case GL_ALPHA4:
+ case GL_ALPHA8:
+ case GL_ALPHA12:
+ case GL_ALPHA16:
+ return ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
+ case GL_LUMINANCE:
+ case GL_LUMINANCE4:
+ case GL_LUMINANCE8:
+ case GL_LUMINANCE12:
+ case GL_LUMINANCE16:
+ return ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE4_ALPHA4:
+ case GL_LUMINANCE6_ALPHA2:
+ case GL_LUMINANCE8_ALPHA8:
+ case GL_LUMINANCE12_ALPHA4:
+ case GL_LUMINANCE12_ALPHA12:
+ case GL_LUMINANCE16_ALPHA16:
+ return ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
+ case GL_INTENSITY:
+ case GL_INTENSITY4:
+ case GL_INTENSITY8:
+ case GL_INTENSITY12:
+ case GL_INTENSITY16:
+ return ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
+ case GL_RGB:
+ case GL_R3_G3_B2:
+ case GL_RGB4:
+ case GL_RGB5:
+ case GL_RGB8:
+ case GL_RGB10:
+ case GL_RGB12:
+ case GL_RGB16:
+ case GL_SRGB8_EXT:
+ return GL_RGB;
+ case GL_RGBA:
+ case GL_RGBA2:
+ case GL_RGBA4:
+ case GL_RGB5_A1:
+ case GL_RGBA8:
+ case GL_RGB10_A2:
+ case GL_RGBA12:
+ case GL_RGBA16:
+ case GL_RGBA16_SNORM:
+ case GL_SRGB8_ALPHA8_EXT:
+ return GL_RGBA;
+ case GL_STENCIL_INDEX:
+ case GL_STENCIL_INDEX1_EXT:
+ case GL_STENCIL_INDEX4_EXT:
+ case GL_STENCIL_INDEX8_EXT:
+ case GL_STENCIL_INDEX16_EXT:
+ return GL_STENCIL_INDEX;
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_COMPONENT16:
+ case GL_DEPTH_COMPONENT24:
+ case GL_DEPTH_COMPONENT32:
+ return GL_DEPTH_COMPONENT;
+ case GL_DEPTH_STENCIL_EXT:
+ case GL_DEPTH24_STENCIL8_EXT:
+ if (ctx->Extensions.EXT_packed_depth_stencil)
+ return GL_DEPTH_STENCIL_EXT;
+ else
+ return 0;
+ case GL_RED:
+ case GL_R8:
+ case GL_R16:
+ return ctx->Extensions.ARB_texture_rg ? GL_RED : 0;
+ case GL_RG:
+ case GL_RG8:
+ case GL_RG16:
+ return ctx->Extensions.ARB_texture_rg ? GL_RG : 0;
+ /* XXX add floating point and integer formats eventually */
+ default:
+ return 0;
+ }
+}
+
+
+/** sentinal value, see below */
+#define NO_SAMPLES 1000
+
+
+/**
+ * Helper function used by _mesa_RenderbufferStorageEXT() and
+ * _mesa_RenderbufferStorageMultisample().
+ * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
+ */
+static void
+renderbuffer_storage(GLenum target, GLenum internalFormat,
+ GLsizei width, GLsizei height, GLsizei samples)
+{
+ const char *func = samples == NO_SAMPLES ?
+ "glRenderbufferStorage" : "RenderbufferStorageMultisample";
+ struct gl_renderbuffer *rb;
+ GLenum baseFormat;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target != GL_RENDERBUFFER_EXT) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
+ return;
+ }
+
+ baseFormat = _mesa_base_fbo_format(ctx, internalFormat);
+ if (baseFormat == 0) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat)", func);
+ return;
+ }
+
+ if (width < 1 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(width)", func);
+ return;
+ }
+
+ if (height < 1 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(height)", func);
+ return;
+ }
+
+ if (samples == NO_SAMPLES) {
+ /* NumSamples == 0 indicates non-multisampling */
+ samples = 0;
+ }
+ else if (samples > (GLsizei) ctx->Const.MaxSamples) {
+ /* note: driver may choose to use more samples than what's requested */
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(samples)", func);
+ return;
+ }
+
+ rb = ctx->CurrentRenderbuffer;
+ if (!rb) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
+ return;
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+ if (rb->InternalFormat == internalFormat &&
+ rb->Width == (GLuint) width &&
+ rb->Height == (GLuint) height) {
+ /* no change in allocation needed */
+ return;
+ }
+
+ /* These MUST get set by the AllocStorage func */
+ rb->Format = MESA_FORMAT_NONE;
+ rb->NumSamples = samples;
+
+ /* Now allocate the storage */
+ ASSERT(rb->AllocStorage);
+ if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) {
+ /* No error - check/set fields now */
+ assert(rb->Format != MESA_FORMAT_NONE);
+ assert(rb->Width == (GLuint) width);
+ assert(rb->Height == (GLuint) height);
+ rb->InternalFormat = internalFormat;
+ rb->_BaseFormat = baseFormat;
+ assert(rb->_BaseFormat != 0);
+ }
+ else {
+ /* Probably ran out of memory - clear the fields */
+ rb->Width = 0;
+ rb->Height = 0;
+ rb->Format = MESA_FORMAT_NONE;
+ rb->InternalFormat = GL_NONE;
+ rb->_BaseFormat = GL_NONE;
+ rb->NumSamples = 0;
+ }
+
+ /*
+ test_framebuffer_completeness(ctx, fb);
+ */
+ /* XXX if this renderbuffer is attached anywhere, invalidate attachment
+ * points???
+ */
+}
+
+
+#if FEATURE_OES_EGL_image
+void GLAPIENTRY
+_mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
+{
+ struct gl_renderbuffer *rb;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!ctx->Extensions.OES_EGL_image) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glEGLImageTargetRenderbufferStorageOES(unsupported)");
+ return;
+ }
+
+ if (target != GL_RENDERBUFFER) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "EGLImageTargetRenderbufferStorageOES");
+ return;
+ }
+
+ rb = ctx->CurrentRenderbuffer;
+ if (!rb) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "EGLImageTargetRenderbufferStorageOES");
+ return;
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+ ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image);
+}
+#endif
+
+
+/**
+ * Helper function for _mesa_GetRenderbufferParameterivEXT() and
+ * _mesa_GetFramebufferAttachmentParameterivEXT()
+ * We have to be careful to respect the base format. For example, if a
+ * renderbuffer/texture was created with internalFormat=GL_RGB but the
+ * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
+ * we need to return zero.
+ */
+static GLint
+get_component_bits(GLenum pname, GLenum baseFormat, gl_format format)
+{
+ switch (pname) {
+ case GL_RENDERBUFFER_RED_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
+ if (baseFormat == GL_RGB || baseFormat == GL_RGBA ||
+ baseFormat == GL_RG || baseFormat == GL_RED)
+ return _mesa_get_format_bits(format, pname);
+ else
+ return 0;
+ case GL_RENDERBUFFER_GREEN_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
+ if (baseFormat == GL_RGB || baseFormat == GL_RGBA || baseFormat == GL_RG)
+ return _mesa_get_format_bits(format, pname);
+ else
+ return 0;
+ case GL_RENDERBUFFER_BLUE_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
+ if (baseFormat == GL_RGB || baseFormat == GL_RGBA)
+ return _mesa_get_format_bits(format, pname);
+ else
+ return 0;
+ case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
+ if (baseFormat == GL_RGBA || baseFormat == GL_ALPHA ||
+ baseFormat == GL_LUMINANCE_ALPHA)
+ return _mesa_get_format_bits(format, pname);
+ else
+ return 0;
+ case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
+ if (baseFormat == GL_DEPTH_COMPONENT || baseFormat == GL_DEPTH_STENCIL)
+ return _mesa_get_format_bits(format, pname);
+ else
+ return 0;
+ case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
+ if (baseFormat == GL_STENCIL_INDEX || baseFormat == GL_DEPTH_STENCIL)
+ return _mesa_get_format_bits(format, pname);
+ else
+ return 0;
+ default:
+ return 0;
+ }
+}
+
+
+
+void GLAPIENTRY
+_mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
+ GLsizei width, GLsizei height)
+{
+ /* GL_ARB_fbo says calling this function is equivalent to calling
+ * glRenderbufferStorageMultisample() with samples=0. We pass in
+ * a token value here just for error reporting purposes.
+ */
+ renderbuffer_storage(target, internalFormat, width, height, NO_SAMPLES);
+}
+
+
+void GLAPIENTRY
+_mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples,
+ GLenum internalFormat,
+ GLsizei width, GLsizei height)
+{
+ renderbuffer_storage(target, internalFormat, width, height, samples);
+}
+
+
+/**
+ * OpenGL ES version of glRenderBufferStorage.
+ */
+void GLAPIENTRY
+_es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
+ GLsizei width, GLsizei height)
+{
+ switch (internalFormat) {
+ case GL_RGB565:
+ /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
+ /* choose a closest format */
+ internalFormat = GL_RGB5;
+ break;
+ default:
+ break;
+ }
+
+ renderbuffer_storage(target, internalFormat, width, height, 0);
+}
+
+
+void GLAPIENTRY
+_mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params)
+{
+ struct gl_renderbuffer *rb;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target != GL_RENDERBUFFER_EXT) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetRenderbufferParameterivEXT(target)");
+ return;
+ }
+
+ rb = ctx->CurrentRenderbuffer;
+ if (!rb) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetRenderbufferParameterivEXT");
+ return;
+ }
+
+ /* No need to flush here since we're just quering state which is
+ * not effected by rendering.
+ */
+
+ switch (pname) {
+ case GL_RENDERBUFFER_WIDTH_EXT:
+ *params = rb->Width;
+ return;
+ case GL_RENDERBUFFER_HEIGHT_EXT:
+ *params = rb->Height;
+ return;
+ case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT:
+ *params = rb->InternalFormat;
+ return;
+ case GL_RENDERBUFFER_RED_SIZE_EXT:
+ case GL_RENDERBUFFER_GREEN_SIZE_EXT:
+ case GL_RENDERBUFFER_BLUE_SIZE_EXT:
+ case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
+ case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
+ case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
+ *params = get_component_bits(pname, rb->_BaseFormat, rb->Format);
+ break;
+ case GL_RENDERBUFFER_SAMPLES:
+ if (ctx->Extensions.ARB_framebuffer_object) {
+ *params = rb->NumSamples;
+ break;
+ }
+ /* fallthrough */
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetRenderbufferParameterivEXT(target)");
+ return;
+ }
+}
+
+
+GLboolean GLAPIENTRY
+_mesa_IsFramebufferEXT(GLuint framebuffer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
+ if (framebuffer) {
+ struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer);
+ if (rb != NULL && rb != &DummyFramebuffer)
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+}
+
+
+/**
+ * Check if any of the attachments of the given framebuffer are textures
+ * (render to texture). Call ctx->Driver.RenderTexture() for such
+ * attachments.
+ */
+static void
+check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+ GLuint i;
+ ASSERT(ctx->Driver.RenderTexture);
+
+ if (fb->Name == 0)
+ return; /* can't render to texture with winsys framebuffers */
+
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ struct gl_renderbuffer_attachment *att = fb->Attachment + i;
+ struct gl_texture_object *texObj = att->Texture;
+ if (texObj
+ && texObj->Image[att->CubeMapFace][att->TextureLevel]) {
+ ctx->Driver.RenderTexture(ctx, fb, att);
+ }
+ }
+}
+
+
+/**
+ * Examine all the framebuffer's attachments to see if any are textures.
+ * If so, call ctx->Driver.FinishRenderTexture() for each texture to
+ * notify the device driver that the texture image may have changed.
+ */
+static void
+check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+ if (fb->Name == 0)
+ return; /* can't render to texture with winsys framebuffers */
+
+ if (ctx->Driver.FinishRenderTexture) {
+ GLuint i;
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ struct gl_renderbuffer_attachment *att = fb->Attachment + i;
+ if (att->Texture && att->Renderbuffer) {
+ ctx->Driver.FinishRenderTexture(ctx, att);
+ }
+ }
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
+{
+ struct gl_framebuffer *newDrawFb, *newReadFb;
+ struct gl_framebuffer *oldDrawFb, *oldReadFb;
+ GLboolean bindReadBuf, bindDrawBuf;
+ GET_CURRENT_CONTEXT(ctx);
+
+#ifdef DEBUG
+ if (ctx->Extensions.ARB_framebuffer_object) {
+ ASSERT(ctx->Extensions.EXT_framebuffer_object);
+ ASSERT(ctx->Extensions.EXT_framebuffer_blit);
+ }
+#endif
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!ctx->Extensions.EXT_framebuffer_object) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBindFramebufferEXT(unsupported)");
+ return;
+ }
+
+ switch (target) {
+#if FEATURE_EXT_framebuffer_blit
+ case GL_DRAW_FRAMEBUFFER_EXT:
+ if (!ctx->Extensions.EXT_framebuffer_blit) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
+ return;
+ }
+ bindDrawBuf = GL_TRUE;
+ bindReadBuf = GL_FALSE;
+ break;
+ case GL_READ_FRAMEBUFFER_EXT:
+ if (!ctx->Extensions.EXT_framebuffer_blit) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
+ return;
+ }
+ bindDrawBuf = GL_FALSE;
+ bindReadBuf = GL_TRUE;
+ break;
+#endif
+ case GL_FRAMEBUFFER_EXT:
+ bindDrawBuf = GL_TRUE;
+ bindReadBuf = GL_TRUE;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
+ return;
+ }
+
+ if (framebuffer) {
+ /* Binding a user-created framebuffer object */
+ newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer);
+ if (newDrawFb == &DummyFramebuffer) {
+ /* ID was reserved, but no real framebuffer object made yet */
+ newDrawFb = NULL;
+ }
+ else if (!newDrawFb && ctx->Extensions.ARB_framebuffer_object) {
+ /* All FBO IDs must be Gen'd */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)");
+ return;
+ }
+
+ if (!newDrawFb) {
+ /* create new framebuffer object */
+ newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer);
+ if (!newDrawFb) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT");
+ return;
+ }
+ _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb);
+ }
+ newReadFb = newDrawFb;
+ }
+ else {
+ /* Binding the window system framebuffer (which was originally set
+ * with MakeCurrent).
+ */
+ newDrawFb = ctx->WinSysDrawBuffer;
+ newReadFb = ctx->WinSysReadBuffer;
+ }
+
+ ASSERT(newDrawFb);
+ ASSERT(newDrawFb != &DummyFramebuffer);
+
+ /* save pointers to current/old framebuffers */
+ oldDrawFb = ctx->DrawBuffer;
+ oldReadFb = ctx->ReadBuffer;
+
+ /* check if really changing bindings */
+ if (oldDrawFb == newDrawFb)
+ bindDrawBuf = GL_FALSE;
+ if (oldReadFb == newReadFb)
+ bindReadBuf = GL_FALSE;
+
+ /*
+ * OK, now bind the new Draw/Read framebuffers, if they're changing.
+ *
+ * We also check if we're beginning and/or ending render-to-texture.
+ * When a framebuffer with texture attachments is unbound, call
+ * ctx->Driver.FinishRenderTexture().
+ * When a framebuffer with texture attachments is bound, call
+ * ctx->Driver.RenderTexture().
+ *
+ * Note that if the ReadBuffer has texture attachments we don't consider
+ * that a render-to-texture case.
+ */
+ if (bindReadBuf) {
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+ /* check if old readbuffer was render-to-texture */
+ check_end_texture_render(ctx, oldReadFb);
+
+ _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb);
+ }
+
+ if (bindDrawBuf) {
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+ /* check if old read/draw buffers were render-to-texture */
+ if (!bindReadBuf)
+ check_end_texture_render(ctx, oldReadFb);
+
+ if (oldDrawFb != oldReadFb)
+ check_end_texture_render(ctx, oldDrawFb);
+
+ /* check if newly bound framebuffer has any texture attachments */
+ check_begin_texture_render(ctx, newDrawFb);
+
+ _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb);
+ }
+
+ if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) {
+ ctx->Driver.BindFramebuffer(ctx, target, newDrawFb, newReadFb);
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers)
+{
+ GLint i;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+ for (i = 0; i < n; i++) {
+ if (framebuffers[i] > 0) {
+ struct gl_framebuffer *fb;
+ fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]);
+ if (fb) {
+ ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]);
+
+ /* check if deleting currently bound framebuffer object */
+ if (ctx->Extensions.EXT_framebuffer_blit) {
+ /* separate draw/read binding points */
+ if (fb == ctx->DrawBuffer) {
+ /* bind default */
+ ASSERT(fb->RefCount >= 2);
+ _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
+ }
+ if (fb == ctx->ReadBuffer) {
+ /* bind default */
+ ASSERT(fb->RefCount >= 2);
+ _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
+ }
+ }
+ else {
+ /* only one binding point for read/draw buffers */
+ if (fb == ctx->DrawBuffer || fb == ctx->ReadBuffer) {
+ /* bind default */
+ ASSERT(fb->RefCount >= 2);
+ _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ }
+ }
+
+ /* remove from hash table immediately, to free the ID */
+ _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]);
+
+ if (fb != &DummyFramebuffer) {
+ /* But the object will not be freed until it's no longer
+ * bound in any context.
+ */
+ _mesa_reference_framebuffer(&fb, NULL);
+ }
+ }
+ }
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GenFramebuffersEXT(GLsizei n, GLuint *framebuffers)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint first;
+ GLint i;
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGenFramebuffersEXT(n)");
+ return;
+ }
+
+ if (!framebuffers)
+ return;
+
+ first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n);
+
+ for (i = 0; i < n; i++) {
+ GLuint name = first + i;
+ framebuffers[i] = name;
+ /* insert dummy placeholder into hash table */
+ _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+ _mesa_HashInsert(ctx->Shared->FrameBuffers, name, &DummyFramebuffer);
+ _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+ }
+}
+
+
+
+GLenum GLAPIENTRY
+_mesa_CheckFramebufferStatusEXT(GLenum target)
+{
+ struct gl_framebuffer *buffer;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
+
+ buffer = get_framebuffer_target(ctx, target);
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
+ return 0;
+ }
+
+ if (buffer->Name == 0) {
+ /* The window system / default framebuffer is always complete */
+ return GL_FRAMEBUFFER_COMPLETE_EXT;
+ }
+
+ /* No need to flush here */
+
+ if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
+ _mesa_test_framebuffer_completeness(ctx, buffer);
+ }
+
+ return buffer->_Status;
+}
+
+
+
+/**
+ * Common code called by glFramebufferTexture1D/2D/3DEXT().
+ */
+static void
+framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
+ GLenum attachment, GLenum textarget, GLuint texture,
+ GLint level, GLint zoffset)
+{
+ struct gl_renderbuffer_attachment *att;
+ struct gl_texture_object *texObj = NULL;
+ struct gl_framebuffer *fb;
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ fb = get_framebuffer_target(ctx, target);
+ if (!fb) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glFramebufferTexture%sEXT(target=0x%x)", caller, target);
+ return;
+ }
+
+ /* check framebuffer binding */
+ if (fb->Name == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glFramebufferTexture%sEXT", caller);
+ return;
+ }
+
+
+ /* The textarget, level, and zoffset parameters are only validated if
+ * texture is non-zero.
+ */
+ if (texture) {
+ GLboolean err = GL_TRUE;
+
+ texObj = _mesa_lookup_texture(ctx, texture);
+ if (texObj != NULL) {
+ if (textarget == 0) {
+ /* XXX what's the purpose of this? */
+ err = (texObj->Target != GL_TEXTURE_3D) &&
+ (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT) &&
+ (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT);
+ }
+ else {
+ err = (texObj->Target == GL_TEXTURE_CUBE_MAP)
+ ? !IS_CUBE_FACE(textarget)
+ : (texObj->Target != textarget);
+ }
+ }
+ else {
+ /* can't render to a non-existant texture */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glFramebufferTexture%sEXT(non existant texture)",
+ caller);
+ return;
+ }
+
+ if (err) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glFramebufferTexture%sEXT(texture target mismatch)",
+ caller);
+ return;
+ }
+
+ if (texObj->Target == GL_TEXTURE_3D) {
+ const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
+ if (zoffset < 0 || zoffset >= maxSize) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glFramebufferTexture%sEXT(zoffset)", caller);
+ return;
+ }
+ }
+ else if ((texObj->Target == GL_TEXTURE_1D_ARRAY_EXT) ||
+ (texObj->Target == GL_TEXTURE_2D_ARRAY_EXT)) {
+ if (zoffset < 0 || zoffset >= ctx->Const.MaxArrayTextureLayers) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glFramebufferTexture%sEXT(layer)", caller);
+ return;
+ }
+ }
+
+ if ((level < 0) ||
+ (level >= _mesa_max_texture_levels(ctx, texObj->Target))) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glFramebufferTexture%sEXT(level)", caller);
+ return;
+ }
+ }
+
+ att = _mesa_get_attachment(ctx, fb, attachment);
+ if (att == NULL) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glFramebufferTexture%sEXT(attachment)", caller);
+ return;
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+ _glthread_LOCK_MUTEX(fb->Mutex);
+ if (texObj) {
+ _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget,
+ level, zoffset);
+ /* Set the render-to-texture flag. We'll check this flag in
+ * glTexImage() and friends to determine if we need to revalidate
+ * any FBOs that might be rendering into this texture.
+ * This flag never gets cleared since it's non-trivial to determine
+ * when all FBOs might be done rendering to this texture. That's OK
+ * though since it's uncommon to render to a texture then repeatedly
+ * call glTexImage() to change images in the texture.
+ */
+ texObj->_RenderToTexture = GL_TRUE;
+ }
+ else {
+ _mesa_remove_attachment(ctx, att);
+ }
+
+ invalidate_framebuffer(fb);
+
+ _glthread_UNLOCK_MUTEX(fb->Mutex);
+}
+
+
+
+void GLAPIENTRY
+_mesa_FramebufferTexture1DEXT(GLenum target, GLenum attachment,
+ GLenum textarget, GLuint texture, GLint level)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if ((texture != 0) && (textarget != GL_TEXTURE_1D)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glFramebufferTexture1DEXT(textarget)");
+ return;
+ }
+
+ framebuffer_texture(ctx, "1D", target, attachment, textarget, texture,
+ level, 0);
+}
+
+
+void GLAPIENTRY
+_mesa_FramebufferTexture2DEXT(GLenum target, GLenum attachment,
+ GLenum textarget, GLuint texture, GLint level)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if ((texture != 0) &&
+ (textarget != GL_TEXTURE_2D) &&
+ (textarget != GL_TEXTURE_RECTANGLE_ARB) &&
+ (!IS_CUBE_FACE(textarget))) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glFramebufferTexture2DEXT(textarget=0x%x)", textarget);
+ return;
+ }
+
+ framebuffer_texture(ctx, "2D", target, attachment, textarget, texture,
+ level, 0);
+}
+
+
+void GLAPIENTRY
+_mesa_FramebufferTexture3DEXT(GLenum target, GLenum attachment,
+ GLenum textarget, GLuint texture,
+ GLint level, GLint zoffset)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if ((texture != 0) && (textarget != GL_TEXTURE_3D)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glFramebufferTexture3DEXT(textarget)");
+ return;
+ }
+
+ framebuffer_texture(ctx, "3D", target, attachment, textarget, texture,
+ level, zoffset);
+}
+
+
+void GLAPIENTRY
+_mesa_FramebufferTextureLayerEXT(GLenum target, GLenum attachment,
+ GLuint texture, GLint level, GLint layer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
+ level, layer);
+}
+
+
+void GLAPIENTRY
+_mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment,
+ GLenum renderbufferTarget,
+ GLuint renderbuffer)
+{
+ struct gl_renderbuffer_attachment *att;
+ struct gl_framebuffer *fb;
+ struct gl_renderbuffer *rb;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ fb = get_framebuffer_target(ctx, target);
+ if (!fb) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glFramebufferRenderbufferEXT(target)");
+ return;
+ }
+
+ if (renderbufferTarget != GL_RENDERBUFFER_EXT) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glFramebufferRenderbufferEXT(renderbufferTarget)");
+ return;
+ }
+
+ if (fb->Name == 0) {
+ /* Can't attach new renderbuffers to a window system framebuffer */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT");
+ return;
+ }
+
+ att = _mesa_get_attachment(ctx, fb, attachment);
+ if (att == NULL) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glFramebufferRenderbufferEXT(invalid attachment %s)",
+ _mesa_lookup_enum_by_nr(attachment));
+ return;
+ }
+
+ if (renderbuffer) {
+ rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
+ if (!rb) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glFramebufferRenderbufferEXT(non-existant"
+ " renderbuffer %u)", renderbuffer);
+ return;
+ }
+ else if (rb == &DummyRenderbuffer) {
+ /* This is what NVIDIA does */
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glFramebufferRenderbufferEXT(renderbuffer %u)",
+ renderbuffer);
+ return;
+ }
+ }
+ else {
+ /* remove renderbuffer attachment */
+ rb = NULL;
+ }
+
+ if (attachment == GL_DEPTH_STENCIL_ATTACHMENT &&
+ rb && rb->Format != MESA_FORMAT_NONE) {
+ /* make sure the renderbuffer is a depth/stencil format */
+ const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
+ if (baseFormat != GL_DEPTH_STENCIL) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glFramebufferRenderbufferEXT(renderbuffer"
+ " is not DEPTH_STENCIL format)");
+ return;
+ }
+ }
+
+
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+ assert(ctx->Driver.FramebufferRenderbuffer);
+ ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb);
+
+ /* Some subsequent GL commands may depend on the framebuffer's visual
+ * after the binding is updated. Update visual info now.
+ */
+ _mesa_update_framebuffer_visual(ctx, fb);
+}
+
+
+void GLAPIENTRY
+_mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment,
+ GLenum pname, GLint *params)
+{
+ const struct gl_renderbuffer_attachment *att;
+ struct gl_framebuffer *buffer;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ buffer = get_framebuffer_target(ctx, target);
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetFramebufferAttachmentParameterivEXT(target)");
+ return;
+ }
+
+ if (buffer->Name == 0) {
+ /* the default / window-system FBO */
+ att = _mesa_get_fb0_attachment(ctx, buffer, attachment);
+ }
+ else {
+ /* user-created framebuffer FBO */
+ att = _mesa_get_attachment(ctx, buffer, attachment);
+ }
+
+ if (att == NULL) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetFramebufferAttachmentParameterivEXT(attachment)");
+ return;
+ }
+
+ if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
+ /* the depth and stencil attachments must point to the same buffer */
+ const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt;
+ depthAtt = _mesa_get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT);
+ stencilAtt = _mesa_get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT);
+ if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
+ " attachments differ)");
+ return;
+ }
+ }
+
+ /* No need to flush here */
+
+ switch (pname) {
+ case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT:
+ *params = buffer->Name == 0 ? GL_FRAMEBUFFER_DEFAULT : att->Type;
+ return;
+ case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT:
+ if (att->Type == GL_RENDERBUFFER_EXT) {
+ *params = att->Renderbuffer->Name;
+ }
+ else if (att->Type == GL_TEXTURE) {
+ *params = att->Texture->Name;
+ }
+ else {
+ assert(att->Type == GL_NONE);
+ *params = 0;
+ }
+ return;
+ case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT:
+ if (att->Type == GL_TEXTURE) {
+ *params = att->TextureLevel;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetFramebufferAttachmentParameterivEXT(pname)");
+ }
+ return;
+ case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT:
+ if (att->Type == GL_TEXTURE) {
+ if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) {
+ *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace;
+ }
+ else {
+ *params = 0;
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetFramebufferAttachmentParameterivEXT(pname)");
+ }
+ return;
+ case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT:
+ if (att->Type == GL_TEXTURE) {
+ if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) {
+ *params = att->Zoffset;
+ }
+ else {
+ *params = 0;
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetFramebufferAttachmentParameterivEXT(pname)");
+ }
+ return;
+ case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
+ if (!ctx->Extensions.ARB_framebuffer_object) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetFramebufferAttachmentParameterivEXT(pname)");
+ }
+ else {
+ if (ctx->Extensions.EXT_framebuffer_sRGB && ctx->Const.sRGBCapable) {
+ *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format);
+ }
+ else {
+ /* According to ARB_framebuffer_sRGB, we should return LINEAR
+ * if the sRGB conversion is unsupported. */
+ *params = GL_LINEAR;
+ }
+ }
+ return;
+ case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
+ if (!ctx->Extensions.ARB_framebuffer_object) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetFramebufferAttachmentParameterivEXT(pname)");
+ return;
+ }
+ else {
+ gl_format format = att->Renderbuffer->Format;
+ if (format == MESA_FORMAT_CI8 || format == MESA_FORMAT_S8) {
+ /* special cases */
+ *params = GL_INDEX;
+ }
+ else {
+ *params = _mesa_get_format_datatype(format);
+ }
+ }
+ return;
+ case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
+ case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
+ case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
+ case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
+ case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
+ case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
+ if (!ctx->Extensions.ARB_framebuffer_object) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetFramebufferAttachmentParameterivEXT(pname)");
+ }
+ else if (att->Texture) {
+ const struct gl_texture_image *texImage =
+ _mesa_select_tex_image(ctx, att->Texture, att->Texture->Target,
+ att->TextureLevel);
+ if (texImage) {
+ *params = get_component_bits(pname, texImage->_BaseFormat,
+ texImage->TexFormat);
+ }
+ else {
+ *params = 0;
+ }
+ }
+ else if (att->Renderbuffer) {
+ *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat,
+ att->Renderbuffer->Format);
+ }
+ else {
+ *params = 0;
+ }
+ return;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetFramebufferAttachmentParameterivEXT(pname)");
+ return;
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GenerateMipmapEXT(GLenum target)
+{
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+ switch (target) {
+ case GL_TEXTURE_1D:
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_3D:
+ case GL_TEXTURE_CUBE_MAP:
+ /* OK, legal value */
+ break;
+ default:
+ /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target)");
+ return;
+ }
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+
+ if (texObj->BaseLevel >= texObj->MaxLevel) {
+ /* nothing to do */
+ return;
+ }
+
+ if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
+ !_mesa_cube_complete(texObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGenerateMipmap(incomplete cube map)");
+ return;
+ }
+
+ _mesa_lock_texture(ctx, texObj);
+ if (target == GL_TEXTURE_CUBE_MAP) {
+ GLuint face;
+ for (face = 0; face < 6; face++)
+ ctx->Driver.GenerateMipmap(ctx,
+ GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face,
+ texObj);
+ }
+ else {
+ ctx->Driver.GenerateMipmap(ctx, target, texObj);
+ }
+ _mesa_unlock_texture(ctx, texObj);
+}
+
+
+#if FEATURE_EXT_framebuffer_blit
+
+static const struct gl_renderbuffer_attachment *
+find_attachment(const struct gl_framebuffer *fb,
+ const struct gl_renderbuffer *rb)
+{
+ GLuint i;
+ for (i = 0; i < Elements(fb->Attachment); i++) {
+ if (fb->Attachment[i].Renderbuffer == rb)
+ return &fb->Attachment[i];
+ }
+ return NULL;
+}
+
+
+
+/**
+ * Blit rectangular region, optionally from one framebuffer to another.
+ *
+ * Note, if the src buffer is multisampled and the dest is not, this is
+ * when the samples must be resolved to a single color.
+ */
+void GLAPIENTRY
+_mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
+ GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
+ GLbitfield mask, GLenum filter)
+{
+ const GLbitfield legalMaskBits = (GL_COLOR_BUFFER_BIT |
+ GL_DEPTH_BUFFER_BIT |
+ GL_STENCIL_BUFFER_BIT);
+ const struct gl_framebuffer *readFb, *drawFb;
+ const struct gl_renderbuffer *colorReadRb, *colorDrawRb;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+ FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx,
+ "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
+ srcX0, srcY0, srcX1, srcY1,
+ dstX0, dstY0, dstX1, dstY1,
+ mask, _mesa_lookup_enum_by_nr(filter));
+
+ if (ctx->NewState) {
+ _mesa_update_state(ctx);
+ }
+
+ readFb = ctx->ReadBuffer;
+ drawFb = ctx->DrawBuffer;
+
+ if (!readFb || !drawFb) {
+ /* This will normally never happen but someday we may want to
+ * support MakeCurrent() with no drawables.
+ */
+ return;
+ }
+
+ /* check for complete framebuffers */
+ if (drawFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
+ readFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+ "glBlitFramebufferEXT(incomplete draw/read buffers)");
+ return;
+ }
+
+ if (filter != GL_NEAREST && filter != GL_LINEAR) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(filter)");
+ return;
+ }
+
+ if (mask & ~legalMaskBits) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glBlitFramebufferEXT(mask)");
+ return;
+ }
+
+ /* depth/stencil must be blitted with nearest filtering */
+ if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
+ && filter != GL_NEAREST) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
+ return;
+ }
+
+ /* get color read/draw renderbuffers */
+ if (mask & GL_COLOR_BUFFER_BIT) {
+ colorReadRb = readFb->_ColorReadBuffer;
+ colorDrawRb = drawFb->_ColorDrawBuffers[0];
+ }
+ else {
+ colorReadRb = colorDrawRb = NULL;
+ }
+
+ if (mask & GL_STENCIL_BUFFER_BIT) {
+ struct gl_renderbuffer *readRb = readFb->_StencilBuffer;
+ struct gl_renderbuffer *drawRb = drawFb->_StencilBuffer;
+ if (!readRb ||
+ !drawRb ||
+ _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) !=
+ _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBlitFramebufferEXT(stencil buffer size mismatch");
+ return;
+ }
+ }
+
+ if (mask & GL_DEPTH_BUFFER_BIT) {
+ struct gl_renderbuffer *readRb = readFb->_DepthBuffer;
+ struct gl_renderbuffer *drawRb = drawFb->_DepthBuffer;
+ if (!readRb ||
+ !drawRb ||
+ _mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) !=
+ _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBlitFramebufferEXT(depth buffer size mismatch");
+ return;
+ }
+ }
+
+ if (readFb->Visual.samples > 0 &&
+ drawFb->Visual.samples > 0 &&
+ readFb->Visual.samples != drawFb->Visual.samples) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBlitFramebufferEXT(mismatched samples");
+ return;
+ }
+
+ /* extra checks for multisample copies... */
+ if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) {
+ /* src and dest region sizes must be the same */
+ if (srcX1 - srcX0 != dstX1 - dstX0 ||
+ srcY1 - srcY0 != dstY1 - dstY0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBlitFramebufferEXT(bad src/dst multisample region sizes");
+ return;
+ }
+
+ /* color formats must match */
+ if (colorReadRb &&
+ colorDrawRb &&
+ colorReadRb->Format != colorDrawRb->Format) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
+ return;
+ }
+ }
+
+ if (!ctx->Extensions.EXT_framebuffer_blit) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT");
+ return;
+ }
+
+ /* Debug code */
+ if (DEBUG_BLIT) {
+ printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
+ " 0x%x, 0x%x)\n",
+ srcX0, srcY0, srcX1, srcY1,
+ dstX0, dstY0, dstX1, dstY1,
+ mask, filter);
+ if (colorReadRb) {
+ const struct gl_renderbuffer_attachment *att;
+
+ att = find_attachment(readFb, colorReadRb);
+ printf(" Src FBO %u RB %u (%dx%d) ",
+ readFb->Name, colorReadRb->Name,
+ colorReadRb->Width, colorReadRb->Height);
+ if (att && att->Texture) {
+ printf("Tex %u tgt 0x%x level %u face %u",
+ att->Texture->Name,
+ att->Texture->Target,
+ att->TextureLevel,
+ att->CubeMapFace);
+ }
+ printf("\n");
+
+ att = find_attachment(drawFb, colorDrawRb);
+ printf(" Dst FBO %u RB %u (%dx%d) ",
+ drawFb->Name, colorDrawRb->Name,
+ colorDrawRb->Width, colorDrawRb->Height);
+ if (att && att->Texture) {
+ printf("Tex %u tgt 0x%x level %u face %u",
+ att->Texture->Name,
+ att->Texture->Target,
+ att->TextureLevel,
+ att->CubeMapFace);
+ }
+ printf("\n");
+ }
+ }
+
+ ASSERT(ctx->Driver.BlitFramebuffer);
+ ctx->Driver.BlitFramebuffer(ctx,
+ srcX0, srcY0, srcX1, srcY1,
+ dstX0, dstY0, dstX1, dstY1,
+ mask, filter);
+}
+#endif /* FEATURE_EXT_framebuffer_blit */
+
+#if FEATURE_ARB_geometry_shader4
+void GLAPIENTRY
+_mesa_FramebufferTextureARB(GLenum target, GLenum attachment,
+ GLuint texture, GLint level)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glFramebufferTextureARB "
+ "not implemented!");
+}
+
+void GLAPIENTRY
+_mesa_FramebufferTextureFaceARB(GLenum target, GLenum attachment,
+ GLuint texture, GLint level, GLenum face)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glFramebufferTextureFaceARB "
+ "not implemented!");
+}
+#endif /* FEATURE_ARB_geometry_shader4 */
diff --git a/mesalib/src/mesa/main/formats.c b/mesalib/src/mesa/main/formats.c
index 947db84a6..1d7bdad24 100644
--- a/mesalib/src/mesa/main/formats.c
+++ b/mesalib/src/mesa/main/formats.c
@@ -1,1658 +1,1658 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.7
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (c) 2008-2009 VMware, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "imports.h"
-#include "formats.h"
-#include "mfeatures.h"
-
-
-/**
- * Information about texture formats.
- */
-struct gl_format_info
-{
- gl_format Name;
-
- /** text name for debugging */
- const char *StrName;
-
- /**
- * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
- * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
- * GL_COLOR_INDEX, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX,
- * GL_DEPTH_STENCIL, GL_DUDV_ATI.
- */
- GLenum BaseFormat;
-
- /**
- * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
- * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
- */
- GLenum DataType;
-
- GLubyte RedBits;
- GLubyte GreenBits;
- GLubyte BlueBits;
- GLubyte AlphaBits;
- GLubyte LuminanceBits;
- GLubyte IntensityBits;
- GLubyte IndexBits;
- GLubyte DepthBits;
- GLubyte StencilBits;
-
- /**
- * To describe compressed formats. If not compressed, Width=Height=1.
- */
- GLubyte BlockWidth, BlockHeight;
- GLubyte BytesPerBlock;
-};
-
-
-/**
- * Info about each format.
- * These must be in the same order as the MESA_FORMAT_* enums so that
- * we can do lookups without searching.
- */
-static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
-{
- {
- MESA_FORMAT_NONE, /* Name */
- "MESA_FORMAT_NONE", /* StrName */
- GL_NONE, /* BaseFormat */
- GL_NONE, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 0, 0, 0 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_RGBA8888, /* Name */
- "MESA_FORMAT_RGBA8888", /* StrName */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_RGBA8888_REV, /* Name */
- "MESA_FORMAT_RGBA8888_REV", /* StrName */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_ARGB8888, /* Name */
- "MESA_FORMAT_ARGB8888", /* StrName */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_ARGB8888_REV, /* Name */
- "MESA_FORMAT_ARGB8888_REV", /* StrName */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_XRGB8888, /* Name */
- "MESA_FORMAT_XRGB8888", /* StrName */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_XRGB8888_REV, /* Name */
- "MESA_FORMAT_XRGB8888_REV", /* StrName */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_RGB888, /* Name */
- "MESA_FORMAT_RGB888", /* StrName */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 3 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_BGR888, /* Name */
- "MESA_FORMAT_BGR888", /* StrName */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 3 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_RGB565, /* Name */
- "MESA_FORMAT_RGB565", /* StrName */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_RGB565_REV, /* Name */
- "MESA_FORMAT_RGB565_REV", /* StrName */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_ARGB4444, /* Name */
- "MESA_FORMAT_ARGB4444", /* StrName */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_ARGB4444_REV, /* Name */
- "MESA_FORMAT_ARGB4444_REV", /* StrName */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_RGBA5551, /* Name */
- "MESA_FORMAT_RGBA5551", /* StrName */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_ARGB1555, /* Name */
- "MESA_FORMAT_ARGB1555", /* StrName */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_ARGB1555_REV, /* Name */
- "MESA_FORMAT_ARGB1555_REV", /* StrName */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_AL44, /* Name */
- "MESA_FORMAT_AL44", /* StrName */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 4, /* Red/Green/Blue/AlphaBits */
- 4, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 1 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_AL88, /* Name */
- "MESA_FORMAT_AL88", /* StrName */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
- 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_AL88_REV, /* Name */
- "MESA_FORMAT_AL88_REV", /* StrName */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
- 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_AL1616, /* Name */
- "MESA_FORMAT_AL1616", /* StrName */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
- 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_AL1616_REV, /* Name */
- "MESA_FORMAT_AL1616_REV", /* StrName */
- GL_LUMINANCE_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
- 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_RGB332, /* Name */
- "MESA_FORMAT_RGB332", /* StrName */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 1 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_A8, /* Name */
- "MESA_FORMAT_A8", /* StrName */
- GL_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 1 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_A16, /* Name */
- "MESA_FORMAT_A16", /* StrName */
- GL_ALPHA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_L8, /* Name */
- "MESA_FORMAT_L8", /* StrName */
- GL_LUMINANCE, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 1 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_L16, /* Name */
- "MESA_FORMAT_L16", /* StrName */
- GL_LUMINANCE, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_I8, /* Name */
- "MESA_FORMAT_I8", /* StrName */
- GL_INTENSITY, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 1 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_I16, /* Name */
- "MESA_FORMAT_I16", /* StrName */
- GL_INTENSITY, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 16, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_CI8, /* Name */
- "MESA_FORMAT_CI8", /* StrName */
- GL_COLOR_INDEX, /* BaseFormat */
- GL_UNSIGNED_INT, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 1 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_YCBCR, /* Name */
- "MESA_FORMAT_YCBCR", /* StrName */
- GL_YCBCR_MESA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_YCBCR_REV, /* Name */
- "MESA_FORMAT_YCBCR_REV", /* StrName */
- GL_YCBCR_MESA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_R8,
- "MESA_FORMAT_R8",
- GL_RED,
- GL_UNSIGNED_NORMALIZED,
- 8, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 1
- },
- {
- MESA_FORMAT_RG88,
- "MESA_FORMAT_RG88",
- GL_RG,
- GL_UNSIGNED_NORMALIZED,
- 8, 8, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_RG88_REV,
- "MESA_FORMAT_RG88_REV",
- GL_RG,
- GL_UNSIGNED_NORMALIZED,
- 8, 8, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_R16,
- "MESA_FORMAT_R16",
- GL_RED,
- GL_UNSIGNED_NORMALIZED,
- 16, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_RG1616,
- "MESA_FORMAT_RG1616",
- GL_RG,
- GL_UNSIGNED_NORMALIZED,
- 16, 16, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_RG1616_REV,
- "MESA_FORMAT_RG1616_REV",
- GL_RG,
- GL_UNSIGNED_NORMALIZED,
- 16, 16, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_ARGB2101010,
- "MESA_FORMAT_ARGB2101010",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 10, 10, 10, 2,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_Z24_S8, /* Name */
- "MESA_FORMAT_Z24_S8", /* StrName */
- GL_DEPTH_STENCIL, /* BaseFormat */
- GL_UNSIGNED_INT, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_S8_Z24, /* Name */
- "MESA_FORMAT_S8_Z24", /* StrName */
- GL_DEPTH_STENCIL, /* BaseFormat */
- GL_UNSIGNED_INT, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_Z16, /* Name */
- "MESA_FORMAT_Z16", /* StrName */
- GL_DEPTH_COMPONENT, /* BaseFormat */
- GL_UNSIGNED_INT, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 2 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_X8_Z24, /* Name */
- "MESA_FORMAT_X8_Z24", /* StrName */
- GL_DEPTH_COMPONENT, /* BaseFormat */
- GL_UNSIGNED_INT, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_Z24_X8, /* Name */
- "MESA_FORMAT_Z24_X8", /* StrName */
- GL_DEPTH_COMPONENT, /* BaseFormat */
- GL_UNSIGNED_INT, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_Z32, /* Name */
- "MESA_FORMAT_Z32", /* StrName */
- GL_DEPTH_COMPONENT, /* BaseFormat */
- GL_UNSIGNED_INT, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 4 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_S8, /* Name */
- "MESA_FORMAT_S8", /* StrName */
- GL_STENCIL_INDEX, /* BaseFormat */
- GL_UNSIGNED_INT, /* DataType */
- 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 1 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_SRGB8,
- "MESA_FORMAT_SRGB8",
- GL_RGB,
- GL_UNSIGNED_NORMALIZED,
- 8, 8, 8, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 3
- },
- {
- MESA_FORMAT_SRGBA8,
- "MESA_FORMAT_SRGBA8",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 8, 8, 8, 8,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_SARGB8,
- "MESA_FORMAT_SARGB8",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 8, 8, 8, 8,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_SL8,
- "MESA_FORMAT_SL8",
- GL_LUMINANCE,
- GL_UNSIGNED_NORMALIZED,
- 0, 0, 0, 0,
- 8, 0, 0, 0, 0,
- 1, 1, 1
- },
- {
- MESA_FORMAT_SLA8,
- "MESA_FORMAT_SLA8",
- GL_LUMINANCE_ALPHA,
- GL_UNSIGNED_NORMALIZED,
- 0, 0, 0, 8,
- 8, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_SRGB_DXT1, /* Name */
- "MESA_FORMAT_SRGB_DXT1", /* StrName */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 4, 4, 8 /* 8 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_SRGBA_DXT1,
- "MESA_FORMAT_SRGBA_DXT1",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 4, 4, 4, 4,
- 0, 0, 0, 0, 0,
- 4, 4, 8 /* 8 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_SRGBA_DXT3,
- "MESA_FORMAT_SRGBA_DXT3",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 4, 4, 4, 4,
- 0, 0, 0, 0, 0,
- 4, 4, 16 /* 16 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_SRGBA_DXT5,
- "MESA_FORMAT_SRGBA_DXT5",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 4, 4, 4, 4,
- 0, 0, 0, 0, 0,
- 4, 4, 16 /* 16 bytes per 4x4 block */
- },
-
- {
- MESA_FORMAT_RGB_FXT1,
- "MESA_FORMAT_RGB_FXT1",
- GL_RGB,
- GL_UNSIGNED_NORMALIZED,
- 4, 4, 4, 0, /* approx Red/Green/BlueBits */
- 0, 0, 0, 0, 0,
- 8, 4, 16 /* 16 bytes per 8x4 block */
- },
- {
- MESA_FORMAT_RGBA_FXT1,
- "MESA_FORMAT_RGBA_FXT1",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0,
- 8, 4, 16 /* 16 bytes per 8x4 block */
- },
-
- {
- MESA_FORMAT_RGB_DXT1, /* Name */
- "MESA_FORMAT_RGB_DXT1", /* StrName */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED, /* DataType */
- 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 4, 4, 8 /* 8 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_RGBA_DXT1,
- "MESA_FORMAT_RGBA_DXT1",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 4, 4, 4, 4,
- 0, 0, 0, 0, 0,
- 4, 4, 8 /* 8 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_RGBA_DXT3,
- "MESA_FORMAT_RGBA_DXT3",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 4, 4, 4, 4,
- 0, 0, 0, 0, 0,
- 4, 4, 16 /* 16 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_RGBA_DXT5,
- "MESA_FORMAT_RGBA_DXT5",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 4, 4, 4, 4,
- 0, 0, 0, 0, 0,
- 4, 4, 16 /* 16 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_RGBA_FLOAT32,
- "MESA_FORMAT_RGBA_FLOAT32",
- GL_RGBA,
- GL_FLOAT,
- 32, 32, 32, 32,
- 0, 0, 0, 0, 0,
- 1, 1, 16
- },
- {
- MESA_FORMAT_RGBA_FLOAT16,
- "MESA_FORMAT_RGBA_FLOAT16",
- GL_RGBA,
- GL_FLOAT,
- 16, 16, 16, 16,
- 0, 0, 0, 0, 0,
- 1, 1, 8
- },
- {
- MESA_FORMAT_RGB_FLOAT32,
- "MESA_FORMAT_RGB_FLOAT32",
- GL_RGB,
- GL_FLOAT,
- 32, 32, 32, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 12
- },
- {
- MESA_FORMAT_RGB_FLOAT16,
- "MESA_FORMAT_RGB_FLOAT16",
- GL_RGB,
- GL_FLOAT,
- 16, 16, 16, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 6
- },
- {
- MESA_FORMAT_ALPHA_FLOAT32,
- "MESA_FORMAT_ALPHA_FLOAT32",
- GL_ALPHA,
- GL_FLOAT,
- 0, 0, 0, 32,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_ALPHA_FLOAT16,
- "MESA_FORMAT_ALPHA_FLOAT16",
- GL_ALPHA,
- GL_FLOAT,
- 0, 0, 0, 16,
- 0, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_LUMINANCE_FLOAT32,
- "MESA_FORMAT_LUMINANCE_FLOAT32",
- GL_ALPHA,
- GL_FLOAT,
- 0, 0, 0, 0,
- 32, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_LUMINANCE_FLOAT16,
- "MESA_FORMAT_LUMINANCE_FLOAT16",
- GL_ALPHA,
- GL_FLOAT,
- 0, 0, 0, 0,
- 16, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
- "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
- GL_LUMINANCE_ALPHA,
- GL_FLOAT,
- 0, 0, 0, 32,
- 32, 0, 0, 0, 0,
- 1, 1, 8
- },
- {
- MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
- "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
- GL_LUMINANCE_ALPHA,
- GL_FLOAT,
- 0, 0, 0, 16,
- 16, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_INTENSITY_FLOAT32,
- "MESA_FORMAT_INTENSITY_FLOAT32",
- GL_INTENSITY,
- GL_FLOAT,
- 0, 0, 0, 0,
- 0, 32, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_INTENSITY_FLOAT16,
- "MESA_FORMAT_INTENSITY_FLOAT16",
- GL_INTENSITY,
- GL_FLOAT,
- 0, 0, 0, 0,
- 0, 16, 0, 0, 0,
- 1, 1, 2
- },
-
- /* unnormalized signed int formats */
- {
- MESA_FORMAT_RGBA_INT8,
- "MESA_FORMAT_RGBA_INT8",
- GL_RGBA,
- GL_INT,
- 8, 8, 8, 8,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_RGBA_INT16,
- "MESA_FORMAT_RGBA_INT16",
- GL_RGBA,
- GL_INT,
- 16, 16, 16, 16,
- 0, 0, 0, 0, 0,
- 1, 1, 8
- },
- {
- MESA_FORMAT_RGBA_INT32,
- "MESA_FORMAT_RGBA_INT32",
- GL_RGBA,
- GL_INT,
- 32, 32, 32, 32,
- 0, 0, 0, 0, 0,
- 1, 1, 16
- },
-
- /* unnormalized unsigned int formats */
- {
- MESA_FORMAT_RGBA_UINT8,
- "MESA_FORMAT_RGBA_UINT8",
- GL_RGBA,
- GL_UNSIGNED_INT,
- 8, 8, 8, 8,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_RGBA_UINT16,
- "MESA_FORMAT_RGBA_UINT16",
- GL_RGBA,
- GL_UNSIGNED_INT,
- 16, 16, 16, 16,
- 0, 0, 0, 0, 0,
- 1, 1, 8
- },
- {
- MESA_FORMAT_RGBA_UINT32,
- "MESA_FORMAT_RGBA_UINT32",
- GL_RGBA,
- GL_UNSIGNED_INT,
- 32, 32, 32, 32,
- 0, 0, 0, 0, 0,
- 1, 1, 16
- },
-
-
- {
- MESA_FORMAT_DUDV8,
- "MESA_FORMAT_DUDV8",
- GL_DUDV_ATI,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 2
- },
-
- /* Signed 8 bits / channel */
- {
- MESA_FORMAT_SIGNED_R8, /* Name */
- "MESA_FORMAT_SIGNED_R8", /* StrName */
- GL_RED, /* BaseFormat */
- GL_SIGNED_NORMALIZED, /* DataType */
- 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
- 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
- 1, 1, 1 /* BlockWidth/Height,Bytes */
- },
- {
- MESA_FORMAT_SIGNED_RG88,
- "MESA_FORMAT_SIGNED_RG88",
- GL_RG,
- GL_SIGNED_NORMALIZED,
- 8, 8, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_SIGNED_RGBX8888,
- "MESA_FORMAT_SIGNED_RGBX8888",
- GL_RGB,
- GL_SIGNED_NORMALIZED,
- 8, 8, 8, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 4 /* 4 bpp, but no alpha */
- },
- {
- MESA_FORMAT_SIGNED_RGBA8888,
- "MESA_FORMAT_SIGNED_RGBA8888",
- GL_RGBA,
- GL_SIGNED_NORMALIZED,
- 8, 8, 8, 8,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_SIGNED_RGBA8888_REV,
- "MESA_FORMAT_SIGNED_RGBA8888_REV",
- GL_RGBA,
- GL_SIGNED_NORMALIZED,
- 8, 8, 8, 8,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
-
- /* Signed 16 bits / channel */
- {
- MESA_FORMAT_SIGNED_R_16,
- "MESA_FORMAT_SIGNED_R_16",
- GL_RED,
- GL_SIGNED_NORMALIZED,
- 16, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_SIGNED_RG_16,
- "MESA_FORMAT_SIGNED_RG_16",
- GL_RG,
- GL_SIGNED_NORMALIZED,
- 16, 16, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_SIGNED_RGB_16,
- "MESA_FORMAT_SIGNED_RGB_16",
- GL_RGB,
- GL_SIGNED_NORMALIZED,
- 16, 16, 16, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 6
- },
- {
- MESA_FORMAT_SIGNED_RGBA_16,
- "MESA_FORMAT_SIGNED_RGBA_16",
- GL_RGBA,
- GL_SIGNED_NORMALIZED,
- 16, 16, 16, 16,
- 0, 0, 0, 0, 0,
- 1, 1, 8
- },
- {
- MESA_FORMAT_RGBA_16,
- "MESA_FORMAT_RGBA_16",
- GL_RGBA,
- GL_UNSIGNED_NORMALIZED,
- 16, 16, 16, 16,
- 0, 0, 0, 0, 0,
- 1, 1, 8
- },
- {
- MESA_FORMAT_RED_RGTC1,
- "MESA_FORMAT_RED_RGTC1",
- GL_RED,
- GL_UNSIGNED_NORMALIZED,
- 4, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 4, 4, 8 /* 8 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_SIGNED_RED_RGTC1,
- "MESA_FORMAT_SIGNED_RED_RGTC1",
- GL_RED,
- GL_SIGNED_NORMALIZED,
- 4, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 4, 4, 8 /* 8 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_RG_RGTC2,
- "MESA_FORMAT_RG_RGTC2",
- GL_RG,
- GL_UNSIGNED_NORMALIZED,
- 4, 4, 0, 0,
- 0, 0, 0, 0, 0,
- 4, 4, 16 /* 16 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_SIGNED_RG_RGTC2,
- "MESA_FORMAT_SIGNED_RG_RGTC2",
- GL_RG,
- GL_SIGNED_NORMALIZED,
- 4, 4, 0, 0,
- 0, 0, 0, 0, 0,
- 4, 4, 16 /* 16 bytes per 4x4 block */
- },
-};
-
-
-
-static const struct gl_format_info *
-_mesa_get_format_info(gl_format format)
-{
- const struct gl_format_info *info = &format_info[format];
- assert(info->Name == format);
- return info;
-}
-
-
-/** Return string name of format (for debugging) */
-const char *
-_mesa_get_format_name(gl_format format)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
- return info->StrName;
-}
-
-
-
-/**
- * Return bytes needed to store a block of pixels in the given format.
- * Normally, a block is 1x1 (a single pixel). But for compressed formats
- * a block may be 4x4 or 8x4, etc.
- */
-GLuint
-_mesa_get_format_bytes(gl_format format)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
- ASSERT(info->BytesPerBlock);
- return info->BytesPerBlock;
-}
-
-
-/**
- * Return bits per component for the given format.
- * \param format one of MESA_FORMAT_x
- * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
- */
-GLint
-_mesa_get_format_bits(gl_format format, GLenum pname)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
-
- switch (pname) {
- case GL_RED_BITS:
- case GL_TEXTURE_RED_SIZE:
- case GL_RENDERBUFFER_RED_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
- return info->RedBits;
- case GL_GREEN_BITS:
- case GL_TEXTURE_GREEN_SIZE:
- case GL_RENDERBUFFER_GREEN_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
- return info->GreenBits;
- case GL_BLUE_BITS:
- case GL_TEXTURE_BLUE_SIZE:
- case GL_RENDERBUFFER_BLUE_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
- return info->BlueBits;
- case GL_ALPHA_BITS:
- case GL_TEXTURE_ALPHA_SIZE:
- case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
- return info->AlphaBits;
- case GL_TEXTURE_INTENSITY_SIZE:
- return info->IntensityBits;
- case GL_TEXTURE_LUMINANCE_SIZE:
- return info->LuminanceBits;
- case GL_INDEX_BITS:
- case GL_TEXTURE_INDEX_SIZE_EXT:
- return info->IndexBits;
- case GL_DEPTH_BITS:
- case GL_TEXTURE_DEPTH_SIZE_ARB:
- case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
- return info->DepthBits;
- case GL_STENCIL_BITS:
- case GL_TEXTURE_STENCIL_SIZE_EXT:
- case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
- case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
- return info->StencilBits;
- default:
- _mesa_problem(NULL, "bad pname in _mesa_get_format_bits()");
- return 0;
- }
-}
-
-
-/**
- * Return the data type (or more specifically, the data representation)
- * for the given format.
- * The return value will be one of:
- * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
- * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
- * GL_UNSIGNED_INT = an ordinary unsigned integer
- * GL_INT = an ordinary signed integer
- * GL_FLOAT = an ordinary float
- */
-GLenum
-_mesa_get_format_datatype(gl_format format)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
- return info->DataType;
-}
-
-
-/**
- * Return the basic format for the given type. The result will be
- * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
- * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
- * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
- */
-GLenum
-_mesa_get_format_base_format(gl_format format)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
- return info->BaseFormat;
-}
-
-
-/**
- * Return the block size (in pixels) for the given format. Normally
- * the block size is 1x1. But compressed formats will have block sizes
- * of 4x4 or 8x4 pixels, etc.
- * \param bw returns block width in pixels
- * \param bh returns block height in pixels
- */
-void
-_mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
- *bw = info->BlockWidth;
- *bh = info->BlockHeight;
-}
-
-
-/** Is the given format a compressed format? */
-GLboolean
-_mesa_is_format_compressed(gl_format format)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
- return info->BlockWidth > 1 || info->BlockHeight > 1;
-}
-
-
-/**
- * Determine if the given format represents a packed depth/stencil buffer.
- */
-GLboolean
-_mesa_is_format_packed_depth_stencil(gl_format format)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
-
- return info->BaseFormat == GL_DEPTH_STENCIL;
-}
-
-
-/**
- * Is the given format a signed/unsigned integer color format?
- */
-GLboolean
-_mesa_is_format_integer_color(gl_format format)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
- return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) &&
- info->BaseFormat != GL_DEPTH_COMPONENT &&
- info->BaseFormat != GL_DEPTH_STENCIL &&
- info->BaseFormat != GL_STENCIL_INDEX;
-}
-
-
-/**
- * Return color encoding for given format.
- * \return GL_LINEAR or GL_SRGB
- */
-GLenum
-_mesa_get_format_color_encoding(gl_format format)
-{
- /* XXX this info should be encoded in gl_format_info */
- switch (format) {
- case MESA_FORMAT_SRGB8:
- case MESA_FORMAT_SRGBA8:
- case MESA_FORMAT_SARGB8:
- case MESA_FORMAT_SL8:
- case MESA_FORMAT_SLA8:
- case MESA_FORMAT_SRGB_DXT1:
- case MESA_FORMAT_SRGBA_DXT1:
- case MESA_FORMAT_SRGBA_DXT3:
- case MESA_FORMAT_SRGBA_DXT5:
- return GL_SRGB;
- default:
- return GL_LINEAR;
- }
-}
-
-
-/**
- * For an sRGB format, return the corresponding linear color space format.
- * For non-sRGB formats, return the format as-is.
- */
-gl_format
-_mesa_get_srgb_format_linear(gl_format format)
-{
- switch (format) {
- case MESA_FORMAT_SRGB8:
- format = MESA_FORMAT_RGB888;
- break;
- case MESA_FORMAT_SRGBA8:
- format = MESA_FORMAT_RGBA8888;
- break;
- case MESA_FORMAT_SARGB8:
- format = MESA_FORMAT_ARGB8888;
- break;
- case MESA_FORMAT_SL8:
- format = MESA_FORMAT_L8;
- break;
- case MESA_FORMAT_SLA8:
- format = MESA_FORMAT_AL88;
- break;
- case MESA_FORMAT_SRGB_DXT1:
- format = MESA_FORMAT_RGB_DXT1;
- break;
- case MESA_FORMAT_SRGBA_DXT1:
- format = MESA_FORMAT_RGBA_DXT1;
- break;
- case MESA_FORMAT_SRGBA_DXT3:
- format = MESA_FORMAT_RGBA_DXT3;
- break;
- case MESA_FORMAT_SRGBA_DXT5:
- format = MESA_FORMAT_RGBA_DXT5;
- break;
- default:
- break;
- }
- return format;
-}
-
-
-/**
- * Return number of bytes needed to store an image of the given size
- * in the given format.
- */
-GLuint
-_mesa_format_image_size(gl_format format, GLsizei width,
- GLsizei height, GLsizei depth)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
- /* Strictly speaking, a conditional isn't needed here */
- if (info->BlockWidth > 1 || info->BlockHeight > 1) {
- /* compressed format (2D only for now) */
- const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
- const GLuint wblocks = (width + bw - 1) / bw;
- const GLuint hblocks = (height + bh - 1) / bh;
- const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
- assert(depth == 1);
- return sz;
- }
- else {
- /* non-compressed */
- const GLuint sz = width * height * depth * info->BytesPerBlock;
- return sz;
- }
-}
-
-
-/**
- * Same as _mesa_format_image_size() but returns a 64-bit value to
- * accomodate very large textures.
- */
-uint64_t
-_mesa_format_image_size64(gl_format format, GLsizei width,
- GLsizei height, GLsizei depth)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
- /* Strictly speaking, a conditional isn't needed here */
- if (info->BlockWidth > 1 || info->BlockHeight > 1) {
- /* compressed format (2D only for now) */
- const uint64_t bw = info->BlockWidth, bh = info->BlockHeight;
- const uint64_t wblocks = (width + bw - 1) / bw;
- const uint64_t hblocks = (height + bh - 1) / bh;
- const uint64_t sz = wblocks * hblocks * info->BytesPerBlock;
- assert(depth == 1);
- return sz;
- }
- else {
- /* non-compressed */
- const uint64_t sz = ((uint64_t) width *
- (uint64_t) height *
- (uint64_t) depth *
- info->BytesPerBlock);
- return sz;
- }
-}
-
-
-
-GLint
-_mesa_format_row_stride(gl_format format, GLsizei width)
-{
- const struct gl_format_info *info = _mesa_get_format_info(format);
- /* Strictly speaking, a conditional isn't needed here */
- if (info->BlockWidth > 1 || info->BlockHeight > 1) {
- /* compressed format */
- const GLuint bw = info->BlockWidth;
- const GLuint wblocks = (width + bw - 1) / bw;
- const GLint stride = wblocks * info->BytesPerBlock;
- return stride;
- }
- else {
- const GLint stride = width * info->BytesPerBlock;
- return stride;
- }
-}
-
-
-/**
- * Debug/test: check that all formats are handled in the
- * _mesa_format_to_type_and_comps() function. When new pixel formats
- * are added to Mesa, that function needs to be updated.
- * This is a no-op after the first call.
- */
-static void
-check_format_to_type_and_comps(void)
-{
- gl_format f;
-
- for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) {
- GLenum datatype = 0;
- GLuint comps = 0;
- /* This function will emit a problem/warning if the format is
- * not handled.
- */
- _mesa_format_to_type_and_comps(f, &datatype, &comps);
- }
-}
-
-
-/**
- * Do sanity checking of the format info table.
- */
-void
-_mesa_test_formats(void)
-{
- GLuint i;
-
- assert(Elements(format_info) == MESA_FORMAT_COUNT);
-
- for (i = 0; i < MESA_FORMAT_COUNT; i++) {
- const struct gl_format_info *info = _mesa_get_format_info(i);
- assert(info);
-
- assert(info->Name == i);
-
- if (info->Name == MESA_FORMAT_NONE)
- continue;
-
- if (info->BlockWidth == 1 && info->BlockHeight == 1) {
- if (info->RedBits > 0) {
- GLuint t = info->RedBits + info->GreenBits
- + info->BlueBits + info->AlphaBits;
- assert(t / 8 <= info->BytesPerBlock);
- (void) t;
- }
- }
-
- assert(info->DataType == GL_UNSIGNED_NORMALIZED ||
- info->DataType == GL_SIGNED_NORMALIZED ||
- info->DataType == GL_UNSIGNED_INT ||
- info->DataType == GL_INT ||
- info->DataType == GL_FLOAT);
-
- if (info->BaseFormat == GL_RGB) {
- assert(info->RedBits > 0);
- assert(info->GreenBits > 0);
- assert(info->BlueBits > 0);
- assert(info->AlphaBits == 0);
- assert(info->LuminanceBits == 0);
- assert(info->IntensityBits == 0);
- }
- else if (info->BaseFormat == GL_RGBA) {
- assert(info->RedBits > 0);
- assert(info->GreenBits > 0);
- assert(info->BlueBits > 0);
- assert(info->AlphaBits > 0);
- assert(info->LuminanceBits == 0);
- assert(info->IntensityBits == 0);
- }
- else if (info->BaseFormat == GL_RG) {
- assert(info->RedBits > 0);
- assert(info->GreenBits > 0);
- assert(info->BlueBits == 0);
- assert(info->AlphaBits == 0);
- assert(info->LuminanceBits == 0);
- assert(info->IntensityBits == 0);
- }
- else if (info->BaseFormat == GL_RED) {
- assert(info->RedBits > 0);
- assert(info->GreenBits == 0);
- assert(info->BlueBits == 0);
- assert(info->AlphaBits == 0);
- assert(info->LuminanceBits == 0);
- assert(info->IntensityBits == 0);
- }
- else if (info->BaseFormat == GL_LUMINANCE) {
- assert(info->RedBits == 0);
- assert(info->GreenBits == 0);
- assert(info->BlueBits == 0);
- assert(info->AlphaBits == 0);
- assert(info->LuminanceBits > 0);
- assert(info->IntensityBits == 0);
- }
- else if (info->BaseFormat == GL_INTENSITY) {
- assert(info->RedBits == 0);
- assert(info->GreenBits == 0);
- assert(info->BlueBits == 0);
- assert(info->AlphaBits == 0);
- assert(info->LuminanceBits == 0);
- assert(info->IntensityBits > 0);
- }
- }
-
- check_format_to_type_and_comps();
-}
-
-
-
-/**
- * Return datatype and number of components per texel for the given gl_format.
- * Only used for mipmap generation code.
- */
-void
-_mesa_format_to_type_and_comps(gl_format format,
- GLenum *datatype, GLuint *comps)
-{
- switch (format) {
- case MESA_FORMAT_RGBA8888:
- case MESA_FORMAT_RGBA8888_REV:
- case MESA_FORMAT_ARGB8888:
- case MESA_FORMAT_ARGB8888_REV:
- case MESA_FORMAT_XRGB8888:
- case MESA_FORMAT_XRGB8888_REV:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 4;
- return;
- case MESA_FORMAT_RGB888:
- case MESA_FORMAT_BGR888:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 3;
- return;
- case MESA_FORMAT_RGB565:
- case MESA_FORMAT_RGB565_REV:
- *datatype = GL_UNSIGNED_SHORT_5_6_5;
- *comps = 3;
- return;
-
- case MESA_FORMAT_ARGB4444:
- case MESA_FORMAT_ARGB4444_REV:
- *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
- *comps = 4;
- return;
-
- case MESA_FORMAT_ARGB1555:
- case MESA_FORMAT_ARGB1555_REV:
- *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
- *comps = 4;
- return;
-
- case MESA_FORMAT_ARGB2101010:
- *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
- *comps = 4;
- return;
-
- case MESA_FORMAT_RGBA5551:
- *datatype = GL_UNSIGNED_SHORT_5_5_5_1;
- *comps = 4;
- return;
-
- case MESA_FORMAT_AL44:
- *datatype = MESA_UNSIGNED_BYTE_4_4;
- *comps = 2;
- return;
-
- case MESA_FORMAT_AL88:
- case MESA_FORMAT_AL88_REV:
- case MESA_FORMAT_RG88:
- case MESA_FORMAT_RG88_REV:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 2;
- return;
-
- case MESA_FORMAT_AL1616:
- case MESA_FORMAT_AL1616_REV:
- case MESA_FORMAT_RG1616:
- case MESA_FORMAT_RG1616_REV:
- *datatype = GL_UNSIGNED_SHORT;
- *comps = 2;
- return;
-
- case MESA_FORMAT_R16:
- case MESA_FORMAT_A16:
- case MESA_FORMAT_L16:
- case MESA_FORMAT_I16:
- *datatype = GL_UNSIGNED_SHORT;
- *comps = 1;
- return;
-
- case MESA_FORMAT_RGB332:
- *datatype = GL_UNSIGNED_BYTE_3_3_2;
- *comps = 3;
- return;
-
- case MESA_FORMAT_A8:
- case MESA_FORMAT_L8:
- case MESA_FORMAT_I8:
- case MESA_FORMAT_CI8:
- case MESA_FORMAT_R8:
- case MESA_FORMAT_S8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 1;
- return;
-
- case MESA_FORMAT_YCBCR:
- case MESA_FORMAT_YCBCR_REV:
- *datatype = GL_UNSIGNED_SHORT;
- *comps = 2;
- return;
-
- case MESA_FORMAT_Z24_S8:
- *datatype = GL_UNSIGNED_INT;
- *comps = 1; /* XXX OK? */
- return;
-
- case MESA_FORMAT_S8_Z24:
- *datatype = GL_UNSIGNED_INT;
- *comps = 1; /* XXX OK? */
- return;
-
- case MESA_FORMAT_Z16:
- *datatype = GL_UNSIGNED_SHORT;
- *comps = 1;
- return;
-
- case MESA_FORMAT_X8_Z24:
- *datatype = GL_UNSIGNED_INT;
- *comps = 1;
- return;
-
- case MESA_FORMAT_Z24_X8:
- *datatype = GL_UNSIGNED_INT;
- *comps = 1;
- return;
-
- case MESA_FORMAT_Z32:
- *datatype = GL_UNSIGNED_INT;
- *comps = 1;
- return;
-
- case MESA_FORMAT_DUDV8:
- *datatype = GL_BYTE;
- *comps = 2;
- return;
-
- case MESA_FORMAT_SIGNED_R8:
- *datatype = GL_BYTE;
- *comps = 1;
- return;
- case MESA_FORMAT_SIGNED_RG88:
- *datatype = GL_BYTE;
- *comps = 2;
- return;
- case MESA_FORMAT_SIGNED_RGBA8888:
- case MESA_FORMAT_SIGNED_RGBA8888_REV:
- case MESA_FORMAT_SIGNED_RGBX8888:
- *datatype = GL_BYTE;
- *comps = 4;
- return;
-
- case MESA_FORMAT_RGBA_16:
- *datatype = GL_UNSIGNED_SHORT;
- *comps = 4;
- return;
-
- case MESA_FORMAT_SIGNED_R_16:
- *datatype = GL_SHORT;
- *comps = 1;
- return;
- case MESA_FORMAT_SIGNED_RG_16:
- *datatype = GL_SHORT;
- *comps = 2;
- return;
- case MESA_FORMAT_SIGNED_RGB_16:
- *datatype = GL_SHORT;
- *comps = 3;
- return;
- case MESA_FORMAT_SIGNED_RGBA_16:
- *datatype = GL_SHORT;
- *comps = 4;
- return;
-
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGB8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 3;
- return;
- case MESA_FORMAT_SRGBA8:
- case MESA_FORMAT_SARGB8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 4;
- return;
- case MESA_FORMAT_SL8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 1;
- return;
- case MESA_FORMAT_SLA8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 2;
- return;
-#endif
-
-#if FEATURE_texture_fxt1
- case MESA_FORMAT_RGB_FXT1:
- case MESA_FORMAT_RGBA_FXT1:
-#endif
-#if FEATURE_texture_s3tc
- case MESA_FORMAT_RGB_DXT1:
- case MESA_FORMAT_RGBA_DXT1:
- case MESA_FORMAT_RGBA_DXT3:
- case MESA_FORMAT_RGBA_DXT5:
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGB_DXT1:
- case MESA_FORMAT_SRGBA_DXT1:
- case MESA_FORMAT_SRGBA_DXT3:
- case MESA_FORMAT_SRGBA_DXT5:
-#endif
-#endif
- case MESA_FORMAT_RED_RGTC1:
- case MESA_FORMAT_SIGNED_RED_RGTC1:
- case MESA_FORMAT_RG_RGTC2:
- case MESA_FORMAT_SIGNED_RG_RGTC2:
- /* XXX generate error instead? */
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 0;
- return;
-
- case MESA_FORMAT_RGBA_FLOAT32:
- *datatype = GL_FLOAT;
- *comps = 4;
- return;
- case MESA_FORMAT_RGBA_FLOAT16:
- *datatype = GL_HALF_FLOAT_ARB;
- *comps = 4;
- return;
- case MESA_FORMAT_RGB_FLOAT32:
- *datatype = GL_FLOAT;
- *comps = 3;
- return;
- case MESA_FORMAT_RGB_FLOAT16:
- *datatype = GL_HALF_FLOAT_ARB;
- *comps = 3;
- return;
- case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
- *datatype = GL_FLOAT;
- *comps = 2;
- return;
- case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
- *datatype = GL_HALF_FLOAT_ARB;
- *comps = 2;
- return;
- case MESA_FORMAT_ALPHA_FLOAT32:
- case MESA_FORMAT_LUMINANCE_FLOAT32:
- case MESA_FORMAT_INTENSITY_FLOAT32:
- *datatype = GL_FLOAT;
- *comps = 1;
- return;
- case MESA_FORMAT_ALPHA_FLOAT16:
- case MESA_FORMAT_LUMINANCE_FLOAT16:
- case MESA_FORMAT_INTENSITY_FLOAT16:
- *datatype = GL_HALF_FLOAT_ARB;
- *comps = 1;
- return;
-
- case MESA_FORMAT_RGBA_INT8:
- *datatype = GL_BYTE;
- *comps = 4;
- return;
- case MESA_FORMAT_RGBA_INT16:
- *datatype = GL_SHORT;
- *comps = 4;
- return;
- case MESA_FORMAT_RGBA_INT32:
- *datatype = GL_INT;
- *comps = 4;
- return;
-
- /**
- * \name Non-normalized unsigned integer formats.
- */
- case MESA_FORMAT_RGBA_UINT8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 4;
- return;
- case MESA_FORMAT_RGBA_UINT16:
- *datatype = GL_UNSIGNED_SHORT;
- *comps = 4;
- return;
- case MESA_FORMAT_RGBA_UINT32:
- *datatype = GL_UNSIGNED_INT;
- *comps = 4;
- return;
-
- case MESA_FORMAT_COUNT:
- assert(0);
- return;
-
- case MESA_FORMAT_NONE:
- /* For debug builds, warn if any formats are not handled */
-#ifdef DEBUG
- default:
-#endif
- _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps",
- _mesa_get_format_name(format));
- *datatype = 0;
- *comps = 1;
- }
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008-2009 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "imports.h"
+#include "formats.h"
+#include "mfeatures.h"
+
+
+/**
+ * Information about texture formats.
+ */
+struct gl_format_info
+{
+ gl_format Name;
+
+ /** text name for debugging */
+ const char *StrName;
+
+ /**
+ * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
+ * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
+ * GL_COLOR_INDEX, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX,
+ * GL_DEPTH_STENCIL, GL_DUDV_ATI.
+ */
+ GLenum BaseFormat;
+
+ /**
+ * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
+ * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
+ */
+ GLenum DataType;
+
+ GLubyte RedBits;
+ GLubyte GreenBits;
+ GLubyte BlueBits;
+ GLubyte AlphaBits;
+ GLubyte LuminanceBits;
+ GLubyte IntensityBits;
+ GLubyte IndexBits;
+ GLubyte DepthBits;
+ GLubyte StencilBits;
+
+ /**
+ * To describe compressed formats. If not compressed, Width=Height=1.
+ */
+ GLubyte BlockWidth, BlockHeight;
+ GLubyte BytesPerBlock;
+};
+
+
+/**
+ * Info about each format.
+ * These must be in the same order as the MESA_FORMAT_* enums so that
+ * we can do lookups without searching.
+ */
+static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
+{
+ {
+ MESA_FORMAT_NONE, /* Name */
+ "MESA_FORMAT_NONE", /* StrName */
+ GL_NONE, /* BaseFormat */
+ GL_NONE, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 0, 0, 0 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGBA8888, /* Name */
+ "MESA_FORMAT_RGBA8888", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGBA8888_REV, /* Name */
+ "MESA_FORMAT_RGBA8888_REV", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB8888, /* Name */
+ "MESA_FORMAT_ARGB8888", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB8888_REV, /* Name */
+ "MESA_FORMAT_ARGB8888_REV", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_XRGB8888, /* Name */
+ "MESA_FORMAT_XRGB8888", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_XRGB8888_REV, /* Name */
+ "MESA_FORMAT_XRGB8888_REV", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGB888, /* Name */
+ "MESA_FORMAT_RGB888", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 3 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_BGR888, /* Name */
+ "MESA_FORMAT_BGR888", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 3 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGB565, /* Name */
+ "MESA_FORMAT_RGB565", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGB565_REV, /* Name */
+ "MESA_FORMAT_RGB565_REV", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB4444, /* Name */
+ "MESA_FORMAT_ARGB4444", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB4444_REV, /* Name */
+ "MESA_FORMAT_ARGB4444_REV", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGBA5551, /* Name */
+ "MESA_FORMAT_RGBA5551", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB1555, /* Name */
+ "MESA_FORMAT_ARGB1555", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_ARGB1555_REV, /* Name */
+ "MESA_FORMAT_ARGB1555_REV", /* StrName */
+ GL_RGBA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_AL44, /* Name */
+ "MESA_FORMAT_AL44", /* StrName */
+ GL_LUMINANCE_ALPHA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 4, /* Red/Green/Blue/AlphaBits */
+ 4, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_AL88, /* Name */
+ "MESA_FORMAT_AL88", /* StrName */
+ GL_LUMINANCE_ALPHA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
+ 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_AL88_REV, /* Name */
+ "MESA_FORMAT_AL88_REV", /* StrName */
+ GL_LUMINANCE_ALPHA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
+ 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_AL1616, /* Name */
+ "MESA_FORMAT_AL1616", /* StrName */
+ GL_LUMINANCE_ALPHA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
+ 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_AL1616_REV, /* Name */
+ "MESA_FORMAT_AL1616_REV", /* StrName */
+ GL_LUMINANCE_ALPHA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
+ 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_RGB332, /* Name */
+ "MESA_FORMAT_RGB332", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_A8, /* Name */
+ "MESA_FORMAT_A8", /* StrName */
+ GL_ALPHA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_A16, /* Name */
+ "MESA_FORMAT_A16", /* StrName */
+ GL_ALPHA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_L8, /* Name */
+ "MESA_FORMAT_L8", /* StrName */
+ GL_LUMINANCE, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_L16, /* Name */
+ "MESA_FORMAT_L16", /* StrName */
+ GL_LUMINANCE, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_I8, /* Name */
+ "MESA_FORMAT_I8", /* StrName */
+ GL_INTENSITY, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_I16, /* Name */
+ "MESA_FORMAT_I16", /* StrName */
+ GL_INTENSITY, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 16, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_CI8, /* Name */
+ "MESA_FORMAT_CI8", /* StrName */
+ GL_COLOR_INDEX, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_YCBCR, /* Name */
+ "MESA_FORMAT_YCBCR", /* StrName */
+ GL_YCBCR_MESA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_YCBCR_REV, /* Name */
+ "MESA_FORMAT_YCBCR_REV", /* StrName */
+ GL_YCBCR_MESA, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_R8,
+ "MESA_FORMAT_R8",
+ GL_RED,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 1
+ },
+ {
+ MESA_FORMAT_RG88,
+ "MESA_FORMAT_RG88",
+ GL_RG,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 8, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_RG88_REV,
+ "MESA_FORMAT_RG88_REV",
+ GL_RG,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 8, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_R16,
+ "MESA_FORMAT_R16",
+ GL_RED,
+ GL_UNSIGNED_NORMALIZED,
+ 16, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_RG1616,
+ "MESA_FORMAT_RG1616",
+ GL_RG,
+ GL_UNSIGNED_NORMALIZED,
+ 16, 16, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_RG1616_REV,
+ "MESA_FORMAT_RG1616_REV",
+ GL_RG,
+ GL_UNSIGNED_NORMALIZED,
+ 16, 16, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_ARGB2101010,
+ "MESA_FORMAT_ARGB2101010",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 10, 10, 10, 2,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_Z24_S8, /* Name */
+ "MESA_FORMAT_Z24_S8", /* StrName */
+ GL_DEPTH_STENCIL, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_S8_Z24, /* Name */
+ "MESA_FORMAT_S8_Z24", /* StrName */
+ GL_DEPTH_STENCIL, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_Z16, /* Name */
+ "MESA_FORMAT_Z16", /* StrName */
+ GL_DEPTH_COMPONENT, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 2 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_X8_Z24, /* Name */
+ "MESA_FORMAT_X8_Z24", /* StrName */
+ GL_DEPTH_COMPONENT, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_Z24_X8, /* Name */
+ "MESA_FORMAT_Z24_X8", /* StrName */
+ GL_DEPTH_COMPONENT, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_Z32, /* Name */
+ "MESA_FORMAT_Z32", /* StrName */
+ GL_DEPTH_COMPONENT, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 4 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_S8, /* Name */
+ "MESA_FORMAT_S8", /* StrName */
+ GL_STENCIL_INDEX, /* BaseFormat */
+ GL_UNSIGNED_INT, /* DataType */
+ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_SRGB8,
+ "MESA_FORMAT_SRGB8",
+ GL_RGB,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 8, 8, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 3
+ },
+ {
+ MESA_FORMAT_SRGBA8,
+ "MESA_FORMAT_SRGBA8",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_SARGB8,
+ "MESA_FORMAT_SARGB8",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_SL8,
+ "MESA_FORMAT_SL8",
+ GL_LUMINANCE,
+ GL_UNSIGNED_NORMALIZED,
+ 0, 0, 0, 0,
+ 8, 0, 0, 0, 0,
+ 1, 1, 1
+ },
+ {
+ MESA_FORMAT_SLA8,
+ "MESA_FORMAT_SLA8",
+ GL_LUMINANCE_ALPHA,
+ GL_UNSIGNED_NORMALIZED,
+ 0, 0, 0, 8,
+ 8, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_SRGB_DXT1, /* Name */
+ "MESA_FORMAT_SRGB_DXT1", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT1,
+ "MESA_FORMAT_SRGBA_DXT1",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT3,
+ "MESA_FORMAT_SRGBA_DXT3",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT5,
+ "MESA_FORMAT_SRGBA_DXT5",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+
+ {
+ MESA_FORMAT_RGB_FXT1,
+ "MESA_FORMAT_RGB_FXT1",
+ GL_RGB,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 0, /* approx Red/Green/BlueBits */
+ 0, 0, 0, 0, 0,
+ 8, 4, 16 /* 16 bytes per 8x4 block */
+ },
+ {
+ MESA_FORMAT_RGBA_FXT1,
+ "MESA_FORMAT_RGBA_FXT1",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0,
+ 8, 4, 16 /* 16 bytes per 8x4 block */
+ },
+
+ {
+ MESA_FORMAT_RGB_DXT1, /* Name */
+ "MESA_FORMAT_RGB_DXT1", /* StrName */
+ GL_RGB, /* BaseFormat */
+ GL_UNSIGNED_NORMALIZED, /* DataType */
+ 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_RGBA_DXT1,
+ "MESA_FORMAT_RGBA_DXT1",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_RGBA_DXT3,
+ "MESA_FORMAT_RGBA_DXT3",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_RGBA_DXT5,
+ "MESA_FORMAT_RGBA_DXT5",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 4, 4,
+ 0, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_RGBA_FLOAT32,
+ "MESA_FORMAT_RGBA_FLOAT32",
+ GL_RGBA,
+ GL_FLOAT,
+ 32, 32, 32, 32,
+ 0, 0, 0, 0, 0,
+ 1, 1, 16
+ },
+ {
+ MESA_FORMAT_RGBA_FLOAT16,
+ "MESA_FORMAT_RGBA_FLOAT16",
+ GL_RGBA,
+ GL_FLOAT,
+ 16, 16, 16, 16,
+ 0, 0, 0, 0, 0,
+ 1, 1, 8
+ },
+ {
+ MESA_FORMAT_RGB_FLOAT32,
+ "MESA_FORMAT_RGB_FLOAT32",
+ GL_RGB,
+ GL_FLOAT,
+ 32, 32, 32, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 12
+ },
+ {
+ MESA_FORMAT_RGB_FLOAT16,
+ "MESA_FORMAT_RGB_FLOAT16",
+ GL_RGB,
+ GL_FLOAT,
+ 16, 16, 16, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 6
+ },
+ {
+ MESA_FORMAT_ALPHA_FLOAT32,
+ "MESA_FORMAT_ALPHA_FLOAT32",
+ GL_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 32,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_ALPHA_FLOAT16,
+ "MESA_FORMAT_ALPHA_FLOAT16",
+ GL_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 16,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_LUMINANCE_FLOAT32,
+ "MESA_FORMAT_LUMINANCE_FLOAT32",
+ GL_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 0,
+ 32, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_LUMINANCE_FLOAT16,
+ "MESA_FORMAT_LUMINANCE_FLOAT16",
+ GL_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 0,
+ 16, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
+ "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
+ GL_LUMINANCE_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 32,
+ 32, 0, 0, 0, 0,
+ 1, 1, 8
+ },
+ {
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
+ "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
+ GL_LUMINANCE_ALPHA,
+ GL_FLOAT,
+ 0, 0, 0, 16,
+ 16, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_INTENSITY_FLOAT32,
+ "MESA_FORMAT_INTENSITY_FLOAT32",
+ GL_INTENSITY,
+ GL_FLOAT,
+ 0, 0, 0, 0,
+ 0, 32, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_INTENSITY_FLOAT16,
+ "MESA_FORMAT_INTENSITY_FLOAT16",
+ GL_INTENSITY,
+ GL_FLOAT,
+ 0, 0, 0, 0,
+ 0, 16, 0, 0, 0,
+ 1, 1, 2
+ },
+
+ /* unnormalized signed int formats */
+ {
+ MESA_FORMAT_RGBA_INT8,
+ "MESA_FORMAT_RGBA_INT8",
+ GL_RGBA,
+ GL_INT,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_RGBA_INT16,
+ "MESA_FORMAT_RGBA_INT16",
+ GL_RGBA,
+ GL_INT,
+ 16, 16, 16, 16,
+ 0, 0, 0, 0, 0,
+ 1, 1, 8
+ },
+ {
+ MESA_FORMAT_RGBA_INT32,
+ "MESA_FORMAT_RGBA_INT32",
+ GL_RGBA,
+ GL_INT,
+ 32, 32, 32, 32,
+ 0, 0, 0, 0, 0,
+ 1, 1, 16
+ },
+
+ /* unnormalized unsigned int formats */
+ {
+ MESA_FORMAT_RGBA_UINT8,
+ "MESA_FORMAT_RGBA_UINT8",
+ GL_RGBA,
+ GL_UNSIGNED_INT,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_RGBA_UINT16,
+ "MESA_FORMAT_RGBA_UINT16",
+ GL_RGBA,
+ GL_UNSIGNED_INT,
+ 16, 16, 16, 16,
+ 0, 0, 0, 0, 0,
+ 1, 1, 8
+ },
+ {
+ MESA_FORMAT_RGBA_UINT32,
+ "MESA_FORMAT_RGBA_UINT32",
+ GL_RGBA,
+ GL_UNSIGNED_INT,
+ 32, 32, 32, 32,
+ 0, 0, 0, 0, 0,
+ 1, 1, 16
+ },
+
+
+ {
+ MESA_FORMAT_DUDV8,
+ "MESA_FORMAT_DUDV8",
+ GL_DUDV_ATI,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+
+ /* Signed 8 bits / channel */
+ {
+ MESA_FORMAT_SIGNED_R8, /* Name */
+ "MESA_FORMAT_SIGNED_R8", /* StrName */
+ GL_RED, /* BaseFormat */
+ GL_SIGNED_NORMALIZED, /* DataType */
+ 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
+ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
+ 1, 1, 1 /* BlockWidth/Height,Bytes */
+ },
+ {
+ MESA_FORMAT_SIGNED_RG88,
+ "MESA_FORMAT_SIGNED_RG88",
+ GL_RG,
+ GL_SIGNED_NORMALIZED,
+ 8, 8, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBX8888,
+ "MESA_FORMAT_SIGNED_RGBX8888",
+ GL_RGB,
+ GL_SIGNED_NORMALIZED,
+ 8, 8, 8, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4 /* 4 bpp, but no alpha */
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA8888,
+ "MESA_FORMAT_SIGNED_RGBA8888",
+ GL_RGBA,
+ GL_SIGNED_NORMALIZED,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA8888_REV,
+ "MESA_FORMAT_SIGNED_RGBA8888_REV",
+ GL_RGBA,
+ GL_SIGNED_NORMALIZED,
+ 8, 8, 8, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+
+ /* Signed 16 bits / channel */
+ {
+ MESA_FORMAT_SIGNED_R_16,
+ "MESA_FORMAT_SIGNED_R_16",
+ GL_RED,
+ GL_SIGNED_NORMALIZED,
+ 16, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_SIGNED_RG_16,
+ "MESA_FORMAT_SIGNED_RG_16",
+ GL_RG,
+ GL_SIGNED_NORMALIZED,
+ 16, 16, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_SIGNED_RGB_16,
+ "MESA_FORMAT_SIGNED_RGB_16",
+ GL_RGB,
+ GL_SIGNED_NORMALIZED,
+ 16, 16, 16, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 6
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA_16,
+ "MESA_FORMAT_SIGNED_RGBA_16",
+ GL_RGBA,
+ GL_SIGNED_NORMALIZED,
+ 16, 16, 16, 16,
+ 0, 0, 0, 0, 0,
+ 1, 1, 8
+ },
+ {
+ MESA_FORMAT_RGBA_16,
+ "MESA_FORMAT_RGBA_16",
+ GL_RGBA,
+ GL_UNSIGNED_NORMALIZED,
+ 16, 16, 16, 16,
+ 0, 0, 0, 0, 0,
+ 1, 1, 8
+ },
+ {
+ MESA_FORMAT_RED_RGTC1,
+ "MESA_FORMAT_RED_RGTC1",
+ GL_RED,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_SIGNED_RED_RGTC1,
+ "MESA_FORMAT_SIGNED_RED_RGTC1",
+ GL_RED,
+ GL_SIGNED_NORMALIZED,
+ 4, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_RG_RGTC2,
+ "MESA_FORMAT_RG_RGTC2",
+ GL_RG,
+ GL_UNSIGNED_NORMALIZED,
+ 4, 4, 0, 0,
+ 0, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_SIGNED_RG_RGTC2,
+ "MESA_FORMAT_SIGNED_RG_RGTC2",
+ GL_RG,
+ GL_SIGNED_NORMALIZED,
+ 4, 4, 0, 0,
+ 0, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+};
+
+
+
+static const struct gl_format_info *
+_mesa_get_format_info(gl_format format)
+{
+ const struct gl_format_info *info = &format_info[format];
+ assert(info->Name == format);
+ return info;
+}
+
+
+/** Return string name of format (for debugging) */
+const char *
+_mesa_get_format_name(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ return info->StrName;
+}
+
+
+
+/**
+ * Return bytes needed to store a block of pixels in the given format.
+ * Normally, a block is 1x1 (a single pixel). But for compressed formats
+ * a block may be 4x4 or 8x4, etc.
+ */
+GLuint
+_mesa_get_format_bytes(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ ASSERT(info->BytesPerBlock);
+ return info->BytesPerBlock;
+}
+
+
+/**
+ * Return bits per component for the given format.
+ * \param format one of MESA_FORMAT_x
+ * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
+ */
+GLint
+_mesa_get_format_bits(gl_format format, GLenum pname)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+
+ switch (pname) {
+ case GL_RED_BITS:
+ case GL_TEXTURE_RED_SIZE:
+ case GL_RENDERBUFFER_RED_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
+ return info->RedBits;
+ case GL_GREEN_BITS:
+ case GL_TEXTURE_GREEN_SIZE:
+ case GL_RENDERBUFFER_GREEN_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
+ return info->GreenBits;
+ case GL_BLUE_BITS:
+ case GL_TEXTURE_BLUE_SIZE:
+ case GL_RENDERBUFFER_BLUE_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
+ return info->BlueBits;
+ case GL_ALPHA_BITS:
+ case GL_TEXTURE_ALPHA_SIZE:
+ case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
+ return info->AlphaBits;
+ case GL_TEXTURE_INTENSITY_SIZE:
+ return info->IntensityBits;
+ case GL_TEXTURE_LUMINANCE_SIZE:
+ return info->LuminanceBits;
+ case GL_INDEX_BITS:
+ case GL_TEXTURE_INDEX_SIZE_EXT:
+ return info->IndexBits;
+ case GL_DEPTH_BITS:
+ case GL_TEXTURE_DEPTH_SIZE_ARB:
+ case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
+ return info->DepthBits;
+ case GL_STENCIL_BITS:
+ case GL_TEXTURE_STENCIL_SIZE_EXT:
+ case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
+ case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
+ return info->StencilBits;
+ default:
+ _mesa_problem(NULL, "bad pname in _mesa_get_format_bits()");
+ return 0;
+ }
+}
+
+
+/**
+ * Return the data type (or more specifically, the data representation)
+ * for the given format.
+ * The return value will be one of:
+ * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
+ * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
+ * GL_UNSIGNED_INT = an ordinary unsigned integer
+ * GL_INT = an ordinary signed integer
+ * GL_FLOAT = an ordinary float
+ */
+GLenum
+_mesa_get_format_datatype(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ return info->DataType;
+}
+
+
+/**
+ * Return the basic format for the given type. The result will be
+ * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
+ * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
+ * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
+ */
+GLenum
+_mesa_get_format_base_format(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ return info->BaseFormat;
+}
+
+
+/**
+ * Return the block size (in pixels) for the given format. Normally
+ * the block size is 1x1. But compressed formats will have block sizes
+ * of 4x4 or 8x4 pixels, etc.
+ * \param bw returns block width in pixels
+ * \param bh returns block height in pixels
+ */
+void
+_mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ *bw = info->BlockWidth;
+ *bh = info->BlockHeight;
+}
+
+
+/** Is the given format a compressed format? */
+GLboolean
+_mesa_is_format_compressed(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ return info->BlockWidth > 1 || info->BlockHeight > 1;
+}
+
+
+/**
+ * Determine if the given format represents a packed depth/stencil buffer.
+ */
+GLboolean
+_mesa_is_format_packed_depth_stencil(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+
+ return info->BaseFormat == GL_DEPTH_STENCIL;
+}
+
+
+/**
+ * Is the given format a signed/unsigned integer color format?
+ */
+GLboolean
+_mesa_is_format_integer_color(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) &&
+ info->BaseFormat != GL_DEPTH_COMPONENT &&
+ info->BaseFormat != GL_DEPTH_STENCIL &&
+ info->BaseFormat != GL_STENCIL_INDEX;
+}
+
+
+/**
+ * Return color encoding for given format.
+ * \return GL_LINEAR or GL_SRGB
+ */
+GLenum
+_mesa_get_format_color_encoding(gl_format format)
+{
+ /* XXX this info should be encoded in gl_format_info */
+ switch (format) {
+ case MESA_FORMAT_SRGB8:
+ case MESA_FORMAT_SRGBA8:
+ case MESA_FORMAT_SARGB8:
+ case MESA_FORMAT_SL8:
+ case MESA_FORMAT_SLA8:
+ case MESA_FORMAT_SRGB_DXT1:
+ case MESA_FORMAT_SRGBA_DXT1:
+ case MESA_FORMAT_SRGBA_DXT3:
+ case MESA_FORMAT_SRGBA_DXT5:
+ return GL_SRGB;
+ default:
+ return GL_LINEAR;
+ }
+}
+
+
+/**
+ * For an sRGB format, return the corresponding linear color space format.
+ * For non-sRGB formats, return the format as-is.
+ */
+gl_format
+_mesa_get_srgb_format_linear(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_SRGB8:
+ format = MESA_FORMAT_RGB888;
+ break;
+ case MESA_FORMAT_SRGBA8:
+ format = MESA_FORMAT_RGBA8888;
+ break;
+ case MESA_FORMAT_SARGB8:
+ format = MESA_FORMAT_ARGB8888;
+ break;
+ case MESA_FORMAT_SL8:
+ format = MESA_FORMAT_L8;
+ break;
+ case MESA_FORMAT_SLA8:
+ format = MESA_FORMAT_AL88;
+ break;
+ case MESA_FORMAT_SRGB_DXT1:
+ format = MESA_FORMAT_RGB_DXT1;
+ break;
+ case MESA_FORMAT_SRGBA_DXT1:
+ format = MESA_FORMAT_RGBA_DXT1;
+ break;
+ case MESA_FORMAT_SRGBA_DXT3:
+ format = MESA_FORMAT_RGBA_DXT3;
+ break;
+ case MESA_FORMAT_SRGBA_DXT5:
+ format = MESA_FORMAT_RGBA_DXT5;
+ break;
+ default:
+ break;
+ }
+ return format;
+}
+
+
+/**
+ * Return number of bytes needed to store an image of the given size
+ * in the given format.
+ */
+GLuint
+_mesa_format_image_size(gl_format format, GLsizei width,
+ GLsizei height, GLsizei depth)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ /* Strictly speaking, a conditional isn't needed here */
+ if (info->BlockWidth > 1 || info->BlockHeight > 1) {
+ /* compressed format (2D only for now) */
+ const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
+ const GLuint wblocks = (width + bw - 1) / bw;
+ const GLuint hblocks = (height + bh - 1) / bh;
+ const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
+ assert(depth == 1);
+ return sz;
+ }
+ else {
+ /* non-compressed */
+ const GLuint sz = width * height * depth * info->BytesPerBlock;
+ return sz;
+ }
+}
+
+
+/**
+ * Same as _mesa_format_image_size() but returns a 64-bit value to
+ * accomodate very large textures.
+ */
+uint64_t
+_mesa_format_image_size64(gl_format format, GLsizei width,
+ GLsizei height, GLsizei depth)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ /* Strictly speaking, a conditional isn't needed here */
+ if (info->BlockWidth > 1 || info->BlockHeight > 1) {
+ /* compressed format (2D only for now) */
+ const uint64_t bw = info->BlockWidth, bh = info->BlockHeight;
+ const uint64_t wblocks = (width + bw - 1) / bw;
+ const uint64_t hblocks = (height + bh - 1) / bh;
+ const uint64_t sz = wblocks * hblocks * info->BytesPerBlock;
+ assert(depth == 1);
+ return sz;
+ }
+ else {
+ /* non-compressed */
+ const uint64_t sz = ((uint64_t) width *
+ (uint64_t) height *
+ (uint64_t) depth *
+ info->BytesPerBlock);
+ return sz;
+ }
+}
+
+
+
+GLint
+_mesa_format_row_stride(gl_format format, GLsizei width)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ /* Strictly speaking, a conditional isn't needed here */
+ if (info->BlockWidth > 1 || info->BlockHeight > 1) {
+ /* compressed format */
+ const GLuint bw = info->BlockWidth;
+ const GLuint wblocks = (width + bw - 1) / bw;
+ const GLint stride = wblocks * info->BytesPerBlock;
+ return stride;
+ }
+ else {
+ const GLint stride = width * info->BytesPerBlock;
+ return stride;
+ }
+}
+
+
+/**
+ * Debug/test: check that all formats are handled in the
+ * _mesa_format_to_type_and_comps() function. When new pixel formats
+ * are added to Mesa, that function needs to be updated.
+ * This is a no-op after the first call.
+ */
+static void
+check_format_to_type_and_comps(void)
+{
+ gl_format f;
+
+ for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) {
+ GLenum datatype = 0;
+ GLuint comps = 0;
+ /* This function will emit a problem/warning if the format is
+ * not handled.
+ */
+ _mesa_format_to_type_and_comps(f, &datatype, &comps);
+ }
+}
+
+
+/**
+ * Do sanity checking of the format info table.
+ */
+void
+_mesa_test_formats(void)
+{
+ GLuint i;
+
+ assert(Elements(format_info) == MESA_FORMAT_COUNT);
+
+ for (i = 0; i < MESA_FORMAT_COUNT; i++) {
+ const struct gl_format_info *info = _mesa_get_format_info(i);
+ assert(info);
+
+ assert(info->Name == i);
+
+ if (info->Name == MESA_FORMAT_NONE)
+ continue;
+
+ if (info->BlockWidth == 1 && info->BlockHeight == 1) {
+ if (info->RedBits > 0) {
+ GLuint t = info->RedBits + info->GreenBits
+ + info->BlueBits + info->AlphaBits;
+ assert(t / 8 <= info->BytesPerBlock);
+ (void) t;
+ }
+ }
+
+ assert(info->DataType == GL_UNSIGNED_NORMALIZED ||
+ info->DataType == GL_SIGNED_NORMALIZED ||
+ info->DataType == GL_UNSIGNED_INT ||
+ info->DataType == GL_INT ||
+ info->DataType == GL_FLOAT);
+
+ if (info->BaseFormat == GL_RGB) {
+ assert(info->RedBits > 0);
+ assert(info->GreenBits > 0);
+ assert(info->BlueBits > 0);
+ assert(info->AlphaBits == 0);
+ assert(info->LuminanceBits == 0);
+ assert(info->IntensityBits == 0);
+ }
+ else if (info->BaseFormat == GL_RGBA) {
+ assert(info->RedBits > 0);
+ assert(info->GreenBits > 0);
+ assert(info->BlueBits > 0);
+ assert(info->AlphaBits > 0);
+ assert(info->LuminanceBits == 0);
+ assert(info->IntensityBits == 0);
+ }
+ else if (info->BaseFormat == GL_RG) {
+ assert(info->RedBits > 0);
+ assert(info->GreenBits > 0);
+ assert(info->BlueBits == 0);
+ assert(info->AlphaBits == 0);
+ assert(info->LuminanceBits == 0);
+ assert(info->IntensityBits == 0);
+ }
+ else if (info->BaseFormat == GL_RED) {
+ assert(info->RedBits > 0);
+ assert(info->GreenBits == 0);
+ assert(info->BlueBits == 0);
+ assert(info->AlphaBits == 0);
+ assert(info->LuminanceBits == 0);
+ assert(info->IntensityBits == 0);
+ }
+ else if (info->BaseFormat == GL_LUMINANCE) {
+ assert(info->RedBits == 0);
+ assert(info->GreenBits == 0);
+ assert(info->BlueBits == 0);
+ assert(info->AlphaBits == 0);
+ assert(info->LuminanceBits > 0);
+ assert(info->IntensityBits == 0);
+ }
+ else if (info->BaseFormat == GL_INTENSITY) {
+ assert(info->RedBits == 0);
+ assert(info->GreenBits == 0);
+ assert(info->BlueBits == 0);
+ assert(info->AlphaBits == 0);
+ assert(info->LuminanceBits == 0);
+ assert(info->IntensityBits > 0);
+ }
+ }
+
+ check_format_to_type_and_comps();
+}
+
+
+
+/**
+ * Return datatype and number of components per texel for the given gl_format.
+ * Only used for mipmap generation code.
+ */
+void
+_mesa_format_to_type_and_comps(gl_format format,
+ GLenum *datatype, GLuint *comps)
+{
+ switch (format) {
+ case MESA_FORMAT_RGBA8888:
+ case MESA_FORMAT_RGBA8888_REV:
+ case MESA_FORMAT_ARGB8888:
+ case MESA_FORMAT_ARGB8888_REV:
+ case MESA_FORMAT_XRGB8888:
+ case MESA_FORMAT_XRGB8888_REV:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_RGB888:
+ case MESA_FORMAT_BGR888:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 3;
+ return;
+ case MESA_FORMAT_RGB565:
+ case MESA_FORMAT_RGB565_REV:
+ *datatype = GL_UNSIGNED_SHORT_5_6_5;
+ *comps = 3;
+ return;
+
+ case MESA_FORMAT_ARGB4444:
+ case MESA_FORMAT_ARGB4444_REV:
+ *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
+ *comps = 4;
+ return;
+
+ case MESA_FORMAT_ARGB1555:
+ case MESA_FORMAT_ARGB1555_REV:
+ *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+ *comps = 4;
+ return;
+
+ case MESA_FORMAT_ARGB2101010:
+ *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
+ *comps = 4;
+ return;
+
+ case MESA_FORMAT_RGBA5551:
+ *datatype = GL_UNSIGNED_SHORT_5_5_5_1;
+ *comps = 4;
+ return;
+
+ case MESA_FORMAT_AL44:
+ *datatype = MESA_UNSIGNED_BYTE_4_4;
+ *comps = 2;
+ return;
+
+ case MESA_FORMAT_AL88:
+ case MESA_FORMAT_AL88_REV:
+ case MESA_FORMAT_RG88:
+ case MESA_FORMAT_RG88_REV:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 2;
+ return;
+
+ case MESA_FORMAT_AL1616:
+ case MESA_FORMAT_AL1616_REV:
+ case MESA_FORMAT_RG1616:
+ case MESA_FORMAT_RG1616_REV:
+ *datatype = GL_UNSIGNED_SHORT;
+ *comps = 2;
+ return;
+
+ case MESA_FORMAT_R16:
+ case MESA_FORMAT_A16:
+ case MESA_FORMAT_L16:
+ case MESA_FORMAT_I16:
+ *datatype = GL_UNSIGNED_SHORT;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_RGB332:
+ *datatype = GL_UNSIGNED_BYTE_3_3_2;
+ *comps = 3;
+ return;
+
+ case MESA_FORMAT_A8:
+ case MESA_FORMAT_L8:
+ case MESA_FORMAT_I8:
+ case MESA_FORMAT_CI8:
+ case MESA_FORMAT_R8:
+ case MESA_FORMAT_S8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_YCBCR:
+ case MESA_FORMAT_YCBCR_REV:
+ *datatype = GL_UNSIGNED_SHORT;
+ *comps = 2;
+ return;
+
+ case MESA_FORMAT_Z24_S8:
+ *datatype = GL_UNSIGNED_INT;
+ *comps = 1; /* XXX OK? */
+ return;
+
+ case MESA_FORMAT_S8_Z24:
+ *datatype = GL_UNSIGNED_INT;
+ *comps = 1; /* XXX OK? */
+ return;
+
+ case MESA_FORMAT_Z16:
+ *datatype = GL_UNSIGNED_SHORT;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_X8_Z24:
+ *datatype = GL_UNSIGNED_INT;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_Z24_X8:
+ *datatype = GL_UNSIGNED_INT;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_Z32:
+ *datatype = GL_UNSIGNED_INT;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_DUDV8:
+ *datatype = GL_BYTE;
+ *comps = 2;
+ return;
+
+ case MESA_FORMAT_SIGNED_R8:
+ *datatype = GL_BYTE;
+ *comps = 1;
+ return;
+ case MESA_FORMAT_SIGNED_RG88:
+ *datatype = GL_BYTE;
+ *comps = 2;
+ return;
+ case MESA_FORMAT_SIGNED_RGBA8888:
+ case MESA_FORMAT_SIGNED_RGBA8888_REV:
+ case MESA_FORMAT_SIGNED_RGBX8888:
+ *datatype = GL_BYTE;
+ *comps = 4;
+ return;
+
+ case MESA_FORMAT_RGBA_16:
+ *datatype = GL_UNSIGNED_SHORT;
+ *comps = 4;
+ return;
+
+ case MESA_FORMAT_SIGNED_R_16:
+ *datatype = GL_SHORT;
+ *comps = 1;
+ return;
+ case MESA_FORMAT_SIGNED_RG_16:
+ *datatype = GL_SHORT;
+ *comps = 2;
+ return;
+ case MESA_FORMAT_SIGNED_RGB_16:
+ *datatype = GL_SHORT;
+ *comps = 3;
+ return;
+ case MESA_FORMAT_SIGNED_RGBA_16:
+ *datatype = GL_SHORT;
+ *comps = 4;
+ return;
+
+#if FEATURE_EXT_texture_sRGB
+ case MESA_FORMAT_SRGB8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 3;
+ return;
+ case MESA_FORMAT_SRGBA8:
+ case MESA_FORMAT_SARGB8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_SL8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 1;
+ return;
+ case MESA_FORMAT_SLA8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 2;
+ return;
+#endif
+
+#if FEATURE_texture_fxt1
+ case MESA_FORMAT_RGB_FXT1:
+ case MESA_FORMAT_RGBA_FXT1:
+#endif
+#if FEATURE_texture_s3tc
+ case MESA_FORMAT_RGB_DXT1:
+ case MESA_FORMAT_RGBA_DXT1:
+ case MESA_FORMAT_RGBA_DXT3:
+ case MESA_FORMAT_RGBA_DXT5:
+#if FEATURE_EXT_texture_sRGB
+ case MESA_FORMAT_SRGB_DXT1:
+ case MESA_FORMAT_SRGBA_DXT1:
+ case MESA_FORMAT_SRGBA_DXT3:
+ case MESA_FORMAT_SRGBA_DXT5:
+#endif
+#endif
+ case MESA_FORMAT_RED_RGTC1:
+ case MESA_FORMAT_SIGNED_RED_RGTC1:
+ case MESA_FORMAT_RG_RGTC2:
+ case MESA_FORMAT_SIGNED_RG_RGTC2:
+ /* XXX generate error instead? */
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 0;
+ return;
+
+ case MESA_FORMAT_RGBA_FLOAT32:
+ *datatype = GL_FLOAT;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_RGBA_FLOAT16:
+ *datatype = GL_HALF_FLOAT_ARB;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_RGB_FLOAT32:
+ *datatype = GL_FLOAT;
+ *comps = 3;
+ return;
+ case MESA_FORMAT_RGB_FLOAT16:
+ *datatype = GL_HALF_FLOAT_ARB;
+ *comps = 3;
+ return;
+ case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
+ *datatype = GL_FLOAT;
+ *comps = 2;
+ return;
+ case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
+ *datatype = GL_HALF_FLOAT_ARB;
+ *comps = 2;
+ return;
+ case MESA_FORMAT_ALPHA_FLOAT32:
+ case MESA_FORMAT_LUMINANCE_FLOAT32:
+ case MESA_FORMAT_INTENSITY_FLOAT32:
+ *datatype = GL_FLOAT;
+ *comps = 1;
+ return;
+ case MESA_FORMAT_ALPHA_FLOAT16:
+ case MESA_FORMAT_LUMINANCE_FLOAT16:
+ case MESA_FORMAT_INTENSITY_FLOAT16:
+ *datatype = GL_HALF_FLOAT_ARB;
+ *comps = 1;
+ return;
+
+ case MESA_FORMAT_RGBA_INT8:
+ *datatype = GL_BYTE;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_RGBA_INT16:
+ *datatype = GL_SHORT;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_RGBA_INT32:
+ *datatype = GL_INT;
+ *comps = 4;
+ return;
+
+ /**
+ * \name Non-normalized unsigned integer formats.
+ */
+ case MESA_FORMAT_RGBA_UINT8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_RGBA_UINT16:
+ *datatype = GL_UNSIGNED_SHORT;
+ *comps = 4;
+ return;
+ case MESA_FORMAT_RGBA_UINT32:
+ *datatype = GL_UNSIGNED_INT;
+ *comps = 4;
+ return;
+
+ case MESA_FORMAT_COUNT:
+ assert(0);
+ return;
+
+ case MESA_FORMAT_NONE:
+ /* For debug builds, warn if any formats are not handled */
+#ifdef DEBUG
+ default:
+#endif
+ _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps",
+ _mesa_get_format_name(format));
+ *datatype = 0;
+ *comps = 1;
+ }
+}
diff --git a/mesalib/src/mesa/main/formats.h b/mesalib/src/mesa/main/formats.h
index e21967e2b..b32829145 100644
--- a/mesalib/src/mesa/main/formats.h
+++ b/mesalib/src/mesa/main/formats.h
@@ -1,243 +1,243 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.7
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (c) 2008-2009 VMware, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * Authors:
- * Brian Paul
- */
-
-
-#ifndef FORMATS_H
-#define FORMATS_H
-
-
-#include <GL/gl.h>
-
-/* OpenGL doesn't have GL_UNSIGNED_BYTE_4_4, so we must define our own type
- * for GL_LUMINANCE4_ALPHA4. */
-#define MESA_UNSIGNED_BYTE_4_4 (GL_UNSIGNED_BYTE<<1)
-
-
-/**
- * Mesa texture/renderbuffer image formats.
- */
-typedef enum
-{
- MESA_FORMAT_NONE = 0,
-
- /**
- * \name Basic hardware formats
- */
- /*@{*/
- /* msb <------ TEXEL BITS -----------> lsb */
- /* ---- ---- ---- ---- ---- ---- ---- ---- */
- MESA_FORMAT_RGBA8888, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
- MESA_FORMAT_RGBA8888_REV, /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
- MESA_FORMAT_ARGB8888, /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
- MESA_FORMAT_ARGB8888_REV, /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
- MESA_FORMAT_XRGB8888, /* xxxx xxxx RRRR RRRR GGGG GGGG BBBB BBBB */
- MESA_FORMAT_XRGB8888_REV, /* BBBB BBBB GGGG GGGG RRRR RRRR xxxx xxxx */
- MESA_FORMAT_RGB888, /* RRRR RRRR GGGG GGGG BBBB BBBB */
- MESA_FORMAT_BGR888, /* BBBB BBBB GGGG GGGG RRRR RRRR */
- MESA_FORMAT_RGB565, /* RRRR RGGG GGGB BBBB */
- MESA_FORMAT_RGB565_REV, /* GGGB BBBB RRRR RGGG */
- MESA_FORMAT_ARGB4444, /* AAAA RRRR GGGG BBBB */
- MESA_FORMAT_ARGB4444_REV, /* GGGG BBBB AAAA RRRR */
- MESA_FORMAT_RGBA5551, /* RRRR RGGG GGBB BBBA */
- MESA_FORMAT_ARGB1555, /* ARRR RRGG GGGB BBBB */
- MESA_FORMAT_ARGB1555_REV, /* GGGB BBBB ARRR RRGG */
- MESA_FORMAT_AL44, /* AAAA LLLL */
- MESA_FORMAT_AL88, /* AAAA AAAA LLLL LLLL */
- MESA_FORMAT_AL88_REV, /* LLLL LLLL AAAA AAAA */
- MESA_FORMAT_AL1616, /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
- MESA_FORMAT_AL1616_REV, /* LLLL LLLL LLLL LLLL AAAA AAAA AAAA AAAA */
- MESA_FORMAT_RGB332, /* RRRG GGBB */
- MESA_FORMAT_A8, /* AAAA AAAA */
- MESA_FORMAT_A16, /* AAAA AAAA AAAA AAAA */
- MESA_FORMAT_L8, /* LLLL LLLL */
- MESA_FORMAT_L16, /* LLLL LLLL LLLL LLLL */
- MESA_FORMAT_I8, /* IIII IIII */
- MESA_FORMAT_I16, /* IIII IIII IIII IIII */
- MESA_FORMAT_CI8, /* CCCC CCCC */
- MESA_FORMAT_YCBCR, /* YYYY YYYY UorV UorV */
- MESA_FORMAT_YCBCR_REV, /* UorV UorV YYYY YYYY */
- MESA_FORMAT_R8, /* RRRR RRRR */
- MESA_FORMAT_RG88, /* RRRR RRRR GGGG GGGG */
- MESA_FORMAT_RG88_REV, /* GGGG GGGG RRRR RRRR */
- MESA_FORMAT_R16, /* RRRR RRRR RRRR RRRR */
- MESA_FORMAT_RG1616, /* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */
- MESA_FORMAT_RG1616_REV, /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
- MESA_FORMAT_ARGB2101010, /* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
- MESA_FORMAT_Z24_S8, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
- MESA_FORMAT_S8_Z24, /* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
- MESA_FORMAT_Z16, /* ZZZZ ZZZZ ZZZZ ZZZZ */
- MESA_FORMAT_X8_Z24, /* xxxx xxxx ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
- MESA_FORMAT_Z24_X8, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ xxxx xxxx */
- MESA_FORMAT_Z32, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
- MESA_FORMAT_S8, /* SSSS SSSS */
- /*@}*/
-
- /**
- * \name 8-bit/channel sRGB formats
- */
- /*@{*/
- MESA_FORMAT_SRGB8,
- MESA_FORMAT_SRGBA8,
- MESA_FORMAT_SARGB8,
- MESA_FORMAT_SL8,
- MESA_FORMAT_SLA8,
- MESA_FORMAT_SRGB_DXT1,
- MESA_FORMAT_SRGBA_DXT1,
- MESA_FORMAT_SRGBA_DXT3,
- MESA_FORMAT_SRGBA_DXT5,
- /*@}*/
-
- /**
- * \name Compressed texture formats.
- */
- /*@{*/
- MESA_FORMAT_RGB_FXT1,
- MESA_FORMAT_RGBA_FXT1,
- MESA_FORMAT_RGB_DXT1,
- MESA_FORMAT_RGBA_DXT1,
- MESA_FORMAT_RGBA_DXT3,
- MESA_FORMAT_RGBA_DXT5,
- /*@}*/
-
- /**
- * \name Floating point texture formats.
- */
- /*@{*/
- MESA_FORMAT_RGBA_FLOAT32,
- MESA_FORMAT_RGBA_FLOAT16,
- MESA_FORMAT_RGB_FLOAT32,
- MESA_FORMAT_RGB_FLOAT16,
- MESA_FORMAT_ALPHA_FLOAT32,
- MESA_FORMAT_ALPHA_FLOAT16,
- MESA_FORMAT_LUMINANCE_FLOAT32,
- MESA_FORMAT_LUMINANCE_FLOAT16,
- MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
- MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
- MESA_FORMAT_INTENSITY_FLOAT32,
- MESA_FORMAT_INTENSITY_FLOAT16,
- /*@}*/
-
- /**
- * \name Non-normalized signed integer formats.
- * XXX Note: these are just stand-ins for some better hardware
- * formats TBD such as BGRA or ARGB.
- */
- MESA_FORMAT_RGBA_INT8,
- MESA_FORMAT_RGBA_INT16,
- MESA_FORMAT_RGBA_INT32,
-
- /**
- * \name Non-normalized unsigned integer formats.
- */
- MESA_FORMAT_RGBA_UINT8,
- MESA_FORMAT_RGBA_UINT16,
- MESA_FORMAT_RGBA_UINT32,
-
- /* msb <------ TEXEL BITS -----------> lsb */
- /* ---- ---- ---- ---- ---- ---- ---- ---- */
- /**
- * \name Signed fixed point texture formats.
- */
- /*@{*/
- MESA_FORMAT_DUDV8, /* DUDU DUDU DVDV DVDV */
- MESA_FORMAT_SIGNED_R8, /* RRRR RRRR */
- MESA_FORMAT_SIGNED_RG88, /* RRRR RRRR GGGG GGGG */
- MESA_FORMAT_SIGNED_RGBX8888, /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */
- MESA_FORMAT_SIGNED_RGBA8888, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
- MESA_FORMAT_SIGNED_RGBA8888_REV,/*AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
- MESA_FORMAT_SIGNED_R_16, /* ushort[0]=R */
- MESA_FORMAT_SIGNED_RG_16, /* ushort[0]=R, ushort[1]=G */
- MESA_FORMAT_SIGNED_RGB_16, /* ushort[0]=R, ushort[1]=G, ushort[2]=B */
- MESA_FORMAT_SIGNED_RGBA_16, /* ... */
- MESA_FORMAT_RGBA_16, /* ... */
- /*@}*/
-
- /*@{*/
- MESA_FORMAT_RED_RGTC1,
- MESA_FORMAT_SIGNED_RED_RGTC1,
- MESA_FORMAT_RG_RGTC2,
- MESA_FORMAT_SIGNED_RG_RGTC2,
- /*@}*/
- MESA_FORMAT_COUNT
-} gl_format;
-
-
-extern const char *
-_mesa_get_format_name(gl_format format);
-
-extern GLuint
-_mesa_get_format_bytes(gl_format format);
-
-extern GLint
-_mesa_get_format_bits(gl_format format, GLenum pname);
-
-extern GLenum
-_mesa_get_format_datatype(gl_format format);
-
-extern GLenum
-_mesa_get_format_base_format(gl_format format);
-
-extern void
-_mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh);
-
-extern GLboolean
-_mesa_is_format_compressed(gl_format format);
-
-extern GLboolean
-_mesa_is_format_packed_depth_stencil(gl_format format);
-
-extern GLboolean
-_mesa_is_format_integer_color(gl_format format);
-
-extern GLenum
-_mesa_get_format_color_encoding(gl_format format);
-
-extern GLuint
-_mesa_format_image_size(gl_format format, GLsizei width,
- GLsizei height, GLsizei depth);
-
-extern uint64_t
-_mesa_format_image_size64(gl_format format, GLsizei width,
- GLsizei height, GLsizei depth);
-
-extern GLint
-_mesa_format_row_stride(gl_format format, GLsizei width);
-
-extern void
-_mesa_format_to_type_and_comps(gl_format format,
- GLenum *datatype, GLuint *comps);
-
-extern void
-_mesa_test_formats(void);
-
-extern gl_format
-_mesa_get_srgb_format_linear(gl_format format);
-
-#endif /* FORMATS_H */
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008-2009 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Brian Paul
+ */
+
+
+#ifndef FORMATS_H
+#define FORMATS_H
+
+
+#include <GL/gl.h>
+
+/* OpenGL doesn't have GL_UNSIGNED_BYTE_4_4, so we must define our own type
+ * for GL_LUMINANCE4_ALPHA4. */
+#define MESA_UNSIGNED_BYTE_4_4 (GL_UNSIGNED_BYTE<<1)
+
+
+/**
+ * Mesa texture/renderbuffer image formats.
+ */
+typedef enum
+{
+ MESA_FORMAT_NONE = 0,
+
+ /**
+ * \name Basic hardware formats
+ */
+ /*@{*/
+ /* msb <------ TEXEL BITS -----------> lsb */
+ /* ---- ---- ---- ---- ---- ---- ---- ---- */
+ MESA_FORMAT_RGBA8888, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
+ MESA_FORMAT_RGBA8888_REV, /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
+ MESA_FORMAT_ARGB8888, /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
+ MESA_FORMAT_ARGB8888_REV, /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
+ MESA_FORMAT_XRGB8888, /* xxxx xxxx RRRR RRRR GGGG GGGG BBBB BBBB */
+ MESA_FORMAT_XRGB8888_REV, /* BBBB BBBB GGGG GGGG RRRR RRRR xxxx xxxx */
+ MESA_FORMAT_RGB888, /* RRRR RRRR GGGG GGGG BBBB BBBB */
+ MESA_FORMAT_BGR888, /* BBBB BBBB GGGG GGGG RRRR RRRR */
+ MESA_FORMAT_RGB565, /* RRRR RGGG GGGB BBBB */
+ MESA_FORMAT_RGB565_REV, /* GGGB BBBB RRRR RGGG */
+ MESA_FORMAT_ARGB4444, /* AAAA RRRR GGGG BBBB */
+ MESA_FORMAT_ARGB4444_REV, /* GGGG BBBB AAAA RRRR */
+ MESA_FORMAT_RGBA5551, /* RRRR RGGG GGBB BBBA */
+ MESA_FORMAT_ARGB1555, /* ARRR RRGG GGGB BBBB */
+ MESA_FORMAT_ARGB1555_REV, /* GGGB BBBB ARRR RRGG */
+ MESA_FORMAT_AL44, /* AAAA LLLL */
+ MESA_FORMAT_AL88, /* AAAA AAAA LLLL LLLL */
+ MESA_FORMAT_AL88_REV, /* LLLL LLLL AAAA AAAA */
+ MESA_FORMAT_AL1616, /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
+ MESA_FORMAT_AL1616_REV, /* LLLL LLLL LLLL LLLL AAAA AAAA AAAA AAAA */
+ MESA_FORMAT_RGB332, /* RRRG GGBB */
+ MESA_FORMAT_A8, /* AAAA AAAA */
+ MESA_FORMAT_A16, /* AAAA AAAA AAAA AAAA */
+ MESA_FORMAT_L8, /* LLLL LLLL */
+ MESA_FORMAT_L16, /* LLLL LLLL LLLL LLLL */
+ MESA_FORMAT_I8, /* IIII IIII */
+ MESA_FORMAT_I16, /* IIII IIII IIII IIII */
+ MESA_FORMAT_CI8, /* CCCC CCCC */
+ MESA_FORMAT_YCBCR, /* YYYY YYYY UorV UorV */
+ MESA_FORMAT_YCBCR_REV, /* UorV UorV YYYY YYYY */
+ MESA_FORMAT_R8, /* RRRR RRRR */
+ MESA_FORMAT_RG88, /* RRRR RRRR GGGG GGGG */
+ MESA_FORMAT_RG88_REV, /* GGGG GGGG RRRR RRRR */
+ MESA_FORMAT_R16, /* RRRR RRRR RRRR RRRR */
+ MESA_FORMAT_RG1616, /* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */
+ MESA_FORMAT_RG1616_REV, /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
+ MESA_FORMAT_ARGB2101010, /* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
+ MESA_FORMAT_Z24_S8, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
+ MESA_FORMAT_S8_Z24, /* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
+ MESA_FORMAT_Z16, /* ZZZZ ZZZZ ZZZZ ZZZZ */
+ MESA_FORMAT_X8_Z24, /* xxxx xxxx ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
+ MESA_FORMAT_Z24_X8, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ xxxx xxxx */
+ MESA_FORMAT_Z32, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
+ MESA_FORMAT_S8, /* SSSS SSSS */
+ /*@}*/
+
+ /**
+ * \name 8-bit/channel sRGB formats
+ */
+ /*@{*/
+ MESA_FORMAT_SRGB8,
+ MESA_FORMAT_SRGBA8,
+ MESA_FORMAT_SARGB8,
+ MESA_FORMAT_SL8,
+ MESA_FORMAT_SLA8,
+ MESA_FORMAT_SRGB_DXT1,
+ MESA_FORMAT_SRGBA_DXT1,
+ MESA_FORMAT_SRGBA_DXT3,
+ MESA_FORMAT_SRGBA_DXT5,
+ /*@}*/
+
+ /**
+ * \name Compressed texture formats.
+ */
+ /*@{*/
+ MESA_FORMAT_RGB_FXT1,
+ MESA_FORMAT_RGBA_FXT1,
+ MESA_FORMAT_RGB_DXT1,
+ MESA_FORMAT_RGBA_DXT1,
+ MESA_FORMAT_RGBA_DXT3,
+ MESA_FORMAT_RGBA_DXT5,
+ /*@}*/
+
+ /**
+ * \name Floating point texture formats.
+ */
+ /*@{*/
+ MESA_FORMAT_RGBA_FLOAT32,
+ MESA_FORMAT_RGBA_FLOAT16,
+ MESA_FORMAT_RGB_FLOAT32,
+ MESA_FORMAT_RGB_FLOAT16,
+ MESA_FORMAT_ALPHA_FLOAT32,
+ MESA_FORMAT_ALPHA_FLOAT16,
+ MESA_FORMAT_LUMINANCE_FLOAT32,
+ MESA_FORMAT_LUMINANCE_FLOAT16,
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
+ MESA_FORMAT_INTENSITY_FLOAT32,
+ MESA_FORMAT_INTENSITY_FLOAT16,
+ /*@}*/
+
+ /**
+ * \name Non-normalized signed integer formats.
+ * XXX Note: these are just stand-ins for some better hardware
+ * formats TBD such as BGRA or ARGB.
+ */
+ MESA_FORMAT_RGBA_INT8,
+ MESA_FORMAT_RGBA_INT16,
+ MESA_FORMAT_RGBA_INT32,
+
+ /**
+ * \name Non-normalized unsigned integer formats.
+ */
+ MESA_FORMAT_RGBA_UINT8,
+ MESA_FORMAT_RGBA_UINT16,
+ MESA_FORMAT_RGBA_UINT32,
+
+ /* msb <------ TEXEL BITS -----------> lsb */
+ /* ---- ---- ---- ---- ---- ---- ---- ---- */
+ /**
+ * \name Signed fixed point texture formats.
+ */
+ /*@{*/
+ MESA_FORMAT_DUDV8, /* DUDU DUDU DVDV DVDV */
+ MESA_FORMAT_SIGNED_R8, /* RRRR RRRR */
+ MESA_FORMAT_SIGNED_RG88, /* RRRR RRRR GGGG GGGG */
+ MESA_FORMAT_SIGNED_RGBX8888, /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */
+ MESA_FORMAT_SIGNED_RGBA8888, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
+ MESA_FORMAT_SIGNED_RGBA8888_REV,/*AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
+ MESA_FORMAT_SIGNED_R_16, /* ushort[0]=R */
+ MESA_FORMAT_SIGNED_RG_16, /* ushort[0]=R, ushort[1]=G */
+ MESA_FORMAT_SIGNED_RGB_16, /* ushort[0]=R, ushort[1]=G, ushort[2]=B */
+ MESA_FORMAT_SIGNED_RGBA_16, /* ... */
+ MESA_FORMAT_RGBA_16, /* ... */
+ /*@}*/
+
+ /*@{*/
+ MESA_FORMAT_RED_RGTC1,
+ MESA_FORMAT_SIGNED_RED_RGTC1,
+ MESA_FORMAT_RG_RGTC2,
+ MESA_FORMAT_SIGNED_RG_RGTC2,
+ /*@}*/
+ MESA_FORMAT_COUNT
+} gl_format;
+
+
+extern const char *
+_mesa_get_format_name(gl_format format);
+
+extern GLuint
+_mesa_get_format_bytes(gl_format format);
+
+extern GLint
+_mesa_get_format_bits(gl_format format, GLenum pname);
+
+extern GLenum
+_mesa_get_format_datatype(gl_format format);
+
+extern GLenum
+_mesa_get_format_base_format(gl_format format);
+
+extern void
+_mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh);
+
+extern GLboolean
+_mesa_is_format_compressed(gl_format format);
+
+extern GLboolean
+_mesa_is_format_packed_depth_stencil(gl_format format);
+
+extern GLboolean
+_mesa_is_format_integer_color(gl_format format);
+
+extern GLenum
+_mesa_get_format_color_encoding(gl_format format);
+
+extern GLuint
+_mesa_format_image_size(gl_format format, GLsizei width,
+ GLsizei height, GLsizei depth);
+
+extern uint64_t
+_mesa_format_image_size64(gl_format format, GLsizei width,
+ GLsizei height, GLsizei depth);
+
+extern GLint
+_mesa_format_row_stride(gl_format format, GLsizei width);
+
+extern void
+_mesa_format_to_type_and_comps(gl_format format,
+ GLenum *datatype, GLuint *comps);
+
+extern void
+_mesa_test_formats(void);
+
+extern gl_format
+_mesa_get_srgb_format_linear(gl_format format);
+
+#endif /* FORMATS_H */
diff --git a/mesalib/src/mesa/main/framebuffer.c b/mesalib/src/mesa/main/framebuffer.c
index 227b214a5..a9e8de8af 100644
--- a/mesalib/src/mesa/main/framebuffer.c
+++ b/mesalib/src/mesa/main/framebuffer.c
@@ -1,1083 +1,1083 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.2
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * Functions for allocating/managing framebuffers and renderbuffers.
- * Also, routines for reading/writing renderbuffer data as ubytes,
- * ushorts, uints, etc.
- */
-
-
-#include "glheader.h"
-#include "imports.h"
-#include "buffers.h"
-#include "context.h"
-#include "depthstencil.h"
-#include "enums.h"
-#include "formats.h"
-#include "macros.h"
-#include "mtypes.h"
-#include "fbobject.h"
-#include "framebuffer.h"
-#include "renderbuffer.h"
-#include "texobj.h"
-
-
-
-/**
- * Compute/set the _DepthMax field for the given framebuffer.
- * This value depends on the Z buffer resolution.
- */
-static void
-compute_depth_max(struct gl_framebuffer *fb)
-{
- if (fb->Visual.depthBits == 0) {
- /* Special case. Even if we don't have a depth buffer we need
- * good values for DepthMax for Z vertex transformation purposes
- * and for per-fragment fog computation.
- */
- fb->_DepthMax = (1 << 16) - 1;
- }
- else if (fb->Visual.depthBits < 32) {
- fb->_DepthMax = (1 << fb->Visual.depthBits) - 1;
- }
- else {
- /* Special case since shift values greater than or equal to the
- * number of bits in the left hand expression's type are undefined.
- */
- fb->_DepthMax = 0xffffffff;
- }
- fb->_DepthMaxF = (GLfloat) fb->_DepthMax;
-
- /* Minimum resolvable depth value, for polygon offset */
- fb->_MRD = (GLfloat)1.0 / fb->_DepthMaxF;
-}
-
-/**
- * Create and initialize a gl_framebuffer object.
- * This is intended for creating _window_system_ framebuffers, not generic
- * framebuffer objects ala GL_EXT_framebuffer_object.
- *
- * \sa _mesa_new_framebuffer
- */
-struct gl_framebuffer *
-_mesa_create_framebuffer(const struct gl_config *visual)
-{
- struct gl_framebuffer *fb = CALLOC_STRUCT(gl_framebuffer);
- assert(visual);
- if (fb) {
- _mesa_initialize_window_framebuffer(fb, visual);
- }
- return fb;
-}
-
-
-/**
- * Allocate a new gl_framebuffer object.
- * This is the default function for ctx->Driver.NewFramebuffer().
- * This is for allocating user-created framebuffers, not window-system
- * framebuffers!
- * \sa _mesa_create_framebuffer
- */
-struct gl_framebuffer *
-_mesa_new_framebuffer(struct gl_context *ctx, GLuint name)
-{
- struct gl_framebuffer *fb;
- (void) ctx;
- assert(name != 0);
- fb = CALLOC_STRUCT(gl_framebuffer);
- if (fb) {
- _mesa_initialize_user_framebuffer(fb, name);
- }
- return fb;
-}
-
-
-/**
- * Initialize a gl_framebuffer object. Typically used to initialize
- * window system-created framebuffers, not user-created framebuffers.
- * \sa _mesa_initialize_user_framebuffer
- */
-void
-_mesa_initialize_window_framebuffer(struct gl_framebuffer *fb,
- const struct gl_config *visual)
-{
- assert(fb);
- assert(visual);
-
- memset(fb, 0, sizeof(struct gl_framebuffer));
-
- _glthread_INIT_MUTEX(fb->Mutex);
-
- fb->RefCount = 1;
-
- /* save the visual */
- fb->Visual = *visual;
-
- /* Init read/draw renderbuffer state */
- if (visual->doubleBufferMode) {
- fb->_NumColorDrawBuffers = 1;
- fb->ColorDrawBuffer[0] = GL_BACK;
- fb->_ColorDrawBufferIndexes[0] = BUFFER_BACK_LEFT;
- fb->ColorReadBuffer = GL_BACK;
- fb->_ColorReadBufferIndex = BUFFER_BACK_LEFT;
- }
- else {
- fb->_NumColorDrawBuffers = 1;
- fb->ColorDrawBuffer[0] = GL_FRONT;
- fb->_ColorDrawBufferIndexes[0] = BUFFER_FRONT_LEFT;
- fb->ColorReadBuffer = GL_FRONT;
- fb->_ColorReadBufferIndex = BUFFER_FRONT_LEFT;
- }
-
- fb->Delete = _mesa_destroy_framebuffer;
- fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
-
- compute_depth_max(fb);
-}
-
-
-/**
- * Initialize a user-created gl_framebuffer object.
- * \sa _mesa_initialize_window_framebuffer
- */
-void
-_mesa_initialize_user_framebuffer(struct gl_framebuffer *fb, GLuint name)
-{
- assert(fb);
- assert(name);
-
- memset(fb, 0, sizeof(struct gl_framebuffer));
-
- fb->Name = name;
- fb->RefCount = 1;
- fb->_NumColorDrawBuffers = 1;
- fb->ColorDrawBuffer[0] = GL_COLOR_ATTACHMENT0_EXT;
- fb->_ColorDrawBufferIndexes[0] = BUFFER_COLOR0;
- fb->ColorReadBuffer = GL_COLOR_ATTACHMENT0_EXT;
- fb->_ColorReadBufferIndex = BUFFER_COLOR0;
- fb->Delete = _mesa_destroy_framebuffer;
- _glthread_INIT_MUTEX(fb->Mutex);
-}
-
-
-/**
- * Deallocate buffer and everything attached to it.
- * Typically called via the gl_framebuffer->Delete() method.
- */
-void
-_mesa_destroy_framebuffer(struct gl_framebuffer *fb)
-{
- if (fb) {
- _mesa_free_framebuffer_data(fb);
- free(fb);
- }
-}
-
-
-/**
- * Free all the data hanging off the given gl_framebuffer, but don't free
- * the gl_framebuffer object itself.
- */
-void
-_mesa_free_framebuffer_data(struct gl_framebuffer *fb)
-{
- GLuint i;
-
- assert(fb);
- assert(fb->RefCount == 0);
-
- _glthread_DESTROY_MUTEX(fb->Mutex);
-
- for (i = 0; i < BUFFER_COUNT; i++) {
- struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
- if (att->Renderbuffer) {
- _mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
- }
- if (att->Texture) {
- _mesa_reference_texobj(&att->Texture, NULL);
- }
- ASSERT(!att->Renderbuffer);
- ASSERT(!att->Texture);
- att->Type = GL_NONE;
- }
-
- /* unbind _Depth/_StencilBuffer to decr ref counts */
- _mesa_reference_renderbuffer(&fb->_DepthBuffer, NULL);
- _mesa_reference_renderbuffer(&fb->_StencilBuffer, NULL);
-}
-
-
-/**
- * Set *ptr to point to fb, with refcounting and locking.
- */
-void
-_mesa_reference_framebuffer(struct gl_framebuffer **ptr,
- struct gl_framebuffer *fb)
-{
- assert(ptr);
- if (*ptr == fb) {
- /* no change */
- return;
- }
-
- if (*ptr) {
- /* unreference old renderbuffer */
- GLboolean deleteFlag = GL_FALSE;
- struct gl_framebuffer *oldFb = *ptr;
-
- _glthread_LOCK_MUTEX(oldFb->Mutex);
- ASSERT(oldFb->RefCount > 0);
- oldFb->RefCount--;
- deleteFlag = (oldFb->RefCount == 0);
- _glthread_UNLOCK_MUTEX(oldFb->Mutex);
-
- if (deleteFlag)
- oldFb->Delete(oldFb);
-
- *ptr = NULL;
- }
- assert(!*ptr);
-
- if (fb) {
- _glthread_LOCK_MUTEX(fb->Mutex);
- fb->RefCount++;
- _glthread_UNLOCK_MUTEX(fb->Mutex);
- *ptr = fb;
- }
-}
-
-
-/**
- * Resize the given framebuffer's renderbuffers to the new width and height.
- * This should only be used for window-system framebuffers, not
- * user-created renderbuffers (i.e. made with GL_EXT_framebuffer_object).
- * This will typically be called via ctx->Driver.ResizeBuffers() or directly
- * from a device driver.
- *
- * \note it's possible for ctx to be null since a window can be resized
- * without a currently bound rendering context.
- */
-void
-_mesa_resize_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
- GLuint width, GLuint height)
-{
- GLuint i;
-
- /* XXX I think we could check if the size is not changing
- * and return early.
- */
-
- /* For window system framebuffers, Name is zero */
- assert(fb->Name == 0);
-
- for (i = 0; i < BUFFER_COUNT; i++) {
- struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
- if (att->Type == GL_RENDERBUFFER_EXT && att->Renderbuffer) {
- struct gl_renderbuffer *rb = att->Renderbuffer;
- /* only resize if size is changing */
- if (rb->Width != width || rb->Height != height) {
- if (rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height)) {
- ASSERT(rb->Width == width);
- ASSERT(rb->Height == height);
- }
- else {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "Resizing framebuffer");
- /* no return */
- }
- }
- }
- }
-
- if (fb->_DepthBuffer) {
- struct gl_renderbuffer *rb = fb->_DepthBuffer;
- if (rb->Width != width || rb->Height != height) {
- if (!rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height)) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "Resizing framebuffer");
- }
- }
- }
-
- if (fb->_StencilBuffer) {
- struct gl_renderbuffer *rb = fb->_StencilBuffer;
- if (rb->Width != width || rb->Height != height) {
- if (!rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height)) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "Resizing framebuffer");
- }
- }
- }
-
- fb->Width = width;
- fb->Height = height;
-
- if (ctx) {
- /* update scissor / window bounds */
- _mesa_update_draw_buffer_bounds(ctx);
- /* Signal new buffer state so that swrast will update its clipping
- * info (the CLIP_BIT flag).
- */
- ctx->NewState |= _NEW_BUFFERS;
- }
-}
-
-
-
-/**
- * XXX THIS IS OBSOLETE - drivers should take care of detecting window
- * size changes and act accordingly, likely calling _mesa_resize_framebuffer().
- *
- * GL_MESA_resize_buffers extension.
- *
- * When this function is called, we'll ask the window system how large
- * the current window is. If it's a new size, we'll call the driver's
- * ResizeBuffers function. The driver will then resize its color buffers
- * as needed, and maybe call the swrast's routine for reallocating
- * swrast-managed depth/stencil/accum/etc buffers.
- * \note This function should only be called through the GL API, not
- * from device drivers (as was done in the past).
- */
-void
-_mesa_resizebuffers( struct gl_context *ctx )
-{
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx );
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glResizeBuffersMESA\n");
-
- if (!ctx->Driver.GetBufferSize) {
- return;
- }
-
- if (ctx->WinSysDrawBuffer) {
- GLuint newWidth, newHeight;
- struct gl_framebuffer *buffer = ctx->WinSysDrawBuffer;
-
- assert(buffer->Name == 0);
-
- /* ask device driver for size of output buffer */
- ctx->Driver.GetBufferSize( buffer, &newWidth, &newHeight );
-
- /* see if size of device driver's color buffer (window) has changed */
- if (buffer->Width != newWidth || buffer->Height != newHeight) {
- if (ctx->Driver.ResizeBuffers)
- ctx->Driver.ResizeBuffers(ctx, buffer, newWidth, newHeight );
- }
- }
-
- if (ctx->WinSysReadBuffer
- && ctx->WinSysReadBuffer != ctx->WinSysDrawBuffer) {
- GLuint newWidth, newHeight;
- struct gl_framebuffer *buffer = ctx->WinSysReadBuffer;
-
- assert(buffer->Name == 0);
-
- /* ask device driver for size of read buffer */
- ctx->Driver.GetBufferSize( buffer, &newWidth, &newHeight );
-
- /* see if size of device driver's color buffer (window) has changed */
- if (buffer->Width != newWidth || buffer->Height != newHeight) {
- if (ctx->Driver.ResizeBuffers)
- ctx->Driver.ResizeBuffers(ctx, buffer, newWidth, newHeight );
- }
- }
-
- ctx->NewState |= _NEW_BUFFERS; /* to update scissor / window bounds */
-}
-
-
-/*
- * XXX THIS IS OBSOLETE
- */
-void GLAPIENTRY
-_mesa_ResizeBuffersMESA( void )
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if (ctx->Extensions.MESA_resize_buffers)
- _mesa_resizebuffers( ctx );
-}
-
-
-
-/**
- * Examine all the framebuffer's renderbuffers to update the Width/Height
- * fields of the framebuffer. If we have renderbuffers with different
- * sizes, set the framebuffer's width and height to the min size.
- * Note: this is only intended for user-created framebuffers, not
- * window-system framebuffes.
- */
-static void
-update_framebuffer_size(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
- GLuint minWidth = ~0, minHeight = ~0;
- GLuint i;
-
- /* user-created framebuffers only */
- assert(fb->Name);
-
- for (i = 0; i < BUFFER_COUNT; i++) {
- struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
- const struct gl_renderbuffer *rb = att->Renderbuffer;
- if (rb) {
- minWidth = MIN2(minWidth, rb->Width);
- minHeight = MIN2(minHeight, rb->Height);
- }
- }
-
- if (minWidth != ~0) {
- fb->Width = minWidth;
- fb->Height = minHeight;
- }
- else {
- fb->Width = 0;
- fb->Height = 0;
- }
-}
-
-
-/**
- * Update the context's current drawing buffer's Xmin, Xmax, Ymin, Ymax fields.
- * These values are computed from the buffer's width and height and
- * the scissor box, if it's enabled.
- * \param ctx the GL context.
- */
-void
-_mesa_update_draw_buffer_bounds(struct gl_context *ctx)
-{
- struct gl_framebuffer *buffer = ctx->DrawBuffer;
-
- if (!buffer)
- return;
-
- if (buffer->Name) {
- /* user-created framebuffer size depends on the renderbuffers */
- update_framebuffer_size(ctx, buffer);
- }
-
- buffer->_Xmin = 0;
- buffer->_Ymin = 0;
- buffer->_Xmax = buffer->Width;
- buffer->_Ymax = buffer->Height;
-
- if (ctx->Scissor.Enabled) {
- if (ctx->Scissor.X > buffer->_Xmin) {
- buffer->_Xmin = ctx->Scissor.X;
- }
- if (ctx->Scissor.Y > buffer->_Ymin) {
- buffer->_Ymin = ctx->Scissor.Y;
- }
- if (ctx->Scissor.X + ctx->Scissor.Width < buffer->_Xmax) {
- buffer->_Xmax = ctx->Scissor.X + ctx->Scissor.Width;
- }
- if (ctx->Scissor.Y + ctx->Scissor.Height < buffer->_Ymax) {
- buffer->_Ymax = ctx->Scissor.Y + ctx->Scissor.Height;
- }
- /* finally, check for empty region */
- if (buffer->_Xmin > buffer->_Xmax) {
- buffer->_Xmin = buffer->_Xmax;
- }
- if (buffer->_Ymin > buffer->_Ymax) {
- buffer->_Ymin = buffer->_Ymax;
- }
- }
-
- ASSERT(buffer->_Xmin <= buffer->_Xmax);
- ASSERT(buffer->_Ymin <= buffer->_Ymax);
-}
-
-
-/**
- * The glGet queries of the framebuffer red/green/blue size, stencil size,
- * etc. are satisfied by the fields of ctx->DrawBuffer->Visual. These can
- * change depending on the renderbuffer bindings. This function updates
- * the given framebuffer's Visual from the current renderbuffer bindings.
- *
- * This may apply to user-created framebuffers or window system framebuffers.
- *
- * Also note: ctx->DrawBuffer->Visual.depthBits might not equal
- * ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer.DepthBits.
- * The former one is used to convert floating point depth values into
- * integer Z values.
- */
-void
-_mesa_update_framebuffer_visual(struct gl_context *ctx,
- struct gl_framebuffer *fb)
-{
- GLuint i;
-
- memset(&fb->Visual, 0, sizeof(fb->Visual));
- fb->Visual.rgbMode = GL_TRUE; /* assume this */
-
-#if 0 /* this _might_ be needed */
- if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- /* leave visual fields zero'd */
- return;
- }
-#endif
-
- /* find first RGB renderbuffer */
- for (i = 0; i < BUFFER_COUNT; i++) {
- if (fb->Attachment[i].Renderbuffer) {
- const struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer;
- const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
- const gl_format fmt = rb->Format;
-
- if (_mesa_is_legal_color_format(ctx, baseFormat)) {
- fb->Visual.redBits = _mesa_get_format_bits(fmt, GL_RED_BITS);
- fb->Visual.greenBits = _mesa_get_format_bits(fmt, GL_GREEN_BITS);
- fb->Visual.blueBits = _mesa_get_format_bits(fmt, GL_BLUE_BITS);
- fb->Visual.alphaBits = _mesa_get_format_bits(fmt, GL_ALPHA_BITS);
- fb->Visual.rgbBits = fb->Visual.redBits
- + fb->Visual.greenBits + fb->Visual.blueBits;
- fb->Visual.floatMode = GL_FALSE;
- fb->Visual.samples = rb->NumSamples;
- if (_mesa_get_format_color_encoding(fmt) == GL_SRGB)
- fb->Visual.sRGBCapable = ctx->Const.sRGBCapable;
- break;
- }
- }
- }
-
- if (fb->Attachment[BUFFER_DEPTH].Renderbuffer) {
- const struct gl_renderbuffer *rb =
- fb->Attachment[BUFFER_DEPTH].Renderbuffer;
- const gl_format fmt = rb->Format;
- fb->Visual.haveDepthBuffer = GL_TRUE;
- fb->Visual.depthBits = _mesa_get_format_bits(fmt, GL_DEPTH_BITS);
- }
-
- if (fb->Attachment[BUFFER_STENCIL].Renderbuffer) {
- const struct gl_renderbuffer *rb =
- fb->Attachment[BUFFER_STENCIL].Renderbuffer;
- const gl_format fmt = rb->Format;
- fb->Visual.haveStencilBuffer = GL_TRUE;
- fb->Visual.stencilBits = _mesa_get_format_bits(fmt, GL_STENCIL_BITS);
- }
-
- if (fb->Attachment[BUFFER_ACCUM].Renderbuffer) {
- const struct gl_renderbuffer *rb =
- fb->Attachment[BUFFER_ACCUM].Renderbuffer;
- const gl_format fmt = rb->Format;
- fb->Visual.haveAccumBuffer = GL_TRUE;
- fb->Visual.accumRedBits = _mesa_get_format_bits(fmt, GL_RED_BITS);
- fb->Visual.accumGreenBits = _mesa_get_format_bits(fmt, GL_GREEN_BITS);
- fb->Visual.accumBlueBits = _mesa_get_format_bits(fmt, GL_BLUE_BITS);
- fb->Visual.accumAlphaBits = _mesa_get_format_bits(fmt, GL_ALPHA_BITS);
- }
-
- compute_depth_max(fb);
-}
-
-
-/**
- * Update the framebuffer's _DepthBuffer field using the renderbuffer
- * found at the given attachment index.
- *
- * If that attachment points to a combined GL_DEPTH_STENCIL renderbuffer,
- * create and install a depth wrapper/adaptor.
- *
- * \param fb the framebuffer whose _DepthBuffer field to update
- * \param attIndex indicates the renderbuffer to possibly wrap
- */
-void
-_mesa_update_depth_buffer(struct gl_context *ctx,
- struct gl_framebuffer *fb,
- GLuint attIndex)
-{
- struct gl_renderbuffer *depthRb;
-
- /* only one possiblity for now */
- ASSERT(attIndex == BUFFER_DEPTH);
-
- depthRb = fb->Attachment[attIndex].Renderbuffer;
-
- if (depthRb && _mesa_is_format_packed_depth_stencil(depthRb->Format)) {
- /* The attached depth buffer is a GL_DEPTH_STENCIL renderbuffer */
- if (!fb->_DepthBuffer
- || fb->_DepthBuffer->Wrapped != depthRb
- || _mesa_get_format_base_format(fb->_DepthBuffer->Format) != GL_DEPTH_COMPONENT) {
- /* need to update wrapper */
- struct gl_renderbuffer *wrapper
- = _mesa_new_z24_renderbuffer_wrapper(ctx, depthRb);
- _mesa_reference_renderbuffer(&fb->_DepthBuffer, wrapper);
- ASSERT(fb->_DepthBuffer->Wrapped == depthRb);
- }
- }
- else {
- /* depthRb may be null */
- _mesa_reference_renderbuffer(&fb->_DepthBuffer, depthRb);
- }
-}
-
-
-/**
- * Update the framebuffer's _StencilBuffer field using the renderbuffer
- * found at the given attachment index.
- *
- * If that attachment points to a combined GL_DEPTH_STENCIL renderbuffer,
- * create and install a stencil wrapper/adaptor.
- *
- * \param fb the framebuffer whose _StencilBuffer field to update
- * \param attIndex indicates the renderbuffer to possibly wrap
- */
-void
-_mesa_update_stencil_buffer(struct gl_context *ctx,
- struct gl_framebuffer *fb,
- GLuint attIndex)
-{
- struct gl_renderbuffer *stencilRb;
-
- ASSERT(attIndex == BUFFER_DEPTH ||
- attIndex == BUFFER_STENCIL);
-
- stencilRb = fb->Attachment[attIndex].Renderbuffer;
-
- if (stencilRb && _mesa_is_format_packed_depth_stencil(stencilRb->Format)) {
- /* The attached stencil buffer is a GL_DEPTH_STENCIL renderbuffer */
- if (!fb->_StencilBuffer
- || fb->_StencilBuffer->Wrapped != stencilRb
- || _mesa_get_format_base_format(fb->_StencilBuffer->Format) != GL_STENCIL_INDEX) {
- /* need to update wrapper */
- struct gl_renderbuffer *wrapper
- = _mesa_new_s8_renderbuffer_wrapper(ctx, stencilRb);
- _mesa_reference_renderbuffer(&fb->_StencilBuffer, wrapper);
- ASSERT(fb->_StencilBuffer->Wrapped == stencilRb);
- }
- }
- else {
- /* stencilRb may be null */
- _mesa_reference_renderbuffer(&fb->_StencilBuffer, stencilRb);
- }
-}
-
-
-/*
- * Example DrawBuffers scenarios:
- *
- * 1. glDrawBuffer(GL_FRONT_AND_BACK), fixed-func or shader writes to
- * "gl_FragColor" or program writes to the "result.color" register:
- *
- * fragment color output renderbuffer
- * --------------------- ---------------
- * color[0] Front, Back
- *
- *
- * 2. glDrawBuffers(3, [GL_FRONT, GL_AUX0, GL_AUX1]), shader writes to
- * gl_FragData[i] or program writes to result.color[i] registers:
- *
- * fragment color output renderbuffer
- * --------------------- ---------------
- * color[0] Front
- * color[1] Aux0
- * color[3] Aux1
- *
- *
- * 3. glDrawBuffers(3, [GL_FRONT, GL_AUX0, GL_AUX1]) and shader writes to
- * gl_FragColor, or fixed function:
- *
- * fragment color output renderbuffer
- * --------------------- ---------------
- * color[0] Front, Aux0, Aux1
- *
- *
- * In either case, the list of renderbuffers is stored in the
- * framebuffer->_ColorDrawBuffers[] array and
- * framebuffer->_NumColorDrawBuffers indicates the number of buffers.
- * The renderer (like swrast) has to look at the current fragment shader
- * to see if it writes to gl_FragColor vs. gl_FragData[i] to determine
- * how to map color outputs to renderbuffers.
- *
- * Note that these two calls are equivalent (for fixed function fragment
- * shading anyway):
- * a) glDrawBuffer(GL_FRONT_AND_BACK); (assuming non-stereo framebuffer)
- * b) glDrawBuffers(2, [GL_FRONT_LEFT, GL_BACK_LEFT]);
- */
-
-
-
-
-/**
- * Update the (derived) list of color drawing renderbuffer pointers.
- * Later, when we're rendering we'll loop from 0 to _NumColorDrawBuffers
- * writing colors.
- */
-static void
-update_color_draw_buffers(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
- GLuint output;
-
- /* set 0th buffer to NULL now in case _NumColorDrawBuffers is zero */
- fb->_ColorDrawBuffers[0] = NULL;
-
- for (output = 0; output < fb->_NumColorDrawBuffers; output++) {
- GLint buf = fb->_ColorDrawBufferIndexes[output];
- if (buf >= 0) {
- fb->_ColorDrawBuffers[output] = fb->Attachment[buf].Renderbuffer;
- }
- else {
- fb->_ColorDrawBuffers[output] = NULL;
- }
- }
-}
-
-
-/**
- * Update the (derived) color read renderbuffer pointer.
- * Unlike the DrawBuffer, we can only read from one (or zero) color buffers.
- */
-static void
-update_color_read_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
- (void) ctx;
- if (fb->_ColorReadBufferIndex == -1 ||
- fb->DeletePending ||
- fb->Width == 0 ||
- fb->Height == 0) {
- fb->_ColorReadBuffer = NULL; /* legal! */
- }
- else {
- ASSERT(fb->_ColorReadBufferIndex >= 0);
- ASSERT(fb->_ColorReadBufferIndex < BUFFER_COUNT);
- fb->_ColorReadBuffer
- = fb->Attachment[fb->_ColorReadBufferIndex].Renderbuffer;
- }
-}
-
-
-/**
- * Update a gl_framebuffer's derived state.
- *
- * Specifically, update these framebuffer fields:
- * _ColorDrawBuffers
- * _NumColorDrawBuffers
- * _ColorReadBuffer
- * _DepthBuffer
- * _StencilBuffer
- *
- * If the framebuffer is user-created, make sure it's complete.
- *
- * The following functions (at least) can effect framebuffer state:
- * glReadBuffer, glDrawBuffer, glDrawBuffersARB, glFramebufferRenderbufferEXT,
- * glRenderbufferStorageEXT.
- */
-static void
-update_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
- if (fb->Name == 0) {
- /* This is a window-system framebuffer */
- /* Need to update the FB's GL_DRAW_BUFFER state to match the
- * context state (GL_READ_BUFFER too).
- */
- if (fb->ColorDrawBuffer[0] != ctx->Color.DrawBuffer[0]) {
- _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers,
- ctx->Color.DrawBuffer, NULL);
- }
- }
- else {
- /* This is a user-created framebuffer.
- * Completeness only matters for user-created framebuffers.
- */
- if (fb->_Status == 0) {
- _mesa_test_framebuffer_completeness(ctx, fb);
- }
- }
-
- /* Strictly speaking, we don't need to update the draw-state
- * if this FB is bound as ctx->ReadBuffer (and conversely, the
- * read-state if this FB is bound as ctx->DrawBuffer), but no
- * harm.
- */
- update_color_draw_buffers(ctx, fb);
- update_color_read_buffer(ctx, fb);
- _mesa_update_depth_buffer(ctx, fb, BUFFER_DEPTH);
- _mesa_update_stencil_buffer(ctx, fb, BUFFER_STENCIL);
-
- compute_depth_max(fb);
-}
-
-
-/**
- * Update state related to the current draw/read framebuffers.
- */
-void
-_mesa_update_framebuffer(struct gl_context *ctx)
-{
- struct gl_framebuffer *drawFb;
- struct gl_framebuffer *readFb;
-
- assert(ctx);
- drawFb = ctx->DrawBuffer;
- readFb = ctx->ReadBuffer;
-
- update_framebuffer(ctx, drawFb);
- if (readFb != drawFb)
- update_framebuffer(ctx, readFb);
-}
-
-
-/**
- * Check if the renderbuffer for a read operation (glReadPixels, glCopyPixels,
- * glCopyTex[Sub]Image, etc) exists.
- * \param format a basic image format such as GL_RGB, GL_RGBA, GL_ALPHA,
- * GL_DEPTH_COMPONENT, etc. or GL_COLOR, GL_DEPTH, GL_STENCIL.
- * \return GL_TRUE if buffer exists, GL_FALSE otherwise
- */
-GLboolean
-_mesa_source_buffer_exists(struct gl_context *ctx, GLenum format)
-{
- const struct gl_renderbuffer_attachment *att = ctx->ReadBuffer->Attachment;
-
- /* If we don't know the framebuffer status, update it now */
- if (ctx->ReadBuffer->_Status == 0) {
- _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
- }
-
- if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- return GL_FALSE;
- }
-
- switch (format) {
- case GL_COLOR:
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
- case GL_LUMINANCE:
- case GL_LUMINANCE_ALPHA:
- case GL_INTENSITY:
- case GL_RG:
- case GL_RGB:
- case GL_BGR:
- case GL_RGBA:
- case GL_BGRA:
- case GL_ABGR_EXT:
- case GL_COLOR_INDEX:
- case GL_RED_INTEGER_EXT:
- case GL_GREEN_INTEGER_EXT:
- case GL_BLUE_INTEGER_EXT:
- case GL_ALPHA_INTEGER_EXT:
- case GL_RGB_INTEGER_EXT:
- case GL_RGBA_INTEGER_EXT:
- case GL_BGR_INTEGER_EXT:
- case GL_BGRA_INTEGER_EXT:
- case GL_LUMINANCE_INTEGER_EXT:
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- if (ctx->ReadBuffer->_ColorReadBuffer == NULL) {
- return GL_FALSE;
- }
- ASSERT(_mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_RED_BITS) > 0 ||
- _mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_ALPHA_BITS) > 0 ||
- _mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_INDEX_BITS) > 0);
- break;
- case GL_DEPTH:
- case GL_DEPTH_COMPONENT:
- if (!att[BUFFER_DEPTH].Renderbuffer) {
- return GL_FALSE;
- }
- /*ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);*/
- break;
- case GL_STENCIL:
- case GL_STENCIL_INDEX:
- if (!att[BUFFER_STENCIL].Renderbuffer) {
- return GL_FALSE;
- }
- /*ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);*/
- break;
- case GL_DEPTH_STENCIL_EXT:
- if (!att[BUFFER_DEPTH].Renderbuffer ||
- !att[BUFFER_STENCIL].Renderbuffer) {
- return GL_FALSE;
- }
- /*
- ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);
- ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);
- */
- break;
- default:
- _mesa_problem(ctx,
- "Unexpected format 0x%x in _mesa_source_buffer_exists",
- format);
- return GL_FALSE;
- }
-
- /* OK */
- return GL_TRUE;
-}
-
-
-/**
- * As above, but for drawing operations.
- * XXX could do some code merging w/ above function.
- */
-GLboolean
-_mesa_dest_buffer_exists(struct gl_context *ctx, GLenum format)
-{
- const struct gl_renderbuffer_attachment *att = ctx->DrawBuffer->Attachment;
-
- /* If we don't know the framebuffer status, update it now */
- if (ctx->DrawBuffer->_Status == 0) {
- _mesa_test_framebuffer_completeness(ctx, ctx->DrawBuffer);
- }
-
- if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- return GL_FALSE;
- }
-
- switch (format) {
- case GL_COLOR:
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
- case GL_LUMINANCE:
- case GL_LUMINANCE_ALPHA:
- case GL_INTENSITY:
- case GL_RGB:
- case GL_BGR:
- case GL_RGBA:
- case GL_BGRA:
- case GL_ABGR_EXT:
- case GL_COLOR_INDEX:
- case GL_RED_INTEGER_EXT:
- case GL_GREEN_INTEGER_EXT:
- case GL_BLUE_INTEGER_EXT:
- case GL_ALPHA_INTEGER_EXT:
- case GL_RGB_INTEGER_EXT:
- case GL_RGBA_INTEGER_EXT:
- case GL_BGR_INTEGER_EXT:
- case GL_BGRA_INTEGER_EXT:
- case GL_LUMINANCE_INTEGER_EXT:
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- /* Nothing special since GL_DRAW_BUFFER could be GL_NONE. */
- /* Could assert that colorbuffer has RedBits > 0 */
- break;
- case GL_DEPTH:
- case GL_DEPTH_COMPONENT:
- if (!att[BUFFER_DEPTH].Renderbuffer) {
- return GL_FALSE;
- }
- /*ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);*/
- break;
- case GL_STENCIL:
- case GL_STENCIL_INDEX:
- if (!att[BUFFER_STENCIL].Renderbuffer) {
- return GL_FALSE;
- }
- /*ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);*/
- break;
- case GL_DEPTH_STENCIL_EXT:
- if (!att[BUFFER_DEPTH].Renderbuffer ||
- !att[BUFFER_STENCIL].Renderbuffer) {
- return GL_FALSE;
- }
- /*
- ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);
- ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);
- */
- break;
- default:
- _mesa_problem(ctx,
- "Unexpected format 0x%x in _mesa_dest_buffer_exists",
- format);
- return GL_FALSE;
- }
-
- /* OK */
- return GL_TRUE;
-}
-
-
-/**
- * Used to answer the GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES query.
- */
-GLenum
-_mesa_get_color_read_format(struct gl_context *ctx)
-{
- switch (ctx->ReadBuffer->_ColorReadBuffer->Format) {
- case MESA_FORMAT_ARGB8888:
- return GL_BGRA;
- case MESA_FORMAT_RGB565:
- return GL_BGR;
- default:
- return GL_RGBA;
- }
-}
-
-
-/**
- * Used to answer the GL_IMPLEMENTATION_COLOR_READ_TYPE_OES query.
- */
-GLenum
-_mesa_get_color_read_type(struct gl_context *ctx)
-{
- switch (ctx->ReadBuffer->_ColorReadBuffer->Format) {
- case MESA_FORMAT_ARGB8888:
- return GL_UNSIGNED_BYTE;
- case MESA_FORMAT_RGB565:
- return GL_UNSIGNED_SHORT_5_6_5_REV;
- default:
- return GL_UNSIGNED_BYTE;
- }
-}
-
-
-/**
- * Print framebuffer info to stderr, for debugging.
- */
-void
-_mesa_print_framebuffer(const struct gl_framebuffer *fb)
-{
- GLuint i;
-
- fprintf(stderr, "Mesa Framebuffer %u at %p\n", fb->Name, (void *) fb);
- fprintf(stderr, " Size: %u x %u Status: %s\n", fb->Width, fb->Height,
- _mesa_lookup_enum_by_nr(fb->_Status));
- fprintf(stderr, " Attachments:\n");
-
- for (i = 0; i < BUFFER_COUNT; i++) {
- const struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
- if (att->Type == GL_TEXTURE) {
- const struct gl_texture_image *texImage;
- fprintf(stderr,
- " %2d: Texture %u, level %u, face %u, slice %u, complete %d\n",
- i, att->Texture->Name, att->TextureLevel, att->CubeMapFace,
- att->Zoffset, att->Complete);
- texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
- fprintf(stderr, " Size: %u x %u x %u Format %s\n",
- texImage->Width, texImage->Height, texImage->Depth,
- _mesa_get_format_name(texImage->TexFormat));
- }
- else if (att->Type == GL_RENDERBUFFER) {
- fprintf(stderr, " %2d: Renderbuffer %u, complete %d\n",
- i, att->Renderbuffer->Name, att->Complete);
- fprintf(stderr, " Size: %u x %u Format %s\n",
- att->Renderbuffer->Width, att->Renderbuffer->Height,
- _mesa_get_format_name(att->Renderbuffer->Format));
- }
- else {
- fprintf(stderr, " %2d: none\n", i);
- }
- }
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.2
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * Functions for allocating/managing framebuffers and renderbuffers.
+ * Also, routines for reading/writing renderbuffer data as ubytes,
+ * ushorts, uints, etc.
+ */
+
+
+#include "glheader.h"
+#include "imports.h"
+#include "buffers.h"
+#include "context.h"
+#include "depthstencil.h"
+#include "enums.h"
+#include "formats.h"
+#include "macros.h"
+#include "mtypes.h"
+#include "fbobject.h"
+#include "framebuffer.h"
+#include "renderbuffer.h"
+#include "texobj.h"
+
+
+
+/**
+ * Compute/set the _DepthMax field for the given framebuffer.
+ * This value depends on the Z buffer resolution.
+ */
+static void
+compute_depth_max(struct gl_framebuffer *fb)
+{
+ if (fb->Visual.depthBits == 0) {
+ /* Special case. Even if we don't have a depth buffer we need
+ * good values for DepthMax for Z vertex transformation purposes
+ * and for per-fragment fog computation.
+ */
+ fb->_DepthMax = (1 << 16) - 1;
+ }
+ else if (fb->Visual.depthBits < 32) {
+ fb->_DepthMax = (1 << fb->Visual.depthBits) - 1;
+ }
+ else {
+ /* Special case since shift values greater than or equal to the
+ * number of bits in the left hand expression's type are undefined.
+ */
+ fb->_DepthMax = 0xffffffff;
+ }
+ fb->_DepthMaxF = (GLfloat) fb->_DepthMax;
+
+ /* Minimum resolvable depth value, for polygon offset */
+ fb->_MRD = (GLfloat)1.0 / fb->_DepthMaxF;
+}
+
+/**
+ * Create and initialize a gl_framebuffer object.
+ * This is intended for creating _window_system_ framebuffers, not generic
+ * framebuffer objects ala GL_EXT_framebuffer_object.
+ *
+ * \sa _mesa_new_framebuffer
+ */
+struct gl_framebuffer *
+_mesa_create_framebuffer(const struct gl_config *visual)
+{
+ struct gl_framebuffer *fb = CALLOC_STRUCT(gl_framebuffer);
+ assert(visual);
+ if (fb) {
+ _mesa_initialize_window_framebuffer(fb, visual);
+ }
+ return fb;
+}
+
+
+/**
+ * Allocate a new gl_framebuffer object.
+ * This is the default function for ctx->Driver.NewFramebuffer().
+ * This is for allocating user-created framebuffers, not window-system
+ * framebuffers!
+ * \sa _mesa_create_framebuffer
+ */
+struct gl_framebuffer *
+_mesa_new_framebuffer(struct gl_context *ctx, GLuint name)
+{
+ struct gl_framebuffer *fb;
+ (void) ctx;
+ assert(name != 0);
+ fb = CALLOC_STRUCT(gl_framebuffer);
+ if (fb) {
+ _mesa_initialize_user_framebuffer(fb, name);
+ }
+ return fb;
+}
+
+
+/**
+ * Initialize a gl_framebuffer object. Typically used to initialize
+ * window system-created framebuffers, not user-created framebuffers.
+ * \sa _mesa_initialize_user_framebuffer
+ */
+void
+_mesa_initialize_window_framebuffer(struct gl_framebuffer *fb,
+ const struct gl_config *visual)
+{
+ assert(fb);
+ assert(visual);
+
+ memset(fb, 0, sizeof(struct gl_framebuffer));
+
+ _glthread_INIT_MUTEX(fb->Mutex);
+
+ fb->RefCount = 1;
+
+ /* save the visual */
+ fb->Visual = *visual;
+
+ /* Init read/draw renderbuffer state */
+ if (visual->doubleBufferMode) {
+ fb->_NumColorDrawBuffers = 1;
+ fb->ColorDrawBuffer[0] = GL_BACK;
+ fb->_ColorDrawBufferIndexes[0] = BUFFER_BACK_LEFT;
+ fb->ColorReadBuffer = GL_BACK;
+ fb->_ColorReadBufferIndex = BUFFER_BACK_LEFT;
+ }
+ else {
+ fb->_NumColorDrawBuffers = 1;
+ fb->ColorDrawBuffer[0] = GL_FRONT;
+ fb->_ColorDrawBufferIndexes[0] = BUFFER_FRONT_LEFT;
+ fb->ColorReadBuffer = GL_FRONT;
+ fb->_ColorReadBufferIndex = BUFFER_FRONT_LEFT;
+ }
+
+ fb->Delete = _mesa_destroy_framebuffer;
+ fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
+
+ compute_depth_max(fb);
+}
+
+
+/**
+ * Initialize a user-created gl_framebuffer object.
+ * \sa _mesa_initialize_window_framebuffer
+ */
+void
+_mesa_initialize_user_framebuffer(struct gl_framebuffer *fb, GLuint name)
+{
+ assert(fb);
+ assert(name);
+
+ memset(fb, 0, sizeof(struct gl_framebuffer));
+
+ fb->Name = name;
+ fb->RefCount = 1;
+ fb->_NumColorDrawBuffers = 1;
+ fb->ColorDrawBuffer[0] = GL_COLOR_ATTACHMENT0_EXT;
+ fb->_ColorDrawBufferIndexes[0] = BUFFER_COLOR0;
+ fb->ColorReadBuffer = GL_COLOR_ATTACHMENT0_EXT;
+ fb->_ColorReadBufferIndex = BUFFER_COLOR0;
+ fb->Delete = _mesa_destroy_framebuffer;
+ _glthread_INIT_MUTEX(fb->Mutex);
+}
+
+
+/**
+ * Deallocate buffer and everything attached to it.
+ * Typically called via the gl_framebuffer->Delete() method.
+ */
+void
+_mesa_destroy_framebuffer(struct gl_framebuffer *fb)
+{
+ if (fb) {
+ _mesa_free_framebuffer_data(fb);
+ free(fb);
+ }
+}
+
+
+/**
+ * Free all the data hanging off the given gl_framebuffer, but don't free
+ * the gl_framebuffer object itself.
+ */
+void
+_mesa_free_framebuffer_data(struct gl_framebuffer *fb)
+{
+ GLuint i;
+
+ assert(fb);
+ assert(fb->RefCount == 0);
+
+ _glthread_DESTROY_MUTEX(fb->Mutex);
+
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
+ if (att->Renderbuffer) {
+ _mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
+ }
+ if (att->Texture) {
+ _mesa_reference_texobj(&att->Texture, NULL);
+ }
+ ASSERT(!att->Renderbuffer);
+ ASSERT(!att->Texture);
+ att->Type = GL_NONE;
+ }
+
+ /* unbind _Depth/_StencilBuffer to decr ref counts */
+ _mesa_reference_renderbuffer(&fb->_DepthBuffer, NULL);
+ _mesa_reference_renderbuffer(&fb->_StencilBuffer, NULL);
+}
+
+
+/**
+ * Set *ptr to point to fb, with refcounting and locking.
+ */
+void
+_mesa_reference_framebuffer(struct gl_framebuffer **ptr,
+ struct gl_framebuffer *fb)
+{
+ assert(ptr);
+ if (*ptr == fb) {
+ /* no change */
+ return;
+ }
+
+ if (*ptr) {
+ /* unreference old renderbuffer */
+ GLboolean deleteFlag = GL_FALSE;
+ struct gl_framebuffer *oldFb = *ptr;
+
+ _glthread_LOCK_MUTEX(oldFb->Mutex);
+ ASSERT(oldFb->RefCount > 0);
+ oldFb->RefCount--;
+ deleteFlag = (oldFb->RefCount == 0);
+ _glthread_UNLOCK_MUTEX(oldFb->Mutex);
+
+ if (deleteFlag)
+ oldFb->Delete(oldFb);
+
+ *ptr = NULL;
+ }
+ assert(!*ptr);
+
+ if (fb) {
+ _glthread_LOCK_MUTEX(fb->Mutex);
+ fb->RefCount++;
+ _glthread_UNLOCK_MUTEX(fb->Mutex);
+ *ptr = fb;
+ }
+}
+
+
+/**
+ * Resize the given framebuffer's renderbuffers to the new width and height.
+ * This should only be used for window-system framebuffers, not
+ * user-created renderbuffers (i.e. made with GL_EXT_framebuffer_object).
+ * This will typically be called via ctx->Driver.ResizeBuffers() or directly
+ * from a device driver.
+ *
+ * \note it's possible for ctx to be null since a window can be resized
+ * without a currently bound rendering context.
+ */
+void
+_mesa_resize_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
+ GLuint width, GLuint height)
+{
+ GLuint i;
+
+ /* XXX I think we could check if the size is not changing
+ * and return early.
+ */
+
+ /* For window system framebuffers, Name is zero */
+ assert(fb->Name == 0);
+
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
+ if (att->Type == GL_RENDERBUFFER_EXT && att->Renderbuffer) {
+ struct gl_renderbuffer *rb = att->Renderbuffer;
+ /* only resize if size is changing */
+ if (rb->Width != width || rb->Height != height) {
+ if (rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height)) {
+ ASSERT(rb->Width == width);
+ ASSERT(rb->Height == height);
+ }
+ else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "Resizing framebuffer");
+ /* no return */
+ }
+ }
+ }
+ }
+
+ if (fb->_DepthBuffer) {
+ struct gl_renderbuffer *rb = fb->_DepthBuffer;
+ if (rb->Width != width || rb->Height != height) {
+ if (!rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height)) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "Resizing framebuffer");
+ }
+ }
+ }
+
+ if (fb->_StencilBuffer) {
+ struct gl_renderbuffer *rb = fb->_StencilBuffer;
+ if (rb->Width != width || rb->Height != height) {
+ if (!rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height)) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "Resizing framebuffer");
+ }
+ }
+ }
+
+ fb->Width = width;
+ fb->Height = height;
+
+ if (ctx) {
+ /* update scissor / window bounds */
+ _mesa_update_draw_buffer_bounds(ctx);
+ /* Signal new buffer state so that swrast will update its clipping
+ * info (the CLIP_BIT flag).
+ */
+ ctx->NewState |= _NEW_BUFFERS;
+ }
+}
+
+
+
+/**
+ * XXX THIS IS OBSOLETE - drivers should take care of detecting window
+ * size changes and act accordingly, likely calling _mesa_resize_framebuffer().
+ *
+ * GL_MESA_resize_buffers extension.
+ *
+ * When this function is called, we'll ask the window system how large
+ * the current window is. If it's a new size, we'll call the driver's
+ * ResizeBuffers function. The driver will then resize its color buffers
+ * as needed, and maybe call the swrast's routine for reallocating
+ * swrast-managed depth/stencil/accum/etc buffers.
+ * \note This function should only be called through the GL API, not
+ * from device drivers (as was done in the past).
+ */
+void
+_mesa_resizebuffers( struct gl_context *ctx )
+{
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx );
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glResizeBuffersMESA\n");
+
+ if (!ctx->Driver.GetBufferSize) {
+ return;
+ }
+
+ if (ctx->WinSysDrawBuffer) {
+ GLuint newWidth, newHeight;
+ struct gl_framebuffer *buffer = ctx->WinSysDrawBuffer;
+
+ assert(buffer->Name == 0);
+
+ /* ask device driver for size of output buffer */
+ ctx->Driver.GetBufferSize( buffer, &newWidth, &newHeight );
+
+ /* see if size of device driver's color buffer (window) has changed */
+ if (buffer->Width != newWidth || buffer->Height != newHeight) {
+ if (ctx->Driver.ResizeBuffers)
+ ctx->Driver.ResizeBuffers(ctx, buffer, newWidth, newHeight );
+ }
+ }
+
+ if (ctx->WinSysReadBuffer
+ && ctx->WinSysReadBuffer != ctx->WinSysDrawBuffer) {
+ GLuint newWidth, newHeight;
+ struct gl_framebuffer *buffer = ctx->WinSysReadBuffer;
+
+ assert(buffer->Name == 0);
+
+ /* ask device driver for size of read buffer */
+ ctx->Driver.GetBufferSize( buffer, &newWidth, &newHeight );
+
+ /* see if size of device driver's color buffer (window) has changed */
+ if (buffer->Width != newWidth || buffer->Height != newHeight) {
+ if (ctx->Driver.ResizeBuffers)
+ ctx->Driver.ResizeBuffers(ctx, buffer, newWidth, newHeight );
+ }
+ }
+
+ ctx->NewState |= _NEW_BUFFERS; /* to update scissor / window bounds */
+}
+
+
+/*
+ * XXX THIS IS OBSOLETE
+ */
+void GLAPIENTRY
+_mesa_ResizeBuffersMESA( void )
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (ctx->Extensions.MESA_resize_buffers)
+ _mesa_resizebuffers( ctx );
+}
+
+
+
+/**
+ * Examine all the framebuffer's renderbuffers to update the Width/Height
+ * fields of the framebuffer. If we have renderbuffers with different
+ * sizes, set the framebuffer's width and height to the min size.
+ * Note: this is only intended for user-created framebuffers, not
+ * window-system framebuffes.
+ */
+static void
+update_framebuffer_size(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+ GLuint minWidth = ~0, minHeight = ~0;
+ GLuint i;
+
+ /* user-created framebuffers only */
+ assert(fb->Name);
+
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
+ const struct gl_renderbuffer *rb = att->Renderbuffer;
+ if (rb) {
+ minWidth = MIN2(minWidth, rb->Width);
+ minHeight = MIN2(minHeight, rb->Height);
+ }
+ }
+
+ if (minWidth != ~0) {
+ fb->Width = minWidth;
+ fb->Height = minHeight;
+ }
+ else {
+ fb->Width = 0;
+ fb->Height = 0;
+ }
+}
+
+
+/**
+ * Update the context's current drawing buffer's Xmin, Xmax, Ymin, Ymax fields.
+ * These values are computed from the buffer's width and height and
+ * the scissor box, if it's enabled.
+ * \param ctx the GL context.
+ */
+void
+_mesa_update_draw_buffer_bounds(struct gl_context *ctx)
+{
+ struct gl_framebuffer *buffer = ctx->DrawBuffer;
+
+ if (!buffer)
+ return;
+
+ if (buffer->Name) {
+ /* user-created framebuffer size depends on the renderbuffers */
+ update_framebuffer_size(ctx, buffer);
+ }
+
+ buffer->_Xmin = 0;
+ buffer->_Ymin = 0;
+ buffer->_Xmax = buffer->Width;
+ buffer->_Ymax = buffer->Height;
+
+ if (ctx->Scissor.Enabled) {
+ if (ctx->Scissor.X > buffer->_Xmin) {
+ buffer->_Xmin = ctx->Scissor.X;
+ }
+ if (ctx->Scissor.Y > buffer->_Ymin) {
+ buffer->_Ymin = ctx->Scissor.Y;
+ }
+ if (ctx->Scissor.X + ctx->Scissor.Width < buffer->_Xmax) {
+ buffer->_Xmax = ctx->Scissor.X + ctx->Scissor.Width;
+ }
+ if (ctx->Scissor.Y + ctx->Scissor.Height < buffer->_Ymax) {
+ buffer->_Ymax = ctx->Scissor.Y + ctx->Scissor.Height;
+ }
+ /* finally, check for empty region */
+ if (buffer->_Xmin > buffer->_Xmax) {
+ buffer->_Xmin = buffer->_Xmax;
+ }
+ if (buffer->_Ymin > buffer->_Ymax) {
+ buffer->_Ymin = buffer->_Ymax;
+ }
+ }
+
+ ASSERT(buffer->_Xmin <= buffer->_Xmax);
+ ASSERT(buffer->_Ymin <= buffer->_Ymax);
+}
+
+
+/**
+ * The glGet queries of the framebuffer red/green/blue size, stencil size,
+ * etc. are satisfied by the fields of ctx->DrawBuffer->Visual. These can
+ * change depending on the renderbuffer bindings. This function updates
+ * the given framebuffer's Visual from the current renderbuffer bindings.
+ *
+ * This may apply to user-created framebuffers or window system framebuffers.
+ *
+ * Also note: ctx->DrawBuffer->Visual.depthBits might not equal
+ * ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer.DepthBits.
+ * The former one is used to convert floating point depth values into
+ * integer Z values.
+ */
+void
+_mesa_update_framebuffer_visual(struct gl_context *ctx,
+ struct gl_framebuffer *fb)
+{
+ GLuint i;
+
+ memset(&fb->Visual, 0, sizeof(fb->Visual));
+ fb->Visual.rgbMode = GL_TRUE; /* assume this */
+
+#if 0 /* this _might_ be needed */
+ if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ /* leave visual fields zero'd */
+ return;
+ }
+#endif
+
+ /* find first RGB renderbuffer */
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ if (fb->Attachment[i].Renderbuffer) {
+ const struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer;
+ const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
+ const gl_format fmt = rb->Format;
+
+ if (_mesa_is_legal_color_format(ctx, baseFormat)) {
+ fb->Visual.redBits = _mesa_get_format_bits(fmt, GL_RED_BITS);
+ fb->Visual.greenBits = _mesa_get_format_bits(fmt, GL_GREEN_BITS);
+ fb->Visual.blueBits = _mesa_get_format_bits(fmt, GL_BLUE_BITS);
+ fb->Visual.alphaBits = _mesa_get_format_bits(fmt, GL_ALPHA_BITS);
+ fb->Visual.rgbBits = fb->Visual.redBits
+ + fb->Visual.greenBits + fb->Visual.blueBits;
+ fb->Visual.floatMode = GL_FALSE;
+ fb->Visual.samples = rb->NumSamples;
+ if (_mesa_get_format_color_encoding(fmt) == GL_SRGB)
+ fb->Visual.sRGBCapable = ctx->Const.sRGBCapable;
+ break;
+ }
+ }
+ }
+
+ if (fb->Attachment[BUFFER_DEPTH].Renderbuffer) {
+ const struct gl_renderbuffer *rb =
+ fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+ const gl_format fmt = rb->Format;
+ fb->Visual.haveDepthBuffer = GL_TRUE;
+ fb->Visual.depthBits = _mesa_get_format_bits(fmt, GL_DEPTH_BITS);
+ }
+
+ if (fb->Attachment[BUFFER_STENCIL].Renderbuffer) {
+ const struct gl_renderbuffer *rb =
+ fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+ const gl_format fmt = rb->Format;
+ fb->Visual.haveStencilBuffer = GL_TRUE;
+ fb->Visual.stencilBits = _mesa_get_format_bits(fmt, GL_STENCIL_BITS);
+ }
+
+ if (fb->Attachment[BUFFER_ACCUM].Renderbuffer) {
+ const struct gl_renderbuffer *rb =
+ fb->Attachment[BUFFER_ACCUM].Renderbuffer;
+ const gl_format fmt = rb->Format;
+ fb->Visual.haveAccumBuffer = GL_TRUE;
+ fb->Visual.accumRedBits = _mesa_get_format_bits(fmt, GL_RED_BITS);
+ fb->Visual.accumGreenBits = _mesa_get_format_bits(fmt, GL_GREEN_BITS);
+ fb->Visual.accumBlueBits = _mesa_get_format_bits(fmt, GL_BLUE_BITS);
+ fb->Visual.accumAlphaBits = _mesa_get_format_bits(fmt, GL_ALPHA_BITS);
+ }
+
+ compute_depth_max(fb);
+}
+
+
+/**
+ * Update the framebuffer's _DepthBuffer field using the renderbuffer
+ * found at the given attachment index.
+ *
+ * If that attachment points to a combined GL_DEPTH_STENCIL renderbuffer,
+ * create and install a depth wrapper/adaptor.
+ *
+ * \param fb the framebuffer whose _DepthBuffer field to update
+ * \param attIndex indicates the renderbuffer to possibly wrap
+ */
+void
+_mesa_update_depth_buffer(struct gl_context *ctx,
+ struct gl_framebuffer *fb,
+ GLuint attIndex)
+{
+ struct gl_renderbuffer *depthRb;
+
+ /* only one possiblity for now */
+ ASSERT(attIndex == BUFFER_DEPTH);
+
+ depthRb = fb->Attachment[attIndex].Renderbuffer;
+
+ if (depthRb && _mesa_is_format_packed_depth_stencil(depthRb->Format)) {
+ /* The attached depth buffer is a GL_DEPTH_STENCIL renderbuffer */
+ if (!fb->_DepthBuffer
+ || fb->_DepthBuffer->Wrapped != depthRb
+ || _mesa_get_format_base_format(fb->_DepthBuffer->Format) != GL_DEPTH_COMPONENT) {
+ /* need to update wrapper */
+ struct gl_renderbuffer *wrapper
+ = _mesa_new_z24_renderbuffer_wrapper(ctx, depthRb);
+ _mesa_reference_renderbuffer(&fb->_DepthBuffer, wrapper);
+ ASSERT(fb->_DepthBuffer->Wrapped == depthRb);
+ }
+ }
+ else {
+ /* depthRb may be null */
+ _mesa_reference_renderbuffer(&fb->_DepthBuffer, depthRb);
+ }
+}
+
+
+/**
+ * Update the framebuffer's _StencilBuffer field using the renderbuffer
+ * found at the given attachment index.
+ *
+ * If that attachment points to a combined GL_DEPTH_STENCIL renderbuffer,
+ * create and install a stencil wrapper/adaptor.
+ *
+ * \param fb the framebuffer whose _StencilBuffer field to update
+ * \param attIndex indicates the renderbuffer to possibly wrap
+ */
+void
+_mesa_update_stencil_buffer(struct gl_context *ctx,
+ struct gl_framebuffer *fb,
+ GLuint attIndex)
+{
+ struct gl_renderbuffer *stencilRb;
+
+ ASSERT(attIndex == BUFFER_DEPTH ||
+ attIndex == BUFFER_STENCIL);
+
+ stencilRb = fb->Attachment[attIndex].Renderbuffer;
+
+ if (stencilRb && _mesa_is_format_packed_depth_stencil(stencilRb->Format)) {
+ /* The attached stencil buffer is a GL_DEPTH_STENCIL renderbuffer */
+ if (!fb->_StencilBuffer
+ || fb->_StencilBuffer->Wrapped != stencilRb
+ || _mesa_get_format_base_format(fb->_StencilBuffer->Format) != GL_STENCIL_INDEX) {
+ /* need to update wrapper */
+ struct gl_renderbuffer *wrapper
+ = _mesa_new_s8_renderbuffer_wrapper(ctx, stencilRb);
+ _mesa_reference_renderbuffer(&fb->_StencilBuffer, wrapper);
+ ASSERT(fb->_StencilBuffer->Wrapped == stencilRb);
+ }
+ }
+ else {
+ /* stencilRb may be null */
+ _mesa_reference_renderbuffer(&fb->_StencilBuffer, stencilRb);
+ }
+}
+
+
+/*
+ * Example DrawBuffers scenarios:
+ *
+ * 1. glDrawBuffer(GL_FRONT_AND_BACK), fixed-func or shader writes to
+ * "gl_FragColor" or program writes to the "result.color" register:
+ *
+ * fragment color output renderbuffer
+ * --------------------- ---------------
+ * color[0] Front, Back
+ *
+ *
+ * 2. glDrawBuffers(3, [GL_FRONT, GL_AUX0, GL_AUX1]), shader writes to
+ * gl_FragData[i] or program writes to result.color[i] registers:
+ *
+ * fragment color output renderbuffer
+ * --------------------- ---------------
+ * color[0] Front
+ * color[1] Aux0
+ * color[3] Aux1
+ *
+ *
+ * 3. glDrawBuffers(3, [GL_FRONT, GL_AUX0, GL_AUX1]) and shader writes to
+ * gl_FragColor, or fixed function:
+ *
+ * fragment color output renderbuffer
+ * --------------------- ---------------
+ * color[0] Front, Aux0, Aux1
+ *
+ *
+ * In either case, the list of renderbuffers is stored in the
+ * framebuffer->_ColorDrawBuffers[] array and
+ * framebuffer->_NumColorDrawBuffers indicates the number of buffers.
+ * The renderer (like swrast) has to look at the current fragment shader
+ * to see if it writes to gl_FragColor vs. gl_FragData[i] to determine
+ * how to map color outputs to renderbuffers.
+ *
+ * Note that these two calls are equivalent (for fixed function fragment
+ * shading anyway):
+ * a) glDrawBuffer(GL_FRONT_AND_BACK); (assuming non-stereo framebuffer)
+ * b) glDrawBuffers(2, [GL_FRONT_LEFT, GL_BACK_LEFT]);
+ */
+
+
+
+
+/**
+ * Update the (derived) list of color drawing renderbuffer pointers.
+ * Later, when we're rendering we'll loop from 0 to _NumColorDrawBuffers
+ * writing colors.
+ */
+static void
+update_color_draw_buffers(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+ GLuint output;
+
+ /* set 0th buffer to NULL now in case _NumColorDrawBuffers is zero */
+ fb->_ColorDrawBuffers[0] = NULL;
+
+ for (output = 0; output < fb->_NumColorDrawBuffers; output++) {
+ GLint buf = fb->_ColorDrawBufferIndexes[output];
+ if (buf >= 0) {
+ fb->_ColorDrawBuffers[output] = fb->Attachment[buf].Renderbuffer;
+ }
+ else {
+ fb->_ColorDrawBuffers[output] = NULL;
+ }
+ }
+}
+
+
+/**
+ * Update the (derived) color read renderbuffer pointer.
+ * Unlike the DrawBuffer, we can only read from one (or zero) color buffers.
+ */
+static void
+update_color_read_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+ (void) ctx;
+ if (fb->_ColorReadBufferIndex == -1 ||
+ fb->DeletePending ||
+ fb->Width == 0 ||
+ fb->Height == 0) {
+ fb->_ColorReadBuffer = NULL; /* legal! */
+ }
+ else {
+ ASSERT(fb->_ColorReadBufferIndex >= 0);
+ ASSERT(fb->_ColorReadBufferIndex < BUFFER_COUNT);
+ fb->_ColorReadBuffer
+ = fb->Attachment[fb->_ColorReadBufferIndex].Renderbuffer;
+ }
+}
+
+
+/**
+ * Update a gl_framebuffer's derived state.
+ *
+ * Specifically, update these framebuffer fields:
+ * _ColorDrawBuffers
+ * _NumColorDrawBuffers
+ * _ColorReadBuffer
+ * _DepthBuffer
+ * _StencilBuffer
+ *
+ * If the framebuffer is user-created, make sure it's complete.
+ *
+ * The following functions (at least) can effect framebuffer state:
+ * glReadBuffer, glDrawBuffer, glDrawBuffersARB, glFramebufferRenderbufferEXT,
+ * glRenderbufferStorageEXT.
+ */
+static void
+update_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+ if (fb->Name == 0) {
+ /* This is a window-system framebuffer */
+ /* Need to update the FB's GL_DRAW_BUFFER state to match the
+ * context state (GL_READ_BUFFER too).
+ */
+ if (fb->ColorDrawBuffer[0] != ctx->Color.DrawBuffer[0]) {
+ _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers,
+ ctx->Color.DrawBuffer, NULL);
+ }
+ }
+ else {
+ /* This is a user-created framebuffer.
+ * Completeness only matters for user-created framebuffers.
+ */
+ if (fb->_Status == 0) {
+ _mesa_test_framebuffer_completeness(ctx, fb);
+ }
+ }
+
+ /* Strictly speaking, we don't need to update the draw-state
+ * if this FB is bound as ctx->ReadBuffer (and conversely, the
+ * read-state if this FB is bound as ctx->DrawBuffer), but no
+ * harm.
+ */
+ update_color_draw_buffers(ctx, fb);
+ update_color_read_buffer(ctx, fb);
+ _mesa_update_depth_buffer(ctx, fb, BUFFER_DEPTH);
+ _mesa_update_stencil_buffer(ctx, fb, BUFFER_STENCIL);
+
+ compute_depth_max(fb);
+}
+
+
+/**
+ * Update state related to the current draw/read framebuffers.
+ */
+void
+_mesa_update_framebuffer(struct gl_context *ctx)
+{
+ struct gl_framebuffer *drawFb;
+ struct gl_framebuffer *readFb;
+
+ assert(ctx);
+ drawFb = ctx->DrawBuffer;
+ readFb = ctx->ReadBuffer;
+
+ update_framebuffer(ctx, drawFb);
+ if (readFb != drawFb)
+ update_framebuffer(ctx, readFb);
+}
+
+
+/**
+ * Check if the renderbuffer for a read operation (glReadPixels, glCopyPixels,
+ * glCopyTex[Sub]Image, etc) exists.
+ * \param format a basic image format such as GL_RGB, GL_RGBA, GL_ALPHA,
+ * GL_DEPTH_COMPONENT, etc. or GL_COLOR, GL_DEPTH, GL_STENCIL.
+ * \return GL_TRUE if buffer exists, GL_FALSE otherwise
+ */
+GLboolean
+_mesa_source_buffer_exists(struct gl_context *ctx, GLenum format)
+{
+ const struct gl_renderbuffer_attachment *att = ctx->ReadBuffer->Attachment;
+
+ /* If we don't know the framebuffer status, update it now */
+ if (ctx->ReadBuffer->_Status == 0) {
+ _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
+ }
+
+ if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ return GL_FALSE;
+ }
+
+ switch (format) {
+ case GL_COLOR:
+ case GL_RED:
+ case GL_GREEN:
+ case GL_BLUE:
+ case GL_ALPHA:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE_ALPHA:
+ case GL_INTENSITY:
+ case GL_RG:
+ case GL_RGB:
+ case GL_BGR:
+ case GL_RGBA:
+ case GL_BGRA:
+ case GL_ABGR_EXT:
+ case GL_COLOR_INDEX:
+ case GL_RED_INTEGER_EXT:
+ case GL_GREEN_INTEGER_EXT:
+ case GL_BLUE_INTEGER_EXT:
+ case GL_ALPHA_INTEGER_EXT:
+ case GL_RGB_INTEGER_EXT:
+ case GL_RGBA_INTEGER_EXT:
+ case GL_BGR_INTEGER_EXT:
+ case GL_BGRA_INTEGER_EXT:
+ case GL_LUMINANCE_INTEGER_EXT:
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ if (ctx->ReadBuffer->_ColorReadBuffer == NULL) {
+ return GL_FALSE;
+ }
+ ASSERT(_mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_RED_BITS) > 0 ||
+ _mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_ALPHA_BITS) > 0 ||
+ _mesa_get_format_bits(ctx->ReadBuffer->_ColorReadBuffer->Format, GL_INDEX_BITS) > 0);
+ break;
+ case GL_DEPTH:
+ case GL_DEPTH_COMPONENT:
+ if (!att[BUFFER_DEPTH].Renderbuffer) {
+ return GL_FALSE;
+ }
+ /*ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);*/
+ break;
+ case GL_STENCIL:
+ case GL_STENCIL_INDEX:
+ if (!att[BUFFER_STENCIL].Renderbuffer) {
+ return GL_FALSE;
+ }
+ /*ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);*/
+ break;
+ case GL_DEPTH_STENCIL_EXT:
+ if (!att[BUFFER_DEPTH].Renderbuffer ||
+ !att[BUFFER_STENCIL].Renderbuffer) {
+ return GL_FALSE;
+ }
+ /*
+ ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);
+ ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);
+ */
+ break;
+ default:
+ _mesa_problem(ctx,
+ "Unexpected format 0x%x in _mesa_source_buffer_exists",
+ format);
+ return GL_FALSE;
+ }
+
+ /* OK */
+ return GL_TRUE;
+}
+
+
+/**
+ * As above, but for drawing operations.
+ * XXX could do some code merging w/ above function.
+ */
+GLboolean
+_mesa_dest_buffer_exists(struct gl_context *ctx, GLenum format)
+{
+ const struct gl_renderbuffer_attachment *att = ctx->DrawBuffer->Attachment;
+
+ /* If we don't know the framebuffer status, update it now */
+ if (ctx->DrawBuffer->_Status == 0) {
+ _mesa_test_framebuffer_completeness(ctx, ctx->DrawBuffer);
+ }
+
+ if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ return GL_FALSE;
+ }
+
+ switch (format) {
+ case GL_COLOR:
+ case GL_RED:
+ case GL_GREEN:
+ case GL_BLUE:
+ case GL_ALPHA:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE_ALPHA:
+ case GL_INTENSITY:
+ case GL_RGB:
+ case GL_BGR:
+ case GL_RGBA:
+ case GL_BGRA:
+ case GL_ABGR_EXT:
+ case GL_COLOR_INDEX:
+ case GL_RED_INTEGER_EXT:
+ case GL_GREEN_INTEGER_EXT:
+ case GL_BLUE_INTEGER_EXT:
+ case GL_ALPHA_INTEGER_EXT:
+ case GL_RGB_INTEGER_EXT:
+ case GL_RGBA_INTEGER_EXT:
+ case GL_BGR_INTEGER_EXT:
+ case GL_BGRA_INTEGER_EXT:
+ case GL_LUMINANCE_INTEGER_EXT:
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ /* Nothing special since GL_DRAW_BUFFER could be GL_NONE. */
+ /* Could assert that colorbuffer has RedBits > 0 */
+ break;
+ case GL_DEPTH:
+ case GL_DEPTH_COMPONENT:
+ if (!att[BUFFER_DEPTH].Renderbuffer) {
+ return GL_FALSE;
+ }
+ /*ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);*/
+ break;
+ case GL_STENCIL:
+ case GL_STENCIL_INDEX:
+ if (!att[BUFFER_STENCIL].Renderbuffer) {
+ return GL_FALSE;
+ }
+ /*ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);*/
+ break;
+ case GL_DEPTH_STENCIL_EXT:
+ if (!att[BUFFER_DEPTH].Renderbuffer ||
+ !att[BUFFER_STENCIL].Renderbuffer) {
+ return GL_FALSE;
+ }
+ /*
+ ASSERT(att[BUFFER_DEPTH].Renderbuffer->DepthBits > 0);
+ ASSERT(att[BUFFER_STENCIL].Renderbuffer->StencilBits > 0);
+ */
+ break;
+ default:
+ _mesa_problem(ctx,
+ "Unexpected format 0x%x in _mesa_dest_buffer_exists",
+ format);
+ return GL_FALSE;
+ }
+
+ /* OK */
+ return GL_TRUE;
+}
+
+
+/**
+ * Used to answer the GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES query.
+ */
+GLenum
+_mesa_get_color_read_format(struct gl_context *ctx)
+{
+ switch (ctx->ReadBuffer->_ColorReadBuffer->Format) {
+ case MESA_FORMAT_ARGB8888:
+ return GL_BGRA;
+ case MESA_FORMAT_RGB565:
+ return GL_BGR;
+ default:
+ return GL_RGBA;
+ }
+}
+
+
+/**
+ * Used to answer the GL_IMPLEMENTATION_COLOR_READ_TYPE_OES query.
+ */
+GLenum
+_mesa_get_color_read_type(struct gl_context *ctx)
+{
+ switch (ctx->ReadBuffer->_ColorReadBuffer->Format) {
+ case MESA_FORMAT_ARGB8888:
+ return GL_UNSIGNED_BYTE;
+ case MESA_FORMAT_RGB565:
+ return GL_UNSIGNED_SHORT_5_6_5_REV;
+ default:
+ return GL_UNSIGNED_BYTE;
+ }
+}
+
+
+/**
+ * Print framebuffer info to stderr, for debugging.
+ */
+void
+_mesa_print_framebuffer(const struct gl_framebuffer *fb)
+{
+ GLuint i;
+
+ fprintf(stderr, "Mesa Framebuffer %u at %p\n", fb->Name, (void *) fb);
+ fprintf(stderr, " Size: %u x %u Status: %s\n", fb->Width, fb->Height,
+ _mesa_lookup_enum_by_nr(fb->_Status));
+ fprintf(stderr, " Attachments:\n");
+
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ const struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
+ if (att->Type == GL_TEXTURE) {
+ const struct gl_texture_image *texImage;
+ fprintf(stderr,
+ " %2d: Texture %u, level %u, face %u, slice %u, complete %d\n",
+ i, att->Texture->Name, att->TextureLevel, att->CubeMapFace,
+ att->Zoffset, att->Complete);
+ texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+ fprintf(stderr, " Size: %u x %u x %u Format %s\n",
+ texImage->Width, texImage->Height, texImage->Depth,
+ _mesa_get_format_name(texImage->TexFormat));
+ }
+ else if (att->Type == GL_RENDERBUFFER) {
+ fprintf(stderr, " %2d: Renderbuffer %u, complete %d\n",
+ i, att->Renderbuffer->Name, att->Complete);
+ fprintf(stderr, " Size: %u x %u Format %s\n",
+ att->Renderbuffer->Width, att->Renderbuffer->Height,
+ _mesa_get_format_name(att->Renderbuffer->Format));
+ }
+ else {
+ fprintf(stderr, " %2d: none\n", i);
+ }
+ }
+}
diff --git a/mesalib/src/mesa/main/get.c b/mesalib/src/mesa/main/get.c
index 336304c59..529285027 100644
--- a/mesalib/src/mesa/main/get.c
+++ b/mesalib/src/mesa/main/get.c
@@ -1,2527 +1,2527 @@
-/*
- * Copyright (C) 2010 Brian Paul All Rights Reserved.
- * Copyright (C) 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Author: Kristian Høgsberg <krh@bitplanet.net>
- */
-
-#include "glheader.h"
-#include "context.h"
-#include "enable.h"
-#include "enums.h"
-#include "extensions.h"
-#include "get.h"
-#include "macros.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "state.h"
-#include "texcompress.h"
-#include "framebuffer.h"
-
-/* This is a table driven implemetation of the glGet*v() functions.
- * The basic idea is that most getters just look up an int somewhere
- * in struct gl_context and then convert it to a bool or float according to
- * which of glGetIntegerv() glGetBooleanv() etc is being called.
- * Instead of generating code to do this, we can just record the enum
- * value and the offset into struct gl_context in an array of structs. Then
- * in glGet*(), we lookup the struct for the enum in question, and use
- * the offset to get the int we need.
- *
- * Sometimes we need to look up a float, a boolean, a bit in a
- * bitfield, a matrix or other types instead, so we need to track the
- * type of the value in struct gl_context. And sometimes the value isn't in
- * struct gl_context but in the drawbuffer, the array object, current texture
- * unit, or maybe it's a computed value. So we need to also track
- * where or how to find the value. Finally, we sometimes need to
- * check that one of a number of extensions are enabled, the GL
- * version or flush or call _mesa_update_state(). This is done by
- * attaching optional extra information to the value description
- * struct, it's sort of like an array of opcodes that describe extra
- * checks or actions.
- *
- * Putting all this together we end up with struct value_desc below,
- * and with a couple of macros to help, the table of struct value_desc
- * is about as concise as the specification in the old python script.
- */
-
-#undef CONST
-
-#define FLOAT_TO_BOOLEAN(X) ( (X) ? GL_TRUE : GL_FALSE )
-#define FLOAT_TO_FIXED(F) ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
- ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
- (GLint) ((F) * 65536.0f) )
-
-#define INT_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
-#define INT_TO_FIXED(I) ( ((I) > SHRT_MAX) ? INT_MAX : \
- ((I) < SHRT_MIN) ? INT_MIN : \
- (GLint) ((I) * 65536) )
-
-#define INT64_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
-#define INT64_TO_INT(I) ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
-
-#define BOOLEAN_TO_INT(B) ( (GLint) (B) )
-#define BOOLEAN_TO_INT64(B) ( (GLint64) (B) )
-#define BOOLEAN_TO_FLOAT(B) ( (B) ? 1.0F : 0.0F )
-#define BOOLEAN_TO_FIXED(B) ( (GLint) ((B) ? 1 : 0) << 16 )
-
-#define ENUM_TO_INT64(E) ( (GLint64) (E) )
-#define ENUM_TO_FIXED(E) (E)
-
-enum value_type {
- TYPE_INVALID,
- TYPE_API_MASK,
- TYPE_INT,
- TYPE_INT_2,
- TYPE_INT_3,
- TYPE_INT_4,
- TYPE_INT_N,
- TYPE_INT64,
- TYPE_ENUM,
- TYPE_ENUM_2,
- TYPE_BOOLEAN,
- TYPE_BIT_0,
- TYPE_BIT_1,
- TYPE_BIT_2,
- TYPE_BIT_3,
- TYPE_BIT_4,
- TYPE_BIT_5,
- TYPE_FLOAT,
- TYPE_FLOAT_2,
- TYPE_FLOAT_3,
- TYPE_FLOAT_4,
- TYPE_FLOATN,
- TYPE_FLOATN_2,
- TYPE_FLOATN_3,
- TYPE_FLOATN_4,
- TYPE_DOUBLEN,
- TYPE_MATRIX,
- TYPE_MATRIX_T,
- TYPE_CONST
-};
-
-enum value_location {
- LOC_BUFFER,
- LOC_CONTEXT,
- LOC_ARRAY,
- LOC_TEXUNIT,
- LOC_CUSTOM
-};
-
-enum value_extra {
- EXTRA_END = 0x8000,
- EXTRA_VERSION_30,
- EXTRA_VERSION_31,
- EXTRA_VERSION_32,
- EXTRA_VERSION_ES2,
- EXTRA_NEW_BUFFERS,
- EXTRA_VALID_DRAW_BUFFER,
- EXTRA_VALID_TEXTURE_UNIT,
- EXTRA_FLUSH_CURRENT,
-};
-
-#define NO_EXTRA NULL
-#define NO_OFFSET 0
-
-struct value_desc {
- GLenum pname;
- GLubyte location; /**< enum value_location */
- GLubyte type; /**< enum value_type */
- int offset;
- const int *extra;
-};
-
-union value {
- GLfloat value_float;
- GLfloat value_float_4[4];
- GLmatrix *value_matrix;
- GLint value_int;
- GLint value_int_4[4];
- GLint64 value_int64;
- GLenum value_enum;
-
- /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
- struct {
- GLint n, ints[100];
- } value_int_n;
- GLboolean value_bool;
-};
-
-#define BUFFER_FIELD(field, type) \
- LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
-#define CONTEXT_FIELD(field, type) \
- LOC_CONTEXT, type, offsetof(struct gl_context, field)
-#define ARRAY_FIELD(field, type) \
- LOC_ARRAY, type, offsetof(struct gl_array_object, field)
-#define CONST(value) \
- LOC_CONTEXT, TYPE_CONST, value
-
-#define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
-#define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
-#define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
-
-#define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
-#define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
-#define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
-#define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
-#define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
-#define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
-#define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
-#define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
-#define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
-#define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
-#define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
-#define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
-#define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
-#define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
-#define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
-#define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
-#define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
-#define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
-
-#define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
-#define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
-#define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
-
-#define EXT(f) \
- offsetof(struct gl_extensions, f)
-
-#define EXTRA_EXT(e) \
- static const int extra_##e[] = { \
- EXT(e), EXTRA_END \
- }
-
-#define EXTRA_EXT2(e1, e2) \
- static const int extra_##e1##_##e2[] = { \
- EXT(e1), EXT(e2), EXTRA_END \
- }
-
-/* The 'extra' mechanism is a way to specify extra checks (such as
- * extensions or specific gl versions) or actions (flush current, new
- * buffers) that we need to do before looking up an enum. We need to
- * declare them all up front so we can refer to them in the value_desc
- * structs below. */
-
-static const int extra_new_buffers[] = {
- EXTRA_NEW_BUFFERS,
- EXTRA_END
-};
-
-static const int extra_valid_draw_buffer[] = {
- EXTRA_VALID_DRAW_BUFFER,
- EXTRA_END
-};
-
-static const int extra_valid_texture_unit[] = {
- EXTRA_VALID_TEXTURE_UNIT,
- EXTRA_END
-};
-
-static const int extra_flush_current_valid_texture_unit[] = {
- EXTRA_FLUSH_CURRENT,
- EXTRA_VALID_TEXTURE_UNIT,
- EXTRA_END
-};
-
-static const int extra_flush_current[] = {
- EXTRA_FLUSH_CURRENT,
- EXTRA_END
-};
-
-static const int extra_new_buffers_OES_read_format[] = {
- EXTRA_NEW_BUFFERS,
- EXT(OES_read_format),
- EXTRA_END
-};
-
-static const int extra_EXT_secondary_color_flush_current[] = {
- EXT(EXT_secondary_color),
- EXTRA_FLUSH_CURRENT,
- EXTRA_END
-};
-
-static const int extra_EXT_fog_coord_flush_current[] = {
- EXT(EXT_fog_coord),
- EXTRA_FLUSH_CURRENT,
- EXTRA_END
-};
-
-static const int extra_EXT_texture_integer[] = {
- EXT(EXT_texture_integer),
- EXTRA_END
-};
-
-static const int extra_EXT_gpu_shader4[] = {
- EXT(EXT_gpu_shader4),
- EXTRA_END
-};
-
-
-EXTRA_EXT(ARB_ES2_compatibility);
-EXTRA_EXT(ARB_multitexture);
-EXTRA_EXT(ARB_texture_cube_map);
-EXTRA_EXT(MESA_texture_array);
-EXTRA_EXT2(EXT_secondary_color, ARB_vertex_program);
-EXTRA_EXT(EXT_secondary_color);
-EXTRA_EXT(EXT_fog_coord);
-EXTRA_EXT(EXT_texture_lod_bias);
-EXTRA_EXT(EXT_texture_filter_anisotropic);
-EXTRA_EXT(IBM_rasterpos_clip);
-EXTRA_EXT(NV_point_sprite);
-EXTRA_EXT(SGIS_generate_mipmap);
-EXTRA_EXT(NV_vertex_program);
-EXTRA_EXT(NV_fragment_program);
-EXTRA_EXT(NV_texture_rectangle);
-EXTRA_EXT(EXT_stencil_two_side);
-EXTRA_EXT(NV_light_max_exponent);
-EXTRA_EXT(EXT_depth_bounds_test);
-EXTRA_EXT(ARB_depth_clamp);
-EXTRA_EXT(ATI_fragment_shader);
-EXTRA_EXT(EXT_framebuffer_blit);
-EXTRA_EXT(ARB_shader_objects);
-EXTRA_EXT(EXT_provoking_vertex);
-EXTRA_EXT(ARB_fragment_shader);
-EXTRA_EXT(ARB_fragment_program);
-EXTRA_EXT2(ARB_framebuffer_object, EXT_framebuffer_multisample);
-EXTRA_EXT(EXT_framebuffer_object);
-EXTRA_EXT(APPLE_vertex_array_object);
-EXTRA_EXT(ARB_seamless_cube_map);
-EXTRA_EXT(EXT_compiled_vertex_array);
-EXTRA_EXT(ARB_sync);
-EXTRA_EXT(ARB_vertex_shader);
-EXTRA_EXT(EXT_transform_feedback);
-EXTRA_EXT(ARB_transform_feedback2);
-EXTRA_EXT(EXT_pixel_buffer_object);
-EXTRA_EXT(ARB_vertex_program);
-EXTRA_EXT2(NV_point_sprite, ARB_point_sprite);
-EXTRA_EXT2(ARB_fragment_program, NV_fragment_program);
-EXTRA_EXT2(ARB_vertex_program, NV_vertex_program);
-EXTRA_EXT2(ARB_vertex_program, ARB_fragment_program);
-EXTRA_EXT(ARB_vertex_buffer_object);
-EXTRA_EXT(ARB_geometry_shader4);
-EXTRA_EXT(ARB_copy_buffer);
-EXTRA_EXT(EXT_framebuffer_sRGB);
-
-static const int
-extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program[] = {
- EXT(ARB_vertex_program),
- EXT(ARB_fragment_program),
- EXT(NV_vertex_program),
- EXTRA_END
-};
-
-static const int
-extra_NV_vertex_program_ARB_vertex_program_ARB_fragment_program_NV_vertex_program[] = {
- EXT(NV_vertex_program),
- EXT(ARB_vertex_program),
- EXT(ARB_fragment_program),
- EXT(NV_vertex_program),
- EXTRA_END
-};
-
-static const int
-extra_NV_primitive_restart[] = {
- EXT(NV_primitive_restart),
- EXTRA_END
-};
-
-static const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
-static const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
-static const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
-
-static const int
-extra_ARB_vertex_program_version_es2[] = {
- EXT(ARB_vertex_program),
- EXTRA_VERSION_ES2,
- EXTRA_END
-};
-
-#define API_OPENGL_BIT (1 << API_OPENGL)
-#define API_OPENGLES_BIT (1 << API_OPENGLES)
-#define API_OPENGLES2_BIT (1 << API_OPENGLES2)
-
-/* This is the big table describing all the enums we accept in
- * glGet*v(). The table is partitioned into six parts: enums
- * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
- * between OpenGL and GLES, enums exclusive to GLES, etc for the
- * remaining combinations. When we add the enums to the hash table in
- * _mesa_init_get_hash(), we only add the enums for the API we're
- * instantiating and the different sections are guarded by #if
- * FEATURE_GL etc to make sure we only compile in the enums we may
- * need. */
-
-static const struct value_desc values[] = {
- /* Enums shared between OpenGL, GLES1 and GLES2 */
- { 0, 0, TYPE_API_MASK,
- API_OPENGL_BIT | API_OPENGLES_BIT | API_OPENGLES2_BIT, NO_EXTRA},
- { GL_ALPHA_BITS, BUFFER_INT(Visual.alphaBits), extra_new_buffers },
- { GL_BLEND, CONTEXT_BIT0(Color.BlendEnabled), NO_EXTRA },
- { GL_BLEND_SRC, CONTEXT_ENUM(Color.Blend[0].SrcRGB), NO_EXTRA },
- { GL_BLUE_BITS, BUFFER_INT(Visual.blueBits), extra_new_buffers },
- { GL_COLOR_CLEAR_VALUE, CONTEXT_FIELD(Color.ClearColor[0], TYPE_FLOATN_4), NO_EXTRA },
- { GL_COLOR_WRITEMASK, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
- { GL_CULL_FACE, CONTEXT_BOOL(Polygon.CullFlag), NO_EXTRA },
- { GL_CULL_FACE_MODE, CONTEXT_ENUM(Polygon.CullFaceMode), NO_EXTRA },
- { GL_DEPTH_BITS, BUFFER_INT(Visual.depthBits), NO_EXTRA },
- { GL_DEPTH_CLEAR_VALUE, CONTEXT_FIELD(Depth.Clear, TYPE_DOUBLEN), NO_EXTRA },
- { GL_DEPTH_FUNC, CONTEXT_ENUM(Depth.Func), NO_EXTRA },
- { GL_DEPTH_RANGE, CONTEXT_FIELD(Viewport.Near, TYPE_FLOATN_2), NO_EXTRA },
- { GL_DEPTH_TEST, CONTEXT_BOOL(Depth.Test), NO_EXTRA },
- { GL_DEPTH_WRITEMASK, CONTEXT_BOOL(Depth.Mask), NO_EXTRA },
- { GL_DITHER, CONTEXT_BOOL(Color.DitherFlag), NO_EXTRA },
- { GL_FRONT_FACE, CONTEXT_ENUM(Polygon.FrontFace), NO_EXTRA },
- { GL_GREEN_BITS, BUFFER_INT(Visual.greenBits), extra_new_buffers },
- { GL_LINE_WIDTH, CONTEXT_FLOAT(Line.Width), NO_EXTRA },
- { GL_ALIASED_LINE_WIDTH_RANGE, CONTEXT_FLOAT2(Const.MinLineWidth), NO_EXTRA },
- { GL_MAX_ELEMENTS_VERTICES, CONTEXT_INT(Const.MaxArrayLockSize), NO_EXTRA },
- { GL_MAX_ELEMENTS_INDICES, CONTEXT_INT(Const.MaxArrayLockSize), NO_EXTRA },
- { GL_MAX_TEXTURE_SIZE, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_context, Const.MaxTextureLevels), NO_EXTRA },
- { GL_MAX_VIEWPORT_DIMS, CONTEXT_INT2(Const.MaxViewportWidth), NO_EXTRA },
- { GL_PACK_ALIGNMENT, CONTEXT_INT(Pack.Alignment), NO_EXTRA },
- { GL_ALIASED_POINT_SIZE_RANGE, CONTEXT_FLOAT2(Const.MinPointSize), NO_EXTRA },
- { GL_POLYGON_OFFSET_FACTOR, CONTEXT_FLOAT(Polygon.OffsetFactor ), NO_EXTRA },
- { GL_POLYGON_OFFSET_UNITS, CONTEXT_FLOAT(Polygon.OffsetUnits ), NO_EXTRA },
- { GL_POLYGON_OFFSET_FILL, CONTEXT_BOOL(Polygon.OffsetFill), NO_EXTRA },
- { GL_RED_BITS, BUFFER_INT(Visual.redBits), extra_new_buffers },
- { GL_SCISSOR_BOX, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
- { GL_SCISSOR_TEST, CONTEXT_BOOL(Scissor.Enabled), NO_EXTRA },
- { GL_STENCIL_BITS, BUFFER_INT(Visual.stencilBits), NO_EXTRA },
- { GL_STENCIL_CLEAR_VALUE, CONTEXT_INT(Stencil.Clear), NO_EXTRA },
- { GL_STENCIL_FAIL, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
- { GL_STENCIL_FUNC, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
- { GL_STENCIL_PASS_DEPTH_FAIL, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
- { GL_STENCIL_PASS_DEPTH_PASS, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
- { GL_STENCIL_REF, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
- { GL_STENCIL_TEST, CONTEXT_BOOL(Stencil.Enabled), NO_EXTRA },
- { GL_STENCIL_VALUE_MASK, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
- { GL_STENCIL_WRITEMASK, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
- { GL_SUBPIXEL_BITS, CONTEXT_INT(Const.SubPixelBits), NO_EXTRA },
- { GL_TEXTURE_BINDING_2D, LOC_CUSTOM, TYPE_INT, TEXTURE_2D_INDEX, NO_EXTRA },
- { GL_UNPACK_ALIGNMENT, CONTEXT_INT(Unpack.Alignment), NO_EXTRA },
- { GL_VIEWPORT, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
-
- /* GL_ARB_multitexture */
- { GL_ACTIVE_TEXTURE_ARB,
- LOC_CUSTOM, TYPE_INT, 0, extra_ARB_multitexture },
-
- /* Note that all the OES_* extensions require that the Mesa "struct
- * gl_extensions" include a member with the name of the extension.
- * That structure does not yet include OES extensions (and we're
- * not sure whether it will). If it does, all the OES_*
- * extensions below should mark the dependency. */
-
- /* GL_ARB_texture_cube_map */
- { GL_TEXTURE_BINDING_CUBE_MAP_ARB, LOC_CUSTOM, TYPE_INT,
- TEXTURE_CUBE_INDEX, extra_ARB_texture_cube_map },
- { GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_context, Const.MaxCubeTextureLevels),
- extra_ARB_texture_cube_map }, /* XXX: OES_texture_cube_map */
-
- /* XXX: OES_blend_subtract */
- { GL_BLEND_SRC_RGB_EXT, CONTEXT_ENUM(Color.Blend[0].SrcRGB), NO_EXTRA },
- { GL_BLEND_DST_RGB_EXT, CONTEXT_ENUM(Color.Blend[0].DstRGB), NO_EXTRA },
- { GL_BLEND_SRC_ALPHA_EXT, CONTEXT_ENUM(Color.Blend[0].SrcA), NO_EXTRA },
- { GL_BLEND_DST_ALPHA_EXT, CONTEXT_ENUM(Color.Blend[0].DstA), NO_EXTRA },
-
- /* GL_BLEND_EQUATION_RGB, which is what we're really after, is
- * defined identically to GL_BLEND_EQUATION. */
- { GL_BLEND_EQUATION, CONTEXT_ENUM(Color.Blend[0].EquationRGB), NO_EXTRA },
- { GL_BLEND_EQUATION_ALPHA_EXT, CONTEXT_ENUM(Color.Blend[0].EquationA), NO_EXTRA },
-
- /* GL_ARB_texture_compression */
- { GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
- { GL_COMPRESSED_TEXTURE_FORMATS_ARB, LOC_CUSTOM, TYPE_INT_N, 0, NO_EXTRA },
-
- /* GL_ARB_multisample */
- { GL_SAMPLE_ALPHA_TO_COVERAGE_ARB,
- CONTEXT_BOOL(Multisample.SampleAlphaToCoverage), NO_EXTRA },
- { GL_SAMPLE_COVERAGE_ARB, CONTEXT_BOOL(Multisample.SampleCoverage), NO_EXTRA },
- { GL_SAMPLE_COVERAGE_VALUE_ARB,
- CONTEXT_FLOAT(Multisample.SampleCoverageValue), NO_EXTRA },
- { GL_SAMPLE_COVERAGE_INVERT_ARB,
- CONTEXT_BOOL(Multisample.SampleCoverageInvert), NO_EXTRA },
- { GL_SAMPLE_BUFFERS_ARB, BUFFER_INT(Visual.sampleBuffers), NO_EXTRA },
- { GL_SAMPLES_ARB, BUFFER_INT(Visual.samples), NO_EXTRA },
-
- /* GL_SGIS_generate_mipmap */
- { GL_GENERATE_MIPMAP_HINT_SGIS, CONTEXT_ENUM(Hint.GenerateMipmap),
- extra_SGIS_generate_mipmap },
-
- /* GL_ARB_vertex_buffer_object */
- { GL_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
-
- /* GL_ARB_vertex_buffer_object */
- /* GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB - not supported */
- { GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, 0,
- extra_ARB_vertex_buffer_object },
-
- /* GL_ARB_copy_buffer */
- { GL_COPY_READ_BUFFER, LOC_CUSTOM, TYPE_INT, 0, extra_ARB_copy_buffer },
- { GL_COPY_WRITE_BUFFER, LOC_CUSTOM, TYPE_INT, 0, extra_ARB_copy_buffer },
-
- /* GL_OES_read_format */
- { GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, LOC_CUSTOM, TYPE_INT, 0,
- extra_new_buffers_OES_read_format },
- { GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, LOC_CUSTOM, TYPE_INT, 0,
- extra_new_buffers_OES_read_format },
-
- /* GL_EXT_framebuffer_object */
- { GL_FRAMEBUFFER_BINDING_EXT, BUFFER_INT(Name),
- extra_EXT_framebuffer_object },
- { GL_RENDERBUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
- extra_EXT_framebuffer_object },
- { GL_MAX_RENDERBUFFER_SIZE_EXT, CONTEXT_INT(Const.MaxRenderbufferSize),
- extra_EXT_framebuffer_object },
-
- /* This entry isn't spec'ed for GLES 2, but is needed for Mesa's
- * GLSL: */
- { GL_MAX_CLIP_PLANES, CONTEXT_INT(Const.MaxClipPlanes), NO_EXTRA },
-
-#if FEATURE_GL || FEATURE_ES1
- /* Enums in OpenGL and GLES1 */
- { 0, 0, TYPE_API_MASK, API_OPENGL_BIT | API_OPENGLES_BIT, NO_EXTRA },
- { GL_LIGHT0, CONTEXT_BOOL(Light.Light[0].Enabled), NO_EXTRA },
- { GL_LIGHT1, CONTEXT_BOOL(Light.Light[1].Enabled), NO_EXTRA },
- { GL_LIGHT2, CONTEXT_BOOL(Light.Light[2].Enabled), NO_EXTRA },
- { GL_LIGHT3, CONTEXT_BOOL(Light.Light[3].Enabled), NO_EXTRA },
- { GL_LIGHT4, CONTEXT_BOOL(Light.Light[4].Enabled), NO_EXTRA },
- { GL_LIGHT5, CONTEXT_BOOL(Light.Light[5].Enabled), NO_EXTRA },
- { GL_LIGHT6, CONTEXT_BOOL(Light.Light[6].Enabled), NO_EXTRA },
- { GL_LIGHT7, CONTEXT_BOOL(Light.Light[7].Enabled), NO_EXTRA },
- { GL_LIGHTING, CONTEXT_BOOL(Light.Enabled), NO_EXTRA },
- { GL_LIGHT_MODEL_AMBIENT,
- CONTEXT_FIELD(Light.Model.Ambient[0], TYPE_FLOATN_4), NO_EXTRA },
- { GL_LIGHT_MODEL_TWO_SIDE, CONTEXT_BOOL(Light.Model.TwoSide), NO_EXTRA },
- { GL_ALPHA_TEST, CONTEXT_BOOL(Color.AlphaEnabled), NO_EXTRA },
- { GL_ALPHA_TEST_FUNC, CONTEXT_ENUM(Color.AlphaFunc), NO_EXTRA },
- { GL_ALPHA_TEST_REF, CONTEXT_FIELD(Color.AlphaRef, TYPE_FLOATN), NO_EXTRA },
- { GL_BLEND_DST, CONTEXT_ENUM(Color.Blend[0].DstRGB), NO_EXTRA },
- { GL_CLIP_PLANE0, CONTEXT_BIT0(Transform.ClipPlanesEnabled), NO_EXTRA },
- { GL_CLIP_PLANE1, CONTEXT_BIT1(Transform.ClipPlanesEnabled), NO_EXTRA },
- { GL_CLIP_PLANE2, CONTEXT_BIT2(Transform.ClipPlanesEnabled), NO_EXTRA },
- { GL_CLIP_PLANE3, CONTEXT_BIT3(Transform.ClipPlanesEnabled), NO_EXTRA },
- { GL_CLIP_PLANE4, CONTEXT_BIT4(Transform.ClipPlanesEnabled), NO_EXTRA },
- { GL_CLIP_PLANE5, CONTEXT_BIT5(Transform.ClipPlanesEnabled), NO_EXTRA },
- { GL_COLOR_MATERIAL, CONTEXT_BOOL(Light.ColorMaterialEnabled), NO_EXTRA },
- { GL_CURRENT_COLOR,
- CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_COLOR0][0], TYPE_FLOATN_4),
- extra_flush_current },
- { GL_CURRENT_NORMAL,
- CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_NORMAL][0], TYPE_FLOATN_3),
- extra_flush_current },
- { GL_CURRENT_TEXTURE_COORDS, LOC_CUSTOM, TYPE_FLOAT_4, 0,
- extra_flush_current_valid_texture_unit },
- { GL_DISTANCE_ATTENUATION_EXT, CONTEXT_FLOAT3(Point.Params[0]), NO_EXTRA },
- { GL_FOG, CONTEXT_BOOL(Fog.Enabled), NO_EXTRA },
- { GL_FOG_COLOR, CONTEXT_FIELD(Fog.Color[0], TYPE_FLOATN_4), NO_EXTRA },
- { GL_FOG_DENSITY, CONTEXT_FLOAT(Fog.Density), NO_EXTRA },
- { GL_FOG_END, CONTEXT_FLOAT(Fog.End), NO_EXTRA },
- { GL_FOG_HINT, CONTEXT_ENUM(Hint.Fog), NO_EXTRA },
- { GL_FOG_MODE, CONTEXT_ENUM(Fog.Mode), NO_EXTRA },
- { GL_FOG_START, CONTEXT_FLOAT(Fog.Start), NO_EXTRA },
- { GL_LINE_SMOOTH, CONTEXT_BOOL(Line.SmoothFlag), NO_EXTRA },
- { GL_LINE_SMOOTH_HINT, CONTEXT_ENUM(Hint.LineSmooth), NO_EXTRA },
- { GL_LINE_WIDTH_RANGE, CONTEXT_FLOAT2(Const.MinLineWidthAA), NO_EXTRA },
- { GL_COLOR_LOGIC_OP, CONTEXT_BOOL(Color.ColorLogicOpEnabled), NO_EXTRA },
- { GL_LOGIC_OP_MODE, CONTEXT_ENUM(Color.LogicOp), NO_EXTRA },
- { GL_MATRIX_MODE, CONTEXT_ENUM(Transform.MatrixMode), NO_EXTRA },
- { GL_MAX_MODELVIEW_STACK_DEPTH, CONST(MAX_MODELVIEW_STACK_DEPTH), NO_EXTRA },
- { GL_MAX_PROJECTION_STACK_DEPTH, CONST(MAX_PROJECTION_STACK_DEPTH), NO_EXTRA },
- { GL_MAX_TEXTURE_STACK_DEPTH, CONST(MAX_TEXTURE_STACK_DEPTH), NO_EXTRA },
- { GL_MODELVIEW_MATRIX, CONTEXT_MATRIX(ModelviewMatrixStack.Top), NO_EXTRA },
- { GL_MODELVIEW_STACK_DEPTH, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_context, ModelviewMatrixStack.Depth), NO_EXTRA },
- { GL_NORMALIZE, CONTEXT_BOOL(Transform.Normalize), NO_EXTRA },
- { GL_PACK_SKIP_IMAGES_EXT, CONTEXT_INT(Pack.SkipImages), NO_EXTRA },
- { GL_PERSPECTIVE_CORRECTION_HINT, CONTEXT_ENUM(Hint.PerspectiveCorrection), NO_EXTRA },
- { GL_POINT_SIZE, CONTEXT_FLOAT(Point.Size), NO_EXTRA },
- { GL_POINT_SIZE_RANGE, CONTEXT_FLOAT2(Const.MinPointSizeAA), NO_EXTRA },
- { GL_POINT_SMOOTH, CONTEXT_BOOL(Point.SmoothFlag), NO_EXTRA },
- { GL_POINT_SMOOTH_HINT, CONTEXT_ENUM(Hint.PointSmooth), NO_EXTRA },
- { GL_POINT_SIZE_MIN_EXT, CONTEXT_FLOAT(Point.MinSize), NO_EXTRA },
- { GL_POINT_SIZE_MAX_EXT, CONTEXT_FLOAT(Point.MaxSize), NO_EXTRA },
- { GL_POINT_FADE_THRESHOLD_SIZE_EXT, CONTEXT_FLOAT(Point.Threshold), NO_EXTRA },
- { GL_PROJECTION_MATRIX, CONTEXT_MATRIX(ProjectionMatrixStack.Top), NO_EXTRA },
- { GL_PROJECTION_STACK_DEPTH, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_context, ProjectionMatrixStack.Depth), NO_EXTRA },
- { GL_RESCALE_NORMAL, CONTEXT_BOOL(Transform.RescaleNormals), NO_EXTRA },
- { GL_SHADE_MODEL, CONTEXT_ENUM(Light.ShadeModel), NO_EXTRA },
- { GL_TEXTURE_2D, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
- { GL_TEXTURE_MATRIX, LOC_CUSTOM, TYPE_MATRIX, 0, extra_valid_texture_unit },
- { GL_TEXTURE_STACK_DEPTH, LOC_CUSTOM, TYPE_INT, 0,
- extra_valid_texture_unit },
-
- { GL_VERTEX_ARRAY, ARRAY_BOOL(Vertex.Enabled), NO_EXTRA },
- { GL_VERTEX_ARRAY_SIZE, ARRAY_INT(Vertex.Size), NO_EXTRA },
- { GL_VERTEX_ARRAY_TYPE, ARRAY_ENUM(Vertex.Type), NO_EXTRA },
- { GL_VERTEX_ARRAY_STRIDE, ARRAY_INT(Vertex.Stride), NO_EXTRA },
- { GL_NORMAL_ARRAY, ARRAY_ENUM(Normal.Enabled), NO_EXTRA },
- { GL_NORMAL_ARRAY_TYPE, ARRAY_ENUM(Normal.Type), NO_EXTRA },
- { GL_NORMAL_ARRAY_STRIDE, ARRAY_INT(Normal.Stride), NO_EXTRA },
- { GL_COLOR_ARRAY, ARRAY_BOOL(Color.Enabled), NO_EXTRA },
- { GL_COLOR_ARRAY_SIZE, ARRAY_INT(Color.Size), NO_EXTRA },
- { GL_COLOR_ARRAY_TYPE, ARRAY_ENUM(Color.Type), NO_EXTRA },
- { GL_COLOR_ARRAY_STRIDE, ARRAY_INT(Color.Stride), NO_EXTRA },
- { GL_TEXTURE_COORD_ARRAY,
- LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct gl_client_array, Enabled), NO_EXTRA },
- { GL_TEXTURE_COORD_ARRAY_SIZE,
- LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct gl_client_array, Size), NO_EXTRA },
- { GL_TEXTURE_COORD_ARRAY_TYPE,
- LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct gl_client_array, Type), NO_EXTRA },
- { GL_TEXTURE_COORD_ARRAY_STRIDE,
- LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct gl_client_array, Stride), NO_EXTRA },
-
- /* GL_ARB_ES2_compatibility */
- { GL_SHADER_COMPILER, CONST(1), extra_ARB_ES2_compatibility },
- { GL_MAX_VARYING_VECTORS, CONTEXT_INT(Const.MaxVarying),
- extra_ARB_ES2_compatibility },
- { GL_MAX_VERTEX_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0,
- extra_ARB_ES2_compatibility },
- { GL_MAX_FRAGMENT_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0,
- extra_ARB_ES2_compatibility },
-
- /* GL_ARB_multitexture */
- { GL_MAX_TEXTURE_UNITS_ARB,
- CONTEXT_INT(Const.MaxTextureUnits), extra_ARB_multitexture },
- { GL_CLIENT_ACTIVE_TEXTURE_ARB,
- LOC_CUSTOM, TYPE_INT, 0, extra_ARB_multitexture },
-
- /* GL_ARB_texture_cube_map */
- { GL_TEXTURE_CUBE_MAP_ARB, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
- /* S, T, and R are always set at the same time */
- { GL_TEXTURE_GEN_STR_OES, LOC_TEXUNIT, TYPE_BIT_0,
- offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
-
- /* GL_ARB_multisample */
- { GL_MULTISAMPLE_ARB, CONTEXT_BOOL(Multisample.Enabled), NO_EXTRA },
- { GL_SAMPLE_ALPHA_TO_ONE_ARB, CONTEXT_BOOL(Multisample.SampleAlphaToOne), NO_EXTRA },
-
- /* GL_ARB_vertex_buffer_object */
- { GL_VERTEX_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_array_object, Vertex.BufferObj), NO_EXTRA },
- { GL_NORMAL_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_array_object, Normal.BufferObj), NO_EXTRA },
- { GL_COLOR_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_array_object, Color.BufferObj), NO_EXTRA },
- { GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
-
- /* GL_OES_point_sprite */
- { GL_POINT_SPRITE_NV,
- CONTEXT_BOOL(Point.PointSprite),
- extra_NV_point_sprite_ARB_point_sprite },
-
- /* GL_ARB_fragment_shader */
- { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB,
- CONTEXT_INT(Const.FragmentProgram.MaxUniformComponents),
- extra_ARB_fragment_shader },
-
- /* GL_ARB_vertex_shader */
- { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB,
- CONTEXT_INT(Const.VertexProgram.MaxUniformComponents),
- extra_ARB_vertex_shader },
- { GL_MAX_VARYING_FLOATS_ARB, LOC_CUSTOM, TYPE_INT, 0,
- extra_ARB_vertex_shader },
-
- /* GL_EXT_texture_lod_bias */
- { GL_MAX_TEXTURE_LOD_BIAS_EXT, CONTEXT_FLOAT(Const.MaxTextureLodBias),
- extra_EXT_texture_lod_bias },
-
- /* GL_EXT_texture_filter_anisotropic */
- { GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,
- CONTEXT_FLOAT(Const.MaxTextureMaxAnisotropy),
- extra_EXT_texture_filter_anisotropic },
-#endif /* FEATURE_GL || FEATURE_ES1 */
-
-#if FEATURE_ES1
- { 0, 0, TYPE_API_MASK, API_OPENGLES_BIT },
- /* XXX: OES_matrix_get */
- { GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES },
- { GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES },
- { GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES },
-
- /* OES_point_size_array */
- { GL_POINT_SIZE_ARRAY_OES, ARRAY_FIELD(PointSize.Enabled, TYPE_BOOLEAN) },
- { GL_POINT_SIZE_ARRAY_TYPE_OES, ARRAY_FIELD(PointSize.Type, TYPE_ENUM) },
- { GL_POINT_SIZE_ARRAY_STRIDE_OES, ARRAY_FIELD(PointSize.Stride, TYPE_INT) },
- { GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES, LOC_CUSTOM, TYPE_INT, 0 },
-#endif /* FEATURE_ES1 */
-
-#if FEATURE_GL || FEATURE_ES2
- { 0, 0, TYPE_API_MASK, API_OPENGL_BIT | API_OPENGLES2_BIT, NO_EXTRA },
- /* This entry isn't spec'ed for GLES 2, but is needed for Mesa's GLSL: */
- { GL_MAX_LIGHTS, CONTEXT_INT(Const.MaxLights), NO_EXTRA },
- { GL_MAX_TEXTURE_COORDS_ARB, /* == GL_MAX_TEXTURE_COORDS_NV */
- CONTEXT_INT(Const.MaxTextureCoordUnits),
- extra_ARB_fragment_program_NV_fragment_program },
-
- /* GL_ARB_draw_buffers */
- { GL_MAX_DRAW_BUFFERS_ARB, CONTEXT_INT(Const.MaxDrawBuffers), NO_EXTRA },
-
- { GL_BLEND_COLOR_EXT, CONTEXT_FIELD(Color.BlendColor[0], TYPE_FLOATN_4), NO_EXTRA },
- /* GL_ARB_fragment_program */
- { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, /* == GL_MAX_TEXTURE_IMAGE_UNITS_NV */
- CONTEXT_INT(Const.MaxTextureImageUnits),
- extra_ARB_fragment_program_NV_fragment_program },
- { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB,
- CONTEXT_INT(Const.MaxVertexTextureImageUnits), extra_ARB_vertex_shader },
- { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB,
- CONTEXT_INT(Const.MaxCombinedTextureImageUnits),
- extra_ARB_vertex_shader },
-
- /* GL_ARB_shader_objects
- * Actually, this token isn't part of GL_ARB_shader_objects, but is
- * close enough for now. */
- { GL_CURRENT_PROGRAM, LOC_CUSTOM, TYPE_INT, 0, extra_ARB_shader_objects },
-
- /* OpenGL 2.0 */
- { GL_STENCIL_BACK_FUNC, CONTEXT_ENUM(Stencil.Function[1]), NO_EXTRA },
- { GL_STENCIL_BACK_VALUE_MASK, CONTEXT_INT(Stencil.ValueMask[1]), NO_EXTRA },
- { GL_STENCIL_BACK_WRITEMASK, CONTEXT_INT(Stencil.WriteMask[1]), NO_EXTRA },
- { GL_STENCIL_BACK_REF, CONTEXT_INT(Stencil.Ref[1]), NO_EXTRA },
- { GL_STENCIL_BACK_FAIL, CONTEXT_ENUM(Stencil.FailFunc[1]), NO_EXTRA },
- { GL_STENCIL_BACK_PASS_DEPTH_FAIL, CONTEXT_ENUM(Stencil.ZFailFunc[1]), NO_EXTRA },
- { GL_STENCIL_BACK_PASS_DEPTH_PASS, CONTEXT_ENUM(Stencil.ZPassFunc[1]), NO_EXTRA },
-
- { GL_MAX_VERTEX_ATTRIBS_ARB,
- CONTEXT_INT(Const.VertexProgram.MaxAttribs),
- extra_ARB_vertex_program_version_es2 },
-
- /* OES_texture_3D */
- { GL_TEXTURE_BINDING_3D, LOC_CUSTOM, TYPE_INT, TEXTURE_3D_INDEX, NO_EXTRA },
- { GL_MAX_3D_TEXTURE_SIZE, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_context, Const.Max3DTextureLevels), NO_EXTRA },
-
- /* GL_ARB_fragment_program/OES_standard_derivatives */
- { GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB,
- CONTEXT_ENUM(Hint.FragmentShaderDerivative), extra_ARB_fragment_shader },
-#endif /* FEATURE_GL || FEATURE_ES2 */
-
-#if FEATURE_ES2
- /* Enums unique to OpenGL ES 2.0 */
- { 0, 0, TYPE_API_MASK, API_OPENGLES2_BIT, NO_EXTRA },
- { GL_MAX_FRAGMENT_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
- { GL_MAX_VARYING_VECTORS, CONTEXT_INT(Const.MaxVarying), NO_EXTRA },
- { GL_MAX_VERTEX_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
- { GL_SHADER_COMPILER, CONST(1), NO_EXTRA },
- /* OES_get_program_binary */
- { GL_NUM_SHADER_BINARY_FORMATS, CONST(0), NO_EXTRA },
- { GL_SHADER_BINARY_FORMATS, CONST(0), NO_EXTRA },
-#endif /* FEATURE_ES2 */
-
-#if FEATURE_GL
- /* Remaining enums are only in OpenGL */
- { 0, 0, TYPE_API_MASK, API_OPENGL_BIT, NO_EXTRA },
- { GL_ACCUM_RED_BITS, BUFFER_INT(Visual.accumRedBits), NO_EXTRA },
- { GL_ACCUM_GREEN_BITS, BUFFER_INT(Visual.accumGreenBits), NO_EXTRA },
- { GL_ACCUM_BLUE_BITS, BUFFER_INT(Visual.accumBlueBits), NO_EXTRA },
- { GL_ACCUM_ALPHA_BITS, BUFFER_INT(Visual.accumAlphaBits), NO_EXTRA },
- { GL_ACCUM_CLEAR_VALUE, CONTEXT_FIELD(Accum.ClearColor[0], TYPE_FLOATN_4), NO_EXTRA },
- { GL_ALPHA_BIAS, CONTEXT_FLOAT(Pixel.AlphaBias), NO_EXTRA },
- { GL_ALPHA_SCALE, CONTEXT_FLOAT(Pixel.AlphaScale), NO_EXTRA },
- { GL_ATTRIB_STACK_DEPTH, CONTEXT_INT(AttribStackDepth), NO_EXTRA },
- { GL_AUTO_NORMAL, CONTEXT_BOOL(Eval.AutoNormal), NO_EXTRA },
- { GL_AUX_BUFFERS, BUFFER_INT(Visual.numAuxBuffers), NO_EXTRA },
- { GL_BLUE_BIAS, CONTEXT_FLOAT(Pixel.BlueBias), NO_EXTRA },
- { GL_BLUE_SCALE, CONTEXT_FLOAT(Pixel.BlueScale), NO_EXTRA },
- { GL_CLIENT_ATTRIB_STACK_DEPTH, CONTEXT_INT(ClientAttribStackDepth), NO_EXTRA },
- { GL_COLOR_MATERIAL_FACE, CONTEXT_ENUM(Light.ColorMaterialFace), NO_EXTRA },
- { GL_COLOR_MATERIAL_PARAMETER, CONTEXT_ENUM(Light.ColorMaterialMode), NO_EXTRA },
- { GL_CURRENT_INDEX,
- CONTEXT_FLOAT(Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0]),
- extra_flush_current },
- { GL_CURRENT_RASTER_COLOR,
- CONTEXT_FIELD(Current.RasterColor[0], TYPE_FLOATN_4), NO_EXTRA },
- { GL_CURRENT_RASTER_DISTANCE, CONTEXT_FLOAT(Current.RasterDistance), NO_EXTRA },
- { GL_CURRENT_RASTER_INDEX, CONST(1), NO_EXTRA },
- { GL_CURRENT_RASTER_POSITION, CONTEXT_FLOAT4(Current.RasterPos[0]), NO_EXTRA },
- { GL_CURRENT_RASTER_SECONDARY_COLOR,
- CONTEXT_FIELD(Current.RasterSecondaryColor[0], TYPE_FLOATN_4), NO_EXTRA },
- { GL_CURRENT_RASTER_TEXTURE_COORDS, LOC_CUSTOM, TYPE_FLOAT_4, 0,
- extra_valid_texture_unit },
- { GL_CURRENT_RASTER_POSITION_VALID, CONTEXT_BOOL(Current.RasterPosValid), NO_EXTRA },
- { GL_DEPTH_BIAS, CONTEXT_FLOAT(Pixel.DepthBias), NO_EXTRA },
- { GL_DEPTH_SCALE, CONTEXT_FLOAT(Pixel.DepthScale), NO_EXTRA },
- { GL_DOUBLEBUFFER, BUFFER_INT(Visual.doubleBufferMode), NO_EXTRA },
- { GL_DRAW_BUFFER, BUFFER_ENUM(ColorDrawBuffer[0]), NO_EXTRA },
- { GL_EDGE_FLAG, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
- { GL_FEEDBACK_BUFFER_SIZE, CONTEXT_INT(Feedback.BufferSize), NO_EXTRA },
- { GL_FEEDBACK_BUFFER_TYPE, CONTEXT_ENUM(Feedback.Type), NO_EXTRA },
- { GL_FOG_INDEX, CONTEXT_FLOAT(Fog.Index), NO_EXTRA },
- { GL_GREEN_BIAS, CONTEXT_FLOAT(Pixel.GreenBias), NO_EXTRA },
- { GL_GREEN_SCALE, CONTEXT_FLOAT(Pixel.GreenScale), NO_EXTRA },
- { GL_INDEX_BITS, BUFFER_INT(Visual.indexBits), extra_new_buffers },
- { GL_INDEX_CLEAR_VALUE, CONTEXT_INT(Color.ClearIndex), NO_EXTRA },
- { GL_INDEX_MODE, CONST(0) , NO_EXTRA},
- { GL_INDEX_OFFSET, CONTEXT_INT(Pixel.IndexOffset), NO_EXTRA },
- { GL_INDEX_SHIFT, CONTEXT_INT(Pixel.IndexShift), NO_EXTRA },
- { GL_INDEX_WRITEMASK, CONTEXT_INT(Color.IndexMask), NO_EXTRA },
- { GL_LIGHT_MODEL_COLOR_CONTROL, CONTEXT_ENUM(Light.Model.ColorControl), NO_EXTRA },
- { GL_LIGHT_MODEL_LOCAL_VIEWER, CONTEXT_BOOL(Light.Model.LocalViewer), NO_EXTRA },
- { GL_LINE_STIPPLE, CONTEXT_BOOL(Line.StippleFlag), NO_EXTRA },
- { GL_LINE_STIPPLE_PATTERN, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
- { GL_LINE_STIPPLE_REPEAT, CONTEXT_INT(Line.StippleFactor), NO_EXTRA },
- { GL_LINE_WIDTH_GRANULARITY, CONTEXT_FLOAT(Const.LineWidthGranularity), NO_EXTRA },
- { GL_LIST_BASE, CONTEXT_INT(List.ListBase), NO_EXTRA },
- { GL_LIST_INDEX, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
- { GL_LIST_MODE, LOC_CUSTOM, TYPE_ENUM, 0, NO_EXTRA },
- { GL_INDEX_LOGIC_OP, CONTEXT_BOOL(Color.IndexLogicOpEnabled), NO_EXTRA },
- { GL_MAP1_COLOR_4, CONTEXT_BOOL(Eval.Map1Color4), NO_EXTRA },
- { GL_MAP1_GRID_DOMAIN, CONTEXT_FLOAT2(Eval.MapGrid1u1), NO_EXTRA },
- { GL_MAP1_GRID_SEGMENTS, CONTEXT_INT(Eval.MapGrid1un), NO_EXTRA },
- { GL_MAP1_INDEX, CONTEXT_BOOL(Eval.Map1Index), NO_EXTRA },
- { GL_MAP1_NORMAL, CONTEXT_BOOL(Eval.Map1Normal), NO_EXTRA },
- { GL_MAP1_TEXTURE_COORD_1, CONTEXT_BOOL(Eval.Map1TextureCoord1), NO_EXTRA },
- { GL_MAP1_TEXTURE_COORD_2, CONTEXT_BOOL(Eval.Map1TextureCoord2), NO_EXTRA },
- { GL_MAP1_TEXTURE_COORD_3, CONTEXT_BOOL(Eval.Map1TextureCoord3), NO_EXTRA },
- { GL_MAP1_TEXTURE_COORD_4, CONTEXT_BOOL(Eval.Map1TextureCoord4), NO_EXTRA },
- { GL_MAP1_VERTEX_3, CONTEXT_BOOL(Eval.Map1Vertex3), NO_EXTRA },
- { GL_MAP1_VERTEX_4, CONTEXT_BOOL(Eval.Map1Vertex4), NO_EXTRA },
- { GL_MAP2_COLOR_4, CONTEXT_BOOL(Eval.Map2Color4), NO_EXTRA },
- { GL_MAP2_GRID_DOMAIN, LOC_CUSTOM, TYPE_FLOAT_4, 0, NO_EXTRA },
- { GL_MAP2_GRID_SEGMENTS, CONTEXT_INT2(Eval.MapGrid2un), NO_EXTRA },
- { GL_MAP2_INDEX, CONTEXT_BOOL(Eval.Map2Index), NO_EXTRA },
- { GL_MAP2_NORMAL, CONTEXT_BOOL(Eval.Map2Normal), NO_EXTRA },
- { GL_MAP2_TEXTURE_COORD_1, CONTEXT_BOOL(Eval.Map2TextureCoord1), NO_EXTRA },
- { GL_MAP2_TEXTURE_COORD_2, CONTEXT_BOOL(Eval.Map2TextureCoord2), NO_EXTRA },
- { GL_MAP2_TEXTURE_COORD_3, CONTEXT_BOOL(Eval.Map2TextureCoord3), NO_EXTRA },
- { GL_MAP2_TEXTURE_COORD_4, CONTEXT_BOOL(Eval.Map2TextureCoord4), NO_EXTRA },
- { GL_MAP2_VERTEX_3, CONTEXT_BOOL(Eval.Map2Vertex3), NO_EXTRA },
- { GL_MAP2_VERTEX_4, CONTEXT_BOOL(Eval.Map2Vertex4), NO_EXTRA },
- { GL_MAP_COLOR, CONTEXT_BOOL(Pixel.MapColorFlag), NO_EXTRA },
- { GL_MAP_STENCIL, CONTEXT_BOOL(Pixel.MapStencilFlag), NO_EXTRA },
- { GL_MAX_ATTRIB_STACK_DEPTH, CONST(MAX_ATTRIB_STACK_DEPTH), NO_EXTRA },
- { GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, CONST(MAX_CLIENT_ATTRIB_STACK_DEPTH), NO_EXTRA },
-
- { GL_MAX_EVAL_ORDER, CONST(MAX_EVAL_ORDER), NO_EXTRA },
- { GL_MAX_LIST_NESTING, CONST(MAX_LIST_NESTING), NO_EXTRA },
- { GL_MAX_NAME_STACK_DEPTH, CONST(MAX_NAME_STACK_DEPTH), NO_EXTRA },
- { GL_MAX_PIXEL_MAP_TABLE, CONST(MAX_PIXEL_MAP_TABLE), NO_EXTRA },
- { GL_NAME_STACK_DEPTH, CONTEXT_INT(Select.NameStackDepth), NO_EXTRA },
- { GL_PACK_LSB_FIRST, CONTEXT_BOOL(Pack.LsbFirst), NO_EXTRA },
- { GL_PACK_ROW_LENGTH, CONTEXT_INT(Pack.RowLength), NO_EXTRA },
- { GL_PACK_SKIP_PIXELS, CONTEXT_INT(Pack.SkipPixels), NO_EXTRA },
- { GL_PACK_SKIP_ROWS, CONTEXT_INT(Pack.SkipRows), NO_EXTRA },
- { GL_PACK_SWAP_BYTES, CONTEXT_BOOL(Pack.SwapBytes), NO_EXTRA },
- { GL_PACK_IMAGE_HEIGHT_EXT, CONTEXT_INT(Pack.ImageHeight), NO_EXTRA },
- { GL_PACK_INVERT_MESA, CONTEXT_BOOL(Pack.Invert), NO_EXTRA },
- { GL_PIXEL_MAP_A_TO_A_SIZE, CONTEXT_INT(PixelMaps.AtoA.Size), NO_EXTRA },
- { GL_PIXEL_MAP_B_TO_B_SIZE, CONTEXT_INT(PixelMaps.BtoB.Size), NO_EXTRA },
- { GL_PIXEL_MAP_G_TO_G_SIZE, CONTEXT_INT(PixelMaps.GtoG.Size), NO_EXTRA },
- { GL_PIXEL_MAP_I_TO_A_SIZE, CONTEXT_INT(PixelMaps.ItoA.Size), NO_EXTRA },
- { GL_PIXEL_MAP_I_TO_B_SIZE, CONTEXT_INT(PixelMaps.ItoB.Size), NO_EXTRA },
- { GL_PIXEL_MAP_I_TO_G_SIZE, CONTEXT_INT(PixelMaps.ItoG.Size), NO_EXTRA },
- { GL_PIXEL_MAP_I_TO_I_SIZE, CONTEXT_INT(PixelMaps.ItoI.Size), NO_EXTRA },
- { GL_PIXEL_MAP_I_TO_R_SIZE, CONTEXT_INT(PixelMaps.ItoR.Size), NO_EXTRA },
- { GL_PIXEL_MAP_R_TO_R_SIZE, CONTEXT_INT(PixelMaps.RtoR.Size), NO_EXTRA },
- { GL_PIXEL_MAP_S_TO_S_SIZE, CONTEXT_INT(PixelMaps.StoS.Size), NO_EXTRA },
- { GL_POINT_SIZE_GRANULARITY, CONTEXT_FLOAT(Const.PointSizeGranularity), NO_EXTRA },
- { GL_POLYGON_MODE, CONTEXT_ENUM2(Polygon.FrontMode), NO_EXTRA },
- { GL_POLYGON_OFFSET_BIAS_EXT, CONTEXT_FLOAT(Polygon.OffsetUnits), NO_EXTRA },
- { GL_POLYGON_OFFSET_POINT, CONTEXT_BOOL(Polygon.OffsetPoint), NO_EXTRA },
- { GL_POLYGON_OFFSET_LINE, CONTEXT_BOOL(Polygon.OffsetLine), NO_EXTRA },
- { GL_POLYGON_SMOOTH, CONTEXT_BOOL(Polygon.SmoothFlag), NO_EXTRA },
- { GL_POLYGON_SMOOTH_HINT, CONTEXT_ENUM(Hint.PolygonSmooth), NO_EXTRA },
- { GL_POLYGON_STIPPLE, CONTEXT_BOOL(Polygon.StippleFlag), NO_EXTRA },
- { GL_READ_BUFFER, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
- { GL_RED_BIAS, CONTEXT_FLOAT(Pixel.RedBias), NO_EXTRA },
- { GL_RED_SCALE, CONTEXT_FLOAT(Pixel.RedScale), NO_EXTRA },
- { GL_RENDER_MODE, CONTEXT_ENUM(RenderMode), NO_EXTRA },
- { GL_RGBA_MODE, CONST(1), NO_EXTRA },
- { GL_SELECTION_BUFFER_SIZE, CONTEXT_INT(Select.BufferSize), NO_EXTRA },
- { GL_SHARED_TEXTURE_PALETTE_EXT, CONTEXT_BOOL(Texture.SharedPalette), NO_EXTRA },
-
- { GL_STEREO, BUFFER_INT(Visual.stereoMode), NO_EXTRA },
-
- { GL_TEXTURE_1D, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
- { GL_TEXTURE_3D, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
- { GL_TEXTURE_1D_ARRAY_EXT, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
- { GL_TEXTURE_2D_ARRAY_EXT, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
-
- { GL_TEXTURE_BINDING_1D, LOC_CUSTOM, TYPE_INT, TEXTURE_1D_INDEX, NO_EXTRA },
- { GL_TEXTURE_BINDING_1D_ARRAY, LOC_CUSTOM, TYPE_INT,
- TEXTURE_1D_ARRAY_INDEX, extra_MESA_texture_array },
- { GL_TEXTURE_BINDING_2D_ARRAY, LOC_CUSTOM, TYPE_INT,
- TEXTURE_1D_ARRAY_INDEX, extra_MESA_texture_array },
- { GL_MAX_ARRAY_TEXTURE_LAYERS_EXT,
- CONTEXT_INT(Const.MaxArrayTextureLayers), extra_MESA_texture_array },
-
- { GL_TEXTURE_GEN_S, LOC_TEXUNIT, TYPE_BIT_0,
- offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
- { GL_TEXTURE_GEN_T, LOC_TEXUNIT, TYPE_BIT_1,
- offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
- { GL_TEXTURE_GEN_R, LOC_TEXUNIT, TYPE_BIT_2,
- offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
- { GL_TEXTURE_GEN_Q, LOC_TEXUNIT, TYPE_BIT_3,
- offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
- { GL_UNPACK_LSB_FIRST, CONTEXT_BOOL(Unpack.LsbFirst), NO_EXTRA },
- { GL_UNPACK_ROW_LENGTH, CONTEXT_INT(Unpack.RowLength), NO_EXTRA },
- { GL_UNPACK_SKIP_PIXELS, CONTEXT_INT(Unpack.SkipPixels), NO_EXTRA },
- { GL_UNPACK_SKIP_ROWS, CONTEXT_INT(Unpack.SkipRows), NO_EXTRA },
- { GL_UNPACK_SWAP_BYTES, CONTEXT_BOOL(Unpack.SwapBytes), NO_EXTRA },
- { GL_UNPACK_SKIP_IMAGES_EXT, CONTEXT_INT(Unpack.SkipImages), NO_EXTRA },
- { GL_UNPACK_IMAGE_HEIGHT_EXT, CONTEXT_INT(Unpack.ImageHeight), NO_EXTRA },
- { GL_UNPACK_CLIENT_STORAGE_APPLE, CONTEXT_BOOL(Unpack.ClientStorage), NO_EXTRA },
- { GL_ZOOM_X, CONTEXT_FLOAT(Pixel.ZoomX), NO_EXTRA },
- { GL_ZOOM_Y, CONTEXT_FLOAT(Pixel.ZoomY), NO_EXTRA },
-
- /* Vertex arrays */
- { GL_VERTEX_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
- { GL_NORMAL_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
- { GL_COLOR_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
- { GL_INDEX_ARRAY, ARRAY_BOOL(Index.Enabled), NO_EXTRA },
- { GL_INDEX_ARRAY_TYPE, ARRAY_ENUM(Index.Type), NO_EXTRA },
- { GL_INDEX_ARRAY_STRIDE, ARRAY_INT(Index.Stride), NO_EXTRA },
- { GL_INDEX_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
- { GL_TEXTURE_COORD_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
- { GL_EDGE_FLAG_ARRAY, ARRAY_BOOL(EdgeFlag.Enabled), NO_EXTRA },
- { GL_EDGE_FLAG_ARRAY_STRIDE, ARRAY_INT(EdgeFlag.Stride), NO_EXTRA },
- { GL_EDGE_FLAG_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
-
- /* GL_ARB_texture_compression */
- { GL_TEXTURE_COMPRESSION_HINT_ARB, CONTEXT_INT(Hint.TextureCompression), NO_EXTRA },
-
- /* GL_EXT_compiled_vertex_array */
- { GL_ARRAY_ELEMENT_LOCK_FIRST_EXT, CONTEXT_INT(Array.LockFirst),
- extra_EXT_compiled_vertex_array },
- { GL_ARRAY_ELEMENT_LOCK_COUNT_EXT, CONTEXT_INT(Array.LockCount),
- extra_EXT_compiled_vertex_array },
-
- /* GL_ARB_transpose_matrix */
- { GL_TRANSPOSE_MODELVIEW_MATRIX_ARB,
- CONTEXT_MATRIX_T(ModelviewMatrixStack), NO_EXTRA },
- { GL_TRANSPOSE_PROJECTION_MATRIX_ARB,
- CONTEXT_MATRIX_T(ProjectionMatrixStack.Top), NO_EXTRA },
- { GL_TRANSPOSE_TEXTURE_MATRIX_ARB, CONTEXT_MATRIX_T(TextureMatrixStack), NO_EXTRA },
-
- /* GL_EXT_secondary_color */
- { GL_COLOR_SUM_EXT, CONTEXT_BOOL(Fog.ColorSumEnabled),
- extra_EXT_secondary_color_ARB_vertex_program },
- { GL_CURRENT_SECONDARY_COLOR_EXT,
- CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_COLOR1][0], TYPE_FLOATN_4),
- extra_EXT_secondary_color_flush_current },
- { GL_SECONDARY_COLOR_ARRAY_EXT, ARRAY_BOOL(SecondaryColor.Enabled),
- extra_EXT_secondary_color },
- { GL_SECONDARY_COLOR_ARRAY_TYPE_EXT, ARRAY_ENUM(SecondaryColor.Type),
- extra_EXT_secondary_color },
- { GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT, ARRAY_INT(SecondaryColor.Stride),
- extra_EXT_secondary_color },
- { GL_SECONDARY_COLOR_ARRAY_SIZE_EXT, ARRAY_INT(SecondaryColor.Size),
- extra_EXT_secondary_color },
-
- /* GL_EXT_fog_coord */
- { GL_CURRENT_FOG_COORDINATE_EXT,
- CONTEXT_FLOAT(Current.Attrib[VERT_ATTRIB_FOG][0]),
- extra_EXT_fog_coord_flush_current },
- { GL_FOG_COORDINATE_ARRAY_EXT, ARRAY_BOOL(FogCoord.Enabled),
- extra_EXT_fog_coord },
- { GL_FOG_COORDINATE_ARRAY_TYPE_EXT, ARRAY_ENUM(FogCoord.Type),
- extra_EXT_fog_coord },
- { GL_FOG_COORDINATE_ARRAY_STRIDE_EXT, ARRAY_INT(FogCoord.Stride),
- extra_EXT_fog_coord },
- { GL_FOG_COORDINATE_SOURCE_EXT, CONTEXT_ENUM(Fog.FogCoordinateSource),
- extra_EXT_fog_coord },
-
- /* GL_IBM_rasterpos_clip */
- { GL_RASTER_POSITION_UNCLIPPED_IBM,
- CONTEXT_BOOL(Transform.RasterPositionUnclipped),
- extra_IBM_rasterpos_clip },
-
- /* GL_NV_point_sprite */
- { GL_POINT_SPRITE_R_MODE_NV,
- CONTEXT_ENUM(Point.SpriteRMode), extra_NV_point_sprite },
- { GL_POINT_SPRITE_COORD_ORIGIN, CONTEXT_ENUM(Point.SpriteOrigin),
- extra_NV_point_sprite_ARB_point_sprite },
-
- /* GL_NV_vertex_program */
- { GL_VERTEX_PROGRAM_BINDING_NV, LOC_CUSTOM, TYPE_INT, 0,
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY0_NV, ARRAY_BOOL(VertexAttrib[0].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY1_NV, ARRAY_BOOL(VertexAttrib[1].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY2_NV, ARRAY_BOOL(VertexAttrib[2].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY3_NV, ARRAY_BOOL(VertexAttrib[3].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY4_NV, ARRAY_BOOL(VertexAttrib[4].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY5_NV, ARRAY_BOOL(VertexAttrib[5].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY6_NV, ARRAY_BOOL(VertexAttrib[6].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY7_NV, ARRAY_BOOL(VertexAttrib[7].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY8_NV, ARRAY_BOOL(VertexAttrib[8].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY9_NV, ARRAY_BOOL(VertexAttrib[9].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY10_NV, ARRAY_BOOL(VertexAttrib[10].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY11_NV, ARRAY_BOOL(VertexAttrib[11].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY12_NV, ARRAY_BOOL(VertexAttrib[12].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY13_NV, ARRAY_BOOL(VertexAttrib[13].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY14_NV, ARRAY_BOOL(VertexAttrib[14].Enabled),
- extra_NV_vertex_program },
- { GL_VERTEX_ATTRIB_ARRAY15_NV, ARRAY_BOOL(VertexAttrib[15].Enabled),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB0_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[0]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB1_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[1]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB2_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[2]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB3_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[3]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB4_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[4]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB5_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[5]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB6_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[6]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB7_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[7]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB8_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[8]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB9_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[9]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB10_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[10]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB11_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[11]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB12_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[12]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB13_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[13]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB14_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[14]),
- extra_NV_vertex_program },
- { GL_MAP1_VERTEX_ATTRIB15_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[15]),
- extra_NV_vertex_program },
-
- /* GL_NV_fragment_program */
- { GL_FRAGMENT_PROGRAM_NV, CONTEXT_BOOL(FragmentProgram.Enabled),
- extra_NV_fragment_program },
- { GL_FRAGMENT_PROGRAM_BINDING_NV, LOC_CUSTOM, TYPE_INT, 0,
- extra_NV_fragment_program },
- { GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV,
- CONST(MAX_NV_FRAGMENT_PROGRAM_PARAMS),
- extra_NV_fragment_program },
-
- /* GL_NV_texture_rectangle */
- { GL_TEXTURE_RECTANGLE_NV,
- LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_NV_texture_rectangle },
- { GL_TEXTURE_BINDING_RECTANGLE_NV,
- LOC_CUSTOM, TYPE_INT, TEXTURE_RECT_INDEX, extra_NV_texture_rectangle },
- { GL_MAX_RECTANGLE_TEXTURE_SIZE_NV,
- CONTEXT_INT(Const.MaxTextureRectSize), extra_NV_texture_rectangle },
-
- /* GL_EXT_stencil_two_side */
- { GL_STENCIL_TEST_TWO_SIDE_EXT, CONTEXT_BOOL(Stencil.TestTwoSide),
- extra_EXT_stencil_two_side },
- { GL_ACTIVE_STENCIL_FACE_EXT, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
-
- /* GL_NV_light_max_exponent */
- { GL_MAX_SHININESS_NV, CONTEXT_FLOAT(Const.MaxShininess),
- extra_NV_light_max_exponent },
- { GL_MAX_SPOT_EXPONENT_NV, CONTEXT_FLOAT(Const.MaxSpotExponent),
- extra_NV_light_max_exponent },
-
- /* GL_NV_primitive_restart */
- { GL_PRIMITIVE_RESTART_NV, CONTEXT_BOOL(Array.PrimitiveRestart),
- extra_NV_primitive_restart },
- { GL_PRIMITIVE_RESTART_INDEX_NV, CONTEXT_INT(Array.RestartIndex),
- extra_NV_primitive_restart },
-
- /* GL_ARB_vertex_buffer_object */
- { GL_INDEX_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_array_object, Index.BufferObj), NO_EXTRA },
- { GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_array_object, EdgeFlag.BufferObj), NO_EXTRA },
- { GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_array_object, SecondaryColor.BufferObj), NO_EXTRA },
- { GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
- offsetof(struct gl_array_object, FogCoord.BufferObj), NO_EXTRA },
-
- /* GL_EXT_pixel_buffer_object */
- { GL_PIXEL_PACK_BUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
- extra_EXT_pixel_buffer_object },
- { GL_PIXEL_UNPACK_BUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
- extra_EXT_pixel_buffer_object },
-
- /* GL_ARB_vertex_program */
- { GL_VERTEX_PROGRAM_ARB, /* == GL_VERTEX_PROGRAM_NV */
- CONTEXT_BOOL(VertexProgram.Enabled),
- extra_ARB_vertex_program_NV_vertex_program },
- { GL_VERTEX_PROGRAM_POINT_SIZE_ARB, /* == GL_VERTEX_PROGRAM_POINT_SIZE_NV*/
- CONTEXT_BOOL(VertexProgram.PointSizeEnabled),
- extra_ARB_vertex_program_NV_vertex_program },
- { GL_VERTEX_PROGRAM_TWO_SIDE_ARB, /* == GL_VERTEX_PROGRAM_TWO_SIDE_NV */
- CONTEXT_BOOL(VertexProgram.TwoSideEnabled),
- extra_ARB_vertex_program_NV_vertex_program },
- { GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB, /* == GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV */
- CONTEXT_INT(Const.MaxProgramMatrixStackDepth),
- extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
- { GL_MAX_PROGRAM_MATRICES_ARB, /* == GL_MAX_TRACK_MATRICES_NV */
- CONTEXT_INT(Const.MaxProgramMatrices),
- extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
- { GL_CURRENT_MATRIX_STACK_DEPTH_ARB, /* == GL_CURRENT_MATRIX_STACK_DEPTH_NV */
- LOC_CUSTOM, TYPE_INT, 0,
- extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
-
- { GL_CURRENT_MATRIX_ARB, /* == GL_CURRENT_MATRIX_NV */
- LOC_CUSTOM, TYPE_MATRIX, 0,
- extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
- { GL_TRANSPOSE_CURRENT_MATRIX_ARB, /* == GL_CURRENT_MATRIX_NV */
- LOC_CUSTOM, TYPE_MATRIX, 0,
- extra_ARB_vertex_program_ARB_fragment_program },
-
- { GL_PROGRAM_ERROR_POSITION_ARB, /* == GL_PROGRAM_ERROR_POSITION_NV */
- CONTEXT_INT(Program.ErrorPos),
- extra_NV_vertex_program_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
-
- /* GL_ARB_fragment_program */
- { GL_FRAGMENT_PROGRAM_ARB, CONTEXT_BOOL(FragmentProgram.Enabled),
- extra_ARB_fragment_program },
-
- /* GL_EXT_depth_bounds_test */
- { GL_DEPTH_BOUNDS_TEST_EXT, CONTEXT_BOOL(Depth.BoundsTest),
- extra_EXT_depth_bounds_test },
- { GL_DEPTH_BOUNDS_EXT, CONTEXT_FLOAT2(Depth.BoundsMin),
- extra_EXT_depth_bounds_test },
-
- /* GL_ARB_depth_clamp*/
- { GL_DEPTH_CLAMP, CONTEXT_BOOL(Transform.DepthClamp),
- extra_ARB_depth_clamp },
-
- /* GL_ARB_draw_buffers */
- { GL_DRAW_BUFFER0_ARB, BUFFER_ENUM(ColorDrawBuffer[0]), NO_EXTRA },
- { GL_DRAW_BUFFER1_ARB, BUFFER_ENUM(ColorDrawBuffer[1]),
- extra_valid_draw_buffer },
- { GL_DRAW_BUFFER2_ARB, BUFFER_ENUM(ColorDrawBuffer[2]),
- extra_valid_draw_buffer },
- { GL_DRAW_BUFFER3_ARB, BUFFER_ENUM(ColorDrawBuffer[3]),
- extra_valid_draw_buffer },
- { GL_DRAW_BUFFER4_ARB, BUFFER_ENUM(ColorDrawBuffer[4]),
- extra_valid_draw_buffer },
- { GL_DRAW_BUFFER5_ARB, BUFFER_ENUM(ColorDrawBuffer[5]),
- extra_valid_draw_buffer },
- { GL_DRAW_BUFFER6_ARB, BUFFER_ENUM(ColorDrawBuffer[6]),
- extra_valid_draw_buffer },
- { GL_DRAW_BUFFER7_ARB, BUFFER_ENUM(ColorDrawBuffer[7]),
- extra_valid_draw_buffer },
-
- /* GL_ATI_fragment_shader */
- { GL_NUM_FRAGMENT_REGISTERS_ATI, CONST(6), extra_ATI_fragment_shader },
- { GL_NUM_FRAGMENT_CONSTANTS_ATI, CONST(8), extra_ATI_fragment_shader },
- { GL_NUM_PASSES_ATI, CONST(2), extra_ATI_fragment_shader },
- { GL_NUM_INSTRUCTIONS_PER_PASS_ATI, CONST(8), extra_ATI_fragment_shader },
- { GL_NUM_INSTRUCTIONS_TOTAL_ATI, CONST(16), extra_ATI_fragment_shader },
- { GL_COLOR_ALPHA_PAIRING_ATI, CONST(GL_TRUE), extra_ATI_fragment_shader },
- { GL_NUM_LOOPBACK_COMPONENTS_ATI, CONST(3), extra_ATI_fragment_shader },
- { GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI,
- CONST(3), extra_ATI_fragment_shader },
-
- /* GL_EXT_framebuffer_object */
- { GL_MAX_COLOR_ATTACHMENTS_EXT, CONTEXT_INT(Const.MaxColorAttachments),
- extra_EXT_framebuffer_object },
-
- /* GL_EXT_framebuffer_blit
- * NOTE: GL_DRAW_FRAMEBUFFER_BINDING_EXT == GL_FRAMEBUFFER_BINDING_EXT */
- { GL_READ_FRAMEBUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
- extra_EXT_framebuffer_blit },
-
- /* GL_EXT_provoking_vertex */
- { GL_PROVOKING_VERTEX_EXT,
- CONTEXT_BOOL(Light.ProvokingVertex), extra_EXT_provoking_vertex },
- { GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT,
- CONTEXT_BOOL(Const.QuadsFollowProvokingVertexConvention),
- extra_EXT_provoking_vertex },
-
- /* GL_ARB_framebuffer_object */
- { GL_MAX_SAMPLES, CONTEXT_INT(Const.MaxSamples),
- extra_ARB_framebuffer_object_EXT_framebuffer_multisample },
-
- /* GL_APPLE_vertex_array_object */
- { GL_VERTEX_ARRAY_BINDING_APPLE, ARRAY_INT(Name),
- extra_APPLE_vertex_array_object },
-
- /* GL_ARB_seamless_cube_map */
- { GL_TEXTURE_CUBE_MAP_SEAMLESS,
- CONTEXT_BOOL(Texture.CubeMapSeamless), extra_ARB_seamless_cube_map },
-
- /* GL_ARB_sync */
- { GL_MAX_SERVER_WAIT_TIMEOUT,
- CONTEXT_INT64(Const.MaxServerWaitTimeout), extra_ARB_sync },
-
- /* GL_EXT_texture_integer */
- { GL_RGBA_INTEGER_MODE_EXT, BUFFER_BOOL(_IntegerColor),
- extra_EXT_texture_integer },
-
- /* GL_EXT_transform_feedback */
- { GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, LOC_CUSTOM, TYPE_INT, 0,
- extra_EXT_transform_feedback },
- { GL_RASTERIZER_DISCARD, CONTEXT_BOOL(TransformFeedback.RasterDiscard),
- extra_EXT_transform_feedback },
- { GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS,
- CONTEXT_INT(Const.MaxTransformFeedbackInterleavedComponents),
- extra_EXT_transform_feedback },
- { GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
- CONTEXT_INT(Const.MaxTransformFeedbackSeparateAttribs),
- extra_EXT_transform_feedback },
- { GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS,
- CONTEXT_INT(Const.MaxTransformFeedbackSeparateComponents),
- extra_EXT_transform_feedback },
-
- /* GL_ARB_transform_feedback2 */
- { GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED, LOC_CUSTOM, TYPE_BOOLEAN, 0,
- extra_ARB_transform_feedback2 },
- { GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE, LOC_CUSTOM, TYPE_BOOLEAN, 0,
- extra_ARB_transform_feedback2 },
- { GL_TRANSFORM_FEEDBACK_BINDING, LOC_CUSTOM, TYPE_INT, 0,
- extra_ARB_transform_feedback2 },
-
- /* GL_ARB_geometry_shader4 */
- { GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB,
- CONTEXT_INT(Const.GeometryProgram.MaxGeometryTextureImageUnits),
- extra_ARB_geometry_shader4 },
- { GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB,
- CONTEXT_INT(Const.GeometryProgram.MaxGeometryOutputVertices),
- extra_ARB_geometry_shader4 },
- { GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB,
- CONTEXT_INT(Const.GeometryProgram.MaxGeometryTotalOutputComponents),
- extra_ARB_geometry_shader4 },
- { GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB,
- CONTEXT_INT(Const.GeometryProgram.MaxGeometryUniformComponents),
- extra_ARB_geometry_shader4 },
- { GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB,
- CONTEXT_INT(Const.GeometryProgram.MaxGeometryVaryingComponents),
- extra_ARB_geometry_shader4 },
- { GL_MAX_VERTEX_VARYING_COMPONENTS_ARB,
- CONTEXT_INT(Const.GeometryProgram.MaxVertexVaryingComponents),
- extra_ARB_geometry_shader4 },
-
- /* GL_EXT_gpu_shader4 / GL 3.0 */
- { GL_MIN_PROGRAM_TEXEL_OFFSET,
- CONTEXT_INT(Const.MinProgramTexelOffset),
- extra_EXT_gpu_shader4 },
- { GL_MAX_PROGRAM_TEXEL_OFFSET,
- CONTEXT_INT(Const.MaxProgramTexelOffset),
- extra_EXT_gpu_shader4 },
-
- /* GL 3.0 */
- { GL_NUM_EXTENSIONS, LOC_CUSTOM, TYPE_INT, 0, extra_version_30 },
- { GL_MAJOR_VERSION, CONTEXT_INT(VersionMajor), extra_version_30 },
- { GL_MINOR_VERSION, CONTEXT_INT(VersionMinor), extra_version_30 },
- { GL_CONTEXT_FLAGS, CONTEXT_INT(Const.ContextFlags), extra_version_30 },
-
- /* GL3.0 / GL_EXT_framebuffer_sRGB */
- { GL_FRAMEBUFFER_SRGB_EXT, CONTEXT_BOOL(Color.sRGBEnabled), extra_EXT_framebuffer_sRGB },
- { GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, BUFFER_INT(Visual.sRGBCapable), extra_EXT_framebuffer_sRGB },
-
- /* GL 3.1 */
- /* NOTE: different enum values for GL_PRIMITIVE_RESTART_NV
- * vs. GL_PRIMITIVE_RESTART!
- */
- { GL_PRIMITIVE_RESTART, CONTEXT_BOOL(Array.PrimitiveRestart),
- extra_version_31 },
- { GL_PRIMITIVE_RESTART_INDEX, CONTEXT_INT(Array.RestartIndex),
- extra_version_31 },
-
-
- /* GL 3.2 */
- { GL_CONTEXT_PROFILE_MASK, CONTEXT_INT(Const.ProfileMask),
- extra_version_32 },
-#endif /* FEATURE_GL */
-};
-
-/* All we need now is a way to look up the value struct from the enum.
- * The code generated by gcc for the old generated big switch
- * statement is a big, balanced, open coded if/else tree, essentially
- * an unrolled binary search. It would be natural to sort the new
- * enum table and use bsearch(), but we will use a read-only hash
- * table instead. bsearch() has a nice guaranteed worst case
- * performance, but we're also guaranteed to hit that worst case
- * (log2(n) iterations) for about half the enums. Instead, using an
- * open addressing hash table, we can find the enum on the first try
- * for 80% of the enums, 1 collision for 10% and never more than 5
- * collisions for any enum (typical numbers). And the code is very
- * simple, even though it feels a little magic. */
-
-static unsigned short table[1024];
-static const int prime_factor = 89, prime_step = 281;
-
-#ifdef GET_DEBUG
-static void
-print_table_stats(void)
-{
- int i, j, collisions[11], count, hash, mask;
- const struct value_desc *d;
-
- count = 0;
- mask = Elements(table) - 1;
- memset(collisions, 0, sizeof collisions);
-
- for (i = 0; i < Elements(table); i++) {
- if (!table[i])
- continue;
- count++;
- d = &values[table[i]];
- hash = (d->pname * prime_factor);
- j = 0;
- while (1) {
- if (values[table[hash & mask]].pname == d->pname)
- break;
- hash += prime_step;
- j++;
- }
-
- if (j < 10)
- collisions[j]++;
- else
- collisions[10]++;
- }
-
- printf("number of enums: %d (total %d)\n", count, Elements(values));
- for (i = 0; i < Elements(collisions) - 1; i++)
- if (collisions[i] > 0)
- printf(" %d enums with %d %scollisions\n",
- collisions[i], i, i == 10 ? "or more " : "");
-}
-#endif
-
-/**
- * Initialize the enum hash for a given API
- *
- * This is called from one_time_init() to insert the enum values that
- * are valid for the API in question into the enum hash table.
- *
- * \param the current context, for determining the API in question
- */
-void _mesa_init_get_hash(struct gl_context *ctx)
-{
- int i, hash, index, mask;
- int api_mask = 0, api_bit;
-
- mask = Elements(table) - 1;
- api_bit = 1 << ctx->API;
-
- for (i = 0; i < Elements(values); i++) {
- if (values[i].type == TYPE_API_MASK) {
- api_mask = values[i].offset;
- continue;
- }
- if (!(api_mask & api_bit))
- continue;
-
- hash = (values[i].pname * prime_factor) & mask;
- while (1) {
- index = hash & mask;
- if (!table[index]) {
- table[index] = i;
- break;
- }
- hash += prime_step;
- }
- }
-
-#ifdef GET_DEBUG
- print_table_stats();
-#endif
-}
-
-/**
- * Handle irregular enums
- *
- * Some values don't conform to the "well-known type at context
- * pointer + offset" pattern, so we have this function to catch all
- * the corner cases. Typically, it's a computed value or a one-off
- * pointer to a custom struct or something.
- *
- * In this case we can't return a pointer to the value, so we'll have
- * to use the temporary variable 'v' declared back in the calling
- * glGet*v() function to store the result.
- *
- * \param ctx the current context
- * \param d the struct value_desc that describes the enum
- * \param v pointer to the tmp declared in the calling glGet*v() function
- */
-static void
-find_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
-{
- struct gl_buffer_object *buffer_obj;
- struct gl_client_array *array;
- GLuint unit, *p;
-
- switch (d->pname) {
- case GL_TEXTURE_1D:
- case GL_TEXTURE_2D:
- case GL_TEXTURE_3D:
- case GL_TEXTURE_1D_ARRAY_EXT:
- case GL_TEXTURE_2D_ARRAY_EXT:
- case GL_TEXTURE_CUBE_MAP_ARB:
- case GL_TEXTURE_RECTANGLE_NV:
- v->value_bool = _mesa_IsEnabled(d->pname);
- break;
-
- case GL_LINE_STIPPLE_PATTERN:
- /* This is the only GLushort, special case it here by promoting
- * to an int rather than introducing a new type. */
- v->value_int = ctx->Line.StipplePattern;
- break;
-
- case GL_CURRENT_RASTER_TEXTURE_COORDS:
- unit = ctx->Texture.CurrentUnit;
- v->value_float_4[0] = ctx->Current.RasterTexCoords[unit][0];
- v->value_float_4[1] = ctx->Current.RasterTexCoords[unit][1];
- v->value_float_4[2] = ctx->Current.RasterTexCoords[unit][2];
- v->value_float_4[3] = ctx->Current.RasterTexCoords[unit][3];
- break;
-
- case GL_CURRENT_TEXTURE_COORDS:
- unit = ctx->Texture.CurrentUnit;
- v->value_float_4[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0];
- v->value_float_4[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1];
- v->value_float_4[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2];
- v->value_float_4[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3];
- break;
-
- case GL_COLOR_WRITEMASK:
- v->value_int_4[0] = ctx->Color.ColorMask[0][RCOMP] ? 1 : 0;
- v->value_int_4[1] = ctx->Color.ColorMask[0][GCOMP] ? 1 : 0;
- v->value_int_4[2] = ctx->Color.ColorMask[0][BCOMP] ? 1 : 0;
- v->value_int_4[3] = ctx->Color.ColorMask[0][ACOMP] ? 1 : 0;
- break;
-
- case GL_EDGE_FLAG:
- v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0;
- break;
-
- case GL_READ_BUFFER:
- v->value_enum = ctx->ReadBuffer->ColorReadBuffer;
- break;
-
- case GL_MAP2_GRID_DOMAIN:
- v->value_float_4[0] = ctx->Eval.MapGrid2u1;
- v->value_float_4[1] = ctx->Eval.MapGrid2u2;
- v->value_float_4[2] = ctx->Eval.MapGrid2v1;
- v->value_float_4[3] = ctx->Eval.MapGrid2v2;
- break;
-
- case GL_TEXTURE_STACK_DEPTH:
- unit = ctx->Texture.CurrentUnit;
- v->value_int = ctx->TextureMatrixStack[unit].Depth + 1;
- break;
- case GL_TEXTURE_MATRIX:
- unit = ctx->Texture.CurrentUnit;
- v->value_matrix = ctx->TextureMatrixStack[unit].Top;
- break;
-
- case GL_TEXTURE_COORD_ARRAY:
- case GL_TEXTURE_COORD_ARRAY_SIZE:
- case GL_TEXTURE_COORD_ARRAY_TYPE:
- case GL_TEXTURE_COORD_ARRAY_STRIDE:
- array = &ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture];
- v->value_int = *(GLuint *) ((char *) array + d->offset);
- break;
-
- case GL_ACTIVE_TEXTURE_ARB:
- v->value_int = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
- break;
- case GL_CLIENT_ACTIVE_TEXTURE_ARB:
- v->value_int = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
- break;
-
- case GL_MODELVIEW_STACK_DEPTH:
- case GL_PROJECTION_STACK_DEPTH:
- v->value_int = *(GLint *) ((char *) ctx + d->offset) + 1;
- break;
-
- case GL_MAX_TEXTURE_SIZE:
- case GL_MAX_3D_TEXTURE_SIZE:
- case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
- p = (GLuint *) ((char *) ctx + d->offset);
- v->value_int = 1 << (*p - 1);
- break;
-
- case GL_SCISSOR_BOX:
- v->value_int_4[0] = ctx->Scissor.X;
- v->value_int_4[1] = ctx->Scissor.Y;
- v->value_int_4[2] = ctx->Scissor.Width;
- v->value_int_4[3] = ctx->Scissor.Height;
- break;
-
- case GL_LIST_INDEX:
- v->value_int =
- ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0;
- break;
- case GL_LIST_MODE:
- if (!ctx->CompileFlag)
- v->value_enum = 0;
- else if (ctx->ExecuteFlag)
- v->value_enum = GL_COMPILE_AND_EXECUTE;
- else
- v->value_enum = GL_COMPILE;
- break;
-
- case GL_VIEWPORT:
- v->value_int_4[0] = ctx->Viewport.X;
- v->value_int_4[1] = ctx->Viewport.Y;
- v->value_int_4[2] = ctx->Viewport.Width;
- v->value_int_4[3] = ctx->Viewport.Height;
- break;
-
- case GL_ACTIVE_STENCIL_FACE_EXT:
- v->value_enum = ctx->Stencil.ActiveFace ? GL_BACK : GL_FRONT;
- break;
-
- case GL_STENCIL_FAIL:
- v->value_enum = ctx->Stencil.FailFunc[ctx->Stencil.ActiveFace];
- break;
- case GL_STENCIL_FUNC:
- v->value_enum = ctx->Stencil.Function[ctx->Stencil.ActiveFace];
- break;
- case GL_STENCIL_PASS_DEPTH_FAIL:
- v->value_enum = ctx->Stencil.ZFailFunc[ctx->Stencil.ActiveFace];
- break;
- case GL_STENCIL_PASS_DEPTH_PASS:
- v->value_enum = ctx->Stencil.ZPassFunc[ctx->Stencil.ActiveFace];
- break;
- case GL_STENCIL_REF:
- v->value_int = ctx->Stencil.Ref[ctx->Stencil.ActiveFace];
- break;
- case GL_STENCIL_VALUE_MASK:
- v->value_int = ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace];
- break;
- case GL_STENCIL_WRITEMASK:
- v->value_int = ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace];
- break;
-
- case GL_NUM_EXTENSIONS:
- v->value_int = _mesa_get_extension_count(ctx);
- break;
-
- case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
- v->value_int = _mesa_get_color_read_type(ctx);
- break;
- case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
- v->value_int = _mesa_get_color_read_format(ctx);
- break;
-
- case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
- v->value_int = ctx->CurrentStack->Depth + 1;
- break;
- case GL_CURRENT_MATRIX_ARB:
- case GL_TRANSPOSE_CURRENT_MATRIX_ARB:
- v->value_matrix = ctx->CurrentStack->Top;
- break;
-
- case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
- v->value_int = _mesa_get_compressed_formats(ctx, NULL, GL_FALSE);
- break;
- case GL_COMPRESSED_TEXTURE_FORMATS_ARB:
- v->value_int_n.n =
- _mesa_get_compressed_formats(ctx, v->value_int_n.ints, GL_FALSE);
- ASSERT(v->value_int_n.n <= 100);
- break;
-
- case GL_MAX_VARYING_FLOATS_ARB:
- v->value_int = ctx->Const.MaxVarying * 4;
- break;
-
- /* Various object names */
-
- case GL_TEXTURE_BINDING_1D:
- case GL_TEXTURE_BINDING_2D:
- case GL_TEXTURE_BINDING_3D:
- case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
- case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
- case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
- case GL_TEXTURE_BINDING_RECTANGLE_NV:
- unit = ctx->Texture.CurrentUnit;
- v->value_int =
- ctx->Texture.Unit[unit].CurrentTex[d->offset]->Name;
- break;
-
- /* GL_ARB_vertex_buffer_object */
- case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
- case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
- case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
- case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
- case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
- case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
- case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
- buffer_obj = (struct gl_buffer_object *)
- ((char *) ctx->Array.ArrayObj + d->offset);
- v->value_int = buffer_obj->Name;
- break;
- case GL_ARRAY_BUFFER_BINDING_ARB:
- v->value_int = ctx->Array.ArrayBufferObj->Name;
- break;
- case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
- v->value_int =
- ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].BufferObj->Name;
- break;
- case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
- v->value_int = ctx->Array.ElementArrayBufferObj->Name;
- break;
-
- /* ARB_copy_buffer */
- case GL_COPY_READ_BUFFER:
- v->value_int = ctx->CopyReadBuffer->Name;
- break;
- case GL_COPY_WRITE_BUFFER:
- v->value_int = ctx->CopyWriteBuffer->Name;
- break;
-
- case GL_FRAGMENT_PROGRAM_BINDING_NV:
- v->value_int =
- ctx->FragmentProgram.Current ? ctx->FragmentProgram.Current->Base.Id : 0;
- break;
- case GL_VERTEX_PROGRAM_BINDING_NV:
- v->value_int =
- ctx->VertexProgram.Current ? ctx->VertexProgram.Current->Base.Id : 0;
- break;
- case GL_PIXEL_PACK_BUFFER_BINDING_EXT:
- v->value_int = ctx->Pack.BufferObj->Name;
- break;
- case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT:
- v->value_int = ctx->Unpack.BufferObj->Name;
- break;
- case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
- v->value_int = ctx->TransformFeedback.CurrentBuffer->Name;
- break;
- case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED:
- v->value_int = ctx->TransformFeedback.CurrentObject->Paused;
- break;
- case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE:
- v->value_int = ctx->TransformFeedback.CurrentObject->Active;
- break;
- case GL_TRANSFORM_FEEDBACK_BINDING:
- v->value_int = ctx->TransformFeedback.CurrentObject->Name;
- break;
- case GL_CURRENT_PROGRAM:
- v->value_int =
- ctx->Shader.ActiveProgram ? ctx->Shader.ActiveProgram->Name : 0;
- break;
- case GL_READ_FRAMEBUFFER_BINDING_EXT:
- v->value_int = ctx->ReadBuffer->Name;
- break;
- case GL_RENDERBUFFER_BINDING_EXT:
- v->value_int =
- ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
- break;
- case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
- v->value_int = ctx->Array.ArrayObj->PointSize.BufferObj->Name;
- break;
-
- case GL_MAX_VERTEX_UNIFORM_VECTORS:
- v->value_int = ctx->Const.VertexProgram.MaxUniformComponents / 4;
- break;
-
- case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
- v->value_int = ctx->Const.FragmentProgram.MaxUniformComponents / 4;
- break;
- }
-}
-
-/**
- * Check extra constraints on a struct value_desc descriptor
- *
- * If a struct value_desc has a non-NULL extra pointer, it means that
- * there are a number of extra constraints to check or actions to
- * perform. The extras is just an integer array where each integer
- * encode different constraints or actions.
- *
- * \param ctx current context
- * \param func name of calling glGet*v() function for error reporting
- * \param d the struct value_desc that has the extra constraints
- *
- * \return GL_FALSE if one of the constraints was not satisfied,
- * otherwise GL_TRUE.
- */
-static GLboolean
-check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d)
-{
- const GLuint version = ctx->VersionMajor * 10 + ctx->VersionMinor;
- int total, enabled;
- const int *e;
-
- total = 0;
- enabled = 0;
- for (e = d->extra; *e != EXTRA_END; e++)
- switch (*e) {
- case EXTRA_VERSION_30:
- if (version >= 30) {
- total++;
- enabled++;
- }
- break;
- case EXTRA_VERSION_31:
- if (version >= 31) {
- total++;
- enabled++;
- }
- break;
- case EXTRA_VERSION_32:
- if (version >= 32) {
- total++;
- enabled++;
- }
- break;
- case EXTRA_VERSION_ES2:
- if (ctx->API == API_OPENGLES2) {
- total++;
- enabled++;
- }
- break;
- case EXTRA_NEW_BUFFERS:
- if (ctx->NewState & _NEW_BUFFERS)
- _mesa_update_state(ctx);
- break;
- case EXTRA_FLUSH_CURRENT:
- FLUSH_CURRENT(ctx, 0);
- break;
- case EXTRA_VALID_DRAW_BUFFER:
- if (d->pname - GL_DRAW_BUFFER0_ARB >= ctx->Const.MaxDrawBuffers) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s(draw buffer %u)",
- func, d->pname - GL_DRAW_BUFFER0_ARB);
- return GL_FALSE;
- }
- break;
- case EXTRA_VALID_TEXTURE_UNIT:
- if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture %u)",
- func, ctx->Texture.CurrentUnit);
- return GL_FALSE;
- }
- break;
- case EXTRA_END:
- break;
- default: /* *e is a offset into the extension struct */
- total++;
- if (*(GLboolean *) ((char *) &ctx->Extensions + *e))
- enabled++;
- break;
- }
-
- if (total > 0 && enabled == 0) {
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
- _mesa_lookup_enum_by_nr(d->pname));
- return GL_FALSE;
- }
-
- return GL_TRUE;
-}
-
-static const struct value_desc error_value =
- { 0, 0, TYPE_INVALID, NO_OFFSET, NO_EXTRA };
-
-/**
- * Find the struct value_desc corresponding to the enum 'pname'.
- *
- * We hash the enum value to get an index into the 'table' array,
- * which holds the index in the 'values' array of struct value_desc.
- * Once we've found the entry, we do the extra checks, if any, then
- * look up the value and return a pointer to it.
- *
- * If the value has to be computed (for example, it's the result of a
- * function call or we need to add 1 to it), we use the tmp 'v' to
- * store the result.
- *
- * \param func name of glGet*v() func for error reporting
- * \param pname the enum value we're looking up
- * \param p is were we return the pointer to the value
- * \param v a tmp union value variable in the calling glGet*v() function
- *
- * \return the struct value_desc corresponding to the enum or a struct
- * value_desc of TYPE_INVALID if not found. This lets the calling
- * glGet*v() function jump right into a switch statement and
- * handle errors there instead of having to check for NULL.
- */
-static const struct value_desc *
-find_value(const char *func, GLenum pname, void **p, union value *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_texture_unit *unit;
- int mask, hash;
- const struct value_desc *d;
-
- mask = Elements(table) - 1;
- hash = (pname * prime_factor);
- while (1) {
- d = &values[table[hash & mask]];
-
- /* If the enum isn't valid, the hash walk ends with index 0,
- * which is the API mask entry at the beginning of values[]. */
- if (unlikely(d->type == TYPE_API_MASK)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
- _mesa_lookup_enum_by_nr(pname));
- return &error_value;
- }
-
- if (likely(d->pname == pname))
- break;
-
- hash += prime_step;
- }
-
- if (unlikely(d->extra && !check_extra(ctx, func, d)))
- return &error_value;
-
- switch (d->location) {
- case LOC_BUFFER:
- *p = ((char *) ctx->DrawBuffer + d->offset);
- return d;
- case LOC_CONTEXT:
- *p = ((char *) ctx + d->offset);
- return d;
- case LOC_ARRAY:
- *p = ((char *) ctx->Array.ArrayObj + d->offset);
- return d;
- case LOC_TEXUNIT:
- unit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- *p = ((char *) unit + d->offset);
- return d;
- case LOC_CUSTOM:
- find_custom_value(ctx, d, v);
- *p = v;
- return d;
- default:
- assert(0);
- break;
- }
-
- /* silence warning */
- return &error_value;
-}
-
-static const int transpose[] = {
- 0, 4, 8, 12,
- 1, 5, 9, 13,
- 2, 6, 10, 14,
- 3, 7, 11, 15
-};
-
-void GLAPIENTRY
-_mesa_GetBooleanv(GLenum pname, GLboolean *params)
-{
- const struct value_desc *d;
- union value v;
- GLmatrix *m;
- int shift, i;
- void *p;
-
- d = find_value("glGetBooleanv", pname, &p, &v);
- switch (d->type) {
- case TYPE_INVALID:
- break;
- case TYPE_CONST:
- params[0] = INT_TO_BOOLEAN(d->offset);
- break;
-
- case TYPE_FLOAT_4:
- case TYPE_FLOATN_4:
- params[3] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[3]);
- case TYPE_FLOAT_3:
- case TYPE_FLOATN_3:
- params[2] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[2]);
- case TYPE_FLOAT_2:
- case TYPE_FLOATN_2:
- params[1] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[1]);
- case TYPE_FLOAT:
- case TYPE_FLOATN:
- params[0] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[0]);
- break;
-
- case TYPE_DOUBLEN:
- params[0] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[0]);
- break;
-
- case TYPE_INT_4:
- params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
- case TYPE_INT_3:
- params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
- case TYPE_INT_2:
- case TYPE_ENUM_2:
- params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
- case TYPE_INT:
- case TYPE_ENUM:
- params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
- break;
-
- case TYPE_INT_N:
- for (i = 0; i < v.value_int_n.n; i++)
- params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
- break;
-
- case TYPE_INT64:
- params[0] = INT64_TO_BOOLEAN(((GLint64 *) p)[0]);
- break;
-
- case TYPE_BOOLEAN:
- params[0] = ((GLboolean*) p)[0];
- break;
-
- case TYPE_MATRIX:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = FLOAT_TO_BOOLEAN(m->m[i]);
- break;
-
- case TYPE_MATRIX_T:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = FLOAT_TO_BOOLEAN(m->m[transpose[i]]);
- break;
-
- case TYPE_BIT_0:
- case TYPE_BIT_1:
- case TYPE_BIT_2:
- case TYPE_BIT_3:
- case TYPE_BIT_4:
- case TYPE_BIT_5:
- shift = d->type - TYPE_BIT_0;
- params[0] = (*(GLbitfield *) p >> shift) & 1;
- break;
- }
-}
-
-void GLAPIENTRY
-_mesa_GetFloatv(GLenum pname, GLfloat *params)
-{
- const struct value_desc *d;
- union value v;
- GLmatrix *m;
- int shift, i;
- void *p;
-
- d = find_value("glGetFloatv", pname, &p, &v);
- switch (d->type) {
- case TYPE_INVALID:
- break;
- case TYPE_CONST:
- params[0] = (GLfloat) d->offset;
- break;
-
- case TYPE_FLOAT_4:
- case TYPE_FLOATN_4:
- params[3] = ((GLfloat *) p)[3];
- case TYPE_FLOAT_3:
- case TYPE_FLOATN_3:
- params[2] = ((GLfloat *) p)[2];
- case TYPE_FLOAT_2:
- case TYPE_FLOATN_2:
- params[1] = ((GLfloat *) p)[1];
- case TYPE_FLOAT:
- case TYPE_FLOATN:
- params[0] = ((GLfloat *) p)[0];
- break;
-
- case TYPE_DOUBLEN:
- params[0] = ((GLdouble *) p)[0];
- break;
-
- case TYPE_INT_4:
- params[3] = (GLfloat) (((GLint *) p)[3]);
- case TYPE_INT_3:
- params[2] = (GLfloat) (((GLint *) p)[2]);
- case TYPE_INT_2:
- case TYPE_ENUM_2:
- params[1] = (GLfloat) (((GLint *) p)[1]);
- case TYPE_INT:
- case TYPE_ENUM:
- params[0] = (GLfloat) (((GLint *) p)[0]);
- break;
-
- case TYPE_INT_N:
- for (i = 0; i < v.value_int_n.n; i++)
- params[i] = INT_TO_FLOAT(v.value_int_n.ints[i]);
- break;
-
- case TYPE_INT64:
- params[0] = ((GLint64 *) p)[0];
- break;
-
- case TYPE_BOOLEAN:
- params[0] = BOOLEAN_TO_FLOAT(*(GLboolean*) p);
- break;
-
- case TYPE_MATRIX:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = m->m[i];
- break;
-
- case TYPE_MATRIX_T:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = m->m[transpose[i]];
- break;
-
- case TYPE_BIT_0:
- case TYPE_BIT_1:
- case TYPE_BIT_2:
- case TYPE_BIT_3:
- case TYPE_BIT_4:
- case TYPE_BIT_5:
- shift = d->type - TYPE_BIT_0;
- params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);
- break;
- }
-}
-
-void GLAPIENTRY
-_mesa_GetIntegerv(GLenum pname, GLint *params)
-{
- const struct value_desc *d;
- union value v;
- GLmatrix *m;
- int shift, i;
- void *p;
-
- d = find_value("glGetIntegerv", pname, &p, &v);
- switch (d->type) {
- case TYPE_INVALID:
- break;
- case TYPE_CONST:
- params[0] = d->offset;
- break;
-
- case TYPE_FLOAT_4:
- params[3] = IROUND(((GLfloat *) p)[3]);
- case TYPE_FLOAT_3:
- params[2] = IROUND(((GLfloat *) p)[2]);
- case TYPE_FLOAT_2:
- params[1] = IROUND(((GLfloat *) p)[1]);
- case TYPE_FLOAT:
- params[0] = IROUND(((GLfloat *) p)[0]);
- break;
-
- case TYPE_FLOATN_4:
- params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
- case TYPE_FLOATN_3:
- params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
- case TYPE_FLOATN_2:
- params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
- case TYPE_FLOATN:
- params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
- break;
-
- case TYPE_DOUBLEN:
- params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
- break;
-
- case TYPE_INT_4:
- params[3] = ((GLint *) p)[3];
- case TYPE_INT_3:
- params[2] = ((GLint *) p)[2];
- case TYPE_INT_2:
- case TYPE_ENUM_2:
- params[1] = ((GLint *) p)[1];
- case TYPE_INT:
- case TYPE_ENUM:
- params[0] = ((GLint *) p)[0];
- break;
-
- case TYPE_INT_N:
- for (i = 0; i < v.value_int_n.n; i++)
- params[i] = v.value_int_n.ints[i];
- break;
-
- case TYPE_INT64:
- params[0] = INT64_TO_INT(((GLint64 *) p)[0]);
- break;
-
- case TYPE_BOOLEAN:
- params[0] = BOOLEAN_TO_INT(*(GLboolean*) p);
- break;
-
- case TYPE_MATRIX:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = FLOAT_TO_INT(m->m[i]);
- break;
-
- case TYPE_MATRIX_T:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = FLOAT_TO_INT(m->m[transpose[i]]);
- break;
-
- case TYPE_BIT_0:
- case TYPE_BIT_1:
- case TYPE_BIT_2:
- case TYPE_BIT_3:
- case TYPE_BIT_4:
- case TYPE_BIT_5:
- shift = d->type - TYPE_BIT_0;
- params[0] = (*(GLbitfield *) p >> shift) & 1;
- break;
- }
-}
-
-#if FEATURE_ARB_sync
-void GLAPIENTRY
-_mesa_GetInteger64v(GLenum pname, GLint64 *params)
-{
- const struct value_desc *d;
- union value v;
- GLmatrix *m;
- int shift, i;
- void *p;
-
- d = find_value("glGetInteger64v", pname, &p, &v);
- switch (d->type) {
- case TYPE_INVALID:
- break;
- case TYPE_CONST:
- params[0] = d->offset;
- break;
-
- case TYPE_FLOAT_4:
- params[3] = IROUND64(((GLfloat *) p)[3]);
- case TYPE_FLOAT_3:
- params[2] = IROUND64(((GLfloat *) p)[2]);
- case TYPE_FLOAT_2:
- params[1] = IROUND64(((GLfloat *) p)[1]);
- case TYPE_FLOAT:
- params[0] = IROUND64(((GLfloat *) p)[0]);
- break;
-
- case TYPE_FLOATN_4:
- params[3] = FLOAT_TO_INT64(((GLfloat *) p)[3]);
- case TYPE_FLOATN_3:
- params[2] = FLOAT_TO_INT64(((GLfloat *) p)[2]);
- case TYPE_FLOATN_2:
- params[1] = FLOAT_TO_INT64(((GLfloat *) p)[1]);
- case TYPE_FLOATN:
- params[0] = FLOAT_TO_INT64(((GLfloat *) p)[0]);
- break;
-
- case TYPE_DOUBLEN:
- params[0] = FLOAT_TO_INT64(((GLdouble *) p)[0]);
- break;
-
- case TYPE_INT_4:
- params[3] = ((GLint *) p)[3];
- case TYPE_INT_3:
- params[2] = ((GLint *) p)[2];
- case TYPE_INT_2:
- case TYPE_ENUM_2:
- params[1] = ((GLint *) p)[1];
- case TYPE_INT:
- case TYPE_ENUM:
- params[0] = ((GLint *) p)[0];
- break;
-
- case TYPE_INT_N:
- for (i = 0; i < v.value_int_n.n; i++)
- params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
- break;
-
- case TYPE_INT64:
- params[0] = ((GLint64 *) p)[0];
- break;
-
- case TYPE_BOOLEAN:
- params[0] = ((GLboolean*) p)[0];
- break;
-
- case TYPE_MATRIX:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = FLOAT_TO_INT64(m->m[i]);
- break;
-
- case TYPE_MATRIX_T:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = FLOAT_TO_INT64(m->m[transpose[i]]);
- break;
-
- case TYPE_BIT_0:
- case TYPE_BIT_1:
- case TYPE_BIT_2:
- case TYPE_BIT_3:
- case TYPE_BIT_4:
- case TYPE_BIT_5:
- shift = d->type - TYPE_BIT_0;
- params[0] = (*(GLbitfield *) p >> shift) & 1;
- break;
- }
-}
-#endif /* FEATURE_ARB_sync */
-
-void GLAPIENTRY
-_mesa_GetDoublev(GLenum pname, GLdouble *params)
-{
- const struct value_desc *d;
- union value v;
- GLmatrix *m;
- int shift, i;
- void *p;
-
- d = find_value("glGetDoublev", pname, &p, &v);
- switch (d->type) {
- case TYPE_INVALID:
- break;
- case TYPE_CONST:
- params[0] = d->offset;
- break;
-
- case TYPE_FLOAT_4:
- case TYPE_FLOATN_4:
- params[3] = ((GLfloat *) p)[3];
- case TYPE_FLOAT_3:
- case TYPE_FLOATN_3:
- params[2] = ((GLfloat *) p)[2];
- case TYPE_FLOAT_2:
- case TYPE_FLOATN_2:
- params[1] = ((GLfloat *) p)[1];
- case TYPE_FLOAT:
- case TYPE_FLOATN:
- params[0] = ((GLfloat *) p)[0];
- break;
-
- case TYPE_DOUBLEN:
- params[0] = ((GLdouble *) p)[0];
- break;
-
- case TYPE_INT_4:
- params[3] = ((GLint *) p)[3];
- case TYPE_INT_3:
- params[2] = ((GLint *) p)[2];
- case TYPE_INT_2:
- case TYPE_ENUM_2:
- params[1] = ((GLint *) p)[1];
- case TYPE_INT:
- case TYPE_ENUM:
- params[0] = ((GLint *) p)[0];
- break;
-
- case TYPE_INT_N:
- for (i = 0; i < v.value_int_n.n; i++)
- params[i] = v.value_int_n.ints[i];
- break;
-
- case TYPE_INT64:
- params[0] = ((GLint64 *) p)[0];
- break;
-
- case TYPE_BOOLEAN:
- params[0] = *(GLboolean*) p;
- break;
-
- case TYPE_MATRIX:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = m->m[i];
- break;
-
- case TYPE_MATRIX_T:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = m->m[transpose[i]];
- break;
-
- case TYPE_BIT_0:
- case TYPE_BIT_1:
- case TYPE_BIT_2:
- case TYPE_BIT_3:
- case TYPE_BIT_4:
- case TYPE_BIT_5:
- shift = d->type - TYPE_BIT_0;
- params[0] = (*(GLbitfield *) p >> shift) & 1;
- break;
- }
-}
-
-static enum value_type
-find_value_indexed(const char *func, GLenum pname, int index, union value *v)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- switch (pname) {
-
- case GL_BLEND:
- if (index >= ctx->Const.MaxDrawBuffers)
- goto invalid_value;
- if (!ctx->Extensions.EXT_draw_buffers2)
- goto invalid_enum;
- v->value_int = (ctx->Color.BlendEnabled >> index) & 1;
- return TYPE_INT;
-
- case GL_BLEND_SRC:
- /* fall-through */
- case GL_BLEND_SRC_RGB:
- if (index >= ctx->Const.MaxDrawBuffers)
- goto invalid_value;
- if (!ctx->Extensions.ARB_draw_buffers_blend)
- goto invalid_enum;
- v->value_int = ctx->Color.Blend[index].SrcRGB;
- return TYPE_INT;
- case GL_BLEND_SRC_ALPHA:
- if (index >= ctx->Const.MaxDrawBuffers)
- goto invalid_value;
- if (!ctx->Extensions.ARB_draw_buffers_blend)
- goto invalid_enum;
- v->value_int = ctx->Color.Blend[index].SrcA;
- return TYPE_INT;
- case GL_BLEND_DST:
- /* fall-through */
- case GL_BLEND_DST_RGB:
- if (index >= ctx->Const.MaxDrawBuffers)
- goto invalid_value;
- if (!ctx->Extensions.ARB_draw_buffers_blend)
- goto invalid_enum;
- v->value_int = ctx->Color.Blend[index].DstRGB;
- return TYPE_INT;
- case GL_BLEND_DST_ALPHA:
- if (index >= ctx->Const.MaxDrawBuffers)
- goto invalid_value;
- if (!ctx->Extensions.ARB_draw_buffers_blend)
- goto invalid_enum;
- v->value_int = ctx->Color.Blend[index].DstA;
- return TYPE_INT;
- case GL_BLEND_EQUATION_RGB:
- if (index >= ctx->Const.MaxDrawBuffers)
- goto invalid_value;
- if (!ctx->Extensions.ARB_draw_buffers_blend)
- goto invalid_enum;
- v->value_int = ctx->Color.Blend[index].EquationRGB;
- return TYPE_INT;
- case GL_BLEND_EQUATION_ALPHA:
- if (index >= ctx->Const.MaxDrawBuffers)
- goto invalid_value;
- if (!ctx->Extensions.ARB_draw_buffers_blend)
- goto invalid_enum;
- v->value_int = ctx->Color.Blend[index].EquationA;
- return TYPE_INT;
-
- case GL_COLOR_WRITEMASK:
- if (index >= ctx->Const.MaxDrawBuffers)
- goto invalid_value;
- if (!ctx->Extensions.EXT_draw_buffers2)
- goto invalid_enum;
- v->value_int_4[0] = ctx->Color.ColorMask[index][RCOMP] ? 1 : 0;
- v->value_int_4[1] = ctx->Color.ColorMask[index][GCOMP] ? 1 : 0;
- v->value_int_4[2] = ctx->Color.ColorMask[index][BCOMP] ? 1 : 0;
- v->value_int_4[3] = ctx->Color.ColorMask[index][ACOMP] ? 1 : 0;
- return TYPE_INT_4;
-
- case GL_TRANSFORM_FEEDBACK_BUFFER_START:
- if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs)
- goto invalid_value;
- if (!ctx->Extensions.EXT_transform_feedback)
- goto invalid_enum;
- v->value_int64 = ctx->TransformFeedback.CurrentObject->Offset[index];
- return TYPE_INT64;
-
- case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
- if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs)
- goto invalid_value;
- if (!ctx->Extensions.EXT_transform_feedback)
- goto invalid_enum;
- v->value_int64 = ctx->TransformFeedback.CurrentObject->Size[index];
- return TYPE_INT64;
-
- case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
- if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs)
- goto invalid_value;
- if (!ctx->Extensions.EXT_transform_feedback)
- goto invalid_enum;
- v->value_int = ctx->TransformFeedback.CurrentObject->Buffers[index]->Name;
- return TYPE_INT;
- }
-
- invalid_enum:
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
- _mesa_lookup_enum_by_nr(pname));
- return TYPE_INVALID;
- invalid_value:
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s)", func,
- _mesa_lookup_enum_by_nr(pname));
- return TYPE_INVALID;
-}
-
-void GLAPIENTRY
-_mesa_GetBooleanIndexedv( GLenum pname, GLuint index, GLboolean *params )
-{
- union value v;
- enum value_type type =
- find_value_indexed("glGetBooleanIndexedv", pname, index, &v);
-
- switch (type) {
- case TYPE_INT:
- params[0] = INT_TO_BOOLEAN(v.value_int);
- break;
- case TYPE_INT_4:
- params[0] = INT_TO_BOOLEAN(v.value_int_4[0]);
- params[1] = INT_TO_BOOLEAN(v.value_int_4[1]);
- params[2] = INT_TO_BOOLEAN(v.value_int_4[2]);
- params[3] = INT_TO_BOOLEAN(v.value_int_4[3]);
- break;
- case TYPE_INT64:
- params[0] = INT64_TO_BOOLEAN(v.value_int);
- break;
- default:
- ; /* nothing - GL error was recorded */
- }
-}
-
-void GLAPIENTRY
-_mesa_GetIntegerIndexedv( GLenum pname, GLuint index, GLint *params )
-{
- union value v;
- enum value_type type =
- find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
-
- switch (type) {
- case TYPE_INT:
- params[0] = v.value_int;
- break;
- case TYPE_INT_4:
- params[0] = v.value_int_4[0];
- params[1] = v.value_int_4[1];
- params[2] = v.value_int_4[2];
- params[3] = v.value_int_4[3];
- break;
- case TYPE_INT64:
- params[0] = INT64_TO_INT(v.value_int);
- break;
- default:
- ; /* nothing - GL error was recorded */
- }
-}
-
-#if FEATURE_ARB_sync
-void GLAPIENTRY
-_mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params )
-{
- union value v;
- enum value_type type =
- find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
-
- switch (type) {
- case TYPE_INT:
- params[0] = v.value_int;
- break;
- case TYPE_INT_4:
- params[0] = v.value_int_4[0];
- params[1] = v.value_int_4[1];
- params[2] = v.value_int_4[2];
- params[3] = v.value_int_4[3];
- break;
- case TYPE_INT64:
- params[0] = v.value_int;
- break;
- default:
- ; /* nothing - GL error was recorded */
- }
-}
-#endif /* FEATURE_ARB_sync */
-
-#if FEATURE_ES1
-void GLAPIENTRY
-_mesa_GetFixedv(GLenum pname, GLfixed *params)
-{
- const struct value_desc *d;
- union value v;
- GLmatrix *m;
- int shift, i;
- void *p;
-
- d = find_value("glGetDoublev", pname, &p, &v);
- switch (d->type) {
- case TYPE_INVALID:
- break;
- case TYPE_CONST:
- params[0] = INT_TO_FIXED(d->offset);
- break;
-
- case TYPE_FLOAT_4:
- case TYPE_FLOATN_4:
- params[3] = FLOAT_TO_FIXED(((GLfloat *) p)[3]);
- case TYPE_FLOAT_3:
- case TYPE_FLOATN_3:
- params[2] = FLOAT_TO_FIXED(((GLfloat *) p)[2]);
- case TYPE_FLOAT_2:
- case TYPE_FLOATN_2:
- params[1] = FLOAT_TO_FIXED(((GLfloat *) p)[1]);
- case TYPE_FLOAT:
- case TYPE_FLOATN:
- params[0] = FLOAT_TO_FIXED(((GLfloat *) p)[0]);
- break;
-
- case TYPE_DOUBLEN:
- params[0] = FLOAT_TO_FIXED(((GLdouble *) p)[0]);
- break;
-
- case TYPE_INT_4:
- params[3] = INT_TO_FIXED(((GLint *) p)[3]);
- case TYPE_INT_3:
- params[2] = INT_TO_FIXED(((GLint *) p)[2]);
- case TYPE_INT_2:
- case TYPE_ENUM_2:
- params[1] = INT_TO_FIXED(((GLint *) p)[1]);
- case TYPE_INT:
- case TYPE_ENUM:
- params[0] = INT_TO_FIXED(((GLint *) p)[0]);
- break;
-
- case TYPE_INT_N:
- for (i = 0; i < v.value_int_n.n; i++)
- params[i] = INT_TO_FIXED(v.value_int_n.ints[i]);
- break;
-
- case TYPE_INT64:
- params[0] = ((GLint64 *) p)[0];
- break;
-
- case TYPE_BOOLEAN:
- params[0] = BOOLEAN_TO_FIXED(((GLboolean*) p)[0]);
- break;
-
- case TYPE_MATRIX:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = FLOAT_TO_FIXED(m->m[i]);
- break;
-
- case TYPE_MATRIX_T:
- m = *(GLmatrix **) p;
- for (i = 0; i < 16; i++)
- params[i] = FLOAT_TO_FIXED(m->m[transpose[i]]);
- break;
-
- case TYPE_BIT_0:
- case TYPE_BIT_1:
- case TYPE_BIT_2:
- case TYPE_BIT_3:
- case TYPE_BIT_4:
- case TYPE_BIT_5:
- shift = d->type - TYPE_BIT_0;
- params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);
- break;
- }
-}
-#endif
+/*
+ * Copyright (C) 2010 Brian Paul All Rights Reserved.
+ * Copyright (C) 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Kristian Høgsberg <krh@bitplanet.net>
+ */
+
+#include "glheader.h"
+#include "context.h"
+#include "enable.h"
+#include "enums.h"
+#include "extensions.h"
+#include "get.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "state.h"
+#include "texcompress.h"
+#include "framebuffer.h"
+
+/* This is a table driven implemetation of the glGet*v() functions.
+ * The basic idea is that most getters just look up an int somewhere
+ * in struct gl_context and then convert it to a bool or float according to
+ * which of glGetIntegerv() glGetBooleanv() etc is being called.
+ * Instead of generating code to do this, we can just record the enum
+ * value and the offset into struct gl_context in an array of structs. Then
+ * in glGet*(), we lookup the struct for the enum in question, and use
+ * the offset to get the int we need.
+ *
+ * Sometimes we need to look up a float, a boolean, a bit in a
+ * bitfield, a matrix or other types instead, so we need to track the
+ * type of the value in struct gl_context. And sometimes the value isn't in
+ * struct gl_context but in the drawbuffer, the array object, current texture
+ * unit, or maybe it's a computed value. So we need to also track
+ * where or how to find the value. Finally, we sometimes need to
+ * check that one of a number of extensions are enabled, the GL
+ * version or flush or call _mesa_update_state(). This is done by
+ * attaching optional extra information to the value description
+ * struct, it's sort of like an array of opcodes that describe extra
+ * checks or actions.
+ *
+ * Putting all this together we end up with struct value_desc below,
+ * and with a couple of macros to help, the table of struct value_desc
+ * is about as concise as the specification in the old python script.
+ */
+
+#undef CONST
+
+#define FLOAT_TO_BOOLEAN(X) ( (X) ? GL_TRUE : GL_FALSE )
+#define FLOAT_TO_FIXED(F) ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
+ ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
+ (GLint) ((F) * 65536.0f) )
+
+#define INT_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
+#define INT_TO_FIXED(I) ( ((I) > SHRT_MAX) ? INT_MAX : \
+ ((I) < SHRT_MIN) ? INT_MIN : \
+ (GLint) ((I) * 65536) )
+
+#define INT64_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
+#define INT64_TO_INT(I) ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
+
+#define BOOLEAN_TO_INT(B) ( (GLint) (B) )
+#define BOOLEAN_TO_INT64(B) ( (GLint64) (B) )
+#define BOOLEAN_TO_FLOAT(B) ( (B) ? 1.0F : 0.0F )
+#define BOOLEAN_TO_FIXED(B) ( (GLint) ((B) ? 1 : 0) << 16 )
+
+#define ENUM_TO_INT64(E) ( (GLint64) (E) )
+#define ENUM_TO_FIXED(E) (E)
+
+enum value_type {
+ TYPE_INVALID,
+ TYPE_API_MASK,
+ TYPE_INT,
+ TYPE_INT_2,
+ TYPE_INT_3,
+ TYPE_INT_4,
+ TYPE_INT_N,
+ TYPE_INT64,
+ TYPE_ENUM,
+ TYPE_ENUM_2,
+ TYPE_BOOLEAN,
+ TYPE_BIT_0,
+ TYPE_BIT_1,
+ TYPE_BIT_2,
+ TYPE_BIT_3,
+ TYPE_BIT_4,
+ TYPE_BIT_5,
+ TYPE_FLOAT,
+ TYPE_FLOAT_2,
+ TYPE_FLOAT_3,
+ TYPE_FLOAT_4,
+ TYPE_FLOATN,
+ TYPE_FLOATN_2,
+ TYPE_FLOATN_3,
+ TYPE_FLOATN_4,
+ TYPE_DOUBLEN,
+ TYPE_MATRIX,
+ TYPE_MATRIX_T,
+ TYPE_CONST
+};
+
+enum value_location {
+ LOC_BUFFER,
+ LOC_CONTEXT,
+ LOC_ARRAY,
+ LOC_TEXUNIT,
+ LOC_CUSTOM
+};
+
+enum value_extra {
+ EXTRA_END = 0x8000,
+ EXTRA_VERSION_30,
+ EXTRA_VERSION_31,
+ EXTRA_VERSION_32,
+ EXTRA_VERSION_ES2,
+ EXTRA_NEW_BUFFERS,
+ EXTRA_VALID_DRAW_BUFFER,
+ EXTRA_VALID_TEXTURE_UNIT,
+ EXTRA_FLUSH_CURRENT,
+};
+
+#define NO_EXTRA NULL
+#define NO_OFFSET 0
+
+struct value_desc {
+ GLenum pname;
+ GLubyte location; /**< enum value_location */
+ GLubyte type; /**< enum value_type */
+ int offset;
+ const int *extra;
+};
+
+union value {
+ GLfloat value_float;
+ GLfloat value_float_4[4];
+ GLmatrix *value_matrix;
+ GLint value_int;
+ GLint value_int_4[4];
+ GLint64 value_int64;
+ GLenum value_enum;
+
+ /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
+ struct {
+ GLint n, ints[100];
+ } value_int_n;
+ GLboolean value_bool;
+};
+
+#define BUFFER_FIELD(field, type) \
+ LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
+#define CONTEXT_FIELD(field, type) \
+ LOC_CONTEXT, type, offsetof(struct gl_context, field)
+#define ARRAY_FIELD(field, type) \
+ LOC_ARRAY, type, offsetof(struct gl_array_object, field)
+#define CONST(value) \
+ LOC_CONTEXT, TYPE_CONST, value
+
+#define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
+#define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
+#define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
+
+#define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
+#define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
+#define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
+#define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
+#define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
+#define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
+#define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
+#define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
+#define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
+#define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
+#define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
+#define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
+#define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
+#define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
+#define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
+#define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
+#define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
+#define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
+
+#define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
+#define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
+#define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
+
+#define EXT(f) \
+ offsetof(struct gl_extensions, f)
+
+#define EXTRA_EXT(e) \
+ static const int extra_##e[] = { \
+ EXT(e), EXTRA_END \
+ }
+
+#define EXTRA_EXT2(e1, e2) \
+ static const int extra_##e1##_##e2[] = { \
+ EXT(e1), EXT(e2), EXTRA_END \
+ }
+
+/* The 'extra' mechanism is a way to specify extra checks (such as
+ * extensions or specific gl versions) or actions (flush current, new
+ * buffers) that we need to do before looking up an enum. We need to
+ * declare them all up front so we can refer to them in the value_desc
+ * structs below. */
+
+static const int extra_new_buffers[] = {
+ EXTRA_NEW_BUFFERS,
+ EXTRA_END
+};
+
+static const int extra_valid_draw_buffer[] = {
+ EXTRA_VALID_DRAW_BUFFER,
+ EXTRA_END
+};
+
+static const int extra_valid_texture_unit[] = {
+ EXTRA_VALID_TEXTURE_UNIT,
+ EXTRA_END
+};
+
+static const int extra_flush_current_valid_texture_unit[] = {
+ EXTRA_FLUSH_CURRENT,
+ EXTRA_VALID_TEXTURE_UNIT,
+ EXTRA_END
+};
+
+static const int extra_flush_current[] = {
+ EXTRA_FLUSH_CURRENT,
+ EXTRA_END
+};
+
+static const int extra_new_buffers_OES_read_format[] = {
+ EXTRA_NEW_BUFFERS,
+ EXT(OES_read_format),
+ EXTRA_END
+};
+
+static const int extra_EXT_secondary_color_flush_current[] = {
+ EXT(EXT_secondary_color),
+ EXTRA_FLUSH_CURRENT,
+ EXTRA_END
+};
+
+static const int extra_EXT_fog_coord_flush_current[] = {
+ EXT(EXT_fog_coord),
+ EXTRA_FLUSH_CURRENT,
+ EXTRA_END
+};
+
+static const int extra_EXT_texture_integer[] = {
+ EXT(EXT_texture_integer),
+ EXTRA_END
+};
+
+static const int extra_EXT_gpu_shader4[] = {
+ EXT(EXT_gpu_shader4),
+ EXTRA_END
+};
+
+
+EXTRA_EXT(ARB_ES2_compatibility);
+EXTRA_EXT(ARB_multitexture);
+EXTRA_EXT(ARB_texture_cube_map);
+EXTRA_EXT(MESA_texture_array);
+EXTRA_EXT2(EXT_secondary_color, ARB_vertex_program);
+EXTRA_EXT(EXT_secondary_color);
+EXTRA_EXT(EXT_fog_coord);
+EXTRA_EXT(EXT_texture_lod_bias);
+EXTRA_EXT(EXT_texture_filter_anisotropic);
+EXTRA_EXT(IBM_rasterpos_clip);
+EXTRA_EXT(NV_point_sprite);
+EXTRA_EXT(SGIS_generate_mipmap);
+EXTRA_EXT(NV_vertex_program);
+EXTRA_EXT(NV_fragment_program);
+EXTRA_EXT(NV_texture_rectangle);
+EXTRA_EXT(EXT_stencil_two_side);
+EXTRA_EXT(NV_light_max_exponent);
+EXTRA_EXT(EXT_depth_bounds_test);
+EXTRA_EXT(ARB_depth_clamp);
+EXTRA_EXT(ATI_fragment_shader);
+EXTRA_EXT(EXT_framebuffer_blit);
+EXTRA_EXT(ARB_shader_objects);
+EXTRA_EXT(EXT_provoking_vertex);
+EXTRA_EXT(ARB_fragment_shader);
+EXTRA_EXT(ARB_fragment_program);
+EXTRA_EXT2(ARB_framebuffer_object, EXT_framebuffer_multisample);
+EXTRA_EXT(EXT_framebuffer_object);
+EXTRA_EXT(APPLE_vertex_array_object);
+EXTRA_EXT(ARB_seamless_cube_map);
+EXTRA_EXT(EXT_compiled_vertex_array);
+EXTRA_EXT(ARB_sync);
+EXTRA_EXT(ARB_vertex_shader);
+EXTRA_EXT(EXT_transform_feedback);
+EXTRA_EXT(ARB_transform_feedback2);
+EXTRA_EXT(EXT_pixel_buffer_object);
+EXTRA_EXT(ARB_vertex_program);
+EXTRA_EXT2(NV_point_sprite, ARB_point_sprite);
+EXTRA_EXT2(ARB_fragment_program, NV_fragment_program);
+EXTRA_EXT2(ARB_vertex_program, NV_vertex_program);
+EXTRA_EXT2(ARB_vertex_program, ARB_fragment_program);
+EXTRA_EXT(ARB_vertex_buffer_object);
+EXTRA_EXT(ARB_geometry_shader4);
+EXTRA_EXT(ARB_copy_buffer);
+EXTRA_EXT(EXT_framebuffer_sRGB);
+
+static const int
+extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program[] = {
+ EXT(ARB_vertex_program),
+ EXT(ARB_fragment_program),
+ EXT(NV_vertex_program),
+ EXTRA_END
+};
+
+static const int
+extra_NV_vertex_program_ARB_vertex_program_ARB_fragment_program_NV_vertex_program[] = {
+ EXT(NV_vertex_program),
+ EXT(ARB_vertex_program),
+ EXT(ARB_fragment_program),
+ EXT(NV_vertex_program),
+ EXTRA_END
+};
+
+static const int
+extra_NV_primitive_restart[] = {
+ EXT(NV_primitive_restart),
+ EXTRA_END
+};
+
+static const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
+static const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
+static const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
+
+static const int
+extra_ARB_vertex_program_version_es2[] = {
+ EXT(ARB_vertex_program),
+ EXTRA_VERSION_ES2,
+ EXTRA_END
+};
+
+#define API_OPENGL_BIT (1 << API_OPENGL)
+#define API_OPENGLES_BIT (1 << API_OPENGLES)
+#define API_OPENGLES2_BIT (1 << API_OPENGLES2)
+
+/* This is the big table describing all the enums we accept in
+ * glGet*v(). The table is partitioned into six parts: enums
+ * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
+ * between OpenGL and GLES, enums exclusive to GLES, etc for the
+ * remaining combinations. When we add the enums to the hash table in
+ * _mesa_init_get_hash(), we only add the enums for the API we're
+ * instantiating and the different sections are guarded by #if
+ * FEATURE_GL etc to make sure we only compile in the enums we may
+ * need. */
+
+static const struct value_desc values[] = {
+ /* Enums shared between OpenGL, GLES1 and GLES2 */
+ { 0, 0, TYPE_API_MASK,
+ API_OPENGL_BIT | API_OPENGLES_BIT | API_OPENGLES2_BIT, NO_EXTRA},
+ { GL_ALPHA_BITS, BUFFER_INT(Visual.alphaBits), extra_new_buffers },
+ { GL_BLEND, CONTEXT_BIT0(Color.BlendEnabled), NO_EXTRA },
+ { GL_BLEND_SRC, CONTEXT_ENUM(Color.Blend[0].SrcRGB), NO_EXTRA },
+ { GL_BLUE_BITS, BUFFER_INT(Visual.blueBits), extra_new_buffers },
+ { GL_COLOR_CLEAR_VALUE, CONTEXT_FIELD(Color.ClearColor[0], TYPE_FLOATN_4), NO_EXTRA },
+ { GL_COLOR_WRITEMASK, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
+ { GL_CULL_FACE, CONTEXT_BOOL(Polygon.CullFlag), NO_EXTRA },
+ { GL_CULL_FACE_MODE, CONTEXT_ENUM(Polygon.CullFaceMode), NO_EXTRA },
+ { GL_DEPTH_BITS, BUFFER_INT(Visual.depthBits), NO_EXTRA },
+ { GL_DEPTH_CLEAR_VALUE, CONTEXT_FIELD(Depth.Clear, TYPE_DOUBLEN), NO_EXTRA },
+ { GL_DEPTH_FUNC, CONTEXT_ENUM(Depth.Func), NO_EXTRA },
+ { GL_DEPTH_RANGE, CONTEXT_FIELD(Viewport.Near, TYPE_FLOATN_2), NO_EXTRA },
+ { GL_DEPTH_TEST, CONTEXT_BOOL(Depth.Test), NO_EXTRA },
+ { GL_DEPTH_WRITEMASK, CONTEXT_BOOL(Depth.Mask), NO_EXTRA },
+ { GL_DITHER, CONTEXT_BOOL(Color.DitherFlag), NO_EXTRA },
+ { GL_FRONT_FACE, CONTEXT_ENUM(Polygon.FrontFace), NO_EXTRA },
+ { GL_GREEN_BITS, BUFFER_INT(Visual.greenBits), extra_new_buffers },
+ { GL_LINE_WIDTH, CONTEXT_FLOAT(Line.Width), NO_EXTRA },
+ { GL_ALIASED_LINE_WIDTH_RANGE, CONTEXT_FLOAT2(Const.MinLineWidth), NO_EXTRA },
+ { GL_MAX_ELEMENTS_VERTICES, CONTEXT_INT(Const.MaxArrayLockSize), NO_EXTRA },
+ { GL_MAX_ELEMENTS_INDICES, CONTEXT_INT(Const.MaxArrayLockSize), NO_EXTRA },
+ { GL_MAX_TEXTURE_SIZE, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_context, Const.MaxTextureLevels), NO_EXTRA },
+ { GL_MAX_VIEWPORT_DIMS, CONTEXT_INT2(Const.MaxViewportWidth), NO_EXTRA },
+ { GL_PACK_ALIGNMENT, CONTEXT_INT(Pack.Alignment), NO_EXTRA },
+ { GL_ALIASED_POINT_SIZE_RANGE, CONTEXT_FLOAT2(Const.MinPointSize), NO_EXTRA },
+ { GL_POLYGON_OFFSET_FACTOR, CONTEXT_FLOAT(Polygon.OffsetFactor ), NO_EXTRA },
+ { GL_POLYGON_OFFSET_UNITS, CONTEXT_FLOAT(Polygon.OffsetUnits ), NO_EXTRA },
+ { GL_POLYGON_OFFSET_FILL, CONTEXT_BOOL(Polygon.OffsetFill), NO_EXTRA },
+ { GL_RED_BITS, BUFFER_INT(Visual.redBits), extra_new_buffers },
+ { GL_SCISSOR_BOX, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
+ { GL_SCISSOR_TEST, CONTEXT_BOOL(Scissor.Enabled), NO_EXTRA },
+ { GL_STENCIL_BITS, BUFFER_INT(Visual.stencilBits), NO_EXTRA },
+ { GL_STENCIL_CLEAR_VALUE, CONTEXT_INT(Stencil.Clear), NO_EXTRA },
+ { GL_STENCIL_FAIL, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
+ { GL_STENCIL_FUNC, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
+ { GL_STENCIL_PASS_DEPTH_FAIL, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
+ { GL_STENCIL_PASS_DEPTH_PASS, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
+ { GL_STENCIL_REF, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
+ { GL_STENCIL_TEST, CONTEXT_BOOL(Stencil.Enabled), NO_EXTRA },
+ { GL_STENCIL_VALUE_MASK, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
+ { GL_STENCIL_WRITEMASK, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
+ { GL_SUBPIXEL_BITS, CONTEXT_INT(Const.SubPixelBits), NO_EXTRA },
+ { GL_TEXTURE_BINDING_2D, LOC_CUSTOM, TYPE_INT, TEXTURE_2D_INDEX, NO_EXTRA },
+ { GL_UNPACK_ALIGNMENT, CONTEXT_INT(Unpack.Alignment), NO_EXTRA },
+ { GL_VIEWPORT, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
+
+ /* GL_ARB_multitexture */
+ { GL_ACTIVE_TEXTURE_ARB,
+ LOC_CUSTOM, TYPE_INT, 0, extra_ARB_multitexture },
+
+ /* Note that all the OES_* extensions require that the Mesa "struct
+ * gl_extensions" include a member with the name of the extension.
+ * That structure does not yet include OES extensions (and we're
+ * not sure whether it will). If it does, all the OES_*
+ * extensions below should mark the dependency. */
+
+ /* GL_ARB_texture_cube_map */
+ { GL_TEXTURE_BINDING_CUBE_MAP_ARB, LOC_CUSTOM, TYPE_INT,
+ TEXTURE_CUBE_INDEX, extra_ARB_texture_cube_map },
+ { GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_context, Const.MaxCubeTextureLevels),
+ extra_ARB_texture_cube_map }, /* XXX: OES_texture_cube_map */
+
+ /* XXX: OES_blend_subtract */
+ { GL_BLEND_SRC_RGB_EXT, CONTEXT_ENUM(Color.Blend[0].SrcRGB), NO_EXTRA },
+ { GL_BLEND_DST_RGB_EXT, CONTEXT_ENUM(Color.Blend[0].DstRGB), NO_EXTRA },
+ { GL_BLEND_SRC_ALPHA_EXT, CONTEXT_ENUM(Color.Blend[0].SrcA), NO_EXTRA },
+ { GL_BLEND_DST_ALPHA_EXT, CONTEXT_ENUM(Color.Blend[0].DstA), NO_EXTRA },
+
+ /* GL_BLEND_EQUATION_RGB, which is what we're really after, is
+ * defined identically to GL_BLEND_EQUATION. */
+ { GL_BLEND_EQUATION, CONTEXT_ENUM(Color.Blend[0].EquationRGB), NO_EXTRA },
+ { GL_BLEND_EQUATION_ALPHA_EXT, CONTEXT_ENUM(Color.Blend[0].EquationA), NO_EXTRA },
+
+ /* GL_ARB_texture_compression */
+ { GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
+ { GL_COMPRESSED_TEXTURE_FORMATS_ARB, LOC_CUSTOM, TYPE_INT_N, 0, NO_EXTRA },
+
+ /* GL_ARB_multisample */
+ { GL_SAMPLE_ALPHA_TO_COVERAGE_ARB,
+ CONTEXT_BOOL(Multisample.SampleAlphaToCoverage), NO_EXTRA },
+ { GL_SAMPLE_COVERAGE_ARB, CONTEXT_BOOL(Multisample.SampleCoverage), NO_EXTRA },
+ { GL_SAMPLE_COVERAGE_VALUE_ARB,
+ CONTEXT_FLOAT(Multisample.SampleCoverageValue), NO_EXTRA },
+ { GL_SAMPLE_COVERAGE_INVERT_ARB,
+ CONTEXT_BOOL(Multisample.SampleCoverageInvert), NO_EXTRA },
+ { GL_SAMPLE_BUFFERS_ARB, BUFFER_INT(Visual.sampleBuffers), NO_EXTRA },
+ { GL_SAMPLES_ARB, BUFFER_INT(Visual.samples), NO_EXTRA },
+
+ /* GL_SGIS_generate_mipmap */
+ { GL_GENERATE_MIPMAP_HINT_SGIS, CONTEXT_ENUM(Hint.GenerateMipmap),
+ extra_SGIS_generate_mipmap },
+
+ /* GL_ARB_vertex_buffer_object */
+ { GL_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
+
+ /* GL_ARB_vertex_buffer_object */
+ /* GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB - not supported */
+ { GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, 0,
+ extra_ARB_vertex_buffer_object },
+
+ /* GL_ARB_copy_buffer */
+ { GL_COPY_READ_BUFFER, LOC_CUSTOM, TYPE_INT, 0, extra_ARB_copy_buffer },
+ { GL_COPY_WRITE_BUFFER, LOC_CUSTOM, TYPE_INT, 0, extra_ARB_copy_buffer },
+
+ /* GL_OES_read_format */
+ { GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, LOC_CUSTOM, TYPE_INT, 0,
+ extra_new_buffers_OES_read_format },
+ { GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, LOC_CUSTOM, TYPE_INT, 0,
+ extra_new_buffers_OES_read_format },
+
+ /* GL_EXT_framebuffer_object */
+ { GL_FRAMEBUFFER_BINDING_EXT, BUFFER_INT(Name),
+ extra_EXT_framebuffer_object },
+ { GL_RENDERBUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
+ extra_EXT_framebuffer_object },
+ { GL_MAX_RENDERBUFFER_SIZE_EXT, CONTEXT_INT(Const.MaxRenderbufferSize),
+ extra_EXT_framebuffer_object },
+
+ /* This entry isn't spec'ed for GLES 2, but is needed for Mesa's
+ * GLSL: */
+ { GL_MAX_CLIP_PLANES, CONTEXT_INT(Const.MaxClipPlanes), NO_EXTRA },
+
+#if FEATURE_GL || FEATURE_ES1
+ /* Enums in OpenGL and GLES1 */
+ { 0, 0, TYPE_API_MASK, API_OPENGL_BIT | API_OPENGLES_BIT, NO_EXTRA },
+ { GL_LIGHT0, CONTEXT_BOOL(Light.Light[0].Enabled), NO_EXTRA },
+ { GL_LIGHT1, CONTEXT_BOOL(Light.Light[1].Enabled), NO_EXTRA },
+ { GL_LIGHT2, CONTEXT_BOOL(Light.Light[2].Enabled), NO_EXTRA },
+ { GL_LIGHT3, CONTEXT_BOOL(Light.Light[3].Enabled), NO_EXTRA },
+ { GL_LIGHT4, CONTEXT_BOOL(Light.Light[4].Enabled), NO_EXTRA },
+ { GL_LIGHT5, CONTEXT_BOOL(Light.Light[5].Enabled), NO_EXTRA },
+ { GL_LIGHT6, CONTEXT_BOOL(Light.Light[6].Enabled), NO_EXTRA },
+ { GL_LIGHT7, CONTEXT_BOOL(Light.Light[7].Enabled), NO_EXTRA },
+ { GL_LIGHTING, CONTEXT_BOOL(Light.Enabled), NO_EXTRA },
+ { GL_LIGHT_MODEL_AMBIENT,
+ CONTEXT_FIELD(Light.Model.Ambient[0], TYPE_FLOATN_4), NO_EXTRA },
+ { GL_LIGHT_MODEL_TWO_SIDE, CONTEXT_BOOL(Light.Model.TwoSide), NO_EXTRA },
+ { GL_ALPHA_TEST, CONTEXT_BOOL(Color.AlphaEnabled), NO_EXTRA },
+ { GL_ALPHA_TEST_FUNC, CONTEXT_ENUM(Color.AlphaFunc), NO_EXTRA },
+ { GL_ALPHA_TEST_REF, CONTEXT_FIELD(Color.AlphaRef, TYPE_FLOATN), NO_EXTRA },
+ { GL_BLEND_DST, CONTEXT_ENUM(Color.Blend[0].DstRGB), NO_EXTRA },
+ { GL_CLIP_PLANE0, CONTEXT_BIT0(Transform.ClipPlanesEnabled), NO_EXTRA },
+ { GL_CLIP_PLANE1, CONTEXT_BIT1(Transform.ClipPlanesEnabled), NO_EXTRA },
+ { GL_CLIP_PLANE2, CONTEXT_BIT2(Transform.ClipPlanesEnabled), NO_EXTRA },
+ { GL_CLIP_PLANE3, CONTEXT_BIT3(Transform.ClipPlanesEnabled), NO_EXTRA },
+ { GL_CLIP_PLANE4, CONTEXT_BIT4(Transform.ClipPlanesEnabled), NO_EXTRA },
+ { GL_CLIP_PLANE5, CONTEXT_BIT5(Transform.ClipPlanesEnabled), NO_EXTRA },
+ { GL_COLOR_MATERIAL, CONTEXT_BOOL(Light.ColorMaterialEnabled), NO_EXTRA },
+ { GL_CURRENT_COLOR,
+ CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_COLOR0][0], TYPE_FLOATN_4),
+ extra_flush_current },
+ { GL_CURRENT_NORMAL,
+ CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_NORMAL][0], TYPE_FLOATN_3),
+ extra_flush_current },
+ { GL_CURRENT_TEXTURE_COORDS, LOC_CUSTOM, TYPE_FLOAT_4, 0,
+ extra_flush_current_valid_texture_unit },
+ { GL_DISTANCE_ATTENUATION_EXT, CONTEXT_FLOAT3(Point.Params[0]), NO_EXTRA },
+ { GL_FOG, CONTEXT_BOOL(Fog.Enabled), NO_EXTRA },
+ { GL_FOG_COLOR, CONTEXT_FIELD(Fog.Color[0], TYPE_FLOATN_4), NO_EXTRA },
+ { GL_FOG_DENSITY, CONTEXT_FLOAT(Fog.Density), NO_EXTRA },
+ { GL_FOG_END, CONTEXT_FLOAT(Fog.End), NO_EXTRA },
+ { GL_FOG_HINT, CONTEXT_ENUM(Hint.Fog), NO_EXTRA },
+ { GL_FOG_MODE, CONTEXT_ENUM(Fog.Mode), NO_EXTRA },
+ { GL_FOG_START, CONTEXT_FLOAT(Fog.Start), NO_EXTRA },
+ { GL_LINE_SMOOTH, CONTEXT_BOOL(Line.SmoothFlag), NO_EXTRA },
+ { GL_LINE_SMOOTH_HINT, CONTEXT_ENUM(Hint.LineSmooth), NO_EXTRA },
+ { GL_LINE_WIDTH_RANGE, CONTEXT_FLOAT2(Const.MinLineWidthAA), NO_EXTRA },
+ { GL_COLOR_LOGIC_OP, CONTEXT_BOOL(Color.ColorLogicOpEnabled), NO_EXTRA },
+ { GL_LOGIC_OP_MODE, CONTEXT_ENUM(Color.LogicOp), NO_EXTRA },
+ { GL_MATRIX_MODE, CONTEXT_ENUM(Transform.MatrixMode), NO_EXTRA },
+ { GL_MAX_MODELVIEW_STACK_DEPTH, CONST(MAX_MODELVIEW_STACK_DEPTH), NO_EXTRA },
+ { GL_MAX_PROJECTION_STACK_DEPTH, CONST(MAX_PROJECTION_STACK_DEPTH), NO_EXTRA },
+ { GL_MAX_TEXTURE_STACK_DEPTH, CONST(MAX_TEXTURE_STACK_DEPTH), NO_EXTRA },
+ { GL_MODELVIEW_MATRIX, CONTEXT_MATRIX(ModelviewMatrixStack.Top), NO_EXTRA },
+ { GL_MODELVIEW_STACK_DEPTH, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_context, ModelviewMatrixStack.Depth), NO_EXTRA },
+ { GL_NORMALIZE, CONTEXT_BOOL(Transform.Normalize), NO_EXTRA },
+ { GL_PACK_SKIP_IMAGES_EXT, CONTEXT_INT(Pack.SkipImages), NO_EXTRA },
+ { GL_PERSPECTIVE_CORRECTION_HINT, CONTEXT_ENUM(Hint.PerspectiveCorrection), NO_EXTRA },
+ { GL_POINT_SIZE, CONTEXT_FLOAT(Point.Size), NO_EXTRA },
+ { GL_POINT_SIZE_RANGE, CONTEXT_FLOAT2(Const.MinPointSizeAA), NO_EXTRA },
+ { GL_POINT_SMOOTH, CONTEXT_BOOL(Point.SmoothFlag), NO_EXTRA },
+ { GL_POINT_SMOOTH_HINT, CONTEXT_ENUM(Hint.PointSmooth), NO_EXTRA },
+ { GL_POINT_SIZE_MIN_EXT, CONTEXT_FLOAT(Point.MinSize), NO_EXTRA },
+ { GL_POINT_SIZE_MAX_EXT, CONTEXT_FLOAT(Point.MaxSize), NO_EXTRA },
+ { GL_POINT_FADE_THRESHOLD_SIZE_EXT, CONTEXT_FLOAT(Point.Threshold), NO_EXTRA },
+ { GL_PROJECTION_MATRIX, CONTEXT_MATRIX(ProjectionMatrixStack.Top), NO_EXTRA },
+ { GL_PROJECTION_STACK_DEPTH, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_context, ProjectionMatrixStack.Depth), NO_EXTRA },
+ { GL_RESCALE_NORMAL, CONTEXT_BOOL(Transform.RescaleNormals), NO_EXTRA },
+ { GL_SHADE_MODEL, CONTEXT_ENUM(Light.ShadeModel), NO_EXTRA },
+ { GL_TEXTURE_2D, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
+ { GL_TEXTURE_MATRIX, LOC_CUSTOM, TYPE_MATRIX, 0, extra_valid_texture_unit },
+ { GL_TEXTURE_STACK_DEPTH, LOC_CUSTOM, TYPE_INT, 0,
+ extra_valid_texture_unit },
+
+ { GL_VERTEX_ARRAY, ARRAY_BOOL(Vertex.Enabled), NO_EXTRA },
+ { GL_VERTEX_ARRAY_SIZE, ARRAY_INT(Vertex.Size), NO_EXTRA },
+ { GL_VERTEX_ARRAY_TYPE, ARRAY_ENUM(Vertex.Type), NO_EXTRA },
+ { GL_VERTEX_ARRAY_STRIDE, ARRAY_INT(Vertex.Stride), NO_EXTRA },
+ { GL_NORMAL_ARRAY, ARRAY_ENUM(Normal.Enabled), NO_EXTRA },
+ { GL_NORMAL_ARRAY_TYPE, ARRAY_ENUM(Normal.Type), NO_EXTRA },
+ { GL_NORMAL_ARRAY_STRIDE, ARRAY_INT(Normal.Stride), NO_EXTRA },
+ { GL_COLOR_ARRAY, ARRAY_BOOL(Color.Enabled), NO_EXTRA },
+ { GL_COLOR_ARRAY_SIZE, ARRAY_INT(Color.Size), NO_EXTRA },
+ { GL_COLOR_ARRAY_TYPE, ARRAY_ENUM(Color.Type), NO_EXTRA },
+ { GL_COLOR_ARRAY_STRIDE, ARRAY_INT(Color.Stride), NO_EXTRA },
+ { GL_TEXTURE_COORD_ARRAY,
+ LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct gl_client_array, Enabled), NO_EXTRA },
+ { GL_TEXTURE_COORD_ARRAY_SIZE,
+ LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct gl_client_array, Size), NO_EXTRA },
+ { GL_TEXTURE_COORD_ARRAY_TYPE,
+ LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct gl_client_array, Type), NO_EXTRA },
+ { GL_TEXTURE_COORD_ARRAY_STRIDE,
+ LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct gl_client_array, Stride), NO_EXTRA },
+
+ /* GL_ARB_ES2_compatibility */
+ { GL_SHADER_COMPILER, CONST(1), extra_ARB_ES2_compatibility },
+ { GL_MAX_VARYING_VECTORS, CONTEXT_INT(Const.MaxVarying),
+ extra_ARB_ES2_compatibility },
+ { GL_MAX_VERTEX_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0,
+ extra_ARB_ES2_compatibility },
+ { GL_MAX_FRAGMENT_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0,
+ extra_ARB_ES2_compatibility },
+
+ /* GL_ARB_multitexture */
+ { GL_MAX_TEXTURE_UNITS_ARB,
+ CONTEXT_INT(Const.MaxTextureUnits), extra_ARB_multitexture },
+ { GL_CLIENT_ACTIVE_TEXTURE_ARB,
+ LOC_CUSTOM, TYPE_INT, 0, extra_ARB_multitexture },
+
+ /* GL_ARB_texture_cube_map */
+ { GL_TEXTURE_CUBE_MAP_ARB, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
+ /* S, T, and R are always set at the same time */
+ { GL_TEXTURE_GEN_STR_OES, LOC_TEXUNIT, TYPE_BIT_0,
+ offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
+
+ /* GL_ARB_multisample */
+ { GL_MULTISAMPLE_ARB, CONTEXT_BOOL(Multisample.Enabled), NO_EXTRA },
+ { GL_SAMPLE_ALPHA_TO_ONE_ARB, CONTEXT_BOOL(Multisample.SampleAlphaToOne), NO_EXTRA },
+
+ /* GL_ARB_vertex_buffer_object */
+ { GL_VERTEX_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_array_object, Vertex.BufferObj), NO_EXTRA },
+ { GL_NORMAL_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_array_object, Normal.BufferObj), NO_EXTRA },
+ { GL_COLOR_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_array_object, Color.BufferObj), NO_EXTRA },
+ { GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
+
+ /* GL_OES_point_sprite */
+ { GL_POINT_SPRITE_NV,
+ CONTEXT_BOOL(Point.PointSprite),
+ extra_NV_point_sprite_ARB_point_sprite },
+
+ /* GL_ARB_fragment_shader */
+ { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB,
+ CONTEXT_INT(Const.FragmentProgram.MaxUniformComponents),
+ extra_ARB_fragment_shader },
+
+ /* GL_ARB_vertex_shader */
+ { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB,
+ CONTEXT_INT(Const.VertexProgram.MaxUniformComponents),
+ extra_ARB_vertex_shader },
+ { GL_MAX_VARYING_FLOATS_ARB, LOC_CUSTOM, TYPE_INT, 0,
+ extra_ARB_vertex_shader },
+
+ /* GL_EXT_texture_lod_bias */
+ { GL_MAX_TEXTURE_LOD_BIAS_EXT, CONTEXT_FLOAT(Const.MaxTextureLodBias),
+ extra_EXT_texture_lod_bias },
+
+ /* GL_EXT_texture_filter_anisotropic */
+ { GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,
+ CONTEXT_FLOAT(Const.MaxTextureMaxAnisotropy),
+ extra_EXT_texture_filter_anisotropic },
+#endif /* FEATURE_GL || FEATURE_ES1 */
+
+#if FEATURE_ES1
+ { 0, 0, TYPE_API_MASK, API_OPENGLES_BIT },
+ /* XXX: OES_matrix_get */
+ { GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES },
+ { GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES },
+ { GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES },
+
+ /* OES_point_size_array */
+ { GL_POINT_SIZE_ARRAY_OES, ARRAY_FIELD(PointSize.Enabled, TYPE_BOOLEAN) },
+ { GL_POINT_SIZE_ARRAY_TYPE_OES, ARRAY_FIELD(PointSize.Type, TYPE_ENUM) },
+ { GL_POINT_SIZE_ARRAY_STRIDE_OES, ARRAY_FIELD(PointSize.Stride, TYPE_INT) },
+ { GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES, LOC_CUSTOM, TYPE_INT, 0 },
+#endif /* FEATURE_ES1 */
+
+#if FEATURE_GL || FEATURE_ES2
+ { 0, 0, TYPE_API_MASK, API_OPENGL_BIT | API_OPENGLES2_BIT, NO_EXTRA },
+ /* This entry isn't spec'ed for GLES 2, but is needed for Mesa's GLSL: */
+ { GL_MAX_LIGHTS, CONTEXT_INT(Const.MaxLights), NO_EXTRA },
+ { GL_MAX_TEXTURE_COORDS_ARB, /* == GL_MAX_TEXTURE_COORDS_NV */
+ CONTEXT_INT(Const.MaxTextureCoordUnits),
+ extra_ARB_fragment_program_NV_fragment_program },
+
+ /* GL_ARB_draw_buffers */
+ { GL_MAX_DRAW_BUFFERS_ARB, CONTEXT_INT(Const.MaxDrawBuffers), NO_EXTRA },
+
+ { GL_BLEND_COLOR_EXT, CONTEXT_FIELD(Color.BlendColor[0], TYPE_FLOATN_4), NO_EXTRA },
+ /* GL_ARB_fragment_program */
+ { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, /* == GL_MAX_TEXTURE_IMAGE_UNITS_NV */
+ CONTEXT_INT(Const.MaxTextureImageUnits),
+ extra_ARB_fragment_program_NV_fragment_program },
+ { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB,
+ CONTEXT_INT(Const.MaxVertexTextureImageUnits), extra_ARB_vertex_shader },
+ { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB,
+ CONTEXT_INT(Const.MaxCombinedTextureImageUnits),
+ extra_ARB_vertex_shader },
+
+ /* GL_ARB_shader_objects
+ * Actually, this token isn't part of GL_ARB_shader_objects, but is
+ * close enough for now. */
+ { GL_CURRENT_PROGRAM, LOC_CUSTOM, TYPE_INT, 0, extra_ARB_shader_objects },
+
+ /* OpenGL 2.0 */
+ { GL_STENCIL_BACK_FUNC, CONTEXT_ENUM(Stencil.Function[1]), NO_EXTRA },
+ { GL_STENCIL_BACK_VALUE_MASK, CONTEXT_INT(Stencil.ValueMask[1]), NO_EXTRA },
+ { GL_STENCIL_BACK_WRITEMASK, CONTEXT_INT(Stencil.WriteMask[1]), NO_EXTRA },
+ { GL_STENCIL_BACK_REF, CONTEXT_INT(Stencil.Ref[1]), NO_EXTRA },
+ { GL_STENCIL_BACK_FAIL, CONTEXT_ENUM(Stencil.FailFunc[1]), NO_EXTRA },
+ { GL_STENCIL_BACK_PASS_DEPTH_FAIL, CONTEXT_ENUM(Stencil.ZFailFunc[1]), NO_EXTRA },
+ { GL_STENCIL_BACK_PASS_DEPTH_PASS, CONTEXT_ENUM(Stencil.ZPassFunc[1]), NO_EXTRA },
+
+ { GL_MAX_VERTEX_ATTRIBS_ARB,
+ CONTEXT_INT(Const.VertexProgram.MaxAttribs),
+ extra_ARB_vertex_program_version_es2 },
+
+ /* OES_texture_3D */
+ { GL_TEXTURE_BINDING_3D, LOC_CUSTOM, TYPE_INT, TEXTURE_3D_INDEX, NO_EXTRA },
+ { GL_MAX_3D_TEXTURE_SIZE, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_context, Const.Max3DTextureLevels), NO_EXTRA },
+
+ /* GL_ARB_fragment_program/OES_standard_derivatives */
+ { GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB,
+ CONTEXT_ENUM(Hint.FragmentShaderDerivative), extra_ARB_fragment_shader },
+#endif /* FEATURE_GL || FEATURE_ES2 */
+
+#if FEATURE_ES2
+ /* Enums unique to OpenGL ES 2.0 */
+ { 0, 0, TYPE_API_MASK, API_OPENGLES2_BIT, NO_EXTRA },
+ { GL_MAX_FRAGMENT_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
+ { GL_MAX_VARYING_VECTORS, CONTEXT_INT(Const.MaxVarying), NO_EXTRA },
+ { GL_MAX_VERTEX_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
+ { GL_SHADER_COMPILER, CONST(1), NO_EXTRA },
+ /* OES_get_program_binary */
+ { GL_NUM_SHADER_BINARY_FORMATS, CONST(0), NO_EXTRA },
+ { GL_SHADER_BINARY_FORMATS, CONST(0), NO_EXTRA },
+#endif /* FEATURE_ES2 */
+
+#if FEATURE_GL
+ /* Remaining enums are only in OpenGL */
+ { 0, 0, TYPE_API_MASK, API_OPENGL_BIT, NO_EXTRA },
+ { GL_ACCUM_RED_BITS, BUFFER_INT(Visual.accumRedBits), NO_EXTRA },
+ { GL_ACCUM_GREEN_BITS, BUFFER_INT(Visual.accumGreenBits), NO_EXTRA },
+ { GL_ACCUM_BLUE_BITS, BUFFER_INT(Visual.accumBlueBits), NO_EXTRA },
+ { GL_ACCUM_ALPHA_BITS, BUFFER_INT(Visual.accumAlphaBits), NO_EXTRA },
+ { GL_ACCUM_CLEAR_VALUE, CONTEXT_FIELD(Accum.ClearColor[0], TYPE_FLOATN_4), NO_EXTRA },
+ { GL_ALPHA_BIAS, CONTEXT_FLOAT(Pixel.AlphaBias), NO_EXTRA },
+ { GL_ALPHA_SCALE, CONTEXT_FLOAT(Pixel.AlphaScale), NO_EXTRA },
+ { GL_ATTRIB_STACK_DEPTH, CONTEXT_INT(AttribStackDepth), NO_EXTRA },
+ { GL_AUTO_NORMAL, CONTEXT_BOOL(Eval.AutoNormal), NO_EXTRA },
+ { GL_AUX_BUFFERS, BUFFER_INT(Visual.numAuxBuffers), NO_EXTRA },
+ { GL_BLUE_BIAS, CONTEXT_FLOAT(Pixel.BlueBias), NO_EXTRA },
+ { GL_BLUE_SCALE, CONTEXT_FLOAT(Pixel.BlueScale), NO_EXTRA },
+ { GL_CLIENT_ATTRIB_STACK_DEPTH, CONTEXT_INT(ClientAttribStackDepth), NO_EXTRA },
+ { GL_COLOR_MATERIAL_FACE, CONTEXT_ENUM(Light.ColorMaterialFace), NO_EXTRA },
+ { GL_COLOR_MATERIAL_PARAMETER, CONTEXT_ENUM(Light.ColorMaterialMode), NO_EXTRA },
+ { GL_CURRENT_INDEX,
+ CONTEXT_FLOAT(Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0]),
+ extra_flush_current },
+ { GL_CURRENT_RASTER_COLOR,
+ CONTEXT_FIELD(Current.RasterColor[0], TYPE_FLOATN_4), NO_EXTRA },
+ { GL_CURRENT_RASTER_DISTANCE, CONTEXT_FLOAT(Current.RasterDistance), NO_EXTRA },
+ { GL_CURRENT_RASTER_INDEX, CONST(1), NO_EXTRA },
+ { GL_CURRENT_RASTER_POSITION, CONTEXT_FLOAT4(Current.RasterPos[0]), NO_EXTRA },
+ { GL_CURRENT_RASTER_SECONDARY_COLOR,
+ CONTEXT_FIELD(Current.RasterSecondaryColor[0], TYPE_FLOATN_4), NO_EXTRA },
+ { GL_CURRENT_RASTER_TEXTURE_COORDS, LOC_CUSTOM, TYPE_FLOAT_4, 0,
+ extra_valid_texture_unit },
+ { GL_CURRENT_RASTER_POSITION_VALID, CONTEXT_BOOL(Current.RasterPosValid), NO_EXTRA },
+ { GL_DEPTH_BIAS, CONTEXT_FLOAT(Pixel.DepthBias), NO_EXTRA },
+ { GL_DEPTH_SCALE, CONTEXT_FLOAT(Pixel.DepthScale), NO_EXTRA },
+ { GL_DOUBLEBUFFER, BUFFER_INT(Visual.doubleBufferMode), NO_EXTRA },
+ { GL_DRAW_BUFFER, BUFFER_ENUM(ColorDrawBuffer[0]), NO_EXTRA },
+ { GL_EDGE_FLAG, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
+ { GL_FEEDBACK_BUFFER_SIZE, CONTEXT_INT(Feedback.BufferSize), NO_EXTRA },
+ { GL_FEEDBACK_BUFFER_TYPE, CONTEXT_ENUM(Feedback.Type), NO_EXTRA },
+ { GL_FOG_INDEX, CONTEXT_FLOAT(Fog.Index), NO_EXTRA },
+ { GL_GREEN_BIAS, CONTEXT_FLOAT(Pixel.GreenBias), NO_EXTRA },
+ { GL_GREEN_SCALE, CONTEXT_FLOAT(Pixel.GreenScale), NO_EXTRA },
+ { GL_INDEX_BITS, BUFFER_INT(Visual.indexBits), extra_new_buffers },
+ { GL_INDEX_CLEAR_VALUE, CONTEXT_INT(Color.ClearIndex), NO_EXTRA },
+ { GL_INDEX_MODE, CONST(0) , NO_EXTRA},
+ { GL_INDEX_OFFSET, CONTEXT_INT(Pixel.IndexOffset), NO_EXTRA },
+ { GL_INDEX_SHIFT, CONTEXT_INT(Pixel.IndexShift), NO_EXTRA },
+ { GL_INDEX_WRITEMASK, CONTEXT_INT(Color.IndexMask), NO_EXTRA },
+ { GL_LIGHT_MODEL_COLOR_CONTROL, CONTEXT_ENUM(Light.Model.ColorControl), NO_EXTRA },
+ { GL_LIGHT_MODEL_LOCAL_VIEWER, CONTEXT_BOOL(Light.Model.LocalViewer), NO_EXTRA },
+ { GL_LINE_STIPPLE, CONTEXT_BOOL(Line.StippleFlag), NO_EXTRA },
+ { GL_LINE_STIPPLE_PATTERN, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
+ { GL_LINE_STIPPLE_REPEAT, CONTEXT_INT(Line.StippleFactor), NO_EXTRA },
+ { GL_LINE_WIDTH_GRANULARITY, CONTEXT_FLOAT(Const.LineWidthGranularity), NO_EXTRA },
+ { GL_LIST_BASE, CONTEXT_INT(List.ListBase), NO_EXTRA },
+ { GL_LIST_INDEX, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
+ { GL_LIST_MODE, LOC_CUSTOM, TYPE_ENUM, 0, NO_EXTRA },
+ { GL_INDEX_LOGIC_OP, CONTEXT_BOOL(Color.IndexLogicOpEnabled), NO_EXTRA },
+ { GL_MAP1_COLOR_4, CONTEXT_BOOL(Eval.Map1Color4), NO_EXTRA },
+ { GL_MAP1_GRID_DOMAIN, CONTEXT_FLOAT2(Eval.MapGrid1u1), NO_EXTRA },
+ { GL_MAP1_GRID_SEGMENTS, CONTEXT_INT(Eval.MapGrid1un), NO_EXTRA },
+ { GL_MAP1_INDEX, CONTEXT_BOOL(Eval.Map1Index), NO_EXTRA },
+ { GL_MAP1_NORMAL, CONTEXT_BOOL(Eval.Map1Normal), NO_EXTRA },
+ { GL_MAP1_TEXTURE_COORD_1, CONTEXT_BOOL(Eval.Map1TextureCoord1), NO_EXTRA },
+ { GL_MAP1_TEXTURE_COORD_2, CONTEXT_BOOL(Eval.Map1TextureCoord2), NO_EXTRA },
+ { GL_MAP1_TEXTURE_COORD_3, CONTEXT_BOOL(Eval.Map1TextureCoord3), NO_EXTRA },
+ { GL_MAP1_TEXTURE_COORD_4, CONTEXT_BOOL(Eval.Map1TextureCoord4), NO_EXTRA },
+ { GL_MAP1_VERTEX_3, CONTEXT_BOOL(Eval.Map1Vertex3), NO_EXTRA },
+ { GL_MAP1_VERTEX_4, CONTEXT_BOOL(Eval.Map1Vertex4), NO_EXTRA },
+ { GL_MAP2_COLOR_4, CONTEXT_BOOL(Eval.Map2Color4), NO_EXTRA },
+ { GL_MAP2_GRID_DOMAIN, LOC_CUSTOM, TYPE_FLOAT_4, 0, NO_EXTRA },
+ { GL_MAP2_GRID_SEGMENTS, CONTEXT_INT2(Eval.MapGrid2un), NO_EXTRA },
+ { GL_MAP2_INDEX, CONTEXT_BOOL(Eval.Map2Index), NO_EXTRA },
+ { GL_MAP2_NORMAL, CONTEXT_BOOL(Eval.Map2Normal), NO_EXTRA },
+ { GL_MAP2_TEXTURE_COORD_1, CONTEXT_BOOL(Eval.Map2TextureCoord1), NO_EXTRA },
+ { GL_MAP2_TEXTURE_COORD_2, CONTEXT_BOOL(Eval.Map2TextureCoord2), NO_EXTRA },
+ { GL_MAP2_TEXTURE_COORD_3, CONTEXT_BOOL(Eval.Map2TextureCoord3), NO_EXTRA },
+ { GL_MAP2_TEXTURE_COORD_4, CONTEXT_BOOL(Eval.Map2TextureCoord4), NO_EXTRA },
+ { GL_MAP2_VERTEX_3, CONTEXT_BOOL(Eval.Map2Vertex3), NO_EXTRA },
+ { GL_MAP2_VERTEX_4, CONTEXT_BOOL(Eval.Map2Vertex4), NO_EXTRA },
+ { GL_MAP_COLOR, CONTEXT_BOOL(Pixel.MapColorFlag), NO_EXTRA },
+ { GL_MAP_STENCIL, CONTEXT_BOOL(Pixel.MapStencilFlag), NO_EXTRA },
+ { GL_MAX_ATTRIB_STACK_DEPTH, CONST(MAX_ATTRIB_STACK_DEPTH), NO_EXTRA },
+ { GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, CONST(MAX_CLIENT_ATTRIB_STACK_DEPTH), NO_EXTRA },
+
+ { GL_MAX_EVAL_ORDER, CONST(MAX_EVAL_ORDER), NO_EXTRA },
+ { GL_MAX_LIST_NESTING, CONST(MAX_LIST_NESTING), NO_EXTRA },
+ { GL_MAX_NAME_STACK_DEPTH, CONST(MAX_NAME_STACK_DEPTH), NO_EXTRA },
+ { GL_MAX_PIXEL_MAP_TABLE, CONST(MAX_PIXEL_MAP_TABLE), NO_EXTRA },
+ { GL_NAME_STACK_DEPTH, CONTEXT_INT(Select.NameStackDepth), NO_EXTRA },
+ { GL_PACK_LSB_FIRST, CONTEXT_BOOL(Pack.LsbFirst), NO_EXTRA },
+ { GL_PACK_ROW_LENGTH, CONTEXT_INT(Pack.RowLength), NO_EXTRA },
+ { GL_PACK_SKIP_PIXELS, CONTEXT_INT(Pack.SkipPixels), NO_EXTRA },
+ { GL_PACK_SKIP_ROWS, CONTEXT_INT(Pack.SkipRows), NO_EXTRA },
+ { GL_PACK_SWAP_BYTES, CONTEXT_BOOL(Pack.SwapBytes), NO_EXTRA },
+ { GL_PACK_IMAGE_HEIGHT_EXT, CONTEXT_INT(Pack.ImageHeight), NO_EXTRA },
+ { GL_PACK_INVERT_MESA, CONTEXT_BOOL(Pack.Invert), NO_EXTRA },
+ { GL_PIXEL_MAP_A_TO_A_SIZE, CONTEXT_INT(PixelMaps.AtoA.Size), NO_EXTRA },
+ { GL_PIXEL_MAP_B_TO_B_SIZE, CONTEXT_INT(PixelMaps.BtoB.Size), NO_EXTRA },
+ { GL_PIXEL_MAP_G_TO_G_SIZE, CONTEXT_INT(PixelMaps.GtoG.Size), NO_EXTRA },
+ { GL_PIXEL_MAP_I_TO_A_SIZE, CONTEXT_INT(PixelMaps.ItoA.Size), NO_EXTRA },
+ { GL_PIXEL_MAP_I_TO_B_SIZE, CONTEXT_INT(PixelMaps.ItoB.Size), NO_EXTRA },
+ { GL_PIXEL_MAP_I_TO_G_SIZE, CONTEXT_INT(PixelMaps.ItoG.Size), NO_EXTRA },
+ { GL_PIXEL_MAP_I_TO_I_SIZE, CONTEXT_INT(PixelMaps.ItoI.Size), NO_EXTRA },
+ { GL_PIXEL_MAP_I_TO_R_SIZE, CONTEXT_INT(PixelMaps.ItoR.Size), NO_EXTRA },
+ { GL_PIXEL_MAP_R_TO_R_SIZE, CONTEXT_INT(PixelMaps.RtoR.Size), NO_EXTRA },
+ { GL_PIXEL_MAP_S_TO_S_SIZE, CONTEXT_INT(PixelMaps.StoS.Size), NO_EXTRA },
+ { GL_POINT_SIZE_GRANULARITY, CONTEXT_FLOAT(Const.PointSizeGranularity), NO_EXTRA },
+ { GL_POLYGON_MODE, CONTEXT_ENUM2(Polygon.FrontMode), NO_EXTRA },
+ { GL_POLYGON_OFFSET_BIAS_EXT, CONTEXT_FLOAT(Polygon.OffsetUnits), NO_EXTRA },
+ { GL_POLYGON_OFFSET_POINT, CONTEXT_BOOL(Polygon.OffsetPoint), NO_EXTRA },
+ { GL_POLYGON_OFFSET_LINE, CONTEXT_BOOL(Polygon.OffsetLine), NO_EXTRA },
+ { GL_POLYGON_SMOOTH, CONTEXT_BOOL(Polygon.SmoothFlag), NO_EXTRA },
+ { GL_POLYGON_SMOOTH_HINT, CONTEXT_ENUM(Hint.PolygonSmooth), NO_EXTRA },
+ { GL_POLYGON_STIPPLE, CONTEXT_BOOL(Polygon.StippleFlag), NO_EXTRA },
+ { GL_READ_BUFFER, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
+ { GL_RED_BIAS, CONTEXT_FLOAT(Pixel.RedBias), NO_EXTRA },
+ { GL_RED_SCALE, CONTEXT_FLOAT(Pixel.RedScale), NO_EXTRA },
+ { GL_RENDER_MODE, CONTEXT_ENUM(RenderMode), NO_EXTRA },
+ { GL_RGBA_MODE, CONST(1), NO_EXTRA },
+ { GL_SELECTION_BUFFER_SIZE, CONTEXT_INT(Select.BufferSize), NO_EXTRA },
+ { GL_SHARED_TEXTURE_PALETTE_EXT, CONTEXT_BOOL(Texture.SharedPalette), NO_EXTRA },
+
+ { GL_STEREO, BUFFER_INT(Visual.stereoMode), NO_EXTRA },
+
+ { GL_TEXTURE_1D, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
+ { GL_TEXTURE_3D, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
+ { GL_TEXTURE_1D_ARRAY_EXT, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
+ { GL_TEXTURE_2D_ARRAY_EXT, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
+
+ { GL_TEXTURE_BINDING_1D, LOC_CUSTOM, TYPE_INT, TEXTURE_1D_INDEX, NO_EXTRA },
+ { GL_TEXTURE_BINDING_1D_ARRAY, LOC_CUSTOM, TYPE_INT,
+ TEXTURE_1D_ARRAY_INDEX, extra_MESA_texture_array },
+ { GL_TEXTURE_BINDING_2D_ARRAY, LOC_CUSTOM, TYPE_INT,
+ TEXTURE_1D_ARRAY_INDEX, extra_MESA_texture_array },
+ { GL_MAX_ARRAY_TEXTURE_LAYERS_EXT,
+ CONTEXT_INT(Const.MaxArrayTextureLayers), extra_MESA_texture_array },
+
+ { GL_TEXTURE_GEN_S, LOC_TEXUNIT, TYPE_BIT_0,
+ offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
+ { GL_TEXTURE_GEN_T, LOC_TEXUNIT, TYPE_BIT_1,
+ offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
+ { GL_TEXTURE_GEN_R, LOC_TEXUNIT, TYPE_BIT_2,
+ offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
+ { GL_TEXTURE_GEN_Q, LOC_TEXUNIT, TYPE_BIT_3,
+ offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
+ { GL_UNPACK_LSB_FIRST, CONTEXT_BOOL(Unpack.LsbFirst), NO_EXTRA },
+ { GL_UNPACK_ROW_LENGTH, CONTEXT_INT(Unpack.RowLength), NO_EXTRA },
+ { GL_UNPACK_SKIP_PIXELS, CONTEXT_INT(Unpack.SkipPixels), NO_EXTRA },
+ { GL_UNPACK_SKIP_ROWS, CONTEXT_INT(Unpack.SkipRows), NO_EXTRA },
+ { GL_UNPACK_SWAP_BYTES, CONTEXT_BOOL(Unpack.SwapBytes), NO_EXTRA },
+ { GL_UNPACK_SKIP_IMAGES_EXT, CONTEXT_INT(Unpack.SkipImages), NO_EXTRA },
+ { GL_UNPACK_IMAGE_HEIGHT_EXT, CONTEXT_INT(Unpack.ImageHeight), NO_EXTRA },
+ { GL_UNPACK_CLIENT_STORAGE_APPLE, CONTEXT_BOOL(Unpack.ClientStorage), NO_EXTRA },
+ { GL_ZOOM_X, CONTEXT_FLOAT(Pixel.ZoomX), NO_EXTRA },
+ { GL_ZOOM_Y, CONTEXT_FLOAT(Pixel.ZoomY), NO_EXTRA },
+
+ /* Vertex arrays */
+ { GL_VERTEX_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
+ { GL_NORMAL_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
+ { GL_COLOR_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
+ { GL_INDEX_ARRAY, ARRAY_BOOL(Index.Enabled), NO_EXTRA },
+ { GL_INDEX_ARRAY_TYPE, ARRAY_ENUM(Index.Type), NO_EXTRA },
+ { GL_INDEX_ARRAY_STRIDE, ARRAY_INT(Index.Stride), NO_EXTRA },
+ { GL_INDEX_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
+ { GL_TEXTURE_COORD_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
+ { GL_EDGE_FLAG_ARRAY, ARRAY_BOOL(EdgeFlag.Enabled), NO_EXTRA },
+ { GL_EDGE_FLAG_ARRAY_STRIDE, ARRAY_INT(EdgeFlag.Stride), NO_EXTRA },
+ { GL_EDGE_FLAG_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
+
+ /* GL_ARB_texture_compression */
+ { GL_TEXTURE_COMPRESSION_HINT_ARB, CONTEXT_INT(Hint.TextureCompression), NO_EXTRA },
+
+ /* GL_EXT_compiled_vertex_array */
+ { GL_ARRAY_ELEMENT_LOCK_FIRST_EXT, CONTEXT_INT(Array.LockFirst),
+ extra_EXT_compiled_vertex_array },
+ { GL_ARRAY_ELEMENT_LOCK_COUNT_EXT, CONTEXT_INT(Array.LockCount),
+ extra_EXT_compiled_vertex_array },
+
+ /* GL_ARB_transpose_matrix */
+ { GL_TRANSPOSE_MODELVIEW_MATRIX_ARB,
+ CONTEXT_MATRIX_T(ModelviewMatrixStack), NO_EXTRA },
+ { GL_TRANSPOSE_PROJECTION_MATRIX_ARB,
+ CONTEXT_MATRIX_T(ProjectionMatrixStack.Top), NO_EXTRA },
+ { GL_TRANSPOSE_TEXTURE_MATRIX_ARB, CONTEXT_MATRIX_T(TextureMatrixStack), NO_EXTRA },
+
+ /* GL_EXT_secondary_color */
+ { GL_COLOR_SUM_EXT, CONTEXT_BOOL(Fog.ColorSumEnabled),
+ extra_EXT_secondary_color_ARB_vertex_program },
+ { GL_CURRENT_SECONDARY_COLOR_EXT,
+ CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_COLOR1][0], TYPE_FLOATN_4),
+ extra_EXT_secondary_color_flush_current },
+ { GL_SECONDARY_COLOR_ARRAY_EXT, ARRAY_BOOL(SecondaryColor.Enabled),
+ extra_EXT_secondary_color },
+ { GL_SECONDARY_COLOR_ARRAY_TYPE_EXT, ARRAY_ENUM(SecondaryColor.Type),
+ extra_EXT_secondary_color },
+ { GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT, ARRAY_INT(SecondaryColor.Stride),
+ extra_EXT_secondary_color },
+ { GL_SECONDARY_COLOR_ARRAY_SIZE_EXT, ARRAY_INT(SecondaryColor.Size),
+ extra_EXT_secondary_color },
+
+ /* GL_EXT_fog_coord */
+ { GL_CURRENT_FOG_COORDINATE_EXT,
+ CONTEXT_FLOAT(Current.Attrib[VERT_ATTRIB_FOG][0]),
+ extra_EXT_fog_coord_flush_current },
+ { GL_FOG_COORDINATE_ARRAY_EXT, ARRAY_BOOL(FogCoord.Enabled),
+ extra_EXT_fog_coord },
+ { GL_FOG_COORDINATE_ARRAY_TYPE_EXT, ARRAY_ENUM(FogCoord.Type),
+ extra_EXT_fog_coord },
+ { GL_FOG_COORDINATE_ARRAY_STRIDE_EXT, ARRAY_INT(FogCoord.Stride),
+ extra_EXT_fog_coord },
+ { GL_FOG_COORDINATE_SOURCE_EXT, CONTEXT_ENUM(Fog.FogCoordinateSource),
+ extra_EXT_fog_coord },
+
+ /* GL_IBM_rasterpos_clip */
+ { GL_RASTER_POSITION_UNCLIPPED_IBM,
+ CONTEXT_BOOL(Transform.RasterPositionUnclipped),
+ extra_IBM_rasterpos_clip },
+
+ /* GL_NV_point_sprite */
+ { GL_POINT_SPRITE_R_MODE_NV,
+ CONTEXT_ENUM(Point.SpriteRMode), extra_NV_point_sprite },
+ { GL_POINT_SPRITE_COORD_ORIGIN, CONTEXT_ENUM(Point.SpriteOrigin),
+ extra_NV_point_sprite_ARB_point_sprite },
+
+ /* GL_NV_vertex_program */
+ { GL_VERTEX_PROGRAM_BINDING_NV, LOC_CUSTOM, TYPE_INT, 0,
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY0_NV, ARRAY_BOOL(VertexAttrib[0].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY1_NV, ARRAY_BOOL(VertexAttrib[1].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY2_NV, ARRAY_BOOL(VertexAttrib[2].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY3_NV, ARRAY_BOOL(VertexAttrib[3].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY4_NV, ARRAY_BOOL(VertexAttrib[4].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY5_NV, ARRAY_BOOL(VertexAttrib[5].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY6_NV, ARRAY_BOOL(VertexAttrib[6].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY7_NV, ARRAY_BOOL(VertexAttrib[7].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY8_NV, ARRAY_BOOL(VertexAttrib[8].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY9_NV, ARRAY_BOOL(VertexAttrib[9].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY10_NV, ARRAY_BOOL(VertexAttrib[10].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY11_NV, ARRAY_BOOL(VertexAttrib[11].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY12_NV, ARRAY_BOOL(VertexAttrib[12].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY13_NV, ARRAY_BOOL(VertexAttrib[13].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY14_NV, ARRAY_BOOL(VertexAttrib[14].Enabled),
+ extra_NV_vertex_program },
+ { GL_VERTEX_ATTRIB_ARRAY15_NV, ARRAY_BOOL(VertexAttrib[15].Enabled),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB0_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[0]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB1_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[1]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB2_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[2]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB3_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[3]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB4_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[4]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB5_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[5]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB6_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[6]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB7_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[7]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB8_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[8]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB9_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[9]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB10_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[10]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB11_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[11]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB12_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[12]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB13_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[13]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB14_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[14]),
+ extra_NV_vertex_program },
+ { GL_MAP1_VERTEX_ATTRIB15_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[15]),
+ extra_NV_vertex_program },
+
+ /* GL_NV_fragment_program */
+ { GL_FRAGMENT_PROGRAM_NV, CONTEXT_BOOL(FragmentProgram.Enabled),
+ extra_NV_fragment_program },
+ { GL_FRAGMENT_PROGRAM_BINDING_NV, LOC_CUSTOM, TYPE_INT, 0,
+ extra_NV_fragment_program },
+ { GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV,
+ CONST(MAX_NV_FRAGMENT_PROGRAM_PARAMS),
+ extra_NV_fragment_program },
+
+ /* GL_NV_texture_rectangle */
+ { GL_TEXTURE_RECTANGLE_NV,
+ LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_NV_texture_rectangle },
+ { GL_TEXTURE_BINDING_RECTANGLE_NV,
+ LOC_CUSTOM, TYPE_INT, TEXTURE_RECT_INDEX, extra_NV_texture_rectangle },
+ { GL_MAX_RECTANGLE_TEXTURE_SIZE_NV,
+ CONTEXT_INT(Const.MaxTextureRectSize), extra_NV_texture_rectangle },
+
+ /* GL_EXT_stencil_two_side */
+ { GL_STENCIL_TEST_TWO_SIDE_EXT, CONTEXT_BOOL(Stencil.TestTwoSide),
+ extra_EXT_stencil_two_side },
+ { GL_ACTIVE_STENCIL_FACE_EXT, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
+
+ /* GL_NV_light_max_exponent */
+ { GL_MAX_SHININESS_NV, CONTEXT_FLOAT(Const.MaxShininess),
+ extra_NV_light_max_exponent },
+ { GL_MAX_SPOT_EXPONENT_NV, CONTEXT_FLOAT(Const.MaxSpotExponent),
+ extra_NV_light_max_exponent },
+
+ /* GL_NV_primitive_restart */
+ { GL_PRIMITIVE_RESTART_NV, CONTEXT_BOOL(Array.PrimitiveRestart),
+ extra_NV_primitive_restart },
+ { GL_PRIMITIVE_RESTART_INDEX_NV, CONTEXT_INT(Array.RestartIndex),
+ extra_NV_primitive_restart },
+
+ /* GL_ARB_vertex_buffer_object */
+ { GL_INDEX_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_array_object, Index.BufferObj), NO_EXTRA },
+ { GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_array_object, EdgeFlag.BufferObj), NO_EXTRA },
+ { GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_array_object, SecondaryColor.BufferObj), NO_EXTRA },
+ { GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
+ offsetof(struct gl_array_object, FogCoord.BufferObj), NO_EXTRA },
+
+ /* GL_EXT_pixel_buffer_object */
+ { GL_PIXEL_PACK_BUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
+ extra_EXT_pixel_buffer_object },
+ { GL_PIXEL_UNPACK_BUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
+ extra_EXT_pixel_buffer_object },
+
+ /* GL_ARB_vertex_program */
+ { GL_VERTEX_PROGRAM_ARB, /* == GL_VERTEX_PROGRAM_NV */
+ CONTEXT_BOOL(VertexProgram.Enabled),
+ extra_ARB_vertex_program_NV_vertex_program },
+ { GL_VERTEX_PROGRAM_POINT_SIZE_ARB, /* == GL_VERTEX_PROGRAM_POINT_SIZE_NV*/
+ CONTEXT_BOOL(VertexProgram.PointSizeEnabled),
+ extra_ARB_vertex_program_NV_vertex_program },
+ { GL_VERTEX_PROGRAM_TWO_SIDE_ARB, /* == GL_VERTEX_PROGRAM_TWO_SIDE_NV */
+ CONTEXT_BOOL(VertexProgram.TwoSideEnabled),
+ extra_ARB_vertex_program_NV_vertex_program },
+ { GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB, /* == GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV */
+ CONTEXT_INT(Const.MaxProgramMatrixStackDepth),
+ extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
+ { GL_MAX_PROGRAM_MATRICES_ARB, /* == GL_MAX_TRACK_MATRICES_NV */
+ CONTEXT_INT(Const.MaxProgramMatrices),
+ extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
+ { GL_CURRENT_MATRIX_STACK_DEPTH_ARB, /* == GL_CURRENT_MATRIX_STACK_DEPTH_NV */
+ LOC_CUSTOM, TYPE_INT, 0,
+ extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
+
+ { GL_CURRENT_MATRIX_ARB, /* == GL_CURRENT_MATRIX_NV */
+ LOC_CUSTOM, TYPE_MATRIX, 0,
+ extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
+ { GL_TRANSPOSE_CURRENT_MATRIX_ARB, /* == GL_CURRENT_MATRIX_NV */
+ LOC_CUSTOM, TYPE_MATRIX, 0,
+ extra_ARB_vertex_program_ARB_fragment_program },
+
+ { GL_PROGRAM_ERROR_POSITION_ARB, /* == GL_PROGRAM_ERROR_POSITION_NV */
+ CONTEXT_INT(Program.ErrorPos),
+ extra_NV_vertex_program_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
+
+ /* GL_ARB_fragment_program */
+ { GL_FRAGMENT_PROGRAM_ARB, CONTEXT_BOOL(FragmentProgram.Enabled),
+ extra_ARB_fragment_program },
+
+ /* GL_EXT_depth_bounds_test */
+ { GL_DEPTH_BOUNDS_TEST_EXT, CONTEXT_BOOL(Depth.BoundsTest),
+ extra_EXT_depth_bounds_test },
+ { GL_DEPTH_BOUNDS_EXT, CONTEXT_FLOAT2(Depth.BoundsMin),
+ extra_EXT_depth_bounds_test },
+
+ /* GL_ARB_depth_clamp*/
+ { GL_DEPTH_CLAMP, CONTEXT_BOOL(Transform.DepthClamp),
+ extra_ARB_depth_clamp },
+
+ /* GL_ARB_draw_buffers */
+ { GL_DRAW_BUFFER0_ARB, BUFFER_ENUM(ColorDrawBuffer[0]), NO_EXTRA },
+ { GL_DRAW_BUFFER1_ARB, BUFFER_ENUM(ColorDrawBuffer[1]),
+ extra_valid_draw_buffer },
+ { GL_DRAW_BUFFER2_ARB, BUFFER_ENUM(ColorDrawBuffer[2]),
+ extra_valid_draw_buffer },
+ { GL_DRAW_BUFFER3_ARB, BUFFER_ENUM(ColorDrawBuffer[3]),
+ extra_valid_draw_buffer },
+ { GL_DRAW_BUFFER4_ARB, BUFFER_ENUM(ColorDrawBuffer[4]),
+ extra_valid_draw_buffer },
+ { GL_DRAW_BUFFER5_ARB, BUFFER_ENUM(ColorDrawBuffer[5]),
+ extra_valid_draw_buffer },
+ { GL_DRAW_BUFFER6_ARB, BUFFER_ENUM(ColorDrawBuffer[6]),
+ extra_valid_draw_buffer },
+ { GL_DRAW_BUFFER7_ARB, BUFFER_ENUM(ColorDrawBuffer[7]),
+ extra_valid_draw_buffer },
+
+ /* GL_ATI_fragment_shader */
+ { GL_NUM_FRAGMENT_REGISTERS_ATI, CONST(6), extra_ATI_fragment_shader },
+ { GL_NUM_FRAGMENT_CONSTANTS_ATI, CONST(8), extra_ATI_fragment_shader },
+ { GL_NUM_PASSES_ATI, CONST(2), extra_ATI_fragment_shader },
+ { GL_NUM_INSTRUCTIONS_PER_PASS_ATI, CONST(8), extra_ATI_fragment_shader },
+ { GL_NUM_INSTRUCTIONS_TOTAL_ATI, CONST(16), extra_ATI_fragment_shader },
+ { GL_COLOR_ALPHA_PAIRING_ATI, CONST(GL_TRUE), extra_ATI_fragment_shader },
+ { GL_NUM_LOOPBACK_COMPONENTS_ATI, CONST(3), extra_ATI_fragment_shader },
+ { GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI,
+ CONST(3), extra_ATI_fragment_shader },
+
+ /* GL_EXT_framebuffer_object */
+ { GL_MAX_COLOR_ATTACHMENTS_EXT, CONTEXT_INT(Const.MaxColorAttachments),
+ extra_EXT_framebuffer_object },
+
+ /* GL_EXT_framebuffer_blit
+ * NOTE: GL_DRAW_FRAMEBUFFER_BINDING_EXT == GL_FRAMEBUFFER_BINDING_EXT */
+ { GL_READ_FRAMEBUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
+ extra_EXT_framebuffer_blit },
+
+ /* GL_EXT_provoking_vertex */
+ { GL_PROVOKING_VERTEX_EXT,
+ CONTEXT_BOOL(Light.ProvokingVertex), extra_EXT_provoking_vertex },
+ { GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT,
+ CONTEXT_BOOL(Const.QuadsFollowProvokingVertexConvention),
+ extra_EXT_provoking_vertex },
+
+ /* GL_ARB_framebuffer_object */
+ { GL_MAX_SAMPLES, CONTEXT_INT(Const.MaxSamples),
+ extra_ARB_framebuffer_object_EXT_framebuffer_multisample },
+
+ /* GL_APPLE_vertex_array_object */
+ { GL_VERTEX_ARRAY_BINDING_APPLE, ARRAY_INT(Name),
+ extra_APPLE_vertex_array_object },
+
+ /* GL_ARB_seamless_cube_map */
+ { GL_TEXTURE_CUBE_MAP_SEAMLESS,
+ CONTEXT_BOOL(Texture.CubeMapSeamless), extra_ARB_seamless_cube_map },
+
+ /* GL_ARB_sync */
+ { GL_MAX_SERVER_WAIT_TIMEOUT,
+ CONTEXT_INT64(Const.MaxServerWaitTimeout), extra_ARB_sync },
+
+ /* GL_EXT_texture_integer */
+ { GL_RGBA_INTEGER_MODE_EXT, BUFFER_BOOL(_IntegerColor),
+ extra_EXT_texture_integer },
+
+ /* GL_EXT_transform_feedback */
+ { GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, LOC_CUSTOM, TYPE_INT, 0,
+ extra_EXT_transform_feedback },
+ { GL_RASTERIZER_DISCARD, CONTEXT_BOOL(TransformFeedback.RasterDiscard),
+ extra_EXT_transform_feedback },
+ { GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS,
+ CONTEXT_INT(Const.MaxTransformFeedbackInterleavedComponents),
+ extra_EXT_transform_feedback },
+ { GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
+ CONTEXT_INT(Const.MaxTransformFeedbackSeparateAttribs),
+ extra_EXT_transform_feedback },
+ { GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS,
+ CONTEXT_INT(Const.MaxTransformFeedbackSeparateComponents),
+ extra_EXT_transform_feedback },
+
+ /* GL_ARB_transform_feedback2 */
+ { GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED, LOC_CUSTOM, TYPE_BOOLEAN, 0,
+ extra_ARB_transform_feedback2 },
+ { GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE, LOC_CUSTOM, TYPE_BOOLEAN, 0,
+ extra_ARB_transform_feedback2 },
+ { GL_TRANSFORM_FEEDBACK_BINDING, LOC_CUSTOM, TYPE_INT, 0,
+ extra_ARB_transform_feedback2 },
+
+ /* GL_ARB_geometry_shader4 */
+ { GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB,
+ CONTEXT_INT(Const.GeometryProgram.MaxGeometryTextureImageUnits),
+ extra_ARB_geometry_shader4 },
+ { GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB,
+ CONTEXT_INT(Const.GeometryProgram.MaxGeometryOutputVertices),
+ extra_ARB_geometry_shader4 },
+ { GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB,
+ CONTEXT_INT(Const.GeometryProgram.MaxGeometryTotalOutputComponents),
+ extra_ARB_geometry_shader4 },
+ { GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB,
+ CONTEXT_INT(Const.GeometryProgram.MaxGeometryUniformComponents),
+ extra_ARB_geometry_shader4 },
+ { GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB,
+ CONTEXT_INT(Const.GeometryProgram.MaxGeometryVaryingComponents),
+ extra_ARB_geometry_shader4 },
+ { GL_MAX_VERTEX_VARYING_COMPONENTS_ARB,
+ CONTEXT_INT(Const.GeometryProgram.MaxVertexVaryingComponents),
+ extra_ARB_geometry_shader4 },
+
+ /* GL_EXT_gpu_shader4 / GL 3.0 */
+ { GL_MIN_PROGRAM_TEXEL_OFFSET,
+ CONTEXT_INT(Const.MinProgramTexelOffset),
+ extra_EXT_gpu_shader4 },
+ { GL_MAX_PROGRAM_TEXEL_OFFSET,
+ CONTEXT_INT(Const.MaxProgramTexelOffset),
+ extra_EXT_gpu_shader4 },
+
+ /* GL 3.0 */
+ { GL_NUM_EXTENSIONS, LOC_CUSTOM, TYPE_INT, 0, extra_version_30 },
+ { GL_MAJOR_VERSION, CONTEXT_INT(VersionMajor), extra_version_30 },
+ { GL_MINOR_VERSION, CONTEXT_INT(VersionMinor), extra_version_30 },
+ { GL_CONTEXT_FLAGS, CONTEXT_INT(Const.ContextFlags), extra_version_30 },
+
+ /* GL3.0 / GL_EXT_framebuffer_sRGB */
+ { GL_FRAMEBUFFER_SRGB_EXT, CONTEXT_BOOL(Color.sRGBEnabled), extra_EXT_framebuffer_sRGB },
+ { GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, BUFFER_INT(Visual.sRGBCapable), extra_EXT_framebuffer_sRGB },
+
+ /* GL 3.1 */
+ /* NOTE: different enum values for GL_PRIMITIVE_RESTART_NV
+ * vs. GL_PRIMITIVE_RESTART!
+ */
+ { GL_PRIMITIVE_RESTART, CONTEXT_BOOL(Array.PrimitiveRestart),
+ extra_version_31 },
+ { GL_PRIMITIVE_RESTART_INDEX, CONTEXT_INT(Array.RestartIndex),
+ extra_version_31 },
+
+
+ /* GL 3.2 */
+ { GL_CONTEXT_PROFILE_MASK, CONTEXT_INT(Const.ProfileMask),
+ extra_version_32 },
+#endif /* FEATURE_GL */
+};
+
+/* All we need now is a way to look up the value struct from the enum.
+ * The code generated by gcc for the old generated big switch
+ * statement is a big, balanced, open coded if/else tree, essentially
+ * an unrolled binary search. It would be natural to sort the new
+ * enum table and use bsearch(), but we will use a read-only hash
+ * table instead. bsearch() has a nice guaranteed worst case
+ * performance, but we're also guaranteed to hit that worst case
+ * (log2(n) iterations) for about half the enums. Instead, using an
+ * open addressing hash table, we can find the enum on the first try
+ * for 80% of the enums, 1 collision for 10% and never more than 5
+ * collisions for any enum (typical numbers). And the code is very
+ * simple, even though it feels a little magic. */
+
+static unsigned short table[1024];
+static const int prime_factor = 89, prime_step = 281;
+
+#ifdef GET_DEBUG
+static void
+print_table_stats(void)
+{
+ int i, j, collisions[11], count, hash, mask;
+ const struct value_desc *d;
+
+ count = 0;
+ mask = Elements(table) - 1;
+ memset(collisions, 0, sizeof collisions);
+
+ for (i = 0; i < Elements(table); i++) {
+ if (!table[i])
+ continue;
+ count++;
+ d = &values[table[i]];
+ hash = (d->pname * prime_factor);
+ j = 0;
+ while (1) {
+ if (values[table[hash & mask]].pname == d->pname)
+ break;
+ hash += prime_step;
+ j++;
+ }
+
+ if (j < 10)
+ collisions[j]++;
+ else
+ collisions[10]++;
+ }
+
+ printf("number of enums: %d (total %d)\n", count, Elements(values));
+ for (i = 0; i < Elements(collisions) - 1; i++)
+ if (collisions[i] > 0)
+ printf(" %d enums with %d %scollisions\n",
+ collisions[i], i, i == 10 ? "or more " : "");
+}
+#endif
+
+/**
+ * Initialize the enum hash for a given API
+ *
+ * This is called from one_time_init() to insert the enum values that
+ * are valid for the API in question into the enum hash table.
+ *
+ * \param the current context, for determining the API in question
+ */
+void _mesa_init_get_hash(struct gl_context *ctx)
+{
+ int i, hash, index, mask;
+ int api_mask = 0, api_bit;
+
+ mask = Elements(table) - 1;
+ api_bit = 1 << ctx->API;
+
+ for (i = 0; i < Elements(values); i++) {
+ if (values[i].type == TYPE_API_MASK) {
+ api_mask = values[i].offset;
+ continue;
+ }
+ if (!(api_mask & api_bit))
+ continue;
+
+ hash = (values[i].pname * prime_factor) & mask;
+ while (1) {
+ index = hash & mask;
+ if (!table[index]) {
+ table[index] = i;
+ break;
+ }
+ hash += prime_step;
+ }
+ }
+
+#ifdef GET_DEBUG
+ print_table_stats();
+#endif
+}
+
+/**
+ * Handle irregular enums
+ *
+ * Some values don't conform to the "well-known type at context
+ * pointer + offset" pattern, so we have this function to catch all
+ * the corner cases. Typically, it's a computed value or a one-off
+ * pointer to a custom struct or something.
+ *
+ * In this case we can't return a pointer to the value, so we'll have
+ * to use the temporary variable 'v' declared back in the calling
+ * glGet*v() function to store the result.
+ *
+ * \param ctx the current context
+ * \param d the struct value_desc that describes the enum
+ * \param v pointer to the tmp declared in the calling glGet*v() function
+ */
+static void
+find_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
+{
+ struct gl_buffer_object *buffer_obj;
+ struct gl_client_array *array;
+ GLuint unit, *p;
+
+ switch (d->pname) {
+ case GL_TEXTURE_1D:
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_3D:
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ case GL_TEXTURE_RECTANGLE_NV:
+ v->value_bool = _mesa_IsEnabled(d->pname);
+ break;
+
+ case GL_LINE_STIPPLE_PATTERN:
+ /* This is the only GLushort, special case it here by promoting
+ * to an int rather than introducing a new type. */
+ v->value_int = ctx->Line.StipplePattern;
+ break;
+
+ case GL_CURRENT_RASTER_TEXTURE_COORDS:
+ unit = ctx->Texture.CurrentUnit;
+ v->value_float_4[0] = ctx->Current.RasterTexCoords[unit][0];
+ v->value_float_4[1] = ctx->Current.RasterTexCoords[unit][1];
+ v->value_float_4[2] = ctx->Current.RasterTexCoords[unit][2];
+ v->value_float_4[3] = ctx->Current.RasterTexCoords[unit][3];
+ break;
+
+ case GL_CURRENT_TEXTURE_COORDS:
+ unit = ctx->Texture.CurrentUnit;
+ v->value_float_4[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0];
+ v->value_float_4[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1];
+ v->value_float_4[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2];
+ v->value_float_4[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3];
+ break;
+
+ case GL_COLOR_WRITEMASK:
+ v->value_int_4[0] = ctx->Color.ColorMask[0][RCOMP] ? 1 : 0;
+ v->value_int_4[1] = ctx->Color.ColorMask[0][GCOMP] ? 1 : 0;
+ v->value_int_4[2] = ctx->Color.ColorMask[0][BCOMP] ? 1 : 0;
+ v->value_int_4[3] = ctx->Color.ColorMask[0][ACOMP] ? 1 : 0;
+ break;
+
+ case GL_EDGE_FLAG:
+ v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0;
+ break;
+
+ case GL_READ_BUFFER:
+ v->value_enum = ctx->ReadBuffer->ColorReadBuffer;
+ break;
+
+ case GL_MAP2_GRID_DOMAIN:
+ v->value_float_4[0] = ctx->Eval.MapGrid2u1;
+ v->value_float_4[1] = ctx->Eval.MapGrid2u2;
+ v->value_float_4[2] = ctx->Eval.MapGrid2v1;
+ v->value_float_4[3] = ctx->Eval.MapGrid2v2;
+ break;
+
+ case GL_TEXTURE_STACK_DEPTH:
+ unit = ctx->Texture.CurrentUnit;
+ v->value_int = ctx->TextureMatrixStack[unit].Depth + 1;
+ break;
+ case GL_TEXTURE_MATRIX:
+ unit = ctx->Texture.CurrentUnit;
+ v->value_matrix = ctx->TextureMatrixStack[unit].Top;
+ break;
+
+ case GL_TEXTURE_COORD_ARRAY:
+ case GL_TEXTURE_COORD_ARRAY_SIZE:
+ case GL_TEXTURE_COORD_ARRAY_TYPE:
+ case GL_TEXTURE_COORD_ARRAY_STRIDE:
+ array = &ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture];
+ v->value_int = *(GLuint *) ((char *) array + d->offset);
+ break;
+
+ case GL_ACTIVE_TEXTURE_ARB:
+ v->value_int = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
+ break;
+ case GL_CLIENT_ACTIVE_TEXTURE_ARB:
+ v->value_int = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
+ break;
+
+ case GL_MODELVIEW_STACK_DEPTH:
+ case GL_PROJECTION_STACK_DEPTH:
+ v->value_int = *(GLint *) ((char *) ctx + d->offset) + 1;
+ break;
+
+ case GL_MAX_TEXTURE_SIZE:
+ case GL_MAX_3D_TEXTURE_SIZE:
+ case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
+ p = (GLuint *) ((char *) ctx + d->offset);
+ v->value_int = 1 << (*p - 1);
+ break;
+
+ case GL_SCISSOR_BOX:
+ v->value_int_4[0] = ctx->Scissor.X;
+ v->value_int_4[1] = ctx->Scissor.Y;
+ v->value_int_4[2] = ctx->Scissor.Width;
+ v->value_int_4[3] = ctx->Scissor.Height;
+ break;
+
+ case GL_LIST_INDEX:
+ v->value_int =
+ ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0;
+ break;
+ case GL_LIST_MODE:
+ if (!ctx->CompileFlag)
+ v->value_enum = 0;
+ else if (ctx->ExecuteFlag)
+ v->value_enum = GL_COMPILE_AND_EXECUTE;
+ else
+ v->value_enum = GL_COMPILE;
+ break;
+
+ case GL_VIEWPORT:
+ v->value_int_4[0] = ctx->Viewport.X;
+ v->value_int_4[1] = ctx->Viewport.Y;
+ v->value_int_4[2] = ctx->Viewport.Width;
+ v->value_int_4[3] = ctx->Viewport.Height;
+ break;
+
+ case GL_ACTIVE_STENCIL_FACE_EXT:
+ v->value_enum = ctx->Stencil.ActiveFace ? GL_BACK : GL_FRONT;
+ break;
+
+ case GL_STENCIL_FAIL:
+ v->value_enum = ctx->Stencil.FailFunc[ctx->Stencil.ActiveFace];
+ break;
+ case GL_STENCIL_FUNC:
+ v->value_enum = ctx->Stencil.Function[ctx->Stencil.ActiveFace];
+ break;
+ case GL_STENCIL_PASS_DEPTH_FAIL:
+ v->value_enum = ctx->Stencil.ZFailFunc[ctx->Stencil.ActiveFace];
+ break;
+ case GL_STENCIL_PASS_DEPTH_PASS:
+ v->value_enum = ctx->Stencil.ZPassFunc[ctx->Stencil.ActiveFace];
+ break;
+ case GL_STENCIL_REF:
+ v->value_int = ctx->Stencil.Ref[ctx->Stencil.ActiveFace];
+ break;
+ case GL_STENCIL_VALUE_MASK:
+ v->value_int = ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace];
+ break;
+ case GL_STENCIL_WRITEMASK:
+ v->value_int = ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace];
+ break;
+
+ case GL_NUM_EXTENSIONS:
+ v->value_int = _mesa_get_extension_count(ctx);
+ break;
+
+ case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
+ v->value_int = _mesa_get_color_read_type(ctx);
+ break;
+ case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
+ v->value_int = _mesa_get_color_read_format(ctx);
+ break;
+
+ case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
+ v->value_int = ctx->CurrentStack->Depth + 1;
+ break;
+ case GL_CURRENT_MATRIX_ARB:
+ case GL_TRANSPOSE_CURRENT_MATRIX_ARB:
+ v->value_matrix = ctx->CurrentStack->Top;
+ break;
+
+ case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
+ v->value_int = _mesa_get_compressed_formats(ctx, NULL, GL_FALSE);
+ break;
+ case GL_COMPRESSED_TEXTURE_FORMATS_ARB:
+ v->value_int_n.n =
+ _mesa_get_compressed_formats(ctx, v->value_int_n.ints, GL_FALSE);
+ ASSERT(v->value_int_n.n <= 100);
+ break;
+
+ case GL_MAX_VARYING_FLOATS_ARB:
+ v->value_int = ctx->Const.MaxVarying * 4;
+ break;
+
+ /* Various object names */
+
+ case GL_TEXTURE_BINDING_1D:
+ case GL_TEXTURE_BINDING_2D:
+ case GL_TEXTURE_BINDING_3D:
+ case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
+ case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
+ case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
+ case GL_TEXTURE_BINDING_RECTANGLE_NV:
+ unit = ctx->Texture.CurrentUnit;
+ v->value_int =
+ ctx->Texture.Unit[unit].CurrentTex[d->offset]->Name;
+ break;
+
+ /* GL_ARB_vertex_buffer_object */
+ case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
+ case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
+ case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
+ case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
+ case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
+ case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
+ case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
+ buffer_obj = (struct gl_buffer_object *)
+ ((char *) ctx->Array.ArrayObj + d->offset);
+ v->value_int = buffer_obj->Name;
+ break;
+ case GL_ARRAY_BUFFER_BINDING_ARB:
+ v->value_int = ctx->Array.ArrayBufferObj->Name;
+ break;
+ case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
+ v->value_int =
+ ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].BufferObj->Name;
+ break;
+ case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
+ v->value_int = ctx->Array.ElementArrayBufferObj->Name;
+ break;
+
+ /* ARB_copy_buffer */
+ case GL_COPY_READ_BUFFER:
+ v->value_int = ctx->CopyReadBuffer->Name;
+ break;
+ case GL_COPY_WRITE_BUFFER:
+ v->value_int = ctx->CopyWriteBuffer->Name;
+ break;
+
+ case GL_FRAGMENT_PROGRAM_BINDING_NV:
+ v->value_int =
+ ctx->FragmentProgram.Current ? ctx->FragmentProgram.Current->Base.Id : 0;
+ break;
+ case GL_VERTEX_PROGRAM_BINDING_NV:
+ v->value_int =
+ ctx->VertexProgram.Current ? ctx->VertexProgram.Current->Base.Id : 0;
+ break;
+ case GL_PIXEL_PACK_BUFFER_BINDING_EXT:
+ v->value_int = ctx->Pack.BufferObj->Name;
+ break;
+ case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT:
+ v->value_int = ctx->Unpack.BufferObj->Name;
+ break;
+ case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
+ v->value_int = ctx->TransformFeedback.CurrentBuffer->Name;
+ break;
+ case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED:
+ v->value_int = ctx->TransformFeedback.CurrentObject->Paused;
+ break;
+ case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE:
+ v->value_int = ctx->TransformFeedback.CurrentObject->Active;
+ break;
+ case GL_TRANSFORM_FEEDBACK_BINDING:
+ v->value_int = ctx->TransformFeedback.CurrentObject->Name;
+ break;
+ case GL_CURRENT_PROGRAM:
+ v->value_int =
+ ctx->Shader.ActiveProgram ? ctx->Shader.ActiveProgram->Name : 0;
+ break;
+ case GL_READ_FRAMEBUFFER_BINDING_EXT:
+ v->value_int = ctx->ReadBuffer->Name;
+ break;
+ case GL_RENDERBUFFER_BINDING_EXT:
+ v->value_int =
+ ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
+ break;
+ case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
+ v->value_int = ctx->Array.ArrayObj->PointSize.BufferObj->Name;
+ break;
+
+ case GL_MAX_VERTEX_UNIFORM_VECTORS:
+ v->value_int = ctx->Const.VertexProgram.MaxUniformComponents / 4;
+ break;
+
+ case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
+ v->value_int = ctx->Const.FragmentProgram.MaxUniformComponents / 4;
+ break;
+ }
+}
+
+/**
+ * Check extra constraints on a struct value_desc descriptor
+ *
+ * If a struct value_desc has a non-NULL extra pointer, it means that
+ * there are a number of extra constraints to check or actions to
+ * perform. The extras is just an integer array where each integer
+ * encode different constraints or actions.
+ *
+ * \param ctx current context
+ * \param func name of calling glGet*v() function for error reporting
+ * \param d the struct value_desc that has the extra constraints
+ *
+ * \return GL_FALSE if one of the constraints was not satisfied,
+ * otherwise GL_TRUE.
+ */
+static GLboolean
+check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d)
+{
+ const GLuint version = ctx->VersionMajor * 10 + ctx->VersionMinor;
+ int total, enabled;
+ const int *e;
+
+ total = 0;
+ enabled = 0;
+ for (e = d->extra; *e != EXTRA_END; e++)
+ switch (*e) {
+ case EXTRA_VERSION_30:
+ if (version >= 30) {
+ total++;
+ enabled++;
+ }
+ break;
+ case EXTRA_VERSION_31:
+ if (version >= 31) {
+ total++;
+ enabled++;
+ }
+ break;
+ case EXTRA_VERSION_32:
+ if (version >= 32) {
+ total++;
+ enabled++;
+ }
+ break;
+ case EXTRA_VERSION_ES2:
+ if (ctx->API == API_OPENGLES2) {
+ total++;
+ enabled++;
+ }
+ break;
+ case EXTRA_NEW_BUFFERS:
+ if (ctx->NewState & _NEW_BUFFERS)
+ _mesa_update_state(ctx);
+ break;
+ case EXTRA_FLUSH_CURRENT:
+ FLUSH_CURRENT(ctx, 0);
+ break;
+ case EXTRA_VALID_DRAW_BUFFER:
+ if (d->pname - GL_DRAW_BUFFER0_ARB >= ctx->Const.MaxDrawBuffers) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(draw buffer %u)",
+ func, d->pname - GL_DRAW_BUFFER0_ARB);
+ return GL_FALSE;
+ }
+ break;
+ case EXTRA_VALID_TEXTURE_UNIT:
+ if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture %u)",
+ func, ctx->Texture.CurrentUnit);
+ return GL_FALSE;
+ }
+ break;
+ case EXTRA_END:
+ break;
+ default: /* *e is a offset into the extension struct */
+ total++;
+ if (*(GLboolean *) ((char *) &ctx->Extensions + *e))
+ enabled++;
+ break;
+ }
+
+ if (total > 0 && enabled == 0) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
+ _mesa_lookup_enum_by_nr(d->pname));
+ return GL_FALSE;
+ }
+
+ return GL_TRUE;
+}
+
+static const struct value_desc error_value =
+ { 0, 0, TYPE_INVALID, NO_OFFSET, NO_EXTRA };
+
+/**
+ * Find the struct value_desc corresponding to the enum 'pname'.
+ *
+ * We hash the enum value to get an index into the 'table' array,
+ * which holds the index in the 'values' array of struct value_desc.
+ * Once we've found the entry, we do the extra checks, if any, then
+ * look up the value and return a pointer to it.
+ *
+ * If the value has to be computed (for example, it's the result of a
+ * function call or we need to add 1 to it), we use the tmp 'v' to
+ * store the result.
+ *
+ * \param func name of glGet*v() func for error reporting
+ * \param pname the enum value we're looking up
+ * \param p is were we return the pointer to the value
+ * \param v a tmp union value variable in the calling glGet*v() function
+ *
+ * \return the struct value_desc corresponding to the enum or a struct
+ * value_desc of TYPE_INVALID if not found. This lets the calling
+ * glGet*v() function jump right into a switch statement and
+ * handle errors there instead of having to check for NULL.
+ */
+static const struct value_desc *
+find_value(const char *func, GLenum pname, void **p, union value *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_texture_unit *unit;
+ int mask, hash;
+ const struct value_desc *d;
+
+ mask = Elements(table) - 1;
+ hash = (pname * prime_factor);
+ while (1) {
+ d = &values[table[hash & mask]];
+
+ /* If the enum isn't valid, the hash walk ends with index 0,
+ * which is the API mask entry at the beginning of values[]. */
+ if (unlikely(d->type == TYPE_API_MASK)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
+ _mesa_lookup_enum_by_nr(pname));
+ return &error_value;
+ }
+
+ if (likely(d->pname == pname))
+ break;
+
+ hash += prime_step;
+ }
+
+ if (unlikely(d->extra && !check_extra(ctx, func, d)))
+ return &error_value;
+
+ switch (d->location) {
+ case LOC_BUFFER:
+ *p = ((char *) ctx->DrawBuffer + d->offset);
+ return d;
+ case LOC_CONTEXT:
+ *p = ((char *) ctx + d->offset);
+ return d;
+ case LOC_ARRAY:
+ *p = ((char *) ctx->Array.ArrayObj + d->offset);
+ return d;
+ case LOC_TEXUNIT:
+ unit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ *p = ((char *) unit + d->offset);
+ return d;
+ case LOC_CUSTOM:
+ find_custom_value(ctx, d, v);
+ *p = v;
+ return d;
+ default:
+ assert(0);
+ break;
+ }
+
+ /* silence warning */
+ return &error_value;
+}
+
+static const int transpose[] = {
+ 0, 4, 8, 12,
+ 1, 5, 9, 13,
+ 2, 6, 10, 14,
+ 3, 7, 11, 15
+};
+
+void GLAPIENTRY
+_mesa_GetBooleanv(GLenum pname, GLboolean *params)
+{
+ const struct value_desc *d;
+ union value v;
+ GLmatrix *m;
+ int shift, i;
+ void *p;
+
+ d = find_value("glGetBooleanv", pname, &p, &v);
+ switch (d->type) {
+ case TYPE_INVALID:
+ break;
+ case TYPE_CONST:
+ params[0] = INT_TO_BOOLEAN(d->offset);
+ break;
+
+ case TYPE_FLOAT_4:
+ case TYPE_FLOATN_4:
+ params[3] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[3]);
+ case TYPE_FLOAT_3:
+ case TYPE_FLOATN_3:
+ params[2] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[2]);
+ case TYPE_FLOAT_2:
+ case TYPE_FLOATN_2:
+ params[1] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[1]);
+ case TYPE_FLOAT:
+ case TYPE_FLOATN:
+ params[0] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[0]);
+ break;
+
+ case TYPE_DOUBLEN:
+ params[0] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[0]);
+ break;
+
+ case TYPE_INT_4:
+ params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
+ case TYPE_INT_3:
+ params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
+ case TYPE_INT_2:
+ case TYPE_ENUM_2:
+ params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
+ case TYPE_INT:
+ case TYPE_ENUM:
+ params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
+ break;
+
+ case TYPE_INT_N:
+ for (i = 0; i < v.value_int_n.n; i++)
+ params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
+ break;
+
+ case TYPE_INT64:
+ params[0] = INT64_TO_BOOLEAN(((GLint64 *) p)[0]);
+ break;
+
+ case TYPE_BOOLEAN:
+ params[0] = ((GLboolean*) p)[0];
+ break;
+
+ case TYPE_MATRIX:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = FLOAT_TO_BOOLEAN(m->m[i]);
+ break;
+
+ case TYPE_MATRIX_T:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = FLOAT_TO_BOOLEAN(m->m[transpose[i]]);
+ break;
+
+ case TYPE_BIT_0:
+ case TYPE_BIT_1:
+ case TYPE_BIT_2:
+ case TYPE_BIT_3:
+ case TYPE_BIT_4:
+ case TYPE_BIT_5:
+ shift = d->type - TYPE_BIT_0;
+ params[0] = (*(GLbitfield *) p >> shift) & 1;
+ break;
+ }
+}
+
+void GLAPIENTRY
+_mesa_GetFloatv(GLenum pname, GLfloat *params)
+{
+ const struct value_desc *d;
+ union value v;
+ GLmatrix *m;
+ int shift, i;
+ void *p;
+
+ d = find_value("glGetFloatv", pname, &p, &v);
+ switch (d->type) {
+ case TYPE_INVALID:
+ break;
+ case TYPE_CONST:
+ params[0] = (GLfloat) d->offset;
+ break;
+
+ case TYPE_FLOAT_4:
+ case TYPE_FLOATN_4:
+ params[3] = ((GLfloat *) p)[3];
+ case TYPE_FLOAT_3:
+ case TYPE_FLOATN_3:
+ params[2] = ((GLfloat *) p)[2];
+ case TYPE_FLOAT_2:
+ case TYPE_FLOATN_2:
+ params[1] = ((GLfloat *) p)[1];
+ case TYPE_FLOAT:
+ case TYPE_FLOATN:
+ params[0] = ((GLfloat *) p)[0];
+ break;
+
+ case TYPE_DOUBLEN:
+ params[0] = ((GLdouble *) p)[0];
+ break;
+
+ case TYPE_INT_4:
+ params[3] = (GLfloat) (((GLint *) p)[3]);
+ case TYPE_INT_3:
+ params[2] = (GLfloat) (((GLint *) p)[2]);
+ case TYPE_INT_2:
+ case TYPE_ENUM_2:
+ params[1] = (GLfloat) (((GLint *) p)[1]);
+ case TYPE_INT:
+ case TYPE_ENUM:
+ params[0] = (GLfloat) (((GLint *) p)[0]);
+ break;
+
+ case TYPE_INT_N:
+ for (i = 0; i < v.value_int_n.n; i++)
+ params[i] = INT_TO_FLOAT(v.value_int_n.ints[i]);
+ break;
+
+ case TYPE_INT64:
+ params[0] = ((GLint64 *) p)[0];
+ break;
+
+ case TYPE_BOOLEAN:
+ params[0] = BOOLEAN_TO_FLOAT(*(GLboolean*) p);
+ break;
+
+ case TYPE_MATRIX:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = m->m[i];
+ break;
+
+ case TYPE_MATRIX_T:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = m->m[transpose[i]];
+ break;
+
+ case TYPE_BIT_0:
+ case TYPE_BIT_1:
+ case TYPE_BIT_2:
+ case TYPE_BIT_3:
+ case TYPE_BIT_4:
+ case TYPE_BIT_5:
+ shift = d->type - TYPE_BIT_0;
+ params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);
+ break;
+ }
+}
+
+void GLAPIENTRY
+_mesa_GetIntegerv(GLenum pname, GLint *params)
+{
+ const struct value_desc *d;
+ union value v;
+ GLmatrix *m;
+ int shift, i;
+ void *p;
+
+ d = find_value("glGetIntegerv", pname, &p, &v);
+ switch (d->type) {
+ case TYPE_INVALID:
+ break;
+ case TYPE_CONST:
+ params[0] = d->offset;
+ break;
+
+ case TYPE_FLOAT_4:
+ params[3] = IROUND(((GLfloat *) p)[3]);
+ case TYPE_FLOAT_3:
+ params[2] = IROUND(((GLfloat *) p)[2]);
+ case TYPE_FLOAT_2:
+ params[1] = IROUND(((GLfloat *) p)[1]);
+ case TYPE_FLOAT:
+ params[0] = IROUND(((GLfloat *) p)[0]);
+ break;
+
+ case TYPE_FLOATN_4:
+ params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
+ case TYPE_FLOATN_3:
+ params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
+ case TYPE_FLOATN_2:
+ params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
+ case TYPE_FLOATN:
+ params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
+ break;
+
+ case TYPE_DOUBLEN:
+ params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
+ break;
+
+ case TYPE_INT_4:
+ params[3] = ((GLint *) p)[3];
+ case TYPE_INT_3:
+ params[2] = ((GLint *) p)[2];
+ case TYPE_INT_2:
+ case TYPE_ENUM_2:
+ params[1] = ((GLint *) p)[1];
+ case TYPE_INT:
+ case TYPE_ENUM:
+ params[0] = ((GLint *) p)[0];
+ break;
+
+ case TYPE_INT_N:
+ for (i = 0; i < v.value_int_n.n; i++)
+ params[i] = v.value_int_n.ints[i];
+ break;
+
+ case TYPE_INT64:
+ params[0] = INT64_TO_INT(((GLint64 *) p)[0]);
+ break;
+
+ case TYPE_BOOLEAN:
+ params[0] = BOOLEAN_TO_INT(*(GLboolean*) p);
+ break;
+
+ case TYPE_MATRIX:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = FLOAT_TO_INT(m->m[i]);
+ break;
+
+ case TYPE_MATRIX_T:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = FLOAT_TO_INT(m->m[transpose[i]]);
+ break;
+
+ case TYPE_BIT_0:
+ case TYPE_BIT_1:
+ case TYPE_BIT_2:
+ case TYPE_BIT_3:
+ case TYPE_BIT_4:
+ case TYPE_BIT_5:
+ shift = d->type - TYPE_BIT_0;
+ params[0] = (*(GLbitfield *) p >> shift) & 1;
+ break;
+ }
+}
+
+#if FEATURE_ARB_sync
+void GLAPIENTRY
+_mesa_GetInteger64v(GLenum pname, GLint64 *params)
+{
+ const struct value_desc *d;
+ union value v;
+ GLmatrix *m;
+ int shift, i;
+ void *p;
+
+ d = find_value("glGetInteger64v", pname, &p, &v);
+ switch (d->type) {
+ case TYPE_INVALID:
+ break;
+ case TYPE_CONST:
+ params[0] = d->offset;
+ break;
+
+ case TYPE_FLOAT_4:
+ params[3] = IROUND64(((GLfloat *) p)[3]);
+ case TYPE_FLOAT_3:
+ params[2] = IROUND64(((GLfloat *) p)[2]);
+ case TYPE_FLOAT_2:
+ params[1] = IROUND64(((GLfloat *) p)[1]);
+ case TYPE_FLOAT:
+ params[0] = IROUND64(((GLfloat *) p)[0]);
+ break;
+
+ case TYPE_FLOATN_4:
+ params[3] = FLOAT_TO_INT64(((GLfloat *) p)[3]);
+ case TYPE_FLOATN_3:
+ params[2] = FLOAT_TO_INT64(((GLfloat *) p)[2]);
+ case TYPE_FLOATN_2:
+ params[1] = FLOAT_TO_INT64(((GLfloat *) p)[1]);
+ case TYPE_FLOATN:
+ params[0] = FLOAT_TO_INT64(((GLfloat *) p)[0]);
+ break;
+
+ case TYPE_DOUBLEN:
+ params[0] = FLOAT_TO_INT64(((GLdouble *) p)[0]);
+ break;
+
+ case TYPE_INT_4:
+ params[3] = ((GLint *) p)[3];
+ case TYPE_INT_3:
+ params[2] = ((GLint *) p)[2];
+ case TYPE_INT_2:
+ case TYPE_ENUM_2:
+ params[1] = ((GLint *) p)[1];
+ case TYPE_INT:
+ case TYPE_ENUM:
+ params[0] = ((GLint *) p)[0];
+ break;
+
+ case TYPE_INT_N:
+ for (i = 0; i < v.value_int_n.n; i++)
+ params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
+ break;
+
+ case TYPE_INT64:
+ params[0] = ((GLint64 *) p)[0];
+ break;
+
+ case TYPE_BOOLEAN:
+ params[0] = ((GLboolean*) p)[0];
+ break;
+
+ case TYPE_MATRIX:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = FLOAT_TO_INT64(m->m[i]);
+ break;
+
+ case TYPE_MATRIX_T:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = FLOAT_TO_INT64(m->m[transpose[i]]);
+ break;
+
+ case TYPE_BIT_0:
+ case TYPE_BIT_1:
+ case TYPE_BIT_2:
+ case TYPE_BIT_3:
+ case TYPE_BIT_4:
+ case TYPE_BIT_5:
+ shift = d->type - TYPE_BIT_0;
+ params[0] = (*(GLbitfield *) p >> shift) & 1;
+ break;
+ }
+}
+#endif /* FEATURE_ARB_sync */
+
+void GLAPIENTRY
+_mesa_GetDoublev(GLenum pname, GLdouble *params)
+{
+ const struct value_desc *d;
+ union value v;
+ GLmatrix *m;
+ int shift, i;
+ void *p;
+
+ d = find_value("glGetDoublev", pname, &p, &v);
+ switch (d->type) {
+ case TYPE_INVALID:
+ break;
+ case TYPE_CONST:
+ params[0] = d->offset;
+ break;
+
+ case TYPE_FLOAT_4:
+ case TYPE_FLOATN_4:
+ params[3] = ((GLfloat *) p)[3];
+ case TYPE_FLOAT_3:
+ case TYPE_FLOATN_3:
+ params[2] = ((GLfloat *) p)[2];
+ case TYPE_FLOAT_2:
+ case TYPE_FLOATN_2:
+ params[1] = ((GLfloat *) p)[1];
+ case TYPE_FLOAT:
+ case TYPE_FLOATN:
+ params[0] = ((GLfloat *) p)[0];
+ break;
+
+ case TYPE_DOUBLEN:
+ params[0] = ((GLdouble *) p)[0];
+ break;
+
+ case TYPE_INT_4:
+ params[3] = ((GLint *) p)[3];
+ case TYPE_INT_3:
+ params[2] = ((GLint *) p)[2];
+ case TYPE_INT_2:
+ case TYPE_ENUM_2:
+ params[1] = ((GLint *) p)[1];
+ case TYPE_INT:
+ case TYPE_ENUM:
+ params[0] = ((GLint *) p)[0];
+ break;
+
+ case TYPE_INT_N:
+ for (i = 0; i < v.value_int_n.n; i++)
+ params[i] = v.value_int_n.ints[i];
+ break;
+
+ case TYPE_INT64:
+ params[0] = ((GLint64 *) p)[0];
+ break;
+
+ case TYPE_BOOLEAN:
+ params[0] = *(GLboolean*) p;
+ break;
+
+ case TYPE_MATRIX:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = m->m[i];
+ break;
+
+ case TYPE_MATRIX_T:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = m->m[transpose[i]];
+ break;
+
+ case TYPE_BIT_0:
+ case TYPE_BIT_1:
+ case TYPE_BIT_2:
+ case TYPE_BIT_3:
+ case TYPE_BIT_4:
+ case TYPE_BIT_5:
+ shift = d->type - TYPE_BIT_0;
+ params[0] = (*(GLbitfield *) p >> shift) & 1;
+ break;
+ }
+}
+
+static enum value_type
+find_value_indexed(const char *func, GLenum pname, int index, union value *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ switch (pname) {
+
+ case GL_BLEND:
+ if (index >= ctx->Const.MaxDrawBuffers)
+ goto invalid_value;
+ if (!ctx->Extensions.EXT_draw_buffers2)
+ goto invalid_enum;
+ v->value_int = (ctx->Color.BlendEnabled >> index) & 1;
+ return TYPE_INT;
+
+ case GL_BLEND_SRC:
+ /* fall-through */
+ case GL_BLEND_SRC_RGB:
+ if (index >= ctx->Const.MaxDrawBuffers)
+ goto invalid_value;
+ if (!ctx->Extensions.ARB_draw_buffers_blend)
+ goto invalid_enum;
+ v->value_int = ctx->Color.Blend[index].SrcRGB;
+ return TYPE_INT;
+ case GL_BLEND_SRC_ALPHA:
+ if (index >= ctx->Const.MaxDrawBuffers)
+ goto invalid_value;
+ if (!ctx->Extensions.ARB_draw_buffers_blend)
+ goto invalid_enum;
+ v->value_int = ctx->Color.Blend[index].SrcA;
+ return TYPE_INT;
+ case GL_BLEND_DST:
+ /* fall-through */
+ case GL_BLEND_DST_RGB:
+ if (index >= ctx->Const.MaxDrawBuffers)
+ goto invalid_value;
+ if (!ctx->Extensions.ARB_draw_buffers_blend)
+ goto invalid_enum;
+ v->value_int = ctx->Color.Blend[index].DstRGB;
+ return TYPE_INT;
+ case GL_BLEND_DST_ALPHA:
+ if (index >= ctx->Const.MaxDrawBuffers)
+ goto invalid_value;
+ if (!ctx->Extensions.ARB_draw_buffers_blend)
+ goto invalid_enum;
+ v->value_int = ctx->Color.Blend[index].DstA;
+ return TYPE_INT;
+ case GL_BLEND_EQUATION_RGB:
+ if (index >= ctx->Const.MaxDrawBuffers)
+ goto invalid_value;
+ if (!ctx->Extensions.ARB_draw_buffers_blend)
+ goto invalid_enum;
+ v->value_int = ctx->Color.Blend[index].EquationRGB;
+ return TYPE_INT;
+ case GL_BLEND_EQUATION_ALPHA:
+ if (index >= ctx->Const.MaxDrawBuffers)
+ goto invalid_value;
+ if (!ctx->Extensions.ARB_draw_buffers_blend)
+ goto invalid_enum;
+ v->value_int = ctx->Color.Blend[index].EquationA;
+ return TYPE_INT;
+
+ case GL_COLOR_WRITEMASK:
+ if (index >= ctx->Const.MaxDrawBuffers)
+ goto invalid_value;
+ if (!ctx->Extensions.EXT_draw_buffers2)
+ goto invalid_enum;
+ v->value_int_4[0] = ctx->Color.ColorMask[index][RCOMP] ? 1 : 0;
+ v->value_int_4[1] = ctx->Color.ColorMask[index][GCOMP] ? 1 : 0;
+ v->value_int_4[2] = ctx->Color.ColorMask[index][BCOMP] ? 1 : 0;
+ v->value_int_4[3] = ctx->Color.ColorMask[index][ACOMP] ? 1 : 0;
+ return TYPE_INT_4;
+
+ case GL_TRANSFORM_FEEDBACK_BUFFER_START:
+ if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs)
+ goto invalid_value;
+ if (!ctx->Extensions.EXT_transform_feedback)
+ goto invalid_enum;
+ v->value_int64 = ctx->TransformFeedback.CurrentObject->Offset[index];
+ return TYPE_INT64;
+
+ case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
+ if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs)
+ goto invalid_value;
+ if (!ctx->Extensions.EXT_transform_feedback)
+ goto invalid_enum;
+ v->value_int64 = ctx->TransformFeedback.CurrentObject->Size[index];
+ return TYPE_INT64;
+
+ case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
+ if (index >= ctx->Const.MaxTransformFeedbackSeparateAttribs)
+ goto invalid_value;
+ if (!ctx->Extensions.EXT_transform_feedback)
+ goto invalid_enum;
+ v->value_int = ctx->TransformFeedback.CurrentObject->Buffers[index]->Name;
+ return TYPE_INT;
+ }
+
+ invalid_enum:
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
+ _mesa_lookup_enum_by_nr(pname));
+ return TYPE_INVALID;
+ invalid_value:
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s)", func,
+ _mesa_lookup_enum_by_nr(pname));
+ return TYPE_INVALID;
+}
+
+void GLAPIENTRY
+_mesa_GetBooleanIndexedv( GLenum pname, GLuint index, GLboolean *params )
+{
+ union value v;
+ enum value_type type =
+ find_value_indexed("glGetBooleanIndexedv", pname, index, &v);
+
+ switch (type) {
+ case TYPE_INT:
+ params[0] = INT_TO_BOOLEAN(v.value_int);
+ break;
+ case TYPE_INT_4:
+ params[0] = INT_TO_BOOLEAN(v.value_int_4[0]);
+ params[1] = INT_TO_BOOLEAN(v.value_int_4[1]);
+ params[2] = INT_TO_BOOLEAN(v.value_int_4[2]);
+ params[3] = INT_TO_BOOLEAN(v.value_int_4[3]);
+ break;
+ case TYPE_INT64:
+ params[0] = INT64_TO_BOOLEAN(v.value_int);
+ break;
+ default:
+ ; /* nothing - GL error was recorded */
+ }
+}
+
+void GLAPIENTRY
+_mesa_GetIntegerIndexedv( GLenum pname, GLuint index, GLint *params )
+{
+ union value v;
+ enum value_type type =
+ find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
+
+ switch (type) {
+ case TYPE_INT:
+ params[0] = v.value_int;
+ break;
+ case TYPE_INT_4:
+ params[0] = v.value_int_4[0];
+ params[1] = v.value_int_4[1];
+ params[2] = v.value_int_4[2];
+ params[3] = v.value_int_4[3];
+ break;
+ case TYPE_INT64:
+ params[0] = INT64_TO_INT(v.value_int);
+ break;
+ default:
+ ; /* nothing - GL error was recorded */
+ }
+}
+
+#if FEATURE_ARB_sync
+void GLAPIENTRY
+_mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params )
+{
+ union value v;
+ enum value_type type =
+ find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
+
+ switch (type) {
+ case TYPE_INT:
+ params[0] = v.value_int;
+ break;
+ case TYPE_INT_4:
+ params[0] = v.value_int_4[0];
+ params[1] = v.value_int_4[1];
+ params[2] = v.value_int_4[2];
+ params[3] = v.value_int_4[3];
+ break;
+ case TYPE_INT64:
+ params[0] = v.value_int;
+ break;
+ default:
+ ; /* nothing - GL error was recorded */
+ }
+}
+#endif /* FEATURE_ARB_sync */
+
+#if FEATURE_ES1
+void GLAPIENTRY
+_mesa_GetFixedv(GLenum pname, GLfixed *params)
+{
+ const struct value_desc *d;
+ union value v;
+ GLmatrix *m;
+ int shift, i;
+ void *p;
+
+ d = find_value("glGetDoublev", pname, &p, &v);
+ switch (d->type) {
+ case TYPE_INVALID:
+ break;
+ case TYPE_CONST:
+ params[0] = INT_TO_FIXED(d->offset);
+ break;
+
+ case TYPE_FLOAT_4:
+ case TYPE_FLOATN_4:
+ params[3] = FLOAT_TO_FIXED(((GLfloat *) p)[3]);
+ case TYPE_FLOAT_3:
+ case TYPE_FLOATN_3:
+ params[2] = FLOAT_TO_FIXED(((GLfloat *) p)[2]);
+ case TYPE_FLOAT_2:
+ case TYPE_FLOATN_2:
+ params[1] = FLOAT_TO_FIXED(((GLfloat *) p)[1]);
+ case TYPE_FLOAT:
+ case TYPE_FLOATN:
+ params[0] = FLOAT_TO_FIXED(((GLfloat *) p)[0]);
+ break;
+
+ case TYPE_DOUBLEN:
+ params[0] = FLOAT_TO_FIXED(((GLdouble *) p)[0]);
+ break;
+
+ case TYPE_INT_4:
+ params[3] = INT_TO_FIXED(((GLint *) p)[3]);
+ case TYPE_INT_3:
+ params[2] = INT_TO_FIXED(((GLint *) p)[2]);
+ case TYPE_INT_2:
+ case TYPE_ENUM_2:
+ params[1] = INT_TO_FIXED(((GLint *) p)[1]);
+ case TYPE_INT:
+ case TYPE_ENUM:
+ params[0] = INT_TO_FIXED(((GLint *) p)[0]);
+ break;
+
+ case TYPE_INT_N:
+ for (i = 0; i < v.value_int_n.n; i++)
+ params[i] = INT_TO_FIXED(v.value_int_n.ints[i]);
+ break;
+
+ case TYPE_INT64:
+ params[0] = ((GLint64 *) p)[0];
+ break;
+
+ case TYPE_BOOLEAN:
+ params[0] = BOOLEAN_TO_FIXED(((GLboolean*) p)[0]);
+ break;
+
+ case TYPE_MATRIX:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = FLOAT_TO_FIXED(m->m[i]);
+ break;
+
+ case TYPE_MATRIX_T:
+ m = *(GLmatrix **) p;
+ for (i = 0; i < 16; i++)
+ params[i] = FLOAT_TO_FIXED(m->m[transpose[i]]);
+ break;
+
+ case TYPE_BIT_0:
+ case TYPE_BIT_1:
+ case TYPE_BIT_2:
+ case TYPE_BIT_3:
+ case TYPE_BIT_4:
+ case TYPE_BIT_5:
+ shift = d->type - TYPE_BIT_0;
+ params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);
+ break;
+ }
+}
+#endif
diff --git a/mesalib/src/mesa/main/hint.c b/mesalib/src/mesa/main/hint.c
index ff8d88fff..aea0d7022 100644
--- a/mesalib/src/mesa/main/hint.c
+++ b/mesalib/src/mesa/main/hint.c
@@ -1,147 +1,147 @@
-
-/*
- * Mesa 3-D graphics library
- * Version: 4.1
- *
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "glheader.h"
-#include "enums.h"
-#include "context.h"
-#include "hint.h"
-#include "imports.h"
-#include "mtypes.h"
-
-
-
-void GLAPIENTRY
-_mesa_Hint( GLenum target, GLenum mode )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glHint %s %s\n",
- _mesa_lookup_enum_by_nr(target),
- _mesa_lookup_enum_by_nr(mode));
-
- if (mode != GL_NICEST && mode != GL_FASTEST && mode != GL_DONT_CARE) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glHint(mode)");
- return;
- }
-
- switch (target) {
- case GL_FOG_HINT:
- if (ctx->Hint.Fog == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_HINT);
- ctx->Hint.Fog = mode;
- break;
- case GL_LINE_SMOOTH_HINT:
- if (ctx->Hint.LineSmooth == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_HINT);
- ctx->Hint.LineSmooth = mode;
- break;
- case GL_PERSPECTIVE_CORRECTION_HINT:
- if (ctx->Hint.PerspectiveCorrection == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_HINT);
- ctx->Hint.PerspectiveCorrection = mode;
- break;
- case GL_POINT_SMOOTH_HINT:
- if (ctx->Hint.PointSmooth == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_HINT);
- ctx->Hint.PointSmooth = mode;
- break;
- case GL_POLYGON_SMOOTH_HINT:
- if (ctx->Hint.PolygonSmooth == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_HINT);
- ctx->Hint.PolygonSmooth = mode;
- break;
-
- /* GL_EXT_clip_volume_hint */
- case GL_CLIP_VOLUME_CLIPPING_HINT_EXT:
- if (ctx->Hint.ClipVolumeClipping == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_HINT);
- ctx->Hint.ClipVolumeClipping = mode;
- break;
-
- /* GL_ARB_texture_compression */
- case GL_TEXTURE_COMPRESSION_HINT_ARB:
- if (ctx->Hint.TextureCompression == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_HINT);
- ctx->Hint.TextureCompression = mode;
- break;
-
- /* GL_SGIS_generate_mipmap */
- case GL_GENERATE_MIPMAP_HINT_SGIS:
- if (ctx->Hint.GenerateMipmap == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_HINT);
- ctx->Hint.GenerateMipmap = mode;
- break;
-
- /* GL_ARB_fragment_shader */
- case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB:
- if (!ctx->Extensions.ARB_fragment_shader) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glHint(target)");
- return;
- }
- if (ctx->Hint.FragmentShaderDerivative == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_HINT);
- ctx->Hint.FragmentShaderDerivative = mode;
- break;
-
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glHint(target)");
- return;
- }
-
- if (ctx->Driver.Hint) {
- (*ctx->Driver.Hint)( ctx, target, mode );
- }
-}
-
-
-/**********************************************************************/
-/***** Initialization *****/
-/**********************************************************************/
-
-void _mesa_init_hint( struct gl_context * ctx )
-{
- /* Hint group */
- ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
- ctx->Hint.PointSmooth = GL_DONT_CARE;
- ctx->Hint.LineSmooth = GL_DONT_CARE;
- ctx->Hint.PolygonSmooth = GL_DONT_CARE;
- ctx->Hint.Fog = GL_DONT_CARE;
- ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
- ctx->Hint.TextureCompression = GL_DONT_CARE;
- ctx->Hint.GenerateMipmap = GL_DONT_CARE;
- ctx->Hint.FragmentShaderDerivative = GL_DONT_CARE;
-}
+
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.1
+ *
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "glheader.h"
+#include "enums.h"
+#include "context.h"
+#include "hint.h"
+#include "imports.h"
+#include "mtypes.h"
+
+
+
+void GLAPIENTRY
+_mesa_Hint( GLenum target, GLenum mode )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glHint %s %s\n",
+ _mesa_lookup_enum_by_nr(target),
+ _mesa_lookup_enum_by_nr(mode));
+
+ if (mode != GL_NICEST && mode != GL_FASTEST && mode != GL_DONT_CARE) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glHint(mode)");
+ return;
+ }
+
+ switch (target) {
+ case GL_FOG_HINT:
+ if (ctx->Hint.Fog == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_HINT);
+ ctx->Hint.Fog = mode;
+ break;
+ case GL_LINE_SMOOTH_HINT:
+ if (ctx->Hint.LineSmooth == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_HINT);
+ ctx->Hint.LineSmooth = mode;
+ break;
+ case GL_PERSPECTIVE_CORRECTION_HINT:
+ if (ctx->Hint.PerspectiveCorrection == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_HINT);
+ ctx->Hint.PerspectiveCorrection = mode;
+ break;
+ case GL_POINT_SMOOTH_HINT:
+ if (ctx->Hint.PointSmooth == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_HINT);
+ ctx->Hint.PointSmooth = mode;
+ break;
+ case GL_POLYGON_SMOOTH_HINT:
+ if (ctx->Hint.PolygonSmooth == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_HINT);
+ ctx->Hint.PolygonSmooth = mode;
+ break;
+
+ /* GL_EXT_clip_volume_hint */
+ case GL_CLIP_VOLUME_CLIPPING_HINT_EXT:
+ if (ctx->Hint.ClipVolumeClipping == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_HINT);
+ ctx->Hint.ClipVolumeClipping = mode;
+ break;
+
+ /* GL_ARB_texture_compression */
+ case GL_TEXTURE_COMPRESSION_HINT_ARB:
+ if (ctx->Hint.TextureCompression == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_HINT);
+ ctx->Hint.TextureCompression = mode;
+ break;
+
+ /* GL_SGIS_generate_mipmap */
+ case GL_GENERATE_MIPMAP_HINT_SGIS:
+ if (ctx->Hint.GenerateMipmap == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_HINT);
+ ctx->Hint.GenerateMipmap = mode;
+ break;
+
+ /* GL_ARB_fragment_shader */
+ case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB:
+ if (!ctx->Extensions.ARB_fragment_shader) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glHint(target)");
+ return;
+ }
+ if (ctx->Hint.FragmentShaderDerivative == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_HINT);
+ ctx->Hint.FragmentShaderDerivative = mode;
+ break;
+
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glHint(target)");
+ return;
+ }
+
+ if (ctx->Driver.Hint) {
+ (*ctx->Driver.Hint)( ctx, target, mode );
+ }
+}
+
+
+/**********************************************************************/
+/***** Initialization *****/
+/**********************************************************************/
+
+void _mesa_init_hint( struct gl_context * ctx )
+{
+ /* Hint group */
+ ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
+ ctx->Hint.PointSmooth = GL_DONT_CARE;
+ ctx->Hint.LineSmooth = GL_DONT_CARE;
+ ctx->Hint.PolygonSmooth = GL_DONT_CARE;
+ ctx->Hint.Fog = GL_DONT_CARE;
+ ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
+ ctx->Hint.TextureCompression = GL_DONT_CARE;
+ ctx->Hint.GenerateMipmap = GL_DONT_CARE;
+ ctx->Hint.FragmentShaderDerivative = GL_DONT_CARE;
+}
diff --git a/mesalib/src/mesa/main/imports.c b/mesalib/src/mesa/main/imports.c
index bf89815f2..3f856402f 100644
--- a/mesalib/src/mesa/main/imports.c
+++ b/mesalib/src/mesa/main/imports.c
@@ -1,1028 +1,1028 @@
-/**
- * \file imports.c
- * Standard C library function wrappers.
- *
- * Imports are services which the device driver or window system or
- * operating system provides to the core renderer. The core renderer (Mesa)
- * will call these functions in order to do memory allocation, simple I/O,
- * etc.
- *
- * Some drivers will want to override/replace this file with something
- * specialized, but that'll be rare.
- *
- * Eventually, I want to move roll the glheader.h file into this.
- *
- * \todo Functions still needed:
- * - scanf
- * - qsort
- * - rand and RAND_MAX
- */
-
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-
-#include "imports.h"
-#include "context.h"
-#include "mtypes.h"
-#include "version.h"
-
-#ifdef _GNU_SOURCE
-#include <locale.h>
-#ifdef __APPLE__
-#include <xlocale.h>
-#endif
-#endif
-
-
-#define MAXSTRING 4000 /* for vsnprintf() */
-
-#ifdef WIN32
-#define vsnprintf _vsnprintf
-#elif defined(__IBMC__) || defined(__IBMCPP__) || ( defined(__VMS) && __CRTL_VER < 70312000 )
-extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
-#ifdef __VMS
-#include "vsnprintf.c"
-#endif
-#endif
-
-/**********************************************************************/
-/** \name Memory */
-/*@{*/
-
-/**
- * Allocate aligned memory.
- *
- * \param bytes number of bytes to allocate.
- * \param alignment alignment (must be greater than zero).
- *
- * Allocates extra memory to accommodate rounding up the address for
- * alignment and to record the real malloc address.
- *
- * \sa _mesa_align_free().
- */
-void *
-_mesa_align_malloc(size_t bytes, unsigned long alignment)
-{
-#if defined(HAVE_POSIX_MEMALIGN)
- void *mem;
- int err = posix_memalign(& mem, alignment, bytes);
- if (err)
- return NULL;
- return mem;
-#elif defined(_WIN32) && defined(_MSC_VER)
- return _aligned_malloc(bytes, alignment);
-#else
- uintptr_t ptr, buf;
-
- ASSERT( alignment > 0 );
-
- ptr = (uintptr_t) malloc(bytes + alignment + sizeof(void *));
- if (!ptr)
- return NULL;
-
- buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
- *(uintptr_t *)(buf - sizeof(void *)) = ptr;
-
-#ifdef DEBUG
- /* mark the non-aligned area */
- while ( ptr < buf - sizeof(void *) ) {
- *(unsigned long *)ptr = 0xcdcdcdcd;
- ptr += sizeof(unsigned long);
- }
-#endif
-
- return (void *) buf;
-#endif /* defined(HAVE_POSIX_MEMALIGN) */
-}
-
-/**
- * Same as _mesa_align_malloc(), but using calloc(1, ) instead of
- * malloc()
- */
-void *
-_mesa_align_calloc(size_t bytes, unsigned long alignment)
-{
-#if defined(HAVE_POSIX_MEMALIGN)
- void *mem;
-
- mem = _mesa_align_malloc(bytes, alignment);
- if (mem != NULL) {
- (void) memset(mem, 0, bytes);
- }
-
- return mem;
-#elif defined(_WIN32) && defined(_MSC_VER)
- void *mem;
-
- mem = _aligned_malloc(bytes, alignment);
- if (mem != NULL) {
- (void) memset(mem, 0, bytes);
- }
-
- return mem;
-#else
- uintptr_t ptr, buf;
-
- ASSERT( alignment > 0 );
-
- ptr = (uintptr_t) calloc(1, bytes + alignment + sizeof(void *));
- if (!ptr)
- return NULL;
-
- buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
- *(uintptr_t *)(buf - sizeof(void *)) = ptr;
-
-#ifdef DEBUG
- /* mark the non-aligned area */
- while ( ptr < buf - sizeof(void *) ) {
- *(unsigned long *)ptr = 0xcdcdcdcd;
- ptr += sizeof(unsigned long);
- }
-#endif
-
- return (void *)buf;
-#endif /* defined(HAVE_POSIX_MEMALIGN) */
-}
-
-/**
- * Free memory which was allocated with either _mesa_align_malloc()
- * or _mesa_align_calloc().
- * \param ptr pointer to the memory to be freed.
- * The actual address to free is stored in the word immediately before the
- * address the client sees.
- */
-void
-_mesa_align_free(void *ptr)
-{
-#if defined(HAVE_POSIX_MEMALIGN)
- free(ptr);
-#elif defined(_WIN32) && defined(_MSC_VER)
- _aligned_free(ptr);
-#else
- void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
- void *realAddr = *cubbyHole;
- free(realAddr);
-#endif /* defined(HAVE_POSIX_MEMALIGN) */
-}
-
-/**
- * Reallocate memory, with alignment.
- */
-void *
-_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
- unsigned long alignment)
-{
-#if defined(_WIN32) && defined(_MSC_VER)
- (void) oldSize;
- return _aligned_realloc(oldBuffer, newSize, alignment);
-#else
- const size_t copySize = (oldSize < newSize) ? oldSize : newSize;
- void *newBuf = _mesa_align_malloc(newSize, alignment);
- if (newBuf && oldBuffer && copySize > 0) {
- memcpy(newBuf, oldBuffer, copySize);
- }
- if (oldBuffer)
- _mesa_align_free(oldBuffer);
- return newBuf;
-#endif
-}
-
-
-
-/** Reallocate memory */
-void *
-_mesa_realloc(void *oldBuffer, size_t oldSize, size_t newSize)
-{
- const size_t copySize = (oldSize < newSize) ? oldSize : newSize;
- void *newBuffer = malloc(newSize);
- if (newBuffer && oldBuffer && copySize > 0)
- memcpy(newBuffer, oldBuffer, copySize);
- if (oldBuffer)
- free(oldBuffer);
- return newBuffer;
-}
-
-/**
- * Fill memory with a constant 16bit word.
- * \param dst destination pointer.
- * \param val value.
- * \param n number of words.
- */
-void
-_mesa_memset16( unsigned short *dst, unsigned short val, size_t n )
-{
- while (n-- > 0)
- *dst++ = val;
-}
-
-/*@}*/
-
-
-/**********************************************************************/
-/** \name Math */
-/*@{*/
-
-/** Wrapper around sqrt() */
-double
-_mesa_sqrtd(double x)
-{
- return sqrt(x);
-}
-
-
-/*
- * A High Speed, Low Precision Square Root
- * by Paul Lalonde and Robert Dawson
- * from "Graphics Gems", Academic Press, 1990
- *
- * SPARC implementation of a fast square root by table
- * lookup.
- * SPARC floating point format is as follows:
- *
- * BIT 31 30 23 22 0
- * sign exponent mantissa
- */
-static short sqrttab[0x100]; /* declare table of square roots */
-
-void
-_mesa_init_sqrt_table(void)
-{
-#if defined(USE_IEEE) && !defined(DEBUG)
- unsigned short i;
- fi_type fi; /* to access the bits of a float in C quickly */
- /* we use a union defined in glheader.h */
-
- for(i=0; i<= 0x7f; i++) {
- fi.i = 0;
-
- /*
- * Build a float with the bit pattern i as mantissa
- * and an exponent of 0, stored as 127
- */
-
- fi.i = (i << 16) | (127 << 23);
- fi.f = _mesa_sqrtd(fi.f);
-
- /*
- * Take the square root then strip the first 7 bits of
- * the mantissa into the table
- */
-
- sqrttab[i] = (fi.i & 0x7fffff) >> 16;
-
- /*
- * Repeat the process, this time with an exponent of
- * 1, stored as 128
- */
-
- fi.i = 0;
- fi.i = (i << 16) | (128 << 23);
- fi.f = sqrt(fi.f);
- sqrttab[i+0x80] = (fi.i & 0x7fffff) >> 16;
- }
-#else
- (void) sqrttab; /* silence compiler warnings */
-#endif /*HAVE_FAST_MATH*/
-}
-
-
-/**
- * Single precision square root.
- */
-float
-_mesa_sqrtf( float x )
-{
-#if defined(USE_IEEE) && !defined(DEBUG)
- fi_type num;
- /* to access the bits of a float in C
- * we use a union from glheader.h */
-
- short e; /* the exponent */
- if (x == 0.0F) return 0.0F; /* check for square root of 0 */
- num.f = x;
- e = (num.i >> 23) - 127; /* get the exponent - on a SPARC the */
- /* exponent is stored with 127 added */
- num.i &= 0x7fffff; /* leave only the mantissa */
- if (e & 0x01) num.i |= 0x800000;
- /* the exponent is odd so we have to */
- /* look it up in the second half of */
- /* the lookup table, so we set the */
- /* high bit */
- e >>= 1; /* divide the exponent by two */
- /* note that in C the shift */
- /* operators are sign preserving */
- /* for signed operands */
- /* Do the table lookup, based on the quaternary mantissa,
- * then reconstruct the result back into a float
- */
- num.i = ((sqrttab[num.i >> 16]) << 16) | ((e + 127) << 23);
-
- return num.f;
-#else
- return (float) _mesa_sqrtd((double) x);
-#endif
-}
-
-
-/**
- inv_sqrt - A single precision 1/sqrt routine for IEEE format floats.
- written by Josh Vanderhoof, based on newsgroup posts by James Van Buskirk
- and Vesa Karvonen.
-*/
-float
-_mesa_inv_sqrtf(float n)
-{
-#if defined(USE_IEEE) && !defined(DEBUG)
- float r0, x0, y0;
- float r1, x1, y1;
- float r2, x2, y2;
-#if 0 /* not used, see below -BP */
- float r3, x3, y3;
-#endif
- fi_type u;
- unsigned int magic;
-
- /*
- Exponent part of the magic number -
-
- We want to:
- 1. subtract the bias from the exponent,
- 2. negate it
- 3. divide by two (rounding towards -inf)
- 4. add the bias back
-
- Which is the same as subtracting the exponent from 381 and dividing
- by 2.
-
- floor(-(x - 127) / 2) + 127 = floor((381 - x) / 2)
- */
-
- magic = 381 << 23;
-
- /*
- Significand part of magic number -
-
- With the current magic number, "(magic - u.i) >> 1" will give you:
-
- for 1 <= u.f <= 2: 1.25 - u.f / 4
- for 2 <= u.f <= 4: 1.00 - u.f / 8
-
- This isn't a bad approximation of 1/sqrt. The maximum difference from
- 1/sqrt will be around .06. After three Newton-Raphson iterations, the
- maximum difference is less than 4.5e-8. (Which is actually close
- enough to make the following bias academic...)
-
- To get a better approximation you can add a bias to the magic
- number. For example, if you subtract 1/2 of the maximum difference in
- the first approximation (.03), you will get the following function:
-
- for 1 <= u.f <= 2: 1.22 - u.f / 4
- for 2 <= u.f <= 3.76: 0.97 - u.f / 8
- for 3.76 <= u.f <= 4: 0.72 - u.f / 16
- (The 3.76 to 4 range is where the result is < .5.)
-
- This is the closest possible initial approximation, but with a maximum
- error of 8e-11 after three NR iterations, it is still not perfect. If
- you subtract 0.0332281 instead of .03, the maximum error will be
- 2.5e-11 after three NR iterations, which should be about as close as
- is possible.
-
- for 1 <= u.f <= 2: 1.2167719 - u.f / 4
- for 2 <= u.f <= 3.73: 0.9667719 - u.f / 8
- for 3.73 <= u.f <= 4: 0.7167719 - u.f / 16
-
- */
-
- magic -= (int)(0.0332281 * (1 << 25));
-
- u.f = n;
- u.i = (magic - u.i) >> 1;
-
- /*
- Instead of Newton-Raphson, we use Goldschmidt's algorithm, which
- allows more parallelism. From what I understand, the parallelism
- comes at the cost of less precision, because it lets error
- accumulate across iterations.
- */
- x0 = 1.0f;
- y0 = 0.5f * n;
- r0 = u.f;
-
- x1 = x0 * r0;
- y1 = y0 * r0 * r0;
- r1 = 1.5f - y1;
-
- x2 = x1 * r1;
- y2 = y1 * r1 * r1;
- r2 = 1.5f - y2;
-
-#if 1
- return x2 * r2; /* we can stop here, and be conformant -BP */
-#else
- x3 = x2 * r2;
- y3 = y2 * r2 * r2;
- r3 = 1.5f - y3;
-
- return x3 * r3;
-#endif
-#else
- return (float) (1.0 / sqrt(n));
-#endif
-}
-
-#ifndef __GNUC__
-/**
- * Find the first bit set in a word.
- */
-int
-_mesa_ffs(int32_t i)
-{
-#if (defined(_WIN32) ) || defined(__IBMC__) || defined(__IBMCPP__)
- register int bit = 0;
- if (i != 0) {
- if ((i & 0xffff) == 0) {
- bit += 16;
- i >>= 16;
- }
- if ((i & 0xff) == 0) {
- bit += 8;
- i >>= 8;
- }
- if ((i & 0xf) == 0) {
- bit += 4;
- i >>= 4;
- }
- while ((i & 1) == 0) {
- bit++;
- i >>= 1;
- }
- bit++;
- }
- return bit;
-#else
- return ffs(i);
-#endif
-}
-
-
-/**
- * Find position of first bit set in given value.
- * XXX Warning: this function can only be used on 64-bit systems!
- * \return position of least-significant bit set, starting at 1, return zero
- * if no bits set.
- */
-int
-_mesa_ffsll(int64_t val)
-{
- int bit;
-
- assert(sizeof(val) == 8);
-
- bit = _mesa_ffs((int32_t)val);
- if (bit != 0)
- return bit;
-
- bit = _mesa_ffs((int32_t)(val >> 32));
- if (bit != 0)
- return 32 + bit;
-
- return 0;
-}
-
-
-#if ((_GNUC__ == 3 && __GNUC_MINOR__ < 4) || __GNUC__ < 4)
-/**
- * Return number of bits set in given GLuint.
- */
-unsigned int
-_mesa_bitcount(unsigned int n)
-{
- unsigned int bits;
- for (bits = 0; n > 0; n = n >> 1) {
- bits += (n & 1);
- }
- return bits;
-}
-#endif
-#endif
-
-
-/**
- * Convert a 4-byte float to a 2-byte half float.
- * Based on code from:
- * http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/008786.html
- */
-GLhalfARB
-_mesa_float_to_half(float val)
-{
- const fi_type fi = {val};
- const int flt_m = fi.i & 0x7fffff;
- const int flt_e = (fi.i >> 23) & 0xff;
- const int flt_s = (fi.i >> 31) & 0x1;
- int s, e, m = 0;
- GLhalfARB result;
-
- /* sign bit */
- s = flt_s;
-
- /* handle special cases */
- if ((flt_e == 0) && (flt_m == 0)) {
- /* zero */
- /* m = 0; - already set */
- e = 0;
- }
- else if ((flt_e == 0) && (flt_m != 0)) {
- /* denorm -- denorm float maps to 0 half */
- /* m = 0; - already set */
- e = 0;
- }
- else if ((flt_e == 0xff) && (flt_m == 0)) {
- /* infinity */
- /* m = 0; - already set */
- e = 31;
- }
- else if ((flt_e == 0xff) && (flt_m != 0)) {
- /* NaN */
- m = 1;
- e = 31;
- }
- else {
- /* regular number */
- const int new_exp = flt_e - 127;
- if (new_exp < -24) {
- /* this maps to 0 */
- /* m = 0; - already set */
- e = 0;
- }
- else if (new_exp < -14) {
- /* this maps to a denorm */
- unsigned int exp_val = (unsigned int) (-14 - new_exp); /* 2^-exp_val*/
- e = 0;
- switch (exp_val) {
- case 0:
- _mesa_warning(NULL,
- "float_to_half: logical error in denorm creation!\n");
- /* m = 0; - already set */
- break;
- case 1: m = 512 + (flt_m >> 14); break;
- case 2: m = 256 + (flt_m >> 15); break;
- case 3: m = 128 + (flt_m >> 16); break;
- case 4: m = 64 + (flt_m >> 17); break;
- case 5: m = 32 + (flt_m >> 18); break;
- case 6: m = 16 + (flt_m >> 19); break;
- case 7: m = 8 + (flt_m >> 20); break;
- case 8: m = 4 + (flt_m >> 21); break;
- case 9: m = 2 + (flt_m >> 22); break;
- case 10: m = 1; break;
- }
- }
- else if (new_exp > 15) {
- /* map this value to infinity */
- /* m = 0; - already set */
- e = 31;
- }
- else {
- /* regular */
- e = new_exp + 15;
- m = flt_m >> 13;
- }
- }
-
- result = (s << 15) | (e << 10) | m;
- return result;
-}
-
-
-/**
- * Convert a 2-byte half float to a 4-byte float.
- * Based on code from:
- * http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/008786.html
- */
-float
-_mesa_half_to_float(GLhalfARB val)
-{
- /* XXX could also use a 64K-entry lookup table */
- const int m = val & 0x3ff;
- const int e = (val >> 10) & 0x1f;
- const int s = (val >> 15) & 0x1;
- int flt_m, flt_e, flt_s;
- fi_type fi;
- float result;
-
- /* sign bit */
- flt_s = s;
-
- /* handle special cases */
- if ((e == 0) && (m == 0)) {
- /* zero */
- flt_m = 0;
- flt_e = 0;
- }
- else if ((e == 0) && (m != 0)) {
- /* denorm -- denorm half will fit in non-denorm single */
- const float half_denorm = 1.0f / 16384.0f; /* 2^-14 */
- float mantissa = ((float) (m)) / 1024.0f;
- float sign = s ? -1.0f : 1.0f;
- return sign * mantissa * half_denorm;
- }
- else if ((e == 31) && (m == 0)) {
- /* infinity */
- flt_e = 0xff;
- flt_m = 0;
- }
- else if ((e == 31) && (m != 0)) {
- /* NaN */
- flt_e = 0xff;
- flt_m = 1;
- }
- else {
- /* regular */
- flt_e = e + 112;
- flt_m = m << 13;
- }
-
- fi.i = (flt_s << 31) | (flt_e << 23) | flt_m;
- result = fi.f;
- return result;
-}
-
-/*@}*/
-
-
-/**********************************************************************/
-/** \name Sort & Search */
-/*@{*/
-
-/**
- * Wrapper for bsearch().
- */
-void *
-_mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size,
- int (*compar)(const void *, const void *) )
-{
-#if defined(_WIN32_WCE)
- void *mid;
- int cmp;
- while (nmemb) {
- nmemb >>= 1;
- mid = (char *)base + nmemb * size;
- cmp = (*compar)(key, mid);
- if (cmp == 0)
- return mid;
- if (cmp > 0) {
- base = (char *)mid + size;
- --nmemb;
- }
- }
- return NULL;
-#else
- return bsearch(key, base, nmemb, size, compar);
-#endif
-}
-
-/*@}*/
-
-
-/**********************************************************************/
-/** \name Environment vars */
-/*@{*/
-
-/**
- * Wrapper for getenv().
- */
-char *
-_mesa_getenv( const char *var )
-{
-#if defined(_XBOX) || defined(_WIN32_WCE)
- return NULL;
-#else
- return getenv(var);
-#endif
-}
-
-/*@}*/
-
-
-/**********************************************************************/
-/** \name String */
-/*@{*/
-
-/**
- * Implemented using malloc() and strcpy.
- * Note that NULL is handled accordingly.
- */
-char *
-_mesa_strdup( const char *s )
-{
- if (s) {
- size_t l = strlen(s);
- char *s2 = (char *) malloc(l + 1);
- if (s2)
- strcpy(s2, s);
- return s2;
- }
- else {
- return NULL;
- }
-}
-
-/** Wrapper around strtof() */
-float
-_mesa_strtof( const char *s, char **end )
-{
-#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__)
- static locale_t loc = NULL;
- if (!loc) {
- loc = newlocale(LC_CTYPE_MASK, "C", NULL);
- }
- return strtof_l(s, end, loc);
-#elif defined(_ISOC99_SOURCE) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
- return strtof(s, end);
-#else
- return (float)strtod(s, end);
-#endif
-}
-
-/** Compute simple checksum/hash for a string */
-unsigned int
-_mesa_str_checksum(const char *str)
-{
- /* This could probably be much better */
- unsigned int sum, i;
- const char *c;
- sum = i = 1;
- for (c = str; *c; c++, i++)
- sum += *c * (i % 100);
- return sum + i;
-}
-
-
-/*@}*/
-
-
-/** Wrapper around vsnprintf() */
-int
-_mesa_snprintf( char *str, size_t size, const char *fmt, ... )
-{
- int r;
- va_list args;
- va_start( args, fmt );
- r = vsnprintf( str, size, fmt, args );
- va_end( args );
- return r;
-}
-
-
-/**********************************************************************/
-/** \name Diagnostics */
-/*@{*/
-
-static void
-output_if_debug(const char *prefixString, const char *outputString,
- GLboolean newline)
-{
- static int debug = -1;
-
- /* Check the MESA_DEBUG environment variable if it hasn't
- * been checked yet. We only have to check it once...
- */
- if (debug == -1) {
- char *env = _mesa_getenv("MESA_DEBUG");
-
- /* In a debug build, we print warning messages *unless*
- * MESA_DEBUG is 0. In a non-debug build, we don't
- * print warning messages *unless* MESA_DEBUG is
- * set *to any value*.
- */
-#ifdef DEBUG
- debug = (env != NULL && atoi(env) == 0) ? 0 : 1;
-#else
- debug = (env != NULL) ? 1 : 0;
-#endif
- }
-
- /* Now only print the string if we're required to do so. */
- if (debug) {
- fprintf(stderr, "%s: %s", prefixString, outputString);
- if (newline)
- fprintf(stderr, "\n");
-
-#if defined(_WIN32) && !defined(_WIN32_WCE)
- /* stderr from windows applications without console is not usually
- * visible, so communicate with the debugger instead */
- {
- char buf[4096];
- _mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : "");
- OutputDebugStringA(buf);
- }
-#endif
- }
-}
-
-
-/**
- * Return string version of GL error code.
- */
-static const char *
-error_string( GLenum error )
-{
- switch (error) {
- case GL_NO_ERROR:
- return "GL_NO_ERROR";
- case GL_INVALID_VALUE:
- return "GL_INVALID_VALUE";
- case GL_INVALID_ENUM:
- return "GL_INVALID_ENUM";
- case GL_INVALID_OPERATION:
- return "GL_INVALID_OPERATION";
- case GL_STACK_OVERFLOW:
- return "GL_STACK_OVERFLOW";
- case GL_STACK_UNDERFLOW:
- return "GL_STACK_UNDERFLOW";
- case GL_OUT_OF_MEMORY:
- return "GL_OUT_OF_MEMORY";
- case GL_TABLE_TOO_LARGE:
- return "GL_TABLE_TOO_LARGE";
- case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
- return "GL_INVALID_FRAMEBUFFER_OPERATION";
- default:
- return "unknown";
- }
-}
-
-
-/**
- * When a new type of error is recorded, print a message describing
- * previous errors which were accumulated.
- */
-static void
-flush_delayed_errors( struct gl_context *ctx )
-{
- char s[MAXSTRING];
-
- if (ctx->ErrorDebugCount) {
- _mesa_snprintf(s, MAXSTRING, "%d similar %s errors",
- ctx->ErrorDebugCount,
- error_string(ctx->ErrorValue));
-
- output_if_debug("Mesa", s, GL_TRUE);
-
- ctx->ErrorDebugCount = 0;
- }
-}
-
-
-/**
- * Report a warning (a recoverable error condition) to stderr if
- * either DEBUG is defined or the MESA_DEBUG env var is set.
- *
- * \param ctx GL context.
- * \param fmtString printf()-like format string.
- */
-void
-_mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
-{
- char str[MAXSTRING];
- va_list args;
- va_start( args, fmtString );
- (void) vsnprintf( str, MAXSTRING, fmtString, args );
- va_end( args );
-
- if (ctx)
- flush_delayed_errors( ctx );
-
- output_if_debug("Mesa warning", str, GL_TRUE);
-}
-
-
-/**
- * Report an internal implementation problem.
- * Prints the message to stderr via fprintf().
- *
- * \param ctx GL context.
- * \param fmtString problem description string.
- */
-void
-_mesa_problem( const struct gl_context *ctx, const char *fmtString, ... )
-{
- va_list args;
- char str[MAXSTRING];
- (void) ctx;
-
- va_start( args, fmtString );
- vsnprintf( str, MAXSTRING, fmtString, args );
- va_end( args );
-
- fprintf(stderr, "Mesa %s implementation error: %s\n", MESA_VERSION_STRING, str);
- fprintf(stderr, "Please report at bugs.freedesktop.org\n");
-}
-
-
-/**
- * Record an OpenGL state error. These usually occur when the user
- * passes invalid parameters to a GL function.
- *
- * If debugging is enabled (either at compile-time via the DEBUG macro, or
- * run-time via the MESA_DEBUG environment variable), report the error with
- * _mesa_debug().
- *
- * \param ctx the GL context.
- * \param error the error value.
- * \param fmtString printf() style format string, followed by optional args
- */
-void
-_mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
-{
- static GLint debug = -1;
-
- /* Check debug environment variable only once:
- */
- if (debug == -1) {
- const char *debugEnv = _mesa_getenv("MESA_DEBUG");
-
-#ifdef DEBUG
- if (debugEnv && strstr(debugEnv, "silent"))
- debug = GL_FALSE;
- else
- debug = GL_TRUE;
-#else
- if (debugEnv)
- debug = GL_TRUE;
- else
- debug = GL_FALSE;
-#endif
- }
-
- if (debug) {
- if (ctx->ErrorValue == error &&
- ctx->ErrorDebugFmtString == fmtString) {
- ctx->ErrorDebugCount++;
- }
- else {
- char s[MAXSTRING], s2[MAXSTRING];
- va_list args;
-
- flush_delayed_errors( ctx );
-
- va_start(args, fmtString);
- vsnprintf(s, MAXSTRING, fmtString, args);
- va_end(args);
-
- _mesa_snprintf(s2, MAXSTRING, "%s in %s", error_string(error), s);
- output_if_debug("Mesa: User error", s2, GL_TRUE);
-
- ctx->ErrorDebugFmtString = fmtString;
- ctx->ErrorDebugCount = 0;
- }
- }
-
- _mesa_record_error(ctx, error);
-}
-
-
-/**
- * Report debug information. Print error message to stderr via fprintf().
- * No-op if DEBUG mode not enabled.
- *
- * \param ctx GL context.
- * \param fmtString printf()-style format string, followed by optional args.
- */
-void
-_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
-{
-#ifdef DEBUG
- char s[MAXSTRING];
- va_list args;
- va_start(args, fmtString);
- vsnprintf(s, MAXSTRING, fmtString, args);
- va_end(args);
- output_if_debug("Mesa", s, GL_FALSE);
-#endif /* DEBUG */
- (void) ctx;
- (void) fmtString;
-}
-
-/*@}*/
+/**
+ * \file imports.c
+ * Standard C library function wrappers.
+ *
+ * Imports are services which the device driver or window system or
+ * operating system provides to the core renderer. The core renderer (Mesa)
+ * will call these functions in order to do memory allocation, simple I/O,
+ * etc.
+ *
+ * Some drivers will want to override/replace this file with something
+ * specialized, but that'll be rare.
+ *
+ * Eventually, I want to move roll the glheader.h file into this.
+ *
+ * \todo Functions still needed:
+ * - scanf
+ * - qsort
+ * - rand and RAND_MAX
+ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+#include "imports.h"
+#include "context.h"
+#include "mtypes.h"
+#include "version.h"
+
+#ifdef _GNU_SOURCE
+#include <locale.h>
+#ifdef __APPLE__
+#include <xlocale.h>
+#endif
+#endif
+
+
+#define MAXSTRING 4000 /* for vsnprintf() */
+
+#ifdef WIN32
+#define vsnprintf _vsnprintf
+#elif defined(__IBMC__) || defined(__IBMCPP__) || ( defined(__VMS) && __CRTL_VER < 70312000 )
+extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
+#ifdef __VMS
+#include "vsnprintf.c"
+#endif
+#endif
+
+/**********************************************************************/
+/** \name Memory */
+/*@{*/
+
+/**
+ * Allocate aligned memory.
+ *
+ * \param bytes number of bytes to allocate.
+ * \param alignment alignment (must be greater than zero).
+ *
+ * Allocates extra memory to accommodate rounding up the address for
+ * alignment and to record the real malloc address.
+ *
+ * \sa _mesa_align_free().
+ */
+void *
+_mesa_align_malloc(size_t bytes, unsigned long alignment)
+{
+#if defined(HAVE_POSIX_MEMALIGN)
+ void *mem;
+ int err = posix_memalign(& mem, alignment, bytes);
+ if (err)
+ return NULL;
+ return mem;
+#elif defined(_WIN32) && defined(_MSC_VER)
+ return _aligned_malloc(bytes, alignment);
+#else
+ uintptr_t ptr, buf;
+
+ ASSERT( alignment > 0 );
+
+ ptr = (uintptr_t) malloc(bytes + alignment + sizeof(void *));
+ if (!ptr)
+ return NULL;
+
+ buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
+ *(uintptr_t *)(buf - sizeof(void *)) = ptr;
+
+#ifdef DEBUG
+ /* mark the non-aligned area */
+ while ( ptr < buf - sizeof(void *) ) {
+ *(unsigned long *)ptr = 0xcdcdcdcd;
+ ptr += sizeof(unsigned long);
+ }
+#endif
+
+ return (void *) buf;
+#endif /* defined(HAVE_POSIX_MEMALIGN) */
+}
+
+/**
+ * Same as _mesa_align_malloc(), but using calloc(1, ) instead of
+ * malloc()
+ */
+void *
+_mesa_align_calloc(size_t bytes, unsigned long alignment)
+{
+#if defined(HAVE_POSIX_MEMALIGN)
+ void *mem;
+
+ mem = _mesa_align_malloc(bytes, alignment);
+ if (mem != NULL) {
+ (void) memset(mem, 0, bytes);
+ }
+
+ return mem;
+#elif defined(_WIN32) && defined(_MSC_VER)
+ void *mem;
+
+ mem = _aligned_malloc(bytes, alignment);
+ if (mem != NULL) {
+ (void) memset(mem, 0, bytes);
+ }
+
+ return mem;
+#else
+ uintptr_t ptr, buf;
+
+ ASSERT( alignment > 0 );
+
+ ptr = (uintptr_t) calloc(1, bytes + alignment + sizeof(void *));
+ if (!ptr)
+ return NULL;
+
+ buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
+ *(uintptr_t *)(buf - sizeof(void *)) = ptr;
+
+#ifdef DEBUG
+ /* mark the non-aligned area */
+ while ( ptr < buf - sizeof(void *) ) {
+ *(unsigned long *)ptr = 0xcdcdcdcd;
+ ptr += sizeof(unsigned long);
+ }
+#endif
+
+ return (void *)buf;
+#endif /* defined(HAVE_POSIX_MEMALIGN) */
+}
+
+/**
+ * Free memory which was allocated with either _mesa_align_malloc()
+ * or _mesa_align_calloc().
+ * \param ptr pointer to the memory to be freed.
+ * The actual address to free is stored in the word immediately before the
+ * address the client sees.
+ */
+void
+_mesa_align_free(void *ptr)
+{
+#if defined(HAVE_POSIX_MEMALIGN)
+ free(ptr);
+#elif defined(_WIN32) && defined(_MSC_VER)
+ _aligned_free(ptr);
+#else
+ void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
+ void *realAddr = *cubbyHole;
+ free(realAddr);
+#endif /* defined(HAVE_POSIX_MEMALIGN) */
+}
+
+/**
+ * Reallocate memory, with alignment.
+ */
+void *
+_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
+ unsigned long alignment)
+{
+#if defined(_WIN32) && defined(_MSC_VER)
+ (void) oldSize;
+ return _aligned_realloc(oldBuffer, newSize, alignment);
+#else
+ const size_t copySize = (oldSize < newSize) ? oldSize : newSize;
+ void *newBuf = _mesa_align_malloc(newSize, alignment);
+ if (newBuf && oldBuffer && copySize > 0) {
+ memcpy(newBuf, oldBuffer, copySize);
+ }
+ if (oldBuffer)
+ _mesa_align_free(oldBuffer);
+ return newBuf;
+#endif
+}
+
+
+
+/** Reallocate memory */
+void *
+_mesa_realloc(void *oldBuffer, size_t oldSize, size_t newSize)
+{
+ const size_t copySize = (oldSize < newSize) ? oldSize : newSize;
+ void *newBuffer = malloc(newSize);
+ if (newBuffer && oldBuffer && copySize > 0)
+ memcpy(newBuffer, oldBuffer, copySize);
+ if (oldBuffer)
+ free(oldBuffer);
+ return newBuffer;
+}
+
+/**
+ * Fill memory with a constant 16bit word.
+ * \param dst destination pointer.
+ * \param val value.
+ * \param n number of words.
+ */
+void
+_mesa_memset16( unsigned short *dst, unsigned short val, size_t n )
+{
+ while (n-- > 0)
+ *dst++ = val;
+}
+
+/*@}*/
+
+
+/**********************************************************************/
+/** \name Math */
+/*@{*/
+
+/** Wrapper around sqrt() */
+double
+_mesa_sqrtd(double x)
+{
+ return sqrt(x);
+}
+
+
+/*
+ * A High Speed, Low Precision Square Root
+ * by Paul Lalonde and Robert Dawson
+ * from "Graphics Gems", Academic Press, 1990
+ *
+ * SPARC implementation of a fast square root by table
+ * lookup.
+ * SPARC floating point format is as follows:
+ *
+ * BIT 31 30 23 22 0
+ * sign exponent mantissa
+ */
+static short sqrttab[0x100]; /* declare table of square roots */
+
+void
+_mesa_init_sqrt_table(void)
+{
+#if defined(USE_IEEE) && !defined(DEBUG)
+ unsigned short i;
+ fi_type fi; /* to access the bits of a float in C quickly */
+ /* we use a union defined in glheader.h */
+
+ for(i=0; i<= 0x7f; i++) {
+ fi.i = 0;
+
+ /*
+ * Build a float with the bit pattern i as mantissa
+ * and an exponent of 0, stored as 127
+ */
+
+ fi.i = (i << 16) | (127 << 23);
+ fi.f = _mesa_sqrtd(fi.f);
+
+ /*
+ * Take the square root then strip the first 7 bits of
+ * the mantissa into the table
+ */
+
+ sqrttab[i] = (fi.i & 0x7fffff) >> 16;
+
+ /*
+ * Repeat the process, this time with an exponent of
+ * 1, stored as 128
+ */
+
+ fi.i = 0;
+ fi.i = (i << 16) | (128 << 23);
+ fi.f = sqrt(fi.f);
+ sqrttab[i+0x80] = (fi.i & 0x7fffff) >> 16;
+ }
+#else
+ (void) sqrttab; /* silence compiler warnings */
+#endif /*HAVE_FAST_MATH*/
+}
+
+
+/**
+ * Single precision square root.
+ */
+float
+_mesa_sqrtf( float x )
+{
+#if defined(USE_IEEE) && !defined(DEBUG)
+ fi_type num;
+ /* to access the bits of a float in C
+ * we use a union from glheader.h */
+
+ short e; /* the exponent */
+ if (x == 0.0F) return 0.0F; /* check for square root of 0 */
+ num.f = x;
+ e = (num.i >> 23) - 127; /* get the exponent - on a SPARC the */
+ /* exponent is stored with 127 added */
+ num.i &= 0x7fffff; /* leave only the mantissa */
+ if (e & 0x01) num.i |= 0x800000;
+ /* the exponent is odd so we have to */
+ /* look it up in the second half of */
+ /* the lookup table, so we set the */
+ /* high bit */
+ e >>= 1; /* divide the exponent by two */
+ /* note that in C the shift */
+ /* operators are sign preserving */
+ /* for signed operands */
+ /* Do the table lookup, based on the quaternary mantissa,
+ * then reconstruct the result back into a float
+ */
+ num.i = ((sqrttab[num.i >> 16]) << 16) | ((e + 127) << 23);
+
+ return num.f;
+#else
+ return (float) _mesa_sqrtd((double) x);
+#endif
+}
+
+
+/**
+ inv_sqrt - A single precision 1/sqrt routine for IEEE format floats.
+ written by Josh Vanderhoof, based on newsgroup posts by James Van Buskirk
+ and Vesa Karvonen.
+*/
+float
+_mesa_inv_sqrtf(float n)
+{
+#if defined(USE_IEEE) && !defined(DEBUG)
+ float r0, x0, y0;
+ float r1, x1, y1;
+ float r2, x2, y2;
+#if 0 /* not used, see below -BP */
+ float r3, x3, y3;
+#endif
+ fi_type u;
+ unsigned int magic;
+
+ /*
+ Exponent part of the magic number -
+
+ We want to:
+ 1. subtract the bias from the exponent,
+ 2. negate it
+ 3. divide by two (rounding towards -inf)
+ 4. add the bias back
+
+ Which is the same as subtracting the exponent from 381 and dividing
+ by 2.
+
+ floor(-(x - 127) / 2) + 127 = floor((381 - x) / 2)
+ */
+
+ magic = 381 << 23;
+
+ /*
+ Significand part of magic number -
+
+ With the current magic number, "(magic - u.i) >> 1" will give you:
+
+ for 1 <= u.f <= 2: 1.25 - u.f / 4
+ for 2 <= u.f <= 4: 1.00 - u.f / 8
+
+ This isn't a bad approximation of 1/sqrt. The maximum difference from
+ 1/sqrt will be around .06. After three Newton-Raphson iterations, the
+ maximum difference is less than 4.5e-8. (Which is actually close
+ enough to make the following bias academic...)
+
+ To get a better approximation you can add a bias to the magic
+ number. For example, if you subtract 1/2 of the maximum difference in
+ the first approximation (.03), you will get the following function:
+
+ for 1 <= u.f <= 2: 1.22 - u.f / 4
+ for 2 <= u.f <= 3.76: 0.97 - u.f / 8
+ for 3.76 <= u.f <= 4: 0.72 - u.f / 16
+ (The 3.76 to 4 range is where the result is < .5.)
+
+ This is the closest possible initial approximation, but with a maximum
+ error of 8e-11 after three NR iterations, it is still not perfect. If
+ you subtract 0.0332281 instead of .03, the maximum error will be
+ 2.5e-11 after three NR iterations, which should be about as close as
+ is possible.
+
+ for 1 <= u.f <= 2: 1.2167719 - u.f / 4
+ for 2 <= u.f <= 3.73: 0.9667719 - u.f / 8
+ for 3.73 <= u.f <= 4: 0.7167719 - u.f / 16
+
+ */
+
+ magic -= (int)(0.0332281 * (1 << 25));
+
+ u.f = n;
+ u.i = (magic - u.i) >> 1;
+
+ /*
+ Instead of Newton-Raphson, we use Goldschmidt's algorithm, which
+ allows more parallelism. From what I understand, the parallelism
+ comes at the cost of less precision, because it lets error
+ accumulate across iterations.
+ */
+ x0 = 1.0f;
+ y0 = 0.5f * n;
+ r0 = u.f;
+
+ x1 = x0 * r0;
+ y1 = y0 * r0 * r0;
+ r1 = 1.5f - y1;
+
+ x2 = x1 * r1;
+ y2 = y1 * r1 * r1;
+ r2 = 1.5f - y2;
+
+#if 1
+ return x2 * r2; /* we can stop here, and be conformant -BP */
+#else
+ x3 = x2 * r2;
+ y3 = y2 * r2 * r2;
+ r3 = 1.5f - y3;
+
+ return x3 * r3;
+#endif
+#else
+ return (float) (1.0 / sqrt(n));
+#endif
+}
+
+#ifndef __GNUC__
+/**
+ * Find the first bit set in a word.
+ */
+int
+_mesa_ffs(int32_t i)
+{
+#if (defined(_WIN32) ) || defined(__IBMC__) || defined(__IBMCPP__)
+ register int bit = 0;
+ if (i != 0) {
+ if ((i & 0xffff) == 0) {
+ bit += 16;
+ i >>= 16;
+ }
+ if ((i & 0xff) == 0) {
+ bit += 8;
+ i >>= 8;
+ }
+ if ((i & 0xf) == 0) {
+ bit += 4;
+ i >>= 4;
+ }
+ while ((i & 1) == 0) {
+ bit++;
+ i >>= 1;
+ }
+ bit++;
+ }
+ return bit;
+#else
+ return ffs(i);
+#endif
+}
+
+
+/**
+ * Find position of first bit set in given value.
+ * XXX Warning: this function can only be used on 64-bit systems!
+ * \return position of least-significant bit set, starting at 1, return zero
+ * if no bits set.
+ */
+int
+_mesa_ffsll(int64_t val)
+{
+ int bit;
+
+ assert(sizeof(val) == 8);
+
+ bit = _mesa_ffs((int32_t)val);
+ if (bit != 0)
+ return bit;
+
+ bit = _mesa_ffs((int32_t)(val >> 32));
+ if (bit != 0)
+ return 32 + bit;
+
+ return 0;
+}
+
+
+#if ((_GNUC__ == 3 && __GNUC_MINOR__ < 4) || __GNUC__ < 4)
+/**
+ * Return number of bits set in given GLuint.
+ */
+unsigned int
+_mesa_bitcount(unsigned int n)
+{
+ unsigned int bits;
+ for (bits = 0; n > 0; n = n >> 1) {
+ bits += (n & 1);
+ }
+ return bits;
+}
+#endif
+#endif
+
+
+/**
+ * Convert a 4-byte float to a 2-byte half float.
+ * Based on code from:
+ * http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/008786.html
+ */
+GLhalfARB
+_mesa_float_to_half(float val)
+{
+ const fi_type fi = {val};
+ const int flt_m = fi.i & 0x7fffff;
+ const int flt_e = (fi.i >> 23) & 0xff;
+ const int flt_s = (fi.i >> 31) & 0x1;
+ int s, e, m = 0;
+ GLhalfARB result;
+
+ /* sign bit */
+ s = flt_s;
+
+ /* handle special cases */
+ if ((flt_e == 0) && (flt_m == 0)) {
+ /* zero */
+ /* m = 0; - already set */
+ e = 0;
+ }
+ else if ((flt_e == 0) && (flt_m != 0)) {
+ /* denorm -- denorm float maps to 0 half */
+ /* m = 0; - already set */
+ e = 0;
+ }
+ else if ((flt_e == 0xff) && (flt_m == 0)) {
+ /* infinity */
+ /* m = 0; - already set */
+ e = 31;
+ }
+ else if ((flt_e == 0xff) && (flt_m != 0)) {
+ /* NaN */
+ m = 1;
+ e = 31;
+ }
+ else {
+ /* regular number */
+ const int new_exp = flt_e - 127;
+ if (new_exp < -24) {
+ /* this maps to 0 */
+ /* m = 0; - already set */
+ e = 0;
+ }
+ else if (new_exp < -14) {
+ /* this maps to a denorm */
+ unsigned int exp_val = (unsigned int) (-14 - new_exp); /* 2^-exp_val*/
+ e = 0;
+ switch (exp_val) {
+ case 0:
+ _mesa_warning(NULL,
+ "float_to_half: logical error in denorm creation!\n");
+ /* m = 0; - already set */
+ break;
+ case 1: m = 512 + (flt_m >> 14); break;
+ case 2: m = 256 + (flt_m >> 15); break;
+ case 3: m = 128 + (flt_m >> 16); break;
+ case 4: m = 64 + (flt_m >> 17); break;
+ case 5: m = 32 + (flt_m >> 18); break;
+ case 6: m = 16 + (flt_m >> 19); break;
+ case 7: m = 8 + (flt_m >> 20); break;
+ case 8: m = 4 + (flt_m >> 21); break;
+ case 9: m = 2 + (flt_m >> 22); break;
+ case 10: m = 1; break;
+ }
+ }
+ else if (new_exp > 15) {
+ /* map this value to infinity */
+ /* m = 0; - already set */
+ e = 31;
+ }
+ else {
+ /* regular */
+ e = new_exp + 15;
+ m = flt_m >> 13;
+ }
+ }
+
+ result = (s << 15) | (e << 10) | m;
+ return result;
+}
+
+
+/**
+ * Convert a 2-byte half float to a 4-byte float.
+ * Based on code from:
+ * http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/008786.html
+ */
+float
+_mesa_half_to_float(GLhalfARB val)
+{
+ /* XXX could also use a 64K-entry lookup table */
+ const int m = val & 0x3ff;
+ const int e = (val >> 10) & 0x1f;
+ const int s = (val >> 15) & 0x1;
+ int flt_m, flt_e, flt_s;
+ fi_type fi;
+ float result;
+
+ /* sign bit */
+ flt_s = s;
+
+ /* handle special cases */
+ if ((e == 0) && (m == 0)) {
+ /* zero */
+ flt_m = 0;
+ flt_e = 0;
+ }
+ else if ((e == 0) && (m != 0)) {
+ /* denorm -- denorm half will fit in non-denorm single */
+ const float half_denorm = 1.0f / 16384.0f; /* 2^-14 */
+ float mantissa = ((float) (m)) / 1024.0f;
+ float sign = s ? -1.0f : 1.0f;
+ return sign * mantissa * half_denorm;
+ }
+ else if ((e == 31) && (m == 0)) {
+ /* infinity */
+ flt_e = 0xff;
+ flt_m = 0;
+ }
+ else if ((e == 31) && (m != 0)) {
+ /* NaN */
+ flt_e = 0xff;
+ flt_m = 1;
+ }
+ else {
+ /* regular */
+ flt_e = e + 112;
+ flt_m = m << 13;
+ }
+
+ fi.i = (flt_s << 31) | (flt_e << 23) | flt_m;
+ result = fi.f;
+ return result;
+}
+
+/*@}*/
+
+
+/**********************************************************************/
+/** \name Sort & Search */
+/*@{*/
+
+/**
+ * Wrapper for bsearch().
+ */
+void *
+_mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size,
+ int (*compar)(const void *, const void *) )
+{
+#if defined(_WIN32_WCE)
+ void *mid;
+ int cmp;
+ while (nmemb) {
+ nmemb >>= 1;
+ mid = (char *)base + nmemb * size;
+ cmp = (*compar)(key, mid);
+ if (cmp == 0)
+ return mid;
+ if (cmp > 0) {
+ base = (char *)mid + size;
+ --nmemb;
+ }
+ }
+ return NULL;
+#else
+ return bsearch(key, base, nmemb, size, compar);
+#endif
+}
+
+/*@}*/
+
+
+/**********************************************************************/
+/** \name Environment vars */
+/*@{*/
+
+/**
+ * Wrapper for getenv().
+ */
+char *
+_mesa_getenv( const char *var )
+{
+#if defined(_XBOX) || defined(_WIN32_WCE)
+ return NULL;
+#else
+ return getenv(var);
+#endif
+}
+
+/*@}*/
+
+
+/**********************************************************************/
+/** \name String */
+/*@{*/
+
+/**
+ * Implemented using malloc() and strcpy.
+ * Note that NULL is handled accordingly.
+ */
+char *
+_mesa_strdup( const char *s )
+{
+ if (s) {
+ size_t l = strlen(s);
+ char *s2 = (char *) malloc(l + 1);
+ if (s2)
+ strcpy(s2, s);
+ return s2;
+ }
+ else {
+ return NULL;
+ }
+}
+
+/** Wrapper around strtof() */
+float
+_mesa_strtof( const char *s, char **end )
+{
+#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__)
+ static locale_t loc = NULL;
+ if (!loc) {
+ loc = newlocale(LC_CTYPE_MASK, "C", NULL);
+ }
+ return strtof_l(s, end, loc);
+#elif defined(_ISOC99_SOURCE) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
+ return strtof(s, end);
+#else
+ return (float)strtod(s, end);
+#endif
+}
+
+/** Compute simple checksum/hash for a string */
+unsigned int
+_mesa_str_checksum(const char *str)
+{
+ /* This could probably be much better */
+ unsigned int sum, i;
+ const char *c;
+ sum = i = 1;
+ for (c = str; *c; c++, i++)
+ sum += *c * (i % 100);
+ return sum + i;
+}
+
+
+/*@}*/
+
+
+/** Wrapper around vsnprintf() */
+int
+_mesa_snprintf( char *str, size_t size, const char *fmt, ... )
+{
+ int r;
+ va_list args;
+ va_start( args, fmt );
+ r = vsnprintf( str, size, fmt, args );
+ va_end( args );
+ return r;
+}
+
+
+/**********************************************************************/
+/** \name Diagnostics */
+/*@{*/
+
+static void
+output_if_debug(const char *prefixString, const char *outputString,
+ GLboolean newline)
+{
+ static int debug = -1;
+
+ /* Check the MESA_DEBUG environment variable if it hasn't
+ * been checked yet. We only have to check it once...
+ */
+ if (debug == -1) {
+ char *env = _mesa_getenv("MESA_DEBUG");
+
+ /* In a debug build, we print warning messages *unless*
+ * MESA_DEBUG is 0. In a non-debug build, we don't
+ * print warning messages *unless* MESA_DEBUG is
+ * set *to any value*.
+ */
+#ifdef DEBUG
+ debug = (env != NULL && atoi(env) == 0) ? 0 : 1;
+#else
+ debug = (env != NULL) ? 1 : 0;
+#endif
+ }
+
+ /* Now only print the string if we're required to do so. */
+ if (debug) {
+ fprintf(stderr, "%s: %s", prefixString, outputString);
+ if (newline)
+ fprintf(stderr, "\n");
+
+#if defined(_WIN32) && !defined(_WIN32_WCE)
+ /* stderr from windows applications without console is not usually
+ * visible, so communicate with the debugger instead */
+ {
+ char buf[4096];
+ _mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : "");
+ OutputDebugStringA(buf);
+ }
+#endif
+ }
+}
+
+
+/**
+ * Return string version of GL error code.
+ */
+static const char *
+error_string( GLenum error )
+{
+ switch (error) {
+ case GL_NO_ERROR:
+ return "GL_NO_ERROR";
+ case GL_INVALID_VALUE:
+ return "GL_INVALID_VALUE";
+ case GL_INVALID_ENUM:
+ return "GL_INVALID_ENUM";
+ case GL_INVALID_OPERATION:
+ return "GL_INVALID_OPERATION";
+ case GL_STACK_OVERFLOW:
+ return "GL_STACK_OVERFLOW";
+ case GL_STACK_UNDERFLOW:
+ return "GL_STACK_UNDERFLOW";
+ case GL_OUT_OF_MEMORY:
+ return "GL_OUT_OF_MEMORY";
+ case GL_TABLE_TOO_LARGE:
+ return "GL_TABLE_TOO_LARGE";
+ case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
+ return "GL_INVALID_FRAMEBUFFER_OPERATION";
+ default:
+ return "unknown";
+ }
+}
+
+
+/**
+ * When a new type of error is recorded, print a message describing
+ * previous errors which were accumulated.
+ */
+static void
+flush_delayed_errors( struct gl_context *ctx )
+{
+ char s[MAXSTRING];
+
+ if (ctx->ErrorDebugCount) {
+ _mesa_snprintf(s, MAXSTRING, "%d similar %s errors",
+ ctx->ErrorDebugCount,
+ error_string(ctx->ErrorValue));
+
+ output_if_debug("Mesa", s, GL_TRUE);
+
+ ctx->ErrorDebugCount = 0;
+ }
+}
+
+
+/**
+ * Report a warning (a recoverable error condition) to stderr if
+ * either DEBUG is defined or the MESA_DEBUG env var is set.
+ *
+ * \param ctx GL context.
+ * \param fmtString printf()-like format string.
+ */
+void
+_mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
+{
+ char str[MAXSTRING];
+ va_list args;
+ va_start( args, fmtString );
+ (void) vsnprintf( str, MAXSTRING, fmtString, args );
+ va_end( args );
+
+ if (ctx)
+ flush_delayed_errors( ctx );
+
+ output_if_debug("Mesa warning", str, GL_TRUE);
+}
+
+
+/**
+ * Report an internal implementation problem.
+ * Prints the message to stderr via fprintf().
+ *
+ * \param ctx GL context.
+ * \param fmtString problem description string.
+ */
+void
+_mesa_problem( const struct gl_context *ctx, const char *fmtString, ... )
+{
+ va_list args;
+ char str[MAXSTRING];
+ (void) ctx;
+
+ va_start( args, fmtString );
+ vsnprintf( str, MAXSTRING, fmtString, args );
+ va_end( args );
+
+ fprintf(stderr, "Mesa %s implementation error: %s\n", MESA_VERSION_STRING, str);
+ fprintf(stderr, "Please report at bugs.freedesktop.org\n");
+}
+
+
+/**
+ * Record an OpenGL state error. These usually occur when the user
+ * passes invalid parameters to a GL function.
+ *
+ * If debugging is enabled (either at compile-time via the DEBUG macro, or
+ * run-time via the MESA_DEBUG environment variable), report the error with
+ * _mesa_debug().
+ *
+ * \param ctx the GL context.
+ * \param error the error value.
+ * \param fmtString printf() style format string, followed by optional args
+ */
+void
+_mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
+{
+ static GLint debug = -1;
+
+ /* Check debug environment variable only once:
+ */
+ if (debug == -1) {
+ const char *debugEnv = _mesa_getenv("MESA_DEBUG");
+
+#ifdef DEBUG
+ if (debugEnv && strstr(debugEnv, "silent"))
+ debug = GL_FALSE;
+ else
+ debug = GL_TRUE;
+#else
+ if (debugEnv)
+ debug = GL_TRUE;
+ else
+ debug = GL_FALSE;
+#endif
+ }
+
+ if (debug) {
+ if (ctx->ErrorValue == error &&
+ ctx->ErrorDebugFmtString == fmtString) {
+ ctx->ErrorDebugCount++;
+ }
+ else {
+ char s[MAXSTRING], s2[MAXSTRING];
+ va_list args;
+
+ flush_delayed_errors( ctx );
+
+ va_start(args, fmtString);
+ vsnprintf(s, MAXSTRING, fmtString, args);
+ va_end(args);
+
+ _mesa_snprintf(s2, MAXSTRING, "%s in %s", error_string(error), s);
+ output_if_debug("Mesa: User error", s2, GL_TRUE);
+
+ ctx->ErrorDebugFmtString = fmtString;
+ ctx->ErrorDebugCount = 0;
+ }
+ }
+
+ _mesa_record_error(ctx, error);
+}
+
+
+/**
+ * Report debug information. Print error message to stderr via fprintf().
+ * No-op if DEBUG mode not enabled.
+ *
+ * \param ctx GL context.
+ * \param fmtString printf()-style format string, followed by optional args.
+ */
+void
+_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
+{
+#ifdef DEBUG
+ char s[MAXSTRING];
+ va_list args;
+ va_start(args, fmtString);
+ vsnprintf(s, MAXSTRING, fmtString, args);
+ va_end(args);
+ output_if_debug("Mesa", s, GL_FALSE);
+#endif /* DEBUG */
+ (void) ctx;
+ (void) fmtString;
+}
+
+/*@}*/
diff --git a/mesalib/src/mesa/main/imports.h b/mesalib/src/mesa/main/imports.h
index ce7baabe2..315c4119d 100644
--- a/mesalib/src/mesa/main/imports.h
+++ b/mesalib/src/mesa/main/imports.h
@@ -1,621 +1,621 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.5
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file imports.h
- * Standard C library function wrappers.
- *
- * This file provides wrappers for all the standard C library functions
- * like malloc(), free(), printf(), getenv(), etc.
- */
-
-
-#ifndef IMPORTS_H
-#define IMPORTS_H
-
-
-#include "compiler.h"
-#include "glheader.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/**********************************************************************/
-/** Memory macros */
-/*@{*/
-
-/** Allocate \p BYTES bytes */
-#define MALLOC(BYTES) malloc(BYTES)
-/** Allocate and zero \p BYTES bytes */
-#define CALLOC(BYTES) calloc(1, BYTES)
-/** Allocate a structure of type \p T */
-#define MALLOC_STRUCT(T) (struct T *) malloc(sizeof(struct T))
-/** Allocate and zero a structure of type \p T */
-#define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
-/** Free memory */
-#define FREE(PTR) free(PTR)
-
-/*@}*/
-
-
-/*
- * For GL_ARB_vertex_buffer_object we need to treat vertex array pointers
- * as offsets into buffer stores. Since the vertex array pointer and
- * buffer store pointer are both pointers and we need to add them, we use
- * this macro.
- * Both pointers/offsets are expressed in bytes.
- */
-#define ADD_POINTERS(A, B) ( (GLubyte *) (A) + (uintptr_t) (B) )
-
-
-/**
- * Sometimes we treat GLfloats as GLints. On x86 systems, moving a float
- * as a int (thereby using integer registers instead of FP registers) is
- * a performance win. Typically, this can be done with ordinary casts.
- * But with gcc's -fstrict-aliasing flag (which defaults to on in gcc 3.0)
- * these casts generate warnings.
- * The following union typedef is used to solve that.
- */
-typedef union { GLfloat f; GLint i; } fi_type;
-
-
-
-/**********************************************************************
- * Math macros
- */
-
-#define MAX_GLUSHORT 0xffff
-#define MAX_GLUINT 0xffffffff
-
-/* Degrees to radians conversion: */
-#define DEG2RAD (M_PI/180.0)
-
-
-/***
- *** SQRTF: single-precision square root
- ***/
-#if 0 /* _mesa_sqrtf() not accurate enough - temporarily disabled */
-# define SQRTF(X) _mesa_sqrtf(X)
-#else
-# define SQRTF(X) (float) sqrt((float) (X))
-#endif
-
-
-/***
- *** INV_SQRTF: single-precision inverse square root
- ***/
-#if 0
-#define INV_SQRTF(X) _mesa_inv_sqrt(X)
-#else
-#define INV_SQRTF(X) (1.0F / SQRTF(X)) /* this is faster on a P4 */
-#endif
-
-
-/**
- * \name Work-arounds for platforms that lack C99 math functions
- */
-/*@{*/
-#if (!defined(_XOPEN_SOURCE) || (_XOPEN_SOURCE < 600)) && !defined(_ISOC99_SOURCE) \
- && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)) \
- && (!defined(_MSC_VER) || (_MSC_VER < 1400))
-#define acosf(f) ((float) acos(f))
-#define asinf(f) ((float) asin(f))
-#define atan2f(x,y) ((float) atan2(x,y))
-#define atanf(f) ((float) atan(f))
-#define cielf(f) ((float) ciel(f))
-#define cosf(f) ((float) cos(f))
-#define coshf(f) ((float) cosh(f))
-#define expf(f) ((float) exp(f))
-#define exp2f(f) ((float) exp2(f))
-#define floorf(f) ((float) floor(f))
-#define logf(f) ((float) log(f))
-#define log2f(f) ((float) log2(f))
-#define powf(x,y) ((float) pow(x,y))
-#define sinf(f) ((float) sin(f))
-#define sinhf(f) ((float) sinh(f))
-#define sqrtf(f) ((float) sqrt(f))
-#define tanf(f) ((float) tan(f))
-#define tanhf(f) ((float) tanh(f))
-#define acoshf(f) ((float) acosh(f))
-#define asinhf(f) ((float) asinh(f))
-#define atanhf(f) ((float) atanh(f))
-#endif
-
-#if defined(_MSC_VER)
-static INLINE float truncf(float x) { return x < 0.0f ? ceilf(x) : floorf(x); }
-static INLINE float exp2f(float x) { return powf(2.0f, x); }
-static INLINE float log2f(float x) { return logf(x) * 1.442695041f; }
-static INLINE float asinhf(float x) { return logf(x + sqrtf(x * x + 1.0f)); }
-static INLINE float acoshf(float x) { return logf(x + sqrtf(x * x - 1.0f)); }
-static INLINE float atanhf(float x) { return (logf(1.0f + x) - logf(1.0f - x)) / 2.0f; }
-static INLINE int isblank(int ch) { return ch == ' ' || ch == '\t'; }
-#define strtoll(p, e, b) _strtoi64(p, e, b)
-#endif
-/*@}*/
-
-/***
- *** LOG2: Log base 2 of float
- ***/
-#ifdef USE_IEEE
-#if 0
-/* This is pretty fast, but not accurate enough (only 2 fractional bits).
- * Based on code from http://www.stereopsis.com/log2.html
- */
-static INLINE GLfloat LOG2(GLfloat x)
-{
- const GLfloat y = x * x * x * x;
- const GLuint ix = *((GLuint *) &y);
- const GLuint exp = (ix >> 23) & 0xFF;
- const GLint log2 = ((GLint) exp) - 127;
- return (GLfloat) log2 * (1.0 / 4.0); /* 4, because of x^4 above */
-}
-#endif
-/* Pretty fast, and accurate.
- * Based on code from http://www.flipcode.com/totd/
- */
-static INLINE GLfloat LOG2(GLfloat val)
-{
- fi_type num;
- GLint log_2;
- num.f = val;
- log_2 = ((num.i >> 23) & 255) - 128;
- num.i &= ~(255 << 23);
- num.i += 127 << 23;
- num.f = ((-1.0f/3) * num.f + 2) * num.f - 2.0f/3;
- return num.f + log_2;
-}
-#else
-/*
- * NOTE: log_base_2(x) = log(x) / log(2)
- * NOTE: 1.442695 = 1/log(2).
- */
-#define LOG2(x) ((GLfloat) (log(x) * 1.442695F))
-#endif
-
-
-/***
- *** IS_INF_OR_NAN: test if float is infinite or NaN
- ***/
-#ifdef USE_IEEE
-static INLINE int IS_INF_OR_NAN( float x )
-{
- fi_type tmp;
- tmp.f = x;
- return !(int)((unsigned int)((tmp.i & 0x7fffffff)-0x7f800000) >> 31);
-}
-#elif defined(isfinite)
-#define IS_INF_OR_NAN(x) (!isfinite(x))
-#elif defined(finite)
-#define IS_INF_OR_NAN(x) (!finite(x))
-#elif defined(__VMS)
-#define IS_INF_OR_NAN(x) (!finite(x))
-#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-#define IS_INF_OR_NAN(x) (!isfinite(x))
-#else
-#define IS_INF_OR_NAN(x) (!finite(x))
-#endif
-
-
-/***
- *** IS_NEGATIVE: test if float is negative
- ***/
-#if defined(USE_IEEE)
-static INLINE int GET_FLOAT_BITS( float x )
-{
- fi_type fi;
- fi.f = x;
- return fi.i;
-}
-#define IS_NEGATIVE(x) (GET_FLOAT_BITS(x) < 0)
-#else
-#define IS_NEGATIVE(x) (x < 0.0F)
-#endif
-
-
-/***
- *** DIFFERENT_SIGNS: test if two floats have opposite signs
- ***/
-#if defined(USE_IEEE)
-#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31))
-#else
-/* Could just use (x*y<0) except for the flatshading requirements.
- * Maybe there's a better way?
- */
-#define DIFFERENT_SIGNS(x,y) ((x) * (y) <= 0.0F && (x) - (y) != 0.0F)
-#endif
-
-
-/***
- *** CEILF: ceiling of float
- *** FLOORF: floor of float
- *** FABSF: absolute value of float
- *** LOGF: the natural logarithm (base e) of the value
- *** EXPF: raise e to the value
- *** LDEXPF: multiply value by an integral power of two
- *** FREXPF: extract mantissa and exponent from value
- ***/
-#if defined(__gnu_linux__)
-/* C99 functions */
-#define CEILF(x) ceilf(x)
-#define FLOORF(x) floorf(x)
-#define FABSF(x) fabsf(x)
-#define LOGF(x) logf(x)
-#define EXPF(x) expf(x)
-#define LDEXPF(x,y) ldexpf(x,y)
-#define FREXPF(x,y) frexpf(x,y)
-#else
-#define CEILF(x) ((GLfloat) ceil(x))
-#define FLOORF(x) ((GLfloat) floor(x))
-#define FABSF(x) ((GLfloat) fabs(x))
-#define LOGF(x) ((GLfloat) log(x))
-#define EXPF(x) ((GLfloat) exp(x))
-#define LDEXPF(x,y) ((GLfloat) ldexp(x,y))
-#define FREXPF(x,y) ((GLfloat) frexp(x,y))
-#endif
-
-
-/***
- *** IROUND: return (as an integer) float rounded to nearest integer
- ***/
-#if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
-static INLINE int iround(float f)
-{
- int r;
- __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
- return r;
-}
-#define IROUND(x) iround(x)
-#elif defined(USE_X86_ASM) && defined(_MSC_VER)
-static INLINE int iround(float f)
-{
- int r;
- _asm {
- fld f
- fistp r
- }
- return r;
-}
-#define IROUND(x) iround(x)
-#elif defined(__WATCOMC__) && defined(__386__)
-long iround(float f);
-#pragma aux iround = \
- "push eax" \
- "fistp dword ptr [esp]" \
- "pop eax" \
- parm [8087] \
- value [eax] \
- modify exact [eax];
-#define IROUND(x) iround(x)
-#else
-#define IROUND(f) ((int) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
-#endif
-
-#define IROUND64(f) ((GLint64) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
-
-/***
- *** IROUND_POS: return (as an integer) positive float rounded to nearest int
- ***/
-#ifdef DEBUG
-#define IROUND_POS(f) (assert((f) >= 0.0F), IROUND(f))
-#else
-#define IROUND_POS(f) (IROUND(f))
-#endif
-
-
-/***
- *** IFLOOR: return (as an integer) floor of float
- ***/
-#if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
-/*
- * IEEE floor for computers that round to nearest or even.
- * 'f' must be between -4194304 and 4194303.
- * This floor operation is done by "(iround(f + .5) + iround(f - .5)) >> 1",
- * but uses some IEEE specific tricks for better speed.
- * Contributed by Josh Vanderhoof
- */
-static INLINE int ifloor(float f)
-{
- int ai, bi;
- double af, bf;
- af = (3 << 22) + 0.5 + (double)f;
- bf = (3 << 22) + 0.5 - (double)f;
- /* GCC generates an extra fstp/fld without this. */
- __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
- __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
- return (ai - bi) >> 1;
-}
-#define IFLOOR(x) ifloor(x)
-#elif defined(USE_IEEE)
-static INLINE int ifloor(float f)
-{
- int ai, bi;
- double af, bf;
- fi_type u;
-
- af = (3 << 22) + 0.5 + (double)f;
- bf = (3 << 22) + 0.5 - (double)f;
- u.f = (float) af; ai = u.i;
- u.f = (float) bf; bi = u.i;
- return (ai - bi) >> 1;
-}
-#define IFLOOR(x) ifloor(x)
-#else
-static INLINE int ifloor(float f)
-{
- int i = IROUND(f);
- return (i > f) ? i - 1 : i;
-}
-#define IFLOOR(x) ifloor(x)
-#endif
-
-
-/***
- *** ICEIL: return (as an integer) ceiling of float
- ***/
-#if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
-/*
- * IEEE ceil for computers that round to nearest or even.
- * 'f' must be between -4194304 and 4194303.
- * This ceil operation is done by "(iround(f + .5) + iround(f - .5) + 1) >> 1",
- * but uses some IEEE specific tricks for better speed.
- * Contributed by Josh Vanderhoof
- */
-static INLINE int iceil(float f)
-{
- int ai, bi;
- double af, bf;
- af = (3 << 22) + 0.5 + (double)f;
- bf = (3 << 22) + 0.5 - (double)f;
- /* GCC generates an extra fstp/fld without this. */
- __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
- __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
- return (ai - bi + 1) >> 1;
-}
-#define ICEIL(x) iceil(x)
-#elif defined(USE_IEEE)
-static INLINE int iceil(float f)
-{
- int ai, bi;
- double af, bf;
- fi_type u;
- af = (3 << 22) + 0.5 + (double)f;
- bf = (3 << 22) + 0.5 - (double)f;
- u.f = (float) af; ai = u.i;
- u.f = (float) bf; bi = u.i;
- return (ai - bi + 1) >> 1;
-}
-#define ICEIL(x) iceil(x)
-#else
-static INLINE int iceil(float f)
-{
- int i = IROUND(f);
- return (i < f) ? i + 1 : i;
-}
-#define ICEIL(x) iceil(x)
-#endif
-
-
-/**
- * Is x a power of two?
- */
-static INLINE int
-_mesa_is_pow_two(int x)
-{
- return !(x & (x - 1));
-}
-
-/**
- * Round given integer to next higer power of two
- * If X is zero result is undefined.
- *
- * Source for the fallback implementation is
- * Sean Eron Anderson's webpage "Bit Twiddling Hacks"
- * http://graphics.stanford.edu/~seander/bithacks.html
- *
- * When using builtin function have to do some work
- * for case when passed values 1 to prevent hiting
- * undefined result from __builtin_clz. Undefined
- * results would be different depending on optimization
- * level used for build.
- */
-static INLINE int32_t
-_mesa_next_pow_two_32(uint32_t x)
-{
-#if defined(__GNUC__) && \
- ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
- uint32_t y = (x != 1);
- return (1 + y) << ((__builtin_clz(x - y) ^ 31) );
-#else
- x--;
- x |= x >> 1;
- x |= x >> 2;
- x |= x >> 4;
- x |= x >> 8;
- x |= x >> 16;
- x++;
- return x;
-#endif
-}
-
-static INLINE int64_t
-_mesa_next_pow_two_64(uint64_t x)
-{
-#if defined(__GNUC__) && \
- ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
- uint64_t y = (x != 1);
- if (sizeof(x) == sizeof(long))
- return (1 + y) << ((__builtin_clzl(x - y) ^ 63));
- else
- return (1 + y) << ((__builtin_clzll(x - y) ^ 63));
-#else
- x--;
- x |= x >> 1;
- x |= x >> 2;
- x |= x >> 4;
- x |= x >> 8;
- x |= x >> 16;
- x |= x >> 32;
- x++;
- return x;
-#endif
-}
-
-
-/**
- * Return 1 if this is a little endian machine, 0 if big endian.
- */
-static INLINE GLboolean
-_mesa_little_endian(void)
-{
- const GLuint ui = 1; /* intentionally not static */
- return *((const GLubyte *) &ui);
-}
-
-
-
-/**********************************************************************
- * Functions
- */
-
-extern void *
-_mesa_align_malloc( size_t bytes, unsigned long alignment );
-
-extern void *
-_mesa_align_calloc( size_t bytes, unsigned long alignment );
-
-extern void
-_mesa_align_free( void *ptr );
-
-extern void *
-_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
- unsigned long alignment);
-
-extern void *
-_mesa_exec_malloc( GLuint size );
-
-extern void
-_mesa_exec_free( void *addr );
-
-extern void *
-_mesa_realloc( void *oldBuffer, size_t oldSize, size_t newSize );
-
-extern void
-_mesa_memset16( unsigned short *dst, unsigned short val, size_t n );
-
-extern double
-_mesa_sqrtd(double x);
-
-extern float
-_mesa_sqrtf(float x);
-
-extern float
-_mesa_inv_sqrtf(float x);
-
-extern void
-_mesa_init_sqrt_table(void);
-
-#ifdef __GNUC__
-
-#ifdef __MINGW32__
-#define ffs __builtin_ffs
-#define ffsll __builtin_ffsll
-#endif
-
-#define _mesa_ffs(i) ffs(i)
-#define _mesa_ffsll(i) ffsll(i)
-
-#if ((_GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
-#define _mesa_bitcount(i) __builtin_popcount(i)
-#else
-extern unsigned int
-_mesa_bitcount(unsigned int n);
-#endif
-
-#else
-extern int
-_mesa_ffs(int32_t i);
-
-extern int
-_mesa_ffsll(int64_t i);
-
-extern unsigned int
-_mesa_bitcount(unsigned int n);
-#endif
-
-extern GLhalfARB
-_mesa_float_to_half(float f);
-
-extern float
-_mesa_half_to_float(GLhalfARB h);
-
-
-extern void *
-_mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size,
- int (*compar)(const void *, const void *) );
-
-extern char *
-_mesa_getenv( const char *var );
-
-extern char *
-_mesa_strdup( const char *s );
-
-extern float
-_mesa_strtof( const char *s, char **end );
-
-extern unsigned int
-_mesa_str_checksum(const char *str);
-
-extern int
-_mesa_snprintf( char *str, size_t size, const char *fmt, ... ) PRINTFLIKE(3, 4);
-
-struct gl_context;
-
-extern void
-_mesa_warning( struct gl_context *gc, const char *fmtString, ... ) PRINTFLIKE(2, 3);
-
-extern void
-_mesa_problem( const struct gl_context *ctx, const char *fmtString, ... ) PRINTFLIKE(2, 3);
-
-extern void
-_mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... ) PRINTFLIKE(3, 4);
-
-extern void
-_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... ) PRINTFLIKE(2, 3);
-
-
-#if defined(_MSC_VER) && !defined(snprintf)
-#define snprintf _snprintf
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* IMPORTS_H */
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.5
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file imports.h
+ * Standard C library function wrappers.
+ *
+ * This file provides wrappers for all the standard C library functions
+ * like malloc(), free(), printf(), getenv(), etc.
+ */
+
+
+#ifndef IMPORTS_H
+#define IMPORTS_H
+
+
+#include "compiler.h"
+#include "glheader.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**********************************************************************/
+/** Memory macros */
+/*@{*/
+
+/** Allocate \p BYTES bytes */
+#define MALLOC(BYTES) malloc(BYTES)
+/** Allocate and zero \p BYTES bytes */
+#define CALLOC(BYTES) calloc(1, BYTES)
+/** Allocate a structure of type \p T */
+#define MALLOC_STRUCT(T) (struct T *) malloc(sizeof(struct T))
+/** Allocate and zero a structure of type \p T */
+#define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
+/** Free memory */
+#define FREE(PTR) free(PTR)
+
+/*@}*/
+
+
+/*
+ * For GL_ARB_vertex_buffer_object we need to treat vertex array pointers
+ * as offsets into buffer stores. Since the vertex array pointer and
+ * buffer store pointer are both pointers and we need to add them, we use
+ * this macro.
+ * Both pointers/offsets are expressed in bytes.
+ */
+#define ADD_POINTERS(A, B) ( (GLubyte *) (A) + (uintptr_t) (B) )
+
+
+/**
+ * Sometimes we treat GLfloats as GLints. On x86 systems, moving a float
+ * as a int (thereby using integer registers instead of FP registers) is
+ * a performance win. Typically, this can be done with ordinary casts.
+ * But with gcc's -fstrict-aliasing flag (which defaults to on in gcc 3.0)
+ * these casts generate warnings.
+ * The following union typedef is used to solve that.
+ */
+typedef union { GLfloat f; GLint i; } fi_type;
+
+
+
+/**********************************************************************
+ * Math macros
+ */
+
+#define MAX_GLUSHORT 0xffff
+#define MAX_GLUINT 0xffffffff
+
+/* Degrees to radians conversion: */
+#define DEG2RAD (M_PI/180.0)
+
+
+/***
+ *** SQRTF: single-precision square root
+ ***/
+#if 0 /* _mesa_sqrtf() not accurate enough - temporarily disabled */
+# define SQRTF(X) _mesa_sqrtf(X)
+#else
+# define SQRTF(X) (float) sqrt((float) (X))
+#endif
+
+
+/***
+ *** INV_SQRTF: single-precision inverse square root
+ ***/
+#if 0
+#define INV_SQRTF(X) _mesa_inv_sqrt(X)
+#else
+#define INV_SQRTF(X) (1.0F / SQRTF(X)) /* this is faster on a P4 */
+#endif
+
+
+/**
+ * \name Work-arounds for platforms that lack C99 math functions
+ */
+/*@{*/
+#if (!defined(_XOPEN_SOURCE) || (_XOPEN_SOURCE < 600)) && !defined(_ISOC99_SOURCE) \
+ && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)) \
+ && (!defined(_MSC_VER) || (_MSC_VER < 1400))
+#define acosf(f) ((float) acos(f))
+#define asinf(f) ((float) asin(f))
+#define atan2f(x,y) ((float) atan2(x,y))
+#define atanf(f) ((float) atan(f))
+#define cielf(f) ((float) ciel(f))
+#define cosf(f) ((float) cos(f))
+#define coshf(f) ((float) cosh(f))
+#define expf(f) ((float) exp(f))
+#define exp2f(f) ((float) exp2(f))
+#define floorf(f) ((float) floor(f))
+#define logf(f) ((float) log(f))
+#define log2f(f) ((float) log2(f))
+#define powf(x,y) ((float) pow(x,y))
+#define sinf(f) ((float) sin(f))
+#define sinhf(f) ((float) sinh(f))
+#define sqrtf(f) ((float) sqrt(f))
+#define tanf(f) ((float) tan(f))
+#define tanhf(f) ((float) tanh(f))
+#define acoshf(f) ((float) acosh(f))
+#define asinhf(f) ((float) asinh(f))
+#define atanhf(f) ((float) atanh(f))
+#endif
+
+#if defined(_MSC_VER)
+static INLINE float truncf(float x) { return x < 0.0f ? ceilf(x) : floorf(x); }
+static INLINE float exp2f(float x) { return powf(2.0f, x); }
+static INLINE float log2f(float x) { return logf(x) * 1.442695041f; }
+static INLINE float asinhf(float x) { return logf(x + sqrtf(x * x + 1.0f)); }
+static INLINE float acoshf(float x) { return logf(x + sqrtf(x * x - 1.0f)); }
+static INLINE float atanhf(float x) { return (logf(1.0f + x) - logf(1.0f - x)) / 2.0f; }
+static INLINE int isblank(int ch) { return ch == ' ' || ch == '\t'; }
+#define strtoll(p, e, b) _strtoi64(p, e, b)
+#endif
+/*@}*/
+
+/***
+ *** LOG2: Log base 2 of float
+ ***/
+#ifdef USE_IEEE
+#if 0
+/* This is pretty fast, but not accurate enough (only 2 fractional bits).
+ * Based on code from http://www.stereopsis.com/log2.html
+ */
+static INLINE GLfloat LOG2(GLfloat x)
+{
+ const GLfloat y = x * x * x * x;
+ const GLuint ix = *((GLuint *) &y);
+ const GLuint exp = (ix >> 23) & 0xFF;
+ const GLint log2 = ((GLint) exp) - 127;
+ return (GLfloat) log2 * (1.0 / 4.0); /* 4, because of x^4 above */
+}
+#endif
+/* Pretty fast, and accurate.
+ * Based on code from http://www.flipcode.com/totd/
+ */
+static INLINE GLfloat LOG2(GLfloat val)
+{
+ fi_type num;
+ GLint log_2;
+ num.f = val;
+ log_2 = ((num.i >> 23) & 255) - 128;
+ num.i &= ~(255 << 23);
+ num.i += 127 << 23;
+ num.f = ((-1.0f/3) * num.f + 2) * num.f - 2.0f/3;
+ return num.f + log_2;
+}
+#else
+/*
+ * NOTE: log_base_2(x) = log(x) / log(2)
+ * NOTE: 1.442695 = 1/log(2).
+ */
+#define LOG2(x) ((GLfloat) (log(x) * 1.442695F))
+#endif
+
+
+/***
+ *** IS_INF_OR_NAN: test if float is infinite or NaN
+ ***/
+#ifdef USE_IEEE
+static INLINE int IS_INF_OR_NAN( float x )
+{
+ fi_type tmp;
+ tmp.f = x;
+ return !(int)((unsigned int)((tmp.i & 0x7fffffff)-0x7f800000) >> 31);
+}
+#elif defined(isfinite)
+#define IS_INF_OR_NAN(x) (!isfinite(x))
+#elif defined(finite)
+#define IS_INF_OR_NAN(x) (!finite(x))
+#elif defined(__VMS)
+#define IS_INF_OR_NAN(x) (!finite(x))
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#define IS_INF_OR_NAN(x) (!isfinite(x))
+#else
+#define IS_INF_OR_NAN(x) (!finite(x))
+#endif
+
+
+/***
+ *** IS_NEGATIVE: test if float is negative
+ ***/
+#if defined(USE_IEEE)
+static INLINE int GET_FLOAT_BITS( float x )
+{
+ fi_type fi;
+ fi.f = x;
+ return fi.i;
+}
+#define IS_NEGATIVE(x) (GET_FLOAT_BITS(x) < 0)
+#else
+#define IS_NEGATIVE(x) (x < 0.0F)
+#endif
+
+
+/***
+ *** DIFFERENT_SIGNS: test if two floats have opposite signs
+ ***/
+#if defined(USE_IEEE)
+#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31))
+#else
+/* Could just use (x*y<0) except for the flatshading requirements.
+ * Maybe there's a better way?
+ */
+#define DIFFERENT_SIGNS(x,y) ((x) * (y) <= 0.0F && (x) - (y) != 0.0F)
+#endif
+
+
+/***
+ *** CEILF: ceiling of float
+ *** FLOORF: floor of float
+ *** FABSF: absolute value of float
+ *** LOGF: the natural logarithm (base e) of the value
+ *** EXPF: raise e to the value
+ *** LDEXPF: multiply value by an integral power of two
+ *** FREXPF: extract mantissa and exponent from value
+ ***/
+#if defined(__gnu_linux__)
+/* C99 functions */
+#define CEILF(x) ceilf(x)
+#define FLOORF(x) floorf(x)
+#define FABSF(x) fabsf(x)
+#define LOGF(x) logf(x)
+#define EXPF(x) expf(x)
+#define LDEXPF(x,y) ldexpf(x,y)
+#define FREXPF(x,y) frexpf(x,y)
+#else
+#define CEILF(x) ((GLfloat) ceil(x))
+#define FLOORF(x) ((GLfloat) floor(x))
+#define FABSF(x) ((GLfloat) fabs(x))
+#define LOGF(x) ((GLfloat) log(x))
+#define EXPF(x) ((GLfloat) exp(x))
+#define LDEXPF(x,y) ((GLfloat) ldexp(x,y))
+#define FREXPF(x,y) ((GLfloat) frexp(x,y))
+#endif
+
+
+/***
+ *** IROUND: return (as an integer) float rounded to nearest integer
+ ***/
+#if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
+static INLINE int iround(float f)
+{
+ int r;
+ __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
+ return r;
+}
+#define IROUND(x) iround(x)
+#elif defined(USE_X86_ASM) && defined(_MSC_VER)
+static INLINE int iround(float f)
+{
+ int r;
+ _asm {
+ fld f
+ fistp r
+ }
+ return r;
+}
+#define IROUND(x) iround(x)
+#elif defined(__WATCOMC__) && defined(__386__)
+long iround(float f);
+#pragma aux iround = \
+ "push eax" \
+ "fistp dword ptr [esp]" \
+ "pop eax" \
+ parm [8087] \
+ value [eax] \
+ modify exact [eax];
+#define IROUND(x) iround(x)
+#else
+#define IROUND(f) ((int) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
+#endif
+
+#define IROUND64(f) ((GLint64) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
+
+/***
+ *** IROUND_POS: return (as an integer) positive float rounded to nearest int
+ ***/
+#ifdef DEBUG
+#define IROUND_POS(f) (assert((f) >= 0.0F), IROUND(f))
+#else
+#define IROUND_POS(f) (IROUND(f))
+#endif
+
+
+/***
+ *** IFLOOR: return (as an integer) floor of float
+ ***/
+#if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
+/*
+ * IEEE floor for computers that round to nearest or even.
+ * 'f' must be between -4194304 and 4194303.
+ * This floor operation is done by "(iround(f + .5) + iround(f - .5)) >> 1",
+ * but uses some IEEE specific tricks for better speed.
+ * Contributed by Josh Vanderhoof
+ */
+static INLINE int ifloor(float f)
+{
+ int ai, bi;
+ double af, bf;
+ af = (3 << 22) + 0.5 + (double)f;
+ bf = (3 << 22) + 0.5 - (double)f;
+ /* GCC generates an extra fstp/fld without this. */
+ __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
+ __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
+ return (ai - bi) >> 1;
+}
+#define IFLOOR(x) ifloor(x)
+#elif defined(USE_IEEE)
+static INLINE int ifloor(float f)
+{
+ int ai, bi;
+ double af, bf;
+ fi_type u;
+
+ af = (3 << 22) + 0.5 + (double)f;
+ bf = (3 << 22) + 0.5 - (double)f;
+ u.f = (float) af; ai = u.i;
+ u.f = (float) bf; bi = u.i;
+ return (ai - bi) >> 1;
+}
+#define IFLOOR(x) ifloor(x)
+#else
+static INLINE int ifloor(float f)
+{
+ int i = IROUND(f);
+ return (i > f) ? i - 1 : i;
+}
+#define IFLOOR(x) ifloor(x)
+#endif
+
+
+/***
+ *** ICEIL: return (as an integer) ceiling of float
+ ***/
+#if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
+/*
+ * IEEE ceil for computers that round to nearest or even.
+ * 'f' must be between -4194304 and 4194303.
+ * This ceil operation is done by "(iround(f + .5) + iround(f - .5) + 1) >> 1",
+ * but uses some IEEE specific tricks for better speed.
+ * Contributed by Josh Vanderhoof
+ */
+static INLINE int iceil(float f)
+{
+ int ai, bi;
+ double af, bf;
+ af = (3 << 22) + 0.5 + (double)f;
+ bf = (3 << 22) + 0.5 - (double)f;
+ /* GCC generates an extra fstp/fld without this. */
+ __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
+ __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
+ return (ai - bi + 1) >> 1;
+}
+#define ICEIL(x) iceil(x)
+#elif defined(USE_IEEE)
+static INLINE int iceil(float f)
+{
+ int ai, bi;
+ double af, bf;
+ fi_type u;
+ af = (3 << 22) + 0.5 + (double)f;
+ bf = (3 << 22) + 0.5 - (double)f;
+ u.f = (float) af; ai = u.i;
+ u.f = (float) bf; bi = u.i;
+ return (ai - bi + 1) >> 1;
+}
+#define ICEIL(x) iceil(x)
+#else
+static INLINE int iceil(float f)
+{
+ int i = IROUND(f);
+ return (i < f) ? i + 1 : i;
+}
+#define ICEIL(x) iceil(x)
+#endif
+
+
+/**
+ * Is x a power of two?
+ */
+static INLINE int
+_mesa_is_pow_two(int x)
+{
+ return !(x & (x - 1));
+}
+
+/**
+ * Round given integer to next higer power of two
+ * If X is zero result is undefined.
+ *
+ * Source for the fallback implementation is
+ * Sean Eron Anderson's webpage "Bit Twiddling Hacks"
+ * http://graphics.stanford.edu/~seander/bithacks.html
+ *
+ * When using builtin function have to do some work
+ * for case when passed values 1 to prevent hiting
+ * undefined result from __builtin_clz. Undefined
+ * results would be different depending on optimization
+ * level used for build.
+ */
+static INLINE int32_t
+_mesa_next_pow_two_32(uint32_t x)
+{
+#if defined(__GNUC__) && \
+ ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
+ uint32_t y = (x != 1);
+ return (1 + y) << ((__builtin_clz(x - y) ^ 31) );
+#else
+ x--;
+ x |= x >> 1;
+ x |= x >> 2;
+ x |= x >> 4;
+ x |= x >> 8;
+ x |= x >> 16;
+ x++;
+ return x;
+#endif
+}
+
+static INLINE int64_t
+_mesa_next_pow_two_64(uint64_t x)
+{
+#if defined(__GNUC__) && \
+ ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
+ uint64_t y = (x != 1);
+ if (sizeof(x) == sizeof(long))
+ return (1 + y) << ((__builtin_clzl(x - y) ^ 63));
+ else
+ return (1 + y) << ((__builtin_clzll(x - y) ^ 63));
+#else
+ x--;
+ x |= x >> 1;
+ x |= x >> 2;
+ x |= x >> 4;
+ x |= x >> 8;
+ x |= x >> 16;
+ x |= x >> 32;
+ x++;
+ return x;
+#endif
+}
+
+
+/**
+ * Return 1 if this is a little endian machine, 0 if big endian.
+ */
+static INLINE GLboolean
+_mesa_little_endian(void)
+{
+ const GLuint ui = 1; /* intentionally not static */
+ return *((const GLubyte *) &ui);
+}
+
+
+
+/**********************************************************************
+ * Functions
+ */
+
+extern void *
+_mesa_align_malloc( size_t bytes, unsigned long alignment );
+
+extern void *
+_mesa_align_calloc( size_t bytes, unsigned long alignment );
+
+extern void
+_mesa_align_free( void *ptr );
+
+extern void *
+_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
+ unsigned long alignment);
+
+extern void *
+_mesa_exec_malloc( GLuint size );
+
+extern void
+_mesa_exec_free( void *addr );
+
+extern void *
+_mesa_realloc( void *oldBuffer, size_t oldSize, size_t newSize );
+
+extern void
+_mesa_memset16( unsigned short *dst, unsigned short val, size_t n );
+
+extern double
+_mesa_sqrtd(double x);
+
+extern float
+_mesa_sqrtf(float x);
+
+extern float
+_mesa_inv_sqrtf(float x);
+
+extern void
+_mesa_init_sqrt_table(void);
+
+#ifdef __GNUC__
+
+#ifdef __MINGW32__
+#define ffs __builtin_ffs
+#define ffsll __builtin_ffsll
+#endif
+
+#define _mesa_ffs(i) ffs(i)
+#define _mesa_ffsll(i) ffsll(i)
+
+#if ((_GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
+#define _mesa_bitcount(i) __builtin_popcount(i)
+#else
+extern unsigned int
+_mesa_bitcount(unsigned int n);
+#endif
+
+#else
+extern int
+_mesa_ffs(int32_t i);
+
+extern int
+_mesa_ffsll(int64_t i);
+
+extern unsigned int
+_mesa_bitcount(unsigned int n);
+#endif
+
+extern GLhalfARB
+_mesa_float_to_half(float f);
+
+extern float
+_mesa_half_to_float(GLhalfARB h);
+
+
+extern void *
+_mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size,
+ int (*compar)(const void *, const void *) );
+
+extern char *
+_mesa_getenv( const char *var );
+
+extern char *
+_mesa_strdup( const char *s );
+
+extern float
+_mesa_strtof( const char *s, char **end );
+
+extern unsigned int
+_mesa_str_checksum(const char *str);
+
+extern int
+_mesa_snprintf( char *str, size_t size, const char *fmt, ... ) PRINTFLIKE(3, 4);
+
+struct gl_context;
+
+extern void
+_mesa_warning( struct gl_context *gc, const char *fmtString, ... ) PRINTFLIKE(2, 3);
+
+extern void
+_mesa_problem( const struct gl_context *ctx, const char *fmtString, ... ) PRINTFLIKE(2, 3);
+
+extern void
+_mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... ) PRINTFLIKE(3, 4);
+
+extern void
+_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... ) PRINTFLIKE(2, 3);
+
+
+#if defined(_MSC_VER) && !defined(snprintf)
+#define snprintf _snprintf
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* IMPORTS_H */
diff --git a/mesalib/src/mesa/main/lines.c b/mesalib/src/mesa/main/lines.c
index 79bf5679d..1df409f45 100644
--- a/mesalib/src/mesa/main/lines.c
+++ b/mesalib/src/mesa/main/lines.c
@@ -1,117 +1,117 @@
-/*
- * Mesa 3-D graphics library
- * Version: 6.5.3
- *
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "glheader.h"
-#include "context.h"
-#include "lines.h"
-#include "macros.h"
-#include "mtypes.h"
-
-
-/**
- * Set the line width.
- *
- * \param width line width in pixels.
- *
- * \sa glLineWidth().
- */
-void GLAPIENTRY
-_mesa_LineWidth( GLfloat width )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glLineWidth %f\n", width);
-
- if (width<=0.0) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" );
- return;
- }
-
- if (ctx->Line.Width == width)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_LINE);
- ctx->Line.Width = width;
-
- if (ctx->Driver.LineWidth)
- ctx->Driver.LineWidth(ctx, width);
-}
-
-
-/**
- * Set the line stipple pattern.
- *
- * \param factor pattern scale factor.
- * \param pattern bit pattern.
- *
- * \sa glLineStipple().
- *
- * Updates gl_line_attrib::StippleFactor and gl_line_attrib::StipplePattern. On
- * change flushes the vertices and notifies the driver via
- * the dd_function_table::LineStipple callback.
- */
-void GLAPIENTRY
-_mesa_LineStipple( GLint factor, GLushort pattern )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glLineStipple %d %u\n", factor, pattern);
-
- factor = CLAMP( factor, 1, 256 );
-
- if (ctx->Line.StippleFactor == factor &&
- ctx->Line.StipplePattern == pattern)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_LINE);
- ctx->Line.StippleFactor = factor;
- ctx->Line.StipplePattern = pattern;
-
- if (ctx->Driver.LineStipple)
- ctx->Driver.LineStipple( ctx, factor, pattern );
-}
-
-
-/**
- * Initialize the context line state.
- *
- * \param ctx GL context.
- *
- * Initializes __struct gl_contextRec::Line and line related constants in
- * __struct gl_contextRec::Const.
- */
-void GLAPIENTRY
-_mesa_init_line( struct gl_context * ctx )
-{
- ctx->Line.SmoothFlag = GL_FALSE;
- ctx->Line.StippleFlag = GL_FALSE;
- ctx->Line.Width = 1.0;
- ctx->Line.StipplePattern = 0xffff;
- ctx->Line.StippleFactor = 1;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5.3
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "glheader.h"
+#include "context.h"
+#include "lines.h"
+#include "macros.h"
+#include "mtypes.h"
+
+
+/**
+ * Set the line width.
+ *
+ * \param width line width in pixels.
+ *
+ * \sa glLineWidth().
+ */
+void GLAPIENTRY
+_mesa_LineWidth( GLfloat width )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glLineWidth %f\n", width);
+
+ if (width<=0.0) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" );
+ return;
+ }
+
+ if (ctx->Line.Width == width)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_LINE);
+ ctx->Line.Width = width;
+
+ if (ctx->Driver.LineWidth)
+ ctx->Driver.LineWidth(ctx, width);
+}
+
+
+/**
+ * Set the line stipple pattern.
+ *
+ * \param factor pattern scale factor.
+ * \param pattern bit pattern.
+ *
+ * \sa glLineStipple().
+ *
+ * Updates gl_line_attrib::StippleFactor and gl_line_attrib::StipplePattern. On
+ * change flushes the vertices and notifies the driver via
+ * the dd_function_table::LineStipple callback.
+ */
+void GLAPIENTRY
+_mesa_LineStipple( GLint factor, GLushort pattern )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glLineStipple %d %u\n", factor, pattern);
+
+ factor = CLAMP( factor, 1, 256 );
+
+ if (ctx->Line.StippleFactor == factor &&
+ ctx->Line.StipplePattern == pattern)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_LINE);
+ ctx->Line.StippleFactor = factor;
+ ctx->Line.StipplePattern = pattern;
+
+ if (ctx->Driver.LineStipple)
+ ctx->Driver.LineStipple( ctx, factor, pattern );
+}
+
+
+/**
+ * Initialize the context line state.
+ *
+ * \param ctx GL context.
+ *
+ * Initializes __struct gl_contextRec::Line and line related constants in
+ * __struct gl_contextRec::Const.
+ */
+void GLAPIENTRY
+_mesa_init_line( struct gl_context * ctx )
+{
+ ctx->Line.SmoothFlag = GL_FALSE;
+ ctx->Line.StippleFlag = GL_FALSE;
+ ctx->Line.Width = 1.0;
+ ctx->Line.StipplePattern = 0xffff;
+ ctx->Line.StippleFactor = 1;
+}
diff --git a/mesalib/src/mesa/main/mipmap.c b/mesalib/src/mesa/main/mipmap.c
index 0727e1818..453d7f29b 100644
--- a/mesalib/src/mesa/main/mipmap.c
+++ b/mesalib/src/mesa/main/mipmap.c
@@ -1,2022 +1,2022 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file mipmap.c mipmap generation and teximage resizing functions.
- */
-
-#include "imports.h"
-#include "formats.h"
-#include "mipmap.h"
-#include "mtypes.h"
-#include "teximage.h"
-#include "texstore.h"
-#include "image.h"
-
-
-
-static GLint
-bytes_per_pixel(GLenum datatype, GLuint comps)
-{
- GLint b = _mesa_sizeof_packed_type(datatype);
- assert(b >= 0);
-
- if (_mesa_type_is_packed(datatype))
- return b;
- else
- return b * comps;
-}
-
-
-/**
- * \name Support macros for do_row and do_row_3d
- *
- * The macro madness is here for two reasons. First, it compacts the code
- * slightly. Second, it makes it much easier to adjust the specifics of the
- * filter to tune the rounding characteristics.
- */
-/*@{*/
-#define DECLARE_ROW_POINTERS(t, e) \
- const t(*rowA)[e] = (const t(*)[e]) srcRowA; \
- const t(*rowB)[e] = (const t(*)[e]) srcRowB; \
- const t(*rowC)[e] = (const t(*)[e]) srcRowC; \
- const t(*rowD)[e] = (const t(*)[e]) srcRowD; \
- t(*dst)[e] = (t(*)[e]) dstRow
-
-#define DECLARE_ROW_POINTERS0(t) \
- const t *rowA = (const t *) srcRowA; \
- const t *rowB = (const t *) srcRowB; \
- const t *rowC = (const t *) srcRowC; \
- const t *rowD = (const t *) srcRowD; \
- t *dst = (t *) dstRow
-
-#define FILTER_SUM_3D(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
- ((unsigned) Aj + (unsigned) Ak \
- + (unsigned) Bj + (unsigned) Bk \
- + (unsigned) Cj + (unsigned) Ck \
- + (unsigned) Dj + (unsigned) Dk \
- + 4) >> 3
-
-#define FILTER_3D(e) \
- do { \
- dst[i][e] = FILTER_SUM_3D(rowA[j][e], rowA[k][e], \
- rowB[j][e], rowB[k][e], \
- rowC[j][e], rowC[k][e], \
- rowD[j][e], rowD[k][e]); \
- } while(0)
-
-#define FILTER_SUM_3D_SIGNED(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
- (Aj + Ak \
- + Bj + Bk \
- + Cj + Ck \
- + Dj + Dk \
- + 4) / 8
-
-#define FILTER_3D_SIGNED(e) \
- do { \
- dst[i][e] = FILTER_SUM_3D_SIGNED(rowA[j][e], rowA[k][e], \
- rowB[j][e], rowB[k][e], \
- rowC[j][e], rowC[k][e], \
- rowD[j][e], rowD[k][e]); \
- } while(0)
-
-#define FILTER_F_3D(e) \
- do { \
- dst[i][e] = (rowA[j][e] + rowA[k][e] \
- + rowB[j][e] + rowB[k][e] \
- + rowC[j][e] + rowC[k][e] \
- + rowD[j][e] + rowD[k][e]) * 0.125F; \
- } while(0)
-
-#define FILTER_HF_3D(e) \
- do { \
- const GLfloat aj = _mesa_half_to_float(rowA[j][e]); \
- const GLfloat ak = _mesa_half_to_float(rowA[k][e]); \
- const GLfloat bj = _mesa_half_to_float(rowB[j][e]); \
- const GLfloat bk = _mesa_half_to_float(rowB[k][e]); \
- const GLfloat cj = _mesa_half_to_float(rowC[j][e]); \
- const GLfloat ck = _mesa_half_to_float(rowC[k][e]); \
- const GLfloat dj = _mesa_half_to_float(rowD[j][e]); \
- const GLfloat dk = _mesa_half_to_float(rowD[k][e]); \
- dst[i][e] = _mesa_float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \
- * 0.125F); \
- } while(0)
-/*@}*/
-
-
-/**
- * Average together two rows of a source image to produce a single new
- * row in the dest image. It's legal for the two source rows to point
- * to the same data. The source width must be equal to either the
- * dest width or two times the dest width.
- * \param datatype GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_FLOAT, etc.
- * \param comps number of components per pixel (1..4)
- */
-static void
-do_row(GLenum datatype, GLuint comps, GLint srcWidth,
- const GLvoid *srcRowA, const GLvoid *srcRowB,
- GLint dstWidth, GLvoid *dstRow)
-{
- const GLuint k0 = (srcWidth == dstWidth) ? 0 : 1;
- const GLuint colStride = (srcWidth == dstWidth) ? 1 : 2;
-
- ASSERT(comps >= 1);
- ASSERT(comps <= 4);
-
- /* This assertion is no longer valid with non-power-of-2 textures
- assert(srcWidth == dstWidth || srcWidth == 2 * dstWidth);
- */
-
- if (datatype == GL_UNSIGNED_BYTE && comps == 4) {
- GLuint i, j, k;
- const GLubyte(*rowA)[4] = (const GLubyte(*)[4]) srcRowA;
- const GLubyte(*rowB)[4] = (const GLubyte(*)[4]) srcRowB;
- GLubyte(*dst)[4] = (GLubyte(*)[4]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
- dst[i][3] = (rowA[j][3] + rowA[k][3] + rowB[j][3] + rowB[k][3]) / 4;
- }
- }
- else if (datatype == GL_UNSIGNED_BYTE && comps == 3) {
- GLuint i, j, k;
- const GLubyte(*rowA)[3] = (const GLubyte(*)[3]) srcRowA;
- const GLubyte(*rowB)[3] = (const GLubyte(*)[3]) srcRowB;
- GLubyte(*dst)[3] = (GLubyte(*)[3]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
- }
- }
- else if (datatype == GL_UNSIGNED_BYTE && comps == 2) {
- GLuint i, j, k;
- const GLubyte(*rowA)[2] = (const GLubyte(*)[2]) srcRowA;
- const GLubyte(*rowB)[2] = (const GLubyte(*)[2]) srcRowB;
- GLubyte(*dst)[2] = (GLubyte(*)[2]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) >> 2;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) >> 2;
- }
- }
- else if (datatype == GL_UNSIGNED_BYTE && comps == 1) {
- GLuint i, j, k;
- const GLubyte *rowA = (const GLubyte *) srcRowA;
- const GLubyte *rowB = (const GLubyte *) srcRowB;
- GLubyte *dst = (GLubyte *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) >> 2;
- }
- }
-
- else if (datatype == GL_BYTE && comps == 4) {
- GLuint i, j, k;
- const GLbyte(*rowA)[4] = (const GLbyte(*)[4]) srcRowA;
- const GLbyte(*rowB)[4] = (const GLbyte(*)[4]) srcRowB;
- GLbyte(*dst)[4] = (GLbyte(*)[4]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
- dst[i][3] = (rowA[j][3] + rowA[k][3] + rowB[j][3] + rowB[k][3]) / 4;
- }
- }
- else if (datatype == GL_BYTE && comps == 3) {
- GLuint i, j, k;
- const GLbyte(*rowA)[3] = (const GLbyte(*)[3]) srcRowA;
- const GLbyte(*rowB)[3] = (const GLbyte(*)[3]) srcRowB;
- GLbyte(*dst)[3] = (GLbyte(*)[3]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
- }
- }
- else if (datatype == GL_BYTE && comps == 2) {
- GLuint i, j, k;
- const GLbyte(*rowA)[2] = (const GLbyte(*)[2]) srcRowA;
- const GLbyte(*rowB)[2] = (const GLbyte(*)[2]) srcRowB;
- GLbyte(*dst)[2] = (GLbyte(*)[2]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- }
- }
- else if (datatype == GL_BYTE && comps == 1) {
- GLuint i, j, k;
- const GLbyte *rowA = (const GLbyte *) srcRowA;
- const GLbyte *rowB = (const GLbyte *) srcRowB;
- GLbyte *dst = (GLbyte *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) / 4;
- }
- }
-
- else if (datatype == GL_UNSIGNED_SHORT && comps == 4) {
- GLuint i, j, k;
- const GLushort(*rowA)[4] = (const GLushort(*)[4]) srcRowA;
- const GLushort(*rowB)[4] = (const GLushort(*)[4]) srcRowB;
- GLushort(*dst)[4] = (GLushort(*)[4]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
- dst[i][3] = (rowA[j][3] + rowA[k][3] + rowB[j][3] + rowB[k][3]) / 4;
- }
- }
- else if (datatype == GL_UNSIGNED_SHORT && comps == 3) {
- GLuint i, j, k;
- const GLushort(*rowA)[3] = (const GLushort(*)[3]) srcRowA;
- const GLushort(*rowB)[3] = (const GLushort(*)[3]) srcRowB;
- GLushort(*dst)[3] = (GLushort(*)[3]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
- }
- }
- else if (datatype == GL_UNSIGNED_SHORT && comps == 2) {
- GLuint i, j, k;
- const GLushort(*rowA)[2] = (const GLushort(*)[2]) srcRowA;
- const GLushort(*rowB)[2] = (const GLushort(*)[2]) srcRowB;
- GLushort(*dst)[2] = (GLushort(*)[2]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- }
- }
- else if (datatype == GL_UNSIGNED_SHORT && comps == 1) {
- GLuint i, j, k;
- const GLushort *rowA = (const GLushort *) srcRowA;
- const GLushort *rowB = (const GLushort *) srcRowB;
- GLushort *dst = (GLushort *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) / 4;
- }
- }
-
- else if (datatype == GL_SHORT && comps == 4) {
- GLuint i, j, k;
- const GLshort(*rowA)[4] = (const GLshort(*)[4]) srcRowA;
- const GLshort(*rowB)[4] = (const GLshort(*)[4]) srcRowB;
- GLshort(*dst)[4] = (GLshort(*)[4]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
- dst[i][3] = (rowA[j][3] + rowA[k][3] + rowB[j][3] + rowB[k][3]) / 4;
- }
- }
- else if (datatype == GL_SHORT && comps == 3) {
- GLuint i, j, k;
- const GLshort(*rowA)[3] = (const GLshort(*)[3]) srcRowA;
- const GLshort(*rowB)[3] = (const GLshort(*)[3]) srcRowB;
- GLshort(*dst)[3] = (GLshort(*)[3]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
- }
- }
- else if (datatype == GL_SHORT && comps == 2) {
- GLuint i, j, k;
- const GLshort(*rowA)[2] = (const GLshort(*)[2]) srcRowA;
- const GLshort(*rowB)[2] = (const GLshort(*)[2]) srcRowB;
- GLshort(*dst)[2] = (GLshort(*)[2]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
- dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
- }
- }
- else if (datatype == GL_SHORT && comps == 1) {
- GLuint i, j, k;
- const GLshort *rowA = (const GLshort *) srcRowA;
- const GLshort *rowB = (const GLshort *) srcRowB;
- GLshort *dst = (GLshort *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) / 4;
- }
- }
-
- else if (datatype == GL_FLOAT && comps == 4) {
- GLuint i, j, k;
- const GLfloat(*rowA)[4] = (const GLfloat(*)[4]) srcRowA;
- const GLfloat(*rowB)[4] = (const GLfloat(*)[4]) srcRowB;
- GLfloat(*dst)[4] = (GLfloat(*)[4]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] +
- rowB[j][0] + rowB[k][0]) * 0.25F;
- dst[i][1] = (rowA[j][1] + rowA[k][1] +
- rowB[j][1] + rowB[k][1]) * 0.25F;
- dst[i][2] = (rowA[j][2] + rowA[k][2] +
- rowB[j][2] + rowB[k][2]) * 0.25F;
- dst[i][3] = (rowA[j][3] + rowA[k][3] +
- rowB[j][3] + rowB[k][3]) * 0.25F;
- }
- }
- else if (datatype == GL_FLOAT && comps == 3) {
- GLuint i, j, k;
- const GLfloat(*rowA)[3] = (const GLfloat(*)[3]) srcRowA;
- const GLfloat(*rowB)[3] = (const GLfloat(*)[3]) srcRowB;
- GLfloat(*dst)[3] = (GLfloat(*)[3]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] +
- rowB[j][0] + rowB[k][0]) * 0.25F;
- dst[i][1] = (rowA[j][1] + rowA[k][1] +
- rowB[j][1] + rowB[k][1]) * 0.25F;
- dst[i][2] = (rowA[j][2] + rowA[k][2] +
- rowB[j][2] + rowB[k][2]) * 0.25F;
- }
- }
- else if (datatype == GL_FLOAT && comps == 2) {
- GLuint i, j, k;
- const GLfloat(*rowA)[2] = (const GLfloat(*)[2]) srcRowA;
- const GLfloat(*rowB)[2] = (const GLfloat(*)[2]) srcRowB;
- GLfloat(*dst)[2] = (GLfloat(*)[2]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i][0] = (rowA[j][0] + rowA[k][0] +
- rowB[j][0] + rowB[k][0]) * 0.25F;
- dst[i][1] = (rowA[j][1] + rowA[k][1] +
- rowB[j][1] + rowB[k][1]) * 0.25F;
- }
- }
- else if (datatype == GL_FLOAT && comps == 1) {
- GLuint i, j, k;
- const GLfloat *rowA = (const GLfloat *) srcRowA;
- const GLfloat *rowB = (const GLfloat *) srcRowB;
- GLfloat *dst = (GLfloat *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) * 0.25F;
- }
- }
-
- else if (datatype == GL_HALF_FLOAT_ARB && comps == 4) {
- GLuint i, j, k, comp;
- const GLhalfARB(*rowA)[4] = (const GLhalfARB(*)[4]) srcRowA;
- const GLhalfARB(*rowB)[4] = (const GLhalfARB(*)[4]) srcRowB;
- GLhalfARB(*dst)[4] = (GLhalfARB(*)[4]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- for (comp = 0; comp < 4; comp++) {
- GLfloat aj, ak, bj, bk;
- aj = _mesa_half_to_float(rowA[j][comp]);
- ak = _mesa_half_to_float(rowA[k][comp]);
- bj = _mesa_half_to_float(rowB[j][comp]);
- bk = _mesa_half_to_float(rowB[k][comp]);
- dst[i][comp] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);
- }
- }
- }
- else if (datatype == GL_HALF_FLOAT_ARB && comps == 3) {
- GLuint i, j, k, comp;
- const GLhalfARB(*rowA)[3] = (const GLhalfARB(*)[3]) srcRowA;
- const GLhalfARB(*rowB)[3] = (const GLhalfARB(*)[3]) srcRowB;
- GLhalfARB(*dst)[3] = (GLhalfARB(*)[3]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- for (comp = 0; comp < 3; comp++) {
- GLfloat aj, ak, bj, bk;
- aj = _mesa_half_to_float(rowA[j][comp]);
- ak = _mesa_half_to_float(rowA[k][comp]);
- bj = _mesa_half_to_float(rowB[j][comp]);
- bk = _mesa_half_to_float(rowB[k][comp]);
- dst[i][comp] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);
- }
- }
- }
- else if (datatype == GL_HALF_FLOAT_ARB && comps == 2) {
- GLuint i, j, k, comp;
- const GLhalfARB(*rowA)[2] = (const GLhalfARB(*)[2]) srcRowA;
- const GLhalfARB(*rowB)[2] = (const GLhalfARB(*)[2]) srcRowB;
- GLhalfARB(*dst)[2] = (GLhalfARB(*)[2]) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- for (comp = 0; comp < 2; comp++) {
- GLfloat aj, ak, bj, bk;
- aj = _mesa_half_to_float(rowA[j][comp]);
- ak = _mesa_half_to_float(rowA[k][comp]);
- bj = _mesa_half_to_float(rowB[j][comp]);
- bk = _mesa_half_to_float(rowB[k][comp]);
- dst[i][comp] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);
- }
- }
- }
- else if (datatype == GL_HALF_FLOAT_ARB && comps == 1) {
- GLuint i, j, k;
- const GLhalfARB *rowA = (const GLhalfARB *) srcRowA;
- const GLhalfARB *rowB = (const GLhalfARB *) srcRowB;
- GLhalfARB *dst = (GLhalfARB *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- GLfloat aj, ak, bj, bk;
- aj = _mesa_half_to_float(rowA[j]);
- ak = _mesa_half_to_float(rowA[k]);
- bj = _mesa_half_to_float(rowB[j]);
- bk = _mesa_half_to_float(rowB[k]);
- dst[i] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);
- }
- }
-
- else if (datatype == GL_UNSIGNED_INT && comps == 1) {
- GLuint i, j, k;
- const GLuint *rowA = (const GLuint *) srcRowA;
- const GLuint *rowB = (const GLuint *) srcRowB;
- GLuint *dst = (GLuint *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- dst[i] = (GLfloat)(rowA[j] / 4 + rowA[k] / 4 + rowB[j] / 4 + rowB[k] / 4);
- }
- }
-
- else if (datatype == GL_UNSIGNED_SHORT_5_6_5 && comps == 3) {
- GLuint i, j, k;
- const GLushort *rowA = (const GLushort *) srcRowA;
- const GLushort *rowB = (const GLushort *) srcRowB;
- GLushort *dst = (GLushort *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0x1f;
- const GLint rowAr1 = rowA[k] & 0x1f;
- const GLint rowBr0 = rowB[j] & 0x1f;
- const GLint rowBr1 = rowB[k] & 0x1f;
- const GLint rowAg0 = (rowA[j] >> 5) & 0x3f;
- const GLint rowAg1 = (rowA[k] >> 5) & 0x3f;
- const GLint rowBg0 = (rowB[j] >> 5) & 0x3f;
- const GLint rowBg1 = (rowB[k] >> 5) & 0x3f;
- const GLint rowAb0 = (rowA[j] >> 11) & 0x1f;
- const GLint rowAb1 = (rowA[k] >> 11) & 0x1f;
- const GLint rowBb0 = (rowB[j] >> 11) & 0x1f;
- const GLint rowBb1 = (rowB[k] >> 11) & 0x1f;
- const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
- const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
- const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
- dst[i] = (blue << 11) | (green << 5) | red;
- }
- }
- else if (datatype == GL_UNSIGNED_SHORT_4_4_4_4 && comps == 4) {
- GLuint i, j, k;
- const GLushort *rowA = (const GLushort *) srcRowA;
- const GLushort *rowB = (const GLushort *) srcRowB;
- GLushort *dst = (GLushort *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0xf;
- const GLint rowAr1 = rowA[k] & 0xf;
- const GLint rowBr0 = rowB[j] & 0xf;
- const GLint rowBr1 = rowB[k] & 0xf;
- const GLint rowAg0 = (rowA[j] >> 4) & 0xf;
- const GLint rowAg1 = (rowA[k] >> 4) & 0xf;
- const GLint rowBg0 = (rowB[j] >> 4) & 0xf;
- const GLint rowBg1 = (rowB[k] >> 4) & 0xf;
- const GLint rowAb0 = (rowA[j] >> 8) & 0xf;
- const GLint rowAb1 = (rowA[k] >> 8) & 0xf;
- const GLint rowBb0 = (rowB[j] >> 8) & 0xf;
- const GLint rowBb1 = (rowB[k] >> 8) & 0xf;
- const GLint rowAa0 = (rowA[j] >> 12) & 0xf;
- const GLint rowAa1 = (rowA[k] >> 12) & 0xf;
- const GLint rowBa0 = (rowB[j] >> 12) & 0xf;
- const GLint rowBa1 = (rowB[k] >> 12) & 0xf;
- const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
- const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
- const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
- const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2;
- dst[i] = (alpha << 12) | (blue << 8) | (green << 4) | red;
- }
- }
- else if (datatype == GL_UNSIGNED_SHORT_1_5_5_5_REV && comps == 4) {
- GLuint i, j, k;
- const GLushort *rowA = (const GLushort *) srcRowA;
- const GLushort *rowB = (const GLushort *) srcRowB;
- GLushort *dst = (GLushort *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0x1f;
- const GLint rowAr1 = rowA[k] & 0x1f;
- const GLint rowBr0 = rowB[j] & 0x1f;
- const GLint rowBr1 = rowB[k] & 0x1f;
- const GLint rowAg0 = (rowA[j] >> 5) & 0x1f;
- const GLint rowAg1 = (rowA[k] >> 5) & 0x1f;
- const GLint rowBg0 = (rowB[j] >> 5) & 0x1f;
- const GLint rowBg1 = (rowB[k] >> 5) & 0x1f;
- const GLint rowAb0 = (rowA[j] >> 10) & 0x1f;
- const GLint rowAb1 = (rowA[k] >> 10) & 0x1f;
- const GLint rowBb0 = (rowB[j] >> 10) & 0x1f;
- const GLint rowBb1 = (rowB[k] >> 10) & 0x1f;
- const GLint rowAa0 = (rowA[j] >> 15) & 0x1;
- const GLint rowAa1 = (rowA[k] >> 15) & 0x1;
- const GLint rowBa0 = (rowB[j] >> 15) & 0x1;
- const GLint rowBa1 = (rowB[k] >> 15) & 0x1;
- const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
- const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
- const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
- const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2;
- dst[i] = (alpha << 15) | (blue << 10) | (green << 5) | red;
- }
- }
- else if (datatype == GL_UNSIGNED_SHORT_5_5_5_1 && comps == 4) {
- GLuint i, j, k;
- const GLushort *rowA = (const GLushort *) srcRowA;
- const GLushort *rowB = (const GLushort *) srcRowB;
- GLushort *dst = (GLushort *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = (rowA[j] >> 11) & 0x1f;
- const GLint rowAr1 = (rowA[k] >> 11) & 0x1f;
- const GLint rowBr0 = (rowB[j] >> 11) & 0x1f;
- const GLint rowBr1 = (rowB[k] >> 11) & 0x1f;
- const GLint rowAg0 = (rowA[j] >> 6) & 0x1f;
- const GLint rowAg1 = (rowA[k] >> 6) & 0x1f;
- const GLint rowBg0 = (rowB[j] >> 6) & 0x1f;
- const GLint rowBg1 = (rowB[k] >> 6) & 0x1f;
- const GLint rowAb0 = (rowA[j] >> 1) & 0x1f;
- const GLint rowAb1 = (rowA[k] >> 1) & 0x1f;
- const GLint rowBb0 = (rowB[j] >> 1) & 0x1f;
- const GLint rowBb1 = (rowB[k] >> 1) & 0x1f;
- const GLint rowAa0 = (rowA[j] & 0x1);
- const GLint rowAa1 = (rowA[k] & 0x1);
- const GLint rowBa0 = (rowB[j] & 0x1);
- const GLint rowBa1 = (rowB[k] & 0x1);
- const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
- const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
- const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
- const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2;
- dst[i] = (red << 11) | (green << 6) | (blue << 1) | alpha;
- }
- }
-
- else if (datatype == GL_UNSIGNED_BYTE_3_3_2 && comps == 3) {
- GLuint i, j, k;
- const GLubyte *rowA = (const GLubyte *) srcRowA;
- const GLubyte *rowB = (const GLubyte *) srcRowB;
- GLubyte *dst = (GLubyte *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0x3;
- const GLint rowAr1 = rowA[k] & 0x3;
- const GLint rowBr0 = rowB[j] & 0x3;
- const GLint rowBr1 = rowB[k] & 0x3;
- const GLint rowAg0 = (rowA[j] >> 2) & 0x7;
- const GLint rowAg1 = (rowA[k] >> 2) & 0x7;
- const GLint rowBg0 = (rowB[j] >> 2) & 0x7;
- const GLint rowBg1 = (rowB[k] >> 2) & 0x7;
- const GLint rowAb0 = (rowA[j] >> 5) & 0x7;
- const GLint rowAb1 = (rowA[k] >> 5) & 0x7;
- const GLint rowBb0 = (rowB[j] >> 5) & 0x7;
- const GLint rowBb1 = (rowB[k] >> 5) & 0x7;
- const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
- const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
- const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
- dst[i] = (blue << 5) | (green << 2) | red;
- }
- }
-
- else if (datatype == MESA_UNSIGNED_BYTE_4_4 && comps == 2) {
- GLuint i, j, k;
- const GLubyte *rowA = (const GLubyte *) srcRowA;
- const GLubyte *rowB = (const GLubyte *) srcRowB;
- GLubyte *dst = (GLubyte *) dstRow;
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0xf;
- const GLint rowAr1 = rowA[k] & 0xf;
- const GLint rowBr0 = rowB[j] & 0xf;
- const GLint rowBr1 = rowB[k] & 0xf;
- const GLint rowAg0 = (rowA[j] >> 4) & 0xf;
- const GLint rowAg1 = (rowA[k] >> 4) & 0xf;
- const GLint rowBg0 = (rowB[j] >> 4) & 0xf;
- const GLint rowBg1 = (rowB[k] >> 4) & 0xf;
- const GLint r = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
- const GLint g = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
- dst[i] = (g << 4) | r;
- }
- }
-
- else {
- _mesa_problem(NULL, "bad format in do_row()");
- }
-}
-
-
-/**
- * Average together four rows of a source image to produce a single new
- * row in the dest image. It's legal for the two source rows to point
- * to the same data. The source width must be equal to either the
- * dest width or two times the dest width.
- *
- * \param datatype GL pixel type \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT,
- * \c GL_FLOAT, etc.
- * \param comps number of components per pixel (1..4)
- * \param srcWidth Width of a row in the source data
- * \param srcRowA Pointer to one of the rows of source data
- * \param srcRowB Pointer to one of the rows of source data
- * \param srcRowC Pointer to one of the rows of source data
- * \param srcRowD Pointer to one of the rows of source data
- * \param dstWidth Width of a row in the destination data
- * \param srcRowA Pointer to the row of destination data
- */
-static void
-do_row_3D(GLenum datatype, GLuint comps, GLint srcWidth,
- const GLvoid *srcRowA, const GLvoid *srcRowB,
- const GLvoid *srcRowC, const GLvoid *srcRowD,
- GLint dstWidth, GLvoid *dstRow)
-{
- const GLuint k0 = (srcWidth == dstWidth) ? 0 : 1;
- const GLuint colStride = (srcWidth == dstWidth) ? 1 : 2;
- GLuint i, j, k;
-
- ASSERT(comps >= 1);
- ASSERT(comps <= 4);
-
- if ((datatype == GL_UNSIGNED_BYTE) && (comps == 4)) {
- DECLARE_ROW_POINTERS(GLubyte, 4);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- FILTER_3D(1);
- FILTER_3D(2);
- FILTER_3D(3);
- }
- }
- else if ((datatype == GL_UNSIGNED_BYTE) && (comps == 3)) {
- DECLARE_ROW_POINTERS(GLubyte, 3);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- FILTER_3D(1);
- FILTER_3D(2);
- }
- }
- else if ((datatype == GL_UNSIGNED_BYTE) && (comps == 2)) {
- DECLARE_ROW_POINTERS(GLubyte, 2);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- FILTER_3D(1);
- }
- }
- else if ((datatype == GL_UNSIGNED_BYTE) && (comps == 1)) {
- DECLARE_ROW_POINTERS(GLubyte, 1);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- }
- }
- else if ((datatype == GL_BYTE) && (comps == 4)) {
- DECLARE_ROW_POINTERS(GLbyte, 4);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D_SIGNED(0);
- FILTER_3D_SIGNED(1);
- FILTER_3D_SIGNED(2);
- FILTER_3D_SIGNED(3);
- }
- }
- else if ((datatype == GL_BYTE) && (comps == 3)) {
- DECLARE_ROW_POINTERS(GLbyte, 3);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D_SIGNED(0);
- FILTER_3D_SIGNED(1);
- FILTER_3D_SIGNED(2);
- }
- }
- else if ((datatype == GL_BYTE) && (comps == 2)) {
- DECLARE_ROW_POINTERS(GLbyte, 2);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D_SIGNED(0);
- FILTER_3D_SIGNED(1);
- }
- }
- else if ((datatype == GL_BYTE) && (comps == 1)) {
- DECLARE_ROW_POINTERS(GLbyte, 1);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D_SIGNED(0);
- }
- }
- else if ((datatype == GL_UNSIGNED_SHORT) && (comps == 4)) {
- DECLARE_ROW_POINTERS(GLushort, 4);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- FILTER_3D(1);
- FILTER_3D(2);
- FILTER_3D(3);
- }
- }
- else if ((datatype == GL_UNSIGNED_SHORT) && (comps == 3)) {
- DECLARE_ROW_POINTERS(GLushort, 3);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- FILTER_3D(1);
- FILTER_3D(2);
- }
- }
- else if ((datatype == GL_UNSIGNED_SHORT) && (comps == 2)) {
- DECLARE_ROW_POINTERS(GLushort, 2);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- FILTER_3D(1);
- }
- }
- else if ((datatype == GL_UNSIGNED_SHORT) && (comps == 1)) {
- DECLARE_ROW_POINTERS(GLushort, 1);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- }
- }
- else if ((datatype == GL_SHORT) && (comps == 4)) {
- DECLARE_ROW_POINTERS(GLshort, 4);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- FILTER_3D(1);
- FILTER_3D(2);
- FILTER_3D(3);
- }
- }
- else if ((datatype == GL_SHORT) && (comps == 3)) {
- DECLARE_ROW_POINTERS(GLshort, 3);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- FILTER_3D(1);
- FILTER_3D(2);
- }
- }
- else if ((datatype == GL_SHORT) && (comps == 2)) {
- DECLARE_ROW_POINTERS(GLshort, 2);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- FILTER_3D(1);
- }
- }
- else if ((datatype == GL_SHORT) && (comps == 1)) {
- DECLARE_ROW_POINTERS(GLshort, 1);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_3D(0);
- }
- }
- else if ((datatype == GL_FLOAT) && (comps == 4)) {
- DECLARE_ROW_POINTERS(GLfloat, 4);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_F_3D(0);
- FILTER_F_3D(1);
- FILTER_F_3D(2);
- FILTER_F_3D(3);
- }
- }
- else if ((datatype == GL_FLOAT) && (comps == 3)) {
- DECLARE_ROW_POINTERS(GLfloat, 3);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_F_3D(0);
- FILTER_F_3D(1);
- FILTER_F_3D(2);
- }
- }
- else if ((datatype == GL_FLOAT) && (comps == 2)) {
- DECLARE_ROW_POINTERS(GLfloat, 2);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_F_3D(0);
- FILTER_F_3D(1);
- }
- }
- else if ((datatype == GL_FLOAT) && (comps == 1)) {
- DECLARE_ROW_POINTERS(GLfloat, 1);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_F_3D(0);
- }
- }
- else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 4)) {
- DECLARE_ROW_POINTERS(GLhalfARB, 4);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_HF_3D(0);
- FILTER_HF_3D(1);
- FILTER_HF_3D(2);
- FILTER_HF_3D(3);
- }
- }
- else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 3)) {
- DECLARE_ROW_POINTERS(GLhalfARB, 4);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_HF_3D(0);
- FILTER_HF_3D(1);
- FILTER_HF_3D(2);
- }
- }
- else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 2)) {
- DECLARE_ROW_POINTERS(GLhalfARB, 4);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_HF_3D(0);
- FILTER_HF_3D(1);
- }
- }
- else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 1)) {
- DECLARE_ROW_POINTERS(GLhalfARB, 4);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- FILTER_HF_3D(0);
- }
- }
- else if ((datatype == GL_UNSIGNED_INT) && (comps == 1)) {
- const GLuint *rowA = (const GLuint *) srcRowA;
- const GLuint *rowB = (const GLuint *) srcRowB;
- const GLuint *rowC = (const GLuint *) srcRowC;
- const GLuint *rowD = (const GLuint *) srcRowD;
- GLfloat *dst = (GLfloat *) dstRow;
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const uint64_t tmp = (((uint64_t) rowA[j] + (uint64_t) rowA[k])
- + ((uint64_t) rowB[j] + (uint64_t) rowB[k])
- + ((uint64_t) rowC[j] + (uint64_t) rowC[k])
- + ((uint64_t) rowD[j] + (uint64_t) rowD[k]));
- dst[i] = (GLfloat)((double) tmp * 0.125);
- }
- }
- else if ((datatype == GL_UNSIGNED_SHORT_5_6_5) && (comps == 3)) {
- DECLARE_ROW_POINTERS0(GLushort);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0x1f;
- const GLint rowAr1 = rowA[k] & 0x1f;
- const GLint rowBr0 = rowB[j] & 0x1f;
- const GLint rowBr1 = rowB[k] & 0x1f;
- const GLint rowCr0 = rowC[j] & 0x1f;
- const GLint rowCr1 = rowC[k] & 0x1f;
- const GLint rowDr0 = rowD[j] & 0x1f;
- const GLint rowDr1 = rowD[k] & 0x1f;
- const GLint rowAg0 = (rowA[j] >> 5) & 0x3f;
- const GLint rowAg1 = (rowA[k] >> 5) & 0x3f;
- const GLint rowBg0 = (rowB[j] >> 5) & 0x3f;
- const GLint rowBg1 = (rowB[k] >> 5) & 0x3f;
- const GLint rowCg0 = (rowC[j] >> 5) & 0x3f;
- const GLint rowCg1 = (rowC[k] >> 5) & 0x3f;
- const GLint rowDg0 = (rowD[j] >> 5) & 0x3f;
- const GLint rowDg1 = (rowD[k] >> 5) & 0x3f;
- const GLint rowAb0 = (rowA[j] >> 11) & 0x1f;
- const GLint rowAb1 = (rowA[k] >> 11) & 0x1f;
- const GLint rowBb0 = (rowB[j] >> 11) & 0x1f;
- const GLint rowBb1 = (rowB[k] >> 11) & 0x1f;
- const GLint rowCb0 = (rowC[j] >> 11) & 0x1f;
- const GLint rowCb1 = (rowC[k] >> 11) & 0x1f;
- const GLint rowDb0 = (rowD[j] >> 11) & 0x1f;
- const GLint rowDb1 = (rowD[k] >> 11) & 0x1f;
- const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
- rowCr0, rowCr1, rowDr0, rowDr1);
- const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
- rowCg0, rowCg1, rowDg0, rowDg1);
- const GLint b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1,
- rowCb0, rowCb1, rowDb0, rowDb1);
- dst[i] = (b << 11) | (g << 5) | r;
- }
- }
- else if ((datatype == GL_UNSIGNED_SHORT_4_4_4_4) && (comps == 4)) {
- DECLARE_ROW_POINTERS0(GLushort);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0xf;
- const GLint rowAr1 = rowA[k] & 0xf;
- const GLint rowBr0 = rowB[j] & 0xf;
- const GLint rowBr1 = rowB[k] & 0xf;
- const GLint rowCr0 = rowC[j] & 0xf;
- const GLint rowCr1 = rowC[k] & 0xf;
- const GLint rowDr0 = rowD[j] & 0xf;
- const GLint rowDr1 = rowD[k] & 0xf;
- const GLint rowAg0 = (rowA[j] >> 4) & 0xf;
- const GLint rowAg1 = (rowA[k] >> 4) & 0xf;
- const GLint rowBg0 = (rowB[j] >> 4) & 0xf;
- const GLint rowBg1 = (rowB[k] >> 4) & 0xf;
- const GLint rowCg0 = (rowC[j] >> 4) & 0xf;
- const GLint rowCg1 = (rowC[k] >> 4) & 0xf;
- const GLint rowDg0 = (rowD[j] >> 4) & 0xf;
- const GLint rowDg1 = (rowD[k] >> 4) & 0xf;
- const GLint rowAb0 = (rowA[j] >> 8) & 0xf;
- const GLint rowAb1 = (rowA[k] >> 8) & 0xf;
- const GLint rowBb0 = (rowB[j] >> 8) & 0xf;
- const GLint rowBb1 = (rowB[k] >> 8) & 0xf;
- const GLint rowCb0 = (rowC[j] >> 8) & 0xf;
- const GLint rowCb1 = (rowC[k] >> 8) & 0xf;
- const GLint rowDb0 = (rowD[j] >> 8) & 0xf;
- const GLint rowDb1 = (rowD[k] >> 8) & 0xf;
- const GLint rowAa0 = (rowA[j] >> 12) & 0xf;
- const GLint rowAa1 = (rowA[k] >> 12) & 0xf;
- const GLint rowBa0 = (rowB[j] >> 12) & 0xf;
- const GLint rowBa1 = (rowB[k] >> 12) & 0xf;
- const GLint rowCa0 = (rowC[j] >> 12) & 0xf;
- const GLint rowCa1 = (rowC[k] >> 12) & 0xf;
- const GLint rowDa0 = (rowD[j] >> 12) & 0xf;
- const GLint rowDa1 = (rowD[k] >> 12) & 0xf;
- const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
- rowCr0, rowCr1, rowDr0, rowDr1);
- const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
- rowCg0, rowCg1, rowDg0, rowDg1);
- const GLint b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1,
- rowCb0, rowCb1, rowDb0, rowDb1);
- const GLint a = FILTER_SUM_3D(rowAa0, rowAa1, rowBa0, rowBa1,
- rowCa0, rowCa1, rowDa0, rowDa1);
-
- dst[i] = (a << 12) | (b << 8) | (g << 4) | r;
- }
- }
- else if ((datatype == GL_UNSIGNED_SHORT_1_5_5_5_REV) && (comps == 4)) {
- DECLARE_ROW_POINTERS0(GLushort);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0x1f;
- const GLint rowAr1 = rowA[k] & 0x1f;
- const GLint rowBr0 = rowB[j] & 0x1f;
- const GLint rowBr1 = rowB[k] & 0x1f;
- const GLint rowCr0 = rowC[j] & 0x1f;
- const GLint rowCr1 = rowC[k] & 0x1f;
- const GLint rowDr0 = rowD[j] & 0x1f;
- const GLint rowDr1 = rowD[k] & 0x1f;
- const GLint rowAg0 = (rowA[j] >> 5) & 0x1f;
- const GLint rowAg1 = (rowA[k] >> 5) & 0x1f;
- const GLint rowBg0 = (rowB[j] >> 5) & 0x1f;
- const GLint rowBg1 = (rowB[k] >> 5) & 0x1f;
- const GLint rowCg0 = (rowC[j] >> 5) & 0x1f;
- const GLint rowCg1 = (rowC[k] >> 5) & 0x1f;
- const GLint rowDg0 = (rowD[j] >> 5) & 0x1f;
- const GLint rowDg1 = (rowD[k] >> 5) & 0x1f;
- const GLint rowAb0 = (rowA[j] >> 10) & 0x1f;
- const GLint rowAb1 = (rowA[k] >> 10) & 0x1f;
- const GLint rowBb0 = (rowB[j] >> 10) & 0x1f;
- const GLint rowBb1 = (rowB[k] >> 10) & 0x1f;
- const GLint rowCb0 = (rowC[j] >> 10) & 0x1f;
- const GLint rowCb1 = (rowC[k] >> 10) & 0x1f;
- const GLint rowDb0 = (rowD[j] >> 10) & 0x1f;
- const GLint rowDb1 = (rowD[k] >> 10) & 0x1f;
- const GLint rowAa0 = (rowA[j] >> 15) & 0x1;
- const GLint rowAa1 = (rowA[k] >> 15) & 0x1;
- const GLint rowBa0 = (rowB[j] >> 15) & 0x1;
- const GLint rowBa1 = (rowB[k] >> 15) & 0x1;
- const GLint rowCa0 = (rowC[j] >> 15) & 0x1;
- const GLint rowCa1 = (rowC[k] >> 15) & 0x1;
- const GLint rowDa0 = (rowD[j] >> 15) & 0x1;
- const GLint rowDa1 = (rowD[k] >> 15) & 0x1;
- const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
- rowCr0, rowCr1, rowDr0, rowDr1);
- const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
- rowCg0, rowCg1, rowDg0, rowDg1);
- const GLint b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1,
- rowCb0, rowCb1, rowDb0, rowDb1);
- const GLint a = FILTER_SUM_3D(rowAa0, rowAa1, rowBa0, rowBa1,
- rowCa0, rowCa1, rowDa0, rowDa1);
-
- dst[i] = (a << 15) | (b << 10) | (g << 5) | r;
- }
- }
- else if ((datatype == GL_UNSIGNED_SHORT_5_5_5_1) && (comps == 4)) {
- DECLARE_ROW_POINTERS0(GLushort);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = (rowA[j] >> 11) & 0x1f;
- const GLint rowAr1 = (rowA[k] >> 11) & 0x1f;
- const GLint rowBr0 = (rowB[j] >> 11) & 0x1f;
- const GLint rowBr1 = (rowB[k] >> 11) & 0x1f;
- const GLint rowCr0 = (rowC[j] >> 11) & 0x1f;
- const GLint rowCr1 = (rowC[k] >> 11) & 0x1f;
- const GLint rowDr0 = (rowD[j] >> 11) & 0x1f;
- const GLint rowDr1 = (rowD[k] >> 11) & 0x1f;
- const GLint rowAg0 = (rowA[j] >> 6) & 0x1f;
- const GLint rowAg1 = (rowA[k] >> 6) & 0x1f;
- const GLint rowBg0 = (rowB[j] >> 6) & 0x1f;
- const GLint rowBg1 = (rowB[k] >> 6) & 0x1f;
- const GLint rowCg0 = (rowC[j] >> 6) & 0x1f;
- const GLint rowCg1 = (rowC[k] >> 6) & 0x1f;
- const GLint rowDg0 = (rowD[j] >> 6) & 0x1f;
- const GLint rowDg1 = (rowD[k] >> 6) & 0x1f;
- const GLint rowAb0 = (rowA[j] >> 1) & 0x1f;
- const GLint rowAb1 = (rowA[k] >> 1) & 0x1f;
- const GLint rowBb0 = (rowB[j] >> 1) & 0x1f;
- const GLint rowBb1 = (rowB[k] >> 1) & 0x1f;
- const GLint rowCb0 = (rowC[j] >> 1) & 0x1f;
- const GLint rowCb1 = (rowC[k] >> 1) & 0x1f;
- const GLint rowDb0 = (rowD[j] >> 1) & 0x1f;
- const GLint rowDb1 = (rowD[k] >> 1) & 0x1f;
- const GLint rowAa0 = (rowA[j] & 0x1);
- const GLint rowAa1 = (rowA[k] & 0x1);
- const GLint rowBa0 = (rowB[j] & 0x1);
- const GLint rowBa1 = (rowB[k] & 0x1);
- const GLint rowCa0 = (rowC[j] & 0x1);
- const GLint rowCa1 = (rowC[k] & 0x1);
- const GLint rowDa0 = (rowD[j] & 0x1);
- const GLint rowDa1 = (rowD[k] & 0x1);
- const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
- rowCr0, rowCr1, rowDr0, rowDr1);
- const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
- rowCg0, rowCg1, rowDg0, rowDg1);
- const GLint b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1,
- rowCb0, rowCb1, rowDb0, rowDb1);
- const GLint a = FILTER_SUM_3D(rowAa0, rowAa1, rowBa0, rowBa1,
- rowCa0, rowCa1, rowDa0, rowDa1);
-
- dst[i] = (r << 11) | (g << 6) | (b << 1) | a;
- }
- }
- else if ((datatype == GL_UNSIGNED_BYTE_3_3_2) && (comps == 3)) {
- DECLARE_ROW_POINTERS0(GLubyte);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0x3;
- const GLint rowAr1 = rowA[k] & 0x3;
- const GLint rowBr0 = rowB[j] & 0x3;
- const GLint rowBr1 = rowB[k] & 0x3;
- const GLint rowCr0 = rowC[j] & 0x3;
- const GLint rowCr1 = rowC[k] & 0x3;
- const GLint rowDr0 = rowD[j] & 0x3;
- const GLint rowDr1 = rowD[k] & 0x3;
- const GLint rowAg0 = (rowA[j] >> 2) & 0x7;
- const GLint rowAg1 = (rowA[k] >> 2) & 0x7;
- const GLint rowBg0 = (rowB[j] >> 2) & 0x7;
- const GLint rowBg1 = (rowB[k] >> 2) & 0x7;
- const GLint rowCg0 = (rowC[j] >> 2) & 0x7;
- const GLint rowCg1 = (rowC[k] >> 2) & 0x7;
- const GLint rowDg0 = (rowD[j] >> 2) & 0x7;
- const GLint rowDg1 = (rowD[k] >> 2) & 0x7;
- const GLint rowAb0 = (rowA[j] >> 5) & 0x7;
- const GLint rowAb1 = (rowA[k] >> 5) & 0x7;
- const GLint rowBb0 = (rowB[j] >> 5) & 0x7;
- const GLint rowBb1 = (rowB[k] >> 5) & 0x7;
- const GLint rowCb0 = (rowC[j] >> 5) & 0x7;
- const GLint rowCb1 = (rowC[k] >> 5) & 0x7;
- const GLint rowDb0 = (rowD[j] >> 5) & 0x7;
- const GLint rowDb1 = (rowD[k] >> 5) & 0x7;
- const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
- rowCr0, rowCr1, rowDr0, rowDr1);
- const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
- rowCg0, rowCg1, rowDg0, rowDg1);
- const GLint b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1,
- rowCb0, rowCb1, rowDb0, rowDb1);
- dst[i] = (b << 5) | (g << 2) | r;
- }
- }
- else if (datatype == MESA_UNSIGNED_BYTE_4_4 && comps == 2) {
- DECLARE_ROW_POINTERS0(GLubyte);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0xf;
- const GLint rowAr1 = rowA[k] & 0xf;
- const GLint rowBr0 = rowB[j] & 0xf;
- const GLint rowBr1 = rowB[k] & 0xf;
- const GLint rowCr0 = rowC[j] & 0xf;
- const GLint rowCr1 = rowC[k] & 0xf;
- const GLint rowDr0 = rowD[j] & 0xf;
- const GLint rowDr1 = rowD[k] & 0xf;
- const GLint rowAg0 = (rowA[j] >> 4) & 0xf;
- const GLint rowAg1 = (rowA[k] >> 4) & 0xf;
- const GLint rowBg0 = (rowB[j] >> 4) & 0xf;
- const GLint rowBg1 = (rowB[k] >> 4) & 0xf;
- const GLint rowCg0 = (rowC[j] >> 4) & 0xf;
- const GLint rowCg1 = (rowC[k] >> 4) & 0xf;
- const GLint rowDg0 = (rowD[j] >> 4) & 0xf;
- const GLint rowDg1 = (rowD[k] >> 4) & 0xf;
- const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
- rowCr0, rowCr1, rowDr0, rowDr1);
- const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
- rowCg0, rowCg1, rowDg0, rowDg1);
- dst[i] = (g << 4) | r;
- }
- }
- else {
- _mesa_problem(NULL, "bad format in do_row()");
- }
-}
-
-
-/*
- * These functions generate a 1/2-size mipmap image from a source image.
- * Texture borders are handled by copying or averaging the source image's
- * border texels, depending on the scale-down factor.
- */
-
-static void
-make_1d_mipmap(GLenum datatype, GLuint comps, GLint border,
- GLint srcWidth, const GLubyte *srcPtr,
- GLint dstWidth, GLubyte *dstPtr)
-{
- const GLint bpt = bytes_per_pixel(datatype, comps);
- const GLubyte *src;
- GLubyte *dst;
-
- /* skip the border pixel, if any */
- src = srcPtr + border * bpt;
- dst = dstPtr + border * bpt;
-
- /* we just duplicate the input row, kind of hack, saves code */
- do_row(datatype, comps, srcWidth - 2 * border, src, src,
- dstWidth - 2 * border, dst);
-
- if (border) {
- /* copy left-most pixel from source */
- assert(dstPtr);
- assert(srcPtr);
- memcpy(dstPtr, srcPtr, bpt);
- /* copy right-most pixel from source */
- memcpy(dstPtr + (dstWidth - 1) * bpt,
- srcPtr + (srcWidth - 1) * bpt,
- bpt);
- }
-}
-
-
-static void
-make_2d_mipmap(GLenum datatype, GLuint comps, GLint border,
- GLint srcWidth, GLint srcHeight,
- const GLubyte *srcPtr, GLint srcRowStride,
- GLint dstWidth, GLint dstHeight,
- GLubyte *dstPtr, GLint dstRowStride)
-{
- const GLint bpt = bytes_per_pixel(datatype, comps);
- const GLint srcWidthNB = srcWidth - 2 * border; /* sizes w/out border */
- const GLint dstWidthNB = dstWidth - 2 * border;
- const GLint dstHeightNB = dstHeight - 2 * border;
- const GLint srcRowBytes = bpt * srcRowStride;
- const GLint dstRowBytes = bpt * dstRowStride;
- const GLubyte *srcA, *srcB;
- GLubyte *dst;
- GLint row, srcRowStep;
-
- /* Compute src and dst pointers, skipping any border */
- srcA = srcPtr + border * ((srcWidth + 1) * bpt);
- if (srcHeight > 1 && srcHeight > dstHeight) {
- /* sample from two source rows */
- srcB = srcA + srcRowBytes;
- srcRowStep = 2;
- }
- else {
- /* sample from one source row */
- srcB = srcA;
- srcRowStep = 1;
- }
-
- dst = dstPtr + border * ((dstWidth + 1) * bpt);
-
- for (row = 0; row < dstHeightNB; row++) {
- do_row(datatype, comps, srcWidthNB, srcA, srcB,
- dstWidthNB, dst);
- srcA += srcRowStep * srcRowBytes;
- srcB += srcRowStep * srcRowBytes;
- dst += dstRowBytes;
- }
-
- /* This is ugly but probably won't be used much */
- if (border > 0) {
- /* fill in dest border */
- /* lower-left border pixel */
- assert(dstPtr);
- assert(srcPtr);
- memcpy(dstPtr, srcPtr, bpt);
- /* lower-right border pixel */
- memcpy(dstPtr + (dstWidth - 1) * bpt,
- srcPtr + (srcWidth - 1) * bpt, bpt);
- /* upper-left border pixel */
- memcpy(dstPtr + dstWidth * (dstHeight - 1) * bpt,
- srcPtr + srcWidth * (srcHeight - 1) * bpt, bpt);
- /* upper-right border pixel */
- memcpy(dstPtr + (dstWidth * dstHeight - 1) * bpt,
- srcPtr + (srcWidth * srcHeight - 1) * bpt, bpt);
- /* lower border */
- do_row(datatype, comps, srcWidthNB,
- srcPtr + bpt,
- srcPtr + bpt,
- dstWidthNB, dstPtr + bpt);
- /* upper border */
- do_row(datatype, comps, srcWidthNB,
- srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt,
- srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt,
- dstWidthNB,
- dstPtr + (dstWidth * (dstHeight - 1) + 1) * bpt);
- /* left and right borders */
- if (srcHeight == dstHeight) {
- /* copy border pixel from src to dst */
- for (row = 1; row < srcHeight; row++) {
- memcpy(dstPtr + dstWidth * row * bpt,
- srcPtr + srcWidth * row * bpt, bpt);
- memcpy(dstPtr + (dstWidth * row + dstWidth - 1) * bpt,
- srcPtr + (srcWidth * row + srcWidth - 1) * bpt, bpt);
- }
- }
- else {
- /* average two src pixels each dest pixel */
- for (row = 0; row < dstHeightNB; row += 2) {
- do_row(datatype, comps, 1,
- srcPtr + (srcWidth * (row * 2 + 1)) * bpt,
- srcPtr + (srcWidth * (row * 2 + 2)) * bpt,
- 1, dstPtr + (dstWidth * row + 1) * bpt);
- do_row(datatype, comps, 1,
- srcPtr + (srcWidth * (row * 2 + 1) + srcWidth - 1) * bpt,
- srcPtr + (srcWidth * (row * 2 + 2) + srcWidth - 1) * bpt,
- 1, dstPtr + (dstWidth * row + 1 + dstWidth - 1) * bpt);
- }
- }
- }
-}
-
-
-static void
-make_3d_mipmap(GLenum datatype, GLuint comps, GLint border,
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- const GLubyte *srcPtr, GLint srcRowStride,
- GLint dstWidth, GLint dstHeight, GLint dstDepth,
- GLubyte *dstPtr, GLint dstRowStride)
-{
- const GLint bpt = bytes_per_pixel(datatype, comps);
- const GLint srcWidthNB = srcWidth - 2 * border; /* sizes w/out border */
- const GLint srcDepthNB = srcDepth - 2 * border;
- const GLint dstWidthNB = dstWidth - 2 * border;
- const GLint dstHeightNB = dstHeight - 2 * border;
- const GLint dstDepthNB = dstDepth - 2 * border;
- GLint img, row;
- GLint bytesPerSrcImage, bytesPerDstImage;
- GLint bytesPerSrcRow, bytesPerDstRow;
- GLint srcImageOffset, srcRowOffset;
-
- (void) srcDepthNB; /* silence warnings */
-
-
- bytesPerSrcImage = srcWidth * srcHeight * bpt;
- bytesPerDstImage = dstWidth * dstHeight * bpt;
-
- bytesPerSrcRow = srcWidth * bpt;
- bytesPerDstRow = dstWidth * bpt;
-
- /* Offset between adjacent src images to be averaged together */
- srcImageOffset = (srcDepth == dstDepth) ? 0 : bytesPerSrcImage;
-
- /* Offset between adjacent src rows to be averaged together */
- srcRowOffset = (srcHeight == dstHeight) ? 0 : srcWidth * bpt;
-
- /*
- * Need to average together up to 8 src pixels for each dest pixel.
- * Break that down into 3 operations:
- * 1. take two rows from source image and average them together.
- * 2. take two rows from next source image and average them together.
- * 3. take the two averaged rows and average them for the final dst row.
- */
-
- /*
- printf("mip3d %d x %d x %d -> %d x %d x %d\n",
- srcWidth, srcHeight, srcDepth, dstWidth, dstHeight, dstDepth);
- */
-
- for (img = 0; img < dstDepthNB; img++) {
- /* first source image pointer, skipping border */
- const GLubyte *imgSrcA = srcPtr
- + (bytesPerSrcImage + bytesPerSrcRow + border) * bpt * border
- + img * (bytesPerSrcImage + srcImageOffset);
- /* second source image pointer, skipping border */
- const GLubyte *imgSrcB = imgSrcA + srcImageOffset;
- /* address of the dest image, skipping border */
- GLubyte *imgDst = dstPtr
- + (bytesPerDstImage + bytesPerDstRow + border) * bpt * border
- + img * bytesPerDstImage;
-
- /* setup the four source row pointers and the dest row pointer */
- const GLubyte *srcImgARowA = imgSrcA;
- const GLubyte *srcImgARowB = imgSrcA + srcRowOffset;
- const GLubyte *srcImgBRowA = imgSrcB;
- const GLubyte *srcImgBRowB = imgSrcB + srcRowOffset;
- GLubyte *dstImgRow = imgDst;
-
- for (row = 0; row < dstHeightNB; row++) {
- do_row_3D(datatype, comps, srcWidthNB,
- srcImgARowA, srcImgARowB,
- srcImgBRowA, srcImgBRowB,
- dstWidthNB, dstImgRow);
-
- /* advance to next rows */
- srcImgARowA += bytesPerSrcRow + srcRowOffset;
- srcImgARowB += bytesPerSrcRow + srcRowOffset;
- srcImgBRowA += bytesPerSrcRow + srcRowOffset;
- srcImgBRowB += bytesPerSrcRow + srcRowOffset;
- dstImgRow += bytesPerDstRow;
- }
- }
-
-
- /* Luckily we can leverage the make_2d_mipmap() function here! */
- if (border > 0) {
- /* do front border image */
- make_2d_mipmap(datatype, comps, 1, srcWidth, srcHeight, srcPtr, srcRowStride,
- dstWidth, dstHeight, dstPtr, dstRowStride);
- /* do back border image */
- make_2d_mipmap(datatype, comps, 1, srcWidth, srcHeight,
- srcPtr + bytesPerSrcImage * (srcDepth - 1), srcRowStride,
- dstWidth, dstHeight,
- dstPtr + bytesPerDstImage * (dstDepth - 1), dstRowStride);
- /* do four remaining border edges that span the image slices */
- if (srcDepth == dstDepth) {
- /* just copy border pixels from src to dst */
- for (img = 0; img < dstDepthNB; img++) {
- const GLubyte *src;
- GLubyte *dst;
-
- /* do border along [img][row=0][col=0] */
- src = srcPtr + (img + 1) * bytesPerSrcImage;
- dst = dstPtr + (img + 1) * bytesPerDstImage;
- memcpy(dst, src, bpt);
-
- /* do border along [img][row=dstHeight-1][col=0] */
- src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
- + (srcHeight - 1) * bytesPerSrcRow;
- dst = dstPtr + (img + 1) * bytesPerDstImage
- + (dstHeight - 1) * bytesPerDstRow;
- memcpy(dst, src, bpt);
-
- /* do border along [img][row=0][col=dstWidth-1] */
- src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
- + (srcWidth - 1) * bpt;
- dst = dstPtr + (img + 1) * bytesPerDstImage
- + (dstWidth - 1) * bpt;
- memcpy(dst, src, bpt);
-
- /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
- src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
- + (bytesPerSrcImage - bpt);
- dst = dstPtr + (img + 1) * bytesPerDstImage
- + (bytesPerDstImage - bpt);
- memcpy(dst, src, bpt);
- }
- }
- else {
- /* average border pixels from adjacent src image pairs */
- ASSERT(srcDepthNB == 2 * dstDepthNB);
- for (img = 0; img < dstDepthNB; img++) {
- const GLubyte *src;
- GLubyte *dst;
-
- /* do border along [img][row=0][col=0] */
- src = srcPtr + (img * 2 + 1) * bytesPerSrcImage;
- dst = dstPtr + (img + 1) * bytesPerDstImage;
- do_row(datatype, comps, 1, src, src + srcImageOffset, 1, dst);
-
- /* do border along [img][row=dstHeight-1][col=0] */
- src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
- + (srcHeight - 1) * bytesPerSrcRow;
- dst = dstPtr + (img + 1) * bytesPerDstImage
- + (dstHeight - 1) * bytesPerDstRow;
- do_row(datatype, comps, 1, src, src + srcImageOffset, 1, dst);
-
- /* do border along [img][row=0][col=dstWidth-1] */
- src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
- + (srcWidth - 1) * bpt;
- dst = dstPtr + (img + 1) * bytesPerDstImage
- + (dstWidth - 1) * bpt;
- do_row(datatype, comps, 1, src, src + srcImageOffset, 1, dst);
-
- /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
- src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
- + (bytesPerSrcImage - bpt);
- dst = dstPtr + (img + 1) * bytesPerDstImage
- + (bytesPerDstImage - bpt);
- do_row(datatype, comps, 1, src, src + srcImageOffset, 1, dst);
- }
- }
- }
-}
-
-
-static void
-make_1d_stack_mipmap(GLenum datatype, GLuint comps, GLint border,
- GLint srcWidth, const GLubyte *srcPtr, GLuint srcRowStride,
- GLint dstWidth, GLint dstHeight,
- GLubyte *dstPtr, GLuint dstRowStride )
-{
- const GLint bpt = bytes_per_pixel(datatype, comps);
- const GLint srcWidthNB = srcWidth - 2 * border; /* sizes w/out border */
- const GLint dstWidthNB = dstWidth - 2 * border;
- const GLint dstHeightNB = dstHeight - 2 * border;
- const GLint srcRowBytes = bpt * srcRowStride;
- const GLint dstRowBytes = bpt * dstRowStride;
- const GLubyte *src;
- GLubyte *dst;
- GLint row;
-
- /* Compute src and dst pointers, skipping any border */
- src = srcPtr + border * ((srcWidth + 1) * bpt);
- dst = dstPtr + border * ((dstWidth + 1) * bpt);
-
- for (row = 0; row < dstHeightNB; row++) {
- do_row(datatype, comps, srcWidthNB, src, src,
- dstWidthNB, dst);
- src += srcRowBytes;
- dst += dstRowBytes;
- }
-
- if (border) {
- /* copy left-most pixel from source */
- assert(dstPtr);
- assert(srcPtr);
- memcpy(dstPtr, srcPtr, bpt);
- /* copy right-most pixel from source */
- memcpy(dstPtr + (dstWidth - 1) * bpt,
- srcPtr + (srcWidth - 1) * bpt,
- bpt);
- }
-}
-
-
-/**
- * \bug
- * There is quite a bit of refactoring that could be done with this function
- * and \c make_2d_mipmap.
- */
-static void
-make_2d_stack_mipmap(GLenum datatype, GLuint comps, GLint border,
- GLint srcWidth, GLint srcHeight,
- const GLubyte *srcPtr, GLint srcRowStride,
- GLint dstWidth, GLint dstHeight, GLint dstDepth,
- GLubyte *dstPtr, GLint dstRowStride)
-{
- const GLint bpt = bytes_per_pixel(datatype, comps);
- const GLint srcWidthNB = srcWidth - 2 * border; /* sizes w/out border */
- const GLint dstWidthNB = dstWidth - 2 * border;
- const GLint dstHeightNB = dstHeight - 2 * border;
- const GLint dstDepthNB = dstDepth - 2 * border;
- const GLint srcRowBytes = bpt * srcRowStride;
- const GLint dstRowBytes = bpt * dstRowStride;
- const GLubyte *srcA, *srcB;
- GLubyte *dst;
- GLint layer;
- GLint row;
-
- /* Compute src and dst pointers, skipping any border */
- srcA = srcPtr + border * ((srcWidth + 1) * bpt);
- if (srcHeight > 1)
- srcB = srcA + srcRowBytes;
- else
- srcB = srcA;
- dst = dstPtr + border * ((dstWidth + 1) * bpt);
-
- for (layer = 0; layer < dstDepthNB; layer++) {
- for (row = 0; row < dstHeightNB; row++) {
- do_row(datatype, comps, srcWidthNB, srcA, srcB,
- dstWidthNB, dst);
- srcA += 2 * srcRowBytes;
- srcB += 2 * srcRowBytes;
- dst += dstRowBytes;
- }
-
- /* This is ugly but probably won't be used much */
- if (border > 0) {
- /* fill in dest border */
- /* lower-left border pixel */
- assert(dstPtr);
- assert(srcPtr);
- memcpy(dstPtr, srcPtr, bpt);
- /* lower-right border pixel */
- memcpy(dstPtr + (dstWidth - 1) * bpt,
- srcPtr + (srcWidth - 1) * bpt, bpt);
- /* upper-left border pixel */
- memcpy(dstPtr + dstWidth * (dstHeight - 1) * bpt,
- srcPtr + srcWidth * (srcHeight - 1) * bpt, bpt);
- /* upper-right border pixel */
- memcpy(dstPtr + (dstWidth * dstHeight - 1) * bpt,
- srcPtr + (srcWidth * srcHeight - 1) * bpt, bpt);
- /* lower border */
- do_row(datatype, comps, srcWidthNB,
- srcPtr + bpt,
- srcPtr + bpt,
- dstWidthNB, dstPtr + bpt);
- /* upper border */
- do_row(datatype, comps, srcWidthNB,
- srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt,
- srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt,
- dstWidthNB,
- dstPtr + (dstWidth * (dstHeight - 1) + 1) * bpt);
- /* left and right borders */
- if (srcHeight == dstHeight) {
- /* copy border pixel from src to dst */
- for (row = 1; row < srcHeight; row++) {
- memcpy(dstPtr + dstWidth * row * bpt,
- srcPtr + srcWidth * row * bpt, bpt);
- memcpy(dstPtr + (dstWidth * row + dstWidth - 1) * bpt,
- srcPtr + (srcWidth * row + srcWidth - 1) * bpt, bpt);
- }
- }
- else {
- /* average two src pixels each dest pixel */
- for (row = 0; row < dstHeightNB; row += 2) {
- do_row(datatype, comps, 1,
- srcPtr + (srcWidth * (row * 2 + 1)) * bpt,
- srcPtr + (srcWidth * (row * 2 + 2)) * bpt,
- 1, dstPtr + (dstWidth * row + 1) * bpt);
- do_row(datatype, comps, 1,
- srcPtr + (srcWidth * (row * 2 + 1) + srcWidth - 1) * bpt,
- srcPtr + (srcWidth * (row * 2 + 2) + srcWidth - 1) * bpt,
- 1, dstPtr + (dstWidth * row + 1 + dstWidth - 1) * bpt);
- }
- }
- }
- }
-}
-
-
-/**
- * Down-sample a texture image to produce the next lower mipmap level.
- * \param comps components per texel (1, 2, 3 or 4)
- * \param srcRowStride stride between source rows, in texels
- * \param dstRowStride stride between destination rows, in texels
- */
-void
-_mesa_generate_mipmap_level(GLenum target,
- GLenum datatype, GLuint comps,
- GLint border,
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- const GLubyte *srcData,
- GLint srcRowStride,
- GLint dstWidth, GLint dstHeight, GLint dstDepth,
- GLubyte *dstData,
- GLint dstRowStride)
-{
- /*
- * We use simple 2x2 averaging to compute the next mipmap level.
- */
- switch (target) {
- case GL_TEXTURE_1D:
- make_1d_mipmap(datatype, comps, border,
- srcWidth, srcData,
- dstWidth, dstData);
- break;
- case GL_TEXTURE_2D:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
- make_2d_mipmap(datatype, comps, border,
- srcWidth, srcHeight, srcData, srcRowStride,
- dstWidth, dstHeight, dstData, dstRowStride);
- break;
- case GL_TEXTURE_3D:
- make_3d_mipmap(datatype, comps, border,
- srcWidth, srcHeight, srcDepth,
- srcData, srcRowStride,
- dstWidth, dstHeight, dstDepth,
- dstData, dstRowStride);
- break;
- case GL_TEXTURE_1D_ARRAY_EXT:
- make_1d_stack_mipmap(datatype, comps, border,
- srcWidth, srcData, srcRowStride,
- dstWidth, dstHeight,
- dstData, dstRowStride);
- break;
- case GL_TEXTURE_2D_ARRAY_EXT:
- make_2d_stack_mipmap(datatype, comps, border,
- srcWidth, srcHeight,
- srcData, srcRowStride,
- dstWidth, dstHeight,
- dstDepth, dstData, dstRowStride);
- break;
- case GL_TEXTURE_RECTANGLE_NV:
- /* no mipmaps, do nothing */
- break;
- default:
- _mesa_problem(NULL, "bad dimensions in _mesa_generate_mipmaps");
- return;
- }
-}
-
-
-/**
- * compute next (level+1) image size
- * \return GL_FALSE if no smaller size can be generated (eg. src is 1x1x1 size)
- */
-static GLboolean
-next_mipmap_level_size(GLenum target, GLint border,
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- GLint *dstWidth, GLint *dstHeight, GLint *dstDepth)
-{
- if (srcWidth - 2 * border > 1) {
- *dstWidth = (srcWidth - 2 * border) / 2 + 2 * border;
- }
- else {
- *dstWidth = srcWidth; /* can't go smaller */
- }
-
- if ((srcHeight - 2 * border > 1) &&
- (target != GL_TEXTURE_1D_ARRAY_EXT)) {
- *dstHeight = (srcHeight - 2 * border) / 2 + 2 * border;
- }
- else {
- *dstHeight = srcHeight; /* can't go smaller */
- }
-
- if ((srcDepth - 2 * border > 1) &&
- (target != GL_TEXTURE_2D_ARRAY_EXT)) {
- *dstDepth = (srcDepth - 2 * border) / 2 + 2 * border;
- }
- else {
- *dstDepth = srcDepth; /* can't go smaller */
- }
-
- if (*dstWidth == srcWidth &&
- *dstHeight == srcHeight &&
- *dstDepth == srcDepth) {
- return GL_FALSE;
- }
- else {
- return GL_TRUE;
- }
-}
-
-
-
-
-/**
- * Automatic mipmap generation.
- * This is the fallback/default function for ctx->Driver.GenerateMipmap().
- * Generate a complete set of mipmaps from texObj's BaseLevel image.
- * Stop at texObj's MaxLevel or when we get to the 1x1 texture.
- * For cube maps, target will be one of
- * GL_TEXTURE_CUBE_MAP_POSITIVE/NEGATIVE_X/Y/Z; never GL_TEXTURE_CUBE_MAP.
- */
-void
-_mesa_generate_mipmap(struct gl_context *ctx, GLenum target,
- struct gl_texture_object *texObj)
-{
- const struct gl_texture_image *srcImage;
- gl_format convertFormat;
- const GLubyte *srcData = NULL;
- GLubyte *dstData = NULL;
- GLint level, maxLevels;
- GLenum datatype;
- GLuint comps;
-
- ASSERT(texObj);
- srcImage = _mesa_select_tex_image(ctx, texObj, target, texObj->BaseLevel);
- ASSERT(srcImage);
-
- maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
- ASSERT(maxLevels > 0); /* bad target */
-
- /* Find convertFormat - the format that do_row() will process */
-
- if (_mesa_is_format_compressed(srcImage->TexFormat)) {
- /* setup for compressed textures - need to allocate temporary
- * image buffers to hold uncompressed images.
- */
- GLuint row;
- GLint components, size;
- GLchan *dst;
-
- assert(texObj->Target == GL_TEXTURE_2D ||
- texObj->Target == GL_TEXTURE_CUBE_MAP_ARB);
-
- if (srcImage->_BaseFormat == GL_RGB) {
- convertFormat = MESA_FORMAT_RGB888;
- components = 3;
- } else if (srcImage->_BaseFormat == GL_RED) {
- convertFormat = MESA_FORMAT_R8;
- components = 1;
- } else if (srcImage->_BaseFormat == GL_RG) {
- convertFormat = MESA_FORMAT_RG88;
- components = 2;
- } else if (srcImage->_BaseFormat == GL_RGBA) {
- convertFormat = MESA_FORMAT_RGBA8888;
- components = 4;
- }
- else {
- _mesa_problem(ctx, "bad srcImage->_BaseFormat in _mesa_generate_mipmaps");
- return;
- }
-
- /* allocate storage for uncompressed GL_RGB or GL_RGBA images */
- size = _mesa_bytes_per_pixel(srcImage->_BaseFormat, CHAN_TYPE)
- * srcImage->Width * srcImage->Height * srcImage->Depth + 20;
- /* 20 extra bytes, just be safe when calling last FetchTexel */
- srcData = (GLubyte *) malloc(size);
- if (!srcData) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
- return;
- }
- dstData = (GLubyte *) malloc(size / 2); /* 1/4 would probably be OK */
- if (!dstData) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
- free((void *) srcData);
- return;
- }
-
- /* decompress base image here */
- dst = (GLchan *) srcData;
- for (row = 0; row < srcImage->Height; row++) {
- GLuint col;
- for (col = 0; col < srcImage->Width; col++) {
- srcImage->FetchTexelc(srcImage, col, row, 0, dst);
- dst += components;
- }
- }
- }
- else {
- /* uncompressed */
- convertFormat = srcImage->TexFormat;
- }
-
- _mesa_format_to_type_and_comps(convertFormat, &datatype, &comps);
-
- for (level = texObj->BaseLevel; level < texObj->MaxLevel
- && level < maxLevels - 1; level++) {
- /* generate image[level+1] from image[level] */
- const struct gl_texture_image *srcImage;
- struct gl_texture_image *dstImage;
- GLint srcWidth, srcHeight, srcDepth;
- GLint dstWidth, dstHeight, dstDepth;
- GLint border;
- GLboolean nextLevel;
-
- /* get src image parameters */
- srcImage = _mesa_select_tex_image(ctx, texObj, target, level);
- ASSERT(srcImage);
- srcWidth = srcImage->Width;
- srcHeight = srcImage->Height;
- srcDepth = srcImage->Depth;
- border = srcImage->Border;
-
- nextLevel = next_mipmap_level_size(target, border,
- srcWidth, srcHeight, srcDepth,
- &dstWidth, &dstHeight, &dstDepth);
- if (!nextLevel) {
- /* all done */
- if (_mesa_is_format_compressed(srcImage->TexFormat)) {
- free((void *) srcData);
- free(dstData);
- }
- return;
- }
-
- /* get dest gl_texture_image */
- dstImage = _mesa_get_tex_image(ctx, texObj, target, level + 1);
- if (!dstImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
- return;
- }
-
- /* Free old image data */
- if (dstImage->Data)
- ctx->Driver.FreeTexImageData(ctx, dstImage);
-
- /* initialize new image */
- _mesa_init_teximage_fields(ctx, target, dstImage, dstWidth, dstHeight,
- dstDepth, border, srcImage->InternalFormat,
- srcImage->TexFormat);
- dstImage->DriverData = NULL;
- dstImage->FetchTexelc = srcImage->FetchTexelc;
- dstImage->FetchTexelf = srcImage->FetchTexelf;
-
- /* Alloc new teximage data buffer */
- {
- GLuint size = _mesa_format_image_size(dstImage->TexFormat,
- dstWidth, dstHeight, dstDepth);
- dstImage->Data = _mesa_alloc_texmemory(size);
- if (!dstImage->Data) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
- return;
- }
- }
-
- /* Setup src and dest data pointers */
- if (_mesa_is_format_compressed(dstImage->TexFormat)) {
- /* srcData and dstData are already set */
- ASSERT(srcData);
- ASSERT(dstData);
- }
- else {
- srcData = (const GLubyte *) srcImage->Data;
- dstData = (GLubyte *) dstImage->Data;
- }
-
- ASSERT(dstImage->TexFormat);
- ASSERT(dstImage->FetchTexelc);
- ASSERT(dstImage->FetchTexelf);
-
- _mesa_generate_mipmap_level(target, datatype, comps, border,
- srcWidth, srcHeight, srcDepth,
- srcData, srcImage->RowStride,
- dstWidth, dstHeight, dstDepth,
- dstData, dstImage->RowStride);
-
-
- if (_mesa_is_format_compressed(dstImage->TexFormat)) {
- GLubyte *temp;
- /* compress image from dstData into dstImage->Data */
- const GLenum srcFormat = _mesa_get_format_base_format(convertFormat);
- GLint dstRowStride
- = _mesa_format_row_stride(dstImage->TexFormat, dstWidth);
- ASSERT(srcFormat == GL_RGB || srcFormat == GL_RGBA);
-
- _mesa_texstore(ctx, 2, dstImage->_BaseFormat,
- dstImage->TexFormat,
- dstImage->Data,
- 0, 0, 0, /* dstX/Y/Zoffset */
- dstRowStride, 0, /* strides */
- dstWidth, dstHeight, 1, /* size */
- srcFormat, CHAN_TYPE,
- dstData, /* src data, actually */
- &ctx->DefaultPacking);
-
- /* swap src and dest pointers */
- temp = (GLubyte *) srcData;
- srcData = dstData;
- dstData = temp;
- }
-
- } /* loop over mipmap levels */
-}
-
-
-/**
- * Helper function for drivers which need to rescale texture images to
- * certain aspect ratios.
- * Nearest filtering only (for broken hardware that can't support
- * all aspect ratios). This can be made a lot faster, but I don't
- * really care enough...
- */
-void
-_mesa_rescale_teximage2d(GLuint bytesPerPixel,
- GLuint srcStrideInPixels,
- GLuint dstRowStride,
- GLint srcWidth, GLint srcHeight,
- GLint dstWidth, GLint dstHeight,
- const GLvoid *srcImage, GLvoid *dstImage)
-{
- GLint row, col;
-
-#define INNER_LOOP( TYPE, HOP, WOP ) \
- for ( row = 0 ; row < dstHeight ; row++ ) { \
- GLint srcRow = row HOP hScale; \
- for ( col = 0 ; col < dstWidth ; col++ ) { \
- GLint srcCol = col WOP wScale; \
- dst[col] = src[srcRow * srcStrideInPixels + srcCol]; \
- } \
- dst = (TYPE *) ((GLubyte *) dst + dstRowStride); \
- } \
-
-#define RESCALE_IMAGE( TYPE ) \
-do { \
- const TYPE *src = (const TYPE *)srcImage; \
- TYPE *dst = (TYPE *)dstImage; \
- \
- if ( srcHeight < dstHeight ) { \
- const GLint hScale = dstHeight / srcHeight; \
- if ( srcWidth < dstWidth ) { \
- const GLint wScale = dstWidth / srcWidth; \
- INNER_LOOP( TYPE, /, / ); \
- } \
- else { \
- const GLint wScale = srcWidth / dstWidth; \
- INNER_LOOP( TYPE, /, * ); \
- } \
- } \
- else { \
- const GLint hScale = srcHeight / dstHeight; \
- if ( srcWidth < dstWidth ) { \
- const GLint wScale = dstWidth / srcWidth; \
- INNER_LOOP( TYPE, *, / ); \
- } \
- else { \
- const GLint wScale = srcWidth / dstWidth; \
- INNER_LOOP( TYPE, *, * ); \
- } \
- } \
-} while (0)
-
- switch ( bytesPerPixel ) {
- case 4:
- RESCALE_IMAGE( GLuint );
- break;
-
- case 2:
- RESCALE_IMAGE( GLushort );
- break;
-
- case 1:
- RESCALE_IMAGE( GLubyte );
- break;
- default:
- _mesa_problem(NULL,"unexpected bytes/pixel in _mesa_rescale_teximage2d");
- }
-}
-
-
-/**
- * Upscale an image by replication, not (typical) stretching.
- * We use this when the image width or height is less than a
- * certain size (4, 8) and we need to upscale an image.
- */
-void
-_mesa_upscale_teximage2d(GLsizei inWidth, GLsizei inHeight,
- GLsizei outWidth, GLsizei outHeight,
- GLint comps, const GLchan *src, GLint srcRowStride,
- GLchan *dest )
-{
- GLint i, j, k;
-
- ASSERT(outWidth >= inWidth);
- ASSERT(outHeight >= inHeight);
-#if 0
- ASSERT(inWidth == 1 || inWidth == 2 || inHeight == 1 || inHeight == 2);
- ASSERT((outWidth & 3) == 0);
- ASSERT((outHeight & 3) == 0);
-#endif
-
- for (i = 0; i < outHeight; i++) {
- const GLint ii = i % inHeight;
- for (j = 0; j < outWidth; j++) {
- const GLint jj = j % inWidth;
- for (k = 0; k < comps; k++) {
- dest[(i * outWidth + j) * comps + k]
- = src[ii * srcRowStride + jj * comps + k];
- }
- }
- }
-}
-
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file mipmap.c mipmap generation and teximage resizing functions.
+ */
+
+#include "imports.h"
+#include "formats.h"
+#include "mipmap.h"
+#include "mtypes.h"
+#include "teximage.h"
+#include "texstore.h"
+#include "image.h"
+
+
+
+static GLint
+bytes_per_pixel(GLenum datatype, GLuint comps)
+{
+ GLint b = _mesa_sizeof_packed_type(datatype);
+ assert(b >= 0);
+
+ if (_mesa_type_is_packed(datatype))
+ return b;
+ else
+ return b * comps;
+}
+
+
+/**
+ * \name Support macros for do_row and do_row_3d
+ *
+ * The macro madness is here for two reasons. First, it compacts the code
+ * slightly. Second, it makes it much easier to adjust the specifics of the
+ * filter to tune the rounding characteristics.
+ */
+/*@{*/
+#define DECLARE_ROW_POINTERS(t, e) \
+ const t(*rowA)[e] = (const t(*)[e]) srcRowA; \
+ const t(*rowB)[e] = (const t(*)[e]) srcRowB; \
+ const t(*rowC)[e] = (const t(*)[e]) srcRowC; \
+ const t(*rowD)[e] = (const t(*)[e]) srcRowD; \
+ t(*dst)[e] = (t(*)[e]) dstRow
+
+#define DECLARE_ROW_POINTERS0(t) \
+ const t *rowA = (const t *) srcRowA; \
+ const t *rowB = (const t *) srcRowB; \
+ const t *rowC = (const t *) srcRowC; \
+ const t *rowD = (const t *) srcRowD; \
+ t *dst = (t *) dstRow
+
+#define FILTER_SUM_3D(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
+ ((unsigned) Aj + (unsigned) Ak \
+ + (unsigned) Bj + (unsigned) Bk \
+ + (unsigned) Cj + (unsigned) Ck \
+ + (unsigned) Dj + (unsigned) Dk \
+ + 4) >> 3
+
+#define FILTER_3D(e) \
+ do { \
+ dst[i][e] = FILTER_SUM_3D(rowA[j][e], rowA[k][e], \
+ rowB[j][e], rowB[k][e], \
+ rowC[j][e], rowC[k][e], \
+ rowD[j][e], rowD[k][e]); \
+ } while(0)
+
+#define FILTER_SUM_3D_SIGNED(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
+ (Aj + Ak \
+ + Bj + Bk \
+ + Cj + Ck \
+ + Dj + Dk \
+ + 4) / 8
+
+#define FILTER_3D_SIGNED(e) \
+ do { \
+ dst[i][e] = FILTER_SUM_3D_SIGNED(rowA[j][e], rowA[k][e], \
+ rowB[j][e], rowB[k][e], \
+ rowC[j][e], rowC[k][e], \
+ rowD[j][e], rowD[k][e]); \
+ } while(0)
+
+#define FILTER_F_3D(e) \
+ do { \
+ dst[i][e] = (rowA[j][e] + rowA[k][e] \
+ + rowB[j][e] + rowB[k][e] \
+ + rowC[j][e] + rowC[k][e] \
+ + rowD[j][e] + rowD[k][e]) * 0.125F; \
+ } while(0)
+
+#define FILTER_HF_3D(e) \
+ do { \
+ const GLfloat aj = _mesa_half_to_float(rowA[j][e]); \
+ const GLfloat ak = _mesa_half_to_float(rowA[k][e]); \
+ const GLfloat bj = _mesa_half_to_float(rowB[j][e]); \
+ const GLfloat bk = _mesa_half_to_float(rowB[k][e]); \
+ const GLfloat cj = _mesa_half_to_float(rowC[j][e]); \
+ const GLfloat ck = _mesa_half_to_float(rowC[k][e]); \
+ const GLfloat dj = _mesa_half_to_float(rowD[j][e]); \
+ const GLfloat dk = _mesa_half_to_float(rowD[k][e]); \
+ dst[i][e] = _mesa_float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \
+ * 0.125F); \
+ } while(0)
+/*@}*/
+
+
+/**
+ * Average together two rows of a source image to produce a single new
+ * row in the dest image. It's legal for the two source rows to point
+ * to the same data. The source width must be equal to either the
+ * dest width or two times the dest width.
+ * \param datatype GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_FLOAT, etc.
+ * \param comps number of components per pixel (1..4)
+ */
+static void
+do_row(GLenum datatype, GLuint comps, GLint srcWidth,
+ const GLvoid *srcRowA, const GLvoid *srcRowB,
+ GLint dstWidth, GLvoid *dstRow)
+{
+ const GLuint k0 = (srcWidth == dstWidth) ? 0 : 1;
+ const GLuint colStride = (srcWidth == dstWidth) ? 1 : 2;
+
+ ASSERT(comps >= 1);
+ ASSERT(comps <= 4);
+
+ /* This assertion is no longer valid with non-power-of-2 textures
+ assert(srcWidth == dstWidth || srcWidth == 2 * dstWidth);
+ */
+
+ if (datatype == GL_UNSIGNED_BYTE && comps == 4) {
+ GLuint i, j, k;
+ const GLubyte(*rowA)[4] = (const GLubyte(*)[4]) srcRowA;
+ const GLubyte(*rowB)[4] = (const GLubyte(*)[4]) srcRowB;
+ GLubyte(*dst)[4] = (GLubyte(*)[4]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
+ dst[i][3] = (rowA[j][3] + rowA[k][3] + rowB[j][3] + rowB[k][3]) / 4;
+ }
+ }
+ else if (datatype == GL_UNSIGNED_BYTE && comps == 3) {
+ GLuint i, j, k;
+ const GLubyte(*rowA)[3] = (const GLubyte(*)[3]) srcRowA;
+ const GLubyte(*rowB)[3] = (const GLubyte(*)[3]) srcRowB;
+ GLubyte(*dst)[3] = (GLubyte(*)[3]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
+ }
+ }
+ else if (datatype == GL_UNSIGNED_BYTE && comps == 2) {
+ GLuint i, j, k;
+ const GLubyte(*rowA)[2] = (const GLubyte(*)[2]) srcRowA;
+ const GLubyte(*rowB)[2] = (const GLubyte(*)[2]) srcRowB;
+ GLubyte(*dst)[2] = (GLubyte(*)[2]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) >> 2;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) >> 2;
+ }
+ }
+ else if (datatype == GL_UNSIGNED_BYTE && comps == 1) {
+ GLuint i, j, k;
+ const GLubyte *rowA = (const GLubyte *) srcRowA;
+ const GLubyte *rowB = (const GLubyte *) srcRowB;
+ GLubyte *dst = (GLubyte *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) >> 2;
+ }
+ }
+
+ else if (datatype == GL_BYTE && comps == 4) {
+ GLuint i, j, k;
+ const GLbyte(*rowA)[4] = (const GLbyte(*)[4]) srcRowA;
+ const GLbyte(*rowB)[4] = (const GLbyte(*)[4]) srcRowB;
+ GLbyte(*dst)[4] = (GLbyte(*)[4]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
+ dst[i][3] = (rowA[j][3] + rowA[k][3] + rowB[j][3] + rowB[k][3]) / 4;
+ }
+ }
+ else if (datatype == GL_BYTE && comps == 3) {
+ GLuint i, j, k;
+ const GLbyte(*rowA)[3] = (const GLbyte(*)[3]) srcRowA;
+ const GLbyte(*rowB)[3] = (const GLbyte(*)[3]) srcRowB;
+ GLbyte(*dst)[3] = (GLbyte(*)[3]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
+ }
+ }
+ else if (datatype == GL_BYTE && comps == 2) {
+ GLuint i, j, k;
+ const GLbyte(*rowA)[2] = (const GLbyte(*)[2]) srcRowA;
+ const GLbyte(*rowB)[2] = (const GLbyte(*)[2]) srcRowB;
+ GLbyte(*dst)[2] = (GLbyte(*)[2]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ }
+ }
+ else if (datatype == GL_BYTE && comps == 1) {
+ GLuint i, j, k;
+ const GLbyte *rowA = (const GLbyte *) srcRowA;
+ const GLbyte *rowB = (const GLbyte *) srcRowB;
+ GLbyte *dst = (GLbyte *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) / 4;
+ }
+ }
+
+ else if (datatype == GL_UNSIGNED_SHORT && comps == 4) {
+ GLuint i, j, k;
+ const GLushort(*rowA)[4] = (const GLushort(*)[4]) srcRowA;
+ const GLushort(*rowB)[4] = (const GLushort(*)[4]) srcRowB;
+ GLushort(*dst)[4] = (GLushort(*)[4]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
+ dst[i][3] = (rowA[j][3] + rowA[k][3] + rowB[j][3] + rowB[k][3]) / 4;
+ }
+ }
+ else if (datatype == GL_UNSIGNED_SHORT && comps == 3) {
+ GLuint i, j, k;
+ const GLushort(*rowA)[3] = (const GLushort(*)[3]) srcRowA;
+ const GLushort(*rowB)[3] = (const GLushort(*)[3]) srcRowB;
+ GLushort(*dst)[3] = (GLushort(*)[3]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
+ }
+ }
+ else if (datatype == GL_UNSIGNED_SHORT && comps == 2) {
+ GLuint i, j, k;
+ const GLushort(*rowA)[2] = (const GLushort(*)[2]) srcRowA;
+ const GLushort(*rowB)[2] = (const GLushort(*)[2]) srcRowB;
+ GLushort(*dst)[2] = (GLushort(*)[2]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ }
+ }
+ else if (datatype == GL_UNSIGNED_SHORT && comps == 1) {
+ GLuint i, j, k;
+ const GLushort *rowA = (const GLushort *) srcRowA;
+ const GLushort *rowB = (const GLushort *) srcRowB;
+ GLushort *dst = (GLushort *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) / 4;
+ }
+ }
+
+ else if (datatype == GL_SHORT && comps == 4) {
+ GLuint i, j, k;
+ const GLshort(*rowA)[4] = (const GLshort(*)[4]) srcRowA;
+ const GLshort(*rowB)[4] = (const GLshort(*)[4]) srcRowB;
+ GLshort(*dst)[4] = (GLshort(*)[4]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
+ dst[i][3] = (rowA[j][3] + rowA[k][3] + rowB[j][3] + rowB[k][3]) / 4;
+ }
+ }
+ else if (datatype == GL_SHORT && comps == 3) {
+ GLuint i, j, k;
+ const GLshort(*rowA)[3] = (const GLshort(*)[3]) srcRowA;
+ const GLshort(*rowB)[3] = (const GLshort(*)[3]) srcRowB;
+ GLshort(*dst)[3] = (GLshort(*)[3]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4;
+ }
+ }
+ else if (datatype == GL_SHORT && comps == 2) {
+ GLuint i, j, k;
+ const GLshort(*rowA)[2] = (const GLshort(*)[2]) srcRowA;
+ const GLshort(*rowB)[2] = (const GLshort(*)[2]) srcRowB;
+ GLshort(*dst)[2] = (GLshort(*)[2]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4;
+ }
+ }
+ else if (datatype == GL_SHORT && comps == 1) {
+ GLuint i, j, k;
+ const GLshort *rowA = (const GLshort *) srcRowA;
+ const GLshort *rowB = (const GLshort *) srcRowB;
+ GLshort *dst = (GLshort *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) / 4;
+ }
+ }
+
+ else if (datatype == GL_FLOAT && comps == 4) {
+ GLuint i, j, k;
+ const GLfloat(*rowA)[4] = (const GLfloat(*)[4]) srcRowA;
+ const GLfloat(*rowB)[4] = (const GLfloat(*)[4]) srcRowB;
+ GLfloat(*dst)[4] = (GLfloat(*)[4]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] +
+ rowB[j][0] + rowB[k][0]) * 0.25F;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] +
+ rowB[j][1] + rowB[k][1]) * 0.25F;
+ dst[i][2] = (rowA[j][2] + rowA[k][2] +
+ rowB[j][2] + rowB[k][2]) * 0.25F;
+ dst[i][3] = (rowA[j][3] + rowA[k][3] +
+ rowB[j][3] + rowB[k][3]) * 0.25F;
+ }
+ }
+ else if (datatype == GL_FLOAT && comps == 3) {
+ GLuint i, j, k;
+ const GLfloat(*rowA)[3] = (const GLfloat(*)[3]) srcRowA;
+ const GLfloat(*rowB)[3] = (const GLfloat(*)[3]) srcRowB;
+ GLfloat(*dst)[3] = (GLfloat(*)[3]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] +
+ rowB[j][0] + rowB[k][0]) * 0.25F;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] +
+ rowB[j][1] + rowB[k][1]) * 0.25F;
+ dst[i][2] = (rowA[j][2] + rowA[k][2] +
+ rowB[j][2] + rowB[k][2]) * 0.25F;
+ }
+ }
+ else if (datatype == GL_FLOAT && comps == 2) {
+ GLuint i, j, k;
+ const GLfloat(*rowA)[2] = (const GLfloat(*)[2]) srcRowA;
+ const GLfloat(*rowB)[2] = (const GLfloat(*)[2]) srcRowB;
+ GLfloat(*dst)[2] = (GLfloat(*)[2]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i][0] = (rowA[j][0] + rowA[k][0] +
+ rowB[j][0] + rowB[k][0]) * 0.25F;
+ dst[i][1] = (rowA[j][1] + rowA[k][1] +
+ rowB[j][1] + rowB[k][1]) * 0.25F;
+ }
+ }
+ else if (datatype == GL_FLOAT && comps == 1) {
+ GLuint i, j, k;
+ const GLfloat *rowA = (const GLfloat *) srcRowA;
+ const GLfloat *rowB = (const GLfloat *) srcRowB;
+ GLfloat *dst = (GLfloat *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) * 0.25F;
+ }
+ }
+
+ else if (datatype == GL_HALF_FLOAT_ARB && comps == 4) {
+ GLuint i, j, k, comp;
+ const GLhalfARB(*rowA)[4] = (const GLhalfARB(*)[4]) srcRowA;
+ const GLhalfARB(*rowB)[4] = (const GLhalfARB(*)[4]) srcRowB;
+ GLhalfARB(*dst)[4] = (GLhalfARB(*)[4]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ for (comp = 0; comp < 4; comp++) {
+ GLfloat aj, ak, bj, bk;
+ aj = _mesa_half_to_float(rowA[j][comp]);
+ ak = _mesa_half_to_float(rowA[k][comp]);
+ bj = _mesa_half_to_float(rowB[j][comp]);
+ bk = _mesa_half_to_float(rowB[k][comp]);
+ dst[i][comp] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);
+ }
+ }
+ }
+ else if (datatype == GL_HALF_FLOAT_ARB && comps == 3) {
+ GLuint i, j, k, comp;
+ const GLhalfARB(*rowA)[3] = (const GLhalfARB(*)[3]) srcRowA;
+ const GLhalfARB(*rowB)[3] = (const GLhalfARB(*)[3]) srcRowB;
+ GLhalfARB(*dst)[3] = (GLhalfARB(*)[3]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ for (comp = 0; comp < 3; comp++) {
+ GLfloat aj, ak, bj, bk;
+ aj = _mesa_half_to_float(rowA[j][comp]);
+ ak = _mesa_half_to_float(rowA[k][comp]);
+ bj = _mesa_half_to_float(rowB[j][comp]);
+ bk = _mesa_half_to_float(rowB[k][comp]);
+ dst[i][comp] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);
+ }
+ }
+ }
+ else if (datatype == GL_HALF_FLOAT_ARB && comps == 2) {
+ GLuint i, j, k, comp;
+ const GLhalfARB(*rowA)[2] = (const GLhalfARB(*)[2]) srcRowA;
+ const GLhalfARB(*rowB)[2] = (const GLhalfARB(*)[2]) srcRowB;
+ GLhalfARB(*dst)[2] = (GLhalfARB(*)[2]) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ for (comp = 0; comp < 2; comp++) {
+ GLfloat aj, ak, bj, bk;
+ aj = _mesa_half_to_float(rowA[j][comp]);
+ ak = _mesa_half_to_float(rowA[k][comp]);
+ bj = _mesa_half_to_float(rowB[j][comp]);
+ bk = _mesa_half_to_float(rowB[k][comp]);
+ dst[i][comp] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);
+ }
+ }
+ }
+ else if (datatype == GL_HALF_FLOAT_ARB && comps == 1) {
+ GLuint i, j, k;
+ const GLhalfARB *rowA = (const GLhalfARB *) srcRowA;
+ const GLhalfARB *rowB = (const GLhalfARB *) srcRowB;
+ GLhalfARB *dst = (GLhalfARB *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ GLfloat aj, ak, bj, bk;
+ aj = _mesa_half_to_float(rowA[j]);
+ ak = _mesa_half_to_float(rowA[k]);
+ bj = _mesa_half_to_float(rowB[j]);
+ bk = _mesa_half_to_float(rowB[k]);
+ dst[i] = _mesa_float_to_half((aj + ak + bj + bk) * 0.25F);
+ }
+ }
+
+ else if (datatype == GL_UNSIGNED_INT && comps == 1) {
+ GLuint i, j, k;
+ const GLuint *rowA = (const GLuint *) srcRowA;
+ const GLuint *rowB = (const GLuint *) srcRowB;
+ GLuint *dst = (GLuint *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ dst[i] = (GLfloat)(rowA[j] / 4 + rowA[k] / 4 + rowB[j] / 4 + rowB[k] / 4);
+ }
+ }
+
+ else if (datatype == GL_UNSIGNED_SHORT_5_6_5 && comps == 3) {
+ GLuint i, j, k;
+ const GLushort *rowA = (const GLushort *) srcRowA;
+ const GLushort *rowB = (const GLushort *) srcRowB;
+ GLushort *dst = (GLushort *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0x1f;
+ const GLint rowAr1 = rowA[k] & 0x1f;
+ const GLint rowBr0 = rowB[j] & 0x1f;
+ const GLint rowBr1 = rowB[k] & 0x1f;
+ const GLint rowAg0 = (rowA[j] >> 5) & 0x3f;
+ const GLint rowAg1 = (rowA[k] >> 5) & 0x3f;
+ const GLint rowBg0 = (rowB[j] >> 5) & 0x3f;
+ const GLint rowBg1 = (rowB[k] >> 5) & 0x3f;
+ const GLint rowAb0 = (rowA[j] >> 11) & 0x1f;
+ const GLint rowAb1 = (rowA[k] >> 11) & 0x1f;
+ const GLint rowBb0 = (rowB[j] >> 11) & 0x1f;
+ const GLint rowBb1 = (rowB[k] >> 11) & 0x1f;
+ const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
+ const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
+ const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
+ dst[i] = (blue << 11) | (green << 5) | red;
+ }
+ }
+ else if (datatype == GL_UNSIGNED_SHORT_4_4_4_4 && comps == 4) {
+ GLuint i, j, k;
+ const GLushort *rowA = (const GLushort *) srcRowA;
+ const GLushort *rowB = (const GLushort *) srcRowB;
+ GLushort *dst = (GLushort *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0xf;
+ const GLint rowAr1 = rowA[k] & 0xf;
+ const GLint rowBr0 = rowB[j] & 0xf;
+ const GLint rowBr1 = rowB[k] & 0xf;
+ const GLint rowAg0 = (rowA[j] >> 4) & 0xf;
+ const GLint rowAg1 = (rowA[k] >> 4) & 0xf;
+ const GLint rowBg0 = (rowB[j] >> 4) & 0xf;
+ const GLint rowBg1 = (rowB[k] >> 4) & 0xf;
+ const GLint rowAb0 = (rowA[j] >> 8) & 0xf;
+ const GLint rowAb1 = (rowA[k] >> 8) & 0xf;
+ const GLint rowBb0 = (rowB[j] >> 8) & 0xf;
+ const GLint rowBb1 = (rowB[k] >> 8) & 0xf;
+ const GLint rowAa0 = (rowA[j] >> 12) & 0xf;
+ const GLint rowAa1 = (rowA[k] >> 12) & 0xf;
+ const GLint rowBa0 = (rowB[j] >> 12) & 0xf;
+ const GLint rowBa1 = (rowB[k] >> 12) & 0xf;
+ const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
+ const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
+ const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
+ const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2;
+ dst[i] = (alpha << 12) | (blue << 8) | (green << 4) | red;
+ }
+ }
+ else if (datatype == GL_UNSIGNED_SHORT_1_5_5_5_REV && comps == 4) {
+ GLuint i, j, k;
+ const GLushort *rowA = (const GLushort *) srcRowA;
+ const GLushort *rowB = (const GLushort *) srcRowB;
+ GLushort *dst = (GLushort *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0x1f;
+ const GLint rowAr1 = rowA[k] & 0x1f;
+ const GLint rowBr0 = rowB[j] & 0x1f;
+ const GLint rowBr1 = rowB[k] & 0x1f;
+ const GLint rowAg0 = (rowA[j] >> 5) & 0x1f;
+ const GLint rowAg1 = (rowA[k] >> 5) & 0x1f;
+ const GLint rowBg0 = (rowB[j] >> 5) & 0x1f;
+ const GLint rowBg1 = (rowB[k] >> 5) & 0x1f;
+ const GLint rowAb0 = (rowA[j] >> 10) & 0x1f;
+ const GLint rowAb1 = (rowA[k] >> 10) & 0x1f;
+ const GLint rowBb0 = (rowB[j] >> 10) & 0x1f;
+ const GLint rowBb1 = (rowB[k] >> 10) & 0x1f;
+ const GLint rowAa0 = (rowA[j] >> 15) & 0x1;
+ const GLint rowAa1 = (rowA[k] >> 15) & 0x1;
+ const GLint rowBa0 = (rowB[j] >> 15) & 0x1;
+ const GLint rowBa1 = (rowB[k] >> 15) & 0x1;
+ const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
+ const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
+ const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
+ const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2;
+ dst[i] = (alpha << 15) | (blue << 10) | (green << 5) | red;
+ }
+ }
+ else if (datatype == GL_UNSIGNED_SHORT_5_5_5_1 && comps == 4) {
+ GLuint i, j, k;
+ const GLushort *rowA = (const GLushort *) srcRowA;
+ const GLushort *rowB = (const GLushort *) srcRowB;
+ GLushort *dst = (GLushort *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = (rowA[j] >> 11) & 0x1f;
+ const GLint rowAr1 = (rowA[k] >> 11) & 0x1f;
+ const GLint rowBr0 = (rowB[j] >> 11) & 0x1f;
+ const GLint rowBr1 = (rowB[k] >> 11) & 0x1f;
+ const GLint rowAg0 = (rowA[j] >> 6) & 0x1f;
+ const GLint rowAg1 = (rowA[k] >> 6) & 0x1f;
+ const GLint rowBg0 = (rowB[j] >> 6) & 0x1f;
+ const GLint rowBg1 = (rowB[k] >> 6) & 0x1f;
+ const GLint rowAb0 = (rowA[j] >> 1) & 0x1f;
+ const GLint rowAb1 = (rowA[k] >> 1) & 0x1f;
+ const GLint rowBb0 = (rowB[j] >> 1) & 0x1f;
+ const GLint rowBb1 = (rowB[k] >> 1) & 0x1f;
+ const GLint rowAa0 = (rowA[j] & 0x1);
+ const GLint rowAa1 = (rowA[k] & 0x1);
+ const GLint rowBa0 = (rowB[j] & 0x1);
+ const GLint rowBa1 = (rowB[k] & 0x1);
+ const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
+ const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
+ const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
+ const GLint alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2;
+ dst[i] = (red << 11) | (green << 6) | (blue << 1) | alpha;
+ }
+ }
+
+ else if (datatype == GL_UNSIGNED_BYTE_3_3_2 && comps == 3) {
+ GLuint i, j, k;
+ const GLubyte *rowA = (const GLubyte *) srcRowA;
+ const GLubyte *rowB = (const GLubyte *) srcRowB;
+ GLubyte *dst = (GLubyte *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0x3;
+ const GLint rowAr1 = rowA[k] & 0x3;
+ const GLint rowBr0 = rowB[j] & 0x3;
+ const GLint rowBr1 = rowB[k] & 0x3;
+ const GLint rowAg0 = (rowA[j] >> 2) & 0x7;
+ const GLint rowAg1 = (rowA[k] >> 2) & 0x7;
+ const GLint rowBg0 = (rowB[j] >> 2) & 0x7;
+ const GLint rowBg1 = (rowB[k] >> 2) & 0x7;
+ const GLint rowAb0 = (rowA[j] >> 5) & 0x7;
+ const GLint rowAb1 = (rowA[k] >> 5) & 0x7;
+ const GLint rowBb0 = (rowB[j] >> 5) & 0x7;
+ const GLint rowBb1 = (rowB[k] >> 5) & 0x7;
+ const GLint red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
+ const GLint green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
+ const GLint blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2;
+ dst[i] = (blue << 5) | (green << 2) | red;
+ }
+ }
+
+ else if (datatype == MESA_UNSIGNED_BYTE_4_4 && comps == 2) {
+ GLuint i, j, k;
+ const GLubyte *rowA = (const GLubyte *) srcRowA;
+ const GLubyte *rowB = (const GLubyte *) srcRowB;
+ GLubyte *dst = (GLubyte *) dstRow;
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0xf;
+ const GLint rowAr1 = rowA[k] & 0xf;
+ const GLint rowBr0 = rowB[j] & 0xf;
+ const GLint rowBr1 = rowB[k] & 0xf;
+ const GLint rowAg0 = (rowA[j] >> 4) & 0xf;
+ const GLint rowAg1 = (rowA[k] >> 4) & 0xf;
+ const GLint rowBg0 = (rowB[j] >> 4) & 0xf;
+ const GLint rowBg1 = (rowB[k] >> 4) & 0xf;
+ const GLint r = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2;
+ const GLint g = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2;
+ dst[i] = (g << 4) | r;
+ }
+ }
+
+ else {
+ _mesa_problem(NULL, "bad format in do_row()");
+ }
+}
+
+
+/**
+ * Average together four rows of a source image to produce a single new
+ * row in the dest image. It's legal for the two source rows to point
+ * to the same data. The source width must be equal to either the
+ * dest width or two times the dest width.
+ *
+ * \param datatype GL pixel type \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT,
+ * \c GL_FLOAT, etc.
+ * \param comps number of components per pixel (1..4)
+ * \param srcWidth Width of a row in the source data
+ * \param srcRowA Pointer to one of the rows of source data
+ * \param srcRowB Pointer to one of the rows of source data
+ * \param srcRowC Pointer to one of the rows of source data
+ * \param srcRowD Pointer to one of the rows of source data
+ * \param dstWidth Width of a row in the destination data
+ * \param srcRowA Pointer to the row of destination data
+ */
+static void
+do_row_3D(GLenum datatype, GLuint comps, GLint srcWidth,
+ const GLvoid *srcRowA, const GLvoid *srcRowB,
+ const GLvoid *srcRowC, const GLvoid *srcRowD,
+ GLint dstWidth, GLvoid *dstRow)
+{
+ const GLuint k0 = (srcWidth == dstWidth) ? 0 : 1;
+ const GLuint colStride = (srcWidth == dstWidth) ? 1 : 2;
+ GLuint i, j, k;
+
+ ASSERT(comps >= 1);
+ ASSERT(comps <= 4);
+
+ if ((datatype == GL_UNSIGNED_BYTE) && (comps == 4)) {
+ DECLARE_ROW_POINTERS(GLubyte, 4);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ FILTER_3D(1);
+ FILTER_3D(2);
+ FILTER_3D(3);
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_BYTE) && (comps == 3)) {
+ DECLARE_ROW_POINTERS(GLubyte, 3);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ FILTER_3D(1);
+ FILTER_3D(2);
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_BYTE) && (comps == 2)) {
+ DECLARE_ROW_POINTERS(GLubyte, 2);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ FILTER_3D(1);
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_BYTE) && (comps == 1)) {
+ DECLARE_ROW_POINTERS(GLubyte, 1);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ }
+ }
+ else if ((datatype == GL_BYTE) && (comps == 4)) {
+ DECLARE_ROW_POINTERS(GLbyte, 4);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D_SIGNED(0);
+ FILTER_3D_SIGNED(1);
+ FILTER_3D_SIGNED(2);
+ FILTER_3D_SIGNED(3);
+ }
+ }
+ else if ((datatype == GL_BYTE) && (comps == 3)) {
+ DECLARE_ROW_POINTERS(GLbyte, 3);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D_SIGNED(0);
+ FILTER_3D_SIGNED(1);
+ FILTER_3D_SIGNED(2);
+ }
+ }
+ else if ((datatype == GL_BYTE) && (comps == 2)) {
+ DECLARE_ROW_POINTERS(GLbyte, 2);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D_SIGNED(0);
+ FILTER_3D_SIGNED(1);
+ }
+ }
+ else if ((datatype == GL_BYTE) && (comps == 1)) {
+ DECLARE_ROW_POINTERS(GLbyte, 1);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D_SIGNED(0);
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_SHORT) && (comps == 4)) {
+ DECLARE_ROW_POINTERS(GLushort, 4);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ FILTER_3D(1);
+ FILTER_3D(2);
+ FILTER_3D(3);
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_SHORT) && (comps == 3)) {
+ DECLARE_ROW_POINTERS(GLushort, 3);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ FILTER_3D(1);
+ FILTER_3D(2);
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_SHORT) && (comps == 2)) {
+ DECLARE_ROW_POINTERS(GLushort, 2);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ FILTER_3D(1);
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_SHORT) && (comps == 1)) {
+ DECLARE_ROW_POINTERS(GLushort, 1);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ }
+ }
+ else if ((datatype == GL_SHORT) && (comps == 4)) {
+ DECLARE_ROW_POINTERS(GLshort, 4);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ FILTER_3D(1);
+ FILTER_3D(2);
+ FILTER_3D(3);
+ }
+ }
+ else if ((datatype == GL_SHORT) && (comps == 3)) {
+ DECLARE_ROW_POINTERS(GLshort, 3);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ FILTER_3D(1);
+ FILTER_3D(2);
+ }
+ }
+ else if ((datatype == GL_SHORT) && (comps == 2)) {
+ DECLARE_ROW_POINTERS(GLshort, 2);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ FILTER_3D(1);
+ }
+ }
+ else if ((datatype == GL_SHORT) && (comps == 1)) {
+ DECLARE_ROW_POINTERS(GLshort, 1);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_3D(0);
+ }
+ }
+ else if ((datatype == GL_FLOAT) && (comps == 4)) {
+ DECLARE_ROW_POINTERS(GLfloat, 4);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_F_3D(0);
+ FILTER_F_3D(1);
+ FILTER_F_3D(2);
+ FILTER_F_3D(3);
+ }
+ }
+ else if ((datatype == GL_FLOAT) && (comps == 3)) {
+ DECLARE_ROW_POINTERS(GLfloat, 3);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_F_3D(0);
+ FILTER_F_3D(1);
+ FILTER_F_3D(2);
+ }
+ }
+ else if ((datatype == GL_FLOAT) && (comps == 2)) {
+ DECLARE_ROW_POINTERS(GLfloat, 2);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_F_3D(0);
+ FILTER_F_3D(1);
+ }
+ }
+ else if ((datatype == GL_FLOAT) && (comps == 1)) {
+ DECLARE_ROW_POINTERS(GLfloat, 1);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_F_3D(0);
+ }
+ }
+ else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 4)) {
+ DECLARE_ROW_POINTERS(GLhalfARB, 4);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_HF_3D(0);
+ FILTER_HF_3D(1);
+ FILTER_HF_3D(2);
+ FILTER_HF_3D(3);
+ }
+ }
+ else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 3)) {
+ DECLARE_ROW_POINTERS(GLhalfARB, 4);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_HF_3D(0);
+ FILTER_HF_3D(1);
+ FILTER_HF_3D(2);
+ }
+ }
+ else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 2)) {
+ DECLARE_ROW_POINTERS(GLhalfARB, 4);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_HF_3D(0);
+ FILTER_HF_3D(1);
+ }
+ }
+ else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 1)) {
+ DECLARE_ROW_POINTERS(GLhalfARB, 4);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ FILTER_HF_3D(0);
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_INT) && (comps == 1)) {
+ const GLuint *rowA = (const GLuint *) srcRowA;
+ const GLuint *rowB = (const GLuint *) srcRowB;
+ const GLuint *rowC = (const GLuint *) srcRowC;
+ const GLuint *rowD = (const GLuint *) srcRowD;
+ GLfloat *dst = (GLfloat *) dstRow;
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const uint64_t tmp = (((uint64_t) rowA[j] + (uint64_t) rowA[k])
+ + ((uint64_t) rowB[j] + (uint64_t) rowB[k])
+ + ((uint64_t) rowC[j] + (uint64_t) rowC[k])
+ + ((uint64_t) rowD[j] + (uint64_t) rowD[k]));
+ dst[i] = (GLfloat)((double) tmp * 0.125);
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_SHORT_5_6_5) && (comps == 3)) {
+ DECLARE_ROW_POINTERS0(GLushort);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0x1f;
+ const GLint rowAr1 = rowA[k] & 0x1f;
+ const GLint rowBr0 = rowB[j] & 0x1f;
+ const GLint rowBr1 = rowB[k] & 0x1f;
+ const GLint rowCr0 = rowC[j] & 0x1f;
+ const GLint rowCr1 = rowC[k] & 0x1f;
+ const GLint rowDr0 = rowD[j] & 0x1f;
+ const GLint rowDr1 = rowD[k] & 0x1f;
+ const GLint rowAg0 = (rowA[j] >> 5) & 0x3f;
+ const GLint rowAg1 = (rowA[k] >> 5) & 0x3f;
+ const GLint rowBg0 = (rowB[j] >> 5) & 0x3f;
+ const GLint rowBg1 = (rowB[k] >> 5) & 0x3f;
+ const GLint rowCg0 = (rowC[j] >> 5) & 0x3f;
+ const GLint rowCg1 = (rowC[k] >> 5) & 0x3f;
+ const GLint rowDg0 = (rowD[j] >> 5) & 0x3f;
+ const GLint rowDg1 = (rowD[k] >> 5) & 0x3f;
+ const GLint rowAb0 = (rowA[j] >> 11) & 0x1f;
+ const GLint rowAb1 = (rowA[k] >> 11) & 0x1f;
+ const GLint rowBb0 = (rowB[j] >> 11) & 0x1f;
+ const GLint rowBb1 = (rowB[k] >> 11) & 0x1f;
+ const GLint rowCb0 = (rowC[j] >> 11) & 0x1f;
+ const GLint rowCb1 = (rowC[k] >> 11) & 0x1f;
+ const GLint rowDb0 = (rowD[j] >> 11) & 0x1f;
+ const GLint rowDb1 = (rowD[k] >> 11) & 0x1f;
+ const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
+ rowCr0, rowCr1, rowDr0, rowDr1);
+ const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
+ rowCg0, rowCg1, rowDg0, rowDg1);
+ const GLint b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1,
+ rowCb0, rowCb1, rowDb0, rowDb1);
+ dst[i] = (b << 11) | (g << 5) | r;
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_SHORT_4_4_4_4) && (comps == 4)) {
+ DECLARE_ROW_POINTERS0(GLushort);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0xf;
+ const GLint rowAr1 = rowA[k] & 0xf;
+ const GLint rowBr0 = rowB[j] & 0xf;
+ const GLint rowBr1 = rowB[k] & 0xf;
+ const GLint rowCr0 = rowC[j] & 0xf;
+ const GLint rowCr1 = rowC[k] & 0xf;
+ const GLint rowDr0 = rowD[j] & 0xf;
+ const GLint rowDr1 = rowD[k] & 0xf;
+ const GLint rowAg0 = (rowA[j] >> 4) & 0xf;
+ const GLint rowAg1 = (rowA[k] >> 4) & 0xf;
+ const GLint rowBg0 = (rowB[j] >> 4) & 0xf;
+ const GLint rowBg1 = (rowB[k] >> 4) & 0xf;
+ const GLint rowCg0 = (rowC[j] >> 4) & 0xf;
+ const GLint rowCg1 = (rowC[k] >> 4) & 0xf;
+ const GLint rowDg0 = (rowD[j] >> 4) & 0xf;
+ const GLint rowDg1 = (rowD[k] >> 4) & 0xf;
+ const GLint rowAb0 = (rowA[j] >> 8) & 0xf;
+ const GLint rowAb1 = (rowA[k] >> 8) & 0xf;
+ const GLint rowBb0 = (rowB[j] >> 8) & 0xf;
+ const GLint rowBb1 = (rowB[k] >> 8) & 0xf;
+ const GLint rowCb0 = (rowC[j] >> 8) & 0xf;
+ const GLint rowCb1 = (rowC[k] >> 8) & 0xf;
+ const GLint rowDb0 = (rowD[j] >> 8) & 0xf;
+ const GLint rowDb1 = (rowD[k] >> 8) & 0xf;
+ const GLint rowAa0 = (rowA[j] >> 12) & 0xf;
+ const GLint rowAa1 = (rowA[k] >> 12) & 0xf;
+ const GLint rowBa0 = (rowB[j] >> 12) & 0xf;
+ const GLint rowBa1 = (rowB[k] >> 12) & 0xf;
+ const GLint rowCa0 = (rowC[j] >> 12) & 0xf;
+ const GLint rowCa1 = (rowC[k] >> 12) & 0xf;
+ const GLint rowDa0 = (rowD[j] >> 12) & 0xf;
+ const GLint rowDa1 = (rowD[k] >> 12) & 0xf;
+ const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
+ rowCr0, rowCr1, rowDr0, rowDr1);
+ const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
+ rowCg0, rowCg1, rowDg0, rowDg1);
+ const GLint b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1,
+ rowCb0, rowCb1, rowDb0, rowDb1);
+ const GLint a = FILTER_SUM_3D(rowAa0, rowAa1, rowBa0, rowBa1,
+ rowCa0, rowCa1, rowDa0, rowDa1);
+
+ dst[i] = (a << 12) | (b << 8) | (g << 4) | r;
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_SHORT_1_5_5_5_REV) && (comps == 4)) {
+ DECLARE_ROW_POINTERS0(GLushort);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0x1f;
+ const GLint rowAr1 = rowA[k] & 0x1f;
+ const GLint rowBr0 = rowB[j] & 0x1f;
+ const GLint rowBr1 = rowB[k] & 0x1f;
+ const GLint rowCr0 = rowC[j] & 0x1f;
+ const GLint rowCr1 = rowC[k] & 0x1f;
+ const GLint rowDr0 = rowD[j] & 0x1f;
+ const GLint rowDr1 = rowD[k] & 0x1f;
+ const GLint rowAg0 = (rowA[j] >> 5) & 0x1f;
+ const GLint rowAg1 = (rowA[k] >> 5) & 0x1f;
+ const GLint rowBg0 = (rowB[j] >> 5) & 0x1f;
+ const GLint rowBg1 = (rowB[k] >> 5) & 0x1f;
+ const GLint rowCg0 = (rowC[j] >> 5) & 0x1f;
+ const GLint rowCg1 = (rowC[k] >> 5) & 0x1f;
+ const GLint rowDg0 = (rowD[j] >> 5) & 0x1f;
+ const GLint rowDg1 = (rowD[k] >> 5) & 0x1f;
+ const GLint rowAb0 = (rowA[j] >> 10) & 0x1f;
+ const GLint rowAb1 = (rowA[k] >> 10) & 0x1f;
+ const GLint rowBb0 = (rowB[j] >> 10) & 0x1f;
+ const GLint rowBb1 = (rowB[k] >> 10) & 0x1f;
+ const GLint rowCb0 = (rowC[j] >> 10) & 0x1f;
+ const GLint rowCb1 = (rowC[k] >> 10) & 0x1f;
+ const GLint rowDb0 = (rowD[j] >> 10) & 0x1f;
+ const GLint rowDb1 = (rowD[k] >> 10) & 0x1f;
+ const GLint rowAa0 = (rowA[j] >> 15) & 0x1;
+ const GLint rowAa1 = (rowA[k] >> 15) & 0x1;
+ const GLint rowBa0 = (rowB[j] >> 15) & 0x1;
+ const GLint rowBa1 = (rowB[k] >> 15) & 0x1;
+ const GLint rowCa0 = (rowC[j] >> 15) & 0x1;
+ const GLint rowCa1 = (rowC[k] >> 15) & 0x1;
+ const GLint rowDa0 = (rowD[j] >> 15) & 0x1;
+ const GLint rowDa1 = (rowD[k] >> 15) & 0x1;
+ const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
+ rowCr0, rowCr1, rowDr0, rowDr1);
+ const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
+ rowCg0, rowCg1, rowDg0, rowDg1);
+ const GLint b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1,
+ rowCb0, rowCb1, rowDb0, rowDb1);
+ const GLint a = FILTER_SUM_3D(rowAa0, rowAa1, rowBa0, rowBa1,
+ rowCa0, rowCa1, rowDa0, rowDa1);
+
+ dst[i] = (a << 15) | (b << 10) | (g << 5) | r;
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_SHORT_5_5_5_1) && (comps == 4)) {
+ DECLARE_ROW_POINTERS0(GLushort);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = (rowA[j] >> 11) & 0x1f;
+ const GLint rowAr1 = (rowA[k] >> 11) & 0x1f;
+ const GLint rowBr0 = (rowB[j] >> 11) & 0x1f;
+ const GLint rowBr1 = (rowB[k] >> 11) & 0x1f;
+ const GLint rowCr0 = (rowC[j] >> 11) & 0x1f;
+ const GLint rowCr1 = (rowC[k] >> 11) & 0x1f;
+ const GLint rowDr0 = (rowD[j] >> 11) & 0x1f;
+ const GLint rowDr1 = (rowD[k] >> 11) & 0x1f;
+ const GLint rowAg0 = (rowA[j] >> 6) & 0x1f;
+ const GLint rowAg1 = (rowA[k] >> 6) & 0x1f;
+ const GLint rowBg0 = (rowB[j] >> 6) & 0x1f;
+ const GLint rowBg1 = (rowB[k] >> 6) & 0x1f;
+ const GLint rowCg0 = (rowC[j] >> 6) & 0x1f;
+ const GLint rowCg1 = (rowC[k] >> 6) & 0x1f;
+ const GLint rowDg0 = (rowD[j] >> 6) & 0x1f;
+ const GLint rowDg1 = (rowD[k] >> 6) & 0x1f;
+ const GLint rowAb0 = (rowA[j] >> 1) & 0x1f;
+ const GLint rowAb1 = (rowA[k] >> 1) & 0x1f;
+ const GLint rowBb0 = (rowB[j] >> 1) & 0x1f;
+ const GLint rowBb1 = (rowB[k] >> 1) & 0x1f;
+ const GLint rowCb0 = (rowC[j] >> 1) & 0x1f;
+ const GLint rowCb1 = (rowC[k] >> 1) & 0x1f;
+ const GLint rowDb0 = (rowD[j] >> 1) & 0x1f;
+ const GLint rowDb1 = (rowD[k] >> 1) & 0x1f;
+ const GLint rowAa0 = (rowA[j] & 0x1);
+ const GLint rowAa1 = (rowA[k] & 0x1);
+ const GLint rowBa0 = (rowB[j] & 0x1);
+ const GLint rowBa1 = (rowB[k] & 0x1);
+ const GLint rowCa0 = (rowC[j] & 0x1);
+ const GLint rowCa1 = (rowC[k] & 0x1);
+ const GLint rowDa0 = (rowD[j] & 0x1);
+ const GLint rowDa1 = (rowD[k] & 0x1);
+ const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
+ rowCr0, rowCr1, rowDr0, rowDr1);
+ const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
+ rowCg0, rowCg1, rowDg0, rowDg1);
+ const GLint b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1,
+ rowCb0, rowCb1, rowDb0, rowDb1);
+ const GLint a = FILTER_SUM_3D(rowAa0, rowAa1, rowBa0, rowBa1,
+ rowCa0, rowCa1, rowDa0, rowDa1);
+
+ dst[i] = (r << 11) | (g << 6) | (b << 1) | a;
+ }
+ }
+ else if ((datatype == GL_UNSIGNED_BYTE_3_3_2) && (comps == 3)) {
+ DECLARE_ROW_POINTERS0(GLubyte);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0x3;
+ const GLint rowAr1 = rowA[k] & 0x3;
+ const GLint rowBr0 = rowB[j] & 0x3;
+ const GLint rowBr1 = rowB[k] & 0x3;
+ const GLint rowCr0 = rowC[j] & 0x3;
+ const GLint rowCr1 = rowC[k] & 0x3;
+ const GLint rowDr0 = rowD[j] & 0x3;
+ const GLint rowDr1 = rowD[k] & 0x3;
+ const GLint rowAg0 = (rowA[j] >> 2) & 0x7;
+ const GLint rowAg1 = (rowA[k] >> 2) & 0x7;
+ const GLint rowBg0 = (rowB[j] >> 2) & 0x7;
+ const GLint rowBg1 = (rowB[k] >> 2) & 0x7;
+ const GLint rowCg0 = (rowC[j] >> 2) & 0x7;
+ const GLint rowCg1 = (rowC[k] >> 2) & 0x7;
+ const GLint rowDg0 = (rowD[j] >> 2) & 0x7;
+ const GLint rowDg1 = (rowD[k] >> 2) & 0x7;
+ const GLint rowAb0 = (rowA[j] >> 5) & 0x7;
+ const GLint rowAb1 = (rowA[k] >> 5) & 0x7;
+ const GLint rowBb0 = (rowB[j] >> 5) & 0x7;
+ const GLint rowBb1 = (rowB[k] >> 5) & 0x7;
+ const GLint rowCb0 = (rowC[j] >> 5) & 0x7;
+ const GLint rowCb1 = (rowC[k] >> 5) & 0x7;
+ const GLint rowDb0 = (rowD[j] >> 5) & 0x7;
+ const GLint rowDb1 = (rowD[k] >> 5) & 0x7;
+ const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
+ rowCr0, rowCr1, rowDr0, rowDr1);
+ const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
+ rowCg0, rowCg1, rowDg0, rowDg1);
+ const GLint b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1,
+ rowCb0, rowCb1, rowDb0, rowDb1);
+ dst[i] = (b << 5) | (g << 2) | r;
+ }
+ }
+ else if (datatype == MESA_UNSIGNED_BYTE_4_4 && comps == 2) {
+ DECLARE_ROW_POINTERS0(GLubyte);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0xf;
+ const GLint rowAr1 = rowA[k] & 0xf;
+ const GLint rowBr0 = rowB[j] & 0xf;
+ const GLint rowBr1 = rowB[k] & 0xf;
+ const GLint rowCr0 = rowC[j] & 0xf;
+ const GLint rowCr1 = rowC[k] & 0xf;
+ const GLint rowDr0 = rowD[j] & 0xf;
+ const GLint rowDr1 = rowD[k] & 0xf;
+ const GLint rowAg0 = (rowA[j] >> 4) & 0xf;
+ const GLint rowAg1 = (rowA[k] >> 4) & 0xf;
+ const GLint rowBg0 = (rowB[j] >> 4) & 0xf;
+ const GLint rowBg1 = (rowB[k] >> 4) & 0xf;
+ const GLint rowCg0 = (rowC[j] >> 4) & 0xf;
+ const GLint rowCg1 = (rowC[k] >> 4) & 0xf;
+ const GLint rowDg0 = (rowD[j] >> 4) & 0xf;
+ const GLint rowDg1 = (rowD[k] >> 4) & 0xf;
+ const GLint r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1,
+ rowCr0, rowCr1, rowDr0, rowDr1);
+ const GLint g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1,
+ rowCg0, rowCg1, rowDg0, rowDg1);
+ dst[i] = (g << 4) | r;
+ }
+ }
+ else {
+ _mesa_problem(NULL, "bad format in do_row()");
+ }
+}
+
+
+/*
+ * These functions generate a 1/2-size mipmap image from a source image.
+ * Texture borders are handled by copying or averaging the source image's
+ * border texels, depending on the scale-down factor.
+ */
+
+static void
+make_1d_mipmap(GLenum datatype, GLuint comps, GLint border,
+ GLint srcWidth, const GLubyte *srcPtr,
+ GLint dstWidth, GLubyte *dstPtr)
+{
+ const GLint bpt = bytes_per_pixel(datatype, comps);
+ const GLubyte *src;
+ GLubyte *dst;
+
+ /* skip the border pixel, if any */
+ src = srcPtr + border * bpt;
+ dst = dstPtr + border * bpt;
+
+ /* we just duplicate the input row, kind of hack, saves code */
+ do_row(datatype, comps, srcWidth - 2 * border, src, src,
+ dstWidth - 2 * border, dst);
+
+ if (border) {
+ /* copy left-most pixel from source */
+ assert(dstPtr);
+ assert(srcPtr);
+ memcpy(dstPtr, srcPtr, bpt);
+ /* copy right-most pixel from source */
+ memcpy(dstPtr + (dstWidth - 1) * bpt,
+ srcPtr + (srcWidth - 1) * bpt,
+ bpt);
+ }
+}
+
+
+static void
+make_2d_mipmap(GLenum datatype, GLuint comps, GLint border,
+ GLint srcWidth, GLint srcHeight,
+ const GLubyte *srcPtr, GLint srcRowStride,
+ GLint dstWidth, GLint dstHeight,
+ GLubyte *dstPtr, GLint dstRowStride)
+{
+ const GLint bpt = bytes_per_pixel(datatype, comps);
+ const GLint srcWidthNB = srcWidth - 2 * border; /* sizes w/out border */
+ const GLint dstWidthNB = dstWidth - 2 * border;
+ const GLint dstHeightNB = dstHeight - 2 * border;
+ const GLint srcRowBytes = bpt * srcRowStride;
+ const GLint dstRowBytes = bpt * dstRowStride;
+ const GLubyte *srcA, *srcB;
+ GLubyte *dst;
+ GLint row, srcRowStep;
+
+ /* Compute src and dst pointers, skipping any border */
+ srcA = srcPtr + border * ((srcWidth + 1) * bpt);
+ if (srcHeight > 1 && srcHeight > dstHeight) {
+ /* sample from two source rows */
+ srcB = srcA + srcRowBytes;
+ srcRowStep = 2;
+ }
+ else {
+ /* sample from one source row */
+ srcB = srcA;
+ srcRowStep = 1;
+ }
+
+ dst = dstPtr + border * ((dstWidth + 1) * bpt);
+
+ for (row = 0; row < dstHeightNB; row++) {
+ do_row(datatype, comps, srcWidthNB, srcA, srcB,
+ dstWidthNB, dst);
+ srcA += srcRowStep * srcRowBytes;
+ srcB += srcRowStep * srcRowBytes;
+ dst += dstRowBytes;
+ }
+
+ /* This is ugly but probably won't be used much */
+ if (border > 0) {
+ /* fill in dest border */
+ /* lower-left border pixel */
+ assert(dstPtr);
+ assert(srcPtr);
+ memcpy(dstPtr, srcPtr, bpt);
+ /* lower-right border pixel */
+ memcpy(dstPtr + (dstWidth - 1) * bpt,
+ srcPtr + (srcWidth - 1) * bpt, bpt);
+ /* upper-left border pixel */
+ memcpy(dstPtr + dstWidth * (dstHeight - 1) * bpt,
+ srcPtr + srcWidth * (srcHeight - 1) * bpt, bpt);
+ /* upper-right border pixel */
+ memcpy(dstPtr + (dstWidth * dstHeight - 1) * bpt,
+ srcPtr + (srcWidth * srcHeight - 1) * bpt, bpt);
+ /* lower border */
+ do_row(datatype, comps, srcWidthNB,
+ srcPtr + bpt,
+ srcPtr + bpt,
+ dstWidthNB, dstPtr + bpt);
+ /* upper border */
+ do_row(datatype, comps, srcWidthNB,
+ srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt,
+ srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt,
+ dstWidthNB,
+ dstPtr + (dstWidth * (dstHeight - 1) + 1) * bpt);
+ /* left and right borders */
+ if (srcHeight == dstHeight) {
+ /* copy border pixel from src to dst */
+ for (row = 1; row < srcHeight; row++) {
+ memcpy(dstPtr + dstWidth * row * bpt,
+ srcPtr + srcWidth * row * bpt, bpt);
+ memcpy(dstPtr + (dstWidth * row + dstWidth - 1) * bpt,
+ srcPtr + (srcWidth * row + srcWidth - 1) * bpt, bpt);
+ }
+ }
+ else {
+ /* average two src pixels each dest pixel */
+ for (row = 0; row < dstHeightNB; row += 2) {
+ do_row(datatype, comps, 1,
+ srcPtr + (srcWidth * (row * 2 + 1)) * bpt,
+ srcPtr + (srcWidth * (row * 2 + 2)) * bpt,
+ 1, dstPtr + (dstWidth * row + 1) * bpt);
+ do_row(datatype, comps, 1,
+ srcPtr + (srcWidth * (row * 2 + 1) + srcWidth - 1) * bpt,
+ srcPtr + (srcWidth * (row * 2 + 2) + srcWidth - 1) * bpt,
+ 1, dstPtr + (dstWidth * row + 1 + dstWidth - 1) * bpt);
+ }
+ }
+ }
+}
+
+
+static void
+make_3d_mipmap(GLenum datatype, GLuint comps, GLint border,
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ const GLubyte *srcPtr, GLint srcRowStride,
+ GLint dstWidth, GLint dstHeight, GLint dstDepth,
+ GLubyte *dstPtr, GLint dstRowStride)
+{
+ const GLint bpt = bytes_per_pixel(datatype, comps);
+ const GLint srcWidthNB = srcWidth - 2 * border; /* sizes w/out border */
+ const GLint srcDepthNB = srcDepth - 2 * border;
+ const GLint dstWidthNB = dstWidth - 2 * border;
+ const GLint dstHeightNB = dstHeight - 2 * border;
+ const GLint dstDepthNB = dstDepth - 2 * border;
+ GLint img, row;
+ GLint bytesPerSrcImage, bytesPerDstImage;
+ GLint bytesPerSrcRow, bytesPerDstRow;
+ GLint srcImageOffset, srcRowOffset;
+
+ (void) srcDepthNB; /* silence warnings */
+
+
+ bytesPerSrcImage = srcWidth * srcHeight * bpt;
+ bytesPerDstImage = dstWidth * dstHeight * bpt;
+
+ bytesPerSrcRow = srcWidth * bpt;
+ bytesPerDstRow = dstWidth * bpt;
+
+ /* Offset between adjacent src images to be averaged together */
+ srcImageOffset = (srcDepth == dstDepth) ? 0 : bytesPerSrcImage;
+
+ /* Offset between adjacent src rows to be averaged together */
+ srcRowOffset = (srcHeight == dstHeight) ? 0 : srcWidth * bpt;
+
+ /*
+ * Need to average together up to 8 src pixels for each dest pixel.
+ * Break that down into 3 operations:
+ * 1. take two rows from source image and average them together.
+ * 2. take two rows from next source image and average them together.
+ * 3. take the two averaged rows and average them for the final dst row.
+ */
+
+ /*
+ printf("mip3d %d x %d x %d -> %d x %d x %d\n",
+ srcWidth, srcHeight, srcDepth, dstWidth, dstHeight, dstDepth);
+ */
+
+ for (img = 0; img < dstDepthNB; img++) {
+ /* first source image pointer, skipping border */
+ const GLubyte *imgSrcA = srcPtr
+ + (bytesPerSrcImage + bytesPerSrcRow + border) * bpt * border
+ + img * (bytesPerSrcImage + srcImageOffset);
+ /* second source image pointer, skipping border */
+ const GLubyte *imgSrcB = imgSrcA + srcImageOffset;
+ /* address of the dest image, skipping border */
+ GLubyte *imgDst = dstPtr
+ + (bytesPerDstImage + bytesPerDstRow + border) * bpt * border
+ + img * bytesPerDstImage;
+
+ /* setup the four source row pointers and the dest row pointer */
+ const GLubyte *srcImgARowA = imgSrcA;
+ const GLubyte *srcImgARowB = imgSrcA + srcRowOffset;
+ const GLubyte *srcImgBRowA = imgSrcB;
+ const GLubyte *srcImgBRowB = imgSrcB + srcRowOffset;
+ GLubyte *dstImgRow = imgDst;
+
+ for (row = 0; row < dstHeightNB; row++) {
+ do_row_3D(datatype, comps, srcWidthNB,
+ srcImgARowA, srcImgARowB,
+ srcImgBRowA, srcImgBRowB,
+ dstWidthNB, dstImgRow);
+
+ /* advance to next rows */
+ srcImgARowA += bytesPerSrcRow + srcRowOffset;
+ srcImgARowB += bytesPerSrcRow + srcRowOffset;
+ srcImgBRowA += bytesPerSrcRow + srcRowOffset;
+ srcImgBRowB += bytesPerSrcRow + srcRowOffset;
+ dstImgRow += bytesPerDstRow;
+ }
+ }
+
+
+ /* Luckily we can leverage the make_2d_mipmap() function here! */
+ if (border > 0) {
+ /* do front border image */
+ make_2d_mipmap(datatype, comps, 1, srcWidth, srcHeight, srcPtr, srcRowStride,
+ dstWidth, dstHeight, dstPtr, dstRowStride);
+ /* do back border image */
+ make_2d_mipmap(datatype, comps, 1, srcWidth, srcHeight,
+ srcPtr + bytesPerSrcImage * (srcDepth - 1), srcRowStride,
+ dstWidth, dstHeight,
+ dstPtr + bytesPerDstImage * (dstDepth - 1), dstRowStride);
+ /* do four remaining border edges that span the image slices */
+ if (srcDepth == dstDepth) {
+ /* just copy border pixels from src to dst */
+ for (img = 0; img < dstDepthNB; img++) {
+ const GLubyte *src;
+ GLubyte *dst;
+
+ /* do border along [img][row=0][col=0] */
+ src = srcPtr + (img + 1) * bytesPerSrcImage;
+ dst = dstPtr + (img + 1) * bytesPerDstImage;
+ memcpy(dst, src, bpt);
+
+ /* do border along [img][row=dstHeight-1][col=0] */
+ src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
+ + (srcHeight - 1) * bytesPerSrcRow;
+ dst = dstPtr + (img + 1) * bytesPerDstImage
+ + (dstHeight - 1) * bytesPerDstRow;
+ memcpy(dst, src, bpt);
+
+ /* do border along [img][row=0][col=dstWidth-1] */
+ src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
+ + (srcWidth - 1) * bpt;
+ dst = dstPtr + (img + 1) * bytesPerDstImage
+ + (dstWidth - 1) * bpt;
+ memcpy(dst, src, bpt);
+
+ /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
+ src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
+ + (bytesPerSrcImage - bpt);
+ dst = dstPtr + (img + 1) * bytesPerDstImage
+ + (bytesPerDstImage - bpt);
+ memcpy(dst, src, bpt);
+ }
+ }
+ else {
+ /* average border pixels from adjacent src image pairs */
+ ASSERT(srcDepthNB == 2 * dstDepthNB);
+ for (img = 0; img < dstDepthNB; img++) {
+ const GLubyte *src;
+ GLubyte *dst;
+
+ /* do border along [img][row=0][col=0] */
+ src = srcPtr + (img * 2 + 1) * bytesPerSrcImage;
+ dst = dstPtr + (img + 1) * bytesPerDstImage;
+ do_row(datatype, comps, 1, src, src + srcImageOffset, 1, dst);
+
+ /* do border along [img][row=dstHeight-1][col=0] */
+ src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
+ + (srcHeight - 1) * bytesPerSrcRow;
+ dst = dstPtr + (img + 1) * bytesPerDstImage
+ + (dstHeight - 1) * bytesPerDstRow;
+ do_row(datatype, comps, 1, src, src + srcImageOffset, 1, dst);
+
+ /* do border along [img][row=0][col=dstWidth-1] */
+ src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
+ + (srcWidth - 1) * bpt;
+ dst = dstPtr + (img + 1) * bytesPerDstImage
+ + (dstWidth - 1) * bpt;
+ do_row(datatype, comps, 1, src, src + srcImageOffset, 1, dst);
+
+ /* do border along [img][row=dstHeight-1][col=dstWidth-1] */
+ src = srcPtr + (img * 2 + 1) * bytesPerSrcImage
+ + (bytesPerSrcImage - bpt);
+ dst = dstPtr + (img + 1) * bytesPerDstImage
+ + (bytesPerDstImage - bpt);
+ do_row(datatype, comps, 1, src, src + srcImageOffset, 1, dst);
+ }
+ }
+ }
+}
+
+
+static void
+make_1d_stack_mipmap(GLenum datatype, GLuint comps, GLint border,
+ GLint srcWidth, const GLubyte *srcPtr, GLuint srcRowStride,
+ GLint dstWidth, GLint dstHeight,
+ GLubyte *dstPtr, GLuint dstRowStride )
+{
+ const GLint bpt = bytes_per_pixel(datatype, comps);
+ const GLint srcWidthNB = srcWidth - 2 * border; /* sizes w/out border */
+ const GLint dstWidthNB = dstWidth - 2 * border;
+ const GLint dstHeightNB = dstHeight - 2 * border;
+ const GLint srcRowBytes = bpt * srcRowStride;
+ const GLint dstRowBytes = bpt * dstRowStride;
+ const GLubyte *src;
+ GLubyte *dst;
+ GLint row;
+
+ /* Compute src and dst pointers, skipping any border */
+ src = srcPtr + border * ((srcWidth + 1) * bpt);
+ dst = dstPtr + border * ((dstWidth + 1) * bpt);
+
+ for (row = 0; row < dstHeightNB; row++) {
+ do_row(datatype, comps, srcWidthNB, src, src,
+ dstWidthNB, dst);
+ src += srcRowBytes;
+ dst += dstRowBytes;
+ }
+
+ if (border) {
+ /* copy left-most pixel from source */
+ assert(dstPtr);
+ assert(srcPtr);
+ memcpy(dstPtr, srcPtr, bpt);
+ /* copy right-most pixel from source */
+ memcpy(dstPtr + (dstWidth - 1) * bpt,
+ srcPtr + (srcWidth - 1) * bpt,
+ bpt);
+ }
+}
+
+
+/**
+ * \bug
+ * There is quite a bit of refactoring that could be done with this function
+ * and \c make_2d_mipmap.
+ */
+static void
+make_2d_stack_mipmap(GLenum datatype, GLuint comps, GLint border,
+ GLint srcWidth, GLint srcHeight,
+ const GLubyte *srcPtr, GLint srcRowStride,
+ GLint dstWidth, GLint dstHeight, GLint dstDepth,
+ GLubyte *dstPtr, GLint dstRowStride)
+{
+ const GLint bpt = bytes_per_pixel(datatype, comps);
+ const GLint srcWidthNB = srcWidth - 2 * border; /* sizes w/out border */
+ const GLint dstWidthNB = dstWidth - 2 * border;
+ const GLint dstHeightNB = dstHeight - 2 * border;
+ const GLint dstDepthNB = dstDepth - 2 * border;
+ const GLint srcRowBytes = bpt * srcRowStride;
+ const GLint dstRowBytes = bpt * dstRowStride;
+ const GLubyte *srcA, *srcB;
+ GLubyte *dst;
+ GLint layer;
+ GLint row;
+
+ /* Compute src and dst pointers, skipping any border */
+ srcA = srcPtr + border * ((srcWidth + 1) * bpt);
+ if (srcHeight > 1)
+ srcB = srcA + srcRowBytes;
+ else
+ srcB = srcA;
+ dst = dstPtr + border * ((dstWidth + 1) * bpt);
+
+ for (layer = 0; layer < dstDepthNB; layer++) {
+ for (row = 0; row < dstHeightNB; row++) {
+ do_row(datatype, comps, srcWidthNB, srcA, srcB,
+ dstWidthNB, dst);
+ srcA += 2 * srcRowBytes;
+ srcB += 2 * srcRowBytes;
+ dst += dstRowBytes;
+ }
+
+ /* This is ugly but probably won't be used much */
+ if (border > 0) {
+ /* fill in dest border */
+ /* lower-left border pixel */
+ assert(dstPtr);
+ assert(srcPtr);
+ memcpy(dstPtr, srcPtr, bpt);
+ /* lower-right border pixel */
+ memcpy(dstPtr + (dstWidth - 1) * bpt,
+ srcPtr + (srcWidth - 1) * bpt, bpt);
+ /* upper-left border pixel */
+ memcpy(dstPtr + dstWidth * (dstHeight - 1) * bpt,
+ srcPtr + srcWidth * (srcHeight - 1) * bpt, bpt);
+ /* upper-right border pixel */
+ memcpy(dstPtr + (dstWidth * dstHeight - 1) * bpt,
+ srcPtr + (srcWidth * srcHeight - 1) * bpt, bpt);
+ /* lower border */
+ do_row(datatype, comps, srcWidthNB,
+ srcPtr + bpt,
+ srcPtr + bpt,
+ dstWidthNB, dstPtr + bpt);
+ /* upper border */
+ do_row(datatype, comps, srcWidthNB,
+ srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt,
+ srcPtr + (srcWidth * (srcHeight - 1) + 1) * bpt,
+ dstWidthNB,
+ dstPtr + (dstWidth * (dstHeight - 1) + 1) * bpt);
+ /* left and right borders */
+ if (srcHeight == dstHeight) {
+ /* copy border pixel from src to dst */
+ for (row = 1; row < srcHeight; row++) {
+ memcpy(dstPtr + dstWidth * row * bpt,
+ srcPtr + srcWidth * row * bpt, bpt);
+ memcpy(dstPtr + (dstWidth * row + dstWidth - 1) * bpt,
+ srcPtr + (srcWidth * row + srcWidth - 1) * bpt, bpt);
+ }
+ }
+ else {
+ /* average two src pixels each dest pixel */
+ for (row = 0; row < dstHeightNB; row += 2) {
+ do_row(datatype, comps, 1,
+ srcPtr + (srcWidth * (row * 2 + 1)) * bpt,
+ srcPtr + (srcWidth * (row * 2 + 2)) * bpt,
+ 1, dstPtr + (dstWidth * row + 1) * bpt);
+ do_row(datatype, comps, 1,
+ srcPtr + (srcWidth * (row * 2 + 1) + srcWidth - 1) * bpt,
+ srcPtr + (srcWidth * (row * 2 + 2) + srcWidth - 1) * bpt,
+ 1, dstPtr + (dstWidth * row + 1 + dstWidth - 1) * bpt);
+ }
+ }
+ }
+ }
+}
+
+
+/**
+ * Down-sample a texture image to produce the next lower mipmap level.
+ * \param comps components per texel (1, 2, 3 or 4)
+ * \param srcRowStride stride between source rows, in texels
+ * \param dstRowStride stride between destination rows, in texels
+ */
+void
+_mesa_generate_mipmap_level(GLenum target,
+ GLenum datatype, GLuint comps,
+ GLint border,
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ const GLubyte *srcData,
+ GLint srcRowStride,
+ GLint dstWidth, GLint dstHeight, GLint dstDepth,
+ GLubyte *dstData,
+ GLint dstRowStride)
+{
+ /*
+ * We use simple 2x2 averaging to compute the next mipmap level.
+ */
+ switch (target) {
+ case GL_TEXTURE_1D:
+ make_1d_mipmap(datatype, comps, border,
+ srcWidth, srcData,
+ dstWidth, dstData);
+ break;
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
+ make_2d_mipmap(datatype, comps, border,
+ srcWidth, srcHeight, srcData, srcRowStride,
+ dstWidth, dstHeight, dstData, dstRowStride);
+ break;
+ case GL_TEXTURE_3D:
+ make_3d_mipmap(datatype, comps, border,
+ srcWidth, srcHeight, srcDepth,
+ srcData, srcRowStride,
+ dstWidth, dstHeight, dstDepth,
+ dstData, dstRowStride);
+ break;
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ make_1d_stack_mipmap(datatype, comps, border,
+ srcWidth, srcData, srcRowStride,
+ dstWidth, dstHeight,
+ dstData, dstRowStride);
+ break;
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ make_2d_stack_mipmap(datatype, comps, border,
+ srcWidth, srcHeight,
+ srcData, srcRowStride,
+ dstWidth, dstHeight,
+ dstDepth, dstData, dstRowStride);
+ break;
+ case GL_TEXTURE_RECTANGLE_NV:
+ /* no mipmaps, do nothing */
+ break;
+ default:
+ _mesa_problem(NULL, "bad dimensions in _mesa_generate_mipmaps");
+ return;
+ }
+}
+
+
+/**
+ * compute next (level+1) image size
+ * \return GL_FALSE if no smaller size can be generated (eg. src is 1x1x1 size)
+ */
+static GLboolean
+next_mipmap_level_size(GLenum target, GLint border,
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ GLint *dstWidth, GLint *dstHeight, GLint *dstDepth)
+{
+ if (srcWidth - 2 * border > 1) {
+ *dstWidth = (srcWidth - 2 * border) / 2 + 2 * border;
+ }
+ else {
+ *dstWidth = srcWidth; /* can't go smaller */
+ }
+
+ if ((srcHeight - 2 * border > 1) &&
+ (target != GL_TEXTURE_1D_ARRAY_EXT)) {
+ *dstHeight = (srcHeight - 2 * border) / 2 + 2 * border;
+ }
+ else {
+ *dstHeight = srcHeight; /* can't go smaller */
+ }
+
+ if ((srcDepth - 2 * border > 1) &&
+ (target != GL_TEXTURE_2D_ARRAY_EXT)) {
+ *dstDepth = (srcDepth - 2 * border) / 2 + 2 * border;
+ }
+ else {
+ *dstDepth = srcDepth; /* can't go smaller */
+ }
+
+ if (*dstWidth == srcWidth &&
+ *dstHeight == srcHeight &&
+ *dstDepth == srcDepth) {
+ return GL_FALSE;
+ }
+ else {
+ return GL_TRUE;
+ }
+}
+
+
+
+
+/**
+ * Automatic mipmap generation.
+ * This is the fallback/default function for ctx->Driver.GenerateMipmap().
+ * Generate a complete set of mipmaps from texObj's BaseLevel image.
+ * Stop at texObj's MaxLevel or when we get to the 1x1 texture.
+ * For cube maps, target will be one of
+ * GL_TEXTURE_CUBE_MAP_POSITIVE/NEGATIVE_X/Y/Z; never GL_TEXTURE_CUBE_MAP.
+ */
+void
+_mesa_generate_mipmap(struct gl_context *ctx, GLenum target,
+ struct gl_texture_object *texObj)
+{
+ const struct gl_texture_image *srcImage;
+ gl_format convertFormat;
+ const GLubyte *srcData = NULL;
+ GLubyte *dstData = NULL;
+ GLint level, maxLevels;
+ GLenum datatype;
+ GLuint comps;
+
+ ASSERT(texObj);
+ srcImage = _mesa_select_tex_image(ctx, texObj, target, texObj->BaseLevel);
+ ASSERT(srcImage);
+
+ maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
+ ASSERT(maxLevels > 0); /* bad target */
+
+ /* Find convertFormat - the format that do_row() will process */
+
+ if (_mesa_is_format_compressed(srcImage->TexFormat)) {
+ /* setup for compressed textures - need to allocate temporary
+ * image buffers to hold uncompressed images.
+ */
+ GLuint row;
+ GLint components, size;
+ GLchan *dst;
+
+ assert(texObj->Target == GL_TEXTURE_2D ||
+ texObj->Target == GL_TEXTURE_CUBE_MAP_ARB);
+
+ if (srcImage->_BaseFormat == GL_RGB) {
+ convertFormat = MESA_FORMAT_RGB888;
+ components = 3;
+ } else if (srcImage->_BaseFormat == GL_RED) {
+ convertFormat = MESA_FORMAT_R8;
+ components = 1;
+ } else if (srcImage->_BaseFormat == GL_RG) {
+ convertFormat = MESA_FORMAT_RG88;
+ components = 2;
+ } else if (srcImage->_BaseFormat == GL_RGBA) {
+ convertFormat = MESA_FORMAT_RGBA8888;
+ components = 4;
+ }
+ else {
+ _mesa_problem(ctx, "bad srcImage->_BaseFormat in _mesa_generate_mipmaps");
+ return;
+ }
+
+ /* allocate storage for uncompressed GL_RGB or GL_RGBA images */
+ size = _mesa_bytes_per_pixel(srcImage->_BaseFormat, CHAN_TYPE)
+ * srcImage->Width * srcImage->Height * srcImage->Depth + 20;
+ /* 20 extra bytes, just be safe when calling last FetchTexel */
+ srcData = (GLubyte *) malloc(size);
+ if (!srcData) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
+ return;
+ }
+ dstData = (GLubyte *) malloc(size / 2); /* 1/4 would probably be OK */
+ if (!dstData) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
+ free((void *) srcData);
+ return;
+ }
+
+ /* decompress base image here */
+ dst = (GLchan *) srcData;
+ for (row = 0; row < srcImage->Height; row++) {
+ GLuint col;
+ for (col = 0; col < srcImage->Width; col++) {
+ srcImage->FetchTexelc(srcImage, col, row, 0, dst);
+ dst += components;
+ }
+ }
+ }
+ else {
+ /* uncompressed */
+ convertFormat = srcImage->TexFormat;
+ }
+
+ _mesa_format_to_type_and_comps(convertFormat, &datatype, &comps);
+
+ for (level = texObj->BaseLevel; level < texObj->MaxLevel
+ && level < maxLevels - 1; level++) {
+ /* generate image[level+1] from image[level] */
+ const struct gl_texture_image *srcImage;
+ struct gl_texture_image *dstImage;
+ GLint srcWidth, srcHeight, srcDepth;
+ GLint dstWidth, dstHeight, dstDepth;
+ GLint border;
+ GLboolean nextLevel;
+
+ /* get src image parameters */
+ srcImage = _mesa_select_tex_image(ctx, texObj, target, level);
+ ASSERT(srcImage);
+ srcWidth = srcImage->Width;
+ srcHeight = srcImage->Height;
+ srcDepth = srcImage->Depth;
+ border = srcImage->Border;
+
+ nextLevel = next_mipmap_level_size(target, border,
+ srcWidth, srcHeight, srcDepth,
+ &dstWidth, &dstHeight, &dstDepth);
+ if (!nextLevel) {
+ /* all done */
+ if (_mesa_is_format_compressed(srcImage->TexFormat)) {
+ free((void *) srcData);
+ free(dstData);
+ }
+ return;
+ }
+
+ /* get dest gl_texture_image */
+ dstImage = _mesa_get_tex_image(ctx, texObj, target, level + 1);
+ if (!dstImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
+ return;
+ }
+
+ /* Free old image data */
+ if (dstImage->Data)
+ ctx->Driver.FreeTexImageData(ctx, dstImage);
+
+ /* initialize new image */
+ _mesa_init_teximage_fields(ctx, target, dstImage, dstWidth, dstHeight,
+ dstDepth, border, srcImage->InternalFormat,
+ srcImage->TexFormat);
+ dstImage->DriverData = NULL;
+ dstImage->FetchTexelc = srcImage->FetchTexelc;
+ dstImage->FetchTexelf = srcImage->FetchTexelf;
+
+ /* Alloc new teximage data buffer */
+ {
+ GLuint size = _mesa_format_image_size(dstImage->TexFormat,
+ dstWidth, dstHeight, dstDepth);
+ dstImage->Data = _mesa_alloc_texmemory(size);
+ if (!dstImage->Data) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
+ return;
+ }
+ }
+
+ /* Setup src and dest data pointers */
+ if (_mesa_is_format_compressed(dstImage->TexFormat)) {
+ /* srcData and dstData are already set */
+ ASSERT(srcData);
+ ASSERT(dstData);
+ }
+ else {
+ srcData = (const GLubyte *) srcImage->Data;
+ dstData = (GLubyte *) dstImage->Data;
+ }
+
+ ASSERT(dstImage->TexFormat);
+ ASSERT(dstImage->FetchTexelc);
+ ASSERT(dstImage->FetchTexelf);
+
+ _mesa_generate_mipmap_level(target, datatype, comps, border,
+ srcWidth, srcHeight, srcDepth,
+ srcData, srcImage->RowStride,
+ dstWidth, dstHeight, dstDepth,
+ dstData, dstImage->RowStride);
+
+
+ if (_mesa_is_format_compressed(dstImage->TexFormat)) {
+ GLubyte *temp;
+ /* compress image from dstData into dstImage->Data */
+ const GLenum srcFormat = _mesa_get_format_base_format(convertFormat);
+ GLint dstRowStride
+ = _mesa_format_row_stride(dstImage->TexFormat, dstWidth);
+ ASSERT(srcFormat == GL_RGB || srcFormat == GL_RGBA);
+
+ _mesa_texstore(ctx, 2, dstImage->_BaseFormat,
+ dstImage->TexFormat,
+ dstImage->Data,
+ 0, 0, 0, /* dstX/Y/Zoffset */
+ dstRowStride, 0, /* strides */
+ dstWidth, dstHeight, 1, /* size */
+ srcFormat, CHAN_TYPE,
+ dstData, /* src data, actually */
+ &ctx->DefaultPacking);
+
+ /* swap src and dest pointers */
+ temp = (GLubyte *) srcData;
+ srcData = dstData;
+ dstData = temp;
+ }
+
+ } /* loop over mipmap levels */
+}
+
+
+/**
+ * Helper function for drivers which need to rescale texture images to
+ * certain aspect ratios.
+ * Nearest filtering only (for broken hardware that can't support
+ * all aspect ratios). This can be made a lot faster, but I don't
+ * really care enough...
+ */
+void
+_mesa_rescale_teximage2d(GLuint bytesPerPixel,
+ GLuint srcStrideInPixels,
+ GLuint dstRowStride,
+ GLint srcWidth, GLint srcHeight,
+ GLint dstWidth, GLint dstHeight,
+ const GLvoid *srcImage, GLvoid *dstImage)
+{
+ GLint row, col;
+
+#define INNER_LOOP( TYPE, HOP, WOP ) \
+ for ( row = 0 ; row < dstHeight ; row++ ) { \
+ GLint srcRow = row HOP hScale; \
+ for ( col = 0 ; col < dstWidth ; col++ ) { \
+ GLint srcCol = col WOP wScale; \
+ dst[col] = src[srcRow * srcStrideInPixels + srcCol]; \
+ } \
+ dst = (TYPE *) ((GLubyte *) dst + dstRowStride); \
+ } \
+
+#define RESCALE_IMAGE( TYPE ) \
+do { \
+ const TYPE *src = (const TYPE *)srcImage; \
+ TYPE *dst = (TYPE *)dstImage; \
+ \
+ if ( srcHeight < dstHeight ) { \
+ const GLint hScale = dstHeight / srcHeight; \
+ if ( srcWidth < dstWidth ) { \
+ const GLint wScale = dstWidth / srcWidth; \
+ INNER_LOOP( TYPE, /, / ); \
+ } \
+ else { \
+ const GLint wScale = srcWidth / dstWidth; \
+ INNER_LOOP( TYPE, /, * ); \
+ } \
+ } \
+ else { \
+ const GLint hScale = srcHeight / dstHeight; \
+ if ( srcWidth < dstWidth ) { \
+ const GLint wScale = dstWidth / srcWidth; \
+ INNER_LOOP( TYPE, *, / ); \
+ } \
+ else { \
+ const GLint wScale = srcWidth / dstWidth; \
+ INNER_LOOP( TYPE, *, * ); \
+ } \
+ } \
+} while (0)
+
+ switch ( bytesPerPixel ) {
+ case 4:
+ RESCALE_IMAGE( GLuint );
+ break;
+
+ case 2:
+ RESCALE_IMAGE( GLushort );
+ break;
+
+ case 1:
+ RESCALE_IMAGE( GLubyte );
+ break;
+ default:
+ _mesa_problem(NULL,"unexpected bytes/pixel in _mesa_rescale_teximage2d");
+ }
+}
+
+
+/**
+ * Upscale an image by replication, not (typical) stretching.
+ * We use this when the image width or height is less than a
+ * certain size (4, 8) and we need to upscale an image.
+ */
+void
+_mesa_upscale_teximage2d(GLsizei inWidth, GLsizei inHeight,
+ GLsizei outWidth, GLsizei outHeight,
+ GLint comps, const GLchan *src, GLint srcRowStride,
+ GLchan *dest )
+{
+ GLint i, j, k;
+
+ ASSERT(outWidth >= inWidth);
+ ASSERT(outHeight >= inHeight);
+#if 0
+ ASSERT(inWidth == 1 || inWidth == 2 || inHeight == 1 || inHeight == 2);
+ ASSERT((outWidth & 3) == 0);
+ ASSERT((outHeight & 3) == 0);
+#endif
+
+ for (i = 0; i < outHeight; i++) {
+ const GLint ii = i % inHeight;
+ for (j = 0; j < outWidth; j++) {
+ const GLint jj = j % inWidth;
+ for (k = 0; k < comps; k++) {
+ dest[(i * outWidth + j) * comps + k]
+ = src[ii * srcRowStride + jj * comps + k];
+ }
+ }
+ }
+}
+
diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h
index fcb06d49e..38fc99817 100644
--- a/mesalib/src/mesa/main/mtypes.h
+++ b/mesalib/src/mesa/main/mtypes.h
@@ -1,3355 +1,3355 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.7
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file mtypes.h
- * Main Mesa data structures.
- *
- * Please try to mark derived values with a leading underscore ('_').
- */
-
-#ifndef MTYPES_H
-#define MTYPES_H
-
-
-#include "main/glheader.h"
-#include "main/config.h"
-#include "main/mfeatures.h"
-#include "glapi/glapi.h"
-#include "math/m_matrix.h" /* GLmatrix */
-#include "main/simple_list.h" /* struct simple_node */
-#include "main/formats.h" /* MESA_FORMAT_COUNT */
-
-
-/**
- * Color channel data type.
- */
-#if CHAN_BITS == 8
- typedef GLubyte GLchan;
-#define CHAN_MAX 255
-#define CHAN_MAXF 255.0F
-#define CHAN_TYPE GL_UNSIGNED_BYTE
-#elif CHAN_BITS == 16
- typedef GLushort GLchan;
-#define CHAN_MAX 65535
-#define CHAN_MAXF 65535.0F
-#define CHAN_TYPE GL_UNSIGNED_SHORT
-#elif CHAN_BITS == 32
- typedef GLfloat GLchan;
-#define CHAN_MAX 1.0
-#define CHAN_MAXF 1.0F
-#define CHAN_TYPE GL_FLOAT
-#else
-#error "illegal number of color channel bits"
-#endif
-
-
-/**
- * Stencil buffer data type.
- */
-#if STENCIL_BITS==8
- typedef GLubyte GLstencil;
-#elif STENCIL_BITS==16
- typedef GLushort GLstencil;
-#else
-# error "illegal number of stencil bits"
-#endif
-
-
-/**
- * \name 64-bit extension of GLbitfield.
- */
-/*@{*/
-typedef GLuint64 GLbitfield64;
-
-/** Set a single bit */
-#define BITFIELD64_BIT(b) (1ULL << (b))
-
-
-/**
- * \name Some forward type declarations
- */
-/*@{*/
-struct _mesa_HashTable;
-struct gl_attrib_node;
-struct gl_list_extensions;
-struct gl_meta_state;
-struct gl_pixelstore_attrib;
-struct gl_program_cache;
-struct gl_texture_format;
-struct gl_texture_image;
-struct gl_texture_object;
-struct gl_context;
-struct st_context;
-/*@}*/
-
-
-/** Extra draw modes beyond GL_POINTS, GL_TRIANGLE_FAN, etc */
-#define PRIM_OUTSIDE_BEGIN_END (GL_POLYGON+1)
-#define PRIM_INSIDE_UNKNOWN_PRIM (GL_POLYGON+2)
-#define PRIM_UNKNOWN (GL_POLYGON+3)
-
-
-/**
- * Shader stages. Note that these will become 5 with tessellation.
- * These MUST have the same values as gallium's PIPE_SHADER_*
- */
-typedef enum
-{
- MESA_SHADER_VERTEX = 0,
- MESA_SHADER_FRAGMENT = 1,
- MESA_SHADER_GEOMETRY = 2,
- MESA_SHADER_TYPES = 3
-} gl_shader_type;
-
-
-
-/**
- * Indexes for vertex program attributes.
- * GL_NV_vertex_program aliases generic attributes over the conventional
- * attributes. In GL_ARB_vertex_program shader the aliasing is optional.
- * In GL_ARB_vertex_shader / OpenGL 2.0 the aliasing is disallowed (the
- * generic attributes are distinct/separate).
- */
-typedef enum
-{
- VERT_ATTRIB_POS = 0,
- VERT_ATTRIB_WEIGHT = 1,
- VERT_ATTRIB_NORMAL = 2,
- VERT_ATTRIB_COLOR0 = 3,
- VERT_ATTRIB_COLOR1 = 4,
- VERT_ATTRIB_FOG = 5,
- VERT_ATTRIB_COLOR_INDEX = 6,
- VERT_ATTRIB_POINT_SIZE = 6, /*alias*/
- VERT_ATTRIB_EDGEFLAG = 7,
- VERT_ATTRIB_TEX0 = 8,
- VERT_ATTRIB_TEX1 = 9,
- VERT_ATTRIB_TEX2 = 10,
- VERT_ATTRIB_TEX3 = 11,
- VERT_ATTRIB_TEX4 = 12,
- VERT_ATTRIB_TEX5 = 13,
- VERT_ATTRIB_TEX6 = 14,
- VERT_ATTRIB_TEX7 = 15,
- VERT_ATTRIB_GENERIC0 = 16,
- VERT_ATTRIB_GENERIC1 = 17,
- VERT_ATTRIB_GENERIC2 = 18,
- VERT_ATTRIB_GENERIC3 = 19,
- VERT_ATTRIB_GENERIC4 = 20,
- VERT_ATTRIB_GENERIC5 = 21,
- VERT_ATTRIB_GENERIC6 = 22,
- VERT_ATTRIB_GENERIC7 = 23,
- VERT_ATTRIB_GENERIC8 = 24,
- VERT_ATTRIB_GENERIC9 = 25,
- VERT_ATTRIB_GENERIC10 = 26,
- VERT_ATTRIB_GENERIC11 = 27,
- VERT_ATTRIB_GENERIC12 = 28,
- VERT_ATTRIB_GENERIC13 = 29,
- VERT_ATTRIB_GENERIC14 = 30,
- VERT_ATTRIB_GENERIC15 = 31,
- VERT_ATTRIB_MAX = 32
-} gl_vert_attrib;
-
-/**
- * Bitflags for vertex attributes.
- * These are used in bitfields in many places.
- */
-/*@{*/
-#define VERT_BIT_POS (1 << VERT_ATTRIB_POS)
-#define VERT_BIT_WEIGHT (1 << VERT_ATTRIB_WEIGHT)
-#define VERT_BIT_NORMAL (1 << VERT_ATTRIB_NORMAL)
-#define VERT_BIT_COLOR0 (1 << VERT_ATTRIB_COLOR0)
-#define VERT_BIT_COLOR1 (1 << VERT_ATTRIB_COLOR1)
-#define VERT_BIT_FOG (1 << VERT_ATTRIB_FOG)
-#define VERT_BIT_COLOR_INDEX (1 << VERT_ATTRIB_COLOR_INDEX)
-#define VERT_BIT_EDGEFLAG (1 << VERT_ATTRIB_EDGEFLAG)
-#define VERT_BIT_TEX0 (1 << VERT_ATTRIB_TEX0)
-#define VERT_BIT_TEX1 (1 << VERT_ATTRIB_TEX1)
-#define VERT_BIT_TEX2 (1 << VERT_ATTRIB_TEX2)
-#define VERT_BIT_TEX3 (1 << VERT_ATTRIB_TEX3)
-#define VERT_BIT_TEX4 (1 << VERT_ATTRIB_TEX4)
-#define VERT_BIT_TEX5 (1 << VERT_ATTRIB_TEX5)
-#define VERT_BIT_TEX6 (1 << VERT_ATTRIB_TEX6)
-#define VERT_BIT_TEX7 (1 << VERT_ATTRIB_TEX7)
-#define VERT_BIT_GENERIC0 (1 << VERT_ATTRIB_GENERIC0)
-#define VERT_BIT_GENERIC1 (1 << VERT_ATTRIB_GENERIC1)
-#define VERT_BIT_GENERIC2 (1 << VERT_ATTRIB_GENERIC2)
-#define VERT_BIT_GENERIC3 (1 << VERT_ATTRIB_GENERIC3)
-#define VERT_BIT_GENERIC4 (1 << VERT_ATTRIB_GENERIC4)
-#define VERT_BIT_GENERIC5 (1 << VERT_ATTRIB_GENERIC5)
-#define VERT_BIT_GENERIC6 (1 << VERT_ATTRIB_GENERIC6)
-#define VERT_BIT_GENERIC7 (1 << VERT_ATTRIB_GENERIC7)
-#define VERT_BIT_GENERIC8 (1 << VERT_ATTRIB_GENERIC8)
-#define VERT_BIT_GENERIC9 (1 << VERT_ATTRIB_GENERIC9)
-#define VERT_BIT_GENERIC10 (1 << VERT_ATTRIB_GENERIC10)
-#define VERT_BIT_GENERIC11 (1 << VERT_ATTRIB_GENERIC11)
-#define VERT_BIT_GENERIC12 (1 << VERT_ATTRIB_GENERIC12)
-#define VERT_BIT_GENERIC13 (1 << VERT_ATTRIB_GENERIC13)
-#define VERT_BIT_GENERIC14 (1 << VERT_ATTRIB_GENERIC14)
-#define VERT_BIT_GENERIC15 (1 << VERT_ATTRIB_GENERIC15)
-
-#define VERT_BIT_TEX(u) (1 << (VERT_ATTRIB_TEX0 + (u)))
-#define VERT_BIT_GENERIC(g) (1 << (VERT_ATTRIB_GENERIC0 + (g)))
-/*@}*/
-
-
-/**
- * Indexes for vertex program result attributes
- */
-typedef enum
-{
- VERT_RESULT_HPOS = 0,
- VERT_RESULT_COL0 = 1,
- VERT_RESULT_COL1 = 2,
- VERT_RESULT_FOGC = 3,
- VERT_RESULT_TEX0 = 4,
- VERT_RESULT_TEX1 = 5,
- VERT_RESULT_TEX2 = 6,
- VERT_RESULT_TEX3 = 7,
- VERT_RESULT_TEX4 = 8,
- VERT_RESULT_TEX5 = 9,
- VERT_RESULT_TEX6 = 10,
- VERT_RESULT_TEX7 = 11,
- VERT_RESULT_PSIZ = 12,
- VERT_RESULT_BFC0 = 13,
- VERT_RESULT_BFC1 = 14,
- VERT_RESULT_EDGE = 15,
- VERT_RESULT_VAR0 = 16, /**< shader varying */
- VERT_RESULT_MAX = (VERT_RESULT_VAR0 + MAX_VARYING)
-} gl_vert_result;
-
-
-/*********************************************/
-
-/**
- * Indexes for geometry program attributes.
- */
-typedef enum
-{
- GEOM_ATTRIB_POSITION = 0,
- GEOM_ATTRIB_COLOR0 = 1,
- GEOM_ATTRIB_COLOR1 = 2,
- GEOM_ATTRIB_SECONDARY_COLOR0 = 3,
- GEOM_ATTRIB_SECONDARY_COLOR1 = 4,
- GEOM_ATTRIB_FOG_FRAG_COORD = 5,
- GEOM_ATTRIB_POINT_SIZE = 6,
- GEOM_ATTRIB_CLIP_VERTEX = 7,
- GEOM_ATTRIB_PRIMITIVE_ID = 8,
- GEOM_ATTRIB_TEX_COORD = 9,
-
- GEOM_ATTRIB_VAR0 = 16,
- GEOM_ATTRIB_MAX = (GEOM_ATTRIB_VAR0 + MAX_VARYING)
-} gl_geom_attrib;
-
-/**
- * Bitflags for geometry attributes.
- * These are used in bitfields in many places.
- */
-/*@{*/
-#define GEOM_BIT_COLOR0 (1 << GEOM_ATTRIB_COLOR0)
-#define GEOM_BIT_COLOR1 (1 << GEOM_ATTRIB_COLOR1)
-#define GEOM_BIT_SCOLOR0 (1 << GEOM_ATTRIB_SECONDARY_COLOR0)
-#define GEOM_BIT_SCOLOR1 (1 << GEOM_ATTRIB_SECONDARY_COLOR1)
-#define GEOM_BIT_TEX_COORD (1 << GEOM_ATTRIB_TEX_COORD)
-#define GEOM_BIT_FOG_COORD (1 << GEOM_ATTRIB_FOG_FRAG_COORD)
-#define GEOM_BIT_POSITION (1 << GEOM_ATTRIB_POSITION)
-#define GEOM_BIT_POINT_SIDE (1 << GEOM_ATTRIB_POINT_SIZE)
-#define GEOM_BIT_CLIP_VERTEX (1 << GEOM_ATTRIB_CLIP_VERTEX)
-#define GEOM_BIT_PRIM_ID (1 << GEOM_ATTRIB_PRIMITIVE_ID)
-#define GEOM_BIT_VAR0 (1 << GEOM_ATTRIB_VAR0)
-
-#define GEOM_BIT_VAR(g) (1 << (GEOM_BIT_VAR0 + (g)))
-/*@}*/
-
-
-/**
- * Indexes for geometry program result attributes
- */
-typedef enum
-{
- GEOM_RESULT_POS = 0,
- GEOM_RESULT_COL0 = 1,
- GEOM_RESULT_COL1 = 2,
- GEOM_RESULT_SCOL0 = 3,
- GEOM_RESULT_SCOL1 = 4,
- GEOM_RESULT_FOGC = 5,
- GEOM_RESULT_TEX0 = 6,
- GEOM_RESULT_TEX1 = 7,
- GEOM_RESULT_TEX2 = 8,
- GEOM_RESULT_TEX3 = 9,
- GEOM_RESULT_TEX4 = 10,
- GEOM_RESULT_TEX5 = 11,
- GEOM_RESULT_TEX6 = 12,
- GEOM_RESULT_TEX7 = 13,
- GEOM_RESULT_PSIZ = 14,
- GEOM_RESULT_CLPV = 15,
- GEOM_RESULT_PRID = 16,
- GEOM_RESULT_LAYR = 17,
- GEOM_RESULT_VAR0 = 18, /**< shader varying, should really be 16 */
- /* ### we need to -2 because var0 is 18 instead 16 like in the others */
- GEOM_RESULT_MAX = (GEOM_RESULT_VAR0 + MAX_VARYING - 2)
-} gl_geom_result;
-
-
-/**
- * Indexes for fragment program input attributes.
- */
-typedef enum
-{
- FRAG_ATTRIB_WPOS = 0,
- FRAG_ATTRIB_COL0 = 1,
- FRAG_ATTRIB_COL1 = 2,
- FRAG_ATTRIB_FOGC = 3,
- FRAG_ATTRIB_TEX0 = 4,
- FRAG_ATTRIB_TEX1 = 5,
- FRAG_ATTRIB_TEX2 = 6,
- FRAG_ATTRIB_TEX3 = 7,
- FRAG_ATTRIB_TEX4 = 8,
- FRAG_ATTRIB_TEX5 = 9,
- FRAG_ATTRIB_TEX6 = 10,
- FRAG_ATTRIB_TEX7 = 11,
- FRAG_ATTRIB_FACE = 12, /**< front/back face */
- FRAG_ATTRIB_PNTC = 13, /**< sprite/point coord */
- FRAG_ATTRIB_VAR0 = 14, /**< shader varying */
- FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + MAX_VARYING)
-} gl_frag_attrib;
-
-/**
- * Bitflags for fragment program input attributes.
- */
-/*@{*/
-#define FRAG_BIT_WPOS (1 << FRAG_ATTRIB_WPOS)
-#define FRAG_BIT_COL0 (1 << FRAG_ATTRIB_COL0)
-#define FRAG_BIT_COL1 (1 << FRAG_ATTRIB_COL1)
-#define FRAG_BIT_FOGC (1 << FRAG_ATTRIB_FOGC)
-#define FRAG_BIT_FACE (1 << FRAG_ATTRIB_FACE)
-#define FRAG_BIT_PNTC (1 << FRAG_ATTRIB_PNTC)
-#define FRAG_BIT_TEX0 (1 << FRAG_ATTRIB_TEX0)
-#define FRAG_BIT_TEX1 (1 << FRAG_ATTRIB_TEX1)
-#define FRAG_BIT_TEX2 (1 << FRAG_ATTRIB_TEX2)
-#define FRAG_BIT_TEX3 (1 << FRAG_ATTRIB_TEX3)
-#define FRAG_BIT_TEX4 (1 << FRAG_ATTRIB_TEX4)
-#define FRAG_BIT_TEX5 (1 << FRAG_ATTRIB_TEX5)
-#define FRAG_BIT_TEX6 (1 << FRAG_ATTRIB_TEX6)
-#define FRAG_BIT_TEX7 (1 << FRAG_ATTRIB_TEX7)
-#define FRAG_BIT_VAR0 (1 << FRAG_ATTRIB_VAR0)
-
-#define FRAG_BIT_TEX(U) (FRAG_BIT_TEX0 << (U))
-#define FRAG_BIT_VAR(V) (FRAG_BIT_VAR0 << (V))
-
-#define FRAG_BITS_TEX_ANY (FRAG_BIT_TEX0| \
- FRAG_BIT_TEX1| \
- FRAG_BIT_TEX2| \
- FRAG_BIT_TEX3| \
- FRAG_BIT_TEX4| \
- FRAG_BIT_TEX5| \
- FRAG_BIT_TEX6| \
- FRAG_BIT_TEX7)
-/*@}*/
-
-
-/**
- * Fragment program results
- */
-typedef enum
-{
- FRAG_RESULT_DEPTH = 0,
- FRAG_RESULT_STENCIL = 1,
- FRAG_RESULT_COLOR = 2,
- FRAG_RESULT_DATA0 = 3,
- FRAG_RESULT_MAX = (FRAG_RESULT_DATA0 + MAX_DRAW_BUFFERS)
-} gl_frag_result;
-
-
-/**
- * Indexes for all renderbuffers
- */
-typedef enum
-{
- /* the four standard color buffers */
- BUFFER_FRONT_LEFT,
- BUFFER_BACK_LEFT,
- BUFFER_FRONT_RIGHT,
- BUFFER_BACK_RIGHT,
- BUFFER_DEPTH,
- BUFFER_STENCIL,
- BUFFER_ACCUM,
- /* optional aux buffer */
- BUFFER_AUX0,
- /* generic renderbuffers */
- BUFFER_COLOR0,
- BUFFER_COLOR1,
- BUFFER_COLOR2,
- BUFFER_COLOR3,
- BUFFER_COLOR4,
- BUFFER_COLOR5,
- BUFFER_COLOR6,
- BUFFER_COLOR7,
- BUFFER_COUNT
-} gl_buffer_index;
-
-/**
- * Bit flags for all renderbuffers
- */
-#define BUFFER_BIT_FRONT_LEFT (1 << BUFFER_FRONT_LEFT)
-#define BUFFER_BIT_BACK_LEFT (1 << BUFFER_BACK_LEFT)
-#define BUFFER_BIT_FRONT_RIGHT (1 << BUFFER_FRONT_RIGHT)
-#define BUFFER_BIT_BACK_RIGHT (1 << BUFFER_BACK_RIGHT)
-#define BUFFER_BIT_AUX0 (1 << BUFFER_AUX0)
-#define BUFFER_BIT_AUX1 (1 << BUFFER_AUX1)
-#define BUFFER_BIT_AUX2 (1 << BUFFER_AUX2)
-#define BUFFER_BIT_AUX3 (1 << BUFFER_AUX3)
-#define BUFFER_BIT_DEPTH (1 << BUFFER_DEPTH)
-#define BUFFER_BIT_STENCIL (1 << BUFFER_STENCIL)
-#define BUFFER_BIT_ACCUM (1 << BUFFER_ACCUM)
-#define BUFFER_BIT_COLOR0 (1 << BUFFER_COLOR0)
-#define BUFFER_BIT_COLOR1 (1 << BUFFER_COLOR1)
-#define BUFFER_BIT_COLOR2 (1 << BUFFER_COLOR2)
-#define BUFFER_BIT_COLOR3 (1 << BUFFER_COLOR3)
-#define BUFFER_BIT_COLOR4 (1 << BUFFER_COLOR4)
-#define BUFFER_BIT_COLOR5 (1 << BUFFER_COLOR5)
-#define BUFFER_BIT_COLOR6 (1 << BUFFER_COLOR6)
-#define BUFFER_BIT_COLOR7 (1 << BUFFER_COLOR7)
-
-/**
- * Mask of all the color buffer bits (but not accum).
- */
-#define BUFFER_BITS_COLOR (BUFFER_BIT_FRONT_LEFT | \
- BUFFER_BIT_BACK_LEFT | \
- BUFFER_BIT_FRONT_RIGHT | \
- BUFFER_BIT_BACK_RIGHT | \
- BUFFER_BIT_AUX0 | \
- BUFFER_BIT_COLOR0 | \
- BUFFER_BIT_COLOR1 | \
- BUFFER_BIT_COLOR2 | \
- BUFFER_BIT_COLOR3 | \
- BUFFER_BIT_COLOR4 | \
- BUFFER_BIT_COLOR5 | \
- BUFFER_BIT_COLOR6 | \
- BUFFER_BIT_COLOR7)
-
-
-/**
- * Framebuffer configuration (aka visual / pixelformat)
- * Note: some of these fields should be boolean, but it appears that
- * code in drivers/dri/common/util.c requires int-sized fields.
- */
-struct gl_config
-{
- GLboolean rgbMode;
- GLboolean floatMode;
- GLboolean colorIndexMode; /* XXX is this used anywhere? */
- GLuint doubleBufferMode;
- GLuint stereoMode;
-
- GLboolean haveAccumBuffer;
- GLboolean haveDepthBuffer;
- GLboolean haveStencilBuffer;
-
- GLint redBits, greenBits, blueBits, alphaBits; /* bits per comp */
- GLuint redMask, greenMask, blueMask, alphaMask;
- GLint rgbBits; /* total bits for rgb */
- GLint indexBits; /* total bits for colorindex */
-
- GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits;
- GLint depthBits;
- GLint stencilBits;
-
- GLint numAuxBuffers;
-
- GLint level;
-
- /* EXT_visual_rating / GLX 1.2 */
- GLint visualRating;
-
- /* EXT_visual_info / GLX 1.2 */
- GLint transparentPixel;
- /* colors are floats scaled to ints */
- GLint transparentRed, transparentGreen, transparentBlue, transparentAlpha;
- GLint transparentIndex;
-
- /* ARB_multisample / SGIS_multisample */
- GLint sampleBuffers;
- GLint samples;
-
- /* SGIX_pbuffer / GLX 1.3 */
- GLint maxPbufferWidth;
- GLint maxPbufferHeight;
- GLint maxPbufferPixels;
- GLint optimalPbufferWidth; /* Only for SGIX_pbuffer. */
- GLint optimalPbufferHeight; /* Only for SGIX_pbuffer. */
-
- /* OML_swap_method */
- GLint swapMethod;
-
- /* EXT_texture_from_pixmap */
- GLint bindToTextureRgb;
- GLint bindToTextureRgba;
- GLint bindToMipmapTexture;
- GLint bindToTextureTargets;
- GLint yInverted;
-
- /* EXT_framebuffer_sRGB */
- GLint sRGBCapable;
-};
-
-
-/**
- * Data structure for color tables
- */
-struct gl_color_table
-{
- GLenum InternalFormat; /**< The user-specified format */
- GLenum _BaseFormat; /**< GL_ALPHA, GL_RGBA, GL_RGB, etc */
- GLuint Size; /**< number of entries in table */
- GLfloat *TableF; /**< Color table, floating point values */
- GLubyte *TableUB; /**< Color table, ubyte values */
- GLubyte RedSize;
- GLubyte GreenSize;
- GLubyte BlueSize;
- GLubyte AlphaSize;
- GLubyte LuminanceSize;
- GLubyte IntensitySize;
-};
-
-
-/**
- * \name Bit flags used for updating material values.
- */
-/*@{*/
-#define MAT_ATTRIB_FRONT_AMBIENT 0
-#define MAT_ATTRIB_BACK_AMBIENT 1
-#define MAT_ATTRIB_FRONT_DIFFUSE 2
-#define MAT_ATTRIB_BACK_DIFFUSE 3
-#define MAT_ATTRIB_FRONT_SPECULAR 4
-#define MAT_ATTRIB_BACK_SPECULAR 5
-#define MAT_ATTRIB_FRONT_EMISSION 6
-#define MAT_ATTRIB_BACK_EMISSION 7
-#define MAT_ATTRIB_FRONT_SHININESS 8
-#define MAT_ATTRIB_BACK_SHININESS 9
-#define MAT_ATTRIB_FRONT_INDEXES 10
-#define MAT_ATTRIB_BACK_INDEXES 11
-#define MAT_ATTRIB_MAX 12
-
-#define MAT_ATTRIB_AMBIENT(f) (MAT_ATTRIB_FRONT_AMBIENT+(f))
-#define MAT_ATTRIB_DIFFUSE(f) (MAT_ATTRIB_FRONT_DIFFUSE+(f))
-#define MAT_ATTRIB_SPECULAR(f) (MAT_ATTRIB_FRONT_SPECULAR+(f))
-#define MAT_ATTRIB_EMISSION(f) (MAT_ATTRIB_FRONT_EMISSION+(f))
-#define MAT_ATTRIB_SHININESS(f)(MAT_ATTRIB_FRONT_SHININESS+(f))
-#define MAT_ATTRIB_INDEXES(f) (MAT_ATTRIB_FRONT_INDEXES+(f))
-
-#define MAT_INDEX_AMBIENT 0
-#define MAT_INDEX_DIFFUSE 1
-#define MAT_INDEX_SPECULAR 2
-
-#define MAT_BIT_FRONT_AMBIENT (1<<MAT_ATTRIB_FRONT_AMBIENT)
-#define MAT_BIT_BACK_AMBIENT (1<<MAT_ATTRIB_BACK_AMBIENT)
-#define MAT_BIT_FRONT_DIFFUSE (1<<MAT_ATTRIB_FRONT_DIFFUSE)
-#define MAT_BIT_BACK_DIFFUSE (1<<MAT_ATTRIB_BACK_DIFFUSE)
-#define MAT_BIT_FRONT_SPECULAR (1<<MAT_ATTRIB_FRONT_SPECULAR)
-#define MAT_BIT_BACK_SPECULAR (1<<MAT_ATTRIB_BACK_SPECULAR)
-#define MAT_BIT_FRONT_EMISSION (1<<MAT_ATTRIB_FRONT_EMISSION)
-#define MAT_BIT_BACK_EMISSION (1<<MAT_ATTRIB_BACK_EMISSION)
-#define MAT_BIT_FRONT_SHININESS (1<<MAT_ATTRIB_FRONT_SHININESS)
-#define MAT_BIT_BACK_SHININESS (1<<MAT_ATTRIB_BACK_SHININESS)
-#define MAT_BIT_FRONT_INDEXES (1<<MAT_ATTRIB_FRONT_INDEXES)
-#define MAT_BIT_BACK_INDEXES (1<<MAT_ATTRIB_BACK_INDEXES)
-
-
-#define FRONT_MATERIAL_BITS (MAT_BIT_FRONT_EMISSION | \
- MAT_BIT_FRONT_AMBIENT | \
- MAT_BIT_FRONT_DIFFUSE | \
- MAT_BIT_FRONT_SPECULAR | \
- MAT_BIT_FRONT_SHININESS | \
- MAT_BIT_FRONT_INDEXES)
-
-#define BACK_MATERIAL_BITS (MAT_BIT_BACK_EMISSION | \
- MAT_BIT_BACK_AMBIENT | \
- MAT_BIT_BACK_DIFFUSE | \
- MAT_BIT_BACK_SPECULAR | \
- MAT_BIT_BACK_SHININESS | \
- MAT_BIT_BACK_INDEXES)
-
-#define ALL_MATERIAL_BITS (FRONT_MATERIAL_BITS | BACK_MATERIAL_BITS)
-/*@}*/
-
-
-#define EXP_TABLE_SIZE 512 /**< Specular exponent lookup table sizes */
-#define SHINE_TABLE_SIZE 256 /**< Material shininess lookup table sizes */
-
-/**
- * Material shininess lookup table.
- */
-struct gl_shine_tab
-{
- struct gl_shine_tab *next, *prev;
- GLfloat tab[SHINE_TABLE_SIZE+1];
- GLfloat shininess;
- GLuint refcount;
-};
-
-
-/**
- * Light source state.
- */
-struct gl_light
-{
- struct gl_light *next; /**< double linked list with sentinel */
- struct gl_light *prev;
-
- GLfloat Ambient[4]; /**< ambient color */
- GLfloat Diffuse[4]; /**< diffuse color */
- GLfloat Specular[4]; /**< specular color */
- GLfloat EyePosition[4]; /**< position in eye coordinates */
- GLfloat SpotDirection[4]; /**< spotlight direction in eye coordinates */
- GLfloat SpotExponent;
- GLfloat SpotCutoff; /**< in degrees */
- GLfloat _CosCutoffNeg; /**< = cos(SpotCutoff) */
- GLfloat _CosCutoff; /**< = MAX(0, cos(SpotCutoff)) */
- GLfloat ConstantAttenuation;
- GLfloat LinearAttenuation;
- GLfloat QuadraticAttenuation;
- GLboolean Enabled; /**< On/off flag */
-
- /**
- * \name Derived fields
- */
- /*@{*/
- GLbitfield _Flags; /**< State */
-
- GLfloat _Position[4]; /**< position in eye/obj coordinates */
- GLfloat _VP_inf_norm[3]; /**< Norm direction to infinite light */
- GLfloat _h_inf_norm[3]; /**< Norm( _VP_inf_norm + <0,0,1> ) */
- GLfloat _NormSpotDirection[4]; /**< normalized spotlight direction */
- GLfloat _VP_inf_spot_attenuation;
-
- GLfloat _SpotExpTable[EXP_TABLE_SIZE][2]; /**< to replace a pow() call */
- GLfloat _MatAmbient[2][3]; /**< material ambient * light ambient */
- GLfloat _MatDiffuse[2][3]; /**< material diffuse * light diffuse */
- GLfloat _MatSpecular[2][3]; /**< material spec * light specular */
- GLfloat _dli; /**< CI diffuse light intensity */
- GLfloat _sli; /**< CI specular light intensity */
- /*@}*/
-};
-
-
-/**
- * Light model state.
- */
-struct gl_lightmodel
-{
- GLfloat Ambient[4]; /**< ambient color */
- GLboolean LocalViewer; /**< Local (or infinite) view point? */
- GLboolean TwoSide; /**< Two (or one) sided lighting? */
- GLenum ColorControl; /**< either GL_SINGLE_COLOR
- * or GL_SEPARATE_SPECULAR_COLOR */
-};
-
-
-/**
- * Material state.
- */
-struct gl_material
-{
- GLfloat Attrib[MAT_ATTRIB_MAX][4];
-};
-
-
-/**
- * Accumulation buffer attribute group (GL_ACCUM_BUFFER_BIT)
- */
-struct gl_accum_attrib
-{
- GLfloat ClearColor[4]; /**< Accumulation buffer clear color */
-};
-
-
-/**
- * Color buffer attribute group (GL_COLOR_BUFFER_BIT).
- */
-struct gl_colorbuffer_attrib
-{
- GLuint ClearIndex; /**< Index to use for glClear */
- GLclampf ClearColor[4]; /**< Color to use for glClear */
-
- GLuint IndexMask; /**< Color index write mask */
- GLubyte ColorMask[MAX_DRAW_BUFFERS][4];/**< Each flag is 0xff or 0x0 */
-
- GLenum DrawBuffer[MAX_DRAW_BUFFERS]; /**< Which buffer to draw into */
-
- /**
- * \name alpha testing
- */
- /*@{*/
- GLboolean AlphaEnabled; /**< Alpha test enabled flag */
- GLenum AlphaFunc; /**< Alpha test function */
- GLclampf AlphaRef; /**< Alpha reference value */
- /*@}*/
-
- /**
- * \name Blending
- */
- /*@{*/
- GLbitfield BlendEnabled; /**< Per-buffer blend enable flags */
- GLfloat BlendColor[4]; /**< Blending color */
- struct
- {
- GLenum SrcRGB; /**< RGB blend source term */
- GLenum DstRGB; /**< RGB blend dest term */
- GLenum SrcA; /**< Alpha blend source term */
- GLenum DstA; /**< Alpha blend dest term */
- GLenum EquationRGB; /**< GL_ADD, GL_SUBTRACT, etc. */
- GLenum EquationA; /**< GL_ADD, GL_SUBTRACT, etc. */
- } Blend[MAX_DRAW_BUFFERS];
- /** Are the blend func terms currently different for each buffer/target? */
- GLboolean _BlendFuncPerBuffer;
- /** Are the blend equations currently different for each buffer/target? */
- GLboolean _BlendEquationPerBuffer;
- /*@}*/
-
- /**
- * \name Logic op
- */
- /*@{*/
- GLenum LogicOp; /**< Logic operator */
- GLboolean IndexLogicOpEnabled; /**< Color index logic op enabled flag */
- GLboolean ColorLogicOpEnabled; /**< RGBA logic op enabled flag */
- GLboolean _LogicOpEnabled; /**< RGBA logic op + EXT_blend_logic_op enabled flag */
- /*@}*/
-
- GLboolean DitherFlag; /**< Dither enable flag */
-
- GLenum ClampFragmentColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
- GLenum ClampReadColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
-
- GLboolean sRGBEnabled; /**< Framebuffer sRGB blending/updating requested */
-};
-
-
-/**
- * Current attribute group (GL_CURRENT_BIT).
- */
-struct gl_current_attrib
-{
- /**
- * \name Current vertex attributes.
- * \note Values are valid only after FLUSH_VERTICES has been called.
- * \note Index and Edgeflag current values are stored as floats in the
- * SIX and SEVEN attribute slots.
- */
- GLfloat Attrib[VERT_ATTRIB_MAX][4]; /**< Position, color, texcoords, etc */
-
- /**
- * \name Current raster position attributes (always valid).
- * \note This set of attributes is very similar to the SWvertex struct.
- */
- /*@{*/
- GLfloat RasterPos[4];
- GLfloat RasterDistance;
- GLfloat RasterColor[4];
- GLfloat RasterSecondaryColor[4];
- GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4];
- GLboolean RasterPosValid;
- /*@}*/
-};
-
-
-/**
- * Depth buffer attribute group (GL_DEPTH_BUFFER_BIT).
- */
-struct gl_depthbuffer_attrib
-{
- GLenum Func; /**< Function for depth buffer compare */
- GLclampd Clear; /**< Value to clear depth buffer to */
- GLboolean Test; /**< Depth buffering enabled flag */
- GLboolean Mask; /**< Depth buffer writable? */
- GLboolean BoundsTest; /**< GL_EXT_depth_bounds_test */
- GLfloat BoundsMin, BoundsMax;/**< GL_EXT_depth_bounds_test */
-};
-
-
-/**
- * Evaluator attribute group (GL_EVAL_BIT).
- */
-struct gl_eval_attrib
-{
- /**
- * \name Enable bits
- */
- /*@{*/
- GLboolean Map1Color4;
- GLboolean Map1Index;
- GLboolean Map1Normal;
- GLboolean Map1TextureCoord1;
- GLboolean Map1TextureCoord2;
- GLboolean Map1TextureCoord3;
- GLboolean Map1TextureCoord4;
- GLboolean Map1Vertex3;
- GLboolean Map1Vertex4;
- GLboolean Map1Attrib[16]; /* GL_NV_vertex_program */
- GLboolean Map2Color4;
- GLboolean Map2Index;
- GLboolean Map2Normal;
- GLboolean Map2TextureCoord1;
- GLboolean Map2TextureCoord2;
- GLboolean Map2TextureCoord3;
- GLboolean Map2TextureCoord4;
- GLboolean Map2Vertex3;
- GLboolean Map2Vertex4;
- GLboolean Map2Attrib[16]; /* GL_NV_vertex_program */
- GLboolean AutoNormal;
- /*@}*/
-
- /**
- * \name Map Grid endpoints and divisions and calculated du values
- */
- /*@{*/
- GLint MapGrid1un;
- GLfloat MapGrid1u1, MapGrid1u2, MapGrid1du;
- GLint MapGrid2un, MapGrid2vn;
- GLfloat MapGrid2u1, MapGrid2u2, MapGrid2du;
- GLfloat MapGrid2v1, MapGrid2v2, MapGrid2dv;
- /*@}*/
-};
-
-
-/**
- * Fog attribute group (GL_FOG_BIT).
- */
-struct gl_fog_attrib
-{
- GLboolean Enabled; /**< Fog enabled flag */
- GLfloat Color[4]; /**< Fog color */
- GLfloat Density; /**< Density >= 0.0 */
- GLfloat Start; /**< Start distance in eye coords */
- GLfloat End; /**< End distance in eye coords */
- GLfloat Index; /**< Fog index */
- GLenum Mode; /**< Fog mode */
- GLboolean ColorSumEnabled;
- GLenum FogCoordinateSource; /**< GL_EXT_fog_coord */
- GLfloat _Scale; /**< (End == Start) ? 1.0 : 1.0 / (End - Start) */
-};
-
-
-/**
- * \brief Layout qualifiers for gl_FragDepth.
- *
- * Extension AMD_conservative_depth allows gl_FragDepth to be redeclared with
- * a layout qualifier.
- *
- * \see enum ir_depth_layout
- */
-enum gl_frag_depth_layout {
- FRAG_DEPTH_LAYOUT_NONE, /**< No layout is specified. */
- FRAG_DEPTH_LAYOUT_ANY,
- FRAG_DEPTH_LAYOUT_GREATER,
- FRAG_DEPTH_LAYOUT_LESS,
- FRAG_DEPTH_LAYOUT_UNCHANGED
-};
-
-
-/**
- * Hint attribute group (GL_HINT_BIT).
- *
- * Values are always one of GL_FASTEST, GL_NICEST, or GL_DONT_CARE.
- */
-struct gl_hint_attrib
-{
- GLenum PerspectiveCorrection;
- GLenum PointSmooth;
- GLenum LineSmooth;
- GLenum PolygonSmooth;
- GLenum Fog;
- GLenum ClipVolumeClipping; /**< GL_EXT_clip_volume_hint */
- GLenum TextureCompression; /**< GL_ARB_texture_compression */
- GLenum GenerateMipmap; /**< GL_SGIS_generate_mipmap */
- GLenum FragmentShaderDerivative; /**< GL_ARB_fragment_shader */
-};
-
-/**
- * Light state flags.
- */
-/*@{*/
-#define LIGHT_SPOT 0x1
-#define LIGHT_LOCAL_VIEWER 0x2
-#define LIGHT_POSITIONAL 0x4
-#define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
-/*@}*/
-
-
-/**
- * Lighting attribute group (GL_LIGHT_BIT).
- */
-struct gl_light_attrib
-{
- struct gl_light Light[MAX_LIGHTS]; /**< Array of light sources */
- struct gl_lightmodel Model; /**< Lighting model */
-
- /**
- * Must flush FLUSH_VERTICES before referencing:
- */
- /*@{*/
- struct gl_material Material; /**< Includes front & back values */
- /*@}*/
-
- GLboolean Enabled; /**< Lighting enabled flag */
- GLenum ShadeModel; /**< GL_FLAT or GL_SMOOTH */
- GLenum ProvokingVertex; /**< GL_EXT_provoking_vertex */
- GLenum ColorMaterialFace; /**< GL_FRONT, BACK or FRONT_AND_BACK */
- GLenum ColorMaterialMode; /**< GL_AMBIENT, GL_DIFFUSE, etc */
- GLbitfield ColorMaterialBitmask; /**< bitmask formed from Face and Mode */
- GLboolean ColorMaterialEnabled;
- GLenum ClampVertexColor;
-
- struct gl_light EnabledList; /**< List sentinel */
-
- /**
- * Derived state for optimizations:
- */
- /*@{*/
- GLboolean _NeedEyeCoords;
- GLboolean _NeedVertices; /**< Use fast shader? */
- GLbitfield _Flags; /**< LIGHT_* flags, see above */
- GLfloat _BaseColor[2][3];
- /*@}*/
-};
-
-
-/**
- * Line attribute group (GL_LINE_BIT).
- */
-struct gl_line_attrib
-{
- GLboolean SmoothFlag; /**< GL_LINE_SMOOTH enabled? */
- GLboolean StippleFlag; /**< GL_LINE_STIPPLE enabled? */
- GLushort StipplePattern; /**< Stipple pattern */
- GLint StippleFactor; /**< Stipple repeat factor */
- GLfloat Width; /**< Line width */
-};
-
-
-/**
- * Display list attribute group (GL_LIST_BIT).
- */
-struct gl_list_attrib
-{
- GLuint ListBase;
-};
-
-
-/**
- * Multisample attribute group (GL_MULTISAMPLE_BIT).
- */
-struct gl_multisample_attrib
-{
- GLboolean Enabled;
- GLboolean _Enabled; /**< true if Enabled and multisample buffer */
- GLboolean SampleAlphaToCoverage;
- GLboolean SampleAlphaToOne;
- GLboolean SampleCoverage;
- GLfloat SampleCoverageValue;
- GLboolean SampleCoverageInvert;
-};
-
-
-/**
- * A pixelmap (see glPixelMap)
- */
-struct gl_pixelmap
-{
- GLint Size;
- GLfloat Map[MAX_PIXEL_MAP_TABLE];
- GLubyte Map8[MAX_PIXEL_MAP_TABLE]; /**< converted to 8-bit color */
-};
-
-
-/**
- * Collection of all pixelmaps
- */
-struct gl_pixelmaps
-{
- struct gl_pixelmap RtoR; /**< i.e. GL_PIXEL_MAP_R_TO_R */
- struct gl_pixelmap GtoG;
- struct gl_pixelmap BtoB;
- struct gl_pixelmap AtoA;
- struct gl_pixelmap ItoR;
- struct gl_pixelmap ItoG;
- struct gl_pixelmap ItoB;
- struct gl_pixelmap ItoA;
- struct gl_pixelmap ItoI;
- struct gl_pixelmap StoS;
-};
-
-
-/**
- * Pixel attribute group (GL_PIXEL_MODE_BIT).
- */
-struct gl_pixel_attrib
-{
- GLenum ReadBuffer; /**< source buffer for glRead/CopyPixels() */
-
- /*--- Begin Pixel Transfer State ---*/
- /* Fields are in the order in which they're applied... */
-
- /** Scale & Bias (index shift, offset) */
- /*@{*/
- GLfloat RedBias, RedScale;
- GLfloat GreenBias, GreenScale;
- GLfloat BlueBias, BlueScale;
- GLfloat AlphaBias, AlphaScale;
- GLfloat DepthBias, DepthScale;
- GLint IndexShift, IndexOffset;
- /*@}*/
-
- /* Pixel Maps */
- /* Note: actual pixel maps are not part of this attrib group */
- GLboolean MapColorFlag;
- GLboolean MapStencilFlag;
-
- /*--- End Pixel Transfer State ---*/
-
- /** glPixelZoom */
- GLfloat ZoomX, ZoomY;
-};
-
-
-/**
- * Point attribute group (GL_POINT_BIT).
- */
-struct gl_point_attrib
-{
- GLboolean SmoothFlag; /**< True if GL_POINT_SMOOTH is enabled */
- GLfloat Size; /**< User-specified point size */
- GLfloat Params[3]; /**< GL_EXT_point_parameters */
- GLfloat MinSize, MaxSize; /**< GL_EXT_point_parameters */
- GLfloat Threshold; /**< GL_EXT_point_parameters */
- GLboolean _Attenuated; /**< True if Params != [1, 0, 0] */
- GLboolean PointSprite; /**< GL_NV/ARB_point_sprite */
- GLboolean CoordReplace[MAX_TEXTURE_COORD_UNITS]; /**< GL_ARB_point_sprite*/
- GLenum SpriteRMode; /**< GL_NV_point_sprite (only!) */
- GLenum SpriteOrigin; /**< GL_ARB_point_sprite */
-};
-
-
-/**
- * Polygon attribute group (GL_POLYGON_BIT).
- */
-struct gl_polygon_attrib
-{
- GLenum FrontFace; /**< Either GL_CW or GL_CCW */
- GLenum FrontMode; /**< Either GL_POINT, GL_LINE or GL_FILL */
- GLenum BackMode; /**< Either GL_POINT, GL_LINE or GL_FILL */
- GLboolean _FrontBit; /**< 0=GL_CCW, 1=GL_CW */
- GLboolean CullFlag; /**< Culling on/off flag */
- GLboolean SmoothFlag; /**< True if GL_POLYGON_SMOOTH is enabled */
- GLboolean StippleFlag; /**< True if GL_POLYGON_STIPPLE is enabled */
- GLenum CullFaceMode; /**< Culling mode GL_FRONT or GL_BACK */
- GLfloat OffsetFactor; /**< Polygon offset factor, from user */
- GLfloat OffsetUnits; /**< Polygon offset units, from user */
- GLboolean OffsetPoint; /**< Offset in GL_POINT mode */
- GLboolean OffsetLine; /**< Offset in GL_LINE mode */
- GLboolean OffsetFill; /**< Offset in GL_FILL mode */
-};
-
-
-/**
- * Scissor attributes (GL_SCISSOR_BIT).
- */
-struct gl_scissor_attrib
-{
- GLboolean Enabled; /**< Scissor test enabled? */
- GLint X, Y; /**< Lower left corner of box */
- GLsizei Width, Height; /**< Size of box */
-};
-
-
-/**
- * Stencil attribute group (GL_STENCIL_BUFFER_BIT).
- *
- * Three sets of stencil data are tracked so that OpenGL 2.0,
- * GL_EXT_stencil_two_side, and GL_ATI_separate_stencil can all be supported
- * simultaneously. In each of the stencil state arrays, element 0 corresponds
- * to GL_FRONT. Element 1 corresponds to the OpenGL 2.0 /
- * GL_ATI_separate_stencil GL_BACK state. Element 2 corresponds to the
- * GL_EXT_stencil_two_side GL_BACK state.
- *
- * The derived value \c _BackFace is either 1 or 2 depending on whether or
- * not GL_STENCIL_TEST_TWO_SIDE_EXT is enabled.
- *
- * The derived value \c _TestTwoSide is set when the front-face and back-face
- * stencil state are different.
- */
-struct gl_stencil_attrib
-{
- GLboolean Enabled; /**< Enabled flag */
- GLboolean TestTwoSide; /**< GL_EXT_stencil_two_side */
- GLubyte ActiveFace; /**< GL_EXT_stencil_two_side (0 or 2) */
- GLboolean _Enabled; /**< Enabled and stencil buffer present */
- GLboolean _TestTwoSide;
- GLubyte _BackFace; /**< Current back stencil state (1 or 2) */
- GLenum Function[3]; /**< Stencil function */
- GLenum FailFunc[3]; /**< Fail function */
- GLenum ZPassFunc[3]; /**< Depth buffer pass function */
- GLenum ZFailFunc[3]; /**< Depth buffer fail function */
- GLint Ref[3]; /**< Reference value */
- GLuint ValueMask[3]; /**< Value mask */
- GLuint WriteMask[3]; /**< Write mask */
- GLuint Clear; /**< Clear value */
-};
-
-
-/**
- * An index for each type of texture object. These correspond to the GL
- * texture target enums, such as GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.
- * Note: the order is from highest priority to lowest priority.
- */
-typedef enum
-{
- TEXTURE_2D_ARRAY_INDEX,
- TEXTURE_1D_ARRAY_INDEX,
- TEXTURE_CUBE_INDEX,
- TEXTURE_3D_INDEX,
- TEXTURE_RECT_INDEX,
- TEXTURE_2D_INDEX,
- TEXTURE_1D_INDEX,
- NUM_TEXTURE_TARGETS
-} gl_texture_index;
-
-
-/**
- * Bit flags for each type of texture object
- * Used for Texture.Unit[]._ReallyEnabled flags.
- */
-/*@{*/
-#define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX)
-#define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX)
-#define TEXTURE_CUBE_BIT (1 << TEXTURE_CUBE_INDEX)
-#define TEXTURE_3D_BIT (1 << TEXTURE_3D_INDEX)
-#define TEXTURE_RECT_BIT (1 << TEXTURE_RECT_INDEX)
-#define TEXTURE_2D_BIT (1 << TEXTURE_2D_INDEX)
-#define TEXTURE_1D_BIT (1 << TEXTURE_1D_INDEX)
-/*@}*/
-
-
-/**
- * TexGenEnabled flags.
- */
-/*@{*/
-#define S_BIT 1
-#define T_BIT 2
-#define R_BIT 4
-#define Q_BIT 8
-#define STR_BITS (S_BIT | T_BIT | R_BIT)
-/*@}*/
-
-
-/**
- * Bit flag versions of the corresponding GL_ constants.
- */
-/*@{*/
-#define TEXGEN_SPHERE_MAP 0x1
-#define TEXGEN_OBJ_LINEAR 0x2
-#define TEXGEN_EYE_LINEAR 0x4
-#define TEXGEN_REFLECTION_MAP_NV 0x8
-#define TEXGEN_NORMAL_MAP_NV 0x10
-
-#define TEXGEN_NEED_NORMALS (TEXGEN_SPHERE_MAP | \
- TEXGEN_REFLECTION_MAP_NV | \
- TEXGEN_NORMAL_MAP_NV)
-#define TEXGEN_NEED_EYE_COORD (TEXGEN_SPHERE_MAP | \
- TEXGEN_REFLECTION_MAP_NV | \
- TEXGEN_NORMAL_MAP_NV | \
- TEXGEN_EYE_LINEAR)
-/*@}*/
-
-
-
-/** Tex-gen enabled for texture unit? */
-#define ENABLE_TEXGEN(unit) (1 << (unit))
-
-/** Non-identity texture matrix for texture unit? */
-#define ENABLE_TEXMAT(unit) (1 << (unit))
-
-
-/**
- * Texel fetch function prototype. We use texel fetch functions to
- * extract RGBA, color indexes and depth components out of 1D, 2D and 3D
- * texture images. These functions help to isolate us from the gritty
- * details of all the various texture image encodings.
- *
- * \param texImage texture image.
- * \param col texel column.
- * \param row texel row.
- * \param img texel image level/layer.
- * \param texelOut output texel (up to 4 GLchans)
- */
-typedef void (*FetchTexelFuncC)( const struct gl_texture_image *texImage,
- GLint col, GLint row, GLint img,
- GLchan *texelOut );
-
-/**
- * As above, but returns floats.
- * Used for depth component images and for upcoming signed/float
- * texture images.
- */
-typedef void (*FetchTexelFuncF)( const struct gl_texture_image *texImage,
- GLint col, GLint row, GLint img,
- GLfloat *texelOut );
-
-
-typedef void (*StoreTexelFunc)(struct gl_texture_image *texImage,
- GLint col, GLint row, GLint img,
- const void *texel);
-
-
-/**
- * Texture image state. Describes the dimensions of a texture image,
- * the texel format and pointers to Texel Fetch functions.
- */
-struct gl_texture_image
-{
- GLint InternalFormat; /**< Internal format as given by the user */
- GLenum _BaseFormat; /**< Either GL_RGB, GL_RGBA, GL_ALPHA,
- * GL_LUMINANCE, GL_LUMINANCE_ALPHA,
- * GL_INTENSITY, GL_COLOR_INDEX,
- * GL_DEPTH_COMPONENT or GL_DEPTH_STENCIL_EXT
- * only. Used for choosing TexEnv arithmetic.
- */
- gl_format TexFormat; /**< The actual texture memory format */
-
- GLuint Border; /**< 0 or 1 */
- GLuint Width; /**< = 2^WidthLog2 + 2*Border */
- GLuint Height; /**< = 2^HeightLog2 + 2*Border */
- GLuint Depth; /**< = 2^DepthLog2 + 2*Border */
- GLuint Width2; /**< = Width - 2*Border */
- GLuint Height2; /**< = Height - 2*Border */
- GLuint Depth2; /**< = Depth - 2*Border */
- GLuint WidthLog2; /**< = log2(Width2) */
- GLuint HeightLog2; /**< = log2(Height2) */
- GLuint DepthLog2; /**< = log2(Depth2) */
- GLuint MaxLog2; /**< = MAX(WidthLog2, HeightLog2) */
- GLfloat WidthScale; /**< used for mipmap LOD computation */
- GLfloat HeightScale; /**< used for mipmap LOD computation */
- GLfloat DepthScale; /**< used for mipmap LOD computation */
- GLboolean IsClientData; /**< Data owned by client? */
- GLboolean _IsPowerOfTwo; /**< Are all dimensions powers of two? */
-
- struct gl_texture_object *TexObject; /**< Pointer back to parent object */
-
- FetchTexelFuncC FetchTexelc; /**< GLchan texel fetch function pointer */
- FetchTexelFuncF FetchTexelf; /**< Float texel fetch function pointer */
-
- GLuint RowStride; /**< Padded width in units of texels */
- GLuint *ImageOffsets; /**< if 3D texture: array [Depth] of offsets to
- each 2D slice in 'Data', in texels */
- GLvoid *Data; /**< Image data, accessed via FetchTexel() */
-
- /**
- * \name For device driver:
- */
- /*@{*/
- void *DriverData; /**< Arbitrary device driver data */
- /*@}*/
-};
-
-
-/**
- * Indexes for cube map faces.
- */
-typedef enum
-{
- FACE_POS_X = 0,
- FACE_NEG_X = 1,
- FACE_POS_Y = 2,
- FACE_NEG_Y = 3,
- FACE_POS_Z = 4,
- FACE_NEG_Z = 5,
- MAX_FACES = 6
-} gl_face_index;
-
-
-/**
- * Texture object state. Contains the array of mipmap images, border color,
- * wrap modes, filter modes, shadow/texcompare state, and the per-texture
- * color palette.
- */
-struct gl_texture_object
-{
- _glthread_Mutex Mutex; /**< for thread safety */
- GLint RefCount; /**< reference count */
- GLuint Name; /**< the user-visible texture object ID */
- GLenum Target; /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
- GLfloat Priority; /**< in [0,1] */
- union {
- GLfloat f[4];
- GLuint ui[4];
- GLint i[4];
- } BorderColor; /**< Interpreted according to texture format */
- GLenum WrapS; /**< S-axis texture image wrap mode */
- GLenum WrapT; /**< T-axis texture image wrap mode */
- GLenum WrapR; /**< R-axis texture image wrap mode */
- GLenum MinFilter; /**< minification filter */
- GLenum MagFilter; /**< magnification filter */
- GLfloat MinLod; /**< min lambda, OpenGL 1.2 */
- GLfloat MaxLod; /**< max lambda, OpenGL 1.2 */
- GLfloat LodBias; /**< OpenGL 1.4 */
- GLint BaseLevel; /**< min mipmap level, OpenGL 1.2 */
- GLint MaxLevel; /**< max mipmap level, OpenGL 1.2 */
- GLfloat MaxAnisotropy; /**< GL_EXT_texture_filter_anisotropic */
- GLenum CompareMode; /**< GL_ARB_shadow */
- GLenum CompareFunc; /**< GL_ARB_shadow */
- GLfloat CompareFailValue; /**< GL_ARB_shadow_ambient */
- GLenum DepthMode; /**< GL_ARB_depth_texture */
- GLint _MaxLevel; /**< actual max mipmap level (q in the spec) */
- GLfloat _MaxLambda; /**< = _MaxLevel - BaseLevel (q - b in spec) */
- GLint CropRect[4]; /**< GL_OES_draw_texture */
- GLenum Swizzle[4]; /**< GL_EXT_texture_swizzle */
- GLuint _Swizzle; /**< same as Swizzle, but SWIZZLE_* format */
- GLboolean GenerateMipmap; /**< GL_SGIS_generate_mipmap */
- GLboolean _Complete; /**< Is texture object complete? */
- GLboolean _RenderToTexture; /**< Any rendering to this texture? */
- GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */
- GLenum sRGBDecode; /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */
-
- /** Actual texture images, indexed by [cube face] and [mipmap level] */
- struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
-
- /** GL_EXT_paletted_texture */
- struct gl_color_table Palette;
-
- /**
- * \name For device driver.
- * Note: instead of attaching driver data to this pointer, it's preferable
- * to instead use this struct as a base class for your own texture object
- * class. Driver->NewTextureObject() can be used to implement the
- * allocation.
- */
- void *DriverData; /**< Arbitrary device driver data */
-};
-
-
-/** Up to four combiner sources are possible with GL_NV_texture_env_combine4 */
-#define MAX_COMBINER_TERMS 4
-
-
-/**
- * Texture combine environment state.
- */
-struct gl_tex_env_combine_state
-{
- GLenum ModeRGB; /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
- GLenum ModeA; /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
- /** Source terms: GL_PRIMARY_COLOR, GL_TEXTURE, etc */
- GLenum SourceRGB[MAX_COMBINER_TERMS];
- GLenum SourceA[MAX_COMBINER_TERMS];
- /** Source operands: GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, etc */
- GLenum OperandRGB[MAX_COMBINER_TERMS];
- GLenum OperandA[MAX_COMBINER_TERMS];
- GLuint ScaleShiftRGB; /**< 0, 1 or 2 */
- GLuint ScaleShiftA; /**< 0, 1 or 2 */
- GLuint _NumArgsRGB; /**< Number of inputs used for the RGB combiner */
- GLuint _NumArgsA; /**< Number of inputs used for the A combiner */
-};
-
-
-/**
- * Texture coord generation state.
- */
-struct gl_texgen
-{
- GLenum Mode; /**< GL_EYE_LINEAR, GL_SPHERE_MAP, etc */
- GLbitfield _ModeBit; /**< TEXGEN_x bit corresponding to Mode */
- GLfloat ObjectPlane[4];
- GLfloat EyePlane[4];
-};
-
-
-/**
- * Texture unit state. Contains enable flags, texture environment/function/
- * combiners, texgen state, pointers to current texture objects and
- * post-filter color tables.
- */
-struct gl_texture_unit
-{
- GLbitfield Enabled; /**< bitmask of TEXTURE_*_BIT flags */
- GLbitfield _ReallyEnabled; /**< 0 or exactly one of TEXTURE_*_BIT flags */
-
- GLenum EnvMode; /**< GL_MODULATE, GL_DECAL, GL_BLEND, etc. */
- GLfloat EnvColor[4];
-
- struct gl_texgen GenS;
- struct gl_texgen GenT;
- struct gl_texgen GenR;
- struct gl_texgen GenQ;
- GLbitfield TexGenEnabled; /**< Bitwise-OR of [STRQ]_BIT values */
- GLbitfield _GenFlags; /**< Bitwise-OR of Gen[STRQ]._ModeBit */
-
- GLfloat LodBias; /**< for biasing mipmap levels */
- GLenum BumpTarget;
- GLfloat RotMatrix[4]; /* 2x2 matrix */
-
- /**
- * \name GL_EXT_texture_env_combine
- */
- struct gl_tex_env_combine_state Combine;
-
- /**
- * Derived state based on \c EnvMode and the \c BaseFormat of the
- * currently enabled texture.
- */
- struct gl_tex_env_combine_state _EnvMode;
-
- /**
- * Currently enabled combiner state. This will point to either
- * \c Combine or \c _EnvMode.
- */
- struct gl_tex_env_combine_state *_CurrentCombine;
-
- /** Current texture object pointers */
- struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
-
- /** Points to highest priority, complete and enabled texture object */
- struct gl_texture_object *_Current;
-};
-
-
-/**
- * Texture attribute group (GL_TEXTURE_BIT).
- */
-struct gl_texture_attrib
-{
- GLuint CurrentUnit; /**< GL_ACTIVE_TEXTURE */
- struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
-
- struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
-
- /** GL_ARB_seamless_cubemap */
- GLboolean CubeMapSeamless;
-
- /** GL_EXT_shared_texture_palette */
- GLboolean SharedPalette;
- struct gl_color_table Palette;
-
- /** Texture units/samplers used by vertex or fragment texturing */
- GLbitfield _EnabledUnits;
-
- /** Texture coord units/sets used for fragment texturing */
- GLbitfield _EnabledCoordUnits;
-
- /** Texture coord units that have texgen enabled */
- GLbitfield _TexGenEnabled;
-
- /** Texture coord units that have non-identity matrices */
- GLbitfield _TexMatEnabled;
-
- /** Bitwise-OR of all Texture.Unit[i]._GenFlags */
- GLbitfield _GenFlags;
-};
-
-
-/**
- * Transformation attribute group (GL_TRANSFORM_BIT).
- */
-struct gl_transform_attrib
-{
- GLenum MatrixMode; /**< Matrix mode */
- GLfloat EyeUserPlane[MAX_CLIP_PLANES][4]; /**< User clip planes */
- GLfloat _ClipUserPlane[MAX_CLIP_PLANES][4]; /**< derived */
- GLbitfield ClipPlanesEnabled; /**< on/off bitmask */
- GLboolean Normalize; /**< Normalize all normals? */
- GLboolean RescaleNormals; /**< GL_EXT_rescale_normal */
- GLboolean RasterPositionUnclipped; /**< GL_IBM_rasterpos_clip */
- GLboolean DepthClamp; /**< GL_ARB_depth_clamp */
-
- GLfloat CullEyePos[4];
- GLfloat CullObjPos[4];
-};
-
-
-/**
- * Viewport attribute group (GL_VIEWPORT_BIT).
- */
-struct gl_viewport_attrib
-{
- GLint X, Y; /**< position */
- GLsizei Width, Height; /**< size */
- GLfloat Near, Far; /**< Depth buffer range */
- GLmatrix _WindowMap; /**< Mapping transformation as a matrix. */
-};
-
-
-/**
- * GL_ARB_vertex/pixel_buffer_object buffer object
- */
-struct gl_buffer_object
-{
- _glthread_Mutex Mutex;
- GLint RefCount;
- GLuint Name;
- GLenum Usage; /**< GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, etc. */
- GLsizeiptrARB Size; /**< Size of buffer storage in bytes */
- GLubyte *Data; /**< Location of storage either in RAM or VRAM. */
- /** Fields describing a mapped buffer */
- /*@{*/
- GLbitfield AccessFlags; /**< Mask of GL_MAP_x_BIT flags */
- GLvoid *Pointer; /**< User-space address of mapping */
- GLintptr Offset; /**< Mapped offset */
- GLsizeiptr Length; /**< Mapped length */
- /*@}*/
- GLboolean Written; /**< Ever written to? (for debugging) */
- GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */
-};
-
-
-/**
- * Client pixel packing/unpacking attributes
- */
-struct gl_pixelstore_attrib
-{
- GLint Alignment;
- GLint RowLength;
- GLint SkipPixels;
- GLint SkipRows;
- GLint ImageHeight;
- GLint SkipImages;
- GLboolean SwapBytes;
- GLboolean LsbFirst;
- GLboolean ClientStorage; /**< GL_APPLE_client_storage */
- GLboolean Invert; /**< GL_MESA_pack_invert */
- struct gl_buffer_object *BufferObj; /**< GL_ARB_pixel_buffer_object */
-};
-
-
-/**
- * Client vertex array attributes
- */
-struct gl_client_array
-{
- GLint Size; /**< components per element (1,2,3,4) */
- GLenum Type; /**< datatype: GL_FLOAT, GL_INT, etc */
- GLenum Format; /**< default: GL_RGBA, but may be GL_BGRA */
- GLsizei Stride; /**< user-specified stride */
- GLsizei StrideB; /**< actual stride in bytes */
- const GLubyte *Ptr; /**< Points to array data */
- GLboolean Enabled; /**< Enabled flag is a boolean */
- GLboolean Normalized; /**< GL_ARB_vertex_program */
- GLboolean Integer; /**< Integer-valued? */
- GLuint InstanceDivisor; /**< GL_ARB_instanced_arrays */
- GLuint _ElementSize; /**< size of each element in bytes */
-
- struct gl_buffer_object *BufferObj;/**< GL_ARB_vertex_buffer_object */
- GLuint _MaxElement; /**< max element index into array buffer + 1 */
-};
-
-
-/**
- * Collection of vertex arrays. Defined by the GL_APPLE_vertex_array_object
- * extension, but a nice encapsulation in any case.
- */
-struct gl_array_object
-{
- /** Name of the array object as received from glGenVertexArrayAPPLE. */
- GLuint Name;
-
- GLint RefCount;
- _glthread_Mutex Mutex;
- GLboolean VBOonly; /**< require all arrays to live in VBOs? */
-
- /** Conventional vertex arrays */
- /*@{*/
- struct gl_client_array Vertex;
- struct gl_client_array Weight;
- struct gl_client_array Normal;
- struct gl_client_array Color;
- struct gl_client_array SecondaryColor;
- struct gl_client_array FogCoord;
- struct gl_client_array Index;
- struct gl_client_array EdgeFlag;
- struct gl_client_array TexCoord[MAX_TEXTURE_COORD_UNITS];
- struct gl_client_array PointSize;
- /*@}*/
-
- /**
- * Generic arrays for vertex programs/shaders.
- * For NV vertex programs, these attributes alias and take priority
- * over the conventional attribs above. For ARB vertex programs and
- * GLSL vertex shaders, these attributes are separate.
- */
- struct gl_client_array VertexAttrib[MAX_VERTEX_GENERIC_ATTRIBS];
-
- /** Mask of _NEW_ARRAY_* values indicating which arrays are enabled */
- GLbitfield _Enabled;
-
- /**
- * Min of all enabled arrays' _MaxElement. When arrays reside inside VBOs
- * we can determine the max legal (in bounds) glDrawElements array index.
- */
- GLuint _MaxElement;
-};
-
-
-/**
- * Vertex array state
- */
-struct gl_array_attrib
-{
- /** Currently bound array object. See _mesa_BindVertexArrayAPPLE() */
- struct gl_array_object *ArrayObj;
-
- /** The default vertex array object */
- struct gl_array_object *DefaultArrayObj;
-
- /** Array objects (GL_ARB/APPLE_vertex_array_object) */
- struct _mesa_HashTable *Objects;
-
- GLint ActiveTexture; /**< Client Active Texture */
- GLuint LockFirst; /**< GL_EXT_compiled_vertex_array */
- GLuint LockCount; /**< GL_EXT_compiled_vertex_array */
-
- /** GL 3.1 (slightly different from GL_NV_primitive_restart) */
- GLboolean PrimitiveRestart;
- GLuint RestartIndex;
-
- GLbitfield NewState; /**< mask of _NEW_ARRAY_* values */
- GLboolean RebindArrays; /**< whether the VBO module should rebind arrays */
-
- /* GL_ARB_vertex_buffer_object */
- struct gl_buffer_object *ArrayBufferObj;
- struct gl_buffer_object *ElementArrayBufferObj;
-};
-
-
-/**
- * Feedback buffer state
- */
-struct gl_feedback
-{
- GLenum Type;
- GLbitfield _Mask; /**< FB_* bits */
- GLfloat *Buffer;
- GLuint BufferSize;
- GLuint Count;
-};
-
-
-/**
- * Selection buffer state
- */
-struct gl_selection
-{
- GLuint *Buffer; /**< selection buffer */
- GLuint BufferSize; /**< size of the selection buffer */
- GLuint BufferCount; /**< number of values in the selection buffer */
- GLuint Hits; /**< number of records in the selection buffer */
- GLuint NameStackDepth; /**< name stack depth */
- GLuint NameStack[MAX_NAME_STACK_DEPTH]; /**< name stack */
- GLboolean HitFlag; /**< hit flag */
- GLfloat HitMinZ; /**< minimum hit depth */
- GLfloat HitMaxZ; /**< maximum hit depth */
-};
-
-
-/**
- * 1-D Evaluator control points
- */
-struct gl_1d_map
-{
- GLuint Order; /**< Number of control points */
- GLfloat u1, u2, du; /**< u1, u2, 1.0/(u2-u1) */
- GLfloat *Points; /**< Points to contiguous control points */
-};
-
-
-/**
- * 2-D Evaluator control points
- */
-struct gl_2d_map
-{
- GLuint Uorder; /**< Number of control points in U dimension */
- GLuint Vorder; /**< Number of control points in V dimension */
- GLfloat u1, u2, du;
- GLfloat v1, v2, dv;
- GLfloat *Points; /**< Points to contiguous control points */
-};
-
-
-/**
- * All evaluator control point state
- */
-struct gl_evaluators
-{
- /**
- * \name 1-D maps
- */
- /*@{*/
- struct gl_1d_map Map1Vertex3;
- struct gl_1d_map Map1Vertex4;
- struct gl_1d_map Map1Index;
- struct gl_1d_map Map1Color4;
- struct gl_1d_map Map1Normal;
- struct gl_1d_map Map1Texture1;
- struct gl_1d_map Map1Texture2;
- struct gl_1d_map Map1Texture3;
- struct gl_1d_map Map1Texture4;
- struct gl_1d_map Map1Attrib[16]; /**< GL_NV_vertex_program */
- /*@}*/
-
- /**
- * \name 2-D maps
- */
- /*@{*/
- struct gl_2d_map Map2Vertex3;
- struct gl_2d_map Map2Vertex4;
- struct gl_2d_map Map2Index;
- struct gl_2d_map Map2Color4;
- struct gl_2d_map Map2Normal;
- struct gl_2d_map Map2Texture1;
- struct gl_2d_map Map2Texture2;
- struct gl_2d_map Map2Texture3;
- struct gl_2d_map Map2Texture4;
- struct gl_2d_map Map2Attrib[16]; /**< GL_NV_vertex_program */
- /*@}*/
-};
-
-
-/**
- * Names of the various vertex/fragment program register files, etc.
- *
- * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
- * All values should fit in a 4-bit field.
- *
- * NOTE: PROGRAM_ENV_PARAM, PROGRAM_STATE_VAR, PROGRAM_NAMED_PARAM,
- * PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be considered to
- * be "uniform" variables since they can only be set outside glBegin/End.
- * They're also all stored in the same Parameters array.
- */
-typedef enum
-{
- PROGRAM_TEMPORARY, /**< machine->Temporary[] */
- PROGRAM_INPUT, /**< machine->Inputs[] */
- PROGRAM_OUTPUT, /**< machine->Outputs[] */
- PROGRAM_VARYING, /**< machine->Inputs[]/Outputs[] */
- PROGRAM_LOCAL_PARAM, /**< gl_program->LocalParams[] */
- PROGRAM_ENV_PARAM, /**< gl_program->Parameters[] */
- PROGRAM_STATE_VAR, /**< gl_program->Parameters[] */
- PROGRAM_NAMED_PARAM, /**< gl_program->Parameters[] */
- PROGRAM_CONSTANT, /**< gl_program->Parameters[] */
- PROGRAM_UNIFORM, /**< gl_program->Parameters[] */
- PROGRAM_WRITE_ONLY, /**< A dummy, write-only register */
- PROGRAM_ADDRESS, /**< machine->AddressReg */
- PROGRAM_SAMPLER, /**< for shader samplers, compile-time only */
- PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */
- PROGRAM_UNDEFINED, /**< Invalid/TBD value */
- PROGRAM_FILE_MAX
-} gl_register_file;
-
-
-/**
- * If the register file is PROGRAM_SYSTEM_VALUE, the register index will be
- * one of these values.
- */
-typedef enum
-{
- SYSTEM_VALUE_FRONT_FACE, /**< Fragment shader only (not done yet) */
- SYSTEM_VALUE_INSTANCE_ID, /**< Vertex shader only */
- SYSTEM_VALUE_MAX /**< Number of values */
-} gl_system_value;
-
-
-/** Vertex and fragment instructions */
-struct prog_instruction;
-struct gl_program_parameter_list;
-struct gl_uniform_list;
-
-
-/**
- * Base class for any kind of program object
- */
-struct gl_program
-{
- GLuint Id;
- GLubyte *String; /**< Null-terminated program text */
- GLint RefCount;
- GLenum Target; /**< GL_VERTEX/FRAGMENT_PROGRAM_ARB, GL_FRAGMENT_PROGRAM_NV */
- GLenum Format; /**< String encoding format */
- GLboolean Resident;
-
- struct prog_instruction *Instructions;
-
- GLbitfield InputsRead; /**< Bitmask of which input regs are read */
- GLbitfield64 OutputsWritten; /**< Bitmask of which output regs are written */
- GLbitfield SystemValuesRead; /**< Bitmask of SYSTEM_VALUE_x inputs used */
- GLbitfield InputFlags[MAX_PROGRAM_INPUTS]; /**< PROG_PARAM_BIT_x flags */
- GLbitfield OutputFlags[MAX_PROGRAM_OUTPUTS]; /**< PROG_PARAM_BIT_x flags */
- GLbitfield TexturesUsed[MAX_TEXTURE_UNITS]; /**< TEXTURE_x_BIT bitmask */
- GLbitfield SamplersUsed; /**< Bitfield of which samplers are used */
- GLbitfield ShadowSamplers; /**< Texture units used for shadow sampling. */
-
-
- /** Named parameters, constants, etc. from program text */
- struct gl_program_parameter_list *Parameters;
- /** Numbered local parameters */
- GLfloat LocalParams[MAX_PROGRAM_LOCAL_PARAMS][4];
-
- /** Vertex/fragment shader varying vars */
- struct gl_program_parameter_list *Varying;
- /** Vertex program user-defined attributes */
- struct gl_program_parameter_list *Attributes;
-
- /** Map from sampler unit to texture unit (set by glUniform1i()) */
- GLubyte SamplerUnits[MAX_SAMPLERS];
- /** Which texture target is being sampled (TEXTURE_1D/2D/3D/etc_INDEX) */
- gl_texture_index SamplerTargets[MAX_SAMPLERS];
-
- /** Bitmask of which register files are read/written with indirect
- * addressing. Mask of (1 << PROGRAM_x) bits.
- */
- GLbitfield IndirectRegisterFiles;
-
- /** Logical counts */
- /*@{*/
- GLuint NumInstructions;
- GLuint NumTemporaries;
- GLuint NumParameters;
- GLuint NumAttributes;
- GLuint NumAddressRegs;
- GLuint NumAluInstructions;
- GLuint NumTexInstructions;
- GLuint NumTexIndirections;
- /*@}*/
- /** Native, actual h/w counts */
- /*@{*/
- GLuint NumNativeInstructions;
- GLuint NumNativeTemporaries;
- GLuint NumNativeParameters;
- GLuint NumNativeAttributes;
- GLuint NumNativeAddressRegs;
- GLuint NumNativeAluInstructions;
- GLuint NumNativeTexInstructions;
- GLuint NumNativeTexIndirections;
- /*@}*/
-};
-
-
-/** Vertex program object */
-struct gl_vertex_program
-{
- struct gl_program Base; /**< base class */
- GLboolean IsNVProgram; /**< is this a GL_NV_vertex_program program? */
- GLboolean IsPositionInvariant;
-};
-
-
-/** Geometry program object */
-struct gl_geometry_program
-{
- struct gl_program Base; /**< base class */
-
- GLint VerticesOut;
- GLenum InputType; /**< GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_ARB,
- GL_TRIANGLES, or GL_TRIANGLES_ADJACENCY_ARB */
- GLenum OutputType; /**< GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP */
-};
-
-
-/** Fragment program object */
-struct gl_fragment_program
-{
- struct gl_program Base; /**< base class */
- GLenum FogOption;
- GLboolean UsesKill; /**< shader uses KIL instruction */
- GLboolean OriginUpperLeft;
- GLboolean PixelCenterInteger;
- enum gl_frag_depth_layout FragDepthLayout;
-};
-
-
-/**
- * State common to vertex and fragment programs.
- */
-struct gl_program_state
-{
- GLint ErrorPos; /* GL_PROGRAM_ERROR_POSITION_ARB/NV */
- const char *ErrorString; /* GL_PROGRAM_ERROR_STRING_ARB/NV */
-};
-
-
-/**
- * Context state for vertex programs.
- */
-struct gl_vertex_program_state
-{
- GLboolean Enabled; /**< User-set GL_VERTEX_PROGRAM_ARB/NV flag */
- GLboolean _Enabled; /**< Enabled and _valid_ user program? */
- GLboolean PointSizeEnabled; /**< GL_VERTEX_PROGRAM_POINT_SIZE_ARB/NV */
- GLboolean TwoSideEnabled; /**< GL_VERTEX_PROGRAM_TWO_SIDE_ARB/NV */
- struct gl_vertex_program *Current; /**< User-bound vertex program */
-
- /** Currently enabled and valid vertex program (including internal
- * programs, user-defined vertex programs and GLSL vertex shaders).
- * This is the program we must use when rendering.
- */
- struct gl_vertex_program *_Current;
-
- GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
-
- /* For GL_NV_vertex_program only: */
- GLenum TrackMatrix[MAX_PROGRAM_ENV_PARAMS / 4];
- GLenum TrackMatrixTransform[MAX_PROGRAM_ENV_PARAMS / 4];
-
- /** Should fixed-function T&L be implemented with a vertex prog? */
- GLboolean _MaintainTnlProgram;
-
- /** Program to emulate fixed-function T&L (see above) */
- struct gl_vertex_program *_TnlProgram;
-
- /** Cache of fixed-function programs */
- struct gl_program_cache *Cache;
-
- GLboolean _Overriden;
-};
-
-
-/**
- * Context state for geometry programs.
- */
-struct gl_geometry_program_state
-{
- GLboolean Enabled; /**< GL_ARB_GEOMETRY_SHADER4 */
- GLboolean _Enabled; /**< Enabled and valid program? */
- struct gl_geometry_program *Current; /**< user-bound geometry program */
-
- /** Currently enabled and valid program (including internal programs
- * and compiled shader programs).
- */
- struct gl_geometry_program *_Current;
-
- GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
-
- /** Cache of fixed-function programs */
- struct gl_program_cache *Cache;
-};
-
-/**
- * Context state for fragment programs.
- */
-struct gl_fragment_program_state
-{
- GLboolean Enabled; /**< User-set fragment program enable flag */
- GLboolean _Enabled; /**< Enabled and _valid_ user program? */
- struct gl_fragment_program *Current; /**< User-bound fragment program */
-
- /** Currently enabled and valid fragment program (including internal
- * programs, user-defined fragment programs and GLSL fragment shaders).
- * This is the program we must use when rendering.
- */
- struct gl_fragment_program *_Current;
-
- GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
-
- /** Should fixed-function texturing be implemented with a fragment prog? */
- GLboolean _MaintainTexEnvProgram;
-
- /** Program to emulate fixed-function texture env/combine (see above) */
- struct gl_fragment_program *_TexEnvProgram;
-
- /** Cache of fixed-function programs */
- struct gl_program_cache *Cache;
-};
-
-
-/**
- * ATI_fragment_shader runtime state
- */
-#define ATI_FS_INPUT_PRIMARY 0
-#define ATI_FS_INPUT_SECONDARY 1
-
-struct atifs_instruction;
-struct atifs_setupinst;
-
-/**
- * ATI fragment shader
- */
-struct ati_fragment_shader
-{
- GLuint Id;
- GLint RefCount;
- struct atifs_instruction *Instructions[2];
- struct atifs_setupinst *SetupInst[2];
- GLfloat Constants[8][4];
- GLbitfield LocalConstDef; /**< Indicates which constants have been set */
- GLubyte numArithInstr[2];
- GLubyte regsAssigned[2];
- GLubyte NumPasses; /**< 1 or 2 */
- GLubyte cur_pass;
- GLubyte last_optype;
- GLboolean interpinp1;
- GLboolean isValid;
- GLuint swizzlerq;
-};
-
-/**
- * Context state for GL_ATI_fragment_shader
- */
-struct gl_ati_fragment_shader_state
-{
- GLboolean Enabled;
- GLboolean _Enabled; /**< enabled and valid shader? */
- GLboolean Compiling;
- GLfloat GlobalConstants[8][4];
- struct ati_fragment_shader *Current;
-};
-
-
-/**
- * Occlusion/timer query object.
- */
-struct gl_query_object
-{
- GLenum Target; /**< The query target, when active */
- GLuint Id; /**< hash table ID/name */
- GLuint64EXT Result; /**< the counter */
- GLboolean Active; /**< inside Begin/EndQuery */
- GLboolean Ready; /**< result is ready? */
-};
-
-
-/**
- * Context state for query objects.
- */
-struct gl_query_state
-{
- struct _mesa_HashTable *QueryObjects;
- struct gl_query_object *CurrentOcclusionObject; /* GL_ARB_occlusion_query */
- struct gl_query_object *CurrentTimerObject; /* GL_EXT_timer_query */
-
- /** GL_NV_conditional_render */
- struct gl_query_object *CondRenderQuery;
-
- /** GL_EXT_transform_feedback */
- struct gl_query_object *PrimitivesGenerated;
- struct gl_query_object *PrimitivesWritten;
-
- /** GL_ARB_timer_query */
- struct gl_query_object *TimeElapsed;
-
- GLenum CondRenderMode;
-};
-
-
-/** Sync object state */
-struct gl_sync_object {
- struct simple_node link;
- GLenum Type; /**< GL_SYNC_FENCE */
- GLuint Name; /**< Fence name */
- GLint RefCount; /**< Reference count */
- GLboolean DeletePending; /**< Object was deleted while there were still
- * live references (e.g., sync not yet finished)
- */
- GLenum SyncCondition;
- GLbitfield Flags; /**< Flags passed to glFenceSync */
- GLuint StatusFlag:1; /**< Has the sync object been signaled? */
-};
-
-
-/** Set by #pragma directives */
-struct gl_sl_pragmas
-{
- GLboolean IgnoreOptimize; /**< ignore #pragma optimize(on/off) ? */
- GLboolean IgnoreDebug; /**< ignore #pragma debug(on/off) ? */
- GLboolean Optimize; /**< defaults on */
- GLboolean Debug; /**< defaults off */
-};
-
-
-/**
- * A GLSL vertex or fragment shader object.
- */
-struct gl_shader
-{
- GLenum Type; /**< GL_FRAGMENT_SHADER || GL_VERTEX_SHADER || GL_GEOMETRY_SHADER_ARB (first field!) */
- GLuint Name; /**< AKA the handle */
- GLint RefCount; /**< Reference count */
- GLboolean DeletePending;
- GLboolean CompileStatus;
- const GLchar *Source; /**< Source code string */
- GLuint SourceChecksum; /**< for debug/logging purposes */
- struct gl_program *Program; /**< Post-compile assembly code */
- GLchar *InfoLog;
- struct gl_sl_pragmas Pragmas;
-
- unsigned Version; /**< GLSL version used for linking */
-
- struct exec_list *ir;
- struct glsl_symbol_table *symbols;
-
- /** Shaders containing built-in functions that are used for linking. */
- struct gl_shader *builtins_to_link[16];
- unsigned num_builtins_to_link;
-};
-
-
-/**
- * A GLSL program object.
- * Basically a linked collection of vertex and fragment shaders.
- */
-struct gl_shader_program
-{
- GLenum Type; /**< Always GL_SHADER_PROGRAM (internal token) */
- GLuint Name; /**< aka handle or ID */
- GLint RefCount; /**< Reference count */
- GLboolean DeletePending;
-
- GLuint NumShaders; /**< number of attached shaders */
- struct gl_shader **Shaders; /**< List of attached the shaders */
-
- /** User-defined attribute bindings (glBindAttribLocation) */
- struct gl_program_parameter_list *Attributes;
-
- /** Transform feedback varyings */
- struct {
- GLenum BufferMode;
- GLuint NumVarying;
- GLchar **VaryingNames; /**< Array [NumVarying] of char * */
- } TransformFeedback;
-
- /** Geometry shader state - copied into gl_geometry_program at link time */
- struct {
- GLint VerticesOut;
- GLenum InputType; /**< GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_ARB,
- GL_TRIANGLES, or GL_TRIANGLES_ADJACENCY_ARB */
- GLenum OutputType; /**< GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP */
- } Geom;
-
- /* post-link info: */
- struct gl_vertex_program *VertexProgram; /**< Linked vertex program */
- struct gl_fragment_program *FragmentProgram; /**< Linked fragment prog */
- struct gl_geometry_program *GeometryProgram; /**< Linked geometry prog */
- struct gl_uniform_list *Uniforms;
- struct gl_program_parameter_list *Varying;
- GLboolean LinkStatus; /**< GL_LINK_STATUS */
- GLboolean Validated;
- GLboolean _Used; /**< Ever used for drawing? */
- GLchar *InfoLog;
-
- unsigned Version; /**< GLSL version used for linking */
-
- /**
- * Per-stage shaders resulting from the first stage of linking.
- *
- * Set of linked shaders for this program. The array is accessed using the
- * \c MESA_SHADER_* defines. Entries for non-existent stages will be
- * \c NULL.
- */
- struct gl_shader *_LinkedShaders[MESA_SHADER_TYPES];
-};
-
-
-#define GLSL_DUMP 0x1 /**< Dump shaders to stdout */
-#define GLSL_LOG 0x2 /**< Write shaders to files */
-#define GLSL_OPT 0x4 /**< Force optimizations (override pragmas) */
-#define GLSL_NO_OPT 0x8 /**< Force no optimizations (override pragmas) */
-#define GLSL_UNIFORMS 0x10 /**< Print glUniform calls */
-#define GLSL_NOP_VERT 0x20 /**< Force no-op vertex shaders */
-#define GLSL_NOP_FRAG 0x40 /**< Force no-op fragment shaders */
-#define GLSL_USE_PROG 0x80 /**< Log glUseProgram calls */
-
-
-/**
- * Context state for GLSL vertex/fragment shaders.
- */
-struct gl_shader_state
-{
- /**
- * Programs used for rendering
- *
- * There is a separate program set for each shader stage. If
- * GL_EXT_separate_shader_objects is not supported, each of these must point
- * to \c NULL or to the same program.
- */
- struct gl_shader_program *CurrentVertexProgram;
- struct gl_shader_program *CurrentGeometryProgram;
- struct gl_shader_program *CurrentFragmentProgram;
-
- /**
- * Program used by glUniform calls.
- *
- * Explicitly set by \c glUseProgram and \c glActiveProgramEXT.
- */
- struct gl_shader_program *ActiveProgram;
-
- void *MemPool;
-
- GLbitfield Flags; /**< Mask of GLSL_x flags */
-};
-
-/**
- * Compiler options for a single GLSL shaders type
- */
-struct gl_shader_compiler_options
-{
- /** Driver-selectable options: */
- GLboolean EmitCondCodes; /**< Use condition codes? */
- GLboolean EmitNVTempInitialization; /**< 0-fill NV temp registers */
- /**
- * Attempts to flatten all ir_if (OPCODE_IF) for GPUs that can't
- * support control flow.
- */
- GLboolean EmitNoIfs;
- GLboolean EmitNoLoops;
- GLboolean EmitNoFunctions;
- GLboolean EmitNoCont; /**< Emit CONT opcode? */
- GLboolean EmitNoMainReturn; /**< Emit CONT/RET opcodes? */
- GLboolean EmitNoNoise; /**< Emit NOISE opcodes? */
- GLboolean EmitNoPow; /**< Emit POW opcodes? */
-
- /**
- * \name Forms of indirect addressing the driver cannot do.
- */
- /*@{*/
- GLboolean EmitNoIndirectInput; /**< No indirect addressing of inputs */
- GLboolean EmitNoIndirectOutput; /**< No indirect addressing of outputs */
- GLboolean EmitNoIndirectTemp; /**< No indirect addressing of temps */
- GLboolean EmitNoIndirectUniform; /**< No indirect addressing of constants */
- /*@}*/
-
- GLuint MaxUnrollIterations;
-
- struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */
-};
-
-/**
- * Transform feedback object state
- */
-struct gl_transform_feedback_object
-{
- GLuint Name; /**< AKA the object ID */
- GLint RefCount;
- GLboolean Active; /**< Is transform feedback enabled? */
- GLboolean Paused; /**< Is transform feedback paused? */
-
- /** The feedback buffers */
- GLuint BufferNames[MAX_FEEDBACK_ATTRIBS];
- struct gl_buffer_object *Buffers[MAX_FEEDBACK_ATTRIBS];
-
- /** Start of feedback data in dest buffer */
- GLintptr Offset[MAX_FEEDBACK_ATTRIBS];
- /** Max data to put into dest buffer (in bytes) */
- GLsizeiptr Size[MAX_FEEDBACK_ATTRIBS];
-};
-
-
-/**
- * Context state for transform feedback.
- */
-struct gl_transform_feedback
-{
- GLenum Mode; /**< GL_POINTS, GL_LINES or GL_TRIANGLES */
-
- GLboolean RasterDiscard; /**< GL_RASTERIZER_DISCARD */
-
- /** The general binding point (GL_TRANSFORM_FEEDBACK_BUFFER) */
- struct gl_buffer_object *CurrentBuffer;
-
- /** The table of all transform feedback objects */
- struct _mesa_HashTable *Objects;
-
- /** The current xform-fb object (GL_TRANSFORM_FEEDBACK_BINDING) */
- struct gl_transform_feedback_object *CurrentObject;
-
- /** The default xform-fb object (Name==0) */
- struct gl_transform_feedback_object *DefaultObject;
-};
-
-
-
-/**
- * State which can be shared by multiple contexts:
- */
-struct gl_shared_state
-{
- _glthread_Mutex Mutex; /**< for thread safety */
- GLint RefCount; /**< Reference count */
- struct _mesa_HashTable *DisplayList; /**< Display lists hash table */
- struct _mesa_HashTable *TexObjects; /**< Texture objects hash table */
-
- /** Default texture objects (shared by all texture units) */
- struct gl_texture_object *DefaultTex[NUM_TEXTURE_TARGETS];
-
- /** Fallback texture used when a bound texture is incomplete */
- struct gl_texture_object *FallbackTex;
-
- /**
- * \name Thread safety and statechange notification for texture
- * objects.
- *
- * \todo Improve the granularity of locking.
- */
- /*@{*/
- _glthread_Mutex TexMutex; /**< texobj thread safety */
- GLuint TextureStateStamp; /**< state notification for shared tex */
- /*@}*/
-
- /** Default buffer object for vertex arrays that aren't in VBOs */
- struct gl_buffer_object *NullBufferObj;
-
- /**
- * \name Vertex/geometry/fragment programs
- */
- /*@{*/
- struct _mesa_HashTable *Programs; /**< All vertex/fragment programs */
- struct gl_vertex_program *DefaultVertexProgram;
- struct gl_fragment_program *DefaultFragmentProgram;
- struct gl_geometry_program *DefaultGeometryProgram;
- /*@}*/
-
- /* GL_ATI_fragment_shader */
- struct _mesa_HashTable *ATIShaders;
- struct ati_fragment_shader *DefaultFragmentShader;
-
- struct _mesa_HashTable *BufferObjects;
-
- /** Table of both gl_shader and gl_shader_program objects */
- struct _mesa_HashTable *ShaderObjects;
-
- /* GL_EXT_framebuffer_object */
- struct _mesa_HashTable *RenderBuffers;
- struct _mesa_HashTable *FrameBuffers;
-
- /* GL_ARB_sync */
- struct simple_node SyncObjects;
-
- void *DriverData; /**< Device driver shared state */
-};
-
-
-
-
-/**
- * A renderbuffer stores colors or depth values or stencil values.
- * A framebuffer object will have a collection of these.
- * Data are read/written to the buffer with a handful of Get/Put functions.
- *
- * Instances of this object are allocated with the Driver's NewRenderbuffer
- * hook. Drivers will likely wrap this class inside a driver-specific
- * class to simulate inheritance.
- */
-struct gl_renderbuffer
-{
-#define RB_MAGIC 0xaabbccdd
- int Magic; /** XXX TEMPORARY DEBUG INFO */
- _glthread_Mutex Mutex; /**< for thread safety */
- GLuint ClassID; /**< Useful for drivers */
- GLuint Name;
- GLint RefCount;
- GLuint Width, Height;
- GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */
-
- GLenum InternalFormat; /**< The user-specified format */
- GLenum _BaseFormat; /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
- GL_STENCIL_INDEX. */
- gl_format Format; /**< The actual renderbuffer memory format */
-
- GLubyte NumSamples;
-
- GLenum DataType; /**< Type of values passed to the Get/Put functions */
- GLvoid *Data; /**< This may not be used by some kinds of RBs */
-
- /* Used to wrap one renderbuffer around another: */
- struct gl_renderbuffer *Wrapped;
-
- /* Delete this renderbuffer */
- void (*Delete)(struct gl_renderbuffer *rb);
-
- /* Allocate new storage for this renderbuffer */
- GLboolean (*AllocStorage)(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLenum internalFormat,
- GLuint width, GLuint height);
-
- /* Lock/Unlock are called before/after calling the Get/Put functions.
- * Not sure this is the right place for these yet.
- void (*Lock)(struct gl_context *ctx, struct gl_renderbuffer *rb);
- void (*Unlock)(struct gl_context *ctx, struct gl_renderbuffer *rb);
- */
-
- /* Return a pointer to the element/pixel at (x,y).
- * Should return NULL if the buffer memory can't be directly addressed.
- */
- void *(*GetPointer)(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLint x, GLint y);
-
- /* Get/Read a row of values.
- * The values will be of format _BaseFormat and type DataType.
- */
- void (*GetRow)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, void *values);
-
- /* Get/Read values at arbitrary locations.
- * The values will be of format _BaseFormat and type DataType.
- */
- void (*GetValues)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], void *values);
-
- /* Put/Write a row of values.
- * The values will be of format _BaseFormat and type DataType.
- */
- void (*PutRow)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask);
-
- /* Put/Write a row of RGB values. This is a special-case routine that's
- * only used for RGBA renderbuffers when the source data is GL_RGB. That's
- * a common case for glDrawPixels and some triangle routines.
- * The values will be of format GL_RGB and type DataType.
- */
- void (*PutRowRGB)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *values, const GLubyte *mask);
-
-
- /* Put/Write a row of identical values.
- * The values will be of format _BaseFormat and type DataType.
- */
- void (*PutMonoRow)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- GLint x, GLint y, const void *value, const GLubyte *mask);
-
- /* Put/Write values at arbitrary locations.
- * The values will be of format _BaseFormat and type DataType.
- */
- void (*PutValues)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
- const GLint x[], const GLint y[], const void *values,
- const GLubyte *mask);
- /* Put/Write identical values at arbitrary locations.
- * The values will be of format _BaseFormat and type DataType.
- */
- void (*PutMonoValues)(struct gl_context *ctx, struct gl_renderbuffer *rb,
- GLuint count, const GLint x[], const GLint y[],
- const void *value, const GLubyte *mask);
-};
-
-
-/**
- * A renderbuffer attachment points to either a texture object (and specifies
- * a mipmap level, cube face or 3D texture slice) or points to a renderbuffer.
- */
-struct gl_renderbuffer_attachment
-{
- GLenum Type; /**< \c GL_NONE or \c GL_TEXTURE or \c GL_RENDERBUFFER_EXT */
- GLboolean Complete;
-
- /**
- * If \c Type is \c GL_RENDERBUFFER_EXT, this stores a pointer to the
- * application supplied renderbuffer object.
- */
- struct gl_renderbuffer *Renderbuffer;
-
- /**
- * If \c Type is \c GL_TEXTURE, this stores a pointer to the application
- * supplied texture object.
- */
- struct gl_texture_object *Texture;
- GLuint TextureLevel; /**< Attached mipmap level. */
- GLuint CubeMapFace; /**< 0 .. 5, for cube map textures. */
- GLuint Zoffset; /**< Slice for 3D textures, or layer for both 1D
- * and 2D array textures */
-};
-
-
-/**
- * A framebuffer is a collection of renderbuffers (color, depth, stencil, etc).
- * In C++ terms, think of this as a base class from which device drivers
- * will make derived classes.
- */
-struct gl_framebuffer
-{
- _glthread_Mutex Mutex; /**< for thread safety */
- /**
- * If zero, this is a window system framebuffer. If non-zero, this
- * is a FBO framebuffer; note that for some devices (i.e. those with
- * a natural pixel coordinate system for FBOs that differs from the
- * OpenGL/Mesa coordinate system), this means that the viewport,
- * polygon face orientation, and polygon stipple will have to be inverted.
- */
- GLuint Name;
-
- GLint RefCount;
- GLboolean DeletePending;
-
- /**
- * The framebuffer's visual. Immutable if this is a window system buffer.
- * Computed from attachments if user-made FBO.
- */
- struct gl_config Visual;
-
- GLboolean Initialized;
-
- GLuint Width, Height; /**< size of frame buffer in pixels */
-
- /** \name Drawing bounds (Intersection of buffer size and scissor box) */
- /*@{*/
- GLint _Xmin, _Xmax; /**< inclusive */
- GLint _Ymin, _Ymax; /**< exclusive */
- /*@}*/
-
- /** \name Derived Z buffer stuff */
- /*@{*/
- GLuint _DepthMax; /**< Max depth buffer value */
- GLfloat _DepthMaxF; /**< Float max depth buffer value */
- GLfloat _MRD; /**< minimum resolvable difference in Z values */
- /*@}*/
-
- /** One of the GL_FRAMEBUFFER_(IN)COMPLETE_* tokens */
- GLenum _Status;
-
- /** Integer color values */
- GLboolean _IntegerColor;
-
- /** Array of all renderbuffer attachments, indexed by BUFFER_* tokens. */
- struct gl_renderbuffer_attachment Attachment[BUFFER_COUNT];
-
- /* In unextended OpenGL these vars are part of the GL_COLOR_BUFFER
- * attribute group and GL_PIXEL attribute group, respectively.
- */
- GLenum ColorDrawBuffer[MAX_DRAW_BUFFERS];
- GLenum ColorReadBuffer;
-
- /** Computed from ColorDraw/ReadBuffer above */
- GLuint _NumColorDrawBuffers;
- GLint _ColorDrawBufferIndexes[MAX_DRAW_BUFFERS]; /**< BUFFER_x or -1 */
- GLint _ColorReadBufferIndex; /* -1 = None */
- struct gl_renderbuffer *_ColorDrawBuffers[MAX_DRAW_BUFFERS];
- struct gl_renderbuffer *_ColorReadBuffer;
-
- /** The Actual depth/stencil buffers to use. May be wrappers around the
- * depth/stencil buffers attached above. */
- struct gl_renderbuffer *_DepthBuffer;
- struct gl_renderbuffer *_StencilBuffer;
-
- /** Delete this framebuffer */
- void (*Delete)(struct gl_framebuffer *fb);
-};
-
-
-/**
- * Precision info for shader datatypes. See glGetShaderPrecisionFormat().
- */
-struct gl_precision
-{
- GLushort RangeMin; /**< min value exponent */
- GLushort RangeMax; /**< max value exponent */
- GLushort Precision; /**< number of mantissa bits */
-};
-
-
-/**
- * Limits for vertex and fragment programs/shaders.
- */
-struct gl_program_constants
-{
- /* logical limits */
- GLuint MaxInstructions;
- GLuint MaxAluInstructions;
- GLuint MaxTexInstructions;
- GLuint MaxTexIndirections;
- GLuint MaxAttribs;
- GLuint MaxTemps;
- GLuint MaxAddressRegs;
- GLuint MaxParameters;
- GLuint MaxLocalParams;
- GLuint MaxEnvParams;
- /* native/hardware limits */
- GLuint MaxNativeInstructions;
- GLuint MaxNativeAluInstructions;
- GLuint MaxNativeTexInstructions;
- GLuint MaxNativeTexIndirections;
- GLuint MaxNativeAttribs;
- GLuint MaxNativeTemps;
- GLuint MaxNativeAddressRegs;
- GLuint MaxNativeParameters;
- /* For shaders */
- GLuint MaxUniformComponents;
- /* GL_ARB_geometry_shader4 */
- GLuint MaxGeometryTextureImageUnits;
- GLuint MaxGeometryVaryingComponents;
- GLuint MaxVertexVaryingComponents;
- GLuint MaxGeometryUniformComponents;
- GLuint MaxGeometryOutputVertices;
- GLuint MaxGeometryTotalOutputComponents;
- /* ES 2.0 and GL_ARB_ES2_compatibility */
- struct gl_precision LowFloat, MediumFloat, HighFloat;
- struct gl_precision LowInt, MediumInt, HighInt;
-};
-
-
-/**
- * Constants which may be overridden by device driver during context creation
- * but are never changed after that.
- */
-struct gl_constants
-{
- GLint MaxTextureMbytes; /**< Max memory per image, in MB */
- GLint MaxTextureLevels; /**< Max mipmap levels. */
- GLint Max3DTextureLevels; /**< Max mipmap levels for 3D textures */
- GLint MaxCubeTextureLevels; /**< Max mipmap levels for cube textures */
- GLint MaxArrayTextureLayers; /**< Max layers in array textures */
- GLint MaxTextureRectSize; /**< Max rectangle texture size, in pixes */
- GLuint MaxTextureCoordUnits;
- GLuint MaxTextureImageUnits;
- GLuint MaxVertexTextureImageUnits;
- GLuint MaxCombinedTextureImageUnits;
- GLuint MaxTextureUnits; /**< = MIN(CoordUnits, ImageUnits) */
- GLfloat MaxTextureMaxAnisotropy; /**< GL_EXT_texture_filter_anisotropic */
- GLfloat MaxTextureLodBias; /**< GL_EXT_texture_lod_bias */
-
- GLuint MaxArrayLockSize;
-
- GLint SubPixelBits;
-
- GLfloat MinPointSize, MaxPointSize; /**< aliased */
- GLfloat MinPointSizeAA, MaxPointSizeAA; /**< antialiased */
- GLfloat PointSizeGranularity;
- GLfloat MinLineWidth, MaxLineWidth; /**< aliased */
- GLfloat MinLineWidthAA, MaxLineWidthAA; /**< antialiased */
- GLfloat LineWidthGranularity;
-
- GLuint MaxColorTableSize;
-
- GLuint MaxClipPlanes;
- GLuint MaxLights;
- GLfloat MaxShininess; /**< GL_NV_light_max_exponent */
- GLfloat MaxSpotExponent; /**< GL_NV_light_max_exponent */
-
- GLuint MaxViewportWidth, MaxViewportHeight;
-
- struct gl_program_constants VertexProgram; /**< GL_ARB_vertex_program */
- struct gl_program_constants FragmentProgram; /**< GL_ARB_fragment_program */
- struct gl_program_constants GeometryProgram; /**< GL_ARB_geometry_shader4 */
- GLuint MaxProgramMatrices;
- GLuint MaxProgramMatrixStackDepth;
-
- /** vertex array / buffer object bounds checking */
- GLboolean CheckArrayBounds;
-
- GLuint MaxDrawBuffers; /**< GL_ARB_draw_buffers */
-
- GLuint MaxColorAttachments; /**< GL_EXT_framebuffer_object */
- GLuint MaxRenderbufferSize; /**< GL_EXT_framebuffer_object */
- GLuint MaxSamples; /**< GL_ARB_framebuffer_object */
-
- GLuint MaxVarying; /**< Number of float[4] varying parameters */
-
- GLuint GLSLVersion; /**< GLSL version supported (ex: 120 = 1.20) */
-
- /** Which texture units support GL_ATI_envmap_bumpmap as targets */
- GLbitfield SupportedBumpUnits;
-
- /**
- * Maximum amount of time, measured in nanseconds, that the server can wait.
- */
- GLuint64 MaxServerWaitTimeout;
-
- /** GL_EXT_provoking_vertex */
- GLboolean QuadsFollowProvokingVertexConvention;
-
- /** OpenGL version 3.0 */
- GLbitfield ContextFlags; /**< Ex: GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT */
-
- /** OpenGL version 3.2 */
- GLbitfield ProfileMask; /**< Mask of CONTEXT_x_PROFILE_BIT */
-
- /** GL_EXT_transform_feedback */
- GLuint MaxTransformFeedbackSeparateAttribs;
- GLuint MaxTransformFeedbackSeparateComponents;
- GLuint MaxTransformFeedbackInterleavedComponents;
-
- /** GL_EXT_gpu_shader4 */
- GLint MinProgramTexelOffset, MaxProgramTexelOffset;
-
- /* GL_EXT_framebuffer_sRGB */
- GLboolean sRGBCapable; /* can enable sRGB blend/update on FBOs */
-};
-
-
-/**
- * Enable flag for each OpenGL extension. Different device drivers will
- * enable different extensions at runtime.
- */
-struct gl_extensions
-{
- GLboolean dummy; /* don't remove this! */
- GLboolean dummy_true; /* Set true by _mesa_init_extensions(). */
- GLboolean dummy_false; /* Set false by _mesa_init_extensions(). */
- GLboolean ARB_ES2_compatibility;
- GLboolean ARB_blend_func_extended;
- GLboolean ARB_copy_buffer;
- GLboolean ARB_depth_buffer_float;
- GLboolean ARB_depth_clamp;
- GLboolean ARB_depth_texture;
- GLboolean ARB_draw_buffers;
- GLboolean ARB_draw_buffers_blend;
- GLboolean ARB_draw_elements_base_vertex;
- GLboolean ARB_draw_instanced;
- GLboolean ARB_fragment_coord_conventions;
- GLboolean ARB_fragment_program;
- GLboolean ARB_fragment_program_shadow;
- GLboolean ARB_fragment_shader;
- GLboolean ARB_framebuffer_object;
- GLboolean ARB_explicit_attrib_location;
- GLboolean ARB_geometry_shader4;
- GLboolean ARB_half_float_pixel;
- GLboolean ARB_half_float_vertex;
- GLboolean ARB_instanced_arrays;
- GLboolean ARB_map_buffer_range;
- GLboolean ARB_multisample;
- GLboolean ARB_multitexture;
- GLboolean ARB_occlusion_query;
- GLboolean ARB_occlusion_query2;
- GLboolean ARB_point_sprite;
- GLboolean ARB_sampler_objects;
- GLboolean ARB_seamless_cube_map;
- GLboolean ARB_shader_objects;
- GLboolean ARB_shader_stencil_export;
- GLboolean ARB_shading_language_100;
- GLboolean ARB_shadow;
- GLboolean ARB_shadow_ambient;
- GLboolean ARB_sync;
- GLboolean ARB_texture_border_clamp;
- GLboolean ARB_texture_buffer_object;
- GLboolean ARB_texture_compression;
- GLboolean ARB_texture_compression_rgtc;
- GLboolean ARB_texture_cube_map;
- GLboolean ARB_texture_env_combine;
- GLboolean ARB_texture_env_crossbar;
- GLboolean ARB_texture_env_dot3;
- GLboolean ARB_texture_float;
- GLboolean ARB_texture_mirrored_repeat;
- GLboolean ARB_texture_multisample;
- GLboolean ARB_texture_non_power_of_two;
- GLboolean ARB_texture_rg;
- GLboolean ARB_texture_rgb10_a2ui;
- GLboolean ARB_timer_query;
- GLboolean ARB_transform_feedback2;
- GLboolean ARB_transpose_matrix;
- GLboolean ARB_uniform_buffer_object;
- GLboolean ARB_vertex_array_object;
- GLboolean ARB_vertex_buffer_object;
- GLboolean ARB_vertex_program;
- GLboolean ARB_vertex_shader;
- GLboolean ARB_vertex_type_2_10_10_10_rev;
- GLboolean ARB_window_pos;
- GLboolean EXT_abgr;
- GLboolean EXT_bgra;
- GLboolean EXT_blend_color;
- GLboolean EXT_blend_equation_separate;
- GLboolean EXT_blend_func_separate;
- GLboolean EXT_blend_logic_op;
- GLboolean EXT_blend_minmax;
- GLboolean EXT_blend_subtract;
- GLboolean EXT_clip_volume_hint;
- GLboolean EXT_compiled_vertex_array;
- GLboolean EXT_copy_texture;
- GLboolean EXT_depth_bounds_test;
- GLboolean EXT_draw_buffers2;
- GLboolean EXT_draw_range_elements;
- GLboolean EXT_fog_coord;
- GLboolean EXT_framebuffer_blit;
- GLboolean EXT_framebuffer_multisample;
- GLboolean EXT_framebuffer_object;
- GLboolean EXT_framebuffer_sRGB;
- GLboolean EXT_gpu_program_parameters;
- GLboolean EXT_gpu_shader4;
- GLboolean EXT_multi_draw_arrays;
- GLboolean EXT_paletted_texture;
- GLboolean EXT_packed_depth_stencil;
- GLboolean EXT_packed_float;
- GLboolean EXT_packed_pixels;
- GLboolean EXT_pixel_buffer_object;
- GLboolean EXT_point_parameters;
- GLboolean EXT_polygon_offset;
- GLboolean EXT_provoking_vertex;
- GLboolean EXT_rescale_normal;
- GLboolean EXT_shadow_funcs;
- GLboolean EXT_secondary_color;
- GLboolean EXT_separate_shader_objects;
- GLboolean EXT_separate_specular_color;
- GLboolean EXT_shared_texture_palette;
- GLboolean EXT_stencil_wrap;
- GLboolean EXT_stencil_two_side;
- GLboolean EXT_subtexture;
- GLboolean EXT_texture;
- GLboolean EXT_texture_object;
- GLboolean EXT_texture3D;
- GLboolean EXT_texture_array;
- GLboolean EXT_texture_compression_s3tc;
- GLboolean EXT_texture_env_add;
- GLboolean EXT_texture_env_combine;
- GLboolean EXT_texture_env_dot3;
- GLboolean EXT_texture_filter_anisotropic;
- GLboolean EXT_texture_integer;
- GLboolean EXT_texture_lod_bias;
- GLboolean EXT_texture_mirror_clamp;
- GLboolean EXT_texture_shared_exponent;
- GLboolean EXT_texture_sRGB;
- GLboolean EXT_texture_sRGB_decode;
- GLboolean EXT_texture_swizzle;
- GLboolean EXT_transform_feedback;
- GLboolean EXT_timer_query;
- GLboolean EXT_vertex_array;
- GLboolean EXT_vertex_array_bgra;
- GLboolean EXT_vertex_array_set;
- GLboolean OES_standard_derivatives;
- /* vendor extensions */
- GLboolean AMD_conservative_depth;
- GLboolean APPLE_client_storage;
- GLboolean APPLE_packed_pixels;
- GLboolean APPLE_vertex_array_object;
- GLboolean APPLE_object_purgeable;
- GLboolean ATI_envmap_bumpmap;
- GLboolean ATI_texture_mirror_once;
- GLboolean ATI_texture_env_combine3;
- GLboolean ATI_fragment_shader;
- GLboolean ATI_separate_stencil;
- GLboolean IBM_rasterpos_clip;
- GLboolean IBM_multimode_draw_arrays;
- GLboolean MESA_pack_invert;
- GLboolean MESA_resize_buffers;
- GLboolean MESA_ycbcr_texture;
- GLboolean MESA_texture_array;
- GLboolean MESA_texture_signed_rgba;
- GLboolean NV_blend_square;
- GLboolean NV_conditional_render;
- GLboolean NV_fragment_program;
- GLboolean NV_fragment_program_option;
- GLboolean NV_light_max_exponent;
- GLboolean NV_point_sprite;
- GLboolean NV_primitive_restart;
- GLboolean NV_texgen_reflection;
- GLboolean NV_texture_env_combine4;
- GLboolean NV_texture_rectangle;
- GLboolean NV_vertex_program;
- GLboolean NV_vertex_program1_1;
- GLboolean OES_read_format;
- GLboolean SGIS_generate_mipmap;
- GLboolean SGIS_texture_edge_clamp;
- GLboolean SGIS_texture_lod;
- GLboolean TDFX_texture_compression_FXT1;
- GLboolean S3_s3tc;
- GLboolean OES_EGL_image;
- GLboolean OES_draw_texture;
- GLboolean EXT_texture_format_BGRA8888;
- GLboolean extension_sentinel;
- /** The extension string */
- const GLubyte *String;
- /** Number of supported extensions */
- GLuint Count;
-};
-
-
-/**
- * A stack of matrices (projection, modelview, color, texture, etc).
- */
-struct gl_matrix_stack
-{
- GLmatrix *Top; /**< points into Stack */
- GLmatrix *Stack; /**< array [MaxDepth] of GLmatrix */
- GLuint Depth; /**< 0 <= Depth < MaxDepth */
- GLuint MaxDepth; /**< size of Stack[] array */
- GLuint DirtyFlag; /**< _NEW_MODELVIEW or _NEW_PROJECTION, for example */
-};
-
-
-/**
- * \name Bits for image transfer operations
- * \sa __struct gl_contextRec::ImageTransferState.
- */
-/*@{*/
-#define IMAGE_SCALE_BIAS_BIT 0x1
-#define IMAGE_SHIFT_OFFSET_BIT 0x2
-#define IMAGE_MAP_COLOR_BIT 0x4
-#define IMAGE_CLAMP_BIT 0x800
-
-
-/** Pixel Transfer ops */
-#define IMAGE_BITS (IMAGE_SCALE_BIAS_BIT | \
- IMAGE_SHIFT_OFFSET_BIT | \
- IMAGE_MAP_COLOR_BIT)
-
-/**
- * \name Bits to indicate what state has changed.
- */
-/*@{*/
-#define _NEW_MODELVIEW (1 << 0) /**< gl_context::ModelView */
-#define _NEW_PROJECTION (1 << 1) /**< gl_context::Projection */
-#define _NEW_TEXTURE_MATRIX (1 << 2) /**< gl_context::TextureMatrix */
-#define _NEW_COLOR (1 << 3) /**< gl_context::Color */
-#define _NEW_DEPTH (1 << 4) /**< gl_context::Depth */
-#define _NEW_EVAL (1 << 5) /**< gl_context::Eval, EvalMap */
-#define _NEW_FOG (1 << 6) /**< gl_context::Fog */
-#define _NEW_HINT (1 << 7) /**< gl_context::Hint */
-#define _NEW_LIGHT (1 << 8) /**< gl_context::Light */
-#define _NEW_LINE (1 << 9) /**< gl_context::Line */
-#define _NEW_PIXEL (1 << 10) /**< gl_context::Pixel */
-#define _NEW_POINT (1 << 11) /**< gl_context::Point */
-#define _NEW_POLYGON (1 << 12) /**< gl_context::Polygon */
-#define _NEW_POLYGONSTIPPLE (1 << 13) /**< gl_context::PolygonStipple */
-#define _NEW_SCISSOR (1 << 14) /**< gl_context::Scissor */
-#define _NEW_STENCIL (1 << 15) /**< gl_context::Stencil */
-#define _NEW_TEXTURE (1 << 16) /**< gl_context::Texture */
-#define _NEW_TRANSFORM (1 << 17) /**< gl_context::Transform */
-#define _NEW_VIEWPORT (1 << 18) /**< gl_context::Viewport */
-#define _NEW_PACKUNPACK (1 << 19) /**< gl_context::Pack, Unpack */
-#define _NEW_ARRAY (1 << 20) /**< gl_context::Array */
-#define _NEW_RENDERMODE (1 << 21) /**< gl_context::RenderMode, etc */
-#define _NEW_BUFFERS (1 << 22) /**< gl_context::Visual, DrawBuffer, */
-#define _NEW_CURRENT_ATTRIB (1 << 23) /**< gl_context::Current */
-#define _NEW_MULTISAMPLE (1 << 24) /**< gl_context::Multisample */
-#define _NEW_TRACK_MATRIX (1 << 25) /**< gl_context::VertexProgram */
-#define _NEW_PROGRAM (1 << 26) /**< New program/shader state */
-#define _NEW_PROGRAM_CONSTANTS (1 << 27)
-#define _NEW_BUFFER_OBJECT (1 << 28)
-#define _NEW_ALL ~0
-/*@}*/
-
-
-/**
- * \name Bits to track array state changes
- *
- * Also used to summarize array enabled.
- */
-/*@{*/
-#define _NEW_ARRAY_VERTEX VERT_BIT_POS
-#define _NEW_ARRAY_WEIGHT VERT_BIT_WEIGHT
-#define _NEW_ARRAY_NORMAL VERT_BIT_NORMAL
-#define _NEW_ARRAY_COLOR0 VERT_BIT_COLOR0
-#define _NEW_ARRAY_COLOR1 VERT_BIT_COLOR1
-#define _NEW_ARRAY_FOGCOORD VERT_BIT_FOG
-#define _NEW_ARRAY_INDEX VERT_BIT_COLOR_INDEX
-#define _NEW_ARRAY_EDGEFLAG VERT_BIT_EDGEFLAG
-#define _NEW_ARRAY_POINT_SIZE VERT_BIT_COLOR_INDEX /* aliased */
-#define _NEW_ARRAY_TEXCOORD_0 VERT_BIT_TEX0
-#define _NEW_ARRAY_TEXCOORD_1 VERT_BIT_TEX1
-#define _NEW_ARRAY_TEXCOORD_2 VERT_BIT_TEX2
-#define _NEW_ARRAY_TEXCOORD_3 VERT_BIT_TEX3
-#define _NEW_ARRAY_TEXCOORD_4 VERT_BIT_TEX4
-#define _NEW_ARRAY_TEXCOORD_5 VERT_BIT_TEX5
-#define _NEW_ARRAY_TEXCOORD_6 VERT_BIT_TEX6
-#define _NEW_ARRAY_TEXCOORD_7 VERT_BIT_TEX7
-#define _NEW_ARRAY_ATTRIB_0 VERT_BIT_GENERIC0 /* start at bit 16 */
-#define _NEW_ARRAY_ALL 0xffffffff
-
-
-#define _NEW_ARRAY_TEXCOORD(i) (_NEW_ARRAY_TEXCOORD_0 << (i))
-#define _NEW_ARRAY_ATTRIB(i) (_NEW_ARRAY_ATTRIB_0 << (i))
-/*@}*/
-
-
-
-/**
- * \name A bunch of flags that we think might be useful to drivers.
- *
- * Set in the __struct gl_contextRec::_TriangleCaps bitfield.
- */
-/*@{*/
-#define DD_FLATSHADE 0x1
-#define DD_SEPARATE_SPECULAR 0x2
-#define DD_TRI_CULL_FRONT_BACK 0x4 /* special case on some hw */
-#define DD_TRI_LIGHT_TWOSIDE 0x8
-#define DD_TRI_UNFILLED 0x10
-#define DD_TRI_SMOOTH 0x20
-#define DD_TRI_STIPPLE 0x40
-#define DD_TRI_OFFSET 0x80
-#define DD_LINE_SMOOTH 0x100
-#define DD_LINE_STIPPLE 0x200
-#define DD_POINT_SMOOTH 0x400
-#define DD_POINT_ATTEN 0x800
-#define DD_TRI_TWOSTENCIL 0x1000
-/*@}*/
-
-
-/**
- * \name Define the state changes under which each of these bits might change
- */
-/*@{*/
-#define _DD_NEW_FLATSHADE _NEW_LIGHT
-#define _DD_NEW_SEPARATE_SPECULAR (_NEW_LIGHT | _NEW_FOG | _NEW_PROGRAM)
-#define _DD_NEW_TRI_CULL_FRONT_BACK _NEW_POLYGON
-#define _DD_NEW_TRI_LIGHT_TWOSIDE _NEW_LIGHT
-#define _DD_NEW_TRI_UNFILLED _NEW_POLYGON
-#define _DD_NEW_TRI_SMOOTH _NEW_POLYGON
-#define _DD_NEW_TRI_STIPPLE _NEW_POLYGON
-#define _DD_NEW_TRI_OFFSET _NEW_POLYGON
-#define _DD_NEW_LINE_SMOOTH _NEW_LINE
-#define _DD_NEW_LINE_STIPPLE _NEW_LINE
-#define _DD_NEW_LINE_WIDTH _NEW_LINE
-#define _DD_NEW_POINT_SMOOTH _NEW_POINT
-#define _DD_NEW_POINT_SIZE _NEW_POINT
-#define _DD_NEW_POINT_ATTEN _NEW_POINT
-/*@}*/
-
-
-/**
- * Composite state flags
- */
-/*@{*/
-#define _MESA_NEW_NEED_EYE_COORDS (_NEW_LIGHT | \
- _NEW_TEXTURE | \
- _NEW_POINT | \
- _NEW_PROGRAM | \
- _NEW_MODELVIEW)
-
-#define _MESA_NEW_NEED_NORMALS (_NEW_LIGHT | \
- _NEW_TEXTURE)
-
-#define _MESA_NEW_TRANSFER_STATE (_NEW_PIXEL)
-/*@}*/
-
-
-
-
-/* This has to be included here. */
-#include "dd.h"
-
-
-/**
- * Display list flags.
- * Strictly this is a tnl-private concept, but it doesn't seem
- * worthwhile adding a tnl private structure just to hold this one bit
- * of information:
- */
-#define DLIST_DANGLING_REFS 0x1
-
-
-/** Opaque declaration of display list payload data type */
-union gl_dlist_node;
-
-
-/**
- * Provide a location where information about a display list can be
- * collected. Could be extended with driverPrivate structures,
- * etc. in the future.
- */
-struct gl_display_list
-{
- GLuint Name;
- GLbitfield Flags; /**< DLIST_x flags */
- /** The dlist commands are in a linked list of nodes */
- union gl_dlist_node *Head;
-};
-
-
-/**
- * State used during display list compilation and execution.
- */
-struct gl_dlist_state
-{
- GLuint CallDepth; /**< Current recursion calling depth */
-
- struct gl_display_list *CurrentList; /**< List currently being compiled */
- union gl_dlist_node *CurrentBlock; /**< Pointer to current block of nodes */
- GLuint CurrentPos; /**< Index into current block of nodes */
-
- GLvertexformat ListVtxfmt;
-
- GLubyte ActiveAttribSize[VERT_ATTRIB_MAX];
- GLfloat CurrentAttrib[VERT_ATTRIB_MAX][4];
-
- GLubyte ActiveMaterialSize[MAT_ATTRIB_MAX];
- GLfloat CurrentMaterial[MAT_ATTRIB_MAX][4];
-
- GLubyte ActiveIndex;
- GLfloat CurrentIndex;
-
- GLubyte ActiveEdgeFlag;
- GLboolean CurrentEdgeFlag;
-
- struct {
- /* State known to have been set by the currently-compiling display
- * list. Used to eliminate some redundant state changes.
- */
- GLenum ShadeModel;
- } Current;
-};
-
-
-/**
- * Enum for the OpenGL APIs we know about and may support.
- */
-typedef enum
-{
- API_OPENGL,
- API_OPENGLES,
- API_OPENGLES2
-} gl_api;
-
-
-/**
- * Mesa rendering context.
- *
- * This is the central context data structure for Mesa. Almost all
- * OpenGL state is contained in this structure.
- * Think of this as a base class from which device drivers will derive
- * sub classes.
- *
- * The struct gl_context typedef names this structure.
- */
-struct gl_context
-{
- /** State possibly shared with other contexts in the address space */
- struct gl_shared_state *Shared;
-
- /** \name API function pointer tables */
- /*@{*/
- gl_api API;
- struct _glapi_table *Save; /**< Display list save functions */
- struct _glapi_table *Exec; /**< Execute functions */
- struct _glapi_table *CurrentDispatch; /**< == Save or Exec !! */
- /*@}*/
-
- struct gl_config Visual;
- struct gl_framebuffer *DrawBuffer; /**< buffer for writing */
- struct gl_framebuffer *ReadBuffer; /**< buffer for reading */
- struct gl_framebuffer *WinSysDrawBuffer; /**< set with MakeCurrent */
- struct gl_framebuffer *WinSysReadBuffer; /**< set with MakeCurrent */
-
- /**
- * Device driver function pointer table
- */
- struct dd_function_table Driver;
-
- void *DriverCtx; /**< Points to device driver context/state */
-
- /** Core/Driver constants */
- struct gl_constants Const;
-
- /** \name The various 4x4 matrix stacks */
- /*@{*/
- struct gl_matrix_stack ModelviewMatrixStack;
- struct gl_matrix_stack ProjectionMatrixStack;
- struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_UNITS];
- struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
- struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */
- /*@}*/
-
- /** Combined modelview and projection matrix */
- GLmatrix _ModelProjectMatrix;
-
- /** \name Display lists */
- struct gl_dlist_state ListState;
-
- GLboolean ExecuteFlag; /**< Execute GL commands? */
- GLboolean CompileFlag; /**< Compile GL commands into display list? */
-
- /** Extension information */
- struct gl_extensions Extensions;
-
- /** Version info */
- GLuint VersionMajor, VersionMinor;
- char *VersionString;
-
- /** \name State attribute stack (for glPush/PopAttrib) */
- /*@{*/
- GLuint AttribStackDepth;
- struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
- /*@}*/
-
- /** \name Renderer attribute groups
- *
- * We define a struct for each attribute group to make pushing and popping
- * attributes easy. Also it's a good organization.
- */
- /*@{*/
- struct gl_accum_attrib Accum; /**< Accum buffer attributes */
- struct gl_colorbuffer_attrib Color; /**< Color buffer attributes */
- struct gl_current_attrib Current; /**< Current attributes */
- struct gl_depthbuffer_attrib Depth; /**< Depth buffer attributes */
- struct gl_eval_attrib Eval; /**< Eval attributes */
- struct gl_fog_attrib Fog; /**< Fog attributes */
- struct gl_hint_attrib Hint; /**< Hint attributes */
- struct gl_light_attrib Light; /**< Light attributes */
- struct gl_line_attrib Line; /**< Line attributes */
- struct gl_list_attrib List; /**< List attributes */
- struct gl_multisample_attrib Multisample;
- struct gl_pixel_attrib Pixel; /**< Pixel attributes */
- struct gl_point_attrib Point; /**< Point attributes */
- struct gl_polygon_attrib Polygon; /**< Polygon attributes */
- GLuint PolygonStipple[32]; /**< Polygon stipple */
- struct gl_scissor_attrib Scissor; /**< Scissor attributes */
- struct gl_stencil_attrib Stencil; /**< Stencil buffer attributes */
- struct gl_texture_attrib Texture; /**< Texture attributes */
- struct gl_transform_attrib Transform; /**< Transformation attributes */
- struct gl_viewport_attrib Viewport; /**< Viewport attributes */
- /*@}*/
-
- /** \name Client attribute stack */
- /*@{*/
- GLuint ClientAttribStackDepth;
- struct gl_attrib_node *ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH];
- /*@}*/
-
- /** \name Client attribute groups */
- /*@{*/
- struct gl_array_attrib Array; /**< Vertex arrays */
- struct gl_pixelstore_attrib Pack; /**< Pixel packing */
- struct gl_pixelstore_attrib Unpack; /**< Pixel unpacking */
- struct gl_pixelstore_attrib DefaultPacking; /**< Default params */
- /*@}*/
-
- /** \name Other assorted state (not pushed/popped on attribute stack) */
- /*@{*/
- struct gl_pixelmaps PixelMaps;
-
- struct gl_evaluators EvalMap; /**< All evaluators */
- struct gl_feedback Feedback; /**< Feedback */
- struct gl_selection Select; /**< Selection */
-
- struct gl_program_state Program; /**< general program state */
- struct gl_vertex_program_state VertexProgram;
- struct gl_fragment_program_state FragmentProgram;
- struct gl_geometry_program_state GeometryProgram;
- struct gl_ati_fragment_shader_state ATIFragmentShader;
-
- struct gl_shader_state Shader; /**< GLSL shader object state */
- struct gl_shader_compiler_options ShaderCompilerOptions[MESA_SHADER_TYPES];
-
- struct gl_query_state Query; /**< occlusion, timer queries */
-
- struct gl_transform_feedback TransformFeedback;
-
- struct gl_buffer_object *CopyReadBuffer; /**< GL_ARB_copy_buffer */
- struct gl_buffer_object *CopyWriteBuffer; /**< GL_ARB_copy_buffer */
- /*@}*/
-
- struct gl_meta_state *Meta; /**< for "meta" operations */
-
- /* GL_EXT_framebuffer_object */
- struct gl_renderbuffer *CurrentRenderbuffer;
-
- GLenum ErrorValue; /**< Last error code */
-
- /**
- * Recognize and silence repeated error debug messages in buggy apps.
- */
- const char *ErrorDebugFmtString;
- GLuint ErrorDebugCount;
-
- GLenum RenderMode; /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
- GLbitfield NewState; /**< bitwise-or of _NEW_* flags */
-
- GLboolean ViewportInitialized; /**< has viewport size been initialized? */
-
- GLbitfield varying_vp_inputs; /**< mask of VERT_BIT_* flags */
-
- /** \name Derived state */
- /*@{*/
- /** Bitwise-or of DD_* flags. Note that this bitfield may be used before
- * state validation so they need to always be current.
- */
- GLbitfield _TriangleCaps;
- GLbitfield _ImageTransferState;/**< bitwise-or of IMAGE_*_BIT flags */
- GLfloat _EyeZDir[3];
- GLfloat _ModelViewInvScale;
- GLboolean _NeedEyeCoords;
- GLboolean _ForceEyeCoords;
-
- GLuint TextureStateTimestamp; /**< detect changes to shared state */
-
- struct gl_shine_tab *_ShineTable[2]; /**< Active shine tables */
- struct gl_shine_tab *_ShineTabList; /**< MRU list of inactive shine tables */
- /**@}*/
-
- struct gl_list_extensions *ListExt; /**< driver dlist extensions */
-
- /** \name For debugging/development only */
- /*@{*/
- GLboolean FirstTimeCurrent;
- /*@}*/
-
- /** software compression/decompression supported or not */
- GLboolean Mesa_DXTn;
-
- GLboolean TextureFormatSupported[MESA_FORMAT_COUNT];
-
- /**
- * Use dp4 (rather than mul/mad) instructions for position
- * transformation?
- */
- GLboolean mvp_with_dp4;
-
- /**
- * \name Hooks for module contexts.
- *
- * These will eventually live in the driver or elsewhere.
- */
- /*@{*/
- void *swrast_context;
- void *swsetup_context;
- void *swtnl_context;
- void *swtnl_im;
- struct st_context *st;
- void *aelt_context;
- /*@}*/
-};
-
-
-#ifdef DEBUG
-extern int MESA_VERBOSE;
-extern int MESA_DEBUG_FLAGS;
-# define MESA_FUNCTION __FUNCTION__
-#else
-# define MESA_VERBOSE 0
-# define MESA_DEBUG_FLAGS 0
-# define MESA_FUNCTION "a function"
-# ifndef NDEBUG
-# define NDEBUG
-# endif
-#endif
-
-
-/** The MESA_VERBOSE var is a bitmask of these flags */
-enum _verbose
-{
- VERBOSE_VARRAY = 0x0001,
- VERBOSE_TEXTURE = 0x0002,
- VERBOSE_MATERIAL = 0x0004,
- VERBOSE_PIPELINE = 0x0008,
- VERBOSE_DRIVER = 0x0010,
- VERBOSE_STATE = 0x0020,
- VERBOSE_API = 0x0040,
- VERBOSE_DISPLAY_LIST = 0x0100,
- VERBOSE_LIGHTING = 0x0200,
- VERBOSE_PRIMS = 0x0400,
- VERBOSE_VERTS = 0x0800,
- VERBOSE_DISASSEM = 0x1000,
- VERBOSE_DRAW = 0x2000,
- VERBOSE_SWAPBUFFERS = 0x4000
-};
-
-
-/** The MESA_DEBUG_FLAGS var is a bitmask of these flags */
-enum _debug
-{
- DEBUG_ALWAYS_FLUSH = 0x1
-};
-
-
-
-#endif /* MTYPES_H */
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file mtypes.h
+ * Main Mesa data structures.
+ *
+ * Please try to mark derived values with a leading underscore ('_').
+ */
+
+#ifndef MTYPES_H
+#define MTYPES_H
+
+
+#include "main/glheader.h"
+#include "main/config.h"
+#include "main/mfeatures.h"
+#include "glapi/glapi.h"
+#include "math/m_matrix.h" /* GLmatrix */
+#include "main/simple_list.h" /* struct simple_node */
+#include "main/formats.h" /* MESA_FORMAT_COUNT */
+
+
+/**
+ * Color channel data type.
+ */
+#if CHAN_BITS == 8
+ typedef GLubyte GLchan;
+#define CHAN_MAX 255
+#define CHAN_MAXF 255.0F
+#define CHAN_TYPE GL_UNSIGNED_BYTE
+#elif CHAN_BITS == 16
+ typedef GLushort GLchan;
+#define CHAN_MAX 65535
+#define CHAN_MAXF 65535.0F
+#define CHAN_TYPE GL_UNSIGNED_SHORT
+#elif CHAN_BITS == 32
+ typedef GLfloat GLchan;
+#define CHAN_MAX 1.0
+#define CHAN_MAXF 1.0F
+#define CHAN_TYPE GL_FLOAT
+#else
+#error "illegal number of color channel bits"
+#endif
+
+
+/**
+ * Stencil buffer data type.
+ */
+#if STENCIL_BITS==8
+ typedef GLubyte GLstencil;
+#elif STENCIL_BITS==16
+ typedef GLushort GLstencil;
+#else
+# error "illegal number of stencil bits"
+#endif
+
+
+/**
+ * \name 64-bit extension of GLbitfield.
+ */
+/*@{*/
+typedef GLuint64 GLbitfield64;
+
+/** Set a single bit */
+#define BITFIELD64_BIT(b) (1ULL << (b))
+
+
+/**
+ * \name Some forward type declarations
+ */
+/*@{*/
+struct _mesa_HashTable;
+struct gl_attrib_node;
+struct gl_list_extensions;
+struct gl_meta_state;
+struct gl_pixelstore_attrib;
+struct gl_program_cache;
+struct gl_texture_format;
+struct gl_texture_image;
+struct gl_texture_object;
+struct gl_context;
+struct st_context;
+/*@}*/
+
+
+/** Extra draw modes beyond GL_POINTS, GL_TRIANGLE_FAN, etc */
+#define PRIM_OUTSIDE_BEGIN_END (GL_POLYGON+1)
+#define PRIM_INSIDE_UNKNOWN_PRIM (GL_POLYGON+2)
+#define PRIM_UNKNOWN (GL_POLYGON+3)
+
+
+/**
+ * Shader stages. Note that these will become 5 with tessellation.
+ * These MUST have the same values as gallium's PIPE_SHADER_*
+ */
+typedef enum
+{
+ MESA_SHADER_VERTEX = 0,
+ MESA_SHADER_FRAGMENT = 1,
+ MESA_SHADER_GEOMETRY = 2,
+ MESA_SHADER_TYPES = 3
+} gl_shader_type;
+
+
+
+/**
+ * Indexes for vertex program attributes.
+ * GL_NV_vertex_program aliases generic attributes over the conventional
+ * attributes. In GL_ARB_vertex_program shader the aliasing is optional.
+ * In GL_ARB_vertex_shader / OpenGL 2.0 the aliasing is disallowed (the
+ * generic attributes are distinct/separate).
+ */
+typedef enum
+{
+ VERT_ATTRIB_POS = 0,
+ VERT_ATTRIB_WEIGHT = 1,
+ VERT_ATTRIB_NORMAL = 2,
+ VERT_ATTRIB_COLOR0 = 3,
+ VERT_ATTRIB_COLOR1 = 4,
+ VERT_ATTRIB_FOG = 5,
+ VERT_ATTRIB_COLOR_INDEX = 6,
+ VERT_ATTRIB_POINT_SIZE = 6, /*alias*/
+ VERT_ATTRIB_EDGEFLAG = 7,
+ VERT_ATTRIB_TEX0 = 8,
+ VERT_ATTRIB_TEX1 = 9,
+ VERT_ATTRIB_TEX2 = 10,
+ VERT_ATTRIB_TEX3 = 11,
+ VERT_ATTRIB_TEX4 = 12,
+ VERT_ATTRIB_TEX5 = 13,
+ VERT_ATTRIB_TEX6 = 14,
+ VERT_ATTRIB_TEX7 = 15,
+ VERT_ATTRIB_GENERIC0 = 16,
+ VERT_ATTRIB_GENERIC1 = 17,
+ VERT_ATTRIB_GENERIC2 = 18,
+ VERT_ATTRIB_GENERIC3 = 19,
+ VERT_ATTRIB_GENERIC4 = 20,
+ VERT_ATTRIB_GENERIC5 = 21,
+ VERT_ATTRIB_GENERIC6 = 22,
+ VERT_ATTRIB_GENERIC7 = 23,
+ VERT_ATTRIB_GENERIC8 = 24,
+ VERT_ATTRIB_GENERIC9 = 25,
+ VERT_ATTRIB_GENERIC10 = 26,
+ VERT_ATTRIB_GENERIC11 = 27,
+ VERT_ATTRIB_GENERIC12 = 28,
+ VERT_ATTRIB_GENERIC13 = 29,
+ VERT_ATTRIB_GENERIC14 = 30,
+ VERT_ATTRIB_GENERIC15 = 31,
+ VERT_ATTRIB_MAX = 32
+} gl_vert_attrib;
+
+/**
+ * Bitflags for vertex attributes.
+ * These are used in bitfields in many places.
+ */
+/*@{*/
+#define VERT_BIT_POS (1 << VERT_ATTRIB_POS)
+#define VERT_BIT_WEIGHT (1 << VERT_ATTRIB_WEIGHT)
+#define VERT_BIT_NORMAL (1 << VERT_ATTRIB_NORMAL)
+#define VERT_BIT_COLOR0 (1 << VERT_ATTRIB_COLOR0)
+#define VERT_BIT_COLOR1 (1 << VERT_ATTRIB_COLOR1)
+#define VERT_BIT_FOG (1 << VERT_ATTRIB_FOG)
+#define VERT_BIT_COLOR_INDEX (1 << VERT_ATTRIB_COLOR_INDEX)
+#define VERT_BIT_EDGEFLAG (1 << VERT_ATTRIB_EDGEFLAG)
+#define VERT_BIT_TEX0 (1 << VERT_ATTRIB_TEX0)
+#define VERT_BIT_TEX1 (1 << VERT_ATTRIB_TEX1)
+#define VERT_BIT_TEX2 (1 << VERT_ATTRIB_TEX2)
+#define VERT_BIT_TEX3 (1 << VERT_ATTRIB_TEX3)
+#define VERT_BIT_TEX4 (1 << VERT_ATTRIB_TEX4)
+#define VERT_BIT_TEX5 (1 << VERT_ATTRIB_TEX5)
+#define VERT_BIT_TEX6 (1 << VERT_ATTRIB_TEX6)
+#define VERT_BIT_TEX7 (1 << VERT_ATTRIB_TEX7)
+#define VERT_BIT_GENERIC0 (1 << VERT_ATTRIB_GENERIC0)
+#define VERT_BIT_GENERIC1 (1 << VERT_ATTRIB_GENERIC1)
+#define VERT_BIT_GENERIC2 (1 << VERT_ATTRIB_GENERIC2)
+#define VERT_BIT_GENERIC3 (1 << VERT_ATTRIB_GENERIC3)
+#define VERT_BIT_GENERIC4 (1 << VERT_ATTRIB_GENERIC4)
+#define VERT_BIT_GENERIC5 (1 << VERT_ATTRIB_GENERIC5)
+#define VERT_BIT_GENERIC6 (1 << VERT_ATTRIB_GENERIC6)
+#define VERT_BIT_GENERIC7 (1 << VERT_ATTRIB_GENERIC7)
+#define VERT_BIT_GENERIC8 (1 << VERT_ATTRIB_GENERIC8)
+#define VERT_BIT_GENERIC9 (1 << VERT_ATTRIB_GENERIC9)
+#define VERT_BIT_GENERIC10 (1 << VERT_ATTRIB_GENERIC10)
+#define VERT_BIT_GENERIC11 (1 << VERT_ATTRIB_GENERIC11)
+#define VERT_BIT_GENERIC12 (1 << VERT_ATTRIB_GENERIC12)
+#define VERT_BIT_GENERIC13 (1 << VERT_ATTRIB_GENERIC13)
+#define VERT_BIT_GENERIC14 (1 << VERT_ATTRIB_GENERIC14)
+#define VERT_BIT_GENERIC15 (1 << VERT_ATTRIB_GENERIC15)
+
+#define VERT_BIT_TEX(u) (1 << (VERT_ATTRIB_TEX0 + (u)))
+#define VERT_BIT_GENERIC(g) (1 << (VERT_ATTRIB_GENERIC0 + (g)))
+/*@}*/
+
+
+/**
+ * Indexes for vertex program result attributes
+ */
+typedef enum
+{
+ VERT_RESULT_HPOS = 0,
+ VERT_RESULT_COL0 = 1,
+ VERT_RESULT_COL1 = 2,
+ VERT_RESULT_FOGC = 3,
+ VERT_RESULT_TEX0 = 4,
+ VERT_RESULT_TEX1 = 5,
+ VERT_RESULT_TEX2 = 6,
+ VERT_RESULT_TEX3 = 7,
+ VERT_RESULT_TEX4 = 8,
+ VERT_RESULT_TEX5 = 9,
+ VERT_RESULT_TEX6 = 10,
+ VERT_RESULT_TEX7 = 11,
+ VERT_RESULT_PSIZ = 12,
+ VERT_RESULT_BFC0 = 13,
+ VERT_RESULT_BFC1 = 14,
+ VERT_RESULT_EDGE = 15,
+ VERT_RESULT_VAR0 = 16, /**< shader varying */
+ VERT_RESULT_MAX = (VERT_RESULT_VAR0 + MAX_VARYING)
+} gl_vert_result;
+
+
+/*********************************************/
+
+/**
+ * Indexes for geometry program attributes.
+ */
+typedef enum
+{
+ GEOM_ATTRIB_POSITION = 0,
+ GEOM_ATTRIB_COLOR0 = 1,
+ GEOM_ATTRIB_COLOR1 = 2,
+ GEOM_ATTRIB_SECONDARY_COLOR0 = 3,
+ GEOM_ATTRIB_SECONDARY_COLOR1 = 4,
+ GEOM_ATTRIB_FOG_FRAG_COORD = 5,
+ GEOM_ATTRIB_POINT_SIZE = 6,
+ GEOM_ATTRIB_CLIP_VERTEX = 7,
+ GEOM_ATTRIB_PRIMITIVE_ID = 8,
+ GEOM_ATTRIB_TEX_COORD = 9,
+
+ GEOM_ATTRIB_VAR0 = 16,
+ GEOM_ATTRIB_MAX = (GEOM_ATTRIB_VAR0 + MAX_VARYING)
+} gl_geom_attrib;
+
+/**
+ * Bitflags for geometry attributes.
+ * These are used in bitfields in many places.
+ */
+/*@{*/
+#define GEOM_BIT_COLOR0 (1 << GEOM_ATTRIB_COLOR0)
+#define GEOM_BIT_COLOR1 (1 << GEOM_ATTRIB_COLOR1)
+#define GEOM_BIT_SCOLOR0 (1 << GEOM_ATTRIB_SECONDARY_COLOR0)
+#define GEOM_BIT_SCOLOR1 (1 << GEOM_ATTRIB_SECONDARY_COLOR1)
+#define GEOM_BIT_TEX_COORD (1 << GEOM_ATTRIB_TEX_COORD)
+#define GEOM_BIT_FOG_COORD (1 << GEOM_ATTRIB_FOG_FRAG_COORD)
+#define GEOM_BIT_POSITION (1 << GEOM_ATTRIB_POSITION)
+#define GEOM_BIT_POINT_SIDE (1 << GEOM_ATTRIB_POINT_SIZE)
+#define GEOM_BIT_CLIP_VERTEX (1 << GEOM_ATTRIB_CLIP_VERTEX)
+#define GEOM_BIT_PRIM_ID (1 << GEOM_ATTRIB_PRIMITIVE_ID)
+#define GEOM_BIT_VAR0 (1 << GEOM_ATTRIB_VAR0)
+
+#define GEOM_BIT_VAR(g) (1 << (GEOM_BIT_VAR0 + (g)))
+/*@}*/
+
+
+/**
+ * Indexes for geometry program result attributes
+ */
+typedef enum
+{
+ GEOM_RESULT_POS = 0,
+ GEOM_RESULT_COL0 = 1,
+ GEOM_RESULT_COL1 = 2,
+ GEOM_RESULT_SCOL0 = 3,
+ GEOM_RESULT_SCOL1 = 4,
+ GEOM_RESULT_FOGC = 5,
+ GEOM_RESULT_TEX0 = 6,
+ GEOM_RESULT_TEX1 = 7,
+ GEOM_RESULT_TEX2 = 8,
+ GEOM_RESULT_TEX3 = 9,
+ GEOM_RESULT_TEX4 = 10,
+ GEOM_RESULT_TEX5 = 11,
+ GEOM_RESULT_TEX6 = 12,
+ GEOM_RESULT_TEX7 = 13,
+ GEOM_RESULT_PSIZ = 14,
+ GEOM_RESULT_CLPV = 15,
+ GEOM_RESULT_PRID = 16,
+ GEOM_RESULT_LAYR = 17,
+ GEOM_RESULT_VAR0 = 18, /**< shader varying, should really be 16 */
+ /* ### we need to -2 because var0 is 18 instead 16 like in the others */
+ GEOM_RESULT_MAX = (GEOM_RESULT_VAR0 + MAX_VARYING - 2)
+} gl_geom_result;
+
+
+/**
+ * Indexes for fragment program input attributes.
+ */
+typedef enum
+{
+ FRAG_ATTRIB_WPOS = 0,
+ FRAG_ATTRIB_COL0 = 1,
+ FRAG_ATTRIB_COL1 = 2,
+ FRAG_ATTRIB_FOGC = 3,
+ FRAG_ATTRIB_TEX0 = 4,
+ FRAG_ATTRIB_TEX1 = 5,
+ FRAG_ATTRIB_TEX2 = 6,
+ FRAG_ATTRIB_TEX3 = 7,
+ FRAG_ATTRIB_TEX4 = 8,
+ FRAG_ATTRIB_TEX5 = 9,
+ FRAG_ATTRIB_TEX6 = 10,
+ FRAG_ATTRIB_TEX7 = 11,
+ FRAG_ATTRIB_FACE = 12, /**< front/back face */
+ FRAG_ATTRIB_PNTC = 13, /**< sprite/point coord */
+ FRAG_ATTRIB_VAR0 = 14, /**< shader varying */
+ FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + MAX_VARYING)
+} gl_frag_attrib;
+
+/**
+ * Bitflags for fragment program input attributes.
+ */
+/*@{*/
+#define FRAG_BIT_WPOS (1 << FRAG_ATTRIB_WPOS)
+#define FRAG_BIT_COL0 (1 << FRAG_ATTRIB_COL0)
+#define FRAG_BIT_COL1 (1 << FRAG_ATTRIB_COL1)
+#define FRAG_BIT_FOGC (1 << FRAG_ATTRIB_FOGC)
+#define FRAG_BIT_FACE (1 << FRAG_ATTRIB_FACE)
+#define FRAG_BIT_PNTC (1 << FRAG_ATTRIB_PNTC)
+#define FRAG_BIT_TEX0 (1 << FRAG_ATTRIB_TEX0)
+#define FRAG_BIT_TEX1 (1 << FRAG_ATTRIB_TEX1)
+#define FRAG_BIT_TEX2 (1 << FRAG_ATTRIB_TEX2)
+#define FRAG_BIT_TEX3 (1 << FRAG_ATTRIB_TEX3)
+#define FRAG_BIT_TEX4 (1 << FRAG_ATTRIB_TEX4)
+#define FRAG_BIT_TEX5 (1 << FRAG_ATTRIB_TEX5)
+#define FRAG_BIT_TEX6 (1 << FRAG_ATTRIB_TEX6)
+#define FRAG_BIT_TEX7 (1 << FRAG_ATTRIB_TEX7)
+#define FRAG_BIT_VAR0 (1 << FRAG_ATTRIB_VAR0)
+
+#define FRAG_BIT_TEX(U) (FRAG_BIT_TEX0 << (U))
+#define FRAG_BIT_VAR(V) (FRAG_BIT_VAR0 << (V))
+
+#define FRAG_BITS_TEX_ANY (FRAG_BIT_TEX0| \
+ FRAG_BIT_TEX1| \
+ FRAG_BIT_TEX2| \
+ FRAG_BIT_TEX3| \
+ FRAG_BIT_TEX4| \
+ FRAG_BIT_TEX5| \
+ FRAG_BIT_TEX6| \
+ FRAG_BIT_TEX7)
+/*@}*/
+
+
+/**
+ * Fragment program results
+ */
+typedef enum
+{
+ FRAG_RESULT_DEPTH = 0,
+ FRAG_RESULT_STENCIL = 1,
+ FRAG_RESULT_COLOR = 2,
+ FRAG_RESULT_DATA0 = 3,
+ FRAG_RESULT_MAX = (FRAG_RESULT_DATA0 + MAX_DRAW_BUFFERS)
+} gl_frag_result;
+
+
+/**
+ * Indexes for all renderbuffers
+ */
+typedef enum
+{
+ /* the four standard color buffers */
+ BUFFER_FRONT_LEFT,
+ BUFFER_BACK_LEFT,
+ BUFFER_FRONT_RIGHT,
+ BUFFER_BACK_RIGHT,
+ BUFFER_DEPTH,
+ BUFFER_STENCIL,
+ BUFFER_ACCUM,
+ /* optional aux buffer */
+ BUFFER_AUX0,
+ /* generic renderbuffers */
+ BUFFER_COLOR0,
+ BUFFER_COLOR1,
+ BUFFER_COLOR2,
+ BUFFER_COLOR3,
+ BUFFER_COLOR4,
+ BUFFER_COLOR5,
+ BUFFER_COLOR6,
+ BUFFER_COLOR7,
+ BUFFER_COUNT
+} gl_buffer_index;
+
+/**
+ * Bit flags for all renderbuffers
+ */
+#define BUFFER_BIT_FRONT_LEFT (1 << BUFFER_FRONT_LEFT)
+#define BUFFER_BIT_BACK_LEFT (1 << BUFFER_BACK_LEFT)
+#define BUFFER_BIT_FRONT_RIGHT (1 << BUFFER_FRONT_RIGHT)
+#define BUFFER_BIT_BACK_RIGHT (1 << BUFFER_BACK_RIGHT)
+#define BUFFER_BIT_AUX0 (1 << BUFFER_AUX0)
+#define BUFFER_BIT_AUX1 (1 << BUFFER_AUX1)
+#define BUFFER_BIT_AUX2 (1 << BUFFER_AUX2)
+#define BUFFER_BIT_AUX3 (1 << BUFFER_AUX3)
+#define BUFFER_BIT_DEPTH (1 << BUFFER_DEPTH)
+#define BUFFER_BIT_STENCIL (1 << BUFFER_STENCIL)
+#define BUFFER_BIT_ACCUM (1 << BUFFER_ACCUM)
+#define BUFFER_BIT_COLOR0 (1 << BUFFER_COLOR0)
+#define BUFFER_BIT_COLOR1 (1 << BUFFER_COLOR1)
+#define BUFFER_BIT_COLOR2 (1 << BUFFER_COLOR2)
+#define BUFFER_BIT_COLOR3 (1 << BUFFER_COLOR3)
+#define BUFFER_BIT_COLOR4 (1 << BUFFER_COLOR4)
+#define BUFFER_BIT_COLOR5 (1 << BUFFER_COLOR5)
+#define BUFFER_BIT_COLOR6 (1 << BUFFER_COLOR6)
+#define BUFFER_BIT_COLOR7 (1 << BUFFER_COLOR7)
+
+/**
+ * Mask of all the color buffer bits (but not accum).
+ */
+#define BUFFER_BITS_COLOR (BUFFER_BIT_FRONT_LEFT | \
+ BUFFER_BIT_BACK_LEFT | \
+ BUFFER_BIT_FRONT_RIGHT | \
+ BUFFER_BIT_BACK_RIGHT | \
+ BUFFER_BIT_AUX0 | \
+ BUFFER_BIT_COLOR0 | \
+ BUFFER_BIT_COLOR1 | \
+ BUFFER_BIT_COLOR2 | \
+ BUFFER_BIT_COLOR3 | \
+ BUFFER_BIT_COLOR4 | \
+ BUFFER_BIT_COLOR5 | \
+ BUFFER_BIT_COLOR6 | \
+ BUFFER_BIT_COLOR7)
+
+
+/**
+ * Framebuffer configuration (aka visual / pixelformat)
+ * Note: some of these fields should be boolean, but it appears that
+ * code in drivers/dri/common/util.c requires int-sized fields.
+ */
+struct gl_config
+{
+ GLboolean rgbMode;
+ GLboolean floatMode;
+ GLboolean colorIndexMode; /* XXX is this used anywhere? */
+ GLuint doubleBufferMode;
+ GLuint stereoMode;
+
+ GLboolean haveAccumBuffer;
+ GLboolean haveDepthBuffer;
+ GLboolean haveStencilBuffer;
+
+ GLint redBits, greenBits, blueBits, alphaBits; /* bits per comp */
+ GLuint redMask, greenMask, blueMask, alphaMask;
+ GLint rgbBits; /* total bits for rgb */
+ GLint indexBits; /* total bits for colorindex */
+
+ GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits;
+ GLint depthBits;
+ GLint stencilBits;
+
+ GLint numAuxBuffers;
+
+ GLint level;
+
+ /* EXT_visual_rating / GLX 1.2 */
+ GLint visualRating;
+
+ /* EXT_visual_info / GLX 1.2 */
+ GLint transparentPixel;
+ /* colors are floats scaled to ints */
+ GLint transparentRed, transparentGreen, transparentBlue, transparentAlpha;
+ GLint transparentIndex;
+
+ /* ARB_multisample / SGIS_multisample */
+ GLint sampleBuffers;
+ GLint samples;
+
+ /* SGIX_pbuffer / GLX 1.3 */
+ GLint maxPbufferWidth;
+ GLint maxPbufferHeight;
+ GLint maxPbufferPixels;
+ GLint optimalPbufferWidth; /* Only for SGIX_pbuffer. */
+ GLint optimalPbufferHeight; /* Only for SGIX_pbuffer. */
+
+ /* OML_swap_method */
+ GLint swapMethod;
+
+ /* EXT_texture_from_pixmap */
+ GLint bindToTextureRgb;
+ GLint bindToTextureRgba;
+ GLint bindToMipmapTexture;
+ GLint bindToTextureTargets;
+ GLint yInverted;
+
+ /* EXT_framebuffer_sRGB */
+ GLint sRGBCapable;
+};
+
+
+/**
+ * Data structure for color tables
+ */
+struct gl_color_table
+{
+ GLenum InternalFormat; /**< The user-specified format */
+ GLenum _BaseFormat; /**< GL_ALPHA, GL_RGBA, GL_RGB, etc */
+ GLuint Size; /**< number of entries in table */
+ GLfloat *TableF; /**< Color table, floating point values */
+ GLubyte *TableUB; /**< Color table, ubyte values */
+ GLubyte RedSize;
+ GLubyte GreenSize;
+ GLubyte BlueSize;
+ GLubyte AlphaSize;
+ GLubyte LuminanceSize;
+ GLubyte IntensitySize;
+};
+
+
+/**
+ * \name Bit flags used for updating material values.
+ */
+/*@{*/
+#define MAT_ATTRIB_FRONT_AMBIENT 0
+#define MAT_ATTRIB_BACK_AMBIENT 1
+#define MAT_ATTRIB_FRONT_DIFFUSE 2
+#define MAT_ATTRIB_BACK_DIFFUSE 3
+#define MAT_ATTRIB_FRONT_SPECULAR 4
+#define MAT_ATTRIB_BACK_SPECULAR 5
+#define MAT_ATTRIB_FRONT_EMISSION 6
+#define MAT_ATTRIB_BACK_EMISSION 7
+#define MAT_ATTRIB_FRONT_SHININESS 8
+#define MAT_ATTRIB_BACK_SHININESS 9
+#define MAT_ATTRIB_FRONT_INDEXES 10
+#define MAT_ATTRIB_BACK_INDEXES 11
+#define MAT_ATTRIB_MAX 12
+
+#define MAT_ATTRIB_AMBIENT(f) (MAT_ATTRIB_FRONT_AMBIENT+(f))
+#define MAT_ATTRIB_DIFFUSE(f) (MAT_ATTRIB_FRONT_DIFFUSE+(f))
+#define MAT_ATTRIB_SPECULAR(f) (MAT_ATTRIB_FRONT_SPECULAR+(f))
+#define MAT_ATTRIB_EMISSION(f) (MAT_ATTRIB_FRONT_EMISSION+(f))
+#define MAT_ATTRIB_SHININESS(f)(MAT_ATTRIB_FRONT_SHININESS+(f))
+#define MAT_ATTRIB_INDEXES(f) (MAT_ATTRIB_FRONT_INDEXES+(f))
+
+#define MAT_INDEX_AMBIENT 0
+#define MAT_INDEX_DIFFUSE 1
+#define MAT_INDEX_SPECULAR 2
+
+#define MAT_BIT_FRONT_AMBIENT (1<<MAT_ATTRIB_FRONT_AMBIENT)
+#define MAT_BIT_BACK_AMBIENT (1<<MAT_ATTRIB_BACK_AMBIENT)
+#define MAT_BIT_FRONT_DIFFUSE (1<<MAT_ATTRIB_FRONT_DIFFUSE)
+#define MAT_BIT_BACK_DIFFUSE (1<<MAT_ATTRIB_BACK_DIFFUSE)
+#define MAT_BIT_FRONT_SPECULAR (1<<MAT_ATTRIB_FRONT_SPECULAR)
+#define MAT_BIT_BACK_SPECULAR (1<<MAT_ATTRIB_BACK_SPECULAR)
+#define MAT_BIT_FRONT_EMISSION (1<<MAT_ATTRIB_FRONT_EMISSION)
+#define MAT_BIT_BACK_EMISSION (1<<MAT_ATTRIB_BACK_EMISSION)
+#define MAT_BIT_FRONT_SHININESS (1<<MAT_ATTRIB_FRONT_SHININESS)
+#define MAT_BIT_BACK_SHININESS (1<<MAT_ATTRIB_BACK_SHININESS)
+#define MAT_BIT_FRONT_INDEXES (1<<MAT_ATTRIB_FRONT_INDEXES)
+#define MAT_BIT_BACK_INDEXES (1<<MAT_ATTRIB_BACK_INDEXES)
+
+
+#define FRONT_MATERIAL_BITS (MAT_BIT_FRONT_EMISSION | \
+ MAT_BIT_FRONT_AMBIENT | \
+ MAT_BIT_FRONT_DIFFUSE | \
+ MAT_BIT_FRONT_SPECULAR | \
+ MAT_BIT_FRONT_SHININESS | \
+ MAT_BIT_FRONT_INDEXES)
+
+#define BACK_MATERIAL_BITS (MAT_BIT_BACK_EMISSION | \
+ MAT_BIT_BACK_AMBIENT | \
+ MAT_BIT_BACK_DIFFUSE | \
+ MAT_BIT_BACK_SPECULAR | \
+ MAT_BIT_BACK_SHININESS | \
+ MAT_BIT_BACK_INDEXES)
+
+#define ALL_MATERIAL_BITS (FRONT_MATERIAL_BITS | BACK_MATERIAL_BITS)
+/*@}*/
+
+
+#define EXP_TABLE_SIZE 512 /**< Specular exponent lookup table sizes */
+#define SHINE_TABLE_SIZE 256 /**< Material shininess lookup table sizes */
+
+/**
+ * Material shininess lookup table.
+ */
+struct gl_shine_tab
+{
+ struct gl_shine_tab *next, *prev;
+ GLfloat tab[SHINE_TABLE_SIZE+1];
+ GLfloat shininess;
+ GLuint refcount;
+};
+
+
+/**
+ * Light source state.
+ */
+struct gl_light
+{
+ struct gl_light *next; /**< double linked list with sentinel */
+ struct gl_light *prev;
+
+ GLfloat Ambient[4]; /**< ambient color */
+ GLfloat Diffuse[4]; /**< diffuse color */
+ GLfloat Specular[4]; /**< specular color */
+ GLfloat EyePosition[4]; /**< position in eye coordinates */
+ GLfloat SpotDirection[4]; /**< spotlight direction in eye coordinates */
+ GLfloat SpotExponent;
+ GLfloat SpotCutoff; /**< in degrees */
+ GLfloat _CosCutoffNeg; /**< = cos(SpotCutoff) */
+ GLfloat _CosCutoff; /**< = MAX(0, cos(SpotCutoff)) */
+ GLfloat ConstantAttenuation;
+ GLfloat LinearAttenuation;
+ GLfloat QuadraticAttenuation;
+ GLboolean Enabled; /**< On/off flag */
+
+ /**
+ * \name Derived fields
+ */
+ /*@{*/
+ GLbitfield _Flags; /**< State */
+
+ GLfloat _Position[4]; /**< position in eye/obj coordinates */
+ GLfloat _VP_inf_norm[3]; /**< Norm direction to infinite light */
+ GLfloat _h_inf_norm[3]; /**< Norm( _VP_inf_norm + <0,0,1> ) */
+ GLfloat _NormSpotDirection[4]; /**< normalized spotlight direction */
+ GLfloat _VP_inf_spot_attenuation;
+
+ GLfloat _SpotExpTable[EXP_TABLE_SIZE][2]; /**< to replace a pow() call */
+ GLfloat _MatAmbient[2][3]; /**< material ambient * light ambient */
+ GLfloat _MatDiffuse[2][3]; /**< material diffuse * light diffuse */
+ GLfloat _MatSpecular[2][3]; /**< material spec * light specular */
+ GLfloat _dli; /**< CI diffuse light intensity */
+ GLfloat _sli; /**< CI specular light intensity */
+ /*@}*/
+};
+
+
+/**
+ * Light model state.
+ */
+struct gl_lightmodel
+{
+ GLfloat Ambient[4]; /**< ambient color */
+ GLboolean LocalViewer; /**< Local (or infinite) view point? */
+ GLboolean TwoSide; /**< Two (or one) sided lighting? */
+ GLenum ColorControl; /**< either GL_SINGLE_COLOR
+ * or GL_SEPARATE_SPECULAR_COLOR */
+};
+
+
+/**
+ * Material state.
+ */
+struct gl_material
+{
+ GLfloat Attrib[MAT_ATTRIB_MAX][4];
+};
+
+
+/**
+ * Accumulation buffer attribute group (GL_ACCUM_BUFFER_BIT)
+ */
+struct gl_accum_attrib
+{
+ GLfloat ClearColor[4]; /**< Accumulation buffer clear color */
+};
+
+
+/**
+ * Color buffer attribute group (GL_COLOR_BUFFER_BIT).
+ */
+struct gl_colorbuffer_attrib
+{
+ GLuint ClearIndex; /**< Index to use for glClear */
+ GLclampf ClearColor[4]; /**< Color to use for glClear */
+
+ GLuint IndexMask; /**< Color index write mask */
+ GLubyte ColorMask[MAX_DRAW_BUFFERS][4];/**< Each flag is 0xff or 0x0 */
+
+ GLenum DrawBuffer[MAX_DRAW_BUFFERS]; /**< Which buffer to draw into */
+
+ /**
+ * \name alpha testing
+ */
+ /*@{*/
+ GLboolean AlphaEnabled; /**< Alpha test enabled flag */
+ GLenum AlphaFunc; /**< Alpha test function */
+ GLclampf AlphaRef; /**< Alpha reference value */
+ /*@}*/
+
+ /**
+ * \name Blending
+ */
+ /*@{*/
+ GLbitfield BlendEnabled; /**< Per-buffer blend enable flags */
+ GLfloat BlendColor[4]; /**< Blending color */
+ struct
+ {
+ GLenum SrcRGB; /**< RGB blend source term */
+ GLenum DstRGB; /**< RGB blend dest term */
+ GLenum SrcA; /**< Alpha blend source term */
+ GLenum DstA; /**< Alpha blend dest term */
+ GLenum EquationRGB; /**< GL_ADD, GL_SUBTRACT, etc. */
+ GLenum EquationA; /**< GL_ADD, GL_SUBTRACT, etc. */
+ } Blend[MAX_DRAW_BUFFERS];
+ /** Are the blend func terms currently different for each buffer/target? */
+ GLboolean _BlendFuncPerBuffer;
+ /** Are the blend equations currently different for each buffer/target? */
+ GLboolean _BlendEquationPerBuffer;
+ /*@}*/
+
+ /**
+ * \name Logic op
+ */
+ /*@{*/
+ GLenum LogicOp; /**< Logic operator */
+ GLboolean IndexLogicOpEnabled; /**< Color index logic op enabled flag */
+ GLboolean ColorLogicOpEnabled; /**< RGBA logic op enabled flag */
+ GLboolean _LogicOpEnabled; /**< RGBA logic op + EXT_blend_logic_op enabled flag */
+ /*@}*/
+
+ GLboolean DitherFlag; /**< Dither enable flag */
+
+ GLenum ClampFragmentColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
+ GLenum ClampReadColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
+
+ GLboolean sRGBEnabled; /**< Framebuffer sRGB blending/updating requested */
+};
+
+
+/**
+ * Current attribute group (GL_CURRENT_BIT).
+ */
+struct gl_current_attrib
+{
+ /**
+ * \name Current vertex attributes.
+ * \note Values are valid only after FLUSH_VERTICES has been called.
+ * \note Index and Edgeflag current values are stored as floats in the
+ * SIX and SEVEN attribute slots.
+ */
+ GLfloat Attrib[VERT_ATTRIB_MAX][4]; /**< Position, color, texcoords, etc */
+
+ /**
+ * \name Current raster position attributes (always valid).
+ * \note This set of attributes is very similar to the SWvertex struct.
+ */
+ /*@{*/
+ GLfloat RasterPos[4];
+ GLfloat RasterDistance;
+ GLfloat RasterColor[4];
+ GLfloat RasterSecondaryColor[4];
+ GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4];
+ GLboolean RasterPosValid;
+ /*@}*/
+};
+
+
+/**
+ * Depth buffer attribute group (GL_DEPTH_BUFFER_BIT).
+ */
+struct gl_depthbuffer_attrib
+{
+ GLenum Func; /**< Function for depth buffer compare */
+ GLclampd Clear; /**< Value to clear depth buffer to */
+ GLboolean Test; /**< Depth buffering enabled flag */
+ GLboolean Mask; /**< Depth buffer writable? */
+ GLboolean BoundsTest; /**< GL_EXT_depth_bounds_test */
+ GLfloat BoundsMin, BoundsMax;/**< GL_EXT_depth_bounds_test */
+};
+
+
+/**
+ * Evaluator attribute group (GL_EVAL_BIT).
+ */
+struct gl_eval_attrib
+{
+ /**
+ * \name Enable bits
+ */
+ /*@{*/
+ GLboolean Map1Color4;
+ GLboolean Map1Index;
+ GLboolean Map1Normal;
+ GLboolean Map1TextureCoord1;
+ GLboolean Map1TextureCoord2;
+ GLboolean Map1TextureCoord3;
+ GLboolean Map1TextureCoord4;
+ GLboolean Map1Vertex3;
+ GLboolean Map1Vertex4;
+ GLboolean Map1Attrib[16]; /* GL_NV_vertex_program */
+ GLboolean Map2Color4;
+ GLboolean Map2Index;
+ GLboolean Map2Normal;
+ GLboolean Map2TextureCoord1;
+ GLboolean Map2TextureCoord2;
+ GLboolean Map2TextureCoord3;
+ GLboolean Map2TextureCoord4;
+ GLboolean Map2Vertex3;
+ GLboolean Map2Vertex4;
+ GLboolean Map2Attrib[16]; /* GL_NV_vertex_program */
+ GLboolean AutoNormal;
+ /*@}*/
+
+ /**
+ * \name Map Grid endpoints and divisions and calculated du values
+ */
+ /*@{*/
+ GLint MapGrid1un;
+ GLfloat MapGrid1u1, MapGrid1u2, MapGrid1du;
+ GLint MapGrid2un, MapGrid2vn;
+ GLfloat MapGrid2u1, MapGrid2u2, MapGrid2du;
+ GLfloat MapGrid2v1, MapGrid2v2, MapGrid2dv;
+ /*@}*/
+};
+
+
+/**
+ * Fog attribute group (GL_FOG_BIT).
+ */
+struct gl_fog_attrib
+{
+ GLboolean Enabled; /**< Fog enabled flag */
+ GLfloat Color[4]; /**< Fog color */
+ GLfloat Density; /**< Density >= 0.0 */
+ GLfloat Start; /**< Start distance in eye coords */
+ GLfloat End; /**< End distance in eye coords */
+ GLfloat Index; /**< Fog index */
+ GLenum Mode; /**< Fog mode */
+ GLboolean ColorSumEnabled;
+ GLenum FogCoordinateSource; /**< GL_EXT_fog_coord */
+ GLfloat _Scale; /**< (End == Start) ? 1.0 : 1.0 / (End - Start) */
+};
+
+
+/**
+ * \brief Layout qualifiers for gl_FragDepth.
+ *
+ * Extension AMD_conservative_depth allows gl_FragDepth to be redeclared with
+ * a layout qualifier.
+ *
+ * \see enum ir_depth_layout
+ */
+enum gl_frag_depth_layout {
+ FRAG_DEPTH_LAYOUT_NONE, /**< No layout is specified. */
+ FRAG_DEPTH_LAYOUT_ANY,
+ FRAG_DEPTH_LAYOUT_GREATER,
+ FRAG_DEPTH_LAYOUT_LESS,
+ FRAG_DEPTH_LAYOUT_UNCHANGED
+};
+
+
+/**
+ * Hint attribute group (GL_HINT_BIT).
+ *
+ * Values are always one of GL_FASTEST, GL_NICEST, or GL_DONT_CARE.
+ */
+struct gl_hint_attrib
+{
+ GLenum PerspectiveCorrection;
+ GLenum PointSmooth;
+ GLenum LineSmooth;
+ GLenum PolygonSmooth;
+ GLenum Fog;
+ GLenum ClipVolumeClipping; /**< GL_EXT_clip_volume_hint */
+ GLenum TextureCompression; /**< GL_ARB_texture_compression */
+ GLenum GenerateMipmap; /**< GL_SGIS_generate_mipmap */
+ GLenum FragmentShaderDerivative; /**< GL_ARB_fragment_shader */
+};
+
+/**
+ * Light state flags.
+ */
+/*@{*/
+#define LIGHT_SPOT 0x1
+#define LIGHT_LOCAL_VIEWER 0x2
+#define LIGHT_POSITIONAL 0x4
+#define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
+/*@}*/
+
+
+/**
+ * Lighting attribute group (GL_LIGHT_BIT).
+ */
+struct gl_light_attrib
+{
+ struct gl_light Light[MAX_LIGHTS]; /**< Array of light sources */
+ struct gl_lightmodel Model; /**< Lighting model */
+
+ /**
+ * Must flush FLUSH_VERTICES before referencing:
+ */
+ /*@{*/
+ struct gl_material Material; /**< Includes front & back values */
+ /*@}*/
+
+ GLboolean Enabled; /**< Lighting enabled flag */
+ GLenum ShadeModel; /**< GL_FLAT or GL_SMOOTH */
+ GLenum ProvokingVertex; /**< GL_EXT_provoking_vertex */
+ GLenum ColorMaterialFace; /**< GL_FRONT, BACK or FRONT_AND_BACK */
+ GLenum ColorMaterialMode; /**< GL_AMBIENT, GL_DIFFUSE, etc */
+ GLbitfield ColorMaterialBitmask; /**< bitmask formed from Face and Mode */
+ GLboolean ColorMaterialEnabled;
+ GLenum ClampVertexColor;
+
+ struct gl_light EnabledList; /**< List sentinel */
+
+ /**
+ * Derived state for optimizations:
+ */
+ /*@{*/
+ GLboolean _NeedEyeCoords;
+ GLboolean _NeedVertices; /**< Use fast shader? */
+ GLbitfield _Flags; /**< LIGHT_* flags, see above */
+ GLfloat _BaseColor[2][3];
+ /*@}*/
+};
+
+
+/**
+ * Line attribute group (GL_LINE_BIT).
+ */
+struct gl_line_attrib
+{
+ GLboolean SmoothFlag; /**< GL_LINE_SMOOTH enabled? */
+ GLboolean StippleFlag; /**< GL_LINE_STIPPLE enabled? */
+ GLushort StipplePattern; /**< Stipple pattern */
+ GLint StippleFactor; /**< Stipple repeat factor */
+ GLfloat Width; /**< Line width */
+};
+
+
+/**
+ * Display list attribute group (GL_LIST_BIT).
+ */
+struct gl_list_attrib
+{
+ GLuint ListBase;
+};
+
+
+/**
+ * Multisample attribute group (GL_MULTISAMPLE_BIT).
+ */
+struct gl_multisample_attrib
+{
+ GLboolean Enabled;
+ GLboolean _Enabled; /**< true if Enabled and multisample buffer */
+ GLboolean SampleAlphaToCoverage;
+ GLboolean SampleAlphaToOne;
+ GLboolean SampleCoverage;
+ GLfloat SampleCoverageValue;
+ GLboolean SampleCoverageInvert;
+};
+
+
+/**
+ * A pixelmap (see glPixelMap)
+ */
+struct gl_pixelmap
+{
+ GLint Size;
+ GLfloat Map[MAX_PIXEL_MAP_TABLE];
+ GLubyte Map8[MAX_PIXEL_MAP_TABLE]; /**< converted to 8-bit color */
+};
+
+
+/**
+ * Collection of all pixelmaps
+ */
+struct gl_pixelmaps
+{
+ struct gl_pixelmap RtoR; /**< i.e. GL_PIXEL_MAP_R_TO_R */
+ struct gl_pixelmap GtoG;
+ struct gl_pixelmap BtoB;
+ struct gl_pixelmap AtoA;
+ struct gl_pixelmap ItoR;
+ struct gl_pixelmap ItoG;
+ struct gl_pixelmap ItoB;
+ struct gl_pixelmap ItoA;
+ struct gl_pixelmap ItoI;
+ struct gl_pixelmap StoS;
+};
+
+
+/**
+ * Pixel attribute group (GL_PIXEL_MODE_BIT).
+ */
+struct gl_pixel_attrib
+{
+ GLenum ReadBuffer; /**< source buffer for glRead/CopyPixels() */
+
+ /*--- Begin Pixel Transfer State ---*/
+ /* Fields are in the order in which they're applied... */
+
+ /** Scale & Bias (index shift, offset) */
+ /*@{*/
+ GLfloat RedBias, RedScale;
+ GLfloat GreenBias, GreenScale;
+ GLfloat BlueBias, BlueScale;
+ GLfloat AlphaBias, AlphaScale;
+ GLfloat DepthBias, DepthScale;
+ GLint IndexShift, IndexOffset;
+ /*@}*/
+
+ /* Pixel Maps */
+ /* Note: actual pixel maps are not part of this attrib group */
+ GLboolean MapColorFlag;
+ GLboolean MapStencilFlag;
+
+ /*--- End Pixel Transfer State ---*/
+
+ /** glPixelZoom */
+ GLfloat ZoomX, ZoomY;
+};
+
+
+/**
+ * Point attribute group (GL_POINT_BIT).
+ */
+struct gl_point_attrib
+{
+ GLboolean SmoothFlag; /**< True if GL_POINT_SMOOTH is enabled */
+ GLfloat Size; /**< User-specified point size */
+ GLfloat Params[3]; /**< GL_EXT_point_parameters */
+ GLfloat MinSize, MaxSize; /**< GL_EXT_point_parameters */
+ GLfloat Threshold; /**< GL_EXT_point_parameters */
+ GLboolean _Attenuated; /**< True if Params != [1, 0, 0] */
+ GLboolean PointSprite; /**< GL_NV/ARB_point_sprite */
+ GLboolean CoordReplace[MAX_TEXTURE_COORD_UNITS]; /**< GL_ARB_point_sprite*/
+ GLenum SpriteRMode; /**< GL_NV_point_sprite (only!) */
+ GLenum SpriteOrigin; /**< GL_ARB_point_sprite */
+};
+
+
+/**
+ * Polygon attribute group (GL_POLYGON_BIT).
+ */
+struct gl_polygon_attrib
+{
+ GLenum FrontFace; /**< Either GL_CW or GL_CCW */
+ GLenum FrontMode; /**< Either GL_POINT, GL_LINE or GL_FILL */
+ GLenum BackMode; /**< Either GL_POINT, GL_LINE or GL_FILL */
+ GLboolean _FrontBit; /**< 0=GL_CCW, 1=GL_CW */
+ GLboolean CullFlag; /**< Culling on/off flag */
+ GLboolean SmoothFlag; /**< True if GL_POLYGON_SMOOTH is enabled */
+ GLboolean StippleFlag; /**< True if GL_POLYGON_STIPPLE is enabled */
+ GLenum CullFaceMode; /**< Culling mode GL_FRONT or GL_BACK */
+ GLfloat OffsetFactor; /**< Polygon offset factor, from user */
+ GLfloat OffsetUnits; /**< Polygon offset units, from user */
+ GLboolean OffsetPoint; /**< Offset in GL_POINT mode */
+ GLboolean OffsetLine; /**< Offset in GL_LINE mode */
+ GLboolean OffsetFill; /**< Offset in GL_FILL mode */
+};
+
+
+/**
+ * Scissor attributes (GL_SCISSOR_BIT).
+ */
+struct gl_scissor_attrib
+{
+ GLboolean Enabled; /**< Scissor test enabled? */
+ GLint X, Y; /**< Lower left corner of box */
+ GLsizei Width, Height; /**< Size of box */
+};
+
+
+/**
+ * Stencil attribute group (GL_STENCIL_BUFFER_BIT).
+ *
+ * Three sets of stencil data are tracked so that OpenGL 2.0,
+ * GL_EXT_stencil_two_side, and GL_ATI_separate_stencil can all be supported
+ * simultaneously. In each of the stencil state arrays, element 0 corresponds
+ * to GL_FRONT. Element 1 corresponds to the OpenGL 2.0 /
+ * GL_ATI_separate_stencil GL_BACK state. Element 2 corresponds to the
+ * GL_EXT_stencil_two_side GL_BACK state.
+ *
+ * The derived value \c _BackFace is either 1 or 2 depending on whether or
+ * not GL_STENCIL_TEST_TWO_SIDE_EXT is enabled.
+ *
+ * The derived value \c _TestTwoSide is set when the front-face and back-face
+ * stencil state are different.
+ */
+struct gl_stencil_attrib
+{
+ GLboolean Enabled; /**< Enabled flag */
+ GLboolean TestTwoSide; /**< GL_EXT_stencil_two_side */
+ GLubyte ActiveFace; /**< GL_EXT_stencil_two_side (0 or 2) */
+ GLboolean _Enabled; /**< Enabled and stencil buffer present */
+ GLboolean _TestTwoSide;
+ GLubyte _BackFace; /**< Current back stencil state (1 or 2) */
+ GLenum Function[3]; /**< Stencil function */
+ GLenum FailFunc[3]; /**< Fail function */
+ GLenum ZPassFunc[3]; /**< Depth buffer pass function */
+ GLenum ZFailFunc[3]; /**< Depth buffer fail function */
+ GLint Ref[3]; /**< Reference value */
+ GLuint ValueMask[3]; /**< Value mask */
+ GLuint WriteMask[3]; /**< Write mask */
+ GLuint Clear; /**< Clear value */
+};
+
+
+/**
+ * An index for each type of texture object. These correspond to the GL
+ * texture target enums, such as GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.
+ * Note: the order is from highest priority to lowest priority.
+ */
+typedef enum
+{
+ TEXTURE_2D_ARRAY_INDEX,
+ TEXTURE_1D_ARRAY_INDEX,
+ TEXTURE_CUBE_INDEX,
+ TEXTURE_3D_INDEX,
+ TEXTURE_RECT_INDEX,
+ TEXTURE_2D_INDEX,
+ TEXTURE_1D_INDEX,
+ NUM_TEXTURE_TARGETS
+} gl_texture_index;
+
+
+/**
+ * Bit flags for each type of texture object
+ * Used for Texture.Unit[]._ReallyEnabled flags.
+ */
+/*@{*/
+#define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX)
+#define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX)
+#define TEXTURE_CUBE_BIT (1 << TEXTURE_CUBE_INDEX)
+#define TEXTURE_3D_BIT (1 << TEXTURE_3D_INDEX)
+#define TEXTURE_RECT_BIT (1 << TEXTURE_RECT_INDEX)
+#define TEXTURE_2D_BIT (1 << TEXTURE_2D_INDEX)
+#define TEXTURE_1D_BIT (1 << TEXTURE_1D_INDEX)
+/*@}*/
+
+
+/**
+ * TexGenEnabled flags.
+ */
+/*@{*/
+#define S_BIT 1
+#define T_BIT 2
+#define R_BIT 4
+#define Q_BIT 8
+#define STR_BITS (S_BIT | T_BIT | R_BIT)
+/*@}*/
+
+
+/**
+ * Bit flag versions of the corresponding GL_ constants.
+ */
+/*@{*/
+#define TEXGEN_SPHERE_MAP 0x1
+#define TEXGEN_OBJ_LINEAR 0x2
+#define TEXGEN_EYE_LINEAR 0x4
+#define TEXGEN_REFLECTION_MAP_NV 0x8
+#define TEXGEN_NORMAL_MAP_NV 0x10
+
+#define TEXGEN_NEED_NORMALS (TEXGEN_SPHERE_MAP | \
+ TEXGEN_REFLECTION_MAP_NV | \
+ TEXGEN_NORMAL_MAP_NV)
+#define TEXGEN_NEED_EYE_COORD (TEXGEN_SPHERE_MAP | \
+ TEXGEN_REFLECTION_MAP_NV | \
+ TEXGEN_NORMAL_MAP_NV | \
+ TEXGEN_EYE_LINEAR)
+/*@}*/
+
+
+
+/** Tex-gen enabled for texture unit? */
+#define ENABLE_TEXGEN(unit) (1 << (unit))
+
+/** Non-identity texture matrix for texture unit? */
+#define ENABLE_TEXMAT(unit) (1 << (unit))
+
+
+/**
+ * Texel fetch function prototype. We use texel fetch functions to
+ * extract RGBA, color indexes and depth components out of 1D, 2D and 3D
+ * texture images. These functions help to isolate us from the gritty
+ * details of all the various texture image encodings.
+ *
+ * \param texImage texture image.
+ * \param col texel column.
+ * \param row texel row.
+ * \param img texel image level/layer.
+ * \param texelOut output texel (up to 4 GLchans)
+ */
+typedef void (*FetchTexelFuncC)( const struct gl_texture_image *texImage,
+ GLint col, GLint row, GLint img,
+ GLchan *texelOut );
+
+/**
+ * As above, but returns floats.
+ * Used for depth component images and for upcoming signed/float
+ * texture images.
+ */
+typedef void (*FetchTexelFuncF)( const struct gl_texture_image *texImage,
+ GLint col, GLint row, GLint img,
+ GLfloat *texelOut );
+
+
+typedef void (*StoreTexelFunc)(struct gl_texture_image *texImage,
+ GLint col, GLint row, GLint img,
+ const void *texel);
+
+
+/**
+ * Texture image state. Describes the dimensions of a texture image,
+ * the texel format and pointers to Texel Fetch functions.
+ */
+struct gl_texture_image
+{
+ GLint InternalFormat; /**< Internal format as given by the user */
+ GLenum _BaseFormat; /**< Either GL_RGB, GL_RGBA, GL_ALPHA,
+ * GL_LUMINANCE, GL_LUMINANCE_ALPHA,
+ * GL_INTENSITY, GL_COLOR_INDEX,
+ * GL_DEPTH_COMPONENT or GL_DEPTH_STENCIL_EXT
+ * only. Used for choosing TexEnv arithmetic.
+ */
+ gl_format TexFormat; /**< The actual texture memory format */
+
+ GLuint Border; /**< 0 or 1 */
+ GLuint Width; /**< = 2^WidthLog2 + 2*Border */
+ GLuint Height; /**< = 2^HeightLog2 + 2*Border */
+ GLuint Depth; /**< = 2^DepthLog2 + 2*Border */
+ GLuint Width2; /**< = Width - 2*Border */
+ GLuint Height2; /**< = Height - 2*Border */
+ GLuint Depth2; /**< = Depth - 2*Border */
+ GLuint WidthLog2; /**< = log2(Width2) */
+ GLuint HeightLog2; /**< = log2(Height2) */
+ GLuint DepthLog2; /**< = log2(Depth2) */
+ GLuint MaxLog2; /**< = MAX(WidthLog2, HeightLog2) */
+ GLfloat WidthScale; /**< used for mipmap LOD computation */
+ GLfloat HeightScale; /**< used for mipmap LOD computation */
+ GLfloat DepthScale; /**< used for mipmap LOD computation */
+ GLboolean IsClientData; /**< Data owned by client? */
+ GLboolean _IsPowerOfTwo; /**< Are all dimensions powers of two? */
+
+ struct gl_texture_object *TexObject; /**< Pointer back to parent object */
+
+ FetchTexelFuncC FetchTexelc; /**< GLchan texel fetch function pointer */
+ FetchTexelFuncF FetchTexelf; /**< Float texel fetch function pointer */
+
+ GLuint RowStride; /**< Padded width in units of texels */
+ GLuint *ImageOffsets; /**< if 3D texture: array [Depth] of offsets to
+ each 2D slice in 'Data', in texels */
+ GLvoid *Data; /**< Image data, accessed via FetchTexel() */
+
+ /**
+ * \name For device driver:
+ */
+ /*@{*/
+ void *DriverData; /**< Arbitrary device driver data */
+ /*@}*/
+};
+
+
+/**
+ * Indexes for cube map faces.
+ */
+typedef enum
+{
+ FACE_POS_X = 0,
+ FACE_NEG_X = 1,
+ FACE_POS_Y = 2,
+ FACE_NEG_Y = 3,
+ FACE_POS_Z = 4,
+ FACE_NEG_Z = 5,
+ MAX_FACES = 6
+} gl_face_index;
+
+
+/**
+ * Texture object state. Contains the array of mipmap images, border color,
+ * wrap modes, filter modes, shadow/texcompare state, and the per-texture
+ * color palette.
+ */
+struct gl_texture_object
+{
+ _glthread_Mutex Mutex; /**< for thread safety */
+ GLint RefCount; /**< reference count */
+ GLuint Name; /**< the user-visible texture object ID */
+ GLenum Target; /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
+ GLfloat Priority; /**< in [0,1] */
+ union {
+ GLfloat f[4];
+ GLuint ui[4];
+ GLint i[4];
+ } BorderColor; /**< Interpreted according to texture format */
+ GLenum WrapS; /**< S-axis texture image wrap mode */
+ GLenum WrapT; /**< T-axis texture image wrap mode */
+ GLenum WrapR; /**< R-axis texture image wrap mode */
+ GLenum MinFilter; /**< minification filter */
+ GLenum MagFilter; /**< magnification filter */
+ GLfloat MinLod; /**< min lambda, OpenGL 1.2 */
+ GLfloat MaxLod; /**< max lambda, OpenGL 1.2 */
+ GLfloat LodBias; /**< OpenGL 1.4 */
+ GLint BaseLevel; /**< min mipmap level, OpenGL 1.2 */
+ GLint MaxLevel; /**< max mipmap level, OpenGL 1.2 */
+ GLfloat MaxAnisotropy; /**< GL_EXT_texture_filter_anisotropic */
+ GLenum CompareMode; /**< GL_ARB_shadow */
+ GLenum CompareFunc; /**< GL_ARB_shadow */
+ GLfloat CompareFailValue; /**< GL_ARB_shadow_ambient */
+ GLenum DepthMode; /**< GL_ARB_depth_texture */
+ GLint _MaxLevel; /**< actual max mipmap level (q in the spec) */
+ GLfloat _MaxLambda; /**< = _MaxLevel - BaseLevel (q - b in spec) */
+ GLint CropRect[4]; /**< GL_OES_draw_texture */
+ GLenum Swizzle[4]; /**< GL_EXT_texture_swizzle */
+ GLuint _Swizzle; /**< same as Swizzle, but SWIZZLE_* format */
+ GLboolean GenerateMipmap; /**< GL_SGIS_generate_mipmap */
+ GLboolean _Complete; /**< Is texture object complete? */
+ GLboolean _RenderToTexture; /**< Any rendering to this texture? */
+ GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */
+ GLenum sRGBDecode; /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */
+
+ /** Actual texture images, indexed by [cube face] and [mipmap level] */
+ struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
+
+ /** GL_EXT_paletted_texture */
+ struct gl_color_table Palette;
+
+ /**
+ * \name For device driver.
+ * Note: instead of attaching driver data to this pointer, it's preferable
+ * to instead use this struct as a base class for your own texture object
+ * class. Driver->NewTextureObject() can be used to implement the
+ * allocation.
+ */
+ void *DriverData; /**< Arbitrary device driver data */
+};
+
+
+/** Up to four combiner sources are possible with GL_NV_texture_env_combine4 */
+#define MAX_COMBINER_TERMS 4
+
+
+/**
+ * Texture combine environment state.
+ */
+struct gl_tex_env_combine_state
+{
+ GLenum ModeRGB; /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
+ GLenum ModeA; /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
+ /** Source terms: GL_PRIMARY_COLOR, GL_TEXTURE, etc */
+ GLenum SourceRGB[MAX_COMBINER_TERMS];
+ GLenum SourceA[MAX_COMBINER_TERMS];
+ /** Source operands: GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, etc */
+ GLenum OperandRGB[MAX_COMBINER_TERMS];
+ GLenum OperandA[MAX_COMBINER_TERMS];
+ GLuint ScaleShiftRGB; /**< 0, 1 or 2 */
+ GLuint ScaleShiftA; /**< 0, 1 or 2 */
+ GLuint _NumArgsRGB; /**< Number of inputs used for the RGB combiner */
+ GLuint _NumArgsA; /**< Number of inputs used for the A combiner */
+};
+
+
+/**
+ * Texture coord generation state.
+ */
+struct gl_texgen
+{
+ GLenum Mode; /**< GL_EYE_LINEAR, GL_SPHERE_MAP, etc */
+ GLbitfield _ModeBit; /**< TEXGEN_x bit corresponding to Mode */
+ GLfloat ObjectPlane[4];
+ GLfloat EyePlane[4];
+};
+
+
+/**
+ * Texture unit state. Contains enable flags, texture environment/function/
+ * combiners, texgen state, pointers to current texture objects and
+ * post-filter color tables.
+ */
+struct gl_texture_unit
+{
+ GLbitfield Enabled; /**< bitmask of TEXTURE_*_BIT flags */
+ GLbitfield _ReallyEnabled; /**< 0 or exactly one of TEXTURE_*_BIT flags */
+
+ GLenum EnvMode; /**< GL_MODULATE, GL_DECAL, GL_BLEND, etc. */
+ GLfloat EnvColor[4];
+
+ struct gl_texgen GenS;
+ struct gl_texgen GenT;
+ struct gl_texgen GenR;
+ struct gl_texgen GenQ;
+ GLbitfield TexGenEnabled; /**< Bitwise-OR of [STRQ]_BIT values */
+ GLbitfield _GenFlags; /**< Bitwise-OR of Gen[STRQ]._ModeBit */
+
+ GLfloat LodBias; /**< for biasing mipmap levels */
+ GLenum BumpTarget;
+ GLfloat RotMatrix[4]; /* 2x2 matrix */
+
+ /**
+ * \name GL_EXT_texture_env_combine
+ */
+ struct gl_tex_env_combine_state Combine;
+
+ /**
+ * Derived state based on \c EnvMode and the \c BaseFormat of the
+ * currently enabled texture.
+ */
+ struct gl_tex_env_combine_state _EnvMode;
+
+ /**
+ * Currently enabled combiner state. This will point to either
+ * \c Combine or \c _EnvMode.
+ */
+ struct gl_tex_env_combine_state *_CurrentCombine;
+
+ /** Current texture object pointers */
+ struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
+
+ /** Points to highest priority, complete and enabled texture object */
+ struct gl_texture_object *_Current;
+};
+
+
+/**
+ * Texture attribute group (GL_TEXTURE_BIT).
+ */
+struct gl_texture_attrib
+{
+ GLuint CurrentUnit; /**< GL_ACTIVE_TEXTURE */
+ struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
+
+ struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
+
+ /** GL_ARB_seamless_cubemap */
+ GLboolean CubeMapSeamless;
+
+ /** GL_EXT_shared_texture_palette */
+ GLboolean SharedPalette;
+ struct gl_color_table Palette;
+
+ /** Texture units/samplers used by vertex or fragment texturing */
+ GLbitfield _EnabledUnits;
+
+ /** Texture coord units/sets used for fragment texturing */
+ GLbitfield _EnabledCoordUnits;
+
+ /** Texture coord units that have texgen enabled */
+ GLbitfield _TexGenEnabled;
+
+ /** Texture coord units that have non-identity matrices */
+ GLbitfield _TexMatEnabled;
+
+ /** Bitwise-OR of all Texture.Unit[i]._GenFlags */
+ GLbitfield _GenFlags;
+};
+
+
+/**
+ * Transformation attribute group (GL_TRANSFORM_BIT).
+ */
+struct gl_transform_attrib
+{
+ GLenum MatrixMode; /**< Matrix mode */
+ GLfloat EyeUserPlane[MAX_CLIP_PLANES][4]; /**< User clip planes */
+ GLfloat _ClipUserPlane[MAX_CLIP_PLANES][4]; /**< derived */
+ GLbitfield ClipPlanesEnabled; /**< on/off bitmask */
+ GLboolean Normalize; /**< Normalize all normals? */
+ GLboolean RescaleNormals; /**< GL_EXT_rescale_normal */
+ GLboolean RasterPositionUnclipped; /**< GL_IBM_rasterpos_clip */
+ GLboolean DepthClamp; /**< GL_ARB_depth_clamp */
+
+ GLfloat CullEyePos[4];
+ GLfloat CullObjPos[4];
+};
+
+
+/**
+ * Viewport attribute group (GL_VIEWPORT_BIT).
+ */
+struct gl_viewport_attrib
+{
+ GLint X, Y; /**< position */
+ GLsizei Width, Height; /**< size */
+ GLfloat Near, Far; /**< Depth buffer range */
+ GLmatrix _WindowMap; /**< Mapping transformation as a matrix. */
+};
+
+
+/**
+ * GL_ARB_vertex/pixel_buffer_object buffer object
+ */
+struct gl_buffer_object
+{
+ _glthread_Mutex Mutex;
+ GLint RefCount;
+ GLuint Name;
+ GLenum Usage; /**< GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, etc. */
+ GLsizeiptrARB Size; /**< Size of buffer storage in bytes */
+ GLubyte *Data; /**< Location of storage either in RAM or VRAM. */
+ /** Fields describing a mapped buffer */
+ /*@{*/
+ GLbitfield AccessFlags; /**< Mask of GL_MAP_x_BIT flags */
+ GLvoid *Pointer; /**< User-space address of mapping */
+ GLintptr Offset; /**< Mapped offset */
+ GLsizeiptr Length; /**< Mapped length */
+ /*@}*/
+ GLboolean Written; /**< Ever written to? (for debugging) */
+ GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */
+};
+
+
+/**
+ * Client pixel packing/unpacking attributes
+ */
+struct gl_pixelstore_attrib
+{
+ GLint Alignment;
+ GLint RowLength;
+ GLint SkipPixels;
+ GLint SkipRows;
+ GLint ImageHeight;
+ GLint SkipImages;
+ GLboolean SwapBytes;
+ GLboolean LsbFirst;
+ GLboolean ClientStorage; /**< GL_APPLE_client_storage */
+ GLboolean Invert; /**< GL_MESA_pack_invert */
+ struct gl_buffer_object *BufferObj; /**< GL_ARB_pixel_buffer_object */
+};
+
+
+/**
+ * Client vertex array attributes
+ */
+struct gl_client_array
+{
+ GLint Size; /**< components per element (1,2,3,4) */
+ GLenum Type; /**< datatype: GL_FLOAT, GL_INT, etc */
+ GLenum Format; /**< default: GL_RGBA, but may be GL_BGRA */
+ GLsizei Stride; /**< user-specified stride */
+ GLsizei StrideB; /**< actual stride in bytes */
+ const GLubyte *Ptr; /**< Points to array data */
+ GLboolean Enabled; /**< Enabled flag is a boolean */
+ GLboolean Normalized; /**< GL_ARB_vertex_program */
+ GLboolean Integer; /**< Integer-valued? */
+ GLuint InstanceDivisor; /**< GL_ARB_instanced_arrays */
+ GLuint _ElementSize; /**< size of each element in bytes */
+
+ struct gl_buffer_object *BufferObj;/**< GL_ARB_vertex_buffer_object */
+ GLuint _MaxElement; /**< max element index into array buffer + 1 */
+};
+
+
+/**
+ * Collection of vertex arrays. Defined by the GL_APPLE_vertex_array_object
+ * extension, but a nice encapsulation in any case.
+ */
+struct gl_array_object
+{
+ /** Name of the array object as received from glGenVertexArrayAPPLE. */
+ GLuint Name;
+
+ GLint RefCount;
+ _glthread_Mutex Mutex;
+ GLboolean VBOonly; /**< require all arrays to live in VBOs? */
+
+ /** Conventional vertex arrays */
+ /*@{*/
+ struct gl_client_array Vertex;
+ struct gl_client_array Weight;
+ struct gl_client_array Normal;
+ struct gl_client_array Color;
+ struct gl_client_array SecondaryColor;
+ struct gl_client_array FogCoord;
+ struct gl_client_array Index;
+ struct gl_client_array EdgeFlag;
+ struct gl_client_array TexCoord[MAX_TEXTURE_COORD_UNITS];
+ struct gl_client_array PointSize;
+ /*@}*/
+
+ /**
+ * Generic arrays for vertex programs/shaders.
+ * For NV vertex programs, these attributes alias and take priority
+ * over the conventional attribs above. For ARB vertex programs and
+ * GLSL vertex shaders, these attributes are separate.
+ */
+ struct gl_client_array VertexAttrib[MAX_VERTEX_GENERIC_ATTRIBS];
+
+ /** Mask of _NEW_ARRAY_* values indicating which arrays are enabled */
+ GLbitfield _Enabled;
+
+ /**
+ * Min of all enabled arrays' _MaxElement. When arrays reside inside VBOs
+ * we can determine the max legal (in bounds) glDrawElements array index.
+ */
+ GLuint _MaxElement;
+};
+
+
+/**
+ * Vertex array state
+ */
+struct gl_array_attrib
+{
+ /** Currently bound array object. See _mesa_BindVertexArrayAPPLE() */
+ struct gl_array_object *ArrayObj;
+
+ /** The default vertex array object */
+ struct gl_array_object *DefaultArrayObj;
+
+ /** Array objects (GL_ARB/APPLE_vertex_array_object) */
+ struct _mesa_HashTable *Objects;
+
+ GLint ActiveTexture; /**< Client Active Texture */
+ GLuint LockFirst; /**< GL_EXT_compiled_vertex_array */
+ GLuint LockCount; /**< GL_EXT_compiled_vertex_array */
+
+ /** GL 3.1 (slightly different from GL_NV_primitive_restart) */
+ GLboolean PrimitiveRestart;
+ GLuint RestartIndex;
+
+ GLbitfield NewState; /**< mask of _NEW_ARRAY_* values */
+ GLboolean RebindArrays; /**< whether the VBO module should rebind arrays */
+
+ /* GL_ARB_vertex_buffer_object */
+ struct gl_buffer_object *ArrayBufferObj;
+ struct gl_buffer_object *ElementArrayBufferObj;
+};
+
+
+/**
+ * Feedback buffer state
+ */
+struct gl_feedback
+{
+ GLenum Type;
+ GLbitfield _Mask; /**< FB_* bits */
+ GLfloat *Buffer;
+ GLuint BufferSize;
+ GLuint Count;
+};
+
+
+/**
+ * Selection buffer state
+ */
+struct gl_selection
+{
+ GLuint *Buffer; /**< selection buffer */
+ GLuint BufferSize; /**< size of the selection buffer */
+ GLuint BufferCount; /**< number of values in the selection buffer */
+ GLuint Hits; /**< number of records in the selection buffer */
+ GLuint NameStackDepth; /**< name stack depth */
+ GLuint NameStack[MAX_NAME_STACK_DEPTH]; /**< name stack */
+ GLboolean HitFlag; /**< hit flag */
+ GLfloat HitMinZ; /**< minimum hit depth */
+ GLfloat HitMaxZ; /**< maximum hit depth */
+};
+
+
+/**
+ * 1-D Evaluator control points
+ */
+struct gl_1d_map
+{
+ GLuint Order; /**< Number of control points */
+ GLfloat u1, u2, du; /**< u1, u2, 1.0/(u2-u1) */
+ GLfloat *Points; /**< Points to contiguous control points */
+};
+
+
+/**
+ * 2-D Evaluator control points
+ */
+struct gl_2d_map
+{
+ GLuint Uorder; /**< Number of control points in U dimension */
+ GLuint Vorder; /**< Number of control points in V dimension */
+ GLfloat u1, u2, du;
+ GLfloat v1, v2, dv;
+ GLfloat *Points; /**< Points to contiguous control points */
+};
+
+
+/**
+ * All evaluator control point state
+ */
+struct gl_evaluators
+{
+ /**
+ * \name 1-D maps
+ */
+ /*@{*/
+ struct gl_1d_map Map1Vertex3;
+ struct gl_1d_map Map1Vertex4;
+ struct gl_1d_map Map1Index;
+ struct gl_1d_map Map1Color4;
+ struct gl_1d_map Map1Normal;
+ struct gl_1d_map Map1Texture1;
+ struct gl_1d_map Map1Texture2;
+ struct gl_1d_map Map1Texture3;
+ struct gl_1d_map Map1Texture4;
+ struct gl_1d_map Map1Attrib[16]; /**< GL_NV_vertex_program */
+ /*@}*/
+
+ /**
+ * \name 2-D maps
+ */
+ /*@{*/
+ struct gl_2d_map Map2Vertex3;
+ struct gl_2d_map Map2Vertex4;
+ struct gl_2d_map Map2Index;
+ struct gl_2d_map Map2Color4;
+ struct gl_2d_map Map2Normal;
+ struct gl_2d_map Map2Texture1;
+ struct gl_2d_map Map2Texture2;
+ struct gl_2d_map Map2Texture3;
+ struct gl_2d_map Map2Texture4;
+ struct gl_2d_map Map2Attrib[16]; /**< GL_NV_vertex_program */
+ /*@}*/
+};
+
+
+/**
+ * Names of the various vertex/fragment program register files, etc.
+ *
+ * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
+ * All values should fit in a 4-bit field.
+ *
+ * NOTE: PROGRAM_ENV_PARAM, PROGRAM_STATE_VAR, PROGRAM_NAMED_PARAM,
+ * PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be considered to
+ * be "uniform" variables since they can only be set outside glBegin/End.
+ * They're also all stored in the same Parameters array.
+ */
+typedef enum
+{
+ PROGRAM_TEMPORARY, /**< machine->Temporary[] */
+ PROGRAM_INPUT, /**< machine->Inputs[] */
+ PROGRAM_OUTPUT, /**< machine->Outputs[] */
+ PROGRAM_VARYING, /**< machine->Inputs[]/Outputs[] */
+ PROGRAM_LOCAL_PARAM, /**< gl_program->LocalParams[] */
+ PROGRAM_ENV_PARAM, /**< gl_program->Parameters[] */
+ PROGRAM_STATE_VAR, /**< gl_program->Parameters[] */
+ PROGRAM_NAMED_PARAM, /**< gl_program->Parameters[] */
+ PROGRAM_CONSTANT, /**< gl_program->Parameters[] */
+ PROGRAM_UNIFORM, /**< gl_program->Parameters[] */
+ PROGRAM_WRITE_ONLY, /**< A dummy, write-only register */
+ PROGRAM_ADDRESS, /**< machine->AddressReg */
+ PROGRAM_SAMPLER, /**< for shader samplers, compile-time only */
+ PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */
+ PROGRAM_UNDEFINED, /**< Invalid/TBD value */
+ PROGRAM_FILE_MAX
+} gl_register_file;
+
+
+/**
+ * If the register file is PROGRAM_SYSTEM_VALUE, the register index will be
+ * one of these values.
+ */
+typedef enum
+{
+ SYSTEM_VALUE_FRONT_FACE, /**< Fragment shader only (not done yet) */
+ SYSTEM_VALUE_INSTANCE_ID, /**< Vertex shader only */
+ SYSTEM_VALUE_MAX /**< Number of values */
+} gl_system_value;
+
+
+/** Vertex and fragment instructions */
+struct prog_instruction;
+struct gl_program_parameter_list;
+struct gl_uniform_list;
+
+
+/**
+ * Base class for any kind of program object
+ */
+struct gl_program
+{
+ GLuint Id;
+ GLubyte *String; /**< Null-terminated program text */
+ GLint RefCount;
+ GLenum Target; /**< GL_VERTEX/FRAGMENT_PROGRAM_ARB, GL_FRAGMENT_PROGRAM_NV */
+ GLenum Format; /**< String encoding format */
+ GLboolean Resident;
+
+ struct prog_instruction *Instructions;
+
+ GLbitfield InputsRead; /**< Bitmask of which input regs are read */
+ GLbitfield64 OutputsWritten; /**< Bitmask of which output regs are written */
+ GLbitfield SystemValuesRead; /**< Bitmask of SYSTEM_VALUE_x inputs used */
+ GLbitfield InputFlags[MAX_PROGRAM_INPUTS]; /**< PROG_PARAM_BIT_x flags */
+ GLbitfield OutputFlags[MAX_PROGRAM_OUTPUTS]; /**< PROG_PARAM_BIT_x flags */
+ GLbitfield TexturesUsed[MAX_TEXTURE_UNITS]; /**< TEXTURE_x_BIT bitmask */
+ GLbitfield SamplersUsed; /**< Bitfield of which samplers are used */
+ GLbitfield ShadowSamplers; /**< Texture units used for shadow sampling. */
+
+
+ /** Named parameters, constants, etc. from program text */
+ struct gl_program_parameter_list *Parameters;
+ /** Numbered local parameters */
+ GLfloat LocalParams[MAX_PROGRAM_LOCAL_PARAMS][4];
+
+ /** Vertex/fragment shader varying vars */
+ struct gl_program_parameter_list *Varying;
+ /** Vertex program user-defined attributes */
+ struct gl_program_parameter_list *Attributes;
+
+ /** Map from sampler unit to texture unit (set by glUniform1i()) */
+ GLubyte SamplerUnits[MAX_SAMPLERS];
+ /** Which texture target is being sampled (TEXTURE_1D/2D/3D/etc_INDEX) */
+ gl_texture_index SamplerTargets[MAX_SAMPLERS];
+
+ /** Bitmask of which register files are read/written with indirect
+ * addressing. Mask of (1 << PROGRAM_x) bits.
+ */
+ GLbitfield IndirectRegisterFiles;
+
+ /** Logical counts */
+ /*@{*/
+ GLuint NumInstructions;
+ GLuint NumTemporaries;
+ GLuint NumParameters;
+ GLuint NumAttributes;
+ GLuint NumAddressRegs;
+ GLuint NumAluInstructions;
+ GLuint NumTexInstructions;
+ GLuint NumTexIndirections;
+ /*@}*/
+ /** Native, actual h/w counts */
+ /*@{*/
+ GLuint NumNativeInstructions;
+ GLuint NumNativeTemporaries;
+ GLuint NumNativeParameters;
+ GLuint NumNativeAttributes;
+ GLuint NumNativeAddressRegs;
+ GLuint NumNativeAluInstructions;
+ GLuint NumNativeTexInstructions;
+ GLuint NumNativeTexIndirections;
+ /*@}*/
+};
+
+
+/** Vertex program object */
+struct gl_vertex_program
+{
+ struct gl_program Base; /**< base class */
+ GLboolean IsNVProgram; /**< is this a GL_NV_vertex_program program? */
+ GLboolean IsPositionInvariant;
+};
+
+
+/** Geometry program object */
+struct gl_geometry_program
+{
+ struct gl_program Base; /**< base class */
+
+ GLint VerticesOut;
+ GLenum InputType; /**< GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_ARB,
+ GL_TRIANGLES, or GL_TRIANGLES_ADJACENCY_ARB */
+ GLenum OutputType; /**< GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP */
+};
+
+
+/** Fragment program object */
+struct gl_fragment_program
+{
+ struct gl_program Base; /**< base class */
+ GLenum FogOption;
+ GLboolean UsesKill; /**< shader uses KIL instruction */
+ GLboolean OriginUpperLeft;
+ GLboolean PixelCenterInteger;
+ enum gl_frag_depth_layout FragDepthLayout;
+};
+
+
+/**
+ * State common to vertex and fragment programs.
+ */
+struct gl_program_state
+{
+ GLint ErrorPos; /* GL_PROGRAM_ERROR_POSITION_ARB/NV */
+ const char *ErrorString; /* GL_PROGRAM_ERROR_STRING_ARB/NV */
+};
+
+
+/**
+ * Context state for vertex programs.
+ */
+struct gl_vertex_program_state
+{
+ GLboolean Enabled; /**< User-set GL_VERTEX_PROGRAM_ARB/NV flag */
+ GLboolean _Enabled; /**< Enabled and _valid_ user program? */
+ GLboolean PointSizeEnabled; /**< GL_VERTEX_PROGRAM_POINT_SIZE_ARB/NV */
+ GLboolean TwoSideEnabled; /**< GL_VERTEX_PROGRAM_TWO_SIDE_ARB/NV */
+ struct gl_vertex_program *Current; /**< User-bound vertex program */
+
+ /** Currently enabled and valid vertex program (including internal
+ * programs, user-defined vertex programs and GLSL vertex shaders).
+ * This is the program we must use when rendering.
+ */
+ struct gl_vertex_program *_Current;
+
+ GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
+
+ /* For GL_NV_vertex_program only: */
+ GLenum TrackMatrix[MAX_PROGRAM_ENV_PARAMS / 4];
+ GLenum TrackMatrixTransform[MAX_PROGRAM_ENV_PARAMS / 4];
+
+ /** Should fixed-function T&L be implemented with a vertex prog? */
+ GLboolean _MaintainTnlProgram;
+
+ /** Program to emulate fixed-function T&L (see above) */
+ struct gl_vertex_program *_TnlProgram;
+
+ /** Cache of fixed-function programs */
+ struct gl_program_cache *Cache;
+
+ GLboolean _Overriden;
+};
+
+
+/**
+ * Context state for geometry programs.
+ */
+struct gl_geometry_program_state
+{
+ GLboolean Enabled; /**< GL_ARB_GEOMETRY_SHADER4 */
+ GLboolean _Enabled; /**< Enabled and valid program? */
+ struct gl_geometry_program *Current; /**< user-bound geometry program */
+
+ /** Currently enabled and valid program (including internal programs
+ * and compiled shader programs).
+ */
+ struct gl_geometry_program *_Current;
+
+ GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
+
+ /** Cache of fixed-function programs */
+ struct gl_program_cache *Cache;
+};
+
+/**
+ * Context state for fragment programs.
+ */
+struct gl_fragment_program_state
+{
+ GLboolean Enabled; /**< User-set fragment program enable flag */
+ GLboolean _Enabled; /**< Enabled and _valid_ user program? */
+ struct gl_fragment_program *Current; /**< User-bound fragment program */
+
+ /** Currently enabled and valid fragment program (including internal
+ * programs, user-defined fragment programs and GLSL fragment shaders).
+ * This is the program we must use when rendering.
+ */
+ struct gl_fragment_program *_Current;
+
+ GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
+
+ /** Should fixed-function texturing be implemented with a fragment prog? */
+ GLboolean _MaintainTexEnvProgram;
+
+ /** Program to emulate fixed-function texture env/combine (see above) */
+ struct gl_fragment_program *_TexEnvProgram;
+
+ /** Cache of fixed-function programs */
+ struct gl_program_cache *Cache;
+};
+
+
+/**
+ * ATI_fragment_shader runtime state
+ */
+#define ATI_FS_INPUT_PRIMARY 0
+#define ATI_FS_INPUT_SECONDARY 1
+
+struct atifs_instruction;
+struct atifs_setupinst;
+
+/**
+ * ATI fragment shader
+ */
+struct ati_fragment_shader
+{
+ GLuint Id;
+ GLint RefCount;
+ struct atifs_instruction *Instructions[2];
+ struct atifs_setupinst *SetupInst[2];
+ GLfloat Constants[8][4];
+ GLbitfield LocalConstDef; /**< Indicates which constants have been set */
+ GLubyte numArithInstr[2];
+ GLubyte regsAssigned[2];
+ GLubyte NumPasses; /**< 1 or 2 */
+ GLubyte cur_pass;
+ GLubyte last_optype;
+ GLboolean interpinp1;
+ GLboolean isValid;
+ GLuint swizzlerq;
+};
+
+/**
+ * Context state for GL_ATI_fragment_shader
+ */
+struct gl_ati_fragment_shader_state
+{
+ GLboolean Enabled;
+ GLboolean _Enabled; /**< enabled and valid shader? */
+ GLboolean Compiling;
+ GLfloat GlobalConstants[8][4];
+ struct ati_fragment_shader *Current;
+};
+
+
+/**
+ * Occlusion/timer query object.
+ */
+struct gl_query_object
+{
+ GLenum Target; /**< The query target, when active */
+ GLuint Id; /**< hash table ID/name */
+ GLuint64EXT Result; /**< the counter */
+ GLboolean Active; /**< inside Begin/EndQuery */
+ GLboolean Ready; /**< result is ready? */
+};
+
+
+/**
+ * Context state for query objects.
+ */
+struct gl_query_state
+{
+ struct _mesa_HashTable *QueryObjects;
+ struct gl_query_object *CurrentOcclusionObject; /* GL_ARB_occlusion_query */
+ struct gl_query_object *CurrentTimerObject; /* GL_EXT_timer_query */
+
+ /** GL_NV_conditional_render */
+ struct gl_query_object *CondRenderQuery;
+
+ /** GL_EXT_transform_feedback */
+ struct gl_query_object *PrimitivesGenerated;
+ struct gl_query_object *PrimitivesWritten;
+
+ /** GL_ARB_timer_query */
+ struct gl_query_object *TimeElapsed;
+
+ GLenum CondRenderMode;
+};
+
+
+/** Sync object state */
+struct gl_sync_object {
+ struct simple_node link;
+ GLenum Type; /**< GL_SYNC_FENCE */
+ GLuint Name; /**< Fence name */
+ GLint RefCount; /**< Reference count */
+ GLboolean DeletePending; /**< Object was deleted while there were still
+ * live references (e.g., sync not yet finished)
+ */
+ GLenum SyncCondition;
+ GLbitfield Flags; /**< Flags passed to glFenceSync */
+ GLuint StatusFlag:1; /**< Has the sync object been signaled? */
+};
+
+
+/** Set by #pragma directives */
+struct gl_sl_pragmas
+{
+ GLboolean IgnoreOptimize; /**< ignore #pragma optimize(on/off) ? */
+ GLboolean IgnoreDebug; /**< ignore #pragma debug(on/off) ? */
+ GLboolean Optimize; /**< defaults on */
+ GLboolean Debug; /**< defaults off */
+};
+
+
+/**
+ * A GLSL vertex or fragment shader object.
+ */
+struct gl_shader
+{
+ GLenum Type; /**< GL_FRAGMENT_SHADER || GL_VERTEX_SHADER || GL_GEOMETRY_SHADER_ARB (first field!) */
+ GLuint Name; /**< AKA the handle */
+ GLint RefCount; /**< Reference count */
+ GLboolean DeletePending;
+ GLboolean CompileStatus;
+ const GLchar *Source; /**< Source code string */
+ GLuint SourceChecksum; /**< for debug/logging purposes */
+ struct gl_program *Program; /**< Post-compile assembly code */
+ GLchar *InfoLog;
+ struct gl_sl_pragmas Pragmas;
+
+ unsigned Version; /**< GLSL version used for linking */
+
+ struct exec_list *ir;
+ struct glsl_symbol_table *symbols;
+
+ /** Shaders containing built-in functions that are used for linking. */
+ struct gl_shader *builtins_to_link[16];
+ unsigned num_builtins_to_link;
+};
+
+
+/**
+ * A GLSL program object.
+ * Basically a linked collection of vertex and fragment shaders.
+ */
+struct gl_shader_program
+{
+ GLenum Type; /**< Always GL_SHADER_PROGRAM (internal token) */
+ GLuint Name; /**< aka handle or ID */
+ GLint RefCount; /**< Reference count */
+ GLboolean DeletePending;
+
+ GLuint NumShaders; /**< number of attached shaders */
+ struct gl_shader **Shaders; /**< List of attached the shaders */
+
+ /** User-defined attribute bindings (glBindAttribLocation) */
+ struct gl_program_parameter_list *Attributes;
+
+ /** Transform feedback varyings */
+ struct {
+ GLenum BufferMode;
+ GLuint NumVarying;
+ GLchar **VaryingNames; /**< Array [NumVarying] of char * */
+ } TransformFeedback;
+
+ /** Geometry shader state - copied into gl_geometry_program at link time */
+ struct {
+ GLint VerticesOut;
+ GLenum InputType; /**< GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_ARB,
+ GL_TRIANGLES, or GL_TRIANGLES_ADJACENCY_ARB */
+ GLenum OutputType; /**< GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP */
+ } Geom;
+
+ /* post-link info: */
+ struct gl_vertex_program *VertexProgram; /**< Linked vertex program */
+ struct gl_fragment_program *FragmentProgram; /**< Linked fragment prog */
+ struct gl_geometry_program *GeometryProgram; /**< Linked geometry prog */
+ struct gl_uniform_list *Uniforms;
+ struct gl_program_parameter_list *Varying;
+ GLboolean LinkStatus; /**< GL_LINK_STATUS */
+ GLboolean Validated;
+ GLboolean _Used; /**< Ever used for drawing? */
+ GLchar *InfoLog;
+
+ unsigned Version; /**< GLSL version used for linking */
+
+ /**
+ * Per-stage shaders resulting from the first stage of linking.
+ *
+ * Set of linked shaders for this program. The array is accessed using the
+ * \c MESA_SHADER_* defines. Entries for non-existent stages will be
+ * \c NULL.
+ */
+ struct gl_shader *_LinkedShaders[MESA_SHADER_TYPES];
+};
+
+
+#define GLSL_DUMP 0x1 /**< Dump shaders to stdout */
+#define GLSL_LOG 0x2 /**< Write shaders to files */
+#define GLSL_OPT 0x4 /**< Force optimizations (override pragmas) */
+#define GLSL_NO_OPT 0x8 /**< Force no optimizations (override pragmas) */
+#define GLSL_UNIFORMS 0x10 /**< Print glUniform calls */
+#define GLSL_NOP_VERT 0x20 /**< Force no-op vertex shaders */
+#define GLSL_NOP_FRAG 0x40 /**< Force no-op fragment shaders */
+#define GLSL_USE_PROG 0x80 /**< Log glUseProgram calls */
+
+
+/**
+ * Context state for GLSL vertex/fragment shaders.
+ */
+struct gl_shader_state
+{
+ /**
+ * Programs used for rendering
+ *
+ * There is a separate program set for each shader stage. If
+ * GL_EXT_separate_shader_objects is not supported, each of these must point
+ * to \c NULL or to the same program.
+ */
+ struct gl_shader_program *CurrentVertexProgram;
+ struct gl_shader_program *CurrentGeometryProgram;
+ struct gl_shader_program *CurrentFragmentProgram;
+
+ /**
+ * Program used by glUniform calls.
+ *
+ * Explicitly set by \c glUseProgram and \c glActiveProgramEXT.
+ */
+ struct gl_shader_program *ActiveProgram;
+
+ void *MemPool;
+
+ GLbitfield Flags; /**< Mask of GLSL_x flags */
+};
+
+/**
+ * Compiler options for a single GLSL shaders type
+ */
+struct gl_shader_compiler_options
+{
+ /** Driver-selectable options: */
+ GLboolean EmitCondCodes; /**< Use condition codes? */
+ GLboolean EmitNVTempInitialization; /**< 0-fill NV temp registers */
+ /**
+ * Attempts to flatten all ir_if (OPCODE_IF) for GPUs that can't
+ * support control flow.
+ */
+ GLboolean EmitNoIfs;
+ GLboolean EmitNoLoops;
+ GLboolean EmitNoFunctions;
+ GLboolean EmitNoCont; /**< Emit CONT opcode? */
+ GLboolean EmitNoMainReturn; /**< Emit CONT/RET opcodes? */
+ GLboolean EmitNoNoise; /**< Emit NOISE opcodes? */
+ GLboolean EmitNoPow; /**< Emit POW opcodes? */
+
+ /**
+ * \name Forms of indirect addressing the driver cannot do.
+ */
+ /*@{*/
+ GLboolean EmitNoIndirectInput; /**< No indirect addressing of inputs */
+ GLboolean EmitNoIndirectOutput; /**< No indirect addressing of outputs */
+ GLboolean EmitNoIndirectTemp; /**< No indirect addressing of temps */
+ GLboolean EmitNoIndirectUniform; /**< No indirect addressing of constants */
+ /*@}*/
+
+ GLuint MaxUnrollIterations;
+
+ struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */
+};
+
+/**
+ * Transform feedback object state
+ */
+struct gl_transform_feedback_object
+{
+ GLuint Name; /**< AKA the object ID */
+ GLint RefCount;
+ GLboolean Active; /**< Is transform feedback enabled? */
+ GLboolean Paused; /**< Is transform feedback paused? */
+
+ /** The feedback buffers */
+ GLuint BufferNames[MAX_FEEDBACK_ATTRIBS];
+ struct gl_buffer_object *Buffers[MAX_FEEDBACK_ATTRIBS];
+
+ /** Start of feedback data in dest buffer */
+ GLintptr Offset[MAX_FEEDBACK_ATTRIBS];
+ /** Max data to put into dest buffer (in bytes) */
+ GLsizeiptr Size[MAX_FEEDBACK_ATTRIBS];
+};
+
+
+/**
+ * Context state for transform feedback.
+ */
+struct gl_transform_feedback
+{
+ GLenum Mode; /**< GL_POINTS, GL_LINES or GL_TRIANGLES */
+
+ GLboolean RasterDiscard; /**< GL_RASTERIZER_DISCARD */
+
+ /** The general binding point (GL_TRANSFORM_FEEDBACK_BUFFER) */
+ struct gl_buffer_object *CurrentBuffer;
+
+ /** The table of all transform feedback objects */
+ struct _mesa_HashTable *Objects;
+
+ /** The current xform-fb object (GL_TRANSFORM_FEEDBACK_BINDING) */
+ struct gl_transform_feedback_object *CurrentObject;
+
+ /** The default xform-fb object (Name==0) */
+ struct gl_transform_feedback_object *DefaultObject;
+};
+
+
+
+/**
+ * State which can be shared by multiple contexts:
+ */
+struct gl_shared_state
+{
+ _glthread_Mutex Mutex; /**< for thread safety */
+ GLint RefCount; /**< Reference count */
+ struct _mesa_HashTable *DisplayList; /**< Display lists hash table */
+ struct _mesa_HashTable *TexObjects; /**< Texture objects hash table */
+
+ /** Default texture objects (shared by all texture units) */
+ struct gl_texture_object *DefaultTex[NUM_TEXTURE_TARGETS];
+
+ /** Fallback texture used when a bound texture is incomplete */
+ struct gl_texture_object *FallbackTex;
+
+ /**
+ * \name Thread safety and statechange notification for texture
+ * objects.
+ *
+ * \todo Improve the granularity of locking.
+ */
+ /*@{*/
+ _glthread_Mutex TexMutex; /**< texobj thread safety */
+ GLuint TextureStateStamp; /**< state notification for shared tex */
+ /*@}*/
+
+ /** Default buffer object for vertex arrays that aren't in VBOs */
+ struct gl_buffer_object *NullBufferObj;
+
+ /**
+ * \name Vertex/geometry/fragment programs
+ */
+ /*@{*/
+ struct _mesa_HashTable *Programs; /**< All vertex/fragment programs */
+ struct gl_vertex_program *DefaultVertexProgram;
+ struct gl_fragment_program *DefaultFragmentProgram;
+ struct gl_geometry_program *DefaultGeometryProgram;
+ /*@}*/
+
+ /* GL_ATI_fragment_shader */
+ struct _mesa_HashTable *ATIShaders;
+ struct ati_fragment_shader *DefaultFragmentShader;
+
+ struct _mesa_HashTable *BufferObjects;
+
+ /** Table of both gl_shader and gl_shader_program objects */
+ struct _mesa_HashTable *ShaderObjects;
+
+ /* GL_EXT_framebuffer_object */
+ struct _mesa_HashTable *RenderBuffers;
+ struct _mesa_HashTable *FrameBuffers;
+
+ /* GL_ARB_sync */
+ struct simple_node SyncObjects;
+
+ void *DriverData; /**< Device driver shared state */
+};
+
+
+
+
+/**
+ * A renderbuffer stores colors or depth values or stencil values.
+ * A framebuffer object will have a collection of these.
+ * Data are read/written to the buffer with a handful of Get/Put functions.
+ *
+ * Instances of this object are allocated with the Driver's NewRenderbuffer
+ * hook. Drivers will likely wrap this class inside a driver-specific
+ * class to simulate inheritance.
+ */
+struct gl_renderbuffer
+{
+#define RB_MAGIC 0xaabbccdd
+ int Magic; /** XXX TEMPORARY DEBUG INFO */
+ _glthread_Mutex Mutex; /**< for thread safety */
+ GLuint ClassID; /**< Useful for drivers */
+ GLuint Name;
+ GLint RefCount;
+ GLuint Width, Height;
+ GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */
+
+ GLenum InternalFormat; /**< The user-specified format */
+ GLenum _BaseFormat; /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
+ GL_STENCIL_INDEX. */
+ gl_format Format; /**< The actual renderbuffer memory format */
+
+ GLubyte NumSamples;
+
+ GLenum DataType; /**< Type of values passed to the Get/Put functions */
+ GLvoid *Data; /**< This may not be used by some kinds of RBs */
+
+ /* Used to wrap one renderbuffer around another: */
+ struct gl_renderbuffer *Wrapped;
+
+ /* Delete this renderbuffer */
+ void (*Delete)(struct gl_renderbuffer *rb);
+
+ /* Allocate new storage for this renderbuffer */
+ GLboolean (*AllocStorage)(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLenum internalFormat,
+ GLuint width, GLuint height);
+
+ /* Lock/Unlock are called before/after calling the Get/Put functions.
+ * Not sure this is the right place for these yet.
+ void (*Lock)(struct gl_context *ctx, struct gl_renderbuffer *rb);
+ void (*Unlock)(struct gl_context *ctx, struct gl_renderbuffer *rb);
+ */
+
+ /* Return a pointer to the element/pixel at (x,y).
+ * Should return NULL if the buffer memory can't be directly addressed.
+ */
+ void *(*GetPointer)(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLint x, GLint y);
+
+ /* Get/Read a row of values.
+ * The values will be of format _BaseFormat and type DataType.
+ */
+ void (*GetRow)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, void *values);
+
+ /* Get/Read values at arbitrary locations.
+ * The values will be of format _BaseFormat and type DataType.
+ */
+ void (*GetValues)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], void *values);
+
+ /* Put/Write a row of values.
+ * The values will be of format _BaseFormat and type DataType.
+ */
+ void (*PutRow)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask);
+
+ /* Put/Write a row of RGB values. This is a special-case routine that's
+ * only used for RGBA renderbuffers when the source data is GL_RGB. That's
+ * a common case for glDrawPixels and some triangle routines.
+ * The values will be of format GL_RGB and type DataType.
+ */
+ void (*PutRowRGB)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *values, const GLubyte *mask);
+
+
+ /* Put/Write a row of identical values.
+ * The values will be of format _BaseFormat and type DataType.
+ */
+ void (*PutMonoRow)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ GLint x, GLint y, const void *value, const GLubyte *mask);
+
+ /* Put/Write values at arbitrary locations.
+ * The values will be of format _BaseFormat and type DataType.
+ */
+ void (*PutValues)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
+ const GLint x[], const GLint y[], const void *values,
+ const GLubyte *mask);
+ /* Put/Write identical values at arbitrary locations.
+ * The values will be of format _BaseFormat and type DataType.
+ */
+ void (*PutMonoValues)(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ GLuint count, const GLint x[], const GLint y[],
+ const void *value, const GLubyte *mask);
+};
+
+
+/**
+ * A renderbuffer attachment points to either a texture object (and specifies
+ * a mipmap level, cube face or 3D texture slice) or points to a renderbuffer.
+ */
+struct gl_renderbuffer_attachment
+{
+ GLenum Type; /**< \c GL_NONE or \c GL_TEXTURE or \c GL_RENDERBUFFER_EXT */
+ GLboolean Complete;
+
+ /**
+ * If \c Type is \c GL_RENDERBUFFER_EXT, this stores a pointer to the
+ * application supplied renderbuffer object.
+ */
+ struct gl_renderbuffer *Renderbuffer;
+
+ /**
+ * If \c Type is \c GL_TEXTURE, this stores a pointer to the application
+ * supplied texture object.
+ */
+ struct gl_texture_object *Texture;
+ GLuint TextureLevel; /**< Attached mipmap level. */
+ GLuint CubeMapFace; /**< 0 .. 5, for cube map textures. */
+ GLuint Zoffset; /**< Slice for 3D textures, or layer for both 1D
+ * and 2D array textures */
+};
+
+
+/**
+ * A framebuffer is a collection of renderbuffers (color, depth, stencil, etc).
+ * In C++ terms, think of this as a base class from which device drivers
+ * will make derived classes.
+ */
+struct gl_framebuffer
+{
+ _glthread_Mutex Mutex; /**< for thread safety */
+ /**
+ * If zero, this is a window system framebuffer. If non-zero, this
+ * is a FBO framebuffer; note that for some devices (i.e. those with
+ * a natural pixel coordinate system for FBOs that differs from the
+ * OpenGL/Mesa coordinate system), this means that the viewport,
+ * polygon face orientation, and polygon stipple will have to be inverted.
+ */
+ GLuint Name;
+
+ GLint RefCount;
+ GLboolean DeletePending;
+
+ /**
+ * The framebuffer's visual. Immutable if this is a window system buffer.
+ * Computed from attachments if user-made FBO.
+ */
+ struct gl_config Visual;
+
+ GLboolean Initialized;
+
+ GLuint Width, Height; /**< size of frame buffer in pixels */
+
+ /** \name Drawing bounds (Intersection of buffer size and scissor box) */
+ /*@{*/
+ GLint _Xmin, _Xmax; /**< inclusive */
+ GLint _Ymin, _Ymax; /**< exclusive */
+ /*@}*/
+
+ /** \name Derived Z buffer stuff */
+ /*@{*/
+ GLuint _DepthMax; /**< Max depth buffer value */
+ GLfloat _DepthMaxF; /**< Float max depth buffer value */
+ GLfloat _MRD; /**< minimum resolvable difference in Z values */
+ /*@}*/
+
+ /** One of the GL_FRAMEBUFFER_(IN)COMPLETE_* tokens */
+ GLenum _Status;
+
+ /** Integer color values */
+ GLboolean _IntegerColor;
+
+ /** Array of all renderbuffer attachments, indexed by BUFFER_* tokens. */
+ struct gl_renderbuffer_attachment Attachment[BUFFER_COUNT];
+
+ /* In unextended OpenGL these vars are part of the GL_COLOR_BUFFER
+ * attribute group and GL_PIXEL attribute group, respectively.
+ */
+ GLenum ColorDrawBuffer[MAX_DRAW_BUFFERS];
+ GLenum ColorReadBuffer;
+
+ /** Computed from ColorDraw/ReadBuffer above */
+ GLuint _NumColorDrawBuffers;
+ GLint _ColorDrawBufferIndexes[MAX_DRAW_BUFFERS]; /**< BUFFER_x or -1 */
+ GLint _ColorReadBufferIndex; /* -1 = None */
+ struct gl_renderbuffer *_ColorDrawBuffers[MAX_DRAW_BUFFERS];
+ struct gl_renderbuffer *_ColorReadBuffer;
+
+ /** The Actual depth/stencil buffers to use. May be wrappers around the
+ * depth/stencil buffers attached above. */
+ struct gl_renderbuffer *_DepthBuffer;
+ struct gl_renderbuffer *_StencilBuffer;
+
+ /** Delete this framebuffer */
+ void (*Delete)(struct gl_framebuffer *fb);
+};
+
+
+/**
+ * Precision info for shader datatypes. See glGetShaderPrecisionFormat().
+ */
+struct gl_precision
+{
+ GLushort RangeMin; /**< min value exponent */
+ GLushort RangeMax; /**< max value exponent */
+ GLushort Precision; /**< number of mantissa bits */
+};
+
+
+/**
+ * Limits for vertex and fragment programs/shaders.
+ */
+struct gl_program_constants
+{
+ /* logical limits */
+ GLuint MaxInstructions;
+ GLuint MaxAluInstructions;
+ GLuint MaxTexInstructions;
+ GLuint MaxTexIndirections;
+ GLuint MaxAttribs;
+ GLuint MaxTemps;
+ GLuint MaxAddressRegs;
+ GLuint MaxParameters;
+ GLuint MaxLocalParams;
+ GLuint MaxEnvParams;
+ /* native/hardware limits */
+ GLuint MaxNativeInstructions;
+ GLuint MaxNativeAluInstructions;
+ GLuint MaxNativeTexInstructions;
+ GLuint MaxNativeTexIndirections;
+ GLuint MaxNativeAttribs;
+ GLuint MaxNativeTemps;
+ GLuint MaxNativeAddressRegs;
+ GLuint MaxNativeParameters;
+ /* For shaders */
+ GLuint MaxUniformComponents;
+ /* GL_ARB_geometry_shader4 */
+ GLuint MaxGeometryTextureImageUnits;
+ GLuint MaxGeometryVaryingComponents;
+ GLuint MaxVertexVaryingComponents;
+ GLuint MaxGeometryUniformComponents;
+ GLuint MaxGeometryOutputVertices;
+ GLuint MaxGeometryTotalOutputComponents;
+ /* ES 2.0 and GL_ARB_ES2_compatibility */
+ struct gl_precision LowFloat, MediumFloat, HighFloat;
+ struct gl_precision LowInt, MediumInt, HighInt;
+};
+
+
+/**
+ * Constants which may be overridden by device driver during context creation
+ * but are never changed after that.
+ */
+struct gl_constants
+{
+ GLint MaxTextureMbytes; /**< Max memory per image, in MB */
+ GLint MaxTextureLevels; /**< Max mipmap levels. */
+ GLint Max3DTextureLevels; /**< Max mipmap levels for 3D textures */
+ GLint MaxCubeTextureLevels; /**< Max mipmap levels for cube textures */
+ GLint MaxArrayTextureLayers; /**< Max layers in array textures */
+ GLint MaxTextureRectSize; /**< Max rectangle texture size, in pixes */
+ GLuint MaxTextureCoordUnits;
+ GLuint MaxTextureImageUnits;
+ GLuint MaxVertexTextureImageUnits;
+ GLuint MaxCombinedTextureImageUnits;
+ GLuint MaxTextureUnits; /**< = MIN(CoordUnits, ImageUnits) */
+ GLfloat MaxTextureMaxAnisotropy; /**< GL_EXT_texture_filter_anisotropic */
+ GLfloat MaxTextureLodBias; /**< GL_EXT_texture_lod_bias */
+
+ GLuint MaxArrayLockSize;
+
+ GLint SubPixelBits;
+
+ GLfloat MinPointSize, MaxPointSize; /**< aliased */
+ GLfloat MinPointSizeAA, MaxPointSizeAA; /**< antialiased */
+ GLfloat PointSizeGranularity;
+ GLfloat MinLineWidth, MaxLineWidth; /**< aliased */
+ GLfloat MinLineWidthAA, MaxLineWidthAA; /**< antialiased */
+ GLfloat LineWidthGranularity;
+
+ GLuint MaxColorTableSize;
+
+ GLuint MaxClipPlanes;
+ GLuint MaxLights;
+ GLfloat MaxShininess; /**< GL_NV_light_max_exponent */
+ GLfloat MaxSpotExponent; /**< GL_NV_light_max_exponent */
+
+ GLuint MaxViewportWidth, MaxViewportHeight;
+
+ struct gl_program_constants VertexProgram; /**< GL_ARB_vertex_program */
+ struct gl_program_constants FragmentProgram; /**< GL_ARB_fragment_program */
+ struct gl_program_constants GeometryProgram; /**< GL_ARB_geometry_shader4 */
+ GLuint MaxProgramMatrices;
+ GLuint MaxProgramMatrixStackDepth;
+
+ /** vertex array / buffer object bounds checking */
+ GLboolean CheckArrayBounds;
+
+ GLuint MaxDrawBuffers; /**< GL_ARB_draw_buffers */
+
+ GLuint MaxColorAttachments; /**< GL_EXT_framebuffer_object */
+ GLuint MaxRenderbufferSize; /**< GL_EXT_framebuffer_object */
+ GLuint MaxSamples; /**< GL_ARB_framebuffer_object */
+
+ GLuint MaxVarying; /**< Number of float[4] varying parameters */
+
+ GLuint GLSLVersion; /**< GLSL version supported (ex: 120 = 1.20) */
+
+ /** Which texture units support GL_ATI_envmap_bumpmap as targets */
+ GLbitfield SupportedBumpUnits;
+
+ /**
+ * Maximum amount of time, measured in nanseconds, that the server can wait.
+ */
+ GLuint64 MaxServerWaitTimeout;
+
+ /** GL_EXT_provoking_vertex */
+ GLboolean QuadsFollowProvokingVertexConvention;
+
+ /** OpenGL version 3.0 */
+ GLbitfield ContextFlags; /**< Ex: GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT */
+
+ /** OpenGL version 3.2 */
+ GLbitfield ProfileMask; /**< Mask of CONTEXT_x_PROFILE_BIT */
+
+ /** GL_EXT_transform_feedback */
+ GLuint MaxTransformFeedbackSeparateAttribs;
+ GLuint MaxTransformFeedbackSeparateComponents;
+ GLuint MaxTransformFeedbackInterleavedComponents;
+
+ /** GL_EXT_gpu_shader4 */
+ GLint MinProgramTexelOffset, MaxProgramTexelOffset;
+
+ /* GL_EXT_framebuffer_sRGB */
+ GLboolean sRGBCapable; /* can enable sRGB blend/update on FBOs */
+};
+
+
+/**
+ * Enable flag for each OpenGL extension. Different device drivers will
+ * enable different extensions at runtime.
+ */
+struct gl_extensions
+{
+ GLboolean dummy; /* don't remove this! */
+ GLboolean dummy_true; /* Set true by _mesa_init_extensions(). */
+ GLboolean dummy_false; /* Set false by _mesa_init_extensions(). */
+ GLboolean ARB_ES2_compatibility;
+ GLboolean ARB_blend_func_extended;
+ GLboolean ARB_copy_buffer;
+ GLboolean ARB_depth_buffer_float;
+ GLboolean ARB_depth_clamp;
+ GLboolean ARB_depth_texture;
+ GLboolean ARB_draw_buffers;
+ GLboolean ARB_draw_buffers_blend;
+ GLboolean ARB_draw_elements_base_vertex;
+ GLboolean ARB_draw_instanced;
+ GLboolean ARB_fragment_coord_conventions;
+ GLboolean ARB_fragment_program;
+ GLboolean ARB_fragment_program_shadow;
+ GLboolean ARB_fragment_shader;
+ GLboolean ARB_framebuffer_object;
+ GLboolean ARB_explicit_attrib_location;
+ GLboolean ARB_geometry_shader4;
+ GLboolean ARB_half_float_pixel;
+ GLboolean ARB_half_float_vertex;
+ GLboolean ARB_instanced_arrays;
+ GLboolean ARB_map_buffer_range;
+ GLboolean ARB_multisample;
+ GLboolean ARB_multitexture;
+ GLboolean ARB_occlusion_query;
+ GLboolean ARB_occlusion_query2;
+ GLboolean ARB_point_sprite;
+ GLboolean ARB_sampler_objects;
+ GLboolean ARB_seamless_cube_map;
+ GLboolean ARB_shader_objects;
+ GLboolean ARB_shader_stencil_export;
+ GLboolean ARB_shading_language_100;
+ GLboolean ARB_shadow;
+ GLboolean ARB_shadow_ambient;
+ GLboolean ARB_sync;
+ GLboolean ARB_texture_border_clamp;
+ GLboolean ARB_texture_buffer_object;
+ GLboolean ARB_texture_compression;
+ GLboolean ARB_texture_compression_rgtc;
+ GLboolean ARB_texture_cube_map;
+ GLboolean ARB_texture_env_combine;
+ GLboolean ARB_texture_env_crossbar;
+ GLboolean ARB_texture_env_dot3;
+ GLboolean ARB_texture_float;
+ GLboolean ARB_texture_mirrored_repeat;
+ GLboolean ARB_texture_multisample;
+ GLboolean ARB_texture_non_power_of_two;
+ GLboolean ARB_texture_rg;
+ GLboolean ARB_texture_rgb10_a2ui;
+ GLboolean ARB_timer_query;
+ GLboolean ARB_transform_feedback2;
+ GLboolean ARB_transpose_matrix;
+ GLboolean ARB_uniform_buffer_object;
+ GLboolean ARB_vertex_array_object;
+ GLboolean ARB_vertex_buffer_object;
+ GLboolean ARB_vertex_program;
+ GLboolean ARB_vertex_shader;
+ GLboolean ARB_vertex_type_2_10_10_10_rev;
+ GLboolean ARB_window_pos;
+ GLboolean EXT_abgr;
+ GLboolean EXT_bgra;
+ GLboolean EXT_blend_color;
+ GLboolean EXT_blend_equation_separate;
+ GLboolean EXT_blend_func_separate;
+ GLboolean EXT_blend_logic_op;
+ GLboolean EXT_blend_minmax;
+ GLboolean EXT_blend_subtract;
+ GLboolean EXT_clip_volume_hint;
+ GLboolean EXT_compiled_vertex_array;
+ GLboolean EXT_copy_texture;
+ GLboolean EXT_depth_bounds_test;
+ GLboolean EXT_draw_buffers2;
+ GLboolean EXT_draw_range_elements;
+ GLboolean EXT_fog_coord;
+ GLboolean EXT_framebuffer_blit;
+ GLboolean EXT_framebuffer_multisample;
+ GLboolean EXT_framebuffer_object;
+ GLboolean EXT_framebuffer_sRGB;
+ GLboolean EXT_gpu_program_parameters;
+ GLboolean EXT_gpu_shader4;
+ GLboolean EXT_multi_draw_arrays;
+ GLboolean EXT_paletted_texture;
+ GLboolean EXT_packed_depth_stencil;
+ GLboolean EXT_packed_float;
+ GLboolean EXT_packed_pixels;
+ GLboolean EXT_pixel_buffer_object;
+ GLboolean EXT_point_parameters;
+ GLboolean EXT_polygon_offset;
+ GLboolean EXT_provoking_vertex;
+ GLboolean EXT_rescale_normal;
+ GLboolean EXT_shadow_funcs;
+ GLboolean EXT_secondary_color;
+ GLboolean EXT_separate_shader_objects;
+ GLboolean EXT_separate_specular_color;
+ GLboolean EXT_shared_texture_palette;
+ GLboolean EXT_stencil_wrap;
+ GLboolean EXT_stencil_two_side;
+ GLboolean EXT_subtexture;
+ GLboolean EXT_texture;
+ GLboolean EXT_texture_object;
+ GLboolean EXT_texture3D;
+ GLboolean EXT_texture_array;
+ GLboolean EXT_texture_compression_s3tc;
+ GLboolean EXT_texture_env_add;
+ GLboolean EXT_texture_env_combine;
+ GLboolean EXT_texture_env_dot3;
+ GLboolean EXT_texture_filter_anisotropic;
+ GLboolean EXT_texture_integer;
+ GLboolean EXT_texture_lod_bias;
+ GLboolean EXT_texture_mirror_clamp;
+ GLboolean EXT_texture_shared_exponent;
+ GLboolean EXT_texture_sRGB;
+ GLboolean EXT_texture_sRGB_decode;
+ GLboolean EXT_texture_swizzle;
+ GLboolean EXT_transform_feedback;
+ GLboolean EXT_timer_query;
+ GLboolean EXT_vertex_array;
+ GLboolean EXT_vertex_array_bgra;
+ GLboolean EXT_vertex_array_set;
+ GLboolean OES_standard_derivatives;
+ /* vendor extensions */
+ GLboolean AMD_conservative_depth;
+ GLboolean APPLE_client_storage;
+ GLboolean APPLE_packed_pixels;
+ GLboolean APPLE_vertex_array_object;
+ GLboolean APPLE_object_purgeable;
+ GLboolean ATI_envmap_bumpmap;
+ GLboolean ATI_texture_mirror_once;
+ GLboolean ATI_texture_env_combine3;
+ GLboolean ATI_fragment_shader;
+ GLboolean ATI_separate_stencil;
+ GLboolean IBM_rasterpos_clip;
+ GLboolean IBM_multimode_draw_arrays;
+ GLboolean MESA_pack_invert;
+ GLboolean MESA_resize_buffers;
+ GLboolean MESA_ycbcr_texture;
+ GLboolean MESA_texture_array;
+ GLboolean MESA_texture_signed_rgba;
+ GLboolean NV_blend_square;
+ GLboolean NV_conditional_render;
+ GLboolean NV_fragment_program;
+ GLboolean NV_fragment_program_option;
+ GLboolean NV_light_max_exponent;
+ GLboolean NV_point_sprite;
+ GLboolean NV_primitive_restart;
+ GLboolean NV_texgen_reflection;
+ GLboolean NV_texture_env_combine4;
+ GLboolean NV_texture_rectangle;
+ GLboolean NV_vertex_program;
+ GLboolean NV_vertex_program1_1;
+ GLboolean OES_read_format;
+ GLboolean SGIS_generate_mipmap;
+ GLboolean SGIS_texture_edge_clamp;
+ GLboolean SGIS_texture_lod;
+ GLboolean TDFX_texture_compression_FXT1;
+ GLboolean S3_s3tc;
+ GLboolean OES_EGL_image;
+ GLboolean OES_draw_texture;
+ GLboolean EXT_texture_format_BGRA8888;
+ GLboolean extension_sentinel;
+ /** The extension string */
+ const GLubyte *String;
+ /** Number of supported extensions */
+ GLuint Count;
+};
+
+
+/**
+ * A stack of matrices (projection, modelview, color, texture, etc).
+ */
+struct gl_matrix_stack
+{
+ GLmatrix *Top; /**< points into Stack */
+ GLmatrix *Stack; /**< array [MaxDepth] of GLmatrix */
+ GLuint Depth; /**< 0 <= Depth < MaxDepth */
+ GLuint MaxDepth; /**< size of Stack[] array */
+ GLuint DirtyFlag; /**< _NEW_MODELVIEW or _NEW_PROJECTION, for example */
+};
+
+
+/**
+ * \name Bits for image transfer operations
+ * \sa __struct gl_contextRec::ImageTransferState.
+ */
+/*@{*/
+#define IMAGE_SCALE_BIAS_BIT 0x1
+#define IMAGE_SHIFT_OFFSET_BIT 0x2
+#define IMAGE_MAP_COLOR_BIT 0x4
+#define IMAGE_CLAMP_BIT 0x800
+
+
+/** Pixel Transfer ops */
+#define IMAGE_BITS (IMAGE_SCALE_BIAS_BIT | \
+ IMAGE_SHIFT_OFFSET_BIT | \
+ IMAGE_MAP_COLOR_BIT)
+
+/**
+ * \name Bits to indicate what state has changed.
+ */
+/*@{*/
+#define _NEW_MODELVIEW (1 << 0) /**< gl_context::ModelView */
+#define _NEW_PROJECTION (1 << 1) /**< gl_context::Projection */
+#define _NEW_TEXTURE_MATRIX (1 << 2) /**< gl_context::TextureMatrix */
+#define _NEW_COLOR (1 << 3) /**< gl_context::Color */
+#define _NEW_DEPTH (1 << 4) /**< gl_context::Depth */
+#define _NEW_EVAL (1 << 5) /**< gl_context::Eval, EvalMap */
+#define _NEW_FOG (1 << 6) /**< gl_context::Fog */
+#define _NEW_HINT (1 << 7) /**< gl_context::Hint */
+#define _NEW_LIGHT (1 << 8) /**< gl_context::Light */
+#define _NEW_LINE (1 << 9) /**< gl_context::Line */
+#define _NEW_PIXEL (1 << 10) /**< gl_context::Pixel */
+#define _NEW_POINT (1 << 11) /**< gl_context::Point */
+#define _NEW_POLYGON (1 << 12) /**< gl_context::Polygon */
+#define _NEW_POLYGONSTIPPLE (1 << 13) /**< gl_context::PolygonStipple */
+#define _NEW_SCISSOR (1 << 14) /**< gl_context::Scissor */
+#define _NEW_STENCIL (1 << 15) /**< gl_context::Stencil */
+#define _NEW_TEXTURE (1 << 16) /**< gl_context::Texture */
+#define _NEW_TRANSFORM (1 << 17) /**< gl_context::Transform */
+#define _NEW_VIEWPORT (1 << 18) /**< gl_context::Viewport */
+#define _NEW_PACKUNPACK (1 << 19) /**< gl_context::Pack, Unpack */
+#define _NEW_ARRAY (1 << 20) /**< gl_context::Array */
+#define _NEW_RENDERMODE (1 << 21) /**< gl_context::RenderMode, etc */
+#define _NEW_BUFFERS (1 << 22) /**< gl_context::Visual, DrawBuffer, */
+#define _NEW_CURRENT_ATTRIB (1 << 23) /**< gl_context::Current */
+#define _NEW_MULTISAMPLE (1 << 24) /**< gl_context::Multisample */
+#define _NEW_TRACK_MATRIX (1 << 25) /**< gl_context::VertexProgram */
+#define _NEW_PROGRAM (1 << 26) /**< New program/shader state */
+#define _NEW_PROGRAM_CONSTANTS (1 << 27)
+#define _NEW_BUFFER_OBJECT (1 << 28)
+#define _NEW_ALL ~0
+/*@}*/
+
+
+/**
+ * \name Bits to track array state changes
+ *
+ * Also used to summarize array enabled.
+ */
+/*@{*/
+#define _NEW_ARRAY_VERTEX VERT_BIT_POS
+#define _NEW_ARRAY_WEIGHT VERT_BIT_WEIGHT
+#define _NEW_ARRAY_NORMAL VERT_BIT_NORMAL
+#define _NEW_ARRAY_COLOR0 VERT_BIT_COLOR0
+#define _NEW_ARRAY_COLOR1 VERT_BIT_COLOR1
+#define _NEW_ARRAY_FOGCOORD VERT_BIT_FOG
+#define _NEW_ARRAY_INDEX VERT_BIT_COLOR_INDEX
+#define _NEW_ARRAY_EDGEFLAG VERT_BIT_EDGEFLAG
+#define _NEW_ARRAY_POINT_SIZE VERT_BIT_COLOR_INDEX /* aliased */
+#define _NEW_ARRAY_TEXCOORD_0 VERT_BIT_TEX0
+#define _NEW_ARRAY_TEXCOORD_1 VERT_BIT_TEX1
+#define _NEW_ARRAY_TEXCOORD_2 VERT_BIT_TEX2
+#define _NEW_ARRAY_TEXCOORD_3 VERT_BIT_TEX3
+#define _NEW_ARRAY_TEXCOORD_4 VERT_BIT_TEX4
+#define _NEW_ARRAY_TEXCOORD_5 VERT_BIT_TEX5
+#define _NEW_ARRAY_TEXCOORD_6 VERT_BIT_TEX6
+#define _NEW_ARRAY_TEXCOORD_7 VERT_BIT_TEX7
+#define _NEW_ARRAY_ATTRIB_0 VERT_BIT_GENERIC0 /* start at bit 16 */
+#define _NEW_ARRAY_ALL 0xffffffff
+
+
+#define _NEW_ARRAY_TEXCOORD(i) (_NEW_ARRAY_TEXCOORD_0 << (i))
+#define _NEW_ARRAY_ATTRIB(i) (_NEW_ARRAY_ATTRIB_0 << (i))
+/*@}*/
+
+
+
+/**
+ * \name A bunch of flags that we think might be useful to drivers.
+ *
+ * Set in the __struct gl_contextRec::_TriangleCaps bitfield.
+ */
+/*@{*/
+#define DD_FLATSHADE 0x1
+#define DD_SEPARATE_SPECULAR 0x2
+#define DD_TRI_CULL_FRONT_BACK 0x4 /* special case on some hw */
+#define DD_TRI_LIGHT_TWOSIDE 0x8
+#define DD_TRI_UNFILLED 0x10
+#define DD_TRI_SMOOTH 0x20
+#define DD_TRI_STIPPLE 0x40
+#define DD_TRI_OFFSET 0x80
+#define DD_LINE_SMOOTH 0x100
+#define DD_LINE_STIPPLE 0x200
+#define DD_POINT_SMOOTH 0x400
+#define DD_POINT_ATTEN 0x800
+#define DD_TRI_TWOSTENCIL 0x1000
+/*@}*/
+
+
+/**
+ * \name Define the state changes under which each of these bits might change
+ */
+/*@{*/
+#define _DD_NEW_FLATSHADE _NEW_LIGHT
+#define _DD_NEW_SEPARATE_SPECULAR (_NEW_LIGHT | _NEW_FOG | _NEW_PROGRAM)
+#define _DD_NEW_TRI_CULL_FRONT_BACK _NEW_POLYGON
+#define _DD_NEW_TRI_LIGHT_TWOSIDE _NEW_LIGHT
+#define _DD_NEW_TRI_UNFILLED _NEW_POLYGON
+#define _DD_NEW_TRI_SMOOTH _NEW_POLYGON
+#define _DD_NEW_TRI_STIPPLE _NEW_POLYGON
+#define _DD_NEW_TRI_OFFSET _NEW_POLYGON
+#define _DD_NEW_LINE_SMOOTH _NEW_LINE
+#define _DD_NEW_LINE_STIPPLE _NEW_LINE
+#define _DD_NEW_LINE_WIDTH _NEW_LINE
+#define _DD_NEW_POINT_SMOOTH _NEW_POINT
+#define _DD_NEW_POINT_SIZE _NEW_POINT
+#define _DD_NEW_POINT_ATTEN _NEW_POINT
+/*@}*/
+
+
+/**
+ * Composite state flags
+ */
+/*@{*/
+#define _MESA_NEW_NEED_EYE_COORDS (_NEW_LIGHT | \
+ _NEW_TEXTURE | \
+ _NEW_POINT | \
+ _NEW_PROGRAM | \
+ _NEW_MODELVIEW)
+
+#define _MESA_NEW_NEED_NORMALS (_NEW_LIGHT | \
+ _NEW_TEXTURE)
+
+#define _MESA_NEW_TRANSFER_STATE (_NEW_PIXEL)
+/*@}*/
+
+
+
+
+/* This has to be included here. */
+#include "dd.h"
+
+
+/**
+ * Display list flags.
+ * Strictly this is a tnl-private concept, but it doesn't seem
+ * worthwhile adding a tnl private structure just to hold this one bit
+ * of information:
+ */
+#define DLIST_DANGLING_REFS 0x1
+
+
+/** Opaque declaration of display list payload data type */
+union gl_dlist_node;
+
+
+/**
+ * Provide a location where information about a display list can be
+ * collected. Could be extended with driverPrivate structures,
+ * etc. in the future.
+ */
+struct gl_display_list
+{
+ GLuint Name;
+ GLbitfield Flags; /**< DLIST_x flags */
+ /** The dlist commands are in a linked list of nodes */
+ union gl_dlist_node *Head;
+};
+
+
+/**
+ * State used during display list compilation and execution.
+ */
+struct gl_dlist_state
+{
+ GLuint CallDepth; /**< Current recursion calling depth */
+
+ struct gl_display_list *CurrentList; /**< List currently being compiled */
+ union gl_dlist_node *CurrentBlock; /**< Pointer to current block of nodes */
+ GLuint CurrentPos; /**< Index into current block of nodes */
+
+ GLvertexformat ListVtxfmt;
+
+ GLubyte ActiveAttribSize[VERT_ATTRIB_MAX];
+ GLfloat CurrentAttrib[VERT_ATTRIB_MAX][4];
+
+ GLubyte ActiveMaterialSize[MAT_ATTRIB_MAX];
+ GLfloat CurrentMaterial[MAT_ATTRIB_MAX][4];
+
+ GLubyte ActiveIndex;
+ GLfloat CurrentIndex;
+
+ GLubyte ActiveEdgeFlag;
+ GLboolean CurrentEdgeFlag;
+
+ struct {
+ /* State known to have been set by the currently-compiling display
+ * list. Used to eliminate some redundant state changes.
+ */
+ GLenum ShadeModel;
+ } Current;
+};
+
+
+/**
+ * Enum for the OpenGL APIs we know about and may support.
+ */
+typedef enum
+{
+ API_OPENGL,
+ API_OPENGLES,
+ API_OPENGLES2
+} gl_api;
+
+
+/**
+ * Mesa rendering context.
+ *
+ * This is the central context data structure for Mesa. Almost all
+ * OpenGL state is contained in this structure.
+ * Think of this as a base class from which device drivers will derive
+ * sub classes.
+ *
+ * The struct gl_context typedef names this structure.
+ */
+struct gl_context
+{
+ /** State possibly shared with other contexts in the address space */
+ struct gl_shared_state *Shared;
+
+ /** \name API function pointer tables */
+ /*@{*/
+ gl_api API;
+ struct _glapi_table *Save; /**< Display list save functions */
+ struct _glapi_table *Exec; /**< Execute functions */
+ struct _glapi_table *CurrentDispatch; /**< == Save or Exec !! */
+ /*@}*/
+
+ struct gl_config Visual;
+ struct gl_framebuffer *DrawBuffer; /**< buffer for writing */
+ struct gl_framebuffer *ReadBuffer; /**< buffer for reading */
+ struct gl_framebuffer *WinSysDrawBuffer; /**< set with MakeCurrent */
+ struct gl_framebuffer *WinSysReadBuffer; /**< set with MakeCurrent */
+
+ /**
+ * Device driver function pointer table
+ */
+ struct dd_function_table Driver;
+
+ void *DriverCtx; /**< Points to device driver context/state */
+
+ /** Core/Driver constants */
+ struct gl_constants Const;
+
+ /** \name The various 4x4 matrix stacks */
+ /*@{*/
+ struct gl_matrix_stack ModelviewMatrixStack;
+ struct gl_matrix_stack ProjectionMatrixStack;
+ struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_UNITS];
+ struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
+ struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */
+ /*@}*/
+
+ /** Combined modelview and projection matrix */
+ GLmatrix _ModelProjectMatrix;
+
+ /** \name Display lists */
+ struct gl_dlist_state ListState;
+
+ GLboolean ExecuteFlag; /**< Execute GL commands? */
+ GLboolean CompileFlag; /**< Compile GL commands into display list? */
+
+ /** Extension information */
+ struct gl_extensions Extensions;
+
+ /** Version info */
+ GLuint VersionMajor, VersionMinor;
+ char *VersionString;
+
+ /** \name State attribute stack (for glPush/PopAttrib) */
+ /*@{*/
+ GLuint AttribStackDepth;
+ struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
+ /*@}*/
+
+ /** \name Renderer attribute groups
+ *
+ * We define a struct for each attribute group to make pushing and popping
+ * attributes easy. Also it's a good organization.
+ */
+ /*@{*/
+ struct gl_accum_attrib Accum; /**< Accum buffer attributes */
+ struct gl_colorbuffer_attrib Color; /**< Color buffer attributes */
+ struct gl_current_attrib Current; /**< Current attributes */
+ struct gl_depthbuffer_attrib Depth; /**< Depth buffer attributes */
+ struct gl_eval_attrib Eval; /**< Eval attributes */
+ struct gl_fog_attrib Fog; /**< Fog attributes */
+ struct gl_hint_attrib Hint; /**< Hint attributes */
+ struct gl_light_attrib Light; /**< Light attributes */
+ struct gl_line_attrib Line; /**< Line attributes */
+ struct gl_list_attrib List; /**< List attributes */
+ struct gl_multisample_attrib Multisample;
+ struct gl_pixel_attrib Pixel; /**< Pixel attributes */
+ struct gl_point_attrib Point; /**< Point attributes */
+ struct gl_polygon_attrib Polygon; /**< Polygon attributes */
+ GLuint PolygonStipple[32]; /**< Polygon stipple */
+ struct gl_scissor_attrib Scissor; /**< Scissor attributes */
+ struct gl_stencil_attrib Stencil; /**< Stencil buffer attributes */
+ struct gl_texture_attrib Texture; /**< Texture attributes */
+ struct gl_transform_attrib Transform; /**< Transformation attributes */
+ struct gl_viewport_attrib Viewport; /**< Viewport attributes */
+ /*@}*/
+
+ /** \name Client attribute stack */
+ /*@{*/
+ GLuint ClientAttribStackDepth;
+ struct gl_attrib_node *ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH];
+ /*@}*/
+
+ /** \name Client attribute groups */
+ /*@{*/
+ struct gl_array_attrib Array; /**< Vertex arrays */
+ struct gl_pixelstore_attrib Pack; /**< Pixel packing */
+ struct gl_pixelstore_attrib Unpack; /**< Pixel unpacking */
+ struct gl_pixelstore_attrib DefaultPacking; /**< Default params */
+ /*@}*/
+
+ /** \name Other assorted state (not pushed/popped on attribute stack) */
+ /*@{*/
+ struct gl_pixelmaps PixelMaps;
+
+ struct gl_evaluators EvalMap; /**< All evaluators */
+ struct gl_feedback Feedback; /**< Feedback */
+ struct gl_selection Select; /**< Selection */
+
+ struct gl_program_state Program; /**< general program state */
+ struct gl_vertex_program_state VertexProgram;
+ struct gl_fragment_program_state FragmentProgram;
+ struct gl_geometry_program_state GeometryProgram;
+ struct gl_ati_fragment_shader_state ATIFragmentShader;
+
+ struct gl_shader_state Shader; /**< GLSL shader object state */
+ struct gl_shader_compiler_options ShaderCompilerOptions[MESA_SHADER_TYPES];
+
+ struct gl_query_state Query; /**< occlusion, timer queries */
+
+ struct gl_transform_feedback TransformFeedback;
+
+ struct gl_buffer_object *CopyReadBuffer; /**< GL_ARB_copy_buffer */
+ struct gl_buffer_object *CopyWriteBuffer; /**< GL_ARB_copy_buffer */
+ /*@}*/
+
+ struct gl_meta_state *Meta; /**< for "meta" operations */
+
+ /* GL_EXT_framebuffer_object */
+ struct gl_renderbuffer *CurrentRenderbuffer;
+
+ GLenum ErrorValue; /**< Last error code */
+
+ /**
+ * Recognize and silence repeated error debug messages in buggy apps.
+ */
+ const char *ErrorDebugFmtString;
+ GLuint ErrorDebugCount;
+
+ GLenum RenderMode; /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
+ GLbitfield NewState; /**< bitwise-or of _NEW_* flags */
+
+ GLboolean ViewportInitialized; /**< has viewport size been initialized? */
+
+ GLbitfield varying_vp_inputs; /**< mask of VERT_BIT_* flags */
+
+ /** \name Derived state */
+ /*@{*/
+ /** Bitwise-or of DD_* flags. Note that this bitfield may be used before
+ * state validation so they need to always be current.
+ */
+ GLbitfield _TriangleCaps;
+ GLbitfield _ImageTransferState;/**< bitwise-or of IMAGE_*_BIT flags */
+ GLfloat _EyeZDir[3];
+ GLfloat _ModelViewInvScale;
+ GLboolean _NeedEyeCoords;
+ GLboolean _ForceEyeCoords;
+
+ GLuint TextureStateTimestamp; /**< detect changes to shared state */
+
+ struct gl_shine_tab *_ShineTable[2]; /**< Active shine tables */
+ struct gl_shine_tab *_ShineTabList; /**< MRU list of inactive shine tables */
+ /**@}*/
+
+ struct gl_list_extensions *ListExt; /**< driver dlist extensions */
+
+ /** \name For debugging/development only */
+ /*@{*/
+ GLboolean FirstTimeCurrent;
+ /*@}*/
+
+ /** software compression/decompression supported or not */
+ GLboolean Mesa_DXTn;
+
+ GLboolean TextureFormatSupported[MESA_FORMAT_COUNT];
+
+ /**
+ * Use dp4 (rather than mul/mad) instructions for position
+ * transformation?
+ */
+ GLboolean mvp_with_dp4;
+
+ /**
+ * \name Hooks for module contexts.
+ *
+ * These will eventually live in the driver or elsewhere.
+ */
+ /*@{*/
+ void *swrast_context;
+ void *swsetup_context;
+ void *swtnl_context;
+ void *swtnl_im;
+ struct st_context *st;
+ void *aelt_context;
+ /*@}*/
+};
+
+
+#ifdef DEBUG
+extern int MESA_VERBOSE;
+extern int MESA_DEBUG_FLAGS;
+# define MESA_FUNCTION __FUNCTION__
+#else
+# define MESA_VERBOSE 0
+# define MESA_DEBUG_FLAGS 0
+# define MESA_FUNCTION "a function"
+# ifndef NDEBUG
+# define NDEBUG
+# endif
+#endif
+
+
+/** The MESA_VERBOSE var is a bitmask of these flags */
+enum _verbose
+{
+ VERBOSE_VARRAY = 0x0001,
+ VERBOSE_TEXTURE = 0x0002,
+ VERBOSE_MATERIAL = 0x0004,
+ VERBOSE_PIPELINE = 0x0008,
+ VERBOSE_DRIVER = 0x0010,
+ VERBOSE_STATE = 0x0020,
+ VERBOSE_API = 0x0040,
+ VERBOSE_DISPLAY_LIST = 0x0100,
+ VERBOSE_LIGHTING = 0x0200,
+ VERBOSE_PRIMS = 0x0400,
+ VERBOSE_VERTS = 0x0800,
+ VERBOSE_DISASSEM = 0x1000,
+ VERBOSE_DRAW = 0x2000,
+ VERBOSE_SWAPBUFFERS = 0x4000
+};
+
+
+/** The MESA_DEBUG_FLAGS var is a bitmask of these flags */
+enum _debug
+{
+ DEBUG_ALWAYS_FLUSH = 0x1
+};
+
+
+
+#endif /* MTYPES_H */
diff --git a/mesalib/src/mesa/main/pixel.c b/mesalib/src/mesa/main/pixel.c
index 195fa234b..55e368c36 100644
--- a/mesalib/src/mesa/main/pixel.c
+++ b/mesalib/src/mesa/main/pixel.c
@@ -1,699 +1,699 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file pixel.c
- * Pixel transfer functions (glPixelZoom, glPixelMap, glPixelTransfer)
- */
-
-#include "glheader.h"
-#include "bufferobj.h"
-#include "colormac.h"
-#include "context.h"
-#include "macros.h"
-#include "mfeatures.h"
-#include "pixel.h"
-#include "pbo.h"
-#include "mtypes.h"
-#include "main/dispatch.h"
-
-
-#if FEATURE_pixel_transfer
-
-
-/**********************************************************************/
-/***** glPixelZoom *****/
-/**********************************************************************/
-
-static void GLAPIENTRY
-_mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor )
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if (ctx->Pixel.ZoomX == xfactor &&
- ctx->Pixel.ZoomY == yfactor)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.ZoomX = xfactor;
- ctx->Pixel.ZoomY = yfactor;
-}
-
-
-
-/**********************************************************************/
-/***** glPixelMap *****/
-/**********************************************************************/
-
-/**
- * Return pointer to a pixelmap by name.
- */
-static struct gl_pixelmap *
-get_pixelmap(struct gl_context *ctx, GLenum map)
-{
- switch (map) {
- case GL_PIXEL_MAP_I_TO_I:
- return &ctx->PixelMaps.ItoI;
- case GL_PIXEL_MAP_S_TO_S:
- return &ctx->PixelMaps.StoS;
- case GL_PIXEL_MAP_I_TO_R:
- return &ctx->PixelMaps.ItoR;
- case GL_PIXEL_MAP_I_TO_G:
- return &ctx->PixelMaps.ItoG;
- case GL_PIXEL_MAP_I_TO_B:
- return &ctx->PixelMaps.ItoB;
- case GL_PIXEL_MAP_I_TO_A:
- return &ctx->PixelMaps.ItoA;
- case GL_PIXEL_MAP_R_TO_R:
- return &ctx->PixelMaps.RtoR;
- case GL_PIXEL_MAP_G_TO_G:
- return &ctx->PixelMaps.GtoG;
- case GL_PIXEL_MAP_B_TO_B:
- return &ctx->PixelMaps.BtoB;
- case GL_PIXEL_MAP_A_TO_A:
- return &ctx->PixelMaps.AtoA;
- default:
- return NULL;
- }
-}
-
-
-/**
- * Helper routine used by the other _mesa_PixelMap() functions.
- */
-static void
-store_pixelmap(struct gl_context *ctx, GLenum map, GLsizei mapsize,
- const GLfloat *values)
-{
- GLint i;
- struct gl_pixelmap *pm = get_pixelmap(ctx, map);
- if (!pm) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glPixelMap(map)");
- return;
- }
-
- switch (map) {
- case GL_PIXEL_MAP_S_TO_S:
- /* special case */
- ctx->PixelMaps.StoS.Size = mapsize;
- for (i = 0; i < mapsize; i++) {
- ctx->PixelMaps.StoS.Map[i] = (GLfloat)IROUND(values[i]);
- }
- break;
- case GL_PIXEL_MAP_I_TO_I:
- /* special case */
- ctx->PixelMaps.ItoI.Size = mapsize;
- for (i = 0; i < mapsize; i++) {
- ctx->PixelMaps.ItoI.Map[i] = values[i];
- }
- break;
- default:
- /* general case */
- pm->Size = mapsize;
- for (i = 0; i < mapsize; i++) {
- GLfloat val = CLAMP(values[i], 0.0F, 1.0F);
- pm->Map[i] = val;
- pm->Map8[i] = (GLint) (val * 255.0F);
- }
- }
-}
-
-
-/**
- * Convenience wrapper for _mesa_validate_pbo_access() for gl[Get]PixelMap().
- */
-static GLboolean
-validate_pbo_access(struct gl_context *ctx, struct gl_pixelstore_attrib *pack,
- GLsizei mapsize, GLenum format, GLenum type,
- const GLvoid *ptr)
-{
- GLboolean ok;
-
- /* Note, need to use DefaultPacking and Unpack's buffer object */
- _mesa_reference_buffer_object(ctx,
- &ctx->DefaultPacking.BufferObj,
- pack->BufferObj);
-
- ok = _mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
- format, type, ptr);
-
- /* restore */
- _mesa_reference_buffer_object(ctx,
- &ctx->DefaultPacking.BufferObj,
- ctx->Shared->NullBufferObj);
-
- if (!ok) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glPixelMap(invalid PBO access)");
- }
- return ok;
-}
-
-
-static void GLAPIENTRY
-_mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- /* XXX someday, test against ctx->Const.MaxPixelMapTableSize */
- if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
- return;
- }
-
- if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
- /* test that mapsize is a power of two */
- if (!_mesa_is_pow_two(mapsize)) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
- return;
- }
- }
-
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
-
- if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize,
- GL_INTENSITY, GL_FLOAT, values)) {
- return;
- }
-
- values = (const GLfloat *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
- if (!values) {
- if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glPixelMapfv(PBO is mapped)");
- }
- return;
- }
-
- store_pixelmap(ctx, map, mapsize, values);
-
- _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
-}
-
-
-static void GLAPIENTRY
-_mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
-{
- GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
- return;
- }
-
- if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
- /* test that mapsize is a power of two */
- if (!_mesa_is_pow_two(mapsize)) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
- return;
- }
- }
-
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
-
- if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize,
- GL_INTENSITY, GL_UNSIGNED_INT, values)) {
- return;
- }
-
- values = (const GLuint *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
- if (!values) {
- if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glPixelMapuiv(PBO is mapped)");
- }
- return;
- }
-
- /* convert to floats */
- if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
- GLint i;
- for (i = 0; i < mapsize; i++) {
- fvalues[i] = (GLfloat) values[i];
- }
- }
- else {
- GLint i;
- for (i = 0; i < mapsize; i++) {
- fvalues[i] = UINT_TO_FLOAT( values[i] );
- }
- }
-
- _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
-
- store_pixelmap(ctx, map, mapsize, fvalues);
-}
-
-
-static void GLAPIENTRY
-_mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
-{
- GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapusv(mapsize)" );
- return;
- }
-
- if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
- /* test that mapsize is a power of two */
- if (!_mesa_is_pow_two(mapsize)) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
- return;
- }
- }
-
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
-
- if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize,
- GL_INTENSITY, GL_UNSIGNED_SHORT, values)) {
- return;
- }
-
- values = (const GLushort *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
- if (!values) {
- if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glPixelMapusv(PBO is mapped)");
- }
- return;
- }
-
- /* convert to floats */
- if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
- GLint i;
- for (i = 0; i < mapsize; i++) {
- fvalues[i] = (GLfloat) values[i];
- }
- }
- else {
- GLint i;
- for (i = 0; i < mapsize; i++) {
- fvalues[i] = USHORT_TO_FLOAT( values[i] );
- }
- }
-
- _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
-
- store_pixelmap(ctx, map, mapsize, fvalues);
-}
-
-
-static void GLAPIENTRY
-_mesa_GetPixelMapfv( GLenum map, GLfloat *values )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint mapsize, i;
- const struct gl_pixelmap *pm;
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- pm = get_pixelmap(ctx, map);
- if (!pm) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapfv(map)");
- return;
- }
-
- mapsize = pm->Size;
-
- if (!validate_pbo_access(ctx, &ctx->Pack, mapsize,
- GL_INTENSITY, GL_FLOAT, values)) {
- return;
- }
-
- values = (GLfloat *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
- if (!values) {
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetPixelMapfv(PBO is mapped)");
- }
- return;
- }
-
- if (map == GL_PIXEL_MAP_S_TO_S) {
- /* special case */
- for (i = 0; i < mapsize; i++) {
- values[i] = (GLfloat) ctx->PixelMaps.StoS.Map[i];
- }
- }
- else {
- memcpy(values, pm->Map, mapsize * sizeof(GLfloat));
- }
-
- _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
-}
-
-
-static void GLAPIENTRY
-_mesa_GetPixelMapuiv( GLenum map, GLuint *values )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint mapsize, i;
- const struct gl_pixelmap *pm;
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- pm = get_pixelmap(ctx, map);
- if (!pm) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapuiv(map)");
- return;
- }
- mapsize = pm->Size;
-
- if (!validate_pbo_access(ctx, &ctx->Pack, mapsize,
- GL_INTENSITY, GL_UNSIGNED_INT, values)) {
- return;
- }
-
- values = (GLuint *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
- if (!values) {
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetPixelMapuiv(PBO is mapped)");
- }
- return;
- }
-
- if (map == GL_PIXEL_MAP_S_TO_S) {
- /* special case */
- memcpy(values, ctx->PixelMaps.StoS.Map, mapsize * sizeof(GLint));
- }
- else {
- for (i = 0; i < mapsize; i++) {
- values[i] = FLOAT_TO_UINT( pm->Map[i] );
- }
- }
-
- _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
-}
-
-
-static void GLAPIENTRY
-_mesa_GetPixelMapusv( GLenum map, GLushort *values )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint mapsize, i;
- const struct gl_pixelmap *pm;
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- pm = get_pixelmap(ctx, map);
- if (!pm) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapusv(map)");
- return;
- }
- mapsize = pm->Size;
-
- if (!validate_pbo_access(ctx, &ctx->Pack, mapsize,
- GL_INTENSITY, GL_UNSIGNED_SHORT, values)) {
- return;
- }
-
- values = (GLushort *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
- if (!values) {
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetPixelMapusv(PBO is mapped)");
- }
- return;
- }
-
- switch (map) {
- /* special cases */
- case GL_PIXEL_MAP_I_TO_I:
- for (i = 0; i < mapsize; i++) {
- values[i] = (GLushort) CLAMP(ctx->PixelMaps.ItoI.Map[i], 0.0, 65535.);
- }
- break;
- case GL_PIXEL_MAP_S_TO_S:
- for (i = 0; i < mapsize; i++) {
- values[i] = (GLushort) CLAMP(ctx->PixelMaps.StoS.Map[i], 0.0, 65535.);
- }
- break;
- default:
- for (i = 0; i < mapsize; i++) {
- CLAMPED_FLOAT_TO_USHORT(values[i], pm->Map[i] );
- }
- }
-
- _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
-}
-
-
-
-/**********************************************************************/
-/***** glPixelTransfer *****/
-/**********************************************************************/
-
-
-/*
- * Implements glPixelTransfer[fi] whether called immediately or from a
- * display list.
- */
-static void GLAPIENTRY
-_mesa_PixelTransferf( GLenum pname, GLfloat param )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- switch (pname) {
- case GL_MAP_COLOR:
- if (ctx->Pixel.MapColorFlag == (param ? GL_TRUE : GL_FALSE))
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.MapColorFlag = param ? GL_TRUE : GL_FALSE;
- break;
- case GL_MAP_STENCIL:
- if (ctx->Pixel.MapStencilFlag == (param ? GL_TRUE : GL_FALSE))
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.MapStencilFlag = param ? GL_TRUE : GL_FALSE;
- break;
- case GL_INDEX_SHIFT:
- if (ctx->Pixel.IndexShift == (GLint) param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.IndexShift = (GLint) param;
- break;
- case GL_INDEX_OFFSET:
- if (ctx->Pixel.IndexOffset == (GLint) param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.IndexOffset = (GLint) param;
- break;
- case GL_RED_SCALE:
- if (ctx->Pixel.RedScale == param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.RedScale = param;
- break;
- case GL_RED_BIAS:
- if (ctx->Pixel.RedBias == param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.RedBias = param;
- break;
- case GL_GREEN_SCALE:
- if (ctx->Pixel.GreenScale == param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.GreenScale = param;
- break;
- case GL_GREEN_BIAS:
- if (ctx->Pixel.GreenBias == param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.GreenBias = param;
- break;
- case GL_BLUE_SCALE:
- if (ctx->Pixel.BlueScale == param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.BlueScale = param;
- break;
- case GL_BLUE_BIAS:
- if (ctx->Pixel.BlueBias == param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.BlueBias = param;
- break;
- case GL_ALPHA_SCALE:
- if (ctx->Pixel.AlphaScale == param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.AlphaScale = param;
- break;
- case GL_ALPHA_BIAS:
- if (ctx->Pixel.AlphaBias == param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.AlphaBias = param;
- break;
- case GL_DEPTH_SCALE:
- if (ctx->Pixel.DepthScale == param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.DepthScale = param;
- break;
- case GL_DEPTH_BIAS:
- if (ctx->Pixel.DepthBias == param)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.DepthBias = param;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glPixelTransfer(pname)" );
- return;
- }
-}
-
-
-static void GLAPIENTRY
-_mesa_PixelTransferi( GLenum pname, GLint param )
-{
- _mesa_PixelTransferf( pname, (GLfloat) param );
-}
-
-
-
-/**********************************************************************/
-/***** State Management *****/
-/**********************************************************************/
-
-/*
- * Return a bitmask of IMAGE_*_BIT flags which to indicate which
- * pixel transfer operations are enabled.
- */
-static void
-update_image_transfer_state(struct gl_context *ctx)
-{
- GLuint mask = 0;
-
- if (ctx->Pixel.RedScale != 1.0F || ctx->Pixel.RedBias != 0.0F ||
- ctx->Pixel.GreenScale != 1.0F || ctx->Pixel.GreenBias != 0.0F ||
- ctx->Pixel.BlueScale != 1.0F || ctx->Pixel.BlueBias != 0.0F ||
- ctx->Pixel.AlphaScale != 1.0F || ctx->Pixel.AlphaBias != 0.0F)
- mask |= IMAGE_SCALE_BIAS_BIT;
-
- if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset)
- mask |= IMAGE_SHIFT_OFFSET_BIT;
-
- if (ctx->Pixel.MapColorFlag)
- mask |= IMAGE_MAP_COLOR_BIT;
-
- ctx->_ImageTransferState = mask;
-}
-
-
-/**
- * Update mesa pixel transfer derived state.
- */
-void _mesa_update_pixel( struct gl_context *ctx, GLuint new_state )
-{
- if (new_state & _MESA_NEW_TRANSFER_STATE)
- update_image_transfer_state(ctx);
-}
-
-
-void
-_mesa_init_pixel_dispatch(struct _glapi_table *disp)
-{
- SET_GetPixelMapfv(disp, _mesa_GetPixelMapfv);
- SET_GetPixelMapuiv(disp, _mesa_GetPixelMapuiv);
- SET_GetPixelMapusv(disp, _mesa_GetPixelMapusv);
- SET_PixelMapfv(disp, _mesa_PixelMapfv);
- SET_PixelMapuiv(disp, _mesa_PixelMapuiv);
- SET_PixelMapusv(disp, _mesa_PixelMapusv);
- SET_PixelTransferf(disp, _mesa_PixelTransferf);
- SET_PixelTransferi(disp, _mesa_PixelTransferi);
- SET_PixelZoom(disp, _mesa_PixelZoom);
-}
-
-
-#endif /* FEATURE_pixel_transfer */
-
-
-/**********************************************************************/
-/***** Initialization *****/
-/**********************************************************************/
-
-static void
-init_pixelmap(struct gl_pixelmap *map)
-{
- map->Size = 1;
- map->Map[0] = 0.0;
- map->Map8[0] = 0;
-}
-
-
-/**
- * Initialize the context's PIXEL attribute group.
- */
-void
-_mesa_init_pixel( struct gl_context *ctx )
-{
- /* Pixel group */
- ctx->Pixel.RedBias = 0.0;
- ctx->Pixel.RedScale = 1.0;
- ctx->Pixel.GreenBias = 0.0;
- ctx->Pixel.GreenScale = 1.0;
- ctx->Pixel.BlueBias = 0.0;
- ctx->Pixel.BlueScale = 1.0;
- ctx->Pixel.AlphaBias = 0.0;
- ctx->Pixel.AlphaScale = 1.0;
- ctx->Pixel.DepthBias = 0.0;
- ctx->Pixel.DepthScale = 1.0;
- ctx->Pixel.IndexOffset = 0;
- ctx->Pixel.IndexShift = 0;
- ctx->Pixel.ZoomX = 1.0;
- ctx->Pixel.ZoomY = 1.0;
- ctx->Pixel.MapColorFlag = GL_FALSE;
- ctx->Pixel.MapStencilFlag = GL_FALSE;
- init_pixelmap(&ctx->PixelMaps.StoS);
- init_pixelmap(&ctx->PixelMaps.ItoI);
- init_pixelmap(&ctx->PixelMaps.ItoR);
- init_pixelmap(&ctx->PixelMaps.ItoG);
- init_pixelmap(&ctx->PixelMaps.ItoB);
- init_pixelmap(&ctx->PixelMaps.ItoA);
- init_pixelmap(&ctx->PixelMaps.RtoR);
- init_pixelmap(&ctx->PixelMaps.GtoG);
- init_pixelmap(&ctx->PixelMaps.BtoB);
- init_pixelmap(&ctx->PixelMaps.AtoA);
-
- if (ctx->Visual.doubleBufferMode) {
- ctx->Pixel.ReadBuffer = GL_BACK;
- }
- else {
- ctx->Pixel.ReadBuffer = GL_FRONT;
- }
-
- /* Miscellaneous */
- ctx->_ImageTransferState = 0;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file pixel.c
+ * Pixel transfer functions (glPixelZoom, glPixelMap, glPixelTransfer)
+ */
+
+#include "glheader.h"
+#include "bufferobj.h"
+#include "colormac.h"
+#include "context.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "pixel.h"
+#include "pbo.h"
+#include "mtypes.h"
+#include "main/dispatch.h"
+
+
+#if FEATURE_pixel_transfer
+
+
+/**********************************************************************/
+/***** glPixelZoom *****/
+/**********************************************************************/
+
+static void GLAPIENTRY
+_mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor )
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (ctx->Pixel.ZoomX == xfactor &&
+ ctx->Pixel.ZoomY == yfactor)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.ZoomX = xfactor;
+ ctx->Pixel.ZoomY = yfactor;
+}
+
+
+
+/**********************************************************************/
+/***** glPixelMap *****/
+/**********************************************************************/
+
+/**
+ * Return pointer to a pixelmap by name.
+ */
+static struct gl_pixelmap *
+get_pixelmap(struct gl_context *ctx, GLenum map)
+{
+ switch (map) {
+ case GL_PIXEL_MAP_I_TO_I:
+ return &ctx->PixelMaps.ItoI;
+ case GL_PIXEL_MAP_S_TO_S:
+ return &ctx->PixelMaps.StoS;
+ case GL_PIXEL_MAP_I_TO_R:
+ return &ctx->PixelMaps.ItoR;
+ case GL_PIXEL_MAP_I_TO_G:
+ return &ctx->PixelMaps.ItoG;
+ case GL_PIXEL_MAP_I_TO_B:
+ return &ctx->PixelMaps.ItoB;
+ case GL_PIXEL_MAP_I_TO_A:
+ return &ctx->PixelMaps.ItoA;
+ case GL_PIXEL_MAP_R_TO_R:
+ return &ctx->PixelMaps.RtoR;
+ case GL_PIXEL_MAP_G_TO_G:
+ return &ctx->PixelMaps.GtoG;
+ case GL_PIXEL_MAP_B_TO_B:
+ return &ctx->PixelMaps.BtoB;
+ case GL_PIXEL_MAP_A_TO_A:
+ return &ctx->PixelMaps.AtoA;
+ default:
+ return NULL;
+ }
+}
+
+
+/**
+ * Helper routine used by the other _mesa_PixelMap() functions.
+ */
+static void
+store_pixelmap(struct gl_context *ctx, GLenum map, GLsizei mapsize,
+ const GLfloat *values)
+{
+ GLint i;
+ struct gl_pixelmap *pm = get_pixelmap(ctx, map);
+ if (!pm) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glPixelMap(map)");
+ return;
+ }
+
+ switch (map) {
+ case GL_PIXEL_MAP_S_TO_S:
+ /* special case */
+ ctx->PixelMaps.StoS.Size = mapsize;
+ for (i = 0; i < mapsize; i++) {
+ ctx->PixelMaps.StoS.Map[i] = (GLfloat)IROUND(values[i]);
+ }
+ break;
+ case GL_PIXEL_MAP_I_TO_I:
+ /* special case */
+ ctx->PixelMaps.ItoI.Size = mapsize;
+ for (i = 0; i < mapsize; i++) {
+ ctx->PixelMaps.ItoI.Map[i] = values[i];
+ }
+ break;
+ default:
+ /* general case */
+ pm->Size = mapsize;
+ for (i = 0; i < mapsize; i++) {
+ GLfloat val = CLAMP(values[i], 0.0F, 1.0F);
+ pm->Map[i] = val;
+ pm->Map8[i] = (GLint) (val * 255.0F);
+ }
+ }
+}
+
+
+/**
+ * Convenience wrapper for _mesa_validate_pbo_access() for gl[Get]PixelMap().
+ */
+static GLboolean
+validate_pbo_access(struct gl_context *ctx, struct gl_pixelstore_attrib *pack,
+ GLsizei mapsize, GLenum format, GLenum type,
+ const GLvoid *ptr)
+{
+ GLboolean ok;
+
+ /* Note, need to use DefaultPacking and Unpack's buffer object */
+ _mesa_reference_buffer_object(ctx,
+ &ctx->DefaultPacking.BufferObj,
+ pack->BufferObj);
+
+ ok = _mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
+ format, type, ptr);
+
+ /* restore */
+ _mesa_reference_buffer_object(ctx,
+ &ctx->DefaultPacking.BufferObj,
+ ctx->Shared->NullBufferObj);
+
+ if (!ok) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMap(invalid PBO access)");
+ }
+ return ok;
+}
+
+
+static void GLAPIENTRY
+_mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ /* XXX someday, test against ctx->Const.MaxPixelMapTableSize */
+ if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
+ return;
+ }
+
+ if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
+ /* test that mapsize is a power of two */
+ if (!_mesa_is_pow_two(mapsize)) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
+ return;
+ }
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+
+ if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize,
+ GL_INTENSITY, GL_FLOAT, values)) {
+ return;
+ }
+
+ values = (const GLfloat *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapfv(PBO is mapped)");
+ }
+ return;
+ }
+
+ store_pixelmap(ctx, map, mapsize, values);
+
+ _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
+}
+
+
+static void GLAPIENTRY
+_mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
+{
+ GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
+ return;
+ }
+
+ if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
+ /* test that mapsize is a power of two */
+ if (!_mesa_is_pow_two(mapsize)) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
+ return;
+ }
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+
+ if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize,
+ GL_INTENSITY, GL_UNSIGNED_INT, values)) {
+ return;
+ }
+
+ values = (const GLuint *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapuiv(PBO is mapped)");
+ }
+ return;
+ }
+
+ /* convert to floats */
+ if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
+ GLint i;
+ for (i = 0; i < mapsize; i++) {
+ fvalues[i] = (GLfloat) values[i];
+ }
+ }
+ else {
+ GLint i;
+ for (i = 0; i < mapsize; i++) {
+ fvalues[i] = UINT_TO_FLOAT( values[i] );
+ }
+ }
+
+ _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
+
+ store_pixelmap(ctx, map, mapsize, fvalues);
+}
+
+
+static void GLAPIENTRY
+_mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
+{
+ GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapusv(mapsize)" );
+ return;
+ }
+
+ if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
+ /* test that mapsize is a power of two */
+ if (!_mesa_is_pow_two(mapsize)) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
+ return;
+ }
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+
+ if (!validate_pbo_access(ctx, &ctx->Unpack, mapsize,
+ GL_INTENSITY, GL_UNSIGNED_SHORT, values)) {
+ return;
+ }
+
+ values = (const GLushort *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPixelMapusv(PBO is mapped)");
+ }
+ return;
+ }
+
+ /* convert to floats */
+ if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
+ GLint i;
+ for (i = 0; i < mapsize; i++) {
+ fvalues[i] = (GLfloat) values[i];
+ }
+ }
+ else {
+ GLint i;
+ for (i = 0; i < mapsize; i++) {
+ fvalues[i] = USHORT_TO_FLOAT( values[i] );
+ }
+ }
+
+ _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
+
+ store_pixelmap(ctx, map, mapsize, fvalues);
+}
+
+
+static void GLAPIENTRY
+_mesa_GetPixelMapfv( GLenum map, GLfloat *values )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint mapsize, i;
+ const struct gl_pixelmap *pm;
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ pm = get_pixelmap(ctx, map);
+ if (!pm) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapfv(map)");
+ return;
+ }
+
+ mapsize = pm->Size;
+
+ if (!validate_pbo_access(ctx, &ctx->Pack, mapsize,
+ GL_INTENSITY, GL_FLOAT, values)) {
+ return;
+ }
+
+ values = (GLfloat *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetPixelMapfv(PBO is mapped)");
+ }
+ return;
+ }
+
+ if (map == GL_PIXEL_MAP_S_TO_S) {
+ /* special case */
+ for (i = 0; i < mapsize; i++) {
+ values[i] = (GLfloat) ctx->PixelMaps.StoS.Map[i];
+ }
+ }
+ else {
+ memcpy(values, pm->Map, mapsize * sizeof(GLfloat));
+ }
+
+ _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
+}
+
+
+static void GLAPIENTRY
+_mesa_GetPixelMapuiv( GLenum map, GLuint *values )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint mapsize, i;
+ const struct gl_pixelmap *pm;
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ pm = get_pixelmap(ctx, map);
+ if (!pm) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapuiv(map)");
+ return;
+ }
+ mapsize = pm->Size;
+
+ if (!validate_pbo_access(ctx, &ctx->Pack, mapsize,
+ GL_INTENSITY, GL_UNSIGNED_INT, values)) {
+ return;
+ }
+
+ values = (GLuint *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetPixelMapuiv(PBO is mapped)");
+ }
+ return;
+ }
+
+ if (map == GL_PIXEL_MAP_S_TO_S) {
+ /* special case */
+ memcpy(values, ctx->PixelMaps.StoS.Map, mapsize * sizeof(GLint));
+ }
+ else {
+ for (i = 0; i < mapsize; i++) {
+ values[i] = FLOAT_TO_UINT( pm->Map[i] );
+ }
+ }
+
+ _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
+}
+
+
+static void GLAPIENTRY
+_mesa_GetPixelMapusv( GLenum map, GLushort *values )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint mapsize, i;
+ const struct gl_pixelmap *pm;
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ pm = get_pixelmap(ctx, map);
+ if (!pm) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapusv(map)");
+ return;
+ }
+ mapsize = pm->Size;
+
+ if (!validate_pbo_access(ctx, &ctx->Pack, mapsize,
+ GL_INTENSITY, GL_UNSIGNED_SHORT, values)) {
+ return;
+ }
+
+ values = (GLushort *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
+ if (!values) {
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetPixelMapusv(PBO is mapped)");
+ }
+ return;
+ }
+
+ switch (map) {
+ /* special cases */
+ case GL_PIXEL_MAP_I_TO_I:
+ for (i = 0; i < mapsize; i++) {
+ values[i] = (GLushort) CLAMP(ctx->PixelMaps.ItoI.Map[i], 0.0, 65535.);
+ }
+ break;
+ case GL_PIXEL_MAP_S_TO_S:
+ for (i = 0; i < mapsize; i++) {
+ values[i] = (GLushort) CLAMP(ctx->PixelMaps.StoS.Map[i], 0.0, 65535.);
+ }
+ break;
+ default:
+ for (i = 0; i < mapsize; i++) {
+ CLAMPED_FLOAT_TO_USHORT(values[i], pm->Map[i] );
+ }
+ }
+
+ _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
+}
+
+
+
+/**********************************************************************/
+/***** glPixelTransfer *****/
+/**********************************************************************/
+
+
+/*
+ * Implements glPixelTransfer[fi] whether called immediately or from a
+ * display list.
+ */
+static void GLAPIENTRY
+_mesa_PixelTransferf( GLenum pname, GLfloat param )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ switch (pname) {
+ case GL_MAP_COLOR:
+ if (ctx->Pixel.MapColorFlag == (param ? GL_TRUE : GL_FALSE))
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.MapColorFlag = param ? GL_TRUE : GL_FALSE;
+ break;
+ case GL_MAP_STENCIL:
+ if (ctx->Pixel.MapStencilFlag == (param ? GL_TRUE : GL_FALSE))
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.MapStencilFlag = param ? GL_TRUE : GL_FALSE;
+ break;
+ case GL_INDEX_SHIFT:
+ if (ctx->Pixel.IndexShift == (GLint) param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.IndexShift = (GLint) param;
+ break;
+ case GL_INDEX_OFFSET:
+ if (ctx->Pixel.IndexOffset == (GLint) param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.IndexOffset = (GLint) param;
+ break;
+ case GL_RED_SCALE:
+ if (ctx->Pixel.RedScale == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.RedScale = param;
+ break;
+ case GL_RED_BIAS:
+ if (ctx->Pixel.RedBias == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.RedBias = param;
+ break;
+ case GL_GREEN_SCALE:
+ if (ctx->Pixel.GreenScale == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.GreenScale = param;
+ break;
+ case GL_GREEN_BIAS:
+ if (ctx->Pixel.GreenBias == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.GreenBias = param;
+ break;
+ case GL_BLUE_SCALE:
+ if (ctx->Pixel.BlueScale == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.BlueScale = param;
+ break;
+ case GL_BLUE_BIAS:
+ if (ctx->Pixel.BlueBias == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.BlueBias = param;
+ break;
+ case GL_ALPHA_SCALE:
+ if (ctx->Pixel.AlphaScale == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.AlphaScale = param;
+ break;
+ case GL_ALPHA_BIAS:
+ if (ctx->Pixel.AlphaBias == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.AlphaBias = param;
+ break;
+ case GL_DEPTH_SCALE:
+ if (ctx->Pixel.DepthScale == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.DepthScale = param;
+ break;
+ case GL_DEPTH_BIAS:
+ if (ctx->Pixel.DepthBias == param)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_PIXEL);
+ ctx->Pixel.DepthBias = param;
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glPixelTransfer(pname)" );
+ return;
+ }
+}
+
+
+static void GLAPIENTRY
+_mesa_PixelTransferi( GLenum pname, GLint param )
+{
+ _mesa_PixelTransferf( pname, (GLfloat) param );
+}
+
+
+
+/**********************************************************************/
+/***** State Management *****/
+/**********************************************************************/
+
+/*
+ * Return a bitmask of IMAGE_*_BIT flags which to indicate which
+ * pixel transfer operations are enabled.
+ */
+static void
+update_image_transfer_state(struct gl_context *ctx)
+{
+ GLuint mask = 0;
+
+ if (ctx->Pixel.RedScale != 1.0F || ctx->Pixel.RedBias != 0.0F ||
+ ctx->Pixel.GreenScale != 1.0F || ctx->Pixel.GreenBias != 0.0F ||
+ ctx->Pixel.BlueScale != 1.0F || ctx->Pixel.BlueBias != 0.0F ||
+ ctx->Pixel.AlphaScale != 1.0F || ctx->Pixel.AlphaBias != 0.0F)
+ mask |= IMAGE_SCALE_BIAS_BIT;
+
+ if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset)
+ mask |= IMAGE_SHIFT_OFFSET_BIT;
+
+ if (ctx->Pixel.MapColorFlag)
+ mask |= IMAGE_MAP_COLOR_BIT;
+
+ ctx->_ImageTransferState = mask;
+}
+
+
+/**
+ * Update mesa pixel transfer derived state.
+ */
+void _mesa_update_pixel( struct gl_context *ctx, GLuint new_state )
+{
+ if (new_state & _MESA_NEW_TRANSFER_STATE)
+ update_image_transfer_state(ctx);
+}
+
+
+void
+_mesa_init_pixel_dispatch(struct _glapi_table *disp)
+{
+ SET_GetPixelMapfv(disp, _mesa_GetPixelMapfv);
+ SET_GetPixelMapuiv(disp, _mesa_GetPixelMapuiv);
+ SET_GetPixelMapusv(disp, _mesa_GetPixelMapusv);
+ SET_PixelMapfv(disp, _mesa_PixelMapfv);
+ SET_PixelMapuiv(disp, _mesa_PixelMapuiv);
+ SET_PixelMapusv(disp, _mesa_PixelMapusv);
+ SET_PixelTransferf(disp, _mesa_PixelTransferf);
+ SET_PixelTransferi(disp, _mesa_PixelTransferi);
+ SET_PixelZoom(disp, _mesa_PixelZoom);
+}
+
+
+#endif /* FEATURE_pixel_transfer */
+
+
+/**********************************************************************/
+/***** Initialization *****/
+/**********************************************************************/
+
+static void
+init_pixelmap(struct gl_pixelmap *map)
+{
+ map->Size = 1;
+ map->Map[0] = 0.0;
+ map->Map8[0] = 0;
+}
+
+
+/**
+ * Initialize the context's PIXEL attribute group.
+ */
+void
+_mesa_init_pixel( struct gl_context *ctx )
+{
+ /* Pixel group */
+ ctx->Pixel.RedBias = 0.0;
+ ctx->Pixel.RedScale = 1.0;
+ ctx->Pixel.GreenBias = 0.0;
+ ctx->Pixel.GreenScale = 1.0;
+ ctx->Pixel.BlueBias = 0.0;
+ ctx->Pixel.BlueScale = 1.0;
+ ctx->Pixel.AlphaBias = 0.0;
+ ctx->Pixel.AlphaScale = 1.0;
+ ctx->Pixel.DepthBias = 0.0;
+ ctx->Pixel.DepthScale = 1.0;
+ ctx->Pixel.IndexOffset = 0;
+ ctx->Pixel.IndexShift = 0;
+ ctx->Pixel.ZoomX = 1.0;
+ ctx->Pixel.ZoomY = 1.0;
+ ctx->Pixel.MapColorFlag = GL_FALSE;
+ ctx->Pixel.MapStencilFlag = GL_FALSE;
+ init_pixelmap(&ctx->PixelMaps.StoS);
+ init_pixelmap(&ctx->PixelMaps.ItoI);
+ init_pixelmap(&ctx->PixelMaps.ItoR);
+ init_pixelmap(&ctx->PixelMaps.ItoG);
+ init_pixelmap(&ctx->PixelMaps.ItoB);
+ init_pixelmap(&ctx->PixelMaps.ItoA);
+ init_pixelmap(&ctx->PixelMaps.RtoR);
+ init_pixelmap(&ctx->PixelMaps.GtoG);
+ init_pixelmap(&ctx->PixelMaps.BtoB);
+ init_pixelmap(&ctx->PixelMaps.AtoA);
+
+ if (ctx->Visual.doubleBufferMode) {
+ ctx->Pixel.ReadBuffer = GL_BACK;
+ }
+ else {
+ ctx->Pixel.ReadBuffer = GL_FRONT;
+ }
+
+ /* Miscellaneous */
+ ctx->_ImageTransferState = 0;
+}
diff --git a/mesalib/src/mesa/main/polygon.c b/mesalib/src/mesa/main/polygon.c
index ff4232ecc..3ad375901 100644
--- a/mesalib/src/mesa/main/polygon.c
+++ b/mesalib/src/mesa/main/polygon.c
@@ -1,322 +1,322 @@
-/**
- * \file polygon.c
- * Polygon operations.
- */
-
-/*
- * Mesa 3-D graphics library
- * Version: 6.5.1
- *
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "glheader.h"
-#include "imports.h"
-#include "context.h"
-#include "image.h"
-#include "enums.h"
-#include "pack.h"
-#include "pbo.h"
-#include "polygon.h"
-#include "mtypes.h"
-
-
-/**
- * Specify whether to cull front- or back-facing facets.
- *
- * \param mode culling mode.
- *
- * \sa glCullFace().
- *
- * Verifies the parameter and updates gl_polygon_attrib::CullFaceMode. On
- * change, flushes the vertices and notifies the driver via
- * the dd_function_table::CullFace callback.
- */
-void GLAPIENTRY
-_mesa_CullFace( GLenum mode )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE&VERBOSE_API)
- _mesa_debug(ctx, "glCullFace %s\n", _mesa_lookup_enum_by_nr(mode));
-
- if (mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glCullFace" );
- return;
- }
-
- if (ctx->Polygon.CullFaceMode == mode)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.CullFaceMode = mode;
-
- if (ctx->Driver.CullFace)
- ctx->Driver.CullFace( ctx, mode );
-}
-
-
-/**
- * Define front- and back-facing
- *
- * \param mode orientation of front-facing polygons.
- *
- * \sa glFrontFace().
- *
- * Verifies the parameter and updates gl_polygon_attrib::FrontFace. On change
- * flushes the vertices and notifies the driver via
- * the dd_function_table::FrontFace callback.
- */
-void GLAPIENTRY
-_mesa_FrontFace( GLenum mode )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE&VERBOSE_API)
- _mesa_debug(ctx, "glFrontFace %s\n", _mesa_lookup_enum_by_nr(mode));
-
- if (mode!=GL_CW && mode!=GL_CCW) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glFrontFace" );
- return;
- }
-
- if (ctx->Polygon.FrontFace == mode)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.FrontFace = mode;
-
- ctx->Polygon._FrontBit = (GLboolean) (mode == GL_CW);
-
- if (ctx->Driver.FrontFace)
- ctx->Driver.FrontFace( ctx, mode );
-}
-
-
-/**
- * Set the polygon rasterization mode.
- *
- * \param face the polygons which \p mode applies to.
- * \param mode how polygons should be rasterized.
- *
- * \sa glPolygonMode().
- *
- * Verifies the parameters and updates gl_polygon_attrib::FrontMode and
- * gl_polygon_attrib::BackMode. On change flushes the vertices and notifies the
- * driver via the dd_function_table::PolygonMode callback.
- */
-void GLAPIENTRY
-_mesa_PolygonMode( GLenum face, GLenum mode )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE&VERBOSE_API)
- _mesa_debug(ctx, "glPolygonMode %s %s\n",
- _mesa_lookup_enum_by_nr(face),
- _mesa_lookup_enum_by_nr(mode));
-
- if (mode!=GL_POINT && mode!=GL_LINE && mode!=GL_FILL) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(mode)" );
- return;
- }
-
- switch (face) {
- case GL_FRONT:
- if (ctx->Polygon.FrontMode == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.FrontMode = mode;
- break;
- case GL_FRONT_AND_BACK:
- if (ctx->Polygon.FrontMode == mode &&
- ctx->Polygon.BackMode == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.FrontMode = mode;
- ctx->Polygon.BackMode = mode;
- break;
- case GL_BACK:
- if (ctx->Polygon.BackMode == mode)
- return;
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.BackMode = mode;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
- return;
- }
-
- if (ctx->Polygon.FrontMode == GL_FILL && ctx->Polygon.BackMode == GL_FILL)
- ctx->_TriangleCaps &= ~DD_TRI_UNFILLED;
- else
- ctx->_TriangleCaps |= DD_TRI_UNFILLED;
-
- if (ctx->Driver.PolygonMode)
- ctx->Driver.PolygonMode(ctx, face, mode);
-}
-
-#if _HAVE_FULL_GL
-
-
-/**
- * This routine updates the ctx->Polygon.Stipple state.
- * If we're getting the stipple data from a PBO, we map the buffer
- * in order to access the data.
- * In any case, we obey the current pixel unpacking parameters when fetching
- * the stipple data.
- *
- * In the future, this routine should be used as a fallback, called via
- * ctx->Driver.PolygonStipple(). We'll have to update all the DRI drivers
- * too.
- */
-void
-_mesa_polygon_stipple(struct gl_context *ctx, const GLubyte *pattern)
-{
- pattern = _mesa_map_validate_pbo_source(ctx, 2,
- &ctx->Unpack, 32, 32, 1,
- GL_COLOR_INDEX, GL_BITMAP, pattern,
- "glPolygonStipple");
- if (!pattern)
- return;
-
- _mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
-
- _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
-}
-
-
-/**
- * Called by glPolygonStipple.
- */
-void GLAPIENTRY
-_mesa_PolygonStipple( const GLubyte *pattern )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE&VERBOSE_API)
- _mesa_debug(ctx, "glPolygonStipple\n");
-
- FLUSH_VERTICES(ctx, _NEW_POLYGONSTIPPLE);
-
- _mesa_polygon_stipple(ctx, pattern);
-
- if (ctx->Driver.PolygonStipple)
- ctx->Driver.PolygonStipple(ctx, pattern);
-}
-
-
-/**
- * Called by glPolygonStipple.
- */
-void GLAPIENTRY
-_mesa_GetPolygonStipple( GLubyte *dest )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE&VERBOSE_API)
- _mesa_debug(ctx, "glGetPolygonStipple\n");
-
- dest = _mesa_map_validate_pbo_dest(ctx, 2,
- &ctx->Pack, 32, 32, 1,
- GL_COLOR_INDEX, GL_BITMAP, dest,
- "glGetPolygonStipple");
- if (!dest)
- return;
-
- _mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
-
- _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
-}
-
-
-void GLAPIENTRY
-_mesa_PolygonOffset( GLfloat factor, GLfloat units )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE&VERBOSE_API)
- _mesa_debug(ctx, "glPolygonOffset %f %f\n", factor, units);
-
- if (ctx->Polygon.OffsetFactor == factor &&
- ctx->Polygon.OffsetUnits == units)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_POLYGON);
- ctx->Polygon.OffsetFactor = factor;
- ctx->Polygon.OffsetUnits = units;
-
- if (ctx->Driver.PolygonOffset)
- ctx->Driver.PolygonOffset( ctx, factor, units );
-}
-
-
-void GLAPIENTRY
-_mesa_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
-{
- GET_CURRENT_CONTEXT(ctx);
- /* XXX mult by DepthMaxF here??? */
- _mesa_PolygonOffset(factor, bias * ctx->DrawBuffer->_DepthMaxF );
-}
-
-#endif
-
-
-/**********************************************************************/
-/** \name Initialization */
-/*@{*/
-
-/**
- * Initialize the context polygon state.
- *
- * \param ctx GL context.
- *
- * Initializes __struct gl_contextRec::Polygon and __struct gl_contextRec::PolygonStipple
- * attribute groups.
- */
-void _mesa_init_polygon( struct gl_context * ctx )
-{
- /* Polygon group */
- ctx->Polygon.CullFlag = GL_FALSE;
- ctx->Polygon.CullFaceMode = GL_BACK;
- ctx->Polygon.FrontFace = GL_CCW;
- ctx->Polygon._FrontBit = 0;
- ctx->Polygon.FrontMode = GL_FILL;
- ctx->Polygon.BackMode = GL_FILL;
- ctx->Polygon.SmoothFlag = GL_FALSE;
- ctx->Polygon.StippleFlag = GL_FALSE;
- ctx->Polygon.OffsetFactor = 0.0F;
- ctx->Polygon.OffsetUnits = 0.0F;
- ctx->Polygon.OffsetPoint = GL_FALSE;
- ctx->Polygon.OffsetLine = GL_FALSE;
- ctx->Polygon.OffsetFill = GL_FALSE;
-
-
- /* Polygon Stipple group */
- memset( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
-}
-
-/*@}*/
+/**
+ * \file polygon.c
+ * Polygon operations.
+ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5.1
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "glheader.h"
+#include "imports.h"
+#include "context.h"
+#include "image.h"
+#include "enums.h"
+#include "pack.h"
+#include "pbo.h"
+#include "polygon.h"
+#include "mtypes.h"
+
+
+/**
+ * Specify whether to cull front- or back-facing facets.
+ *
+ * \param mode culling mode.
+ *
+ * \sa glCullFace().
+ *
+ * Verifies the parameter and updates gl_polygon_attrib::CullFaceMode. On
+ * change, flushes the vertices and notifies the driver via
+ * the dd_function_table::CullFace callback.
+ */
+void GLAPIENTRY
+_mesa_CullFace( GLenum mode )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE&VERBOSE_API)
+ _mesa_debug(ctx, "glCullFace %s\n", _mesa_lookup_enum_by_nr(mode));
+
+ if (mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glCullFace" );
+ return;
+ }
+
+ if (ctx->Polygon.CullFaceMode == mode)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.CullFaceMode = mode;
+
+ if (ctx->Driver.CullFace)
+ ctx->Driver.CullFace( ctx, mode );
+}
+
+
+/**
+ * Define front- and back-facing
+ *
+ * \param mode orientation of front-facing polygons.
+ *
+ * \sa glFrontFace().
+ *
+ * Verifies the parameter and updates gl_polygon_attrib::FrontFace. On change
+ * flushes the vertices and notifies the driver via
+ * the dd_function_table::FrontFace callback.
+ */
+void GLAPIENTRY
+_mesa_FrontFace( GLenum mode )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE&VERBOSE_API)
+ _mesa_debug(ctx, "glFrontFace %s\n", _mesa_lookup_enum_by_nr(mode));
+
+ if (mode!=GL_CW && mode!=GL_CCW) {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glFrontFace" );
+ return;
+ }
+
+ if (ctx->Polygon.FrontFace == mode)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.FrontFace = mode;
+
+ ctx->Polygon._FrontBit = (GLboolean) (mode == GL_CW);
+
+ if (ctx->Driver.FrontFace)
+ ctx->Driver.FrontFace( ctx, mode );
+}
+
+
+/**
+ * Set the polygon rasterization mode.
+ *
+ * \param face the polygons which \p mode applies to.
+ * \param mode how polygons should be rasterized.
+ *
+ * \sa glPolygonMode().
+ *
+ * Verifies the parameters and updates gl_polygon_attrib::FrontMode and
+ * gl_polygon_attrib::BackMode. On change flushes the vertices and notifies the
+ * driver via the dd_function_table::PolygonMode callback.
+ */
+void GLAPIENTRY
+_mesa_PolygonMode( GLenum face, GLenum mode )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE&VERBOSE_API)
+ _mesa_debug(ctx, "glPolygonMode %s %s\n",
+ _mesa_lookup_enum_by_nr(face),
+ _mesa_lookup_enum_by_nr(mode));
+
+ if (mode!=GL_POINT && mode!=GL_LINE && mode!=GL_FILL) {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(mode)" );
+ return;
+ }
+
+ switch (face) {
+ case GL_FRONT:
+ if (ctx->Polygon.FrontMode == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.FrontMode = mode;
+ break;
+ case GL_FRONT_AND_BACK:
+ if (ctx->Polygon.FrontMode == mode &&
+ ctx->Polygon.BackMode == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.FrontMode = mode;
+ ctx->Polygon.BackMode = mode;
+ break;
+ case GL_BACK:
+ if (ctx->Polygon.BackMode == mode)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.BackMode = mode;
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
+ return;
+ }
+
+ if (ctx->Polygon.FrontMode == GL_FILL && ctx->Polygon.BackMode == GL_FILL)
+ ctx->_TriangleCaps &= ~DD_TRI_UNFILLED;
+ else
+ ctx->_TriangleCaps |= DD_TRI_UNFILLED;
+
+ if (ctx->Driver.PolygonMode)
+ ctx->Driver.PolygonMode(ctx, face, mode);
+}
+
+#if _HAVE_FULL_GL
+
+
+/**
+ * This routine updates the ctx->Polygon.Stipple state.
+ * If we're getting the stipple data from a PBO, we map the buffer
+ * in order to access the data.
+ * In any case, we obey the current pixel unpacking parameters when fetching
+ * the stipple data.
+ *
+ * In the future, this routine should be used as a fallback, called via
+ * ctx->Driver.PolygonStipple(). We'll have to update all the DRI drivers
+ * too.
+ */
+void
+_mesa_polygon_stipple(struct gl_context *ctx, const GLubyte *pattern)
+{
+ pattern = _mesa_map_validate_pbo_source(ctx, 2,
+ &ctx->Unpack, 32, 32, 1,
+ GL_COLOR_INDEX, GL_BITMAP, pattern,
+ "glPolygonStipple");
+ if (!pattern)
+ return;
+
+ _mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
+
+ _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
+}
+
+
+/**
+ * Called by glPolygonStipple.
+ */
+void GLAPIENTRY
+_mesa_PolygonStipple( const GLubyte *pattern )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE&VERBOSE_API)
+ _mesa_debug(ctx, "glPolygonStipple\n");
+
+ FLUSH_VERTICES(ctx, _NEW_POLYGONSTIPPLE);
+
+ _mesa_polygon_stipple(ctx, pattern);
+
+ if (ctx->Driver.PolygonStipple)
+ ctx->Driver.PolygonStipple(ctx, pattern);
+}
+
+
+/**
+ * Called by glPolygonStipple.
+ */
+void GLAPIENTRY
+_mesa_GetPolygonStipple( GLubyte *dest )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE&VERBOSE_API)
+ _mesa_debug(ctx, "glGetPolygonStipple\n");
+
+ dest = _mesa_map_validate_pbo_dest(ctx, 2,
+ &ctx->Pack, 32, 32, 1,
+ GL_COLOR_INDEX, GL_BITMAP, dest,
+ "glGetPolygonStipple");
+ if (!dest)
+ return;
+
+ _mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
+
+ _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
+}
+
+
+void GLAPIENTRY
+_mesa_PolygonOffset( GLfloat factor, GLfloat units )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE&VERBOSE_API)
+ _mesa_debug(ctx, "glPolygonOffset %f %f\n", factor, units);
+
+ if (ctx->Polygon.OffsetFactor == factor &&
+ ctx->Polygon.OffsetUnits == units)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_POLYGON);
+ ctx->Polygon.OffsetFactor = factor;
+ ctx->Polygon.OffsetUnits = units;
+
+ if (ctx->Driver.PolygonOffset)
+ ctx->Driver.PolygonOffset( ctx, factor, units );
+}
+
+
+void GLAPIENTRY
+_mesa_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ /* XXX mult by DepthMaxF here??? */
+ _mesa_PolygonOffset(factor, bias * ctx->DrawBuffer->_DepthMaxF );
+}
+
+#endif
+
+
+/**********************************************************************/
+/** \name Initialization */
+/*@{*/
+
+/**
+ * Initialize the context polygon state.
+ *
+ * \param ctx GL context.
+ *
+ * Initializes __struct gl_contextRec::Polygon and __struct gl_contextRec::PolygonStipple
+ * attribute groups.
+ */
+void _mesa_init_polygon( struct gl_context * ctx )
+{
+ /* Polygon group */
+ ctx->Polygon.CullFlag = GL_FALSE;
+ ctx->Polygon.CullFaceMode = GL_BACK;
+ ctx->Polygon.FrontFace = GL_CCW;
+ ctx->Polygon._FrontBit = 0;
+ ctx->Polygon.FrontMode = GL_FILL;
+ ctx->Polygon.BackMode = GL_FILL;
+ ctx->Polygon.SmoothFlag = GL_FALSE;
+ ctx->Polygon.StippleFlag = GL_FALSE;
+ ctx->Polygon.OffsetFactor = 0.0F;
+ ctx->Polygon.OffsetUnits = 0.0F;
+ ctx->Polygon.OffsetPoint = GL_FALSE;
+ ctx->Polygon.OffsetLine = GL_FALSE;
+ ctx->Polygon.OffsetFill = GL_FALSE;
+
+
+ /* Polygon Stipple group */
+ memset( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
+}
+
+/*@}*/
diff --git a/mesalib/src/mesa/main/queryobj.c b/mesalib/src/mesa/main/queryobj.c
index fa35c6ce5..dc9f18a65 100644
--- a/mesalib/src/mesa/main/queryobj.c
+++ b/mesalib/src/mesa/main/queryobj.c
@@ -1,623 +1,623 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "glheader.h"
-#include "context.h"
-#include "enums.h"
-#include "hash.h"
-#include "imports.h"
-#include "queryobj.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "main/dispatch.h"
-
-
-#if FEATURE_queryobj
-
-
-/**
- * Allocate a new query object. This is a fallback routine called via
- * ctx->Driver.NewQueryObject().
- * \param ctx - rendering context
- * \param id - the new object's ID
- * \return pointer to new query_object object or NULL if out of memory.
- */
-static struct gl_query_object *
-_mesa_new_query_object(struct gl_context *ctx, GLuint id)
-{
- struct gl_query_object *q = MALLOC_STRUCT(gl_query_object);
- (void) ctx;
- if (q) {
- q->Id = id;
- q->Result = 0;
- q->Active = GL_FALSE;
- q->Ready = GL_TRUE; /* correct, see spec */
- }
- return q;
-}
-
-
-/**
- * Begin a query. Software driver fallback.
- * Called via ctx->Driver.BeginQuery().
- */
-static void
-_mesa_begin_query(struct gl_context *ctx, struct gl_query_object *q)
-{
- /* no-op */
-}
-
-
-/**
- * End a query. Software driver fallback.
- * Called via ctx->Driver.EndQuery().
- */
-static void
-_mesa_end_query(struct gl_context *ctx, struct gl_query_object *q)
-{
- q->Ready = GL_TRUE;
-}
-
-
-/**
- * Wait for query to complete. Software driver fallback.
- * Called via ctx->Driver.WaitQuery().
- */
-static void
-_mesa_wait_query(struct gl_context *ctx, struct gl_query_object *q)
-{
- /* For software drivers, _mesa_end_query() should have completed the query.
- * For real hardware, implement a proper WaitQuery() driver function,
- * which may require issuing a flush.
- */
- assert(q->Ready);
-}
-
-
-/**
- * Check if a query results are ready. Software driver fallback.
- * Called via ctx->Driver.CheckQuery().
- */
-static void
-_mesa_check_query(struct gl_context *ctx, struct gl_query_object *q)
-{
- /* No-op for sw rendering.
- * HW drivers may need to flush at this time.
- */
-}
-
-
-/**
- * Delete a query object. Called via ctx->Driver.DeleteQuery().
- * Not removed from hash table here.
- */
-static void
-_mesa_delete_query(struct gl_context *ctx, struct gl_query_object *q)
-{
- free(q);
-}
-
-
-void
-_mesa_init_query_object_functions(struct dd_function_table *driver)
-{
- driver->NewQueryObject = _mesa_new_query_object;
- driver->DeleteQuery = _mesa_delete_query;
- driver->BeginQuery = _mesa_begin_query;
- driver->EndQuery = _mesa_end_query;
- driver->WaitQuery = _mesa_wait_query;
- driver->CheckQuery = _mesa_check_query;
-}
-
-
-/**
- * Return pointer to the query object binding point for the given target.
- * \return NULL if invalid target, else the address of binding point
- */
-static struct gl_query_object **
-get_query_binding_point(struct gl_context *ctx, GLenum target)
-{
- switch (target) {
- case GL_SAMPLES_PASSED_ARB:
- if (ctx->Extensions.ARB_occlusion_query)
- return &ctx->Query.CurrentOcclusionObject;
- else
- return NULL;
- case GL_ANY_SAMPLES_PASSED:
- if (ctx->Extensions.ARB_occlusion_query2)
- return &ctx->Query.CurrentOcclusionObject;
- else
- return NULL;
- case GL_TIME_ELAPSED_EXT:
- if (ctx->Extensions.EXT_timer_query)
- return &ctx->Query.CurrentTimerObject;
- else
- return NULL;
-#if FEATURE_EXT_transform_feedback
- case GL_PRIMITIVES_GENERATED:
- if (ctx->Extensions.EXT_transform_feedback)
- return &ctx->Query.PrimitivesGenerated;
- else
- return NULL;
- case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
- if (ctx->Extensions.EXT_transform_feedback)
- return &ctx->Query.PrimitivesWritten;
- else
- return NULL;
-#endif
- default:
- return NULL;
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GenQueriesARB(GLsizei n, GLuint *ids)
-{
- GLuint first;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glGenQueries(%d)\n", n);
-
- if (n < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGenQueriesARB(n < 0)");
- return;
- }
-
- /* No query objects can be active at this time! */
- if (ctx->Query.CurrentOcclusionObject ||
- ctx->Query.CurrentTimerObject) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGenQueriesARB");
- return;
- }
-
- first = _mesa_HashFindFreeKeyBlock(ctx->Query.QueryObjects, n);
- if (first) {
- GLsizei i;
- for (i = 0; i < n; i++) {
- struct gl_query_object *q
- = ctx->Driver.NewQueryObject(ctx, first + i);
- if (!q) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenQueriesARB");
- return;
- }
- ids[i] = first + i;
- _mesa_HashInsert(ctx->Query.QueryObjects, first + i, q);
- }
- }
-}
-
-
-void GLAPIENTRY
-_mesa_DeleteQueriesARB(GLsizei n, const GLuint *ids)
-{
- GLint i;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glDeleeteQueries(%d)\n", n);
-
- if (n < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteQueriesARB(n < 0)");
- return;
- }
-
- /* No query objects can be active at this time! */
- if (ctx->Query.CurrentOcclusionObject ||
- ctx->Query.CurrentTimerObject) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glDeleteQueriesARB");
- return;
- }
-
- for (i = 0; i < n; i++) {
- if (ids[i] > 0) {
- struct gl_query_object *q = _mesa_lookup_query_object(ctx, ids[i]);
- if (q) {
- ASSERT(!q->Active); /* should be caught earlier */
- _mesa_HashRemove(ctx->Query.QueryObjects, ids[i]);
- ctx->Driver.DeleteQuery(ctx, q);
- }
- }
- }
-}
-
-
-GLboolean GLAPIENTRY
-_mesa_IsQueryARB(GLuint id)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glIsQuery(%u)\n", id);
-
- if (id && _mesa_lookup_query_object(ctx, id))
- return GL_TRUE;
- else
- return GL_FALSE;
-}
-
-
-static void GLAPIENTRY
-_mesa_BeginQueryARB(GLenum target, GLuint id)
-{
- struct gl_query_object *q, **bindpt;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glBeginQuery(%s, %u)\n",
- _mesa_lookup_enum_by_nr(target), id);
-
- FLUSH_VERTICES(ctx, _NEW_DEPTH);
-
- bindpt = get_query_binding_point(ctx, target);
- if (!bindpt) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBeginQueryARB(target)");
- return;
- }
-
- if (id == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginQueryARB(id==0)");
- return;
- }
-
- q = _mesa_lookup_query_object(ctx, id);
- if (!q) {
- /* create new object */
- q = ctx->Driver.NewQueryObject(ctx, id);
- if (!q) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBeginQueryARB");
- return;
- }
- _mesa_HashInsert(ctx->Query.QueryObjects, id, q);
- }
- else {
- /* pre-existing object */
- if (q->Active) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBeginQueryARB(query already active)");
- return;
- }
- }
-
- q->Target = target;
- q->Active = GL_TRUE;
- q->Result = 0;
- q->Ready = GL_FALSE;
-
- /* XXX should probably refcount query objects */
- *bindpt = q;
-
- ctx->Driver.BeginQuery(ctx, q);
-}
-
-
-static void GLAPIENTRY
-_mesa_EndQueryARB(GLenum target)
-{
- struct gl_query_object *q, **bindpt;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glEndQuery(%s)\n", _mesa_lookup_enum_by_nr(target));
-
- FLUSH_VERTICES(ctx, _NEW_DEPTH);
-
- bindpt = get_query_binding_point(ctx, target);
- if (!bindpt) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glEndQueryARB(target)");
- return;
- }
-
- /* XXX should probably refcount query objects */
- q = *bindpt;
- *bindpt = NULL;
-
- if (!q || !q->Active) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glEndQueryARB(no matching glBeginQueryARB)");
- return;
- }
-
- q->Active = GL_FALSE;
- ctx->Driver.EndQuery(ctx, q);
-}
-
-
-void GLAPIENTRY
-_mesa_GetQueryivARB(GLenum target, GLenum pname, GLint *params)
-{
- struct gl_query_object *q, **bindpt;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glGetQueryiv(%s, %s)\n",
- _mesa_lookup_enum_by_nr(target),
- _mesa_lookup_enum_by_nr(pname));
-
- bindpt = get_query_binding_point(ctx, target);
- if (!bindpt) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryARB(target)");
- return;
- }
-
- q = *bindpt;
-
- switch (pname) {
- case GL_QUERY_COUNTER_BITS_ARB:
- *params = 8 * sizeof(q->Result);
- break;
- case GL_CURRENT_QUERY_ARB:
- *params = q ? q->Id : 0;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryivARB(pname)");
- return;
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params)
-{
- struct gl_query_object *q = NULL;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glGetQueryObjectiv(%u, %s)\n", id,
- _mesa_lookup_enum_by_nr(pname));
-
- if (id)
- q = _mesa_lookup_query_object(ctx, id);
-
- if (!q || q->Active) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetQueryObjectivARB(id=%d is invalid or active)", id);
- return;
- }
-
- switch (pname) {
- case GL_QUERY_RESULT_ARB:
- if (!q->Ready)
- ctx->Driver.WaitQuery(ctx, q);
- /* if result is too large for returned type, clamp to max value */
- if (q->Target == GL_ANY_SAMPLES_PASSED) {
- if (q->Result)
- *params = GL_TRUE;
- else
- *params = GL_FALSE;
- } else {
- if (q->Result > 0x7fffffff) {
- *params = 0x7fffffff;
- }
- else {
- *params = (GLint)q->Result;
- }
- }
- break;
- case GL_QUERY_RESULT_AVAILABLE_ARB:
- if (!q->Ready)
- ctx->Driver.CheckQuery( ctx, q );
- *params = q->Ready;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryObjectivARB(pname)");
- return;
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
-{
- struct gl_query_object *q = NULL;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glGetQueryObjectuiv(%u, %s)\n", id,
- _mesa_lookup_enum_by_nr(pname));
-
- if (id)
- q = _mesa_lookup_query_object(ctx, id);
-
- if (!q || q->Active) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetQueryObjectuivARB(id=%d is invalid or active)", id);
- return;
- }
-
- switch (pname) {
- case GL_QUERY_RESULT_ARB:
- if (!q->Ready)
- ctx->Driver.WaitQuery(ctx, q);
- /* if result is too large for returned type, clamp to max value */
- if (q->Target == GL_ANY_SAMPLES_PASSED) {
- if (q->Result)
- *params = GL_TRUE;
- else
- *params = GL_FALSE;
- } else {
- if (q->Result > 0xffffffff) {
- *params = 0xffffffff;
- }
- else {
- *params = (GLuint)q->Result;
- }
- }
- break;
- case GL_QUERY_RESULT_AVAILABLE_ARB:
- if (!q->Ready)
- ctx->Driver.CheckQuery( ctx, q );
- *params = q->Ready;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryObjectuivARB(pname)");
- return;
- }
-}
-
-
-/**
- * New with GL_EXT_timer_query
- */
-static void GLAPIENTRY
-_mesa_GetQueryObjecti64vEXT(GLuint id, GLenum pname, GLint64EXT *params)
-{
- struct gl_query_object *q = NULL;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glGetQueryObjecti64v(%u, %s)\n", id,
- _mesa_lookup_enum_by_nr(pname));
-
- if (id)
- q = _mesa_lookup_query_object(ctx, id);
-
- if (!q || q->Active) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetQueryObjectui64vARB(id=%d is invalid or active)", id);
- return;
- }
-
- switch (pname) {
- case GL_QUERY_RESULT_ARB:
- if (!q->Ready)
- ctx->Driver.WaitQuery(ctx, q);
- *params = q->Result;
- break;
- case GL_QUERY_RESULT_AVAILABLE_ARB:
- if (!q->Ready)
- ctx->Driver.CheckQuery( ctx, q );
- *params = q->Ready;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryObjecti64vARB(pname)");
- return;
- }
-}
-
-
-/**
- * New with GL_EXT_timer_query
- */
-static void GLAPIENTRY
-_mesa_GetQueryObjectui64vEXT(GLuint id, GLenum pname, GLuint64EXT *params)
-{
- struct gl_query_object *q = NULL;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glGetQueryObjectui64v(%u, %s)\n", id,
- _mesa_lookup_enum_by_nr(pname));
-
- if (id)
- q = _mesa_lookup_query_object(ctx, id);
-
- if (!q || q->Active) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetQueryObjectuui64vARB(id=%d is invalid or active)", id);
- return;
- }
-
- switch (pname) {
- case GL_QUERY_RESULT_ARB:
- if (!q->Ready)
- ctx->Driver.WaitQuery(ctx, q);
- *params = q->Result;
- break;
- case GL_QUERY_RESULT_AVAILABLE_ARB:
- if (!q->Ready)
- ctx->Driver.CheckQuery( ctx, q );
- *params = q->Ready;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryObjectui64vARB(pname)");
- return;
- }
-}
-
-
-void
-_mesa_init_queryobj_dispatch(struct _glapi_table *disp)
-{
- SET_GenQueriesARB(disp, _mesa_GenQueriesARB);
- SET_DeleteQueriesARB(disp, _mesa_DeleteQueriesARB);
- SET_IsQueryARB(disp, _mesa_IsQueryARB);
- SET_BeginQueryARB(disp, _mesa_BeginQueryARB);
- SET_EndQueryARB(disp, _mesa_EndQueryARB);
- SET_GetQueryivARB(disp, _mesa_GetQueryivARB);
- SET_GetQueryObjectivARB(disp, _mesa_GetQueryObjectivARB);
- SET_GetQueryObjectuivARB(disp, _mesa_GetQueryObjectuivARB);
-
- SET_GetQueryObjecti64vEXT(disp, _mesa_GetQueryObjecti64vEXT);
- SET_GetQueryObjectui64vEXT(disp, _mesa_GetQueryObjectui64vEXT);
-}
-
-
-#endif /* FEATURE_queryobj */
-
-
-/**
- * Allocate/init the context state related to query objects.
- */
-void
-_mesa_init_queryobj(struct gl_context *ctx)
-{
- ctx->Query.QueryObjects = _mesa_NewHashTable();
- ctx->Query.CurrentOcclusionObject = NULL;
-}
-
-
-/**
- * Callback for deleting a query object. Called by _mesa_HashDeleteAll().
- */
-static void
-delete_queryobj_cb(GLuint id, void *data, void *userData)
-{
- struct gl_query_object *q= (struct gl_query_object *) data;
- struct gl_context *ctx = (struct gl_context *)userData;
- ctx->Driver.DeleteQuery(ctx, q);
-}
-
-
-/**
- * Free the context state related to query objects.
- */
-void
-_mesa_free_queryobj_data(struct gl_context *ctx)
-{
- _mesa_HashDeleteAll(ctx->Query.QueryObjects, delete_queryobj_cb, ctx);
- _mesa_DeleteHashTable(ctx->Query.QueryObjects);
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "glheader.h"
+#include "context.h"
+#include "enums.h"
+#include "hash.h"
+#include "imports.h"
+#include "queryobj.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "main/dispatch.h"
+
+
+#if FEATURE_queryobj
+
+
+/**
+ * Allocate a new query object. This is a fallback routine called via
+ * ctx->Driver.NewQueryObject().
+ * \param ctx - rendering context
+ * \param id - the new object's ID
+ * \return pointer to new query_object object or NULL if out of memory.
+ */
+struct gl_query_object *
+_mesa_new_query_object(struct gl_context *ctx, GLuint id)
+{
+ struct gl_query_object *q = MALLOC_STRUCT(gl_query_object);
+ (void) ctx;
+ if (q) {
+ q->Id = id;
+ q->Result = 0;
+ q->Active = GL_FALSE;
+ q->Ready = GL_TRUE; /* correct, see spec */
+ }
+ return q;
+}
+
+
+/**
+ * Begin a query. Software driver fallback.
+ * Called via ctx->Driver.BeginQuery().
+ */
+void
+_mesa_begin_query(struct gl_context *ctx, struct gl_query_object *q)
+{
+ /* no-op */
+}
+
+
+/**
+ * End a query. Software driver fallback.
+ * Called via ctx->Driver.EndQuery().
+ */
+void
+_mesa_end_query(struct gl_context *ctx, struct gl_query_object *q)
+{
+ q->Ready = GL_TRUE;
+}
+
+
+/**
+ * Wait for query to complete. Software driver fallback.
+ * Called via ctx->Driver.WaitQuery().
+ */
+void
+_mesa_wait_query(struct gl_context *ctx, struct gl_query_object *q)
+{
+ /* For software drivers, _mesa_end_query() should have completed the query.
+ * For real hardware, implement a proper WaitQuery() driver function,
+ * which may require issuing a flush.
+ */
+ assert(q->Ready);
+}
+
+
+/**
+ * Check if a query results are ready. Software driver fallback.
+ * Called via ctx->Driver.CheckQuery().
+ */
+static void
+_mesa_check_query(struct gl_context *ctx, struct gl_query_object *q)
+{
+ /* No-op for sw rendering.
+ * HW drivers may need to flush at this time.
+ */
+}
+
+
+/**
+ * Delete a query object. Called via ctx->Driver.DeleteQuery().
+ * Not removed from hash table here.
+ */
+void
+_mesa_delete_query(struct gl_context *ctx, struct gl_query_object *q)
+{
+ free(q);
+}
+
+
+void
+_mesa_init_query_object_functions(struct dd_function_table *driver)
+{
+ driver->NewQueryObject = _mesa_new_query_object;
+ driver->DeleteQuery = _mesa_delete_query;
+ driver->BeginQuery = _mesa_begin_query;
+ driver->EndQuery = _mesa_end_query;
+ driver->WaitQuery = _mesa_wait_query;
+ driver->CheckQuery = _mesa_check_query;
+}
+
+
+/**
+ * Return pointer to the query object binding point for the given target.
+ * \return NULL if invalid target, else the address of binding point
+ */
+static struct gl_query_object **
+get_query_binding_point(struct gl_context *ctx, GLenum target)
+{
+ switch (target) {
+ case GL_SAMPLES_PASSED_ARB:
+ if (ctx->Extensions.ARB_occlusion_query)
+ return &ctx->Query.CurrentOcclusionObject;
+ else
+ return NULL;
+ case GL_ANY_SAMPLES_PASSED:
+ if (ctx->Extensions.ARB_occlusion_query2)
+ return &ctx->Query.CurrentOcclusionObject;
+ else
+ return NULL;
+ case GL_TIME_ELAPSED_EXT:
+ if (ctx->Extensions.EXT_timer_query)
+ return &ctx->Query.CurrentTimerObject;
+ else
+ return NULL;
+#if FEATURE_EXT_transform_feedback
+ case GL_PRIMITIVES_GENERATED:
+ if (ctx->Extensions.EXT_transform_feedback)
+ return &ctx->Query.PrimitivesGenerated;
+ else
+ return NULL;
+ case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
+ if (ctx->Extensions.EXT_transform_feedback)
+ return &ctx->Query.PrimitivesWritten;
+ else
+ return NULL;
+#endif
+ default:
+ return NULL;
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GenQueriesARB(GLsizei n, GLuint *ids)
+{
+ GLuint first;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glGenQueries(%d)\n", n);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGenQueriesARB(n < 0)");
+ return;
+ }
+
+ /* No query objects can be active at this time! */
+ if (ctx->Query.CurrentOcclusionObject ||
+ ctx->Query.CurrentTimerObject) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGenQueriesARB");
+ return;
+ }
+
+ first = _mesa_HashFindFreeKeyBlock(ctx->Query.QueryObjects, n);
+ if (first) {
+ GLsizei i;
+ for (i = 0; i < n; i++) {
+ struct gl_query_object *q
+ = ctx->Driver.NewQueryObject(ctx, first + i);
+ if (!q) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenQueriesARB");
+ return;
+ }
+ ids[i] = first + i;
+ _mesa_HashInsert(ctx->Query.QueryObjects, first + i, q);
+ }
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_DeleteQueriesARB(GLsizei n, const GLuint *ids)
+{
+ GLint i;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glDeleeteQueries(%d)\n", n);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteQueriesARB(n < 0)");
+ return;
+ }
+
+ /* No query objects can be active at this time! */
+ if (ctx->Query.CurrentOcclusionObject ||
+ ctx->Query.CurrentTimerObject) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glDeleteQueriesARB");
+ return;
+ }
+
+ for (i = 0; i < n; i++) {
+ if (ids[i] > 0) {
+ struct gl_query_object *q = _mesa_lookup_query_object(ctx, ids[i]);
+ if (q) {
+ ASSERT(!q->Active); /* should be caught earlier */
+ _mesa_HashRemove(ctx->Query.QueryObjects, ids[i]);
+ ctx->Driver.DeleteQuery(ctx, q);
+ }
+ }
+ }
+}
+
+
+GLboolean GLAPIENTRY
+_mesa_IsQueryARB(GLuint id)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glIsQuery(%u)\n", id);
+
+ if (id && _mesa_lookup_query_object(ctx, id))
+ return GL_TRUE;
+ else
+ return GL_FALSE;
+}
+
+
+static void GLAPIENTRY
+_mesa_BeginQueryARB(GLenum target, GLuint id)
+{
+ struct gl_query_object *q, **bindpt;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glBeginQuery(%s, %u)\n",
+ _mesa_lookup_enum_by_nr(target), id);
+
+ FLUSH_VERTICES(ctx, _NEW_DEPTH);
+
+ bindpt = get_query_binding_point(ctx, target);
+ if (!bindpt) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBeginQueryARB(target)");
+ return;
+ }
+
+ if (id == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginQueryARB(id==0)");
+ return;
+ }
+
+ q = _mesa_lookup_query_object(ctx, id);
+ if (!q) {
+ /* create new object */
+ q = ctx->Driver.NewQueryObject(ctx, id);
+ if (!q) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBeginQueryARB");
+ return;
+ }
+ _mesa_HashInsert(ctx->Query.QueryObjects, id, q);
+ }
+ else {
+ /* pre-existing object */
+ if (q->Active) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBeginQueryARB(query already active)");
+ return;
+ }
+ }
+
+ q->Target = target;
+ q->Active = GL_TRUE;
+ q->Result = 0;
+ q->Ready = GL_FALSE;
+
+ /* XXX should probably refcount query objects */
+ *bindpt = q;
+
+ ctx->Driver.BeginQuery(ctx, q);
+}
+
+
+static void GLAPIENTRY
+_mesa_EndQueryARB(GLenum target)
+{
+ struct gl_query_object *q, **bindpt;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glEndQuery(%s)\n", _mesa_lookup_enum_by_nr(target));
+
+ FLUSH_VERTICES(ctx, _NEW_DEPTH);
+
+ bindpt = get_query_binding_point(ctx, target);
+ if (!bindpt) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glEndQueryARB(target)");
+ return;
+ }
+
+ /* XXX should probably refcount query objects */
+ q = *bindpt;
+ *bindpt = NULL;
+
+ if (!q || !q->Active) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glEndQueryARB(no matching glBeginQueryARB)");
+ return;
+ }
+
+ q->Active = GL_FALSE;
+ ctx->Driver.EndQuery(ctx, q);
+}
+
+
+void GLAPIENTRY
+_mesa_GetQueryivARB(GLenum target, GLenum pname, GLint *params)
+{
+ struct gl_query_object *q, **bindpt;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glGetQueryiv(%s, %s)\n",
+ _mesa_lookup_enum_by_nr(target),
+ _mesa_lookup_enum_by_nr(pname));
+
+ bindpt = get_query_binding_point(ctx, target);
+ if (!bindpt) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryARB(target)");
+ return;
+ }
+
+ q = *bindpt;
+
+ switch (pname) {
+ case GL_QUERY_COUNTER_BITS_ARB:
+ *params = 8 * sizeof(q->Result);
+ break;
+ case GL_CURRENT_QUERY_ARB:
+ *params = q ? q->Id : 0;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryivARB(pname)");
+ return;
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params)
+{
+ struct gl_query_object *q = NULL;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glGetQueryObjectiv(%u, %s)\n", id,
+ _mesa_lookup_enum_by_nr(pname));
+
+ if (id)
+ q = _mesa_lookup_query_object(ctx, id);
+
+ if (!q || q->Active) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetQueryObjectivARB(id=%d is invalid or active)", id);
+ return;
+ }
+
+ switch (pname) {
+ case GL_QUERY_RESULT_ARB:
+ if (!q->Ready)
+ ctx->Driver.WaitQuery(ctx, q);
+ /* if result is too large for returned type, clamp to max value */
+ if (q->Target == GL_ANY_SAMPLES_PASSED) {
+ if (q->Result)
+ *params = GL_TRUE;
+ else
+ *params = GL_FALSE;
+ } else {
+ if (q->Result > 0x7fffffff) {
+ *params = 0x7fffffff;
+ }
+ else {
+ *params = (GLint)q->Result;
+ }
+ }
+ break;
+ case GL_QUERY_RESULT_AVAILABLE_ARB:
+ if (!q->Ready)
+ ctx->Driver.CheckQuery( ctx, q );
+ *params = q->Ready;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryObjectivARB(pname)");
+ return;
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
+{
+ struct gl_query_object *q = NULL;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glGetQueryObjectuiv(%u, %s)\n", id,
+ _mesa_lookup_enum_by_nr(pname));
+
+ if (id)
+ q = _mesa_lookup_query_object(ctx, id);
+
+ if (!q || q->Active) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetQueryObjectuivARB(id=%d is invalid or active)", id);
+ return;
+ }
+
+ switch (pname) {
+ case GL_QUERY_RESULT_ARB:
+ if (!q->Ready)
+ ctx->Driver.WaitQuery(ctx, q);
+ /* if result is too large for returned type, clamp to max value */
+ if (q->Target == GL_ANY_SAMPLES_PASSED) {
+ if (q->Result)
+ *params = GL_TRUE;
+ else
+ *params = GL_FALSE;
+ } else {
+ if (q->Result > 0xffffffff) {
+ *params = 0xffffffff;
+ }
+ else {
+ *params = (GLuint)q->Result;
+ }
+ }
+ break;
+ case GL_QUERY_RESULT_AVAILABLE_ARB:
+ if (!q->Ready)
+ ctx->Driver.CheckQuery( ctx, q );
+ *params = q->Ready;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryObjectuivARB(pname)");
+ return;
+ }
+}
+
+
+/**
+ * New with GL_EXT_timer_query
+ */
+static void GLAPIENTRY
+_mesa_GetQueryObjecti64vEXT(GLuint id, GLenum pname, GLint64EXT *params)
+{
+ struct gl_query_object *q = NULL;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glGetQueryObjecti64v(%u, %s)\n", id,
+ _mesa_lookup_enum_by_nr(pname));
+
+ if (id)
+ q = _mesa_lookup_query_object(ctx, id);
+
+ if (!q || q->Active) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetQueryObjectui64vARB(id=%d is invalid or active)", id);
+ return;
+ }
+
+ switch (pname) {
+ case GL_QUERY_RESULT_ARB:
+ if (!q->Ready)
+ ctx->Driver.WaitQuery(ctx, q);
+ *params = q->Result;
+ break;
+ case GL_QUERY_RESULT_AVAILABLE_ARB:
+ if (!q->Ready)
+ ctx->Driver.CheckQuery( ctx, q );
+ *params = q->Ready;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryObjecti64vARB(pname)");
+ return;
+ }
+}
+
+
+/**
+ * New with GL_EXT_timer_query
+ */
+static void GLAPIENTRY
+_mesa_GetQueryObjectui64vEXT(GLuint id, GLenum pname, GLuint64EXT *params)
+{
+ struct gl_query_object *q = NULL;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glGetQueryObjectui64v(%u, %s)\n", id,
+ _mesa_lookup_enum_by_nr(pname));
+
+ if (id)
+ q = _mesa_lookup_query_object(ctx, id);
+
+ if (!q || q->Active) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetQueryObjectuui64vARB(id=%d is invalid or active)", id);
+ return;
+ }
+
+ switch (pname) {
+ case GL_QUERY_RESULT_ARB:
+ if (!q->Ready)
+ ctx->Driver.WaitQuery(ctx, q);
+ *params = q->Result;
+ break;
+ case GL_QUERY_RESULT_AVAILABLE_ARB:
+ if (!q->Ready)
+ ctx->Driver.CheckQuery( ctx, q );
+ *params = q->Ready;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryObjectui64vARB(pname)");
+ return;
+ }
+}
+
+
+void
+_mesa_init_queryobj_dispatch(struct _glapi_table *disp)
+{
+ SET_GenQueriesARB(disp, _mesa_GenQueriesARB);
+ SET_DeleteQueriesARB(disp, _mesa_DeleteQueriesARB);
+ SET_IsQueryARB(disp, _mesa_IsQueryARB);
+ SET_BeginQueryARB(disp, _mesa_BeginQueryARB);
+ SET_EndQueryARB(disp, _mesa_EndQueryARB);
+ SET_GetQueryivARB(disp, _mesa_GetQueryivARB);
+ SET_GetQueryObjectivARB(disp, _mesa_GetQueryObjectivARB);
+ SET_GetQueryObjectuivARB(disp, _mesa_GetQueryObjectuivARB);
+
+ SET_GetQueryObjecti64vEXT(disp, _mesa_GetQueryObjecti64vEXT);
+ SET_GetQueryObjectui64vEXT(disp, _mesa_GetQueryObjectui64vEXT);
+}
+
+
+#endif /* FEATURE_queryobj */
+
+
+/**
+ * Allocate/init the context state related to query objects.
+ */
+void
+_mesa_init_queryobj(struct gl_context *ctx)
+{
+ ctx->Query.QueryObjects = _mesa_NewHashTable();
+ ctx->Query.CurrentOcclusionObject = NULL;
+}
+
+
+/**
+ * Callback for deleting a query object. Called by _mesa_HashDeleteAll().
+ */
+static void
+delete_queryobj_cb(GLuint id, void *data, void *userData)
+{
+ struct gl_query_object *q= (struct gl_query_object *) data;
+ struct gl_context *ctx = (struct gl_context *)userData;
+ ctx->Driver.DeleteQuery(ctx, q);
+}
+
+
+/**
+ * Free the context state related to query objects.
+ */
+void
+_mesa_free_queryobj_data(struct gl_context *ctx)
+{
+ _mesa_HashDeleteAll(ctx->Query.QueryObjects, delete_queryobj_cb, ctx);
+ _mesa_DeleteHashTable(ctx->Query.QueryObjects);
+}
diff --git a/mesalib/src/mesa/main/readpix.c b/mesalib/src/mesa/main/readpix.c
index 6e09a52c8..e8b889d92 100644
--- a/mesalib/src/mesa/main/readpix.c
+++ b/mesalib/src/mesa/main/readpix.c
@@ -1,244 +1,244 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "glheader.h"
-#include "imports.h"
-#include "bufferobj.h"
-#include "context.h"
-#include "enums.h"
-#include "readpix.h"
-#include "framebuffer.h"
-#include "formats.h"
-#include "image.h"
-#include "mtypes.h"
-#include "pbo.h"
-#include "state.h"
-
-
-/**
- * Do error checking of the format/type parameters to glReadPixels and
- * glDrawPixels.
- * \param drawing if GL_TRUE do checking for DrawPixels, else do checking
- * for ReadPixels.
- * \return GL_TRUE if error detected, GL_FALSE if no errors
- */
-GLboolean
-_mesa_error_check_format_type(struct gl_context *ctx, GLenum format, GLenum type,
- GLboolean drawing)
-{
- const char *readDraw = drawing ? "Draw" : "Read";
- const GLboolean reading = !drawing;
-
- /* state validation should have already been done */
- ASSERT(ctx->NewState == 0x0);
-
- if (ctx->Extensions.EXT_packed_depth_stencil
- && type == GL_UNSIGNED_INT_24_8_EXT
- && format != GL_DEPTH_STENCIL_EXT) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "gl%sPixels(format is not GL_DEPTH_STENCIL_EXT)", readDraw);
- return GL_TRUE;
- }
-
- /* basic combinations test */
- if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "gl%sPixels(format or type)", readDraw);
- return GL_TRUE;
- }
-
- /* additional checks */
- switch (format) {
- case GL_RG:
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
- case GL_LUMINANCE:
- case GL_LUMINANCE_ALPHA:
- case GL_RGB:
- case GL_BGR:
- case GL_RGBA:
- case GL_BGRA:
- case GL_ABGR_EXT:
- case GL_RED_INTEGER_EXT:
- case GL_GREEN_INTEGER_EXT:
- case GL_BLUE_INTEGER_EXT:
- case GL_ALPHA_INTEGER_EXT:
- case GL_RGB_INTEGER_EXT:
- case GL_RGBA_INTEGER_EXT:
- case GL_BGR_INTEGER_EXT:
- case GL_BGRA_INTEGER_EXT:
- case GL_LUMINANCE_INTEGER_EXT:
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- if (!drawing) {
- /* reading */
- if (!_mesa_source_buffer_exists(ctx, GL_COLOR)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glReadPixels(no color buffer)");
- return GL_TRUE;
- }
- }
- break;
- case GL_COLOR_INDEX:
- if (drawing) {
- if (ctx->PixelMaps.ItoR.Size == 0 ||
- ctx->PixelMaps.ItoG.Size == 0 ||
- ctx->PixelMaps.ItoB.Size == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glDrawPixels(drawing color index pixels into RGB buffer)");
- return GL_TRUE;
- }
- }
- else {
- /* reading */
- if (!_mesa_source_buffer_exists(ctx, GL_COLOR)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glReadPixels(no color buffer)");
- return GL_TRUE;
- }
- /* We no longer support CI-mode color buffers so trying to read
- * GL_COLOR_INDEX pixels is always an error.
- */
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glReadPixels(color buffer is RGB)");
- return GL_TRUE;
- }
- break;
- case GL_STENCIL_INDEX:
- if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
- (reading && !_mesa_source_buffer_exists(ctx, format))) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "gl%sPixels(no stencil buffer)", readDraw);
- return GL_TRUE;
- }
- break;
- case GL_DEPTH_COMPONENT:
- if ((drawing && !_mesa_dest_buffer_exists(ctx, format))) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "gl%sPixels(no depth buffer)", readDraw);
- return GL_TRUE;
- }
- break;
- case GL_DEPTH_STENCIL_EXT:
- if (!ctx->Extensions.EXT_packed_depth_stencil ||
- type != GL_UNSIGNED_INT_24_8_EXT) {
- _mesa_error(ctx, GL_INVALID_ENUM, "gl%sPixels(type)", readDraw);
- return GL_TRUE;
- }
- if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
- (reading && !_mesa_source_buffer_exists(ctx, format))) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "gl%sPixels(no depth or stencil buffer)", readDraw);
- return GL_TRUE;
- }
- break;
- default:
- /* this should have been caught in _mesa_is_legal_format_type() */
- _mesa_problem(ctx, "unexpected format in _mesa_%sPixels", readDraw);
- return GL_TRUE;
- }
-
- /* no errors */
- return GL_FALSE;
-}
-
-
-
-void GLAPIENTRY
-_mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type, GLvoid *pixels )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- FLUSH_CURRENT(ctx, 0);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glReadPixels(%d, %d, %s, %s, %p)\n",
- width, height,
- _mesa_lookup_enum_by_nr(format),
- _mesa_lookup_enum_by_nr(type),
- pixels);
-
- if (width < 0 || height < 0) {
- _mesa_error( ctx, GL_INVALID_VALUE,
- "glReadPixels(width=%d height=%d)", width, height );
- return;
- }
-
- if (ctx->NewState)
- _mesa_update_state(ctx);
-
- if (_mesa_error_check_format_type(ctx, format, type, GL_FALSE)) {
- /* found an error */
- return;
- }
-
- /* Check that the destination format and source buffer are both
- * integer-valued or both non-integer-valued.
- */
- if (ctx->Extensions.EXT_texture_integer && _mesa_is_color_format(format)) {
- const struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
- const GLboolean srcInteger = _mesa_is_format_integer_color(rb->Format);
- const GLboolean dstInteger = _mesa_is_integer_format(format);
- if (dstInteger != srcInteger) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glReadPixels(integer / non-integer format mismatch");
- return;
- }
- }
-
- if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
- "glReadPixels(incomplete framebuffer)" );
- return;
- }
-
- if (!_mesa_source_buffer_exists(ctx, format)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(no readbuffer)");
- return;
- }
-
- if (width == 0 || height == 0)
- return; /* nothing to do */
-
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- if (!_mesa_validate_pbo_access(2, &ctx->Pack, width, height, 1,
- format, type, pixels)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glReadPixels(invalid PBO access)");
- return;
- }
-
- if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
- /* buffer is mapped - that's an error */
- _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
- return;
- }
- }
-
- ctx->Driver.ReadPixels(ctx, x, y, width, height,
- format, type, &ctx->Pack, pixels);
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "glheader.h"
+#include "imports.h"
+#include "bufferobj.h"
+#include "context.h"
+#include "enums.h"
+#include "readpix.h"
+#include "framebuffer.h"
+#include "formats.h"
+#include "image.h"
+#include "mtypes.h"
+#include "pbo.h"
+#include "state.h"
+
+
+/**
+ * Do error checking of the format/type parameters to glReadPixels and
+ * glDrawPixels.
+ * \param drawing if GL_TRUE do checking for DrawPixels, else do checking
+ * for ReadPixels.
+ * \return GL_TRUE if error detected, GL_FALSE if no errors
+ */
+GLboolean
+_mesa_error_check_format_type(struct gl_context *ctx, GLenum format, GLenum type,
+ GLboolean drawing)
+{
+ const char *readDraw = drawing ? "Draw" : "Read";
+ const GLboolean reading = !drawing;
+
+ /* state validation should have already been done */
+ ASSERT(ctx->NewState == 0x0);
+
+ if (ctx->Extensions.EXT_packed_depth_stencil
+ && type == GL_UNSIGNED_INT_24_8_EXT
+ && format != GL_DEPTH_STENCIL_EXT) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "gl%sPixels(format is not GL_DEPTH_STENCIL_EXT)", readDraw);
+ return GL_TRUE;
+ }
+
+ /* basic combinations test */
+ if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "gl%sPixels(format or type)", readDraw);
+ return GL_TRUE;
+ }
+
+ /* additional checks */
+ switch (format) {
+ case GL_RG:
+ case GL_RED:
+ case GL_GREEN:
+ case GL_BLUE:
+ case GL_ALPHA:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE_ALPHA:
+ case GL_RGB:
+ case GL_BGR:
+ case GL_RGBA:
+ case GL_BGRA:
+ case GL_ABGR_EXT:
+ case GL_RED_INTEGER_EXT:
+ case GL_GREEN_INTEGER_EXT:
+ case GL_BLUE_INTEGER_EXT:
+ case GL_ALPHA_INTEGER_EXT:
+ case GL_RGB_INTEGER_EXT:
+ case GL_RGBA_INTEGER_EXT:
+ case GL_BGR_INTEGER_EXT:
+ case GL_BGRA_INTEGER_EXT:
+ case GL_LUMINANCE_INTEGER_EXT:
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ if (!drawing) {
+ /* reading */
+ if (!_mesa_source_buffer_exists(ctx, GL_COLOR)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glReadPixels(no color buffer)");
+ return GL_TRUE;
+ }
+ }
+ break;
+ case GL_COLOR_INDEX:
+ if (drawing) {
+ if (ctx->PixelMaps.ItoR.Size == 0 ||
+ ctx->PixelMaps.ItoG.Size == 0 ||
+ ctx->PixelMaps.ItoB.Size == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glDrawPixels(drawing color index pixels into RGB buffer)");
+ return GL_TRUE;
+ }
+ }
+ else {
+ /* reading */
+ if (!_mesa_source_buffer_exists(ctx, GL_COLOR)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glReadPixels(no color buffer)");
+ return GL_TRUE;
+ }
+ /* We no longer support CI-mode color buffers so trying to read
+ * GL_COLOR_INDEX pixels is always an error.
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glReadPixels(color buffer is RGB)");
+ return GL_TRUE;
+ }
+ break;
+ case GL_STENCIL_INDEX:
+ if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
+ (reading && !_mesa_source_buffer_exists(ctx, format))) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "gl%sPixels(no stencil buffer)", readDraw);
+ return GL_TRUE;
+ }
+ break;
+ case GL_DEPTH_COMPONENT:
+ if ((drawing && !_mesa_dest_buffer_exists(ctx, format))) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "gl%sPixels(no depth buffer)", readDraw);
+ return GL_TRUE;
+ }
+ break;
+ case GL_DEPTH_STENCIL_EXT:
+ if (!ctx->Extensions.EXT_packed_depth_stencil ||
+ type != GL_UNSIGNED_INT_24_8_EXT) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "gl%sPixels(type)", readDraw);
+ return GL_TRUE;
+ }
+ if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
+ (reading && !_mesa_source_buffer_exists(ctx, format))) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "gl%sPixels(no depth or stencil buffer)", readDraw);
+ return GL_TRUE;
+ }
+ break;
+ default:
+ /* this should have been caught in _mesa_is_legal_format_type() */
+ _mesa_problem(ctx, "unexpected format in _mesa_%sPixels", readDraw);
+ return GL_TRUE;
+ }
+
+ /* no errors */
+ return GL_FALSE;
+}
+
+
+
+void GLAPIENTRY
+_mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type, GLvoid *pixels )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ FLUSH_CURRENT(ctx, 0);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glReadPixels(%d, %d, %s, %s, %p)\n",
+ width, height,
+ _mesa_lookup_enum_by_nr(format),
+ _mesa_lookup_enum_by_nr(type),
+ pixels);
+
+ if (width < 0 || height < 0) {
+ _mesa_error( ctx, GL_INVALID_VALUE,
+ "glReadPixels(width=%d height=%d)", width, height );
+ return;
+ }
+
+ if (ctx->NewState)
+ _mesa_update_state(ctx);
+
+ if (_mesa_error_check_format_type(ctx, format, type, GL_FALSE)) {
+ /* found an error */
+ return;
+ }
+
+ /* Check that the destination format and source buffer are both
+ * integer-valued or both non-integer-valued.
+ */
+ if (ctx->Extensions.EXT_texture_integer && _mesa_is_color_format(format)) {
+ const struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
+ const GLboolean srcInteger = _mesa_is_format_integer_color(rb->Format);
+ const GLboolean dstInteger = _mesa_is_integer_format(format);
+ if (dstInteger != srcInteger) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glReadPixels(integer / non-integer format mismatch");
+ return;
+ }
+ }
+
+ if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+ "glReadPixels(incomplete framebuffer)" );
+ return;
+ }
+
+ if (!_mesa_source_buffer_exists(ctx, format)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(no readbuffer)");
+ return;
+ }
+
+ if (width == 0 || height == 0)
+ return; /* nothing to do */
+
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ if (!_mesa_validate_pbo_access(2, &ctx->Pack, width, height, 1,
+ format, type, pixels)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glReadPixels(invalid PBO access)");
+ return;
+ }
+
+ if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
+ /* buffer is mapped - that's an error */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
+ return;
+ }
+ }
+
+ ctx->Driver.ReadPixels(ctx, x, y, width, height,
+ format, type, &ctx->Pack, pixels);
+}
diff --git a/mesalib/src/mesa/main/shaderapi.c b/mesalib/src/mesa/main/shaderapi.c
index 11b0f884f..252cda845 100644
--- a/mesalib/src/mesa/main/shaderapi.c
+++ b/mesalib/src/mesa/main/shaderapi.c
@@ -1,1942 +1,1942 @@
-/*
- * Mesa 3-D graphics library
- *
- * Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009-2010 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file shaderapi.c
- * \author Brian Paul
- *
- * Implementation of GLSL-related API functions.
- * The glUniform* functions are in uniforms.c
- *
- *
- * XXX things to do:
- * 1. Check that the right error code is generated for all _mesa_error() calls.
- * 2. Insert FLUSH_VERTICES calls in various places
- */
-
-
-#include "main/glheader.h"
-#include "main/context.h"
-#include "main/dispatch.h"
-#include "main/enums.h"
-#include "main/hash.h"
-#include "main/mfeatures.h"
-#include "main/mtypes.h"
-#include "main/shaderapi.h"
-#include "main/shaderobj.h"
-#include "program/program.h"
-#include "program/prog_parameter.h"
-#include "program/prog_uniform.h"
-#include "ralloc.h"
-#include <stdbool.h>
-#include "../glsl/glsl_parser_extras.h"
-
-/** Define this to enable shader substitution (see below) */
-#define SHADER_SUBST 0
-
-
-/**
- * Return mask of GLSL_x flags by examining the MESA_GLSL env var.
- */
-static GLbitfield
-get_shader_flags(void)
-{
- GLbitfield flags = 0x0;
- const char *env = _mesa_getenv("MESA_GLSL");
-
- if (env) {
- if (strstr(env, "dump"))
- flags |= GLSL_DUMP;
- if (strstr(env, "log"))
- flags |= GLSL_LOG;
- if (strstr(env, "nopvert"))
- flags |= GLSL_NOP_VERT;
- if (strstr(env, "nopfrag"))
- flags |= GLSL_NOP_FRAG;
- if (strstr(env, "nopt"))
- flags |= GLSL_NO_OPT;
- else if (strstr(env, "opt"))
- flags |= GLSL_OPT;
- if (strstr(env, "uniform"))
- flags |= GLSL_UNIFORMS;
- if (strstr(env, "useprog"))
- flags |= GLSL_USE_PROG;
- }
-
- return flags;
-}
-
-
-/**
- * Initialize context's shader state.
- */
-void
-_mesa_init_shader_state(struct gl_context *ctx)
-{
- /* Device drivers may override these to control what kind of instructions
- * are generated by the GLSL compiler.
- */
- struct gl_shader_compiler_options options;
- gl_shader_type sh;
-
- memset(&options, 0, sizeof(options));
- options.MaxUnrollIterations = 32;
-
- /* Default pragma settings */
- options.DefaultPragmas.Optimize = GL_TRUE;
-
- for (sh = 0; sh < MESA_SHADER_TYPES; ++sh)
- memcpy(&ctx->ShaderCompilerOptions[sh], &options, sizeof(options));
-
- ctx->Shader.Flags = get_shader_flags();
-}
-
-
-/**
- * Free the per-context shader-related state.
- */
-void
-_mesa_free_shader_state(struct gl_context *ctx)
-{
- _mesa_reference_shader_program(ctx, &ctx->Shader.CurrentVertexProgram, NULL);
- _mesa_reference_shader_program(ctx, &ctx->Shader.CurrentGeometryProgram,
- NULL);
- _mesa_reference_shader_program(ctx, &ctx->Shader.CurrentFragmentProgram,
- NULL);
- _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, NULL);
-}
-
-
-/**
- * Return the size of the given GLSL datatype, in floats (components).
- */
-GLint
-_mesa_sizeof_glsl_type(GLenum type)
-{
- switch (type) {
- case GL_FLOAT:
- case GL_INT:
- case GL_BOOL:
- case GL_SAMPLER_1D:
- case GL_SAMPLER_2D:
- case GL_SAMPLER_3D:
- case GL_SAMPLER_CUBE:
- case GL_SAMPLER_1D_SHADOW:
- case GL_SAMPLER_2D_SHADOW:
- case GL_SAMPLER_2D_RECT_ARB:
- case GL_SAMPLER_2D_RECT_SHADOW_ARB:
- case GL_SAMPLER_1D_ARRAY_EXT:
- case GL_SAMPLER_2D_ARRAY_EXT:
- case GL_SAMPLER_1D_ARRAY_SHADOW_EXT:
- case GL_SAMPLER_2D_ARRAY_SHADOW_EXT:
- case GL_SAMPLER_CUBE_SHADOW_EXT:
- return 1;
- case GL_FLOAT_VEC2:
- case GL_INT_VEC2:
- case GL_UNSIGNED_INT_VEC2:
- case GL_BOOL_VEC2:
- return 2;
- case GL_FLOAT_VEC3:
- case GL_INT_VEC3:
- case GL_UNSIGNED_INT_VEC3:
- case GL_BOOL_VEC3:
- return 3;
- case GL_FLOAT_VEC4:
- case GL_INT_VEC4:
- case GL_UNSIGNED_INT_VEC4:
- case GL_BOOL_VEC4:
- return 4;
- case GL_FLOAT_MAT2:
- case GL_FLOAT_MAT2x3:
- case GL_FLOAT_MAT2x4:
- return 8; /* two float[4] vectors */
- case GL_FLOAT_MAT3:
- case GL_FLOAT_MAT3x2:
- case GL_FLOAT_MAT3x4:
- return 12; /* three float[4] vectors */
- case GL_FLOAT_MAT4:
- case GL_FLOAT_MAT4x2:
- case GL_FLOAT_MAT4x3:
- return 16; /* four float[4] vectors */
- default:
- _mesa_problem(NULL, "Invalid type in _mesa_sizeof_glsl_type()");
- return 1;
- }
-}
-
-
-/**
- * Copy string from <src> to <dst>, up to maxLength characters, returning
- * length of <dst> in <length>.
- * \param src the strings source
- * \param maxLength max chars to copy
- * \param length returns number of chars copied
- * \param dst the string destination
- */
-void
-_mesa_copy_string(GLchar *dst, GLsizei maxLength,
- GLsizei *length, const GLchar *src)
-{
- GLsizei len;
- for (len = 0; len < maxLength - 1 && src && src[len]; len++)
- dst[len] = src[len];
- if (maxLength > 0)
- dst[len] = 0;
- if (length)
- *length = len;
-}
-
-
-
-/**
- * Confirm that the a shader type is valid and supported by the implementation
- *
- * \param ctx Current GL context
- * \param type Shader target
- *
- */
-static bool
-validate_shader_target(const struct gl_context *ctx, GLenum type)
-{
- switch (type) {
-#if FEATURE_ARB_fragment_shader
- case GL_FRAGMENT_SHADER:
- return ctx->Extensions.ARB_fragment_shader;
-#endif
-#if FEATURE_ARB_vertex_shader
- case GL_VERTEX_SHADER:
- return ctx->Extensions.ARB_vertex_shader;
-#endif
-#if FEATURE_ARB_geometry_shader4
- case GL_GEOMETRY_SHADER_ARB:
- return ctx->Extensions.ARB_geometry_shader4;
-#endif
- default:
- return false;
- }
-}
-
-
-/**
- * Find the length of the longest transform feedback varying name
- * which was specified with glTransformFeedbackVaryings().
- */
-static GLint
-longest_feedback_varying_name(const struct gl_shader_program *shProg)
-{
- GLuint i;
- GLint max = 0;
- for (i = 0; i < shProg->TransformFeedback.NumVarying; i++) {
- GLint len = strlen(shProg->TransformFeedback.VaryingNames[i]);
- if (len > max)
- max = len;
- }
- return max;
-}
-
-
-
-static GLboolean
-is_program(struct gl_context *ctx, GLuint name)
-{
- struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, name);
- return shProg ? GL_TRUE : GL_FALSE;
-}
-
-
-static GLboolean
-is_shader(struct gl_context *ctx, GLuint name)
-{
- struct gl_shader *shader = _mesa_lookup_shader(ctx, name);
- return shader ? GL_TRUE : GL_FALSE;
-}
-
-
-/**
- * Attach shader to a shader program.
- */
-static void
-attach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
-{
- struct gl_shader_program *shProg;
- struct gl_shader *sh;
- GLuint i, n;
-
- shProg = _mesa_lookup_shader_program_err(ctx, program, "glAttachShader");
- if (!shProg)
- return;
-
- sh = _mesa_lookup_shader_err(ctx, shader, "glAttachShader");
- if (!sh) {
- return;
- }
-
- n = shProg->NumShaders;
- for (i = 0; i < n; i++) {
- if (shProg->Shaders[i] == sh) {
- /* The shader is already attched to this program. The
- * GL_ARB_shader_objects spec says:
- *
- * "The error INVALID_OPERATION is generated by AttachObjectARB
- * if <obj> is already attached to <containerObj>."
- */
- _mesa_error(ctx, GL_INVALID_OPERATION, "glAttachShader");
- return;
- }
- }
-
- /* grow list */
- shProg->Shaders = (struct gl_shader **)
- _mesa_realloc(shProg->Shaders,
- n * sizeof(struct gl_shader *),
- (n + 1) * sizeof(struct gl_shader *));
- if (!shProg->Shaders) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAttachShader");
- return;
- }
-
- /* append */
- shProg->Shaders[n] = NULL; /* since realloc() didn't zero the new space */
- _mesa_reference_shader(ctx, &shProg->Shaders[n], sh);
- shProg->NumShaders++;
-}
-
-
-static GLint
-get_attrib_location(struct gl_context *ctx, GLuint program, const GLchar *name)
-{
- struct gl_shader_program *shProg
- = _mesa_lookup_shader_program_err(ctx, program, "glGetAttribLocation");
-
- if (!shProg) {
- return -1;
- }
-
- if (!shProg->LinkStatus) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetAttribLocation(program not linked)");
- return -1;
- }
-
- if (!name)
- return -1;
-
- if (shProg->VertexProgram) {
- const struct gl_program_parameter_list *attribs =
- shProg->VertexProgram->Base.Attributes;
- if (attribs) {
- GLint i = _mesa_lookup_parameter_index(attribs, -1, name);
- if (i >= 0) {
- return attribs->Parameters[i].StateIndexes[0];
- }
- }
- }
- return -1;
-}
-
-
-static void
-bind_attrib_location(struct gl_context *ctx, GLuint program, GLuint index,
- const GLchar *name)
-{
- struct gl_shader_program *shProg;
- const GLint size = -1; /* unknown size */
- GLint i, oldIndex;
- GLenum datatype = GL_FLOAT_VEC4;
-
- shProg = _mesa_lookup_shader_program_err(ctx, program,
- "glBindAttribLocation");
- if (!shProg) {
- return;
- }
-
- if (!name)
- return;
-
- if (strncmp(name, "gl_", 3) == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBindAttribLocation(illegal name)");
- return;
- }
-
- if (index >= ctx->Const.VertexProgram.MaxAttribs) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glBindAttribLocation(index)");
- return;
- }
-
- if (shProg->LinkStatus) {
- /* get current index/location for the attribute */
- oldIndex = get_attrib_location(ctx, program, name);
- }
- else {
- oldIndex = -1;
- }
-
- /* this will replace the current value if it's already in the list */
- i = _mesa_add_attribute(shProg->Attributes, name, size, datatype, index);
- if (i < 0) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindAttribLocation");
- return;
- }
-
- /*
- * Note that this attribute binding won't go into effect until
- * glLinkProgram is called again.
- */
-}
-
-
-static void
-bind_frag_data_location(struct gl_context *ctx, GLuint program,
- GLuint colorNumber, const GLchar *name)
-{
- _mesa_problem(ctx, "bind_frag_data_location() not implemented yet");
-}
-
-
-static GLuint
-create_shader(struct gl_context *ctx, GLenum type)
-{
- struct gl_shader *sh;
- GLuint name;
-
- if (!validate_shader_target(ctx, type)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "CreateShader(type)");
- return 0;
- }
-
- name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
- sh = ctx->Driver.NewShader(ctx, name, type);
- _mesa_HashInsert(ctx->Shared->ShaderObjects, name, sh);
-
- return name;
-}
-
-
-static GLuint
-create_shader_program(struct gl_context *ctx)
-{
- GLuint name;
- struct gl_shader_program *shProg;
-
- name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
-
- shProg = ctx->Driver.NewShaderProgram(ctx, name);
-
- _mesa_HashInsert(ctx->Shared->ShaderObjects, name, shProg);
-
- assert(shProg->RefCount == 1);
-
- return name;
-}
-
-
-/**
- * Named w/ "2" to indicate OpenGL 2.x vs GL_ARB_fragment_programs's
- * DeleteProgramARB.
- */
-static void
-delete_shader_program(struct gl_context *ctx, GLuint name)
-{
- /*
- * NOTE: deleting shaders/programs works a bit differently than
- * texture objects (and buffer objects, etc). Shader/program
- * handles/IDs exist in the hash table until the object is really
- * deleted (refcount==0). With texture objects, the handle/ID is
- * removed from the hash table in glDeleteTextures() while the tex
- * object itself might linger until its refcount goes to zero.
- */
- struct gl_shader_program *shProg;
-
- shProg = _mesa_lookup_shader_program_err(ctx, name, "glDeleteProgram");
- if (!shProg)
- return;
-
- shProg->DeletePending = GL_TRUE;
-
- /* effectively, decr shProg's refcount */
- _mesa_reference_shader_program(ctx, &shProg, NULL);
-}
-
-
-static void
-delete_shader(struct gl_context *ctx, GLuint shader)
-{
- struct gl_shader *sh;
-
- sh = _mesa_lookup_shader_err(ctx, shader, "glDeleteShader");
- if (!sh)
- return;
-
- sh->DeletePending = GL_TRUE;
-
- /* effectively, decr sh's refcount */
- _mesa_reference_shader(ctx, &sh, NULL);
-}
-
-
-static void
-detach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
-{
- struct gl_shader_program *shProg;
- GLuint n;
- GLuint i, j;
-
- shProg = _mesa_lookup_shader_program_err(ctx, program, "glDetachShader");
- if (!shProg)
- return;
-
- n = shProg->NumShaders;
-
- for (i = 0; i < n; i++) {
- if (shProg->Shaders[i]->Name == shader) {
- /* found it */
- struct gl_shader **newList;
-
- /* release */
- _mesa_reference_shader(ctx, &shProg->Shaders[i], NULL);
-
- /* alloc new, smaller array */
- newList = (struct gl_shader **)
- malloc((n - 1) * sizeof(struct gl_shader *));
- if (!newList) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDetachShader");
- return;
- }
- for (j = 0; j < i; j++) {
- newList[j] = shProg->Shaders[j];
- }
- while (++i < n)
- newList[j++] = shProg->Shaders[i];
- free(shProg->Shaders);
-
- shProg->Shaders = newList;
- shProg->NumShaders = n - 1;
-
-#ifdef DEBUG
- /* sanity check */
- {
- for (j = 0; j < shProg->NumShaders; j++) {
- assert(shProg->Shaders[j]->Type == GL_VERTEX_SHADER ||
- shProg->Shaders[j]->Type == GL_FRAGMENT_SHADER);
- assert(shProg->Shaders[j]->RefCount > 0);
- }
- }
-#endif
-
- return;
- }
- }
-
- /* not found */
- {
- GLenum err;
- if (is_shader(ctx, shader))
- err = GL_INVALID_OPERATION;
- else if (is_program(ctx, shader))
- err = GL_INVALID_OPERATION;
- else
- err = GL_INVALID_VALUE;
- _mesa_error(ctx, err, "glDetachProgram(shader)");
- return;
- }
-}
-
-
-static void
-get_active_attrib(struct gl_context *ctx, GLuint program, GLuint index,
- GLsizei maxLength, GLsizei *length, GLint *size,
- GLenum *type, GLchar *nameOut)
-{
- const struct gl_program_parameter_list *attribs = NULL;
- struct gl_shader_program *shProg;
-
- shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveAttrib");
- if (!shProg)
- return;
-
- if (shProg->VertexProgram)
- attribs = shProg->VertexProgram->Base.Attributes;
-
- if (!attribs || index >= attribs->NumParameters) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveAttrib(index)");
- return;
- }
-
- _mesa_copy_string(nameOut, maxLength, length,
- attribs->Parameters[index].Name);
-
- if (size)
- *size = attribs->Parameters[index].Size
- / _mesa_sizeof_glsl_type(attribs->Parameters[index].DataType);
-
- if (type)
- *type = attribs->Parameters[index].DataType;
-}
-
-
-/**
- * Return list of shaders attached to shader program.
- */
-static void
-get_attached_shaders(struct gl_context *ctx, GLuint program, GLsizei maxCount,
- GLsizei *count, GLuint *obj)
-{
- struct gl_shader_program *shProg =
- _mesa_lookup_shader_program_err(ctx, program, "glGetAttachedShaders");
- if (shProg) {
- GLuint i;
- for (i = 0; i < (GLuint) maxCount && i < shProg->NumShaders; i++) {
- obj[i] = shProg->Shaders[i]->Name;
- }
- if (count)
- *count = i;
- }
-}
-
-
-static GLint
-get_frag_data_location(struct gl_context *ctx, GLuint program,
- const GLchar *name)
-{
- _mesa_problem(ctx, "get_frag_data_location() not implemented yet");
- return -1;
-}
-
-
-
-/**
- * glGetHandleARB() - return ID/name of currently bound shader program.
- */
-static GLuint
-get_handle(struct gl_context *ctx, GLenum pname)
-{
- if (pname == GL_PROGRAM_OBJECT_ARB) {
- if (ctx->Shader.ActiveProgram)
- return ctx->Shader.ActiveProgram->Name;
- else
- return 0;
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetHandleARB");
- return 0;
- }
-}
-
-
-/**
- * glGetProgramiv() - get shader program state.
- * Note that this is for GLSL shader programs, not ARB vertex/fragment
- * programs (see glGetProgramivARB).
- */
-static void
-get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, GLint *params)
-{
- const struct gl_program_parameter_list *attribs;
- struct gl_shader_program *shProg
- = _mesa_lookup_shader_program(ctx, program);
-
- if (!shProg) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramiv(program)");
- return;
- }
-
- if (shProg->VertexProgram)
- attribs = shProg->VertexProgram->Base.Attributes;
- else
- attribs = NULL;
-
- switch (pname) {
- case GL_DELETE_STATUS:
- *params = shProg->DeletePending;
- break;
- case GL_LINK_STATUS:
- *params = shProg->LinkStatus;
- break;
- case GL_VALIDATE_STATUS:
- *params = shProg->Validated;
- break;
- case GL_INFO_LOG_LENGTH:
- *params = shProg->InfoLog ? strlen(shProg->InfoLog) + 1 : 0;
- break;
- case GL_ATTACHED_SHADERS:
- *params = shProg->NumShaders;
- break;
- case GL_ACTIVE_ATTRIBUTES:
- *params = attribs ? attribs->NumParameters : 0;
- break;
- case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
- *params = _mesa_longest_parameter_name(attribs, PROGRAM_INPUT) + 1;
- break;
- case GL_ACTIVE_UNIFORMS:
- *params = shProg->Uniforms ? shProg->Uniforms->NumUniforms : 0;
- break;
- case GL_ACTIVE_UNIFORM_MAX_LENGTH:
- *params = _mesa_longest_uniform_name(shProg->Uniforms);
- if (*params > 0)
- (*params)++; /* add one for terminating zero */
- break;
- case GL_PROGRAM_BINARY_LENGTH_OES:
- *params = 0;
- break;
-#if FEATURE_EXT_transform_feedback
- case GL_TRANSFORM_FEEDBACK_VARYINGS:
- *params = shProg->TransformFeedback.NumVarying;
- break;
- case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
- *params = longest_feedback_varying_name(shProg) + 1;
- break;
- case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
- *params = shProg->TransformFeedback.BufferMode;
- break;
-#endif
-#if FEATURE_ARB_geometry_shader4
- case GL_GEOMETRY_VERTICES_OUT_ARB:
- *params = shProg->Geom.VerticesOut;
- break;
- case GL_GEOMETRY_INPUT_TYPE_ARB:
- *params = shProg->Geom.InputType;
- break;
- case GL_GEOMETRY_OUTPUT_TYPE_ARB:
- *params = shProg->Geom.OutputType;
- break;
-#endif
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramiv(pname)");
- return;
- }
-}
-
-
-/**
- * glGetShaderiv() - get GLSL shader state
- */
-static void
-get_shaderiv(struct gl_context *ctx, GLuint name, GLenum pname, GLint *params)
-{
- struct gl_shader *shader =
- _mesa_lookup_shader_err(ctx, name, "glGetShaderiv");
-
- if (!shader) {
- return;
- }
-
- switch (pname) {
- case GL_SHADER_TYPE:
- *params = shader->Type;
- break;
- case GL_DELETE_STATUS:
- *params = shader->DeletePending;
- break;
- case GL_COMPILE_STATUS:
- *params = shader->CompileStatus;
- break;
- case GL_INFO_LOG_LENGTH:
- *params = shader->InfoLog ? strlen(shader->InfoLog) + 1 : 0;
- break;
- case GL_SHADER_SOURCE_LENGTH:
- *params = shader->Source ? strlen((char *) shader->Source) + 1 : 0;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetShaderiv(pname)");
- return;
- }
-}
-
-
-static void
-get_program_info_log(struct gl_context *ctx, GLuint program, GLsizei bufSize,
- GLsizei *length, GLchar *infoLog)
-{
- struct gl_shader_program *shProg
- = _mesa_lookup_shader_program(ctx, program);
- if (!shProg) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramInfoLog(program)");
- return;
- }
- _mesa_copy_string(infoLog, bufSize, length, shProg->InfoLog);
-}
-
-
-static void
-get_shader_info_log(struct gl_context *ctx, GLuint shader, GLsizei bufSize,
- GLsizei *length, GLchar *infoLog)
-{
- struct gl_shader *sh = _mesa_lookup_shader(ctx, shader);
- if (!sh) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGetShaderInfoLog(shader)");
- return;
- }
- _mesa_copy_string(infoLog, bufSize, length, sh->InfoLog);
-}
-
-
-/**
- * Return shader source code.
- */
-static void
-get_shader_source(struct gl_context *ctx, GLuint shader, GLsizei maxLength,
- GLsizei *length, GLchar *sourceOut)
-{
- struct gl_shader *sh;
- sh = _mesa_lookup_shader_err(ctx, shader, "glGetShaderSource");
- if (!sh) {
- return;
- }
- _mesa_copy_string(sourceOut, maxLength, length, sh->Source);
-}
-
-
-/**
- * Set/replace shader source code.
- */
-static void
-shader_source(struct gl_context *ctx, GLuint shader, const GLchar *source)
-{
- struct gl_shader *sh;
-
- sh = _mesa_lookup_shader_err(ctx, shader, "glShaderSource");
- if (!sh)
- return;
-
- /* free old shader source string and install new one */
- if (sh->Source) {
- free((void *) sh->Source);
- }
- sh->Source = source;
- sh->CompileStatus = GL_FALSE;
-#ifdef DEBUG
- sh->SourceChecksum = _mesa_str_checksum(sh->Source);
-#endif
-}
-
-
-/**
- * Compile a shader.
- */
-static void
-compile_shader(struct gl_context *ctx, GLuint shaderObj)
-{
- struct gl_shader *sh;
- struct gl_shader_compiler_options *options;
-
- sh = _mesa_lookup_shader_err(ctx, shaderObj, "glCompileShader");
- if (!sh)
- return;
-
- options = &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(sh->Type)];
-
- /* set default pragma state for shader */
- sh->Pragmas = options->DefaultPragmas;
-
- /* this call will set the sh->CompileStatus field to indicate if
- * compilation was successful.
- */
- _mesa_glsl_compile_shader(ctx, sh);
-}
-
-
-/**
- * Link a program's shaders.
- */
-static void
-link_program(struct gl_context *ctx, GLuint program)
-{
- struct gl_shader_program *shProg;
- struct gl_transform_feedback_object *obj =
- ctx->TransformFeedback.CurrentObject;
-
- shProg = _mesa_lookup_shader_program_err(ctx, program, "glLinkProgram");
- if (!shProg)
- return;
-
- if (obj->Active
- && (shProg == ctx->Shader.CurrentVertexProgram
- || shProg == ctx->Shader.CurrentGeometryProgram
- || shProg == ctx->Shader.CurrentFragmentProgram)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glLinkProgram(transform feedback active");
- return;
- }
-
- FLUSH_VERTICES(ctx, _NEW_PROGRAM);
-
- _mesa_glsl_link_shader(ctx, shProg);
-
- /* debug code */
- if (0) {
- GLuint i;
-
- printf("Link %u shaders in program %u: %s\n",
- shProg->NumShaders, shProg->Name,
- shProg->LinkStatus ? "Success" : "Failed");
-
- for (i = 0; i < shProg->NumShaders; i++) {
- printf(" shader %u, type 0x%x\n",
- shProg->Shaders[i]->Name,
- shProg->Shaders[i]->Type);
- }
- }
-}
-
-
-/**
- * Print basic shader info (for debug).
- */
-static void
-print_shader_info(const struct gl_shader_program *shProg)
-{
- GLuint i;
-
- printf("Mesa: glUseProgram(%u)\n", shProg->Name);
- for (i = 0; i < shProg->NumShaders; i++) {
- const char *s;
- switch (shProg->Shaders[i]->Type) {
- case GL_VERTEX_SHADER:
- s = "vertex";
- break;
- case GL_FRAGMENT_SHADER:
- s = "fragment";
- break;
- case GL_GEOMETRY_SHADER:
- s = "geometry";
- break;
- default:
- s = "";
- }
- printf(" %s shader %u, checksum %u\n", s,
- shProg->Shaders[i]->Name,
- shProg->Shaders[i]->SourceChecksum);
- }
- if (shProg->VertexProgram)
- printf(" vert prog %u\n", shProg->VertexProgram->Base.Id);
- if (shProg->FragmentProgram)
- printf(" frag prog %u\n", shProg->FragmentProgram->Base.Id);
-}
-
-
-/**
- * Use the named shader program for subsequent glUniform calls
- */
-void
-_mesa_active_program(struct gl_context *ctx, struct gl_shader_program *shProg,
- const char *caller)
-{
- if ((shProg != NULL) && !shProg->LinkStatus) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(program %u not linked)", caller, shProg->Name);
- return;
- }
-
- if (ctx->Shader.ActiveProgram != shProg) {
- _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, shProg);
- }
-}
-
-/**
- */
-static bool
-use_shader_program(struct gl_context *ctx, GLenum type,
- struct gl_shader_program *shProg)
-{
- struct gl_shader_program **target;
-
- switch (type) {
-#if FEATURE_ARB_vertex_shader
- case GL_VERTEX_SHADER:
- target = &ctx->Shader.CurrentVertexProgram;
- if ((shProg == NULL)
- || (shProg->_LinkedShaders[MESA_SHADER_VERTEX] == NULL)) {
- shProg = NULL;
- }
- break;
-#endif
-#if FEATURE_ARB_geometry_shader4
- case GL_GEOMETRY_SHADER_ARB:
- target = &ctx->Shader.CurrentGeometryProgram;
- if ((shProg == NULL)
- || (shProg->_LinkedShaders[MESA_SHADER_GEOMETRY] == NULL)) {
- shProg = NULL;
- }
- break;
-#endif
-#if FEATURE_ARB_fragment_shader
- case GL_FRAGMENT_SHADER:
- target = &ctx->Shader.CurrentFragmentProgram;
- if ((shProg == NULL)
- || (shProg->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL)) {
- shProg = NULL;
- }
- break;
-#endif
- default:
- return false;
- }
-
- if (*target != shProg) {
- FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS);
- _mesa_reference_shader_program(ctx, target, shProg);
- return true;
- }
-
- return false;
-}
-
-/**
- * Use the named shader program for subsequent rendering.
- */
-void
-_mesa_use_program(struct gl_context *ctx, struct gl_shader_program *shProg)
-{
- use_shader_program(ctx, GL_VERTEX_SHADER, shProg);
- use_shader_program(ctx, GL_GEOMETRY_SHADER_ARB, shProg);
- use_shader_program(ctx, GL_FRAGMENT_SHADER, shProg);
- _mesa_active_program(ctx, shProg, "glUseProgram");
-
- if (ctx->Driver.UseProgram)
- ctx->Driver.UseProgram(ctx, shProg);
-}
-
-
-/**
- * Validate a program's samplers.
- * Specifically, check that there aren't two samplers of different types
- * pointing to the same texture unit.
- * \return GL_TRUE if valid, GL_FALSE if invalid
- */
-static GLboolean
-validate_samplers(const struct gl_program *prog, char *errMsg)
-{
- static const char *targetName[] = {
- "TEXTURE_2D_ARRAY",
- "TEXTURE_1D_ARRAY",
- "TEXTURE_CUBE",
- "TEXTURE_3D",
- "TEXTURE_RECT",
- "TEXTURE_2D",
- "TEXTURE_1D",
- };
- GLint targetUsed[MAX_TEXTURE_IMAGE_UNITS];
- GLbitfield samplersUsed = prog->SamplersUsed;
- GLuint i;
-
- assert(Elements(targetName) == NUM_TEXTURE_TARGETS);
-
- if (samplersUsed == 0x0)
- return GL_TRUE;
-
- for (i = 0; i < Elements(targetUsed); i++)
- targetUsed[i] = -1;
-
- /* walk over bits which are set in 'samplers' */
- while (samplersUsed) {
- GLuint unit;
- gl_texture_index target;
- GLint sampler = _mesa_ffs(samplersUsed) - 1;
- assert(sampler >= 0);
- assert(sampler < MAX_TEXTURE_IMAGE_UNITS);
- unit = prog->SamplerUnits[sampler];
- target = prog->SamplerTargets[sampler];
- if (targetUsed[unit] != -1 && targetUsed[unit] != (int) target) {
- _mesa_snprintf(errMsg, 100,
- "Texture unit %d is accessed both as %s and %s",
- unit, targetName[targetUsed[unit]], targetName[target]);
- return GL_FALSE;
- }
- targetUsed[unit] = target;
- samplersUsed ^= (1 << sampler);
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Do validation of the given shader program.
- * \param errMsg returns error message if validation fails.
- * \return GL_TRUE if valid, GL_FALSE if invalid (and set errMsg)
- */
-static GLboolean
-validate_shader_program(const struct gl_shader_program *shProg,
- char *errMsg)
-{
- const struct gl_vertex_program *vp = shProg->VertexProgram;
- const struct gl_fragment_program *fp = shProg->FragmentProgram;
-
- if (!shProg->LinkStatus) {
- return GL_FALSE;
- }
-
- /* From the GL spec, a program is invalid if any of these are true:
-
- any two active samplers in the current program object are of
- different types, but refer to the same texture image unit,
-
- any active sampler in the current program object refers to a texture
- image unit where fixed-function fragment processing accesses a
- texture target that does not match the sampler type, or
-
- the sum of the number of active samplers in the program and the
- number of texture image units enabled for fixed-function fragment
- processing exceeds the combined limit on the total number of texture
- image units allowed.
- */
-
-
- /*
- * Check: any two active samplers in the current program object are of
- * different types, but refer to the same texture image unit,
- */
- if (vp && !validate_samplers(&vp->Base, errMsg)) {
- return GL_FALSE;
- }
- if (fp && !validate_samplers(&fp->Base, errMsg)) {
- return GL_FALSE;
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Called via glValidateProgram()
- */
-static void
-validate_program(struct gl_context *ctx, GLuint program)
-{
- struct gl_shader_program *shProg;
- char errMsg[100];
-
- shProg = _mesa_lookup_shader_program_err(ctx, program, "glValidateProgram");
- if (!shProg) {
- return;
- }
-
- shProg->Validated = validate_shader_program(shProg, errMsg);
- if (!shProg->Validated) {
- /* update info log */
- if (shProg->InfoLog) {
- ralloc_free(shProg->InfoLog);
- }
- shProg->InfoLog = ralloc_strdup(shProg, errMsg);
- }
-}
-
-
-
-void GLAPIENTRY
-_mesa_AttachObjectARB(GLhandleARB program, GLhandleARB shader)
-{
- GET_CURRENT_CONTEXT(ctx);
- attach_shader(ctx, program, shader);
-}
-
-
-void GLAPIENTRY
-_mesa_AttachShader(GLuint program, GLuint shader)
-{
- GET_CURRENT_CONTEXT(ctx);
- attach_shader(ctx, program, shader);
-}
-
-
-void GLAPIENTRY
-_mesa_BindAttribLocationARB(GLhandleARB program, GLuint index,
- const GLcharARB *name)
-{
- GET_CURRENT_CONTEXT(ctx);
- bind_attrib_location(ctx, program, index, name);
-}
-
-
-/* GL_EXT_gpu_shader4, GL3 */
-void GLAPIENTRY
-_mesa_BindFragDataLocation(GLuint program, GLuint colorNumber,
- const GLchar *name)
-{
- GET_CURRENT_CONTEXT(ctx);
- bind_frag_data_location(ctx, program, colorNumber, name);
-}
-
-
-void GLAPIENTRY
-_mesa_CompileShaderARB(GLhandleARB shaderObj)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glCompileShader %u\n", shaderObj);
- compile_shader(ctx, shaderObj);
-}
-
-
-GLuint GLAPIENTRY
-_mesa_CreateShader(GLenum type)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glCreateShader %s\n", _mesa_lookup_enum_by_nr(type));
- return create_shader(ctx, type);
-}
-
-
-GLhandleARB GLAPIENTRY
-_mesa_CreateShaderObjectARB(GLenum type)
-{
- GET_CURRENT_CONTEXT(ctx);
- return create_shader(ctx, type);
-}
-
-
-GLuint GLAPIENTRY
-_mesa_CreateProgram(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glCreateProgram\n");
- return create_shader_program(ctx);
-}
-
-
-GLhandleARB GLAPIENTRY
-_mesa_CreateProgramObjectARB(void)
-{
- GET_CURRENT_CONTEXT(ctx);
- return create_shader_program(ctx);
-}
-
-
-void GLAPIENTRY
-_mesa_DeleteObjectARB(GLhandleARB obj)
-{
- if (MESA_VERBOSE & VERBOSE_API) {
- GET_CURRENT_CONTEXT(ctx);
- _mesa_debug(ctx, "glDeleteObjectARB(%u)\n", obj);
- }
-
- if (obj) {
- GET_CURRENT_CONTEXT(ctx);
- if (is_program(ctx, obj)) {
- delete_shader_program(ctx, obj);
- }
- else if (is_shader(ctx, obj)) {
- delete_shader(ctx, obj);
- }
- else {
- /* error? */
- }
- }
-}
-
-
-void GLAPIENTRY
-_mesa_DeleteProgram(GLuint name)
-{
- if (name) {
- GET_CURRENT_CONTEXT(ctx);
- delete_shader_program(ctx, name);
- }
-}
-
-
-void GLAPIENTRY
-_mesa_DeleteShader(GLuint name)
-{
- if (name) {
- GET_CURRENT_CONTEXT(ctx);
- delete_shader(ctx, name);
- }
-}
-
-
-void GLAPIENTRY
-_mesa_DetachObjectARB(GLhandleARB program, GLhandleARB shader)
-{
- GET_CURRENT_CONTEXT(ctx);
- detach_shader(ctx, program, shader);
-}
-
-
-void GLAPIENTRY
-_mesa_DetachShader(GLuint program, GLuint shader)
-{
- GET_CURRENT_CONTEXT(ctx);
- detach_shader(ctx, program, shader);
-}
-
-
-void GLAPIENTRY
-_mesa_GetActiveAttribARB(GLhandleARB program, GLuint index,
- GLsizei maxLength, GLsizei * length, GLint * size,
- GLenum * type, GLcharARB * name)
-{
- GET_CURRENT_CONTEXT(ctx);
- get_active_attrib(ctx, program, index, maxLength, length, size, type, name);
-}
-
-
-void GLAPIENTRY
-_mesa_GetAttachedObjectsARB(GLhandleARB container, GLsizei maxCount,
- GLsizei * count, GLhandleARB * obj)
-{
- GET_CURRENT_CONTEXT(ctx);
- get_attached_shaders(ctx, container, maxCount, count, obj);
-}
-
-
-void GLAPIENTRY
-_mesa_GetAttachedShaders(GLuint program, GLsizei maxCount,
- GLsizei *count, GLuint *obj)
-{
- GET_CURRENT_CONTEXT(ctx);
- get_attached_shaders(ctx, program, maxCount, count, obj);
-}
-
-
-GLint GLAPIENTRY
-_mesa_GetAttribLocationARB(GLhandleARB program, const GLcharARB * name)
-{
- GET_CURRENT_CONTEXT(ctx);
- return get_attrib_location(ctx, program, name);
-}
-
-
-/* GL_EXT_gpu_shader4, GL3 */
-GLint GLAPIENTRY
-_mesa_GetFragDataLocation(GLuint program, const GLchar *name)
-{
- GET_CURRENT_CONTEXT(ctx);
- return get_frag_data_location(ctx, program, name);
-}
-
-
-
-void GLAPIENTRY
-_mesa_GetInfoLogARB(GLhandleARB object, GLsizei maxLength, GLsizei * length,
- GLcharARB * infoLog)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (is_program(ctx, object)) {
- get_program_info_log(ctx, object, maxLength, length, infoLog);
- }
- else if (is_shader(ctx, object)) {
- get_shader_info_log(ctx, object, maxLength, length, infoLog);
- }
- else {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetInfoLogARB");
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetObjectParameterivARB(GLhandleARB object, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- /* Implement in terms of GetProgramiv, GetShaderiv */
- if (is_program(ctx, object)) {
- if (pname == GL_OBJECT_TYPE_ARB) {
- *params = GL_PROGRAM_OBJECT_ARB;
- }
- else {
- get_programiv(ctx, object, pname, params);
- }
- }
- else if (is_shader(ctx, object)) {
- if (pname == GL_OBJECT_TYPE_ARB) {
- *params = GL_SHADER_OBJECT_ARB;
- }
- else {
- get_shaderiv(ctx, object, pname, params);
- }
- }
- else {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGetObjectParameterivARB");
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetObjectParameterfvARB(GLhandleARB object, GLenum pname,
- GLfloat *params)
-{
- GLint iparams[1]; /* XXX is one element enough? */
- _mesa_GetObjectParameterivARB(object, pname, iparams);
- params[0] = (GLfloat) iparams[0];
-}
-
-
-void GLAPIENTRY
-_mesa_GetProgramiv(GLuint program, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- get_programiv(ctx, program, pname, params);
-}
-
-
-void GLAPIENTRY
-_mesa_GetShaderiv(GLuint shader, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- get_shaderiv(ctx, shader, pname, params);
-}
-
-
-void GLAPIENTRY
-_mesa_GetProgramInfoLog(GLuint program, GLsizei bufSize,
- GLsizei *length, GLchar *infoLog)
-{
- GET_CURRENT_CONTEXT(ctx);
- get_program_info_log(ctx, program, bufSize, length, infoLog);
-}
-
-
-void GLAPIENTRY
-_mesa_GetShaderInfoLog(GLuint shader, GLsizei bufSize,
- GLsizei *length, GLchar *infoLog)
-{
- GET_CURRENT_CONTEXT(ctx);
- get_shader_info_log(ctx, shader, bufSize, length, infoLog);
-}
-
-
-void GLAPIENTRY
-_mesa_GetShaderSourceARB(GLhandleARB shader, GLsizei maxLength,
- GLsizei *length, GLcharARB *sourceOut)
-{
- GET_CURRENT_CONTEXT(ctx);
- get_shader_source(ctx, shader, maxLength, length, sourceOut);
-}
-
-
-GLhandleARB GLAPIENTRY
-_mesa_GetHandleARB(GLenum pname)
-{
- GET_CURRENT_CONTEXT(ctx);
- return get_handle(ctx, pname);
-}
-
-
-GLboolean GLAPIENTRY
-_mesa_IsProgram(GLuint name)
-{
- GET_CURRENT_CONTEXT(ctx);
- return is_program(ctx, name);
-}
-
-
-GLboolean GLAPIENTRY
-_mesa_IsShader(GLuint name)
-{
- GET_CURRENT_CONTEXT(ctx);
- return is_shader(ctx, name);
-}
-
-
-void GLAPIENTRY
-_mesa_LinkProgramARB(GLhandleARB programObj)
-{
- GET_CURRENT_CONTEXT(ctx);
- link_program(ctx, programObj);
-}
-
-
-
-/**
- * Read shader source code from a file.
- * Useful for debugging to override an app's shader.
- */
-static GLcharARB *
-read_shader(const char *fname)
-{
- const int max = 50*1000;
- FILE *f = fopen(fname, "r");
- GLcharARB *buffer, *shader;
- int len;
-
- if (!f) {
- return NULL;
- }
-
- buffer = (char *) malloc(max);
- len = fread(buffer, 1, max, f);
- buffer[len] = 0;
-
- fclose(f);
-
- shader = _mesa_strdup(buffer);
- free(buffer);
-
- return shader;
-}
-
-
-/**
- * Called via glShaderSource() and glShaderSourceARB() API functions.
- * Basically, concatenate the source code strings into one long string
- * and pass it to _mesa_shader_source().
- */
-void GLAPIENTRY
-_mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count,
- const GLcharARB ** string, const GLint * length)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint *offsets;
- GLsizei i, totalLength;
- GLcharARB *source;
- GLuint checksum;
-
- if (!shaderObj || string == NULL) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glShaderSourceARB");
- return;
- }
-
- /*
- * This array holds offsets of where the appropriate string ends, thus the
- * last element will be set to the total length of the source code.
- */
- offsets = (GLint *) malloc(count * sizeof(GLint));
- if (offsets == NULL) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
- return;
- }
-
- for (i = 0; i < count; i++) {
- if (string[i] == NULL) {
- free((GLvoid *) offsets);
- _mesa_error(ctx, GL_INVALID_OPERATION, "glShaderSourceARB(null string)");
- return;
- }
- if (length == NULL || length[i] < 0)
- offsets[i] = strlen(string[i]);
- else
- offsets[i] = length[i];
- /* accumulate string lengths */
- if (i > 0)
- offsets[i] += offsets[i - 1];
- }
-
- /* Total length of source string is sum off all strings plus two.
- * One extra byte for terminating zero, another extra byte to silence
- * valgrind warnings in the parser/grammer code.
- */
- totalLength = offsets[count - 1] + 2;
- source = (GLcharARB *) malloc(totalLength * sizeof(GLcharARB));
- if (source == NULL) {
- free((GLvoid *) offsets);
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
- return;
- }
-
- for (i = 0; i < count; i++) {
- GLint start = (i > 0) ? offsets[i - 1] : 0;
- memcpy(source + start, string[i],
- (offsets[i] - start) * sizeof(GLcharARB));
- }
- source[totalLength - 1] = '\0';
- source[totalLength - 2] = '\0';
-
- if (SHADER_SUBST) {
- /* Compute the shader's source code checksum then try to open a file
- * named newshader_<CHECKSUM>. If it exists, use it in place of the
- * original shader source code. For debugging.
- */
- char filename[100];
- GLcharARB *newSource;
-
- checksum = _mesa_str_checksum(source);
-
- _mesa_snprintf(filename, sizeof(filename), "newshader_%d", checksum);
-
- newSource = read_shader(filename);
- if (newSource) {
- fprintf(stderr, "Mesa: Replacing shader %u chksum=%d with %s\n",
- shaderObj, checksum, filename);
- free(source);
- source = newSource;
- }
- }
-
- shader_source(ctx, shaderObj, source);
-
- if (SHADER_SUBST) {
- struct gl_shader *sh = _mesa_lookup_shader(ctx, shaderObj);
- if (sh)
- sh->SourceChecksum = checksum; /* save original checksum */
- }
-
- free(offsets);
-}
-
-
-void GLAPIENTRY
-_mesa_UseProgramObjectARB(GLhandleARB program)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_shader_program *shProg;
- struct gl_transform_feedback_object *obj =
- ctx->TransformFeedback.CurrentObject;
-
- if (obj->Active) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glUseProgram(transform feedback active)");
- return;
- }
-
- if (program) {
- shProg = _mesa_lookup_shader_program_err(ctx, program, "glUseProgram");
- if (!shProg) {
- return;
- }
- if (!shProg->LinkStatus) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glUseProgram(program %u not linked)", program);
- return;
- }
-
- /* debug code */
- if (ctx->Shader.Flags & GLSL_USE_PROG) {
- print_shader_info(shProg);
- }
- }
- else {
- shProg = NULL;
- }
-
- _mesa_use_program(ctx, shProg);
-}
-
-
-void GLAPIENTRY
-_mesa_ValidateProgramARB(GLhandleARB program)
-{
- GET_CURRENT_CONTEXT(ctx);
- validate_program(ctx, program);
-}
-
-#ifdef FEATURE_ES2
-
-void GLAPIENTRY
-_mesa_GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype,
- GLint* range, GLint* precision)
-{
- const struct gl_program_constants *limits;
- const struct gl_precision *p;
- GET_CURRENT_CONTEXT(ctx);
-
- switch (shadertype) {
- case GL_VERTEX_SHADER:
- limits = &ctx->Const.VertexProgram;
- break;
- case GL_FRAGMENT_SHADER:
- limits = &ctx->Const.FragmentProgram;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetShaderPrecisionFormat(shadertype)");
- return;
- }
-
- switch (precisiontype) {
- case GL_LOW_FLOAT:
- p = &limits->LowFloat;
- break;
- case GL_MEDIUM_FLOAT:
- p = &limits->MediumFloat;
- break;
- case GL_HIGH_FLOAT:
- p = &limits->HighFloat;
- break;
- case GL_LOW_INT:
- p = &limits->LowInt;
- break;
- case GL_MEDIUM_INT:
- p = &limits->MediumInt;
- break;
- case GL_HIGH_INT:
- p = &limits->HighInt;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetShaderPrecisionFormat(precisiontype)");
- return;
- }
-
- range[0] = p->RangeMin;
- range[1] = p->RangeMax;
- precision[0] = p->Precision;
-}
-
-
-void GLAPIENTRY
-_mesa_ReleaseShaderCompiler(void)
-{
- _mesa_destroy_shader_compiler_caches();
-}
-
-
-void GLAPIENTRY
-_mesa_ShaderBinary(GLint n, const GLuint* shaders, GLenum binaryformat,
- const void* binary, GLint length)
-{
- GET_CURRENT_CONTEXT(ctx);
- (void) n;
- (void) shaders;
- (void) binaryformat;
- (void) binary;
- (void) length;
- _mesa_error(ctx, GL_INVALID_OPERATION, __FUNCTION__);
-}
-
-#endif /* FEATURE_ES2 */
-
-
-#if FEATURE_ARB_geometry_shader4
-
-void GLAPIENTRY
-_mesa_ProgramParameteriARB(GLuint program, GLenum pname,
- GLint value)
-{
- struct gl_shader_program *shProg;
- GET_CURRENT_CONTEXT(ctx);
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- shProg = _mesa_lookup_shader_program_err(ctx, program,
- "glProgramParameteri");
- if (!shProg)
- return;
-
- switch (pname) {
- case GL_GEOMETRY_VERTICES_OUT_ARB:
- if (value < 1 ||
- (unsigned) value > ctx->Const.GeometryProgram.MaxGeometryOutputVertices) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glProgramParameteri(GL_GEOMETRY_VERTICES_OUT_ARB=%d",
- value);
- return;
- }
- shProg->Geom.VerticesOut = value;
- break;
- case GL_GEOMETRY_INPUT_TYPE_ARB:
- switch (value) {
- case GL_POINTS:
- case GL_LINES:
- case GL_LINES_ADJACENCY_ARB:
- case GL_TRIANGLES:
- case GL_TRIANGLES_ADJACENCY_ARB:
- shProg->Geom.InputType = value;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glProgramParameteri(geometry input type = %s",
- _mesa_lookup_enum_by_nr(value));
- return;
- }
- break;
- case GL_GEOMETRY_OUTPUT_TYPE_ARB:
- switch (value) {
- case GL_POINTS:
- case GL_LINE_STRIP:
- case GL_TRIANGLE_STRIP:
- shProg->Geom.OutputType = value;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glProgramParameteri(geometry output type = %s",
- _mesa_lookup_enum_by_nr(value));
- return;
- }
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameteriARB(pname=%s)",
- _mesa_lookup_enum_by_nr(pname));
- break;
- }
-}
-
-#endif
-
-void
-_mesa_use_shader_program(struct gl_context *ctx, GLenum type,
- struct gl_shader_program *shProg)
-{
- use_shader_program(ctx, type, shProg);
-
- if (ctx->Driver.UseProgram)
- ctx->Driver.UseProgram(ctx, shProg);
-}
-
-void GLAPIENTRY
-_mesa_UseShaderProgramEXT(GLenum type, GLuint program)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_shader_program *shProg = NULL;
-
- if (!validate_shader_target(ctx, type)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glUseShaderProgramEXT(type)");
- return;
- }
-
- if (ctx->TransformFeedback.CurrentObject->Active) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glUseShaderProgramEXT(transform feedback is active)");
- return;
- }
-
- if (program) {
- shProg = _mesa_lookup_shader_program_err(ctx, program,
- "glUseShaderProgramEXT");
- if (shProg == NULL)
- return;
-
- if (!shProg->LinkStatus) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glUseShaderProgramEXT(program not linked)");
- return;
- }
- }
-
- _mesa_use_shader_program(ctx, type, shProg);
-}
-
-void GLAPIENTRY
-_mesa_ActiveProgramEXT(GLuint program)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_shader_program *shProg = (program != 0)
- ? _mesa_lookup_shader_program_err(ctx, program, "glActiveProgramEXT")
- : NULL;
-
- _mesa_active_program(ctx, shProg, "glActiveProgramEXT");
- return;
-}
-
-GLuint GLAPIENTRY
-_mesa_CreateShaderProgramEXT(GLenum type, const GLchar *string)
-{
- GET_CURRENT_CONTEXT(ctx);
- const GLuint shader = create_shader(ctx, type);
- GLuint program = 0;
-
- if (shader) {
- shader_source(ctx, shader, _mesa_strdup(string));
- compile_shader(ctx, shader);
-
- program = create_shader_program(ctx);
- if (program) {
- struct gl_shader_program *shProg;
- struct gl_shader *sh;
- GLint compiled = GL_FALSE;
-
- shProg = _mesa_lookup_shader_program(ctx, program);
- sh = _mesa_lookup_shader(ctx, shader);
-
- get_shaderiv(ctx, shader, GL_COMPILE_STATUS, &compiled);
- if (compiled) {
- attach_shader(ctx, program, shader);
- link_program(ctx, program);
- detach_shader(ctx, program, shader);
-
-#if 0
- /* Possibly... */
- if (active-user-defined-varyings-in-linked-program) {
- append-error-to-info-log;
- shProg->LinkStatus = GL_FALSE;
- }
-#endif
- }
-
- ralloc_strcat(&shProg->InfoLog, sh->InfoLog);
- }
-
- delete_shader(ctx, shader);
- }
-
- return program;
-}
-
-/**
- * Plug in shader-related functions into API dispatch table.
- */
-void
-_mesa_init_shader_dispatch(struct _glapi_table *exec)
-{
-#if FEATURE_GL
- /* GL_ARB_vertex/fragment_shader */
- SET_DeleteObjectARB(exec, _mesa_DeleteObjectARB);
- SET_GetHandleARB(exec, _mesa_GetHandleARB);
- SET_DetachObjectARB(exec, _mesa_DetachObjectARB);
- SET_CreateShaderObjectARB(exec, _mesa_CreateShaderObjectARB);
- SET_ShaderSourceARB(exec, _mesa_ShaderSourceARB);
- SET_CompileShaderARB(exec, _mesa_CompileShaderARB);
- SET_CreateProgramObjectARB(exec, _mesa_CreateProgramObjectARB);
- SET_AttachObjectARB(exec, _mesa_AttachObjectARB);
- SET_LinkProgramARB(exec, _mesa_LinkProgramARB);
- SET_UseProgramObjectARB(exec, _mesa_UseProgramObjectARB);
- SET_ValidateProgramARB(exec, _mesa_ValidateProgramARB);
- SET_GetObjectParameterfvARB(exec, _mesa_GetObjectParameterfvARB);
- SET_GetObjectParameterivARB(exec, _mesa_GetObjectParameterivARB);
- SET_GetInfoLogARB(exec, _mesa_GetInfoLogARB);
- SET_GetAttachedObjectsARB(exec, _mesa_GetAttachedObjectsARB);
- SET_GetShaderSourceARB(exec, _mesa_GetShaderSourceARB);
-
- /* OpenGL 2.0 */
- SET_AttachShader(exec, _mesa_AttachShader);
- SET_CreateProgram(exec, _mesa_CreateProgram);
- SET_CreateShader(exec, _mesa_CreateShader);
- SET_DeleteProgram(exec, _mesa_DeleteProgram);
- SET_DeleteShader(exec, _mesa_DeleteShader);
- SET_DetachShader(exec, _mesa_DetachShader);
- SET_GetAttachedShaders(exec, _mesa_GetAttachedShaders);
- SET_GetProgramiv(exec, _mesa_GetProgramiv);
- SET_GetProgramInfoLog(exec, _mesa_GetProgramInfoLog);
- SET_GetShaderiv(exec, _mesa_GetShaderiv);
- SET_GetShaderInfoLog(exec, _mesa_GetShaderInfoLog);
- SET_IsProgram(exec, _mesa_IsProgram);
- SET_IsShader(exec, _mesa_IsShader);
-
-#if FEATURE_ARB_vertex_shader
- SET_BindAttribLocationARB(exec, _mesa_BindAttribLocationARB);
- SET_GetActiveAttribARB(exec, _mesa_GetActiveAttribARB);
- SET_GetAttribLocationARB(exec, _mesa_GetAttribLocationARB);
-#endif
-
-#if FEATURE_ARB_geometry_shader4
- SET_ProgramParameteriARB(exec, _mesa_ProgramParameteriARB);
-#endif
-
- SET_UseShaderProgramEXT(exec, _mesa_UseShaderProgramEXT);
- SET_ActiveProgramEXT(exec, _mesa_ActiveProgramEXT);
- SET_CreateShaderProgramEXT(exec, _mesa_CreateShaderProgramEXT);
-
- /* GL_EXT_gpu_shader4 / GL 3.0 */
- SET_BindFragDataLocationEXT(exec, _mesa_BindFragDataLocation);
- SET_GetFragDataLocationEXT(exec, _mesa_GetFragDataLocation);
-
- /* GL_ARB_ES2_compatibility */
- SET_ReleaseShaderCompiler(exec, _mesa_ReleaseShaderCompiler);
- SET_GetShaderPrecisionFormat(exec, _mesa_GetShaderPrecisionFormat);
-
-#endif /* FEATURE_GL */
-}
-
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009-2010 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file shaderapi.c
+ * \author Brian Paul
+ *
+ * Implementation of GLSL-related API functions.
+ * The glUniform* functions are in uniforms.c
+ *
+ *
+ * XXX things to do:
+ * 1. Check that the right error code is generated for all _mesa_error() calls.
+ * 2. Insert FLUSH_VERTICES calls in various places
+ */
+
+
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/dispatch.h"
+#include "main/enums.h"
+#include "main/hash.h"
+#include "main/mfeatures.h"
+#include "main/mtypes.h"
+#include "main/shaderapi.h"
+#include "main/shaderobj.h"
+#include "program/program.h"
+#include "program/prog_parameter.h"
+#include "program/prog_uniform.h"
+#include "ralloc.h"
+#include <stdbool.h>
+#include "../glsl/glsl_parser_extras.h"
+
+/** Define this to enable shader substitution (see below) */
+#define SHADER_SUBST 0
+
+
+/**
+ * Return mask of GLSL_x flags by examining the MESA_GLSL env var.
+ */
+static GLbitfield
+get_shader_flags(void)
+{
+ GLbitfield flags = 0x0;
+ const char *env = _mesa_getenv("MESA_GLSL");
+
+ if (env) {
+ if (strstr(env, "dump"))
+ flags |= GLSL_DUMP;
+ if (strstr(env, "log"))
+ flags |= GLSL_LOG;
+ if (strstr(env, "nopvert"))
+ flags |= GLSL_NOP_VERT;
+ if (strstr(env, "nopfrag"))
+ flags |= GLSL_NOP_FRAG;
+ if (strstr(env, "nopt"))
+ flags |= GLSL_NO_OPT;
+ else if (strstr(env, "opt"))
+ flags |= GLSL_OPT;
+ if (strstr(env, "uniform"))
+ flags |= GLSL_UNIFORMS;
+ if (strstr(env, "useprog"))
+ flags |= GLSL_USE_PROG;
+ }
+
+ return flags;
+}
+
+
+/**
+ * Initialize context's shader state.
+ */
+void
+_mesa_init_shader_state(struct gl_context *ctx)
+{
+ /* Device drivers may override these to control what kind of instructions
+ * are generated by the GLSL compiler.
+ */
+ struct gl_shader_compiler_options options;
+ gl_shader_type sh;
+
+ memset(&options, 0, sizeof(options));
+ options.MaxUnrollIterations = 32;
+
+ /* Default pragma settings */
+ options.DefaultPragmas.Optimize = GL_TRUE;
+
+ for (sh = 0; sh < MESA_SHADER_TYPES; ++sh)
+ memcpy(&ctx->ShaderCompilerOptions[sh], &options, sizeof(options));
+
+ ctx->Shader.Flags = get_shader_flags();
+}
+
+
+/**
+ * Free the per-context shader-related state.
+ */
+void
+_mesa_free_shader_state(struct gl_context *ctx)
+{
+ _mesa_reference_shader_program(ctx, &ctx->Shader.CurrentVertexProgram, NULL);
+ _mesa_reference_shader_program(ctx, &ctx->Shader.CurrentGeometryProgram,
+ NULL);
+ _mesa_reference_shader_program(ctx, &ctx->Shader.CurrentFragmentProgram,
+ NULL);
+ _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, NULL);
+}
+
+
+/**
+ * Return the size of the given GLSL datatype, in floats (components).
+ */
+GLint
+_mesa_sizeof_glsl_type(GLenum type)
+{
+ switch (type) {
+ case GL_FLOAT:
+ case GL_INT:
+ case GL_BOOL:
+ case GL_SAMPLER_1D:
+ case GL_SAMPLER_2D:
+ case GL_SAMPLER_3D:
+ case GL_SAMPLER_CUBE:
+ case GL_SAMPLER_1D_SHADOW:
+ case GL_SAMPLER_2D_SHADOW:
+ case GL_SAMPLER_2D_RECT_ARB:
+ case GL_SAMPLER_2D_RECT_SHADOW_ARB:
+ case GL_SAMPLER_1D_ARRAY_EXT:
+ case GL_SAMPLER_2D_ARRAY_EXT:
+ case GL_SAMPLER_1D_ARRAY_SHADOW_EXT:
+ case GL_SAMPLER_2D_ARRAY_SHADOW_EXT:
+ case GL_SAMPLER_CUBE_SHADOW_EXT:
+ return 1;
+ case GL_FLOAT_VEC2:
+ case GL_INT_VEC2:
+ case GL_UNSIGNED_INT_VEC2:
+ case GL_BOOL_VEC2:
+ return 2;
+ case GL_FLOAT_VEC3:
+ case GL_INT_VEC3:
+ case GL_UNSIGNED_INT_VEC3:
+ case GL_BOOL_VEC3:
+ return 3;
+ case GL_FLOAT_VEC4:
+ case GL_INT_VEC4:
+ case GL_UNSIGNED_INT_VEC4:
+ case GL_BOOL_VEC4:
+ return 4;
+ case GL_FLOAT_MAT2:
+ case GL_FLOAT_MAT2x3:
+ case GL_FLOAT_MAT2x4:
+ return 8; /* two float[4] vectors */
+ case GL_FLOAT_MAT3:
+ case GL_FLOAT_MAT3x2:
+ case GL_FLOAT_MAT3x4:
+ return 12; /* three float[4] vectors */
+ case GL_FLOAT_MAT4:
+ case GL_FLOAT_MAT4x2:
+ case GL_FLOAT_MAT4x3:
+ return 16; /* four float[4] vectors */
+ default:
+ _mesa_problem(NULL, "Invalid type in _mesa_sizeof_glsl_type()");
+ return 1;
+ }
+}
+
+
+/**
+ * Copy string from <src> to <dst>, up to maxLength characters, returning
+ * length of <dst> in <length>.
+ * \param src the strings source
+ * \param maxLength max chars to copy
+ * \param length returns number of chars copied
+ * \param dst the string destination
+ */
+void
+_mesa_copy_string(GLchar *dst, GLsizei maxLength,
+ GLsizei *length, const GLchar *src)
+{
+ GLsizei len;
+ for (len = 0; len < maxLength - 1 && src && src[len]; len++)
+ dst[len] = src[len];
+ if (maxLength > 0)
+ dst[len] = 0;
+ if (length)
+ *length = len;
+}
+
+
+
+/**
+ * Confirm that the a shader type is valid and supported by the implementation
+ *
+ * \param ctx Current GL context
+ * \param type Shader target
+ *
+ */
+static bool
+validate_shader_target(const struct gl_context *ctx, GLenum type)
+{
+ switch (type) {
+#if FEATURE_ARB_fragment_shader
+ case GL_FRAGMENT_SHADER:
+ return ctx->Extensions.ARB_fragment_shader;
+#endif
+#if FEATURE_ARB_vertex_shader
+ case GL_VERTEX_SHADER:
+ return ctx->Extensions.ARB_vertex_shader;
+#endif
+#if FEATURE_ARB_geometry_shader4
+ case GL_GEOMETRY_SHADER_ARB:
+ return ctx->Extensions.ARB_geometry_shader4;
+#endif
+ default:
+ return false;
+ }
+}
+
+
+/**
+ * Find the length of the longest transform feedback varying name
+ * which was specified with glTransformFeedbackVaryings().
+ */
+static GLint
+longest_feedback_varying_name(const struct gl_shader_program *shProg)
+{
+ GLuint i;
+ GLint max = 0;
+ for (i = 0; i < shProg->TransformFeedback.NumVarying; i++) {
+ GLint len = strlen(shProg->TransformFeedback.VaryingNames[i]);
+ if (len > max)
+ max = len;
+ }
+ return max;
+}
+
+
+
+static GLboolean
+is_program(struct gl_context *ctx, GLuint name)
+{
+ struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, name);
+ return shProg ? GL_TRUE : GL_FALSE;
+}
+
+
+static GLboolean
+is_shader(struct gl_context *ctx, GLuint name)
+{
+ struct gl_shader *shader = _mesa_lookup_shader(ctx, name);
+ return shader ? GL_TRUE : GL_FALSE;
+}
+
+
+/**
+ * Attach shader to a shader program.
+ */
+static void
+attach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
+{
+ struct gl_shader_program *shProg;
+ struct gl_shader *sh;
+ GLuint i, n;
+
+ shProg = _mesa_lookup_shader_program_err(ctx, program, "glAttachShader");
+ if (!shProg)
+ return;
+
+ sh = _mesa_lookup_shader_err(ctx, shader, "glAttachShader");
+ if (!sh) {
+ return;
+ }
+
+ n = shProg->NumShaders;
+ for (i = 0; i < n; i++) {
+ if (shProg->Shaders[i] == sh) {
+ /* The shader is already attched to this program. The
+ * GL_ARB_shader_objects spec says:
+ *
+ * "The error INVALID_OPERATION is generated by AttachObjectARB
+ * if <obj> is already attached to <containerObj>."
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glAttachShader");
+ return;
+ }
+ }
+
+ /* grow list */
+ shProg->Shaders = (struct gl_shader **)
+ _mesa_realloc(shProg->Shaders,
+ n * sizeof(struct gl_shader *),
+ (n + 1) * sizeof(struct gl_shader *));
+ if (!shProg->Shaders) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAttachShader");
+ return;
+ }
+
+ /* append */
+ shProg->Shaders[n] = NULL; /* since realloc() didn't zero the new space */
+ _mesa_reference_shader(ctx, &shProg->Shaders[n], sh);
+ shProg->NumShaders++;
+}
+
+
+static GLint
+get_attrib_location(struct gl_context *ctx, GLuint program, const GLchar *name)
+{
+ struct gl_shader_program *shProg
+ = _mesa_lookup_shader_program_err(ctx, program, "glGetAttribLocation");
+
+ if (!shProg) {
+ return -1;
+ }
+
+ if (!shProg->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetAttribLocation(program not linked)");
+ return -1;
+ }
+
+ if (!name)
+ return -1;
+
+ if (shProg->VertexProgram) {
+ const struct gl_program_parameter_list *attribs =
+ shProg->VertexProgram->Base.Attributes;
+ if (attribs) {
+ GLint i = _mesa_lookup_parameter_index(attribs, -1, name);
+ if (i >= 0) {
+ return attribs->Parameters[i].StateIndexes[0];
+ }
+ }
+ }
+ return -1;
+}
+
+
+static void
+bind_attrib_location(struct gl_context *ctx, GLuint program, GLuint index,
+ const GLchar *name)
+{
+ struct gl_shader_program *shProg;
+ const GLint size = -1; /* unknown size */
+ GLint i, oldIndex;
+ GLenum datatype = GL_FLOAT_VEC4;
+
+ shProg = _mesa_lookup_shader_program_err(ctx, program,
+ "glBindAttribLocation");
+ if (!shProg) {
+ return;
+ }
+
+ if (!name)
+ return;
+
+ if (strncmp(name, "gl_", 3) == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBindAttribLocation(illegal name)");
+ return;
+ }
+
+ if (index >= ctx->Const.VertexProgram.MaxAttribs) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindAttribLocation(index)");
+ return;
+ }
+
+ if (shProg->LinkStatus) {
+ /* get current index/location for the attribute */
+ oldIndex = get_attrib_location(ctx, program, name);
+ }
+ else {
+ oldIndex = -1;
+ }
+
+ /* this will replace the current value if it's already in the list */
+ i = _mesa_add_attribute(shProg->Attributes, name, size, datatype, index);
+ if (i < 0) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindAttribLocation");
+ return;
+ }
+
+ /*
+ * Note that this attribute binding won't go into effect until
+ * glLinkProgram is called again.
+ */
+}
+
+
+static void
+bind_frag_data_location(struct gl_context *ctx, GLuint program,
+ GLuint colorNumber, const GLchar *name)
+{
+ _mesa_problem(ctx, "bind_frag_data_location() not implemented yet");
+}
+
+
+static GLuint
+create_shader(struct gl_context *ctx, GLenum type)
+{
+ struct gl_shader *sh;
+ GLuint name;
+
+ if (!validate_shader_target(ctx, type)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "CreateShader(type)");
+ return 0;
+ }
+
+ name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
+ sh = ctx->Driver.NewShader(ctx, name, type);
+ _mesa_HashInsert(ctx->Shared->ShaderObjects, name, sh);
+
+ return name;
+}
+
+
+static GLuint
+create_shader_program(struct gl_context *ctx)
+{
+ GLuint name;
+ struct gl_shader_program *shProg;
+
+ name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
+
+ shProg = ctx->Driver.NewShaderProgram(ctx, name);
+
+ _mesa_HashInsert(ctx->Shared->ShaderObjects, name, shProg);
+
+ assert(shProg->RefCount == 1);
+
+ return name;
+}
+
+
+/**
+ * Named w/ "2" to indicate OpenGL 2.x vs GL_ARB_fragment_programs's
+ * DeleteProgramARB.
+ */
+static void
+delete_shader_program(struct gl_context *ctx, GLuint name)
+{
+ /*
+ * NOTE: deleting shaders/programs works a bit differently than
+ * texture objects (and buffer objects, etc). Shader/program
+ * handles/IDs exist in the hash table until the object is really
+ * deleted (refcount==0). With texture objects, the handle/ID is
+ * removed from the hash table in glDeleteTextures() while the tex
+ * object itself might linger until its refcount goes to zero.
+ */
+ struct gl_shader_program *shProg;
+
+ shProg = _mesa_lookup_shader_program_err(ctx, name, "glDeleteProgram");
+ if (!shProg)
+ return;
+
+ shProg->DeletePending = GL_TRUE;
+
+ /* effectively, decr shProg's refcount */
+ _mesa_reference_shader_program(ctx, &shProg, NULL);
+}
+
+
+static void
+delete_shader(struct gl_context *ctx, GLuint shader)
+{
+ struct gl_shader *sh;
+
+ sh = _mesa_lookup_shader_err(ctx, shader, "glDeleteShader");
+ if (!sh)
+ return;
+
+ sh->DeletePending = GL_TRUE;
+
+ /* effectively, decr sh's refcount */
+ _mesa_reference_shader(ctx, &sh, NULL);
+}
+
+
+static void
+detach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
+{
+ struct gl_shader_program *shProg;
+ GLuint n;
+ GLuint i, j;
+
+ shProg = _mesa_lookup_shader_program_err(ctx, program, "glDetachShader");
+ if (!shProg)
+ return;
+
+ n = shProg->NumShaders;
+
+ for (i = 0; i < n; i++) {
+ if (shProg->Shaders[i]->Name == shader) {
+ /* found it */
+ struct gl_shader **newList;
+
+ /* release */
+ _mesa_reference_shader(ctx, &shProg->Shaders[i], NULL);
+
+ /* alloc new, smaller array */
+ newList = (struct gl_shader **)
+ malloc((n - 1) * sizeof(struct gl_shader *));
+ if (!newList) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDetachShader");
+ return;
+ }
+ for (j = 0; j < i; j++) {
+ newList[j] = shProg->Shaders[j];
+ }
+ while (++i < n)
+ newList[j++] = shProg->Shaders[i];
+ free(shProg->Shaders);
+
+ shProg->Shaders = newList;
+ shProg->NumShaders = n - 1;
+
+#ifdef DEBUG
+ /* sanity check */
+ {
+ for (j = 0; j < shProg->NumShaders; j++) {
+ assert(shProg->Shaders[j]->Type == GL_VERTEX_SHADER ||
+ shProg->Shaders[j]->Type == GL_FRAGMENT_SHADER);
+ assert(shProg->Shaders[j]->RefCount > 0);
+ }
+ }
+#endif
+
+ return;
+ }
+ }
+
+ /* not found */
+ {
+ GLenum err;
+ if (is_shader(ctx, shader))
+ err = GL_INVALID_OPERATION;
+ else if (is_program(ctx, shader))
+ err = GL_INVALID_OPERATION;
+ else
+ err = GL_INVALID_VALUE;
+ _mesa_error(ctx, err, "glDetachProgram(shader)");
+ return;
+ }
+}
+
+
+static void
+get_active_attrib(struct gl_context *ctx, GLuint program, GLuint index,
+ GLsizei maxLength, GLsizei *length, GLint *size,
+ GLenum *type, GLchar *nameOut)
+{
+ const struct gl_program_parameter_list *attribs = NULL;
+ struct gl_shader_program *shProg;
+
+ shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveAttrib");
+ if (!shProg)
+ return;
+
+ if (shProg->VertexProgram)
+ attribs = shProg->VertexProgram->Base.Attributes;
+
+ if (!attribs || index >= attribs->NumParameters) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveAttrib(index)");
+ return;
+ }
+
+ _mesa_copy_string(nameOut, maxLength, length,
+ attribs->Parameters[index].Name);
+
+ if (size)
+ *size = attribs->Parameters[index].Size
+ / _mesa_sizeof_glsl_type(attribs->Parameters[index].DataType);
+
+ if (type)
+ *type = attribs->Parameters[index].DataType;
+}
+
+
+/**
+ * Return list of shaders attached to shader program.
+ */
+static void
+get_attached_shaders(struct gl_context *ctx, GLuint program, GLsizei maxCount,
+ GLsizei *count, GLuint *obj)
+{
+ struct gl_shader_program *shProg =
+ _mesa_lookup_shader_program_err(ctx, program, "glGetAttachedShaders");
+ if (shProg) {
+ GLuint i;
+ for (i = 0; i < (GLuint) maxCount && i < shProg->NumShaders; i++) {
+ obj[i] = shProg->Shaders[i]->Name;
+ }
+ if (count)
+ *count = i;
+ }
+}
+
+
+static GLint
+get_frag_data_location(struct gl_context *ctx, GLuint program,
+ const GLchar *name)
+{
+ _mesa_problem(ctx, "get_frag_data_location() not implemented yet");
+ return -1;
+}
+
+
+
+/**
+ * glGetHandleARB() - return ID/name of currently bound shader program.
+ */
+static GLuint
+get_handle(struct gl_context *ctx, GLenum pname)
+{
+ if (pname == GL_PROGRAM_OBJECT_ARB) {
+ if (ctx->Shader.ActiveProgram)
+ return ctx->Shader.ActiveProgram->Name;
+ else
+ return 0;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetHandleARB");
+ return 0;
+ }
+}
+
+
+/**
+ * glGetProgramiv() - get shader program state.
+ * Note that this is for GLSL shader programs, not ARB vertex/fragment
+ * programs (see glGetProgramivARB).
+ */
+static void
+get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, GLint *params)
+{
+ const struct gl_program_parameter_list *attribs;
+ struct gl_shader_program *shProg
+ = _mesa_lookup_shader_program(ctx, program);
+
+ if (!shProg) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramiv(program)");
+ return;
+ }
+
+ if (shProg->VertexProgram)
+ attribs = shProg->VertexProgram->Base.Attributes;
+ else
+ attribs = NULL;
+
+ switch (pname) {
+ case GL_DELETE_STATUS:
+ *params = shProg->DeletePending;
+ break;
+ case GL_LINK_STATUS:
+ *params = shProg->LinkStatus;
+ break;
+ case GL_VALIDATE_STATUS:
+ *params = shProg->Validated;
+ break;
+ case GL_INFO_LOG_LENGTH:
+ *params = shProg->InfoLog ? strlen(shProg->InfoLog) + 1 : 0;
+ break;
+ case GL_ATTACHED_SHADERS:
+ *params = shProg->NumShaders;
+ break;
+ case GL_ACTIVE_ATTRIBUTES:
+ *params = attribs ? attribs->NumParameters : 0;
+ break;
+ case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
+ *params = _mesa_longest_parameter_name(attribs, PROGRAM_INPUT) + 1;
+ break;
+ case GL_ACTIVE_UNIFORMS:
+ *params = shProg->Uniforms ? shProg->Uniforms->NumUniforms : 0;
+ break;
+ case GL_ACTIVE_UNIFORM_MAX_LENGTH:
+ *params = _mesa_longest_uniform_name(shProg->Uniforms);
+ if (*params > 0)
+ (*params)++; /* add one for terminating zero */
+ break;
+ case GL_PROGRAM_BINARY_LENGTH_OES:
+ *params = 0;
+ break;
+#if FEATURE_EXT_transform_feedback
+ case GL_TRANSFORM_FEEDBACK_VARYINGS:
+ *params = shProg->TransformFeedback.NumVarying;
+ break;
+ case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
+ *params = longest_feedback_varying_name(shProg) + 1;
+ break;
+ case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
+ *params = shProg->TransformFeedback.BufferMode;
+ break;
+#endif
+#if FEATURE_ARB_geometry_shader4
+ case GL_GEOMETRY_VERTICES_OUT_ARB:
+ *params = shProg->Geom.VerticesOut;
+ break;
+ case GL_GEOMETRY_INPUT_TYPE_ARB:
+ *params = shProg->Geom.InputType;
+ break;
+ case GL_GEOMETRY_OUTPUT_TYPE_ARB:
+ *params = shProg->Geom.OutputType;
+ break;
+#endif
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramiv(pname)");
+ return;
+ }
+}
+
+
+/**
+ * glGetShaderiv() - get GLSL shader state
+ */
+static void
+get_shaderiv(struct gl_context *ctx, GLuint name, GLenum pname, GLint *params)
+{
+ struct gl_shader *shader =
+ _mesa_lookup_shader_err(ctx, name, "glGetShaderiv");
+
+ if (!shader) {
+ return;
+ }
+
+ switch (pname) {
+ case GL_SHADER_TYPE:
+ *params = shader->Type;
+ break;
+ case GL_DELETE_STATUS:
+ *params = shader->DeletePending;
+ break;
+ case GL_COMPILE_STATUS:
+ *params = shader->CompileStatus;
+ break;
+ case GL_INFO_LOG_LENGTH:
+ *params = shader->InfoLog ? strlen(shader->InfoLog) + 1 : 0;
+ break;
+ case GL_SHADER_SOURCE_LENGTH:
+ *params = shader->Source ? strlen((char *) shader->Source) + 1 : 0;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetShaderiv(pname)");
+ return;
+ }
+}
+
+
+static void
+get_program_info_log(struct gl_context *ctx, GLuint program, GLsizei bufSize,
+ GLsizei *length, GLchar *infoLog)
+{
+ struct gl_shader_program *shProg
+ = _mesa_lookup_shader_program(ctx, program);
+ if (!shProg) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramInfoLog(program)");
+ return;
+ }
+ _mesa_copy_string(infoLog, bufSize, length, shProg->InfoLog);
+}
+
+
+static void
+get_shader_info_log(struct gl_context *ctx, GLuint shader, GLsizei bufSize,
+ GLsizei *length, GLchar *infoLog)
+{
+ struct gl_shader *sh = _mesa_lookup_shader(ctx, shader);
+ if (!sh) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetShaderInfoLog(shader)");
+ return;
+ }
+ _mesa_copy_string(infoLog, bufSize, length, sh->InfoLog);
+}
+
+
+/**
+ * Return shader source code.
+ */
+static void
+get_shader_source(struct gl_context *ctx, GLuint shader, GLsizei maxLength,
+ GLsizei *length, GLchar *sourceOut)
+{
+ struct gl_shader *sh;
+ sh = _mesa_lookup_shader_err(ctx, shader, "glGetShaderSource");
+ if (!sh) {
+ return;
+ }
+ _mesa_copy_string(sourceOut, maxLength, length, sh->Source);
+}
+
+
+/**
+ * Set/replace shader source code.
+ */
+static void
+shader_source(struct gl_context *ctx, GLuint shader, const GLchar *source)
+{
+ struct gl_shader *sh;
+
+ sh = _mesa_lookup_shader_err(ctx, shader, "glShaderSource");
+ if (!sh)
+ return;
+
+ /* free old shader source string and install new one */
+ if (sh->Source) {
+ free((void *) sh->Source);
+ }
+ sh->Source = source;
+ sh->CompileStatus = GL_FALSE;
+#ifdef DEBUG
+ sh->SourceChecksum = _mesa_str_checksum(sh->Source);
+#endif
+}
+
+
+/**
+ * Compile a shader.
+ */
+static void
+compile_shader(struct gl_context *ctx, GLuint shaderObj)
+{
+ struct gl_shader *sh;
+ struct gl_shader_compiler_options *options;
+
+ sh = _mesa_lookup_shader_err(ctx, shaderObj, "glCompileShader");
+ if (!sh)
+ return;
+
+ options = &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(sh->Type)];
+
+ /* set default pragma state for shader */
+ sh->Pragmas = options->DefaultPragmas;
+
+ /* this call will set the sh->CompileStatus field to indicate if
+ * compilation was successful.
+ */
+ _mesa_glsl_compile_shader(ctx, sh);
+}
+
+
+/**
+ * Link a program's shaders.
+ */
+static void
+link_program(struct gl_context *ctx, GLuint program)
+{
+ struct gl_shader_program *shProg;
+ struct gl_transform_feedback_object *obj =
+ ctx->TransformFeedback.CurrentObject;
+
+ shProg = _mesa_lookup_shader_program_err(ctx, program, "glLinkProgram");
+ if (!shProg)
+ return;
+
+ if (obj->Active
+ && (shProg == ctx->Shader.CurrentVertexProgram
+ || shProg == ctx->Shader.CurrentGeometryProgram
+ || shProg == ctx->Shader.CurrentFragmentProgram)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glLinkProgram(transform feedback active");
+ return;
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+
+ _mesa_glsl_link_shader(ctx, shProg);
+
+ /* debug code */
+ if (0) {
+ GLuint i;
+
+ printf("Link %u shaders in program %u: %s\n",
+ shProg->NumShaders, shProg->Name,
+ shProg->LinkStatus ? "Success" : "Failed");
+
+ for (i = 0; i < shProg->NumShaders; i++) {
+ printf(" shader %u, type 0x%x\n",
+ shProg->Shaders[i]->Name,
+ shProg->Shaders[i]->Type);
+ }
+ }
+}
+
+
+/**
+ * Print basic shader info (for debug).
+ */
+static void
+print_shader_info(const struct gl_shader_program *shProg)
+{
+ GLuint i;
+
+ printf("Mesa: glUseProgram(%u)\n", shProg->Name);
+ for (i = 0; i < shProg->NumShaders; i++) {
+ const char *s;
+ switch (shProg->Shaders[i]->Type) {
+ case GL_VERTEX_SHADER:
+ s = "vertex";
+ break;
+ case GL_FRAGMENT_SHADER:
+ s = "fragment";
+ break;
+ case GL_GEOMETRY_SHADER:
+ s = "geometry";
+ break;
+ default:
+ s = "";
+ }
+ printf(" %s shader %u, checksum %u\n", s,
+ shProg->Shaders[i]->Name,
+ shProg->Shaders[i]->SourceChecksum);
+ }
+ if (shProg->VertexProgram)
+ printf(" vert prog %u\n", shProg->VertexProgram->Base.Id);
+ if (shProg->FragmentProgram)
+ printf(" frag prog %u\n", shProg->FragmentProgram->Base.Id);
+}
+
+
+/**
+ * Use the named shader program for subsequent glUniform calls
+ */
+void
+_mesa_active_program(struct gl_context *ctx, struct gl_shader_program *shProg,
+ const char *caller)
+{
+ if ((shProg != NULL) && !shProg->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(program %u not linked)", caller, shProg->Name);
+ return;
+ }
+
+ if (ctx->Shader.ActiveProgram != shProg) {
+ _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, shProg);
+ }
+}
+
+/**
+ */
+static bool
+use_shader_program(struct gl_context *ctx, GLenum type,
+ struct gl_shader_program *shProg)
+{
+ struct gl_shader_program **target;
+
+ switch (type) {
+#if FEATURE_ARB_vertex_shader
+ case GL_VERTEX_SHADER:
+ target = &ctx->Shader.CurrentVertexProgram;
+ if ((shProg == NULL)
+ || (shProg->_LinkedShaders[MESA_SHADER_VERTEX] == NULL)) {
+ shProg = NULL;
+ }
+ break;
+#endif
+#if FEATURE_ARB_geometry_shader4
+ case GL_GEOMETRY_SHADER_ARB:
+ target = &ctx->Shader.CurrentGeometryProgram;
+ if ((shProg == NULL)
+ || (shProg->_LinkedShaders[MESA_SHADER_GEOMETRY] == NULL)) {
+ shProg = NULL;
+ }
+ break;
+#endif
+#if FEATURE_ARB_fragment_shader
+ case GL_FRAGMENT_SHADER:
+ target = &ctx->Shader.CurrentFragmentProgram;
+ if ((shProg == NULL)
+ || (shProg->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL)) {
+ shProg = NULL;
+ }
+ break;
+#endif
+ default:
+ return false;
+ }
+
+ if (*target != shProg) {
+ FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS);
+ _mesa_reference_shader_program(ctx, target, shProg);
+ return true;
+ }
+
+ return false;
+}
+
+/**
+ * Use the named shader program for subsequent rendering.
+ */
+void
+_mesa_use_program(struct gl_context *ctx, struct gl_shader_program *shProg)
+{
+ use_shader_program(ctx, GL_VERTEX_SHADER, shProg);
+ use_shader_program(ctx, GL_GEOMETRY_SHADER_ARB, shProg);
+ use_shader_program(ctx, GL_FRAGMENT_SHADER, shProg);
+ _mesa_active_program(ctx, shProg, "glUseProgram");
+
+ if (ctx->Driver.UseProgram)
+ ctx->Driver.UseProgram(ctx, shProg);
+}
+
+
+/**
+ * Validate a program's samplers.
+ * Specifically, check that there aren't two samplers of different types
+ * pointing to the same texture unit.
+ * \return GL_TRUE if valid, GL_FALSE if invalid
+ */
+static GLboolean
+validate_samplers(const struct gl_program *prog, char *errMsg)
+{
+ static const char *targetName[] = {
+ "TEXTURE_2D_ARRAY",
+ "TEXTURE_1D_ARRAY",
+ "TEXTURE_CUBE",
+ "TEXTURE_3D",
+ "TEXTURE_RECT",
+ "TEXTURE_2D",
+ "TEXTURE_1D",
+ };
+ GLint targetUsed[MAX_TEXTURE_IMAGE_UNITS];
+ GLbitfield samplersUsed = prog->SamplersUsed;
+ GLuint i;
+
+ assert(Elements(targetName) == NUM_TEXTURE_TARGETS);
+
+ if (samplersUsed == 0x0)
+ return GL_TRUE;
+
+ for (i = 0; i < Elements(targetUsed); i++)
+ targetUsed[i] = -1;
+
+ /* walk over bits which are set in 'samplers' */
+ while (samplersUsed) {
+ GLuint unit;
+ gl_texture_index target;
+ GLint sampler = _mesa_ffs(samplersUsed) - 1;
+ assert(sampler >= 0);
+ assert(sampler < MAX_TEXTURE_IMAGE_UNITS);
+ unit = prog->SamplerUnits[sampler];
+ target = prog->SamplerTargets[sampler];
+ if (targetUsed[unit] != -1 && targetUsed[unit] != (int) target) {
+ _mesa_snprintf(errMsg, 100,
+ "Texture unit %d is accessed both as %s and %s",
+ unit, targetName[targetUsed[unit]], targetName[target]);
+ return GL_FALSE;
+ }
+ targetUsed[unit] = target;
+ samplersUsed ^= (1 << sampler);
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Do validation of the given shader program.
+ * \param errMsg returns error message if validation fails.
+ * \return GL_TRUE if valid, GL_FALSE if invalid (and set errMsg)
+ */
+static GLboolean
+validate_shader_program(const struct gl_shader_program *shProg,
+ char *errMsg)
+{
+ const struct gl_vertex_program *vp = shProg->VertexProgram;
+ const struct gl_fragment_program *fp = shProg->FragmentProgram;
+
+ if (!shProg->LinkStatus) {
+ return GL_FALSE;
+ }
+
+ /* From the GL spec, a program is invalid if any of these are true:
+
+ any two active samplers in the current program object are of
+ different types, but refer to the same texture image unit,
+
+ any active sampler in the current program object refers to a texture
+ image unit where fixed-function fragment processing accesses a
+ texture target that does not match the sampler type, or
+
+ the sum of the number of active samplers in the program and the
+ number of texture image units enabled for fixed-function fragment
+ processing exceeds the combined limit on the total number of texture
+ image units allowed.
+ */
+
+
+ /*
+ * Check: any two active samplers in the current program object are of
+ * different types, but refer to the same texture image unit,
+ */
+ if (vp && !validate_samplers(&vp->Base, errMsg)) {
+ return GL_FALSE;
+ }
+ if (fp && !validate_samplers(&fp->Base, errMsg)) {
+ return GL_FALSE;
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Called via glValidateProgram()
+ */
+static void
+validate_program(struct gl_context *ctx, GLuint program)
+{
+ struct gl_shader_program *shProg;
+ char errMsg[100];
+
+ shProg = _mesa_lookup_shader_program_err(ctx, program, "glValidateProgram");
+ if (!shProg) {
+ return;
+ }
+
+ shProg->Validated = validate_shader_program(shProg, errMsg);
+ if (!shProg->Validated) {
+ /* update info log */
+ if (shProg->InfoLog) {
+ ralloc_free(shProg->InfoLog);
+ }
+ shProg->InfoLog = ralloc_strdup(shProg, errMsg);
+ }
+}
+
+
+
+void GLAPIENTRY
+_mesa_AttachObjectARB(GLhandleARB program, GLhandleARB shader)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ attach_shader(ctx, program, shader);
+}
+
+
+void GLAPIENTRY
+_mesa_AttachShader(GLuint program, GLuint shader)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ attach_shader(ctx, program, shader);
+}
+
+
+void GLAPIENTRY
+_mesa_BindAttribLocationARB(GLhandleARB program, GLuint index,
+ const GLcharARB *name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ bind_attrib_location(ctx, program, index, name);
+}
+
+
+/* GL_EXT_gpu_shader4, GL3 */
+void GLAPIENTRY
+_mesa_BindFragDataLocation(GLuint program, GLuint colorNumber,
+ const GLchar *name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ bind_frag_data_location(ctx, program, colorNumber, name);
+}
+
+
+void GLAPIENTRY
+_mesa_CompileShaderARB(GLhandleARB shaderObj)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glCompileShader %u\n", shaderObj);
+ compile_shader(ctx, shaderObj);
+}
+
+
+GLuint GLAPIENTRY
+_mesa_CreateShader(GLenum type)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glCreateShader %s\n", _mesa_lookup_enum_by_nr(type));
+ return create_shader(ctx, type);
+}
+
+
+GLhandleARB GLAPIENTRY
+_mesa_CreateShaderObjectARB(GLenum type)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ return create_shader(ctx, type);
+}
+
+
+GLuint GLAPIENTRY
+_mesa_CreateProgram(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glCreateProgram\n");
+ return create_shader_program(ctx);
+}
+
+
+GLhandleARB GLAPIENTRY
+_mesa_CreateProgramObjectARB(void)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ return create_shader_program(ctx);
+}
+
+
+void GLAPIENTRY
+_mesa_DeleteObjectARB(GLhandleARB obj)
+{
+ if (MESA_VERBOSE & VERBOSE_API) {
+ GET_CURRENT_CONTEXT(ctx);
+ _mesa_debug(ctx, "glDeleteObjectARB(%u)\n", obj);
+ }
+
+ if (obj) {
+ GET_CURRENT_CONTEXT(ctx);
+ if (is_program(ctx, obj)) {
+ delete_shader_program(ctx, obj);
+ }
+ else if (is_shader(ctx, obj)) {
+ delete_shader(ctx, obj);
+ }
+ else {
+ /* error? */
+ }
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_DeleteProgram(GLuint name)
+{
+ if (name) {
+ GET_CURRENT_CONTEXT(ctx);
+ delete_shader_program(ctx, name);
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_DeleteShader(GLuint name)
+{
+ if (name) {
+ GET_CURRENT_CONTEXT(ctx);
+ delete_shader(ctx, name);
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_DetachObjectARB(GLhandleARB program, GLhandleARB shader)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ detach_shader(ctx, program, shader);
+}
+
+
+void GLAPIENTRY
+_mesa_DetachShader(GLuint program, GLuint shader)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ detach_shader(ctx, program, shader);
+}
+
+
+void GLAPIENTRY
+_mesa_GetActiveAttribARB(GLhandleARB program, GLuint index,
+ GLsizei maxLength, GLsizei * length, GLint * size,
+ GLenum * type, GLcharARB * name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ get_active_attrib(ctx, program, index, maxLength, length, size, type, name);
+}
+
+
+void GLAPIENTRY
+_mesa_GetAttachedObjectsARB(GLhandleARB container, GLsizei maxCount,
+ GLsizei * count, GLhandleARB * obj)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ get_attached_shaders(ctx, container, maxCount, count, obj);
+}
+
+
+void GLAPIENTRY
+_mesa_GetAttachedShaders(GLuint program, GLsizei maxCount,
+ GLsizei *count, GLuint *obj)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ get_attached_shaders(ctx, program, maxCount, count, obj);
+}
+
+
+GLint GLAPIENTRY
+_mesa_GetAttribLocationARB(GLhandleARB program, const GLcharARB * name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ return get_attrib_location(ctx, program, name);
+}
+
+
+/* GL_EXT_gpu_shader4, GL3 */
+GLint GLAPIENTRY
+_mesa_GetFragDataLocation(GLuint program, const GLchar *name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ return get_frag_data_location(ctx, program, name);
+}
+
+
+
+void GLAPIENTRY
+_mesa_GetInfoLogARB(GLhandleARB object, GLsizei maxLength, GLsizei * length,
+ GLcharARB * infoLog)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (is_program(ctx, object)) {
+ get_program_info_log(ctx, object, maxLength, length, infoLog);
+ }
+ else if (is_shader(ctx, object)) {
+ get_shader_info_log(ctx, object, maxLength, length, infoLog);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetInfoLogARB");
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetObjectParameterivARB(GLhandleARB object, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ /* Implement in terms of GetProgramiv, GetShaderiv */
+ if (is_program(ctx, object)) {
+ if (pname == GL_OBJECT_TYPE_ARB) {
+ *params = GL_PROGRAM_OBJECT_ARB;
+ }
+ else {
+ get_programiv(ctx, object, pname, params);
+ }
+ }
+ else if (is_shader(ctx, object)) {
+ if (pname == GL_OBJECT_TYPE_ARB) {
+ *params = GL_SHADER_OBJECT_ARB;
+ }
+ else {
+ get_shaderiv(ctx, object, pname, params);
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetObjectParameterivARB");
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetObjectParameterfvARB(GLhandleARB object, GLenum pname,
+ GLfloat *params)
+{
+ GLint iparams[1]; /* XXX is one element enough? */
+ _mesa_GetObjectParameterivARB(object, pname, iparams);
+ params[0] = (GLfloat) iparams[0];
+}
+
+
+void GLAPIENTRY
+_mesa_GetProgramiv(GLuint program, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ get_programiv(ctx, program, pname, params);
+}
+
+
+void GLAPIENTRY
+_mesa_GetShaderiv(GLuint shader, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ get_shaderiv(ctx, shader, pname, params);
+}
+
+
+void GLAPIENTRY
+_mesa_GetProgramInfoLog(GLuint program, GLsizei bufSize,
+ GLsizei *length, GLchar *infoLog)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ get_program_info_log(ctx, program, bufSize, length, infoLog);
+}
+
+
+void GLAPIENTRY
+_mesa_GetShaderInfoLog(GLuint shader, GLsizei bufSize,
+ GLsizei *length, GLchar *infoLog)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ get_shader_info_log(ctx, shader, bufSize, length, infoLog);
+}
+
+
+void GLAPIENTRY
+_mesa_GetShaderSourceARB(GLhandleARB shader, GLsizei maxLength,
+ GLsizei *length, GLcharARB *sourceOut)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ get_shader_source(ctx, shader, maxLength, length, sourceOut);
+}
+
+
+GLhandleARB GLAPIENTRY
+_mesa_GetHandleARB(GLenum pname)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ return get_handle(ctx, pname);
+}
+
+
+GLboolean GLAPIENTRY
+_mesa_IsProgram(GLuint name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ return is_program(ctx, name);
+}
+
+
+GLboolean GLAPIENTRY
+_mesa_IsShader(GLuint name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ return is_shader(ctx, name);
+}
+
+
+void GLAPIENTRY
+_mesa_LinkProgramARB(GLhandleARB programObj)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ link_program(ctx, programObj);
+}
+
+
+
+/**
+ * Read shader source code from a file.
+ * Useful for debugging to override an app's shader.
+ */
+static GLcharARB *
+read_shader(const char *fname)
+{
+ const int max = 50*1000;
+ FILE *f = fopen(fname, "r");
+ GLcharARB *buffer, *shader;
+ int len;
+
+ if (!f) {
+ return NULL;
+ }
+
+ buffer = (char *) malloc(max);
+ len = fread(buffer, 1, max, f);
+ buffer[len] = 0;
+
+ fclose(f);
+
+ shader = _mesa_strdup(buffer);
+ free(buffer);
+
+ return shader;
+}
+
+
+/**
+ * Called via glShaderSource() and glShaderSourceARB() API functions.
+ * Basically, concatenate the source code strings into one long string
+ * and pass it to _mesa_shader_source().
+ */
+void GLAPIENTRY
+_mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count,
+ const GLcharARB ** string, const GLint * length)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint *offsets;
+ GLsizei i, totalLength;
+ GLcharARB *source;
+ GLuint checksum;
+
+ if (!shaderObj || string == NULL) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glShaderSourceARB");
+ return;
+ }
+
+ /*
+ * This array holds offsets of where the appropriate string ends, thus the
+ * last element will be set to the total length of the source code.
+ */
+ offsets = (GLint *) malloc(count * sizeof(GLint));
+ if (offsets == NULL) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
+ return;
+ }
+
+ for (i = 0; i < count; i++) {
+ if (string[i] == NULL) {
+ free((GLvoid *) offsets);
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glShaderSourceARB(null string)");
+ return;
+ }
+ if (length == NULL || length[i] < 0)
+ offsets[i] = strlen(string[i]);
+ else
+ offsets[i] = length[i];
+ /* accumulate string lengths */
+ if (i > 0)
+ offsets[i] += offsets[i - 1];
+ }
+
+ /* Total length of source string is sum off all strings plus two.
+ * One extra byte for terminating zero, another extra byte to silence
+ * valgrind warnings in the parser/grammer code.
+ */
+ totalLength = offsets[count - 1] + 2;
+ source = (GLcharARB *) malloc(totalLength * sizeof(GLcharARB));
+ if (source == NULL) {
+ free((GLvoid *) offsets);
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
+ return;
+ }
+
+ for (i = 0; i < count; i++) {
+ GLint start = (i > 0) ? offsets[i - 1] : 0;
+ memcpy(source + start, string[i],
+ (offsets[i] - start) * sizeof(GLcharARB));
+ }
+ source[totalLength - 1] = '\0';
+ source[totalLength - 2] = '\0';
+
+ if (SHADER_SUBST) {
+ /* Compute the shader's source code checksum then try to open a file
+ * named newshader_<CHECKSUM>. If it exists, use it in place of the
+ * original shader source code. For debugging.
+ */
+ char filename[100];
+ GLcharARB *newSource;
+
+ checksum = _mesa_str_checksum(source);
+
+ _mesa_snprintf(filename, sizeof(filename), "newshader_%d", checksum);
+
+ newSource = read_shader(filename);
+ if (newSource) {
+ fprintf(stderr, "Mesa: Replacing shader %u chksum=%d with %s\n",
+ shaderObj, checksum, filename);
+ free(source);
+ source = newSource;
+ }
+ }
+
+ shader_source(ctx, shaderObj, source);
+
+ if (SHADER_SUBST) {
+ struct gl_shader *sh = _mesa_lookup_shader(ctx, shaderObj);
+ if (sh)
+ sh->SourceChecksum = checksum; /* save original checksum */
+ }
+
+ free(offsets);
+}
+
+
+void GLAPIENTRY
+_mesa_UseProgramObjectARB(GLhandleARB program)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_shader_program *shProg;
+ struct gl_transform_feedback_object *obj =
+ ctx->TransformFeedback.CurrentObject;
+
+ if (obj->Active) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glUseProgram(transform feedback active)");
+ return;
+ }
+
+ if (program) {
+ shProg = _mesa_lookup_shader_program_err(ctx, program, "glUseProgram");
+ if (!shProg) {
+ return;
+ }
+ if (!shProg->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glUseProgram(program %u not linked)", program);
+ return;
+ }
+
+ /* debug code */
+ if (ctx->Shader.Flags & GLSL_USE_PROG) {
+ print_shader_info(shProg);
+ }
+ }
+ else {
+ shProg = NULL;
+ }
+
+ _mesa_use_program(ctx, shProg);
+}
+
+
+void GLAPIENTRY
+_mesa_ValidateProgramARB(GLhandleARB program)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ validate_program(ctx, program);
+}
+
+#ifdef FEATURE_ES2
+
+void GLAPIENTRY
+_mesa_GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype,
+ GLint* range, GLint* precision)
+{
+ const struct gl_program_constants *limits;
+ const struct gl_precision *p;
+ GET_CURRENT_CONTEXT(ctx);
+
+ switch (shadertype) {
+ case GL_VERTEX_SHADER:
+ limits = &ctx->Const.VertexProgram;
+ break;
+ case GL_FRAGMENT_SHADER:
+ limits = &ctx->Const.FragmentProgram;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetShaderPrecisionFormat(shadertype)");
+ return;
+ }
+
+ switch (precisiontype) {
+ case GL_LOW_FLOAT:
+ p = &limits->LowFloat;
+ break;
+ case GL_MEDIUM_FLOAT:
+ p = &limits->MediumFloat;
+ break;
+ case GL_HIGH_FLOAT:
+ p = &limits->HighFloat;
+ break;
+ case GL_LOW_INT:
+ p = &limits->LowInt;
+ break;
+ case GL_MEDIUM_INT:
+ p = &limits->MediumInt;
+ break;
+ case GL_HIGH_INT:
+ p = &limits->HighInt;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetShaderPrecisionFormat(precisiontype)");
+ return;
+ }
+
+ range[0] = p->RangeMin;
+ range[1] = p->RangeMax;
+ precision[0] = p->Precision;
+}
+
+
+void GLAPIENTRY
+_mesa_ReleaseShaderCompiler(void)
+{
+ _mesa_destroy_shader_compiler_caches();
+}
+
+
+void GLAPIENTRY
+_mesa_ShaderBinary(GLint n, const GLuint* shaders, GLenum binaryformat,
+ const void* binary, GLint length)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) n;
+ (void) shaders;
+ (void) binaryformat;
+ (void) binary;
+ (void) length;
+ _mesa_error(ctx, GL_INVALID_OPERATION, __FUNCTION__);
+}
+
+#endif /* FEATURE_ES2 */
+
+
+#if FEATURE_ARB_geometry_shader4
+
+void GLAPIENTRY
+_mesa_ProgramParameteriARB(GLuint program, GLenum pname,
+ GLint value)
+{
+ struct gl_shader_program *shProg;
+ GET_CURRENT_CONTEXT(ctx);
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ shProg = _mesa_lookup_shader_program_err(ctx, program,
+ "glProgramParameteri");
+ if (!shProg)
+ return;
+
+ switch (pname) {
+ case GL_GEOMETRY_VERTICES_OUT_ARB:
+ if (value < 1 ||
+ (unsigned) value > ctx->Const.GeometryProgram.MaxGeometryOutputVertices) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glProgramParameteri(GL_GEOMETRY_VERTICES_OUT_ARB=%d",
+ value);
+ return;
+ }
+ shProg->Geom.VerticesOut = value;
+ break;
+ case GL_GEOMETRY_INPUT_TYPE_ARB:
+ switch (value) {
+ case GL_POINTS:
+ case GL_LINES:
+ case GL_LINES_ADJACENCY_ARB:
+ case GL_TRIANGLES:
+ case GL_TRIANGLES_ADJACENCY_ARB:
+ shProg->Geom.InputType = value;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glProgramParameteri(geometry input type = %s",
+ _mesa_lookup_enum_by_nr(value));
+ return;
+ }
+ break;
+ case GL_GEOMETRY_OUTPUT_TYPE_ARB:
+ switch (value) {
+ case GL_POINTS:
+ case GL_LINE_STRIP:
+ case GL_TRIANGLE_STRIP:
+ shProg->Geom.OutputType = value;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glProgramParameteri(geometry output type = %s",
+ _mesa_lookup_enum_by_nr(value));
+ return;
+ }
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameteriARB(pname=%s)",
+ _mesa_lookup_enum_by_nr(pname));
+ break;
+ }
+}
+
+#endif
+
+void
+_mesa_use_shader_program(struct gl_context *ctx, GLenum type,
+ struct gl_shader_program *shProg)
+{
+ use_shader_program(ctx, type, shProg);
+
+ if (ctx->Driver.UseProgram)
+ ctx->Driver.UseProgram(ctx, shProg);
+}
+
+void GLAPIENTRY
+_mesa_UseShaderProgramEXT(GLenum type, GLuint program)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_shader_program *shProg = NULL;
+
+ if (!validate_shader_target(ctx, type)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glUseShaderProgramEXT(type)");
+ return;
+ }
+
+ if (ctx->TransformFeedback.CurrentObject->Active) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glUseShaderProgramEXT(transform feedback is active)");
+ return;
+ }
+
+ if (program) {
+ shProg = _mesa_lookup_shader_program_err(ctx, program,
+ "glUseShaderProgramEXT");
+ if (shProg == NULL)
+ return;
+
+ if (!shProg->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glUseShaderProgramEXT(program not linked)");
+ return;
+ }
+ }
+
+ _mesa_use_shader_program(ctx, type, shProg);
+}
+
+void GLAPIENTRY
+_mesa_ActiveProgramEXT(GLuint program)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_shader_program *shProg = (program != 0)
+ ? _mesa_lookup_shader_program_err(ctx, program, "glActiveProgramEXT")
+ : NULL;
+
+ _mesa_active_program(ctx, shProg, "glActiveProgramEXT");
+ return;
+}
+
+GLuint GLAPIENTRY
+_mesa_CreateShaderProgramEXT(GLenum type, const GLchar *string)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ const GLuint shader = create_shader(ctx, type);
+ GLuint program = 0;
+
+ if (shader) {
+ shader_source(ctx, shader, _mesa_strdup(string));
+ compile_shader(ctx, shader);
+
+ program = create_shader_program(ctx);
+ if (program) {
+ struct gl_shader_program *shProg;
+ struct gl_shader *sh;
+ GLint compiled = GL_FALSE;
+
+ shProg = _mesa_lookup_shader_program(ctx, program);
+ sh = _mesa_lookup_shader(ctx, shader);
+
+ get_shaderiv(ctx, shader, GL_COMPILE_STATUS, &compiled);
+ if (compiled) {
+ attach_shader(ctx, program, shader);
+ link_program(ctx, program);
+ detach_shader(ctx, program, shader);
+
+#if 0
+ /* Possibly... */
+ if (active-user-defined-varyings-in-linked-program) {
+ append-error-to-info-log;
+ shProg->LinkStatus = GL_FALSE;
+ }
+#endif
+ }
+
+ ralloc_strcat(&shProg->InfoLog, sh->InfoLog);
+ }
+
+ delete_shader(ctx, shader);
+ }
+
+ return program;
+}
+
+/**
+ * Plug in shader-related functions into API dispatch table.
+ */
+void
+_mesa_init_shader_dispatch(struct _glapi_table *exec)
+{
+#if FEATURE_GL
+ /* GL_ARB_vertex/fragment_shader */
+ SET_DeleteObjectARB(exec, _mesa_DeleteObjectARB);
+ SET_GetHandleARB(exec, _mesa_GetHandleARB);
+ SET_DetachObjectARB(exec, _mesa_DetachObjectARB);
+ SET_CreateShaderObjectARB(exec, _mesa_CreateShaderObjectARB);
+ SET_ShaderSourceARB(exec, _mesa_ShaderSourceARB);
+ SET_CompileShaderARB(exec, _mesa_CompileShaderARB);
+ SET_CreateProgramObjectARB(exec, _mesa_CreateProgramObjectARB);
+ SET_AttachObjectARB(exec, _mesa_AttachObjectARB);
+ SET_LinkProgramARB(exec, _mesa_LinkProgramARB);
+ SET_UseProgramObjectARB(exec, _mesa_UseProgramObjectARB);
+ SET_ValidateProgramARB(exec, _mesa_ValidateProgramARB);
+ SET_GetObjectParameterfvARB(exec, _mesa_GetObjectParameterfvARB);
+ SET_GetObjectParameterivARB(exec, _mesa_GetObjectParameterivARB);
+ SET_GetInfoLogARB(exec, _mesa_GetInfoLogARB);
+ SET_GetAttachedObjectsARB(exec, _mesa_GetAttachedObjectsARB);
+ SET_GetShaderSourceARB(exec, _mesa_GetShaderSourceARB);
+
+ /* OpenGL 2.0 */
+ SET_AttachShader(exec, _mesa_AttachShader);
+ SET_CreateProgram(exec, _mesa_CreateProgram);
+ SET_CreateShader(exec, _mesa_CreateShader);
+ SET_DeleteProgram(exec, _mesa_DeleteProgram);
+ SET_DeleteShader(exec, _mesa_DeleteShader);
+ SET_DetachShader(exec, _mesa_DetachShader);
+ SET_GetAttachedShaders(exec, _mesa_GetAttachedShaders);
+ SET_GetProgramiv(exec, _mesa_GetProgramiv);
+ SET_GetProgramInfoLog(exec, _mesa_GetProgramInfoLog);
+ SET_GetShaderiv(exec, _mesa_GetShaderiv);
+ SET_GetShaderInfoLog(exec, _mesa_GetShaderInfoLog);
+ SET_IsProgram(exec, _mesa_IsProgram);
+ SET_IsShader(exec, _mesa_IsShader);
+
+#if FEATURE_ARB_vertex_shader
+ SET_BindAttribLocationARB(exec, _mesa_BindAttribLocationARB);
+ SET_GetActiveAttribARB(exec, _mesa_GetActiveAttribARB);
+ SET_GetAttribLocationARB(exec, _mesa_GetAttribLocationARB);
+#endif
+
+#if FEATURE_ARB_geometry_shader4
+ SET_ProgramParameteriARB(exec, _mesa_ProgramParameteriARB);
+#endif
+
+ SET_UseShaderProgramEXT(exec, _mesa_UseShaderProgramEXT);
+ SET_ActiveProgramEXT(exec, _mesa_ActiveProgramEXT);
+ SET_CreateShaderProgramEXT(exec, _mesa_CreateShaderProgramEXT);
+
+ /* GL_EXT_gpu_shader4 / GL 3.0 */
+ SET_BindFragDataLocationEXT(exec, _mesa_BindFragDataLocation);
+ SET_GetFragDataLocationEXT(exec, _mesa_GetFragDataLocation);
+
+ /* GL_ARB_ES2_compatibility */
+ SET_ReleaseShaderCompiler(exec, _mesa_ReleaseShaderCompiler);
+ SET_GetShaderPrecisionFormat(exec, _mesa_GetShaderPrecisionFormat);
+
+#endif /* FEATURE_GL */
+}
+
diff --git a/mesalib/src/mesa/main/state.c b/mesalib/src/mesa/main/state.c
index 502c42929..f11578faf 100644
--- a/mesalib/src/mesa/main/state.c
+++ b/mesalib/src/mesa/main/state.c
@@ -1,734 +1,734 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.3
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file state.c
- * State management.
- *
- * This file manages recalculation of derived values in struct gl_context.
- */
-
-
-#include "glheader.h"
-#include "mtypes.h"
-#include "context.h"
-#include "debug.h"
-#include "macros.h"
-#include "ffvertex_prog.h"
-#include "framebuffer.h"
-#include "light.h"
-#include "matrix.h"
-#include "pixel.h"
-#include "program/program.h"
-#include "program/prog_parameter.h"
-#include "state.h"
-#include "stencil.h"
-#include "texenvprogram.h"
-#include "texobj.h"
-#include "texstate.h"
-
-
-static void
-update_separate_specular(struct gl_context *ctx)
-{
- if (NEED_SECONDARY_COLOR(ctx))
- ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
- else
- ctx->_TriangleCaps &= ~DD_SEPARATE_SPECULAR;
-}
-
-
-/**
- * Compute the index of the last array element that can be safely accessed
- * in a vertex array. We can really only do this when the array lives in
- * a VBO.
- * The array->_MaxElement field will be updated.
- * Later in glDrawArrays/Elements/etc we can do some bounds checking.
- */
-static void
-compute_max_element(struct gl_client_array *array)
-{
- assert(array->Enabled);
- if (array->BufferObj->Name) {
- GLsizeiptrARB offset = (GLsizeiptrARB) array->Ptr;
- GLsizeiptrARB obj_size = (GLsizeiptrARB) array->BufferObj->Size;
-
- if (offset < obj_size) {
- array->_MaxElement = (obj_size - offset +
- array->StrideB -
- array->_ElementSize) / array->StrideB;
- } else {
- array->_MaxElement = 0;
- }
- }
- else {
- /* user-space array, no idea how big it is */
- array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */
- }
-}
-
-
-/**
- * Helper for update_arrays().
- * \return min(current min, array->_MaxElement).
- */
-static GLuint
-update_min(GLuint min, struct gl_client_array *array)
-{
- compute_max_element(array);
- return MIN2(min, array->_MaxElement);
-}
-
-
-/**
- * Update ctx->Array._MaxElement (the max legal index into all enabled arrays).
- * Need to do this upon new array state or new buffer object state.
- */
-static void
-update_arrays( struct gl_context *ctx )
-{
- struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
- GLuint i, min = ~0;
-
- /* find min of _MaxElement values for all enabled arrays */
-
- /* 0 */
- if (ctx->VertexProgram._Current
- && arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled) {
- min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_POS]);
- }
- else if (arrayObj->Vertex.Enabled) {
- min = update_min(min, &arrayObj->Vertex);
- }
-
- /* 1 */
- if (ctx->VertexProgram._Enabled
- && arrayObj->VertexAttrib[VERT_ATTRIB_WEIGHT].Enabled) {
- min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_WEIGHT]);
- }
- /* no conventional vertex weight array */
-
- /* 2 */
- if (ctx->VertexProgram._Enabled
- && arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) {
- min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL]);
- }
- else if (arrayObj->Normal.Enabled) {
- min = update_min(min, &arrayObj->Normal);
- }
-
- /* 3 */
- if (ctx->VertexProgram._Enabled
- && arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) {
- min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0]);
- }
- else if (arrayObj->Color.Enabled) {
- min = update_min(min, &arrayObj->Color);
- }
-
- /* 4 */
- if (ctx->VertexProgram._Enabled
- && arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled) {
- min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1]);
- }
- else if (arrayObj->SecondaryColor.Enabled) {
- min = update_min(min, &arrayObj->SecondaryColor);
- }
-
- /* 5 */
- if (ctx->VertexProgram._Enabled
- && arrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled) {
- min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_FOG]);
- }
- else if (arrayObj->FogCoord.Enabled) {
- min = update_min(min, &arrayObj->FogCoord);
- }
-
- /* 6 */
- if (ctx->VertexProgram._Enabled
- && arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled) {
- min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX]);
- }
- else if (arrayObj->Index.Enabled) {
- min = update_min(min, &arrayObj->Index);
- }
-
- /* 7 */
- if (ctx->VertexProgram._Enabled
- && arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled) {
- min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG]);
- }
-
- /* 8..15 */
- for (i = VERT_ATTRIB_TEX0; i <= VERT_ATTRIB_TEX7; i++) {
- if (ctx->VertexProgram._Enabled
- && arrayObj->VertexAttrib[i].Enabled) {
- min = update_min(min, &arrayObj->VertexAttrib[i]);
- }
- else if (i - VERT_ATTRIB_TEX0 < ctx->Const.MaxTextureCoordUnits
- && arrayObj->TexCoord[i - VERT_ATTRIB_TEX0].Enabled) {
- min = update_min(min, &arrayObj->TexCoord[i - VERT_ATTRIB_TEX0]);
- }
- }
-
- /* 16..31 */
- if (ctx->VertexProgram._Current) {
- for (i = 0; i < Elements(arrayObj->VertexAttrib); i++) {
- if (arrayObj->VertexAttrib[i].Enabled) {
- min = update_min(min, &arrayObj->VertexAttrib[i]);
- }
- }
- }
-
- if (arrayObj->EdgeFlag.Enabled) {
- min = update_min(min, &arrayObj->EdgeFlag);
- }
-
- /* _MaxElement is one past the last legal array element */
- arrayObj->_MaxElement = min;
-}
-
-
-/**
- * Update the following fields:
- * ctx->VertexProgram._Enabled
- * ctx->FragmentProgram._Enabled
- * ctx->ATIFragmentShader._Enabled
- * This needs to be done before texture state validation.
- */
-static void
-update_program_enables(struct gl_context *ctx)
-{
- /* These _Enabled flags indicate if the program is enabled AND valid. */
- ctx->VertexProgram._Enabled = ctx->VertexProgram.Enabled
- && ctx->VertexProgram.Current->Base.Instructions;
- ctx->FragmentProgram._Enabled = ctx->FragmentProgram.Enabled
- && ctx->FragmentProgram.Current->Base.Instructions;
- ctx->ATIFragmentShader._Enabled = ctx->ATIFragmentShader.Enabled
- && ctx->ATIFragmentShader.Current->Instructions[0];
-}
-
-
-/**
- * Update vertex/fragment program state. In particular, update these fields:
- * ctx->VertexProgram._Current
- * ctx->VertexProgram._TnlProgram,
- * These point to the highest priority enabled vertex/fragment program or are
- * NULL if fixed-function processing is to be done.
- *
- * This function needs to be called after texture state validation in case
- * we're generating a fragment program from fixed-function texture state.
- *
- * \return bitfield which will indicate _NEW_PROGRAM state if a new vertex
- * or fragment program is being used.
- */
-static GLbitfield
-update_program(struct gl_context *ctx)
-{
- const struct gl_shader_program *vsProg = ctx->Shader.CurrentVertexProgram;
- const struct gl_shader_program *gsProg = ctx->Shader.CurrentGeometryProgram;
- const struct gl_shader_program *fsProg = ctx->Shader.CurrentFragmentProgram;
- const struct gl_vertex_program *prevVP = ctx->VertexProgram._Current;
- const struct gl_fragment_program *prevFP = ctx->FragmentProgram._Current;
- const struct gl_geometry_program *prevGP = ctx->GeometryProgram._Current;
- GLbitfield new_state = 0x0;
-
- /*
- * Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current
- * pointers to the programs that should be used for rendering. If either
- * is NULL, use fixed-function code paths.
- *
- * These programs may come from several sources. The priority is as
- * follows:
- * 1. OpenGL 2.0/ARB vertex/fragment shaders
- * 2. ARB/NV vertex/fragment programs
- * 3. Programs derived from fixed-function state.
- *
- * Note: it's possible for a vertex shader to get used with a fragment
- * program (and vice versa) here, but in practice that shouldn't ever
- * come up, or matter.
- */
-
- if (fsProg && fsProg->LinkStatus && fsProg->FragmentProgram) {
- /* Use shader programs */
- _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
- fsProg->FragmentProgram);
- }
- else if (ctx->FragmentProgram._Enabled) {
- /* use user-defined vertex program */
- _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
- ctx->FragmentProgram.Current);
- }
- else if (ctx->FragmentProgram._MaintainTexEnvProgram) {
- /* Use fragment program generated from fixed-function state.
- */
- _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
- _mesa_get_fixed_func_fragment_program(ctx));
- _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram,
- ctx->FragmentProgram._Current);
- }
- else {
- /* no fragment program */
- _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
- }
-
- if (gsProg && gsProg->LinkStatus && gsProg->GeometryProgram) {
- /* Use shader programs */
- _mesa_reference_geomprog(ctx, &ctx->GeometryProgram._Current,
- gsProg->GeometryProgram);
- } else {
- /* no fragment program */
- _mesa_reference_geomprog(ctx, &ctx->GeometryProgram._Current, NULL);
- }
-
- /* Examine vertex program after fragment program as
- * _mesa_get_fixed_func_vertex_program() needs to know active
- * fragprog inputs.
- */
- if (vsProg && vsProg->LinkStatus && vsProg->VertexProgram) {
- /* Use shader programs */
- _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
- vsProg->VertexProgram);
- }
- else if (ctx->VertexProgram._Enabled) {
- /* use user-defined vertex program */
- _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
- ctx->VertexProgram.Current);
- }
- else if (ctx->VertexProgram._MaintainTnlProgram) {
- /* Use vertex program generated from fixed-function state.
- */
- _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
- _mesa_get_fixed_func_vertex_program(ctx));
- _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram,
- ctx->VertexProgram._Current);
- }
- else {
- /* no vertex program */
- _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
- }
-
- /* Let the driver know what's happening:
- */
- if (ctx->FragmentProgram._Current != prevFP) {
- new_state |= _NEW_PROGRAM;
- if (ctx->Driver.BindProgram) {
- ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB,
- (struct gl_program *) ctx->FragmentProgram._Current);
- }
- }
-
- if (ctx->GeometryProgram._Current != prevGP) {
- new_state |= _NEW_PROGRAM;
- if (ctx->Driver.BindProgram) {
- ctx->Driver.BindProgram(ctx, MESA_GEOMETRY_PROGRAM,
- (struct gl_program *) ctx->GeometryProgram._Current);
- }
- }
-
- if (ctx->VertexProgram._Current != prevVP) {
- new_state |= _NEW_PROGRAM;
- if (ctx->Driver.BindProgram) {
- ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB,
- (struct gl_program *) ctx->VertexProgram._Current);
- }
- }
-
- return new_state;
-}
-
-
-/**
- * Examine shader constants and return either _NEW_PROGRAM_CONSTANTS or 0.
- */
-static GLbitfield
-update_program_constants(struct gl_context *ctx)
-{
- GLbitfield new_state = 0x0;
-
- if (ctx->FragmentProgram._Current) {
- const struct gl_program_parameter_list *params =
- ctx->FragmentProgram._Current->Base.Parameters;
- if (params && params->StateFlags & ctx->NewState) {
- new_state |= _NEW_PROGRAM_CONSTANTS;
- }
- }
-
- if (ctx->GeometryProgram._Current) {
- const struct gl_program_parameter_list *params =
- ctx->GeometryProgram._Current->Base.Parameters;
- /*FIXME: StateFlags is always 0 because we have unnamed constant
- * not state changes */
- if (params /*&& params->StateFlags & ctx->NewState*/) {
- new_state |= _NEW_PROGRAM_CONSTANTS;
- }
- }
-
- if (ctx->VertexProgram._Current) {
- const struct gl_program_parameter_list *params =
- ctx->VertexProgram._Current->Base.Parameters;
- if (params && params->StateFlags & ctx->NewState) {
- new_state |= _NEW_PROGRAM_CONSTANTS;
- }
- }
-
- return new_state;
-}
-
-
-
-
-static void
-update_viewport_matrix(struct gl_context *ctx)
-{
- const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF;
-
- ASSERT(depthMax > 0);
-
- /* Compute scale and bias values. This is really driver-specific
- * and should be maintained elsewhere if at all.
- * NOTE: RasterPos uses this.
- */
- _math_matrix_viewport(&ctx->Viewport._WindowMap,
- ctx->Viewport.X, ctx->Viewport.Y,
- ctx->Viewport.Width, ctx->Viewport.Height,
- ctx->Viewport.Near, ctx->Viewport.Far,
- depthMax);
-}
-
-
-/**
- * Update derived multisample state.
- */
-static void
-update_multisample(struct gl_context *ctx)
-{
- ctx->Multisample._Enabled = GL_FALSE;
- if (ctx->Multisample.Enabled &&
- ctx->DrawBuffer &&
- ctx->DrawBuffer->Visual.sampleBuffers)
- ctx->Multisample._Enabled = GL_TRUE;
-}
-
-
-/**
- * Update derived color/blend/logicop state.
- */
-static void
-update_color(struct gl_context *ctx)
-{
- /* This is needed to support 1.1's RGB logic ops AND
- * 1.0's blending logicops.
- */
- ctx->Color._LogicOpEnabled = RGBA_LOGICOP_ENABLED(ctx);
-}
-
-
-/*
- * Check polygon state and set DD_TRI_CULL_FRONT_BACK and/or DD_TRI_OFFSET
- * in ctx->_TriangleCaps if needed.
- */
-static void
-update_polygon(struct gl_context *ctx)
-{
- ctx->_TriangleCaps &= ~(DD_TRI_CULL_FRONT_BACK | DD_TRI_OFFSET);
-
- if (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
- ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
-
- if ( ctx->Polygon.OffsetPoint
- || ctx->Polygon.OffsetLine
- || ctx->Polygon.OffsetFill)
- ctx->_TriangleCaps |= DD_TRI_OFFSET;
-}
-
-
-/**
- * Update the ctx->_TriangleCaps bitfield.
- * XXX that bitfield should really go away someday!
- * This function must be called after other update_*() functions since
- * there are dependencies on some other derived values.
- */
-#if 0
-static void
-update_tricaps(struct gl_context *ctx, GLbitfield new_state)
-{
- ctx->_TriangleCaps = 0;
-
- /*
- * Points
- */
- if (1/*new_state & _NEW_POINT*/) {
- if (ctx->Point.SmoothFlag)
- ctx->_TriangleCaps |= DD_POINT_SMOOTH;
- if (ctx->Point._Attenuated)
- ctx->_TriangleCaps |= DD_POINT_ATTEN;
- }
-
- /*
- * Lines
- */
- if (1/*new_state & _NEW_LINE*/) {
- if (ctx->Line.SmoothFlag)
- ctx->_TriangleCaps |= DD_LINE_SMOOTH;
- if (ctx->Line.StippleFlag)
- ctx->_TriangleCaps |= DD_LINE_STIPPLE;
- }
-
- /*
- * Polygons
- */
- if (1/*new_state & _NEW_POLYGON*/) {
- if (ctx->Polygon.SmoothFlag)
- ctx->_TriangleCaps |= DD_TRI_SMOOTH;
- if (ctx->Polygon.StippleFlag)
- ctx->_TriangleCaps |= DD_TRI_STIPPLE;
- if (ctx->Polygon.FrontMode != GL_FILL
- || ctx->Polygon.BackMode != GL_FILL)
- ctx->_TriangleCaps |= DD_TRI_UNFILLED;
- if (ctx->Polygon.CullFlag
- && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
- ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
- if (ctx->Polygon.OffsetPoint ||
- ctx->Polygon.OffsetLine ||
- ctx->Polygon.OffsetFill)
- ctx->_TriangleCaps |= DD_TRI_OFFSET;
- }
-
- /*
- * Lighting and shading
- */
- if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
- ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
- if (ctx->Light.ShadeModel == GL_FLAT)
- ctx->_TriangleCaps |= DD_FLATSHADE;
- if (NEED_SECONDARY_COLOR(ctx))
- ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
-
- /*
- * Stencil
- */
- if (ctx->Stencil._TestTwoSide)
- ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
-}
-#endif
-
-
-/**
- * Compute derived GL state.
- * If __struct gl_contextRec::NewState is non-zero then this function \b must
- * be called before rendering anything.
- *
- * Calls dd_function_table::UpdateState to perform any internal state
- * management necessary.
- *
- * \sa _mesa_update_modelview_project(), _mesa_update_texture(),
- * _mesa_update_buffer_bounds(),
- * _mesa_update_lighting() and _mesa_update_tnl_spaces().
- */
-void
-_mesa_update_state_locked( struct gl_context *ctx )
-{
- GLbitfield new_state = ctx->NewState;
- GLbitfield prog_flags = _NEW_PROGRAM;
- GLbitfield new_prog_state = 0x0;
-
- if (new_state == _NEW_CURRENT_ATTRIB)
- goto out;
-
- if (MESA_VERBOSE & VERBOSE_STATE)
- _mesa_print_state("_mesa_update_state", new_state);
-
- /* Determine which state flags effect vertex/fragment program state */
- if (ctx->FragmentProgram._MaintainTexEnvProgram) {
- prog_flags |= (_NEW_BUFFERS | _NEW_TEXTURE | _NEW_FOG |
- _NEW_ARRAY | _NEW_LIGHT | _NEW_POINT | _NEW_RENDERMODE |
- _NEW_PROGRAM);
- }
- if (ctx->VertexProgram._MaintainTnlProgram) {
- prog_flags |= (_NEW_ARRAY | _NEW_TEXTURE | _NEW_TEXTURE_MATRIX |
- _NEW_TRANSFORM | _NEW_POINT |
- _NEW_FOG | _NEW_LIGHT |
- _MESA_NEW_NEED_EYE_COORDS);
- }
-
- /*
- * Now update derived state info
- */
-
- if (new_state & prog_flags)
- update_program_enables( ctx );
-
- if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION))
- _mesa_update_modelview_project( ctx, new_state );
-
- if (new_state & (_NEW_PROGRAM|_NEW_TEXTURE|_NEW_TEXTURE_MATRIX))
- _mesa_update_texture( ctx, new_state );
-
- if (new_state & _NEW_BUFFERS)
- _mesa_update_framebuffer(ctx);
-
- if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
- _mesa_update_draw_buffer_bounds( ctx );
-
- if (new_state & _NEW_POLYGON)
- update_polygon( ctx );
-
- if (new_state & _NEW_LIGHT)
- _mesa_update_lighting( ctx );
-
- if (new_state & (_NEW_STENCIL | _NEW_BUFFERS))
- _mesa_update_stencil( ctx );
-
- if (new_state & _MESA_NEW_TRANSFER_STATE)
- _mesa_update_pixel( ctx, new_state );
-
- if (new_state & _DD_NEW_SEPARATE_SPECULAR)
- update_separate_specular( ctx );
-
- if (new_state & (_NEW_BUFFERS | _NEW_VIEWPORT))
- update_viewport_matrix(ctx);
-
- if (new_state & _NEW_MULTISAMPLE)
- update_multisample( ctx );
-
- if (new_state & _NEW_COLOR)
- update_color( ctx );
-
-#if 0
- if (new_state & (_NEW_POINT | _NEW_LINE | _NEW_POLYGON | _NEW_LIGHT
- | _NEW_STENCIL | _DD_NEW_SEPARATE_SPECULAR))
- update_tricaps( ctx, new_state );
-#endif
-
- /* ctx->_NeedEyeCoords is now up to date.
- *
- * If the truth value of this variable has changed, update for the
- * new lighting space and recompute the positions of lights and the
- * normal transform.
- *
- * If the lighting space hasn't changed, may still need to recompute
- * light positions & normal transforms for other reasons.
- */
- if (new_state & _MESA_NEW_NEED_EYE_COORDS)
- _mesa_update_tnl_spaces( ctx, new_state );
-
- if (new_state & prog_flags) {
- /* When we generate programs from fixed-function vertex/fragment state
- * this call may generate/bind a new program. If so, we need to
- * propogate the _NEW_PROGRAM flag to the driver.
- */
- new_prog_state |= update_program( ctx );
- }
-
- if (new_state & (_NEW_ARRAY | _NEW_PROGRAM | _NEW_BUFFER_OBJECT))
- update_arrays( ctx );
-
- out:
- new_prog_state |= update_program_constants(ctx);
-
- /*
- * Give the driver a chance to act upon the new_state flags.
- * The driver might plug in different span functions, for example.
- * Also, this is where the driver can invalidate the state of any
- * active modules (such as swrast_setup, swrast, tnl, etc).
- *
- * Set ctx->NewState to zero to avoid recursion if
- * Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?)
- */
- new_state = ctx->NewState | new_prog_state;
- ctx->NewState = 0;
- ctx->Driver.UpdateState(ctx, new_state);
- ctx->Array.NewState = 0;
- if (!ctx->Array.RebindArrays)
- ctx->Array.RebindArrays = (new_state & (_NEW_ARRAY | _NEW_PROGRAM)) != 0;
-}
-
-
-/* This is the usual entrypoint for state updates:
- */
-void
-_mesa_update_state( struct gl_context *ctx )
-{
- _mesa_lock_context_textures(ctx);
- _mesa_update_state_locked(ctx);
- _mesa_unlock_context_textures(ctx);
-}
-
-
-
-
-/**
- * Want to figure out which fragment program inputs are actually
- * constant/current values from ctx->Current. These should be
- * referenced as a tracked state variable rather than a fragment
- * program input, to save the overhead of putting a constant value in
- * every submitted vertex, transferring it to hardware, interpolating
- * it across the triangle, etc...
- *
- * When there is a VP bound, just use vp->outputs. But when we're
- * generating vp from fixed function state, basically want to
- * calculate:
- *
- * vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) |
- * potential_vp_outputs )
- *
- * Where potential_vp_outputs is calculated by looking at enabled
- * texgen, etc.
- *
- * The generated fragment program should then only declare inputs that
- * may vary or otherwise differ from the ctx->Current values.
- * Otherwise, the fp should track them as state values instead.
- */
-void
-_mesa_set_varying_vp_inputs( struct gl_context *ctx,
- GLbitfield varying_inputs )
-{
- if (ctx->varying_vp_inputs != varying_inputs) {
- ctx->varying_vp_inputs = varying_inputs;
- ctx->NewState |= _NEW_ARRAY;
- /*printf("%s %x\n", __FUNCTION__, varying_inputs);*/
- }
-}
-
-
-/**
- * Used by drivers to tell core Mesa that the driver is going to
- * install/ use its own vertex program. In particular, this will
- * prevent generated fragment programs from using state vars instead
- * of ordinary varyings/inputs.
- */
-void
-_mesa_set_vp_override(struct gl_context *ctx, GLboolean flag)
-{
- if (ctx->VertexProgram._Overriden != flag) {
- ctx->VertexProgram._Overriden = flag;
-
- /* Set one of the bits which will trigger fragment program
- * regeneration:
- */
- ctx->NewState |= _NEW_PROGRAM;
- }
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.3
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file state.c
+ * State management.
+ *
+ * This file manages recalculation of derived values in struct gl_context.
+ */
+
+
+#include "glheader.h"
+#include "mtypes.h"
+#include "context.h"
+#include "debug.h"
+#include "macros.h"
+#include "ffvertex_prog.h"
+#include "framebuffer.h"
+#include "light.h"
+#include "matrix.h"
+#include "pixel.h"
+#include "program/program.h"
+#include "program/prog_parameter.h"
+#include "state.h"
+#include "stencil.h"
+#include "texenvprogram.h"
+#include "texobj.h"
+#include "texstate.h"
+
+
+static void
+update_separate_specular(struct gl_context *ctx)
+{
+ if (NEED_SECONDARY_COLOR(ctx))
+ ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
+ else
+ ctx->_TriangleCaps &= ~DD_SEPARATE_SPECULAR;
+}
+
+
+/**
+ * Compute the index of the last array element that can be safely accessed
+ * in a vertex array. We can really only do this when the array lives in
+ * a VBO.
+ * The array->_MaxElement field will be updated.
+ * Later in glDrawArrays/Elements/etc we can do some bounds checking.
+ */
+static void
+compute_max_element(struct gl_client_array *array)
+{
+ assert(array->Enabled);
+ if (array->BufferObj->Name) {
+ GLsizeiptrARB offset = (GLsizeiptrARB) array->Ptr;
+ GLsizeiptrARB obj_size = (GLsizeiptrARB) array->BufferObj->Size;
+
+ if (offset < obj_size) {
+ array->_MaxElement = (obj_size - offset +
+ array->StrideB -
+ array->_ElementSize) / array->StrideB;
+ } else {
+ array->_MaxElement = 0;
+ }
+ }
+ else {
+ /* user-space array, no idea how big it is */
+ array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */
+ }
+}
+
+
+/**
+ * Helper for update_arrays().
+ * \return min(current min, array->_MaxElement).
+ */
+static GLuint
+update_min(GLuint min, struct gl_client_array *array)
+{
+ compute_max_element(array);
+ return MIN2(min, array->_MaxElement);
+}
+
+
+/**
+ * Update ctx->Array._MaxElement (the max legal index into all enabled arrays).
+ * Need to do this upon new array state or new buffer object state.
+ */
+static void
+update_arrays( struct gl_context *ctx )
+{
+ struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
+ GLuint i, min = ~0;
+
+ /* find min of _MaxElement values for all enabled arrays */
+
+ /* 0 */
+ if (ctx->VertexProgram._Current
+ && arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled) {
+ min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_POS]);
+ }
+ else if (arrayObj->Vertex.Enabled) {
+ min = update_min(min, &arrayObj->Vertex);
+ }
+
+ /* 1 */
+ if (ctx->VertexProgram._Enabled
+ && arrayObj->VertexAttrib[VERT_ATTRIB_WEIGHT].Enabled) {
+ min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_WEIGHT]);
+ }
+ /* no conventional vertex weight array */
+
+ /* 2 */
+ if (ctx->VertexProgram._Enabled
+ && arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) {
+ min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL]);
+ }
+ else if (arrayObj->Normal.Enabled) {
+ min = update_min(min, &arrayObj->Normal);
+ }
+
+ /* 3 */
+ if (ctx->VertexProgram._Enabled
+ && arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) {
+ min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0]);
+ }
+ else if (arrayObj->Color.Enabled) {
+ min = update_min(min, &arrayObj->Color);
+ }
+
+ /* 4 */
+ if (ctx->VertexProgram._Enabled
+ && arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled) {
+ min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1]);
+ }
+ else if (arrayObj->SecondaryColor.Enabled) {
+ min = update_min(min, &arrayObj->SecondaryColor);
+ }
+
+ /* 5 */
+ if (ctx->VertexProgram._Enabled
+ && arrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled) {
+ min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_FOG]);
+ }
+ else if (arrayObj->FogCoord.Enabled) {
+ min = update_min(min, &arrayObj->FogCoord);
+ }
+
+ /* 6 */
+ if (ctx->VertexProgram._Enabled
+ && arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled) {
+ min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX]);
+ }
+ else if (arrayObj->Index.Enabled) {
+ min = update_min(min, &arrayObj->Index);
+ }
+
+ /* 7 */
+ if (ctx->VertexProgram._Enabled
+ && arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled) {
+ min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG]);
+ }
+
+ /* 8..15 */
+ for (i = VERT_ATTRIB_TEX0; i <= VERT_ATTRIB_TEX7; i++) {
+ if (ctx->VertexProgram._Enabled
+ && arrayObj->VertexAttrib[i].Enabled) {
+ min = update_min(min, &arrayObj->VertexAttrib[i]);
+ }
+ else if (i - VERT_ATTRIB_TEX0 < ctx->Const.MaxTextureCoordUnits
+ && arrayObj->TexCoord[i - VERT_ATTRIB_TEX0].Enabled) {
+ min = update_min(min, &arrayObj->TexCoord[i - VERT_ATTRIB_TEX0]);
+ }
+ }
+
+ /* 16..31 */
+ if (ctx->VertexProgram._Current) {
+ for (i = 0; i < Elements(arrayObj->VertexAttrib); i++) {
+ if (arrayObj->VertexAttrib[i].Enabled) {
+ min = update_min(min, &arrayObj->VertexAttrib[i]);
+ }
+ }
+ }
+
+ if (arrayObj->EdgeFlag.Enabled) {
+ min = update_min(min, &arrayObj->EdgeFlag);
+ }
+
+ /* _MaxElement is one past the last legal array element */
+ arrayObj->_MaxElement = min;
+}
+
+
+/**
+ * Update the following fields:
+ * ctx->VertexProgram._Enabled
+ * ctx->FragmentProgram._Enabled
+ * ctx->ATIFragmentShader._Enabled
+ * This needs to be done before texture state validation.
+ */
+static void
+update_program_enables(struct gl_context *ctx)
+{
+ /* These _Enabled flags indicate if the program is enabled AND valid. */
+ ctx->VertexProgram._Enabled = ctx->VertexProgram.Enabled
+ && ctx->VertexProgram.Current->Base.Instructions;
+ ctx->FragmentProgram._Enabled = ctx->FragmentProgram.Enabled
+ && ctx->FragmentProgram.Current->Base.Instructions;
+ ctx->ATIFragmentShader._Enabled = ctx->ATIFragmentShader.Enabled
+ && ctx->ATIFragmentShader.Current->Instructions[0];
+}
+
+
+/**
+ * Update vertex/fragment program state. In particular, update these fields:
+ * ctx->VertexProgram._Current
+ * ctx->VertexProgram._TnlProgram,
+ * These point to the highest priority enabled vertex/fragment program or are
+ * NULL if fixed-function processing is to be done.
+ *
+ * This function needs to be called after texture state validation in case
+ * we're generating a fragment program from fixed-function texture state.
+ *
+ * \return bitfield which will indicate _NEW_PROGRAM state if a new vertex
+ * or fragment program is being used.
+ */
+static GLbitfield
+update_program(struct gl_context *ctx)
+{
+ const struct gl_shader_program *vsProg = ctx->Shader.CurrentVertexProgram;
+ const struct gl_shader_program *gsProg = ctx->Shader.CurrentGeometryProgram;
+ const struct gl_shader_program *fsProg = ctx->Shader.CurrentFragmentProgram;
+ const struct gl_vertex_program *prevVP = ctx->VertexProgram._Current;
+ const struct gl_fragment_program *prevFP = ctx->FragmentProgram._Current;
+ const struct gl_geometry_program *prevGP = ctx->GeometryProgram._Current;
+ GLbitfield new_state = 0x0;
+
+ /*
+ * Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current
+ * pointers to the programs that should be used for rendering. If either
+ * is NULL, use fixed-function code paths.
+ *
+ * These programs may come from several sources. The priority is as
+ * follows:
+ * 1. OpenGL 2.0/ARB vertex/fragment shaders
+ * 2. ARB/NV vertex/fragment programs
+ * 3. Programs derived from fixed-function state.
+ *
+ * Note: it's possible for a vertex shader to get used with a fragment
+ * program (and vice versa) here, but in practice that shouldn't ever
+ * come up, or matter.
+ */
+
+ if (fsProg && fsProg->LinkStatus && fsProg->FragmentProgram) {
+ /* Use shader programs */
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
+ fsProg->FragmentProgram);
+ }
+ else if (ctx->FragmentProgram._Enabled) {
+ /* use user-defined vertex program */
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
+ ctx->FragmentProgram.Current);
+ }
+ else if (ctx->FragmentProgram._MaintainTexEnvProgram) {
+ /* Use fragment program generated from fixed-function state.
+ */
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
+ _mesa_get_fixed_func_fragment_program(ctx));
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram,
+ ctx->FragmentProgram._Current);
+ }
+ else {
+ /* no fragment program */
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
+ }
+
+ if (gsProg && gsProg->LinkStatus && gsProg->GeometryProgram) {
+ /* Use shader programs */
+ _mesa_reference_geomprog(ctx, &ctx->GeometryProgram._Current,
+ gsProg->GeometryProgram);
+ } else {
+ /* no fragment program */
+ _mesa_reference_geomprog(ctx, &ctx->GeometryProgram._Current, NULL);
+ }
+
+ /* Examine vertex program after fragment program as
+ * _mesa_get_fixed_func_vertex_program() needs to know active
+ * fragprog inputs.
+ */
+ if (vsProg && vsProg->LinkStatus && vsProg->VertexProgram) {
+ /* Use shader programs */
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
+ vsProg->VertexProgram);
+ }
+ else if (ctx->VertexProgram._Enabled) {
+ /* use user-defined vertex program */
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
+ ctx->VertexProgram.Current);
+ }
+ else if (ctx->VertexProgram._MaintainTnlProgram) {
+ /* Use vertex program generated from fixed-function state.
+ */
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
+ _mesa_get_fixed_func_vertex_program(ctx));
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram,
+ ctx->VertexProgram._Current);
+ }
+ else {
+ /* no vertex program */
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
+ }
+
+ /* Let the driver know what's happening:
+ */
+ if (ctx->FragmentProgram._Current != prevFP) {
+ new_state |= _NEW_PROGRAM;
+ if (ctx->Driver.BindProgram) {
+ ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB,
+ (struct gl_program *) ctx->FragmentProgram._Current);
+ }
+ }
+
+ if (ctx->GeometryProgram._Current != prevGP) {
+ new_state |= _NEW_PROGRAM;
+ if (ctx->Driver.BindProgram) {
+ ctx->Driver.BindProgram(ctx, MESA_GEOMETRY_PROGRAM,
+ (struct gl_program *) ctx->GeometryProgram._Current);
+ }
+ }
+
+ if (ctx->VertexProgram._Current != prevVP) {
+ new_state |= _NEW_PROGRAM;
+ if (ctx->Driver.BindProgram) {
+ ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB,
+ (struct gl_program *) ctx->VertexProgram._Current);
+ }
+ }
+
+ return new_state;
+}
+
+
+/**
+ * Examine shader constants and return either _NEW_PROGRAM_CONSTANTS or 0.
+ */
+static GLbitfield
+update_program_constants(struct gl_context *ctx)
+{
+ GLbitfield new_state = 0x0;
+
+ if (ctx->FragmentProgram._Current) {
+ const struct gl_program_parameter_list *params =
+ ctx->FragmentProgram._Current->Base.Parameters;
+ if (params && params->StateFlags & ctx->NewState) {
+ new_state |= _NEW_PROGRAM_CONSTANTS;
+ }
+ }
+
+ if (ctx->GeometryProgram._Current) {
+ const struct gl_program_parameter_list *params =
+ ctx->GeometryProgram._Current->Base.Parameters;
+ /*FIXME: StateFlags is always 0 because we have unnamed constant
+ * not state changes */
+ if (params /*&& params->StateFlags & ctx->NewState*/) {
+ new_state |= _NEW_PROGRAM_CONSTANTS;
+ }
+ }
+
+ if (ctx->VertexProgram._Current) {
+ const struct gl_program_parameter_list *params =
+ ctx->VertexProgram._Current->Base.Parameters;
+ if (params && params->StateFlags & ctx->NewState) {
+ new_state |= _NEW_PROGRAM_CONSTANTS;
+ }
+ }
+
+ return new_state;
+}
+
+
+
+
+static void
+update_viewport_matrix(struct gl_context *ctx)
+{
+ const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF;
+
+ ASSERT(depthMax > 0);
+
+ /* Compute scale and bias values. This is really driver-specific
+ * and should be maintained elsewhere if at all.
+ * NOTE: RasterPos uses this.
+ */
+ _math_matrix_viewport(&ctx->Viewport._WindowMap,
+ ctx->Viewport.X, ctx->Viewport.Y,
+ ctx->Viewport.Width, ctx->Viewport.Height,
+ ctx->Viewport.Near, ctx->Viewport.Far,
+ depthMax);
+}
+
+
+/**
+ * Update derived multisample state.
+ */
+static void
+update_multisample(struct gl_context *ctx)
+{
+ ctx->Multisample._Enabled = GL_FALSE;
+ if (ctx->Multisample.Enabled &&
+ ctx->DrawBuffer &&
+ ctx->DrawBuffer->Visual.sampleBuffers)
+ ctx->Multisample._Enabled = GL_TRUE;
+}
+
+
+/**
+ * Update derived color/blend/logicop state.
+ */
+static void
+update_color(struct gl_context *ctx)
+{
+ /* This is needed to support 1.1's RGB logic ops AND
+ * 1.0's blending logicops.
+ */
+ ctx->Color._LogicOpEnabled = RGBA_LOGICOP_ENABLED(ctx);
+}
+
+
+/*
+ * Check polygon state and set DD_TRI_CULL_FRONT_BACK and/or DD_TRI_OFFSET
+ * in ctx->_TriangleCaps if needed.
+ */
+static void
+update_polygon(struct gl_context *ctx)
+{
+ ctx->_TriangleCaps &= ~(DD_TRI_CULL_FRONT_BACK | DD_TRI_OFFSET);
+
+ if (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
+ ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
+
+ if ( ctx->Polygon.OffsetPoint
+ || ctx->Polygon.OffsetLine
+ || ctx->Polygon.OffsetFill)
+ ctx->_TriangleCaps |= DD_TRI_OFFSET;
+}
+
+
+/**
+ * Update the ctx->_TriangleCaps bitfield.
+ * XXX that bitfield should really go away someday!
+ * This function must be called after other update_*() functions since
+ * there are dependencies on some other derived values.
+ */
+#if 0
+static void
+update_tricaps(struct gl_context *ctx, GLbitfield new_state)
+{
+ ctx->_TriangleCaps = 0;
+
+ /*
+ * Points
+ */
+ if (1/*new_state & _NEW_POINT*/) {
+ if (ctx->Point.SmoothFlag)
+ ctx->_TriangleCaps |= DD_POINT_SMOOTH;
+ if (ctx->Point._Attenuated)
+ ctx->_TriangleCaps |= DD_POINT_ATTEN;
+ }
+
+ /*
+ * Lines
+ */
+ if (1/*new_state & _NEW_LINE*/) {
+ if (ctx->Line.SmoothFlag)
+ ctx->_TriangleCaps |= DD_LINE_SMOOTH;
+ if (ctx->Line.StippleFlag)
+ ctx->_TriangleCaps |= DD_LINE_STIPPLE;
+ }
+
+ /*
+ * Polygons
+ */
+ if (1/*new_state & _NEW_POLYGON*/) {
+ if (ctx->Polygon.SmoothFlag)
+ ctx->_TriangleCaps |= DD_TRI_SMOOTH;
+ if (ctx->Polygon.StippleFlag)
+ ctx->_TriangleCaps |= DD_TRI_STIPPLE;
+ if (ctx->Polygon.FrontMode != GL_FILL
+ || ctx->Polygon.BackMode != GL_FILL)
+ ctx->_TriangleCaps |= DD_TRI_UNFILLED;
+ if (ctx->Polygon.CullFlag
+ && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
+ ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
+ if (ctx->Polygon.OffsetPoint ||
+ ctx->Polygon.OffsetLine ||
+ ctx->Polygon.OffsetFill)
+ ctx->_TriangleCaps |= DD_TRI_OFFSET;
+ }
+
+ /*
+ * Lighting and shading
+ */
+ if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
+ ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
+ if (ctx->Light.ShadeModel == GL_FLAT)
+ ctx->_TriangleCaps |= DD_FLATSHADE;
+ if (NEED_SECONDARY_COLOR(ctx))
+ ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
+
+ /*
+ * Stencil
+ */
+ if (ctx->Stencil._TestTwoSide)
+ ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
+}
+#endif
+
+
+/**
+ * Compute derived GL state.
+ * If __struct gl_contextRec::NewState is non-zero then this function \b must
+ * be called before rendering anything.
+ *
+ * Calls dd_function_table::UpdateState to perform any internal state
+ * management necessary.
+ *
+ * \sa _mesa_update_modelview_project(), _mesa_update_texture(),
+ * _mesa_update_buffer_bounds(),
+ * _mesa_update_lighting() and _mesa_update_tnl_spaces().
+ */
+void
+_mesa_update_state_locked( struct gl_context *ctx )
+{
+ GLbitfield new_state = ctx->NewState;
+ GLbitfield prog_flags = _NEW_PROGRAM;
+ GLbitfield new_prog_state = 0x0;
+
+ if (new_state == _NEW_CURRENT_ATTRIB)
+ goto out;
+
+ if (MESA_VERBOSE & VERBOSE_STATE)
+ _mesa_print_state("_mesa_update_state", new_state);
+
+ /* Determine which state flags effect vertex/fragment program state */
+ if (ctx->FragmentProgram._MaintainTexEnvProgram) {
+ prog_flags |= (_NEW_BUFFERS | _NEW_TEXTURE | _NEW_FOG |
+ _NEW_ARRAY | _NEW_LIGHT | _NEW_POINT | _NEW_RENDERMODE |
+ _NEW_PROGRAM);
+ }
+ if (ctx->VertexProgram._MaintainTnlProgram) {
+ prog_flags |= (_NEW_ARRAY | _NEW_TEXTURE | _NEW_TEXTURE_MATRIX |
+ _NEW_TRANSFORM | _NEW_POINT |
+ _NEW_FOG | _NEW_LIGHT |
+ _MESA_NEW_NEED_EYE_COORDS);
+ }
+
+ /*
+ * Now update derived state info
+ */
+
+ if (new_state & prog_flags)
+ update_program_enables( ctx );
+
+ if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION))
+ _mesa_update_modelview_project( ctx, new_state );
+
+ if (new_state & (_NEW_PROGRAM|_NEW_TEXTURE|_NEW_TEXTURE_MATRIX))
+ _mesa_update_texture( ctx, new_state );
+
+ if (new_state & _NEW_BUFFERS)
+ _mesa_update_framebuffer(ctx);
+
+ if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
+ _mesa_update_draw_buffer_bounds( ctx );
+
+ if (new_state & _NEW_POLYGON)
+ update_polygon( ctx );
+
+ if (new_state & _NEW_LIGHT)
+ _mesa_update_lighting( ctx );
+
+ if (new_state & (_NEW_STENCIL | _NEW_BUFFERS))
+ _mesa_update_stencil( ctx );
+
+ if (new_state & _MESA_NEW_TRANSFER_STATE)
+ _mesa_update_pixel( ctx, new_state );
+
+ if (new_state & _DD_NEW_SEPARATE_SPECULAR)
+ update_separate_specular( ctx );
+
+ if (new_state & (_NEW_BUFFERS | _NEW_VIEWPORT))
+ update_viewport_matrix(ctx);
+
+ if (new_state & _NEW_MULTISAMPLE)
+ update_multisample( ctx );
+
+ if (new_state & _NEW_COLOR)
+ update_color( ctx );
+
+#if 0
+ if (new_state & (_NEW_POINT | _NEW_LINE | _NEW_POLYGON | _NEW_LIGHT
+ | _NEW_STENCIL | _DD_NEW_SEPARATE_SPECULAR))
+ update_tricaps( ctx, new_state );
+#endif
+
+ /* ctx->_NeedEyeCoords is now up to date.
+ *
+ * If the truth value of this variable has changed, update for the
+ * new lighting space and recompute the positions of lights and the
+ * normal transform.
+ *
+ * If the lighting space hasn't changed, may still need to recompute
+ * light positions & normal transforms for other reasons.
+ */
+ if (new_state & _MESA_NEW_NEED_EYE_COORDS)
+ _mesa_update_tnl_spaces( ctx, new_state );
+
+ if (new_state & prog_flags) {
+ /* When we generate programs from fixed-function vertex/fragment state
+ * this call may generate/bind a new program. If so, we need to
+ * propogate the _NEW_PROGRAM flag to the driver.
+ */
+ new_prog_state |= update_program( ctx );
+ }
+
+ if (new_state & (_NEW_ARRAY | _NEW_PROGRAM | _NEW_BUFFER_OBJECT))
+ update_arrays( ctx );
+
+ out:
+ new_prog_state |= update_program_constants(ctx);
+
+ /*
+ * Give the driver a chance to act upon the new_state flags.
+ * The driver might plug in different span functions, for example.
+ * Also, this is where the driver can invalidate the state of any
+ * active modules (such as swrast_setup, swrast, tnl, etc).
+ *
+ * Set ctx->NewState to zero to avoid recursion if
+ * Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?)
+ */
+ new_state = ctx->NewState | new_prog_state;
+ ctx->NewState = 0;
+ ctx->Driver.UpdateState(ctx, new_state);
+ ctx->Array.NewState = 0;
+ if (!ctx->Array.RebindArrays)
+ ctx->Array.RebindArrays = (new_state & (_NEW_ARRAY | _NEW_PROGRAM)) != 0;
+}
+
+
+/* This is the usual entrypoint for state updates:
+ */
+void
+_mesa_update_state( struct gl_context *ctx )
+{
+ _mesa_lock_context_textures(ctx);
+ _mesa_update_state_locked(ctx);
+ _mesa_unlock_context_textures(ctx);
+}
+
+
+
+
+/**
+ * Want to figure out which fragment program inputs are actually
+ * constant/current values from ctx->Current. These should be
+ * referenced as a tracked state variable rather than a fragment
+ * program input, to save the overhead of putting a constant value in
+ * every submitted vertex, transferring it to hardware, interpolating
+ * it across the triangle, etc...
+ *
+ * When there is a VP bound, just use vp->outputs. But when we're
+ * generating vp from fixed function state, basically want to
+ * calculate:
+ *
+ * vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) |
+ * potential_vp_outputs )
+ *
+ * Where potential_vp_outputs is calculated by looking at enabled
+ * texgen, etc.
+ *
+ * The generated fragment program should then only declare inputs that
+ * may vary or otherwise differ from the ctx->Current values.
+ * Otherwise, the fp should track them as state values instead.
+ */
+void
+_mesa_set_varying_vp_inputs( struct gl_context *ctx,
+ GLbitfield varying_inputs )
+{
+ if (ctx->varying_vp_inputs != varying_inputs) {
+ ctx->varying_vp_inputs = varying_inputs;
+ ctx->NewState |= _NEW_ARRAY;
+ /*printf("%s %x\n", __FUNCTION__, varying_inputs);*/
+ }
+}
+
+
+/**
+ * Used by drivers to tell core Mesa that the driver is going to
+ * install/ use its own vertex program. In particular, this will
+ * prevent generated fragment programs from using state vars instead
+ * of ordinary varyings/inputs.
+ */
+void
+_mesa_set_vp_override(struct gl_context *ctx, GLboolean flag)
+{
+ if (ctx->VertexProgram._Overriden != flag) {
+ ctx->VertexProgram._Overriden = flag;
+
+ /* Set one of the bits which will trigger fragment program
+ * regeneration:
+ */
+ ctx->NewState |= _NEW_PROGRAM;
+ }
+}
diff --git a/mesalib/src/mesa/main/stencil.c b/mesalib/src/mesa/main/stencil.c
index d898bf1d7..b49ddbdbb 100644
--- a/mesalib/src/mesa/main/stencil.c
+++ b/mesalib/src/mesa/main/stencil.c
@@ -1,614 +1,614 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file stencil.c
- * Stencil operations.
- *
- * Note: There's some conflict between GL_EXT_stencil_two_side and
- * OpenGL 2.0's two-sided stencil feature.
- *
- * With GL_EXT_stencil_two_side, calling glStencilOp/Func/Mask() only the
- * front OR back face state (as set by glActiveStencilFaceEXT) is set.
- *
- * But with OpenGL 2.0, calling glStencilOp/Func/Mask() sets BOTH the
- * front AND back state.
- *
- * Also, note that GL_ATI_separate_stencil is different as well:
- * glStencilFuncSeparateATI(GLenum frontfunc, GLenum backfunc, ...) vs.
- * glStencilFuncSeparate(GLenum face, GLenum func, ...).
- *
- * This problem is solved by keeping three sets of stencil state:
- * state[0] = GL_FRONT state.
- * state[1] = OpenGL 2.0 / GL_ATI_separate_stencil GL_BACK state.
- * state[2] = GL_EXT_stencil_two_side GL_BACK state.
- */
-
-
-#include "glheader.h"
-#include "imports.h"
-#include "context.h"
-#include "macros.h"
-#include "stencil.h"
-#include "mtypes.h"
-
-
-static GLboolean
-validate_stencil_op(struct gl_context *ctx, GLenum op)
-{
- switch (op) {
- case GL_KEEP:
- case GL_ZERO:
- case GL_REPLACE:
- case GL_INCR:
- case GL_DECR:
- case GL_INVERT:
- return GL_TRUE;
- case GL_INCR_WRAP_EXT:
- case GL_DECR_WRAP_EXT:
- if (ctx->Extensions.EXT_stencil_wrap) {
- return GL_TRUE;
- }
- /* FALL-THROUGH */
- default:
- return GL_FALSE;
- }
-}
-
-
-static GLboolean
-validate_stencil_func(struct gl_context *ctx, GLenum func)
-{
- switch (func) {
- case GL_NEVER:
- case GL_LESS:
- case GL_LEQUAL:
- case GL_GREATER:
- case GL_GEQUAL:
- case GL_EQUAL:
- case GL_NOTEQUAL:
- case GL_ALWAYS:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Set the clear value for the stencil buffer.
- *
- * \param s clear value.
- *
- * \sa glClearStencil().
- *
- * Updates gl_stencil_attrib::Clear. On change
- * flushes the vertices and notifies the driver via
- * the dd_function_table::ClearStencil callback.
- */
-void GLAPIENTRY
-_mesa_ClearStencil( GLint s )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (ctx->Stencil.Clear == (GLuint) s)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.Clear = (GLuint) s;
-
- if (ctx->Driver.ClearStencil) {
- ctx->Driver.ClearStencil( ctx, s );
- }
-}
-
-
-/**
- * Set the function and reference value for stencil testing.
- *
- * \param frontfunc front test function.
- * \param backfunc back test function.
- * \param ref front and back reference value.
- * \param mask front and back bitmask.
- *
- * \sa glStencilFunc().
- *
- * Verifies the parameters and updates the respective values in
- * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies the
- * driver via the dd_function_table::StencilFunc callback.
- */
-void GLAPIENTRY
-_mesa_StencilFuncSeparateATI( GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask )
-{
- GET_CURRENT_CONTEXT(ctx);
- const GLint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glStencilFuncSeparateATI()\n");
-
- if (!validate_stencil_func(ctx, frontfunc)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glStencilFuncSeparateATI(frontfunc)");
- return;
- }
- if (!validate_stencil_func(ctx, backfunc)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glStencilFuncSeparateATI(backfunc)");
- return;
- }
-
- ref = CLAMP( ref, 0, stencilMax );
-
- /* set both front and back state */
- if (ctx->Stencil.Function[0] == frontfunc &&
- ctx->Stencil.Function[1] == backfunc &&
- ctx->Stencil.ValueMask[0] == mask &&
- ctx->Stencil.ValueMask[1] == mask &&
- ctx->Stencil.Ref[0] == ref &&
- ctx->Stencil.Ref[1] == ref)
- return;
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.Function[0] = frontfunc;
- ctx->Stencil.Function[1] = backfunc;
- ctx->Stencil.Ref[0] = ctx->Stencil.Ref[1] = ref;
- ctx->Stencil.ValueMask[0] = ctx->Stencil.ValueMask[1] = mask;
- if (ctx->Driver.StencilFuncSeparate) {
- ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
- frontfunc, ref, mask);
- ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
- backfunc, ref, mask);
- }
-}
-
-
-/**
- * Set the function and reference value for stencil testing.
- *
- * \param func test function.
- * \param ref reference value.
- * \param mask bitmask.
- *
- * \sa glStencilFunc().
- *
- * Verifies the parameters and updates the respective values in
- * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies the
- * driver via the dd_function_table::StencilFunc callback.
- */
-void GLAPIENTRY
-_mesa_StencilFunc( GLenum func, GLint ref, GLuint mask )
-{
- GET_CURRENT_CONTEXT(ctx);
- const GLint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
- const GLint face = ctx->Stencil.ActiveFace;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glStencilFunc()\n");
-
- if (!validate_stencil_func(ctx, func)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFunc(func)");
- return;
- }
-
- ref = CLAMP( ref, 0, stencilMax );
-
- if (face != 0) {
- if (ctx->Stencil.Function[face] == func &&
- ctx->Stencil.ValueMask[face] == mask &&
- ctx->Stencil.Ref[face] == ref)
- return;
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.Function[face] = func;
- ctx->Stencil.Ref[face] = ref;
- ctx->Stencil.ValueMask[face] = mask;
-
- /* Only propagate the change to the driver if EXT_stencil_two_side
- * is enabled.
- */
- if (ctx->Driver.StencilFuncSeparate && ctx->Stencil.TestTwoSide) {
- ctx->Driver.StencilFuncSeparate(ctx, GL_BACK, func, ref, mask);
- }
- }
- else {
- /* set both front and back state */
- if (ctx->Stencil.Function[0] == func &&
- ctx->Stencil.Function[1] == func &&
- ctx->Stencil.ValueMask[0] == mask &&
- ctx->Stencil.ValueMask[1] == mask &&
- ctx->Stencil.Ref[0] == ref &&
- ctx->Stencil.Ref[1] == ref)
- return;
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.Function[0] = ctx->Stencil.Function[1] = func;
- ctx->Stencil.Ref[0] = ctx->Stencil.Ref[1] = ref;
- ctx->Stencil.ValueMask[0] = ctx->Stencil.ValueMask[1] = mask;
- if (ctx->Driver.StencilFuncSeparate) {
- ctx->Driver.StencilFuncSeparate(ctx,
- ((ctx->Stencil.TestTwoSide)
- ? GL_FRONT : GL_FRONT_AND_BACK),
- func, ref, mask);
- }
- }
-}
-
-
-/**
- * Set the stencil writing mask.
- *
- * \param mask bit-mask to enable/disable writing of individual bits in the
- * stencil planes.
- *
- * \sa glStencilMask().
- *
- * Updates gl_stencil_attrib::WriteMask. On change flushes the vertices and
- * notifies the driver via the dd_function_table::StencilMask callback.
- */
-void GLAPIENTRY
-_mesa_StencilMask( GLuint mask )
-{
- GET_CURRENT_CONTEXT(ctx);
- const GLint face = ctx->Stencil.ActiveFace;
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glStencilMask()\n");
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (face != 0) {
- /* Only modify the EXT_stencil_two_side back-face state.
- */
- if (ctx->Stencil.WriteMask[face] == mask)
- return;
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.WriteMask[face] = mask;
-
- /* Only propagate the change to the driver if EXT_stencil_two_side
- * is enabled.
- */
- if (ctx->Driver.StencilMaskSeparate && ctx->Stencil.TestTwoSide) {
- ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, mask);
- }
- }
- else {
- /* set both front and back state */
- if (ctx->Stencil.WriteMask[0] == mask &&
- ctx->Stencil.WriteMask[1] == mask)
- return;
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.WriteMask[0] = ctx->Stencil.WriteMask[1] = mask;
- if (ctx->Driver.StencilMaskSeparate) {
- ctx->Driver.StencilMaskSeparate(ctx,
- ((ctx->Stencil.TestTwoSide)
- ? GL_FRONT : GL_FRONT_AND_BACK),
- mask);
- }
- }
-}
-
-
-/**
- * Set the stencil test actions.
- *
- * \param fail action to take when stencil test fails.
- * \param zfail action to take when stencil test passes, but depth test fails.
- * \param zpass action to take when stencil test passes and the depth test
- * passes (or depth testing is not enabled).
- *
- * \sa glStencilOp().
- *
- * Verifies the parameters and updates the respective fields in
- * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies the
- * driver via the dd_function_table::StencilOp callback.
- */
-void GLAPIENTRY
-_mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
-{
- GET_CURRENT_CONTEXT(ctx);
- const GLint face = ctx->Stencil.ActiveFace;
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glStencilOp()\n");
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (!validate_stencil_op(ctx, fail)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(sfail)");
- return;
- }
- if (!validate_stencil_op(ctx, zfail)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zfail)");
- return;
- }
- if (!validate_stencil_op(ctx, zpass)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zpass)");
- return;
- }
-
- if (face != 0) {
- /* only set active face state */
- if (ctx->Stencil.ZFailFunc[face] == zfail &&
- ctx->Stencil.ZPassFunc[face] == zpass &&
- ctx->Stencil.FailFunc[face] == fail)
- return;
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.ZFailFunc[face] = zfail;
- ctx->Stencil.ZPassFunc[face] = zpass;
- ctx->Stencil.FailFunc[face] = fail;
-
- /* Only propagate the change to the driver if EXT_stencil_two_side
- * is enabled.
- */
- if (ctx->Driver.StencilOpSeparate && ctx->Stencil.TestTwoSide) {
- ctx->Driver.StencilOpSeparate(ctx, GL_BACK, fail, zfail, zpass);
- }
- }
- else {
- /* set both front and back state */
- if (ctx->Stencil.ZFailFunc[0] == zfail &&
- ctx->Stencil.ZFailFunc[1] == zfail &&
- ctx->Stencil.ZPassFunc[0] == zpass &&
- ctx->Stencil.ZPassFunc[1] == zpass &&
- ctx->Stencil.FailFunc[0] == fail &&
- ctx->Stencil.FailFunc[1] == fail)
- return;
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.ZFailFunc[0] = ctx->Stencil.ZFailFunc[1] = zfail;
- ctx->Stencil.ZPassFunc[0] = ctx->Stencil.ZPassFunc[1] = zpass;
- ctx->Stencil.FailFunc[0] = ctx->Stencil.FailFunc[1] = fail;
- if (ctx->Driver.StencilOpSeparate) {
- ctx->Driver.StencilOpSeparate(ctx,
- ((ctx->Stencil.TestTwoSide)
- ? GL_FRONT : GL_FRONT_AND_BACK),
- fail, zfail, zpass);
- }
- }
-}
-
-
-
-#if _HAVE_FULL_GL
-/* GL_EXT_stencil_two_side */
-void GLAPIENTRY
-_mesa_ActiveStencilFaceEXT(GLenum face)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glActiveStencilFaceEXT()\n");
-
- if (!ctx->Extensions.EXT_stencil_two_side) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glActiveStencilFaceEXT");
- return;
- }
-
- if (face == GL_FRONT || face == GL_BACK) {
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.ActiveFace = (face == GL_FRONT) ? 0 : 2;
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glActiveStencilFaceEXT(face)");
- }
-}
-#endif
-
-
-
-/**
- * OpenGL 2.0 function.
- * \todo Make StencilOp() call this function. And eventually remove the
- * ctx->Driver.StencilOp function and use ctx->Driver.StencilOpSeparate
- * instead.
- */
-void GLAPIENTRY
-_mesa_StencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass)
-{
- GLboolean set = GL_FALSE;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glStencilOpSeparate()\n");
-
- if (!validate_stencil_op(ctx, sfail)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(sfail)");
- return;
- }
- if (!validate_stencil_op(ctx, zfail)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zfail)");
- return;
- }
- if (!validate_stencil_op(ctx, zpass)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zpass)");
- return;
- }
- if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(face)");
- return;
- }
-
- if (face != GL_BACK) {
- /* set front */
- if (ctx->Stencil.ZFailFunc[0] != zfail ||
- ctx->Stencil.ZPassFunc[0] != zpass ||
- ctx->Stencil.FailFunc[0] != sfail){
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.ZFailFunc[0] = zfail;
- ctx->Stencil.ZPassFunc[0] = zpass;
- ctx->Stencil.FailFunc[0] = sfail;
- set = GL_TRUE;
- }
- }
- if (face != GL_FRONT) {
- /* set back */
- if (ctx->Stencil.ZFailFunc[1] != zfail ||
- ctx->Stencil.ZPassFunc[1] != zpass ||
- ctx->Stencil.FailFunc[1] != sfail) {
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
- ctx->Stencil.ZFailFunc[1] = zfail;
- ctx->Stencil.ZPassFunc[1] = zpass;
- ctx->Stencil.FailFunc[1] = sfail;
- set = GL_TRUE;
- }
- }
- if (set && ctx->Driver.StencilOpSeparate) {
- ctx->Driver.StencilOpSeparate(ctx, face, sfail, zfail, zpass);
- }
-}
-
-
-/* OpenGL 2.0 */
-void GLAPIENTRY
-_mesa_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- const GLint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glStencilFuncSeparate()\n");
-
- if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(face)");
- return;
- }
- if (!validate_stencil_func(ctx, func)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(func)");
- return;
- }
-
- ref = CLAMP(ref, 0, stencilMax);
-
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
-
- if (face != GL_BACK) {
- /* set front */
- ctx->Stencil.Function[0] = func;
- ctx->Stencil.Ref[0] = ref;
- ctx->Stencil.ValueMask[0] = mask;
- }
- if (face != GL_FRONT) {
- /* set back */
- ctx->Stencil.Function[1] = func;
- ctx->Stencil.Ref[1] = ref;
- ctx->Stencil.ValueMask[1] = mask;
- }
- if (ctx->Driver.StencilFuncSeparate) {
- ctx->Driver.StencilFuncSeparate(ctx, face, func, ref, mask);
- }
-}
-
-
-/* OpenGL 2.0 */
-void GLAPIENTRY
-_mesa_StencilMaskSeparate(GLenum face, GLuint mask)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glStencilMaskSeparate()\n");
-
- if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glStencilaMaskSeparate(face)");
- return;
- }
-
- FLUSH_VERTICES(ctx, _NEW_STENCIL);
-
- if (face != GL_BACK) {
- ctx->Stencil.WriteMask[0] = mask;
- }
- if (face != GL_FRONT) {
- ctx->Stencil.WriteMask[1] = mask;
- }
- if (ctx->Driver.StencilMaskSeparate) {
- ctx->Driver.StencilMaskSeparate(ctx, face, mask);
- }
-}
-
-
-/**
- * Update derived stencil state.
- */
-void
-_mesa_update_stencil(struct gl_context *ctx)
-{
- const GLint face = ctx->Stencil._BackFace;
-
- ctx->Stencil._Enabled = (ctx->Stencil.Enabled &&
- ctx->DrawBuffer->Visual.stencilBits > 0);
-
- ctx->Stencil._TestTwoSide =
- ctx->Stencil._Enabled &&
- (ctx->Stencil.Function[0] != ctx->Stencil.Function[face] ||
- ctx->Stencil.FailFunc[0] != ctx->Stencil.FailFunc[face] ||
- ctx->Stencil.ZPassFunc[0] != ctx->Stencil.ZPassFunc[face] ||
- ctx->Stencil.ZFailFunc[0] != ctx->Stencil.ZFailFunc[face] ||
- ctx->Stencil.Ref[0] != ctx->Stencil.Ref[face] ||
- ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[face] ||
- ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[face]);
-}
-
-
-/**
- * Initialize the context stipple state.
- *
- * \param ctx GL context.
- *
- * Initializes __struct gl_contextRec::Stencil attribute group.
- */
-void
-_mesa_init_stencil(struct gl_context *ctx)
-{
- ctx->Stencil.Enabled = GL_FALSE;
- ctx->Stencil.TestTwoSide = GL_FALSE;
- ctx->Stencil.ActiveFace = 0; /* 0 = GL_FRONT, 2 = GL_BACK */
- ctx->Stencil.Function[0] = GL_ALWAYS;
- ctx->Stencil.Function[1] = GL_ALWAYS;
- ctx->Stencil.Function[2] = GL_ALWAYS;
- ctx->Stencil.FailFunc[0] = GL_KEEP;
- ctx->Stencil.FailFunc[1] = GL_KEEP;
- ctx->Stencil.FailFunc[2] = GL_KEEP;
- ctx->Stencil.ZPassFunc[0] = GL_KEEP;
- ctx->Stencil.ZPassFunc[1] = GL_KEEP;
- ctx->Stencil.ZPassFunc[2] = GL_KEEP;
- ctx->Stencil.ZFailFunc[0] = GL_KEEP;
- ctx->Stencil.ZFailFunc[1] = GL_KEEP;
- ctx->Stencil.ZFailFunc[2] = GL_KEEP;
- ctx->Stencil.Ref[0] = 0;
- ctx->Stencil.Ref[1] = 0;
- ctx->Stencil.Ref[2] = 0;
- ctx->Stencil.ValueMask[0] = ~0U;
- ctx->Stencil.ValueMask[1] = ~0U;
- ctx->Stencil.ValueMask[2] = ~0U;
- ctx->Stencil.WriteMask[0] = ~0U;
- ctx->Stencil.WriteMask[1] = ~0U;
- ctx->Stencil.WriteMask[2] = ~0U;
- ctx->Stencil.Clear = 0;
- ctx->Stencil._BackFace = 1;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file stencil.c
+ * Stencil operations.
+ *
+ * Note: There's some conflict between GL_EXT_stencil_two_side and
+ * OpenGL 2.0's two-sided stencil feature.
+ *
+ * With GL_EXT_stencil_two_side, calling glStencilOp/Func/Mask() only the
+ * front OR back face state (as set by glActiveStencilFaceEXT) is set.
+ *
+ * But with OpenGL 2.0, calling glStencilOp/Func/Mask() sets BOTH the
+ * front AND back state.
+ *
+ * Also, note that GL_ATI_separate_stencil is different as well:
+ * glStencilFuncSeparateATI(GLenum frontfunc, GLenum backfunc, ...) vs.
+ * glStencilFuncSeparate(GLenum face, GLenum func, ...).
+ *
+ * This problem is solved by keeping three sets of stencil state:
+ * state[0] = GL_FRONT state.
+ * state[1] = OpenGL 2.0 / GL_ATI_separate_stencil GL_BACK state.
+ * state[2] = GL_EXT_stencil_two_side GL_BACK state.
+ */
+
+
+#include "glheader.h"
+#include "imports.h"
+#include "context.h"
+#include "macros.h"
+#include "stencil.h"
+#include "mtypes.h"
+
+
+static GLboolean
+validate_stencil_op(struct gl_context *ctx, GLenum op)
+{
+ switch (op) {
+ case GL_KEEP:
+ case GL_ZERO:
+ case GL_REPLACE:
+ case GL_INCR:
+ case GL_DECR:
+ case GL_INVERT:
+ return GL_TRUE;
+ case GL_INCR_WRAP_EXT:
+ case GL_DECR_WRAP_EXT:
+ if (ctx->Extensions.EXT_stencil_wrap) {
+ return GL_TRUE;
+ }
+ /* FALL-THROUGH */
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+static GLboolean
+validate_stencil_func(struct gl_context *ctx, GLenum func)
+{
+ switch (func) {
+ case GL_NEVER:
+ case GL_LESS:
+ case GL_LEQUAL:
+ case GL_GREATER:
+ case GL_GEQUAL:
+ case GL_EQUAL:
+ case GL_NOTEQUAL:
+ case GL_ALWAYS:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Set the clear value for the stencil buffer.
+ *
+ * \param s clear value.
+ *
+ * \sa glClearStencil().
+ *
+ * Updates gl_stencil_attrib::Clear. On change
+ * flushes the vertices and notifies the driver via
+ * the dd_function_table::ClearStencil callback.
+ */
+void GLAPIENTRY
+_mesa_ClearStencil( GLint s )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (ctx->Stencil.Clear == (GLuint) s)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.Clear = (GLuint) s;
+
+ if (ctx->Driver.ClearStencil) {
+ ctx->Driver.ClearStencil( ctx, s );
+ }
+}
+
+
+/**
+ * Set the function and reference value for stencil testing.
+ *
+ * \param frontfunc front test function.
+ * \param backfunc back test function.
+ * \param ref front and back reference value.
+ * \param mask front and back bitmask.
+ *
+ * \sa glStencilFunc().
+ *
+ * Verifies the parameters and updates the respective values in
+ * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies the
+ * driver via the dd_function_table::StencilFunc callback.
+ */
+void GLAPIENTRY
+_mesa_StencilFuncSeparateATI( GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ const GLint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glStencilFuncSeparateATI()\n");
+
+ if (!validate_stencil_func(ctx, frontfunc)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glStencilFuncSeparateATI(frontfunc)");
+ return;
+ }
+ if (!validate_stencil_func(ctx, backfunc)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glStencilFuncSeparateATI(backfunc)");
+ return;
+ }
+
+ ref = CLAMP( ref, 0, stencilMax );
+
+ /* set both front and back state */
+ if (ctx->Stencil.Function[0] == frontfunc &&
+ ctx->Stencil.Function[1] == backfunc &&
+ ctx->Stencil.ValueMask[0] == mask &&
+ ctx->Stencil.ValueMask[1] == mask &&
+ ctx->Stencil.Ref[0] == ref &&
+ ctx->Stencil.Ref[1] == ref)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.Function[0] = frontfunc;
+ ctx->Stencil.Function[1] = backfunc;
+ ctx->Stencil.Ref[0] = ctx->Stencil.Ref[1] = ref;
+ ctx->Stencil.ValueMask[0] = ctx->Stencil.ValueMask[1] = mask;
+ if (ctx->Driver.StencilFuncSeparate) {
+ ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
+ frontfunc, ref, mask);
+ ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
+ backfunc, ref, mask);
+ }
+}
+
+
+/**
+ * Set the function and reference value for stencil testing.
+ *
+ * \param func test function.
+ * \param ref reference value.
+ * \param mask bitmask.
+ *
+ * \sa glStencilFunc().
+ *
+ * Verifies the parameters and updates the respective values in
+ * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies the
+ * driver via the dd_function_table::StencilFunc callback.
+ */
+void GLAPIENTRY
+_mesa_StencilFunc( GLenum func, GLint ref, GLuint mask )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ const GLint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
+ const GLint face = ctx->Stencil.ActiveFace;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glStencilFunc()\n");
+
+ if (!validate_stencil_func(ctx, func)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFunc(func)");
+ return;
+ }
+
+ ref = CLAMP( ref, 0, stencilMax );
+
+ if (face != 0) {
+ if (ctx->Stencil.Function[face] == func &&
+ ctx->Stencil.ValueMask[face] == mask &&
+ ctx->Stencil.Ref[face] == ref)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.Function[face] = func;
+ ctx->Stencil.Ref[face] = ref;
+ ctx->Stencil.ValueMask[face] = mask;
+
+ /* Only propagate the change to the driver if EXT_stencil_two_side
+ * is enabled.
+ */
+ if (ctx->Driver.StencilFuncSeparate && ctx->Stencil.TestTwoSide) {
+ ctx->Driver.StencilFuncSeparate(ctx, GL_BACK, func, ref, mask);
+ }
+ }
+ else {
+ /* set both front and back state */
+ if (ctx->Stencil.Function[0] == func &&
+ ctx->Stencil.Function[1] == func &&
+ ctx->Stencil.ValueMask[0] == mask &&
+ ctx->Stencil.ValueMask[1] == mask &&
+ ctx->Stencil.Ref[0] == ref &&
+ ctx->Stencil.Ref[1] == ref)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.Function[0] = ctx->Stencil.Function[1] = func;
+ ctx->Stencil.Ref[0] = ctx->Stencil.Ref[1] = ref;
+ ctx->Stencil.ValueMask[0] = ctx->Stencil.ValueMask[1] = mask;
+ if (ctx->Driver.StencilFuncSeparate) {
+ ctx->Driver.StencilFuncSeparate(ctx,
+ ((ctx->Stencil.TestTwoSide)
+ ? GL_FRONT : GL_FRONT_AND_BACK),
+ func, ref, mask);
+ }
+ }
+}
+
+
+/**
+ * Set the stencil writing mask.
+ *
+ * \param mask bit-mask to enable/disable writing of individual bits in the
+ * stencil planes.
+ *
+ * \sa glStencilMask().
+ *
+ * Updates gl_stencil_attrib::WriteMask. On change flushes the vertices and
+ * notifies the driver via the dd_function_table::StencilMask callback.
+ */
+void GLAPIENTRY
+_mesa_StencilMask( GLuint mask )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ const GLint face = ctx->Stencil.ActiveFace;
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glStencilMask()\n");
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (face != 0) {
+ /* Only modify the EXT_stencil_two_side back-face state.
+ */
+ if (ctx->Stencil.WriteMask[face] == mask)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.WriteMask[face] = mask;
+
+ /* Only propagate the change to the driver if EXT_stencil_two_side
+ * is enabled.
+ */
+ if (ctx->Driver.StencilMaskSeparate && ctx->Stencil.TestTwoSide) {
+ ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, mask);
+ }
+ }
+ else {
+ /* set both front and back state */
+ if (ctx->Stencil.WriteMask[0] == mask &&
+ ctx->Stencil.WriteMask[1] == mask)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.WriteMask[0] = ctx->Stencil.WriteMask[1] = mask;
+ if (ctx->Driver.StencilMaskSeparate) {
+ ctx->Driver.StencilMaskSeparate(ctx,
+ ((ctx->Stencil.TestTwoSide)
+ ? GL_FRONT : GL_FRONT_AND_BACK),
+ mask);
+ }
+ }
+}
+
+
+/**
+ * Set the stencil test actions.
+ *
+ * \param fail action to take when stencil test fails.
+ * \param zfail action to take when stencil test passes, but depth test fails.
+ * \param zpass action to take when stencil test passes and the depth test
+ * passes (or depth testing is not enabled).
+ *
+ * \sa glStencilOp().
+ *
+ * Verifies the parameters and updates the respective fields in
+ * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies the
+ * driver via the dd_function_table::StencilOp callback.
+ */
+void GLAPIENTRY
+_mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ const GLint face = ctx->Stencil.ActiveFace;
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glStencilOp()\n");
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!validate_stencil_op(ctx, fail)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(sfail)");
+ return;
+ }
+ if (!validate_stencil_op(ctx, zfail)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zfail)");
+ return;
+ }
+ if (!validate_stencil_op(ctx, zpass)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zpass)");
+ return;
+ }
+
+ if (face != 0) {
+ /* only set active face state */
+ if (ctx->Stencil.ZFailFunc[face] == zfail &&
+ ctx->Stencil.ZPassFunc[face] == zpass &&
+ ctx->Stencil.FailFunc[face] == fail)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.ZFailFunc[face] = zfail;
+ ctx->Stencil.ZPassFunc[face] = zpass;
+ ctx->Stencil.FailFunc[face] = fail;
+
+ /* Only propagate the change to the driver if EXT_stencil_two_side
+ * is enabled.
+ */
+ if (ctx->Driver.StencilOpSeparate && ctx->Stencil.TestTwoSide) {
+ ctx->Driver.StencilOpSeparate(ctx, GL_BACK, fail, zfail, zpass);
+ }
+ }
+ else {
+ /* set both front and back state */
+ if (ctx->Stencil.ZFailFunc[0] == zfail &&
+ ctx->Stencil.ZFailFunc[1] == zfail &&
+ ctx->Stencil.ZPassFunc[0] == zpass &&
+ ctx->Stencil.ZPassFunc[1] == zpass &&
+ ctx->Stencil.FailFunc[0] == fail &&
+ ctx->Stencil.FailFunc[1] == fail)
+ return;
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.ZFailFunc[0] = ctx->Stencil.ZFailFunc[1] = zfail;
+ ctx->Stencil.ZPassFunc[0] = ctx->Stencil.ZPassFunc[1] = zpass;
+ ctx->Stencil.FailFunc[0] = ctx->Stencil.FailFunc[1] = fail;
+ if (ctx->Driver.StencilOpSeparate) {
+ ctx->Driver.StencilOpSeparate(ctx,
+ ((ctx->Stencil.TestTwoSide)
+ ? GL_FRONT : GL_FRONT_AND_BACK),
+ fail, zfail, zpass);
+ }
+ }
+}
+
+
+
+#if _HAVE_FULL_GL
+/* GL_EXT_stencil_two_side */
+void GLAPIENTRY
+_mesa_ActiveStencilFaceEXT(GLenum face)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glActiveStencilFaceEXT()\n");
+
+ if (!ctx->Extensions.EXT_stencil_two_side) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glActiveStencilFaceEXT");
+ return;
+ }
+
+ if (face == GL_FRONT || face == GL_BACK) {
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.ActiveFace = (face == GL_FRONT) ? 0 : 2;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glActiveStencilFaceEXT(face)");
+ }
+}
+#endif
+
+
+
+/**
+ * OpenGL 2.0 function.
+ * \todo Make StencilOp() call this function. And eventually remove the
+ * ctx->Driver.StencilOp function and use ctx->Driver.StencilOpSeparate
+ * instead.
+ */
+void GLAPIENTRY
+_mesa_StencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass)
+{
+ GLboolean set = GL_FALSE;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glStencilOpSeparate()\n");
+
+ if (!validate_stencil_op(ctx, sfail)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(sfail)");
+ return;
+ }
+ if (!validate_stencil_op(ctx, zfail)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zfail)");
+ return;
+ }
+ if (!validate_stencil_op(ctx, zpass)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zpass)");
+ return;
+ }
+ if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(face)");
+ return;
+ }
+
+ if (face != GL_BACK) {
+ /* set front */
+ if (ctx->Stencil.ZFailFunc[0] != zfail ||
+ ctx->Stencil.ZPassFunc[0] != zpass ||
+ ctx->Stencil.FailFunc[0] != sfail){
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.ZFailFunc[0] = zfail;
+ ctx->Stencil.ZPassFunc[0] = zpass;
+ ctx->Stencil.FailFunc[0] = sfail;
+ set = GL_TRUE;
+ }
+ }
+ if (face != GL_FRONT) {
+ /* set back */
+ if (ctx->Stencil.ZFailFunc[1] != zfail ||
+ ctx->Stencil.ZPassFunc[1] != zpass ||
+ ctx->Stencil.FailFunc[1] != sfail) {
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+ ctx->Stencil.ZFailFunc[1] = zfail;
+ ctx->Stencil.ZPassFunc[1] = zpass;
+ ctx->Stencil.FailFunc[1] = sfail;
+ set = GL_TRUE;
+ }
+ }
+ if (set && ctx->Driver.StencilOpSeparate) {
+ ctx->Driver.StencilOpSeparate(ctx, face, sfail, zfail, zpass);
+ }
+}
+
+
+/* OpenGL 2.0 */
+void GLAPIENTRY
+_mesa_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ const GLint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glStencilFuncSeparate()\n");
+
+ if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(face)");
+ return;
+ }
+ if (!validate_stencil_func(ctx, func)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(func)");
+ return;
+ }
+
+ ref = CLAMP(ref, 0, stencilMax);
+
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+
+ if (face != GL_BACK) {
+ /* set front */
+ ctx->Stencil.Function[0] = func;
+ ctx->Stencil.Ref[0] = ref;
+ ctx->Stencil.ValueMask[0] = mask;
+ }
+ if (face != GL_FRONT) {
+ /* set back */
+ ctx->Stencil.Function[1] = func;
+ ctx->Stencil.Ref[1] = ref;
+ ctx->Stencil.ValueMask[1] = mask;
+ }
+ if (ctx->Driver.StencilFuncSeparate) {
+ ctx->Driver.StencilFuncSeparate(ctx, face, func, ref, mask);
+ }
+}
+
+
+/* OpenGL 2.0 */
+void GLAPIENTRY
+_mesa_StencilMaskSeparate(GLenum face, GLuint mask)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glStencilMaskSeparate()\n");
+
+ if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glStencilaMaskSeparate(face)");
+ return;
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_STENCIL);
+
+ if (face != GL_BACK) {
+ ctx->Stencil.WriteMask[0] = mask;
+ }
+ if (face != GL_FRONT) {
+ ctx->Stencil.WriteMask[1] = mask;
+ }
+ if (ctx->Driver.StencilMaskSeparate) {
+ ctx->Driver.StencilMaskSeparate(ctx, face, mask);
+ }
+}
+
+
+/**
+ * Update derived stencil state.
+ */
+void
+_mesa_update_stencil(struct gl_context *ctx)
+{
+ const GLint face = ctx->Stencil._BackFace;
+
+ ctx->Stencil._Enabled = (ctx->Stencil.Enabled &&
+ ctx->DrawBuffer->Visual.stencilBits > 0);
+
+ ctx->Stencil._TestTwoSide =
+ ctx->Stencil._Enabled &&
+ (ctx->Stencil.Function[0] != ctx->Stencil.Function[face] ||
+ ctx->Stencil.FailFunc[0] != ctx->Stencil.FailFunc[face] ||
+ ctx->Stencil.ZPassFunc[0] != ctx->Stencil.ZPassFunc[face] ||
+ ctx->Stencil.ZFailFunc[0] != ctx->Stencil.ZFailFunc[face] ||
+ ctx->Stencil.Ref[0] != ctx->Stencil.Ref[face] ||
+ ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[face] ||
+ ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[face]);
+}
+
+
+/**
+ * Initialize the context stipple state.
+ *
+ * \param ctx GL context.
+ *
+ * Initializes __struct gl_contextRec::Stencil attribute group.
+ */
+void
+_mesa_init_stencil(struct gl_context *ctx)
+{
+ ctx->Stencil.Enabled = GL_FALSE;
+ ctx->Stencil.TestTwoSide = GL_FALSE;
+ ctx->Stencil.ActiveFace = 0; /* 0 = GL_FRONT, 2 = GL_BACK */
+ ctx->Stencil.Function[0] = GL_ALWAYS;
+ ctx->Stencil.Function[1] = GL_ALWAYS;
+ ctx->Stencil.Function[2] = GL_ALWAYS;
+ ctx->Stencil.FailFunc[0] = GL_KEEP;
+ ctx->Stencil.FailFunc[1] = GL_KEEP;
+ ctx->Stencil.FailFunc[2] = GL_KEEP;
+ ctx->Stencil.ZPassFunc[0] = GL_KEEP;
+ ctx->Stencil.ZPassFunc[1] = GL_KEEP;
+ ctx->Stencil.ZPassFunc[2] = GL_KEEP;
+ ctx->Stencil.ZFailFunc[0] = GL_KEEP;
+ ctx->Stencil.ZFailFunc[1] = GL_KEEP;
+ ctx->Stencil.ZFailFunc[2] = GL_KEEP;
+ ctx->Stencil.Ref[0] = 0;
+ ctx->Stencil.Ref[1] = 0;
+ ctx->Stencil.Ref[2] = 0;
+ ctx->Stencil.ValueMask[0] = ~0U;
+ ctx->Stencil.ValueMask[1] = ~0U;
+ ctx->Stencil.ValueMask[2] = ~0U;
+ ctx->Stencil.WriteMask[0] = ~0U;
+ ctx->Stencil.WriteMask[1] = ~0U;
+ ctx->Stencil.WriteMask[2] = ~0U;
+ ctx->Stencil.Clear = 0;
+ ctx->Stencil._BackFace = 1;
+}
diff --git a/mesalib/src/mesa/main/syncobj.c b/mesalib/src/mesa/main/syncobj.c
index 676038430..25307a17c 100644
--- a/mesalib/src/mesa/main/syncobj.c
+++ b/mesalib/src/mesa/main/syncobj.c
@@ -125,7 +125,7 @@ _mesa_wait_sync(struct gl_context *ctx, struct gl_sync_object *syncObj,
}
-void
+void GLAPIENTRY
_mesa_init_sync_object_functions(struct dd_function_table *driver)
{
driver->NewSyncObject = _mesa_new_sync_object;
@@ -140,7 +140,7 @@ _mesa_init_sync_object_functions(struct dd_function_table *driver)
}
-void
+void GLAPIENTRY
_mesa_init_sync_dispatch(struct _glapi_table *disp)
{
SET_IsSync(disp, _mesa_IsSync);
@@ -156,7 +156,7 @@ _mesa_init_sync_dispatch(struct _glapi_table *disp)
/**
* Allocate/init the context state related to sync objects.
*/
-void
+void GLAPIENTRY
_mesa_init_sync(struct gl_context *ctx)
{
(void) ctx;
@@ -166,7 +166,7 @@ _mesa_init_sync(struct gl_context *ctx)
/**
* Free the context state related to sync objects.
*/
-void
+void GLAPIENTRY
_mesa_free_sync_data(struct gl_context *ctx)
{
(void) ctx;
@@ -182,7 +182,7 @@ _mesa_validate_sync(struct gl_sync_object *syncObj)
}
-void
+void GLAPIENTRY
_mesa_ref_sync_object(struct gl_context *ctx, struct gl_sync_object *syncObj)
{
_glthread_LOCK_MUTEX(ctx->Shared->Mutex);
@@ -191,7 +191,7 @@ _mesa_ref_sync_object(struct gl_context *ctx, struct gl_sync_object *syncObj)
}
-void
+void GLAPIENTRY
_mesa_unref_sync_object(struct gl_context *ctx, struct gl_sync_object *syncObj)
{
_glthread_LOCK_MUTEX(ctx->Shared->Mutex);
diff --git a/mesalib/src/mesa/main/syncobj.h b/mesalib/src/mesa/main/syncobj.h
index ac1384f61..e83ac8b0e 100644
--- a/mesalib/src/mesa/main/syncobj.h
+++ b/mesalib/src/mesa/main/syncobj.h
@@ -41,22 +41,22 @@ struct gl_sync_object;
#if FEATURE_ARB_sync
-extern void
+extern void GLAPIENTRY
_mesa_init_sync_object_functions(struct dd_function_table *driver);
-extern void
+extern void GLAPIENTRY
_mesa_init_sync_dispatch(struct _glapi_table *disp);
-extern void
+extern void GLAPIENTRY
_mesa_init_sync(struct gl_context *);
-extern void
+extern void GLAPIENTRY
_mesa_free_sync_data(struct gl_context *);
-extern void
+extern void GLAPIENTRY
_mesa_ref_sync_object(struct gl_context *ctx, struct gl_sync_object *syncObj);
-extern void
+extern void GLAPIENTRY
_mesa_unref_sync_object(struct gl_context *ctx, struct gl_sync_object *syncObj);
extern GLboolean GLAPIENTRY
diff --git a/mesalib/src/mesa/main/texcompress.c b/mesalib/src/mesa/main/texcompress.c
index 82d02ed0e..9891946df 100644
--- a/mesalib/src/mesa/main/texcompress.c
+++ b/mesalib/src/mesa/main/texcompress.c
@@ -1,269 +1,269 @@
-/*
- * Mesa 3-D graphics library
- * Version: 6.5.1
- *
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- * Copyright (c) 2008 VMware, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file texcompress.c
- * Helper functions for texture compression.
- */
-
-
-#include "glheader.h"
-#include "imports.h"
-#include "colormac.h"
-#include "formats.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "texcompress.h"
-
-
-/**
- * Return list of (and count of) all specific texture compression
- * formats that are supported.
- *
- * \param ctx the GL context
- * \param formats the resulting format list (may be NULL).
- * \param all if true return all formats, even those with some kind
- * of restrictions/limitations (See GL_ARB_texture_compression
- * spec for more info).
- *
- * \return number of formats.
- */
-GLuint
-_mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats, GLboolean all)
-{
- GLuint n = 0;
- if (ctx->Extensions.TDFX_texture_compression_FXT1) {
- if (formats) {
- formats[n++] = GL_COMPRESSED_RGB_FXT1_3DFX;
- formats[n++] = GL_COMPRESSED_RGBA_FXT1_3DFX;
- }
- else {
- n += 2;
- }
- }
- /* don't return RGTC - ARB_texture_compression_rgtc query 19 */
- if (ctx->Extensions.EXT_texture_compression_s3tc) {
- if (formats) {
- formats[n++] = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
- /* This format has some restrictions/limitations and so should
- * not be returned via the GL_COMPRESSED_TEXTURE_FORMATS query.
- * Specifically, all transparent pixels become black. NVIDIA
- * omits this format too.
- */
- if (all)
- formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
- formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
- formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
- }
- else {
- n += 3;
- if (all)
- n += 1;
- }
- }
- if (ctx->Extensions.S3_s3tc) {
- if (formats) {
- formats[n++] = GL_RGB_S3TC;
- formats[n++] = GL_RGB4_S3TC;
- formats[n++] = GL_RGBA_S3TC;
- formats[n++] = GL_RGBA4_S3TC;
- }
- else {
- n += 4;
- }
- }
-#if FEATURE_EXT_texture_sRGB
- if (ctx->Extensions.EXT_texture_sRGB) {
- if (formats) {
- formats[n++] = GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
- formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
- formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
- formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
- }
- else {
- n += 4;
- }
- }
-#endif /* FEATURE_EXT_texture_sRGB */
- return n;
-
-#if FEATURE_ES1 || FEATURE_ES2
- if (formats) {
- formats[n++] = GL_PALETTE4_RGB8_OES;
- formats[n++] = GL_PALETTE4_RGBA8_OES;
- formats[n++] = GL_PALETTE4_R5_G6_B5_OES;
- formats[n++] = GL_PALETTE4_RGBA4_OES;
- formats[n++] = GL_PALETTE4_RGB5_A1_OES;
- formats[n++] = GL_PALETTE8_RGB8_OES;
- formats[n++] = GL_PALETTE8_RGBA8_OES;
- formats[n++] = GL_PALETTE8_R5_G6_B5_OES;
- formats[n++] = GL_PALETTE8_RGBA4_OES;
- formats[n++] = GL_PALETTE8_RGB5_A1_OES;
- }
- else {
- n += 10;
- }
-#endif
-}
-
-
-/**
- * Convert a compressed MESA_FORMAT_x to a GLenum.
- */
-gl_format
-_mesa_glenum_to_compressed_format(GLenum format)
-{
- switch (format) {
- case GL_COMPRESSED_RGB_FXT1_3DFX:
- return MESA_FORMAT_RGB_FXT1;
- case GL_COMPRESSED_RGBA_FXT1_3DFX:
- return MESA_FORMAT_RGBA_FXT1;
-
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- case GL_RGB_S3TC:
- return MESA_FORMAT_RGB_DXT1;
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
- case GL_RGB4_S3TC:
- return MESA_FORMAT_RGBA_DXT1;
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- case GL_RGBA_S3TC:
- return MESA_FORMAT_RGBA_DXT3;
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- case GL_RGBA4_S3TC:
- return MESA_FORMAT_RGBA_DXT5;
-
- case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
- return MESA_FORMAT_SRGB_DXT1;
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
- return MESA_FORMAT_SRGBA_DXT1;
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
- return MESA_FORMAT_SRGBA_DXT3;
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
- return MESA_FORMAT_SRGBA_DXT5;
-
- case GL_COMPRESSED_RED_RGTC1:
- return MESA_FORMAT_RED_RGTC1;
- case GL_COMPRESSED_SIGNED_RED_RGTC1:
- return MESA_FORMAT_SIGNED_RED_RGTC1;
- case GL_COMPRESSED_RG_RGTC2:
- return MESA_FORMAT_RG_RGTC2;
- case GL_COMPRESSED_SIGNED_RG_RGTC2:
- return MESA_FORMAT_SIGNED_RG_RGTC2;
-
- default:
- return MESA_FORMAT_NONE;
- }
-}
-
-
-/**
- * Given a compressed MESA_FORMAT_x value, return the corresponding
- * GLenum for that format.
- * This is needed for glGetTexLevelParameter(GL_TEXTURE_INTERNAL_FORMAT)
- * which must return the specific texture format used when the user might
- * have originally specified a generic compressed format in their
- * glTexImage2D() call.
- * For non-compressed textures, we always return the user-specified
- * internal format unchanged.
- */
-GLenum
-_mesa_compressed_format_to_glenum(struct gl_context *ctx, GLuint mesaFormat)
-{
- switch (mesaFormat) {
-#if FEATURE_texture_fxt1
- case MESA_FORMAT_RGB_FXT1:
- return GL_COMPRESSED_RGB_FXT1_3DFX;
- case MESA_FORMAT_RGBA_FXT1:
- return GL_COMPRESSED_RGBA_FXT1_3DFX;
-#endif
-#if FEATURE_texture_s3tc
- case MESA_FORMAT_RGB_DXT1:
- return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
- case MESA_FORMAT_RGBA_DXT1:
- return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
- case MESA_FORMAT_RGBA_DXT3:
- return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
- case MESA_FORMAT_RGBA_DXT5:
- return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGB_DXT1:
- return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
- case MESA_FORMAT_SRGBA_DXT1:
- return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
- case MESA_FORMAT_SRGBA_DXT3:
- return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
- case MESA_FORMAT_SRGBA_DXT5:
- return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
-#endif
-#endif
-
- case MESA_FORMAT_RED_RGTC1:
- return GL_COMPRESSED_RED_RGTC1;
- case MESA_FORMAT_SIGNED_RED_RGTC1:
- return GL_COMPRESSED_SIGNED_RED_RGTC1;
- case MESA_FORMAT_RG_RGTC2:
- return GL_COMPRESSED_RG_RGTC2;
- case MESA_FORMAT_SIGNED_RG_RGTC2:
- return GL_COMPRESSED_SIGNED_RG_RGTC2;
-
- default:
- _mesa_problem(ctx, "Unexpected mesa texture format in"
- " _mesa_compressed_format_to_glenum()");
- return 0;
- }
-}
-
-
-/*
- * Return the address of the pixel at (col, row, img) in a
- * compressed texture image.
- * \param col, row, img - image position (3D), should be a multiple of the
- * format's block size.
- * \param format - compressed image format
- * \param width - image width (stride) in pixels
- * \param image - the image address
- * \return address of pixel at (row, col, img)
- */
-GLubyte *
-_mesa_compressed_image_address(GLint col, GLint row, GLint img,
- gl_format mesaFormat,
- GLsizei width, const GLubyte *image)
-{
- /* XXX only 2D images implemented, not 3D */
- const GLuint blockSize = _mesa_get_format_bytes(mesaFormat);
- GLuint bw, bh;
- GLint offset;
-
- _mesa_get_format_block_size(mesaFormat, &bw, &bh);
-
- ASSERT(col % bw == 0);
- ASSERT(row % bh == 0);
-
- offset = ((width + bw - 1) / bw) * (row / bh) + col / bw;
- offset *= blockSize;
-
- return (GLubyte *) image + offset;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5.1
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file texcompress.c
+ * Helper functions for texture compression.
+ */
+
+
+#include "glheader.h"
+#include "imports.h"
+#include "colormac.h"
+#include "formats.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "texcompress.h"
+
+
+/**
+ * Return list of (and count of) all specific texture compression
+ * formats that are supported.
+ *
+ * \param ctx the GL context
+ * \param formats the resulting format list (may be NULL).
+ * \param all if true return all formats, even those with some kind
+ * of restrictions/limitations (See GL_ARB_texture_compression
+ * spec for more info).
+ *
+ * \return number of formats.
+ */
+GLuint
+_mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats, GLboolean all)
+{
+ GLuint n = 0;
+ if (ctx->Extensions.TDFX_texture_compression_FXT1) {
+ if (formats) {
+ formats[n++] = GL_COMPRESSED_RGB_FXT1_3DFX;
+ formats[n++] = GL_COMPRESSED_RGBA_FXT1_3DFX;
+ }
+ else {
+ n += 2;
+ }
+ }
+ /* don't return RGTC - ARB_texture_compression_rgtc query 19 */
+ if (ctx->Extensions.EXT_texture_compression_s3tc) {
+ if (formats) {
+ formats[n++] = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
+ /* This format has some restrictions/limitations and so should
+ * not be returned via the GL_COMPRESSED_TEXTURE_FORMATS query.
+ * Specifically, all transparent pixels become black. NVIDIA
+ * omits this format too.
+ */
+ if (all)
+ formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
+ formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
+ formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
+ }
+ else {
+ n += 3;
+ if (all)
+ n += 1;
+ }
+ }
+ if (ctx->Extensions.S3_s3tc) {
+ if (formats) {
+ formats[n++] = GL_RGB_S3TC;
+ formats[n++] = GL_RGB4_S3TC;
+ formats[n++] = GL_RGBA_S3TC;
+ formats[n++] = GL_RGBA4_S3TC;
+ }
+ else {
+ n += 4;
+ }
+ }
+#if FEATURE_EXT_texture_sRGB
+ if (ctx->Extensions.EXT_texture_sRGB) {
+ if (formats) {
+ formats[n++] = GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
+ formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
+ formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
+ formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
+ }
+ else {
+ n += 4;
+ }
+ }
+#endif /* FEATURE_EXT_texture_sRGB */
+ return n;
+
+#if FEATURE_ES1 || FEATURE_ES2
+ if (formats) {
+ formats[n++] = GL_PALETTE4_RGB8_OES;
+ formats[n++] = GL_PALETTE4_RGBA8_OES;
+ formats[n++] = GL_PALETTE4_R5_G6_B5_OES;
+ formats[n++] = GL_PALETTE4_RGBA4_OES;
+ formats[n++] = GL_PALETTE4_RGB5_A1_OES;
+ formats[n++] = GL_PALETTE8_RGB8_OES;
+ formats[n++] = GL_PALETTE8_RGBA8_OES;
+ formats[n++] = GL_PALETTE8_R5_G6_B5_OES;
+ formats[n++] = GL_PALETTE8_RGBA4_OES;
+ formats[n++] = GL_PALETTE8_RGB5_A1_OES;
+ }
+ else {
+ n += 10;
+ }
+#endif
+}
+
+
+/**
+ * Convert a compressed MESA_FORMAT_x to a GLenum.
+ */
+gl_format
+_mesa_glenum_to_compressed_format(GLenum format)
+{
+ switch (format) {
+ case GL_COMPRESSED_RGB_FXT1_3DFX:
+ return MESA_FORMAT_RGB_FXT1;
+ case GL_COMPRESSED_RGBA_FXT1_3DFX:
+ return MESA_FORMAT_RGBA_FXT1;
+
+ case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+ case GL_RGB_S3TC:
+ return MESA_FORMAT_RGB_DXT1;
+ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+ case GL_RGB4_S3TC:
+ return MESA_FORMAT_RGBA_DXT1;
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ case GL_RGBA_S3TC:
+ return MESA_FORMAT_RGBA_DXT3;
+ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+ case GL_RGBA4_S3TC:
+ return MESA_FORMAT_RGBA_DXT5;
+
+ case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
+ return MESA_FORMAT_SRGB_DXT1;
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
+ return MESA_FORMAT_SRGBA_DXT1;
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
+ return MESA_FORMAT_SRGBA_DXT3;
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
+ return MESA_FORMAT_SRGBA_DXT5;
+
+ case GL_COMPRESSED_RED_RGTC1:
+ return MESA_FORMAT_RED_RGTC1;
+ case GL_COMPRESSED_SIGNED_RED_RGTC1:
+ return MESA_FORMAT_SIGNED_RED_RGTC1;
+ case GL_COMPRESSED_RG_RGTC2:
+ return MESA_FORMAT_RG_RGTC2;
+ case GL_COMPRESSED_SIGNED_RG_RGTC2:
+ return MESA_FORMAT_SIGNED_RG_RGTC2;
+
+ default:
+ return MESA_FORMAT_NONE;
+ }
+}
+
+
+/**
+ * Given a compressed MESA_FORMAT_x value, return the corresponding
+ * GLenum for that format.
+ * This is needed for glGetTexLevelParameter(GL_TEXTURE_INTERNAL_FORMAT)
+ * which must return the specific texture format used when the user might
+ * have originally specified a generic compressed format in their
+ * glTexImage2D() call.
+ * For non-compressed textures, we always return the user-specified
+ * internal format unchanged.
+ */
+GLenum
+_mesa_compressed_format_to_glenum(struct gl_context *ctx, GLuint mesaFormat)
+{
+ switch (mesaFormat) {
+#if FEATURE_texture_fxt1
+ case MESA_FORMAT_RGB_FXT1:
+ return GL_COMPRESSED_RGB_FXT1_3DFX;
+ case MESA_FORMAT_RGBA_FXT1:
+ return GL_COMPRESSED_RGBA_FXT1_3DFX;
+#endif
+#if FEATURE_texture_s3tc
+ case MESA_FORMAT_RGB_DXT1:
+ return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
+ case MESA_FORMAT_RGBA_DXT1:
+ return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
+ case MESA_FORMAT_RGBA_DXT3:
+ return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
+ case MESA_FORMAT_RGBA_DXT5:
+ return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
+#if FEATURE_EXT_texture_sRGB
+ case MESA_FORMAT_SRGB_DXT1:
+ return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
+ case MESA_FORMAT_SRGBA_DXT1:
+ return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
+ case MESA_FORMAT_SRGBA_DXT3:
+ return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
+ case MESA_FORMAT_SRGBA_DXT5:
+ return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
+#endif
+#endif
+
+ case MESA_FORMAT_RED_RGTC1:
+ return GL_COMPRESSED_RED_RGTC1;
+ case MESA_FORMAT_SIGNED_RED_RGTC1:
+ return GL_COMPRESSED_SIGNED_RED_RGTC1;
+ case MESA_FORMAT_RG_RGTC2:
+ return GL_COMPRESSED_RG_RGTC2;
+ case MESA_FORMAT_SIGNED_RG_RGTC2:
+ return GL_COMPRESSED_SIGNED_RG_RGTC2;
+
+ default:
+ _mesa_problem(ctx, "Unexpected mesa texture format in"
+ " _mesa_compressed_format_to_glenum()");
+ return 0;
+ }
+}
+
+
+/*
+ * Return the address of the pixel at (col, row, img) in a
+ * compressed texture image.
+ * \param col, row, img - image position (3D), should be a multiple of the
+ * format's block size.
+ * \param format - compressed image format
+ * \param width - image width (stride) in pixels
+ * \param image - the image address
+ * \return address of pixel at (row, col, img)
+ */
+GLubyte *
+_mesa_compressed_image_address(GLint col, GLint row, GLint img,
+ gl_format mesaFormat,
+ GLsizei width, const GLubyte *image)
+{
+ /* XXX only 2D images implemented, not 3D */
+ const GLuint blockSize = _mesa_get_format_bytes(mesaFormat);
+ GLuint bw, bh;
+ GLint offset;
+
+ _mesa_get_format_block_size(mesaFormat, &bw, &bh);
+
+ ASSERT(col % bw == 0);
+ ASSERT(row % bh == 0);
+
+ offset = ((width + bw - 1) / bw) * (row / bh) + col / bw;
+ offset *= blockSize;
+
+ return (GLubyte *) image + offset;
+}
diff --git a/mesalib/src/mesa/main/texcompress_rgtc.c b/mesalib/src/mesa/main/texcompress_rgtc.c
index 26dca2d76..b5dd56dce 100644
--- a/mesalib/src/mesa/main/texcompress_rgtc.c
+++ b/mesalib/src/mesa/main/texcompress_rgtc.c
@@ -1,400 +1,400 @@
-/*
- * Copyright (C) 2011 Red Hat Inc.
- *
- * block compression parts are:
- * Copyright (C) 2004 Roland Scheidegger All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Author:
- * Dave Airlie
- */
-
-/**
- * \file texcompress_rgtc.c
- * GL_EXT_texture_compression_rgtc support.
- */
-
-
-#include "glheader.h"
-#include "imports.h"
-#include "colormac.h"
-#include "image.h"
-#include "macros.h"
-#include "mfeatures.h"
-#include "mipmap.h"
-#include "texcompress.h"
-#include "texcompress_rgtc.h"
-#include "texstore.h"
-
-#define RGTC_DEBUG 0
-
-static void unsigned_encode_rgtc_chan(GLubyte *blkaddr, GLubyte srccolors[4][4],
- GLint numxpixels, GLint numypixels);
-static void signed_encode_rgtc_chan(GLbyte *blkaddr, GLbyte srccolors[4][4],
- GLint numxpixels, GLint numypixels);
-
-static void unsigned_fetch_texel_rgtc(unsigned srcRowStride, const GLubyte *pixdata,
- unsigned i, unsigned j, GLubyte *value, unsigned comps);
-
-static void signed_fetch_texel_rgtc(unsigned srcRowStride, const GLbyte *pixdata,
- unsigned i, unsigned j, GLbyte *value, unsigned comps);
-
-static void extractsrc_u( GLubyte srcpixels[4][4], const GLchan *srcaddr,
- GLint srcRowStride, GLint numxpixels, GLint numypixels, GLint comps)
-{
- GLubyte i, j;
- const GLchan *curaddr;
- for (j = 0; j < numypixels; j++) {
- curaddr = srcaddr + j * srcRowStride * comps;
- for (i = 0; i < numxpixels; i++) {
- srcpixels[j][i] = *curaddr / (CHAN_MAX / 255);
- curaddr += comps;
- }
- }
-}
-
-static void extractsrc_s( GLbyte srcpixels[4][4], const GLfloat *srcaddr,
- GLint srcRowStride, GLint numxpixels, GLint numypixels, GLint comps)
-{
- GLubyte i, j;
- const GLfloat *curaddr;
- for (j = 0; j < numypixels; j++) {
- curaddr = srcaddr + j * srcRowStride * comps;
- for (i = 0; i < numxpixels; i++) {
- srcpixels[j][i] = FLOAT_TO_BYTE_TEX(*curaddr);
- curaddr += comps;
- }
- }
-}
-
-
-GLboolean
-_mesa_texstore_red_rgtc1(TEXSTORE_PARAMS)
-{
- GLubyte *dst;
- const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
- const GLchan *tempImage = NULL;
- int i, j;
- int numxpixels, numypixels;
- const GLchan *srcaddr;
- GLubyte srcpixels[4][4];
- GLubyte *blkaddr;
- GLint dstRowDiff;
- ASSERT(dstFormat == MESA_FORMAT_RED_RGTC1);
- ASSERT(dstXoffset % 4 == 0);
- ASSERT(dstYoffset % 4 == 0);
- ASSERT(dstZoffset % 4 == 0);
- (void) dstZoffset;
- (void) dstImageOffsets;
-
-
- tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- _mesa_get_format_base_format(dstFormat),
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- if (!tempImage)
- return GL_FALSE; /* out of memory */
-
- dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- dstFormat,
- texWidth, (GLubyte *) dstAddr);
-
- blkaddr = dst;
- dstRowDiff = dstRowStride >= (srcWidth * 4) ? dstRowStride - (((srcWidth + 3) & ~3) * 4) : 0;
- for (j = 0; j < srcHeight; j+=4) {
- if (srcHeight > j + 3) numypixels = 4;
- else numypixels = srcHeight - j;
- srcaddr = tempImage + j * srcWidth;
- for (i = 0; i < srcWidth; i += 4) {
- if (srcWidth > i + 3) numxpixels = 4;
- else numxpixels = srcWidth - i;
- extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1);
- unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
- srcaddr += numxpixels;
- blkaddr += 8;
- }
- blkaddr += dstRowDiff;
- }
- if (tempImage)
- free((void *) tempImage);
-
- return GL_TRUE;
-}
-
-GLboolean
-_mesa_texstore_signed_red_rgtc1(TEXSTORE_PARAMS)
-{
- GLbyte *dst;
- const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
- const GLfloat *tempImage = NULL;
- int i, j;
- int numxpixels, numypixels;
- const GLfloat *srcaddr;
- GLbyte srcpixels[4][4];
- GLbyte *blkaddr;
- GLint dstRowDiff;
- ASSERT(dstFormat == MESA_FORMAT_SIGNED_RED_RGTC1);
- ASSERT(dstXoffset % 4 == 0);
- ASSERT(dstYoffset % 4 == 0);
- ASSERT(dstZoffset % 4 == 0);
- (void) dstZoffset;
- (void) dstImageOffsets;
-
- tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- _mesa_get_format_base_format(dstFormat),
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking, 0x0);
- if (!tempImage)
- return GL_FALSE; /* out of memory */
-
- dst = (GLbyte *)_mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- dstFormat,
- texWidth, (GLubyte *) dstAddr);
-
- blkaddr = dst;
- dstRowDiff = dstRowStride >= (srcWidth * 4) ? dstRowStride - (((srcWidth + 3) & ~3) * 4) : 0;
- for (j = 0; j < srcHeight; j+=4) {
- if (srcHeight > j + 3) numypixels = 4;
- else numypixels = srcHeight - j;
- srcaddr = tempImage + j * srcWidth;
- for (i = 0; i < srcWidth; i += 4) {
- if (srcWidth > i + 3) numxpixels = 4;
- else numxpixels = srcWidth - i;
- extractsrc_s(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1);
- signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
- srcaddr += numxpixels;
- blkaddr += 8;
- }
- blkaddr += dstRowDiff;
- }
- if (tempImage)
- free((void *) tempImage);
-
- return GL_TRUE;
-}
-
-GLboolean
-_mesa_texstore_rg_rgtc2(TEXSTORE_PARAMS)
-{
- GLubyte *dst;
- const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
- const GLchan *tempImage = NULL;
- int i, j;
- int numxpixels, numypixels;
- const GLchan *srcaddr;
- GLubyte srcpixels[4][4];
- GLubyte *blkaddr;
- GLint dstRowDiff;
-
- ASSERT(dstFormat == MESA_FORMAT_RG_RGTC2);
- ASSERT(dstXoffset % 4 == 0);
- ASSERT(dstYoffset % 4 == 0);
- ASSERT(dstZoffset % 4 == 0);
- (void) dstZoffset;
- (void) dstImageOffsets;
-
- tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- _mesa_get_format_base_format(dstFormat),
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- if (!tempImage)
- return GL_FALSE; /* out of memory */
-
- dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- dstFormat,
- texWidth, (GLubyte *) dstAddr);
-
- blkaddr = dst;
- dstRowDiff = dstRowStride >= (srcWidth * 8) ? dstRowStride - (((srcWidth + 7) & ~7) * 8) : 0;
- for (j = 0; j < srcHeight; j+=4) {
- if (srcHeight > j + 3) numypixels = 4;
- else numypixels = srcHeight - j;
- srcaddr = tempImage + j * srcWidth * 2;
- for (i = 0; i < srcWidth; i += 4) {
- if (srcWidth > i + 3) numxpixels = 4;
- else numxpixels = srcWidth - i;
- extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2);
- unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
-
- blkaddr += 8;
- extractsrc_u(srcpixels, (GLchan *)srcaddr + 1, srcWidth, numxpixels, numypixels, 2);
- unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
-
- blkaddr += 8;
-
- srcaddr += numxpixels * 2;
- }
- blkaddr += dstRowDiff;
- }
- if (tempImage)
- free((void *) tempImage);
-
- return GL_TRUE;
-}
-
-GLboolean
-_mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS)
-{
- GLbyte *dst;
- const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
- const GLfloat *tempImage = NULL;
- int i, j;
- int numxpixels, numypixels;
- const GLfloat *srcaddr;
- GLbyte srcpixels[4][4];
- GLbyte *blkaddr;
- GLint dstRowDiff;
-
- ASSERT(dstFormat == MESA_FORMAT_SIGNED_RG_RGTC2);
- ASSERT(dstXoffset % 4 == 0);
- ASSERT(dstYoffset % 4 == 0);
- ASSERT(dstZoffset % 4 == 0);
- (void) dstZoffset;
- (void) dstImageOffsets;
-
- tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- _mesa_get_format_base_format(dstFormat),
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking, 0x0);
- if (!tempImage)
- return GL_FALSE; /* out of memory */
-
- dst = (GLbyte *)_mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- dstFormat,
- texWidth, (GLubyte *) dstAddr);
-
- blkaddr = dst;
- dstRowDiff = dstRowStride >= (srcWidth * 8) ? dstRowStride - (((srcWidth + 7) & ~7) * 8) : 0;
- for (j = 0; j < srcHeight; j += 4) {
- if (srcHeight > j + 3) numypixels = 4;
- else numypixels = srcHeight - j;
- srcaddr = tempImage + j * srcWidth * 2;
- for (i = 0; i < srcWidth; i += 4) {
- if (srcWidth > i + 3) numxpixels = 4;
- else numxpixels = srcWidth - i;
-
- extractsrc_s(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2);
- signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
- blkaddr += 8;
-
- extractsrc_s(srcpixels, srcaddr + 1, srcWidth, numxpixels, numypixels, 2);
- signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
- blkaddr += 8;
-
- srcaddr += numxpixels * 2;
-
- }
- blkaddr += dstRowDiff;
- }
- if (tempImage)
- free((void *) tempImage);
-
- return GL_TRUE;
-}
-
-void
-_mesa_fetch_texel_2d_f_red_rgtc1(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- GLubyte red;
- unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data),
- i, j, &red, 1);
- texel[RCOMP] = UBYTE_TO_FLOAT(red);
- texel[GCOMP] = 0.0;
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 1.0;
-}
-
-void
-_mesa_fetch_texel_2d_f_signed_red_rgtc1(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- GLbyte red;
- signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
- i, j, &red, 1);
- texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
- texel[GCOMP] = 0.0;
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 1.0;
-}
-
-void
-_mesa_fetch_texel_2d_f_rg_rgtc2(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- GLubyte red, green;
- unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data),
- i, j, &red, 2);
- unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data) + 8,
- i, j, &green, 2);
- texel[RCOMP] = UBYTE_TO_FLOAT(red);
- texel[GCOMP] = UBYTE_TO_FLOAT(green);
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 1.0;
-}
-
-void
-_mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- GLbyte red, green;
- signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
- i, j, &red, 2);
- signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8,
- i, j, &green, 2);
- texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
- texel[GCOMP] = BYTE_TO_FLOAT_TEX(green);
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 1.0;
-}
-
-#define TAG(x) unsigned_##x
-
-#define TYPE GLubyte
-#define T_MIN 0
-#define T_MAX 0xff
-
-#include "texcompress_rgtc_tmp.h"
-
-#undef TAG
-#undef TYPE
-#undef T_MIN
-#undef T_MAX
-
-#define TAG(x) signed_##x
-#define TYPE GLbyte
-#define T_MIN (GLbyte)-128
-#define T_MAX (GLbyte)127
-
-#include "texcompress_rgtc_tmp.h"
-
-#undef TAG
-#undef TYPE
-#undef T_MIN
-#undef T_MAX
+/*
+ * Copyright (C) 2011 Red Hat Inc.
+ *
+ * block compression parts are:
+ * Copyright (C) 2004 Roland Scheidegger All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author:
+ * Dave Airlie
+ */
+
+/**
+ * \file texcompress_rgtc.c
+ * GL_EXT_texture_compression_rgtc support.
+ */
+
+
+#include "glheader.h"
+#include "imports.h"
+#include "colormac.h"
+#include "image.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "mipmap.h"
+#include "texcompress.h"
+#include "texcompress_rgtc.h"
+#include "texstore.h"
+
+#define RGTC_DEBUG 0
+
+static void unsigned_encode_rgtc_chan(GLubyte *blkaddr, GLubyte srccolors[4][4],
+ GLint numxpixels, GLint numypixels);
+static void signed_encode_rgtc_chan(GLbyte *blkaddr, GLbyte srccolors[4][4],
+ GLint numxpixels, GLint numypixels);
+
+static void unsigned_fetch_texel_rgtc(unsigned srcRowStride, const GLubyte *pixdata,
+ unsigned i, unsigned j, GLubyte *value, unsigned comps);
+
+static void signed_fetch_texel_rgtc(unsigned srcRowStride, const GLbyte *pixdata,
+ unsigned i, unsigned j, GLbyte *value, unsigned comps);
+
+static void extractsrc_u( GLubyte srcpixels[4][4], const GLchan *srcaddr,
+ GLint srcRowStride, GLint numxpixels, GLint numypixels, GLint comps)
+{
+ GLubyte i, j;
+ const GLchan *curaddr;
+ for (j = 0; j < numypixels; j++) {
+ curaddr = srcaddr + j * srcRowStride * comps;
+ for (i = 0; i < numxpixels; i++) {
+ srcpixels[j][i] = *curaddr / (CHAN_MAX / 255);
+ curaddr += comps;
+ }
+ }
+}
+
+static void extractsrc_s( GLbyte srcpixels[4][4], const GLfloat *srcaddr,
+ GLint srcRowStride, GLint numxpixels, GLint numypixels, GLint comps)
+{
+ GLubyte i, j;
+ const GLfloat *curaddr;
+ for (j = 0; j < numypixels; j++) {
+ curaddr = srcaddr + j * srcRowStride * comps;
+ for (i = 0; i < numxpixels; i++) {
+ srcpixels[j][i] = FLOAT_TO_BYTE_TEX(*curaddr);
+ curaddr += comps;
+ }
+ }
+}
+
+
+GLboolean
+_mesa_texstore_red_rgtc1(TEXSTORE_PARAMS)
+{
+ GLubyte *dst;
+ const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
+ const GLchan *tempImage = NULL;
+ int i, j;
+ int numxpixels, numypixels;
+ const GLchan *srcaddr;
+ GLubyte srcpixels[4][4];
+ GLubyte *blkaddr;
+ GLint dstRowDiff;
+ ASSERT(dstFormat == MESA_FORMAT_RED_RGTC1);
+ ASSERT(dstXoffset % 4 == 0);
+ ASSERT(dstYoffset % 4 == 0);
+ ASSERT(dstZoffset % 4 == 0);
+ (void) dstZoffset;
+ (void) dstImageOffsets;
+
+
+ tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ _mesa_get_format_base_format(dstFormat),
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ if (!tempImage)
+ return GL_FALSE; /* out of memory */
+
+ dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
+ dstFormat,
+ texWidth, (GLubyte *) dstAddr);
+
+ blkaddr = dst;
+ dstRowDiff = dstRowStride >= (srcWidth * 4) ? dstRowStride - (((srcWidth + 3) & ~3) * 4) : 0;
+ for (j = 0; j < srcHeight; j+=4) {
+ if (srcHeight > j + 3) numypixels = 4;
+ else numypixels = srcHeight - j;
+ srcaddr = tempImage + j * srcWidth;
+ for (i = 0; i < srcWidth; i += 4) {
+ if (srcWidth > i + 3) numxpixels = 4;
+ else numxpixels = srcWidth - i;
+ extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1);
+ unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
+ srcaddr += numxpixels;
+ blkaddr += 8;
+ }
+ blkaddr += dstRowDiff;
+ }
+ if (tempImage)
+ free((void *) tempImage);
+
+ return GL_TRUE;
+}
+
+GLboolean
+_mesa_texstore_signed_red_rgtc1(TEXSTORE_PARAMS)
+{
+ GLbyte *dst;
+ const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
+ const GLfloat *tempImage = NULL;
+ int i, j;
+ int numxpixels, numypixels;
+ const GLfloat *srcaddr;
+ GLbyte srcpixels[4][4];
+ GLbyte *blkaddr;
+ GLint dstRowDiff;
+ ASSERT(dstFormat == MESA_FORMAT_SIGNED_RED_RGTC1);
+ ASSERT(dstXoffset % 4 == 0);
+ ASSERT(dstYoffset % 4 == 0);
+ ASSERT(dstZoffset % 4 == 0);
+ (void) dstZoffset;
+ (void) dstImageOffsets;
+
+ tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ _mesa_get_format_base_format(dstFormat),
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking, 0x0);
+ if (!tempImage)
+ return GL_FALSE; /* out of memory */
+
+ dst = (GLbyte *)_mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
+ dstFormat,
+ texWidth, (GLubyte *) dstAddr);
+
+ blkaddr = dst;
+ dstRowDiff = dstRowStride >= (srcWidth * 4) ? dstRowStride - (((srcWidth + 3) & ~3) * 4) : 0;
+ for (j = 0; j < srcHeight; j+=4) {
+ if (srcHeight > j + 3) numypixels = 4;
+ else numypixels = srcHeight - j;
+ srcaddr = tempImage + j * srcWidth;
+ for (i = 0; i < srcWidth; i += 4) {
+ if (srcWidth > i + 3) numxpixels = 4;
+ else numxpixels = srcWidth - i;
+ extractsrc_s(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1);
+ signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
+ srcaddr += numxpixels;
+ blkaddr += 8;
+ }
+ blkaddr += dstRowDiff;
+ }
+ if (tempImage)
+ free((void *) tempImage);
+
+ return GL_TRUE;
+}
+
+GLboolean
+_mesa_texstore_rg_rgtc2(TEXSTORE_PARAMS)
+{
+ GLubyte *dst;
+ const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
+ const GLchan *tempImage = NULL;
+ int i, j;
+ int numxpixels, numypixels;
+ const GLchan *srcaddr;
+ GLubyte srcpixels[4][4];
+ GLubyte *blkaddr;
+ GLint dstRowDiff;
+
+ ASSERT(dstFormat == MESA_FORMAT_RG_RGTC2);
+ ASSERT(dstXoffset % 4 == 0);
+ ASSERT(dstYoffset % 4 == 0);
+ ASSERT(dstZoffset % 4 == 0);
+ (void) dstZoffset;
+ (void) dstImageOffsets;
+
+ tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ _mesa_get_format_base_format(dstFormat),
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ if (!tempImage)
+ return GL_FALSE; /* out of memory */
+
+ dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
+ dstFormat,
+ texWidth, (GLubyte *) dstAddr);
+
+ blkaddr = dst;
+ dstRowDiff = dstRowStride >= (srcWidth * 8) ? dstRowStride - (((srcWidth + 7) & ~7) * 8) : 0;
+ for (j = 0; j < srcHeight; j+=4) {
+ if (srcHeight > j + 3) numypixels = 4;
+ else numypixels = srcHeight - j;
+ srcaddr = tempImage + j * srcWidth * 2;
+ for (i = 0; i < srcWidth; i += 4) {
+ if (srcWidth > i + 3) numxpixels = 4;
+ else numxpixels = srcWidth - i;
+ extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2);
+ unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
+
+ blkaddr += 8;
+ extractsrc_u(srcpixels, (GLchan *)srcaddr + 1, srcWidth, numxpixels, numypixels, 2);
+ unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
+
+ blkaddr += 8;
+
+ srcaddr += numxpixels * 2;
+ }
+ blkaddr += dstRowDiff;
+ }
+ if (tempImage)
+ free((void *) tempImage);
+
+ return GL_TRUE;
+}
+
+GLboolean
+_mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS)
+{
+ GLbyte *dst;
+ const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
+ const GLfloat *tempImage = NULL;
+ int i, j;
+ int numxpixels, numypixels;
+ const GLfloat *srcaddr;
+ GLbyte srcpixels[4][4];
+ GLbyte *blkaddr;
+ GLint dstRowDiff;
+
+ ASSERT(dstFormat == MESA_FORMAT_SIGNED_RG_RGTC2);
+ ASSERT(dstXoffset % 4 == 0);
+ ASSERT(dstYoffset % 4 == 0);
+ ASSERT(dstZoffset % 4 == 0);
+ (void) dstZoffset;
+ (void) dstImageOffsets;
+
+ tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ _mesa_get_format_base_format(dstFormat),
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking, 0x0);
+ if (!tempImage)
+ return GL_FALSE; /* out of memory */
+
+ dst = (GLbyte *)_mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
+ dstFormat,
+ texWidth, (GLubyte *) dstAddr);
+
+ blkaddr = dst;
+ dstRowDiff = dstRowStride >= (srcWidth * 8) ? dstRowStride - (((srcWidth + 7) & ~7) * 8) : 0;
+ for (j = 0; j < srcHeight; j += 4) {
+ if (srcHeight > j + 3) numypixels = 4;
+ else numypixels = srcHeight - j;
+ srcaddr = tempImage + j * srcWidth * 2;
+ for (i = 0; i < srcWidth; i += 4) {
+ if (srcWidth > i + 3) numxpixels = 4;
+ else numxpixels = srcWidth - i;
+
+ extractsrc_s(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2);
+ signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
+ blkaddr += 8;
+
+ extractsrc_s(srcpixels, srcaddr + 1, srcWidth, numxpixels, numypixels, 2);
+ signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels);
+ blkaddr += 8;
+
+ srcaddr += numxpixels * 2;
+
+ }
+ blkaddr += dstRowDiff;
+ }
+ if (tempImage)
+ free((void *) tempImage);
+
+ return GL_TRUE;
+}
+
+void
+_mesa_fetch_texel_2d_f_red_rgtc1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ GLubyte red;
+ unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data),
+ i, j, &red, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT(red);
+ texel[GCOMP] = 0.0;
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 1.0;
+}
+
+void
+_mesa_fetch_texel_2d_f_signed_red_rgtc1(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ GLbyte red;
+ signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
+ i, j, &red, 1);
+ texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
+ texel[GCOMP] = 0.0;
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 1.0;
+}
+
+void
+_mesa_fetch_texel_2d_f_rg_rgtc2(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ GLubyte red, green;
+ unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data),
+ i, j, &red, 2);
+ unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data) + 8,
+ i, j, &green, 2);
+ texel[RCOMP] = UBYTE_TO_FLOAT(red);
+ texel[GCOMP] = UBYTE_TO_FLOAT(green);
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 1.0;
+}
+
+void
+_mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ GLbyte red, green;
+ signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
+ i, j, &red, 2);
+ signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8,
+ i, j, &green, 2);
+ texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
+ texel[GCOMP] = BYTE_TO_FLOAT_TEX(green);
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 1.0;
+}
+
+#define TAG(x) unsigned_##x
+
+#define TYPE GLubyte
+#define T_MIN 0
+#define T_MAX 0xff
+
+#include "texcompress_rgtc_tmp.h"
+
+#undef TAG
+#undef TYPE
+#undef T_MIN
+#undef T_MAX
+
+#define TAG(x) signed_##x
+#define TYPE GLbyte
+#define T_MIN (GLbyte)-128
+#define T_MAX (GLbyte)127
+
+#include "texcompress_rgtc_tmp.h"
+
+#undef TAG
+#undef TYPE
+#undef T_MIN
+#undef T_MAX
diff --git a/mesalib/src/mesa/main/texcompress_rgtc_tmp.h b/mesalib/src/mesa/main/texcompress_rgtc_tmp.h
index c8bf082a1..335e1f4a1 100644
--- a/mesalib/src/mesa/main/texcompress_rgtc_tmp.h
+++ b/mesalib/src/mesa/main/texcompress_rgtc_tmp.h
@@ -1,418 +1,418 @@
-/*
- * Copyright (C) 2011 Red Hat Inc.
- *
- * block compression parts are:
- * Copyright (C) 2004 Roland Scheidegger All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Author:
- * Dave Airlie
- */
-
-/* included by texcompress_rgtc to define byte/ubyte compressors */
-
-static void TAG(fetch_texel_rgtc)(unsigned srcRowStride, const TYPE *pixdata,
- unsigned i, unsigned j, TYPE *value, unsigned comps)
-{
- TYPE decode;
- const TYPE *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8 * comps);
- const TYPE alpha0 = blksrc[0];
- const TYPE alpha1 = blksrc[1];
- const char bit_pos = ((j&3) * 4 + (i&3)) * 3;
- const TYPE acodelow = blksrc[2 + bit_pos / 8];
- const TYPE acodehigh = (3 + bit_pos / 8) < 8 ? blksrc[3 + bit_pos / 8] : 0;
- const TYPE code = (acodelow >> (bit_pos & 0x7) |
- (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7;
-
- if (code == 0)
- decode = alpha0;
- else if (code == 1)
- decode = alpha1;
- else if (alpha0 > alpha1)
- decode = ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7);
- else if (code < 6)
- decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5);
- else if (code == 6)
- decode = T_MIN;
- else
- decode = T_MAX;
-
- *value = decode;
-}
-
-static void TAG(write_rgtc_encoded_channel)(TYPE *blkaddr,
- TYPE alphabase1,
- TYPE alphabase2,
- TYPE alphaenc[16])
-{
- *blkaddr++ = alphabase1;
- *blkaddr++ = alphabase2;
- *blkaddr++ = alphaenc[0] | (alphaenc[1] << 3) | ((alphaenc[2] & 3) << 6);
- *blkaddr++ = (alphaenc[2] >> 2) | (alphaenc[3] << 1) | (alphaenc[4] << 4) | ((alphaenc[5] & 1) << 7);
- *blkaddr++ = (alphaenc[5] >> 1) | (alphaenc[6] << 2) | (alphaenc[7] << 5);
- *blkaddr++ = alphaenc[8] | (alphaenc[9] << 3) | ((alphaenc[10] & 3) << 6);
- *blkaddr++ = (alphaenc[10] >> 2) | (alphaenc[11] << 1) | (alphaenc[12] << 4) | ((alphaenc[13] & 1) << 7);
- *blkaddr++ = (alphaenc[13] >> 1) | (alphaenc[14] << 2) | (alphaenc[15] << 5);
-}
-
-static void TAG(encode_rgtc_chan)(TYPE *blkaddr, TYPE srccolors[4][4],
- int numxpixels, int numypixels)
-{
- TYPE alphabase[2], alphause[2];
- short alphatest[2] = { 0 };
- unsigned int alphablockerror1, alphablockerror2, alphablockerror3;
- TYPE i, j, aindex, acutValues[7];
- TYPE alphaenc1[16], alphaenc2[16], alphaenc3[16];
- int alphaabsmin = 0, alphaabsmax = 0;
- short alphadist;
-
- /* find lowest and highest alpha value in block, alphabase[0] lowest, alphabase[1] highest */
- alphabase[0] = T_MAX; alphabase[1] = T_MIN;
- for (j = 0; j < numypixels; j++) {
- for (i = 0; i < numxpixels; i++) {
- if (srccolors[j][i] == T_MIN)
- alphaabsmin = 1;
- else if (srccolors[j][i] == T_MAX)
- alphaabsmax = 1;
- else {
- if (srccolors[j][i] > alphabase[1])
- alphabase[1] = srccolors[j][i];
- if (srccolors[j][i] < alphabase[0])
- alphabase[0] = srccolors[j][i];
- }
- }
- }
-
-
- if (((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax))
- || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax)) { /* one color, either max or min */
- /* shortcut here since it is a very common case (and also avoids later problems) */
- /* could also thest for alpha0 == alpha1 (and not min/max), but probably not common, so don't bother */
-
- *blkaddr++ = srccolors[0][0];
- blkaddr++;
- *blkaddr++ = 0;
- *blkaddr++ = 0;
- *blkaddr++ = 0;
- *blkaddr++ = 0;
- *blkaddr++ = 0;
- *blkaddr++ = 0;
-#if RGTC_DEBUG
- fprintf(stderr, "enc0 used\n");
-#endif
- return;
- }
-
- /* find best encoding for alpha0 > alpha1 */
- /* it's possible this encoding is better even if both alphaabsmin and alphaabsmax are true */
- alphablockerror1 = 0x0;
- alphablockerror2 = 0xffffffff;
- alphablockerror3 = 0xffffffff;
- if (alphaabsmin) alphause[0] = T_MIN;
- else alphause[0] = alphabase[0];
- if (alphaabsmax) alphause[1] = T_MAX;
- else alphause[1] = alphabase[1];
- /* calculate the 7 cut values, just the middle between 2 of the computed alpha values */
- for (aindex = 0; aindex < 7; aindex++) {
- /* don't forget here is always rounded down */
- acutValues[aindex] = (alphause[0] * (2*aindex + 1) + alphause[1] * (14 - (2*aindex + 1))) / 14;
- }
-
- for (j = 0; j < numypixels; j++) {
- for (i = 0; i < numxpixels; i++) {
- /* maybe it's overkill to have the most complicated calculation just for the error
- calculation which we only need to figure out if encoding1 or encoding2 is better... */
- if (srccolors[j][i] > acutValues[0]) {
- alphaenc1[4*j + i] = 0;
- alphadist = srccolors[j][i] - alphause[1];
- }
- else if (srccolors[j][i] > acutValues[1]) {
- alphaenc1[4*j + i] = 2;
- alphadist = srccolors[j][i] - (alphause[1] * 6 + alphause[0] * 1) / 7;
- }
- else if (srccolors[j][i] > acutValues[2]) {
- alphaenc1[4*j + i] = 3;
- alphadist = srccolors[j][i] - (alphause[1] * 5 + alphause[0] * 2) / 7;
- }
- else if (srccolors[j][i] > acutValues[3]) {
- alphaenc1[4*j + i] = 4;
- alphadist = srccolors[j][i] - (alphause[1] * 4 + alphause[0] * 3) / 7;
- }
- else if (srccolors[j][i] > acutValues[4]) {
- alphaenc1[4*j + i] = 5;
- alphadist = srccolors[j][i] - (alphause[1] * 3 + alphause[0] * 4) / 7;
- }
- else if (srccolors[j][i] > acutValues[5]) {
- alphaenc1[4*j + i] = 6;
- alphadist = srccolors[j][i] - (alphause[1] * 2 + alphause[0] * 5) / 7;
- }
- else if (srccolors[j][i] > acutValues[6]) {
- alphaenc1[4*j + i] = 7;
- alphadist = srccolors[j][i] - (alphause[1] * 1 + alphause[0] * 6) / 7;
- }
- else {
- alphaenc1[4*j + i] = 1;
- alphadist = srccolors[j][i] - alphause[0];
- }
- alphablockerror1 += alphadist * alphadist;
- }
- }
-
-#if RGTC_DEBUG
- for (i = 0; i < 16; i++) {
- fprintf(stderr, "%d ", alphaenc1[i]);
- }
- fprintf(stderr, "cutVals ");
- for (i = 0; i < 8; i++) {
- fprintf(stderr, "%d ", acutValues[i]);
- }
- fprintf(stderr, "srcVals ");
- for (j = 0; j < numypixels; j++) {
- for (i = 0; i < numxpixels; i++) {
- fprintf(stderr, "%d ", srccolors[j][i]);
- }
- }
- fprintf(stderr, "\n");
-#endif
-
- /* it's not very likely this encoding is better if both alphaabsmin and alphaabsmax
- are false but try it anyway */
- if (alphablockerror1 >= 32) {
-
- /* don't bother if encoding is already very good, this condition should also imply
- we have valid alphabase colors which we absolutely need (alphabase[0] <= alphabase[1]) */
- alphablockerror2 = 0;
- for (aindex = 0; aindex < 5; aindex++) {
- /* don't forget here is always rounded down */
- acutValues[aindex] = (alphabase[0] * (10 - (2*aindex + 1)) + alphabase[1] * (2*aindex + 1)) / 10;
- }
- for (j = 0; j < numypixels; j++) {
- for (i = 0; i < numxpixels; i++) {
- /* maybe it's overkill to have the most complicated calculation just for the error
- calculation which we only need to figure out if encoding1 or encoding2 is better... */
- if (srccolors[j][i] == T_MIN) {
- alphaenc2[4*j + i] = 6;
- alphadist = 0;
- }
- else if (srccolors[j][i] == T_MAX) {
- alphaenc2[4*j + i] = 7;
- alphadist = 0;
- }
- else if (srccolors[j][i] <= acutValues[0]) {
- alphaenc2[4*j + i] = 0;
- alphadist = srccolors[j][i] - alphabase[0];
- }
- else if (srccolors[j][i] <= acutValues[1]) {
- alphaenc2[4*j + i] = 2;
- alphadist = srccolors[j][i] - (alphabase[0] * 4 + alphabase[1] * 1) / 5;
- }
- else if (srccolors[j][i] <= acutValues[2]) {
- alphaenc2[4*j + i] = 3;
- alphadist = srccolors[j][i] - (alphabase[0] * 3 + alphabase[1] * 2) / 5;
- }
- else if (srccolors[j][i] <= acutValues[3]) {
- alphaenc2[4*j + i] = 4;
- alphadist = srccolors[j][i] - (alphabase[0] * 2 + alphabase[1] * 3) / 5;
- }
- else if (srccolors[j][i] <= acutValues[4]) {
- alphaenc2[4*j + i] = 5;
- alphadist = srccolors[j][i] - (alphabase[0] * 1 + alphabase[1] * 4) / 5;
- }
- else {
- alphaenc2[4*j + i] = 1;
- alphadist = srccolors[j][i] - alphabase[1];
- }
- alphablockerror2 += alphadist * alphadist;
- }
- }
-
-
- /* skip this if the error is already very small
- this encoding is MUCH better on average than #2 though, but expensive! */
- if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) {
- short blockerrlin1 = 0;
- short blockerrlin2 = 0;
- TYPE nralphainrangelow = 0;
- TYPE nralphainrangehigh = 0;
- alphatest[0] = T_MAX;
- alphatest[1] = T_MIN;
- /* if we have large range it's likely there are values close to 0/255, try to map them to 0/255 */
- for (j = 0; j < numypixels; j++) {
- for (i = 0; i < numxpixels; i++) {
- if ((srccolors[j][i] > alphatest[1]) && (srccolors[j][i] < (T_MAX -(alphabase[1] - alphabase[0]) / 28)))
- alphatest[1] = srccolors[j][i];
- if ((srccolors[j][i] < alphatest[0]) && (srccolors[j][i] > (alphabase[1] - alphabase[0]) / 28))
- alphatest[0] = srccolors[j][i];
- }
- }
- /* shouldn't happen too often, don't really care about those degenerated cases */
- if (alphatest[1] <= alphatest[0]) {
- alphatest[0] = T_MIN+1;
- alphatest[1] = T_MAX-1;
- }
- for (aindex = 0; aindex < 5; aindex++) {
- /* don't forget here is always rounded down */
- acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;
- }
-
- /* find the "average" difference between the alpha values and the next encoded value.
- This is then used to calculate new base values.
- Should there be some weighting, i.e. those values closer to alphatest[x] have more weight,
- since they will see more improvement, and also because the values in the middle are somewhat
- likely to get no improvement at all (because the base values might move in different directions)?
- OTOH it would mean the values in the middle are even less likely to get an improvement
- */
- for (j = 0; j < numypixels; j++) {
- for (i = 0; i < numxpixels; i++) {
- if (srccolors[j][i] <= alphatest[0] / 2) {
- }
- else if (srccolors[j][i] > ((T_MAX + alphatest[1]) / 2)) {
- }
- else if (srccolors[j][i] <= acutValues[0]) {
- blockerrlin1 += (srccolors[j][i] - alphatest[0]);
- nralphainrangelow += 1;
- }
- else if (srccolors[j][i] <= acutValues[1]) {
- blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);
- blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);
- nralphainrangelow += 1;
- nralphainrangehigh += 1;
- }
- else if (srccolors[j][i] <= acutValues[2]) {
- blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);
- blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);
- nralphainrangelow += 1;
- nralphainrangehigh += 1;
- }
- else if (srccolors[j][i] <= acutValues[3]) {
- blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);
- blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);
- nralphainrangelow += 1;
- nralphainrangehigh += 1;
- }
- else if (srccolors[j][i] <= acutValues[4]) {
- blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);
- blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);
- nralphainrangelow += 1;
- nralphainrangehigh += 1;
- }
- else {
- blockerrlin2 += (srccolors[j][i] - alphatest[1]);
- nralphainrangehigh += 1;
- }
- }
- }
- /* shouldn't happen often, needed to avoid div by zero */
- if (nralphainrangelow == 0) nralphainrangelow = 1;
- if (nralphainrangehigh == 0) nralphainrangehigh = 1;
- alphatest[0] = alphatest[0] + (blockerrlin1 / nralphainrangelow);
-#if RGTC_DEBUG
- fprintf(stderr, "block err lin low %d, nr %d\n", blockerrlin1, nralphainrangelow);
- fprintf(stderr, "block err lin high %d, nr %d\n", blockerrlin2, nralphainrangehigh);
-#endif
- /* again shouldn't really happen often... */
- if (alphatest[0] < T_MIN) {
- alphatest[0] = T_MIN;
- }
- alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh);
- if (alphatest[1] > T_MAX) {
- alphatest[1] = T_MAX;
- }
-
- alphablockerror3 = 0;
- for (aindex = 0; aindex < 5; aindex++) {
- /* don't forget here is always rounded down */
- acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;
- }
- for (j = 0; j < numypixels; j++) {
- for (i = 0; i < numxpixels; i++) {
- /* maybe it's overkill to have the most complicated calculation just for the error
- calculation which we only need to figure out if encoding1 or encoding2 is better... */
- if (srccolors[j][i] <= alphatest[0] / 2) {
- alphaenc3[4*j + i] = 6;
- alphadist = srccolors[j][i];
- }
- else if (srccolors[j][i] > ((T_MAX + alphatest[1]) / 2)) {
- alphaenc3[4*j + i] = 7;
- alphadist = T_MAX - srccolors[j][i];
- }
- else if (srccolors[j][i] <= acutValues[0]) {
- alphaenc3[4*j + i] = 0;
- alphadist = srccolors[j][i] - alphatest[0];
- }
- else if (srccolors[j][i] <= acutValues[1]) {
- alphaenc3[4*j + i] = 2;
- alphadist = srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5;
- }
- else if (srccolors[j][i] <= acutValues[2]) {
- alphaenc3[4*j + i] = 3;
- alphadist = srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5;
- }
- else if (srccolors[j][i] <= acutValues[3]) {
- alphaenc3[4*j + i] = 4;
- alphadist = srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5;
- }
- else if (srccolors[j][i] <= acutValues[4]) {
- alphaenc3[4*j + i] = 5;
- alphadist = srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5;
- }
- else {
- alphaenc3[4*j + i] = 1;
- alphadist = srccolors[j][i] - alphatest[1];
- }
- alphablockerror3 += alphadist * alphadist;
- }
- }
- }
- }
-
- /* write the alpha values and encoding back. */
- if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) {
-#if RGTC_DEBUG
- if (alphablockerror1 > 96) fprintf(stderr, "enc1 used, error %d\n", alphablockerror1);
- fprintf(stderr,"w1: min %d max %d au0 %d au1 %d\n",
- T_MIN, T_MAX,
- alphause[1], alphause[0]);
-#endif
-
- TAG(write_rgtc_encoded_channel)( blkaddr, alphause[1], alphause[0], alphaenc1 );
- }
- else if (alphablockerror2 <= alphablockerror3) {
-#if RGTC_DEBUG
- if (alphablockerror2 > 96) fprintf(stderr, "enc2 used, error %d\n", alphablockerror2);
- fprintf(stderr,"w2: min %d max %d au0 %d au1 %d\n",
- T_MIN, T_MAX,
- alphabase[0], alphabase[1]);
-#endif
-
- TAG(write_rgtc_encoded_channel)( blkaddr, alphabase[0], alphabase[1], alphaenc2 );
- }
- else {
-#if RGTC_DEBUG
- fprintf(stderr, "enc3 used, error %d\n", alphablockerror3);
- fprintf(stderr,"w3: min %d max %d au0 %d au1 %d\n",
- T_MIN, T_MAX,
- alphatest[0], alphatest[1]);
-#endif
-
- TAG(write_rgtc_encoded_channel)( blkaddr, (TYPE)alphatest[0], (TYPE)alphatest[1], alphaenc3 );
- }
-}
+/*
+ * Copyright (C) 2011 Red Hat Inc.
+ *
+ * block compression parts are:
+ * Copyright (C) 2004 Roland Scheidegger All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author:
+ * Dave Airlie
+ */
+
+/* included by texcompress_rgtc to define byte/ubyte compressors */
+
+static void TAG(fetch_texel_rgtc)(unsigned srcRowStride, const TYPE *pixdata,
+ unsigned i, unsigned j, TYPE *value, unsigned comps)
+{
+ TYPE decode;
+ const TYPE *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8 * comps);
+ const TYPE alpha0 = blksrc[0];
+ const TYPE alpha1 = blksrc[1];
+ const char bit_pos = ((j&3) * 4 + (i&3)) * 3;
+ const TYPE acodelow = blksrc[2 + bit_pos / 8];
+ const TYPE acodehigh = (3 + bit_pos / 8) < 8 ? blksrc[3 + bit_pos / 8] : 0;
+ const TYPE code = (acodelow >> (bit_pos & 0x7) |
+ (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7;
+
+ if (code == 0)
+ decode = alpha0;
+ else if (code == 1)
+ decode = alpha1;
+ else if (alpha0 > alpha1)
+ decode = ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7);
+ else if (code < 6)
+ decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5);
+ else if (code == 6)
+ decode = T_MIN;
+ else
+ decode = T_MAX;
+
+ *value = decode;
+}
+
+static void TAG(write_rgtc_encoded_channel)(TYPE *blkaddr,
+ TYPE alphabase1,
+ TYPE alphabase2,
+ TYPE alphaenc[16])
+{
+ *blkaddr++ = alphabase1;
+ *blkaddr++ = alphabase2;
+ *blkaddr++ = alphaenc[0] | (alphaenc[1] << 3) | ((alphaenc[2] & 3) << 6);
+ *blkaddr++ = (alphaenc[2] >> 2) | (alphaenc[3] << 1) | (alphaenc[4] << 4) | ((alphaenc[5] & 1) << 7);
+ *blkaddr++ = (alphaenc[5] >> 1) | (alphaenc[6] << 2) | (alphaenc[7] << 5);
+ *blkaddr++ = alphaenc[8] | (alphaenc[9] << 3) | ((alphaenc[10] & 3) << 6);
+ *blkaddr++ = (alphaenc[10] >> 2) | (alphaenc[11] << 1) | (alphaenc[12] << 4) | ((alphaenc[13] & 1) << 7);
+ *blkaddr++ = (alphaenc[13] >> 1) | (alphaenc[14] << 2) | (alphaenc[15] << 5);
+}
+
+static void TAG(encode_rgtc_chan)(TYPE *blkaddr, TYPE srccolors[4][4],
+ int numxpixels, int numypixels)
+{
+ TYPE alphabase[2], alphause[2];
+ short alphatest[2] = { 0 };
+ unsigned int alphablockerror1, alphablockerror2, alphablockerror3;
+ TYPE i, j, aindex, acutValues[7];
+ TYPE alphaenc1[16], alphaenc2[16], alphaenc3[16];
+ int alphaabsmin = 0, alphaabsmax = 0;
+ short alphadist;
+
+ /* find lowest and highest alpha value in block, alphabase[0] lowest, alphabase[1] highest */
+ alphabase[0] = T_MAX; alphabase[1] = T_MIN;
+ for (j = 0; j < numypixels; j++) {
+ for (i = 0; i < numxpixels; i++) {
+ if (srccolors[j][i] == T_MIN)
+ alphaabsmin = 1;
+ else if (srccolors[j][i] == T_MAX)
+ alphaabsmax = 1;
+ else {
+ if (srccolors[j][i] > alphabase[1])
+ alphabase[1] = srccolors[j][i];
+ if (srccolors[j][i] < alphabase[0])
+ alphabase[0] = srccolors[j][i];
+ }
+ }
+ }
+
+
+ if (((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax))
+ || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax)) { /* one color, either max or min */
+ /* shortcut here since it is a very common case (and also avoids later problems) */
+ /* could also thest for alpha0 == alpha1 (and not min/max), but probably not common, so don't bother */
+
+ *blkaddr++ = srccolors[0][0];
+ blkaddr++;
+ *blkaddr++ = 0;
+ *blkaddr++ = 0;
+ *blkaddr++ = 0;
+ *blkaddr++ = 0;
+ *blkaddr++ = 0;
+ *blkaddr++ = 0;
+#if RGTC_DEBUG
+ fprintf(stderr, "enc0 used\n");
+#endif
+ return;
+ }
+
+ /* find best encoding for alpha0 > alpha1 */
+ /* it's possible this encoding is better even if both alphaabsmin and alphaabsmax are true */
+ alphablockerror1 = 0x0;
+ alphablockerror2 = 0xffffffff;
+ alphablockerror3 = 0xffffffff;
+ if (alphaabsmin) alphause[0] = T_MIN;
+ else alphause[0] = alphabase[0];
+ if (alphaabsmax) alphause[1] = T_MAX;
+ else alphause[1] = alphabase[1];
+ /* calculate the 7 cut values, just the middle between 2 of the computed alpha values */
+ for (aindex = 0; aindex < 7; aindex++) {
+ /* don't forget here is always rounded down */
+ acutValues[aindex] = (alphause[0] * (2*aindex + 1) + alphause[1] * (14 - (2*aindex + 1))) / 14;
+ }
+
+ for (j = 0; j < numypixels; j++) {
+ for (i = 0; i < numxpixels; i++) {
+ /* maybe it's overkill to have the most complicated calculation just for the error
+ calculation which we only need to figure out if encoding1 or encoding2 is better... */
+ if (srccolors[j][i] > acutValues[0]) {
+ alphaenc1[4*j + i] = 0;
+ alphadist = srccolors[j][i] - alphause[1];
+ }
+ else if (srccolors[j][i] > acutValues[1]) {
+ alphaenc1[4*j + i] = 2;
+ alphadist = srccolors[j][i] - (alphause[1] * 6 + alphause[0] * 1) / 7;
+ }
+ else if (srccolors[j][i] > acutValues[2]) {
+ alphaenc1[4*j + i] = 3;
+ alphadist = srccolors[j][i] - (alphause[1] * 5 + alphause[0] * 2) / 7;
+ }
+ else if (srccolors[j][i] > acutValues[3]) {
+ alphaenc1[4*j + i] = 4;
+ alphadist = srccolors[j][i] - (alphause[1] * 4 + alphause[0] * 3) / 7;
+ }
+ else if (srccolors[j][i] > acutValues[4]) {
+ alphaenc1[4*j + i] = 5;
+ alphadist = srccolors[j][i] - (alphause[1] * 3 + alphause[0] * 4) / 7;
+ }
+ else if (srccolors[j][i] > acutValues[5]) {
+ alphaenc1[4*j + i] = 6;
+ alphadist = srccolors[j][i] - (alphause[1] * 2 + alphause[0] * 5) / 7;
+ }
+ else if (srccolors[j][i] > acutValues[6]) {
+ alphaenc1[4*j + i] = 7;
+ alphadist = srccolors[j][i] - (alphause[1] * 1 + alphause[0] * 6) / 7;
+ }
+ else {
+ alphaenc1[4*j + i] = 1;
+ alphadist = srccolors[j][i] - alphause[0];
+ }
+ alphablockerror1 += alphadist * alphadist;
+ }
+ }
+
+#if RGTC_DEBUG
+ for (i = 0; i < 16; i++) {
+ fprintf(stderr, "%d ", alphaenc1[i]);
+ }
+ fprintf(stderr, "cutVals ");
+ for (i = 0; i < 8; i++) {
+ fprintf(stderr, "%d ", acutValues[i]);
+ }
+ fprintf(stderr, "srcVals ");
+ for (j = 0; j < numypixels; j++) {
+ for (i = 0; i < numxpixels; i++) {
+ fprintf(stderr, "%d ", srccolors[j][i]);
+ }
+ }
+ fprintf(stderr, "\n");
+#endif
+
+ /* it's not very likely this encoding is better if both alphaabsmin and alphaabsmax
+ are false but try it anyway */
+ if (alphablockerror1 >= 32) {
+
+ /* don't bother if encoding is already very good, this condition should also imply
+ we have valid alphabase colors which we absolutely need (alphabase[0] <= alphabase[1]) */
+ alphablockerror2 = 0;
+ for (aindex = 0; aindex < 5; aindex++) {
+ /* don't forget here is always rounded down */
+ acutValues[aindex] = (alphabase[0] * (10 - (2*aindex + 1)) + alphabase[1] * (2*aindex + 1)) / 10;
+ }
+ for (j = 0; j < numypixels; j++) {
+ for (i = 0; i < numxpixels; i++) {
+ /* maybe it's overkill to have the most complicated calculation just for the error
+ calculation which we only need to figure out if encoding1 or encoding2 is better... */
+ if (srccolors[j][i] == T_MIN) {
+ alphaenc2[4*j + i] = 6;
+ alphadist = 0;
+ }
+ else if (srccolors[j][i] == T_MAX) {
+ alphaenc2[4*j + i] = 7;
+ alphadist = 0;
+ }
+ else if (srccolors[j][i] <= acutValues[0]) {
+ alphaenc2[4*j + i] = 0;
+ alphadist = srccolors[j][i] - alphabase[0];
+ }
+ else if (srccolors[j][i] <= acutValues[1]) {
+ alphaenc2[4*j + i] = 2;
+ alphadist = srccolors[j][i] - (alphabase[0] * 4 + alphabase[1] * 1) / 5;
+ }
+ else if (srccolors[j][i] <= acutValues[2]) {
+ alphaenc2[4*j + i] = 3;
+ alphadist = srccolors[j][i] - (alphabase[0] * 3 + alphabase[1] * 2) / 5;
+ }
+ else if (srccolors[j][i] <= acutValues[3]) {
+ alphaenc2[4*j + i] = 4;
+ alphadist = srccolors[j][i] - (alphabase[0] * 2 + alphabase[1] * 3) / 5;
+ }
+ else if (srccolors[j][i] <= acutValues[4]) {
+ alphaenc2[4*j + i] = 5;
+ alphadist = srccolors[j][i] - (alphabase[0] * 1 + alphabase[1] * 4) / 5;
+ }
+ else {
+ alphaenc2[4*j + i] = 1;
+ alphadist = srccolors[j][i] - alphabase[1];
+ }
+ alphablockerror2 += alphadist * alphadist;
+ }
+ }
+
+
+ /* skip this if the error is already very small
+ this encoding is MUCH better on average than #2 though, but expensive! */
+ if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) {
+ short blockerrlin1 = 0;
+ short blockerrlin2 = 0;
+ TYPE nralphainrangelow = 0;
+ TYPE nralphainrangehigh = 0;
+ alphatest[0] = T_MAX;
+ alphatest[1] = T_MIN;
+ /* if we have large range it's likely there are values close to 0/255, try to map them to 0/255 */
+ for (j = 0; j < numypixels; j++) {
+ for (i = 0; i < numxpixels; i++) {
+ if ((srccolors[j][i] > alphatest[1]) && (srccolors[j][i] < (T_MAX -(alphabase[1] - alphabase[0]) / 28)))
+ alphatest[1] = srccolors[j][i];
+ if ((srccolors[j][i] < alphatest[0]) && (srccolors[j][i] > (alphabase[1] - alphabase[0]) / 28))
+ alphatest[0] = srccolors[j][i];
+ }
+ }
+ /* shouldn't happen too often, don't really care about those degenerated cases */
+ if (alphatest[1] <= alphatest[0]) {
+ alphatest[0] = T_MIN+1;
+ alphatest[1] = T_MAX-1;
+ }
+ for (aindex = 0; aindex < 5; aindex++) {
+ /* don't forget here is always rounded down */
+ acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;
+ }
+
+ /* find the "average" difference between the alpha values and the next encoded value.
+ This is then used to calculate new base values.
+ Should there be some weighting, i.e. those values closer to alphatest[x] have more weight,
+ since they will see more improvement, and also because the values in the middle are somewhat
+ likely to get no improvement at all (because the base values might move in different directions)?
+ OTOH it would mean the values in the middle are even less likely to get an improvement
+ */
+ for (j = 0; j < numypixels; j++) {
+ for (i = 0; i < numxpixels; i++) {
+ if (srccolors[j][i] <= alphatest[0] / 2) {
+ }
+ else if (srccolors[j][i] > ((T_MAX + alphatest[1]) / 2)) {
+ }
+ else if (srccolors[j][i] <= acutValues[0]) {
+ blockerrlin1 += (srccolors[j][i] - alphatest[0]);
+ nralphainrangelow += 1;
+ }
+ else if (srccolors[j][i] <= acutValues[1]) {
+ blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);
+ blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);
+ nralphainrangelow += 1;
+ nralphainrangehigh += 1;
+ }
+ else if (srccolors[j][i] <= acutValues[2]) {
+ blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);
+ blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);
+ nralphainrangelow += 1;
+ nralphainrangehigh += 1;
+ }
+ else if (srccolors[j][i] <= acutValues[3]) {
+ blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);
+ blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);
+ nralphainrangelow += 1;
+ nralphainrangehigh += 1;
+ }
+ else if (srccolors[j][i] <= acutValues[4]) {
+ blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);
+ blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);
+ nralphainrangelow += 1;
+ nralphainrangehigh += 1;
+ }
+ else {
+ blockerrlin2 += (srccolors[j][i] - alphatest[1]);
+ nralphainrangehigh += 1;
+ }
+ }
+ }
+ /* shouldn't happen often, needed to avoid div by zero */
+ if (nralphainrangelow == 0) nralphainrangelow = 1;
+ if (nralphainrangehigh == 0) nralphainrangehigh = 1;
+ alphatest[0] = alphatest[0] + (blockerrlin1 / nralphainrangelow);
+#if RGTC_DEBUG
+ fprintf(stderr, "block err lin low %d, nr %d\n", blockerrlin1, nralphainrangelow);
+ fprintf(stderr, "block err lin high %d, nr %d\n", blockerrlin2, nralphainrangehigh);
+#endif
+ /* again shouldn't really happen often... */
+ if (alphatest[0] < T_MIN) {
+ alphatest[0] = T_MIN;
+ }
+ alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh);
+ if (alphatest[1] > T_MAX) {
+ alphatest[1] = T_MAX;
+ }
+
+ alphablockerror3 = 0;
+ for (aindex = 0; aindex < 5; aindex++) {
+ /* don't forget here is always rounded down */
+ acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;
+ }
+ for (j = 0; j < numypixels; j++) {
+ for (i = 0; i < numxpixels; i++) {
+ /* maybe it's overkill to have the most complicated calculation just for the error
+ calculation which we only need to figure out if encoding1 or encoding2 is better... */
+ if (srccolors[j][i] <= alphatest[0] / 2) {
+ alphaenc3[4*j + i] = 6;
+ alphadist = srccolors[j][i];
+ }
+ else if (srccolors[j][i] > ((T_MAX + alphatest[1]) / 2)) {
+ alphaenc3[4*j + i] = 7;
+ alphadist = T_MAX - srccolors[j][i];
+ }
+ else if (srccolors[j][i] <= acutValues[0]) {
+ alphaenc3[4*j + i] = 0;
+ alphadist = srccolors[j][i] - alphatest[0];
+ }
+ else if (srccolors[j][i] <= acutValues[1]) {
+ alphaenc3[4*j + i] = 2;
+ alphadist = srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5;
+ }
+ else if (srccolors[j][i] <= acutValues[2]) {
+ alphaenc3[4*j + i] = 3;
+ alphadist = srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5;
+ }
+ else if (srccolors[j][i] <= acutValues[3]) {
+ alphaenc3[4*j + i] = 4;
+ alphadist = srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5;
+ }
+ else if (srccolors[j][i] <= acutValues[4]) {
+ alphaenc3[4*j + i] = 5;
+ alphadist = srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5;
+ }
+ else {
+ alphaenc3[4*j + i] = 1;
+ alphadist = srccolors[j][i] - alphatest[1];
+ }
+ alphablockerror3 += alphadist * alphadist;
+ }
+ }
+ }
+ }
+
+ /* write the alpha values and encoding back. */
+ if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) {
+#if RGTC_DEBUG
+ if (alphablockerror1 > 96) fprintf(stderr, "enc1 used, error %d\n", alphablockerror1);
+ fprintf(stderr,"w1: min %d max %d au0 %d au1 %d\n",
+ T_MIN, T_MAX,
+ alphause[1], alphause[0]);
+#endif
+
+ TAG(write_rgtc_encoded_channel)( blkaddr, alphause[1], alphause[0], alphaenc1 );
+ }
+ else if (alphablockerror2 <= alphablockerror3) {
+#if RGTC_DEBUG
+ if (alphablockerror2 > 96) fprintf(stderr, "enc2 used, error %d\n", alphablockerror2);
+ fprintf(stderr,"w2: min %d max %d au0 %d au1 %d\n",
+ T_MIN, T_MAX,
+ alphabase[0], alphabase[1]);
+#endif
+
+ TAG(write_rgtc_encoded_channel)( blkaddr, alphabase[0], alphabase[1], alphaenc2 );
+ }
+ else {
+#if RGTC_DEBUG
+ fprintf(stderr, "enc3 used, error %d\n", alphablockerror3);
+ fprintf(stderr,"w3: min %d max %d au0 %d au1 %d\n",
+ T_MIN, T_MAX,
+ alphatest[0], alphatest[1]);
+#endif
+
+ TAG(write_rgtc_encoded_channel)( blkaddr, (TYPE)alphatest[0], (TYPE)alphatest[1], alphaenc3 );
+ }
+}
diff --git a/mesalib/src/mesa/main/texcompress_s3tc.c b/mesalib/src/mesa/main/texcompress_s3tc.c
index 90be6c0a8..479806eca 100644
--- a/mesalib/src/mesa/main/texcompress_s3tc.c
+++ b/mesalib/src/mesa/main/texcompress_s3tc.c
@@ -50,7 +50,11 @@
#if defined(_WIN32) || defined(WIN32)
+#ifdef _DEBUG
+#define DXTN_LIBNAME "dxtn_dbg.dll"
+#else
#define DXTN_LIBNAME "dxtn.dll"
+#endif
#define RTLD_LAZY 0
#define RTLD_GLOBAL 0
#elif defined(__DJGPP__)
diff --git a/mesalib/src/mesa/main/texfetch.c b/mesalib/src/mesa/main/texfetch.c
index 550597e1c..8666076ab 100644
--- a/mesalib/src/mesa/main/texfetch.c
+++ b/mesalib/src/mesa/main/texfetch.c
@@ -1,922 +1,922 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.7
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (c) 2009 VMware, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file texfetch.c
- *
- * Texel fetch/store functions
- *
- * \author Gareth Hughes
- */
-
-
-#include "colormac.h"
-#include "macros.h"
-#include "texcompress.h"
-#include "texcompress_fxt1.h"
-#include "texcompress_s3tc.h"
-#include "texcompress_rgtc.h"
-#include "texfetch.h"
-#include "teximage.h"
-
-
-/**
- * Convert an 8-bit sRGB value from non-linear space to a
- * linear RGB value in [0, 1].
- * Implemented with a 256-entry lookup table.
- */
-static INLINE GLfloat
-nonlinear_to_linear(GLubyte cs8)
-{
- static GLfloat table[256];
- static GLboolean tableReady = GL_FALSE;
- if (!tableReady) {
- /* compute lookup table now */
- GLuint i;
- for (i = 0; i < 256; i++) {
- const GLfloat cs = UBYTE_TO_FLOAT(i);
- if (cs <= 0.04045) {
- table[i] = cs / 12.92f;
- }
- else {
- table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
- }
- }
- tableReady = GL_TRUE;
- }
- return table[cs8];
-}
-
-
-
-/* Texel fetch routines for all supported formats
- */
-#define DIM 1
-#include "texfetch_tmp.h"
-
-#define DIM 2
-#include "texfetch_tmp.h"
-
-#define DIM 3
-#include "texfetch_tmp.h"
-
-/**
- * Null texel fetch function.
- *
- * Have to have this so the FetchTexel function pointer is never NULL.
- */
-static void fetch_null_texelf( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- (void) texImage; (void) i; (void) j; (void) k;
- texel[RCOMP] = 0.0;
- texel[GCOMP] = 0.0;
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 0.0;
- _mesa_warning(NULL, "fetch_null_texelf() called!");
-}
-
-static void store_null_texel(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- (void) texImage;
- (void) i;
- (void) j;
- (void) k;
- (void) texel;
- /* no-op */
-}
-
-
-
-/**
- * Table to map MESA_FORMAT_ to texel fetch/store funcs.
- * XXX this is somewhat temporary.
- */
-static struct {
- gl_format Name;
- FetchTexelFuncF Fetch1D;
- FetchTexelFuncF Fetch2D;
- FetchTexelFuncF Fetch3D;
- StoreTexelFunc StoreTexel;
-}
-texfetch_funcs[MESA_FORMAT_COUNT] =
-{
- {
- MESA_FORMAT_NONE,
- fetch_null_texelf,
- fetch_null_texelf,
- fetch_null_texelf,
- store_null_texel
- },
-
- {
- MESA_FORMAT_RGBA8888,
- fetch_texel_1d_f_rgba8888,
- fetch_texel_2d_f_rgba8888,
- fetch_texel_3d_f_rgba8888,
- store_texel_rgba8888
- },
- {
- MESA_FORMAT_RGBA8888_REV,
- fetch_texel_1d_f_rgba8888_rev,
- fetch_texel_2d_f_rgba8888_rev,
- fetch_texel_3d_f_rgba8888_rev,
- store_texel_rgba8888_rev
- },
- {
- MESA_FORMAT_ARGB8888,
- fetch_texel_1d_f_argb8888,
- fetch_texel_2d_f_argb8888,
- fetch_texel_3d_f_argb8888,
- store_texel_argb8888
- },
- {
- MESA_FORMAT_ARGB8888_REV,
- fetch_texel_1d_f_argb8888_rev,
- fetch_texel_2d_f_argb8888_rev,
- fetch_texel_3d_f_argb8888_rev,
- store_texel_argb8888_rev
- },
- {
- MESA_FORMAT_XRGB8888,
- fetch_texel_1d_f_xrgb8888,
- fetch_texel_2d_f_xrgb8888,
- fetch_texel_3d_f_xrgb8888,
- store_texel_xrgb8888
- },
- {
- MESA_FORMAT_XRGB8888_REV,
- fetch_texel_1d_f_xrgb8888_rev,
- fetch_texel_2d_f_xrgb8888_rev,
- fetch_texel_3d_f_xrgb8888_rev,
- store_texel_xrgb8888_rev,
- },
- {
- MESA_FORMAT_RGB888,
- fetch_texel_1d_f_rgb888,
- fetch_texel_2d_f_rgb888,
- fetch_texel_3d_f_rgb888,
- store_texel_rgb888
- },
- {
- MESA_FORMAT_BGR888,
- fetch_texel_1d_f_bgr888,
- fetch_texel_2d_f_bgr888,
- fetch_texel_3d_f_bgr888,
- store_texel_bgr888
- },
- {
- MESA_FORMAT_RGB565,
- fetch_texel_1d_f_rgb565,
- fetch_texel_2d_f_rgb565,
- fetch_texel_3d_f_rgb565,
- store_texel_rgb565
- },
- {
- MESA_FORMAT_RGB565_REV,
- fetch_texel_1d_f_rgb565_rev,
- fetch_texel_2d_f_rgb565_rev,
- fetch_texel_3d_f_rgb565_rev,
- store_texel_rgb565_rev
- },
- {
- MESA_FORMAT_ARGB4444,
- fetch_texel_1d_f_argb4444,
- fetch_texel_2d_f_argb4444,
- fetch_texel_3d_f_argb4444,
- store_texel_argb4444
- },
- {
- MESA_FORMAT_ARGB4444_REV,
- fetch_texel_1d_f_argb4444_rev,
- fetch_texel_2d_f_argb4444_rev,
- fetch_texel_3d_f_argb4444_rev,
- store_texel_argb4444_rev
- },
- {
- MESA_FORMAT_RGBA5551,
- fetch_texel_1d_f_rgba5551,
- fetch_texel_2d_f_rgba5551,
- fetch_texel_3d_f_rgba5551,
- store_texel_rgba5551
- },
- {
- MESA_FORMAT_ARGB1555,
- fetch_texel_1d_f_argb1555,
- fetch_texel_2d_f_argb1555,
- fetch_texel_3d_f_argb1555,
- store_texel_argb1555
- },
- {
- MESA_FORMAT_ARGB1555_REV,
- fetch_texel_1d_f_argb1555_rev,
- fetch_texel_2d_f_argb1555_rev,
- fetch_texel_3d_f_argb1555_rev,
- store_texel_argb1555_rev
- },
- {
- MESA_FORMAT_AL44,
- fetch_texel_1d_f_al44,
- fetch_texel_2d_f_al44,
- fetch_texel_3d_f_al44,
- store_texel_al44
- },
- {
- MESA_FORMAT_AL88,
- fetch_texel_1d_f_al88,
- fetch_texel_2d_f_al88,
- fetch_texel_3d_f_al88,
- store_texel_al88
- },
- {
- MESA_FORMAT_AL88_REV,
- fetch_texel_1d_f_al88_rev,
- fetch_texel_2d_f_al88_rev,
- fetch_texel_3d_f_al88_rev,
- store_texel_al88_rev
- },
- {
- MESA_FORMAT_AL1616,
- fetch_texel_1d_f_al1616,
- fetch_texel_2d_f_al1616,
- fetch_texel_3d_f_al1616,
- store_texel_al1616
- },
- {
- MESA_FORMAT_AL1616_REV,
- fetch_texel_1d_f_al1616_rev,
- fetch_texel_2d_f_al1616_rev,
- fetch_texel_3d_f_al1616_rev,
- store_texel_al1616_rev
- },
- {
- MESA_FORMAT_RGB332,
- fetch_texel_1d_f_rgb332,
- fetch_texel_2d_f_rgb332,
- fetch_texel_3d_f_rgb332,
- store_texel_rgb332
- },
- {
- MESA_FORMAT_A8,
- fetch_texel_1d_f_a8,
- fetch_texel_2d_f_a8,
- fetch_texel_3d_f_a8,
- store_texel_a8
- },
- {
- MESA_FORMAT_A16,
- fetch_texel_1d_f_a16,
- fetch_texel_2d_f_a16,
- fetch_texel_3d_f_a16,
- store_texel_a16
- },
- {
- MESA_FORMAT_L8,
- fetch_texel_1d_f_l8,
- fetch_texel_2d_f_l8,
- fetch_texel_3d_f_l8,
- store_texel_l8
- },
- {
- MESA_FORMAT_L16,
- fetch_texel_1d_f_l16,
- fetch_texel_2d_f_l16,
- fetch_texel_3d_f_l16,
- store_texel_l16
- },
- {
- MESA_FORMAT_I8,
- fetch_texel_1d_f_i8,
- fetch_texel_2d_f_i8,
- fetch_texel_3d_f_i8,
- store_texel_i8
- },
- {
- MESA_FORMAT_I16,
- fetch_texel_1d_f_i16,
- fetch_texel_2d_f_i16,
- fetch_texel_3d_f_i16,
- store_texel_i16
- },
- {
- MESA_FORMAT_CI8,
- fetch_texel_1d_f_ci8,
- fetch_texel_2d_f_ci8,
- fetch_texel_3d_f_ci8,
- store_texel_ci8
- },
- {
- MESA_FORMAT_YCBCR,
- fetch_texel_1d_f_ycbcr,
- fetch_texel_2d_f_ycbcr,
- fetch_texel_3d_f_ycbcr,
- store_texel_ycbcr
- },
- {
- MESA_FORMAT_YCBCR_REV,
- fetch_texel_1d_f_ycbcr_rev,
- fetch_texel_2d_f_ycbcr_rev,
- fetch_texel_3d_f_ycbcr_rev,
- store_texel_ycbcr_rev
- },
- {
- MESA_FORMAT_R8,
- fetch_texel_1d_f_r8,
- fetch_texel_2d_f_r8,
- fetch_texel_3d_f_r8,
- store_texel_r8,
- },
- {
- MESA_FORMAT_RG88,
- fetch_texel_1d_f_rg88,
- fetch_texel_2d_f_rg88,
- fetch_texel_3d_f_rg88,
- store_texel_rg88,
- },
- {
- MESA_FORMAT_RG88_REV,
- fetch_texel_1d_f_rg88_rev,
- fetch_texel_2d_f_rg88_rev,
- fetch_texel_3d_f_rg88_rev,
- store_texel_rg88_rev,
- },
- {
- MESA_FORMAT_R16,
- fetch_texel_1d_f_r16,
- fetch_texel_2d_f_r16,
- fetch_texel_3d_f_r16,
- store_texel_r16,
- },
- {
- MESA_FORMAT_RG1616,
- fetch_texel_1d_f_rg1616,
- fetch_texel_2d_f_rg1616,
- fetch_texel_3d_f_rg1616,
- store_texel_rg1616,
- },
- {
- MESA_FORMAT_RG1616_REV,
- fetch_texel_1d_f_rg1616_rev,
- fetch_texel_2d_f_rg1616_rev,
- fetch_texel_3d_f_rg1616_rev,
- store_texel_rg1616_rev,
- },
- {
- MESA_FORMAT_ARGB2101010,
- fetch_texel_1d_f_argb2101010,
- fetch_texel_2d_f_argb2101010,
- fetch_texel_3d_f_argb2101010,
- store_texel_argb2101010
- },
- {
- MESA_FORMAT_Z24_S8,
- fetch_texel_1d_f_z24_s8,
- fetch_texel_2d_f_z24_s8,
- fetch_texel_3d_f_z24_s8,
- store_texel_z24_s8
- },
- {
- MESA_FORMAT_S8_Z24,
- fetch_texel_1d_f_s8_z24,
- fetch_texel_2d_f_s8_z24,
- fetch_texel_3d_f_s8_z24,
- store_texel_s8_z24
- },
- {
- MESA_FORMAT_Z16,
- fetch_texel_1d_f_z16,
- fetch_texel_2d_f_z16,
- fetch_texel_3d_f_z16,
- store_texel_z16
- },
- {
- MESA_FORMAT_X8_Z24,
- fetch_texel_1d_f_s8_z24,
- fetch_texel_2d_f_s8_z24,
- fetch_texel_3d_f_s8_z24,
- store_texel_s8_z24
- },
- {
- MESA_FORMAT_Z24_X8,
- fetch_texel_1d_f_z24_s8,
- fetch_texel_2d_f_z24_s8,
- fetch_texel_3d_f_z24_s8,
- store_texel_z24_s8
- },
- {
- MESA_FORMAT_Z32,
- fetch_texel_1d_f_z32,
- fetch_texel_2d_f_z32,
- fetch_texel_3d_f_z32,
- store_texel_z32
- },
- {
- MESA_FORMAT_S8,
- NULL,
- NULL,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_SRGB8,
- fetch_texel_1d_srgb8,
- fetch_texel_2d_srgb8,
- fetch_texel_3d_srgb8,
- store_texel_srgb8
- },
- {
- MESA_FORMAT_SRGBA8,
- fetch_texel_1d_srgba8,
- fetch_texel_2d_srgba8,
- fetch_texel_3d_srgba8,
- store_texel_srgba8
- },
- {
- MESA_FORMAT_SARGB8,
- fetch_texel_1d_sargb8,
- fetch_texel_2d_sargb8,
- fetch_texel_3d_sargb8,
- store_texel_sargb8
- },
- {
- MESA_FORMAT_SL8,
- fetch_texel_1d_sl8,
- fetch_texel_2d_sl8,
- fetch_texel_3d_sl8,
- store_texel_sl8
- },
- {
- MESA_FORMAT_SLA8,
- fetch_texel_1d_sla8,
- fetch_texel_2d_sla8,
- fetch_texel_3d_sla8,
- store_texel_sla8
- },
- {
- MESA_FORMAT_SRGB_DXT1,
- NULL,
- _mesa_fetch_texel_2d_f_srgb_dxt1,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_SRGBA_DXT1,
- NULL,
- _mesa_fetch_texel_2d_f_srgba_dxt1,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_SRGBA_DXT3,
- NULL,
- _mesa_fetch_texel_2d_f_srgba_dxt3,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_SRGBA_DXT5,
- NULL,
- _mesa_fetch_texel_2d_f_srgba_dxt5,
- NULL,
- NULL
- },
-
- {
- MESA_FORMAT_RGB_FXT1,
- NULL,
- _mesa_fetch_texel_2d_f_rgb_fxt1,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_RGBA_FXT1,
- NULL,
- _mesa_fetch_texel_2d_f_rgba_fxt1,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_RGB_DXT1,
- NULL,
- _mesa_fetch_texel_2d_f_rgb_dxt1,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_RGBA_DXT1,
- NULL,
- _mesa_fetch_texel_2d_f_rgba_dxt1,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_RGBA_DXT3,
- NULL,
- _mesa_fetch_texel_2d_f_rgba_dxt3,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_RGBA_DXT5,
- NULL,
- _mesa_fetch_texel_2d_f_rgba_dxt5,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_RGBA_FLOAT32,
- fetch_texel_1d_f_rgba_f32,
- fetch_texel_2d_f_rgba_f32,
- fetch_texel_3d_f_rgba_f32,
- store_texel_rgba_f32
- },
- {
- MESA_FORMAT_RGBA_FLOAT16,
- fetch_texel_1d_f_rgba_f16,
- fetch_texel_2d_f_rgba_f16,
- fetch_texel_3d_f_rgba_f16,
- store_texel_rgba_f16
- },
- {
- MESA_FORMAT_RGB_FLOAT32,
- fetch_texel_1d_f_rgb_f32,
- fetch_texel_2d_f_rgb_f32,
- fetch_texel_3d_f_rgb_f32,
- store_texel_rgb_f32
- },
- {
- MESA_FORMAT_RGB_FLOAT16,
- fetch_texel_1d_f_rgb_f16,
- fetch_texel_2d_f_rgb_f16,
- fetch_texel_3d_f_rgb_f16,
- store_texel_rgb_f16
- },
- {
- MESA_FORMAT_ALPHA_FLOAT32,
- fetch_texel_1d_f_alpha_f32,
- fetch_texel_2d_f_alpha_f32,
- fetch_texel_3d_f_alpha_f32,
- store_texel_alpha_f32
- },
- {
- MESA_FORMAT_ALPHA_FLOAT16,
- fetch_texel_1d_f_alpha_f16,
- fetch_texel_2d_f_alpha_f16,
- fetch_texel_3d_f_alpha_f16,
- store_texel_alpha_f16
- },
- {
- MESA_FORMAT_LUMINANCE_FLOAT32,
- fetch_texel_1d_f_luminance_f32,
- fetch_texel_2d_f_luminance_f32,
- fetch_texel_3d_f_luminance_f32,
- store_texel_luminance_f32
- },
- {
- MESA_FORMAT_LUMINANCE_FLOAT16,
- fetch_texel_1d_f_luminance_f16,
- fetch_texel_2d_f_luminance_f16,
- fetch_texel_3d_f_luminance_f16,
- store_texel_luminance_f16
- },
- {
- MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
- fetch_texel_1d_f_luminance_alpha_f32,
- fetch_texel_2d_f_luminance_alpha_f32,
- fetch_texel_3d_f_luminance_alpha_f32,
- store_texel_luminance_alpha_f32
- },
- {
- MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
- fetch_texel_1d_f_luminance_alpha_f16,
- fetch_texel_2d_f_luminance_alpha_f16,
- fetch_texel_3d_f_luminance_alpha_f16,
- store_texel_luminance_alpha_f16
- },
- {
- MESA_FORMAT_INTENSITY_FLOAT32,
- fetch_texel_1d_f_intensity_f32,
- fetch_texel_2d_f_intensity_f32,
- fetch_texel_3d_f_intensity_f32,
- store_texel_intensity_f32
- },
- {
- MESA_FORMAT_INTENSITY_FLOAT16,
- fetch_texel_1d_f_intensity_f16,
- fetch_texel_2d_f_intensity_f16,
- fetch_texel_3d_f_intensity_f16,
- store_texel_intensity_f16
- },
-
- /* non-normalized, signed int */
- {
- MESA_FORMAT_RGBA_INT8,
- fetch_texel_1d_rgba_int8,
- fetch_texel_2d_rgba_int8,
- fetch_texel_3d_rgba_int8,
- store_texel_rgba_int8
- },
- {
- MESA_FORMAT_RGBA_INT16,
- fetch_texel_1d_rgba_int16,
- fetch_texel_2d_rgba_int16,
- fetch_texel_3d_rgba_int16,
- store_texel_rgba_int16
- },
- {
- MESA_FORMAT_RGBA_INT32,
- fetch_texel_1d_rgba_int32,
- fetch_texel_2d_rgba_int32,
- fetch_texel_3d_rgba_int32,
- store_texel_rgba_int32
- },
-
- /* non-normalized, unsigned int */
- {
- MESA_FORMAT_RGBA_UINT8,
- fetch_texel_1d_rgba_uint8,
- fetch_texel_2d_rgba_uint8,
- fetch_texel_3d_rgba_uint8,
- store_texel_rgba_uint8
- },
- {
- MESA_FORMAT_RGBA_UINT16,
- fetch_texel_1d_rgba_uint16,
- fetch_texel_2d_rgba_uint16,
- fetch_texel_3d_rgba_uint16,
- store_texel_rgba_uint16
- },
- {
- MESA_FORMAT_RGBA_UINT32,
- fetch_texel_1d_rgba_uint32,
- fetch_texel_2d_rgba_uint32,
- fetch_texel_3d_rgba_uint32,
- store_texel_rgba_uint32
- },
-
- /* dudv */
- {
- MESA_FORMAT_DUDV8,
- fetch_texel_1d_dudv8,
- fetch_texel_2d_dudv8,
- fetch_texel_3d_dudv8,
- NULL
- },
-
- /* signed, normalized */
- {
- MESA_FORMAT_SIGNED_R8,
- fetch_texel_1d_signed_r8,
- fetch_texel_2d_signed_r8,
- fetch_texel_3d_signed_r8,
- store_texel_signed_r8
- },
- {
- MESA_FORMAT_SIGNED_RG88,
- fetch_texel_1d_signed_rg88,
- fetch_texel_2d_signed_rg88,
- fetch_texel_3d_signed_rg88,
- store_texel_signed_rg88
- },
- {
- MESA_FORMAT_SIGNED_RGBX8888,
- fetch_texel_1d_signed_rgbx8888,
- fetch_texel_2d_signed_rgbx8888,
- fetch_texel_3d_signed_rgbx8888,
- store_texel_signed_rgbx8888
- },
- {
- MESA_FORMAT_SIGNED_RGBA8888,
- fetch_texel_1d_signed_rgba8888,
- fetch_texel_2d_signed_rgba8888,
- fetch_texel_3d_signed_rgba8888,
- store_texel_signed_rgba8888
- },
- {
- MESA_FORMAT_SIGNED_RGBA8888_REV,
- fetch_texel_1d_signed_rgba8888_rev,
- fetch_texel_2d_signed_rgba8888_rev,
- fetch_texel_3d_signed_rgba8888_rev,
- store_texel_signed_rgba8888_rev
- },
- {
- MESA_FORMAT_SIGNED_R_16,
- fetch_texel_1d_signed_r_16,
- fetch_texel_2d_signed_r_16,
- fetch_texel_3d_signed_r_16,
- store_texel_signed_r_16
- },
- {
- MESA_FORMAT_SIGNED_RG_16,
- fetch_texel_1d_signed_rg_16,
- fetch_texel_2d_signed_rg_16,
- fetch_texel_3d_signed_rg_16,
- store_texel_signed_rg_16
- },
- {
- MESA_FORMAT_SIGNED_RGB_16,
- fetch_texel_1d_signed_rgb_16,
- fetch_texel_2d_signed_rgb_16,
- fetch_texel_3d_signed_rgb_16,
- store_texel_signed_rgb_16
- },
- {
- MESA_FORMAT_SIGNED_RGBA_16,
- fetch_texel_1d_signed_rgba_16,
- fetch_texel_2d_signed_rgba_16,
- fetch_texel_3d_signed_rgba_16,
- store_texel_signed_rgba_16
- },
- {
- MESA_FORMAT_RGBA_16,
- fetch_texel_1d_rgba_16,
- fetch_texel_2d_rgba_16,
- fetch_texel_3d_rgba_16,
- store_texel_rgba_16
- },
- {
- MESA_FORMAT_RED_RGTC1,
- NULL,
- _mesa_fetch_texel_2d_f_red_rgtc1,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_SIGNED_RED_RGTC1,
- NULL,
- _mesa_fetch_texel_2d_f_signed_red_rgtc1,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_RG_RGTC2,
- NULL,
- _mesa_fetch_texel_2d_f_rg_rgtc2,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_SIGNED_RG_RGTC2,
- NULL,
- _mesa_fetch_texel_2d_f_signed_rg_rgtc2,
- NULL,
- NULL
- },
-};
-
-
-FetchTexelFuncF
-_mesa_get_texel_fetch_func(gl_format format, GLuint dims)
-{
-#ifdef DEBUG
- /* check that the table entries are sorted by format name */
- gl_format fmt;
- for (fmt = 0; fmt < MESA_FORMAT_COUNT; fmt++) {
- assert(texfetch_funcs[fmt].Name == fmt);
- }
-#endif
-
- assert(Elements(texfetch_funcs) == MESA_FORMAT_COUNT);
- assert(format < MESA_FORMAT_COUNT);
-
- switch (dims) {
- case 1:
- return texfetch_funcs[format].Fetch1D;
- case 2:
- return texfetch_funcs[format].Fetch2D;
- case 3:
- return texfetch_funcs[format].Fetch3D;
- default:
- assert(0 && "bad dims in _mesa_get_texel_fetch_func");
- return NULL;
- }
-}
-
-
-StoreTexelFunc
-_mesa_get_texel_store_func(gl_format format)
-{
- assert(format < MESA_FORMAT_COUNT);
- return texfetch_funcs[format].StoreTexel;
-}
-
-
-/**
- * Adaptor for fetching a GLchan texel from a float-valued texture.
- */
-static void
-fetch_texel_float_to_chan(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLchan *texelOut)
-{
- GLfloat temp[4];
- GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
-
- ASSERT(texImage->FetchTexelf);
- texImage->FetchTexelf(texImage, i, j, k, temp);
- if (baseFormat == GL_DEPTH_COMPONENT ||
- baseFormat == GL_DEPTH_STENCIL_EXT) {
- /* just one channel */
- UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
- }
- else {
- /* four channels */
- UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
- UNCLAMPED_FLOAT_TO_CHAN(texelOut[1], temp[1]);
- UNCLAMPED_FLOAT_TO_CHAN(texelOut[2], temp[2]);
- UNCLAMPED_FLOAT_TO_CHAN(texelOut[3], temp[3]);
- }
-}
-
-
-#if 0
-/**
- * Adaptor for fetching a float texel from a GLchan-valued texture.
- */
-static void
-fetch_texel_chan_to_float(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texelOut)
-{
- GLchan temp[4];
- GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
-
- ASSERT(texImage->FetchTexelc);
- texImage->FetchTexelc(texImage, i, j, k, temp);
- if (baseFormat == GL_DEPTH_COMPONENT ||
- baseFormat == GL_DEPTH_STENCIL_EXT) {
- /* just one channel */
- texelOut[0] = CHAN_TO_FLOAT(temp[0]);
- }
- else {
- /* four channels */
- texelOut[0] = CHAN_TO_FLOAT(temp[0]);
- texelOut[1] = CHAN_TO_FLOAT(temp[1]);
- texelOut[2] = CHAN_TO_FLOAT(temp[2]);
- texelOut[3] = CHAN_TO_FLOAT(temp[3]);
- }
-}
-#endif
-
-
-/**
- * Initialize the texture image's FetchTexelc and FetchTexelf methods.
- */
-void
-_mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims)
-{
- gl_format format = texImage->TexFormat;
-
- ASSERT(dims == 1 || dims == 2 || dims == 3);
-
- if (texImage->TexObject->sRGBDecode == GL_SKIP_DECODE_EXT &&
- _mesa_get_format_color_encoding(format) == GL_SRGB) {
- format = _mesa_get_srgb_format_linear(format);
- }
-
- texImage->FetchTexelf = _mesa_get_texel_fetch_func(format, dims);
-
- texImage->FetchTexelc = fetch_texel_float_to_chan;
-
- ASSERT(texImage->FetchTexelc);
- ASSERT(texImage->FetchTexelf);
-}
-
-void
-_mesa_update_fetch_functions(struct gl_texture_object *texObj)
-{
- GLuint face, i;
- GLuint dims;
-
- dims = _mesa_get_texture_dimensions(texObj->Target);
-
- for (face = 0; face < 6; face++) {
- for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
- if (texObj->Image[face][i]) {
- _mesa_set_fetch_functions(texObj->Image[face][i], dims);
- }
- }
- }
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2009 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file texfetch.c
+ *
+ * Texel fetch/store functions
+ *
+ * \author Gareth Hughes
+ */
+
+
+#include "colormac.h"
+#include "macros.h"
+#include "texcompress.h"
+#include "texcompress_fxt1.h"
+#include "texcompress_s3tc.h"
+#include "texcompress_rgtc.h"
+#include "texfetch.h"
+#include "teximage.h"
+
+
+/**
+ * Convert an 8-bit sRGB value from non-linear space to a
+ * linear RGB value in [0, 1].
+ * Implemented with a 256-entry lookup table.
+ */
+static INLINE GLfloat
+nonlinear_to_linear(GLubyte cs8)
+{
+ static GLfloat table[256];
+ static GLboolean tableReady = GL_FALSE;
+ if (!tableReady) {
+ /* compute lookup table now */
+ GLuint i;
+ for (i = 0; i < 256; i++) {
+ const GLfloat cs = UBYTE_TO_FLOAT(i);
+ if (cs <= 0.04045) {
+ table[i] = cs / 12.92f;
+ }
+ else {
+ table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
+ }
+ }
+ tableReady = GL_TRUE;
+ }
+ return table[cs8];
+}
+
+
+
+/* Texel fetch routines for all supported formats
+ */
+#define DIM 1
+#include "texfetch_tmp.h"
+
+#define DIM 2
+#include "texfetch_tmp.h"
+
+#define DIM 3
+#include "texfetch_tmp.h"
+
+/**
+ * Null texel fetch function.
+ *
+ * Have to have this so the FetchTexel function pointer is never NULL.
+ */
+static void fetch_null_texelf( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ (void) texImage; (void) i; (void) j; (void) k;
+ texel[RCOMP] = 0.0;
+ texel[GCOMP] = 0.0;
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 0.0;
+ _mesa_warning(NULL, "fetch_null_texelf() called!");
+}
+
+static void store_null_texel(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ (void) texImage;
+ (void) i;
+ (void) j;
+ (void) k;
+ (void) texel;
+ /* no-op */
+}
+
+
+
+/**
+ * Table to map MESA_FORMAT_ to texel fetch/store funcs.
+ * XXX this is somewhat temporary.
+ */
+static struct {
+ gl_format Name;
+ FetchTexelFuncF Fetch1D;
+ FetchTexelFuncF Fetch2D;
+ FetchTexelFuncF Fetch3D;
+ StoreTexelFunc StoreTexel;
+}
+texfetch_funcs[MESA_FORMAT_COUNT] =
+{
+ {
+ MESA_FORMAT_NONE,
+ fetch_null_texelf,
+ fetch_null_texelf,
+ fetch_null_texelf,
+ store_null_texel
+ },
+
+ {
+ MESA_FORMAT_RGBA8888,
+ fetch_texel_1d_f_rgba8888,
+ fetch_texel_2d_f_rgba8888,
+ fetch_texel_3d_f_rgba8888,
+ store_texel_rgba8888
+ },
+ {
+ MESA_FORMAT_RGBA8888_REV,
+ fetch_texel_1d_f_rgba8888_rev,
+ fetch_texel_2d_f_rgba8888_rev,
+ fetch_texel_3d_f_rgba8888_rev,
+ store_texel_rgba8888_rev
+ },
+ {
+ MESA_FORMAT_ARGB8888,
+ fetch_texel_1d_f_argb8888,
+ fetch_texel_2d_f_argb8888,
+ fetch_texel_3d_f_argb8888,
+ store_texel_argb8888
+ },
+ {
+ MESA_FORMAT_ARGB8888_REV,
+ fetch_texel_1d_f_argb8888_rev,
+ fetch_texel_2d_f_argb8888_rev,
+ fetch_texel_3d_f_argb8888_rev,
+ store_texel_argb8888_rev
+ },
+ {
+ MESA_FORMAT_XRGB8888,
+ fetch_texel_1d_f_xrgb8888,
+ fetch_texel_2d_f_xrgb8888,
+ fetch_texel_3d_f_xrgb8888,
+ store_texel_xrgb8888
+ },
+ {
+ MESA_FORMAT_XRGB8888_REV,
+ fetch_texel_1d_f_xrgb8888_rev,
+ fetch_texel_2d_f_xrgb8888_rev,
+ fetch_texel_3d_f_xrgb8888_rev,
+ store_texel_xrgb8888_rev,
+ },
+ {
+ MESA_FORMAT_RGB888,
+ fetch_texel_1d_f_rgb888,
+ fetch_texel_2d_f_rgb888,
+ fetch_texel_3d_f_rgb888,
+ store_texel_rgb888
+ },
+ {
+ MESA_FORMAT_BGR888,
+ fetch_texel_1d_f_bgr888,
+ fetch_texel_2d_f_bgr888,
+ fetch_texel_3d_f_bgr888,
+ store_texel_bgr888
+ },
+ {
+ MESA_FORMAT_RGB565,
+ fetch_texel_1d_f_rgb565,
+ fetch_texel_2d_f_rgb565,
+ fetch_texel_3d_f_rgb565,
+ store_texel_rgb565
+ },
+ {
+ MESA_FORMAT_RGB565_REV,
+ fetch_texel_1d_f_rgb565_rev,
+ fetch_texel_2d_f_rgb565_rev,
+ fetch_texel_3d_f_rgb565_rev,
+ store_texel_rgb565_rev
+ },
+ {
+ MESA_FORMAT_ARGB4444,
+ fetch_texel_1d_f_argb4444,
+ fetch_texel_2d_f_argb4444,
+ fetch_texel_3d_f_argb4444,
+ store_texel_argb4444
+ },
+ {
+ MESA_FORMAT_ARGB4444_REV,
+ fetch_texel_1d_f_argb4444_rev,
+ fetch_texel_2d_f_argb4444_rev,
+ fetch_texel_3d_f_argb4444_rev,
+ store_texel_argb4444_rev
+ },
+ {
+ MESA_FORMAT_RGBA5551,
+ fetch_texel_1d_f_rgba5551,
+ fetch_texel_2d_f_rgba5551,
+ fetch_texel_3d_f_rgba5551,
+ store_texel_rgba5551
+ },
+ {
+ MESA_FORMAT_ARGB1555,
+ fetch_texel_1d_f_argb1555,
+ fetch_texel_2d_f_argb1555,
+ fetch_texel_3d_f_argb1555,
+ store_texel_argb1555
+ },
+ {
+ MESA_FORMAT_ARGB1555_REV,
+ fetch_texel_1d_f_argb1555_rev,
+ fetch_texel_2d_f_argb1555_rev,
+ fetch_texel_3d_f_argb1555_rev,
+ store_texel_argb1555_rev
+ },
+ {
+ MESA_FORMAT_AL44,
+ fetch_texel_1d_f_al44,
+ fetch_texel_2d_f_al44,
+ fetch_texel_3d_f_al44,
+ store_texel_al44
+ },
+ {
+ MESA_FORMAT_AL88,
+ fetch_texel_1d_f_al88,
+ fetch_texel_2d_f_al88,
+ fetch_texel_3d_f_al88,
+ store_texel_al88
+ },
+ {
+ MESA_FORMAT_AL88_REV,
+ fetch_texel_1d_f_al88_rev,
+ fetch_texel_2d_f_al88_rev,
+ fetch_texel_3d_f_al88_rev,
+ store_texel_al88_rev
+ },
+ {
+ MESA_FORMAT_AL1616,
+ fetch_texel_1d_f_al1616,
+ fetch_texel_2d_f_al1616,
+ fetch_texel_3d_f_al1616,
+ store_texel_al1616
+ },
+ {
+ MESA_FORMAT_AL1616_REV,
+ fetch_texel_1d_f_al1616_rev,
+ fetch_texel_2d_f_al1616_rev,
+ fetch_texel_3d_f_al1616_rev,
+ store_texel_al1616_rev
+ },
+ {
+ MESA_FORMAT_RGB332,
+ fetch_texel_1d_f_rgb332,
+ fetch_texel_2d_f_rgb332,
+ fetch_texel_3d_f_rgb332,
+ store_texel_rgb332
+ },
+ {
+ MESA_FORMAT_A8,
+ fetch_texel_1d_f_a8,
+ fetch_texel_2d_f_a8,
+ fetch_texel_3d_f_a8,
+ store_texel_a8
+ },
+ {
+ MESA_FORMAT_A16,
+ fetch_texel_1d_f_a16,
+ fetch_texel_2d_f_a16,
+ fetch_texel_3d_f_a16,
+ store_texel_a16
+ },
+ {
+ MESA_FORMAT_L8,
+ fetch_texel_1d_f_l8,
+ fetch_texel_2d_f_l8,
+ fetch_texel_3d_f_l8,
+ store_texel_l8
+ },
+ {
+ MESA_FORMAT_L16,
+ fetch_texel_1d_f_l16,
+ fetch_texel_2d_f_l16,
+ fetch_texel_3d_f_l16,
+ store_texel_l16
+ },
+ {
+ MESA_FORMAT_I8,
+ fetch_texel_1d_f_i8,
+ fetch_texel_2d_f_i8,
+ fetch_texel_3d_f_i8,
+ store_texel_i8
+ },
+ {
+ MESA_FORMAT_I16,
+ fetch_texel_1d_f_i16,
+ fetch_texel_2d_f_i16,
+ fetch_texel_3d_f_i16,
+ store_texel_i16
+ },
+ {
+ MESA_FORMAT_CI8,
+ fetch_texel_1d_f_ci8,
+ fetch_texel_2d_f_ci8,
+ fetch_texel_3d_f_ci8,
+ store_texel_ci8
+ },
+ {
+ MESA_FORMAT_YCBCR,
+ fetch_texel_1d_f_ycbcr,
+ fetch_texel_2d_f_ycbcr,
+ fetch_texel_3d_f_ycbcr,
+ store_texel_ycbcr
+ },
+ {
+ MESA_FORMAT_YCBCR_REV,
+ fetch_texel_1d_f_ycbcr_rev,
+ fetch_texel_2d_f_ycbcr_rev,
+ fetch_texel_3d_f_ycbcr_rev,
+ store_texel_ycbcr_rev
+ },
+ {
+ MESA_FORMAT_R8,
+ fetch_texel_1d_f_r8,
+ fetch_texel_2d_f_r8,
+ fetch_texel_3d_f_r8,
+ store_texel_r8,
+ },
+ {
+ MESA_FORMAT_RG88,
+ fetch_texel_1d_f_rg88,
+ fetch_texel_2d_f_rg88,
+ fetch_texel_3d_f_rg88,
+ store_texel_rg88,
+ },
+ {
+ MESA_FORMAT_RG88_REV,
+ fetch_texel_1d_f_rg88_rev,
+ fetch_texel_2d_f_rg88_rev,
+ fetch_texel_3d_f_rg88_rev,
+ store_texel_rg88_rev,
+ },
+ {
+ MESA_FORMAT_R16,
+ fetch_texel_1d_f_r16,
+ fetch_texel_2d_f_r16,
+ fetch_texel_3d_f_r16,
+ store_texel_r16,
+ },
+ {
+ MESA_FORMAT_RG1616,
+ fetch_texel_1d_f_rg1616,
+ fetch_texel_2d_f_rg1616,
+ fetch_texel_3d_f_rg1616,
+ store_texel_rg1616,
+ },
+ {
+ MESA_FORMAT_RG1616_REV,
+ fetch_texel_1d_f_rg1616_rev,
+ fetch_texel_2d_f_rg1616_rev,
+ fetch_texel_3d_f_rg1616_rev,
+ store_texel_rg1616_rev,
+ },
+ {
+ MESA_FORMAT_ARGB2101010,
+ fetch_texel_1d_f_argb2101010,
+ fetch_texel_2d_f_argb2101010,
+ fetch_texel_3d_f_argb2101010,
+ store_texel_argb2101010
+ },
+ {
+ MESA_FORMAT_Z24_S8,
+ fetch_texel_1d_f_z24_s8,
+ fetch_texel_2d_f_z24_s8,
+ fetch_texel_3d_f_z24_s8,
+ store_texel_z24_s8
+ },
+ {
+ MESA_FORMAT_S8_Z24,
+ fetch_texel_1d_f_s8_z24,
+ fetch_texel_2d_f_s8_z24,
+ fetch_texel_3d_f_s8_z24,
+ store_texel_s8_z24
+ },
+ {
+ MESA_FORMAT_Z16,
+ fetch_texel_1d_f_z16,
+ fetch_texel_2d_f_z16,
+ fetch_texel_3d_f_z16,
+ store_texel_z16
+ },
+ {
+ MESA_FORMAT_X8_Z24,
+ fetch_texel_1d_f_s8_z24,
+ fetch_texel_2d_f_s8_z24,
+ fetch_texel_3d_f_s8_z24,
+ store_texel_s8_z24
+ },
+ {
+ MESA_FORMAT_Z24_X8,
+ fetch_texel_1d_f_z24_s8,
+ fetch_texel_2d_f_z24_s8,
+ fetch_texel_3d_f_z24_s8,
+ store_texel_z24_s8
+ },
+ {
+ MESA_FORMAT_Z32,
+ fetch_texel_1d_f_z32,
+ fetch_texel_2d_f_z32,
+ fetch_texel_3d_f_z32,
+ store_texel_z32
+ },
+ {
+ MESA_FORMAT_S8,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SRGB8,
+ fetch_texel_1d_srgb8,
+ fetch_texel_2d_srgb8,
+ fetch_texel_3d_srgb8,
+ store_texel_srgb8
+ },
+ {
+ MESA_FORMAT_SRGBA8,
+ fetch_texel_1d_srgba8,
+ fetch_texel_2d_srgba8,
+ fetch_texel_3d_srgba8,
+ store_texel_srgba8
+ },
+ {
+ MESA_FORMAT_SARGB8,
+ fetch_texel_1d_sargb8,
+ fetch_texel_2d_sargb8,
+ fetch_texel_3d_sargb8,
+ store_texel_sargb8
+ },
+ {
+ MESA_FORMAT_SL8,
+ fetch_texel_1d_sl8,
+ fetch_texel_2d_sl8,
+ fetch_texel_3d_sl8,
+ store_texel_sl8
+ },
+ {
+ MESA_FORMAT_SLA8,
+ fetch_texel_1d_sla8,
+ fetch_texel_2d_sla8,
+ fetch_texel_3d_sla8,
+ store_texel_sla8
+ },
+ {
+ MESA_FORMAT_SRGB_DXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_srgb_dxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_srgba_dxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT3,
+ NULL,
+ _mesa_fetch_texel_2d_f_srgba_dxt3,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SRGBA_DXT5,
+ NULL,
+ _mesa_fetch_texel_2d_f_srgba_dxt5,
+ NULL,
+ NULL
+ },
+
+ {
+ MESA_FORMAT_RGB_FXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgb_fxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA_FXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgba_fxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGB_DXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgb_dxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA_DXT1,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgba_dxt1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA_DXT3,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgba_dxt3,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA_DXT5,
+ NULL,
+ _mesa_fetch_texel_2d_f_rgba_dxt5,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RGBA_FLOAT32,
+ fetch_texel_1d_f_rgba_f32,
+ fetch_texel_2d_f_rgba_f32,
+ fetch_texel_3d_f_rgba_f32,
+ store_texel_rgba_f32
+ },
+ {
+ MESA_FORMAT_RGBA_FLOAT16,
+ fetch_texel_1d_f_rgba_f16,
+ fetch_texel_2d_f_rgba_f16,
+ fetch_texel_3d_f_rgba_f16,
+ store_texel_rgba_f16
+ },
+ {
+ MESA_FORMAT_RGB_FLOAT32,
+ fetch_texel_1d_f_rgb_f32,
+ fetch_texel_2d_f_rgb_f32,
+ fetch_texel_3d_f_rgb_f32,
+ store_texel_rgb_f32
+ },
+ {
+ MESA_FORMAT_RGB_FLOAT16,
+ fetch_texel_1d_f_rgb_f16,
+ fetch_texel_2d_f_rgb_f16,
+ fetch_texel_3d_f_rgb_f16,
+ store_texel_rgb_f16
+ },
+ {
+ MESA_FORMAT_ALPHA_FLOAT32,
+ fetch_texel_1d_f_alpha_f32,
+ fetch_texel_2d_f_alpha_f32,
+ fetch_texel_3d_f_alpha_f32,
+ store_texel_alpha_f32
+ },
+ {
+ MESA_FORMAT_ALPHA_FLOAT16,
+ fetch_texel_1d_f_alpha_f16,
+ fetch_texel_2d_f_alpha_f16,
+ fetch_texel_3d_f_alpha_f16,
+ store_texel_alpha_f16
+ },
+ {
+ MESA_FORMAT_LUMINANCE_FLOAT32,
+ fetch_texel_1d_f_luminance_f32,
+ fetch_texel_2d_f_luminance_f32,
+ fetch_texel_3d_f_luminance_f32,
+ store_texel_luminance_f32
+ },
+ {
+ MESA_FORMAT_LUMINANCE_FLOAT16,
+ fetch_texel_1d_f_luminance_f16,
+ fetch_texel_2d_f_luminance_f16,
+ fetch_texel_3d_f_luminance_f16,
+ store_texel_luminance_f16
+ },
+ {
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
+ fetch_texel_1d_f_luminance_alpha_f32,
+ fetch_texel_2d_f_luminance_alpha_f32,
+ fetch_texel_3d_f_luminance_alpha_f32,
+ store_texel_luminance_alpha_f32
+ },
+ {
+ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
+ fetch_texel_1d_f_luminance_alpha_f16,
+ fetch_texel_2d_f_luminance_alpha_f16,
+ fetch_texel_3d_f_luminance_alpha_f16,
+ store_texel_luminance_alpha_f16
+ },
+ {
+ MESA_FORMAT_INTENSITY_FLOAT32,
+ fetch_texel_1d_f_intensity_f32,
+ fetch_texel_2d_f_intensity_f32,
+ fetch_texel_3d_f_intensity_f32,
+ store_texel_intensity_f32
+ },
+ {
+ MESA_FORMAT_INTENSITY_FLOAT16,
+ fetch_texel_1d_f_intensity_f16,
+ fetch_texel_2d_f_intensity_f16,
+ fetch_texel_3d_f_intensity_f16,
+ store_texel_intensity_f16
+ },
+
+ /* non-normalized, signed int */
+ {
+ MESA_FORMAT_RGBA_INT8,
+ fetch_texel_1d_rgba_int8,
+ fetch_texel_2d_rgba_int8,
+ fetch_texel_3d_rgba_int8,
+ store_texel_rgba_int8
+ },
+ {
+ MESA_FORMAT_RGBA_INT16,
+ fetch_texel_1d_rgba_int16,
+ fetch_texel_2d_rgba_int16,
+ fetch_texel_3d_rgba_int16,
+ store_texel_rgba_int16
+ },
+ {
+ MESA_FORMAT_RGBA_INT32,
+ fetch_texel_1d_rgba_int32,
+ fetch_texel_2d_rgba_int32,
+ fetch_texel_3d_rgba_int32,
+ store_texel_rgba_int32
+ },
+
+ /* non-normalized, unsigned int */
+ {
+ MESA_FORMAT_RGBA_UINT8,
+ fetch_texel_1d_rgba_uint8,
+ fetch_texel_2d_rgba_uint8,
+ fetch_texel_3d_rgba_uint8,
+ store_texel_rgba_uint8
+ },
+ {
+ MESA_FORMAT_RGBA_UINT16,
+ fetch_texel_1d_rgba_uint16,
+ fetch_texel_2d_rgba_uint16,
+ fetch_texel_3d_rgba_uint16,
+ store_texel_rgba_uint16
+ },
+ {
+ MESA_FORMAT_RGBA_UINT32,
+ fetch_texel_1d_rgba_uint32,
+ fetch_texel_2d_rgba_uint32,
+ fetch_texel_3d_rgba_uint32,
+ store_texel_rgba_uint32
+ },
+
+ /* dudv */
+ {
+ MESA_FORMAT_DUDV8,
+ fetch_texel_1d_dudv8,
+ fetch_texel_2d_dudv8,
+ fetch_texel_3d_dudv8,
+ NULL
+ },
+
+ /* signed, normalized */
+ {
+ MESA_FORMAT_SIGNED_R8,
+ fetch_texel_1d_signed_r8,
+ fetch_texel_2d_signed_r8,
+ fetch_texel_3d_signed_r8,
+ store_texel_signed_r8
+ },
+ {
+ MESA_FORMAT_SIGNED_RG88,
+ fetch_texel_1d_signed_rg88,
+ fetch_texel_2d_signed_rg88,
+ fetch_texel_3d_signed_rg88,
+ store_texel_signed_rg88
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBX8888,
+ fetch_texel_1d_signed_rgbx8888,
+ fetch_texel_2d_signed_rgbx8888,
+ fetch_texel_3d_signed_rgbx8888,
+ store_texel_signed_rgbx8888
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA8888,
+ fetch_texel_1d_signed_rgba8888,
+ fetch_texel_2d_signed_rgba8888,
+ fetch_texel_3d_signed_rgba8888,
+ store_texel_signed_rgba8888
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA8888_REV,
+ fetch_texel_1d_signed_rgba8888_rev,
+ fetch_texel_2d_signed_rgba8888_rev,
+ fetch_texel_3d_signed_rgba8888_rev,
+ store_texel_signed_rgba8888_rev
+ },
+ {
+ MESA_FORMAT_SIGNED_R_16,
+ fetch_texel_1d_signed_r_16,
+ fetch_texel_2d_signed_r_16,
+ fetch_texel_3d_signed_r_16,
+ store_texel_signed_r_16
+ },
+ {
+ MESA_FORMAT_SIGNED_RG_16,
+ fetch_texel_1d_signed_rg_16,
+ fetch_texel_2d_signed_rg_16,
+ fetch_texel_3d_signed_rg_16,
+ store_texel_signed_rg_16
+ },
+ {
+ MESA_FORMAT_SIGNED_RGB_16,
+ fetch_texel_1d_signed_rgb_16,
+ fetch_texel_2d_signed_rgb_16,
+ fetch_texel_3d_signed_rgb_16,
+ store_texel_signed_rgb_16
+ },
+ {
+ MESA_FORMAT_SIGNED_RGBA_16,
+ fetch_texel_1d_signed_rgba_16,
+ fetch_texel_2d_signed_rgba_16,
+ fetch_texel_3d_signed_rgba_16,
+ store_texel_signed_rgba_16
+ },
+ {
+ MESA_FORMAT_RGBA_16,
+ fetch_texel_1d_rgba_16,
+ fetch_texel_2d_rgba_16,
+ fetch_texel_3d_rgba_16,
+ store_texel_rgba_16
+ },
+ {
+ MESA_FORMAT_RED_RGTC1,
+ NULL,
+ _mesa_fetch_texel_2d_f_red_rgtc1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SIGNED_RED_RGTC1,
+ NULL,
+ _mesa_fetch_texel_2d_f_signed_red_rgtc1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_RG_RGTC2,
+ NULL,
+ _mesa_fetch_texel_2d_f_rg_rgtc2,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SIGNED_RG_RGTC2,
+ NULL,
+ _mesa_fetch_texel_2d_f_signed_rg_rgtc2,
+ NULL,
+ NULL
+ },
+};
+
+
+FetchTexelFuncF
+_mesa_get_texel_fetch_func(gl_format format, GLuint dims)
+{
+#ifdef DEBUG
+ /* check that the table entries are sorted by format name */
+ gl_format fmt;
+ for (fmt = 0; fmt < MESA_FORMAT_COUNT; fmt++) {
+ assert(texfetch_funcs[fmt].Name == fmt);
+ }
+#endif
+
+ assert(Elements(texfetch_funcs) == MESA_FORMAT_COUNT);
+ assert(format < MESA_FORMAT_COUNT);
+
+ switch (dims) {
+ case 1:
+ return texfetch_funcs[format].Fetch1D;
+ case 2:
+ return texfetch_funcs[format].Fetch2D;
+ case 3:
+ return texfetch_funcs[format].Fetch3D;
+ default:
+ assert(0 && "bad dims in _mesa_get_texel_fetch_func");
+ return NULL;
+ }
+}
+
+
+StoreTexelFunc
+_mesa_get_texel_store_func(gl_format format)
+{
+ assert(format < MESA_FORMAT_COUNT);
+ return texfetch_funcs[format].StoreTexel;
+}
+
+
+/**
+ * Adaptor for fetching a GLchan texel from a float-valued texture.
+ */
+static void
+fetch_texel_float_to_chan(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLchan *texelOut)
+{
+ GLfloat temp[4];
+ GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
+
+ ASSERT(texImage->FetchTexelf);
+ texImage->FetchTexelf(texImage, i, j, k, temp);
+ if (baseFormat == GL_DEPTH_COMPONENT ||
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
+ /* just one channel */
+ UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
+ }
+ else {
+ /* four channels */
+ UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
+ UNCLAMPED_FLOAT_TO_CHAN(texelOut[1], temp[1]);
+ UNCLAMPED_FLOAT_TO_CHAN(texelOut[2], temp[2]);
+ UNCLAMPED_FLOAT_TO_CHAN(texelOut[3], temp[3]);
+ }
+}
+
+
+#if 0
+/**
+ * Adaptor for fetching a float texel from a GLchan-valued texture.
+ */
+static void
+fetch_texel_chan_to_float(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texelOut)
+{
+ GLchan temp[4];
+ GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
+
+ ASSERT(texImage->FetchTexelc);
+ texImage->FetchTexelc(texImage, i, j, k, temp);
+ if (baseFormat == GL_DEPTH_COMPONENT ||
+ baseFormat == GL_DEPTH_STENCIL_EXT) {
+ /* just one channel */
+ texelOut[0] = CHAN_TO_FLOAT(temp[0]);
+ }
+ else {
+ /* four channels */
+ texelOut[0] = CHAN_TO_FLOAT(temp[0]);
+ texelOut[1] = CHAN_TO_FLOAT(temp[1]);
+ texelOut[2] = CHAN_TO_FLOAT(temp[2]);
+ texelOut[3] = CHAN_TO_FLOAT(temp[3]);
+ }
+}
+#endif
+
+
+/**
+ * Initialize the texture image's FetchTexelc and FetchTexelf methods.
+ */
+void
+_mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims)
+{
+ gl_format format = texImage->TexFormat;
+
+ ASSERT(dims == 1 || dims == 2 || dims == 3);
+
+ if (texImage->TexObject->sRGBDecode == GL_SKIP_DECODE_EXT &&
+ _mesa_get_format_color_encoding(format) == GL_SRGB) {
+ format = _mesa_get_srgb_format_linear(format);
+ }
+
+ texImage->FetchTexelf = _mesa_get_texel_fetch_func(format, dims);
+
+ texImage->FetchTexelc = fetch_texel_float_to_chan;
+
+ ASSERT(texImage->FetchTexelc);
+ ASSERT(texImage->FetchTexelf);
+}
+
+void
+_mesa_update_fetch_functions(struct gl_texture_object *texObj)
+{
+ GLuint face, i;
+ GLuint dims;
+
+ dims = _mesa_get_texture_dimensions(texObj->Target);
+
+ for (face = 0; face < 6; face++) {
+ for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
+ if (texObj->Image[face][i]) {
+ _mesa_set_fetch_functions(texObj->Image[face][i], dims);
+ }
+ }
+ }
+}
diff --git a/mesalib/src/mesa/main/texformat.c b/mesalib/src/mesa/main/texformat.c
index 72025cf82..8040fac7d 100644
--- a/mesalib/src/mesa/main/texformat.c
+++ b/mesalib/src/mesa/main/texformat.c
@@ -1,627 +1,627 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.7
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (c) 2008-2009 VMware, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file texformat.c
- * Texture formats.
- *
- * \author Gareth Hughes
- * \author Brian Paul
- */
-
-
-#include "context.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "texcompress.h"
-#include "texformat.h"
-
-#define RETURN_IF_SUPPORTED(f) do { \
- if (ctx->TextureFormatSupported[f]) \
- return f; \
-} while (0)
-
-/**
- * Choose an appropriate texture format given the format, type and
- * internalFormat parameters passed to glTexImage().
- *
- * \param ctx the GL context.
- * \param internalFormat user's prefered internal texture format.
- * \param format incoming image pixel format.
- * \param type incoming image data type.
- *
- * \return a pointer to a gl_texture_format object which describes the
- * choosen texture format, or NULL on failure.
- *
- * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
- * will typically override this function with a specialized version.
- */
-gl_format
-_mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
- GLenum format, GLenum type )
-{
- (void) format;
- (void) type;
-
- switch (internalFormat) {
- /* shallow RGBA formats */
- case 4:
- case GL_RGBA:
- if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
- } else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555);
- }
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
- break;
-
- case GL_RGBA8:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
- break;
- case GL_RGB5_A1:
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555);
- break;
- case GL_RGBA2:
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444_REV); /* just to test another format*/
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
- break;
- case GL_RGBA4:
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
- break;
-
- /* deep RGBA formats */
- case GL_RGB10_A2:
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010);
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
- break;
- case GL_RGBA12:
- case GL_RGBA16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
- break;
-
- /* shallow RGB formats */
- case 3:
- case GL_RGB:
- case GL_RGB8:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
- break;
- case GL_R3_G3_B2:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB332);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
- break;
- case GL_RGB4:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565_REV); /* just to test another format */
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
- break;
- case GL_RGB5:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
- break;
-
- /* deep RGB formats */
- case GL_RGB10:
- case GL_RGB12:
- case GL_RGB16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
- break;
-
- /* Alpha formats */
- case GL_ALPHA:
- case GL_ALPHA4:
- case GL_ALPHA8:
- RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
- break;
-
- case GL_ALPHA12:
- case GL_ALPHA16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_A16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
- break;
-
- /* Luminance formats */
- case 1:
- case GL_LUMINANCE:
- case GL_LUMINANCE4:
- case GL_LUMINANCE8:
- RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
- break;
-
- case GL_LUMINANCE12:
- case GL_LUMINANCE16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_L16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
- break;
-
- /* Luminance/Alpha formats */
- case GL_LUMINANCE4_ALPHA4:
- RETURN_IF_SUPPORTED(MESA_FORMAT_AL44);
- RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
- break;
-
- case 2:
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE6_ALPHA2:
- case GL_LUMINANCE8_ALPHA8:
- RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
- break;
-
- case GL_LUMINANCE12_ALPHA4:
- case GL_LUMINANCE12_ALPHA12:
- case GL_LUMINANCE16_ALPHA16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_AL1616);
- RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
- break;
-
- case GL_INTENSITY:
- case GL_INTENSITY4:
- case GL_INTENSITY8:
- RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
- break;
-
- case GL_INTENSITY12:
- case GL_INTENSITY16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_I16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
- break;
-
- case GL_COLOR_INDEX:
- case GL_COLOR_INDEX1_EXT:
- case GL_COLOR_INDEX2_EXT:
- case GL_COLOR_INDEX4_EXT:
- case GL_COLOR_INDEX12_EXT:
- case GL_COLOR_INDEX16_EXT:
- case GL_COLOR_INDEX8_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_CI8);
- break;
-
- default:
- ; /* fallthrough */
- }
-
- if (ctx->Extensions.ARB_depth_texture) {
- switch (internalFormat) {
- case GL_DEPTH_COMPONENT:
- case GL_DEPTH_COMPONENT24:
- case GL_DEPTH_COMPONENT32:
- RETURN_IF_SUPPORTED(MESA_FORMAT_Z32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
- break;
- case GL_DEPTH_COMPONENT16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_Z16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
- default:
- ; /* fallthrough */
- }
- }
-
- switch (internalFormat) {
- case GL_COMPRESSED_ALPHA_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
- break;
- case GL_COMPRESSED_LUMINANCE_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
- break;
- case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
- break;
- case GL_COMPRESSED_INTENSITY_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
- break;
- case GL_COMPRESSED_RGB_ARB:
- if (ctx->Extensions.EXT_texture_compression_s3tc ||
- ctx->Extensions.S3_s3tc)
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
- if (ctx->Extensions.TDFX_texture_compression_FXT1)
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
- break;
- case GL_COMPRESSED_RGBA_ARB:
- if (ctx->Extensions.EXT_texture_compression_s3tc ||
- ctx->Extensions.S3_s3tc)
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); /* Not rgba_dxt1, see spec */
- if (ctx->Extensions.TDFX_texture_compression_FXT1)
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
- break;
- default:
- ; /* fallthrough */
- }
-
- if (ctx->Extensions.MESA_ycbcr_texture) {
- if (internalFormat == GL_YCBCR_MESA) {
- if (type == GL_UNSIGNED_SHORT_8_8_MESA)
- RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR);
- else
- RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR_REV);
- }
- }
-
-#if FEATURE_texture_fxt1
- if (ctx->Extensions.TDFX_texture_compression_FXT1) {
- switch (internalFormat) {
- case GL_COMPRESSED_RGB_FXT1_3DFX:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1);
- break;
- case GL_COMPRESSED_RGBA_FXT1_3DFX:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1);
- break;
- default:
- ; /* fallthrough */
- }
- }
-#endif
-
-#if FEATURE_texture_s3tc
- if (ctx->Extensions.EXT_texture_compression_s3tc) {
- switch (internalFormat) {
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
- break;
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT1);
- break;
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3);
- break;
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT5);
- break;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.S3_s3tc) {
- switch (internalFormat) {
- case GL_RGB_S3TC:
- case GL_RGB4_S3TC:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
- break;
- case GL_RGBA_S3TC:
- case GL_RGBA4_S3TC:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3);
- break;
- default:
- ; /* fallthrough */
- }
- }
-#endif
-
- if (ctx->Extensions.ARB_texture_float) {
- switch (internalFormat) {
- case GL_ALPHA16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16);
- break;
- case GL_ALPHA32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
- break;
- case GL_LUMINANCE16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16);
- break;
- case GL_LUMINANCE32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
- break;
- case GL_LUMINANCE_ALPHA16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16);
- break;
- case GL_LUMINANCE_ALPHA32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
- break;
- case GL_INTENSITY16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16);
- break;
- case GL_INTENSITY32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
- break;
- case GL_RGB16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
- break;
- case GL_RGB32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
- break;
- case GL_RGBA16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
- break;
- case GL_RGBA32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.EXT_packed_depth_stencil) {
- switch (internalFormat) {
- case GL_DEPTH_STENCIL_EXT:
- case GL_DEPTH24_STENCIL8_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_S8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
- break;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.ATI_envmap_bumpmap) {
- switch (internalFormat) {
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- RETURN_IF_SUPPORTED(MESA_FORMAT_DUDV8);
- break;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.MESA_texture_signed_rgba) {
- switch (internalFormat) {
- case GL_RGBA_SNORM:
- case GL_RGBA8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
- break;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->VersionMajor * 10 + ctx->VersionMinor >= 31) {
- switch (internalFormat) {
- case GL_RED_SNORM:
- case GL_R8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R8);
- break;
- case GL_RG_SNORM:
- case GL_RG8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG88);
- break;
- case GL_RGB_SNORM:
- case GL_RGB8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888);
- break;
- case GL_RGBA_SNORM:
- case GL_RGBA8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- break;
- case GL_R16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R_16);
- break;
- case GL_RG16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG_16);
- break;
- case GL_RGB16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGB_16);
- break;
- case GL_RGBA16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
- break;
- default:
- ; /* fall-through */
- }
- }
-
-#if FEATURE_EXT_texture_sRGB
- if (ctx->Extensions.EXT_texture_sRGB) {
- switch (internalFormat) {
- case GL_SRGB_EXT:
- case GL_SRGB8_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
- case GL_SRGB_ALPHA_EXT:
- case GL_SRGB8_ALPHA8_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
- case GL_SLUMINANCE_EXT:
- case GL_SLUMINANCE8_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SL8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
- case GL_SLUMINANCE_ALPHA_EXT:
- case GL_SLUMINANCE8_ALPHA8_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
- case GL_COMPRESSED_SLUMINANCE_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SL8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
- case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
- case GL_COMPRESSED_SRGB_EXT:
-#if FEATURE_texture_s3tc
- if (ctx->Extensions.EXT_texture_compression_s3tc)
- RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
-#endif
- RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
- case GL_COMPRESSED_SRGB_ALPHA_EXT:
-#if FEATURE_texture_s3tc
- if (ctx->Extensions.EXT_texture_compression_s3tc)
- RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); /* Not srgba_dxt1, see spec */
-#endif
- RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
-#if FEATURE_texture_s3tc
- case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
- if (ctx->Extensions.EXT_texture_compression_s3tc)
- RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
- if (ctx->Extensions.EXT_texture_compression_s3tc)
- RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT1);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
- if (ctx->Extensions.EXT_texture_compression_s3tc)
- RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
- if (ctx->Extensions.EXT_texture_compression_s3tc)
- RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT5);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
- break;
-#endif
- default:
- ; /* fallthrough */
- }
- }
-#endif /* FEATURE_EXT_texture_sRGB */
-
- if (ctx->Extensions.EXT_texture_integer) {
- switch (internalFormat) {
- case GL_RGBA32UI_EXT:
- case GL_RGB32UI_EXT:
- case GL_ALPHA32UI_EXT:
- case GL_INTENSITY32UI_EXT:
- case GL_LUMINANCE32UI_EXT:
- case GL_LUMINANCE_ALPHA32UI_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
- break;
- case GL_RGBA16UI_EXT:
- case GL_RGB16UI_EXT:
- case GL_ALPHA16UI_EXT:
- case GL_INTENSITY16UI_EXT:
- case GL_LUMINANCE16UI_EXT:
- case GL_LUMINANCE_ALPHA16UI_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
- break;
- case GL_RGBA8UI_EXT:
- case GL_RGB8UI_EXT:
- case GL_ALPHA8UI_EXT:
- case GL_INTENSITY8UI_EXT:
- case GL_LUMINANCE8UI_EXT:
- case GL_LUMINANCE_ALPHA8UI_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
- break;
- case GL_RGBA32I_EXT:
- case GL_RGB32I_EXT:
- case GL_ALPHA32I_EXT:
- case GL_INTENSITY32I_EXT:
- case GL_LUMINANCE32I_EXT:
- case GL_LUMINANCE_ALPHA32I_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
- break;
- case GL_RGBA16I_EXT:
- case GL_RGB16I_EXT:
- case GL_ALPHA16I_EXT:
- case GL_INTENSITY16I_EXT:
- case GL_LUMINANCE16I_EXT:
- case GL_LUMINANCE_ALPHA16I_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
- break;
- case GL_RGBA8I_EXT:
- case GL_RGB8I_EXT:
- case GL_ALPHA8I_EXT:
- case GL_INTENSITY8I_EXT:
- case GL_LUMINANCE8I_EXT:
- case GL_LUMINANCE_ALPHA8I_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
- break;
- }
- }
-
- if (ctx->Extensions.ARB_texture_rg) {
- switch (internalFormat) {
- case GL_R8:
- case GL_RED:
- case GL_COMPRESSED_RED:
- RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
- break;
-
- case GL_R16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_R16);
- break;
-
- case GL_RG:
- case GL_RG8:
- case GL_COMPRESSED_RG:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RG88);
- break;
-
- case GL_RG16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RG1616);
- break;
-
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.EXT_texture_format_BGRA8888) {
- switch (internalFormat) {
- case GL_BGRA:
- RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
- break;
-
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.ARB_texture_compression_rgtc) {
- switch (internalFormat) {
- case GL_COMPRESSED_RED_RGTC1:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RED_RGTC1);
- break;
- case GL_COMPRESSED_SIGNED_RED_RGTC1:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RED_RGTC1);
- break;
- case GL_COMPRESSED_RG_RGTC2:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2);
- break;
- case GL_COMPRESSED_SIGNED_RG_RGTC2:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG_RGTC2);
- break;
- default:
- ; /* fallthrough */
- }
- }
-
- _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
- return MESA_FORMAT_NONE;
-}
-
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008-2009 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file texformat.c
+ * Texture formats.
+ *
+ * \author Gareth Hughes
+ * \author Brian Paul
+ */
+
+
+#include "context.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "texcompress.h"
+#include "texformat.h"
+
+#define RETURN_IF_SUPPORTED(f) do { \
+ if (ctx->TextureFormatSupported[f]) \
+ return f; \
+} while (0)
+
+/**
+ * Choose an appropriate texture format given the format, type and
+ * internalFormat parameters passed to glTexImage().
+ *
+ * \param ctx the GL context.
+ * \param internalFormat user's prefered internal texture format.
+ * \param format incoming image pixel format.
+ * \param type incoming image data type.
+ *
+ * \return a pointer to a gl_texture_format object which describes the
+ * choosen texture format, or NULL on failure.
+ *
+ * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
+ * will typically override this function with a specialized version.
+ */
+gl_format
+_mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
+ GLenum format, GLenum type )
+{
+ (void) format;
+ (void) type;
+
+ switch (internalFormat) {
+ /* shallow RGBA formats */
+ case 4:
+ case GL_RGBA:
+ if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
+ } else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555);
+ }
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+ break;
+
+ case GL_RGBA8:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+ break;
+ case GL_RGB5_A1:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555);
+ break;
+ case GL_RGBA2:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444_REV); /* just to test another format*/
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
+ break;
+ case GL_RGBA4:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
+ break;
+
+ /* deep RGBA formats */
+ case GL_RGB10_A2:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+ break;
+ case GL_RGBA12:
+ case GL_RGBA16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+ break;
+
+ /* shallow RGB formats */
+ case 3:
+ case GL_RGB:
+ case GL_RGB8:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+ break;
+ case GL_R3_G3_B2:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB332);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+ break;
+ case GL_RGB4:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565_REV); /* just to test another format */
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
+ break;
+ case GL_RGB5:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
+ break;
+
+ /* deep RGB formats */
+ case GL_RGB10:
+ case GL_RGB12:
+ case GL_RGB16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+ break;
+
+ /* Alpha formats */
+ case GL_ALPHA:
+ case GL_ALPHA4:
+ case GL_ALPHA8:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
+ break;
+
+ case GL_ALPHA12:
+ case GL_ALPHA16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_A16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
+ break;
+
+ /* Luminance formats */
+ case 1:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE4:
+ case GL_LUMINANCE8:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
+ break;
+
+ case GL_LUMINANCE12:
+ case GL_LUMINANCE16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_L16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
+ break;
+
+ /* Luminance/Alpha formats */
+ case GL_LUMINANCE4_ALPHA4:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_AL44);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
+ break;
+
+ case 2:
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE6_ALPHA2:
+ case GL_LUMINANCE8_ALPHA8:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
+ break;
+
+ case GL_LUMINANCE12_ALPHA4:
+ case GL_LUMINANCE12_ALPHA12:
+ case GL_LUMINANCE16_ALPHA16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_AL1616);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
+ break;
+
+ case GL_INTENSITY:
+ case GL_INTENSITY4:
+ case GL_INTENSITY8:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
+ break;
+
+ case GL_INTENSITY12:
+ case GL_INTENSITY16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_I16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
+ break;
+
+ case GL_COLOR_INDEX:
+ case GL_COLOR_INDEX1_EXT:
+ case GL_COLOR_INDEX2_EXT:
+ case GL_COLOR_INDEX4_EXT:
+ case GL_COLOR_INDEX12_EXT:
+ case GL_COLOR_INDEX16_EXT:
+ case GL_COLOR_INDEX8_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_CI8);
+ break;
+
+ default:
+ ; /* fallthrough */
+ }
+
+ if (ctx->Extensions.ARB_depth_texture) {
+ switch (internalFormat) {
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_COMPONENT24:
+ case GL_DEPTH_COMPONENT32:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_Z32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
+ break;
+ case GL_DEPTH_COMPONENT16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_Z16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ switch (internalFormat) {
+ case GL_COMPRESSED_ALPHA_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
+ break;
+ case GL_COMPRESSED_LUMINANCE_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
+ break;
+ case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
+ break;
+ case GL_COMPRESSED_INTENSITY_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
+ break;
+ case GL_COMPRESSED_RGB_ARB:
+ if (ctx->Extensions.EXT_texture_compression_s3tc ||
+ ctx->Extensions.S3_s3tc)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
+ if (ctx->Extensions.TDFX_texture_compression_FXT1)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+ break;
+ case GL_COMPRESSED_RGBA_ARB:
+ if (ctx->Extensions.EXT_texture_compression_s3tc ||
+ ctx->Extensions.S3_s3tc)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); /* Not rgba_dxt1, see spec */
+ if (ctx->Extensions.TDFX_texture_compression_FXT1)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+
+ if (ctx->Extensions.MESA_ycbcr_texture) {
+ if (internalFormat == GL_YCBCR_MESA) {
+ if (type == GL_UNSIGNED_SHORT_8_8_MESA)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR);
+ else
+ RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR_REV);
+ }
+ }
+
+#if FEATURE_texture_fxt1
+ if (ctx->Extensions.TDFX_texture_compression_FXT1) {
+ switch (internalFormat) {
+ case GL_COMPRESSED_RGB_FXT1_3DFX:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1);
+ break;
+ case GL_COMPRESSED_RGBA_FXT1_3DFX:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+#endif
+
+#if FEATURE_texture_s3tc
+ if (ctx->Extensions.EXT_texture_compression_s3tc) {
+ switch (internalFormat) {
+ case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
+ break;
+ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT1);
+ break;
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3);
+ break;
+ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT5);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.S3_s3tc) {
+ switch (internalFormat) {
+ case GL_RGB_S3TC:
+ case GL_RGB4_S3TC:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
+ break;
+ case GL_RGBA_S3TC:
+ case GL_RGBA4_S3TC:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+#endif
+
+ if (ctx->Extensions.ARB_texture_float) {
+ switch (internalFormat) {
+ case GL_ALPHA16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16);
+ break;
+ case GL_ALPHA32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
+ break;
+ case GL_LUMINANCE16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16);
+ break;
+ case GL_LUMINANCE32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
+ break;
+ case GL_LUMINANCE_ALPHA16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16);
+ break;
+ case GL_LUMINANCE_ALPHA32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
+ break;
+ case GL_INTENSITY16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16);
+ break;
+ case GL_INTENSITY32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
+ break;
+ case GL_RGB16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
+ break;
+ case GL_RGB32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
+ break;
+ case GL_RGBA16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
+ break;
+ case GL_RGBA32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.EXT_packed_depth_stencil) {
+ switch (internalFormat) {
+ case GL_DEPTH_STENCIL_EXT:
+ case GL_DEPTH24_STENCIL8_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_S8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.ATI_envmap_bumpmap) {
+ switch (internalFormat) {
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_DUDV8);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.MESA_texture_signed_rgba) {
+ switch (internalFormat) {
+ case GL_RGBA_SNORM:
+ case GL_RGBA8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->VersionMajor * 10 + ctx->VersionMinor >= 31) {
+ switch (internalFormat) {
+ case GL_RED_SNORM:
+ case GL_R8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R8);
+ break;
+ case GL_RG_SNORM:
+ case GL_RG8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG88);
+ break;
+ case GL_RGB_SNORM:
+ case GL_RGB8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888);
+ break;
+ case GL_RGBA_SNORM:
+ case GL_RGBA8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ break;
+ case GL_R16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R_16);
+ break;
+ case GL_RG16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG_16);
+ break;
+ case GL_RGB16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGB_16);
+ break;
+ case GL_RGBA16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
+ break;
+ default:
+ ; /* fall-through */
+ }
+ }
+
+#if FEATURE_EXT_texture_sRGB
+ if (ctx->Extensions.EXT_texture_sRGB) {
+ switch (internalFormat) {
+ case GL_SRGB_EXT:
+ case GL_SRGB8_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+ case GL_SRGB_ALPHA_EXT:
+ case GL_SRGB8_ALPHA8_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+ case GL_SLUMINANCE_EXT:
+ case GL_SLUMINANCE8_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SL8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+ case GL_SLUMINANCE_ALPHA_EXT:
+ case GL_SLUMINANCE8_ALPHA8_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+ case GL_COMPRESSED_SLUMINANCE_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SL8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+ case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+ case GL_COMPRESSED_SRGB_EXT:
+#if FEATURE_texture_s3tc
+ if (ctx->Extensions.EXT_texture_compression_s3tc)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
+#endif
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+ case GL_COMPRESSED_SRGB_ALPHA_EXT:
+#if FEATURE_texture_s3tc
+ if (ctx->Extensions.EXT_texture_compression_s3tc)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); /* Not srgba_dxt1, see spec */
+#endif
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+#if FEATURE_texture_s3tc
+ case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
+ if (ctx->Extensions.EXT_texture_compression_s3tc)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
+ if (ctx->Extensions.EXT_texture_compression_s3tc)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT1);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
+ if (ctx->Extensions.EXT_texture_compression_s3tc)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
+ if (ctx->Extensions.EXT_texture_compression_s3tc)
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT5);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
+ break;
+#endif
+ default:
+ ; /* fallthrough */
+ }
+ }
+#endif /* FEATURE_EXT_texture_sRGB */
+
+ if (ctx->Extensions.EXT_texture_integer) {
+ switch (internalFormat) {
+ case GL_RGBA32UI_EXT:
+ case GL_RGB32UI_EXT:
+ case GL_ALPHA32UI_EXT:
+ case GL_INTENSITY32UI_EXT:
+ case GL_LUMINANCE32UI_EXT:
+ case GL_LUMINANCE_ALPHA32UI_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
+ break;
+ case GL_RGBA16UI_EXT:
+ case GL_RGB16UI_EXT:
+ case GL_ALPHA16UI_EXT:
+ case GL_INTENSITY16UI_EXT:
+ case GL_LUMINANCE16UI_EXT:
+ case GL_LUMINANCE_ALPHA16UI_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
+ break;
+ case GL_RGBA8UI_EXT:
+ case GL_RGB8UI_EXT:
+ case GL_ALPHA8UI_EXT:
+ case GL_INTENSITY8UI_EXT:
+ case GL_LUMINANCE8UI_EXT:
+ case GL_LUMINANCE_ALPHA8UI_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
+ break;
+ case GL_RGBA32I_EXT:
+ case GL_RGB32I_EXT:
+ case GL_ALPHA32I_EXT:
+ case GL_INTENSITY32I_EXT:
+ case GL_LUMINANCE32I_EXT:
+ case GL_LUMINANCE_ALPHA32I_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
+ break;
+ case GL_RGBA16I_EXT:
+ case GL_RGB16I_EXT:
+ case GL_ALPHA16I_EXT:
+ case GL_INTENSITY16I_EXT:
+ case GL_LUMINANCE16I_EXT:
+ case GL_LUMINANCE_ALPHA16I_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
+ break;
+ case GL_RGBA8I_EXT:
+ case GL_RGB8I_EXT:
+ case GL_ALPHA8I_EXT:
+ case GL_INTENSITY8I_EXT:
+ case GL_LUMINANCE8I_EXT:
+ case GL_LUMINANCE_ALPHA8I_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
+ break;
+ }
+ }
+
+ if (ctx->Extensions.ARB_texture_rg) {
+ switch (internalFormat) {
+ case GL_R8:
+ case GL_RED:
+ case GL_COMPRESSED_RED:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
+ break;
+
+ case GL_R16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_R16);
+ break;
+
+ case GL_RG:
+ case GL_RG8:
+ case GL_COMPRESSED_RG:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RG88);
+ break;
+
+ case GL_RG16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RG1616);
+ break;
+
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.EXT_texture_format_BGRA8888) {
+ switch (internalFormat) {
+ case GL_BGRA:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+ break;
+
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.ARB_texture_compression_rgtc) {
+ switch (internalFormat) {
+ case GL_COMPRESSED_RED_RGTC1:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RED_RGTC1);
+ break;
+ case GL_COMPRESSED_SIGNED_RED_RGTC1:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RED_RGTC1);
+ break;
+ case GL_COMPRESSED_RG_RGTC2:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2);
+ break;
+ case GL_COMPRESSED_SIGNED_RG_RGTC2:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG_RGTC2);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
+ return MESA_FORMAT_NONE;
+}
+
diff --git a/mesalib/src/mesa/main/texgetimage.c b/mesalib/src/mesa/main/texgetimage.c
index 21d9140c5..fe5ac0a89 100644
--- a/mesalib/src/mesa/main/texgetimage.c
+++ b/mesalib/src/mesa/main/texgetimage.c
@@ -1,918 +1,918 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.7
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (c) 2009 VMware, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * Code for glGetTexImage() and glGetCompressedTexImage().
- */
-
-
-#include "glheader.h"
-#include "bufferobj.h"
-#include "enums.h"
-#include "context.h"
-#include "formats.h"
-#include "image.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "pack.h"
-#include "pbo.h"
-#include "texgetimage.h"
-#include "teximage.h"
-
-
-
-/**
- * Can the given type represent negative values?
- */
-static INLINE GLboolean
-type_with_negative_values(GLenum type)
-{
- switch (type) {
- case GL_BYTE:
- case GL_SHORT:
- case GL_INT:
- case GL_FLOAT:
- case GL_HALF_FLOAT_ARB:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * glGetTexImage for color index pixels.
- */
-static void
-get_tex_color_index(struct gl_context *ctx, GLuint dimensions,
- GLenum format, GLenum type, GLvoid *pixels,
- const struct gl_texture_image *texImage)
-{
- const GLint width = texImage->Width;
- const GLint height = texImage->Height;
- const GLint depth = texImage->Depth;
- const GLuint indexBits =
- _mesa_get_format_bits(texImage->TexFormat, GL_TEXTURE_INDEX_SIZE_EXT);
- const GLbitfield transferOps = 0x0;
- GLint img, row, col;
-
- for (img = 0; img < depth; img++) {
- for (row = 0; row < height; row++) {
- GLuint indexRow[MAX_WIDTH] = { 0 };
- void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
- width, height, format, type,
- img, row, 0);
- assert(dest);
-
- if (indexBits == 8) {
- const GLubyte *src = (const GLubyte *) texImage->Data;
- src += width * (img * texImage->Height + row);
- for (col = 0; col < width; col++) {
- indexRow[col] = src[col];
- }
- }
- else if (indexBits == 16) {
- const GLushort *src = (const GLushort *) texImage->Data;
- src += width * (img * texImage->Height + row);
- for (col = 0; col < width; col++) {
- indexRow[col] = src[col];
- }
- }
- else {
- _mesa_problem(ctx, "Color index problem in _mesa_GetTexImage");
- }
- _mesa_pack_index_span(ctx, width, type, dest,
- indexRow, &ctx->Pack, transferOps);
- }
- }
-}
-
-
-/**
- * glGetTexImage for depth/Z pixels.
- */
-static void
-get_tex_depth(struct gl_context *ctx, GLuint dimensions,
- GLenum format, GLenum type, GLvoid *pixels,
- const struct gl_texture_image *texImage)
-{
- const GLint width = texImage->Width;
- const GLint height = texImage->Height;
- const GLint depth = texImage->Depth;
- GLint img, row, col;
- GLfloat *depthRow = (GLfloat *) malloc(width * sizeof(GLfloat));
-
- if (!depthRow) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
- return;
- }
-
- for (img = 0; img < depth; img++) {
- for (row = 0; row < height; row++) {
- void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
- width, height, format, type,
- img, row, 0);
- assert(dest);
-
- for (col = 0; col < width; col++) {
- texImage->FetchTexelf(texImage, col, row, img, depthRow + col);
- }
- _mesa_pack_depth_span(ctx, width, dest, type, depthRow, &ctx->Pack);
- }
- }
-
- free(depthRow);
-}
-
-
-/**
- * glGetTexImage for depth/stencil pixels.
- */
-static void
-get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions,
- GLenum format, GLenum type, GLvoid *pixels,
- const struct gl_texture_image *texImage)
-{
- const GLint width = texImage->Width;
- const GLint height = texImage->Height;
- const GLint depth = texImage->Depth;
- const GLuint *src = (const GLuint *) texImage->Data;
- GLint img, row;
-
- for (img = 0; img < depth; img++) {
- for (row = 0; row < height; row++) {
- void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
- width, height, format, type,
- img, row, 0);
- memcpy(dest, src, width * sizeof(GLuint));
- if (ctx->Pack.SwapBytes) {
- _mesa_swap4((GLuint *) dest, width);
- }
-
- src += width * row + width * height * img;
- }
- }
-}
-
-
-/**
- * glGetTexImage for YCbCr pixels.
- */
-static void
-get_tex_ycbcr(struct gl_context *ctx, GLuint dimensions,
- GLenum format, GLenum type, GLvoid *pixels,
- const struct gl_texture_image *texImage)
-{
- const GLint width = texImage->Width;
- const GLint height = texImage->Height;
- const GLint depth = texImage->Depth;
- const GLint rowstride = texImage->RowStride;
- const GLushort *src = (const GLushort *) texImage->Data;
- GLint img, row;
-
- for (img = 0; img < depth; img++) {
- for (row = 0; row < height; row++) {
- void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
- width, height, format, type,
- img, row, 0);
- memcpy(dest, src, width * sizeof(GLushort));
-
- /* check for byte swapping */
- if ((texImage->TexFormat == MESA_FORMAT_YCBCR
- && type == GL_UNSIGNED_SHORT_8_8_REV_MESA) ||
- (texImage->TexFormat == MESA_FORMAT_YCBCR_REV
- && type == GL_UNSIGNED_SHORT_8_8_MESA)) {
- if (!ctx->Pack.SwapBytes)
- _mesa_swap2((GLushort *) dest, width);
- }
- else if (ctx->Pack.SwapBytes) {
- _mesa_swap2((GLushort *) dest, width);
- }
-
- src += rowstride;
- }
- }
-}
-
-
-#if FEATURE_EXT_texture_sRGB
-
-
-/**
- * Convert a float value from linear space to a
- * non-linear sRGB value in [0, 255].
- * Not terribly efficient.
- */
-static INLINE GLfloat
-linear_to_nonlinear(GLfloat cl)
-{
- /* can't have values outside [0, 1] */
- GLfloat cs;
- if (cl < 0.0031308f) {
- cs = 12.92f * cl;
- }
- else {
- cs = (GLfloat)(1.055 * pow(cl, 0.41666) - 0.055);
- }
- return cs;
-}
-
-
-/**
- * glGetTexImagefor sRGB pixels;
- */
-static void
-get_tex_srgb(struct gl_context *ctx, GLuint dimensions,
- GLenum format, GLenum type, GLvoid *pixels,
- const struct gl_texture_image *texImage)
-{
- const GLint width = texImage->Width;
- const GLint height = texImage->Height;
- const GLint depth = texImage->Depth;
- const GLbitfield transferOps = 0x0;
- GLint img, row;
- GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
-
- if (!rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
- return;
- }
-
- for (img = 0; img < depth; img++) {
- for (row = 0; row < height; row++) {
- void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
- width, height, format, type,
- img, row, 0);
-
- GLint col;
-
- /* convert row to RGBA format */
- for (col = 0; col < width; col++) {
- texImage->FetchTexelf(texImage, col, row, img, rgba[col]);
- if (texImage->_BaseFormat == GL_LUMINANCE) {
- rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]);
- rgba[col][GCOMP] = 0.0;
- rgba[col][BCOMP] = 0.0;
- }
- else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
- rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]);
- rgba[col][GCOMP] = 0.0;
- rgba[col][BCOMP] = 0.0;
- }
- else if (texImage->_BaseFormat == GL_RGB ||
- texImage->_BaseFormat == GL_RGBA) {
- rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]);
- rgba[col][GCOMP] = linear_to_nonlinear(rgba[col][GCOMP]);
- rgba[col][BCOMP] = linear_to_nonlinear(rgba[col][BCOMP]);
- }
- }
- _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
- format, type, dest,
- &ctx->Pack, transferOps);
- }
- }
-
- free(rgba);
-}
-
-
-#else /* FEATURE_EXT_texture_sRGB */
-
-
-static INLINE void
-get_tex_srgb(struct gl_context *ctx, GLuint dimensions,
- GLenum format, GLenum type, GLvoid *pixels,
- const struct gl_texture_image *texImage)
-{
- ASSERT_NO_FEATURE();
-}
-
-
-#endif /* FEATURE_EXT_texture_sRGB */
-
-
-/**
- * glGetTexImagefor RGBA, Luminance, etc. pixels.
- * This is the slow way since we use texture sampling.
- */
-static void
-get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
- GLenum format, GLenum type, GLvoid *pixels,
- const struct gl_texture_image *texImage)
-{
- const GLint width = texImage->Width;
- const GLint height = texImage->Height;
- const GLint depth = texImage->Depth;
- /* Normally, no pixel transfer ops are performed during glGetTexImage.
- * The only possible exception is component clamping to [0,1].
- */
- GLbitfield transferOps = 0x0;
- GLint img, row;
- GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
-
- if (!rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
- return;
- }
-
- for (img = 0; img < depth; img++) {
- for (row = 0; row < height; row++) {
- void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
- width, height, format, type,
- img, row, 0);
- GLint col;
- GLenum dataType = _mesa_get_format_datatype(texImage->TexFormat);
-
- /* clamp does not apply to GetTexImage (final conversion)?
- * Looks like we need clamp though when going from format
- * containing negative values to unsigned format.
- */
- if (format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA) {
- transferOps |= IMAGE_CLAMP_BIT;
- }
- else if (!type_with_negative_values(type) &&
- (dataType == GL_FLOAT ||
- dataType == GL_SIGNED_NORMALIZED)) {
- transferOps |= IMAGE_CLAMP_BIT;
- }
-
- for (col = 0; col < width; col++) {
- texImage->FetchTexelf(texImage, col, row, img, rgba[col]);
- if (texImage->_BaseFormat == GL_ALPHA) {
- rgba[col][RCOMP] = 0.0F;
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
- }
- else if (texImage->_BaseFormat == GL_LUMINANCE) {
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
- rgba[col][ACOMP] = 1.0F;
- }
- else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
- }
- else if (texImage->_BaseFormat == GL_INTENSITY) {
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
- rgba[col][ACOMP] = 1.0F;
- }
- }
- _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
- format, type, dest,
- &ctx->Pack, transferOps);
- }
- }
-
- free(rgba);
-}
-
-
-/**
- * Try to do glGetTexImage() with simple memcpy().
- * \return GL_TRUE if done, GL_FALSE otherwise
- */
-static GLboolean
-get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type, GLvoid *pixels,
- const struct gl_texture_object *texObj,
- const struct gl_texture_image *texImage)
-{
- GLboolean memCopy = GL_FALSE;
-
- /* Texture image should have been mapped already */
- assert(texImage->Data);
-
- /*
- * Check if the src/dst formats are compatible.
- * Also note that GL's pixel transfer ops don't apply to glGetTexImage()
- * so we don't have to worry about those.
- * XXX more format combinations could be supported here.
- */
- if ((texObj->Target == GL_TEXTURE_1D ||
- texObj->Target == GL_TEXTURE_2D ||
- texObj->Target == GL_TEXTURE_RECTANGLE ||
- (texObj->Target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
- texObj->Target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) {
- if (texImage->TexFormat == MESA_FORMAT_ARGB8888 &&
- format == GL_BGRA &&
- type == GL_UNSIGNED_BYTE &&
- !ctx->Pack.SwapBytes &&
- _mesa_little_endian()) {
- memCopy = GL_TRUE;
- }
- else if (texImage->TexFormat == MESA_FORMAT_AL88 &&
- format == GL_LUMINANCE_ALPHA &&
- type == GL_UNSIGNED_BYTE &&
- !ctx->Pack.SwapBytes &&
- _mesa_little_endian()) {
- memCopy = GL_TRUE;
- }
- else if (texImage->TexFormat == MESA_FORMAT_L8 &&
- format == GL_LUMINANCE &&
- type == GL_UNSIGNED_BYTE) {
- memCopy = GL_TRUE;
- }
- else if (texImage->TexFormat == MESA_FORMAT_L16 &&
- format == GL_LUMINANCE &&
- type == GL_UNSIGNED_SHORT) {
- memCopy = GL_TRUE;
- }
- else if (texImage->TexFormat == MESA_FORMAT_A8 &&
- format == GL_ALPHA &&
- type == GL_UNSIGNED_BYTE) {
- memCopy = GL_TRUE;
- }
- else if (texImage->TexFormat == MESA_FORMAT_A16 &&
- format == GL_ALPHA &&
- type == GL_UNSIGNED_SHORT) {
- memCopy = GL_TRUE;
- }
- }
-
- if (memCopy) {
- const GLuint bpp = _mesa_get_format_bytes(texImage->TexFormat);
- const GLuint bytesPerRow = texImage->Width * bpp;
- GLubyte *dst =
- _mesa_image_address2d(&ctx->Pack, pixels, texImage->Width,
- texImage->Height, format, type, 0, 0);
- const GLint dstRowStride =
- _mesa_image_row_stride(&ctx->Pack, texImage->Width, format, type);
- const GLubyte *src = texImage->Data;
- const GLint srcRowStride = texImage->RowStride * bpp;
- GLuint row;
-
- if (bytesPerRow == dstRowStride && bytesPerRow == srcRowStride) {
- memcpy(dst, src, bytesPerRow * texImage->Height);
- }
- else {
- for (row = 0; row < texImage->Height; row++) {
- memcpy(dst, src, bytesPerRow);
- dst += dstRowStride;
- src += srcRowStride;
- }
- }
- }
-
- return memCopy;
-}
-
-
-/**
- * This is the software fallback for Driver.GetTexImage().
- * All error checking will have been done before this routine is called.
- * The texture image must be mapped.
- */
-void
-_mesa_get_teximage(struct gl_context *ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid *pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- GLuint dimensions;
-
- /* If we get here, the texture image should be mapped */
- assert(texImage->Data);
-
- switch (target) {
- case GL_TEXTURE_1D:
- dimensions = 1;
- break;
- case GL_TEXTURE_3D:
- dimensions = 3;
- break;
- default:
- dimensions = 2;
- }
-
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- /* Packing texture image into a PBO.
- * Map the (potentially) VRAM-based buffer into our process space so
- * we can write into it with the code below.
- * A hardware driver might use a sophisticated blit to move the
- * texture data to the PBO if the PBO is in VRAM along with the texture.
- */
- GLubyte *buf = (GLubyte *)
- ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
- GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj);
- if (!buf) {
- /* out of memory or other unexpected error */
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage(map PBO failed)");
- return;
- }
- /* <pixels> was an offset into the PBO.
- * Now make it a real, client-side pointer inside the mapped region.
- */
- pixels = ADD_POINTERS(buf, pixels);
- }
-
- if (get_tex_memcpy(ctx, format, type, pixels, texObj, texImage)) {
- /* all done */
- }
- else if (format == GL_COLOR_INDEX) {
- get_tex_color_index(ctx, dimensions, format, type, pixels, texImage);
- }
- else if (format == GL_DEPTH_COMPONENT) {
- get_tex_depth(ctx, dimensions, format, type, pixels, texImage);
- }
- else if (format == GL_DEPTH_STENCIL_EXT) {
- get_tex_depth_stencil(ctx, dimensions, format, type, pixels, texImage);
- }
- else if (format == GL_YCBCR_MESA) {
- get_tex_ycbcr(ctx, dimensions, format, type, pixels, texImage);
- }
- else if (_mesa_get_format_color_encoding(texImage->TexFormat) == GL_SRGB) {
- get_tex_srgb(ctx, dimensions, format, type, pixels, texImage);
- }
- else {
- get_tex_rgba(ctx, dimensions, format, type, pixels, texImage);
- }
-
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
- ctx->Pack.BufferObj);
- }
-}
-
-
-
-/**
- * This is the software fallback for Driver.GetCompressedTexImage().
- * All error checking will have been done before this routine is called.
- */
-void
-_mesa_get_compressed_teximage(struct gl_context *ctx, GLenum target, GLint level,
- GLvoid *img,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- const GLuint row_stride = _mesa_format_row_stride(texImage->TexFormat,
- texImage->Width);
- const GLuint row_stride_stored = _mesa_format_row_stride(texImage->TexFormat,
- texImage->RowStride);
- GLuint i;
-
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- /* pack texture image into a PBO */
- GLubyte *buf = (GLubyte *)
- ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
- GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj);
- if (!buf) {
- /* out of memory or other unexpected error */
- _mesa_error(ctx, GL_OUT_OF_MEMORY,
- "glGetCompresssedTexImage(map PBO failed)");
- return;
- }
- img = ADD_POINTERS(buf, img);
- }
-
- /* no pixelstore or pixel transfer, but respect stride */
-
- if (row_stride == row_stride_stored) {
- const GLuint size = _mesa_format_image_size(texImage->TexFormat,
- texImage->Width,
- texImage->Height,
- texImage->Depth);
- memcpy(img, texImage->Data, size);
- }
- else {
- GLuint bw, bh;
- _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
- for (i = 0; i < (texImage->Height + bh - 1) / bh; i++) {
- memcpy((GLubyte *)img + i * row_stride,
- (GLubyte *)texImage->Data + i * row_stride_stored,
- row_stride);
- }
- }
-
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
- ctx->Pack.BufferObj);
- }
-}
-
-
-
-/**
- * Do error checking for a glGetTexImage() call.
- * \return GL_TRUE if any error, GL_FALSE if no errors.
- */
-static GLboolean
-getteximage_error_check(struct gl_context *ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid *pixels )
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
- GLenum baseFormat;
-
- if (maxLevels == 0) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target=0x%x)", target);
- return GL_TRUE;
- }
-
- if (level < 0 || level >= maxLevels) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" );
- return GL_TRUE;
- }
-
- if (_mesa_sizeof_packed_type(type) <= 0) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" );
- return GL_TRUE;
- }
-
- if (_mesa_components_in_format(format) <= 0 ||
- format == GL_STENCIL_INDEX) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" );
- return GL_TRUE;
- }
-
- if (!ctx->Extensions.EXT_paletted_texture && _mesa_is_index_format(format)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
- return GL_TRUE;
- }
-
- if (!ctx->Extensions.ARB_depth_texture && _mesa_is_depth_format(format)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
- return GL_TRUE;
- }
-
- if (!ctx->Extensions.MESA_ycbcr_texture && _mesa_is_ycbcr_format(format)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
- return GL_TRUE;
- }
-
- if (!ctx->Extensions.EXT_packed_depth_stencil
- && _mesa_is_depthstencil_format(format)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
- return GL_TRUE;
- }
-
- if (!ctx->Extensions.ATI_envmap_bumpmap
- && _mesa_is_dudv_format(format)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
- return GL_TRUE;
- }
-
- texObj = _mesa_get_current_tex_object(ctx, target);
-
- if (!texObj || _mesa_is_proxy_texture(target)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)");
- return GL_TRUE;
- }
-
- texImage = _mesa_select_tex_image(ctx, texObj, target, level);
- if (!texImage) {
- /* out of memory */
- return GL_TRUE;
- }
-
- baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
-
- /* Make sure the requested image format is compatible with the
- * texture's format. Note that a color index texture can be converted
- * to RGBA so that combo is allowed.
- */
- if (_mesa_is_color_format(format)
- && !_mesa_is_color_format(baseFormat)
- && !_mesa_is_index_format(baseFormat)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
- return GL_TRUE;
- }
- else if (_mesa_is_index_format(format)
- && !_mesa_is_index_format(baseFormat)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
- return GL_TRUE;
- }
- else if (_mesa_is_depth_format(format)
- && !_mesa_is_depth_format(baseFormat)
- && !_mesa_is_depthstencil_format(baseFormat)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
- return GL_TRUE;
- }
- else if (_mesa_is_ycbcr_format(format)
- && !_mesa_is_ycbcr_format(baseFormat)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
- return GL_TRUE;
- }
- else if (_mesa_is_depthstencil_format(format)
- && !_mesa_is_depthstencil_format(baseFormat)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
- return GL_TRUE;
- }
- else if (_mesa_is_dudv_format(format)
- && !_mesa_is_dudv_format(baseFormat)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
- return GL_TRUE;
- }
-
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- /* packing texture image into a PBO */
- const GLuint dimensions = (target == GL_TEXTURE_3D) ? 3 : 2;
- if (!_mesa_validate_pbo_access(dimensions, &ctx->Pack, texImage->Width,
- texImage->Height, texImage->Depth,
- format, type, pixels)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTexImage(out of bounds PBO write)");
- return GL_TRUE;
- }
-
- /* PBO should not be mapped */
- if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTexImage(PBO is mapped)");
- return GL_TRUE;
- }
- }
-
- return GL_FALSE;
-}
-
-
-
-/**
- * Get texture image. Called by glGetTexImage.
- *
- * \param target texture target.
- * \param level image level.
- * \param format pixel data format for returned image.
- * \param type pixel data type for returned image.
- * \param pixels returned pixel data.
- */
-void GLAPIENTRY
-_mesa_GetTexImage( GLenum target, GLint level, GLenum format,
- GLenum type, GLvoid *pixels )
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (getteximage_error_check(ctx, target, level, format, type, pixels)) {
- return;
- }
-
- if (!_mesa_is_bufferobj(ctx->Pack.BufferObj) && !pixels) {
- /* not an error, do nothing */
- return;
- }
-
- texObj = _mesa_get_current_tex_object(ctx, target);
- texImage = _mesa_select_tex_image(ctx, texObj, target, level);
-
- if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
- _mesa_debug(ctx, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
- " dstFmt=0x%x, dstType=0x%x\n",
- texObj->Name,
- _mesa_get_format_name(texImage->TexFormat),
- texImage->Width, texImage->Height,
- format, type);
- }
-
- _mesa_lock_texture(ctx, texObj);
- {
- ctx->Driver.GetTexImage(ctx, target, level, format, type, pixels,
- texObj, texImage);
- }
- _mesa_unlock_texture(ctx, texObj);
-}
-
-
-
-/**
- * Do error checking for a glGetCompressedTexImage() call.
- * \return GL_TRUE if any error, GL_FALSE if no errors.
- */
-static GLboolean
-getcompressedteximage_error_check(struct gl_context *ctx, GLenum target,
- GLint level, GLvoid *img)
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
-
- if (maxLevels == 0) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImage(target=0x%x)",
- target);
- return GL_TRUE;
- }
-
- if (level < 0 || level >= maxLevels) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glGetCompressedTexImageARB(bad level = %d)", level);
- return GL_TRUE;
- }
-
- if (_mesa_is_proxy_texture(target)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetCompressedTexImageARB(bad target = %s)",
- _mesa_lookup_enum_by_nr(target));
- return GL_TRUE;
- }
-
- texObj = _mesa_get_current_tex_object(ctx, target);
- if (!texObj) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)");
- return GL_TRUE;
- }
-
- texImage = _mesa_select_tex_image(ctx, texObj, target, level);
-
- if (!texImage) {
- /* probably invalid mipmap level */
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glGetCompressedTexImageARB(level)");
- return GL_TRUE;
- }
-
- if (!_mesa_is_format_compressed(texImage->TexFormat)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetCompressedTexImageARB(texture is not compressed)");
- return GL_TRUE;
- }
-
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- GLuint compressedSize;
-
- /* make sure PBO is not mapped */
- if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetCompressedTexImage(PBO is mapped)");
- return GL_TRUE;
- }
-
- compressedSize = _mesa_format_image_size(texImage->TexFormat,
- texImage->Width,
- texImage->Height,
- texImage->Depth);
-
- /* do bounds checking on PBO write */
- if ((const GLubyte *) img + compressedSize >
- (const GLubyte *) ctx->Pack.BufferObj->Size) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetCompressedTexImage(out of bounds PBO write)");
- return GL_TRUE;
- }
- }
-
- return GL_FALSE;
-}
-
-
-void GLAPIENTRY
-_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img)
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (getcompressedteximage_error_check(ctx, target, level, img)) {
- return;
- }
-
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj) && !img) {
- /* not an error, do nothing */
- return;
- }
-
- texObj = _mesa_get_current_tex_object(ctx, target);
- texImage = _mesa_select_tex_image(ctx, texObj, target, level);
-
- if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
- _mesa_debug(ctx,
- "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
- texObj->Name,
- _mesa_get_format_name(texImage->TexFormat),
- texImage->Width, texImage->Height);
- }
-
- _mesa_lock_texture(ctx, texObj);
- {
- ctx->Driver.GetCompressedTexImage(ctx, target, level, img,
- texObj, texImage);
- }
- _mesa_unlock_texture(ctx, texObj);
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.7
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2009 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * Code for glGetTexImage() and glGetCompressedTexImage().
+ */
+
+
+#include "glheader.h"
+#include "bufferobj.h"
+#include "enums.h"
+#include "context.h"
+#include "formats.h"
+#include "image.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "pack.h"
+#include "pbo.h"
+#include "texgetimage.h"
+#include "teximage.h"
+
+
+
+/**
+ * Can the given type represent negative values?
+ */
+static INLINE GLboolean
+type_with_negative_values(GLenum type)
+{
+ switch (type) {
+ case GL_BYTE:
+ case GL_SHORT:
+ case GL_INT:
+ case GL_FLOAT:
+ case GL_HALF_FLOAT_ARB:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * glGetTexImage for color index pixels.
+ */
+static void
+get_tex_color_index(struct gl_context *ctx, GLuint dimensions,
+ GLenum format, GLenum type, GLvoid *pixels,
+ const struct gl_texture_image *texImage)
+{
+ const GLint width = texImage->Width;
+ const GLint height = texImage->Height;
+ const GLint depth = texImage->Depth;
+ const GLuint indexBits =
+ _mesa_get_format_bits(texImage->TexFormat, GL_TEXTURE_INDEX_SIZE_EXT);
+ const GLbitfield transferOps = 0x0;
+ GLint img, row, col;
+
+ for (img = 0; img < depth; img++) {
+ for (row = 0; row < height; row++) {
+ GLuint indexRow[MAX_WIDTH] = { 0 };
+ void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
+ width, height, format, type,
+ img, row, 0);
+ assert(dest);
+
+ if (indexBits == 8) {
+ const GLubyte *src = (const GLubyte *) texImage->Data;
+ src += width * (img * texImage->Height + row);
+ for (col = 0; col < width; col++) {
+ indexRow[col] = src[col];
+ }
+ }
+ else if (indexBits == 16) {
+ const GLushort *src = (const GLushort *) texImage->Data;
+ src += width * (img * texImage->Height + row);
+ for (col = 0; col < width; col++) {
+ indexRow[col] = src[col];
+ }
+ }
+ else {
+ _mesa_problem(ctx, "Color index problem in _mesa_GetTexImage");
+ }
+ _mesa_pack_index_span(ctx, width, type, dest,
+ indexRow, &ctx->Pack, transferOps);
+ }
+ }
+}
+
+
+/**
+ * glGetTexImage for depth/Z pixels.
+ */
+static void
+get_tex_depth(struct gl_context *ctx, GLuint dimensions,
+ GLenum format, GLenum type, GLvoid *pixels,
+ const struct gl_texture_image *texImage)
+{
+ const GLint width = texImage->Width;
+ const GLint height = texImage->Height;
+ const GLint depth = texImage->Depth;
+ GLint img, row, col;
+ GLfloat *depthRow = (GLfloat *) malloc(width * sizeof(GLfloat));
+
+ if (!depthRow) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
+ return;
+ }
+
+ for (img = 0; img < depth; img++) {
+ for (row = 0; row < height; row++) {
+ void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
+ width, height, format, type,
+ img, row, 0);
+ assert(dest);
+
+ for (col = 0; col < width; col++) {
+ texImage->FetchTexelf(texImage, col, row, img, depthRow + col);
+ }
+ _mesa_pack_depth_span(ctx, width, dest, type, depthRow, &ctx->Pack);
+ }
+ }
+
+ free(depthRow);
+}
+
+
+/**
+ * glGetTexImage for depth/stencil pixels.
+ */
+static void
+get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions,
+ GLenum format, GLenum type, GLvoid *pixels,
+ const struct gl_texture_image *texImage)
+{
+ const GLint width = texImage->Width;
+ const GLint height = texImage->Height;
+ const GLint depth = texImage->Depth;
+ const GLuint *src = (const GLuint *) texImage->Data;
+ GLint img, row;
+
+ for (img = 0; img < depth; img++) {
+ for (row = 0; row < height; row++) {
+ void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
+ width, height, format, type,
+ img, row, 0);
+ memcpy(dest, src, width * sizeof(GLuint));
+ if (ctx->Pack.SwapBytes) {
+ _mesa_swap4((GLuint *) dest, width);
+ }
+
+ src += width * row + width * height * img;
+ }
+ }
+}
+
+
+/**
+ * glGetTexImage for YCbCr pixels.
+ */
+static void
+get_tex_ycbcr(struct gl_context *ctx, GLuint dimensions,
+ GLenum format, GLenum type, GLvoid *pixels,
+ const struct gl_texture_image *texImage)
+{
+ const GLint width = texImage->Width;
+ const GLint height = texImage->Height;
+ const GLint depth = texImage->Depth;
+ const GLint rowstride = texImage->RowStride;
+ const GLushort *src = (const GLushort *) texImage->Data;
+ GLint img, row;
+
+ for (img = 0; img < depth; img++) {
+ for (row = 0; row < height; row++) {
+ void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
+ width, height, format, type,
+ img, row, 0);
+ memcpy(dest, src, width * sizeof(GLushort));
+
+ /* check for byte swapping */
+ if ((texImage->TexFormat == MESA_FORMAT_YCBCR
+ && type == GL_UNSIGNED_SHORT_8_8_REV_MESA) ||
+ (texImage->TexFormat == MESA_FORMAT_YCBCR_REV
+ && type == GL_UNSIGNED_SHORT_8_8_MESA)) {
+ if (!ctx->Pack.SwapBytes)
+ _mesa_swap2((GLushort *) dest, width);
+ }
+ else if (ctx->Pack.SwapBytes) {
+ _mesa_swap2((GLushort *) dest, width);
+ }
+
+ src += rowstride;
+ }
+ }
+}
+
+
+#if FEATURE_EXT_texture_sRGB
+
+
+/**
+ * Convert a float value from linear space to a
+ * non-linear sRGB value in [0, 255].
+ * Not terribly efficient.
+ */
+static INLINE GLfloat
+linear_to_nonlinear(GLfloat cl)
+{
+ /* can't have values outside [0, 1] */
+ GLfloat cs;
+ if (cl < 0.0031308f) {
+ cs = 12.92f * cl;
+ }
+ else {
+ cs = (GLfloat)(1.055 * pow(cl, 0.41666) - 0.055);
+ }
+ return cs;
+}
+
+
+/**
+ * glGetTexImagefor sRGB pixels;
+ */
+static void
+get_tex_srgb(struct gl_context *ctx, GLuint dimensions,
+ GLenum format, GLenum type, GLvoid *pixels,
+ const struct gl_texture_image *texImage)
+{
+ const GLint width = texImage->Width;
+ const GLint height = texImage->Height;
+ const GLint depth = texImage->Depth;
+ const GLbitfield transferOps = 0x0;
+ GLint img, row;
+ GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
+
+ if (!rgba) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
+ return;
+ }
+
+ for (img = 0; img < depth; img++) {
+ for (row = 0; row < height; row++) {
+ void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
+ width, height, format, type,
+ img, row, 0);
+
+ GLint col;
+
+ /* convert row to RGBA format */
+ for (col = 0; col < width; col++) {
+ texImage->FetchTexelf(texImage, col, row, img, rgba[col]);
+ if (texImage->_BaseFormat == GL_LUMINANCE) {
+ rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]);
+ rgba[col][GCOMP] = 0.0;
+ rgba[col][BCOMP] = 0.0;
+ }
+ else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
+ rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]);
+ rgba[col][GCOMP] = 0.0;
+ rgba[col][BCOMP] = 0.0;
+ }
+ else if (texImage->_BaseFormat == GL_RGB ||
+ texImage->_BaseFormat == GL_RGBA) {
+ rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]);
+ rgba[col][GCOMP] = linear_to_nonlinear(rgba[col][GCOMP]);
+ rgba[col][BCOMP] = linear_to_nonlinear(rgba[col][BCOMP]);
+ }
+ }
+ _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
+ format, type, dest,
+ &ctx->Pack, transferOps);
+ }
+ }
+
+ free(rgba);
+}
+
+
+#else /* FEATURE_EXT_texture_sRGB */
+
+
+static INLINE void
+get_tex_srgb(struct gl_context *ctx, GLuint dimensions,
+ GLenum format, GLenum type, GLvoid *pixels,
+ const struct gl_texture_image *texImage)
+{
+ ASSERT_NO_FEATURE();
+}
+
+
+#endif /* FEATURE_EXT_texture_sRGB */
+
+
+/**
+ * glGetTexImagefor RGBA, Luminance, etc. pixels.
+ * This is the slow way since we use texture sampling.
+ */
+static void
+get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
+ GLenum format, GLenum type, GLvoid *pixels,
+ const struct gl_texture_image *texImage)
+{
+ const GLint width = texImage->Width;
+ const GLint height = texImage->Height;
+ const GLint depth = texImage->Depth;
+ /* Normally, no pixel transfer ops are performed during glGetTexImage.
+ * The only possible exception is component clamping to [0,1].
+ */
+ GLbitfield transferOps = 0x0;
+ GLint img, row;
+ GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
+
+ if (!rgba) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
+ return;
+ }
+
+ for (img = 0; img < depth; img++) {
+ for (row = 0; row < height; row++) {
+ void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
+ width, height, format, type,
+ img, row, 0);
+ GLint col;
+ GLenum dataType = _mesa_get_format_datatype(texImage->TexFormat);
+
+ /* clamp does not apply to GetTexImage (final conversion)?
+ * Looks like we need clamp though when going from format
+ * containing negative values to unsigned format.
+ */
+ if (format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA) {
+ transferOps |= IMAGE_CLAMP_BIT;
+ }
+ else if (!type_with_negative_values(type) &&
+ (dataType == GL_FLOAT ||
+ dataType == GL_SIGNED_NORMALIZED)) {
+ transferOps |= IMAGE_CLAMP_BIT;
+ }
+
+ for (col = 0; col < width; col++) {
+ texImage->FetchTexelf(texImage, col, row, img, rgba[col]);
+ if (texImage->_BaseFormat == GL_ALPHA) {
+ rgba[col][RCOMP] = 0.0F;
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ }
+ else if (texImage->_BaseFormat == GL_LUMINANCE) {
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ rgba[col][ACOMP] = 1.0F;
+ }
+ else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ }
+ else if (texImage->_BaseFormat == GL_INTENSITY) {
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ rgba[col][ACOMP] = 1.0F;
+ }
+ }
+ _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
+ format, type, dest,
+ &ctx->Pack, transferOps);
+ }
+ }
+
+ free(rgba);
+}
+
+
+/**
+ * Try to do glGetTexImage() with simple memcpy().
+ * \return GL_TRUE if done, GL_FALSE otherwise
+ */
+static GLboolean
+get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type, GLvoid *pixels,
+ const struct gl_texture_object *texObj,
+ const struct gl_texture_image *texImage)
+{
+ GLboolean memCopy = GL_FALSE;
+
+ /* Texture image should have been mapped already */
+ assert(texImage->Data);
+
+ /*
+ * Check if the src/dst formats are compatible.
+ * Also note that GL's pixel transfer ops don't apply to glGetTexImage()
+ * so we don't have to worry about those.
+ * XXX more format combinations could be supported here.
+ */
+ if ((texObj->Target == GL_TEXTURE_1D ||
+ texObj->Target == GL_TEXTURE_2D ||
+ texObj->Target == GL_TEXTURE_RECTANGLE ||
+ (texObj->Target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
+ texObj->Target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) {
+ if (texImage->TexFormat == MESA_FORMAT_ARGB8888 &&
+ format == GL_BGRA &&
+ type == GL_UNSIGNED_BYTE &&
+ !ctx->Pack.SwapBytes &&
+ _mesa_little_endian()) {
+ memCopy = GL_TRUE;
+ }
+ else if (texImage->TexFormat == MESA_FORMAT_AL88 &&
+ format == GL_LUMINANCE_ALPHA &&
+ type == GL_UNSIGNED_BYTE &&
+ !ctx->Pack.SwapBytes &&
+ _mesa_little_endian()) {
+ memCopy = GL_TRUE;
+ }
+ else if (texImage->TexFormat == MESA_FORMAT_L8 &&
+ format == GL_LUMINANCE &&
+ type == GL_UNSIGNED_BYTE) {
+ memCopy = GL_TRUE;
+ }
+ else if (texImage->TexFormat == MESA_FORMAT_L16 &&
+ format == GL_LUMINANCE &&
+ type == GL_UNSIGNED_SHORT) {
+ memCopy = GL_TRUE;
+ }
+ else if (texImage->TexFormat == MESA_FORMAT_A8 &&
+ format == GL_ALPHA &&
+ type == GL_UNSIGNED_BYTE) {
+ memCopy = GL_TRUE;
+ }
+ else if (texImage->TexFormat == MESA_FORMAT_A16 &&
+ format == GL_ALPHA &&
+ type == GL_UNSIGNED_SHORT) {
+ memCopy = GL_TRUE;
+ }
+ }
+
+ if (memCopy) {
+ const GLuint bpp = _mesa_get_format_bytes(texImage->TexFormat);
+ const GLuint bytesPerRow = texImage->Width * bpp;
+ GLubyte *dst =
+ _mesa_image_address2d(&ctx->Pack, pixels, texImage->Width,
+ texImage->Height, format, type, 0, 0);
+ const GLint dstRowStride =
+ _mesa_image_row_stride(&ctx->Pack, texImage->Width, format, type);
+ const GLubyte *src = texImage->Data;
+ const GLint srcRowStride = texImage->RowStride * bpp;
+ GLuint row;
+
+ if (bytesPerRow == dstRowStride && bytesPerRow == srcRowStride) {
+ memcpy(dst, src, bytesPerRow * texImage->Height);
+ }
+ else {
+ for (row = 0; row < texImage->Height; row++) {
+ memcpy(dst, src, bytesPerRow);
+ dst += dstRowStride;
+ src += srcRowStride;
+ }
+ }
+ }
+
+ return memCopy;
+}
+
+
+/**
+ * This is the software fallback for Driver.GetTexImage().
+ * All error checking will have been done before this routine is called.
+ * The texture image must be mapped.
+ */
+void
+_mesa_get_teximage(struct gl_context *ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ GLuint dimensions;
+
+ /* If we get here, the texture image should be mapped */
+ assert(texImage->Data);
+
+ switch (target) {
+ case GL_TEXTURE_1D:
+ dimensions = 1;
+ break;
+ case GL_TEXTURE_3D:
+ dimensions = 3;
+ break;
+ default:
+ dimensions = 2;
+ }
+
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ /* Packing texture image into a PBO.
+ * Map the (potentially) VRAM-based buffer into our process space so
+ * we can write into it with the code below.
+ * A hardware driver might use a sophisticated blit to move the
+ * texture data to the PBO if the PBO is in VRAM along with the texture.
+ */
+ GLubyte *buf = (GLubyte *)
+ ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+ GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj);
+ if (!buf) {
+ /* out of memory or other unexpected error */
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage(map PBO failed)");
+ return;
+ }
+ /* <pixels> was an offset into the PBO.
+ * Now make it a real, client-side pointer inside the mapped region.
+ */
+ pixels = ADD_POINTERS(buf, pixels);
+ }
+
+ if (get_tex_memcpy(ctx, format, type, pixels, texObj, texImage)) {
+ /* all done */
+ }
+ else if (format == GL_COLOR_INDEX) {
+ get_tex_color_index(ctx, dimensions, format, type, pixels, texImage);
+ }
+ else if (format == GL_DEPTH_COMPONENT) {
+ get_tex_depth(ctx, dimensions, format, type, pixels, texImage);
+ }
+ else if (format == GL_DEPTH_STENCIL_EXT) {
+ get_tex_depth_stencil(ctx, dimensions, format, type, pixels, texImage);
+ }
+ else if (format == GL_YCBCR_MESA) {
+ get_tex_ycbcr(ctx, dimensions, format, type, pixels, texImage);
+ }
+ else if (_mesa_get_format_color_encoding(texImage->TexFormat) == GL_SRGB) {
+ get_tex_srgb(ctx, dimensions, format, type, pixels, texImage);
+ }
+ else {
+ get_tex_rgba(ctx, dimensions, format, type, pixels, texImage);
+ }
+
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+ ctx->Pack.BufferObj);
+ }
+}
+
+
+
+/**
+ * This is the software fallback for Driver.GetCompressedTexImage().
+ * All error checking will have been done before this routine is called.
+ */
+void
+_mesa_get_compressed_teximage(struct gl_context *ctx, GLenum target, GLint level,
+ GLvoid *img,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ const GLuint row_stride = _mesa_format_row_stride(texImage->TexFormat,
+ texImage->Width);
+ const GLuint row_stride_stored = _mesa_format_row_stride(texImage->TexFormat,
+ texImage->RowStride);
+ GLuint i;
+
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ /* pack texture image into a PBO */
+ GLubyte *buf = (GLubyte *)
+ ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+ GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj);
+ if (!buf) {
+ /* out of memory or other unexpected error */
+ _mesa_error(ctx, GL_OUT_OF_MEMORY,
+ "glGetCompresssedTexImage(map PBO failed)");
+ return;
+ }
+ img = ADD_POINTERS(buf, img);
+ }
+
+ /* no pixelstore or pixel transfer, but respect stride */
+
+ if (row_stride == row_stride_stored) {
+ const GLuint size = _mesa_format_image_size(texImage->TexFormat,
+ texImage->Width,
+ texImage->Height,
+ texImage->Depth);
+ memcpy(img, texImage->Data, size);
+ }
+ else {
+ GLuint bw, bh;
+ _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
+ for (i = 0; i < (texImage->Height + bh - 1) / bh; i++) {
+ memcpy((GLubyte *)img + i * row_stride,
+ (GLubyte *)texImage->Data + i * row_stride_stored,
+ row_stride);
+ }
+ }
+
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+ ctx->Pack.BufferObj);
+ }
+}
+
+
+
+/**
+ * Do error checking for a glGetTexImage() call.
+ * \return GL_TRUE if any error, GL_FALSE if no errors.
+ */
+static GLboolean
+getteximage_error_check(struct gl_context *ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid *pixels )
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
+ GLenum baseFormat;
+
+ if (maxLevels == 0) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target=0x%x)", target);
+ return GL_TRUE;
+ }
+
+ if (level < 0 || level >= maxLevels) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" );
+ return GL_TRUE;
+ }
+
+ if (_mesa_sizeof_packed_type(type) <= 0) {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" );
+ return GL_TRUE;
+ }
+
+ if (_mesa_components_in_format(format) <= 0 ||
+ format == GL_STENCIL_INDEX) {
+ _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" );
+ return GL_TRUE;
+ }
+
+ if (!ctx->Extensions.EXT_paletted_texture && _mesa_is_index_format(format)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
+ return GL_TRUE;
+ }
+
+ if (!ctx->Extensions.ARB_depth_texture && _mesa_is_depth_format(format)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
+ return GL_TRUE;
+ }
+
+ if (!ctx->Extensions.MESA_ycbcr_texture && _mesa_is_ycbcr_format(format)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
+ return GL_TRUE;
+ }
+
+ if (!ctx->Extensions.EXT_packed_depth_stencil
+ && _mesa_is_depthstencil_format(format)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
+ return GL_TRUE;
+ }
+
+ if (!ctx->Extensions.ATI_envmap_bumpmap
+ && _mesa_is_dudv_format(format)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
+ return GL_TRUE;
+ }
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+
+ if (!texObj || _mesa_is_proxy_texture(target)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)");
+ return GL_TRUE;
+ }
+
+ texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+ if (!texImage) {
+ /* out of memory */
+ return GL_TRUE;
+ }
+
+ baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
+
+ /* Make sure the requested image format is compatible with the
+ * texture's format. Note that a color index texture can be converted
+ * to RGBA so that combo is allowed.
+ */
+ if (_mesa_is_color_format(format)
+ && !_mesa_is_color_format(baseFormat)
+ && !_mesa_is_index_format(baseFormat)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
+ return GL_TRUE;
+ }
+ else if (_mesa_is_index_format(format)
+ && !_mesa_is_index_format(baseFormat)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
+ return GL_TRUE;
+ }
+ else if (_mesa_is_depth_format(format)
+ && !_mesa_is_depth_format(baseFormat)
+ && !_mesa_is_depthstencil_format(baseFormat)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
+ return GL_TRUE;
+ }
+ else if (_mesa_is_ycbcr_format(format)
+ && !_mesa_is_ycbcr_format(baseFormat)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
+ return GL_TRUE;
+ }
+ else if (_mesa_is_depthstencil_format(format)
+ && !_mesa_is_depthstencil_format(baseFormat)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
+ return GL_TRUE;
+ }
+ else if (_mesa_is_dudv_format(format)
+ && !_mesa_is_dudv_format(baseFormat)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
+ return GL_TRUE;
+ }
+
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ /* packing texture image into a PBO */
+ const GLuint dimensions = (target == GL_TEXTURE_3D) ? 3 : 2;
+ if (!_mesa_validate_pbo_access(dimensions, &ctx->Pack, texImage->Width,
+ texImage->Height, texImage->Depth,
+ format, type, pixels)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetTexImage(out of bounds PBO write)");
+ return GL_TRUE;
+ }
+
+ /* PBO should not be mapped */
+ if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetTexImage(PBO is mapped)");
+ return GL_TRUE;
+ }
+ }
+
+ return GL_FALSE;
+}
+
+
+
+/**
+ * Get texture image. Called by glGetTexImage.
+ *
+ * \param target texture target.
+ * \param level image level.
+ * \param format pixel data format for returned image.
+ * \param type pixel data type for returned image.
+ * \param pixels returned pixel data.
+ */
+void GLAPIENTRY
+_mesa_GetTexImage( GLenum target, GLint level, GLenum format,
+ GLenum type, GLvoid *pixels )
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (getteximage_error_check(ctx, target, level, format, type, pixels)) {
+ return;
+ }
+
+ if (!_mesa_is_bufferobj(ctx->Pack.BufferObj) && !pixels) {
+ /* not an error, do nothing */
+ return;
+ }
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+ texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+
+ if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
+ _mesa_debug(ctx, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
+ " dstFmt=0x%x, dstType=0x%x\n",
+ texObj->Name,
+ _mesa_get_format_name(texImage->TexFormat),
+ texImage->Width, texImage->Height,
+ format, type);
+ }
+
+ _mesa_lock_texture(ctx, texObj);
+ {
+ ctx->Driver.GetTexImage(ctx, target, level, format, type, pixels,
+ texObj, texImage);
+ }
+ _mesa_unlock_texture(ctx, texObj);
+}
+
+
+
+/**
+ * Do error checking for a glGetCompressedTexImage() call.
+ * \return GL_TRUE if any error, GL_FALSE if no errors.
+ */
+static GLboolean
+getcompressedteximage_error_check(struct gl_context *ctx, GLenum target,
+ GLint level, GLvoid *img)
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
+
+ if (maxLevels == 0) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImage(target=0x%x)",
+ target);
+ return GL_TRUE;
+ }
+
+ if (level < 0 || level >= maxLevels) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glGetCompressedTexImageARB(bad level = %d)", level);
+ return GL_TRUE;
+ }
+
+ if (_mesa_is_proxy_texture(target)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetCompressedTexImageARB(bad target = %s)",
+ _mesa_lookup_enum_by_nr(target));
+ return GL_TRUE;
+ }
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+ if (!texObj) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)");
+ return GL_TRUE;
+ }
+
+ texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+
+ if (!texImage) {
+ /* probably invalid mipmap level */
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glGetCompressedTexImageARB(level)");
+ return GL_TRUE;
+ }
+
+ if (!_mesa_is_format_compressed(texImage->TexFormat)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetCompressedTexImageARB(texture is not compressed)");
+ return GL_TRUE;
+ }
+
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ GLuint compressedSize;
+
+ /* make sure PBO is not mapped */
+ if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetCompressedTexImage(PBO is mapped)");
+ return GL_TRUE;
+ }
+
+ compressedSize = _mesa_format_image_size(texImage->TexFormat,
+ texImage->Width,
+ texImage->Height,
+ texImage->Depth);
+
+ /* do bounds checking on PBO write */
+ if ((const GLubyte *) img + compressedSize >
+ (const GLubyte *) ctx->Pack.BufferObj->Size) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetCompressedTexImage(out of bounds PBO write)");
+ return GL_TRUE;
+ }
+ }
+
+ return GL_FALSE;
+}
+
+
+void GLAPIENTRY
+_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img)
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (getcompressedteximage_error_check(ctx, target, level, img)) {
+ return;
+ }
+
+ if (_mesa_is_bufferobj(ctx->Pack.BufferObj) && !img) {
+ /* not an error, do nothing */
+ return;
+ }
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+ texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+
+ if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
+ _mesa_debug(ctx,
+ "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
+ texObj->Name,
+ _mesa_get_format_name(texImage->TexFormat),
+ texImage->Width, texImage->Height);
+ }
+
+ _mesa_lock_texture(ctx, texObj);
+ {
+ ctx->Driver.GetCompressedTexImage(ctx, target, level, img,
+ texObj, texImage);
+ }
+ _mesa_unlock_texture(ctx, texObj);
+}
diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c
index d4ae6dd69..164dcba5f 100644
--- a/mesalib/src/mesa/main/teximage.c
+++ b/mesalib/src/mesa/main/teximage.c
@@ -1,3504 +1,3504 @@
-/*
- * mesa 3-D graphics library
- * Version: 7.6
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file teximage.c
- * Texture image-related functions.
- */
-
-
-#include "glheader.h"
-#include "bufferobj.h"
-#include "context.h"
-#include "enums.h"
-#include "fbobject.h"
-#include "framebuffer.h"
-#include "hash.h"
-#include "image.h"
-#include "imports.h"
-#include "macros.h"
-#include "mfeatures.h"
-#include "state.h"
-#include "texcompress.h"
-#include "texfetch.h"
-#include "teximage.h"
-#include "texstate.h"
-#include "texpal.h"
-#include "mtypes.h"
-
-
-/**
- * State changes which we care about for glCopyTex[Sub]Image() calls.
- * In particular, we care about pixel transfer state and buffer state
- * (such as glReadBuffer to make sure we read from the right renderbuffer).
- */
-#define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
- _NEW_BUFFERS | \
- _NEW_PIXEL)
-
-
-
-/**
- * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
- * elsewhere.
- */
-void *
-_mesa_alloc_texmemory(GLsizei bytes)
-{
- return _mesa_align_malloc(bytes, 512);
-}
-
-
-/**
- * Free texture memory allocated with _mesa_alloc_texmemory()
- */
-void
-_mesa_free_texmemory(void *m)
-{
- _mesa_align_free(m);
-}
-
-
-/*
- * Compute floor(log_base_2(n)).
- * If n < 0 return -1.
- */
-static int
-logbase2( int n )
-{
- GLint i = 1;
- GLint log2 = 0;
-
- if (n < 0)
- return -1;
-
- if (n == 0)
- return 0;
-
- while ( n > i ) {
- i *= 2;
- log2++;
- }
- if (i != n) {
- return log2 - 1;
- }
- else {
- return log2;
- }
-}
-
-
-
-/**
- * Return the simple base format for a given internal texture format.
- * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
- *
- * \param ctx GL context.
- * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
- *
- * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
- * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
- *
- * This is the format which is used during texture application (i.e. the
- * texture format and env mode determine the arithmetic used.
- *
- * XXX this could be static
- */
-GLint
-_mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat )
-{
- switch (internalFormat) {
- case GL_ALPHA:
- case GL_ALPHA4:
- case GL_ALPHA8:
- case GL_ALPHA12:
- case GL_ALPHA16:
- return GL_ALPHA;
- case 1:
- case GL_LUMINANCE:
- case GL_LUMINANCE4:
- case GL_LUMINANCE8:
- case GL_LUMINANCE12:
- case GL_LUMINANCE16:
- return GL_LUMINANCE;
- case 2:
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE4_ALPHA4:
- case GL_LUMINANCE6_ALPHA2:
- case GL_LUMINANCE8_ALPHA8:
- case GL_LUMINANCE12_ALPHA4:
- case GL_LUMINANCE12_ALPHA12:
- case GL_LUMINANCE16_ALPHA16:
- return GL_LUMINANCE_ALPHA;
- case GL_INTENSITY:
- case GL_INTENSITY4:
- case GL_INTENSITY8:
- case GL_INTENSITY12:
- case GL_INTENSITY16:
- return GL_INTENSITY;
- case 3:
- case GL_RGB:
- case GL_R3_G3_B2:
- case GL_RGB4:
- case GL_RGB5:
- case GL_RGB8:
- case GL_RGB10:
- case GL_RGB12:
- case GL_RGB16:
- return GL_RGB;
- case 4:
- case GL_RGBA:
- case GL_RGBA2:
- case GL_RGBA4:
- case GL_RGB5_A1:
- case GL_RGBA8:
- case GL_RGB10_A2:
- case GL_RGBA12:
- case GL_RGBA16:
- return GL_RGBA;
- default:
- ; /* fallthrough */
- }
-
- if (ctx->Extensions.EXT_texture_format_BGRA8888) {
- switch (internalFormat) {
- case GL_BGRA_EXT:
- return GL_RGBA;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.EXT_paletted_texture) {
- switch (internalFormat) {
- case GL_COLOR_INDEX:
- case GL_COLOR_INDEX1_EXT:
- case GL_COLOR_INDEX2_EXT:
- case GL_COLOR_INDEX4_EXT:
- case GL_COLOR_INDEX8_EXT:
- case GL_COLOR_INDEX12_EXT:
- case GL_COLOR_INDEX16_EXT:
- return GL_COLOR_INDEX;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.ARB_depth_texture) {
- switch (internalFormat) {
- case GL_DEPTH_COMPONENT:
- case GL_DEPTH_COMPONENT16:
- case GL_DEPTH_COMPONENT24:
- case GL_DEPTH_COMPONENT32:
- return GL_DEPTH_COMPONENT;
- default:
- ; /* fallthrough */
- }
- }
-
- switch (internalFormat) {
- case GL_COMPRESSED_ALPHA:
- return GL_ALPHA;
- case GL_COMPRESSED_LUMINANCE:
- return GL_LUMINANCE;
- case GL_COMPRESSED_LUMINANCE_ALPHA:
- return GL_LUMINANCE_ALPHA;
- case GL_COMPRESSED_INTENSITY:
- return GL_INTENSITY;
- case GL_COMPRESSED_RGB:
- return GL_RGB;
- case GL_COMPRESSED_RGBA:
- return GL_RGBA;
- default:
- ; /* fallthrough */
- }
-
- if (ctx->Extensions.TDFX_texture_compression_FXT1) {
- switch (internalFormat) {
- case GL_COMPRESSED_RGB_FXT1_3DFX:
- return GL_RGB;
- case GL_COMPRESSED_RGBA_FXT1_3DFX:
- return GL_RGBA;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.EXT_texture_compression_s3tc) {
- switch (internalFormat) {
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- return GL_RGB;
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- return GL_RGBA;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.S3_s3tc) {
- switch (internalFormat) {
- case GL_RGB_S3TC:
- case GL_RGB4_S3TC:
- return GL_RGB;
- case GL_RGBA_S3TC:
- case GL_RGBA4_S3TC:
- return GL_RGBA;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.MESA_ycbcr_texture) {
- if (internalFormat == GL_YCBCR_MESA)
- return GL_YCBCR_MESA;
- }
-
- if (ctx->Extensions.ARB_texture_float) {
- switch (internalFormat) {
- case GL_ALPHA16F_ARB:
- case GL_ALPHA32F_ARB:
- return GL_ALPHA;
- case GL_RGBA16F_ARB:
- case GL_RGBA32F_ARB:
- return GL_RGBA;
- case GL_RGB16F_ARB:
- case GL_RGB32F_ARB:
- return GL_RGB;
- case GL_INTENSITY16F_ARB:
- case GL_INTENSITY32F_ARB:
- return GL_INTENSITY;
- case GL_LUMINANCE16F_ARB:
- case GL_LUMINANCE32F_ARB:
- return GL_LUMINANCE;
- case GL_LUMINANCE_ALPHA16F_ARB:
- case GL_LUMINANCE_ALPHA32F_ARB:
- return GL_LUMINANCE_ALPHA;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.ATI_envmap_bumpmap) {
- switch (internalFormat) {
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- return GL_DUDV_ATI;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.MESA_texture_signed_rgba) {
- switch (internalFormat) {
- case GL_RGBA_SNORM:
- case GL_RGBA8_SNORM:
- return GL_RGBA;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.EXT_packed_depth_stencil) {
- switch (internalFormat) {
- case GL_DEPTH_STENCIL_EXT:
- case GL_DEPTH24_STENCIL8_EXT:
- return GL_DEPTH_STENCIL_EXT;
- default:
- ; /* fallthrough */
- }
- }
-
-#if FEATURE_EXT_texture_sRGB
- if (ctx->Extensions.EXT_texture_sRGB) {
- switch (internalFormat) {
- case GL_SRGB_EXT:
- case GL_SRGB8_EXT:
- case GL_COMPRESSED_SRGB_EXT:
- case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
- return GL_RGB;
- case GL_SRGB_ALPHA_EXT:
- case GL_SRGB8_ALPHA8_EXT:
- case GL_COMPRESSED_SRGB_ALPHA_EXT:
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
- return GL_RGBA;
- case GL_SLUMINANCE_ALPHA_EXT:
- case GL_SLUMINANCE8_ALPHA8_EXT:
- case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
- return GL_LUMINANCE_ALPHA;
- case GL_SLUMINANCE_EXT:
- case GL_SLUMINANCE8_EXT:
- case GL_COMPRESSED_SLUMINANCE_EXT:
- return GL_LUMINANCE;
- default:
- ; /* fallthrough */
- }
- }
-#endif /* FEATURE_EXT_texture_sRGB */
-
- if (ctx->Extensions.EXT_texture_integer) {
- switch (internalFormat) {
- case GL_RGBA8UI_EXT:
- case GL_RGBA16UI_EXT:
- case GL_RGBA32UI_EXT:
- case GL_RGBA8I_EXT:
- case GL_RGBA16I_EXT:
- case GL_RGBA32I_EXT:
- return GL_RGBA;
- case GL_RGB8UI_EXT:
- case GL_RGB16UI_EXT:
- case GL_RGB32UI_EXT:
- case GL_RGB8I_EXT:
- case GL_RGB16I_EXT:
- case GL_RGB32I_EXT:
- return GL_RGB;
- case GL_ALPHA8UI_EXT:
- case GL_ALPHA16UI_EXT:
- case GL_ALPHA32UI_EXT:
- case GL_ALPHA8I_EXT:
- case GL_ALPHA16I_EXT:
- case GL_ALPHA32I_EXT:
- return GL_ALPHA;
- case GL_INTENSITY8UI_EXT:
- case GL_INTENSITY16UI_EXT:
- case GL_INTENSITY32UI_EXT:
- case GL_INTENSITY8I_EXT:
- case GL_INTENSITY16I_EXT:
- case GL_INTENSITY32I_EXT:
- return GL_INTENSITY;
- case GL_LUMINANCE8UI_EXT:
- case GL_LUMINANCE16UI_EXT:
- case GL_LUMINANCE32UI_EXT:
- case GL_LUMINANCE8I_EXT:
- case GL_LUMINANCE16I_EXT:
- case GL_LUMINANCE32I_EXT:
- return GL_LUMINANCE;
- case GL_LUMINANCE_ALPHA8UI_EXT:
- case GL_LUMINANCE_ALPHA16UI_EXT:
- case GL_LUMINANCE_ALPHA32UI_EXT:
- case GL_LUMINANCE_ALPHA8I_EXT:
- case GL_LUMINANCE_ALPHA16I_EXT:
- case GL_LUMINANCE_ALPHA32I_EXT:
- return GL_LUMINANCE_ALPHA;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.ARB_texture_rg) {
- switch (internalFormat) {
- case GL_R16F:
- /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
- */
- if (!ctx->Extensions.ARB_half_float_pixel)
- break;
- /* FALLTHROUGH */
- case GL_R32F:
- if (!ctx->Extensions.ARB_texture_float)
- break;
- return GL_RED;
- case GL_R8I:
- case GL_R8UI:
- case GL_R16I:
- case GL_R16UI:
- case GL_R32I:
- case GL_R32UI:
- if (!ctx->Extensions.EXT_texture_integer)
- break;
- /* FALLTHROUGH */
- case GL_R8:
- case GL_R16:
- case GL_RED:
- case GL_COMPRESSED_RED:
- return GL_RED;
-
- case GL_RG16F:
- /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
- */
- if (!ctx->Extensions.ARB_half_float_pixel)
- break;
- /* FALLTHROUGH */
- case GL_RG32F:
- if (!ctx->Extensions.ARB_texture_float)
- break;
- return GL_RG;
- case GL_RG8I:
- case GL_RG8UI:
- case GL_RG16I:
- case GL_RG16UI:
- case GL_RG32I:
- case GL_RG32UI:
- if (!ctx->Extensions.EXT_texture_integer)
- break;
- /* FALLTHROUGH */
- case GL_RG:
- case GL_RG8:
- case GL_RG16:
- case GL_COMPRESSED_RG:
- return GL_RG;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.EXT_texture_shared_exponent) {
- switch (internalFormat) {
- case GL_RGB9_E5_EXT:
- return GL_RGB;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.EXT_packed_float) {
- switch (internalFormat) {
- case GL_R11F_G11F_B10F_EXT:
- return GL_RGB;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.ARB_depth_buffer_float) {
- switch (internalFormat) {
- case GL_DEPTH_COMPONENT32F:
- return GL_DEPTH_COMPONENT;
- case GL_DEPTH32F_STENCIL8:
- return GL_DEPTH_STENCIL;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.ARB_texture_compression_rgtc) {
- switch (internalFormat) {
- case GL_COMPRESSED_RED_RGTC1:
- case GL_COMPRESSED_SIGNED_RED_RGTC1:
- return GL_RED;
- case GL_COMPRESSED_RG_RGTC2:
- case GL_COMPRESSED_SIGNED_RG_RGTC2:
- return GL_RG;
- default:
- ; /* fallthrough */
- }
- }
-
- return -1; /* error */
-}
-
-
-/**
- * For cube map faces, return a face index in [0,5].
- * For other targets return 0;
- */
-GLuint
-_mesa_tex_target_to_face(GLenum target)
-{
- if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
- target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)
- return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X;
- else
- return 0;
-}
-
-
-
-/**
- * Store a gl_texture_image pointer in a gl_texture_object structure
- * according to the target and level parameters.
- *
- * \param tObj texture object.
- * \param target texture target.
- * \param level image level.
- * \param texImage texture image.
- *
- * This was basically prompted by the introduction of cube maps.
- */
-void
-_mesa_set_tex_image(struct gl_texture_object *tObj,
- GLenum target, GLint level,
- struct gl_texture_image *texImage)
-{
- const GLuint face = _mesa_tex_target_to_face(target);
-
- ASSERT(tObj);
- ASSERT(texImage);
- ASSERT(target != GL_TEXTURE_RECTANGLE_NV || level == 0);
-
- tObj->Image[face][level] = texImage;
-
- /* Set the 'back' pointer */
- texImage->TexObject = tObj;
-}
-
-
-/**
- * Allocate a texture image structure.
- *
- * Called via ctx->Driver.NewTextureImage() unless overriden by a device
- * driver.
- *
- * \return a pointer to gl_texture_image struct with all fields initialized to
- * zero.
- */
-struct gl_texture_image *
-_mesa_new_texture_image( struct gl_context *ctx )
-{
- (void) ctx;
- return CALLOC_STRUCT(gl_texture_image);
-}
-
-
-/**
- * Free texture image data.
- * This function is a fallback called via ctx->Driver.FreeTexImageData().
- *
- * \param texImage texture image.
- *
- * Free the texture image data if it's not marked as client data.
- */
-void
-_mesa_free_texture_image_data(struct gl_context *ctx,
- struct gl_texture_image *texImage)
-{
- (void) ctx;
-
- if (texImage->Data && !texImage->IsClientData) {
- /* free the old texture data */
- _mesa_free_texmemory(texImage->Data);
- }
-
- texImage->Data = NULL;
-}
-
-
-/**
- * Free texture image.
- *
- * \param texImage texture image.
- *
- * Free the texture image structure and the associated image data.
- */
-void
-_mesa_delete_texture_image(struct gl_context *ctx,
- struct gl_texture_image *texImage)
-{
- /* Free texImage->Data and/or any other driver-specific texture
- * image storage.
- */
- ASSERT(ctx->Driver.FreeTexImageData);
- ctx->Driver.FreeTexImageData( ctx, texImage );
-
- ASSERT(texImage->Data == NULL);
- if (texImage->ImageOffsets)
- free(texImage->ImageOffsets);
- free(texImage);
-}
-
-
-/**
- * Test if a target is a proxy target.
- *
- * \param target texture target.
- *
- * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
- */
-GLboolean
-_mesa_is_proxy_texture(GLenum target)
-{
- /* NUM_TEXTURE_TARGETS should match number of terms below */
- assert(NUM_TEXTURE_TARGETS == 7);
-
- return (target == GL_PROXY_TEXTURE_1D ||
- target == GL_PROXY_TEXTURE_2D ||
- target == GL_PROXY_TEXTURE_3D ||
- target == GL_PROXY_TEXTURE_CUBE_MAP_ARB ||
- target == GL_PROXY_TEXTURE_RECTANGLE_NV ||
- target == GL_PROXY_TEXTURE_1D_ARRAY_EXT ||
- target == GL_PROXY_TEXTURE_2D_ARRAY_EXT);
-}
-
-
-/**
- * Return the proxy target which corresponds to the given texture target
- */
-static GLenum
-get_proxy_target(GLenum target)
-{
- switch (target) {
- case GL_TEXTURE_1D:
- case GL_PROXY_TEXTURE_1D:
- return GL_PROXY_TEXTURE_1D;
- case GL_TEXTURE_2D:
- case GL_PROXY_TEXTURE_2D:
- return GL_PROXY_TEXTURE_2D;
- case GL_TEXTURE_3D:
- case GL_PROXY_TEXTURE_3D:
- return GL_PROXY_TEXTURE_3D;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
- case GL_TEXTURE_CUBE_MAP_ARB:
- case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
- return GL_PROXY_TEXTURE_CUBE_MAP_ARB;
- case GL_TEXTURE_RECTANGLE_NV:
- case GL_PROXY_TEXTURE_RECTANGLE_NV:
- return GL_PROXY_TEXTURE_RECTANGLE_NV;
- case GL_TEXTURE_1D_ARRAY_EXT:
- case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
- return GL_PROXY_TEXTURE_1D_ARRAY_EXT;
- case GL_TEXTURE_2D_ARRAY_EXT:
- case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
- return GL_PROXY_TEXTURE_2D_ARRAY_EXT;
- default:
- _mesa_problem(NULL, "unexpected target in get_proxy_target()");
- return 0;
- }
-}
-
-
-/**
- * Get the texture object that corresponds to the target of the given
- * texture unit.
- *
- * \param ctx GL context.
- * \param texUnit texture unit.
- * \param target texture target.
- *
- * \return pointer to the texture object on success, or NULL on failure.
- *
- * \sa gl_texture_unit.
- */
-struct gl_texture_object *
-_mesa_select_tex_object(struct gl_context *ctx,
- const struct gl_texture_unit *texUnit,
- GLenum target)
-{
- const GLboolean arrayTex = (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array);
-
- switch (target) {
- case GL_TEXTURE_1D:
- return texUnit->CurrentTex[TEXTURE_1D_INDEX];
- case GL_PROXY_TEXTURE_1D:
- return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX];
- case GL_TEXTURE_2D:
- return texUnit->CurrentTex[TEXTURE_2D_INDEX];
- case GL_PROXY_TEXTURE_2D:
- return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
- case GL_TEXTURE_3D:
- return texUnit->CurrentTex[TEXTURE_3D_INDEX];
- case GL_PROXY_TEXTURE_3D:
- return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX];
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
- case GL_TEXTURE_CUBE_MAP_ARB:
- return ctx->Extensions.ARB_texture_cube_map
- ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL;
- case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
- return ctx->Extensions.ARB_texture_cube_map
- ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL;
- case GL_TEXTURE_RECTANGLE_NV:
- return ctx->Extensions.NV_texture_rectangle
- ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL;
- case GL_PROXY_TEXTURE_RECTANGLE_NV:
- return ctx->Extensions.NV_texture_rectangle
- ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL;
- case GL_TEXTURE_1D_ARRAY_EXT:
- return arrayTex ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
- case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
- return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
- case GL_TEXTURE_2D_ARRAY_EXT:
- return arrayTex ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
- case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
- return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
- default:
- _mesa_problem(NULL, "bad target in _mesa_select_tex_object()");
- return NULL;
- }
-}
-
-
-/**
- * Return pointer to texture object for given target on current texture unit.
- */
-struct gl_texture_object *
-_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target)
-{
- struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
- return _mesa_select_tex_object(ctx, texUnit, target);
-}
-
-
-/**
- * Get a texture image pointer from a texture object, given a texture
- * target and mipmap level. The target and level parameters should
- * have already been error-checked.
- *
- * \param ctx GL context.
- * \param texObj texture unit.
- * \param target texture target.
- * \param level image level.
- *
- * \return pointer to the texture image structure, or NULL on failure.
- */
-struct gl_texture_image *
-_mesa_select_tex_image(struct gl_context *ctx,
- const struct gl_texture_object *texObj,
- GLenum target, GLint level)
-{
- const GLuint face = _mesa_tex_target_to_face(target);
-
- ASSERT(texObj);
- ASSERT(level >= 0);
- ASSERT(level < MAX_TEXTURE_LEVELS);
-
- return texObj->Image[face][level];
-}
-
-
-/**
- * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
- * it and install it. Only return NULL if passed a bad parameter or run
- * out of memory.
- */
-struct gl_texture_image *
-_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj,
- GLenum target, GLint level)
-{
- struct gl_texture_image *texImage;
-
- if (!texObj)
- return NULL;
-
- texImage = _mesa_select_tex_image(ctx, texObj, target, level);
- if (!texImage) {
- texImage = ctx->Driver.NewTextureImage(ctx);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation");
- return NULL;
- }
-
- _mesa_set_tex_image(texObj, target, level, texImage);
- }
-
- return texImage;
-}
-
-
-/**
- * Return pointer to the specified proxy texture image.
- * Note that proxy textures are per-context, not per-texture unit.
- * \return pointer to texture image or NULL if invalid target, invalid
- * level, or out of memory.
- */
-struct gl_texture_image *
-_mesa_get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level)
-{
- struct gl_texture_image *texImage;
- GLuint texIndex;
-
- if (level < 0 )
- return NULL;
-
- switch (target) {
- case GL_PROXY_TEXTURE_1D:
- if (level >= ctx->Const.MaxTextureLevels)
- return NULL;
- texIndex = TEXTURE_1D_INDEX;
- break;
- case GL_PROXY_TEXTURE_2D:
- if (level >= ctx->Const.MaxTextureLevels)
- return NULL;
- texIndex = TEXTURE_2D_INDEX;
- break;
- case GL_PROXY_TEXTURE_3D:
- if (level >= ctx->Const.Max3DTextureLevels)
- return NULL;
- texIndex = TEXTURE_3D_INDEX;
- break;
- case GL_PROXY_TEXTURE_CUBE_MAP:
- if (level >= ctx->Const.MaxCubeTextureLevels)
- return NULL;
- texIndex = TEXTURE_CUBE_INDEX;
- break;
- case GL_PROXY_TEXTURE_RECTANGLE_NV:
- if (level > 0)
- return NULL;
- texIndex = TEXTURE_RECT_INDEX;
- break;
- case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
- if (level >= ctx->Const.MaxTextureLevels)
- return NULL;
- texIndex = TEXTURE_1D_ARRAY_INDEX;
- break;
- case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
- if (level >= ctx->Const.MaxTextureLevels)
- return NULL;
- texIndex = TEXTURE_2D_ARRAY_INDEX;
- break;
- default:
- return NULL;
- }
-
- texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level];
- if (!texImage) {
- texImage = ctx->Driver.NewTextureImage(ctx);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
- return NULL;
- }
- ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage;
- /* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.ProxyTex[texIndex];
- }
- return texImage;
-}
-
-
-/**
- * Get the maximum number of allowed mipmap levels.
- *
- * \param ctx GL context.
- * \param target texture target.
- *
- * \return the maximum number of allowed mipmap levels for the given
- * texture target, or zero if passed a bad target.
- *
- * \sa gl_constants.
- */
-GLint
-_mesa_max_texture_levels(struct gl_context *ctx, GLenum target)
-{
- switch (target) {
- case GL_TEXTURE_1D:
- case GL_PROXY_TEXTURE_1D:
- case GL_TEXTURE_2D:
- case GL_PROXY_TEXTURE_2D:
- return ctx->Const.MaxTextureLevels;
- case GL_TEXTURE_3D:
- case GL_PROXY_TEXTURE_3D:
- return ctx->Const.Max3DTextureLevels;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
- case GL_TEXTURE_CUBE_MAP_ARB:
- case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
- return ctx->Extensions.ARB_texture_cube_map
- ? ctx->Const.MaxCubeTextureLevels : 0;
- case GL_TEXTURE_RECTANGLE_NV:
- case GL_PROXY_TEXTURE_RECTANGLE_NV:
- return ctx->Extensions.NV_texture_rectangle ? 1 : 0;
- case GL_TEXTURE_1D_ARRAY_EXT:
- case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
- case GL_TEXTURE_2D_ARRAY_EXT:
- case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
- return (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array)
- ? ctx->Const.MaxTextureLevels : 0;
- default:
- return 0; /* bad target */
- }
-}
-
-
-/**
- * Return number of dimensions per mipmap level for the given texture target.
- */
-GLint
-_mesa_get_texture_dimensions(GLenum target)
-{
- switch (target) {
- case GL_TEXTURE_1D:
- case GL_PROXY_TEXTURE_1D:
- return 1;
- case GL_TEXTURE_2D:
- case GL_TEXTURE_RECTANGLE:
- case GL_TEXTURE_CUBE_MAP:
- case GL_PROXY_TEXTURE_2D:
- case GL_PROXY_TEXTURE_RECTANGLE:
- case GL_PROXY_TEXTURE_CUBE_MAP:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- case GL_TEXTURE_1D_ARRAY:
- case GL_PROXY_TEXTURE_1D_ARRAY:
- return 2;
- case GL_TEXTURE_3D:
- case GL_PROXY_TEXTURE_3D:
- case GL_TEXTURE_2D_ARRAY:
- case GL_PROXY_TEXTURE_2D_ARRAY:
- return 3;
- default:
- _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()",
- target);
- return 2;
- }
-}
-
-
-
-
-#if 000 /* not used anymore */
-/*
- * glTexImage[123]D can accept a NULL image pointer. In this case we
- * create a texture image with unspecified image contents per the OpenGL
- * spec.
- */
-static GLubyte *
-make_null_texture(GLint width, GLint height, GLint depth, GLenum format)
-{
- const GLint components = _mesa_components_in_format(format);
- const GLint numPixels = width * height * depth;
- GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte));
-
-#ifdef DEBUG
- /*
- * Let's see if anyone finds this. If glTexImage2D() is called with
- * a NULL image pointer then load the texture image with something
- * interesting instead of leaving it indeterminate.
- */
- if (data) {
- static const char message[8][32] = {
- " X X XXXXX XXX X ",
- " XX XX X X X X X ",
- " X X X X X X X ",
- " X X XXXX XXX XXXXX ",
- " X X X X X X ",
- " X X X X X X X ",
- " X X XXXXX XXX X X ",
- " "
- };
-
- GLubyte *imgPtr = data;
- GLint h, i, j, k;
- for (h = 0; h < depth; h++) {
- for (i = 0; i < height; i++) {
- GLint srcRow = 7 - (i % 8);
- for (j = 0; j < width; j++) {
- GLint srcCol = j % 32;
- GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70;
- for (k = 0; k < components; k++) {
- *imgPtr++ = texel;
- }
- }
- }
- }
- }
-#endif
-
- return data;
-}
-#endif
-
-
-
-/**
- * Reset the fields of a gl_texture_image struct to zero.
- *
- * \param img texture image structure.
- *
- * This is called when a proxy texture test fails, we set all the
- * image members (except DriverData) to zero.
- * It's also used in glTexImage[123]D as a safeguard to be sure all
- * required fields get initialized properly by the Driver.TexImage[123]D
- * functions.
- */
-static void
-clear_teximage_fields(struct gl_texture_image *img)
-{
- ASSERT(img);
- img->_BaseFormat = 0;
- img->InternalFormat = 0;
- img->Border = 0;
- img->Width = 0;
- img->Height = 0;
- img->Depth = 0;
- img->RowStride = 0;
- if (img->ImageOffsets) {
- free(img->ImageOffsets);
- img->ImageOffsets = NULL;
- }
- img->Width2 = 0;
- img->Height2 = 0;
- img->Depth2 = 0;
- img->WidthLog2 = 0;
- img->HeightLog2 = 0;
- img->DepthLog2 = 0;
- img->Data = NULL;
- img->TexFormat = MESA_FORMAT_NONE;
- img->FetchTexelc = NULL;
- img->FetchTexelf = NULL;
-}
-
-
-/**
- * Initialize basic fields of the gl_texture_image struct.
- *
- * \param ctx GL context.
- * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
- * \param img texture image structure to be initialized.
- * \param width image width.
- * \param height image height.
- * \param depth image depth.
- * \param border image border.
- * \param internalFormat internal format.
- * \param format the actual hardware format (one of MESA_FORMAT_*)
- *
- * Fills in the fields of \p img with the given information.
- * Note: width, height and depth include the border.
- */
-void
-_mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
- struct gl_texture_image *img,
- GLsizei width, GLsizei height, GLsizei depth,
- GLint border, GLenum internalFormat,
- gl_format format)
-{
- GLint i, dims;
-
- ASSERT(img);
- ASSERT(width >= 0);
- ASSERT(height >= 0);
- ASSERT(depth >= 0);
-
- img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat );
- ASSERT(img->_BaseFormat > 0);
- img->InternalFormat = internalFormat;
- img->Border = border;
- img->Width = width;
- img->Height = height;
- img->Depth = depth;
-
- img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */
- img->WidthLog2 = logbase2(img->Width2);
-
- if (height == 1) { /* 1-D texture */
- img->Height2 = 1;
- img->HeightLog2 = 0;
- }
- else {
- img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */
- img->HeightLog2 = logbase2(img->Height2);
- }
-
- if (depth == 1) { /* 2-D texture */
- img->Depth2 = 1;
- img->DepthLog2 = 0;
- }
- else {
- img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */
- img->DepthLog2 = logbase2(img->Depth2);
- }
-
- img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
-
- if ((width == 1 || _mesa_is_pow_two(img->Width2)) &&
- (height == 1 || _mesa_is_pow_two(img->Height2)) &&
- (depth == 1 || _mesa_is_pow_two(img->Depth2)))
- img->_IsPowerOfTwo = GL_TRUE;
- else
- img->_IsPowerOfTwo = GL_FALSE;
-
- /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
- img->RowStride = width;
- /* Allocate the ImageOffsets array and initialize to typical values.
- * We allocate the array for 1D/2D textures too in order to avoid special-
- * case code in the texstore routines.
- */
- if (img->ImageOffsets)
- free(img->ImageOffsets);
- img->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint));
- for (i = 0; i < depth; i++) {
- img->ImageOffsets[i] = i * width * height;
- }
-
- /* Compute Width/Height/DepthScale for mipmap lod computation */
- if (target == GL_TEXTURE_RECTANGLE_NV) {
- /* scale = 1.0 since texture coords directly map to texels */
- img->WidthScale = 1.0;
- img->HeightScale = 1.0;
- img->DepthScale = 1.0;
- }
- else {
- img->WidthScale = (GLfloat) img->Width;
- img->HeightScale = (GLfloat) img->Height;
- img->DepthScale = (GLfloat) img->Depth;
- }
-
- img->TexFormat = format;
-
- dims = _mesa_get_texture_dimensions(target);
-
- _mesa_set_fetch_functions(img, dims);
-}
-
-
-/**
- * Free and clear fields of the gl_texture_image struct.
- *
- * \param ctx GL context.
- * \param texImage texture image structure to be cleared.
- *
- * After the call, \p texImage will have no data associated with it. Its
- * fields are cleared so that its parent object will test incomplete.
- */
-void
-_mesa_clear_texture_image(struct gl_context *ctx,
- struct gl_texture_image *texImage)
-{
- ctx->Driver.FreeTexImageData(ctx, texImage);
- clear_teximage_fields(texImage);
-}
-
-
-/**
- * This is the fallback for Driver.TestProxyTexImage(). Test the texture
- * level, width, height and depth against the ctx->Const limits for textures.
- *
- * A hardware driver might override this function if, for example, the
- * max 3D texture size is 512x512x64 (i.e. not a cube).
- *
- * Note that width, height, depth == 0 is not an error. However, a
- * texture with zero width/height/depth will be considered "incomplete"
- * and texturing will effectively be disabled.
- *
- * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
- * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
- * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
- * \param level as passed to glTexImage
- * \param internalFormat as passed to glTexImage
- * \param format as passed to glTexImage
- * \param type as passed to glTexImage
- * \param width as passed to glTexImage
- * \param height as passed to glTexImage
- * \param depth as passed to glTexImage
- * \param border as passed to glTexImage
- * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
- */
-GLboolean
-_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat, GLenum format, GLenum type,
- GLint width, GLint height, GLint depth, GLint border)
-{
- GLint maxSize;
-
- (void) internalFormat;
- (void) format;
- (void) type;
-
- switch (target) {
- case GL_PROXY_TEXTURE_1D:
- maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
- if (width < 2 * border || width > 2 + maxSize)
- return GL_FALSE;
- if (level >= ctx->Const.MaxTextureLevels)
- return GL_FALSE;
- if (!ctx->Extensions.ARB_texture_non_power_of_two) {
- if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
- return GL_FALSE;
- }
- return GL_TRUE;
-
- case GL_PROXY_TEXTURE_2D:
- maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
- if (width < 2 * border || width > 2 + maxSize)
- return GL_FALSE;
- if (height < 2 * border || height > 2 + maxSize)
- return GL_FALSE;
- if (level >= ctx->Const.MaxTextureLevels)
- return GL_FALSE;
- if (!ctx->Extensions.ARB_texture_non_power_of_two) {
- if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
- return GL_FALSE;
- if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
- return GL_FALSE;
- }
- return GL_TRUE;
-
- case GL_PROXY_TEXTURE_3D:
- maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
- if (width < 2 * border || width > 2 + maxSize)
- return GL_FALSE;
- if (height < 2 * border || height > 2 + maxSize)
- return GL_FALSE;
- if (depth < 2 * border || depth > 2 + maxSize)
- return GL_FALSE;
- if (level >= ctx->Const.Max3DTextureLevels)
- return GL_FALSE;
- if (!ctx->Extensions.ARB_texture_non_power_of_two) {
- if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
- return GL_FALSE;
- if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
- return GL_FALSE;
- if (depth > 0 && !_mesa_is_pow_two(depth - 2 * border))
- return GL_FALSE;
- }
- return GL_TRUE;
-
- case GL_PROXY_TEXTURE_RECTANGLE_NV:
- maxSize = ctx->Const.MaxTextureRectSize;
- if (width < 0 || width > maxSize)
- return GL_FALSE;
- if (height < 0 || height > maxSize)
- return GL_FALSE;
- if (level != 0)
- return GL_FALSE;
- return GL_TRUE;
-
- case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
- maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1);
- if (width < 2 * border || width > 2 + maxSize)
- return GL_FALSE;
- if (height < 2 * border || height > 2 + maxSize)
- return GL_FALSE;
- if (level >= ctx->Const.MaxCubeTextureLevels)
- return GL_FALSE;
- if (!ctx->Extensions.ARB_texture_non_power_of_two) {
- if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
- return GL_FALSE;
- if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
- return GL_FALSE;
- }
- return GL_TRUE;
-
- case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
- maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
- if (width < 2 * border || width > 2 + maxSize)
- return GL_FALSE;
- if (height < 1 || height > ctx->Const.MaxArrayTextureLayers)
- return GL_FALSE;
- if (level >= ctx->Const.MaxTextureLevels)
- return GL_FALSE;
- if (!ctx->Extensions.ARB_texture_non_power_of_two) {
- if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
- return GL_FALSE;
- }
- return GL_TRUE;
-
- case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
- maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
- if (width < 2 * border || width > 2 + maxSize)
- return GL_FALSE;
- if (height < 2 * border || height > 2 + maxSize)
- return GL_FALSE;
- if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers)
- return GL_FALSE;
- if (level >= ctx->Const.MaxTextureLevels)
- return GL_FALSE;
- if (!ctx->Extensions.ARB_texture_non_power_of_two) {
- if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
- return GL_FALSE;
- if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
- return GL_FALSE;
- }
- return GL_TRUE;
-
- default:
- _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage");
- return GL_FALSE;
- }
-}
-
-
-/**
- * Check if the memory used by the texture would exceed the driver's limit.
- * This lets us support a max 3D texture size of 8K (for example) but
- * prevents allocating a full 8K x 8K x 8K texture.
- * XXX this could be rolled into the proxy texture size test (above) but
- * we don't have the actual texture internal format at that point.
- */
-static GLboolean
-legal_texture_size(struct gl_context *ctx, gl_format format,
- GLint width, GLint height, GLint depth)
-{
- uint64_t bytes = _mesa_format_image_size64(format, width, height, depth);
- uint64_t mbytes = bytes / (1024 * 1024); /* convert to MB */
- return mbytes <= (uint64_t) ctx->Const.MaxTextureMbytes;
-}
-
-
-
-/**
- * Helper function to determine whether a target and specific compression
- * format are supported.
- */
-static GLboolean
-target_can_be_compressed(const struct gl_context *ctx, GLenum target,
- GLenum intFormat)
-{
- (void) intFormat; /* not used yet */
-
- switch (target) {
- case GL_TEXTURE_2D:
- case GL_PROXY_TEXTURE_2D:
- return GL_TRUE; /* true for any compressed format so far */
- case GL_PROXY_TEXTURE_CUBE_MAP:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- return ctx->Extensions.ARB_texture_cube_map;
- case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
- case GL_TEXTURE_2D_ARRAY_EXT:
- return (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array);
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Check if the given texture target value is legal for a
- * glTexImage1/2/3D call.
- */
-static GLboolean
-legal_teximage_target(struct gl_context *ctx, GLuint dims, GLenum target)
-{
- switch (dims) {
- case 1:
- switch (target) {
- case GL_TEXTURE_1D:
- case GL_PROXY_TEXTURE_1D:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
- case 2:
- switch (target) {
- case GL_TEXTURE_2D:
- case GL_PROXY_TEXTURE_2D:
- return GL_TRUE;
- case GL_PROXY_TEXTURE_CUBE_MAP:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- return ctx->Extensions.ARB_texture_cube_map;
- case GL_TEXTURE_RECTANGLE_NV:
- case GL_PROXY_TEXTURE_RECTANGLE_NV:
- return ctx->Extensions.NV_texture_rectangle;
- case GL_TEXTURE_1D_ARRAY_EXT:
- case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
- return (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array);
- default:
- return GL_FALSE;
- }
- case 3:
- switch (target) {
- case GL_TEXTURE_3D:
- case GL_PROXY_TEXTURE_3D:
- return GL_TRUE;
- case GL_TEXTURE_2D_ARRAY_EXT:
- case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
- return (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array);
- default:
- return GL_FALSE;
- }
- default:
- _mesa_problem(ctx, "invalid dims=%u in legal_teximage_target()", dims);
- return GL_FALSE;
- }
-}
-
-
-/**
- * Check if the given texture target value is legal for a
- * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
- * The difference compared to legal_teximage_target() above is that
- * proxy targets are not supported.
- */
-static GLboolean
-legal_texsubimage_target(struct gl_context *ctx, GLuint dims, GLenum target)
-{
- switch (dims) {
- case 1:
- return target == GL_TEXTURE_1D;
- case 2:
- switch (target) {
- case GL_TEXTURE_2D:
- return GL_TRUE;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- return ctx->Extensions.ARB_texture_cube_map;
- case GL_TEXTURE_RECTANGLE_NV:
- return ctx->Extensions.NV_texture_rectangle;
- case GL_TEXTURE_1D_ARRAY_EXT:
- return (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array);
- default:
- return GL_FALSE;
- }
- case 3:
- switch (target) {
- case GL_TEXTURE_3D:
- return GL_TRUE;
- case GL_TEXTURE_2D_ARRAY_EXT:
- return (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array);
- default:
- return GL_FALSE;
- }
- default:
- _mesa_problem(ctx, "invalid dims=%u in legal_texsubimage_target()",
- dims);
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test the glTexImage[123]D() parameters for errors.
- *
- * \param ctx GL context.
- * \param dimensions texture image dimensions (must be 1, 2 or 3).
- * \param target texture target given by the user.
- * \param level image level given by the user.
- * \param internalFormat internal format given by the user.
- * \param format pixel data format given by the user.
- * \param type pixel data type given by the user.
- * \param width image width given by the user.
- * \param height image height given by the user.
- * \param depth image depth given by the user.
- * \param border image border given by the user.
- *
- * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
- *
- * Verifies each of the parameters against the constants specified in
- * __struct gl_contextRec::Const and the supported extensions, and according
- * to the OpenGL specification.
- */
-static GLboolean
-texture_error_check( struct gl_context *ctx,
- GLuint dimensions, GLenum target,
- GLint level, GLint internalFormat,
- GLenum format, GLenum type,
- GLint width, GLint height,
- GLint depth, GLint border )
-{
- const GLenum proxyTarget = get_proxy_target(target);
- const GLboolean isProxy = target == proxyTarget;
- GLboolean sizeOK = GL_TRUE;
- GLboolean colorFormat, indexFormat;
-
- /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
- if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
- if (!isProxy) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexImage%dD(level=%d)", dimensions, level);
- }
- return GL_TRUE;
- }
-
- /* Check border */
- if (border < 0 || border > 1 ||
- ((target == GL_TEXTURE_RECTANGLE_NV ||
- target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) {
- if (!isProxy) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexImage%dD(border=%d)", dimensions, border);
- }
- return GL_TRUE;
- }
-
- if (width < 0 || height < 0 || depth < 0) {
- if (!isProxy) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexImage%dD(width, height or depth < 0)", dimensions);
- }
- return GL_TRUE;
- }
-
- /* Do this simple check before calling the TestProxyTexImage() function */
- if (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
- sizeOK = (width == height);
- }
-
- /*
- * Use the proxy texture driver hook to see if the size/level/etc are
- * legal.
- */
- sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level,
- internalFormat, format,
- type, width, height,
- depth, border);
- if (!sizeOK) {
- if (!isProxy) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
- dimensions, level, width, height, depth);
- }
- return GL_TRUE;
- }
-
- /* Check internalFormat */
- if (_mesa_base_tex_format(ctx, internalFormat) < 0) {
- if (!isProxy) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexImage%dD(internalFormat=%s)",
- dimensions, _mesa_lookup_enum_by_nr(internalFormat));
- }
- return GL_TRUE;
- }
-
- /* Check incoming image format and type */
- if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
- /* Normally, GL_INVALID_OPERATION is generated by a format/type
- * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
- * GL_EXT_texture_integer extension, some combinations should generate
- * GL_INVALID_ENUM instead (grr!).
- */
- if (!isProxy) {
- GLenum error = _mesa_is_integer_format(format)
- ? GL_INVALID_ENUM : GL_INVALID_OPERATION;
- _mesa_error(ctx, error,
- "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
- dimensions, format, type);
- }
- return GL_TRUE;
- }
-
- /* make sure internal format and format basically agree */
- colorFormat = _mesa_is_color_format(format);
- indexFormat = _mesa_is_index_format(format);
- if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) ||
- (_mesa_is_index_format(internalFormat) && !indexFormat) ||
- (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) ||
- (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) ||
- (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) ||
- (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) {
- if (!isProxy)
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
- dimensions, internalFormat, format);
- return GL_TRUE;
- }
-
- /* additional checks for ycbcr textures */
- if (internalFormat == GL_YCBCR_MESA) {
- ASSERT(ctx->Extensions.MESA_ycbcr_texture);
- if (type != GL_UNSIGNED_SHORT_8_8_MESA &&
- type != GL_UNSIGNED_SHORT_8_8_REV_MESA) {
- char message[100];
- _mesa_snprintf(message, sizeof(message),
- "glTexImage%dD(format/type YCBCR mismatch", dimensions);
- _mesa_error(ctx, GL_INVALID_ENUM, "%s", message);
- return GL_TRUE; /* error */
- }
- if (target != GL_TEXTURE_2D &&
- target != GL_PROXY_TEXTURE_2D &&
- target != GL_TEXTURE_RECTANGLE_NV &&
- target != GL_PROXY_TEXTURE_RECTANGLE_NV) {
- if (!isProxy)
- _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)");
- return GL_TRUE;
- }
- if (border != 0) {
- if (!isProxy) {
- char message[100];
- _mesa_snprintf(message, sizeof(message),
- "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
- dimensions, border);
- _mesa_error(ctx, GL_INVALID_VALUE, "%s", message);
- }
- return GL_TRUE;
- }
- }
-
- /* additional checks for depth textures */
- if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) {
- /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
- if (target != GL_TEXTURE_1D &&
- target != GL_PROXY_TEXTURE_1D &&
- target != GL_TEXTURE_2D &&
- target != GL_PROXY_TEXTURE_2D &&
- target != GL_TEXTURE_RECTANGLE_ARB &&
- target != GL_PROXY_TEXTURE_RECTANGLE_ARB) {
- if (!isProxy)
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glTexImage(target/internalFormat)");
- return GL_TRUE;
- }
- }
-
- /* additional checks for compressed textures */
- if (_mesa_is_compressed_format(ctx, internalFormat)) {
- if (!target_can_be_compressed(ctx, target, internalFormat)) {
- if (!isProxy)
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glTexImage%dD(target)", dimensions);
- return GL_TRUE;
- }
- if (border != 0) {
- if (!isProxy) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexImage%dD(border!=0)", dimensions);
- }
- return GL_TRUE;
- }
- }
-
- /* additional checks for integer textures */
- if (ctx->Extensions.EXT_texture_integer &&
- (_mesa_is_integer_format(format) !=
- _mesa_is_integer_format(internalFormat))) {
- if (!isProxy) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexImage%dD(integer/non-integer format mismatch)",
- dimensions);
- }
- return GL_TRUE;
- }
-
- /* if we get here, the parameters are OK */
- return GL_FALSE;
-}
-
-
-/**
- * Test glTexSubImage[123]D() parameters for errors.
- *
- * \param ctx GL context.
- * \param dimensions texture image dimensions (must be 1, 2 or 3).
- * \param target texture target given by the user.
- * \param level image level given by the user.
- * \param xoffset sub-image x offset given by the user.
- * \param yoffset sub-image y offset given by the user.
- * \param zoffset sub-image z offset given by the user.
- * \param format pixel data format given by the user.
- * \param type pixel data type given by the user.
- * \param width image width given by the user.
- * \param height image height given by the user.
- * \param depth image depth given by the user.
- *
- * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
- *
- * Verifies each of the parameters against the constants specified in
- * __struct gl_contextRec::Const and the supported extensions, and according
- * to the OpenGL specification.
- */
-static GLboolean
-subtexture_error_check( struct gl_context *ctx, GLuint dimensions,
- GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint width, GLint height, GLint depth,
- GLenum format, GLenum type )
-{
- /* Basic level check */
- if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level);
- return GL_TRUE;
- }
-
- /* Check for negative sizes */
- if (width < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexSubImage%dD(width=%d)", dimensions, width);
- return GL_TRUE;
- }
- if (height < 0 && dimensions > 1) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexSubImage%dD(height=%d)", dimensions, height);
- return GL_TRUE;
- }
- if (depth < 0 && dimensions > 2) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexSubImage%dD(depth=%d)", dimensions, depth);
- return GL_TRUE;
- }
-
- if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
- /* As with the glTexImage2D check above, the error code here
- * depends on texture integer.
- */
- GLenum error = _mesa_is_integer_format(format)
- ? GL_INVALID_OPERATION : GL_INVALID_ENUM;
- _mesa_error(ctx, error,
- "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
- dimensions, format, type);
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-
-/**
- * Do second part of glTexSubImage which depends on the destination texture.
- * \return GL_TRUE if error recorded, GL_FALSE otherwise
- */
-static GLboolean
-subtexture_error_check2( struct gl_context *ctx, GLuint dimensions,
- GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint width, GLint height, GLint depth,
- GLenum format, GLenum type,
- const struct gl_texture_image *destTex )
-{
- if (!destTex) {
- /* undefined image level */
- _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions);
- return GL_TRUE;
- }
-
- if (xoffset < -((GLint)destTex->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)",
- dimensions);
- return GL_TRUE;
- }
- if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)",
- dimensions);
- return GL_TRUE;
- }
- if (dimensions > 1) {
- if (yoffset < -((GLint)destTex->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)",
- dimensions);
- return GL_TRUE;
- }
- if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)",
- dimensions);
- return GL_TRUE;
- }
- }
- if (dimensions > 2) {
- if (zoffset < -((GLint)destTex->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)");
- return GL_TRUE;
- }
- if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)");
- return GL_TRUE;
- }
- }
-
- if (_mesa_is_format_compressed(destTex->TexFormat)) {
- GLuint bw, bh;
-
- /* do tests which depend on compression block size */
- _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh);
-
- /* offset must be multiple of block size */
- if ((xoffset % bw != 0) || (yoffset % bh != 0)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
- dimensions, xoffset, yoffset);
- return GL_TRUE;
- }
- /* size must be multiple of bw by bh or equal to whole texture size */
- if ((width % bw != 0) && (GLuint) width != destTex->Width) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexSubImage%dD(width = %d)", dimensions, width);
- return GL_TRUE;
- }
- if ((height % bh != 0) && (GLuint) height != destTex->Height) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexSubImage%dD(height = %d)", dimensions, height);
- return GL_TRUE;
- }
- }
-
- return GL_FALSE;
-}
-
-
-/**
- * Test glCopyTexImage[12]D() parameters for errors.
- *
- * \param ctx GL context.
- * \param dimensions texture image dimensions (must be 1, 2 or 3).
- * \param target texture target given by the user.
- * \param level image level given by the user.
- * \param internalFormat internal format given by the user.
- * \param width image width given by the user.
- * \param height image height given by the user.
- * \param border texture border.
- *
- * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
- *
- * Verifies each of the parameters against the constants specified in
- * __struct gl_contextRec::Const and the supported extensions, and according
- * to the OpenGL specification.
- */
-static GLboolean
-copytexture_error_check( struct gl_context *ctx, GLuint dimensions,
- GLenum target, GLint level, GLint internalFormat,
- GLint width, GLint height, GLint border )
-{
- const GLenum proxyTarget = get_proxy_target(target);
- const GLenum type = GL_FLOAT;
- GLboolean sizeOK;
- GLint format;
-
- /* check target */
- if (!legal_texsubimage_target(ctx, dimensions, target)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)",
- dimensions, _mesa_lookup_enum_by_nr(target));
- return GL_TRUE;
- }
-
- /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
- if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexImage%dD(level=%d)", dimensions, level);
- return GL_TRUE;
- }
-
- /* Check that the source buffer is complete */
- if (ctx->ReadBuffer->Name) {
- if (ctx->ReadBuffer->_Status == 0) {
- _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
- }
- if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
- "glCopyTexImage%dD(invalid readbuffer)", dimensions);
- return GL_TRUE;
- }
- }
-
- /* Check border */
- if (border < 0 || border > 1 ||
- ((target == GL_TEXTURE_RECTANGLE_NV ||
- target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) {
- return GL_TRUE;
- }
-
- format = _mesa_base_tex_format(ctx, internalFormat);
- if (format < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexImage%dD(internalFormat)", dimensions);
- return GL_TRUE;
- }
-
- if (!_mesa_source_buffer_exists(ctx, format)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyTexImage%dD(missing readbuffer)", dimensions);
- return GL_TRUE;
- }
-
- /* Do size, level checking */
- sizeOK = (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB)
- ? (width == height) : 1;
-
- sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level,
- internalFormat, format,
- type, width, height,
- 1, border);
-
- if (!sizeOK) {
- if (dimensions == 1) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexImage1D(width=%d)", width);
- }
- else {
- ASSERT(dimensions == 2);
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexImage2D(width=%d, height=%d)", width, height);
- }
- return GL_TRUE;
- }
-
- if (_mesa_is_compressed_format(ctx, internalFormat)) {
- if (!target_can_be_compressed(ctx, target, internalFormat)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glCopyTexImage%dD(target)", dimensions);
- return GL_TRUE;
- }
- if (border != 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyTexImage%dD(border!=0)", dimensions);
- return GL_TRUE;
- }
- }
- else if (_mesa_is_depth_format(internalFormat)) {
- /* make sure we have depth/stencil buffers */
- if (!ctx->ReadBuffer->_DepthBuffer) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyTexImage%dD(no depth)", dimensions);
- return GL_TRUE;
- }
- }
- else if (_mesa_is_depthstencil_format(internalFormat)) {
- /* make sure we have depth/stencil buffers */
- if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyTexImage%dD(no depth/stencil buffer)", dimensions);
- return GL_TRUE;
- }
- }
-
- /* if we get here, the parameters are OK */
- return GL_FALSE;
-}
-
-
-/**
- * Test glCopyTexSubImage[12]D() parameters for errors.
- * Note that this is the first part of error checking.
- * See also copytexsubimage_error_check2() below for the second part.
- *
- * \param ctx GL context.
- * \param dimensions texture image dimensions (must be 1, 2 or 3).
- * \param target texture target given by the user.
- * \param level image level given by the user.
- *
- * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
- */
-static GLboolean
-copytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions,
- GLenum target, GLint level)
-{
- /* Check that the source buffer is complete */
- if (ctx->ReadBuffer->Name) {
- if (ctx->ReadBuffer->_Status == 0) {
- _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
- }
- if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
- "glCopyTexImage%dD(invalid readbuffer)", dimensions);
- return GL_TRUE;
- }
- }
-
- /* check target (proxies not allowed) */
- if (!legal_texsubimage_target(ctx, dimensions, target)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexSubImage%uD(target=%s)",
- dimensions, _mesa_lookup_enum_by_nr(target));
- return GL_TRUE;
- }
-
- /* Check level */
- if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(level=%d)", dimensions, level);
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-
-/**
- * Second part of error checking for glCopyTexSubImage[12]D().
- * \param xoffset sub-image x offset given by the user.
- * \param yoffset sub-image y offset given by the user.
- * \param zoffset sub-image z offset given by the user.
- * \param width image width given by the user.
- * \param height image height given by the user.
- */
-static GLboolean
-copytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions,
- GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height,
- const struct gl_texture_image *teximage )
-{
- /* check that dest tex image exists */
- if (!teximage) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyTexSubImage%dD(undefined texture level: %d)",
- dimensions, level);
- return GL_TRUE;
- }
-
- /* Check size */
- if (width < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(width=%d)", dimensions, width);
- return GL_TRUE;
- }
- if (dimensions > 1 && height < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(height=%d)", dimensions, height);
- return GL_TRUE;
- }
-
- /* check x/y offsets */
- if (xoffset < -((GLint)teximage->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset);
- return GL_TRUE;
- }
- if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(xoffset+width)", dimensions);
- return GL_TRUE;
- }
- if (dimensions > 1) {
- if (yoffset < -((GLint)teximage->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset);
- return GL_TRUE;
- }
- /* NOTE: we're adding the border here, not subtracting! */
- if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(yoffset+height)", dimensions);
- return GL_TRUE;
- }
- }
-
- /* check z offset */
- if (dimensions > 2) {
- if (zoffset < -((GLint)teximage->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(zoffset)", dimensions);
- return GL_TRUE;
- }
- if (zoffset > (GLint) (teximage->Depth + teximage->Border)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(zoffset+depth)", dimensions);
- return GL_TRUE;
- }
- }
-
- if (_mesa_is_format_compressed(teximage->TexFormat)) {
- /* offset must be multiple of 4 */
- if ((xoffset & 3) || (yoffset & 3)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions);
- return GL_TRUE;
- }
- /* size must be multiple of 4 */
- if ((width & 3) != 0 && (GLuint) width != teximage->Width) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(width)", dimensions);
- return GL_TRUE;
- }
- if ((height & 3) != 0 && (GLuint) height != teximage->Height) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(height)", dimensions);
- return GL_TRUE;
- }
- }
-
- if (teximage->InternalFormat == GL_YCBCR_MESA) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D");
- return GL_TRUE;
- }
-
- if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
- dimensions, teximage->_BaseFormat);
- return GL_TRUE;
- }
-
- if (teximage->_BaseFormat == GL_DEPTH_COMPONENT) {
- if (!ctx->ReadBuffer->_DepthBuffer) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyTexSubImage%dD(no depth buffer)",
- dimensions);
- return GL_TRUE;
- }
- }
- else if (teximage->_BaseFormat == GL_DEPTH_STENCIL_EXT) {
- if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyTexSubImage%dD(no depth/stencil buffer)",
- dimensions);
- return GL_TRUE;
- }
- }
-
- /* If copying into an integer texture, the source buffer must also be
- * integer-valued.
- */
- if (_mesa_is_format_integer_color(teximage->TexFormat)) {
- struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
- if (!_mesa_is_format_integer_color(rb->Format)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyTexSubImage%dD(source buffer is not integer format)",
- dimensions);
- return GL_TRUE;
- }
- }
-
- /* if we get here, the parameters are OK */
- return GL_FALSE;
-}
-
-
-/** Callback info for walking over FBO hash table */
-struct cb_info
-{
- struct gl_context *ctx;
- struct gl_texture_object *texObj;
- GLuint level, face;
-};
-
-
-/**
- * Check render to texture callback. Called from _mesa_HashWalk().
- */
-static void
-check_rtt_cb(GLuint key, void *data, void *userData)
-{
- struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
- const struct cb_info *info = (struct cb_info *) userData;
- struct gl_context *ctx = info->ctx;
- const struct gl_texture_object *texObj = info->texObj;
- const GLuint level = info->level, face = info->face;
-
- /* If this is a user-created FBO */
- if (fb->Name) {
- GLuint i;
- /* check if any of the FBO's attachments point to 'texObj' */
- for (i = 0; i < BUFFER_COUNT; i++) {
- struct gl_renderbuffer_attachment *att = fb->Attachment + i;
- if (att->Type == GL_TEXTURE &&
- att->Texture == texObj &&
- att->TextureLevel == level &&
- att->CubeMapFace == face) {
- ASSERT(att->Texture->Image[att->CubeMapFace][att->TextureLevel]);
- /* Tell driver about the new renderbuffer texture */
- ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att);
- /* Mark fb status as indeterminate to force re-validation */
- fb->_Status = 0;
- }
- }
- }
-}
-
-
-/**
- * When a texture image is specified we have to check if it's bound to
- * any framebuffer objects (render to texture) in order to detect changes
- * in size or format since that effects FBO completeness.
- * Any FBOs rendering into the texture must be re-validated.
- */
-static void
-update_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj,
- GLuint face, GLuint level)
-{
- /* Only check this texture if it's been marked as RenderToTexture */
- if (texObj->_RenderToTexture) {
- struct cb_info info;
- info.ctx = ctx;
- info.texObj = texObj;
- info.level = level;
- info.face = face;
- _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info);
- }
-}
-
-
-/**
- * If the texture object's GenerateMipmap flag is set and we've
- * changed the texture base level image, regenerate the rest of the
- * mipmap levels now.
- */
-static INLINE void
-check_gen_mipmap(struct gl_context *ctx, GLenum target,
- struct gl_texture_object *texObj, GLint level)
-{
- ASSERT(target != GL_TEXTURE_CUBE_MAP);
- if (texObj->GenerateMipmap &&
- level == texObj->BaseLevel &&
- level < texObj->MaxLevel) {
- ASSERT(ctx->Driver.GenerateMipmap);
- ctx->Driver.GenerateMipmap(ctx, target, texObj);
- }
-}
-
-
-/** Debug helper: override the user-requested internal format */
-static GLenum
-override_internal_format(GLenum internalFormat, GLint width, GLint height)
-{
-#if 0
- if (internalFormat == GL_RGBA16F_ARB ||
- internalFormat == GL_RGBA32F_ARB) {
- printf("Convert rgba float tex to int %d x %d\n", width, height);
- return GL_RGBA;
- }
- else if (internalFormat == GL_RGB16F_ARB ||
- internalFormat == GL_RGB32F_ARB) {
- printf("Convert rgb float tex to int %d x %d\n", width, height);
- return GL_RGB;
- }
- else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB ||
- internalFormat == GL_LUMINANCE_ALPHA32F_ARB) {
- printf("Convert luminance float tex to int %d x %d\n", width, height);
- return GL_LUMINANCE_ALPHA;
- }
- else if (internalFormat == GL_LUMINANCE16F_ARB ||
- internalFormat == GL_LUMINANCE32F_ARB) {
- printf("Convert luminance float tex to int %d x %d\n", width, height);
- return GL_LUMINANCE;
- }
- else if (internalFormat == GL_ALPHA16F_ARB ||
- internalFormat == GL_ALPHA32F_ARB) {
- printf("Convert luminance float tex to int %d x %d\n", width, height);
- return GL_ALPHA;
- }
- /*
- else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
- internalFormat = GL_RGBA;
- }
- */
- else {
- return internalFormat;
- }
-#else
- return internalFormat;
-#endif
-}
-
-
-/**
- * Choose the actual hardware format for a texture image.
- * Try to use the same format as the previous image level when possible.
- * Otherwise, ask the driver for the best format.
- * It's important to try to choose a consistant format for all levels
- * for efficient texture memory layout/allocation. In particular, this
- * comes up during automatic mipmap generation.
- */
-gl_format
-_mesa_choose_texture_format(struct gl_context *ctx,
- struct gl_texture_object *texObj,
- GLenum target, GLint level,
- GLenum internalFormat, GLenum format, GLenum type)
-{
- gl_format f;
-
- /* see if we've already chosen a format for the previous level */
- if (level > 0) {
- struct gl_texture_image *prevImage =
- _mesa_select_tex_image(ctx, texObj, target, level - 1);
- /* See if the prev level is defined and has an internal format which
- * matches the new internal format.
- */
- if (prevImage &&
- prevImage->Width > 0 &&
- prevImage->InternalFormat == internalFormat) {
- /* use the same format */
- ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE);
- return prevImage->TexFormat;
- }
- }
-
- /* choose format from scratch */
- f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
- ASSERT(f != MESA_FORMAT_NONE);
- return f;
-}
-
-
-/**
- * Common code to implement all the glTexImage1D/2D/3D functions.
- */
-static void
-teximage(struct gl_context *ctx, GLuint dims,
- GLenum target, GLint level, GLint internalFormat,
- GLsizei width, GLsizei height, GLsizei depth,
- GLint border, GLenum format, GLenum type,
- const GLvoid *pixels)
-{
- GLboolean error;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
- _mesa_debug(ctx, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
- dims,
- _mesa_lookup_enum_by_nr(target), level,
- _mesa_lookup_enum_by_nr(internalFormat),
- width, height, depth, border,
- _mesa_lookup_enum_by_nr(format),
- _mesa_lookup_enum_by_nr(type), pixels);
-
- internalFormat = override_internal_format(internalFormat, width, height);
-
- /* target error checking */
- if (!legal_teximage_target(ctx, dims, target)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%uD(target=%s)",
- dims, _mesa_lookup_enum_by_nr(target));
- return;
- }
-
- /* general error checking */
- error = texture_error_check(ctx, dims, target, level, internalFormat,
- format, type, width, height, depth, border);
-
- if (_mesa_is_proxy_texture(target)) {
- /* Proxy texture: just clear or set state depending on error checking */
- struct gl_texture_image *texImage =
- _mesa_get_proxy_tex_image(ctx, target, level);
-
- if (error) {
- /* when error, clear all proxy texture image parameters */
- if (texImage)
- clear_teximage_fields(texImage);
- }
- else {
- /* no error, set the tex image parameters */
- struct gl_texture_object *texObj =
- _mesa_get_current_tex_object(ctx, target);
- gl_format texFormat = _mesa_choose_texture_format(ctx, texObj,
- target, level,
- internalFormat,
- format, type);
-
- if (legal_texture_size(ctx, texFormat, width, height, depth)) {
- _mesa_init_teximage_fields(ctx, target, texImage, width, height,
- depth, border, internalFormat,
- texFormat);
- }
- else if (texImage) {
- clear_teximage_fields(texImage);
- }
- }
- }
- else {
- /* non-proxy target */
- const GLuint face = _mesa_tex_target_to_face(target);
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
-
- if (error) {
- return; /* error was recorded */
- }
-
- if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
- _mesa_update_state(ctx);
-
- texObj = _mesa_get_current_tex_object(ctx, target);
-
- _mesa_lock_texture(ctx, texObj);
- {
- texImage = _mesa_get_tex_image(ctx, texObj, target, level);
-
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims);
- }
- else {
- gl_format texFormat;
-
- if (texImage->Data) {
- ctx->Driver.FreeTexImageData( ctx, texImage );
- }
-
- ASSERT(texImage->Data == NULL);
- texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
- internalFormat, format,
- type);
-
- if (legal_texture_size(ctx, texFormat, width, height, depth)) {
- _mesa_init_teximage_fields(ctx, target, texImage,
- width, height, depth,
- border, internalFormat, texFormat);
-
- /* Give the texture to the driver. <pixels> may be null. */
- ASSERT(ctx->Driver.TexImage3D);
- switch (dims) {
- case 1:
- ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
- width, border, format,
- type, pixels, &ctx->Unpack, texObj,
- texImage);
- break;
- case 2:
- ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
- width, height, border, format,
- type, pixels, &ctx->Unpack, texObj,
- texImage);
- break;
- case 3:
- ctx->Driver.TexImage3D(ctx, target, level, internalFormat,
- width, height, depth, border, format,
- type, pixels, &ctx->Unpack, texObj,
- texImage);
- break;
- default:
- _mesa_problem(ctx, "invalid dims=%u in teximage()", dims);
- }
-
- check_gen_mipmap(ctx, target, texObj, level);
-
- update_fbo_texture(ctx, texObj, face, level);
-
- /* state update */
- texObj->_Complete = GL_FALSE;
- ctx->NewState |= _NEW_TEXTURE;
- }
- else {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims);
- }
- }
- }
- _mesa_unlock_texture(ctx, texObj);
- }
-}
-
-
-/*
- * Called from the API. Note that width includes the border.
- */
-void GLAPIENTRY
-_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
- GLsizei width, GLint border, GLenum format,
- GLenum type, const GLvoid *pixels )
-{
- GET_CURRENT_CONTEXT(ctx);
- teximage(ctx, 1, target, level, internalFormat, width, 1, 1,
- border, format, type, pixels);
-}
-
-
-void GLAPIENTRY
-_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
- GLsizei width, GLsizei height, GLint border,
- GLenum format, GLenum type,
- const GLvoid *pixels )
-{
- GET_CURRENT_CONTEXT(ctx);
- teximage(ctx, 2, target, level, internalFormat, width, height, 1,
- border, format, type, pixels);
-}
-
-
-/*
- * Called by the API or display list executor.
- * Note that width and height include the border.
- */
-void GLAPIENTRY
-_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
- GLsizei width, GLsizei height, GLsizei depth,
- GLint border, GLenum format, GLenum type,
- const GLvoid *pixels )
-{
- GET_CURRENT_CONTEXT(ctx);
- teximage(ctx, 3, target, level, internalFormat, width, height, depth,
- border, format, type, pixels);
-}
-
-
-void GLAPIENTRY
-_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat,
- GLsizei width, GLsizei height, GLsizei depth,
- GLint border, GLenum format, GLenum type,
- const GLvoid *pixels )
-{
- _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height,
- depth, border, format, type, pixels);
-}
-
-
-#if FEATURE_OES_EGL_image
-void GLAPIENTRY
-_mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image)
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (!ctx->Extensions.OES_EGL_image) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glEGLImageTargetTexture2DOES(unsupported)");
- return;
- }
-
- if (target != GL_TEXTURE_2D) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glEGLImageTargetTexture2D(target=%d)", target);
- return;
- }
-
- if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
- _mesa_update_state(ctx);
-
- texObj = _mesa_get_current_tex_object(ctx, target);
- _mesa_lock_texture(ctx, texObj);
-
- texImage = _mesa_get_tex_image(ctx, texObj, target, 0);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEGLImageTargetTexture2D");
- } else {
- if (texImage->Data)
- ctx->Driver.FreeTexImageData( ctx, texImage );
-
- ASSERT(texImage->Data == NULL);
- ctx->Driver.EGLImageTargetTexture2D(ctx, target,
- texObj, texImage, image);
-
- /* state update */
- texObj->_Complete = GL_FALSE;
- ctx->NewState |= _NEW_TEXTURE;
- }
- _mesa_unlock_texture(ctx, texObj);
-
-}
-#endif
-
-
-
-/**
- * Implement all the glTexSubImage1/2/3D() functions.
- */
-static void
-texsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLenum type, const GLvoid *pixels )
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
- _mesa_debug(ctx, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
- dims,
- _mesa_lookup_enum_by_nr(target), level,
- xoffset, yoffset, zoffset, width, height, depth,
- _mesa_lookup_enum_by_nr(format),
- _mesa_lookup_enum_by_nr(type), pixels);
-
- /* check target (proxies not allowed) */
- if (!legal_texsubimage_target(ctx, dims, target)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage%uD(target=%s)",
- dims, _mesa_lookup_enum_by_nr(target));
- return;
- }
-
- if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
- _mesa_update_state(ctx);
-
- if (subtexture_error_check(ctx, dims, target, level, xoffset, yoffset, zoffset,
- width, height, depth, format, type)) {
- return; /* error was detected */
- }
-
- texObj = _mesa_get_current_tex_object(ctx, target);
-
- _mesa_lock_texture(ctx, texObj);
- {
- texImage = _mesa_select_tex_image(ctx, texObj, target, level);
-
- if (subtexture_error_check2(ctx, dims, target, level,
- xoffset, yoffset, zoffset,
- width, height, depth,
- format, type, texImage)) {
- /* error was recorded */
- }
- else if (width > 0 && height > 0 && height > 0) {
- /* If we have a border, offset=-1 is legal. Bias by border width. */
- switch (dims) {
- case 3:
- zoffset += texImage->Border;
- /* fall-through */
- case 2:
- yoffset += texImage->Border;
- /* fall-through */
- case 1:
- xoffset += texImage->Border;
- }
-
- switch (dims) {
- case 1:
- ctx->Driver.TexSubImage1D(ctx, target, level,
- xoffset, width,
- format, type, pixels,
- &ctx->Unpack, texObj, texImage );
- break;
- case 2:
- ctx->Driver.TexSubImage2D(ctx, target, level,
- xoffset, yoffset, width, height,
- format, type, pixels,
- &ctx->Unpack, texObj, texImage );
- break;
- case 3:
- ctx->Driver.TexSubImage3D(ctx, target, level,
- xoffset, yoffset, zoffset,
- width, height, depth,
- format, type, pixels,
- &ctx->Unpack, texObj, texImage );
- break;
- default:
- _mesa_problem(ctx, "unexpected dims in subteximage()");
- }
-
- check_gen_mipmap(ctx, target, texObj, level);
-
- ctx->NewState |= _NEW_TEXTURE;
- }
- }
- _mesa_unlock_texture(ctx, texObj);
-}
-
-
-void GLAPIENTRY
-_mesa_TexSubImage1D( GLenum target, GLint level,
- GLint xoffset, GLsizei width,
- GLenum format, GLenum type,
- const GLvoid *pixels )
-{
- GET_CURRENT_CONTEXT(ctx);
- texsubimage(ctx, 1, target, level,
- xoffset, 0, 0,
- width, 1, 1,
- format, type, pixels);
-}
-
-
-void GLAPIENTRY
-_mesa_TexSubImage2D( GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const GLvoid *pixels )
-{
- GET_CURRENT_CONTEXT(ctx);
- texsubimage(ctx, 2, target, level,
- xoffset, yoffset, 0,
- width, height, 1,
- format, type, pixels);
-}
-
-
-
-void GLAPIENTRY
-_mesa_TexSubImage3D( GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLenum type,
- const GLvoid *pixels )
-{
- GET_CURRENT_CONTEXT(ctx);
- texsubimage(ctx, 3, target, level,
- xoffset, yoffset, zoffset,
- width, height, depth,
- format, type, pixels);
-}
-
-
-
-/**
- * Implement the glCopyTexImage1/2D() functions.
- */
-static void
-copyteximage(struct gl_context *ctx, GLuint dims,
- GLenum target, GLint level, GLenum internalFormat,
- GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- const GLuint face = _mesa_tex_target_to_face(target);
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
- _mesa_debug(ctx, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
- dims,
- _mesa_lookup_enum_by_nr(target), level,
- _mesa_lookup_enum_by_nr(internalFormat),
- x, y, width, height, border);
-
- if (ctx->NewState & NEW_COPY_TEX_STATE)
- _mesa_update_state(ctx);
-
- if (copytexture_error_check(ctx, dims, target, level, internalFormat,
- width, height, border))
- return;
-
- texObj = _mesa_get_current_tex_object(ctx, target);
-
- _mesa_lock_texture(ctx, texObj);
- {
- texImage = _mesa_get_tex_image(ctx, texObj, target, level);
-
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims);
- }
- else {
- gl_format texFormat;
-
- if (texImage->Data) {
- ctx->Driver.FreeTexImageData( ctx, texImage );
- }
-
- ASSERT(texImage->Data == NULL);
-
- texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
- internalFormat, GL_NONE,
- GL_NONE);
-
- if (legal_texture_size(ctx, texFormat, width, height, 1)) {
- _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
- border, internalFormat, texFormat);
-
- ASSERT(ctx->Driver.CopyTexImage2D);
- if (dims == 1)
- ctx->Driver.CopyTexImage1D(ctx, target, level, internalFormat,
- x, y, width, border);
- else
- ctx->Driver.CopyTexImage2D(ctx, target, level, internalFormat,
- x, y, width, height, border);
-
- check_gen_mipmap(ctx, target, texObj, level);
-
- update_fbo_texture(ctx, texObj, face, level);
-
- /* state update */
- texObj->_Complete = GL_FALSE;
- ctx->NewState |= _NEW_TEXTURE;
- }
- else {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims);
- }
- }
- }
- _mesa_unlock_texture(ctx, texObj);
-}
-
-
-
-void GLAPIENTRY
-_mesa_CopyTexImage1D( GLenum target, GLint level,
- GLenum internalFormat,
- GLint x, GLint y,
- GLsizei width, GLint border )
-{
- GET_CURRENT_CONTEXT(ctx);
- copyteximage(ctx, 1, target, level, internalFormat, x, y, width, 1, border);
-}
-
-
-
-void GLAPIENTRY
-_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLint border )
-{
- GET_CURRENT_CONTEXT(ctx);
- copyteximage(ctx, 2, target, level, internalFormat,
- x, y, width, height, border);
-}
-
-
-
-/**
- * Implementation for glCopyTexSubImage1/2/3D() functions.
- */
-static void
-copytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint x, GLint y, GLsizei width, GLsizei height)
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
- _mesa_debug(ctx, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
- dims,
- _mesa_lookup_enum_by_nr(target),
- level, xoffset, yoffset, zoffset, x, y, width, height);
-
- if (ctx->NewState & NEW_COPY_TEX_STATE)
- _mesa_update_state(ctx);
-
- if (copytexsubimage_error_check1(ctx, dims, target, level))
- return;
-
- texObj = _mesa_get_current_tex_object(ctx, target);
-
- _mesa_lock_texture(ctx, texObj);
- {
- texImage = _mesa_select_tex_image(ctx, texObj, target, level);
-
- if (copytexsubimage_error_check2(ctx, dims, target, level, xoffset, yoffset,
- zoffset, width, height, texImage)) {
- /* error was recored */
- }
- else {
- /* If we have a border, offset=-1 is legal. Bias by border width. */
- switch (dims) {
- case 3:
- zoffset += texImage->Border;
- /* fall-through */
- case 2:
- yoffset += texImage->Border;
- /* fall-through */
- case 1:
- xoffset += texImage->Border;
- }
-
- if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y,
- &width, &height)) {
- switch (dims) {
- case 1:
- ctx->Driver.CopyTexSubImage1D(ctx, target, level,
- xoffset, x, y, width);
- break;
- case 2:
- ctx->Driver.CopyTexSubImage2D(ctx, target, level,
- xoffset, yoffset,
- x, y, width, height);
- break;
- case 3:
- ctx->Driver.CopyTexSubImage3D(ctx, target, level,
- xoffset, yoffset, zoffset,
- x, y, width, height);
- break;
- default:
- _mesa_problem(ctx, "bad dims in copytexsubimage()");
- }
-
- check_gen_mipmap(ctx, target, texObj, level);
-
- ctx->NewState |= _NEW_TEXTURE;
- }
- }
- }
- _mesa_unlock_texture(ctx, texObj);
-}
-
-
-void GLAPIENTRY
-_mesa_CopyTexSubImage1D( GLenum target, GLint level,
- GLint xoffset, GLint x, GLint y, GLsizei width )
-{
- GET_CURRENT_CONTEXT(ctx);
- copytexsubimage(ctx, 1, target, level, xoffset, 0, 0, x, y, width, 1);
-}
-
-
-
-void GLAPIENTRY
-_mesa_CopyTexSubImage2D( GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLint x, GLint y, GLsizei width, GLsizei height )
-{
- GET_CURRENT_CONTEXT(ctx);
- copytexsubimage(ctx, 2, target, level, xoffset, yoffset, 0, x, y,
- width, height);
-}
-
-
-
-void GLAPIENTRY
-_mesa_CopyTexSubImage3D( GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint x, GLint y, GLsizei width, GLsizei height )
-{
- GET_CURRENT_CONTEXT(ctx);
- copytexsubimage(ctx, 3, target, level, xoffset, yoffset, zoffset,
- x, y, width, height);
-}
-
-
-
-
-/**********************************************************************/
-/****** Compressed Textures ******/
-/**********************************************************************/
-
-
-/**
- * Return expected size of a compressed texture.
- */
-static GLuint
-compressed_tex_size(GLsizei width, GLsizei height, GLsizei depth,
- GLenum glformat)
-{
- gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
- return _mesa_format_image_size(mesaFormat, width, height, depth);
-}
-
-
-/*
- * Return compressed texture block size, in pixels.
- */
-static void
-get_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh)
-{
- gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
- _mesa_get_format_block_size(mesaFormat, bw, bh);
-}
-
-
-/**
- * Error checking for glCompressedTexImage[123]D().
- * \return error code or GL_NO_ERROR.
- */
-static GLenum
-compressed_texture_error_check(struct gl_context *ctx, GLint dimensions,
- GLenum target, GLint level,
- GLenum internalFormat, GLsizei width,
- GLsizei height, GLsizei depth, GLint border,
- GLsizei imageSize)
-{
- const GLenum proxyTarget = get_proxy_target(target);
- const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
- GLint expectedSize;
-
- /* check level */
- if (level < 0 || level >= maxLevels)
- return GL_INVALID_VALUE;
-
- if (!target_can_be_compressed(ctx, target, internalFormat)) {
- return GL_INVALID_ENUM;
- }
-
- /* This will detect any invalid internalFormat value */
- if (!_mesa_is_compressed_format(ctx, internalFormat))
- return GL_INVALID_ENUM;
-
- /* This should really never fail */
- if (_mesa_base_tex_format(ctx, internalFormat) < 0)
- return GL_INVALID_ENUM;
-
- /* No compressed formats support borders at this time */
- if (border != 0)
- return GL_INVALID_VALUE;
-
- /* For cube map, width must equal height */
- if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
- target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height)
- return GL_INVALID_VALUE;
-
- /* check image size against compression block size */
- {
- gl_format texFormat =
- ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
- GL_NONE, GL_NONE);
- GLuint bw, bh;
-
- _mesa_get_format_block_size(texFormat, &bw, &bh);
- if ((width > bw && width % bw > 0) ||
- (height > bh && height % bh > 0)) {
- /*
- * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
- * generated [...] if any parameter combinations are not
- * supported by the specific compressed internal format.
- */
- return GL_INVALID_OPERATION;
- }
- }
-
- /* check image sizes */
- if (!ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level,
- internalFormat, GL_NONE, GL_NONE,
- width, height, depth, border)) {
- /* See error comment above */
- return GL_INVALID_OPERATION;
- }
-
- /* check image size in bytes */
- expectedSize = compressed_tex_size(width, height, depth, internalFormat);
- if (expectedSize != imageSize) {
- /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
- * if <imageSize> is not consistent with the format, dimensions, and
- * contents of the specified image.
- */
- return GL_INVALID_VALUE;
- }
-
- return GL_NO_ERROR;
-}
-
-
-/**
- * Error checking for glCompressedTexSubImage[123]D().
- * \warning There are some bad assumptions here about the size of compressed
- * texture tiles (multiple of 4) used to test the validity of the
- * offset and size parameters.
- * \return error code or GL_NO_ERROR.
- */
-static GLenum
-compressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions,
- GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLsizei imageSize)
-{
- GLint expectedSize, maxLevels = 0, maxTextureSize;
- GLuint bw, bh;
- (void) zoffset;
-
- if (dimensions == 1) {
- /* 1D compressed textures not allowed */
- return GL_INVALID_ENUM;
- }
- else if (dimensions == 2) {
- if (target == GL_PROXY_TEXTURE_2D) {
- maxLevels = ctx->Const.MaxTextureLevels;
- }
- else if (target == GL_TEXTURE_2D) {
- maxLevels = ctx->Const.MaxTextureLevels;
- }
- else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
- if (!ctx->Extensions.ARB_texture_cube_map)
- return GL_INVALID_ENUM; /*target*/
- maxLevels = ctx->Const.MaxCubeTextureLevels;
- }
- else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
- target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
- if (!ctx->Extensions.ARB_texture_cube_map)
- return GL_INVALID_ENUM; /*target*/
- maxLevels = ctx->Const.MaxCubeTextureLevels;
- }
- else {
- return GL_INVALID_ENUM; /*target*/
- }
- }
- else if (dimensions == 3) {
- /* 3D compressed textures not allowed */
- return GL_INVALID_ENUM;
- }
-
- maxTextureSize = 1 << (maxLevels - 1);
-
- /* this will catch any invalid compressed format token */
- if (!_mesa_is_compressed_format(ctx, format))
- return GL_INVALID_ENUM;
-
- if (width < 1 || width > maxTextureSize)
- return GL_INVALID_VALUE;
-
- if ((height < 1 || height > maxTextureSize)
- && dimensions > 1)
- return GL_INVALID_VALUE;
-
- if (level < 0 || level >= maxLevels)
- return GL_INVALID_VALUE;
-
- /*
- * do checks which depend on compression block size
- */
- get_compressed_block_size(format, &bw, &bh);
-
- if ((xoffset % bw != 0) || (yoffset % bh != 0))
- return GL_INVALID_VALUE;
-
- if ((width % bw != 0) && width != 2 && width != 1)
- return GL_INVALID_VALUE;
-
- if ((height % bh != 0) && height != 2 && height != 1)
- return GL_INVALID_VALUE;
-
- expectedSize = compressed_tex_size(width, height, depth, format);
- if (expectedSize != imageSize)
- return GL_INVALID_VALUE;
-
- return GL_NO_ERROR;
-}
-
-
-/**
- * Do second part of glCompressedTexSubImage error checking.
- * \return GL_TRUE if error found, GL_FALSE otherwise.
- */
-static GLboolean
-compressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims,
- GLsizei width, GLsizei height,
- GLsizei depth, GLenum format,
- struct gl_texture_image *texImage)
-{
-
- if ((GLint) format != texImage->InternalFormat) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCompressedTexSubImage%uD(format=0x%x)", dims, format);
- return GL_TRUE;
- }
-
- if (((width == 1 || width == 2) &&
- width != (GLsizei) texImage->Width) ||
- (width > (GLsizei) texImage->Width)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCompressedTexSubImage%uD(width=%d)", dims, width);
- return GL_TRUE;
- }
-
- if (dims >= 2) {
- if (((height == 1 || height == 2) &&
- height != (GLsizei) texImage->Height) ||
- (height > (GLsizei) texImage->Height)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCompressedTexSubImage%uD(height=%d)", dims, height);
- return GL_TRUE;
- }
- }
-
- if (dims >= 3) {
- if (((depth == 1 || depth == 2) &&
- depth != (GLsizei) texImage->Depth) ||
- (depth > (GLsizei) texImage->Depth)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCompressedTexSubImage%uD(depth=%d)", dims, depth);
- return GL_TRUE;
- }
- }
-
- return GL_FALSE;
-}
-
-
-/**
- * Implementation of the glCompressedTexImage1/2/3D() functions.
- */
-static void
-compressedteximage(struct gl_context *ctx, GLuint dims,
- GLenum target, GLint level,
- GLenum internalFormat, GLsizei width,
- GLsizei height, GLsizei depth, GLint border,
- GLsizei imageSize, const GLvoid *data)
-{
- GLenum error;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
- _mesa_debug(ctx,
- "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
- dims,
- _mesa_lookup_enum_by_nr(target), level,
- _mesa_lookup_enum_by_nr(internalFormat),
- width, height, depth, border, imageSize, data);
-
- /* check target */
- if (!legal_teximage_target(ctx, dims, target)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage%uD(target=%s)",
- dims, _mesa_lookup_enum_by_nr(target));
- return;
- }
-
- error = compressed_texture_error_check(ctx, dims, target, level,
- internalFormat, width, height, depth,
- border, imageSize);
-
-#if FEATURE_ES
- /* XXX this is kind of a hack */
- if (error) {
- _mesa_error(ctx, error, "glTexImage2D");
- return;
- }
-
- if (dims == 2) {
- switch (internalFormat) {
- case GL_PALETTE4_RGB8_OES:
- case GL_PALETTE4_RGBA8_OES:
- case GL_PALETTE4_R5_G6_B5_OES:
- case GL_PALETTE4_RGBA4_OES:
- case GL_PALETTE4_RGB5_A1_OES:
- case GL_PALETTE8_RGB8_OES:
- case GL_PALETTE8_RGBA8_OES:
- case GL_PALETTE8_R5_G6_B5_OES:
- case GL_PALETTE8_RGBA4_OES:
- case GL_PALETTE8_RGB5_A1_OES:
- _mesa_cpal_compressed_teximage2d(target, level, internalFormat,
- width, height, imageSize, data);
- return;
- }
- }
-#endif
-
- if (_mesa_is_proxy_texture(target)) {
- /* Proxy texture: just check for errors and update proxy state */
- struct gl_texture_image *texImage;
-
- if (!error) {
- struct gl_texture_object *texObj =
- _mesa_get_current_tex_object(ctx, target);
- gl_format texFormat =
- _mesa_choose_texture_format(ctx, texObj, target, level,
- internalFormat, GL_NONE, GL_NONE);
- if (!legal_texture_size(ctx, texFormat, width, height, depth)) {
- error = GL_OUT_OF_MEMORY;
- }
- }
-
- texImage = _mesa_get_proxy_tex_image(ctx, target, level);
- if (texImage) {
- if (error) {
- /* if error, clear all proxy texture image parameters */
- clear_teximage_fields(texImage);
- }
- else {
- /* no error: store the teximage parameters */
- _mesa_init_teximage_fields(ctx, target, texImage, width, height,
- depth, border, internalFormat,
- MESA_FORMAT_NONE);
- }
- }
- }
- else {
- /* non-proxy target */
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
-
- if (error) {
- _mesa_error(ctx, error, "glCompressedTexImage%uD", dims);
- return;
- }
-
- texObj = _mesa_get_current_tex_object(ctx, target);
-
- _mesa_lock_texture(ctx, texObj);
- {
- texImage = _mesa_get_tex_image(ctx, texObj, target, level);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY,
- "glCompressedTexImage%uD", dims);
- }
- else {
- gl_format texFormat;
-
- if (texImage->Data) {
- ctx->Driver.FreeTexImageData( ctx, texImage );
- }
- ASSERT(texImage->Data == NULL);
-
- texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
- internalFormat, GL_NONE,
- GL_NONE);
-
- if (legal_texture_size(ctx, texFormat, width, height, depth)) {
- _mesa_init_teximage_fields(ctx, target, texImage,
- width, height, depth,
- border, internalFormat, texFormat);
-
- switch (dims) {
- case 1:
- ASSERT(ctx->Driver.CompressedTexImage1D);
- ctx->Driver.CompressedTexImage1D(ctx, target, level,
- internalFormat,
- width,
- border, imageSize, data,
- texObj, texImage);
- break;
- case 2:
- ASSERT(ctx->Driver.CompressedTexImage2D);
- ctx->Driver.CompressedTexImage2D(ctx, target, level,
- internalFormat,
- width, height,
- border, imageSize, data,
- texObj, texImage);
- break;
- case 3:
- ASSERT(ctx->Driver.CompressedTexImage3D);
- ctx->Driver.CompressedTexImage3D(ctx, target, level,
- internalFormat,
- width, height, depth,
- border, imageSize, data,
- texObj, texImage);
- break;
- default:
- _mesa_problem(ctx, "bad dims in compressedteximage");
- }
-
- check_gen_mipmap(ctx, target, texObj, level);
-
- /* state update */
- texObj->_Complete = GL_FALSE;
- ctx->NewState |= _NEW_TEXTURE;
- }
- else {
- _mesa_error(ctx, GL_OUT_OF_MEMORY,
- "glCompressedTexImage%uD", dims);
- }
- }
- }
- _mesa_unlock_texture(ctx, texObj);
- }
-}
-
-
-void GLAPIENTRY
-_mesa_CompressedTexImage1DARB(GLenum target, GLint level,
- GLenum internalFormat, GLsizei width,
- GLint border, GLsizei imageSize,
- const GLvoid *data)
-{
- GET_CURRENT_CONTEXT(ctx);
- compressedteximage(ctx, 1, target, level, internalFormat,
- width, 1, 1, border, imageSize, data);
-}
-
-
-void GLAPIENTRY
-_mesa_CompressedTexImage2DARB(GLenum target, GLint level,
- GLenum internalFormat, GLsizei width,
- GLsizei height, GLint border, GLsizei imageSize,
- const GLvoid *data)
-{
- GET_CURRENT_CONTEXT(ctx);
- compressedteximage(ctx, 2, target, level, internalFormat,
- width, height, 1, border, imageSize, data);
-}
-
-
-void GLAPIENTRY
-_mesa_CompressedTexImage3DARB(GLenum target, GLint level,
- GLenum internalFormat, GLsizei width,
- GLsizei height, GLsizei depth, GLint border,
- GLsizei imageSize, const GLvoid *data)
-{
- GET_CURRENT_CONTEXT(ctx);
- compressedteximage(ctx, 3, target, level, internalFormat,
- width, height, depth, border, imageSize, data);
-}
-
-
-/**
- * Common helper for glCompressedTexSubImage1/2/3D().
- */
-static void
-compressed_tex_sub_image(GLuint dims, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLsizei imageSize, const GLvoid *data)
-{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- GLenum error;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- error = compressed_subtexture_error_check(ctx, dims, target, level,
- xoffset, 0, 0, /* pos */
- width, height, depth, /* size */
- format, imageSize);
- if (error) {
- _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims);
- return;
- }
-
- texObj = _mesa_get_current_tex_object(ctx, target);
-
- _mesa_lock_texture(ctx, texObj);
- {
- texImage = _mesa_select_tex_image(ctx, texObj, target, level);
- assert(texImage);
-
- if (compressed_subtexture_error_check2(ctx, dims, width, height, depth,
- format, texImage)) {
- /* error was recorded */
- }
- else if (width > 0 && height > 0 && depth > 0) {
- switch (dims) {
- case 1:
- if (ctx->Driver.CompressedTexSubImage1D) {
- ctx->Driver.CompressedTexSubImage1D(ctx, target, level,
- xoffset, width,
- format, imageSize, data,
- texObj, texImage);
- }
- break;
- case 2:
- if (ctx->Driver.CompressedTexSubImage2D) {
- ctx->Driver.CompressedTexSubImage2D(ctx, target, level,
- xoffset, yoffset,
- width, height,
- format, imageSize, data,
- texObj, texImage);
- }
- break;
- case 3:
- if (ctx->Driver.CompressedTexSubImage3D) {
- ctx->Driver.CompressedTexSubImage3D(ctx, target, level,
- xoffset, yoffset, zoffset,
- width, height, depth,
- format, imageSize, data,
- texObj, texImage);
- }
- break;
- default:
- ;
- }
-
- check_gen_mipmap(ctx, target, texObj, level);
-
- ctx->NewState |= _NEW_TEXTURE;
- }
- }
- _mesa_unlock_texture(ctx, texObj);
-}
-
-
-void GLAPIENTRY
-_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
- GLsizei width, GLenum format,
- GLsizei imageSize, const GLvoid *data)
-{
- compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1,
- format, imageSize, data);
-}
-
-
-void GLAPIENTRY
-_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
- GLint yoffset, GLsizei width, GLsizei height,
- GLenum format, GLsizei imageSize,
- const GLvoid *data)
-{
- compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0,
- width, height, 1, format, imageSize, data);
-}
-
-
-void GLAPIENTRY
-_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
- GLint yoffset, GLint zoffset, GLsizei width,
- GLsizei height, GLsizei depth, GLenum format,
- GLsizei imageSize, const GLvoid *data)
-{
- compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset,
- width, height, depth, format, imageSize, data);
-}
+/*
+ * mesa 3-D graphics library
+ * Version: 7.6
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file teximage.c
+ * Texture image-related functions.
+ */
+
+
+#include "glheader.h"
+#include "bufferobj.h"
+#include "context.h"
+#include "enums.h"
+#include "fbobject.h"
+#include "framebuffer.h"
+#include "hash.h"
+#include "image.h"
+#include "imports.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "state.h"
+#include "texcompress.h"
+#include "texfetch.h"
+#include "teximage.h"
+#include "texstate.h"
+#include "texpal.h"
+#include "mtypes.h"
+
+
+/**
+ * State changes which we care about for glCopyTex[Sub]Image() calls.
+ * In particular, we care about pixel transfer state and buffer state
+ * (such as glReadBuffer to make sure we read from the right renderbuffer).
+ */
+#define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
+ _NEW_BUFFERS | \
+ _NEW_PIXEL)
+
+
+
+/**
+ * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
+ * elsewhere.
+ */
+void *
+_mesa_alloc_texmemory(GLsizei bytes)
+{
+ return _mesa_align_malloc(bytes, 512);
+}
+
+
+/**
+ * Free texture memory allocated with _mesa_alloc_texmemory()
+ */
+void
+_mesa_free_texmemory(void *m)
+{
+ _mesa_align_free(m);
+}
+
+
+/*
+ * Compute floor(log_base_2(n)).
+ * If n < 0 return -1.
+ */
+static int
+logbase2( int n )
+{
+ GLint i = 1;
+ GLint log2 = 0;
+
+ if (n < 0)
+ return -1;
+
+ if (n == 0)
+ return 0;
+
+ while ( n > i ) {
+ i *= 2;
+ log2++;
+ }
+ if (i != n) {
+ return log2 - 1;
+ }
+ else {
+ return log2;
+ }
+}
+
+
+
+/**
+ * Return the simple base format for a given internal texture format.
+ * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
+ *
+ * \param ctx GL context.
+ * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
+ *
+ * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
+ * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
+ *
+ * This is the format which is used during texture application (i.e. the
+ * texture format and env mode determine the arithmetic used.
+ *
+ * XXX this could be static
+ */
+GLint
+_mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat )
+{
+ switch (internalFormat) {
+ case GL_ALPHA:
+ case GL_ALPHA4:
+ case GL_ALPHA8:
+ case GL_ALPHA12:
+ case GL_ALPHA16:
+ return GL_ALPHA;
+ case 1:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE4:
+ case GL_LUMINANCE8:
+ case GL_LUMINANCE12:
+ case GL_LUMINANCE16:
+ return GL_LUMINANCE;
+ case 2:
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE4_ALPHA4:
+ case GL_LUMINANCE6_ALPHA2:
+ case GL_LUMINANCE8_ALPHA8:
+ case GL_LUMINANCE12_ALPHA4:
+ case GL_LUMINANCE12_ALPHA12:
+ case GL_LUMINANCE16_ALPHA16:
+ return GL_LUMINANCE_ALPHA;
+ case GL_INTENSITY:
+ case GL_INTENSITY4:
+ case GL_INTENSITY8:
+ case GL_INTENSITY12:
+ case GL_INTENSITY16:
+ return GL_INTENSITY;
+ case 3:
+ case GL_RGB:
+ case GL_R3_G3_B2:
+ case GL_RGB4:
+ case GL_RGB5:
+ case GL_RGB8:
+ case GL_RGB10:
+ case GL_RGB12:
+ case GL_RGB16:
+ return GL_RGB;
+ case 4:
+ case GL_RGBA:
+ case GL_RGBA2:
+ case GL_RGBA4:
+ case GL_RGB5_A1:
+ case GL_RGBA8:
+ case GL_RGB10_A2:
+ case GL_RGBA12:
+ case GL_RGBA16:
+ return GL_RGBA;
+ default:
+ ; /* fallthrough */
+ }
+
+ if (ctx->Extensions.EXT_texture_format_BGRA8888) {
+ switch (internalFormat) {
+ case GL_BGRA_EXT:
+ return GL_RGBA;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.EXT_paletted_texture) {
+ switch (internalFormat) {
+ case GL_COLOR_INDEX:
+ case GL_COLOR_INDEX1_EXT:
+ case GL_COLOR_INDEX2_EXT:
+ case GL_COLOR_INDEX4_EXT:
+ case GL_COLOR_INDEX8_EXT:
+ case GL_COLOR_INDEX12_EXT:
+ case GL_COLOR_INDEX16_EXT:
+ return GL_COLOR_INDEX;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.ARB_depth_texture) {
+ switch (internalFormat) {
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_COMPONENT16:
+ case GL_DEPTH_COMPONENT24:
+ case GL_DEPTH_COMPONENT32:
+ return GL_DEPTH_COMPONENT;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ switch (internalFormat) {
+ case GL_COMPRESSED_ALPHA:
+ return GL_ALPHA;
+ case GL_COMPRESSED_LUMINANCE:
+ return GL_LUMINANCE;
+ case GL_COMPRESSED_LUMINANCE_ALPHA:
+ return GL_LUMINANCE_ALPHA;
+ case GL_COMPRESSED_INTENSITY:
+ return GL_INTENSITY;
+ case GL_COMPRESSED_RGB:
+ return GL_RGB;
+ case GL_COMPRESSED_RGBA:
+ return GL_RGBA;
+ default:
+ ; /* fallthrough */
+ }
+
+ if (ctx->Extensions.TDFX_texture_compression_FXT1) {
+ switch (internalFormat) {
+ case GL_COMPRESSED_RGB_FXT1_3DFX:
+ return GL_RGB;
+ case GL_COMPRESSED_RGBA_FXT1_3DFX:
+ return GL_RGBA;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.EXT_texture_compression_s3tc) {
+ switch (internalFormat) {
+ case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+ return GL_RGB;
+ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+ return GL_RGBA;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.S3_s3tc) {
+ switch (internalFormat) {
+ case GL_RGB_S3TC:
+ case GL_RGB4_S3TC:
+ return GL_RGB;
+ case GL_RGBA_S3TC:
+ case GL_RGBA4_S3TC:
+ return GL_RGBA;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.MESA_ycbcr_texture) {
+ if (internalFormat == GL_YCBCR_MESA)
+ return GL_YCBCR_MESA;
+ }
+
+ if (ctx->Extensions.ARB_texture_float) {
+ switch (internalFormat) {
+ case GL_ALPHA16F_ARB:
+ case GL_ALPHA32F_ARB:
+ return GL_ALPHA;
+ case GL_RGBA16F_ARB:
+ case GL_RGBA32F_ARB:
+ return GL_RGBA;
+ case GL_RGB16F_ARB:
+ case GL_RGB32F_ARB:
+ return GL_RGB;
+ case GL_INTENSITY16F_ARB:
+ case GL_INTENSITY32F_ARB:
+ return GL_INTENSITY;
+ case GL_LUMINANCE16F_ARB:
+ case GL_LUMINANCE32F_ARB:
+ return GL_LUMINANCE;
+ case GL_LUMINANCE_ALPHA16F_ARB:
+ case GL_LUMINANCE_ALPHA32F_ARB:
+ return GL_LUMINANCE_ALPHA;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.ATI_envmap_bumpmap) {
+ switch (internalFormat) {
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ return GL_DUDV_ATI;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.MESA_texture_signed_rgba) {
+ switch (internalFormat) {
+ case GL_RGBA_SNORM:
+ case GL_RGBA8_SNORM:
+ return GL_RGBA;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.EXT_packed_depth_stencil) {
+ switch (internalFormat) {
+ case GL_DEPTH_STENCIL_EXT:
+ case GL_DEPTH24_STENCIL8_EXT:
+ return GL_DEPTH_STENCIL_EXT;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+#if FEATURE_EXT_texture_sRGB
+ if (ctx->Extensions.EXT_texture_sRGB) {
+ switch (internalFormat) {
+ case GL_SRGB_EXT:
+ case GL_SRGB8_EXT:
+ case GL_COMPRESSED_SRGB_EXT:
+ case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
+ return GL_RGB;
+ case GL_SRGB_ALPHA_EXT:
+ case GL_SRGB8_ALPHA8_EXT:
+ case GL_COMPRESSED_SRGB_ALPHA_EXT:
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
+ return GL_RGBA;
+ case GL_SLUMINANCE_ALPHA_EXT:
+ case GL_SLUMINANCE8_ALPHA8_EXT:
+ case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
+ return GL_LUMINANCE_ALPHA;
+ case GL_SLUMINANCE_EXT:
+ case GL_SLUMINANCE8_EXT:
+ case GL_COMPRESSED_SLUMINANCE_EXT:
+ return GL_LUMINANCE;
+ default:
+ ; /* fallthrough */
+ }
+ }
+#endif /* FEATURE_EXT_texture_sRGB */
+
+ if (ctx->Extensions.EXT_texture_integer) {
+ switch (internalFormat) {
+ case GL_RGBA8UI_EXT:
+ case GL_RGBA16UI_EXT:
+ case GL_RGBA32UI_EXT:
+ case GL_RGBA8I_EXT:
+ case GL_RGBA16I_EXT:
+ case GL_RGBA32I_EXT:
+ return GL_RGBA;
+ case GL_RGB8UI_EXT:
+ case GL_RGB16UI_EXT:
+ case GL_RGB32UI_EXT:
+ case GL_RGB8I_EXT:
+ case GL_RGB16I_EXT:
+ case GL_RGB32I_EXT:
+ return GL_RGB;
+ case GL_ALPHA8UI_EXT:
+ case GL_ALPHA16UI_EXT:
+ case GL_ALPHA32UI_EXT:
+ case GL_ALPHA8I_EXT:
+ case GL_ALPHA16I_EXT:
+ case GL_ALPHA32I_EXT:
+ return GL_ALPHA;
+ case GL_INTENSITY8UI_EXT:
+ case GL_INTENSITY16UI_EXT:
+ case GL_INTENSITY32UI_EXT:
+ case GL_INTENSITY8I_EXT:
+ case GL_INTENSITY16I_EXT:
+ case GL_INTENSITY32I_EXT:
+ return GL_INTENSITY;
+ case GL_LUMINANCE8UI_EXT:
+ case GL_LUMINANCE16UI_EXT:
+ case GL_LUMINANCE32UI_EXT:
+ case GL_LUMINANCE8I_EXT:
+ case GL_LUMINANCE16I_EXT:
+ case GL_LUMINANCE32I_EXT:
+ return GL_LUMINANCE;
+ case GL_LUMINANCE_ALPHA8UI_EXT:
+ case GL_LUMINANCE_ALPHA16UI_EXT:
+ case GL_LUMINANCE_ALPHA32UI_EXT:
+ case GL_LUMINANCE_ALPHA8I_EXT:
+ case GL_LUMINANCE_ALPHA16I_EXT:
+ case GL_LUMINANCE_ALPHA32I_EXT:
+ return GL_LUMINANCE_ALPHA;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.ARB_texture_rg) {
+ switch (internalFormat) {
+ case GL_R16F:
+ /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
+ */
+ if (!ctx->Extensions.ARB_half_float_pixel)
+ break;
+ /* FALLTHROUGH */
+ case GL_R32F:
+ if (!ctx->Extensions.ARB_texture_float)
+ break;
+ return GL_RED;
+ case GL_R8I:
+ case GL_R8UI:
+ case GL_R16I:
+ case GL_R16UI:
+ case GL_R32I:
+ case GL_R32UI:
+ if (!ctx->Extensions.EXT_texture_integer)
+ break;
+ /* FALLTHROUGH */
+ case GL_R8:
+ case GL_R16:
+ case GL_RED:
+ case GL_COMPRESSED_RED:
+ return GL_RED;
+
+ case GL_RG16F:
+ /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
+ */
+ if (!ctx->Extensions.ARB_half_float_pixel)
+ break;
+ /* FALLTHROUGH */
+ case GL_RG32F:
+ if (!ctx->Extensions.ARB_texture_float)
+ break;
+ return GL_RG;
+ case GL_RG8I:
+ case GL_RG8UI:
+ case GL_RG16I:
+ case GL_RG16UI:
+ case GL_RG32I:
+ case GL_RG32UI:
+ if (!ctx->Extensions.EXT_texture_integer)
+ break;
+ /* FALLTHROUGH */
+ case GL_RG:
+ case GL_RG8:
+ case GL_RG16:
+ case GL_COMPRESSED_RG:
+ return GL_RG;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.EXT_texture_shared_exponent) {
+ switch (internalFormat) {
+ case GL_RGB9_E5_EXT:
+ return GL_RGB;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.EXT_packed_float) {
+ switch (internalFormat) {
+ case GL_R11F_G11F_B10F_EXT:
+ return GL_RGB;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.ARB_depth_buffer_float) {
+ switch (internalFormat) {
+ case GL_DEPTH_COMPONENT32F:
+ return GL_DEPTH_COMPONENT;
+ case GL_DEPTH32F_STENCIL8:
+ return GL_DEPTH_STENCIL;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.ARB_texture_compression_rgtc) {
+ switch (internalFormat) {
+ case GL_COMPRESSED_RED_RGTC1:
+ case GL_COMPRESSED_SIGNED_RED_RGTC1:
+ return GL_RED;
+ case GL_COMPRESSED_RG_RGTC2:
+ case GL_COMPRESSED_SIGNED_RG_RGTC2:
+ return GL_RG;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ return -1; /* error */
+}
+
+
+/**
+ * For cube map faces, return a face index in [0,5].
+ * For other targets return 0;
+ */
+GLuint
+_mesa_tex_target_to_face(GLenum target)
+{
+ if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
+ target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)
+ return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X;
+ else
+ return 0;
+}
+
+
+
+/**
+ * Store a gl_texture_image pointer in a gl_texture_object structure
+ * according to the target and level parameters.
+ *
+ * \param tObj texture object.
+ * \param target texture target.
+ * \param level image level.
+ * \param texImage texture image.
+ *
+ * This was basically prompted by the introduction of cube maps.
+ */
+void
+_mesa_set_tex_image(struct gl_texture_object *tObj,
+ GLenum target, GLint level,
+ struct gl_texture_image *texImage)
+{
+ const GLuint face = _mesa_tex_target_to_face(target);
+
+ ASSERT(tObj);
+ ASSERT(texImage);
+ ASSERT(target != GL_TEXTURE_RECTANGLE_NV || level == 0);
+
+ tObj->Image[face][level] = texImage;
+
+ /* Set the 'back' pointer */
+ texImage->TexObject = tObj;
+}
+
+
+/**
+ * Allocate a texture image structure.
+ *
+ * Called via ctx->Driver.NewTextureImage() unless overriden by a device
+ * driver.
+ *
+ * \return a pointer to gl_texture_image struct with all fields initialized to
+ * zero.
+ */
+struct gl_texture_image *
+_mesa_new_texture_image( struct gl_context *ctx )
+{
+ (void) ctx;
+ return CALLOC_STRUCT(gl_texture_image);
+}
+
+
+/**
+ * Free texture image data.
+ * This function is a fallback called via ctx->Driver.FreeTexImageData().
+ *
+ * \param texImage texture image.
+ *
+ * Free the texture image data if it's not marked as client data.
+ */
+void
+_mesa_free_texture_image_data(struct gl_context *ctx,
+ struct gl_texture_image *texImage)
+{
+ (void) ctx;
+
+ if (texImage->Data && !texImage->IsClientData) {
+ /* free the old texture data */
+ _mesa_free_texmemory(texImage->Data);
+ }
+
+ texImage->Data = NULL;
+}
+
+
+/**
+ * Free texture image.
+ *
+ * \param texImage texture image.
+ *
+ * Free the texture image structure and the associated image data.
+ */
+void
+_mesa_delete_texture_image(struct gl_context *ctx,
+ struct gl_texture_image *texImage)
+{
+ /* Free texImage->Data and/or any other driver-specific texture
+ * image storage.
+ */
+ ASSERT(ctx->Driver.FreeTexImageData);
+ ctx->Driver.FreeTexImageData( ctx, texImage );
+
+ ASSERT(texImage->Data == NULL);
+ if (texImage->ImageOffsets)
+ free(texImage->ImageOffsets);
+ free(texImage);
+}
+
+
+/**
+ * Test if a target is a proxy target.
+ *
+ * \param target texture target.
+ *
+ * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
+ */
+GLboolean
+_mesa_is_proxy_texture(GLenum target)
+{
+ /* NUM_TEXTURE_TARGETS should match number of terms below */
+ assert(NUM_TEXTURE_TARGETS == 7);
+
+ return (target == GL_PROXY_TEXTURE_1D ||
+ target == GL_PROXY_TEXTURE_2D ||
+ target == GL_PROXY_TEXTURE_3D ||
+ target == GL_PROXY_TEXTURE_CUBE_MAP_ARB ||
+ target == GL_PROXY_TEXTURE_RECTANGLE_NV ||
+ target == GL_PROXY_TEXTURE_1D_ARRAY_EXT ||
+ target == GL_PROXY_TEXTURE_2D_ARRAY_EXT);
+}
+
+
+/**
+ * Return the proxy target which corresponds to the given texture target
+ */
+static GLenum
+get_proxy_target(GLenum target)
+{
+ switch (target) {
+ case GL_TEXTURE_1D:
+ case GL_PROXY_TEXTURE_1D:
+ return GL_PROXY_TEXTURE_1D;
+ case GL_TEXTURE_2D:
+ case GL_PROXY_TEXTURE_2D:
+ return GL_PROXY_TEXTURE_2D;
+ case GL_TEXTURE_3D:
+ case GL_PROXY_TEXTURE_3D:
+ return GL_PROXY_TEXTURE_3D;
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
+ return GL_PROXY_TEXTURE_CUBE_MAP_ARB;
+ case GL_TEXTURE_RECTANGLE_NV:
+ case GL_PROXY_TEXTURE_RECTANGLE_NV:
+ return GL_PROXY_TEXTURE_RECTANGLE_NV;
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
+ return GL_PROXY_TEXTURE_1D_ARRAY_EXT;
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
+ return GL_PROXY_TEXTURE_2D_ARRAY_EXT;
+ default:
+ _mesa_problem(NULL, "unexpected target in get_proxy_target()");
+ return 0;
+ }
+}
+
+
+/**
+ * Get the texture object that corresponds to the target of the given
+ * texture unit.
+ *
+ * \param ctx GL context.
+ * \param texUnit texture unit.
+ * \param target texture target.
+ *
+ * \return pointer to the texture object on success, or NULL on failure.
+ *
+ * \sa gl_texture_unit.
+ */
+struct gl_texture_object *
+_mesa_select_tex_object(struct gl_context *ctx,
+ const struct gl_texture_unit *texUnit,
+ GLenum target)
+{
+ const GLboolean arrayTex = (ctx->Extensions.MESA_texture_array ||
+ ctx->Extensions.EXT_texture_array);
+
+ switch (target) {
+ case GL_TEXTURE_1D:
+ return texUnit->CurrentTex[TEXTURE_1D_INDEX];
+ case GL_PROXY_TEXTURE_1D:
+ return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX];
+ case GL_TEXTURE_2D:
+ return texUnit->CurrentTex[TEXTURE_2D_INDEX];
+ case GL_PROXY_TEXTURE_2D:
+ return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
+ case GL_TEXTURE_3D:
+ return texUnit->CurrentTex[TEXTURE_3D_INDEX];
+ case GL_PROXY_TEXTURE_3D:
+ return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX];
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ return ctx->Extensions.ARB_texture_cube_map
+ ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL;
+ case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
+ return ctx->Extensions.ARB_texture_cube_map
+ ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL;
+ case GL_TEXTURE_RECTANGLE_NV:
+ return ctx->Extensions.NV_texture_rectangle
+ ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL;
+ case GL_PROXY_TEXTURE_RECTANGLE_NV:
+ return ctx->Extensions.NV_texture_rectangle
+ ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL;
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ return arrayTex ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
+ case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
+ return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ return arrayTex ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
+ case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
+ return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
+ default:
+ _mesa_problem(NULL, "bad target in _mesa_select_tex_object()");
+ return NULL;
+ }
+}
+
+
+/**
+ * Return pointer to texture object for given target on current texture unit.
+ */
+struct gl_texture_object *
+_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target)
+{
+ struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+ return _mesa_select_tex_object(ctx, texUnit, target);
+}
+
+
+/**
+ * Get a texture image pointer from a texture object, given a texture
+ * target and mipmap level. The target and level parameters should
+ * have already been error-checked.
+ *
+ * \param ctx GL context.
+ * \param texObj texture unit.
+ * \param target texture target.
+ * \param level image level.
+ *
+ * \return pointer to the texture image structure, or NULL on failure.
+ */
+struct gl_texture_image *
+_mesa_select_tex_image(struct gl_context *ctx,
+ const struct gl_texture_object *texObj,
+ GLenum target, GLint level)
+{
+ const GLuint face = _mesa_tex_target_to_face(target);
+
+ ASSERT(texObj);
+ ASSERT(level >= 0);
+ ASSERT(level < MAX_TEXTURE_LEVELS);
+
+ return texObj->Image[face][level];
+}
+
+
+/**
+ * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
+ * it and install it. Only return NULL if passed a bad parameter or run
+ * out of memory.
+ */
+struct gl_texture_image *
+_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj,
+ GLenum target, GLint level)
+{
+ struct gl_texture_image *texImage;
+
+ if (!texObj)
+ return NULL;
+
+ texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+ if (!texImage) {
+ texImage = ctx->Driver.NewTextureImage(ctx);
+ if (!texImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation");
+ return NULL;
+ }
+
+ _mesa_set_tex_image(texObj, target, level, texImage);
+ }
+
+ return texImage;
+}
+
+
+/**
+ * Return pointer to the specified proxy texture image.
+ * Note that proxy textures are per-context, not per-texture unit.
+ * \return pointer to texture image or NULL if invalid target, invalid
+ * level, or out of memory.
+ */
+struct gl_texture_image *
+_mesa_get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level)
+{
+ struct gl_texture_image *texImage;
+ GLuint texIndex;
+
+ if (level < 0 )
+ return NULL;
+
+ switch (target) {
+ case GL_PROXY_TEXTURE_1D:
+ if (level >= ctx->Const.MaxTextureLevels)
+ return NULL;
+ texIndex = TEXTURE_1D_INDEX;
+ break;
+ case GL_PROXY_TEXTURE_2D:
+ if (level >= ctx->Const.MaxTextureLevels)
+ return NULL;
+ texIndex = TEXTURE_2D_INDEX;
+ break;
+ case GL_PROXY_TEXTURE_3D:
+ if (level >= ctx->Const.Max3DTextureLevels)
+ return NULL;
+ texIndex = TEXTURE_3D_INDEX;
+ break;
+ case GL_PROXY_TEXTURE_CUBE_MAP:
+ if (level >= ctx->Const.MaxCubeTextureLevels)
+ return NULL;
+ texIndex = TEXTURE_CUBE_INDEX;
+ break;
+ case GL_PROXY_TEXTURE_RECTANGLE_NV:
+ if (level > 0)
+ return NULL;
+ texIndex = TEXTURE_RECT_INDEX;
+ break;
+ case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
+ if (level >= ctx->Const.MaxTextureLevels)
+ return NULL;
+ texIndex = TEXTURE_1D_ARRAY_INDEX;
+ break;
+ case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
+ if (level >= ctx->Const.MaxTextureLevels)
+ return NULL;
+ texIndex = TEXTURE_2D_ARRAY_INDEX;
+ break;
+ default:
+ return NULL;
+ }
+
+ texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level];
+ if (!texImage) {
+ texImage = ctx->Driver.NewTextureImage(ctx);
+ if (!texImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
+ return NULL;
+ }
+ ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage;
+ /* Set the 'back' pointer */
+ texImage->TexObject = ctx->Texture.ProxyTex[texIndex];
+ }
+ return texImage;
+}
+
+
+/**
+ * Get the maximum number of allowed mipmap levels.
+ *
+ * \param ctx GL context.
+ * \param target texture target.
+ *
+ * \return the maximum number of allowed mipmap levels for the given
+ * texture target, or zero if passed a bad target.
+ *
+ * \sa gl_constants.
+ */
+GLint
+_mesa_max_texture_levels(struct gl_context *ctx, GLenum target)
+{
+ switch (target) {
+ case GL_TEXTURE_1D:
+ case GL_PROXY_TEXTURE_1D:
+ case GL_TEXTURE_2D:
+ case GL_PROXY_TEXTURE_2D:
+ return ctx->Const.MaxTextureLevels;
+ case GL_TEXTURE_3D:
+ case GL_PROXY_TEXTURE_3D:
+ return ctx->Const.Max3DTextureLevels;
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
+ return ctx->Extensions.ARB_texture_cube_map
+ ? ctx->Const.MaxCubeTextureLevels : 0;
+ case GL_TEXTURE_RECTANGLE_NV:
+ case GL_PROXY_TEXTURE_RECTANGLE_NV:
+ return ctx->Extensions.NV_texture_rectangle ? 1 : 0;
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
+ return (ctx->Extensions.MESA_texture_array ||
+ ctx->Extensions.EXT_texture_array)
+ ? ctx->Const.MaxTextureLevels : 0;
+ default:
+ return 0; /* bad target */
+ }
+}
+
+
+/**
+ * Return number of dimensions per mipmap level for the given texture target.
+ */
+GLint
+_mesa_get_texture_dimensions(GLenum target)
+{
+ switch (target) {
+ case GL_TEXTURE_1D:
+ case GL_PROXY_TEXTURE_1D:
+ return 1;
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_RECTANGLE:
+ case GL_TEXTURE_CUBE_MAP:
+ case GL_PROXY_TEXTURE_2D:
+ case GL_PROXY_TEXTURE_RECTANGLE:
+ case GL_PROXY_TEXTURE_CUBE_MAP:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ case GL_TEXTURE_1D_ARRAY:
+ case GL_PROXY_TEXTURE_1D_ARRAY:
+ return 2;
+ case GL_TEXTURE_3D:
+ case GL_PROXY_TEXTURE_3D:
+ case GL_TEXTURE_2D_ARRAY:
+ case GL_PROXY_TEXTURE_2D_ARRAY:
+ return 3;
+ default:
+ _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()",
+ target);
+ return 2;
+ }
+}
+
+
+
+
+#if 000 /* not used anymore */
+/*
+ * glTexImage[123]D can accept a NULL image pointer. In this case we
+ * create a texture image with unspecified image contents per the OpenGL
+ * spec.
+ */
+static GLubyte *
+make_null_texture(GLint width, GLint height, GLint depth, GLenum format)
+{
+ const GLint components = _mesa_components_in_format(format);
+ const GLint numPixels = width * height * depth;
+ GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte));
+
+#ifdef DEBUG
+ /*
+ * Let's see if anyone finds this. If glTexImage2D() is called with
+ * a NULL image pointer then load the texture image with something
+ * interesting instead of leaving it indeterminate.
+ */
+ if (data) {
+ static const char message[8][32] = {
+ " X X XXXXX XXX X ",
+ " XX XX X X X X X ",
+ " X X X X X X X ",
+ " X X XXXX XXX XXXXX ",
+ " X X X X X X ",
+ " X X X X X X X ",
+ " X X XXXXX XXX X X ",
+ " "
+ };
+
+ GLubyte *imgPtr = data;
+ GLint h, i, j, k;
+ for (h = 0; h < depth; h++) {
+ for (i = 0; i < height; i++) {
+ GLint srcRow = 7 - (i % 8);
+ for (j = 0; j < width; j++) {
+ GLint srcCol = j % 32;
+ GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70;
+ for (k = 0; k < components; k++) {
+ *imgPtr++ = texel;
+ }
+ }
+ }
+ }
+ }
+#endif
+
+ return data;
+}
+#endif
+
+
+
+/**
+ * Reset the fields of a gl_texture_image struct to zero.
+ *
+ * \param img texture image structure.
+ *
+ * This is called when a proxy texture test fails, we set all the
+ * image members (except DriverData) to zero.
+ * It's also used in glTexImage[123]D as a safeguard to be sure all
+ * required fields get initialized properly by the Driver.TexImage[123]D
+ * functions.
+ */
+static void
+clear_teximage_fields(struct gl_texture_image *img)
+{
+ ASSERT(img);
+ img->_BaseFormat = 0;
+ img->InternalFormat = 0;
+ img->Border = 0;
+ img->Width = 0;
+ img->Height = 0;
+ img->Depth = 0;
+ img->RowStride = 0;
+ if (img->ImageOffsets) {
+ free(img->ImageOffsets);
+ img->ImageOffsets = NULL;
+ }
+ img->Width2 = 0;
+ img->Height2 = 0;
+ img->Depth2 = 0;
+ img->WidthLog2 = 0;
+ img->HeightLog2 = 0;
+ img->DepthLog2 = 0;
+ img->Data = NULL;
+ img->TexFormat = MESA_FORMAT_NONE;
+ img->FetchTexelc = NULL;
+ img->FetchTexelf = NULL;
+}
+
+
+/**
+ * Initialize basic fields of the gl_texture_image struct.
+ *
+ * \param ctx GL context.
+ * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
+ * \param img texture image structure to be initialized.
+ * \param width image width.
+ * \param height image height.
+ * \param depth image depth.
+ * \param border image border.
+ * \param internalFormat internal format.
+ * \param format the actual hardware format (one of MESA_FORMAT_*)
+ *
+ * Fills in the fields of \p img with the given information.
+ * Note: width, height and depth include the border.
+ */
+void
+_mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
+ struct gl_texture_image *img,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLint border, GLenum internalFormat,
+ gl_format format)
+{
+ GLint i, dims;
+
+ ASSERT(img);
+ ASSERT(width >= 0);
+ ASSERT(height >= 0);
+ ASSERT(depth >= 0);
+
+ img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat );
+ ASSERT(img->_BaseFormat > 0);
+ img->InternalFormat = internalFormat;
+ img->Border = border;
+ img->Width = width;
+ img->Height = height;
+ img->Depth = depth;
+
+ img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */
+ img->WidthLog2 = logbase2(img->Width2);
+
+ if (height == 1) { /* 1-D texture */
+ img->Height2 = 1;
+ img->HeightLog2 = 0;
+ }
+ else {
+ img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */
+ img->HeightLog2 = logbase2(img->Height2);
+ }
+
+ if (depth == 1) { /* 2-D texture */
+ img->Depth2 = 1;
+ img->DepthLog2 = 0;
+ }
+ else {
+ img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */
+ img->DepthLog2 = logbase2(img->Depth2);
+ }
+
+ img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
+
+ if ((width == 1 || _mesa_is_pow_two(img->Width2)) &&
+ (height == 1 || _mesa_is_pow_two(img->Height2)) &&
+ (depth == 1 || _mesa_is_pow_two(img->Depth2)))
+ img->_IsPowerOfTwo = GL_TRUE;
+ else
+ img->_IsPowerOfTwo = GL_FALSE;
+
+ /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
+ img->RowStride = width;
+ /* Allocate the ImageOffsets array and initialize to typical values.
+ * We allocate the array for 1D/2D textures too in order to avoid special-
+ * case code in the texstore routines.
+ */
+ if (img->ImageOffsets)
+ free(img->ImageOffsets);
+ img->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint));
+ for (i = 0; i < depth; i++) {
+ img->ImageOffsets[i] = i * width * height;
+ }
+
+ /* Compute Width/Height/DepthScale for mipmap lod computation */
+ if (target == GL_TEXTURE_RECTANGLE_NV) {
+ /* scale = 1.0 since texture coords directly map to texels */
+ img->WidthScale = 1.0;
+ img->HeightScale = 1.0;
+ img->DepthScale = 1.0;
+ }
+ else {
+ img->WidthScale = (GLfloat) img->Width;
+ img->HeightScale = (GLfloat) img->Height;
+ img->DepthScale = (GLfloat) img->Depth;
+ }
+
+ img->TexFormat = format;
+
+ dims = _mesa_get_texture_dimensions(target);
+
+ _mesa_set_fetch_functions(img, dims);
+}
+
+
+/**
+ * Free and clear fields of the gl_texture_image struct.
+ *
+ * \param ctx GL context.
+ * \param texImage texture image structure to be cleared.
+ *
+ * After the call, \p texImage will have no data associated with it. Its
+ * fields are cleared so that its parent object will test incomplete.
+ */
+void
+_mesa_clear_texture_image(struct gl_context *ctx,
+ struct gl_texture_image *texImage)
+{
+ ctx->Driver.FreeTexImageData(ctx, texImage);
+ clear_teximage_fields(texImage);
+}
+
+
+/**
+ * This is the fallback for Driver.TestProxyTexImage(). Test the texture
+ * level, width, height and depth against the ctx->Const limits for textures.
+ *
+ * A hardware driver might override this function if, for example, the
+ * max 3D texture size is 512x512x64 (i.e. not a cube).
+ *
+ * Note that width, height, depth == 0 is not an error. However, a
+ * texture with zero width/height/depth will be considered "incomplete"
+ * and texturing will effectively be disabled.
+ *
+ * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
+ * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
+ * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
+ * \param level as passed to glTexImage
+ * \param internalFormat as passed to glTexImage
+ * \param format as passed to glTexImage
+ * \param type as passed to glTexImage
+ * \param width as passed to glTexImage
+ * \param height as passed to glTexImage
+ * \param depth as passed to glTexImage
+ * \param border as passed to glTexImage
+ * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
+ */
+GLboolean
+_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat, GLenum format, GLenum type,
+ GLint width, GLint height, GLint depth, GLint border)
+{
+ GLint maxSize;
+
+ (void) internalFormat;
+ (void) format;
+ (void) type;
+
+ switch (target) {
+ case GL_PROXY_TEXTURE_1D:
+ maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
+ if (width < 2 * border || width > 2 + maxSize)
+ return GL_FALSE;
+ if (level >= ctx->Const.MaxTextureLevels)
+ return GL_FALSE;
+ if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+ if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+ return GL_FALSE;
+ }
+ return GL_TRUE;
+
+ case GL_PROXY_TEXTURE_2D:
+ maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
+ if (width < 2 * border || width > 2 + maxSize)
+ return GL_FALSE;
+ if (height < 2 * border || height > 2 + maxSize)
+ return GL_FALSE;
+ if (level >= ctx->Const.MaxTextureLevels)
+ return GL_FALSE;
+ if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+ if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+ return GL_FALSE;
+ if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
+ return GL_FALSE;
+ }
+ return GL_TRUE;
+
+ case GL_PROXY_TEXTURE_3D:
+ maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
+ if (width < 2 * border || width > 2 + maxSize)
+ return GL_FALSE;
+ if (height < 2 * border || height > 2 + maxSize)
+ return GL_FALSE;
+ if (depth < 2 * border || depth > 2 + maxSize)
+ return GL_FALSE;
+ if (level >= ctx->Const.Max3DTextureLevels)
+ return GL_FALSE;
+ if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+ if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+ return GL_FALSE;
+ if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
+ return GL_FALSE;
+ if (depth > 0 && !_mesa_is_pow_two(depth - 2 * border))
+ return GL_FALSE;
+ }
+ return GL_TRUE;
+
+ case GL_PROXY_TEXTURE_RECTANGLE_NV:
+ maxSize = ctx->Const.MaxTextureRectSize;
+ if (width < 0 || width > maxSize)
+ return GL_FALSE;
+ if (height < 0 || height > maxSize)
+ return GL_FALSE;
+ if (level != 0)
+ return GL_FALSE;
+ return GL_TRUE;
+
+ case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
+ maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1);
+ if (width < 2 * border || width > 2 + maxSize)
+ return GL_FALSE;
+ if (height < 2 * border || height > 2 + maxSize)
+ return GL_FALSE;
+ if (level >= ctx->Const.MaxCubeTextureLevels)
+ return GL_FALSE;
+ if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+ if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+ return GL_FALSE;
+ if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
+ return GL_FALSE;
+ }
+ return GL_TRUE;
+
+ case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
+ maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
+ if (width < 2 * border || width > 2 + maxSize)
+ return GL_FALSE;
+ if (height < 1 || height > ctx->Const.MaxArrayTextureLayers)
+ return GL_FALSE;
+ if (level >= ctx->Const.MaxTextureLevels)
+ return GL_FALSE;
+ if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+ if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+ return GL_FALSE;
+ }
+ return GL_TRUE;
+
+ case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
+ maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
+ if (width < 2 * border || width > 2 + maxSize)
+ return GL_FALSE;
+ if (height < 2 * border || height > 2 + maxSize)
+ return GL_FALSE;
+ if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers)
+ return GL_FALSE;
+ if (level >= ctx->Const.MaxTextureLevels)
+ return GL_FALSE;
+ if (!ctx->Extensions.ARB_texture_non_power_of_two) {
+ if (width > 0 && !_mesa_is_pow_two(width - 2 * border))
+ return GL_FALSE;
+ if (height > 0 && !_mesa_is_pow_two(height - 2 * border))
+ return GL_FALSE;
+ }
+ return GL_TRUE;
+
+ default:
+ _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage");
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Check if the memory used by the texture would exceed the driver's limit.
+ * This lets us support a max 3D texture size of 8K (for example) but
+ * prevents allocating a full 8K x 8K x 8K texture.
+ * XXX this could be rolled into the proxy texture size test (above) but
+ * we don't have the actual texture internal format at that point.
+ */
+static GLboolean
+legal_texture_size(struct gl_context *ctx, gl_format format,
+ GLint width, GLint height, GLint depth)
+{
+ uint64_t bytes = _mesa_format_image_size64(format, width, height, depth);
+ uint64_t mbytes = bytes / (1024 * 1024); /* convert to MB */
+ return mbytes <= (uint64_t) ctx->Const.MaxTextureMbytes;
+}
+
+
+
+/**
+ * Helper function to determine whether a target and specific compression
+ * format are supported.
+ */
+static GLboolean
+target_can_be_compressed(const struct gl_context *ctx, GLenum target,
+ GLenum intFormat)
+{
+ (void) intFormat; /* not used yet */
+
+ switch (target) {
+ case GL_TEXTURE_2D:
+ case GL_PROXY_TEXTURE_2D:
+ return GL_TRUE; /* true for any compressed format so far */
+ case GL_PROXY_TEXTURE_CUBE_MAP:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ return ctx->Extensions.ARB_texture_cube_map;
+ case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ return (ctx->Extensions.MESA_texture_array ||
+ ctx->Extensions.EXT_texture_array);
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Check if the given texture target value is legal for a
+ * glTexImage1/2/3D call.
+ */
+static GLboolean
+legal_teximage_target(struct gl_context *ctx, GLuint dims, GLenum target)
+{
+ switch (dims) {
+ case 1:
+ switch (target) {
+ case GL_TEXTURE_1D:
+ case GL_PROXY_TEXTURE_1D:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+ case 2:
+ switch (target) {
+ case GL_TEXTURE_2D:
+ case GL_PROXY_TEXTURE_2D:
+ return GL_TRUE;
+ case GL_PROXY_TEXTURE_CUBE_MAP:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ return ctx->Extensions.ARB_texture_cube_map;
+ case GL_TEXTURE_RECTANGLE_NV:
+ case GL_PROXY_TEXTURE_RECTANGLE_NV:
+ return ctx->Extensions.NV_texture_rectangle;
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
+ return (ctx->Extensions.MESA_texture_array ||
+ ctx->Extensions.EXT_texture_array);
+ default:
+ return GL_FALSE;
+ }
+ case 3:
+ switch (target) {
+ case GL_TEXTURE_3D:
+ case GL_PROXY_TEXTURE_3D:
+ return GL_TRUE;
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
+ return (ctx->Extensions.MESA_texture_array ||
+ ctx->Extensions.EXT_texture_array);
+ default:
+ return GL_FALSE;
+ }
+ default:
+ _mesa_problem(ctx, "invalid dims=%u in legal_teximage_target()", dims);
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Check if the given texture target value is legal for a
+ * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
+ * The difference compared to legal_teximage_target() above is that
+ * proxy targets are not supported.
+ */
+static GLboolean
+legal_texsubimage_target(struct gl_context *ctx, GLuint dims, GLenum target)
+{
+ switch (dims) {
+ case 1:
+ return target == GL_TEXTURE_1D;
+ case 2:
+ switch (target) {
+ case GL_TEXTURE_2D:
+ return GL_TRUE;
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ return ctx->Extensions.ARB_texture_cube_map;
+ case GL_TEXTURE_RECTANGLE_NV:
+ return ctx->Extensions.NV_texture_rectangle;
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ return (ctx->Extensions.MESA_texture_array ||
+ ctx->Extensions.EXT_texture_array);
+ default:
+ return GL_FALSE;
+ }
+ case 3:
+ switch (target) {
+ case GL_TEXTURE_3D:
+ return GL_TRUE;
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ return (ctx->Extensions.MESA_texture_array ||
+ ctx->Extensions.EXT_texture_array);
+ default:
+ return GL_FALSE;
+ }
+ default:
+ _mesa_problem(ctx, "invalid dims=%u in legal_texsubimage_target()",
+ dims);
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test the glTexImage[123]D() parameters for errors.
+ *
+ * \param ctx GL context.
+ * \param dimensions texture image dimensions (must be 1, 2 or 3).
+ * \param target texture target given by the user.
+ * \param level image level given by the user.
+ * \param internalFormat internal format given by the user.
+ * \param format pixel data format given by the user.
+ * \param type pixel data type given by the user.
+ * \param width image width given by the user.
+ * \param height image height given by the user.
+ * \param depth image depth given by the user.
+ * \param border image border given by the user.
+ *
+ * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
+ *
+ * Verifies each of the parameters against the constants specified in
+ * __struct gl_contextRec::Const and the supported extensions, and according
+ * to the OpenGL specification.
+ */
+static GLboolean
+texture_error_check( struct gl_context *ctx,
+ GLuint dimensions, GLenum target,
+ GLint level, GLint internalFormat,
+ GLenum format, GLenum type,
+ GLint width, GLint height,
+ GLint depth, GLint border )
+{
+ const GLenum proxyTarget = get_proxy_target(target);
+ const GLboolean isProxy = target == proxyTarget;
+ GLboolean sizeOK = GL_TRUE;
+ GLboolean colorFormat, indexFormat;
+
+ /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
+ if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
+ if (!isProxy) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTexImage%dD(level=%d)", dimensions, level);
+ }
+ return GL_TRUE;
+ }
+
+ /* Check border */
+ if (border < 0 || border > 1 ||
+ ((target == GL_TEXTURE_RECTANGLE_NV ||
+ target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) {
+ if (!isProxy) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTexImage%dD(border=%d)", dimensions, border);
+ }
+ return GL_TRUE;
+ }
+
+ if (width < 0 || height < 0 || depth < 0) {
+ if (!isProxy) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTexImage%dD(width, height or depth < 0)", dimensions);
+ }
+ return GL_TRUE;
+ }
+
+ /* Do this simple check before calling the TestProxyTexImage() function */
+ if (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
+ sizeOK = (width == height);
+ }
+
+ /*
+ * Use the proxy texture driver hook to see if the size/level/etc are
+ * legal.
+ */
+ sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level,
+ internalFormat, format,
+ type, width, height,
+ depth, border);
+ if (!sizeOK) {
+ if (!isProxy) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
+ dimensions, level, width, height, depth);
+ }
+ return GL_TRUE;
+ }
+
+ /* Check internalFormat */
+ if (_mesa_base_tex_format(ctx, internalFormat) < 0) {
+ if (!isProxy) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTexImage%dD(internalFormat=%s)",
+ dimensions, _mesa_lookup_enum_by_nr(internalFormat));
+ }
+ return GL_TRUE;
+ }
+
+ /* Check incoming image format and type */
+ if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
+ /* Normally, GL_INVALID_OPERATION is generated by a format/type
+ * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
+ * GL_EXT_texture_integer extension, some combinations should generate
+ * GL_INVALID_ENUM instead (grr!).
+ */
+ if (!isProxy) {
+ GLenum error = _mesa_is_integer_format(format)
+ ? GL_INVALID_ENUM : GL_INVALID_OPERATION;
+ _mesa_error(ctx, error,
+ "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
+ dimensions, format, type);
+ }
+ return GL_TRUE;
+ }
+
+ /* make sure internal format and format basically agree */
+ colorFormat = _mesa_is_color_format(format);
+ indexFormat = _mesa_is_index_format(format);
+ if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) ||
+ (_mesa_is_index_format(internalFormat) && !indexFormat) ||
+ (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) ||
+ (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) ||
+ (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) ||
+ (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) {
+ if (!isProxy)
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
+ dimensions, internalFormat, format);
+ return GL_TRUE;
+ }
+
+ /* additional checks for ycbcr textures */
+ if (internalFormat == GL_YCBCR_MESA) {
+ ASSERT(ctx->Extensions.MESA_ycbcr_texture);
+ if (type != GL_UNSIGNED_SHORT_8_8_MESA &&
+ type != GL_UNSIGNED_SHORT_8_8_REV_MESA) {
+ char message[100];
+ _mesa_snprintf(message, sizeof(message),
+ "glTexImage%dD(format/type YCBCR mismatch", dimensions);
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s", message);
+ return GL_TRUE; /* error */
+ }
+ if (target != GL_TEXTURE_2D &&
+ target != GL_PROXY_TEXTURE_2D &&
+ target != GL_TEXTURE_RECTANGLE_NV &&
+ target != GL_PROXY_TEXTURE_RECTANGLE_NV) {
+ if (!isProxy)
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)");
+ return GL_TRUE;
+ }
+ if (border != 0) {
+ if (!isProxy) {
+ char message[100];
+ _mesa_snprintf(message, sizeof(message),
+ "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
+ dimensions, border);
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s", message);
+ }
+ return GL_TRUE;
+ }
+ }
+
+ /* additional checks for depth textures */
+ if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) {
+ /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
+ if (target != GL_TEXTURE_1D &&
+ target != GL_PROXY_TEXTURE_1D &&
+ target != GL_TEXTURE_2D &&
+ target != GL_PROXY_TEXTURE_2D &&
+ target != GL_TEXTURE_RECTANGLE_ARB &&
+ target != GL_PROXY_TEXTURE_RECTANGLE_ARB) {
+ if (!isProxy)
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glTexImage(target/internalFormat)");
+ return GL_TRUE;
+ }
+ }
+
+ /* additional checks for compressed textures */
+ if (_mesa_is_compressed_format(ctx, internalFormat)) {
+ if (!target_can_be_compressed(ctx, target, internalFormat)) {
+ if (!isProxy)
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glTexImage%dD(target)", dimensions);
+ return GL_TRUE;
+ }
+ if (border != 0) {
+ if (!isProxy) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glTexImage%dD(border!=0)", dimensions);
+ }
+ return GL_TRUE;
+ }
+ }
+
+ /* additional checks for integer textures */
+ if (ctx->Extensions.EXT_texture_integer &&
+ (_mesa_is_integer_format(format) !=
+ _mesa_is_integer_format(internalFormat))) {
+ if (!isProxy) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glTexImage%dD(integer/non-integer format mismatch)",
+ dimensions);
+ }
+ return GL_TRUE;
+ }
+
+ /* if we get here, the parameters are OK */
+ return GL_FALSE;
+}
+
+
+/**
+ * Test glTexSubImage[123]D() parameters for errors.
+ *
+ * \param ctx GL context.
+ * \param dimensions texture image dimensions (must be 1, 2 or 3).
+ * \param target texture target given by the user.
+ * \param level image level given by the user.
+ * \param xoffset sub-image x offset given by the user.
+ * \param yoffset sub-image y offset given by the user.
+ * \param zoffset sub-image z offset given by the user.
+ * \param format pixel data format given by the user.
+ * \param type pixel data type given by the user.
+ * \param width image width given by the user.
+ * \param height image height given by the user.
+ * \param depth image depth given by the user.
+ *
+ * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
+ *
+ * Verifies each of the parameters against the constants specified in
+ * __struct gl_contextRec::Const and the supported extensions, and according
+ * to the OpenGL specification.
+ */
+static GLboolean
+subtexture_error_check( struct gl_context *ctx, GLuint dimensions,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint width, GLint height, GLint depth,
+ GLenum format, GLenum type )
+{
+ /* Basic level check */
+ if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level);
+ return GL_TRUE;
+ }
+
+ /* Check for negative sizes */
+ if (width < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTexSubImage%dD(width=%d)", dimensions, width);
+ return GL_TRUE;
+ }
+ if (height < 0 && dimensions > 1) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTexSubImage%dD(height=%d)", dimensions, height);
+ return GL_TRUE;
+ }
+ if (depth < 0 && dimensions > 2) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTexSubImage%dD(depth=%d)", dimensions, depth);
+ return GL_TRUE;
+ }
+
+ if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
+ /* As with the glTexImage2D check above, the error code here
+ * depends on texture integer.
+ */
+ GLenum error = _mesa_is_integer_format(format)
+ ? GL_INVALID_OPERATION : GL_INVALID_ENUM;
+ _mesa_error(ctx, error,
+ "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
+ dimensions, format, type);
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+
+/**
+ * Do second part of glTexSubImage which depends on the destination texture.
+ * \return GL_TRUE if error recorded, GL_FALSE otherwise
+ */
+static GLboolean
+subtexture_error_check2( struct gl_context *ctx, GLuint dimensions,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint width, GLint height, GLint depth,
+ GLenum format, GLenum type,
+ const struct gl_texture_image *destTex )
+{
+ if (!destTex) {
+ /* undefined image level */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions);
+ return GL_TRUE;
+ }
+
+ if (xoffset < -((GLint)destTex->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)",
+ dimensions);
+ return GL_TRUE;
+ }
+ if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)",
+ dimensions);
+ return GL_TRUE;
+ }
+ if (dimensions > 1) {
+ if (yoffset < -((GLint)destTex->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)",
+ dimensions);
+ return GL_TRUE;
+ }
+ if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)",
+ dimensions);
+ return GL_TRUE;
+ }
+ }
+ if (dimensions > 2) {
+ if (zoffset < -((GLint)destTex->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)");
+ return GL_TRUE;
+ }
+ if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)");
+ return GL_TRUE;
+ }
+ }
+
+ if (_mesa_is_format_compressed(destTex->TexFormat)) {
+ GLuint bw, bh;
+
+ /* do tests which depend on compression block size */
+ _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh);
+
+ /* offset must be multiple of block size */
+ if ((xoffset % bw != 0) || (yoffset % bh != 0)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
+ dimensions, xoffset, yoffset);
+ return GL_TRUE;
+ }
+ /* size must be multiple of bw by bh or equal to whole texture size */
+ if ((width % bw != 0) && (GLuint) width != destTex->Width) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glTexSubImage%dD(width = %d)", dimensions, width);
+ return GL_TRUE;
+ }
+ if ((height % bh != 0) && (GLuint) height != destTex->Height) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glTexSubImage%dD(height = %d)", dimensions, height);
+ return GL_TRUE;
+ }
+ }
+
+ return GL_FALSE;
+}
+
+
+/**
+ * Test glCopyTexImage[12]D() parameters for errors.
+ *
+ * \param ctx GL context.
+ * \param dimensions texture image dimensions (must be 1, 2 or 3).
+ * \param target texture target given by the user.
+ * \param level image level given by the user.
+ * \param internalFormat internal format given by the user.
+ * \param width image width given by the user.
+ * \param height image height given by the user.
+ * \param border texture border.
+ *
+ * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
+ *
+ * Verifies each of the parameters against the constants specified in
+ * __struct gl_contextRec::Const and the supported extensions, and according
+ * to the OpenGL specification.
+ */
+static GLboolean
+copytexture_error_check( struct gl_context *ctx, GLuint dimensions,
+ GLenum target, GLint level, GLint internalFormat,
+ GLint width, GLint height, GLint border )
+{
+ const GLenum proxyTarget = get_proxy_target(target);
+ const GLenum type = GL_FLOAT;
+ GLboolean sizeOK;
+ GLint format;
+
+ /* check target */
+ if (!legal_texsubimage_target(ctx, dimensions, target)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)",
+ dimensions, _mesa_lookup_enum_by_nr(target));
+ return GL_TRUE;
+ }
+
+ /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
+ if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexImage%dD(level=%d)", dimensions, level);
+ return GL_TRUE;
+ }
+
+ /* Check that the source buffer is complete */
+ if (ctx->ReadBuffer->Name) {
+ if (ctx->ReadBuffer->_Status == 0) {
+ _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
+ }
+ if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+ "glCopyTexImage%dD(invalid readbuffer)", dimensions);
+ return GL_TRUE;
+ }
+ }
+
+ /* Check border */
+ if (border < 0 || border > 1 ||
+ ((target == GL_TEXTURE_RECTANGLE_NV ||
+ target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) {
+ return GL_TRUE;
+ }
+
+ format = _mesa_base_tex_format(ctx, internalFormat);
+ if (format < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexImage%dD(internalFormat)", dimensions);
+ return GL_TRUE;
+ }
+
+ if (!_mesa_source_buffer_exists(ctx, format)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyTexImage%dD(missing readbuffer)", dimensions);
+ return GL_TRUE;
+ }
+
+ /* Do size, level checking */
+ sizeOK = (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB)
+ ? (width == height) : 1;
+
+ sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level,
+ internalFormat, format,
+ type, width, height,
+ 1, border);
+
+ if (!sizeOK) {
+ if (dimensions == 1) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexImage1D(width=%d)", width);
+ }
+ else {
+ ASSERT(dimensions == 2);
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexImage2D(width=%d, height=%d)", width, height);
+ }
+ return GL_TRUE;
+ }
+
+ if (_mesa_is_compressed_format(ctx, internalFormat)) {
+ if (!target_can_be_compressed(ctx, target, internalFormat)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glCopyTexImage%dD(target)", dimensions);
+ return GL_TRUE;
+ }
+ if (border != 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyTexImage%dD(border!=0)", dimensions);
+ return GL_TRUE;
+ }
+ }
+ else if (_mesa_is_depth_format(internalFormat)) {
+ /* make sure we have depth/stencil buffers */
+ if (!ctx->ReadBuffer->_DepthBuffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyTexImage%dD(no depth)", dimensions);
+ return GL_TRUE;
+ }
+ }
+ else if (_mesa_is_depthstencil_format(internalFormat)) {
+ /* make sure we have depth/stencil buffers */
+ if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyTexImage%dD(no depth/stencil buffer)", dimensions);
+ return GL_TRUE;
+ }
+ }
+
+ /* if we get here, the parameters are OK */
+ return GL_FALSE;
+}
+
+
+/**
+ * Test glCopyTexSubImage[12]D() parameters for errors.
+ * Note that this is the first part of error checking.
+ * See also copytexsubimage_error_check2() below for the second part.
+ *
+ * \param ctx GL context.
+ * \param dimensions texture image dimensions (must be 1, 2 or 3).
+ * \param target texture target given by the user.
+ * \param level image level given by the user.
+ *
+ * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
+ */
+static GLboolean
+copytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions,
+ GLenum target, GLint level)
+{
+ /* Check that the source buffer is complete */
+ if (ctx->ReadBuffer->Name) {
+ if (ctx->ReadBuffer->_Status == 0) {
+ _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
+ }
+ if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+ "glCopyTexImage%dD(invalid readbuffer)", dimensions);
+ return GL_TRUE;
+ }
+ }
+
+ /* check target (proxies not allowed) */
+ if (!legal_texsubimage_target(ctx, dimensions, target)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexSubImage%uD(target=%s)",
+ dimensions, _mesa_lookup_enum_by_nr(target));
+ return GL_TRUE;
+ }
+
+ /* Check level */
+ if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(level=%d)", dimensions, level);
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+
+/**
+ * Second part of error checking for glCopyTexSubImage[12]D().
+ * \param xoffset sub-image x offset given by the user.
+ * \param yoffset sub-image y offset given by the user.
+ * \param zoffset sub-image z offset given by the user.
+ * \param width image width given by the user.
+ * \param height image height given by the user.
+ */
+static GLboolean
+copytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height,
+ const struct gl_texture_image *teximage )
+{
+ /* check that dest tex image exists */
+ if (!teximage) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyTexSubImage%dD(undefined texture level: %d)",
+ dimensions, level);
+ return GL_TRUE;
+ }
+
+ /* Check size */
+ if (width < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(width=%d)", dimensions, width);
+ return GL_TRUE;
+ }
+ if (dimensions > 1 && height < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(height=%d)", dimensions, height);
+ return GL_TRUE;
+ }
+
+ /* check x/y offsets */
+ if (xoffset < -((GLint)teximage->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset);
+ return GL_TRUE;
+ }
+ if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(xoffset+width)", dimensions);
+ return GL_TRUE;
+ }
+ if (dimensions > 1) {
+ if (yoffset < -((GLint)teximage->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset);
+ return GL_TRUE;
+ }
+ /* NOTE: we're adding the border here, not subtracting! */
+ if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(yoffset+height)", dimensions);
+ return GL_TRUE;
+ }
+ }
+
+ /* check z offset */
+ if (dimensions > 2) {
+ if (zoffset < -((GLint)teximage->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(zoffset)", dimensions);
+ return GL_TRUE;
+ }
+ if (zoffset > (GLint) (teximage->Depth + teximage->Border)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(zoffset+depth)", dimensions);
+ return GL_TRUE;
+ }
+ }
+
+ if (_mesa_is_format_compressed(teximage->TexFormat)) {
+ /* offset must be multiple of 4 */
+ if ((xoffset & 3) || (yoffset & 3)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions);
+ return GL_TRUE;
+ }
+ /* size must be multiple of 4 */
+ if ((width & 3) != 0 && (GLuint) width != teximage->Width) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(width)", dimensions);
+ return GL_TRUE;
+ }
+ if ((height & 3) != 0 && (GLuint) height != teximage->Height) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(height)", dimensions);
+ return GL_TRUE;
+ }
+ }
+
+ if (teximage->InternalFormat == GL_YCBCR_MESA) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D");
+ return GL_TRUE;
+ }
+
+ if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
+ dimensions, teximage->_BaseFormat);
+ return GL_TRUE;
+ }
+
+ if (teximage->_BaseFormat == GL_DEPTH_COMPONENT) {
+ if (!ctx->ReadBuffer->_DepthBuffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyTexSubImage%dD(no depth buffer)",
+ dimensions);
+ return GL_TRUE;
+ }
+ }
+ else if (teximage->_BaseFormat == GL_DEPTH_STENCIL_EXT) {
+ if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyTexSubImage%dD(no depth/stencil buffer)",
+ dimensions);
+ return GL_TRUE;
+ }
+ }
+
+ /* If copying into an integer texture, the source buffer must also be
+ * integer-valued.
+ */
+ if (_mesa_is_format_integer_color(teximage->TexFormat)) {
+ struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
+ if (!_mesa_is_format_integer_color(rb->Format)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCopyTexSubImage%dD(source buffer is not integer format)",
+ dimensions);
+ return GL_TRUE;
+ }
+ }
+
+ /* if we get here, the parameters are OK */
+ return GL_FALSE;
+}
+
+
+/** Callback info for walking over FBO hash table */
+struct cb_info
+{
+ struct gl_context *ctx;
+ struct gl_texture_object *texObj;
+ GLuint level, face;
+};
+
+
+/**
+ * Check render to texture callback. Called from _mesa_HashWalk().
+ */
+static void
+check_rtt_cb(GLuint key, void *data, void *userData)
+{
+ struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
+ const struct cb_info *info = (struct cb_info *) userData;
+ struct gl_context *ctx = info->ctx;
+ const struct gl_texture_object *texObj = info->texObj;
+ const GLuint level = info->level, face = info->face;
+
+ /* If this is a user-created FBO */
+ if (fb->Name) {
+ GLuint i;
+ /* check if any of the FBO's attachments point to 'texObj' */
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ struct gl_renderbuffer_attachment *att = fb->Attachment + i;
+ if (att->Type == GL_TEXTURE &&
+ att->Texture == texObj &&
+ att->TextureLevel == level &&
+ att->CubeMapFace == face) {
+ ASSERT(att->Texture->Image[att->CubeMapFace][att->TextureLevel]);
+ /* Tell driver about the new renderbuffer texture */
+ ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att);
+ /* Mark fb status as indeterminate to force re-validation */
+ fb->_Status = 0;
+ }
+ }
+ }
+}
+
+
+/**
+ * When a texture image is specified we have to check if it's bound to
+ * any framebuffer objects (render to texture) in order to detect changes
+ * in size or format since that effects FBO completeness.
+ * Any FBOs rendering into the texture must be re-validated.
+ */
+static void
+update_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj,
+ GLuint face, GLuint level)
+{
+ /* Only check this texture if it's been marked as RenderToTexture */
+ if (texObj->_RenderToTexture) {
+ struct cb_info info;
+ info.ctx = ctx;
+ info.texObj = texObj;
+ info.level = level;
+ info.face = face;
+ _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info);
+ }
+}
+
+
+/**
+ * If the texture object's GenerateMipmap flag is set and we've
+ * changed the texture base level image, regenerate the rest of the
+ * mipmap levels now.
+ */
+static INLINE void
+check_gen_mipmap(struct gl_context *ctx, GLenum target,
+ struct gl_texture_object *texObj, GLint level)
+{
+ ASSERT(target != GL_TEXTURE_CUBE_MAP);
+ if (texObj->GenerateMipmap &&
+ level == texObj->BaseLevel &&
+ level < texObj->MaxLevel) {
+ ASSERT(ctx->Driver.GenerateMipmap);
+ ctx->Driver.GenerateMipmap(ctx, target, texObj);
+ }
+}
+
+
+/** Debug helper: override the user-requested internal format */
+static GLenum
+override_internal_format(GLenum internalFormat, GLint width, GLint height)
+{
+#if 0
+ if (internalFormat == GL_RGBA16F_ARB ||
+ internalFormat == GL_RGBA32F_ARB) {
+ printf("Convert rgba float tex to int %d x %d\n", width, height);
+ return GL_RGBA;
+ }
+ else if (internalFormat == GL_RGB16F_ARB ||
+ internalFormat == GL_RGB32F_ARB) {
+ printf("Convert rgb float tex to int %d x %d\n", width, height);
+ return GL_RGB;
+ }
+ else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB ||
+ internalFormat == GL_LUMINANCE_ALPHA32F_ARB) {
+ printf("Convert luminance float tex to int %d x %d\n", width, height);
+ return GL_LUMINANCE_ALPHA;
+ }
+ else if (internalFormat == GL_LUMINANCE16F_ARB ||
+ internalFormat == GL_LUMINANCE32F_ARB) {
+ printf("Convert luminance float tex to int %d x %d\n", width, height);
+ return GL_LUMINANCE;
+ }
+ else if (internalFormat == GL_ALPHA16F_ARB ||
+ internalFormat == GL_ALPHA32F_ARB) {
+ printf("Convert luminance float tex to int %d x %d\n", width, height);
+ return GL_ALPHA;
+ }
+ /*
+ else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
+ internalFormat = GL_RGBA;
+ }
+ */
+ else {
+ return internalFormat;
+ }
+#else
+ return internalFormat;
+#endif
+}
+
+
+/**
+ * Choose the actual hardware format for a texture image.
+ * Try to use the same format as the previous image level when possible.
+ * Otherwise, ask the driver for the best format.
+ * It's important to try to choose a consistant format for all levels
+ * for efficient texture memory layout/allocation. In particular, this
+ * comes up during automatic mipmap generation.
+ */
+gl_format
+_mesa_choose_texture_format(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ GLenum target, GLint level,
+ GLenum internalFormat, GLenum format, GLenum type)
+{
+ gl_format f;
+
+ /* see if we've already chosen a format for the previous level */
+ if (level > 0) {
+ struct gl_texture_image *prevImage =
+ _mesa_select_tex_image(ctx, texObj, target, level - 1);
+ /* See if the prev level is defined and has an internal format which
+ * matches the new internal format.
+ */
+ if (prevImage &&
+ prevImage->Width > 0 &&
+ prevImage->InternalFormat == internalFormat) {
+ /* use the same format */
+ ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE);
+ return prevImage->TexFormat;
+ }
+ }
+
+ /* choose format from scratch */
+ f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
+ ASSERT(f != MESA_FORMAT_NONE);
+ return f;
+}
+
+
+/**
+ * Common code to implement all the glTexImage1D/2D/3D functions.
+ */
+static void
+teximage(struct gl_context *ctx, GLuint dims,
+ GLenum target, GLint level, GLint internalFormat,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLint border, GLenum format, GLenum type,
+ const GLvoid *pixels)
+{
+ GLboolean error;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+ _mesa_debug(ctx, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
+ dims,
+ _mesa_lookup_enum_by_nr(target), level,
+ _mesa_lookup_enum_by_nr(internalFormat),
+ width, height, depth, border,
+ _mesa_lookup_enum_by_nr(format),
+ _mesa_lookup_enum_by_nr(type), pixels);
+
+ internalFormat = override_internal_format(internalFormat, width, height);
+
+ /* target error checking */
+ if (!legal_teximage_target(ctx, dims, target)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%uD(target=%s)",
+ dims, _mesa_lookup_enum_by_nr(target));
+ return;
+ }
+
+ /* general error checking */
+ error = texture_error_check(ctx, dims, target, level, internalFormat,
+ format, type, width, height, depth, border);
+
+ if (_mesa_is_proxy_texture(target)) {
+ /* Proxy texture: just clear or set state depending on error checking */
+ struct gl_texture_image *texImage =
+ _mesa_get_proxy_tex_image(ctx, target, level);
+
+ if (error) {
+ /* when error, clear all proxy texture image parameters */
+ if (texImage)
+ clear_teximage_fields(texImage);
+ }
+ else {
+ /* no error, set the tex image parameters */
+ struct gl_texture_object *texObj =
+ _mesa_get_current_tex_object(ctx, target);
+ gl_format texFormat = _mesa_choose_texture_format(ctx, texObj,
+ target, level,
+ internalFormat,
+ format, type);
+
+ if (legal_texture_size(ctx, texFormat, width, height, depth)) {
+ _mesa_init_teximage_fields(ctx, target, texImage, width, height,
+ depth, border, internalFormat,
+ texFormat);
+ }
+ else if (texImage) {
+ clear_teximage_fields(texImage);
+ }
+ }
+ }
+ else {
+ /* non-proxy target */
+ const GLuint face = _mesa_tex_target_to_face(target);
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+
+ if (error) {
+ return; /* error was recorded */
+ }
+
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
+ _mesa_update_state(ctx);
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+
+ _mesa_lock_texture(ctx, texObj);
+ {
+ texImage = _mesa_get_tex_image(ctx, texObj, target, level);
+
+ if (!texImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims);
+ }
+ else {
+ gl_format texFormat;
+
+ if (texImage->Data) {
+ ctx->Driver.FreeTexImageData( ctx, texImage );
+ }
+
+ ASSERT(texImage->Data == NULL);
+ texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+ internalFormat, format,
+ type);
+
+ if (legal_texture_size(ctx, texFormat, width, height, depth)) {
+ _mesa_init_teximage_fields(ctx, target, texImage,
+ width, height, depth,
+ border, internalFormat, texFormat);
+
+ /* Give the texture to the driver. <pixels> may be null. */
+ ASSERT(ctx->Driver.TexImage3D);
+ switch (dims) {
+ case 1:
+ ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
+ width, border, format,
+ type, pixels, &ctx->Unpack, texObj,
+ texImage);
+ break;
+ case 2:
+ ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
+ width, height, border, format,
+ type, pixels, &ctx->Unpack, texObj,
+ texImage);
+ break;
+ case 3:
+ ctx->Driver.TexImage3D(ctx, target, level, internalFormat,
+ width, height, depth, border, format,
+ type, pixels, &ctx->Unpack, texObj,
+ texImage);
+ break;
+ default:
+ _mesa_problem(ctx, "invalid dims=%u in teximage()", dims);
+ }
+
+ check_gen_mipmap(ctx, target, texObj, level);
+
+ update_fbo_texture(ctx, texObj, face, level);
+
+ /* state update */
+ texObj->_Complete = GL_FALSE;
+ ctx->NewState |= _NEW_TEXTURE;
+ }
+ else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims);
+ }
+ }
+ }
+ _mesa_unlock_texture(ctx, texObj);
+ }
+}
+
+
+/*
+ * Called from the API. Note that width includes the border.
+ */
+void GLAPIENTRY
+_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
+ GLsizei width, GLint border, GLenum format,
+ GLenum type, const GLvoid *pixels )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ teximage(ctx, 1, target, level, internalFormat, width, 1, 1,
+ border, format, type, pixels);
+}
+
+
+void GLAPIENTRY
+_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
+ GLsizei width, GLsizei height, GLint border,
+ GLenum format, GLenum type,
+ const GLvoid *pixels )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ teximage(ctx, 2, target, level, internalFormat, width, height, 1,
+ border, format, type, pixels);
+}
+
+
+/*
+ * Called by the API or display list executor.
+ * Note that width and height include the border.
+ */
+void GLAPIENTRY
+_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLint border, GLenum format, GLenum type,
+ const GLvoid *pixels )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ teximage(ctx, 3, target, level, internalFormat, width, height, depth,
+ border, format, type, pixels);
+}
+
+
+void GLAPIENTRY
+_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLint border, GLenum format, GLenum type,
+ const GLvoid *pixels )
+{
+ _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height,
+ depth, border, format, type, pixels);
+}
+
+
+#if FEATURE_OES_EGL_image
+void GLAPIENTRY
+_mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image)
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (!ctx->Extensions.OES_EGL_image) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glEGLImageTargetTexture2DOES(unsupported)");
+ return;
+ }
+
+ if (target != GL_TEXTURE_2D) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glEGLImageTargetTexture2D(target=%d)", target);
+ return;
+ }
+
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
+ _mesa_update_state(ctx);
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+ _mesa_lock_texture(ctx, texObj);
+
+ texImage = _mesa_get_tex_image(ctx, texObj, target, 0);
+ if (!texImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEGLImageTargetTexture2D");
+ } else {
+ if (texImage->Data)
+ ctx->Driver.FreeTexImageData( ctx, texImage );
+
+ ASSERT(texImage->Data == NULL);
+ ctx->Driver.EGLImageTargetTexture2D(ctx, target,
+ texObj, texImage, image);
+
+ /* state update */
+ texObj->_Complete = GL_FALSE;
+ ctx->NewState |= _NEW_TEXTURE;
+ }
+ _mesa_unlock_texture(ctx, texObj);
+
+}
+#endif
+
+
+
+/**
+ * Implement all the glTexSubImage1/2/3D() functions.
+ */
+static void
+texsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, const GLvoid *pixels )
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+ _mesa_debug(ctx, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
+ dims,
+ _mesa_lookup_enum_by_nr(target), level,
+ xoffset, yoffset, zoffset, width, height, depth,
+ _mesa_lookup_enum_by_nr(format),
+ _mesa_lookup_enum_by_nr(type), pixels);
+
+ /* check target (proxies not allowed) */
+ if (!legal_texsubimage_target(ctx, dims, target)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage%uD(target=%s)",
+ dims, _mesa_lookup_enum_by_nr(target));
+ return;
+ }
+
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
+ _mesa_update_state(ctx);
+
+ if (subtexture_error_check(ctx, dims, target, level, xoffset, yoffset, zoffset,
+ width, height, depth, format, type)) {
+ return; /* error was detected */
+ }
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+
+ _mesa_lock_texture(ctx, texObj);
+ {
+ texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+
+ if (subtexture_error_check2(ctx, dims, target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth,
+ format, type, texImage)) {
+ /* error was recorded */
+ }
+ else if (width > 0 && height > 0 && height > 0) {
+ /* If we have a border, offset=-1 is legal. Bias by border width. */
+ switch (dims) {
+ case 3:
+ zoffset += texImage->Border;
+ /* fall-through */
+ case 2:
+ yoffset += texImage->Border;
+ /* fall-through */
+ case 1:
+ xoffset += texImage->Border;
+ }
+
+ switch (dims) {
+ case 1:
+ ctx->Driver.TexSubImage1D(ctx, target, level,
+ xoffset, width,
+ format, type, pixels,
+ &ctx->Unpack, texObj, texImage );
+ break;
+ case 2:
+ ctx->Driver.TexSubImage2D(ctx, target, level,
+ xoffset, yoffset, width, height,
+ format, type, pixels,
+ &ctx->Unpack, texObj, texImage );
+ break;
+ case 3:
+ ctx->Driver.TexSubImage3D(ctx, target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth,
+ format, type, pixels,
+ &ctx->Unpack, texObj, texImage );
+ break;
+ default:
+ _mesa_problem(ctx, "unexpected dims in subteximage()");
+ }
+
+ check_gen_mipmap(ctx, target, texObj, level);
+
+ ctx->NewState |= _NEW_TEXTURE;
+ }
+ }
+ _mesa_unlock_texture(ctx, texObj);
+}
+
+
+void GLAPIENTRY
+_mesa_TexSubImage1D( GLenum target, GLint level,
+ GLint xoffset, GLsizei width,
+ GLenum format, GLenum type,
+ const GLvoid *pixels )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ texsubimage(ctx, 1, target, level,
+ xoffset, 0, 0,
+ width, 1, 1,
+ format, type, pixels);
+}
+
+
+void GLAPIENTRY
+_mesa_TexSubImage2D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const GLvoid *pixels )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ texsubimage(ctx, 2, target, level,
+ xoffset, yoffset, 0,
+ width, height, 1,
+ format, type, pixels);
+}
+
+
+
+void GLAPIENTRY
+_mesa_TexSubImage3D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type,
+ const GLvoid *pixels )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ texsubimage(ctx, 3, target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth,
+ format, type, pixels);
+}
+
+
+
+/**
+ * Implement the glCopyTexImage1/2D() functions.
+ */
+static void
+copyteximage(struct gl_context *ctx, GLuint dims,
+ GLenum target, GLint level, GLenum internalFormat,
+ GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ const GLuint face = _mesa_tex_target_to_face(target);
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+ _mesa_debug(ctx, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
+ dims,
+ _mesa_lookup_enum_by_nr(target), level,
+ _mesa_lookup_enum_by_nr(internalFormat),
+ x, y, width, height, border);
+
+ if (ctx->NewState & NEW_COPY_TEX_STATE)
+ _mesa_update_state(ctx);
+
+ if (copytexture_error_check(ctx, dims, target, level, internalFormat,
+ width, height, border))
+ return;
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+
+ _mesa_lock_texture(ctx, texObj);
+ {
+ texImage = _mesa_get_tex_image(ctx, texObj, target, level);
+
+ if (!texImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims);
+ }
+ else {
+ gl_format texFormat;
+
+ if (texImage->Data) {
+ ctx->Driver.FreeTexImageData( ctx, texImage );
+ }
+
+ ASSERT(texImage->Data == NULL);
+
+ texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+ internalFormat, GL_NONE,
+ GL_NONE);
+
+ if (legal_texture_size(ctx, texFormat, width, height, 1)) {
+ _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
+ border, internalFormat, texFormat);
+
+ ASSERT(ctx->Driver.CopyTexImage2D);
+ if (dims == 1)
+ ctx->Driver.CopyTexImage1D(ctx, target, level, internalFormat,
+ x, y, width, border);
+ else
+ ctx->Driver.CopyTexImage2D(ctx, target, level, internalFormat,
+ x, y, width, height, border);
+
+ check_gen_mipmap(ctx, target, texObj, level);
+
+ update_fbo_texture(ctx, texObj, face, level);
+
+ /* state update */
+ texObj->_Complete = GL_FALSE;
+ ctx->NewState |= _NEW_TEXTURE;
+ }
+ else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims);
+ }
+ }
+ }
+ _mesa_unlock_texture(ctx, texObj);
+}
+
+
+
+void GLAPIENTRY
+_mesa_CopyTexImage1D( GLenum target, GLint level,
+ GLenum internalFormat,
+ GLint x, GLint y,
+ GLsizei width, GLint border )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ copyteximage(ctx, 1, target, level, internalFormat, x, y, width, 1, border);
+}
+
+
+
+void GLAPIENTRY
+_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ GLint border )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ copyteximage(ctx, 2, target, level, internalFormat,
+ x, y, width, height, border);
+}
+
+
+
+/**
+ * Implementation for glCopyTexSubImage1/2/3D() functions.
+ */
+static void
+copytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height)
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+ _mesa_debug(ctx, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
+ dims,
+ _mesa_lookup_enum_by_nr(target),
+ level, xoffset, yoffset, zoffset, x, y, width, height);
+
+ if (ctx->NewState & NEW_COPY_TEX_STATE)
+ _mesa_update_state(ctx);
+
+ if (copytexsubimage_error_check1(ctx, dims, target, level))
+ return;
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+
+ _mesa_lock_texture(ctx, texObj);
+ {
+ texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+
+ if (copytexsubimage_error_check2(ctx, dims, target, level, xoffset, yoffset,
+ zoffset, width, height, texImage)) {
+ /* error was recored */
+ }
+ else {
+ /* If we have a border, offset=-1 is legal. Bias by border width. */
+ switch (dims) {
+ case 3:
+ zoffset += texImage->Border;
+ /* fall-through */
+ case 2:
+ yoffset += texImage->Border;
+ /* fall-through */
+ case 1:
+ xoffset += texImage->Border;
+ }
+
+ if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y,
+ &width, &height)) {
+ switch (dims) {
+ case 1:
+ ctx->Driver.CopyTexSubImage1D(ctx, target, level,
+ xoffset, x, y, width);
+ break;
+ case 2:
+ ctx->Driver.CopyTexSubImage2D(ctx, target, level,
+ xoffset, yoffset,
+ x, y, width, height);
+ break;
+ case 3:
+ ctx->Driver.CopyTexSubImage3D(ctx, target, level,
+ xoffset, yoffset, zoffset,
+ x, y, width, height);
+ break;
+ default:
+ _mesa_problem(ctx, "bad dims in copytexsubimage()");
+ }
+
+ check_gen_mipmap(ctx, target, texObj, level);
+
+ ctx->NewState |= _NEW_TEXTURE;
+ }
+ }
+ }
+ _mesa_unlock_texture(ctx, texObj);
+}
+
+
+void GLAPIENTRY
+_mesa_CopyTexSubImage1D( GLenum target, GLint level,
+ GLint xoffset, GLint x, GLint y, GLsizei width )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ copytexsubimage(ctx, 1, target, level, xoffset, 0, 0, x, y, width, 1);
+}
+
+
+
+void GLAPIENTRY
+_mesa_CopyTexSubImage2D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ copytexsubimage(ctx, 2, target, level, xoffset, yoffset, 0, x, y,
+ width, height);
+}
+
+
+
+void GLAPIENTRY
+_mesa_CopyTexSubImage3D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ copytexsubimage(ctx, 3, target, level, xoffset, yoffset, zoffset,
+ x, y, width, height);
+}
+
+
+
+
+/**********************************************************************/
+/****** Compressed Textures ******/
+/**********************************************************************/
+
+
+/**
+ * Return expected size of a compressed texture.
+ */
+static GLuint
+compressed_tex_size(GLsizei width, GLsizei height, GLsizei depth,
+ GLenum glformat)
+{
+ gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
+ return _mesa_format_image_size(mesaFormat, width, height, depth);
+}
+
+
+/*
+ * Return compressed texture block size, in pixels.
+ */
+static void
+get_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh)
+{
+ gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
+ _mesa_get_format_block_size(mesaFormat, bw, bh);
+}
+
+
+/**
+ * Error checking for glCompressedTexImage[123]D().
+ * \return error code or GL_NO_ERROR.
+ */
+static GLenum
+compressed_texture_error_check(struct gl_context *ctx, GLint dimensions,
+ GLenum target, GLint level,
+ GLenum internalFormat, GLsizei width,
+ GLsizei height, GLsizei depth, GLint border,
+ GLsizei imageSize)
+{
+ const GLenum proxyTarget = get_proxy_target(target);
+ const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
+ GLint expectedSize;
+
+ /* check level */
+ if (level < 0 || level >= maxLevels)
+ return GL_INVALID_VALUE;
+
+ if (!target_can_be_compressed(ctx, target, internalFormat)) {
+ return GL_INVALID_ENUM;
+ }
+
+ /* This will detect any invalid internalFormat value */
+ if (!_mesa_is_compressed_format(ctx, internalFormat))
+ return GL_INVALID_ENUM;
+
+ /* This should really never fail */
+ if (_mesa_base_tex_format(ctx, internalFormat) < 0)
+ return GL_INVALID_ENUM;
+
+ /* No compressed formats support borders at this time */
+ if (border != 0)
+ return GL_INVALID_VALUE;
+
+ /* For cube map, width must equal height */
+ if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
+ target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height)
+ return GL_INVALID_VALUE;
+
+ /* check image size against compression block size */
+ {
+ gl_format texFormat =
+ ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
+ GL_NONE, GL_NONE);
+ GLuint bw, bh;
+
+ _mesa_get_format_block_size(texFormat, &bw, &bh);
+ if ((width > bw && width % bw > 0) ||
+ (height > bh && height % bh > 0)) {
+ /*
+ * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
+ * generated [...] if any parameter combinations are not
+ * supported by the specific compressed internal format.
+ */
+ return GL_INVALID_OPERATION;
+ }
+ }
+
+ /* check image sizes */
+ if (!ctx->Driver.TestProxyTexImage(ctx, proxyTarget, level,
+ internalFormat, GL_NONE, GL_NONE,
+ width, height, depth, border)) {
+ /* See error comment above */
+ return GL_INVALID_OPERATION;
+ }
+
+ /* check image size in bytes */
+ expectedSize = compressed_tex_size(width, height, depth, internalFormat);
+ if (expectedSize != imageSize) {
+ /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
+ * if <imageSize> is not consistent with the format, dimensions, and
+ * contents of the specified image.
+ */
+ return GL_INVALID_VALUE;
+ }
+
+ return GL_NO_ERROR;
+}
+
+
+/**
+ * Error checking for glCompressedTexSubImage[123]D().
+ * \warning There are some bad assumptions here about the size of compressed
+ * texture tiles (multiple of 4) used to test the validity of the
+ * offset and size parameters.
+ * \return error code or GL_NO_ERROR.
+ */
+static GLenum
+compressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLsizei imageSize)
+{
+ GLint expectedSize, maxLevels = 0, maxTextureSize;
+ GLuint bw, bh;
+ (void) zoffset;
+
+ if (dimensions == 1) {
+ /* 1D compressed textures not allowed */
+ return GL_INVALID_ENUM;
+ }
+ else if (dimensions == 2) {
+ if (target == GL_PROXY_TEXTURE_2D) {
+ maxLevels = ctx->Const.MaxTextureLevels;
+ }
+ else if (target == GL_TEXTURE_2D) {
+ maxLevels = ctx->Const.MaxTextureLevels;
+ }
+ else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
+ if (!ctx->Extensions.ARB_texture_cube_map)
+ return GL_INVALID_ENUM; /*target*/
+ maxLevels = ctx->Const.MaxCubeTextureLevels;
+ }
+ else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
+ target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
+ if (!ctx->Extensions.ARB_texture_cube_map)
+ return GL_INVALID_ENUM; /*target*/
+ maxLevels = ctx->Const.MaxCubeTextureLevels;
+ }
+ else {
+ return GL_INVALID_ENUM; /*target*/
+ }
+ }
+ else if (dimensions == 3) {
+ /* 3D compressed textures not allowed */
+ return GL_INVALID_ENUM;
+ }
+
+ maxTextureSize = 1 << (maxLevels - 1);
+
+ /* this will catch any invalid compressed format token */
+ if (!_mesa_is_compressed_format(ctx, format))
+ return GL_INVALID_ENUM;
+
+ if (width < 1 || width > maxTextureSize)
+ return GL_INVALID_VALUE;
+
+ if ((height < 1 || height > maxTextureSize)
+ && dimensions > 1)
+ return GL_INVALID_VALUE;
+
+ if (level < 0 || level >= maxLevels)
+ return GL_INVALID_VALUE;
+
+ /*
+ * do checks which depend on compression block size
+ */
+ get_compressed_block_size(format, &bw, &bh);
+
+ if ((xoffset % bw != 0) || (yoffset % bh != 0))
+ return GL_INVALID_VALUE;
+
+ if ((width % bw != 0) && width != 2 && width != 1)
+ return GL_INVALID_VALUE;
+
+ if ((height % bh != 0) && height != 2 && height != 1)
+ return GL_INVALID_VALUE;
+
+ expectedSize = compressed_tex_size(width, height, depth, format);
+ if (expectedSize != imageSize)
+ return GL_INVALID_VALUE;
+
+ return GL_NO_ERROR;
+}
+
+
+/**
+ * Do second part of glCompressedTexSubImage error checking.
+ * \return GL_TRUE if error found, GL_FALSE otherwise.
+ */
+static GLboolean
+compressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims,
+ GLsizei width, GLsizei height,
+ GLsizei depth, GLenum format,
+ struct gl_texture_image *texImage)
+{
+
+ if ((GLint) format != texImage->InternalFormat) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glCompressedTexSubImage%uD(format=0x%x)", dims, format);
+ return GL_TRUE;
+ }
+
+ if (((width == 1 || width == 2) &&
+ width != (GLsizei) texImage->Width) ||
+ (width > (GLsizei) texImage->Width)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCompressedTexSubImage%uD(width=%d)", dims, width);
+ return GL_TRUE;
+ }
+
+ if (dims >= 2) {
+ if (((height == 1 || height == 2) &&
+ height != (GLsizei) texImage->Height) ||
+ (height > (GLsizei) texImage->Height)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCompressedTexSubImage%uD(height=%d)", dims, height);
+ return GL_TRUE;
+ }
+ }
+
+ if (dims >= 3) {
+ if (((depth == 1 || depth == 2) &&
+ depth != (GLsizei) texImage->Depth) ||
+ (depth > (GLsizei) texImage->Depth)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCompressedTexSubImage%uD(depth=%d)", dims, depth);
+ return GL_TRUE;
+ }
+ }
+
+ return GL_FALSE;
+}
+
+
+/**
+ * Implementation of the glCompressedTexImage1/2/3D() functions.
+ */
+static void
+compressedteximage(struct gl_context *ctx, GLuint dims,
+ GLenum target, GLint level,
+ GLenum internalFormat, GLsizei width,
+ GLsizei height, GLsizei depth, GLint border,
+ GLsizei imageSize, const GLvoid *data)
+{
+ GLenum error;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+ _mesa_debug(ctx,
+ "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
+ dims,
+ _mesa_lookup_enum_by_nr(target), level,
+ _mesa_lookup_enum_by_nr(internalFormat),
+ width, height, depth, border, imageSize, data);
+
+ /* check target */
+ if (!legal_teximage_target(ctx, dims, target)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage%uD(target=%s)",
+ dims, _mesa_lookup_enum_by_nr(target));
+ return;
+ }
+
+ error = compressed_texture_error_check(ctx, dims, target, level,
+ internalFormat, width, height, depth,
+ border, imageSize);
+
+#if FEATURE_ES
+ /* XXX this is kind of a hack */
+ if (error) {
+ _mesa_error(ctx, error, "glTexImage2D");
+ return;
+ }
+
+ if (dims == 2) {
+ switch (internalFormat) {
+ case GL_PALETTE4_RGB8_OES:
+ case GL_PALETTE4_RGBA8_OES:
+ case GL_PALETTE4_R5_G6_B5_OES:
+ case GL_PALETTE4_RGBA4_OES:
+ case GL_PALETTE4_RGB5_A1_OES:
+ case GL_PALETTE8_RGB8_OES:
+ case GL_PALETTE8_RGBA8_OES:
+ case GL_PALETTE8_R5_G6_B5_OES:
+ case GL_PALETTE8_RGBA4_OES:
+ case GL_PALETTE8_RGB5_A1_OES:
+ _mesa_cpal_compressed_teximage2d(target, level, internalFormat,
+ width, height, imageSize, data);
+ return;
+ }
+ }
+#endif
+
+ if (_mesa_is_proxy_texture(target)) {
+ /* Proxy texture: just check for errors and update proxy state */
+ struct gl_texture_image *texImage;
+
+ if (!error) {
+ struct gl_texture_object *texObj =
+ _mesa_get_current_tex_object(ctx, target);
+ gl_format texFormat =
+ _mesa_choose_texture_format(ctx, texObj, target, level,
+ internalFormat, GL_NONE, GL_NONE);
+ if (!legal_texture_size(ctx, texFormat, width, height, depth)) {
+ error = GL_OUT_OF_MEMORY;
+ }
+ }
+
+ texImage = _mesa_get_proxy_tex_image(ctx, target, level);
+ if (texImage) {
+ if (error) {
+ /* if error, clear all proxy texture image parameters */
+ clear_teximage_fields(texImage);
+ }
+ else {
+ /* no error: store the teximage parameters */
+ _mesa_init_teximage_fields(ctx, target, texImage, width, height,
+ depth, border, internalFormat,
+ MESA_FORMAT_NONE);
+ }
+ }
+ }
+ else {
+ /* non-proxy target */
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+
+ if (error) {
+ _mesa_error(ctx, error, "glCompressedTexImage%uD", dims);
+ return;
+ }
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+
+ _mesa_lock_texture(ctx, texObj);
+ {
+ texImage = _mesa_get_tex_image(ctx, texObj, target, level);
+ if (!texImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY,
+ "glCompressedTexImage%uD", dims);
+ }
+ else {
+ gl_format texFormat;
+
+ if (texImage->Data) {
+ ctx->Driver.FreeTexImageData( ctx, texImage );
+ }
+ ASSERT(texImage->Data == NULL);
+
+ texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+ internalFormat, GL_NONE,
+ GL_NONE);
+
+ if (legal_texture_size(ctx, texFormat, width, height, depth)) {
+ _mesa_init_teximage_fields(ctx, target, texImage,
+ width, height, depth,
+ border, internalFormat, texFormat);
+
+ switch (dims) {
+ case 1:
+ ASSERT(ctx->Driver.CompressedTexImage1D);
+ ctx->Driver.CompressedTexImage1D(ctx, target, level,
+ internalFormat,
+ width,
+ border, imageSize, data,
+ texObj, texImage);
+ break;
+ case 2:
+ ASSERT(ctx->Driver.CompressedTexImage2D);
+ ctx->Driver.CompressedTexImage2D(ctx, target, level,
+ internalFormat,
+ width, height,
+ border, imageSize, data,
+ texObj, texImage);
+ break;
+ case 3:
+ ASSERT(ctx->Driver.CompressedTexImage3D);
+ ctx->Driver.CompressedTexImage3D(ctx, target, level,
+ internalFormat,
+ width, height, depth,
+ border, imageSize, data,
+ texObj, texImage);
+ break;
+ default:
+ _mesa_problem(ctx, "bad dims in compressedteximage");
+ }
+
+ check_gen_mipmap(ctx, target, texObj, level);
+
+ /* state update */
+ texObj->_Complete = GL_FALSE;
+ ctx->NewState |= _NEW_TEXTURE;
+ }
+ else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY,
+ "glCompressedTexImage%uD", dims);
+ }
+ }
+ }
+ _mesa_unlock_texture(ctx, texObj);
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_CompressedTexImage1DARB(GLenum target, GLint level,
+ GLenum internalFormat, GLsizei width,
+ GLint border, GLsizei imageSize,
+ const GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ compressedteximage(ctx, 1, target, level, internalFormat,
+ width, 1, 1, border, imageSize, data);
+}
+
+
+void GLAPIENTRY
+_mesa_CompressedTexImage2DARB(GLenum target, GLint level,
+ GLenum internalFormat, GLsizei width,
+ GLsizei height, GLint border, GLsizei imageSize,
+ const GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ compressedteximage(ctx, 2, target, level, internalFormat,
+ width, height, 1, border, imageSize, data);
+}
+
+
+void GLAPIENTRY
+_mesa_CompressedTexImage3DARB(GLenum target, GLint level,
+ GLenum internalFormat, GLsizei width,
+ GLsizei height, GLsizei depth, GLint border,
+ GLsizei imageSize, const GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ compressedteximage(ctx, 3, target, level, internalFormat,
+ width, height, depth, border, imageSize, data);
+}
+
+
+/**
+ * Common helper for glCompressedTexSubImage1/2/3D().
+ */
+static void
+compressed_tex_sub_image(GLuint dims, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLsizei imageSize, const GLvoid *data)
+{
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ GLenum error;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ error = compressed_subtexture_error_check(ctx, dims, target, level,
+ xoffset, 0, 0, /* pos */
+ width, height, depth, /* size */
+ format, imageSize);
+ if (error) {
+ _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims);
+ return;
+ }
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+
+ _mesa_lock_texture(ctx, texObj);
+ {
+ texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+ assert(texImage);
+
+ if (compressed_subtexture_error_check2(ctx, dims, width, height, depth,
+ format, texImage)) {
+ /* error was recorded */
+ }
+ else if (width > 0 && height > 0 && depth > 0) {
+ switch (dims) {
+ case 1:
+ if (ctx->Driver.CompressedTexSubImage1D) {
+ ctx->Driver.CompressedTexSubImage1D(ctx, target, level,
+ xoffset, width,
+ format, imageSize, data,
+ texObj, texImage);
+ }
+ break;
+ case 2:
+ if (ctx->Driver.CompressedTexSubImage2D) {
+ ctx->Driver.CompressedTexSubImage2D(ctx, target, level,
+ xoffset, yoffset,
+ width, height,
+ format, imageSize, data,
+ texObj, texImage);
+ }
+ break;
+ case 3:
+ if (ctx->Driver.CompressedTexSubImage3D) {
+ ctx->Driver.CompressedTexSubImage3D(ctx, target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth,
+ format, imageSize, data,
+ texObj, texImage);
+ }
+ break;
+ default:
+ ;
+ }
+
+ check_gen_mipmap(ctx, target, texObj, level);
+
+ ctx->NewState |= _NEW_TEXTURE;
+ }
+ }
+ _mesa_unlock_texture(ctx, texObj);
+}
+
+
+void GLAPIENTRY
+_mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
+ GLsizei width, GLenum format,
+ GLsizei imageSize, const GLvoid *data)
+{
+ compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1,
+ format, imageSize, data);
+}
+
+
+void GLAPIENTRY
+_mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
+ GLint yoffset, GLsizei width, GLsizei height,
+ GLenum format, GLsizei imageSize,
+ const GLvoid *data)
+{
+ compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0,
+ width, height, 1, format, imageSize, data);
+}
+
+
+void GLAPIENTRY
+_mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
+ GLint yoffset, GLint zoffset, GLsizei width,
+ GLsizei height, GLsizei depth, GLenum format,
+ GLsizei imageSize, const GLvoid *data)
+{
+ compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset,
+ width, height, depth, format, imageSize, data);
+}
diff --git a/mesalib/src/mesa/main/texstate.c b/mesalib/src/mesa/main/texstate.c
index 41d531f59..40282eabf 100644
--- a/mesalib/src/mesa/main/texstate.c
+++ b/mesalib/src/mesa/main/texstate.c
@@ -1,841 +1,841 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.5
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file texstate.c
- *
- * Texture state handling.
- */
-
-#include "glheader.h"
-#include "mfeatures.h"
-#include "colormac.h"
-#include "colortab.h"
-#include "context.h"
-#include "enums.h"
-#include "macros.h"
-#include "texobj.h"
-#include "teximage.h"
-#include "texstate.h"
-#include "mtypes.h"
-
-
-
-/**
- * Default texture combine environment state. This is used to initialize
- * a context's texture units and as the basis for converting "classic"
- * texture environmnets to ARB_texture_env_combine style values.
- */
-static const struct gl_tex_env_combine_state default_combine_state = {
- GL_MODULATE, GL_MODULATE,
- { GL_TEXTURE, GL_PREVIOUS, GL_CONSTANT, GL_CONSTANT },
- { GL_TEXTURE, GL_PREVIOUS, GL_CONSTANT, GL_CONSTANT },
- { GL_SRC_COLOR, GL_SRC_COLOR, GL_SRC_ALPHA, GL_SRC_ALPHA },
- { GL_SRC_ALPHA, GL_SRC_ALPHA, GL_SRC_ALPHA, GL_SRC_ALPHA },
- 0, 0,
- 2, 2
-};
-
-
-
-/**
- * Used by glXCopyContext to copy texture state from one context to another.
- */
-void
-_mesa_copy_texture_state( const struct gl_context *src, struct gl_context *dst )
-{
- GLuint u, tex;
-
- ASSERT(src);
- ASSERT(dst);
-
- dst->Texture.CurrentUnit = src->Texture.CurrentUnit;
- dst->Texture._GenFlags = src->Texture._GenFlags;
- dst->Texture._TexGenEnabled = src->Texture._TexGenEnabled;
- dst->Texture._TexMatEnabled = src->Texture._TexMatEnabled;
- dst->Texture.SharedPalette = src->Texture.SharedPalette;
-
- /* per-unit state */
- for (u = 0; u < src->Const.MaxCombinedTextureImageUnits; u++) {
- dst->Texture.Unit[u].Enabled = src->Texture.Unit[u].Enabled;
- dst->Texture.Unit[u].EnvMode = src->Texture.Unit[u].EnvMode;
- COPY_4V(dst->Texture.Unit[u].EnvColor, src->Texture.Unit[u].EnvColor);
- dst->Texture.Unit[u].TexGenEnabled = src->Texture.Unit[u].TexGenEnabled;
- dst->Texture.Unit[u].GenS = src->Texture.Unit[u].GenS;
- dst->Texture.Unit[u].GenT = src->Texture.Unit[u].GenT;
- dst->Texture.Unit[u].GenR = src->Texture.Unit[u].GenR;
- dst->Texture.Unit[u].GenQ = src->Texture.Unit[u].GenQ;
- dst->Texture.Unit[u].LodBias = src->Texture.Unit[u].LodBias;
-
- /* GL_EXT_texture_env_combine */
- dst->Texture.Unit[u].Combine = src->Texture.Unit[u].Combine;
-
- /* GL_ATI_envmap_bumpmap - need this? */
- dst->Texture.Unit[u].BumpTarget = src->Texture.Unit[u].BumpTarget;
- COPY_4V(dst->Texture.Unit[u].RotMatrix, src->Texture.Unit[u].RotMatrix);
-
- /*
- * XXX strictly speaking, we should compare texture names/ids and
- * bind textures in the dest context according to id. For now, only
- * copy bindings if the contexts share the same pool of textures to
- * avoid refcounting bugs.
- */
- if (dst->Shared == src->Shared) {
- /* copy texture object bindings, not contents of texture objects */
- _mesa_lock_context_textures(dst);
-
- for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
- _mesa_reference_texobj(&dst->Texture.Unit[u].CurrentTex[tex],
- src->Texture.Unit[u].CurrentTex[tex]);
- }
- _mesa_unlock_context_textures(dst);
- }
- }
-}
-
-
-/*
- * For debugging
- */
-void
-_mesa_print_texunit_state( struct gl_context *ctx, GLuint unit )
-{
- const struct gl_texture_unit *texUnit = ctx->Texture.Unit + unit;
- printf("Texture Unit %d\n", unit);
- printf(" GL_TEXTURE_ENV_MODE = %s\n", _mesa_lookup_enum_by_nr(texUnit->EnvMode));
- printf(" GL_COMBINE_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.ModeRGB));
- printf(" GL_COMBINE_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.ModeA));
- printf(" GL_SOURCE0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[0]));
- printf(" GL_SOURCE1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[1]));
- printf(" GL_SOURCE2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[2]));
- printf(" GL_SOURCE0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[0]));
- printf(" GL_SOURCE1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[1]));
- printf(" GL_SOURCE2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[2]));
- printf(" GL_OPERAND0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[0]));
- printf(" GL_OPERAND1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[1]));
- printf(" GL_OPERAND2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[2]));
- printf(" GL_OPERAND0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[0]));
- printf(" GL_OPERAND1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[1]));
- printf(" GL_OPERAND2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[2]));
- printf(" GL_RGB_SCALE = %d\n", 1 << texUnit->Combine.ScaleShiftRGB);
- printf(" GL_ALPHA_SCALE = %d\n", 1 << texUnit->Combine.ScaleShiftA);
- printf(" GL_TEXTURE_ENV_COLOR = (%f, %f, %f, %f)\n", texUnit->EnvColor[0], texUnit->EnvColor[1], texUnit->EnvColor[2], texUnit->EnvColor[3]);
-}
-
-
-
-/**********************************************************************/
-/* Texture Environment */
-/**********************************************************************/
-
-/**
- * Convert "classic" texture environment to ARB_texture_env_combine style
- * environments.
- *
- * \param state texture_env_combine state vector to be filled-in.
- * \param mode Classic texture environment mode (i.e., \c GL_REPLACE,
- * \c GL_BLEND, \c GL_DECAL, etc.).
- * \param texBaseFormat Base format of the texture associated with the
- * texture unit.
- */
-static void
-calculate_derived_texenv( struct gl_tex_env_combine_state *state,
- GLenum mode, GLenum texBaseFormat )
-{
- GLenum mode_rgb;
- GLenum mode_a;
-
- *state = default_combine_state;
-
- switch (texBaseFormat) {
- case GL_ALPHA:
- state->SourceRGB[0] = GL_PREVIOUS;
- break;
-
- case GL_LUMINANCE_ALPHA:
- case GL_INTENSITY:
- case GL_RGBA:
- break;
-
- case GL_LUMINANCE:
- case GL_RED:
- case GL_RG:
- case GL_RGB:
- case GL_YCBCR_MESA:
- case GL_DUDV_ATI:
- state->SourceA[0] = GL_PREVIOUS;
- break;
-
- default:
- _mesa_problem(NULL,
- "Invalid texBaseFormat 0x%x in calculate_derived_texenv",
- texBaseFormat);
- return;
- }
-
- if (mode == GL_REPLACE_EXT)
- mode = GL_REPLACE;
-
- switch (mode) {
- case GL_REPLACE:
- case GL_MODULATE:
- mode_rgb = (texBaseFormat == GL_ALPHA) ? GL_REPLACE : mode;
- mode_a = mode;
- break;
-
- case GL_DECAL:
- mode_rgb = GL_INTERPOLATE;
- mode_a = GL_REPLACE;
-
- state->SourceA[0] = GL_PREVIOUS;
-
- /* Having alpha / luminance / intensity textures replace using the
- * incoming fragment color matches the definition in NV_texture_shader.
- * The 1.5 spec simply marks these as "undefined".
- */
- switch (texBaseFormat) {
- case GL_ALPHA:
- case GL_LUMINANCE:
- case GL_LUMINANCE_ALPHA:
- case GL_INTENSITY:
- state->SourceRGB[0] = GL_PREVIOUS;
- break;
- case GL_RED:
- case GL_RG:
- case GL_RGB:
- case GL_YCBCR_MESA:
- case GL_DUDV_ATI:
- mode_rgb = GL_REPLACE;
- break;
- case GL_RGBA:
- state->SourceRGB[2] = GL_TEXTURE;
- break;
- }
- break;
-
- case GL_BLEND:
- mode_rgb = GL_INTERPOLATE;
- mode_a = GL_MODULATE;
-
- switch (texBaseFormat) {
- case GL_ALPHA:
- mode_rgb = GL_REPLACE;
- break;
- case GL_INTENSITY:
- mode_a = GL_INTERPOLATE;
- state->SourceA[0] = GL_CONSTANT;
- state->OperandA[2] = GL_SRC_ALPHA;
- /* FALLTHROUGH */
- case GL_LUMINANCE:
- case GL_RED:
- case GL_RG:
- case GL_RGB:
- case GL_LUMINANCE_ALPHA:
- case GL_RGBA:
- case GL_YCBCR_MESA:
- case GL_DUDV_ATI:
- state->SourceRGB[2] = GL_TEXTURE;
- state->SourceA[2] = GL_TEXTURE;
- state->SourceRGB[0] = GL_CONSTANT;
- state->OperandRGB[2] = GL_SRC_COLOR;
- break;
- }
- break;
-
- case GL_ADD:
- mode_rgb = (texBaseFormat == GL_ALPHA) ? GL_REPLACE : GL_ADD;
- mode_a = (texBaseFormat == GL_INTENSITY) ? GL_ADD : GL_MODULATE;
- break;
-
- default:
- _mesa_problem(NULL,
- "Invalid texture env mode 0x%x in calculate_derived_texenv",
- mode);
- return;
- }
-
- state->ModeRGB = (state->SourceRGB[0] != GL_PREVIOUS)
- ? mode_rgb : GL_REPLACE;
- state->ModeA = (state->SourceA[0] != GL_PREVIOUS)
- ? mode_a : GL_REPLACE;
-}
-
-
-
-
-/* GL_ARB_multitexture */
-void GLAPIENTRY
-_mesa_ActiveTextureARB(GLenum texture)
-{
- const GLuint texUnit = texture - GL_TEXTURE0;
- GLuint k;
- GET_CURRENT_CONTEXT(ctx);
-
- /* See OpenGL spec for glActiveTexture: */
- k = MAX2(ctx->Const.MaxCombinedTextureImageUnits,
- ctx->Const.MaxTextureCoordUnits);
-
- ASSERT(k <= Elements(ctx->Texture.Unit));
-
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
- _mesa_debug(ctx, "glActiveTexture %s\n",
- _mesa_lookup_enum_by_nr(texture));
-
- if (texUnit >= k) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glActiveTexture(texture=%s)",
- _mesa_lookup_enum_by_nr(texture));
- return;
- }
-
- if (ctx->Texture.CurrentUnit == texUnit)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-
- ctx->Texture.CurrentUnit = texUnit;
- if (ctx->Transform.MatrixMode == GL_TEXTURE) {
- /* update current stack pointer */
- ctx->CurrentStack = &ctx->TextureMatrixStack[texUnit];
- }
-}
-
-
-/* GL_ARB_multitexture */
-void GLAPIENTRY
-_mesa_ClientActiveTextureARB(GLenum texture)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint texUnit = texture - GL_TEXTURE0;
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE))
- _mesa_debug(ctx, "glClientActiveTexture %s\n",
- _mesa_lookup_enum_by_nr(texture));
-
- if (texUnit >= ctx->Const.MaxTextureCoordUnits) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glClientActiveTexture(texture)");
- return;
- }
-
- if (ctx->Array.ActiveTexture == texUnit)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_ARRAY);
- ctx->Array.ActiveTexture = texUnit;
-}
-
-
-
-/**********************************************************************/
-/***** State management *****/
-/**********************************************************************/
-
-
-/**
- * \note This routine refers to derived texture attribute values to
- * compute the ENABLE_TEXMAT flags, but is only called on
- * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
- * flags are updated by _mesa_update_textures(), below.
- *
- * \param ctx GL context.
- */
-static void
-update_texture_matrices( struct gl_context *ctx )
-{
- GLuint u;
-
- ctx->Texture._TexMatEnabled = 0x0;
-
- for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) {
- ASSERT(u < Elements(ctx->TextureMatrixStack));
- if (_math_matrix_is_dirty(ctx->TextureMatrixStack[u].Top)) {
- _math_matrix_analyse( ctx->TextureMatrixStack[u].Top );
-
- if (ctx->Texture.Unit[u]._ReallyEnabled &&
- ctx->TextureMatrixStack[u].Top->type != MATRIX_IDENTITY)
- ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(u);
- }
- }
-}
-
-
-/**
- * Examine texture unit's combine/env state to update derived state.
- */
-static void
-update_tex_combine(struct gl_context *ctx, struct gl_texture_unit *texUnit)
-{
- struct gl_tex_env_combine_state *combine;
-
- /* Set the texUnit->_CurrentCombine field to point to the user's combiner
- * state, or the combiner state which is derived from traditional texenv
- * mode.
- */
- if (texUnit->EnvMode == GL_COMBINE ||
- texUnit->EnvMode == GL_COMBINE4_NV) {
- texUnit->_CurrentCombine = & texUnit->Combine;
- }
- else {
- const struct gl_texture_object *texObj = texUnit->_Current;
- GLenum format = texObj->Image[0][texObj->BaseLevel]->_BaseFormat;
- if (format == GL_COLOR_INDEX) {
- format = GL_RGBA; /* a bit of a hack */
- }
- else if (format == GL_DEPTH_COMPONENT ||
- format == GL_DEPTH_STENCIL_EXT) {
- format = texObj->DepthMode;
- }
- calculate_derived_texenv(&texUnit->_EnvMode, texUnit->EnvMode, format);
- texUnit->_CurrentCombine = & texUnit->_EnvMode;
- }
-
- combine = texUnit->_CurrentCombine;
-
- /* Determine number of source RGB terms in the combiner function */
- switch (combine->ModeRGB) {
- case GL_REPLACE:
- combine->_NumArgsRGB = 1;
- break;
- case GL_ADD:
- case GL_ADD_SIGNED:
- if (texUnit->EnvMode == GL_COMBINE4_NV)
- combine->_NumArgsRGB = 4;
- else
- combine->_NumArgsRGB = 2;
- break;
- case GL_MODULATE:
- case GL_SUBTRACT:
- case GL_DOT3_RGB:
- case GL_DOT3_RGBA:
- case GL_DOT3_RGB_EXT:
- case GL_DOT3_RGBA_EXT:
- combine->_NumArgsRGB = 2;
- break;
- case GL_INTERPOLATE:
- case GL_MODULATE_ADD_ATI:
- case GL_MODULATE_SIGNED_ADD_ATI:
- case GL_MODULATE_SUBTRACT_ATI:
- combine->_NumArgsRGB = 3;
- break;
- case GL_BUMP_ENVMAP_ATI:
- /* no real arguments for this case */
- combine->_NumArgsRGB = 0;
- break;
- default:
- combine->_NumArgsRGB = 0;
- _mesa_problem(ctx, "invalid RGB combine mode in update_texture_state");
- return;
- }
-
- /* Determine number of source Alpha terms in the combiner function */
- switch (combine->ModeA) {
- case GL_REPLACE:
- combine->_NumArgsA = 1;
- break;
- case GL_ADD:
- case GL_ADD_SIGNED:
- if (texUnit->EnvMode == GL_COMBINE4_NV)
- combine->_NumArgsA = 4;
- else
- combine->_NumArgsA = 2;
- break;
- case GL_MODULATE:
- case GL_SUBTRACT:
- combine->_NumArgsA = 2;
- break;
- case GL_INTERPOLATE:
- case GL_MODULATE_ADD_ATI:
- case GL_MODULATE_SIGNED_ADD_ATI:
- case GL_MODULATE_SUBTRACT_ATI:
- combine->_NumArgsA = 3;
- break;
- default:
- combine->_NumArgsA = 0;
- _mesa_problem(ctx, "invalid Alpha combine mode in update_texture_state");
- break;
- }
-}
-
-
-/**
- * \note This routine refers to derived texture matrix values to
- * compute the ENABLE_TEXMAT flags, but is only called on
- * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
- * flags are updated by _mesa_update_texture_matrices, above.
- *
- * \param ctx GL context.
- */
-static void
-update_texture_state( struct gl_context *ctx )
-{
- GLuint unit;
- struct gl_fragment_program *fprog = NULL;
- struct gl_vertex_program *vprog = NULL;
- GLbitfield enabledFragUnits = 0x0;
-
- if (ctx->Shader.CurrentVertexProgram &&
- ctx->Shader.CurrentVertexProgram->LinkStatus) {
- vprog = ctx->Shader.CurrentVertexProgram->VertexProgram;
- } else if (ctx->VertexProgram._Enabled) {
- /* XXX enable this if/when non-shader vertex programs get
- * texture fetches:
- vprog = ctx->VertexProgram.Current;
- */
- }
-
- if (ctx->Shader.CurrentFragmentProgram &&
- ctx->Shader.CurrentFragmentProgram->LinkStatus) {
- fprog = ctx->Shader.CurrentFragmentProgram->FragmentProgram;
- }
- else if (ctx->FragmentProgram._Enabled) {
- fprog = ctx->FragmentProgram.Current;
- }
-
- /* FINISHME: Geometry shader texture accesses should also be considered
- * FINISHME: here.
- */
-
- /* TODO: only set this if there are actual changes */
- ctx->NewState |= _NEW_TEXTURE;
-
- ctx->Texture._EnabledUnits = 0x0;
- ctx->Texture._GenFlags = 0x0;
- ctx->Texture._TexMatEnabled = 0x0;
- ctx->Texture._TexGenEnabled = 0x0;
-
- /*
- * Update texture unit state.
- */
- for (unit = 0; unit < ctx->Const.MaxCombinedTextureImageUnits; unit++) {
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
- GLbitfield enabledVertTargets = 0x0;
- GLbitfield enabledFragTargets = 0x0;
- GLbitfield enabledTargets = 0x0;
- GLuint texIndex;
-
- /* Get the bitmask of texture target enables.
- * enableBits will be a mask of the TEXTURE_*_BIT flags indicating
- * which texture targets are enabled (fixed function) or referenced
- * by a fragment program/program. When multiple flags are set, we'll
- * settle on the one with highest priority (see below).
- */
- if (vprog) {
- enabledVertTargets |= vprog->Base.TexturesUsed[unit];
- }
-
- if (fprog) {
- enabledFragTargets |= fprog->Base.TexturesUsed[unit];
- }
- else {
- /* fixed-function fragment program */
- enabledFragTargets |= texUnit->Enabled;
- }
-
- enabledTargets = enabledVertTargets | enabledFragTargets;
-
- texUnit->_ReallyEnabled = 0x0;
-
- if (enabledTargets == 0x0) {
- /* neither vertex nor fragment processing uses this unit */
- continue;
- }
-
- /* Look for the highest priority texture target that's enabled (or used
- * by the vert/frag shaders) and "complete". That's the one we'll use
- * for texturing. If we're using vert/frag program we're guaranteed
- * that bitcount(enabledBits) <= 1.
- * Note that the TEXTURE_x_INDEX values are in high to low priority.
- */
- for (texIndex = 0; texIndex < NUM_TEXTURE_TARGETS; texIndex++) {
- if (enabledTargets & (1 << texIndex)) {
- struct gl_texture_object *texObj = texUnit->CurrentTex[texIndex];
- if (!texObj->_Complete) {
- _mesa_test_texobj_completeness(ctx, texObj);
- }
- if (texObj->_Complete) {
- texUnit->_ReallyEnabled = 1 << texIndex;
- _mesa_reference_texobj(&texUnit->_Current, texObj);
- break;
- }
- }
- }
-
- if (!texUnit->_ReallyEnabled) {
- if (fprog) {
- /* If we get here it means the shader is expecting a texture
- * object, but there isn't one (or it's incomplete). Use the
- * fallback texture.
- */
- struct gl_texture_object *texObj = _mesa_get_fallback_texture(ctx);
- texUnit->_ReallyEnabled = 1 << TEXTURE_2D_INDEX;
- _mesa_reference_texobj(&texUnit->_Current, texObj);
- }
- else {
- /* fixed-function: texture unit is really disabled */
- continue;
- }
- }
-
- /* if we get here, we know this texture unit is enabled */
-
- ctx->Texture._EnabledUnits |= (1 << unit);
-
- if (enabledFragTargets)
- enabledFragUnits |= (1 << unit);
-
- update_tex_combine(ctx, texUnit);
- }
-
-
- /* Determine which texture coordinate sets are actually needed */
- if (fprog) {
- const GLuint coordMask = (1 << MAX_TEXTURE_COORD_UNITS) - 1;
- ctx->Texture._EnabledCoordUnits
- = (fprog->Base.InputsRead >> FRAG_ATTRIB_TEX0) & coordMask;
- }
- else {
- ctx->Texture._EnabledCoordUnits = enabledFragUnits;
- }
-
- /* Setup texgen for those texture coordinate sets that are in use */
- for (unit = 0; unit < ctx->Const.MaxTextureCoordUnits; unit++) {
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
-
- texUnit->_GenFlags = 0x0;
-
- if (!(ctx->Texture._EnabledCoordUnits & (1 << unit)))
- continue;
-
- if (texUnit->TexGenEnabled) {
- if (texUnit->TexGenEnabled & S_BIT) {
- texUnit->_GenFlags |= texUnit->GenS._ModeBit;
- }
- if (texUnit->TexGenEnabled & T_BIT) {
- texUnit->_GenFlags |= texUnit->GenT._ModeBit;
- }
- if (texUnit->TexGenEnabled & R_BIT) {
- texUnit->_GenFlags |= texUnit->GenR._ModeBit;
- }
- if (texUnit->TexGenEnabled & Q_BIT) {
- texUnit->_GenFlags |= texUnit->GenQ._ModeBit;
- }
-
- ctx->Texture._TexGenEnabled |= ENABLE_TEXGEN(unit);
- ctx->Texture._GenFlags |= texUnit->_GenFlags;
- }
-
- ASSERT(unit < Elements(ctx->TextureMatrixStack));
- if (ctx->TextureMatrixStack[unit].Top->type != MATRIX_IDENTITY)
- ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(unit);
- }
-}
-
-
-/**
- * Update texture-related derived state.
- */
-void
-_mesa_update_texture( struct gl_context *ctx, GLuint new_state )
-{
- if (new_state & _NEW_TEXTURE_MATRIX)
- update_texture_matrices( ctx );
-
- if (new_state & (_NEW_TEXTURE | _NEW_PROGRAM))
- update_texture_state( ctx );
-}
-
-
-/**********************************************************************/
-/***** Initialization *****/
-/**********************************************************************/
-
-/**
- * Allocate the proxy textures for the given context.
- *
- * \param ctx the context to allocate proxies for.
- *
- * \return GL_TRUE on success, or GL_FALSE on failure
- *
- * If run out of memory part way through the allocations, clean up and return
- * GL_FALSE.
- */
-static GLboolean
-alloc_proxy_textures( struct gl_context *ctx )
-{
- static const GLenum targets[] = {
- GL_TEXTURE_1D,
- GL_TEXTURE_2D,
- GL_TEXTURE_3D,
- GL_TEXTURE_CUBE_MAP_ARB,
- GL_TEXTURE_RECTANGLE_NV,
- GL_TEXTURE_1D_ARRAY_EXT,
- GL_TEXTURE_2D_ARRAY_EXT
- };
- GLint tgt;
-
- ASSERT(Elements(targets) == NUM_TEXTURE_TARGETS);
-
- for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
- if (!(ctx->Texture.ProxyTex[tgt]
- = ctx->Driver.NewTextureObject(ctx, 0, targets[tgt]))) {
- /* out of memory, free what we did allocate */
- while (--tgt >= 0) {
- ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
- }
- return GL_FALSE;
- }
- }
-
- assert(ctx->Texture.ProxyTex[0]->RefCount == 1); /* sanity check */
- return GL_TRUE;
-}
-
-
-/**
- * Initialize a texture unit.
- *
- * \param ctx GL context.
- * \param unit texture unit number to be initialized.
- */
-static void
-init_texture_unit( struct gl_context *ctx, GLuint unit )
-{
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
- GLuint tex;
-
- texUnit->EnvMode = GL_MODULATE;
- ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
-
- texUnit->Combine = default_combine_state;
- texUnit->_EnvMode = default_combine_state;
- texUnit->_CurrentCombine = & texUnit->_EnvMode;
- texUnit->BumpTarget = GL_TEXTURE0;
-
- texUnit->TexGenEnabled = 0x0;
- texUnit->GenS.Mode = GL_EYE_LINEAR;
- texUnit->GenT.Mode = GL_EYE_LINEAR;
- texUnit->GenR.Mode = GL_EYE_LINEAR;
- texUnit->GenQ.Mode = GL_EYE_LINEAR;
- texUnit->GenS._ModeBit = TEXGEN_EYE_LINEAR;
- texUnit->GenT._ModeBit = TEXGEN_EYE_LINEAR;
- texUnit->GenR._ModeBit = TEXGEN_EYE_LINEAR;
- texUnit->GenQ._ModeBit = TEXGEN_EYE_LINEAR;
-
- /* Yes, these plane coefficients are correct! */
- ASSIGN_4V( texUnit->GenS.ObjectPlane, 1.0, 0.0, 0.0, 0.0 );
- ASSIGN_4V( texUnit->GenT.ObjectPlane, 0.0, 1.0, 0.0, 0.0 );
- ASSIGN_4V( texUnit->GenR.ObjectPlane, 0.0, 0.0, 0.0, 0.0 );
- ASSIGN_4V( texUnit->GenQ.ObjectPlane, 0.0, 0.0, 0.0, 0.0 );
- ASSIGN_4V( texUnit->GenS.EyePlane, 1.0, 0.0, 0.0, 0.0 );
- ASSIGN_4V( texUnit->GenT.EyePlane, 0.0, 1.0, 0.0, 0.0 );
- ASSIGN_4V( texUnit->GenR.EyePlane, 0.0, 0.0, 0.0, 0.0 );
- ASSIGN_4V( texUnit->GenQ.EyePlane, 0.0, 0.0, 0.0, 0.0 );
-
- /* no mention of this in spec, but maybe id matrix expected? */
- ASSIGN_4V( texUnit->RotMatrix, 1.0, 0.0, 0.0, 1.0 );
-
- /* initialize current texture object ptrs to the shared default objects */
- for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
- _mesa_reference_texobj(&texUnit->CurrentTex[tex],
- ctx->Shared->DefaultTex[tex]);
- }
-}
-
-
-/**
- * Initialize texture state for the given context.
- */
-GLboolean
-_mesa_init_texture(struct gl_context *ctx)
-{
- GLuint u;
-
- /* Texture group */
- ctx->Texture.CurrentUnit = 0; /* multitexture */
- ctx->Texture._EnabledUnits = 0x0;
- ctx->Texture.SharedPalette = GL_FALSE;
- _mesa_init_colortable(&ctx->Texture.Palette);
-
- for (u = 0; u < Elements(ctx->Texture.Unit); u++)
- init_texture_unit(ctx, u);
-
- /* After we're done initializing the context's texture state the default
- * texture objects' refcounts should be at least
- * MAX_COMBINED_TEXTURE_IMAGE_UNITS + 1.
- */
- assert(ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]->RefCount
- >= MAX_COMBINED_TEXTURE_IMAGE_UNITS + 1);
-
- /* Allocate proxy textures */
- if (!alloc_proxy_textures( ctx ))
- return GL_FALSE;
-
- return GL_TRUE;
-}
-
-
-/**
- * Free dynamically-allocted texture data attached to the given context.
- */
-void
-_mesa_free_texture_data(struct gl_context *ctx)
-{
- GLuint u, tgt;
-
- /* unreference current textures */
- for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
- /* The _Current texture could account for another reference */
- _mesa_reference_texobj(&ctx->Texture.Unit[u]._Current, NULL);
-
- for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
- _mesa_reference_texobj(&ctx->Texture.Unit[u].CurrentTex[tgt], NULL);
- }
- }
-
- /* Free proxy texture objects */
- for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++)
- ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
-}
-
-
-/**
- * Update the default texture objects in the given context to reference those
- * specified in the shared state and release those referencing the old
- * shared state.
- */
-void
-_mesa_update_default_objects_texture(struct gl_context *ctx)
-{
- GLuint u, tex;
-
- for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[u];
- for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
- _mesa_reference_texobj(&texUnit->CurrentTex[tex],
- ctx->Shared->DefaultTex[tex]);
- }
- }
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.5
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file texstate.c
+ *
+ * Texture state handling.
+ */
+
+#include "glheader.h"
+#include "mfeatures.h"
+#include "colormac.h"
+#include "colortab.h"
+#include "context.h"
+#include "enums.h"
+#include "macros.h"
+#include "texobj.h"
+#include "teximage.h"
+#include "texstate.h"
+#include "mtypes.h"
+
+
+
+/**
+ * Default texture combine environment state. This is used to initialize
+ * a context's texture units and as the basis for converting "classic"
+ * texture environmnets to ARB_texture_env_combine style values.
+ */
+static const struct gl_tex_env_combine_state default_combine_state = {
+ GL_MODULATE, GL_MODULATE,
+ { GL_TEXTURE, GL_PREVIOUS, GL_CONSTANT, GL_CONSTANT },
+ { GL_TEXTURE, GL_PREVIOUS, GL_CONSTANT, GL_CONSTANT },
+ { GL_SRC_COLOR, GL_SRC_COLOR, GL_SRC_ALPHA, GL_SRC_ALPHA },
+ { GL_SRC_ALPHA, GL_SRC_ALPHA, GL_SRC_ALPHA, GL_SRC_ALPHA },
+ 0, 0,
+ 2, 2
+};
+
+
+
+/**
+ * Used by glXCopyContext to copy texture state from one context to another.
+ */
+void
+_mesa_copy_texture_state( const struct gl_context *src, struct gl_context *dst )
+{
+ GLuint u, tex;
+
+ ASSERT(src);
+ ASSERT(dst);
+
+ dst->Texture.CurrentUnit = src->Texture.CurrentUnit;
+ dst->Texture._GenFlags = src->Texture._GenFlags;
+ dst->Texture._TexGenEnabled = src->Texture._TexGenEnabled;
+ dst->Texture._TexMatEnabled = src->Texture._TexMatEnabled;
+ dst->Texture.SharedPalette = src->Texture.SharedPalette;
+
+ /* per-unit state */
+ for (u = 0; u < src->Const.MaxCombinedTextureImageUnits; u++) {
+ dst->Texture.Unit[u].Enabled = src->Texture.Unit[u].Enabled;
+ dst->Texture.Unit[u].EnvMode = src->Texture.Unit[u].EnvMode;
+ COPY_4V(dst->Texture.Unit[u].EnvColor, src->Texture.Unit[u].EnvColor);
+ dst->Texture.Unit[u].TexGenEnabled = src->Texture.Unit[u].TexGenEnabled;
+ dst->Texture.Unit[u].GenS = src->Texture.Unit[u].GenS;
+ dst->Texture.Unit[u].GenT = src->Texture.Unit[u].GenT;
+ dst->Texture.Unit[u].GenR = src->Texture.Unit[u].GenR;
+ dst->Texture.Unit[u].GenQ = src->Texture.Unit[u].GenQ;
+ dst->Texture.Unit[u].LodBias = src->Texture.Unit[u].LodBias;
+
+ /* GL_EXT_texture_env_combine */
+ dst->Texture.Unit[u].Combine = src->Texture.Unit[u].Combine;
+
+ /* GL_ATI_envmap_bumpmap - need this? */
+ dst->Texture.Unit[u].BumpTarget = src->Texture.Unit[u].BumpTarget;
+ COPY_4V(dst->Texture.Unit[u].RotMatrix, src->Texture.Unit[u].RotMatrix);
+
+ /*
+ * XXX strictly speaking, we should compare texture names/ids and
+ * bind textures in the dest context according to id. For now, only
+ * copy bindings if the contexts share the same pool of textures to
+ * avoid refcounting bugs.
+ */
+ if (dst->Shared == src->Shared) {
+ /* copy texture object bindings, not contents of texture objects */
+ _mesa_lock_context_textures(dst);
+
+ for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
+ _mesa_reference_texobj(&dst->Texture.Unit[u].CurrentTex[tex],
+ src->Texture.Unit[u].CurrentTex[tex]);
+ }
+ _mesa_unlock_context_textures(dst);
+ }
+ }
+}
+
+
+/*
+ * For debugging
+ */
+void
+_mesa_print_texunit_state( struct gl_context *ctx, GLuint unit )
+{
+ const struct gl_texture_unit *texUnit = ctx->Texture.Unit + unit;
+ printf("Texture Unit %d\n", unit);
+ printf(" GL_TEXTURE_ENV_MODE = %s\n", _mesa_lookup_enum_by_nr(texUnit->EnvMode));
+ printf(" GL_COMBINE_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.ModeRGB));
+ printf(" GL_COMBINE_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.ModeA));
+ printf(" GL_SOURCE0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[0]));
+ printf(" GL_SOURCE1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[1]));
+ printf(" GL_SOURCE2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[2]));
+ printf(" GL_SOURCE0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[0]));
+ printf(" GL_SOURCE1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[1]));
+ printf(" GL_SOURCE2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[2]));
+ printf(" GL_OPERAND0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[0]));
+ printf(" GL_OPERAND1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[1]));
+ printf(" GL_OPERAND2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[2]));
+ printf(" GL_OPERAND0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[0]));
+ printf(" GL_OPERAND1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[1]));
+ printf(" GL_OPERAND2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[2]));
+ printf(" GL_RGB_SCALE = %d\n", 1 << texUnit->Combine.ScaleShiftRGB);
+ printf(" GL_ALPHA_SCALE = %d\n", 1 << texUnit->Combine.ScaleShiftA);
+ printf(" GL_TEXTURE_ENV_COLOR = (%f, %f, %f, %f)\n", texUnit->EnvColor[0], texUnit->EnvColor[1], texUnit->EnvColor[2], texUnit->EnvColor[3]);
+}
+
+
+
+/**********************************************************************/
+/* Texture Environment */
+/**********************************************************************/
+
+/**
+ * Convert "classic" texture environment to ARB_texture_env_combine style
+ * environments.
+ *
+ * \param state texture_env_combine state vector to be filled-in.
+ * \param mode Classic texture environment mode (i.e., \c GL_REPLACE,
+ * \c GL_BLEND, \c GL_DECAL, etc.).
+ * \param texBaseFormat Base format of the texture associated with the
+ * texture unit.
+ */
+static void
+calculate_derived_texenv( struct gl_tex_env_combine_state *state,
+ GLenum mode, GLenum texBaseFormat )
+{
+ GLenum mode_rgb;
+ GLenum mode_a;
+
+ *state = default_combine_state;
+
+ switch (texBaseFormat) {
+ case GL_ALPHA:
+ state->SourceRGB[0] = GL_PREVIOUS;
+ break;
+
+ case GL_LUMINANCE_ALPHA:
+ case GL_INTENSITY:
+ case GL_RGBA:
+ break;
+
+ case GL_LUMINANCE:
+ case GL_RED:
+ case GL_RG:
+ case GL_RGB:
+ case GL_YCBCR_MESA:
+ case GL_DUDV_ATI:
+ state->SourceA[0] = GL_PREVIOUS;
+ break;
+
+ default:
+ _mesa_problem(NULL,
+ "Invalid texBaseFormat 0x%x in calculate_derived_texenv",
+ texBaseFormat);
+ return;
+ }
+
+ if (mode == GL_REPLACE_EXT)
+ mode = GL_REPLACE;
+
+ switch (mode) {
+ case GL_REPLACE:
+ case GL_MODULATE:
+ mode_rgb = (texBaseFormat == GL_ALPHA) ? GL_REPLACE : mode;
+ mode_a = mode;
+ break;
+
+ case GL_DECAL:
+ mode_rgb = GL_INTERPOLATE;
+ mode_a = GL_REPLACE;
+
+ state->SourceA[0] = GL_PREVIOUS;
+
+ /* Having alpha / luminance / intensity textures replace using the
+ * incoming fragment color matches the definition in NV_texture_shader.
+ * The 1.5 spec simply marks these as "undefined".
+ */
+ switch (texBaseFormat) {
+ case GL_ALPHA:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE_ALPHA:
+ case GL_INTENSITY:
+ state->SourceRGB[0] = GL_PREVIOUS;
+ break;
+ case GL_RED:
+ case GL_RG:
+ case GL_RGB:
+ case GL_YCBCR_MESA:
+ case GL_DUDV_ATI:
+ mode_rgb = GL_REPLACE;
+ break;
+ case GL_RGBA:
+ state->SourceRGB[2] = GL_TEXTURE;
+ break;
+ }
+ break;
+
+ case GL_BLEND:
+ mode_rgb = GL_INTERPOLATE;
+ mode_a = GL_MODULATE;
+
+ switch (texBaseFormat) {
+ case GL_ALPHA:
+ mode_rgb = GL_REPLACE;
+ break;
+ case GL_INTENSITY:
+ mode_a = GL_INTERPOLATE;
+ state->SourceA[0] = GL_CONSTANT;
+ state->OperandA[2] = GL_SRC_ALPHA;
+ /* FALLTHROUGH */
+ case GL_LUMINANCE:
+ case GL_RED:
+ case GL_RG:
+ case GL_RGB:
+ case GL_LUMINANCE_ALPHA:
+ case GL_RGBA:
+ case GL_YCBCR_MESA:
+ case GL_DUDV_ATI:
+ state->SourceRGB[2] = GL_TEXTURE;
+ state->SourceA[2] = GL_TEXTURE;
+ state->SourceRGB[0] = GL_CONSTANT;
+ state->OperandRGB[2] = GL_SRC_COLOR;
+ break;
+ }
+ break;
+
+ case GL_ADD:
+ mode_rgb = (texBaseFormat == GL_ALPHA) ? GL_REPLACE : GL_ADD;
+ mode_a = (texBaseFormat == GL_INTENSITY) ? GL_ADD : GL_MODULATE;
+ break;
+
+ default:
+ _mesa_problem(NULL,
+ "Invalid texture env mode 0x%x in calculate_derived_texenv",
+ mode);
+ return;
+ }
+
+ state->ModeRGB = (state->SourceRGB[0] != GL_PREVIOUS)
+ ? mode_rgb : GL_REPLACE;
+ state->ModeA = (state->SourceA[0] != GL_PREVIOUS)
+ ? mode_a : GL_REPLACE;
+}
+
+
+
+
+/* GL_ARB_multitexture */
+void GLAPIENTRY
+_mesa_ActiveTextureARB(GLenum texture)
+{
+ const GLuint texUnit = texture - GL_TEXTURE0;
+ GLuint k;
+ GET_CURRENT_CONTEXT(ctx);
+
+ /* See OpenGL spec for glActiveTexture: */
+ k = MAX2(ctx->Const.MaxCombinedTextureImageUnits,
+ ctx->Const.MaxTextureCoordUnits);
+
+ ASSERT(k <= Elements(ctx->Texture.Unit));
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+ _mesa_debug(ctx, "glActiveTexture %s\n",
+ _mesa_lookup_enum_by_nr(texture));
+
+ if (texUnit >= k) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glActiveTexture(texture=%s)",
+ _mesa_lookup_enum_by_nr(texture));
+ return;
+ }
+
+ if (ctx->Texture.CurrentUnit == texUnit)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+
+ ctx->Texture.CurrentUnit = texUnit;
+ if (ctx->Transform.MatrixMode == GL_TEXTURE) {
+ /* update current stack pointer */
+ ctx->CurrentStack = &ctx->TextureMatrixStack[texUnit];
+ }
+}
+
+
+/* GL_ARB_multitexture */
+void GLAPIENTRY
+_mesa_ClientActiveTextureARB(GLenum texture)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint texUnit = texture - GL_TEXTURE0;
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE))
+ _mesa_debug(ctx, "glClientActiveTexture %s\n",
+ _mesa_lookup_enum_by_nr(texture));
+
+ if (texUnit >= ctx->Const.MaxTextureCoordUnits) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glClientActiveTexture(texture)");
+ return;
+ }
+
+ if (ctx->Array.ActiveTexture == texUnit)
+ return;
+
+ FLUSH_VERTICES(ctx, _NEW_ARRAY);
+ ctx->Array.ActiveTexture = texUnit;
+}
+
+
+
+/**********************************************************************/
+/***** State management *****/
+/**********************************************************************/
+
+
+/**
+ * \note This routine refers to derived texture attribute values to
+ * compute the ENABLE_TEXMAT flags, but is only called on
+ * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
+ * flags are updated by _mesa_update_textures(), below.
+ *
+ * \param ctx GL context.
+ */
+static void
+update_texture_matrices( struct gl_context *ctx )
+{
+ GLuint u;
+
+ ctx->Texture._TexMatEnabled = 0x0;
+
+ for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) {
+ ASSERT(u < Elements(ctx->TextureMatrixStack));
+ if (_math_matrix_is_dirty(ctx->TextureMatrixStack[u].Top)) {
+ _math_matrix_analyse( ctx->TextureMatrixStack[u].Top );
+
+ if (ctx->Texture.Unit[u]._ReallyEnabled &&
+ ctx->TextureMatrixStack[u].Top->type != MATRIX_IDENTITY)
+ ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(u);
+ }
+ }
+}
+
+
+/**
+ * Examine texture unit's combine/env state to update derived state.
+ */
+static void
+update_tex_combine(struct gl_context *ctx, struct gl_texture_unit *texUnit)
+{
+ struct gl_tex_env_combine_state *combine;
+
+ /* Set the texUnit->_CurrentCombine field to point to the user's combiner
+ * state, or the combiner state which is derived from traditional texenv
+ * mode.
+ */
+ if (texUnit->EnvMode == GL_COMBINE ||
+ texUnit->EnvMode == GL_COMBINE4_NV) {
+ texUnit->_CurrentCombine = & texUnit->Combine;
+ }
+ else {
+ const struct gl_texture_object *texObj = texUnit->_Current;
+ GLenum format = texObj->Image[0][texObj->BaseLevel]->_BaseFormat;
+ if (format == GL_COLOR_INDEX) {
+ format = GL_RGBA; /* a bit of a hack */
+ }
+ else if (format == GL_DEPTH_COMPONENT ||
+ format == GL_DEPTH_STENCIL_EXT) {
+ format = texObj->DepthMode;
+ }
+ calculate_derived_texenv(&texUnit->_EnvMode, texUnit->EnvMode, format);
+ texUnit->_CurrentCombine = & texUnit->_EnvMode;
+ }
+
+ combine = texUnit->_CurrentCombine;
+
+ /* Determine number of source RGB terms in the combiner function */
+ switch (combine->ModeRGB) {
+ case GL_REPLACE:
+ combine->_NumArgsRGB = 1;
+ break;
+ case GL_ADD:
+ case GL_ADD_SIGNED:
+ if (texUnit->EnvMode == GL_COMBINE4_NV)
+ combine->_NumArgsRGB = 4;
+ else
+ combine->_NumArgsRGB = 2;
+ break;
+ case GL_MODULATE:
+ case GL_SUBTRACT:
+ case GL_DOT3_RGB:
+ case GL_DOT3_RGBA:
+ case GL_DOT3_RGB_EXT:
+ case GL_DOT3_RGBA_EXT:
+ combine->_NumArgsRGB = 2;
+ break;
+ case GL_INTERPOLATE:
+ case GL_MODULATE_ADD_ATI:
+ case GL_MODULATE_SIGNED_ADD_ATI:
+ case GL_MODULATE_SUBTRACT_ATI:
+ combine->_NumArgsRGB = 3;
+ break;
+ case GL_BUMP_ENVMAP_ATI:
+ /* no real arguments for this case */
+ combine->_NumArgsRGB = 0;
+ break;
+ default:
+ combine->_NumArgsRGB = 0;
+ _mesa_problem(ctx, "invalid RGB combine mode in update_texture_state");
+ return;
+ }
+
+ /* Determine number of source Alpha terms in the combiner function */
+ switch (combine->ModeA) {
+ case GL_REPLACE:
+ combine->_NumArgsA = 1;
+ break;
+ case GL_ADD:
+ case GL_ADD_SIGNED:
+ if (texUnit->EnvMode == GL_COMBINE4_NV)
+ combine->_NumArgsA = 4;
+ else
+ combine->_NumArgsA = 2;
+ break;
+ case GL_MODULATE:
+ case GL_SUBTRACT:
+ combine->_NumArgsA = 2;
+ break;
+ case GL_INTERPOLATE:
+ case GL_MODULATE_ADD_ATI:
+ case GL_MODULATE_SIGNED_ADD_ATI:
+ case GL_MODULATE_SUBTRACT_ATI:
+ combine->_NumArgsA = 3;
+ break;
+ default:
+ combine->_NumArgsA = 0;
+ _mesa_problem(ctx, "invalid Alpha combine mode in update_texture_state");
+ break;
+ }
+}
+
+
+/**
+ * \note This routine refers to derived texture matrix values to
+ * compute the ENABLE_TEXMAT flags, but is only called on
+ * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
+ * flags are updated by _mesa_update_texture_matrices, above.
+ *
+ * \param ctx GL context.
+ */
+static void
+update_texture_state( struct gl_context *ctx )
+{
+ GLuint unit;
+ struct gl_fragment_program *fprog = NULL;
+ struct gl_vertex_program *vprog = NULL;
+ GLbitfield enabledFragUnits = 0x0;
+
+ if (ctx->Shader.CurrentVertexProgram &&
+ ctx->Shader.CurrentVertexProgram->LinkStatus) {
+ vprog = ctx->Shader.CurrentVertexProgram->VertexProgram;
+ } else if (ctx->VertexProgram._Enabled) {
+ /* XXX enable this if/when non-shader vertex programs get
+ * texture fetches:
+ vprog = ctx->VertexProgram.Current;
+ */
+ }
+
+ if (ctx->Shader.CurrentFragmentProgram &&
+ ctx->Shader.CurrentFragmentProgram->LinkStatus) {
+ fprog = ctx->Shader.CurrentFragmentProgram->FragmentProgram;
+ }
+ else if (ctx->FragmentProgram._Enabled) {
+ fprog = ctx->FragmentProgram.Current;
+ }
+
+ /* FINISHME: Geometry shader texture accesses should also be considered
+ * FINISHME: here.
+ */
+
+ /* TODO: only set this if there are actual changes */
+ ctx->NewState |= _NEW_TEXTURE;
+
+ ctx->Texture._EnabledUnits = 0x0;
+ ctx->Texture._GenFlags = 0x0;
+ ctx->Texture._TexMatEnabled = 0x0;
+ ctx->Texture._TexGenEnabled = 0x0;
+
+ /*
+ * Update texture unit state.
+ */
+ for (unit = 0; unit < ctx->Const.MaxCombinedTextureImageUnits; unit++) {
+ struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+ GLbitfield enabledVertTargets = 0x0;
+ GLbitfield enabledFragTargets = 0x0;
+ GLbitfield enabledTargets = 0x0;
+ GLuint texIndex;
+
+ /* Get the bitmask of texture target enables.
+ * enableBits will be a mask of the TEXTURE_*_BIT flags indicating
+ * which texture targets are enabled (fixed function) or referenced
+ * by a fragment program/program. When multiple flags are set, we'll
+ * settle on the one with highest priority (see below).
+ */
+ if (vprog) {
+ enabledVertTargets |= vprog->Base.TexturesUsed[unit];
+ }
+
+ if (fprog) {
+ enabledFragTargets |= fprog->Base.TexturesUsed[unit];
+ }
+ else {
+ /* fixed-function fragment program */
+ enabledFragTargets |= texUnit->Enabled;
+ }
+
+ enabledTargets = enabledVertTargets | enabledFragTargets;
+
+ texUnit->_ReallyEnabled = 0x0;
+
+ if (enabledTargets == 0x0) {
+ /* neither vertex nor fragment processing uses this unit */
+ continue;
+ }
+
+ /* Look for the highest priority texture target that's enabled (or used
+ * by the vert/frag shaders) and "complete". That's the one we'll use
+ * for texturing. If we're using vert/frag program we're guaranteed
+ * that bitcount(enabledBits) <= 1.
+ * Note that the TEXTURE_x_INDEX values are in high to low priority.
+ */
+ for (texIndex = 0; texIndex < NUM_TEXTURE_TARGETS; texIndex++) {
+ if (enabledTargets & (1 << texIndex)) {
+ struct gl_texture_object *texObj = texUnit->CurrentTex[texIndex];
+ if (!texObj->_Complete) {
+ _mesa_test_texobj_completeness(ctx, texObj);
+ }
+ if (texObj->_Complete) {
+ texUnit->_ReallyEnabled = 1 << texIndex;
+ _mesa_reference_texobj(&texUnit->_Current, texObj);
+ break;
+ }
+ }
+ }
+
+ if (!texUnit->_ReallyEnabled) {
+ if (fprog) {
+ /* If we get here it means the shader is expecting a texture
+ * object, but there isn't one (or it's incomplete). Use the
+ * fallback texture.
+ */
+ struct gl_texture_object *texObj = _mesa_get_fallback_texture(ctx);
+ texUnit->_ReallyEnabled = 1 << TEXTURE_2D_INDEX;
+ _mesa_reference_texobj(&texUnit->_Current, texObj);
+ }
+ else {
+ /* fixed-function: texture unit is really disabled */
+ continue;
+ }
+ }
+
+ /* if we get here, we know this texture unit is enabled */
+
+ ctx->Texture._EnabledUnits |= (1 << unit);
+
+ if (enabledFragTargets)
+ enabledFragUnits |= (1 << unit);
+
+ update_tex_combine(ctx, texUnit);
+ }
+
+
+ /* Determine which texture coordinate sets are actually needed */
+ if (fprog) {
+ const GLuint coordMask = (1 << MAX_TEXTURE_COORD_UNITS) - 1;
+ ctx->Texture._EnabledCoordUnits
+ = (fprog->Base.InputsRead >> FRAG_ATTRIB_TEX0) & coordMask;
+ }
+ else {
+ ctx->Texture._EnabledCoordUnits = enabledFragUnits;
+ }
+
+ /* Setup texgen for those texture coordinate sets that are in use */
+ for (unit = 0; unit < ctx->Const.MaxTextureCoordUnits; unit++) {
+ struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+
+ texUnit->_GenFlags = 0x0;
+
+ if (!(ctx->Texture._EnabledCoordUnits & (1 << unit)))
+ continue;
+
+ if (texUnit->TexGenEnabled) {
+ if (texUnit->TexGenEnabled & S_BIT) {
+ texUnit->_GenFlags |= texUnit->GenS._ModeBit;
+ }
+ if (texUnit->TexGenEnabled & T_BIT) {
+ texUnit->_GenFlags |= texUnit->GenT._ModeBit;
+ }
+ if (texUnit->TexGenEnabled & R_BIT) {
+ texUnit->_GenFlags |= texUnit->GenR._ModeBit;
+ }
+ if (texUnit->TexGenEnabled & Q_BIT) {
+ texUnit->_GenFlags |= texUnit->GenQ._ModeBit;
+ }
+
+ ctx->Texture._TexGenEnabled |= ENABLE_TEXGEN(unit);
+ ctx->Texture._GenFlags |= texUnit->_GenFlags;
+ }
+
+ ASSERT(unit < Elements(ctx->TextureMatrixStack));
+ if (ctx->TextureMatrixStack[unit].Top->type != MATRIX_IDENTITY)
+ ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(unit);
+ }
+}
+
+
+/**
+ * Update texture-related derived state.
+ */
+void
+_mesa_update_texture( struct gl_context *ctx, GLuint new_state )
+{
+ if (new_state & _NEW_TEXTURE_MATRIX)
+ update_texture_matrices( ctx );
+
+ if (new_state & (_NEW_TEXTURE | _NEW_PROGRAM))
+ update_texture_state( ctx );
+}
+
+
+/**********************************************************************/
+/***** Initialization *****/
+/**********************************************************************/
+
+/**
+ * Allocate the proxy textures for the given context.
+ *
+ * \param ctx the context to allocate proxies for.
+ *
+ * \return GL_TRUE on success, or GL_FALSE on failure
+ *
+ * If run out of memory part way through the allocations, clean up and return
+ * GL_FALSE.
+ */
+static GLboolean
+alloc_proxy_textures( struct gl_context *ctx )
+{
+ static const GLenum targets[] = {
+ GL_TEXTURE_1D,
+ GL_TEXTURE_2D,
+ GL_TEXTURE_3D,
+ GL_TEXTURE_CUBE_MAP_ARB,
+ GL_TEXTURE_RECTANGLE_NV,
+ GL_TEXTURE_1D_ARRAY_EXT,
+ GL_TEXTURE_2D_ARRAY_EXT
+ };
+ GLint tgt;
+
+ ASSERT(Elements(targets) == NUM_TEXTURE_TARGETS);
+
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+ if (!(ctx->Texture.ProxyTex[tgt]
+ = ctx->Driver.NewTextureObject(ctx, 0, targets[tgt]))) {
+ /* out of memory, free what we did allocate */
+ while (--tgt >= 0) {
+ ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
+ }
+ return GL_FALSE;
+ }
+ }
+
+ assert(ctx->Texture.ProxyTex[0]->RefCount == 1); /* sanity check */
+ return GL_TRUE;
+}
+
+
+/**
+ * Initialize a texture unit.
+ *
+ * \param ctx GL context.
+ * \param unit texture unit number to be initialized.
+ */
+static void
+init_texture_unit( struct gl_context *ctx, GLuint unit )
+{
+ struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+ GLuint tex;
+
+ texUnit->EnvMode = GL_MODULATE;
+ ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
+
+ texUnit->Combine = default_combine_state;
+ texUnit->_EnvMode = default_combine_state;
+ texUnit->_CurrentCombine = & texUnit->_EnvMode;
+ texUnit->BumpTarget = GL_TEXTURE0;
+
+ texUnit->TexGenEnabled = 0x0;
+ texUnit->GenS.Mode = GL_EYE_LINEAR;
+ texUnit->GenT.Mode = GL_EYE_LINEAR;
+ texUnit->GenR.Mode = GL_EYE_LINEAR;
+ texUnit->GenQ.Mode = GL_EYE_LINEAR;
+ texUnit->GenS._ModeBit = TEXGEN_EYE_LINEAR;
+ texUnit->GenT._ModeBit = TEXGEN_EYE_LINEAR;
+ texUnit->GenR._ModeBit = TEXGEN_EYE_LINEAR;
+ texUnit->GenQ._ModeBit = TEXGEN_EYE_LINEAR;
+
+ /* Yes, these plane coefficients are correct! */
+ ASSIGN_4V( texUnit->GenS.ObjectPlane, 1.0, 0.0, 0.0, 0.0 );
+ ASSIGN_4V( texUnit->GenT.ObjectPlane, 0.0, 1.0, 0.0, 0.0 );
+ ASSIGN_4V( texUnit->GenR.ObjectPlane, 0.0, 0.0, 0.0, 0.0 );
+ ASSIGN_4V( texUnit->GenQ.ObjectPlane, 0.0, 0.0, 0.0, 0.0 );
+ ASSIGN_4V( texUnit->GenS.EyePlane, 1.0, 0.0, 0.0, 0.0 );
+ ASSIGN_4V( texUnit->GenT.EyePlane, 0.0, 1.0, 0.0, 0.0 );
+ ASSIGN_4V( texUnit->GenR.EyePlane, 0.0, 0.0, 0.0, 0.0 );
+ ASSIGN_4V( texUnit->GenQ.EyePlane, 0.0, 0.0, 0.0, 0.0 );
+
+ /* no mention of this in spec, but maybe id matrix expected? */
+ ASSIGN_4V( texUnit->RotMatrix, 1.0, 0.0, 0.0, 1.0 );
+
+ /* initialize current texture object ptrs to the shared default objects */
+ for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
+ _mesa_reference_texobj(&texUnit->CurrentTex[tex],
+ ctx->Shared->DefaultTex[tex]);
+ }
+}
+
+
+/**
+ * Initialize texture state for the given context.
+ */
+GLboolean
+_mesa_init_texture(struct gl_context *ctx)
+{
+ GLuint u;
+
+ /* Texture group */
+ ctx->Texture.CurrentUnit = 0; /* multitexture */
+ ctx->Texture._EnabledUnits = 0x0;
+ ctx->Texture.SharedPalette = GL_FALSE;
+ _mesa_init_colortable(&ctx->Texture.Palette);
+
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++)
+ init_texture_unit(ctx, u);
+
+ /* After we're done initializing the context's texture state the default
+ * texture objects' refcounts should be at least
+ * MAX_COMBINED_TEXTURE_IMAGE_UNITS + 1.
+ */
+ assert(ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]->RefCount
+ >= MAX_COMBINED_TEXTURE_IMAGE_UNITS + 1);
+
+ /* Allocate proxy textures */
+ if (!alloc_proxy_textures( ctx ))
+ return GL_FALSE;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Free dynamically-allocted texture data attached to the given context.
+ */
+void
+_mesa_free_texture_data(struct gl_context *ctx)
+{
+ GLuint u, tgt;
+
+ /* unreference current textures */
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
+ /* The _Current texture could account for another reference */
+ _mesa_reference_texobj(&ctx->Texture.Unit[u]._Current, NULL);
+
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+ _mesa_reference_texobj(&ctx->Texture.Unit[u].CurrentTex[tgt], NULL);
+ }
+ }
+
+ /* Free proxy texture objects */
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++)
+ ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
+}
+
+
+/**
+ * Update the default texture objects in the given context to reference those
+ * specified in the shared state and release those referencing the old
+ * shared state.
+ */
+void
+_mesa_update_default_objects_texture(struct gl_context *ctx)
+{
+ GLuint u, tex;
+
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
+ struct gl_texture_unit *texUnit = &ctx->Texture.Unit[u];
+ for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
+ _mesa_reference_texobj(&texUnit->CurrentTex[tex],
+ ctx->Shared->DefaultTex[tex]);
+ }
+ }
+}
diff --git a/mesalib/src/mesa/main/texstore.c b/mesalib/src/mesa/main/texstore.c
index cd30fa021..d091311c1 100644
--- a/mesalib/src/mesa/main/texstore.c
+++ b/mesalib/src/mesa/main/texstore.c
@@ -1,4702 +1,4702 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.5
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (c) 2008-2009 VMware, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * Authors:
- * Brian Paul
- */
-
-/**
- * The GL texture image functions in teximage.c basically just do
- * error checking and data structure allocation. They in turn call
- * device driver functions which actually copy/convert/store the user's
- * texture image data.
- *
- * However, most device drivers will be able to use the fallback functions
- * in this file. That is, most drivers will have the following bit of
- * code:
- * ctx->Driver.TexImage1D = _mesa_store_teximage1d;
- * ctx->Driver.TexImage2D = _mesa_store_teximage2d;
- * ctx->Driver.TexImage3D = _mesa_store_teximage3d;
- * etc...
- *
- * Texture image processing is actually kind of complicated. We have to do:
- * Format/type conversions
- * pixel unpacking
- * pixel transfer (scale, bais, lookup, etc)
- *
- * These functions can handle most everything, including processing full
- * images and sub-images.
- */
-
-
-#include "glheader.h"
-#include "bufferobj.h"
-#include "colormac.h"
-#include "image.h"
-#include "macros.h"
-#include "mipmap.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "pack.h"
-#include "pbo.h"
-#include "imports.h"
-#include "pack.h"
-#include "texcompress.h"
-#include "texcompress_fxt1.h"
-#include "texcompress_rgtc.h"
-#include "texcompress_s3tc.h"
-#include "teximage.h"
-#include "texstore.h"
-#include "enums.h"
-
-
-enum {
- ZERO = 4,
- ONE = 5
-};
-
-
-/**
- * Texture image storage function.
- */
-typedef GLboolean (*StoreTexImageFunc)(TEXSTORE_PARAMS);
-
-
-/**
- * Return GL_TRUE if the given image format is one that be converted
- * to another format by swizzling.
- */
-static GLboolean
-can_swizzle(GLenum logicalBaseFormat)
-{
- switch (logicalBaseFormat) {
- case GL_RGBA:
- case GL_RGB:
- case GL_LUMINANCE_ALPHA:
- case GL_INTENSITY:
- case GL_ALPHA:
- case GL_LUMINANCE:
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_BGR:
- case GL_BGRA:
- case GL_ABGR_EXT:
- case GL_RG:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-
-enum {
- IDX_LUMINANCE = 0,
- IDX_ALPHA,
- IDX_INTENSITY,
- IDX_LUMINANCE_ALPHA,
- IDX_RGB,
- IDX_RGBA,
- IDX_RED,
- IDX_GREEN,
- IDX_BLUE,
- IDX_BGR,
- IDX_BGRA,
- IDX_ABGR,
- IDX_RG,
- MAX_IDX
-};
-
-#define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
-#define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
-#define MAP3(x,y,z) MAP4(x, y, z, ZERO)
-#define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
-
-
-static const struct {
- GLubyte format_idx;
- GLubyte to_rgba[6];
- GLubyte from_rgba[6];
-} mappings[MAX_IDX] =
-{
- {
- IDX_LUMINANCE,
- MAP4(0,0,0,ONE),
- MAP1(0)
- },
-
- {
- IDX_ALPHA,
- MAP4(ZERO, ZERO, ZERO, 0),
- MAP1(3)
- },
-
- {
- IDX_INTENSITY,
- MAP4(0, 0, 0, 0),
- MAP1(0),
- },
-
- {
- IDX_LUMINANCE_ALPHA,
- MAP4(0,0,0,1),
- MAP2(0,3)
- },
-
- {
- IDX_RGB,
- MAP4(0,1,2,ONE),
- MAP3(0,1,2)
- },
-
- {
- IDX_RGBA,
- MAP4(0,1,2,3),
- MAP4(0,1,2,3),
- },
-
- {
- IDX_RED,
- MAP4(0, ZERO, ZERO, ONE),
- MAP1(0),
- },
-
- {
- IDX_GREEN,
- MAP4(ZERO, 0, ZERO, ONE),
- MAP1(1),
- },
-
- {
- IDX_BLUE,
- MAP4(ZERO, ZERO, 0, ONE),
- MAP1(2),
- },
-
- {
- IDX_BGR,
- MAP4(2,1,0,ONE),
- MAP3(2,1,0)
- },
-
- {
- IDX_BGRA,
- MAP4(2,1,0,3),
- MAP4(2,1,0,3)
- },
-
- {
- IDX_ABGR,
- MAP4(3,2,1,0),
- MAP4(3,2,1,0)
- },
-
- {
- IDX_RG,
- MAP4(0, 1, ZERO, ONE),
- MAP2(0, 1)
- },
-};
-
-
-
-/**
- * Convert a GL image format enum to an IDX_* value (see above).
- */
-static int
-get_map_idx(GLenum value)
-{
- switch (value) {
- case GL_LUMINANCE: return IDX_LUMINANCE;
- case GL_ALPHA: return IDX_ALPHA;
- case GL_INTENSITY: return IDX_INTENSITY;
- case GL_LUMINANCE_ALPHA: return IDX_LUMINANCE_ALPHA;
- case GL_RGB: return IDX_RGB;
- case GL_RGBA: return IDX_RGBA;
- case GL_RED: return IDX_RED;
- case GL_GREEN: return IDX_GREEN;
- case GL_BLUE: return IDX_BLUE;
- case GL_BGR: return IDX_BGR;
- case GL_BGRA: return IDX_BGRA;
- case GL_ABGR_EXT: return IDX_ABGR;
- case GL_RG: return IDX_RG;
- default:
- _mesa_problem(NULL, "Unexpected inFormat");
- return 0;
- }
-}
-
-
-/**
- * When promoting texture formats (see below) we need to compute the
- * mapping of dest components back to source components.
- * This function does that.
- * \param inFormat the incoming format of the texture
- * \param outFormat the final texture format
- * \return map[6] a full 6-component map
- */
-static void
-compute_component_mapping(GLenum inFormat, GLenum outFormat,
- GLubyte *map)
-{
- const int inFmt = get_map_idx(inFormat);
- const int outFmt = get_map_idx(outFormat);
- const GLubyte *in2rgba = mappings[inFmt].to_rgba;
- const GLubyte *rgba2out = mappings[outFmt].from_rgba;
- int i;
-
- for (i = 0; i < 4; i++)
- map[i] = in2rgba[rgba2out[i]];
-
- map[ZERO] = ZERO;
- map[ONE] = ONE;
-
-#if 0
- printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
- inFormat, _mesa_lookup_enum_by_nr(inFormat),
- outFormat, _mesa_lookup_enum_by_nr(outFormat),
- map[0],
- map[1],
- map[2],
- map[3],
- map[4],
- map[5]);
-#endif
-}
-
-
-/**
- * Make a temporary (color) texture image with GLfloat components.
- * Apply all needed pixel unpacking and pixel transfer operations.
- * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
- * Suppose the user specifies GL_LUMINANCE as the internal texture format
- * but the graphics hardware doesn't support luminance textures. So, we might
- * use an RGB hardware format instead.
- * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
- *
- * \param ctx the rendering context
- * \param dims image dimensions: 1, 2 or 3
- * \param logicalBaseFormat basic texture derived from the user's
- * internal texture format value
- * \param textureBaseFormat the actual basic format of the texture
- * \param srcWidth source image width
- * \param srcHeight source image height
- * \param srcDepth source image depth
- * \param srcFormat source image format
- * \param srcType source image type
- * \param srcAddr source image address
- * \param srcPacking source image pixel packing
- * \return resulting image with format = textureBaseFormat and type = GLfloat.
- */
-GLfloat *
-_mesa_make_temp_float_image(struct gl_context *ctx, GLuint dims,
- GLenum logicalBaseFormat,
- GLenum textureBaseFormat,
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- GLenum srcFormat, GLenum srcType,
- const GLvoid *srcAddr,
- const struct gl_pixelstore_attrib *srcPacking,
- GLbitfield transferOps)
-{
- GLfloat *tempImage;
- const GLint components = _mesa_components_in_format(logicalBaseFormat);
- const GLint srcStride =
- _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
- GLfloat *dst;
- GLint img, row;
-
- ASSERT(dims >= 1 && dims <= 3);
-
- ASSERT(logicalBaseFormat == GL_RGBA ||
- logicalBaseFormat == GL_RGB ||
- logicalBaseFormat == GL_RG ||
- logicalBaseFormat == GL_RED ||
- logicalBaseFormat == GL_LUMINANCE_ALPHA ||
- logicalBaseFormat == GL_LUMINANCE ||
- logicalBaseFormat == GL_ALPHA ||
- logicalBaseFormat == GL_INTENSITY ||
- logicalBaseFormat == GL_COLOR_INDEX ||
- logicalBaseFormat == GL_DEPTH_COMPONENT);
-
- ASSERT(textureBaseFormat == GL_RGBA ||
- textureBaseFormat == GL_RGB ||
- textureBaseFormat == GL_RG ||
- textureBaseFormat == GL_RED ||
- textureBaseFormat == GL_LUMINANCE_ALPHA ||
- textureBaseFormat == GL_LUMINANCE ||
- textureBaseFormat == GL_ALPHA ||
- textureBaseFormat == GL_INTENSITY ||
- textureBaseFormat == GL_COLOR_INDEX ||
- textureBaseFormat == GL_DEPTH_COMPONENT);
-
- tempImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
- * components * sizeof(GLfloat));
- if (!tempImage)
- return NULL;
-
- dst = tempImage;
- for (img = 0; img < srcDepth; img++) {
- const GLubyte *src
- = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
- srcWidth, srcHeight,
- srcFormat, srcType,
- img, 0, 0);
- for (row = 0; row < srcHeight; row++) {
- _mesa_unpack_color_span_float(ctx, srcWidth, logicalBaseFormat,
- dst, srcFormat, srcType, src,
- srcPacking, transferOps);
- dst += srcWidth * components;
- src += srcStride;
- }
- }
-
- if (logicalBaseFormat != textureBaseFormat) {
- /* more work */
- GLint texComponents = _mesa_components_in_format(textureBaseFormat);
- GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
- GLfloat *newImage;
- GLint i, n;
- GLubyte map[6];
-
- /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
- ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
- textureBaseFormat == GL_LUMINANCE_ALPHA);
-
- /* The actual texture format should have at least as many components
- * as the logical texture format.
- */
- ASSERT(texComponents >= logComponents);
-
- newImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
- * texComponents * sizeof(GLfloat));
- if (!newImage) {
- free(tempImage);
- return NULL;
- }
-
- compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
-
- n = srcWidth * srcHeight * srcDepth;
- for (i = 0; i < n; i++) {
- GLint k;
- for (k = 0; k < texComponents; k++) {
- GLint j = map[k];
- if (j == ZERO)
- newImage[i * texComponents + k] = 0.0F;
- else if (j == ONE)
- newImage[i * texComponents + k] = 1.0F;
- else
- newImage[i * texComponents + k] = tempImage[i * logComponents + j];
- }
- }
-
- free(tempImage);
- tempImage = newImage;
- }
-
- return tempImage;
-}
-
-
-/**
- * Make temporary image with uint pixel values. Used for unsigned
- * integer-valued textures.
- */
-static GLuint *
-make_temp_uint_image(struct gl_context *ctx, GLuint dims,
- GLenum logicalBaseFormat,
- GLenum textureBaseFormat,
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- GLenum srcFormat, GLenum srcType,
- const GLvoid *srcAddr,
- const struct gl_pixelstore_attrib *srcPacking)
-{
- GLuint *tempImage;
- const GLint components = _mesa_components_in_format(logicalBaseFormat);
- const GLint srcStride =
- _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
- GLuint *dst;
- GLint img, row;
-
- ASSERT(dims >= 1 && dims <= 3);
-
- ASSERT(logicalBaseFormat == GL_RGBA ||
- logicalBaseFormat == GL_RGB ||
- logicalBaseFormat == GL_RG ||
- logicalBaseFormat == GL_RED ||
- logicalBaseFormat == GL_LUMINANCE_ALPHA ||
- logicalBaseFormat == GL_LUMINANCE ||
- logicalBaseFormat == GL_INTENSITY ||
- logicalBaseFormat == GL_ALPHA);
-
- ASSERT(textureBaseFormat == GL_RGBA ||
- textureBaseFormat == GL_RGB ||
- textureBaseFormat == GL_RG ||
- textureBaseFormat == GL_RED ||
- textureBaseFormat == GL_LUMINANCE_ALPHA ||
- textureBaseFormat == GL_LUMINANCE ||
- textureBaseFormat == GL_ALPHA);
-
- tempImage = (GLuint *) malloc(srcWidth * srcHeight * srcDepth
- * components * sizeof(GLuint));
- if (!tempImage)
- return NULL;
-
- dst = tempImage;
- for (img = 0; img < srcDepth; img++) {
- const GLubyte *src
- = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
- srcWidth, srcHeight,
- srcFormat, srcType,
- img, 0, 0);
- for (row = 0; row < srcHeight; row++) {
- _mesa_unpack_color_span_uint(ctx, srcWidth, logicalBaseFormat,
- dst, srcFormat, srcType, src,
- srcPacking);
- dst += srcWidth * components;
- src += srcStride;
- }
- }
-
- if (logicalBaseFormat != textureBaseFormat) {
- /* more work */
- GLint texComponents = _mesa_components_in_format(textureBaseFormat);
- GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
- GLuint *newImage;
- GLint i, n;
- GLubyte map[6];
-
- /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
- ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
- textureBaseFormat == GL_LUMINANCE_ALPHA);
-
- /* The actual texture format should have at least as many components
- * as the logical texture format.
- */
- ASSERT(texComponents >= logComponents);
-
- newImage = (GLuint *) malloc(srcWidth * srcHeight * srcDepth
- * texComponents * sizeof(GLuint));
- if (!newImage) {
- free(tempImage);
- return NULL;
- }
-
- compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
-
- n = srcWidth * srcHeight * srcDepth;
- for (i = 0; i < n; i++) {
- GLint k;
- for (k = 0; k < texComponents; k++) {
- GLint j = map[k];
- if (j == ZERO)
- newImage[i * texComponents + k] = 0.0F;
- else if (j == ONE)
- newImage[i * texComponents + k] = 1.0F;
- else
- newImage[i * texComponents + k] = tempImage[i * logComponents + j];
- }
- }
-
- free(tempImage);
- tempImage = newImage;
- }
-
- return tempImage;
-}
-
-
-
-/**
- * Make a temporary (color) texture image with GLchan components.
- * Apply all needed pixel unpacking and pixel transfer operations.
- * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
- * Suppose the user specifies GL_LUMINANCE as the internal texture format
- * but the graphics hardware doesn't support luminance textures. So, we might
- * use an RGB hardware format instead.
- * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
- *
- * \param ctx the rendering context
- * \param dims image dimensions: 1, 2 or 3
- * \param logicalBaseFormat basic texture derived from the user's
- * internal texture format value
- * \param textureBaseFormat the actual basic format of the texture
- * \param srcWidth source image width
- * \param srcHeight source image height
- * \param srcDepth source image depth
- * \param srcFormat source image format
- * \param srcType source image type
- * \param srcAddr source image address
- * \param srcPacking source image pixel packing
- * \return resulting image with format = textureBaseFormat and type = GLchan.
- */
-GLchan *
-_mesa_make_temp_chan_image(struct gl_context *ctx, GLuint dims,
- GLenum logicalBaseFormat,
- GLenum textureBaseFormat,
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- GLenum srcFormat, GLenum srcType,
- const GLvoid *srcAddr,
- const struct gl_pixelstore_attrib *srcPacking)
-{
- GLuint transferOps = ctx->_ImageTransferState;
- const GLint components = _mesa_components_in_format(logicalBaseFormat);
- GLint img, row;
- GLchan *tempImage, *dst;
-
- ASSERT(dims >= 1 && dims <= 3);
-
- ASSERT(logicalBaseFormat == GL_RGBA ||
- logicalBaseFormat == GL_RGB ||
- logicalBaseFormat == GL_RG ||
- logicalBaseFormat == GL_RED ||
- logicalBaseFormat == GL_LUMINANCE_ALPHA ||
- logicalBaseFormat == GL_LUMINANCE ||
- logicalBaseFormat == GL_ALPHA ||
- logicalBaseFormat == GL_INTENSITY);
-
- ASSERT(textureBaseFormat == GL_RGBA ||
- textureBaseFormat == GL_RGB ||
- textureBaseFormat == GL_RG ||
- textureBaseFormat == GL_RED ||
- textureBaseFormat == GL_LUMINANCE_ALPHA ||
- textureBaseFormat == GL_LUMINANCE ||
- textureBaseFormat == GL_ALPHA ||
- textureBaseFormat == GL_INTENSITY);
-
- /* unpack and transfer the source image */
- tempImage = (GLchan *) malloc(srcWidth * srcHeight * srcDepth
- * components * sizeof(GLchan));
- if (!tempImage) {
- return NULL;
- }
-
- dst = tempImage;
- for (img = 0; img < srcDepth; img++) {
- const GLint srcStride =
- _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
- const GLubyte *src =
- (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
- srcWidth, srcHeight,
- srcFormat, srcType,
- img, 0, 0);
- for (row = 0; row < srcHeight; row++) {
- _mesa_unpack_color_span_chan(ctx, srcWidth, logicalBaseFormat, dst,
- srcFormat, srcType, src, srcPacking,
- transferOps);
- dst += srcWidth * components;
- src += srcStride;
- }
- }
-
- if (logicalBaseFormat != textureBaseFormat) {
- /* one more conversion step */
- GLint texComponents = _mesa_components_in_format(textureBaseFormat);
- GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
- GLchan *newImage;
- GLint i, n;
- GLubyte map[6];
-
- /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
- ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
- textureBaseFormat == GL_LUMINANCE_ALPHA);
-
- /* The actual texture format should have at least as many components
- * as the logical texture format.
- */
- ASSERT(texComponents >= logComponents);
-
- newImage = (GLchan *) malloc(srcWidth * srcHeight * srcDepth
- * texComponents * sizeof(GLchan));
- if (!newImage) {
- free(tempImage);
- return NULL;
- }
-
- compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
-
- n = srcWidth * srcHeight * srcDepth;
- for (i = 0; i < n; i++) {
- GLint k;
- for (k = 0; k < texComponents; k++) {
- GLint j = map[k];
- if (j == ZERO)
- newImage[i * texComponents + k] = 0;
- else if (j == ONE)
- newImage[i * texComponents + k] = CHAN_MAX;
- else
- newImage[i * texComponents + k] = tempImage[i * logComponents + j];
- }
- }
-
- free(tempImage);
- tempImage = newImage;
- }
-
- return tempImage;
-}
-
-
-/**
- * Copy GLubyte pixels from <src> to <dst> with swizzling.
- * \param dst destination pixels
- * \param dstComponents number of color components in destination pixels
- * \param src source pixels
- * \param srcComponents number of color components in source pixels
- * \param map the swizzle mapping. map[X] says where to find the X component
- * in the source image's pixels. For example, if the source image
- * is GL_BGRA and X = red, map[0] yields 2.
- * \param count number of pixels to copy/swizzle.
- */
-static void
-swizzle_copy(GLubyte *dst, GLuint dstComponents, const GLubyte *src,
- GLuint srcComponents, const GLubyte *map, GLuint count)
-{
-#define SWZ_CPY(dst, src, count, dstComps, srcComps) \
- do { \
- GLuint i; \
- for (i = 0; i < count; i++) { \
- GLuint j; \
- if (srcComps == 4) { \
- COPY_4UBV(tmp, src); \
- } \
- else { \
- for (j = 0; j < srcComps; j++) { \
- tmp[j] = src[j]; \
- } \
- } \
- src += srcComps; \
- for (j = 0; j < dstComps; j++) { \
- dst[j] = tmp[map[j]]; \
- } \
- dst += dstComps; \
- } \
- } while (0)
-
- GLubyte tmp[6];
-
- tmp[ZERO] = 0x0;
- tmp[ONE] = 0xff;
-
- ASSERT(srcComponents <= 4);
- ASSERT(dstComponents <= 4);
-
- switch (dstComponents) {
- case 4:
- switch (srcComponents) {
- case 4:
- SWZ_CPY(dst, src, count, 4, 4);
- break;
- case 3:
- SWZ_CPY(dst, src, count, 4, 3);
- break;
- case 2:
- SWZ_CPY(dst, src, count, 4, 2);
- break;
- case 1:
- SWZ_CPY(dst, src, count, 4, 1);
- break;
- default:
- ;
- }
- break;
- case 3:
- switch (srcComponents) {
- case 4:
- SWZ_CPY(dst, src, count, 3, 4);
- break;
- case 3:
- SWZ_CPY(dst, src, count, 3, 3);
- break;
- case 2:
- SWZ_CPY(dst, src, count, 3, 2);
- break;
- case 1:
- SWZ_CPY(dst, src, count, 3, 1);
- break;
- default:
- ;
- }
- break;
- case 2:
- switch (srcComponents) {
- case 4:
- SWZ_CPY(dst, src, count, 2, 4);
- break;
- case 3:
- SWZ_CPY(dst, src, count, 2, 3);
- break;
- case 2:
- SWZ_CPY(dst, src, count, 2, 2);
- break;
- case 1:
- SWZ_CPY(dst, src, count, 2, 1);
- break;
- default:
- ;
- }
- break;
- case 1:
- switch (srcComponents) {
- case 4:
- SWZ_CPY(dst, src, count, 1, 4);
- break;
- case 3:
- SWZ_CPY(dst, src, count, 1, 3);
- break;
- case 2:
- SWZ_CPY(dst, src, count, 1, 2);
- break;
- case 1:
- SWZ_CPY(dst, src, count, 1, 1);
- break;
- default:
- ;
- }
- break;
- default:
- ;
- }
-#undef SWZ_CPY
-}
-
-
-
-static const GLubyte map_identity[6] = { 0, 1, 2, 3, ZERO, ONE };
-static const GLubyte map_3210[6] = { 3, 2, 1, 0, ZERO, ONE };
-
-
-/**
- * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
- * mapping array depending on endianness.
- */
-static const GLubyte *
-type_mapping( GLenum srcType )
-{
- switch (srcType) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- return map_identity;
- case GL_UNSIGNED_INT_8_8_8_8:
- return _mesa_little_endian() ? map_3210 : map_identity;
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- return _mesa_little_endian() ? map_identity : map_3210;
- default:
- return NULL;
- }
-}
-
-
-/**
- * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
- * mapping array depending on pixelstore byte swapping state.
- */
-static const GLubyte *
-byteswap_mapping( GLboolean swapBytes,
- GLenum srcType )
-{
- if (!swapBytes)
- return map_identity;
-
- switch (srcType) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- return map_identity;
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- return map_3210;
- default:
- return NULL;
- }
-}
-
-
-
-/**
- * Transfer a GLubyte texture image with component swizzling.
- */
-static void
-_mesa_swizzle_ubyte_image(struct gl_context *ctx,
- GLuint dimensions,
- GLenum srcFormat,
- GLenum srcType,
-
- GLenum baseInternalFormat,
-
- const GLubyte *rgba2dst,
- GLuint dstComponents,
-
- GLvoid *dstAddr,
- GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
- GLint dstRowStride,
- const GLuint *dstImageOffsets,
-
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- const GLvoid *srcAddr,
- const struct gl_pixelstore_attrib *srcPacking )
-{
- GLint srcComponents = _mesa_components_in_format(srcFormat);
- const GLubyte *srctype2ubyte, *swap;
- GLubyte map[4], src2base[6], base2rgba[6];
- GLint i;
- const GLint srcRowStride =
- _mesa_image_row_stride(srcPacking, srcWidth,
- srcFormat, GL_UNSIGNED_BYTE);
- const GLint srcImageStride
- = _mesa_image_image_stride(srcPacking, srcWidth, srcHeight, srcFormat,
- GL_UNSIGNED_BYTE);
- const GLubyte *srcImage
- = (const GLubyte *) _mesa_image_address(dimensions, srcPacking, srcAddr,
- srcWidth, srcHeight, srcFormat,
- GL_UNSIGNED_BYTE, 0, 0, 0);
-
- (void) ctx;
-
- /* Translate from src->baseInternal->GL_RGBA->dst. This will
- * correctly deal with RGBA->RGB->RGBA conversions where the final
- * A value must be 0xff regardless of the incoming alpha values.
- */
- compute_component_mapping(srcFormat, baseInternalFormat, src2base);
- compute_component_mapping(baseInternalFormat, GL_RGBA, base2rgba);
- swap = byteswap_mapping(srcPacking->SwapBytes, srcType);
- srctype2ubyte = type_mapping(srcType);
-
-
- for (i = 0; i < 4; i++)
- map[i] = srctype2ubyte[swap[src2base[base2rgba[rgba2dst[i]]]]];
-
-/* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
-
- if (srcComponents == dstComponents &&
- srcRowStride == dstRowStride &&
- srcRowStride == srcWidth * srcComponents &&
- dimensions < 3) {
- /* 1 and 2D images only */
- GLubyte *dstImage = (GLubyte *) dstAddr
- + dstYoffset * dstRowStride
- + dstXoffset * dstComponents;
- swizzle_copy(dstImage, dstComponents, srcImage, srcComponents, map,
- srcWidth * srcHeight);
- }
- else {
- GLint img, row;
- for (img = 0; img < srcDepth; img++) {
- const GLubyte *srcRow = srcImage;
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * dstComponents
- + dstYoffset * dstRowStride
- + dstXoffset * dstComponents;
- for (row = 0; row < srcHeight; row++) {
- swizzle_copy(dstRow, dstComponents, srcRow, srcComponents, map, srcWidth);
- dstRow += dstRowStride;
- srcRow += srcRowStride;
- }
- srcImage += srcImageStride;
- }
- }
-}
-
-
-/**
- * Teximage storage routine for when a simple memcpy will do.
- * No pixel transfer operations or special texel encodings allowed.
- * 1D, 2D and 3D images supported.
- */
-static void
-memcpy_texture(struct gl_context *ctx,
- GLuint dimensions,
- gl_format dstFormat,
- GLvoid *dstAddr,
- GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
- GLint dstRowStride,
- const GLuint *dstImageOffsets,
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- GLenum srcFormat, GLenum srcType,
- const GLvoid *srcAddr,
- const struct gl_pixelstore_attrib *srcPacking)
-{
- const GLint srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth,
- srcFormat, srcType);
- const GLint srcImageStride = _mesa_image_image_stride(srcPacking,
- srcWidth, srcHeight, srcFormat, srcType);
- const GLubyte *srcImage = (const GLubyte *) _mesa_image_address(dimensions,
- srcPacking, srcAddr, srcWidth, srcHeight, srcFormat, srcType, 0, 0, 0);
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLint bytesPerRow = srcWidth * texelBytes;
-
-#if 0
- /* XXX update/re-enable for dstImageOffsets array */
- const GLint bytesPerImage = srcHeight * bytesPerRow;
- const GLint bytesPerTexture = srcDepth * bytesPerImage;
- GLubyte *dstImage = (GLubyte *) dstAddr
- + dstZoffset * dstImageStride
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
-
- if (dstRowStride == srcRowStride &&
- dstRowStride == bytesPerRow &&
- ((dstImageStride == srcImageStride &&
- dstImageStride == bytesPerImage) ||
- (srcDepth == 1))) {
- /* one big memcpy */
- ctx->Driver.TextureMemCpy(dstImage, srcImage, bytesPerTexture);
- }
- else
- {
- GLint img, row;
- for (img = 0; img < srcDepth; img++) {
- const GLubyte *srcRow = srcImage;
- GLubyte *dstRow = dstImage;
- for (row = 0; row < srcHeight; row++) {
- ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);
- dstRow += dstRowStride;
- srcRow += srcRowStride;
- }
- srcImage += srcImageStride;
- dstImage += dstImageStride;
- }
- }
-#endif
-
- GLint img, row;
- for (img = 0; img < srcDepth; img++) {
- const GLubyte *srcRow = srcImage;
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);
- dstRow += dstRowStride;
- srcRow += srcRowStride;
- }
- srcImage += srcImageStride;
- }
-}
-
-
-
-/**
- * Store a 32-bit integer depth component texture image.
- */
-static GLboolean
-_mesa_texstore_z32(TEXSTORE_PARAMS)
-{
- const GLuint depthScale = 0xffffffff;
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- (void) dims;
- ASSERT(dstFormat == MESA_FORMAT_Z32);
- ASSERT(texelBytes == sizeof(GLuint));
-
- if (ctx->Pixel.DepthScale == 1.0f &&
- ctx->Pixel.DepthBias == 0.0f &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == GL_DEPTH_COMPONENT &&
- srcFormat == GL_DEPTH_COMPONENT &&
- srcType == GL_UNSIGNED_INT) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- GLint img, row;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- const GLvoid *src = _mesa_image_address(dims, srcPacking,
- srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
- _mesa_unpack_depth_span(ctx, srcWidth,
- GL_UNSIGNED_INT, (GLuint *) dstRow,
- depthScale, srcType, src, srcPacking);
- dstRow += dstRowStride;
- }
- }
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store a 24-bit integer depth component texture image.
- */
-static GLboolean
-_mesa_texstore_x8_z24(TEXSTORE_PARAMS)
-{
- const GLuint depthScale = 0xffffff;
- const GLuint texelBytes = 4;
-
- (void) dims;
- ASSERT(dstFormat == MESA_FORMAT_X8_Z24);
-
- {
- /* general path */
- GLint img, row;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- const GLvoid *src = _mesa_image_address(dims, srcPacking,
- srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
- _mesa_unpack_depth_span(ctx, srcWidth,
- GL_UNSIGNED_INT, (GLuint *) dstRow,
- depthScale, srcType, src, srcPacking);
- dstRow += dstRowStride;
- }
- }
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store a 24-bit integer depth component texture image.
- */
-static GLboolean
-_mesa_texstore_z24_x8(TEXSTORE_PARAMS)
-{
- const GLuint depthScale = 0xffffff;
- const GLuint texelBytes = 4;
-
- (void) dims;
- ASSERT(dstFormat == MESA_FORMAT_Z24_X8);
-
- {
- /* general path */
- GLint img, row;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- const GLvoid *src = _mesa_image_address(dims, srcPacking,
- srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
- GLuint *dst = (GLuint *) dstRow;
- GLint i;
- _mesa_unpack_depth_span(ctx, srcWidth,
- GL_UNSIGNED_INT, dst,
- depthScale, srcType, src, srcPacking);
- for (i = 0; i < srcWidth; i++)
- dst[i] <<= 8;
- dstRow += dstRowStride;
- }
- }
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store a 16-bit integer depth component texture image.
- */
-static GLboolean
-_mesa_texstore_z16(TEXSTORE_PARAMS)
-{
- const GLuint depthScale = 0xffff;
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- (void) dims;
- ASSERT(dstFormat == MESA_FORMAT_Z16);
- ASSERT(texelBytes == sizeof(GLushort));
-
- if (ctx->Pixel.DepthScale == 1.0f &&
- ctx->Pixel.DepthBias == 0.0f &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == GL_DEPTH_COMPONENT &&
- srcFormat == GL_DEPTH_COMPONENT &&
- srcType == GL_UNSIGNED_SHORT) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- GLint img, row;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- const GLvoid *src = _mesa_image_address(dims, srcPacking,
- srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
- GLushort *dst16 = (GLushort *) dstRow;
- _mesa_unpack_depth_span(ctx, srcWidth,
- GL_UNSIGNED_SHORT, dst16, depthScale,
- srcType, src, srcPacking);
- dstRow += dstRowStride;
- }
- }
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store an rgb565 or rgb565_rev texture image.
- */
-static GLboolean
-_mesa_texstore_rgb565(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGB565 ||
- dstFormat == MESA_FORMAT_RGB565_REV);
- ASSERT(texelBytes == 2);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_RGB565 &&
- baseInternalFormat == GL_RGB &&
- srcFormat == GL_RGB &&
- srcType == GL_UNSIGNED_SHORT_5_6_5) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == GL_RGB &&
- srcFormat == GL_RGB &&
- srcType == GL_UNSIGNED_BYTE &&
- dims == 2) {
- /* do optimized tex store */
- const GLint srcRowStride =
- _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
- const GLubyte *src = (const GLubyte *)
- _mesa_image_address(dims, srcPacking, srcAddr, srcWidth, srcHeight,
- srcFormat, srcType, 0, 0, 0);
- GLubyte *dst = (GLubyte *) dstAddr
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- GLint row, col;
- for (row = 0; row < srcHeight; row++) {
- const GLubyte *srcUB = (const GLubyte *) src;
- GLushort *dstUS = (GLushort *) dst;
- /* check for byteswapped format */
- if (dstFormat == MESA_FORMAT_RGB565) {
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_565( srcUB[0], srcUB[1], srcUB[2] );
- srcUB += 3;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_565_REV( srcUB[0], srcUB[1], srcUB[2] );
- srcUB += 3;
- }
- }
- dst += dstRowStride;
- src += srcRowStride;
- }
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstUS = (GLushort *) dstRow;
- /* check for byteswapped format */
- if (dstFormat == MESA_FORMAT_RGB565) {
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_565( CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]) );
- src += 3;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]) );
- src += 3;
- }
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
- */
-static GLboolean
-_mesa_texstore_rgba8888(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA8888 ||
- dstFormat == MESA_FORMAT_RGBA8888_REV);
- ASSERT(texelBytes == 4);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_RGBA8888 &&
- baseInternalFormat == GL_RGBA &&
- ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
- (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
- (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||
- (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && littleEndian))) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_RGBA8888_REV &&
- baseInternalFormat == GL_RGBA &&
- ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||
- (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && littleEndian) ||
- (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
- (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && !littleEndian))) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- (srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_UNSIGNED_INT_8_8_8_8 ||
- srcType == GL_UNSIGNED_INT_8_8_8_8_REV) &&
- can_swizzle(baseInternalFormat) &&
- can_swizzle(srcFormat)) {
-
- GLubyte dstmap[4];
-
- /* dstmap - how to swizzle from RGBA to dst format:
- */
- if ((littleEndian && dstFormat == MESA_FORMAT_RGBA8888) ||
- (!littleEndian && dstFormat == MESA_FORMAT_RGBA8888_REV)) {
- dstmap[3] = 0;
- dstmap[2] = 1;
- dstmap[1] = 2;
- dstmap[0] = 3;
- }
- else {
- dstmap[3] = 3;
- dstmap[2] = 2;
- dstmap[1] = 1;
- dstmap[0] = 0;
- }
-
- _mesa_swizzle_ubyte_image(ctx, dims,
- srcFormat,
- srcType,
- baseInternalFormat,
- dstmap, 4,
- dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcAddr,
- srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLuint *dstUI = (GLuint *) dstRow;
- if (dstFormat == MESA_FORMAT_RGBA8888) {
- for (col = 0; col < srcWidth; col++) {
- dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]),
- CHAN_TO_UBYTE(src[ACOMP]) );
- src += 4;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]),
- CHAN_TO_UBYTE(src[ACOMP]) );
- src += 4;
- }
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-static GLboolean
-_mesa_texstore_argb8888(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = GL_RGBA;
-
- ASSERT(dstFormat == MESA_FORMAT_ARGB8888 ||
- dstFormat == MESA_FORMAT_ARGB8888_REV ||
- dstFormat == MESA_FORMAT_XRGB8888 ||
- dstFormat == MESA_FORMAT_XRGB8888_REV );
- ASSERT(texelBytes == 4);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- (dstFormat == MESA_FORMAT_ARGB8888 ||
- dstFormat == MESA_FORMAT_XRGB8888) &&
- baseInternalFormat == GL_RGBA &&
- srcFormat == GL_BGRA &&
- ((srcType == GL_UNSIGNED_BYTE && littleEndian) ||
- srcType == GL_UNSIGNED_INT_8_8_8_8_REV)) {
- /* simple memcpy path (little endian) */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- (dstFormat == MESA_FORMAT_ARGB8888_REV ||
- dstFormat == MESA_FORMAT_XRGB8888_REV) &&
- baseInternalFormat == GL_RGBA &&
- srcFormat == GL_BGRA &&
- ((srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
- srcType == GL_UNSIGNED_INT_8_8_8_8)) {
- /* simple memcpy path (big endian) */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- (dstFormat == MESA_FORMAT_ARGB8888 ||
- dstFormat == MESA_FORMAT_XRGB8888) &&
- srcFormat == GL_RGB &&
- (baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB) &&
- srcType == GL_UNSIGNED_BYTE) {
- int img, row, col;
- for (img = 0; img < srcDepth; img++) {
- const GLint srcRowStride =
- _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
- GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
- srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLuint *d4 = (GLuint *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- d4[col] = PACK_COLOR_8888(0xff,
- srcRow[col * 3 + RCOMP],
- srcRow[col * 3 + GCOMP],
- srcRow[col * 3 + BCOMP]);
- }
- dstRow += dstRowStride;
- srcRow += srcRowStride;
- }
- }
- }
- else if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_ARGB8888 &&
- srcFormat == GL_RGBA &&
- baseInternalFormat == GL_RGBA &&
- srcType == GL_UNSIGNED_BYTE) {
- /* same as above case, but src data has alpha too */
- GLint img, row, col;
- /* For some reason, streaming copies to write-combined regions
- * are extremely sensitive to the characteristics of how the
- * source data is retrieved. By reordering the source reads to
- * be in-order, the speed of this operation increases by half.
- * Strangely the same isn't required for the RGB path, above.
- */
- for (img = 0; img < srcDepth; img++) {
- const GLint srcRowStride =
- _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
- GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
- srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLuint *d4 = (GLuint *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- d4[col] = PACK_COLOR_8888(srcRow[col * 4 + ACOMP],
- srcRow[col * 4 + RCOMP],
- srcRow[col * 4 + GCOMP],
- srcRow[col * 4 + BCOMP]);
- }
- dstRow += dstRowStride;
- srcRow += srcRowStride;
- }
- }
- }
- else if (!ctx->_ImageTransferState &&
- (srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_UNSIGNED_INT_8_8_8_8 ||
- srcType == GL_UNSIGNED_INT_8_8_8_8_REV) &&
- can_swizzle(baseInternalFormat) &&
- can_swizzle(srcFormat)) {
-
- GLubyte dstmap[4];
-
- /* dstmap - how to swizzle from RGBA to dst format:
- */
- if ((littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
- (littleEndian && dstFormat == MESA_FORMAT_XRGB8888) ||
- (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
- (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888_REV)) {
- dstmap[3] = 3; /* alpha */
- dstmap[2] = 0; /* red */
- dstmap[1] = 1; /* green */
- dstmap[0] = 2; /* blue */
- }
- else {
- assert((littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
- (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
- (littleEndian && dstFormat == MESA_FORMAT_XRGB8888_REV) ||
- (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888));
- dstmap[3] = 2;
- dstmap[2] = 1;
- dstmap[1] = 0;
- dstmap[0] = 3;
- }
-
- _mesa_swizzle_ubyte_image(ctx, dims,
- srcFormat,
- srcType,
- baseInternalFormat,
- dstmap, 4,
- dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcAddr,
- srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLuint *dstUI = (GLuint *) dstRow;
- if (dstFormat == MESA_FORMAT_ARGB8888) {
- for (col = 0; col < srcWidth; col++) {
- dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[ACOMP]),
- CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]) );
- src += 4;
- }
- }
- else if (dstFormat == MESA_FORMAT_XRGB8888) {
- for (col = 0; col < srcWidth; col++) {
- dstUI[col] = PACK_COLOR_8888( 0xff,
- CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]) );
- src += 4;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[ACOMP]),
- CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]) );
- src += 4;
- }
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-static GLboolean
-_mesa_texstore_rgb888(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGB888);
- ASSERT(texelBytes == 3);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == GL_RGB &&
- srcFormat == GL_BGR &&
- srcType == GL_UNSIGNED_BYTE &&
- littleEndian) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- srcFormat == GL_RGBA &&
- srcType == GL_UNSIGNED_BYTE) {
- /* extract RGB from RGBA */
- GLint img, row, col;
- for (img = 0; img < srcDepth; img++) {
- const GLint srcRowStride =
- _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
- GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
- srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- for (col = 0; col < srcWidth; col++) {
- dstRow[col * 3 + 0] = srcRow[col * 4 + BCOMP];
- dstRow[col * 3 + 1] = srcRow[col * 4 + GCOMP];
- dstRow[col * 3 + 2] = srcRow[col * 4 + RCOMP];
- }
- dstRow += dstRowStride;
- srcRow += srcRowStride;
- }
- }
- }
- else if (!ctx->_ImageTransferState &&
- srcType == GL_UNSIGNED_BYTE &&
- can_swizzle(baseInternalFormat) &&
- can_swizzle(srcFormat)) {
-
- GLubyte dstmap[4];
-
- /* dstmap - how to swizzle from RGBA to dst format:
- */
- dstmap[0] = 2;
- dstmap[1] = 1;
- dstmap[2] = 0;
- dstmap[3] = ONE; /* ? */
-
- _mesa_swizzle_ubyte_image(ctx, dims,
- srcFormat,
- srcType,
- baseInternalFormat,
- dstmap, 3,
- dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcAddr,
- srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = (const GLchan *) tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
-#if 0
- if (littleEndian) {
- for (col = 0; col < srcWidth; col++) {
- dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[RCOMP]);
- dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
- dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[BCOMP]);
- srcUB += 3;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- dstRow[col * 3 + 0] = srcUB[BCOMP];
- dstRow[col * 3 + 1] = srcUB[GCOMP];
- dstRow[col * 3 + 2] = srcUB[RCOMP];
- srcUB += 3;
- }
- }
-#else
- for (col = 0; col < srcWidth; col++) {
- dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[BCOMP]);
- dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
- dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[RCOMP]);
- src += 3;
- }
-#endif
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-static GLboolean
-_mesa_texstore_bgr888(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_BGR888);
- ASSERT(texelBytes == 3);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == GL_RGB &&
- srcFormat == GL_RGB &&
- srcType == GL_UNSIGNED_BYTE &&
- littleEndian) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- srcFormat == GL_RGBA &&
- srcType == GL_UNSIGNED_BYTE) {
- /* extract BGR from RGBA */
- int img, row, col;
- for (img = 0; img < srcDepth; img++) {
- const GLint srcRowStride =
- _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
- GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
- srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- for (col = 0; col < srcWidth; col++) {
- dstRow[col * 3 + 0] = srcRow[col * 4 + RCOMP];
- dstRow[col * 3 + 1] = srcRow[col * 4 + GCOMP];
- dstRow[col * 3 + 2] = srcRow[col * 4 + BCOMP];
- }
- dstRow += dstRowStride;
- srcRow += srcRowStride;
- }
- }
- }
- else if (!ctx->_ImageTransferState &&
- srcType == GL_UNSIGNED_BYTE &&
- can_swizzle(baseInternalFormat) &&
- can_swizzle(srcFormat)) {
-
- GLubyte dstmap[4];
-
- /* dstmap - how to swizzle from RGBA to dst format:
- */
- dstmap[0] = 0;
- dstmap[1] = 1;
- dstmap[2] = 2;
- dstmap[3] = ONE; /* ? */
-
- _mesa_swizzle_ubyte_image(ctx, dims,
- srcFormat,
- srcType,
- baseInternalFormat,
- dstmap, 3,
- dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcAddr,
- srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = (const GLchan *) tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- for (col = 0; col < srcWidth; col++) {
- dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[RCOMP]);
- dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
- dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[BCOMP]);
- src += 3;
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-static GLboolean
-_mesa_texstore_argb4444(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_ARGB4444 ||
- dstFormat == MESA_FORMAT_ARGB4444_REV);
- ASSERT(texelBytes == 2);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_ARGB4444 &&
- baseInternalFormat == GL_RGBA &&
- srcFormat == GL_BGRA &&
- srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstUS = (GLushort *) dstRow;
- if (dstFormat == MESA_FORMAT_ARGB4444) {
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_4444( CHAN_TO_UBYTE(src[ACOMP]),
- CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]) );
- src += 4;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src[ACOMP]),
- CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]) );
- src += 4;
- }
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-static GLboolean
-_mesa_texstore_rgba5551(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA5551);
- ASSERT(texelBytes == 2);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_RGBA5551 &&
- baseInternalFormat == GL_RGBA &&
- srcFormat == GL_RGBA &&
- srcType == GL_UNSIGNED_SHORT_5_5_5_1) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src =tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstUS = (GLushort *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_5551( CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]),
- CHAN_TO_UBYTE(src[ACOMP]) );
- src += 4;
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-static GLboolean
-_mesa_texstore_argb1555(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_ARGB1555 ||
- dstFormat == MESA_FORMAT_ARGB1555_REV);
- ASSERT(texelBytes == 2);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_ARGB1555 &&
- baseInternalFormat == GL_RGBA &&
- srcFormat == GL_BGRA &&
- srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src =tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstUS = (GLushort *) dstRow;
- if (dstFormat == MESA_FORMAT_ARGB1555) {
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_1555( CHAN_TO_UBYTE(src[ACOMP]),
- CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]) );
- src += 4;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src[ACOMP]),
- CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]) );
- src += 4;
- }
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-static GLboolean
-_mesa_texstore_argb2101010(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_ARGB2101010);
- ASSERT(texelBytes == 4);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_ARGB2101010 &&
- srcFormat == GL_BGRA &&
- srcType == GL_UNSIGNED_INT_2_10_10_10_REV &&
- baseInternalFormat == GL_RGBA) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- if (baseInternalFormat == GL_RGBA) {
- for (row = 0; row < srcHeight; row++) {
- GLuint *dstUI = (GLuint *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- GLushort a,r,g,b;
-
- UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]);
- UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
- UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
- UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]);
- dstUI[col] = PACK_COLOR_2101010_US(a, r, g, b);
- src += 4;
- }
- dstRow += dstRowStride;
- }
- } else if (baseInternalFormat == GL_RGB) {
- for (row = 0; row < srcHeight; row++) {
- GLuint *dstUI = (GLuint *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- GLushort r,g,b;
-
- UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
- UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
- UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]);
- dstUI[col] = PACK_COLOR_2101010_US(0xffff, r, g, b);
- src += 4;
- }
- dstRow += dstRowStride;
- }
- } else {
- ASSERT(0);
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
- */
-static GLboolean
-_mesa_texstore_unorm44(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_AL44);
- ASSERT(texelBytes == 1);
-
- {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLubyte *dstUS = (GLubyte *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- /* src[0] is luminance, src[1] is alpha */
- dstUS[col] = PACK_COLOR_44( CHAN_TO_UBYTE(src[1]),
- CHAN_TO_UBYTE(src[0]) );
- src += 2;
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
- */
-static GLboolean
-_mesa_texstore_unorm88(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_AL88 ||
- dstFormat == MESA_FORMAT_AL88_REV ||
- dstFormat == MESA_FORMAT_RG88 ||
- dstFormat == MESA_FORMAT_RG88_REV);
- ASSERT(texelBytes == 2);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- (dstFormat == MESA_FORMAT_AL88 || dstFormat == MESA_FORMAT_RG88) &&
- baseInternalFormat == srcFormat &&
- srcType == GL_UNSIGNED_BYTE &&
- littleEndian) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- littleEndian &&
- srcType == GL_UNSIGNED_BYTE &&
- can_swizzle(baseInternalFormat) &&
- can_swizzle(srcFormat)) {
- GLubyte dstmap[4];
-
- /* dstmap - how to swizzle from RGBA to dst format:
- */
- if (dstFormat == MESA_FORMAT_AL88 || dstFormat == MESA_FORMAT_AL88_REV) {
- if ((littleEndian && dstFormat == MESA_FORMAT_AL88) ||
- (!littleEndian && dstFormat == MESA_FORMAT_AL88_REV)) {
- dstmap[0] = 0;
- dstmap[1] = 3;
- }
- else {
- dstmap[0] = 3;
- dstmap[1] = 0;
- }
- }
- else {
- if ((littleEndian && dstFormat == MESA_FORMAT_RG88) ||
- (!littleEndian && dstFormat == MESA_FORMAT_RG88_REV)) {
- dstmap[0] = 0;
- dstmap[1] = 1;
- }
- else {
- dstmap[0] = 1;
- dstmap[1] = 0;
- }
- }
- dstmap[2] = ZERO; /* ? */
- dstmap[3] = ONE; /* ? */
-
- _mesa_swizzle_ubyte_image(ctx, dims,
- srcFormat,
- srcType,
- baseInternalFormat,
- dstmap, 2,
- dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcAddr,
- srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstUS = (GLushort *) dstRow;
- if (dstFormat == MESA_FORMAT_AL88 ||
- dstFormat == MESA_FORMAT_RG88) {
- for (col = 0; col < srcWidth; col++) {
- /* src[0] is luminance, src[1] is alpha */
- dstUS[col] = PACK_COLOR_88( CHAN_TO_UBYTE(src[1]),
- CHAN_TO_UBYTE(src[0]) );
- src += 2;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- /* src[0] is luminance, src[1] is alpha */
- dstUS[col] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src[1]),
- CHAN_TO_UBYTE(src[0]) );
- src += 2;
- }
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
- */
-static GLboolean
-_mesa_texstore_unorm1616(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_AL1616 ||
- dstFormat == MESA_FORMAT_AL1616_REV ||
- dstFormat == MESA_FORMAT_RG1616 ||
- dstFormat == MESA_FORMAT_RG1616_REV);
- ASSERT(texelBytes == 4);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- (dstFormat == MESA_FORMAT_AL1616 || dstFormat == MESA_FORMAT_RG1616) &&
- baseInternalFormat == srcFormat &&
- srcType == GL_UNSIGNED_SHORT &&
- littleEndian) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLuint *dstUI = (GLuint *) dstRow;
- if (dstFormat == MESA_FORMAT_AL1616 ||
- dstFormat == MESA_FORMAT_RG1616) {
- for (col = 0; col < srcWidth; col++) {
- GLushort l, a;
-
- UNCLAMPED_FLOAT_TO_USHORT(l, src[0]);
- UNCLAMPED_FLOAT_TO_USHORT(a, src[1]);
- dstUI[col] = PACK_COLOR_1616(a, l);
- src += 2;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- GLushort l, a;
-
- UNCLAMPED_FLOAT_TO_USHORT(l, src[0]);
- UNCLAMPED_FLOAT_TO_USHORT(a, src[1]);
- dstUI[col] = PACK_COLOR_1616_REV(a, l);
- src += 2;
- }
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/* Texstore for R16, A16, L16, I16. */
-static GLboolean
-_mesa_texstore_unorm16(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_R16 ||
- dstFormat == MESA_FORMAT_A16 ||
- dstFormat == MESA_FORMAT_L16 ||
- dstFormat == MESA_FORMAT_I16);
- ASSERT(texelBytes == 2);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_UNSIGNED_SHORT &&
- littleEndian) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstUS = (GLushort *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- GLushort r;
-
- UNCLAMPED_FLOAT_TO_USHORT(r, src[0]);
- dstUS[col] = r;
- src += 1;
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-static GLboolean
-_mesa_texstore_rgba_16(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA_16);
- ASSERT(texelBytes == 8);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == GL_RGBA &&
- srcFormat == GL_RGBA &&
- srcType == GL_UNSIGNED_SHORT) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstUS = (GLushort *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- GLushort r, g, b, a;
-
- UNCLAMPED_FLOAT_TO_USHORT(r, src[0]);
- UNCLAMPED_FLOAT_TO_USHORT(g, src[1]);
- UNCLAMPED_FLOAT_TO_USHORT(b, src[2]);
- UNCLAMPED_FLOAT_TO_USHORT(a, src[3]);
- dstUS[col*4+0] = r;
- dstUS[col*4+1] = g;
- dstUS[col*4+2] = b;
- dstUS[col*4+3] = a;
- src += 4;
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-static GLboolean
-_mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_SIGNED_R_16 ||
- dstFormat == MESA_FORMAT_SIGNED_RG_16 ||
- dstFormat == MESA_FORMAT_SIGNED_RGB_16 ||
- dstFormat == MESA_FORMAT_SIGNED_RGBA_16);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == GL_RGBA &&
- dstFormat == MESA_FORMAT_SIGNED_RGBA_16 &&
- srcFormat == GL_RGBA &&
- srcType == GL_SHORT) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *src = tempImage;
- const GLuint comps = _mesa_get_format_bytes(dstFormat) / 2;
- GLint img, row, col;
-
- if (!tempImage)
- return GL_FALSE;
-
- /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
- * 3 or 4 components/pixel here.
- */
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLshort *dstRowS = (GLshort *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- GLuint c;
- for (c = 0; c < comps; c++) {
- GLshort p;
- UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 4 + c]);
- dstRowS[col * comps + c] = p;
- }
- }
- dstRow += dstRowStride;
- src += 4 * srcWidth;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-static GLboolean
-_mesa_texstore_rgb332(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGB332);
- ASSERT(texelBytes == 1);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == GL_RGB &&
- srcFormat == GL_RGB && srcType == GL_UNSIGNED_BYTE_3_3_2) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- for (col = 0; col < srcWidth; col++) {
- dstRow[col] = PACK_COLOR_332( CHAN_TO_UBYTE(src[RCOMP]),
- CHAN_TO_UBYTE(src[GCOMP]),
- CHAN_TO_UBYTE(src[BCOMP]) );
- src += 3;
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
- */
-static GLboolean
-_mesa_texstore_a8(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_A8 ||
- dstFormat == MESA_FORMAT_L8 ||
- dstFormat == MESA_FORMAT_I8 ||
- dstFormat == MESA_FORMAT_R8);
- ASSERT(texelBytes == 1);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_UNSIGNED_BYTE) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- srcType == GL_UNSIGNED_BYTE &&
- can_swizzle(baseInternalFormat) &&
- can_swizzle(srcFormat)) {
- GLubyte dstmap[4];
-
- /* dstmap - how to swizzle from RGBA to dst format:
- */
- if (dstFormat == MESA_FORMAT_A8) {
- dstmap[0] = 3;
- }
- else {
- dstmap[0] = 0;
- }
- dstmap[1] = ZERO; /* ? */
- dstmap[2] = ZERO; /* ? */
- dstmap[3] = ONE; /* ? */
-
- _mesa_swizzle_ubyte_image(ctx, dims,
- srcFormat,
- srcType,
- baseInternalFormat,
- dstmap, 1,
- dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcAddr,
- srcPacking);
- }
- else {
- /* general path */
- const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
- const GLchan *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- for (col = 0; col < srcWidth; col++) {
- dstRow[col] = CHAN_TO_UBYTE(src[col]);
- }
- dstRow += dstRowStride;
- src += srcWidth;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-
-static GLboolean
-_mesa_texstore_ci8(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
-
- (void) dims; (void) baseInternalFormat;
- ASSERT(dstFormat == MESA_FORMAT_CI8);
- ASSERT(texelBytes == 1);
- ASSERT(baseInternalFormat == GL_COLOR_INDEX);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- srcFormat == GL_COLOR_INDEX &&
- srcType == GL_UNSIGNED_BYTE) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- GLint img, row;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- const GLvoid *src = _mesa_image_address(dims, srcPacking,
- srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
- _mesa_unpack_index_span(ctx, srcWidth, GL_UNSIGNED_BYTE, dstRow,
- srcType, src, srcPacking,
- ctx->_ImageTransferState);
- dstRow += dstRowStride;
- }
- }
- }
- return GL_TRUE;
-}
-
-
-/**
- * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
- */
-static GLboolean
-_mesa_texstore_ycbcr(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
-
- (void) ctx; (void) dims; (void) baseInternalFormat;
-
- ASSERT((dstFormat == MESA_FORMAT_YCBCR) ||
- (dstFormat == MESA_FORMAT_YCBCR_REV));
- ASSERT(texelBytes == 2);
- ASSERT(ctx->Extensions.MESA_ycbcr_texture);
- ASSERT(srcFormat == GL_YCBCR_MESA);
- ASSERT((srcType == GL_UNSIGNED_SHORT_8_8_MESA) ||
- (srcType == GL_UNSIGNED_SHORT_8_8_REV_MESA));
- ASSERT(baseInternalFormat == GL_YCBCR_MESA);
-
- /* always just memcpy since no pixel transfer ops apply */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
-
- /* Check if we need byte swapping */
- /* XXX the logic here _might_ be wrong */
- if (srcPacking->SwapBytes ^
- (srcType == GL_UNSIGNED_SHORT_8_8_REV_MESA) ^
- (dstFormat == MESA_FORMAT_YCBCR_REV) ^
- !littleEndian) {
- GLint img, row;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- _mesa_swap2((GLushort *) dstRow, srcWidth);
- dstRow += dstRowStride;
- }
- }
- }
- return GL_TRUE;
-}
-
-static GLboolean
-_mesa_texstore_dudv8(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_DUDV8);
- ASSERT(texelBytes == 2);
- ASSERT(ctx->Extensions.ATI_envmap_bumpmap);
- ASSERT((srcFormat == GL_DU8DV8_ATI) ||
- (srcFormat == GL_DUDV_ATI));
- ASSERT(baseInternalFormat == GL_DUDV_ATI);
-
- if (!srcPacking->SwapBytes && srcType == GL_BYTE &&
- littleEndian) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (srcType == GL_BYTE) {
- GLubyte dstmap[4];
-
- /* dstmap - how to swizzle from RGBA to dst format:
- */
- if (littleEndian) {
- dstmap[0] = 0;
- dstmap[1] = 3;
- }
- else {
- dstmap[0] = 3;
- dstmap[1] = 0;
- }
- dstmap[2] = ZERO; /* ? */
- dstmap[3] = ONE; /* ? */
-
- _mesa_swizzle_ubyte_image(ctx, dims,
- GL_LUMINANCE_ALPHA, /* hack */
- GL_UNSIGNED_BYTE, /* hack */
- GL_LUMINANCE_ALPHA, /* hack */
- dstmap, 2,
- dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcAddr,
- srcPacking);
- }
- else {
- /* general path - note this is defined for 2d textures only */
- const GLint components = _mesa_components_in_format(baseInternalFormat);
- const GLint srcStride = _mesa_image_row_stride(srcPacking, srcWidth,
- srcFormat, srcType);
- GLbyte *tempImage, *dst, *src;
- GLint row;
-
- tempImage = (GLbyte *) malloc(srcWidth * srcHeight * srcDepth
- * components * sizeof(GLbyte));
- if (!tempImage)
- return GL_FALSE;
-
- src = (GLbyte *) _mesa_image_address(dims, srcPacking, srcAddr,
- srcWidth, srcHeight,
- srcFormat, srcType,
- 0, 0, 0);
-
- dst = tempImage;
- for (row = 0; row < srcHeight; row++) {
- _mesa_unpack_dudv_span_byte(ctx, srcWidth, baseInternalFormat,
- dst, srcFormat, srcType, src,
- srcPacking, 0);
- dst += srcWidth * components;
- src += srcStride;
- }
-
- src = tempImage;
- dst = (GLbyte *) dstAddr
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- memcpy(dst, src, srcWidth * texelBytes);
- dst += dstRowStride;
- src += srcWidth * texelBytes;
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store a texture in MESA_FORMAT_SIGNED_R8 format.
- */
-static GLboolean
-_mesa_texstore_signed_r8(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_SIGNED_R8);
- ASSERT(texelBytes == 1);
-
- /* XXX look at adding optimized paths */
- {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *srcRow = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLubyte *dstB = (GLubyte *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- dstB[col] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]);
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
- */
-static GLboolean
-_mesa_texstore_signed_rg88(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_SIGNED_RG88);
- ASSERT(texelBytes == 1);
-
- /* XXX look at adding optimized paths */
- {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *srcRow = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstUS = (GLushort *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- dstUS[col] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
- FLOAT_TO_BYTE_TEX(srcRow[GCOMP]));
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
- */
-static GLboolean
-_mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBX8888);
- ASSERT(texelBytes == 4);
-
- {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *srcRow = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLuint *dstUI = (GLuint *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- dstUI[col] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
- FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
- FLOAT_TO_BYTE_TEX(srcRow[BCOMP]),
- 0xff );
- srcRow += 4;
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-
-/**
- * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
- * MESA_FORMAT_SIGNED_RGBA8888_REV
- */
-static GLboolean
-_mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBA8888 ||
- dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV);
- ASSERT(texelBytes == 4);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_SIGNED_RGBA8888 &&
- baseInternalFormat == GL_RGBA &&
- ((srcFormat == GL_RGBA && srcType == GL_BYTE && !littleEndian) ||
- (srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && littleEndian))) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV &&
- baseInternalFormat == GL_RGBA &&
- ((srcFormat == GL_RGBA && srcType == GL_BYTE && littleEndian) ||
- (srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && !littleEndian))) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- (srcType == GL_BYTE) &&
- can_swizzle(baseInternalFormat) &&
- can_swizzle(srcFormat)) {
-
- GLubyte dstmap[4];
-
- /* dstmap - how to swizzle from RGBA to dst format:
- */
- if ((littleEndian && dstFormat == MESA_FORMAT_SIGNED_RGBA8888) ||
- (!littleEndian && dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV)) {
- dstmap[3] = 0;
- dstmap[2] = 1;
- dstmap[1] = 2;
- dstmap[0] = 3;
- }
- else {
- dstmap[3] = 3;
- dstmap[2] = 2;
- dstmap[1] = 1;
- dstmap[0] = 0;
- }
-
- _mesa_swizzle_ubyte_image(ctx, dims,
- srcFormat,
- srcType,
- baseInternalFormat,
- dstmap, 4,
- dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcAddr,
- srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *srcRow = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLuint *dstUI = (GLuint *) dstRow;
- if (dstFormat == MESA_FORMAT_SIGNED_RGBA8888) {
- for (col = 0; col < srcWidth; col++) {
- dstUI[col] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
- FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
- FLOAT_TO_BYTE_TEX(srcRow[BCOMP]),
- FLOAT_TO_BYTE_TEX(srcRow[ACOMP]) );
- srcRow += 4;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- dstUI[col] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
- FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
- FLOAT_TO_BYTE_TEX(srcRow[BCOMP]),
- FLOAT_TO_BYTE_TEX(srcRow[ACOMP]) );
- srcRow += 4;
- }
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store a combined depth/stencil texture image.
- */
-static GLboolean
-_mesa_texstore_z24_s8(TEXSTORE_PARAMS)
-{
- const GLuint depthScale = 0xffffff;
- const GLint srcRowStride
- = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
- / sizeof(GLuint);
- GLint img, row;
-
- ASSERT(dstFormat == MESA_FORMAT_Z24_S8);
- ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT || srcFormat == GL_DEPTH_COMPONENT);
- ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT || srcType == GL_UNSIGNED_INT_24_8_EXT);
-
- if (srcFormat != GL_DEPTH_COMPONENT && ctx->Pixel.DepthScale == 1.0f &&
- ctx->Pixel.DepthBias == 0.0f &&
- !srcPacking->SwapBytes) {
- /* simple path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (srcFormat == GL_DEPTH_COMPONENT) {
- /* In case we only upload depth we need to preserve the stencil */
- for (img = 0; img < srcDepth; img++) {
- GLuint *dstRow = (GLuint *) dstAddr
- + dstImageOffsets[dstZoffset + img]
- + dstYoffset * dstRowStride / sizeof(GLuint)
- + dstXoffset;
- const GLuint *src
- = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
- srcWidth, srcHeight,
- srcFormat, srcType,
- img, 0, 0);
- for (row = 0; row < srcHeight; row++) {
- GLuint depth[MAX_WIDTH];
- GLubyte stencil[MAX_WIDTH];
- GLint i;
- GLboolean keepdepth = GL_FALSE, keepstencil = GL_FALSE;
-
- if (srcFormat == GL_DEPTH_COMPONENT) { /* preserve stencil */
- keepstencil = GL_TRUE;
- }
- else if (srcFormat == GL_STENCIL_INDEX) { /* preserve depth */
- keepdepth = GL_TRUE;
- }
-
- if (keepdepth == GL_FALSE)
- /* the 24 depth bits will be in the low position: */
- _mesa_unpack_depth_span(ctx, srcWidth,
- GL_UNSIGNED_INT, /* dst type */
- keepstencil ? depth : dstRow, /* dst addr */
- depthScale,
- srcType, src, srcPacking);
-
- if (keepstencil == GL_FALSE)
- /* get the 8-bit stencil values */
- _mesa_unpack_stencil_span(ctx, srcWidth,
- GL_UNSIGNED_BYTE, /* dst type */
- stencil, /* dst addr */
- srcType, src, srcPacking,
- ctx->_ImageTransferState);
-
- for (i = 0; i < srcWidth; i++) {
- if (keepstencil)
- dstRow[i] = depth[i] << 8 | (dstRow[i] & 0x000000FF);
- else
- dstRow[i] = (dstRow[i] & 0xFFFFFF00) | (stencil[i] & 0xFF);
- }
-
- src += srcRowStride;
- dstRow += dstRowStride / sizeof(GLuint);
- }
- }
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store a combined depth/stencil texture image.
- */
-static GLboolean
-_mesa_texstore_s8_z24(TEXSTORE_PARAMS)
-{
- const GLuint depthScale = 0xffffff;
- const GLint srcRowStride
- = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
- / sizeof(GLuint);
- GLint img, row;
-
- ASSERT(dstFormat == MESA_FORMAT_S8_Z24);
- ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT ||
- srcFormat == GL_DEPTH_COMPONENT ||
- srcFormat == GL_STENCIL_INDEX);
- ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT ||
- srcType == GL_UNSIGNED_INT_24_8_EXT);
-
- for (img = 0; img < srcDepth; img++) {
- GLuint *dstRow = (GLuint *) dstAddr
- + dstImageOffsets[dstZoffset + img]
- + dstYoffset * dstRowStride / sizeof(GLuint)
- + dstXoffset;
- const GLuint *src
- = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
- srcWidth, srcHeight,
- srcFormat, srcType,
- img, 0, 0);
- for (row = 0; row < srcHeight; row++) {
- GLuint depth[MAX_WIDTH];
- GLubyte stencil[MAX_WIDTH];
- GLint i;
- GLboolean keepdepth = GL_FALSE, keepstencil = GL_FALSE;
-
- if (srcFormat == GL_DEPTH_COMPONENT) { /* preserve stencil */
- keepstencil = GL_TRUE;
- }
- else if (srcFormat == GL_STENCIL_INDEX) { /* preserve depth */
- keepdepth = GL_TRUE;
- }
-
- if (keepdepth == GL_FALSE)
- /* the 24 depth bits will be in the low position: */
- _mesa_unpack_depth_span(ctx, srcWidth,
- GL_UNSIGNED_INT, /* dst type */
- keepstencil ? depth : dstRow, /* dst addr */
- depthScale,
- srcType, src, srcPacking);
-
- if (keepstencil == GL_FALSE)
- /* get the 8-bit stencil values */
- _mesa_unpack_stencil_span(ctx, srcWidth,
- GL_UNSIGNED_BYTE, /* dst type */
- stencil, /* dst addr */
- srcType, src, srcPacking,
- ctx->_ImageTransferState);
-
- /* merge stencil values into depth values */
- for (i = 0; i < srcWidth; i++) {
- if (keepstencil)
- dstRow[i] = depth[i] | (dstRow[i] & 0xFF000000);
- else
- dstRow[i] = (dstRow[i] & 0xFFFFFF) | (stencil[i] << 24);
-
- }
- src += srcRowStride;
- dstRow += dstRowStride / sizeof(GLuint);
- }
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store simple 8-bit/value stencil texture data.
- */
-static GLboolean
-_mesa_texstore_s8(TEXSTORE_PARAMS)
-{
- ASSERT(dstFormat == MESA_FORMAT_S8);
- ASSERT(srcFormat == GL_STENCIL_INDEX);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_UNSIGNED_BYTE) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- const GLint srcRowStride
- = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
- / sizeof(GLuint);
- GLint img, row;
-
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img]
- + dstYoffset * dstRowStride / sizeof(GLuint)
- + dstXoffset;
- const GLuint *src
- = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
- srcWidth, srcHeight,
- srcFormat, srcType,
- img, 0, 0);
- for (row = 0; row < srcHeight; row++) {
- GLubyte stencil[MAX_WIDTH];
- GLint i;
-
- /* get the 8-bit stencil values */
- _mesa_unpack_stencil_span(ctx, srcWidth,
- GL_UNSIGNED_BYTE, /* dst type */
- stencil, /* dst addr */
- srcType, src, srcPacking,
- ctx->_ImageTransferState);
- /* merge stencil values into depth values */
- for (i = 0; i < srcWidth; i++)
- dstRow[i] = stencil[i];
-
- src += srcRowStride;
- dstRow += dstRowStride / sizeof(GLubyte);
- }
- }
-
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Store an image in any of the formats:
- * _mesa_texformat_rgba_float32
- * _mesa_texformat_rgb_float32
- * _mesa_texformat_alpha_float32
- * _mesa_texformat_luminance_float32
- * _mesa_texformat_luminance_alpha_float32
- * _mesa_texformat_intensity_float32
- */
-static GLboolean
-_mesa_texstore_rgba_float32(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- const GLint components = _mesa_components_in_format(baseFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA_FLOAT32 ||
- dstFormat == MESA_FORMAT_RGB_FLOAT32 ||
- dstFormat == MESA_FORMAT_ALPHA_FLOAT32 ||
- dstFormat == MESA_FORMAT_LUMINANCE_FLOAT32 ||
- dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 ||
- dstFormat == MESA_FORMAT_INTENSITY_FLOAT32);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY);
- ASSERT(texelBytes == components * sizeof(GLfloat));
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_FLOAT) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *srcRow = tempImage;
- GLint bytesPerRow;
- GLint img, row;
- if (!tempImage)
- return GL_FALSE;
- bytesPerRow = srcWidth * components * sizeof(GLfloat);
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- memcpy(dstRow, srcRow, bytesPerRow);
- dstRow += dstRowStride;
- srcRow += srcWidth * components;
- }
- }
-
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-
-/**
- * As above, but store 16-bit floats.
- */
-static GLboolean
-_mesa_texstore_rgba_float16(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- const GLint components = _mesa_components_in_format(baseFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA_FLOAT16 ||
- dstFormat == MESA_FORMAT_RGB_FLOAT16 ||
- dstFormat == MESA_FORMAT_ALPHA_FLOAT16 ||
- dstFormat == MESA_FORMAT_LUMINANCE_FLOAT16 ||
- dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 ||
- dstFormat == MESA_FORMAT_INTENSITY_FLOAT16);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY);
- ASSERT(texelBytes == components * sizeof(GLhalfARB));
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_HALF_FLOAT_ARB) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking,
- ctx->_ImageTransferState);
- const GLfloat *src = tempImage;
- GLint img, row;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLhalfARB *dstTexel = (GLhalfARB *) dstRow;
- GLint i;
- for (i = 0; i < srcWidth * components; i++) {
- dstTexel[i] = _mesa_float_to_half(src[i]);
- }
- dstRow += dstRowStride;
- src += srcWidth * components;
- }
- }
-
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/* non-normalized, signed int8 */
-static GLboolean
-_mesa_texstore_rgba_int8(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- const GLint components = _mesa_components_in_format(baseFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA_INT8);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY);
- ASSERT(texelBytes == components * sizeof(GLbyte));
-
- /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
- * to integer formats.
- */
- if (!srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_BYTE) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking, 0x0);
- const GLfloat *src = tempImage;
- GLint img, row;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLbyte *dstTexel = (GLbyte *) dstRow;
- GLint i;
- for (i = 0; i < srcWidth * components; i++) {
- dstTexel[i] = (GLbyte) src[i];
- }
- dstRow += dstRowStride;
- src += srcWidth * components;
- }
- }
-
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/* non-normalized, signed int16 */
-static GLboolean
-_mesa_texstore_rgba_int16(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- const GLint components = _mesa_components_in_format(baseFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA_INT16);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY);
- ASSERT(texelBytes == components * sizeof(GLshort));
-
- /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
- * to integer formats.
- */
- if (!srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_SHORT) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking, 0x0);
- const GLfloat *src = tempImage;
- GLint img, row;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLshort *dstTexel = (GLshort *) dstRow;
- GLint i;
- for (i = 0; i < srcWidth * components; i++) {
- dstTexel[i] = (GLint) src[i];
- }
- dstRow += dstRowStride;
- src += srcWidth * components;
- }
- }
-
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/* non-normalized, signed int32 */
-static GLboolean
-_mesa_texstore_rgba_int32(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- const GLint components = _mesa_components_in_format(baseFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA_INT32);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY);
- ASSERT(texelBytes == components * sizeof(GLint));
-
- /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
- * to integer formats.
- */
- if (!srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_INT) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
- baseInternalFormat,
- baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking, 0x0);
- const GLfloat *src = tempImage;
- GLint img, row;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLint *dstTexel = (GLint *) dstRow;
- GLint i;
- for (i = 0; i < srcWidth * components; i++) {
- dstTexel[i] = (GLint) src[i];
- }
- dstRow += dstRowStride;
- src += srcWidth * components;
- }
- }
-
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/* non-normalized, unsigned int8 */
-static GLboolean
-_mesa_texstore_rgba_uint8(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- const GLint components = _mesa_components_in_format(baseFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT8);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY);
- ASSERT(texelBytes == components * sizeof(GLubyte));
-
- /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
- * to integer formats.
- */
- if (!srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_UNSIGNED_BYTE) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLuint *tempImage =
- make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr, srcPacking);
- const GLuint *src = tempImage;
- GLint img, row;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLubyte *dstTexel = (GLubyte *) dstRow;
- GLint i;
- for (i = 0; i < srcWidth * components; i++) {
- dstTexel[i] = (GLubyte) CLAMP(src[i], 0, 0xff);
- }
- dstRow += dstRowStride;
- src += srcWidth * components;
- }
- }
-
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/* non-normalized, unsigned int16 */
-static GLboolean
-_mesa_texstore_rgba_uint16(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- const GLint components = _mesa_components_in_format(baseFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT16);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY);
- ASSERT(texelBytes == components * sizeof(GLushort));
-
- /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
- * to integer formats.
- */
- if (!srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_UNSIGNED_SHORT) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLuint *tempImage =
- make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr, srcPacking);
- const GLuint *src = tempImage;
- GLint img, row;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstTexel = (GLushort *) dstRow;
- GLint i;
- for (i = 0; i < srcWidth * components; i++) {
- dstTexel[i] = (GLushort) CLAMP(src[i], 0, 0xffff);
- }
- dstRow += dstRowStride;
- src += srcWidth * components;
- }
- }
-
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/* non-normalized, unsigned int32 */
-static GLboolean
-_mesa_texstore_rgba_uint32(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- const GLint components = _mesa_components_in_format(baseFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT32);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY);
- ASSERT(texelBytes == components * sizeof(GLuint));
-
- /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
- * to integer formats.
- */
- if (!srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_UNSIGNED_INT) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else {
- /* general path */
- const GLuint *tempImage =
- make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr, srcPacking);
- const GLuint *src = tempImage;
- GLint img, row;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLuint *dstTexel = (GLuint *) dstRow;
- GLint i;
- for (i = 0; i < srcWidth * components; i++) {
- dstTexel[i] = src[i];
- }
- dstRow += dstRowStride;
- src += srcWidth * components;
- }
- }
-
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-
-
-#if FEATURE_EXT_texture_sRGB
-static GLboolean
-_mesa_texstore_srgb8(TEXSTORE_PARAMS)
-{
- gl_format newDstFormat;
- GLboolean k;
-
- ASSERT(dstFormat == MESA_FORMAT_SRGB8);
-
- /* reuse normal rgb texstore code */
- newDstFormat = MESA_FORMAT_RGB888;
-
- k = _mesa_texstore_rgb888(ctx, dims, baseInternalFormat,
- newDstFormat, dstAddr,
- dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType,
- srcAddr, srcPacking);
- return k;
-}
-
-
-static GLboolean
-_mesa_texstore_srgba8(TEXSTORE_PARAMS)
-{
- gl_format newDstFormat;
- GLboolean k;
-
- ASSERT(dstFormat == MESA_FORMAT_SRGBA8);
-
- /* reuse normal rgba texstore code */
- newDstFormat = MESA_FORMAT_RGBA8888;
- k = _mesa_texstore_rgba8888(ctx, dims, baseInternalFormat,
- newDstFormat, dstAddr,
- dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType,
- srcAddr, srcPacking);
- return k;
-}
-
-
-static GLboolean
-_mesa_texstore_sargb8(TEXSTORE_PARAMS)
-{
- gl_format newDstFormat;
- GLboolean k;
-
- ASSERT(dstFormat == MESA_FORMAT_SARGB8);
-
- /* reuse normal rgba texstore code */
- newDstFormat = MESA_FORMAT_ARGB8888;
-
- k = _mesa_texstore_argb8888(ctx, dims, baseInternalFormat,
- newDstFormat, dstAddr,
- dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType,
- srcAddr, srcPacking);
- return k;
-}
-
-
-static GLboolean
-_mesa_texstore_sl8(TEXSTORE_PARAMS)
-{
- gl_format newDstFormat;
- GLboolean k;
-
- ASSERT(dstFormat == MESA_FORMAT_SL8);
-
- newDstFormat = MESA_FORMAT_L8;
-
- /* _mesa_textore_a8 handles luminance8 too */
- k = _mesa_texstore_a8(ctx, dims, baseInternalFormat,
- newDstFormat, dstAddr,
- dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType,
- srcAddr, srcPacking);
- return k;
-}
-
-
-static GLboolean
-_mesa_texstore_sla8(TEXSTORE_PARAMS)
-{
- gl_format newDstFormat;
- GLboolean k;
-
- ASSERT(dstFormat == MESA_FORMAT_SLA8);
-
- /* reuse normal luminance/alpha texstore code */
- newDstFormat = MESA_FORMAT_AL88;
-
- k = _mesa_texstore_unorm88(ctx, dims, baseInternalFormat,
- newDstFormat, dstAddr,
- dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType,
- srcAddr, srcPacking);
- return k;
-}
-
-#else
-
-/* these are used only in texstore_funcs[] below */
-#define _mesa_texstore_srgb8 NULL
-#define _mesa_texstore_srgba8 NULL
-#define _mesa_texstore_sargb8 NULL
-#define _mesa_texstore_sl8 NULL
-#define _mesa_texstore_sla8 NULL
-
-#endif /* FEATURE_EXT_texture_sRGB */
-
-
-
-
-/**
- * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
- * XXX this is somewhat temporary.
- */
-static const struct {
- gl_format Name;
- StoreTexImageFunc Store;
-}
-texstore_funcs[MESA_FORMAT_COUNT] =
-{
- { MESA_FORMAT_NONE, NULL },
- { MESA_FORMAT_RGBA8888, _mesa_texstore_rgba8888 },
- { MESA_FORMAT_RGBA8888_REV, _mesa_texstore_rgba8888 },
- { MESA_FORMAT_ARGB8888, _mesa_texstore_argb8888 },
- { MESA_FORMAT_ARGB8888_REV, _mesa_texstore_argb8888 },
- { MESA_FORMAT_XRGB8888, _mesa_texstore_argb8888 },
- { MESA_FORMAT_XRGB8888_REV, _mesa_texstore_argb8888 },
- { MESA_FORMAT_RGB888, _mesa_texstore_rgb888 },
- { MESA_FORMAT_BGR888, _mesa_texstore_bgr888 },
- { MESA_FORMAT_RGB565, _mesa_texstore_rgb565 },
- { MESA_FORMAT_RGB565_REV, _mesa_texstore_rgb565 },
- { MESA_FORMAT_ARGB4444, _mesa_texstore_argb4444 },
- { MESA_FORMAT_ARGB4444_REV, _mesa_texstore_argb4444 },
- { MESA_FORMAT_RGBA5551, _mesa_texstore_rgba5551 },
- { MESA_FORMAT_ARGB1555, _mesa_texstore_argb1555 },
- { MESA_FORMAT_ARGB1555_REV, _mesa_texstore_argb1555 },
- { MESA_FORMAT_AL44, _mesa_texstore_unorm44 },
- { MESA_FORMAT_AL88, _mesa_texstore_unorm88 },
- { MESA_FORMAT_AL88_REV, _mesa_texstore_unorm88 },
- { MESA_FORMAT_AL1616, _mesa_texstore_unorm1616 },
- { MESA_FORMAT_AL1616_REV, _mesa_texstore_unorm1616 },
- { MESA_FORMAT_RGB332, _mesa_texstore_rgb332 },
- { MESA_FORMAT_A8, _mesa_texstore_a8 },
- { MESA_FORMAT_A16, _mesa_texstore_unorm16 },
- { MESA_FORMAT_L8, _mesa_texstore_a8 },
- { MESA_FORMAT_L16, _mesa_texstore_unorm16 },
- { MESA_FORMAT_I8, _mesa_texstore_a8 },
- { MESA_FORMAT_I16, _mesa_texstore_unorm16 },
- { MESA_FORMAT_CI8, _mesa_texstore_ci8 },
- { MESA_FORMAT_YCBCR, _mesa_texstore_ycbcr },
- { MESA_FORMAT_YCBCR_REV, _mesa_texstore_ycbcr },
- { MESA_FORMAT_R8, _mesa_texstore_a8 },
- { MESA_FORMAT_RG88, _mesa_texstore_unorm88 },
- { MESA_FORMAT_RG88_REV, _mesa_texstore_unorm88 },
- { MESA_FORMAT_R16, _mesa_texstore_unorm16 },
- { MESA_FORMAT_RG1616, _mesa_texstore_unorm1616 },
- { MESA_FORMAT_RG1616_REV, _mesa_texstore_unorm1616 },
- { MESA_FORMAT_ARGB2101010, _mesa_texstore_argb2101010 },
- { MESA_FORMAT_Z24_S8, _mesa_texstore_z24_s8 },
- { MESA_FORMAT_S8_Z24, _mesa_texstore_s8_z24 },
- { MESA_FORMAT_Z16, _mesa_texstore_z16 },
- { MESA_FORMAT_X8_Z24, _mesa_texstore_x8_z24 },
- { MESA_FORMAT_Z24_X8, _mesa_texstore_z24_x8 },
- { MESA_FORMAT_Z32, _mesa_texstore_z32 },
- { MESA_FORMAT_S8, _mesa_texstore_s8 },
- { MESA_FORMAT_SRGB8, _mesa_texstore_srgb8 },
- { MESA_FORMAT_SRGBA8, _mesa_texstore_srgba8 },
- { MESA_FORMAT_SARGB8, _mesa_texstore_sargb8 },
- { MESA_FORMAT_SL8, _mesa_texstore_sl8 },
- { MESA_FORMAT_SLA8, _mesa_texstore_sla8 },
- { MESA_FORMAT_SRGB_DXT1, _mesa_texstore_rgb_dxt1 },
- { MESA_FORMAT_SRGBA_DXT1, _mesa_texstore_rgba_dxt1 },
- { MESA_FORMAT_SRGBA_DXT3, _mesa_texstore_rgba_dxt3 },
- { MESA_FORMAT_SRGBA_DXT5, _mesa_texstore_rgba_dxt5 },
- { MESA_FORMAT_RGB_FXT1, _mesa_texstore_rgb_fxt1 },
- { MESA_FORMAT_RGBA_FXT1, _mesa_texstore_rgba_fxt1 },
- { MESA_FORMAT_RGB_DXT1, _mesa_texstore_rgb_dxt1 },
- { MESA_FORMAT_RGBA_DXT1, _mesa_texstore_rgba_dxt1 },
- { MESA_FORMAT_RGBA_DXT3, _mesa_texstore_rgba_dxt3 },
- { MESA_FORMAT_RGBA_DXT5, _mesa_texstore_rgba_dxt5 },
- { MESA_FORMAT_RGBA_FLOAT32, _mesa_texstore_rgba_float32 },
- { MESA_FORMAT_RGBA_FLOAT16, _mesa_texstore_rgba_float16 },
- { MESA_FORMAT_RGB_FLOAT32, _mesa_texstore_rgba_float32 },
- { MESA_FORMAT_RGB_FLOAT16, _mesa_texstore_rgba_float16 },
- { MESA_FORMAT_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
- { MESA_FORMAT_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
- { MESA_FORMAT_LUMINANCE_FLOAT32, _mesa_texstore_rgba_float32 },
- { MESA_FORMAT_LUMINANCE_FLOAT16, _mesa_texstore_rgba_float16 },
- { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
- { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
- { MESA_FORMAT_INTENSITY_FLOAT32, _mesa_texstore_rgba_float32 },
- { MESA_FORMAT_INTENSITY_FLOAT16, _mesa_texstore_rgba_float16 },
-
- { MESA_FORMAT_RGBA_INT8, _mesa_texstore_rgba_int8 },
- { MESA_FORMAT_RGBA_INT16, _mesa_texstore_rgba_int16 },
- { MESA_FORMAT_RGBA_INT32, _mesa_texstore_rgba_int32 },
- { MESA_FORMAT_RGBA_UINT8, _mesa_texstore_rgba_uint8 },
- { MESA_FORMAT_RGBA_UINT16, _mesa_texstore_rgba_uint16 },
- { MESA_FORMAT_RGBA_UINT32, _mesa_texstore_rgba_uint32 },
-
- { MESA_FORMAT_DUDV8, _mesa_texstore_dudv8 },
-
- { MESA_FORMAT_SIGNED_R8, _mesa_texstore_signed_r8 },
- { MESA_FORMAT_SIGNED_RG88, _mesa_texstore_signed_rg88 },
- { MESA_FORMAT_SIGNED_RGBX8888, _mesa_texstore_signed_rgbx8888 },
-
- { MESA_FORMAT_SIGNED_RGBA8888, _mesa_texstore_signed_rgba8888 },
- { MESA_FORMAT_SIGNED_RGBA8888_REV, _mesa_texstore_signed_rgba8888 },
-
- { MESA_FORMAT_SIGNED_R_16, _mesa_texstore_signed_rgba_16 },
- { MESA_FORMAT_SIGNED_RG_16, _mesa_texstore_signed_rgba_16 },
- { MESA_FORMAT_SIGNED_RGB_16, _mesa_texstore_signed_rgba_16 },
- { MESA_FORMAT_SIGNED_RGBA_16, _mesa_texstore_signed_rgba_16 },
- { MESA_FORMAT_RGBA_16, _mesa_texstore_rgba_16 },
-
- { MESA_FORMAT_RED_RGTC1, _mesa_texstore_red_rgtc1 },
- { MESA_FORMAT_SIGNED_RED_RGTC1, _mesa_texstore_signed_red_rgtc1 },
- { MESA_FORMAT_RG_RGTC2, _mesa_texstore_rg_rgtc2 },
- { MESA_FORMAT_SIGNED_RG_RGTC2, _mesa_texstore_signed_rg_rgtc2 }
-};
-
-
-static GLboolean
-_mesa_texstore_null(TEXSTORE_PARAMS)
-{
- (void) ctx; (void) dims;
- (void) baseInternalFormat;
- (void) dstFormat;
- (void) dstAddr;
- (void) dstXoffset; (void) dstYoffset; (void) dstZoffset;
- (void) dstRowStride; (void) dstImageOffsets;
- (void) srcWidth; (void) srcHeight; (void) srcDepth;
- (void) srcFormat; (void) srcType;
- (void) srcAddr;
- (void) srcPacking;
-
- /* should never happen */
- _mesa_problem(NULL, "_mesa_texstore_null() is called");
- return GL_FALSE;
-}
-
-
-/**
- * Return the StoreTexImageFunc pointer to store an image in the given format.
- */
-static StoreTexImageFunc
-_mesa_get_texstore_func(gl_format format)
-{
-#ifdef DEBUG
- GLuint i;
- for (i = 0; i < MESA_FORMAT_COUNT; i++) {
- ASSERT(texstore_funcs[i].Name == i);
- }
-#endif
- ASSERT(texstore_funcs[format].Name == format);
-
- if (texstore_funcs[format].Store)
- return texstore_funcs[format].Store;
- else
- return _mesa_texstore_null;
-}
-
-
-/**
- * Store user data into texture memory.
- * Called via glTex[Sub]Image1/2/3D()
- */
-GLboolean
-_mesa_texstore(TEXSTORE_PARAMS)
-{
- StoreTexImageFunc storeImage;
- GLboolean success;
-
- storeImage = _mesa_get_texstore_func(dstFormat);
-
- success = storeImage(ctx, dims, baseInternalFormat,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr, srcPacking);
- return success;
-}
-
-
-/** Return texture size in bytes */
-static GLuint
-texture_size(const struct gl_texture_image *texImage)
-{
- GLuint sz = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
- texImage->Height, texImage->Depth);
- return sz;
-}
-
-
-/** Return row stride in bytes */
-static GLuint
-texture_row_stride(const struct gl_texture_image *texImage)
-{
- GLuint stride = _mesa_format_row_stride(texImage->TexFormat,
- texImage->Width);
- return stride;
-}
-
-
-
-/**
- * This is the software fallback for Driver.TexImage1D()
- * and Driver.CopyTexImage1D().
- * \sa _mesa_store_teximage2d()
- */
-void
-_mesa_store_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint border,
- GLenum format, GLenum type, const GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- GLuint sizeInBytes;
- (void) border;
-
- /* allocate memory */
- sizeInBytes = texture_size(texImage);
- texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
- if (!texImage->Data) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
- return;
- }
-
- pixels = _mesa_validate_pbo_teximage(ctx, 1, width, 1, 1, format, type,
- pixels, packing, "glTexImage1D");
- if (!pixels) {
- /* Note: we check for a NULL image pointer here, _after_ we allocated
- * memory for the texture. That's what the GL spec calls for.
- */
- return;
- }
- else {
- const GLint dstRowStride = 0;
- GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- 0, 0, 0, /* dstX/Y/Zoffset */
- dstRowStride,
- texImage->ImageOffsets,
- width, 1, 1,
- format, type, pixels, packing);
- if (!success) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
- }
- }
-
- _mesa_unmap_teximage_pbo(ctx, packing);
-}
-
-
-/**
- * This is the software fallback for Driver.TexImage2D()
- * and Driver.CopyTexImage2D().
- *
- * This function is oriented toward storing images in main memory, rather
- * than VRAM. Device driver's can easily plug in their own replacement.
- */
-void
-_mesa_store_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint border,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- GLuint sizeInBytes;
- (void) border;
-
- /* allocate memory */
- sizeInBytes = texture_size(texImage);
- texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
- if (!texImage->Data) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
- return;
- }
-
- pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
- pixels, packing, "glTexImage2D");
- if (!pixels) {
- /* Note: we check for a NULL image pointer here, _after_ we allocated
- * memory for the texture. That's what the GL spec calls for.
- */
- return;
- }
- else {
- GLint dstRowStride = texture_row_stride(texImage);
- GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- 0, 0, 0, /* dstX/Y/Zoffset */
- dstRowStride,
- texImage->ImageOffsets,
- width, height, 1,
- format, type, pixels, packing);
- if (!success) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
- }
- }
-
- _mesa_unmap_teximage_pbo(ctx, packing);
-}
-
-
-
-/**
- * This is the software fallback for Driver.TexImage3D()
- * and Driver.CopyTexImage3D().
- * \sa _mesa_store_teximage2d()
- */
-void
-_mesa_store_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint depth, GLint border,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- GLuint sizeInBytes;
- (void) border;
-
- /* allocate memory */
- sizeInBytes = texture_size(texImage);
- texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
- if (!texImage->Data) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
- return;
- }
-
- pixels = _mesa_validate_pbo_teximage(ctx, 3, width, height, depth, format,
- type, pixels, packing, "glTexImage3D");
- if (!pixels) {
- /* Note: we check for a NULL image pointer here, _after_ we allocated
- * memory for the texture. That's what the GL spec calls for.
- */
- return;
- }
- else {
- GLint dstRowStride = texture_row_stride(texImage);
- GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- 0, 0, 0, /* dstX/Y/Zoffset */
- dstRowStride,
- texImage->ImageOffsets,
- width, height, depth,
- format, type, pixels, packing);
- if (!success) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
- }
- }
-
- _mesa_unmap_teximage_pbo(ctx, packing);
-}
-
-
-
-
-/*
- * This is the software fallback for Driver.TexSubImage1D()
- * and Driver.CopyTexSubImage1D().
- */
-void
-_mesa_store_texsubimage1d(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint width,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- /* get pointer to src pixels (may be in a pbo which we'll map here) */
- pixels = _mesa_validate_pbo_teximage(ctx, 1, width, 1, 1, format, type,
- pixels, packing, "glTexSubImage1D");
- if (!pixels)
- return;
-
- {
- const GLint dstRowStride = 0;
- GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- xoffset, 0, 0, /* offsets */
- dstRowStride,
- texImage->ImageOffsets,
- width, 1, 1,
- format, type, pixels, packing);
- if (!success) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage1D");
- }
- }
-
- _mesa_unmap_teximage_pbo(ctx, packing);
-}
-
-
-
-/**
- * This is the software fallback for Driver.TexSubImage2D()
- * and Driver.CopyTexSubImage2D().
- */
-void
-_mesa_store_texsubimage2d(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLint width, GLint height,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- /* get pointer to src pixels (may be in a pbo which we'll map here) */
- pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
- pixels, packing, "glTexSubImage2D");
- if (!pixels)
- return;
-
- {
- GLint dstRowStride = texture_row_stride(texImage);
- GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- xoffset, yoffset, 0,
- dstRowStride,
- texImage->ImageOffsets,
- width, height, 1,
- format, type, pixels, packing);
- if (!success) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D");
- }
- }
-
- _mesa_unmap_teximage_pbo(ctx, packing);
-}
-
-
-/*
- * This is the software fallback for Driver.TexSubImage3D().
- * and Driver.CopyTexSubImage3D().
- */
-void
-_mesa_store_texsubimage3d(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint width, GLint height, GLint depth,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- /* get pointer to src pixels (may be in a pbo which we'll map here) */
- pixels = _mesa_validate_pbo_teximage(ctx, 3, width, height, depth, format,
- type, pixels, packing,
- "glTexSubImage3D");
- if (!pixels)
- return;
-
- {
- GLint dstRowStride = texture_row_stride(texImage);
- GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- xoffset, yoffset, zoffset,
- dstRowStride,
- texImage->ImageOffsets,
- width, height, depth,
- format, type, pixels, packing);
- if (!success) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage3D");
- }
- }
-
- _mesa_unmap_teximage_pbo(ctx, packing);
-}
-
-
-/*
- * Fallback for Driver.CompressedTexImage1D()
- */
-void
-_mesa_store_compressed_teximage1d(struct gl_context *ctx,
- GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint border,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- /* this space intentionally left blank */
- (void) ctx;
- (void) target; (void) level;
- (void) internalFormat;
- (void) width; (void) border;
- (void) imageSize; (void) data;
- (void) texObj;
- (void) texImage;
-}
-
-
-
-/**
- * Fallback for Driver.CompressedTexImage2D()
- */
-void
-_mesa_store_compressed_teximage2d(struct gl_context *ctx,
- GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint border,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- (void) width; (void) height; (void) border;
-
- /* This is pretty simple, basically just do a memcpy without worrying
- * about the usual image unpacking or image transfer operations.
- */
- ASSERT(texObj);
- ASSERT(texImage);
- ASSERT(texImage->Width > 0);
- ASSERT(texImage->Height > 0);
- ASSERT(texImage->Depth == 1);
- ASSERT(texImage->Data == NULL); /* was freed in glCompressedTexImage2DARB */
-
- /* allocate storage */
- texImage->Data = _mesa_alloc_texmemory(imageSize);
- if (!texImage->Data) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
- return;
- }
-
- data = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, data,
- &ctx->Unpack,
- "glCompressedTexImage2D");
- if (!data)
- return;
-
- /* copy the data */
- memcpy(texImage->Data, data, imageSize);
-
- _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
-}
-
-
-
-/*
- * Fallback for Driver.CompressedTexImage3D()
- */
-void
-_mesa_store_compressed_teximage3d(struct gl_context *ctx,
- GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint depth,
- GLint border,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- /* this space intentionally left blank */
- (void) ctx;
- (void) target; (void) level;
- (void) internalFormat;
- (void) width; (void) height; (void) depth;
- (void) border;
- (void) imageSize; (void) data;
- (void) texObj;
- (void) texImage;
-}
-
-
-
-/**
- * Fallback for Driver.CompressedTexSubImage1D()
- */
-void
-_mesa_store_compressed_texsubimage1d(struct gl_context *ctx, GLenum target,
- GLint level,
- GLint xoffset, GLsizei width,
- GLenum format,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- /* there are no compressed 1D texture formats yet */
- (void) ctx;
- (void) target; (void) level;
- (void) xoffset; (void) width;
- (void) format;
- (void) imageSize; (void) data;
- (void) texObj;
- (void) texImage;
-}
-
-
-/**
- * Fallback for Driver.CompressedTexSubImage2D()
- */
-void
-_mesa_store_compressed_texsubimage2d(struct gl_context *ctx, GLenum target,
- GLint level,
- GLint xoffset, GLint yoffset,
- GLsizei width, GLsizei height,
- GLenum format,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- GLint bytesPerRow, destRowStride, srcRowStride;
- GLint i, rows;
- GLubyte *dest;
- const GLubyte *src;
- const gl_format texFormat = texImage->TexFormat;
- const GLint destWidth = texImage->Width;
- GLuint bw, bh;
-
- _mesa_get_format_block_size(texFormat, &bw, &bh);
-
- (void) level;
- (void) format;
-
- /* these should have been caught sooner */
- ASSERT((width % bw) == 0 || width == 2 || width == 1);
- ASSERT((height % bh) == 0 || height == 2 || height == 1);
- ASSERT((xoffset % bw) == 0);
- ASSERT((yoffset % bh) == 0);
-
- /* get pointer to src pixels (may be in a pbo which we'll map here) */
- data = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, data,
- &ctx->Unpack,
- "glCompressedTexSubImage2D");
- if (!data)
- return;
-
- srcRowStride = _mesa_format_row_stride(texFormat, width);
- src = (const GLubyte *) data;
-
- destRowStride = _mesa_format_row_stride(texFormat, destWidth);
- dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
- texFormat, destWidth,
- (GLubyte *) texImage->Data);
-
- bytesPerRow = srcRowStride; /* bytes per row of blocks */
- rows = height / bh; /* rows in blocks */
-
- /* copy rows of blocks */
- for (i = 0; i < rows; i++) {
- memcpy(dest, src, bytesPerRow);
- dest += destRowStride;
- src += srcRowStride;
- }
-
- _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
-}
-
-
-/**
- * Fallback for Driver.CompressedTexSubImage3D()
- */
-void
-_mesa_store_compressed_texsubimage3d(struct gl_context *ctx, GLenum target,
- GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- /* there are no compressed 3D texture formats yet */
- (void) ctx;
- (void) target; (void) level;
- (void) xoffset; (void) yoffset; (void) zoffset;
- (void) width; (void) height; (void) depth;
- (void) format;
- (void) imageSize; (void) data;
- (void) texObj;
- (void) texImage;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.5
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008-2009 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Authors:
+ * Brian Paul
+ */
+
+/**
+ * The GL texture image functions in teximage.c basically just do
+ * error checking and data structure allocation. They in turn call
+ * device driver functions which actually copy/convert/store the user's
+ * texture image data.
+ *
+ * However, most device drivers will be able to use the fallback functions
+ * in this file. That is, most drivers will have the following bit of
+ * code:
+ * ctx->Driver.TexImage1D = _mesa_store_teximage1d;
+ * ctx->Driver.TexImage2D = _mesa_store_teximage2d;
+ * ctx->Driver.TexImage3D = _mesa_store_teximage3d;
+ * etc...
+ *
+ * Texture image processing is actually kind of complicated. We have to do:
+ * Format/type conversions
+ * pixel unpacking
+ * pixel transfer (scale, bais, lookup, etc)
+ *
+ * These functions can handle most everything, including processing full
+ * images and sub-images.
+ */
+
+
+#include "glheader.h"
+#include "bufferobj.h"
+#include "colormac.h"
+#include "image.h"
+#include "macros.h"
+#include "mipmap.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "pack.h"
+#include "pbo.h"
+#include "imports.h"
+#include "pack.h"
+#include "texcompress.h"
+#include "texcompress_fxt1.h"
+#include "texcompress_rgtc.h"
+#include "texcompress_s3tc.h"
+#include "teximage.h"
+#include "texstore.h"
+#include "enums.h"
+
+
+enum {
+ ZERO = 4,
+ ONE = 5
+};
+
+
+/**
+ * Texture image storage function.
+ */
+typedef GLboolean (*StoreTexImageFunc)(TEXSTORE_PARAMS);
+
+
+/**
+ * Return GL_TRUE if the given image format is one that be converted
+ * to another format by swizzling.
+ */
+static GLboolean
+can_swizzle(GLenum logicalBaseFormat)
+{
+ switch (logicalBaseFormat) {
+ case GL_RGBA:
+ case GL_RGB:
+ case GL_LUMINANCE_ALPHA:
+ case GL_INTENSITY:
+ case GL_ALPHA:
+ case GL_LUMINANCE:
+ case GL_RED:
+ case GL_GREEN:
+ case GL_BLUE:
+ case GL_BGR:
+ case GL_BGRA:
+ case GL_ABGR_EXT:
+ case GL_RG:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+
+enum {
+ IDX_LUMINANCE = 0,
+ IDX_ALPHA,
+ IDX_INTENSITY,
+ IDX_LUMINANCE_ALPHA,
+ IDX_RGB,
+ IDX_RGBA,
+ IDX_RED,
+ IDX_GREEN,
+ IDX_BLUE,
+ IDX_BGR,
+ IDX_BGRA,
+ IDX_ABGR,
+ IDX_RG,
+ MAX_IDX
+};
+
+#define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
+#define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
+#define MAP3(x,y,z) MAP4(x, y, z, ZERO)
+#define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
+
+
+static const struct {
+ GLubyte format_idx;
+ GLubyte to_rgba[6];
+ GLubyte from_rgba[6];
+} mappings[MAX_IDX] =
+{
+ {
+ IDX_LUMINANCE,
+ MAP4(0,0,0,ONE),
+ MAP1(0)
+ },
+
+ {
+ IDX_ALPHA,
+ MAP4(ZERO, ZERO, ZERO, 0),
+ MAP1(3)
+ },
+
+ {
+ IDX_INTENSITY,
+ MAP4(0, 0, 0, 0),
+ MAP1(0),
+ },
+
+ {
+ IDX_LUMINANCE_ALPHA,
+ MAP4(0,0,0,1),
+ MAP2(0,3)
+ },
+
+ {
+ IDX_RGB,
+ MAP4(0,1,2,ONE),
+ MAP3(0,1,2)
+ },
+
+ {
+ IDX_RGBA,
+ MAP4(0,1,2,3),
+ MAP4(0,1,2,3),
+ },
+
+ {
+ IDX_RED,
+ MAP4(0, ZERO, ZERO, ONE),
+ MAP1(0),
+ },
+
+ {
+ IDX_GREEN,
+ MAP4(ZERO, 0, ZERO, ONE),
+ MAP1(1),
+ },
+
+ {
+ IDX_BLUE,
+ MAP4(ZERO, ZERO, 0, ONE),
+ MAP1(2),
+ },
+
+ {
+ IDX_BGR,
+ MAP4(2,1,0,ONE),
+ MAP3(2,1,0)
+ },
+
+ {
+ IDX_BGRA,
+ MAP4(2,1,0,3),
+ MAP4(2,1,0,3)
+ },
+
+ {
+ IDX_ABGR,
+ MAP4(3,2,1,0),
+ MAP4(3,2,1,0)
+ },
+
+ {
+ IDX_RG,
+ MAP4(0, 1, ZERO, ONE),
+ MAP2(0, 1)
+ },
+};
+
+
+
+/**
+ * Convert a GL image format enum to an IDX_* value (see above).
+ */
+static int
+get_map_idx(GLenum value)
+{
+ switch (value) {
+ case GL_LUMINANCE: return IDX_LUMINANCE;
+ case GL_ALPHA: return IDX_ALPHA;
+ case GL_INTENSITY: return IDX_INTENSITY;
+ case GL_LUMINANCE_ALPHA: return IDX_LUMINANCE_ALPHA;
+ case GL_RGB: return IDX_RGB;
+ case GL_RGBA: return IDX_RGBA;
+ case GL_RED: return IDX_RED;
+ case GL_GREEN: return IDX_GREEN;
+ case GL_BLUE: return IDX_BLUE;
+ case GL_BGR: return IDX_BGR;
+ case GL_BGRA: return IDX_BGRA;
+ case GL_ABGR_EXT: return IDX_ABGR;
+ case GL_RG: return IDX_RG;
+ default:
+ _mesa_problem(NULL, "Unexpected inFormat");
+ return 0;
+ }
+}
+
+
+/**
+ * When promoting texture formats (see below) we need to compute the
+ * mapping of dest components back to source components.
+ * This function does that.
+ * \param inFormat the incoming format of the texture
+ * \param outFormat the final texture format
+ * \return map[6] a full 6-component map
+ */
+static void
+compute_component_mapping(GLenum inFormat, GLenum outFormat,
+ GLubyte *map)
+{
+ const int inFmt = get_map_idx(inFormat);
+ const int outFmt = get_map_idx(outFormat);
+ const GLubyte *in2rgba = mappings[inFmt].to_rgba;
+ const GLubyte *rgba2out = mappings[outFmt].from_rgba;
+ int i;
+
+ for (i = 0; i < 4; i++)
+ map[i] = in2rgba[rgba2out[i]];
+
+ map[ZERO] = ZERO;
+ map[ONE] = ONE;
+
+#if 0
+ printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
+ inFormat, _mesa_lookup_enum_by_nr(inFormat),
+ outFormat, _mesa_lookup_enum_by_nr(outFormat),
+ map[0],
+ map[1],
+ map[2],
+ map[3],
+ map[4],
+ map[5]);
+#endif
+}
+
+
+/**
+ * Make a temporary (color) texture image with GLfloat components.
+ * Apply all needed pixel unpacking and pixel transfer operations.
+ * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
+ * Suppose the user specifies GL_LUMINANCE as the internal texture format
+ * but the graphics hardware doesn't support luminance textures. So, we might
+ * use an RGB hardware format instead.
+ * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
+ *
+ * \param ctx the rendering context
+ * \param dims image dimensions: 1, 2 or 3
+ * \param logicalBaseFormat basic texture derived from the user's
+ * internal texture format value
+ * \param textureBaseFormat the actual basic format of the texture
+ * \param srcWidth source image width
+ * \param srcHeight source image height
+ * \param srcDepth source image depth
+ * \param srcFormat source image format
+ * \param srcType source image type
+ * \param srcAddr source image address
+ * \param srcPacking source image pixel packing
+ * \return resulting image with format = textureBaseFormat and type = GLfloat.
+ */
+GLfloat *
+_mesa_make_temp_float_image(struct gl_context *ctx, GLuint dims,
+ GLenum logicalBaseFormat,
+ GLenum textureBaseFormat,
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ GLenum srcFormat, GLenum srcType,
+ const GLvoid *srcAddr,
+ const struct gl_pixelstore_attrib *srcPacking,
+ GLbitfield transferOps)
+{
+ GLfloat *tempImage;
+ const GLint components = _mesa_components_in_format(logicalBaseFormat);
+ const GLint srcStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
+ GLfloat *dst;
+ GLint img, row;
+
+ ASSERT(dims >= 1 && dims <= 3);
+
+ ASSERT(logicalBaseFormat == GL_RGBA ||
+ logicalBaseFormat == GL_RGB ||
+ logicalBaseFormat == GL_RG ||
+ logicalBaseFormat == GL_RED ||
+ logicalBaseFormat == GL_LUMINANCE_ALPHA ||
+ logicalBaseFormat == GL_LUMINANCE ||
+ logicalBaseFormat == GL_ALPHA ||
+ logicalBaseFormat == GL_INTENSITY ||
+ logicalBaseFormat == GL_COLOR_INDEX ||
+ logicalBaseFormat == GL_DEPTH_COMPONENT);
+
+ ASSERT(textureBaseFormat == GL_RGBA ||
+ textureBaseFormat == GL_RGB ||
+ textureBaseFormat == GL_RG ||
+ textureBaseFormat == GL_RED ||
+ textureBaseFormat == GL_LUMINANCE_ALPHA ||
+ textureBaseFormat == GL_LUMINANCE ||
+ textureBaseFormat == GL_ALPHA ||
+ textureBaseFormat == GL_INTENSITY ||
+ textureBaseFormat == GL_COLOR_INDEX ||
+ textureBaseFormat == GL_DEPTH_COMPONENT);
+
+ tempImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
+ * components * sizeof(GLfloat));
+ if (!tempImage)
+ return NULL;
+
+ dst = tempImage;
+ for (img = 0; img < srcDepth; img++) {
+ const GLubyte *src
+ = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
+ srcWidth, srcHeight,
+ srcFormat, srcType,
+ img, 0, 0);
+ for (row = 0; row < srcHeight; row++) {
+ _mesa_unpack_color_span_float(ctx, srcWidth, logicalBaseFormat,
+ dst, srcFormat, srcType, src,
+ srcPacking, transferOps);
+ dst += srcWidth * components;
+ src += srcStride;
+ }
+ }
+
+ if (logicalBaseFormat != textureBaseFormat) {
+ /* more work */
+ GLint texComponents = _mesa_components_in_format(textureBaseFormat);
+ GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
+ GLfloat *newImage;
+ GLint i, n;
+ GLubyte map[6];
+
+ /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
+ ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
+ textureBaseFormat == GL_LUMINANCE_ALPHA);
+
+ /* The actual texture format should have at least as many components
+ * as the logical texture format.
+ */
+ ASSERT(texComponents >= logComponents);
+
+ newImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
+ * texComponents * sizeof(GLfloat));
+ if (!newImage) {
+ free(tempImage);
+ return NULL;
+ }
+
+ compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
+
+ n = srcWidth * srcHeight * srcDepth;
+ for (i = 0; i < n; i++) {
+ GLint k;
+ for (k = 0; k < texComponents; k++) {
+ GLint j = map[k];
+ if (j == ZERO)
+ newImage[i * texComponents + k] = 0.0F;
+ else if (j == ONE)
+ newImage[i * texComponents + k] = 1.0F;
+ else
+ newImage[i * texComponents + k] = tempImage[i * logComponents + j];
+ }
+ }
+
+ free(tempImage);
+ tempImage = newImage;
+ }
+
+ return tempImage;
+}
+
+
+/**
+ * Make temporary image with uint pixel values. Used for unsigned
+ * integer-valued textures.
+ */
+static GLuint *
+make_temp_uint_image(struct gl_context *ctx, GLuint dims,
+ GLenum logicalBaseFormat,
+ GLenum textureBaseFormat,
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ GLenum srcFormat, GLenum srcType,
+ const GLvoid *srcAddr,
+ const struct gl_pixelstore_attrib *srcPacking)
+{
+ GLuint *tempImage;
+ const GLint components = _mesa_components_in_format(logicalBaseFormat);
+ const GLint srcStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
+ GLuint *dst;
+ GLint img, row;
+
+ ASSERT(dims >= 1 && dims <= 3);
+
+ ASSERT(logicalBaseFormat == GL_RGBA ||
+ logicalBaseFormat == GL_RGB ||
+ logicalBaseFormat == GL_RG ||
+ logicalBaseFormat == GL_RED ||
+ logicalBaseFormat == GL_LUMINANCE_ALPHA ||
+ logicalBaseFormat == GL_LUMINANCE ||
+ logicalBaseFormat == GL_INTENSITY ||
+ logicalBaseFormat == GL_ALPHA);
+
+ ASSERT(textureBaseFormat == GL_RGBA ||
+ textureBaseFormat == GL_RGB ||
+ textureBaseFormat == GL_RG ||
+ textureBaseFormat == GL_RED ||
+ textureBaseFormat == GL_LUMINANCE_ALPHA ||
+ textureBaseFormat == GL_LUMINANCE ||
+ textureBaseFormat == GL_ALPHA);
+
+ tempImage = (GLuint *) malloc(srcWidth * srcHeight * srcDepth
+ * components * sizeof(GLuint));
+ if (!tempImage)
+ return NULL;
+
+ dst = tempImage;
+ for (img = 0; img < srcDepth; img++) {
+ const GLubyte *src
+ = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
+ srcWidth, srcHeight,
+ srcFormat, srcType,
+ img, 0, 0);
+ for (row = 0; row < srcHeight; row++) {
+ _mesa_unpack_color_span_uint(ctx, srcWidth, logicalBaseFormat,
+ dst, srcFormat, srcType, src,
+ srcPacking);
+ dst += srcWidth * components;
+ src += srcStride;
+ }
+ }
+
+ if (logicalBaseFormat != textureBaseFormat) {
+ /* more work */
+ GLint texComponents = _mesa_components_in_format(textureBaseFormat);
+ GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
+ GLuint *newImage;
+ GLint i, n;
+ GLubyte map[6];
+
+ /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
+ ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
+ textureBaseFormat == GL_LUMINANCE_ALPHA);
+
+ /* The actual texture format should have at least as many components
+ * as the logical texture format.
+ */
+ ASSERT(texComponents >= logComponents);
+
+ newImage = (GLuint *) malloc(srcWidth * srcHeight * srcDepth
+ * texComponents * sizeof(GLuint));
+ if (!newImage) {
+ free(tempImage);
+ return NULL;
+ }
+
+ compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
+
+ n = srcWidth * srcHeight * srcDepth;
+ for (i = 0; i < n; i++) {
+ GLint k;
+ for (k = 0; k < texComponents; k++) {
+ GLint j = map[k];
+ if (j == ZERO)
+ newImage[i * texComponents + k] = 0.0F;
+ else if (j == ONE)
+ newImage[i * texComponents + k] = 1.0F;
+ else
+ newImage[i * texComponents + k] = tempImage[i * logComponents + j];
+ }
+ }
+
+ free(tempImage);
+ tempImage = newImage;
+ }
+
+ return tempImage;
+}
+
+
+
+/**
+ * Make a temporary (color) texture image with GLchan components.
+ * Apply all needed pixel unpacking and pixel transfer operations.
+ * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
+ * Suppose the user specifies GL_LUMINANCE as the internal texture format
+ * but the graphics hardware doesn't support luminance textures. So, we might
+ * use an RGB hardware format instead.
+ * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
+ *
+ * \param ctx the rendering context
+ * \param dims image dimensions: 1, 2 or 3
+ * \param logicalBaseFormat basic texture derived from the user's
+ * internal texture format value
+ * \param textureBaseFormat the actual basic format of the texture
+ * \param srcWidth source image width
+ * \param srcHeight source image height
+ * \param srcDepth source image depth
+ * \param srcFormat source image format
+ * \param srcType source image type
+ * \param srcAddr source image address
+ * \param srcPacking source image pixel packing
+ * \return resulting image with format = textureBaseFormat and type = GLchan.
+ */
+GLchan *
+_mesa_make_temp_chan_image(struct gl_context *ctx, GLuint dims,
+ GLenum logicalBaseFormat,
+ GLenum textureBaseFormat,
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ GLenum srcFormat, GLenum srcType,
+ const GLvoid *srcAddr,
+ const struct gl_pixelstore_attrib *srcPacking)
+{
+ GLuint transferOps = ctx->_ImageTransferState;
+ const GLint components = _mesa_components_in_format(logicalBaseFormat);
+ GLint img, row;
+ GLchan *tempImage, *dst;
+
+ ASSERT(dims >= 1 && dims <= 3);
+
+ ASSERT(logicalBaseFormat == GL_RGBA ||
+ logicalBaseFormat == GL_RGB ||
+ logicalBaseFormat == GL_RG ||
+ logicalBaseFormat == GL_RED ||
+ logicalBaseFormat == GL_LUMINANCE_ALPHA ||
+ logicalBaseFormat == GL_LUMINANCE ||
+ logicalBaseFormat == GL_ALPHA ||
+ logicalBaseFormat == GL_INTENSITY);
+
+ ASSERT(textureBaseFormat == GL_RGBA ||
+ textureBaseFormat == GL_RGB ||
+ textureBaseFormat == GL_RG ||
+ textureBaseFormat == GL_RED ||
+ textureBaseFormat == GL_LUMINANCE_ALPHA ||
+ textureBaseFormat == GL_LUMINANCE ||
+ textureBaseFormat == GL_ALPHA ||
+ textureBaseFormat == GL_INTENSITY);
+
+ /* unpack and transfer the source image */
+ tempImage = (GLchan *) malloc(srcWidth * srcHeight * srcDepth
+ * components * sizeof(GLchan));
+ if (!tempImage) {
+ return NULL;
+ }
+
+ dst = tempImage;
+ for (img = 0; img < srcDepth; img++) {
+ const GLint srcStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
+ const GLubyte *src =
+ (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
+ srcWidth, srcHeight,
+ srcFormat, srcType,
+ img, 0, 0);
+ for (row = 0; row < srcHeight; row++) {
+ _mesa_unpack_color_span_chan(ctx, srcWidth, logicalBaseFormat, dst,
+ srcFormat, srcType, src, srcPacking,
+ transferOps);
+ dst += srcWidth * components;
+ src += srcStride;
+ }
+ }
+
+ if (logicalBaseFormat != textureBaseFormat) {
+ /* one more conversion step */
+ GLint texComponents = _mesa_components_in_format(textureBaseFormat);
+ GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
+ GLchan *newImage;
+ GLint i, n;
+ GLubyte map[6];
+
+ /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
+ ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
+ textureBaseFormat == GL_LUMINANCE_ALPHA);
+
+ /* The actual texture format should have at least as many components
+ * as the logical texture format.
+ */
+ ASSERT(texComponents >= logComponents);
+
+ newImage = (GLchan *) malloc(srcWidth * srcHeight * srcDepth
+ * texComponents * sizeof(GLchan));
+ if (!newImage) {
+ free(tempImage);
+ return NULL;
+ }
+
+ compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
+
+ n = srcWidth * srcHeight * srcDepth;
+ for (i = 0; i < n; i++) {
+ GLint k;
+ for (k = 0; k < texComponents; k++) {
+ GLint j = map[k];
+ if (j == ZERO)
+ newImage[i * texComponents + k] = 0;
+ else if (j == ONE)
+ newImage[i * texComponents + k] = CHAN_MAX;
+ else
+ newImage[i * texComponents + k] = tempImage[i * logComponents + j];
+ }
+ }
+
+ free(tempImage);
+ tempImage = newImage;
+ }
+
+ return tempImage;
+}
+
+
+/**
+ * Copy GLubyte pixels from <src> to <dst> with swizzling.
+ * \param dst destination pixels
+ * \param dstComponents number of color components in destination pixels
+ * \param src source pixels
+ * \param srcComponents number of color components in source pixels
+ * \param map the swizzle mapping. map[X] says where to find the X component
+ * in the source image's pixels. For example, if the source image
+ * is GL_BGRA and X = red, map[0] yields 2.
+ * \param count number of pixels to copy/swizzle.
+ */
+static void
+swizzle_copy(GLubyte *dst, GLuint dstComponents, const GLubyte *src,
+ GLuint srcComponents, const GLubyte *map, GLuint count)
+{
+#define SWZ_CPY(dst, src, count, dstComps, srcComps) \
+ do { \
+ GLuint i; \
+ for (i = 0; i < count; i++) { \
+ GLuint j; \
+ if (srcComps == 4) { \
+ COPY_4UBV(tmp, src); \
+ } \
+ else { \
+ for (j = 0; j < srcComps; j++) { \
+ tmp[j] = src[j]; \
+ } \
+ } \
+ src += srcComps; \
+ for (j = 0; j < dstComps; j++) { \
+ dst[j] = tmp[map[j]]; \
+ } \
+ dst += dstComps; \
+ } \
+ } while (0)
+
+ GLubyte tmp[6];
+
+ tmp[ZERO] = 0x0;
+ tmp[ONE] = 0xff;
+
+ ASSERT(srcComponents <= 4);
+ ASSERT(dstComponents <= 4);
+
+ switch (dstComponents) {
+ case 4:
+ switch (srcComponents) {
+ case 4:
+ SWZ_CPY(dst, src, count, 4, 4);
+ break;
+ case 3:
+ SWZ_CPY(dst, src, count, 4, 3);
+ break;
+ case 2:
+ SWZ_CPY(dst, src, count, 4, 2);
+ break;
+ case 1:
+ SWZ_CPY(dst, src, count, 4, 1);
+ break;
+ default:
+ ;
+ }
+ break;
+ case 3:
+ switch (srcComponents) {
+ case 4:
+ SWZ_CPY(dst, src, count, 3, 4);
+ break;
+ case 3:
+ SWZ_CPY(dst, src, count, 3, 3);
+ break;
+ case 2:
+ SWZ_CPY(dst, src, count, 3, 2);
+ break;
+ case 1:
+ SWZ_CPY(dst, src, count, 3, 1);
+ break;
+ default:
+ ;
+ }
+ break;
+ case 2:
+ switch (srcComponents) {
+ case 4:
+ SWZ_CPY(dst, src, count, 2, 4);
+ break;
+ case 3:
+ SWZ_CPY(dst, src, count, 2, 3);
+ break;
+ case 2:
+ SWZ_CPY(dst, src, count, 2, 2);
+ break;
+ case 1:
+ SWZ_CPY(dst, src, count, 2, 1);
+ break;
+ default:
+ ;
+ }
+ break;
+ case 1:
+ switch (srcComponents) {
+ case 4:
+ SWZ_CPY(dst, src, count, 1, 4);
+ break;
+ case 3:
+ SWZ_CPY(dst, src, count, 1, 3);
+ break;
+ case 2:
+ SWZ_CPY(dst, src, count, 1, 2);
+ break;
+ case 1:
+ SWZ_CPY(dst, src, count, 1, 1);
+ break;
+ default:
+ ;
+ }
+ break;
+ default:
+ ;
+ }
+#undef SWZ_CPY
+}
+
+
+
+static const GLubyte map_identity[6] = { 0, 1, 2, 3, ZERO, ONE };
+static const GLubyte map_3210[6] = { 3, 2, 1, 0, ZERO, ONE };
+
+
+/**
+ * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
+ * mapping array depending on endianness.
+ */
+static const GLubyte *
+type_mapping( GLenum srcType )
+{
+ switch (srcType) {
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ return map_identity;
+ case GL_UNSIGNED_INT_8_8_8_8:
+ return _mesa_little_endian() ? map_3210 : map_identity;
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ return _mesa_little_endian() ? map_identity : map_3210;
+ default:
+ return NULL;
+ }
+}
+
+
+/**
+ * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
+ * mapping array depending on pixelstore byte swapping state.
+ */
+static const GLubyte *
+byteswap_mapping( GLboolean swapBytes,
+ GLenum srcType )
+{
+ if (!swapBytes)
+ return map_identity;
+
+ switch (srcType) {
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ return map_identity;
+ case GL_UNSIGNED_INT_8_8_8_8:
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ return map_3210;
+ default:
+ return NULL;
+ }
+}
+
+
+
+/**
+ * Transfer a GLubyte texture image with component swizzling.
+ */
+static void
+_mesa_swizzle_ubyte_image(struct gl_context *ctx,
+ GLuint dimensions,
+ GLenum srcFormat,
+ GLenum srcType,
+
+ GLenum baseInternalFormat,
+
+ const GLubyte *rgba2dst,
+ GLuint dstComponents,
+
+ GLvoid *dstAddr,
+ GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
+ GLint dstRowStride,
+ const GLuint *dstImageOffsets,
+
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ const GLvoid *srcAddr,
+ const struct gl_pixelstore_attrib *srcPacking )
+{
+ GLint srcComponents = _mesa_components_in_format(srcFormat);
+ const GLubyte *srctype2ubyte, *swap;
+ GLubyte map[4], src2base[6], base2rgba[6];
+ GLint i;
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth,
+ srcFormat, GL_UNSIGNED_BYTE);
+ const GLint srcImageStride
+ = _mesa_image_image_stride(srcPacking, srcWidth, srcHeight, srcFormat,
+ GL_UNSIGNED_BYTE);
+ const GLubyte *srcImage
+ = (const GLubyte *) _mesa_image_address(dimensions, srcPacking, srcAddr,
+ srcWidth, srcHeight, srcFormat,
+ GL_UNSIGNED_BYTE, 0, 0, 0);
+
+ (void) ctx;
+
+ /* Translate from src->baseInternal->GL_RGBA->dst. This will
+ * correctly deal with RGBA->RGB->RGBA conversions where the final
+ * A value must be 0xff regardless of the incoming alpha values.
+ */
+ compute_component_mapping(srcFormat, baseInternalFormat, src2base);
+ compute_component_mapping(baseInternalFormat, GL_RGBA, base2rgba);
+ swap = byteswap_mapping(srcPacking->SwapBytes, srcType);
+ srctype2ubyte = type_mapping(srcType);
+
+
+ for (i = 0; i < 4; i++)
+ map[i] = srctype2ubyte[swap[src2base[base2rgba[rgba2dst[i]]]]];
+
+/* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
+
+ if (srcComponents == dstComponents &&
+ srcRowStride == dstRowStride &&
+ srcRowStride == srcWidth * srcComponents &&
+ dimensions < 3) {
+ /* 1 and 2D images only */
+ GLubyte *dstImage = (GLubyte *) dstAddr
+ + dstYoffset * dstRowStride
+ + dstXoffset * dstComponents;
+ swizzle_copy(dstImage, dstComponents, srcImage, srcComponents, map,
+ srcWidth * srcHeight);
+ }
+ else {
+ GLint img, row;
+ for (img = 0; img < srcDepth; img++) {
+ const GLubyte *srcRow = srcImage;
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * dstComponents
+ + dstYoffset * dstRowStride
+ + dstXoffset * dstComponents;
+ for (row = 0; row < srcHeight; row++) {
+ swizzle_copy(dstRow, dstComponents, srcRow, srcComponents, map, srcWidth);
+ dstRow += dstRowStride;
+ srcRow += srcRowStride;
+ }
+ srcImage += srcImageStride;
+ }
+ }
+}
+
+
+/**
+ * Teximage storage routine for when a simple memcpy will do.
+ * No pixel transfer operations or special texel encodings allowed.
+ * 1D, 2D and 3D images supported.
+ */
+static void
+memcpy_texture(struct gl_context *ctx,
+ GLuint dimensions,
+ gl_format dstFormat,
+ GLvoid *dstAddr,
+ GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
+ GLint dstRowStride,
+ const GLuint *dstImageOffsets,
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ GLenum srcFormat, GLenum srcType,
+ const GLvoid *srcAddr,
+ const struct gl_pixelstore_attrib *srcPacking)
+{
+ const GLint srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth,
+ srcFormat, srcType);
+ const GLint srcImageStride = _mesa_image_image_stride(srcPacking,
+ srcWidth, srcHeight, srcFormat, srcType);
+ const GLubyte *srcImage = (const GLubyte *) _mesa_image_address(dimensions,
+ srcPacking, srcAddr, srcWidth, srcHeight, srcFormat, srcType, 0, 0, 0);
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLint bytesPerRow = srcWidth * texelBytes;
+
+#if 0
+ /* XXX update/re-enable for dstImageOffsets array */
+ const GLint bytesPerImage = srcHeight * bytesPerRow;
+ const GLint bytesPerTexture = srcDepth * bytesPerImage;
+ GLubyte *dstImage = (GLubyte *) dstAddr
+ + dstZoffset * dstImageStride
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+
+ if (dstRowStride == srcRowStride &&
+ dstRowStride == bytesPerRow &&
+ ((dstImageStride == srcImageStride &&
+ dstImageStride == bytesPerImage) ||
+ (srcDepth == 1))) {
+ /* one big memcpy */
+ ctx->Driver.TextureMemCpy(dstImage, srcImage, bytesPerTexture);
+ }
+ else
+ {
+ GLint img, row;
+ for (img = 0; img < srcDepth; img++) {
+ const GLubyte *srcRow = srcImage;
+ GLubyte *dstRow = dstImage;
+ for (row = 0; row < srcHeight; row++) {
+ ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);
+ dstRow += dstRowStride;
+ srcRow += srcRowStride;
+ }
+ srcImage += srcImageStride;
+ dstImage += dstImageStride;
+ }
+ }
+#endif
+
+ GLint img, row;
+ for (img = 0; img < srcDepth; img++) {
+ const GLubyte *srcRow = srcImage;
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);
+ dstRow += dstRowStride;
+ srcRow += srcRowStride;
+ }
+ srcImage += srcImageStride;
+ }
+}
+
+
+
+/**
+ * Store a 32-bit integer depth component texture image.
+ */
+static GLboolean
+_mesa_texstore_z32(TEXSTORE_PARAMS)
+{
+ const GLuint depthScale = 0xffffffff;
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ (void) dims;
+ ASSERT(dstFormat == MESA_FORMAT_Z32);
+ ASSERT(texelBytes == sizeof(GLuint));
+
+ if (ctx->Pixel.DepthScale == 1.0f &&
+ ctx->Pixel.DepthBias == 0.0f &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == GL_DEPTH_COMPONENT &&
+ srcFormat == GL_DEPTH_COMPONENT &&
+ srcType == GL_UNSIGNED_INT) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ GLint img, row;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ const GLvoid *src = _mesa_image_address(dims, srcPacking,
+ srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
+ _mesa_unpack_depth_span(ctx, srcWidth,
+ GL_UNSIGNED_INT, (GLuint *) dstRow,
+ depthScale, srcType, src, srcPacking);
+ dstRow += dstRowStride;
+ }
+ }
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store a 24-bit integer depth component texture image.
+ */
+static GLboolean
+_mesa_texstore_x8_z24(TEXSTORE_PARAMS)
+{
+ const GLuint depthScale = 0xffffff;
+ const GLuint texelBytes = 4;
+
+ (void) dims;
+ ASSERT(dstFormat == MESA_FORMAT_X8_Z24);
+
+ {
+ /* general path */
+ GLint img, row;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ const GLvoid *src = _mesa_image_address(dims, srcPacking,
+ srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
+ _mesa_unpack_depth_span(ctx, srcWidth,
+ GL_UNSIGNED_INT, (GLuint *) dstRow,
+ depthScale, srcType, src, srcPacking);
+ dstRow += dstRowStride;
+ }
+ }
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store a 24-bit integer depth component texture image.
+ */
+static GLboolean
+_mesa_texstore_z24_x8(TEXSTORE_PARAMS)
+{
+ const GLuint depthScale = 0xffffff;
+ const GLuint texelBytes = 4;
+
+ (void) dims;
+ ASSERT(dstFormat == MESA_FORMAT_Z24_X8);
+
+ {
+ /* general path */
+ GLint img, row;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ const GLvoid *src = _mesa_image_address(dims, srcPacking,
+ srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
+ GLuint *dst = (GLuint *) dstRow;
+ GLint i;
+ _mesa_unpack_depth_span(ctx, srcWidth,
+ GL_UNSIGNED_INT, dst,
+ depthScale, srcType, src, srcPacking);
+ for (i = 0; i < srcWidth; i++)
+ dst[i] <<= 8;
+ dstRow += dstRowStride;
+ }
+ }
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store a 16-bit integer depth component texture image.
+ */
+static GLboolean
+_mesa_texstore_z16(TEXSTORE_PARAMS)
+{
+ const GLuint depthScale = 0xffff;
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ (void) dims;
+ ASSERT(dstFormat == MESA_FORMAT_Z16);
+ ASSERT(texelBytes == sizeof(GLushort));
+
+ if (ctx->Pixel.DepthScale == 1.0f &&
+ ctx->Pixel.DepthBias == 0.0f &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == GL_DEPTH_COMPONENT &&
+ srcFormat == GL_DEPTH_COMPONENT &&
+ srcType == GL_UNSIGNED_SHORT) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ GLint img, row;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ const GLvoid *src = _mesa_image_address(dims, srcPacking,
+ srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
+ GLushort *dst16 = (GLushort *) dstRow;
+ _mesa_unpack_depth_span(ctx, srcWidth,
+ GL_UNSIGNED_SHORT, dst16, depthScale,
+ srcType, src, srcPacking);
+ dstRow += dstRowStride;
+ }
+ }
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store an rgb565 or rgb565_rev texture image.
+ */
+static GLboolean
+_mesa_texstore_rgb565(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGB565 ||
+ dstFormat == MESA_FORMAT_RGB565_REV);
+ ASSERT(texelBytes == 2);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ dstFormat == MESA_FORMAT_RGB565 &&
+ baseInternalFormat == GL_RGB &&
+ srcFormat == GL_RGB &&
+ srcType == GL_UNSIGNED_SHORT_5_6_5) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == GL_RGB &&
+ srcFormat == GL_RGB &&
+ srcType == GL_UNSIGNED_BYTE &&
+ dims == 2) {
+ /* do optimized tex store */
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
+ const GLubyte *src = (const GLubyte *)
+ _mesa_image_address(dims, srcPacking, srcAddr, srcWidth, srcHeight,
+ srcFormat, srcType, 0, 0, 0);
+ GLubyte *dst = (GLubyte *) dstAddr
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ GLint row, col;
+ for (row = 0; row < srcHeight; row++) {
+ const GLubyte *srcUB = (const GLubyte *) src;
+ GLushort *dstUS = (GLushort *) dst;
+ /* check for byteswapped format */
+ if (dstFormat == MESA_FORMAT_RGB565) {
+ for (col = 0; col < srcWidth; col++) {
+ dstUS[col] = PACK_COLOR_565( srcUB[0], srcUB[1], srcUB[2] );
+ srcUB += 3;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ dstUS[col] = PACK_COLOR_565_REV( srcUB[0], srcUB[1], srcUB[2] );
+ srcUB += 3;
+ }
+ }
+ dst += dstRowStride;
+ src += srcRowStride;
+ }
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLushort *dstUS = (GLushort *) dstRow;
+ /* check for byteswapped format */
+ if (dstFormat == MESA_FORMAT_RGB565) {
+ for (col = 0; col < srcWidth; col++) {
+ dstUS[col] = PACK_COLOR_565( CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 3;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ dstUS[col] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 3;
+ }
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
+ */
+static GLboolean
+_mesa_texstore_rgba8888(TEXSTORE_PARAMS)
+{
+ const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA8888 ||
+ dstFormat == MESA_FORMAT_RGBA8888_REV);
+ ASSERT(texelBytes == 4);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ dstFormat == MESA_FORMAT_RGBA8888 &&
+ baseInternalFormat == GL_RGBA &&
+ ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
+ (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
+ (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||
+ (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && littleEndian))) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ dstFormat == MESA_FORMAT_RGBA8888_REV &&
+ baseInternalFormat == GL_RGBA &&
+ ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||
+ (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && littleEndian) ||
+ (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
+ (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && !littleEndian))) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ (srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8 ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8_REV) &&
+ can_swizzle(baseInternalFormat) &&
+ can_swizzle(srcFormat)) {
+
+ GLubyte dstmap[4];
+
+ /* dstmap - how to swizzle from RGBA to dst format:
+ */
+ if ((littleEndian && dstFormat == MESA_FORMAT_RGBA8888) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_RGBA8888_REV)) {
+ dstmap[3] = 0;
+ dstmap[2] = 1;
+ dstmap[1] = 2;
+ dstmap[0] = 3;
+ }
+ else {
+ dstmap[3] = 3;
+ dstmap[2] = 2;
+ dstmap[1] = 1;
+ dstmap[0] = 0;
+ }
+
+ _mesa_swizzle_ubyte_image(ctx, dims,
+ srcFormat,
+ srcType,
+ baseInternalFormat,
+ dstmap, 4,
+ dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcAddr,
+ srcPacking);
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstUI = (GLuint *) dstRow;
+ if (dstFormat == MESA_FORMAT_RGBA8888) {
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]),
+ CHAN_TO_UBYTE(src[ACOMP]) );
+ src += 4;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]),
+ CHAN_TO_UBYTE(src[ACOMP]) );
+ src += 4;
+ }
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_argb8888(TEXSTORE_PARAMS)
+{
+ const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = GL_RGBA;
+
+ ASSERT(dstFormat == MESA_FORMAT_ARGB8888 ||
+ dstFormat == MESA_FORMAT_ARGB8888_REV ||
+ dstFormat == MESA_FORMAT_XRGB8888 ||
+ dstFormat == MESA_FORMAT_XRGB8888_REV );
+ ASSERT(texelBytes == 4);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ (dstFormat == MESA_FORMAT_ARGB8888 ||
+ dstFormat == MESA_FORMAT_XRGB8888) &&
+ baseInternalFormat == GL_RGBA &&
+ srcFormat == GL_BGRA &&
+ ((srcType == GL_UNSIGNED_BYTE && littleEndian) ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8_REV)) {
+ /* simple memcpy path (little endian) */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ (dstFormat == MESA_FORMAT_ARGB8888_REV ||
+ dstFormat == MESA_FORMAT_XRGB8888_REV) &&
+ baseInternalFormat == GL_RGBA &&
+ srcFormat == GL_BGRA &&
+ ((srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8)) {
+ /* simple memcpy path (big endian) */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ (dstFormat == MESA_FORMAT_ARGB8888 ||
+ dstFormat == MESA_FORMAT_XRGB8888) &&
+ srcFormat == GL_RGB &&
+ (baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB) &&
+ srcType == GL_UNSIGNED_BYTE) {
+ int img, row, col;
+ for (img = 0; img < srcDepth; img++) {
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
+ GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
+ srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *d4 = (GLuint *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ d4[col] = PACK_COLOR_8888(0xff,
+ srcRow[col * 3 + RCOMP],
+ srcRow[col * 3 + GCOMP],
+ srcRow[col * 3 + BCOMP]);
+ }
+ dstRow += dstRowStride;
+ srcRow += srcRowStride;
+ }
+ }
+ }
+ else if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ dstFormat == MESA_FORMAT_ARGB8888 &&
+ srcFormat == GL_RGBA &&
+ baseInternalFormat == GL_RGBA &&
+ srcType == GL_UNSIGNED_BYTE) {
+ /* same as above case, but src data has alpha too */
+ GLint img, row, col;
+ /* For some reason, streaming copies to write-combined regions
+ * are extremely sensitive to the characteristics of how the
+ * source data is retrieved. By reordering the source reads to
+ * be in-order, the speed of this operation increases by half.
+ * Strangely the same isn't required for the RGB path, above.
+ */
+ for (img = 0; img < srcDepth; img++) {
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
+ GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
+ srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *d4 = (GLuint *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ d4[col] = PACK_COLOR_8888(srcRow[col * 4 + ACOMP],
+ srcRow[col * 4 + RCOMP],
+ srcRow[col * 4 + GCOMP],
+ srcRow[col * 4 + BCOMP]);
+ }
+ dstRow += dstRowStride;
+ srcRow += srcRowStride;
+ }
+ }
+ }
+ else if (!ctx->_ImageTransferState &&
+ (srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8 ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8_REV) &&
+ can_swizzle(baseInternalFormat) &&
+ can_swizzle(srcFormat)) {
+
+ GLubyte dstmap[4];
+
+ /* dstmap - how to swizzle from RGBA to dst format:
+ */
+ if ((littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
+ (littleEndian && dstFormat == MESA_FORMAT_XRGB8888) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888_REV)) {
+ dstmap[3] = 3; /* alpha */
+ dstmap[2] = 0; /* red */
+ dstmap[1] = 1; /* green */
+ dstmap[0] = 2; /* blue */
+ }
+ else {
+ assert((littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
+ (littleEndian && dstFormat == MESA_FORMAT_XRGB8888_REV) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888));
+ dstmap[3] = 2;
+ dstmap[2] = 1;
+ dstmap[1] = 0;
+ dstmap[0] = 3;
+ }
+
+ _mesa_swizzle_ubyte_image(ctx, dims,
+ srcFormat,
+ srcType,
+ baseInternalFormat,
+ dstmap, 4,
+ dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcAddr,
+ srcPacking);
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstUI = (GLuint *) dstRow;
+ if (dstFormat == MESA_FORMAT_ARGB8888) {
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[ACOMP]),
+ CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 4;
+ }
+ }
+ else if (dstFormat == MESA_FORMAT_XRGB8888) {
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = PACK_COLOR_8888( 0xff,
+ CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 4;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[ACOMP]),
+ CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 4;
+ }
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_rgb888(TEXSTORE_PARAMS)
+{
+ const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGB888);
+ ASSERT(texelBytes == 3);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == GL_RGB &&
+ srcFormat == GL_BGR &&
+ srcType == GL_UNSIGNED_BYTE &&
+ littleEndian) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ srcFormat == GL_RGBA &&
+ srcType == GL_UNSIGNED_BYTE) {
+ /* extract RGB from RGBA */
+ GLint img, row, col;
+ for (img = 0; img < srcDepth; img++) {
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
+ GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
+ srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ for (col = 0; col < srcWidth; col++) {
+ dstRow[col * 3 + 0] = srcRow[col * 4 + BCOMP];
+ dstRow[col * 3 + 1] = srcRow[col * 4 + GCOMP];
+ dstRow[col * 3 + 2] = srcRow[col * 4 + RCOMP];
+ }
+ dstRow += dstRowStride;
+ srcRow += srcRowStride;
+ }
+ }
+ }
+ else if (!ctx->_ImageTransferState &&
+ srcType == GL_UNSIGNED_BYTE &&
+ can_swizzle(baseInternalFormat) &&
+ can_swizzle(srcFormat)) {
+
+ GLubyte dstmap[4];
+
+ /* dstmap - how to swizzle from RGBA to dst format:
+ */
+ dstmap[0] = 2;
+ dstmap[1] = 1;
+ dstmap[2] = 0;
+ dstmap[3] = ONE; /* ? */
+
+ _mesa_swizzle_ubyte_image(ctx, dims,
+ srcFormat,
+ srcType,
+ baseInternalFormat,
+ dstmap, 3,
+ dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcAddr,
+ srcPacking);
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src = (const GLchan *) tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+#if 0
+ if (littleEndian) {
+ for (col = 0; col < srcWidth; col++) {
+ dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[RCOMP]);
+ dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
+ dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[BCOMP]);
+ srcUB += 3;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ dstRow[col * 3 + 0] = srcUB[BCOMP];
+ dstRow[col * 3 + 1] = srcUB[GCOMP];
+ dstRow[col * 3 + 2] = srcUB[RCOMP];
+ srcUB += 3;
+ }
+ }
+#else
+ for (col = 0; col < srcWidth; col++) {
+ dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[BCOMP]);
+ dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
+ dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[RCOMP]);
+ src += 3;
+ }
+#endif
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_bgr888(TEXSTORE_PARAMS)
+{
+ const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_BGR888);
+ ASSERT(texelBytes == 3);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == GL_RGB &&
+ srcFormat == GL_RGB &&
+ srcType == GL_UNSIGNED_BYTE &&
+ littleEndian) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ srcFormat == GL_RGBA &&
+ srcType == GL_UNSIGNED_BYTE) {
+ /* extract BGR from RGBA */
+ int img, row, col;
+ for (img = 0; img < srcDepth; img++) {
+ const GLint srcRowStride =
+ _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
+ GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
+ srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ for (col = 0; col < srcWidth; col++) {
+ dstRow[col * 3 + 0] = srcRow[col * 4 + RCOMP];
+ dstRow[col * 3 + 1] = srcRow[col * 4 + GCOMP];
+ dstRow[col * 3 + 2] = srcRow[col * 4 + BCOMP];
+ }
+ dstRow += dstRowStride;
+ srcRow += srcRowStride;
+ }
+ }
+ }
+ else if (!ctx->_ImageTransferState &&
+ srcType == GL_UNSIGNED_BYTE &&
+ can_swizzle(baseInternalFormat) &&
+ can_swizzle(srcFormat)) {
+
+ GLubyte dstmap[4];
+
+ /* dstmap - how to swizzle from RGBA to dst format:
+ */
+ dstmap[0] = 0;
+ dstmap[1] = 1;
+ dstmap[2] = 2;
+ dstmap[3] = ONE; /* ? */
+
+ _mesa_swizzle_ubyte_image(ctx, dims,
+ srcFormat,
+ srcType,
+ baseInternalFormat,
+ dstmap, 3,
+ dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcAddr,
+ srcPacking);
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src = (const GLchan *) tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ for (col = 0; col < srcWidth; col++) {
+ dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[RCOMP]);
+ dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
+ dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[BCOMP]);
+ src += 3;
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_argb4444(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_ARGB4444 ||
+ dstFormat == MESA_FORMAT_ARGB4444_REV);
+ ASSERT(texelBytes == 2);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ dstFormat == MESA_FORMAT_ARGB4444 &&
+ baseInternalFormat == GL_RGBA &&
+ srcFormat == GL_BGRA &&
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLushort *dstUS = (GLushort *) dstRow;
+ if (dstFormat == MESA_FORMAT_ARGB4444) {
+ for (col = 0; col < srcWidth; col++) {
+ dstUS[col] = PACK_COLOR_4444( CHAN_TO_UBYTE(src[ACOMP]),
+ CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 4;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ dstUS[col] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src[ACOMP]),
+ CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 4;
+ }
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+static GLboolean
+_mesa_texstore_rgba5551(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA5551);
+ ASSERT(texelBytes == 2);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ dstFormat == MESA_FORMAT_RGBA5551 &&
+ baseInternalFormat == GL_RGBA &&
+ srcFormat == GL_RGBA &&
+ srcType == GL_UNSIGNED_SHORT_5_5_5_1) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src =tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLushort *dstUS = (GLushort *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ dstUS[col] = PACK_COLOR_5551( CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]),
+ CHAN_TO_UBYTE(src[ACOMP]) );
+ src += 4;
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+static GLboolean
+_mesa_texstore_argb1555(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_ARGB1555 ||
+ dstFormat == MESA_FORMAT_ARGB1555_REV);
+ ASSERT(texelBytes == 2);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ dstFormat == MESA_FORMAT_ARGB1555 &&
+ baseInternalFormat == GL_RGBA &&
+ srcFormat == GL_BGRA &&
+ srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src =tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLushort *dstUS = (GLushort *) dstRow;
+ if (dstFormat == MESA_FORMAT_ARGB1555) {
+ for (col = 0; col < srcWidth; col++) {
+ dstUS[col] = PACK_COLOR_1555( CHAN_TO_UBYTE(src[ACOMP]),
+ CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 4;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ dstUS[col] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src[ACOMP]),
+ CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 4;
+ }
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_argb2101010(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_ARGB2101010);
+ ASSERT(texelBytes == 4);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ dstFormat == MESA_FORMAT_ARGB2101010 &&
+ srcFormat == GL_BGRA &&
+ srcType == GL_UNSIGNED_INT_2_10_10_10_REV &&
+ baseInternalFormat == GL_RGBA) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ if (baseInternalFormat == GL_RGBA) {
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstUI = (GLuint *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ GLushort a,r,g,b;
+
+ UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]);
+ dstUI[col] = PACK_COLOR_2101010_US(a, r, g, b);
+ src += 4;
+ }
+ dstRow += dstRowStride;
+ }
+ } else if (baseInternalFormat == GL_RGB) {
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstUI = (GLuint *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ GLushort r,g,b;
+
+ UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]);
+ dstUI[col] = PACK_COLOR_2101010_US(0xffff, r, g, b);
+ src += 4;
+ }
+ dstRow += dstRowStride;
+ }
+ } else {
+ ASSERT(0);
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
+ */
+static GLboolean
+_mesa_texstore_unorm44(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_AL44);
+ ASSERT(texelBytes == 1);
+
+ {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLubyte *dstUS = (GLubyte *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ /* src[0] is luminance, src[1] is alpha */
+ dstUS[col] = PACK_COLOR_44( CHAN_TO_UBYTE(src[1]),
+ CHAN_TO_UBYTE(src[0]) );
+ src += 2;
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
+ */
+static GLboolean
+_mesa_texstore_unorm88(TEXSTORE_PARAMS)
+{
+ const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_AL88 ||
+ dstFormat == MESA_FORMAT_AL88_REV ||
+ dstFormat == MESA_FORMAT_RG88 ||
+ dstFormat == MESA_FORMAT_RG88_REV);
+ ASSERT(texelBytes == 2);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ (dstFormat == MESA_FORMAT_AL88 || dstFormat == MESA_FORMAT_RG88) &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_UNSIGNED_BYTE &&
+ littleEndian) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ littleEndian &&
+ srcType == GL_UNSIGNED_BYTE &&
+ can_swizzle(baseInternalFormat) &&
+ can_swizzle(srcFormat)) {
+ GLubyte dstmap[4];
+
+ /* dstmap - how to swizzle from RGBA to dst format:
+ */
+ if (dstFormat == MESA_FORMAT_AL88 || dstFormat == MESA_FORMAT_AL88_REV) {
+ if ((littleEndian && dstFormat == MESA_FORMAT_AL88) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_AL88_REV)) {
+ dstmap[0] = 0;
+ dstmap[1] = 3;
+ }
+ else {
+ dstmap[0] = 3;
+ dstmap[1] = 0;
+ }
+ }
+ else {
+ if ((littleEndian && dstFormat == MESA_FORMAT_RG88) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_RG88_REV)) {
+ dstmap[0] = 0;
+ dstmap[1] = 1;
+ }
+ else {
+ dstmap[0] = 1;
+ dstmap[1] = 0;
+ }
+ }
+ dstmap[2] = ZERO; /* ? */
+ dstmap[3] = ONE; /* ? */
+
+ _mesa_swizzle_ubyte_image(ctx, dims,
+ srcFormat,
+ srcType,
+ baseInternalFormat,
+ dstmap, 2,
+ dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcAddr,
+ srcPacking);
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLushort *dstUS = (GLushort *) dstRow;
+ if (dstFormat == MESA_FORMAT_AL88 ||
+ dstFormat == MESA_FORMAT_RG88) {
+ for (col = 0; col < srcWidth; col++) {
+ /* src[0] is luminance, src[1] is alpha */
+ dstUS[col] = PACK_COLOR_88( CHAN_TO_UBYTE(src[1]),
+ CHAN_TO_UBYTE(src[0]) );
+ src += 2;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ /* src[0] is luminance, src[1] is alpha */
+ dstUS[col] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src[1]),
+ CHAN_TO_UBYTE(src[0]) );
+ src += 2;
+ }
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
+ */
+static GLboolean
+_mesa_texstore_unorm1616(TEXSTORE_PARAMS)
+{
+ const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_AL1616 ||
+ dstFormat == MESA_FORMAT_AL1616_REV ||
+ dstFormat == MESA_FORMAT_RG1616 ||
+ dstFormat == MESA_FORMAT_RG1616_REV);
+ ASSERT(texelBytes == 4);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ (dstFormat == MESA_FORMAT_AL1616 || dstFormat == MESA_FORMAT_RG1616) &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_UNSIGNED_SHORT &&
+ littleEndian) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstUI = (GLuint *) dstRow;
+ if (dstFormat == MESA_FORMAT_AL1616 ||
+ dstFormat == MESA_FORMAT_RG1616) {
+ for (col = 0; col < srcWidth; col++) {
+ GLushort l, a;
+
+ UNCLAMPED_FLOAT_TO_USHORT(l, src[0]);
+ UNCLAMPED_FLOAT_TO_USHORT(a, src[1]);
+ dstUI[col] = PACK_COLOR_1616(a, l);
+ src += 2;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ GLushort l, a;
+
+ UNCLAMPED_FLOAT_TO_USHORT(l, src[0]);
+ UNCLAMPED_FLOAT_TO_USHORT(a, src[1]);
+ dstUI[col] = PACK_COLOR_1616_REV(a, l);
+ src += 2;
+ }
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/* Texstore for R16, A16, L16, I16. */
+static GLboolean
+_mesa_texstore_unorm16(TEXSTORE_PARAMS)
+{
+ const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_R16 ||
+ dstFormat == MESA_FORMAT_A16 ||
+ dstFormat == MESA_FORMAT_L16 ||
+ dstFormat == MESA_FORMAT_I16);
+ ASSERT(texelBytes == 2);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_UNSIGNED_SHORT &&
+ littleEndian) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLushort *dstUS = (GLushort *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ GLushort r;
+
+ UNCLAMPED_FLOAT_TO_USHORT(r, src[0]);
+ dstUS[col] = r;
+ src += 1;
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_rgba_16(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_16);
+ ASSERT(texelBytes == 8);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == GL_RGBA &&
+ srcFormat == GL_RGBA &&
+ srcType == GL_UNSIGNED_SHORT) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLushort *dstUS = (GLushort *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ GLushort r, g, b, a;
+
+ UNCLAMPED_FLOAT_TO_USHORT(r, src[0]);
+ UNCLAMPED_FLOAT_TO_USHORT(g, src[1]);
+ UNCLAMPED_FLOAT_TO_USHORT(b, src[2]);
+ UNCLAMPED_FLOAT_TO_USHORT(a, src[3]);
+ dstUS[col*4+0] = r;
+ dstUS[col*4+1] = g;
+ dstUS[col*4+2] = b;
+ dstUS[col*4+3] = a;
+ src += 4;
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_SIGNED_R_16 ||
+ dstFormat == MESA_FORMAT_SIGNED_RG_16 ||
+ dstFormat == MESA_FORMAT_SIGNED_RGB_16 ||
+ dstFormat == MESA_FORMAT_SIGNED_RGBA_16);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == GL_RGBA &&
+ dstFormat == MESA_FORMAT_SIGNED_RGBA_16 &&
+ srcFormat == GL_RGBA &&
+ srcType == GL_SHORT) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *src = tempImage;
+ const GLuint comps = _mesa_get_format_bytes(dstFormat) / 2;
+ GLint img, row, col;
+
+ if (!tempImage)
+ return GL_FALSE;
+
+ /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
+ * 3 or 4 components/pixel here.
+ */
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLshort *dstRowS = (GLshort *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ GLuint c;
+ for (c = 0; c < comps; c++) {
+ GLshort p;
+ UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 4 + c]);
+ dstRowS[col * comps + c] = p;
+ }
+ }
+ dstRow += dstRowStride;
+ src += 4 * srcWidth;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+static GLboolean
+_mesa_texstore_rgb332(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGB332);
+ ASSERT(texelBytes == 1);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == GL_RGB &&
+ srcFormat == GL_RGB && srcType == GL_UNSIGNED_BYTE_3_3_2) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ for (col = 0; col < srcWidth; col++) {
+ dstRow[col] = PACK_COLOR_332( CHAN_TO_UBYTE(src[RCOMP]),
+ CHAN_TO_UBYTE(src[GCOMP]),
+ CHAN_TO_UBYTE(src[BCOMP]) );
+ src += 3;
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
+ */
+static GLboolean
+_mesa_texstore_a8(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_A8 ||
+ dstFormat == MESA_FORMAT_L8 ||
+ dstFormat == MESA_FORMAT_I8 ||
+ dstFormat == MESA_FORMAT_R8);
+ ASSERT(texelBytes == 1);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_UNSIGNED_BYTE) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ srcType == GL_UNSIGNED_BYTE &&
+ can_swizzle(baseInternalFormat) &&
+ can_swizzle(srcFormat)) {
+ GLubyte dstmap[4];
+
+ /* dstmap - how to swizzle from RGBA to dst format:
+ */
+ if (dstFormat == MESA_FORMAT_A8) {
+ dstmap[0] = 3;
+ }
+ else {
+ dstmap[0] = 0;
+ }
+ dstmap[1] = ZERO; /* ? */
+ dstmap[2] = ZERO; /* ? */
+ dstmap[3] = ONE; /* ? */
+
+ _mesa_swizzle_ubyte_image(ctx, dims,
+ srcFormat,
+ srcType,
+ baseInternalFormat,
+ dstmap, 1,
+ dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcAddr,
+ srcPacking);
+ }
+ else {
+ /* general path */
+ const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
+ const GLchan *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ for (col = 0; col < srcWidth; col++) {
+ dstRow[col] = CHAN_TO_UBYTE(src[col]);
+ }
+ dstRow += dstRowStride;
+ src += srcWidth;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+
+static GLboolean
+_mesa_texstore_ci8(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+
+ (void) dims; (void) baseInternalFormat;
+ ASSERT(dstFormat == MESA_FORMAT_CI8);
+ ASSERT(texelBytes == 1);
+ ASSERT(baseInternalFormat == GL_COLOR_INDEX);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ srcFormat == GL_COLOR_INDEX &&
+ srcType == GL_UNSIGNED_BYTE) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ GLint img, row;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ const GLvoid *src = _mesa_image_address(dims, srcPacking,
+ srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
+ _mesa_unpack_index_span(ctx, srcWidth, GL_UNSIGNED_BYTE, dstRow,
+ srcType, src, srcPacking,
+ ctx->_ImageTransferState);
+ dstRow += dstRowStride;
+ }
+ }
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
+ */
+static GLboolean
+_mesa_texstore_ycbcr(TEXSTORE_PARAMS)
+{
+ const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+
+ (void) ctx; (void) dims; (void) baseInternalFormat;
+
+ ASSERT((dstFormat == MESA_FORMAT_YCBCR) ||
+ (dstFormat == MESA_FORMAT_YCBCR_REV));
+ ASSERT(texelBytes == 2);
+ ASSERT(ctx->Extensions.MESA_ycbcr_texture);
+ ASSERT(srcFormat == GL_YCBCR_MESA);
+ ASSERT((srcType == GL_UNSIGNED_SHORT_8_8_MESA) ||
+ (srcType == GL_UNSIGNED_SHORT_8_8_REV_MESA));
+ ASSERT(baseInternalFormat == GL_YCBCR_MESA);
+
+ /* always just memcpy since no pixel transfer ops apply */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+
+ /* Check if we need byte swapping */
+ /* XXX the logic here _might_ be wrong */
+ if (srcPacking->SwapBytes ^
+ (srcType == GL_UNSIGNED_SHORT_8_8_REV_MESA) ^
+ (dstFormat == MESA_FORMAT_YCBCR_REV) ^
+ !littleEndian) {
+ GLint img, row;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ _mesa_swap2((GLushort *) dstRow, srcWidth);
+ dstRow += dstRowStride;
+ }
+ }
+ }
+ return GL_TRUE;
+}
+
+static GLboolean
+_mesa_texstore_dudv8(TEXSTORE_PARAMS)
+{
+ const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_DUDV8);
+ ASSERT(texelBytes == 2);
+ ASSERT(ctx->Extensions.ATI_envmap_bumpmap);
+ ASSERT((srcFormat == GL_DU8DV8_ATI) ||
+ (srcFormat == GL_DUDV_ATI));
+ ASSERT(baseInternalFormat == GL_DUDV_ATI);
+
+ if (!srcPacking->SwapBytes && srcType == GL_BYTE &&
+ littleEndian) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (srcType == GL_BYTE) {
+ GLubyte dstmap[4];
+
+ /* dstmap - how to swizzle from RGBA to dst format:
+ */
+ if (littleEndian) {
+ dstmap[0] = 0;
+ dstmap[1] = 3;
+ }
+ else {
+ dstmap[0] = 3;
+ dstmap[1] = 0;
+ }
+ dstmap[2] = ZERO; /* ? */
+ dstmap[3] = ONE; /* ? */
+
+ _mesa_swizzle_ubyte_image(ctx, dims,
+ GL_LUMINANCE_ALPHA, /* hack */
+ GL_UNSIGNED_BYTE, /* hack */
+ GL_LUMINANCE_ALPHA, /* hack */
+ dstmap, 2,
+ dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcAddr,
+ srcPacking);
+ }
+ else {
+ /* general path - note this is defined for 2d textures only */
+ const GLint components = _mesa_components_in_format(baseInternalFormat);
+ const GLint srcStride = _mesa_image_row_stride(srcPacking, srcWidth,
+ srcFormat, srcType);
+ GLbyte *tempImage, *dst, *src;
+ GLint row;
+
+ tempImage = (GLbyte *) malloc(srcWidth * srcHeight * srcDepth
+ * components * sizeof(GLbyte));
+ if (!tempImage)
+ return GL_FALSE;
+
+ src = (GLbyte *) _mesa_image_address(dims, srcPacking, srcAddr,
+ srcWidth, srcHeight,
+ srcFormat, srcType,
+ 0, 0, 0);
+
+ dst = tempImage;
+ for (row = 0; row < srcHeight; row++) {
+ _mesa_unpack_dudv_span_byte(ctx, srcWidth, baseInternalFormat,
+ dst, srcFormat, srcType, src,
+ srcPacking, 0);
+ dst += srcWidth * components;
+ src += srcStride;
+ }
+
+ src = tempImage;
+ dst = (GLbyte *) dstAddr
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ memcpy(dst, src, srcWidth * texelBytes);
+ dst += dstRowStride;
+ src += srcWidth * texelBytes;
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store a texture in MESA_FORMAT_SIGNED_R8 format.
+ */
+static GLboolean
+_mesa_texstore_signed_r8(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_SIGNED_R8);
+ ASSERT(texelBytes == 1);
+
+ /* XXX look at adding optimized paths */
+ {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *srcRow = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLubyte *dstB = (GLubyte *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ dstB[col] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]);
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
+ */
+static GLboolean
+_mesa_texstore_signed_rg88(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_SIGNED_RG88);
+ ASSERT(texelBytes == 1);
+
+ /* XXX look at adding optimized paths */
+ {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *srcRow = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLushort *dstUS = (GLushort *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ dstUS[col] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
+ FLOAT_TO_BYTE_TEX(srcRow[GCOMP]));
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
+ */
+static GLboolean
+_mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBX8888);
+ ASSERT(texelBytes == 4);
+
+ {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *srcRow = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstUI = (GLuint *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
+ FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
+ FLOAT_TO_BYTE_TEX(srcRow[BCOMP]),
+ 0xff );
+ srcRow += 4;
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+
+/**
+ * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
+ * MESA_FORMAT_SIGNED_RGBA8888_REV
+ */
+static GLboolean
+_mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
+{
+ const GLboolean littleEndian = _mesa_little_endian();
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBA8888 ||
+ dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV);
+ ASSERT(texelBytes == 4);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ dstFormat == MESA_FORMAT_SIGNED_RGBA8888 &&
+ baseInternalFormat == GL_RGBA &&
+ ((srcFormat == GL_RGBA && srcType == GL_BYTE && !littleEndian) ||
+ (srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && littleEndian))) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV &&
+ baseInternalFormat == GL_RGBA &&
+ ((srcFormat == GL_RGBA && srcType == GL_BYTE && littleEndian) ||
+ (srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && !littleEndian))) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (!ctx->_ImageTransferState &&
+ (srcType == GL_BYTE) &&
+ can_swizzle(baseInternalFormat) &&
+ can_swizzle(srcFormat)) {
+
+ GLubyte dstmap[4];
+
+ /* dstmap - how to swizzle from RGBA to dst format:
+ */
+ if ((littleEndian && dstFormat == MESA_FORMAT_SIGNED_RGBA8888) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV)) {
+ dstmap[3] = 0;
+ dstmap[2] = 1;
+ dstmap[1] = 2;
+ dstmap[0] = 3;
+ }
+ else {
+ dstmap[3] = 3;
+ dstmap[2] = 2;
+ dstmap[1] = 1;
+ dstmap[0] = 0;
+ }
+
+ _mesa_swizzle_ubyte_image(ctx, dims,
+ srcFormat,
+ srcType,
+ baseInternalFormat,
+ dstmap, 4,
+ dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcAddr,
+ srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *srcRow = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstUI = (GLuint *) dstRow;
+ if (dstFormat == MESA_FORMAT_SIGNED_RGBA8888) {
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
+ FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
+ FLOAT_TO_BYTE_TEX(srcRow[BCOMP]),
+ FLOAT_TO_BYTE_TEX(srcRow[ACOMP]) );
+ srcRow += 4;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
+ FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
+ FLOAT_TO_BYTE_TEX(srcRow[BCOMP]),
+ FLOAT_TO_BYTE_TEX(srcRow[ACOMP]) );
+ srcRow += 4;
+ }
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store a combined depth/stencil texture image.
+ */
+static GLboolean
+_mesa_texstore_z24_s8(TEXSTORE_PARAMS)
+{
+ const GLuint depthScale = 0xffffff;
+ const GLint srcRowStride
+ = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
+ / sizeof(GLuint);
+ GLint img, row;
+
+ ASSERT(dstFormat == MESA_FORMAT_Z24_S8);
+ ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT || srcFormat == GL_DEPTH_COMPONENT);
+ ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT || srcType == GL_UNSIGNED_INT_24_8_EXT);
+
+ if (srcFormat != GL_DEPTH_COMPONENT && ctx->Pixel.DepthScale == 1.0f &&
+ ctx->Pixel.DepthBias == 0.0f &&
+ !srcPacking->SwapBytes) {
+ /* simple path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else if (srcFormat == GL_DEPTH_COMPONENT) {
+ /* In case we only upload depth we need to preserve the stencil */
+ for (img = 0; img < srcDepth; img++) {
+ GLuint *dstRow = (GLuint *) dstAddr
+ + dstImageOffsets[dstZoffset + img]
+ + dstYoffset * dstRowStride / sizeof(GLuint)
+ + dstXoffset;
+ const GLuint *src
+ = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
+ srcWidth, srcHeight,
+ srcFormat, srcType,
+ img, 0, 0);
+ for (row = 0; row < srcHeight; row++) {
+ GLuint depth[MAX_WIDTH];
+ GLubyte stencil[MAX_WIDTH];
+ GLint i;
+ GLboolean keepdepth = GL_FALSE, keepstencil = GL_FALSE;
+
+ if (srcFormat == GL_DEPTH_COMPONENT) { /* preserve stencil */
+ keepstencil = GL_TRUE;
+ }
+ else if (srcFormat == GL_STENCIL_INDEX) { /* preserve depth */
+ keepdepth = GL_TRUE;
+ }
+
+ if (keepdepth == GL_FALSE)
+ /* the 24 depth bits will be in the low position: */
+ _mesa_unpack_depth_span(ctx, srcWidth,
+ GL_UNSIGNED_INT, /* dst type */
+ keepstencil ? depth : dstRow, /* dst addr */
+ depthScale,
+ srcType, src, srcPacking);
+
+ if (keepstencil == GL_FALSE)
+ /* get the 8-bit stencil values */
+ _mesa_unpack_stencil_span(ctx, srcWidth,
+ GL_UNSIGNED_BYTE, /* dst type */
+ stencil, /* dst addr */
+ srcType, src, srcPacking,
+ ctx->_ImageTransferState);
+
+ for (i = 0; i < srcWidth; i++) {
+ if (keepstencil)
+ dstRow[i] = depth[i] << 8 | (dstRow[i] & 0x000000FF);
+ else
+ dstRow[i] = (dstRow[i] & 0xFFFFFF00) | (stencil[i] & 0xFF);
+ }
+
+ src += srcRowStride;
+ dstRow += dstRowStride / sizeof(GLuint);
+ }
+ }
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store a combined depth/stencil texture image.
+ */
+static GLboolean
+_mesa_texstore_s8_z24(TEXSTORE_PARAMS)
+{
+ const GLuint depthScale = 0xffffff;
+ const GLint srcRowStride
+ = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
+ / sizeof(GLuint);
+ GLint img, row;
+
+ ASSERT(dstFormat == MESA_FORMAT_S8_Z24);
+ ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT ||
+ srcFormat == GL_DEPTH_COMPONENT ||
+ srcFormat == GL_STENCIL_INDEX);
+ ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT ||
+ srcType == GL_UNSIGNED_INT_24_8_EXT);
+
+ for (img = 0; img < srcDepth; img++) {
+ GLuint *dstRow = (GLuint *) dstAddr
+ + dstImageOffsets[dstZoffset + img]
+ + dstYoffset * dstRowStride / sizeof(GLuint)
+ + dstXoffset;
+ const GLuint *src
+ = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
+ srcWidth, srcHeight,
+ srcFormat, srcType,
+ img, 0, 0);
+ for (row = 0; row < srcHeight; row++) {
+ GLuint depth[MAX_WIDTH];
+ GLubyte stencil[MAX_WIDTH];
+ GLint i;
+ GLboolean keepdepth = GL_FALSE, keepstencil = GL_FALSE;
+
+ if (srcFormat == GL_DEPTH_COMPONENT) { /* preserve stencil */
+ keepstencil = GL_TRUE;
+ }
+ else if (srcFormat == GL_STENCIL_INDEX) { /* preserve depth */
+ keepdepth = GL_TRUE;
+ }
+
+ if (keepdepth == GL_FALSE)
+ /* the 24 depth bits will be in the low position: */
+ _mesa_unpack_depth_span(ctx, srcWidth,
+ GL_UNSIGNED_INT, /* dst type */
+ keepstencil ? depth : dstRow, /* dst addr */
+ depthScale,
+ srcType, src, srcPacking);
+
+ if (keepstencil == GL_FALSE)
+ /* get the 8-bit stencil values */
+ _mesa_unpack_stencil_span(ctx, srcWidth,
+ GL_UNSIGNED_BYTE, /* dst type */
+ stencil, /* dst addr */
+ srcType, src, srcPacking,
+ ctx->_ImageTransferState);
+
+ /* merge stencil values into depth values */
+ for (i = 0; i < srcWidth; i++) {
+ if (keepstencil)
+ dstRow[i] = depth[i] | (dstRow[i] & 0xFF000000);
+ else
+ dstRow[i] = (dstRow[i] & 0xFFFFFF) | (stencil[i] << 24);
+
+ }
+ src += srcRowStride;
+ dstRow += dstRowStride / sizeof(GLuint);
+ }
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store simple 8-bit/value stencil texture data.
+ */
+static GLboolean
+_mesa_texstore_s8(TEXSTORE_PARAMS)
+{
+ ASSERT(dstFormat == MESA_FORMAT_S8);
+ ASSERT(srcFormat == GL_STENCIL_INDEX);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_UNSIGNED_BYTE) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ const GLint srcRowStride
+ = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
+ / sizeof(GLuint);
+ GLint img, row;
+
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img]
+ + dstYoffset * dstRowStride / sizeof(GLuint)
+ + dstXoffset;
+ const GLuint *src
+ = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
+ srcWidth, srcHeight,
+ srcFormat, srcType,
+ img, 0, 0);
+ for (row = 0; row < srcHeight; row++) {
+ GLubyte stencil[MAX_WIDTH];
+ GLint i;
+
+ /* get the 8-bit stencil values */
+ _mesa_unpack_stencil_span(ctx, srcWidth,
+ GL_UNSIGNED_BYTE, /* dst type */
+ stencil, /* dst addr */
+ srcType, src, srcPacking,
+ ctx->_ImageTransferState);
+ /* merge stencil values into depth values */
+ for (i = 0; i < srcWidth; i++)
+ dstRow[i] = stencil[i];
+
+ src += srcRowStride;
+ dstRow += dstRowStride / sizeof(GLubyte);
+ }
+ }
+
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Store an image in any of the formats:
+ * _mesa_texformat_rgba_float32
+ * _mesa_texformat_rgb_float32
+ * _mesa_texformat_alpha_float32
+ * _mesa_texformat_luminance_float32
+ * _mesa_texformat_luminance_alpha_float32
+ * _mesa_texformat_intensity_float32
+ */
+static GLboolean
+_mesa_texstore_rgba_float32(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+ const GLint components = _mesa_components_in_format(baseFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_FLOAT32 ||
+ dstFormat == MESA_FORMAT_RGB_FLOAT32 ||
+ dstFormat == MESA_FORMAT_ALPHA_FLOAT32 ||
+ dstFormat == MESA_FORMAT_LUMINANCE_FLOAT32 ||
+ dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 ||
+ dstFormat == MESA_FORMAT_INTENSITY_FLOAT32);
+ ASSERT(baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_ALPHA ||
+ baseInternalFormat == GL_LUMINANCE ||
+ baseInternalFormat == GL_LUMINANCE_ALPHA ||
+ baseInternalFormat == GL_INTENSITY);
+ ASSERT(texelBytes == components * sizeof(GLfloat));
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_FLOAT) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *srcRow = tempImage;
+ GLint bytesPerRow;
+ GLint img, row;
+ if (!tempImage)
+ return GL_FALSE;
+ bytesPerRow = srcWidth * components * sizeof(GLfloat);
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ memcpy(dstRow, srcRow, bytesPerRow);
+ dstRow += dstRowStride;
+ srcRow += srcWidth * components;
+ }
+ }
+
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+
+/**
+ * As above, but store 16-bit floats.
+ */
+static GLboolean
+_mesa_texstore_rgba_float16(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+ const GLint components = _mesa_components_in_format(baseFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_FLOAT16 ||
+ dstFormat == MESA_FORMAT_RGB_FLOAT16 ||
+ dstFormat == MESA_FORMAT_ALPHA_FLOAT16 ||
+ dstFormat == MESA_FORMAT_LUMINANCE_FLOAT16 ||
+ dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 ||
+ dstFormat == MESA_FORMAT_INTENSITY_FLOAT16);
+ ASSERT(baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_ALPHA ||
+ baseInternalFormat == GL_LUMINANCE ||
+ baseInternalFormat == GL_LUMINANCE_ALPHA ||
+ baseInternalFormat == GL_INTENSITY);
+ ASSERT(texelBytes == components * sizeof(GLhalfARB));
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_HALF_FLOAT_ARB) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking,
+ ctx->_ImageTransferState);
+ const GLfloat *src = tempImage;
+ GLint img, row;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLhalfARB *dstTexel = (GLhalfARB *) dstRow;
+ GLint i;
+ for (i = 0; i < srcWidth * components; i++) {
+ dstTexel[i] = _mesa_float_to_half(src[i]);
+ }
+ dstRow += dstRowStride;
+ src += srcWidth * components;
+ }
+ }
+
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/* non-normalized, signed int8 */
+static GLboolean
+_mesa_texstore_rgba_int8(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+ const GLint components = _mesa_components_in_format(baseFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_INT8);
+ ASSERT(baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_ALPHA ||
+ baseInternalFormat == GL_LUMINANCE ||
+ baseInternalFormat == GL_LUMINANCE_ALPHA ||
+ baseInternalFormat == GL_INTENSITY);
+ ASSERT(texelBytes == components * sizeof(GLbyte));
+
+ /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
+ * to integer formats.
+ */
+ if (!srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_BYTE) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking, 0x0);
+ const GLfloat *src = tempImage;
+ GLint img, row;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLbyte *dstTexel = (GLbyte *) dstRow;
+ GLint i;
+ for (i = 0; i < srcWidth * components; i++) {
+ dstTexel[i] = (GLbyte) src[i];
+ }
+ dstRow += dstRowStride;
+ src += srcWidth * components;
+ }
+ }
+
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/* non-normalized, signed int16 */
+static GLboolean
+_mesa_texstore_rgba_int16(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+ const GLint components = _mesa_components_in_format(baseFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_INT16);
+ ASSERT(baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_ALPHA ||
+ baseInternalFormat == GL_LUMINANCE ||
+ baseInternalFormat == GL_LUMINANCE_ALPHA ||
+ baseInternalFormat == GL_INTENSITY);
+ ASSERT(texelBytes == components * sizeof(GLshort));
+
+ /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
+ * to integer formats.
+ */
+ if (!srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_SHORT) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking, 0x0);
+ const GLfloat *src = tempImage;
+ GLint img, row;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLshort *dstTexel = (GLshort *) dstRow;
+ GLint i;
+ for (i = 0; i < srcWidth * components; i++) {
+ dstTexel[i] = (GLint) src[i];
+ }
+ dstRow += dstRowStride;
+ src += srcWidth * components;
+ }
+ }
+
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/* non-normalized, signed int32 */
+static GLboolean
+_mesa_texstore_rgba_int32(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+ const GLint components = _mesa_components_in_format(baseFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_INT32);
+ ASSERT(baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_ALPHA ||
+ baseInternalFormat == GL_LUMINANCE ||
+ baseInternalFormat == GL_LUMINANCE_ALPHA ||
+ baseInternalFormat == GL_INTENSITY);
+ ASSERT(texelBytes == components * sizeof(GLint));
+
+ /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
+ * to integer formats.
+ */
+ if (!srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_INT) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking, 0x0);
+ const GLfloat *src = tempImage;
+ GLint img, row;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLint *dstTexel = (GLint *) dstRow;
+ GLint i;
+ for (i = 0; i < srcWidth * components; i++) {
+ dstTexel[i] = (GLint) src[i];
+ }
+ dstRow += dstRowStride;
+ src += srcWidth * components;
+ }
+ }
+
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/* non-normalized, unsigned int8 */
+static GLboolean
+_mesa_texstore_rgba_uint8(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+ const GLint components = _mesa_components_in_format(baseFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT8);
+ ASSERT(baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_ALPHA ||
+ baseInternalFormat == GL_LUMINANCE ||
+ baseInternalFormat == GL_LUMINANCE_ALPHA ||
+ baseInternalFormat == GL_INTENSITY);
+ ASSERT(texelBytes == components * sizeof(GLubyte));
+
+ /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
+ * to integer formats.
+ */
+ if (!srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_UNSIGNED_BYTE) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLuint *tempImage =
+ make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr, srcPacking);
+ const GLuint *src = tempImage;
+ GLint img, row;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLubyte *dstTexel = (GLubyte *) dstRow;
+ GLint i;
+ for (i = 0; i < srcWidth * components; i++) {
+ dstTexel[i] = (GLubyte) CLAMP(src[i], 0, 0xff);
+ }
+ dstRow += dstRowStride;
+ src += srcWidth * components;
+ }
+ }
+
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/* non-normalized, unsigned int16 */
+static GLboolean
+_mesa_texstore_rgba_uint16(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+ const GLint components = _mesa_components_in_format(baseFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT16);
+ ASSERT(baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_ALPHA ||
+ baseInternalFormat == GL_LUMINANCE ||
+ baseInternalFormat == GL_LUMINANCE_ALPHA ||
+ baseInternalFormat == GL_INTENSITY);
+ ASSERT(texelBytes == components * sizeof(GLushort));
+
+ /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
+ * to integer formats.
+ */
+ if (!srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_UNSIGNED_SHORT) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLuint *tempImage =
+ make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr, srcPacking);
+ const GLuint *src = tempImage;
+ GLint img, row;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLushort *dstTexel = (GLushort *) dstRow;
+ GLint i;
+ for (i = 0; i < srcWidth * components; i++) {
+ dstTexel[i] = (GLushort) CLAMP(src[i], 0, 0xffff);
+ }
+ dstRow += dstRowStride;
+ src += srcWidth * components;
+ }
+ }
+
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/* non-normalized, unsigned int32 */
+static GLboolean
+_mesa_texstore_rgba_uint32(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+ const GLint components = _mesa_components_in_format(baseFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT32);
+ ASSERT(baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_ALPHA ||
+ baseInternalFormat == GL_LUMINANCE ||
+ baseInternalFormat == GL_LUMINANCE_ALPHA ||
+ baseInternalFormat == GL_INTENSITY);
+ ASSERT(texelBytes == components * sizeof(GLuint));
+
+ /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
+ * to integer formats.
+ */
+ if (!srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_UNSIGNED_INT) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride,
+ dstImageOffsets,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLuint *tempImage =
+ make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr, srcPacking);
+ const GLuint *src = tempImage;
+ GLint img, row;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = (GLubyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstTexel = (GLuint *) dstRow;
+ GLint i;
+ for (i = 0; i < srcWidth * components; i++) {
+ dstTexel[i] = src[i];
+ }
+ dstRow += dstRowStride;
+ src += srcWidth * components;
+ }
+ }
+
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+
+
+#if FEATURE_EXT_texture_sRGB
+static GLboolean
+_mesa_texstore_srgb8(TEXSTORE_PARAMS)
+{
+ gl_format newDstFormat;
+ GLboolean k;
+
+ ASSERT(dstFormat == MESA_FORMAT_SRGB8);
+
+ /* reuse normal rgb texstore code */
+ newDstFormat = MESA_FORMAT_RGB888;
+
+ k = _mesa_texstore_rgb888(ctx, dims, baseInternalFormat,
+ newDstFormat, dstAddr,
+ dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType,
+ srcAddr, srcPacking);
+ return k;
+}
+
+
+static GLboolean
+_mesa_texstore_srgba8(TEXSTORE_PARAMS)
+{
+ gl_format newDstFormat;
+ GLboolean k;
+
+ ASSERT(dstFormat == MESA_FORMAT_SRGBA8);
+
+ /* reuse normal rgba texstore code */
+ newDstFormat = MESA_FORMAT_RGBA8888;
+ k = _mesa_texstore_rgba8888(ctx, dims, baseInternalFormat,
+ newDstFormat, dstAddr,
+ dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType,
+ srcAddr, srcPacking);
+ return k;
+}
+
+
+static GLboolean
+_mesa_texstore_sargb8(TEXSTORE_PARAMS)
+{
+ gl_format newDstFormat;
+ GLboolean k;
+
+ ASSERT(dstFormat == MESA_FORMAT_SARGB8);
+
+ /* reuse normal rgba texstore code */
+ newDstFormat = MESA_FORMAT_ARGB8888;
+
+ k = _mesa_texstore_argb8888(ctx, dims, baseInternalFormat,
+ newDstFormat, dstAddr,
+ dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType,
+ srcAddr, srcPacking);
+ return k;
+}
+
+
+static GLboolean
+_mesa_texstore_sl8(TEXSTORE_PARAMS)
+{
+ gl_format newDstFormat;
+ GLboolean k;
+
+ ASSERT(dstFormat == MESA_FORMAT_SL8);
+
+ newDstFormat = MESA_FORMAT_L8;
+
+ /* _mesa_textore_a8 handles luminance8 too */
+ k = _mesa_texstore_a8(ctx, dims, baseInternalFormat,
+ newDstFormat, dstAddr,
+ dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType,
+ srcAddr, srcPacking);
+ return k;
+}
+
+
+static GLboolean
+_mesa_texstore_sla8(TEXSTORE_PARAMS)
+{
+ gl_format newDstFormat;
+ GLboolean k;
+
+ ASSERT(dstFormat == MESA_FORMAT_SLA8);
+
+ /* reuse normal luminance/alpha texstore code */
+ newDstFormat = MESA_FORMAT_AL88;
+
+ k = _mesa_texstore_unorm88(ctx, dims, baseInternalFormat,
+ newDstFormat, dstAddr,
+ dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType,
+ srcAddr, srcPacking);
+ return k;
+}
+
+#else
+
+/* these are used only in texstore_funcs[] below */
+#define _mesa_texstore_srgb8 NULL
+#define _mesa_texstore_srgba8 NULL
+#define _mesa_texstore_sargb8 NULL
+#define _mesa_texstore_sl8 NULL
+#define _mesa_texstore_sla8 NULL
+
+#endif /* FEATURE_EXT_texture_sRGB */
+
+
+
+
+/**
+ * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
+ * XXX this is somewhat temporary.
+ */
+static const struct {
+ gl_format Name;
+ StoreTexImageFunc Store;
+}
+texstore_funcs[MESA_FORMAT_COUNT] =
+{
+ { MESA_FORMAT_NONE, NULL },
+ { MESA_FORMAT_RGBA8888, _mesa_texstore_rgba8888 },
+ { MESA_FORMAT_RGBA8888_REV, _mesa_texstore_rgba8888 },
+ { MESA_FORMAT_ARGB8888, _mesa_texstore_argb8888 },
+ { MESA_FORMAT_ARGB8888_REV, _mesa_texstore_argb8888 },
+ { MESA_FORMAT_XRGB8888, _mesa_texstore_argb8888 },
+ { MESA_FORMAT_XRGB8888_REV, _mesa_texstore_argb8888 },
+ { MESA_FORMAT_RGB888, _mesa_texstore_rgb888 },
+ { MESA_FORMAT_BGR888, _mesa_texstore_bgr888 },
+ { MESA_FORMAT_RGB565, _mesa_texstore_rgb565 },
+ { MESA_FORMAT_RGB565_REV, _mesa_texstore_rgb565 },
+ { MESA_FORMAT_ARGB4444, _mesa_texstore_argb4444 },
+ { MESA_FORMAT_ARGB4444_REV, _mesa_texstore_argb4444 },
+ { MESA_FORMAT_RGBA5551, _mesa_texstore_rgba5551 },
+ { MESA_FORMAT_ARGB1555, _mesa_texstore_argb1555 },
+ { MESA_FORMAT_ARGB1555_REV, _mesa_texstore_argb1555 },
+ { MESA_FORMAT_AL44, _mesa_texstore_unorm44 },
+ { MESA_FORMAT_AL88, _mesa_texstore_unorm88 },
+ { MESA_FORMAT_AL88_REV, _mesa_texstore_unorm88 },
+ { MESA_FORMAT_AL1616, _mesa_texstore_unorm1616 },
+ { MESA_FORMAT_AL1616_REV, _mesa_texstore_unorm1616 },
+ { MESA_FORMAT_RGB332, _mesa_texstore_rgb332 },
+ { MESA_FORMAT_A8, _mesa_texstore_a8 },
+ { MESA_FORMAT_A16, _mesa_texstore_unorm16 },
+ { MESA_FORMAT_L8, _mesa_texstore_a8 },
+ { MESA_FORMAT_L16, _mesa_texstore_unorm16 },
+ { MESA_FORMAT_I8, _mesa_texstore_a8 },
+ { MESA_FORMAT_I16, _mesa_texstore_unorm16 },
+ { MESA_FORMAT_CI8, _mesa_texstore_ci8 },
+ { MESA_FORMAT_YCBCR, _mesa_texstore_ycbcr },
+ { MESA_FORMAT_YCBCR_REV, _mesa_texstore_ycbcr },
+ { MESA_FORMAT_R8, _mesa_texstore_a8 },
+ { MESA_FORMAT_RG88, _mesa_texstore_unorm88 },
+ { MESA_FORMAT_RG88_REV, _mesa_texstore_unorm88 },
+ { MESA_FORMAT_R16, _mesa_texstore_unorm16 },
+ { MESA_FORMAT_RG1616, _mesa_texstore_unorm1616 },
+ { MESA_FORMAT_RG1616_REV, _mesa_texstore_unorm1616 },
+ { MESA_FORMAT_ARGB2101010, _mesa_texstore_argb2101010 },
+ { MESA_FORMAT_Z24_S8, _mesa_texstore_z24_s8 },
+ { MESA_FORMAT_S8_Z24, _mesa_texstore_s8_z24 },
+ { MESA_FORMAT_Z16, _mesa_texstore_z16 },
+ { MESA_FORMAT_X8_Z24, _mesa_texstore_x8_z24 },
+ { MESA_FORMAT_Z24_X8, _mesa_texstore_z24_x8 },
+ { MESA_FORMAT_Z32, _mesa_texstore_z32 },
+ { MESA_FORMAT_S8, _mesa_texstore_s8 },
+ { MESA_FORMAT_SRGB8, _mesa_texstore_srgb8 },
+ { MESA_FORMAT_SRGBA8, _mesa_texstore_srgba8 },
+ { MESA_FORMAT_SARGB8, _mesa_texstore_sargb8 },
+ { MESA_FORMAT_SL8, _mesa_texstore_sl8 },
+ { MESA_FORMAT_SLA8, _mesa_texstore_sla8 },
+ { MESA_FORMAT_SRGB_DXT1, _mesa_texstore_rgb_dxt1 },
+ { MESA_FORMAT_SRGBA_DXT1, _mesa_texstore_rgba_dxt1 },
+ { MESA_FORMAT_SRGBA_DXT3, _mesa_texstore_rgba_dxt3 },
+ { MESA_FORMAT_SRGBA_DXT5, _mesa_texstore_rgba_dxt5 },
+ { MESA_FORMAT_RGB_FXT1, _mesa_texstore_rgb_fxt1 },
+ { MESA_FORMAT_RGBA_FXT1, _mesa_texstore_rgba_fxt1 },
+ { MESA_FORMAT_RGB_DXT1, _mesa_texstore_rgb_dxt1 },
+ { MESA_FORMAT_RGBA_DXT1, _mesa_texstore_rgba_dxt1 },
+ { MESA_FORMAT_RGBA_DXT3, _mesa_texstore_rgba_dxt3 },
+ { MESA_FORMAT_RGBA_DXT5, _mesa_texstore_rgba_dxt5 },
+ { MESA_FORMAT_RGBA_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_RGBA_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_RGB_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_RGB_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_LUMINANCE_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_LUMINANCE_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_INTENSITY_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_INTENSITY_FLOAT16, _mesa_texstore_rgba_float16 },
+
+ { MESA_FORMAT_RGBA_INT8, _mesa_texstore_rgba_int8 },
+ { MESA_FORMAT_RGBA_INT16, _mesa_texstore_rgba_int16 },
+ { MESA_FORMAT_RGBA_INT32, _mesa_texstore_rgba_int32 },
+ { MESA_FORMAT_RGBA_UINT8, _mesa_texstore_rgba_uint8 },
+ { MESA_FORMAT_RGBA_UINT16, _mesa_texstore_rgba_uint16 },
+ { MESA_FORMAT_RGBA_UINT32, _mesa_texstore_rgba_uint32 },
+
+ { MESA_FORMAT_DUDV8, _mesa_texstore_dudv8 },
+
+ { MESA_FORMAT_SIGNED_R8, _mesa_texstore_signed_r8 },
+ { MESA_FORMAT_SIGNED_RG88, _mesa_texstore_signed_rg88 },
+ { MESA_FORMAT_SIGNED_RGBX8888, _mesa_texstore_signed_rgbx8888 },
+
+ { MESA_FORMAT_SIGNED_RGBA8888, _mesa_texstore_signed_rgba8888 },
+ { MESA_FORMAT_SIGNED_RGBA8888_REV, _mesa_texstore_signed_rgba8888 },
+
+ { MESA_FORMAT_SIGNED_R_16, _mesa_texstore_signed_rgba_16 },
+ { MESA_FORMAT_SIGNED_RG_16, _mesa_texstore_signed_rgba_16 },
+ { MESA_FORMAT_SIGNED_RGB_16, _mesa_texstore_signed_rgba_16 },
+ { MESA_FORMAT_SIGNED_RGBA_16, _mesa_texstore_signed_rgba_16 },
+ { MESA_FORMAT_RGBA_16, _mesa_texstore_rgba_16 },
+
+ { MESA_FORMAT_RED_RGTC1, _mesa_texstore_red_rgtc1 },
+ { MESA_FORMAT_SIGNED_RED_RGTC1, _mesa_texstore_signed_red_rgtc1 },
+ { MESA_FORMAT_RG_RGTC2, _mesa_texstore_rg_rgtc2 },
+ { MESA_FORMAT_SIGNED_RG_RGTC2, _mesa_texstore_signed_rg_rgtc2 }
+};
+
+
+static GLboolean
+_mesa_texstore_null(TEXSTORE_PARAMS)
+{
+ (void) ctx; (void) dims;
+ (void) baseInternalFormat;
+ (void) dstFormat;
+ (void) dstAddr;
+ (void) dstXoffset; (void) dstYoffset; (void) dstZoffset;
+ (void) dstRowStride; (void) dstImageOffsets;
+ (void) srcWidth; (void) srcHeight; (void) srcDepth;
+ (void) srcFormat; (void) srcType;
+ (void) srcAddr;
+ (void) srcPacking;
+
+ /* should never happen */
+ _mesa_problem(NULL, "_mesa_texstore_null() is called");
+ return GL_FALSE;
+}
+
+
+/**
+ * Return the StoreTexImageFunc pointer to store an image in the given format.
+ */
+static StoreTexImageFunc
+_mesa_get_texstore_func(gl_format format)
+{
+#ifdef DEBUG
+ GLuint i;
+ for (i = 0; i < MESA_FORMAT_COUNT; i++) {
+ ASSERT(texstore_funcs[i].Name == i);
+ }
+#endif
+ ASSERT(texstore_funcs[format].Name == format);
+
+ if (texstore_funcs[format].Store)
+ return texstore_funcs[format].Store;
+ else
+ return _mesa_texstore_null;
+}
+
+
+/**
+ * Store user data into texture memory.
+ * Called via glTex[Sub]Image1/2/3D()
+ */
+GLboolean
+_mesa_texstore(TEXSTORE_PARAMS)
+{
+ StoreTexImageFunc storeImage;
+ GLboolean success;
+
+ storeImage = _mesa_get_texstore_func(dstFormat);
+
+ success = storeImage(ctx, dims, baseInternalFormat,
+ dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr, srcPacking);
+ return success;
+}
+
+
+/** Return texture size in bytes */
+static GLuint
+texture_size(const struct gl_texture_image *texImage)
+{
+ GLuint sz = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
+ texImage->Height, texImage->Depth);
+ return sz;
+}
+
+
+/** Return row stride in bytes */
+static GLuint
+texture_row_stride(const struct gl_texture_image *texImage)
+{
+ GLuint stride = _mesa_format_row_stride(texImage->TexFormat,
+ texImage->Width);
+ return stride;
+}
+
+
+
+/**
+ * This is the software fallback for Driver.TexImage1D()
+ * and Driver.CopyTexImage1D().
+ * \sa _mesa_store_teximage2d()
+ */
+void
+_mesa_store_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint border,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ GLuint sizeInBytes;
+ (void) border;
+
+ /* allocate memory */
+ sizeInBytes = texture_size(texImage);
+ texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
+ if (!texImage->Data) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
+ return;
+ }
+
+ pixels = _mesa_validate_pbo_teximage(ctx, 1, width, 1, 1, format, type,
+ pixels, packing, "glTexImage1D");
+ if (!pixels) {
+ /* Note: we check for a NULL image pointer here, _after_ we allocated
+ * memory for the texture. That's what the GL spec calls for.
+ */
+ return;
+ }
+ else {
+ const GLint dstRowStride = 0;
+ GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ 0, 0, 0, /* dstX/Y/Zoffset */
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, 1, 1,
+ format, type, pixels, packing);
+ if (!success) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
+ }
+ }
+
+ _mesa_unmap_teximage_pbo(ctx, packing);
+}
+
+
+/**
+ * This is the software fallback for Driver.TexImage2D()
+ * and Driver.CopyTexImage2D().
+ *
+ * This function is oriented toward storing images in main memory, rather
+ * than VRAM. Device driver's can easily plug in their own replacement.
+ */
+void
+_mesa_store_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint border,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ GLuint sizeInBytes;
+ (void) border;
+
+ /* allocate memory */
+ sizeInBytes = texture_size(texImage);
+ texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
+ if (!texImage->Data) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
+ return;
+ }
+
+ pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
+ pixels, packing, "glTexImage2D");
+ if (!pixels) {
+ /* Note: we check for a NULL image pointer here, _after_ we allocated
+ * memory for the texture. That's what the GL spec calls for.
+ */
+ return;
+ }
+ else {
+ GLint dstRowStride = texture_row_stride(texImage);
+ GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ 0, 0, 0, /* dstX/Y/Zoffset */
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, 1,
+ format, type, pixels, packing);
+ if (!success) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
+ }
+ }
+
+ _mesa_unmap_teximage_pbo(ctx, packing);
+}
+
+
+
+/**
+ * This is the software fallback for Driver.TexImage3D()
+ * and Driver.CopyTexImage3D().
+ * \sa _mesa_store_teximage2d()
+ */
+void
+_mesa_store_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint depth, GLint border,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ GLuint sizeInBytes;
+ (void) border;
+
+ /* allocate memory */
+ sizeInBytes = texture_size(texImage);
+ texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
+ if (!texImage->Data) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
+ return;
+ }
+
+ pixels = _mesa_validate_pbo_teximage(ctx, 3, width, height, depth, format,
+ type, pixels, packing, "glTexImage3D");
+ if (!pixels) {
+ /* Note: we check for a NULL image pointer here, _after_ we allocated
+ * memory for the texture. That's what the GL spec calls for.
+ */
+ return;
+ }
+ else {
+ GLint dstRowStride = texture_row_stride(texImage);
+ GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ 0, 0, 0, /* dstX/Y/Zoffset */
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, depth,
+ format, type, pixels, packing);
+ if (!success) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
+ }
+ }
+
+ _mesa_unmap_teximage_pbo(ctx, packing);
+}
+
+
+
+
+/*
+ * This is the software fallback for Driver.TexSubImage1D()
+ * and Driver.CopyTexSubImage1D().
+ */
+void
+_mesa_store_texsubimage1d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint width,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ /* get pointer to src pixels (may be in a pbo which we'll map here) */
+ pixels = _mesa_validate_pbo_teximage(ctx, 1, width, 1, 1, format, type,
+ pixels, packing, "glTexSubImage1D");
+ if (!pixels)
+ return;
+
+ {
+ const GLint dstRowStride = 0;
+ GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ xoffset, 0, 0, /* offsets */
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, 1, 1,
+ format, type, pixels, packing);
+ if (!success) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage1D");
+ }
+ }
+
+ _mesa_unmap_teximage_pbo(ctx, packing);
+}
+
+
+
+/**
+ * This is the software fallback for Driver.TexSubImage2D()
+ * and Driver.CopyTexSubImage2D().
+ */
+void
+_mesa_store_texsubimage2d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint width, GLint height,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ /* get pointer to src pixels (may be in a pbo which we'll map here) */
+ pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
+ pixels, packing, "glTexSubImage2D");
+ if (!pixels)
+ return;
+
+ {
+ GLint dstRowStride = texture_row_stride(texImage);
+ GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ xoffset, yoffset, 0,
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, 1,
+ format, type, pixels, packing);
+ if (!success) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D");
+ }
+ }
+
+ _mesa_unmap_teximage_pbo(ctx, packing);
+}
+
+
+/*
+ * This is the software fallback for Driver.TexSubImage3D().
+ * and Driver.CopyTexSubImage3D().
+ */
+void
+_mesa_store_texsubimage3d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint width, GLint height, GLint depth,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ /* get pointer to src pixels (may be in a pbo which we'll map here) */
+ pixels = _mesa_validate_pbo_teximage(ctx, 3, width, height, depth, format,
+ type, pixels, packing,
+ "glTexSubImage3D");
+ if (!pixels)
+ return;
+
+ {
+ GLint dstRowStride = texture_row_stride(texImage);
+ GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ xoffset, yoffset, zoffset,
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, depth,
+ format, type, pixels, packing);
+ if (!success) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage3D");
+ }
+ }
+
+ _mesa_unmap_teximage_pbo(ctx, packing);
+}
+
+
+/*
+ * Fallback for Driver.CompressedTexImage1D()
+ */
+void
+_mesa_store_compressed_teximage1d(struct gl_context *ctx,
+ GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint border,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ /* this space intentionally left blank */
+ (void) ctx;
+ (void) target; (void) level;
+ (void) internalFormat;
+ (void) width; (void) border;
+ (void) imageSize; (void) data;
+ (void) texObj;
+ (void) texImage;
+}
+
+
+
+/**
+ * Fallback for Driver.CompressedTexImage2D()
+ */
+void
+_mesa_store_compressed_teximage2d(struct gl_context *ctx,
+ GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint border,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ (void) width; (void) height; (void) border;
+
+ /* This is pretty simple, basically just do a memcpy without worrying
+ * about the usual image unpacking or image transfer operations.
+ */
+ ASSERT(texObj);
+ ASSERT(texImage);
+ ASSERT(texImage->Width > 0);
+ ASSERT(texImage->Height > 0);
+ ASSERT(texImage->Depth == 1);
+ ASSERT(texImage->Data == NULL); /* was freed in glCompressedTexImage2DARB */
+
+ /* allocate storage */
+ texImage->Data = _mesa_alloc_texmemory(imageSize);
+ if (!texImage->Data) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
+ return;
+ }
+
+ data = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, data,
+ &ctx->Unpack,
+ "glCompressedTexImage2D");
+ if (!data)
+ return;
+
+ /* copy the data */
+ memcpy(texImage->Data, data, imageSize);
+
+ _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
+}
+
+
+
+/*
+ * Fallback for Driver.CompressedTexImage3D()
+ */
+void
+_mesa_store_compressed_teximage3d(struct gl_context *ctx,
+ GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint depth,
+ GLint border,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ /* this space intentionally left blank */
+ (void) ctx;
+ (void) target; (void) level;
+ (void) internalFormat;
+ (void) width; (void) height; (void) depth;
+ (void) border;
+ (void) imageSize; (void) data;
+ (void) texObj;
+ (void) texImage;
+}
+
+
+
+/**
+ * Fallback for Driver.CompressedTexSubImage1D()
+ */
+void
+_mesa_store_compressed_texsubimage1d(struct gl_context *ctx, GLenum target,
+ GLint level,
+ GLint xoffset, GLsizei width,
+ GLenum format,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ /* there are no compressed 1D texture formats yet */
+ (void) ctx;
+ (void) target; (void) level;
+ (void) xoffset; (void) width;
+ (void) format;
+ (void) imageSize; (void) data;
+ (void) texObj;
+ (void) texImage;
+}
+
+
+/**
+ * Fallback for Driver.CompressedTexSubImage2D()
+ */
+void
+_mesa_store_compressed_texsubimage2d(struct gl_context *ctx, GLenum target,
+ GLint level,
+ GLint xoffset, GLint yoffset,
+ GLsizei width, GLsizei height,
+ GLenum format,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ GLint bytesPerRow, destRowStride, srcRowStride;
+ GLint i, rows;
+ GLubyte *dest;
+ const GLubyte *src;
+ const gl_format texFormat = texImage->TexFormat;
+ const GLint destWidth = texImage->Width;
+ GLuint bw, bh;
+
+ _mesa_get_format_block_size(texFormat, &bw, &bh);
+
+ (void) level;
+ (void) format;
+
+ /* these should have been caught sooner */
+ ASSERT((width % bw) == 0 || width == 2 || width == 1);
+ ASSERT((height % bh) == 0 || height == 2 || height == 1);
+ ASSERT((xoffset % bw) == 0);
+ ASSERT((yoffset % bh) == 0);
+
+ /* get pointer to src pixels (may be in a pbo which we'll map here) */
+ data = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, data,
+ &ctx->Unpack,
+ "glCompressedTexSubImage2D");
+ if (!data)
+ return;
+
+ srcRowStride = _mesa_format_row_stride(texFormat, width);
+ src = (const GLubyte *) data;
+
+ destRowStride = _mesa_format_row_stride(texFormat, destWidth);
+ dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
+ texFormat, destWidth,
+ (GLubyte *) texImage->Data);
+
+ bytesPerRow = srcRowStride; /* bytes per row of blocks */
+ rows = height / bh; /* rows in blocks */
+
+ /* copy rows of blocks */
+ for (i = 0; i < rows; i++) {
+ memcpy(dest, src, bytesPerRow);
+ dest += destRowStride;
+ src += srcRowStride;
+ }
+
+ _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
+}
+
+
+/**
+ * Fallback for Driver.CompressedTexSubImage3D()
+ */
+void
+_mesa_store_compressed_texsubimage3d(struct gl_context *ctx, GLenum target,
+ GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ /* there are no compressed 3D texture formats yet */
+ (void) ctx;
+ (void) target; (void) level;
+ (void) xoffset; (void) yoffset; (void) zoffset;
+ (void) width; (void) height; (void) depth;
+ (void) format;
+ (void) imageSize; (void) data;
+ (void) texObj;
+ (void) texImage;
+}
diff --git a/mesalib/src/mesa/main/texstore.h b/mesalib/src/mesa/main/texstore.h
index d56318709..1d0ce7d4a 100644
--- a/mesalib/src/mesa/main/texstore.h
+++ b/mesalib/src/mesa/main/texstore.h
@@ -1,209 +1,209 @@
-/*
- * Mesa 3-D graphics library
- * Version: 6.5.1
- *
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- * Copyright (c) 2008 VMware, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file texstore.h
- * Texture image storage routines.
- *
- * \author Brian Paul
- */
-
-
-#ifndef TEXSTORE_H
-#define TEXSTORE_H
-
-
-#include "mtypes.h"
-#include "formats.h"
-
-
-/**
- * This macro defines the (many) parameters to the texstore functions.
- * \param dims either 1 or 2 or 3
- * \param baseInternalFormat user-specified base internal format
- * \param dstFormat destination Mesa texture format
- * \param dstAddr destination image address
- * \param dstX/Y/Zoffset destination x/y/z offset (ala TexSubImage), in texels
- * \param dstRowStride destination image row stride, in bytes
- * \param dstImageOffsets offset of each 2D slice within 3D texture, in texels
- * \param srcWidth/Height/Depth source image size, in pixels
- * \param srcFormat incoming image format
- * \param srcType incoming image data type
- * \param srcAddr source image address
- * \param srcPacking source image packing parameters
- */
-#define TEXSTORE_PARAMS \
- struct gl_context *ctx, GLuint dims, \
- GLenum baseInternalFormat, \
- gl_format dstFormat, \
- GLvoid *dstAddr, \
- GLint dstXoffset, GLint dstYoffset, GLint dstZoffset, \
- GLint dstRowStride, const GLuint *dstImageOffsets, \
- GLint srcWidth, GLint srcHeight, GLint srcDepth, \
- GLenum srcFormat, GLenum srcType, \
- const GLvoid *srcAddr, \
- const struct gl_pixelstore_attrib *srcPacking
-
-
-extern GLboolean
-_mesa_texstore(TEXSTORE_PARAMS);
-
-
-extern GLchan *
-_mesa_make_temp_chan_image(struct gl_context *ctx, GLuint dims,
- GLenum logicalBaseFormat,
- GLenum textureBaseFormat,
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- GLenum srcFormat, GLenum srcType,
- const GLvoid *srcAddr,
- const struct gl_pixelstore_attrib *srcPacking);
-
-GLfloat *
-_mesa_make_temp_float_image(struct gl_context *ctx, GLuint dims,
- GLenum logicalBaseFormat,
- GLenum textureBaseFormat,
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- GLenum srcFormat, GLenum srcType,
- const GLvoid *srcAddr,
- const struct gl_pixelstore_attrib *srcPacking,
- GLbitfield transferOps);
-
-extern void
-_mesa_store_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint border,
- GLenum format, GLenum type, const GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-
-extern void
-_mesa_store_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint border,
- GLenum format, GLenum type, const GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-
-extern void
-_mesa_store_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint depth, GLint border,
- GLenum format, GLenum type, const GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-
-extern void
-_mesa_store_texsubimage1d(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint width,
- GLenum format, GLenum type, const GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-
-extern void
-_mesa_store_texsubimage2d(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLint width, GLint height,
- GLenum format, GLenum type, const GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-
-extern void
-_mesa_store_texsubimage3d(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint width, GLint height, GLint depth,
- GLenum format, GLenum type, const GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-
-extern void
-_mesa_store_compressed_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint border,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-extern void
-_mesa_store_compressed_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint border,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-extern void
-_mesa_store_compressed_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint depth,
- GLint border,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-
-extern void
-_mesa_store_compressed_texsubimage1d(struct gl_context *ctx, GLenum target,
- GLint level,
- GLint xoffset, GLsizei width,
- GLenum format,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-extern void
-_mesa_store_compressed_texsubimage2d(struct gl_context *ctx, GLenum target,
- GLint level,
- GLint xoffset, GLint yoffset,
- GLsizei width, GLsizei height,
- GLenum format,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-extern void
-_mesa_store_compressed_texsubimage3d(struct gl_context *ctx, GLenum target,
- GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
-
-
-#endif
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5.1
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file texstore.h
+ * Texture image storage routines.
+ *
+ * \author Brian Paul
+ */
+
+
+#ifndef TEXSTORE_H
+#define TEXSTORE_H
+
+
+#include "mtypes.h"
+#include "formats.h"
+
+
+/**
+ * This macro defines the (many) parameters to the texstore functions.
+ * \param dims either 1 or 2 or 3
+ * \param baseInternalFormat user-specified base internal format
+ * \param dstFormat destination Mesa texture format
+ * \param dstAddr destination image address
+ * \param dstX/Y/Zoffset destination x/y/z offset (ala TexSubImage), in texels
+ * \param dstRowStride destination image row stride, in bytes
+ * \param dstImageOffsets offset of each 2D slice within 3D texture, in texels
+ * \param srcWidth/Height/Depth source image size, in pixels
+ * \param srcFormat incoming image format
+ * \param srcType incoming image data type
+ * \param srcAddr source image address
+ * \param srcPacking source image packing parameters
+ */
+#define TEXSTORE_PARAMS \
+ struct gl_context *ctx, GLuint dims, \
+ GLenum baseInternalFormat, \
+ gl_format dstFormat, \
+ GLvoid *dstAddr, \
+ GLint dstXoffset, GLint dstYoffset, GLint dstZoffset, \
+ GLint dstRowStride, const GLuint *dstImageOffsets, \
+ GLint srcWidth, GLint srcHeight, GLint srcDepth, \
+ GLenum srcFormat, GLenum srcType, \
+ const GLvoid *srcAddr, \
+ const struct gl_pixelstore_attrib *srcPacking
+
+
+extern GLboolean
+_mesa_texstore(TEXSTORE_PARAMS);
+
+
+extern GLchan *
+_mesa_make_temp_chan_image(struct gl_context *ctx, GLuint dims,
+ GLenum logicalBaseFormat,
+ GLenum textureBaseFormat,
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ GLenum srcFormat, GLenum srcType,
+ const GLvoid *srcAddr,
+ const struct gl_pixelstore_attrib *srcPacking);
+
+GLfloat *
+_mesa_make_temp_float_image(struct gl_context *ctx, GLuint dims,
+ GLenum logicalBaseFormat,
+ GLenum textureBaseFormat,
+ GLint srcWidth, GLint srcHeight, GLint srcDepth,
+ GLenum srcFormat, GLenum srcType,
+ const GLvoid *srcAddr,
+ const struct gl_pixelstore_attrib *srcPacking,
+ GLbitfield transferOps);
+
+extern void
+_mesa_store_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint border,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+
+extern void
+_mesa_store_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint border,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+
+extern void
+_mesa_store_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint depth, GLint border,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+
+extern void
+_mesa_store_texsubimage1d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint width,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+
+extern void
+_mesa_store_texsubimage2d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint width, GLint height,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+
+extern void
+_mesa_store_texsubimage3d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint width, GLint height, GLint depth,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+
+extern void
+_mesa_store_compressed_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint border,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+extern void
+_mesa_store_compressed_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint border,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+extern void
+_mesa_store_compressed_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint depth,
+ GLint border,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+
+extern void
+_mesa_store_compressed_texsubimage1d(struct gl_context *ctx, GLenum target,
+ GLint level,
+ GLint xoffset, GLsizei width,
+ GLenum format,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+extern void
+_mesa_store_compressed_texsubimage2d(struct gl_context *ctx, GLenum target,
+ GLint level,
+ GLint xoffset, GLint yoffset,
+ GLsizei width, GLsizei height,
+ GLenum format,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+extern void
+_mesa_store_compressed_texsubimage3d(struct gl_context *ctx, GLenum target,
+ GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage);
+
+
+#endif
diff --git a/mesalib/src/mesa/program/dobison.bat b/mesalib/src/mesa/program/dobison.bat
new file mode 100644
index 000000000..33f27a235
--- /dev/null
+++ b/mesalib/src/mesa/program/dobison.bat
@@ -0,0 +1,13 @@
+@echo off
+setlocal
+
+cd "%~dp0"
+
+set M4=..\..\..\..\tools\mhmake\m4.exe
+
+set BISON_PKGDATADIR=../../../../tools/mhmake/src/bisondata
+
+..\..\..\..\tools\mhmake\bison.exe -v -d --output=program_parse.tab.c program_parse.y
+
+endlocal
+
diff --git a/mesalib/src/mesa/program/doflex.bat b/mesalib/src/mesa/program/doflex.bat
new file mode 100644
index 000000000..bd3ccb0e0
--- /dev/null
+++ b/mesalib/src/mesa/program/doflex.bat
@@ -0,0 +1,18 @@
+@echo off
+setlocal
+
+cd "%~dp0"
+
+set M4=..\..\..\..\tools\mhmake\m4.exe
+
+set path=..\..\..\..\tools\mhmake;%path%
+
+copy "..\..\..\..\tools\mhmake\flex++.exe" flex.exe
+
+
+flex.exe --never-interactive --outfile=lex.yy.c program_lexer.l
+
+del flex.exe
+
+endlocal
+
diff --git a/mesalib/src/mesa/program/sampler.cpp b/mesalib/src/mesa/program/sampler.cpp
index 1457d1199..b219d7016 100644
--- a/mesalib/src/mesa/program/sampler.cpp
+++ b/mesalib/src/mesa/program/sampler.cpp
@@ -1,137 +1,137 @@
-/*
- * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
- * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include "ir.h"
-#include "glsl_types.h"
-#include "ir_visitor.h"
-
-extern "C" {
-#include "main/compiler.h"
-#include "main/mtypes.h"
-#include "program/prog_parameter.h"
-}
-
-static void fail_link(struct gl_shader_program *prog, const char *fmt, ...) PRINTFLIKE(2, 3);
-
-static void fail_link(struct gl_shader_program *prog, const char *fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
- ralloc_vasprintf_append(&prog->InfoLog, fmt, args);
- va_end(args);
-
- prog->LinkStatus = GL_FALSE;
-}
-
-class get_sampler_name : public ir_hierarchical_visitor
-{
-public:
- get_sampler_name(ir_dereference *last,
- struct gl_shader_program *shader_program)
- {
- this->mem_ctx = ralloc_context(NULL);
- this->shader_program = shader_program;
- this->name = NULL;
- this->offset = 0;
- this->last = last;
- }
-
- ~get_sampler_name()
- {
- ralloc_free(this->mem_ctx);
- }
-
- virtual ir_visitor_status visit(ir_dereference_variable *ir)
- {
- this->name = ir->var->name;
- return visit_continue;
- }
-
- virtual ir_visitor_status visit_leave(ir_dereference_record *ir)
- {
- this->name = ralloc_asprintf(mem_ctx, "%s.%s", name, ir->field);
- return visit_continue;
- }
-
- virtual ir_visitor_status visit_leave(ir_dereference_array *ir)
- {
- ir_constant *index = ir->array_index->as_constant();
- int i;
-
- if (index) {
- i = index->value.i[0];
- } else {
- /* GLSL 1.10 and 1.20 allowed variable sampler array indices,
- * while GLSL 1.30 requires that the array indices be
- * constant integer expressions. We don't expect any driver
- * to actually work with a really variable array index, so
- * all that would work would be an unrolled loop counter that ends
- * up being constant above.
- */
- ralloc_strcat(&shader_program->InfoLog,
- "warning: Variable sampler array index unsupported.\n"
- "This feature of the language was removed in GLSL 1.20 "
- "and is unlikely to be supported for 1.10 in Mesa.\n");
- i = 0;
- }
- if (ir != last) {
- this->name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i);
- } else {
- offset = i;
- }
- return visit_continue;
- }
-
- struct gl_shader_program *shader_program;
- const char *name;
- void *mem_ctx;
- int offset;
- ir_dereference *last;
-};
-
-extern "C" {
-int
-_mesa_get_sampler_uniform_value(class ir_dereference *sampler,
- struct gl_shader_program *shader_program,
- const struct gl_program *prog)
-{
- get_sampler_name getname(sampler, shader_program);
-
- sampler->accept(&getname);
-
- GLint index = _mesa_lookup_parameter_index(prog->Parameters, -1,
- getname.name);
-
- if (index < 0) {
- fail_link(shader_program,
- "failed to find sampler named %s.\n", getname.name);
- return 0;
- }
-
- index += getname.offset;
-
- return prog->Parameters->ParameterValues[index][0];
-}
-}
+/*
+ * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
+ * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "ir.h"
+#include "glsl_types.h"
+#include "ir_visitor.h"
+
+extern "C" {
+#include "main/compiler.h"
+#include "main/mtypes.h"
+#include "program/prog_parameter.h"
+}
+
+static void fail_link(struct gl_shader_program *prog, const char *fmt, ...) PRINTFLIKE(2, 3);
+
+static void fail_link(struct gl_shader_program *prog, const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ ralloc_vasprintf_append(&prog->InfoLog, fmt, args);
+ va_end(args);
+
+ prog->LinkStatus = GL_FALSE;
+}
+
+class get_sampler_name : public ir_hierarchical_visitor
+{
+public:
+ get_sampler_name(ir_dereference *last,
+ struct gl_shader_program *shader_program)
+ {
+ this->mem_ctx = ralloc_context(NULL);
+ this->shader_program = shader_program;
+ this->name = NULL;
+ this->offset = 0;
+ this->last = last;
+ }
+
+ ~get_sampler_name()
+ {
+ ralloc_free(this->mem_ctx);
+ }
+
+ virtual ir_visitor_status visit(ir_dereference_variable *ir)
+ {
+ this->name = ir->var->name;
+ return visit_continue;
+ }
+
+ virtual ir_visitor_status visit_leave(ir_dereference_record *ir)
+ {
+ this->name = ralloc_asprintf(mem_ctx, "%s.%s", name, ir->field);
+ return visit_continue;
+ }
+
+ virtual ir_visitor_status visit_leave(ir_dereference_array *ir)
+ {
+ ir_constant *index = ir->array_index->as_constant();
+ int i;
+
+ if (index) {
+ i = index->value.i[0];
+ } else {
+ /* GLSL 1.10 and 1.20 allowed variable sampler array indices,
+ * while GLSL 1.30 requires that the array indices be
+ * constant integer expressions. We don't expect any driver
+ * to actually work with a really variable array index, so
+ * all that would work would be an unrolled loop counter that ends
+ * up being constant above.
+ */
+ ralloc_strcat(&shader_program->InfoLog,
+ "warning: Variable sampler array index unsupported.\n"
+ "This feature of the language was removed in GLSL 1.20 "
+ "and is unlikely to be supported for 1.10 in Mesa.\n");
+ i = 0;
+ }
+ if (ir != last) {
+ this->name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i);
+ } else {
+ offset = i;
+ }
+ return visit_continue;
+ }
+
+ struct gl_shader_program *shader_program;
+ const char *name;
+ void *mem_ctx;
+ int offset;
+ ir_dereference *last;
+};
+
+extern "C" {
+int
+_mesa_get_sampler_uniform_value(class ir_dereference *sampler,
+ struct gl_shader_program *shader_program,
+ const struct gl_program *prog)
+{
+ get_sampler_name getname(sampler, shader_program);
+
+ sampler->accept(&getname);
+
+ GLint index = _mesa_lookup_parameter_index(prog->Parameters, -1,
+ getname.name);
+
+ if (index < 0) {
+ fail_link(shader_program,
+ "failed to find sampler named %s.\n", getname.name);
+ return 0;
+ }
+
+ index += getname.offset;
+
+ return prog->Parameters->ParameterValues[index][0];
+}
+}
diff --git a/mesalib/src/mesa/sources.mak b/mesalib/src/mesa/sources.mak
index a8c0bbd2b..8cf629d16 100644
--- a/mesalib/src/mesa/sources.mak
+++ b/mesalib/src/mesa/sources.mak
@@ -1,370 +1,370 @@
-### Lists of source files, included by Makefiles
-
-# this is part of MAIN_SOURCES
-MAIN_ES_SOURCES = \
- main/api_exec_es1.c \
- main/api_exec_es2.c
-
-MAIN_SOURCES = \
- main/api_arrayelt.c \
- main/api_exec.c \
- main/api_loopback.c \
- main/api_noop.c \
- main/api_validate.c \
- main/accum.c \
- main/arbprogram.c \
- main/atifragshader.c \
- main/attrib.c \
- main/arrayobj.c \
- main/blend.c \
- main/bufferobj.c \
- main/buffers.c \
- main/clear.c \
- main/clip.c \
- main/colortab.c \
- main/condrender.c \
- main/context.c \
- main/convolve.c \
- main/cpuinfo.c \
- main/debug.c \
- main/depth.c \
- main/depthstencil.c \
- main/dlist.c \
- main/dlopen.c \
- main/drawpix.c \
- main/drawtex.c \
- main/enable.c \
- main/enums.c \
- main/eval.c \
- main/execmem.c \
- main/extensions.c \
- main/fbobject.c \
- main/feedback.c \
- main/ffvertex_prog.c \
- main/fog.c \
- main/formats.c \
- main/framebuffer.c \
- main/get.c \
- main/getstring.c \
- main/hash.c \
- main/hint.c \
- main/histogram.c \
- main/image.c \
- main/imports.c \
- main/light.c \
- main/lines.c \
- main/matrix.c \
- main/mipmap.c \
- main/mm.c \
- main/multisample.c \
- main/nvprogram.c \
- main/pack.c \
- main/pbo.c \
- main/pixel.c \
- main/pixelstore.c \
- main/pixeltransfer.c \
- main/points.c \
- main/polygon.c \
- main/queryobj.c \
- main/querymatrix.c \
- main/rastpos.c \
- main/readpix.c \
- main/remap.c \
- main/renderbuffer.c \
- main/scissor.c \
- main/shaderapi.c \
- main/shaderobj.c \
- main/shared.c \
- main/state.c \
- main/stencil.c \
- main/syncobj.c \
- main/texcompress.c \
- main/texcompress_rgtc.c \
- main/texcompress_s3tc.c \
- main/texcompress_fxt1.c \
- main/texenv.c \
- main/texenvprogram.c \
- main/texfetch.c \
- main/texformat.c \
- main/texgen.c \
- main/texgetimage.c \
- main/teximage.c \
- main/texobj.c \
- main/texpal.c \
- main/texparam.c \
- main/texrender.c \
- main/texstate.c \
- main/texstore.c \
- main/transformfeedback.c \
- main/uniforms.c \
- main/varray.c \
- main/version.c \
- main/viewport.c \
- main/vtxfmt.c \
- $(MAIN_ES_SOURCES)
-
-MATH_SOURCES = \
- math/m_debug_clip.c \
- math/m_debug_norm.c \
- math/m_debug_xform.c \
- math/m_eval.c \
- math/m_matrix.c \
- math/m_translate.c \
- math/m_vector.c
-
-MATH_XFORM_SOURCES = \
- math/m_xform.c
-
-SWRAST_SOURCES = \
- swrast/s_aaline.c \
- swrast/s_aatriangle.c \
- swrast/s_accum.c \
- swrast/s_alpha.c \
- swrast/s_atifragshader.c \
- swrast/s_bitmap.c \
- swrast/s_blend.c \
- swrast/s_blit.c \
- swrast/s_clear.c \
- swrast/s_copypix.c \
- swrast/s_context.c \
- swrast/s_depth.c \
- swrast/s_drawpix.c \
- swrast/s_feedback.c \
- swrast/s_fog.c \
- swrast/s_fragprog.c \
- swrast/s_lines.c \
- swrast/s_logic.c \
- swrast/s_masking.c \
- swrast/s_points.c \
- swrast/s_readpix.c \
- swrast/s_span.c \
- swrast/s_stencil.c \
- swrast/s_texcombine.c \
- swrast/s_texfilter.c \
- swrast/s_triangle.c \
- swrast/s_zoom.c
-
-SWRAST_SETUP_SOURCES = \
- swrast_setup/ss_context.c \
- swrast_setup/ss_triangle.c
-
-TNL_SOURCES = \
- tnl/t_context.c \
- tnl/t_pipeline.c \
- tnl/t_draw.c \
- tnl/t_rasterpos.c \
- tnl/t_vb_program.c \
- tnl/t_vb_render.c \
- tnl/t_vb_texgen.c \
- tnl/t_vb_texmat.c \
- tnl/t_vb_vertex.c \
- tnl/t_vb_fog.c \
- tnl/t_vb_light.c \
- tnl/t_vb_normals.c \
- tnl/t_vb_points.c \
- tnl/t_vp_build.c \
- tnl/t_vertex.c \
- tnl/t_vertex_sse.c \
- tnl/t_vertex_generic.c
-
-VBO_SOURCES = \
- vbo/vbo_context.c \
- vbo/vbo_exec.c \
- vbo/vbo_exec_api.c \
- vbo/vbo_exec_array.c \
- vbo/vbo_exec_draw.c \
- vbo/vbo_exec_eval.c \
- vbo/vbo_rebase.c \
- vbo/vbo_split.c \
- vbo/vbo_split_copy.c \
- vbo/vbo_split_inplace.c \
- vbo/vbo_save.c \
- vbo/vbo_save_api.c \
- vbo/vbo_save_draw.c \
- vbo/vbo_save_loopback.c
-
-STATETRACKER_SOURCES = \
- state_tracker/st_atom.c \
- state_tracker/st_atom_blend.c \
- state_tracker/st_atom_clip.c \
- state_tracker/st_atom_constbuf.c \
- state_tracker/st_atom_depth.c \
- state_tracker/st_atom_framebuffer.c \
- state_tracker/st_atom_msaa.c \
- state_tracker/st_atom_pixeltransfer.c \
- state_tracker/st_atom_sampler.c \
- state_tracker/st_atom_scissor.c \
- state_tracker/st_atom_shader.c \
- state_tracker/st_atom_rasterizer.c \
- state_tracker/st_atom_stipple.c \
- state_tracker/st_atom_texture.c \
- state_tracker/st_atom_viewport.c \
- state_tracker/st_cb_accum.c \
- state_tracker/st_cb_bitmap.c \
- state_tracker/st_cb_blit.c \
- state_tracker/st_cb_bufferobjects.c \
- state_tracker/st_cb_clear.c \
- state_tracker/st_cb_condrender.c \
- state_tracker/st_cb_flush.c \
- state_tracker/st_cb_drawpixels.c \
- state_tracker/st_cb_drawtex.c \
- state_tracker/st_cb_eglimage.c \
- state_tracker/st_cb_fbo.c \
- state_tracker/st_cb_feedback.c \
- state_tracker/st_cb_program.c \
- state_tracker/st_cb_queryobj.c \
- state_tracker/st_cb_rasterpos.c \
- state_tracker/st_cb_readpixels.c \
- state_tracker/st_cb_strings.c \
- state_tracker/st_cb_texture.c \
- state_tracker/st_cb_viewport.c \
- state_tracker/st_cb_xformfb.c \
- state_tracker/st_context.c \
- state_tracker/st_debug.c \
- state_tracker/st_draw.c \
- state_tracker/st_draw_feedback.c \
- state_tracker/st_extensions.c \
- state_tracker/st_format.c \
- state_tracker/st_gen_mipmap.c \
- state_tracker/st_manager.c \
- state_tracker/st_mesa_to_tgsi.c \
- state_tracker/st_program.c \
- state_tracker/st_texture.c
-
-PROGRAM_SOURCES = \
- program/arbprogparse.c \
- program/hash_table.c \
- program/lex.yy.c \
- program/nvfragparse.c \
- program/nvvertparse.c \
- program/program.c \
- program/program_parse.tab.c \
- program/program_parse_extra.c \
- program/prog_cache.c \
- program/prog_execute.c \
- program/prog_instruction.c \
- program/prog_noise.c \
- program/prog_optimize.c \
- program/prog_parameter.c \
- program/prog_parameter_layout.c \
- program/prog_print.c \
- program/prog_statevars.c \
- program/prog_uniform.c \
- program/programopt.c \
- program/register_allocate.c \
- program/symbol_table.c
-
-SHADER_CXX_SOURCES = \
- program/ir_to_mesa.cpp \
- program/sampler.cpp
-
-ASM_C_SOURCES = \
- x86/common_x86.c \
- x86/x86_xform.c \
- x86/3dnow.c \
- x86/sse.c \
- x86/rtasm/x86sse.c \
- sparc/sparc.c \
- ppc/common_ppc.c \
- x86-64/x86-64.c
-
-X86_SOURCES = \
- x86/common_x86_asm.S \
- x86/x86_xform2.S \
- x86/x86_xform3.S \
- x86/x86_xform4.S \
- x86/x86_cliptest.S \
- x86/mmx_blend.S \
- x86/3dnow_xform1.S \
- x86/3dnow_xform2.S \
- x86/3dnow_xform3.S \
- x86/3dnow_xform4.S \
- x86/3dnow_normal.S \
- x86/sse_xform1.S \
- x86/sse_xform2.S \
- x86/sse_xform3.S \
- x86/sse_xform4.S \
- x86/sse_normal.S \
- x86/read_rgba_span_x86.S
-
-X86-64_SOURCES = \
- x86-64/xform4.S
-
-SPARC_SOURCES = \
- sparc/clip.S \
- sparc/norm.S \
- sparc/xform.S
-
-COMMON_DRIVER_SOURCES = \
- drivers/common/driverfuncs.c \
- drivers/common/meta.c
-
-
-# Sources for building non-Gallium drivers
-MESA_SOURCES = \
- $(MAIN_SOURCES) \
- $(MATH_SOURCES) \
- $(MATH_XFORM_SOURCES) \
- $(VBO_SOURCES) \
- $(TNL_SOURCES) \
- $(PROGRAM_SOURCES) \
- $(SWRAST_SOURCES) \
- $(SWRAST_SETUP_SOURCES) \
- $(COMMON_DRIVER_SOURCES)\
- $(ASM_C_SOURCES)
-
-MESA_CXX_SOURCES = \
- $(SHADER_CXX_SOURCES)
-
-# Sources for building Gallium drivers
-MESA_GALLIUM_SOURCES = \
- $(MAIN_SOURCES) \
- $(MATH_SOURCES) \
- $(VBO_SOURCES) \
- $(STATETRACKER_SOURCES) \
- $(PROGRAM_SOURCES) \
- ppc/common_ppc.c \
- x86/common_x86.c
-
-MESA_GALLIUM_CXX_SOURCES = \
- $(SHADER_CXX_SOURCES)
-
-# All the core C sources, for dependency checking
-ALL_SOURCES = \
- $(MESA_SOURCES) \
- $(MESA_CXX_SOURCES) \
- $(MESA_ASM_SOURCES) \
- $(STATETRACKER_SOURCES)
-
-
-### Object files
-
-MESA_OBJECTS = \
- $(MESA_SOURCES:.c=.o) \
- $(MESA_CXX_SOURCES:.cpp=.o) \
- $(MESA_ASM_SOURCES:.S=.o)
-
-MESA_GALLIUM_OBJECTS = \
- $(MESA_GALLIUM_SOURCES:.c=.o) \
- $(MESA_GALLIUM_CXX_SOURCES:.cpp=.o) \
- $(MESA_ASM_SOURCES:.S=.o)
-
-
-COMMON_DRIVER_OBJECTS = $(COMMON_DRIVER_SOURCES:.c=.o)
-
-
-### Other archives/libraries
-
-GLSL_LIBS = \
- $(TOP)/src/glsl/libglsl.a
-
-
-### Include directories
-
-INCLUDE_DIRS = \
- -I$(TOP)/include \
- -I$(TOP)/src/glsl \
- -I$(TOP)/src/mesa \
- -I$(TOP)/src/mapi \
- -I$(TOP)/src/gallium/include \
- -I$(TOP)/src/gallium/auxiliary
+### Lists of source files, included by Makefiles
+
+# this is part of MAIN_SOURCES
+MAIN_ES_SOURCES = \
+ main/api_exec_es1.c \
+ main/api_exec_es2.c
+
+MAIN_SOURCES = \
+ main/api_arrayelt.c \
+ main/api_exec.c \
+ main/api_loopback.c \
+ main/api_noop.c \
+ main/api_validate.c \
+ main/accum.c \
+ main/arbprogram.c \
+ main/atifragshader.c \
+ main/attrib.c \
+ main/arrayobj.c \
+ main/blend.c \
+ main/bufferobj.c \
+ main/buffers.c \
+ main/clear.c \
+ main/clip.c \
+ main/colortab.c \
+ main/condrender.c \
+ main/context.c \
+ main/convolve.c \
+ main/cpuinfo.c \
+ main/debug.c \
+ main/depth.c \
+ main/depthstencil.c \
+ main/dlist.c \
+ main/dlopen.c \
+ main/drawpix.c \
+ main/drawtex.c \
+ main/enable.c \
+ main/enums.c \
+ main/eval.c \
+ main/execmem.c \
+ main/extensions.c \
+ main/fbobject.c \
+ main/feedback.c \
+ main/ffvertex_prog.c \
+ main/fog.c \
+ main/formats.c \
+ main/framebuffer.c \
+ main/get.c \
+ main/getstring.c \
+ main/hash.c \
+ main/hint.c \
+ main/histogram.c \
+ main/image.c \
+ main/imports.c \
+ main/light.c \
+ main/lines.c \
+ main/matrix.c \
+ main/mipmap.c \
+ main/mm.c \
+ main/multisample.c \
+ main/nvprogram.c \
+ main/pack.c \
+ main/pbo.c \
+ main/pixel.c \
+ main/pixelstore.c \
+ main/pixeltransfer.c \
+ main/points.c \
+ main/polygon.c \
+ main/queryobj.c \
+ main/querymatrix.c \
+ main/rastpos.c \
+ main/readpix.c \
+ main/remap.c \
+ main/renderbuffer.c \
+ main/scissor.c \
+ main/shaderapi.c \
+ main/shaderobj.c \
+ main/shared.c \
+ main/state.c \
+ main/stencil.c \
+ main/syncobj.c \
+ main/texcompress.c \
+ main/texcompress_rgtc.c \
+ main/texcompress_s3tc.c \
+ main/texcompress_fxt1.c \
+ main/texenv.c \
+ main/texenvprogram.c \
+ main/texfetch.c \
+ main/texformat.c \
+ main/texgen.c \
+ main/texgetimage.c \
+ main/teximage.c \
+ main/texobj.c \
+ main/texpal.c \
+ main/texparam.c \
+ main/texrender.c \
+ main/texstate.c \
+ main/texstore.c \
+ main/transformfeedback.c \
+ main/uniforms.c \
+ main/varray.c \
+ main/version.c \
+ main/viewport.c \
+ main/vtxfmt.c \
+ $(MAIN_ES_SOURCES)
+
+MATH_SOURCES = \
+ math/m_debug_clip.c \
+ math/m_debug_norm.c \
+ math/m_debug_xform.c \
+ math/m_eval.c \
+ math/m_matrix.c \
+ math/m_translate.c \
+ math/m_vector.c
+
+MATH_XFORM_SOURCES = \
+ math/m_xform.c
+
+SWRAST_SOURCES = \
+ swrast/s_aaline.c \
+ swrast/s_aatriangle.c \
+ swrast/s_accum.c \
+ swrast/s_alpha.c \
+ swrast/s_atifragshader.c \
+ swrast/s_bitmap.c \
+ swrast/s_blend.c \
+ swrast/s_blit.c \
+ swrast/s_clear.c \
+ swrast/s_copypix.c \
+ swrast/s_context.c \
+ swrast/s_depth.c \
+ swrast/s_drawpix.c \
+ swrast/s_feedback.c \
+ swrast/s_fog.c \
+ swrast/s_fragprog.c \
+ swrast/s_lines.c \
+ swrast/s_logic.c \
+ swrast/s_masking.c \
+ swrast/s_points.c \
+ swrast/s_readpix.c \
+ swrast/s_span.c \
+ swrast/s_stencil.c \
+ swrast/s_texcombine.c \
+ swrast/s_texfilter.c \
+ swrast/s_triangle.c \
+ swrast/s_zoom.c
+
+SWRAST_SETUP_SOURCES = \
+ swrast_setup/ss_context.c \
+ swrast_setup/ss_triangle.c
+
+TNL_SOURCES = \
+ tnl/t_context.c \
+ tnl/t_pipeline.c \
+ tnl/t_draw.c \
+ tnl/t_rasterpos.c \
+ tnl/t_vb_program.c \
+ tnl/t_vb_render.c \
+ tnl/t_vb_texgen.c \
+ tnl/t_vb_texmat.c \
+ tnl/t_vb_vertex.c \
+ tnl/t_vb_fog.c \
+ tnl/t_vb_light.c \
+ tnl/t_vb_normals.c \
+ tnl/t_vb_points.c \
+ tnl/t_vp_build.c \
+ tnl/t_vertex.c \
+ tnl/t_vertex_sse.c \
+ tnl/t_vertex_generic.c
+
+VBO_SOURCES = \
+ vbo/vbo_context.c \
+ vbo/vbo_exec.c \
+ vbo/vbo_exec_api.c \
+ vbo/vbo_exec_array.c \
+ vbo/vbo_exec_draw.c \
+ vbo/vbo_exec_eval.c \
+ vbo/vbo_rebase.c \
+ vbo/vbo_split.c \
+ vbo/vbo_split_copy.c \
+ vbo/vbo_split_inplace.c \
+ vbo/vbo_save.c \
+ vbo/vbo_save_api.c \
+ vbo/vbo_save_draw.c \
+ vbo/vbo_save_loopback.c
+
+STATETRACKER_SOURCES = \
+ state_tracker/st_atom.c \
+ state_tracker/st_atom_blend.c \
+ state_tracker/st_atom_clip.c \
+ state_tracker/st_atom_constbuf.c \
+ state_tracker/st_atom_depth.c \
+ state_tracker/st_atom_framebuffer.c \
+ state_tracker/st_atom_msaa.c \
+ state_tracker/st_atom_pixeltransfer.c \
+ state_tracker/st_atom_sampler.c \
+ state_tracker/st_atom_scissor.c \
+ state_tracker/st_atom_shader.c \
+ state_tracker/st_atom_rasterizer.c \
+ state_tracker/st_atom_stipple.c \
+ state_tracker/st_atom_texture.c \
+ state_tracker/st_atom_viewport.c \
+ state_tracker/st_cb_accum.c \
+ state_tracker/st_cb_bitmap.c \
+ state_tracker/st_cb_blit.c \
+ state_tracker/st_cb_bufferobjects.c \
+ state_tracker/st_cb_clear.c \
+ state_tracker/st_cb_condrender.c \
+ state_tracker/st_cb_flush.c \
+ state_tracker/st_cb_drawpixels.c \
+ state_tracker/st_cb_drawtex.c \
+ state_tracker/st_cb_eglimage.c \
+ state_tracker/st_cb_fbo.c \
+ state_tracker/st_cb_feedback.c \
+ state_tracker/st_cb_program.c \
+ state_tracker/st_cb_queryobj.c \
+ state_tracker/st_cb_rasterpos.c \
+ state_tracker/st_cb_readpixels.c \
+ state_tracker/st_cb_strings.c \
+ state_tracker/st_cb_texture.c \
+ state_tracker/st_cb_viewport.c \
+ state_tracker/st_cb_xformfb.c \
+ state_tracker/st_context.c \
+ state_tracker/st_debug.c \
+ state_tracker/st_draw.c \
+ state_tracker/st_draw_feedback.c \
+ state_tracker/st_extensions.c \
+ state_tracker/st_format.c \
+ state_tracker/st_gen_mipmap.c \
+ state_tracker/st_manager.c \
+ state_tracker/st_mesa_to_tgsi.c \
+ state_tracker/st_program.c \
+ state_tracker/st_texture.c
+
+PROGRAM_SOURCES = \
+ program/arbprogparse.c \
+ program/hash_table.c \
+ program/lex.yy.c \
+ program/nvfragparse.c \
+ program/nvvertparse.c \
+ program/program.c \
+ program/program_parse.tab.c \
+ program/program_parse_extra.c \
+ program/prog_cache.c \
+ program/prog_execute.c \
+ program/prog_instruction.c \
+ program/prog_noise.c \
+ program/prog_optimize.c \
+ program/prog_parameter.c \
+ program/prog_parameter_layout.c \
+ program/prog_print.c \
+ program/prog_statevars.c \
+ program/prog_uniform.c \
+ program/programopt.c \
+ program/register_allocate.c \
+ program/symbol_table.c
+
+SHADER_CXX_SOURCES = \
+ program/ir_to_mesa.cpp \
+ program/sampler.cpp
+
+ASM_C_SOURCES = \
+ x86/common_x86.c \
+ x86/x86_xform.c \
+ x86/3dnow.c \
+ x86/sse.c \
+ x86/rtasm/x86sse.c \
+ sparc/sparc.c \
+ ppc/common_ppc.c \
+ x86-64/x86-64.c
+
+X86_SOURCES = \
+ x86/common_x86_asm.S \
+ x86/x86_xform2.S \
+ x86/x86_xform3.S \
+ x86/x86_xform4.S \
+ x86/x86_cliptest.S \
+ x86/mmx_blend.S \
+ x86/3dnow_xform1.S \
+ x86/3dnow_xform2.S \
+ x86/3dnow_xform3.S \
+ x86/3dnow_xform4.S \
+ x86/3dnow_normal.S \
+ x86/sse_xform1.S \
+ x86/sse_xform2.S \
+ x86/sse_xform3.S \
+ x86/sse_xform4.S \
+ x86/sse_normal.S \
+ x86/read_rgba_span_x86.S
+
+X86-64_SOURCES = \
+ x86-64/xform4.S
+
+SPARC_SOURCES = \
+ sparc/clip.S \
+ sparc/norm.S \
+ sparc/xform.S
+
+COMMON_DRIVER_SOURCES = \
+ drivers/common/driverfuncs.c \
+ drivers/common/meta.c
+
+
+# Sources for building non-Gallium drivers
+MESA_SOURCES = \
+ $(MAIN_SOURCES) \
+ $(MATH_SOURCES) \
+ $(MATH_XFORM_SOURCES) \
+ $(VBO_SOURCES) \
+ $(TNL_SOURCES) \
+ $(PROGRAM_SOURCES) \
+ $(SWRAST_SOURCES) \
+ $(SWRAST_SETUP_SOURCES) \
+ $(COMMON_DRIVER_SOURCES)\
+ $(ASM_C_SOURCES)
+
+MESA_CXX_SOURCES = \
+ $(SHADER_CXX_SOURCES)
+
+# Sources for building Gallium drivers
+MESA_GALLIUM_SOURCES = \
+ $(MAIN_SOURCES) \
+ $(MATH_SOURCES) \
+ $(VBO_SOURCES) \
+ $(STATETRACKER_SOURCES) \
+ $(PROGRAM_SOURCES) \
+ ppc/common_ppc.c \
+ x86/common_x86.c
+
+MESA_GALLIUM_CXX_SOURCES = \
+ $(SHADER_CXX_SOURCES)
+
+# All the core C sources, for dependency checking
+ALL_SOURCES = \
+ $(MESA_SOURCES) \
+ $(MESA_CXX_SOURCES) \
+ $(MESA_ASM_SOURCES) \
+ $(STATETRACKER_SOURCES)
+
+
+### Object files
+
+MESA_OBJECTS = \
+ $(MESA_SOURCES:.c=.o) \
+ $(MESA_CXX_SOURCES:.cpp=.o) \
+ $(MESA_ASM_SOURCES:.S=.o)
+
+MESA_GALLIUM_OBJECTS = \
+ $(MESA_GALLIUM_SOURCES:.c=.o) \
+ $(MESA_GALLIUM_CXX_SOURCES:.cpp=.o) \
+ $(MESA_ASM_SOURCES:.S=.o)
+
+
+COMMON_DRIVER_OBJECTS = $(COMMON_DRIVER_SOURCES:.c=.o)
+
+
+### Other archives/libraries
+
+GLSL_LIBS = \
+ $(TOP)/src/glsl/libglsl.a
+
+
+### Include directories
+
+INCLUDE_DIRS = \
+ -I$(TOP)/include \
+ -I$(TOP)/src/glsl \
+ -I$(TOP)/src/mesa \
+ -I$(TOP)/src/mapi \
+ -I$(TOP)/src/gallium/include \
+ -I$(TOP)/src/gallium/auxiliary
diff --git a/mesalib/src/mesa/state_tracker/st_atom_blend.c b/mesalib/src/mesa/state_tracker/st_atom_blend.c
index fb1c7a4ef..e3b3b9936 100644
--- a/mesalib/src/mesa/state_tracker/st_atom_blend.c
+++ b/mesalib/src/mesa/state_tracker/st_atom_blend.c
@@ -1,302 +1,302 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
- /*
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- * Brian Paul
- */
-
-
-#include "st_context.h"
-#include "st_atom.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "cso_cache/cso_context.h"
-
-#include "main/macros.h"
-
-/**
- * Convert GLenum blend tokens to pipe tokens.
- * Both blend factors and blend funcs are accepted.
- */
-static GLuint
-translate_blend(GLenum blend)
-{
- switch (blend) {
- /* blend functions */
- case GL_FUNC_ADD:
- return PIPE_BLEND_ADD;
- case GL_FUNC_SUBTRACT:
- return PIPE_BLEND_SUBTRACT;
- case GL_FUNC_REVERSE_SUBTRACT:
- return PIPE_BLEND_REVERSE_SUBTRACT;
- case GL_MIN:
- return PIPE_BLEND_MIN;
- case GL_MAX:
- return PIPE_BLEND_MAX;
-
- /* blend factors */
- case GL_ONE:
- return PIPE_BLENDFACTOR_ONE;
- case GL_SRC_COLOR:
- return PIPE_BLENDFACTOR_SRC_COLOR;
- case GL_SRC_ALPHA:
- return PIPE_BLENDFACTOR_SRC_ALPHA;
- case GL_DST_ALPHA:
- return PIPE_BLENDFACTOR_DST_ALPHA;
- case GL_DST_COLOR:
- return PIPE_BLENDFACTOR_DST_COLOR;
- case GL_SRC_ALPHA_SATURATE:
- return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
- case GL_CONSTANT_COLOR:
- return PIPE_BLENDFACTOR_CONST_COLOR;
- case GL_CONSTANT_ALPHA:
- return PIPE_BLENDFACTOR_CONST_ALPHA;
- /*
- return PIPE_BLENDFACTOR_SRC1_COLOR;
- return PIPE_BLENDFACTOR_SRC1_ALPHA;
- */
- case GL_ZERO:
- return PIPE_BLENDFACTOR_ZERO;
- case GL_ONE_MINUS_SRC_COLOR:
- return PIPE_BLENDFACTOR_INV_SRC_COLOR;
- case GL_ONE_MINUS_SRC_ALPHA:
- return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
- case GL_ONE_MINUS_DST_COLOR:
- return PIPE_BLENDFACTOR_INV_DST_COLOR;
- case GL_ONE_MINUS_DST_ALPHA:
- return PIPE_BLENDFACTOR_INV_DST_ALPHA;
- case GL_ONE_MINUS_CONSTANT_COLOR:
- return PIPE_BLENDFACTOR_INV_CONST_COLOR;
- case GL_ONE_MINUS_CONSTANT_ALPHA:
- return PIPE_BLENDFACTOR_INV_CONST_ALPHA;
- /*
- return PIPE_BLENDFACTOR_INV_SRC1_COLOR;
- return PIPE_BLENDFACTOR_INV_SRC1_ALPHA;
- */
- default:
- assert("invalid GL token in translate_blend()" == NULL);
- return 0;
- }
-}
-
-
-/**
- * Convert GLenum logicop tokens to pipe tokens.
- */
-static GLuint
-translate_logicop(GLenum logicop)
-{
- switch (logicop) {
- case GL_CLEAR:
- return PIPE_LOGICOP_CLEAR;
- case GL_NOR:
- return PIPE_LOGICOP_NOR;
- case GL_AND_INVERTED:
- return PIPE_LOGICOP_AND_INVERTED;
- case GL_COPY_INVERTED:
- return PIPE_LOGICOP_COPY_INVERTED;
- case GL_AND_REVERSE:
- return PIPE_LOGICOP_AND_REVERSE;
- case GL_INVERT:
- return PIPE_LOGICOP_INVERT;
- case GL_XOR:
- return PIPE_LOGICOP_XOR;
- case GL_NAND:
- return PIPE_LOGICOP_NAND;
- case GL_AND:
- return PIPE_LOGICOP_AND;
- case GL_EQUIV:
- return PIPE_LOGICOP_EQUIV;
- case GL_NOOP:
- return PIPE_LOGICOP_NOOP;
- case GL_OR_INVERTED:
- return PIPE_LOGICOP_OR_INVERTED;
- case GL_COPY:
- return PIPE_LOGICOP_COPY;
- case GL_OR_REVERSE:
- return PIPE_LOGICOP_OR_REVERSE;
- case GL_OR:
- return PIPE_LOGICOP_OR;
- case GL_SET:
- return PIPE_LOGICOP_SET;
- default:
- assert("invalid GL token in translate_logicop()" == NULL);
- return 0;
- }
-}
-
-/**
- * Figure out if colormasks are different per rt.
- */
-static GLboolean
-colormask_per_rt(struct gl_context *ctx)
-{
- /* a bit suboptimal have to compare lots of values */
- unsigned i;
- for (i = 1; i < ctx->Const.MaxDrawBuffers; i++) {
- if (memcmp(ctx->Color.ColorMask[0], ctx->Color.ColorMask[i], 4)) {
- return GL_TRUE;
- }
- }
- return GL_FALSE;
-}
-
-/**
- * Figure out if blend enables/state are different per rt.
- */
-static GLboolean
-blend_per_rt(struct gl_context *ctx)
-{
- if (ctx->Color.BlendEnabled &&
- (ctx->Color.BlendEnabled != ((1 << ctx->Const.MaxDrawBuffers) - 1))) {
- /* This can only happen if GL_EXT_draw_buffers2 is enabled */
- return GL_TRUE;
- }
- if (ctx->Color._BlendFuncPerBuffer || ctx->Color._BlendEquationPerBuffer) {
- /* this can only happen if GL_ARB_draw_buffers_blend is enabled */
- return GL_TRUE;
- }
- return GL_FALSE;
-}
-
-static void
-update_blend( struct st_context *st )
-{
- struct pipe_blend_state *blend = &st->state.blend;
- unsigned num_state = 1;
- unsigned i, j;
-
- memset(blend, 0, sizeof(*blend));
-
- if (blend_per_rt(st->ctx) || colormask_per_rt(st->ctx)) {
- num_state = st->ctx->Const.MaxDrawBuffers;
- blend->independent_blend_enable = 1;
- }
- /* Note it is impossible to correctly deal with EXT_blend_logic_op and
- EXT_draw_buffers2/EXT_blend_equation_separate at the same time.
- These combinations would require support for per-rt logicop enables
- and separate alpha/rgb logicop/blend support respectively. Neither
- possible in gallium nor most hardware. Assume these combinations
- don't happen. */
- if (st->ctx->Color.ColorLogicOpEnabled ||
- (st->ctx->Color.BlendEnabled &&
- st->ctx->Color.Blend[0].EquationRGB == GL_LOGIC_OP)) {
- /* logicop enabled */
- blend->logicop_enable = 1;
- blend->logicop_func = translate_logicop(st->ctx->Color.LogicOp);
- }
- else if (st->ctx->Color.BlendEnabled) {
- /* blending enabled */
- for (i = 0, j = 0; i < num_state; i++) {
-
- blend->rt[i].blend_enable = (st->ctx->Color.BlendEnabled >> i) & 0x1;
-
- if (st->ctx->Extensions.ARB_draw_buffers_blend)
- j = i;
-
- blend->rt[i].rgb_func =
- translate_blend(st->ctx->Color.Blend[j].EquationRGB);
-
- if (st->ctx->Color.Blend[i].EquationRGB == GL_MIN ||
- st->ctx->Color.Blend[i].EquationRGB == GL_MAX) {
- /* Min/max are special */
- blend->rt[i].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
- blend->rt[i].rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
- }
- else {
- blend->rt[i].rgb_src_factor =
- translate_blend(st->ctx->Color.Blend[j].SrcRGB);
- blend->rt[i].rgb_dst_factor =
- translate_blend(st->ctx->Color.Blend[j].DstRGB);
- }
-
- blend->rt[i].alpha_func =
- translate_blend(st->ctx->Color.Blend[j].EquationA);
-
- if (st->ctx->Color.Blend[i].EquationA == GL_MIN ||
- st->ctx->Color.Blend[i].EquationA == GL_MAX) {
- /* Min/max are special */
- blend->rt[i].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
- blend->rt[i].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
- }
- else {
- blend->rt[i].alpha_src_factor =
- translate_blend(st->ctx->Color.Blend[j].SrcA);
- blend->rt[i].alpha_dst_factor =
- translate_blend(st->ctx->Color.Blend[j].DstA);
- }
- }
- }
- else {
- /* no blending / logicop */
- }
-
- /* Colormask - maybe reverse these bits? */
- for (i = 0; i < num_state; i++) {
- if (st->ctx->Color.ColorMask[i][0])
- blend->rt[i].colormask |= PIPE_MASK_R;
- if (st->ctx->Color.ColorMask[i][1])
- blend->rt[i].colormask |= PIPE_MASK_G;
- if (st->ctx->Color.ColorMask[i][2])
- blend->rt[i].colormask |= PIPE_MASK_B;
- if (st->ctx->Color.ColorMask[i][3])
- blend->rt[i].colormask |= PIPE_MASK_A;
- }
-
- if (st->ctx->Color.DitherFlag)
- blend->dither = 1;
-
- if (st->ctx->Multisample.Enabled) {
- /* unlike in gallium/d3d10 these operations are only performed
- if msaa is enabled */
- if (st->ctx->Multisample.SampleAlphaToCoverage)
- blend->alpha_to_coverage = 1;
- if (st->ctx->Multisample.SampleAlphaToOne)
- blend->alpha_to_one = 1;
- }
-
- cso_set_blend(st->cso_context, blend);
-
- {
- struct pipe_blend_color bc;
- COPY_4FV(bc.color, st->ctx->Color.BlendColor);
- cso_set_blend_color(st->cso_context, &bc);
- }
-}
-
-
-const struct st_tracked_state st_update_blend = {
- "st_update_blend", /* name */
- { /* dirty */
- (_NEW_COLOR | _NEW_MULTISAMPLE), /* XXX _NEW_BLEND someday? */ /* mesa */
- 0, /* st */
- },
- update_blend, /* update */
-};
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+
+#include "st_context.h"
+#include "st_atom.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "cso_cache/cso_context.h"
+
+#include "main/macros.h"
+
+/**
+ * Convert GLenum blend tokens to pipe tokens.
+ * Both blend factors and blend funcs are accepted.
+ */
+static GLuint
+translate_blend(GLenum blend)
+{
+ switch (blend) {
+ /* blend functions */
+ case GL_FUNC_ADD:
+ return PIPE_BLEND_ADD;
+ case GL_FUNC_SUBTRACT:
+ return PIPE_BLEND_SUBTRACT;
+ case GL_FUNC_REVERSE_SUBTRACT:
+ return PIPE_BLEND_REVERSE_SUBTRACT;
+ case GL_MIN:
+ return PIPE_BLEND_MIN;
+ case GL_MAX:
+ return PIPE_BLEND_MAX;
+
+ /* blend factors */
+ case GL_ONE:
+ return PIPE_BLENDFACTOR_ONE;
+ case GL_SRC_COLOR:
+ return PIPE_BLENDFACTOR_SRC_COLOR;
+ case GL_SRC_ALPHA:
+ return PIPE_BLENDFACTOR_SRC_ALPHA;
+ case GL_DST_ALPHA:
+ return PIPE_BLENDFACTOR_DST_ALPHA;
+ case GL_DST_COLOR:
+ return PIPE_BLENDFACTOR_DST_COLOR;
+ case GL_SRC_ALPHA_SATURATE:
+ return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
+ case GL_CONSTANT_COLOR:
+ return PIPE_BLENDFACTOR_CONST_COLOR;
+ case GL_CONSTANT_ALPHA:
+ return PIPE_BLENDFACTOR_CONST_ALPHA;
+ /*
+ return PIPE_BLENDFACTOR_SRC1_COLOR;
+ return PIPE_BLENDFACTOR_SRC1_ALPHA;
+ */
+ case GL_ZERO:
+ return PIPE_BLENDFACTOR_ZERO;
+ case GL_ONE_MINUS_SRC_COLOR:
+ return PIPE_BLENDFACTOR_INV_SRC_COLOR;
+ case GL_ONE_MINUS_SRC_ALPHA:
+ return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
+ case GL_ONE_MINUS_DST_COLOR:
+ return PIPE_BLENDFACTOR_INV_DST_COLOR;
+ case GL_ONE_MINUS_DST_ALPHA:
+ return PIPE_BLENDFACTOR_INV_DST_ALPHA;
+ case GL_ONE_MINUS_CONSTANT_COLOR:
+ return PIPE_BLENDFACTOR_INV_CONST_COLOR;
+ case GL_ONE_MINUS_CONSTANT_ALPHA:
+ return PIPE_BLENDFACTOR_INV_CONST_ALPHA;
+ /*
+ return PIPE_BLENDFACTOR_INV_SRC1_COLOR;
+ return PIPE_BLENDFACTOR_INV_SRC1_ALPHA;
+ */
+ default:
+ assert("invalid GL token in translate_blend()" == NULL);
+ return 0;
+ }
+}
+
+
+/**
+ * Convert GLenum logicop tokens to pipe tokens.
+ */
+static GLuint
+translate_logicop(GLenum logicop)
+{
+ switch (logicop) {
+ case GL_CLEAR:
+ return PIPE_LOGICOP_CLEAR;
+ case GL_NOR:
+ return PIPE_LOGICOP_NOR;
+ case GL_AND_INVERTED:
+ return PIPE_LOGICOP_AND_INVERTED;
+ case GL_COPY_INVERTED:
+ return PIPE_LOGICOP_COPY_INVERTED;
+ case GL_AND_REVERSE:
+ return PIPE_LOGICOP_AND_REVERSE;
+ case GL_INVERT:
+ return PIPE_LOGICOP_INVERT;
+ case GL_XOR:
+ return PIPE_LOGICOP_XOR;
+ case GL_NAND:
+ return PIPE_LOGICOP_NAND;
+ case GL_AND:
+ return PIPE_LOGICOP_AND;
+ case GL_EQUIV:
+ return PIPE_LOGICOP_EQUIV;
+ case GL_NOOP:
+ return PIPE_LOGICOP_NOOP;
+ case GL_OR_INVERTED:
+ return PIPE_LOGICOP_OR_INVERTED;
+ case GL_COPY:
+ return PIPE_LOGICOP_COPY;
+ case GL_OR_REVERSE:
+ return PIPE_LOGICOP_OR_REVERSE;
+ case GL_OR:
+ return PIPE_LOGICOP_OR;
+ case GL_SET:
+ return PIPE_LOGICOP_SET;
+ default:
+ assert("invalid GL token in translate_logicop()" == NULL);
+ return 0;
+ }
+}
+
+/**
+ * Figure out if colormasks are different per rt.
+ */
+static GLboolean
+colormask_per_rt(struct gl_context *ctx)
+{
+ /* a bit suboptimal have to compare lots of values */
+ unsigned i;
+ for (i = 1; i < ctx->Const.MaxDrawBuffers; i++) {
+ if (memcmp(ctx->Color.ColorMask[0], ctx->Color.ColorMask[i], 4)) {
+ return GL_TRUE;
+ }
+ }
+ return GL_FALSE;
+}
+
+/**
+ * Figure out if blend enables/state are different per rt.
+ */
+static GLboolean
+blend_per_rt(struct gl_context *ctx)
+{
+ if (ctx->Color.BlendEnabled &&
+ (ctx->Color.BlendEnabled != ((1 << ctx->Const.MaxDrawBuffers) - 1))) {
+ /* This can only happen if GL_EXT_draw_buffers2 is enabled */
+ return GL_TRUE;
+ }
+ if (ctx->Color._BlendFuncPerBuffer || ctx->Color._BlendEquationPerBuffer) {
+ /* this can only happen if GL_ARB_draw_buffers_blend is enabled */
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+}
+
+static void
+update_blend( struct st_context *st )
+{
+ struct pipe_blend_state *blend = &st->state.blend;
+ unsigned num_state = 1;
+ unsigned i, j;
+
+ memset(blend, 0, sizeof(*blend));
+
+ if (blend_per_rt(st->ctx) || colormask_per_rt(st->ctx)) {
+ num_state = st->ctx->Const.MaxDrawBuffers;
+ blend->independent_blend_enable = 1;
+ }
+ /* Note it is impossible to correctly deal with EXT_blend_logic_op and
+ EXT_draw_buffers2/EXT_blend_equation_separate at the same time.
+ These combinations would require support for per-rt logicop enables
+ and separate alpha/rgb logicop/blend support respectively. Neither
+ possible in gallium nor most hardware. Assume these combinations
+ don't happen. */
+ if (st->ctx->Color.ColorLogicOpEnabled ||
+ (st->ctx->Color.BlendEnabled &&
+ st->ctx->Color.Blend[0].EquationRGB == GL_LOGIC_OP)) {
+ /* logicop enabled */
+ blend->logicop_enable = 1;
+ blend->logicop_func = translate_logicop(st->ctx->Color.LogicOp);
+ }
+ else if (st->ctx->Color.BlendEnabled) {
+ /* blending enabled */
+ for (i = 0, j = 0; i < num_state; i++) {
+
+ blend->rt[i].blend_enable = (st->ctx->Color.BlendEnabled >> i) & 0x1;
+
+ if (st->ctx->Extensions.ARB_draw_buffers_blend)
+ j = i;
+
+ blend->rt[i].rgb_func =
+ translate_blend(st->ctx->Color.Blend[j].EquationRGB);
+
+ if (st->ctx->Color.Blend[i].EquationRGB == GL_MIN ||
+ st->ctx->Color.Blend[i].EquationRGB == GL_MAX) {
+ /* Min/max are special */
+ blend->rt[i].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
+ blend->rt[i].rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
+ }
+ else {
+ blend->rt[i].rgb_src_factor =
+ translate_blend(st->ctx->Color.Blend[j].SrcRGB);
+ blend->rt[i].rgb_dst_factor =
+ translate_blend(st->ctx->Color.Blend[j].DstRGB);
+ }
+
+ blend->rt[i].alpha_func =
+ translate_blend(st->ctx->Color.Blend[j].EquationA);
+
+ if (st->ctx->Color.Blend[i].EquationA == GL_MIN ||
+ st->ctx->Color.Blend[i].EquationA == GL_MAX) {
+ /* Min/max are special */
+ blend->rt[i].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
+ blend->rt[i].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
+ }
+ else {
+ blend->rt[i].alpha_src_factor =
+ translate_blend(st->ctx->Color.Blend[j].SrcA);
+ blend->rt[i].alpha_dst_factor =
+ translate_blend(st->ctx->Color.Blend[j].DstA);
+ }
+ }
+ }
+ else {
+ /* no blending / logicop */
+ }
+
+ /* Colormask - maybe reverse these bits? */
+ for (i = 0; i < num_state; i++) {
+ if (st->ctx->Color.ColorMask[i][0])
+ blend->rt[i].colormask |= PIPE_MASK_R;
+ if (st->ctx->Color.ColorMask[i][1])
+ blend->rt[i].colormask |= PIPE_MASK_G;
+ if (st->ctx->Color.ColorMask[i][2])
+ blend->rt[i].colormask |= PIPE_MASK_B;
+ if (st->ctx->Color.ColorMask[i][3])
+ blend->rt[i].colormask |= PIPE_MASK_A;
+ }
+
+ if (st->ctx->Color.DitherFlag)
+ blend->dither = 1;
+
+ if (st->ctx->Multisample.Enabled) {
+ /* unlike in gallium/d3d10 these operations are only performed
+ if msaa is enabled */
+ if (st->ctx->Multisample.SampleAlphaToCoverage)
+ blend->alpha_to_coverage = 1;
+ if (st->ctx->Multisample.SampleAlphaToOne)
+ blend->alpha_to_one = 1;
+ }
+
+ cso_set_blend(st->cso_context, blend);
+
+ {
+ struct pipe_blend_color bc;
+ COPY_4FV(bc.color, st->ctx->Color.BlendColor);
+ cso_set_blend_color(st->cso_context, &bc);
+ }
+}
+
+
+const struct st_tracked_state st_update_blend = {
+ "st_update_blend", /* name */
+ { /* dirty */
+ (_NEW_COLOR | _NEW_MULTISAMPLE), /* XXX _NEW_BLEND someday? */ /* mesa */
+ 0, /* st */
+ },
+ update_blend, /* update */
+};
diff --git a/mesalib/src/mesa/state_tracker/st_atom_framebuffer.c b/mesalib/src/mesa/state_tracker/st_atom_framebuffer.c
index 76386fe01..678a270c7 100644
--- a/mesalib/src/mesa/state_tracker/st_atom_framebuffer.c
+++ b/mesalib/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -1,182 +1,182 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
- /*
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- * Brian Paul
- */
-
-#include "st_context.h"
-#include "st_atom.h"
-#include "st_cb_fbo.h"
-#include "st_texture.h"
-#include "pipe/p_context.h"
-#include "cso_cache/cso_context.h"
-#include "util/u_math.h"
-#include "util/u_inlines.h"
-#include "util/u_format.h"
-
-
-/**
- * When doing GL render to texture, we have to be sure that finalize_texture()
- * didn't yank out the pipe_resource that we earlier created a surface for.
- * Check for that here and create a new surface if needed.
- */
-static void
-update_renderbuffer_surface(struct st_context *st,
- struct st_renderbuffer *strb)
-{
- struct pipe_context *pipe = st->pipe;
- struct pipe_resource *resource = strb->rtt->pt;
- int rtt_width = strb->Base.Width;
- int rtt_height = strb->Base.Height;
- enum pipe_format format = st->ctx->Color.sRGBEnabled ? resource->format : util_format_linear(resource->format);
-
- if (!strb->surface ||
- strb->surface->format != format ||
- strb->surface->texture != resource ||
- strb->surface->width != rtt_width ||
- strb->surface->height != rtt_height) {
- GLuint level;
- /* find matching mipmap level size */
- for (level = 0; level <= resource->last_level; level++) {
- if (u_minify(resource->width0, level) == rtt_width &&
- u_minify(resource->height0, level) == rtt_height) {
- struct pipe_surface surf_tmpl;
- memset(&surf_tmpl, 0, sizeof(surf_tmpl));
- surf_tmpl.format = format;
- surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
- surf_tmpl.u.tex.level = level;
- surf_tmpl.u.tex.first_layer = strb->rtt_face + strb->rtt_slice;
- surf_tmpl.u.tex.last_layer = strb->rtt_face + strb->rtt_slice;
-
- pipe_surface_reference(&strb->surface, NULL);
-
- strb->surface = pipe->create_surface(pipe,
- resource,
- &surf_tmpl);
-#if 0
- printf("-- alloc new surface %d x %d into tex %p\n",
- strb->surface->width, strb->surface->height,
- texture);
-#endif
- break;
- }
- }
- }
-}
-
-
-/**
- * Update framebuffer state (color, depth, stencil, etc. buffers)
- */
-static void
-update_framebuffer_state( struct st_context *st )
-{
- struct pipe_framebuffer_state *framebuffer = &st->state.framebuffer;
- struct gl_framebuffer *fb = st->ctx->DrawBuffer;
- struct st_renderbuffer *strb;
- GLuint i;
-
- framebuffer->width = fb->Width;
- framebuffer->height = fb->Height;
-
- /*printf("------ fb size %d x %d\n", fb->Width, fb->Height);*/
-
- /* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state
- * to determine which surfaces to draw to
- */
- framebuffer->nr_cbufs = 0;
- for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
- strb = st_renderbuffer(fb->_ColorDrawBuffers[i]);
-
- if (strb) {
- /*printf("--------- framebuffer surface rtt %p\n", strb->rtt);*/
- if (strb->rtt) {
- /* rendering to a GL texture, may have to update surface */
- update_renderbuffer_surface(st, strb);
- }
-
- if (strb->surface) {
- pipe_surface_reference(&framebuffer->cbufs[framebuffer->nr_cbufs],
- strb->surface);
- framebuffer->nr_cbufs++;
- }
- strb->defined = GL_TRUE; /* we'll be drawing something */
- }
- }
- for (i = framebuffer->nr_cbufs; i < PIPE_MAX_COLOR_BUFS; i++) {
- pipe_surface_reference(&framebuffer->cbufs[i], NULL);
- }
-
- /*
- * Depth/Stencil renderbuffer/surface.
- */
- strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
- if (strb) {
- strb = st_renderbuffer(strb->Base.Wrapped);
- if (strb->rtt) {
- /* rendering to a GL texture, may have to update surface */
- update_renderbuffer_surface(st, strb);
- }
- pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
- }
- else {
- strb = st_renderbuffer(fb->Attachment[BUFFER_STENCIL].Renderbuffer);
- if (strb) {
- strb = st_renderbuffer(strb->Base.Wrapped);
- assert(strb->surface);
- pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
- }
- else
- pipe_surface_reference(&framebuffer->zsbuf, NULL);
- }
-
-#ifdef DEBUG
- /* Make sure the resource binding flags were set properly */
- for (i = 0; i < framebuffer->nr_cbufs; i++) {
- assert(framebuffer->cbufs[i]->texture->bind & PIPE_BIND_RENDER_TARGET);
- }
- if (framebuffer->zsbuf) {
- assert(framebuffer->zsbuf->texture->bind & PIPE_BIND_DEPTH_STENCIL);
- }
-#endif
-
- cso_set_framebuffer(st->cso_context, framebuffer);
-}
-
-
-const struct st_tracked_state st_update_framebuffer = {
- "st_update_framebuffer", /* name */
- { /* dirty */
- _NEW_BUFFERS, /* mesa */
- ST_NEW_FRAMEBUFFER, /* st */
- },
- update_framebuffer_state /* update */
-};
-
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_cb_fbo.h"
+#include "st_texture.h"
+#include "pipe/p_context.h"
+#include "cso_cache/cso_context.h"
+#include "util/u_math.h"
+#include "util/u_inlines.h"
+#include "util/u_format.h"
+
+
+/**
+ * When doing GL render to texture, we have to be sure that finalize_texture()
+ * didn't yank out the pipe_resource that we earlier created a surface for.
+ * Check for that here and create a new surface if needed.
+ */
+static void
+update_renderbuffer_surface(struct st_context *st,
+ struct st_renderbuffer *strb)
+{
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_resource *resource = strb->rtt->pt;
+ int rtt_width = strb->Base.Width;
+ int rtt_height = strb->Base.Height;
+ enum pipe_format format = st->ctx->Color.sRGBEnabled ? resource->format : util_format_linear(resource->format);
+
+ if (!strb->surface ||
+ strb->surface->format != format ||
+ strb->surface->texture != resource ||
+ strb->surface->width != rtt_width ||
+ strb->surface->height != rtt_height) {
+ GLuint level;
+ /* find matching mipmap level size */
+ for (level = 0; level <= resource->last_level; level++) {
+ if (u_minify(resource->width0, level) == rtt_width &&
+ u_minify(resource->height0, level) == rtt_height) {
+ struct pipe_surface surf_tmpl;
+ memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+ surf_tmpl.format = format;
+ surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
+ surf_tmpl.u.tex.level = level;
+ surf_tmpl.u.tex.first_layer = strb->rtt_face + strb->rtt_slice;
+ surf_tmpl.u.tex.last_layer = strb->rtt_face + strb->rtt_slice;
+
+ pipe_surface_reference(&strb->surface, NULL);
+
+ strb->surface = pipe->create_surface(pipe,
+ resource,
+ &surf_tmpl);
+#if 0
+ printf("-- alloc new surface %d x %d into tex %p\n",
+ strb->surface->width, strb->surface->height,
+ texture);
+#endif
+ break;
+ }
+ }
+ }
+}
+
+
+/**
+ * Update framebuffer state (color, depth, stencil, etc. buffers)
+ */
+static void
+update_framebuffer_state( struct st_context *st )
+{
+ struct pipe_framebuffer_state *framebuffer = &st->state.framebuffer;
+ struct gl_framebuffer *fb = st->ctx->DrawBuffer;
+ struct st_renderbuffer *strb;
+ GLuint i;
+
+ framebuffer->width = fb->Width;
+ framebuffer->height = fb->Height;
+
+ /*printf("------ fb size %d x %d\n", fb->Width, fb->Height);*/
+
+ /* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state
+ * to determine which surfaces to draw to
+ */
+ framebuffer->nr_cbufs = 0;
+ for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
+ strb = st_renderbuffer(fb->_ColorDrawBuffers[i]);
+
+ if (strb) {
+ /*printf("--------- framebuffer surface rtt %p\n", strb->rtt);*/
+ if (strb->rtt) {
+ /* rendering to a GL texture, may have to update surface */
+ update_renderbuffer_surface(st, strb);
+ }
+
+ if (strb->surface) {
+ pipe_surface_reference(&framebuffer->cbufs[framebuffer->nr_cbufs],
+ strb->surface);
+ framebuffer->nr_cbufs++;
+ }
+ strb->defined = GL_TRUE; /* we'll be drawing something */
+ }
+ }
+ for (i = framebuffer->nr_cbufs; i < PIPE_MAX_COLOR_BUFS; i++) {
+ pipe_surface_reference(&framebuffer->cbufs[i], NULL);
+ }
+
+ /*
+ * Depth/Stencil renderbuffer/surface.
+ */
+ strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
+ if (strb) {
+ strb = st_renderbuffer(strb->Base.Wrapped);
+ if (strb->rtt) {
+ /* rendering to a GL texture, may have to update surface */
+ update_renderbuffer_surface(st, strb);
+ }
+ pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
+ }
+ else {
+ strb = st_renderbuffer(fb->Attachment[BUFFER_STENCIL].Renderbuffer);
+ if (strb) {
+ strb = st_renderbuffer(strb->Base.Wrapped);
+ assert(strb->surface);
+ pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
+ }
+ else
+ pipe_surface_reference(&framebuffer->zsbuf, NULL);
+ }
+
+#ifdef DEBUG
+ /* Make sure the resource binding flags were set properly */
+ for (i = 0; i < framebuffer->nr_cbufs; i++) {
+ assert(framebuffer->cbufs[i]->texture->bind & PIPE_BIND_RENDER_TARGET);
+ }
+ if (framebuffer->zsbuf) {
+ assert(framebuffer->zsbuf->texture->bind & PIPE_BIND_DEPTH_STENCIL);
+ }
+#endif
+
+ cso_set_framebuffer(st->cso_context, framebuffer);
+}
+
+
+const struct st_tracked_state st_update_framebuffer = {
+ "st_update_framebuffer", /* name */
+ { /* dirty */
+ _NEW_BUFFERS, /* mesa */
+ ST_NEW_FRAMEBUFFER, /* st */
+ },
+ update_framebuffer_state /* update */
+};
+
diff --git a/mesalib/src/mesa/state_tracker/st_atom_sampler.c b/mesalib/src/mesa/state_tracker/st_atom_sampler.c
index 474cbd589..17596d4c8 100644
--- a/mesalib/src/mesa/state_tracker/st_atom_sampler.c
+++ b/mesalib/src/mesa/state_tracker/st_atom_sampler.c
@@ -1,228 +1,228 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
- /*
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- * Brian Paul
- */
-
-
-#include "main/macros.h"
-
-#include "st_context.h"
-#include "st_cb_texture.h"
-#include "st_format.h"
-#include "st_atom.h"
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-
-#include "cso_cache/cso_context.h"
-
-
-/**
- * Convert GLenum texcoord wrap tokens to pipe tokens.
- */
-static GLuint
-gl_wrap_xlate(GLenum wrap)
-{
- switch (wrap) {
- case GL_REPEAT:
- return PIPE_TEX_WRAP_REPEAT;
- case GL_CLAMP:
- return PIPE_TEX_WRAP_CLAMP;
- case GL_CLAMP_TO_EDGE:
- return PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- case GL_CLAMP_TO_BORDER:
- return PIPE_TEX_WRAP_CLAMP_TO_BORDER;
- case GL_MIRRORED_REPEAT:
- return PIPE_TEX_WRAP_MIRROR_REPEAT;
- case GL_MIRROR_CLAMP_EXT:
- return PIPE_TEX_WRAP_MIRROR_CLAMP;
- case GL_MIRROR_CLAMP_TO_EDGE_EXT:
- return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
- case GL_MIRROR_CLAMP_TO_BORDER_EXT:
- return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER;
- default:
- assert(0);
- return 0;
- }
-}
-
-
-static GLuint
-gl_filter_to_mip_filter(GLenum filter)
-{
- switch (filter) {
- case GL_NEAREST:
- case GL_LINEAR:
- return PIPE_TEX_MIPFILTER_NONE;
-
- case GL_NEAREST_MIPMAP_NEAREST:
- case GL_LINEAR_MIPMAP_NEAREST:
- return PIPE_TEX_MIPFILTER_NEAREST;
-
- case GL_NEAREST_MIPMAP_LINEAR:
- case GL_LINEAR_MIPMAP_LINEAR:
- return PIPE_TEX_MIPFILTER_LINEAR;
-
- default:
- assert(0);
- return PIPE_TEX_MIPFILTER_NONE;
- }
-}
-
-
-static GLuint
-gl_filter_to_img_filter(GLenum filter)
-{
- switch (filter) {
- case GL_NEAREST:
- case GL_NEAREST_MIPMAP_NEAREST:
- case GL_NEAREST_MIPMAP_LINEAR:
- return PIPE_TEX_FILTER_NEAREST;
-
- case GL_LINEAR:
- case GL_LINEAR_MIPMAP_NEAREST:
- case GL_LINEAR_MIPMAP_LINEAR:
- return PIPE_TEX_FILTER_LINEAR;
-
- default:
- assert(0);
- return PIPE_TEX_FILTER_NEAREST;
- }
-}
-
-
-static void
-update_samplers(struct st_context *st)
-{
- struct gl_vertex_program *vprog = st->ctx->VertexProgram._Current;
- struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current;
- const GLbitfield samplersUsed = (vprog->Base.SamplersUsed |
- fprog->Base.SamplersUsed);
- GLuint su;
-
- st->state.num_samplers = 0;
-
- /* loop over sampler units (aka tex image units) */
- for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) {
- struct pipe_sampler_state *sampler = st->state.samplers + su;
-
- memset(sampler, 0, sizeof(*sampler));
-
- if (samplersUsed & (1 << su)) {
- struct gl_texture_object *texobj;
- struct gl_texture_image *teximg;
- GLuint texUnit;
-
- if (fprog->Base.SamplersUsed & (1 << su))
- texUnit = fprog->Base.SamplerUnits[su];
- else
- texUnit = vprog->Base.SamplerUnits[su];
-
- texobj = st->ctx->Texture.Unit[texUnit]._Current;
- if (!texobj) {
- texobj = st_get_default_texture(st);
- }
-
- teximg = texobj->Image[0][texobj->BaseLevel];
-
- sampler->wrap_s = gl_wrap_xlate(texobj->WrapS);
- sampler->wrap_t = gl_wrap_xlate(texobj->WrapT);
- sampler->wrap_r = gl_wrap_xlate(texobj->WrapR);
-
- sampler->min_img_filter = gl_filter_to_img_filter(texobj->MinFilter);
- sampler->min_mip_filter = gl_filter_to_mip_filter(texobj->MinFilter);
- sampler->mag_img_filter = gl_filter_to_img_filter(texobj->MagFilter);
-
- if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB)
- sampler->normalized_coords = 1;
-
- sampler->lod_bias = st->ctx->Texture.Unit[su].LodBias;
-
- sampler->min_lod = texobj->BaseLevel + texobj->MinLod;
- if (sampler->min_lod < texobj->BaseLevel)
- sampler->min_lod = texobj->BaseLevel;
-
- sampler->max_lod = MIN2((GLfloat) texobj->MaxLevel,
- (texobj->MaxLod + texobj->BaseLevel));
- if (sampler->max_lod < sampler->min_lod) {
- /* The GL spec doesn't seem to specify what to do in this case.
- * Swap the values.
- */
- float tmp = sampler->max_lod;
- sampler->max_lod = sampler->min_lod;
- sampler->min_lod = tmp;
- assert(sampler->min_lod <= sampler->max_lod);
- }
-
- st_translate_color(texobj->BorderColor.f,
- teximg ? teximg->_BaseFormat : GL_RGBA,
- sampler->border_color);
-
- sampler->max_anisotropy = (texobj->MaxAnisotropy == 1.0 ? 0 : (GLuint)texobj->MaxAnisotropy);
-
- /* only care about ARB_shadow, not SGI shadow */
- if (texobj->CompareMode == GL_COMPARE_R_TO_TEXTURE) {
- sampler->compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE;
- sampler->compare_func
- = st_compare_func_to_pipe(texobj->CompareFunc);
- }
-
- st->state.num_samplers = su + 1;
-
- /*printf("%s su=%u non-null\n", __FUNCTION__, su);*/
- cso_single_sampler(st->cso_context, su, sampler);
- if (su < st->ctx->Const.MaxVertexTextureImageUnits) {
- cso_single_vertex_sampler(st->cso_context, su, sampler);
- }
- }
- else {
- /*printf("%s su=%u null\n", __FUNCTION__, su);*/
- cso_single_sampler(st->cso_context, su, NULL);
- if (su < st->ctx->Const.MaxVertexTextureImageUnits) {
- cso_single_vertex_sampler(st->cso_context, su, NULL);
- }
- }
- }
-
- cso_single_sampler_done(st->cso_context);
- if (st->ctx->Const.MaxVertexTextureImageUnits > 0) {
- cso_single_vertex_sampler_done(st->cso_context);
- }
-}
-
-
-const struct st_tracked_state st_update_sampler = {
- "st_update_sampler", /* name */
- { /* dirty */
- _NEW_TEXTURE, /* mesa */
- 0, /* st */
- },
- update_samplers /* update */
-};
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+
+#include "main/macros.h"
+
+#include "st_context.h"
+#include "st_cb_texture.h"
+#include "st_format.h"
+#include "st_atom.h"
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+
+#include "cso_cache/cso_context.h"
+
+
+/**
+ * Convert GLenum texcoord wrap tokens to pipe tokens.
+ */
+static GLuint
+gl_wrap_xlate(GLenum wrap)
+{
+ switch (wrap) {
+ case GL_REPEAT:
+ return PIPE_TEX_WRAP_REPEAT;
+ case GL_CLAMP:
+ return PIPE_TEX_WRAP_CLAMP;
+ case GL_CLAMP_TO_EDGE:
+ return PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ case GL_CLAMP_TO_BORDER:
+ return PIPE_TEX_WRAP_CLAMP_TO_BORDER;
+ case GL_MIRRORED_REPEAT:
+ return PIPE_TEX_WRAP_MIRROR_REPEAT;
+ case GL_MIRROR_CLAMP_EXT:
+ return PIPE_TEX_WRAP_MIRROR_CLAMP;
+ case GL_MIRROR_CLAMP_TO_EDGE_EXT:
+ return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
+ case GL_MIRROR_CLAMP_TO_BORDER_EXT:
+ return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER;
+ default:
+ assert(0);
+ return 0;
+ }
+}
+
+
+static GLuint
+gl_filter_to_mip_filter(GLenum filter)
+{
+ switch (filter) {
+ case GL_NEAREST:
+ case GL_LINEAR:
+ return PIPE_TEX_MIPFILTER_NONE;
+
+ case GL_NEAREST_MIPMAP_NEAREST:
+ case GL_LINEAR_MIPMAP_NEAREST:
+ return PIPE_TEX_MIPFILTER_NEAREST;
+
+ case GL_NEAREST_MIPMAP_LINEAR:
+ case GL_LINEAR_MIPMAP_LINEAR:
+ return PIPE_TEX_MIPFILTER_LINEAR;
+
+ default:
+ assert(0);
+ return PIPE_TEX_MIPFILTER_NONE;
+ }
+}
+
+
+static GLuint
+gl_filter_to_img_filter(GLenum filter)
+{
+ switch (filter) {
+ case GL_NEAREST:
+ case GL_NEAREST_MIPMAP_NEAREST:
+ case GL_NEAREST_MIPMAP_LINEAR:
+ return PIPE_TEX_FILTER_NEAREST;
+
+ case GL_LINEAR:
+ case GL_LINEAR_MIPMAP_NEAREST:
+ case GL_LINEAR_MIPMAP_LINEAR:
+ return PIPE_TEX_FILTER_LINEAR;
+
+ default:
+ assert(0);
+ return PIPE_TEX_FILTER_NEAREST;
+ }
+}
+
+
+static void
+update_samplers(struct st_context *st)
+{
+ struct gl_vertex_program *vprog = st->ctx->VertexProgram._Current;
+ struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current;
+ const GLbitfield samplersUsed = (vprog->Base.SamplersUsed |
+ fprog->Base.SamplersUsed);
+ GLuint su;
+
+ st->state.num_samplers = 0;
+
+ /* loop over sampler units (aka tex image units) */
+ for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) {
+ struct pipe_sampler_state *sampler = st->state.samplers + su;
+
+ memset(sampler, 0, sizeof(*sampler));
+
+ if (samplersUsed & (1 << su)) {
+ struct gl_texture_object *texobj;
+ struct gl_texture_image *teximg;
+ GLuint texUnit;
+
+ if (fprog->Base.SamplersUsed & (1 << su))
+ texUnit = fprog->Base.SamplerUnits[su];
+ else
+ texUnit = vprog->Base.SamplerUnits[su];
+
+ texobj = st->ctx->Texture.Unit[texUnit]._Current;
+ if (!texobj) {
+ texobj = st_get_default_texture(st);
+ }
+
+ teximg = texobj->Image[0][texobj->BaseLevel];
+
+ sampler->wrap_s = gl_wrap_xlate(texobj->WrapS);
+ sampler->wrap_t = gl_wrap_xlate(texobj->WrapT);
+ sampler->wrap_r = gl_wrap_xlate(texobj->WrapR);
+
+ sampler->min_img_filter = gl_filter_to_img_filter(texobj->MinFilter);
+ sampler->min_mip_filter = gl_filter_to_mip_filter(texobj->MinFilter);
+ sampler->mag_img_filter = gl_filter_to_img_filter(texobj->MagFilter);
+
+ if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB)
+ sampler->normalized_coords = 1;
+
+ sampler->lod_bias = st->ctx->Texture.Unit[su].LodBias;
+
+ sampler->min_lod = texobj->BaseLevel + texobj->MinLod;
+ if (sampler->min_lod < texobj->BaseLevel)
+ sampler->min_lod = texobj->BaseLevel;
+
+ sampler->max_lod = MIN2((GLfloat) texobj->MaxLevel,
+ (texobj->MaxLod + texobj->BaseLevel));
+ if (sampler->max_lod < sampler->min_lod) {
+ /* The GL spec doesn't seem to specify what to do in this case.
+ * Swap the values.
+ */
+ float tmp = sampler->max_lod;
+ sampler->max_lod = sampler->min_lod;
+ sampler->min_lod = tmp;
+ assert(sampler->min_lod <= sampler->max_lod);
+ }
+
+ st_translate_color(texobj->BorderColor.f,
+ teximg ? teximg->_BaseFormat : GL_RGBA,
+ sampler->border_color);
+
+ sampler->max_anisotropy = (texobj->MaxAnisotropy == 1.0 ? 0 : (GLuint)texobj->MaxAnisotropy);
+
+ /* only care about ARB_shadow, not SGI shadow */
+ if (texobj->CompareMode == GL_COMPARE_R_TO_TEXTURE) {
+ sampler->compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE;
+ sampler->compare_func
+ = st_compare_func_to_pipe(texobj->CompareFunc);
+ }
+
+ st->state.num_samplers = su + 1;
+
+ /*printf("%s su=%u non-null\n", __FUNCTION__, su);*/
+ cso_single_sampler(st->cso_context, su, sampler);
+ if (su < st->ctx->Const.MaxVertexTextureImageUnits) {
+ cso_single_vertex_sampler(st->cso_context, su, sampler);
+ }
+ }
+ else {
+ /*printf("%s su=%u null\n", __FUNCTION__, su);*/
+ cso_single_sampler(st->cso_context, su, NULL);
+ if (su < st->ctx->Const.MaxVertexTextureImageUnits) {
+ cso_single_vertex_sampler(st->cso_context, su, NULL);
+ }
+ }
+ }
+
+ cso_single_sampler_done(st->cso_context);
+ if (st->ctx->Const.MaxVertexTextureImageUnits > 0) {
+ cso_single_vertex_sampler_done(st->cso_context);
+ }
+}
+
+
+const struct st_tracked_state st_update_sampler = {
+ "st_update_sampler", /* name */
+ { /* dirty */
+ _NEW_TEXTURE, /* mesa */
+ 0, /* st */
+ },
+ update_samplers /* update */
+};
diff --git a/mesalib/src/mesa/state_tracker/st_cb_bitmap.c b/mesalib/src/mesa/state_tracker/st_cb_bitmap.c
index 149f1ca44..d602c0b41 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_bitmap.c
@@ -1,894 +1,894 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
- /*
- * Authors:
- * Brian Paul
- */
-
-#include "main/imports.h"
-#include "main/image.h"
-#include "main/bufferobj.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-#include "main/pbo.h"
-#include "program/program.h"
-#include "program/prog_print.h"
-
-#include "st_context.h"
-#include "st_atom.h"
-#include "st_atom_constbuf.h"
-#include "st_program.h"
-#include "st_cb_bitmap.h"
-#include "st_texture.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_shader_tokens.h"
-#include "util/u_inlines.h"
-#include "util/u_draw_quad.h"
-#include "util/u_simple_shaders.h"
-#include "program/prog_instruction.h"
-#include "cso_cache/cso_context.h"
-
-
-#if FEATURE_drawpix
-
-/**
- * glBitmaps are drawn as textured quads. The user's bitmap pattern
- * is stored in a texture image. An alpha8 texture format is used.
- * The fragment shader samples a bit (texel) from the texture, then
- * discards the fragment if the bit is off.
- *
- * Note that we actually store the inverse image of the bitmap to
- * simplify the fragment program. An "on" bit gets stored as texel=0x0
- * and an "off" bit is stored as texel=0xff. Then we kill the
- * fragment if the negated texel value is less than zero.
- */
-
-
-/**
- * The bitmap cache attempts to accumulate multiple glBitmap calls in a
- * buffer which is then rendered en mass upon a flush, state change, etc.
- * A wide, short buffer is used to target the common case of a series
- * of glBitmap calls being used to draw text.
- */
-static GLboolean UseBitmapCache = GL_TRUE;
-
-
-#define BITMAP_CACHE_WIDTH 512
-#define BITMAP_CACHE_HEIGHT 32
-
-struct bitmap_cache
-{
- /** Window pos to render the cached image */
- GLint xpos, ypos;
- /** Bounds of region used in window coords */
- GLint xmin, ymin, xmax, ymax;
-
- GLfloat color[4];
-
- /** Bitmap's Z position */
- GLfloat zpos;
-
- struct pipe_resource *texture;
- struct pipe_transfer *trans;
-
- GLboolean empty;
-
- /** An I8 texture image: */
- ubyte *buffer;
-};
-
-
-/** Epsilon for Z comparisons */
-#define Z_EPSILON 1e-06
-
-
-/**
- * Make fragment program for glBitmap:
- * Sample the texture and kill the fragment if the bit is 0.
- * This program will be combined with the user's fragment program.
- */
-static struct st_fragment_program *
-make_bitmap_fragment_program(struct gl_context *ctx, GLuint samplerIndex)
-{
- struct st_context *st = st_context(ctx);
- struct st_fragment_program *stfp;
- struct gl_program *p;
- GLuint ic = 0;
-
- p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
- if (!p)
- return NULL;
-
- p->NumInstructions = 3;
-
- p->Instructions = _mesa_alloc_instructions(p->NumInstructions);
- if (!p->Instructions) {
- ctx->Driver.DeleteProgram(ctx, p);
- return NULL;
- }
- _mesa_init_instructions(p->Instructions, p->NumInstructions);
-
- /* TEX tmp0, fragment.texcoord[0], texture[0], 2D; */
- p->Instructions[ic].Opcode = OPCODE_TEX;
- p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY;
- p->Instructions[ic].DstReg.Index = 0;
- p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT;
- p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0;
- p->Instructions[ic].TexSrcUnit = samplerIndex;
- p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX;
- ic++;
-
- /* KIL if -tmp0 < 0 # texel=0 -> keep / texel=0 -> discard */
- p->Instructions[ic].Opcode = OPCODE_KIL;
- p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY;
-
- if (st->bitmap.tex_format == PIPE_FORMAT_L8_UNORM)
- p->Instructions[ic].SrcReg[0].Swizzle = SWIZZLE_XXXX;
-
- p->Instructions[ic].SrcReg[0].Index = 0;
- p->Instructions[ic].SrcReg[0].Negate = NEGATE_XYZW;
- ic++;
-
- /* END; */
- p->Instructions[ic++].Opcode = OPCODE_END;
-
- assert(ic == p->NumInstructions);
-
- p->InputsRead = FRAG_BIT_TEX0;
- p->OutputsWritten = 0x0;
- p->SamplersUsed = (1 << samplerIndex);
-
- stfp = (struct st_fragment_program *) p;
- stfp->Base.UsesKill = GL_TRUE;
-
- return stfp;
-}
-
-
-static int
-find_free_bit(uint bitfield)
-{
- int i;
- for (i = 0; i < 32; i++) {
- if ((bitfield & (1 << i)) == 0) {
- return i;
- }
- }
- return -1;
-}
-
-
-/**
- * Combine basic bitmap fragment program with the user-defined program.
- * \param st current context
- * \param fpIn the incoming fragment program
- * \param fpOut the new fragment program which does fragment culling
- * \param bitmap_sampler sampler number for the bitmap texture
- */
-void
-st_make_bitmap_fragment_program(struct st_context *st,
- struct gl_fragment_program *fpIn,
- struct gl_fragment_program **fpOut,
- GLuint *bitmap_sampler)
-{
- struct st_fragment_program *bitmap_prog;
- struct gl_program *newProg;
- uint sampler;
-
- /*
- * Generate new program which is the user-defined program prefixed
- * with the bitmap sampler/kill instructions.
- */
- sampler = find_free_bit(fpIn->Base.SamplersUsed);
- bitmap_prog = make_bitmap_fragment_program(st->ctx, sampler);
-
- newProg = _mesa_combine_programs(st->ctx,
- &bitmap_prog->Base.Base,
- &fpIn->Base);
- /* done with this after combining */
- st_reference_fragprog(st, &bitmap_prog, NULL);
-
-#if 0
- {
- printf("Combined bitmap program:\n");
- _mesa_print_program(newProg);
- printf("InputsRead: 0x%x\n", newProg->InputsRead);
- printf("OutputsWritten: 0x%x\n", newProg->OutputsWritten);
- _mesa_print_parameter_list(newProg->Parameters);
- }
-#endif
-
- /* return results */
- *fpOut = (struct gl_fragment_program *) newProg;
- *bitmap_sampler = sampler;
-}
-
-
-/**
- * Copy user-provide bitmap bits into texture buffer, expanding
- * bits into texels.
- * "On" bits will set texels to 0x0.
- * "Off" bits will not modify texels.
- * Note that the image is actually going to be upside down in
- * the texture. We deal with that with texcoords.
- */
-static void
-unpack_bitmap(struct st_context *st,
- GLint px, GLint py, GLsizei width, GLsizei height,
- const struct gl_pixelstore_attrib *unpack,
- const GLubyte *bitmap,
- ubyte *destBuffer, uint destStride)
-{
- destBuffer += py * destStride + px;
-
- _mesa_expand_bitmap(width, height, unpack, bitmap,
- destBuffer, destStride, 0x0);
-}
-
-
-/**
- * Create a texture which represents a bitmap image.
- */
-static struct pipe_resource *
-make_bitmap_texture(struct gl_context *ctx, GLsizei width, GLsizei height,
- const struct gl_pixelstore_attrib *unpack,
- const GLubyte *bitmap)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct pipe_transfer *transfer;
- ubyte *dest;
- struct pipe_resource *pt;
-
- /* PBO source... */
- bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap);
- if (!bitmap) {
- return NULL;
- }
-
- /**
- * Create texture to hold bitmap pattern.
- */
- pt = st_texture_create(st, st->internal_target, st->bitmap.tex_format,
- 0, width, height, 1, 1,
- PIPE_BIND_SAMPLER_VIEW);
- if (!pt) {
- _mesa_unmap_pbo_source(ctx, unpack);
- return NULL;
- }
-
- transfer = pipe_get_transfer(st->pipe, pt, 0, 0,
- PIPE_TRANSFER_WRITE,
- 0, 0, width, height);
-
- dest = pipe_transfer_map(pipe, transfer);
-
- /* Put image into texture transfer */
- memset(dest, 0xff, height * transfer->stride);
- unpack_bitmap(st, 0, 0, width, height, unpack, bitmap,
- dest, transfer->stride);
-
- _mesa_unmap_pbo_source(ctx, unpack);
-
- /* Release transfer */
- pipe_transfer_unmap(pipe, transfer);
- pipe->transfer_destroy(pipe, transfer);
-
- return pt;
-}
-
-static GLuint
-setup_bitmap_vertex_data(struct st_context *st, bool normalized,
- int x, int y, int width, int height,
- float z, const float color[4])
-{
- struct pipe_context *pipe = st->pipe;
- const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
- const GLfloat fb_width = (GLfloat)fb->Width;
- const GLfloat fb_height = (GLfloat)fb->Height;
- const GLfloat x0 = (GLfloat)x;
- const GLfloat x1 = (GLfloat)(x + width);
- const GLfloat y0 = (GLfloat)y;
- const GLfloat y1 = (GLfloat)(y + height);
- GLfloat sLeft = (GLfloat)0.0, sRight = (GLfloat)1.0;
- GLfloat tTop = (GLfloat)0.0, tBot = (GLfloat)1.0 - tTop;
- const GLfloat clip_x0 = (GLfloat)(x0 / fb_width * 2.0 - 1.0);
- const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0);
- const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0);
- const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0);
- const GLuint max_slots = 1; /* 4096 / sizeof(st->bitmap.vertices); */
- GLuint i;
-
- if(!normalized)
- {
- sRight = width;
- tBot = height;
- }
-
- /* XXX: Need to improve buffer_write to allow NO_WAIT (as well as
- * no_flush) updates to buffers where we know there is no conflict
- * with previous data. Currently using max_slots > 1 will cause
- * synchronous rendering if the driver flushes its command buffers
- * between one bitmap and the next. Our flush hook below isn't
- * sufficient to catch this as the driver doesn't tell us when it
- * flushes its own command buffers. Until this gets fixed, pay the
- * price of allocating a new buffer for each bitmap cache-flush to
- * avoid synchronous rendering.
- */
- if (st->bitmap.vbuf_slot >= max_slots) {
- pipe_resource_reference(&st->bitmap.vbuf, NULL);
- st->bitmap.vbuf_slot = 0;
- }
-
- if (!st->bitmap.vbuf) {
- st->bitmap.vbuf = pipe_buffer_create(pipe->screen,
- PIPE_BIND_VERTEX_BUFFER,
- PIPE_USAGE_STREAM,
- max_slots *
- sizeof(st->bitmap.vertices));
- }
-
- /* Positions are in clip coords since we need to do clipping in case
- * the bitmap quad goes beyond the window bounds.
- */
- st->bitmap.vertices[0][0][0] = clip_x0;
- st->bitmap.vertices[0][0][1] = clip_y0;
- st->bitmap.vertices[0][2][0] = sLeft;
- st->bitmap.vertices[0][2][1] = tTop;
-
- st->bitmap.vertices[1][0][0] = clip_x1;
- st->bitmap.vertices[1][0][1] = clip_y0;
- st->bitmap.vertices[1][2][0] = sRight;
- st->bitmap.vertices[1][2][1] = tTop;
-
- st->bitmap.vertices[2][0][0] = clip_x1;
- st->bitmap.vertices[2][0][1] = clip_y1;
- st->bitmap.vertices[2][2][0] = sRight;
- st->bitmap.vertices[2][2][1] = tBot;
-
- st->bitmap.vertices[3][0][0] = clip_x0;
- st->bitmap.vertices[3][0][1] = clip_y1;
- st->bitmap.vertices[3][2][0] = sLeft;
- st->bitmap.vertices[3][2][1] = tBot;
-
- /* same for all verts: */
- for (i = 0; i < 4; i++) {
- st->bitmap.vertices[i][0][2] = z;
- st->bitmap.vertices[i][0][3] = 1.0;
- st->bitmap.vertices[i][1][0] = color[0];
- st->bitmap.vertices[i][1][1] = color[1];
- st->bitmap.vertices[i][1][2] = color[2];
- st->bitmap.vertices[i][1][3] = color[3];
- st->bitmap.vertices[i][2][2] = 0.0; /*R*/
- st->bitmap.vertices[i][2][3] = 1.0; /*Q*/
- }
-
- /* put vertex data into vbuf */
- pipe_buffer_write_nooverlap(st->pipe,
- st->bitmap.vbuf,
- st->bitmap.vbuf_slot
- * sizeof(st->bitmap.vertices),
- sizeof st->bitmap.vertices,
- st->bitmap.vertices);
-
- return st->bitmap.vbuf_slot++ * sizeof st->bitmap.vertices;
-}
-
-
-
-/**
- * Render a glBitmap by drawing a textured quad
- */
-static void
-draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
- GLsizei width, GLsizei height,
- struct pipe_sampler_view *sv,
- const GLfloat *color)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct cso_context *cso = st->cso_context;
- struct st_fp_variant *fpv;
- struct st_fp_variant_key key;
- GLuint maxSize;
- GLuint offset;
-
- memset(&key, 0, sizeof(key));
- key.st = st;
- key.bitmap = GL_TRUE;
-
- fpv = st_get_fp_variant(st, st->fp, &key);
-
- /* As an optimization, Mesa's fragment programs will sometimes get the
- * primary color from a statevar/constant rather than a varying variable.
- * when that's the case, we need to ensure that we use the 'color'
- * parameter and not the current attribute color (which may have changed
- * through glRasterPos and state validation.
- * So, we force the proper color here. Not elegant, but it works.
- */
- {
- GLfloat colorSave[4];
- COPY_4V(colorSave, ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
- COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], color);
- st_upload_constants(st, fpv->parameters, PIPE_SHADER_FRAGMENT);
- COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], colorSave);
- }
-
-
- /* limit checks */
- /* XXX if the bitmap is larger than the max texture size, break
- * it up into chunks.
- */
- maxSize = 1 << (pipe->screen->get_param(pipe->screen,
- PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
- assert(width <= (GLsizei)maxSize);
- assert(height <= (GLsizei)maxSize);
-
- cso_save_rasterizer(cso);
- cso_save_samplers(cso);
- cso_save_fragment_sampler_views(cso);
- cso_save_viewport(cso);
- cso_save_fragment_shader(cso);
- cso_save_vertex_shader(cso);
- cso_save_vertex_elements(cso);
- cso_save_vertex_buffers(cso);
-
- /* rasterizer state: just scissor */
- st->bitmap.rasterizer.scissor = ctx->Scissor.Enabled;
- cso_set_rasterizer(cso, &st->bitmap.rasterizer);
-
- /* fragment shader state: TEX lookup program */
- cso_set_fragment_shader_handle(cso, fpv->driver_shader);
-
- /* vertex shader state: position + texcoord pass-through */
- cso_set_vertex_shader_handle(cso, st->bitmap.vs);
-
- /* user samplers, plus our bitmap sampler */
- {
- struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
- uint num = MAX2(fpv->bitmap_sampler + 1, st->state.num_samplers);
- uint i;
- for (i = 0; i < st->state.num_samplers; i++) {
- samplers[i] = &st->state.samplers[i];
- }
- samplers[fpv->bitmap_sampler] =
- &st->bitmap.samplers[sv->texture->target != PIPE_TEXTURE_RECT];
- cso_set_samplers(cso, num, (const struct pipe_sampler_state **) samplers);
- }
-
- /* user textures, plus the bitmap texture */
- {
- struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
- uint num = MAX2(fpv->bitmap_sampler + 1, st->state.num_textures);
- memcpy(sampler_views, st->state.sampler_views, sizeof(sampler_views));
- sampler_views[fpv->bitmap_sampler] = sv;
- cso_set_fragment_sampler_views(cso, num, sampler_views);
- }
-
- /* viewport state: viewport matching window dims */
- {
- const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
- const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP);
- const GLfloat width = (GLfloat)fb->Width;
- const GLfloat height = (GLfloat)fb->Height;
- struct pipe_viewport_state vp;
- vp.scale[0] = 0.5f * width;
- vp.scale[1] = height * (invert ? -0.5f : 0.5f);
- vp.scale[2] = 0.5f;
- vp.scale[3] = 1.0f;
- vp.translate[0] = 0.5f * width;
- vp.translate[1] = 0.5f * height;
- vp.translate[2] = 0.5f;
- vp.translate[3] = 0.0f;
- cso_set_viewport(cso, &vp);
- }
-
- cso_set_vertex_elements(cso, 3, st->velems_util_draw);
-
- /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
- z = z * 2.0 - 1.0;
-
- /* draw textured quad */
- offset = setup_bitmap_vertex_data(st,
- sv->texture->target != PIPE_TEXTURE_RECT,
- x, y, width, height, z, color);
-
- util_draw_vertex_buffer(pipe, st->cso_context, st->bitmap.vbuf, offset,
- PIPE_PRIM_TRIANGLE_FAN,
- 4, /* verts */
- 3); /* attribs/vert */
-
-
- /* restore state */
- cso_restore_rasterizer(cso);
- cso_restore_samplers(cso);
- cso_restore_fragment_sampler_views(cso);
- cso_restore_viewport(cso);
- cso_restore_fragment_shader(cso);
- cso_restore_vertex_shader(cso);
- cso_restore_vertex_elements(cso);
- cso_restore_vertex_buffers(cso);
-}
-
-
-static void
-reset_cache(struct st_context *st)
-{
- struct pipe_context *pipe = st->pipe;
- struct bitmap_cache *cache = st->bitmap.cache;
-
- /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
- cache->empty = GL_TRUE;
-
- cache->xmin = 1000000;
- cache->xmax = -1000000;
- cache->ymin = 1000000;
- cache->ymax = -1000000;
-
- if (cache->trans) {
- pipe->transfer_destroy(pipe, cache->trans);
- cache->trans = NULL;
- }
-
- assert(!cache->texture);
-
- /* allocate a new texture */
- cache->texture = st_texture_create(st, PIPE_TEXTURE_2D,
- st->bitmap.tex_format, 0,
- BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
- 1, 1,
- PIPE_BIND_SAMPLER_VIEW);
-}
-
-
-/** Print bitmap image to stdout (debug) */
-static void
-print_cache(const struct bitmap_cache *cache)
-{
- int i, j, k;
-
- for (i = 0; i < BITMAP_CACHE_HEIGHT; i++) {
- k = BITMAP_CACHE_WIDTH * (BITMAP_CACHE_HEIGHT - i - 1);
- for (j = 0; j < BITMAP_CACHE_WIDTH; j++) {
- if (cache->buffer[k])
- printf("X");
- else
- printf(" ");
- k++;
- }
- printf("\n");
- }
-}
-
-
-/**
- * Create gallium pipe_transfer object for the bitmap cache.
- */
-static void
-create_cache_trans(struct st_context *st)
-{
- struct pipe_context *pipe = st->pipe;
- struct bitmap_cache *cache = st->bitmap.cache;
-
- if (cache->trans)
- return;
-
- /* Map the texture transfer.
- * Subsequent glBitmap calls will write into the texture image.
- */
- cache->trans = pipe_get_transfer(st->pipe, cache->texture, 0, 0,
- PIPE_TRANSFER_WRITE, 0, 0,
- BITMAP_CACHE_WIDTH,
- BITMAP_CACHE_HEIGHT);
- cache->buffer = pipe_transfer_map(pipe, cache->trans);
-
- /* init image to all 0xff */
- memset(cache->buffer, 0xff, cache->trans->stride * BITMAP_CACHE_HEIGHT);
-}
-
-
-/**
- * If there's anything in the bitmap cache, draw/flush it now.
- */
-void
-st_flush_bitmap_cache(struct st_context *st)
-{
- if (!st->bitmap.cache->empty) {
- struct bitmap_cache *cache = st->bitmap.cache;
-
- if (st->ctx->DrawBuffer) {
- struct pipe_context *pipe = st->pipe;
- struct pipe_sampler_view *sv;
-
- assert(cache->xmin <= cache->xmax);
-
-/* printf("flush size %d x %d at %d, %d\n",
- cache->xmax - cache->xmin,
- cache->ymax - cache->ymin,
- cache->xpos, cache->ypos);
-*/
-
- /* The texture transfer has been mapped until now.
- * So unmap and release the texture transfer before drawing.
- */
- if (cache->trans) {
- if (0)
- print_cache(cache);
- pipe_transfer_unmap(pipe, cache->trans);
- cache->buffer = NULL;
-
- pipe->transfer_destroy(pipe, cache->trans);
- cache->trans = NULL;
- }
-
- sv = st_create_texture_sampler_view(st->pipe, cache->texture);
- if (sv) {
- draw_bitmap_quad(st->ctx,
- cache->xpos,
- cache->ypos,
- cache->zpos,
- BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
- sv,
- cache->color);
-
- pipe_sampler_view_reference(&sv, NULL);
- }
- }
-
- /* release/free the texture */
- pipe_resource_reference(&cache->texture, NULL);
-
- reset_cache(st);
- }
-}
-
-
-/**
- * Flush bitmap cache and release vertex buffer.
- */
-void
-st_flush_bitmap( struct st_context *st )
-{
- st_flush_bitmap_cache(st);
-
- /* Release vertex buffer to avoid synchronous rendering if we were
- * to map it in the next frame.
- */
- pipe_resource_reference(&st->bitmap.vbuf, NULL);
- st->bitmap.vbuf_slot = 0;
-}
-
-
-/**
- * Try to accumulate this glBitmap call in the bitmap cache.
- * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
- */
-static GLboolean
-accum_bitmap(struct st_context *st,
- GLint x, GLint y, GLsizei width, GLsizei height,
- const struct gl_pixelstore_attrib *unpack,
- const GLubyte *bitmap )
-{
- struct bitmap_cache *cache = st->bitmap.cache;
- int px = -999, py = -999;
- const GLfloat z = st->ctx->Current.RasterPos[2];
-
- if (width > BITMAP_CACHE_WIDTH ||
- height > BITMAP_CACHE_HEIGHT)
- return GL_FALSE; /* too big to cache */
-
- if (!cache->empty) {
- px = x - cache->xpos; /* pos in buffer */
- py = y - cache->ypos;
- if (px < 0 || px + width > BITMAP_CACHE_WIDTH ||
- py < 0 || py + height > BITMAP_CACHE_HEIGHT ||
- !TEST_EQ_4V(st->ctx->Current.RasterColor, cache->color) ||
- ((fabs(z - cache->zpos) > Z_EPSILON))) {
- /* This bitmap would extend beyond cache bounds, or the bitmap
- * color is changing
- * so flush and continue.
- */
- st_flush_bitmap_cache(st);
- }
- }
-
- if (cache->empty) {
- /* Initialize. Center bitmap vertically in the buffer. */
- px = 0;
- py = (BITMAP_CACHE_HEIGHT - height) / 2;
- cache->xpos = x;
- cache->ypos = y - py;
- cache->zpos = z;
- cache->empty = GL_FALSE;
- COPY_4FV(cache->color, st->ctx->Current.RasterColor);
- }
-
- assert(px != -999);
- assert(py != -999);
-
- if (x < cache->xmin)
- cache->xmin = x;
- if (y < cache->ymin)
- cache->ymin = y;
- if (x + width > cache->xmax)
- cache->xmax = x + width;
- if (y + height > cache->ymax)
- cache->ymax = y + height;
-
- /* create the transfer if needed */
- create_cache_trans(st);
-
- unpack_bitmap(st, px, py, width, height, unpack, bitmap,
- cache->buffer, BITMAP_CACHE_WIDTH);
-
- return GL_TRUE; /* accumulated */
-}
-
-
-
-/**
- * Called via ctx->Driver.Bitmap()
- */
-static void
-st_Bitmap(struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height,
- const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap )
-{
- struct st_context *st = st_context(ctx);
- struct pipe_resource *pt;
-
- if (width == 0 || height == 0)
- return;
-
- st_validate_state(st);
-
- if (!st->bitmap.vs) {
- /* create pass-through vertex shader now */
- const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
- TGSI_SEMANTIC_COLOR,
- TGSI_SEMANTIC_GENERIC };
- const uint semantic_indexes[] = { 0, 0, 0 };
- st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3,
- semantic_names,
- semantic_indexes);
- }
-
- if (UseBitmapCache && accum_bitmap(st, x, y, width, height, unpack, bitmap))
- return;
-
- pt = make_bitmap_texture(ctx, width, height, unpack, bitmap);
- if (pt) {
- struct pipe_sampler_view *sv =
- st_create_texture_sampler_view(st->pipe, pt);
-
- assert(pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT);
-
- if (sv) {
- draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
- width, height, sv,
- st->ctx->Current.RasterColor);
-
- pipe_sampler_view_reference(&sv, NULL);
- }
-
- /* release/free the texture */
- pipe_resource_reference(&pt, NULL);
- }
-}
-
-
-/** Per-context init */
-void
-st_init_bitmap_functions(struct dd_function_table *functions)
-{
- functions->Bitmap = st_Bitmap;
-}
-
-
-/** Per-context init */
-void
-st_init_bitmap(struct st_context *st)
-{
- struct pipe_sampler_state *sampler = &st->bitmap.samplers[0];
- struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
-
- /* init sampler state once */
- memset(sampler, 0, sizeof(*sampler));
- sampler->wrap_s = PIPE_TEX_WRAP_CLAMP;
- sampler->wrap_t = PIPE_TEX_WRAP_CLAMP;
- sampler->wrap_r = PIPE_TEX_WRAP_CLAMP;
- sampler->min_img_filter = PIPE_TEX_FILTER_NEAREST;
- sampler->min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
- sampler->mag_img_filter = PIPE_TEX_FILTER_NEAREST;
- st->bitmap.samplers[1] = *sampler;
- st->bitmap.samplers[1].normalized_coords = 1;
-
- /* init baseline rasterizer state once */
- memset(&st->bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer));
- st->bitmap.rasterizer.gl_rasterization_rules = 1;
-
- /* find a usable texture format */
- if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0)) {
- st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM;
- }
- else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0)) {
- st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM;
- }
- else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0)) {
- st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM;
- }
- else {
- /* XXX support more formats */
- assert(0);
- }
-
- /* alloc bitmap cache object */
- st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache);
-
- reset_cache(st);
-}
-
-
-/** Per-context tear-down */
-void
-st_destroy_bitmap(struct st_context *st)
-{
- struct pipe_context *pipe = st->pipe;
- struct bitmap_cache *cache = st->bitmap.cache;
-
- if (st->bitmap.vs) {
- cso_delete_vertex_shader(st->cso_context, st->bitmap.vs);
- st->bitmap.vs = NULL;
- }
-
- if (st->bitmap.vbuf) {
- pipe_resource_reference(&st->bitmap.vbuf, NULL);
- st->bitmap.vbuf = NULL;
- }
-
- if (cache) {
- if (cache->trans) {
- pipe_transfer_unmap(pipe, cache->trans);
- pipe->transfer_destroy(pipe, cache->trans);
- }
- pipe_resource_reference(&st->bitmap.cache->texture, NULL);
- free(st->bitmap.cache);
- st->bitmap.cache = NULL;
- }
-}
-
-#endif /* FEATURE_drawpix */
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Brian Paul
+ */
+
+#include "main/imports.h"
+#include "main/image.h"
+#include "main/bufferobj.h"
+#include "main/macros.h"
+#include "main/mfeatures.h"
+#include "main/pbo.h"
+#include "program/program.h"
+#include "program/prog_print.h"
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_atom_constbuf.h"
+#include "st_program.h"
+#include "st_cb_bitmap.h"
+#include "st_texture.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_shader_tokens.h"
+#include "util/u_inlines.h"
+#include "util/u_draw_quad.h"
+#include "util/u_simple_shaders.h"
+#include "program/prog_instruction.h"
+#include "cso_cache/cso_context.h"
+
+
+#if FEATURE_drawpix
+
+/**
+ * glBitmaps are drawn as textured quads. The user's bitmap pattern
+ * is stored in a texture image. An alpha8 texture format is used.
+ * The fragment shader samples a bit (texel) from the texture, then
+ * discards the fragment if the bit is off.
+ *
+ * Note that we actually store the inverse image of the bitmap to
+ * simplify the fragment program. An "on" bit gets stored as texel=0x0
+ * and an "off" bit is stored as texel=0xff. Then we kill the
+ * fragment if the negated texel value is less than zero.
+ */
+
+
+/**
+ * The bitmap cache attempts to accumulate multiple glBitmap calls in a
+ * buffer which is then rendered en mass upon a flush, state change, etc.
+ * A wide, short buffer is used to target the common case of a series
+ * of glBitmap calls being used to draw text.
+ */
+static GLboolean UseBitmapCache = GL_TRUE;
+
+
+#define BITMAP_CACHE_WIDTH 512
+#define BITMAP_CACHE_HEIGHT 32
+
+struct bitmap_cache
+{
+ /** Window pos to render the cached image */
+ GLint xpos, ypos;
+ /** Bounds of region used in window coords */
+ GLint xmin, ymin, xmax, ymax;
+
+ GLfloat color[4];
+
+ /** Bitmap's Z position */
+ GLfloat zpos;
+
+ struct pipe_resource *texture;
+ struct pipe_transfer *trans;
+
+ GLboolean empty;
+
+ /** An I8 texture image: */
+ ubyte *buffer;
+};
+
+
+/** Epsilon for Z comparisons */
+#define Z_EPSILON 1e-06
+
+
+/**
+ * Make fragment program for glBitmap:
+ * Sample the texture and kill the fragment if the bit is 0.
+ * This program will be combined with the user's fragment program.
+ */
+static struct st_fragment_program *
+make_bitmap_fragment_program(struct gl_context *ctx, GLuint samplerIndex)
+{
+ struct st_context *st = st_context(ctx);
+ struct st_fragment_program *stfp;
+ struct gl_program *p;
+ GLuint ic = 0;
+
+ p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
+ if (!p)
+ return NULL;
+
+ p->NumInstructions = 3;
+
+ p->Instructions = _mesa_alloc_instructions(p->NumInstructions);
+ if (!p->Instructions) {
+ ctx->Driver.DeleteProgram(ctx, p);
+ return NULL;
+ }
+ _mesa_init_instructions(p->Instructions, p->NumInstructions);
+
+ /* TEX tmp0, fragment.texcoord[0], texture[0], 2D; */
+ p->Instructions[ic].Opcode = OPCODE_TEX;
+ p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY;
+ p->Instructions[ic].DstReg.Index = 0;
+ p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT;
+ p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0;
+ p->Instructions[ic].TexSrcUnit = samplerIndex;
+ p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX;
+ ic++;
+
+ /* KIL if -tmp0 < 0 # texel=0 -> keep / texel=0 -> discard */
+ p->Instructions[ic].Opcode = OPCODE_KIL;
+ p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY;
+
+ if (st->bitmap.tex_format == PIPE_FORMAT_L8_UNORM)
+ p->Instructions[ic].SrcReg[0].Swizzle = SWIZZLE_XXXX;
+
+ p->Instructions[ic].SrcReg[0].Index = 0;
+ p->Instructions[ic].SrcReg[0].Negate = NEGATE_XYZW;
+ ic++;
+
+ /* END; */
+ p->Instructions[ic++].Opcode = OPCODE_END;
+
+ assert(ic == p->NumInstructions);
+
+ p->InputsRead = FRAG_BIT_TEX0;
+ p->OutputsWritten = 0x0;
+ p->SamplersUsed = (1 << samplerIndex);
+
+ stfp = (struct st_fragment_program *) p;
+ stfp->Base.UsesKill = GL_TRUE;
+
+ return stfp;
+}
+
+
+static int
+find_free_bit(uint bitfield)
+{
+ int i;
+ for (i = 0; i < 32; i++) {
+ if ((bitfield & (1 << i)) == 0) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+
+/**
+ * Combine basic bitmap fragment program with the user-defined program.
+ * \param st current context
+ * \param fpIn the incoming fragment program
+ * \param fpOut the new fragment program which does fragment culling
+ * \param bitmap_sampler sampler number for the bitmap texture
+ */
+void
+st_make_bitmap_fragment_program(struct st_context *st,
+ struct gl_fragment_program *fpIn,
+ struct gl_fragment_program **fpOut,
+ GLuint *bitmap_sampler)
+{
+ struct st_fragment_program *bitmap_prog;
+ struct gl_program *newProg;
+ uint sampler;
+
+ /*
+ * Generate new program which is the user-defined program prefixed
+ * with the bitmap sampler/kill instructions.
+ */
+ sampler = find_free_bit(fpIn->Base.SamplersUsed);
+ bitmap_prog = make_bitmap_fragment_program(st->ctx, sampler);
+
+ newProg = _mesa_combine_programs(st->ctx,
+ &bitmap_prog->Base.Base,
+ &fpIn->Base);
+ /* done with this after combining */
+ st_reference_fragprog(st, &bitmap_prog, NULL);
+
+#if 0
+ {
+ printf("Combined bitmap program:\n");
+ _mesa_print_program(newProg);
+ printf("InputsRead: 0x%x\n", newProg->InputsRead);
+ printf("OutputsWritten: 0x%x\n", newProg->OutputsWritten);
+ _mesa_print_parameter_list(newProg->Parameters);
+ }
+#endif
+
+ /* return results */
+ *fpOut = (struct gl_fragment_program *) newProg;
+ *bitmap_sampler = sampler;
+}
+
+
+/**
+ * Copy user-provide bitmap bits into texture buffer, expanding
+ * bits into texels.
+ * "On" bits will set texels to 0x0.
+ * "Off" bits will not modify texels.
+ * Note that the image is actually going to be upside down in
+ * the texture. We deal with that with texcoords.
+ */
+static void
+unpack_bitmap(struct st_context *st,
+ GLint px, GLint py, GLsizei width, GLsizei height,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLubyte *bitmap,
+ ubyte *destBuffer, uint destStride)
+{
+ destBuffer += py * destStride + px;
+
+ _mesa_expand_bitmap(width, height, unpack, bitmap,
+ destBuffer, destStride, 0x0);
+}
+
+
+/**
+ * Create a texture which represents a bitmap image.
+ */
+static struct pipe_resource *
+make_bitmap_texture(struct gl_context *ctx, GLsizei width, GLsizei height,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLubyte *bitmap)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_transfer *transfer;
+ ubyte *dest;
+ struct pipe_resource *pt;
+
+ /* PBO source... */
+ bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap);
+ if (!bitmap) {
+ return NULL;
+ }
+
+ /**
+ * Create texture to hold bitmap pattern.
+ */
+ pt = st_texture_create(st, st->internal_target, st->bitmap.tex_format,
+ 0, width, height, 1, 1,
+ PIPE_BIND_SAMPLER_VIEW);
+ if (!pt) {
+ _mesa_unmap_pbo_source(ctx, unpack);
+ return NULL;
+ }
+
+ transfer = pipe_get_transfer(st->pipe, pt, 0, 0,
+ PIPE_TRANSFER_WRITE,
+ 0, 0, width, height);
+
+ dest = pipe_transfer_map(pipe, transfer);
+
+ /* Put image into texture transfer */
+ memset(dest, 0xff, height * transfer->stride);
+ unpack_bitmap(st, 0, 0, width, height, unpack, bitmap,
+ dest, transfer->stride);
+
+ _mesa_unmap_pbo_source(ctx, unpack);
+
+ /* Release transfer */
+ pipe_transfer_unmap(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
+
+ return pt;
+}
+
+static GLuint
+setup_bitmap_vertex_data(struct st_context *st, bool normalized,
+ int x, int y, int width, int height,
+ float z, const float color[4])
+{
+ struct pipe_context *pipe = st->pipe;
+ const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
+ const GLfloat fb_width = (GLfloat)fb->Width;
+ const GLfloat fb_height = (GLfloat)fb->Height;
+ const GLfloat x0 = (GLfloat)x;
+ const GLfloat x1 = (GLfloat)(x + width);
+ const GLfloat y0 = (GLfloat)y;
+ const GLfloat y1 = (GLfloat)(y + height);
+ GLfloat sLeft = (GLfloat)0.0, sRight = (GLfloat)1.0;
+ GLfloat tTop = (GLfloat)0.0, tBot = (GLfloat)1.0 - tTop;
+ const GLfloat clip_x0 = (GLfloat)(x0 / fb_width * 2.0 - 1.0);
+ const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0);
+ const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0);
+ const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0);
+ const GLuint max_slots = 1; /* 4096 / sizeof(st->bitmap.vertices); */
+ GLuint i;
+
+ if(!normalized)
+ {
+ sRight = width;
+ tBot = height;
+ }
+
+ /* XXX: Need to improve buffer_write to allow NO_WAIT (as well as
+ * no_flush) updates to buffers where we know there is no conflict
+ * with previous data. Currently using max_slots > 1 will cause
+ * synchronous rendering if the driver flushes its command buffers
+ * between one bitmap and the next. Our flush hook below isn't
+ * sufficient to catch this as the driver doesn't tell us when it
+ * flushes its own command buffers. Until this gets fixed, pay the
+ * price of allocating a new buffer for each bitmap cache-flush to
+ * avoid synchronous rendering.
+ */
+ if (st->bitmap.vbuf_slot >= max_slots) {
+ pipe_resource_reference(&st->bitmap.vbuf, NULL);
+ st->bitmap.vbuf_slot = 0;
+ }
+
+ if (!st->bitmap.vbuf) {
+ st->bitmap.vbuf = pipe_buffer_create(pipe->screen,
+ PIPE_BIND_VERTEX_BUFFER,
+ PIPE_USAGE_STREAM,
+ max_slots *
+ sizeof(st->bitmap.vertices));
+ }
+
+ /* Positions are in clip coords since we need to do clipping in case
+ * the bitmap quad goes beyond the window bounds.
+ */
+ st->bitmap.vertices[0][0][0] = clip_x0;
+ st->bitmap.vertices[0][0][1] = clip_y0;
+ st->bitmap.vertices[0][2][0] = sLeft;
+ st->bitmap.vertices[0][2][1] = tTop;
+
+ st->bitmap.vertices[1][0][0] = clip_x1;
+ st->bitmap.vertices[1][0][1] = clip_y0;
+ st->bitmap.vertices[1][2][0] = sRight;
+ st->bitmap.vertices[1][2][1] = tTop;
+
+ st->bitmap.vertices[2][0][0] = clip_x1;
+ st->bitmap.vertices[2][0][1] = clip_y1;
+ st->bitmap.vertices[2][2][0] = sRight;
+ st->bitmap.vertices[2][2][1] = tBot;
+
+ st->bitmap.vertices[3][0][0] = clip_x0;
+ st->bitmap.vertices[3][0][1] = clip_y1;
+ st->bitmap.vertices[3][2][0] = sLeft;
+ st->bitmap.vertices[3][2][1] = tBot;
+
+ /* same for all verts: */
+ for (i = 0; i < 4; i++) {
+ st->bitmap.vertices[i][0][2] = z;
+ st->bitmap.vertices[i][0][3] = 1.0;
+ st->bitmap.vertices[i][1][0] = color[0];
+ st->bitmap.vertices[i][1][1] = color[1];
+ st->bitmap.vertices[i][1][2] = color[2];
+ st->bitmap.vertices[i][1][3] = color[3];
+ st->bitmap.vertices[i][2][2] = 0.0; /*R*/
+ st->bitmap.vertices[i][2][3] = 1.0; /*Q*/
+ }
+
+ /* put vertex data into vbuf */
+ pipe_buffer_write_nooverlap(st->pipe,
+ st->bitmap.vbuf,
+ st->bitmap.vbuf_slot
+ * sizeof(st->bitmap.vertices),
+ sizeof st->bitmap.vertices,
+ st->bitmap.vertices);
+
+ return st->bitmap.vbuf_slot++ * sizeof st->bitmap.vertices;
+}
+
+
+
+/**
+ * Render a glBitmap by drawing a textured quad
+ */
+static void
+draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
+ GLsizei width, GLsizei height,
+ struct pipe_sampler_view *sv,
+ const GLfloat *color)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct cso_context *cso = st->cso_context;
+ struct st_fp_variant *fpv;
+ struct st_fp_variant_key key;
+ GLuint maxSize;
+ GLuint offset;
+
+ memset(&key, 0, sizeof(key));
+ key.st = st;
+ key.bitmap = GL_TRUE;
+
+ fpv = st_get_fp_variant(st, st->fp, &key);
+
+ /* As an optimization, Mesa's fragment programs will sometimes get the
+ * primary color from a statevar/constant rather than a varying variable.
+ * when that's the case, we need to ensure that we use the 'color'
+ * parameter and not the current attribute color (which may have changed
+ * through glRasterPos and state validation.
+ * So, we force the proper color here. Not elegant, but it works.
+ */
+ {
+ GLfloat colorSave[4];
+ COPY_4V(colorSave, ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
+ COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], color);
+ st_upload_constants(st, fpv->parameters, PIPE_SHADER_FRAGMENT);
+ COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], colorSave);
+ }
+
+
+ /* limit checks */
+ /* XXX if the bitmap is larger than the max texture size, break
+ * it up into chunks.
+ */
+ maxSize = 1 << (pipe->screen->get_param(pipe->screen,
+ PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
+ assert(width <= (GLsizei)maxSize);
+ assert(height <= (GLsizei)maxSize);
+
+ cso_save_rasterizer(cso);
+ cso_save_samplers(cso);
+ cso_save_fragment_sampler_views(cso);
+ cso_save_viewport(cso);
+ cso_save_fragment_shader(cso);
+ cso_save_vertex_shader(cso);
+ cso_save_vertex_elements(cso);
+ cso_save_vertex_buffers(cso);
+
+ /* rasterizer state: just scissor */
+ st->bitmap.rasterizer.scissor = ctx->Scissor.Enabled;
+ cso_set_rasterizer(cso, &st->bitmap.rasterizer);
+
+ /* fragment shader state: TEX lookup program */
+ cso_set_fragment_shader_handle(cso, fpv->driver_shader);
+
+ /* vertex shader state: position + texcoord pass-through */
+ cso_set_vertex_shader_handle(cso, st->bitmap.vs);
+
+ /* user samplers, plus our bitmap sampler */
+ {
+ struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
+ uint num = MAX2(fpv->bitmap_sampler + 1, st->state.num_samplers);
+ uint i;
+ for (i = 0; i < st->state.num_samplers; i++) {
+ samplers[i] = &st->state.samplers[i];
+ }
+ samplers[fpv->bitmap_sampler] =
+ &st->bitmap.samplers[sv->texture->target != PIPE_TEXTURE_RECT];
+ cso_set_samplers(cso, num, (const struct pipe_sampler_state **) samplers);
+ }
+
+ /* user textures, plus the bitmap texture */
+ {
+ struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
+ uint num = MAX2(fpv->bitmap_sampler + 1, st->state.num_textures);
+ memcpy(sampler_views, st->state.sampler_views, sizeof(sampler_views));
+ sampler_views[fpv->bitmap_sampler] = sv;
+ cso_set_fragment_sampler_views(cso, num, sampler_views);
+ }
+
+ /* viewport state: viewport matching window dims */
+ {
+ const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
+ const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP);
+ const GLfloat width = (GLfloat)fb->Width;
+ const GLfloat height = (GLfloat)fb->Height;
+ struct pipe_viewport_state vp;
+ vp.scale[0] = 0.5f * width;
+ vp.scale[1] = height * (invert ? -0.5f : 0.5f);
+ vp.scale[2] = 0.5f;
+ vp.scale[3] = 1.0f;
+ vp.translate[0] = 0.5f * width;
+ vp.translate[1] = 0.5f * height;
+ vp.translate[2] = 0.5f;
+ vp.translate[3] = 0.0f;
+ cso_set_viewport(cso, &vp);
+ }
+
+ cso_set_vertex_elements(cso, 3, st->velems_util_draw);
+
+ /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
+ z = z * 2.0 - 1.0;
+
+ /* draw textured quad */
+ offset = setup_bitmap_vertex_data(st,
+ sv->texture->target != PIPE_TEXTURE_RECT,
+ x, y, width, height, z, color);
+
+ util_draw_vertex_buffer(pipe, st->cso_context, st->bitmap.vbuf, offset,
+ PIPE_PRIM_TRIANGLE_FAN,
+ 4, /* verts */
+ 3); /* attribs/vert */
+
+
+ /* restore state */
+ cso_restore_rasterizer(cso);
+ cso_restore_samplers(cso);
+ cso_restore_fragment_sampler_views(cso);
+ cso_restore_viewport(cso);
+ cso_restore_fragment_shader(cso);
+ cso_restore_vertex_shader(cso);
+ cso_restore_vertex_elements(cso);
+ cso_restore_vertex_buffers(cso);
+}
+
+
+static void
+reset_cache(struct st_context *st)
+{
+ struct pipe_context *pipe = st->pipe;
+ struct bitmap_cache *cache = st->bitmap.cache;
+
+ /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
+ cache->empty = GL_TRUE;
+
+ cache->xmin = 1000000;
+ cache->xmax = -1000000;
+ cache->ymin = 1000000;
+ cache->ymax = -1000000;
+
+ if (cache->trans) {
+ pipe->transfer_destroy(pipe, cache->trans);
+ cache->trans = NULL;
+ }
+
+ assert(!cache->texture);
+
+ /* allocate a new texture */
+ cache->texture = st_texture_create(st, PIPE_TEXTURE_2D,
+ st->bitmap.tex_format, 0,
+ BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
+ 1, 1,
+ PIPE_BIND_SAMPLER_VIEW);
+}
+
+
+/** Print bitmap image to stdout (debug) */
+static void
+print_cache(const struct bitmap_cache *cache)
+{
+ int i, j, k;
+
+ for (i = 0; i < BITMAP_CACHE_HEIGHT; i++) {
+ k = BITMAP_CACHE_WIDTH * (BITMAP_CACHE_HEIGHT - i - 1);
+ for (j = 0; j < BITMAP_CACHE_WIDTH; j++) {
+ if (cache->buffer[k])
+ printf("X");
+ else
+ printf(" ");
+ k++;
+ }
+ printf("\n");
+ }
+}
+
+
+/**
+ * Create gallium pipe_transfer object for the bitmap cache.
+ */
+static void
+create_cache_trans(struct st_context *st)
+{
+ struct pipe_context *pipe = st->pipe;
+ struct bitmap_cache *cache = st->bitmap.cache;
+
+ if (cache->trans)
+ return;
+
+ /* Map the texture transfer.
+ * Subsequent glBitmap calls will write into the texture image.
+ */
+ cache->trans = pipe_get_transfer(st->pipe, cache->texture, 0, 0,
+ PIPE_TRANSFER_WRITE, 0, 0,
+ BITMAP_CACHE_WIDTH,
+ BITMAP_CACHE_HEIGHT);
+ cache->buffer = pipe_transfer_map(pipe, cache->trans);
+
+ /* init image to all 0xff */
+ memset(cache->buffer, 0xff, cache->trans->stride * BITMAP_CACHE_HEIGHT);
+}
+
+
+/**
+ * If there's anything in the bitmap cache, draw/flush it now.
+ */
+void
+st_flush_bitmap_cache(struct st_context *st)
+{
+ if (!st->bitmap.cache->empty) {
+ struct bitmap_cache *cache = st->bitmap.cache;
+
+ if (st->ctx->DrawBuffer) {
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_sampler_view *sv;
+
+ assert(cache->xmin <= cache->xmax);
+
+/* printf("flush size %d x %d at %d, %d\n",
+ cache->xmax - cache->xmin,
+ cache->ymax - cache->ymin,
+ cache->xpos, cache->ypos);
+*/
+
+ /* The texture transfer has been mapped until now.
+ * So unmap and release the texture transfer before drawing.
+ */
+ if (cache->trans) {
+ if (0)
+ print_cache(cache);
+ pipe_transfer_unmap(pipe, cache->trans);
+ cache->buffer = NULL;
+
+ pipe->transfer_destroy(pipe, cache->trans);
+ cache->trans = NULL;
+ }
+
+ sv = st_create_texture_sampler_view(st->pipe, cache->texture);
+ if (sv) {
+ draw_bitmap_quad(st->ctx,
+ cache->xpos,
+ cache->ypos,
+ cache->zpos,
+ BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
+ sv,
+ cache->color);
+
+ pipe_sampler_view_reference(&sv, NULL);
+ }
+ }
+
+ /* release/free the texture */
+ pipe_resource_reference(&cache->texture, NULL);
+
+ reset_cache(st);
+ }
+}
+
+
+/**
+ * Flush bitmap cache and release vertex buffer.
+ */
+void
+st_flush_bitmap( struct st_context *st )
+{
+ st_flush_bitmap_cache(st);
+
+ /* Release vertex buffer to avoid synchronous rendering if we were
+ * to map it in the next frame.
+ */
+ pipe_resource_reference(&st->bitmap.vbuf, NULL);
+ st->bitmap.vbuf_slot = 0;
+}
+
+
+/**
+ * Try to accumulate this glBitmap call in the bitmap cache.
+ * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
+ */
+static GLboolean
+accum_bitmap(struct st_context *st,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLubyte *bitmap )
+{
+ struct bitmap_cache *cache = st->bitmap.cache;
+ int px = -999, py = -999;
+ const GLfloat z = st->ctx->Current.RasterPos[2];
+
+ if (width > BITMAP_CACHE_WIDTH ||
+ height > BITMAP_CACHE_HEIGHT)
+ return GL_FALSE; /* too big to cache */
+
+ if (!cache->empty) {
+ px = x - cache->xpos; /* pos in buffer */
+ py = y - cache->ypos;
+ if (px < 0 || px + width > BITMAP_CACHE_WIDTH ||
+ py < 0 || py + height > BITMAP_CACHE_HEIGHT ||
+ !TEST_EQ_4V(st->ctx->Current.RasterColor, cache->color) ||
+ ((fabs(z - cache->zpos) > Z_EPSILON))) {
+ /* This bitmap would extend beyond cache bounds, or the bitmap
+ * color is changing
+ * so flush and continue.
+ */
+ st_flush_bitmap_cache(st);
+ }
+ }
+
+ if (cache->empty) {
+ /* Initialize. Center bitmap vertically in the buffer. */
+ px = 0;
+ py = (BITMAP_CACHE_HEIGHT - height) / 2;
+ cache->xpos = x;
+ cache->ypos = y - py;
+ cache->zpos = z;
+ cache->empty = GL_FALSE;
+ COPY_4FV(cache->color, st->ctx->Current.RasterColor);
+ }
+
+ assert(px != -999);
+ assert(py != -999);
+
+ if (x < cache->xmin)
+ cache->xmin = x;
+ if (y < cache->ymin)
+ cache->ymin = y;
+ if (x + width > cache->xmax)
+ cache->xmax = x + width;
+ if (y + height > cache->ymax)
+ cache->ymax = y + height;
+
+ /* create the transfer if needed */
+ create_cache_trans(st);
+
+ unpack_bitmap(st, px, py, width, height, unpack, bitmap,
+ cache->buffer, BITMAP_CACHE_WIDTH);
+
+ return GL_TRUE; /* accumulated */
+}
+
+
+
+/**
+ * Called via ctx->Driver.Bitmap()
+ */
+static void
+st_Bitmap(struct gl_context *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap )
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_resource *pt;
+
+ if (width == 0 || height == 0)
+ return;
+
+ st_validate_state(st);
+
+ if (!st->bitmap.vs) {
+ /* create pass-through vertex shader now */
+ const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
+ TGSI_SEMANTIC_COLOR,
+ TGSI_SEMANTIC_GENERIC };
+ const uint semantic_indexes[] = { 0, 0, 0 };
+ st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3,
+ semantic_names,
+ semantic_indexes);
+ }
+
+ if (UseBitmapCache && accum_bitmap(st, x, y, width, height, unpack, bitmap))
+ return;
+
+ pt = make_bitmap_texture(ctx, width, height, unpack, bitmap);
+ if (pt) {
+ struct pipe_sampler_view *sv =
+ st_create_texture_sampler_view(st->pipe, pt);
+
+ assert(pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT);
+
+ if (sv) {
+ draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
+ width, height, sv,
+ st->ctx->Current.RasterColor);
+
+ pipe_sampler_view_reference(&sv, NULL);
+ }
+
+ /* release/free the texture */
+ pipe_resource_reference(&pt, NULL);
+ }
+}
+
+
+/** Per-context init */
+void
+st_init_bitmap_functions(struct dd_function_table *functions)
+{
+ functions->Bitmap = st_Bitmap;
+}
+
+
+/** Per-context init */
+void
+st_init_bitmap(struct st_context *st)
+{
+ struct pipe_sampler_state *sampler = &st->bitmap.samplers[0];
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_screen *screen = pipe->screen;
+
+ /* init sampler state once */
+ memset(sampler, 0, sizeof(*sampler));
+ sampler->wrap_s = PIPE_TEX_WRAP_CLAMP;
+ sampler->wrap_t = PIPE_TEX_WRAP_CLAMP;
+ sampler->wrap_r = PIPE_TEX_WRAP_CLAMP;
+ sampler->min_img_filter = PIPE_TEX_FILTER_NEAREST;
+ sampler->min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
+ sampler->mag_img_filter = PIPE_TEX_FILTER_NEAREST;
+ st->bitmap.samplers[1] = *sampler;
+ st->bitmap.samplers[1].normalized_coords = 1;
+
+ /* init baseline rasterizer state once */
+ memset(&st->bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer));
+ st->bitmap.rasterizer.gl_rasterization_rules = 1;
+
+ /* find a usable texture format */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
+ st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM;
+ }
+ else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
+ st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM;
+ }
+ else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
+ st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM;
+ }
+ else {
+ /* XXX support more formats */
+ assert(0);
+ }
+
+ /* alloc bitmap cache object */
+ st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache);
+
+ reset_cache(st);
+}
+
+
+/** Per-context tear-down */
+void
+st_destroy_bitmap(struct st_context *st)
+{
+ struct pipe_context *pipe = st->pipe;
+ struct bitmap_cache *cache = st->bitmap.cache;
+
+ if (st->bitmap.vs) {
+ cso_delete_vertex_shader(st->cso_context, st->bitmap.vs);
+ st->bitmap.vs = NULL;
+ }
+
+ if (st->bitmap.vbuf) {
+ pipe_resource_reference(&st->bitmap.vbuf, NULL);
+ st->bitmap.vbuf = NULL;
+ }
+
+ if (cache) {
+ if (cache->trans) {
+ pipe_transfer_unmap(pipe, cache->trans);
+ pipe->transfer_destroy(pipe, cache->trans);
+ }
+ pipe_resource_reference(&st->bitmap.cache->texture, NULL);
+ free(st->bitmap.cache);
+ st->bitmap.cache = NULL;
+ }
+}
+
+#endif /* FEATURE_drawpix */
diff --git a/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c b/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c
index 12528f49f..9dd1f8a3e 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -1,468 +1,468 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-/**
- * Functions for pixel buffer objects and vertex/element buffer objects.
- */
-
-
-#include "main/imports.h"
-#include "main/mtypes.h"
-#include "main/arrayobj.h"
-#include "main/bufferobj.h"
-
-#include "st_context.h"
-#include "st_cb_bufferobjects.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-
-
-/**
- * There is some duplication between mesa's bufferobjects and our
- * bufmgr buffers. Both have an integer handle and a hashtable to
- * lookup an opaque structure. It would be nice if the handles and
- * internal structure where somehow shared.
- */
-static struct gl_buffer_object *
-st_bufferobj_alloc(struct gl_context *ctx, GLuint name, GLenum target)
-{
- struct st_buffer_object *st_obj = ST_CALLOC_STRUCT(st_buffer_object);
-
- if (!st_obj)
- return NULL;
-
- _mesa_initialize_buffer_object(&st_obj->Base, name, target);
-
- return &st_obj->Base;
-}
-
-
-
-/**
- * Deallocate/free a vertex/pixel buffer object.
- * Called via glDeleteBuffersARB().
- */
-static void
-st_bufferobj_free(struct gl_context *ctx, struct gl_buffer_object *obj)
-{
- struct st_buffer_object *st_obj = st_buffer_object(obj);
-
- assert(obj->RefCount == 0);
- assert(st_obj->transfer == NULL);
-
- if (st_obj->buffer)
- pipe_resource_reference(&st_obj->buffer, NULL);
-
- free(st_obj);
-}
-
-
-
-/**
- * Replace data in a subrange of buffer object. If the data range
- * specified by size + offset extends beyond the end of the buffer or
- * if data is NULL, no copy is performed.
- * Called via glBufferSubDataARB().
- */
-static void
-st_bufferobj_subdata(struct gl_context *ctx,
- GLenum target,
- GLintptrARB offset,
- GLsizeiptrARB size,
- const GLvoid * data, struct gl_buffer_object *obj)
-{
- struct st_buffer_object *st_obj = st_buffer_object(obj);
-
- /* we may be called from VBO code, so double-check params here */
- ASSERT(offset >= 0);
- ASSERT(size >= 0);
- ASSERT(offset + size <= obj->Size);
-
- if (!size)
- return;
-
- /*
- * According to ARB_vertex_buffer_object specification, if data is null,
- * then the contents of the buffer object's data store is undefined. We just
- * ignore, and leave it unchanged.
- */
- if (!data)
- return;
-
- /* Now that transfers are per-context, we don't have to figure out
- * flushing here. Usually drivers won't need to flush in this case
- * even if the buffer is currently referenced by hardware - they
- * just queue the upload as dma rather than mapping the underlying
- * buffer directly.
- */
- pipe_buffer_write(st_context(ctx)->pipe,
- st_obj->buffer,
- offset, size, data);
-}
-
-
-/**
- * Called via glGetBufferSubDataARB().
- */
-static void
-st_bufferobj_get_subdata(struct gl_context *ctx,
- GLenum target,
- GLintptrARB offset,
- GLsizeiptrARB size,
- GLvoid * data, struct gl_buffer_object *obj)
-{
- struct st_buffer_object *st_obj = st_buffer_object(obj);
-
- /* we may be called from VBO code, so double-check params here */
- ASSERT(offset >= 0);
- ASSERT(size >= 0);
- ASSERT(offset + size <= obj->Size);
-
- if (!size)
- return;
-
- pipe_buffer_read(st_context(ctx)->pipe, st_obj->buffer,
- offset, size, data);
-}
-
-
-/**
- * Allocate space for and store data in a buffer object. Any data that was
- * previously stored in the buffer object is lost. If data is NULL,
- * memory will be allocated, but no copy will occur.
- * Called via ctx->Driver.BufferData().
- * \return GL_TRUE for success, GL_FALSE if out of memory
- */
-static GLboolean
-st_bufferobj_data(struct gl_context *ctx,
- GLenum target,
- GLsizeiptrARB size,
- const GLvoid * data,
- GLenum usage,
- struct gl_buffer_object *obj)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct st_buffer_object *st_obj = st_buffer_object(obj);
- unsigned bind, pipe_usage;
-
- st_obj->Base.Size = size;
- st_obj->Base.Usage = usage;
-
- switch(target) {
- case GL_PIXEL_PACK_BUFFER_ARB:
- case GL_PIXEL_UNPACK_BUFFER_ARB:
- bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
- break;
- case GL_ARRAY_BUFFER_ARB:
- bind = PIPE_BIND_VERTEX_BUFFER;
- break;
- case GL_ELEMENT_ARRAY_BUFFER_ARB:
- bind = PIPE_BIND_INDEX_BUFFER;
- break;
- default:
- bind = 0;
- }
-
- switch (usage) {
- case GL_STATIC_DRAW:
- case GL_STATIC_READ:
- case GL_STATIC_COPY:
- pipe_usage = PIPE_USAGE_STATIC;
- break;
- case GL_DYNAMIC_DRAW:
- case GL_DYNAMIC_READ:
- case GL_DYNAMIC_COPY:
- pipe_usage = PIPE_USAGE_DYNAMIC;
- break;
- case GL_STREAM_DRAW:
- case GL_STREAM_READ:
- case GL_STREAM_COPY:
- pipe_usage = PIPE_USAGE_STREAM;
- break;
- default:
- pipe_usage = PIPE_USAGE_DEFAULT;
- }
-
- pipe_resource_reference( &st_obj->buffer, NULL );
-
- if (size != 0) {
- st_obj->buffer = pipe_buffer_create(pipe->screen, bind,
- pipe_usage, size);
-
- if (!st_obj->buffer) {
- return GL_FALSE;
- }
-
- if (data)
- pipe_buffer_write(st_context(ctx)->pipe, st_obj->buffer, 0,
- size, data);
- return GL_TRUE;
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Dummy data whose's pointer is used for zero size buffers or ranges.
- */
-static long st_bufferobj_zero_length = 0;
-
-
-
-/**
- * Called via glMapBufferARB().
- */
-static void *
-st_bufferobj_map(struct gl_context *ctx, GLenum target, GLenum access,
- struct gl_buffer_object *obj)
-{
- struct st_buffer_object *st_obj = st_buffer_object(obj);
- uint flags;
-
- switch (access) {
- case GL_WRITE_ONLY:
- flags = PIPE_TRANSFER_WRITE;
- break;
- case GL_READ_ONLY:
- flags = PIPE_TRANSFER_READ;
- break;
- case GL_READ_WRITE:
- default:
- flags = PIPE_TRANSFER_READ_WRITE;
- break;
- }
-
- /* Handle zero-size buffers here rather than in drivers */
- if (obj->Size == 0) {
- obj->Pointer = &st_bufferobj_zero_length;
- }
- else {
- obj->Pointer = pipe_buffer_map(st_context(ctx)->pipe,
- st_obj->buffer,
- flags,
- &st_obj->transfer);
- }
-
- if (obj->Pointer) {
- obj->Offset = 0;
- obj->Length = obj->Size;
- }
- return obj->Pointer;
-}
-
-
-/**
- * Called via glMapBufferRange().
- */
-static void *
-st_bufferobj_map_range(struct gl_context *ctx, GLenum target,
- GLintptr offset, GLsizeiptr length, GLbitfield access,
- struct gl_buffer_object *obj)
-{
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct st_buffer_object *st_obj = st_buffer_object(obj);
- enum pipe_transfer_usage flags = 0x0;
-
- if (access & GL_MAP_WRITE_BIT)
- flags |= PIPE_TRANSFER_WRITE;
-
- if (access & GL_MAP_READ_BIT)
- flags |= PIPE_TRANSFER_READ;
-
- if (access & GL_MAP_FLUSH_EXPLICIT_BIT)
- flags |= PIPE_TRANSFER_FLUSH_EXPLICIT;
-
- if (access & GL_MAP_INVALIDATE_RANGE_BIT)
- flags |= PIPE_TRANSFER_DISCARD;
-
- if (access & GL_MAP_INVALIDATE_BUFFER_BIT)
- flags |= PIPE_TRANSFER_DISCARD;
-
- if (access & GL_MAP_UNSYNCHRONIZED_BIT)
- flags |= PIPE_TRANSFER_UNSYNCHRONIZED;
-
- /* ... other flags ...
- */
-
- if (access & MESA_MAP_NOWAIT_BIT)
- flags |= PIPE_TRANSFER_DONTBLOCK;
-
- assert(offset >= 0);
- assert(length >= 0);
- assert(offset < obj->Size);
- assert(offset + length <= obj->Size);
-
- /*
- * We go out of way here to hide the degenerate yet valid case of zero
- * length range from the pipe driver.
- */
- if (!length) {
- obj->Pointer = &st_bufferobj_zero_length;
- }
- else {
- obj->Pointer = pipe_buffer_map_range(pipe,
- st_obj->buffer,
- offset, length,
- flags,
- &st_obj->transfer);
- if (obj->Pointer) {
- obj->Pointer = (ubyte *) obj->Pointer + offset;
- }
- }
-
- if (obj->Pointer) {
- obj->Offset = offset;
- obj->Length = length;
- obj->AccessFlags = access;
- }
-
- return obj->Pointer;
-}
-
-
-static void
-st_bufferobj_flush_mapped_range(struct gl_context *ctx, GLenum target,
- GLintptr offset, GLsizeiptr length,
- struct gl_buffer_object *obj)
-{
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct st_buffer_object *st_obj = st_buffer_object(obj);
-
- /* Subrange is relative to mapped range */
- assert(offset >= 0);
- assert(length >= 0);
- assert(offset + length <= obj->Length);
- assert(obj->Pointer);
-
- if (!length)
- return;
-
- pipe_buffer_flush_mapped_range(pipe, st_obj->transfer,
- obj->Offset + offset, length);
-}
-
-
-/**
- * Called via glUnmapBufferARB().
- */
-static GLboolean
-st_bufferobj_unmap(struct gl_context *ctx, GLenum target, struct gl_buffer_object *obj)
-{
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct st_buffer_object *st_obj = st_buffer_object(obj);
-
- if (obj->Length)
- pipe_buffer_unmap(pipe, st_obj->transfer);
-
- st_obj->transfer = NULL;
- obj->Pointer = NULL;
- obj->Offset = 0;
- obj->Length = 0;
- return GL_TRUE;
-}
-
-
-/**
- * Called via glCopyBufferSubData().
- */
-static void
-st_copy_buffer_subdata(struct gl_context *ctx,
- struct gl_buffer_object *src,
- struct gl_buffer_object *dst,
- GLintptr readOffset, GLintptr writeOffset,
- GLsizeiptr size)
-{
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct st_buffer_object *srcObj = st_buffer_object(src);
- struct st_buffer_object *dstObj = st_buffer_object(dst);
- struct pipe_transfer *src_transfer;
- struct pipe_transfer *dst_transfer;
- ubyte *srcPtr, *dstPtr;
-
- if(!size)
- return;
-
- /* buffer should not already be mapped */
- assert(!src->Pointer);
- assert(!dst->Pointer);
-
- srcPtr = (ubyte *) pipe_buffer_map_range(pipe,
- srcObj->buffer,
- readOffset, size,
- PIPE_TRANSFER_READ,
- &src_transfer);
-
- dstPtr = (ubyte *) pipe_buffer_map_range(pipe,
- dstObj->buffer,
- writeOffset, size,
- PIPE_TRANSFER_WRITE,
- &dst_transfer);
-
- if (srcPtr && dstPtr)
- memcpy(dstPtr + writeOffset, srcPtr + readOffset, size);
-
- pipe_buffer_unmap(pipe, src_transfer);
- pipe_buffer_unmap(pipe, dst_transfer);
-}
-
-
-/* TODO: if buffer wasn't created with appropriate usage flags, need
- * to recreate it now and copy contents -- or possibly create a
- * gallium entrypoint to extend the usage flags and let the driver
- * decide if a copy is necessary.
- */
-void
-st_bufferobj_validate_usage(struct st_context *st,
- struct st_buffer_object *obj,
- unsigned usage)
-{
-}
-
-
-void
-st_init_bufferobject_functions(struct dd_function_table *functions)
-{
- functions->NewBufferObject = st_bufferobj_alloc;
- functions->DeleteBuffer = st_bufferobj_free;
- functions->BufferData = st_bufferobj_data;
- functions->BufferSubData = st_bufferobj_subdata;
- functions->GetBufferSubData = st_bufferobj_get_subdata;
- functions->MapBuffer = st_bufferobj_map;
- functions->MapBufferRange = st_bufferobj_map_range;
- functions->FlushMappedBufferRange = st_bufferobj_flush_mapped_range;
- functions->UnmapBuffer = st_bufferobj_unmap;
- functions->CopyBufferSubData = st_copy_buffer_subdata;
-
- /* For GL_APPLE_vertex_array_object */
- functions->NewArrayObject = _mesa_new_array_object;
- functions->DeleteArrayObject = _mesa_delete_array_object;
-}
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+/**
+ * Functions for pixel buffer objects and vertex/element buffer objects.
+ */
+
+
+#include "main/imports.h"
+#include "main/mtypes.h"
+#include "main/arrayobj.h"
+#include "main/bufferobj.h"
+
+#include "st_context.h"
+#include "st_cb_bufferobjects.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+
+
+/**
+ * There is some duplication between mesa's bufferobjects and our
+ * bufmgr buffers. Both have an integer handle and a hashtable to
+ * lookup an opaque structure. It would be nice if the handles and
+ * internal structure where somehow shared.
+ */
+static struct gl_buffer_object *
+st_bufferobj_alloc(struct gl_context *ctx, GLuint name, GLenum target)
+{
+ struct st_buffer_object *st_obj = ST_CALLOC_STRUCT(st_buffer_object);
+
+ if (!st_obj)
+ return NULL;
+
+ _mesa_initialize_buffer_object(&st_obj->Base, name, target);
+
+ return &st_obj->Base;
+}
+
+
+
+/**
+ * Deallocate/free a vertex/pixel buffer object.
+ * Called via glDeleteBuffersARB().
+ */
+static void
+st_bufferobj_free(struct gl_context *ctx, struct gl_buffer_object *obj)
+{
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+
+ assert(obj->RefCount == 0);
+ assert(st_obj->transfer == NULL);
+
+ if (st_obj->buffer)
+ pipe_resource_reference(&st_obj->buffer, NULL);
+
+ free(st_obj);
+}
+
+
+
+/**
+ * Replace data in a subrange of buffer object. If the data range
+ * specified by size + offset extends beyond the end of the buffer or
+ * if data is NULL, no copy is performed.
+ * Called via glBufferSubDataARB().
+ */
+static void
+st_bufferobj_subdata(struct gl_context *ctx,
+ GLenum target,
+ GLintptrARB offset,
+ GLsizeiptrARB size,
+ const GLvoid * data, struct gl_buffer_object *obj)
+{
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+
+ /* we may be called from VBO code, so double-check params here */
+ ASSERT(offset >= 0);
+ ASSERT(size >= 0);
+ ASSERT(offset + size <= obj->Size);
+
+ if (!size)
+ return;
+
+ /*
+ * According to ARB_vertex_buffer_object specification, if data is null,
+ * then the contents of the buffer object's data store is undefined. We just
+ * ignore, and leave it unchanged.
+ */
+ if (!data)
+ return;
+
+ /* Now that transfers are per-context, we don't have to figure out
+ * flushing here. Usually drivers won't need to flush in this case
+ * even if the buffer is currently referenced by hardware - they
+ * just queue the upload as dma rather than mapping the underlying
+ * buffer directly.
+ */
+ pipe_buffer_write(st_context(ctx)->pipe,
+ st_obj->buffer,
+ offset, size, data);
+}
+
+
+/**
+ * Called via glGetBufferSubDataARB().
+ */
+static void
+st_bufferobj_get_subdata(struct gl_context *ctx,
+ GLenum target,
+ GLintptrARB offset,
+ GLsizeiptrARB size,
+ GLvoid * data, struct gl_buffer_object *obj)
+{
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+
+ /* we may be called from VBO code, so double-check params here */
+ ASSERT(offset >= 0);
+ ASSERT(size >= 0);
+ ASSERT(offset + size <= obj->Size);
+
+ if (!size)
+ return;
+
+ pipe_buffer_read(st_context(ctx)->pipe, st_obj->buffer,
+ offset, size, data);
+}
+
+
+/**
+ * Allocate space for and store data in a buffer object. Any data that was
+ * previously stored in the buffer object is lost. If data is NULL,
+ * memory will be allocated, but no copy will occur.
+ * Called via ctx->Driver.BufferData().
+ * \return GL_TRUE for success, GL_FALSE if out of memory
+ */
+static GLboolean
+st_bufferobj_data(struct gl_context *ctx,
+ GLenum target,
+ GLsizeiptrARB size,
+ const GLvoid * data,
+ GLenum usage,
+ struct gl_buffer_object *obj)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+ unsigned bind, pipe_usage;
+
+ st_obj->Base.Size = size;
+ st_obj->Base.Usage = usage;
+
+ switch(target) {
+ case GL_PIXEL_PACK_BUFFER_ARB:
+ case GL_PIXEL_UNPACK_BUFFER_ARB:
+ bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+ break;
+ case GL_ARRAY_BUFFER_ARB:
+ bind = PIPE_BIND_VERTEX_BUFFER;
+ break;
+ case GL_ELEMENT_ARRAY_BUFFER_ARB:
+ bind = PIPE_BIND_INDEX_BUFFER;
+ break;
+ default:
+ bind = 0;
+ }
+
+ switch (usage) {
+ case GL_STATIC_DRAW:
+ case GL_STATIC_READ:
+ case GL_STATIC_COPY:
+ pipe_usage = PIPE_USAGE_STATIC;
+ break;
+ case GL_DYNAMIC_DRAW:
+ case GL_DYNAMIC_READ:
+ case GL_DYNAMIC_COPY:
+ pipe_usage = PIPE_USAGE_DYNAMIC;
+ break;
+ case GL_STREAM_DRAW:
+ case GL_STREAM_READ:
+ case GL_STREAM_COPY:
+ pipe_usage = PIPE_USAGE_STREAM;
+ break;
+ default:
+ pipe_usage = PIPE_USAGE_DEFAULT;
+ }
+
+ pipe_resource_reference( &st_obj->buffer, NULL );
+
+ if (size != 0) {
+ st_obj->buffer = pipe_buffer_create(pipe->screen, bind,
+ pipe_usage, size);
+
+ if (!st_obj->buffer) {
+ return GL_FALSE;
+ }
+
+ if (data)
+ pipe_buffer_write(st_context(ctx)->pipe, st_obj->buffer, 0,
+ size, data);
+ return GL_TRUE;
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Dummy data whose's pointer is used for zero size buffers or ranges.
+ */
+static long st_bufferobj_zero_length = 0;
+
+
+
+/**
+ * Called via glMapBufferARB().
+ */
+static void *
+st_bufferobj_map(struct gl_context *ctx, GLenum target, GLenum access,
+ struct gl_buffer_object *obj)
+{
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+ uint flags;
+
+ switch (access) {
+ case GL_WRITE_ONLY:
+ flags = PIPE_TRANSFER_WRITE;
+ break;
+ case GL_READ_ONLY:
+ flags = PIPE_TRANSFER_READ;
+ break;
+ case GL_READ_WRITE:
+ default:
+ flags = PIPE_TRANSFER_READ_WRITE;
+ break;
+ }
+
+ /* Handle zero-size buffers here rather than in drivers */
+ if (obj->Size == 0) {
+ obj->Pointer = &st_bufferobj_zero_length;
+ }
+ else {
+ obj->Pointer = pipe_buffer_map(st_context(ctx)->pipe,
+ st_obj->buffer,
+ flags,
+ &st_obj->transfer);
+ }
+
+ if (obj->Pointer) {
+ obj->Offset = 0;
+ obj->Length = obj->Size;
+ }
+ return obj->Pointer;
+}
+
+
+/**
+ * Called via glMapBufferRange().
+ */
+static void *
+st_bufferobj_map_range(struct gl_context *ctx, GLenum target,
+ GLintptr offset, GLsizeiptr length, GLbitfield access,
+ struct gl_buffer_object *obj)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+ enum pipe_transfer_usage flags = 0x0;
+
+ if (access & GL_MAP_WRITE_BIT)
+ flags |= PIPE_TRANSFER_WRITE;
+
+ if (access & GL_MAP_READ_BIT)
+ flags |= PIPE_TRANSFER_READ;
+
+ if (access & GL_MAP_FLUSH_EXPLICIT_BIT)
+ flags |= PIPE_TRANSFER_FLUSH_EXPLICIT;
+
+ if (access & GL_MAP_INVALIDATE_RANGE_BIT)
+ flags |= PIPE_TRANSFER_DISCARD;
+
+ if (access & GL_MAP_INVALIDATE_BUFFER_BIT)
+ flags |= PIPE_TRANSFER_DISCARD;
+
+ if (access & GL_MAP_UNSYNCHRONIZED_BIT)
+ flags |= PIPE_TRANSFER_UNSYNCHRONIZED;
+
+ /* ... other flags ...
+ */
+
+ if (access & MESA_MAP_NOWAIT_BIT)
+ flags |= PIPE_TRANSFER_DONTBLOCK;
+
+ assert(offset >= 0);
+ assert(length >= 0);
+ assert(offset < obj->Size);
+ assert(offset + length <= obj->Size);
+
+ /*
+ * We go out of way here to hide the degenerate yet valid case of zero
+ * length range from the pipe driver.
+ */
+ if (!length) {
+ obj->Pointer = &st_bufferobj_zero_length;
+ }
+ else {
+ obj->Pointer = pipe_buffer_map_range(pipe,
+ st_obj->buffer,
+ offset, length,
+ flags,
+ &st_obj->transfer);
+ if (obj->Pointer) {
+ obj->Pointer = (ubyte *) obj->Pointer + offset;
+ }
+ }
+
+ if (obj->Pointer) {
+ obj->Offset = offset;
+ obj->Length = length;
+ obj->AccessFlags = access;
+ }
+
+ return obj->Pointer;
+}
+
+
+static void
+st_bufferobj_flush_mapped_range(struct gl_context *ctx, GLenum target,
+ GLintptr offset, GLsizeiptr length,
+ struct gl_buffer_object *obj)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+
+ /* Subrange is relative to mapped range */
+ assert(offset >= 0);
+ assert(length >= 0);
+ assert(offset + length <= obj->Length);
+ assert(obj->Pointer);
+
+ if (!length)
+ return;
+
+ pipe_buffer_flush_mapped_range(pipe, st_obj->transfer,
+ obj->Offset + offset, length);
+}
+
+
+/**
+ * Called via glUnmapBufferARB().
+ */
+static GLboolean
+st_bufferobj_unmap(struct gl_context *ctx, GLenum target, struct gl_buffer_object *obj)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+
+ if (obj->Length)
+ pipe_buffer_unmap(pipe, st_obj->transfer);
+
+ st_obj->transfer = NULL;
+ obj->Pointer = NULL;
+ obj->Offset = 0;
+ obj->Length = 0;
+ return GL_TRUE;
+}
+
+
+/**
+ * Called via glCopyBufferSubData().
+ */
+static void
+st_copy_buffer_subdata(struct gl_context *ctx,
+ struct gl_buffer_object *src,
+ struct gl_buffer_object *dst,
+ GLintptr readOffset, GLintptr writeOffset,
+ GLsizeiptr size)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_buffer_object *srcObj = st_buffer_object(src);
+ struct st_buffer_object *dstObj = st_buffer_object(dst);
+ struct pipe_transfer *src_transfer;
+ struct pipe_transfer *dst_transfer;
+ ubyte *srcPtr, *dstPtr;
+
+ if(!size)
+ return;
+
+ /* buffer should not already be mapped */
+ assert(!src->Pointer);
+ assert(!dst->Pointer);
+
+ srcPtr = (ubyte *) pipe_buffer_map_range(pipe,
+ srcObj->buffer,
+ readOffset, size,
+ PIPE_TRANSFER_READ,
+ &src_transfer);
+
+ dstPtr = (ubyte *) pipe_buffer_map_range(pipe,
+ dstObj->buffer,
+ writeOffset, size,
+ PIPE_TRANSFER_WRITE,
+ &dst_transfer);
+
+ if (srcPtr && dstPtr)
+ memcpy(dstPtr + writeOffset, srcPtr + readOffset, size);
+
+ pipe_buffer_unmap(pipe, src_transfer);
+ pipe_buffer_unmap(pipe, dst_transfer);
+}
+
+
+/* TODO: if buffer wasn't created with appropriate usage flags, need
+ * to recreate it now and copy contents -- or possibly create a
+ * gallium entrypoint to extend the usage flags and let the driver
+ * decide if a copy is necessary.
+ */
+void
+st_bufferobj_validate_usage(struct st_context *st,
+ struct st_buffer_object *obj,
+ unsigned usage)
+{
+}
+
+
+void
+st_init_bufferobject_functions(struct dd_function_table *functions)
+{
+ functions->NewBufferObject = st_bufferobj_alloc;
+ functions->DeleteBuffer = st_bufferobj_free;
+ functions->BufferData = st_bufferobj_data;
+ functions->BufferSubData = st_bufferobj_subdata;
+ functions->GetBufferSubData = st_bufferobj_get_subdata;
+ functions->MapBuffer = st_bufferobj_map;
+ functions->MapBufferRange = st_bufferobj_map_range;
+ functions->FlushMappedBufferRange = st_bufferobj_flush_mapped_range;
+ functions->UnmapBuffer = st_bufferobj_unmap;
+ functions->CopyBufferSubData = st_copy_buffer_subdata;
+
+ /* For GL_APPLE_vertex_array_object */
+ functions->NewArrayObject = _mesa_new_array_object;
+ functions->DeleteArrayObject = _mesa_delete_array_object;
+}
diff --git a/mesalib/src/mesa/state_tracker/st_cb_clear.c b/mesalib/src/mesa/state_tracker/st_cb_clear.c
index 0e0c4326e..79e58182f 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_clear.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_clear.c
@@ -1,579 +1,579 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- * Copyright 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
- /*
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- * Brian Paul
- * Michel Dänzer
- */
-
-#include "main/glheader.h"
-#include "main/formats.h"
-#include "main/macros.h"
-#include "program/prog_instruction.h"
-#include "st_context.h"
-#include "st_atom.h"
-#include "st_cb_accum.h"
-#include "st_cb_clear.h"
-#include "st_cb_fbo.h"
-#include "st_format.h"
-#include "st_program.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_shader_tokens.h"
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "util/u_format.h"
-#include "util/u_inlines.h"
-#include "util/u_simple_shaders.h"
-#include "util/u_draw_quad.h"
-
-#include "cso_cache/cso_context.h"
-
-
-/**
- * Do per-context initialization for glClear.
- */
-void
-st_init_clear(struct st_context *st)
-{
- struct pipe_context *pipe = st->pipe;
- struct pipe_screen *pscreen = st->pipe->screen;
-
- memset(&st->clear, 0, sizeof(st->clear));
-
- st->clear.raster.gl_rasterization_rules = 1;
- st->clear.enable_ds_separate = pscreen->get_param(pscreen, PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE);
-
- /* fragment shader state: color pass-through program */
- st->clear.fs = util_make_fragment_passthrough_shader(pipe);
-
- /* vertex shader state: color/position pass-through */
- {
- const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
- TGSI_SEMANTIC_COLOR };
- const uint semantic_indexes[] = { 0, 0 };
- st->clear.vs = util_make_vertex_passthrough_shader(pipe, 2,
- semantic_names,
- semantic_indexes);
- }
-}
-
-
-/**
- * Free per-context state for glClear.
- */
-void
-st_destroy_clear(struct st_context *st)
-{
- if (st->clear.fs) {
- cso_delete_fragment_shader(st->cso_context, st->clear.fs);
- st->clear.fs = NULL;
- }
- if (st->clear.vs) {
- cso_delete_vertex_shader(st->cso_context, st->clear.vs);
- st->clear.vs = NULL;
- }
- if (st->clear.vbuf) {
- pipe_resource_reference(&st->clear.vbuf, NULL);
- st->clear.vbuf = NULL;
- }
-}
-
-
-/**
- * Draw a screen-aligned quadrilateral.
- * Coords are clip coords with y=0=bottom.
- */
-static void
-draw_quad(struct st_context *st,
- float x0, float y0, float x1, float y1, GLfloat z,
- const GLfloat color[4])
-{
- struct pipe_context *pipe = st->pipe;
-
- /* XXX: Need to improve buffer_write to allow NO_WAIT (as well as
- * no_flush) updates to buffers where we know there is no conflict
- * with previous data. Currently using max_slots > 1 will cause
- * synchronous rendering if the driver flushes its command buffers
- * between one bitmap and the next. Our flush hook below isn't
- * sufficient to catch this as the driver doesn't tell us when it
- * flushes its own command buffers. Until this gets fixed, pay the
- * price of allocating a new buffer for each bitmap cache-flush to
- * avoid synchronous rendering.
- */
- const GLuint max_slots = 1; /* 1024 / sizeof(st->clear.vertices); */
- GLuint i;
-
- if (st->clear.vbuf_slot >= max_slots) {
- pipe_resource_reference(&st->clear.vbuf, NULL);
- st->clear.vbuf_slot = 0;
- }
-
- if (!st->clear.vbuf) {
- st->clear.vbuf = pipe_buffer_create(pipe->screen,
- PIPE_BIND_VERTEX_BUFFER,
- PIPE_USAGE_STREAM,
- max_slots * sizeof(st->clear.vertices));
- }
-
- /* positions */
- st->clear.vertices[0][0][0] = x0;
- st->clear.vertices[0][0][1] = y0;
-
- st->clear.vertices[1][0][0] = x1;
- st->clear.vertices[1][0][1] = y0;
-
- st->clear.vertices[2][0][0] = x1;
- st->clear.vertices[2][0][1] = y1;
-
- st->clear.vertices[3][0][0] = x0;
- st->clear.vertices[3][0][1] = y1;
-
- /* same for all verts: */
- for (i = 0; i < 4; i++) {
- st->clear.vertices[i][0][2] = z;
- st->clear.vertices[i][0][3] = 1.0;
- st->clear.vertices[i][1][0] = color[0];
- st->clear.vertices[i][1][1] = color[1];
- st->clear.vertices[i][1][2] = color[2];
- st->clear.vertices[i][1][3] = color[3];
- }
-
- /* put vertex data into vbuf */
- pipe_buffer_write_nooverlap(st->pipe, st->clear.vbuf,
- st->clear.vbuf_slot
- * sizeof(st->clear.vertices),
- sizeof(st->clear.vertices),
- st->clear.vertices);
-
- /* draw */
- util_draw_vertex_buffer(pipe,
- st->cso_context,
- st->clear.vbuf,
- st->clear.vbuf_slot * sizeof(st->clear.vertices),
- PIPE_PRIM_TRIANGLE_FAN,
- 4, /* verts */
- 2); /* attribs/vert */
-
- /* Increment slot */
- st->clear.vbuf_slot++;
-}
-
-
-
-/**
- * Do glClear by drawing a quadrilateral.
- * The vertices of the quad will be computed from the
- * ctx->DrawBuffer->_X/Ymin/max fields.
- */
-static void
-clear_with_quad(struct gl_context *ctx,
- GLboolean color, GLboolean depth, GLboolean stencil)
-{
- struct st_context *st = st_context(ctx);
- const struct gl_framebuffer *fb = ctx->DrawBuffer;
- const GLfloat fb_width = (GLfloat) fb->Width;
- const GLfloat fb_height = (GLfloat) fb->Height;
- const GLfloat x0 = (GLfloat) ctx->DrawBuffer->_Xmin / fb_width * 2.0f - 1.0f;
- const GLfloat x1 = (GLfloat) ctx->DrawBuffer->_Xmax / fb_width * 2.0f - 1.0f;
- const GLfloat y0 = (GLfloat) ctx->DrawBuffer->_Ymin / fb_height * 2.0f - 1.0f;
- const GLfloat y1 = (GLfloat) ctx->DrawBuffer->_Ymax / fb_height * 2.0f - 1.0f;
- float clearColor[4];
-
- /*
- printf("%s %s%s%s %f,%f %f,%f\n", __FUNCTION__,
- color ? "color, " : "",
- depth ? "depth, " : "",
- stencil ? "stencil" : "",
- x0, y0,
- x1, y1);
- */
-
- cso_save_blend(st->cso_context);
- cso_save_stencil_ref(st->cso_context);
- cso_save_depth_stencil_alpha(st->cso_context);
- cso_save_rasterizer(st->cso_context);
- cso_save_viewport(st->cso_context);
- cso_save_clip(st->cso_context);
- cso_save_fragment_shader(st->cso_context);
- cso_save_vertex_shader(st->cso_context);
- cso_save_vertex_elements(st->cso_context);
- cso_save_vertex_buffers(st->cso_context);
-
- /* blend state: RGBA masking */
- {
- struct pipe_blend_state blend;
- memset(&blend, 0, sizeof(blend));
- blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
- blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
- blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
- blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
- if (color) {
- if (ctx->Color.ColorMask[0][0])
- blend.rt[0].colormask |= PIPE_MASK_R;
- if (ctx->Color.ColorMask[0][1])
- blend.rt[0].colormask |= PIPE_MASK_G;
- if (ctx->Color.ColorMask[0][2])
- blend.rt[0].colormask |= PIPE_MASK_B;
- if (ctx->Color.ColorMask[0][3])
- blend.rt[0].colormask |= PIPE_MASK_A;
- if (st->ctx->Color.DitherFlag)
- blend.dither = 1;
- }
- cso_set_blend(st->cso_context, &blend);
- }
-
- /* depth_stencil state: always pass/set to ref value */
- {
- struct pipe_depth_stencil_alpha_state depth_stencil;
- memset(&depth_stencil, 0, sizeof(depth_stencil));
- if (depth) {
- depth_stencil.depth.enabled = 1;
- depth_stencil.depth.writemask = 1;
- depth_stencil.depth.func = PIPE_FUNC_ALWAYS;
- }
-
- if (stencil) {
- struct pipe_stencil_ref stencil_ref;
- memset(&stencil_ref, 0, sizeof(stencil_ref));
- depth_stencil.stencil[0].enabled = 1;
- depth_stencil.stencil[0].func = PIPE_FUNC_ALWAYS;
- depth_stencil.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
- depth_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
- depth_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
- depth_stencil.stencil[0].valuemask = 0xff;
- depth_stencil.stencil[0].writemask = ctx->Stencil.WriteMask[0] & 0xff;
- stencil_ref.ref_value[0] = ctx->Stencil.Clear;
- cso_set_stencil_ref(st->cso_context, &stencil_ref);
- }
-
- cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil);
- }
-
- cso_set_vertex_elements(st->cso_context, 2, st->velems_util_draw);
-
- cso_set_rasterizer(st->cso_context, &st->clear.raster);
-
- /* viewport state: viewport matching window dims */
- {
- const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP);
- struct pipe_viewport_state vp;
- vp.scale[0] = 0.5f * fb_width;
- vp.scale[1] = fb_height * (invert ? -0.5f : 0.5f);
- vp.scale[2] = 1.0f;
- vp.scale[3] = 1.0f;
- vp.translate[0] = 0.5f * fb_width;
- vp.translate[1] = 0.5f * fb_height;
- vp.translate[2] = 0.0f;
- vp.translate[3] = 0.0f;
- cso_set_viewport(st->cso_context, &vp);
- }
-
- cso_set_clip(st->cso_context, &st->clear.clip);
- cso_set_fragment_shader_handle(st->cso_context, st->clear.fs);
- cso_set_vertex_shader_handle(st->cso_context, st->clear.vs);
-
- if (ctx->DrawBuffer->_ColorDrawBuffers[0]) {
- st_translate_color(ctx->Color.ClearColor,
- ctx->DrawBuffer->_ColorDrawBuffers[0]->_BaseFormat,
- clearColor);
- }
-
- /* draw quad matching scissor rect */
- draw_quad(st, x0, y0, x1, y1, (GLfloat) ctx->Depth.Clear, clearColor);
-
- /* Restore pipe state */
- cso_restore_blend(st->cso_context);
- cso_restore_stencil_ref(st->cso_context);
- cso_restore_depth_stencil_alpha(st->cso_context);
- cso_restore_rasterizer(st->cso_context);
- cso_restore_viewport(st->cso_context);
- cso_restore_clip(st->cso_context);
- cso_restore_fragment_shader(st->cso_context);
- cso_restore_vertex_shader(st->cso_context);
- cso_restore_vertex_elements(st->cso_context);
- cso_restore_vertex_buffers(st->cso_context);
-}
-
-
-/**
- * Determine if we need to clear the depth buffer by drawing a quad.
- */
-static INLINE GLboolean
-check_clear_color_with_quad(struct gl_context *ctx, struct gl_renderbuffer *rb)
-{
- if (ctx->Scissor.Enabled &&
- (ctx->Scissor.X != 0 ||
- ctx->Scissor.Y != 0 ||
- ctx->Scissor.Width < rb->Width ||
- ctx->Scissor.Height < rb->Height))
- return GL_TRUE;
-
- if (!ctx->Color.ColorMask[0][0] ||
- !ctx->Color.ColorMask[0][1] ||
- !ctx->Color.ColorMask[0][2] ||
- !ctx->Color.ColorMask[0][3])
- return GL_TRUE;
-
- return GL_FALSE;
-}
-
-
-/**
- * Determine if we need to clear the combiend depth/stencil buffer by
- * drawing a quad.
- */
-static INLINE GLboolean
-check_clear_depth_stencil_with_quad(struct gl_context *ctx, struct gl_renderbuffer *rb)
-{
- const GLuint stencilMax = 0xff;
- GLboolean maskStencil
- = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
-
- assert(rb->Format == MESA_FORMAT_S8 ||
- rb->Format == MESA_FORMAT_Z24_S8 ||
- rb->Format == MESA_FORMAT_S8_Z24);
-
- if (ctx->Scissor.Enabled &&
- (ctx->Scissor.X != 0 ||
- ctx->Scissor.Y != 0 ||
- ctx->Scissor.Width < rb->Width ||
- ctx->Scissor.Height < rb->Height))
- return GL_TRUE;
-
- if (maskStencil)
- return GL_TRUE;
-
- return GL_FALSE;
-}
-
-
-/**
- * Determine if we need to clear the depth buffer by drawing a quad.
- */
-static INLINE GLboolean
-check_clear_depth_with_quad(struct gl_context *ctx, struct gl_renderbuffer *rb,
- boolean ds_separate)
-{
- const struct st_renderbuffer *strb = st_renderbuffer(rb);
- const GLboolean isDS = util_format_is_depth_and_stencil(strb->surface->format);
-
- if (ctx->Scissor.Enabled &&
- (ctx->Scissor.X != 0 ||
- ctx->Scissor.Y != 0 ||
- ctx->Scissor.Width < rb->Width ||
- ctx->Scissor.Height < rb->Height))
- return GL_TRUE;
-
- if (!ds_separate && isDS && ctx->DrawBuffer->Visual.stencilBits > 0)
- return GL_TRUE;
-
- return GL_FALSE;
-}
-
-
-/**
- * Determine if we need to clear the stencil buffer by drawing a quad.
- */
-static INLINE GLboolean
-check_clear_stencil_with_quad(struct gl_context *ctx, struct gl_renderbuffer *rb,
- boolean ds_separate)
-{
- const struct st_renderbuffer *strb = st_renderbuffer(rb);
- const GLboolean isDS = util_format_is_depth_and_stencil(strb->surface->format);
- const GLuint stencilMax = 0xff;
- const GLboolean maskStencil
- = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
-
- assert(rb->Format == MESA_FORMAT_S8 ||
- rb->Format == MESA_FORMAT_Z24_S8 ||
- rb->Format == MESA_FORMAT_S8_Z24);
-
- if (maskStencil)
- return GL_TRUE;
-
- if (ctx->Scissor.Enabled &&
- (ctx->Scissor.X != 0 ||
- ctx->Scissor.Y != 0 ||
- ctx->Scissor.Width < rb->Width ||
- ctx->Scissor.Height < rb->Height))
- return GL_TRUE;
-
- /* This is correct, but it is necessary to look at the depth clear
- * value held in the surface when it comes time to issue the clear,
- * rather than taking depth and stencil clear values from the
- * current state.
- */
- if (!ds_separate && isDS && ctx->DrawBuffer->Visual.depthBits > 0)
- return GL_TRUE;
-
- return GL_FALSE;
-}
-
-
-
-/**
- * Called when we need to flush.
- */
-void
-st_flush_clear(struct st_context *st)
-{
- /* Release vertex buffer to avoid synchronous rendering if we were
- * to map it in the next frame.
- */
- pipe_resource_reference(&st->clear.vbuf, NULL);
- st->clear.vbuf_slot = 0;
-}
-
-
-
-/**
- * Called via ctx->Driver.Clear()
- */
-static void
-st_Clear(struct gl_context *ctx, GLbitfield mask)
-{
- static const GLbitfield BUFFER_BITS_DS
- = (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL);
- struct st_context *st = st_context(ctx);
- struct gl_renderbuffer *depthRb
- = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
- struct gl_renderbuffer *stencilRb
- = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
- GLbitfield quad_buffers = 0x0;
- GLbitfield clear_buffers = 0x0;
- GLuint i;
-
- /* This makes sure the pipe has the latest scissor, etc values */
- st_validate_state( st );
-
- if (mask & BUFFER_BITS_COLOR) {
- for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
- GLuint b = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
-
- if (mask & (1 << b)) {
- struct gl_renderbuffer *rb
- = ctx->DrawBuffer->Attachment[b].Renderbuffer;
- struct st_renderbuffer *strb = st_renderbuffer(rb);
-
- if (!strb || !strb->surface)
- continue;
-
- if (check_clear_color_with_quad( ctx, rb ))
- quad_buffers |= PIPE_CLEAR_COLOR;
- else
- clear_buffers |= PIPE_CLEAR_COLOR;
- }
- }
- }
-
- if ((mask & BUFFER_BITS_DS) == BUFFER_BITS_DS && depthRb == stencilRb) {
- /* clearing combined depth + stencil */
- struct st_renderbuffer *strb = st_renderbuffer(depthRb);
-
- if (strb->surface) {
- if (check_clear_depth_stencil_with_quad(ctx, depthRb))
- quad_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
- else
- clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
- }
- }
- else {
- /* separate depth/stencil clears */
- /* I don't think truly separate buffers are actually possible in gallium or hw? */
- if (mask & BUFFER_BIT_DEPTH) {
- struct st_renderbuffer *strb = st_renderbuffer(depthRb);
-
- if (strb->surface) {
- if (check_clear_depth_with_quad(ctx, depthRb,
- st->clear.enable_ds_separate))
- quad_buffers |= PIPE_CLEAR_DEPTH;
- else
- clear_buffers |= PIPE_CLEAR_DEPTH;
- }
- }
- if (mask & BUFFER_BIT_STENCIL) {
- struct st_renderbuffer *strb = st_renderbuffer(stencilRb);
-
- if (strb->surface) {
- if (check_clear_stencil_with_quad(ctx, stencilRb,
- st->clear.enable_ds_separate))
- quad_buffers |= PIPE_CLEAR_STENCIL;
- else
- clear_buffers |= PIPE_CLEAR_STENCIL;
- }
- }
- }
-
- /*
- * If we're going to use clear_with_quad() for any reason, use it for
- * everything possible.
- */
- if (quad_buffers) {
- quad_buffers |= clear_buffers;
- clear_with_quad(ctx,
- quad_buffers & PIPE_CLEAR_COLOR,
- quad_buffers & PIPE_CLEAR_DEPTH,
- quad_buffers & PIPE_CLEAR_STENCIL);
- } else if (clear_buffers) {
- /* driver cannot know it can clear everything if the buffer
- * is a combined depth/stencil buffer but this wasn't actually
- * required from the visual. Hence fix this up to avoid potential
- * read-modify-write in the driver.
- */
- float clearColor[4];
-
- if ((clear_buffers & PIPE_CLEAR_DEPTHSTENCIL) &&
- ((clear_buffers & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) &&
- (depthRb == stencilRb) &&
- (ctx->DrawBuffer->Visual.depthBits == 0 ||
- ctx->DrawBuffer->Visual.stencilBits == 0))
- clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
-
- if (ctx->DrawBuffer->_ColorDrawBuffers[0]) {
- st_translate_color(ctx->Color.ClearColor,
- ctx->DrawBuffer->_ColorDrawBuffers[0]->_BaseFormat,
- clearColor);
- }
-
- st->pipe->clear(st->pipe, clear_buffers, ctx->Color.ClearColor,
- ctx->Depth.Clear, ctx->Stencil.Clear);
- }
- if (mask & BUFFER_BIT_ACCUM)
- st_clear_accum_buffer(ctx,
- ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
-}
-
-
-void
-st_init_clear_functions(struct dd_function_table *functions)
-{
- functions->Clear = st_Clear;
-}
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ * Copyright 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ * Michel Dänzer
+ */
+
+#include "main/glheader.h"
+#include "main/formats.h"
+#include "main/macros.h"
+#include "program/prog_instruction.h"
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_cb_accum.h"
+#include "st_cb_clear.h"
+#include "st_cb_fbo.h"
+#include "st_format.h"
+#include "st_program.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_shader_tokens.h"
+#include "pipe/p_state.h"
+#include "pipe/p_defines.h"
+#include "util/u_format.h"
+#include "util/u_inlines.h"
+#include "util/u_simple_shaders.h"
+#include "util/u_draw_quad.h"
+
+#include "cso_cache/cso_context.h"
+
+
+/**
+ * Do per-context initialization for glClear.
+ */
+void
+st_init_clear(struct st_context *st)
+{
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_screen *pscreen = st->pipe->screen;
+
+ memset(&st->clear, 0, sizeof(st->clear));
+
+ st->clear.raster.gl_rasterization_rules = 1;
+ st->clear.enable_ds_separate = pscreen->get_param(pscreen, PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE);
+
+ /* fragment shader state: color pass-through program */
+ st->clear.fs = util_make_fragment_passthrough_shader(pipe);
+
+ /* vertex shader state: color/position pass-through */
+ {
+ const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
+ TGSI_SEMANTIC_COLOR };
+ const uint semantic_indexes[] = { 0, 0 };
+ st->clear.vs = util_make_vertex_passthrough_shader(pipe, 2,
+ semantic_names,
+ semantic_indexes);
+ }
+}
+
+
+/**
+ * Free per-context state for glClear.
+ */
+void
+st_destroy_clear(struct st_context *st)
+{
+ if (st->clear.fs) {
+ cso_delete_fragment_shader(st->cso_context, st->clear.fs);
+ st->clear.fs = NULL;
+ }
+ if (st->clear.vs) {
+ cso_delete_vertex_shader(st->cso_context, st->clear.vs);
+ st->clear.vs = NULL;
+ }
+ if (st->clear.vbuf) {
+ pipe_resource_reference(&st->clear.vbuf, NULL);
+ st->clear.vbuf = NULL;
+ }
+}
+
+
+/**
+ * Draw a screen-aligned quadrilateral.
+ * Coords are clip coords with y=0=bottom.
+ */
+static void
+draw_quad(struct st_context *st,
+ float x0, float y0, float x1, float y1, GLfloat z,
+ const GLfloat color[4])
+{
+ struct pipe_context *pipe = st->pipe;
+
+ /* XXX: Need to improve buffer_write to allow NO_WAIT (as well as
+ * no_flush) updates to buffers where we know there is no conflict
+ * with previous data. Currently using max_slots > 1 will cause
+ * synchronous rendering if the driver flushes its command buffers
+ * between one bitmap and the next. Our flush hook below isn't
+ * sufficient to catch this as the driver doesn't tell us when it
+ * flushes its own command buffers. Until this gets fixed, pay the
+ * price of allocating a new buffer for each bitmap cache-flush to
+ * avoid synchronous rendering.
+ */
+ const GLuint max_slots = 1; /* 1024 / sizeof(st->clear.vertices); */
+ GLuint i;
+
+ if (st->clear.vbuf_slot >= max_slots) {
+ pipe_resource_reference(&st->clear.vbuf, NULL);
+ st->clear.vbuf_slot = 0;
+ }
+
+ if (!st->clear.vbuf) {
+ st->clear.vbuf = pipe_buffer_create(pipe->screen,
+ PIPE_BIND_VERTEX_BUFFER,
+ PIPE_USAGE_STREAM,
+ max_slots * sizeof(st->clear.vertices));
+ }
+
+ /* positions */
+ st->clear.vertices[0][0][0] = x0;
+ st->clear.vertices[0][0][1] = y0;
+
+ st->clear.vertices[1][0][0] = x1;
+ st->clear.vertices[1][0][1] = y0;
+
+ st->clear.vertices[2][0][0] = x1;
+ st->clear.vertices[2][0][1] = y1;
+
+ st->clear.vertices[3][0][0] = x0;
+ st->clear.vertices[3][0][1] = y1;
+
+ /* same for all verts: */
+ for (i = 0; i < 4; i++) {
+ st->clear.vertices[i][0][2] = z;
+ st->clear.vertices[i][0][3] = 1.0;
+ st->clear.vertices[i][1][0] = color[0];
+ st->clear.vertices[i][1][1] = color[1];
+ st->clear.vertices[i][1][2] = color[2];
+ st->clear.vertices[i][1][3] = color[3];
+ }
+
+ /* put vertex data into vbuf */
+ pipe_buffer_write_nooverlap(st->pipe, st->clear.vbuf,
+ st->clear.vbuf_slot
+ * sizeof(st->clear.vertices),
+ sizeof(st->clear.vertices),
+ st->clear.vertices);
+
+ /* draw */
+ util_draw_vertex_buffer(pipe,
+ st->cso_context,
+ st->clear.vbuf,
+ st->clear.vbuf_slot * sizeof(st->clear.vertices),
+ PIPE_PRIM_TRIANGLE_FAN,
+ 4, /* verts */
+ 2); /* attribs/vert */
+
+ /* Increment slot */
+ st->clear.vbuf_slot++;
+}
+
+
+
+/**
+ * Do glClear by drawing a quadrilateral.
+ * The vertices of the quad will be computed from the
+ * ctx->DrawBuffer->_X/Ymin/max fields.
+ */
+static void
+clear_with_quad(struct gl_context *ctx,
+ GLboolean color, GLboolean depth, GLboolean stencil)
+{
+ struct st_context *st = st_context(ctx);
+ const struct gl_framebuffer *fb = ctx->DrawBuffer;
+ const GLfloat fb_width = (GLfloat) fb->Width;
+ const GLfloat fb_height = (GLfloat) fb->Height;
+ const GLfloat x0 = (GLfloat) ctx->DrawBuffer->_Xmin / fb_width * 2.0f - 1.0f;
+ const GLfloat x1 = (GLfloat) ctx->DrawBuffer->_Xmax / fb_width * 2.0f - 1.0f;
+ const GLfloat y0 = (GLfloat) ctx->DrawBuffer->_Ymin / fb_height * 2.0f - 1.0f;
+ const GLfloat y1 = (GLfloat) ctx->DrawBuffer->_Ymax / fb_height * 2.0f - 1.0f;
+ float clearColor[4];
+
+ /*
+ printf("%s %s%s%s %f,%f %f,%f\n", __FUNCTION__,
+ color ? "color, " : "",
+ depth ? "depth, " : "",
+ stencil ? "stencil" : "",
+ x0, y0,
+ x1, y1);
+ */
+
+ cso_save_blend(st->cso_context);
+ cso_save_stencil_ref(st->cso_context);
+ cso_save_depth_stencil_alpha(st->cso_context);
+ cso_save_rasterizer(st->cso_context);
+ cso_save_viewport(st->cso_context);
+ cso_save_clip(st->cso_context);
+ cso_save_fragment_shader(st->cso_context);
+ cso_save_vertex_shader(st->cso_context);
+ cso_save_vertex_elements(st->cso_context);
+ cso_save_vertex_buffers(st->cso_context);
+
+ /* blend state: RGBA masking */
+ {
+ struct pipe_blend_state blend;
+ memset(&blend, 0, sizeof(blend));
+ blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
+ blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
+ blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
+ blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
+ if (color) {
+ if (ctx->Color.ColorMask[0][0])
+ blend.rt[0].colormask |= PIPE_MASK_R;
+ if (ctx->Color.ColorMask[0][1])
+ blend.rt[0].colormask |= PIPE_MASK_G;
+ if (ctx->Color.ColorMask[0][2])
+ blend.rt[0].colormask |= PIPE_MASK_B;
+ if (ctx->Color.ColorMask[0][3])
+ blend.rt[0].colormask |= PIPE_MASK_A;
+ if (st->ctx->Color.DitherFlag)
+ blend.dither = 1;
+ }
+ cso_set_blend(st->cso_context, &blend);
+ }
+
+ /* depth_stencil state: always pass/set to ref value */
+ {
+ struct pipe_depth_stencil_alpha_state depth_stencil;
+ memset(&depth_stencil, 0, sizeof(depth_stencil));
+ if (depth) {
+ depth_stencil.depth.enabled = 1;
+ depth_stencil.depth.writemask = 1;
+ depth_stencil.depth.func = PIPE_FUNC_ALWAYS;
+ }
+
+ if (stencil) {
+ struct pipe_stencil_ref stencil_ref;
+ memset(&stencil_ref, 0, sizeof(stencil_ref));
+ depth_stencil.stencil[0].enabled = 1;
+ depth_stencil.stencil[0].func = PIPE_FUNC_ALWAYS;
+ depth_stencil.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
+ depth_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
+ depth_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
+ depth_stencil.stencil[0].valuemask = 0xff;
+ depth_stencil.stencil[0].writemask = ctx->Stencil.WriteMask[0] & 0xff;
+ stencil_ref.ref_value[0] = ctx->Stencil.Clear;
+ cso_set_stencil_ref(st->cso_context, &stencil_ref);
+ }
+
+ cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil);
+ }
+
+ cso_set_vertex_elements(st->cso_context, 2, st->velems_util_draw);
+
+ cso_set_rasterizer(st->cso_context, &st->clear.raster);
+
+ /* viewport state: viewport matching window dims */
+ {
+ const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP);
+ struct pipe_viewport_state vp;
+ vp.scale[0] = 0.5f * fb_width;
+ vp.scale[1] = fb_height * (invert ? -0.5f : 0.5f);
+ vp.scale[2] = 1.0f;
+ vp.scale[3] = 1.0f;
+ vp.translate[0] = 0.5f * fb_width;
+ vp.translate[1] = 0.5f * fb_height;
+ vp.translate[2] = 0.0f;
+ vp.translate[3] = 0.0f;
+ cso_set_viewport(st->cso_context, &vp);
+ }
+
+ cso_set_clip(st->cso_context, &st->clear.clip);
+ cso_set_fragment_shader_handle(st->cso_context, st->clear.fs);
+ cso_set_vertex_shader_handle(st->cso_context, st->clear.vs);
+
+ if (ctx->DrawBuffer->_ColorDrawBuffers[0]) {
+ st_translate_color(ctx->Color.ClearColor,
+ ctx->DrawBuffer->_ColorDrawBuffers[0]->_BaseFormat,
+ clearColor);
+ }
+
+ /* draw quad matching scissor rect */
+ draw_quad(st, x0, y0, x1, y1, (GLfloat) ctx->Depth.Clear, clearColor);
+
+ /* Restore pipe state */
+ cso_restore_blend(st->cso_context);
+ cso_restore_stencil_ref(st->cso_context);
+ cso_restore_depth_stencil_alpha(st->cso_context);
+ cso_restore_rasterizer(st->cso_context);
+ cso_restore_viewport(st->cso_context);
+ cso_restore_clip(st->cso_context);
+ cso_restore_fragment_shader(st->cso_context);
+ cso_restore_vertex_shader(st->cso_context);
+ cso_restore_vertex_elements(st->cso_context);
+ cso_restore_vertex_buffers(st->cso_context);
+}
+
+
+/**
+ * Determine if we need to clear the depth buffer by drawing a quad.
+ */
+static INLINE GLboolean
+check_clear_color_with_quad(struct gl_context *ctx, struct gl_renderbuffer *rb)
+{
+ if (ctx->Scissor.Enabled &&
+ (ctx->Scissor.X != 0 ||
+ ctx->Scissor.Y != 0 ||
+ ctx->Scissor.Width < rb->Width ||
+ ctx->Scissor.Height < rb->Height))
+ return GL_TRUE;
+
+ if (!ctx->Color.ColorMask[0][0] ||
+ !ctx->Color.ColorMask[0][1] ||
+ !ctx->Color.ColorMask[0][2] ||
+ !ctx->Color.ColorMask[0][3])
+ return GL_TRUE;
+
+ return GL_FALSE;
+}
+
+
+/**
+ * Determine if we need to clear the combiend depth/stencil buffer by
+ * drawing a quad.
+ */
+static INLINE GLboolean
+check_clear_depth_stencil_with_quad(struct gl_context *ctx, struct gl_renderbuffer *rb)
+{
+ const GLuint stencilMax = 0xff;
+ GLboolean maskStencil
+ = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
+
+ assert(rb->Format == MESA_FORMAT_S8 ||
+ rb->Format == MESA_FORMAT_Z24_S8 ||
+ rb->Format == MESA_FORMAT_S8_Z24);
+
+ if (ctx->Scissor.Enabled &&
+ (ctx->Scissor.X != 0 ||
+ ctx->Scissor.Y != 0 ||
+ ctx->Scissor.Width < rb->Width ||
+ ctx->Scissor.Height < rb->Height))
+ return GL_TRUE;
+
+ if (maskStencil)
+ return GL_TRUE;
+
+ return GL_FALSE;
+}
+
+
+/**
+ * Determine if we need to clear the depth buffer by drawing a quad.
+ */
+static INLINE GLboolean
+check_clear_depth_with_quad(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ boolean ds_separate)
+{
+ const struct st_renderbuffer *strb = st_renderbuffer(rb);
+ const GLboolean isDS = util_format_is_depth_and_stencil(strb->surface->format);
+
+ if (ctx->Scissor.Enabled &&
+ (ctx->Scissor.X != 0 ||
+ ctx->Scissor.Y != 0 ||
+ ctx->Scissor.Width < rb->Width ||
+ ctx->Scissor.Height < rb->Height))
+ return GL_TRUE;
+
+ if (!ds_separate && isDS && ctx->DrawBuffer->Visual.stencilBits > 0)
+ return GL_TRUE;
+
+ return GL_FALSE;
+}
+
+
+/**
+ * Determine if we need to clear the stencil buffer by drawing a quad.
+ */
+static INLINE GLboolean
+check_clear_stencil_with_quad(struct gl_context *ctx, struct gl_renderbuffer *rb,
+ boolean ds_separate)
+{
+ const struct st_renderbuffer *strb = st_renderbuffer(rb);
+ const GLboolean isDS = util_format_is_depth_and_stencil(strb->surface->format);
+ const GLuint stencilMax = 0xff;
+ const GLboolean maskStencil
+ = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
+
+ assert(rb->Format == MESA_FORMAT_S8 ||
+ rb->Format == MESA_FORMAT_Z24_S8 ||
+ rb->Format == MESA_FORMAT_S8_Z24);
+
+ if (maskStencil)
+ return GL_TRUE;
+
+ if (ctx->Scissor.Enabled &&
+ (ctx->Scissor.X != 0 ||
+ ctx->Scissor.Y != 0 ||
+ ctx->Scissor.Width < rb->Width ||
+ ctx->Scissor.Height < rb->Height))
+ return GL_TRUE;
+
+ /* This is correct, but it is necessary to look at the depth clear
+ * value held in the surface when it comes time to issue the clear,
+ * rather than taking depth and stencil clear values from the
+ * current state.
+ */
+ if (!ds_separate && isDS && ctx->DrawBuffer->Visual.depthBits > 0)
+ return GL_TRUE;
+
+ return GL_FALSE;
+}
+
+
+
+/**
+ * Called when we need to flush.
+ */
+void
+st_flush_clear(struct st_context *st)
+{
+ /* Release vertex buffer to avoid synchronous rendering if we were
+ * to map it in the next frame.
+ */
+ pipe_resource_reference(&st->clear.vbuf, NULL);
+ st->clear.vbuf_slot = 0;
+}
+
+
+
+/**
+ * Called via ctx->Driver.Clear()
+ */
+static void
+st_Clear(struct gl_context *ctx, GLbitfield mask)
+{
+ static const GLbitfield BUFFER_BITS_DS
+ = (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL);
+ struct st_context *st = st_context(ctx);
+ struct gl_renderbuffer *depthRb
+ = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+ struct gl_renderbuffer *stencilRb
+ = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
+ GLbitfield quad_buffers = 0x0;
+ GLbitfield clear_buffers = 0x0;
+ GLuint i;
+
+ /* This makes sure the pipe has the latest scissor, etc values */
+ st_validate_state( st );
+
+ if (mask & BUFFER_BITS_COLOR) {
+ for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
+ GLuint b = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
+
+ if (mask & (1 << b)) {
+ struct gl_renderbuffer *rb
+ = ctx->DrawBuffer->Attachment[b].Renderbuffer;
+ struct st_renderbuffer *strb = st_renderbuffer(rb);
+
+ if (!strb || !strb->surface)
+ continue;
+
+ if (check_clear_color_with_quad( ctx, rb ))
+ quad_buffers |= PIPE_CLEAR_COLOR;
+ else
+ clear_buffers |= PIPE_CLEAR_COLOR;
+ }
+ }
+ }
+
+ if ((mask & BUFFER_BITS_DS) == BUFFER_BITS_DS && depthRb == stencilRb) {
+ /* clearing combined depth + stencil */
+ struct st_renderbuffer *strb = st_renderbuffer(depthRb);
+
+ if (strb->surface) {
+ if (check_clear_depth_stencil_with_quad(ctx, depthRb))
+ quad_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
+ else
+ clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
+ }
+ }
+ else {
+ /* separate depth/stencil clears */
+ /* I don't think truly separate buffers are actually possible in gallium or hw? */
+ if (mask & BUFFER_BIT_DEPTH) {
+ struct st_renderbuffer *strb = st_renderbuffer(depthRb);
+
+ if (strb->surface) {
+ if (check_clear_depth_with_quad(ctx, depthRb,
+ st->clear.enable_ds_separate))
+ quad_buffers |= PIPE_CLEAR_DEPTH;
+ else
+ clear_buffers |= PIPE_CLEAR_DEPTH;
+ }
+ }
+ if (mask & BUFFER_BIT_STENCIL) {
+ struct st_renderbuffer *strb = st_renderbuffer(stencilRb);
+
+ if (strb->surface) {
+ if (check_clear_stencil_with_quad(ctx, stencilRb,
+ st->clear.enable_ds_separate))
+ quad_buffers |= PIPE_CLEAR_STENCIL;
+ else
+ clear_buffers |= PIPE_CLEAR_STENCIL;
+ }
+ }
+ }
+
+ /*
+ * If we're going to use clear_with_quad() for any reason, use it for
+ * everything possible.
+ */
+ if (quad_buffers) {
+ quad_buffers |= clear_buffers;
+ clear_with_quad(ctx,
+ quad_buffers & PIPE_CLEAR_COLOR,
+ quad_buffers & PIPE_CLEAR_DEPTH,
+ quad_buffers & PIPE_CLEAR_STENCIL);
+ } else if (clear_buffers) {
+ /* driver cannot know it can clear everything if the buffer
+ * is a combined depth/stencil buffer but this wasn't actually
+ * required from the visual. Hence fix this up to avoid potential
+ * read-modify-write in the driver.
+ */
+ float clearColor[4];
+
+ if ((clear_buffers & PIPE_CLEAR_DEPTHSTENCIL) &&
+ ((clear_buffers & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) &&
+ (depthRb == stencilRb) &&
+ (ctx->DrawBuffer->Visual.depthBits == 0 ||
+ ctx->DrawBuffer->Visual.stencilBits == 0))
+ clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
+
+ if (ctx->DrawBuffer->_ColorDrawBuffers[0]) {
+ st_translate_color(ctx->Color.ClearColor,
+ ctx->DrawBuffer->_ColorDrawBuffers[0]->_BaseFormat,
+ clearColor);
+ }
+
+ st->pipe->clear(st->pipe, clear_buffers, ctx->Color.ClearColor,
+ ctx->Depth.Clear, ctx->Stencil.Clear);
+ }
+ if (mask & BUFFER_BIT_ACCUM)
+ st_clear_accum_buffer(ctx,
+ ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
+}
+
+
+void
+st_init_clear_functions(struct dd_function_table *functions)
+{
+ functions->Clear = st_Clear;
+}
diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
index c2b4e1808..c5950304f 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -1,1488 +1,1488 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
- /*
- * Authors:
- * Brian Paul
- */
-
-#include "main/imports.h"
-#include "main/image.h"
-#include "main/bufferobj.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-#include "main/mtypes.h"
-#include "main/pack.h"
-#include "main/pbo.h"
-#include "main/texformat.h"
-#include "main/texstore.h"
-#include "program/program.h"
-#include "program/prog_print.h"
-#include "program/prog_instruction.h"
-
-#include "st_atom.h"
-#include "st_atom_constbuf.h"
-#include "st_cb_drawpixels.h"
-#include "st_cb_readpixels.h"
-#include "st_cb_fbo.h"
-#include "st_context.h"
-#include "st_debug.h"
-#include "st_format.h"
-#include "st_program.h"
-#include "st_texture.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "tgsi/tgsi_ureg.h"
-#include "util/u_draw_quad.h"
-#include "util/u_format.h"
-#include "util/u_inlines.h"
-#include "util/u_math.h"
-#include "util/u_tile.h"
-#include "cso_cache/cso_context.h"
-
-
-#if FEATURE_drawpix
-
-/**
- * Check if the given program is:
- * 0: MOVE result.color, fragment.color;
- * 1: END;
- */
-static GLboolean
-is_passthrough_program(const struct gl_fragment_program *prog)
-{
- if (prog->Base.NumInstructions == 2) {
- const struct prog_instruction *inst = prog->Base.Instructions;
- if (inst[0].Opcode == OPCODE_MOV &&
- inst[1].Opcode == OPCODE_END &&
- inst[0].DstReg.File == PROGRAM_OUTPUT &&
- inst[0].DstReg.Index == FRAG_RESULT_COLOR &&
- inst[0].DstReg.WriteMask == WRITEMASK_XYZW &&
- inst[0].SrcReg[0].File == PROGRAM_INPUT &&
- inst[0].SrcReg[0].Index == FRAG_ATTRIB_COL0 &&
- inst[0].SrcReg[0].Swizzle == SWIZZLE_XYZW) {
- return GL_TRUE;
- }
- }
- return GL_FALSE;
-}
-
-
-
-/**
- * Make fragment shader for glDraw/CopyPixels. This shader is made
- * by combining the pixel transfer shader with the user-defined shader.
- * \param fpIn the current/incoming fragment program
- * \param fpOut returns the combined fragment program
- */
-void
-st_make_drawpix_fragment_program(struct st_context *st,
- struct gl_fragment_program *fpIn,
- struct gl_fragment_program **fpOut)
-{
- struct gl_program *newProg;
-
- if (is_passthrough_program(fpIn)) {
- newProg = (struct gl_program *) _mesa_clone_fragment_program(st->ctx,
- &st->pixel_xfer.program->Base);
- }
- else {
-#if 0
- /* debug */
- printf("Base program:\n");
- _mesa_print_program(&fpIn->Base);
- printf("DrawPix program:\n");
- _mesa_print_program(&st->pixel_xfer.program->Base.Base);
-#endif
- newProg = _mesa_combine_programs(st->ctx,
- &st->pixel_xfer.program->Base.Base,
- &fpIn->Base);
- }
-
-#if 0
- /* debug */
- printf("Combined DrawPixels program:\n");
- _mesa_print_program(newProg);
- printf("InputsRead: 0x%x\n", newProg->InputsRead);
- printf("OutputsWritten: 0x%x\n", newProg->OutputsWritten);
- _mesa_print_parameter_list(newProg->Parameters);
-#endif
-
- *fpOut = (struct gl_fragment_program *) newProg;
-}
-
-
-/**
- * Create fragment program that does a TEX() instruction to get a Z and/or
- * stencil value value, then writes to FRAG_RESULT_DEPTH/FRAG_RESULT_STENCIL.
- * Used for glDrawPixels(GL_DEPTH_COMPONENT / GL_STENCIL_INDEX).
- * Pass fragment color through as-is.
- * \return pointer to the gl_fragment program
- */
-struct gl_fragment_program *
-st_make_drawpix_z_stencil_program(struct st_context *st,
- GLboolean write_depth,
- GLboolean write_stencil)
-{
- struct gl_context *ctx = st->ctx;
- struct gl_program *p;
- struct gl_fragment_program *fp;
- GLuint ic = 0;
- const GLuint shaderIndex = write_depth * 2 + write_stencil;
-
- assert(shaderIndex < Elements(st->drawpix.shaders));
-
- if (st->drawpix.shaders[shaderIndex]) {
- /* already have the proper shader */
- return st->drawpix.shaders[shaderIndex];
- }
-
- /*
- * Create shader now
- */
- p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
- if (!p)
- return NULL;
-
- p->NumInstructions = write_depth ? 2 : 1;
- p->NumInstructions += write_stencil ? 1 : 0;
-
- p->Instructions = _mesa_alloc_instructions(p->NumInstructions);
- if (!p->Instructions) {
- ctx->Driver.DeleteProgram(ctx, p);
- return NULL;
- }
- _mesa_init_instructions(p->Instructions, p->NumInstructions);
-
- if (write_depth) {
- /* TEX result.depth, fragment.texcoord[0], texture[0], 2D; */
- p->Instructions[ic].Opcode = OPCODE_TEX;
- p->Instructions[ic].DstReg.File = PROGRAM_OUTPUT;
- p->Instructions[ic].DstReg.Index = FRAG_RESULT_DEPTH;
- p->Instructions[ic].DstReg.WriteMask = WRITEMASK_Z;
- p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT;
- p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0;
- p->Instructions[ic].TexSrcUnit = 0;
- p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX;
- ic++;
- }
-
- if (write_stencil) {
- /* TEX result.stencil, fragment.texcoord[0], texture[0], 2D; */
- p->Instructions[ic].Opcode = OPCODE_TEX;
- p->Instructions[ic].DstReg.File = PROGRAM_OUTPUT;
- p->Instructions[ic].DstReg.Index = FRAG_RESULT_STENCIL;
- p->Instructions[ic].DstReg.WriteMask = WRITEMASK_Y;
- p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT;
- p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0;
- p->Instructions[ic].TexSrcUnit = 1;
- p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX;
- ic++;
- }
-
- /* END; */
- p->Instructions[ic++].Opcode = OPCODE_END;
-
- assert(ic == p->NumInstructions);
-
- p->InputsRead = FRAG_BIT_TEX0 | FRAG_BIT_COL0;
- p->OutputsWritten = 0;
- if (write_depth)
- p->OutputsWritten |= (1 << FRAG_RESULT_DEPTH);
- if (write_stencil)
- p->OutputsWritten |= (1 << FRAG_RESULT_STENCIL);
-
- p->SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */
- if (write_stencil)
- p->SamplersUsed |= 1 << 1;
-
- fp = (struct gl_fragment_program *) p;
-
- /* save the new shader */
- st->drawpix.shaders[shaderIndex] = fp;
-
- return fp;
-}
-
-
-/**
- * Create a simple vertex shader that just passes through the
- * vertex position and texcoord (and optionally, color).
- */
-static void *
-make_passthrough_vertex_shader(struct st_context *st,
- GLboolean passColor)
-{
- if (!st->drawpix.vert_shaders[passColor]) {
- struct ureg_program *ureg = ureg_create( TGSI_PROCESSOR_VERTEX );
-
- if (ureg == NULL)
- return NULL;
-
- /* MOV result.pos, vertex.pos; */
- ureg_MOV(ureg,
- ureg_DECL_output( ureg, TGSI_SEMANTIC_POSITION, 0 ),
- ureg_DECL_vs_input( ureg, 0 ));
-
- /* MOV result.texcoord0, vertex.attr[1]; */
- ureg_MOV(ureg,
- ureg_DECL_output( ureg, TGSI_SEMANTIC_GENERIC, 0 ),
- ureg_DECL_vs_input( ureg, 1 ));
-
- if (passColor) {
- /* MOV result.color0, vertex.attr[2]; */
- ureg_MOV(ureg,
- ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, 0 ),
- ureg_DECL_vs_input( ureg, 2 ));
- }
-
- ureg_END( ureg );
-
- st->drawpix.vert_shaders[passColor] =
- ureg_create_shader_and_destroy( ureg, st->pipe );
- }
-
- return st->drawpix.vert_shaders[passColor];
-}
-
-
-/**
- * Return a texture base format for drawing/copying an image
- * of the given format.
- */
-static GLenum
-base_format(GLenum format)
-{
- switch (format) {
- case GL_DEPTH_COMPONENT:
- return GL_DEPTH_COMPONENT;
- case GL_DEPTH_STENCIL:
- return GL_DEPTH_STENCIL;
- case GL_STENCIL_INDEX:
- return GL_STENCIL_INDEX;
- default:
- return GL_RGBA;
- }
-}
-
-
-/**
- * Return a texture internalFormat for drawing/copying an image
- * of the given format and type.
- */
-static GLenum
-internal_format(GLenum format, GLenum type)
-{
- switch (format) {
- case GL_DEPTH_COMPONENT:
- return GL_DEPTH_COMPONENT;
- case GL_DEPTH_STENCIL:
- return GL_DEPTH_STENCIL;
- case GL_STENCIL_INDEX:
- return GL_STENCIL_INDEX;
- default:
- if (_mesa_is_integer_format(format)) {
- switch (type) {
- case GL_BYTE:
- return GL_RGBA8I;
- case GL_UNSIGNED_BYTE:
- return GL_RGBA8UI;
- case GL_SHORT:
- return GL_RGBA16I;
- case GL_UNSIGNED_SHORT:
- return GL_RGBA16UI;
- case GL_INT:
- return GL_RGBA32I;
- case GL_UNSIGNED_INT:
- return GL_RGBA32UI;
- default:
- assert(0 && "Unexpected type in internal_format()");
- return GL_RGBA_INTEGER;
- }
- }
- else {
- return GL_RGBA;
- }
- }
-}
-
-
-/**
- * Create a temporary texture to hold an image of the given size.
- * If width, height are not POT and the driver only handles POT textures,
- * allocate the next larger size of texture that is POT.
- */
-static struct pipe_resource *
-alloc_texture(struct st_context *st, GLsizei width, GLsizei height,
- enum pipe_format texFormat)
-{
- struct pipe_resource *pt;
-
- pt = st_texture_create(st, st->internal_target, texFormat, 0,
- width, height, 1, 1, PIPE_BIND_SAMPLER_VIEW);
-
- return pt;
-}
-
-
-/**
- * Make texture containing an image for glDrawPixels image.
- * If 'pixels' is NULL, leave the texture image data undefined.
- */
-static struct pipe_resource *
-make_texture(struct st_context *st,
- GLsizei width, GLsizei height, GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels)
-{
- struct gl_context *ctx = st->ctx;
- struct pipe_context *pipe = st->pipe;
- gl_format mformat;
- struct pipe_resource *pt;
- enum pipe_format pipeFormat;
- GLuint cpp;
- GLenum baseFormat, intFormat;
-
- baseFormat = base_format(format);
- intFormat = internal_format(format, type);
-
- mformat = st_ChooseTextureFormat_renderable(ctx, intFormat,
- format, type, GL_FALSE);
- assert(mformat);
-
- pipeFormat = st_mesa_format_to_pipe_format(mformat);
- assert(pipeFormat);
- cpp = util_format_get_blocksize(pipeFormat);
-
- pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
- if (!pixels)
- return NULL;
-
- /* alloc temporary texture */
- pt = alloc_texture(st, width, height, pipeFormat);
- if (!pt) {
- _mesa_unmap_pbo_source(ctx, unpack);
- return NULL;
- }
-
- {
- struct pipe_transfer *transfer;
- static const GLuint dstImageOffsets = 0;
- GLboolean success;
- GLubyte *dest;
- const GLbitfield imageTransferStateSave = ctx->_ImageTransferState;
-
- /* we'll do pixel transfer in a fragment shader */
- ctx->_ImageTransferState = 0x0;
-
- transfer = pipe_get_transfer(st->pipe, pt, 0, 0,
- PIPE_TRANSFER_WRITE, 0, 0,
- width, height);
-
- /* map texture transfer */
- dest = pipe_transfer_map(pipe, transfer);
-
-
- /* Put image into texture transfer.
- * Note that the image is actually going to be upside down in
- * the texture. We deal with that with texcoords.
- */
- success = _mesa_texstore(ctx, 2, /* dims */
- baseFormat, /* baseInternalFormat */
- mformat, /* gl_format */
- dest, /* dest */
- 0, 0, 0, /* dstX/Y/Zoffset */
- transfer->stride, /* dstRowStride, bytes */
- &dstImageOffsets, /* dstImageOffsets */
- width, height, 1, /* size */
- format, type, /* src format/type */
- pixels, /* data source */
- unpack);
-
- /* unmap */
- pipe_transfer_unmap(pipe, transfer);
- pipe->transfer_destroy(pipe, transfer);
-
- assert(success);
-
- /* restore */
- ctx->_ImageTransferState = imageTransferStateSave;
- }
-
- _mesa_unmap_pbo_source(ctx, unpack);
-
- return pt;
-}
-
-
-/**
- * Draw quad with texcoords and optional color.
- * Coords are gallium window coords with y=0=top.
- * \param color may be null
- * \param invertTex if true, flip texcoords vertically
- */
-static void
-draw_quad(struct gl_context *ctx, GLfloat x0, GLfloat y0, GLfloat z,
- GLfloat x1, GLfloat y1, const GLfloat *color,
- GLboolean invertTex, GLfloat maxXcoord, GLfloat maxYcoord)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- GLfloat verts[4][3][4]; /* four verts, three attribs, XYZW */
-
- /* setup vertex data */
- {
- const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
- const GLfloat fb_width = (GLfloat) fb->Width;
- const GLfloat fb_height = (GLfloat) fb->Height;
- const GLfloat clip_x0 = x0 / fb_width * 2.0f - 1.0f;
- const GLfloat clip_y0 = y0 / fb_height * 2.0f - 1.0f;
- const GLfloat clip_x1 = x1 / fb_width * 2.0f - 1.0f;
- const GLfloat clip_y1 = y1 / fb_height * 2.0f - 1.0f;
- const GLfloat sLeft = 0.0f, sRight = maxXcoord;
- const GLfloat tTop = invertTex ? maxYcoord : 0.0f;
- const GLfloat tBot = invertTex ? 0.0f : maxYcoord;
- GLuint i;
-
- /* upper-left */
- verts[0][0][0] = clip_x0; /* v[0].attr[0].x */
- verts[0][0][1] = clip_y0; /* v[0].attr[0].y */
-
- /* upper-right */
- verts[1][0][0] = clip_x1;
- verts[1][0][1] = clip_y0;
-
- /* lower-right */
- verts[2][0][0] = clip_x1;
- verts[2][0][1] = clip_y1;
-
- /* lower-left */
- verts[3][0][0] = clip_x0;
- verts[3][0][1] = clip_y1;
-
- verts[0][1][0] = sLeft; /* v[0].attr[1].S */
- verts[0][1][1] = tTop; /* v[0].attr[1].T */
- verts[1][1][0] = sRight;
- verts[1][1][1] = tTop;
- verts[2][1][0] = sRight;
- verts[2][1][1] = tBot;
- verts[3][1][0] = sLeft;
- verts[3][1][1] = tBot;
-
- /* same for all verts: */
- if (color) {
- for (i = 0; i < 4; i++) {
- verts[i][0][2] = z; /* v[i].attr[0].z */
- verts[i][0][3] = 1.0f; /* v[i].attr[0].w */
- verts[i][2][0] = color[0]; /* v[i].attr[2].r */
- verts[i][2][1] = color[1]; /* v[i].attr[2].g */
- verts[i][2][2] = color[2]; /* v[i].attr[2].b */
- verts[i][2][3] = color[3]; /* v[i].attr[2].a */
- verts[i][1][2] = 0.0f; /* v[i].attr[1].R */
- verts[i][1][3] = 1.0f; /* v[i].attr[1].Q */
- }
- }
- else {
- for (i = 0; i < 4; i++) {
- verts[i][0][2] = z; /*Z*/
- verts[i][0][3] = 1.0f; /*W*/
- verts[i][1][2] = 0.0f; /*R*/
- verts[i][1][3] = 1.0f; /*Q*/
- }
- }
- }
-
- {
- struct pipe_resource *buf;
-
- /* allocate/load buffer object with vertex data */
- buf = pipe_buffer_create(pipe->screen,
- PIPE_BIND_VERTEX_BUFFER,
- PIPE_USAGE_STATIC,
- sizeof(verts));
- pipe_buffer_write(st->pipe, buf, 0, sizeof(verts), verts);
-
- util_draw_vertex_buffer(pipe, st->cso_context, buf, 0,
- PIPE_PRIM_QUADS,
- 4, /* verts */
- 3); /* attribs/vert */
- pipe_resource_reference(&buf, NULL);
- }
-}
-
-
-
-static void
-draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
- GLsizei width, GLsizei height,
- GLfloat zoomX, GLfloat zoomY,
- struct pipe_sampler_view **sv,
- int num_sampler_view,
- void *driver_vp,
- void *driver_fp,
- const GLfloat *color,
- GLboolean invertTex,
- GLboolean write_depth, GLboolean write_stencil)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct cso_context *cso = st->cso_context;
- GLfloat x0, y0, x1, y1;
- GLsizei maxSize;
- boolean normalized = sv[0]->texture->target != PIPE_TEXTURE_RECT;
-
- /* limit checks */
- /* XXX if DrawPixels image is larger than max texture size, break
- * it up into chunks.
- */
- maxSize = 1 << (pipe->screen->get_param(pipe->screen,
- PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
- assert(width <= maxSize);
- assert(height <= maxSize);
-
- cso_save_rasterizer(cso);
- cso_save_viewport(cso);
- cso_save_samplers(cso);
- cso_save_fragment_sampler_views(cso);
- cso_save_fragment_shader(cso);
- cso_save_vertex_shader(cso);
- cso_save_vertex_elements(cso);
- cso_save_vertex_buffers(cso);
- if (write_stencil) {
- cso_save_depth_stencil_alpha(cso);
- cso_save_blend(cso);
- }
-
- /* rasterizer state: just scissor */
- {
- struct pipe_rasterizer_state rasterizer;
- memset(&rasterizer, 0, sizeof(rasterizer));
- rasterizer.gl_rasterization_rules = 1;
- rasterizer.scissor = ctx->Scissor.Enabled;
- cso_set_rasterizer(cso, &rasterizer);
- }
-
- if (write_stencil) {
- /* Stencil writing bypasses the normal fragment pipeline to
- * disable color writing and set stencil test to always pass.
- */
- struct pipe_depth_stencil_alpha_state dsa;
- struct pipe_blend_state blend;
-
- /* depth/stencil */
- memset(&dsa, 0, sizeof(dsa));
- dsa.stencil[0].enabled = 1;
- dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
- dsa.stencil[0].writemask = ctx->Stencil.WriteMask[0] & 0xff;
- dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
- if (write_depth) {
- /* writing depth+stencil: depth test always passes */
- dsa.depth.enabled = 1;
- dsa.depth.writemask = ctx->Depth.Mask;
- dsa.depth.func = PIPE_FUNC_ALWAYS;
- }
- cso_set_depth_stencil_alpha(cso, &dsa);
-
- /* blend (colormask) */
- memset(&blend, 0, sizeof(blend));
- cso_set_blend(cso, &blend);
- }
-
- /* fragment shader state: TEX lookup program */
- cso_set_fragment_shader_handle(cso, driver_fp);
-
- /* vertex shader state: position + texcoord pass-through */
- cso_set_vertex_shader_handle(cso, driver_vp);
-
-
- /* texture sampling state: */
- {
- struct pipe_sampler_state sampler;
- memset(&sampler, 0, sizeof(sampler));
- sampler.wrap_s = PIPE_TEX_WRAP_CLAMP;
- sampler.wrap_t = PIPE_TEX_WRAP_CLAMP;
- sampler.wrap_r = PIPE_TEX_WRAP_CLAMP;
- sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST;
- sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
- sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
- sampler.normalized_coords = normalized;
-
- cso_single_sampler(cso, 0, &sampler);
- if (num_sampler_view > 1) {
- cso_single_sampler(cso, 1, &sampler);
- }
- cso_single_sampler_done(cso);
- }
-
- /* viewport state: viewport matching window dims */
- {
- const float w = (float) ctx->DrawBuffer->Width;
- const float h = (float) ctx->DrawBuffer->Height;
- struct pipe_viewport_state vp;
- vp.scale[0] = 0.5f * w;
- vp.scale[1] = -0.5f * h;
- vp.scale[2] = 0.5f;
- vp.scale[3] = 1.0f;
- vp.translate[0] = 0.5f * w;
- vp.translate[1] = 0.5f * h;
- vp.translate[2] = 0.5f;
- vp.translate[3] = 0.0f;
- cso_set_viewport(cso, &vp);
- }
-
- cso_set_vertex_elements(cso, 3, st->velems_util_draw);
-
- /* texture state: */
- cso_set_fragment_sampler_views(cso, num_sampler_view, sv);
-
- /* Compute Gallium window coords (y=0=top) with pixel zoom.
- * Recall that these coords are transformed by the current
- * vertex shader and viewport transformation.
- */
- if (st_fb_orientation(ctx->DrawBuffer) == Y_0_BOTTOM) {
- y = ctx->DrawBuffer->Height - (int) (y + height * ctx->Pixel.ZoomY);
- invertTex = !invertTex;
- }
-
- x0 = (GLfloat) x;
- x1 = x + width * ctx->Pixel.ZoomX;
- y0 = (GLfloat) y;
- y1 = y + height * ctx->Pixel.ZoomY;
-
- /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
- z = z * 2.0 - 1.0;
-
- draw_quad(ctx, x0, y0, z, x1, y1, color, invertTex,
- normalized ? ((GLfloat) width / sv[0]->texture->width0) : (GLfloat)width,
- normalized ? ((GLfloat) height / sv[0]->texture->height0) : (GLfloat)height);
-
- /* restore state */
- cso_restore_rasterizer(cso);
- cso_restore_viewport(cso);
- cso_restore_samplers(cso);
- cso_restore_fragment_sampler_views(cso);
- cso_restore_fragment_shader(cso);
- cso_restore_vertex_shader(cso);
- cso_restore_vertex_elements(cso);
- cso_restore_vertex_buffers(cso);
- if (write_stencil) {
- cso_restore_depth_stencil_alpha(cso);
- cso_restore_blend(cso);
- }
-}
-
-
-/**
- * Software fallback to do glDrawPixels(GL_STENCIL_INDEX) when we
- * can't use a fragment shader to write stencil values.
- */
-static void
-draw_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height, GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct st_renderbuffer *strb;
- enum pipe_transfer_usage usage;
- struct pipe_transfer *pt;
- const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
- GLint skipPixels;
- ubyte *stmap;
- struct gl_pixelstore_attrib clippedUnpack = *unpack;
-
- if (!zoom) {
- if (!_mesa_clip_drawpixels(ctx, &x, &y, &width, &height,
- &clippedUnpack)) {
- /* totally clipped */
- return;
- }
- }
-
- strb = st_renderbuffer(ctx->DrawBuffer->
- Attachment[BUFFER_STENCIL].Renderbuffer);
-
- if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
- y = ctx->DrawBuffer->Height - y - height;
- }
-
- if(format != GL_DEPTH_STENCIL &&
- util_format_get_component_bits(strb->format,
- UTIL_FORMAT_COLORSPACE_ZS, 0) != 0)
- usage = PIPE_TRANSFER_READ_WRITE;
- else
- usage = PIPE_TRANSFER_WRITE;
-
- pt = pipe_get_transfer(st_context(ctx)->pipe, strb->texture, 0, 0,
- usage, x, y,
- width, height);
-
- stmap = pipe_transfer_map(pipe, pt);
-
- pixels = _mesa_map_pbo_source(ctx, &clippedUnpack, pixels);
- assert(pixels);
-
- /* if width > MAX_WIDTH, have to process image in chunks */
- skipPixels = 0;
- while (skipPixels < width) {
- const GLint spanX = skipPixels;
- const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
- GLint row;
- for (row = 0; row < height; row++) {
- GLubyte sValues[MAX_WIDTH];
- GLuint zValues[MAX_WIDTH];
- GLenum destType = GL_UNSIGNED_BYTE;
- const GLvoid *source = _mesa_image_address2d(&clippedUnpack, pixels,
- width, height,
- format, type,
- row, skipPixels);
- _mesa_unpack_stencil_span(ctx, spanWidth, destType, sValues,
- type, source, &clippedUnpack,
- ctx->_ImageTransferState);
-
- if (format == GL_DEPTH_STENCIL) {
- _mesa_unpack_depth_span(ctx, spanWidth, GL_UNSIGNED_INT, zValues,
- (1 << 24) - 1, type, source,
- &clippedUnpack);
- }
-
- if (zoom) {
- _mesa_problem(ctx, "Gallium glDrawPixels(GL_STENCIL) with "
- "zoom not complete");
- }
-
- {
- GLint spanY;
-
- if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
- spanY = height - row - 1;
- }
- else {
- spanY = row;
- }
-
- /* now pack the stencil (and Z) values in the dest format */
- switch (pt->resource->format) {
- case PIPE_FORMAT_S8_USCALED:
- {
- ubyte *dest = stmap + spanY * pt->stride + spanX;
- assert(usage == PIPE_TRANSFER_WRITE);
- memcpy(dest, sValues, spanWidth);
- }
- break;
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- if (format == GL_DEPTH_STENCIL) {
- uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4);
- GLint k;
- assert(usage == PIPE_TRANSFER_WRITE);
- for (k = 0; k < spanWidth; k++) {
- dest[k] = zValues[k] | (sValues[k] << 24);
- }
- }
- else {
- uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4);
- GLint k;
- assert(usage == PIPE_TRANSFER_READ_WRITE);
- for (k = 0; k < spanWidth; k++) {
- dest[k] = (dest[k] & 0xffffff) | (sValues[k] << 24);
- }
- }
- break;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- if (format == GL_DEPTH_STENCIL) {
- uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4);
- GLint k;
- assert(usage == PIPE_TRANSFER_WRITE);
- for (k = 0; k < spanWidth; k++) {
- dest[k] = (zValues[k] << 8) | (sValues[k] & 0xff);
- }
- }
- else {
- uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4);
- GLint k;
- assert(usage == PIPE_TRANSFER_READ_WRITE);
- for (k = 0; k < spanWidth; k++) {
- dest[k] = (dest[k] & 0xffffff00) | (sValues[k] & 0xff);
- }
- }
- break;
- default:
- assert(0);
- }
- }
- }
- skipPixels += spanWidth;
- }
-
- _mesa_unmap_pbo_source(ctx, &clippedUnpack);
-
- /* unmap the stencil buffer */
- pipe_transfer_unmap(pipe, pt);
- pipe->transfer_destroy(pipe, pt);
-}
-
-
-/**
- * Get fragment program variant for a glDrawPixels or glCopyPixels
- * command for RGBA data.
- */
-static struct st_fp_variant *
-get_color_fp_variant(struct st_context *st)
-{
- struct gl_context *ctx = st->ctx;
- struct st_fp_variant_key key;
- struct st_fp_variant *fpv;
-
- memset(&key, 0, sizeof(key));
-
- key.st = st;
- key.drawpixels = 1;
- key.scaleAndBias = (ctx->Pixel.RedBias != 0.0 ||
- ctx->Pixel.RedScale != 1.0 ||
- ctx->Pixel.GreenBias != 0.0 ||
- ctx->Pixel.GreenScale != 1.0 ||
- ctx->Pixel.BlueBias != 0.0 ||
- ctx->Pixel.BlueScale != 1.0 ||
- ctx->Pixel.AlphaBias != 0.0 ||
- ctx->Pixel.AlphaScale != 1.0);
- key.pixelMaps = ctx->Pixel.MapColorFlag;
-
- fpv = st_get_fp_variant(st, st->fp, &key);
-
- return fpv;
-}
-
-
-/**
- * Get fragment program variant for a glDrawPixels or glCopyPixels
- * command for depth/stencil data.
- */
-static struct st_fp_variant *
-get_depth_stencil_fp_variant(struct st_context *st, GLboolean write_depth,
- GLboolean write_stencil)
-{
- struct st_fp_variant_key key;
- struct st_fp_variant *fpv;
-
- memset(&key, 0, sizeof(key));
-
- key.st = st;
- key.drawpixels = 1;
- key.drawpixels_z = write_depth;
- key.drawpixels_stencil = write_stencil;
-
- fpv = st_get_fp_variant(st, st->fp, &key);
-
- return fpv;
-}
-
-
-/**
- * Called via ctx->Driver.DrawPixels()
- */
-static void
-st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels)
-{
- void *driver_vp, *driver_fp;
- struct st_context *st = st_context(ctx);
- const GLfloat *color;
- struct pipe_context *pipe = st->pipe;
- GLboolean write_stencil = GL_FALSE, write_depth = GL_FALSE;
- struct pipe_sampler_view *sv[2];
- int num_sampler_view = 1;
- enum pipe_format stencil_format = PIPE_FORMAT_NONE;
- struct st_fp_variant *fpv;
-
- if (format == GL_DEPTH_STENCIL)
- write_stencil = write_depth = GL_TRUE;
- else if (format == GL_STENCIL_INDEX)
- write_stencil = GL_TRUE;
- else if (format == GL_DEPTH_COMPONENT)
- write_depth = GL_TRUE;
-
- if (write_stencil) {
- enum pipe_format tex_format;
- /* can we write to stencil if not fallback */
- if (!pipe->screen->get_param(pipe->screen, PIPE_CAP_SHADER_STENCIL_EXPORT))
- goto stencil_fallback;
-
- tex_format = st_choose_format(st->pipe->screen, base_format(format),
- PIPE_TEXTURE_2D,
- 0, PIPE_BIND_SAMPLER_VIEW);
- if (tex_format == PIPE_FORMAT_Z24_UNORM_S8_USCALED)
- stencil_format = PIPE_FORMAT_X24S8_USCALED;
- else if (tex_format == PIPE_FORMAT_S8_USCALED_Z24_UNORM)
- stencil_format = PIPE_FORMAT_S8X24_USCALED;
- else
- stencil_format = PIPE_FORMAT_S8_USCALED;
- if (stencil_format == PIPE_FORMAT_NONE)
- goto stencil_fallback;
- }
-
- /* Mesa state should be up to date by now */
- assert(ctx->NewState == 0x0);
-
- st_validate_state(st);
-
- /*
- * Get vertex/fragment shaders
- */
- if (write_depth || write_stencil) {
- fpv = get_depth_stencil_fp_variant(st, write_depth, write_stencil);
-
- driver_fp = fpv->driver_shader;
-
- driver_vp = make_passthrough_vertex_shader(st, GL_TRUE);
-
- color = ctx->Current.RasterColor;
- }
- else {
- fpv = get_color_fp_variant(st);
-
- driver_fp = fpv->driver_shader;
-
- driver_vp = make_passthrough_vertex_shader(st, GL_FALSE);
-
- color = NULL;
- if (st->pixel_xfer.pixelmap_enabled) {
- sv[1] = st->pixel_xfer.pixelmap_sampler_view;
- num_sampler_view++;
- }
- }
-
- /* update fragment program constants */
- st_upload_constants(st, fpv->parameters, PIPE_SHADER_FRAGMENT);
-
- /* draw with textured quad */
- {
- struct pipe_resource *pt
- = make_texture(st, width, height, format, type, unpack, pixels);
- if (pt) {
- sv[0] = st_create_texture_sampler_view(st->pipe, pt);
-
- if (sv[0]) {
- if (write_stencil) {
- sv[1] = st_create_texture_sampler_view_format(st->pipe, pt,
- stencil_format);
- num_sampler_view++;
- }
-
- draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
- width, height,
- ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
- sv,
- num_sampler_view,
- driver_vp,
- driver_fp,
- color, GL_FALSE, write_depth, write_stencil);
- pipe_sampler_view_reference(&sv[0], NULL);
- if (num_sampler_view > 1)
- pipe_sampler_view_reference(&sv[1], NULL);
- }
- pipe_resource_reference(&pt, NULL);
- }
- }
- return;
-
-stencil_fallback:
- draw_stencil_pixels(ctx, x, y, width, height, format, type,
- unpack, pixels);
-}
-
-
-
-/**
- * Software fallback for glCopyPixels(GL_STENCIL).
- */
-static void
-copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
- GLsizei width, GLsizei height,
- GLint dstx, GLint dsty)
-{
- struct st_renderbuffer *rbDraw;
- struct pipe_context *pipe = st_context(ctx)->pipe;
- enum pipe_transfer_usage usage;
- struct pipe_transfer *ptDraw;
- ubyte *drawMap;
- ubyte *buffer;
- int i;
-
- buffer = malloc(width * height * sizeof(ubyte));
- if (!buffer) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels(stencil)");
- return;
- }
-
- /* Get the dest renderbuffer. If there's a wrapper, use the
- * underlying renderbuffer.
- */
- rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer);
- if (rbDraw->Base.Wrapped)
- rbDraw = st_renderbuffer(rbDraw->Base.Wrapped);
-
- /* this will do stencil pixel transfer ops */
- st_read_stencil_pixels(ctx, srcx, srcy, width, height,
- GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,
- &ctx->DefaultPacking, buffer);
-
- if (0) {
- /* debug code: dump stencil values */
- GLint row, col;
- for (row = 0; row < height; row++) {
- printf("%3d: ", row);
- for (col = 0; col < width; col++) {
- printf("%02x ", buffer[col + row * width]);
- }
- printf("\n");
- }
- }
-
- if (util_format_get_component_bits(rbDraw->format,
- UTIL_FORMAT_COLORSPACE_ZS, 0) != 0)
- usage = PIPE_TRANSFER_READ_WRITE;
- else
- usage = PIPE_TRANSFER_WRITE;
-
- if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
- dsty = rbDraw->Base.Height - dsty - height;
- }
-
- ptDraw = pipe_get_transfer(st_context(ctx)->pipe,
- rbDraw->texture, 0, 0,
- usage, dstx, dsty,
- width, height);
-
- assert(util_format_get_blockwidth(ptDraw->resource->format) == 1);
- assert(util_format_get_blockheight(ptDraw->resource->format) == 1);
-
- /* map the stencil buffer */
- drawMap = pipe_transfer_map(pipe, ptDraw);
-
- /* draw */
- /* XXX PixelZoom not handled yet */
- for (i = 0; i < height; i++) {
- ubyte *dst;
- const ubyte *src;
- int y;
-
- y = i;
-
- if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
- y = height - y - 1;
- }
-
- dst = drawMap + y * ptDraw->stride;
- src = buffer + i * width;
-
- switch (ptDraw->resource->format) {
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- {
- uint *dst4 = (uint *) dst;
- int j;
- assert(usage == PIPE_TRANSFER_READ_WRITE);
- for (j = 0; j < width; j++) {
- *dst4 = (*dst4 & 0xffffff) | (src[j] << 24);
- dst4++;
- }
- }
- break;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- {
- uint *dst4 = (uint *) dst;
- int j;
- assert(usage == PIPE_TRANSFER_READ_WRITE);
- for (j = 0; j < width; j++) {
- *dst4 = (*dst4 & 0xffffff00) | (src[j] & 0xff);
- dst4++;
- }
- }
- break;
- case PIPE_FORMAT_S8_USCALED:
- assert(usage == PIPE_TRANSFER_WRITE);
- memcpy(dst, src, width);
- break;
- default:
- assert(0);
- }
- }
-
- free(buffer);
-
- /* unmap the stencil buffer */
- pipe_transfer_unmap(pipe, ptDraw);
- pipe->transfer_destroy(pipe, ptDraw);
-}
-
-
-/** Do the src/dest regions overlap? */
-static GLboolean
-regions_overlap(GLint srcX, GLint srcY, GLint dstX, GLint dstY,
- GLsizei width, GLsizei height)
-{
- if (srcX + width <= dstX ||
- dstX + width <= srcX ||
- srcY + height <= dstY ||
- dstY + height <= srcY)
- return GL_FALSE;
- else
- return GL_TRUE;
-}
-
-
-/**
- * Try to do a glCopyPixels for simple cases with a blit by calling
- * pipe->resource_copy_region().
- *
- * We can do this when we're copying color pixels (depth/stencil
- * eventually) with no pixel zoom, no pixel transfer ops, no
- * per-fragment ops, the src/dest regions don't overlap and the
- * src/dest pixel formats are the same.
- */
-static GLboolean
-blit_copy_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
- GLsizei width, GLsizei height,
- GLint dstx, GLint dsty, GLenum type)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct gl_pixelstore_attrib pack, unpack;
- GLint readX, readY, readW, readH;
-
- if (type == GL_COLOR &&
- ctx->Pixel.ZoomX == 1.0 &&
- ctx->Pixel.ZoomY == 1.0 &&
- ctx->_ImageTransferState == 0x0 &&
- !ctx->Color.BlendEnabled &&
- !ctx->Color.AlphaEnabled &&
- !ctx->Depth.Test &&
- !ctx->Fog.Enabled &&
- !ctx->Stencil.Enabled &&
- !ctx->FragmentProgram.Enabled &&
- !ctx->VertexProgram.Enabled &&
- !ctx->Shader.CurrentFragmentProgram &&
- st_fb_orientation(ctx->ReadBuffer) == st_fb_orientation(ctx->DrawBuffer) &&
- ctx->DrawBuffer->_NumColorDrawBuffers == 1) {
- struct st_renderbuffer *rbRead, *rbDraw;
- GLint drawX, drawY;
-
- /*
- * Clip the read region against the src buffer bounds.
- * We'll still allocate a temporary buffer/texture for the original
- * src region size but we'll only read the region which is on-screen.
- * This may mean that we draw garbage pixels into the dest region, but
- * that's expected.
- */
- readX = srcx;
- readY = srcy;
- readW = width;
- readH = height;
- pack = ctx->DefaultPacking;
- if (!_mesa_clip_readpixels(ctx, &readX, &readY, &readW, &readH, &pack))
- return GL_TRUE; /* all done */
-
- /* clip against dest buffer bounds and scissor box */
- drawX = dstx + pack.SkipPixels;
- drawY = dsty + pack.SkipRows;
- unpack = pack;
- if (!_mesa_clip_drawpixels(ctx, &drawX, &drawY, &readW, &readH, &unpack))
- return GL_TRUE; /* all done */
-
- readX = readX - pack.SkipPixels + unpack.SkipPixels;
- readY = readY - pack.SkipRows + unpack.SkipRows;
-
- rbRead = st_get_color_read_renderbuffer(ctx);
- rbDraw = st_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
-
- if ((rbRead != rbDraw ||
- !regions_overlap(readX, readY, drawX, drawY, readW, readH)) &&
- rbRead->Base.Format == rbDraw->Base.Format) {
- struct pipe_box srcBox;
-
- /* flip src/dst position if needed */
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- /* both buffers will have the same orientation */
- readY = ctx->ReadBuffer->Height - readY - readH;
- drawY = ctx->DrawBuffer->Height - drawY - readH;
- }
-
- u_box_2d(readX, readY, readW, readH, &srcBox);
-
- pipe->resource_copy_region(pipe,
- rbDraw->texture, 0, drawX, drawY, 0,
- rbRead->texture, 0, &srcBox);
- return GL_TRUE;
- }
- }
-
- return GL_FALSE;
-}
-
-
-static void
-st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
- GLsizei width, GLsizei height,
- GLint dstx, GLint dsty, GLenum type)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
- struct st_renderbuffer *rbRead;
- void *driver_vp, *driver_fp;
- struct pipe_resource *pt;
- struct pipe_sampler_view *sv[2];
- int num_sampler_view = 1;
- GLfloat *color;
- enum pipe_format srcFormat, texFormat;
- GLboolean invertTex = GL_FALSE;
- GLint readX, readY, readW, readH;
- GLuint sample_count;
- struct gl_pixelstore_attrib pack = ctx->DefaultPacking;
- struct st_fp_variant *fpv;
-
- st_validate_state(st);
-
- if (type == GL_STENCIL) {
- /* can't use texturing to do stencil */
- copy_stencil_pixels(ctx, srcx, srcy, width, height, dstx, dsty);
- return;
- }
-
- if (blit_copy_pixels(ctx, srcx, srcy, width, height, dstx, dsty, type))
- return;
-
- /*
- * The subsequent code implements glCopyPixels by copying the source
- * pixels into a temporary texture that's then applied to a textured quad.
- * When we draw the textured quad, all the usual per-fragment operations
- * are handled.
- */
-
-
- /*
- * Get vertex/fragment shaders
- */
- if (type == GL_COLOR) {
- rbRead = st_get_color_read_renderbuffer(ctx);
- color = NULL;
-
- fpv = get_color_fp_variant(st);
- driver_fp = fpv->driver_shader;
-
- driver_vp = make_passthrough_vertex_shader(st, GL_FALSE);
-
- if (st->pixel_xfer.pixelmap_enabled) {
- sv[1] = st->pixel_xfer.pixelmap_sampler_view;
- num_sampler_view++;
- }
- }
- else {
- assert(type == GL_DEPTH);
- rbRead = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer);
- color = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
-
- fpv = get_depth_stencil_fp_variant(st, GL_TRUE, GL_FALSE);
- driver_fp = fpv->driver_shader;
-
- driver_vp = make_passthrough_vertex_shader(st, GL_TRUE);
- }
-
- /* update fragment program constants */
- st_upload_constants(st, fpv->parameters, PIPE_SHADER_FRAGMENT);
-
-
- if (rbRead->Base.Wrapped)
- rbRead = st_renderbuffer(rbRead->Base.Wrapped);
-
- sample_count = rbRead->texture->nr_samples;
- /* I believe this would be legal, presumably would need to do a resolve
- for color, and for depth/stencil spec says to just use one of the
- depth/stencil samples per pixel? Need some transfer clarifications. */
- assert(sample_count < 2);
-
- srcFormat = rbRead->texture->format;
-
- if (screen->is_format_supported(screen, srcFormat, st->internal_target,
- sample_count,
- PIPE_BIND_SAMPLER_VIEW, 0)) {
- texFormat = srcFormat;
- }
- else {
- /* srcFormat can't be used as a texture format */
- if (type == GL_DEPTH) {
- texFormat = st_choose_format(screen, GL_DEPTH_COMPONENT,
- st->internal_target, sample_count,
- PIPE_BIND_DEPTH_STENCIL);
- assert(texFormat != PIPE_FORMAT_NONE);
- }
- else {
- /* default color format */
- texFormat = st_choose_format(screen, GL_RGBA, st->internal_target,
- sample_count, PIPE_BIND_SAMPLER_VIEW);
- assert(texFormat != PIPE_FORMAT_NONE);
- }
- }
-
- /* Invert src region if needed */
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- srcy = ctx->ReadBuffer->Height - srcy - height;
- invertTex = !invertTex;
- }
-
- /* Clip the read region against the src buffer bounds.
- * We'll still allocate a temporary buffer/texture for the original
- * src region size but we'll only read the region which is on-screen.
- * This may mean that we draw garbage pixels into the dest region, but
- * that's expected.
- */
- readX = srcx;
- readY = srcy;
- readW = width;
- readH = height;
- _mesa_clip_readpixels(ctx, &readX, &readY, &readW, &readH, &pack);
- readW = MAX2(0, readW);
- readH = MAX2(0, readH);
-
- /* alloc temporary texture */
- pt = alloc_texture(st, width, height, texFormat);
- if (!pt)
- return;
-
- sv[0] = st_create_texture_sampler_view(st->pipe, pt);
- if (!sv[0]) {
- pipe_resource_reference(&pt, NULL);
- return;
- }
-
- /* Make temporary texture which is a copy of the src region.
- */
- if (srcFormat == texFormat) {
- struct pipe_box src_box;
- u_box_2d(readX, readY, readW, readH, &src_box);
- /* copy source framebuffer surface into mipmap/texture */
- pipe->resource_copy_region(pipe,
- pt, /* dest tex */
- 0,
- pack.SkipPixels, pack.SkipRows, 0, /* dest pos */
- rbRead->texture, /* src tex */
- 0,
- &src_box);
-
- }
- else {
- /* CPU-based fallback/conversion */
- struct pipe_transfer *ptRead =
- pipe_get_transfer(st->pipe, rbRead->texture,
- 0, 0, /* level, layer */
- PIPE_TRANSFER_READ,
- readX, readY, readW, readH);
- struct pipe_transfer *ptTex;
- enum pipe_transfer_usage transfer_usage;
-
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s: fallback processing\n", __FUNCTION__);
-
- if (type == GL_DEPTH && util_format_is_depth_and_stencil(pt->format))
- transfer_usage = PIPE_TRANSFER_READ_WRITE;
- else
- transfer_usage = PIPE_TRANSFER_WRITE;
-
- ptTex = pipe_get_transfer(st->pipe, pt, 0, 0, transfer_usage,
- 0, 0, width, height);
-
- /* copy image from ptRead surface to ptTex surface */
- if (type == GL_COLOR) {
- /* alternate path using get/put_tile() */
- GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
- enum pipe_format readFormat, drawFormat;
- readFormat = util_format_linear(rbRead->texture->format);
- drawFormat = util_format_linear(pt->format);
- pipe_get_tile_rgba_format(pipe, ptRead, 0, 0, readW, readH,
- readFormat, buf);
- pipe_put_tile_rgba_format(pipe, ptTex, pack.SkipPixels, pack.SkipRows,
- readW, readH, drawFormat, buf);
- free(buf);
- }
- else {
- /* GL_DEPTH */
- GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint));
- pipe_get_tile_z(pipe, ptRead, 0, 0, readW, readH, buf);
- pipe_put_tile_z(pipe, ptTex, pack.SkipPixels, pack.SkipRows,
- readW, readH, buf);
- free(buf);
- }
-
- pipe->transfer_destroy(pipe, ptRead);
- pipe->transfer_destroy(pipe, ptTex);
- }
-
- /* OK, the texture 'pt' contains the src image/pixels. Now draw a
- * textured quad with that texture.
- */
- draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2],
- width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
- sv,
- num_sampler_view,
- driver_vp,
- driver_fp,
- color, invertTex, GL_FALSE, GL_FALSE);
-
- pipe_resource_reference(&pt, NULL);
- pipe_sampler_view_reference(&sv[0], NULL);
-}
-
-
-
-void st_init_drawpixels_functions(struct dd_function_table *functions)
-{
- functions->DrawPixels = st_DrawPixels;
- functions->CopyPixels = st_CopyPixels;
-}
-
-
-void
-st_destroy_drawpix(struct st_context *st)
-{
- GLuint i;
-
- for (i = 0; i < Elements(st->drawpix.shaders); i++) {
- if (st->drawpix.shaders[i])
- _mesa_reference_fragprog(st->ctx, &st->drawpix.shaders[i], NULL);
- }
-
- st_reference_fragprog(st, &st->pixel_xfer.combined_prog, NULL);
- if (st->drawpix.vert_shaders[0])
- ureg_free_tokens(st->drawpix.vert_shaders[0]);
- if (st->drawpix.vert_shaders[1])
- ureg_free_tokens(st->drawpix.vert_shaders[1]);
-}
-
-#endif /* FEATURE_drawpix */
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Brian Paul
+ */
+
+#include "main/imports.h"
+#include "main/image.h"
+#include "main/bufferobj.h"
+#include "main/macros.h"
+#include "main/mfeatures.h"
+#include "main/mtypes.h"
+#include "main/pack.h"
+#include "main/pbo.h"
+#include "main/texformat.h"
+#include "main/texstore.h"
+#include "program/program.h"
+#include "program/prog_print.h"
+#include "program/prog_instruction.h"
+
+#include "st_atom.h"
+#include "st_atom_constbuf.h"
+#include "st_cb_drawpixels.h"
+#include "st_cb_readpixels.h"
+#include "st_cb_fbo.h"
+#include "st_context.h"
+#include "st_debug.h"
+#include "st_format.h"
+#include "st_program.h"
+#include "st_texture.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "tgsi/tgsi_ureg.h"
+#include "util/u_draw_quad.h"
+#include "util/u_format.h"
+#include "util/u_inlines.h"
+#include "util/u_math.h"
+#include "util/u_tile.h"
+#include "cso_cache/cso_context.h"
+
+
+#if FEATURE_drawpix
+
+/**
+ * Check if the given program is:
+ * 0: MOVE result.color, fragment.color;
+ * 1: END;
+ */
+static GLboolean
+is_passthrough_program(const struct gl_fragment_program *prog)
+{
+ if (prog->Base.NumInstructions == 2) {
+ const struct prog_instruction *inst = prog->Base.Instructions;
+ if (inst[0].Opcode == OPCODE_MOV &&
+ inst[1].Opcode == OPCODE_END &&
+ inst[0].DstReg.File == PROGRAM_OUTPUT &&
+ inst[0].DstReg.Index == FRAG_RESULT_COLOR &&
+ inst[0].DstReg.WriteMask == WRITEMASK_XYZW &&
+ inst[0].SrcReg[0].File == PROGRAM_INPUT &&
+ inst[0].SrcReg[0].Index == FRAG_ATTRIB_COL0 &&
+ inst[0].SrcReg[0].Swizzle == SWIZZLE_XYZW) {
+ return GL_TRUE;
+ }
+ }
+ return GL_FALSE;
+}
+
+
+
+/**
+ * Make fragment shader for glDraw/CopyPixels. This shader is made
+ * by combining the pixel transfer shader with the user-defined shader.
+ * \param fpIn the current/incoming fragment program
+ * \param fpOut returns the combined fragment program
+ */
+void
+st_make_drawpix_fragment_program(struct st_context *st,
+ struct gl_fragment_program *fpIn,
+ struct gl_fragment_program **fpOut)
+{
+ struct gl_program *newProg;
+
+ if (is_passthrough_program(fpIn)) {
+ newProg = (struct gl_program *) _mesa_clone_fragment_program(st->ctx,
+ &st->pixel_xfer.program->Base);
+ }
+ else {
+#if 0
+ /* debug */
+ printf("Base program:\n");
+ _mesa_print_program(&fpIn->Base);
+ printf("DrawPix program:\n");
+ _mesa_print_program(&st->pixel_xfer.program->Base.Base);
+#endif
+ newProg = _mesa_combine_programs(st->ctx,
+ &st->pixel_xfer.program->Base.Base,
+ &fpIn->Base);
+ }
+
+#if 0
+ /* debug */
+ printf("Combined DrawPixels program:\n");
+ _mesa_print_program(newProg);
+ printf("InputsRead: 0x%x\n", newProg->InputsRead);
+ printf("OutputsWritten: 0x%x\n", newProg->OutputsWritten);
+ _mesa_print_parameter_list(newProg->Parameters);
+#endif
+
+ *fpOut = (struct gl_fragment_program *) newProg;
+}
+
+
+/**
+ * Create fragment program that does a TEX() instruction to get a Z and/or
+ * stencil value value, then writes to FRAG_RESULT_DEPTH/FRAG_RESULT_STENCIL.
+ * Used for glDrawPixels(GL_DEPTH_COMPONENT / GL_STENCIL_INDEX).
+ * Pass fragment color through as-is.
+ * \return pointer to the gl_fragment program
+ */
+struct gl_fragment_program *
+st_make_drawpix_z_stencil_program(struct st_context *st,
+ GLboolean write_depth,
+ GLboolean write_stencil)
+{
+ struct gl_context *ctx = st->ctx;
+ struct gl_program *p;
+ struct gl_fragment_program *fp;
+ GLuint ic = 0;
+ const GLuint shaderIndex = write_depth * 2 + write_stencil;
+
+ assert(shaderIndex < Elements(st->drawpix.shaders));
+
+ if (st->drawpix.shaders[shaderIndex]) {
+ /* already have the proper shader */
+ return st->drawpix.shaders[shaderIndex];
+ }
+
+ /*
+ * Create shader now
+ */
+ p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
+ if (!p)
+ return NULL;
+
+ p->NumInstructions = write_depth ? 2 : 1;
+ p->NumInstructions += write_stencil ? 1 : 0;
+
+ p->Instructions = _mesa_alloc_instructions(p->NumInstructions);
+ if (!p->Instructions) {
+ ctx->Driver.DeleteProgram(ctx, p);
+ return NULL;
+ }
+ _mesa_init_instructions(p->Instructions, p->NumInstructions);
+
+ if (write_depth) {
+ /* TEX result.depth, fragment.texcoord[0], texture[0], 2D; */
+ p->Instructions[ic].Opcode = OPCODE_TEX;
+ p->Instructions[ic].DstReg.File = PROGRAM_OUTPUT;
+ p->Instructions[ic].DstReg.Index = FRAG_RESULT_DEPTH;
+ p->Instructions[ic].DstReg.WriteMask = WRITEMASK_Z;
+ p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT;
+ p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0;
+ p->Instructions[ic].TexSrcUnit = 0;
+ p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX;
+ ic++;
+ }
+
+ if (write_stencil) {
+ /* TEX result.stencil, fragment.texcoord[0], texture[0], 2D; */
+ p->Instructions[ic].Opcode = OPCODE_TEX;
+ p->Instructions[ic].DstReg.File = PROGRAM_OUTPUT;
+ p->Instructions[ic].DstReg.Index = FRAG_RESULT_STENCIL;
+ p->Instructions[ic].DstReg.WriteMask = WRITEMASK_Y;
+ p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT;
+ p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0;
+ p->Instructions[ic].TexSrcUnit = 1;
+ p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX;
+ ic++;
+ }
+
+ /* END; */
+ p->Instructions[ic++].Opcode = OPCODE_END;
+
+ assert(ic == p->NumInstructions);
+
+ p->InputsRead = FRAG_BIT_TEX0 | FRAG_BIT_COL0;
+ p->OutputsWritten = 0;
+ if (write_depth)
+ p->OutputsWritten |= (1 << FRAG_RESULT_DEPTH);
+ if (write_stencil)
+ p->OutputsWritten |= (1 << FRAG_RESULT_STENCIL);
+
+ p->SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */
+ if (write_stencil)
+ p->SamplersUsed |= 1 << 1;
+
+ fp = (struct gl_fragment_program *) p;
+
+ /* save the new shader */
+ st->drawpix.shaders[shaderIndex] = fp;
+
+ return fp;
+}
+
+
+/**
+ * Create a simple vertex shader that just passes through the
+ * vertex position and texcoord (and optionally, color).
+ */
+static void *
+make_passthrough_vertex_shader(struct st_context *st,
+ GLboolean passColor)
+{
+ if (!st->drawpix.vert_shaders[passColor]) {
+ struct ureg_program *ureg = ureg_create( TGSI_PROCESSOR_VERTEX );
+
+ if (ureg == NULL)
+ return NULL;
+
+ /* MOV result.pos, vertex.pos; */
+ ureg_MOV(ureg,
+ ureg_DECL_output( ureg, TGSI_SEMANTIC_POSITION, 0 ),
+ ureg_DECL_vs_input( ureg, 0 ));
+
+ /* MOV result.texcoord0, vertex.attr[1]; */
+ ureg_MOV(ureg,
+ ureg_DECL_output( ureg, TGSI_SEMANTIC_GENERIC, 0 ),
+ ureg_DECL_vs_input( ureg, 1 ));
+
+ if (passColor) {
+ /* MOV result.color0, vertex.attr[2]; */
+ ureg_MOV(ureg,
+ ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, 0 ),
+ ureg_DECL_vs_input( ureg, 2 ));
+ }
+
+ ureg_END( ureg );
+
+ st->drawpix.vert_shaders[passColor] =
+ ureg_create_shader_and_destroy( ureg, st->pipe );
+ }
+
+ return st->drawpix.vert_shaders[passColor];
+}
+
+
+/**
+ * Return a texture base format for drawing/copying an image
+ * of the given format.
+ */
+static GLenum
+base_format(GLenum format)
+{
+ switch (format) {
+ case GL_DEPTH_COMPONENT:
+ return GL_DEPTH_COMPONENT;
+ case GL_DEPTH_STENCIL:
+ return GL_DEPTH_STENCIL;
+ case GL_STENCIL_INDEX:
+ return GL_STENCIL_INDEX;
+ default:
+ return GL_RGBA;
+ }
+}
+
+
+/**
+ * Return a texture internalFormat for drawing/copying an image
+ * of the given format and type.
+ */
+static GLenum
+internal_format(GLenum format, GLenum type)
+{
+ switch (format) {
+ case GL_DEPTH_COMPONENT:
+ return GL_DEPTH_COMPONENT;
+ case GL_DEPTH_STENCIL:
+ return GL_DEPTH_STENCIL;
+ case GL_STENCIL_INDEX:
+ return GL_STENCIL_INDEX;
+ default:
+ if (_mesa_is_integer_format(format)) {
+ switch (type) {
+ case GL_BYTE:
+ return GL_RGBA8I;
+ case GL_UNSIGNED_BYTE:
+ return GL_RGBA8UI;
+ case GL_SHORT:
+ return GL_RGBA16I;
+ case GL_UNSIGNED_SHORT:
+ return GL_RGBA16UI;
+ case GL_INT:
+ return GL_RGBA32I;
+ case GL_UNSIGNED_INT:
+ return GL_RGBA32UI;
+ default:
+ assert(0 && "Unexpected type in internal_format()");
+ return GL_RGBA_INTEGER;
+ }
+ }
+ else {
+ return GL_RGBA;
+ }
+ }
+}
+
+
+/**
+ * Create a temporary texture to hold an image of the given size.
+ * If width, height are not POT and the driver only handles POT textures,
+ * allocate the next larger size of texture that is POT.
+ */
+static struct pipe_resource *
+alloc_texture(struct st_context *st, GLsizei width, GLsizei height,
+ enum pipe_format texFormat)
+{
+ struct pipe_resource *pt;
+
+ pt = st_texture_create(st, st->internal_target, texFormat, 0,
+ width, height, 1, 1, PIPE_BIND_SAMPLER_VIEW);
+
+ return pt;
+}
+
+
+/**
+ * Make texture containing an image for glDrawPixels image.
+ * If 'pixels' is NULL, leave the texture image data undefined.
+ */
+static struct pipe_resource *
+make_texture(struct st_context *st,
+ GLsizei width, GLsizei height, GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels)
+{
+ struct gl_context *ctx = st->ctx;
+ struct pipe_context *pipe = st->pipe;
+ gl_format mformat;
+ struct pipe_resource *pt;
+ enum pipe_format pipeFormat;
+ GLuint cpp;
+ GLenum baseFormat, intFormat;
+
+ baseFormat = base_format(format);
+ intFormat = internal_format(format, type);
+
+ mformat = st_ChooseTextureFormat_renderable(ctx, intFormat,
+ format, type, GL_FALSE);
+ assert(mformat);
+
+ pipeFormat = st_mesa_format_to_pipe_format(mformat);
+ assert(pipeFormat);
+ cpp = util_format_get_blocksize(pipeFormat);
+
+ pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
+ if (!pixels)
+ return NULL;
+
+ /* alloc temporary texture */
+ pt = alloc_texture(st, width, height, pipeFormat);
+ if (!pt) {
+ _mesa_unmap_pbo_source(ctx, unpack);
+ return NULL;
+ }
+
+ {
+ struct pipe_transfer *transfer;
+ static const GLuint dstImageOffsets = 0;
+ GLboolean success;
+ GLubyte *dest;
+ const GLbitfield imageTransferStateSave = ctx->_ImageTransferState;
+
+ /* we'll do pixel transfer in a fragment shader */
+ ctx->_ImageTransferState = 0x0;
+
+ transfer = pipe_get_transfer(st->pipe, pt, 0, 0,
+ PIPE_TRANSFER_WRITE, 0, 0,
+ width, height);
+
+ /* map texture transfer */
+ dest = pipe_transfer_map(pipe, transfer);
+
+
+ /* Put image into texture transfer.
+ * Note that the image is actually going to be upside down in
+ * the texture. We deal with that with texcoords.
+ */
+ success = _mesa_texstore(ctx, 2, /* dims */
+ baseFormat, /* baseInternalFormat */
+ mformat, /* gl_format */
+ dest, /* dest */
+ 0, 0, 0, /* dstX/Y/Zoffset */
+ transfer->stride, /* dstRowStride, bytes */
+ &dstImageOffsets, /* dstImageOffsets */
+ width, height, 1, /* size */
+ format, type, /* src format/type */
+ pixels, /* data source */
+ unpack);
+
+ /* unmap */
+ pipe_transfer_unmap(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
+
+ assert(success);
+
+ /* restore */
+ ctx->_ImageTransferState = imageTransferStateSave;
+ }
+
+ _mesa_unmap_pbo_source(ctx, unpack);
+
+ return pt;
+}
+
+
+/**
+ * Draw quad with texcoords and optional color.
+ * Coords are gallium window coords with y=0=top.
+ * \param color may be null
+ * \param invertTex if true, flip texcoords vertically
+ */
+static void
+draw_quad(struct gl_context *ctx, GLfloat x0, GLfloat y0, GLfloat z,
+ GLfloat x1, GLfloat y1, const GLfloat *color,
+ GLboolean invertTex, GLfloat maxXcoord, GLfloat maxYcoord)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ GLfloat verts[4][3][4]; /* four verts, three attribs, XYZW */
+
+ /* setup vertex data */
+ {
+ const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
+ const GLfloat fb_width = (GLfloat) fb->Width;
+ const GLfloat fb_height = (GLfloat) fb->Height;
+ const GLfloat clip_x0 = x0 / fb_width * 2.0f - 1.0f;
+ const GLfloat clip_y0 = y0 / fb_height * 2.0f - 1.0f;
+ const GLfloat clip_x1 = x1 / fb_width * 2.0f - 1.0f;
+ const GLfloat clip_y1 = y1 / fb_height * 2.0f - 1.0f;
+ const GLfloat sLeft = 0.0f, sRight = maxXcoord;
+ const GLfloat tTop = invertTex ? maxYcoord : 0.0f;
+ const GLfloat tBot = invertTex ? 0.0f : maxYcoord;
+ GLuint i;
+
+ /* upper-left */
+ verts[0][0][0] = clip_x0; /* v[0].attr[0].x */
+ verts[0][0][1] = clip_y0; /* v[0].attr[0].y */
+
+ /* upper-right */
+ verts[1][0][0] = clip_x1;
+ verts[1][0][1] = clip_y0;
+
+ /* lower-right */
+ verts[2][0][0] = clip_x1;
+ verts[2][0][1] = clip_y1;
+
+ /* lower-left */
+ verts[3][0][0] = clip_x0;
+ verts[3][0][1] = clip_y1;
+
+ verts[0][1][0] = sLeft; /* v[0].attr[1].S */
+ verts[0][1][1] = tTop; /* v[0].attr[1].T */
+ verts[1][1][0] = sRight;
+ verts[1][1][1] = tTop;
+ verts[2][1][0] = sRight;
+ verts[2][1][1] = tBot;
+ verts[3][1][0] = sLeft;
+ verts[3][1][1] = tBot;
+
+ /* same for all verts: */
+ if (color) {
+ for (i = 0; i < 4; i++) {
+ verts[i][0][2] = z; /* v[i].attr[0].z */
+ verts[i][0][3] = 1.0f; /* v[i].attr[0].w */
+ verts[i][2][0] = color[0]; /* v[i].attr[2].r */
+ verts[i][2][1] = color[1]; /* v[i].attr[2].g */
+ verts[i][2][2] = color[2]; /* v[i].attr[2].b */
+ verts[i][2][3] = color[3]; /* v[i].attr[2].a */
+ verts[i][1][2] = 0.0f; /* v[i].attr[1].R */
+ verts[i][1][3] = 1.0f; /* v[i].attr[1].Q */
+ }
+ }
+ else {
+ for (i = 0; i < 4; i++) {
+ verts[i][0][2] = z; /*Z*/
+ verts[i][0][3] = 1.0f; /*W*/
+ verts[i][1][2] = 0.0f; /*R*/
+ verts[i][1][3] = 1.0f; /*Q*/
+ }
+ }
+ }
+
+ {
+ struct pipe_resource *buf;
+
+ /* allocate/load buffer object with vertex data */
+ buf = pipe_buffer_create(pipe->screen,
+ PIPE_BIND_VERTEX_BUFFER,
+ PIPE_USAGE_STATIC,
+ sizeof(verts));
+ pipe_buffer_write(st->pipe, buf, 0, sizeof(verts), verts);
+
+ util_draw_vertex_buffer(pipe, st->cso_context, buf, 0,
+ PIPE_PRIM_QUADS,
+ 4, /* verts */
+ 3); /* attribs/vert */
+ pipe_resource_reference(&buf, NULL);
+ }
+}
+
+
+
+static void
+draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
+ GLsizei width, GLsizei height,
+ GLfloat zoomX, GLfloat zoomY,
+ struct pipe_sampler_view **sv,
+ int num_sampler_view,
+ void *driver_vp,
+ void *driver_fp,
+ const GLfloat *color,
+ GLboolean invertTex,
+ GLboolean write_depth, GLboolean write_stencil)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct cso_context *cso = st->cso_context;
+ GLfloat x0, y0, x1, y1;
+ GLsizei maxSize;
+ boolean normalized = sv[0]->texture->target != PIPE_TEXTURE_RECT;
+
+ /* limit checks */
+ /* XXX if DrawPixels image is larger than max texture size, break
+ * it up into chunks.
+ */
+ maxSize = 1 << (pipe->screen->get_param(pipe->screen,
+ PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
+ assert(width <= maxSize);
+ assert(height <= maxSize);
+
+ cso_save_rasterizer(cso);
+ cso_save_viewport(cso);
+ cso_save_samplers(cso);
+ cso_save_fragment_sampler_views(cso);
+ cso_save_fragment_shader(cso);
+ cso_save_vertex_shader(cso);
+ cso_save_vertex_elements(cso);
+ cso_save_vertex_buffers(cso);
+ if (write_stencil) {
+ cso_save_depth_stencil_alpha(cso);
+ cso_save_blend(cso);
+ }
+
+ /* rasterizer state: just scissor */
+ {
+ struct pipe_rasterizer_state rasterizer;
+ memset(&rasterizer, 0, sizeof(rasterizer));
+ rasterizer.gl_rasterization_rules = 1;
+ rasterizer.scissor = ctx->Scissor.Enabled;
+ cso_set_rasterizer(cso, &rasterizer);
+ }
+
+ if (write_stencil) {
+ /* Stencil writing bypasses the normal fragment pipeline to
+ * disable color writing and set stencil test to always pass.
+ */
+ struct pipe_depth_stencil_alpha_state dsa;
+ struct pipe_blend_state blend;
+
+ /* depth/stencil */
+ memset(&dsa, 0, sizeof(dsa));
+ dsa.stencil[0].enabled = 1;
+ dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
+ dsa.stencil[0].writemask = ctx->Stencil.WriteMask[0] & 0xff;
+ dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
+ if (write_depth) {
+ /* writing depth+stencil: depth test always passes */
+ dsa.depth.enabled = 1;
+ dsa.depth.writemask = ctx->Depth.Mask;
+ dsa.depth.func = PIPE_FUNC_ALWAYS;
+ }
+ cso_set_depth_stencil_alpha(cso, &dsa);
+
+ /* blend (colormask) */
+ memset(&blend, 0, sizeof(blend));
+ cso_set_blend(cso, &blend);
+ }
+
+ /* fragment shader state: TEX lookup program */
+ cso_set_fragment_shader_handle(cso, driver_fp);
+
+ /* vertex shader state: position + texcoord pass-through */
+ cso_set_vertex_shader_handle(cso, driver_vp);
+
+
+ /* texture sampling state: */
+ {
+ struct pipe_sampler_state sampler;
+ memset(&sampler, 0, sizeof(sampler));
+ sampler.wrap_s = PIPE_TEX_WRAP_CLAMP;
+ sampler.wrap_t = PIPE_TEX_WRAP_CLAMP;
+ sampler.wrap_r = PIPE_TEX_WRAP_CLAMP;
+ sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST;
+ sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
+ sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
+ sampler.normalized_coords = normalized;
+
+ cso_single_sampler(cso, 0, &sampler);
+ if (num_sampler_view > 1) {
+ cso_single_sampler(cso, 1, &sampler);
+ }
+ cso_single_sampler_done(cso);
+ }
+
+ /* viewport state: viewport matching window dims */
+ {
+ const float w = (float) ctx->DrawBuffer->Width;
+ const float h = (float) ctx->DrawBuffer->Height;
+ struct pipe_viewport_state vp;
+ vp.scale[0] = 0.5f * w;
+ vp.scale[1] = -0.5f * h;
+ vp.scale[2] = 0.5f;
+ vp.scale[3] = 1.0f;
+ vp.translate[0] = 0.5f * w;
+ vp.translate[1] = 0.5f * h;
+ vp.translate[2] = 0.5f;
+ vp.translate[3] = 0.0f;
+ cso_set_viewport(cso, &vp);
+ }
+
+ cso_set_vertex_elements(cso, 3, st->velems_util_draw);
+
+ /* texture state: */
+ cso_set_fragment_sampler_views(cso, num_sampler_view, sv);
+
+ /* Compute Gallium window coords (y=0=top) with pixel zoom.
+ * Recall that these coords are transformed by the current
+ * vertex shader and viewport transformation.
+ */
+ if (st_fb_orientation(ctx->DrawBuffer) == Y_0_BOTTOM) {
+ y = ctx->DrawBuffer->Height - (int) (y + height * ctx->Pixel.ZoomY);
+ invertTex = !invertTex;
+ }
+
+ x0 = (GLfloat) x;
+ x1 = x + width * ctx->Pixel.ZoomX;
+ y0 = (GLfloat) y;
+ y1 = y + height * ctx->Pixel.ZoomY;
+
+ /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
+ z = z * 2.0 - 1.0;
+
+ draw_quad(ctx, x0, y0, z, x1, y1, color, invertTex,
+ normalized ? ((GLfloat) width / sv[0]->texture->width0) : (GLfloat)width,
+ normalized ? ((GLfloat) height / sv[0]->texture->height0) : (GLfloat)height);
+
+ /* restore state */
+ cso_restore_rasterizer(cso);
+ cso_restore_viewport(cso);
+ cso_restore_samplers(cso);
+ cso_restore_fragment_sampler_views(cso);
+ cso_restore_fragment_shader(cso);
+ cso_restore_vertex_shader(cso);
+ cso_restore_vertex_elements(cso);
+ cso_restore_vertex_buffers(cso);
+ if (write_stencil) {
+ cso_restore_depth_stencil_alpha(cso);
+ cso_restore_blend(cso);
+ }
+}
+
+
+/**
+ * Software fallback to do glDrawPixels(GL_STENCIL_INDEX) when we
+ * can't use a fragment shader to write stencil values.
+ */
+static void
+draw_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height, GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct st_renderbuffer *strb;
+ enum pipe_transfer_usage usage;
+ struct pipe_transfer *pt;
+ const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
+ GLint skipPixels;
+ ubyte *stmap;
+ struct gl_pixelstore_attrib clippedUnpack = *unpack;
+
+ if (!zoom) {
+ if (!_mesa_clip_drawpixels(ctx, &x, &y, &width, &height,
+ &clippedUnpack)) {
+ /* totally clipped */
+ return;
+ }
+ }
+
+ strb = st_renderbuffer(ctx->DrawBuffer->
+ Attachment[BUFFER_STENCIL].Renderbuffer);
+
+ if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
+ y = ctx->DrawBuffer->Height - y - height;
+ }
+
+ if(format != GL_DEPTH_STENCIL &&
+ util_format_get_component_bits(strb->format,
+ UTIL_FORMAT_COLORSPACE_ZS, 0) != 0)
+ usage = PIPE_TRANSFER_READ_WRITE;
+ else
+ usage = PIPE_TRANSFER_WRITE;
+
+ pt = pipe_get_transfer(st_context(ctx)->pipe, strb->texture, 0, 0,
+ usage, x, y,
+ width, height);
+
+ stmap = pipe_transfer_map(pipe, pt);
+
+ pixels = _mesa_map_pbo_source(ctx, &clippedUnpack, pixels);
+ assert(pixels);
+
+ /* if width > MAX_WIDTH, have to process image in chunks */
+ skipPixels = 0;
+ while (skipPixels < width) {
+ const GLint spanX = skipPixels;
+ const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
+ GLint row;
+ for (row = 0; row < height; row++) {
+ GLubyte sValues[MAX_WIDTH];
+ GLuint zValues[MAX_WIDTH];
+ GLenum destType = GL_UNSIGNED_BYTE;
+ const GLvoid *source = _mesa_image_address2d(&clippedUnpack, pixels,
+ width, height,
+ format, type,
+ row, skipPixels);
+ _mesa_unpack_stencil_span(ctx, spanWidth, destType, sValues,
+ type, source, &clippedUnpack,
+ ctx->_ImageTransferState);
+
+ if (format == GL_DEPTH_STENCIL) {
+ _mesa_unpack_depth_span(ctx, spanWidth, GL_UNSIGNED_INT, zValues,
+ (1 << 24) - 1, type, source,
+ &clippedUnpack);
+ }
+
+ if (zoom) {
+ _mesa_problem(ctx, "Gallium glDrawPixels(GL_STENCIL) with "
+ "zoom not complete");
+ }
+
+ {
+ GLint spanY;
+
+ if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
+ spanY = height - row - 1;
+ }
+ else {
+ spanY = row;
+ }
+
+ /* now pack the stencil (and Z) values in the dest format */
+ switch (pt->resource->format) {
+ case PIPE_FORMAT_S8_USCALED:
+ {
+ ubyte *dest = stmap + spanY * pt->stride + spanX;
+ assert(usage == PIPE_TRANSFER_WRITE);
+ memcpy(dest, sValues, spanWidth);
+ }
+ break;
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ if (format == GL_DEPTH_STENCIL) {
+ uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4);
+ GLint k;
+ assert(usage == PIPE_TRANSFER_WRITE);
+ for (k = 0; k < spanWidth; k++) {
+ dest[k] = zValues[k] | (sValues[k] << 24);
+ }
+ }
+ else {
+ uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4);
+ GLint k;
+ assert(usage == PIPE_TRANSFER_READ_WRITE);
+ for (k = 0; k < spanWidth; k++) {
+ dest[k] = (dest[k] & 0xffffff) | (sValues[k] << 24);
+ }
+ }
+ break;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ if (format == GL_DEPTH_STENCIL) {
+ uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4);
+ GLint k;
+ assert(usage == PIPE_TRANSFER_WRITE);
+ for (k = 0; k < spanWidth; k++) {
+ dest[k] = (zValues[k] << 8) | (sValues[k] & 0xff);
+ }
+ }
+ else {
+ uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4);
+ GLint k;
+ assert(usage == PIPE_TRANSFER_READ_WRITE);
+ for (k = 0; k < spanWidth; k++) {
+ dest[k] = (dest[k] & 0xffffff00) | (sValues[k] & 0xff);
+ }
+ }
+ break;
+ default:
+ assert(0);
+ }
+ }
+ }
+ skipPixels += spanWidth;
+ }
+
+ _mesa_unmap_pbo_source(ctx, &clippedUnpack);
+
+ /* unmap the stencil buffer */
+ pipe_transfer_unmap(pipe, pt);
+ pipe->transfer_destroy(pipe, pt);
+}
+
+
+/**
+ * Get fragment program variant for a glDrawPixels or glCopyPixels
+ * command for RGBA data.
+ */
+static struct st_fp_variant *
+get_color_fp_variant(struct st_context *st)
+{
+ struct gl_context *ctx = st->ctx;
+ struct st_fp_variant_key key;
+ struct st_fp_variant *fpv;
+
+ memset(&key, 0, sizeof(key));
+
+ key.st = st;
+ key.drawpixels = 1;
+ key.scaleAndBias = (ctx->Pixel.RedBias != 0.0 ||
+ ctx->Pixel.RedScale != 1.0 ||
+ ctx->Pixel.GreenBias != 0.0 ||
+ ctx->Pixel.GreenScale != 1.0 ||
+ ctx->Pixel.BlueBias != 0.0 ||
+ ctx->Pixel.BlueScale != 1.0 ||
+ ctx->Pixel.AlphaBias != 0.0 ||
+ ctx->Pixel.AlphaScale != 1.0);
+ key.pixelMaps = ctx->Pixel.MapColorFlag;
+
+ fpv = st_get_fp_variant(st, st->fp, &key);
+
+ return fpv;
+}
+
+
+/**
+ * Get fragment program variant for a glDrawPixels or glCopyPixels
+ * command for depth/stencil data.
+ */
+static struct st_fp_variant *
+get_depth_stencil_fp_variant(struct st_context *st, GLboolean write_depth,
+ GLboolean write_stencil)
+{
+ struct st_fp_variant_key key;
+ struct st_fp_variant *fpv;
+
+ memset(&key, 0, sizeof(key));
+
+ key.st = st;
+ key.drawpixels = 1;
+ key.drawpixels_z = write_depth;
+ key.drawpixels_stencil = write_stencil;
+
+ fpv = st_get_fp_variant(st, st->fp, &key);
+
+ return fpv;
+}
+
+
+/**
+ * Called via ctx->Driver.DrawPixels()
+ */
+static void
+st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels)
+{
+ void *driver_vp, *driver_fp;
+ struct st_context *st = st_context(ctx);
+ const GLfloat *color;
+ struct pipe_context *pipe = st->pipe;
+ GLboolean write_stencil = GL_FALSE, write_depth = GL_FALSE;
+ struct pipe_sampler_view *sv[2];
+ int num_sampler_view = 1;
+ enum pipe_format stencil_format = PIPE_FORMAT_NONE;
+ struct st_fp_variant *fpv;
+
+ if (format == GL_DEPTH_STENCIL)
+ write_stencil = write_depth = GL_TRUE;
+ else if (format == GL_STENCIL_INDEX)
+ write_stencil = GL_TRUE;
+ else if (format == GL_DEPTH_COMPONENT)
+ write_depth = GL_TRUE;
+
+ if (write_stencil) {
+ enum pipe_format tex_format;
+ /* can we write to stencil if not fallback */
+ if (!pipe->screen->get_param(pipe->screen, PIPE_CAP_SHADER_STENCIL_EXPORT))
+ goto stencil_fallback;
+
+ tex_format = st_choose_format(st->pipe->screen, base_format(format),
+ PIPE_TEXTURE_2D,
+ 0, PIPE_BIND_SAMPLER_VIEW);
+ if (tex_format == PIPE_FORMAT_Z24_UNORM_S8_USCALED)
+ stencil_format = PIPE_FORMAT_X24S8_USCALED;
+ else if (tex_format == PIPE_FORMAT_S8_USCALED_Z24_UNORM)
+ stencil_format = PIPE_FORMAT_S8X24_USCALED;
+ else
+ stencil_format = PIPE_FORMAT_S8_USCALED;
+ if (stencil_format == PIPE_FORMAT_NONE)
+ goto stencil_fallback;
+ }
+
+ /* Mesa state should be up to date by now */
+ assert(ctx->NewState == 0x0);
+
+ st_validate_state(st);
+
+ /*
+ * Get vertex/fragment shaders
+ */
+ if (write_depth || write_stencil) {
+ fpv = get_depth_stencil_fp_variant(st, write_depth, write_stencil);
+
+ driver_fp = fpv->driver_shader;
+
+ driver_vp = make_passthrough_vertex_shader(st, GL_TRUE);
+
+ color = ctx->Current.RasterColor;
+ }
+ else {
+ fpv = get_color_fp_variant(st);
+
+ driver_fp = fpv->driver_shader;
+
+ driver_vp = make_passthrough_vertex_shader(st, GL_FALSE);
+
+ color = NULL;
+ if (st->pixel_xfer.pixelmap_enabled) {
+ sv[1] = st->pixel_xfer.pixelmap_sampler_view;
+ num_sampler_view++;
+ }
+ }
+
+ /* update fragment program constants */
+ st_upload_constants(st, fpv->parameters, PIPE_SHADER_FRAGMENT);
+
+ /* draw with textured quad */
+ {
+ struct pipe_resource *pt
+ = make_texture(st, width, height, format, type, unpack, pixels);
+ if (pt) {
+ sv[0] = st_create_texture_sampler_view(st->pipe, pt);
+
+ if (sv[0]) {
+ if (write_stencil) {
+ sv[1] = st_create_texture_sampler_view_format(st->pipe, pt,
+ stencil_format);
+ num_sampler_view++;
+ }
+
+ draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
+ width, height,
+ ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
+ sv,
+ num_sampler_view,
+ driver_vp,
+ driver_fp,
+ color, GL_FALSE, write_depth, write_stencil);
+ pipe_sampler_view_reference(&sv[0], NULL);
+ if (num_sampler_view > 1)
+ pipe_sampler_view_reference(&sv[1], NULL);
+ }
+ pipe_resource_reference(&pt, NULL);
+ }
+ }
+ return;
+
+stencil_fallback:
+ draw_stencil_pixels(ctx, x, y, width, height, format, type,
+ unpack, pixels);
+}
+
+
+
+/**
+ * Software fallback for glCopyPixels(GL_STENCIL).
+ */
+static void
+copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
+ GLsizei width, GLsizei height,
+ GLint dstx, GLint dsty)
+{
+ struct st_renderbuffer *rbDraw;
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ enum pipe_transfer_usage usage;
+ struct pipe_transfer *ptDraw;
+ ubyte *drawMap;
+ ubyte *buffer;
+ int i;
+
+ buffer = malloc(width * height * sizeof(ubyte));
+ if (!buffer) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels(stencil)");
+ return;
+ }
+
+ /* Get the dest renderbuffer. If there's a wrapper, use the
+ * underlying renderbuffer.
+ */
+ rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer);
+ if (rbDraw->Base.Wrapped)
+ rbDraw = st_renderbuffer(rbDraw->Base.Wrapped);
+
+ /* this will do stencil pixel transfer ops */
+ st_read_stencil_pixels(ctx, srcx, srcy, width, height,
+ GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,
+ &ctx->DefaultPacking, buffer);
+
+ if (0) {
+ /* debug code: dump stencil values */
+ GLint row, col;
+ for (row = 0; row < height; row++) {
+ printf("%3d: ", row);
+ for (col = 0; col < width; col++) {
+ printf("%02x ", buffer[col + row * width]);
+ }
+ printf("\n");
+ }
+ }
+
+ if (util_format_get_component_bits(rbDraw->format,
+ UTIL_FORMAT_COLORSPACE_ZS, 0) != 0)
+ usage = PIPE_TRANSFER_READ_WRITE;
+ else
+ usage = PIPE_TRANSFER_WRITE;
+
+ if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
+ dsty = rbDraw->Base.Height - dsty - height;
+ }
+
+ ptDraw = pipe_get_transfer(st_context(ctx)->pipe,
+ rbDraw->texture, 0, 0,
+ usage, dstx, dsty,
+ width, height);
+
+ assert(util_format_get_blockwidth(ptDraw->resource->format) == 1);
+ assert(util_format_get_blockheight(ptDraw->resource->format) == 1);
+
+ /* map the stencil buffer */
+ drawMap = pipe_transfer_map(pipe, ptDraw);
+
+ /* draw */
+ /* XXX PixelZoom not handled yet */
+ for (i = 0; i < height; i++) {
+ ubyte *dst;
+ const ubyte *src;
+ int y;
+
+ y = i;
+
+ if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
+ y = height - y - 1;
+ }
+
+ dst = drawMap + y * ptDraw->stride;
+ src = buffer + i * width;
+
+ switch (ptDraw->resource->format) {
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ {
+ uint *dst4 = (uint *) dst;
+ int j;
+ assert(usage == PIPE_TRANSFER_READ_WRITE);
+ for (j = 0; j < width; j++) {
+ *dst4 = (*dst4 & 0xffffff) | (src[j] << 24);
+ dst4++;
+ }
+ }
+ break;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ {
+ uint *dst4 = (uint *) dst;
+ int j;
+ assert(usage == PIPE_TRANSFER_READ_WRITE);
+ for (j = 0; j < width; j++) {
+ *dst4 = (*dst4 & 0xffffff00) | (src[j] & 0xff);
+ dst4++;
+ }
+ }
+ break;
+ case PIPE_FORMAT_S8_USCALED:
+ assert(usage == PIPE_TRANSFER_WRITE);
+ memcpy(dst, src, width);
+ break;
+ default:
+ assert(0);
+ }
+ }
+
+ free(buffer);
+
+ /* unmap the stencil buffer */
+ pipe_transfer_unmap(pipe, ptDraw);
+ pipe->transfer_destroy(pipe, ptDraw);
+}
+
+
+/** Do the src/dest regions overlap? */
+static GLboolean
+regions_overlap(GLint srcX, GLint srcY, GLint dstX, GLint dstY,
+ GLsizei width, GLsizei height)
+{
+ if (srcX + width <= dstX ||
+ dstX + width <= srcX ||
+ srcY + height <= dstY ||
+ dstY + height <= srcY)
+ return GL_FALSE;
+ else
+ return GL_TRUE;
+}
+
+
+/**
+ * Try to do a glCopyPixels for simple cases with a blit by calling
+ * pipe->resource_copy_region().
+ *
+ * We can do this when we're copying color pixels (depth/stencil
+ * eventually) with no pixel zoom, no pixel transfer ops, no
+ * per-fragment ops, the src/dest regions don't overlap and the
+ * src/dest pixel formats are the same.
+ */
+static GLboolean
+blit_copy_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
+ GLsizei width, GLsizei height,
+ GLint dstx, GLint dsty, GLenum type)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct gl_pixelstore_attrib pack, unpack;
+ GLint readX, readY, readW, readH;
+
+ if (type == GL_COLOR &&
+ ctx->Pixel.ZoomX == 1.0 &&
+ ctx->Pixel.ZoomY == 1.0 &&
+ ctx->_ImageTransferState == 0x0 &&
+ !ctx->Color.BlendEnabled &&
+ !ctx->Color.AlphaEnabled &&
+ !ctx->Depth.Test &&
+ !ctx->Fog.Enabled &&
+ !ctx->Stencil.Enabled &&
+ !ctx->FragmentProgram.Enabled &&
+ !ctx->VertexProgram.Enabled &&
+ !ctx->Shader.CurrentFragmentProgram &&
+ st_fb_orientation(ctx->ReadBuffer) == st_fb_orientation(ctx->DrawBuffer) &&
+ ctx->DrawBuffer->_NumColorDrawBuffers == 1) {
+ struct st_renderbuffer *rbRead, *rbDraw;
+ GLint drawX, drawY;
+
+ /*
+ * Clip the read region against the src buffer bounds.
+ * We'll still allocate a temporary buffer/texture for the original
+ * src region size but we'll only read the region which is on-screen.
+ * This may mean that we draw garbage pixels into the dest region, but
+ * that's expected.
+ */
+ readX = srcx;
+ readY = srcy;
+ readW = width;
+ readH = height;
+ pack = ctx->DefaultPacking;
+ if (!_mesa_clip_readpixels(ctx, &readX, &readY, &readW, &readH, &pack))
+ return GL_TRUE; /* all done */
+
+ /* clip against dest buffer bounds and scissor box */
+ drawX = dstx + pack.SkipPixels;
+ drawY = dsty + pack.SkipRows;
+ unpack = pack;
+ if (!_mesa_clip_drawpixels(ctx, &drawX, &drawY, &readW, &readH, &unpack))
+ return GL_TRUE; /* all done */
+
+ readX = readX - pack.SkipPixels + unpack.SkipPixels;
+ readY = readY - pack.SkipRows + unpack.SkipRows;
+
+ rbRead = st_get_color_read_renderbuffer(ctx);
+ rbDraw = st_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
+
+ if ((rbRead != rbDraw ||
+ !regions_overlap(readX, readY, drawX, drawY, readW, readH)) &&
+ rbRead->Base.Format == rbDraw->Base.Format) {
+ struct pipe_box srcBox;
+
+ /* flip src/dst position if needed */
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ /* both buffers will have the same orientation */
+ readY = ctx->ReadBuffer->Height - readY - readH;
+ drawY = ctx->DrawBuffer->Height - drawY - readH;
+ }
+
+ u_box_2d(readX, readY, readW, readH, &srcBox);
+
+ pipe->resource_copy_region(pipe,
+ rbDraw->texture, 0, drawX, drawY, 0,
+ rbRead->texture, 0, &srcBox);
+ return GL_TRUE;
+ }
+ }
+
+ return GL_FALSE;
+}
+
+
+static void
+st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
+ GLsizei width, GLsizei height,
+ GLint dstx, GLint dsty, GLenum type)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_screen *screen = pipe->screen;
+ struct st_renderbuffer *rbRead;
+ void *driver_vp, *driver_fp;
+ struct pipe_resource *pt;
+ struct pipe_sampler_view *sv[2];
+ int num_sampler_view = 1;
+ GLfloat *color;
+ enum pipe_format srcFormat, texFormat;
+ GLboolean invertTex = GL_FALSE;
+ GLint readX, readY, readW, readH;
+ GLuint sample_count;
+ struct gl_pixelstore_attrib pack = ctx->DefaultPacking;
+ struct st_fp_variant *fpv;
+
+ st_validate_state(st);
+
+ if (type == GL_STENCIL) {
+ /* can't use texturing to do stencil */
+ copy_stencil_pixels(ctx, srcx, srcy, width, height, dstx, dsty);
+ return;
+ }
+
+ if (blit_copy_pixels(ctx, srcx, srcy, width, height, dstx, dsty, type))
+ return;
+
+ /*
+ * The subsequent code implements glCopyPixels by copying the source
+ * pixels into a temporary texture that's then applied to a textured quad.
+ * When we draw the textured quad, all the usual per-fragment operations
+ * are handled.
+ */
+
+
+ /*
+ * Get vertex/fragment shaders
+ */
+ if (type == GL_COLOR) {
+ rbRead = st_get_color_read_renderbuffer(ctx);
+ color = NULL;
+
+ fpv = get_color_fp_variant(st);
+ driver_fp = fpv->driver_shader;
+
+ driver_vp = make_passthrough_vertex_shader(st, GL_FALSE);
+
+ if (st->pixel_xfer.pixelmap_enabled) {
+ sv[1] = st->pixel_xfer.pixelmap_sampler_view;
+ num_sampler_view++;
+ }
+ }
+ else {
+ assert(type == GL_DEPTH);
+ rbRead = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer);
+ color = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
+
+ fpv = get_depth_stencil_fp_variant(st, GL_TRUE, GL_FALSE);
+ driver_fp = fpv->driver_shader;
+
+ driver_vp = make_passthrough_vertex_shader(st, GL_TRUE);
+ }
+
+ /* update fragment program constants */
+ st_upload_constants(st, fpv->parameters, PIPE_SHADER_FRAGMENT);
+
+
+ if (rbRead->Base.Wrapped)
+ rbRead = st_renderbuffer(rbRead->Base.Wrapped);
+
+ sample_count = rbRead->texture->nr_samples;
+ /* I believe this would be legal, presumably would need to do a resolve
+ for color, and for depth/stencil spec says to just use one of the
+ depth/stencil samples per pixel? Need some transfer clarifications. */
+ assert(sample_count < 2);
+
+ srcFormat = rbRead->texture->format;
+
+ if (screen->is_format_supported(screen, srcFormat, st->internal_target,
+ sample_count,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
+ texFormat = srcFormat;
+ }
+ else {
+ /* srcFormat can't be used as a texture format */
+ if (type == GL_DEPTH) {
+ texFormat = st_choose_format(screen, GL_DEPTH_COMPONENT,
+ st->internal_target, sample_count,
+ PIPE_BIND_DEPTH_STENCIL);
+ assert(texFormat != PIPE_FORMAT_NONE);
+ }
+ else {
+ /* default color format */
+ texFormat = st_choose_format(screen, GL_RGBA, st->internal_target,
+ sample_count, PIPE_BIND_SAMPLER_VIEW);
+ assert(texFormat != PIPE_FORMAT_NONE);
+ }
+ }
+
+ /* Invert src region if needed */
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ srcy = ctx->ReadBuffer->Height - srcy - height;
+ invertTex = !invertTex;
+ }
+
+ /* Clip the read region against the src buffer bounds.
+ * We'll still allocate a temporary buffer/texture for the original
+ * src region size but we'll only read the region which is on-screen.
+ * This may mean that we draw garbage pixels into the dest region, but
+ * that's expected.
+ */
+ readX = srcx;
+ readY = srcy;
+ readW = width;
+ readH = height;
+ _mesa_clip_readpixels(ctx, &readX, &readY, &readW, &readH, &pack);
+ readW = MAX2(0, readW);
+ readH = MAX2(0, readH);
+
+ /* alloc temporary texture */
+ pt = alloc_texture(st, width, height, texFormat);
+ if (!pt)
+ return;
+
+ sv[0] = st_create_texture_sampler_view(st->pipe, pt);
+ if (!sv[0]) {
+ pipe_resource_reference(&pt, NULL);
+ return;
+ }
+
+ /* Make temporary texture which is a copy of the src region.
+ */
+ if (srcFormat == texFormat) {
+ struct pipe_box src_box;
+ u_box_2d(readX, readY, readW, readH, &src_box);
+ /* copy source framebuffer surface into mipmap/texture */
+ pipe->resource_copy_region(pipe,
+ pt, /* dest tex */
+ 0,
+ pack.SkipPixels, pack.SkipRows, 0, /* dest pos */
+ rbRead->texture, /* src tex */
+ 0,
+ &src_box);
+
+ }
+ else {
+ /* CPU-based fallback/conversion */
+ struct pipe_transfer *ptRead =
+ pipe_get_transfer(st->pipe, rbRead->texture,
+ 0, 0, /* level, layer */
+ PIPE_TRANSFER_READ,
+ readX, readY, readW, readH);
+ struct pipe_transfer *ptTex;
+ enum pipe_transfer_usage transfer_usage;
+
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
+
+ if (type == GL_DEPTH && util_format_is_depth_and_stencil(pt->format))
+ transfer_usage = PIPE_TRANSFER_READ_WRITE;
+ else
+ transfer_usage = PIPE_TRANSFER_WRITE;
+
+ ptTex = pipe_get_transfer(st->pipe, pt, 0, 0, transfer_usage,
+ 0, 0, width, height);
+
+ /* copy image from ptRead surface to ptTex surface */
+ if (type == GL_COLOR) {
+ /* alternate path using get/put_tile() */
+ GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+ enum pipe_format readFormat, drawFormat;
+ readFormat = util_format_linear(rbRead->texture->format);
+ drawFormat = util_format_linear(pt->format);
+ pipe_get_tile_rgba_format(pipe, ptRead, 0, 0, readW, readH,
+ readFormat, buf);
+ pipe_put_tile_rgba_format(pipe, ptTex, pack.SkipPixels, pack.SkipRows,
+ readW, readH, drawFormat, buf);
+ free(buf);
+ }
+ else {
+ /* GL_DEPTH */
+ GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint));
+ pipe_get_tile_z(pipe, ptRead, 0, 0, readW, readH, buf);
+ pipe_put_tile_z(pipe, ptTex, pack.SkipPixels, pack.SkipRows,
+ readW, readH, buf);
+ free(buf);
+ }
+
+ pipe->transfer_destroy(pipe, ptRead);
+ pipe->transfer_destroy(pipe, ptTex);
+ }
+
+ /* OK, the texture 'pt' contains the src image/pixels. Now draw a
+ * textured quad with that texture.
+ */
+ draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2],
+ width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
+ sv,
+ num_sampler_view,
+ driver_vp,
+ driver_fp,
+ color, invertTex, GL_FALSE, GL_FALSE);
+
+ pipe_resource_reference(&pt, NULL);
+ pipe_sampler_view_reference(&sv[0], NULL);
+}
+
+
+
+void st_init_drawpixels_functions(struct dd_function_table *functions)
+{
+ functions->DrawPixels = st_DrawPixels;
+ functions->CopyPixels = st_CopyPixels;
+}
+
+
+void
+st_destroy_drawpix(struct st_context *st)
+{
+ GLuint i;
+
+ for (i = 0; i < Elements(st->drawpix.shaders); i++) {
+ if (st->drawpix.shaders[i])
+ _mesa_reference_fragprog(st->ctx, &st->drawpix.shaders[i], NULL);
+ }
+
+ st_reference_fragprog(st, &st->pixel_xfer.combined_prog, NULL);
+ if (st->drawpix.vert_shaders[0])
+ ureg_free_tokens(st->drawpix.vert_shaders[0]);
+ if (st->drawpix.vert_shaders[1])
+ ureg_free_tokens(st->drawpix.vert_shaders[1]);
+}
+
+#endif /* FEATURE_drawpix */
diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawtex.c b/mesalib/src/mesa/state_tracker/st_cb_drawtex.c
index 86ceb9d78..db299eb8d 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_drawtex.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_drawtex.c
@@ -1,307 +1,307 @@
-/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- **************************************************************************/
-
-
-/**
- * Implementation of glDrawTex() for GL_OES_draw_tex
- */
-
-
-
-#include "main/imports.h"
-#include "main/image.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-#include "program/program.h"
-#include "program/prog_print.h"
-
-#include "st_context.h"
-#include "st_atom.h"
-#include "st_cb_drawtex.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-#include "pipe/p_shader_tokens.h"
-#include "util/u_draw_quad.h"
-#include "util/u_simple_shaders.h"
-
-#include "cso_cache/cso_context.h"
-
-
-#if FEATURE_OES_draw_texture
-
-
-struct cached_shader
-{
- void *handle;
-
- uint num_attribs;
- uint semantic_names[2 + MAX_TEXTURE_UNITS];
- uint semantic_indexes[2 + MAX_TEXTURE_UNITS];
-};
-
-#define MAX_SHADERS (2 * MAX_TEXTURE_UNITS)
-
-/**
- * Simple linear list cache.
- * Most of the time there'll only be one cached shader.
- */
-static struct cached_shader CachedShaders[MAX_SHADERS];
-static GLuint NumCachedShaders = 0;
-
-
-static void *
-lookup_shader(struct pipe_context *pipe,
- uint num_attribs,
- const uint *semantic_names,
- const uint *semantic_indexes)
-{
- GLuint i, j;
-
- /* look for existing shader with same attributes */
- for (i = 0; i < NumCachedShaders; i++) {
- if (CachedShaders[i].num_attribs == num_attribs) {
- GLboolean match = GL_TRUE;
- for (j = 0; j < num_attribs; j++) {
- if (semantic_names[j] != CachedShaders[i].semantic_names[j] ||
- semantic_indexes[j] != CachedShaders[i].semantic_indexes[j]) {
- match = GL_FALSE;
- break;
- }
- }
- if (match)
- return CachedShaders[i].handle;
- }
- }
-
- /* not found - create new one now */
- if (NumCachedShaders >= MAX_SHADERS) {
- return NULL;
- }
-
- CachedShaders[i].num_attribs = num_attribs;
- for (j = 0; j < num_attribs; j++) {
- CachedShaders[i].semantic_names[j] = semantic_names[j];
- CachedShaders[i].semantic_indexes[j] = semantic_indexes[j];
- }
-
- CachedShaders[i].handle =
- util_make_vertex_passthrough_shader(pipe,
- num_attribs,
- semantic_names,
- semantic_indexes);
- NumCachedShaders++;
-
- return CachedShaders[i].handle;
-}
-
-static void
-st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
- GLfloat width, GLfloat height)
-{
- struct st_context *st = ctx->st;
- struct pipe_context *pipe = st->pipe;
- struct cso_context *cso = ctx->st->cso_context;
- struct pipe_resource *vbuffer;
- struct pipe_transfer *vbuffer_transfer;
- GLuint i, numTexCoords, numAttribs;
- GLboolean emitColor;
- uint semantic_names[2 + MAX_TEXTURE_UNITS];
- uint semantic_indexes[2 + MAX_TEXTURE_UNITS];
- struct pipe_vertex_element velements[2 + MAX_TEXTURE_UNITS];
- GLbitfield inputs = VERT_BIT_POS;
-
- st_validate_state(st);
-
- /* determine if we need vertex color */
- if (ctx->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_COL0)
- emitColor = GL_TRUE;
- else
- emitColor = GL_FALSE;
-
- /* determine how many enabled sets of texcoords */
- numTexCoords = 0;
- for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
- if (ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_2D_BIT) {
- inputs |= VERT_BIT_TEX(i);
- numTexCoords++;
- }
- }
-
- /* total number of attributes per vertex */
- numAttribs = 1 + emitColor + numTexCoords;
-
-
- /* create the vertex buffer */
- vbuffer = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER,
- PIPE_USAGE_STREAM,
- numAttribs * 4 * 4 * sizeof(GLfloat));
-
- /* load vertex buffer */
- {
-#define SET_ATTRIB(VERT, ATTR, X, Y, Z, W) \
- do { \
- GLuint k = (((VERT) * numAttribs + (ATTR)) * 4); \
- assert(k < 4 * 4 * numAttribs); \
- vbuf[k + 0] = X; \
- vbuf[k + 1] = Y; \
- vbuf[k + 2] = Z; \
- vbuf[k + 3] = W; \
- } while (0)
-
- const GLfloat x0 = x, y0 = y, x1 = x + width, y1 = y + height;
- GLfloat *vbuf = (GLfloat *) pipe_buffer_map(pipe, vbuffer,
- PIPE_TRANSFER_WRITE,
- &vbuffer_transfer);
- GLuint attr;
-
- z = CLAMP(z, 0.0f, 1.0f);
-
- /* positions (in clip coords) */
- {
- const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
- const GLfloat fb_width = (GLfloat)fb->Width;
- const GLfloat fb_height = (GLfloat)fb->Height;
-
- const GLfloat clip_x0 = (GLfloat)(x0 / fb_width * 2.0 - 1.0);
- const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0);
- const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0);
- const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0);
-
- SET_ATTRIB(0, 0, clip_x0, clip_y0, z, 1.0f); /* lower left */
- SET_ATTRIB(1, 0, clip_x1, clip_y0, z, 1.0f); /* lower right */
- SET_ATTRIB(2, 0, clip_x1, clip_y1, z, 1.0f); /* upper right */
- SET_ATTRIB(3, 0, clip_x0, clip_y1, z, 1.0f); /* upper left */
-
- semantic_names[0] = TGSI_SEMANTIC_POSITION;
- semantic_indexes[0] = 0;
- }
-
- /* colors */
- if (emitColor) {
- const GLfloat *c = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
- SET_ATTRIB(0, 1, c[0], c[1], c[2], c[3]);
- SET_ATTRIB(1, 1, c[0], c[1], c[2], c[3]);
- SET_ATTRIB(2, 1, c[0], c[1], c[2], c[3]);
- SET_ATTRIB(3, 1, c[0], c[1], c[2], c[3]);
- semantic_names[1] = TGSI_SEMANTIC_COLOR;
- semantic_indexes[1] = 0;
- attr = 2;
- }
- else {
- attr = 1;
- }
-
- /* texcoords */
- for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
- if (ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_2D_BIT) {
- struct gl_texture_object *obj = ctx->Texture.Unit[i]._Current;
- struct gl_texture_image *img = obj->Image[0][obj->BaseLevel];
- const GLfloat wt = (GLfloat) img->Width;
- const GLfloat ht = (GLfloat) img->Height;
- const GLfloat s0 = obj->CropRect[0] / wt;
- const GLfloat t0 = obj->CropRect[1] / ht;
- const GLfloat s1 = (obj->CropRect[0] + obj->CropRect[2]) / wt;
- const GLfloat t1 = (obj->CropRect[1] + obj->CropRect[3]) / ht;
-
- /*printf("crop texcoords: %g, %g .. %g, %g\n", s0, t0, s1, t1);*/
- SET_ATTRIB(0, attr, s0, t0, 0.0f, 1.0f); /* lower left */
- SET_ATTRIB(1, attr, s1, t0, 0.0f, 1.0f); /* lower right */
- SET_ATTRIB(2, attr, s1, t1, 0.0f, 1.0f); /* upper right */
- SET_ATTRIB(3, attr, s0, t1, 0.0f, 1.0f); /* upper left */
-
- semantic_names[attr] = TGSI_SEMANTIC_GENERIC;
- semantic_indexes[attr] = 0;
-
- attr++;
- }
- }
-
- pipe_buffer_unmap(pipe, vbuffer_transfer);
-
-#undef SET_ATTRIB
- }
-
-
- cso_save_viewport(cso);
- cso_save_vertex_shader(cso);
- cso_save_vertex_elements(cso);
- cso_save_vertex_buffers(cso);
-
- {
- void *vs = lookup_shader(pipe, numAttribs,
- semantic_names, semantic_indexes);
- cso_set_vertex_shader_handle(cso, vs);
- }
-
- for (i = 0; i < numAttribs; i++) {
- velements[i].src_offset = i * 4 * sizeof(float);
- velements[i].instance_divisor = 0;
- velements[i].vertex_buffer_index = 0;
- velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
- }
- cso_set_vertex_elements(cso, numAttribs, velements);
-
- /* viewport state: viewport matching window dims */
- {
- const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
- const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP);
- const GLfloat width = (GLfloat)fb->Width;
- const GLfloat height = (GLfloat)fb->Height;
- struct pipe_viewport_state vp;
- vp.scale[0] = 0.5f * width;
- vp.scale[1] = height * (invert ? -0.5f : 0.5f);
- vp.scale[2] = 1.0f;
- vp.scale[3] = 1.0f;
- vp.translate[0] = 0.5f * width;
- vp.translate[1] = 0.5f * height;
- vp.translate[2] = 0.0f;
- vp.translate[3] = 0.0f;
- cso_set_viewport(cso, &vp);
- }
-
-
- util_draw_vertex_buffer(pipe, cso, vbuffer,
- 0, /* offset */
- PIPE_PRIM_TRIANGLE_FAN,
- 4, /* verts */
- numAttribs); /* attribs/vert */
-
-
- pipe_resource_reference(&vbuffer, NULL);
-
- /* restore state */
- cso_restore_viewport(cso);
- cso_restore_vertex_shader(cso);
- cso_restore_vertex_elements(cso);
- cso_restore_vertex_buffers(cso);
-}
-
-
-void
-st_init_drawtex_functions(struct dd_function_table *functions)
-{
- functions->DrawTex = st_DrawTex;
-}
-
-
-/**
- * Free any cached shaders
- */
-void
-st_destroy_drawtex(struct st_context *st)
-{
- GLuint i;
- for (i = 0; i < NumCachedShaders; i++) {
- cso_delete_vertex_shader(st->cso_context, CachedShaders[i].handle);
- }
- NumCachedShaders = 0;
-}
-
-
-#endif /* FEATURE_OES_draw_texture */
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ **************************************************************************/
+
+
+/**
+ * Implementation of glDrawTex() for GL_OES_draw_tex
+ */
+
+
+
+#include "main/imports.h"
+#include "main/image.h"
+#include "main/macros.h"
+#include "main/mfeatures.h"
+#include "program/program.h"
+#include "program/prog_print.h"
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_cb_drawtex.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "pipe/p_shader_tokens.h"
+#include "util/u_draw_quad.h"
+#include "util/u_simple_shaders.h"
+
+#include "cso_cache/cso_context.h"
+
+
+#if FEATURE_OES_draw_texture
+
+
+struct cached_shader
+{
+ void *handle;
+
+ uint num_attribs;
+ uint semantic_names[2 + MAX_TEXTURE_UNITS];
+ uint semantic_indexes[2 + MAX_TEXTURE_UNITS];
+};
+
+#define MAX_SHADERS (2 * MAX_TEXTURE_UNITS)
+
+/**
+ * Simple linear list cache.
+ * Most of the time there'll only be one cached shader.
+ */
+static struct cached_shader CachedShaders[MAX_SHADERS];
+static GLuint NumCachedShaders = 0;
+
+
+static void *
+lookup_shader(struct pipe_context *pipe,
+ uint num_attribs,
+ const uint *semantic_names,
+ const uint *semantic_indexes)
+{
+ GLuint i, j;
+
+ /* look for existing shader with same attributes */
+ for (i = 0; i < NumCachedShaders; i++) {
+ if (CachedShaders[i].num_attribs == num_attribs) {
+ GLboolean match = GL_TRUE;
+ for (j = 0; j < num_attribs; j++) {
+ if (semantic_names[j] != CachedShaders[i].semantic_names[j] ||
+ semantic_indexes[j] != CachedShaders[i].semantic_indexes[j]) {
+ match = GL_FALSE;
+ break;
+ }
+ }
+ if (match)
+ return CachedShaders[i].handle;
+ }
+ }
+
+ /* not found - create new one now */
+ if (NumCachedShaders >= MAX_SHADERS) {
+ return NULL;
+ }
+
+ CachedShaders[i].num_attribs = num_attribs;
+ for (j = 0; j < num_attribs; j++) {
+ CachedShaders[i].semantic_names[j] = semantic_names[j];
+ CachedShaders[i].semantic_indexes[j] = semantic_indexes[j];
+ }
+
+ CachedShaders[i].handle =
+ util_make_vertex_passthrough_shader(pipe,
+ num_attribs,
+ semantic_names,
+ semantic_indexes);
+ NumCachedShaders++;
+
+ return CachedShaders[i].handle;
+}
+
+static void
+st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
+ GLfloat width, GLfloat height)
+{
+ struct st_context *st = ctx->st;
+ struct pipe_context *pipe = st->pipe;
+ struct cso_context *cso = ctx->st->cso_context;
+ struct pipe_resource *vbuffer;
+ struct pipe_transfer *vbuffer_transfer;
+ GLuint i, numTexCoords, numAttribs;
+ GLboolean emitColor;
+ uint semantic_names[2 + MAX_TEXTURE_UNITS];
+ uint semantic_indexes[2 + MAX_TEXTURE_UNITS];
+ struct pipe_vertex_element velements[2 + MAX_TEXTURE_UNITS];
+ GLbitfield inputs = VERT_BIT_POS;
+
+ st_validate_state(st);
+
+ /* determine if we need vertex color */
+ if (ctx->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_COL0)
+ emitColor = GL_TRUE;
+ else
+ emitColor = GL_FALSE;
+
+ /* determine how many enabled sets of texcoords */
+ numTexCoords = 0;
+ for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
+ if (ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_2D_BIT) {
+ inputs |= VERT_BIT_TEX(i);
+ numTexCoords++;
+ }
+ }
+
+ /* total number of attributes per vertex */
+ numAttribs = 1 + emitColor + numTexCoords;
+
+
+ /* create the vertex buffer */
+ vbuffer = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER,
+ PIPE_USAGE_STREAM,
+ numAttribs * 4 * 4 * sizeof(GLfloat));
+
+ /* load vertex buffer */
+ {
+#define SET_ATTRIB(VERT, ATTR, X, Y, Z, W) \
+ do { \
+ GLuint k = (((VERT) * numAttribs + (ATTR)) * 4); \
+ assert(k < 4 * 4 * numAttribs); \
+ vbuf[k + 0] = X; \
+ vbuf[k + 1] = Y; \
+ vbuf[k + 2] = Z; \
+ vbuf[k + 3] = W; \
+ } while (0)
+
+ const GLfloat x0 = x, y0 = y, x1 = x + width, y1 = y + height;
+ GLfloat *vbuf = (GLfloat *) pipe_buffer_map(pipe, vbuffer,
+ PIPE_TRANSFER_WRITE,
+ &vbuffer_transfer);
+ GLuint attr;
+
+ z = CLAMP(z, 0.0f, 1.0f);
+
+ /* positions (in clip coords) */
+ {
+ const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
+ const GLfloat fb_width = (GLfloat)fb->Width;
+ const GLfloat fb_height = (GLfloat)fb->Height;
+
+ const GLfloat clip_x0 = (GLfloat)(x0 / fb_width * 2.0 - 1.0);
+ const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0);
+ const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0);
+ const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0);
+
+ SET_ATTRIB(0, 0, clip_x0, clip_y0, z, 1.0f); /* lower left */
+ SET_ATTRIB(1, 0, clip_x1, clip_y0, z, 1.0f); /* lower right */
+ SET_ATTRIB(2, 0, clip_x1, clip_y1, z, 1.0f); /* upper right */
+ SET_ATTRIB(3, 0, clip_x0, clip_y1, z, 1.0f); /* upper left */
+
+ semantic_names[0] = TGSI_SEMANTIC_POSITION;
+ semantic_indexes[0] = 0;
+ }
+
+ /* colors */
+ if (emitColor) {
+ const GLfloat *c = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
+ SET_ATTRIB(0, 1, c[0], c[1], c[2], c[3]);
+ SET_ATTRIB(1, 1, c[0], c[1], c[2], c[3]);
+ SET_ATTRIB(2, 1, c[0], c[1], c[2], c[3]);
+ SET_ATTRIB(3, 1, c[0], c[1], c[2], c[3]);
+ semantic_names[1] = TGSI_SEMANTIC_COLOR;
+ semantic_indexes[1] = 0;
+ attr = 2;
+ }
+ else {
+ attr = 1;
+ }
+
+ /* texcoords */
+ for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
+ if (ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_2D_BIT) {
+ struct gl_texture_object *obj = ctx->Texture.Unit[i]._Current;
+ struct gl_texture_image *img = obj->Image[0][obj->BaseLevel];
+ const GLfloat wt = (GLfloat) img->Width;
+ const GLfloat ht = (GLfloat) img->Height;
+ const GLfloat s0 = obj->CropRect[0] / wt;
+ const GLfloat t0 = obj->CropRect[1] / ht;
+ const GLfloat s1 = (obj->CropRect[0] + obj->CropRect[2]) / wt;
+ const GLfloat t1 = (obj->CropRect[1] + obj->CropRect[3]) / ht;
+
+ /*printf("crop texcoords: %g, %g .. %g, %g\n", s0, t0, s1, t1);*/
+ SET_ATTRIB(0, attr, s0, t0, 0.0f, 1.0f); /* lower left */
+ SET_ATTRIB(1, attr, s1, t0, 0.0f, 1.0f); /* lower right */
+ SET_ATTRIB(2, attr, s1, t1, 0.0f, 1.0f); /* upper right */
+ SET_ATTRIB(3, attr, s0, t1, 0.0f, 1.0f); /* upper left */
+
+ semantic_names[attr] = TGSI_SEMANTIC_GENERIC;
+ semantic_indexes[attr] = 0;
+
+ attr++;
+ }
+ }
+
+ pipe_buffer_unmap(pipe, vbuffer_transfer);
+
+#undef SET_ATTRIB
+ }
+
+
+ cso_save_viewport(cso);
+ cso_save_vertex_shader(cso);
+ cso_save_vertex_elements(cso);
+ cso_save_vertex_buffers(cso);
+
+ {
+ void *vs = lookup_shader(pipe, numAttribs,
+ semantic_names, semantic_indexes);
+ cso_set_vertex_shader_handle(cso, vs);
+ }
+
+ for (i = 0; i < numAttribs; i++) {
+ velements[i].src_offset = i * 4 * sizeof(float);
+ velements[i].instance_divisor = 0;
+ velements[i].vertex_buffer_index = 0;
+ velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+ }
+ cso_set_vertex_elements(cso, numAttribs, velements);
+
+ /* viewport state: viewport matching window dims */
+ {
+ const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
+ const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP);
+ const GLfloat width = (GLfloat)fb->Width;
+ const GLfloat height = (GLfloat)fb->Height;
+ struct pipe_viewport_state vp;
+ vp.scale[0] = 0.5f * width;
+ vp.scale[1] = height * (invert ? -0.5f : 0.5f);
+ vp.scale[2] = 1.0f;
+ vp.scale[3] = 1.0f;
+ vp.translate[0] = 0.5f * width;
+ vp.translate[1] = 0.5f * height;
+ vp.translate[2] = 0.0f;
+ vp.translate[3] = 0.0f;
+ cso_set_viewport(cso, &vp);
+ }
+
+
+ util_draw_vertex_buffer(pipe, cso, vbuffer,
+ 0, /* offset */
+ PIPE_PRIM_TRIANGLE_FAN,
+ 4, /* verts */
+ numAttribs); /* attribs/vert */
+
+
+ pipe_resource_reference(&vbuffer, NULL);
+
+ /* restore state */
+ cso_restore_viewport(cso);
+ cso_restore_vertex_shader(cso);
+ cso_restore_vertex_elements(cso);
+ cso_restore_vertex_buffers(cso);
+}
+
+
+void
+st_init_drawtex_functions(struct dd_function_table *functions)
+{
+ functions->DrawTex = st_DrawTex;
+}
+
+
+/**
+ * Free any cached shaders
+ */
+void
+st_destroy_drawtex(struct st_context *st)
+{
+ GLuint i;
+ for (i = 0; i < NumCachedShaders; i++) {
+ cso_delete_vertex_shader(st->cso_context, CachedShaders[i].handle);
+ }
+ NumCachedShaders = 0;
+}
+
+
+#endif /* FEATURE_OES_draw_texture */
diff --git a/mesalib/src/mesa/state_tracker/st_cb_readpixels.c b/mesalib/src/mesa/state_tracker/st_cb_readpixels.c
index f8da2a4d1..687a49a57 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_readpixels.c
@@ -1,561 +1,561 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-/**
- * glReadPixels interface to pipe
- *
- * \author Brian Paul
- */
-
-
-#include "main/imports.h"
-#include "main/bufferobj.h"
-#include "main/context.h"
-#include "main/image.h"
-#include "main/pack.h"
-#include "main/pbo.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "util/u_format.h"
-#include "util/u_inlines.h"
-#include "util/u_tile.h"
-
-#include "st_debug.h"
-#include "st_context.h"
-#include "st_atom.h"
-#include "st_cb_bitmap.h"
-#include "st_cb_readpixels.h"
-#include "st_cb_fbo.h"
-
-/**
- * Special case for reading stencil buffer.
- * For color/depth we use get_tile(). For stencil, map the stencil buffer.
- */
-void
-st_read_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *packing,
- GLvoid *pixels)
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer);
- struct pipe_transfer *pt;
- ubyte *stmap;
- GLint j;
-
- if (strb->Base.Wrapped) {
- strb = st_renderbuffer(strb->Base.Wrapped);
- }
-
- if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
- y = ctx->DrawBuffer->Height - y - height;
- }
-
- /* Create a read transfer from the renderbuffer's texture */
-
- pt = pipe_get_transfer(pipe, strb->texture,
- 0, 0,
- PIPE_TRANSFER_READ,
- x, y, width, height);
-
- /* map the stencil buffer */
- stmap = pipe_transfer_map(pipe, pt);
-
- /* width should never be > MAX_WIDTH since we did clipping earlier */
- ASSERT(width <= MAX_WIDTH);
-
- /* process image row by row */
- for (j = 0; j < height; j++) {
- GLvoid *dest;
- GLstencil sValues[MAX_WIDTH];
- GLfloat zValues[MAX_WIDTH];
- GLint srcY;
-
- if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
- srcY = height - j - 1;
- }
- else {
- srcY = j;
- }
-
- /* get stencil (and Z) values */
- switch (pt->resource->format) {
- case PIPE_FORMAT_S8_USCALED:
- {
- const ubyte *src = stmap + srcY * pt->stride;
- memcpy(sValues, src, width);
- }
- break;
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- if (format == GL_DEPTH_STENCIL) {
- const uint *src = (uint *) (stmap + srcY * pt->stride);
- const GLfloat scale = 1.0f / (0xffffff);
- GLint k;
- for (k = 0; k < width; k++) {
- sValues[k] = src[k] >> 24;
- zValues[k] = (src[k] & 0xffffff) * scale;
- }
- }
- else {
- const uint *src = (uint *) (stmap + srcY * pt->stride);
- GLint k;
- for (k = 0; k < width; k++) {
- sValues[k] = src[k] >> 24;
- }
- }
- break;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- if (format == GL_DEPTH_STENCIL) {
- const uint *src = (uint *) (stmap + srcY * pt->stride);
- const GLfloat scale = 1.0f / (0xffffff);
- GLint k;
- for (k = 0; k < width; k++) {
- sValues[k] = src[k] & 0xff;
- zValues[k] = (src[k] >> 8) * scale;
- }
- }
- else {
- const uint *src = (uint *) (stmap + srcY * pt->stride);
- GLint k;
- for (k = 0; k < width; k++) {
- sValues[k] = src[k] & 0xff;
- }
- }
- break;
- default:
- assert(0);
- }
-
- /* store */
- dest = _mesa_image_address2d(packing, pixels, width, height,
- format, type, j, 0);
- if (format == GL_DEPTH_STENCIL) {
- _mesa_pack_depth_stencil_span(ctx, width, dest,
- zValues, sValues, packing);
- }
- else {
- _mesa_pack_stencil_span(ctx, width, type, dest, sValues, packing);
- }
- }
-
- /* unmap the stencil buffer */
- pipe_transfer_unmap(pipe, pt);
- pipe->transfer_destroy(pipe, pt);
-}
-
-
-/**
- * Return renderbuffer to use for reading color pixels for glRead/CopyPixel
- * commands.
- */
-struct st_renderbuffer *
-st_get_color_read_renderbuffer(struct gl_context *ctx)
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct st_renderbuffer *strb =
- st_renderbuffer(fb->_ColorReadBuffer);
-
- return strb;
-}
-
-
-/**
- * Try to do glReadPixels in a fast manner for common cases.
- * \return GL_TRUE for success, GL_FALSE for failure
- */
-static GLboolean
-st_fast_readpixels(struct gl_context *ctx, struct st_renderbuffer *strb,
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *pack,
- GLvoid *dest)
-{
- enum combination {
- A8R8G8B8_UNORM_TO_RGBA_UBYTE,
- A8R8G8B8_UNORM_TO_RGB_UBYTE,
- A8R8G8B8_UNORM_TO_BGRA_UINT
- } combo;
-
- if (ctx->_ImageTransferState)
- return GL_FALSE;
-
- if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM &&
- format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
- combo = A8R8G8B8_UNORM_TO_RGBA_UBYTE;
- }
- else if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM &&
- format == GL_RGB && type == GL_UNSIGNED_BYTE) {
- combo = A8R8G8B8_UNORM_TO_RGB_UBYTE;
- }
- else if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM &&
- format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV) {
- combo = A8R8G8B8_UNORM_TO_BGRA_UINT;
- }
- else {
- return GL_FALSE;
- }
-
- /*printf("st_fast_readpixels combo %d\n", (GLint) combo);*/
-
- {
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct pipe_transfer *trans;
- const GLubyte *map;
- GLubyte *dst;
- GLint row, col, dy, dstStride;
-
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- /* convert GL Y to Gallium Y */
- y = strb->texture->height0 - y - height;
- }
-
- trans = pipe_get_transfer(pipe, strb->texture,
- 0, 0,
- PIPE_TRANSFER_READ,
- x, y, width, height);
- if (!trans) {
- return GL_FALSE;
- }
-
- map = pipe_transfer_map(pipe, trans);
- if (!map) {
- pipe->transfer_destroy(pipe, trans);
- return GL_FALSE;
- }
-
- /* We always write to the user/dest buffer from low addr to high addr
- * but the read order depends on renderbuffer orientation
- */
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- /* read source rows from bottom to top */
- y = height - 1;
- dy = -1;
- }
- else {
- /* read source rows from top to bottom */
- y = 0;
- dy = 1;
- }
-
- dst = _mesa_image_address2d(pack, dest, width, height,
- format, type, 0, 0);
- dstStride = _mesa_image_row_stride(pack, width, format, type);
-
- switch (combo) {
- case A8R8G8B8_UNORM_TO_RGBA_UBYTE:
- for (row = 0; row < height; row++) {
- const GLubyte *src = map + y * trans->stride;
- for (col = 0; col < width; col++) {
- GLuint pixel = ((GLuint *) src)[col];
- dst[col*4+0] = (pixel >> 16) & 0xff;
- dst[col*4+1] = (pixel >> 8) & 0xff;
- dst[col*4+2] = (pixel >> 0) & 0xff;
- dst[col*4+3] = (pixel >> 24) & 0xff;
- }
- dst += dstStride;
- y += dy;
- }
- break;
- case A8R8G8B8_UNORM_TO_RGB_UBYTE:
- for (row = 0; row < height; row++) {
- const GLubyte *src = map + y * trans->stride;
- for (col = 0; col < width; col++) {
- GLuint pixel = ((GLuint *) src)[col];
- dst[col*3+0] = (pixel >> 16) & 0xff;
- dst[col*3+1] = (pixel >> 8) & 0xff;
- dst[col*3+2] = (pixel >> 0) & 0xff;
- }
- dst += dstStride;
- y += dy;
- }
- break;
- case A8R8G8B8_UNORM_TO_BGRA_UINT:
- for (row = 0; row < height; row++) {
- const GLubyte *src = map + y * trans->stride;
- memcpy(dst, src, 4 * width);
- dst += dstStride;
- y += dy;
- }
- break;
- default:
- ; /* nothing */
- }
-
- pipe_transfer_unmap(pipe, trans);
- pipe->transfer_destroy(pipe, trans);
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Do glReadPixels by getting rows from the framebuffer transfer with
- * get_tile(). Convert to requested format/type with Mesa image routines.
- * Image transfer ops are done in software too.
- */
-static void
-st_readpixels(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *pack,
- GLvoid *dest)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- GLfloat (*temp)[4];
- const GLbitfield transferOps = ctx->_ImageTransferState;
- GLsizei i, j;
- GLint yStep, dfStride;
- GLfloat *df;
- struct st_renderbuffer *strb;
- struct gl_pixelstore_attrib clippedPacking = *pack;
- struct pipe_transfer *trans;
- enum pipe_format pformat;
-
- assert(ctx->ReadBuffer->Width > 0);
-
- st_validate_state(st);
-
- /* Do all needed clipping here, so that we can forget about it later */
- if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
- /* The ReadPixels transfer is totally outside the window bounds */
- return;
- }
-
- st_flush_bitmap_cache(st);
-
- dest = _mesa_map_pbo_dest(ctx, &clippedPacking, dest);
- if (!dest)
- return;
-
- if (format == GL_STENCIL_INDEX ||
- format == GL_DEPTH_STENCIL) {
- st_read_stencil_pixels(ctx, x, y, width, height,
- format, type, pack, dest);
- return;
- }
- else if (format == GL_DEPTH_COMPONENT) {
- strb = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer);
- if (strb->Base.Wrapped) {
- strb = st_renderbuffer(strb->Base.Wrapped);
- }
- }
- else {
- /* Read color buffer */
- strb = st_get_color_read_renderbuffer(ctx);
- }
-
- if (!strb)
- return;
-
- /* try a fast-path readpixels before anything else */
- if (st_fast_readpixels(ctx, strb, x, y, width, height,
- format, type, pack, dest)) {
- /* success! */
- _mesa_unmap_pbo_dest(ctx, &clippedPacking);
- return;
- }
-
- /* allocate temp pixel row buffer */
- temp = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
- if (!temp) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
- return;
- }
-
- if (format == GL_RGBA && type == GL_FLOAT) {
- /* write tile(row) directly into user's buffer */
- df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width,
- height, format, type, 0, 0);
- dfStride = width * 4;
- }
- else {
- /* write tile(row) into temp row buffer */
- df = (GLfloat *) temp;
- dfStride = 0;
- }
-
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- /* convert GL Y to Gallium Y */
- y = strb->Base.Height - y - height;
- }
-
- /* Create a read transfer from the renderbuffer's texture */
- trans = pipe_get_transfer(pipe, strb->texture,
- 0, 0,
- PIPE_TRANSFER_READ,
- x, y, width, height);
-
- /* determine bottom-to-top vs. top-to-bottom order */
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- y = height - 1;
- yStep = -1;
- }
- else {
- y = 0;
- yStep = 1;
- }
-
- /* possibly convert sRGB format to linear RGB format */
- pformat = util_format_linear(trans->resource->format);
-
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s: fallback processing\n", __FUNCTION__);
-
- /*
- * Copy pixels from pipe_transfer to user memory
- */
- {
- /* dest of first pixel in client memory */
- GLubyte *dst = _mesa_image_address2d(&clippedPacking, dest, width,
- height, format, type, 0, 0);
- /* dest row stride */
- const GLint dstStride = _mesa_image_row_stride(&clippedPacking, width,
- format, type);
-
- if (pformat == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
- pformat == PIPE_FORMAT_Z24X8_UNORM) {
- if (format == GL_DEPTH_COMPONENT) {
- for (i = 0; i < height; i++) {
- GLuint ztemp[MAX_WIDTH];
- GLfloat zfloat[MAX_WIDTH];
- const double scale = 1.0 / ((1 << 24) - 1);
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
- y += yStep;
- for (j = 0; j < width; j++) {
- zfloat[j] = (float) (scale * (ztemp[j] & 0xffffff));
- }
- _mesa_pack_depth_span(ctx, width, dst, type,
- zfloat, &clippedPacking);
- dst += dstStride;
- }
- }
- else {
- /* XXX: unreachable code -- should be before st_read_stencil_pixels */
- assert(format == GL_DEPTH_STENCIL_EXT);
- for (i = 0; i < height; i++) {
- GLuint *zshort = (GLuint *)dst;
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0);
- y += yStep;
- /* Reverse into 24/8 */
- for (j = 0; j < width; j++) {
- zshort[j] = (zshort[j] << 8) | (zshort[j] >> 24);
- }
- dst += dstStride;
- }
- }
- }
- else if (pformat == PIPE_FORMAT_S8_USCALED_Z24_UNORM ||
- pformat == PIPE_FORMAT_X8Z24_UNORM) {
- if (format == GL_DEPTH_COMPONENT) {
- for (i = 0; i < height; i++) {
- GLuint ztemp[MAX_WIDTH];
- GLfloat zfloat[MAX_WIDTH];
- const double scale = 1.0 / ((1 << 24) - 1);
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
- y += yStep;
- for (j = 0; j < width; j++) {
- zfloat[j] = (float) (scale * ((ztemp[j] >> 8) & 0xffffff));
- }
- _mesa_pack_depth_span(ctx, width, dst, type,
- zfloat, &clippedPacking);
- dst += dstStride;
- }
- }
- else {
- /* XXX: unreachable code -- should be before st_read_stencil_pixels */
- assert(format == GL_DEPTH_STENCIL_EXT);
- for (i = 0; i < height; i++) {
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0);
- y += yStep;
- dst += dstStride;
- }
- }
- }
- else if (pformat == PIPE_FORMAT_Z16_UNORM) {
- for (i = 0; i < height; i++) {
- GLushort ztemp[MAX_WIDTH];
- GLfloat zfloat[MAX_WIDTH];
- const double scale = 1.0 / 0xffff;
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
- y += yStep;
- for (j = 0; j < width; j++) {
- zfloat[j] = (float) (scale * ztemp[j]);
- }
- _mesa_pack_depth_span(ctx, width, dst, type,
- zfloat, &clippedPacking);
- dst += dstStride;
- }
- }
- else if (pformat == PIPE_FORMAT_Z32_UNORM) {
- for (i = 0; i < height; i++) {
- GLuint ztemp[MAX_WIDTH];
- GLfloat zfloat[MAX_WIDTH];
- const double scale = 1.0 / 0xffffffff;
- pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
- y += yStep;
- for (j = 0; j < width; j++) {
- zfloat[j] = (float) (scale * ztemp[j]);
- }
- _mesa_pack_depth_span(ctx, width, dst, type,
- zfloat, &clippedPacking);
- dst += dstStride;
- }
- }
- else {
- /* RGBA format */
- /* Do a row at a time to flip image data vertically */
- for (i = 0; i < height; i++) {
- pipe_get_tile_rgba_format(pipe, trans, 0, y, width, 1,
- pformat, df);
- y += yStep;
- df += dfStride;
- if (!dfStride) {
- _mesa_pack_rgba_span_float(ctx, width, temp, format, type, dst,
- &clippedPacking, transferOps);
- dst += dstStride;
- }
- }
- }
- }
-
- free(temp);
-
- pipe->transfer_destroy(pipe, trans);
-
- _mesa_unmap_pbo_dest(ctx, &clippedPacking);
-}
-
-
-void st_init_readpixels_functions(struct dd_function_table *functions)
-{
- functions->ReadPixels = st_readpixels;
-}
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+/**
+ * glReadPixels interface to pipe
+ *
+ * \author Brian Paul
+ */
+
+
+#include "main/imports.h"
+#include "main/bufferobj.h"
+#include "main/context.h"
+#include "main/image.h"
+#include "main/pack.h"
+#include "main/pbo.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "util/u_format.h"
+#include "util/u_inlines.h"
+#include "util/u_tile.h"
+
+#include "st_debug.h"
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_cb_bitmap.h"
+#include "st_cb_readpixels.h"
+#include "st_cb_fbo.h"
+
+/**
+ * Special case for reading stencil buffer.
+ * For color/depth we use get_tile(). For stencil, map the stencil buffer.
+ */
+void
+st_read_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *packing,
+ GLvoid *pixels)
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer);
+ struct pipe_transfer *pt;
+ ubyte *stmap;
+ GLint j;
+
+ if (strb->Base.Wrapped) {
+ strb = st_renderbuffer(strb->Base.Wrapped);
+ }
+
+ if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
+ y = ctx->DrawBuffer->Height - y - height;
+ }
+
+ /* Create a read transfer from the renderbuffer's texture */
+
+ pt = pipe_get_transfer(pipe, strb->texture,
+ 0, 0,
+ PIPE_TRANSFER_READ,
+ x, y, width, height);
+
+ /* map the stencil buffer */
+ stmap = pipe_transfer_map(pipe, pt);
+
+ /* width should never be > MAX_WIDTH since we did clipping earlier */
+ ASSERT(width <= MAX_WIDTH);
+
+ /* process image row by row */
+ for (j = 0; j < height; j++) {
+ GLvoid *dest;
+ GLstencil sValues[MAX_WIDTH];
+ GLfloat zValues[MAX_WIDTH];
+ GLint srcY;
+
+ if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
+ srcY = height - j - 1;
+ }
+ else {
+ srcY = j;
+ }
+
+ /* get stencil (and Z) values */
+ switch (pt->resource->format) {
+ case PIPE_FORMAT_S8_USCALED:
+ {
+ const ubyte *src = stmap + srcY * pt->stride;
+ memcpy(sValues, src, width);
+ }
+ break;
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ if (format == GL_DEPTH_STENCIL) {
+ const uint *src = (uint *) (stmap + srcY * pt->stride);
+ const GLfloat scale = 1.0f / (0xffffff);
+ GLint k;
+ for (k = 0; k < width; k++) {
+ sValues[k] = src[k] >> 24;
+ zValues[k] = (src[k] & 0xffffff) * scale;
+ }
+ }
+ else {
+ const uint *src = (uint *) (stmap + srcY * pt->stride);
+ GLint k;
+ for (k = 0; k < width; k++) {
+ sValues[k] = src[k] >> 24;
+ }
+ }
+ break;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ if (format == GL_DEPTH_STENCIL) {
+ const uint *src = (uint *) (stmap + srcY * pt->stride);
+ const GLfloat scale = 1.0f / (0xffffff);
+ GLint k;
+ for (k = 0; k < width; k++) {
+ sValues[k] = src[k] & 0xff;
+ zValues[k] = (src[k] >> 8) * scale;
+ }
+ }
+ else {
+ const uint *src = (uint *) (stmap + srcY * pt->stride);
+ GLint k;
+ for (k = 0; k < width; k++) {
+ sValues[k] = src[k] & 0xff;
+ }
+ }
+ break;
+ default:
+ assert(0);
+ }
+
+ /* store */
+ dest = _mesa_image_address2d(packing, pixels, width, height,
+ format, type, j, 0);
+ if (format == GL_DEPTH_STENCIL) {
+ _mesa_pack_depth_stencil_span(ctx, width, dest,
+ zValues, sValues, packing);
+ }
+ else {
+ _mesa_pack_stencil_span(ctx, width, type, dest, sValues, packing);
+ }
+ }
+
+ /* unmap the stencil buffer */
+ pipe_transfer_unmap(pipe, pt);
+ pipe->transfer_destroy(pipe, pt);
+}
+
+
+/**
+ * Return renderbuffer to use for reading color pixels for glRead/CopyPixel
+ * commands.
+ */
+struct st_renderbuffer *
+st_get_color_read_renderbuffer(struct gl_context *ctx)
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct st_renderbuffer *strb =
+ st_renderbuffer(fb->_ColorReadBuffer);
+
+ return strb;
+}
+
+
+/**
+ * Try to do glReadPixels in a fast manner for common cases.
+ * \return GL_TRUE for success, GL_FALSE for failure
+ */
+static GLboolean
+st_fast_readpixels(struct gl_context *ctx, struct st_renderbuffer *strb,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *pack,
+ GLvoid *dest)
+{
+ enum combination {
+ A8R8G8B8_UNORM_TO_RGBA_UBYTE,
+ A8R8G8B8_UNORM_TO_RGB_UBYTE,
+ A8R8G8B8_UNORM_TO_BGRA_UINT
+ } combo;
+
+ if (ctx->_ImageTransferState)
+ return GL_FALSE;
+
+ if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM &&
+ format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
+ combo = A8R8G8B8_UNORM_TO_RGBA_UBYTE;
+ }
+ else if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM &&
+ format == GL_RGB && type == GL_UNSIGNED_BYTE) {
+ combo = A8R8G8B8_UNORM_TO_RGB_UBYTE;
+ }
+ else if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM &&
+ format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV) {
+ combo = A8R8G8B8_UNORM_TO_BGRA_UINT;
+ }
+ else {
+ return GL_FALSE;
+ }
+
+ /*printf("st_fast_readpixels combo %d\n", (GLint) combo);*/
+
+ {
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct pipe_transfer *trans;
+ const GLubyte *map;
+ GLubyte *dst;
+ GLint row, col, dy, dstStride;
+
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ /* convert GL Y to Gallium Y */
+ y = strb->texture->height0 - y - height;
+ }
+
+ trans = pipe_get_transfer(pipe, strb->texture,
+ 0, 0,
+ PIPE_TRANSFER_READ,
+ x, y, width, height);
+ if (!trans) {
+ return GL_FALSE;
+ }
+
+ map = pipe_transfer_map(pipe, trans);
+ if (!map) {
+ pipe->transfer_destroy(pipe, trans);
+ return GL_FALSE;
+ }
+
+ /* We always write to the user/dest buffer from low addr to high addr
+ * but the read order depends on renderbuffer orientation
+ */
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ /* read source rows from bottom to top */
+ y = height - 1;
+ dy = -1;
+ }
+ else {
+ /* read source rows from top to bottom */
+ y = 0;
+ dy = 1;
+ }
+
+ dst = _mesa_image_address2d(pack, dest, width, height,
+ format, type, 0, 0);
+ dstStride = _mesa_image_row_stride(pack, width, format, type);
+
+ switch (combo) {
+ case A8R8G8B8_UNORM_TO_RGBA_UBYTE:
+ for (row = 0; row < height; row++) {
+ const GLubyte *src = map + y * trans->stride;
+ for (col = 0; col < width; col++) {
+ GLuint pixel = ((GLuint *) src)[col];
+ dst[col*4+0] = (pixel >> 16) & 0xff;
+ dst[col*4+1] = (pixel >> 8) & 0xff;
+ dst[col*4+2] = (pixel >> 0) & 0xff;
+ dst[col*4+3] = (pixel >> 24) & 0xff;
+ }
+ dst += dstStride;
+ y += dy;
+ }
+ break;
+ case A8R8G8B8_UNORM_TO_RGB_UBYTE:
+ for (row = 0; row < height; row++) {
+ const GLubyte *src = map + y * trans->stride;
+ for (col = 0; col < width; col++) {
+ GLuint pixel = ((GLuint *) src)[col];
+ dst[col*3+0] = (pixel >> 16) & 0xff;
+ dst[col*3+1] = (pixel >> 8) & 0xff;
+ dst[col*3+2] = (pixel >> 0) & 0xff;
+ }
+ dst += dstStride;
+ y += dy;
+ }
+ break;
+ case A8R8G8B8_UNORM_TO_BGRA_UINT:
+ for (row = 0; row < height; row++) {
+ const GLubyte *src = map + y * trans->stride;
+ memcpy(dst, src, 4 * width);
+ dst += dstStride;
+ y += dy;
+ }
+ break;
+ default:
+ ; /* nothing */
+ }
+
+ pipe_transfer_unmap(pipe, trans);
+ pipe->transfer_destroy(pipe, trans);
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Do glReadPixels by getting rows from the framebuffer transfer with
+ * get_tile(). Convert to requested format/type with Mesa image routines.
+ * Image transfer ops are done in software too.
+ */
+static void
+st_readpixels(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *pack,
+ GLvoid *dest)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ GLfloat (*temp)[4];
+ const GLbitfield transferOps = ctx->_ImageTransferState;
+ GLsizei i, j;
+ GLint yStep, dfStride;
+ GLfloat *df;
+ struct st_renderbuffer *strb;
+ struct gl_pixelstore_attrib clippedPacking = *pack;
+ struct pipe_transfer *trans;
+ enum pipe_format pformat;
+
+ assert(ctx->ReadBuffer->Width > 0);
+
+ st_validate_state(st);
+
+ /* Do all needed clipping here, so that we can forget about it later */
+ if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
+ /* The ReadPixels transfer is totally outside the window bounds */
+ return;
+ }
+
+ st_flush_bitmap_cache(st);
+
+ dest = _mesa_map_pbo_dest(ctx, &clippedPacking, dest);
+ if (!dest)
+ return;
+
+ if (format == GL_STENCIL_INDEX ||
+ format == GL_DEPTH_STENCIL) {
+ st_read_stencil_pixels(ctx, x, y, width, height,
+ format, type, pack, dest);
+ return;
+ }
+ else if (format == GL_DEPTH_COMPONENT) {
+ strb = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer);
+ if (strb->Base.Wrapped) {
+ strb = st_renderbuffer(strb->Base.Wrapped);
+ }
+ }
+ else {
+ /* Read color buffer */
+ strb = st_get_color_read_renderbuffer(ctx);
+ }
+
+ if (!strb)
+ return;
+
+ /* try a fast-path readpixels before anything else */
+ if (st_fast_readpixels(ctx, strb, x, y, width, height,
+ format, type, pack, dest)) {
+ /* success! */
+ _mesa_unmap_pbo_dest(ctx, &clippedPacking);
+ return;
+ }
+
+ /* allocate temp pixel row buffer */
+ temp = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
+ if (!temp) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return;
+ }
+
+ if (format == GL_RGBA && type == GL_FLOAT) {
+ /* write tile(row) directly into user's buffer */
+ df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width,
+ height, format, type, 0, 0);
+ dfStride = width * 4;
+ }
+ else {
+ /* write tile(row) into temp row buffer */
+ df = (GLfloat *) temp;
+ dfStride = 0;
+ }
+
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ /* convert GL Y to Gallium Y */
+ y = strb->Base.Height - y - height;
+ }
+
+ /* Create a read transfer from the renderbuffer's texture */
+ trans = pipe_get_transfer(pipe, strb->texture,
+ 0, 0,
+ PIPE_TRANSFER_READ,
+ x, y, width, height);
+
+ /* determine bottom-to-top vs. top-to-bottom order */
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ y = height - 1;
+ yStep = -1;
+ }
+ else {
+ y = 0;
+ yStep = 1;
+ }
+
+ /* possibly convert sRGB format to linear RGB format */
+ pformat = util_format_linear(trans->resource->format);
+
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
+
+ /*
+ * Copy pixels from pipe_transfer to user memory
+ */
+ {
+ /* dest of first pixel in client memory */
+ GLubyte *dst = _mesa_image_address2d(&clippedPacking, dest, width,
+ height, format, type, 0, 0);
+ /* dest row stride */
+ const GLint dstStride = _mesa_image_row_stride(&clippedPacking, width,
+ format, type);
+
+ if (pformat == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
+ pformat == PIPE_FORMAT_Z24X8_UNORM) {
+ if (format == GL_DEPTH_COMPONENT) {
+ for (i = 0; i < height; i++) {
+ GLuint ztemp[MAX_WIDTH];
+ GLfloat zfloat[MAX_WIDTH];
+ const double scale = 1.0 / ((1 << 24) - 1);
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
+ y += yStep;
+ for (j = 0; j < width; j++) {
+ zfloat[j] = (float) (scale * (ztemp[j] & 0xffffff));
+ }
+ _mesa_pack_depth_span(ctx, width, dst, type,
+ zfloat, &clippedPacking);
+ dst += dstStride;
+ }
+ }
+ else {
+ /* XXX: unreachable code -- should be before st_read_stencil_pixels */
+ assert(format == GL_DEPTH_STENCIL_EXT);
+ for (i = 0; i < height; i++) {
+ GLuint *zshort = (GLuint *)dst;
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0);
+ y += yStep;
+ /* Reverse into 24/8 */
+ for (j = 0; j < width; j++) {
+ zshort[j] = (zshort[j] << 8) | (zshort[j] >> 24);
+ }
+ dst += dstStride;
+ }
+ }
+ }
+ else if (pformat == PIPE_FORMAT_S8_USCALED_Z24_UNORM ||
+ pformat == PIPE_FORMAT_X8Z24_UNORM) {
+ if (format == GL_DEPTH_COMPONENT) {
+ for (i = 0; i < height; i++) {
+ GLuint ztemp[MAX_WIDTH];
+ GLfloat zfloat[MAX_WIDTH];
+ const double scale = 1.0 / ((1 << 24) - 1);
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
+ y += yStep;
+ for (j = 0; j < width; j++) {
+ zfloat[j] = (float) (scale * ((ztemp[j] >> 8) & 0xffffff));
+ }
+ _mesa_pack_depth_span(ctx, width, dst, type,
+ zfloat, &clippedPacking);
+ dst += dstStride;
+ }
+ }
+ else {
+ /* XXX: unreachable code -- should be before st_read_stencil_pixels */
+ assert(format == GL_DEPTH_STENCIL_EXT);
+ for (i = 0; i < height; i++) {
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0);
+ y += yStep;
+ dst += dstStride;
+ }
+ }
+ }
+ else if (pformat == PIPE_FORMAT_Z16_UNORM) {
+ for (i = 0; i < height; i++) {
+ GLushort ztemp[MAX_WIDTH];
+ GLfloat zfloat[MAX_WIDTH];
+ const double scale = 1.0 / 0xffff;
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
+ y += yStep;
+ for (j = 0; j < width; j++) {
+ zfloat[j] = (float) (scale * ztemp[j]);
+ }
+ _mesa_pack_depth_span(ctx, width, dst, type,
+ zfloat, &clippedPacking);
+ dst += dstStride;
+ }
+ }
+ else if (pformat == PIPE_FORMAT_Z32_UNORM) {
+ for (i = 0; i < height; i++) {
+ GLuint ztemp[MAX_WIDTH];
+ GLfloat zfloat[MAX_WIDTH];
+ const double scale = 1.0 / 0xffffffff;
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
+ y += yStep;
+ for (j = 0; j < width; j++) {
+ zfloat[j] = (float) (scale * ztemp[j]);
+ }
+ _mesa_pack_depth_span(ctx, width, dst, type,
+ zfloat, &clippedPacking);
+ dst += dstStride;
+ }
+ }
+ else {
+ /* RGBA format */
+ /* Do a row at a time to flip image data vertically */
+ for (i = 0; i < height; i++) {
+ pipe_get_tile_rgba_format(pipe, trans, 0, y, width, 1,
+ pformat, df);
+ y += yStep;
+ df += dfStride;
+ if (!dfStride) {
+ _mesa_pack_rgba_span_float(ctx, width, temp, format, type, dst,
+ &clippedPacking, transferOps);
+ dst += dstStride;
+ }
+ }
+ }
+ }
+
+ free(temp);
+
+ pipe->transfer_destroy(pipe, trans);
+
+ _mesa_unmap_pbo_dest(ctx, &clippedPacking);
+}
+
+
+void st_init_readpixels_functions(struct dd_function_table *functions)
+{
+ functions->ReadPixels = st_readpixels;
+}
diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c
index c3c4246d1..cea2a4a8d 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_texture.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c
@@ -1,1931 +1,1931 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#include "main/mfeatures.h"
-#include "main/bufferobj.h"
-#include "main/enums.h"
-#include "main/fbobject.h"
-#include "main/formats.h"
-#include "main/image.h"
-#include "main/imports.h"
-#include "main/macros.h"
-#include "main/mipmap.h"
-#include "main/pack.h"
-#include "main/pbo.h"
-#include "main/pixeltransfer.h"
-#include "main/texcompress.h"
-#include "main/texfetch.h"
-#include "main/texgetimage.h"
-#include "main/teximage.h"
-#include "main/texobj.h"
-#include "main/texstore.h"
-
-#include "state_tracker/st_debug.h"
-#include "state_tracker/st_context.h"
-#include "state_tracker/st_cb_fbo.h"
-#include "state_tracker/st_cb_flush.h"
-#include "state_tracker/st_cb_texture.h"
-#include "state_tracker/st_format.h"
-#include "state_tracker/st_texture.h"
-#include "state_tracker/st_gen_mipmap.h"
-#include "state_tracker/st_atom.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-#include "pipe/p_shader_tokens.h"
-#include "util/u_tile.h"
-#include "util/u_blit.h"
-#include "util/u_format.h"
-#include "util/u_surface.h"
-#include "util/u_sampler.h"
-#include "util/u_math.h"
-#include "util/u_box.h"
-
-#define DBG if (0) printf
-
-
-static enum pipe_texture_target
-gl_target_to_pipe(GLenum target)
-{
- switch (target) {
- case GL_TEXTURE_1D:
- return PIPE_TEXTURE_1D;
- case GL_TEXTURE_2D:
- return PIPE_TEXTURE_2D;
- case GL_TEXTURE_RECTANGLE_NV:
- return PIPE_TEXTURE_RECT;
- case GL_TEXTURE_3D:
- return PIPE_TEXTURE_3D;
- case GL_TEXTURE_CUBE_MAP_ARB:
- return PIPE_TEXTURE_CUBE;
- case GL_TEXTURE_1D_ARRAY_EXT:
- return PIPE_TEXTURE_1D_ARRAY;
- case GL_TEXTURE_2D_ARRAY_EXT:
- return PIPE_TEXTURE_2D_ARRAY;
- default:
- assert(0);
- return 0;
- }
-}
-
-
-/** called via ctx->Driver.NewTextureImage() */
-static struct gl_texture_image *
-st_NewTextureImage(struct gl_context * ctx)
-{
- DBG("%s\n", __FUNCTION__);
- (void) ctx;
- return (struct gl_texture_image *) ST_CALLOC_STRUCT(st_texture_image);
-}
-
-
-/** called via ctx->Driver.NewTextureObject() */
-static struct gl_texture_object *
-st_NewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
-{
- struct st_texture_object *obj = ST_CALLOC_STRUCT(st_texture_object);
-
- DBG("%s\n", __FUNCTION__);
- _mesa_initialize_texture_object(&obj->base, name, target);
-
- return &obj->base;
-}
-
-/** called via ctx->Driver.DeleteTextureObject() */
-static void
-st_DeleteTextureObject(struct gl_context *ctx,
- struct gl_texture_object *texObj)
-{
- struct st_context *st = st_context(ctx);
- struct st_texture_object *stObj = st_texture_object(texObj);
- if (stObj->pt)
- pipe_resource_reference(&stObj->pt, NULL);
- if (stObj->sampler_view) {
- if (stObj->sampler_view->context != st->pipe) {
- /* Take "ownership" of this texture sampler view by setting
- * its context pointer to this context. This avoids potential
- * crashes when the texture object is shared among contexts
- * and the original/owner context has already been destroyed.
- */
- stObj->sampler_view->context = st->pipe;
- }
- pipe_sampler_view_reference(&stObj->sampler_view, NULL);
- }
- _mesa_delete_texture_object(ctx, texObj);
-}
-
-
-/** called via ctx->Driver.FreeTexImageData() */
-static void
-st_FreeTextureImageData(struct gl_context * ctx, struct gl_texture_image *texImage)
-{
- struct st_texture_image *stImage = st_texture_image(texImage);
-
- DBG("%s\n", __FUNCTION__);
-
- if (stImage->pt) {
- pipe_resource_reference(&stImage->pt, NULL);
- }
-
- if (texImage->Data) {
- _mesa_align_free(texImage->Data);
- texImage->Data = NULL;
- }
-}
-
-
-/**
- * From linux kernel i386 header files, copes with odd sizes better
- * than COPY_DWORDS would:
- * XXX Put this in src/mesa/main/imports.h ???
- */
-#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
-static INLINE void *
-__memcpy(void *to, const void *from, size_t n)
-{
- int d0, d1, d2;
- __asm__ __volatile__("rep ; movsl\n\t"
- "testb $2,%b4\n\t"
- "je 1f\n\t"
- "movsw\n"
- "1:\ttestb $1,%b4\n\t"
- "je 2f\n\t"
- "movsb\n" "2:":"=&c"(d0), "=&D"(d1), "=&S"(d2)
- :"0"(n / 4), "q"(n), "1"((long) to), "2"((long) from)
- :"memory");
- return (to);
-}
-#else
-#define __memcpy(a,b,c) memcpy(a,b,c)
-#endif
-
-
-/**
- * The system memcpy (at least on ubuntu 5.10) has problems copying
- * to agp (writecombined) memory from a source which isn't 64-byte
- * aligned - there is a 4x performance falloff.
- *
- * The x86 __memcpy is immune to this but is slightly slower
- * (10%-ish) than the system memcpy.
- *
- * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
- * isn't much faster than x86_memcpy for agp copies.
- *
- * TODO: switch dynamically.
- */
-static void *
-do_memcpy(void *dest, const void *src, size_t n)
-{
- if ((((unsigned long) src) & 63) || (((unsigned long) dest) & 63)) {
- return __memcpy(dest, src, n);
- }
- else
- return memcpy(dest, src, n);
-}
-
-
-/**
- * Return default texture resource binding bitmask for the given format.
- */
-static GLuint
-default_bindings(struct st_context *st, enum pipe_format format)
-{
- struct pipe_screen *screen = st->pipe->screen;
- const unsigned target = PIPE_TEXTURE_2D;
- const unsigned geom = 0x0;
- unsigned bindings;
-
- if (util_format_is_depth_or_stencil(format))
- bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_DEPTH_STENCIL;
- else
- bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
-
- if (screen->is_format_supported(screen, format, target, 0, bindings, geom))
- return bindings;
- else
- return PIPE_BIND_SAMPLER_VIEW;
-}
-
-
-/** Return number of image dimensions (1, 2 or 3) for a texture target. */
-static GLuint
-get_texture_dims(GLenum target)
-{
- switch (target) {
- case GL_TEXTURE_1D:
- case GL_TEXTURE_1D_ARRAY_EXT:
- return 1;
- case GL_TEXTURE_2D:
- case GL_TEXTURE_CUBE_MAP_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
- case GL_TEXTURE_RECTANGLE_NV:
- case GL_TEXTURE_2D_ARRAY_EXT:
- return 2;
- case GL_TEXTURE_3D:
- return 3;
- default:
- assert(0 && "invalid texture target in get_texture_dims()");
- return 1;
- }
-}
-
-
-/**
- * Given the size of a mipmap image, try to compute the size of the level=0
- * mipmap image.
- *
- * Note that this isn't always accurate for odd-sized, non-POW textures.
- * For example, if level=1 and width=40 then the level=0 width may be 80 or 81.
- *
- * \return GL_TRUE for success, GL_FALSE for failure
- */
-static GLboolean
-guess_base_level_size(GLenum target,
- GLuint width, GLuint height, GLuint depth, GLuint level,
- GLuint *width0, GLuint *height0, GLuint *depth0)
-{
- const GLuint dims = get_texture_dims(target);
-
- assert(width >= 1);
- assert(height >= 1);
- assert(depth >= 1);
-
- if (level > 0) {
- /* Depending on the image's size, we can't always make a guess here */
- if ((dims >= 1 && width == 1) ||
- (dims >= 2 && height == 1) ||
- (dims >= 3 && depth == 1)) {
- /* we can't determine the image size at level=0 */
- return GL_FALSE;
- }
-
- /* grow the image size until we hit level = 0 */
- while (level > 0) {
- if (width > 1)
- width <<= 1;
- if (height > 1)
- height <<= 1;
- if (depth > 1)
- depth <<= 1;
- level--;
- }
- }
-
- *width0 = width;
- *height0 = height;
- *depth0 = depth;
-
- return GL_TRUE;
-}
-
-
-/**
- * Try to allocate a pipe_resource object for the given st_texture_object.
- *
- * We use the given st_texture_image as a clue to determine the size of the
- * mipmap image at level=0.
- *
- * \return GL_TRUE for success, GL_FALSE if out of memory.
- */
-static GLboolean
-guess_and_alloc_texture(struct st_context *st,
- struct st_texture_object *stObj,
- const struct st_texture_image *stImage)
-{
- GLuint lastLevel, width, height, depth;
- GLuint bindings;
- GLuint ptWidth, ptHeight, ptDepth, ptLayers;
- enum pipe_format fmt;
-
- DBG("%s\n", __FUNCTION__);
-
- assert(!stObj->pt);
-
- if (!guess_base_level_size(stObj->base.Target,
- stImage->base.Width2,
- stImage->base.Height2,
- stImage->base.Depth2,
- stImage->level,
- &width, &height, &depth)) {
- /* we can't determine the image size at level=0 */
- stObj->width0 = stObj->height0 = stObj->depth0 = 0;
- /* this is not an out of memory error */
- return GL_TRUE;
- }
-
- /* At this point, (width x height x depth) is the expected size of
- * the level=0 mipmap image.
- */
-
- /* Guess a reasonable value for lastLevel. With OpenGL we have no
- * idea how many mipmap levels will be in a texture until we start
- * to render with it. Make an educated guess here but be prepared
- * to re-allocating a texture buffer with space for more (or fewer)
- * mipmap levels later.
- */
- if ((stObj->base.MinFilter == GL_NEAREST ||
- stObj->base.MinFilter == GL_LINEAR ||
- stImage->base._BaseFormat == GL_DEPTH_COMPONENT ||
- stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) &&
- !stObj->base.GenerateMipmap &&
- stImage->level == 0) {
- /* only alloc space for a single mipmap level */
- lastLevel = 0;
- }
- else {
- /* alloc space for a full mipmap */
- GLuint l2width = util_logbase2(width);
- GLuint l2height = util_logbase2(height);
- GLuint l2depth = util_logbase2(depth);
- lastLevel = MAX2(MAX2(l2width, l2height), l2depth);
- }
-
- /* Save the level=0 dimensions */
- stObj->width0 = width;
- stObj->height0 = height;
- stObj->depth0 = depth;
-
- fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat);
-
- bindings = default_bindings(st, fmt);
-
- st_gl_texture_dims_to_pipe_dims(stObj->base.Target,
- width, height, depth,
- &ptWidth, &ptHeight, &ptDepth, &ptLayers);
-
- stObj->pt = st_texture_create(st,
- gl_target_to_pipe(stObj->base.Target),
- fmt,
- lastLevel,
- ptWidth,
- ptHeight,
- ptDepth,
- ptLayers,
- bindings);
-
- DBG("%s returning %d\n", __FUNCTION__, (stObj->pt != NULL));
-
- return stObj->pt != NULL;
-}
-
-
-/**
- * Adjust pixel unpack params and image dimensions to strip off the
- * texture border.
- * Gallium doesn't support texture borders. They've seldem been used
- * and seldom been implemented correctly anyway.
- * \param unpackNew returns the new pixel unpack parameters
- */
-static void
-strip_texture_border(GLint border,
- GLint *width, GLint *height, GLint *depth,
- const struct gl_pixelstore_attrib *unpack,
- struct gl_pixelstore_attrib *unpackNew)
-{
- assert(border > 0); /* sanity check */
-
- *unpackNew = *unpack;
-
- if (unpackNew->RowLength == 0)
- unpackNew->RowLength = *width;
-
- if (depth && unpackNew->ImageHeight == 0)
- unpackNew->ImageHeight = *height;
-
- unpackNew->SkipPixels += border;
- if (height)
- unpackNew->SkipRows += border;
- if (depth)
- unpackNew->SkipImages += border;
-
- assert(*width >= 3);
- *width = *width - 2 * border;
- if (height && *height >= 3)
- *height = *height - 2 * border;
- if (depth && *depth >= 3)
- *depth = *depth - 2 * border;
-}
-
-
-/**
- * Do glTexImage1/2/3D().
- */
-static void
-st_TexImage(struct gl_context * ctx,
- GLint dims,
- GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint depth,
- GLint border,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *unpack,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage,
- GLsizei imageSize, GLboolean compressed_src)
-{
- struct st_context *st = st_context(ctx);
- struct st_texture_object *stObj = st_texture_object(texObj);
- struct st_texture_image *stImage = st_texture_image(texImage);
- GLuint dstRowStride = 0;
- struct gl_pixelstore_attrib unpackNB;
- enum pipe_transfer_usage transfer_usage = 0;
-
- DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
- _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
-
- /* switch to "normal" */
- if (stObj->surface_based) {
- gl_format texFormat;
-
- _mesa_clear_texture_object(ctx, texObj);
- pipe_resource_reference(&stObj->pt, NULL);
-
- /* oops, need to init this image again */
- texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
- internalFormat, format, type);
-
- _mesa_init_teximage_fields(ctx, target, texImage,
- width, height, depth, border,
- internalFormat, texFormat);
-
- stObj->surface_based = GL_FALSE;
- }
-
- /* gallium does not support texture borders, strip it off */
- if (border) {
- strip_texture_border(border, &width, &height, &depth, unpack, &unpackNB);
- unpack = &unpackNB;
- texImage->Width = width;
- texImage->Height = height;
- texImage->Depth = depth;
- texImage->Border = 0;
- border = 0;
- }
- else {
- assert(texImage->Width == width);
- assert(texImage->Height == height);
- assert(texImage->Depth == depth);
- }
-
- stImage->face = _mesa_tex_target_to_face(target);
- stImage->level = level;
-
- _mesa_set_fetch_functions(texImage, dims);
-
- /* Release the reference to a potentially orphaned buffer.
- * Release any old malloced memory.
- */
- if (stImage->pt) {
- pipe_resource_reference(&stImage->pt, NULL);
- assert(!texImage->Data);
- }
- else if (texImage->Data) {
- _mesa_align_free(texImage->Data);
- }
-
- /*
- * See if the new image is somehow incompatible with the existing
- * mipmap. If so, free the old mipmap.
- */
- if (stObj->pt) {
- if (level > (GLint) stObj->pt->last_level ||
- !st_texture_match_image(stObj->pt, &stImage->base,
- stImage->face, stImage->level)) {
- DBG("release it\n");
- pipe_resource_reference(&stObj->pt, NULL);
- assert(!stObj->pt);
- pipe_sampler_view_reference(&stObj->sampler_view, NULL);
- }
- }
-
- if (width == 0 || height == 0 || depth == 0) {
- /* stop after freeing old image */
- return;
- }
-
- if (!stObj->pt) {
- if (!guess_and_alloc_texture(st, stObj, stImage)) {
- /* Probably out of memory.
- * Try flushing any pending rendering, then retry.
- */
- st_finish(st);
- if (!guess_and_alloc_texture(st, stObj, stImage)) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
- return;
- }
- }
- }
-
- assert(!stImage->pt);
-
- /* Check if this texture image can live inside the texture object's buffer.
- * If so, store the image there. Otherwise the image will temporarily live
- * in its own buffer.
- */
- if (stObj->pt &&
- st_texture_match_image(stObj->pt, &stImage->base,
- stImage->face, stImage->level)) {
-
- pipe_resource_reference(&stImage->pt, stObj->pt);
- assert(stImage->pt);
- }
-
- if (!stImage->pt)
- DBG("XXX: Image did not fit into texture - storing in local memory!\n");
-
- /* Pixel data may come from regular user memory or a PBO. For the later,
- * do bounds checking and map the PBO to read pixels data from it.
- *
- * XXX we should try to use a GPU-accelerated path to copy the image data
- * from the PBO to the texture.
- */
- if (compressed_src) {
- pixels = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, pixels,
- unpack,
- "glCompressedTexImage");
- }
- else {
- pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1,
- format, type,
- pixels, unpack, "glTexImage");
- }
-
- /* for a 1D array upload the image as a series of layer with height = 1 */
- if (target == GL_TEXTURE_1D_ARRAY) {
- depth = height;
- height = 1;
- }
-
- /*
- * Prepare to store the texture data. Either map the gallium texture buffer
- * memory or malloc space for it.
- */
- if (stImage->pt) {
- /* Store the image in the gallium texture memory buffer */
- if (format == GL_DEPTH_COMPONENT &&
- util_format_is_depth_and_stencil(stImage->pt->format))
- transfer_usage = PIPE_TRANSFER_READ_WRITE;
- else
- transfer_usage = PIPE_TRANSFER_WRITE;
-
- texImage->Data = st_texture_image_map(st, stImage, 0,
- transfer_usage, 0, 0, width, height);
- if(stImage->transfer)
- dstRowStride = stImage->transfer->stride;
- }
- else {
- /* Allocate regular memory and store the image there temporarily. */
- GLuint imageSize = _mesa_format_image_size(texImage->TexFormat,
- width, height, depth);
- dstRowStride = _mesa_format_row_stride(texImage->TexFormat, width);
-
- texImage->Data = _mesa_align_malloc(imageSize, 16);
- }
-
- if (!texImage->Data) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
- return;
- }
-
- if (!pixels) {
- /* We've allocated texture memory, but have no pixel data - all done. */
- goto done;
- }
-
- DBG("Upload image %dx%dx%d row_len %x pitch %x\n",
- width, height, depth, width, dstRowStride);
-
- /* Copy user texture image into the texture buffer.
- */
- if (compressed_src) {
- const GLuint srcRowStride =
- _mesa_format_row_stride(texImage->TexFormat, width);
- if (dstRowStride == srcRowStride) {
- memcpy(texImage->Data, pixels, imageSize);
- }
- else {
- char *dst = texImage->Data;
- const char *src = pixels;
- GLuint i, bw, bh, lines;
- _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
- lines = (height + bh - 1) / bh;
-
- for (i = 0; i < lines; ++i) {
- memcpy(dst, src, srcRowStride);
- dst += dstRowStride;
- src += srcRowStride;
- }
- }
- }
- else {
- const GLuint srcImageStride =
- _mesa_image_image_stride(unpack, width, height, format, type);
- GLint i;
- const GLubyte *src = (const GLubyte *) pixels;
-
- for (i = 0; i < depth; i++) {
- if (!_mesa_texstore(ctx, dims,
- texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- 0, 0, 0, /* dstX/Y/Zoffset */
- dstRowStride,
- texImage->ImageOffsets,
- width, height, 1,
- format, type, src, unpack)) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
- }
-
- if (stImage->pt && i + 1 < depth) {
- /* unmap this slice */
- st_texture_image_unmap(st, stImage);
- /* map next slice of 3D texture */
- texImage->Data = st_texture_image_map(st, stImage, i + 1,
- transfer_usage, 0, 0,
- width, height);
- src += srcImageStride;
- }
- }
- }
-
-done:
- _mesa_unmap_teximage_pbo(ctx, unpack);
-
- if (stImage->pt && texImage->Data) {
- st_texture_image_unmap(st, stImage);
- texImage->Data = NULL;
- }
-}
-
-
-static void
-st_TexImage3D(struct gl_context * ctx,
- GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint depth,
- GLint border,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *unpack,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- st_TexImage(ctx, 3, target, level, internalFormat, width, height, depth,
- border, format, type, pixels, unpack, texObj, texImage,
- 0, GL_FALSE);
-}
-
-
-static void
-st_TexImage2D(struct gl_context * ctx,
- GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint border,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *unpack,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
- format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
-}
-
-
-static void
-st_TexImage1D(struct gl_context * ctx,
- GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint border,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *unpack,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- st_TexImage(ctx, 1, target, level, internalFormat, width, 1, 1, border,
- format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
-}
-
-
-static void
-st_CompressedTexImage2D(struct gl_context *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint border,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
- 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, GL_TRUE);
-}
-
-
-
-/**
- * glGetTexImage() helper: decompress a compressed texture by rendering
- * a textured quad. Store the results in the user's buffer.
- */
-static void
-decompress_with_blit(struct gl_context * ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid *pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct st_texture_image *stImage = st_texture_image(texImage);
- struct st_texture_object *stObj = st_texture_object(texObj);
- struct pipe_sampler_view *src_view =
- st_get_texture_sampler_view(stObj, pipe);
- const GLuint width = texImage->Width;
- const GLuint height = texImage->Height;
- struct pipe_surface *dst_surface;
- struct pipe_resource *dst_texture;
- struct pipe_transfer *tex_xfer;
- unsigned bind = (PIPE_BIND_RENDER_TARGET | /* util_blit may choose to render */
- PIPE_BIND_TRANSFER_READ);
-
- /* create temp / dest surface */
- if (!util_create_rgba_surface(pipe, width, height, bind,
- &dst_texture, &dst_surface)) {
- _mesa_problem(ctx, "util_create_rgba_surface() failed "
- "in decompress_with_blit()");
- return;
- }
-
- /* blit/render/decompress */
- util_blit_pixels_tex(st->blit,
- src_view, /* pipe_resource (src) */
- 0, 0, /* src x0, y0 */
- width, height, /* src x1, y1 */
- dst_surface, /* pipe_surface (dst) */
- 0, 0, /* dst x0, y0 */
- width, height, /* dst x1, y1 */
- 0.0, /* z */
- PIPE_TEX_MIPFILTER_NEAREST);
-
- /* map the dst_surface so we can read from it */
- tex_xfer = pipe_get_transfer(st_context(ctx)->pipe,
- dst_texture, 0, 0,
- PIPE_TRANSFER_READ,
- 0, 0, width, height);
-
- pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels);
-
- /* copy/pack data into user buffer */
- if (st_equal_formats(stImage->pt->format, format, type)) {
- /* memcpy */
- const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format);
- ubyte *map = pipe_transfer_map(pipe, tex_xfer);
- GLuint row;
- for (row = 0; row < height; row++) {
- GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
- height, format, type, row, 0);
- memcpy(dest, map, bytesPerRow);
- map += tex_xfer->stride;
- }
- pipe_transfer_unmap(pipe, tex_xfer);
- }
- else {
- /* format translation via floats */
- GLuint row;
- enum pipe_format format = util_format_linear(dst_texture->format);
- for (row = 0; row < height; row++) {
- const GLbitfield transferOps = 0x0; /* bypassed for glGetTexImage() */
- GLfloat rgba[4 * MAX_WIDTH];
- GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
- height, format, type, row, 0);
-
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s: fallback format translation\n", __FUNCTION__);
-
- /* get float[4] rgba row from surface */
- pipe_get_tile_rgba_format(pipe, tex_xfer, 0, row, width, 1,
- format, rgba);
-
- _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
- type, dest, &ctx->Pack, transferOps);
- }
- }
-
- _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
-
- pipe->transfer_destroy(pipe, tex_xfer);
-
- /* destroy the temp / dest surface */
- util_destroy_rgba_surface(dst_texture, dst_surface);
-}
-
-
-
-/**
- * Need to map texture image into memory before copying image data,
- * then unmap it.
- */
-static void
-st_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid * pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage, GLboolean compressed_dst)
-{
- struct st_context *st = st_context(ctx);
- struct st_texture_image *stImage = st_texture_image(texImage);
- const GLuint dstImageStride =
- _mesa_image_image_stride(&ctx->Pack, texImage->Width, texImage->Height,
- format, type);
- GLuint depth, i;
- GLubyte *dest;
-
- if (stImage->pt &&
- util_format_is_s3tc(stImage->pt->format) &&
- !compressed_dst) {
- /* Need to decompress the texture.
- * We'll do this by rendering a textured quad.
- * Note that we only expect RGBA formats (no Z/depth formats).
- */
- decompress_with_blit(ctx, target, level, format, type, pixels,
- texObj, texImage);
- return;
- }
-
- /* Map */
- if (stImage->pt) {
- /* Image is stored in hardware format in a buffer managed by the
- * kernel. Need to explicitly map and unmap it.
- */
- texImage->Data = st_texture_image_map(st, stImage, 0,
- PIPE_TRANSFER_READ, 0, 0,
- stImage->base.Width,
- stImage->base.Height);
- /* compute stride in texels from stride in bytes */
- texImage->RowStride = stImage->transfer->stride
- * util_format_get_blockwidth(stImage->pt->format)
- / util_format_get_blocksize(stImage->pt->format);
- }
- else {
- /* Otherwise, the image should actually be stored in
- * texImage->Data. This is pretty confusing for
- * everybody, I'd much prefer to separate the two functions of
- * texImage->Data - storage for texture images in main memory
- * and access (ie mappings) of images. In other words, we'd
- * create a new texImage->Map field and leave Data simply for
- * storage.
- */
- assert(texImage->Data);
- }
-
- depth = texImage->Depth;
- texImage->Depth = 1;
-
- dest = (GLubyte *) pixels;
-
- _mesa_set_fetch_functions(texImage, get_texture_dims(target));
-
- for (i = 0; i < depth; i++) {
- if (compressed_dst) {
- _mesa_get_compressed_teximage(ctx, target, level, dest,
- texObj, texImage);
- }
- else {
- _mesa_get_teximage(ctx, target, level, format, type, dest,
- texObj, texImage);
- }
-
- if (stImage->pt && i + 1 < depth) {
- /* unmap this slice */
- st_texture_image_unmap(st, stImage);
- /* map next slice of 3D texture */
- texImage->Data = st_texture_image_map(st, stImage, i + 1,
- PIPE_TRANSFER_READ, 0, 0,
- stImage->base.Width,
- stImage->base.Height);
- dest += dstImageStride;
- }
- }
-
- texImage->Depth = depth;
-
- /* Unmap */
- if (stImage->pt) {
- st_texture_image_unmap(st, stImage);
- texImage->Data = NULL;
- }
-}
-
-
-static void
-st_GetTexImage(struct gl_context * ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid * pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- st_get_tex_image(ctx, target, level, format, type, pixels, texObj, texImage,
- GL_FALSE);
-}
-
-
-static void
-st_GetCompressedTexImage(struct gl_context *ctx, GLenum target, GLint level,
- GLvoid *pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- st_get_tex_image(ctx, target, level, 0, 0, pixels, texObj, texImage,
- GL_TRUE);
-}
-
-
-
-static void
-st_TexSubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint width, GLint height, GLint depth,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- struct st_context *st = st_context(ctx);
- struct st_texture_image *stImage = st_texture_image(texImage);
- GLuint dstRowStride;
- const GLuint srcImageStride =
- _mesa_image_image_stride(packing, width, height, format, type);
- GLint i;
- const GLubyte *src;
- /* init to silence warning only: */
- enum pipe_transfer_usage transfer_usage = PIPE_TRANSFER_WRITE;
-
- DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__,
- _mesa_lookup_enum_by_nr(target),
- level, xoffset, yoffset, width, height);
-
- pixels =
- _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, format,
- type, pixels, packing, "glTexSubImage2D");
- if (!pixels)
- return;
-
- /* for a 1D array upload the image as a series of layer with height = 1 */
- if (target == GL_TEXTURE_1D_ARRAY) {
- depth = height;
- height = 1;
- }
-
- /* Map buffer if necessary. Need to lock to prevent other contexts
- * from uploading the buffer under us.
- */
- if (stImage->pt) {
- if (format == GL_DEPTH_COMPONENT &&
- util_format_is_depth_and_stencil(stImage->pt->format))
- transfer_usage = PIPE_TRANSFER_READ_WRITE;
- else
- transfer_usage = PIPE_TRANSFER_WRITE;
-
- texImage->Data = st_texture_image_map(st, stImage, zoffset,
- transfer_usage,
- xoffset, yoffset,
- width, height);
- }
-
- if (!texImage->Data) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
- goto done;
- }
-
- src = (const GLubyte *) pixels;
- dstRowStride = stImage->transfer->stride;
-
- for (i = 0; i < depth; i++) {
- if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
- texImage->TexFormat,
- texImage->Data,
- 0, 0, 0,
- dstRowStride,
- texImage->ImageOffsets,
- width, height, 1,
- format, type, src, packing)) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
- }
-
- if (stImage->pt && i + 1 < depth) {
- /* unmap this slice */
- st_texture_image_unmap(st, stImage);
- /* map next slice of 3D texture */
- texImage->Data = st_texture_image_map(st, stImage,
- zoffset + i + 1,
- transfer_usage,
- xoffset, yoffset,
- width, height);
- src += srcImageStride;
- }
- }
-
-done:
- _mesa_unmap_teximage_pbo(ctx, packing);
-
- if (stImage->pt && texImage->Data) {
- st_texture_image_unmap(st, stImage);
- texImage->Data = NULL;
- }
-}
-
-
-
-static void
-st_TexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLenum type, const GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- st_TexSubimage(ctx, 3, target, level, xoffset, yoffset, zoffset,
- width, height, depth, format, type,
- pixels, packing, texObj, texImage);
-}
-
-
-static void
-st_TexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type, const GLvoid * pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- st_TexSubimage(ctx, 2, target, level, xoffset, yoffset, 0,
- width, height, 1, format, type,
- pixels, packing, texObj, texImage);
-}
-
-
-static void
-st_TexSubImage1D(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLsizei width, GLenum format, GLenum type,
- const GLvoid * pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- st_TexSubimage(ctx, 1, target, level, xoffset, 0, 0, width, 1, 1,
- format, type, pixels, packing, texObj, texImage);
-}
-
-
-static void
-st_CompressedTexSubImage1D(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLsizei width,
- GLenum format,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- assert(0);
-}
-
-
-static void
-st_CompressedTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLsizei width, GLint height,
- GLenum format,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- struct st_context *st = st_context(ctx);
- struct st_texture_image *stImage = st_texture_image(texImage);
- int srcBlockStride;
- int dstBlockStride;
- int y;
- enum pipe_format pformat;
-
- if (stImage->pt) {
- pformat = stImage->pt->format;
-
- texImage->Data = st_texture_image_map(st, stImage, 0,
- PIPE_TRANSFER_WRITE,
- xoffset, yoffset,
- width, height);
-
- srcBlockStride = util_format_get_stride(pformat, width);
- dstBlockStride = stImage->transfer->stride;
- } else {
- assert(stImage->pt);
- /* TODO find good values for block and strides */
- /* TODO also adjust texImage->data for yoffset/xoffset */
- return;
- }
-
- if (!texImage->Data) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage");
- return;
- }
-
- assert(xoffset % util_format_get_blockwidth(pformat) == 0);
- assert(yoffset % util_format_get_blockheight(pformat) == 0);
-
- for (y = 0; y < height; y += util_format_get_blockheight(pformat)) {
- /* don't need to adjust for xoffset and yoffset as st_texture_image_map does that */
- const char *src = (const char*)data + srcBlockStride * util_format_get_nblocksy(pformat, y);
- char *dst = (char*)texImage->Data + dstBlockStride * util_format_get_nblocksy(pformat, y);
- memcpy(dst, src, util_format_get_stride(pformat, width));
- }
-
- if (stImage->pt) {
- st_texture_image_unmap(st, stImage);
- texImage->Data = NULL;
- }
-}
-
-
-static void
-st_CompressedTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLint height, GLint depth,
- GLenum format,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- assert(0);
-}
-
-
-
-/**
- * Do a CopyTexSubImage operation using a read transfer from the source,
- * a write transfer to the destination and get_tile()/put_tile() to access
- * the pixels/texels.
- *
- * Note: srcY=0=TOP of renderbuffer
- */
-static void
-fallback_copy_texsubimage(struct gl_context *ctx, GLenum target, GLint level,
- struct st_renderbuffer *strb,
- struct st_texture_image *stImage,
- GLenum baseFormat,
- GLint destX, GLint destY, GLint destZ,
- GLint srcX, GLint srcY,
- GLsizei width, GLsizei height)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct pipe_transfer *src_trans;
- GLvoid *texDest;
- enum pipe_transfer_usage transfer_usage;
-
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s: fallback processing\n", __FUNCTION__);
-
- assert(width <= MAX_WIDTH);
-
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- srcY = strb->Base.Height - srcY - height;
- }
-
- src_trans = pipe_get_transfer(st_context(ctx)->pipe,
- strb->texture,
- 0, 0,
- PIPE_TRANSFER_READ,
- srcX, srcY,
- width, height);
-
- if ((baseFormat == GL_DEPTH_COMPONENT ||
- baseFormat == GL_DEPTH_STENCIL) &&
- util_format_is_depth_and_stencil(stImage->pt->format))
- transfer_usage = PIPE_TRANSFER_READ_WRITE;
- else
- transfer_usage = PIPE_TRANSFER_WRITE;
-
- /* XXX this used to ignore destZ param */
- texDest = st_texture_image_map(st, stImage, destZ, transfer_usage,
- destX, destY, width, height);
-
- if (baseFormat == GL_DEPTH_COMPONENT ||
- baseFormat == GL_DEPTH_STENCIL) {
- const GLboolean scaleOrBias = (ctx->Pixel.DepthScale != 1.0F ||
- ctx->Pixel.DepthBias != 0.0F);
- GLint row, yStep;
-
- /* determine bottom-to-top vs. top-to-bottom order for src buffer */
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- srcY = height - 1;
- yStep = -1;
- }
- else {
- srcY = 0;
- yStep = 1;
- }
-
- /* To avoid a large temp memory allocation, do copy row by row */
- for (row = 0; row < height; row++, srcY += yStep) {
- uint data[MAX_WIDTH];
- pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data);
- if (scaleOrBias) {
- _mesa_scale_and_bias_depth_uint(ctx, width, data);
- }
- pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data);
- }
- }
- else {
- /* RGBA format */
- GLfloat *tempSrc =
- (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
-
- if (tempSrc && texDest) {
- const GLint dims = 2;
- const GLint dstRowStride = stImage->transfer->stride;
- struct gl_texture_image *texImage = &stImage->base;
- struct gl_pixelstore_attrib unpack = ctx->DefaultPacking;
-
- if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- unpack.Invert = GL_TRUE;
- }
-
- /* get float/RGBA image from framebuffer */
- /* XXX this usually involves a lot of int/float conversion.
- * try to avoid that someday.
- */
- pipe_get_tile_rgba_format(pipe, src_trans, 0, 0, width, height,
- util_format_linear(strb->texture->format),
- tempSrc);
-
- /* Store into texture memory.
- * Note that this does some special things such as pixel transfer
- * ops and format conversion. In particular, if the dest tex format
- * is actually RGBA but the user created the texture as GL_RGB we
- * need to fill-in/override the alpha channel with 1.0.
- */
- _mesa_texstore(ctx, dims,
- texImage->_BaseFormat,
- texImage->TexFormat,
- texDest,
- 0, 0, 0,
- dstRowStride,
- texImage->ImageOffsets,
- width, height, 1,
- GL_RGBA, GL_FLOAT, tempSrc, /* src */
- &unpack);
- }
- else {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
- }
-
- if (tempSrc)
- free(tempSrc);
- }
-
- st_texture_image_unmap(st, stImage);
- pipe->transfer_destroy(pipe, src_trans);
-}
-
-
-
-/**
- * If the format of the src renderbuffer and the format of the dest
- * texture are compatible (in terms of blitting), return a TGSI writemask
- * to be used during the blit.
- * If the src/dest are incompatible, return 0.
- */
-static unsigned
-compatible_src_dst_formats(struct gl_context *ctx,
- const struct gl_renderbuffer *src,
- const struct gl_texture_image *dst)
-{
- /* Get logical base formats for the src and dest.
- * That is, use the user-requested formats and not the actual, device-
- * chosen formats.
- * For example, the user may have requested an A8 texture but the
- * driver may actually be using an RGBA texture format. When we
- * copy/blit to that texture, we only want to copy the Alpha channel
- * and not the RGB channels.
- *
- * Similarly, when the src FBO was created an RGB format may have been
- * requested but the driver actually chose an RGBA format. In that case,
- * we don't want to copy the undefined Alpha channel to the dest texture
- * (it should be 1.0).
- */
- const GLenum srcFormat = _mesa_base_fbo_format(ctx, src->InternalFormat);
- const GLenum dstFormat = _mesa_base_tex_format(ctx, dst->InternalFormat);
-
- /**
- * XXX when we have red-only and red/green renderbuffers we'll need
- * to add more cases here (or implement a general-purpose routine that
- * queries the existance of the R,G,B,A channels in the src and dest).
- */
- if (srcFormat == dstFormat) {
- /* This is the same as matching_base_formats, which should
- * always pass, as it did previously.
- */
- return TGSI_WRITEMASK_XYZW;
- }
- else if (srcFormat == GL_RGB && dstFormat == GL_RGBA) {
- /* Make sure that A in the dest is 1. The actual src format
- * may be RGBA and have undefined A values.
- */
- return TGSI_WRITEMASK_XYZ;
- }
- else if (srcFormat == GL_RGBA && dstFormat == GL_RGB) {
- /* Make sure that A in the dest is 1. The actual dst format
- * may be RGBA and will need A=1 to provide proper alpha values
- * when sampled later.
- */
- return TGSI_WRITEMASK_XYZ;
- }
- else {
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s failed for src %s, dst %s\n",
- __FUNCTION__,
- _mesa_lookup_enum_by_nr(srcFormat),
- _mesa_lookup_enum_by_nr(dstFormat));
-
- /* Otherwise fail.
- */
- return 0;
- }
-}
-
-
-
-/**
- * Do a CopyTex[Sub]Image1/2/3D() using a hardware (blit) path if possible.
- * Note that the region to copy has already been clipped so we know we
- * won't read from outside the source renderbuffer's bounds.
- *
- * Note: srcY=0=Bottom of renderbuffer (GL convention)
- */
-static void
-st_copy_texsubimage(struct gl_context *ctx,
- GLenum target, GLint level,
- GLint destX, GLint destY, GLint destZ,
- GLint srcX, GLint srcY,
- GLsizei width, GLsizei height)
-{
- struct gl_texture_unit *texUnit =
- &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- struct gl_texture_object *texObj =
- _mesa_select_tex_object(ctx, texUnit, target);
- struct gl_texture_image *texImage =
- _mesa_select_tex_image(ctx, texObj, target, level);
- struct st_texture_image *stImage = st_texture_image(texImage);
- const GLenum texBaseFormat = texImage->_BaseFormat;
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct st_renderbuffer *strb;
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
- enum pipe_format dest_format, src_format;
- GLboolean use_fallback = GL_TRUE;
- GLboolean matching_base_formats;
- GLuint format_writemask, sample_count;
- struct pipe_surface *dest_surface = NULL;
- GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
-
- /* make sure finalize_textures has been called?
- */
- if (0) st_validate_state(st);
-
- /* determine if copying depth or color data */
- if (texBaseFormat == GL_DEPTH_COMPONENT ||
- texBaseFormat == GL_DEPTH_STENCIL) {
- strb = st_renderbuffer(fb->_DepthBuffer);
- if (strb->Base.Wrapped) {
- strb = st_renderbuffer(strb->Base.Wrapped);
- }
- }
- else {
- /* texBaseFormat == GL_RGB, GL_RGBA, GL_ALPHA, etc */
- strb = st_renderbuffer(fb->_ColorReadBuffer);
- }
-
- if (!strb || !strb->surface || !stImage->pt) {
- debug_printf("%s: null strb or stImage\n", __FUNCTION__);
- return;
- }
-
- sample_count = strb->surface->texture->nr_samples;
- /* I believe this would be legal, presumably would need to do a resolve
- for color, and for depth/stencil spec says to just use one of the
- depth/stencil samples per pixel? Need some transfer clarifications. */
- assert(sample_count < 2);
-
- if (srcX < 0) {
- width -= -srcX;
- destX += -srcX;
- srcX = 0;
- }
-
- if (srcY < 0) {
- height -= -srcY;
- destY += -srcY;
- srcY = 0;
- }
-
- if (destX < 0) {
- width -= -destX;
- srcX += -destX;
- destX = 0;
- }
-
- if (destY < 0) {
- height -= -destY;
- srcY += -destY;
- destY = 0;
- }
-
- if (width < 0 || height < 0)
- return;
-
-
- assert(strb);
- assert(strb->surface);
- assert(stImage->pt);
-
- src_format = strb->surface->format;
- dest_format = stImage->pt->format;
-
- /*
- * Determine if the src framebuffer and dest texture have the same
- * base format. We need this to detect a case such as the framebuffer
- * being GL_RGBA but the texture being GL_RGB. If the actual hardware
- * texture format stores RGBA we need to set A=1 (overriding the
- * framebuffer's alpha values). We can't do that with the blit or
- * textured-quad paths.
- */
- matching_base_formats =
- (_mesa_get_format_base_format(strb->Base.Format) ==
- _mesa_get_format_base_format(texImage->TexFormat));
- format_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage);
-
- if (ctx->_ImageTransferState == 0x0) {
-
- if (matching_base_formats &&
- src_format == dest_format &&
- !do_flip)
- {
- /* use surface_copy() / blit */
- struct pipe_box src_box;
- u_box_2d_zslice(srcX, srcY, strb->surface->u.tex.first_layer,
- width, height, &src_box);
-
- /* for resource_copy_region(), y=0=top, always */
- pipe->resource_copy_region(pipe,
- /* dest */
- stImage->pt,
- stImage->level,
- destX, destY, destZ + stImage->face,
- /* src */
- strb->texture,
- strb->surface->u.tex.level,
- &src_box);
- use_fallback = GL_FALSE;
- }
- else if (format_writemask &&
- texBaseFormat != GL_DEPTH_COMPONENT &&
- texBaseFormat != GL_DEPTH_STENCIL &&
- screen->is_format_supported(screen, src_format,
- PIPE_TEXTURE_2D, sample_count,
- PIPE_BIND_SAMPLER_VIEW,
- 0) &&
- screen->is_format_supported(screen, dest_format,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET,
- 0)) {
- /* draw textured quad to do the copy */
- GLint srcY0, srcY1;
- struct pipe_surface surf_tmpl;
- memset(&surf_tmpl, 0, sizeof(surf_tmpl));
- surf_tmpl.format = stImage->pt->format;
- surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
- surf_tmpl.u.tex.level = stImage->level;
- surf_tmpl.u.tex.first_layer = stImage->face + destZ;
- surf_tmpl.u.tex.last_layer = stImage->face + destZ;
-
- dest_surface = pipe->create_surface(pipe, stImage->pt,
- &surf_tmpl);
-
- if (do_flip) {
- srcY1 = strb->Base.Height - srcY - height;
- srcY0 = srcY1 + height;
- }
- else {
- srcY0 = srcY;
- srcY1 = srcY0 + height;
- }
-
- util_blit_pixels_writemask(st->blit,
- strb->texture,
- strb->surface->u.tex.level,
- srcX, srcY0,
- srcX + width, srcY1,
- strb->surface->u.tex.first_layer,
- dest_surface,
- destX, destY,
- destX + width, destY + height,
- 0.0, PIPE_TEX_MIPFILTER_NEAREST,
- format_writemask);
- use_fallback = GL_FALSE;
- }
-
- if (dest_surface)
- pipe_surface_reference(&dest_surface, NULL);
- }
-
- if (use_fallback) {
- /* software fallback */
- fallback_copy_texsubimage(ctx, target, level,
- strb, stImage, texBaseFormat,
- destX, destY, destZ,
- srcX, srcY, width, height);
- }
-}
-
-
-
-static void
-st_CopyTexImage1D(struct gl_context * ctx, GLenum target, GLint level,
- GLenum internalFormat,
- GLint x, GLint y, GLsizei width, GLint border)
-{
- struct gl_texture_unit *texUnit =
- &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- struct gl_texture_object *texObj =
- _mesa_select_tex_object(ctx, texUnit, target);
- struct gl_texture_image *texImage =
- _mesa_select_tex_image(ctx, texObj, target, level);
-
- /* Setup or redefine the texture object, texture and texture
- * image. Don't populate yet.
- */
- ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
- width, border,
- GL_RGBA, CHAN_TYPE, NULL,
- &ctx->DefaultPacking, texObj, texImage);
-
- st_copy_texsubimage(ctx, target, level,
- 0, 0, 0, /* destX,Y,Z */
- x, y, width, 1); /* src X, Y, size */
-}
-
-
-static void
-st_CopyTexImage2D(struct gl_context * ctx, GLenum target, GLint level,
- GLenum internalFormat,
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLint border)
-{
- struct gl_texture_unit *texUnit =
- &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- struct gl_texture_object *texObj =
- _mesa_select_tex_object(ctx, texUnit, target);
- struct gl_texture_image *texImage =
- _mesa_select_tex_image(ctx, texObj, target, level);
-
- /* Setup or redefine the texture object, texture and texture
- * image. Don't populate yet.
- */
- ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
- width, height, border,
- GL_RGBA, CHAN_TYPE, NULL,
- &ctx->DefaultPacking, texObj, texImage);
-
- st_copy_texsubimage(ctx, target, level,
- 0, 0, 0, /* destX,Y,Z */
- x, y, width, height); /* src X, Y, size */
-}
-
-
-static void
-st_CopyTexSubImage1D(struct gl_context * ctx, GLenum target, GLint level,
- GLint xoffset, GLint x, GLint y, GLsizei width)
-{
- const GLint yoffset = 0, zoffset = 0;
- const GLsizei height = 1;
- st_copy_texsubimage(ctx, target, level,
- xoffset, yoffset, zoffset, /* destX,Y,Z */
- x, y, width, height); /* src X, Y, size */
-}
-
-
-static void
-st_CopyTexSubImage2D(struct gl_context * ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset,
- GLint x, GLint y, GLsizei width, GLsizei height)
-{
- const GLint zoffset = 0;
- st_copy_texsubimage(ctx, target, level,
- xoffset, yoffset, zoffset, /* destX,Y,Z */
- x, y, width, height); /* src X, Y, size */
-}
-
-
-static void
-st_CopyTexSubImage3D(struct gl_context * ctx, GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint x, GLint y, GLsizei width, GLsizei height)
-{
- st_copy_texsubimage(ctx, target, level,
- xoffset, yoffset, zoffset, /* destX,Y,Z */
- x, y, width, height); /* src X, Y, size */
-}
-
-
-/**
- * Copy image data from stImage into the texture object 'stObj' at level
- * 'dstLevel'.
- */
-static void
-copy_image_data_to_texture(struct st_context *st,
- struct st_texture_object *stObj,
- GLuint dstLevel,
- struct st_texture_image *stImage)
-{
- /* debug checks */
- {
- const struct gl_texture_image *dstImage =
- stObj->base.Image[stImage->face][stImage->level];
- assert(dstImage);
- assert(dstImage->Width == stImage->base.Width);
- assert(dstImage->Height == stImage->base.Height);
- assert(dstImage->Depth == stImage->base.Depth);
- }
-
- if (stImage->pt) {
- /* Copy potentially with the blitter:
- */
- st_texture_image_copy(st->pipe,
- stObj->pt, dstLevel, /* dest texture, level */
- stImage->pt, stImage->level, /* src texture, level */
- stImage->face);
-
- pipe_resource_reference(&stImage->pt, NULL);
- }
- else if (stImage->base.Data) {
- st_texture_image_data(st,
- stObj->pt,
- stImage->face,
- dstLevel,
- stImage->base.Data,
- stImage->base.RowStride *
- util_format_get_blocksize(stObj->pt->format),
- stImage->base.RowStride *
- stImage->base.Height *
- util_format_get_blocksize(stObj->pt->format));
- _mesa_align_free(stImage->base.Data);
- stImage->base.Data = NULL;
- }
-
- pipe_resource_reference(&stImage->pt, stObj->pt);
-}
-
-
-/**
- * Called during state validation. When this function is finished,
- * the texture object should be ready for rendering.
- * \return GL_TRUE for success, GL_FALSE for failure (out of mem)
- */
-GLboolean
-st_finalize_texture(struct gl_context *ctx,
- struct pipe_context *pipe,
- struct gl_texture_object *tObj)
-{
- struct st_context *st = st_context(ctx);
- struct st_texture_object *stObj = st_texture_object(tObj);
- const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
- GLuint face;
- struct st_texture_image *firstImage;
- enum pipe_format firstImageFormat;
- GLuint ptWidth, ptHeight, ptDepth, ptLayers;
-
- if (stObj->base._Complete) {
- /* The texture is complete and we know exactly how many mipmap levels
- * are present/needed. This is conditional because we may be called
- * from the st_generate_mipmap() function when the texture object is
- * incomplete. In that case, we'll have set stObj->lastLevel before
- * we get here.
- */
- if (stObj->base.MinFilter == GL_LINEAR ||
- stObj->base.MinFilter == GL_NEAREST)
- stObj->lastLevel = stObj->base.BaseLevel;
- else
- stObj->lastLevel = stObj->base._MaxLevel;
- }
-
- firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
- assert(firstImage);
-
- /* If both firstImage and stObj point to a texture which can contain
- * all active images, favour firstImage. Note that because of the
- * completeness requirement, we know that the image dimensions
- * will match.
- */
- if (firstImage->pt &&
- firstImage->pt != stObj->pt &&
- (!stObj->pt || firstImage->pt->last_level >= stObj->pt->last_level)) {
- pipe_resource_reference(&stObj->pt, firstImage->pt);
- pipe_sampler_view_reference(&stObj->sampler_view, NULL);
- }
-
- /* Find gallium format for the Mesa texture */
- firstImageFormat = st_mesa_format_to_pipe_format(firstImage->base.TexFormat);
-
- /* Find size of level=0 Gallium mipmap image, plus number of texture layers */
- {
- GLuint width, height, depth;
- if (!guess_base_level_size(stObj->base.Target,
- firstImage->base.Width2,
- firstImage->base.Height2,
- firstImage->base.Depth2,
- stObj->base.BaseLevel,
- &width, &height, &depth)) {
- width = stObj->width0;
- height = stObj->height0;
- depth = stObj->depth0;
- }
- /* convert GL dims to Gallium dims */
- st_gl_texture_dims_to_pipe_dims(stObj->base.Target, width, height, depth,
- &ptWidth, &ptHeight, &ptDepth, &ptLayers);
- }
-
- /* If we already have a gallium texture, check that it matches the texture
- * object's format, target, size, num_levels, etc.
- */
- if (stObj->pt) {
- if (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) ||
- !st_sampler_compat_formats(stObj->pt->format, firstImageFormat) ||
- stObj->pt->last_level < stObj->lastLevel ||
- stObj->pt->width0 != ptWidth ||
- stObj->pt->height0 != ptHeight ||
- stObj->pt->depth0 != ptDepth ||
- stObj->pt->array_size != ptLayers)
- {
- /* The gallium texture does not match the Mesa texture so delete the
- * gallium texture now. We'll make a new one below.
- */
- pipe_resource_reference(&stObj->pt, NULL);
- pipe_sampler_view_reference(&stObj->sampler_view, NULL);
- st->dirty.st |= ST_NEW_FRAMEBUFFER;
- }
- }
-
- /* May need to create a new gallium texture:
- */
- if (!stObj->pt) {
- GLuint bindings = default_bindings(st, firstImageFormat);
-
- stObj->pt = st_texture_create(st,
- gl_target_to_pipe(stObj->base.Target),
- firstImageFormat,
- stObj->lastLevel,
- ptWidth,
- ptHeight,
- ptDepth,
- ptLayers,
- bindings);
-
- if (!stObj->pt) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
- return GL_FALSE;
- }
- }
-
- /* Pull in any images not in the object's texture:
- */
- for (face = 0; face < nr_faces; face++) {
- GLuint level;
- for (level = stObj->base.BaseLevel; level <= stObj->lastLevel; level++) {
- struct st_texture_image *stImage =
- st_texture_image(stObj->base.Image[face][level]);
-
- /* Need to import images in main memory or held in other textures.
- */
- if (stImage && stObj->pt != stImage->pt) {
- copy_image_data_to_texture(st, stObj, level, stImage);
- }
- }
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Returns pointer to a default/dummy texture.
- * This is typically used when the current shader has tex/sample instructions
- * but the user has not provided a (any) texture(s).
- */
-struct gl_texture_object *
-st_get_default_texture(struct st_context *st)
-{
- if (!st->default_texture) {
- static const GLenum target = GL_TEXTURE_2D;
- GLubyte pixels[16][16][4];
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImg;
- GLuint i, j;
-
- /* The ARB_fragment_program spec says (0,0,0,1) should be returned
- * when attempting to sample incomplete textures.
- */
- for (i = 0; i < 16; i++) {
- for (j = 0; j < 16; j++) {
- pixels[i][j][0] = 0;
- pixels[i][j][1] = 0;
- pixels[i][j][2] = 0;
- pixels[i][j][3] = 255;
- }
- }
-
- texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target);
-
- texImg = _mesa_get_tex_image(st->ctx, texObj, target, 0);
-
- _mesa_init_teximage_fields(st->ctx, target, texImg,
- 16, 16, 1, 0, /* w, h, d, border */
- GL_RGBA, MESA_FORMAT_RGBA8888);
-
- st_TexImage(st->ctx, 2, target,
- 0, GL_RGBA, /* level, intformat */
- 16, 16, 1, 0, /* w, h, d, border */
- GL_RGBA, GL_UNSIGNED_BYTE, pixels,
- &st->ctx->DefaultPacking,
- texObj, texImg,
- 0, 0);
-
- texObj->MinFilter = GL_NEAREST;
- texObj->MagFilter = GL_NEAREST;
- texObj->_Complete = GL_TRUE;
-
- st->default_texture = texObj;
- }
- return st->default_texture;
-}
-
-
-void
-st_init_texture_functions(struct dd_function_table *functions)
-{
- functions->ChooseTextureFormat = st_ChooseTextureFormat;
- functions->TexImage1D = st_TexImage1D;
- functions->TexImage2D = st_TexImage2D;
- functions->TexImage3D = st_TexImage3D;
- functions->TexSubImage1D = st_TexSubImage1D;
- functions->TexSubImage2D = st_TexSubImage2D;
- functions->TexSubImage3D = st_TexSubImage3D;
- functions->CompressedTexSubImage1D = st_CompressedTexSubImage1D;
- functions->CompressedTexSubImage2D = st_CompressedTexSubImage2D;
- functions->CompressedTexSubImage3D = st_CompressedTexSubImage3D;
- functions->CopyTexImage1D = st_CopyTexImage1D;
- functions->CopyTexImage2D = st_CopyTexImage2D;
- functions->CopyTexSubImage1D = st_CopyTexSubImage1D;
- functions->CopyTexSubImage2D = st_CopyTexSubImage2D;
- functions->CopyTexSubImage3D = st_CopyTexSubImage3D;
- functions->GenerateMipmap = st_generate_mipmap;
-
- functions->GetTexImage = st_GetTexImage;
-
- /* compressed texture functions */
- functions->CompressedTexImage2D = st_CompressedTexImage2D;
- functions->GetCompressedTexImage = st_GetCompressedTexImage;
-
- functions->NewTextureObject = st_NewTextureObject;
- functions->NewTextureImage = st_NewTextureImage;
- functions->DeleteTexture = st_DeleteTextureObject;
- functions->FreeTexImageData = st_FreeTextureImageData;
-
- functions->TextureMemCpy = do_memcpy;
-
- /* XXX Temporary until we can query pipe's texture sizes */
- functions->TestProxyTexImage = _mesa_test_proxy_teximage;
-}
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "main/mfeatures.h"
+#include "main/bufferobj.h"
+#include "main/enums.h"
+#include "main/fbobject.h"
+#include "main/formats.h"
+#include "main/image.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/mipmap.h"
+#include "main/pack.h"
+#include "main/pbo.h"
+#include "main/pixeltransfer.h"
+#include "main/texcompress.h"
+#include "main/texfetch.h"
+#include "main/texgetimage.h"
+#include "main/teximage.h"
+#include "main/texobj.h"
+#include "main/texstore.h"
+
+#include "state_tracker/st_debug.h"
+#include "state_tracker/st_context.h"
+#include "state_tracker/st_cb_fbo.h"
+#include "state_tracker/st_cb_flush.h"
+#include "state_tracker/st_cb_texture.h"
+#include "state_tracker/st_format.h"
+#include "state_tracker/st_texture.h"
+#include "state_tracker/st_gen_mipmap.h"
+#include "state_tracker/st_atom.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "pipe/p_shader_tokens.h"
+#include "util/u_tile.h"
+#include "util/u_blit.h"
+#include "util/u_format.h"
+#include "util/u_surface.h"
+#include "util/u_sampler.h"
+#include "util/u_math.h"
+#include "util/u_box.h"
+
+#define DBG if (0) printf
+
+
+static enum pipe_texture_target
+gl_target_to_pipe(GLenum target)
+{
+ switch (target) {
+ case GL_TEXTURE_1D:
+ return PIPE_TEXTURE_1D;
+ case GL_TEXTURE_2D:
+ return PIPE_TEXTURE_2D;
+ case GL_TEXTURE_RECTANGLE_NV:
+ return PIPE_TEXTURE_RECT;
+ case GL_TEXTURE_3D:
+ return PIPE_TEXTURE_3D;
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ return PIPE_TEXTURE_CUBE;
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ return PIPE_TEXTURE_1D_ARRAY;
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ return PIPE_TEXTURE_2D_ARRAY;
+ default:
+ assert(0);
+ return 0;
+ }
+}
+
+
+/** called via ctx->Driver.NewTextureImage() */
+static struct gl_texture_image *
+st_NewTextureImage(struct gl_context * ctx)
+{
+ DBG("%s\n", __FUNCTION__);
+ (void) ctx;
+ return (struct gl_texture_image *) ST_CALLOC_STRUCT(st_texture_image);
+}
+
+
+/** called via ctx->Driver.NewTextureObject() */
+static struct gl_texture_object *
+st_NewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
+{
+ struct st_texture_object *obj = ST_CALLOC_STRUCT(st_texture_object);
+
+ DBG("%s\n", __FUNCTION__);
+ _mesa_initialize_texture_object(&obj->base, name, target);
+
+ return &obj->base;
+}
+
+/** called via ctx->Driver.DeleteTextureObject() */
+static void
+st_DeleteTextureObject(struct gl_context *ctx,
+ struct gl_texture_object *texObj)
+{
+ struct st_context *st = st_context(ctx);
+ struct st_texture_object *stObj = st_texture_object(texObj);
+ if (stObj->pt)
+ pipe_resource_reference(&stObj->pt, NULL);
+ if (stObj->sampler_view) {
+ if (stObj->sampler_view->context != st->pipe) {
+ /* Take "ownership" of this texture sampler view by setting
+ * its context pointer to this context. This avoids potential
+ * crashes when the texture object is shared among contexts
+ * and the original/owner context has already been destroyed.
+ */
+ stObj->sampler_view->context = st->pipe;
+ }
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+ }
+ _mesa_delete_texture_object(ctx, texObj);
+}
+
+
+/** called via ctx->Driver.FreeTexImageData() */
+static void
+st_FreeTextureImageData(struct gl_context * ctx, struct gl_texture_image *texImage)
+{
+ struct st_texture_image *stImage = st_texture_image(texImage);
+
+ DBG("%s\n", __FUNCTION__);
+
+ if (stImage->pt) {
+ pipe_resource_reference(&stImage->pt, NULL);
+ }
+
+ if (texImage->Data) {
+ _mesa_align_free(texImage->Data);
+ texImage->Data = NULL;
+ }
+}
+
+
+/**
+ * From linux kernel i386 header files, copes with odd sizes better
+ * than COPY_DWORDS would:
+ * XXX Put this in src/mesa/main/imports.h ???
+ */
+#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
+static INLINE void *
+__memcpy(void *to, const void *from, size_t n)
+{
+ int d0, d1, d2;
+ __asm__ __volatile__("rep ; movsl\n\t"
+ "testb $2,%b4\n\t"
+ "je 1f\n\t"
+ "movsw\n"
+ "1:\ttestb $1,%b4\n\t"
+ "je 2f\n\t"
+ "movsb\n" "2:":"=&c"(d0), "=&D"(d1), "=&S"(d2)
+ :"0"(n / 4), "q"(n), "1"((long) to), "2"((long) from)
+ :"memory");
+ return (to);
+}
+#else
+#define __memcpy(a,b,c) memcpy(a,b,c)
+#endif
+
+
+/**
+ * The system memcpy (at least on ubuntu 5.10) has problems copying
+ * to agp (writecombined) memory from a source which isn't 64-byte
+ * aligned - there is a 4x performance falloff.
+ *
+ * The x86 __memcpy is immune to this but is slightly slower
+ * (10%-ish) than the system memcpy.
+ *
+ * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
+ * isn't much faster than x86_memcpy for agp copies.
+ *
+ * TODO: switch dynamically.
+ */
+static void *
+do_memcpy(void *dest, const void *src, size_t n)
+{
+ if ((((unsigned long) src) & 63) || (((unsigned long) dest) & 63)) {
+ return __memcpy(dest, src, n);
+ }
+ else
+ return memcpy(dest, src, n);
+}
+
+
+/**
+ * Return default texture resource binding bitmask for the given format.
+ */
+static GLuint
+default_bindings(struct st_context *st, enum pipe_format format)
+{
+ struct pipe_screen *screen = st->pipe->screen;
+ const unsigned target = PIPE_TEXTURE_2D;
+ const unsigned geom = 0x0;
+ unsigned bindings;
+
+ if (util_format_is_depth_or_stencil(format))
+ bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_DEPTH_STENCIL;
+ else
+ bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
+
+ if (screen->is_format_supported(screen, format, target, 0, bindings, geom))
+ return bindings;
+ else
+ return PIPE_BIND_SAMPLER_VIEW;
+}
+
+
+/** Return number of image dimensions (1, 2 or 3) for a texture target. */
+static GLuint
+get_texture_dims(GLenum target)
+{
+ switch (target) {
+ case GL_TEXTURE_1D:
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ return 1;
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
+ case GL_TEXTURE_RECTANGLE_NV:
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ return 2;
+ case GL_TEXTURE_3D:
+ return 3;
+ default:
+ assert(0 && "invalid texture target in get_texture_dims()");
+ return 1;
+ }
+}
+
+
+/**
+ * Given the size of a mipmap image, try to compute the size of the level=0
+ * mipmap image.
+ *
+ * Note that this isn't always accurate for odd-sized, non-POW textures.
+ * For example, if level=1 and width=40 then the level=0 width may be 80 or 81.
+ *
+ * \return GL_TRUE for success, GL_FALSE for failure
+ */
+static GLboolean
+guess_base_level_size(GLenum target,
+ GLuint width, GLuint height, GLuint depth, GLuint level,
+ GLuint *width0, GLuint *height0, GLuint *depth0)
+{
+ const GLuint dims = get_texture_dims(target);
+
+ assert(width >= 1);
+ assert(height >= 1);
+ assert(depth >= 1);
+
+ if (level > 0) {
+ /* Depending on the image's size, we can't always make a guess here */
+ if ((dims >= 1 && width == 1) ||
+ (dims >= 2 && height == 1) ||
+ (dims >= 3 && depth == 1)) {
+ /* we can't determine the image size at level=0 */
+ return GL_FALSE;
+ }
+
+ /* grow the image size until we hit level = 0 */
+ while (level > 0) {
+ if (width > 1)
+ width <<= 1;
+ if (height > 1)
+ height <<= 1;
+ if (depth > 1)
+ depth <<= 1;
+ level--;
+ }
+ }
+
+ *width0 = width;
+ *height0 = height;
+ *depth0 = depth;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Try to allocate a pipe_resource object for the given st_texture_object.
+ *
+ * We use the given st_texture_image as a clue to determine the size of the
+ * mipmap image at level=0.
+ *
+ * \return GL_TRUE for success, GL_FALSE if out of memory.
+ */
+static GLboolean
+guess_and_alloc_texture(struct st_context *st,
+ struct st_texture_object *stObj,
+ const struct st_texture_image *stImage)
+{
+ GLuint lastLevel, width, height, depth;
+ GLuint bindings;
+ GLuint ptWidth, ptHeight, ptDepth, ptLayers;
+ enum pipe_format fmt;
+
+ DBG("%s\n", __FUNCTION__);
+
+ assert(!stObj->pt);
+
+ if (!guess_base_level_size(stObj->base.Target,
+ stImage->base.Width2,
+ stImage->base.Height2,
+ stImage->base.Depth2,
+ stImage->level,
+ &width, &height, &depth)) {
+ /* we can't determine the image size at level=0 */
+ stObj->width0 = stObj->height0 = stObj->depth0 = 0;
+ /* this is not an out of memory error */
+ return GL_TRUE;
+ }
+
+ /* At this point, (width x height x depth) is the expected size of
+ * the level=0 mipmap image.
+ */
+
+ /* Guess a reasonable value for lastLevel. With OpenGL we have no
+ * idea how many mipmap levels will be in a texture until we start
+ * to render with it. Make an educated guess here but be prepared
+ * to re-allocating a texture buffer with space for more (or fewer)
+ * mipmap levels later.
+ */
+ if ((stObj->base.MinFilter == GL_NEAREST ||
+ stObj->base.MinFilter == GL_LINEAR ||
+ stImage->base._BaseFormat == GL_DEPTH_COMPONENT ||
+ stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) &&
+ !stObj->base.GenerateMipmap &&
+ stImage->level == 0) {
+ /* only alloc space for a single mipmap level */
+ lastLevel = 0;
+ }
+ else {
+ /* alloc space for a full mipmap */
+ GLuint l2width = util_logbase2(width);
+ GLuint l2height = util_logbase2(height);
+ GLuint l2depth = util_logbase2(depth);
+ lastLevel = MAX2(MAX2(l2width, l2height), l2depth);
+ }
+
+ /* Save the level=0 dimensions */
+ stObj->width0 = width;
+ stObj->height0 = height;
+ stObj->depth0 = depth;
+
+ fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat);
+
+ bindings = default_bindings(st, fmt);
+
+ st_gl_texture_dims_to_pipe_dims(stObj->base.Target,
+ width, height, depth,
+ &ptWidth, &ptHeight, &ptDepth, &ptLayers);
+
+ stObj->pt = st_texture_create(st,
+ gl_target_to_pipe(stObj->base.Target),
+ fmt,
+ lastLevel,
+ ptWidth,
+ ptHeight,
+ ptDepth,
+ ptLayers,
+ bindings);
+
+ DBG("%s returning %d\n", __FUNCTION__, (stObj->pt != NULL));
+
+ return stObj->pt != NULL;
+}
+
+
+/**
+ * Adjust pixel unpack params and image dimensions to strip off the
+ * texture border.
+ * Gallium doesn't support texture borders. They've seldem been used
+ * and seldom been implemented correctly anyway.
+ * \param unpackNew returns the new pixel unpack parameters
+ */
+static void
+strip_texture_border(GLint border,
+ GLint *width, GLint *height, GLint *depth,
+ const struct gl_pixelstore_attrib *unpack,
+ struct gl_pixelstore_attrib *unpackNew)
+{
+ assert(border > 0); /* sanity check */
+
+ *unpackNew = *unpack;
+
+ if (unpackNew->RowLength == 0)
+ unpackNew->RowLength = *width;
+
+ if (depth && unpackNew->ImageHeight == 0)
+ unpackNew->ImageHeight = *height;
+
+ unpackNew->SkipPixels += border;
+ if (height)
+ unpackNew->SkipRows += border;
+ if (depth)
+ unpackNew->SkipImages += border;
+
+ assert(*width >= 3);
+ *width = *width - 2 * border;
+ if (height && *height >= 3)
+ *height = *height - 2 * border;
+ if (depth && *depth >= 3)
+ *depth = *depth - 2 * border;
+}
+
+
+/**
+ * Do glTexImage1/2/3D().
+ */
+static void
+st_TexImage(struct gl_context * ctx,
+ GLint dims,
+ GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint depth,
+ GLint border,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *unpack,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage,
+ GLsizei imageSize, GLboolean compressed_src)
+{
+ struct st_context *st = st_context(ctx);
+ struct st_texture_object *stObj = st_texture_object(texObj);
+ struct st_texture_image *stImage = st_texture_image(texImage);
+ GLuint dstRowStride = 0;
+ struct gl_pixelstore_attrib unpackNB;
+ enum pipe_transfer_usage transfer_usage = 0;
+
+ DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
+ _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
+
+ /* switch to "normal" */
+ if (stObj->surface_based) {
+ gl_format texFormat;
+
+ _mesa_clear_texture_object(ctx, texObj);
+ pipe_resource_reference(&stObj->pt, NULL);
+
+ /* oops, need to init this image again */
+ texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+ internalFormat, format, type);
+
+ _mesa_init_teximage_fields(ctx, target, texImage,
+ width, height, depth, border,
+ internalFormat, texFormat);
+
+ stObj->surface_based = GL_FALSE;
+ }
+
+ /* gallium does not support texture borders, strip it off */
+ if (border) {
+ strip_texture_border(border, &width, &height, &depth, unpack, &unpackNB);
+ unpack = &unpackNB;
+ texImage->Width = width;
+ texImage->Height = height;
+ texImage->Depth = depth;
+ texImage->Border = 0;
+ border = 0;
+ }
+ else {
+ assert(texImage->Width == width);
+ assert(texImage->Height == height);
+ assert(texImage->Depth == depth);
+ }
+
+ stImage->face = _mesa_tex_target_to_face(target);
+ stImage->level = level;
+
+ _mesa_set_fetch_functions(texImage, dims);
+
+ /* Release the reference to a potentially orphaned buffer.
+ * Release any old malloced memory.
+ */
+ if (stImage->pt) {
+ pipe_resource_reference(&stImage->pt, NULL);
+ assert(!texImage->Data);
+ }
+ else if (texImage->Data) {
+ _mesa_align_free(texImage->Data);
+ }
+
+ /*
+ * See if the new image is somehow incompatible with the existing
+ * mipmap. If so, free the old mipmap.
+ */
+ if (stObj->pt) {
+ if (level > (GLint) stObj->pt->last_level ||
+ !st_texture_match_image(stObj->pt, &stImage->base,
+ stImage->face, stImage->level)) {
+ DBG("release it\n");
+ pipe_resource_reference(&stObj->pt, NULL);
+ assert(!stObj->pt);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+ }
+ }
+
+ if (width == 0 || height == 0 || depth == 0) {
+ /* stop after freeing old image */
+ return;
+ }
+
+ if (!stObj->pt) {
+ if (!guess_and_alloc_texture(st, stObj, stImage)) {
+ /* Probably out of memory.
+ * Try flushing any pending rendering, then retry.
+ */
+ st_finish(st);
+ if (!guess_and_alloc_texture(st, stObj, stImage)) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
+ return;
+ }
+ }
+ }
+
+ assert(!stImage->pt);
+
+ /* Check if this texture image can live inside the texture object's buffer.
+ * If so, store the image there. Otherwise the image will temporarily live
+ * in its own buffer.
+ */
+ if (stObj->pt &&
+ st_texture_match_image(stObj->pt, &stImage->base,
+ stImage->face, stImage->level)) {
+
+ pipe_resource_reference(&stImage->pt, stObj->pt);
+ assert(stImage->pt);
+ }
+
+ if (!stImage->pt)
+ DBG("XXX: Image did not fit into texture - storing in local memory!\n");
+
+ /* Pixel data may come from regular user memory or a PBO. For the later,
+ * do bounds checking and map the PBO to read pixels data from it.
+ *
+ * XXX we should try to use a GPU-accelerated path to copy the image data
+ * from the PBO to the texture.
+ */
+ if (compressed_src) {
+ pixels = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, pixels,
+ unpack,
+ "glCompressedTexImage");
+ }
+ else {
+ pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1,
+ format, type,
+ pixels, unpack, "glTexImage");
+ }
+
+ /* for a 1D array upload the image as a series of layer with height = 1 */
+ if (target == GL_TEXTURE_1D_ARRAY) {
+ depth = height;
+ height = 1;
+ }
+
+ /*
+ * Prepare to store the texture data. Either map the gallium texture buffer
+ * memory or malloc space for it.
+ */
+ if (stImage->pt) {
+ /* Store the image in the gallium texture memory buffer */
+ if (format == GL_DEPTH_COMPONENT &&
+ util_format_is_depth_and_stencil(stImage->pt->format))
+ transfer_usage = PIPE_TRANSFER_READ_WRITE;
+ else
+ transfer_usage = PIPE_TRANSFER_WRITE;
+
+ texImage->Data = st_texture_image_map(st, stImage, 0,
+ transfer_usage, 0, 0, width, height);
+ if(stImage->transfer)
+ dstRowStride = stImage->transfer->stride;
+ }
+ else {
+ /* Allocate regular memory and store the image there temporarily. */
+ GLuint imageSize = _mesa_format_image_size(texImage->TexFormat,
+ width, height, depth);
+ dstRowStride = _mesa_format_row_stride(texImage->TexFormat, width);
+
+ texImage->Data = _mesa_align_malloc(imageSize, 16);
+ }
+
+ if (!texImage->Data) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
+ return;
+ }
+
+ if (!pixels) {
+ /* We've allocated texture memory, but have no pixel data - all done. */
+ goto done;
+ }
+
+ DBG("Upload image %dx%dx%d row_len %x pitch %x\n",
+ width, height, depth, width, dstRowStride);
+
+ /* Copy user texture image into the texture buffer.
+ */
+ if (compressed_src) {
+ const GLuint srcRowStride =
+ _mesa_format_row_stride(texImage->TexFormat, width);
+ if (dstRowStride == srcRowStride) {
+ memcpy(texImage->Data, pixels, imageSize);
+ }
+ else {
+ char *dst = texImage->Data;
+ const char *src = pixels;
+ GLuint i, bw, bh, lines;
+ _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
+ lines = (height + bh - 1) / bh;
+
+ for (i = 0; i < lines; ++i) {
+ memcpy(dst, src, srcRowStride);
+ dst += dstRowStride;
+ src += srcRowStride;
+ }
+ }
+ }
+ else {
+ const GLuint srcImageStride =
+ _mesa_image_image_stride(unpack, width, height, format, type);
+ GLint i;
+ const GLubyte *src = (const GLubyte *) pixels;
+
+ for (i = 0; i < depth; i++) {
+ if (!_mesa_texstore(ctx, dims,
+ texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ 0, 0, 0, /* dstX/Y/Zoffset */
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, 1,
+ format, type, src, unpack)) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
+ }
+
+ if (stImage->pt && i + 1 < depth) {
+ /* unmap this slice */
+ st_texture_image_unmap(st, stImage);
+ /* map next slice of 3D texture */
+ texImage->Data = st_texture_image_map(st, stImage, i + 1,
+ transfer_usage, 0, 0,
+ width, height);
+ src += srcImageStride;
+ }
+ }
+ }
+
+done:
+ _mesa_unmap_teximage_pbo(ctx, unpack);
+
+ if (stImage->pt && texImage->Data) {
+ st_texture_image_unmap(st, stImage);
+ texImage->Data = NULL;
+ }
+}
+
+
+static void
+st_TexImage3D(struct gl_context * ctx,
+ GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint depth,
+ GLint border,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *unpack,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ st_TexImage(ctx, 3, target, level, internalFormat, width, height, depth,
+ border, format, type, pixels, unpack, texObj, texImage,
+ 0, GL_FALSE);
+}
+
+
+static void
+st_TexImage2D(struct gl_context * ctx,
+ GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint border,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *unpack,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
+ format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
+}
+
+
+static void
+st_TexImage1D(struct gl_context * ctx,
+ GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint border,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *unpack,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ st_TexImage(ctx, 1, target, level, internalFormat, width, 1, 1, border,
+ format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
+}
+
+
+static void
+st_CompressedTexImage2D(struct gl_context *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint border,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
+ 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, GL_TRUE);
+}
+
+
+
+/**
+ * glGetTexImage() helper: decompress a compressed texture by rendering
+ * a textured quad. Store the results in the user's buffer.
+ */
+static void
+decompress_with_blit(struct gl_context * ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct st_texture_image *stImage = st_texture_image(texImage);
+ struct st_texture_object *stObj = st_texture_object(texObj);
+ struct pipe_sampler_view *src_view =
+ st_get_texture_sampler_view(stObj, pipe);
+ const GLuint width = texImage->Width;
+ const GLuint height = texImage->Height;
+ struct pipe_surface *dst_surface;
+ struct pipe_resource *dst_texture;
+ struct pipe_transfer *tex_xfer;
+ unsigned bind = (PIPE_BIND_RENDER_TARGET | /* util_blit may choose to render */
+ PIPE_BIND_TRANSFER_READ);
+
+ /* create temp / dest surface */
+ if (!util_create_rgba_surface(pipe, width, height, bind,
+ &dst_texture, &dst_surface)) {
+ _mesa_problem(ctx, "util_create_rgba_surface() failed "
+ "in decompress_with_blit()");
+ return;
+ }
+
+ /* blit/render/decompress */
+ util_blit_pixels_tex(st->blit,
+ src_view, /* pipe_resource (src) */
+ 0, 0, /* src x0, y0 */
+ width, height, /* src x1, y1 */
+ dst_surface, /* pipe_surface (dst) */
+ 0, 0, /* dst x0, y0 */
+ width, height, /* dst x1, y1 */
+ 0.0, /* z */
+ PIPE_TEX_MIPFILTER_NEAREST);
+
+ /* map the dst_surface so we can read from it */
+ tex_xfer = pipe_get_transfer(st_context(ctx)->pipe,
+ dst_texture, 0, 0,
+ PIPE_TRANSFER_READ,
+ 0, 0, width, height);
+
+ pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels);
+
+ /* copy/pack data into user buffer */
+ if (st_equal_formats(stImage->pt->format, format, type)) {
+ /* memcpy */
+ const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format);
+ ubyte *map = pipe_transfer_map(pipe, tex_xfer);
+ GLuint row;
+ for (row = 0; row < height; row++) {
+ GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
+ height, format, type, row, 0);
+ memcpy(dest, map, bytesPerRow);
+ map += tex_xfer->stride;
+ }
+ pipe_transfer_unmap(pipe, tex_xfer);
+ }
+ else {
+ /* format translation via floats */
+ GLuint row;
+ enum pipe_format format = util_format_linear(dst_texture->format);
+ for (row = 0; row < height; row++) {
+ const GLbitfield transferOps = 0x0; /* bypassed for glGetTexImage() */
+ GLfloat rgba[4 * MAX_WIDTH];
+ GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
+ height, format, type, row, 0);
+
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback format translation\n", __FUNCTION__);
+
+ /* get float[4] rgba row from surface */
+ pipe_get_tile_rgba_format(pipe, tex_xfer, 0, row, width, 1,
+ format, rgba);
+
+ _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
+ type, dest, &ctx->Pack, transferOps);
+ }
+ }
+
+ _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
+
+ pipe->transfer_destroy(pipe, tex_xfer);
+
+ /* destroy the temp / dest surface */
+ util_destroy_rgba_surface(dst_texture, dst_surface);
+}
+
+
+
+/**
+ * Need to map texture image into memory before copying image data,
+ * then unmap it.
+ */
+static void
+st_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid * pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage, GLboolean compressed_dst)
+{
+ struct st_context *st = st_context(ctx);
+ struct st_texture_image *stImage = st_texture_image(texImage);
+ const GLuint dstImageStride =
+ _mesa_image_image_stride(&ctx->Pack, texImage->Width, texImage->Height,
+ format, type);
+ GLuint depth, i;
+ GLubyte *dest;
+
+ if (stImage->pt &&
+ util_format_is_s3tc(stImage->pt->format) &&
+ !compressed_dst) {
+ /* Need to decompress the texture.
+ * We'll do this by rendering a textured quad.
+ * Note that we only expect RGBA formats (no Z/depth formats).
+ */
+ decompress_with_blit(ctx, target, level, format, type, pixels,
+ texObj, texImage);
+ return;
+ }
+
+ /* Map */
+ if (stImage->pt) {
+ /* Image is stored in hardware format in a buffer managed by the
+ * kernel. Need to explicitly map and unmap it.
+ */
+ texImage->Data = st_texture_image_map(st, stImage, 0,
+ PIPE_TRANSFER_READ, 0, 0,
+ stImage->base.Width,
+ stImage->base.Height);
+ /* compute stride in texels from stride in bytes */
+ texImage->RowStride = stImage->transfer->stride
+ * util_format_get_blockwidth(stImage->pt->format)
+ / util_format_get_blocksize(stImage->pt->format);
+ }
+ else {
+ /* Otherwise, the image should actually be stored in
+ * texImage->Data. This is pretty confusing for
+ * everybody, I'd much prefer to separate the two functions of
+ * texImage->Data - storage for texture images in main memory
+ * and access (ie mappings) of images. In other words, we'd
+ * create a new texImage->Map field and leave Data simply for
+ * storage.
+ */
+ assert(texImage->Data);
+ }
+
+ depth = texImage->Depth;
+ texImage->Depth = 1;
+
+ dest = (GLubyte *) pixels;
+
+ _mesa_set_fetch_functions(texImage, get_texture_dims(target));
+
+ for (i = 0; i < depth; i++) {
+ if (compressed_dst) {
+ _mesa_get_compressed_teximage(ctx, target, level, dest,
+ texObj, texImage);
+ }
+ else {
+ _mesa_get_teximage(ctx, target, level, format, type, dest,
+ texObj, texImage);
+ }
+
+ if (stImage->pt && i + 1 < depth) {
+ /* unmap this slice */
+ st_texture_image_unmap(st, stImage);
+ /* map next slice of 3D texture */
+ texImage->Data = st_texture_image_map(st, stImage, i + 1,
+ PIPE_TRANSFER_READ, 0, 0,
+ stImage->base.Width,
+ stImage->base.Height);
+ dest += dstImageStride;
+ }
+ }
+
+ texImage->Depth = depth;
+
+ /* Unmap */
+ if (stImage->pt) {
+ st_texture_image_unmap(st, stImage);
+ texImage->Data = NULL;
+ }
+}
+
+
+static void
+st_GetTexImage(struct gl_context * ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid * pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ st_get_tex_image(ctx, target, level, format, type, pixels, texObj, texImage,
+ GL_FALSE);
+}
+
+
+static void
+st_GetCompressedTexImage(struct gl_context *ctx, GLenum target, GLint level,
+ GLvoid *pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ st_get_tex_image(ctx, target, level, 0, 0, pixels, texObj, texImage,
+ GL_TRUE);
+}
+
+
+
+static void
+st_TexSubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint width, GLint height, GLint depth,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ struct st_context *st = st_context(ctx);
+ struct st_texture_image *stImage = st_texture_image(texImage);
+ GLuint dstRowStride;
+ const GLuint srcImageStride =
+ _mesa_image_image_stride(packing, width, height, format, type);
+ GLint i;
+ const GLubyte *src;
+ /* init to silence warning only: */
+ enum pipe_transfer_usage transfer_usage = PIPE_TRANSFER_WRITE;
+
+ DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__,
+ _mesa_lookup_enum_by_nr(target),
+ level, xoffset, yoffset, width, height);
+
+ pixels =
+ _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, format,
+ type, pixels, packing, "glTexSubImage2D");
+ if (!pixels)
+ return;
+
+ /* for a 1D array upload the image as a series of layer with height = 1 */
+ if (target == GL_TEXTURE_1D_ARRAY) {
+ depth = height;
+ height = 1;
+ }
+
+ /* Map buffer if necessary. Need to lock to prevent other contexts
+ * from uploading the buffer under us.
+ */
+ if (stImage->pt) {
+ if (format == GL_DEPTH_COMPONENT &&
+ util_format_is_depth_and_stencil(stImage->pt->format))
+ transfer_usage = PIPE_TRANSFER_READ_WRITE;
+ else
+ transfer_usage = PIPE_TRANSFER_WRITE;
+
+ texImage->Data = st_texture_image_map(st, stImage, zoffset,
+ transfer_usage,
+ xoffset, yoffset,
+ width, height);
+ }
+
+ if (!texImage->Data) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
+ goto done;
+ }
+
+ src = (const GLubyte *) pixels;
+ dstRowStride = stImage->transfer->stride;
+
+ for (i = 0; i < depth; i++) {
+ if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
+ texImage->TexFormat,
+ texImage->Data,
+ 0, 0, 0,
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, 1,
+ format, type, src, packing)) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
+ }
+
+ if (stImage->pt && i + 1 < depth) {
+ /* unmap this slice */
+ st_texture_image_unmap(st, stImage);
+ /* map next slice of 3D texture */
+ texImage->Data = st_texture_image_map(st, stImage,
+ zoffset + i + 1,
+ transfer_usage,
+ xoffset, yoffset,
+ width, height);
+ src += srcImageStride;
+ }
+ }
+
+done:
+ _mesa_unmap_teximage_pbo(ctx, packing);
+
+ if (stImage->pt && texImage->Data) {
+ st_texture_image_unmap(st, stImage);
+ texImage->Data = NULL;
+ }
+}
+
+
+
+static void
+st_TexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ st_TexSubimage(ctx, 3, target, level, xoffset, yoffset, zoffset,
+ width, height, depth, format, type,
+ pixels, packing, texObj, texImage);
+}
+
+
+static void
+st_TexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type, const GLvoid * pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ st_TexSubimage(ctx, 2, target, level, xoffset, yoffset, 0,
+ width, height, 1, format, type,
+ pixels, packing, texObj, texImage);
+}
+
+
+static void
+st_TexSubImage1D(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLsizei width, GLenum format, GLenum type,
+ const GLvoid * pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ st_TexSubimage(ctx, 1, target, level, xoffset, 0, 0, width, 1, 1,
+ format, type, pixels, packing, texObj, texImage);
+}
+
+
+static void
+st_CompressedTexSubImage1D(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLsizei width,
+ GLenum format,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ assert(0);
+}
+
+
+static void
+st_CompressedTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLsizei width, GLint height,
+ GLenum format,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ struct st_context *st = st_context(ctx);
+ struct st_texture_image *stImage = st_texture_image(texImage);
+ int srcBlockStride;
+ int dstBlockStride;
+ int y;
+ enum pipe_format pformat;
+
+ if (stImage->pt) {
+ pformat = stImage->pt->format;
+
+ texImage->Data = st_texture_image_map(st, stImage, 0,
+ PIPE_TRANSFER_WRITE,
+ xoffset, yoffset,
+ width, height);
+
+ srcBlockStride = util_format_get_stride(pformat, width);
+ dstBlockStride = stImage->transfer->stride;
+ } else {
+ assert(stImage->pt);
+ /* TODO find good values for block and strides */
+ /* TODO also adjust texImage->data for yoffset/xoffset */
+ return;
+ }
+
+ if (!texImage->Data) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage");
+ return;
+ }
+
+ assert(xoffset % util_format_get_blockwidth(pformat) == 0);
+ assert(yoffset % util_format_get_blockheight(pformat) == 0);
+
+ for (y = 0; y < height; y += util_format_get_blockheight(pformat)) {
+ /* don't need to adjust for xoffset and yoffset as st_texture_image_map does that */
+ const char *src = (const char*)data + srcBlockStride * util_format_get_nblocksy(pformat, y);
+ char *dst = (char*)texImage->Data + dstBlockStride * util_format_get_nblocksy(pformat, y);
+ memcpy(dst, src, util_format_get_stride(pformat, width));
+ }
+
+ if (stImage->pt) {
+ st_texture_image_unmap(st, stImage);
+ texImage->Data = NULL;
+ }
+}
+
+
+static void
+st_CompressedTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLint height, GLint depth,
+ GLenum format,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ assert(0);
+}
+
+
+
+/**
+ * Do a CopyTexSubImage operation using a read transfer from the source,
+ * a write transfer to the destination and get_tile()/put_tile() to access
+ * the pixels/texels.
+ *
+ * Note: srcY=0=TOP of renderbuffer
+ */
+static void
+fallback_copy_texsubimage(struct gl_context *ctx, GLenum target, GLint level,
+ struct st_renderbuffer *strb,
+ struct st_texture_image *stImage,
+ GLenum baseFormat,
+ GLint destX, GLint destY, GLint destZ,
+ GLint srcX, GLint srcY,
+ GLsizei width, GLsizei height)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_transfer *src_trans;
+ GLvoid *texDest;
+ enum pipe_transfer_usage transfer_usage;
+
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
+
+ assert(width <= MAX_WIDTH);
+
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ srcY = strb->Base.Height - srcY - height;
+ }
+
+ src_trans = pipe_get_transfer(st_context(ctx)->pipe,
+ strb->texture,
+ 0, 0,
+ PIPE_TRANSFER_READ,
+ srcX, srcY,
+ width, height);
+
+ if ((baseFormat == GL_DEPTH_COMPONENT ||
+ baseFormat == GL_DEPTH_STENCIL) &&
+ util_format_is_depth_and_stencil(stImage->pt->format))
+ transfer_usage = PIPE_TRANSFER_READ_WRITE;
+ else
+ transfer_usage = PIPE_TRANSFER_WRITE;
+
+ /* XXX this used to ignore destZ param */
+ texDest = st_texture_image_map(st, stImage, destZ, transfer_usage,
+ destX, destY, width, height);
+
+ if (baseFormat == GL_DEPTH_COMPONENT ||
+ baseFormat == GL_DEPTH_STENCIL) {
+ const GLboolean scaleOrBias = (ctx->Pixel.DepthScale != 1.0F ||
+ ctx->Pixel.DepthBias != 0.0F);
+ GLint row, yStep;
+
+ /* determine bottom-to-top vs. top-to-bottom order for src buffer */
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ srcY = height - 1;
+ yStep = -1;
+ }
+ else {
+ srcY = 0;
+ yStep = 1;
+ }
+
+ /* To avoid a large temp memory allocation, do copy row by row */
+ for (row = 0; row < height; row++, srcY += yStep) {
+ uint data[MAX_WIDTH];
+ pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data);
+ if (scaleOrBias) {
+ _mesa_scale_and_bias_depth_uint(ctx, width, data);
+ }
+ pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data);
+ }
+ }
+ else {
+ /* RGBA format */
+ GLfloat *tempSrc =
+ (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+
+ if (tempSrc && texDest) {
+ const GLint dims = 2;
+ const GLint dstRowStride = stImage->transfer->stride;
+ struct gl_texture_image *texImage = &stImage->base;
+ struct gl_pixelstore_attrib unpack = ctx->DefaultPacking;
+
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ unpack.Invert = GL_TRUE;
+ }
+
+ /* get float/RGBA image from framebuffer */
+ /* XXX this usually involves a lot of int/float conversion.
+ * try to avoid that someday.
+ */
+ pipe_get_tile_rgba_format(pipe, src_trans, 0, 0, width, height,
+ util_format_linear(strb->texture->format),
+ tempSrc);
+
+ /* Store into texture memory.
+ * Note that this does some special things such as pixel transfer
+ * ops and format conversion. In particular, if the dest tex format
+ * is actually RGBA but the user created the texture as GL_RGB we
+ * need to fill-in/override the alpha channel with 1.0.
+ */
+ _mesa_texstore(ctx, dims,
+ texImage->_BaseFormat,
+ texImage->TexFormat,
+ texDest,
+ 0, 0, 0,
+ dstRowStride,
+ texImage->ImageOffsets,
+ width, height, 1,
+ GL_RGBA, GL_FLOAT, tempSrc, /* src */
+ &unpack);
+ }
+ else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
+ }
+
+ if (tempSrc)
+ free(tempSrc);
+ }
+
+ st_texture_image_unmap(st, stImage);
+ pipe->transfer_destroy(pipe, src_trans);
+}
+
+
+
+/**
+ * If the format of the src renderbuffer and the format of the dest
+ * texture are compatible (in terms of blitting), return a TGSI writemask
+ * to be used during the blit.
+ * If the src/dest are incompatible, return 0.
+ */
+static unsigned
+compatible_src_dst_formats(struct gl_context *ctx,
+ const struct gl_renderbuffer *src,
+ const struct gl_texture_image *dst)
+{
+ /* Get logical base formats for the src and dest.
+ * That is, use the user-requested formats and not the actual, device-
+ * chosen formats.
+ * For example, the user may have requested an A8 texture but the
+ * driver may actually be using an RGBA texture format. When we
+ * copy/blit to that texture, we only want to copy the Alpha channel
+ * and not the RGB channels.
+ *
+ * Similarly, when the src FBO was created an RGB format may have been
+ * requested but the driver actually chose an RGBA format. In that case,
+ * we don't want to copy the undefined Alpha channel to the dest texture
+ * (it should be 1.0).
+ */
+ const GLenum srcFormat = _mesa_base_fbo_format(ctx, src->InternalFormat);
+ const GLenum dstFormat = _mesa_base_tex_format(ctx, dst->InternalFormat);
+
+ /**
+ * XXX when we have red-only and red/green renderbuffers we'll need
+ * to add more cases here (or implement a general-purpose routine that
+ * queries the existance of the R,G,B,A channels in the src and dest).
+ */
+ if (srcFormat == dstFormat) {
+ /* This is the same as matching_base_formats, which should
+ * always pass, as it did previously.
+ */
+ return TGSI_WRITEMASK_XYZW;
+ }
+ else if (srcFormat == GL_RGB && dstFormat == GL_RGBA) {
+ /* Make sure that A in the dest is 1. The actual src format
+ * may be RGBA and have undefined A values.
+ */
+ return TGSI_WRITEMASK_XYZ;
+ }
+ else if (srcFormat == GL_RGBA && dstFormat == GL_RGB) {
+ /* Make sure that A in the dest is 1. The actual dst format
+ * may be RGBA and will need A=1 to provide proper alpha values
+ * when sampled later.
+ */
+ return TGSI_WRITEMASK_XYZ;
+ }
+ else {
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s failed for src %s, dst %s\n",
+ __FUNCTION__,
+ _mesa_lookup_enum_by_nr(srcFormat),
+ _mesa_lookup_enum_by_nr(dstFormat));
+
+ /* Otherwise fail.
+ */
+ return 0;
+ }
+}
+
+
+
+/**
+ * Do a CopyTex[Sub]Image1/2/3D() using a hardware (blit) path if possible.
+ * Note that the region to copy has already been clipped so we know we
+ * won't read from outside the source renderbuffer's bounds.
+ *
+ * Note: srcY=0=Bottom of renderbuffer (GL convention)
+ */
+static void
+st_copy_texsubimage(struct gl_context *ctx,
+ GLenum target, GLint level,
+ GLint destX, GLint destY, GLint destZ,
+ GLint srcX, GLint srcY,
+ GLsizei width, GLsizei height)
+{
+ struct gl_texture_unit *texUnit =
+ &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ struct gl_texture_object *texObj =
+ _mesa_select_tex_object(ctx, texUnit, target);
+ struct gl_texture_image *texImage =
+ _mesa_select_tex_image(ctx, texObj, target, level);
+ struct st_texture_image *stImage = st_texture_image(texImage);
+ const GLenum texBaseFormat = texImage->_BaseFormat;
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct st_renderbuffer *strb;
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_screen *screen = pipe->screen;
+ enum pipe_format dest_format, src_format;
+ GLboolean use_fallback = GL_TRUE;
+ GLboolean matching_base_formats;
+ GLuint format_writemask, sample_count;
+ struct pipe_surface *dest_surface = NULL;
+ GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
+
+ /* make sure finalize_textures has been called?
+ */
+ if (0) st_validate_state(st);
+
+ /* determine if copying depth or color data */
+ if (texBaseFormat == GL_DEPTH_COMPONENT ||
+ texBaseFormat == GL_DEPTH_STENCIL) {
+ strb = st_renderbuffer(fb->_DepthBuffer);
+ if (strb->Base.Wrapped) {
+ strb = st_renderbuffer(strb->Base.Wrapped);
+ }
+ }
+ else {
+ /* texBaseFormat == GL_RGB, GL_RGBA, GL_ALPHA, etc */
+ strb = st_renderbuffer(fb->_ColorReadBuffer);
+ }
+
+ if (!strb || !strb->surface || !stImage->pt) {
+ debug_printf("%s: null strb or stImage\n", __FUNCTION__);
+ return;
+ }
+
+ sample_count = strb->surface->texture->nr_samples;
+ /* I believe this would be legal, presumably would need to do a resolve
+ for color, and for depth/stencil spec says to just use one of the
+ depth/stencil samples per pixel? Need some transfer clarifications. */
+ assert(sample_count < 2);
+
+ if (srcX < 0) {
+ width -= -srcX;
+ destX += -srcX;
+ srcX = 0;
+ }
+
+ if (srcY < 0) {
+ height -= -srcY;
+ destY += -srcY;
+ srcY = 0;
+ }
+
+ if (destX < 0) {
+ width -= -destX;
+ srcX += -destX;
+ destX = 0;
+ }
+
+ if (destY < 0) {
+ height -= -destY;
+ srcY += -destY;
+ destY = 0;
+ }
+
+ if (width < 0 || height < 0)
+ return;
+
+
+ assert(strb);
+ assert(strb->surface);
+ assert(stImage->pt);
+
+ src_format = strb->surface->format;
+ dest_format = stImage->pt->format;
+
+ /*
+ * Determine if the src framebuffer and dest texture have the same
+ * base format. We need this to detect a case such as the framebuffer
+ * being GL_RGBA but the texture being GL_RGB. If the actual hardware
+ * texture format stores RGBA we need to set A=1 (overriding the
+ * framebuffer's alpha values). We can't do that with the blit or
+ * textured-quad paths.
+ */
+ matching_base_formats =
+ (_mesa_get_format_base_format(strb->Base.Format) ==
+ _mesa_get_format_base_format(texImage->TexFormat));
+ format_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage);
+
+ if (ctx->_ImageTransferState == 0x0) {
+
+ if (matching_base_formats &&
+ src_format == dest_format &&
+ !do_flip)
+ {
+ /* use surface_copy() / blit */
+ struct pipe_box src_box;
+ u_box_2d_zslice(srcX, srcY, strb->surface->u.tex.first_layer,
+ width, height, &src_box);
+
+ /* for resource_copy_region(), y=0=top, always */
+ pipe->resource_copy_region(pipe,
+ /* dest */
+ stImage->pt,
+ stImage->level,
+ destX, destY, destZ + stImage->face,
+ /* src */
+ strb->texture,
+ strb->surface->u.tex.level,
+ &src_box);
+ use_fallback = GL_FALSE;
+ }
+ else if (format_writemask &&
+ texBaseFormat != GL_DEPTH_COMPONENT &&
+ texBaseFormat != GL_DEPTH_STENCIL &&
+ screen->is_format_supported(screen, src_format,
+ PIPE_TEXTURE_2D, sample_count,
+ PIPE_BIND_SAMPLER_VIEW,
+ 0) &&
+ screen->is_format_supported(screen, dest_format,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET,
+ 0)) {
+ /* draw textured quad to do the copy */
+ GLint srcY0, srcY1;
+ struct pipe_surface surf_tmpl;
+ memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+ surf_tmpl.format = stImage->pt->format;
+ surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
+ surf_tmpl.u.tex.level = stImage->level;
+ surf_tmpl.u.tex.first_layer = stImage->face + destZ;
+ surf_tmpl.u.tex.last_layer = stImage->face + destZ;
+
+ dest_surface = pipe->create_surface(pipe, stImage->pt,
+ &surf_tmpl);
+
+ if (do_flip) {
+ srcY1 = strb->Base.Height - srcY - height;
+ srcY0 = srcY1 + height;
+ }
+ else {
+ srcY0 = srcY;
+ srcY1 = srcY0 + height;
+ }
+
+ util_blit_pixels_writemask(st->blit,
+ strb->texture,
+ strb->surface->u.tex.level,
+ srcX, srcY0,
+ srcX + width, srcY1,
+ strb->surface->u.tex.first_layer,
+ dest_surface,
+ destX, destY,
+ destX + width, destY + height,
+ 0.0, PIPE_TEX_MIPFILTER_NEAREST,
+ format_writemask);
+ use_fallback = GL_FALSE;
+ }
+
+ if (dest_surface)
+ pipe_surface_reference(&dest_surface, NULL);
+ }
+
+ if (use_fallback) {
+ /* software fallback */
+ fallback_copy_texsubimage(ctx, target, level,
+ strb, stImage, texBaseFormat,
+ destX, destY, destZ,
+ srcX, srcY, width, height);
+ }
+}
+
+
+
+static void
+st_CopyTexImage1D(struct gl_context * ctx, GLenum target, GLint level,
+ GLenum internalFormat,
+ GLint x, GLint y, GLsizei width, GLint border)
+{
+ struct gl_texture_unit *texUnit =
+ &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ struct gl_texture_object *texObj =
+ _mesa_select_tex_object(ctx, texUnit, target);
+ struct gl_texture_image *texImage =
+ _mesa_select_tex_image(ctx, texObj, target, level);
+
+ /* Setup or redefine the texture object, texture and texture
+ * image. Don't populate yet.
+ */
+ ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
+ width, border,
+ GL_RGBA, CHAN_TYPE, NULL,
+ &ctx->DefaultPacking, texObj, texImage);
+
+ st_copy_texsubimage(ctx, target, level,
+ 0, 0, 0, /* destX,Y,Z */
+ x, y, width, 1); /* src X, Y, size */
+}
+
+
+static void
+st_CopyTexImage2D(struct gl_context * ctx, GLenum target, GLint level,
+ GLenum internalFormat,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ GLint border)
+{
+ struct gl_texture_unit *texUnit =
+ &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ struct gl_texture_object *texObj =
+ _mesa_select_tex_object(ctx, texUnit, target);
+ struct gl_texture_image *texImage =
+ _mesa_select_tex_image(ctx, texObj, target, level);
+
+ /* Setup or redefine the texture object, texture and texture
+ * image. Don't populate yet.
+ */
+ ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
+ width, height, border,
+ GL_RGBA, CHAN_TYPE, NULL,
+ &ctx->DefaultPacking, texObj, texImage);
+
+ st_copy_texsubimage(ctx, target, level,
+ 0, 0, 0, /* destX,Y,Z */
+ x, y, width, height); /* src X, Y, size */
+}
+
+
+static void
+st_CopyTexSubImage1D(struct gl_context * ctx, GLenum target, GLint level,
+ GLint xoffset, GLint x, GLint y, GLsizei width)
+{
+ const GLint yoffset = 0, zoffset = 0;
+ const GLsizei height = 1;
+ st_copy_texsubimage(ctx, target, level,
+ xoffset, yoffset, zoffset, /* destX,Y,Z */
+ x, y, width, height); /* src X, Y, size */
+}
+
+
+static void
+st_CopyTexSubImage2D(struct gl_context * ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height)
+{
+ const GLint zoffset = 0;
+ st_copy_texsubimage(ctx, target, level,
+ xoffset, yoffset, zoffset, /* destX,Y,Z */
+ x, y, width, height); /* src X, Y, size */
+}
+
+
+static void
+st_CopyTexSubImage3D(struct gl_context * ctx, GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height)
+{
+ st_copy_texsubimage(ctx, target, level,
+ xoffset, yoffset, zoffset, /* destX,Y,Z */
+ x, y, width, height); /* src X, Y, size */
+}
+
+
+/**
+ * Copy image data from stImage into the texture object 'stObj' at level
+ * 'dstLevel'.
+ */
+static void
+copy_image_data_to_texture(struct st_context *st,
+ struct st_texture_object *stObj,
+ GLuint dstLevel,
+ struct st_texture_image *stImage)
+{
+ /* debug checks */
+ {
+ const struct gl_texture_image *dstImage =
+ stObj->base.Image[stImage->face][stImage->level];
+ assert(dstImage);
+ assert(dstImage->Width == stImage->base.Width);
+ assert(dstImage->Height == stImage->base.Height);
+ assert(dstImage->Depth == stImage->base.Depth);
+ }
+
+ if (stImage->pt) {
+ /* Copy potentially with the blitter:
+ */
+ st_texture_image_copy(st->pipe,
+ stObj->pt, dstLevel, /* dest texture, level */
+ stImage->pt, stImage->level, /* src texture, level */
+ stImage->face);
+
+ pipe_resource_reference(&stImage->pt, NULL);
+ }
+ else if (stImage->base.Data) {
+ st_texture_image_data(st,
+ stObj->pt,
+ stImage->face,
+ dstLevel,
+ stImage->base.Data,
+ stImage->base.RowStride *
+ util_format_get_blocksize(stObj->pt->format),
+ stImage->base.RowStride *
+ stImage->base.Height *
+ util_format_get_blocksize(stObj->pt->format));
+ _mesa_align_free(stImage->base.Data);
+ stImage->base.Data = NULL;
+ }
+
+ pipe_resource_reference(&stImage->pt, stObj->pt);
+}
+
+
+/**
+ * Called during state validation. When this function is finished,
+ * the texture object should be ready for rendering.
+ * \return GL_TRUE for success, GL_FALSE for failure (out of mem)
+ */
+GLboolean
+st_finalize_texture(struct gl_context *ctx,
+ struct pipe_context *pipe,
+ struct gl_texture_object *tObj)
+{
+ struct st_context *st = st_context(ctx);
+ struct st_texture_object *stObj = st_texture_object(tObj);
+ const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+ GLuint face;
+ struct st_texture_image *firstImage;
+ enum pipe_format firstImageFormat;
+ GLuint ptWidth, ptHeight, ptDepth, ptLayers;
+
+ if (stObj->base._Complete) {
+ /* The texture is complete and we know exactly how many mipmap levels
+ * are present/needed. This is conditional because we may be called
+ * from the st_generate_mipmap() function when the texture object is
+ * incomplete. In that case, we'll have set stObj->lastLevel before
+ * we get here.
+ */
+ if (stObj->base.MinFilter == GL_LINEAR ||
+ stObj->base.MinFilter == GL_NEAREST)
+ stObj->lastLevel = stObj->base.BaseLevel;
+ else
+ stObj->lastLevel = stObj->base._MaxLevel;
+ }
+
+ firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
+ assert(firstImage);
+
+ /* If both firstImage and stObj point to a texture which can contain
+ * all active images, favour firstImage. Note that because of the
+ * completeness requirement, we know that the image dimensions
+ * will match.
+ */
+ if (firstImage->pt &&
+ firstImage->pt != stObj->pt &&
+ (!stObj->pt || firstImage->pt->last_level >= stObj->pt->last_level)) {
+ pipe_resource_reference(&stObj->pt, firstImage->pt);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+ }
+
+ /* Find gallium format for the Mesa texture */
+ firstImageFormat = st_mesa_format_to_pipe_format(firstImage->base.TexFormat);
+
+ /* Find size of level=0 Gallium mipmap image, plus number of texture layers */
+ {
+ GLuint width, height, depth;
+ if (!guess_base_level_size(stObj->base.Target,
+ firstImage->base.Width2,
+ firstImage->base.Height2,
+ firstImage->base.Depth2,
+ stObj->base.BaseLevel,
+ &width, &height, &depth)) {
+ width = stObj->width0;
+ height = stObj->height0;
+ depth = stObj->depth0;
+ }
+ /* convert GL dims to Gallium dims */
+ st_gl_texture_dims_to_pipe_dims(stObj->base.Target, width, height, depth,
+ &ptWidth, &ptHeight, &ptDepth, &ptLayers);
+ }
+
+ /* If we already have a gallium texture, check that it matches the texture
+ * object's format, target, size, num_levels, etc.
+ */
+ if (stObj->pt) {
+ if (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) ||
+ !st_sampler_compat_formats(stObj->pt->format, firstImageFormat) ||
+ stObj->pt->last_level < stObj->lastLevel ||
+ stObj->pt->width0 != ptWidth ||
+ stObj->pt->height0 != ptHeight ||
+ stObj->pt->depth0 != ptDepth ||
+ stObj->pt->array_size != ptLayers)
+ {
+ /* The gallium texture does not match the Mesa texture so delete the
+ * gallium texture now. We'll make a new one below.
+ */
+ pipe_resource_reference(&stObj->pt, NULL);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+ st->dirty.st |= ST_NEW_FRAMEBUFFER;
+ }
+ }
+
+ /* May need to create a new gallium texture:
+ */
+ if (!stObj->pt) {
+ GLuint bindings = default_bindings(st, firstImageFormat);
+
+ stObj->pt = st_texture_create(st,
+ gl_target_to_pipe(stObj->base.Target),
+ firstImageFormat,
+ stObj->lastLevel,
+ ptWidth,
+ ptHeight,
+ ptDepth,
+ ptLayers,
+ bindings);
+
+ if (!stObj->pt) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
+ return GL_FALSE;
+ }
+ }
+
+ /* Pull in any images not in the object's texture:
+ */
+ for (face = 0; face < nr_faces; face++) {
+ GLuint level;
+ for (level = stObj->base.BaseLevel; level <= stObj->lastLevel; level++) {
+ struct st_texture_image *stImage =
+ st_texture_image(stObj->base.Image[face][level]);
+
+ /* Need to import images in main memory or held in other textures.
+ */
+ if (stImage && stObj->pt != stImage->pt) {
+ copy_image_data_to_texture(st, stObj, level, stImage);
+ }
+ }
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Returns pointer to a default/dummy texture.
+ * This is typically used when the current shader has tex/sample instructions
+ * but the user has not provided a (any) texture(s).
+ */
+struct gl_texture_object *
+st_get_default_texture(struct st_context *st)
+{
+ if (!st->default_texture) {
+ static const GLenum target = GL_TEXTURE_2D;
+ GLubyte pixels[16][16][4];
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImg;
+ GLuint i, j;
+
+ /* The ARB_fragment_program spec says (0,0,0,1) should be returned
+ * when attempting to sample incomplete textures.
+ */
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j++) {
+ pixels[i][j][0] = 0;
+ pixels[i][j][1] = 0;
+ pixels[i][j][2] = 0;
+ pixels[i][j][3] = 255;
+ }
+ }
+
+ texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target);
+
+ texImg = _mesa_get_tex_image(st->ctx, texObj, target, 0);
+
+ _mesa_init_teximage_fields(st->ctx, target, texImg,
+ 16, 16, 1, 0, /* w, h, d, border */
+ GL_RGBA, MESA_FORMAT_RGBA8888);
+
+ st_TexImage(st->ctx, 2, target,
+ 0, GL_RGBA, /* level, intformat */
+ 16, 16, 1, 0, /* w, h, d, border */
+ GL_RGBA, GL_UNSIGNED_BYTE, pixels,
+ &st->ctx->DefaultPacking,
+ texObj, texImg,
+ 0, 0);
+
+ texObj->MinFilter = GL_NEAREST;
+ texObj->MagFilter = GL_NEAREST;
+ texObj->_Complete = GL_TRUE;
+
+ st->default_texture = texObj;
+ }
+ return st->default_texture;
+}
+
+
+void
+st_init_texture_functions(struct dd_function_table *functions)
+{
+ functions->ChooseTextureFormat = st_ChooseTextureFormat;
+ functions->TexImage1D = st_TexImage1D;
+ functions->TexImage2D = st_TexImage2D;
+ functions->TexImage3D = st_TexImage3D;
+ functions->TexSubImage1D = st_TexSubImage1D;
+ functions->TexSubImage2D = st_TexSubImage2D;
+ functions->TexSubImage3D = st_TexSubImage3D;
+ functions->CompressedTexSubImage1D = st_CompressedTexSubImage1D;
+ functions->CompressedTexSubImage2D = st_CompressedTexSubImage2D;
+ functions->CompressedTexSubImage3D = st_CompressedTexSubImage3D;
+ functions->CopyTexImage1D = st_CopyTexImage1D;
+ functions->CopyTexImage2D = st_CopyTexImage2D;
+ functions->CopyTexSubImage1D = st_CopyTexSubImage1D;
+ functions->CopyTexSubImage2D = st_CopyTexSubImage2D;
+ functions->CopyTexSubImage3D = st_CopyTexSubImage3D;
+ functions->GenerateMipmap = st_generate_mipmap;
+
+ functions->GetTexImage = st_GetTexImage;
+
+ /* compressed texture functions */
+ functions->CompressedTexImage2D = st_CompressedTexImage2D;
+ functions->GetCompressedTexImage = st_GetCompressedTexImage;
+
+ functions->NewTextureObject = st_NewTextureObject;
+ functions->NewTextureImage = st_NewTextureImage;
+ functions->DeleteTexture = st_DeleteTextureObject;
+ functions->FreeTexImageData = st_FreeTextureImageData;
+
+ functions->TextureMemCpy = do_memcpy;
+
+ /* XXX Temporary until we can query pipe's texture sizes */
+ functions->TestProxyTexImage = _mesa_test_proxy_teximage;
+}
diff --git a/mesalib/src/mesa/state_tracker/st_context.c b/mesalib/src/mesa/state_tracker/st_context.c
index 7a19f35bb..8f3a7415d 100644
--- a/mesalib/src/mesa/state_tracker/st_context.c
+++ b/mesalib/src/mesa/state_tracker/st_context.c
@@ -1,297 +1,297 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#include "main/imports.h"
-#include "main/context.h"
-#include "main/shaderobj.h"
-#include "program/prog_cache.h"
-#include "vbo/vbo.h"
-#include "glapi/glapi.h"
-#include "st_context.h"
-#include "st_debug.h"
-#include "st_cb_accum.h"
-#include "st_cb_bitmap.h"
-#include "st_cb_blit.h"
-#include "st_cb_bufferobjects.h"
-#include "st_cb_clear.h"
-#include "st_cb_condrender.h"
-#include "st_cb_drawpixels.h"
-#include "st_cb_rasterpos.h"
-#include "st_cb_drawtex.h"
-#include "st_cb_eglimage.h"
-#include "st_cb_fbo.h"
-#include "st_cb_feedback.h"
-#include "st_cb_program.h"
-#include "st_cb_queryobj.h"
-#include "st_cb_readpixels.h"
-#include "st_cb_texture.h"
-#include "st_cb_xformfb.h"
-#include "st_cb_flush.h"
-#include "st_cb_strings.h"
-#include "st_cb_viewport.h"
-#include "st_atom.h"
-#include "st_draw.h"
-#include "st_extensions.h"
-#include "st_gen_mipmap.h"
-#include "st_program.h"
-#include "pipe/p_context.h"
-#include "util/u_inlines.h"
-#include "cso_cache/cso_context.h"
-
-
-DEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4, "MESA_MVP_DP4", FALSE)
-
-
-/**
- * Called via ctx->Driver.UpdateState()
- */
-void st_invalidate_state(struct gl_context * ctx, GLuint new_state)
-{
- struct st_context *st = st_context(ctx);
-
- st->dirty.mesa |= new_state;
- st->dirty.st |= ST_NEW_MESA;
-
- /* This is the only core Mesa module we depend upon.
- * No longer use swrast, swsetup, tnl.
- */
- _vbo_InvalidateState(ctx, new_state);
-}
-
-
-/**
- * Check for multisample env var override.
- */
-int
-st_get_msaa(void)
-{
- const char *msaa = _mesa_getenv("__GL_FSAA_MODE");
- if (msaa)
- return atoi(msaa);
- return 0;
-}
-
-
-static struct st_context *
-st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe )
-{
- uint i;
- struct st_context *st = ST_CALLOC_STRUCT( st_context );
-
- ctx->st = st;
-
- st->ctx = ctx;
- st->pipe = pipe;
-
- /* XXX: this is one-off, per-screen init: */
- st_debug_init();
-
- /* state tracker needs the VBO module */
- _vbo_CreateContext(ctx);
-
- st->dirty.mesa = ~0;
- st->dirty.st = ~0;
-
- st->cso_context = cso_create_context(pipe);
-
- st_init_atoms( st );
- st_init_bitmap(st);
- st_init_clear(st);
- st_init_draw( st );
- st_init_generate_mipmap(st);
- st_init_blit(st);
-
- if(pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES))
- st->internal_target = PIPE_TEXTURE_2D;
- else
- st->internal_target = PIPE_TEXTURE_RECT;
-
- for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
- st->state.sampler_list[i] = &st->state.samplers[i];
-
- for (i = 0; i < 3; i++) {
- memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element));
- st->velems_util_draw[i].src_offset = i * 4 * sizeof(float);
- st->velems_util_draw[i].instance_divisor = 0;
- st->velems_util_draw[i].vertex_buffer_index = 0;
- st->velems_util_draw[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
- }
-
- /* we want all vertex data to be placed in buffer objects */
- vbo_use_buffer_objects(ctx);
-
- /* Need these flags:
- */
- st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
-
- st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
-
- st->pixel_xfer.cache = _mesa_new_program_cache();
-
- st->force_msaa = st_get_msaa();
-
- /* GL limits and extensions */
- st_init_limits(st);
- st_init_extensions(st);
-
- return st;
-}
-
-
-struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
- const struct gl_config *visual,
- struct st_context *share)
-{
- struct gl_context *ctx;
- struct gl_context *shareCtx = share ? share->ctx : NULL;
- struct dd_function_table funcs;
-
- /* Sanity checks */
- assert(MESA_SHADER_VERTEX == PIPE_SHADER_VERTEX);
- assert(MESA_SHADER_FRAGMENT == PIPE_SHADER_FRAGMENT);
- assert(MESA_SHADER_GEOMETRY == PIPE_SHADER_GEOMETRY);
-
- memset(&funcs, 0, sizeof(funcs));
- st_init_driver_functions(&funcs);
-
- ctx = _mesa_create_context(api, visual, shareCtx, &funcs, NULL);
-
- /* XXX: need a capability bit in gallium to query if the pipe
- * driver prefers DP4 or MUL/MAD for vertex transformation.
- */
- if (debug_get_option_mesa_mvp_dp4())
- _mesa_set_mvp_with_dp4( ctx, GL_TRUE );
-
- return st_create_context_priv(ctx, pipe);
-}
-
-
-static void st_destroy_context_priv( struct st_context *st )
-{
- uint i;
-
- st_destroy_atoms( st );
- st_destroy_draw( st );
- st_destroy_generate_mipmap(st);
- st_destroy_blit(st);
- st_destroy_clear(st);
- st_destroy_bitmap(st);
- st_destroy_drawpix(st);
- st_destroy_drawtex(st);
-
- /* Unreference any user vertex buffers. */
- for (i = 0; i < st->num_user_vbs; i++) {
- pipe_resource_reference(&st->user_vb[i], NULL);
- }
-
- for (i = 0; i < Elements(st->state.sampler_views); i++) {
- pipe_sampler_view_reference(&st->state.sampler_views[i], NULL);
- }
-
- if (st->default_texture) {
- st->ctx->Driver.DeleteTexture(st->ctx, st->default_texture);
- st->default_texture = NULL;
- }
-
- free( st );
-}
-
-
-void st_destroy_context( struct st_context *st )
-{
- struct pipe_context *pipe = st->pipe;
- struct cso_context *cso = st->cso_context;
- struct gl_context *ctx = st->ctx;
- GLuint i;
-
- /* need to unbind and destroy CSO objects before anything else */
- cso_release_all(st->cso_context);
-
- st_reference_fragprog(st, &st->fp, NULL);
- st_reference_vertprog(st, &st->vp, NULL);
-
- /* release framebuffer surfaces */
- for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
- pipe_surface_reference(&st->state.framebuffer.cbufs[i], NULL);
- }
- pipe_surface_reference(&st->state.framebuffer.zsbuf, NULL);
-
- pipe->set_index_buffer(pipe, NULL);
-
- for (i = 0; i < PIPE_SHADER_TYPES; i++) {
- pipe->set_constant_buffer(pipe, i, 0, NULL);
- }
-
- _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache);
-
- _vbo_DestroyContext(st->ctx);
-
- st_destroy_program_variants(st);
-
- _mesa_free_context_data(ctx);
-
- st_destroy_context_priv(st);
-
- cso_destroy_context(cso);
-
- pipe->destroy( pipe );
-
- free(ctx);
-}
-
-
-void st_init_driver_functions(struct dd_function_table *functions)
-{
- _mesa_init_shader_object_functions(functions);
-
- st_init_accum_functions(functions);
- st_init_blit_functions(functions);
- st_init_bufferobject_functions(functions);
- st_init_clear_functions(functions);
- st_init_bitmap_functions(functions);
- st_init_drawpixels_functions(functions);
- st_init_rasterpos_functions(functions);
-
- st_init_drawtex_functions(functions);
-
- st_init_eglimage_functions(functions);
-
- st_init_fbo_functions(functions);
- st_init_feedback_functions(functions);
- st_init_program_functions(functions);
- st_init_query_functions(functions);
- st_init_cond_render_functions(functions);
- st_init_readpixels_functions(functions);
- st_init_texture_functions(functions);
- st_init_flush_functions(functions);
- st_init_string_functions(functions);
- st_init_viewport_functions(functions);
-
- st_init_xformfb_functions(functions);
-
- functions->UpdateState = st_invalidate_state;
-}
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "main/imports.h"
+#include "main/context.h"
+#include "main/shaderobj.h"
+#include "program/prog_cache.h"
+#include "vbo/vbo.h"
+#include "glapi/glapi.h"
+#include "st_context.h"
+#include "st_debug.h"
+#include "st_cb_accum.h"
+#include "st_cb_bitmap.h"
+#include "st_cb_blit.h"
+#include "st_cb_bufferobjects.h"
+#include "st_cb_clear.h"
+#include "st_cb_condrender.h"
+#include "st_cb_drawpixels.h"
+#include "st_cb_rasterpos.h"
+#include "st_cb_drawtex.h"
+#include "st_cb_eglimage.h"
+#include "st_cb_fbo.h"
+#include "st_cb_feedback.h"
+#include "st_cb_program.h"
+#include "st_cb_queryobj.h"
+#include "st_cb_readpixels.h"
+#include "st_cb_texture.h"
+#include "st_cb_xformfb.h"
+#include "st_cb_flush.h"
+#include "st_cb_strings.h"
+#include "st_cb_viewport.h"
+#include "st_atom.h"
+#include "st_draw.h"
+#include "st_extensions.h"
+#include "st_gen_mipmap.h"
+#include "st_program.h"
+#include "pipe/p_context.h"
+#include "util/u_inlines.h"
+#include "cso_cache/cso_context.h"
+
+
+DEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4, "MESA_MVP_DP4", FALSE)
+
+
+/**
+ * Called via ctx->Driver.UpdateState()
+ */
+void st_invalidate_state(struct gl_context * ctx, GLuint new_state)
+{
+ struct st_context *st = st_context(ctx);
+
+ st->dirty.mesa |= new_state;
+ st->dirty.st |= ST_NEW_MESA;
+
+ /* This is the only core Mesa module we depend upon.
+ * No longer use swrast, swsetup, tnl.
+ */
+ _vbo_InvalidateState(ctx, new_state);
+}
+
+
+/**
+ * Check for multisample env var override.
+ */
+int
+st_get_msaa(void)
+{
+ const char *msaa = _mesa_getenv("__GL_FSAA_MODE");
+ if (msaa)
+ return atoi(msaa);
+ return 0;
+}
+
+
+static struct st_context *
+st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe )
+{
+ uint i;
+ struct st_context *st = ST_CALLOC_STRUCT( st_context );
+
+ ctx->st = st;
+
+ st->ctx = ctx;
+ st->pipe = pipe;
+
+ /* XXX: this is one-off, per-screen init: */
+ st_debug_init();
+
+ /* state tracker needs the VBO module */
+ _vbo_CreateContext(ctx);
+
+ st->dirty.mesa = ~0;
+ st->dirty.st = ~0;
+
+ st->cso_context = cso_create_context(pipe);
+
+ st_init_atoms( st );
+ st_init_bitmap(st);
+ st_init_clear(st);
+ st_init_draw( st );
+ st_init_generate_mipmap(st);
+ st_init_blit(st);
+
+ if(pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES))
+ st->internal_target = PIPE_TEXTURE_2D;
+ else
+ st->internal_target = PIPE_TEXTURE_RECT;
+
+ for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
+ st->state.sampler_list[i] = &st->state.samplers[i];
+
+ for (i = 0; i < 3; i++) {
+ memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element));
+ st->velems_util_draw[i].src_offset = i * 4 * sizeof(float);
+ st->velems_util_draw[i].instance_divisor = 0;
+ st->velems_util_draw[i].vertex_buffer_index = 0;
+ st->velems_util_draw[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+ }
+
+ /* we want all vertex data to be placed in buffer objects */
+ vbo_use_buffer_objects(ctx);
+
+ /* Need these flags:
+ */
+ st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
+
+ st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
+
+ st->pixel_xfer.cache = _mesa_new_program_cache();
+
+ st->force_msaa = st_get_msaa();
+
+ /* GL limits and extensions */
+ st_init_limits(st);
+ st_init_extensions(st);
+
+ return st;
+}
+
+
+struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
+ const struct gl_config *visual,
+ struct st_context *share)
+{
+ struct gl_context *ctx;
+ struct gl_context *shareCtx = share ? share->ctx : NULL;
+ struct dd_function_table funcs;
+
+ /* Sanity checks */
+ assert(MESA_SHADER_VERTEX == PIPE_SHADER_VERTEX);
+ assert(MESA_SHADER_FRAGMENT == PIPE_SHADER_FRAGMENT);
+ assert(MESA_SHADER_GEOMETRY == PIPE_SHADER_GEOMETRY);
+
+ memset(&funcs, 0, sizeof(funcs));
+ st_init_driver_functions(&funcs);
+
+ ctx = _mesa_create_context(api, visual, shareCtx, &funcs, NULL);
+
+ /* XXX: need a capability bit in gallium to query if the pipe
+ * driver prefers DP4 or MUL/MAD for vertex transformation.
+ */
+ if (debug_get_option_mesa_mvp_dp4())
+ _mesa_set_mvp_with_dp4( ctx, GL_TRUE );
+
+ return st_create_context_priv(ctx, pipe);
+}
+
+
+static void st_destroy_context_priv( struct st_context *st )
+{
+ uint i;
+
+ st_destroy_atoms( st );
+ st_destroy_draw( st );
+ st_destroy_generate_mipmap(st);
+ st_destroy_blit(st);
+ st_destroy_clear(st);
+ st_destroy_bitmap(st);
+ st_destroy_drawpix(st);
+ st_destroy_drawtex(st);
+
+ /* Unreference any user vertex buffers. */
+ for (i = 0; i < st->num_user_vbs; i++) {
+ pipe_resource_reference(&st->user_vb[i], NULL);
+ }
+
+ for (i = 0; i < Elements(st->state.sampler_views); i++) {
+ pipe_sampler_view_reference(&st->state.sampler_views[i], NULL);
+ }
+
+ if (st->default_texture) {
+ st->ctx->Driver.DeleteTexture(st->ctx, st->default_texture);
+ st->default_texture = NULL;
+ }
+
+ free( st );
+}
+
+
+void st_destroy_context( struct st_context *st )
+{
+ struct pipe_context *pipe = st->pipe;
+ struct cso_context *cso = st->cso_context;
+ struct gl_context *ctx = st->ctx;
+ GLuint i;
+
+ /* need to unbind and destroy CSO objects before anything else */
+ cso_release_all(st->cso_context);
+
+ st_reference_fragprog(st, &st->fp, NULL);
+ st_reference_vertprog(st, &st->vp, NULL);
+
+ /* release framebuffer surfaces */
+ for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
+ pipe_surface_reference(&st->state.framebuffer.cbufs[i], NULL);
+ }
+ pipe_surface_reference(&st->state.framebuffer.zsbuf, NULL);
+
+ pipe->set_index_buffer(pipe, NULL);
+
+ for (i = 0; i < PIPE_SHADER_TYPES; i++) {
+ pipe->set_constant_buffer(pipe, i, 0, NULL);
+ }
+
+ _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache);
+
+ _vbo_DestroyContext(st->ctx);
+
+ st_destroy_program_variants(st);
+
+ _mesa_free_context_data(ctx);
+
+ st_destroy_context_priv(st);
+
+ cso_destroy_context(cso);
+
+ pipe->destroy( pipe );
+
+ free(ctx);
+}
+
+
+void st_init_driver_functions(struct dd_function_table *functions)
+{
+ _mesa_init_shader_object_functions(functions);
+
+ st_init_accum_functions(functions);
+ st_init_blit_functions(functions);
+ st_init_bufferobject_functions(functions);
+ st_init_clear_functions(functions);
+ st_init_bitmap_functions(functions);
+ st_init_drawpixels_functions(functions);
+ st_init_rasterpos_functions(functions);
+
+ st_init_drawtex_functions(functions);
+
+ st_init_eglimage_functions(functions);
+
+ st_init_fbo_functions(functions);
+ st_init_feedback_functions(functions);
+ st_init_program_functions(functions);
+ st_init_query_functions(functions);
+ st_init_cond_render_functions(functions);
+ st_init_readpixels_functions(functions);
+ st_init_texture_functions(functions);
+ st_init_flush_functions(functions);
+ st_init_string_functions(functions);
+ st_init_viewport_functions(functions);
+
+ st_init_xformfb_functions(functions);
+
+ functions->UpdateState = st_invalidate_state;
+}
diff --git a/mesalib/src/mesa/state_tracker/st_context.h b/mesalib/src/mesa/state_tracker/st_context.h
index 77765f023..ef54fd7cd 100644
--- a/mesalib/src/mesa/state_tracker/st_context.h
+++ b/mesalib/src/mesa/state_tracker/st_context.h
@@ -1,270 +1,270 @@
-/**************************************************************************
- *
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#ifndef ST_CONTEXT_H
-#define ST_CONTEXT_H
-
-#include "main/mtypes.h"
-#include "pipe/p_state.h"
-#include "state_tracker/st_api.h"
-
-struct bitmap_cache;
-struct blit_state;
-struct dd_function_table;
-struct draw_context;
-struct draw_stage;
-struct gen_mipmap_state;
-struct st_context;
-struct st_fragment_program;
-
-
-#define ST_NEW_MESA 0x1 /* Mesa state has changed */
-#define ST_NEW_FRAGMENT_PROGRAM 0x2
-#define ST_NEW_VERTEX_PROGRAM 0x4
-#define ST_NEW_FRAMEBUFFER 0x8
-#define ST_NEW_EDGEFLAGS_DATA 0x10
-#define ST_NEW_GEOMETRY_PROGRAM 0x20
-
-
-struct st_state_flags {
- GLuint mesa;
- GLuint st;
-};
-
-struct st_tracked_state {
- const char *name;
- struct st_state_flags dirty;
- void (*update)( struct st_context *st );
-};
-
-
-
-struct st_context
-{
- struct st_context_iface iface;
-
- struct gl_context *ctx;
-
- struct pipe_context *pipe;
-
- struct draw_context *draw; /**< For selection/feedback/rastpos only */
- struct draw_stage *feedback_stage; /**< For GL_FEEDBACK rendermode */
- struct draw_stage *selection_stage; /**< For GL_SELECT rendermode */
- struct draw_stage *rastpos_stage; /**< For glRasterPos */
-
-
- /* On old libGL's for linux we need to invalidate the drawables
- * on glViewpport calls, this is set via a option.
- */
- boolean invalidate_on_gl_viewport;
-
- /* Some state is contained in constant objects.
- * Other state is just parameter values.
- */
- struct {
- struct pipe_blend_state blend;
- struct pipe_depth_stencil_alpha_state depth_stencil;
- struct pipe_rasterizer_state rasterizer;
- struct pipe_sampler_state samplers[PIPE_MAX_SAMPLERS];
- struct pipe_sampler_state *sampler_list[PIPE_MAX_SAMPLERS];
- struct pipe_clip_state clip;
- struct {
- void *ptr;
- unsigned size;
- } constants[PIPE_SHADER_TYPES];
- struct pipe_framebuffer_state framebuffer;
- struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
- struct pipe_scissor_state scissor;
- struct pipe_viewport_state viewport;
- unsigned sample_mask;
-
- GLuint num_samplers;
- GLuint num_textures;
-
- GLuint poly_stipple[32]; /**< In OpenGL's bottom-to-top order */
- } state;
-
- char vendor[100];
- char renderer[100];
-
- struct st_state_flags dirty;
-
- GLboolean missing_textures;
- GLboolean vertdata_edgeflags;
-
- /** Mapping from VERT_RESULT_x to post-transformed vertex slot */
- const GLuint *vertex_result_to_slot;
-
- struct st_vertex_program *vp; /**< Currently bound vertex program */
- struct st_fragment_program *fp; /**< Currently bound fragment program */
- struct st_geometry_program *gp; /**< Currently bound geometry program */
-
- struct st_vp_variant *vp_variant;
- struct st_fp_variant *fp_variant;
- struct st_gp_variant *gp_variant;
-
- struct gl_texture_object *default_texture;
-
- struct {
- struct gl_program_cache *cache;
- struct st_fragment_program *program; /**< cur pixel transfer prog */
- GLuint xfer_prog_sn; /**< pixel xfer program serial no. */
- GLuint user_prog_sn; /**< user fragment program serial no. */
- struct st_fragment_program *combined_prog;
- GLuint combined_prog_sn;
- struct pipe_resource *pixelmap_texture;
- struct pipe_sampler_view *pixelmap_sampler_view;
- boolean pixelmap_enabled; /**< use the pixelmap texture? */
- } pixel_xfer;
-
- /** for glBitmap */
- struct {
- struct pipe_rasterizer_state rasterizer;
- struct pipe_sampler_state samplers[2];
- enum pipe_format tex_format;
- void *vs;
- float vertices[4][3][4]; /**< vertex pos + color + texcoord */
- struct pipe_resource *vbuf;
- unsigned vbuf_slot; /* next free slot in vbuf */
- struct bitmap_cache *cache;
- } bitmap;
-
- /** for glDraw/CopyPixels */
- struct {
- struct gl_fragment_program *shaders[4];
- void *vert_shaders[2]; /**< ureg shaders */
- } drawpix;
-
- /** for glClear */
- struct {
- struct pipe_rasterizer_state raster;
- struct pipe_viewport_state viewport;
- struct pipe_clip_state clip;
- void *vs;
- void *fs;
- float vertices[4][2][4]; /**< vertex pos + color */
- struct pipe_resource *vbuf;
- unsigned vbuf_slot;
- boolean enable_ds_separate;
- } clear;
-
- /** used for anything using util_draw_vertex_buffer */
- struct pipe_vertex_element velems_util_draw[3];
-
- void *passthrough_fs; /**< simple pass-through frag shader */
-
- enum pipe_texture_target internal_target;
- struct gen_mipmap_state *gen_mipmap;
- struct blit_state *blit;
-
- struct cso_context *cso_context;
-
- int force_msaa;
- void *winsys_drawable_handle;
-
- /* User vertex buffers. */
- struct pipe_resource *user_vb[PIPE_MAX_ATTRIBS];
- unsigned user_vb_stride[PIPE_MAX_ATTRIBS];
- unsigned num_user_vbs;
-};
-
-
-/* Need this so that we can implement Mesa callbacks in this module.
- */
-static INLINE struct st_context *st_context(struct gl_context *ctx)
-{
- return ctx->st;
-}
-
-
-/**
- * Wrapper for struct gl_framebuffer.
- * This is an opaque type to the outside world.
- */
-struct st_framebuffer
-{
- struct gl_framebuffer Base;
- void *Private;
-
- struct st_framebuffer_iface *iface;
- enum st_attachment_type statts[ST_ATTACHMENT_COUNT];
- unsigned num_statts;
- int32_t revalidate;
-};
-
-
-extern void st_init_driver_functions(struct dd_function_table *functions);
-
-void st_invalidate_state(struct gl_context * ctx, GLuint new_state);
-
-
-
-#define Y_0_TOP 1
-#define Y_0_BOTTOM 2
-
-static INLINE GLuint
-st_fb_orientation(const struct gl_framebuffer *fb)
-{
- if (fb && fb->Name == 0) {
- /* Drawing into a window (on-screen buffer).
- *
- * Negate Y scale to flip image vertically.
- * The NDC Y coords prior to viewport transformation are in the range
- * [y=-1=bottom, y=1=top]
- * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
- * H is the window height.
- * Use the viewport transformation to invert Y.
- */
- return Y_0_TOP;
- }
- else {
- /* Drawing into user-created FBO (very likely a texture).
- *
- * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
- */
- return Y_0_BOTTOM;
- }
-}
-
-
-/** clear-alloc a struct-sized object, with casting */
-#define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
-
-
-extern int
-st_get_msaa(void);
-
-extern struct st_context *
-st_create_context(gl_api api, struct pipe_context *pipe,
- const struct gl_config *visual,
- struct st_context *share);
-
-extern void
-st_destroy_context(struct st_context *st);
-
-
-#endif
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef ST_CONTEXT_H
+#define ST_CONTEXT_H
+
+#include "main/mtypes.h"
+#include "pipe/p_state.h"
+#include "state_tracker/st_api.h"
+
+struct bitmap_cache;
+struct blit_state;
+struct dd_function_table;
+struct draw_context;
+struct draw_stage;
+struct gen_mipmap_state;
+struct st_context;
+struct st_fragment_program;
+
+
+#define ST_NEW_MESA 0x1 /* Mesa state has changed */
+#define ST_NEW_FRAGMENT_PROGRAM 0x2
+#define ST_NEW_VERTEX_PROGRAM 0x4
+#define ST_NEW_FRAMEBUFFER 0x8
+#define ST_NEW_EDGEFLAGS_DATA 0x10
+#define ST_NEW_GEOMETRY_PROGRAM 0x20
+
+
+struct st_state_flags {
+ GLuint mesa;
+ GLuint st;
+};
+
+struct st_tracked_state {
+ const char *name;
+ struct st_state_flags dirty;
+ void (*update)( struct st_context *st );
+};
+
+
+
+struct st_context
+{
+ struct st_context_iface iface;
+
+ struct gl_context *ctx;
+
+ struct pipe_context *pipe;
+
+ struct draw_context *draw; /**< For selection/feedback/rastpos only */
+ struct draw_stage *feedback_stage; /**< For GL_FEEDBACK rendermode */
+ struct draw_stage *selection_stage; /**< For GL_SELECT rendermode */
+ struct draw_stage *rastpos_stage; /**< For glRasterPos */
+
+
+ /* On old libGL's for linux we need to invalidate the drawables
+ * on glViewpport calls, this is set via a option.
+ */
+ boolean invalidate_on_gl_viewport;
+
+ /* Some state is contained in constant objects.
+ * Other state is just parameter values.
+ */
+ struct {
+ struct pipe_blend_state blend;
+ struct pipe_depth_stencil_alpha_state depth_stencil;
+ struct pipe_rasterizer_state rasterizer;
+ struct pipe_sampler_state samplers[PIPE_MAX_SAMPLERS];
+ struct pipe_sampler_state *sampler_list[PIPE_MAX_SAMPLERS];
+ struct pipe_clip_state clip;
+ struct {
+ void *ptr;
+ unsigned size;
+ } constants[PIPE_SHADER_TYPES];
+ struct pipe_framebuffer_state framebuffer;
+ struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
+ struct pipe_scissor_state scissor;
+ struct pipe_viewport_state viewport;
+ unsigned sample_mask;
+
+ GLuint num_samplers;
+ GLuint num_textures;
+
+ GLuint poly_stipple[32]; /**< In OpenGL's bottom-to-top order */
+ } state;
+
+ char vendor[100];
+ char renderer[100];
+
+ struct st_state_flags dirty;
+
+ GLboolean missing_textures;
+ GLboolean vertdata_edgeflags;
+
+ /** Mapping from VERT_RESULT_x to post-transformed vertex slot */
+ const GLuint *vertex_result_to_slot;
+
+ struct st_vertex_program *vp; /**< Currently bound vertex program */
+ struct st_fragment_program *fp; /**< Currently bound fragment program */
+ struct st_geometry_program *gp; /**< Currently bound geometry program */
+
+ struct st_vp_variant *vp_variant;
+ struct st_fp_variant *fp_variant;
+ struct st_gp_variant *gp_variant;
+
+ struct gl_texture_object *default_texture;
+
+ struct {
+ struct gl_program_cache *cache;
+ struct st_fragment_program *program; /**< cur pixel transfer prog */
+ GLuint xfer_prog_sn; /**< pixel xfer program serial no. */
+ GLuint user_prog_sn; /**< user fragment program serial no. */
+ struct st_fragment_program *combined_prog;
+ GLuint combined_prog_sn;
+ struct pipe_resource *pixelmap_texture;
+ struct pipe_sampler_view *pixelmap_sampler_view;
+ boolean pixelmap_enabled; /**< use the pixelmap texture? */
+ } pixel_xfer;
+
+ /** for glBitmap */
+ struct {
+ struct pipe_rasterizer_state rasterizer;
+ struct pipe_sampler_state samplers[2];
+ enum pipe_format tex_format;
+ void *vs;
+ float vertices[4][3][4]; /**< vertex pos + color + texcoord */
+ struct pipe_resource *vbuf;
+ unsigned vbuf_slot; /* next free slot in vbuf */
+ struct bitmap_cache *cache;
+ } bitmap;
+
+ /** for glDraw/CopyPixels */
+ struct {
+ struct gl_fragment_program *shaders[4];
+ void *vert_shaders[2]; /**< ureg shaders */
+ } drawpix;
+
+ /** for glClear */
+ struct {
+ struct pipe_rasterizer_state raster;
+ struct pipe_viewport_state viewport;
+ struct pipe_clip_state clip;
+ void *vs;
+ void *fs;
+ float vertices[4][2][4]; /**< vertex pos + color */
+ struct pipe_resource *vbuf;
+ unsigned vbuf_slot;
+ boolean enable_ds_separate;
+ } clear;
+
+ /** used for anything using util_draw_vertex_buffer */
+ struct pipe_vertex_element velems_util_draw[3];
+
+ void *passthrough_fs; /**< simple pass-through frag shader */
+
+ enum pipe_texture_target internal_target;
+ struct gen_mipmap_state *gen_mipmap;
+ struct blit_state *blit;
+
+ struct cso_context *cso_context;
+
+ int force_msaa;
+ void *winsys_drawable_handle;
+
+ /* User vertex buffers. */
+ struct pipe_resource *user_vb[PIPE_MAX_ATTRIBS];
+ unsigned user_vb_stride[PIPE_MAX_ATTRIBS];
+ unsigned num_user_vbs;
+};
+
+
+/* Need this so that we can implement Mesa callbacks in this module.
+ */
+static INLINE struct st_context *st_context(struct gl_context *ctx)
+{
+ return ctx->st;
+}
+
+
+/**
+ * Wrapper for struct gl_framebuffer.
+ * This is an opaque type to the outside world.
+ */
+struct st_framebuffer
+{
+ struct gl_framebuffer Base;
+ void *Private;
+
+ struct st_framebuffer_iface *iface;
+ enum st_attachment_type statts[ST_ATTACHMENT_COUNT];
+ unsigned num_statts;
+ int32_t revalidate;
+};
+
+
+extern void st_init_driver_functions(struct dd_function_table *functions);
+
+void st_invalidate_state(struct gl_context * ctx, GLuint new_state);
+
+
+
+#define Y_0_TOP 1
+#define Y_0_BOTTOM 2
+
+static INLINE GLuint
+st_fb_orientation(const struct gl_framebuffer *fb)
+{
+ if (fb && fb->Name == 0) {
+ /* Drawing into a window (on-screen buffer).
+ *
+ * Negate Y scale to flip image vertically.
+ * The NDC Y coords prior to viewport transformation are in the range
+ * [y=-1=bottom, y=1=top]
+ * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
+ * H is the window height.
+ * Use the viewport transformation to invert Y.
+ */
+ return Y_0_TOP;
+ }
+ else {
+ /* Drawing into user-created FBO (very likely a texture).
+ *
+ * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
+ */
+ return Y_0_BOTTOM;
+ }
+}
+
+
+/** clear-alloc a struct-sized object, with casting */
+#define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
+
+
+extern int
+st_get_msaa(void);
+
+extern struct st_context *
+st_create_context(gl_api api, struct pipe_context *pipe,
+ const struct gl_config *visual,
+ struct st_context *share);
+
+extern void
+st_destroy_context(struct st_context *st);
+
+
+#endif
diff --git a/mesalib/src/mesa/state_tracker/st_draw.c b/mesalib/src/mesa/state_tracker/st_draw.c
index d6e67b7fb..12142b84e 100644
--- a/mesalib/src/mesa/state_tracker/st_draw.c
+++ b/mesalib/src/mesa/state_tracker/st_draw.c
@@ -1,775 +1,775 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-/*
- * This file implements the st_draw_vbo() function which is called from
- * Mesa's VBO module. All point/line/triangle rendering is done through
- * this function whether the user called glBegin/End, glDrawArrays,
- * glDrawElements, glEvalMesh, or glCalList, etc.
- *
- * We basically convert the VBO's vertex attribute/array information into
- * Gallium vertex state, bind the vertex buffer objects and call
- * pipe->draw_elements(), pipe->draw_range_elements() or pipe->draw_arrays().
- *
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- */
-
-
-#include "main/imports.h"
-#include "main/image.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-#include "program/prog_uniform.h"
-
-#include "vbo/vbo.h"
-
-#include "st_context.h"
-#include "st_atom.h"
-#include "st_cb_bufferobjects.h"
-#include "st_draw.h"
-#include "st_program.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-#include "util/u_format.h"
-#include "util/u_prim.h"
-#include "util/u_draw_quad.h"
-#include "draw/draw_context.h"
-#include "cso_cache/cso_context.h"
-
-
-static GLuint double_types[4] = {
- PIPE_FORMAT_R64_FLOAT,
- PIPE_FORMAT_R64G64_FLOAT,
- PIPE_FORMAT_R64G64B64_FLOAT,
- PIPE_FORMAT_R64G64B64A64_FLOAT
-};
-
-static GLuint float_types[4] = {
- PIPE_FORMAT_R32_FLOAT,
- PIPE_FORMAT_R32G32_FLOAT,
- PIPE_FORMAT_R32G32B32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT
-};
-
-static GLuint half_float_types[4] = {
- PIPE_FORMAT_R16_FLOAT,
- PIPE_FORMAT_R16G16_FLOAT,
- PIPE_FORMAT_R16G16B16_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT
-};
-
-static GLuint uint_types_norm[4] = {
- PIPE_FORMAT_R32_UNORM,
- PIPE_FORMAT_R32G32_UNORM,
- PIPE_FORMAT_R32G32B32_UNORM,
- PIPE_FORMAT_R32G32B32A32_UNORM
-};
-
-static GLuint uint_types_scale[4] = {
- PIPE_FORMAT_R32_USCALED,
- PIPE_FORMAT_R32G32_USCALED,
- PIPE_FORMAT_R32G32B32_USCALED,
- PIPE_FORMAT_R32G32B32A32_USCALED
-};
-
-static GLuint int_types_norm[4] = {
- PIPE_FORMAT_R32_SNORM,
- PIPE_FORMAT_R32G32_SNORM,
- PIPE_FORMAT_R32G32B32_SNORM,
- PIPE_FORMAT_R32G32B32A32_SNORM
-};
-
-static GLuint int_types_scale[4] = {
- PIPE_FORMAT_R32_SSCALED,
- PIPE_FORMAT_R32G32_SSCALED,
- PIPE_FORMAT_R32G32B32_SSCALED,
- PIPE_FORMAT_R32G32B32A32_SSCALED
-};
-
-static GLuint ushort_types_norm[4] = {
- PIPE_FORMAT_R16_UNORM,
- PIPE_FORMAT_R16G16_UNORM,
- PIPE_FORMAT_R16G16B16_UNORM,
- PIPE_FORMAT_R16G16B16A16_UNORM
-};
-
-static GLuint ushort_types_scale[4] = {
- PIPE_FORMAT_R16_USCALED,
- PIPE_FORMAT_R16G16_USCALED,
- PIPE_FORMAT_R16G16B16_USCALED,
- PIPE_FORMAT_R16G16B16A16_USCALED
-};
-
-static GLuint short_types_norm[4] = {
- PIPE_FORMAT_R16_SNORM,
- PIPE_FORMAT_R16G16_SNORM,
- PIPE_FORMAT_R16G16B16_SNORM,
- PIPE_FORMAT_R16G16B16A16_SNORM
-};
-
-static GLuint short_types_scale[4] = {
- PIPE_FORMAT_R16_SSCALED,
- PIPE_FORMAT_R16G16_SSCALED,
- PIPE_FORMAT_R16G16B16_SSCALED,
- PIPE_FORMAT_R16G16B16A16_SSCALED
-};
-
-static GLuint ubyte_types_norm[4] = {
- PIPE_FORMAT_R8_UNORM,
- PIPE_FORMAT_R8G8_UNORM,
- PIPE_FORMAT_R8G8B8_UNORM,
- PIPE_FORMAT_R8G8B8A8_UNORM
-};
-
-static GLuint ubyte_types_scale[4] = {
- PIPE_FORMAT_R8_USCALED,
- PIPE_FORMAT_R8G8_USCALED,
- PIPE_FORMAT_R8G8B8_USCALED,
- PIPE_FORMAT_R8G8B8A8_USCALED
-};
-
-static GLuint byte_types_norm[4] = {
- PIPE_FORMAT_R8_SNORM,
- PIPE_FORMAT_R8G8_SNORM,
- PIPE_FORMAT_R8G8B8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM
-};
-
-static GLuint byte_types_scale[4] = {
- PIPE_FORMAT_R8_SSCALED,
- PIPE_FORMAT_R8G8_SSCALED,
- PIPE_FORMAT_R8G8B8_SSCALED,
- PIPE_FORMAT_R8G8B8A8_SSCALED
-};
-
-static GLuint fixed_types[4] = {
- PIPE_FORMAT_R32_FIXED,
- PIPE_FORMAT_R32G32_FIXED,
- PIPE_FORMAT_R32G32B32_FIXED,
- PIPE_FORMAT_R32G32B32A32_FIXED
-};
-
-
-
-/**
- * Return a PIPE_FORMAT_x for the given GL datatype and size.
- */
-GLuint
-st_pipe_vertex_format(GLenum type, GLuint size, GLenum format,
- GLboolean normalized)
-{
- assert((type >= GL_BYTE && type <= GL_DOUBLE) ||
- type == GL_FIXED || type == GL_HALF_FLOAT);
- assert(size >= 1);
- assert(size <= 4);
- assert(format == GL_RGBA || format == GL_BGRA);
-
- if (format == GL_BGRA) {
- /* this is an odd-ball case */
- assert(type == GL_UNSIGNED_BYTE);
- assert(normalized);
- return PIPE_FORMAT_B8G8R8A8_UNORM;
- }
-
- if (normalized) {
- switch (type) {
- case GL_DOUBLE: return double_types[size-1];
- case GL_FLOAT: return float_types[size-1];
- case GL_HALF_FLOAT: return half_float_types[size-1];
- case GL_INT: return int_types_norm[size-1];
- case GL_SHORT: return short_types_norm[size-1];
- case GL_BYTE: return byte_types_norm[size-1];
- case GL_UNSIGNED_INT: return uint_types_norm[size-1];
- case GL_UNSIGNED_SHORT: return ushort_types_norm[size-1];
- case GL_UNSIGNED_BYTE: return ubyte_types_norm[size-1];
- case GL_FIXED: return fixed_types[size-1];
- default: assert(0); return 0;
- }
- }
- else {
- switch (type) {
- case GL_DOUBLE: return double_types[size-1];
- case GL_FLOAT: return float_types[size-1];
- case GL_HALF_FLOAT: return half_float_types[size-1];
- case GL_INT: return int_types_scale[size-1];
- case GL_SHORT: return short_types_scale[size-1];
- case GL_BYTE: return byte_types_scale[size-1];
- case GL_UNSIGNED_INT: return uint_types_scale[size-1];
- case GL_UNSIGNED_SHORT: return ushort_types_scale[size-1];
- case GL_UNSIGNED_BYTE: return ubyte_types_scale[size-1];
- case GL_FIXED: return fixed_types[size-1];
- default: assert(0); return 0;
- }
- }
- return 0; /* silence compiler warning */
-}
-
-
-
-
-
-/**
- * Examine the active arrays to determine if we have interleaved
- * vertex arrays all living in one VBO, or all living in user space.
- * \param userSpace returns whether the arrays are in user space.
- */
-static GLboolean
-is_interleaved_arrays(const struct st_vertex_program *vp,
- const struct st_vp_variant *vpv,
- const struct gl_client_array **arrays)
-{
- GLuint attr;
- const struct gl_buffer_object *firstBufObj = NULL;
- GLint firstStride = -1;
- const GLubyte *client_addr = NULL;
- GLboolean user_memory;
-
- for (attr = 0; attr < vpv->num_inputs; attr++) {
- const GLuint mesaAttr = vp->index_to_input[attr];
- const struct gl_buffer_object *bufObj = arrays[mesaAttr]->BufferObj;
- const GLsizei stride = arrays[mesaAttr]->StrideB; /* in bytes */
-
- if (firstStride < 0) {
- firstStride = stride;
- user_memory = !bufObj || !bufObj->Name;
- }
- else if (firstStride != stride) {
- return GL_FALSE;
- }
-
- if (!bufObj || !bufObj->Name) {
- /* Try to detect if the client-space arrays are
- * "close" to each other.
- */
- if (!user_memory) {
- return GL_FALSE;
- }
- if (!client_addr) {
- client_addr = arrays[mesaAttr]->Ptr;
- }
- else if (abs(arrays[mesaAttr]->Ptr - client_addr) > firstStride) {
- /* arrays start too far apart */
- return GL_FALSE;
- }
- }
- else if (!firstBufObj) {
- if (user_memory) {
- return GL_FALSE;
- }
- firstBufObj = bufObj;
- }
- else if (bufObj != firstBufObj) {
- return GL_FALSE;
- }
- }
-
- return GL_TRUE;
-}
-
-
-/**
- * Set up for drawing interleaved arrays that all live in one VBO
- * or all live in user space.
- * \param vbuffer returns vertex buffer info
- * \param velements returns vertex element info
- */
-static void
-setup_interleaved_attribs(struct gl_context *ctx,
- const struct st_vertex_program *vp,
- const struct st_vp_variant *vpv,
- const struct gl_client_array **arrays,
- struct pipe_vertex_buffer *vbuffer,
- struct pipe_vertex_element velements[],
- unsigned max_index,
- unsigned num_instances)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- GLuint attr;
- const GLubyte *low_addr = NULL;
-
- /* Find the lowest address. */
- if(vpv->num_inputs) {
- low_addr = arrays[vp->index_to_input[0]]->Ptr;
-
- for (attr = 1; attr < vpv->num_inputs; attr++) {
- const GLubyte *start = arrays[vp->index_to_input[attr]]->Ptr;
- low_addr = MIN2(low_addr, start);
- }
- }
-
- for (attr = 0; attr < vpv->num_inputs; attr++) {
- const GLuint mesaAttr = vp->index_to_input[attr];
- struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
- struct st_buffer_object *stobj = st_buffer_object(bufobj);
- GLsizei stride = arrays[mesaAttr]->StrideB;
-
- if (attr == 0) {
- if (bufobj && bufobj->Name) {
- vbuffer->buffer = NULL;
- pipe_resource_reference(&vbuffer->buffer, stobj->buffer);
- vbuffer->buffer_offset = pointer_to_offset(low_addr);
- } else {
- uint divisor = arrays[mesaAttr]->InstanceDivisor;
- uint length = (divisor ? num_instances / divisor : max_index) + 1;
- vbuffer->buffer =
- pipe_user_buffer_create(pipe->screen, (void*)low_addr,
- stride * length,
- PIPE_BIND_VERTEX_BUFFER);
- vbuffer->buffer_offset = 0;
-
- /* Track user vertex buffers. */
- pipe_resource_reference(&st->user_vb[0], vbuffer->buffer);
- st->user_vb_stride[0] = stride;
- st->num_user_vbs = 1;
- }
- vbuffer->stride = stride; /* in bytes */
- }
-
- velements[attr].src_offset =
- (unsigned) (arrays[mesaAttr]->Ptr - low_addr);
- velements[attr].instance_divisor = arrays[mesaAttr]->InstanceDivisor;
- velements[attr].vertex_buffer_index = 0;
- velements[attr].src_format =
- st_pipe_vertex_format(arrays[mesaAttr]->Type,
- arrays[mesaAttr]->Size,
- arrays[mesaAttr]->Format,
- arrays[mesaAttr]->Normalized);
- assert(velements[attr].src_format);
- }
-}
-
-
-/**
- * Set up a separate pipe_vertex_buffer and pipe_vertex_element for each
- * vertex attribute.
- * \param vbuffer returns vertex buffer info
- * \param velements returns vertex element info
- */
-static void
-setup_non_interleaved_attribs(struct gl_context *ctx,
- const struct st_vertex_program *vp,
- const struct st_vp_variant *vpv,
- const struct gl_client_array **arrays,
- struct pipe_vertex_buffer vbuffer[],
- struct pipe_vertex_element velements[],
- unsigned max_index,
- unsigned num_instances)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- GLuint attr;
-
- for (attr = 0; attr < vpv->num_inputs; attr++) {
- const GLuint mesaAttr = vp->index_to_input[attr];
- struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
- GLsizei stride = arrays[mesaAttr]->StrideB;
-
- if (bufobj && bufobj->Name) {
- /* Attribute data is in a VBO.
- * Recall that for VBOs, the gl_client_array->Ptr field is
- * really an offset from the start of the VBO, not a pointer.
- */
- struct st_buffer_object *stobj = st_buffer_object(bufobj);
- assert(stobj->buffer);
-
- vbuffer[attr].buffer = NULL;
- pipe_resource_reference(&vbuffer[attr].buffer, stobj->buffer);
- vbuffer[attr].buffer_offset = pointer_to_offset(arrays[mesaAttr]->Ptr);
- }
- else {
- /* wrap user data */
- if (arrays[mesaAttr]->Ptr) {
- uint divisor = arrays[mesaAttr]->InstanceDivisor;
- uint length = (divisor ? num_instances / divisor : max_index) + 1;
- vbuffer[attr].buffer =
- pipe_user_buffer_create(pipe->screen,
- (void *) arrays[mesaAttr]->Ptr,
- stride * length,
- PIPE_BIND_VERTEX_BUFFER);
- }
- else {
- /* no array, use ctx->Current.Attrib[] value */
- uint bytes = sizeof(ctx->Current.Attrib[0]);
- vbuffer[attr].buffer =
- pipe_user_buffer_create(pipe->screen,
- (void *) ctx->Current.Attrib[mesaAttr],
- bytes,
- PIPE_BIND_VERTEX_BUFFER);
- stride = 0;
- }
-
- vbuffer[attr].buffer_offset = 0;
-
- /* Track user vertex buffers. */
- pipe_resource_reference(&st->user_vb[attr], vbuffer->buffer);
- st->user_vb_stride[attr] = stride;
- st->num_user_vbs = MAX2(st->num_user_vbs, attr+1);
- }
-
- /* common-case setup */
- vbuffer[attr].stride = stride; /* in bytes */
-
- velements[attr].src_offset = 0;
- velements[attr].instance_divisor = arrays[mesaAttr]->InstanceDivisor;
- velements[attr].vertex_buffer_index = attr;
- velements[attr].src_format
- = st_pipe_vertex_format(arrays[mesaAttr]->Type,
- arrays[mesaAttr]->Size,
- arrays[mesaAttr]->Format,
- arrays[mesaAttr]->Normalized);
- assert(velements[attr].src_format);
- }
-}
-
-
-static void
-setup_index_buffer(struct gl_context *ctx,
- const struct _mesa_index_buffer *ib,
- struct pipe_index_buffer *ibuffer)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
-
- memset(ibuffer, 0, sizeof(*ibuffer));
- if (ib) {
- struct gl_buffer_object *bufobj = ib->obj;
-
- switch (ib->type) {
- case GL_UNSIGNED_INT:
- ibuffer->index_size = 4;
- break;
- case GL_UNSIGNED_SHORT:
- ibuffer->index_size = 2;
- break;
- case GL_UNSIGNED_BYTE:
- ibuffer->index_size = 1;
- break;
- default:
- assert(0);
- return;
- }
-
- /* get/create the index buffer object */
- if (bufobj && bufobj->Name) {
- /* elements/indexes are in a real VBO */
- struct st_buffer_object *stobj = st_buffer_object(bufobj);
- pipe_resource_reference(&ibuffer->buffer, stobj->buffer);
- ibuffer->offset = pointer_to_offset(ib->ptr);
- }
- else {
- /* element/indicies are in user space memory */
- ibuffer->buffer =
- pipe_user_buffer_create(pipe->screen, (void *) ib->ptr,
- ib->count * ibuffer->index_size,
- PIPE_BIND_INDEX_BUFFER);
- }
- }
-}
-
-/**
- * Prior to drawing, check that any uniforms referenced by the
- * current shader have been set. If a uniform has not been set,
- * issue a warning.
- */
-static void
-check_uniforms(struct gl_context *ctx)
-{
- struct gl_shader_program *shProg[3] = {
- ctx->Shader.CurrentVertexProgram,
- ctx->Shader.CurrentGeometryProgram,
- ctx->Shader.CurrentFragmentProgram,
- };
- unsigned j;
-
- for (j = 0; j < 3; j++) {
- unsigned i;
-
- if (shProg[j] == NULL || !shProg[j]->LinkStatus)
- continue;
-
- for (i = 0; i < shProg[j]->Uniforms->NumUniforms; i++) {
- const struct gl_uniform *u = &shProg[j]->Uniforms->Uniforms[i];
- if (!u->Initialized) {
- _mesa_warning(ctx,
- "Using shader with uninitialized uniform: %s",
- u->Name);
- }
- }
- }
-}
-
-
-/**
- * Translate OpenGL primtive type (GL_POINTS, GL_TRIANGLE_STRIP, etc) to
- * the corresponding Gallium type.
- */
-static unsigned
-translate_prim(const struct gl_context *ctx, unsigned prim)
-{
- /* GL prims should match Gallium prims, spot-check a few */
- assert(GL_POINTS == PIPE_PRIM_POINTS);
- assert(GL_QUADS == PIPE_PRIM_QUADS);
- assert(GL_TRIANGLE_STRIP_ADJACENCY == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY);
-
- /* Avoid quadstrips if it's easy to do so:
- * Note: it's imporant to do the correct trimming if we change the prim type!
- * We do that wherever this function is called.
- */
- if (prim == GL_QUAD_STRIP &&
- ctx->Light.ShadeModel != GL_FLAT &&
- ctx->Polygon.FrontMode == GL_FILL &&
- ctx->Polygon.BackMode == GL_FILL)
- prim = GL_TRIANGLE_STRIP;
-
- return prim;
-}
-
-
-static void
-st_validate_varrays(struct gl_context *ctx,
- const struct gl_client_array **arrays,
- unsigned max_index,
- unsigned num_instances)
-{
- struct st_context *st = st_context(ctx);
- const struct st_vertex_program *vp;
- const struct st_vp_variant *vpv;
- struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS];
- struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
- unsigned num_vbuffers, num_velements;
- GLuint attr;
- unsigned i;
-
- /* must get these after state validation! */
- vp = st->vp;
- vpv = st->vp_variant;
-
- memset(velements, 0, sizeof(struct pipe_vertex_element) * vpv->num_inputs);
-
- /* Unreference any user vertex buffers. */
- for (i = 0; i < st->num_user_vbs; i++) {
- pipe_resource_reference(&st->user_vb[i], NULL);
- }
- st->num_user_vbs = 0;
-
- /*
- * Setup the vbuffer[] and velements[] arrays.
- */
- if (is_interleaved_arrays(vp, vpv, arrays)) {
- setup_interleaved_attribs(ctx, vp, vpv, arrays, vbuffer, velements,
- max_index, num_instances);
-
- num_vbuffers = 1;
- num_velements = vpv->num_inputs;
- if (num_velements == 0)
- num_vbuffers = 0;
- }
- else {
- setup_non_interleaved_attribs(ctx, vp, vpv, arrays,
- vbuffer, velements, max_index, num_instances);
- num_vbuffers = vpv->num_inputs;
- num_velements = vpv->num_inputs;
- }
-
- cso_set_vertex_buffers(st->cso_context, num_vbuffers, vbuffer);
- cso_set_vertex_elements(st->cso_context, num_velements, velements);
-
- /* unreference buffers (frees wrapped user-space buffer objects)
- * This is OK, because the pipe driver should reference buffers by itself
- * in set_vertex_buffers. */
- for (attr = 0; attr < num_vbuffers; attr++) {
- pipe_resource_reference(&vbuffer[attr].buffer, NULL);
- assert(!vbuffer[attr].buffer);
- }
-}
-
-
-/**
- * This function gets plugged into the VBO module and is called when
- * we have something to render.
- * Basically, translate the information into the format expected by gallium.
- */
-void
-st_draw_vbo(struct gl_context *ctx,
- const struct gl_client_array **arrays,
- const struct _mesa_prim *prims,
- GLuint nr_prims,
- const struct _mesa_index_buffer *ib,
- GLboolean index_bounds_valid,
- GLuint min_index,
- GLuint max_index)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct pipe_index_buffer ibuffer;
- struct pipe_draw_info info;
- unsigned i, num_instances = 1;
- GLboolean new_array = GL_TRUE;
- /* Fix this (Bug 34378):
- GLboolean new_array =
- st->dirty.st && (st->dirty.mesa & (_NEW_ARRAY | _NEW_PROGRAM)) != 0;*/
-
- /* Mesa core state should have been validated already */
- assert(ctx->NewState == 0x0);
-
- if (ib) {
- /* Gallium probably doesn't want this in some cases. */
- if (!index_bounds_valid)
- if (!vbo_all_varyings_in_vbos(arrays))
- vbo_get_minmax_index(ctx, prims, ib, &min_index, &max_index);
-
- for (i = 0; i < nr_prims; i++) {
- num_instances = MAX2(num_instances, prims[i].num_instances);
- }
- } else {
- /* Get min/max index for non-indexed drawing. */
- min_index = ~0;
- max_index = 0;
-
- for (i = 0; i < nr_prims; i++) {
- min_index = MIN2(min_index, prims[i].start);
- max_index = MAX2(max_index, prims[i].start + prims[i].count - 1);
- num_instances = MAX2(num_instances, prims[i].num_instances);
- }
- }
-
- /* Validate state. */
- if (st->dirty.st) {
- GLboolean vertDataEdgeFlags;
-
- /* sanity check for pointer arithmetic below */
- assert(sizeof(arrays[0]->Ptr[0]) == 1);
-
- vertDataEdgeFlags = arrays[VERT_ATTRIB_EDGEFLAG]->BufferObj &&
- arrays[VERT_ATTRIB_EDGEFLAG]->BufferObj->Name;
- if (vertDataEdgeFlags != st->vertdata_edgeflags) {
- st->vertdata_edgeflags = vertDataEdgeFlags;
- st->dirty.st |= ST_NEW_EDGEFLAGS_DATA;
- }
-
- st_validate_state(st);
-
- if (new_array) {
- st_validate_varrays(ctx, arrays, max_index, num_instances);
- }
-
-#if 0
- if (MESA_VERBOSE & VERBOSE_GLSL) {
- check_uniforms(ctx);
- }
-#else
- (void) check_uniforms;
-#endif
- }
-
- /* Notify the driver that the content of user buffers may have been
- * changed. */
- if (!new_array && st->num_user_vbs) {
- for (i = 0; i < st->num_user_vbs; i++) {
- if (st->user_vb[i]) {
- unsigned stride = st->user_vb_stride[i];
-
- if (stride) {
- pipe->redefine_user_buffer(pipe, st->user_vb[i],
- min_index * stride,
- (max_index + 1 - min_index) * stride);
- } else {
- /* stride == 0 */
- pipe->redefine_user_buffer(pipe, st->user_vb[i],
- 0, st->user_vb[i]->width0);
- }
- }
- }
- }
-
- setup_index_buffer(ctx, ib, &ibuffer);
- pipe->set_index_buffer(pipe, &ibuffer);
-
- util_draw_init_info(&info);
- if (ib) {
- info.indexed = TRUE;
- if (min_index != ~0 && max_index != ~0) {
- info.min_index = min_index;
- info.max_index = max_index;
- }
- }
-
- info.primitive_restart = st->ctx->Array.PrimitiveRestart;
- info.restart_index = st->ctx->Array.RestartIndex;
-
- /* do actual drawing */
- for (i = 0; i < nr_prims; i++) {
- info.mode = translate_prim( ctx, prims[i].mode );
- info.start = prims[i].start;
- info.count = prims[i].count;
- info.instance_count = prims[i].num_instances;
- info.index_bias = prims[i].basevertex;
- if (!ib) {
- info.min_index = info.start;
- info.max_index = info.start + info.count - 1;
- }
-
- if (u_trim_pipe_prim(info.mode, &info.count))
- pipe->draw_vbo(pipe, &info);
- }
-
- pipe_resource_reference(&ibuffer.buffer, NULL);
-}
-
-
-void st_init_draw( struct st_context *st )
-{
- struct gl_context *ctx = st->ctx;
-
- vbo_set_draw_func(ctx, st_draw_vbo);
-
-#if FEATURE_feedback || FEATURE_rastpos
- st->draw = draw_create(st->pipe); /* for selection/feedback */
-
- /* Disable draw options that might convert points/lines to tris, etc.
- * as that would foul-up feedback/selection mode.
- */
- draw_wide_line_threshold(st->draw, 1000.0f);
- draw_wide_point_threshold(st->draw, 1000.0f);
- draw_enable_line_stipple(st->draw, FALSE);
- draw_enable_point_sprites(st->draw, FALSE);
-#endif
-}
-
-
-void st_destroy_draw( struct st_context *st )
-{
-#if FEATURE_feedback || FEATURE_rastpos
- draw_destroy(st->draw);
-#endif
-}
-
-
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/*
+ * This file implements the st_draw_vbo() function which is called from
+ * Mesa's VBO module. All point/line/triangle rendering is done through
+ * this function whether the user called glBegin/End, glDrawArrays,
+ * glDrawElements, glEvalMesh, or glCalList, etc.
+ *
+ * We basically convert the VBO's vertex attribute/array information into
+ * Gallium vertex state, bind the vertex buffer objects and call
+ * pipe->draw_elements(), pipe->draw_range_elements() or pipe->draw_arrays().
+ *
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#include "main/imports.h"
+#include "main/image.h"
+#include "main/macros.h"
+#include "main/mfeatures.h"
+#include "program/prog_uniform.h"
+
+#include "vbo/vbo.h"
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_cb_bufferobjects.h"
+#include "st_draw.h"
+#include "st_program.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "util/u_format.h"
+#include "util/u_prim.h"
+#include "util/u_draw_quad.h"
+#include "draw/draw_context.h"
+#include "cso_cache/cso_context.h"
+
+
+static GLuint double_types[4] = {
+ PIPE_FORMAT_R64_FLOAT,
+ PIPE_FORMAT_R64G64_FLOAT,
+ PIPE_FORMAT_R64G64B64_FLOAT,
+ PIPE_FORMAT_R64G64B64A64_FLOAT
+};
+
+static GLuint float_types[4] = {
+ PIPE_FORMAT_R32_FLOAT,
+ PIPE_FORMAT_R32G32_FLOAT,
+ PIPE_FORMAT_R32G32B32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT
+};
+
+static GLuint half_float_types[4] = {
+ PIPE_FORMAT_R16_FLOAT,
+ PIPE_FORMAT_R16G16_FLOAT,
+ PIPE_FORMAT_R16G16B16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT
+};
+
+static GLuint uint_types_norm[4] = {
+ PIPE_FORMAT_R32_UNORM,
+ PIPE_FORMAT_R32G32_UNORM,
+ PIPE_FORMAT_R32G32B32_UNORM,
+ PIPE_FORMAT_R32G32B32A32_UNORM
+};
+
+static GLuint uint_types_scale[4] = {
+ PIPE_FORMAT_R32_USCALED,
+ PIPE_FORMAT_R32G32_USCALED,
+ PIPE_FORMAT_R32G32B32_USCALED,
+ PIPE_FORMAT_R32G32B32A32_USCALED
+};
+
+static GLuint int_types_norm[4] = {
+ PIPE_FORMAT_R32_SNORM,
+ PIPE_FORMAT_R32G32_SNORM,
+ PIPE_FORMAT_R32G32B32_SNORM,
+ PIPE_FORMAT_R32G32B32A32_SNORM
+};
+
+static GLuint int_types_scale[4] = {
+ PIPE_FORMAT_R32_SSCALED,
+ PIPE_FORMAT_R32G32_SSCALED,
+ PIPE_FORMAT_R32G32B32_SSCALED,
+ PIPE_FORMAT_R32G32B32A32_SSCALED
+};
+
+static GLuint ushort_types_norm[4] = {
+ PIPE_FORMAT_R16_UNORM,
+ PIPE_FORMAT_R16G16_UNORM,
+ PIPE_FORMAT_R16G16B16_UNORM,
+ PIPE_FORMAT_R16G16B16A16_UNORM
+};
+
+static GLuint ushort_types_scale[4] = {
+ PIPE_FORMAT_R16_USCALED,
+ PIPE_FORMAT_R16G16_USCALED,
+ PIPE_FORMAT_R16G16B16_USCALED,
+ PIPE_FORMAT_R16G16B16A16_USCALED
+};
+
+static GLuint short_types_norm[4] = {
+ PIPE_FORMAT_R16_SNORM,
+ PIPE_FORMAT_R16G16_SNORM,
+ PIPE_FORMAT_R16G16B16_SNORM,
+ PIPE_FORMAT_R16G16B16A16_SNORM
+};
+
+static GLuint short_types_scale[4] = {
+ PIPE_FORMAT_R16_SSCALED,
+ PIPE_FORMAT_R16G16_SSCALED,
+ PIPE_FORMAT_R16G16B16_SSCALED,
+ PIPE_FORMAT_R16G16B16A16_SSCALED
+};
+
+static GLuint ubyte_types_norm[4] = {
+ PIPE_FORMAT_R8_UNORM,
+ PIPE_FORMAT_R8G8_UNORM,
+ PIPE_FORMAT_R8G8B8_UNORM,
+ PIPE_FORMAT_R8G8B8A8_UNORM
+};
+
+static GLuint ubyte_types_scale[4] = {
+ PIPE_FORMAT_R8_USCALED,
+ PIPE_FORMAT_R8G8_USCALED,
+ PIPE_FORMAT_R8G8B8_USCALED,
+ PIPE_FORMAT_R8G8B8A8_USCALED
+};
+
+static GLuint byte_types_norm[4] = {
+ PIPE_FORMAT_R8_SNORM,
+ PIPE_FORMAT_R8G8_SNORM,
+ PIPE_FORMAT_R8G8B8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM
+};
+
+static GLuint byte_types_scale[4] = {
+ PIPE_FORMAT_R8_SSCALED,
+ PIPE_FORMAT_R8G8_SSCALED,
+ PIPE_FORMAT_R8G8B8_SSCALED,
+ PIPE_FORMAT_R8G8B8A8_SSCALED
+};
+
+static GLuint fixed_types[4] = {
+ PIPE_FORMAT_R32_FIXED,
+ PIPE_FORMAT_R32G32_FIXED,
+ PIPE_FORMAT_R32G32B32_FIXED,
+ PIPE_FORMAT_R32G32B32A32_FIXED
+};
+
+
+
+/**
+ * Return a PIPE_FORMAT_x for the given GL datatype and size.
+ */
+GLuint
+st_pipe_vertex_format(GLenum type, GLuint size, GLenum format,
+ GLboolean normalized)
+{
+ assert((type >= GL_BYTE && type <= GL_DOUBLE) ||
+ type == GL_FIXED || type == GL_HALF_FLOAT);
+ assert(size >= 1);
+ assert(size <= 4);
+ assert(format == GL_RGBA || format == GL_BGRA);
+
+ if (format == GL_BGRA) {
+ /* this is an odd-ball case */
+ assert(type == GL_UNSIGNED_BYTE);
+ assert(normalized);
+ return PIPE_FORMAT_B8G8R8A8_UNORM;
+ }
+
+ if (normalized) {
+ switch (type) {
+ case GL_DOUBLE: return double_types[size-1];
+ case GL_FLOAT: return float_types[size-1];
+ case GL_HALF_FLOAT: return half_float_types[size-1];
+ case GL_INT: return int_types_norm[size-1];
+ case GL_SHORT: return short_types_norm[size-1];
+ case GL_BYTE: return byte_types_norm[size-1];
+ case GL_UNSIGNED_INT: return uint_types_norm[size-1];
+ case GL_UNSIGNED_SHORT: return ushort_types_norm[size-1];
+ case GL_UNSIGNED_BYTE: return ubyte_types_norm[size-1];
+ case GL_FIXED: return fixed_types[size-1];
+ default: assert(0); return 0;
+ }
+ }
+ else {
+ switch (type) {
+ case GL_DOUBLE: return double_types[size-1];
+ case GL_FLOAT: return float_types[size-1];
+ case GL_HALF_FLOAT: return half_float_types[size-1];
+ case GL_INT: return int_types_scale[size-1];
+ case GL_SHORT: return short_types_scale[size-1];
+ case GL_BYTE: return byte_types_scale[size-1];
+ case GL_UNSIGNED_INT: return uint_types_scale[size-1];
+ case GL_UNSIGNED_SHORT: return ushort_types_scale[size-1];
+ case GL_UNSIGNED_BYTE: return ubyte_types_scale[size-1];
+ case GL_FIXED: return fixed_types[size-1];
+ default: assert(0); return 0;
+ }
+ }
+ return 0; /* silence compiler warning */
+}
+
+
+
+
+
+/**
+ * Examine the active arrays to determine if we have interleaved
+ * vertex arrays all living in one VBO, or all living in user space.
+ * \param userSpace returns whether the arrays are in user space.
+ */
+static GLboolean
+is_interleaved_arrays(const struct st_vertex_program *vp,
+ const struct st_vp_variant *vpv,
+ const struct gl_client_array **arrays)
+{
+ GLuint attr;
+ const struct gl_buffer_object *firstBufObj = NULL;
+ GLint firstStride = -1;
+ const GLubyte *client_addr = NULL;
+ GLboolean user_memory;
+
+ for (attr = 0; attr < vpv->num_inputs; attr++) {
+ const GLuint mesaAttr = vp->index_to_input[attr];
+ const struct gl_buffer_object *bufObj = arrays[mesaAttr]->BufferObj;
+ const GLsizei stride = arrays[mesaAttr]->StrideB; /* in bytes */
+
+ if (firstStride < 0) {
+ firstStride = stride;
+ user_memory = !bufObj || !bufObj->Name;
+ }
+ else if (firstStride != stride) {
+ return GL_FALSE;
+ }
+
+ if (!bufObj || !bufObj->Name) {
+ /* Try to detect if the client-space arrays are
+ * "close" to each other.
+ */
+ if (!user_memory) {
+ return GL_FALSE;
+ }
+ if (!client_addr) {
+ client_addr = arrays[mesaAttr]->Ptr;
+ }
+ else if (abs(arrays[mesaAttr]->Ptr - client_addr) > firstStride) {
+ /* arrays start too far apart */
+ return GL_FALSE;
+ }
+ }
+ else if (!firstBufObj) {
+ if (user_memory) {
+ return GL_FALSE;
+ }
+ firstBufObj = bufObj;
+ }
+ else if (bufObj != firstBufObj) {
+ return GL_FALSE;
+ }
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Set up for drawing interleaved arrays that all live in one VBO
+ * or all live in user space.
+ * \param vbuffer returns vertex buffer info
+ * \param velements returns vertex element info
+ */
+static void
+setup_interleaved_attribs(struct gl_context *ctx,
+ const struct st_vertex_program *vp,
+ const struct st_vp_variant *vpv,
+ const struct gl_client_array **arrays,
+ struct pipe_vertex_buffer *vbuffer,
+ struct pipe_vertex_element velements[],
+ unsigned max_index,
+ unsigned num_instances)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ GLuint attr;
+ const GLubyte *low_addr = NULL;
+
+ /* Find the lowest address. */
+ if(vpv->num_inputs) {
+ low_addr = arrays[vp->index_to_input[0]]->Ptr;
+
+ for (attr = 1; attr < vpv->num_inputs; attr++) {
+ const GLubyte *start = arrays[vp->index_to_input[attr]]->Ptr;
+ low_addr = MIN2(low_addr, start);
+ }
+ }
+
+ for (attr = 0; attr < vpv->num_inputs; attr++) {
+ const GLuint mesaAttr = vp->index_to_input[attr];
+ struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
+ struct st_buffer_object *stobj = st_buffer_object(bufobj);
+ GLsizei stride = arrays[mesaAttr]->StrideB;
+
+ if (attr == 0) {
+ if (bufobj && bufobj->Name) {
+ vbuffer->buffer = NULL;
+ pipe_resource_reference(&vbuffer->buffer, stobj->buffer);
+ vbuffer->buffer_offset = pointer_to_offset(low_addr);
+ } else {
+ uint divisor = arrays[mesaAttr]->InstanceDivisor;
+ uint length = (divisor ? num_instances / divisor : max_index) + 1;
+ vbuffer->buffer =
+ pipe_user_buffer_create(pipe->screen, (void*)low_addr,
+ stride * length,
+ PIPE_BIND_VERTEX_BUFFER);
+ vbuffer->buffer_offset = 0;
+
+ /* Track user vertex buffers. */
+ pipe_resource_reference(&st->user_vb[0], vbuffer->buffer);
+ st->user_vb_stride[0] = stride;
+ st->num_user_vbs = 1;
+ }
+ vbuffer->stride = stride; /* in bytes */
+ }
+
+ velements[attr].src_offset =
+ (unsigned) (arrays[mesaAttr]->Ptr - low_addr);
+ velements[attr].instance_divisor = arrays[mesaAttr]->InstanceDivisor;
+ velements[attr].vertex_buffer_index = 0;
+ velements[attr].src_format =
+ st_pipe_vertex_format(arrays[mesaAttr]->Type,
+ arrays[mesaAttr]->Size,
+ arrays[mesaAttr]->Format,
+ arrays[mesaAttr]->Normalized);
+ assert(velements[attr].src_format);
+ }
+}
+
+
+/**
+ * Set up a separate pipe_vertex_buffer and pipe_vertex_element for each
+ * vertex attribute.
+ * \param vbuffer returns vertex buffer info
+ * \param velements returns vertex element info
+ */
+static void
+setup_non_interleaved_attribs(struct gl_context *ctx,
+ const struct st_vertex_program *vp,
+ const struct st_vp_variant *vpv,
+ const struct gl_client_array **arrays,
+ struct pipe_vertex_buffer vbuffer[],
+ struct pipe_vertex_element velements[],
+ unsigned max_index,
+ unsigned num_instances)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ GLuint attr;
+
+ for (attr = 0; attr < vpv->num_inputs; attr++) {
+ const GLuint mesaAttr = vp->index_to_input[attr];
+ struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
+ GLsizei stride = arrays[mesaAttr]->StrideB;
+
+ if (bufobj && bufobj->Name) {
+ /* Attribute data is in a VBO.
+ * Recall that for VBOs, the gl_client_array->Ptr field is
+ * really an offset from the start of the VBO, not a pointer.
+ */
+ struct st_buffer_object *stobj = st_buffer_object(bufobj);
+ assert(stobj->buffer);
+
+ vbuffer[attr].buffer = NULL;
+ pipe_resource_reference(&vbuffer[attr].buffer, stobj->buffer);
+ vbuffer[attr].buffer_offset = pointer_to_offset(arrays[mesaAttr]->Ptr);
+ }
+ else {
+ /* wrap user data */
+ if (arrays[mesaAttr]->Ptr) {
+ uint divisor = arrays[mesaAttr]->InstanceDivisor;
+ uint length = (divisor ? num_instances / divisor : max_index) + 1;
+ vbuffer[attr].buffer =
+ pipe_user_buffer_create(pipe->screen,
+ (void *) arrays[mesaAttr]->Ptr,
+ stride * length,
+ PIPE_BIND_VERTEX_BUFFER);
+ }
+ else {
+ /* no array, use ctx->Current.Attrib[] value */
+ uint bytes = sizeof(ctx->Current.Attrib[0]);
+ vbuffer[attr].buffer =
+ pipe_user_buffer_create(pipe->screen,
+ (void *) ctx->Current.Attrib[mesaAttr],
+ bytes,
+ PIPE_BIND_VERTEX_BUFFER);
+ stride = 0;
+ }
+
+ vbuffer[attr].buffer_offset = 0;
+
+ /* Track user vertex buffers. */
+ pipe_resource_reference(&st->user_vb[attr], vbuffer->buffer);
+ st->user_vb_stride[attr] = stride;
+ st->num_user_vbs = MAX2(st->num_user_vbs, attr+1);
+ }
+
+ /* common-case setup */
+ vbuffer[attr].stride = stride; /* in bytes */
+
+ velements[attr].src_offset = 0;
+ velements[attr].instance_divisor = arrays[mesaAttr]->InstanceDivisor;
+ velements[attr].vertex_buffer_index = attr;
+ velements[attr].src_format
+ = st_pipe_vertex_format(arrays[mesaAttr]->Type,
+ arrays[mesaAttr]->Size,
+ arrays[mesaAttr]->Format,
+ arrays[mesaAttr]->Normalized);
+ assert(velements[attr].src_format);
+ }
+}
+
+
+static void
+setup_index_buffer(struct gl_context *ctx,
+ const struct _mesa_index_buffer *ib,
+ struct pipe_index_buffer *ibuffer)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+
+ memset(ibuffer, 0, sizeof(*ibuffer));
+ if (ib) {
+ struct gl_buffer_object *bufobj = ib->obj;
+
+ switch (ib->type) {
+ case GL_UNSIGNED_INT:
+ ibuffer->index_size = 4;
+ break;
+ case GL_UNSIGNED_SHORT:
+ ibuffer->index_size = 2;
+ break;
+ case GL_UNSIGNED_BYTE:
+ ibuffer->index_size = 1;
+ break;
+ default:
+ assert(0);
+ return;
+ }
+
+ /* get/create the index buffer object */
+ if (bufobj && bufobj->Name) {
+ /* elements/indexes are in a real VBO */
+ struct st_buffer_object *stobj = st_buffer_object(bufobj);
+ pipe_resource_reference(&ibuffer->buffer, stobj->buffer);
+ ibuffer->offset = pointer_to_offset(ib->ptr);
+ }
+ else {
+ /* element/indicies are in user space memory */
+ ibuffer->buffer =
+ pipe_user_buffer_create(pipe->screen, (void *) ib->ptr,
+ ib->count * ibuffer->index_size,
+ PIPE_BIND_INDEX_BUFFER);
+ }
+ }
+}
+
+/**
+ * Prior to drawing, check that any uniforms referenced by the
+ * current shader have been set. If a uniform has not been set,
+ * issue a warning.
+ */
+static void
+check_uniforms(struct gl_context *ctx)
+{
+ struct gl_shader_program *shProg[3] = {
+ ctx->Shader.CurrentVertexProgram,
+ ctx->Shader.CurrentGeometryProgram,
+ ctx->Shader.CurrentFragmentProgram,
+ };
+ unsigned j;
+
+ for (j = 0; j < 3; j++) {
+ unsigned i;
+
+ if (shProg[j] == NULL || !shProg[j]->LinkStatus)
+ continue;
+
+ for (i = 0; i < shProg[j]->Uniforms->NumUniforms; i++) {
+ const struct gl_uniform *u = &shProg[j]->Uniforms->Uniforms[i];
+ if (!u->Initialized) {
+ _mesa_warning(ctx,
+ "Using shader with uninitialized uniform: %s",
+ u->Name);
+ }
+ }
+ }
+}
+
+
+/**
+ * Translate OpenGL primtive type (GL_POINTS, GL_TRIANGLE_STRIP, etc) to
+ * the corresponding Gallium type.
+ */
+static unsigned
+translate_prim(const struct gl_context *ctx, unsigned prim)
+{
+ /* GL prims should match Gallium prims, spot-check a few */
+ assert(GL_POINTS == PIPE_PRIM_POINTS);
+ assert(GL_QUADS == PIPE_PRIM_QUADS);
+ assert(GL_TRIANGLE_STRIP_ADJACENCY == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY);
+
+ /* Avoid quadstrips if it's easy to do so:
+ * Note: it's imporant to do the correct trimming if we change the prim type!
+ * We do that wherever this function is called.
+ */
+ if (prim == GL_QUAD_STRIP &&
+ ctx->Light.ShadeModel != GL_FLAT &&
+ ctx->Polygon.FrontMode == GL_FILL &&
+ ctx->Polygon.BackMode == GL_FILL)
+ prim = GL_TRIANGLE_STRIP;
+
+ return prim;
+}
+
+
+static void
+st_validate_varrays(struct gl_context *ctx,
+ const struct gl_client_array **arrays,
+ unsigned max_index,
+ unsigned num_instances)
+{
+ struct st_context *st = st_context(ctx);
+ const struct st_vertex_program *vp;
+ const struct st_vp_variant *vpv;
+ struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS];
+ struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
+ unsigned num_vbuffers, num_velements;
+ GLuint attr;
+ unsigned i;
+
+ /* must get these after state validation! */
+ vp = st->vp;
+ vpv = st->vp_variant;
+
+ memset(velements, 0, sizeof(struct pipe_vertex_element) * vpv->num_inputs);
+
+ /* Unreference any user vertex buffers. */
+ for (i = 0; i < st->num_user_vbs; i++) {
+ pipe_resource_reference(&st->user_vb[i], NULL);
+ }
+ st->num_user_vbs = 0;
+
+ /*
+ * Setup the vbuffer[] and velements[] arrays.
+ */
+ if (is_interleaved_arrays(vp, vpv, arrays)) {
+ setup_interleaved_attribs(ctx, vp, vpv, arrays, vbuffer, velements,
+ max_index, num_instances);
+
+ num_vbuffers = 1;
+ num_velements = vpv->num_inputs;
+ if (num_velements == 0)
+ num_vbuffers = 0;
+ }
+ else {
+ setup_non_interleaved_attribs(ctx, vp, vpv, arrays,
+ vbuffer, velements, max_index, num_instances);
+ num_vbuffers = vpv->num_inputs;
+ num_velements = vpv->num_inputs;
+ }
+
+ cso_set_vertex_buffers(st->cso_context, num_vbuffers, vbuffer);
+ cso_set_vertex_elements(st->cso_context, num_velements, velements);
+
+ /* unreference buffers (frees wrapped user-space buffer objects)
+ * This is OK, because the pipe driver should reference buffers by itself
+ * in set_vertex_buffers. */
+ for (attr = 0; attr < num_vbuffers; attr++) {
+ pipe_resource_reference(&vbuffer[attr].buffer, NULL);
+ assert(!vbuffer[attr].buffer);
+ }
+}
+
+
+/**
+ * This function gets plugged into the VBO module and is called when
+ * we have something to render.
+ * Basically, translate the information into the format expected by gallium.
+ */
+void
+st_draw_vbo(struct gl_context *ctx,
+ const struct gl_client_array **arrays,
+ const struct _mesa_prim *prims,
+ GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLboolean index_bounds_valid,
+ GLuint min_index,
+ GLuint max_index)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_index_buffer ibuffer;
+ struct pipe_draw_info info;
+ unsigned i, num_instances = 1;
+ GLboolean new_array = GL_TRUE;
+ /* Fix this (Bug 34378):
+ GLboolean new_array =
+ st->dirty.st && (st->dirty.mesa & (_NEW_ARRAY | _NEW_PROGRAM)) != 0;*/
+
+ /* Mesa core state should have been validated already */
+ assert(ctx->NewState == 0x0);
+
+ if (ib) {
+ /* Gallium probably doesn't want this in some cases. */
+ if (!index_bounds_valid)
+ if (!vbo_all_varyings_in_vbos(arrays))
+ vbo_get_minmax_index(ctx, prims, ib, &min_index, &max_index);
+
+ for (i = 0; i < nr_prims; i++) {
+ num_instances = MAX2(num_instances, prims[i].num_instances);
+ }
+ } else {
+ /* Get min/max index for non-indexed drawing. */
+ min_index = ~0;
+ max_index = 0;
+
+ for (i = 0; i < nr_prims; i++) {
+ min_index = MIN2(min_index, prims[i].start);
+ max_index = MAX2(max_index, prims[i].start + prims[i].count - 1);
+ num_instances = MAX2(num_instances, prims[i].num_instances);
+ }
+ }
+
+ /* Validate state. */
+ if (st->dirty.st) {
+ GLboolean vertDataEdgeFlags;
+
+ /* sanity check for pointer arithmetic below */
+ assert(sizeof(arrays[0]->Ptr[0]) == 1);
+
+ vertDataEdgeFlags = arrays[VERT_ATTRIB_EDGEFLAG]->BufferObj &&
+ arrays[VERT_ATTRIB_EDGEFLAG]->BufferObj->Name;
+ if (vertDataEdgeFlags != st->vertdata_edgeflags) {
+ st->vertdata_edgeflags = vertDataEdgeFlags;
+ st->dirty.st |= ST_NEW_EDGEFLAGS_DATA;
+ }
+
+ st_validate_state(st);
+
+ if (new_array) {
+ st_validate_varrays(ctx, arrays, max_index, num_instances);
+ }
+
+#if 0
+ if (MESA_VERBOSE & VERBOSE_GLSL) {
+ check_uniforms(ctx);
+ }
+#else
+ (void) check_uniforms;
+#endif
+ }
+
+ /* Notify the driver that the content of user buffers may have been
+ * changed. */
+ if (!new_array && st->num_user_vbs) {
+ for (i = 0; i < st->num_user_vbs; i++) {
+ if (st->user_vb[i]) {
+ unsigned stride = st->user_vb_stride[i];
+
+ if (stride) {
+ pipe->redefine_user_buffer(pipe, st->user_vb[i],
+ min_index * stride,
+ (max_index + 1 - min_index) * stride);
+ } else {
+ /* stride == 0 */
+ pipe->redefine_user_buffer(pipe, st->user_vb[i],
+ 0, st->user_vb[i]->width0);
+ }
+ }
+ }
+ }
+
+ setup_index_buffer(ctx, ib, &ibuffer);
+ pipe->set_index_buffer(pipe, &ibuffer);
+
+ util_draw_init_info(&info);
+ if (ib) {
+ info.indexed = TRUE;
+ if (min_index != ~0 && max_index != ~0) {
+ info.min_index = min_index;
+ info.max_index = max_index;
+ }
+ }
+
+ info.primitive_restart = st->ctx->Array.PrimitiveRestart;
+ info.restart_index = st->ctx->Array.RestartIndex;
+
+ /* do actual drawing */
+ for (i = 0; i < nr_prims; i++) {
+ info.mode = translate_prim( ctx, prims[i].mode );
+ info.start = prims[i].start;
+ info.count = prims[i].count;
+ info.instance_count = prims[i].num_instances;
+ info.index_bias = prims[i].basevertex;
+ if (!ib) {
+ info.min_index = info.start;
+ info.max_index = info.start + info.count - 1;
+ }
+
+ if (u_trim_pipe_prim(info.mode, &info.count))
+ pipe->draw_vbo(pipe, &info);
+ }
+
+ pipe_resource_reference(&ibuffer.buffer, NULL);
+}
+
+
+void st_init_draw( struct st_context *st )
+{
+ struct gl_context *ctx = st->ctx;
+
+ vbo_set_draw_func(ctx, st_draw_vbo);
+
+#if FEATURE_feedback || FEATURE_rastpos
+ st->draw = draw_create(st->pipe); /* for selection/feedback */
+
+ /* Disable draw options that might convert points/lines to tris, etc.
+ * as that would foul-up feedback/selection mode.
+ */
+ draw_wide_line_threshold(st->draw, 1000.0f);
+ draw_wide_point_threshold(st->draw, 1000.0f);
+ draw_enable_line_stipple(st->draw, FALSE);
+ draw_enable_point_sprites(st->draw, FALSE);
+#endif
+}
+
+
+void st_destroy_draw( struct st_context *st )
+{
+#if FEATURE_feedback || FEATURE_rastpos
+ draw_destroy(st->draw);
+#endif
+}
+
+
diff --git a/mesalib/src/mesa/state_tracker/st_draw_feedback.c b/mesalib/src/mesa/state_tracker/st_draw_feedback.c
index 1e1220bfe..f0734eae0 100644
--- a/mesalib/src/mesa/state_tracker/st_draw_feedback.c
+++ b/mesalib/src/mesa/state_tracker/st_draw_feedback.c
@@ -1,277 +1,277 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#include "main/imports.h"
-#include "main/image.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-
-#include "vbo/vbo.h"
-
-#include "st_context.h"
-#include "st_atom.h"
-#include "st_cb_bufferobjects.h"
-#include "st_draw.h"
-#include "st_program.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-
-#include "draw/draw_private.h"
-#include "draw/draw_context.h"
-
-
-#if FEATURE_feedback || FEATURE_rastpos
-
-/**
- * Set the (private) draw module's post-transformed vertex format when in
- * GL_SELECT or GL_FEEDBACK mode or for glRasterPos.
- */
-static void
-set_feedback_vertex_format(struct gl_context *ctx)
-{
-#if 0
- struct st_context *st = st_context(ctx);
- struct vertex_info vinfo;
- GLuint i;
-
- memset(&vinfo, 0, sizeof(vinfo));
-
- if (ctx->RenderMode == GL_SELECT) {
- assert(ctx->RenderMode == GL_SELECT);
- vinfo.num_attribs = 1;
- vinfo.format[0] = FORMAT_4F;
- vinfo.interp_mode[0] = INTERP_LINEAR;
- }
- else {
- /* GL_FEEDBACK, or glRasterPos */
- /* emit all attribs (pos, color, texcoord) as GLfloat[4] */
- vinfo.num_attribs = st->state.vs->cso->state.num_outputs;
- for (i = 0; i < vinfo.num_attribs; i++) {
- vinfo.format[i] = FORMAT_4F;
- vinfo.interp_mode[i] = INTERP_LINEAR;
- }
- }
-
- draw_set_vertex_info(st->draw, &vinfo);
-#endif
-}
-
-
-/**
- * Called by VBO to draw arrays when in selection or feedback mode and
- * to implement glRasterPos.
- * This is very much like the normal draw_vbo() function above.
- * Look at code refactoring some day.
- * Might move this into the failover module some day.
- */
-void
-st_feedback_draw_vbo(struct gl_context *ctx,
- const struct gl_client_array **arrays,
- const struct _mesa_prim *prims,
- GLuint nr_prims,
- const struct _mesa_index_buffer *ib,
- GLboolean index_bounds_valid,
- GLuint min_index,
- GLuint max_index)
-{
- struct st_context *st = st_context(ctx);
- struct pipe_context *pipe = st->pipe;
- struct draw_context *draw = st->draw;
- const struct st_vertex_program *vp;
- const struct pipe_shader_state *vs;
- struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS];
- struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
- struct pipe_index_buffer ibuffer;
- struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS];
- struct pipe_transfer *ib_transfer = NULL;
- GLuint attr, i;
- const void *mapped_indices = NULL;
-
- assert(draw);
-
- st_validate_state(st);
-
- if (!index_bounds_valid)
- vbo_get_minmax_index(ctx, prims, ib, &min_index, &max_index);
-
- /* must get these after state validation! */
- vp = st->vp;
- vs = &st->vp_variant->tgsi;
-
- if (!st->vp_variant->draw_shader) {
- st->vp_variant->draw_shader = draw_create_vertex_shader(draw, vs);
- }
-
- /*
- * Set up the draw module's state.
- *
- * We'd like to do this less frequently, but the normal state-update
- * code sends state updates to the pipe, not to our private draw module.
- */
- assert(draw);
- draw_set_viewport_state(draw, &st->state.viewport);
- draw_set_clip_state(draw, &st->state.clip);
- draw_set_rasterizer_state(draw, &st->state.rasterizer, NULL);
- draw_bind_vertex_shader(draw, st->vp_variant->draw_shader);
- set_feedback_vertex_format(ctx);
-
- /* loop over TGSI shader inputs to determine vertex buffer
- * and attribute info
- */
- for (attr = 0; attr < vp->num_inputs; attr++) {
- const GLuint mesaAttr = vp->index_to_input[attr];
- struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
- void *map;
-
- if (bufobj && bufobj->Name) {
- /* Attribute data is in a VBO.
- * Recall that for VBOs, the gl_client_array->Ptr field is
- * really an offset from the start of the VBO, not a pointer.
- */
- struct st_buffer_object *stobj = st_buffer_object(bufobj);
- assert(stobj->buffer);
-
- vbuffers[attr].buffer = NULL;
- pipe_resource_reference(&vbuffers[attr].buffer, stobj->buffer);
- vbuffers[attr].buffer_offset = pointer_to_offset(arrays[0]->Ptr);
- velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr;
- }
- else {
- /* attribute data is in user-space memory, not a VBO */
- uint bytes = (arrays[mesaAttr]->Size
- * _mesa_sizeof_type(arrays[mesaAttr]->Type)
- * (max_index + 1));
-
- /* wrap user data */
- vbuffers[attr].buffer
- = pipe_user_buffer_create(pipe->screen, (void *) arrays[mesaAttr]->Ptr,
- bytes,
- PIPE_BIND_VERTEX_BUFFER);
- vbuffers[attr].buffer_offset = 0;
- velements[attr].src_offset = 0;
- }
-
- /* common-case setup */
- vbuffers[attr].stride = arrays[mesaAttr]->StrideB; /* in bytes */
- velements[attr].instance_divisor = 0;
- velements[attr].vertex_buffer_index = attr;
- velements[attr].src_format =
- st_pipe_vertex_format(arrays[mesaAttr]->Type,
- arrays[mesaAttr]->Size,
- arrays[mesaAttr]->Format,
- arrays[mesaAttr]->Normalized);
- assert(velements[attr].src_format);
-
- /* tell draw about this attribute */
-#if 0
- draw_set_vertex_buffer(draw, attr, &vbuffer[attr]);
-#endif
-
- /* map the attrib buffer */
- map = pipe_buffer_map(pipe, vbuffers[attr].buffer,
- PIPE_TRANSFER_READ,
- &vb_transfer[attr]);
- draw_set_mapped_vertex_buffer(draw, attr, map);
- }
-
- draw_set_vertex_buffers(draw, vp->num_inputs, vbuffers);
- draw_set_vertex_elements(draw, vp->num_inputs, velements);
-
- memset(&ibuffer, 0, sizeof(ibuffer));
- if (ib) {
- struct gl_buffer_object *bufobj = ib->obj;
-
- switch (ib->type) {
- case GL_UNSIGNED_INT:
- ibuffer.index_size = 4;
- break;
- case GL_UNSIGNED_SHORT:
- ibuffer.index_size = 2;
- break;
- case GL_UNSIGNED_BYTE:
- ibuffer.index_size = 1;
- break;
- default:
- assert(0);
- goto out_unref_vertex;
- }
-
- if (bufobj && bufobj->Name) {
- struct st_buffer_object *stobj = st_buffer_object(bufobj);
-
- pipe_resource_reference(&ibuffer.buffer, stobj->buffer);
- ibuffer.offset = pointer_to_offset(ib->ptr);
-
- mapped_indices = pipe_buffer_map(pipe, stobj->buffer,
- PIPE_TRANSFER_READ, &ib_transfer);
- }
- else {
- /* skip setting ibuffer.buffer as the draw module does not use it */
- mapped_indices = ib->ptr;
- }
-
- draw_set_index_buffer(draw, &ibuffer);
- draw_set_mapped_index_buffer(draw, mapped_indices);
- }
-
- /* set the constant buffer */
- draw_set_mapped_constant_buffer(st->draw, PIPE_SHADER_VERTEX, 0,
- st->state.constants[PIPE_SHADER_VERTEX].ptr,
- st->state.constants[PIPE_SHADER_VERTEX].size);
-
-
- /* draw here */
- for (i = 0; i < nr_prims; i++) {
- draw_arrays(draw, prims[i].mode, prims[i].start, prims[i].count);
- }
-
-
- /*
- * unmap vertex/index buffers
- */
- if (ib) {
- draw_set_mapped_index_buffer(draw, NULL);
- draw_set_index_buffer(draw, NULL);
-
- if (ib_transfer)
- pipe_buffer_unmap(pipe, ib_transfer);
- pipe_resource_reference(&ibuffer.buffer, NULL);
- }
-
- out_unref_vertex:
- for (attr = 0; attr < vp->num_inputs; attr++) {
- pipe_buffer_unmap(pipe, vb_transfer[attr]);
- draw_set_mapped_vertex_buffer(draw, attr, NULL);
- pipe_resource_reference(&vbuffers[attr].buffer, NULL);
- }
- draw_set_vertex_buffers(draw, 0, NULL);
-}
-
-#endif /* FEATURE_feedback || FEATURE_rastpos */
-
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "main/imports.h"
+#include "main/image.h"
+#include "main/macros.h"
+#include "main/mfeatures.h"
+
+#include "vbo/vbo.h"
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_cb_bufferobjects.h"
+#include "st_draw.h"
+#include "st_program.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+
+#include "draw/draw_private.h"
+#include "draw/draw_context.h"
+
+
+#if FEATURE_feedback || FEATURE_rastpos
+
+/**
+ * Set the (private) draw module's post-transformed vertex format when in
+ * GL_SELECT or GL_FEEDBACK mode or for glRasterPos.
+ */
+static void
+set_feedback_vertex_format(struct gl_context *ctx)
+{
+#if 0
+ struct st_context *st = st_context(ctx);
+ struct vertex_info vinfo;
+ GLuint i;
+
+ memset(&vinfo, 0, sizeof(vinfo));
+
+ if (ctx->RenderMode == GL_SELECT) {
+ assert(ctx->RenderMode == GL_SELECT);
+ vinfo.num_attribs = 1;
+ vinfo.format[0] = FORMAT_4F;
+ vinfo.interp_mode[0] = INTERP_LINEAR;
+ }
+ else {
+ /* GL_FEEDBACK, or glRasterPos */
+ /* emit all attribs (pos, color, texcoord) as GLfloat[4] */
+ vinfo.num_attribs = st->state.vs->cso->state.num_outputs;
+ for (i = 0; i < vinfo.num_attribs; i++) {
+ vinfo.format[i] = FORMAT_4F;
+ vinfo.interp_mode[i] = INTERP_LINEAR;
+ }
+ }
+
+ draw_set_vertex_info(st->draw, &vinfo);
+#endif
+}
+
+
+/**
+ * Called by VBO to draw arrays when in selection or feedback mode and
+ * to implement glRasterPos.
+ * This is very much like the normal draw_vbo() function above.
+ * Look at code refactoring some day.
+ * Might move this into the failover module some day.
+ */
+void
+st_feedback_draw_vbo(struct gl_context *ctx,
+ const struct gl_client_array **arrays,
+ const struct _mesa_prim *prims,
+ GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLboolean index_bounds_valid,
+ GLuint min_index,
+ GLuint max_index)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
+ struct draw_context *draw = st->draw;
+ const struct st_vertex_program *vp;
+ const struct pipe_shader_state *vs;
+ struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS];
+ struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
+ struct pipe_index_buffer ibuffer;
+ struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS];
+ struct pipe_transfer *ib_transfer = NULL;
+ GLuint attr, i;
+ const void *mapped_indices = NULL;
+
+ assert(draw);
+
+ st_validate_state(st);
+
+ if (!index_bounds_valid)
+ vbo_get_minmax_index(ctx, prims, ib, &min_index, &max_index);
+
+ /* must get these after state validation! */
+ vp = st->vp;
+ vs = &st->vp_variant->tgsi;
+
+ if (!st->vp_variant->draw_shader) {
+ st->vp_variant->draw_shader = draw_create_vertex_shader(draw, vs);
+ }
+
+ /*
+ * Set up the draw module's state.
+ *
+ * We'd like to do this less frequently, but the normal state-update
+ * code sends state updates to the pipe, not to our private draw module.
+ */
+ assert(draw);
+ draw_set_viewport_state(draw, &st->state.viewport);
+ draw_set_clip_state(draw, &st->state.clip);
+ draw_set_rasterizer_state(draw, &st->state.rasterizer, NULL);
+ draw_bind_vertex_shader(draw, st->vp_variant->draw_shader);
+ set_feedback_vertex_format(ctx);
+
+ /* loop over TGSI shader inputs to determine vertex buffer
+ * and attribute info
+ */
+ for (attr = 0; attr < vp->num_inputs; attr++) {
+ const GLuint mesaAttr = vp->index_to_input[attr];
+ struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
+ void *map;
+
+ if (bufobj && bufobj->Name) {
+ /* Attribute data is in a VBO.
+ * Recall that for VBOs, the gl_client_array->Ptr field is
+ * really an offset from the start of the VBO, not a pointer.
+ */
+ struct st_buffer_object *stobj = st_buffer_object(bufobj);
+ assert(stobj->buffer);
+
+ vbuffers[attr].buffer = NULL;
+ pipe_resource_reference(&vbuffers[attr].buffer, stobj->buffer);
+ vbuffers[attr].buffer_offset = pointer_to_offset(arrays[0]->Ptr);
+ velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr;
+ }
+ else {
+ /* attribute data is in user-space memory, not a VBO */
+ uint bytes = (arrays[mesaAttr]->Size
+ * _mesa_sizeof_type(arrays[mesaAttr]->Type)
+ * (max_index + 1));
+
+ /* wrap user data */
+ vbuffers[attr].buffer
+ = pipe_user_buffer_create(pipe->screen, (void *) arrays[mesaAttr]->Ptr,
+ bytes,
+ PIPE_BIND_VERTEX_BUFFER);
+ vbuffers[attr].buffer_offset = 0;
+ velements[attr].src_offset = 0;
+ }
+
+ /* common-case setup */
+ vbuffers[attr].stride = arrays[mesaAttr]->StrideB; /* in bytes */
+ velements[attr].instance_divisor = 0;
+ velements[attr].vertex_buffer_index = attr;
+ velements[attr].src_format =
+ st_pipe_vertex_format(arrays[mesaAttr]->Type,
+ arrays[mesaAttr]->Size,
+ arrays[mesaAttr]->Format,
+ arrays[mesaAttr]->Normalized);
+ assert(velements[attr].src_format);
+
+ /* tell draw about this attribute */
+#if 0
+ draw_set_vertex_buffer(draw, attr, &vbuffer[attr]);
+#endif
+
+ /* map the attrib buffer */
+ map = pipe_buffer_map(pipe, vbuffers[attr].buffer,
+ PIPE_TRANSFER_READ,
+ &vb_transfer[attr]);
+ draw_set_mapped_vertex_buffer(draw, attr, map);
+ }
+
+ draw_set_vertex_buffers(draw, vp->num_inputs, vbuffers);
+ draw_set_vertex_elements(draw, vp->num_inputs, velements);
+
+ memset(&ibuffer, 0, sizeof(ibuffer));
+ if (ib) {
+ struct gl_buffer_object *bufobj = ib->obj;
+
+ switch (ib->type) {
+ case GL_UNSIGNED_INT:
+ ibuffer.index_size = 4;
+ break;
+ case GL_UNSIGNED_SHORT:
+ ibuffer.index_size = 2;
+ break;
+ case GL_UNSIGNED_BYTE:
+ ibuffer.index_size = 1;
+ break;
+ default:
+ assert(0);
+ goto out_unref_vertex;
+ }
+
+ if (bufobj && bufobj->Name) {
+ struct st_buffer_object *stobj = st_buffer_object(bufobj);
+
+ pipe_resource_reference(&ibuffer.buffer, stobj->buffer);
+ ibuffer.offset = pointer_to_offset(ib->ptr);
+
+ mapped_indices = pipe_buffer_map(pipe, stobj->buffer,
+ PIPE_TRANSFER_READ, &ib_transfer);
+ }
+ else {
+ /* skip setting ibuffer.buffer as the draw module does not use it */
+ mapped_indices = ib->ptr;
+ }
+
+ draw_set_index_buffer(draw, &ibuffer);
+ draw_set_mapped_index_buffer(draw, mapped_indices);
+ }
+
+ /* set the constant buffer */
+ draw_set_mapped_constant_buffer(st->draw, PIPE_SHADER_VERTEX, 0,
+ st->state.constants[PIPE_SHADER_VERTEX].ptr,
+ st->state.constants[PIPE_SHADER_VERTEX].size);
+
+
+ /* draw here */
+ for (i = 0; i < nr_prims; i++) {
+ draw_arrays(draw, prims[i].mode, prims[i].start, prims[i].count);
+ }
+
+
+ /*
+ * unmap vertex/index buffers
+ */
+ if (ib) {
+ draw_set_mapped_index_buffer(draw, NULL);
+ draw_set_index_buffer(draw, NULL);
+
+ if (ib_transfer)
+ pipe_buffer_unmap(pipe, ib_transfer);
+ pipe_resource_reference(&ibuffer.buffer, NULL);
+ }
+
+ out_unref_vertex:
+ for (attr = 0; attr < vp->num_inputs; attr++) {
+ pipe_buffer_unmap(pipe, vb_transfer[attr]);
+ draw_set_mapped_vertex_buffer(draw, attr, NULL);
+ pipe_resource_reference(&vbuffers[attr].buffer, NULL);
+ }
+ draw_set_vertex_buffers(draw, 0, NULL);
+}
+
+#endif /* FEATURE_feedback || FEATURE_rastpos */
+
diff --git a/mesalib/src/mesa/state_tracker/st_extensions.c b/mesalib/src/mesa/state_tracker/st_extensions.c
index d2098987d..71c6c9252 100644
--- a/mesalib/src/mesa/state_tracker/st_extensions.c
+++ b/mesalib/src/mesa/state_tracker/st_extensions.c
@@ -1,498 +1,498 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * Copyright (c) 2008 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#include "main/imports.h"
-#include "main/context.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_screen.h"
-
-#include "st_context.h"
-#include "st_extensions.h"
-
-
-static int _min(int a, int b)
-{
- return (a < b) ? a : b;
-}
-
-static float _maxf(float a, float b)
-{
- return (a > b) ? a : b;
-}
-
-static int _clamp(int a, int min, int max)
-{
- if (a < min)
- return min;
- else if (a > max)
- return max;
- else
- return a;
-}
-
-
-/**
- * Query driver to get implementation limits.
- * Note that we have to limit/clamp against Mesa's internal limits too.
- */
-void st_init_limits(struct st_context *st)
-{
- struct pipe_screen *screen = st->pipe->screen;
- struct gl_constants *c = &st->ctx->Const;
- gl_shader_type sh;
-
- c->MaxTextureLevels
- = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
- MAX_TEXTURE_LEVELS);
-
- c->Max3DTextureLevels
- = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS),
- MAX_3D_TEXTURE_LEVELS);
-
- c->MaxCubeTextureLevels
- = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS),
- MAX_CUBE_TEXTURE_LEVELS);
-
- c->MaxTextureRectSize
- = _min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE);
-
- c->MaxTextureImageUnits
- = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS),
- MAX_TEXTURE_IMAGE_UNITS);
-
- c->MaxVertexTextureImageUnits
- = _min(screen->get_param(screen, PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS),
- MAX_VERTEX_TEXTURE_IMAGE_UNITS);
-
- c->MaxCombinedTextureImageUnits
- = _min(screen->get_param(screen, PIPE_CAP_MAX_COMBINED_SAMPLERS),
- MAX_COMBINED_TEXTURE_IMAGE_UNITS);
-
- c->MaxTextureCoordUnits
- = _min(c->MaxTextureImageUnits, MAX_TEXTURE_COORD_UNITS);
-
- c->MaxTextureUnits = _min(c->MaxTextureImageUnits, c->MaxTextureCoordUnits);
-
- c->MaxDrawBuffers
- = _clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
- 1, MAX_DRAW_BUFFERS);
-
- c->MaxLineWidth
- = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH));
- c->MaxLineWidthAA
- = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH_AA));
-
- c->MaxPointSize
- = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH));
- c->MaxPointSizeAA
- = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH_AA));
- /* called after _mesa_create_context/_mesa_init_point, fix default user
- * settable max point size up
- */
- st->ctx->Point.MaxSize = MAX2(c->MaxPointSize, c->MaxPointSizeAA);
- /* these are not queryable. Note that GL basically mandates a 1.0 minimum
- * for non-aa sizes, but we can go down to 0.0 for aa points.
- */
- c->MinPointSize = 1.0f;
- c->MinPointSizeAA = 0.0f;
-
- c->MaxTextureMaxAnisotropy
- = _maxf(2.0f, screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_ANISOTROPY));
-
- c->MaxTextureLodBias
- = screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_LOD_BIAS);
-
- c->MaxDrawBuffers
- = CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
- 1, MAX_DRAW_BUFFERS);
-
- /* Quads always follow GL provoking rules. */
- c->QuadsFollowProvokingVertexConvention = GL_FALSE;
-
- for (sh = 0; sh < MESA_SHADER_TYPES; ++sh) {
- struct gl_shader_compiler_options *options =
- &st->ctx->ShaderCompilerOptions[sh];
- struct gl_program_constants *pc;
-
- switch (sh) {
- case PIPE_SHADER_FRAGMENT:
- pc = &c->FragmentProgram;
- break;
- case PIPE_SHADER_VERTEX:
- pc = &c->VertexProgram;
- break;
- case PIPE_SHADER_GEOMETRY:
- pc = &c->GeometryProgram;
- break;
- default:
- assert(0);
- continue;
- }
-
- pc->MaxNativeInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
- pc->MaxNativeAluInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS);
- pc->MaxNativeTexInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS);
- pc->MaxNativeTexIndirections = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS);
- pc->MaxNativeAttribs = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS);
- pc->MaxNativeTemps = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEMPS);
- pc->MaxNativeAddressRegs = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ADDRS);
- pc->MaxNativeParameters = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONSTS);
- pc->MaxUniformComponents = 4 * MIN2(pc->MaxNativeParameters, MAX_UNIFORMS);
-
- options->EmitNoNoise = TRUE;
-
- /* TODO: make these more fine-grained if anyone needs it */
- options->EmitNoIfs = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
- options->EmitNoLoops = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
- options->EmitNoFunctions = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
- options->EmitNoMainReturn = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
-
- options->EmitNoCont = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED);
-
- options->EmitNoIndirectInput = !screen->get_shader_param(screen, sh,
- PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR);
- options->EmitNoIndirectOutput = !screen->get_shader_param(screen, sh,
- PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR);
- options->EmitNoIndirectTemp = !screen->get_shader_param(screen, sh,
- PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR);
- options->EmitNoIndirectUniform = !screen->get_shader_param(screen, sh,
- PIPE_SHADER_CAP_INDIRECT_CONST_ADDR);
-
- if(options->EmitNoLoops)
- options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536);
- }
-
- /* PIPE_CAP_MAX_FS_INPUTS specifies the number of COLORn + GENERICn inputs
- * and is set in MaxNativeAttribs. It's always 2 colors + N generic
- * attributes. The GLSL compiler never uses COLORn for varyings, so we
- * subtract the 2 colors to get the maximum number of varyings (generic
- * attributes) supported by a driver. */
- c->MaxVarying = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_MAX_INPUTS) - 2;
- c->MaxVarying = MIN2(c->MaxVarying, MAX_VARYING);
-
- /* XXX we'll need a better query here someday */
- if (screen->get_param(screen, PIPE_CAP_GLSL)) {
- c->GLSLVersion = 120;
- }
-}
-
-
-/**
- * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
- * which GL extensions are supported.
- * Quite a few extensions are always supported because they are standard
- * features or can be built on top of other gallium features.
- * Some fine tuning may still be needed.
- */
-void st_init_extensions(struct st_context *st)
-{
- struct pipe_screen *screen = st->pipe->screen;
- struct gl_context *ctx = st->ctx;
-
- /*
- * Extensions that are supported by all Gallium drivers:
- */
- ctx->Extensions.ARB_copy_buffer = GL_TRUE;
- ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
- ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
- ctx->Extensions.ARB_fragment_program = GL_TRUE;
- ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
- ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
- ctx->Extensions.ARB_multisample = GL_TRUE;
- ctx->Extensions.ARB_texture_border_clamp = GL_TRUE; /* XXX temp */
- ctx->Extensions.ARB_texture_compression = GL_TRUE;
- ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
- ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
- ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
- ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
- ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
- ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;
- ctx->Extensions.ARB_vertex_program = GL_TRUE;
- ctx->Extensions.ARB_window_pos = GL_TRUE;
-
- ctx->Extensions.EXT_blend_color = GL_TRUE;
- ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
- ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
- ctx->Extensions.EXT_blend_minmax = GL_TRUE;
- ctx->Extensions.EXT_blend_subtract = GL_TRUE;
- ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
- ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
- ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
- ctx->Extensions.EXT_fog_coord = GL_TRUE;
- ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
- ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;
- ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
- ctx->Extensions.EXT_point_parameters = GL_TRUE;
- ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
- ctx->Extensions.EXT_secondary_color = GL_TRUE;
- ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
- ctx->Extensions.EXT_texture_env_add = GL_TRUE;
- ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
- ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
- ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
- ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
- if (ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2)
- ctx->Extensions.EXT_texture_format_BGRA8888 = GL_TRUE;
-
- ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
-
- ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
-
- ctx->Extensions.MESA_pack_invert = GL_TRUE;
-
- ctx->Extensions.NV_blend_square = GL_TRUE;
- ctx->Extensions.NV_texgen_reflection = GL_TRUE;
- ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
- ctx->Extensions.NV_texture_rectangle = GL_TRUE;
-#if 0
- /* possibly could support the following two */
- ctx->Extensions.NV_vertex_program = GL_TRUE;
- ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
-#endif
-
-#if FEATURE_OES_EGL_image
- ctx->Extensions.OES_EGL_image = GL_TRUE;
-#endif
-#if FEATURE_OES_draw_texture
- ctx->Extensions.OES_draw_texture = GL_TRUE;
-#endif
-
- ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
-
- /*
- * Extensions that depend on the driver/hardware:
- */
- if (screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS) > 0) {
- ctx->Extensions.ARB_draw_buffers = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_TEXTURE_SWIZZLE) > 0) {
- ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_GLSL)) {
- ctx->Extensions.ARB_fragment_shader = GL_TRUE;
- ctx->Extensions.ARB_vertex_shader = GL_TRUE;
- ctx->Extensions.ARB_shader_objects = GL_TRUE;
- ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
- ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
- ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_TEXTURE_MIRROR_REPEAT) > 0) {
- ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_BLEND_EQUATION_SEPARATE)) {
- ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_TEXTURE_MIRROR_CLAMP) > 0) {
- ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
- ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) {
- ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS) > 1) {
- ctx->Extensions.ARB_multitexture = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_TWO_SIDED_STENCIL)) {
- ctx->Extensions.ATI_separate_stencil = GL_TRUE;
- ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_ANISOTROPIC_FILTER)) {
- ctx->Extensions.EXT_texture_filter_anisotropic = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_POINT_SPRITE)) {
- ctx->Extensions.ARB_point_sprite = GL_TRUE;
- /* GL_NV_point_sprite is not supported by gallium because we don't
- * support the GL_POINT_SPRITE_R_MODE_NV option.
- */
- }
-
- if (screen->get_param(screen, PIPE_CAP_OCCLUSION_QUERY)) {
- ctx->Extensions.ARB_occlusion_query = GL_TRUE;
- ctx->Extensions.ARB_occlusion_query2 = GL_TRUE;
- }
- if (screen->get_param(screen, PIPE_CAP_TIMER_QUERY)) {
- ctx->Extensions.EXT_timer_query = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_TEXTURE_SHADOW_MAP)) {
- ctx->Extensions.ARB_depth_texture = GL_TRUE;
- ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
- ctx->Extensions.ARB_shadow = GL_TRUE;
- ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
- /*ctx->Extensions.ARB_shadow_ambient = GL_TRUE;*/
- }
-
- /* GL_EXT_packed_depth_stencil requires both the ability to render to
- * a depth/stencil buffer and texture from depth/stencil source.
- */
- if (screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_DEPTH_STENCIL, 0) &&
- screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0)) {
- ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
- }
- else if (screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_DEPTH_STENCIL, 0) &&
- screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0)) {
- ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
- }
-
- /* sRGB support */
- if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0) ||
- screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0)) {
- ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
- ctx->Extensions.EXT_texture_sRGB_decode = GL_TRUE;
- if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET, 0) ||
- screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET, 0)) {
- ctx->Extensions.EXT_framebuffer_sRGB = GL_TRUE;
- ctx->Const.sRGBCapable = GL_TRUE;
- }
- }
-
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0)) {
- ctx->Extensions.ARB_texture_rg = GL_TRUE;
- }
-
- /* s3tc support */
- if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0) &&
- ctx->Mesa_DXTn) {
- ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE;
- ctx->Extensions.S3_s3tc = GL_TRUE;
- }
-
- if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0) &&
- screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_SNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0) &&
- screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0) &&
- screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_SNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0)
- ) {
- ctx->Extensions.ARB_texture_compression_rgtc = GL_TRUE;
- }
-
- /* ycbcr support */
- if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0) ||
- screen->is_format_supported(screen, PIPE_FORMAT_YUYV,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW, 0)) {
- ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
- }
-
- /* GL_EXT_texture_array */
- if (screen->get_param(screen, PIPE_CAP_ARRAY_TEXTURES)) {
- ctx->Extensions.EXT_texture_array = GL_TRUE;
- ctx->Extensions.MESA_texture_array = GL_TRUE;
- }
-
- /* GL_ARB_framebuffer_object */
- if (ctx->Extensions.EXT_packed_depth_stencil) {
- /* we support always support GL_EXT_framebuffer_blit */
- ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
- }
-
- if (st->pipe->render_condition) {
- ctx->Extensions.NV_conditional_render = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_INDEP_BLEND_ENABLE)) {
- ctx->Extensions.EXT_draw_buffers2 = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_INDEP_BLEND_FUNC)) {
- ctx->Extensions.ARB_draw_buffers_blend = GL_TRUE;
- }
-
- /* GL_ARB_half_float_vertex */
- if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_BUFFER, 0,
- PIPE_BIND_VERTEX_BUFFER, 0)) {
- ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
- }
-
- if (screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY, PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
-#if 0 /* XXX re-enable when GLSL compiler again supports geometry shaders */
- ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
-#endif
- }
-
- if (screen->get_param(screen, PIPE_CAP_PRIMITIVE_RESTART)) {
- ctx->Extensions.NV_primitive_restart = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_DEPTH_CLAMP)) {
- ctx->Extensions.ARB_depth_clamp = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT)) {
- ctx->Extensions.ARB_shader_stencil_export = GL_TRUE;
- }
-
- if (screen->get_param(screen, PIPE_CAP_INSTANCED_DRAWING)) {
- ctx->Extensions.ARB_draw_instanced = GL_TRUE;
- ctx->Extensions.ARB_instanced_arrays = GL_TRUE;
- }
-}
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright (c) 2008 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "main/imports.h"
+#include "main/context.h"
+#include "main/macros.h"
+#include "main/mfeatures.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_screen.h"
+
+#include "st_context.h"
+#include "st_extensions.h"
+
+
+static int _min(int a, int b)
+{
+ return (a < b) ? a : b;
+}
+
+static float _maxf(float a, float b)
+{
+ return (a > b) ? a : b;
+}
+
+static int _clamp(int a, int min, int max)
+{
+ if (a < min)
+ return min;
+ else if (a > max)
+ return max;
+ else
+ return a;
+}
+
+
+/**
+ * Query driver to get implementation limits.
+ * Note that we have to limit/clamp against Mesa's internal limits too.
+ */
+void st_init_limits(struct st_context *st)
+{
+ struct pipe_screen *screen = st->pipe->screen;
+ struct gl_constants *c = &st->ctx->Const;
+ gl_shader_type sh;
+
+ c->MaxTextureLevels
+ = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
+ MAX_TEXTURE_LEVELS);
+
+ c->Max3DTextureLevels
+ = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS),
+ MAX_3D_TEXTURE_LEVELS);
+
+ c->MaxCubeTextureLevels
+ = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS),
+ MAX_CUBE_TEXTURE_LEVELS);
+
+ c->MaxTextureRectSize
+ = _min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE);
+
+ c->MaxTextureImageUnits
+ = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS),
+ MAX_TEXTURE_IMAGE_UNITS);
+
+ c->MaxVertexTextureImageUnits
+ = _min(screen->get_param(screen, PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS),
+ MAX_VERTEX_TEXTURE_IMAGE_UNITS);
+
+ c->MaxCombinedTextureImageUnits
+ = _min(screen->get_param(screen, PIPE_CAP_MAX_COMBINED_SAMPLERS),
+ MAX_COMBINED_TEXTURE_IMAGE_UNITS);
+
+ c->MaxTextureCoordUnits
+ = _min(c->MaxTextureImageUnits, MAX_TEXTURE_COORD_UNITS);
+
+ c->MaxTextureUnits = _min(c->MaxTextureImageUnits, c->MaxTextureCoordUnits);
+
+ c->MaxDrawBuffers
+ = _clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
+ 1, MAX_DRAW_BUFFERS);
+
+ c->MaxLineWidth
+ = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH));
+ c->MaxLineWidthAA
+ = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH_AA));
+
+ c->MaxPointSize
+ = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH));
+ c->MaxPointSizeAA
+ = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH_AA));
+ /* called after _mesa_create_context/_mesa_init_point, fix default user
+ * settable max point size up
+ */
+ st->ctx->Point.MaxSize = MAX2(c->MaxPointSize, c->MaxPointSizeAA);
+ /* these are not queryable. Note that GL basically mandates a 1.0 minimum
+ * for non-aa sizes, but we can go down to 0.0 for aa points.
+ */
+ c->MinPointSize = 1.0f;
+ c->MinPointSizeAA = 0.0f;
+
+ c->MaxTextureMaxAnisotropy
+ = _maxf(2.0f, screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_ANISOTROPY));
+
+ c->MaxTextureLodBias
+ = screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_LOD_BIAS);
+
+ c->MaxDrawBuffers
+ = CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
+ 1, MAX_DRAW_BUFFERS);
+
+ /* Quads always follow GL provoking rules. */
+ c->QuadsFollowProvokingVertexConvention = GL_FALSE;
+
+ for (sh = 0; sh < MESA_SHADER_TYPES; ++sh) {
+ struct gl_shader_compiler_options *options =
+ &st->ctx->ShaderCompilerOptions[sh];
+ struct gl_program_constants *pc;
+
+ switch (sh) {
+ case PIPE_SHADER_FRAGMENT:
+ pc = &c->FragmentProgram;
+ break;
+ case PIPE_SHADER_VERTEX:
+ pc = &c->VertexProgram;
+ break;
+ case PIPE_SHADER_GEOMETRY:
+ pc = &c->GeometryProgram;
+ break;
+ default:
+ assert(0);
+ continue;
+ }
+
+ pc->MaxNativeInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
+ pc->MaxNativeAluInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS);
+ pc->MaxNativeTexInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS);
+ pc->MaxNativeTexIndirections = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS);
+ pc->MaxNativeAttribs = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS);
+ pc->MaxNativeTemps = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEMPS);
+ pc->MaxNativeAddressRegs = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ADDRS);
+ pc->MaxNativeParameters = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONSTS);
+ pc->MaxUniformComponents = 4 * MIN2(pc->MaxNativeParameters, MAX_UNIFORMS);
+
+ options->EmitNoNoise = TRUE;
+
+ /* TODO: make these more fine-grained if anyone needs it */
+ options->EmitNoIfs = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
+ options->EmitNoLoops = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
+ options->EmitNoFunctions = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
+ options->EmitNoMainReturn = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
+
+ options->EmitNoCont = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED);
+
+ options->EmitNoIndirectInput = !screen->get_shader_param(screen, sh,
+ PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR);
+ options->EmitNoIndirectOutput = !screen->get_shader_param(screen, sh,
+ PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR);
+ options->EmitNoIndirectTemp = !screen->get_shader_param(screen, sh,
+ PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR);
+ options->EmitNoIndirectUniform = !screen->get_shader_param(screen, sh,
+ PIPE_SHADER_CAP_INDIRECT_CONST_ADDR);
+
+ if(options->EmitNoLoops)
+ options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536);
+ }
+
+ /* PIPE_CAP_MAX_FS_INPUTS specifies the number of COLORn + GENERICn inputs
+ * and is set in MaxNativeAttribs. It's always 2 colors + N generic
+ * attributes. The GLSL compiler never uses COLORn for varyings, so we
+ * subtract the 2 colors to get the maximum number of varyings (generic
+ * attributes) supported by a driver. */
+ c->MaxVarying = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_MAX_INPUTS) - 2;
+ c->MaxVarying = MIN2(c->MaxVarying, MAX_VARYING);
+
+ /* XXX we'll need a better query here someday */
+ if (screen->get_param(screen, PIPE_CAP_GLSL)) {
+ c->GLSLVersion = 120;
+ }
+}
+
+
+/**
+ * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
+ * which GL extensions are supported.
+ * Quite a few extensions are always supported because they are standard
+ * features or can be built on top of other gallium features.
+ * Some fine tuning may still be needed.
+ */
+void st_init_extensions(struct st_context *st)
+{
+ struct pipe_screen *screen = st->pipe->screen;
+ struct gl_context *ctx = st->ctx;
+
+ /*
+ * Extensions that are supported by all Gallium drivers:
+ */
+ ctx->Extensions.ARB_copy_buffer = GL_TRUE;
+ ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
+ ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
+ ctx->Extensions.ARB_fragment_program = GL_TRUE;
+ ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
+ ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
+ ctx->Extensions.ARB_multisample = GL_TRUE;
+ ctx->Extensions.ARB_texture_border_clamp = GL_TRUE; /* XXX temp */
+ ctx->Extensions.ARB_texture_compression = GL_TRUE;
+ ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
+ ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
+ ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
+ ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
+ ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
+ ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;
+ ctx->Extensions.ARB_vertex_program = GL_TRUE;
+ ctx->Extensions.ARB_window_pos = GL_TRUE;
+
+ ctx->Extensions.EXT_blend_color = GL_TRUE;
+ ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
+ ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
+ ctx->Extensions.EXT_blend_minmax = GL_TRUE;
+ ctx->Extensions.EXT_blend_subtract = GL_TRUE;
+ ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
+ ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
+ ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
+ ctx->Extensions.EXT_fog_coord = GL_TRUE;
+ ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
+ ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;
+ ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
+ ctx->Extensions.EXT_point_parameters = GL_TRUE;
+ ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
+ ctx->Extensions.EXT_secondary_color = GL_TRUE;
+ ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
+ ctx->Extensions.EXT_texture_env_add = GL_TRUE;
+ ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
+ ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
+ ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
+ ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
+ if (ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2)
+ ctx->Extensions.EXT_texture_format_BGRA8888 = GL_TRUE;
+
+ ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
+
+ ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
+
+ ctx->Extensions.MESA_pack_invert = GL_TRUE;
+
+ ctx->Extensions.NV_blend_square = GL_TRUE;
+ ctx->Extensions.NV_texgen_reflection = GL_TRUE;
+ ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
+ ctx->Extensions.NV_texture_rectangle = GL_TRUE;
+#if 0
+ /* possibly could support the following two */
+ ctx->Extensions.NV_vertex_program = GL_TRUE;
+ ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
+#endif
+
+#if FEATURE_OES_EGL_image
+ ctx->Extensions.OES_EGL_image = GL_TRUE;
+#endif
+#if FEATURE_OES_draw_texture
+ ctx->Extensions.OES_draw_texture = GL_TRUE;
+#endif
+
+ ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
+
+ /*
+ * Extensions that depend on the driver/hardware:
+ */
+ if (screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS) > 0) {
+ ctx->Extensions.ARB_draw_buffers = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_TEXTURE_SWIZZLE) > 0) {
+ ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_GLSL)) {
+ ctx->Extensions.ARB_fragment_shader = GL_TRUE;
+ ctx->Extensions.ARB_vertex_shader = GL_TRUE;
+ ctx->Extensions.ARB_shader_objects = GL_TRUE;
+ ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
+ ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
+ ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_TEXTURE_MIRROR_REPEAT) > 0) {
+ ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_BLEND_EQUATION_SEPARATE)) {
+ ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_TEXTURE_MIRROR_CLAMP) > 0) {
+ ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
+ ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) {
+ ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS) > 1) {
+ ctx->Extensions.ARB_multitexture = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_TWO_SIDED_STENCIL)) {
+ ctx->Extensions.ATI_separate_stencil = GL_TRUE;
+ ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_ANISOTROPIC_FILTER)) {
+ ctx->Extensions.EXT_texture_filter_anisotropic = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_POINT_SPRITE)) {
+ ctx->Extensions.ARB_point_sprite = GL_TRUE;
+ /* GL_NV_point_sprite is not supported by gallium because we don't
+ * support the GL_POINT_SPRITE_R_MODE_NV option.
+ */
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_OCCLUSION_QUERY)) {
+ ctx->Extensions.ARB_occlusion_query = GL_TRUE;
+ ctx->Extensions.ARB_occlusion_query2 = GL_TRUE;
+ }
+ if (screen->get_param(screen, PIPE_CAP_TIMER_QUERY)) {
+ ctx->Extensions.EXT_timer_query = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_TEXTURE_SHADOW_MAP)) {
+ ctx->Extensions.ARB_depth_texture = GL_TRUE;
+ ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
+ ctx->Extensions.ARB_shadow = GL_TRUE;
+ ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
+ /*ctx->Extensions.ARB_shadow_ambient = GL_TRUE;*/
+ }
+
+ /* GL_EXT_packed_depth_stencil requires both the ability to render to
+ * a depth/stencil buffer and texture from depth/stencil source.
+ */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_DEPTH_STENCIL, 0) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
+ ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
+ }
+ else if (screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_DEPTH_STENCIL, 0) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
+ ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
+ }
+
+ /* sRGB support */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0) ||
+ screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
+ ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
+ ctx->Extensions.EXT_texture_sRGB_decode = GL_TRUE;
+ if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET, 0) ||
+ screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET, 0)) {
+ ctx->Extensions.EXT_framebuffer_sRGB = GL_TRUE;
+ ctx->Const.sRGBCapable = GL_TRUE;
+ }
+ }
+
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
+ ctx->Extensions.ARB_texture_rg = GL_TRUE;
+ }
+
+ /* s3tc support */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0) &&
+ ctx->Mesa_DXTn) {
+ ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE;
+ ctx->Extensions.S3_s3tc = GL_TRUE;
+ }
+
+ if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_SNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_SNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)
+ ) {
+ ctx->Extensions.ARB_texture_compression_rgtc = GL_TRUE;
+ }
+
+ /* ycbcr support */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0) ||
+ screen->is_format_supported(screen, PIPE_FORMAT_YUYV,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
+ ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
+ }
+
+ /* GL_EXT_texture_array */
+ if (screen->get_param(screen, PIPE_CAP_ARRAY_TEXTURES)) {
+ ctx->Extensions.EXT_texture_array = GL_TRUE;
+ ctx->Extensions.MESA_texture_array = GL_TRUE;
+ }
+
+ /* GL_ARB_framebuffer_object */
+ if (ctx->Extensions.EXT_packed_depth_stencil) {
+ /* we support always support GL_EXT_framebuffer_blit */
+ ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
+ }
+
+ if (st->pipe->render_condition) {
+ ctx->Extensions.NV_conditional_render = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_INDEP_BLEND_ENABLE)) {
+ ctx->Extensions.EXT_draw_buffers2 = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_INDEP_BLEND_FUNC)) {
+ ctx->Extensions.ARB_draw_buffers_blend = GL_TRUE;
+ }
+
+ /* GL_ARB_half_float_vertex */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_BUFFER, 0,
+ PIPE_BIND_VERTEX_BUFFER, 0)) {
+ ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
+ }
+
+ if (screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY, PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
+#if 0 /* XXX re-enable when GLSL compiler again supports geometry shaders */
+ ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
+#endif
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_PRIMITIVE_RESTART)) {
+ ctx->Extensions.NV_primitive_restart = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_DEPTH_CLAMP)) {
+ ctx->Extensions.ARB_depth_clamp = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT)) {
+ ctx->Extensions.ARB_shader_stencil_export = GL_TRUE;
+ }
+
+ if (screen->get_param(screen, PIPE_CAP_INSTANCED_DRAWING)) {
+ ctx->Extensions.ARB_draw_instanced = GL_TRUE;
+ ctx->Extensions.ARB_instanced_arrays = GL_TRUE;
+ }
+}
diff --git a/mesalib/src/mesa/state_tracker/st_format.c b/mesalib/src/mesa/state_tracker/st_format.c
index 22a1450cf..1adfdf72c 100644
--- a/mesalib/src/mesa/state_tracker/st_format.c
+++ b/mesalib/src/mesa/state_tracker/st_format.c
@@ -1,1172 +1,1172 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * Copyright (c) 2008-2010 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-/**
- * Mesa / Gallium format conversion and format selection code.
- * \author Brian Paul
- */
-
-#include "main/imports.h"
-#include "main/context.h"
-#include "main/texstore.h"
-#include "main/image.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_screen.h"
-#include "util/u_format.h"
-#include "st_context.h"
-#include "st_format.h"
-
-
-static GLuint
-format_max_bits(enum pipe_format format)
-{
- GLuint size = util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0);
-
- size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 1));
- size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 2));
- size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 3));
- size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 0));
- size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1));
- return size;
-}
-
-
-/**
- * Return basic GL datatype for the given gallium format.
- */
-GLenum
-st_format_datatype(enum pipe_format format)
-{
- const struct util_format_description *desc;
-
- desc = util_format_description(format);
- assert(desc);
-
- if (desc->layout == UTIL_FORMAT_LAYOUT_PLAIN) {
- if (format == PIPE_FORMAT_B5G5R5A1_UNORM ||
- format == PIPE_FORMAT_B5G6R5_UNORM) {
- return GL_UNSIGNED_SHORT;
- }
- else if (format == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
- format == PIPE_FORMAT_S8_USCALED_Z24_UNORM ||
- format == PIPE_FORMAT_Z24X8_UNORM ||
- format == PIPE_FORMAT_X8Z24_UNORM) {
- return GL_UNSIGNED_INT_24_8;
- }
- else {
- const GLuint size = format_max_bits(format);
- if (size == 8) {
- if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED)
- return GL_UNSIGNED_BYTE;
- else
- return GL_BYTE;
- }
- else if (size == 16) {
- if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED)
- return GL_UNSIGNED_SHORT;
- else
- return GL_SHORT;
- }
- else {
- assert( size <= 32 );
- if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED)
- return GL_UNSIGNED_INT;
- else
- return GL_INT;
- }
- }
- }
- else if (format == PIPE_FORMAT_UYVY) {
- return GL_UNSIGNED_SHORT;
- }
- else if (format == PIPE_FORMAT_YUYV) {
- return GL_UNSIGNED_SHORT;
- }
- else {
- /* probably a compressed format, unsupported anyway */
- return GL_NONE;
- }
-}
-
-
-/**
- * Translate Mesa format to Gallium format.
- */
-enum pipe_format
-st_mesa_format_to_pipe_format(gl_format mesaFormat)
-{
- switch (mesaFormat) {
- case MESA_FORMAT_RGBA8888:
- return PIPE_FORMAT_A8B8G8R8_UNORM;
- case MESA_FORMAT_RGBA8888_REV:
- return PIPE_FORMAT_R8G8B8A8_UNORM;
- case MESA_FORMAT_ARGB8888:
- return PIPE_FORMAT_B8G8R8A8_UNORM;
- case MESA_FORMAT_ARGB8888_REV:
- return PIPE_FORMAT_A8R8G8B8_UNORM;
- case MESA_FORMAT_XRGB8888:
- return PIPE_FORMAT_B8G8R8X8_UNORM;
- case MESA_FORMAT_XRGB8888_REV:
- return PIPE_FORMAT_X8R8G8B8_UNORM;
- case MESA_FORMAT_ARGB1555:
- return PIPE_FORMAT_B5G5R5A1_UNORM;
- case MESA_FORMAT_ARGB4444:
- return PIPE_FORMAT_B4G4R4A4_UNORM;
- case MESA_FORMAT_RGB565:
- return PIPE_FORMAT_B5G6R5_UNORM;
- case MESA_FORMAT_RGB332:
- return PIPE_FORMAT_B2G3R3_UNORM;
- case MESA_FORMAT_ARGB2101010:
- return PIPE_FORMAT_B10G10R10A2_UNORM;
- case MESA_FORMAT_AL44:
- return PIPE_FORMAT_L4A4_UNORM;
- case MESA_FORMAT_AL88:
- return PIPE_FORMAT_L8A8_UNORM;
- case MESA_FORMAT_AL1616:
- return PIPE_FORMAT_L16A16_UNORM;
- case MESA_FORMAT_A8:
- return PIPE_FORMAT_A8_UNORM;
- case MESA_FORMAT_A16:
- return PIPE_FORMAT_A16_UNORM;
- case MESA_FORMAT_L8:
- return PIPE_FORMAT_L8_UNORM;
- case MESA_FORMAT_L16:
- return PIPE_FORMAT_L16_UNORM;
- case MESA_FORMAT_I8:
- return PIPE_FORMAT_I8_UNORM;
- case MESA_FORMAT_I16:
- return PIPE_FORMAT_I16_UNORM;
- case MESA_FORMAT_Z16:
- return PIPE_FORMAT_Z16_UNORM;
- case MESA_FORMAT_Z32:
- return PIPE_FORMAT_Z32_UNORM;
- case MESA_FORMAT_Z24_S8:
- return PIPE_FORMAT_S8_USCALED_Z24_UNORM;
- case MESA_FORMAT_S8_Z24:
- return PIPE_FORMAT_Z24_UNORM_S8_USCALED;
- case MESA_FORMAT_Z24_X8:
- return PIPE_FORMAT_X8Z24_UNORM;
- case MESA_FORMAT_X8_Z24:
- return PIPE_FORMAT_Z24X8_UNORM;
- case MESA_FORMAT_S8:
- return PIPE_FORMAT_S8_USCALED;
- case MESA_FORMAT_YCBCR:
- return PIPE_FORMAT_UYVY;
-#if FEATURE_texture_s3tc
- case MESA_FORMAT_RGB_DXT1:
- return PIPE_FORMAT_DXT1_RGB;
- case MESA_FORMAT_RGBA_DXT1:
- return PIPE_FORMAT_DXT1_RGBA;
- case MESA_FORMAT_RGBA_DXT3:
- return PIPE_FORMAT_DXT3_RGBA;
- case MESA_FORMAT_RGBA_DXT5:
- return PIPE_FORMAT_DXT5_RGBA;
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SRGB_DXT1:
- return PIPE_FORMAT_DXT1_SRGB;
- case MESA_FORMAT_SRGBA_DXT1:
- return PIPE_FORMAT_DXT1_SRGBA;
- case MESA_FORMAT_SRGBA_DXT3:
- return PIPE_FORMAT_DXT3_SRGBA;
- case MESA_FORMAT_SRGBA_DXT5:
- return PIPE_FORMAT_DXT5_SRGBA;
-#endif
-#endif
-#if FEATURE_EXT_texture_sRGB
- case MESA_FORMAT_SLA8:
- return PIPE_FORMAT_L8A8_SRGB;
- case MESA_FORMAT_SL8:
- return PIPE_FORMAT_L8_SRGB;
- case MESA_FORMAT_SRGB8:
- return PIPE_FORMAT_R8G8B8_SRGB;
- case MESA_FORMAT_SRGBA8:
- return PIPE_FORMAT_A8B8G8R8_SRGB;
- case MESA_FORMAT_SARGB8:
- return PIPE_FORMAT_B8G8R8A8_SRGB;
-#endif
- case MESA_FORMAT_R8:
- return PIPE_FORMAT_R8_UNORM;
- case MESA_FORMAT_R16:
- return PIPE_FORMAT_R16_UNORM;
- case MESA_FORMAT_RG88:
- return PIPE_FORMAT_R8G8_UNORM;
- case MESA_FORMAT_RG1616:
- return PIPE_FORMAT_R16G16_UNORM;
- case MESA_FORMAT_RGBA_16:
- return PIPE_FORMAT_R16G16B16A16_UNORM;
-
- /* signed int formats */
- case MESA_FORMAT_RGBA_INT8:
- return PIPE_FORMAT_R8G8B8A8_SSCALED;
- case MESA_FORMAT_RGBA_INT16:
- return PIPE_FORMAT_R16G16B16A16_SSCALED;
- case MESA_FORMAT_RGBA_INT32:
- return PIPE_FORMAT_R32G32B32A32_SSCALED;
-
- /* unsigned int formats */
- case MESA_FORMAT_RGBA_UINT8:
- return PIPE_FORMAT_R8G8B8A8_USCALED;
- case MESA_FORMAT_RGBA_UINT16:
- return PIPE_FORMAT_R16G16B16A16_USCALED;
- case MESA_FORMAT_RGBA_UINT32:
- return PIPE_FORMAT_R32G32B32A32_USCALED;
-
- case MESA_FORMAT_RED_RGTC1:
- return PIPE_FORMAT_RGTC1_UNORM;
- case MESA_FORMAT_SIGNED_RED_RGTC1:
- return PIPE_FORMAT_RGTC1_SNORM;
- case MESA_FORMAT_RG_RGTC2:
- return PIPE_FORMAT_RGTC2_UNORM;
- case MESA_FORMAT_SIGNED_RG_RGTC2:
- return PIPE_FORMAT_RGTC2_SNORM;
- default:
- assert(0);
- return PIPE_FORMAT_NONE;
- }
-}
-
-
-/**
- * Translate Gallium format to Mesa format.
- */
-gl_format
-st_pipe_format_to_mesa_format(enum pipe_format format)
-{
- switch (format) {
- case PIPE_FORMAT_A8B8G8R8_UNORM:
- return MESA_FORMAT_RGBA8888;
- case PIPE_FORMAT_R8G8B8A8_UNORM:
- return MESA_FORMAT_RGBA8888_REV;
- case PIPE_FORMAT_B8G8R8A8_UNORM:
- return MESA_FORMAT_ARGB8888;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- return MESA_FORMAT_ARGB8888_REV;
- case PIPE_FORMAT_B8G8R8X8_UNORM:
- return MESA_FORMAT_XRGB8888;
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- return MESA_FORMAT_XRGB8888_REV;
- case PIPE_FORMAT_B5G5R5A1_UNORM:
- return MESA_FORMAT_ARGB1555;
- case PIPE_FORMAT_B4G4R4A4_UNORM:
- return MESA_FORMAT_ARGB4444;
- case PIPE_FORMAT_B5G6R5_UNORM:
- return MESA_FORMAT_RGB565;
- case PIPE_FORMAT_B2G3R3_UNORM:
- return MESA_FORMAT_RGB332;
- case PIPE_FORMAT_B10G10R10A2_UNORM:
- return MESA_FORMAT_ARGB2101010;
- case PIPE_FORMAT_L4A4_UNORM:
- return MESA_FORMAT_AL44;
- case PIPE_FORMAT_L8A8_UNORM:
- return MESA_FORMAT_AL88;
- case PIPE_FORMAT_L16A16_UNORM:
- return MESA_FORMAT_AL1616;
- case PIPE_FORMAT_A8_UNORM:
- return MESA_FORMAT_A8;
- case PIPE_FORMAT_A16_UNORM:
- return MESA_FORMAT_A16;
- case PIPE_FORMAT_L8_UNORM:
- return MESA_FORMAT_L8;
- case PIPE_FORMAT_L16_UNORM:
- return MESA_FORMAT_L16;
- case PIPE_FORMAT_I8_UNORM:
- return MESA_FORMAT_I8;
- case PIPE_FORMAT_I16_UNORM:
- return MESA_FORMAT_I16;
- case PIPE_FORMAT_S8_USCALED:
- return MESA_FORMAT_S8;
-
- case PIPE_FORMAT_R16G16B16A16_UNORM:
- return MESA_FORMAT_RGBA_16;
- case PIPE_FORMAT_R16G16B16A16_SNORM:
- return MESA_FORMAT_SIGNED_RGBA_16;
-
- case PIPE_FORMAT_Z16_UNORM:
- return MESA_FORMAT_Z16;
- case PIPE_FORMAT_Z32_UNORM:
- return MESA_FORMAT_Z32;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- return MESA_FORMAT_Z24_S8;
- case PIPE_FORMAT_X8Z24_UNORM:
- return MESA_FORMAT_Z24_X8;
- case PIPE_FORMAT_Z24X8_UNORM:
- return MESA_FORMAT_X8_Z24;
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- return MESA_FORMAT_S8_Z24;
-
- case PIPE_FORMAT_UYVY:
- return MESA_FORMAT_YCBCR;
- case PIPE_FORMAT_YUYV:
- return MESA_FORMAT_YCBCR_REV;
-
-#if FEATURE_texture_s3tc
- case PIPE_FORMAT_DXT1_RGB:
- return MESA_FORMAT_RGB_DXT1;
- case PIPE_FORMAT_DXT1_RGBA:
- return MESA_FORMAT_RGBA_DXT1;
- case PIPE_FORMAT_DXT3_RGBA:
- return MESA_FORMAT_RGBA_DXT3;
- case PIPE_FORMAT_DXT5_RGBA:
- return MESA_FORMAT_RGBA_DXT5;
-#if FEATURE_EXT_texture_sRGB
- case PIPE_FORMAT_DXT1_SRGB:
- return MESA_FORMAT_SRGB_DXT1;
- case PIPE_FORMAT_DXT1_SRGBA:
- return MESA_FORMAT_SRGBA_DXT1;
- case PIPE_FORMAT_DXT3_SRGBA:
- return MESA_FORMAT_SRGBA_DXT3;
- case PIPE_FORMAT_DXT5_SRGBA:
- return MESA_FORMAT_SRGBA_DXT5;
-#endif
-#endif
-
-#if FEATURE_EXT_texture_sRGB
- case PIPE_FORMAT_L8A8_SRGB:
- return MESA_FORMAT_SLA8;
- case PIPE_FORMAT_L8_SRGB:
- return MESA_FORMAT_SL8;
- case PIPE_FORMAT_R8G8B8_SRGB:
- return MESA_FORMAT_SRGB8;
- case PIPE_FORMAT_A8B8G8R8_SRGB:
- return MESA_FORMAT_SRGBA8;
- case PIPE_FORMAT_B8G8R8A8_SRGB:
- return MESA_FORMAT_SARGB8;
-#endif
-
- case PIPE_FORMAT_R8_UNORM:
- return MESA_FORMAT_R8;
- case PIPE_FORMAT_R16_UNORM:
- return MESA_FORMAT_R16;
- case PIPE_FORMAT_R8G8_UNORM:
- return MESA_FORMAT_RG88;
- case PIPE_FORMAT_R16G16_UNORM:
- return MESA_FORMAT_RG1616;
-
- /* signed int formats */
- case PIPE_FORMAT_R8G8B8A8_SSCALED:
- return MESA_FORMAT_RGBA_INT8;
- case PIPE_FORMAT_R16G16B16A16_SSCALED:
- return MESA_FORMAT_RGBA_INT16;
- case PIPE_FORMAT_R32G32B32A32_SSCALED:
- return MESA_FORMAT_RGBA_INT32;
-
- /* unsigned int formats */
- case PIPE_FORMAT_R8G8B8A8_USCALED:
- return MESA_FORMAT_RGBA_UINT8;
- case PIPE_FORMAT_R16G16B16A16_USCALED:
- return MESA_FORMAT_RGBA_UINT16;
- case PIPE_FORMAT_R32G32B32A32_USCALED:
- return MESA_FORMAT_RGBA_UINT32;
-
- case PIPE_FORMAT_RGTC1_UNORM:
- return MESA_FORMAT_RED_RGTC1;
- case PIPE_FORMAT_RGTC1_SNORM:
- return MESA_FORMAT_SIGNED_RED_RGTC1;
- case PIPE_FORMAT_RGTC2_UNORM:
- return MESA_FORMAT_RG_RGTC2;
- case PIPE_FORMAT_RGTC2_SNORM:
- return MESA_FORMAT_SIGNED_RG_RGTC2;
-
- default:
- assert(0);
- return MESA_FORMAT_NONE;
- }
-}
-
-
-/**
- * Return first supported format from the given list.
- */
-static enum pipe_format
-find_supported_format(struct pipe_screen *screen,
- const enum pipe_format formats[],
- uint num_formats,
- enum pipe_texture_target target,
- unsigned sample_count,
- unsigned tex_usage,
- unsigned geom_flags)
-{
- uint i;
- for (i = 0; i < num_formats; i++) {
- if (screen->is_format_supported(screen, formats[i], target,
- sample_count, tex_usage, geom_flags)) {
- return formats[i];
- }
- }
- return PIPE_FORMAT_NONE;
-}
-
-
-/**
- * Find an RGBA format supported by the context/winsys.
- */
-static enum pipe_format
-default_rgba_format(struct pipe_screen *screen,
- enum pipe_texture_target target,
- unsigned sample_count,
- unsigned tex_usage,
- unsigned geom_flags)
-{
- static const enum pipe_format colorFormats[] = {
- PIPE_FORMAT_B8G8R8A8_UNORM,
- PIPE_FORMAT_A8R8G8B8_UNORM,
- PIPE_FORMAT_A8B8G8R8_UNORM,
- PIPE_FORMAT_B5G6R5_UNORM
- };
- return find_supported_format(screen, colorFormats, Elements(colorFormats),
- target, sample_count, tex_usage, geom_flags);
-}
-
-
-/**
- * Find an RGB format supported by the context/winsys.
- */
-static enum pipe_format
-default_rgb_format(struct pipe_screen *screen,
- enum pipe_texture_target target,
- unsigned sample_count,
- unsigned tex_usage,
- unsigned geom_flags)
-{
- static const enum pipe_format colorFormats[] = {
- PIPE_FORMAT_B8G8R8X8_UNORM,
- PIPE_FORMAT_X8R8G8B8_UNORM,
- PIPE_FORMAT_X8B8G8R8_UNORM,
- PIPE_FORMAT_B8G8R8A8_UNORM,
- PIPE_FORMAT_A8R8G8B8_UNORM,
- PIPE_FORMAT_A8B8G8R8_UNORM,
- PIPE_FORMAT_B5G6R5_UNORM
- };
- return find_supported_format(screen, colorFormats, Elements(colorFormats),
- target, sample_count, tex_usage, geom_flags);
-}
-
-/**
- * Find an sRGBA format supported by the context/winsys.
- */
-static enum pipe_format
-default_srgba_format(struct pipe_screen *screen,
- enum pipe_texture_target target,
- unsigned sample_count,
- unsigned tex_usage,
- unsigned geom_flags)
-{
- static const enum pipe_format colorFormats[] = {
- PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_FORMAT_A8R8G8B8_SRGB,
- PIPE_FORMAT_A8B8G8R8_SRGB,
- };
- return find_supported_format(screen, colorFormats, Elements(colorFormats),
- target, sample_count, tex_usage, geom_flags);
-}
-
-
-/**
- * Given an OpenGL internalFormat value for a texture or surface, return
- * the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match.
- * This is called during glTexImage2D, for example.
- *
- * The bindings parameter typically has PIPE_BIND_SAMPLER_VIEW set, plus
- * either PIPE_BINDING_RENDER_TARGET or PIPE_BINDING_DEPTH_STENCIL if
- * we want render-to-texture ability.
- *
- * \param internalFormat the user value passed to glTexImage2D
- * \param target one of PIPE_TEXTURE_x
- * \param bindings bitmask of PIPE_BIND_x flags.
- */
-enum pipe_format
-st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
- enum pipe_texture_target target, unsigned sample_count,
- unsigned bindings)
-{
- unsigned geom_flags = 0; /* we don't care about POT vs. NPOT here, yet */
-
- switch (internalFormat) {
- case GL_RGB10:
- case GL_RGB10_A2:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B10G10R10A2_UNORM,
- target, sample_count, bindings,
- geom_flags ))
- return PIPE_FORMAT_B10G10R10A2_UNORM;
- /* Pass through. */
- case 4:
- case GL_RGBA:
- case GL_RGBA8:
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_BGRA:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B8G8R8A8_UNORM,
- target, sample_count, bindings,
- geom_flags ))
- return PIPE_FORMAT_B8G8R8A8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case 3:
- case GL_RGB:
- case GL_RGB8:
- return default_rgb_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_RGB12:
- case GL_RGB16:
- case GL_RGBA12:
- case GL_RGBA16:
- if (screen->is_format_supported( screen, PIPE_FORMAT_R16G16B16A16_UNORM,
- target, sample_count, bindings,
- geom_flags ))
- return PIPE_FORMAT_R16G16B16A16_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_RGBA4:
- case GL_RGBA2:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B4G4R4A4_UNORM,
- target, sample_count, bindings,
- geom_flags ))
- return PIPE_FORMAT_B4G4R4A4_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_RGB5_A1:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM,
- target, sample_count, bindings,
- geom_flags ))
- return PIPE_FORMAT_B5G5R5A1_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_R3_G3_B2:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B2G3R3_UNORM,
- target, sample_count, bindings,
- geom_flags ))
- return PIPE_FORMAT_B2G3R3_UNORM;
- /* Pass through. */
- case GL_RGB5:
- case GL_RGB4:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B5G6R5_UNORM,
- target, sample_count, bindings,
- geom_flags ))
- return PIPE_FORMAT_B5G6R5_UNORM;
- if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM,
- target, sample_count, bindings,
- geom_flags ))
- return PIPE_FORMAT_B5G5R5A1_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_ALPHA12:
- case GL_ALPHA16:
- if (screen->is_format_supported( screen, PIPE_FORMAT_A16_UNORM, target,
- sample_count, bindings, geom_flags ))
- return PIPE_FORMAT_A16_UNORM;
- /* Pass through. */
- case GL_ALPHA:
- case GL_ALPHA4:
- case GL_ALPHA8:
- case GL_COMPRESSED_ALPHA:
- if (screen->is_format_supported( screen, PIPE_FORMAT_A8_UNORM, target,
- sample_count, bindings, geom_flags ))
- return PIPE_FORMAT_A8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_LUMINANCE12:
- case GL_LUMINANCE16:
- if (screen->is_format_supported( screen, PIPE_FORMAT_L16_UNORM, target,
- sample_count, bindings, geom_flags ))
- return PIPE_FORMAT_L16_UNORM;
- /* Pass through. */
- case 1:
- case GL_LUMINANCE:
- case GL_LUMINANCE4:
- case GL_LUMINANCE8:
- case GL_COMPRESSED_LUMINANCE:
- if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, target,
- sample_count, bindings, geom_flags ))
- return PIPE_FORMAT_L8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_LUMINANCE12_ALPHA4:
- case GL_LUMINANCE12_ALPHA12:
- case GL_LUMINANCE16_ALPHA16:
- if (screen->is_format_supported( screen, PIPE_FORMAT_L16A16_UNORM, target,
- sample_count, bindings, geom_flags ))
- return PIPE_FORMAT_L16A16_UNORM;
- /* Pass through. */
- case 2:
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE6_ALPHA2:
- case GL_LUMINANCE8_ALPHA8:
- case GL_COMPRESSED_LUMINANCE_ALPHA:
- if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_UNORM, target,
- sample_count, bindings, geom_flags ))
- return PIPE_FORMAT_L8A8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_LUMINANCE4_ALPHA4:
- if (screen->is_format_supported( screen, PIPE_FORMAT_L4A4_UNORM, target,
- sample_count, bindings, geom_flags ))
- return PIPE_FORMAT_L4A4_UNORM;
- if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_UNORM, target,
- sample_count, bindings, geom_flags ))
- return PIPE_FORMAT_L8A8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_INTENSITY12:
- case GL_INTENSITY16:
- if (screen->is_format_supported( screen, PIPE_FORMAT_I16_UNORM, target,
- sample_count, bindings, geom_flags ))
- return PIPE_FORMAT_I16_UNORM;
- /* Pass through. */
- case GL_INTENSITY:
- case GL_INTENSITY4:
- case GL_INTENSITY8:
- case GL_COMPRESSED_INTENSITY:
- if (screen->is_format_supported( screen, PIPE_FORMAT_I8_UNORM, target,
- sample_count, bindings, geom_flags ))
- return PIPE_FORMAT_I8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_YCBCR_MESA:
- if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY, target,
- sample_count, bindings, geom_flags)) {
- return PIPE_FORMAT_UYVY;
- }
- if (screen->is_format_supported(screen, PIPE_FORMAT_YUYV, target,
- sample_count, bindings, geom_flags)) {
- return PIPE_FORMAT_YUYV;
- }
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_RGB:
- /* can only sample from compressed formats */
- if (bindings & ~PIPE_BIND_SAMPLER_VIEW)
- return PIPE_FORMAT_NONE;
- else if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGB,
- target, sample_count, bindings,
- geom_flags))
- return PIPE_FORMAT_DXT1_RGB;
- else
- return default_rgb_format(screen, target, sample_count, bindings,
- geom_flags);
-
- case GL_COMPRESSED_RGBA:
- /* can only sample from compressed formats */
- if (bindings & ~PIPE_BIND_SAMPLER_VIEW)
- return PIPE_FORMAT_NONE;
- else if (screen->is_format_supported(screen, PIPE_FORMAT_DXT3_RGBA,
- target, sample_count, bindings,
- geom_flags))
- return PIPE_FORMAT_DXT3_RGBA;
- else
- return default_rgba_format(screen, target, sample_count, bindings,
- geom_flags);
-
- case GL_RGB_S3TC:
- case GL_RGB4_S3TC:
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGB,
- target, sample_count, bindings,
- geom_flags))
- return PIPE_FORMAT_DXT1_RGB;
- else
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGBA,
- target, sample_count, bindings,
- geom_flags))
- return PIPE_FORMAT_DXT1_RGBA;
- else
- return PIPE_FORMAT_NONE;
-
- case GL_RGBA_S3TC:
- case GL_RGBA4_S3TC:
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_DXT3_RGBA,
- target, sample_count, bindings,
- geom_flags))
- return PIPE_FORMAT_DXT3_RGBA;
- else
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
- target, sample_count, bindings,
- geom_flags))
- return PIPE_FORMAT_DXT5_RGBA;
- else
- return PIPE_FORMAT_NONE;
-
-#if 0
- case GL_COMPRESSED_RGB_FXT1_3DFX:
- return PIPE_FORMAT_RGB_FXT1;
- case GL_COMPRESSED_RGBA_FXT1_3DFX:
- return PIPE_FORMAT_RGB_FXT1;
-#endif
-
- case GL_DEPTH_COMPONENT16:
- if (screen->is_format_supported(screen, PIPE_FORMAT_Z16_UNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_Z16_UNORM;
- /* fall-through */
- case GL_DEPTH_COMPONENT24:
- if (screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
- target, sample_count, bindings, geom_flags))
- return PIPE_FORMAT_Z24_UNORM_S8_USCALED;
- if (screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
- target, sample_count, bindings, geom_flags))
- return PIPE_FORMAT_S8_USCALED_Z24_UNORM;
- /* fall-through */
- case GL_DEPTH_COMPONENT32:
- if (screen->is_format_supported(screen, PIPE_FORMAT_Z32_UNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_Z32_UNORM;
- /* fall-through */
- case GL_DEPTH_COMPONENT:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_Z32_UNORM,
- PIPE_FORMAT_Z24_UNORM_S8_USCALED,
- PIPE_FORMAT_S8_USCALED_Z24_UNORM,
- PIPE_FORMAT_Z16_UNORM
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings, geom_flags);
- }
-
- case GL_STENCIL_INDEX:
- case GL_STENCIL_INDEX1_EXT:
- case GL_STENCIL_INDEX4_EXT:
- case GL_STENCIL_INDEX8_EXT:
- case GL_STENCIL_INDEX16_EXT:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_S8_USCALED,
- PIPE_FORMAT_Z24_UNORM_S8_USCALED,
- PIPE_FORMAT_S8_USCALED_Z24_UNORM
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings, geom_flags);
- }
-
- case GL_DEPTH_STENCIL_EXT:
- case GL_DEPTH24_STENCIL8_EXT:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_Z24_UNORM_S8_USCALED,
- PIPE_FORMAT_S8_USCALED_Z24_UNORM
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings, geom_flags);
- }
-
- case GL_SRGB_EXT:
- case GL_SRGB8_EXT:
- case GL_SRGB_ALPHA_EXT:
- case GL_SRGB8_ALPHA8_EXT:
- return default_srgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_COMPRESSED_SRGB_EXT:
- case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_SRGB, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_DXT1_SRGB;
- return default_srgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
- return PIPE_FORMAT_DXT1_SRGBA;
-
- case GL_COMPRESSED_SRGB_ALPHA_EXT:
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_DXT3_SRGBA, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_DXT3_SRGBA;
- return default_srgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
- return PIPE_FORMAT_DXT5_SRGBA;
-
- case GL_SLUMINANCE_ALPHA_EXT:
- case GL_SLUMINANCE8_ALPHA8_EXT:
- case GL_COMPRESSED_SLUMINANCE_EXT:
- case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_L8A8_SRGB, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_L8A8_SRGB;
- return default_srgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_SLUMINANCE_EXT:
- case GL_SLUMINANCE8_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_L8_SRGB, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_L8_SRGB;
- return default_srgba_format( screen, target, sample_count, bindings,
- geom_flags );
-
- case GL_RED:
- case GL_R8:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R8_UNORM;
- return PIPE_FORMAT_NONE;
- case GL_RG:
- case GL_RG8:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R8G8_UNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_R16:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R16_UNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R16_UNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_RG16:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16_UNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R16G16_UNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_RED:
- case GL_COMPRESSED_RED_RGTC1:
- if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_UNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_RGTC1_UNORM;
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R8_UNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_SIGNED_RED_RGTC1:
- if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_SNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_RGTC1_SNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_RG:
- case GL_COMPRESSED_RG_RGTC2:
- if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_UNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_RGTC2_UNORM;
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R8G8_UNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_SIGNED_RG_RGTC2:
- if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_SNORM, target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_RGTC2_SNORM;
- return PIPE_FORMAT_NONE;
-
- /* signed/unsigned integer formats.
- * XXX Mesa only has formats for RGBA signed/unsigned integer formats.
- * If/when new formats are added this code should be updated.
- */
- case GL_RED_INTEGER_EXT:
- case GL_GREEN_INTEGER_EXT:
- case GL_BLUE_INTEGER_EXT:
- case GL_ALPHA_INTEGER_EXT:
- case GL_RGB_INTEGER_EXT:
- case GL_RGBA_INTEGER_EXT:
- case GL_BGR_INTEGER_EXT:
- case GL_BGRA_INTEGER_EXT:
- case GL_LUMINANCE_INTEGER_EXT:
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- /* fall-through */
- case GL_RGBA8I_EXT:
- case GL_RGB8I_EXT:
- case GL_ALPHA8I_EXT:
- case GL_INTENSITY8I_EXT:
- case GL_LUMINANCE8I_EXT:
- case GL_LUMINANCE_ALPHA8I_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SSCALED,
- target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R8G8B8A8_SSCALED;
- return PIPE_FORMAT_NONE;
- case GL_RGBA16I_EXT:
- case GL_RGB16I_EXT:
- case GL_ALPHA16I_EXT:
- case GL_INTENSITY16I_EXT:
- case GL_LUMINANCE16I_EXT:
- case GL_LUMINANCE_ALPHA16I_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SSCALED,
- target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R16G16B16A16_SSCALED;
- return PIPE_FORMAT_NONE;
- case GL_RGBA32I_EXT:
- case GL_RGB32I_EXT:
- case GL_ALPHA32I_EXT:
- case GL_INTENSITY32I_EXT:
- case GL_LUMINANCE32I_EXT:
- case GL_LUMINANCE_ALPHA32I_EXT:
- /* xxx */
- if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_SSCALED,
- target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R32G32B32A32_SSCALED;
- return PIPE_FORMAT_NONE;
-
- case GL_RGBA8UI_EXT:
- case GL_RGB8UI_EXT:
- case GL_ALPHA8UI_EXT:
- case GL_INTENSITY8UI_EXT:
- case GL_LUMINANCE8UI_EXT:
- case GL_LUMINANCE_ALPHA8UI_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_USCALED,
- target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R8G8B8A8_USCALED;
- return PIPE_FORMAT_NONE;
-
- case GL_RGBA16UI_EXT:
- case GL_RGB16UI_EXT:
- case GL_ALPHA16UI_EXT:
- case GL_INTENSITY16UI_EXT:
- case GL_LUMINANCE16UI_EXT:
- case GL_LUMINANCE_ALPHA16UI_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_USCALED,
- target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R16G16B16A16_USCALED;
- return PIPE_FORMAT_NONE;
-
- case GL_RGBA32UI_EXT:
- case GL_RGB32UI_EXT:
- case GL_ALPHA32UI_EXT:
- case GL_INTENSITY32UI_EXT:
- case GL_LUMINANCE32UI_EXT:
- case GL_LUMINANCE_ALPHA32UI_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_USCALED,
- target,
- sample_count, bindings, geom_flags))
- return PIPE_FORMAT_R32G32B32A32_USCALED;
- return PIPE_FORMAT_NONE;
-
- default:
- return PIPE_FORMAT_NONE;
- }
-}
-
-
-/**
- * Called by FBO code to choose a PIPE_FORMAT_ for drawing surfaces.
- */
-enum pipe_format
-st_choose_renderbuffer_format(struct pipe_screen *screen,
- GLenum internalFormat, unsigned sample_count)
-{
- uint usage;
- if (_mesa_is_depth_or_stencil_format(internalFormat))
- usage = PIPE_BIND_DEPTH_STENCIL;
- else
- usage = PIPE_BIND_RENDER_TARGET;
- return st_choose_format(screen, internalFormat, PIPE_TEXTURE_2D,
- sample_count, usage);
-}
-
-
-/**
- * Called via ctx->Driver.chooseTextureFormat().
- */
-gl_format
-st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
- GLenum format, GLenum type, GLboolean renderable)
-{
- struct pipe_screen *screen = st_context(ctx)->pipe->screen;
- enum pipe_format pFormat;
- uint bindings;
-
- (void) format;
- (void) type;
-
- /* GL textures may wind up being render targets, but we don't know
- * that in advance. Specify potential render target flags now.
- */
- bindings = PIPE_BIND_SAMPLER_VIEW;
- if (renderable == GL_TRUE) {
- if (_mesa_is_depth_format(internalFormat) ||
- _mesa_is_depth_or_stencil_format(internalFormat))
- bindings |= PIPE_BIND_DEPTH_STENCIL;
- else
- bindings |= PIPE_BIND_RENDER_TARGET;
- }
-
- pFormat = st_choose_format(screen, internalFormat,
- PIPE_TEXTURE_2D, 0, bindings);
-
- if (pFormat == PIPE_FORMAT_NONE) {
- /* try choosing format again, this time without render target bindings */
- pFormat = st_choose_format(screen, internalFormat,
- PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
- }
-
- if (pFormat == PIPE_FORMAT_NONE) {
- /* no luck at all */
- return MESA_FORMAT_NONE;
- }
-
- return st_pipe_format_to_mesa_format(pFormat);
-}
-
-gl_format
-st_ChooseTextureFormat(struct gl_context *ctx, GLint internalFormat,
- GLenum format, GLenum type)
-{
- boolean want_renderable =
- internalFormat == 3 || internalFormat == 4 ||
- internalFormat == GL_RGB || internalFormat == GL_RGBA ||
- internalFormat == GL_RGB8 || internalFormat == GL_RGBA8 ||
- internalFormat == GL_BGRA;
-
- return st_ChooseTextureFormat_renderable(ctx, internalFormat,
- format, type, want_renderable);
-}
-
-/**
- * Test if a gallium format is equivalent to a GL format/type.
- */
-GLboolean
-st_equal_formats(enum pipe_format pFormat, GLenum format, GLenum type)
-{
- switch (pFormat) {
- case PIPE_FORMAT_A8B8G8R8_UNORM:
- return format == GL_RGBA && type == GL_UNSIGNED_BYTE;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- return format == GL_BGRA && type == GL_UNSIGNED_BYTE;
- case PIPE_FORMAT_B5G6R5_UNORM:
- return format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5;
- /* XXX more combos... */
- default:
- return GL_FALSE;
- }
-}
-
-GLboolean
-st_sampler_compat_formats(enum pipe_format format1, enum pipe_format format2)
-{
- if (format1 == format2)
- return GL_TRUE;
-
- if (format1 == PIPE_FORMAT_B8G8R8A8_UNORM &&
- format2 == PIPE_FORMAT_B8G8R8X8_UNORM)
- return GL_TRUE;
-
- if (format1 == PIPE_FORMAT_B8G8R8X8_UNORM &&
- format2 == PIPE_FORMAT_B8G8R8A8_UNORM)
- return GL_TRUE;
-
- if (format1 == PIPE_FORMAT_A8B8G8R8_UNORM &&
- format2 == PIPE_FORMAT_X8B8G8R8_UNORM)
- return GL_TRUE;
-
- if (format1 == PIPE_FORMAT_X8B8G8R8_UNORM &&
- format2 == PIPE_FORMAT_A8B8G8R8_UNORM)
- return GL_TRUE;
-
- if (format1 == PIPE_FORMAT_A8R8G8B8_UNORM &&
- format2 == PIPE_FORMAT_X8R8G8B8_UNORM)
- return GL_TRUE;
-
- if (format1 == PIPE_FORMAT_X8R8G8B8_UNORM &&
- format2 == PIPE_FORMAT_A8R8G8B8_UNORM)
- return GL_TRUE;
-
- return GL_FALSE;
-}
-
-
-
-/**
- * This is used for translating texture border color and the clear
- * color. For example, the clear color is interpreted according to
- * the renderbuffer's base format. For example, if clearing a
- * GL_LUMINANCE buffer, ClearColor[0] = luminance and ClearColor[1] =
- * alpha. Similarly for texture border colors.
- */
-void
-st_translate_color(const GLfloat colorIn[4], GLenum baseFormat,
- GLfloat colorOut[4])
-{
- switch (baseFormat) {
- case GL_RED:
- colorOut[0] = colorIn[0];
- colorOut[1] = 0.0F;
- colorOut[2] = 0.0F;
- colorOut[3] = 1.0F;
- break;
- case GL_RG:
- colorOut[0] = colorIn[0];
- colorOut[1] = colorIn[1];
- colorOut[2] = 0.0F;
- colorOut[3] = 1.0F;
- break;
- case GL_RGB:
- colorOut[0] = colorIn[0];
- colorOut[1] = colorIn[1];
- colorOut[2] = colorIn[2];
- colorOut[3] = 1.0F;
- break;
- case GL_ALPHA:
- colorOut[0] = colorOut[1] = colorOut[2] = 0.0;
- colorOut[3] = colorIn[3];
- break;
- case GL_LUMINANCE:
- colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0];
- colorOut[3] = 1.0;
- break;
- case GL_LUMINANCE_ALPHA:
- colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0];
- colorOut[3] = colorIn[3];
- break;
- case GL_INTENSITY:
- colorOut[0] = colorOut[1] = colorOut[2] = colorOut[3] = colorIn[0];
- break;
- default:
- COPY_4V(colorOut, colorIn);
- }
-}
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright (c) 2008-2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+/**
+ * Mesa / Gallium format conversion and format selection code.
+ * \author Brian Paul
+ */
+
+#include "main/imports.h"
+#include "main/context.h"
+#include "main/texstore.h"
+#include "main/image.h"
+#include "main/macros.h"
+#include "main/mfeatures.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_screen.h"
+#include "util/u_format.h"
+#include "st_context.h"
+#include "st_format.h"
+
+
+static GLuint
+format_max_bits(enum pipe_format format)
+{
+ GLuint size = util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0);
+
+ size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 1));
+ size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 2));
+ size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 3));
+ size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 0));
+ size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1));
+ return size;
+}
+
+
+/**
+ * Return basic GL datatype for the given gallium format.
+ */
+GLenum
+st_format_datatype(enum pipe_format format)
+{
+ const struct util_format_description *desc;
+
+ desc = util_format_description(format);
+ assert(desc);
+
+ if (desc->layout == UTIL_FORMAT_LAYOUT_PLAIN) {
+ if (format == PIPE_FORMAT_B5G5R5A1_UNORM ||
+ format == PIPE_FORMAT_B5G6R5_UNORM) {
+ return GL_UNSIGNED_SHORT;
+ }
+ else if (format == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
+ format == PIPE_FORMAT_S8_USCALED_Z24_UNORM ||
+ format == PIPE_FORMAT_Z24X8_UNORM ||
+ format == PIPE_FORMAT_X8Z24_UNORM) {
+ return GL_UNSIGNED_INT_24_8;
+ }
+ else {
+ const GLuint size = format_max_bits(format);
+ if (size == 8) {
+ if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED)
+ return GL_UNSIGNED_BYTE;
+ else
+ return GL_BYTE;
+ }
+ else if (size == 16) {
+ if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED)
+ return GL_UNSIGNED_SHORT;
+ else
+ return GL_SHORT;
+ }
+ else {
+ assert( size <= 32 );
+ if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED)
+ return GL_UNSIGNED_INT;
+ else
+ return GL_INT;
+ }
+ }
+ }
+ else if (format == PIPE_FORMAT_UYVY) {
+ return GL_UNSIGNED_SHORT;
+ }
+ else if (format == PIPE_FORMAT_YUYV) {
+ return GL_UNSIGNED_SHORT;
+ }
+ else {
+ /* probably a compressed format, unsupported anyway */
+ return GL_NONE;
+ }
+}
+
+
+/**
+ * Translate Mesa format to Gallium format.
+ */
+enum pipe_format
+st_mesa_format_to_pipe_format(gl_format mesaFormat)
+{
+ switch (mesaFormat) {
+ case MESA_FORMAT_RGBA8888:
+ return PIPE_FORMAT_A8B8G8R8_UNORM;
+ case MESA_FORMAT_RGBA8888_REV:
+ return PIPE_FORMAT_R8G8B8A8_UNORM;
+ case MESA_FORMAT_ARGB8888:
+ return PIPE_FORMAT_B8G8R8A8_UNORM;
+ case MESA_FORMAT_ARGB8888_REV:
+ return PIPE_FORMAT_A8R8G8B8_UNORM;
+ case MESA_FORMAT_XRGB8888:
+ return PIPE_FORMAT_B8G8R8X8_UNORM;
+ case MESA_FORMAT_XRGB8888_REV:
+ return PIPE_FORMAT_X8R8G8B8_UNORM;
+ case MESA_FORMAT_ARGB1555:
+ return PIPE_FORMAT_B5G5R5A1_UNORM;
+ case MESA_FORMAT_ARGB4444:
+ return PIPE_FORMAT_B4G4R4A4_UNORM;
+ case MESA_FORMAT_RGB565:
+ return PIPE_FORMAT_B5G6R5_UNORM;
+ case MESA_FORMAT_RGB332:
+ return PIPE_FORMAT_B2G3R3_UNORM;
+ case MESA_FORMAT_ARGB2101010:
+ return PIPE_FORMAT_B10G10R10A2_UNORM;
+ case MESA_FORMAT_AL44:
+ return PIPE_FORMAT_L4A4_UNORM;
+ case MESA_FORMAT_AL88:
+ return PIPE_FORMAT_L8A8_UNORM;
+ case MESA_FORMAT_AL1616:
+ return PIPE_FORMAT_L16A16_UNORM;
+ case MESA_FORMAT_A8:
+ return PIPE_FORMAT_A8_UNORM;
+ case MESA_FORMAT_A16:
+ return PIPE_FORMAT_A16_UNORM;
+ case MESA_FORMAT_L8:
+ return PIPE_FORMAT_L8_UNORM;
+ case MESA_FORMAT_L16:
+ return PIPE_FORMAT_L16_UNORM;
+ case MESA_FORMAT_I8:
+ return PIPE_FORMAT_I8_UNORM;
+ case MESA_FORMAT_I16:
+ return PIPE_FORMAT_I16_UNORM;
+ case MESA_FORMAT_Z16:
+ return PIPE_FORMAT_Z16_UNORM;
+ case MESA_FORMAT_Z32:
+ return PIPE_FORMAT_Z32_UNORM;
+ case MESA_FORMAT_Z24_S8:
+ return PIPE_FORMAT_S8_USCALED_Z24_UNORM;
+ case MESA_FORMAT_S8_Z24:
+ return PIPE_FORMAT_Z24_UNORM_S8_USCALED;
+ case MESA_FORMAT_Z24_X8:
+ return PIPE_FORMAT_X8Z24_UNORM;
+ case MESA_FORMAT_X8_Z24:
+ return PIPE_FORMAT_Z24X8_UNORM;
+ case MESA_FORMAT_S8:
+ return PIPE_FORMAT_S8_USCALED;
+ case MESA_FORMAT_YCBCR:
+ return PIPE_FORMAT_UYVY;
+#if FEATURE_texture_s3tc
+ case MESA_FORMAT_RGB_DXT1:
+ return PIPE_FORMAT_DXT1_RGB;
+ case MESA_FORMAT_RGBA_DXT1:
+ return PIPE_FORMAT_DXT1_RGBA;
+ case MESA_FORMAT_RGBA_DXT3:
+ return PIPE_FORMAT_DXT3_RGBA;
+ case MESA_FORMAT_RGBA_DXT5:
+ return PIPE_FORMAT_DXT5_RGBA;
+#if FEATURE_EXT_texture_sRGB
+ case MESA_FORMAT_SRGB_DXT1:
+ return PIPE_FORMAT_DXT1_SRGB;
+ case MESA_FORMAT_SRGBA_DXT1:
+ return PIPE_FORMAT_DXT1_SRGBA;
+ case MESA_FORMAT_SRGBA_DXT3:
+ return PIPE_FORMAT_DXT3_SRGBA;
+ case MESA_FORMAT_SRGBA_DXT5:
+ return PIPE_FORMAT_DXT5_SRGBA;
+#endif
+#endif
+#if FEATURE_EXT_texture_sRGB
+ case MESA_FORMAT_SLA8:
+ return PIPE_FORMAT_L8A8_SRGB;
+ case MESA_FORMAT_SL8:
+ return PIPE_FORMAT_L8_SRGB;
+ case MESA_FORMAT_SRGB8:
+ return PIPE_FORMAT_R8G8B8_SRGB;
+ case MESA_FORMAT_SRGBA8:
+ return PIPE_FORMAT_A8B8G8R8_SRGB;
+ case MESA_FORMAT_SARGB8:
+ return PIPE_FORMAT_B8G8R8A8_SRGB;
+#endif
+ case MESA_FORMAT_R8:
+ return PIPE_FORMAT_R8_UNORM;
+ case MESA_FORMAT_R16:
+ return PIPE_FORMAT_R16_UNORM;
+ case MESA_FORMAT_RG88:
+ return PIPE_FORMAT_R8G8_UNORM;
+ case MESA_FORMAT_RG1616:
+ return PIPE_FORMAT_R16G16_UNORM;
+ case MESA_FORMAT_RGBA_16:
+ return PIPE_FORMAT_R16G16B16A16_UNORM;
+
+ /* signed int formats */
+ case MESA_FORMAT_RGBA_INT8:
+ return PIPE_FORMAT_R8G8B8A8_SSCALED;
+ case MESA_FORMAT_RGBA_INT16:
+ return PIPE_FORMAT_R16G16B16A16_SSCALED;
+ case MESA_FORMAT_RGBA_INT32:
+ return PIPE_FORMAT_R32G32B32A32_SSCALED;
+
+ /* unsigned int formats */
+ case MESA_FORMAT_RGBA_UINT8:
+ return PIPE_FORMAT_R8G8B8A8_USCALED;
+ case MESA_FORMAT_RGBA_UINT16:
+ return PIPE_FORMAT_R16G16B16A16_USCALED;
+ case MESA_FORMAT_RGBA_UINT32:
+ return PIPE_FORMAT_R32G32B32A32_USCALED;
+
+ case MESA_FORMAT_RED_RGTC1:
+ return PIPE_FORMAT_RGTC1_UNORM;
+ case MESA_FORMAT_SIGNED_RED_RGTC1:
+ return PIPE_FORMAT_RGTC1_SNORM;
+ case MESA_FORMAT_RG_RGTC2:
+ return PIPE_FORMAT_RGTC2_UNORM;
+ case MESA_FORMAT_SIGNED_RG_RGTC2:
+ return PIPE_FORMAT_RGTC2_SNORM;
+ default:
+ assert(0);
+ return PIPE_FORMAT_NONE;
+ }
+}
+
+
+/**
+ * Translate Gallium format to Mesa format.
+ */
+gl_format
+st_pipe_format_to_mesa_format(enum pipe_format format)
+{
+ switch (format) {
+ case PIPE_FORMAT_A8B8G8R8_UNORM:
+ return MESA_FORMAT_RGBA8888;
+ case PIPE_FORMAT_R8G8B8A8_UNORM:
+ return MESA_FORMAT_RGBA8888_REV;
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ return MESA_FORMAT_ARGB8888;
+ case PIPE_FORMAT_A8R8G8B8_UNORM:
+ return MESA_FORMAT_ARGB8888_REV;
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ return MESA_FORMAT_XRGB8888;
+ case PIPE_FORMAT_X8R8G8B8_UNORM:
+ return MESA_FORMAT_XRGB8888_REV;
+ case PIPE_FORMAT_B5G5R5A1_UNORM:
+ return MESA_FORMAT_ARGB1555;
+ case PIPE_FORMAT_B4G4R4A4_UNORM:
+ return MESA_FORMAT_ARGB4444;
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ return MESA_FORMAT_RGB565;
+ case PIPE_FORMAT_B2G3R3_UNORM:
+ return MESA_FORMAT_RGB332;
+ case PIPE_FORMAT_B10G10R10A2_UNORM:
+ return MESA_FORMAT_ARGB2101010;
+ case PIPE_FORMAT_L4A4_UNORM:
+ return MESA_FORMAT_AL44;
+ case PIPE_FORMAT_L8A8_UNORM:
+ return MESA_FORMAT_AL88;
+ case PIPE_FORMAT_L16A16_UNORM:
+ return MESA_FORMAT_AL1616;
+ case PIPE_FORMAT_A8_UNORM:
+ return MESA_FORMAT_A8;
+ case PIPE_FORMAT_A16_UNORM:
+ return MESA_FORMAT_A16;
+ case PIPE_FORMAT_L8_UNORM:
+ return MESA_FORMAT_L8;
+ case PIPE_FORMAT_L16_UNORM:
+ return MESA_FORMAT_L16;
+ case PIPE_FORMAT_I8_UNORM:
+ return MESA_FORMAT_I8;
+ case PIPE_FORMAT_I16_UNORM:
+ return MESA_FORMAT_I16;
+ case PIPE_FORMAT_S8_USCALED:
+ return MESA_FORMAT_S8;
+
+ case PIPE_FORMAT_R16G16B16A16_UNORM:
+ return MESA_FORMAT_RGBA_16;
+ case PIPE_FORMAT_R16G16B16A16_SNORM:
+ return MESA_FORMAT_SIGNED_RGBA_16;
+
+ case PIPE_FORMAT_Z16_UNORM:
+ return MESA_FORMAT_Z16;
+ case PIPE_FORMAT_Z32_UNORM:
+ return MESA_FORMAT_Z32;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ return MESA_FORMAT_Z24_S8;
+ case PIPE_FORMAT_X8Z24_UNORM:
+ return MESA_FORMAT_Z24_X8;
+ case PIPE_FORMAT_Z24X8_UNORM:
+ return MESA_FORMAT_X8_Z24;
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ return MESA_FORMAT_S8_Z24;
+
+ case PIPE_FORMAT_UYVY:
+ return MESA_FORMAT_YCBCR;
+ case PIPE_FORMAT_YUYV:
+ return MESA_FORMAT_YCBCR_REV;
+
+#if FEATURE_texture_s3tc
+ case PIPE_FORMAT_DXT1_RGB:
+ return MESA_FORMAT_RGB_DXT1;
+ case PIPE_FORMAT_DXT1_RGBA:
+ return MESA_FORMAT_RGBA_DXT1;
+ case PIPE_FORMAT_DXT3_RGBA:
+ return MESA_FORMAT_RGBA_DXT3;
+ case PIPE_FORMAT_DXT5_RGBA:
+ return MESA_FORMAT_RGBA_DXT5;
+#if FEATURE_EXT_texture_sRGB
+ case PIPE_FORMAT_DXT1_SRGB:
+ return MESA_FORMAT_SRGB_DXT1;
+ case PIPE_FORMAT_DXT1_SRGBA:
+ return MESA_FORMAT_SRGBA_DXT1;
+ case PIPE_FORMAT_DXT3_SRGBA:
+ return MESA_FORMAT_SRGBA_DXT3;
+ case PIPE_FORMAT_DXT5_SRGBA:
+ return MESA_FORMAT_SRGBA_DXT5;
+#endif
+#endif
+
+#if FEATURE_EXT_texture_sRGB
+ case PIPE_FORMAT_L8A8_SRGB:
+ return MESA_FORMAT_SLA8;
+ case PIPE_FORMAT_L8_SRGB:
+ return MESA_FORMAT_SL8;
+ case PIPE_FORMAT_R8G8B8_SRGB:
+ return MESA_FORMAT_SRGB8;
+ case PIPE_FORMAT_A8B8G8R8_SRGB:
+ return MESA_FORMAT_SRGBA8;
+ case PIPE_FORMAT_B8G8R8A8_SRGB:
+ return MESA_FORMAT_SARGB8;
+#endif
+
+ case PIPE_FORMAT_R8_UNORM:
+ return MESA_FORMAT_R8;
+ case PIPE_FORMAT_R16_UNORM:
+ return MESA_FORMAT_R16;
+ case PIPE_FORMAT_R8G8_UNORM:
+ return MESA_FORMAT_RG88;
+ case PIPE_FORMAT_R16G16_UNORM:
+ return MESA_FORMAT_RG1616;
+
+ /* signed int formats */
+ case PIPE_FORMAT_R8G8B8A8_SSCALED:
+ return MESA_FORMAT_RGBA_INT8;
+ case PIPE_FORMAT_R16G16B16A16_SSCALED:
+ return MESA_FORMAT_RGBA_INT16;
+ case PIPE_FORMAT_R32G32B32A32_SSCALED:
+ return MESA_FORMAT_RGBA_INT32;
+
+ /* unsigned int formats */
+ case PIPE_FORMAT_R8G8B8A8_USCALED:
+ return MESA_FORMAT_RGBA_UINT8;
+ case PIPE_FORMAT_R16G16B16A16_USCALED:
+ return MESA_FORMAT_RGBA_UINT16;
+ case PIPE_FORMAT_R32G32B32A32_USCALED:
+ return MESA_FORMAT_RGBA_UINT32;
+
+ case PIPE_FORMAT_RGTC1_UNORM:
+ return MESA_FORMAT_RED_RGTC1;
+ case PIPE_FORMAT_RGTC1_SNORM:
+ return MESA_FORMAT_SIGNED_RED_RGTC1;
+ case PIPE_FORMAT_RGTC2_UNORM:
+ return MESA_FORMAT_RG_RGTC2;
+ case PIPE_FORMAT_RGTC2_SNORM:
+ return MESA_FORMAT_SIGNED_RG_RGTC2;
+
+ default:
+ assert(0);
+ return MESA_FORMAT_NONE;
+ }
+}
+
+
+/**
+ * Return first supported format from the given list.
+ */
+static enum pipe_format
+find_supported_format(struct pipe_screen *screen,
+ const enum pipe_format formats[],
+ uint num_formats,
+ enum pipe_texture_target target,
+ unsigned sample_count,
+ unsigned tex_usage,
+ unsigned geom_flags)
+{
+ uint i;
+ for (i = 0; i < num_formats; i++) {
+ if (screen->is_format_supported(screen, formats[i], target,
+ sample_count, tex_usage, geom_flags)) {
+ return formats[i];
+ }
+ }
+ return PIPE_FORMAT_NONE;
+}
+
+
+/**
+ * Find an RGBA format supported by the context/winsys.
+ */
+static enum pipe_format
+default_rgba_format(struct pipe_screen *screen,
+ enum pipe_texture_target target,
+ unsigned sample_count,
+ unsigned tex_usage,
+ unsigned geom_flags)
+{
+ static const enum pipe_format colorFormats[] = {
+ PIPE_FORMAT_B8G8R8A8_UNORM,
+ PIPE_FORMAT_A8R8G8B8_UNORM,
+ PIPE_FORMAT_A8B8G8R8_UNORM,
+ PIPE_FORMAT_B5G6R5_UNORM
+ };
+ return find_supported_format(screen, colorFormats, Elements(colorFormats),
+ target, sample_count, tex_usage, geom_flags);
+}
+
+
+/**
+ * Find an RGB format supported by the context/winsys.
+ */
+static enum pipe_format
+default_rgb_format(struct pipe_screen *screen,
+ enum pipe_texture_target target,
+ unsigned sample_count,
+ unsigned tex_usage,
+ unsigned geom_flags)
+{
+ static const enum pipe_format colorFormats[] = {
+ PIPE_FORMAT_B8G8R8X8_UNORM,
+ PIPE_FORMAT_X8R8G8B8_UNORM,
+ PIPE_FORMAT_X8B8G8R8_UNORM,
+ PIPE_FORMAT_B8G8R8A8_UNORM,
+ PIPE_FORMAT_A8R8G8B8_UNORM,
+ PIPE_FORMAT_A8B8G8R8_UNORM,
+ PIPE_FORMAT_B5G6R5_UNORM
+ };
+ return find_supported_format(screen, colorFormats, Elements(colorFormats),
+ target, sample_count, tex_usage, geom_flags);
+}
+
+/**
+ * Find an sRGBA format supported by the context/winsys.
+ */
+static enum pipe_format
+default_srgba_format(struct pipe_screen *screen,
+ enum pipe_texture_target target,
+ unsigned sample_count,
+ unsigned tex_usage,
+ unsigned geom_flags)
+{
+ static const enum pipe_format colorFormats[] = {
+ PIPE_FORMAT_B8G8R8A8_SRGB,
+ PIPE_FORMAT_A8R8G8B8_SRGB,
+ PIPE_FORMAT_A8B8G8R8_SRGB,
+ };
+ return find_supported_format(screen, colorFormats, Elements(colorFormats),
+ target, sample_count, tex_usage, geom_flags);
+}
+
+
+/**
+ * Given an OpenGL internalFormat value for a texture or surface, return
+ * the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match.
+ * This is called during glTexImage2D, for example.
+ *
+ * The bindings parameter typically has PIPE_BIND_SAMPLER_VIEW set, plus
+ * either PIPE_BINDING_RENDER_TARGET or PIPE_BINDING_DEPTH_STENCIL if
+ * we want render-to-texture ability.
+ *
+ * \param internalFormat the user value passed to glTexImage2D
+ * \param target one of PIPE_TEXTURE_x
+ * \param bindings bitmask of PIPE_BIND_x flags.
+ */
+enum pipe_format
+st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
+ enum pipe_texture_target target, unsigned sample_count,
+ unsigned bindings)
+{
+ unsigned geom_flags = 0; /* we don't care about POT vs. NPOT here, yet */
+
+ switch (internalFormat) {
+ case GL_RGB10:
+ case GL_RGB10_A2:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B10G10R10A2_UNORM,
+ target, sample_count, bindings,
+ geom_flags ))
+ return PIPE_FORMAT_B10G10R10A2_UNORM;
+ /* Pass through. */
+ case 4:
+ case GL_RGBA:
+ case GL_RGBA8:
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_BGRA:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B8G8R8A8_UNORM,
+ target, sample_count, bindings,
+ geom_flags ))
+ return PIPE_FORMAT_B8G8R8A8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case 3:
+ case GL_RGB:
+ case GL_RGB8:
+ return default_rgb_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_RGB12:
+ case GL_RGB16:
+ case GL_RGBA12:
+ case GL_RGBA16:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_R16G16B16A16_UNORM,
+ target, sample_count, bindings,
+ geom_flags ))
+ return PIPE_FORMAT_R16G16B16A16_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_RGBA4:
+ case GL_RGBA2:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B4G4R4A4_UNORM,
+ target, sample_count, bindings,
+ geom_flags ))
+ return PIPE_FORMAT_B4G4R4A4_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_RGB5_A1:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM,
+ target, sample_count, bindings,
+ geom_flags ))
+ return PIPE_FORMAT_B5G5R5A1_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_R3_G3_B2:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B2G3R3_UNORM,
+ target, sample_count, bindings,
+ geom_flags ))
+ return PIPE_FORMAT_B2G3R3_UNORM;
+ /* Pass through. */
+ case GL_RGB5:
+ case GL_RGB4:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B5G6R5_UNORM,
+ target, sample_count, bindings,
+ geom_flags ))
+ return PIPE_FORMAT_B5G6R5_UNORM;
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM,
+ target, sample_count, bindings,
+ geom_flags ))
+ return PIPE_FORMAT_B5G5R5A1_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_ALPHA12:
+ case GL_ALPHA16:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_A16_UNORM, target,
+ sample_count, bindings, geom_flags ))
+ return PIPE_FORMAT_A16_UNORM;
+ /* Pass through. */
+ case GL_ALPHA:
+ case GL_ALPHA4:
+ case GL_ALPHA8:
+ case GL_COMPRESSED_ALPHA:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_A8_UNORM, target,
+ sample_count, bindings, geom_flags ))
+ return PIPE_FORMAT_A8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_LUMINANCE12:
+ case GL_LUMINANCE16:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L16_UNORM, target,
+ sample_count, bindings, geom_flags ))
+ return PIPE_FORMAT_L16_UNORM;
+ /* Pass through. */
+ case 1:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE4:
+ case GL_LUMINANCE8:
+ case GL_COMPRESSED_LUMINANCE:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, target,
+ sample_count, bindings, geom_flags ))
+ return PIPE_FORMAT_L8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_LUMINANCE12_ALPHA4:
+ case GL_LUMINANCE12_ALPHA12:
+ case GL_LUMINANCE16_ALPHA16:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L16A16_UNORM, target,
+ sample_count, bindings, geom_flags ))
+ return PIPE_FORMAT_L16A16_UNORM;
+ /* Pass through. */
+ case 2:
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE6_ALPHA2:
+ case GL_LUMINANCE8_ALPHA8:
+ case GL_COMPRESSED_LUMINANCE_ALPHA:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_UNORM, target,
+ sample_count, bindings, geom_flags ))
+ return PIPE_FORMAT_L8A8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_LUMINANCE4_ALPHA4:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L4A4_UNORM, target,
+ sample_count, bindings, geom_flags ))
+ return PIPE_FORMAT_L4A4_UNORM;
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_UNORM, target,
+ sample_count, bindings, geom_flags ))
+ return PIPE_FORMAT_L8A8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_INTENSITY12:
+ case GL_INTENSITY16:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_I16_UNORM, target,
+ sample_count, bindings, geom_flags ))
+ return PIPE_FORMAT_I16_UNORM;
+ /* Pass through. */
+ case GL_INTENSITY:
+ case GL_INTENSITY4:
+ case GL_INTENSITY8:
+ case GL_COMPRESSED_INTENSITY:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_I8_UNORM, target,
+ sample_count, bindings, geom_flags ))
+ return PIPE_FORMAT_I8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_YCBCR_MESA:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY, target,
+ sample_count, bindings, geom_flags)) {
+ return PIPE_FORMAT_UYVY;
+ }
+ if (screen->is_format_supported(screen, PIPE_FORMAT_YUYV, target,
+ sample_count, bindings, geom_flags)) {
+ return PIPE_FORMAT_YUYV;
+ }
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_RGB:
+ /* can only sample from compressed formats */
+ if (bindings & ~PIPE_BIND_SAMPLER_VIEW)
+ return PIPE_FORMAT_NONE;
+ else if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGB,
+ target, sample_count, bindings,
+ geom_flags))
+ return PIPE_FORMAT_DXT1_RGB;
+ else
+ return default_rgb_format(screen, target, sample_count, bindings,
+ geom_flags);
+
+ case GL_COMPRESSED_RGBA:
+ /* can only sample from compressed formats */
+ if (bindings & ~PIPE_BIND_SAMPLER_VIEW)
+ return PIPE_FORMAT_NONE;
+ else if (screen->is_format_supported(screen, PIPE_FORMAT_DXT3_RGBA,
+ target, sample_count, bindings,
+ geom_flags))
+ return PIPE_FORMAT_DXT3_RGBA;
+ else
+ return default_rgba_format(screen, target, sample_count, bindings,
+ geom_flags);
+
+ case GL_RGB_S3TC:
+ case GL_RGB4_S3TC:
+ case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGB,
+ target, sample_count, bindings,
+ geom_flags))
+ return PIPE_FORMAT_DXT1_RGB;
+ else
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGBA,
+ target, sample_count, bindings,
+ geom_flags))
+ return PIPE_FORMAT_DXT1_RGBA;
+ else
+ return PIPE_FORMAT_NONE;
+
+ case GL_RGBA_S3TC:
+ case GL_RGBA4_S3TC:
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_DXT3_RGBA,
+ target, sample_count, bindings,
+ geom_flags))
+ return PIPE_FORMAT_DXT3_RGBA;
+ else
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
+ target, sample_count, bindings,
+ geom_flags))
+ return PIPE_FORMAT_DXT5_RGBA;
+ else
+ return PIPE_FORMAT_NONE;
+
+#if 0
+ case GL_COMPRESSED_RGB_FXT1_3DFX:
+ return PIPE_FORMAT_RGB_FXT1;
+ case GL_COMPRESSED_RGBA_FXT1_3DFX:
+ return PIPE_FORMAT_RGB_FXT1;
+#endif
+
+ case GL_DEPTH_COMPONENT16:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_Z16_UNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_Z16_UNORM;
+ /* fall-through */
+ case GL_DEPTH_COMPONENT24:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
+ target, sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_Z24_UNORM_S8_USCALED;
+ if (screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
+ target, sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_S8_USCALED_Z24_UNORM;
+ /* fall-through */
+ case GL_DEPTH_COMPONENT32:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_Z32_UNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_Z32_UNORM;
+ /* fall-through */
+ case GL_DEPTH_COMPONENT:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_Z32_UNORM,
+ PIPE_FORMAT_Z24_UNORM_S8_USCALED,
+ PIPE_FORMAT_S8_USCALED_Z24_UNORM,
+ PIPE_FORMAT_Z16_UNORM
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings, geom_flags);
+ }
+
+ case GL_STENCIL_INDEX:
+ case GL_STENCIL_INDEX1_EXT:
+ case GL_STENCIL_INDEX4_EXT:
+ case GL_STENCIL_INDEX8_EXT:
+ case GL_STENCIL_INDEX16_EXT:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_S8_USCALED,
+ PIPE_FORMAT_Z24_UNORM_S8_USCALED,
+ PIPE_FORMAT_S8_USCALED_Z24_UNORM
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings, geom_flags);
+ }
+
+ case GL_DEPTH_STENCIL_EXT:
+ case GL_DEPTH24_STENCIL8_EXT:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_Z24_UNORM_S8_USCALED,
+ PIPE_FORMAT_S8_USCALED_Z24_UNORM
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings, geom_flags);
+ }
+
+ case GL_SRGB_EXT:
+ case GL_SRGB8_EXT:
+ case GL_SRGB_ALPHA_EXT:
+ case GL_SRGB8_ALPHA8_EXT:
+ return default_srgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_COMPRESSED_SRGB_EXT:
+ case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_SRGB, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_DXT1_SRGB;
+ return default_srgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
+ return PIPE_FORMAT_DXT1_SRGBA;
+
+ case GL_COMPRESSED_SRGB_ALPHA_EXT:
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_DXT3_SRGBA, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_DXT3_SRGBA;
+ return default_srgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
+ return PIPE_FORMAT_DXT5_SRGBA;
+
+ case GL_SLUMINANCE_ALPHA_EXT:
+ case GL_SLUMINANCE8_ALPHA8_EXT:
+ case GL_COMPRESSED_SLUMINANCE_EXT:
+ case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_L8A8_SRGB, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_L8A8_SRGB;
+ return default_srgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_SLUMINANCE_EXT:
+ case GL_SLUMINANCE8_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_L8_SRGB, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_L8_SRGB;
+ return default_srgba_format( screen, target, sample_count, bindings,
+ geom_flags );
+
+ case GL_RED:
+ case GL_R8:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R8_UNORM;
+ return PIPE_FORMAT_NONE;
+ case GL_RG:
+ case GL_RG8:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R8G8_UNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_R16:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R16_UNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R16_UNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_RG16:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16_UNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R16G16_UNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_RED:
+ case GL_COMPRESSED_RED_RGTC1:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_UNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_RGTC1_UNORM;
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R8_UNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_SIGNED_RED_RGTC1:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_SNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_RGTC1_SNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_RG:
+ case GL_COMPRESSED_RG_RGTC2:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_UNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_RGTC2_UNORM;
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R8G8_UNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_SIGNED_RG_RGTC2:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_SNORM, target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_RGTC2_SNORM;
+ return PIPE_FORMAT_NONE;
+
+ /* signed/unsigned integer formats.
+ * XXX Mesa only has formats for RGBA signed/unsigned integer formats.
+ * If/when new formats are added this code should be updated.
+ */
+ case GL_RED_INTEGER_EXT:
+ case GL_GREEN_INTEGER_EXT:
+ case GL_BLUE_INTEGER_EXT:
+ case GL_ALPHA_INTEGER_EXT:
+ case GL_RGB_INTEGER_EXT:
+ case GL_RGBA_INTEGER_EXT:
+ case GL_BGR_INTEGER_EXT:
+ case GL_BGRA_INTEGER_EXT:
+ case GL_LUMINANCE_INTEGER_EXT:
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ /* fall-through */
+ case GL_RGBA8I_EXT:
+ case GL_RGB8I_EXT:
+ case GL_ALPHA8I_EXT:
+ case GL_INTENSITY8I_EXT:
+ case GL_LUMINANCE8I_EXT:
+ case GL_LUMINANCE_ALPHA8I_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SSCALED,
+ target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R8G8B8A8_SSCALED;
+ return PIPE_FORMAT_NONE;
+ case GL_RGBA16I_EXT:
+ case GL_RGB16I_EXT:
+ case GL_ALPHA16I_EXT:
+ case GL_INTENSITY16I_EXT:
+ case GL_LUMINANCE16I_EXT:
+ case GL_LUMINANCE_ALPHA16I_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SSCALED,
+ target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R16G16B16A16_SSCALED;
+ return PIPE_FORMAT_NONE;
+ case GL_RGBA32I_EXT:
+ case GL_RGB32I_EXT:
+ case GL_ALPHA32I_EXT:
+ case GL_INTENSITY32I_EXT:
+ case GL_LUMINANCE32I_EXT:
+ case GL_LUMINANCE_ALPHA32I_EXT:
+ /* xxx */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_SSCALED,
+ target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R32G32B32A32_SSCALED;
+ return PIPE_FORMAT_NONE;
+
+ case GL_RGBA8UI_EXT:
+ case GL_RGB8UI_EXT:
+ case GL_ALPHA8UI_EXT:
+ case GL_INTENSITY8UI_EXT:
+ case GL_LUMINANCE8UI_EXT:
+ case GL_LUMINANCE_ALPHA8UI_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_USCALED,
+ target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R8G8B8A8_USCALED;
+ return PIPE_FORMAT_NONE;
+
+ case GL_RGBA16UI_EXT:
+ case GL_RGB16UI_EXT:
+ case GL_ALPHA16UI_EXT:
+ case GL_INTENSITY16UI_EXT:
+ case GL_LUMINANCE16UI_EXT:
+ case GL_LUMINANCE_ALPHA16UI_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_USCALED,
+ target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R16G16B16A16_USCALED;
+ return PIPE_FORMAT_NONE;
+
+ case GL_RGBA32UI_EXT:
+ case GL_RGB32UI_EXT:
+ case GL_ALPHA32UI_EXT:
+ case GL_INTENSITY32UI_EXT:
+ case GL_LUMINANCE32UI_EXT:
+ case GL_LUMINANCE_ALPHA32UI_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_USCALED,
+ target,
+ sample_count, bindings, geom_flags))
+ return PIPE_FORMAT_R32G32B32A32_USCALED;
+ return PIPE_FORMAT_NONE;
+
+ default:
+ return PIPE_FORMAT_NONE;
+ }
+}
+
+
+/**
+ * Called by FBO code to choose a PIPE_FORMAT_ for drawing surfaces.
+ */
+enum pipe_format
+st_choose_renderbuffer_format(struct pipe_screen *screen,
+ GLenum internalFormat, unsigned sample_count)
+{
+ uint usage;
+ if (_mesa_is_depth_or_stencil_format(internalFormat))
+ usage = PIPE_BIND_DEPTH_STENCIL;
+ else
+ usage = PIPE_BIND_RENDER_TARGET;
+ return st_choose_format(screen, internalFormat, PIPE_TEXTURE_2D,
+ sample_count, usage);
+}
+
+
+/**
+ * Called via ctx->Driver.chooseTextureFormat().
+ */
+gl_format
+st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
+ GLenum format, GLenum type, GLboolean renderable)
+{
+ struct pipe_screen *screen = st_context(ctx)->pipe->screen;
+ enum pipe_format pFormat;
+ uint bindings;
+
+ (void) format;
+ (void) type;
+
+ /* GL textures may wind up being render targets, but we don't know
+ * that in advance. Specify potential render target flags now.
+ */
+ bindings = PIPE_BIND_SAMPLER_VIEW;
+ if (renderable == GL_TRUE) {
+ if (_mesa_is_depth_format(internalFormat) ||
+ _mesa_is_depth_or_stencil_format(internalFormat))
+ bindings |= PIPE_BIND_DEPTH_STENCIL;
+ else
+ bindings |= PIPE_BIND_RENDER_TARGET;
+ }
+
+ pFormat = st_choose_format(screen, internalFormat,
+ PIPE_TEXTURE_2D, 0, bindings);
+
+ if (pFormat == PIPE_FORMAT_NONE) {
+ /* try choosing format again, this time without render target bindings */
+ pFormat = st_choose_format(screen, internalFormat,
+ PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
+ }
+
+ if (pFormat == PIPE_FORMAT_NONE) {
+ /* no luck at all */
+ return MESA_FORMAT_NONE;
+ }
+
+ return st_pipe_format_to_mesa_format(pFormat);
+}
+
+gl_format
+st_ChooseTextureFormat(struct gl_context *ctx, GLint internalFormat,
+ GLenum format, GLenum type)
+{
+ boolean want_renderable =
+ internalFormat == 3 || internalFormat == 4 ||
+ internalFormat == GL_RGB || internalFormat == GL_RGBA ||
+ internalFormat == GL_RGB8 || internalFormat == GL_RGBA8 ||
+ internalFormat == GL_BGRA;
+
+ return st_ChooseTextureFormat_renderable(ctx, internalFormat,
+ format, type, want_renderable);
+}
+
+/**
+ * Test if a gallium format is equivalent to a GL format/type.
+ */
+GLboolean
+st_equal_formats(enum pipe_format pFormat, GLenum format, GLenum type)
+{
+ switch (pFormat) {
+ case PIPE_FORMAT_A8B8G8R8_UNORM:
+ return format == GL_RGBA && type == GL_UNSIGNED_BYTE;
+ case PIPE_FORMAT_A8R8G8B8_UNORM:
+ return format == GL_BGRA && type == GL_UNSIGNED_BYTE;
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ return format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5;
+ /* XXX more combos... */
+ default:
+ return GL_FALSE;
+ }
+}
+
+GLboolean
+st_sampler_compat_formats(enum pipe_format format1, enum pipe_format format2)
+{
+ if (format1 == format2)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_B8G8R8A8_UNORM &&
+ format2 == PIPE_FORMAT_B8G8R8X8_UNORM)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_B8G8R8X8_UNORM &&
+ format2 == PIPE_FORMAT_B8G8R8A8_UNORM)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_A8B8G8R8_UNORM &&
+ format2 == PIPE_FORMAT_X8B8G8R8_UNORM)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_X8B8G8R8_UNORM &&
+ format2 == PIPE_FORMAT_A8B8G8R8_UNORM)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_A8R8G8B8_UNORM &&
+ format2 == PIPE_FORMAT_X8R8G8B8_UNORM)
+ return GL_TRUE;
+
+ if (format1 == PIPE_FORMAT_X8R8G8B8_UNORM &&
+ format2 == PIPE_FORMAT_A8R8G8B8_UNORM)
+ return GL_TRUE;
+
+ return GL_FALSE;
+}
+
+
+
+/**
+ * This is used for translating texture border color and the clear
+ * color. For example, the clear color is interpreted according to
+ * the renderbuffer's base format. For example, if clearing a
+ * GL_LUMINANCE buffer, ClearColor[0] = luminance and ClearColor[1] =
+ * alpha. Similarly for texture border colors.
+ */
+void
+st_translate_color(const GLfloat colorIn[4], GLenum baseFormat,
+ GLfloat colorOut[4])
+{
+ switch (baseFormat) {
+ case GL_RED:
+ colorOut[0] = colorIn[0];
+ colorOut[1] = 0.0F;
+ colorOut[2] = 0.0F;
+ colorOut[3] = 1.0F;
+ break;
+ case GL_RG:
+ colorOut[0] = colorIn[0];
+ colorOut[1] = colorIn[1];
+ colorOut[2] = 0.0F;
+ colorOut[3] = 1.0F;
+ break;
+ case GL_RGB:
+ colorOut[0] = colorIn[0];
+ colorOut[1] = colorIn[1];
+ colorOut[2] = colorIn[2];
+ colorOut[3] = 1.0F;
+ break;
+ case GL_ALPHA:
+ colorOut[0] = colorOut[1] = colorOut[2] = 0.0;
+ colorOut[3] = colorIn[3];
+ break;
+ case GL_LUMINANCE:
+ colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0];
+ colorOut[3] = 1.0;
+ break;
+ case GL_LUMINANCE_ALPHA:
+ colorOut[0] = colorOut[1] = colorOut[2] = colorIn[0];
+ colorOut[3] = colorIn[3];
+ break;
+ case GL_INTENSITY:
+ colorOut[0] = colorOut[1] = colorOut[2] = colorOut[3] = colorIn[0];
+ break;
+ default:
+ COPY_4V(colorOut, colorIn);
+ }
+}
diff --git a/mesalib/src/mesa/state_tracker/st_format.h b/mesalib/src/mesa/state_tracker/st_format.h
index 0fb570f6e..d31e60711 100644
--- a/mesalib/src/mesa/state_tracker/st_format.h
+++ b/mesalib/src/mesa/state_tracker/st_format.h
@@ -1,86 +1,86 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * Copyright (c) 2010 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#ifndef ST_FORMAT_H
-#define ST_FORMAT_H
-
-#include "main/formats.h"
-#include "main/glheader.h"
-
-#include "pipe/p_defines.h"
-#include "pipe/p_format.h"
-
-struct gl_context;
-struct pipe_screen;
-
-extern GLenum
-st_format_datatype(enum pipe_format format);
-
-
-extern enum pipe_format
-st_mesa_format_to_pipe_format(gl_format mesaFormat);
-
-extern gl_format
-st_pipe_format_to_mesa_format(enum pipe_format pipeFormat);
-
-
-extern enum pipe_format
-st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
- enum pipe_texture_target target, unsigned sample_count,
- unsigned tex_usage);
-
-extern enum pipe_format
-st_choose_renderbuffer_format(struct pipe_screen *screen,
- GLenum internalFormat, unsigned sample_count);
-
-
-gl_format
-st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
- GLenum format, GLenum type, GLboolean renderable);
-
-extern gl_format
-st_ChooseTextureFormat(struct gl_context * ctx, GLint internalFormat,
- GLenum format, GLenum type);
-
-
-extern GLboolean
-st_equal_formats(enum pipe_format pFormat, GLenum format, GLenum type);
-
-/* can we use a sampler view to translate these formats
- only used to make TFP so far */
-extern GLboolean
-st_sampler_compat_formats(enum pipe_format format1, enum pipe_format format2);
-
-
-extern void
-st_translate_color(const GLfloat colorIn[4], GLenum baseFormat,
- GLfloat colorOut[4]);
-
-
-#endif /* ST_FORMAT_H */
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright (c) 2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#ifndef ST_FORMAT_H
+#define ST_FORMAT_H
+
+#include "main/formats.h"
+#include "main/glheader.h"
+
+#include "pipe/p_defines.h"
+#include "pipe/p_format.h"
+
+struct gl_context;
+struct pipe_screen;
+
+extern GLenum
+st_format_datatype(enum pipe_format format);
+
+
+extern enum pipe_format
+st_mesa_format_to_pipe_format(gl_format mesaFormat);
+
+extern gl_format
+st_pipe_format_to_mesa_format(enum pipe_format pipeFormat);
+
+
+extern enum pipe_format
+st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
+ enum pipe_texture_target target, unsigned sample_count,
+ unsigned tex_usage);
+
+extern enum pipe_format
+st_choose_renderbuffer_format(struct pipe_screen *screen,
+ GLenum internalFormat, unsigned sample_count);
+
+
+gl_format
+st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
+ GLenum format, GLenum type, GLboolean renderable);
+
+extern gl_format
+st_ChooseTextureFormat(struct gl_context * ctx, GLint internalFormat,
+ GLenum format, GLenum type);
+
+
+extern GLboolean
+st_equal_formats(enum pipe_format pFormat, GLenum format, GLenum type);
+
+/* can we use a sampler view to translate these formats
+ only used to make TFP so far */
+extern GLboolean
+st_sampler_compat_formats(enum pipe_format format1, enum pipe_format format2);
+
+
+extern void
+st_translate_color(const GLfloat colorIn[4], GLenum baseFormat,
+ GLfloat colorOut[4]);
+
+
+#endif /* ST_FORMAT_H */
diff --git a/mesalib/src/mesa/state_tracker/st_gen_mipmap.c b/mesalib/src/mesa/state_tracker/st_gen_mipmap.c
index a12a32e11..7a61998e2 100644
--- a/mesalib/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/mesalib/src/mesa/state_tracker/st_gen_mipmap.c
@@ -1,453 +1,453 @@
-/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#include "main/imports.h"
-#include "main/mipmap.h"
-#include "main/teximage.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-#include "util/u_format.h"
-#include "util/u_gen_mipmap.h"
-
-#include "st_debug.h"
-#include "st_context.h"
-#include "st_texture.h"
-#include "st_gen_mipmap.h"
-#include "st_cb_texture.h"
-
-
-/**
- * one-time init for generate mipmap
- * XXX Note: there may be other times we need no-op/simple state like this.
- * In that case, some code refactoring would be good.
- */
-void
-st_init_generate_mipmap(struct st_context *st)
-{
- st->gen_mipmap = util_create_gen_mipmap(st->pipe, st->cso_context);
-}
-
-
-void
-st_destroy_generate_mipmap(struct st_context *st)
-{
- util_destroy_gen_mipmap(st->gen_mipmap);
- st->gen_mipmap = NULL;
-}
-
-
-/**
- * Generate mipmap levels using hardware rendering.
- * \return TRUE if successful, FALSE if not possible
- */
-static boolean
-st_render_mipmap(struct st_context *st,
- GLenum target,
- struct st_texture_object *stObj,
- uint baseLevel, uint lastLevel)
-{
- struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
- struct pipe_sampler_view *psv = st_get_texture_sampler_view(stObj, pipe);
- const uint face = _mesa_tex_target_to_face(target);
-
- assert(psv->texture == stObj->pt);
-#if 0
- assert(target != GL_TEXTURE_3D); /* implemented but untested */
-#endif
-
- /* check if we can render in the texture's format */
- /* XXX should probably kill this and always use util_gen_mipmap
- since this implements a sw fallback as well */
- if (!screen->is_format_supported(screen, psv->format, psv->texture->target,
- 0, PIPE_BIND_RENDER_TARGET, 0)) {
- return FALSE;
- }
-
- util_gen_mipmap(st->gen_mipmap, psv, face, baseLevel, lastLevel,
- PIPE_TEX_FILTER_LINEAR);
-
- return TRUE;
-}
-
-
-/**
- * Helper function to decompress an image. The result is a 32-bpp RGBA
- * image with stride==width.
- */
-static void
-decompress_image(enum pipe_format format, int datatype,
- const uint8_t *src, void *dst,
- unsigned width, unsigned height, unsigned src_stride)
-{
- const struct util_format_description *desc = util_format_description(format);
- const uint bw = util_format_get_blockwidth(format);
- const uint bh = util_format_get_blockheight(format);
- uint dst_stride = 4 * MAX2(width, bw);
-
- if (datatype == GL_FLOAT) {
- desc->unpack_rgba_float((float *)dst, dst_stride * sizeof(GLfloat), src, src_stride, width, height);
- if (width < bw || height < bh) {
- float *dst_p = (float *)dst;
- /* We're decompressing an image smaller than the compression
- * block size. We don't want garbage pixel values in the region
- * outside (width x height) so replicate pixels from the (width
- * x height) region to fill out the (bw x bh) block size.
- */
- uint x, y;
- for (y = 0; y < bh; y++) {
- for (x = 0; x < bw; x++) {
- if (x >= width || y >= height) {
- uint p = (y * bw + x) * 4;
- dst_p[p + 0] = dst_p[0];
- dst_p[p + 1] = dst_p[1];
- dst_p[p + 2] = dst_p[2];
- dst_p[p + 3] = dst_p[3];
- }
- }
- }
- }
- } else {
- desc->unpack_rgba_8unorm((uint8_t *)dst, dst_stride, src, src_stride, width, height);
- if (width < bw || height < bh) {
- uint8_t *dst_p = (uint8_t *)dst;
- /* We're decompressing an image smaller than the compression
- * block size. We don't want garbage pixel values in the region
- * outside (width x height) so replicate pixels from the (width
- * x height) region to fill out the (bw x bh) block size.
- */
- uint x, y;
- for (y = 0; y < bh; y++) {
- for (x = 0; x < bw; x++) {
- if (x >= width || y >= height) {
- uint p = (y * bw + x) * 4;
- dst_p[p + 0] = dst_p[0];
- dst_p[p + 1] = dst_p[1];
- dst_p[p + 2] = dst_p[2];
- dst_p[p + 3] = dst_p[3];
- }
- }
- }
- }
- }
-}
-
-/**
- * Helper function to compress an image. The source is a 32-bpp RGBA image
- * with stride==width.
- */
-static void
-compress_image(enum pipe_format format, int datatype,
- const void *src, uint8_t *dst,
- unsigned width, unsigned height, unsigned dst_stride)
-{
- const struct util_format_description *desc = util_format_description(format);
- const uint src_stride = 4 * width;
-
- if (datatype == GL_FLOAT)
- desc->pack_rgba_float(dst, dst_stride, (GLfloat *)src, src_stride * sizeof(GLfloat), width, height);
- else
- desc->pack_rgba_8unorm(dst, dst_stride, (uint8_t *)src, src_stride, width, height);
-}
-
-
-/**
- * Software fallback for generate mipmap levels.
- */
-static void
-fallback_generate_mipmap(struct gl_context *ctx, GLenum target,
- struct gl_texture_object *texObj)
-{
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct pipe_resource *pt = st_get_texobj_resource(texObj);
- const uint baseLevel = texObj->BaseLevel;
- const uint lastLevel = pt->last_level;
- const uint face = _mesa_tex_target_to_face(target);
- uint dstLevel;
- GLenum datatype;
- GLuint comps;
- GLboolean compressed;
-
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s: fallback processing\n", __FUNCTION__);
-
- assert(target != GL_TEXTURE_3D); /* not done yet */
-
- compressed =
- _mesa_is_format_compressed(texObj->Image[face][baseLevel]->TexFormat);
-
- if (compressed) {
- if (texObj->Image[face][baseLevel]->TexFormat == MESA_FORMAT_SIGNED_RED_RGTC1 ||
- texObj->Image[face][baseLevel]->TexFormat == MESA_FORMAT_SIGNED_RG_RGTC2)
- datatype = GL_FLOAT;
- else
- datatype = GL_UNSIGNED_BYTE;
-
- comps = 4;
- }
- else {
- _mesa_format_to_type_and_comps(texObj->Image[face][baseLevel]->TexFormat,
- &datatype, &comps);
- assert(comps > 0 && "bad texture format in fallback_generate_mipmap()");
- }
-
- for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
- const uint srcLevel = dstLevel - 1;
- const uint srcWidth = u_minify(pt->width0, srcLevel);
- const uint srcHeight = u_minify(pt->height0, srcLevel);
- const uint srcDepth = u_minify(pt->depth0, srcLevel);
- const uint dstWidth = u_minify(pt->width0, dstLevel);
- const uint dstHeight = u_minify(pt->height0, dstLevel);
- const uint dstDepth = u_minify(pt->depth0, dstLevel);
- struct pipe_transfer *srcTrans, *dstTrans;
- const ubyte *srcData;
- ubyte *dstData;
- int srcStride, dstStride;
-
- srcTrans = pipe_get_transfer(st_context(ctx)->pipe, pt, srcLevel,
- face,
- PIPE_TRANSFER_READ, 0, 0,
- srcWidth, srcHeight);
-
- dstTrans = pipe_get_transfer(st_context(ctx)->pipe, pt, dstLevel,
- face,
- PIPE_TRANSFER_WRITE, 0, 0,
- dstWidth, dstHeight);
-
- srcData = (ubyte *) pipe_transfer_map(pipe, srcTrans);
- dstData = (ubyte *) pipe_transfer_map(pipe, dstTrans);
-
- srcStride = srcTrans->stride / util_format_get_blocksize(srcTrans->resource->format);
- dstStride = dstTrans->stride / util_format_get_blocksize(dstTrans->resource->format);
-
- /* this cannot work correctly for 3d since it does
- not respect layerStride. */
- if (compressed) {
- const enum pipe_format format = pt->format;
- const uint bw = util_format_get_blockwidth(format);
- const uint bh = util_format_get_blockheight(format);
- const uint srcWidth2 = align(srcWidth, bw);
- const uint srcHeight2 = align(srcHeight, bh);
- const uint dstWidth2 = align(dstWidth, bw);
- const uint dstHeight2 = align(dstHeight, bh);
- uint8_t *srcTemp, *dstTemp;
-
- assert(comps == 4);
-
- srcTemp = malloc(srcWidth2 * srcHeight2 * comps * (datatype == GL_FLOAT ? 4 : 1));
- dstTemp = malloc(dstWidth2 * dstHeight2 * comps * (datatype == GL_FLOAT ? 4 : 1));
-
- /* decompress the src image: srcData -> srcTemp */
- decompress_image(format, datatype, srcData, srcTemp, srcWidth2, srcHeight2, srcTrans->stride);
-
- _mesa_generate_mipmap_level(target, datatype, comps,
- 0 /*border*/,
- srcWidth2, srcHeight2, srcDepth,
- srcTemp,
- srcWidth2, /* stride in texels */
- dstWidth2, dstHeight2, dstDepth,
- dstTemp,
- dstWidth2); /* stride in texels */
-
- /* compress the new image: dstTemp -> dstData */
- compress_image(format, datatype, dstTemp, dstData, dstWidth2, dstHeight2, dstTrans->stride);
-
- free(srcTemp);
- free(dstTemp);
- }
- else {
- _mesa_generate_mipmap_level(target, datatype, comps,
- 0 /*border*/,
- srcWidth, srcHeight, srcDepth,
- srcData,
- srcStride, /* stride in texels */
- dstWidth, dstHeight, dstDepth,
- dstData,
- dstStride); /* stride in texels */
- }
-
- pipe_transfer_unmap(pipe, srcTrans);
- pipe_transfer_unmap(pipe, dstTrans);
-
- pipe->transfer_destroy(pipe, srcTrans);
- pipe->transfer_destroy(pipe, dstTrans);
- }
-}
-
-
-/**
- * Compute the expected number of mipmap levels in the texture given
- * the width/height/depth of the base image and the GL_TEXTURE_BASE_LEVEL/
- * GL_TEXTURE_MAX_LEVEL settings. This will tell us how many mipmap
- * levels should be generated.
- */
-static GLuint
-compute_num_levels(struct gl_context *ctx,
- struct gl_texture_object *texObj,
- GLenum target)
-{
- if (target == GL_TEXTURE_RECTANGLE_ARB) {
- return 1;
- }
- else {
- const struct gl_texture_image *baseImage =
- _mesa_get_tex_image(ctx, texObj, target, texObj->BaseLevel);
- GLuint size, numLevels;
-
- size = MAX2(baseImage->Width2, baseImage->Height2);
- size = MAX2(size, baseImage->Depth2);
-
- numLevels = texObj->BaseLevel;
-
- while (size > 0) {
- numLevels++;
- size >>= 1;
- }
-
- numLevels = MIN2(numLevels, texObj->MaxLevel + 1);
-
- assert(numLevels >= 1);
-
- return numLevels;
- }
-}
-
-
-/**
- * Called via ctx->Driver.GenerateMipmap().
- */
-void
-st_generate_mipmap(struct gl_context *ctx, GLenum target,
- struct gl_texture_object *texObj)
-{
- struct st_context *st = st_context(ctx);
- struct st_texture_object *stObj = st_texture_object(texObj);
- struct pipe_resource *pt = st_get_texobj_resource(texObj);
- const uint baseLevel = texObj->BaseLevel;
- uint lastLevel;
- uint dstLevel;
-
- if (!pt)
- return;
-
- /* not sure if this ultimately actually should work,
- but we're not supporting multisampled textures yet. */
- assert(pt->nr_samples < 2);
-
- /* find expected last mipmap level to generate*/
- lastLevel = compute_num_levels(ctx, texObj, target) - 1;
-
- if (lastLevel == 0)
- return;
-
- /* The texture isn't in a "complete" state yet so set the expected
- * lastLevel here, since it won't get done in st_finalize_texture().
- */
- stObj->lastLevel = lastLevel;
-
- if (pt->last_level < lastLevel) {
- /* The current gallium texture doesn't have space for all the
- * mipmap levels we need to generate. So allocate a new texture.
- */
- struct pipe_resource *oldTex = stObj->pt;
-
- /* create new texture with space for more levels */
- stObj->pt = st_texture_create(st,
- oldTex->target,
- oldTex->format,
- lastLevel,
- oldTex->width0,
- oldTex->height0,
- oldTex->depth0,
- oldTex->array_size,
- oldTex->bind);
-
- /* This will copy the old texture's base image into the new texture
- * which we just allocated.
- */
- st_finalize_texture(ctx, st->pipe, texObj);
-
- /* release the old tex (will likely be freed too) */
- pipe_resource_reference(&oldTex, NULL);
- pipe_sampler_view_reference(&stObj->sampler_view, NULL);
- }
- else {
- /* Make sure that the base texture image data is present in the
- * texture buffer.
- */
- st_finalize_texture(ctx, st->pipe, texObj);
- }
-
- pt = stObj->pt;
-
- assert(pt->last_level >= lastLevel);
-
- /* Try to generate the mipmap by rendering/texturing. If that fails,
- * use the software fallback.
- */
- if (!st_render_mipmap(st, target, stObj, baseLevel, lastLevel)) {
- /* since the util code actually also has a fallback, should
- probably make it never fail and kill this */
- fallback_generate_mipmap(ctx, target, texObj);
- }
-
- /* Fill in the Mesa gl_texture_image fields */
- for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
- const uint srcLevel = dstLevel - 1;
- const struct gl_texture_image *srcImage
- = _mesa_get_tex_image(ctx, texObj, target, srcLevel);
- struct gl_texture_image *dstImage;
- struct st_texture_image *stImage;
- uint dstWidth = u_minify(pt->width0, dstLevel);
- uint dstHeight = u_minify(pt->height0, dstLevel);
- uint dstDepth = u_minify(pt->depth0, dstLevel);
- uint border = srcImage->Border;
-
- dstImage = _mesa_get_tex_image(ctx, texObj, target, dstLevel);
- if (!dstImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
- return;
- }
-
- /* Free old image data */
- if (dstImage->Data)
- ctx->Driver.FreeTexImageData(ctx, dstImage);
-
- /* initialize new image */
- _mesa_init_teximage_fields(ctx, target, dstImage, dstWidth, dstHeight,
- dstDepth, border, srcImage->InternalFormat,
- srcImage->TexFormat);
-
- stImage = st_texture_image(dstImage);
- stImage->level = dstLevel;
-
- pipe_resource_reference(&stImage->pt, pt);
- }
-}
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include "main/imports.h"
+#include "main/mipmap.h"
+#include "main/teximage.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "util/u_format.h"
+#include "util/u_gen_mipmap.h"
+
+#include "st_debug.h"
+#include "st_context.h"
+#include "st_texture.h"
+#include "st_gen_mipmap.h"
+#include "st_cb_texture.h"
+
+
+/**
+ * one-time init for generate mipmap
+ * XXX Note: there may be other times we need no-op/simple state like this.
+ * In that case, some code refactoring would be good.
+ */
+void
+st_init_generate_mipmap(struct st_context *st)
+{
+ st->gen_mipmap = util_create_gen_mipmap(st->pipe, st->cso_context);
+}
+
+
+void
+st_destroy_generate_mipmap(struct st_context *st)
+{
+ util_destroy_gen_mipmap(st->gen_mipmap);
+ st->gen_mipmap = NULL;
+}
+
+
+/**
+ * Generate mipmap levels using hardware rendering.
+ * \return TRUE if successful, FALSE if not possible
+ */
+static boolean
+st_render_mipmap(struct st_context *st,
+ GLenum target,
+ struct st_texture_object *stObj,
+ uint baseLevel, uint lastLevel)
+{
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_screen *screen = pipe->screen;
+ struct pipe_sampler_view *psv = st_get_texture_sampler_view(stObj, pipe);
+ const uint face = _mesa_tex_target_to_face(target);
+
+ assert(psv->texture == stObj->pt);
+#if 0
+ assert(target != GL_TEXTURE_3D); /* implemented but untested */
+#endif
+
+ /* check if we can render in the texture's format */
+ /* XXX should probably kill this and always use util_gen_mipmap
+ since this implements a sw fallback as well */
+ if (!screen->is_format_supported(screen, psv->format, psv->texture->target,
+ 0, PIPE_BIND_RENDER_TARGET, 0)) {
+ return FALSE;
+ }
+
+ util_gen_mipmap(st->gen_mipmap, psv, face, baseLevel, lastLevel,
+ PIPE_TEX_FILTER_LINEAR);
+
+ return TRUE;
+}
+
+
+/**
+ * Helper function to decompress an image. The result is a 32-bpp RGBA
+ * image with stride==width.
+ */
+static void
+decompress_image(enum pipe_format format, int datatype,
+ const uint8_t *src, void *dst,
+ unsigned width, unsigned height, unsigned src_stride)
+{
+ const struct util_format_description *desc = util_format_description(format);
+ const uint bw = util_format_get_blockwidth(format);
+ const uint bh = util_format_get_blockheight(format);
+ uint dst_stride = 4 * MAX2(width, bw);
+
+ if (datatype == GL_FLOAT) {
+ desc->unpack_rgba_float((float *)dst, dst_stride * sizeof(GLfloat), src, src_stride, width, height);
+ if (width < bw || height < bh) {
+ float *dst_p = (float *)dst;
+ /* We're decompressing an image smaller than the compression
+ * block size. We don't want garbage pixel values in the region
+ * outside (width x height) so replicate pixels from the (width
+ * x height) region to fill out the (bw x bh) block size.
+ */
+ uint x, y;
+ for (y = 0; y < bh; y++) {
+ for (x = 0; x < bw; x++) {
+ if (x >= width || y >= height) {
+ uint p = (y * bw + x) * 4;
+ dst_p[p + 0] = dst_p[0];
+ dst_p[p + 1] = dst_p[1];
+ dst_p[p + 2] = dst_p[2];
+ dst_p[p + 3] = dst_p[3];
+ }
+ }
+ }
+ }
+ } else {
+ desc->unpack_rgba_8unorm((uint8_t *)dst, dst_stride, src, src_stride, width, height);
+ if (width < bw || height < bh) {
+ uint8_t *dst_p = (uint8_t *)dst;
+ /* We're decompressing an image smaller than the compression
+ * block size. We don't want garbage pixel values in the region
+ * outside (width x height) so replicate pixels from the (width
+ * x height) region to fill out the (bw x bh) block size.
+ */
+ uint x, y;
+ for (y = 0; y < bh; y++) {
+ for (x = 0; x < bw; x++) {
+ if (x >= width || y >= height) {
+ uint p = (y * bw + x) * 4;
+ dst_p[p + 0] = dst_p[0];
+ dst_p[p + 1] = dst_p[1];
+ dst_p[p + 2] = dst_p[2];
+ dst_p[p + 3] = dst_p[3];
+ }
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Helper function to compress an image. The source is a 32-bpp RGBA image
+ * with stride==width.
+ */
+static void
+compress_image(enum pipe_format format, int datatype,
+ const void *src, uint8_t *dst,
+ unsigned width, unsigned height, unsigned dst_stride)
+{
+ const struct util_format_description *desc = util_format_description(format);
+ const uint src_stride = 4 * width;
+
+ if (datatype == GL_FLOAT)
+ desc->pack_rgba_float(dst, dst_stride, (GLfloat *)src, src_stride * sizeof(GLfloat), width, height);
+ else
+ desc->pack_rgba_8unorm(dst, dst_stride, (uint8_t *)src, src_stride, width, height);
+}
+
+
+/**
+ * Software fallback for generate mipmap levels.
+ */
+static void
+fallback_generate_mipmap(struct gl_context *ctx, GLenum target,
+ struct gl_texture_object *texObj)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct pipe_resource *pt = st_get_texobj_resource(texObj);
+ const uint baseLevel = texObj->BaseLevel;
+ const uint lastLevel = pt->last_level;
+ const uint face = _mesa_tex_target_to_face(target);
+ uint dstLevel;
+ GLenum datatype;
+ GLuint comps;
+ GLboolean compressed;
+
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
+
+ assert(target != GL_TEXTURE_3D); /* not done yet */
+
+ compressed =
+ _mesa_is_format_compressed(texObj->Image[face][baseLevel]->TexFormat);
+
+ if (compressed) {
+ if (texObj->Image[face][baseLevel]->TexFormat == MESA_FORMAT_SIGNED_RED_RGTC1 ||
+ texObj->Image[face][baseLevel]->TexFormat == MESA_FORMAT_SIGNED_RG_RGTC2)
+ datatype = GL_FLOAT;
+ else
+ datatype = GL_UNSIGNED_BYTE;
+
+ comps = 4;
+ }
+ else {
+ _mesa_format_to_type_and_comps(texObj->Image[face][baseLevel]->TexFormat,
+ &datatype, &comps);
+ assert(comps > 0 && "bad texture format in fallback_generate_mipmap()");
+ }
+
+ for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
+ const uint srcLevel = dstLevel - 1;
+ const uint srcWidth = u_minify(pt->width0, srcLevel);
+ const uint srcHeight = u_minify(pt->height0, srcLevel);
+ const uint srcDepth = u_minify(pt->depth0, srcLevel);
+ const uint dstWidth = u_minify(pt->width0, dstLevel);
+ const uint dstHeight = u_minify(pt->height0, dstLevel);
+ const uint dstDepth = u_minify(pt->depth0, dstLevel);
+ struct pipe_transfer *srcTrans, *dstTrans;
+ const ubyte *srcData;
+ ubyte *dstData;
+ int srcStride, dstStride;
+
+ srcTrans = pipe_get_transfer(st_context(ctx)->pipe, pt, srcLevel,
+ face,
+ PIPE_TRANSFER_READ, 0, 0,
+ srcWidth, srcHeight);
+
+ dstTrans = pipe_get_transfer(st_context(ctx)->pipe, pt, dstLevel,
+ face,
+ PIPE_TRANSFER_WRITE, 0, 0,
+ dstWidth, dstHeight);
+
+ srcData = (ubyte *) pipe_transfer_map(pipe, srcTrans);
+ dstData = (ubyte *) pipe_transfer_map(pipe, dstTrans);
+
+ srcStride = srcTrans->stride / util_format_get_blocksize(srcTrans->resource->format);
+ dstStride = dstTrans->stride / util_format_get_blocksize(dstTrans->resource->format);
+
+ /* this cannot work correctly for 3d since it does
+ not respect layerStride. */
+ if (compressed) {
+ const enum pipe_format format = pt->format;
+ const uint bw = util_format_get_blockwidth(format);
+ const uint bh = util_format_get_blockheight(format);
+ const uint srcWidth2 = align(srcWidth, bw);
+ const uint srcHeight2 = align(srcHeight, bh);
+ const uint dstWidth2 = align(dstWidth, bw);
+ const uint dstHeight2 = align(dstHeight, bh);
+ uint8_t *srcTemp, *dstTemp;
+
+ assert(comps == 4);
+
+ srcTemp = malloc(srcWidth2 * srcHeight2 * comps * (datatype == GL_FLOAT ? 4 : 1));
+ dstTemp = malloc(dstWidth2 * dstHeight2 * comps * (datatype == GL_FLOAT ? 4 : 1));
+
+ /* decompress the src image: srcData -> srcTemp */
+ decompress_image(format, datatype, srcData, srcTemp, srcWidth2, srcHeight2, srcTrans->stride);
+
+ _mesa_generate_mipmap_level(target, datatype, comps,
+ 0 /*border*/,
+ srcWidth2, srcHeight2, srcDepth,
+ srcTemp,
+ srcWidth2, /* stride in texels */
+ dstWidth2, dstHeight2, dstDepth,
+ dstTemp,
+ dstWidth2); /* stride in texels */
+
+ /* compress the new image: dstTemp -> dstData */
+ compress_image(format, datatype, dstTemp, dstData, dstWidth2, dstHeight2, dstTrans->stride);
+
+ free(srcTemp);
+ free(dstTemp);
+ }
+ else {
+ _mesa_generate_mipmap_level(target, datatype, comps,
+ 0 /*border*/,
+ srcWidth, srcHeight, srcDepth,
+ srcData,
+ srcStride, /* stride in texels */
+ dstWidth, dstHeight, dstDepth,
+ dstData,
+ dstStride); /* stride in texels */
+ }
+
+ pipe_transfer_unmap(pipe, srcTrans);
+ pipe_transfer_unmap(pipe, dstTrans);
+
+ pipe->transfer_destroy(pipe, srcTrans);
+ pipe->transfer_destroy(pipe, dstTrans);
+ }
+}
+
+
+/**
+ * Compute the expected number of mipmap levels in the texture given
+ * the width/height/depth of the base image and the GL_TEXTURE_BASE_LEVEL/
+ * GL_TEXTURE_MAX_LEVEL settings. This will tell us how many mipmap
+ * levels should be generated.
+ */
+static GLuint
+compute_num_levels(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ GLenum target)
+{
+ if (target == GL_TEXTURE_RECTANGLE_ARB) {
+ return 1;
+ }
+ else {
+ const struct gl_texture_image *baseImage =
+ _mesa_get_tex_image(ctx, texObj, target, texObj->BaseLevel);
+ GLuint size, numLevels;
+
+ size = MAX2(baseImage->Width2, baseImage->Height2);
+ size = MAX2(size, baseImage->Depth2);
+
+ numLevels = texObj->BaseLevel;
+
+ while (size > 0) {
+ numLevels++;
+ size >>= 1;
+ }
+
+ numLevels = MIN2(numLevels, texObj->MaxLevel + 1);
+
+ assert(numLevels >= 1);
+
+ return numLevels;
+ }
+}
+
+
+/**
+ * Called via ctx->Driver.GenerateMipmap().
+ */
+void
+st_generate_mipmap(struct gl_context *ctx, GLenum target,
+ struct gl_texture_object *texObj)
+{
+ struct st_context *st = st_context(ctx);
+ struct st_texture_object *stObj = st_texture_object(texObj);
+ struct pipe_resource *pt = st_get_texobj_resource(texObj);
+ const uint baseLevel = texObj->BaseLevel;
+ uint lastLevel;
+ uint dstLevel;
+
+ if (!pt)
+ return;
+
+ /* not sure if this ultimately actually should work,
+ but we're not supporting multisampled textures yet. */
+ assert(pt->nr_samples < 2);
+
+ /* find expected last mipmap level to generate*/
+ lastLevel = compute_num_levels(ctx, texObj, target) - 1;
+
+ if (lastLevel == 0)
+ return;
+
+ /* The texture isn't in a "complete" state yet so set the expected
+ * lastLevel here, since it won't get done in st_finalize_texture().
+ */
+ stObj->lastLevel = lastLevel;
+
+ if (pt->last_level < lastLevel) {
+ /* The current gallium texture doesn't have space for all the
+ * mipmap levels we need to generate. So allocate a new texture.
+ */
+ struct pipe_resource *oldTex = stObj->pt;
+
+ /* create new texture with space for more levels */
+ stObj->pt = st_texture_create(st,
+ oldTex->target,
+ oldTex->format,
+ lastLevel,
+ oldTex->width0,
+ oldTex->height0,
+ oldTex->depth0,
+ oldTex->array_size,
+ oldTex->bind);
+
+ /* This will copy the old texture's base image into the new texture
+ * which we just allocated.
+ */
+ st_finalize_texture(ctx, st->pipe, texObj);
+
+ /* release the old tex (will likely be freed too) */
+ pipe_resource_reference(&oldTex, NULL);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+ }
+ else {
+ /* Make sure that the base texture image data is present in the
+ * texture buffer.
+ */
+ st_finalize_texture(ctx, st->pipe, texObj);
+ }
+
+ pt = stObj->pt;
+
+ assert(pt->last_level >= lastLevel);
+
+ /* Try to generate the mipmap by rendering/texturing. If that fails,
+ * use the software fallback.
+ */
+ if (!st_render_mipmap(st, target, stObj, baseLevel, lastLevel)) {
+ /* since the util code actually also has a fallback, should
+ probably make it never fail and kill this */
+ fallback_generate_mipmap(ctx, target, texObj);
+ }
+
+ /* Fill in the Mesa gl_texture_image fields */
+ for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
+ const uint srcLevel = dstLevel - 1;
+ const struct gl_texture_image *srcImage
+ = _mesa_get_tex_image(ctx, texObj, target, srcLevel);
+ struct gl_texture_image *dstImage;
+ struct st_texture_image *stImage;
+ uint dstWidth = u_minify(pt->width0, dstLevel);
+ uint dstHeight = u_minify(pt->height0, dstLevel);
+ uint dstDepth = u_minify(pt->depth0, dstLevel);
+ uint border = srcImage->Border;
+
+ dstImage = _mesa_get_tex_image(ctx, texObj, target, dstLevel);
+ if (!dstImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
+ return;
+ }
+
+ /* Free old image data */
+ if (dstImage->Data)
+ ctx->Driver.FreeTexImageData(ctx, dstImage);
+
+ /* initialize new image */
+ _mesa_init_teximage_fields(ctx, target, dstImage, dstWidth, dstHeight,
+ dstDepth, border, srcImage->InternalFormat,
+ srcImage->TexFormat);
+
+ stImage = st_texture_image(dstImage);
+ stImage->level = dstLevel;
+
+ pipe_resource_reference(&stImage->pt, pt);
+ }
+}
diff --git a/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c b/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c
index c07739f9d..bf0bfd6df 100644
--- a/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -1,1249 +1,1249 @@
-/**************************************************************************
- *
- * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-/*
- * \author
- * Michal Krol,
- * Keith Whitwell
- */
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_context.h"
-#include "pipe/p_screen.h"
-#include "pipe/p_shader_tokens.h"
-#include "pipe/p_state.h"
-#include "tgsi/tgsi_ureg.h"
-#include "st_mesa_to_tgsi.h"
-#include "st_context.h"
-#include "program/prog_instruction.h"
-#include "program/prog_parameter.h"
-#include "util/u_debug.h"
-#include "util/u_math.h"
-#include "util/u_memory.h"
-
-
-#define PROGRAM_ANY_CONST ((1 << PROGRAM_LOCAL_PARAM) | \
- (1 << PROGRAM_ENV_PARAM) | \
- (1 << PROGRAM_STATE_VAR) | \
- (1 << PROGRAM_NAMED_PARAM) | \
- (1 << PROGRAM_CONSTANT) | \
- (1 << PROGRAM_UNIFORM))
-
-
-struct label {
- unsigned branch_target;
- unsigned token;
-};
-
-
-/**
- * Intermediate state used during shader translation.
- */
-struct st_translate {
- struct ureg_program *ureg;
-
- struct ureg_dst temps[MAX_PROGRAM_TEMPS];
- struct ureg_src *constants;
- struct ureg_dst outputs[PIPE_MAX_SHADER_OUTPUTS];
- struct ureg_src inputs[PIPE_MAX_SHADER_INPUTS];
- struct ureg_dst address[1];
- struct ureg_src samplers[PIPE_MAX_SAMPLERS];
- struct ureg_src systemValues[SYSTEM_VALUE_MAX];
-
- /* Extra info for handling point size clamping in vertex shader */
- struct ureg_dst pointSizeResult; /**< Actual point size output register */
- struct ureg_src pointSizeConst; /**< Point size range constant register */
- GLint pointSizeOutIndex; /**< Temp point size output register */
- GLboolean prevInstWrotePointSize;
-
- const GLuint *inputMapping;
- const GLuint *outputMapping;
-
- /* For every instruction that contains a label (eg CALL), keep
- * details so that we can go back afterwards and emit the correct
- * tgsi instruction number for each label.
- */
- struct label *labels;
- unsigned labels_size;
- unsigned labels_count;
-
- /* Keep a record of the tgsi instruction number that each mesa
- * instruction starts at, will be used to fix up labels after
- * translation.
- */
- unsigned *insn;
- unsigned insn_size;
- unsigned insn_count;
-
- unsigned procType; /**< TGSI_PROCESSOR_VERTEX/FRAGMENT */
-
- boolean error;
-};
-
-
-/** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */
-static unsigned mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = {
- TGSI_SEMANTIC_FACE,
- TGSI_SEMANTIC_INSTANCEID
-};
-
-
-/**
- * Make note of a branch to a label in the TGSI code.
- * After we've emitted all instructions, we'll go over the list
- * of labels built here and patch the TGSI code with the actual
- * location of each label.
- */
-static unsigned *get_label( struct st_translate *t,
- unsigned branch_target )
-{
- unsigned i;
-
- if (t->labels_count + 1 >= t->labels_size) {
- unsigned old_size = t->labels_size;
- t->labels_size = 1 << (util_logbase2(t->labels_size) + 1);
- t->labels = REALLOC( t->labels,
- old_size * sizeof t->labels[0],
- t->labels_size * sizeof t->labels[0] );
- if (t->labels == NULL) {
- static unsigned dummy;
- t->error = TRUE;
- return &dummy;
- }
- }
-
- i = t->labels_count++;
- t->labels[i].branch_target = branch_target;
- return &t->labels[i].token;
-}
-
-
-/**
- * Called prior to emitting the TGSI code for each Mesa instruction.
- * Allocate additional space for instructions if needed.
- * Update the insn[] array so the next Mesa instruction points to
- * the next TGSI instruction.
- */
-static void set_insn_start( struct st_translate *t,
- unsigned start )
-{
- if (t->insn_count + 1 >= t->insn_size) {
- unsigned old_size = t->insn_size;
- t->insn_size = 1 << (util_logbase2(t->insn_size) + 1);
- t->insn = REALLOC( t->insn,
- old_size * sizeof t->insn[0],
- t->insn_size * sizeof t->insn[0] );
- if (t->insn == NULL) {
- t->error = TRUE;
- return;
- }
- }
-
- t->insn[t->insn_count++] = start;
-}
-
-
-/**
- * Map a Mesa dst register to a TGSI ureg_dst register.
- */
-static struct ureg_dst
-dst_register( struct st_translate *t,
- gl_register_file file,
- GLuint index )
-{
- switch( file ) {
- case PROGRAM_UNDEFINED:
- return ureg_dst_undef();
-
- case PROGRAM_TEMPORARY:
- if (ureg_dst_is_undef(t->temps[index]))
- t->temps[index] = ureg_DECL_temporary( t->ureg );
-
- return t->temps[index];
-
- case PROGRAM_OUTPUT:
- if (t->procType == TGSI_PROCESSOR_VERTEX && index == VERT_RESULT_PSIZ)
- t->prevInstWrotePointSize = GL_TRUE;
-
- if (t->procType == TGSI_PROCESSOR_VERTEX)
- assert(index < VERT_RESULT_MAX);
- else if (t->procType == TGSI_PROCESSOR_FRAGMENT)
- assert(index < FRAG_RESULT_MAX);
- else
- assert(index < GEOM_RESULT_MAX);
-
- assert(t->outputMapping[index] < Elements(t->outputs));
-
- return t->outputs[t->outputMapping[index]];
-
- case PROGRAM_ADDRESS:
- return t->address[index];
-
- default:
- debug_assert( 0 );
- return ureg_dst_undef();
- }
-}
-
-
-/**
- * Map a Mesa src register to a TGSI ureg_src register.
- */
-static struct ureg_src
-src_register( struct st_translate *t,
- gl_register_file file,
- GLint index )
-{
- switch( file ) {
- case PROGRAM_UNDEFINED:
- return ureg_src_undef();
-
- case PROGRAM_TEMPORARY:
- assert(index >= 0);
- assert(index < Elements(t->temps));
- if (ureg_dst_is_undef(t->temps[index]))
- t->temps[index] = ureg_DECL_temporary( t->ureg );
- return ureg_src(t->temps[index]);
-
- case PROGRAM_NAMED_PARAM:
- case PROGRAM_ENV_PARAM:
- case PROGRAM_LOCAL_PARAM:
- case PROGRAM_UNIFORM:
- assert(index >= 0);
- return t->constants[index];
- case PROGRAM_STATE_VAR:
- case PROGRAM_CONSTANT: /* ie, immediate */
- if (index < 0)
- return ureg_DECL_constant( t->ureg, 0 );
- else
- return t->constants[index];
-
- case PROGRAM_INPUT:
- assert(t->inputMapping[index] < Elements(t->inputs));
- return t->inputs[t->inputMapping[index]];
-
- case PROGRAM_OUTPUT:
- assert(t->outputMapping[index] < Elements(t->outputs));
- return ureg_src(t->outputs[t->outputMapping[index]]); /* not needed? */
-
- case PROGRAM_ADDRESS:
- return ureg_src(t->address[index]);
-
- case PROGRAM_SYSTEM_VALUE:
- assert(index < Elements(t->systemValues));
- return t->systemValues[index];
-
- default:
- debug_assert( 0 );
- return ureg_src_undef();
- }
-}
-
-
-/**
- * Map mesa texture target to TGSI texture target.
- */
-static unsigned
-translate_texture_target( GLuint textarget,
- GLboolean shadow )
-{
- if (shadow) {
- switch( textarget ) {
- case TEXTURE_1D_INDEX: return TGSI_TEXTURE_SHADOW1D;
- case TEXTURE_2D_INDEX: return TGSI_TEXTURE_SHADOW2D;
- case TEXTURE_RECT_INDEX: return TGSI_TEXTURE_SHADOWRECT;
- default: break;
- }
- }
-
- switch( textarget ) {
- case TEXTURE_1D_INDEX: return TGSI_TEXTURE_1D;
- case TEXTURE_2D_INDEX: return TGSI_TEXTURE_2D;
- case TEXTURE_3D_INDEX: return TGSI_TEXTURE_3D;
- case TEXTURE_CUBE_INDEX: return TGSI_TEXTURE_CUBE;
- case TEXTURE_RECT_INDEX: return TGSI_TEXTURE_RECT;
- case TEXTURE_1D_ARRAY_INDEX: return TGSI_TEXTURE_1D_ARRAY;
- case TEXTURE_2D_ARRAY_INDEX: return TGSI_TEXTURE_2D_ARRAY;
- default:
- debug_assert( 0 );
- return TGSI_TEXTURE_1D;
- }
-}
-
-
-/**
- * Create a TGSI ureg_dst register from a Mesa dest register.
- */
-static struct ureg_dst
-translate_dst( struct st_translate *t,
- const struct prog_dst_register *DstReg,
- boolean saturate )
-{
- struct ureg_dst dst = dst_register( t,
- DstReg->File,
- DstReg->Index );
-
- dst = ureg_writemask( dst,
- DstReg->WriteMask );
-
- if (saturate)
- dst = ureg_saturate( dst );
-
- if (DstReg->RelAddr)
- dst = ureg_dst_indirect( dst, ureg_src(t->address[0]) );
-
- return dst;
-}
-
-
-/**
- * Create a TGSI ureg_src register from a Mesa src register.
- */
-static struct ureg_src
-translate_src( struct st_translate *t,
- const struct prog_src_register *SrcReg )
-{
- struct ureg_src src = src_register( t, SrcReg->File, SrcReg->Index );
-
- if (t->procType == TGSI_PROCESSOR_GEOMETRY && SrcReg->HasIndex2) {
- src = src_register( t, SrcReg->File, SrcReg->Index2 );
- if (SrcReg->RelAddr2)
- src = ureg_src_dimension_indirect( src, ureg_src(t->address[0]),
- SrcReg->Index);
- else
- src = ureg_src_dimension( src, SrcReg->Index);
- }
-
- src = ureg_swizzle( src,
- GET_SWZ( SrcReg->Swizzle, 0 ) & 0x3,
- GET_SWZ( SrcReg->Swizzle, 1 ) & 0x3,
- GET_SWZ( SrcReg->Swizzle, 2 ) & 0x3,
- GET_SWZ( SrcReg->Swizzle, 3 ) & 0x3);
-
- if (SrcReg->Negate == NEGATE_XYZW)
- src = ureg_negate(src);
-
- if (SrcReg->Abs)
- src = ureg_abs(src);
-
- if (SrcReg->RelAddr) {
- src = ureg_src_indirect( src, ureg_src(t->address[0]));
- if (SrcReg->File != PROGRAM_INPUT &&
- SrcReg->File != PROGRAM_OUTPUT) {
- /* If SrcReg->Index was negative, it was set to zero in
- * src_register(). Reassign it now. But don't do this
- * for input/output regs since they get remapped while
- * const buffers don't.
- */
- src.Index = SrcReg->Index;
- }
- }
-
- return src;
-}
-
-
-static struct ureg_src swizzle_4v( struct ureg_src src,
- const unsigned *swz )
-{
- return ureg_swizzle( src, swz[0], swz[1], swz[2], swz[3] );
-}
-
-
-/**
- * Translate a SWZ instruction into a MOV, MUL or MAD instruction. EG:
- *
- * SWZ dst, src.x-y10
- *
- * becomes:
- *
- * MAD dst {1,-1,0,0}, src.xyxx, {0,0,1,0}
- */
-static void emit_swz( struct st_translate *t,
- struct ureg_dst dst,
- const struct prog_src_register *SrcReg )
-{
- struct ureg_program *ureg = t->ureg;
- struct ureg_src src = src_register( t, SrcReg->File, SrcReg->Index );
-
- unsigned negate_mask = SrcReg->Negate;
-
- unsigned one_mask = ((GET_SWZ(SrcReg->Swizzle, 0) == SWIZZLE_ONE) << 0 |
- (GET_SWZ(SrcReg->Swizzle, 1) == SWIZZLE_ONE) << 1 |
- (GET_SWZ(SrcReg->Swizzle, 2) == SWIZZLE_ONE) << 2 |
- (GET_SWZ(SrcReg->Swizzle, 3) == SWIZZLE_ONE) << 3);
-
- unsigned zero_mask = ((GET_SWZ(SrcReg->Swizzle, 0) == SWIZZLE_ZERO) << 0 |
- (GET_SWZ(SrcReg->Swizzle, 1) == SWIZZLE_ZERO) << 1 |
- (GET_SWZ(SrcReg->Swizzle, 2) == SWIZZLE_ZERO) << 2 |
- (GET_SWZ(SrcReg->Swizzle, 3) == SWIZZLE_ZERO) << 3);
-
- unsigned negative_one_mask = one_mask & negate_mask;
- unsigned positive_one_mask = one_mask & ~negate_mask;
-
- struct ureg_src imm;
- unsigned i;
- unsigned mul_swizzle[4] = {0,0,0,0};
- unsigned add_swizzle[4] = {0,0,0,0};
- unsigned src_swizzle[4] = {0,0,0,0};
- boolean need_add = FALSE;
- boolean need_mul = FALSE;
-
- if (dst.WriteMask == 0)
- return;
-
- /* Is this just a MOV?
- */
- if (zero_mask == 0 &&
- one_mask == 0 &&
- (negate_mask == 0 || negate_mask == TGSI_WRITEMASK_XYZW))
- {
- ureg_MOV( ureg, dst, translate_src( t, SrcReg ));
- return;
- }
-
-#define IMM_ZERO 0
-#define IMM_ONE 1
-#define IMM_NEG_ONE 2
-
- imm = ureg_imm3f( ureg, 0, 1, -1 );
-
- for (i = 0; i < 4; i++) {
- unsigned bit = 1 << i;
-
- if (dst.WriteMask & bit) {
- if (positive_one_mask & bit) {
- mul_swizzle[i] = IMM_ZERO;
- add_swizzle[i] = IMM_ONE;
- need_add = TRUE;
- }
- else if (negative_one_mask & bit) {
- mul_swizzle[i] = IMM_ZERO;
- add_swizzle[i] = IMM_NEG_ONE;
- need_add = TRUE;
- }
- else if (zero_mask & bit) {
- mul_swizzle[i] = IMM_ZERO;
- add_swizzle[i] = IMM_ZERO;
- need_add = TRUE;
- }
- else {
- add_swizzle[i] = IMM_ZERO;
- src_swizzle[i] = GET_SWZ(SrcReg->Swizzle, i);
- need_mul = TRUE;
- if (negate_mask & bit) {
- mul_swizzle[i] = IMM_NEG_ONE;
- }
- else {
- mul_swizzle[i] = IMM_ONE;
- }
- }
- }
- }
-
- if (need_mul && need_add) {
- ureg_MAD( ureg,
- dst,
- swizzle_4v( src, src_swizzle ),
- swizzle_4v( imm, mul_swizzle ),
- swizzle_4v( imm, add_swizzle ) );
- }
- else if (need_mul) {
- ureg_MUL( ureg,
- dst,
- swizzle_4v( src, src_swizzle ),
- swizzle_4v( imm, mul_swizzle ) );
- }
- else if (need_add) {
- ureg_MOV( ureg,
- dst,
- swizzle_4v( imm, add_swizzle ) );
- }
- else {
- debug_assert(0);
- }
-
-#undef IMM_ZERO
-#undef IMM_ONE
-#undef IMM_NEG_ONE
-}
-
-
-/**
- * Negate the value of DDY to match GL semantics where (0,0) is the
- * lower-left corner of the window.
- * Note that the GL_ARB_fragment_coord_conventions extension will
- * effect this someday.
- */
-static void emit_ddy( struct st_translate *t,
- struct ureg_dst dst,
- const struct prog_src_register *SrcReg )
-{
- struct ureg_program *ureg = t->ureg;
- struct ureg_src src = translate_src( t, SrcReg );
- src = ureg_negate( src );
- ureg_DDY( ureg, dst, src );
-}
-
-
-
-static unsigned
-translate_opcode( unsigned op )
-{
- switch( op ) {
- case OPCODE_ARL:
- return TGSI_OPCODE_ARL;
- case OPCODE_ABS:
- return TGSI_OPCODE_ABS;
- case OPCODE_ADD:
- return TGSI_OPCODE_ADD;
- case OPCODE_BGNLOOP:
- return TGSI_OPCODE_BGNLOOP;
- case OPCODE_BGNSUB:
- return TGSI_OPCODE_BGNSUB;
- case OPCODE_BRA:
- return TGSI_OPCODE_BRA;
- case OPCODE_BRK:
- return TGSI_OPCODE_BRK;
- case OPCODE_CAL:
- return TGSI_OPCODE_CAL;
- case OPCODE_CMP:
- return TGSI_OPCODE_CMP;
- case OPCODE_CONT:
- return TGSI_OPCODE_CONT;
- case OPCODE_COS:
- return TGSI_OPCODE_COS;
- case OPCODE_DDX:
- return TGSI_OPCODE_DDX;
- case OPCODE_DDY:
- return TGSI_OPCODE_DDY;
- case OPCODE_DP2:
- return TGSI_OPCODE_DP2;
- case OPCODE_DP2A:
- return TGSI_OPCODE_DP2A;
- case OPCODE_DP3:
- return TGSI_OPCODE_DP3;
- case OPCODE_DP4:
- return TGSI_OPCODE_DP4;
- case OPCODE_DPH:
- return TGSI_OPCODE_DPH;
- case OPCODE_DST:
- return TGSI_OPCODE_DST;
- case OPCODE_ELSE:
- return TGSI_OPCODE_ELSE;
- case OPCODE_EMIT_VERTEX:
- return TGSI_OPCODE_EMIT;
- case OPCODE_END_PRIMITIVE:
- return TGSI_OPCODE_ENDPRIM;
- case OPCODE_ENDIF:
- return TGSI_OPCODE_ENDIF;
- case OPCODE_ENDLOOP:
- return TGSI_OPCODE_ENDLOOP;
- case OPCODE_ENDSUB:
- return TGSI_OPCODE_ENDSUB;
- case OPCODE_EX2:
- return TGSI_OPCODE_EX2;
- case OPCODE_EXP:
- return TGSI_OPCODE_EXP;
- case OPCODE_FLR:
- return TGSI_OPCODE_FLR;
- case OPCODE_FRC:
- return TGSI_OPCODE_FRC;
- case OPCODE_IF:
- return TGSI_OPCODE_IF;
- case OPCODE_TRUNC:
- return TGSI_OPCODE_TRUNC;
- case OPCODE_KIL:
- return TGSI_OPCODE_KIL;
- case OPCODE_KIL_NV:
- return TGSI_OPCODE_KILP;
- case OPCODE_LG2:
- return TGSI_OPCODE_LG2;
- case OPCODE_LOG:
- return TGSI_OPCODE_LOG;
- case OPCODE_LIT:
- return TGSI_OPCODE_LIT;
- case OPCODE_LRP:
- return TGSI_OPCODE_LRP;
- case OPCODE_MAD:
- return TGSI_OPCODE_MAD;
- case OPCODE_MAX:
- return TGSI_OPCODE_MAX;
- case OPCODE_MIN:
- return TGSI_OPCODE_MIN;
- case OPCODE_MOV:
- return TGSI_OPCODE_MOV;
- case OPCODE_MUL:
- return TGSI_OPCODE_MUL;
- case OPCODE_NOP:
- return TGSI_OPCODE_NOP;
- case OPCODE_NRM3:
- return TGSI_OPCODE_NRM;
- case OPCODE_NRM4:
- return TGSI_OPCODE_NRM4;
- case OPCODE_POW:
- return TGSI_OPCODE_POW;
- case OPCODE_RCP:
- return TGSI_OPCODE_RCP;
- case OPCODE_RET:
- return TGSI_OPCODE_RET;
- case OPCODE_RSQ:
- return TGSI_OPCODE_RSQ;
- case OPCODE_SCS:
- return TGSI_OPCODE_SCS;
- case OPCODE_SEQ:
- return TGSI_OPCODE_SEQ;
- case OPCODE_SGE:
- return TGSI_OPCODE_SGE;
- case OPCODE_SGT:
- return TGSI_OPCODE_SGT;
- case OPCODE_SIN:
- return TGSI_OPCODE_SIN;
- case OPCODE_SLE:
- return TGSI_OPCODE_SLE;
- case OPCODE_SLT:
- return TGSI_OPCODE_SLT;
- case OPCODE_SNE:
- return TGSI_OPCODE_SNE;
- case OPCODE_SSG:
- return TGSI_OPCODE_SSG;
- case OPCODE_SUB:
- return TGSI_OPCODE_SUB;
- case OPCODE_TEX:
- return TGSI_OPCODE_TEX;
- case OPCODE_TXB:
- return TGSI_OPCODE_TXB;
- case OPCODE_TXD:
- return TGSI_OPCODE_TXD;
- case OPCODE_TXL:
- return TGSI_OPCODE_TXL;
- case OPCODE_TXP:
- return TGSI_OPCODE_TXP;
- case OPCODE_XPD:
- return TGSI_OPCODE_XPD;
- case OPCODE_END:
- return TGSI_OPCODE_END;
- default:
- debug_assert( 0 );
- return TGSI_OPCODE_NOP;
- }
-}
-
-
-static void
-compile_instruction(
- struct st_translate *t,
- const struct prog_instruction *inst )
-{
- struct ureg_program *ureg = t->ureg;
- GLuint i;
- struct ureg_dst dst[1];
- struct ureg_src src[4];
- unsigned num_dst;
- unsigned num_src;
-
- num_dst = _mesa_num_inst_dst_regs( inst->Opcode );
- num_src = _mesa_num_inst_src_regs( inst->Opcode );
-
- if (num_dst)
- dst[0] = translate_dst( t,
- &inst->DstReg,
- inst->SaturateMode );
-
- for (i = 0; i < num_src; i++)
- src[i] = translate_src( t, &inst->SrcReg[i] );
-
- switch( inst->Opcode ) {
- case OPCODE_SWZ:
- emit_swz( t, dst[0], &inst->SrcReg[0] );
- return;
-
- case OPCODE_BGNLOOP:
- case OPCODE_CAL:
- case OPCODE_ELSE:
- case OPCODE_ENDLOOP:
- case OPCODE_IF:
- debug_assert(num_dst == 0);
- ureg_label_insn( ureg,
- translate_opcode( inst->Opcode ),
- src, num_src,
- get_label( t, inst->BranchTarget ));
- return;
-
- case OPCODE_TEX:
- case OPCODE_TXB:
- case OPCODE_TXD:
- case OPCODE_TXL:
- case OPCODE_TXP:
- src[num_src++] = t->samplers[inst->TexSrcUnit];
- ureg_tex_insn( ureg,
- translate_opcode( inst->Opcode ),
- dst, num_dst,
- translate_texture_target( inst->TexSrcTarget,
- inst->TexShadow ),
- src, num_src );
- return;
-
- case OPCODE_SCS:
- dst[0] = ureg_writemask(dst[0], TGSI_WRITEMASK_XY );
- ureg_insn( ureg,
- translate_opcode( inst->Opcode ),
- dst, num_dst,
- src, num_src );
- break;
-
- case OPCODE_XPD:
- dst[0] = ureg_writemask(dst[0], TGSI_WRITEMASK_XYZ );
- ureg_insn( ureg,
- translate_opcode( inst->Opcode ),
- dst, num_dst,
- src, num_src );
- break;
-
- case OPCODE_NOISE1:
- case OPCODE_NOISE2:
- case OPCODE_NOISE3:
- case OPCODE_NOISE4:
- /* At some point, a motivated person could add a better
- * implementation of noise. Currently not even the nvidia
- * binary drivers do anything more than this. In any case, the
- * place to do this is in the GL state tracker, not the poor
- * driver.
- */
- ureg_MOV( ureg, dst[0], ureg_imm1f(ureg, 0.5) );
- break;
-
- case OPCODE_DDY:
- emit_ddy( t, dst[0], &inst->SrcReg[0] );
- break;
-
- default:
- ureg_insn( ureg,
- translate_opcode( inst->Opcode ),
- dst, num_dst,
- src, num_src );
- break;
- }
-}
-
-
-/**
- * Emit the TGSI instructions to adjust the WPOS pixel center convention
- * Basically, add (adjX, adjY) to the fragment position.
- */
-static void
-emit_adjusted_wpos( struct st_translate *t,
- const struct gl_program *program,
- GLfloat adjX, GLfloat adjY)
-{
- struct ureg_program *ureg = t->ureg;
- struct ureg_dst wpos_temp = ureg_DECL_temporary(ureg);
- struct ureg_src wpos_input = t->inputs[t->inputMapping[FRAG_ATTRIB_WPOS]];
-
- /* Note that we bias X and Y and pass Z and W through unchanged.
- * The shader might also use gl_FragCoord.w and .z.
- */
- ureg_ADD(ureg, wpos_temp, wpos_input,
- ureg_imm4f(ureg, adjX, adjY, 0.0f, 0.0f));
-
- t->inputs[t->inputMapping[FRAG_ATTRIB_WPOS]] = ureg_src(wpos_temp);
-}
-
-
-/**
- * Emit the TGSI instructions for inverting the WPOS y coordinate.
- * This code is unavoidable because it also depends on whether
- * a FBO is bound (STATE_FB_WPOS_Y_TRANSFORM).
- */
-static void
-emit_wpos_inversion( struct st_translate *t,
- const struct gl_program *program,
- boolean invert)
-{
- struct ureg_program *ureg = t->ureg;
-
- /* Fragment program uses fragment position input.
- * Need to replace instances of INPUT[WPOS] with temp T
- * where T = INPUT[WPOS] by y is inverted.
- */
- static const gl_state_index wposTransformState[STATE_LENGTH]
- = { STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM, 0, 0, 0 };
-
- /* XXX: note we are modifying the incoming shader here! Need to
- * do this before emitting the constant decls below, or this
- * will be missed:
- */
- unsigned wposTransConst = _mesa_add_state_reference(program->Parameters,
- wposTransformState);
-
- struct ureg_src wpostrans = ureg_DECL_constant( ureg, wposTransConst );
- struct ureg_dst wpos_temp;
- struct ureg_src wpos_input = t->inputs[t->inputMapping[FRAG_ATTRIB_WPOS]];
-
- /* MOV wpos_temp, input[wpos]
- */
- if (wpos_input.File == TGSI_FILE_TEMPORARY)
- wpos_temp = ureg_dst(wpos_input);
- else {
- wpos_temp = ureg_DECL_temporary( ureg );
- ureg_MOV( ureg, wpos_temp, wpos_input );
- }
-
- if (invert) {
- /* MAD wpos_temp.y, wpos_input, wpostrans.xxxx, wpostrans.yyyy
- */
- ureg_MAD( ureg,
- ureg_writemask(wpos_temp, TGSI_WRITEMASK_Y ),
- wpos_input,
- ureg_scalar(wpostrans, 0),
- ureg_scalar(wpostrans, 1));
- } else {
- /* MAD wpos_temp.y, wpos_input, wpostrans.zzzz, wpostrans.wwww
- */
- ureg_MAD( ureg,
- ureg_writemask(wpos_temp, TGSI_WRITEMASK_Y ),
- wpos_input,
- ureg_scalar(wpostrans, 2),
- ureg_scalar(wpostrans, 3));
- }
-
- /* Use wpos_temp as position input from here on:
- */
- t->inputs[t->inputMapping[FRAG_ATTRIB_WPOS]] = ureg_src(wpos_temp);
-}
-
-
-/**
- * Emit fragment position/ooordinate code.
- */
-static void
-emit_wpos(struct st_context *st,
- struct st_translate *t,
- const struct gl_program *program,
- struct ureg_program *ureg)
-{
- const struct gl_fragment_program *fp =
- (const struct gl_fragment_program *) program;
- struct pipe_screen *pscreen = st->pipe->screen;
- boolean invert = FALSE;
-
- if (fp->OriginUpperLeft) {
- /* Fragment shader wants origin in upper-left */
- if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT)) {
- /* the driver supports upper-left origin */
- }
- else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT)) {
- /* the driver supports lower-left origin, need to invert Y */
- ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT);
- invert = TRUE;
- }
- else
- assert(0);
- }
- else {
- /* Fragment shader wants origin in lower-left */
- if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT))
- /* the driver supports lower-left origin */
- ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT);
- else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT))
- /* the driver supports upper-left origin, need to invert Y */
- invert = TRUE;
- else
- assert(0);
- }
-
- if (fp->PixelCenterInteger) {
- /* Fragment shader wants pixel center integer */
- if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER))
- /* the driver supports pixel center integer */
- ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER);
- else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER))
- /* the driver supports pixel center half integer, need to bias X,Y */
- emit_adjusted_wpos(t, program, 0.5f, invert ? 0.5f : -0.5f);
- else
- assert(0);
- }
- else {
- /* Fragment shader wants pixel center half integer */
- if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER)) {
- /* the driver supports pixel center half integer */
- }
- else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER)) {
- /* the driver supports pixel center integer, need to bias X,Y */
- ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER);
- emit_adjusted_wpos(t, program, 0.5f, invert ? -0.5f : 0.5f);
- }
- else
- assert(0);
- }
-
- /* we invert after adjustment so that we avoid the MOV to temporary,
- * and reuse the adjustment ADD instead */
- emit_wpos_inversion(t, program, invert);
-}
-
-
-/**
- * OpenGL's fragment gl_FrontFace input is 1 for front-facing, 0 for back.
- * TGSI uses +1 for front, -1 for back.
- * This function converts the TGSI value to the GL value. Simply clamping/
- * saturating the value to [0,1] does the job.
- */
-static void
-emit_face_var( struct st_translate *t,
- const struct gl_program *program )
-{
- struct ureg_program *ureg = t->ureg;
- struct ureg_dst face_temp = ureg_DECL_temporary( ureg );
- struct ureg_src face_input = t->inputs[t->inputMapping[FRAG_ATTRIB_FACE]];
-
- /* MOV_SAT face_temp, input[face]
- */
- face_temp = ureg_saturate( face_temp );
- ureg_MOV( ureg, face_temp, face_input );
-
- /* Use face_temp as face input from here on:
- */
- t->inputs[t->inputMapping[FRAG_ATTRIB_FACE]] = ureg_src(face_temp);
-}
-
-
-static void
-emit_edgeflags( struct st_translate *t,
- const struct gl_program *program )
-{
- struct ureg_program *ureg = t->ureg;
- struct ureg_dst edge_dst = t->outputs[t->outputMapping[VERT_RESULT_EDGE]];
- struct ureg_src edge_src = t->inputs[t->inputMapping[VERT_ATTRIB_EDGEFLAG]];
-
- ureg_MOV( ureg, edge_dst, edge_src );
-}
-
-
-/**
- * Translate Mesa program to TGSI format.
- * \param program the program to translate
- * \param numInputs number of input registers used
- * \param inputMapping maps Mesa fragment program inputs to TGSI generic
- * input indexes
- * \param inputSemanticName the TGSI_SEMANTIC flag for each input
- * \param inputSemanticIndex the semantic index (ex: which texcoord) for
- * each input
- * \param interpMode the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input
- * \param numOutputs number of output registers used
- * \param outputMapping maps Mesa fragment program outputs to TGSI
- * generic outputs
- * \param outputSemanticName the TGSI_SEMANTIC flag for each output
- * \param outputSemanticIndex the semantic index (ex: which texcoord) for
- * each output
- *
- * \return PIPE_OK or PIPE_ERROR_OUT_OF_MEMORY
- */
-enum pipe_error
-st_translate_mesa_program(
- struct gl_context *ctx,
- uint procType,
- struct ureg_program *ureg,
- const struct gl_program *program,
- GLuint numInputs,
- const GLuint inputMapping[],
- const ubyte inputSemanticName[],
- const ubyte inputSemanticIndex[],
- const GLuint interpMode[],
- GLuint numOutputs,
- const GLuint outputMapping[],
- const ubyte outputSemanticName[],
- const ubyte outputSemanticIndex[],
- boolean passthrough_edgeflags )
-{
- struct st_translate translate, *t;
- unsigned i;
- enum pipe_error ret = PIPE_OK;
-
- assert(numInputs <= Elements(t->inputs));
- assert(numOutputs <= Elements(t->outputs));
-
- t = &translate;
- memset(t, 0, sizeof *t);
-
- t->procType = procType;
- t->inputMapping = inputMapping;
- t->outputMapping = outputMapping;
- t->ureg = ureg;
- t->pointSizeOutIndex = -1;
- t->prevInstWrotePointSize = GL_FALSE;
-
- /*_mesa_print_program(program);*/
-
- /*
- * Declare input attributes.
- */
- if (procType == TGSI_PROCESSOR_FRAGMENT) {
- for (i = 0; i < numInputs; i++) {
- if (program->InputFlags[0] & PROG_PARAM_BIT_CYL_WRAP) {
- t->inputs[i] = ureg_DECL_fs_input_cyl(ureg,
- inputSemanticName[i],
- inputSemanticIndex[i],
- interpMode[i],
- TGSI_CYLINDRICAL_WRAP_X);
- }
- else {
- t->inputs[i] = ureg_DECL_fs_input(ureg,
- inputSemanticName[i],
- inputSemanticIndex[i],
- interpMode[i]);
- }
- }
-
- if (program->InputsRead & FRAG_BIT_WPOS) {
- /* Must do this after setting up t->inputs, and before
- * emitting constant references, below:
- */
- emit_wpos(st_context(ctx), t, program, ureg);
- }
-
- if (program->InputsRead & FRAG_BIT_FACE) {
- emit_face_var( t, program );
- }
-
- /*
- * Declare output attributes.
- */
- for (i = 0; i < numOutputs; i++) {
- switch (outputSemanticName[i]) {
- case TGSI_SEMANTIC_POSITION:
- t->outputs[i] = ureg_DECL_output( ureg,
- TGSI_SEMANTIC_POSITION, /* Z / Depth */
- outputSemanticIndex[i] );
-
- t->outputs[i] = ureg_writemask( t->outputs[i],
- TGSI_WRITEMASK_Z );
- break;
- case TGSI_SEMANTIC_STENCIL:
- t->outputs[i] = ureg_DECL_output( ureg,
- TGSI_SEMANTIC_STENCIL, /* Stencil */
- outputSemanticIndex[i] );
- t->outputs[i] = ureg_writemask( t->outputs[i],
- TGSI_WRITEMASK_Y );
- break;
- case TGSI_SEMANTIC_COLOR:
- t->outputs[i] = ureg_DECL_output( ureg,
- TGSI_SEMANTIC_COLOR,
- outputSemanticIndex[i] );
- break;
- default:
- debug_assert(0);
- return 0;
- }
- }
- }
- else if (procType == TGSI_PROCESSOR_GEOMETRY) {
- for (i = 0; i < numInputs; i++) {
- t->inputs[i] = ureg_DECL_gs_input(ureg,
- i,
- inputSemanticName[i],
- inputSemanticIndex[i]);
- }
-
- for (i = 0; i < numOutputs; i++) {
- t->outputs[i] = ureg_DECL_output( ureg,
- outputSemanticName[i],
- outputSemanticIndex[i] );
- }
- }
- else {
- assert(procType == TGSI_PROCESSOR_VERTEX);
-
- for (i = 0; i < numInputs; i++) {
- t->inputs[i] = ureg_DECL_vs_input(ureg, i);
- }
-
- for (i = 0; i < numOutputs; i++) {
- t->outputs[i] = ureg_DECL_output( ureg,
- outputSemanticName[i],
- outputSemanticIndex[i] );
- if ((outputSemanticName[i] == TGSI_SEMANTIC_PSIZE) && program->Id) {
- /* Writing to the point size result register requires special
- * handling to implement clamping.
- */
- static const gl_state_index pointSizeClampState[STATE_LENGTH]
- = { STATE_INTERNAL, STATE_POINT_SIZE_IMPL_CLAMP, 0, 0, 0 };
- /* XXX: note we are modifying the incoming shader here! Need to
- * do this before emitting the constant decls below, or this
- * will be missed:
- */
- unsigned pointSizeClampConst =
- _mesa_add_state_reference(program->Parameters,
- pointSizeClampState);
- struct ureg_dst psizregtemp = ureg_DECL_temporary( ureg );
- t->pointSizeConst = ureg_DECL_constant( ureg, pointSizeClampConst );
- t->pointSizeResult = t->outputs[i];
- t->pointSizeOutIndex = i;
- t->outputs[i] = psizregtemp;
- }
- }
- if (passthrough_edgeflags)
- emit_edgeflags( t, program );
- }
-
- /* Declare address register.
- */
- if (program->NumAddressRegs > 0) {
- debug_assert( program->NumAddressRegs == 1 );
- t->address[0] = ureg_DECL_address( ureg );
- }
-
- /* Declare misc input registers
- */
- {
- GLbitfield sysInputs = program->SystemValuesRead;
- unsigned numSys = 0;
- for (i = 0; sysInputs; i++) {
- if (sysInputs & (1 << i)) {
- unsigned semName = mesa_sysval_to_semantic[i];
- t->systemValues[i] = ureg_DECL_system_value(ureg, numSys, semName, 0);
- numSys++;
- sysInputs &= ~(1 << i);
- }
- }
- }
-
- if (program->IndirectRegisterFiles & (1 << PROGRAM_TEMPORARY)) {
- /* If temps are accessed with indirect addressing, declare temporaries
- * in sequential order. Else, we declare them on demand elsewhere.
- */
- for (i = 0; i < program->NumTemporaries; i++) {
- /* XXX use TGSI_FILE_TEMPORARY_ARRAY when it's supported by ureg */
- t->temps[i] = ureg_DECL_temporary( t->ureg );
- }
- }
-
- /* Emit constants and immediates. Mesa uses a single index space
- * for these, so we put all the translated regs in t->constants.
- */
- if (program->Parameters) {
- t->constants = CALLOC( program->Parameters->NumParameters,
- sizeof t->constants[0] );
- if (t->constants == NULL) {
- ret = PIPE_ERROR_OUT_OF_MEMORY;
- goto out;
- }
-
- for (i = 0; i < program->Parameters->NumParameters; i++) {
- switch (program->Parameters->Parameters[i].Type) {
- case PROGRAM_ENV_PARAM:
- case PROGRAM_LOCAL_PARAM:
- case PROGRAM_STATE_VAR:
- case PROGRAM_NAMED_PARAM:
- case PROGRAM_UNIFORM:
- t->constants[i] = ureg_DECL_constant( ureg, i );
- break;
-
- /* Emit immediates only when there's no indirect addressing of
- * the const buffer.
- * FIXME: Be smarter and recognize param arrays:
- * indirect addressing is only valid within the referenced
- * array.
- */
- case PROGRAM_CONSTANT:
- if (program->IndirectRegisterFiles & PROGRAM_ANY_CONST)
- t->constants[i] = ureg_DECL_constant( ureg, i );
- else
- t->constants[i] =
- ureg_DECL_immediate( ureg,
- program->Parameters->ParameterValues[i],
- 4 );
- break;
- default:
- break;
- }
- }
- }
-
- /* texture samplers */
- for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
- if (program->SamplersUsed & (1 << i)) {
- t->samplers[i] = ureg_DECL_sampler( ureg, i );
- }
- }
-
- /* Emit each instruction in turn:
- */
- for (i = 0; i < program->NumInstructions; i++) {
- set_insn_start( t, ureg_get_instruction_number( ureg ));
- compile_instruction( t, &program->Instructions[i] );
-
- if (t->prevInstWrotePointSize && program->Id) {
- /* The previous instruction wrote to the (fake) vertex point size
- * result register. Now we need to clamp that value to the min/max
- * point size range, putting the result into the real point size
- * register.
- * Note that we can't do this easily at the end of program due to
- * possible early return.
- */
- set_insn_start( t, ureg_get_instruction_number( ureg ));
- ureg_MAX( t->ureg,
- ureg_writemask(t->outputs[t->pointSizeOutIndex], WRITEMASK_X),
- ureg_src(t->outputs[t->pointSizeOutIndex]),
- ureg_swizzle(t->pointSizeConst, 1,1,1,1));
- ureg_MIN( t->ureg, ureg_writemask(t->pointSizeResult, WRITEMASK_X),
- ureg_src(t->outputs[t->pointSizeOutIndex]),
- ureg_swizzle(t->pointSizeConst, 2,2,2,2));
- }
- t->prevInstWrotePointSize = GL_FALSE;
- }
-
- /* Fix up all emitted labels:
- */
- for (i = 0; i < t->labels_count; i++) {
- ureg_fixup_label( ureg,
- t->labels[i].token,
- t->insn[t->labels[i].branch_target] );
- }
-
-out:
- FREE(t->insn);
- FREE(t->labels);
- FREE(t->constants);
-
- if (t->error) {
- debug_printf("%s: translate error flag set\n", __FUNCTION__);
- }
-
- return ret;
-}
-
-
-/**
- * Tokens cannot be free with free otherwise the builtin gallium
- * malloc debugging will get confused.
- */
-void
-st_free_tokens(const struct tgsi_token *tokens)
-{
- FREE((void *)tokens);
-}
+/**************************************************************************
+ *
+ * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/*
+ * \author
+ * Michal Krol,
+ * Keith Whitwell
+ */
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_context.h"
+#include "pipe/p_screen.h"
+#include "pipe/p_shader_tokens.h"
+#include "pipe/p_state.h"
+#include "tgsi/tgsi_ureg.h"
+#include "st_mesa_to_tgsi.h"
+#include "st_context.h"
+#include "program/prog_instruction.h"
+#include "program/prog_parameter.h"
+#include "util/u_debug.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+
+
+#define PROGRAM_ANY_CONST ((1 << PROGRAM_LOCAL_PARAM) | \
+ (1 << PROGRAM_ENV_PARAM) | \
+ (1 << PROGRAM_STATE_VAR) | \
+ (1 << PROGRAM_NAMED_PARAM) | \
+ (1 << PROGRAM_CONSTANT) | \
+ (1 << PROGRAM_UNIFORM))
+
+
+struct label {
+ unsigned branch_target;
+ unsigned token;
+};
+
+
+/**
+ * Intermediate state used during shader translation.
+ */
+struct st_translate {
+ struct ureg_program *ureg;
+
+ struct ureg_dst temps[MAX_PROGRAM_TEMPS];
+ struct ureg_src *constants;
+ struct ureg_dst outputs[PIPE_MAX_SHADER_OUTPUTS];
+ struct ureg_src inputs[PIPE_MAX_SHADER_INPUTS];
+ struct ureg_dst address[1];
+ struct ureg_src samplers[PIPE_MAX_SAMPLERS];
+ struct ureg_src systemValues[SYSTEM_VALUE_MAX];
+
+ /* Extra info for handling point size clamping in vertex shader */
+ struct ureg_dst pointSizeResult; /**< Actual point size output register */
+ struct ureg_src pointSizeConst; /**< Point size range constant register */
+ GLint pointSizeOutIndex; /**< Temp point size output register */
+ GLboolean prevInstWrotePointSize;
+
+ const GLuint *inputMapping;
+ const GLuint *outputMapping;
+
+ /* For every instruction that contains a label (eg CALL), keep
+ * details so that we can go back afterwards and emit the correct
+ * tgsi instruction number for each label.
+ */
+ struct label *labels;
+ unsigned labels_size;
+ unsigned labels_count;
+
+ /* Keep a record of the tgsi instruction number that each mesa
+ * instruction starts at, will be used to fix up labels after
+ * translation.
+ */
+ unsigned *insn;
+ unsigned insn_size;
+ unsigned insn_count;
+
+ unsigned procType; /**< TGSI_PROCESSOR_VERTEX/FRAGMENT */
+
+ boolean error;
+};
+
+
+/** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */
+static unsigned mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = {
+ TGSI_SEMANTIC_FACE,
+ TGSI_SEMANTIC_INSTANCEID
+};
+
+
+/**
+ * Make note of a branch to a label in the TGSI code.
+ * After we've emitted all instructions, we'll go over the list
+ * of labels built here and patch the TGSI code with the actual
+ * location of each label.
+ */
+static unsigned *get_label( struct st_translate *t,
+ unsigned branch_target )
+{
+ unsigned i;
+
+ if (t->labels_count + 1 >= t->labels_size) {
+ unsigned old_size = t->labels_size;
+ t->labels_size = 1 << (util_logbase2(t->labels_size) + 1);
+ t->labels = REALLOC( t->labels,
+ old_size * sizeof t->labels[0],
+ t->labels_size * sizeof t->labels[0] );
+ if (t->labels == NULL) {
+ static unsigned dummy;
+ t->error = TRUE;
+ return &dummy;
+ }
+ }
+
+ i = t->labels_count++;
+ t->labels[i].branch_target = branch_target;
+ return &t->labels[i].token;
+}
+
+
+/**
+ * Called prior to emitting the TGSI code for each Mesa instruction.
+ * Allocate additional space for instructions if needed.
+ * Update the insn[] array so the next Mesa instruction points to
+ * the next TGSI instruction.
+ */
+static void set_insn_start( struct st_translate *t,
+ unsigned start )
+{
+ if (t->insn_count + 1 >= t->insn_size) {
+ unsigned old_size = t->insn_size;
+ t->insn_size = 1 << (util_logbase2(t->insn_size) + 1);
+ t->insn = REALLOC( t->insn,
+ old_size * sizeof t->insn[0],
+ t->insn_size * sizeof t->insn[0] );
+ if (t->insn == NULL) {
+ t->error = TRUE;
+ return;
+ }
+ }
+
+ t->insn[t->insn_count++] = start;
+}
+
+
+/**
+ * Map a Mesa dst register to a TGSI ureg_dst register.
+ */
+static struct ureg_dst
+dst_register( struct st_translate *t,
+ gl_register_file file,
+ GLuint index )
+{
+ switch( file ) {
+ case PROGRAM_UNDEFINED:
+ return ureg_dst_undef();
+
+ case PROGRAM_TEMPORARY:
+ if (ureg_dst_is_undef(t->temps[index]))
+ t->temps[index] = ureg_DECL_temporary( t->ureg );
+
+ return t->temps[index];
+
+ case PROGRAM_OUTPUT:
+ if (t->procType == TGSI_PROCESSOR_VERTEX && index == VERT_RESULT_PSIZ)
+ t->prevInstWrotePointSize = GL_TRUE;
+
+ if (t->procType == TGSI_PROCESSOR_VERTEX)
+ assert(index < VERT_RESULT_MAX);
+ else if (t->procType == TGSI_PROCESSOR_FRAGMENT)
+ assert(index < FRAG_RESULT_MAX);
+ else
+ assert(index < GEOM_RESULT_MAX);
+
+ assert(t->outputMapping[index] < Elements(t->outputs));
+
+ return t->outputs[t->outputMapping[index]];
+
+ case PROGRAM_ADDRESS:
+ return t->address[index];
+
+ default:
+ debug_assert( 0 );
+ return ureg_dst_undef();
+ }
+}
+
+
+/**
+ * Map a Mesa src register to a TGSI ureg_src register.
+ */
+static struct ureg_src
+src_register( struct st_translate *t,
+ gl_register_file file,
+ GLint index )
+{
+ switch( file ) {
+ case PROGRAM_UNDEFINED:
+ return ureg_src_undef();
+
+ case PROGRAM_TEMPORARY:
+ assert(index >= 0);
+ assert(index < Elements(t->temps));
+ if (ureg_dst_is_undef(t->temps[index]))
+ t->temps[index] = ureg_DECL_temporary( t->ureg );
+ return ureg_src(t->temps[index]);
+
+ case PROGRAM_NAMED_PARAM:
+ case PROGRAM_ENV_PARAM:
+ case PROGRAM_LOCAL_PARAM:
+ case PROGRAM_UNIFORM:
+ assert(index >= 0);
+ return t->constants[index];
+ case PROGRAM_STATE_VAR:
+ case PROGRAM_CONSTANT: /* ie, immediate */
+ if (index < 0)
+ return ureg_DECL_constant( t->ureg, 0 );
+ else
+ return t->constants[index];
+
+ case PROGRAM_INPUT:
+ assert(t->inputMapping[index] < Elements(t->inputs));
+ return t->inputs[t->inputMapping[index]];
+
+ case PROGRAM_OUTPUT:
+ assert(t->outputMapping[index] < Elements(t->outputs));
+ return ureg_src(t->outputs[t->outputMapping[index]]); /* not needed? */
+
+ case PROGRAM_ADDRESS:
+ return ureg_src(t->address[index]);
+
+ case PROGRAM_SYSTEM_VALUE:
+ assert(index < Elements(t->systemValues));
+ return t->systemValues[index];
+
+ default:
+ debug_assert( 0 );
+ return ureg_src_undef();
+ }
+}
+
+
+/**
+ * Map mesa texture target to TGSI texture target.
+ */
+static unsigned
+translate_texture_target( GLuint textarget,
+ GLboolean shadow )
+{
+ if (shadow) {
+ switch( textarget ) {
+ case TEXTURE_1D_INDEX: return TGSI_TEXTURE_SHADOW1D;
+ case TEXTURE_2D_INDEX: return TGSI_TEXTURE_SHADOW2D;
+ case TEXTURE_RECT_INDEX: return TGSI_TEXTURE_SHADOWRECT;
+ default: break;
+ }
+ }
+
+ switch( textarget ) {
+ case TEXTURE_1D_INDEX: return TGSI_TEXTURE_1D;
+ case TEXTURE_2D_INDEX: return TGSI_TEXTURE_2D;
+ case TEXTURE_3D_INDEX: return TGSI_TEXTURE_3D;
+ case TEXTURE_CUBE_INDEX: return TGSI_TEXTURE_CUBE;
+ case TEXTURE_RECT_INDEX: return TGSI_TEXTURE_RECT;
+ case TEXTURE_1D_ARRAY_INDEX: return TGSI_TEXTURE_1D_ARRAY;
+ case TEXTURE_2D_ARRAY_INDEX: return TGSI_TEXTURE_2D_ARRAY;
+ default:
+ debug_assert( 0 );
+ return TGSI_TEXTURE_1D;
+ }
+}
+
+
+/**
+ * Create a TGSI ureg_dst register from a Mesa dest register.
+ */
+static struct ureg_dst
+translate_dst( struct st_translate *t,
+ const struct prog_dst_register *DstReg,
+ boolean saturate )
+{
+ struct ureg_dst dst = dst_register( t,
+ DstReg->File,
+ DstReg->Index );
+
+ dst = ureg_writemask( dst,
+ DstReg->WriteMask );
+
+ if (saturate)
+ dst = ureg_saturate( dst );
+
+ if (DstReg->RelAddr)
+ dst = ureg_dst_indirect( dst, ureg_src(t->address[0]) );
+
+ return dst;
+}
+
+
+/**
+ * Create a TGSI ureg_src register from a Mesa src register.
+ */
+static struct ureg_src
+translate_src( struct st_translate *t,
+ const struct prog_src_register *SrcReg )
+{
+ struct ureg_src src = src_register( t, SrcReg->File, SrcReg->Index );
+
+ if (t->procType == TGSI_PROCESSOR_GEOMETRY && SrcReg->HasIndex2) {
+ src = src_register( t, SrcReg->File, SrcReg->Index2 );
+ if (SrcReg->RelAddr2)
+ src = ureg_src_dimension_indirect( src, ureg_src(t->address[0]),
+ SrcReg->Index);
+ else
+ src = ureg_src_dimension( src, SrcReg->Index);
+ }
+
+ src = ureg_swizzle( src,
+ GET_SWZ( SrcReg->Swizzle, 0 ) & 0x3,
+ GET_SWZ( SrcReg->Swizzle, 1 ) & 0x3,
+ GET_SWZ( SrcReg->Swizzle, 2 ) & 0x3,
+ GET_SWZ( SrcReg->Swizzle, 3 ) & 0x3);
+
+ if (SrcReg->Negate == NEGATE_XYZW)
+ src = ureg_negate(src);
+
+ if (SrcReg->Abs)
+ src = ureg_abs(src);
+
+ if (SrcReg->RelAddr) {
+ src = ureg_src_indirect( src, ureg_src(t->address[0]));
+ if (SrcReg->File != PROGRAM_INPUT &&
+ SrcReg->File != PROGRAM_OUTPUT) {
+ /* If SrcReg->Index was negative, it was set to zero in
+ * src_register(). Reassign it now. But don't do this
+ * for input/output regs since they get remapped while
+ * const buffers don't.
+ */
+ src.Index = SrcReg->Index;
+ }
+ }
+
+ return src;
+}
+
+
+static struct ureg_src swizzle_4v( struct ureg_src src,
+ const unsigned *swz )
+{
+ return ureg_swizzle( src, swz[0], swz[1], swz[2], swz[3] );
+}
+
+
+/**
+ * Translate a SWZ instruction into a MOV, MUL or MAD instruction. EG:
+ *
+ * SWZ dst, src.x-y10
+ *
+ * becomes:
+ *
+ * MAD dst {1,-1,0,0}, src.xyxx, {0,0,1,0}
+ */
+static void emit_swz( struct st_translate *t,
+ struct ureg_dst dst,
+ const struct prog_src_register *SrcReg )
+{
+ struct ureg_program *ureg = t->ureg;
+ struct ureg_src src = src_register( t, SrcReg->File, SrcReg->Index );
+
+ unsigned negate_mask = SrcReg->Negate;
+
+ unsigned one_mask = ((GET_SWZ(SrcReg->Swizzle, 0) == SWIZZLE_ONE) << 0 |
+ (GET_SWZ(SrcReg->Swizzle, 1) == SWIZZLE_ONE) << 1 |
+ (GET_SWZ(SrcReg->Swizzle, 2) == SWIZZLE_ONE) << 2 |
+ (GET_SWZ(SrcReg->Swizzle, 3) == SWIZZLE_ONE) << 3);
+
+ unsigned zero_mask = ((GET_SWZ(SrcReg->Swizzle, 0) == SWIZZLE_ZERO) << 0 |
+ (GET_SWZ(SrcReg->Swizzle, 1) == SWIZZLE_ZERO) << 1 |
+ (GET_SWZ(SrcReg->Swizzle, 2) == SWIZZLE_ZERO) << 2 |
+ (GET_SWZ(SrcReg->Swizzle, 3) == SWIZZLE_ZERO) << 3);
+
+ unsigned negative_one_mask = one_mask & negate_mask;
+ unsigned positive_one_mask = one_mask & ~negate_mask;
+
+ struct ureg_src imm;
+ unsigned i;
+ unsigned mul_swizzle[4] = {0,0,0,0};
+ unsigned add_swizzle[4] = {0,0,0,0};
+ unsigned src_swizzle[4] = {0,0,0,0};
+ boolean need_add = FALSE;
+ boolean need_mul = FALSE;
+
+ if (dst.WriteMask == 0)
+ return;
+
+ /* Is this just a MOV?
+ */
+ if (zero_mask == 0 &&
+ one_mask == 0 &&
+ (negate_mask == 0 || negate_mask == TGSI_WRITEMASK_XYZW))
+ {
+ ureg_MOV( ureg, dst, translate_src( t, SrcReg ));
+ return;
+ }
+
+#define IMM_ZERO 0
+#define IMM_ONE 1
+#define IMM_NEG_ONE 2
+
+ imm = ureg_imm3f( ureg, 0, 1, -1 );
+
+ for (i = 0; i < 4; i++) {
+ unsigned bit = 1 << i;
+
+ if (dst.WriteMask & bit) {
+ if (positive_one_mask & bit) {
+ mul_swizzle[i] = IMM_ZERO;
+ add_swizzle[i] = IMM_ONE;
+ need_add = TRUE;
+ }
+ else if (negative_one_mask & bit) {
+ mul_swizzle[i] = IMM_ZERO;
+ add_swizzle[i] = IMM_NEG_ONE;
+ need_add = TRUE;
+ }
+ else if (zero_mask & bit) {
+ mul_swizzle[i] = IMM_ZERO;
+ add_swizzle[i] = IMM_ZERO;
+ need_add = TRUE;
+ }
+ else {
+ add_swizzle[i] = IMM_ZERO;
+ src_swizzle[i] = GET_SWZ(SrcReg->Swizzle, i);
+ need_mul = TRUE;
+ if (negate_mask & bit) {
+ mul_swizzle[i] = IMM_NEG_ONE;
+ }
+ else {
+ mul_swizzle[i] = IMM_ONE;
+ }
+ }
+ }
+ }
+
+ if (need_mul && need_add) {
+ ureg_MAD( ureg,
+ dst,
+ swizzle_4v( src, src_swizzle ),
+ swizzle_4v( imm, mul_swizzle ),
+ swizzle_4v( imm, add_swizzle ) );
+ }
+ else if (need_mul) {
+ ureg_MUL( ureg,
+ dst,
+ swizzle_4v( src, src_swizzle ),
+ swizzle_4v( imm, mul_swizzle ) );
+ }
+ else if (need_add) {
+ ureg_MOV( ureg,
+ dst,
+ swizzle_4v( imm, add_swizzle ) );
+ }
+ else {
+ debug_assert(0);
+ }
+
+#undef IMM_ZERO
+#undef IMM_ONE
+#undef IMM_NEG_ONE
+}
+
+
+/**
+ * Negate the value of DDY to match GL semantics where (0,0) is the
+ * lower-left corner of the window.
+ * Note that the GL_ARB_fragment_coord_conventions extension will
+ * effect this someday.
+ */
+static void emit_ddy( struct st_translate *t,
+ struct ureg_dst dst,
+ const struct prog_src_register *SrcReg )
+{
+ struct ureg_program *ureg = t->ureg;
+ struct ureg_src src = translate_src( t, SrcReg );
+ src = ureg_negate( src );
+ ureg_DDY( ureg, dst, src );
+}
+
+
+
+static unsigned
+translate_opcode( unsigned op )
+{
+ switch( op ) {
+ case OPCODE_ARL:
+ return TGSI_OPCODE_ARL;
+ case OPCODE_ABS:
+ return TGSI_OPCODE_ABS;
+ case OPCODE_ADD:
+ return TGSI_OPCODE_ADD;
+ case OPCODE_BGNLOOP:
+ return TGSI_OPCODE_BGNLOOP;
+ case OPCODE_BGNSUB:
+ return TGSI_OPCODE_BGNSUB;
+ case OPCODE_BRA:
+ return TGSI_OPCODE_BRA;
+ case OPCODE_BRK:
+ return TGSI_OPCODE_BRK;
+ case OPCODE_CAL:
+ return TGSI_OPCODE_CAL;
+ case OPCODE_CMP:
+ return TGSI_OPCODE_CMP;
+ case OPCODE_CONT:
+ return TGSI_OPCODE_CONT;
+ case OPCODE_COS:
+ return TGSI_OPCODE_COS;
+ case OPCODE_DDX:
+ return TGSI_OPCODE_DDX;
+ case OPCODE_DDY:
+ return TGSI_OPCODE_DDY;
+ case OPCODE_DP2:
+ return TGSI_OPCODE_DP2;
+ case OPCODE_DP2A:
+ return TGSI_OPCODE_DP2A;
+ case OPCODE_DP3:
+ return TGSI_OPCODE_DP3;
+ case OPCODE_DP4:
+ return TGSI_OPCODE_DP4;
+ case OPCODE_DPH:
+ return TGSI_OPCODE_DPH;
+ case OPCODE_DST:
+ return TGSI_OPCODE_DST;
+ case OPCODE_ELSE:
+ return TGSI_OPCODE_ELSE;
+ case OPCODE_EMIT_VERTEX:
+ return TGSI_OPCODE_EMIT;
+ case OPCODE_END_PRIMITIVE:
+ return TGSI_OPCODE_ENDPRIM;
+ case OPCODE_ENDIF:
+ return TGSI_OPCODE_ENDIF;
+ case OPCODE_ENDLOOP:
+ return TGSI_OPCODE_ENDLOOP;
+ case OPCODE_ENDSUB:
+ return TGSI_OPCODE_ENDSUB;
+ case OPCODE_EX2:
+ return TGSI_OPCODE_EX2;
+ case OPCODE_EXP:
+ return TGSI_OPCODE_EXP;
+ case OPCODE_FLR:
+ return TGSI_OPCODE_FLR;
+ case OPCODE_FRC:
+ return TGSI_OPCODE_FRC;
+ case OPCODE_IF:
+ return TGSI_OPCODE_IF;
+ case OPCODE_TRUNC:
+ return TGSI_OPCODE_TRUNC;
+ case OPCODE_KIL:
+ return TGSI_OPCODE_KIL;
+ case OPCODE_KIL_NV:
+ return TGSI_OPCODE_KILP;
+ case OPCODE_LG2:
+ return TGSI_OPCODE_LG2;
+ case OPCODE_LOG:
+ return TGSI_OPCODE_LOG;
+ case OPCODE_LIT:
+ return TGSI_OPCODE_LIT;
+ case OPCODE_LRP:
+ return TGSI_OPCODE_LRP;
+ case OPCODE_MAD:
+ return TGSI_OPCODE_MAD;
+ case OPCODE_MAX:
+ return TGSI_OPCODE_MAX;
+ case OPCODE_MIN:
+ return TGSI_OPCODE_MIN;
+ case OPCODE_MOV:
+ return TGSI_OPCODE_MOV;
+ case OPCODE_MUL:
+ return TGSI_OPCODE_MUL;
+ case OPCODE_NOP:
+ return TGSI_OPCODE_NOP;
+ case OPCODE_NRM3:
+ return TGSI_OPCODE_NRM;
+ case OPCODE_NRM4:
+ return TGSI_OPCODE_NRM4;
+ case OPCODE_POW:
+ return TGSI_OPCODE_POW;
+ case OPCODE_RCP:
+ return TGSI_OPCODE_RCP;
+ case OPCODE_RET:
+ return TGSI_OPCODE_RET;
+ case OPCODE_RSQ:
+ return TGSI_OPCODE_RSQ;
+ case OPCODE_SCS:
+ return TGSI_OPCODE_SCS;
+ case OPCODE_SEQ:
+ return TGSI_OPCODE_SEQ;
+ case OPCODE_SGE:
+ return TGSI_OPCODE_SGE;
+ case OPCODE_SGT:
+ return TGSI_OPCODE_SGT;
+ case OPCODE_SIN:
+ return TGSI_OPCODE_SIN;
+ case OPCODE_SLE:
+ return TGSI_OPCODE_SLE;
+ case OPCODE_SLT:
+ return TGSI_OPCODE_SLT;
+ case OPCODE_SNE:
+ return TGSI_OPCODE_SNE;
+ case OPCODE_SSG:
+ return TGSI_OPCODE_SSG;
+ case OPCODE_SUB:
+ return TGSI_OPCODE_SUB;
+ case OPCODE_TEX:
+ return TGSI_OPCODE_TEX;
+ case OPCODE_TXB:
+ return TGSI_OPCODE_TXB;
+ case OPCODE_TXD:
+ return TGSI_OPCODE_TXD;
+ case OPCODE_TXL:
+ return TGSI_OPCODE_TXL;
+ case OPCODE_TXP:
+ return TGSI_OPCODE_TXP;
+ case OPCODE_XPD:
+ return TGSI_OPCODE_XPD;
+ case OPCODE_END:
+ return TGSI_OPCODE_END;
+ default:
+ debug_assert( 0 );
+ return TGSI_OPCODE_NOP;
+ }
+}
+
+
+static void
+compile_instruction(
+ struct st_translate *t,
+ const struct prog_instruction *inst )
+{
+ struct ureg_program *ureg = t->ureg;
+ GLuint i;
+ struct ureg_dst dst[1];
+ struct ureg_src src[4];
+ unsigned num_dst;
+ unsigned num_src;
+
+ num_dst = _mesa_num_inst_dst_regs( inst->Opcode );
+ num_src = _mesa_num_inst_src_regs( inst->Opcode );
+
+ if (num_dst)
+ dst[0] = translate_dst( t,
+ &inst->DstReg,
+ inst->SaturateMode );
+
+ for (i = 0; i < num_src; i++)
+ src[i] = translate_src( t, &inst->SrcReg[i] );
+
+ switch( inst->Opcode ) {
+ case OPCODE_SWZ:
+ emit_swz( t, dst[0], &inst->SrcReg[0] );
+ return;
+
+ case OPCODE_BGNLOOP:
+ case OPCODE_CAL:
+ case OPCODE_ELSE:
+ case OPCODE_ENDLOOP:
+ case OPCODE_IF:
+ debug_assert(num_dst == 0);
+ ureg_label_insn( ureg,
+ translate_opcode( inst->Opcode ),
+ src, num_src,
+ get_label( t, inst->BranchTarget ));
+ return;
+
+ case OPCODE_TEX:
+ case OPCODE_TXB:
+ case OPCODE_TXD:
+ case OPCODE_TXL:
+ case OPCODE_TXP:
+ src[num_src++] = t->samplers[inst->TexSrcUnit];
+ ureg_tex_insn( ureg,
+ translate_opcode( inst->Opcode ),
+ dst, num_dst,
+ translate_texture_target( inst->TexSrcTarget,
+ inst->TexShadow ),
+ src, num_src );
+ return;
+
+ case OPCODE_SCS:
+ dst[0] = ureg_writemask(dst[0], TGSI_WRITEMASK_XY );
+ ureg_insn( ureg,
+ translate_opcode( inst->Opcode ),
+ dst, num_dst,
+ src, num_src );
+ break;
+
+ case OPCODE_XPD:
+ dst[0] = ureg_writemask(dst[0], TGSI_WRITEMASK_XYZ );
+ ureg_insn( ureg,
+ translate_opcode( inst->Opcode ),
+ dst, num_dst,
+ src, num_src );
+ break;
+
+ case OPCODE_NOISE1:
+ case OPCODE_NOISE2:
+ case OPCODE_NOISE3:
+ case OPCODE_NOISE4:
+ /* At some point, a motivated person could add a better
+ * implementation of noise. Currently not even the nvidia
+ * binary drivers do anything more than this. In any case, the
+ * place to do this is in the GL state tracker, not the poor
+ * driver.
+ */
+ ureg_MOV( ureg, dst[0], ureg_imm1f(ureg, 0.5) );
+ break;
+
+ case OPCODE_DDY:
+ emit_ddy( t, dst[0], &inst->SrcReg[0] );
+ break;
+
+ default:
+ ureg_insn( ureg,
+ translate_opcode( inst->Opcode ),
+ dst, num_dst,
+ src, num_src );
+ break;
+ }
+}
+
+
+/**
+ * Emit the TGSI instructions to adjust the WPOS pixel center convention
+ * Basically, add (adjX, adjY) to the fragment position.
+ */
+static void
+emit_adjusted_wpos( struct st_translate *t,
+ const struct gl_program *program,
+ GLfloat adjX, GLfloat adjY)
+{
+ struct ureg_program *ureg = t->ureg;
+ struct ureg_dst wpos_temp = ureg_DECL_temporary(ureg);
+ struct ureg_src wpos_input = t->inputs[t->inputMapping[FRAG_ATTRIB_WPOS]];
+
+ /* Note that we bias X and Y and pass Z and W through unchanged.
+ * The shader might also use gl_FragCoord.w and .z.
+ */
+ ureg_ADD(ureg, wpos_temp, wpos_input,
+ ureg_imm4f(ureg, adjX, adjY, 0.0f, 0.0f));
+
+ t->inputs[t->inputMapping[FRAG_ATTRIB_WPOS]] = ureg_src(wpos_temp);
+}
+
+
+/**
+ * Emit the TGSI instructions for inverting the WPOS y coordinate.
+ * This code is unavoidable because it also depends on whether
+ * a FBO is bound (STATE_FB_WPOS_Y_TRANSFORM).
+ */
+static void
+emit_wpos_inversion( struct st_translate *t,
+ const struct gl_program *program,
+ boolean invert)
+{
+ struct ureg_program *ureg = t->ureg;
+
+ /* Fragment program uses fragment position input.
+ * Need to replace instances of INPUT[WPOS] with temp T
+ * where T = INPUT[WPOS] by y is inverted.
+ */
+ static const gl_state_index wposTransformState[STATE_LENGTH]
+ = { STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM, 0, 0, 0 };
+
+ /* XXX: note we are modifying the incoming shader here! Need to
+ * do this before emitting the constant decls below, or this
+ * will be missed:
+ */
+ unsigned wposTransConst = _mesa_add_state_reference(program->Parameters,
+ wposTransformState);
+
+ struct ureg_src wpostrans = ureg_DECL_constant( ureg, wposTransConst );
+ struct ureg_dst wpos_temp;
+ struct ureg_src wpos_input = t->inputs[t->inputMapping[FRAG_ATTRIB_WPOS]];
+
+ /* MOV wpos_temp, input[wpos]
+ */
+ if (wpos_input.File == TGSI_FILE_TEMPORARY)
+ wpos_temp = ureg_dst(wpos_input);
+ else {
+ wpos_temp = ureg_DECL_temporary( ureg );
+ ureg_MOV( ureg, wpos_temp, wpos_input );
+ }
+
+ if (invert) {
+ /* MAD wpos_temp.y, wpos_input, wpostrans.xxxx, wpostrans.yyyy
+ */
+ ureg_MAD( ureg,
+ ureg_writemask(wpos_temp, TGSI_WRITEMASK_Y ),
+ wpos_input,
+ ureg_scalar(wpostrans, 0),
+ ureg_scalar(wpostrans, 1));
+ } else {
+ /* MAD wpos_temp.y, wpos_input, wpostrans.zzzz, wpostrans.wwww
+ */
+ ureg_MAD( ureg,
+ ureg_writemask(wpos_temp, TGSI_WRITEMASK_Y ),
+ wpos_input,
+ ureg_scalar(wpostrans, 2),
+ ureg_scalar(wpostrans, 3));
+ }
+
+ /* Use wpos_temp as position input from here on:
+ */
+ t->inputs[t->inputMapping[FRAG_ATTRIB_WPOS]] = ureg_src(wpos_temp);
+}
+
+
+/**
+ * Emit fragment position/ooordinate code.
+ */
+static void
+emit_wpos(struct st_context *st,
+ struct st_translate *t,
+ const struct gl_program *program,
+ struct ureg_program *ureg)
+{
+ const struct gl_fragment_program *fp =
+ (const struct gl_fragment_program *) program;
+ struct pipe_screen *pscreen = st->pipe->screen;
+ boolean invert = FALSE;
+
+ if (fp->OriginUpperLeft) {
+ /* Fragment shader wants origin in upper-left */
+ if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT)) {
+ /* the driver supports upper-left origin */
+ }
+ else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT)) {
+ /* the driver supports lower-left origin, need to invert Y */
+ ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT);
+ invert = TRUE;
+ }
+ else
+ assert(0);
+ }
+ else {
+ /* Fragment shader wants origin in lower-left */
+ if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT))
+ /* the driver supports lower-left origin */
+ ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT);
+ else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT))
+ /* the driver supports upper-left origin, need to invert Y */
+ invert = TRUE;
+ else
+ assert(0);
+ }
+
+ if (fp->PixelCenterInteger) {
+ /* Fragment shader wants pixel center integer */
+ if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER))
+ /* the driver supports pixel center integer */
+ ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER);
+ else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER))
+ /* the driver supports pixel center half integer, need to bias X,Y */
+ emit_adjusted_wpos(t, program, 0.5f, invert ? 0.5f : -0.5f);
+ else
+ assert(0);
+ }
+ else {
+ /* Fragment shader wants pixel center half integer */
+ if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER)) {
+ /* the driver supports pixel center half integer */
+ }
+ else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER)) {
+ /* the driver supports pixel center integer, need to bias X,Y */
+ ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER);
+ emit_adjusted_wpos(t, program, 0.5f, invert ? -0.5f : 0.5f);
+ }
+ else
+ assert(0);
+ }
+
+ /* we invert after adjustment so that we avoid the MOV to temporary,
+ * and reuse the adjustment ADD instead */
+ emit_wpos_inversion(t, program, invert);
+}
+
+
+/**
+ * OpenGL's fragment gl_FrontFace input is 1 for front-facing, 0 for back.
+ * TGSI uses +1 for front, -1 for back.
+ * This function converts the TGSI value to the GL value. Simply clamping/
+ * saturating the value to [0,1] does the job.
+ */
+static void
+emit_face_var( struct st_translate *t,
+ const struct gl_program *program )
+{
+ struct ureg_program *ureg = t->ureg;
+ struct ureg_dst face_temp = ureg_DECL_temporary( ureg );
+ struct ureg_src face_input = t->inputs[t->inputMapping[FRAG_ATTRIB_FACE]];
+
+ /* MOV_SAT face_temp, input[face]
+ */
+ face_temp = ureg_saturate( face_temp );
+ ureg_MOV( ureg, face_temp, face_input );
+
+ /* Use face_temp as face input from here on:
+ */
+ t->inputs[t->inputMapping[FRAG_ATTRIB_FACE]] = ureg_src(face_temp);
+}
+
+
+static void
+emit_edgeflags( struct st_translate *t,
+ const struct gl_program *program )
+{
+ struct ureg_program *ureg = t->ureg;
+ struct ureg_dst edge_dst = t->outputs[t->outputMapping[VERT_RESULT_EDGE]];
+ struct ureg_src edge_src = t->inputs[t->inputMapping[VERT_ATTRIB_EDGEFLAG]];
+
+ ureg_MOV( ureg, edge_dst, edge_src );
+}
+
+
+/**
+ * Translate Mesa program to TGSI format.
+ * \param program the program to translate
+ * \param numInputs number of input registers used
+ * \param inputMapping maps Mesa fragment program inputs to TGSI generic
+ * input indexes
+ * \param inputSemanticName the TGSI_SEMANTIC flag for each input
+ * \param inputSemanticIndex the semantic index (ex: which texcoord) for
+ * each input
+ * \param interpMode the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input
+ * \param numOutputs number of output registers used
+ * \param outputMapping maps Mesa fragment program outputs to TGSI
+ * generic outputs
+ * \param outputSemanticName the TGSI_SEMANTIC flag for each output
+ * \param outputSemanticIndex the semantic index (ex: which texcoord) for
+ * each output
+ *
+ * \return PIPE_OK or PIPE_ERROR_OUT_OF_MEMORY
+ */
+enum pipe_error
+st_translate_mesa_program(
+ struct gl_context *ctx,
+ uint procType,
+ struct ureg_program *ureg,
+ const struct gl_program *program,
+ GLuint numInputs,
+ const GLuint inputMapping[],
+ const ubyte inputSemanticName[],
+ const ubyte inputSemanticIndex[],
+ const GLuint interpMode[],
+ GLuint numOutputs,
+ const GLuint outputMapping[],
+ const ubyte outputSemanticName[],
+ const ubyte outputSemanticIndex[],
+ boolean passthrough_edgeflags )
+{
+ struct st_translate translate, *t;
+ unsigned i;
+ enum pipe_error ret = PIPE_OK;
+
+ assert(numInputs <= Elements(t->inputs));
+ assert(numOutputs <= Elements(t->outputs));
+
+ t = &translate;
+ memset(t, 0, sizeof *t);
+
+ t->procType = procType;
+ t->inputMapping = inputMapping;
+ t->outputMapping = outputMapping;
+ t->ureg = ureg;
+ t->pointSizeOutIndex = -1;
+ t->prevInstWrotePointSize = GL_FALSE;
+
+ /*_mesa_print_program(program);*/
+
+ /*
+ * Declare input attributes.
+ */
+ if (procType == TGSI_PROCESSOR_FRAGMENT) {
+ for (i = 0; i < numInputs; i++) {
+ if (program->InputFlags[0] & PROG_PARAM_BIT_CYL_WRAP) {
+ t->inputs[i] = ureg_DECL_fs_input_cyl(ureg,
+ inputSemanticName[i],
+ inputSemanticIndex[i],
+ interpMode[i],
+ TGSI_CYLINDRICAL_WRAP_X);
+ }
+ else {
+ t->inputs[i] = ureg_DECL_fs_input(ureg,
+ inputSemanticName[i],
+ inputSemanticIndex[i],
+ interpMode[i]);
+ }
+ }
+
+ if (program->InputsRead & FRAG_BIT_WPOS) {
+ /* Must do this after setting up t->inputs, and before
+ * emitting constant references, below:
+ */
+ emit_wpos(st_context(ctx), t, program, ureg);
+ }
+
+ if (program->InputsRead & FRAG_BIT_FACE) {
+ emit_face_var( t, program );
+ }
+
+ /*
+ * Declare output attributes.
+ */
+ for (i = 0; i < numOutputs; i++) {
+ switch (outputSemanticName[i]) {
+ case TGSI_SEMANTIC_POSITION:
+ t->outputs[i] = ureg_DECL_output( ureg,
+ TGSI_SEMANTIC_POSITION, /* Z / Depth */
+ outputSemanticIndex[i] );
+
+ t->outputs[i] = ureg_writemask( t->outputs[i],
+ TGSI_WRITEMASK_Z );
+ break;
+ case TGSI_SEMANTIC_STENCIL:
+ t->outputs[i] = ureg_DECL_output( ureg,
+ TGSI_SEMANTIC_STENCIL, /* Stencil */
+ outputSemanticIndex[i] );
+ t->outputs[i] = ureg_writemask( t->outputs[i],
+ TGSI_WRITEMASK_Y );
+ break;
+ case TGSI_SEMANTIC_COLOR:
+ t->outputs[i] = ureg_DECL_output( ureg,
+ TGSI_SEMANTIC_COLOR,
+ outputSemanticIndex[i] );
+ break;
+ default:
+ debug_assert(0);
+ return 0;
+ }
+ }
+ }
+ else if (procType == TGSI_PROCESSOR_GEOMETRY) {
+ for (i = 0; i < numInputs; i++) {
+ t->inputs[i] = ureg_DECL_gs_input(ureg,
+ i,
+ inputSemanticName[i],
+ inputSemanticIndex[i]);
+ }
+
+ for (i = 0; i < numOutputs; i++) {
+ t->outputs[i] = ureg_DECL_output( ureg,
+ outputSemanticName[i],
+ outputSemanticIndex[i] );
+ }
+ }
+ else {
+ assert(procType == TGSI_PROCESSOR_VERTEX);
+
+ for (i = 0; i < numInputs; i++) {
+ t->inputs[i] = ureg_DECL_vs_input(ureg, i);
+ }
+
+ for (i = 0; i < numOutputs; i++) {
+ t->outputs[i] = ureg_DECL_output( ureg,
+ outputSemanticName[i],
+ outputSemanticIndex[i] );
+ if ((outputSemanticName[i] == TGSI_SEMANTIC_PSIZE) && program->Id) {
+ /* Writing to the point size result register requires special
+ * handling to implement clamping.
+ */
+ static const gl_state_index pointSizeClampState[STATE_LENGTH]
+ = { STATE_INTERNAL, STATE_POINT_SIZE_IMPL_CLAMP, 0, 0, 0 };
+ /* XXX: note we are modifying the incoming shader here! Need to
+ * do this before emitting the constant decls below, or this
+ * will be missed:
+ */
+ unsigned pointSizeClampConst =
+ _mesa_add_state_reference(program->Parameters,
+ pointSizeClampState);
+ struct ureg_dst psizregtemp = ureg_DECL_temporary( ureg );
+ t->pointSizeConst = ureg_DECL_constant( ureg, pointSizeClampConst );
+ t->pointSizeResult = t->outputs[i];
+ t->pointSizeOutIndex = i;
+ t->outputs[i] = psizregtemp;
+ }
+ }
+ if (passthrough_edgeflags)
+ emit_edgeflags( t, program );
+ }
+
+ /* Declare address register.
+ */
+ if (program->NumAddressRegs > 0) {
+ debug_assert( program->NumAddressRegs == 1 );
+ t->address[0] = ureg_DECL_address( ureg );
+ }
+
+ /* Declare misc input registers
+ */
+ {
+ GLbitfield sysInputs = program->SystemValuesRead;
+ unsigned numSys = 0;
+ for (i = 0; sysInputs; i++) {
+ if (sysInputs & (1 << i)) {
+ unsigned semName = mesa_sysval_to_semantic[i];
+ t->systemValues[i] = ureg_DECL_system_value(ureg, numSys, semName, 0);
+ numSys++;
+ sysInputs &= ~(1 << i);
+ }
+ }
+ }
+
+ if (program->IndirectRegisterFiles & (1 << PROGRAM_TEMPORARY)) {
+ /* If temps are accessed with indirect addressing, declare temporaries
+ * in sequential order. Else, we declare them on demand elsewhere.
+ */
+ for (i = 0; i < program->NumTemporaries; i++) {
+ /* XXX use TGSI_FILE_TEMPORARY_ARRAY when it's supported by ureg */
+ t->temps[i] = ureg_DECL_temporary( t->ureg );
+ }
+ }
+
+ /* Emit constants and immediates. Mesa uses a single index space
+ * for these, so we put all the translated regs in t->constants.
+ */
+ if (program->Parameters) {
+ t->constants = CALLOC( program->Parameters->NumParameters,
+ sizeof t->constants[0] );
+ if (t->constants == NULL) {
+ ret = PIPE_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ for (i = 0; i < program->Parameters->NumParameters; i++) {
+ switch (program->Parameters->Parameters[i].Type) {
+ case PROGRAM_ENV_PARAM:
+ case PROGRAM_LOCAL_PARAM:
+ case PROGRAM_STATE_VAR:
+ case PROGRAM_NAMED_PARAM:
+ case PROGRAM_UNIFORM:
+ t->constants[i] = ureg_DECL_constant( ureg, i );
+ break;
+
+ /* Emit immediates only when there's no indirect addressing of
+ * the const buffer.
+ * FIXME: Be smarter and recognize param arrays:
+ * indirect addressing is only valid within the referenced
+ * array.
+ */
+ case PROGRAM_CONSTANT:
+ if (program->IndirectRegisterFiles & PROGRAM_ANY_CONST)
+ t->constants[i] = ureg_DECL_constant( ureg, i );
+ else
+ t->constants[i] =
+ ureg_DECL_immediate( ureg,
+ program->Parameters->ParameterValues[i],
+ 4 );
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ /* texture samplers */
+ for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
+ if (program->SamplersUsed & (1 << i)) {
+ t->samplers[i] = ureg_DECL_sampler( ureg, i );
+ }
+ }
+
+ /* Emit each instruction in turn:
+ */
+ for (i = 0; i < program->NumInstructions; i++) {
+ set_insn_start( t, ureg_get_instruction_number( ureg ));
+ compile_instruction( t, &program->Instructions[i] );
+
+ if (t->prevInstWrotePointSize && program->Id) {
+ /* The previous instruction wrote to the (fake) vertex point size
+ * result register. Now we need to clamp that value to the min/max
+ * point size range, putting the result into the real point size
+ * register.
+ * Note that we can't do this easily at the end of program due to
+ * possible early return.
+ */
+ set_insn_start( t, ureg_get_instruction_number( ureg ));
+ ureg_MAX( t->ureg,
+ ureg_writemask(t->outputs[t->pointSizeOutIndex], WRITEMASK_X),
+ ureg_src(t->outputs[t->pointSizeOutIndex]),
+ ureg_swizzle(t->pointSizeConst, 1,1,1,1));
+ ureg_MIN( t->ureg, ureg_writemask(t->pointSizeResult, WRITEMASK_X),
+ ureg_src(t->outputs[t->pointSizeOutIndex]),
+ ureg_swizzle(t->pointSizeConst, 2,2,2,2));
+ }
+ t->prevInstWrotePointSize = GL_FALSE;
+ }
+
+ /* Fix up all emitted labels:
+ */
+ for (i = 0; i < t->labels_count; i++) {
+ ureg_fixup_label( ureg,
+ t->labels[i].token,
+ t->insn[t->labels[i].branch_target] );
+ }
+
+out:
+ FREE(t->insn);
+ FREE(t->labels);
+ FREE(t->constants);
+
+ if (t->error) {
+ debug_printf("%s: translate error flag set\n", __FUNCTION__);
+ }
+
+ return ret;
+}
+
+
+/**
+ * Tokens cannot be free with free otherwise the builtin gallium
+ * malloc debugging will get confused.
+ */
+void
+st_free_tokens(const struct tgsi_token *tokens)
+{
+ FREE((void *)tokens);
+}
diff --git a/mesalib/src/mesa/state_tracker/st_program.c b/mesalib/src/mesa/state_tracker/st_program.c
index fc1dfb3ef..e5c26c563 100644
--- a/mesalib/src/mesa/state_tracker/st_program.c
+++ b/mesalib/src/mesa/state_tracker/st_program.c
@@ -1,1165 +1,1165 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
- /*
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- * Brian Paul
- */
-
-
-#include "main/imports.h"
-#include "main/hash.h"
-#include "main/mfeatures.h"
-#include "main/mtypes.h"
-#include "program/prog_parameter.h"
-#include "program/prog_print.h"
-#include "program/programopt.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_shader_tokens.h"
-#include "draw/draw_context.h"
-#include "tgsi/tgsi_dump.h"
-#include "tgsi/tgsi_ureg.h"
-
-#include "st_debug.h"
-#include "st_cb_bitmap.h"
-#include "st_cb_drawpixels.h"
-#include "st_context.h"
-#include "st_program.h"
-#include "st_mesa_to_tgsi.h"
-#include "cso_cache/cso_context.h"
-
-
-
-/**
- * Delete a vertex program variant. Note the caller must unlink
- * the variant from the linked list.
- */
-static void
-delete_vp_variant(struct st_context *st, struct st_vp_variant *vpv)
-{
- if (vpv->driver_shader)
- cso_delete_vertex_shader(st->cso_context, vpv->driver_shader);
-
-#if FEATURE_feedback || FEATURE_rastpos
- if (vpv->draw_shader)
- draw_delete_vertex_shader( st->draw, vpv->draw_shader );
-#endif
-
- if (vpv->tgsi.tokens)
- st_free_tokens(vpv->tgsi.tokens);
-
- FREE( vpv );
-}
-
-
-
-/**
- * Clean out any old compilations:
- */
-void
-st_release_vp_variants( struct st_context *st,
- struct st_vertex_program *stvp )
-{
- struct st_vp_variant *vpv;
-
- for (vpv = stvp->variants; vpv; ) {
- struct st_vp_variant *next = vpv->next;
- delete_vp_variant(st, vpv);
- vpv = next;
- }
-
- stvp->variants = NULL;
-}
-
-
-
-/**
- * Delete a fragment program variant. Note the caller must unlink
- * the variant from the linked list.
- */
-static void
-delete_fp_variant(struct st_context *st, struct st_fp_variant *fpv)
-{
- if (fpv->driver_shader)
- cso_delete_fragment_shader(st->cso_context, fpv->driver_shader);
- if (fpv->parameters)
- _mesa_free_parameter_list(fpv->parameters);
-
- FREE(fpv);
-}
-
-
-/**
- * Free all variants of a fragment program.
- */
-void
-st_release_fp_variants(struct st_context *st, struct st_fragment_program *stfp)
-{
- struct st_fp_variant *fpv;
-
- for (fpv = stfp->variants; fpv; ) {
- struct st_fp_variant *next = fpv->next;
- delete_fp_variant(st, fpv);
- fpv = next;
- }
-
- stfp->variants = NULL;
-}
-
-
-/**
- * Delete a geometry program variant. Note the caller must unlink
- * the variant from the linked list.
- */
-static void
-delete_gp_variant(struct st_context *st, struct st_gp_variant *gpv)
-{
- if (gpv->driver_shader)
- cso_delete_geometry_shader(st->cso_context, gpv->driver_shader);
-
- FREE(gpv);
-}
-
-
-/**
- * Free all variants of a geometry program.
- */
-void
-st_release_gp_variants(struct st_context *st, struct st_geometry_program *stgp)
-{
- struct st_gp_variant *gpv;
-
- for (gpv = stgp->variants; gpv; ) {
- struct st_gp_variant *next = gpv->next;
- delete_gp_variant(st, gpv);
- gpv = next;
- }
-
- stgp->variants = NULL;
-}
-
-
-
-
-/**
- * Translate a Mesa vertex shader into a TGSI shader.
- * \param outputMapping to map vertex program output registers (VERT_RESULT_x)
- * to TGSI output slots
- * \param tokensOut destination for TGSI tokens
- * \return pointer to cached pipe_shader object.
- */
-static void
-st_prepare_vertex_program(struct st_context *st,
- struct st_vertex_program *stvp)
-{
- GLuint attr;
-
- stvp->num_inputs = 0;
- stvp->num_outputs = 0;
-
- if (stvp->Base.IsPositionInvariant)
- _mesa_insert_mvp_code(st->ctx, &stvp->Base);
-
- assert(stvp->Base.Base.NumInstructions > 1);
-
- /*
- * Determine number of inputs, the mappings between VERT_ATTRIB_x
- * and TGSI generic input indexes, plus input attrib semantic info.
- */
- for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
- if (stvp->Base.Base.InputsRead & (1 << attr)) {
- stvp->input_to_index[attr] = stvp->num_inputs;
- stvp->index_to_input[stvp->num_inputs] = attr;
- stvp->num_inputs++;
- }
- }
- /* bit of a hack, presetup potentially unused edgeflag input */
- stvp->input_to_index[VERT_ATTRIB_EDGEFLAG] = stvp->num_inputs;
- stvp->index_to_input[stvp->num_inputs] = VERT_ATTRIB_EDGEFLAG;
-
- /* Compute mapping of vertex program outputs to slots.
- */
- for (attr = 0; attr < VERT_RESULT_MAX; attr++) {
- if ((stvp->Base.Base.OutputsWritten & BITFIELD64_BIT(attr)) == 0) {
- stvp->result_to_output[attr] = ~0;
- }
- else {
- unsigned slot = stvp->num_outputs++;
-
- stvp->result_to_output[attr] = slot;
-
- switch (attr) {
- case VERT_RESULT_HPOS:
- stvp->output_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
- stvp->output_semantic_index[slot] = 0;
- break;
- case VERT_RESULT_COL0:
- stvp->output_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
- stvp->output_semantic_index[slot] = 0;
- break;
- case VERT_RESULT_COL1:
- stvp->output_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
- stvp->output_semantic_index[slot] = 1;
- break;
- case VERT_RESULT_BFC0:
- stvp->output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR;
- stvp->output_semantic_index[slot] = 0;
- break;
- case VERT_RESULT_BFC1:
- stvp->output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR;
- stvp->output_semantic_index[slot] = 1;
- break;
- case VERT_RESULT_FOGC:
- stvp->output_semantic_name[slot] = TGSI_SEMANTIC_FOG;
- stvp->output_semantic_index[slot] = 0;
- break;
- case VERT_RESULT_PSIZ:
- stvp->output_semantic_name[slot] = TGSI_SEMANTIC_PSIZE;
- stvp->output_semantic_index[slot] = 0;
- break;
- case VERT_RESULT_EDGE:
- assert(0);
- break;
-
- case VERT_RESULT_TEX0:
- case VERT_RESULT_TEX1:
- case VERT_RESULT_TEX2:
- case VERT_RESULT_TEX3:
- case VERT_RESULT_TEX4:
- case VERT_RESULT_TEX5:
- case VERT_RESULT_TEX6:
- case VERT_RESULT_TEX7:
- stvp->output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
- stvp->output_semantic_index[slot] = attr - VERT_RESULT_TEX0;
- break;
-
- case VERT_RESULT_VAR0:
- default:
- assert(attr < VERT_RESULT_MAX);
- stvp->output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
- stvp->output_semantic_index[slot] = (FRAG_ATTRIB_VAR0 -
- FRAG_ATTRIB_TEX0 +
- attr -
- VERT_RESULT_VAR0);
- break;
- }
- }
- }
- /* similar hack to above, presetup potentially unused edgeflag output */
- stvp->result_to_output[VERT_RESULT_EDGE] = stvp->num_outputs;
- stvp->output_semantic_name[stvp->num_outputs] = TGSI_SEMANTIC_EDGEFLAG;
- stvp->output_semantic_index[stvp->num_outputs] = 0;
-}
-
-
-/**
- * Translate a vertex program to create a new variant.
- */
-static struct st_vp_variant *
-st_translate_vertex_program(struct st_context *st,
- struct st_vertex_program *stvp,
- const struct st_vp_variant_key *key)
-{
- struct st_vp_variant *vpv = CALLOC_STRUCT(st_vp_variant);
- struct pipe_context *pipe = st->pipe;
- struct ureg_program *ureg;
- enum pipe_error error;
- unsigned num_outputs;
-
- st_prepare_vertex_program( st, stvp );
-
- _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_OUTPUT);
- _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_VARYING);
-
- ureg = ureg_create( TGSI_PROCESSOR_VERTEX );
- if (ureg == NULL) {
- FREE(vpv);
- return NULL;
- }
-
- vpv->key = *key;
-
- vpv->num_inputs = stvp->num_inputs;
- num_outputs = stvp->num_outputs;
- if (key->passthrough_edgeflags) {
- vpv->num_inputs++;
- num_outputs++;
- }
-
- if (ST_DEBUG & DEBUG_MESA) {
- _mesa_print_program(&stvp->Base.Base);
- _mesa_print_program_parameters(st->ctx, &stvp->Base.Base);
- debug_printf("\n");
- }
-
- error = st_translate_mesa_program(st->ctx,
- TGSI_PROCESSOR_VERTEX,
- ureg,
- &stvp->Base.Base,
- /* inputs */
- vpv->num_inputs,
- stvp->input_to_index,
- NULL, /* input semantic name */
- NULL, /* input semantic index */
- NULL,
- /* outputs */
- num_outputs,
- stvp->result_to_output,
- stvp->output_semantic_name,
- stvp->output_semantic_index,
- key->passthrough_edgeflags );
-
- if (error)
- goto fail;
-
- vpv->tgsi.tokens = ureg_get_tokens( ureg, NULL );
- if (!vpv->tgsi.tokens)
- goto fail;
-
- ureg_destroy( ureg );
-
- vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi);
-
- if (ST_DEBUG & DEBUG_TGSI) {
- tgsi_dump( vpv->tgsi.tokens, 0 );
- debug_printf("\n");
- }
-
- return vpv;
-
-fail:
- debug_printf("%s: failed to translate Mesa program:\n", __FUNCTION__);
- _mesa_print_program(&stvp->Base.Base);
- debug_assert(0);
-
- ureg_destroy( ureg );
- return NULL;
-}
-
-
-/**
- * Find/create a vertex program variant.
- */
-struct st_vp_variant *
-st_get_vp_variant(struct st_context *st,
- struct st_vertex_program *stvp,
- const struct st_vp_variant_key *key)
-{
- struct st_vp_variant *vpv;
-
- /* Search for existing variant */
- for (vpv = stvp->variants; vpv; vpv = vpv->next) {
- if (memcmp(&vpv->key, key, sizeof(*key)) == 0) {
- break;
- }
- }
-
- if (!vpv) {
- /* create now */
- vpv = st_translate_vertex_program(st, stvp, key);
- if (vpv) {
- /* insert into list */
- vpv->next = stvp->variants;
- stvp->variants = vpv;
- }
- }
-
- return vpv;
-}
-
-
-/**
- * Translate a Mesa fragment shader into a TGSI shader using extra info in
- * the key.
- * \return new fragment program variant
- */
-static struct st_fp_variant *
-st_translate_fragment_program(struct st_context *st,
- struct st_fragment_program *stfp,
- const struct st_fp_variant_key *key)
-{
- struct pipe_context *pipe = st->pipe;
- struct st_fp_variant *variant = CALLOC_STRUCT(st_fp_variant);
- GLboolean deleteFP = GL_FALSE;
-
- if (!variant)
- return NULL;
-
- assert(!(key->bitmap && key->drawpixels));
-
-#if FEATURE_drawpix
- if (key->bitmap) {
- /* glBitmap drawing */
- struct gl_fragment_program *fp; /* we free this temp program below */
-
- st_make_bitmap_fragment_program(st, &stfp->Base,
- &fp, &variant->bitmap_sampler);
-
- variant->parameters = _mesa_clone_parameter_list(fp->Base.Parameters);
- stfp = st_fragment_program(fp);
- deleteFP = GL_TRUE;
- }
- else if (key->drawpixels) {
- /* glDrawPixels drawing */
- struct gl_fragment_program *fp; /* we free this temp program below */
-
- if (key->drawpixels_z || key->drawpixels_stencil) {
- fp = st_make_drawpix_z_stencil_program(st, key->drawpixels_z,
- key->drawpixels_stencil);
- }
- else {
- /* RGBA */
- st_make_drawpix_fragment_program(st, &stfp->Base, &fp);
- variant->parameters = _mesa_clone_parameter_list(fp->Base.Parameters);
- deleteFP = GL_TRUE;
- }
- stfp = st_fragment_program(fp);
- }
-#endif
-
- if (!stfp->tgsi.tokens) {
- /* need to translate Mesa instructions to TGSI now */
- GLuint outputMapping[FRAG_RESULT_MAX];
- GLuint inputMapping[FRAG_ATTRIB_MAX];
- GLuint interpMode[PIPE_MAX_SHADER_INPUTS]; /* XXX size? */
- GLuint attr;
- enum pipe_error error;
- const GLbitfield inputsRead = stfp->Base.Base.InputsRead;
- struct ureg_program *ureg;
- GLboolean write_all = GL_FALSE;
-
- ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
- ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
- uint fs_num_inputs = 0;
-
- ubyte fs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS];
- ubyte fs_output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
- uint fs_num_outputs = 0;
-
-
- _mesa_remove_output_reads(&stfp->Base.Base, PROGRAM_OUTPUT);
-
- /*
- * Convert Mesa program inputs to TGSI input register semantics.
- */
- for (attr = 0; attr < FRAG_ATTRIB_MAX; attr++) {
- if (inputsRead & (1 << attr)) {
- const GLuint slot = fs_num_inputs++;
-
- inputMapping[attr] = slot;
-
- switch (attr) {
- case FRAG_ATTRIB_WPOS:
- input_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
- input_semantic_index[slot] = 0;
- interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
- break;
- case FRAG_ATTRIB_COL0:
- input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
- input_semantic_index[slot] = 0;
- interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
- break;
- case FRAG_ATTRIB_COL1:
- input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
- input_semantic_index[slot] = 1;
- interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
- break;
- case FRAG_ATTRIB_FOGC:
- input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
- input_semantic_index[slot] = 0;
- interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
- break;
- case FRAG_ATTRIB_FACE:
- input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
- input_semantic_index[slot] = 0;
- interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
- break;
- /* In most cases, there is nothing special about these
- * inputs, so adopt a convention to use the generic
- * semantic name and the mesa FRAG_ATTRIB_ number as the
- * index.
- *
- * All that is required is that the vertex shader labels
- * its own outputs similarly, and that the vertex shader
- * generates at least every output required by the
- * fragment shader plus fixed-function hardware (such as
- * BFC).
- *
- * There is no requirement that semantic indexes start at
- * zero or be restricted to a particular range -- nobody
- * should be building tables based on semantic index.
- */
- case FRAG_ATTRIB_PNTC:
- case FRAG_ATTRIB_TEX0:
- case FRAG_ATTRIB_TEX1:
- case FRAG_ATTRIB_TEX2:
- case FRAG_ATTRIB_TEX3:
- case FRAG_ATTRIB_TEX4:
- case FRAG_ATTRIB_TEX5:
- case FRAG_ATTRIB_TEX6:
- case FRAG_ATTRIB_TEX7:
- case FRAG_ATTRIB_VAR0:
- default:
- /* Actually, let's try and zero-base this just for
- * readability of the generated TGSI.
- */
- assert(attr >= FRAG_ATTRIB_TEX0);
- input_semantic_index[slot] = (attr - FRAG_ATTRIB_TEX0);
- input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
- if (attr == FRAG_ATTRIB_PNTC)
- interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
- else
- interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
- break;
- }
- }
- else {
- inputMapping[attr] = -1;
- }
- }
-
- /*
- * Semantics and mapping for outputs
- */
- {
- uint numColors = 0;
- GLbitfield64 outputsWritten = stfp->Base.Base.OutputsWritten;
-
- /* if z is written, emit that first */
- if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
- fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_POSITION;
- fs_output_semantic_index[fs_num_outputs] = 0;
- outputMapping[FRAG_RESULT_DEPTH] = fs_num_outputs;
- fs_num_outputs++;
- outputsWritten &= ~(1 << FRAG_RESULT_DEPTH);
- }
-
- if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_STENCIL)) {
- fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_STENCIL;
- fs_output_semantic_index[fs_num_outputs] = 0;
- outputMapping[FRAG_RESULT_STENCIL] = fs_num_outputs;
- fs_num_outputs++;
- outputsWritten &= ~(1 << FRAG_RESULT_STENCIL);
- }
-
- /* handle remaning outputs (color) */
- for (attr = 0; attr < FRAG_RESULT_MAX; attr++) {
- if (outputsWritten & BITFIELD64_BIT(attr)) {
- switch (attr) {
- case FRAG_RESULT_DEPTH:
- case FRAG_RESULT_STENCIL:
- /* handled above */
- assert(0);
- break;
- case FRAG_RESULT_COLOR:
- write_all = GL_TRUE; /* fallthrough */
- default:
- assert(attr == FRAG_RESULT_COLOR ||
- (FRAG_RESULT_DATA0 <= attr && attr < FRAG_RESULT_MAX));
- fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_COLOR;
- fs_output_semantic_index[fs_num_outputs] = numColors;
- outputMapping[attr] = fs_num_outputs;
- numColors++;
- break;
- }
-
- fs_num_outputs++;
- }
- }
- }
-
- ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
- if (ureg == NULL)
- return NULL;
-
- if (ST_DEBUG & DEBUG_MESA) {
- _mesa_print_program(&stfp->Base.Base);
- _mesa_print_program_parameters(st->ctx, &stfp->Base.Base);
- debug_printf("\n");
- }
- if (write_all == GL_TRUE)
- ureg_property_fs_color0_writes_all_cbufs(ureg, 1);
-
- error = st_translate_mesa_program(st->ctx,
- TGSI_PROCESSOR_FRAGMENT,
- ureg,
- &stfp->Base.Base,
- /* inputs */
- fs_num_inputs,
- inputMapping,
- input_semantic_name,
- input_semantic_index,
- interpMode,
- /* outputs */
- fs_num_outputs,
- outputMapping,
- fs_output_semantic_name,
- fs_output_semantic_index, FALSE );
-
- stfp->tgsi.tokens = ureg_get_tokens( ureg, NULL );
- ureg_destroy( ureg );
- }
-
- /* fill in variant */
- variant->driver_shader = pipe->create_fs_state(pipe, &stfp->tgsi);
- variant->key = *key;
-
- if (ST_DEBUG & DEBUG_TGSI) {
- tgsi_dump( stfp->tgsi.tokens, 0/*TGSI_DUMP_VERBOSE*/ );
- debug_printf("\n");
- }
-
- if (deleteFP) {
- /* Free the temporary program made above */
- struct gl_fragment_program *fp = &stfp->Base;
- _mesa_reference_fragprog(st->ctx, &fp, NULL);
- }
-
- return variant;
-}
-
-
-/**
- * Translate fragment program if needed.
- */
-struct st_fp_variant *
-st_get_fp_variant(struct st_context *st,
- struct st_fragment_program *stfp,
- const struct st_fp_variant_key *key)
-{
- struct st_fp_variant *fpv;
-
- /* Search for existing variant */
- for (fpv = stfp->variants; fpv; fpv = fpv->next) {
- if (memcmp(&fpv->key, key, sizeof(*key)) == 0) {
- break;
- }
- }
-
- if (!fpv) {
- /* create new */
- fpv = st_translate_fragment_program(st, stfp, key);
- if (fpv) {
- /* insert into list */
- fpv->next = stfp->variants;
- stfp->variants = fpv;
- }
- }
-
- return fpv;
-}
-
-
-/**
- * Translate a geometry program to create a new variant.
- */
-static struct st_gp_variant *
-st_translate_geometry_program(struct st_context *st,
- struct st_geometry_program *stgp,
- const struct st_gp_variant_key *key)
-{
- GLuint inputMapping[GEOM_ATTRIB_MAX];
- GLuint outputMapping[GEOM_RESULT_MAX];
- struct pipe_context *pipe = st->pipe;
- enum pipe_error error;
- GLuint attr;
- const GLbitfield inputsRead = stgp->Base.Base.InputsRead;
- GLuint vslot = 0;
- GLuint num_generic = 0;
-
- uint gs_num_inputs = 0;
- uint gs_builtin_inputs = 0;
- uint gs_array_offset = 0;
-
- ubyte gs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS];
- ubyte gs_output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
- uint gs_num_outputs = 0;
-
- GLint i;
- GLuint maxSlot = 0;
- struct ureg_program *ureg;
-
- struct st_gp_variant *gpv;
-
- gpv = CALLOC_STRUCT(st_gp_variant);
- if (!gpv)
- return NULL;
-
- _mesa_remove_output_reads(&stgp->Base.Base, PROGRAM_OUTPUT);
- _mesa_remove_output_reads(&stgp->Base.Base, PROGRAM_VARYING);
-
- ureg = ureg_create( TGSI_PROCESSOR_GEOMETRY );
- if (ureg == NULL) {
- FREE(gpv);
- return NULL;
- }
-
- /* which vertex output goes to the first geometry input */
- vslot = 0;
-
- memset(inputMapping, 0, sizeof(inputMapping));
- memset(outputMapping, 0, sizeof(outputMapping));
-
- /*
- * Convert Mesa program inputs to TGSI input register semantics.
- */
- for (attr = 0; attr < GEOM_ATTRIB_MAX; attr++) {
- if (inputsRead & (1 << attr)) {
- const GLuint slot = gs_num_inputs;
-
- gs_num_inputs++;
-
- inputMapping[attr] = slot;
-
- stgp->input_map[slot + gs_array_offset] = vslot - gs_builtin_inputs;
- stgp->input_to_index[attr] = vslot;
- stgp->index_to_input[vslot] = attr;
- ++vslot;
-
- if (attr != GEOM_ATTRIB_PRIMITIVE_ID) {
- gs_array_offset += 2;
- } else
- ++gs_builtin_inputs;
-
-#if 0
- debug_printf("input map at %d = %d\n",
- slot + gs_array_offset, stgp->input_map[slot + gs_array_offset]);
-#endif
-
- switch (attr) {
- case GEOM_ATTRIB_PRIMITIVE_ID:
- stgp->input_semantic_name[slot] = TGSI_SEMANTIC_PRIMID;
- stgp->input_semantic_index[slot] = 0;
- break;
- case GEOM_ATTRIB_POSITION:
- stgp->input_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
- stgp->input_semantic_index[slot] = 0;
- break;
- case GEOM_ATTRIB_COLOR0:
- stgp->input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
- stgp->input_semantic_index[slot] = 0;
- break;
- case GEOM_ATTRIB_COLOR1:
- stgp->input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
- stgp->input_semantic_index[slot] = 1;
- break;
- case GEOM_ATTRIB_FOG_FRAG_COORD:
- stgp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
- stgp->input_semantic_index[slot] = 0;
- break;
- case GEOM_ATTRIB_TEX_COORD:
- stgp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
- stgp->input_semantic_index[slot] = num_generic++;
- break;
- case GEOM_ATTRIB_VAR0:
- /* fall-through */
- default:
- stgp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
- stgp->input_semantic_index[slot] = num_generic++;
- }
- }
- }
-
- /* initialize output semantics to defaults */
- for (i = 0; i < PIPE_MAX_SHADER_OUTPUTS; i++) {
- gs_output_semantic_name[i] = TGSI_SEMANTIC_GENERIC;
- gs_output_semantic_index[i] = 0;
- }
-
- num_generic = 0;
- /*
- * Determine number of outputs, the (default) output register
- * mapping and the semantic information for each output.
- */
- for (attr = 0; attr < GEOM_RESULT_MAX; attr++) {
- if (stgp->Base.Base.OutputsWritten & (1 << attr)) {
- GLuint slot;
-
- slot = gs_num_outputs;
- gs_num_outputs++;
- outputMapping[attr] = slot;
-
- switch (attr) {
- case GEOM_RESULT_POS:
- assert(slot == 0);
- gs_output_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
- gs_output_semantic_index[slot] = 0;
- break;
- case GEOM_RESULT_COL0:
- gs_output_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
- gs_output_semantic_index[slot] = 0;
- break;
- case GEOM_RESULT_COL1:
- gs_output_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
- gs_output_semantic_index[slot] = 1;
- break;
- case GEOM_RESULT_SCOL0:
- gs_output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR;
- gs_output_semantic_index[slot] = 0;
- break;
- case GEOM_RESULT_SCOL1:
- gs_output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR;
- gs_output_semantic_index[slot] = 1;
- break;
- case GEOM_RESULT_FOGC:
- gs_output_semantic_name[slot] = TGSI_SEMANTIC_FOG;
- gs_output_semantic_index[slot] = 0;
- break;
- case GEOM_RESULT_PSIZ:
- gs_output_semantic_name[slot] = TGSI_SEMANTIC_PSIZE;
- gs_output_semantic_index[slot] = 0;
- break;
- case GEOM_RESULT_TEX0:
- case GEOM_RESULT_TEX1:
- case GEOM_RESULT_TEX2:
- case GEOM_RESULT_TEX3:
- case GEOM_RESULT_TEX4:
- case GEOM_RESULT_TEX5:
- case GEOM_RESULT_TEX6:
- case GEOM_RESULT_TEX7:
- /* fall-through */
- case GEOM_RESULT_VAR0:
- /* fall-through */
- default:
- assert(slot < Elements(gs_output_semantic_name));
- /* use default semantic info */
- gs_output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
- gs_output_semantic_index[slot] = num_generic++;
- }
- }
- }
-
- assert(gs_output_semantic_name[0] == TGSI_SEMANTIC_POSITION);
-
- /* find max output slot referenced to compute gs_num_outputs */
- for (attr = 0; attr < GEOM_RESULT_MAX; attr++) {
- if (outputMapping[attr] != ~0 && outputMapping[attr] > maxSlot)
- maxSlot = outputMapping[attr];
- }
- gs_num_outputs = maxSlot + 1;
-
-#if 0 /* debug */
- {
- GLuint i;
- printf("outputMapping? %d\n", outputMapping ? 1 : 0);
- if (outputMapping) {
- printf("attr -> slot\n");
- for (i = 0; i < 16; i++) {
- printf(" %2d %3d\n", i, outputMapping[i]);
- }
- }
- printf("slot sem_name sem_index\n");
- for (i = 0; i < gs_num_outputs; i++) {
- printf(" %2d %d %d\n",
- i,
- gs_output_semantic_name[i],
- gs_output_semantic_index[i]);
- }
- }
-#endif
-
- /* free old shader state, if any */
- if (stgp->tgsi.tokens) {
- st_free_tokens(stgp->tgsi.tokens);
- stgp->tgsi.tokens = NULL;
- }
-
- ureg_property_gs_input_prim(ureg, stgp->Base.InputType);
- ureg_property_gs_output_prim(ureg, stgp->Base.OutputType);
- ureg_property_gs_max_vertices(ureg, stgp->Base.VerticesOut);
-
- error = st_translate_mesa_program(st->ctx,
- TGSI_PROCESSOR_GEOMETRY,
- ureg,
- &stgp->Base.Base,
- /* inputs */
- gs_num_inputs,
- inputMapping,
- stgp->input_semantic_name,
- stgp->input_semantic_index,
- NULL,
- /* outputs */
- gs_num_outputs,
- outputMapping,
- gs_output_semantic_name,
- gs_output_semantic_index,
- FALSE);
-
- stgp->num_inputs = gs_num_inputs;
- stgp->tgsi.tokens = ureg_get_tokens( ureg, NULL );
- ureg_destroy( ureg );
-
- /* fill in new variant */
- gpv->driver_shader = pipe->create_gs_state(pipe, &stgp->tgsi);
- gpv->key = *key;
-
- if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) {
- _mesa_print_program(&stgp->Base.Base);
- debug_printf("\n");
- }
-
- if (ST_DEBUG & DEBUG_TGSI) {
- tgsi_dump(stgp->tgsi.tokens, 0);
- debug_printf("\n");
- }
-
- return gpv;
-}
-
-
-/**
- * Get/create geometry program variant.
- */
-struct st_gp_variant *
-st_get_gp_variant(struct st_context *st,
- struct st_geometry_program *stgp,
- const struct st_gp_variant_key *key)
-{
- struct st_gp_variant *gpv;
-
- /* Search for existing variant */
- for (gpv = stgp->variants; gpv; gpv = gpv->next) {
- if (memcmp(&gpv->key, key, sizeof(*key)) == 0) {
- break;
- }
- }
-
- if (!gpv) {
- /* create new */
- gpv = st_translate_geometry_program(st, stgp, key);
- if (gpv) {
- /* insert into list */
- gpv->next = stgp->variants;
- stgp->variants = gpv;
- }
- }
-
- return gpv;
-}
-
-
-
-
-/**
- * Debug- print current shader text
- */
-void
-st_print_shaders(struct gl_context *ctx)
-{
- struct gl_shader_program *shProg[3] = {
- ctx->Shader.CurrentVertexProgram,
- ctx->Shader.CurrentGeometryProgram,
- ctx->Shader.CurrentFragmentProgram,
- };
- unsigned j;
-
- for (j = 0; j < 3; j++) {
- unsigned i;
-
- if (shProg[j] == NULL)
- continue;
-
- for (i = 0; i < shProg[j]->NumShaders; i++) {
- struct gl_shader *sh;
-
- switch (shProg[j]->Shaders[i]->Type) {
- case GL_VERTEX_SHADER:
- sh = (i != 0) ? NULL : shProg[j]->Shaders[i];
- break;
- case GL_GEOMETRY_SHADER_ARB:
- sh = (i != 1) ? NULL : shProg[j]->Shaders[i];
- break;
- case GL_FRAGMENT_SHADER:
- sh = (i != 2) ? NULL : shProg[j]->Shaders[i];
- break;
- default:
- assert(0);
- sh = NULL;
- break;
- }
-
- if (sh != NULL) {
- printf("GLSL shader %u of %u:\n", i, shProg[j]->NumShaders);
- printf("%s\n", sh->Source);
- }
- }
- }
-}
-
-
-/**
- * Vert/Geom/Frag programs have per-context variants. Free all the
- * variants attached to the given program which match the given context.
- */
-static void
-destroy_program_variants(struct st_context *st, struct gl_program *program)
-{
- if (!program)
- return;
-
- switch (program->Target) {
- case GL_VERTEX_PROGRAM_ARB:
- {
- struct st_vertex_program *stvp = (struct st_vertex_program *) program;
- struct st_vp_variant *vpv, **prevPtr = &stvp->variants;
-
- for (vpv = stvp->variants; vpv; ) {
- struct st_vp_variant *next = vpv->next;
- if (vpv->key.st == st) {
- /* unlink from list */
- *prevPtr = next;
- /* destroy this variant */
- delete_vp_variant(st, vpv);
- }
- else {
- prevPtr = &vpv->next;
- }
- vpv = next;
- }
- }
- break;
- case GL_FRAGMENT_PROGRAM_ARB:
- {
- struct st_fragment_program *stfp =
- (struct st_fragment_program *) program;
- struct st_fp_variant *fpv, **prevPtr = &stfp->variants;
-
- for (fpv = stfp->variants; fpv; ) {
- struct st_fp_variant *next = fpv->next;
- if (fpv->key.st == st) {
- /* unlink from list */
- *prevPtr = next;
- /* destroy this variant */
- delete_fp_variant(st, fpv);
- }
- else {
- prevPtr = &fpv->next;
- }
- fpv = next;
- }
- }
- break;
- case MESA_GEOMETRY_PROGRAM:
- {
- struct st_geometry_program *stgp =
- (struct st_geometry_program *) program;
- struct st_gp_variant *gpv, **prevPtr = &stgp->variants;
-
- for (gpv = stgp->variants; gpv; ) {
- struct st_gp_variant *next = gpv->next;
- if (gpv->key.st == st) {
- /* unlink from list */
- *prevPtr = next;
- /* destroy this variant */
- delete_gp_variant(st, gpv);
- }
- else {
- prevPtr = &gpv->next;
- }
- gpv = next;
- }
- }
- break;
- default:
- _mesa_problem(NULL, "Unexpected program target in "
- "destroy_program_variants_cb()");
- }
-}
-
-
-/**
- * Callback for _mesa_HashWalk. Free all the shader's program variants
- * which match the given context.
- */
-static void
-destroy_shader_program_variants_cb(GLuint key, void *data, void *userData)
-{
- struct st_context *st = (struct st_context *) userData;
- struct gl_shader *shader = (struct gl_shader *) data;
-
- switch (shader->Type) {
- case GL_SHADER_PROGRAM_MESA:
- {
- struct gl_shader_program *shProg = (struct gl_shader_program *) data;
- GLuint i;
-
- for (i = 0; i < shProg->NumShaders; i++) {
- destroy_program_variants(st, shProg->Shaders[i]->Program);
- }
-
- destroy_program_variants(st, (struct gl_program *)
- shProg->VertexProgram);
- destroy_program_variants(st, (struct gl_program *)
- shProg->FragmentProgram);
- destroy_program_variants(st, (struct gl_program *)
- shProg->GeometryProgram);
- }
- break;
- case GL_VERTEX_SHADER:
- case GL_FRAGMENT_SHADER:
- case GL_GEOMETRY_SHADER:
- {
- destroy_program_variants(st, shader->Program);
- }
- break;
- default:
- assert(0);
- }
-}
-
-
-/**
- * Callback for _mesa_HashWalk. Free all the program variants which match
- * the given context.
- */
-static void
-destroy_program_variants_cb(GLuint key, void *data, void *userData)
-{
- struct st_context *st = (struct st_context *) userData;
- struct gl_program *program = (struct gl_program *) data;
- destroy_program_variants(st, program);
-}
-
-
-/**
- * Walk over all shaders and programs to delete any variants which
- * belong to the given context.
- * This is called during context tear-down.
- */
-void
-st_destroy_program_variants(struct st_context *st)
-{
- /* ARB vert/frag program */
- _mesa_HashWalk(st->ctx->Shared->Programs,
- destroy_program_variants_cb, st);
-
- /* GLSL vert/frag/geom shaders */
- _mesa_HashWalk(st->ctx->Shared->ShaderObjects,
- destroy_shader_program_variants_cb, st);
-}
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul
+ */
+
+
+#include "main/imports.h"
+#include "main/hash.h"
+#include "main/mfeatures.h"
+#include "main/mtypes.h"
+#include "program/prog_parameter.h"
+#include "program/prog_print.h"
+#include "program/programopt.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_shader_tokens.h"
+#include "draw/draw_context.h"
+#include "tgsi/tgsi_dump.h"
+#include "tgsi/tgsi_ureg.h"
+
+#include "st_debug.h"
+#include "st_cb_bitmap.h"
+#include "st_cb_drawpixels.h"
+#include "st_context.h"
+#include "st_program.h"
+#include "st_mesa_to_tgsi.h"
+#include "cso_cache/cso_context.h"
+
+
+
+/**
+ * Delete a vertex program variant. Note the caller must unlink
+ * the variant from the linked list.
+ */
+static void
+delete_vp_variant(struct st_context *st, struct st_vp_variant *vpv)
+{
+ if (vpv->driver_shader)
+ cso_delete_vertex_shader(st->cso_context, vpv->driver_shader);
+
+#if FEATURE_feedback || FEATURE_rastpos
+ if (vpv->draw_shader)
+ draw_delete_vertex_shader( st->draw, vpv->draw_shader );
+#endif
+
+ if (vpv->tgsi.tokens)
+ st_free_tokens(vpv->tgsi.tokens);
+
+ FREE( vpv );
+}
+
+
+
+/**
+ * Clean out any old compilations:
+ */
+void
+st_release_vp_variants( struct st_context *st,
+ struct st_vertex_program *stvp )
+{
+ struct st_vp_variant *vpv;
+
+ for (vpv = stvp->variants; vpv; ) {
+ struct st_vp_variant *next = vpv->next;
+ delete_vp_variant(st, vpv);
+ vpv = next;
+ }
+
+ stvp->variants = NULL;
+}
+
+
+
+/**
+ * Delete a fragment program variant. Note the caller must unlink
+ * the variant from the linked list.
+ */
+static void
+delete_fp_variant(struct st_context *st, struct st_fp_variant *fpv)
+{
+ if (fpv->driver_shader)
+ cso_delete_fragment_shader(st->cso_context, fpv->driver_shader);
+ if (fpv->parameters)
+ _mesa_free_parameter_list(fpv->parameters);
+
+ FREE(fpv);
+}
+
+
+/**
+ * Free all variants of a fragment program.
+ */
+void
+st_release_fp_variants(struct st_context *st, struct st_fragment_program *stfp)
+{
+ struct st_fp_variant *fpv;
+
+ for (fpv = stfp->variants; fpv; ) {
+ struct st_fp_variant *next = fpv->next;
+ delete_fp_variant(st, fpv);
+ fpv = next;
+ }
+
+ stfp->variants = NULL;
+}
+
+
+/**
+ * Delete a geometry program variant. Note the caller must unlink
+ * the variant from the linked list.
+ */
+static void
+delete_gp_variant(struct st_context *st, struct st_gp_variant *gpv)
+{
+ if (gpv->driver_shader)
+ cso_delete_geometry_shader(st->cso_context, gpv->driver_shader);
+
+ FREE(gpv);
+}
+
+
+/**
+ * Free all variants of a geometry program.
+ */
+void
+st_release_gp_variants(struct st_context *st, struct st_geometry_program *stgp)
+{
+ struct st_gp_variant *gpv;
+
+ for (gpv = stgp->variants; gpv; ) {
+ struct st_gp_variant *next = gpv->next;
+ delete_gp_variant(st, gpv);
+ gpv = next;
+ }
+
+ stgp->variants = NULL;
+}
+
+
+
+
+/**
+ * Translate a Mesa vertex shader into a TGSI shader.
+ * \param outputMapping to map vertex program output registers (VERT_RESULT_x)
+ * to TGSI output slots
+ * \param tokensOut destination for TGSI tokens
+ * \return pointer to cached pipe_shader object.
+ */
+static void
+st_prepare_vertex_program(struct st_context *st,
+ struct st_vertex_program *stvp)
+{
+ GLuint attr;
+
+ stvp->num_inputs = 0;
+ stvp->num_outputs = 0;
+
+ if (stvp->Base.IsPositionInvariant)
+ _mesa_insert_mvp_code(st->ctx, &stvp->Base);
+
+ assert(stvp->Base.Base.NumInstructions > 1);
+
+ /*
+ * Determine number of inputs, the mappings between VERT_ATTRIB_x
+ * and TGSI generic input indexes, plus input attrib semantic info.
+ */
+ for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
+ if (stvp->Base.Base.InputsRead & (1 << attr)) {
+ stvp->input_to_index[attr] = stvp->num_inputs;
+ stvp->index_to_input[stvp->num_inputs] = attr;
+ stvp->num_inputs++;
+ }
+ }
+ /* bit of a hack, presetup potentially unused edgeflag input */
+ stvp->input_to_index[VERT_ATTRIB_EDGEFLAG] = stvp->num_inputs;
+ stvp->index_to_input[stvp->num_inputs] = VERT_ATTRIB_EDGEFLAG;
+
+ /* Compute mapping of vertex program outputs to slots.
+ */
+ for (attr = 0; attr < VERT_RESULT_MAX; attr++) {
+ if ((stvp->Base.Base.OutputsWritten & BITFIELD64_BIT(attr)) == 0) {
+ stvp->result_to_output[attr] = ~0;
+ }
+ else {
+ unsigned slot = stvp->num_outputs++;
+
+ stvp->result_to_output[attr] = slot;
+
+ switch (attr) {
+ case VERT_RESULT_HPOS:
+ stvp->output_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
+ stvp->output_semantic_index[slot] = 0;
+ break;
+ case VERT_RESULT_COL0:
+ stvp->output_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
+ stvp->output_semantic_index[slot] = 0;
+ break;
+ case VERT_RESULT_COL1:
+ stvp->output_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
+ stvp->output_semantic_index[slot] = 1;
+ break;
+ case VERT_RESULT_BFC0:
+ stvp->output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR;
+ stvp->output_semantic_index[slot] = 0;
+ break;
+ case VERT_RESULT_BFC1:
+ stvp->output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR;
+ stvp->output_semantic_index[slot] = 1;
+ break;
+ case VERT_RESULT_FOGC:
+ stvp->output_semantic_name[slot] = TGSI_SEMANTIC_FOG;
+ stvp->output_semantic_index[slot] = 0;
+ break;
+ case VERT_RESULT_PSIZ:
+ stvp->output_semantic_name[slot] = TGSI_SEMANTIC_PSIZE;
+ stvp->output_semantic_index[slot] = 0;
+ break;
+ case VERT_RESULT_EDGE:
+ assert(0);
+ break;
+
+ case VERT_RESULT_TEX0:
+ case VERT_RESULT_TEX1:
+ case VERT_RESULT_TEX2:
+ case VERT_RESULT_TEX3:
+ case VERT_RESULT_TEX4:
+ case VERT_RESULT_TEX5:
+ case VERT_RESULT_TEX6:
+ case VERT_RESULT_TEX7:
+ stvp->output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
+ stvp->output_semantic_index[slot] = attr - VERT_RESULT_TEX0;
+ break;
+
+ case VERT_RESULT_VAR0:
+ default:
+ assert(attr < VERT_RESULT_MAX);
+ stvp->output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
+ stvp->output_semantic_index[slot] = (FRAG_ATTRIB_VAR0 -
+ FRAG_ATTRIB_TEX0 +
+ attr -
+ VERT_RESULT_VAR0);
+ break;
+ }
+ }
+ }
+ /* similar hack to above, presetup potentially unused edgeflag output */
+ stvp->result_to_output[VERT_RESULT_EDGE] = stvp->num_outputs;
+ stvp->output_semantic_name[stvp->num_outputs] = TGSI_SEMANTIC_EDGEFLAG;
+ stvp->output_semantic_index[stvp->num_outputs] = 0;
+}
+
+
+/**
+ * Translate a vertex program to create a new variant.
+ */
+static struct st_vp_variant *
+st_translate_vertex_program(struct st_context *st,
+ struct st_vertex_program *stvp,
+ const struct st_vp_variant_key *key)
+{
+ struct st_vp_variant *vpv = CALLOC_STRUCT(st_vp_variant);
+ struct pipe_context *pipe = st->pipe;
+ struct ureg_program *ureg;
+ enum pipe_error error;
+ unsigned num_outputs;
+
+ st_prepare_vertex_program( st, stvp );
+
+ _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_OUTPUT);
+ _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_VARYING);
+
+ ureg = ureg_create( TGSI_PROCESSOR_VERTEX );
+ if (ureg == NULL) {
+ FREE(vpv);
+ return NULL;
+ }
+
+ vpv->key = *key;
+
+ vpv->num_inputs = stvp->num_inputs;
+ num_outputs = stvp->num_outputs;
+ if (key->passthrough_edgeflags) {
+ vpv->num_inputs++;
+ num_outputs++;
+ }
+
+ if (ST_DEBUG & DEBUG_MESA) {
+ _mesa_print_program(&stvp->Base.Base);
+ _mesa_print_program_parameters(st->ctx, &stvp->Base.Base);
+ debug_printf("\n");
+ }
+
+ error = st_translate_mesa_program(st->ctx,
+ TGSI_PROCESSOR_VERTEX,
+ ureg,
+ &stvp->Base.Base,
+ /* inputs */
+ vpv->num_inputs,
+ stvp->input_to_index,
+ NULL, /* input semantic name */
+ NULL, /* input semantic index */
+ NULL,
+ /* outputs */
+ num_outputs,
+ stvp->result_to_output,
+ stvp->output_semantic_name,
+ stvp->output_semantic_index,
+ key->passthrough_edgeflags );
+
+ if (error)
+ goto fail;
+
+ vpv->tgsi.tokens = ureg_get_tokens( ureg, NULL );
+ if (!vpv->tgsi.tokens)
+ goto fail;
+
+ ureg_destroy( ureg );
+
+ vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi);
+
+ if (ST_DEBUG & DEBUG_TGSI) {
+ tgsi_dump( vpv->tgsi.tokens, 0 );
+ debug_printf("\n");
+ }
+
+ return vpv;
+
+fail:
+ debug_printf("%s: failed to translate Mesa program:\n", __FUNCTION__);
+ _mesa_print_program(&stvp->Base.Base);
+ debug_assert(0);
+
+ ureg_destroy( ureg );
+ return NULL;
+}
+
+
+/**
+ * Find/create a vertex program variant.
+ */
+struct st_vp_variant *
+st_get_vp_variant(struct st_context *st,
+ struct st_vertex_program *stvp,
+ const struct st_vp_variant_key *key)
+{
+ struct st_vp_variant *vpv;
+
+ /* Search for existing variant */
+ for (vpv = stvp->variants; vpv; vpv = vpv->next) {
+ if (memcmp(&vpv->key, key, sizeof(*key)) == 0) {
+ break;
+ }
+ }
+
+ if (!vpv) {
+ /* create now */
+ vpv = st_translate_vertex_program(st, stvp, key);
+ if (vpv) {
+ /* insert into list */
+ vpv->next = stvp->variants;
+ stvp->variants = vpv;
+ }
+ }
+
+ return vpv;
+}
+
+
+/**
+ * Translate a Mesa fragment shader into a TGSI shader using extra info in
+ * the key.
+ * \return new fragment program variant
+ */
+static struct st_fp_variant *
+st_translate_fragment_program(struct st_context *st,
+ struct st_fragment_program *stfp,
+ const struct st_fp_variant_key *key)
+{
+ struct pipe_context *pipe = st->pipe;
+ struct st_fp_variant *variant = CALLOC_STRUCT(st_fp_variant);
+ GLboolean deleteFP = GL_FALSE;
+
+ if (!variant)
+ return NULL;
+
+ assert(!(key->bitmap && key->drawpixels));
+
+#if FEATURE_drawpix
+ if (key->bitmap) {
+ /* glBitmap drawing */
+ struct gl_fragment_program *fp; /* we free this temp program below */
+
+ st_make_bitmap_fragment_program(st, &stfp->Base,
+ &fp, &variant->bitmap_sampler);
+
+ variant->parameters = _mesa_clone_parameter_list(fp->Base.Parameters);
+ stfp = st_fragment_program(fp);
+ deleteFP = GL_TRUE;
+ }
+ else if (key->drawpixels) {
+ /* glDrawPixels drawing */
+ struct gl_fragment_program *fp; /* we free this temp program below */
+
+ if (key->drawpixels_z || key->drawpixels_stencil) {
+ fp = st_make_drawpix_z_stencil_program(st, key->drawpixels_z,
+ key->drawpixels_stencil);
+ }
+ else {
+ /* RGBA */
+ st_make_drawpix_fragment_program(st, &stfp->Base, &fp);
+ variant->parameters = _mesa_clone_parameter_list(fp->Base.Parameters);
+ deleteFP = GL_TRUE;
+ }
+ stfp = st_fragment_program(fp);
+ }
+#endif
+
+ if (!stfp->tgsi.tokens) {
+ /* need to translate Mesa instructions to TGSI now */
+ GLuint outputMapping[FRAG_RESULT_MAX];
+ GLuint inputMapping[FRAG_ATTRIB_MAX];
+ GLuint interpMode[PIPE_MAX_SHADER_INPUTS]; /* XXX size? */
+ GLuint attr;
+ enum pipe_error error;
+ const GLbitfield inputsRead = stfp->Base.Base.InputsRead;
+ struct ureg_program *ureg;
+ GLboolean write_all = GL_FALSE;
+
+ ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
+ ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
+ uint fs_num_inputs = 0;
+
+ ubyte fs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS];
+ ubyte fs_output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
+ uint fs_num_outputs = 0;
+
+
+ _mesa_remove_output_reads(&stfp->Base.Base, PROGRAM_OUTPUT);
+
+ /*
+ * Convert Mesa program inputs to TGSI input register semantics.
+ */
+ for (attr = 0; attr < FRAG_ATTRIB_MAX; attr++) {
+ if (inputsRead & (1 << attr)) {
+ const GLuint slot = fs_num_inputs++;
+
+ inputMapping[attr] = slot;
+
+ switch (attr) {
+ case FRAG_ATTRIB_WPOS:
+ input_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
+ break;
+ case FRAG_ATTRIB_COL0:
+ input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
+ break;
+ case FRAG_ATTRIB_COL1:
+ input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
+ input_semantic_index[slot] = 1;
+ interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
+ break;
+ case FRAG_ATTRIB_FOGC:
+ input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+ break;
+ case FRAG_ATTRIB_FACE:
+ input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
+ break;
+ /* In most cases, there is nothing special about these
+ * inputs, so adopt a convention to use the generic
+ * semantic name and the mesa FRAG_ATTRIB_ number as the
+ * index.
+ *
+ * All that is required is that the vertex shader labels
+ * its own outputs similarly, and that the vertex shader
+ * generates at least every output required by the
+ * fragment shader plus fixed-function hardware (such as
+ * BFC).
+ *
+ * There is no requirement that semantic indexes start at
+ * zero or be restricted to a particular range -- nobody
+ * should be building tables based on semantic index.
+ */
+ case FRAG_ATTRIB_PNTC:
+ case FRAG_ATTRIB_TEX0:
+ case FRAG_ATTRIB_TEX1:
+ case FRAG_ATTRIB_TEX2:
+ case FRAG_ATTRIB_TEX3:
+ case FRAG_ATTRIB_TEX4:
+ case FRAG_ATTRIB_TEX5:
+ case FRAG_ATTRIB_TEX6:
+ case FRAG_ATTRIB_TEX7:
+ case FRAG_ATTRIB_VAR0:
+ default:
+ /* Actually, let's try and zero-base this just for
+ * readability of the generated TGSI.
+ */
+ assert(attr >= FRAG_ATTRIB_TEX0);
+ input_semantic_index[slot] = (attr - FRAG_ATTRIB_TEX0);
+ input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
+ if (attr == FRAG_ATTRIB_PNTC)
+ interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
+ else
+ interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+ break;
+ }
+ }
+ else {
+ inputMapping[attr] = -1;
+ }
+ }
+
+ /*
+ * Semantics and mapping for outputs
+ */
+ {
+ uint numColors = 0;
+ GLbitfield64 outputsWritten = stfp->Base.Base.OutputsWritten;
+
+ /* if z is written, emit that first */
+ if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
+ fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_POSITION;
+ fs_output_semantic_index[fs_num_outputs] = 0;
+ outputMapping[FRAG_RESULT_DEPTH] = fs_num_outputs;
+ fs_num_outputs++;
+ outputsWritten &= ~(1 << FRAG_RESULT_DEPTH);
+ }
+
+ if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_STENCIL)) {
+ fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_STENCIL;
+ fs_output_semantic_index[fs_num_outputs] = 0;
+ outputMapping[FRAG_RESULT_STENCIL] = fs_num_outputs;
+ fs_num_outputs++;
+ outputsWritten &= ~(1 << FRAG_RESULT_STENCIL);
+ }
+
+ /* handle remaning outputs (color) */
+ for (attr = 0; attr < FRAG_RESULT_MAX; attr++) {
+ if (outputsWritten & BITFIELD64_BIT(attr)) {
+ switch (attr) {
+ case FRAG_RESULT_DEPTH:
+ case FRAG_RESULT_STENCIL:
+ /* handled above */
+ assert(0);
+ break;
+ case FRAG_RESULT_COLOR:
+ write_all = GL_TRUE; /* fallthrough */
+ default:
+ assert(attr == FRAG_RESULT_COLOR ||
+ (FRAG_RESULT_DATA0 <= attr && attr < FRAG_RESULT_MAX));
+ fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_COLOR;
+ fs_output_semantic_index[fs_num_outputs] = numColors;
+ outputMapping[attr] = fs_num_outputs;
+ numColors++;
+ break;
+ }
+
+ fs_num_outputs++;
+ }
+ }
+ }
+
+ ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
+ if (ureg == NULL)
+ return NULL;
+
+ if (ST_DEBUG & DEBUG_MESA) {
+ _mesa_print_program(&stfp->Base.Base);
+ _mesa_print_program_parameters(st->ctx, &stfp->Base.Base);
+ debug_printf("\n");
+ }
+ if (write_all == GL_TRUE)
+ ureg_property_fs_color0_writes_all_cbufs(ureg, 1);
+
+ error = st_translate_mesa_program(st->ctx,
+ TGSI_PROCESSOR_FRAGMENT,
+ ureg,
+ &stfp->Base.Base,
+ /* inputs */
+ fs_num_inputs,
+ inputMapping,
+ input_semantic_name,
+ input_semantic_index,
+ interpMode,
+ /* outputs */
+ fs_num_outputs,
+ outputMapping,
+ fs_output_semantic_name,
+ fs_output_semantic_index, FALSE );
+
+ stfp->tgsi.tokens = ureg_get_tokens( ureg, NULL );
+ ureg_destroy( ureg );
+ }
+
+ /* fill in variant */
+ variant->driver_shader = pipe->create_fs_state(pipe, &stfp->tgsi);
+ variant->key = *key;
+
+ if (ST_DEBUG & DEBUG_TGSI) {
+ tgsi_dump( stfp->tgsi.tokens, 0/*TGSI_DUMP_VERBOSE*/ );
+ debug_printf("\n");
+ }
+
+ if (deleteFP) {
+ /* Free the temporary program made above */
+ struct gl_fragment_program *fp = &stfp->Base;
+ _mesa_reference_fragprog(st->ctx, &fp, NULL);
+ }
+
+ return variant;
+}
+
+
+/**
+ * Translate fragment program if needed.
+ */
+struct st_fp_variant *
+st_get_fp_variant(struct st_context *st,
+ struct st_fragment_program *stfp,
+ const struct st_fp_variant_key *key)
+{
+ struct st_fp_variant *fpv;
+
+ /* Search for existing variant */
+ for (fpv = stfp->variants; fpv; fpv = fpv->next) {
+ if (memcmp(&fpv->key, key, sizeof(*key)) == 0) {
+ break;
+ }
+ }
+
+ if (!fpv) {
+ /* create new */
+ fpv = st_translate_fragment_program(st, stfp, key);
+ if (fpv) {
+ /* insert into list */
+ fpv->next = stfp->variants;
+ stfp->variants = fpv;
+ }
+ }
+
+ return fpv;
+}
+
+
+/**
+ * Translate a geometry program to create a new variant.
+ */
+static struct st_gp_variant *
+st_translate_geometry_program(struct st_context *st,
+ struct st_geometry_program *stgp,
+ const struct st_gp_variant_key *key)
+{
+ GLuint inputMapping[GEOM_ATTRIB_MAX];
+ GLuint outputMapping[GEOM_RESULT_MAX];
+ struct pipe_context *pipe = st->pipe;
+ enum pipe_error error;
+ GLuint attr;
+ const GLbitfield inputsRead = stgp->Base.Base.InputsRead;
+ GLuint vslot = 0;
+ GLuint num_generic = 0;
+
+ uint gs_num_inputs = 0;
+ uint gs_builtin_inputs = 0;
+ uint gs_array_offset = 0;
+
+ ubyte gs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS];
+ ubyte gs_output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
+ uint gs_num_outputs = 0;
+
+ GLint i;
+ GLuint maxSlot = 0;
+ struct ureg_program *ureg;
+
+ struct st_gp_variant *gpv;
+
+ gpv = CALLOC_STRUCT(st_gp_variant);
+ if (!gpv)
+ return NULL;
+
+ _mesa_remove_output_reads(&stgp->Base.Base, PROGRAM_OUTPUT);
+ _mesa_remove_output_reads(&stgp->Base.Base, PROGRAM_VARYING);
+
+ ureg = ureg_create( TGSI_PROCESSOR_GEOMETRY );
+ if (ureg == NULL) {
+ FREE(gpv);
+ return NULL;
+ }
+
+ /* which vertex output goes to the first geometry input */
+ vslot = 0;
+
+ memset(inputMapping, 0, sizeof(inputMapping));
+ memset(outputMapping, 0, sizeof(outputMapping));
+
+ /*
+ * Convert Mesa program inputs to TGSI input register semantics.
+ */
+ for (attr = 0; attr < GEOM_ATTRIB_MAX; attr++) {
+ if (inputsRead & (1 << attr)) {
+ const GLuint slot = gs_num_inputs;
+
+ gs_num_inputs++;
+
+ inputMapping[attr] = slot;
+
+ stgp->input_map[slot + gs_array_offset] = vslot - gs_builtin_inputs;
+ stgp->input_to_index[attr] = vslot;
+ stgp->index_to_input[vslot] = attr;
+ ++vslot;
+
+ if (attr != GEOM_ATTRIB_PRIMITIVE_ID) {
+ gs_array_offset += 2;
+ } else
+ ++gs_builtin_inputs;
+
+#if 0
+ debug_printf("input map at %d = %d\n",
+ slot + gs_array_offset, stgp->input_map[slot + gs_array_offset]);
+#endif
+
+ switch (attr) {
+ case GEOM_ATTRIB_PRIMITIVE_ID:
+ stgp->input_semantic_name[slot] = TGSI_SEMANTIC_PRIMID;
+ stgp->input_semantic_index[slot] = 0;
+ break;
+ case GEOM_ATTRIB_POSITION:
+ stgp->input_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
+ stgp->input_semantic_index[slot] = 0;
+ break;
+ case GEOM_ATTRIB_COLOR0:
+ stgp->input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
+ stgp->input_semantic_index[slot] = 0;
+ break;
+ case GEOM_ATTRIB_COLOR1:
+ stgp->input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
+ stgp->input_semantic_index[slot] = 1;
+ break;
+ case GEOM_ATTRIB_FOG_FRAG_COORD:
+ stgp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
+ stgp->input_semantic_index[slot] = 0;
+ break;
+ case GEOM_ATTRIB_TEX_COORD:
+ stgp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
+ stgp->input_semantic_index[slot] = num_generic++;
+ break;
+ case GEOM_ATTRIB_VAR0:
+ /* fall-through */
+ default:
+ stgp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
+ stgp->input_semantic_index[slot] = num_generic++;
+ }
+ }
+ }
+
+ /* initialize output semantics to defaults */
+ for (i = 0; i < PIPE_MAX_SHADER_OUTPUTS; i++) {
+ gs_output_semantic_name[i] = TGSI_SEMANTIC_GENERIC;
+ gs_output_semantic_index[i] = 0;
+ }
+
+ num_generic = 0;
+ /*
+ * Determine number of outputs, the (default) output register
+ * mapping and the semantic information for each output.
+ */
+ for (attr = 0; attr < GEOM_RESULT_MAX; attr++) {
+ if (stgp->Base.Base.OutputsWritten & (1 << attr)) {
+ GLuint slot;
+
+ slot = gs_num_outputs;
+ gs_num_outputs++;
+ outputMapping[attr] = slot;
+
+ switch (attr) {
+ case GEOM_RESULT_POS:
+ assert(slot == 0);
+ gs_output_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
+ gs_output_semantic_index[slot] = 0;
+ break;
+ case GEOM_RESULT_COL0:
+ gs_output_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
+ gs_output_semantic_index[slot] = 0;
+ break;
+ case GEOM_RESULT_COL1:
+ gs_output_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
+ gs_output_semantic_index[slot] = 1;
+ break;
+ case GEOM_RESULT_SCOL0:
+ gs_output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR;
+ gs_output_semantic_index[slot] = 0;
+ break;
+ case GEOM_RESULT_SCOL1:
+ gs_output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR;
+ gs_output_semantic_index[slot] = 1;
+ break;
+ case GEOM_RESULT_FOGC:
+ gs_output_semantic_name[slot] = TGSI_SEMANTIC_FOG;
+ gs_output_semantic_index[slot] = 0;
+ break;
+ case GEOM_RESULT_PSIZ:
+ gs_output_semantic_name[slot] = TGSI_SEMANTIC_PSIZE;
+ gs_output_semantic_index[slot] = 0;
+ break;
+ case GEOM_RESULT_TEX0:
+ case GEOM_RESULT_TEX1:
+ case GEOM_RESULT_TEX2:
+ case GEOM_RESULT_TEX3:
+ case GEOM_RESULT_TEX4:
+ case GEOM_RESULT_TEX5:
+ case GEOM_RESULT_TEX6:
+ case GEOM_RESULT_TEX7:
+ /* fall-through */
+ case GEOM_RESULT_VAR0:
+ /* fall-through */
+ default:
+ assert(slot < Elements(gs_output_semantic_name));
+ /* use default semantic info */
+ gs_output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
+ gs_output_semantic_index[slot] = num_generic++;
+ }
+ }
+ }
+
+ assert(gs_output_semantic_name[0] == TGSI_SEMANTIC_POSITION);
+
+ /* find max output slot referenced to compute gs_num_outputs */
+ for (attr = 0; attr < GEOM_RESULT_MAX; attr++) {
+ if (outputMapping[attr] != ~0 && outputMapping[attr] > maxSlot)
+ maxSlot = outputMapping[attr];
+ }
+ gs_num_outputs = maxSlot + 1;
+
+#if 0 /* debug */
+ {
+ GLuint i;
+ printf("outputMapping? %d\n", outputMapping ? 1 : 0);
+ if (outputMapping) {
+ printf("attr -> slot\n");
+ for (i = 0; i < 16; i++) {
+ printf(" %2d %3d\n", i, outputMapping[i]);
+ }
+ }
+ printf("slot sem_name sem_index\n");
+ for (i = 0; i < gs_num_outputs; i++) {
+ printf(" %2d %d %d\n",
+ i,
+ gs_output_semantic_name[i],
+ gs_output_semantic_index[i]);
+ }
+ }
+#endif
+
+ /* free old shader state, if any */
+ if (stgp->tgsi.tokens) {
+ st_free_tokens(stgp->tgsi.tokens);
+ stgp->tgsi.tokens = NULL;
+ }
+
+ ureg_property_gs_input_prim(ureg, stgp->Base.InputType);
+ ureg_property_gs_output_prim(ureg, stgp->Base.OutputType);
+ ureg_property_gs_max_vertices(ureg, stgp->Base.VerticesOut);
+
+ error = st_translate_mesa_program(st->ctx,
+ TGSI_PROCESSOR_GEOMETRY,
+ ureg,
+ &stgp->Base.Base,
+ /* inputs */
+ gs_num_inputs,
+ inputMapping,
+ stgp->input_semantic_name,
+ stgp->input_semantic_index,
+ NULL,
+ /* outputs */
+ gs_num_outputs,
+ outputMapping,
+ gs_output_semantic_name,
+ gs_output_semantic_index,
+ FALSE);
+
+ stgp->num_inputs = gs_num_inputs;
+ stgp->tgsi.tokens = ureg_get_tokens( ureg, NULL );
+ ureg_destroy( ureg );
+
+ /* fill in new variant */
+ gpv->driver_shader = pipe->create_gs_state(pipe, &stgp->tgsi);
+ gpv->key = *key;
+
+ if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) {
+ _mesa_print_program(&stgp->Base.Base);
+ debug_printf("\n");
+ }
+
+ if (ST_DEBUG & DEBUG_TGSI) {
+ tgsi_dump(stgp->tgsi.tokens, 0);
+ debug_printf("\n");
+ }
+
+ return gpv;
+}
+
+
+/**
+ * Get/create geometry program variant.
+ */
+struct st_gp_variant *
+st_get_gp_variant(struct st_context *st,
+ struct st_geometry_program *stgp,
+ const struct st_gp_variant_key *key)
+{
+ struct st_gp_variant *gpv;
+
+ /* Search for existing variant */
+ for (gpv = stgp->variants; gpv; gpv = gpv->next) {
+ if (memcmp(&gpv->key, key, sizeof(*key)) == 0) {
+ break;
+ }
+ }
+
+ if (!gpv) {
+ /* create new */
+ gpv = st_translate_geometry_program(st, stgp, key);
+ if (gpv) {
+ /* insert into list */
+ gpv->next = stgp->variants;
+ stgp->variants = gpv;
+ }
+ }
+
+ return gpv;
+}
+
+
+
+
+/**
+ * Debug- print current shader text
+ */
+void
+st_print_shaders(struct gl_context *ctx)
+{
+ struct gl_shader_program *shProg[3] = {
+ ctx->Shader.CurrentVertexProgram,
+ ctx->Shader.CurrentGeometryProgram,
+ ctx->Shader.CurrentFragmentProgram,
+ };
+ unsigned j;
+
+ for (j = 0; j < 3; j++) {
+ unsigned i;
+
+ if (shProg[j] == NULL)
+ continue;
+
+ for (i = 0; i < shProg[j]->NumShaders; i++) {
+ struct gl_shader *sh;
+
+ switch (shProg[j]->Shaders[i]->Type) {
+ case GL_VERTEX_SHADER:
+ sh = (i != 0) ? NULL : shProg[j]->Shaders[i];
+ break;
+ case GL_GEOMETRY_SHADER_ARB:
+ sh = (i != 1) ? NULL : shProg[j]->Shaders[i];
+ break;
+ case GL_FRAGMENT_SHADER:
+ sh = (i != 2) ? NULL : shProg[j]->Shaders[i];
+ break;
+ default:
+ assert(0);
+ sh = NULL;
+ break;
+ }
+
+ if (sh != NULL) {
+ printf("GLSL shader %u of %u:\n", i, shProg[j]->NumShaders);
+ printf("%s\n", sh->Source);
+ }
+ }
+ }
+}
+
+
+/**
+ * Vert/Geom/Frag programs have per-context variants. Free all the
+ * variants attached to the given program which match the given context.
+ */
+static void
+destroy_program_variants(struct st_context *st, struct gl_program *program)
+{
+ if (!program)
+ return;
+
+ switch (program->Target) {
+ case GL_VERTEX_PROGRAM_ARB:
+ {
+ struct st_vertex_program *stvp = (struct st_vertex_program *) program;
+ struct st_vp_variant *vpv, **prevPtr = &stvp->variants;
+
+ for (vpv = stvp->variants; vpv; ) {
+ struct st_vp_variant *next = vpv->next;
+ if (vpv->key.st == st) {
+ /* unlink from list */
+ *prevPtr = next;
+ /* destroy this variant */
+ delete_vp_variant(st, vpv);
+ }
+ else {
+ prevPtr = &vpv->next;
+ }
+ vpv = next;
+ }
+ }
+ break;
+ case GL_FRAGMENT_PROGRAM_ARB:
+ {
+ struct st_fragment_program *stfp =
+ (struct st_fragment_program *) program;
+ struct st_fp_variant *fpv, **prevPtr = &stfp->variants;
+
+ for (fpv = stfp->variants; fpv; ) {
+ struct st_fp_variant *next = fpv->next;
+ if (fpv->key.st == st) {
+ /* unlink from list */
+ *prevPtr = next;
+ /* destroy this variant */
+ delete_fp_variant(st, fpv);
+ }
+ else {
+ prevPtr = &fpv->next;
+ }
+ fpv = next;
+ }
+ }
+ break;
+ case MESA_GEOMETRY_PROGRAM:
+ {
+ struct st_geometry_program *stgp =
+ (struct st_geometry_program *) program;
+ struct st_gp_variant *gpv, **prevPtr = &stgp->variants;
+
+ for (gpv = stgp->variants; gpv; ) {
+ struct st_gp_variant *next = gpv->next;
+ if (gpv->key.st == st) {
+ /* unlink from list */
+ *prevPtr = next;
+ /* destroy this variant */
+ delete_gp_variant(st, gpv);
+ }
+ else {
+ prevPtr = &gpv->next;
+ }
+ gpv = next;
+ }
+ }
+ break;
+ default:
+ _mesa_problem(NULL, "Unexpected program target in "
+ "destroy_program_variants_cb()");
+ }
+}
+
+
+/**
+ * Callback for _mesa_HashWalk. Free all the shader's program variants
+ * which match the given context.
+ */
+static void
+destroy_shader_program_variants_cb(GLuint key, void *data, void *userData)
+{
+ struct st_context *st = (struct st_context *) userData;
+ struct gl_shader *shader = (struct gl_shader *) data;
+
+ switch (shader->Type) {
+ case GL_SHADER_PROGRAM_MESA:
+ {
+ struct gl_shader_program *shProg = (struct gl_shader_program *) data;
+ GLuint i;
+
+ for (i = 0; i < shProg->NumShaders; i++) {
+ destroy_program_variants(st, shProg->Shaders[i]->Program);
+ }
+
+ destroy_program_variants(st, (struct gl_program *)
+ shProg->VertexProgram);
+ destroy_program_variants(st, (struct gl_program *)
+ shProg->FragmentProgram);
+ destroy_program_variants(st, (struct gl_program *)
+ shProg->GeometryProgram);
+ }
+ break;
+ case GL_VERTEX_SHADER:
+ case GL_FRAGMENT_SHADER:
+ case GL_GEOMETRY_SHADER:
+ {
+ destroy_program_variants(st, shader->Program);
+ }
+ break;
+ default:
+ assert(0);
+ }
+}
+
+
+/**
+ * Callback for _mesa_HashWalk. Free all the program variants which match
+ * the given context.
+ */
+static void
+destroy_program_variants_cb(GLuint key, void *data, void *userData)
+{
+ struct st_context *st = (struct st_context *) userData;
+ struct gl_program *program = (struct gl_program *) data;
+ destroy_program_variants(st, program);
+}
+
+
+/**
+ * Walk over all shaders and programs to delete any variants which
+ * belong to the given context.
+ * This is called during context tear-down.
+ */
+void
+st_destroy_program_variants(struct st_context *st)
+{
+ /* ARB vert/frag program */
+ _mesa_HashWalk(st->ctx->Shared->Programs,
+ destroy_program_variants_cb, st);
+
+ /* GLSL vert/frag/geom shaders */
+ _mesa_HashWalk(st->ctx->Shared->ShaderObjects,
+ destroy_shader_program_variants_cb, st);
+}
diff --git a/mesalib/src/mesa/swrast/s_bitmap.c b/mesalib/src/mesa/swrast/s_bitmap.c
index 18f1c1866..af65874fd 100644
--- a/mesalib/src/mesa/swrast/s_bitmap.c
+++ b/mesalib/src/mesa/swrast/s_bitmap.c
@@ -1,223 +1,223 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file swrast/s_bitmap.c
- * \brief glBitmap rendering.
- * \author Brian Paul
- */
-
-#include "main/glheader.h"
-#include "main/bufferobj.h"
-#include "main/condrender.h"
-#include "main/image.h"
-#include "main/macros.h"
-#include "main/pbo.h"
-
-#include "s_context.h"
-#include "s_span.h"
-
-
-
-/**
- * Render a bitmap.
- * Called via ctx->Driver.Bitmap()
- * All parameter error checking will have been done before this is called.
- */
-void
-_swrast_Bitmap( struct gl_context *ctx, GLint px, GLint py,
- GLsizei width, GLsizei height,
- const struct gl_pixelstore_attrib *unpack,
- const GLubyte *bitmap )
-{
- GLint row, col;
- GLuint count = 0;
- SWspan span;
-
- ASSERT(ctx->RenderMode == GL_RENDER);
-
- if (!_mesa_check_conditional_render(ctx))
- return; /* don't draw */
-
- bitmap = (const GLubyte *) _mesa_map_pbo_source(ctx, unpack, bitmap);
- if (!bitmap)
- return;
-
- swrast_render_start(ctx);
-
- if (SWRAST_CONTEXT(ctx)->NewState)
- _swrast_validate_derived( ctx );
-
- INIT_SPAN(span, GL_BITMAP);
- span.end = width;
- span.arrayMask = SPAN_XY;
- _swrast_span_default_attribs(ctx, &span);
-
- for (row = 0; row < height; row++) {
- const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
- bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
-
- if (unpack->LsbFirst) {
- /* Lsb first */
- GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
- for (col = 0; col < width; col++) {
- if (*src & mask) {
- span.array->x[count] = px + col;
- span.array->y[count] = py + row;
- count++;
- }
- if (mask == 128U) {
- src++;
- mask = 1U;
- }
- else {
- mask = mask << 1;
- }
- }
-
- /* get ready for next row */
- if (mask != 1)
- src++;
- }
- else {
- /* Msb first */
- GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
- for (col = 0; col < width; col++) {
- if (*src & mask) {
- span.array->x[count] = px + col;
- span.array->y[count] = py + row;
- count++;
- }
- if (mask == 1U) {
- src++;
- mask = 128U;
- }
- else {
- mask = mask >> 1;
- }
- }
-
- /* get ready for next row */
- if (mask != 128)
- src++;
- }
-
- if (count + width >= MAX_WIDTH || row + 1 == height) {
- /* flush the span */
- span.end = count;
- _swrast_write_rgba_span(ctx, &span);
- span.end = 0;
- count = 0;
- }
- }
-
- swrast_render_finish(ctx);
-
- _mesa_unmap_pbo_source(ctx, unpack);
-}
-
-
-#if 0
-/*
- * XXX this is another way to implement Bitmap. Use horizontal runs of
- * fragments, initializing the mask array to indicate which fragments to
- * draw or skip.
- */
-void
-_swrast_Bitmap( struct gl_context *ctx, GLint px, GLint py,
- GLsizei width, GLsizei height,
- const struct gl_pixelstore_attrib *unpack,
- const GLubyte *bitmap )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- GLint row, col;
- SWspan span;
-
- ASSERT(ctx->RenderMode == GL_RENDER);
- ASSERT(bitmap);
-
- swrast_render_start(ctx);
-
- if (SWRAST_CONTEXT(ctx)->NewState)
- _swrast_validate_derived( ctx );
-
- INIT_SPAN(span, GL_BITMAP);
- span.end = width;
- span.arrayMask = SPAN_MASK;
- _swrast_span_default_attribs(ctx, &span);
-
- /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
- span.x = px;
- span.y = py;
- /*span.end = width;*/
-
- for (row=0; row<height; row++, span.y++) {
- const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
- bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
-
- if (unpack->LsbFirst) {
- /* Lsb first */
- GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
- for (col=0; col<width; col++) {
- span.array->mask[col] = (*src & mask) ? GL_TRUE : GL_FALSE;
- if (mask == 128U) {
- src++;
- mask = 1U;
- }
- else {
- mask = mask << 1;
- }
- }
-
- _swrast_write_rgba_span(ctx, &span);
-
- /* get ready for next row */
- if (mask != 1)
- src++;
- }
- else {
- /* Msb first */
- GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
- for (col=0; col<width; col++) {
- span.array->mask[col] = (*src & mask) ? GL_TRUE : GL_FALSE;
- if (mask == 1U) {
- src++;
- mask = 128U;
- }
- else {
- mask = mask >> 1;
- }
- }
-
- _swrast_write_rgba_span(ctx, &span);
-
- /* get ready for next row */
- if (mask != 128)
- src++;
- }
- }
-
- swrast_render_finish(ctx);
-}
-#endif
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file swrast/s_bitmap.c
+ * \brief glBitmap rendering.
+ * \author Brian Paul
+ */
+
+#include "main/glheader.h"
+#include "main/bufferobj.h"
+#include "main/condrender.h"
+#include "main/image.h"
+#include "main/macros.h"
+#include "main/pbo.h"
+
+#include "s_context.h"
+#include "s_span.h"
+
+
+
+/**
+ * Render a bitmap.
+ * Called via ctx->Driver.Bitmap()
+ * All parameter error checking will have been done before this is called.
+ */
+void
+_swrast_Bitmap( struct gl_context *ctx, GLint px, GLint py,
+ GLsizei width, GLsizei height,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLubyte *bitmap )
+{
+ GLint row, col;
+ GLuint count = 0;
+ SWspan span;
+
+ ASSERT(ctx->RenderMode == GL_RENDER);
+
+ if (!_mesa_check_conditional_render(ctx))
+ return; /* don't draw */
+
+ bitmap = (const GLubyte *) _mesa_map_pbo_source(ctx, unpack, bitmap);
+ if (!bitmap)
+ return;
+
+ swrast_render_start(ctx);
+
+ if (SWRAST_CONTEXT(ctx)->NewState)
+ _swrast_validate_derived( ctx );
+
+ INIT_SPAN(span, GL_BITMAP);
+ span.end = width;
+ span.arrayMask = SPAN_XY;
+ _swrast_span_default_attribs(ctx, &span);
+
+ for (row = 0; row < height; row++) {
+ const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
+ bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
+
+ if (unpack->LsbFirst) {
+ /* Lsb first */
+ GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
+ for (col = 0; col < width; col++) {
+ if (*src & mask) {
+ span.array->x[count] = px + col;
+ span.array->y[count] = py + row;
+ count++;
+ }
+ if (mask == 128U) {
+ src++;
+ mask = 1U;
+ }
+ else {
+ mask = mask << 1;
+ }
+ }
+
+ /* get ready for next row */
+ if (mask != 1)
+ src++;
+ }
+ else {
+ /* Msb first */
+ GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
+ for (col = 0; col < width; col++) {
+ if (*src & mask) {
+ span.array->x[count] = px + col;
+ span.array->y[count] = py + row;
+ count++;
+ }
+ if (mask == 1U) {
+ src++;
+ mask = 128U;
+ }
+ else {
+ mask = mask >> 1;
+ }
+ }
+
+ /* get ready for next row */
+ if (mask != 128)
+ src++;
+ }
+
+ if (count + width >= MAX_WIDTH || row + 1 == height) {
+ /* flush the span */
+ span.end = count;
+ _swrast_write_rgba_span(ctx, &span);
+ span.end = 0;
+ count = 0;
+ }
+ }
+
+ swrast_render_finish(ctx);
+
+ _mesa_unmap_pbo_source(ctx, unpack);
+}
+
+
+#if 0
+/*
+ * XXX this is another way to implement Bitmap. Use horizontal runs of
+ * fragments, initializing the mask array to indicate which fragments to
+ * draw or skip.
+ */
+void
+_swrast_Bitmap( struct gl_context *ctx, GLint px, GLint py,
+ GLsizei width, GLsizei height,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLubyte *bitmap )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ GLint row, col;
+ SWspan span;
+
+ ASSERT(ctx->RenderMode == GL_RENDER);
+ ASSERT(bitmap);
+
+ swrast_render_start(ctx);
+
+ if (SWRAST_CONTEXT(ctx)->NewState)
+ _swrast_validate_derived( ctx );
+
+ INIT_SPAN(span, GL_BITMAP);
+ span.end = width;
+ span.arrayMask = SPAN_MASK;
+ _swrast_span_default_attribs(ctx, &span);
+
+ /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
+ span.x = px;
+ span.y = py;
+ /*span.end = width;*/
+
+ for (row=0; row<height; row++, span.y++) {
+ const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
+ bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
+
+ if (unpack->LsbFirst) {
+ /* Lsb first */
+ GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
+ for (col=0; col<width; col++) {
+ span.array->mask[col] = (*src & mask) ? GL_TRUE : GL_FALSE;
+ if (mask == 128U) {
+ src++;
+ mask = 1U;
+ }
+ else {
+ mask = mask << 1;
+ }
+ }
+
+ _swrast_write_rgba_span(ctx, &span);
+
+ /* get ready for next row */
+ if (mask != 1)
+ src++;
+ }
+ else {
+ /* Msb first */
+ GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
+ for (col=0; col<width; col++) {
+ span.array->mask[col] = (*src & mask) ? GL_TRUE : GL_FALSE;
+ if (mask == 1U) {
+ src++;
+ mask = 128U;
+ }
+ else {
+ mask = mask >> 1;
+ }
+ }
+
+ _swrast_write_rgba_span(ctx, &span);
+
+ /* get ready for next row */
+ if (mask != 128)
+ src++;
+ }
+ }
+
+ swrast_render_finish(ctx);
+}
+#endif
diff --git a/mesalib/src/mesa/swrast/s_drawpix.c b/mesalib/src/mesa/swrast/s_drawpix.c
index 11c63457f..71f998324 100644
--- a/mesalib/src/mesa/swrast/s_drawpix.c
+++ b/mesalib/src/mesa/swrast/s_drawpix.c
@@ -1,753 +1,753 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "main/glheader.h"
-#include "main/bufferobj.h"
-#include "main/condrender.h"
-#include "main/context.h"
-#include "main/image.h"
-#include "main/imports.h"
-#include "main/macros.h"
-#include "main/pack.h"
-#include "main/pbo.h"
-#include "main/pixeltransfer.h"
-#include "main/state.h"
-
-#include "s_context.h"
-#include "s_span.h"
-#include "s_stencil.h"
-#include "s_zoom.h"
-
-
-
-/**
- * Try to do a fast and simple RGB(a) glDrawPixels.
- * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead
- */
-static GLboolean
-fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *userUnpack,
- const GLvoid *pixels)
-{
- const GLint imgX = x, imgY = y;
- struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
- GLenum rbType;
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- SWspan span;
- GLboolean simpleZoom;
- GLint yStep; /* +1 or -1 */
- struct gl_pixelstore_attrib unpack;
- GLint destX, destY, drawWidth, drawHeight; /* post clipping */
-
- if (!rb)
- return GL_TRUE; /* no-op */
-
- rbType = rb->DataType;
-
- if ((swrast->_RasterMask & ~CLIP_BIT) ||
- ctx->Texture._EnabledCoordUnits ||
- userUnpack->SwapBytes ||
- ctx->_ImageTransferState) {
- /* can't handle any of those conditions */
- return GL_FALSE;
- }
-
- INIT_SPAN(span, GL_BITMAP);
- span.arrayMask = SPAN_RGBA;
- span.arrayAttribs = FRAG_BIT_COL0;
- _swrast_span_default_attribs(ctx, &span);
-
- /* copy input params since clipping may change them */
- unpack = *userUnpack;
- destX = x;
- destY = y;
- drawWidth = width;
- drawHeight = height;
-
- /* check for simple zooming and clipping */
- if (ctx->Pixel.ZoomX == 1.0F &&
- (ctx->Pixel.ZoomY == 1.0F || ctx->Pixel.ZoomY == -1.0F)) {
- if (!_mesa_clip_drawpixels(ctx, &destX, &destY,
- &drawWidth, &drawHeight, &unpack)) {
- /* image was completely clipped: no-op, all done */
- return GL_TRUE;
- }
- simpleZoom = GL_TRUE;
- yStep = (GLint) ctx->Pixel.ZoomY;
- ASSERT(yStep == 1 || yStep == -1);
- }
- else {
- /* non-simple zooming */
- simpleZoom = GL_FALSE;
- yStep = 1;
- if (unpack.RowLength == 0)
- unpack.RowLength = width;
- }
-
- /*
- * Ready to draw!
- */
-
- if (format == GL_RGBA && type == rbType) {
- const GLubyte *src
- = (const GLubyte *) _mesa_image_address2d(&unpack, pixels, width,
- height, format, type, 0, 0);
- const GLint srcStride = _mesa_image_row_stride(&unpack, width,
- format, type);
- if (simpleZoom) {
- GLint row;
- for (row = 0; row < drawHeight; row++) {
- rb->PutRow(ctx, rb, drawWidth, destX, destY, src, NULL);
- src += srcStride;
- destY += yStep;
- }
- }
- else {
- /* with zooming */
- GLint row;
- for (row = 0; row < drawHeight; row++) {
- span.x = destX;
- span.y = destY + row;
- span.end = drawWidth;
- span.array->ChanType = rbType;
- _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span, src);
- src += srcStride;
- }
- span.array->ChanType = CHAN_TYPE;
- }
- return GL_TRUE;
- }
-
- if (format == GL_RGB && type == rbType) {
- const GLubyte *src
- = (const GLubyte *) _mesa_image_address2d(&unpack, pixels, width,
- height, format, type, 0, 0);
- const GLint srcStride = _mesa_image_row_stride(&unpack, width,
- format, type);
- if (simpleZoom) {
- GLint row;
- for (row = 0; row < drawHeight; row++) {
- rb->PutRowRGB(ctx, rb, drawWidth, destX, destY, src, NULL);
- src += srcStride;
- destY += yStep;
- }
- }
- else {
- /* with zooming */
- GLint row;
- for (row = 0; row < drawHeight; row++) {
- span.x = destX;
- span.y = destY;
- span.end = drawWidth;
- span.array->ChanType = rbType;
- _swrast_write_zoomed_rgb_span(ctx, imgX, imgY, &span, src);
- src += srcStride;
- destY++;
- }
- span.array->ChanType = CHAN_TYPE;
- }
- return GL_TRUE;
- }
-
- /* Remaining cases haven't been tested with alignment != 1 */
- if (userUnpack->Alignment != 1)
- return GL_FALSE;
-
- if (format == GL_LUMINANCE && type == CHAN_TYPE && rbType == CHAN_TYPE) {
- const GLchan *src = (const GLchan *) pixels
- + (unpack.SkipRows * unpack.RowLength + unpack.SkipPixels);
- if (simpleZoom) {
- /* no zooming */
- GLint row;
- ASSERT(drawWidth <= MAX_WIDTH);
- for (row = 0; row < drawHeight; row++) {
- GLchan rgb[MAX_WIDTH][3];
- GLint i;
- for (i = 0;i<drawWidth;i++) {
- rgb[i][0] = src[i];
- rgb[i][1] = src[i];
- rgb[i][2] = src[i];
- }
- rb->PutRowRGB(ctx, rb, drawWidth, destX, destY, rgb, NULL);
- src += unpack.RowLength;
- destY += yStep;
- }
- }
- else {
- /* with zooming */
- GLint row;
- ASSERT(drawWidth <= MAX_WIDTH);
- for (row = 0; row < drawHeight; row++) {
- GLchan rgb[MAX_WIDTH][3];
- GLint i;
- for (i = 0;i<drawWidth;i++) {
- rgb[i][0] = src[i];
- rgb[i][1] = src[i];
- rgb[i][2] = src[i];
- }
- span.x = destX;
- span.y = destY;
- span.end = drawWidth;
- _swrast_write_zoomed_rgb_span(ctx, imgX, imgY, &span, rgb);
- src += unpack.RowLength;
- destY++;
- }
- }
- return GL_TRUE;
- }
-
- if (format == GL_LUMINANCE_ALPHA && type == CHAN_TYPE && rbType == CHAN_TYPE) {
- const GLchan *src = (const GLchan *) pixels
- + (unpack.SkipRows * unpack.RowLength + unpack.SkipPixels)*2;
- if (simpleZoom) {
- GLint row;
- ASSERT(drawWidth <= MAX_WIDTH);
- for (row = 0; row < drawHeight; row++) {
- GLint i;
- const GLchan *ptr = src;
- for (i = 0;i<drawWidth;i++) {
- span.array->rgba[i][0] = *ptr;
- span.array->rgba[i][1] = *ptr;
- span.array->rgba[i][2] = *ptr++;
- span.array->rgba[i][3] = *ptr++;
- }
- rb->PutRow(ctx, rb, drawWidth, destX, destY,
- span.array->rgba, NULL);
- src += unpack.RowLength*2;
- destY += yStep;
- }
- }
- else {
- /* with zooming */
- GLint row;
- ASSERT(drawWidth <= MAX_WIDTH);
- for (row = 0; row < drawHeight; row++) {
- const GLchan *ptr = src;
- GLint i;
- for (i = 0;i<drawWidth;i++) {
- span.array->rgba[i][0] = *ptr;
- span.array->rgba[i][1] = *ptr;
- span.array->rgba[i][2] = *ptr++;
- span.array->rgba[i][3] = *ptr++;
- }
- span.x = destX;
- span.y = destY;
- span.end = drawWidth;
- _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span,
- span.array->rgba);
- src += unpack.RowLength*2;
- destY++;
- }
- }
- return GL_TRUE;
- }
-
- if (format == GL_COLOR_INDEX && type == GL_UNSIGNED_BYTE) {
- const GLubyte *src = (const GLubyte *) pixels
- + unpack.SkipRows * unpack.RowLength + unpack.SkipPixels;
- if (rbType == GL_UNSIGNED_BYTE) {
- /* convert ubyte/CI data to ubyte/RGBA */
- if (simpleZoom) {
- GLint row;
- for (row = 0; row < drawHeight; row++) {
- ASSERT(drawWidth <= MAX_WIDTH);
- _mesa_map_ci8_to_rgba8(ctx, drawWidth, src,
- span.array->rgba8);
- rb->PutRow(ctx, rb, drawWidth, destX, destY,
- span.array->rgba8, NULL);
- src += unpack.RowLength;
- destY += yStep;
- }
- }
- else {
- /* ubyte/CI to ubyte/RGBA with zooming */
- GLint row;
- for (row = 0; row < drawHeight; row++) {
- ASSERT(drawWidth <= MAX_WIDTH);
- _mesa_map_ci8_to_rgba8(ctx, drawWidth, src,
- span.array->rgba8);
- span.x = destX;
- span.y = destY;
- span.end = drawWidth;
- _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span,
- span.array->rgba8);
- src += unpack.RowLength;
- destY++;
- }
- }
- return GL_TRUE;
- }
- }
-
- /* can't handle this pixel format and/or data type */
- return GL_FALSE;
-}
-
-
-
-/*
- * Draw stencil image.
- */
-static void
-draw_stencil_pixels( struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels )
-{
- const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
- GLint skipPixels;
-
- /* if width > MAX_WIDTH, have to process image in chunks */
- skipPixels = 0;
- while (skipPixels < width) {
- const GLint spanX = x + skipPixels;
- const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
- GLint row;
- for (row = 0; row < height; row++) {
- const GLint spanY = y + row;
- GLstencil values[MAX_WIDTH];
- GLenum destType = (sizeof(GLstencil) == sizeof(GLubyte))
- ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
- const GLvoid *source = _mesa_image_address2d(unpack, pixels,
- width, height,
- GL_COLOR_INDEX, type,
- row, skipPixels);
- _mesa_unpack_stencil_span(ctx, spanWidth, destType, values,
- type, source, unpack,
- ctx->_ImageTransferState);
- if (zoom) {
- _swrast_write_zoomed_stencil_span(ctx, x, y, spanWidth,
- spanX, spanY, values);
- }
- else {
- _swrast_write_stencil_span(ctx, spanWidth, spanX, spanY, values);
- }
- }
- skipPixels += spanWidth;
- }
-}
-
-
-/*
- * Draw depth image.
- */
-static void
-draw_depth_pixels( struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels )
-{
- const GLboolean scaleOrBias
- = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
- const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
- SWspan span;
-
- INIT_SPAN(span, GL_BITMAP);
- span.arrayMask = SPAN_Z;
- _swrast_span_default_attribs(ctx, &span);
-
- if (type == GL_UNSIGNED_SHORT
- && ctx->DrawBuffer->Visual.depthBits == 16
- && !scaleOrBias
- && !zoom
- && width <= MAX_WIDTH
- && !unpack->SwapBytes) {
- /* Special case: directly write 16-bit depth values */
- GLint row;
- for (row = 0; row < height; row++) {
- const GLushort *zSrc = (const GLushort *)
- _mesa_image_address2d(unpack, pixels, width, height,
- GL_DEPTH_COMPONENT, type, row, 0);
- GLint i;
- for (i = 0; i < width; i++)
- span.array->z[i] = zSrc[i];
- span.x = x;
- span.y = y + row;
- span.end = width;
- _swrast_write_rgba_span(ctx, &span);
- }
- }
- else if (type == GL_UNSIGNED_INT
- && !scaleOrBias
- && !zoom
- && width <= MAX_WIDTH
- && !unpack->SwapBytes) {
- /* Special case: shift 32-bit values down to Visual.depthBits */
- const GLint shift = 32 - ctx->DrawBuffer->Visual.depthBits;
- GLint row;
- for (row = 0; row < height; row++) {
- const GLuint *zSrc = (const GLuint *)
- _mesa_image_address2d(unpack, pixels, width, height,
- GL_DEPTH_COMPONENT, type, row, 0);
- if (shift == 0) {
- memcpy(span.array->z, zSrc, width * sizeof(GLuint));
- }
- else {
- GLint col;
- for (col = 0; col < width; col++)
- span.array->z[col] = zSrc[col] >> shift;
- }
- span.x = x;
- span.y = y + row;
- span.end = width;
- _swrast_write_rgba_span(ctx, &span);
- }
- }
- else {
- /* General case */
- const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
- GLint skipPixels = 0;
-
- /* in case width > MAX_WIDTH do the copy in chunks */
- while (skipPixels < width) {
- const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
- GLint row;
- ASSERT(span.end <= MAX_WIDTH);
- for (row = 0; row < height; row++) {
- const GLvoid *zSrc = _mesa_image_address2d(unpack,
- pixels, width, height,
- GL_DEPTH_COMPONENT, type,
- row, skipPixels);
-
- /* Set these for each row since the _swrast_write_* function may
- * change them while clipping.
- */
- span.x = x + skipPixels;
- span.y = y + row;
- span.end = spanWidth;
-
- _mesa_unpack_depth_span(ctx, spanWidth,
- GL_UNSIGNED_INT, span.array->z, depthMax,
- type, zSrc, unpack);
- if (zoom) {
- _swrast_write_zoomed_depth_span(ctx, x, y, &span);
- }
- else {
- _swrast_write_rgba_span(ctx, &span);
- }
- }
- skipPixels += spanWidth;
- }
- }
-}
-
-
-
-/**
- * Draw RGBA image.
- */
-static void
-draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels )
-{
- const GLint imgX = x, imgY = y;
- const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
- GLfloat *convImage = NULL;
- GLbitfield transferOps = ctx->_ImageTransferState;
- SWspan span;
-
- /* Try an optimized glDrawPixels first */
- if (fast_draw_rgba_pixels(ctx, x, y, width, height, format, type,
- unpack, pixels)) {
- return;
- }
-
- INIT_SPAN(span, GL_BITMAP);
- _swrast_span_default_attribs(ctx, &span);
- span.arrayMask = SPAN_RGBA;
- span.arrayAttribs = FRAG_BIT_COL0; /* we're fill in COL0 attrib values */
-
- if (ctx->DrawBuffer->_NumColorDrawBuffers > 0 &&
- ctx->DrawBuffer->_ColorDrawBuffers[0]->DataType != GL_FLOAT &&
- ctx->Color.ClampFragmentColor != GL_FALSE) {
- /* need to clamp colors before applying fragment ops */
- transferOps |= IMAGE_CLAMP_BIT;
- }
-
- /*
- * General solution
- */
- {
- const GLbitfield interpMask = span.interpMask;
- const GLbitfield arrayMask = span.arrayMask;
- const GLint srcStride
- = _mesa_image_row_stride(unpack, width, format, type);
- GLint skipPixels = 0;
- /* use span array for temp color storage */
- GLfloat *rgba = (GLfloat *) span.array->attribs[FRAG_ATTRIB_COL0];
-
- /* if the span is wider than MAX_WIDTH we have to do it in chunks */
- while (skipPixels < width) {
- const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
- const GLubyte *source
- = (const GLubyte *) _mesa_image_address2d(unpack, pixels,
- width, height, format,
- type, 0, skipPixels);
- GLint row;
-
- for (row = 0; row < height; row++) {
- /* get image row as float/RGBA */
- _mesa_unpack_color_span_float(ctx, spanWidth, GL_RGBA, rgba,
- format, type, source, unpack,
- transferOps);
- /* Set these for each row since the _swrast_write_* functions
- * may change them while clipping/rendering.
- */
- span.array->ChanType = GL_FLOAT;
- span.x = x + skipPixels;
- span.y = y + row;
- span.end = spanWidth;
- span.arrayMask = arrayMask;
- span.interpMask = interpMask;
- if (zoom) {
- _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span, rgba);
- }
- else {
- _swrast_write_rgba_span(ctx, &span);
- }
-
- source += srcStride;
- } /* for row */
-
- skipPixels += spanWidth;
- } /* while skipPixels < width */
-
- /* XXX this is ugly/temporary, to undo above change */
- span.array->ChanType = CHAN_TYPE;
- }
-
- if (convImage) {
- free(convImage);
- }
-}
-
-
-/**
- * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
- * The only per-pixel operations that apply are depth scale/bias,
- * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
- * and pixel zoom.
- * Also, only the depth buffer and stencil buffers are touched, not the
- * color buffer(s).
- */
-static void
-draw_depth_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height, GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels)
-{
- const GLint imgX = x, imgY = y;
- const GLboolean scaleOrBias
- = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
- const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
- const GLuint stencilMask = ctx->Stencil.WriteMask[0];
- const GLuint stencilType = (STENCIL_BITS == 8) ?
- GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
- const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
- struct gl_renderbuffer *depthRb, *stencilRb;
- struct gl_pixelstore_attrib clippedUnpack = *unpack;
-
- if (!zoom) {
- if (!_mesa_clip_drawpixels(ctx, &x, &y, &width, &height,
- &clippedUnpack)) {
- /* totally clipped */
- return;
- }
- }
-
- depthRb = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
- stencilRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
- ASSERT(depthRb);
- ASSERT(stencilRb);
-
- if (depthRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
- stencilRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
- depthRb == stencilRb &&
- !scaleOrBias &&
- !zoom &&
- ctx->Depth.Mask &&
- (stencilMask & 0xff) == 0xff) {
- /* This is the ideal case.
- * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
- * Plus, no pixel transfer ops, zooming, or masking needed.
- */
- GLint i;
- for (i = 0; i < height; i++) {
- const GLuint *src = (const GLuint *)
- _mesa_image_address2d(&clippedUnpack, pixels, width, height,
- GL_DEPTH_STENCIL_EXT, type, i, 0);
- depthRb->PutRow(ctx, depthRb, width, x, y + i, src, NULL);
- }
- }
- else {
- /* sub-optimal cases:
- * Separate depth/stencil buffers, or pixel transfer ops required.
- */
- /* XXX need to handle very wide images (skippixels) */
- GLint i;
-
- depthRb = ctx->DrawBuffer->_DepthBuffer;
- stencilRb = ctx->DrawBuffer->_StencilBuffer;
-
- for (i = 0; i < height; i++) {
- const GLuint *depthStencilSrc = (const GLuint *)
- _mesa_image_address2d(&clippedUnpack, pixels, width, height,
- GL_DEPTH_STENCIL_EXT, type, i, 0);
-
- if (ctx->Depth.Mask) {
- if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 24) {
- /* fast path 24-bit zbuffer */
- GLuint zValues[MAX_WIDTH];
- GLint j;
- ASSERT(depthRb->DataType == GL_UNSIGNED_INT);
- for (j = 0; j < width; j++) {
- zValues[j] = depthStencilSrc[j] >> 8;
- }
- if (zoom)
- _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,
- x, y + i, zValues);
- else
- depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
- }
- else if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 16) {
- /* fast path 16-bit zbuffer */
- GLushort zValues[MAX_WIDTH];
- GLint j;
- ASSERT(depthRb->DataType == GL_UNSIGNED_SHORT);
- for (j = 0; j < width; j++) {
- zValues[j] = depthStencilSrc[j] >> 16;
- }
- if (zoom)
- _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,
- x, y + i, zValues);
- else
- depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
- }
- else {
- /* general case */
- GLuint zValues[MAX_WIDTH]; /* 16 or 32-bit Z value storage */
- _mesa_unpack_depth_span(ctx, width,
- depthRb->DataType, zValues, depthMax,
- type, depthStencilSrc, &clippedUnpack);
- if (zoom) {
- _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x,
- y + i, zValues);
- }
- else {
- depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
- }
- }
- }
-
- if (stencilMask != 0x0) {
- GLstencil stencilValues[MAX_WIDTH];
- /* get stencil values, with shift/offset/mapping */
- _mesa_unpack_stencil_span(ctx, width, stencilType, stencilValues,
- type, depthStencilSrc, &clippedUnpack,
- ctx->_ImageTransferState);
- if (zoom)
- _swrast_write_zoomed_stencil_span(ctx, imgX, imgY, width,
- x, y + i, stencilValues);
- else
- _swrast_write_stencil_span(ctx, width, x, y + i, stencilValues);
- }
- }
- }
-}
-
-
-/**
- * Execute software-based glDrawPixels.
- * By time we get here, all error checking will have been done.
- */
-void
-_swrast_DrawPixels( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *unpack,
- const GLvoid *pixels )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- GLboolean save_vp_override = ctx->VertexProgram._Overriden;
-
- if (!_mesa_check_conditional_render(ctx))
- return; /* don't draw */
-
- /* We are creating fragments directly, without going through vertex
- * programs.
- *
- * This override flag tells the fragment processing code that its input
- * comes from a non-standard source, and it may therefore not rely on
- * optimizations that assume e.g. constant color if there is no color
- * vertex array.
- */
- _mesa_set_vp_override(ctx, GL_TRUE);
-
- swrast_render_start(ctx);
-
- if (ctx->NewState)
- _mesa_update_state(ctx);
-
- if (swrast->NewState)
- _swrast_validate_derived( ctx );
-
- pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
- if (!pixels) {
- swrast_render_finish(ctx);
- _mesa_set_vp_override(ctx, save_vp_override);
- return;
- }
-
- /*
- * By time we get here, all error checking should have been done.
- */
- switch (format) {
- case GL_STENCIL_INDEX:
- draw_stencil_pixels( ctx, x, y, width, height, type, unpack, pixels );
- break;
- case GL_DEPTH_COMPONENT:
- draw_depth_pixels( ctx, x, y, width, height, type, unpack, pixels );
- break;
- case GL_DEPTH_STENCIL_EXT:
- draw_depth_stencil_pixels(ctx, x, y, width, height, type, unpack, pixels);
- break;
- default:
- /* all other formats should be color formats */
- draw_rgba_pixels(ctx, x, y, width, height, format, type, unpack, pixels);
- }
-
- swrast_render_finish(ctx);
- _mesa_set_vp_override(ctx, save_vp_override);
-
- _mesa_unmap_pbo_source(ctx, unpack);
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "main/glheader.h"
+#include "main/bufferobj.h"
+#include "main/condrender.h"
+#include "main/context.h"
+#include "main/image.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/pack.h"
+#include "main/pbo.h"
+#include "main/pixeltransfer.h"
+#include "main/state.h"
+
+#include "s_context.h"
+#include "s_span.h"
+#include "s_stencil.h"
+#include "s_zoom.h"
+
+
+
+/**
+ * Try to do a fast and simple RGB(a) glDrawPixels.
+ * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead
+ */
+static GLboolean
+fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *userUnpack,
+ const GLvoid *pixels)
+{
+ const GLint imgX = x, imgY = y;
+ struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
+ GLenum rbType;
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ SWspan span;
+ GLboolean simpleZoom;
+ GLint yStep; /* +1 or -1 */
+ struct gl_pixelstore_attrib unpack;
+ GLint destX, destY, drawWidth, drawHeight; /* post clipping */
+
+ if (!rb)
+ return GL_TRUE; /* no-op */
+
+ rbType = rb->DataType;
+
+ if ((swrast->_RasterMask & ~CLIP_BIT) ||
+ ctx->Texture._EnabledCoordUnits ||
+ userUnpack->SwapBytes ||
+ ctx->_ImageTransferState) {
+ /* can't handle any of those conditions */
+ return GL_FALSE;
+ }
+
+ INIT_SPAN(span, GL_BITMAP);
+ span.arrayMask = SPAN_RGBA;
+ span.arrayAttribs = FRAG_BIT_COL0;
+ _swrast_span_default_attribs(ctx, &span);
+
+ /* copy input params since clipping may change them */
+ unpack = *userUnpack;
+ destX = x;
+ destY = y;
+ drawWidth = width;
+ drawHeight = height;
+
+ /* check for simple zooming and clipping */
+ if (ctx->Pixel.ZoomX == 1.0F &&
+ (ctx->Pixel.ZoomY == 1.0F || ctx->Pixel.ZoomY == -1.0F)) {
+ if (!_mesa_clip_drawpixels(ctx, &destX, &destY,
+ &drawWidth, &drawHeight, &unpack)) {
+ /* image was completely clipped: no-op, all done */
+ return GL_TRUE;
+ }
+ simpleZoom = GL_TRUE;
+ yStep = (GLint) ctx->Pixel.ZoomY;
+ ASSERT(yStep == 1 || yStep == -1);
+ }
+ else {
+ /* non-simple zooming */
+ simpleZoom = GL_FALSE;
+ yStep = 1;
+ if (unpack.RowLength == 0)
+ unpack.RowLength = width;
+ }
+
+ /*
+ * Ready to draw!
+ */
+
+ if (format == GL_RGBA && type == rbType) {
+ const GLubyte *src
+ = (const GLubyte *) _mesa_image_address2d(&unpack, pixels, width,
+ height, format, type, 0, 0);
+ const GLint srcStride = _mesa_image_row_stride(&unpack, width,
+ format, type);
+ if (simpleZoom) {
+ GLint row;
+ for (row = 0; row < drawHeight; row++) {
+ rb->PutRow(ctx, rb, drawWidth, destX, destY, src, NULL);
+ src += srcStride;
+ destY += yStep;
+ }
+ }
+ else {
+ /* with zooming */
+ GLint row;
+ for (row = 0; row < drawHeight; row++) {
+ span.x = destX;
+ span.y = destY + row;
+ span.end = drawWidth;
+ span.array->ChanType = rbType;
+ _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span, src);
+ src += srcStride;
+ }
+ span.array->ChanType = CHAN_TYPE;
+ }
+ return GL_TRUE;
+ }
+
+ if (format == GL_RGB && type == rbType) {
+ const GLubyte *src
+ = (const GLubyte *) _mesa_image_address2d(&unpack, pixels, width,
+ height, format, type, 0, 0);
+ const GLint srcStride = _mesa_image_row_stride(&unpack, width,
+ format, type);
+ if (simpleZoom) {
+ GLint row;
+ for (row = 0; row < drawHeight; row++) {
+ rb->PutRowRGB(ctx, rb, drawWidth, destX, destY, src, NULL);
+ src += srcStride;
+ destY += yStep;
+ }
+ }
+ else {
+ /* with zooming */
+ GLint row;
+ for (row = 0; row < drawHeight; row++) {
+ span.x = destX;
+ span.y = destY;
+ span.end = drawWidth;
+ span.array->ChanType = rbType;
+ _swrast_write_zoomed_rgb_span(ctx, imgX, imgY, &span, src);
+ src += srcStride;
+ destY++;
+ }
+ span.array->ChanType = CHAN_TYPE;
+ }
+ return GL_TRUE;
+ }
+
+ /* Remaining cases haven't been tested with alignment != 1 */
+ if (userUnpack->Alignment != 1)
+ return GL_FALSE;
+
+ if (format == GL_LUMINANCE && type == CHAN_TYPE && rbType == CHAN_TYPE) {
+ const GLchan *src = (const GLchan *) pixels
+ + (unpack.SkipRows * unpack.RowLength + unpack.SkipPixels);
+ if (simpleZoom) {
+ /* no zooming */
+ GLint row;
+ ASSERT(drawWidth <= MAX_WIDTH);
+ for (row = 0; row < drawHeight; row++) {
+ GLchan rgb[MAX_WIDTH][3];
+ GLint i;
+ for (i = 0;i<drawWidth;i++) {
+ rgb[i][0] = src[i];
+ rgb[i][1] = src[i];
+ rgb[i][2] = src[i];
+ }
+ rb->PutRowRGB(ctx, rb, drawWidth, destX, destY, rgb, NULL);
+ src += unpack.RowLength;
+ destY += yStep;
+ }
+ }
+ else {
+ /* with zooming */
+ GLint row;
+ ASSERT(drawWidth <= MAX_WIDTH);
+ for (row = 0; row < drawHeight; row++) {
+ GLchan rgb[MAX_WIDTH][3];
+ GLint i;
+ for (i = 0;i<drawWidth;i++) {
+ rgb[i][0] = src[i];
+ rgb[i][1] = src[i];
+ rgb[i][2] = src[i];
+ }
+ span.x = destX;
+ span.y = destY;
+ span.end = drawWidth;
+ _swrast_write_zoomed_rgb_span(ctx, imgX, imgY, &span, rgb);
+ src += unpack.RowLength;
+ destY++;
+ }
+ }
+ return GL_TRUE;
+ }
+
+ if (format == GL_LUMINANCE_ALPHA && type == CHAN_TYPE && rbType == CHAN_TYPE) {
+ const GLchan *src = (const GLchan *) pixels
+ + (unpack.SkipRows * unpack.RowLength + unpack.SkipPixels)*2;
+ if (simpleZoom) {
+ GLint row;
+ ASSERT(drawWidth <= MAX_WIDTH);
+ for (row = 0; row < drawHeight; row++) {
+ GLint i;
+ const GLchan *ptr = src;
+ for (i = 0;i<drawWidth;i++) {
+ span.array->rgba[i][0] = *ptr;
+ span.array->rgba[i][1] = *ptr;
+ span.array->rgba[i][2] = *ptr++;
+ span.array->rgba[i][3] = *ptr++;
+ }
+ rb->PutRow(ctx, rb, drawWidth, destX, destY,
+ span.array->rgba, NULL);
+ src += unpack.RowLength*2;
+ destY += yStep;
+ }
+ }
+ else {
+ /* with zooming */
+ GLint row;
+ ASSERT(drawWidth <= MAX_WIDTH);
+ for (row = 0; row < drawHeight; row++) {
+ const GLchan *ptr = src;
+ GLint i;
+ for (i = 0;i<drawWidth;i++) {
+ span.array->rgba[i][0] = *ptr;
+ span.array->rgba[i][1] = *ptr;
+ span.array->rgba[i][2] = *ptr++;
+ span.array->rgba[i][3] = *ptr++;
+ }
+ span.x = destX;
+ span.y = destY;
+ span.end = drawWidth;
+ _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span,
+ span.array->rgba);
+ src += unpack.RowLength*2;
+ destY++;
+ }
+ }
+ return GL_TRUE;
+ }
+
+ if (format == GL_COLOR_INDEX && type == GL_UNSIGNED_BYTE) {
+ const GLubyte *src = (const GLubyte *) pixels
+ + unpack.SkipRows * unpack.RowLength + unpack.SkipPixels;
+ if (rbType == GL_UNSIGNED_BYTE) {
+ /* convert ubyte/CI data to ubyte/RGBA */
+ if (simpleZoom) {
+ GLint row;
+ for (row = 0; row < drawHeight; row++) {
+ ASSERT(drawWidth <= MAX_WIDTH);
+ _mesa_map_ci8_to_rgba8(ctx, drawWidth, src,
+ span.array->rgba8);
+ rb->PutRow(ctx, rb, drawWidth, destX, destY,
+ span.array->rgba8, NULL);
+ src += unpack.RowLength;
+ destY += yStep;
+ }
+ }
+ else {
+ /* ubyte/CI to ubyte/RGBA with zooming */
+ GLint row;
+ for (row = 0; row < drawHeight; row++) {
+ ASSERT(drawWidth <= MAX_WIDTH);
+ _mesa_map_ci8_to_rgba8(ctx, drawWidth, src,
+ span.array->rgba8);
+ span.x = destX;
+ span.y = destY;
+ span.end = drawWidth;
+ _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span,
+ span.array->rgba8);
+ src += unpack.RowLength;
+ destY++;
+ }
+ }
+ return GL_TRUE;
+ }
+ }
+
+ /* can't handle this pixel format and/or data type */
+ return GL_FALSE;
+}
+
+
+
+/*
+ * Draw stencil image.
+ */
+static void
+draw_stencil_pixels( struct gl_context *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels )
+{
+ const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
+ GLint skipPixels;
+
+ /* if width > MAX_WIDTH, have to process image in chunks */
+ skipPixels = 0;
+ while (skipPixels < width) {
+ const GLint spanX = x + skipPixels;
+ const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
+ GLint row;
+ for (row = 0; row < height; row++) {
+ const GLint spanY = y + row;
+ GLstencil values[MAX_WIDTH];
+ GLenum destType = (sizeof(GLstencil) == sizeof(GLubyte))
+ ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
+ const GLvoid *source = _mesa_image_address2d(unpack, pixels,
+ width, height,
+ GL_COLOR_INDEX, type,
+ row, skipPixels);
+ _mesa_unpack_stencil_span(ctx, spanWidth, destType, values,
+ type, source, unpack,
+ ctx->_ImageTransferState);
+ if (zoom) {
+ _swrast_write_zoomed_stencil_span(ctx, x, y, spanWidth,
+ spanX, spanY, values);
+ }
+ else {
+ _swrast_write_stencil_span(ctx, spanWidth, spanX, spanY, values);
+ }
+ }
+ skipPixels += spanWidth;
+ }
+}
+
+
+/*
+ * Draw depth image.
+ */
+static void
+draw_depth_pixels( struct gl_context *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels )
+{
+ const GLboolean scaleOrBias
+ = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
+ const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
+ SWspan span;
+
+ INIT_SPAN(span, GL_BITMAP);
+ span.arrayMask = SPAN_Z;
+ _swrast_span_default_attribs(ctx, &span);
+
+ if (type == GL_UNSIGNED_SHORT
+ && ctx->DrawBuffer->Visual.depthBits == 16
+ && !scaleOrBias
+ && !zoom
+ && width <= MAX_WIDTH
+ && !unpack->SwapBytes) {
+ /* Special case: directly write 16-bit depth values */
+ GLint row;
+ for (row = 0; row < height; row++) {
+ const GLushort *zSrc = (const GLushort *)
+ _mesa_image_address2d(unpack, pixels, width, height,
+ GL_DEPTH_COMPONENT, type, row, 0);
+ GLint i;
+ for (i = 0; i < width; i++)
+ span.array->z[i] = zSrc[i];
+ span.x = x;
+ span.y = y + row;
+ span.end = width;
+ _swrast_write_rgba_span(ctx, &span);
+ }
+ }
+ else if (type == GL_UNSIGNED_INT
+ && !scaleOrBias
+ && !zoom
+ && width <= MAX_WIDTH
+ && !unpack->SwapBytes) {
+ /* Special case: shift 32-bit values down to Visual.depthBits */
+ const GLint shift = 32 - ctx->DrawBuffer->Visual.depthBits;
+ GLint row;
+ for (row = 0; row < height; row++) {
+ const GLuint *zSrc = (const GLuint *)
+ _mesa_image_address2d(unpack, pixels, width, height,
+ GL_DEPTH_COMPONENT, type, row, 0);
+ if (shift == 0) {
+ memcpy(span.array->z, zSrc, width * sizeof(GLuint));
+ }
+ else {
+ GLint col;
+ for (col = 0; col < width; col++)
+ span.array->z[col] = zSrc[col] >> shift;
+ }
+ span.x = x;
+ span.y = y + row;
+ span.end = width;
+ _swrast_write_rgba_span(ctx, &span);
+ }
+ }
+ else {
+ /* General case */
+ const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
+ GLint skipPixels = 0;
+
+ /* in case width > MAX_WIDTH do the copy in chunks */
+ while (skipPixels < width) {
+ const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
+ GLint row;
+ ASSERT(span.end <= MAX_WIDTH);
+ for (row = 0; row < height; row++) {
+ const GLvoid *zSrc = _mesa_image_address2d(unpack,
+ pixels, width, height,
+ GL_DEPTH_COMPONENT, type,
+ row, skipPixels);
+
+ /* Set these for each row since the _swrast_write_* function may
+ * change them while clipping.
+ */
+ span.x = x + skipPixels;
+ span.y = y + row;
+ span.end = spanWidth;
+
+ _mesa_unpack_depth_span(ctx, spanWidth,
+ GL_UNSIGNED_INT, span.array->z, depthMax,
+ type, zSrc, unpack);
+ if (zoom) {
+ _swrast_write_zoomed_depth_span(ctx, x, y, &span);
+ }
+ else {
+ _swrast_write_rgba_span(ctx, &span);
+ }
+ }
+ skipPixels += spanWidth;
+ }
+ }
+}
+
+
+
+/**
+ * Draw RGBA image.
+ */
+static void
+draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels )
+{
+ const GLint imgX = x, imgY = y;
+ const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
+ GLfloat *convImage = NULL;
+ GLbitfield transferOps = ctx->_ImageTransferState;
+ SWspan span;
+
+ /* Try an optimized glDrawPixels first */
+ if (fast_draw_rgba_pixels(ctx, x, y, width, height, format, type,
+ unpack, pixels)) {
+ return;
+ }
+
+ INIT_SPAN(span, GL_BITMAP);
+ _swrast_span_default_attribs(ctx, &span);
+ span.arrayMask = SPAN_RGBA;
+ span.arrayAttribs = FRAG_BIT_COL0; /* we're fill in COL0 attrib values */
+
+ if (ctx->DrawBuffer->_NumColorDrawBuffers > 0 &&
+ ctx->DrawBuffer->_ColorDrawBuffers[0]->DataType != GL_FLOAT &&
+ ctx->Color.ClampFragmentColor != GL_FALSE) {
+ /* need to clamp colors before applying fragment ops */
+ transferOps |= IMAGE_CLAMP_BIT;
+ }
+
+ /*
+ * General solution
+ */
+ {
+ const GLbitfield interpMask = span.interpMask;
+ const GLbitfield arrayMask = span.arrayMask;
+ const GLint srcStride
+ = _mesa_image_row_stride(unpack, width, format, type);
+ GLint skipPixels = 0;
+ /* use span array for temp color storage */
+ GLfloat *rgba = (GLfloat *) span.array->attribs[FRAG_ATTRIB_COL0];
+
+ /* if the span is wider than MAX_WIDTH we have to do it in chunks */
+ while (skipPixels < width) {
+ const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
+ const GLubyte *source
+ = (const GLubyte *) _mesa_image_address2d(unpack, pixels,
+ width, height, format,
+ type, 0, skipPixels);
+ GLint row;
+
+ for (row = 0; row < height; row++) {
+ /* get image row as float/RGBA */
+ _mesa_unpack_color_span_float(ctx, spanWidth, GL_RGBA, rgba,
+ format, type, source, unpack,
+ transferOps);
+ /* Set these for each row since the _swrast_write_* functions
+ * may change them while clipping/rendering.
+ */
+ span.array->ChanType = GL_FLOAT;
+ span.x = x + skipPixels;
+ span.y = y + row;
+ span.end = spanWidth;
+ span.arrayMask = arrayMask;
+ span.interpMask = interpMask;
+ if (zoom) {
+ _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span, rgba);
+ }
+ else {
+ _swrast_write_rgba_span(ctx, &span);
+ }
+
+ source += srcStride;
+ } /* for row */
+
+ skipPixels += spanWidth;
+ } /* while skipPixels < width */
+
+ /* XXX this is ugly/temporary, to undo above change */
+ span.array->ChanType = CHAN_TYPE;
+ }
+
+ if (convImage) {
+ free(convImage);
+ }
+}
+
+
+/**
+ * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
+ * The only per-pixel operations that apply are depth scale/bias,
+ * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
+ * and pixel zoom.
+ * Also, only the depth buffer and stencil buffers are touched, not the
+ * color buffer(s).
+ */
+static void
+draw_depth_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
+ GLsizei width, GLsizei height, GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels)
+{
+ const GLint imgX = x, imgY = y;
+ const GLboolean scaleOrBias
+ = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
+ const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
+ const GLuint stencilMask = ctx->Stencil.WriteMask[0];
+ const GLuint stencilType = (STENCIL_BITS == 8) ?
+ GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
+ const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
+ struct gl_renderbuffer *depthRb, *stencilRb;
+ struct gl_pixelstore_attrib clippedUnpack = *unpack;
+
+ if (!zoom) {
+ if (!_mesa_clip_drawpixels(ctx, &x, &y, &width, &height,
+ &clippedUnpack)) {
+ /* totally clipped */
+ return;
+ }
+ }
+
+ depthRb = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+ stencilRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
+ ASSERT(depthRb);
+ ASSERT(stencilRb);
+
+ if (depthRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
+ stencilRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
+ depthRb == stencilRb &&
+ !scaleOrBias &&
+ !zoom &&
+ ctx->Depth.Mask &&
+ (stencilMask & 0xff) == 0xff) {
+ /* This is the ideal case.
+ * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
+ * Plus, no pixel transfer ops, zooming, or masking needed.
+ */
+ GLint i;
+ for (i = 0; i < height; i++) {
+ const GLuint *src = (const GLuint *)
+ _mesa_image_address2d(&clippedUnpack, pixels, width, height,
+ GL_DEPTH_STENCIL_EXT, type, i, 0);
+ depthRb->PutRow(ctx, depthRb, width, x, y + i, src, NULL);
+ }
+ }
+ else {
+ /* sub-optimal cases:
+ * Separate depth/stencil buffers, or pixel transfer ops required.
+ */
+ /* XXX need to handle very wide images (skippixels) */
+ GLint i;
+
+ depthRb = ctx->DrawBuffer->_DepthBuffer;
+ stencilRb = ctx->DrawBuffer->_StencilBuffer;
+
+ for (i = 0; i < height; i++) {
+ const GLuint *depthStencilSrc = (const GLuint *)
+ _mesa_image_address2d(&clippedUnpack, pixels, width, height,
+ GL_DEPTH_STENCIL_EXT, type, i, 0);
+
+ if (ctx->Depth.Mask) {
+ if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 24) {
+ /* fast path 24-bit zbuffer */
+ GLuint zValues[MAX_WIDTH];
+ GLint j;
+ ASSERT(depthRb->DataType == GL_UNSIGNED_INT);
+ for (j = 0; j < width; j++) {
+ zValues[j] = depthStencilSrc[j] >> 8;
+ }
+ if (zoom)
+ _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,
+ x, y + i, zValues);
+ else
+ depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
+ }
+ else if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 16) {
+ /* fast path 16-bit zbuffer */
+ GLushort zValues[MAX_WIDTH];
+ GLint j;
+ ASSERT(depthRb->DataType == GL_UNSIGNED_SHORT);
+ for (j = 0; j < width; j++) {
+ zValues[j] = depthStencilSrc[j] >> 16;
+ }
+ if (zoom)
+ _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,
+ x, y + i, zValues);
+ else
+ depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
+ }
+ else {
+ /* general case */
+ GLuint zValues[MAX_WIDTH]; /* 16 or 32-bit Z value storage */
+ _mesa_unpack_depth_span(ctx, width,
+ depthRb->DataType, zValues, depthMax,
+ type, depthStencilSrc, &clippedUnpack);
+ if (zoom) {
+ _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x,
+ y + i, zValues);
+ }
+ else {
+ depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
+ }
+ }
+ }
+
+ if (stencilMask != 0x0) {
+ GLstencil stencilValues[MAX_WIDTH];
+ /* get stencil values, with shift/offset/mapping */
+ _mesa_unpack_stencil_span(ctx, width, stencilType, stencilValues,
+ type, depthStencilSrc, &clippedUnpack,
+ ctx->_ImageTransferState);
+ if (zoom)
+ _swrast_write_zoomed_stencil_span(ctx, imgX, imgY, width,
+ x, y + i, stencilValues);
+ else
+ _swrast_write_stencil_span(ctx, width, x, y + i, stencilValues);
+ }
+ }
+ }
+}
+
+
+/**
+ * Execute software-based glDrawPixels.
+ * By time we get here, all error checking will have been done.
+ */
+void
+_swrast_DrawPixels( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ GLboolean save_vp_override = ctx->VertexProgram._Overriden;
+
+ if (!_mesa_check_conditional_render(ctx))
+ return; /* don't draw */
+
+ /* We are creating fragments directly, without going through vertex
+ * programs.
+ *
+ * This override flag tells the fragment processing code that its input
+ * comes from a non-standard source, and it may therefore not rely on
+ * optimizations that assume e.g. constant color if there is no color
+ * vertex array.
+ */
+ _mesa_set_vp_override(ctx, GL_TRUE);
+
+ swrast_render_start(ctx);
+
+ if (ctx->NewState)
+ _mesa_update_state(ctx);
+
+ if (swrast->NewState)
+ _swrast_validate_derived( ctx );
+
+ pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
+ if (!pixels) {
+ swrast_render_finish(ctx);
+ _mesa_set_vp_override(ctx, save_vp_override);
+ return;
+ }
+
+ /*
+ * By time we get here, all error checking should have been done.
+ */
+ switch (format) {
+ case GL_STENCIL_INDEX:
+ draw_stencil_pixels( ctx, x, y, width, height, type, unpack, pixels );
+ break;
+ case GL_DEPTH_COMPONENT:
+ draw_depth_pixels( ctx, x, y, width, height, type, unpack, pixels );
+ break;
+ case GL_DEPTH_STENCIL_EXT:
+ draw_depth_stencil_pixels(ctx, x, y, width, height, type, unpack, pixels);
+ break;
+ default:
+ /* all other formats should be color formats */
+ draw_rgba_pixels(ctx, x, y, width, height, format, type, unpack, pixels);
+ }
+
+ swrast_render_finish(ctx);
+ _mesa_set_vp_override(ctx, save_vp_override);
+
+ _mesa_unmap_pbo_source(ctx, unpack);
+}
diff --git a/mesalib/src/mesa/swrast/s_readpix.c b/mesalib/src/mesa/swrast/s_readpix.c
index 5c8d7e9c5..23da10dab 100644
--- a/mesalib/src/mesa/swrast/s_readpix.c
+++ b/mesalib/src/mesa/swrast/s_readpix.c
@@ -1,508 +1,508 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.0.3
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "main/glheader.h"
-#include "main/colormac.h"
-#include "main/feedback.h"
-#include "main/formats.h"
-#include "main/image.h"
-#include "main/imports.h"
-#include "main/macros.h"
-#include "main/pack.h"
-#include "main/pbo.h"
-#include "main/state.h"
-
-#include "s_context.h"
-#include "s_depth.h"
-#include "s_span.h"
-#include "s_stencil.h"
-
-
-/**
- * Read pixels for format=GL_DEPTH_COMPONENT.
- */
-static void
-read_depth_pixels( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum type, GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *rb = fb->_DepthBuffer;
- const GLboolean biasOrScale
- = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
-
- if (!rb)
- return;
-
- /* clipping should have been done already */
- ASSERT(x >= 0);
- ASSERT(y >= 0);
- ASSERT(x + width <= (GLint) rb->Width);
- ASSERT(y + height <= (GLint) rb->Height);
- /* width should never be > MAX_WIDTH since we did clipping earlier */
- ASSERT(width <= MAX_WIDTH);
-
- if (type == GL_UNSIGNED_SHORT && fb->Visual.depthBits == 16
- && !biasOrScale && !packing->SwapBytes) {
- /* Special case: directly read 16-bit unsigned depth values. */
- GLint j;
- ASSERT(rb->Format == MESA_FORMAT_Z16);
- ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
- for (j = 0; j < height; j++, y++) {
- void *dest =_mesa_image_address2d(packing, pixels, width, height,
- GL_DEPTH_COMPONENT, type, j, 0);
- rb->GetRow(ctx, rb, width, x, y, dest);
- }
- }
- else if (type == GL_UNSIGNED_INT && fb->Visual.depthBits == 24
- && !biasOrScale && !packing->SwapBytes) {
- /* Special case: directly read 24-bit unsigned depth values. */
- GLint j;
- ASSERT(rb->Format == MESA_FORMAT_X8_Z24 ||
- rb->Format == MESA_FORMAT_S8_Z24 ||
- rb->Format == MESA_FORMAT_Z24_X8 ||
- rb->Format == MESA_FORMAT_Z24_S8);
- ASSERT(rb->DataType == GL_UNSIGNED_INT ||
- rb->DataType == GL_UNSIGNED_INT_24_8);
- for (j = 0; j < height; j++, y++) {
- GLuint *dest = (GLuint *)
- _mesa_image_address2d(packing, pixels, width, height,
- GL_DEPTH_COMPONENT, type, j, 0);
- GLint k;
- rb->GetRow(ctx, rb, width, x, y, dest);
- /* convert range from 24-bit to 32-bit */
- if (rb->Format == MESA_FORMAT_X8_Z24 ||
- rb->Format == MESA_FORMAT_S8_Z24) {
- for (k = 0; k < width; k++) {
- /* Note: put MSByte of 24-bit value into LSByte */
- dest[k] = (dest[k] << 8) | ((dest[k] >> 16) & 0xff);
- }
- }
- else {
- for (k = 0; k < width; k++) {
- /* Note: fill in LSByte by replication */
- dest[k] = dest[k] | ((dest[k] >> 8) & 0xff);
- }
- }
- }
- }
- else if (type == GL_UNSIGNED_INT && fb->Visual.depthBits == 32
- && !biasOrScale && !packing->SwapBytes) {
- /* Special case: directly read 32-bit unsigned depth values. */
- GLint j;
- ASSERT(rb->Format == MESA_FORMAT_Z32);
- ASSERT(rb->DataType == GL_UNSIGNED_INT);
- for (j = 0; j < height; j++, y++) {
- void *dest = _mesa_image_address2d(packing, pixels, width, height,
- GL_DEPTH_COMPONENT, type, j, 0);
- rb->GetRow(ctx, rb, width, x, y, dest);
- }
- }
- else {
- /* General case (slower) */
- GLint j;
- for (j = 0; j < height; j++, y++) {
- GLfloat depthValues[MAX_WIDTH];
- GLvoid *dest = _mesa_image_address2d(packing, pixels, width, height,
- GL_DEPTH_COMPONENT, type, j, 0);
- _swrast_read_depth_span_float(ctx, rb, width, x, y, depthValues);
- _mesa_pack_depth_span(ctx, width, dest, type, depthValues, packing);
- }
- }
-}
-
-
-/**
- * Read pixels for format=GL_STENCIL_INDEX.
- */
-static void
-read_stencil_pixels( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum type, GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *rb = fb->_StencilBuffer;
- GLint j;
-
- if (!rb)
- return;
-
- /* width should never be > MAX_WIDTH since we did clipping earlier */
- ASSERT(width <= MAX_WIDTH);
-
- /* process image row by row */
- for (j=0;j<height;j++,y++) {
- GLvoid *dest;
- GLstencil stencil[MAX_WIDTH];
-
- _swrast_read_stencil_span(ctx, rb, width, x, y, stencil);
-
- dest = _mesa_image_address2d(packing, pixels, width, height,
- GL_STENCIL_INDEX, type, j, 0);
-
- _mesa_pack_stencil_span(ctx, width, type, dest, stencil, packing);
- }
-}
-
-
-
-/**
- * Optimized glReadPixels for particular pixel formats when pixel
- * scaling, biasing, mapping, etc. are disabled.
- * \return GL_TRUE if success, GL_FALSE if unable to do the readpixels
- */
-static GLboolean
-fast_read_rgba_pixels( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing,
- GLbitfield transferOps)
-{
- struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
-
- if (!rb)
- return GL_FALSE;
-
- ASSERT(rb->_BaseFormat == GL_RGBA || rb->_BaseFormat == GL_RGB ||
- rb->_BaseFormat == GL_ALPHA);
-
- /* clipping should have already been done */
- ASSERT(x + width <= (GLint) rb->Width);
- ASSERT(y + height <= (GLint) rb->Height);
-
- /* check for things we can't handle here */
- if (transferOps ||
- packing->SwapBytes ||
- packing->LsbFirst) {
- return GL_FALSE;
- }
-
- if (format == GL_RGBA && rb->DataType == type) {
- const GLint dstStride = _mesa_image_row_stride(packing, width,
- format, type);
- GLubyte *dest
- = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
- format, type, 0, 0);
- GLint row;
- ASSERT(rb->GetRow);
- for (row = 0; row < height; row++) {
- rb->GetRow(ctx, rb, width, x, y + row, dest);
- dest += dstStride;
- }
- return GL_TRUE;
- }
-
- if (format == GL_RGB &&
- rb->DataType == GL_UNSIGNED_BYTE &&
- type == GL_UNSIGNED_BYTE) {
- const GLint dstStride = _mesa_image_row_stride(packing, width,
- format, type);
- GLubyte *dest
- = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
- format, type, 0, 0);
- GLint row;
- ASSERT(rb->GetRow);
- for (row = 0; row < height; row++) {
- GLubyte tempRow[MAX_WIDTH][4];
- GLint col;
- rb->GetRow(ctx, rb, width, x, y + row, tempRow);
- /* convert RGBA to RGB */
- for (col = 0; col < width; col++) {
- dest[col * 3 + 0] = tempRow[col][0];
- dest[col * 3 + 1] = tempRow[col][1];
- dest[col * 3 + 2] = tempRow[col][2];
- }
- dest += dstStride;
- }
- return GL_TRUE;
- }
-
- /* not handled */
- return GL_FALSE;
-}
-
-
-/**
- * When we're using a low-precision color buffer (like 16-bit 5/6/5)
- * we have to adjust our color values a bit to pass conformance.
- * The problem is when a 5 or 6-bit color value is converted to an 8-bit
- * value and then a floating point value, the floating point values don't
- * increment uniformly as the 5 or 6-bit value is incremented.
- *
- * This function adjusts floating point values to compensate.
- */
-static void
-adjust_colors(const struct gl_framebuffer *fb, GLuint n, GLfloat rgba[][4])
-{
- const GLuint rShift = 8 - fb->Visual.redBits;
- const GLuint gShift = 8 - fb->Visual.greenBits;
- const GLuint bShift = 8 - fb->Visual.blueBits;
- GLfloat rScale = 1.0F / (GLfloat) ((1 << fb->Visual.redBits ) - 1);
- GLfloat gScale = 1.0F / (GLfloat) ((1 << fb->Visual.greenBits) - 1);
- GLfloat bScale = 1.0F / (GLfloat) ((1 << fb->Visual.blueBits ) - 1);
- GLuint i;
-
- if (fb->Visual.redBits == 0)
- rScale = 0;
- if (fb->Visual.greenBits == 0)
- gScale = 0;
- if (fb->Visual.blueBits == 0)
- bScale = 0;
-
- for (i = 0; i < n; i++) {
- GLint r, g, b;
- /* convert float back to ubyte */
- CLAMPED_FLOAT_TO_UBYTE(r, rgba[i][RCOMP]);
- CLAMPED_FLOAT_TO_UBYTE(g, rgba[i][GCOMP]);
- CLAMPED_FLOAT_TO_UBYTE(b, rgba[i][BCOMP]);
- /* using only the N most significant bits of the ubyte value, convert to
- * float in [0,1].
- */
- rgba[i][RCOMP] = (GLfloat) (r >> rShift) * rScale;
- rgba[i][GCOMP] = (GLfloat) (g >> gShift) * gScale;
- rgba[i][BCOMP] = (GLfloat) (b >> bShift) * bScale;
- }
-}
-
-
-
-/*
- * Read R, G, B, A, RGB, L, or LA pixels.
- */
-static void
-read_rgba_pixels( struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type, GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- GLbitfield transferOps = ctx->_ImageTransferState;
- struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct gl_renderbuffer *rb = fb->_ColorReadBuffer;
-
- if (!rb)
- return;
-
- if (type == GL_FLOAT && ((ctx->Color.ClampReadColor == GL_TRUE) ||
- (ctx->Color.ClampReadColor == GL_FIXED_ONLY_ARB &&
- rb->DataType != GL_FLOAT)))
- transferOps |= IMAGE_CLAMP_BIT;
-
- /* Try optimized path first */
- if (fast_read_rgba_pixels(ctx, x, y, width, height,
- format, type, pixels, packing, transferOps)) {
- return; /* done! */
- }
-
- /* width should never be > MAX_WIDTH since we did clipping earlier */
- ASSERT(width <= MAX_WIDTH);
-
- do {
- const GLint dstStride
- = _mesa_image_row_stride(packing, width, format, type);
- GLfloat (*rgba)[4] = swrast->SpanArrays->attribs[FRAG_ATTRIB_COL0];
- GLint row;
- GLubyte *dst
- = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
- format, type, 0, 0);
-
- for (row = 0; row < height; row++, y++) {
-
- /* Get float rgba pixels */
- _swrast_read_rgba_span(ctx, rb, width, x, y, GL_FLOAT, rgba);
-
- /* apply fudge factor for shallow color buffers */
- if (fb->Visual.redBits < 8 ||
- fb->Visual.greenBits < 8 ||
- fb->Visual.blueBits < 8) {
- adjust_colors(fb, width, rgba);
- }
-
- /* pack the row of RGBA pixels into user's buffer */
- _mesa_pack_rgba_span_float(ctx, width, rgba, format, type, dst,
- packing, transferOps);
-
- dst += dstStride;
- }
- } while (0);
-}
-
-
-/**
- * Read combined depth/stencil values.
- * We'll have already done error checking to be sure the expected
- * depth and stencil buffers really exist.
- */
-static void
-read_depth_stencil_pixels(struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum type, GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
- const GLboolean scaleOrBias
- = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
- const GLboolean stencilTransfer = ctx->Pixel.IndexShift
- || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag;
- struct gl_renderbuffer *depthRb, *stencilRb;
-
- depthRb = ctx->ReadBuffer->_DepthBuffer;
- stencilRb = ctx->ReadBuffer->_StencilBuffer;
-
- if (!depthRb || !stencilRb)
- return;
-
- depthRb = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
- stencilRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
-
- if (depthRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
- stencilRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
- depthRb == stencilRb &&
- !scaleOrBias &&
- !stencilTransfer) {
- /* This is the ideal case.
- * Reading GL_DEPTH_STENCIL pixels from combined depth/stencil buffer.
- * Plus, no pixel transfer ops to worry about!
- */
- GLint i;
- GLint dstStride = _mesa_image_row_stride(packing, width,
- GL_DEPTH_STENCIL_EXT, type);
- GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, pixels,
- width, height,
- GL_DEPTH_STENCIL_EXT,
- type, 0, 0);
- for (i = 0; i < height; i++) {
- depthRb->GetRow(ctx, depthRb, width, x, y + i, dst);
- dst += dstStride;
- }
- }
- else {
- /* Reading GL_DEPTH_STENCIL pixels from separate depth/stencil buffers,
- * or we need pixel transfer.
- */
- GLint i;
- depthRb = ctx->ReadBuffer->_DepthBuffer;
- stencilRb = ctx->ReadBuffer->_StencilBuffer;
-
- for (i = 0; i < height; i++) {
- GLstencil stencilVals[MAX_WIDTH];
-
- GLuint *depthStencilDst = (GLuint *)
- _mesa_image_address2d(packing, pixels, width, height,
- GL_DEPTH_STENCIL_EXT, type, i, 0);
-
- _swrast_read_stencil_span(ctx, stencilRb, width,
- x, y + i, stencilVals);
-
- if (!scaleOrBias && !stencilTransfer
- && ctx->ReadBuffer->Visual.depthBits == 24) {
- /* ideal case */
- GLuint zVals[MAX_WIDTH]; /* 24-bit values! */
- GLint j;
- ASSERT(depthRb->DataType == GL_UNSIGNED_INT);
- /* note, we've already been clipped */
- depthRb->GetRow(ctx, depthRb, width, x, y + i, zVals);
- for (j = 0; j < width; j++) {
- depthStencilDst[j] = (zVals[j] << 8) | (stencilVals[j] & 0xff);
- }
- }
- else {
- /* general case */
- GLfloat depthVals[MAX_WIDTH];
- _swrast_read_depth_span_float(ctx, depthRb, width, x, y + i,
- depthVals);
- _mesa_pack_depth_stencil_span(ctx, width, depthStencilDst,
- depthVals, stencilVals, packing);
- }
- }
- }
-}
-
-
-
-/**
- * Software fallback routine for ctx->Driver.ReadPixels().
- * By time we get here, all error checking will have been done.
- */
-void
-_swrast_ReadPixels( struct gl_context *ctx,
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- const struct gl_pixelstore_attrib *packing,
- GLvoid *pixels )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- struct gl_pixelstore_attrib clippedPacking = *packing;
-
- if (ctx->NewState)
- _mesa_update_state(ctx);
-
- /* Need to do swrast_render_start() before clipping or anything else
- * since this is where a driver may grab the hw lock and get an updated
- * window size.
- */
- swrast_render_start(ctx);
-
- if (swrast->NewState)
- _swrast_validate_derived( ctx );
-
- /* Do all needed clipping here, so that we can forget about it later */
- if (_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
-
- pixels = _mesa_map_pbo_dest(ctx, &clippedPacking, pixels);
-
- if (pixels) {
- switch (format) {
- case GL_STENCIL_INDEX:
- read_stencil_pixels(ctx, x, y, width, height, type, pixels,
- &clippedPacking);
- break;
- case GL_DEPTH_COMPONENT:
- read_depth_pixels(ctx, x, y, width, height, type, pixels,
- &clippedPacking);
- break;
- case GL_DEPTH_STENCIL_EXT:
- read_depth_stencil_pixels(ctx, x, y, width, height, type, pixels,
- &clippedPacking);
- break;
- default:
- /* all other formats should be color formats */
- read_rgba_pixels(ctx, x, y, width, height, format, type, pixels,
- &clippedPacking);
- }
-
- _mesa_unmap_pbo_dest(ctx, &clippedPacking);
- }
- }
-
- swrast_render_finish(ctx);
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.0.3
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "main/glheader.h"
+#include "main/colormac.h"
+#include "main/feedback.h"
+#include "main/formats.h"
+#include "main/image.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/pack.h"
+#include "main/pbo.h"
+#include "main/state.h"
+
+#include "s_context.h"
+#include "s_depth.h"
+#include "s_span.h"
+#include "s_stencil.h"
+
+
+/**
+ * Read pixels for format=GL_DEPTH_COMPONENT.
+ */
+static void
+read_depth_pixels( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type, GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing )
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *rb = fb->_DepthBuffer;
+ const GLboolean biasOrScale
+ = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
+
+ if (!rb)
+ return;
+
+ /* clipping should have been done already */
+ ASSERT(x >= 0);
+ ASSERT(y >= 0);
+ ASSERT(x + width <= (GLint) rb->Width);
+ ASSERT(y + height <= (GLint) rb->Height);
+ /* width should never be > MAX_WIDTH since we did clipping earlier */
+ ASSERT(width <= MAX_WIDTH);
+
+ if (type == GL_UNSIGNED_SHORT && fb->Visual.depthBits == 16
+ && !biasOrScale && !packing->SwapBytes) {
+ /* Special case: directly read 16-bit unsigned depth values. */
+ GLint j;
+ ASSERT(rb->Format == MESA_FORMAT_Z16);
+ ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
+ for (j = 0; j < height; j++, y++) {
+ void *dest =_mesa_image_address2d(packing, pixels, width, height,
+ GL_DEPTH_COMPONENT, type, j, 0);
+ rb->GetRow(ctx, rb, width, x, y, dest);
+ }
+ }
+ else if (type == GL_UNSIGNED_INT && fb->Visual.depthBits == 24
+ && !biasOrScale && !packing->SwapBytes) {
+ /* Special case: directly read 24-bit unsigned depth values. */
+ GLint j;
+ ASSERT(rb->Format == MESA_FORMAT_X8_Z24 ||
+ rb->Format == MESA_FORMAT_S8_Z24 ||
+ rb->Format == MESA_FORMAT_Z24_X8 ||
+ rb->Format == MESA_FORMAT_Z24_S8);
+ ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+ rb->DataType == GL_UNSIGNED_INT_24_8);
+ for (j = 0; j < height; j++, y++) {
+ GLuint *dest = (GLuint *)
+ _mesa_image_address2d(packing, pixels, width, height,
+ GL_DEPTH_COMPONENT, type, j, 0);
+ GLint k;
+ rb->GetRow(ctx, rb, width, x, y, dest);
+ /* convert range from 24-bit to 32-bit */
+ if (rb->Format == MESA_FORMAT_X8_Z24 ||
+ rb->Format == MESA_FORMAT_S8_Z24) {
+ for (k = 0; k < width; k++) {
+ /* Note: put MSByte of 24-bit value into LSByte */
+ dest[k] = (dest[k] << 8) | ((dest[k] >> 16) & 0xff);
+ }
+ }
+ else {
+ for (k = 0; k < width; k++) {
+ /* Note: fill in LSByte by replication */
+ dest[k] = dest[k] | ((dest[k] >> 8) & 0xff);
+ }
+ }
+ }
+ }
+ else if (type == GL_UNSIGNED_INT && fb->Visual.depthBits == 32
+ && !biasOrScale && !packing->SwapBytes) {
+ /* Special case: directly read 32-bit unsigned depth values. */
+ GLint j;
+ ASSERT(rb->Format == MESA_FORMAT_Z32);
+ ASSERT(rb->DataType == GL_UNSIGNED_INT);
+ for (j = 0; j < height; j++, y++) {
+ void *dest = _mesa_image_address2d(packing, pixels, width, height,
+ GL_DEPTH_COMPONENT, type, j, 0);
+ rb->GetRow(ctx, rb, width, x, y, dest);
+ }
+ }
+ else {
+ /* General case (slower) */
+ GLint j;
+ for (j = 0; j < height; j++, y++) {
+ GLfloat depthValues[MAX_WIDTH];
+ GLvoid *dest = _mesa_image_address2d(packing, pixels, width, height,
+ GL_DEPTH_COMPONENT, type, j, 0);
+ _swrast_read_depth_span_float(ctx, rb, width, x, y, depthValues);
+ _mesa_pack_depth_span(ctx, width, dest, type, depthValues, packing);
+ }
+ }
+}
+
+
+/**
+ * Read pixels for format=GL_STENCIL_INDEX.
+ */
+static void
+read_stencil_pixels( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type, GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing )
+{
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *rb = fb->_StencilBuffer;
+ GLint j;
+
+ if (!rb)
+ return;
+
+ /* width should never be > MAX_WIDTH since we did clipping earlier */
+ ASSERT(width <= MAX_WIDTH);
+
+ /* process image row by row */
+ for (j=0;j<height;j++,y++) {
+ GLvoid *dest;
+ GLstencil stencil[MAX_WIDTH];
+
+ _swrast_read_stencil_span(ctx, rb, width, x, y, stencil);
+
+ dest = _mesa_image_address2d(packing, pixels, width, height,
+ GL_STENCIL_INDEX, type, j, 0);
+
+ _mesa_pack_stencil_span(ctx, width, type, dest, stencil, packing);
+ }
+}
+
+
+
+/**
+ * Optimized glReadPixels for particular pixel formats when pixel
+ * scaling, biasing, mapping, etc. are disabled.
+ * \return GL_TRUE if success, GL_FALSE if unable to do the readpixels
+ */
+static GLboolean
+fast_read_rgba_pixels( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ GLbitfield transferOps)
+{
+ struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
+
+ if (!rb)
+ return GL_FALSE;
+
+ ASSERT(rb->_BaseFormat == GL_RGBA || rb->_BaseFormat == GL_RGB ||
+ rb->_BaseFormat == GL_ALPHA);
+
+ /* clipping should have already been done */
+ ASSERT(x + width <= (GLint) rb->Width);
+ ASSERT(y + height <= (GLint) rb->Height);
+
+ /* check for things we can't handle here */
+ if (transferOps ||
+ packing->SwapBytes ||
+ packing->LsbFirst) {
+ return GL_FALSE;
+ }
+
+ if (format == GL_RGBA && rb->DataType == type) {
+ const GLint dstStride = _mesa_image_row_stride(packing, width,
+ format, type);
+ GLubyte *dest
+ = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
+ format, type, 0, 0);
+ GLint row;
+ ASSERT(rb->GetRow);
+ for (row = 0; row < height; row++) {
+ rb->GetRow(ctx, rb, width, x, y + row, dest);
+ dest += dstStride;
+ }
+ return GL_TRUE;
+ }
+
+ if (format == GL_RGB &&
+ rb->DataType == GL_UNSIGNED_BYTE &&
+ type == GL_UNSIGNED_BYTE) {
+ const GLint dstStride = _mesa_image_row_stride(packing, width,
+ format, type);
+ GLubyte *dest
+ = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
+ format, type, 0, 0);
+ GLint row;
+ ASSERT(rb->GetRow);
+ for (row = 0; row < height; row++) {
+ GLubyte tempRow[MAX_WIDTH][4];
+ GLint col;
+ rb->GetRow(ctx, rb, width, x, y + row, tempRow);
+ /* convert RGBA to RGB */
+ for (col = 0; col < width; col++) {
+ dest[col * 3 + 0] = tempRow[col][0];
+ dest[col * 3 + 1] = tempRow[col][1];
+ dest[col * 3 + 2] = tempRow[col][2];
+ }
+ dest += dstStride;
+ }
+ return GL_TRUE;
+ }
+
+ /* not handled */
+ return GL_FALSE;
+}
+
+
+/**
+ * When we're using a low-precision color buffer (like 16-bit 5/6/5)
+ * we have to adjust our color values a bit to pass conformance.
+ * The problem is when a 5 or 6-bit color value is converted to an 8-bit
+ * value and then a floating point value, the floating point values don't
+ * increment uniformly as the 5 or 6-bit value is incremented.
+ *
+ * This function adjusts floating point values to compensate.
+ */
+static void
+adjust_colors(const struct gl_framebuffer *fb, GLuint n, GLfloat rgba[][4])
+{
+ const GLuint rShift = 8 - fb->Visual.redBits;
+ const GLuint gShift = 8 - fb->Visual.greenBits;
+ const GLuint bShift = 8 - fb->Visual.blueBits;
+ GLfloat rScale = 1.0F / (GLfloat) ((1 << fb->Visual.redBits ) - 1);
+ GLfloat gScale = 1.0F / (GLfloat) ((1 << fb->Visual.greenBits) - 1);
+ GLfloat bScale = 1.0F / (GLfloat) ((1 << fb->Visual.blueBits ) - 1);
+ GLuint i;
+
+ if (fb->Visual.redBits == 0)
+ rScale = 0;
+ if (fb->Visual.greenBits == 0)
+ gScale = 0;
+ if (fb->Visual.blueBits == 0)
+ bScale = 0;
+
+ for (i = 0; i < n; i++) {
+ GLint r, g, b;
+ /* convert float back to ubyte */
+ CLAMPED_FLOAT_TO_UBYTE(r, rgba[i][RCOMP]);
+ CLAMPED_FLOAT_TO_UBYTE(g, rgba[i][GCOMP]);
+ CLAMPED_FLOAT_TO_UBYTE(b, rgba[i][BCOMP]);
+ /* using only the N most significant bits of the ubyte value, convert to
+ * float in [0,1].
+ */
+ rgba[i][RCOMP] = (GLfloat) (r >> rShift) * rScale;
+ rgba[i][GCOMP] = (GLfloat) (g >> gShift) * gScale;
+ rgba[i][BCOMP] = (GLfloat) (b >> bShift) * bScale;
+ }
+}
+
+
+
+/*
+ * Read R, G, B, A, RGB, L, or LA pixels.
+ */
+static void
+read_rgba_pixels( struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type, GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ GLbitfield transferOps = ctx->_ImageTransferState;
+ struct gl_framebuffer *fb = ctx->ReadBuffer;
+ struct gl_renderbuffer *rb = fb->_ColorReadBuffer;
+
+ if (!rb)
+ return;
+
+ if (type == GL_FLOAT && ((ctx->Color.ClampReadColor == GL_TRUE) ||
+ (ctx->Color.ClampReadColor == GL_FIXED_ONLY_ARB &&
+ rb->DataType != GL_FLOAT)))
+ transferOps |= IMAGE_CLAMP_BIT;
+
+ /* Try optimized path first */
+ if (fast_read_rgba_pixels(ctx, x, y, width, height,
+ format, type, pixels, packing, transferOps)) {
+ return; /* done! */
+ }
+
+ /* width should never be > MAX_WIDTH since we did clipping earlier */
+ ASSERT(width <= MAX_WIDTH);
+
+ do {
+ const GLint dstStride
+ = _mesa_image_row_stride(packing, width, format, type);
+ GLfloat (*rgba)[4] = swrast->SpanArrays->attribs[FRAG_ATTRIB_COL0];
+ GLint row;
+ GLubyte *dst
+ = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
+ format, type, 0, 0);
+
+ for (row = 0; row < height; row++, y++) {
+
+ /* Get float rgba pixels */
+ _swrast_read_rgba_span(ctx, rb, width, x, y, GL_FLOAT, rgba);
+
+ /* apply fudge factor for shallow color buffers */
+ if (fb->Visual.redBits < 8 ||
+ fb->Visual.greenBits < 8 ||
+ fb->Visual.blueBits < 8) {
+ adjust_colors(fb, width, rgba);
+ }
+
+ /* pack the row of RGBA pixels into user's buffer */
+ _mesa_pack_rgba_span_float(ctx, width, rgba, format, type, dst,
+ packing, transferOps);
+
+ dst += dstStride;
+ }
+ } while (0);
+}
+
+
+/**
+ * Read combined depth/stencil values.
+ * We'll have already done error checking to be sure the expected
+ * depth and stencil buffers really exist.
+ */
+static void
+read_depth_stencil_pixels(struct gl_context *ctx,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type, GLvoid *pixels,
+ const struct gl_pixelstore_attrib *packing )
+{
+ const GLboolean scaleOrBias
+ = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
+ const GLboolean stencilTransfer = ctx->Pixel.IndexShift
+ || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag;
+ struct gl_renderbuffer *depthRb, *stencilRb;
+
+ depthRb = ctx->ReadBuffer->_DepthBuffer;
+ stencilRb = ctx->ReadBuffer->_StencilBuffer;
+
+ if (!depthRb || !stencilRb)
+ return;
+
+ depthRb = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+ stencilRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
+
+ if (depthRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
+ stencilRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
+ depthRb == stencilRb &&
+ !scaleOrBias &&
+ !stencilTransfer) {
+ /* This is the ideal case.
+ * Reading GL_DEPTH_STENCIL pixels from combined depth/stencil buffer.
+ * Plus, no pixel transfer ops to worry about!
+ */
+ GLint i;
+ GLint dstStride = _mesa_image_row_stride(packing, width,
+ GL_DEPTH_STENCIL_EXT, type);
+ GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, pixels,
+ width, height,
+ GL_DEPTH_STENCIL_EXT,
+ type, 0, 0);
+ for (i = 0; i < height; i++) {
+ depthRb->GetRow(ctx, depthRb, width, x, y + i, dst);
+ dst += dstStride;
+ }
+ }
+ else {
+ /* Reading GL_DEPTH_STENCIL pixels from separate depth/stencil buffers,
+ * or we need pixel transfer.
+ */
+ GLint i;
+ depthRb = ctx->ReadBuffer->_DepthBuffer;
+ stencilRb = ctx->ReadBuffer->_StencilBuffer;
+
+ for (i = 0; i < height; i++) {
+ GLstencil stencilVals[MAX_WIDTH];
+
+ GLuint *depthStencilDst = (GLuint *)
+ _mesa_image_address2d(packing, pixels, width, height,
+ GL_DEPTH_STENCIL_EXT, type, i, 0);
+
+ _swrast_read_stencil_span(ctx, stencilRb, width,
+ x, y + i, stencilVals);
+
+ if (!scaleOrBias && !stencilTransfer
+ && ctx->ReadBuffer->Visual.depthBits == 24) {
+ /* ideal case */
+ GLuint zVals[MAX_WIDTH]; /* 24-bit values! */
+ GLint j;
+ ASSERT(depthRb->DataType == GL_UNSIGNED_INT);
+ /* note, we've already been clipped */
+ depthRb->GetRow(ctx, depthRb, width, x, y + i, zVals);
+ for (j = 0; j < width; j++) {
+ depthStencilDst[j] = (zVals[j] << 8) | (stencilVals[j] & 0xff);
+ }
+ }
+ else {
+ /* general case */
+ GLfloat depthVals[MAX_WIDTH];
+ _swrast_read_depth_span_float(ctx, depthRb, width, x, y + i,
+ depthVals);
+ _mesa_pack_depth_stencil_span(ctx, width, depthStencilDst,
+ depthVals, stencilVals, packing);
+ }
+ }
+ }
+}
+
+
+
+/**
+ * Software fallback routine for ctx->Driver.ReadPixels().
+ * By time we get here, all error checking will have been done.
+ */
+void
+_swrast_ReadPixels( struct gl_context *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *packing,
+ GLvoid *pixels )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ struct gl_pixelstore_attrib clippedPacking = *packing;
+
+ if (ctx->NewState)
+ _mesa_update_state(ctx);
+
+ /* Need to do swrast_render_start() before clipping or anything else
+ * since this is where a driver may grab the hw lock and get an updated
+ * window size.
+ */
+ swrast_render_start(ctx);
+
+ if (swrast->NewState)
+ _swrast_validate_derived( ctx );
+
+ /* Do all needed clipping here, so that we can forget about it later */
+ if (_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
+
+ pixels = _mesa_map_pbo_dest(ctx, &clippedPacking, pixels);
+
+ if (pixels) {
+ switch (format) {
+ case GL_STENCIL_INDEX:
+ read_stencil_pixels(ctx, x, y, width, height, type, pixels,
+ &clippedPacking);
+ break;
+ case GL_DEPTH_COMPONENT:
+ read_depth_pixels(ctx, x, y, width, height, type, pixels,
+ &clippedPacking);
+ break;
+ case GL_DEPTH_STENCIL_EXT:
+ read_depth_stencil_pixels(ctx, x, y, width, height, type, pixels,
+ &clippedPacking);
+ break;
+ default:
+ /* all other formats should be color formats */
+ read_rgba_pixels(ctx, x, y, width, height, format, type, pixels,
+ &clippedPacking);
+ }
+
+ _mesa_unmap_pbo_dest(ctx, &clippedPacking);
+ }
+ }
+
+ swrast_render_finish(ctx);
+}
diff --git a/mesalib/src/mesa/swrast/s_texcombine.c b/mesalib/src/mesa/swrast/s_texcombine.c
index 0c8cc9ff3..a7f4fe67d 100644
--- a/mesalib/src/mesa/swrast/s_texcombine.c
+++ b/mesalib/src/mesa/swrast/s_texcombine.c
@@ -1,737 +1,737 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.5
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "main/glheader.h"
-#include "main/context.h"
-#include "main/colormac.h"
-#include "main/imports.h"
-#include "main/pixeltransfer.h"
-#include "program/prog_instruction.h"
-
-#include "s_context.h"
-#include "s_texcombine.h"
-
-
-/**
- * Pointer to array of float[4]
- * This type makes the code below more concise and avoids a lot of casting.
- */
-typedef float (*float4_array)[4];
-
-
-/**
- * Return array of texels for given unit.
- */
-static INLINE float4_array
-get_texel_array(SWcontext *swrast, GLuint unit)
-{
- return (float4_array) (swrast->TexelBuffer + unit * MAX_WIDTH * 4);
-}
-
-
-
-/**
- * Do texture application for:
- * GL_EXT_texture_env_combine
- * GL_ARB_texture_env_combine
- * GL_EXT_texture_env_dot3
- * GL_ARB_texture_env_dot3
- * GL_ATI_texture_env_combine3
- * GL_NV_texture_env_combine4
- * conventional GL texture env modes
- *
- * \param ctx rendering context
- * \param unit the texture combiner unit
- * \param n number of fragments to process (span width)
- * \param primary_rgba incoming fragment color array
- * \param texelBuffer pointer to texel colors for all texture units
- *
- * \param rgba incoming/result fragment colors
- */
-static void
-texture_combine( struct gl_context *ctx, GLuint unit, GLuint n,
- const float4_array primary_rgba,
- const GLfloat *texelBuffer,
- GLchan (*rgbaChan)[4] )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- const struct gl_texture_unit *textureUnit = &(ctx->Texture.Unit[unit]);
- const struct gl_tex_env_combine_state *combine = textureUnit->_CurrentCombine;
- float4_array argRGB[MAX_COMBINER_TERMS];
- float4_array argA[MAX_COMBINER_TERMS];
- const GLfloat scaleRGB = (GLfloat) (1 << combine->ScaleShiftRGB);
- const GLfloat scaleA = (GLfloat) (1 << combine->ScaleShiftA);
- const GLuint numArgsRGB = combine->_NumArgsRGB;
- const GLuint numArgsA = combine->_NumArgsA;
- float4_array ccolor[4], rgba;
- GLuint i, term;
-
- /* alloc temp pixel buffers */
- rgba = (float4_array) malloc(4 * n * sizeof(GLfloat));
- if (!rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture_combine");
- return;
- }
-
- for (i = 0; i < numArgsRGB || i < numArgsA; i++) {
- ccolor[i] = (float4_array) malloc(4 * n * sizeof(GLfloat));
- if (!ccolor[i]) {
- while (i) {
- free(ccolor[i]);
- i--;
- }
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture_combine");
- return;
- }
- }
-
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = CHAN_TO_FLOAT(rgbaChan[i][RCOMP]);
- rgba[i][GCOMP] = CHAN_TO_FLOAT(rgbaChan[i][GCOMP]);
- rgba[i][BCOMP] = CHAN_TO_FLOAT(rgbaChan[i][BCOMP]);
- rgba[i][ACOMP] = CHAN_TO_FLOAT(rgbaChan[i][ACOMP]);
- }
-
- /*
- printf("modeRGB 0x%x modeA 0x%x srcRGB1 0x%x srcA1 0x%x srcRGB2 0x%x srcA2 0x%x\n",
- combine->ModeRGB,
- combine->ModeA,
- combine->SourceRGB[0],
- combine->SourceA[0],
- combine->SourceRGB[1],
- combine->SourceA[1]);
- */
-
- /*
- * Do operand setup for up to 4 operands. Loop over the terms.
- */
- for (term = 0; term < numArgsRGB; term++) {
- const GLenum srcRGB = combine->SourceRGB[term];
- const GLenum operandRGB = combine->OperandRGB[term];
-
- switch (srcRGB) {
- case GL_TEXTURE:
- argRGB[term] = get_texel_array(swrast, unit);
- break;
- case GL_PRIMARY_COLOR:
- argRGB[term] = primary_rgba;
- break;
- case GL_PREVIOUS:
- argRGB[term] = rgba;
- break;
- case GL_CONSTANT:
- {
- float4_array c = ccolor[term];
- GLfloat red = textureUnit->EnvColor[0];
- GLfloat green = textureUnit->EnvColor[1];
- GLfloat blue = textureUnit->EnvColor[2];
- GLfloat alpha = textureUnit->EnvColor[3];
- for (i = 0; i < n; i++) {
- ASSIGN_4V(c[i], red, green, blue, alpha);
- }
- argRGB[term] = ccolor[term];
- }
- break;
- /* GL_ATI_texture_env_combine3 allows GL_ZERO & GL_ONE as sources.
- */
- case GL_ZERO:
- {
- float4_array c = ccolor[term];
- for (i = 0; i < n; i++) {
- ASSIGN_4V(c[i], 0.0F, 0.0F, 0.0F, 0.0F);
- }
- argRGB[term] = ccolor[term];
- }
- break;
- case GL_ONE:
- {
- float4_array c = ccolor[term];
- for (i = 0; i < n; i++) {
- ASSIGN_4V(c[i], 1.0F, 1.0F, 1.0F, 1.0F);
- }
- argRGB[term] = ccolor[term];
- }
- break;
- default:
- /* ARB_texture_env_crossbar source */
- {
- const GLuint srcUnit = srcRGB - GL_TEXTURE0;
- ASSERT(srcUnit < ctx->Const.MaxTextureUnits);
- if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled)
- goto end;
- argRGB[term] = get_texel_array(swrast, srcUnit);
- }
- }
-
- if (operandRGB != GL_SRC_COLOR) {
- float4_array src = argRGB[term];
- float4_array dst = ccolor[term];
-
- /* point to new arg[term] storage */
- argRGB[term] = ccolor[term];
-
- switch (operandRGB) {
- case GL_ONE_MINUS_SRC_COLOR:
- for (i = 0; i < n; i++) {
- dst[i][RCOMP] = 1.0F - src[i][RCOMP];
- dst[i][GCOMP] = 1.0F - src[i][GCOMP];
- dst[i][BCOMP] = 1.0F - src[i][BCOMP];
- }
- break;
- case GL_SRC_ALPHA:
- for (i = 0; i < n; i++) {
- dst[i][RCOMP] =
- dst[i][GCOMP] =
- dst[i][BCOMP] = src[i][ACOMP];
- }
- break;
- case GL_ONE_MINUS_SRC_ALPHA:
- for (i = 0; i < n; i++) {
- dst[i][RCOMP] =
- dst[i][GCOMP] =
- dst[i][BCOMP] = 1.0F - src[i][ACOMP];
- }
- break;
- default:
- _mesa_problem(ctx, "Bad operandRGB");
- }
- }
- }
-
- /*
- * Set up the argA[term] pointers
- */
- for (term = 0; term < numArgsA; term++) {
- const GLenum srcA = combine->SourceA[term];
- const GLenum operandA = combine->OperandA[term];
-
- switch (srcA) {
- case GL_TEXTURE:
- argA[term] = get_texel_array(swrast, unit);
- break;
- case GL_PRIMARY_COLOR:
- argA[term] = primary_rgba;
- break;
- case GL_PREVIOUS:
- argA[term] = rgba;
- break;
- case GL_CONSTANT:
- {
- float4_array c = ccolor[term];
- GLfloat alpha = textureUnit->EnvColor[3];
- for (i = 0; i < n; i++)
- c[i][ACOMP] = alpha;
- argA[term] = ccolor[term];
- }
- break;
- /* GL_ATI_texture_env_combine3 allows GL_ZERO & GL_ONE as sources.
- */
- case GL_ZERO:
- {
- float4_array c = ccolor[term];
- for (i = 0; i < n; i++)
- c[i][ACOMP] = 0.0F;
- argA[term] = ccolor[term];
- }
- break;
- case GL_ONE:
- {
- float4_array c = ccolor[term];
- for (i = 0; i < n; i++)
- c[i][ACOMP] = 1.0F;
- argA[term] = ccolor[term];
- }
- break;
- default:
- /* ARB_texture_env_crossbar source */
- {
- const GLuint srcUnit = srcA - GL_TEXTURE0;
- ASSERT(srcUnit < ctx->Const.MaxTextureUnits);
- if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled)
- goto end;
- argA[term] = get_texel_array(swrast, srcUnit);
- }
- }
-
- if (operandA == GL_ONE_MINUS_SRC_ALPHA) {
- float4_array src = argA[term];
- float4_array dst = ccolor[term];
- argA[term] = ccolor[term];
- for (i = 0; i < n; i++) {
- dst[i][ACOMP] = 1.0F - src[i][ACOMP];
- }
- }
- }
-
- /* RGB channel combine */
- {
- float4_array arg0 = argRGB[0];
- float4_array arg1 = argRGB[1];
- float4_array arg2 = argRGB[2];
- float4_array arg3 = argRGB[3];
-
- switch (combine->ModeRGB) {
- case GL_REPLACE:
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = arg0[i][RCOMP] * scaleRGB;
- rgba[i][GCOMP] = arg0[i][GCOMP] * scaleRGB;
- rgba[i][BCOMP] = arg0[i][BCOMP] * scaleRGB;
- }
- break;
- case GL_MODULATE:
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = arg0[i][RCOMP] * arg1[i][RCOMP] * scaleRGB;
- rgba[i][GCOMP] = arg0[i][GCOMP] * arg1[i][GCOMP] * scaleRGB;
- rgba[i][BCOMP] = arg0[i][BCOMP] * arg1[i][BCOMP] * scaleRGB;
- }
- break;
- case GL_ADD:
- if (textureUnit->EnvMode == GL_COMBINE4_NV) {
- /* (a * b) + (c * d) */
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = (arg0[i][RCOMP] * arg1[i][RCOMP] +
- arg2[i][RCOMP] * arg3[i][RCOMP]) * scaleRGB;
- rgba[i][GCOMP] = (arg0[i][GCOMP] * arg1[i][GCOMP] +
- arg2[i][GCOMP] * arg3[i][GCOMP]) * scaleRGB;
- rgba[i][BCOMP] = (arg0[i][BCOMP] * arg1[i][BCOMP] +
- arg2[i][BCOMP] * arg3[i][BCOMP]) * scaleRGB;
- }
- }
- else {
- /* 2-term addition */
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP]) * scaleRGB;
- rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP]) * scaleRGB;
- rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP]) * scaleRGB;
- }
- }
- break;
- case GL_ADD_SIGNED:
- if (textureUnit->EnvMode == GL_COMBINE4_NV) {
- /* (a * b) + (c * d) - 0.5 */
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = (arg0[i][RCOMP] * arg1[i][RCOMP] +
- arg2[i][RCOMP] * arg3[i][RCOMP] - 0.5F) * scaleRGB;
- rgba[i][GCOMP] = (arg0[i][GCOMP] * arg1[i][GCOMP] +
- arg2[i][GCOMP] * arg3[i][GCOMP] - 0.5F) * scaleRGB;
- rgba[i][BCOMP] = (arg0[i][BCOMP] * arg1[i][BCOMP] +
- arg2[i][BCOMP] * arg3[i][BCOMP] - 0.5F) * scaleRGB;
- }
- }
- else {
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP] - 0.5F) * scaleRGB;
- rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP] - 0.5F) * scaleRGB;
- rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP] - 0.5F) * scaleRGB;
- }
- }
- break;
- case GL_INTERPOLATE:
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = (arg0[i][RCOMP] * arg2[i][RCOMP] +
- arg1[i][RCOMP] * (1.0F - arg2[i][RCOMP])) * scaleRGB;
- rgba[i][GCOMP] = (arg0[i][GCOMP] * arg2[i][GCOMP] +
- arg1[i][GCOMP] * (1.0F - arg2[i][GCOMP])) * scaleRGB;
- rgba[i][BCOMP] = (arg0[i][BCOMP] * arg2[i][BCOMP] +
- arg1[i][BCOMP] * (1.0F - arg2[i][BCOMP])) * scaleRGB;
- }
- break;
- case GL_SUBTRACT:
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = (arg0[i][RCOMP] - arg1[i][RCOMP]) * scaleRGB;
- rgba[i][GCOMP] = (arg0[i][GCOMP] - arg1[i][GCOMP]) * scaleRGB;
- rgba[i][BCOMP] = (arg0[i][BCOMP] - arg1[i][BCOMP]) * scaleRGB;
- }
- break;
- case GL_DOT3_RGB_EXT:
- case GL_DOT3_RGBA_EXT:
- /* Do not scale the result by 1 2 or 4 */
- for (i = 0; i < n; i++) {
- GLfloat dot = ((arg0[i][RCOMP] - 0.5F) * (arg1[i][RCOMP] - 0.5F) +
- (arg0[i][GCOMP] - 0.5F) * (arg1[i][GCOMP] - 0.5F) +
- (arg0[i][BCOMP] - 0.5F) * (arg1[i][BCOMP] - 0.5F))
- * 4.0F;
- dot = CLAMP(dot, 0.0F, 1.0F);
- rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = dot;
- }
- break;
- case GL_DOT3_RGB:
- case GL_DOT3_RGBA:
- /* DO scale the result by 1 2 or 4 */
- for (i = 0; i < n; i++) {
- GLfloat dot = ((arg0[i][RCOMP] - 0.5F) * (arg1[i][RCOMP] - 0.5F) +
- (arg0[i][GCOMP] - 0.5F) * (arg1[i][GCOMP] - 0.5F) +
- (arg0[i][BCOMP] - 0.5F) * (arg1[i][BCOMP] - 0.5F))
- * 4.0F * scaleRGB;
- dot = CLAMP(dot, 0.0F, 1.0F);
- rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = dot;
- }
- break;
- case GL_MODULATE_ADD_ATI:
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) +
- arg1[i][RCOMP]) * scaleRGB;
- rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) +
- arg1[i][GCOMP]) * scaleRGB;
- rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) +
- arg1[i][BCOMP]) * scaleRGB;
- }
- break;
- case GL_MODULATE_SIGNED_ADD_ATI:
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) +
- arg1[i][RCOMP] - 0.5F) * scaleRGB;
- rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) +
- arg1[i][GCOMP] - 0.5F) * scaleRGB;
- rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) +
- arg1[i][BCOMP] - 0.5F) * scaleRGB;
- }
- break;
- case GL_MODULATE_SUBTRACT_ATI:
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) -
- arg1[i][RCOMP]) * scaleRGB;
- rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) -
- arg1[i][GCOMP]) * scaleRGB;
- rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) -
- arg1[i][BCOMP]) * scaleRGB;
- }
- break;
- case GL_BUMP_ENVMAP_ATI:
- /* this produces a fixed rgba color, and the coord calc is done elsewhere */
- for (i = 0; i < n; i++) {
- /* rgba result is 0,0,0,1 */
- rgba[i][RCOMP] = 0.0;
- rgba[i][GCOMP] = 0.0;
- rgba[i][BCOMP] = 0.0;
- rgba[i][ACOMP] = 1.0;
- }
- goto end; /* no alpha processing */
- default:
- _mesa_problem(ctx, "invalid combine mode");
- }
- }
-
- /* Alpha channel combine */
- {
- float4_array arg0 = argA[0];
- float4_array arg1 = argA[1];
- float4_array arg2 = argA[2];
- float4_array arg3 = argA[3];
-
- switch (combine->ModeA) {
- case GL_REPLACE:
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = arg0[i][ACOMP] * scaleA;
- }
- break;
- case GL_MODULATE:
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = arg0[i][ACOMP] * arg1[i][ACOMP] * scaleA;
- }
- break;
- case GL_ADD:
- if (textureUnit->EnvMode == GL_COMBINE4_NV) {
- /* (a * b) + (c * d) */
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = (arg0[i][ACOMP] * arg1[i][ACOMP] +
- arg2[i][ACOMP] * arg3[i][ACOMP]) * scaleA;
- }
- }
- else {
- /* two-term add */
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = (arg0[i][ACOMP] + arg1[i][ACOMP]) * scaleA;
- }
- }
- break;
- case GL_ADD_SIGNED:
- if (textureUnit->EnvMode == GL_COMBINE4_NV) {
- /* (a * b) + (c * d) - 0.5 */
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = (arg0[i][ACOMP] * arg1[i][ACOMP] +
- arg2[i][ACOMP] * arg3[i][ACOMP] -
- 0.5F) * scaleA;
- }
- }
- else {
- /* a + b - 0.5 */
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = (arg0[i][ACOMP] + arg1[i][ACOMP] - 0.5F) * scaleA;
- }
- }
- break;
- case GL_INTERPOLATE:
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = (arg0[i][ACOMP] * arg2[i][ACOMP] +
- arg1[i][ACOMP] * (1.0F - arg2[i][ACOMP]))
- * scaleA;
- }
- break;
- case GL_SUBTRACT:
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = (arg0[i][ACOMP] - arg1[i][ACOMP]) * scaleA;
- }
- break;
- case GL_MODULATE_ADD_ATI:
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP])
- + arg1[i][ACOMP]) * scaleA;
- }
- break;
- case GL_MODULATE_SIGNED_ADD_ATI:
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) +
- arg1[i][ACOMP] - 0.5F) * scaleA;
- }
- break;
- case GL_MODULATE_SUBTRACT_ATI:
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP])
- - arg1[i][ACOMP]) * scaleA;
- }
- break;
- default:
- _mesa_problem(ctx, "invalid combine mode");
- }
- }
-
- /* Fix the alpha component for GL_DOT3_RGBA_EXT/ARB combining.
- * This is kind of a kludge. It would have been better if the spec
- * were written such that the GL_COMBINE_ALPHA value could be set to
- * GL_DOT3.
- */
- if (combine->ModeRGB == GL_DOT3_RGBA_EXT ||
- combine->ModeRGB == GL_DOT3_RGBA) {
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = rgba[i][RCOMP];
- }
- }
-
- for (i = 0; i < n; i++) {
- UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][RCOMP], rgba[i][RCOMP]);
- UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][GCOMP], rgba[i][GCOMP]);
- UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][BCOMP], rgba[i][BCOMP]);
- UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][ACOMP], rgba[i][ACOMP]);
- }
-
-end:
- for (i = 0; i < numArgsRGB || i < numArgsA; i++) {
- free(ccolor[i]);
- }
- free(rgba);
-}
-
-
-/**
- * Apply X/Y/Z/W/0/1 swizzle to an array of colors/texels.
- * See GL_EXT_texture_swizzle.
- */
-static void
-swizzle_texels(GLuint swizzle, GLuint count, float4_array texels)
-{
- const GLuint swzR = GET_SWZ(swizzle, 0);
- const GLuint swzG = GET_SWZ(swizzle, 1);
- const GLuint swzB = GET_SWZ(swizzle, 2);
- const GLuint swzA = GET_SWZ(swizzle, 3);
- GLfloat vector[6];
- GLuint i;
-
- vector[SWIZZLE_ZERO] = 0;
- vector[SWIZZLE_ONE] = 1.0F;
-
- for (i = 0; i < count; i++) {
- vector[SWIZZLE_X] = texels[i][0];
- vector[SWIZZLE_Y] = texels[i][1];
- vector[SWIZZLE_Z] = texels[i][2];
- vector[SWIZZLE_W] = texels[i][3];
- texels[i][RCOMP] = vector[swzR];
- texels[i][GCOMP] = vector[swzG];
- texels[i][BCOMP] = vector[swzB];
- texels[i][ACOMP] = vector[swzA];
- }
-}
-
-
-/**
- * Apply texture mapping to a span of fragments.
- */
-void
-_swrast_texture_span( struct gl_context *ctx, SWspan *span )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- float4_array primary_rgba;
- GLuint unit;
-
- primary_rgba = (float4_array) malloc(span->end * 4 * sizeof(GLfloat));
-
- if (!primary_rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture_span");
- return;
- }
-
- ASSERT(span->end <= MAX_WIDTH);
-
- /*
- * Save copy of the incoming fragment colors (the GL_PRIMARY_COLOR)
- */
- if (swrast->_TextureCombinePrimary) {
- GLuint i;
- for (i = 0; i < span->end; i++) {
- primary_rgba[i][RCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][RCOMP]);
- primary_rgba[i][GCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][GCOMP]);
- primary_rgba[i][BCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][BCOMP]);
- primary_rgba[i][ACOMP] = CHAN_TO_FLOAT(span->array->rgba[i][ACOMP]);
- }
- }
-
- /* First must sample all bump maps */
- for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
- const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
-
- if (texUnit->_ReallyEnabled &&
- texUnit->_CurrentCombine->ModeRGB == GL_BUMP_ENVMAP_ATI) {
- const GLfloat (*texcoords)[4] = (const GLfloat (*)[4])
- span->array->attribs[FRAG_ATTRIB_TEX0 + unit];
- float4_array targetcoords =
- span->array->attribs[FRAG_ATTRIB_TEX0 +
- ctx->Texture.Unit[unit].BumpTarget - GL_TEXTURE0];
-
- const struct gl_texture_object *curObj = texUnit->_Current;
- GLfloat *lambda = span->array->lambda[unit];
- float4_array texels = get_texel_array(swrast, unit);
- GLuint i;
- GLfloat rotMatrix00 = ctx->Texture.Unit[unit].RotMatrix[0];
- GLfloat rotMatrix01 = ctx->Texture.Unit[unit].RotMatrix[1];
- GLfloat rotMatrix10 = ctx->Texture.Unit[unit].RotMatrix[2];
- GLfloat rotMatrix11 = ctx->Texture.Unit[unit].RotMatrix[3];
-
- /* adjust texture lod (lambda) */
- if (span->arrayMask & SPAN_LAMBDA) {
- if (texUnit->LodBias + curObj->LodBias != 0.0F) {
- /* apply LOD bias, but don't clamp yet */
- const GLfloat bias = CLAMP(texUnit->LodBias + curObj->LodBias,
- -ctx->Const.MaxTextureLodBias,
- ctx->Const.MaxTextureLodBias);
- GLuint i;
- for (i = 0; i < span->end; i++) {
- lambda[i] += bias;
- }
- }
-
- if (curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) {
- /* apply LOD clamping to lambda */
- const GLfloat min = curObj->MinLod;
- const GLfloat max = curObj->MaxLod;
- GLuint i;
- for (i = 0; i < span->end; i++) {
- GLfloat l = lambda[i];
- lambda[i] = CLAMP(l, min, max);
- }
- }
- }
-
- /* Sample the texture (span->end = number of fragments) */
- swrast->TextureSample[unit]( ctx, texUnit->_Current, span->end,
- texcoords, lambda, texels );
-
- /* manipulate the span values of the bump target
- not sure this can work correctly even ignoring
- the problem that channel is unsigned */
- for (i = 0; i < span->end; i++) {
- targetcoords[i][0] += (texels[i][0] * rotMatrix00 + texels[i][1] *
- rotMatrix01) / targetcoords[i][3];
- targetcoords[i][1] += (texels[i][0] * rotMatrix10 + texels[i][1] *
- rotMatrix11) / targetcoords[i][3];
- }
- }
- }
-
- /*
- * Must do all texture sampling before combining in order to
- * accomodate GL_ARB_texture_env_crossbar.
- */
- for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
- const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
- if (texUnit->_ReallyEnabled &&
- texUnit->_CurrentCombine->ModeRGB != GL_BUMP_ENVMAP_ATI) {
- const GLfloat (*texcoords)[4] = (const GLfloat (*)[4])
- span->array->attribs[FRAG_ATTRIB_TEX0 + unit];
- const struct gl_texture_object *curObj = texUnit->_Current;
- GLfloat *lambda = span->array->lambda[unit];
- float4_array texels = get_texel_array(swrast, unit);
-
- /* adjust texture lod (lambda) */
- if (span->arrayMask & SPAN_LAMBDA) {
- if (texUnit->LodBias + curObj->LodBias != 0.0F) {
- /* apply LOD bias, but don't clamp yet */
- const GLfloat bias = CLAMP(texUnit->LodBias + curObj->LodBias,
- -ctx->Const.MaxTextureLodBias,
- ctx->Const.MaxTextureLodBias);
- GLuint i;
- for (i = 0; i < span->end; i++) {
- lambda[i] += bias;
- }
- }
-
- if (curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) {
- /* apply LOD clamping to lambda */
- const GLfloat min = curObj->MinLod;
- const GLfloat max = curObj->MaxLod;
- GLuint i;
- for (i = 0; i < span->end; i++) {
- GLfloat l = lambda[i];
- lambda[i] = CLAMP(l, min, max);
- }
- }
- }
-
- /* Sample the texture (span->end = number of fragments) */
- swrast->TextureSample[unit]( ctx, texUnit->_Current, span->end,
- texcoords, lambda, texels );
-
- /* GL_EXT_texture_swizzle */
- if (curObj->_Swizzle != SWIZZLE_NOOP) {
- swizzle_texels(curObj->_Swizzle, span->end, texels);
- }
- }
- }
-
- /*
- * OK, now apply the texture (aka texture combine/blend).
- * We modify the span->color.rgba values.
- */
- for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
- if (ctx->Texture.Unit[unit]._ReallyEnabled) {
- texture_combine( ctx, unit, span->end,
- primary_rgba,
- swrast->TexelBuffer,
- span->array->rgba );
- }
- }
-
- free(primary_rgba);
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.5
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/colormac.h"
+#include "main/imports.h"
+#include "main/pixeltransfer.h"
+#include "program/prog_instruction.h"
+
+#include "s_context.h"
+#include "s_texcombine.h"
+
+
+/**
+ * Pointer to array of float[4]
+ * This type makes the code below more concise and avoids a lot of casting.
+ */
+typedef float (*float4_array)[4];
+
+
+/**
+ * Return array of texels for given unit.
+ */
+static INLINE float4_array
+get_texel_array(SWcontext *swrast, GLuint unit)
+{
+ return (float4_array) (swrast->TexelBuffer + unit * MAX_WIDTH * 4);
+}
+
+
+
+/**
+ * Do texture application for:
+ * GL_EXT_texture_env_combine
+ * GL_ARB_texture_env_combine
+ * GL_EXT_texture_env_dot3
+ * GL_ARB_texture_env_dot3
+ * GL_ATI_texture_env_combine3
+ * GL_NV_texture_env_combine4
+ * conventional GL texture env modes
+ *
+ * \param ctx rendering context
+ * \param unit the texture combiner unit
+ * \param n number of fragments to process (span width)
+ * \param primary_rgba incoming fragment color array
+ * \param texelBuffer pointer to texel colors for all texture units
+ *
+ * \param rgba incoming/result fragment colors
+ */
+static void
+texture_combine( struct gl_context *ctx, GLuint unit, GLuint n,
+ const float4_array primary_rgba,
+ const GLfloat *texelBuffer,
+ GLchan (*rgbaChan)[4] )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ const struct gl_texture_unit *textureUnit = &(ctx->Texture.Unit[unit]);
+ const struct gl_tex_env_combine_state *combine = textureUnit->_CurrentCombine;
+ float4_array argRGB[MAX_COMBINER_TERMS];
+ float4_array argA[MAX_COMBINER_TERMS];
+ const GLfloat scaleRGB = (GLfloat) (1 << combine->ScaleShiftRGB);
+ const GLfloat scaleA = (GLfloat) (1 << combine->ScaleShiftA);
+ const GLuint numArgsRGB = combine->_NumArgsRGB;
+ const GLuint numArgsA = combine->_NumArgsA;
+ float4_array ccolor[4], rgba;
+ GLuint i, term;
+
+ /* alloc temp pixel buffers */
+ rgba = (float4_array) malloc(4 * n * sizeof(GLfloat));
+ if (!rgba) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture_combine");
+ return;
+ }
+
+ for (i = 0; i < numArgsRGB || i < numArgsA; i++) {
+ ccolor[i] = (float4_array) malloc(4 * n * sizeof(GLfloat));
+ if (!ccolor[i]) {
+ while (i) {
+ free(ccolor[i]);
+ i--;
+ }
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture_combine");
+ return;
+ }
+ }
+
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = CHAN_TO_FLOAT(rgbaChan[i][RCOMP]);
+ rgba[i][GCOMP] = CHAN_TO_FLOAT(rgbaChan[i][GCOMP]);
+ rgba[i][BCOMP] = CHAN_TO_FLOAT(rgbaChan[i][BCOMP]);
+ rgba[i][ACOMP] = CHAN_TO_FLOAT(rgbaChan[i][ACOMP]);
+ }
+
+ /*
+ printf("modeRGB 0x%x modeA 0x%x srcRGB1 0x%x srcA1 0x%x srcRGB2 0x%x srcA2 0x%x\n",
+ combine->ModeRGB,
+ combine->ModeA,
+ combine->SourceRGB[0],
+ combine->SourceA[0],
+ combine->SourceRGB[1],
+ combine->SourceA[1]);
+ */
+
+ /*
+ * Do operand setup for up to 4 operands. Loop over the terms.
+ */
+ for (term = 0; term < numArgsRGB; term++) {
+ const GLenum srcRGB = combine->SourceRGB[term];
+ const GLenum operandRGB = combine->OperandRGB[term];
+
+ switch (srcRGB) {
+ case GL_TEXTURE:
+ argRGB[term] = get_texel_array(swrast, unit);
+ break;
+ case GL_PRIMARY_COLOR:
+ argRGB[term] = primary_rgba;
+ break;
+ case GL_PREVIOUS:
+ argRGB[term] = rgba;
+ break;
+ case GL_CONSTANT:
+ {
+ float4_array c = ccolor[term];
+ GLfloat red = textureUnit->EnvColor[0];
+ GLfloat green = textureUnit->EnvColor[1];
+ GLfloat blue = textureUnit->EnvColor[2];
+ GLfloat alpha = textureUnit->EnvColor[3];
+ for (i = 0; i < n; i++) {
+ ASSIGN_4V(c[i], red, green, blue, alpha);
+ }
+ argRGB[term] = ccolor[term];
+ }
+ break;
+ /* GL_ATI_texture_env_combine3 allows GL_ZERO & GL_ONE as sources.
+ */
+ case GL_ZERO:
+ {
+ float4_array c = ccolor[term];
+ for (i = 0; i < n; i++) {
+ ASSIGN_4V(c[i], 0.0F, 0.0F, 0.0F, 0.0F);
+ }
+ argRGB[term] = ccolor[term];
+ }
+ break;
+ case GL_ONE:
+ {
+ float4_array c = ccolor[term];
+ for (i = 0; i < n; i++) {
+ ASSIGN_4V(c[i], 1.0F, 1.0F, 1.0F, 1.0F);
+ }
+ argRGB[term] = ccolor[term];
+ }
+ break;
+ default:
+ /* ARB_texture_env_crossbar source */
+ {
+ const GLuint srcUnit = srcRGB - GL_TEXTURE0;
+ ASSERT(srcUnit < ctx->Const.MaxTextureUnits);
+ if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled)
+ goto end;
+ argRGB[term] = get_texel_array(swrast, srcUnit);
+ }
+ }
+
+ if (operandRGB != GL_SRC_COLOR) {
+ float4_array src = argRGB[term];
+ float4_array dst = ccolor[term];
+
+ /* point to new arg[term] storage */
+ argRGB[term] = ccolor[term];
+
+ switch (operandRGB) {
+ case GL_ONE_MINUS_SRC_COLOR:
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = 1.0F - src[i][RCOMP];
+ dst[i][GCOMP] = 1.0F - src[i][GCOMP];
+ dst[i][BCOMP] = 1.0F - src[i][BCOMP];
+ }
+ break;
+ case GL_SRC_ALPHA:
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = src[i][ACOMP];
+ }
+ break;
+ case GL_ONE_MINUS_SRC_ALPHA:
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] =
+ dst[i][GCOMP] =
+ dst[i][BCOMP] = 1.0F - src[i][ACOMP];
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "Bad operandRGB");
+ }
+ }
+ }
+
+ /*
+ * Set up the argA[term] pointers
+ */
+ for (term = 0; term < numArgsA; term++) {
+ const GLenum srcA = combine->SourceA[term];
+ const GLenum operandA = combine->OperandA[term];
+
+ switch (srcA) {
+ case GL_TEXTURE:
+ argA[term] = get_texel_array(swrast, unit);
+ break;
+ case GL_PRIMARY_COLOR:
+ argA[term] = primary_rgba;
+ break;
+ case GL_PREVIOUS:
+ argA[term] = rgba;
+ break;
+ case GL_CONSTANT:
+ {
+ float4_array c = ccolor[term];
+ GLfloat alpha = textureUnit->EnvColor[3];
+ for (i = 0; i < n; i++)
+ c[i][ACOMP] = alpha;
+ argA[term] = ccolor[term];
+ }
+ break;
+ /* GL_ATI_texture_env_combine3 allows GL_ZERO & GL_ONE as sources.
+ */
+ case GL_ZERO:
+ {
+ float4_array c = ccolor[term];
+ for (i = 0; i < n; i++)
+ c[i][ACOMP] = 0.0F;
+ argA[term] = ccolor[term];
+ }
+ break;
+ case GL_ONE:
+ {
+ float4_array c = ccolor[term];
+ for (i = 0; i < n; i++)
+ c[i][ACOMP] = 1.0F;
+ argA[term] = ccolor[term];
+ }
+ break;
+ default:
+ /* ARB_texture_env_crossbar source */
+ {
+ const GLuint srcUnit = srcA - GL_TEXTURE0;
+ ASSERT(srcUnit < ctx->Const.MaxTextureUnits);
+ if (!ctx->Texture.Unit[srcUnit]._ReallyEnabled)
+ goto end;
+ argA[term] = get_texel_array(swrast, srcUnit);
+ }
+ }
+
+ if (operandA == GL_ONE_MINUS_SRC_ALPHA) {
+ float4_array src = argA[term];
+ float4_array dst = ccolor[term];
+ argA[term] = ccolor[term];
+ for (i = 0; i < n; i++) {
+ dst[i][ACOMP] = 1.0F - src[i][ACOMP];
+ }
+ }
+ }
+
+ /* RGB channel combine */
+ {
+ float4_array arg0 = argRGB[0];
+ float4_array arg1 = argRGB[1];
+ float4_array arg2 = argRGB[2];
+ float4_array arg3 = argRGB[3];
+
+ switch (combine->ModeRGB) {
+ case GL_REPLACE:
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = arg0[i][RCOMP] * scaleRGB;
+ rgba[i][GCOMP] = arg0[i][GCOMP] * scaleRGB;
+ rgba[i][BCOMP] = arg0[i][BCOMP] * scaleRGB;
+ }
+ break;
+ case GL_MODULATE:
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = arg0[i][RCOMP] * arg1[i][RCOMP] * scaleRGB;
+ rgba[i][GCOMP] = arg0[i][GCOMP] * arg1[i][GCOMP] * scaleRGB;
+ rgba[i][BCOMP] = arg0[i][BCOMP] * arg1[i][BCOMP] * scaleRGB;
+ }
+ break;
+ case GL_ADD:
+ if (textureUnit->EnvMode == GL_COMBINE4_NV) {
+ /* (a * b) + (c * d) */
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = (arg0[i][RCOMP] * arg1[i][RCOMP] +
+ arg2[i][RCOMP] * arg3[i][RCOMP]) * scaleRGB;
+ rgba[i][GCOMP] = (arg0[i][GCOMP] * arg1[i][GCOMP] +
+ arg2[i][GCOMP] * arg3[i][GCOMP]) * scaleRGB;
+ rgba[i][BCOMP] = (arg0[i][BCOMP] * arg1[i][BCOMP] +
+ arg2[i][BCOMP] * arg3[i][BCOMP]) * scaleRGB;
+ }
+ }
+ else {
+ /* 2-term addition */
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP]) * scaleRGB;
+ rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP]) * scaleRGB;
+ rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP]) * scaleRGB;
+ }
+ }
+ break;
+ case GL_ADD_SIGNED:
+ if (textureUnit->EnvMode == GL_COMBINE4_NV) {
+ /* (a * b) + (c * d) - 0.5 */
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = (arg0[i][RCOMP] * arg1[i][RCOMP] +
+ arg2[i][RCOMP] * arg3[i][RCOMP] - 0.5F) * scaleRGB;
+ rgba[i][GCOMP] = (arg0[i][GCOMP] * arg1[i][GCOMP] +
+ arg2[i][GCOMP] * arg3[i][GCOMP] - 0.5F) * scaleRGB;
+ rgba[i][BCOMP] = (arg0[i][BCOMP] * arg1[i][BCOMP] +
+ arg2[i][BCOMP] * arg3[i][BCOMP] - 0.5F) * scaleRGB;
+ }
+ }
+ else {
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = (arg0[i][RCOMP] + arg1[i][RCOMP] - 0.5F) * scaleRGB;
+ rgba[i][GCOMP] = (arg0[i][GCOMP] + arg1[i][GCOMP] - 0.5F) * scaleRGB;
+ rgba[i][BCOMP] = (arg0[i][BCOMP] + arg1[i][BCOMP] - 0.5F) * scaleRGB;
+ }
+ }
+ break;
+ case GL_INTERPOLATE:
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = (arg0[i][RCOMP] * arg2[i][RCOMP] +
+ arg1[i][RCOMP] * (1.0F - arg2[i][RCOMP])) * scaleRGB;
+ rgba[i][GCOMP] = (arg0[i][GCOMP] * arg2[i][GCOMP] +
+ arg1[i][GCOMP] * (1.0F - arg2[i][GCOMP])) * scaleRGB;
+ rgba[i][BCOMP] = (arg0[i][BCOMP] * arg2[i][BCOMP] +
+ arg1[i][BCOMP] * (1.0F - arg2[i][BCOMP])) * scaleRGB;
+ }
+ break;
+ case GL_SUBTRACT:
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = (arg0[i][RCOMP] - arg1[i][RCOMP]) * scaleRGB;
+ rgba[i][GCOMP] = (arg0[i][GCOMP] - arg1[i][GCOMP]) * scaleRGB;
+ rgba[i][BCOMP] = (arg0[i][BCOMP] - arg1[i][BCOMP]) * scaleRGB;
+ }
+ break;
+ case GL_DOT3_RGB_EXT:
+ case GL_DOT3_RGBA_EXT:
+ /* Do not scale the result by 1 2 or 4 */
+ for (i = 0; i < n; i++) {
+ GLfloat dot = ((arg0[i][RCOMP] - 0.5F) * (arg1[i][RCOMP] - 0.5F) +
+ (arg0[i][GCOMP] - 0.5F) * (arg1[i][GCOMP] - 0.5F) +
+ (arg0[i][BCOMP] - 0.5F) * (arg1[i][BCOMP] - 0.5F))
+ * 4.0F;
+ dot = CLAMP(dot, 0.0F, 1.0F);
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = dot;
+ }
+ break;
+ case GL_DOT3_RGB:
+ case GL_DOT3_RGBA:
+ /* DO scale the result by 1 2 or 4 */
+ for (i = 0; i < n; i++) {
+ GLfloat dot = ((arg0[i][RCOMP] - 0.5F) * (arg1[i][RCOMP] - 0.5F) +
+ (arg0[i][GCOMP] - 0.5F) * (arg1[i][GCOMP] - 0.5F) +
+ (arg0[i][BCOMP] - 0.5F) * (arg1[i][BCOMP] - 0.5F))
+ * 4.0F * scaleRGB;
+ dot = CLAMP(dot, 0.0F, 1.0F);
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = dot;
+ }
+ break;
+ case GL_MODULATE_ADD_ATI:
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) +
+ arg1[i][RCOMP]) * scaleRGB;
+ rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) +
+ arg1[i][GCOMP]) * scaleRGB;
+ rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) +
+ arg1[i][BCOMP]) * scaleRGB;
+ }
+ break;
+ case GL_MODULATE_SIGNED_ADD_ATI:
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) +
+ arg1[i][RCOMP] - 0.5F) * scaleRGB;
+ rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) +
+ arg1[i][GCOMP] - 0.5F) * scaleRGB;
+ rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) +
+ arg1[i][BCOMP] - 0.5F) * scaleRGB;
+ }
+ break;
+ case GL_MODULATE_SUBTRACT_ATI:
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = ((arg0[i][RCOMP] * arg2[i][RCOMP]) -
+ arg1[i][RCOMP]) * scaleRGB;
+ rgba[i][GCOMP] = ((arg0[i][GCOMP] * arg2[i][GCOMP]) -
+ arg1[i][GCOMP]) * scaleRGB;
+ rgba[i][BCOMP] = ((arg0[i][BCOMP] * arg2[i][BCOMP]) -
+ arg1[i][BCOMP]) * scaleRGB;
+ }
+ break;
+ case GL_BUMP_ENVMAP_ATI:
+ /* this produces a fixed rgba color, and the coord calc is done elsewhere */
+ for (i = 0; i < n; i++) {
+ /* rgba result is 0,0,0,1 */
+ rgba[i][RCOMP] = 0.0;
+ rgba[i][GCOMP] = 0.0;
+ rgba[i][BCOMP] = 0.0;
+ rgba[i][ACOMP] = 1.0;
+ }
+ goto end; /* no alpha processing */
+ default:
+ _mesa_problem(ctx, "invalid combine mode");
+ }
+ }
+
+ /* Alpha channel combine */
+ {
+ float4_array arg0 = argA[0];
+ float4_array arg1 = argA[1];
+ float4_array arg2 = argA[2];
+ float4_array arg3 = argA[3];
+
+ switch (combine->ModeA) {
+ case GL_REPLACE:
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = arg0[i][ACOMP] * scaleA;
+ }
+ break;
+ case GL_MODULATE:
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = arg0[i][ACOMP] * arg1[i][ACOMP] * scaleA;
+ }
+ break;
+ case GL_ADD:
+ if (textureUnit->EnvMode == GL_COMBINE4_NV) {
+ /* (a * b) + (c * d) */
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = (arg0[i][ACOMP] * arg1[i][ACOMP] +
+ arg2[i][ACOMP] * arg3[i][ACOMP]) * scaleA;
+ }
+ }
+ else {
+ /* two-term add */
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = (arg0[i][ACOMP] + arg1[i][ACOMP]) * scaleA;
+ }
+ }
+ break;
+ case GL_ADD_SIGNED:
+ if (textureUnit->EnvMode == GL_COMBINE4_NV) {
+ /* (a * b) + (c * d) - 0.5 */
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = (arg0[i][ACOMP] * arg1[i][ACOMP] +
+ arg2[i][ACOMP] * arg3[i][ACOMP] -
+ 0.5F) * scaleA;
+ }
+ }
+ else {
+ /* a + b - 0.5 */
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = (arg0[i][ACOMP] + arg1[i][ACOMP] - 0.5F) * scaleA;
+ }
+ }
+ break;
+ case GL_INTERPOLATE:
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = (arg0[i][ACOMP] * arg2[i][ACOMP] +
+ arg1[i][ACOMP] * (1.0F - arg2[i][ACOMP]))
+ * scaleA;
+ }
+ break;
+ case GL_SUBTRACT:
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = (arg0[i][ACOMP] - arg1[i][ACOMP]) * scaleA;
+ }
+ break;
+ case GL_MODULATE_ADD_ATI:
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP])
+ + arg1[i][ACOMP]) * scaleA;
+ }
+ break;
+ case GL_MODULATE_SIGNED_ADD_ATI:
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP]) +
+ arg1[i][ACOMP] - 0.5F) * scaleA;
+ }
+ break;
+ case GL_MODULATE_SUBTRACT_ATI:
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = ((arg0[i][ACOMP] * arg2[i][ACOMP])
+ - arg1[i][ACOMP]) * scaleA;
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "invalid combine mode");
+ }
+ }
+
+ /* Fix the alpha component for GL_DOT3_RGBA_EXT/ARB combining.
+ * This is kind of a kludge. It would have been better if the spec
+ * were written such that the GL_COMBINE_ALPHA value could be set to
+ * GL_DOT3.
+ */
+ if (combine->ModeRGB == GL_DOT3_RGBA_EXT ||
+ combine->ModeRGB == GL_DOT3_RGBA) {
+ for (i = 0; i < n; i++) {
+ rgba[i][ACOMP] = rgba[i][RCOMP];
+ }
+ }
+
+ for (i = 0; i < n; i++) {
+ UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][RCOMP], rgba[i][RCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][GCOMP], rgba[i][GCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][BCOMP], rgba[i][BCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][ACOMP], rgba[i][ACOMP]);
+ }
+
+end:
+ for (i = 0; i < numArgsRGB || i < numArgsA; i++) {
+ free(ccolor[i]);
+ }
+ free(rgba);
+}
+
+
+/**
+ * Apply X/Y/Z/W/0/1 swizzle to an array of colors/texels.
+ * See GL_EXT_texture_swizzle.
+ */
+static void
+swizzle_texels(GLuint swizzle, GLuint count, float4_array texels)
+{
+ const GLuint swzR = GET_SWZ(swizzle, 0);
+ const GLuint swzG = GET_SWZ(swizzle, 1);
+ const GLuint swzB = GET_SWZ(swizzle, 2);
+ const GLuint swzA = GET_SWZ(swizzle, 3);
+ GLfloat vector[6];
+ GLuint i;
+
+ vector[SWIZZLE_ZERO] = 0;
+ vector[SWIZZLE_ONE] = 1.0F;
+
+ for (i = 0; i < count; i++) {
+ vector[SWIZZLE_X] = texels[i][0];
+ vector[SWIZZLE_Y] = texels[i][1];
+ vector[SWIZZLE_Z] = texels[i][2];
+ vector[SWIZZLE_W] = texels[i][3];
+ texels[i][RCOMP] = vector[swzR];
+ texels[i][GCOMP] = vector[swzG];
+ texels[i][BCOMP] = vector[swzB];
+ texels[i][ACOMP] = vector[swzA];
+ }
+}
+
+
+/**
+ * Apply texture mapping to a span of fragments.
+ */
+void
+_swrast_texture_span( struct gl_context *ctx, SWspan *span )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ float4_array primary_rgba;
+ GLuint unit;
+
+ primary_rgba = (float4_array) malloc(span->end * 4 * sizeof(GLfloat));
+
+ if (!primary_rgba) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture_span");
+ return;
+ }
+
+ ASSERT(span->end <= MAX_WIDTH);
+
+ /*
+ * Save copy of the incoming fragment colors (the GL_PRIMARY_COLOR)
+ */
+ if (swrast->_TextureCombinePrimary) {
+ GLuint i;
+ for (i = 0; i < span->end; i++) {
+ primary_rgba[i][RCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][RCOMP]);
+ primary_rgba[i][GCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][GCOMP]);
+ primary_rgba[i][BCOMP] = CHAN_TO_FLOAT(span->array->rgba[i][BCOMP]);
+ primary_rgba[i][ACOMP] = CHAN_TO_FLOAT(span->array->rgba[i][ACOMP]);
+ }
+ }
+
+ /* First must sample all bump maps */
+ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
+ const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+
+ if (texUnit->_ReallyEnabled &&
+ texUnit->_CurrentCombine->ModeRGB == GL_BUMP_ENVMAP_ATI) {
+ const GLfloat (*texcoords)[4] = (const GLfloat (*)[4])
+ span->array->attribs[FRAG_ATTRIB_TEX0 + unit];
+ float4_array targetcoords =
+ span->array->attribs[FRAG_ATTRIB_TEX0 +
+ ctx->Texture.Unit[unit].BumpTarget - GL_TEXTURE0];
+
+ const struct gl_texture_object *curObj = texUnit->_Current;
+ GLfloat *lambda = span->array->lambda[unit];
+ float4_array texels = get_texel_array(swrast, unit);
+ GLuint i;
+ GLfloat rotMatrix00 = ctx->Texture.Unit[unit].RotMatrix[0];
+ GLfloat rotMatrix01 = ctx->Texture.Unit[unit].RotMatrix[1];
+ GLfloat rotMatrix10 = ctx->Texture.Unit[unit].RotMatrix[2];
+ GLfloat rotMatrix11 = ctx->Texture.Unit[unit].RotMatrix[3];
+
+ /* adjust texture lod (lambda) */
+ if (span->arrayMask & SPAN_LAMBDA) {
+ if (texUnit->LodBias + curObj->LodBias != 0.0F) {
+ /* apply LOD bias, but don't clamp yet */
+ const GLfloat bias = CLAMP(texUnit->LodBias + curObj->LodBias,
+ -ctx->Const.MaxTextureLodBias,
+ ctx->Const.MaxTextureLodBias);
+ GLuint i;
+ for (i = 0; i < span->end; i++) {
+ lambda[i] += bias;
+ }
+ }
+
+ if (curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) {
+ /* apply LOD clamping to lambda */
+ const GLfloat min = curObj->MinLod;
+ const GLfloat max = curObj->MaxLod;
+ GLuint i;
+ for (i = 0; i < span->end; i++) {
+ GLfloat l = lambda[i];
+ lambda[i] = CLAMP(l, min, max);
+ }
+ }
+ }
+
+ /* Sample the texture (span->end = number of fragments) */
+ swrast->TextureSample[unit]( ctx, texUnit->_Current, span->end,
+ texcoords, lambda, texels );
+
+ /* manipulate the span values of the bump target
+ not sure this can work correctly even ignoring
+ the problem that channel is unsigned */
+ for (i = 0; i < span->end; i++) {
+ targetcoords[i][0] += (texels[i][0] * rotMatrix00 + texels[i][1] *
+ rotMatrix01) / targetcoords[i][3];
+ targetcoords[i][1] += (texels[i][0] * rotMatrix10 + texels[i][1] *
+ rotMatrix11) / targetcoords[i][3];
+ }
+ }
+ }
+
+ /*
+ * Must do all texture sampling before combining in order to
+ * accomodate GL_ARB_texture_env_crossbar.
+ */
+ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
+ const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+ if (texUnit->_ReallyEnabled &&
+ texUnit->_CurrentCombine->ModeRGB != GL_BUMP_ENVMAP_ATI) {
+ const GLfloat (*texcoords)[4] = (const GLfloat (*)[4])
+ span->array->attribs[FRAG_ATTRIB_TEX0 + unit];
+ const struct gl_texture_object *curObj = texUnit->_Current;
+ GLfloat *lambda = span->array->lambda[unit];
+ float4_array texels = get_texel_array(swrast, unit);
+
+ /* adjust texture lod (lambda) */
+ if (span->arrayMask & SPAN_LAMBDA) {
+ if (texUnit->LodBias + curObj->LodBias != 0.0F) {
+ /* apply LOD bias, but don't clamp yet */
+ const GLfloat bias = CLAMP(texUnit->LodBias + curObj->LodBias,
+ -ctx->Const.MaxTextureLodBias,
+ ctx->Const.MaxTextureLodBias);
+ GLuint i;
+ for (i = 0; i < span->end; i++) {
+ lambda[i] += bias;
+ }
+ }
+
+ if (curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) {
+ /* apply LOD clamping to lambda */
+ const GLfloat min = curObj->MinLod;
+ const GLfloat max = curObj->MaxLod;
+ GLuint i;
+ for (i = 0; i < span->end; i++) {
+ GLfloat l = lambda[i];
+ lambda[i] = CLAMP(l, min, max);
+ }
+ }
+ }
+
+ /* Sample the texture (span->end = number of fragments) */
+ swrast->TextureSample[unit]( ctx, texUnit->_Current, span->end,
+ texcoords, lambda, texels );
+
+ /* GL_EXT_texture_swizzle */
+ if (curObj->_Swizzle != SWIZZLE_NOOP) {
+ swizzle_texels(curObj->_Swizzle, span->end, texels);
+ }
+ }
+ }
+
+ /*
+ * OK, now apply the texture (aka texture combine/blend).
+ * We modify the span->color.rgba values.
+ */
+ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
+ if (ctx->Texture.Unit[unit]._ReallyEnabled) {
+ texture_combine( ctx, unit, span->end,
+ primary_rgba,
+ swrast->TexelBuffer,
+ span->array->rgba );
+ }
+ }
+
+ free(primary_rgba);
+}
diff --git a/mesalib/src/mesa/tnl/t_draw.c b/mesalib/src/mesa/tnl/t_draw.c
index b1967e654..a2ca6225b 100644
--- a/mesalib/src/mesa/tnl/t_draw.c
+++ b/mesalib/src/mesa/tnl/t_draw.c
@@ -1,534 +1,534 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- */
-
-#include "main/glheader.h"
-#include "main/condrender.h"
-#include "main/context.h"
-#include "main/imports.h"
-#include "main/mtypes.h"
-#include "main/macros.h"
-#include "main/enums.h"
-
-#include "t_context.h"
-#include "tnl.h"
-
-
-
-static GLubyte *get_space(struct gl_context *ctx, GLuint bytes)
-{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- GLubyte *space = malloc(bytes);
-
- tnl->block[tnl->nr_blocks++] = space;
- return space;
-}
-
-
-static void free_space(struct gl_context *ctx)
-{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- GLuint i;
- for (i = 0; i < tnl->nr_blocks; i++)
- free(tnl->block[i]);
- tnl->nr_blocks = 0;
-}
-
-
-/* Convert the incoming array to GLfloats. Understands the
- * array->Normalized flag and selects the correct conversion method.
- */
-#define CONVERT( TYPE, MACRO ) do { \
- GLuint i, j; \
- if (input->Normalized) { \
- for (i = 0; i < count; i++) { \
- const TYPE *in = (TYPE *)ptr; \
- for (j = 0; j < sz; j++) { \
- *fptr++ = MACRO(*in); \
- in++; \
- } \
- ptr += input->StrideB; \
- } \
- } else { \
- for (i = 0; i < count; i++) { \
- const TYPE *in = (TYPE *)ptr; \
- for (j = 0; j < sz; j++) { \
- *fptr++ = (GLfloat)(*in); \
- in++; \
- } \
- ptr += input->StrideB; \
- } \
- } \
-} while (0)
-
-
-/**
- * Convert array of BGRA/GLubyte[4] values to RGBA/float[4]
- * \param ptr input/ubyte array
- * \param fptr output/float array
- */
-static void
-convert_bgra_to_float(const struct gl_client_array *input,
- const GLubyte *ptr, GLfloat *fptr,
- GLuint count )
-{
- GLuint i;
- assert(input->Normalized);
- assert(input->Size == 4);
- for (i = 0; i < count; i++) {
- const GLubyte *in = (GLubyte *) ptr; /* in is in BGRA order */
- *fptr++ = UBYTE_TO_FLOAT(in[2]); /* red */
- *fptr++ = UBYTE_TO_FLOAT(in[1]); /* green */
- *fptr++ = UBYTE_TO_FLOAT(in[0]); /* blue */
- *fptr++ = UBYTE_TO_FLOAT(in[3]); /* alpha */
- ptr += input->StrideB;
- }
-}
-
-static void
-convert_half_to_float(const struct gl_client_array *input,
- const GLubyte *ptr, GLfloat *fptr,
- GLuint count, GLuint sz)
-{
- GLuint i, j;
-
- for (i = 0; i < count; i++) {
- GLhalfARB *in = (GLhalfARB *)ptr;
-
- for (j = 0; j < sz; j++) {
- *fptr++ = _mesa_half_to_float(in[j]);
- }
- ptr += input->StrideB;
- }
-}
-
-/**
- * \brief Convert fixed-point to floating-point.
- *
- * In OpenGL, a fixed-point number is a "signed 2's complement 16.16 scaled
- * integer" (Table 2.2 of the OpenGL ES 2.0 spec).
- *
- * If the buffer has the \c normalized flag set, the formula
- * \code normalize(x) := (2*x + 1) / (2^16 - 1) \endcode
- * is used to map the fixed-point numbers into the range [-1, 1].
- */
-static void
-convert_fixed_to_float(const struct gl_client_array *input,
- const GLubyte *ptr, GLfloat *fptr,
- GLuint count)
-{
- GLuint i, j;
- const GLint size = input->Size;
-
- if (input->Normalized) {
- for (i = 0; i < count; ++i) {
- const GLfixed *in = (GLfixed *) ptr;
- for (j = 0; j < size; ++j) {
- *fptr++ = (GLfloat) (2 * in[j] + 1) / (GLfloat) ((1 << 16) - 1);
- }
- ptr += input->StrideB;
- }
- } else {
- for (i = 0; i < count; ++i) {
- const GLfixed *in = (GLfixed *) ptr;
- for (j = 0; j < size; ++j) {
- *fptr++ = in[j] / (GLfloat) (1 << 16);
- }
- ptr += input->StrideB;
- }
- }
-}
-
-/* Adjust pointer to point at first requested element, convert to
- * floating point, populate VB->AttribPtr[].
- */
-static void _tnl_import_array( struct gl_context *ctx,
- GLuint attrib,
- GLuint count,
- const struct gl_client_array *input,
- const GLubyte *ptr )
-{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- struct vertex_buffer *VB = &tnl->vb;
- GLuint stride = input->StrideB;
-
- if (input->Type != GL_FLOAT) {
- const GLuint sz = input->Size;
- GLubyte *buf = get_space(ctx, count * sz * sizeof(GLfloat));
- GLfloat *fptr = (GLfloat *)buf;
-
- switch (input->Type) {
- case GL_BYTE:
- CONVERT(GLbyte, BYTE_TO_FLOAT);
- break;
- case GL_UNSIGNED_BYTE:
- if (input->Format == GL_BGRA) {
- /* See GL_EXT_vertex_array_bgra */
- convert_bgra_to_float(input, ptr, fptr, count);
- }
- else {
- CONVERT(GLubyte, UBYTE_TO_FLOAT);
- }
- break;
- case GL_SHORT:
- CONVERT(GLshort, SHORT_TO_FLOAT);
- break;
- case GL_UNSIGNED_SHORT:
- CONVERT(GLushort, USHORT_TO_FLOAT);
- break;
- case GL_INT:
- CONVERT(GLint, INT_TO_FLOAT);
- break;
- case GL_UNSIGNED_INT:
- CONVERT(GLuint, UINT_TO_FLOAT);
- break;
- case GL_DOUBLE:
- CONVERT(GLdouble, (GLfloat));
- break;
- case GL_HALF_FLOAT:
- convert_half_to_float(input, ptr, fptr, count, sz);
- break;
- case GL_FIXED:
- convert_fixed_to_float(input, ptr, fptr, count);
- break;
- default:
- assert(0);
- break;
- }
-
- ptr = buf;
- stride = sz * sizeof(GLfloat);
- }
-
- VB->AttribPtr[attrib] = &tnl->tmp_inputs[attrib];
- VB->AttribPtr[attrib]->data = (GLfloat (*)[4])ptr;
- VB->AttribPtr[attrib]->start = (GLfloat *)ptr;
- VB->AttribPtr[attrib]->count = count;
- VB->AttribPtr[attrib]->stride = stride;
- VB->AttribPtr[attrib]->size = input->Size;
-
- /* This should die, but so should the whole GLvector4f concept:
- */
- VB->AttribPtr[attrib]->flags = (((1<<input->Size)-1) |
- VEC_NOT_WRITEABLE |
- (stride == 4*sizeof(GLfloat) ? 0 : VEC_BAD_STRIDE));
-
- VB->AttribPtr[attrib]->storage = NULL;
-}
-
-#define CLIPVERTS ((6 + MAX_CLIP_PLANES) * 2)
-
-
-static GLboolean *_tnl_import_edgeflag( struct gl_context *ctx,
- const GLvector4f *input,
- GLuint count)
-{
- const GLubyte *ptr = (const GLubyte *)input->data;
- const GLuint stride = input->stride;
- GLboolean *space = (GLboolean *)get_space(ctx, count + CLIPVERTS);
- GLboolean *bptr = space;
- GLuint i;
-
- for (i = 0; i < count; i++) {
- *bptr++ = ((GLfloat *)ptr)[0] == 1.0;
- ptr += stride;
- }
-
- return space;
-}
-
-
-static void bind_inputs( struct gl_context *ctx,
- const struct gl_client_array *inputs[],
- GLint count,
- struct gl_buffer_object **bo,
- GLuint *nr_bo )
-{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- struct vertex_buffer *VB = &tnl->vb;
- GLuint i;
-
- /* Map all the VBOs
- */
- for (i = 0; i < VERT_ATTRIB_MAX; i++) {
- const void *ptr;
-
- if (inputs[i]->BufferObj->Name) {
- if (!inputs[i]->BufferObj->Pointer) {
- bo[*nr_bo] = inputs[i]->BufferObj;
- (*nr_bo)++;
- ctx->Driver.MapBuffer(ctx,
- GL_ARRAY_BUFFER,
- GL_READ_ONLY_ARB,
- inputs[i]->BufferObj);
-
- assert(inputs[i]->BufferObj->Pointer);
- }
-
- ptr = ADD_POINTERS(inputs[i]->BufferObj->Pointer,
- inputs[i]->Ptr);
- }
- else
- ptr = inputs[i]->Ptr;
-
- /* Just make sure the array is floating point, otherwise convert to
- * temporary storage.
- *
- * XXX: remove the GLvector4f type at some stage and just use
- * client arrays.
- */
- _tnl_import_array(ctx, i, count, inputs[i], ptr);
- }
-
- /* We process only the vertices between min & max index:
- */
- VB->Count = count;
-
- /* These should perhaps be part of _TNL_ATTRIB_* */
- VB->BackfaceColorPtr = NULL;
- VB->BackfaceIndexPtr = NULL;
- VB->BackfaceSecondaryColorPtr = NULL;
-
- /* Clipping and drawing code still requires this to be a packed
- * array of ubytes which can be written into. TODO: Fix and
- * remove.
- */
- if (ctx->Polygon.FrontMode != GL_FILL ||
- ctx->Polygon.BackMode != GL_FILL)
- {
- VB->EdgeFlag = _tnl_import_edgeflag( ctx,
- VB->AttribPtr[_TNL_ATTRIB_EDGEFLAG],
- VB->Count );
- }
- else {
- /* the data previously pointed to by EdgeFlag may have been freed */
- VB->EdgeFlag = NULL;
- }
-}
-
-
-/* Translate indices to GLuints and store in VB->Elts.
- */
-static void bind_indices( struct gl_context *ctx,
- const struct _mesa_index_buffer *ib,
- struct gl_buffer_object **bo,
- GLuint *nr_bo)
-{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- struct vertex_buffer *VB = &tnl->vb;
- GLuint i;
- void *ptr;
-
- if (!ib) {
- VB->Elts = NULL;
- return;
- }
-
- if (ib->obj->Name && !ib->obj->Pointer) {
- bo[*nr_bo] = ib->obj;
- (*nr_bo)++;
- ctx->Driver.MapBuffer(ctx,
- GL_ELEMENT_ARRAY_BUFFER,
- GL_READ_ONLY_ARB,
- ib->obj);
-
- assert(ib->obj->Pointer);
- }
-
- ptr = ADD_POINTERS(ib->obj->Pointer, ib->ptr);
-
- if (ib->type == GL_UNSIGNED_INT && VB->Primitive[0].basevertex == 0) {
- VB->Elts = (GLuint *) ptr;
- }
- else {
- GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint));
- VB->Elts = elts;
-
- if (ib->type == GL_UNSIGNED_INT) {
- const GLuint *in = (GLuint *)ptr;
- for (i = 0; i < ib->count; i++)
- *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
- }
- else if (ib->type == GL_UNSIGNED_SHORT) {
- const GLushort *in = (GLushort *)ptr;
- for (i = 0; i < ib->count; i++)
- *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
- }
- else {
- const GLubyte *in = (GLubyte *)ptr;
- for (i = 0; i < ib->count; i++)
- *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
- }
- }
-}
-
-static void bind_prims( struct gl_context *ctx,
- const struct _mesa_prim *prim,
- GLuint nr_prims )
-{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- struct vertex_buffer *VB = &tnl->vb;
-
- VB->Primitive = prim;
- VB->PrimitiveCount = nr_prims;
-}
-
-static void unmap_vbos( struct gl_context *ctx,
- struct gl_buffer_object **bo,
- GLuint nr_bo )
-{
- GLuint i;
- for (i = 0; i < nr_bo; i++) {
- ctx->Driver.UnmapBuffer(ctx,
- 0, /* target -- I don't see why this would be needed */
- bo[i]);
- }
-}
-
-
-void _tnl_vbo_draw_prims(struct gl_context *ctx,
- const struct gl_client_array *arrays[],
- const struct _mesa_prim *prim,
- GLuint nr_prims,
- const struct _mesa_index_buffer *ib,
- GLboolean index_bounds_valid,
- GLuint min_index,
- GLuint max_index)
-{
- if (!index_bounds_valid)
- vbo_get_minmax_index(ctx, prim, ib, &min_index, &max_index);
-
- _tnl_draw_prims(ctx, arrays, prim, nr_prims, ib, min_index, max_index);
-}
-
-/* This is the main entrypoint into the slimmed-down software tnl
- * module. In a regular swtnl driver, this can be plugged straight
- * into the vbo->Driver.DrawPrims() callback.
- */
-void _tnl_draw_prims( struct gl_context *ctx,
- const struct gl_client_array *arrays[],
- const struct _mesa_prim *prim,
- GLuint nr_prims,
- const struct _mesa_index_buffer *ib,
- GLuint min_index,
- GLuint max_index)
-{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- const GLuint TEST_SPLIT = 0;
- const GLint max = TEST_SPLIT ? 8 : tnl->vb.Size - MAX_CLIPPED_VERTICES;
- GLint max_basevertex = prim->basevertex;
- GLuint i;
-
- /* Mesa core state should have been validated already */
- assert(ctx->NewState == 0x0);
-
- if (!_mesa_check_conditional_render(ctx))
- return; /* don't draw */
-
- for (i = 1; i < nr_prims; i++)
- max_basevertex = MAX2(max_basevertex, prim[i].basevertex);
-
- if (0)
- {
- printf("%s %d..%d\n", __FUNCTION__, min_index, max_index);
- for (i = 0; i < nr_prims; i++)
- printf("prim %d: %s start %d count %d\n", i,
- _mesa_lookup_enum_by_nr(prim[i].mode),
- prim[i].start,
- prim[i].count);
- }
-
- if (min_index) {
- /* We always translate away calls with min_index != 0.
- */
- vbo_rebase_prims( ctx, arrays, prim, nr_prims, ib,
- min_index, max_index,
- _tnl_vbo_draw_prims );
- return;
- }
- else if ((GLint)max_index + max_basevertex > max) {
- /* The software TNL pipeline has a fixed amount of storage for
- * vertices and it is necessary to split incoming drawing commands
- * if they exceed that limit.
- */
- struct split_limits limits;
- limits.max_verts = max;
- limits.max_vb_size = ~0;
- limits.max_indices = ~0;
-
- /* This will split the buffers one way or another and
- * recursively call back into this function.
- */
- vbo_split_prims( ctx, arrays, prim, nr_prims, ib,
- 0, max_index + prim->basevertex,
- _tnl_vbo_draw_prims,
- &limits );
- }
- else {
- /* May need to map a vertex buffer object for every attribute plus
- * one for the index buffer.
- */
- struct gl_buffer_object *bo[VERT_ATTRIB_MAX + 1];
- GLuint nr_bo = 0;
- GLuint inst;
-
- for (i = 0; i < nr_prims;) {
- GLuint this_nr_prims;
-
- /* Our SW TNL pipeline doesn't handle basevertex yet, so bind_indices
- * will rebase the elements to the basevertex, and we'll only
- * emit strings of prims with the same basevertex in one draw call.
- */
- for (this_nr_prims = 1; i + this_nr_prims < nr_prims;
- this_nr_prims++) {
- if (prim[i].basevertex != prim[i + this_nr_prims].basevertex)
- break;
- }
-
- assert(prim[i].num_instances > 0);
-
- /* Binding inputs may imply mapping some vertex buffer objects.
- * They will need to be unmapped below.
- */
- for (inst = 0; inst < prim[i].num_instances; inst++) {
-
- bind_prims(ctx, &prim[i], this_nr_prims);
- bind_inputs(ctx, arrays, max_index + prim[i].basevertex + 1,
- bo, &nr_bo);
- bind_indices(ctx, ib, bo, &nr_bo);
-
- tnl->CurInstance = inst;
- TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx);
-
- unmap_vbos(ctx, bo, nr_bo);
- free_space(ctx);
- }
-
- i += this_nr_prims;
- }
- }
-}
-
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "main/glheader.h"
+#include "main/condrender.h"
+#include "main/context.h"
+#include "main/imports.h"
+#include "main/mtypes.h"
+#include "main/macros.h"
+#include "main/enums.h"
+
+#include "t_context.h"
+#include "tnl.h"
+
+
+
+static GLubyte *get_space(struct gl_context *ctx, GLuint bytes)
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ GLubyte *space = malloc(bytes);
+
+ tnl->block[tnl->nr_blocks++] = space;
+ return space;
+}
+
+
+static void free_space(struct gl_context *ctx)
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ GLuint i;
+ for (i = 0; i < tnl->nr_blocks; i++)
+ free(tnl->block[i]);
+ tnl->nr_blocks = 0;
+}
+
+
+/* Convert the incoming array to GLfloats. Understands the
+ * array->Normalized flag and selects the correct conversion method.
+ */
+#define CONVERT( TYPE, MACRO ) do { \
+ GLuint i, j; \
+ if (input->Normalized) { \
+ for (i = 0; i < count; i++) { \
+ const TYPE *in = (TYPE *)ptr; \
+ for (j = 0; j < sz; j++) { \
+ *fptr++ = MACRO(*in); \
+ in++; \
+ } \
+ ptr += input->StrideB; \
+ } \
+ } else { \
+ for (i = 0; i < count; i++) { \
+ const TYPE *in = (TYPE *)ptr; \
+ for (j = 0; j < sz; j++) { \
+ *fptr++ = (GLfloat)(*in); \
+ in++; \
+ } \
+ ptr += input->StrideB; \
+ } \
+ } \
+} while (0)
+
+
+/**
+ * Convert array of BGRA/GLubyte[4] values to RGBA/float[4]
+ * \param ptr input/ubyte array
+ * \param fptr output/float array
+ */
+static void
+convert_bgra_to_float(const struct gl_client_array *input,
+ const GLubyte *ptr, GLfloat *fptr,
+ GLuint count )
+{
+ GLuint i;
+ assert(input->Normalized);
+ assert(input->Size == 4);
+ for (i = 0; i < count; i++) {
+ const GLubyte *in = (GLubyte *) ptr; /* in is in BGRA order */
+ *fptr++ = UBYTE_TO_FLOAT(in[2]); /* red */
+ *fptr++ = UBYTE_TO_FLOAT(in[1]); /* green */
+ *fptr++ = UBYTE_TO_FLOAT(in[0]); /* blue */
+ *fptr++ = UBYTE_TO_FLOAT(in[3]); /* alpha */
+ ptr += input->StrideB;
+ }
+}
+
+static void
+convert_half_to_float(const struct gl_client_array *input,
+ const GLubyte *ptr, GLfloat *fptr,
+ GLuint count, GLuint sz)
+{
+ GLuint i, j;
+
+ for (i = 0; i < count; i++) {
+ GLhalfARB *in = (GLhalfARB *)ptr;
+
+ for (j = 0; j < sz; j++) {
+ *fptr++ = _mesa_half_to_float(in[j]);
+ }
+ ptr += input->StrideB;
+ }
+}
+
+/**
+ * \brief Convert fixed-point to floating-point.
+ *
+ * In OpenGL, a fixed-point number is a "signed 2's complement 16.16 scaled
+ * integer" (Table 2.2 of the OpenGL ES 2.0 spec).
+ *
+ * If the buffer has the \c normalized flag set, the formula
+ * \code normalize(x) := (2*x + 1) / (2^16 - 1) \endcode
+ * is used to map the fixed-point numbers into the range [-1, 1].
+ */
+static void
+convert_fixed_to_float(const struct gl_client_array *input,
+ const GLubyte *ptr, GLfloat *fptr,
+ GLuint count)
+{
+ GLuint i, j;
+ const GLint size = input->Size;
+
+ if (input->Normalized) {
+ for (i = 0; i < count; ++i) {
+ const GLfixed *in = (GLfixed *) ptr;
+ for (j = 0; j < size; ++j) {
+ *fptr++ = (GLfloat) (2 * in[j] + 1) / (GLfloat) ((1 << 16) - 1);
+ }
+ ptr += input->StrideB;
+ }
+ } else {
+ for (i = 0; i < count; ++i) {
+ const GLfixed *in = (GLfixed *) ptr;
+ for (j = 0; j < size; ++j) {
+ *fptr++ = in[j] / (GLfloat) (1 << 16);
+ }
+ ptr += input->StrideB;
+ }
+ }
+}
+
+/* Adjust pointer to point at first requested element, convert to
+ * floating point, populate VB->AttribPtr[].
+ */
+static void _tnl_import_array( struct gl_context *ctx,
+ GLuint attrib,
+ GLuint count,
+ const struct gl_client_array *input,
+ const GLubyte *ptr )
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct vertex_buffer *VB = &tnl->vb;
+ GLuint stride = input->StrideB;
+
+ if (input->Type != GL_FLOAT) {
+ const GLuint sz = input->Size;
+ GLubyte *buf = get_space(ctx, count * sz * sizeof(GLfloat));
+ GLfloat *fptr = (GLfloat *)buf;
+
+ switch (input->Type) {
+ case GL_BYTE:
+ CONVERT(GLbyte, BYTE_TO_FLOAT);
+ break;
+ case GL_UNSIGNED_BYTE:
+ if (input->Format == GL_BGRA) {
+ /* See GL_EXT_vertex_array_bgra */
+ convert_bgra_to_float(input, ptr, fptr, count);
+ }
+ else {
+ CONVERT(GLubyte, UBYTE_TO_FLOAT);
+ }
+ break;
+ case GL_SHORT:
+ CONVERT(GLshort, SHORT_TO_FLOAT);
+ break;
+ case GL_UNSIGNED_SHORT:
+ CONVERT(GLushort, USHORT_TO_FLOAT);
+ break;
+ case GL_INT:
+ CONVERT(GLint, INT_TO_FLOAT);
+ break;
+ case GL_UNSIGNED_INT:
+ CONVERT(GLuint, UINT_TO_FLOAT);
+ break;
+ case GL_DOUBLE:
+ CONVERT(GLdouble, (GLfloat));
+ break;
+ case GL_HALF_FLOAT:
+ convert_half_to_float(input, ptr, fptr, count, sz);
+ break;
+ case GL_FIXED:
+ convert_fixed_to_float(input, ptr, fptr, count);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ ptr = buf;
+ stride = sz * sizeof(GLfloat);
+ }
+
+ VB->AttribPtr[attrib] = &tnl->tmp_inputs[attrib];
+ VB->AttribPtr[attrib]->data = (GLfloat (*)[4])ptr;
+ VB->AttribPtr[attrib]->start = (GLfloat *)ptr;
+ VB->AttribPtr[attrib]->count = count;
+ VB->AttribPtr[attrib]->stride = stride;
+ VB->AttribPtr[attrib]->size = input->Size;
+
+ /* This should die, but so should the whole GLvector4f concept:
+ */
+ VB->AttribPtr[attrib]->flags = (((1<<input->Size)-1) |
+ VEC_NOT_WRITEABLE |
+ (stride == 4*sizeof(GLfloat) ? 0 : VEC_BAD_STRIDE));
+
+ VB->AttribPtr[attrib]->storage = NULL;
+}
+
+#define CLIPVERTS ((6 + MAX_CLIP_PLANES) * 2)
+
+
+static GLboolean *_tnl_import_edgeflag( struct gl_context *ctx,
+ const GLvector4f *input,
+ GLuint count)
+{
+ const GLubyte *ptr = (const GLubyte *)input->data;
+ const GLuint stride = input->stride;
+ GLboolean *space = (GLboolean *)get_space(ctx, count + CLIPVERTS);
+ GLboolean *bptr = space;
+ GLuint i;
+
+ for (i = 0; i < count; i++) {
+ *bptr++ = ((GLfloat *)ptr)[0] == 1.0;
+ ptr += stride;
+ }
+
+ return space;
+}
+
+
+static void bind_inputs( struct gl_context *ctx,
+ const struct gl_client_array *inputs[],
+ GLint count,
+ struct gl_buffer_object **bo,
+ GLuint *nr_bo )
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct vertex_buffer *VB = &tnl->vb;
+ GLuint i;
+
+ /* Map all the VBOs
+ */
+ for (i = 0; i < VERT_ATTRIB_MAX; i++) {
+ const void *ptr;
+
+ if (inputs[i]->BufferObj->Name) {
+ if (!inputs[i]->BufferObj->Pointer) {
+ bo[*nr_bo] = inputs[i]->BufferObj;
+ (*nr_bo)++;
+ ctx->Driver.MapBuffer(ctx,
+ GL_ARRAY_BUFFER,
+ GL_READ_ONLY_ARB,
+ inputs[i]->BufferObj);
+
+ assert(inputs[i]->BufferObj->Pointer);
+ }
+
+ ptr = ADD_POINTERS(inputs[i]->BufferObj->Pointer,
+ inputs[i]->Ptr);
+ }
+ else
+ ptr = inputs[i]->Ptr;
+
+ /* Just make sure the array is floating point, otherwise convert to
+ * temporary storage.
+ *
+ * XXX: remove the GLvector4f type at some stage and just use
+ * client arrays.
+ */
+ _tnl_import_array(ctx, i, count, inputs[i], ptr);
+ }
+
+ /* We process only the vertices between min & max index:
+ */
+ VB->Count = count;
+
+ /* These should perhaps be part of _TNL_ATTRIB_* */
+ VB->BackfaceColorPtr = NULL;
+ VB->BackfaceIndexPtr = NULL;
+ VB->BackfaceSecondaryColorPtr = NULL;
+
+ /* Clipping and drawing code still requires this to be a packed
+ * array of ubytes which can be written into. TODO: Fix and
+ * remove.
+ */
+ if (ctx->Polygon.FrontMode != GL_FILL ||
+ ctx->Polygon.BackMode != GL_FILL)
+ {
+ VB->EdgeFlag = _tnl_import_edgeflag( ctx,
+ VB->AttribPtr[_TNL_ATTRIB_EDGEFLAG],
+ VB->Count );
+ }
+ else {
+ /* the data previously pointed to by EdgeFlag may have been freed */
+ VB->EdgeFlag = NULL;
+ }
+}
+
+
+/* Translate indices to GLuints and store in VB->Elts.
+ */
+static void bind_indices( struct gl_context *ctx,
+ const struct _mesa_index_buffer *ib,
+ struct gl_buffer_object **bo,
+ GLuint *nr_bo)
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct vertex_buffer *VB = &tnl->vb;
+ GLuint i;
+ void *ptr;
+
+ if (!ib) {
+ VB->Elts = NULL;
+ return;
+ }
+
+ if (ib->obj->Name && !ib->obj->Pointer) {
+ bo[*nr_bo] = ib->obj;
+ (*nr_bo)++;
+ ctx->Driver.MapBuffer(ctx,
+ GL_ELEMENT_ARRAY_BUFFER,
+ GL_READ_ONLY_ARB,
+ ib->obj);
+
+ assert(ib->obj->Pointer);
+ }
+
+ ptr = ADD_POINTERS(ib->obj->Pointer, ib->ptr);
+
+ if (ib->type == GL_UNSIGNED_INT && VB->Primitive[0].basevertex == 0) {
+ VB->Elts = (GLuint *) ptr;
+ }
+ else {
+ GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint));
+ VB->Elts = elts;
+
+ if (ib->type == GL_UNSIGNED_INT) {
+ const GLuint *in = (GLuint *)ptr;
+ for (i = 0; i < ib->count; i++)
+ *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
+ }
+ else if (ib->type == GL_UNSIGNED_SHORT) {
+ const GLushort *in = (GLushort *)ptr;
+ for (i = 0; i < ib->count; i++)
+ *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
+ }
+ else {
+ const GLubyte *in = (GLubyte *)ptr;
+ for (i = 0; i < ib->count; i++)
+ *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
+ }
+ }
+}
+
+static void bind_prims( struct gl_context *ctx,
+ const struct _mesa_prim *prim,
+ GLuint nr_prims )
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct vertex_buffer *VB = &tnl->vb;
+
+ VB->Primitive = prim;
+ VB->PrimitiveCount = nr_prims;
+}
+
+static void unmap_vbos( struct gl_context *ctx,
+ struct gl_buffer_object **bo,
+ GLuint nr_bo )
+{
+ GLuint i;
+ for (i = 0; i < nr_bo; i++) {
+ ctx->Driver.UnmapBuffer(ctx,
+ 0, /* target -- I don't see why this would be needed */
+ bo[i]);
+ }
+}
+
+
+void _tnl_vbo_draw_prims(struct gl_context *ctx,
+ const struct gl_client_array *arrays[],
+ const struct _mesa_prim *prim,
+ GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLboolean index_bounds_valid,
+ GLuint min_index,
+ GLuint max_index)
+{
+ if (!index_bounds_valid)
+ vbo_get_minmax_index(ctx, prim, ib, &min_index, &max_index);
+
+ _tnl_draw_prims(ctx, arrays, prim, nr_prims, ib, min_index, max_index);
+}
+
+/* This is the main entrypoint into the slimmed-down software tnl
+ * module. In a regular swtnl driver, this can be plugged straight
+ * into the vbo->Driver.DrawPrims() callback.
+ */
+void _tnl_draw_prims( struct gl_context *ctx,
+ const struct gl_client_array *arrays[],
+ const struct _mesa_prim *prim,
+ GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLuint min_index,
+ GLuint max_index)
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ const GLuint TEST_SPLIT = 0;
+ const GLint max = TEST_SPLIT ? 8 : tnl->vb.Size - MAX_CLIPPED_VERTICES;
+ GLint max_basevertex = prim->basevertex;
+ GLuint i;
+
+ /* Mesa core state should have been validated already */
+ assert(ctx->NewState == 0x0);
+
+ if (!_mesa_check_conditional_render(ctx))
+ return; /* don't draw */
+
+ for (i = 1; i < nr_prims; i++)
+ max_basevertex = MAX2(max_basevertex, prim[i].basevertex);
+
+ if (0)
+ {
+ printf("%s %d..%d\n", __FUNCTION__, min_index, max_index);
+ for (i = 0; i < nr_prims; i++)
+ printf("prim %d: %s start %d count %d\n", i,
+ _mesa_lookup_enum_by_nr(prim[i].mode),
+ prim[i].start,
+ prim[i].count);
+ }
+
+ if (min_index) {
+ /* We always translate away calls with min_index != 0.
+ */
+ vbo_rebase_prims( ctx, arrays, prim, nr_prims, ib,
+ min_index, max_index,
+ _tnl_vbo_draw_prims );
+ return;
+ }
+ else if ((GLint)max_index + max_basevertex > max) {
+ /* The software TNL pipeline has a fixed amount of storage for
+ * vertices and it is necessary to split incoming drawing commands
+ * if they exceed that limit.
+ */
+ struct split_limits limits;
+ limits.max_verts = max;
+ limits.max_vb_size = ~0;
+ limits.max_indices = ~0;
+
+ /* This will split the buffers one way or another and
+ * recursively call back into this function.
+ */
+ vbo_split_prims( ctx, arrays, prim, nr_prims, ib,
+ 0, max_index + prim->basevertex,
+ _tnl_vbo_draw_prims,
+ &limits );
+ }
+ else {
+ /* May need to map a vertex buffer object for every attribute plus
+ * one for the index buffer.
+ */
+ struct gl_buffer_object *bo[VERT_ATTRIB_MAX + 1];
+ GLuint nr_bo = 0;
+ GLuint inst;
+
+ for (i = 0; i < nr_prims;) {
+ GLuint this_nr_prims;
+
+ /* Our SW TNL pipeline doesn't handle basevertex yet, so bind_indices
+ * will rebase the elements to the basevertex, and we'll only
+ * emit strings of prims with the same basevertex in one draw call.
+ */
+ for (this_nr_prims = 1; i + this_nr_prims < nr_prims;
+ this_nr_prims++) {
+ if (prim[i].basevertex != prim[i + this_nr_prims].basevertex)
+ break;
+ }
+
+ assert(prim[i].num_instances > 0);
+
+ /* Binding inputs may imply mapping some vertex buffer objects.
+ * They will need to be unmapped below.
+ */
+ for (inst = 0; inst < prim[i].num_instances; inst++) {
+
+ bind_prims(ctx, &prim[i], this_nr_prims);
+ bind_inputs(ctx, arrays, max_index + prim[i].basevertex + 1,
+ bo, &nr_bo);
+ bind_indices(ctx, ib, bo, &nr_bo);
+
+ tnl->CurInstance = inst;
+ TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx);
+
+ unmap_vbos(ctx, bo, nr_bo);
+ free_space(ctx);
+ }
+
+ i += this_nr_prims;
+ }
+ }
+}
+
diff --git a/mesalib/src/mesa/vbo/vbo.h b/mesalib/src/mesa/vbo/vbo.h
index 26c3d4e0a..37bdde9a8 100644
--- a/mesalib/src/mesa/vbo/vbo.h
+++ b/mesalib/src/mesa/vbo/vbo.h
@@ -1,176 +1,176 @@
-/*
- * mesa 3-D graphics library
- * Version: 6.5
- *
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file vbo_context.h
- * \brief VBO builder module datatypes and definitions.
- * \author Keith Whitwell
- */
-
-
-#ifndef _VBO_H
-#define _VBO_H
-
-#include "main/glheader.h"
-
-struct gl_client_array;
-struct gl_context;
-
-struct _mesa_prim {
- GLuint mode:8; /**< GL_POINTS, GL_LINES, GL_QUAD_STRIP, etc */
- GLuint indexed:1;
- GLuint begin:1;
- GLuint end:1;
- GLuint weak:1;
- GLuint no_current_update:1;
- GLuint pad:19;
-
- GLuint start;
- GLuint count;
- GLint basevertex;
- GLsizei num_instances;
-};
-
-/* Would like to call this a "vbo_index_buffer", but this would be
- * confusing as the indices are not neccessarily yet in a non-null
- * buffer object.
- */
-struct _mesa_index_buffer {
- GLuint count;
- GLenum type;
- struct gl_buffer_object *obj;
- const void *ptr;
-};
-
-
-
-GLboolean _vbo_CreateContext( struct gl_context *ctx );
-void _vbo_DestroyContext( struct gl_context *ctx );
-void _vbo_InvalidateState( struct gl_context *ctx, GLuint new_state );
-
-
-typedef void (*vbo_draw_func)( struct gl_context *ctx,
- const struct gl_client_array **arrays,
- const struct _mesa_prim *prims,
- GLuint nr_prims,
- const struct _mesa_index_buffer *ib,
- GLboolean index_bounds_valid,
- GLuint min_index,
- GLuint max_index );
-
-
-
-
-/* Utility function to cope with various constraints on tnl modules or
- * hardware. This can be used to split an incoming set of arrays and
- * primitives against the following constraints:
- * - Maximum number of indices in index buffer.
- * - Maximum number of vertices referenced by index buffer.
- * - Maximum hardware vertex buffer size.
- */
-struct split_limits {
- GLuint max_verts;
- GLuint max_indices;
- GLuint max_vb_size; /* bytes */
-};
-
-
-void vbo_split_prims( struct gl_context *ctx,
- const struct gl_client_array *arrays[],
- const struct _mesa_prim *prim,
- GLuint nr_prims,
- const struct _mesa_index_buffer *ib,
- GLuint min_index,
- GLuint max_index,
- vbo_draw_func draw,
- const struct split_limits *limits );
-
-
-/* Helpers for dealing translating away non-zero min_index.
- */
-GLboolean vbo_all_varyings_in_vbos( const struct gl_client_array *arrays[] );
-GLboolean vbo_any_varyings_in_vbos( const struct gl_client_array *arrays[] );
-
-void vbo_rebase_prims( struct gl_context *ctx,
- const struct gl_client_array *arrays[],
- const struct _mesa_prim *prim,
- GLuint nr_prims,
- const struct _mesa_index_buffer *ib,
- GLuint min_index,
- GLuint max_index,
- vbo_draw_func draw );
-void
-vbo_get_minmax_index(struct gl_context *ctx, const struct _mesa_prim *prim,
- const struct _mesa_index_buffer *ib,
- GLuint *min_index, GLuint *max_index);
-
-void vbo_use_buffer_objects(struct gl_context *ctx);
-
-void vbo_always_unmap_buffers(struct gl_context *ctx);
-
-void vbo_set_draw_func(struct gl_context *ctx, vbo_draw_func func);
-
-void vbo_check_buffers_are_unmapped(struct gl_context *ctx);
-
-
-void GLAPIENTRY
-_es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
-
-void GLAPIENTRY
-_es_Normal3f(GLfloat x, GLfloat y, GLfloat z);
-
-void GLAPIENTRY
-_es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
-
-void GLAPIENTRY
-_es_Materialfv(GLenum face, GLenum pname, const GLfloat *params);
-
-void GLAPIENTRY
-_es_Materialf(GLenum face, GLenum pname, GLfloat param);
-
-void GLAPIENTRY
-_es_VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
-
-void GLAPIENTRY
-_es_VertexAttrib1f(GLuint indx, GLfloat x);
-
-void GLAPIENTRY
-_es_VertexAttrib1fv(GLuint indx, const GLfloat* values);
-
-void GLAPIENTRY
-_es_VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y);
-
-void GLAPIENTRY
-_es_VertexAttrib2fv(GLuint indx, const GLfloat* values);
-
-void GLAPIENTRY
-_es_VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z);
-
-void GLAPIENTRY
-_es_VertexAttrib3fv(GLuint indx, const GLfloat* values);
-
-void GLAPIENTRY
-_es_VertexAttrib4fv(GLuint indx, const GLfloat* values);
-
-#endif
+/*
+ * mesa 3-D graphics library
+ * Version: 6.5
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file vbo_context.h
+ * \brief VBO builder module datatypes and definitions.
+ * \author Keith Whitwell
+ */
+
+
+#ifndef _VBO_H
+#define _VBO_H
+
+#include "main/glheader.h"
+
+struct gl_client_array;
+struct gl_context;
+
+struct _mesa_prim {
+ GLuint mode:8; /**< GL_POINTS, GL_LINES, GL_QUAD_STRIP, etc */
+ GLuint indexed:1;
+ GLuint begin:1;
+ GLuint end:1;
+ GLuint weak:1;
+ GLuint no_current_update:1;
+ GLuint pad:19;
+
+ GLuint start;
+ GLuint count;
+ GLint basevertex;
+ GLsizei num_instances;
+};
+
+/* Would like to call this a "vbo_index_buffer", but this would be
+ * confusing as the indices are not neccessarily yet in a non-null
+ * buffer object.
+ */
+struct _mesa_index_buffer {
+ GLuint count;
+ GLenum type;
+ struct gl_buffer_object *obj;
+ const void *ptr;
+};
+
+
+
+GLboolean _vbo_CreateContext( struct gl_context *ctx );
+void _vbo_DestroyContext( struct gl_context *ctx );
+void _vbo_InvalidateState( struct gl_context *ctx, GLuint new_state );
+
+
+typedef void (*vbo_draw_func)( struct gl_context *ctx,
+ const struct gl_client_array **arrays,
+ const struct _mesa_prim *prims,
+ GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLboolean index_bounds_valid,
+ GLuint min_index,
+ GLuint max_index );
+
+
+
+
+/* Utility function to cope with various constraints on tnl modules or
+ * hardware. This can be used to split an incoming set of arrays and
+ * primitives against the following constraints:
+ * - Maximum number of indices in index buffer.
+ * - Maximum number of vertices referenced by index buffer.
+ * - Maximum hardware vertex buffer size.
+ */
+struct split_limits {
+ GLuint max_verts;
+ GLuint max_indices;
+ GLuint max_vb_size; /* bytes */
+};
+
+
+void vbo_split_prims( struct gl_context *ctx,
+ const struct gl_client_array *arrays[],
+ const struct _mesa_prim *prim,
+ GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLuint min_index,
+ GLuint max_index,
+ vbo_draw_func draw,
+ const struct split_limits *limits );
+
+
+/* Helpers for dealing translating away non-zero min_index.
+ */
+GLboolean vbo_all_varyings_in_vbos( const struct gl_client_array *arrays[] );
+GLboolean vbo_any_varyings_in_vbos( const struct gl_client_array *arrays[] );
+
+void vbo_rebase_prims( struct gl_context *ctx,
+ const struct gl_client_array *arrays[],
+ const struct _mesa_prim *prim,
+ GLuint nr_prims,
+ const struct _mesa_index_buffer *ib,
+ GLuint min_index,
+ GLuint max_index,
+ vbo_draw_func draw );
+void
+vbo_get_minmax_index(struct gl_context *ctx, const struct _mesa_prim *prim,
+ const struct _mesa_index_buffer *ib,
+ GLuint *min_index, GLuint *max_index);
+
+void vbo_use_buffer_objects(struct gl_context *ctx);
+
+void vbo_always_unmap_buffers(struct gl_context *ctx);
+
+void vbo_set_draw_func(struct gl_context *ctx, vbo_draw_func func);
+
+void vbo_check_buffers_are_unmapped(struct gl_context *ctx);
+
+
+void GLAPIENTRY
+_es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
+
+void GLAPIENTRY
+_es_Normal3f(GLfloat x, GLfloat y, GLfloat z);
+
+void GLAPIENTRY
+_es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+
+void GLAPIENTRY
+_es_Materialfv(GLenum face, GLenum pname, const GLfloat *params);
+
+void GLAPIENTRY
+_es_Materialf(GLenum face, GLenum pname, GLfloat param);
+
+void GLAPIENTRY
+_es_VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+
+void GLAPIENTRY
+_es_VertexAttrib1f(GLuint indx, GLfloat x);
+
+void GLAPIENTRY
+_es_VertexAttrib1fv(GLuint indx, const GLfloat* values);
+
+void GLAPIENTRY
+_es_VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y);
+
+void GLAPIENTRY
+_es_VertexAttrib2fv(GLuint indx, const GLfloat* values);
+
+void GLAPIENTRY
+_es_VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z);
+
+void GLAPIENTRY
+_es_VertexAttrib3fv(GLuint indx, const GLfloat* values);
+
+void GLAPIENTRY
+_es_VertexAttrib4fv(GLuint indx, const GLfloat* values);
+
+#endif
diff --git a/mesalib/src/mesa/vbo/vbo_attrib_tmp.h b/mesalib/src/mesa/vbo/vbo_attrib_tmp.h
index c793ce0dc..198b2d85f 100644
--- a/mesalib/src/mesa/vbo/vbo_attrib_tmp.h
+++ b/mesalib/src/mesa/vbo/vbo_attrib_tmp.h
@@ -1,740 +1,740 @@
-/**************************************************************************
-
-Copyright 2002 Tungsten Graphics Inc., Cedar Park, Texas.
-
-All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-on the rights to use, copy, modify, merge, publish, distribute, sub
-license, and/or sell copies of the Software, and to permit persons to whom
-the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice (including the next
-paragraph) shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
-TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
-DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-/* float */
-#define ATTR1FV( A, V ) ATTR( A, 1, (V)[0], 0, 0, 1 )
-#define ATTR2FV( A, V ) ATTR( A, 2, (V)[0], (V)[1], 0, 1 )
-#define ATTR3FV( A, V ) ATTR( A, 3, (V)[0], (V)[1], (V)[2], 1 )
-#define ATTR4FV( A, V ) ATTR( A, 4, (V)[0], (V)[1], (V)[2], (V)[3] )
-
-#define ATTR1F( A, X ) ATTR( A, 1, X, 0, 0, 1 )
-#define ATTR2F( A, X, Y ) ATTR( A, 2, X, Y, 0, 1 )
-#define ATTR3F( A, X, Y, Z ) ATTR( A, 3, X, Y, Z, 1 )
-#define ATTR4F( A, X, Y, Z, W ) ATTR( A, 4, X, Y, Z, W )
-
-/* int */
-#define ATTR2IV( A, V ) ATTR( A, 2, (V)[0], (V)[1], 0, 1 )
-#define ATTR3IV( A, V ) ATTR( A, 3, (V)[0], (V)[1], (V)[2], 1 )
-#define ATTR4IV( A, V ) ATTR( A, 4, (V)[0], (V)[1], (V)[2], (V)[3] )
-
-#define ATTR1I( A, X ) ATTR( A, 1, X, 0, 0, 1 )
-#define ATTR2I( A, X, Y ) ATTR( A, 2, X, Y, 0, 1 )
-#define ATTR3I( A, X, Y, Z ) ATTR( A, 3, X, Y, Z, 1 )
-#define ATTR4I( A, X, Y, Z, W ) ATTR( A, 4, X, Y, Z, W )
-
-
-/* uint */
-#define ATTR2UIV( A, V ) ATTR( A, 2, (V)[0], (V)[1], 0, 1 )
-#define ATTR3UIV( A, V ) ATTR( A, 3, (V)[0], (V)[1], (V)[2], 1 )
-#define ATTR4UIV( A, V ) ATTR( A, 4, (V)[0], (V)[1], (V)[2], (V)[3] )
-
-#define ATTR1UI( A, X ) ATTR( A, 1, X, 0, 0, 1 )
-#define ATTR2UI( A, X, Y ) ATTR( A, 2, X, Y, 0, 1 )
-#define ATTR3UI( A, X, Y, Z ) ATTR( A, 3, X, Y, Z, 1 )
-#define ATTR4UI( A, X, Y, Z, W ) ATTR( A, 4, X, Y, Z, W )
-
-#define MAT_ATTR( A, N, V ) ATTR( A, N, (V)[0], (V)[1], (V)[2], (V)[3] )
-
-
-
-static void GLAPIENTRY
-TAG(Vertex2f)(GLfloat x, GLfloat y)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR2F(VBO_ATTRIB_POS, x, y);
-}
-
-static void GLAPIENTRY
-TAG(Vertex2fv)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR2FV(VBO_ATTRIB_POS, v);
-}
-
-static void GLAPIENTRY
-TAG(Vertex3f)(GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR3F(VBO_ATTRIB_POS, x, y, z);
-}
-
-static void GLAPIENTRY
-TAG(Vertex3fv)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR3FV(VBO_ATTRIB_POS, v);
-}
-
-static void GLAPIENTRY
-TAG(Vertex4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR4F(VBO_ATTRIB_POS, x, y, z, w);
-}
-
-static void GLAPIENTRY
-TAG(Vertex4fv)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR4FV(VBO_ATTRIB_POS, v);
-}
-
-
-
-static void GLAPIENTRY
-TAG(TexCoord1f)(GLfloat x)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR1F(VBO_ATTRIB_TEX0, x);
-}
-
-static void GLAPIENTRY
-TAG(TexCoord1fv)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR1FV(VBO_ATTRIB_TEX0, v);
-}
-
-static void GLAPIENTRY
-TAG(TexCoord2f)(GLfloat x, GLfloat y)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR2F(VBO_ATTRIB_TEX0, x, y);
-}
-
-static void GLAPIENTRY
-TAG(TexCoord2fv)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR2FV(VBO_ATTRIB_TEX0, v);
-}
-
-static void GLAPIENTRY
-TAG(TexCoord3f)(GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR3F(VBO_ATTRIB_TEX0, x, y, z);
-}
-
-static void GLAPIENTRY
-TAG(TexCoord3fv)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR3FV(VBO_ATTRIB_TEX0, v);
-}
-
-static void GLAPIENTRY
-TAG(TexCoord4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR4F(VBO_ATTRIB_TEX0, x, y, z, w);
-}
-
-static void GLAPIENTRY
-TAG(TexCoord4fv)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR4FV(VBO_ATTRIB_TEX0, v);
-}
-
-
-
-static void GLAPIENTRY
-TAG(Normal3f)(GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR3F(VBO_ATTRIB_NORMAL, x, y, z);
-}
-
-static void GLAPIENTRY
-TAG(Normal3fv)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR3FV(VBO_ATTRIB_NORMAL, v);
-}
-
-
-
-static void GLAPIENTRY
-TAG(FogCoordfEXT)(GLfloat x)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR1F(VBO_ATTRIB_FOG, x);
-}
-
-
-
-static void GLAPIENTRY
-TAG(FogCoordfvEXT)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR1FV(VBO_ATTRIB_FOG, v);
-}
-
-static void GLAPIENTRY
-TAG(Color3f)(GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR3F(VBO_ATTRIB_COLOR0, x, y, z);
-}
-
-static void GLAPIENTRY
-TAG(Color3fv)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR3FV(VBO_ATTRIB_COLOR0, v);
-}
-
-static void GLAPIENTRY
-TAG(Color4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR4F(VBO_ATTRIB_COLOR0, x, y, z, w);
-}
-
-static void GLAPIENTRY
-TAG(Color4fv)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR4FV(VBO_ATTRIB_COLOR0, v);
-}
-
-
-
-static void GLAPIENTRY
-TAG(SecondaryColor3fEXT)(GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR3F(VBO_ATTRIB_COLOR1, x, y, z);
-}
-
-static void GLAPIENTRY
-TAG(SecondaryColor3fvEXT)(const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR3FV(VBO_ATTRIB_COLOR1, v);
-}
-
-
-
-static void GLAPIENTRY
-TAG(EdgeFlag)(GLboolean b)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR1F(VBO_ATTRIB_EDGEFLAG, (GLfloat) b);
-}
-
-
-
-static void GLAPIENTRY
-TAG(Indexf)(GLfloat f)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR1F(VBO_ATTRIB_INDEX, f);
-}
-
-static void GLAPIENTRY
-TAG(Indexfv)(const GLfloat * f)
-{
- GET_CURRENT_CONTEXT(ctx);
- ATTR1FV(VBO_ATTRIB_INDEX, f);
-}
-
-
-
-static void GLAPIENTRY
-TAG(MultiTexCoord1f)(GLenum target, GLfloat x)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
- ATTR1F(attr, x);
-}
-
-static void GLAPIENTRY
-TAG(MultiTexCoord1fv)(GLenum target, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
- ATTR1FV(attr, v);
-}
-
-static void GLAPIENTRY
-TAG(MultiTexCoord2f)(GLenum target, GLfloat x, GLfloat y)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
- ATTR2F(attr, x, y);
-}
-
-static void GLAPIENTRY
-TAG(MultiTexCoord2fv)(GLenum target, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
- ATTR2FV(attr, v);
-}
-
-static void GLAPIENTRY
-TAG(MultiTexCoord3f)(GLenum target, GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
- ATTR3F(attr, x, y, z);
-}
-
-static void GLAPIENTRY
-TAG(MultiTexCoord3fv)(GLenum target, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
- ATTR3FV(attr, v);
-}
-
-static void GLAPIENTRY
-TAG(MultiTexCoord4f)(GLenum target, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
- ATTR4F(attr, x, y, z, w);
-}
-
-static void GLAPIENTRY
-TAG(MultiTexCoord4fv)(GLenum target, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
- ATTR4FV(attr, v);
-}
-
-
-
-static void GLAPIENTRY
-TAG(VertexAttrib1fARB)(GLuint index, GLfloat x)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR1F(0, x);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR1F(VBO_ATTRIB_GENERIC0 + index, x);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib1fvARB)(GLuint index, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR1FV(0, v);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR1FV(VBO_ATTRIB_GENERIC0 + index, v);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib2fARB)(GLuint index, GLfloat x, GLfloat y)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR2F(0, x, y);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR2F(VBO_ATTRIB_GENERIC0 + index, x, y);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib2fvARB)(GLuint index, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR2FV(0, v);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR2FV(VBO_ATTRIB_GENERIC0 + index, v);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib3fARB)(GLuint index, GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR3F(0, x, y, z);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR3F(VBO_ATTRIB_GENERIC0 + index, x, y, z);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib3fvARB)(GLuint index, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR3FV(0, v);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR3FV(VBO_ATTRIB_GENERIC0 + index, v);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib4fARB)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR4F(0, x, y, z, w);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR4F(VBO_ATTRIB_GENERIC0 + index, x, y, z, w);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib4fvARB)(GLuint index, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR4FV(0, v);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR4FV(VBO_ATTRIB_GENERIC0 + index, v);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-
-
-/* Integer-valued generic attributes.
- * XXX: the integers just get converted to floats at this time
- */
-static void GLAPIENTRY
-TAG(VertexAttribI1i)(GLuint index, GLint x)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR1I(0, x);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR1I(VBO_ATTRIB_GENERIC0 + index, x);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI2i)(GLuint index, GLint x, GLint y)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR2I(0, x, y);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR2I(VBO_ATTRIB_GENERIC0 + index, x, y);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI3i)(GLuint index, GLint x, GLint y, GLint z)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR3I(0, x, y, z);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR3I(VBO_ATTRIB_GENERIC0 + index, x, y, z);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI4i)(GLuint index, GLint x, GLint y, GLint z, GLint w)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR4I(0, x, y, z, w);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR4I(VBO_ATTRIB_GENERIC0 + index, x, y, z, w);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI2iv)(GLuint index, const GLint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR2IV(0, v);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR2IV(VBO_ATTRIB_GENERIC0 + index, v);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI3iv)(GLuint index, const GLint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR3IV(0, v);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR3IV(VBO_ATTRIB_GENERIC0 + index, v);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI4iv)(GLuint index, const GLint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR4IV(0, v);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR4IV(VBO_ATTRIB_GENERIC0 + index, v);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-
-
-/* Unsigned integer-valued generic attributes.
- * XXX: the integers just get converted to floats at this time
- */
-static void GLAPIENTRY
-TAG(VertexAttribI1ui)(GLuint index, GLuint x)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR1UI(0, x);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR1UI(VBO_ATTRIB_GENERIC0 + index, x);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI2ui)(GLuint index, GLuint x, GLuint y)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR2UI(0, x, y);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR2UI(VBO_ATTRIB_GENERIC0 + index, x, y);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI3ui)(GLuint index, GLuint x, GLuint y, GLuint z)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR3UI(0, x, y, z);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR3UI(VBO_ATTRIB_GENERIC0 + index, x, y, z);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI4ui)(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR4UI(0, x, y, z, w);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR4UI(VBO_ATTRIB_GENERIC0 + index, x, y, z, w);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI2uiv)(GLuint index, const GLuint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR2UIV(0, v);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR2UIV(VBO_ATTRIB_GENERIC0 + index, v);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI3uiv)(GLuint index, const GLuint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR3UIV(0, v);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR3UIV(VBO_ATTRIB_GENERIC0 + index, v);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttribI4uiv)(GLuint index, const GLuint *v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index == 0)
- ATTR4UIV(0, v);
- else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR4UIV(VBO_ATTRIB_GENERIC0 + index, v);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-
-
-/* In addition to supporting NV_vertex_program, these entrypoints are
- * used by the display list and other code specifically because of
- * their property of aliasing with other attributes. (See
- * vbo_save_loopback.c)
- */
-static void GLAPIENTRY
-TAG(VertexAttrib1fNV)(GLuint index, GLfloat x)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index < VBO_ATTRIB_MAX)
- ATTR1F(index, x);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib1fvNV)(GLuint index, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index < VBO_ATTRIB_MAX)
- ATTR1FV(index, v);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib2fNV)(GLuint index, GLfloat x, GLfloat y)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index < VBO_ATTRIB_MAX)
- ATTR2F(index, x, y);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib2fvNV)(GLuint index, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index < VBO_ATTRIB_MAX)
- ATTR2FV(index, v);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib3fNV)(GLuint index, GLfloat x, GLfloat y, GLfloat z)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index < VBO_ATTRIB_MAX)
- ATTR3F(index, x, y, z);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib3fvNV)(GLuint index,
- const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index < VBO_ATTRIB_MAX)
- ATTR3FV(index, v);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib4fNV)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index < VBO_ATTRIB_MAX)
- ATTR4F(index, x, y, z, w);
-}
-
-static void GLAPIENTRY
-TAG(VertexAttrib4fvNV)(GLuint index, const GLfloat * v)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index < VBO_ATTRIB_MAX)
- ATTR4FV(index, v);
-}
-
-
-
-#define MAT( ATTR, N, face, params ) \
-do { \
- if (face != GL_BACK) \
- MAT_ATTR( ATTR, N, params ); /* front */ \
- if (face != GL_FRONT) \
- MAT_ATTR( ATTR + 1, N, params ); /* back */ \
-} while (0)
-
-
-/* Colormaterial conflicts are dealt with later.
- */
-static void GLAPIENTRY
-TAG(Materialfv)(GLenum face, GLenum pname,
- const GLfloat * params)
-{
- GET_CURRENT_CONTEXT(ctx);
- switch (pname) {
- case GL_EMISSION:
- MAT(VBO_ATTRIB_MAT_FRONT_EMISSION, 4, face, params);
- break;
- case GL_AMBIENT:
- MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT, 4, face, params);
- break;
- case GL_DIFFUSE:
- MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE, 4, face, params);
- break;
- case GL_SPECULAR:
- MAT(VBO_ATTRIB_MAT_FRONT_SPECULAR, 4, face, params);
- break;
- case GL_SHININESS:
- MAT(VBO_ATTRIB_MAT_FRONT_SHININESS, 1, face, params);
- break;
- case GL_COLOR_INDEXES:
- MAT(VBO_ATTRIB_MAT_FRONT_INDEXES, 3, face, params);
- break;
- case GL_AMBIENT_AND_DIFFUSE:
- MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT, 4, face, params);
- MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE, 4, face, params);
- break;
- default:
- ERROR(GL_INVALID_ENUM);
- return;
- }
-}
-
-
-#undef ATTR1FV
-#undef ATTR2FV
-#undef ATTR3FV
-#undef ATTR4FV
-
-#undef ATTR1F
-#undef ATTR2F
-#undef ATTR3F
-#undef ATTR4F
-
-#undef MAT
-#undef MAT_ATTR
+/**************************************************************************
+
+Copyright 2002 Tungsten Graphics Inc., Cedar Park, Texas.
+
+All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+on the rights to use, copy, modify, merge, publish, distribute, sub
+license, and/or sell copies of the Software, and to permit persons to whom
+the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+/* float */
+#define ATTR1FV( A, V ) ATTR( A, 1, (V)[0], 0, 0, 1 )
+#define ATTR2FV( A, V ) ATTR( A, 2, (V)[0], (V)[1], 0, 1 )
+#define ATTR3FV( A, V ) ATTR( A, 3, (V)[0], (V)[1], (V)[2], 1 )
+#define ATTR4FV( A, V ) ATTR( A, 4, (V)[0], (V)[1], (V)[2], (V)[3] )
+
+#define ATTR1F( A, X ) ATTR( A, 1, X, 0, 0, 1 )
+#define ATTR2F( A, X, Y ) ATTR( A, 2, X, Y, 0, 1 )
+#define ATTR3F( A, X, Y, Z ) ATTR( A, 3, X, Y, Z, 1 )
+#define ATTR4F( A, X, Y, Z, W ) ATTR( A, 4, X, Y, Z, W )
+
+/* int */
+#define ATTR2IV( A, V ) ATTR( A, 2, (V)[0], (V)[1], 0, 1 )
+#define ATTR3IV( A, V ) ATTR( A, 3, (V)[0], (V)[1], (V)[2], 1 )
+#define ATTR4IV( A, V ) ATTR( A, 4, (V)[0], (V)[1], (V)[2], (V)[3] )
+
+#define ATTR1I( A, X ) ATTR( A, 1, X, 0, 0, 1 )
+#define ATTR2I( A, X, Y ) ATTR( A, 2, X, Y, 0, 1 )
+#define ATTR3I( A, X, Y, Z ) ATTR( A, 3, X, Y, Z, 1 )
+#define ATTR4I( A, X, Y, Z, W ) ATTR( A, 4, X, Y, Z, W )
+
+
+/* uint */
+#define ATTR2UIV( A, V ) ATTR( A, 2, (V)[0], (V)[1], 0, 1 )
+#define ATTR3UIV( A, V ) ATTR( A, 3, (V)[0], (V)[1], (V)[2], 1 )
+#define ATTR4UIV( A, V ) ATTR( A, 4, (V)[0], (V)[1], (V)[2], (V)[3] )
+
+#define ATTR1UI( A, X ) ATTR( A, 1, X, 0, 0, 1 )
+#define ATTR2UI( A, X, Y ) ATTR( A, 2, X, Y, 0, 1 )
+#define ATTR3UI( A, X, Y, Z ) ATTR( A, 3, X, Y, Z, 1 )
+#define ATTR4UI( A, X, Y, Z, W ) ATTR( A, 4, X, Y, Z, W )
+
+#define MAT_ATTR( A, N, V ) ATTR( A, N, (V)[0], (V)[1], (V)[2], (V)[3] )
+
+
+
+static void GLAPIENTRY
+TAG(Vertex2f)(GLfloat x, GLfloat y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR2F(VBO_ATTRIB_POS, x, y);
+}
+
+static void GLAPIENTRY
+TAG(Vertex2fv)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR2FV(VBO_ATTRIB_POS, v);
+}
+
+static void GLAPIENTRY
+TAG(Vertex3f)(GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR3F(VBO_ATTRIB_POS, x, y, z);
+}
+
+static void GLAPIENTRY
+TAG(Vertex3fv)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR3FV(VBO_ATTRIB_POS, v);
+}
+
+static void GLAPIENTRY
+TAG(Vertex4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR4F(VBO_ATTRIB_POS, x, y, z, w);
+}
+
+static void GLAPIENTRY
+TAG(Vertex4fv)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR4FV(VBO_ATTRIB_POS, v);
+}
+
+
+
+static void GLAPIENTRY
+TAG(TexCoord1f)(GLfloat x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR1F(VBO_ATTRIB_TEX0, x);
+}
+
+static void GLAPIENTRY
+TAG(TexCoord1fv)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR1FV(VBO_ATTRIB_TEX0, v);
+}
+
+static void GLAPIENTRY
+TAG(TexCoord2f)(GLfloat x, GLfloat y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR2F(VBO_ATTRIB_TEX0, x, y);
+}
+
+static void GLAPIENTRY
+TAG(TexCoord2fv)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR2FV(VBO_ATTRIB_TEX0, v);
+}
+
+static void GLAPIENTRY
+TAG(TexCoord3f)(GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR3F(VBO_ATTRIB_TEX0, x, y, z);
+}
+
+static void GLAPIENTRY
+TAG(TexCoord3fv)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR3FV(VBO_ATTRIB_TEX0, v);
+}
+
+static void GLAPIENTRY
+TAG(TexCoord4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR4F(VBO_ATTRIB_TEX0, x, y, z, w);
+}
+
+static void GLAPIENTRY
+TAG(TexCoord4fv)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR4FV(VBO_ATTRIB_TEX0, v);
+}
+
+
+
+static void GLAPIENTRY
+TAG(Normal3f)(GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR3F(VBO_ATTRIB_NORMAL, x, y, z);
+}
+
+static void GLAPIENTRY
+TAG(Normal3fv)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR3FV(VBO_ATTRIB_NORMAL, v);
+}
+
+
+
+static void GLAPIENTRY
+TAG(FogCoordfEXT)(GLfloat x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR1F(VBO_ATTRIB_FOG, x);
+}
+
+
+
+static void GLAPIENTRY
+TAG(FogCoordfvEXT)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR1FV(VBO_ATTRIB_FOG, v);
+}
+
+static void GLAPIENTRY
+TAG(Color3f)(GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR3F(VBO_ATTRIB_COLOR0, x, y, z);
+}
+
+static void GLAPIENTRY
+TAG(Color3fv)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR3FV(VBO_ATTRIB_COLOR0, v);
+}
+
+static void GLAPIENTRY
+TAG(Color4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR4F(VBO_ATTRIB_COLOR0, x, y, z, w);
+}
+
+static void GLAPIENTRY
+TAG(Color4fv)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR4FV(VBO_ATTRIB_COLOR0, v);
+}
+
+
+
+static void GLAPIENTRY
+TAG(SecondaryColor3fEXT)(GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR3F(VBO_ATTRIB_COLOR1, x, y, z);
+}
+
+static void GLAPIENTRY
+TAG(SecondaryColor3fvEXT)(const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR3FV(VBO_ATTRIB_COLOR1, v);
+}
+
+
+
+static void GLAPIENTRY
+TAG(EdgeFlag)(GLboolean b)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR1F(VBO_ATTRIB_EDGEFLAG, (GLfloat) b);
+}
+
+
+
+static void GLAPIENTRY
+TAG(Indexf)(GLfloat f)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR1F(VBO_ATTRIB_INDEX, f);
+}
+
+static void GLAPIENTRY
+TAG(Indexfv)(const GLfloat * f)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ATTR1FV(VBO_ATTRIB_INDEX, f);
+}
+
+
+
+static void GLAPIENTRY
+TAG(MultiTexCoord1f)(GLenum target, GLfloat x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
+ ATTR1F(attr, x);
+}
+
+static void GLAPIENTRY
+TAG(MultiTexCoord1fv)(GLenum target, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
+ ATTR1FV(attr, v);
+}
+
+static void GLAPIENTRY
+TAG(MultiTexCoord2f)(GLenum target, GLfloat x, GLfloat y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
+ ATTR2F(attr, x, y);
+}
+
+static void GLAPIENTRY
+TAG(MultiTexCoord2fv)(GLenum target, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
+ ATTR2FV(attr, v);
+}
+
+static void GLAPIENTRY
+TAG(MultiTexCoord3f)(GLenum target, GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
+ ATTR3F(attr, x, y, z);
+}
+
+static void GLAPIENTRY
+TAG(MultiTexCoord3fv)(GLenum target, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
+ ATTR3FV(attr, v);
+}
+
+static void GLAPIENTRY
+TAG(MultiTexCoord4f)(GLenum target, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
+ ATTR4F(attr, x, y, z, w);
+}
+
+static void GLAPIENTRY
+TAG(MultiTexCoord4fv)(GLenum target, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLuint attr = (target & 0x7) + VBO_ATTRIB_TEX0;
+ ATTR4FV(attr, v);
+}
+
+
+
+static void GLAPIENTRY
+TAG(VertexAttrib1fARB)(GLuint index, GLfloat x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR1F(0, x);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR1F(VBO_ATTRIB_GENERIC0 + index, x);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib1fvARB)(GLuint index, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR1FV(0, v);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR1FV(VBO_ATTRIB_GENERIC0 + index, v);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib2fARB)(GLuint index, GLfloat x, GLfloat y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR2F(0, x, y);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR2F(VBO_ATTRIB_GENERIC0 + index, x, y);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib2fvARB)(GLuint index, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR2FV(0, v);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR2FV(VBO_ATTRIB_GENERIC0 + index, v);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib3fARB)(GLuint index, GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR3F(0, x, y, z);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR3F(VBO_ATTRIB_GENERIC0 + index, x, y, z);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib3fvARB)(GLuint index, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR3FV(0, v);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR3FV(VBO_ATTRIB_GENERIC0 + index, v);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib4fARB)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR4F(0, x, y, z, w);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR4F(VBO_ATTRIB_GENERIC0 + index, x, y, z, w);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib4fvARB)(GLuint index, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR4FV(0, v);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR4FV(VBO_ATTRIB_GENERIC0 + index, v);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+
+
+/* Integer-valued generic attributes.
+ * XXX: the integers just get converted to floats at this time
+ */
+static void GLAPIENTRY
+TAG(VertexAttribI1i)(GLuint index, GLint x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR1I(0, x);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR1I(VBO_ATTRIB_GENERIC0 + index, x);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI2i)(GLuint index, GLint x, GLint y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR2I(0, x, y);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR2I(VBO_ATTRIB_GENERIC0 + index, x, y);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI3i)(GLuint index, GLint x, GLint y, GLint z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR3I(0, x, y, z);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR3I(VBO_ATTRIB_GENERIC0 + index, x, y, z);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI4i)(GLuint index, GLint x, GLint y, GLint z, GLint w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR4I(0, x, y, z, w);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR4I(VBO_ATTRIB_GENERIC0 + index, x, y, z, w);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI2iv)(GLuint index, const GLint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR2IV(0, v);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR2IV(VBO_ATTRIB_GENERIC0 + index, v);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI3iv)(GLuint index, const GLint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR3IV(0, v);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR3IV(VBO_ATTRIB_GENERIC0 + index, v);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI4iv)(GLuint index, const GLint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR4IV(0, v);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR4IV(VBO_ATTRIB_GENERIC0 + index, v);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+
+
+/* Unsigned integer-valued generic attributes.
+ * XXX: the integers just get converted to floats at this time
+ */
+static void GLAPIENTRY
+TAG(VertexAttribI1ui)(GLuint index, GLuint x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR1UI(0, x);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR1UI(VBO_ATTRIB_GENERIC0 + index, x);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI2ui)(GLuint index, GLuint x, GLuint y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR2UI(0, x, y);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR2UI(VBO_ATTRIB_GENERIC0 + index, x, y);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI3ui)(GLuint index, GLuint x, GLuint y, GLuint z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR3UI(0, x, y, z);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR3UI(VBO_ATTRIB_GENERIC0 + index, x, y, z);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI4ui)(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR4UI(0, x, y, z, w);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR4UI(VBO_ATTRIB_GENERIC0 + index, x, y, z, w);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI2uiv)(GLuint index, const GLuint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR2UIV(0, v);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR2UIV(VBO_ATTRIB_GENERIC0 + index, v);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI3uiv)(GLuint index, const GLuint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR3UIV(0, v);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR3UIV(VBO_ATTRIB_GENERIC0 + index, v);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttribI4uiv)(GLuint index, const GLuint *v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index == 0)
+ ATTR4UIV(0, v);
+ else if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR4UIV(VBO_ATTRIB_GENERIC0 + index, v);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+
+
+/* In addition to supporting NV_vertex_program, these entrypoints are
+ * used by the display list and other code specifically because of
+ * their property of aliasing with other attributes. (See
+ * vbo_save_loopback.c)
+ */
+static void GLAPIENTRY
+TAG(VertexAttrib1fNV)(GLuint index, GLfloat x)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index < VBO_ATTRIB_MAX)
+ ATTR1F(index, x);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib1fvNV)(GLuint index, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index < VBO_ATTRIB_MAX)
+ ATTR1FV(index, v);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib2fNV)(GLuint index, GLfloat x, GLfloat y)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index < VBO_ATTRIB_MAX)
+ ATTR2F(index, x, y);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib2fvNV)(GLuint index, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index < VBO_ATTRIB_MAX)
+ ATTR2FV(index, v);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib3fNV)(GLuint index, GLfloat x, GLfloat y, GLfloat z)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index < VBO_ATTRIB_MAX)
+ ATTR3F(index, x, y, z);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib3fvNV)(GLuint index,
+ const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index < VBO_ATTRIB_MAX)
+ ATTR3FV(index, v);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib4fNV)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index < VBO_ATTRIB_MAX)
+ ATTR4F(index, x, y, z, w);
+}
+
+static void GLAPIENTRY
+TAG(VertexAttrib4fvNV)(GLuint index, const GLfloat * v)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index < VBO_ATTRIB_MAX)
+ ATTR4FV(index, v);
+}
+
+
+
+#define MAT( ATTR, N, face, params ) \
+do { \
+ if (face != GL_BACK) \
+ MAT_ATTR( ATTR, N, params ); /* front */ \
+ if (face != GL_FRONT) \
+ MAT_ATTR( ATTR + 1, N, params ); /* back */ \
+} while (0)
+
+
+/* Colormaterial conflicts are dealt with later.
+ */
+static void GLAPIENTRY
+TAG(Materialfv)(GLenum face, GLenum pname,
+ const GLfloat * params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ switch (pname) {
+ case GL_EMISSION:
+ MAT(VBO_ATTRIB_MAT_FRONT_EMISSION, 4, face, params);
+ break;
+ case GL_AMBIENT:
+ MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT, 4, face, params);
+ break;
+ case GL_DIFFUSE:
+ MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE, 4, face, params);
+ break;
+ case GL_SPECULAR:
+ MAT(VBO_ATTRIB_MAT_FRONT_SPECULAR, 4, face, params);
+ break;
+ case GL_SHININESS:
+ MAT(VBO_ATTRIB_MAT_FRONT_SHININESS, 1, face, params);
+ break;
+ case GL_COLOR_INDEXES:
+ MAT(VBO_ATTRIB_MAT_FRONT_INDEXES, 3, face, params);
+ break;
+ case GL_AMBIENT_AND_DIFFUSE:
+ MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT, 4, face, params);
+ MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE, 4, face, params);
+ break;
+ default:
+ ERROR(GL_INVALID_ENUM);
+ return;
+ }
+}
+
+
+#undef ATTR1FV
+#undef ATTR2FV
+#undef ATTR3FV
+#undef ATTR4FV
+
+#undef ATTR1F
+#undef ATTR2F
+#undef ATTR3F
+#undef ATTR4F
+
+#undef MAT
+#undef MAT_ATTR
diff --git a/mesalib/src/mesa/vbo/vbo_exec.h b/mesalib/src/mesa/vbo/vbo_exec.h
index d52a557e0..c8e509285 100644
--- a/mesalib/src/mesa/vbo/vbo_exec.h
+++ b/mesalib/src/mesa/vbo/vbo_exec.h
@@ -1,204 +1,204 @@
-/**************************************************************************
-
-Copyright 2002 Tungsten Graphics Inc., Cedar Park, Texas.
-
-All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-on the rights to use, copy, modify, merge, publish, distribute, sub
-license, and/or sell copies of the Software, and to permit persons to whom
-the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice (including the next
-paragraph) shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
-TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
-DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-/*
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- *
- */
-
-#ifndef __VBO_EXEC_H__
-#define __VBO_EXEC_H__
-
-#include "main/mfeatures.h"
-#include "main/mtypes.h"
-#include "vbo.h"
-#include "vbo_attrib.h"
-
-
-/**
- * Max number of primitives (number of glBegin/End pairs) per VBO.
- */
-#define VBO_MAX_PRIM 64
-
-
-/**
- * Size of the VBO to use for glBegin/glVertex/glEnd-style rendering.
- */
-#define VBO_VERT_BUFFER_SIZE (1024*64) /* bytes */
-
-
-/** Current vertex program mode */
-enum vp_mode {
- VP_NONE, /**< fixed function */
- VP_NV, /**< NV vertex program */
- VP_ARB /**< ARB vertex program or GLSL vertex shader */
-};
-
-
-struct vbo_exec_eval1_map {
- struct gl_1d_map *map;
- GLuint sz;
-};
-
-struct vbo_exec_eval2_map {
- struct gl_2d_map *map;
- GLuint sz;
-};
-
-
-
-struct vbo_exec_copied_vtx {
- GLfloat buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS];
- GLuint nr;
-};
-
-
-typedef void (*vbo_attrfv_func)( const GLfloat * );
-
-
-struct vbo_exec_context
-{
- struct gl_context *ctx;
- GLvertexformat vtxfmt;
-
- struct {
- struct gl_buffer_object *bufferobj;
-
- GLuint vertex_size; /* in dwords */
-
- struct _mesa_prim prim[VBO_MAX_PRIM];
- GLuint prim_count;
-
- GLfloat *buffer_map;
- GLfloat *buffer_ptr; /* cursor, points into buffer */
- GLuint buffer_used; /* in bytes */
- GLfloat vertex[VBO_ATTRIB_MAX*4]; /* current vertex */
-
- GLuint vert_count;
- GLuint max_vert;
- struct vbo_exec_copied_vtx copied;
-
- GLubyte attrsz[VBO_ATTRIB_MAX];
- GLubyte active_sz[VBO_ATTRIB_MAX];
-
- GLfloat *attrptr[VBO_ATTRIB_MAX];
- struct gl_client_array arrays[VERT_ATTRIB_MAX];
-
- /* According to program mode, the values above plus current
- * values are squashed down to the 32 attributes passed to the
- * vertex program below:
- */
- enum vp_mode program_mode;
- GLuint enabled_flags;
- const struct gl_client_array *inputs[VERT_ATTRIB_MAX];
- } vtx;
-
-
- struct {
- GLboolean recalculate_maps;
- struct vbo_exec_eval1_map map1[VERT_ATTRIB_MAX];
- struct vbo_exec_eval2_map map2[VERT_ATTRIB_MAX];
- } eval;
-
- struct {
- enum vp_mode program_mode;
- GLuint enabled_flags;
- GLuint array_obj;
-
- /* These just mirror the current arrayobj (todo: make arrayobj
- * look like this and remove the mirror):
- */
- const struct gl_client_array *legacy_array[16];
- const struct gl_client_array *generic_array[16];
-
- /* Arrays and current values manipulated according to program
- * mode, etc. These are the attributes as seen by vertex
- * programs:
- */
- const struct gl_client_array *inputs[VERT_ATTRIB_MAX];
- } array;
-
- /* Which flags to set in vbo_exec_BeginVertices() */
- GLbitfield begin_vertices_flags;
-
-#ifdef DEBUG
- GLint flush_call_depth;
-#endif
-};
-
-
-
-/* External API:
- */
-void vbo_exec_init( struct gl_context *ctx );
-void vbo_exec_destroy( struct gl_context *ctx );
-void vbo_exec_invalidate_state( struct gl_context *ctx, GLuint new_state );
-
-void vbo_exec_BeginVertices( struct gl_context *ctx );
-void vbo_exec_FlushVertices( struct gl_context *ctx, GLuint flags );
-
-
-/* Internal functions:
- */
-void vbo_exec_array_init( struct vbo_exec_context *exec );
-void vbo_exec_array_destroy( struct vbo_exec_context *exec );
-
-
-void vbo_exec_vtx_init( struct vbo_exec_context *exec );
-void vbo_exec_vtx_destroy( struct vbo_exec_context *exec );
-
-#if FEATURE_beginend
-
-void vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap );
-void vbo_exec_vtx_map( struct vbo_exec_context *exec );
-
-#else /* FEATURE_beginend */
-
-static INLINE void
-vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
-{
-}
-
-static INLINE void
-vbo_exec_vtx_map( struct vbo_exec_context *exec )
-{
-}
-
-#endif /* FEATURE_beginend */
-
-void vbo_exec_vtx_wrap( struct vbo_exec_context *exec );
-
-void vbo_exec_eval_update( struct vbo_exec_context *exec );
-
-void vbo_exec_do_EvalCoord2f( struct vbo_exec_context *exec,
- GLfloat u, GLfloat v );
-
-void vbo_exec_do_EvalCoord1f( struct vbo_exec_context *exec,
- GLfloat u);
-
-#endif
+/**************************************************************************
+
+Copyright 2002 Tungsten Graphics Inc., Cedar Park, Texas.
+
+All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+on the rights to use, copy, modify, merge, publish, distribute, sub
+license, and/or sell copies of the Software, and to permit persons to whom
+the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ *
+ */
+
+#ifndef __VBO_EXEC_H__
+#define __VBO_EXEC_H__
+
+#include "main/mfeatures.h"
+#include "main/mtypes.h"
+#include "vbo.h"
+#include "vbo_attrib.h"
+
+
+/**
+ * Max number of primitives (number of glBegin/End pairs) per VBO.
+ */
+#define VBO_MAX_PRIM 64
+
+
+/**
+ * Size of the VBO to use for glBegin/glVertex/glEnd-style rendering.
+ */
+#define VBO_VERT_BUFFER_SIZE (1024*64) /* bytes */
+
+
+/** Current vertex program mode */
+enum vp_mode {
+ VP_NONE, /**< fixed function */
+ VP_NV, /**< NV vertex program */
+ VP_ARB /**< ARB vertex program or GLSL vertex shader */
+};
+
+
+struct vbo_exec_eval1_map {
+ struct gl_1d_map *map;
+ GLuint sz;
+};
+
+struct vbo_exec_eval2_map {
+ struct gl_2d_map *map;
+ GLuint sz;
+};
+
+
+
+struct vbo_exec_copied_vtx {
+ GLfloat buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS];
+ GLuint nr;
+};
+
+
+typedef void (*vbo_attrfv_func)( const GLfloat * );
+
+
+struct vbo_exec_context
+{
+ struct gl_context *ctx;
+ GLvertexformat vtxfmt;
+
+ struct {
+ struct gl_buffer_object *bufferobj;
+
+ GLuint vertex_size; /* in dwords */
+
+ struct _mesa_prim prim[VBO_MAX_PRIM];
+ GLuint prim_count;
+
+ GLfloat *buffer_map;
+ GLfloat *buffer_ptr; /* cursor, points into buffer */
+ GLuint buffer_used; /* in bytes */
+ GLfloat vertex[VBO_ATTRIB_MAX*4]; /* current vertex */
+
+ GLuint vert_count;
+ GLuint max_vert;
+ struct vbo_exec_copied_vtx copied;
+
+ GLubyte attrsz[VBO_ATTRIB_MAX];
+ GLubyte active_sz[VBO_ATTRIB_MAX];
+
+ GLfloat *attrptr[VBO_ATTRIB_MAX];
+ struct gl_client_array arrays[VERT_ATTRIB_MAX];
+
+ /* According to program mode, the values above plus current
+ * values are squashed down to the 32 attributes passed to the
+ * vertex program below:
+ */
+ enum vp_mode program_mode;
+ GLuint enabled_flags;
+ const struct gl_client_array *inputs[VERT_ATTRIB_MAX];
+ } vtx;
+
+
+ struct {
+ GLboolean recalculate_maps;
+ struct vbo_exec_eval1_map map1[VERT_ATTRIB_MAX];
+ struct vbo_exec_eval2_map map2[VERT_ATTRIB_MAX];
+ } eval;
+
+ struct {
+ enum vp_mode program_mode;
+ GLuint enabled_flags;
+ GLuint array_obj;
+
+ /* These just mirror the current arrayobj (todo: make arrayobj
+ * look like this and remove the mirror):
+ */
+ const struct gl_client_array *legacy_array[16];
+ const struct gl_client_array *generic_array[16];
+
+ /* Arrays and current values manipulated according to program
+ * mode, etc. These are the attributes as seen by vertex
+ * programs:
+ */
+ const struct gl_client_array *inputs[VERT_ATTRIB_MAX];
+ } array;
+
+ /* Which flags to set in vbo_exec_BeginVertices() */
+ GLbitfield begin_vertices_flags;
+
+#ifdef DEBUG
+ GLint flush_call_depth;
+#endif
+};
+
+
+
+/* External API:
+ */
+void vbo_exec_init( struct gl_context *ctx );
+void vbo_exec_destroy( struct gl_context *ctx );
+void vbo_exec_invalidate_state( struct gl_context *ctx, GLuint new_state );
+
+void vbo_exec_BeginVertices( struct gl_context *ctx );
+void vbo_exec_FlushVertices( struct gl_context *ctx, GLuint flags );
+
+
+/* Internal functions:
+ */
+void vbo_exec_array_init( struct vbo_exec_context *exec );
+void vbo_exec_array_destroy( struct vbo_exec_context *exec );
+
+
+void vbo_exec_vtx_init( struct vbo_exec_context *exec );
+void vbo_exec_vtx_destroy( struct vbo_exec_context *exec );
+
+#if FEATURE_beginend
+
+void vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap );
+void vbo_exec_vtx_map( struct vbo_exec_context *exec );
+
+#else /* FEATURE_beginend */
+
+static INLINE void
+vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
+{
+}
+
+static INLINE void
+vbo_exec_vtx_map( struct vbo_exec_context *exec )
+{
+}
+
+#endif /* FEATURE_beginend */
+
+void vbo_exec_vtx_wrap( struct vbo_exec_context *exec );
+
+void vbo_exec_eval_update( struct vbo_exec_context *exec );
+
+void vbo_exec_do_EvalCoord2f( struct vbo_exec_context *exec,
+ GLfloat u, GLfloat v );
+
+void vbo_exec_do_EvalCoord1f( struct vbo_exec_context *exec,
+ GLfloat u);
+
+#endif
diff --git a/mesalib/src/mesa/vbo/vbo_exec_api.c b/mesalib/src/mesa/vbo/vbo_exec_api.c
index fcd544de7..790310903 100644
--- a/mesalib/src/mesa/vbo/vbo_exec_api.c
+++ b/mesalib/src/mesa/vbo/vbo_exec_api.c
@@ -1,1121 +1,1121 @@
-/**************************************************************************
-
-Copyright 2002-2008 Tungsten Graphics Inc., Cedar Park, Texas.
-
-All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-on the rights to use, copy, modify, merge, publish, distribute, sub
-license, and/or sell copies of the Software, and to permit persons to whom
-the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice (including the next
-paragraph) shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
-TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
-DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-/*
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- */
-
-#include "main/glheader.h"
-#include "main/bufferobj.h"
-#include "main/context.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-#include "main/vtxfmt.h"
-#include "main/dlist.h"
-#include "main/eval.h"
-#include "main/state.h"
-#include "main/light.h"
-#include "main/api_arrayelt.h"
-#include "main/api_noop.h"
-#include "main/dispatch.h"
-
-#include "vbo_context.h"
-
-#ifdef ERROR
-#undef ERROR
-#endif
-
-
-/** ID/name for immediate-mode VBO */
-#define IMM_BUFFER_NAME 0xaabbccdd
-
-
-static void reset_attrfv( struct vbo_exec_context *exec );
-
-
-/**
- * Close off the last primitive, execute the buffer, restart the
- * primitive.
- */
-static void vbo_exec_wrap_buffers( struct vbo_exec_context *exec )
-{
- if (exec->vtx.prim_count == 0) {
- exec->vtx.copied.nr = 0;
- exec->vtx.vert_count = 0;
- exec->vtx.buffer_ptr = exec->vtx.buffer_map;
- }
- else {
- GLuint last_begin = exec->vtx.prim[exec->vtx.prim_count-1].begin;
- GLuint last_count;
-
- if (exec->ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
- GLint i = exec->vtx.prim_count - 1;
- assert(i >= 0);
- exec->vtx.prim[i].count = (exec->vtx.vert_count -
- exec->vtx.prim[i].start);
- }
-
- last_count = exec->vtx.prim[exec->vtx.prim_count-1].count;
-
- /* Execute the buffer and save copied vertices.
- */
- if (exec->vtx.vert_count)
- vbo_exec_vtx_flush( exec, GL_FALSE );
- else {
- exec->vtx.prim_count = 0;
- exec->vtx.copied.nr = 0;
- }
-
- /* Emit a glBegin to start the new list.
- */
- assert(exec->vtx.prim_count == 0);
-
- if (exec->ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
- exec->vtx.prim[0].mode = exec->ctx->Driver.CurrentExecPrimitive;
- exec->vtx.prim[0].start = 0;
- exec->vtx.prim[0].count = 0;
- exec->vtx.prim_count++;
-
- if (exec->vtx.copied.nr == last_count)
- exec->vtx.prim[0].begin = last_begin;
- }
- }
-}
-
-
-/**
- * Deal with buffer wrapping where provoked by the vertex buffer
- * filling up, as opposed to upgrade_vertex().
- */
-void vbo_exec_vtx_wrap( struct vbo_exec_context *exec )
-{
- GLfloat *data = exec->vtx.copied.buffer;
- GLuint i;
-
- /* Run pipeline on current vertices, copy wrapped vertices
- * to exec->vtx.copied.
- */
- vbo_exec_wrap_buffers( exec );
-
- /* Copy stored stored vertices to start of new list.
- */
- assert(exec->vtx.max_vert - exec->vtx.vert_count > exec->vtx.copied.nr);
-
- for (i = 0 ; i < exec->vtx.copied.nr ; i++) {
- memcpy( exec->vtx.buffer_ptr, data,
- exec->vtx.vertex_size * sizeof(GLfloat));
- exec->vtx.buffer_ptr += exec->vtx.vertex_size;
- data += exec->vtx.vertex_size;
- exec->vtx.vert_count++;
- }
-
- exec->vtx.copied.nr = 0;
-}
-
-
-/**
- * Copy the active vertex's values to the ctx->Current fields.
- */
-static void vbo_exec_copy_to_current( struct vbo_exec_context *exec )
-{
- struct gl_context *ctx = exec->ctx;
- struct vbo_context *vbo = vbo_context(ctx);
- GLuint i;
-
- for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
- if (exec->vtx.attrsz[i]) {
- /* Note: the exec->vtx.current[i] pointers point into the
- * ctx->Current.Attrib and ctx->Light.Material.Attrib arrays.
- */
- GLfloat *current = (GLfloat *)vbo->currval[i].Ptr;
- GLfloat tmp[4];
-
- COPY_CLEAN_4V(tmp,
- exec->vtx.attrsz[i],
- exec->vtx.attrptr[i]);
-
- if (memcmp(current, tmp, sizeof(tmp)) != 0) {
- memcpy(current, tmp, sizeof(tmp));
-
- /* Given that we explicitly state size here, there is no need
- * for the COPY_CLEAN above, could just copy 16 bytes and be
- * done. The only problem is when Mesa accesses ctx->Current
- * directly.
- */
- vbo->currval[i].Size = exec->vtx.attrsz[i];
-
- /* This triggers rather too much recalculation of Mesa state
- * that doesn't get used (eg light positions).
- */
- if (i >= VBO_ATTRIB_MAT_FRONT_AMBIENT &&
- i <= VBO_ATTRIB_MAT_BACK_INDEXES)
- ctx->NewState |= _NEW_LIGHT;
-
- ctx->NewState |= _NEW_CURRENT_ATTRIB;
- }
- }
- }
-
- /* Colormaterial -- this kindof sucks.
- */
- if (ctx->Light.ColorMaterialEnabled &&
- exec->vtx.attrsz[VBO_ATTRIB_COLOR0]) {
- _mesa_update_color_material(ctx,
- ctx->Current.Attrib[VBO_ATTRIB_COLOR0]);
- }
-}
-
-
-/**
- * Copy current vertex attribute values into the current vertex.
- */
-static void
-vbo_exec_copy_from_current(struct vbo_exec_context *exec)
-{
- struct gl_context *ctx = exec->ctx;
- struct vbo_context *vbo = vbo_context(ctx);
- GLint i;
-
- for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
- const GLfloat *current = (GLfloat *) vbo->currval[i].Ptr;
- switch (exec->vtx.attrsz[i]) {
- case 4: exec->vtx.attrptr[i][3] = current[3];
- case 3: exec->vtx.attrptr[i][2] = current[2];
- case 2: exec->vtx.attrptr[i][1] = current[1];
- case 1: exec->vtx.attrptr[i][0] = current[0];
- break;
- }
- }
-}
-
-
-/**
- * Flush existing data, set new attrib size, replay copied vertices.
- * This is called when we transition from a small vertex attribute size
- * to a larger one. Ex: glTexCoord2f -> glTexCoord4f.
- * We need to go back over the previous 2-component texcoords and insert
- * zero and one values.
- */
-static void
-vbo_exec_wrap_upgrade_vertex(struct vbo_exec_context *exec,
- GLuint attr, GLuint newSize )
-{
- struct gl_context *ctx = exec->ctx;
- struct vbo_context *vbo = vbo_context(ctx);
- const GLint lastcount = exec->vtx.vert_count;
- GLfloat *old_attrptr[VBO_ATTRIB_MAX];
- const GLuint old_vtx_size = exec->vtx.vertex_size; /* floats per vertex */
- const GLuint oldSize = exec->vtx.attrsz[attr];
- GLuint i;
-
- /* Run pipeline on current vertices, copy wrapped vertices
- * to exec->vtx.copied.
- */
- vbo_exec_wrap_buffers( exec );
-
- if (unlikely(exec->vtx.copied.nr)) {
- /* We're in the middle of a primitive, keep the old vertex
- * format around to be able to translate the copied vertices to
- * the new format.
- */
- memcpy(old_attrptr, exec->vtx.attrptr, sizeof(old_attrptr));
- }
-
- if (unlikely(oldSize)) {
- /* Do a COPY_TO_CURRENT to ensure back-copying works for the
- * case when the attribute already exists in the vertex and is
- * having its size increased.
- */
- vbo_exec_copy_to_current( exec );
- }
-
- /* Heuristic: Attempt to isolate attributes received outside
- * begin/end so that they don't bloat the vertices.
- */
- if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END &&
- !oldSize && lastcount > 8 && exec->vtx.vertex_size) {
- vbo_exec_copy_to_current( exec );
- reset_attrfv( exec );
- }
-
- /* Fix up sizes:
- */
- exec->vtx.attrsz[attr] = newSize;
- exec->vtx.vertex_size += newSize - oldSize;
- exec->vtx.max_vert = ((VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) /
- (exec->vtx.vertex_size * sizeof(GLfloat)));
- exec->vtx.vert_count = 0;
- exec->vtx.buffer_ptr = exec->vtx.buffer_map;
-
- if (unlikely(oldSize)) {
- /* Size changed, recalculate all the attrptr[] values
- */
- GLfloat *tmp = exec->vtx.vertex;
-
- for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) {
- if (exec->vtx.attrsz[i]) {
- exec->vtx.attrptr[i] = tmp;
- tmp += exec->vtx.attrsz[i];
- }
- else
- exec->vtx.attrptr[i] = NULL; /* will not be dereferenced */
- }
-
- /* Copy from current to repopulate the vertex with correct
- * values.
- */
- vbo_exec_copy_from_current( exec );
- }
- else {
- /* Just have to append the new attribute at the end */
- exec->vtx.attrptr[attr] = exec->vtx.vertex +
- exec->vtx.vertex_size - newSize;
- }
-
- /* Replay stored vertices to translate them
- * to new format here.
- *
- * -- No need to replay - just copy piecewise
- */
- if (unlikely(exec->vtx.copied.nr)) {
- GLfloat *data = exec->vtx.copied.buffer;
- GLfloat *dest = exec->vtx.buffer_ptr;
- GLuint j;
-
- assert(exec->vtx.buffer_ptr == exec->vtx.buffer_map);
-
- for (i = 0 ; i < exec->vtx.copied.nr ; i++) {
- for (j = 0 ; j < VBO_ATTRIB_MAX ; j++) {
- GLuint sz = exec->vtx.attrsz[j];
-
- if (sz) {
- GLint old_offset = old_attrptr[j] - exec->vtx.vertex;
- GLint new_offset = exec->vtx.attrptr[j] - exec->vtx.vertex;
-
- if (j == attr) {
- if (oldSize) {
- GLfloat tmp[4];
- COPY_CLEAN_4V(tmp, oldSize, data + old_offset);
- COPY_SZ_4V(dest + new_offset, newSize, tmp);
- } else {
- GLfloat *current = (GLfloat *)vbo->currval[j].Ptr;
- COPY_SZ_4V(dest + new_offset, sz, current);
- }
- }
- else {
- COPY_SZ_4V(dest + new_offset, sz, data + old_offset);
- }
- }
- }
-
- data += old_vtx_size;
- dest += exec->vtx.vertex_size;
- }
-
- exec->vtx.buffer_ptr = dest;
- exec->vtx.vert_count += exec->vtx.copied.nr;
- exec->vtx.copied.nr = 0;
- }
-}
-
-
-/**
- * This is when a vertex attribute transitions to a different size.
- * For example, we saw a bunch of glTexCoord2f() calls and now we got a
- * glTexCoord4f() call. We promote the array from size=2 to size=4.
- */
-static void
-vbo_exec_fixup_vertex(struct gl_context *ctx, GLuint attr, GLuint newSize)
-{
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
-
- if (newSize > exec->vtx.attrsz[attr]) {
- /* New size is larger. Need to flush existing vertices and get
- * an enlarged vertex format.
- */
- vbo_exec_wrap_upgrade_vertex( exec, attr, newSize );
- }
- else if (newSize < exec->vtx.active_sz[attr]) {
- static const GLfloat id[4] = { 0, 0, 0, 1 };
- GLuint i;
-
- /* New size is smaller - just need to fill in some
- * zeros. Don't need to flush or wrap.
- */
- for (i = newSize; i <= exec->vtx.attrsz[attr]; i++)
- exec->vtx.attrptr[attr][i-1] = id[i-1];
- }
-
- exec->vtx.active_sz[attr] = newSize;
-
- /* Does setting NeedFlush belong here? Necessitates resetting
- * vtxfmt on each flush (otherwise flags won't get reset
- * afterwards).
- */
- if (attr == 0)
- ctx->Driver.NeedFlush |= FLUSH_STORED_VERTICES;
-}
-
-
-/**
- * This macro is used to implement all the glVertex, glColor, glTexCoord,
- * glVertexAttrib, etc functions.
- */
-#define ATTR( A, N, V0, V1, V2, V3 ) \
-do { \
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec; \
- \
- if (unlikely(!(ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT))) \
- ctx->Driver.BeginVertices( ctx ); \
- \
- if (unlikely(exec->vtx.active_sz[A] != N)) \
- vbo_exec_fixup_vertex(ctx, A, N); \
- \
- { \
- GLfloat *dest = exec->vtx.attrptr[A]; \
- if (N>0) dest[0] = V0; \
- if (N>1) dest[1] = V1; \
- if (N>2) dest[2] = V2; \
- if (N>3) dest[3] = V3; \
- } \
- \
- if ((A) == 0) { \
- /* This is a glVertex call */ \
- GLuint i; \
- \
- for (i = 0; i < exec->vtx.vertex_size; i++) \
- exec->vtx.buffer_ptr[i] = exec->vtx.vertex[i]; \
- \
- exec->vtx.buffer_ptr += exec->vtx.vertex_size; \
- \
- /* Set FLUSH_STORED_VERTICES to indicate that there's now */ \
- /* something to draw (not just updating a color or texcoord).*/ \
- ctx->Driver.NeedFlush |= FLUSH_STORED_VERTICES; \
- \
- if (++exec->vtx.vert_count >= exec->vtx.max_vert) \
- vbo_exec_vtx_wrap( exec ); \
- } \
-} while (0)
-
-
-#define ERROR(err) _mesa_error( ctx, err, __FUNCTION__ )
-#define TAG(x) vbo_##x
-
-#include "vbo_attrib_tmp.h"
-
-
-#if FEATURE_beginend
-
-
-#if FEATURE_evaluators
-
-static void GLAPIENTRY vbo_exec_EvalCoord1f( GLfloat u )
-{
- GET_CURRENT_CONTEXT( ctx );
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
-
- {
- GLint i;
- if (exec->eval.recalculate_maps)
- vbo_exec_eval_update( exec );
-
- for (i = 0; i <= VBO_ATTRIB_TEX7; i++) {
- if (exec->eval.map1[i].map)
- if (exec->vtx.active_sz[i] != exec->eval.map1[i].sz)
- vbo_exec_fixup_vertex( ctx, i, exec->eval.map1[i].sz );
- }
- }
-
-
- memcpy( exec->vtx.copied.buffer, exec->vtx.vertex,
- exec->vtx.vertex_size * sizeof(GLfloat));
-
- vbo_exec_do_EvalCoord1f( exec, u );
-
- memcpy( exec->vtx.vertex, exec->vtx.copied.buffer,
- exec->vtx.vertex_size * sizeof(GLfloat));
-}
-
-static void GLAPIENTRY vbo_exec_EvalCoord2f( GLfloat u, GLfloat v )
-{
- GET_CURRENT_CONTEXT( ctx );
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
-
- {
- GLint i;
- if (exec->eval.recalculate_maps)
- vbo_exec_eval_update( exec );
-
- for (i = 0; i <= VBO_ATTRIB_TEX7; i++) {
- if (exec->eval.map2[i].map)
- if (exec->vtx.active_sz[i] != exec->eval.map2[i].sz)
- vbo_exec_fixup_vertex( ctx, i, exec->eval.map2[i].sz );
- }
-
- if (ctx->Eval.AutoNormal)
- if (exec->vtx.active_sz[VBO_ATTRIB_NORMAL] != 3)
- vbo_exec_fixup_vertex( ctx, VBO_ATTRIB_NORMAL, 3 );
- }
-
- memcpy( exec->vtx.copied.buffer, exec->vtx.vertex,
- exec->vtx.vertex_size * sizeof(GLfloat));
-
- vbo_exec_do_EvalCoord2f( exec, u, v );
-
- memcpy( exec->vtx.vertex, exec->vtx.copied.buffer,
- exec->vtx.vertex_size * sizeof(GLfloat));
-}
-
-static void GLAPIENTRY vbo_exec_EvalCoord1fv( const GLfloat *u )
-{
- vbo_exec_EvalCoord1f( u[0] );
-}
-
-static void GLAPIENTRY vbo_exec_EvalCoord2fv( const GLfloat *u )
-{
- vbo_exec_EvalCoord2f( u[0], u[1] );
-}
-
-static void GLAPIENTRY vbo_exec_EvalPoint1( GLint i )
-{
- GET_CURRENT_CONTEXT( ctx );
- GLfloat du = ((ctx->Eval.MapGrid1u2 - ctx->Eval.MapGrid1u1) /
- (GLfloat) ctx->Eval.MapGrid1un);
- GLfloat u = i * du + ctx->Eval.MapGrid1u1;
-
- vbo_exec_EvalCoord1f( u );
-}
-
-
-static void GLAPIENTRY vbo_exec_EvalPoint2( GLint i, GLint j )
-{
- GET_CURRENT_CONTEXT( ctx );
- GLfloat du = ((ctx->Eval.MapGrid2u2 - ctx->Eval.MapGrid2u1) /
- (GLfloat) ctx->Eval.MapGrid2un);
- GLfloat dv = ((ctx->Eval.MapGrid2v2 - ctx->Eval.MapGrid2v1) /
- (GLfloat) ctx->Eval.MapGrid2vn);
- GLfloat u = i * du + ctx->Eval.MapGrid2u1;
- GLfloat v = j * dv + ctx->Eval.MapGrid2v1;
-
- vbo_exec_EvalCoord2f( u, v );
-}
-
-/* use noop eval mesh */
-#define vbo_exec_EvalMesh1 _mesa_noop_EvalMesh1
-#define vbo_exec_EvalMesh2 _mesa_noop_EvalMesh2
-
-#endif /* FEATURE_evaluators */
-
-
-/**
- * Flush (draw) vertices.
- * \param unmap - leave VBO unmapped after flushing?
- */
-static void
-vbo_exec_FlushVertices_internal(struct vbo_exec_context *exec, GLboolean unmap)
-{
- if (exec->vtx.vert_count || unmap) {
- vbo_exec_vtx_flush( exec, unmap );
- }
-
- if (exec->vtx.vertex_size) {
- vbo_exec_copy_to_current( exec );
- reset_attrfv( exec );
- }
-}
-
-
-/**
- * Called via glBegin.
- */
-static void GLAPIENTRY vbo_exec_Begin( GLenum mode )
-{
- GET_CURRENT_CONTEXT( ctx );
-
- if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END) {
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
- int i;
-
- if (ctx->NewState) {
- _mesa_update_state( ctx );
-
- CALL_Begin(ctx->Exec, (mode));
- return;
- }
-
- if (!_mesa_valid_to_render(ctx, "glBegin")) {
- return;
- }
-
- /* Heuristic: attempt to isolate attributes occuring outside
- * begin/end pairs.
- */
- if (exec->vtx.vertex_size && !exec->vtx.attrsz[0])
- vbo_exec_FlushVertices_internal(exec, GL_FALSE);
-
- i = exec->vtx.prim_count++;
- exec->vtx.prim[i].mode = mode;
- exec->vtx.prim[i].begin = 1;
- exec->vtx.prim[i].end = 0;
- exec->vtx.prim[i].indexed = 0;
- exec->vtx.prim[i].weak = 0;
- exec->vtx.prim[i].pad = 0;
- exec->vtx.prim[i].start = exec->vtx.vert_count;
- exec->vtx.prim[i].count = 0;
- exec->vtx.prim[i].num_instances = 1;
-
- ctx->Driver.CurrentExecPrimitive = mode;
- }
- else
- _mesa_error( ctx, GL_INVALID_OPERATION, "glBegin" );
-
-}
-
-
-/**
- * Called via glEnd.
- */
-static void GLAPIENTRY vbo_exec_End( void )
-{
- GET_CURRENT_CONTEXT( ctx );
-
- if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
- int idx = exec->vtx.vert_count;
- int i = exec->vtx.prim_count - 1;
-
- exec->vtx.prim[i].end = 1;
- exec->vtx.prim[i].count = idx - exec->vtx.prim[i].start;
-
- ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
-
- if (exec->vtx.prim_count == VBO_MAX_PRIM)
- vbo_exec_vtx_flush( exec, GL_FALSE );
- }
- else
- _mesa_error( ctx, GL_INVALID_OPERATION, "glEnd" );
-}
-
-
-/**
- * Called via glPrimitiveRestartNV()
- */
-static void GLAPIENTRY
-vbo_exec_PrimitiveRestartNV(void)
-{
- GLenum curPrim;
- GET_CURRENT_CONTEXT( ctx );
-
- curPrim = ctx->Driver.CurrentExecPrimitive;
-
- if (curPrim == PRIM_OUTSIDE_BEGIN_END) {
- _mesa_error( ctx, GL_INVALID_OPERATION, "glPrimitiveRestartNV" );
- }
- else {
- vbo_exec_End();
- vbo_exec_Begin(curPrim);
- }
-}
-
-
-
-static void vbo_exec_vtxfmt_init( struct vbo_exec_context *exec )
-{
- GLvertexformat *vfmt = &exec->vtxfmt;
-
- _MESA_INIT_ARRAYELT_VTXFMT(vfmt, _ae_);
-
- vfmt->Begin = vbo_exec_Begin;
- vfmt->End = vbo_exec_End;
- vfmt->PrimitiveRestartNV = vbo_exec_PrimitiveRestartNV;
-
- _MESA_INIT_DLIST_VTXFMT(vfmt, _mesa_);
- _MESA_INIT_EVAL_VTXFMT(vfmt, vbo_exec_);
-
- vfmt->Rectf = _mesa_noop_Rectf;
-
- /* from attrib_tmp.h:
- */
- vfmt->Color3f = vbo_Color3f;
- vfmt->Color3fv = vbo_Color3fv;
- vfmt->Color4f = vbo_Color4f;
- vfmt->Color4fv = vbo_Color4fv;
- vfmt->FogCoordfEXT = vbo_FogCoordfEXT;
- vfmt->FogCoordfvEXT = vbo_FogCoordfvEXT;
- vfmt->MultiTexCoord1fARB = vbo_MultiTexCoord1f;
- vfmt->MultiTexCoord1fvARB = vbo_MultiTexCoord1fv;
- vfmt->MultiTexCoord2fARB = vbo_MultiTexCoord2f;
- vfmt->MultiTexCoord2fvARB = vbo_MultiTexCoord2fv;
- vfmt->MultiTexCoord3fARB = vbo_MultiTexCoord3f;
- vfmt->MultiTexCoord3fvARB = vbo_MultiTexCoord3fv;
- vfmt->MultiTexCoord4fARB = vbo_MultiTexCoord4f;
- vfmt->MultiTexCoord4fvARB = vbo_MultiTexCoord4fv;
- vfmt->Normal3f = vbo_Normal3f;
- vfmt->Normal3fv = vbo_Normal3fv;
- vfmt->SecondaryColor3fEXT = vbo_SecondaryColor3fEXT;
- vfmt->SecondaryColor3fvEXT = vbo_SecondaryColor3fvEXT;
- vfmt->TexCoord1f = vbo_TexCoord1f;
- vfmt->TexCoord1fv = vbo_TexCoord1fv;
- vfmt->TexCoord2f = vbo_TexCoord2f;
- vfmt->TexCoord2fv = vbo_TexCoord2fv;
- vfmt->TexCoord3f = vbo_TexCoord3f;
- vfmt->TexCoord3fv = vbo_TexCoord3fv;
- vfmt->TexCoord4f = vbo_TexCoord4f;
- vfmt->TexCoord4fv = vbo_TexCoord4fv;
- vfmt->Vertex2f = vbo_Vertex2f;
- vfmt->Vertex2fv = vbo_Vertex2fv;
- vfmt->Vertex3f = vbo_Vertex3f;
- vfmt->Vertex3fv = vbo_Vertex3fv;
- vfmt->Vertex4f = vbo_Vertex4f;
- vfmt->Vertex4fv = vbo_Vertex4fv;
-
- vfmt->VertexAttrib1fARB = vbo_VertexAttrib1fARB;
- vfmt->VertexAttrib1fvARB = vbo_VertexAttrib1fvARB;
- vfmt->VertexAttrib2fARB = vbo_VertexAttrib2fARB;
- vfmt->VertexAttrib2fvARB = vbo_VertexAttrib2fvARB;
- vfmt->VertexAttrib3fARB = vbo_VertexAttrib3fARB;
- vfmt->VertexAttrib3fvARB = vbo_VertexAttrib3fvARB;
- vfmt->VertexAttrib4fARB = vbo_VertexAttrib4fARB;
- vfmt->VertexAttrib4fvARB = vbo_VertexAttrib4fvARB;
-
- vfmt->VertexAttrib1fNV = vbo_VertexAttrib1fNV;
- vfmt->VertexAttrib1fvNV = vbo_VertexAttrib1fvNV;
- vfmt->VertexAttrib2fNV = vbo_VertexAttrib2fNV;
- vfmt->VertexAttrib2fvNV = vbo_VertexAttrib2fvNV;
- vfmt->VertexAttrib3fNV = vbo_VertexAttrib3fNV;
- vfmt->VertexAttrib3fvNV = vbo_VertexAttrib3fvNV;
- vfmt->VertexAttrib4fNV = vbo_VertexAttrib4fNV;
- vfmt->VertexAttrib4fvNV = vbo_VertexAttrib4fvNV;
-
- /* integer-valued */
- vfmt->VertexAttribI1i = vbo_VertexAttribI1i;
- vfmt->VertexAttribI2i = vbo_VertexAttribI2i;
- vfmt->VertexAttribI3i = vbo_VertexAttribI3i;
- vfmt->VertexAttribI4i = vbo_VertexAttribI4i;
- vfmt->VertexAttribI2iv = vbo_VertexAttribI2iv;
- vfmt->VertexAttribI3iv = vbo_VertexAttribI3iv;
- vfmt->VertexAttribI4iv = vbo_VertexAttribI4iv;
-
- /* unsigned integer-valued */
- vfmt->VertexAttribI1ui = vbo_VertexAttribI1ui;
- vfmt->VertexAttribI2ui = vbo_VertexAttribI2ui;
- vfmt->VertexAttribI3ui = vbo_VertexAttribI3ui;
- vfmt->VertexAttribI4ui = vbo_VertexAttribI4ui;
- vfmt->VertexAttribI2uiv = vbo_VertexAttribI2uiv;
- vfmt->VertexAttribI3uiv = vbo_VertexAttribI3uiv;
- vfmt->VertexAttribI4uiv = vbo_VertexAttribI4uiv;
-
- vfmt->Materialfv = vbo_Materialfv;
-
- vfmt->EdgeFlag = vbo_EdgeFlag;
- vfmt->Indexf = vbo_Indexf;
- vfmt->Indexfv = vbo_Indexfv;
-
-}
-
-
-#else /* FEATURE_beginend */
-
-
-static void vbo_exec_vtxfmt_init( struct vbo_exec_context *exec )
-{
- /* silence warnings */
- (void) vbo_Color3f;
- (void) vbo_Color3fv;
- (void) vbo_Color4f;
- (void) vbo_Color4fv;
- (void) vbo_FogCoordfEXT;
- (void) vbo_FogCoordfvEXT;
- (void) vbo_MultiTexCoord1f;
- (void) vbo_MultiTexCoord1fv;
- (void) vbo_MultiTexCoord2f;
- (void) vbo_MultiTexCoord2fv;
- (void) vbo_MultiTexCoord3f;
- (void) vbo_MultiTexCoord3fv;
- (void) vbo_MultiTexCoord4f;
- (void) vbo_MultiTexCoord4fv;
- (void) vbo_Normal3f;
- (void) vbo_Normal3fv;
- (void) vbo_SecondaryColor3fEXT;
- (void) vbo_SecondaryColor3fvEXT;
- (void) vbo_TexCoord1f;
- (void) vbo_TexCoord1fv;
- (void) vbo_TexCoord2f;
- (void) vbo_TexCoord2fv;
- (void) vbo_TexCoord3f;
- (void) vbo_TexCoord3fv;
- (void) vbo_TexCoord4f;
- (void) vbo_TexCoord4fv;
- (void) vbo_Vertex2f;
- (void) vbo_Vertex2fv;
- (void) vbo_Vertex3f;
- (void) vbo_Vertex3fv;
- (void) vbo_Vertex4f;
- (void) vbo_Vertex4fv;
-
- (void) vbo_VertexAttrib1fARB;
- (void) vbo_VertexAttrib1fvARB;
- (void) vbo_VertexAttrib2fARB;
- (void) vbo_VertexAttrib2fvARB;
- (void) vbo_VertexAttrib3fARB;
- (void) vbo_VertexAttrib3fvARB;
- (void) vbo_VertexAttrib4fARB;
- (void) vbo_VertexAttrib4fvARB;
-
- (void) vbo_VertexAttrib1fNV;
- (void) vbo_VertexAttrib1fvNV;
- (void) vbo_VertexAttrib2fNV;
- (void) vbo_VertexAttrib2fvNV;
- (void) vbo_VertexAttrib3fNV;
- (void) vbo_VertexAttrib3fvNV;
- (void) vbo_VertexAttrib4fNV;
- (void) vbo_VertexAttrib4fvNV;
-
- (void) vbo_Materialfv;
-
- (void) vbo_EdgeFlag;
- (void) vbo_Indexf;
- (void) vbo_Indexfv;
-}
-
-
-#endif /* FEATURE_beginend */
-
-
-/**
- * Tell the VBO module to use a real OpenGL vertex buffer object to
- * store accumulated immediate-mode vertex data.
- * This replaces the malloced buffer which was created in
- * vb_exec_vtx_init() below.
- */
-void vbo_use_buffer_objects(struct gl_context *ctx)
-{
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
- /* Any buffer name but 0 can be used here since this bufferobj won't
- * go into the bufferobj hashtable.
- */
- GLuint bufName = IMM_BUFFER_NAME;
- GLenum target = GL_ARRAY_BUFFER_ARB;
- GLenum usage = GL_STREAM_DRAW_ARB;
- GLsizei size = VBO_VERT_BUFFER_SIZE;
-
- /* Make sure this func is only used once */
- assert(exec->vtx.bufferobj == ctx->Shared->NullBufferObj);
- if (exec->vtx.buffer_map) {
- _mesa_align_free(exec->vtx.buffer_map);
- exec->vtx.buffer_map = NULL;
- exec->vtx.buffer_ptr = NULL;
- }
-
- /* Allocate a real buffer object now */
- _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
- exec->vtx.bufferobj = ctx->Driver.NewBufferObject(ctx, bufName, target);
- ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj);
-}
-
-
-/**
- * If this function is called, all VBO buffers will be unmapped when
- * we flush.
- * Otherwise, if a simple command like glColor3f() is called and we flush,
- * the current VBO may be left mapped.
- */
-void
-vbo_always_unmap_buffers(struct gl_context *ctx)
-{
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
- exec->begin_vertices_flags |= FLUSH_STORED_VERTICES;
-}
-
-
-void vbo_exec_vtx_init( struct vbo_exec_context *exec )
-{
- struct gl_context *ctx = exec->ctx;
- struct vbo_context *vbo = vbo_context(ctx);
- GLuint i;
-
- /* Allocate a buffer object. Will just reuse this object
- * continuously, unless vbo_use_buffer_objects() is called to enable
- * use of real VBOs.
- */
- _mesa_reference_buffer_object(ctx,
- &exec->vtx.bufferobj,
- ctx->Shared->NullBufferObj);
-
- ASSERT(!exec->vtx.buffer_map);
- exec->vtx.buffer_map = (GLfloat *)_mesa_align_malloc(VBO_VERT_BUFFER_SIZE, 64);
- exec->vtx.buffer_ptr = exec->vtx.buffer_map;
-
- vbo_exec_vtxfmt_init( exec );
-
- /* Hook our functions into the dispatch table.
- */
- _mesa_install_exec_vtxfmt( ctx, &exec->vtxfmt );
-
- for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) {
- ASSERT(i < Elements(exec->vtx.attrsz));
- exec->vtx.attrsz[i] = 0;
- ASSERT(i < Elements(exec->vtx.active_sz));
- exec->vtx.active_sz[i] = 0;
- }
- for (i = 0 ; i < VERT_ATTRIB_MAX; i++) {
- ASSERT(i < Elements(exec->vtx.inputs));
- ASSERT(i < Elements(exec->vtx.arrays));
- exec->vtx.inputs[i] = &exec->vtx.arrays[i];
- }
-
- {
- struct gl_client_array *arrays = exec->vtx.arrays;
- unsigned i;
-
- memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0]));
- memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0]));
-
- for (i = 0; i < 16; ++i) {
- arrays[i ].BufferObj = NULL;
- arrays[i + 16].BufferObj = NULL;
- _mesa_reference_buffer_object(ctx, &arrays[i ].BufferObj,
- vbo->legacy_currval[i].BufferObj);
- _mesa_reference_buffer_object(ctx, &arrays[i + 16].BufferObj,
- vbo->generic_currval[i].BufferObj);
- }
- }
-
- exec->vtx.vertex_size = 0;
-
- exec->begin_vertices_flags = FLUSH_UPDATE_CURRENT;
-}
-
-
-void vbo_exec_vtx_destroy( struct vbo_exec_context *exec )
-{
- /* using a real VBO for vertex data */
- struct gl_context *ctx = exec->ctx;
- unsigned i;
-
- /* True VBOs should already be unmapped
- */
- if (exec->vtx.buffer_map) {
- ASSERT(exec->vtx.bufferobj->Name == 0 ||
- exec->vtx.bufferobj->Name == IMM_BUFFER_NAME);
- if (exec->vtx.bufferobj->Name == 0) {
- _mesa_align_free(exec->vtx.buffer_map);
- exec->vtx.buffer_map = NULL;
- exec->vtx.buffer_ptr = NULL;
- }
- }
-
- /* Drop any outstanding reference to the vertex buffer
- */
- for (i = 0; i < Elements(exec->vtx.arrays); i++) {
- _mesa_reference_buffer_object(ctx,
- &exec->vtx.arrays[i].BufferObj,
- NULL);
- }
-
- /* Free the vertex buffer. Unmap first if needed.
- */
- if (_mesa_bufferobj_mapped(exec->vtx.bufferobj)) {
- ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER, exec->vtx.bufferobj);
- }
- _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
-}
-
-
-/**
- * Called upon first glVertex, glColor, glTexCoord, etc.
- */
-void vbo_exec_BeginVertices( struct gl_context *ctx )
-{
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
-
- vbo_exec_vtx_map( exec );
-
- assert((ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) == 0);
- assert(exec->begin_vertices_flags);
-
- ctx->Driver.NeedFlush |= exec->begin_vertices_flags;
-}
-
-
-/**
- * Called via ctx->Driver.FlushVertices()
- * \param flags bitmask of FLUSH_STORED_VERTICES, FLUSH_UPDATE_CURRENT
- */
-void vbo_exec_FlushVertices( struct gl_context *ctx, GLuint flags )
-{
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
-
-#ifdef DEBUG
- /* debug check: make sure we don't get called recursively */
- exec->flush_call_depth++;
- assert(exec->flush_call_depth == 1);
-#endif
-
- if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
- /* We've had glBegin but not glEnd! */
-#ifdef DEBUG
- exec->flush_call_depth--;
- assert(exec->flush_call_depth == 0);
-#endif
- return;
- }
-
- /* Flush (draw), and make sure VBO is left unmapped when done */
- vbo_exec_FlushVertices_internal(exec, GL_TRUE);
-
- /* Need to do this to ensure BeginVertices gets called again:
- */
- ctx->Driver.NeedFlush &= ~(FLUSH_UPDATE_CURRENT | flags);
-
-#ifdef DEBUG
- exec->flush_call_depth--;
- assert(exec->flush_call_depth == 0);
-#endif
-}
-
-
-static void reset_attrfv( struct vbo_exec_context *exec )
-{
- GLuint i;
-
- for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) {
- exec->vtx.attrsz[i] = 0;
- exec->vtx.active_sz[i] = 0;
- }
-
- exec->vtx.vertex_size = 0;
-}
-
-
-void GLAPIENTRY
-_es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
-{
- vbo_Color4f(r, g, b, a);
-}
-
-
-void GLAPIENTRY
-_es_Normal3f(GLfloat x, GLfloat y, GLfloat z)
-{
- vbo_Normal3f(x, y, z);
-}
-
-
-void GLAPIENTRY
-_es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
-{
- vbo_MultiTexCoord4f(target, s, t, r, q);
-}
-
-
-void GLAPIENTRY
-_es_Materialfv(GLenum face, GLenum pname, const GLfloat *params)
-{
- vbo_Materialfv(face, pname, params);
-}
-
-
-void GLAPIENTRY
-_es_Materialf(GLenum face, GLenum pname, GLfloat param)
-{
- GLfloat p[4];
- p[0] = param;
- p[1] = p[2] = p[3] = 0.0F;
- vbo_Materialfv(face, pname, p);
-}
-
-
-/**
- * A special version of glVertexAttrib4f that does not treat index 0 as
- * VBO_ATTRIB_POS.
- */
-static void
-VertexAttrib4f_nopos(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (index < MAX_VERTEX_GENERIC_ATTRIBS)
- ATTR(VBO_ATTRIB_GENERIC0 + index, 4, x, y, z, w);
- else
- ERROR(GL_INVALID_VALUE);
-}
-
-void GLAPIENTRY
-_es_VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- VertexAttrib4f_nopos(index, x, y, z, w);
-}
-
-
-void GLAPIENTRY
-_es_VertexAttrib1f(GLuint indx, GLfloat x)
-{
- VertexAttrib4f_nopos(indx, x, 0.0f, 0.0f, 1.0f);
-}
-
-
-void GLAPIENTRY
-_es_VertexAttrib1fv(GLuint indx, const GLfloat* values)
-{
- VertexAttrib4f_nopos(indx, values[0], 0.0f, 0.0f, 1.0f);
-}
-
-
-void GLAPIENTRY
-_es_VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y)
-{
- VertexAttrib4f_nopos(indx, x, y, 0.0f, 1.0f);
-}
-
-
-void GLAPIENTRY
-_es_VertexAttrib2fv(GLuint indx, const GLfloat* values)
-{
- VertexAttrib4f_nopos(indx, values[0], values[1], 0.0f, 1.0f);
-}
-
-
-void GLAPIENTRY
-_es_VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
-{
- VertexAttrib4f_nopos(indx, x, y, z, 1.0f);
-}
-
-
-void GLAPIENTRY
-_es_VertexAttrib3fv(GLuint indx, const GLfloat* values)
-{
- VertexAttrib4f_nopos(indx, values[0], values[1], values[2], 1.0f);
-}
-
-
-void GLAPIENTRY
-_es_VertexAttrib4fv(GLuint indx, const GLfloat* values)
-{
- VertexAttrib4f_nopos(indx, values[0], values[1], values[2], values[3]);
-}
+/**************************************************************************
+
+Copyright 2002-2008 Tungsten Graphics Inc., Cedar Park, Texas.
+
+All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+on the rights to use, copy, modify, merge, publish, distribute, sub
+license, and/or sell copies of the Software, and to permit persons to whom
+the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "main/glheader.h"
+#include "main/bufferobj.h"
+#include "main/context.h"
+#include "main/macros.h"
+#include "main/mfeatures.h"
+#include "main/vtxfmt.h"
+#include "main/dlist.h"
+#include "main/eval.h"
+#include "main/state.h"
+#include "main/light.h"
+#include "main/api_arrayelt.h"
+#include "main/api_noop.h"
+#include "main/dispatch.h"
+
+#include "vbo_context.h"
+
+#ifdef ERROR
+#undef ERROR
+#endif
+
+
+/** ID/name for immediate-mode VBO */
+#define IMM_BUFFER_NAME 0xaabbccdd
+
+
+static void reset_attrfv( struct vbo_exec_context *exec );
+
+
+/**
+ * Close off the last primitive, execute the buffer, restart the
+ * primitive.
+ */
+static void vbo_exec_wrap_buffers( struct vbo_exec_context *exec )
+{
+ if (exec->vtx.prim_count == 0) {
+ exec->vtx.copied.nr = 0;
+ exec->vtx.vert_count = 0;
+ exec->vtx.buffer_ptr = exec->vtx.buffer_map;
+ }
+ else {
+ GLuint last_begin = exec->vtx.prim[exec->vtx.prim_count-1].begin;
+ GLuint last_count;
+
+ if (exec->ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
+ GLint i = exec->vtx.prim_count - 1;
+ assert(i >= 0);
+ exec->vtx.prim[i].count = (exec->vtx.vert_count -
+ exec->vtx.prim[i].start);
+ }
+
+ last_count = exec->vtx.prim[exec->vtx.prim_count-1].count;
+
+ /* Execute the buffer and save copied vertices.
+ */
+ if (exec->vtx.vert_count)
+ vbo_exec_vtx_flush( exec, GL_FALSE );
+ else {
+ exec->vtx.prim_count = 0;
+ exec->vtx.copied.nr = 0;
+ }
+
+ /* Emit a glBegin to start the new list.
+ */
+ assert(exec->vtx.prim_count == 0);
+
+ if (exec->ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
+ exec->vtx.prim[0].mode = exec->ctx->Driver.CurrentExecPrimitive;
+ exec->vtx.prim[0].start = 0;
+ exec->vtx.prim[0].count = 0;
+ exec->vtx.prim_count++;
+
+ if (exec->vtx.copied.nr == last_count)
+ exec->vtx.prim[0].begin = last_begin;
+ }
+ }
+}
+
+
+/**
+ * Deal with buffer wrapping where provoked by the vertex buffer
+ * filling up, as opposed to upgrade_vertex().
+ */
+void vbo_exec_vtx_wrap( struct vbo_exec_context *exec )
+{
+ GLfloat *data = exec->vtx.copied.buffer;
+ GLuint i;
+
+ /* Run pipeline on current vertices, copy wrapped vertices
+ * to exec->vtx.copied.
+ */
+ vbo_exec_wrap_buffers( exec );
+
+ /* Copy stored stored vertices to start of new list.
+ */
+ assert(exec->vtx.max_vert - exec->vtx.vert_count > exec->vtx.copied.nr);
+
+ for (i = 0 ; i < exec->vtx.copied.nr ; i++) {
+ memcpy( exec->vtx.buffer_ptr, data,
+ exec->vtx.vertex_size * sizeof(GLfloat));
+ exec->vtx.buffer_ptr += exec->vtx.vertex_size;
+ data += exec->vtx.vertex_size;
+ exec->vtx.vert_count++;
+ }
+
+ exec->vtx.copied.nr = 0;
+}
+
+
+/**
+ * Copy the active vertex's values to the ctx->Current fields.
+ */
+static void vbo_exec_copy_to_current( struct vbo_exec_context *exec )
+{
+ struct gl_context *ctx = exec->ctx;
+ struct vbo_context *vbo = vbo_context(ctx);
+ GLuint i;
+
+ for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
+ if (exec->vtx.attrsz[i]) {
+ /* Note: the exec->vtx.current[i] pointers point into the
+ * ctx->Current.Attrib and ctx->Light.Material.Attrib arrays.
+ */
+ GLfloat *current = (GLfloat *)vbo->currval[i].Ptr;
+ GLfloat tmp[4];
+
+ COPY_CLEAN_4V(tmp,
+ exec->vtx.attrsz[i],
+ exec->vtx.attrptr[i]);
+
+ if (memcmp(current, tmp, sizeof(tmp)) != 0) {
+ memcpy(current, tmp, sizeof(tmp));
+
+ /* Given that we explicitly state size here, there is no need
+ * for the COPY_CLEAN above, could just copy 16 bytes and be
+ * done. The only problem is when Mesa accesses ctx->Current
+ * directly.
+ */
+ vbo->currval[i].Size = exec->vtx.attrsz[i];
+
+ /* This triggers rather too much recalculation of Mesa state
+ * that doesn't get used (eg light positions).
+ */
+ if (i >= VBO_ATTRIB_MAT_FRONT_AMBIENT &&
+ i <= VBO_ATTRIB_MAT_BACK_INDEXES)
+ ctx->NewState |= _NEW_LIGHT;
+
+ ctx->NewState |= _NEW_CURRENT_ATTRIB;
+ }
+ }
+ }
+
+ /* Colormaterial -- this kindof sucks.
+ */
+ if (ctx->Light.ColorMaterialEnabled &&
+ exec->vtx.attrsz[VBO_ATTRIB_COLOR0]) {
+ _mesa_update_color_material(ctx,
+ ctx->Current.Attrib[VBO_ATTRIB_COLOR0]);
+ }
+}
+
+
+/**
+ * Copy current vertex attribute values into the current vertex.
+ */
+static void
+vbo_exec_copy_from_current(struct vbo_exec_context *exec)
+{
+ struct gl_context *ctx = exec->ctx;
+ struct vbo_context *vbo = vbo_context(ctx);
+ GLint i;
+
+ for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
+ const GLfloat *current = (GLfloat *) vbo->currval[i].Ptr;
+ switch (exec->vtx.attrsz[i]) {
+ case 4: exec->vtx.attrptr[i][3] = current[3];
+ case 3: exec->vtx.attrptr[i][2] = current[2];
+ case 2: exec->vtx.attrptr[i][1] = current[1];
+ case 1: exec->vtx.attrptr[i][0] = current[0];
+ break;
+ }
+ }
+}
+
+
+/**
+ * Flush existing data, set new attrib size, replay copied vertices.
+ * This is called when we transition from a small vertex attribute size
+ * to a larger one. Ex: glTexCoord2f -> glTexCoord4f.
+ * We need to go back over the previous 2-component texcoords and insert
+ * zero and one values.
+ */
+static void
+vbo_exec_wrap_upgrade_vertex(struct vbo_exec_context *exec,
+ GLuint attr, GLuint newSize )
+{
+ struct gl_context *ctx = exec->ctx;
+ struct vbo_context *vbo = vbo_context(ctx);
+ const GLint lastcount = exec->vtx.vert_count;
+ GLfloat *old_attrptr[VBO_ATTRIB_MAX];
+ const GLuint old_vtx_size = exec->vtx.vertex_size; /* floats per vertex */
+ const GLuint oldSize = exec->vtx.attrsz[attr];
+ GLuint i;
+
+ /* Run pipeline on current vertices, copy wrapped vertices
+ * to exec->vtx.copied.
+ */
+ vbo_exec_wrap_buffers( exec );
+
+ if (unlikely(exec->vtx.copied.nr)) {
+ /* We're in the middle of a primitive, keep the old vertex
+ * format around to be able to translate the copied vertices to
+ * the new format.
+ */
+ memcpy(old_attrptr, exec->vtx.attrptr, sizeof(old_attrptr));
+ }
+
+ if (unlikely(oldSize)) {
+ /* Do a COPY_TO_CURRENT to ensure back-copying works for the
+ * case when the attribute already exists in the vertex and is
+ * having its size increased.
+ */
+ vbo_exec_copy_to_current( exec );
+ }
+
+ /* Heuristic: Attempt to isolate attributes received outside
+ * begin/end so that they don't bloat the vertices.
+ */
+ if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END &&
+ !oldSize && lastcount > 8 && exec->vtx.vertex_size) {
+ vbo_exec_copy_to_current( exec );
+ reset_attrfv( exec );
+ }
+
+ /* Fix up sizes:
+ */
+ exec->vtx.attrsz[attr] = newSize;
+ exec->vtx.vertex_size += newSize - oldSize;
+ exec->vtx.max_vert = ((VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) /
+ (exec->vtx.vertex_size * sizeof(GLfloat)));
+ exec->vtx.vert_count = 0;
+ exec->vtx.buffer_ptr = exec->vtx.buffer_map;
+
+ if (unlikely(oldSize)) {
+ /* Size changed, recalculate all the attrptr[] values
+ */
+ GLfloat *tmp = exec->vtx.vertex;
+
+ for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) {
+ if (exec->vtx.attrsz[i]) {
+ exec->vtx.attrptr[i] = tmp;
+ tmp += exec->vtx.attrsz[i];
+ }
+ else
+ exec->vtx.attrptr[i] = NULL; /* will not be dereferenced */
+ }
+
+ /* Copy from current to repopulate the vertex with correct
+ * values.
+ */
+ vbo_exec_copy_from_current( exec );
+ }
+ else {
+ /* Just have to append the new attribute at the end */
+ exec->vtx.attrptr[attr] = exec->vtx.vertex +
+ exec->vtx.vertex_size - newSize;
+ }
+
+ /* Replay stored vertices to translate them
+ * to new format here.
+ *
+ * -- No need to replay - just copy piecewise
+ */
+ if (unlikely(exec->vtx.copied.nr)) {
+ GLfloat *data = exec->vtx.copied.buffer;
+ GLfloat *dest = exec->vtx.buffer_ptr;
+ GLuint j;
+
+ assert(exec->vtx.buffer_ptr == exec->vtx.buffer_map);
+
+ for (i = 0 ; i < exec->vtx.copied.nr ; i++) {
+ for (j = 0 ; j < VBO_ATTRIB_MAX ; j++) {
+ GLuint sz = exec->vtx.attrsz[j];
+
+ if (sz) {
+ GLint old_offset = old_attrptr[j] - exec->vtx.vertex;
+ GLint new_offset = exec->vtx.attrptr[j] - exec->vtx.vertex;
+
+ if (j == attr) {
+ if (oldSize) {
+ GLfloat tmp[4];
+ COPY_CLEAN_4V(tmp, oldSize, data + old_offset);
+ COPY_SZ_4V(dest + new_offset, newSize, tmp);
+ } else {
+ GLfloat *current = (GLfloat *)vbo->currval[j].Ptr;
+ COPY_SZ_4V(dest + new_offset, sz, current);
+ }
+ }
+ else {
+ COPY_SZ_4V(dest + new_offset, sz, data + old_offset);
+ }
+ }
+ }
+
+ data += old_vtx_size;
+ dest += exec->vtx.vertex_size;
+ }
+
+ exec->vtx.buffer_ptr = dest;
+ exec->vtx.vert_count += exec->vtx.copied.nr;
+ exec->vtx.copied.nr = 0;
+ }
+}
+
+
+/**
+ * This is when a vertex attribute transitions to a different size.
+ * For example, we saw a bunch of glTexCoord2f() calls and now we got a
+ * glTexCoord4f() call. We promote the array from size=2 to size=4.
+ */
+static void
+vbo_exec_fixup_vertex(struct gl_context *ctx, GLuint attr, GLuint newSize)
+{
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+
+ if (newSize > exec->vtx.attrsz[attr]) {
+ /* New size is larger. Need to flush existing vertices and get
+ * an enlarged vertex format.
+ */
+ vbo_exec_wrap_upgrade_vertex( exec, attr, newSize );
+ }
+ else if (newSize < exec->vtx.active_sz[attr]) {
+ static const GLfloat id[4] = { 0, 0, 0, 1 };
+ GLuint i;
+
+ /* New size is smaller - just need to fill in some
+ * zeros. Don't need to flush or wrap.
+ */
+ for (i = newSize; i <= exec->vtx.attrsz[attr]; i++)
+ exec->vtx.attrptr[attr][i-1] = id[i-1];
+ }
+
+ exec->vtx.active_sz[attr] = newSize;
+
+ /* Does setting NeedFlush belong here? Necessitates resetting
+ * vtxfmt on each flush (otherwise flags won't get reset
+ * afterwards).
+ */
+ if (attr == 0)
+ ctx->Driver.NeedFlush |= FLUSH_STORED_VERTICES;
+}
+
+
+/**
+ * This macro is used to implement all the glVertex, glColor, glTexCoord,
+ * glVertexAttrib, etc functions.
+ */
+#define ATTR( A, N, V0, V1, V2, V3 ) \
+do { \
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec; \
+ \
+ if (unlikely(!(ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT))) \
+ ctx->Driver.BeginVertices( ctx ); \
+ \
+ if (unlikely(exec->vtx.active_sz[A] != N)) \
+ vbo_exec_fixup_vertex(ctx, A, N); \
+ \
+ { \
+ GLfloat *dest = exec->vtx.attrptr[A]; \
+ if (N>0) dest[0] = V0; \
+ if (N>1) dest[1] = V1; \
+ if (N>2) dest[2] = V2; \
+ if (N>3) dest[3] = V3; \
+ } \
+ \
+ if ((A) == 0) { \
+ /* This is a glVertex call */ \
+ GLuint i; \
+ \
+ for (i = 0; i < exec->vtx.vertex_size; i++) \
+ exec->vtx.buffer_ptr[i] = exec->vtx.vertex[i]; \
+ \
+ exec->vtx.buffer_ptr += exec->vtx.vertex_size; \
+ \
+ /* Set FLUSH_STORED_VERTICES to indicate that there's now */ \
+ /* something to draw (not just updating a color or texcoord).*/ \
+ ctx->Driver.NeedFlush |= FLUSH_STORED_VERTICES; \
+ \
+ if (++exec->vtx.vert_count >= exec->vtx.max_vert) \
+ vbo_exec_vtx_wrap( exec ); \
+ } \
+} while (0)
+
+
+#define ERROR(err) _mesa_error( ctx, err, __FUNCTION__ )
+#define TAG(x) vbo_##x
+
+#include "vbo_attrib_tmp.h"
+
+
+#if FEATURE_beginend
+
+
+#if FEATURE_evaluators
+
+static void GLAPIENTRY vbo_exec_EvalCoord1f( GLfloat u )
+{
+ GET_CURRENT_CONTEXT( ctx );
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+
+ {
+ GLint i;
+ if (exec->eval.recalculate_maps)
+ vbo_exec_eval_update( exec );
+
+ for (i = 0; i <= VBO_ATTRIB_TEX7; i++) {
+ if (exec->eval.map1[i].map)
+ if (exec->vtx.active_sz[i] != exec->eval.map1[i].sz)
+ vbo_exec_fixup_vertex( ctx, i, exec->eval.map1[i].sz );
+ }
+ }
+
+
+ memcpy( exec->vtx.copied.buffer, exec->vtx.vertex,
+ exec->vtx.vertex_size * sizeof(GLfloat));
+
+ vbo_exec_do_EvalCoord1f( exec, u );
+
+ memcpy( exec->vtx.vertex, exec->vtx.copied.buffer,
+ exec->vtx.vertex_size * sizeof(GLfloat));
+}
+
+static void GLAPIENTRY vbo_exec_EvalCoord2f( GLfloat u, GLfloat v )
+{
+ GET_CURRENT_CONTEXT( ctx );
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+
+ {
+ GLint i;
+ if (exec->eval.recalculate_maps)
+ vbo_exec_eval_update( exec );
+
+ for (i = 0; i <= VBO_ATTRIB_TEX7; i++) {
+ if (exec->eval.map2[i].map)
+ if (exec->vtx.active_sz[i] != exec->eval.map2[i].sz)
+ vbo_exec_fixup_vertex( ctx, i, exec->eval.map2[i].sz );
+ }
+
+ if (ctx->Eval.AutoNormal)
+ if (exec->vtx.active_sz[VBO_ATTRIB_NORMAL] != 3)
+ vbo_exec_fixup_vertex( ctx, VBO_ATTRIB_NORMAL, 3 );
+ }
+
+ memcpy( exec->vtx.copied.buffer, exec->vtx.vertex,
+ exec->vtx.vertex_size * sizeof(GLfloat));
+
+ vbo_exec_do_EvalCoord2f( exec, u, v );
+
+ memcpy( exec->vtx.vertex, exec->vtx.copied.buffer,
+ exec->vtx.vertex_size * sizeof(GLfloat));
+}
+
+static void GLAPIENTRY vbo_exec_EvalCoord1fv( const GLfloat *u )
+{
+ vbo_exec_EvalCoord1f( u[0] );
+}
+
+static void GLAPIENTRY vbo_exec_EvalCoord2fv( const GLfloat *u )
+{
+ vbo_exec_EvalCoord2f( u[0], u[1] );
+}
+
+static void GLAPIENTRY vbo_exec_EvalPoint1( GLint i )
+{
+ GET_CURRENT_CONTEXT( ctx );
+ GLfloat du = ((ctx->Eval.MapGrid1u2 - ctx->Eval.MapGrid1u1) /
+ (GLfloat) ctx->Eval.MapGrid1un);
+ GLfloat u = i * du + ctx->Eval.MapGrid1u1;
+
+ vbo_exec_EvalCoord1f( u );
+}
+
+
+static void GLAPIENTRY vbo_exec_EvalPoint2( GLint i, GLint j )
+{
+ GET_CURRENT_CONTEXT( ctx );
+ GLfloat du = ((ctx->Eval.MapGrid2u2 - ctx->Eval.MapGrid2u1) /
+ (GLfloat) ctx->Eval.MapGrid2un);
+ GLfloat dv = ((ctx->Eval.MapGrid2v2 - ctx->Eval.MapGrid2v1) /
+ (GLfloat) ctx->Eval.MapGrid2vn);
+ GLfloat u = i * du + ctx->Eval.MapGrid2u1;
+ GLfloat v = j * dv + ctx->Eval.MapGrid2v1;
+
+ vbo_exec_EvalCoord2f( u, v );
+}
+
+/* use noop eval mesh */
+#define vbo_exec_EvalMesh1 _mesa_noop_EvalMesh1
+#define vbo_exec_EvalMesh2 _mesa_noop_EvalMesh2
+
+#endif /* FEATURE_evaluators */
+
+
+/**
+ * Flush (draw) vertices.
+ * \param unmap - leave VBO unmapped after flushing?
+ */
+static void
+vbo_exec_FlushVertices_internal(struct vbo_exec_context *exec, GLboolean unmap)
+{
+ if (exec->vtx.vert_count || unmap) {
+ vbo_exec_vtx_flush( exec, unmap );
+ }
+
+ if (exec->vtx.vertex_size) {
+ vbo_exec_copy_to_current( exec );
+ reset_attrfv( exec );
+ }
+}
+
+
+/**
+ * Called via glBegin.
+ */
+static void GLAPIENTRY vbo_exec_Begin( GLenum mode )
+{
+ GET_CURRENT_CONTEXT( ctx );
+
+ if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END) {
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+ int i;
+
+ if (ctx->NewState) {
+ _mesa_update_state( ctx );
+
+ CALL_Begin(ctx->Exec, (mode));
+ return;
+ }
+
+ if (!_mesa_valid_to_render(ctx, "glBegin")) {
+ return;
+ }
+
+ /* Heuristic: attempt to isolate attributes occuring outside
+ * begin/end pairs.
+ */
+ if (exec->vtx.vertex_size && !exec->vtx.attrsz[0])
+ vbo_exec_FlushVertices_internal(exec, GL_FALSE);
+
+ i = exec->vtx.prim_count++;
+ exec->vtx.prim[i].mode = mode;
+ exec->vtx.prim[i].begin = 1;
+ exec->vtx.prim[i].end = 0;
+ exec->vtx.prim[i].indexed = 0;
+ exec->vtx.prim[i].weak = 0;
+ exec->vtx.prim[i].pad = 0;
+ exec->vtx.prim[i].start = exec->vtx.vert_count;
+ exec->vtx.prim[i].count = 0;
+ exec->vtx.prim[i].num_instances = 1;
+
+ ctx->Driver.CurrentExecPrimitive = mode;
+ }
+ else
+ _mesa_error( ctx, GL_INVALID_OPERATION, "glBegin" );
+
+}
+
+
+/**
+ * Called via glEnd.
+ */
+static void GLAPIENTRY vbo_exec_End( void )
+{
+ GET_CURRENT_CONTEXT( ctx );
+
+ if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+ int idx = exec->vtx.vert_count;
+ int i = exec->vtx.prim_count - 1;
+
+ exec->vtx.prim[i].end = 1;
+ exec->vtx.prim[i].count = idx - exec->vtx.prim[i].start;
+
+ ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
+
+ if (exec->vtx.prim_count == VBO_MAX_PRIM)
+ vbo_exec_vtx_flush( exec, GL_FALSE );
+ }
+ else
+ _mesa_error( ctx, GL_INVALID_OPERATION, "glEnd" );
+}
+
+
+/**
+ * Called via glPrimitiveRestartNV()
+ */
+static void GLAPIENTRY
+vbo_exec_PrimitiveRestartNV(void)
+{
+ GLenum curPrim;
+ GET_CURRENT_CONTEXT( ctx );
+
+ curPrim = ctx->Driver.CurrentExecPrimitive;
+
+ if (curPrim == PRIM_OUTSIDE_BEGIN_END) {
+ _mesa_error( ctx, GL_INVALID_OPERATION, "glPrimitiveRestartNV" );
+ }
+ else {
+ vbo_exec_End();
+ vbo_exec_Begin(curPrim);
+ }
+}
+
+
+
+static void vbo_exec_vtxfmt_init( struct vbo_exec_context *exec )
+{
+ GLvertexformat *vfmt = &exec->vtxfmt;
+
+ _MESA_INIT_ARRAYELT_VTXFMT(vfmt, _ae_);
+
+ vfmt->Begin = vbo_exec_Begin;
+ vfmt->End = vbo_exec_End;
+ vfmt->PrimitiveRestartNV = vbo_exec_PrimitiveRestartNV;
+
+ _MESA_INIT_DLIST_VTXFMT(vfmt, _mesa_);
+ _MESA_INIT_EVAL_VTXFMT(vfmt, vbo_exec_);
+
+ vfmt->Rectf = _mesa_noop_Rectf;
+
+ /* from attrib_tmp.h:
+ */
+ vfmt->Color3f = vbo_Color3f;
+ vfmt->Color3fv = vbo_Color3fv;
+ vfmt->Color4f = vbo_Color4f;
+ vfmt->Color4fv = vbo_Color4fv;
+ vfmt->FogCoordfEXT = vbo_FogCoordfEXT;
+ vfmt->FogCoordfvEXT = vbo_FogCoordfvEXT;
+ vfmt->MultiTexCoord1fARB = vbo_MultiTexCoord1f;
+ vfmt->MultiTexCoord1fvARB = vbo_MultiTexCoord1fv;
+ vfmt->MultiTexCoord2fARB = vbo_MultiTexCoord2f;
+ vfmt->MultiTexCoord2fvARB = vbo_MultiTexCoord2fv;
+ vfmt->MultiTexCoord3fARB = vbo_MultiTexCoord3f;
+ vfmt->MultiTexCoord3fvARB = vbo_MultiTexCoord3fv;
+ vfmt->MultiTexCoord4fARB = vbo_MultiTexCoord4f;
+ vfmt->MultiTexCoord4fvARB = vbo_MultiTexCoord4fv;
+ vfmt->Normal3f = vbo_Normal3f;
+ vfmt->Normal3fv = vbo_Normal3fv;
+ vfmt->SecondaryColor3fEXT = vbo_SecondaryColor3fEXT;
+ vfmt->SecondaryColor3fvEXT = vbo_SecondaryColor3fvEXT;
+ vfmt->TexCoord1f = vbo_TexCoord1f;
+ vfmt->TexCoord1fv = vbo_TexCoord1fv;
+ vfmt->TexCoord2f = vbo_TexCoord2f;
+ vfmt->TexCoord2fv = vbo_TexCoord2fv;
+ vfmt->TexCoord3f = vbo_TexCoord3f;
+ vfmt->TexCoord3fv = vbo_TexCoord3fv;
+ vfmt->TexCoord4f = vbo_TexCoord4f;
+ vfmt->TexCoord4fv = vbo_TexCoord4fv;
+ vfmt->Vertex2f = vbo_Vertex2f;
+ vfmt->Vertex2fv = vbo_Vertex2fv;
+ vfmt->Vertex3f = vbo_Vertex3f;
+ vfmt->Vertex3fv = vbo_Vertex3fv;
+ vfmt->Vertex4f = vbo_Vertex4f;
+ vfmt->Vertex4fv = vbo_Vertex4fv;
+
+ vfmt->VertexAttrib1fARB = vbo_VertexAttrib1fARB;
+ vfmt->VertexAttrib1fvARB = vbo_VertexAttrib1fvARB;
+ vfmt->VertexAttrib2fARB = vbo_VertexAttrib2fARB;
+ vfmt->VertexAttrib2fvARB = vbo_VertexAttrib2fvARB;
+ vfmt->VertexAttrib3fARB = vbo_VertexAttrib3fARB;
+ vfmt->VertexAttrib3fvARB = vbo_VertexAttrib3fvARB;
+ vfmt->VertexAttrib4fARB = vbo_VertexAttrib4fARB;
+ vfmt->VertexAttrib4fvARB = vbo_VertexAttrib4fvARB;
+
+ vfmt->VertexAttrib1fNV = vbo_VertexAttrib1fNV;
+ vfmt->VertexAttrib1fvNV = vbo_VertexAttrib1fvNV;
+ vfmt->VertexAttrib2fNV = vbo_VertexAttrib2fNV;
+ vfmt->VertexAttrib2fvNV = vbo_VertexAttrib2fvNV;
+ vfmt->VertexAttrib3fNV = vbo_VertexAttrib3fNV;
+ vfmt->VertexAttrib3fvNV = vbo_VertexAttrib3fvNV;
+ vfmt->VertexAttrib4fNV = vbo_VertexAttrib4fNV;
+ vfmt->VertexAttrib4fvNV = vbo_VertexAttrib4fvNV;
+
+ /* integer-valued */
+ vfmt->VertexAttribI1i = vbo_VertexAttribI1i;
+ vfmt->VertexAttribI2i = vbo_VertexAttribI2i;
+ vfmt->VertexAttribI3i = vbo_VertexAttribI3i;
+ vfmt->VertexAttribI4i = vbo_VertexAttribI4i;
+ vfmt->VertexAttribI2iv = vbo_VertexAttribI2iv;
+ vfmt->VertexAttribI3iv = vbo_VertexAttribI3iv;
+ vfmt->VertexAttribI4iv = vbo_VertexAttribI4iv;
+
+ /* unsigned integer-valued */
+ vfmt->VertexAttribI1ui = vbo_VertexAttribI1ui;
+ vfmt->VertexAttribI2ui = vbo_VertexAttribI2ui;
+ vfmt->VertexAttribI3ui = vbo_VertexAttribI3ui;
+ vfmt->VertexAttribI4ui = vbo_VertexAttribI4ui;
+ vfmt->VertexAttribI2uiv = vbo_VertexAttribI2uiv;
+ vfmt->VertexAttribI3uiv = vbo_VertexAttribI3uiv;
+ vfmt->VertexAttribI4uiv = vbo_VertexAttribI4uiv;
+
+ vfmt->Materialfv = vbo_Materialfv;
+
+ vfmt->EdgeFlag = vbo_EdgeFlag;
+ vfmt->Indexf = vbo_Indexf;
+ vfmt->Indexfv = vbo_Indexfv;
+
+}
+
+
+#else /* FEATURE_beginend */
+
+
+static void vbo_exec_vtxfmt_init( struct vbo_exec_context *exec )
+{
+ /* silence warnings */
+ (void) vbo_Color3f;
+ (void) vbo_Color3fv;
+ (void) vbo_Color4f;
+ (void) vbo_Color4fv;
+ (void) vbo_FogCoordfEXT;
+ (void) vbo_FogCoordfvEXT;
+ (void) vbo_MultiTexCoord1f;
+ (void) vbo_MultiTexCoord1fv;
+ (void) vbo_MultiTexCoord2f;
+ (void) vbo_MultiTexCoord2fv;
+ (void) vbo_MultiTexCoord3f;
+ (void) vbo_MultiTexCoord3fv;
+ (void) vbo_MultiTexCoord4f;
+ (void) vbo_MultiTexCoord4fv;
+ (void) vbo_Normal3f;
+ (void) vbo_Normal3fv;
+ (void) vbo_SecondaryColor3fEXT;
+ (void) vbo_SecondaryColor3fvEXT;
+ (void) vbo_TexCoord1f;
+ (void) vbo_TexCoord1fv;
+ (void) vbo_TexCoord2f;
+ (void) vbo_TexCoord2fv;
+ (void) vbo_TexCoord3f;
+ (void) vbo_TexCoord3fv;
+ (void) vbo_TexCoord4f;
+ (void) vbo_TexCoord4fv;
+ (void) vbo_Vertex2f;
+ (void) vbo_Vertex2fv;
+ (void) vbo_Vertex3f;
+ (void) vbo_Vertex3fv;
+ (void) vbo_Vertex4f;
+ (void) vbo_Vertex4fv;
+
+ (void) vbo_VertexAttrib1fARB;
+ (void) vbo_VertexAttrib1fvARB;
+ (void) vbo_VertexAttrib2fARB;
+ (void) vbo_VertexAttrib2fvARB;
+ (void) vbo_VertexAttrib3fARB;
+ (void) vbo_VertexAttrib3fvARB;
+ (void) vbo_VertexAttrib4fARB;
+ (void) vbo_VertexAttrib4fvARB;
+
+ (void) vbo_VertexAttrib1fNV;
+ (void) vbo_VertexAttrib1fvNV;
+ (void) vbo_VertexAttrib2fNV;
+ (void) vbo_VertexAttrib2fvNV;
+ (void) vbo_VertexAttrib3fNV;
+ (void) vbo_VertexAttrib3fvNV;
+ (void) vbo_VertexAttrib4fNV;
+ (void) vbo_VertexAttrib4fvNV;
+
+ (void) vbo_Materialfv;
+
+ (void) vbo_EdgeFlag;
+ (void) vbo_Indexf;
+ (void) vbo_Indexfv;
+}
+
+
+#endif /* FEATURE_beginend */
+
+
+/**
+ * Tell the VBO module to use a real OpenGL vertex buffer object to
+ * store accumulated immediate-mode vertex data.
+ * This replaces the malloced buffer which was created in
+ * vb_exec_vtx_init() below.
+ */
+void vbo_use_buffer_objects(struct gl_context *ctx)
+{
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+ /* Any buffer name but 0 can be used here since this bufferobj won't
+ * go into the bufferobj hashtable.
+ */
+ GLuint bufName = IMM_BUFFER_NAME;
+ GLenum target = GL_ARRAY_BUFFER_ARB;
+ GLenum usage = GL_STREAM_DRAW_ARB;
+ GLsizei size = VBO_VERT_BUFFER_SIZE;
+
+ /* Make sure this func is only used once */
+ assert(exec->vtx.bufferobj == ctx->Shared->NullBufferObj);
+ if (exec->vtx.buffer_map) {
+ _mesa_align_free(exec->vtx.buffer_map);
+ exec->vtx.buffer_map = NULL;
+ exec->vtx.buffer_ptr = NULL;
+ }
+
+ /* Allocate a real buffer object now */
+ _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
+ exec->vtx.bufferobj = ctx->Driver.NewBufferObject(ctx, bufName, target);
+ ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj);
+}
+
+
+/**
+ * If this function is called, all VBO buffers will be unmapped when
+ * we flush.
+ * Otherwise, if a simple command like glColor3f() is called and we flush,
+ * the current VBO may be left mapped.
+ */
+void
+vbo_always_unmap_buffers(struct gl_context *ctx)
+{
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+ exec->begin_vertices_flags |= FLUSH_STORED_VERTICES;
+}
+
+
+void vbo_exec_vtx_init( struct vbo_exec_context *exec )
+{
+ struct gl_context *ctx = exec->ctx;
+ struct vbo_context *vbo = vbo_context(ctx);
+ GLuint i;
+
+ /* Allocate a buffer object. Will just reuse this object
+ * continuously, unless vbo_use_buffer_objects() is called to enable
+ * use of real VBOs.
+ */
+ _mesa_reference_buffer_object(ctx,
+ &exec->vtx.bufferobj,
+ ctx->Shared->NullBufferObj);
+
+ ASSERT(!exec->vtx.buffer_map);
+ exec->vtx.buffer_map = (GLfloat *)_mesa_align_malloc(VBO_VERT_BUFFER_SIZE, 64);
+ exec->vtx.buffer_ptr = exec->vtx.buffer_map;
+
+ vbo_exec_vtxfmt_init( exec );
+
+ /* Hook our functions into the dispatch table.
+ */
+ _mesa_install_exec_vtxfmt( ctx, &exec->vtxfmt );
+
+ for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) {
+ ASSERT(i < Elements(exec->vtx.attrsz));
+ exec->vtx.attrsz[i] = 0;
+ ASSERT(i < Elements(exec->vtx.active_sz));
+ exec->vtx.active_sz[i] = 0;
+ }
+ for (i = 0 ; i < VERT_ATTRIB_MAX; i++) {
+ ASSERT(i < Elements(exec->vtx.inputs));
+ ASSERT(i < Elements(exec->vtx.arrays));
+ exec->vtx.inputs[i] = &exec->vtx.arrays[i];
+ }
+
+ {
+ struct gl_client_array *arrays = exec->vtx.arrays;
+ unsigned i;
+
+ memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0]));
+ memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0]));
+
+ for (i = 0; i < 16; ++i) {
+ arrays[i ].BufferObj = NULL;
+ arrays[i + 16].BufferObj = NULL;
+ _mesa_reference_buffer_object(ctx, &arrays[i ].BufferObj,
+ vbo->legacy_currval[i].BufferObj);
+ _mesa_reference_buffer_object(ctx, &arrays[i + 16].BufferObj,
+ vbo->generic_currval[i].BufferObj);
+ }
+ }
+
+ exec->vtx.vertex_size = 0;
+
+ exec->begin_vertices_flags = FLUSH_UPDATE_CURRENT;
+}
+
+
+void vbo_exec_vtx_destroy( struct vbo_exec_context *exec )
+{
+ /* using a real VBO for vertex data */
+ struct gl_context *ctx = exec->ctx;
+ unsigned i;
+
+ /* True VBOs should already be unmapped
+ */
+ if (exec->vtx.buffer_map) {
+ ASSERT(exec->vtx.bufferobj->Name == 0 ||
+ exec->vtx.bufferobj->Name == IMM_BUFFER_NAME);
+ if (exec->vtx.bufferobj->Name == 0) {
+ _mesa_align_free(exec->vtx.buffer_map);
+ exec->vtx.buffer_map = NULL;
+ exec->vtx.buffer_ptr = NULL;
+ }
+ }
+
+ /* Drop any outstanding reference to the vertex buffer
+ */
+ for (i = 0; i < Elements(exec->vtx.arrays); i++) {
+ _mesa_reference_buffer_object(ctx,
+ &exec->vtx.arrays[i].BufferObj,
+ NULL);
+ }
+
+ /* Free the vertex buffer. Unmap first if needed.
+ */
+ if (_mesa_bufferobj_mapped(exec->vtx.bufferobj)) {
+ ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER, exec->vtx.bufferobj);
+ }
+ _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
+}
+
+
+/**
+ * Called upon first glVertex, glColor, glTexCoord, etc.
+ */
+void vbo_exec_BeginVertices( struct gl_context *ctx )
+{
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+
+ vbo_exec_vtx_map( exec );
+
+ assert((ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) == 0);
+ assert(exec->begin_vertices_flags);
+
+ ctx->Driver.NeedFlush |= exec->begin_vertices_flags;
+}
+
+
+/**
+ * Called via ctx->Driver.FlushVertices()
+ * \param flags bitmask of FLUSH_STORED_VERTICES, FLUSH_UPDATE_CURRENT
+ */
+void vbo_exec_FlushVertices( struct gl_context *ctx, GLuint flags )
+{
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+
+#ifdef DEBUG
+ /* debug check: make sure we don't get called recursively */
+ exec->flush_call_depth++;
+ assert(exec->flush_call_depth == 1);
+#endif
+
+ if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
+ /* We've had glBegin but not glEnd! */
+#ifdef DEBUG
+ exec->flush_call_depth--;
+ assert(exec->flush_call_depth == 0);
+#endif
+ return;
+ }
+
+ /* Flush (draw), and make sure VBO is left unmapped when done */
+ vbo_exec_FlushVertices_internal(exec, GL_TRUE);
+
+ /* Need to do this to ensure BeginVertices gets called again:
+ */
+ ctx->Driver.NeedFlush &= ~(FLUSH_UPDATE_CURRENT | flags);
+
+#ifdef DEBUG
+ exec->flush_call_depth--;
+ assert(exec->flush_call_depth == 0);
+#endif
+}
+
+
+static void reset_attrfv( struct vbo_exec_context *exec )
+{
+ GLuint i;
+
+ for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) {
+ exec->vtx.attrsz[i] = 0;
+ exec->vtx.active_sz[i] = 0;
+ }
+
+ exec->vtx.vertex_size = 0;
+}
+
+
+void GLAPIENTRY
+_es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
+{
+ vbo_Color4f(r, g, b, a);
+}
+
+
+void GLAPIENTRY
+_es_Normal3f(GLfloat x, GLfloat y, GLfloat z)
+{
+ vbo_Normal3f(x, y, z);
+}
+
+
+void GLAPIENTRY
+_es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
+{
+ vbo_MultiTexCoord4f(target, s, t, r, q);
+}
+
+
+void GLAPIENTRY
+_es_Materialfv(GLenum face, GLenum pname, const GLfloat *params)
+{
+ vbo_Materialfv(face, pname, params);
+}
+
+
+void GLAPIENTRY
+_es_Materialf(GLenum face, GLenum pname, GLfloat param)
+{
+ GLfloat p[4];
+ p[0] = param;
+ p[1] = p[2] = p[3] = 0.0F;
+ vbo_Materialfv(face, pname, p);
+}
+
+
+/**
+ * A special version of glVertexAttrib4f that does not treat index 0 as
+ * VBO_ATTRIB_POS.
+ */
+static void
+VertexAttrib4f_nopos(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (index < MAX_VERTEX_GENERIC_ATTRIBS)
+ ATTR(VBO_ATTRIB_GENERIC0 + index, 4, x, y, z, w);
+ else
+ ERROR(GL_INVALID_VALUE);
+}
+
+void GLAPIENTRY
+_es_VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ VertexAttrib4f_nopos(index, x, y, z, w);
+}
+
+
+void GLAPIENTRY
+_es_VertexAttrib1f(GLuint indx, GLfloat x)
+{
+ VertexAttrib4f_nopos(indx, x, 0.0f, 0.0f, 1.0f);
+}
+
+
+void GLAPIENTRY
+_es_VertexAttrib1fv(GLuint indx, const GLfloat* values)
+{
+ VertexAttrib4f_nopos(indx, values[0], 0.0f, 0.0f, 1.0f);
+}
+
+
+void GLAPIENTRY
+_es_VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y)
+{
+ VertexAttrib4f_nopos(indx, x, y, 0.0f, 1.0f);
+}
+
+
+void GLAPIENTRY
+_es_VertexAttrib2fv(GLuint indx, const GLfloat* values)
+{
+ VertexAttrib4f_nopos(indx, values[0], values[1], 0.0f, 1.0f);
+}
+
+
+void GLAPIENTRY
+_es_VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
+{
+ VertexAttrib4f_nopos(indx, x, y, z, 1.0f);
+}
+
+
+void GLAPIENTRY
+_es_VertexAttrib3fv(GLuint indx, const GLfloat* values)
+{
+ VertexAttrib4f_nopos(indx, values[0], values[1], values[2], 1.0f);
+}
+
+
+void GLAPIENTRY
+_es_VertexAttrib4fv(GLuint indx, const GLfloat* values)
+{
+ VertexAttrib4f_nopos(indx, values[0], values[1], values[2], values[3]);
+}
diff --git a/mesalib/src/mesa/vbo/vbo_exec_array.c b/mesalib/src/mesa/vbo/vbo_exec_array.c
index 5818b134d..78aba9039 100644
--- a/mesalib/src/mesa/vbo/vbo_exec_array.c
+++ b/mesalib/src/mesa/vbo/vbo_exec_array.c
@@ -1,1325 +1,1325 @@
-/**************************************************************************
- *
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * Copyright 2009 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#include "main/glheader.h"
-#include "main/context.h"
-#include "main/state.h"
-#include "main/api_validate.h"
-#include "main/varray.h"
-#include "main/bufferobj.h"
-#include "main/enums.h"
-#include "main/macros.h"
-
-#include "vbo_context.h"
-
-
-/**
- * All vertex buffers should be in an unmapped state when we're about
- * to draw. This debug function checks that.
- */
-static void
-check_buffers_are_unmapped(const struct gl_client_array **inputs)
-{
-#ifdef DEBUG
- GLuint i;
-
- for (i = 0; i < VERT_ATTRIB_MAX; i++) {
- if (inputs[i]) {
- struct gl_buffer_object *obj = inputs[i]->BufferObj;
- assert(!_mesa_bufferobj_mapped(obj));
- (void) obj;
- }
- }
-#endif
-}
-
-
-/**
- * A debug function that may be called from other parts of Mesa as
- * needed during debugging.
- */
-void
-vbo_check_buffers_are_unmapped(struct gl_context *ctx)
-{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
- /* check the current vertex arrays */
- check_buffers_are_unmapped(exec->array.inputs);
- /* check the current glBegin/glVertex/glEnd-style VBO */
- assert(!_mesa_bufferobj_mapped(exec->vtx.bufferobj));
-}
-
-
-
-/**
- * Compute min and max elements by scanning the index buffer for
- * glDraw[Range]Elements() calls.
- * If primitive restart is enabled, we need to ignore restart
- * indexes when computing min/max.
- */
-void
-vbo_get_minmax_index(struct gl_context *ctx,
- const struct _mesa_prim *prim,
- const struct _mesa_index_buffer *ib,
- GLuint *min_index, GLuint *max_index)
-{
- const GLboolean restart = ctx->Array.PrimitiveRestart;
- const GLuint restartIndex = ctx->Array.RestartIndex;
- const GLuint count = prim->count;
- const void *indices;
- GLuint i;
-
- if (_mesa_is_bufferobj(ib->obj)) {
- const GLvoid *map =
- ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB,
- GL_READ_ONLY, ib->obj);
- indices = ADD_POINTERS(map, ib->ptr);
- } else {
- indices = ib->ptr;
- }
-
- switch (ib->type) {
- case GL_UNSIGNED_INT: {
- const GLuint *ui_indices = (const GLuint *)indices;
- GLuint max_ui = 0;
- GLuint min_ui = ~0U;
- if (restart) {
- for (i = 0; i < count; i++) {
- if (ui_indices[i] != restartIndex) {
- if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
- if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
- }
- }
- }
- else {
- for (i = 0; i < count; i++) {
- if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
- if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
- }
- }
- *min_index = min_ui;
- *max_index = max_ui;
- break;
- }
- case GL_UNSIGNED_SHORT: {
- const GLushort *us_indices = (const GLushort *)indices;
- GLuint max_us = 0;
- GLuint min_us = ~0U;
- if (restart) {
- for (i = 0; i < count; i++) {
- if (us_indices[i] != restartIndex) {
- if (us_indices[i] > max_us) max_us = us_indices[i];
- if (us_indices[i] < min_us) min_us = us_indices[i];
- }
- }
- }
- else {
- for (i = 0; i < count; i++) {
- if (us_indices[i] > max_us) max_us = us_indices[i];
- if (us_indices[i] < min_us) min_us = us_indices[i];
- }
- }
- *min_index = min_us;
- *max_index = max_us;
- break;
- }
- case GL_UNSIGNED_BYTE: {
- const GLubyte *ub_indices = (const GLubyte *)indices;
- GLuint max_ub = 0;
- GLuint min_ub = ~0U;
- if (restart) {
- for (i = 0; i < count; i++) {
- if (ub_indices[i] != restartIndex) {
- if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
- if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
- }
- }
- }
- else {
- for (i = 0; i < count; i++) {
- if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
- if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
- }
- }
- *min_index = min_ub;
- *max_index = max_ub;
- break;
- }
- default:
- assert(0);
- break;
- }
-
- if (_mesa_is_bufferobj(ib->obj)) {
- ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, ib->obj);
- }
-}
-
-
-/**
- * Check that element 'j' of the array has reasonable data.
- * Map VBO if needed.
- * For debugging purposes; not normally used.
- */
-static void
-check_array_data(struct gl_context *ctx, struct gl_client_array *array,
- GLuint attrib, GLuint j)
-{
- if (array->Enabled) {
- const void *data = array->Ptr;
- if (_mesa_is_bufferobj(array->BufferObj)) {
- if (!array->BufferObj->Pointer) {
- /* need to map now */
- array->BufferObj->Pointer =
- ctx->Driver.MapBuffer(ctx, GL_ARRAY_BUFFER_ARB,
- GL_READ_ONLY, array->BufferObj);
- }
- data = ADD_POINTERS(data, array->BufferObj->Pointer);
- }
- switch (array->Type) {
- case GL_FLOAT:
- {
- GLfloat *f = (GLfloat *) ((GLubyte *) data + array->StrideB * j);
- GLint k;
- for (k = 0; k < array->Size; k++) {
- if (IS_INF_OR_NAN(f[k]) ||
- f[k] >= 1.0e20 || f[k] <= -1.0e10) {
- printf("Bad array data:\n");
- printf(" Element[%u].%u = %f\n", j, k, f[k]);
- printf(" Array %u at %p\n", attrib, (void* ) array);
- printf(" Type 0x%x, Size %d, Stride %d\n",
- array->Type, array->Size, array->Stride);
- printf(" Address/offset %p in Buffer Object %u\n",
- array->Ptr, array->BufferObj->Name);
- f[k] = 1.0; /* XXX replace the bad value! */
- }
- /*assert(!IS_INF_OR_NAN(f[k]));*/
- }
- }
- break;
- default:
- ;
- }
- }
-}
-
-
-/**
- * Unmap the buffer object referenced by given array, if mapped.
- */
-static void
-unmap_array_buffer(struct gl_context *ctx, struct gl_client_array *array)
-{
- if (array->Enabled &&
- _mesa_is_bufferobj(array->BufferObj) &&
- _mesa_bufferobj_mapped(array->BufferObj)) {
- ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB, array->BufferObj);
- }
-}
-
-
-/**
- * Examine the array's data for NaNs, etc.
- * For debug purposes; not normally used.
- */
-static void
-check_draw_elements_data(struct gl_context *ctx, GLsizei count, GLenum elemType,
- const void *elements, GLint basevertex)
-{
- struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
- const void *elemMap;
- GLint i, k;
-
- if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
- elemMap = ctx->Driver.MapBuffer(ctx,
- GL_ELEMENT_ARRAY_BUFFER_ARB,
- GL_READ_ONLY,
- ctx->Array.ElementArrayBufferObj);
- elements = ADD_POINTERS(elements, elemMap);
- }
-
- for (i = 0; i < count; i++) {
- GLuint j;
-
- /* j = element[i] */
- switch (elemType) {
- case GL_UNSIGNED_BYTE:
- j = ((const GLubyte *) elements)[i];
- break;
- case GL_UNSIGNED_SHORT:
- j = ((const GLushort *) elements)[i];
- break;
- case GL_UNSIGNED_INT:
- j = ((const GLuint *) elements)[i];
- break;
- default:
- assert(0);
- }
-
- /* check element j of each enabled array */
- check_array_data(ctx, &arrayObj->Vertex, VERT_ATTRIB_POS, j);
- check_array_data(ctx, &arrayObj->Normal, VERT_ATTRIB_NORMAL, j);
- check_array_data(ctx, &arrayObj->Color, VERT_ATTRIB_COLOR0, j);
- check_array_data(ctx, &arrayObj->SecondaryColor, VERT_ATTRIB_COLOR1, j);
- for (k = 0; k < Elements(arrayObj->TexCoord); k++) {
- check_array_data(ctx, &arrayObj->TexCoord[k], VERT_ATTRIB_TEX0 + k, j);
- }
- for (k = 0; k < Elements(arrayObj->VertexAttrib); k++) {
- check_array_data(ctx, &arrayObj->VertexAttrib[k],
- VERT_ATTRIB_GENERIC0 + k, j);
- }
- }
-
- if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
- ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB,
- ctx->Array.ElementArrayBufferObj);
- }
-
- unmap_array_buffer(ctx, &arrayObj->Vertex);
- unmap_array_buffer(ctx, &arrayObj->Normal);
- unmap_array_buffer(ctx, &arrayObj->Color);
- for (k = 0; k < Elements(arrayObj->TexCoord); k++) {
- unmap_array_buffer(ctx, &arrayObj->TexCoord[k]);
- }
- for (k = 0; k < Elements(arrayObj->VertexAttrib); k++) {
- unmap_array_buffer(ctx, &arrayObj->VertexAttrib[k]);
- }
-}
-
-
-/**
- * Check array data, looking for NaNs, etc.
- */
-static void
-check_draw_arrays_data(struct gl_context *ctx, GLint start, GLsizei count)
-{
- /* TO DO */
-}
-
-
-/**
- * Print info/data for glDrawArrays(), for debugging.
- */
-static void
-print_draw_arrays(struct gl_context *ctx,
- GLenum mode, GLint start, GLsizei count)
-{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
- int i;
-
- printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
- mode, start, count);
-
- for (i = 0; i < 32; i++) {
- GLuint bufName = exec->array.inputs[i]->BufferObj->Name;
- GLint stride = exec->array.inputs[i]->Stride;
- printf("attr %2d: size %d stride %d enabled %d "
- "ptr %p Bufobj %u\n",
- i,
- exec->array.inputs[i]->Size,
- stride,
- /*exec->array.inputs[i]->Enabled,*/
- exec->array.legacy_array[i]->Enabled,
- exec->array.inputs[i]->Ptr,
- bufName);
-
- if (bufName) {
- struct gl_buffer_object *buf = _mesa_lookup_bufferobj(ctx, bufName);
- GLubyte *p = ctx->Driver.MapBuffer(ctx, GL_ARRAY_BUFFER_ARB,
- GL_READ_ONLY_ARB, buf);
- int offset = (int) (GLintptr) exec->array.inputs[i]->Ptr;
- float *f = (float *) (p + offset);
- int *k = (int *) f;
- int i;
- int n = (count * stride) / 4;
- if (n > 32)
- n = 32;
- printf(" Data at offset %d:\n", offset);
- for (i = 0; i < n; i++) {
- printf(" float[%d] = 0x%08x %f\n", i, k[i], f[i]);
- }
- ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB, buf);
- }
- }
-}
-
-
-/**
- * Bind the VBO executor to the current vertex array object prior
- * to drawing.
- *
- * Just translate the arrayobj into a sane layout.
- */
-static void
-bind_array_obj(struct gl_context *ctx)
-{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
- struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
- GLuint i;
-
- /* TODO: Fix the ArrayObj struct to keep legacy arrays in an array
- * rather than as individual named arrays. Then this function can
- * go away.
- */
- exec->array.legacy_array[VERT_ATTRIB_POS] = &arrayObj->Vertex;
- exec->array.legacy_array[VERT_ATTRIB_WEIGHT] = &arrayObj->Weight;
- exec->array.legacy_array[VERT_ATTRIB_NORMAL] = &arrayObj->Normal;
- exec->array.legacy_array[VERT_ATTRIB_COLOR0] = &arrayObj->Color;
- exec->array.legacy_array[VERT_ATTRIB_COLOR1] = &arrayObj->SecondaryColor;
- exec->array.legacy_array[VERT_ATTRIB_FOG] = &arrayObj->FogCoord;
- exec->array.legacy_array[VERT_ATTRIB_COLOR_INDEX] = &arrayObj->Index;
- if (arrayObj->PointSize.Enabled) {
- /* this aliases COLOR_INDEX */
- exec->array.legacy_array[VERT_ATTRIB_POINT_SIZE] = &arrayObj->PointSize;
- }
- exec->array.legacy_array[VERT_ATTRIB_EDGEFLAG] = &arrayObj->EdgeFlag;
-
- for (i = 0; i < Elements(arrayObj->TexCoord); i++)
- exec->array.legacy_array[VERT_ATTRIB_TEX0 + i] = &arrayObj->TexCoord[i];
-
- for (i = 0; i < Elements(arrayObj->VertexAttrib); i++) {
- assert(i < Elements(exec->array.generic_array));
- exec->array.generic_array[i] = &arrayObj->VertexAttrib[i];
- }
-
- exec->array.array_obj = arrayObj->Name;
-}
-
-
-/**
- * Set the vbo->exec->inputs[] pointers to point to the enabled
- * vertex arrays. This depends on the current vertex program/shader
- * being executed because of whether or not generic vertex arrays
- * alias the conventional vertex arrays.
- * For arrays that aren't enabled, we set the input[attrib] pointer
- * to point at a zero-stride current value "array".
- */
-static void
-recalculate_input_bindings(struct gl_context *ctx)
-{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
- const struct gl_client_array **inputs = &exec->array.inputs[0];
- GLbitfield const_inputs = 0x0;
- GLuint i;
-
- exec->array.program_mode = get_program_mode(ctx);
- exec->array.enabled_flags = ctx->Array.ArrayObj->_Enabled;
-
- switch (exec->array.program_mode) {
- case VP_NONE:
- /* When no vertex program is active (or the vertex program is generated
- * from fixed-function state). We put the material values into the
- * generic slots. This is the only situation where material values
- * are available as per-vertex attributes.
- */
- for (i = 0; i <= VERT_ATTRIB_TEX7; i++) {
- if (exec->array.legacy_array[i]->Enabled)
- inputs[i] = exec->array.legacy_array[i];
- else {
- inputs[i] = &vbo->legacy_currval[i];
- const_inputs |= 1 << i;
- }
- }
-
- for (i = 0; i < MAT_ATTRIB_MAX; i++) {
- inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->mat_currval[i];
- const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
- }
-
- /* Could use just about anything, just to fill in the empty
- * slots:
- */
- for (i = MAT_ATTRIB_MAX; i < VERT_ATTRIB_MAX - VERT_ATTRIB_GENERIC0; i++) {
- inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
- const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
- }
- break;
-
- case VP_NV:
- /* NV_vertex_program - attribute arrays alias and override
- * conventional, legacy arrays. No materials, and the generic
- * slots are vacant.
- */
- for (i = 0; i <= VERT_ATTRIB_TEX7; i++) {
- if (exec->array.generic_array[i]->Enabled)
- inputs[i] = exec->array.generic_array[i];
- else if (exec->array.legacy_array[i]->Enabled)
- inputs[i] = exec->array.legacy_array[i];
- else {
- inputs[i] = &vbo->legacy_currval[i];
- const_inputs |= 1 << i;
- }
- }
-
- /* Could use just about anything, just to fill in the empty
- * slots:
- */
- for (i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++) {
- inputs[i] = &vbo->generic_currval[i - VERT_ATTRIB_GENERIC0];
- const_inputs |= 1 << i;
- }
- break;
-
- case VP_ARB:
- /* GL_ARB_vertex_program or GLSL vertex shader - Only the generic[0]
- * attribute array aliases and overrides the legacy position array.
- *
- * Otherwise, legacy attributes available in the legacy slots,
- * generic attributes in the generic slots and materials are not
- * available as per-vertex attributes.
- */
- if (exec->array.generic_array[0]->Enabled)
- inputs[0] = exec->array.generic_array[0];
- else if (exec->array.legacy_array[0]->Enabled)
- inputs[0] = exec->array.legacy_array[0];
- else {
- inputs[0] = &vbo->legacy_currval[0];
- const_inputs |= 1 << 0;
- }
-
- for (i = 1; i <= VERT_ATTRIB_TEX7; i++) {
- if (exec->array.legacy_array[i]->Enabled)
- inputs[i] = exec->array.legacy_array[i];
- else {
- inputs[i] = &vbo->legacy_currval[i];
- const_inputs |= 1 << i;
- }
- }
-
- for (i = 0; i < MAX_VERTEX_GENERIC_ATTRIBS; i++) {
- if (exec->array.generic_array[i]->Enabled)
- inputs[VERT_ATTRIB_GENERIC0 + i] = exec->array.generic_array[i];
- else {
- inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
- const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
- }
-
- }
- break;
- }
-
- _mesa_set_varying_vp_inputs( ctx, ~const_inputs );
-}
-
-
-/**
- * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
- * These will point to the arrays to actually use for drawing. Some will
- * be user-provided arrays, other will be zero-stride const-valued arrays.
- * Note that this might set the _NEW_ARRAY dirty flag so state validation
- * must be done after this call.
- */
-static void
-bind_arrays(struct gl_context *ctx)
-{
- if (!ctx->Array.RebindArrays) {
- return;
- }
-
- bind_array_obj(ctx);
- recalculate_input_bindings(ctx);
- ctx->Array.RebindArrays = GL_FALSE;
-}
-
-
-/**
- * Helper function called by the other DrawArrays() functions below.
- * This is where we handle primitive restart for drawing non-indexed
- * arrays. If primitive restart is enabled, it typically means
- * splitting one DrawArrays() into two.
- */
-static void
-vbo_draw_arrays(struct gl_context *ctx, GLenum mode, GLint start,
- GLsizei count, GLuint numInstances)
-{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
- struct _mesa_prim prim[2];
-
- bind_arrays(ctx);
-
- /* Again... because we may have changed the bitmask of per-vertex varying
- * attributes. If we regenerate the fixed-function vertex program now
- * we may be able to prune down the number of vertex attributes which we
- * need in the shader.
- */
- if (ctx->NewState)
- _mesa_update_state(ctx);
-
- prim[0].begin = 1;
- prim[0].end = 1;
- prim[0].weak = 0;
- prim[0].pad = 0;
- prim[0].mode = mode;
- prim[0].start = 0; /* filled in below */
- prim[0].count = 0; /* filled in below */
- prim[0].indexed = 0;
- prim[0].basevertex = 0;
- prim[0].num_instances = numInstances;
-
- /* Implement the primitive restart index */
- if (ctx->Array.PrimitiveRestart && ctx->Array.RestartIndex < count) {
- GLuint primCount = 0;
-
- if (ctx->Array.RestartIndex == start) {
- /* special case: RestartIndex at beginning */
- if (count > 1) {
- prim[0].start = start + 1;
- prim[0].count = count - 1;
- primCount = 1;
- }
- }
- else if (ctx->Array.RestartIndex == start + count - 1) {
- /* special case: RestartIndex at end */
- if (count > 1) {
- prim[0].start = start;
- prim[0].count = count - 1;
- primCount = 1;
- }
- }
- else {
- /* general case: RestartIndex in middle, split into two prims */
- prim[0].start = start;
- prim[0].count = ctx->Array.RestartIndex - start;
-
- prim[1] = prim[0];
- prim[1].start = ctx->Array.RestartIndex + 1;
- prim[1].count = count - prim[1].start;
-
- primCount = 2;
- }
-
- if (primCount > 0) {
- /* draw one or two prims */
- check_buffers_are_unmapped(exec->array.inputs);
- vbo->draw_prims(ctx, exec->array.inputs, prim, primCount, NULL,
- GL_TRUE, start, start + count - 1);
- }
- }
- else {
- /* no prim restart */
- prim[0].start = start;
- prim[0].count = count;
-
- check_buffers_are_unmapped(exec->array.inputs);
- vbo->draw_prims(ctx, exec->array.inputs, prim, 1, NULL,
- GL_TRUE, start, start + count - 1);
- }
-}
-
-
-
-/**
- * Called from glDrawArrays when in immediate mode (not display list mode).
- */
-static void GLAPIENTRY
-vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if (MESA_VERBOSE & VERBOSE_DRAW)
- _mesa_debug(ctx, "glDrawArrays(%s, %d, %d)\n",
- _mesa_lookup_enum_by_nr(mode), start, count);
-
- if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
- return;
-
- FLUSH_CURRENT( ctx, 0 );
-
- if (!_mesa_valid_to_render(ctx, "glDrawArrays")) {
- return;
- }
-
- if (0)
- check_draw_arrays_data(ctx, start, count);
-
- vbo_draw_arrays(ctx, mode, start, count, 1);
-
- if (0)
- print_draw_arrays(ctx, mode, start, count);
-}
-
-
-/**
- * Called from glDrawArraysInstanced when in immediate mode (not
- * display list mode).
- */
-static void GLAPIENTRY
-vbo_exec_DrawArraysInstanced(GLenum mode, GLint start, GLsizei count,
- GLsizei numInstances)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if (MESA_VERBOSE & VERBOSE_DRAW)
- _mesa_debug(ctx, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
- _mesa_lookup_enum_by_nr(mode), start, count, numInstances);
-
- if (!_mesa_validate_DrawArraysInstanced(ctx, mode, start, count, numInstances))
- return;
-
- FLUSH_CURRENT( ctx, 0 );
-
- if (!_mesa_valid_to_render(ctx, "glDrawArraysInstanced")) {
- return;
- }
-
- if (0)
- check_draw_arrays_data(ctx, start, count);
-
- vbo_draw_arrays(ctx, mode, start, count, numInstances);
-
- if (0)
- print_draw_arrays(ctx, mode, start, count);
-}
-
-
-/**
- * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
- * For debugging.
- */
-static void
-dump_element_buffer(struct gl_context *ctx, GLenum type)
-{
- const GLvoid *map = ctx->Driver.MapBuffer(ctx,
- GL_ELEMENT_ARRAY_BUFFER_ARB,
- GL_READ_ONLY,
- ctx->Array.ElementArrayBufferObj);
- switch (type) {
- case GL_UNSIGNED_BYTE:
- {
- const GLubyte *us = (const GLubyte *) map;
- GLint i;
- for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size; i++) {
- printf("%02x ", us[i]);
- if (i % 32 == 31)
- printf("\n");
- }
- printf("\n");
- }
- break;
- case GL_UNSIGNED_SHORT:
- {
- const GLushort *us = (const GLushort *) map;
- GLint i;
- for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size / 2; i++) {
- printf("%04x ", us[i]);
- if (i % 16 == 15)
- printf("\n");
- }
- printf("\n");
- }
- break;
- case GL_UNSIGNED_INT:
- {
- const GLuint *us = (const GLuint *) map;
- GLint i;
- for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size / 4; i++) {
- printf("%08x ", us[i]);
- if (i % 8 == 7)
- printf("\n");
- }
- printf("\n");
- }
- break;
- default:
- ;
- }
-
- ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB,
- ctx->Array.ElementArrayBufferObj);
-}
-
-
-/**
- * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
- * Do the rendering for a glDrawElements or glDrawRangeElements call after
- * we've validated buffer bounds, etc.
- */
-static void
-vbo_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
- GLboolean index_bounds_valid,
- GLuint start, GLuint end,
- GLsizei count, GLenum type,
- const GLvoid *indices,
- GLint basevertex, GLint numInstances)
-{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
- struct _mesa_index_buffer ib;
- struct _mesa_prim prim[1];
-
- FLUSH_CURRENT( ctx, 0 );
-
- if (!_mesa_valid_to_render(ctx, "glDraw[Range]Elements")) {
- return;
- }
-
- bind_arrays( ctx );
-
- /* check for dirty state again */
- if (ctx->NewState)
- _mesa_update_state( ctx );
-
- ib.count = count;
- ib.type = type;
- ib.obj = ctx->Array.ElementArrayBufferObj;
- ib.ptr = indices;
-
- prim[0].begin = 1;
- prim[0].end = 1;
- prim[0].weak = 0;
- prim[0].pad = 0;
- prim[0].mode = mode;
- prim[0].start = 0;
- prim[0].count = count;
- prim[0].indexed = 1;
- prim[0].basevertex = basevertex;
- prim[0].num_instances = numInstances;
-
- /* Need to give special consideration to rendering a range of
- * indices starting somewhere above zero. Typically the
- * application is issuing multiple DrawRangeElements() to draw
- * successive primitives layed out linearly in the vertex arrays.
- * Unless the vertex arrays are all in a VBO (or locked as with
- * CVA), the OpenGL semantics imply that we need to re-read or
- * re-upload the vertex data on each draw call.
- *
- * In the case of hardware tnl, we want to avoid starting the
- * upload at zero, as it will mean every draw call uploads an
- * increasing amount of not-used vertex data. Worse - in the
- * software tnl module, all those vertices might be transformed and
- * lit but never rendered.
- *
- * If we just upload or transform the vertices in start..end,
- * however, the indices will be incorrect.
- *
- * At this level, we don't know exactly what the requirements of
- * the backend are going to be, though it will likely boil down to
- * either:
- *
- * 1) Do nothing, everything is in a VBO and is processed once
- * only.
- *
- * 2) Adjust the indices and vertex arrays so that start becomes
- * zero.
- *
- * Rather than doing anything here, I'll provide a helper function
- * for the latter case elsewhere.
- */
-
- check_buffers_are_unmapped(exec->array.inputs);
- vbo->draw_prims( ctx, exec->array.inputs, prim, 1, &ib,
- index_bounds_valid, start, end );
-}
-
-
-/**
- * Called by glDrawRangeElementsBaseVertex() in immediate mode.
- */
-static void GLAPIENTRY
-vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
- GLuint start, GLuint end,
- GLsizei count, GLenum type,
- const GLvoid *indices,
- GLint basevertex)
-{
- static GLuint warnCount = 0;
- GET_CURRENT_CONTEXT(ctx);
-
- if (MESA_VERBOSE & VERBOSE_DRAW)
- _mesa_debug(ctx,
- "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
- _mesa_lookup_enum_by_nr(mode), start, end, count,
- _mesa_lookup_enum_by_nr(type), indices, basevertex);
-
- if (!_mesa_validate_DrawRangeElements( ctx, mode, start, end, count,
- type, indices, basevertex ))
- return;
-
- /* NOTE: It's important that 'end' is a reasonable value.
- * in _tnl_draw_prims(), we use end to determine how many vertices
- * to transform. If it's too large, we can unnecessarily split prims
- * or we can read/write out of memory in several different places!
- */
-
- /* Catch/fix some potential user errors */
- if (type == GL_UNSIGNED_BYTE) {
- start = MIN2(start, 0xff);
- end = MIN2(end, 0xff);
- }
- else if (type == GL_UNSIGNED_SHORT) {
- start = MIN2(start, 0xffff);
- end = MIN2(end, 0xffff);
- }
-
- if (end >= ctx->Array.ArrayObj->_MaxElement) {
- /* the max element is out of bounds of one or more enabled arrays */
- warnCount++;
-
- if (warnCount < 10) {
- _mesa_warning(ctx, "glDraw[Range]Elements(start %u, end %u, count %d, "
- "type 0x%x, indices=%p)\n"
- "\tend is out of bounds (max=%u) "
- "Element Buffer %u (size %d)\n"
- "\tThis should probably be fixed in the application.",
- start, end, count, type, indices,
- ctx->Array.ArrayObj->_MaxElement - 1,
- ctx->Array.ElementArrayBufferObj->Name,
- (int) ctx->Array.ElementArrayBufferObj->Size);
- }
-
- if (0)
- dump_element_buffer(ctx, type);
-
- if (0)
- _mesa_print_arrays(ctx);
-
-#ifdef DEBUG
- /* 'end' was out of bounds, but now let's check the actual array
- * indexes to see if any of them are out of bounds.
- */
- {
- GLuint max = _mesa_max_buffer_index(ctx, count, type, indices,
- ctx->Array.ElementArrayBufferObj);
- if (max >= ctx->Array.ArrayObj->_MaxElement) {
- if (warnCount < 10) {
- _mesa_warning(ctx, "glDraw[Range]Elements(start %u, end %u, "
- "count %d, type 0x%x, indices=%p)\n"
- "\tindex=%u is out of bounds (max=%u) "
- "Element Buffer %u (size %d)\n"
- "\tSkipping the glDrawRangeElements() call",
- start, end, count, type, indices, max,
- ctx->Array.ArrayObj->_MaxElement - 1,
- ctx->Array.ElementArrayBufferObj->Name,
- (int) ctx->Array.ElementArrayBufferObj->Size);
- }
- }
- /* XXX we could also find the min index and compare to 'start'
- * to see if start is correct. But it's more likely to get the
- * upper bound wrong.
- */
- }
-#endif
-
- /* Set 'end' to the max possible legal value */
- assert(ctx->Array.ArrayObj->_MaxElement >= 1);
- end = ctx->Array.ArrayObj->_MaxElement - 1;
- }
- else if (0) {
- printf("glDraw[Range]Elements{,BaseVertex}"
- "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
- "base %d\n",
- start, end, type, count,
- ctx->Array.ElementArrayBufferObj->Name,
- basevertex);
- }
-
-#if 0
- check_draw_elements_data(ctx, count, type, indices);
-#else
- (void) check_draw_elements_data;
-#endif
-
- vbo_validated_drawrangeelements(ctx, mode, GL_TRUE, start, end,
- count, type, indices, basevertex, 1);
-}
-
-
-/**
- * Called by glDrawRangeElements() in immediate mode.
- */
-static void GLAPIENTRY
-vbo_exec_DrawRangeElements(GLenum mode, GLuint start, GLuint end,
- GLsizei count, GLenum type, const GLvoid *indices)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if (MESA_VERBOSE & VERBOSE_DRAW)
- _mesa_debug(ctx,
- "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
- _mesa_lookup_enum_by_nr(mode), start, end, count,
- _mesa_lookup_enum_by_nr(type), indices);
-
- vbo_exec_DrawRangeElementsBaseVertex(mode, start, end, count, type,
- indices, 0);
-}
-
-
-/**
- * Called by glDrawElements() in immediate mode.
- */
-static void GLAPIENTRY
-vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type,
- const GLvoid *indices)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if (MESA_VERBOSE & VERBOSE_DRAW)
- _mesa_debug(ctx, "glDrawElements(%s, %u, %s, %p)\n",
- _mesa_lookup_enum_by_nr(mode), count,
- _mesa_lookup_enum_by_nr(type), indices);
-
- if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, 0 ))
- return;
-
- vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
- count, type, indices, 0, 1);
-}
-
-
-/**
- * Called by glDrawElementsBaseVertex() in immediate mode.
- */
-static void GLAPIENTRY
-vbo_exec_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
- const GLvoid *indices, GLint basevertex)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if (MESA_VERBOSE & VERBOSE_DRAW)
- _mesa_debug(ctx, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
- _mesa_lookup_enum_by_nr(mode), count,
- _mesa_lookup_enum_by_nr(type), indices, basevertex);
-
- if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices,
- basevertex ))
- return;
-
- vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
- count, type, indices, basevertex, 1);
-}
-
-
-/**
- * Called by glDrawElementsInstanced() in immediate mode.
- */
-static void GLAPIENTRY
-vbo_exec_DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
- const GLvoid *indices, GLsizei numInstances)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if (MESA_VERBOSE & VERBOSE_DRAW)
- _mesa_debug(ctx, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
- _mesa_lookup_enum_by_nr(mode), count,
- _mesa_lookup_enum_by_nr(type), indices, numInstances);
-
- if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
- numInstances))
- return;
-
- vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
- count, type, indices, 0, numInstances);
-}
-
-
-/**
- * Inner support for both _mesa_MultiDrawElements() and
- * _mesa_MultiDrawRangeElements().
- * This does the actual rendering after we've checked array indexes, etc.
- */
-static void
-vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
- const GLsizei *count, GLenum type,
- const GLvoid **indices, GLsizei primcount,
- const GLint *basevertex)
-{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
- struct _mesa_index_buffer ib;
- struct _mesa_prim *prim;
- unsigned int index_type_size = 0;
- uintptr_t min_index_ptr, max_index_ptr;
- GLboolean fallback = GL_FALSE;
- int i;
-
- if (primcount == 0)
- return;
-
- FLUSH_CURRENT( ctx, 0 );
-
- if (!_mesa_valid_to_render(ctx, "glMultiDrawElements")) {
- return;
- }
-
- prim = calloc(1, primcount * sizeof(*prim));
- if (prim == NULL) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMultiDrawElements");
- return;
- }
-
- /* Decide if we can do this all as one set of primitives sharing the
- * same index buffer, or if we have to reset the index pointer per
- * primitive.
- */
- bind_arrays( ctx );
-
- /* check for dirty state again */
- if (ctx->NewState)
- _mesa_update_state( ctx );
-
- switch (type) {
- case GL_UNSIGNED_INT:
- index_type_size = 4;
- break;
- case GL_UNSIGNED_SHORT:
- index_type_size = 2;
- break;
- case GL_UNSIGNED_BYTE:
- index_type_size = 1;
- break;
- default:
- assert(0);
- }
-
- min_index_ptr = (uintptr_t)indices[0];
- max_index_ptr = 0;
- for (i = 0; i < primcount; i++) {
- min_index_ptr = MIN2(min_index_ptr, (uintptr_t)indices[i]);
- max_index_ptr = MAX2(max_index_ptr, (uintptr_t)indices[i] +
- index_type_size * count[i]);
- }
-
- /* Check if we can handle this thing as a bunch of index offsets from the
- * same index pointer. If we can't, then we have to fall back to doing
- * a draw_prims per primitive.
- * Check that the difference between each prim's indexes is a multiple of
- * the index/element size.
- */
- if (index_type_size != 1) {
- for (i = 0; i < primcount; i++) {
- if ((((uintptr_t)indices[i] - min_index_ptr) % index_type_size) != 0) {
- fallback = GL_TRUE;
- break;
- }
- }
- }
-
- /* If the index buffer isn't in a VBO, then treating the application's
- * subranges of the index buffer as one large index buffer may lead to
- * us reading unmapped memory.
- */
- if (!_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj))
- fallback = GL_TRUE;
-
- if (!fallback) {
- ib.count = (max_index_ptr - min_index_ptr) / index_type_size;
- ib.type = type;
- ib.obj = ctx->Array.ElementArrayBufferObj;
- ib.ptr = (void *)min_index_ptr;
-
- for (i = 0; i < primcount; i++) {
- prim[i].begin = (i == 0);
- prim[i].end = (i == primcount - 1);
- prim[i].weak = 0;
- prim[i].pad = 0;
- prim[i].mode = mode;
- prim[i].start = ((uintptr_t)indices[i] - min_index_ptr) / index_type_size;
- prim[i].count = count[i];
- prim[i].indexed = 1;
- prim[i].num_instances = 1;
- if (basevertex != NULL)
- prim[i].basevertex = basevertex[i];
- else
- prim[i].basevertex = 0;
- }
-
- check_buffers_are_unmapped(exec->array.inputs);
- vbo->draw_prims(ctx, exec->array.inputs, prim, primcount, &ib,
- GL_FALSE, ~0, ~0);
- } else {
- /* render one prim at a time */
- for (i = 0; i < primcount; i++) {
- ib.count = count[i];
- ib.type = type;
- ib.obj = ctx->Array.ElementArrayBufferObj;
- ib.ptr = indices[i];
-
- prim[0].begin = 1;
- prim[0].end = 1;
- prim[0].weak = 0;
- prim[0].pad = 0;
- prim[0].mode = mode;
- prim[0].start = 0;
- prim[0].count = count[i];
- prim[0].indexed = 1;
- prim[0].num_instances = 1;
- if (basevertex != NULL)
- prim[0].basevertex = basevertex[i];
- else
- prim[0].basevertex = 0;
-
- check_buffers_are_unmapped(exec->array.inputs);
- vbo->draw_prims(ctx, exec->array.inputs, prim, 1, &ib,
- GL_FALSE, ~0, ~0);
- }
- }
-
- free(prim);
-}
-
-
-static void GLAPIENTRY
-vbo_exec_MultiDrawElements(GLenum mode,
- const GLsizei *count, GLenum type,
- const GLvoid **indices,
- GLsizei primcount)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- for (i = 0; i < primcount; i++) {
- if (!_mesa_validate_DrawElements(ctx, mode, count[i], type, indices[i],
- 0))
- return;
- }
-
- vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
- NULL);
-}
-
-
-static void GLAPIENTRY
-vbo_exec_MultiDrawElementsBaseVertex(GLenum mode,
- const GLsizei *count, GLenum type,
- const GLvoid **indices,
- GLsizei primcount,
- const GLsizei *basevertex)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- for (i = 0; i < primcount; i++) {
- if (!_mesa_validate_DrawElements(ctx, mode, count[i], type, indices[i],
- basevertex[i]))
- return;
- }
-
- vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
- basevertex);
-}
-
-
-/**
- * Plug in the immediate-mode vertex array drawing commands into the
- * givven vbo_exec_context object.
- */
-void
-vbo_exec_array_init( struct vbo_exec_context *exec )
-{
- exec->vtxfmt.DrawArrays = vbo_exec_DrawArrays;
- exec->vtxfmt.DrawElements = vbo_exec_DrawElements;
- exec->vtxfmt.DrawRangeElements = vbo_exec_DrawRangeElements;
- exec->vtxfmt.MultiDrawElementsEXT = vbo_exec_MultiDrawElements;
- exec->vtxfmt.DrawElementsBaseVertex = vbo_exec_DrawElementsBaseVertex;
- exec->vtxfmt.DrawRangeElementsBaseVertex = vbo_exec_DrawRangeElementsBaseVertex;
- exec->vtxfmt.MultiDrawElementsBaseVertex = vbo_exec_MultiDrawElementsBaseVertex;
- exec->vtxfmt.DrawArraysInstanced = vbo_exec_DrawArraysInstanced;
- exec->vtxfmt.DrawElementsInstanced = vbo_exec_DrawElementsInstanced;
-}
-
-
-void
-vbo_exec_array_destroy( struct vbo_exec_context *exec )
-{
- /* nothing to do */
-}
-
-
-
-/**
- * The following functions are only used for OpenGL ES 1/2 support.
- * And some aren't even supported (yet) in ES 1/2.
- */
-
-
-void GLAPIENTRY
-_mesa_DrawArrays(GLenum mode, GLint first, GLsizei count)
-{
- vbo_exec_DrawArrays(mode, first, count);
-}
-
-
-void GLAPIENTRY
-_mesa_DrawElements(GLenum mode, GLsizei count, GLenum type,
- const GLvoid *indices)
-{
- vbo_exec_DrawElements(mode, count, type, indices);
-}
-
-
-void GLAPIENTRY
-_mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
- const GLvoid *indices, GLint basevertex)
-{
- vbo_exec_DrawElementsBaseVertex(mode, count, type, indices, basevertex);
-}
-
-
-void GLAPIENTRY
-_mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
- GLenum type, const GLvoid *indices)
-{
- vbo_exec_DrawRangeElements(mode, start, end, count, type, indices);
-}
-
-
-void GLAPIENTRY
-_mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
- GLsizei count, GLenum type,
- const GLvoid *indices, GLint basevertex)
-{
- vbo_exec_DrawRangeElementsBaseVertex(mode, start, end, count, type,
- indices, basevertex);
-}
-
-
-void GLAPIENTRY
-_mesa_MultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type,
- const GLvoid **indices, GLsizei primcount)
-{
- vbo_exec_MultiDrawElements(mode, count, type, indices, primcount);
-}
-
-
-void GLAPIENTRY
-_mesa_MultiDrawElementsBaseVertex(GLenum mode,
- const GLsizei *count, GLenum type,
- const GLvoid **indices, GLsizei primcount,
- const GLint *basevertex)
-{
- vbo_exec_MultiDrawElementsBaseVertex(mode, count, type, indices,
- primcount, basevertex);
-}
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/state.h"
+#include "main/api_validate.h"
+#include "main/varray.h"
+#include "main/bufferobj.h"
+#include "main/enums.h"
+#include "main/macros.h"
+
+#include "vbo_context.h"
+
+
+/**
+ * All vertex buffers should be in an unmapped state when we're about
+ * to draw. This debug function checks that.
+ */
+static void
+check_buffers_are_unmapped(const struct gl_client_array **inputs)
+{
+#ifdef DEBUG
+ GLuint i;
+
+ for (i = 0; i < VERT_ATTRIB_MAX; i++) {
+ if (inputs[i]) {
+ struct gl_buffer_object *obj = inputs[i]->BufferObj;
+ assert(!_mesa_bufferobj_mapped(obj));
+ (void) obj;
+ }
+ }
+#endif
+}
+
+
+/**
+ * A debug function that may be called from other parts of Mesa as
+ * needed during debugging.
+ */
+void
+vbo_check_buffers_are_unmapped(struct gl_context *ctx)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_exec_context *exec = &vbo->exec;
+ /* check the current vertex arrays */
+ check_buffers_are_unmapped(exec->array.inputs);
+ /* check the current glBegin/glVertex/glEnd-style VBO */
+ assert(!_mesa_bufferobj_mapped(exec->vtx.bufferobj));
+}
+
+
+
+/**
+ * Compute min and max elements by scanning the index buffer for
+ * glDraw[Range]Elements() calls.
+ * If primitive restart is enabled, we need to ignore restart
+ * indexes when computing min/max.
+ */
+void
+vbo_get_minmax_index(struct gl_context *ctx,
+ const struct _mesa_prim *prim,
+ const struct _mesa_index_buffer *ib,
+ GLuint *min_index, GLuint *max_index)
+{
+ const GLboolean restart = ctx->Array.PrimitiveRestart;
+ const GLuint restartIndex = ctx->Array.RestartIndex;
+ const GLuint count = prim->count;
+ const void *indices;
+ GLuint i;
+
+ if (_mesa_is_bufferobj(ib->obj)) {
+ const GLvoid *map =
+ ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB,
+ GL_READ_ONLY, ib->obj);
+ indices = ADD_POINTERS(map, ib->ptr);
+ } else {
+ indices = ib->ptr;
+ }
+
+ switch (ib->type) {
+ case GL_UNSIGNED_INT: {
+ const GLuint *ui_indices = (const GLuint *)indices;
+ GLuint max_ui = 0;
+ GLuint min_ui = ~0U;
+ if (restart) {
+ for (i = 0; i < count; i++) {
+ if (ui_indices[i] != restartIndex) {
+ if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
+ if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
+ if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
+ }
+ }
+ *min_index = min_ui;
+ *max_index = max_ui;
+ break;
+ }
+ case GL_UNSIGNED_SHORT: {
+ const GLushort *us_indices = (const GLushort *)indices;
+ GLuint max_us = 0;
+ GLuint min_us = ~0U;
+ if (restart) {
+ for (i = 0; i < count; i++) {
+ if (us_indices[i] != restartIndex) {
+ if (us_indices[i] > max_us) max_us = us_indices[i];
+ if (us_indices[i] < min_us) min_us = us_indices[i];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ if (us_indices[i] > max_us) max_us = us_indices[i];
+ if (us_indices[i] < min_us) min_us = us_indices[i];
+ }
+ }
+ *min_index = min_us;
+ *max_index = max_us;
+ break;
+ }
+ case GL_UNSIGNED_BYTE: {
+ const GLubyte *ub_indices = (const GLubyte *)indices;
+ GLuint max_ub = 0;
+ GLuint min_ub = ~0U;
+ if (restart) {
+ for (i = 0; i < count; i++) {
+ if (ub_indices[i] != restartIndex) {
+ if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
+ if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
+ if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
+ }
+ }
+ *min_index = min_ub;
+ *max_index = max_ub;
+ break;
+ }
+ default:
+ assert(0);
+ break;
+ }
+
+ if (_mesa_is_bufferobj(ib->obj)) {
+ ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, ib->obj);
+ }
+}
+
+
+/**
+ * Check that element 'j' of the array has reasonable data.
+ * Map VBO if needed.
+ * For debugging purposes; not normally used.
+ */
+static void
+check_array_data(struct gl_context *ctx, struct gl_client_array *array,
+ GLuint attrib, GLuint j)
+{
+ if (array->Enabled) {
+ const void *data = array->Ptr;
+ if (_mesa_is_bufferobj(array->BufferObj)) {
+ if (!array->BufferObj->Pointer) {
+ /* need to map now */
+ array->BufferObj->Pointer =
+ ctx->Driver.MapBuffer(ctx, GL_ARRAY_BUFFER_ARB,
+ GL_READ_ONLY, array->BufferObj);
+ }
+ data = ADD_POINTERS(data, array->BufferObj->Pointer);
+ }
+ switch (array->Type) {
+ case GL_FLOAT:
+ {
+ GLfloat *f = (GLfloat *) ((GLubyte *) data + array->StrideB * j);
+ GLint k;
+ for (k = 0; k < array->Size; k++) {
+ if (IS_INF_OR_NAN(f[k]) ||
+ f[k] >= 1.0e20 || f[k] <= -1.0e10) {
+ printf("Bad array data:\n");
+ printf(" Element[%u].%u = %f\n", j, k, f[k]);
+ printf(" Array %u at %p\n", attrib, (void* ) array);
+ printf(" Type 0x%x, Size %d, Stride %d\n",
+ array->Type, array->Size, array->Stride);
+ printf(" Address/offset %p in Buffer Object %u\n",
+ array->Ptr, array->BufferObj->Name);
+ f[k] = 1.0; /* XXX replace the bad value! */
+ }
+ /*assert(!IS_INF_OR_NAN(f[k]));*/
+ }
+ }
+ break;
+ default:
+ ;
+ }
+ }
+}
+
+
+/**
+ * Unmap the buffer object referenced by given array, if mapped.
+ */
+static void
+unmap_array_buffer(struct gl_context *ctx, struct gl_client_array *array)
+{
+ if (array->Enabled &&
+ _mesa_is_bufferobj(array->BufferObj) &&
+ _mesa_bufferobj_mapped(array->BufferObj)) {
+ ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB, array->BufferObj);
+ }
+}
+
+
+/**
+ * Examine the array's data for NaNs, etc.
+ * For debug purposes; not normally used.
+ */
+static void
+check_draw_elements_data(struct gl_context *ctx, GLsizei count, GLenum elemType,
+ const void *elements, GLint basevertex)
+{
+ struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
+ const void *elemMap;
+ GLint i, k;
+
+ if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
+ elemMap = ctx->Driver.MapBuffer(ctx,
+ GL_ELEMENT_ARRAY_BUFFER_ARB,
+ GL_READ_ONLY,
+ ctx->Array.ElementArrayBufferObj);
+ elements = ADD_POINTERS(elements, elemMap);
+ }
+
+ for (i = 0; i < count; i++) {
+ GLuint j;
+
+ /* j = element[i] */
+ switch (elemType) {
+ case GL_UNSIGNED_BYTE:
+ j = ((const GLubyte *) elements)[i];
+ break;
+ case GL_UNSIGNED_SHORT:
+ j = ((const GLushort *) elements)[i];
+ break;
+ case GL_UNSIGNED_INT:
+ j = ((const GLuint *) elements)[i];
+ break;
+ default:
+ assert(0);
+ }
+
+ /* check element j of each enabled array */
+ check_array_data(ctx, &arrayObj->Vertex, VERT_ATTRIB_POS, j);
+ check_array_data(ctx, &arrayObj->Normal, VERT_ATTRIB_NORMAL, j);
+ check_array_data(ctx, &arrayObj->Color, VERT_ATTRIB_COLOR0, j);
+ check_array_data(ctx, &arrayObj->SecondaryColor, VERT_ATTRIB_COLOR1, j);
+ for (k = 0; k < Elements(arrayObj->TexCoord); k++) {
+ check_array_data(ctx, &arrayObj->TexCoord[k], VERT_ATTRIB_TEX0 + k, j);
+ }
+ for (k = 0; k < Elements(arrayObj->VertexAttrib); k++) {
+ check_array_data(ctx, &arrayObj->VertexAttrib[k],
+ VERT_ATTRIB_GENERIC0 + k, j);
+ }
+ }
+
+ if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
+ ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB,
+ ctx->Array.ElementArrayBufferObj);
+ }
+
+ unmap_array_buffer(ctx, &arrayObj->Vertex);
+ unmap_array_buffer(ctx, &arrayObj->Normal);
+ unmap_array_buffer(ctx, &arrayObj->Color);
+ for (k = 0; k < Elements(arrayObj->TexCoord); k++) {
+ unmap_array_buffer(ctx, &arrayObj->TexCoord[k]);
+ }
+ for (k = 0; k < Elements(arrayObj->VertexAttrib); k++) {
+ unmap_array_buffer(ctx, &arrayObj->VertexAttrib[k]);
+ }
+}
+
+
+/**
+ * Check array data, looking for NaNs, etc.
+ */
+static void
+check_draw_arrays_data(struct gl_context *ctx, GLint start, GLsizei count)
+{
+ /* TO DO */
+}
+
+
+/**
+ * Print info/data for glDrawArrays(), for debugging.
+ */
+static void
+print_draw_arrays(struct gl_context *ctx,
+ GLenum mode, GLint start, GLsizei count)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_exec_context *exec = &vbo->exec;
+ int i;
+
+ printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
+ mode, start, count);
+
+ for (i = 0; i < 32; i++) {
+ GLuint bufName = exec->array.inputs[i]->BufferObj->Name;
+ GLint stride = exec->array.inputs[i]->Stride;
+ printf("attr %2d: size %d stride %d enabled %d "
+ "ptr %p Bufobj %u\n",
+ i,
+ exec->array.inputs[i]->Size,
+ stride,
+ /*exec->array.inputs[i]->Enabled,*/
+ exec->array.legacy_array[i]->Enabled,
+ exec->array.inputs[i]->Ptr,
+ bufName);
+
+ if (bufName) {
+ struct gl_buffer_object *buf = _mesa_lookup_bufferobj(ctx, bufName);
+ GLubyte *p = ctx->Driver.MapBuffer(ctx, GL_ARRAY_BUFFER_ARB,
+ GL_READ_ONLY_ARB, buf);
+ int offset = (int) (GLintptr) exec->array.inputs[i]->Ptr;
+ float *f = (float *) (p + offset);
+ int *k = (int *) f;
+ int i;
+ int n = (count * stride) / 4;
+ if (n > 32)
+ n = 32;
+ printf(" Data at offset %d:\n", offset);
+ for (i = 0; i < n; i++) {
+ printf(" float[%d] = 0x%08x %f\n", i, k[i], f[i]);
+ }
+ ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB, buf);
+ }
+ }
+}
+
+
+/**
+ * Bind the VBO executor to the current vertex array object prior
+ * to drawing.
+ *
+ * Just translate the arrayobj into a sane layout.
+ */
+static void
+bind_array_obj(struct gl_context *ctx)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_exec_context *exec = &vbo->exec;
+ struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
+ GLuint i;
+
+ /* TODO: Fix the ArrayObj struct to keep legacy arrays in an array
+ * rather than as individual named arrays. Then this function can
+ * go away.
+ */
+ exec->array.legacy_array[VERT_ATTRIB_POS] = &arrayObj->Vertex;
+ exec->array.legacy_array[VERT_ATTRIB_WEIGHT] = &arrayObj->Weight;
+ exec->array.legacy_array[VERT_ATTRIB_NORMAL] = &arrayObj->Normal;
+ exec->array.legacy_array[VERT_ATTRIB_COLOR0] = &arrayObj->Color;
+ exec->array.legacy_array[VERT_ATTRIB_COLOR1] = &arrayObj->SecondaryColor;
+ exec->array.legacy_array[VERT_ATTRIB_FOG] = &arrayObj->FogCoord;
+ exec->array.legacy_array[VERT_ATTRIB_COLOR_INDEX] = &arrayObj->Index;
+ if (arrayObj->PointSize.Enabled) {
+ /* this aliases COLOR_INDEX */
+ exec->array.legacy_array[VERT_ATTRIB_POINT_SIZE] = &arrayObj->PointSize;
+ }
+ exec->array.legacy_array[VERT_ATTRIB_EDGEFLAG] = &arrayObj->EdgeFlag;
+
+ for (i = 0; i < Elements(arrayObj->TexCoord); i++)
+ exec->array.legacy_array[VERT_ATTRIB_TEX0 + i] = &arrayObj->TexCoord[i];
+
+ for (i = 0; i < Elements(arrayObj->VertexAttrib); i++) {
+ assert(i < Elements(exec->array.generic_array));
+ exec->array.generic_array[i] = &arrayObj->VertexAttrib[i];
+ }
+
+ exec->array.array_obj = arrayObj->Name;
+}
+
+
+/**
+ * Set the vbo->exec->inputs[] pointers to point to the enabled
+ * vertex arrays. This depends on the current vertex program/shader
+ * being executed because of whether or not generic vertex arrays
+ * alias the conventional vertex arrays.
+ * For arrays that aren't enabled, we set the input[attrib] pointer
+ * to point at a zero-stride current value "array".
+ */
+static void
+recalculate_input_bindings(struct gl_context *ctx)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_exec_context *exec = &vbo->exec;
+ const struct gl_client_array **inputs = &exec->array.inputs[0];
+ GLbitfield const_inputs = 0x0;
+ GLuint i;
+
+ exec->array.program_mode = get_program_mode(ctx);
+ exec->array.enabled_flags = ctx->Array.ArrayObj->_Enabled;
+
+ switch (exec->array.program_mode) {
+ case VP_NONE:
+ /* When no vertex program is active (or the vertex program is generated
+ * from fixed-function state). We put the material values into the
+ * generic slots. This is the only situation where material values
+ * are available as per-vertex attributes.
+ */
+ for (i = 0; i <= VERT_ATTRIB_TEX7; i++) {
+ if (exec->array.legacy_array[i]->Enabled)
+ inputs[i] = exec->array.legacy_array[i];
+ else {
+ inputs[i] = &vbo->legacy_currval[i];
+ const_inputs |= 1 << i;
+ }
+ }
+
+ for (i = 0; i < MAT_ATTRIB_MAX; i++) {
+ inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->mat_currval[i];
+ const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
+ }
+
+ /* Could use just about anything, just to fill in the empty
+ * slots:
+ */
+ for (i = MAT_ATTRIB_MAX; i < VERT_ATTRIB_MAX - VERT_ATTRIB_GENERIC0; i++) {
+ inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
+ const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
+ }
+ break;
+
+ case VP_NV:
+ /* NV_vertex_program - attribute arrays alias and override
+ * conventional, legacy arrays. No materials, and the generic
+ * slots are vacant.
+ */
+ for (i = 0; i <= VERT_ATTRIB_TEX7; i++) {
+ if (exec->array.generic_array[i]->Enabled)
+ inputs[i] = exec->array.generic_array[i];
+ else if (exec->array.legacy_array[i]->Enabled)
+ inputs[i] = exec->array.legacy_array[i];
+ else {
+ inputs[i] = &vbo->legacy_currval[i];
+ const_inputs |= 1 << i;
+ }
+ }
+
+ /* Could use just about anything, just to fill in the empty
+ * slots:
+ */
+ for (i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++) {
+ inputs[i] = &vbo->generic_currval[i - VERT_ATTRIB_GENERIC0];
+ const_inputs |= 1 << i;
+ }
+ break;
+
+ case VP_ARB:
+ /* GL_ARB_vertex_program or GLSL vertex shader - Only the generic[0]
+ * attribute array aliases and overrides the legacy position array.
+ *
+ * Otherwise, legacy attributes available in the legacy slots,
+ * generic attributes in the generic slots and materials are not
+ * available as per-vertex attributes.
+ */
+ if (exec->array.generic_array[0]->Enabled)
+ inputs[0] = exec->array.generic_array[0];
+ else if (exec->array.legacy_array[0]->Enabled)
+ inputs[0] = exec->array.legacy_array[0];
+ else {
+ inputs[0] = &vbo->legacy_currval[0];
+ const_inputs |= 1 << 0;
+ }
+
+ for (i = 1; i <= VERT_ATTRIB_TEX7; i++) {
+ if (exec->array.legacy_array[i]->Enabled)
+ inputs[i] = exec->array.legacy_array[i];
+ else {
+ inputs[i] = &vbo->legacy_currval[i];
+ const_inputs |= 1 << i;
+ }
+ }
+
+ for (i = 0; i < MAX_VERTEX_GENERIC_ATTRIBS; i++) {
+ if (exec->array.generic_array[i]->Enabled)
+ inputs[VERT_ATTRIB_GENERIC0 + i] = exec->array.generic_array[i];
+ else {
+ inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
+ const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i);
+ }
+
+ }
+ break;
+ }
+
+ _mesa_set_varying_vp_inputs( ctx, ~const_inputs );
+}
+
+
+/**
+ * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
+ * These will point to the arrays to actually use for drawing. Some will
+ * be user-provided arrays, other will be zero-stride const-valued arrays.
+ * Note that this might set the _NEW_ARRAY dirty flag so state validation
+ * must be done after this call.
+ */
+static void
+bind_arrays(struct gl_context *ctx)
+{
+ if (!ctx->Array.RebindArrays) {
+ return;
+ }
+
+ bind_array_obj(ctx);
+ recalculate_input_bindings(ctx);
+ ctx->Array.RebindArrays = GL_FALSE;
+}
+
+
+/**
+ * Helper function called by the other DrawArrays() functions below.
+ * This is where we handle primitive restart for drawing non-indexed
+ * arrays. If primitive restart is enabled, it typically means
+ * splitting one DrawArrays() into two.
+ */
+static void
+vbo_draw_arrays(struct gl_context *ctx, GLenum mode, GLint start,
+ GLsizei count, GLuint numInstances)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_exec_context *exec = &vbo->exec;
+ struct _mesa_prim prim[2];
+
+ bind_arrays(ctx);
+
+ /* Again... because we may have changed the bitmask of per-vertex varying
+ * attributes. If we regenerate the fixed-function vertex program now
+ * we may be able to prune down the number of vertex attributes which we
+ * need in the shader.
+ */
+ if (ctx->NewState)
+ _mesa_update_state(ctx);
+
+ prim[0].begin = 1;
+ prim[0].end = 1;
+ prim[0].weak = 0;
+ prim[0].pad = 0;
+ prim[0].mode = mode;
+ prim[0].start = 0; /* filled in below */
+ prim[0].count = 0; /* filled in below */
+ prim[0].indexed = 0;
+ prim[0].basevertex = 0;
+ prim[0].num_instances = numInstances;
+
+ /* Implement the primitive restart index */
+ if (ctx->Array.PrimitiveRestart && ctx->Array.RestartIndex < count) {
+ GLuint primCount = 0;
+
+ if (ctx->Array.RestartIndex == start) {
+ /* special case: RestartIndex at beginning */
+ if (count > 1) {
+ prim[0].start = start + 1;
+ prim[0].count = count - 1;
+ primCount = 1;
+ }
+ }
+ else if (ctx->Array.RestartIndex == start + count - 1) {
+ /* special case: RestartIndex at end */
+ if (count > 1) {
+ prim[0].start = start;
+ prim[0].count = count - 1;
+ primCount = 1;
+ }
+ }
+ else {
+ /* general case: RestartIndex in middle, split into two prims */
+ prim[0].start = start;
+ prim[0].count = ctx->Array.RestartIndex - start;
+
+ prim[1] = prim[0];
+ prim[1].start = ctx->Array.RestartIndex + 1;
+ prim[1].count = count - prim[1].start;
+
+ primCount = 2;
+ }
+
+ if (primCount > 0) {
+ /* draw one or two prims */
+ check_buffers_are_unmapped(exec->array.inputs);
+ vbo->draw_prims(ctx, exec->array.inputs, prim, primCount, NULL,
+ GL_TRUE, start, start + count - 1);
+ }
+ }
+ else {
+ /* no prim restart */
+ prim[0].start = start;
+ prim[0].count = count;
+
+ check_buffers_are_unmapped(exec->array.inputs);
+ vbo->draw_prims(ctx, exec->array.inputs, prim, 1, NULL,
+ GL_TRUE, start, start + count - 1);
+ }
+}
+
+
+
+/**
+ * Called from glDrawArrays when in immediate mode (not display list mode).
+ */
+static void GLAPIENTRY
+vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_DRAW)
+ _mesa_debug(ctx, "glDrawArrays(%s, %d, %d)\n",
+ _mesa_lookup_enum_by_nr(mode), start, count);
+
+ if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
+ return;
+
+ FLUSH_CURRENT( ctx, 0 );
+
+ if (!_mesa_valid_to_render(ctx, "glDrawArrays")) {
+ return;
+ }
+
+ if (0)
+ check_draw_arrays_data(ctx, start, count);
+
+ vbo_draw_arrays(ctx, mode, start, count, 1);
+
+ if (0)
+ print_draw_arrays(ctx, mode, start, count);
+}
+
+
+/**
+ * Called from glDrawArraysInstanced when in immediate mode (not
+ * display list mode).
+ */
+static void GLAPIENTRY
+vbo_exec_DrawArraysInstanced(GLenum mode, GLint start, GLsizei count,
+ GLsizei numInstances)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_DRAW)
+ _mesa_debug(ctx, "glDrawArraysInstanced(%s, %d, %d, %d)\n",
+ _mesa_lookup_enum_by_nr(mode), start, count, numInstances);
+
+ if (!_mesa_validate_DrawArraysInstanced(ctx, mode, start, count, numInstances))
+ return;
+
+ FLUSH_CURRENT( ctx, 0 );
+
+ if (!_mesa_valid_to_render(ctx, "glDrawArraysInstanced")) {
+ return;
+ }
+
+ if (0)
+ check_draw_arrays_data(ctx, start, count);
+
+ vbo_draw_arrays(ctx, mode, start, count, numInstances);
+
+ if (0)
+ print_draw_arrays(ctx, mode, start, count);
+}
+
+
+/**
+ * Map GL_ELEMENT_ARRAY_BUFFER and print contents.
+ * For debugging.
+ */
+static void
+dump_element_buffer(struct gl_context *ctx, GLenum type)
+{
+ const GLvoid *map = ctx->Driver.MapBuffer(ctx,
+ GL_ELEMENT_ARRAY_BUFFER_ARB,
+ GL_READ_ONLY,
+ ctx->Array.ElementArrayBufferObj);
+ switch (type) {
+ case GL_UNSIGNED_BYTE:
+ {
+ const GLubyte *us = (const GLubyte *) map;
+ GLint i;
+ for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size; i++) {
+ printf("%02x ", us[i]);
+ if (i % 32 == 31)
+ printf("\n");
+ }
+ printf("\n");
+ }
+ break;
+ case GL_UNSIGNED_SHORT:
+ {
+ const GLushort *us = (const GLushort *) map;
+ GLint i;
+ for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size / 2; i++) {
+ printf("%04x ", us[i]);
+ if (i % 16 == 15)
+ printf("\n");
+ }
+ printf("\n");
+ }
+ break;
+ case GL_UNSIGNED_INT:
+ {
+ const GLuint *us = (const GLuint *) map;
+ GLint i;
+ for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size / 4; i++) {
+ printf("%08x ", us[i]);
+ if (i % 8 == 7)
+ printf("\n");
+ }
+ printf("\n");
+ }
+ break;
+ default:
+ ;
+ }
+
+ ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB,
+ ctx->Array.ElementArrayBufferObj);
+}
+
+
+/**
+ * Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements.
+ * Do the rendering for a glDrawElements or glDrawRangeElements call after
+ * we've validated buffer bounds, etc.
+ */
+static void
+vbo_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
+ GLboolean index_bounds_valid,
+ GLuint start, GLuint end,
+ GLsizei count, GLenum type,
+ const GLvoid *indices,
+ GLint basevertex, GLint numInstances)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_exec_context *exec = &vbo->exec;
+ struct _mesa_index_buffer ib;
+ struct _mesa_prim prim[1];
+
+ FLUSH_CURRENT( ctx, 0 );
+
+ if (!_mesa_valid_to_render(ctx, "glDraw[Range]Elements")) {
+ return;
+ }
+
+ bind_arrays( ctx );
+
+ /* check for dirty state again */
+ if (ctx->NewState)
+ _mesa_update_state( ctx );
+
+ ib.count = count;
+ ib.type = type;
+ ib.obj = ctx->Array.ElementArrayBufferObj;
+ ib.ptr = indices;
+
+ prim[0].begin = 1;
+ prim[0].end = 1;
+ prim[0].weak = 0;
+ prim[0].pad = 0;
+ prim[0].mode = mode;
+ prim[0].start = 0;
+ prim[0].count = count;
+ prim[0].indexed = 1;
+ prim[0].basevertex = basevertex;
+ prim[0].num_instances = numInstances;
+
+ /* Need to give special consideration to rendering a range of
+ * indices starting somewhere above zero. Typically the
+ * application is issuing multiple DrawRangeElements() to draw
+ * successive primitives layed out linearly in the vertex arrays.
+ * Unless the vertex arrays are all in a VBO (or locked as with
+ * CVA), the OpenGL semantics imply that we need to re-read or
+ * re-upload the vertex data on each draw call.
+ *
+ * In the case of hardware tnl, we want to avoid starting the
+ * upload at zero, as it will mean every draw call uploads an
+ * increasing amount of not-used vertex data. Worse - in the
+ * software tnl module, all those vertices might be transformed and
+ * lit but never rendered.
+ *
+ * If we just upload or transform the vertices in start..end,
+ * however, the indices will be incorrect.
+ *
+ * At this level, we don't know exactly what the requirements of
+ * the backend are going to be, though it will likely boil down to
+ * either:
+ *
+ * 1) Do nothing, everything is in a VBO and is processed once
+ * only.
+ *
+ * 2) Adjust the indices and vertex arrays so that start becomes
+ * zero.
+ *
+ * Rather than doing anything here, I'll provide a helper function
+ * for the latter case elsewhere.
+ */
+
+ check_buffers_are_unmapped(exec->array.inputs);
+ vbo->draw_prims( ctx, exec->array.inputs, prim, 1, &ib,
+ index_bounds_valid, start, end );
+}
+
+
+/**
+ * Called by glDrawRangeElementsBaseVertex() in immediate mode.
+ */
+static void GLAPIENTRY
+vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
+ GLuint start, GLuint end,
+ GLsizei count, GLenum type,
+ const GLvoid *indices,
+ GLint basevertex)
+{
+ static GLuint warnCount = 0;
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_DRAW)
+ _mesa_debug(ctx,
+ "glDrawRangeElementsBaseVertex(%s, %u, %u, %d, %s, %p, %d)\n",
+ _mesa_lookup_enum_by_nr(mode), start, end, count,
+ _mesa_lookup_enum_by_nr(type), indices, basevertex);
+
+ if (!_mesa_validate_DrawRangeElements( ctx, mode, start, end, count,
+ type, indices, basevertex ))
+ return;
+
+ /* NOTE: It's important that 'end' is a reasonable value.
+ * in _tnl_draw_prims(), we use end to determine how many vertices
+ * to transform. If it's too large, we can unnecessarily split prims
+ * or we can read/write out of memory in several different places!
+ */
+
+ /* Catch/fix some potential user errors */
+ if (type == GL_UNSIGNED_BYTE) {
+ start = MIN2(start, 0xff);
+ end = MIN2(end, 0xff);
+ }
+ else if (type == GL_UNSIGNED_SHORT) {
+ start = MIN2(start, 0xffff);
+ end = MIN2(end, 0xffff);
+ }
+
+ if (end >= ctx->Array.ArrayObj->_MaxElement) {
+ /* the max element is out of bounds of one or more enabled arrays */
+ warnCount++;
+
+ if (warnCount < 10) {
+ _mesa_warning(ctx, "glDraw[Range]Elements(start %u, end %u, count %d, "
+ "type 0x%x, indices=%p)\n"
+ "\tend is out of bounds (max=%u) "
+ "Element Buffer %u (size %d)\n"
+ "\tThis should probably be fixed in the application.",
+ start, end, count, type, indices,
+ ctx->Array.ArrayObj->_MaxElement - 1,
+ ctx->Array.ElementArrayBufferObj->Name,
+ (int) ctx->Array.ElementArrayBufferObj->Size);
+ }
+
+ if (0)
+ dump_element_buffer(ctx, type);
+
+ if (0)
+ _mesa_print_arrays(ctx);
+
+#ifdef DEBUG
+ /* 'end' was out of bounds, but now let's check the actual array
+ * indexes to see if any of them are out of bounds.
+ */
+ {
+ GLuint max = _mesa_max_buffer_index(ctx, count, type, indices,
+ ctx->Array.ElementArrayBufferObj);
+ if (max >= ctx->Array.ArrayObj->_MaxElement) {
+ if (warnCount < 10) {
+ _mesa_warning(ctx, "glDraw[Range]Elements(start %u, end %u, "
+ "count %d, type 0x%x, indices=%p)\n"
+ "\tindex=%u is out of bounds (max=%u) "
+ "Element Buffer %u (size %d)\n"
+ "\tSkipping the glDrawRangeElements() call",
+ start, end, count, type, indices, max,
+ ctx->Array.ArrayObj->_MaxElement - 1,
+ ctx->Array.ElementArrayBufferObj->Name,
+ (int) ctx->Array.ElementArrayBufferObj->Size);
+ }
+ }
+ /* XXX we could also find the min index and compare to 'start'
+ * to see if start is correct. But it's more likely to get the
+ * upper bound wrong.
+ */
+ }
+#endif
+
+ /* Set 'end' to the max possible legal value */
+ assert(ctx->Array.ArrayObj->_MaxElement >= 1);
+ end = ctx->Array.ArrayObj->_MaxElement - 1;
+ }
+ else if (0) {
+ printf("glDraw[Range]Elements{,BaseVertex}"
+ "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
+ "base %d\n",
+ start, end, type, count,
+ ctx->Array.ElementArrayBufferObj->Name,
+ basevertex);
+ }
+
+#if 0
+ check_draw_elements_data(ctx, count, type, indices);
+#else
+ (void) check_draw_elements_data;
+#endif
+
+ vbo_validated_drawrangeelements(ctx, mode, GL_TRUE, start, end,
+ count, type, indices, basevertex, 1);
+}
+
+
+/**
+ * Called by glDrawRangeElements() in immediate mode.
+ */
+static void GLAPIENTRY
+vbo_exec_DrawRangeElements(GLenum mode, GLuint start, GLuint end,
+ GLsizei count, GLenum type, const GLvoid *indices)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_DRAW)
+ _mesa_debug(ctx,
+ "glDrawRangeElements(%s, %u, %u, %d, %s, %p)\n",
+ _mesa_lookup_enum_by_nr(mode), start, end, count,
+ _mesa_lookup_enum_by_nr(type), indices);
+
+ vbo_exec_DrawRangeElementsBaseVertex(mode, start, end, count, type,
+ indices, 0);
+}
+
+
+/**
+ * Called by glDrawElements() in immediate mode.
+ */
+static void GLAPIENTRY
+vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_DRAW)
+ _mesa_debug(ctx, "glDrawElements(%s, %u, %s, %p)\n",
+ _mesa_lookup_enum_by_nr(mode), count,
+ _mesa_lookup_enum_by_nr(type), indices);
+
+ if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, 0 ))
+ return;
+
+ vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
+ count, type, indices, 0, 1);
+}
+
+
+/**
+ * Called by glDrawElementsBaseVertex() in immediate mode.
+ */
+static void GLAPIENTRY
+vbo_exec_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices, GLint basevertex)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_DRAW)
+ _mesa_debug(ctx, "glDrawElementsBaseVertex(%s, %d, %s, %p, %d)\n",
+ _mesa_lookup_enum_by_nr(mode), count,
+ _mesa_lookup_enum_by_nr(type), indices, basevertex);
+
+ if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices,
+ basevertex ))
+ return;
+
+ vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
+ count, type, indices, basevertex, 1);
+}
+
+
+/**
+ * Called by glDrawElementsInstanced() in immediate mode.
+ */
+static void GLAPIENTRY
+vbo_exec_DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices, GLsizei numInstances)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_DRAW)
+ _mesa_debug(ctx, "glDrawElementsInstanced(%s, %d, %s, %p, %d)\n",
+ _mesa_lookup_enum_by_nr(mode), count,
+ _mesa_lookup_enum_by_nr(type), indices, numInstances);
+
+ if (!_mesa_validate_DrawElementsInstanced(ctx, mode, count, type, indices,
+ numInstances))
+ return;
+
+ vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0,
+ count, type, indices, 0, numInstances);
+}
+
+
+/**
+ * Inner support for both _mesa_MultiDrawElements() and
+ * _mesa_MultiDrawRangeElements().
+ * This does the actual rendering after we've checked array indexes, etc.
+ */
+static void
+vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
+ const GLsizei *count, GLenum type,
+ const GLvoid **indices, GLsizei primcount,
+ const GLint *basevertex)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_exec_context *exec = &vbo->exec;
+ struct _mesa_index_buffer ib;
+ struct _mesa_prim *prim;
+ unsigned int index_type_size = 0;
+ uintptr_t min_index_ptr, max_index_ptr;
+ GLboolean fallback = GL_FALSE;
+ int i;
+
+ if (primcount == 0)
+ return;
+
+ FLUSH_CURRENT( ctx, 0 );
+
+ if (!_mesa_valid_to_render(ctx, "glMultiDrawElements")) {
+ return;
+ }
+
+ prim = calloc(1, primcount * sizeof(*prim));
+ if (prim == NULL) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMultiDrawElements");
+ return;
+ }
+
+ /* Decide if we can do this all as one set of primitives sharing the
+ * same index buffer, or if we have to reset the index pointer per
+ * primitive.
+ */
+ bind_arrays( ctx );
+
+ /* check for dirty state again */
+ if (ctx->NewState)
+ _mesa_update_state( ctx );
+
+ switch (type) {
+ case GL_UNSIGNED_INT:
+ index_type_size = 4;
+ break;
+ case GL_UNSIGNED_SHORT:
+ index_type_size = 2;
+ break;
+ case GL_UNSIGNED_BYTE:
+ index_type_size = 1;
+ break;
+ default:
+ assert(0);
+ }
+
+ min_index_ptr = (uintptr_t)indices[0];
+ max_index_ptr = 0;
+ for (i = 0; i < primcount; i++) {
+ min_index_ptr = MIN2(min_index_ptr, (uintptr_t)indices[i]);
+ max_index_ptr = MAX2(max_index_ptr, (uintptr_t)indices[i] +
+ index_type_size * count[i]);
+ }
+
+ /* Check if we can handle this thing as a bunch of index offsets from the
+ * same index pointer. If we can't, then we have to fall back to doing
+ * a draw_prims per primitive.
+ * Check that the difference between each prim's indexes is a multiple of
+ * the index/element size.
+ */
+ if (index_type_size != 1) {
+ for (i = 0; i < primcount; i++) {
+ if ((((uintptr_t)indices[i] - min_index_ptr) % index_type_size) != 0) {
+ fallback = GL_TRUE;
+ break;
+ }
+ }
+ }
+
+ /* If the index buffer isn't in a VBO, then treating the application's
+ * subranges of the index buffer as one large index buffer may lead to
+ * us reading unmapped memory.
+ */
+ if (!_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj))
+ fallback = GL_TRUE;
+
+ if (!fallback) {
+ ib.count = (max_index_ptr - min_index_ptr) / index_type_size;
+ ib.type = type;
+ ib.obj = ctx->Array.ElementArrayBufferObj;
+ ib.ptr = (void *)min_index_ptr;
+
+ for (i = 0; i < primcount; i++) {
+ prim[i].begin = (i == 0);
+ prim[i].end = (i == primcount - 1);
+ prim[i].weak = 0;
+ prim[i].pad = 0;
+ prim[i].mode = mode;
+ prim[i].start = ((uintptr_t)indices[i] - min_index_ptr) / index_type_size;
+ prim[i].count = count[i];
+ prim[i].indexed = 1;
+ prim[i].num_instances = 1;
+ if (basevertex != NULL)
+ prim[i].basevertex = basevertex[i];
+ else
+ prim[i].basevertex = 0;
+ }
+
+ check_buffers_are_unmapped(exec->array.inputs);
+ vbo->draw_prims(ctx, exec->array.inputs, prim, primcount, &ib,
+ GL_FALSE, ~0, ~0);
+ } else {
+ /* render one prim at a time */
+ for (i = 0; i < primcount; i++) {
+ ib.count = count[i];
+ ib.type = type;
+ ib.obj = ctx->Array.ElementArrayBufferObj;
+ ib.ptr = indices[i];
+
+ prim[0].begin = 1;
+ prim[0].end = 1;
+ prim[0].weak = 0;
+ prim[0].pad = 0;
+ prim[0].mode = mode;
+ prim[0].start = 0;
+ prim[0].count = count[i];
+ prim[0].indexed = 1;
+ prim[0].num_instances = 1;
+ if (basevertex != NULL)
+ prim[0].basevertex = basevertex[i];
+ else
+ prim[0].basevertex = 0;
+
+ check_buffers_are_unmapped(exec->array.inputs);
+ vbo->draw_prims(ctx, exec->array.inputs, prim, 1, &ib,
+ GL_FALSE, ~0, ~0);
+ }
+ }
+
+ free(prim);
+}
+
+
+static void GLAPIENTRY
+vbo_exec_MultiDrawElements(GLenum mode,
+ const GLsizei *count, GLenum type,
+ const GLvoid **indices,
+ GLsizei primcount)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ for (i = 0; i < primcount; i++) {
+ if (!_mesa_validate_DrawElements(ctx, mode, count[i], type, indices[i],
+ 0))
+ return;
+ }
+
+ vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
+ NULL);
+}
+
+
+static void GLAPIENTRY
+vbo_exec_MultiDrawElementsBaseVertex(GLenum mode,
+ const GLsizei *count, GLenum type,
+ const GLvoid **indices,
+ GLsizei primcount,
+ const GLsizei *basevertex)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ for (i = 0; i < primcount; i++) {
+ if (!_mesa_validate_DrawElements(ctx, mode, count[i], type, indices[i],
+ basevertex[i]))
+ return;
+ }
+
+ vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount,
+ basevertex);
+}
+
+
+/**
+ * Plug in the immediate-mode vertex array drawing commands into the
+ * givven vbo_exec_context object.
+ */
+void
+vbo_exec_array_init( struct vbo_exec_context *exec )
+{
+ exec->vtxfmt.DrawArrays = vbo_exec_DrawArrays;
+ exec->vtxfmt.DrawElements = vbo_exec_DrawElements;
+ exec->vtxfmt.DrawRangeElements = vbo_exec_DrawRangeElements;
+ exec->vtxfmt.MultiDrawElementsEXT = vbo_exec_MultiDrawElements;
+ exec->vtxfmt.DrawElementsBaseVertex = vbo_exec_DrawElementsBaseVertex;
+ exec->vtxfmt.DrawRangeElementsBaseVertex = vbo_exec_DrawRangeElementsBaseVertex;
+ exec->vtxfmt.MultiDrawElementsBaseVertex = vbo_exec_MultiDrawElementsBaseVertex;
+ exec->vtxfmt.DrawArraysInstanced = vbo_exec_DrawArraysInstanced;
+ exec->vtxfmt.DrawElementsInstanced = vbo_exec_DrawElementsInstanced;
+}
+
+
+void
+vbo_exec_array_destroy( struct vbo_exec_context *exec )
+{
+ /* nothing to do */
+}
+
+
+
+/**
+ * The following functions are only used for OpenGL ES 1/2 support.
+ * And some aren't even supported (yet) in ES 1/2.
+ */
+
+
+void GLAPIENTRY
+_mesa_DrawArrays(GLenum mode, GLint first, GLsizei count)
+{
+ vbo_exec_DrawArrays(mode, first, count);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawElements(GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices)
+{
+ vbo_exec_DrawElements(mode, count, type, indices);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices, GLint basevertex)
+{
+ vbo_exec_DrawElementsBaseVertex(mode, count, type, indices, basevertex);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
+ GLenum type, const GLvoid *indices)
+{
+ vbo_exec_DrawRangeElements(mode, start, end, count, type, indices);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
+ GLsizei count, GLenum type,
+ const GLvoid *indices, GLint basevertex)
+{
+ vbo_exec_DrawRangeElementsBaseVertex(mode, start, end, count, type,
+ indices, basevertex);
+}
+
+
+void GLAPIENTRY
+_mesa_MultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type,
+ const GLvoid **indices, GLsizei primcount)
+{
+ vbo_exec_MultiDrawElements(mode, count, type, indices, primcount);
+}
+
+
+void GLAPIENTRY
+_mesa_MultiDrawElementsBaseVertex(GLenum mode,
+ const GLsizei *count, GLenum type,
+ const GLvoid **indices, GLsizei primcount,
+ const GLint *basevertex)
+{
+ vbo_exec_MultiDrawElementsBaseVertex(mode, count, type, indices,
+ primcount, basevertex);
+}
diff --git a/mesalib/src/mesa/vbo/vbo_exec_draw.c b/mesalib/src/mesa/vbo/vbo_exec_draw.c
index 539658021..7cc843779 100644
--- a/mesalib/src/mesa/vbo/vbo_exec_draw.c
+++ b/mesalib/src/mesa/vbo/vbo_exec_draw.c
@@ -1,426 +1,426 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.2
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- */
-
-#include "main/glheader.h"
-#include "main/bufferobj.h"
-#include "main/compiler.h"
-#include "main/enums.h"
-#include "main/mfeatures.h"
-#include "main/state.h"
-
-#include "vbo_context.h"
-
-
-#if FEATURE_beginend
-
-
-static void
-vbo_exec_debug_verts( struct vbo_exec_context *exec )
-{
- GLuint count = exec->vtx.vert_count;
- GLuint i;
-
- printf("%s: %u vertices %d primitives, %d vertsize\n",
- __FUNCTION__,
- count,
- exec->vtx.prim_count,
- exec->vtx.vertex_size);
-
- for (i = 0 ; i < exec->vtx.prim_count ; i++) {
- struct _mesa_prim *prim = &exec->vtx.prim[i];
- printf(" prim %d: %s%s %d..%d %s %s\n",
- i,
- _mesa_lookup_prim_by_nr(prim->mode),
- prim->weak ? " (weak)" : "",
- prim->start,
- prim->start + prim->count,
- prim->begin ? "BEGIN" : "(wrap)",
- prim->end ? "END" : "(wrap)");
- }
-}
-
-
-/*
- * NOTE: Need to have calculated primitives by this point -- do it on the fly.
- * NOTE: Old 'parity' issue is gone.
- */
-static GLuint
-vbo_copy_vertices( struct vbo_exec_context *exec )
-{
- GLuint nr = exec->vtx.prim[exec->vtx.prim_count-1].count;
- GLuint ovf, i;
- GLuint sz = exec->vtx.vertex_size;
- GLfloat *dst = exec->vtx.copied.buffer;
- const GLfloat *src = (exec->vtx.buffer_map +
- exec->vtx.prim[exec->vtx.prim_count-1].start *
- exec->vtx.vertex_size);
-
-
- switch (exec->ctx->Driver.CurrentExecPrimitive) {
- case GL_POINTS:
- return 0;
- case GL_LINES:
- ovf = nr&1;
- for (i = 0 ; i < ovf ; i++)
- memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
- return i;
- case GL_TRIANGLES:
- ovf = nr%3;
- for (i = 0 ; i < ovf ; i++)
- memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
- return i;
- case GL_QUADS:
- ovf = nr&3;
- for (i = 0 ; i < ovf ; i++)
- memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
- return i;
- case GL_LINE_STRIP:
- if (nr == 0) {
- return 0;
- }
- else {
- memcpy( dst, src+(nr-1)*sz, sz * sizeof(GLfloat) );
- return 1;
- }
- case GL_LINE_LOOP:
- case GL_TRIANGLE_FAN:
- case GL_POLYGON:
- if (nr == 0) {
- return 0;
- }
- else if (nr == 1) {
- memcpy( dst, src+0, sz * sizeof(GLfloat) );
- return 1;
- }
- else {
- memcpy( dst, src+0, sz * sizeof(GLfloat) );
- memcpy( dst+sz, src+(nr-1)*sz, sz * sizeof(GLfloat) );
- return 2;
- }
- case GL_TRIANGLE_STRIP:
- /* no parity issue, but need to make sure the tri is not drawn twice */
- if (nr & 1) {
- exec->vtx.prim[exec->vtx.prim_count-1].count--;
- }
- /* fallthrough */
- case GL_QUAD_STRIP:
- switch (nr) {
- case 0:
- ovf = 0;
- break;
- case 1:
- ovf = 1;
- break;
- default:
- ovf = 2 + (nr & 1);
- break;
- }
- for (i = 0 ; i < ovf ; i++)
- memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
- return i;
- case PRIM_OUTSIDE_BEGIN_END:
- return 0;
- default:
- assert(0);
- return 0;
- }
-}
-
-
-
-/* TODO: populate these as the vertex is defined:
- */
-static void
-vbo_exec_bind_arrays( struct gl_context *ctx )
-{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
- struct gl_client_array *arrays = exec->vtx.arrays;
- const GLuint count = exec->vtx.vert_count;
- const GLuint *map;
- GLuint attr;
- GLbitfield varying_inputs = 0x0;
-
- /* Install the default (ie Current) attributes first, then overlay
- * all active ones.
- */
- switch (get_program_mode(exec->ctx)) {
- case VP_NONE:
- for (attr = 0; attr < 16; attr++) {
- exec->vtx.inputs[attr] = &vbo->legacy_currval[attr];
- }
- for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) {
- ASSERT(attr + 16 < Elements(exec->vtx.inputs));
- exec->vtx.inputs[attr + 16] = &vbo->mat_currval[attr];
- }
- map = vbo->map_vp_none;
- break;
- case VP_NV:
- case VP_ARB:
- /* The aliasing of attributes for NV vertex programs has already
- * occurred. NV vertex programs cannot access material values,
- * nor attributes greater than VERT_ATTRIB_TEX7.
- */
- for (attr = 0; attr < 16; attr++) {
- exec->vtx.inputs[attr] = &vbo->legacy_currval[attr];
- ASSERT(attr + 16 < Elements(exec->vtx.inputs));
- exec->vtx.inputs[attr + 16] = &vbo->generic_currval[attr];
- }
- map = vbo->map_vp_arb;
-
- /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read.
- * In that case we effectively need to route the data from
- * glVertexAttrib(0, val) calls to feed into the GENERIC0 input.
- */
- if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 &&
- (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) {
- exec->vtx.inputs[16] = exec->vtx.inputs[0];
- exec->vtx.attrsz[16] = exec->vtx.attrsz[0];
- exec->vtx.attrptr[16] = exec->vtx.attrptr[0];
- exec->vtx.attrsz[0] = 0;
- }
- break;
- default:
- assert(0);
- }
-
- /* Make all active attributes (including edgeflag) available as
- * arrays of floats.
- */
- for (attr = 0; attr < VERT_ATTRIB_MAX ; attr++) {
- const GLuint src = map[attr];
-
- if (exec->vtx.attrsz[src]) {
- GLsizeiptr offset = (GLbyte *)exec->vtx.attrptr[src] -
- (GLbyte *)exec->vtx.vertex;
-
- /* override the default array set above */
- ASSERT(attr < Elements(exec->vtx.inputs));
- ASSERT(attr < Elements(exec->vtx.arrays)); /* arrays[] */
- exec->vtx.inputs[attr] = &arrays[attr];
-
- if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
- /* a real buffer obj: Ptr is an offset, not a pointer*/
- assert(exec->vtx.bufferobj->Pointer); /* buf should be mapped */
- assert(offset >= 0);
- arrays[attr].Ptr = (GLubyte *)exec->vtx.bufferobj->Offset + offset;
- }
- else {
- /* Ptr into ordinary app memory */
- arrays[attr].Ptr = (GLubyte *)exec->vtx.buffer_map + offset;
- }
- arrays[attr].Size = exec->vtx.attrsz[src];
- arrays[attr].StrideB = exec->vtx.vertex_size * sizeof(GLfloat);
- arrays[attr].Stride = exec->vtx.vertex_size * sizeof(GLfloat);
- arrays[attr].Type = GL_FLOAT;
- arrays[attr].Format = GL_RGBA;
- arrays[attr].Enabled = 1;
- _mesa_reference_buffer_object(ctx,
- &arrays[attr].BufferObj,
- exec->vtx.bufferobj);
- arrays[attr]._MaxElement = count; /* ??? */
-
- varying_inputs |= 1 << attr;
- ctx->NewState |= _NEW_ARRAY;
- }
- }
-
- _mesa_set_varying_vp_inputs( ctx, varying_inputs );
-}
-
-
-/**
- * Unmap the VBO. This is called before drawing.
- */
-static void
-vbo_exec_vtx_unmap( struct vbo_exec_context *exec )
-{
- GLenum target = GL_ARRAY_BUFFER_ARB;
-
- if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
- struct gl_context *ctx = exec->ctx;
-
- if (ctx->Driver.FlushMappedBufferRange) {
- GLintptr offset = exec->vtx.buffer_used - exec->vtx.bufferobj->Offset;
- GLsizeiptr length = (exec->vtx.buffer_ptr - exec->vtx.buffer_map) * sizeof(float);
-
- if (length)
- ctx->Driver.FlushMappedBufferRange(ctx, target,
- offset, length,
- exec->vtx.bufferobj);
- }
-
- exec->vtx.buffer_used += (exec->vtx.buffer_ptr -
- exec->vtx.buffer_map) * sizeof(float);
-
- assert(exec->vtx.buffer_used <= VBO_VERT_BUFFER_SIZE);
- assert(exec->vtx.buffer_ptr != NULL);
-
- ctx->Driver.UnmapBuffer(ctx, target, exec->vtx.bufferobj);
- exec->vtx.buffer_map = NULL;
- exec->vtx.buffer_ptr = NULL;
- exec->vtx.max_vert = 0;
- }
-}
-
-
-/**
- * Map the vertex buffer to begin storing glVertex, glColor, etc data.
- */
-void
-vbo_exec_vtx_map( struct vbo_exec_context *exec )
-{
- struct gl_context *ctx = exec->ctx;
- const GLenum target = GL_ARRAY_BUFFER_ARB;
- const GLenum access = GL_READ_WRITE_ARB; /* for MapBuffer */
- const GLenum accessRange = GL_MAP_WRITE_BIT | /* for MapBufferRange */
- GL_MAP_INVALIDATE_RANGE_BIT |
- GL_MAP_UNSYNCHRONIZED_BIT |
- GL_MAP_FLUSH_EXPLICIT_BIT |
- MESA_MAP_NOWAIT_BIT;
- const GLenum usage = GL_STREAM_DRAW_ARB;
-
- if (!_mesa_is_bufferobj(exec->vtx.bufferobj))
- return;
-
- assert(!exec->vtx.buffer_map);
- assert(!exec->vtx.buffer_ptr);
-
- if (VBO_VERT_BUFFER_SIZE > exec->vtx.buffer_used + 1024 &&
- ctx->Driver.MapBufferRange) {
- /* The VBO exists and there's room for more */
- exec->vtx.buffer_map =
- (GLfloat *)ctx->Driver.MapBufferRange(ctx,
- target,
- exec->vtx.buffer_used,
- (VBO_VERT_BUFFER_SIZE -
- exec->vtx.buffer_used),
- accessRange,
- exec->vtx.bufferobj);
- exec->vtx.buffer_ptr = exec->vtx.buffer_map;
- }
-
- if (!exec->vtx.buffer_map) {
- /* Need to allocate a new VBO */
- exec->vtx.buffer_used = 0;
-
- ctx->Driver.BufferData(ctx, target,
- VBO_VERT_BUFFER_SIZE,
- NULL, usage, exec->vtx.bufferobj);
-
-
- if (ctx->Driver.MapBufferRange)
- exec->vtx.buffer_map =
- (GLfloat *)ctx->Driver.MapBufferRange(ctx, target,
- 0, VBO_VERT_BUFFER_SIZE,
- accessRange,
- exec->vtx.bufferobj);
- if (!exec->vtx.buffer_map)
- exec->vtx.buffer_map =
- (GLfloat *)ctx->Driver.MapBuffer(ctx, target, access, exec->vtx.bufferobj);
- assert(exec->vtx.buffer_map);
- exec->vtx.buffer_ptr = exec->vtx.buffer_map;
- }
-
- if (0)
- printf("map %d..\n", exec->vtx.buffer_used);
-}
-
-
-
-/**
- * Execute the buffer and save copied verts.
- * \param keep_unmapped if true, leave the VBO unmapped when we're done.
- */
-void
-vbo_exec_vtx_flush(struct vbo_exec_context *exec, GLboolean keepUnmapped)
-{
- if (0)
- vbo_exec_debug_verts( exec );
-
- if (exec->vtx.prim_count &&
- exec->vtx.vert_count) {
-
- exec->vtx.copied.nr = vbo_copy_vertices( exec );
-
- if (exec->vtx.copied.nr != exec->vtx.vert_count) {
- struct gl_context *ctx = exec->ctx;
-
- /* Before the update_state() as this may raise _NEW_ARRAY
- * from _mesa_set_varying_vp_inputs().
- */
- vbo_exec_bind_arrays( ctx );
-
- if (ctx->NewState)
- _mesa_update_state( ctx );
-
- if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
- vbo_exec_vtx_unmap( exec );
- }
-
- if (0)
- printf("%s %d %d\n", __FUNCTION__, exec->vtx.prim_count,
- exec->vtx.vert_count);
-
- vbo_context(ctx)->draw_prims( ctx,
- exec->vtx.inputs,
- exec->vtx.prim,
- exec->vtx.prim_count,
- NULL,
- GL_TRUE,
- 0,
- exec->vtx.vert_count - 1);
-
- /* If using a real VBO, get new storage -- unless asked not to.
- */
- if (_mesa_is_bufferobj(exec->vtx.bufferobj) && !keepUnmapped) {
- vbo_exec_vtx_map( exec );
- }
- }
- }
-
- /* May have to unmap explicitly if we didn't draw:
- */
- if (keepUnmapped &&
- _mesa_is_bufferobj(exec->vtx.bufferobj) &&
- exec->vtx.buffer_map) {
- vbo_exec_vtx_unmap( exec );
- }
-
- if (keepUnmapped || exec->vtx.vertex_size == 0)
- exec->vtx.max_vert = 0;
- else
- exec->vtx.max_vert = ((VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) /
- (exec->vtx.vertex_size * sizeof(GLfloat)));
-
- exec->vtx.buffer_ptr = exec->vtx.buffer_map;
- exec->vtx.prim_count = 0;
- exec->vtx.vert_count = 0;
-}
-
-
-#endif /* FEATURE_beginend */
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.2
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "main/glheader.h"
+#include "main/bufferobj.h"
+#include "main/compiler.h"
+#include "main/enums.h"
+#include "main/mfeatures.h"
+#include "main/state.h"
+
+#include "vbo_context.h"
+
+
+#if FEATURE_beginend
+
+
+static void
+vbo_exec_debug_verts( struct vbo_exec_context *exec )
+{
+ GLuint count = exec->vtx.vert_count;
+ GLuint i;
+
+ printf("%s: %u vertices %d primitives, %d vertsize\n",
+ __FUNCTION__,
+ count,
+ exec->vtx.prim_count,
+ exec->vtx.vertex_size);
+
+ for (i = 0 ; i < exec->vtx.prim_count ; i++) {
+ struct _mesa_prim *prim = &exec->vtx.prim[i];
+ printf(" prim %d: %s%s %d..%d %s %s\n",
+ i,
+ _mesa_lookup_prim_by_nr(prim->mode),
+ prim->weak ? " (weak)" : "",
+ prim->start,
+ prim->start + prim->count,
+ prim->begin ? "BEGIN" : "(wrap)",
+ prim->end ? "END" : "(wrap)");
+ }
+}
+
+
+/*
+ * NOTE: Need to have calculated primitives by this point -- do it on the fly.
+ * NOTE: Old 'parity' issue is gone.
+ */
+static GLuint
+vbo_copy_vertices( struct vbo_exec_context *exec )
+{
+ GLuint nr = exec->vtx.prim[exec->vtx.prim_count-1].count;
+ GLuint ovf, i;
+ GLuint sz = exec->vtx.vertex_size;
+ GLfloat *dst = exec->vtx.copied.buffer;
+ const GLfloat *src = (exec->vtx.buffer_map +
+ exec->vtx.prim[exec->vtx.prim_count-1].start *
+ exec->vtx.vertex_size);
+
+
+ switch (exec->ctx->Driver.CurrentExecPrimitive) {
+ case GL_POINTS:
+ return 0;
+ case GL_LINES:
+ ovf = nr&1;
+ for (i = 0 ; i < ovf ; i++)
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+ return i;
+ case GL_TRIANGLES:
+ ovf = nr%3;
+ for (i = 0 ; i < ovf ; i++)
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+ return i;
+ case GL_QUADS:
+ ovf = nr&3;
+ for (i = 0 ; i < ovf ; i++)
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+ return i;
+ case GL_LINE_STRIP:
+ if (nr == 0) {
+ return 0;
+ }
+ else {
+ memcpy( dst, src+(nr-1)*sz, sz * sizeof(GLfloat) );
+ return 1;
+ }
+ case GL_LINE_LOOP:
+ case GL_TRIANGLE_FAN:
+ case GL_POLYGON:
+ if (nr == 0) {
+ return 0;
+ }
+ else if (nr == 1) {
+ memcpy( dst, src+0, sz * sizeof(GLfloat) );
+ return 1;
+ }
+ else {
+ memcpy( dst, src+0, sz * sizeof(GLfloat) );
+ memcpy( dst+sz, src+(nr-1)*sz, sz * sizeof(GLfloat) );
+ return 2;
+ }
+ case GL_TRIANGLE_STRIP:
+ /* no parity issue, but need to make sure the tri is not drawn twice */
+ if (nr & 1) {
+ exec->vtx.prim[exec->vtx.prim_count-1].count--;
+ }
+ /* fallthrough */
+ case GL_QUAD_STRIP:
+ switch (nr) {
+ case 0:
+ ovf = 0;
+ break;
+ case 1:
+ ovf = 1;
+ break;
+ default:
+ ovf = 2 + (nr & 1);
+ break;
+ }
+ for (i = 0 ; i < ovf ; i++)
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+ return i;
+ case PRIM_OUTSIDE_BEGIN_END:
+ return 0;
+ default:
+ assert(0);
+ return 0;
+ }
+}
+
+
+
+/* TODO: populate these as the vertex is defined:
+ */
+static void
+vbo_exec_bind_arrays( struct gl_context *ctx )
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_exec_context *exec = &vbo->exec;
+ struct gl_client_array *arrays = exec->vtx.arrays;
+ const GLuint count = exec->vtx.vert_count;
+ const GLuint *map;
+ GLuint attr;
+ GLbitfield varying_inputs = 0x0;
+
+ /* Install the default (ie Current) attributes first, then overlay
+ * all active ones.
+ */
+ switch (get_program_mode(exec->ctx)) {
+ case VP_NONE:
+ for (attr = 0; attr < 16; attr++) {
+ exec->vtx.inputs[attr] = &vbo->legacy_currval[attr];
+ }
+ for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) {
+ ASSERT(attr + 16 < Elements(exec->vtx.inputs));
+ exec->vtx.inputs[attr + 16] = &vbo->mat_currval[attr];
+ }
+ map = vbo->map_vp_none;
+ break;
+ case VP_NV:
+ case VP_ARB:
+ /* The aliasing of attributes for NV vertex programs has already
+ * occurred. NV vertex programs cannot access material values,
+ * nor attributes greater than VERT_ATTRIB_TEX7.
+ */
+ for (attr = 0; attr < 16; attr++) {
+ exec->vtx.inputs[attr] = &vbo->legacy_currval[attr];
+ ASSERT(attr + 16 < Elements(exec->vtx.inputs));
+ exec->vtx.inputs[attr + 16] = &vbo->generic_currval[attr];
+ }
+ map = vbo->map_vp_arb;
+
+ /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read.
+ * In that case we effectively need to route the data from
+ * glVertexAttrib(0, val) calls to feed into the GENERIC0 input.
+ */
+ if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 &&
+ (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) {
+ exec->vtx.inputs[16] = exec->vtx.inputs[0];
+ exec->vtx.attrsz[16] = exec->vtx.attrsz[0];
+ exec->vtx.attrptr[16] = exec->vtx.attrptr[0];
+ exec->vtx.attrsz[0] = 0;
+ }
+ break;
+ default:
+ assert(0);
+ }
+
+ /* Make all active attributes (including edgeflag) available as
+ * arrays of floats.
+ */
+ for (attr = 0; attr < VERT_ATTRIB_MAX ; attr++) {
+ const GLuint src = map[attr];
+
+ if (exec->vtx.attrsz[src]) {
+ GLsizeiptr offset = (GLbyte *)exec->vtx.attrptr[src] -
+ (GLbyte *)exec->vtx.vertex;
+
+ /* override the default array set above */
+ ASSERT(attr < Elements(exec->vtx.inputs));
+ ASSERT(attr < Elements(exec->vtx.arrays)); /* arrays[] */
+ exec->vtx.inputs[attr] = &arrays[attr];
+
+ if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
+ /* a real buffer obj: Ptr is an offset, not a pointer*/
+ assert(exec->vtx.bufferobj->Pointer); /* buf should be mapped */
+ assert(offset >= 0);
+ arrays[attr].Ptr = (GLubyte *)exec->vtx.bufferobj->Offset + offset;
+ }
+ else {
+ /* Ptr into ordinary app memory */
+ arrays[attr].Ptr = (GLubyte *)exec->vtx.buffer_map + offset;
+ }
+ arrays[attr].Size = exec->vtx.attrsz[src];
+ arrays[attr].StrideB = exec->vtx.vertex_size * sizeof(GLfloat);
+ arrays[attr].Stride = exec->vtx.vertex_size * sizeof(GLfloat);
+ arrays[attr].Type = GL_FLOAT;
+ arrays[attr].Format = GL_RGBA;
+ arrays[attr].Enabled = 1;
+ _mesa_reference_buffer_object(ctx,
+ &arrays[attr].BufferObj,
+ exec->vtx.bufferobj);
+ arrays[attr]._MaxElement = count; /* ??? */
+
+ varying_inputs |= 1 << attr;
+ ctx->NewState |= _NEW_ARRAY;
+ }
+ }
+
+ _mesa_set_varying_vp_inputs( ctx, varying_inputs );
+}
+
+
+/**
+ * Unmap the VBO. This is called before drawing.
+ */
+static void
+vbo_exec_vtx_unmap( struct vbo_exec_context *exec )
+{
+ GLenum target = GL_ARRAY_BUFFER_ARB;
+
+ if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
+ struct gl_context *ctx = exec->ctx;
+
+ if (ctx->Driver.FlushMappedBufferRange) {
+ GLintptr offset = exec->vtx.buffer_used - exec->vtx.bufferobj->Offset;
+ GLsizeiptr length = (exec->vtx.buffer_ptr - exec->vtx.buffer_map) * sizeof(float);
+
+ if (length)
+ ctx->Driver.FlushMappedBufferRange(ctx, target,
+ offset, length,
+ exec->vtx.bufferobj);
+ }
+
+ exec->vtx.buffer_used += (exec->vtx.buffer_ptr -
+ exec->vtx.buffer_map) * sizeof(float);
+
+ assert(exec->vtx.buffer_used <= VBO_VERT_BUFFER_SIZE);
+ assert(exec->vtx.buffer_ptr != NULL);
+
+ ctx->Driver.UnmapBuffer(ctx, target, exec->vtx.bufferobj);
+ exec->vtx.buffer_map = NULL;
+ exec->vtx.buffer_ptr = NULL;
+ exec->vtx.max_vert = 0;
+ }
+}
+
+
+/**
+ * Map the vertex buffer to begin storing glVertex, glColor, etc data.
+ */
+void
+vbo_exec_vtx_map( struct vbo_exec_context *exec )
+{
+ struct gl_context *ctx = exec->ctx;
+ const GLenum target = GL_ARRAY_BUFFER_ARB;
+ const GLenum access = GL_READ_WRITE_ARB; /* for MapBuffer */
+ const GLenum accessRange = GL_MAP_WRITE_BIT | /* for MapBufferRange */
+ GL_MAP_INVALIDATE_RANGE_BIT |
+ GL_MAP_UNSYNCHRONIZED_BIT |
+ GL_MAP_FLUSH_EXPLICIT_BIT |
+ MESA_MAP_NOWAIT_BIT;
+ const GLenum usage = GL_STREAM_DRAW_ARB;
+
+ if (!_mesa_is_bufferobj(exec->vtx.bufferobj))
+ return;
+
+ assert(!exec->vtx.buffer_map);
+ assert(!exec->vtx.buffer_ptr);
+
+ if (VBO_VERT_BUFFER_SIZE > exec->vtx.buffer_used + 1024 &&
+ ctx->Driver.MapBufferRange) {
+ /* The VBO exists and there's room for more */
+ exec->vtx.buffer_map =
+ (GLfloat *)ctx->Driver.MapBufferRange(ctx,
+ target,
+ exec->vtx.buffer_used,
+ (VBO_VERT_BUFFER_SIZE -
+ exec->vtx.buffer_used),
+ accessRange,
+ exec->vtx.bufferobj);
+ exec->vtx.buffer_ptr = exec->vtx.buffer_map;
+ }
+
+ if (!exec->vtx.buffer_map) {
+ /* Need to allocate a new VBO */
+ exec->vtx.buffer_used = 0;
+
+ ctx->Driver.BufferData(ctx, target,
+ VBO_VERT_BUFFER_SIZE,
+ NULL, usage, exec->vtx.bufferobj);
+
+
+ if (ctx->Driver.MapBufferRange)
+ exec->vtx.buffer_map =
+ (GLfloat *)ctx->Driver.MapBufferRange(ctx, target,
+ 0, VBO_VERT_BUFFER_SIZE,
+ accessRange,
+ exec->vtx.bufferobj);
+ if (!exec->vtx.buffer_map)
+ exec->vtx.buffer_map =
+ (GLfloat *)ctx->Driver.MapBuffer(ctx, target, access, exec->vtx.bufferobj);
+ assert(exec->vtx.buffer_map);
+ exec->vtx.buffer_ptr = exec->vtx.buffer_map;
+ }
+
+ if (0)
+ printf("map %d..\n", exec->vtx.buffer_used);
+}
+
+
+
+/**
+ * Execute the buffer and save copied verts.
+ * \param keep_unmapped if true, leave the VBO unmapped when we're done.
+ */
+void
+vbo_exec_vtx_flush(struct vbo_exec_context *exec, GLboolean keepUnmapped)
+{
+ if (0)
+ vbo_exec_debug_verts( exec );
+
+ if (exec->vtx.prim_count &&
+ exec->vtx.vert_count) {
+
+ exec->vtx.copied.nr = vbo_copy_vertices( exec );
+
+ if (exec->vtx.copied.nr != exec->vtx.vert_count) {
+ struct gl_context *ctx = exec->ctx;
+
+ /* Before the update_state() as this may raise _NEW_ARRAY
+ * from _mesa_set_varying_vp_inputs().
+ */
+ vbo_exec_bind_arrays( ctx );
+
+ if (ctx->NewState)
+ _mesa_update_state( ctx );
+
+ if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
+ vbo_exec_vtx_unmap( exec );
+ }
+
+ if (0)
+ printf("%s %d %d\n", __FUNCTION__, exec->vtx.prim_count,
+ exec->vtx.vert_count);
+
+ vbo_context(ctx)->draw_prims( ctx,
+ exec->vtx.inputs,
+ exec->vtx.prim,
+ exec->vtx.prim_count,
+ NULL,
+ GL_TRUE,
+ 0,
+ exec->vtx.vert_count - 1);
+
+ /* If using a real VBO, get new storage -- unless asked not to.
+ */
+ if (_mesa_is_bufferobj(exec->vtx.bufferobj) && !keepUnmapped) {
+ vbo_exec_vtx_map( exec );
+ }
+ }
+ }
+
+ /* May have to unmap explicitly if we didn't draw:
+ */
+ if (keepUnmapped &&
+ _mesa_is_bufferobj(exec->vtx.bufferobj) &&
+ exec->vtx.buffer_map) {
+ vbo_exec_vtx_unmap( exec );
+ }
+
+ if (keepUnmapped || exec->vtx.vertex_size == 0)
+ exec->vtx.max_vert = 0;
+ else
+ exec->vtx.max_vert = ((VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) /
+ (exec->vtx.vertex_size * sizeof(GLfloat)));
+
+ exec->vtx.buffer_ptr = exec->vtx.buffer_map;
+ exec->vtx.prim_count = 0;
+ exec->vtx.vert_count = 0;
+}
+
+
+#endif /* FEATURE_beginend */
diff --git a/mesalib/src/mesa/vbo/vbo_save_api.c b/mesalib/src/mesa/vbo/vbo_save_api.c
index fc5f60e92..d10d44139 100644
--- a/mesalib/src/mesa/vbo/vbo_save_api.c
+++ b/mesalib/src/mesa/vbo/vbo_save_api.c
@@ -1,1310 +1,1310 @@
-/**************************************************************************
-
-Copyright 2002-2008 Tungsten Graphics Inc., Cedar Park, Texas.
-
-All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-on the rights to use, copy, modify, merge, publish, distribute, sub
-license, and/or sell copies of the Software, and to permit persons to whom
-the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice (including the next
-paragraph) shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
-TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
-DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-/*
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- */
-
-
-
-/* Display list compiler attempts to store lists of vertices with the
- * same vertex layout. Additionally it attempts to minimize the need
- * for execute-time fixup of these vertex lists, allowing them to be
- * cached on hardware.
- *
- * There are still some circumstances where this can be thwarted, for
- * example by building a list that consists of one very long primitive
- * (eg Begin(Triangles), 1000 vertices, End), and calling that list
- * from inside a different begin/end object (Begin(Lines), CallList,
- * End).
- *
- * In that case the code will have to replay the list as individual
- * commands through the Exec dispatch table, or fix up the copied
- * vertices at execute-time.
- *
- * The other case where fixup is required is when a vertex attribute
- * is introduced in the middle of a primitive. Eg:
- * Begin(Lines)
- * TexCoord1f() Vertex2f()
- * TexCoord1f() Color3f() Vertex2f()
- * End()
- *
- * If the current value of Color isn't known at compile-time, this
- * primitive will require fixup.
- *
- *
- * The list compiler currently doesn't attempt to compile lists
- * containing EvalCoord or EvalPoint commands. On encountering one of
- * these, compilation falls back to opcodes.
- *
- * This could be improved to fallback only when a mix of EvalCoord and
- * Vertex commands are issued within a single primitive.
- */
-
-
-#include "main/glheader.h"
-#include "main/bufferobj.h"
-#include "main/context.h"
-#include "main/dlist.h"
-#include "main/enums.h"
-#include "main/eval.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-#include "main/api_noop.h"
-#include "main/api_validate.h"
-#include "main/api_arrayelt.h"
-#include "main/vtxfmt.h"
-#include "main/dispatch.h"
-
-#include "vbo_context.h"
-
-
-#if FEATURE_dlist
-
-
-#ifdef ERROR
-#undef ERROR
-#endif
-
-
-/* An interesting VBO number/name to help with debugging */
-#define VBO_BUF_ID 12345
-
-
-/*
- * NOTE: Old 'parity' issue is gone, but copying can still be
- * wrong-footed on replay.
- */
-static GLuint _save_copy_vertices( struct gl_context *ctx,
- const struct vbo_save_vertex_list *node,
- const GLfloat *src_buffer)
-{
- struct vbo_save_context *save = &vbo_context( ctx )->save;
- const struct _mesa_prim *prim = &node->prim[node->prim_count-1];
- GLuint nr = prim->count;
- GLuint sz = save->vertex_size;
- const GLfloat *src = src_buffer + prim->start * sz;
- GLfloat *dst = save->copied.buffer;
- GLuint ovf, i;
-
- if (prim->end)
- return 0;
-
- switch( prim->mode )
- {
- case GL_POINTS:
- return 0;
- case GL_LINES:
- ovf = nr&1;
- for (i = 0 ; i < ovf ; i++)
- memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
- return i;
- case GL_TRIANGLES:
- ovf = nr%3;
- for (i = 0 ; i < ovf ; i++)
- memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
- return i;
- case GL_QUADS:
- ovf = nr&3;
- for (i = 0 ; i < ovf ; i++)
- memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
- return i;
- case GL_LINE_STRIP:
- if (nr == 0)
- return 0;
- else {
- memcpy( dst, src+(nr-1)*sz, sz*sizeof(GLfloat) );
- return 1;
- }
- case GL_LINE_LOOP:
- case GL_TRIANGLE_FAN:
- case GL_POLYGON:
- if (nr == 0)
- return 0;
- else if (nr == 1) {
- memcpy( dst, src+0, sz*sizeof(GLfloat) );
- return 1;
- } else {
- memcpy( dst, src+0, sz*sizeof(GLfloat) );
- memcpy( dst+sz, src+(nr-1)*sz, sz*sizeof(GLfloat) );
- return 2;
- }
- case GL_TRIANGLE_STRIP:
- case GL_QUAD_STRIP:
- switch (nr) {
- case 0: ovf = 0; break;
- case 1: ovf = 1; break;
- default: ovf = 2 + (nr&1); break;
- }
- for (i = 0 ; i < ovf ; i++)
- memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
- return i;
- default:
- assert(0);
- return 0;
- }
-}
-
-
-static struct vbo_save_vertex_store *alloc_vertex_store( struct gl_context *ctx )
-{
- struct vbo_save_vertex_store *vertex_store = CALLOC_STRUCT(vbo_save_vertex_store);
-
- /* obj->Name needs to be non-zero, but won't ever be examined more
- * closely than that. In particular these buffers won't be entered
- * into the hash and can never be confused with ones visible to the
- * user. Perhaps there could be a special number for internal
- * buffers:
- */
- vertex_store->bufferobj = ctx->Driver.NewBufferObject(ctx,
- VBO_BUF_ID,
- GL_ARRAY_BUFFER_ARB);
-
- ctx->Driver.BufferData( ctx,
- GL_ARRAY_BUFFER_ARB,
- VBO_SAVE_BUFFER_SIZE * sizeof(GLfloat),
- NULL,
- GL_STATIC_DRAW_ARB,
- vertex_store->bufferobj);
-
- vertex_store->buffer = NULL;
- vertex_store->used = 0;
- vertex_store->refcount = 1;
-
- return vertex_store;
-}
-
-static void free_vertex_store( struct gl_context *ctx, struct vbo_save_vertex_store *vertex_store )
-{
- assert(!vertex_store->buffer);
-
- if (vertex_store->bufferobj) {
- _mesa_reference_buffer_object(ctx, &vertex_store->bufferobj, NULL);
- }
-
- FREE( vertex_store );
-}
-
-static GLfloat *map_vertex_store( struct gl_context *ctx, struct vbo_save_vertex_store *vertex_store )
-{
- assert(vertex_store->bufferobj);
- assert(!vertex_store->buffer);
- vertex_store->buffer = (GLfloat *)ctx->Driver.MapBuffer(ctx,
- GL_ARRAY_BUFFER_ARB, /* not used */
- GL_WRITE_ONLY, /* not used */
- vertex_store->bufferobj);
-
- assert(vertex_store->buffer);
- return vertex_store->buffer + vertex_store->used;
-}
-
-static void unmap_vertex_store( struct gl_context *ctx, struct vbo_save_vertex_store *vertex_store )
-{
- ctx->Driver.UnmapBuffer( ctx, GL_ARRAY_BUFFER_ARB, vertex_store->bufferobj );
- vertex_store->buffer = NULL;
-}
-
-
-static struct vbo_save_primitive_store *alloc_prim_store( struct gl_context *ctx )
-{
- struct vbo_save_primitive_store *store = CALLOC_STRUCT(vbo_save_primitive_store);
- (void) ctx;
- store->used = 0;
- store->refcount = 1;
- return store;
-}
-
-static void _save_reset_counters( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
-
- save->prim = save->prim_store->buffer + save->prim_store->used;
- save->buffer = (save->vertex_store->buffer +
- save->vertex_store->used);
-
- assert(save->buffer == save->buffer_ptr);
-
- if (save->vertex_size)
- save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
- save->vertex_size);
- else
- save->max_vert = 0;
-
- save->vert_count = 0;
- save->prim_count = 0;
- save->prim_max = VBO_SAVE_PRIM_SIZE - save->prim_store->used;
- save->dangling_attr_ref = 0;
-}
-
-
-/* Insert the active immediate struct onto the display list currently
- * being built.
- */
-static void _save_compile_vertex_list( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- struct vbo_save_vertex_list *node;
-
- /* Allocate space for this structure in the display list currently
- * being compiled.
- */
- node = (struct vbo_save_vertex_list *)
- _mesa_dlist_alloc(ctx, save->opcode_vertex_list, sizeof(*node));
-
- if (!node)
- return;
-
- /* Duplicate our template, increment refcounts to the storage structs:
- */
- memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
- node->vertex_size = save->vertex_size;
- node->buffer_offset = (save->buffer - save->vertex_store->buffer) * sizeof(GLfloat);
- node->count = save->vert_count;
- node->wrap_count = save->copied.nr;
- node->dangling_attr_ref = save->dangling_attr_ref;
- node->prim = save->prim;
- node->prim_count = save->prim_count;
- node->vertex_store = save->vertex_store;
- node->prim_store = save->prim_store;
-
- node->vertex_store->refcount++;
- node->prim_store->refcount++;
-
- if (node->prim[0].no_current_update) {
- node->current_size = 0;
- node->current_data = NULL;
- } else {
- node->current_size = node->vertex_size - node->attrsz[0];
- node->current_data = NULL;
-
- if (node->current_size) {
- /* If the malloc fails, we just pull the data out of the VBO
- * later instead.
- */
- node->current_data = MALLOC( node->current_size * sizeof(GLfloat) );
- if (node->current_data) {
- const char *buffer = (const char *)save->vertex_store->buffer;
- unsigned attr_offset = node->attrsz[0] * sizeof(GLfloat);
- unsigned vertex_offset = 0;
-
- if (node->count)
- vertex_offset = (node->count-1) * node->vertex_size * sizeof(GLfloat);
-
- memcpy( node->current_data,
- buffer + node->buffer_offset + vertex_offset + attr_offset,
- node->current_size * sizeof(GLfloat) );
- }
- }
- }
-
-
-
- assert(node->attrsz[VBO_ATTRIB_POS] != 0 ||
- node->count == 0);
-
- if (save->dangling_attr_ref)
- ctx->ListState.CurrentList->Flags |= DLIST_DANGLING_REFS;
-
- save->vertex_store->used += save->vertex_size * node->count;
- save->prim_store->used += node->prim_count;
-
-
- /* Copy duplicated vertices
- */
- save->copied.nr = _save_copy_vertices( ctx, node, save->buffer );
-
-
- /* Deal with GL_COMPILE_AND_EXECUTE:
- */
- if (ctx->ExecuteFlag) {
- struct _glapi_table *dispatch = GET_DISPATCH();
-
- _glapi_set_dispatch(ctx->Exec);
-
- vbo_loopback_vertex_list( ctx,
- (const GLfloat *)((const char *)save->vertex_store->buffer +
- node->buffer_offset),
- node->attrsz,
- node->prim,
- node->prim_count,
- node->wrap_count,
- node->vertex_size);
-
- _glapi_set_dispatch(dispatch);
- }
-
-
- /* Decide whether the storage structs are full, or can be used for
- * the next vertex lists as well.
- */
- if (save->vertex_store->used >
- VBO_SAVE_BUFFER_SIZE - 16 * (save->vertex_size + 4)) {
-
- /* Unmap old store:
- */
- unmap_vertex_store( ctx, save->vertex_store );
-
- /* Release old reference:
- */
- save->vertex_store->refcount--;
- assert(save->vertex_store->refcount != 0);
- save->vertex_store = NULL;
-
- /* Allocate and map new store:
- */
- save->vertex_store = alloc_vertex_store( ctx );
- save->buffer_ptr = map_vertex_store( ctx, save->vertex_store );
- }
-
- if (save->prim_store->used > VBO_SAVE_PRIM_SIZE - 6) {
- save->prim_store->refcount--;
- assert(save->prim_store->refcount != 0);
- save->prim_store = alloc_prim_store( ctx );
- }
-
- /* Reset our structures for the next run of vertices:
- */
- _save_reset_counters( ctx );
-}
-
-
-/* TODO -- If no new vertices have been stored, don't bother saving
- * it.
- */
-static void _save_wrap_buffers( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLint i = save->prim_count - 1;
- GLenum mode;
- GLboolean weak;
- GLboolean no_current_update;
-
- assert(i < (GLint) save->prim_max);
- assert(i >= 0);
-
- /* Close off in-progress primitive.
- */
- save->prim[i].count = (save->vert_count -
- save->prim[i].start);
- mode = save->prim[i].mode;
- weak = save->prim[i].weak;
- no_current_update = save->prim[i].no_current_update;
-
- /* store the copied vertices, and allocate a new list.
- */
- _save_compile_vertex_list( ctx );
-
- /* Restart interrupted primitive
- */
- save->prim[0].mode = mode;
- save->prim[0].weak = weak;
- save->prim[0].no_current_update = no_current_update;
- save->prim[0].begin = 0;
- save->prim[0].end = 0;
- save->prim[0].pad = 0;
- save->prim[0].start = 0;
- save->prim[0].count = 0;
- save->prim[0].num_instances = 1;
- save->prim_count = 1;
-}
-
-
-
-/* Called only when buffers are wrapped as the result of filling the
- * vertex_store struct.
- */
-static void _save_wrap_filled_vertex( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLfloat *data = save->copied.buffer;
- GLuint i;
-
- /* Emit a glEnd to close off the last vertex list.
- */
- _save_wrap_buffers( ctx );
-
- /* Copy stored stored vertices to start of new list.
- */
- assert(save->max_vert - save->vert_count > save->copied.nr);
-
- for (i = 0 ; i < save->copied.nr ; i++) {
- memcpy( save->buffer_ptr, data, save->vertex_size * sizeof(GLfloat));
- data += save->vertex_size;
- save->buffer_ptr += save->vertex_size;
- save->vert_count++;
- }
-}
-
-
-static void _save_copy_to_current( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLuint i;
-
- for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
- if (save->attrsz[i]) {
- save->currentsz[i][0] = save->attrsz[i];
- COPY_CLEAN_4V(save->current[i],
- save->attrsz[i],
- save->attrptr[i]);
- }
- }
-}
-
-
-static void _save_copy_from_current( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLint i;
-
- for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
- switch (save->attrsz[i]) {
- case 4: save->attrptr[i][3] = save->current[i][3];
- case 3: save->attrptr[i][2] = save->current[i][2];
- case 2: save->attrptr[i][1] = save->current[i][1];
- case 1: save->attrptr[i][0] = save->current[i][0];
- case 0: break;
- }
- }
-}
-
-
-
-
-/* Flush existing data, set new attrib size, replay copied vertices.
- */
-static void _save_upgrade_vertex( struct gl_context *ctx,
- GLuint attr,
- GLuint newsz )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLuint oldsz;
- GLuint i;
- GLfloat *tmp;
-
- /* Store the current run of vertices, and emit a GL_END. Emit a
- * BEGIN in the new buffer.
- */
- if (save->vert_count)
- _save_wrap_buffers( ctx );
- else
- assert( save->copied.nr == 0 );
-
- /* Do a COPY_TO_CURRENT to ensure back-copying works for the case
- * when the attribute already exists in the vertex and is having
- * its size increased.
- */
- _save_copy_to_current( ctx );
-
- /* Fix up sizes:
- */
- oldsz = save->attrsz[attr];
- save->attrsz[attr] = newsz;
-
- save->vertex_size += newsz - oldsz;
- save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
- save->vertex_size);
- save->vert_count = 0;
-
- /* Recalculate all the attrptr[] values:
- */
- for (i = 0, tmp = save->vertex ; i < VBO_ATTRIB_MAX ; i++) {
- if (save->attrsz[i]) {
- save->attrptr[i] = tmp;
- tmp += save->attrsz[i];
- }
- else
- save->attrptr[i] = NULL; /* will not be dereferenced. */
- }
-
- /* Copy from current to repopulate the vertex with correct values.
- */
- _save_copy_from_current( ctx );
-
- /* Replay stored vertices to translate them to new format here.
- *
- * If there are copied vertices and the new (upgraded) attribute
- * has not been defined before, this list is somewhat degenerate,
- * and will need fixup at runtime.
- */
- if (save->copied.nr)
- {
- GLfloat *data = save->copied.buffer;
- GLfloat *dest = save->buffer;
- GLuint j;
-
- /* Need to note this and fix up at runtime (or loopback):
- */
- if (attr != VBO_ATTRIB_POS && save->currentsz[attr][0] == 0) {
- assert(oldsz == 0);
- save->dangling_attr_ref = GL_TRUE;
- }
-
- for (i = 0 ; i < save->copied.nr ; i++) {
- for (j = 0 ; j < VBO_ATTRIB_MAX ; j++) {
- if (save->attrsz[j]) {
- if (j == attr) {
- if (oldsz) {
- COPY_CLEAN_4V( dest, oldsz, data );
- data += oldsz;
- dest += newsz;
- }
- else {
- COPY_SZ_4V( dest, newsz, save->current[attr] );
- dest += newsz;
- }
- }
- else {
- GLint sz = save->attrsz[j];
- COPY_SZ_4V( dest, sz, data );
- data += sz;
- dest += sz;
- }
- }
- }
- }
-
- save->buffer_ptr = dest;
- save->vert_count += save->copied.nr;
- }
-}
-
-static void save_fixup_vertex( struct gl_context *ctx, GLuint attr, GLuint sz )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
-
- if (sz > save->attrsz[attr]) {
- /* New size is larger. Need to flush existing vertices and get
- * an enlarged vertex format.
- */
- _save_upgrade_vertex( ctx, attr, sz );
- }
- else if (sz < save->active_sz[attr]) {
- static GLfloat id[4] = { 0, 0, 0, 1 };
- GLuint i;
-
- /* New size is equal or smaller - just need to fill in some
- * zeros.
- */
- for (i = sz ; i <= save->attrsz[attr] ; i++)
- save->attrptr[attr][i-1] = id[i-1];
- }
-
- save->active_sz[attr] = sz;
-}
-
-static void _save_reset_vertex( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLuint i;
-
- for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) {
- save->attrsz[i] = 0;
- save->active_sz[i] = 0;
- }
-
- save->vertex_size = 0;
-}
-
-
-
-#define ERROR(err) _mesa_compile_error( ctx, GL_INVALID_ENUM, __FUNCTION__ );
-
-
-/* Only one size for each attribute may be active at once. Eg. if
- * Color3f is installed/active, then Color4f may not be, even if the
- * vertex actually contains 4 color coordinates. This is because the
- * 3f version won't otherwise set color[3] to 1.0 -- this is the job
- * of the chooser function when switching between Color4f and Color3f.
- */
-#define ATTR( A, N, V0, V1, V2, V3 ) \
-do { \
- struct vbo_save_context *save = &vbo_context(ctx)->save; \
- \
- if (save->active_sz[A] != N) \
- save_fixup_vertex(ctx, A, N); \
- \
- { \
- GLfloat *dest = save->attrptr[A]; \
- if (N>0) dest[0] = V0; \
- if (N>1) dest[1] = V1; \
- if (N>2) dest[2] = V2; \
- if (N>3) dest[3] = V3; \
- } \
- \
- if ((A) == 0) { \
- GLuint i; \
- \
- for (i = 0; i < save->vertex_size; i++) \
- save->buffer_ptr[i] = save->vertex[i]; \
- \
- save->buffer_ptr += save->vertex_size; \
- \
- if (++save->vert_count >= save->max_vert) \
- _save_wrap_filled_vertex( ctx ); \
- } \
-} while (0)
-
-#define TAG(x) _save_##x
-
-#include "vbo_attrib_tmp.h"
-
-
-
-
-/* Cope with EvalCoord/CallList called within a begin/end object:
- * -- Flush current buffer
- * -- Fallback to opcodes for the rest of the begin/end object.
- */
-static void DO_FALLBACK( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
-
- if (save->vert_count || save->prim_count) {
- GLint i = save->prim_count - 1;
-
- /* Close off in-progress primitive.
- */
- save->prim[i].count = (save->vert_count -
- save->prim[i].start);
-
- /* Need to replay this display list with loopback,
- * unfortunately, otherwise this primitive won't be handled
- * properly:
- */
- save->dangling_attr_ref = 1;
-
- _save_compile_vertex_list( ctx );
- }
-
- _save_copy_to_current( ctx );
- _save_reset_vertex( ctx );
- _save_reset_counters( ctx );
- _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
- ctx->Driver.SaveNeedFlush = 0;
-}
-
-static void GLAPIENTRY _save_EvalCoord1f( GLfloat u )
-{
- GET_CURRENT_CONTEXT(ctx);
- DO_FALLBACK(ctx);
- CALL_EvalCoord1f(ctx->Save, (u));
-}
-
-static void GLAPIENTRY _save_EvalCoord1fv( const GLfloat *v )
-{
- GET_CURRENT_CONTEXT(ctx);
- DO_FALLBACK(ctx);
- CALL_EvalCoord1fv(ctx->Save, (v));
-}
-
-static void GLAPIENTRY _save_EvalCoord2f( GLfloat u, GLfloat v )
-{
- GET_CURRENT_CONTEXT(ctx);
- DO_FALLBACK(ctx);
- CALL_EvalCoord2f(ctx->Save, (u, v));
-}
-
-static void GLAPIENTRY _save_EvalCoord2fv( const GLfloat *v )
-{
- GET_CURRENT_CONTEXT(ctx);
- DO_FALLBACK(ctx);
- CALL_EvalCoord2fv(ctx->Save, (v));
-}
-
-static void GLAPIENTRY _save_EvalPoint1( GLint i )
-{
- GET_CURRENT_CONTEXT(ctx);
- DO_FALLBACK(ctx);
- CALL_EvalPoint1(ctx->Save, (i));
-}
-
-static void GLAPIENTRY _save_EvalPoint2( GLint i, GLint j )
-{
- GET_CURRENT_CONTEXT(ctx);
- DO_FALLBACK(ctx);
- CALL_EvalPoint2(ctx->Save, (i, j));
-}
-
-static void GLAPIENTRY _save_CallList( GLuint l )
-{
- GET_CURRENT_CONTEXT(ctx);
- DO_FALLBACK(ctx);
- CALL_CallList(ctx->Save, (l));
-}
-
-static void GLAPIENTRY _save_CallLists( GLsizei n, GLenum type, const GLvoid *v )
-{
- GET_CURRENT_CONTEXT(ctx);
- DO_FALLBACK(ctx);
- CALL_CallLists(ctx->Save, (n, type, v));
-}
-
-
-
-
-/* This begin is hooked into ... Updating of
- * ctx->Driver.CurrentSavePrimitive is already taken care of.
- */
-GLboolean vbo_save_NotifyBegin( struct gl_context *ctx, GLenum mode )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
-
- GLuint i = save->prim_count++;
-
- assert(i < save->prim_max);
- save->prim[i].mode = mode & VBO_SAVE_PRIM_MODE_MASK;
- save->prim[i].begin = 1;
- save->prim[i].end = 0;
- save->prim[i].weak = (mode & VBO_SAVE_PRIM_WEAK) ? 1 : 0;
- save->prim[i].no_current_update = (mode & VBO_SAVE_PRIM_NO_CURRENT_UPDATE) ? 1 : 0;
- save->prim[i].pad = 0;
- save->prim[i].start = save->vert_count;
- save->prim[i].count = 0;
- save->prim[i].num_instances = 1;
-
- _mesa_install_save_vtxfmt( ctx, &save->vtxfmt );
- ctx->Driver.SaveNeedFlush = 1;
- return GL_TRUE;
-}
-
-
-
-static void GLAPIENTRY _save_End( void )
-{
- GET_CURRENT_CONTEXT( ctx );
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLint i = save->prim_count - 1;
-
- ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
- save->prim[i].end = 1;
- save->prim[i].count = (save->vert_count -
- save->prim[i].start);
-
- if (i == (GLint) save->prim_max - 1) {
- _save_compile_vertex_list( ctx );
- assert(save->copied.nr == 0);
- }
-
- /* Swap out this vertex format while outside begin/end. Any color,
- * etc. received between here and the next begin will be compiled
- * as opcodes.
- */
- _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
-}
-
-
-/* These are all errors as this vtxfmt is only installed inside
- * begin/end pairs.
- */
-static void GLAPIENTRY _save_DrawElements(GLenum mode, GLsizei count, GLenum type,
- const GLvoid *indices)
-{
- GET_CURRENT_CONTEXT(ctx);
- (void) mode; (void) count; (void) type; (void) indices;
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawElements" );
-}
-
-
-static void GLAPIENTRY _save_DrawRangeElements(GLenum mode,
- GLuint start, GLuint end,
- GLsizei count, GLenum type,
- const GLvoid *indices)
-{
- GET_CURRENT_CONTEXT(ctx);
- (void) mode; (void) start; (void) end; (void) count; (void) type; (void) indices;
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawRangeElements" );
-}
-
-static void GLAPIENTRY _save_DrawElementsBaseVertex(GLenum mode,
- GLsizei count,
- GLenum type,
- const GLvoid *indices,
- GLint basevertex)
-{
- GET_CURRENT_CONTEXT(ctx);
- (void) mode; (void) count; (void) type; (void) indices; (void)basevertex;
-
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawElements" );
-}
-
-static void GLAPIENTRY _save_DrawRangeElementsBaseVertex(GLenum mode,
- GLuint start,
- GLuint end,
- GLsizei count,
- GLenum type,
- const GLvoid *indices,
- GLint basevertex)
-{
- GET_CURRENT_CONTEXT(ctx);
- (void) mode; (void) start; (void) end; (void) count; (void) type;
- (void) indices; (void)basevertex;
-
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawRangeElements" );
-}
-
-static void GLAPIENTRY _save_DrawArrays(GLenum mode, GLint start, GLsizei count)
-{
- GET_CURRENT_CONTEXT(ctx);
- (void) mode; (void) start; (void) count;
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawArrays" );
-}
-
-static void GLAPIENTRY _save_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
-{
- GET_CURRENT_CONTEXT(ctx);
- (void) x1; (void) y1; (void) x2; (void) y2;
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glRectf" );
-}
-
-static void GLAPIENTRY _save_EvalMesh1( GLenum mode, GLint i1, GLint i2 )
-{
- GET_CURRENT_CONTEXT(ctx);
- (void) mode; (void) i1; (void) i2;
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glEvalMesh1" );
-}
-
-static void GLAPIENTRY _save_EvalMesh2( GLenum mode, GLint i1, GLint i2,
- GLint j1, GLint j2 )
-{
- GET_CURRENT_CONTEXT(ctx);
- (void) mode; (void) i1; (void) i2; (void) j1; (void) j2;
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glEvalMesh2" );
-}
-
-static void GLAPIENTRY _save_Begin( GLenum mode )
-{
- GET_CURRENT_CONTEXT( ctx );
- (void) mode;
- _mesa_compile_error( ctx, GL_INVALID_OPERATION, "Recursive glBegin" );
-}
-
-
-static void GLAPIENTRY _save_PrimitiveRestartNV( void )
-{
- GLenum curPrim;
- GET_CURRENT_CONTEXT( ctx );
-
- curPrim = ctx->Driver.CurrentSavePrimitive;
-
- _save_End();
- _save_Begin(curPrim);
-}
-
-
-/* Unlike the functions above, these are to be hooked into the vtxfmt
- * maintained in ctx->ListState, active when the list is known or
- * suspected to be outside any begin/end primitive.
- */
-static void GLAPIENTRY _save_OBE_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
-{
- GET_CURRENT_CONTEXT(ctx);
- vbo_save_NotifyBegin( ctx, GL_QUADS | VBO_SAVE_PRIM_WEAK );
- CALL_Vertex2f(GET_DISPATCH(), ( x1, y1 ));
- CALL_Vertex2f(GET_DISPATCH(), ( x2, y1 ));
- CALL_Vertex2f(GET_DISPATCH(), ( x2, y2 ));
- CALL_Vertex2f(GET_DISPATCH(), ( x1, y2 ));
- CALL_End(GET_DISPATCH(), ());
-}
-
-
-static void GLAPIENTRY _save_OBE_DrawArrays(GLenum mode, GLint start, GLsizei count)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i;
-
- if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
- return;
-
- _ae_map_vbos( ctx );
-
- vbo_save_NotifyBegin( ctx, mode | VBO_SAVE_PRIM_WEAK | VBO_SAVE_PRIM_NO_CURRENT_UPDATE);
-
- for (i = 0; i < count; i++)
- CALL_ArrayElement(GET_DISPATCH(), (start + i));
- CALL_End(GET_DISPATCH(), ());
-
- _ae_unmap_vbos( ctx );
-}
-
-/* Could do better by copying the arrays and element list intact and
- * then emitting an indexed prim at runtime.
- */
-static void GLAPIENTRY _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum type,
- const GLvoid *indices)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i;
-
- if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, 0 ))
- return;
-
- _ae_map_vbos( ctx );
-
- if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj))
- indices = ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Pointer, indices);
-
- vbo_save_NotifyBegin( ctx, mode | VBO_SAVE_PRIM_WEAK | VBO_SAVE_PRIM_NO_CURRENT_UPDATE );
-
- switch (type) {
- case GL_UNSIGNED_BYTE:
- for (i = 0 ; i < count ; i++)
- CALL_ArrayElement(GET_DISPATCH(), ( ((GLubyte *)indices)[i] ));
- break;
- case GL_UNSIGNED_SHORT:
- for (i = 0 ; i < count ; i++)
- CALL_ArrayElement(GET_DISPATCH(), ( ((GLushort *)indices)[i] ));
- break;
- case GL_UNSIGNED_INT:
- for (i = 0 ; i < count ; i++)
- CALL_ArrayElement(GET_DISPATCH(), ( ((GLuint *)indices)[i] ));
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
- break;
- }
-
- CALL_End(GET_DISPATCH(), ());
-
- _ae_unmap_vbos( ctx );
-}
-
-static void GLAPIENTRY _save_OBE_DrawRangeElements(GLenum mode,
- GLuint start, GLuint end,
- GLsizei count, GLenum type,
- const GLvoid *indices)
-{
- GET_CURRENT_CONTEXT(ctx);
- if (_mesa_validate_DrawRangeElements( ctx, mode,
- start, end,
- count, type, indices, 0 ))
- _save_OBE_DrawElements( mode, count, type, indices );
-}
-
-
-
-
-
-static void _save_vtxfmt_init( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLvertexformat *vfmt = &save->vtxfmt;
-
- _MESA_INIT_ARRAYELT_VTXFMT(vfmt, _ae_);
-
- vfmt->Begin = _save_Begin;
- vfmt->Color3f = _save_Color3f;
- vfmt->Color3fv = _save_Color3fv;
- vfmt->Color4f = _save_Color4f;
- vfmt->Color4fv = _save_Color4fv;
- vfmt->EdgeFlag = _save_EdgeFlag;
- vfmt->End = _save_End;
- vfmt->PrimitiveRestartNV = _save_PrimitiveRestartNV;
- vfmt->FogCoordfEXT = _save_FogCoordfEXT;
- vfmt->FogCoordfvEXT = _save_FogCoordfvEXT;
- vfmt->Indexf = _save_Indexf;
- vfmt->Indexfv = _save_Indexfv;
- vfmt->Materialfv = _save_Materialfv;
- vfmt->MultiTexCoord1fARB = _save_MultiTexCoord1f;
- vfmt->MultiTexCoord1fvARB = _save_MultiTexCoord1fv;
- vfmt->MultiTexCoord2fARB = _save_MultiTexCoord2f;
- vfmt->MultiTexCoord2fvARB = _save_MultiTexCoord2fv;
- vfmt->MultiTexCoord3fARB = _save_MultiTexCoord3f;
- vfmt->MultiTexCoord3fvARB = _save_MultiTexCoord3fv;
- vfmt->MultiTexCoord4fARB = _save_MultiTexCoord4f;
- vfmt->MultiTexCoord4fvARB = _save_MultiTexCoord4fv;
- vfmt->Normal3f = _save_Normal3f;
- vfmt->Normal3fv = _save_Normal3fv;
- vfmt->SecondaryColor3fEXT = _save_SecondaryColor3fEXT;
- vfmt->SecondaryColor3fvEXT = _save_SecondaryColor3fvEXT;
- vfmt->TexCoord1f = _save_TexCoord1f;
- vfmt->TexCoord1fv = _save_TexCoord1fv;
- vfmt->TexCoord2f = _save_TexCoord2f;
- vfmt->TexCoord2fv = _save_TexCoord2fv;
- vfmt->TexCoord3f = _save_TexCoord3f;
- vfmt->TexCoord3fv = _save_TexCoord3fv;
- vfmt->TexCoord4f = _save_TexCoord4f;
- vfmt->TexCoord4fv = _save_TexCoord4fv;
- vfmt->Vertex2f = _save_Vertex2f;
- vfmt->Vertex2fv = _save_Vertex2fv;
- vfmt->Vertex3f = _save_Vertex3f;
- vfmt->Vertex3fv = _save_Vertex3fv;
- vfmt->Vertex4f = _save_Vertex4f;
- vfmt->Vertex4fv = _save_Vertex4fv;
- vfmt->VertexAttrib1fARB = _save_VertexAttrib1fARB;
- vfmt->VertexAttrib1fvARB = _save_VertexAttrib1fvARB;
- vfmt->VertexAttrib2fARB = _save_VertexAttrib2fARB;
- vfmt->VertexAttrib2fvARB = _save_VertexAttrib2fvARB;
- vfmt->VertexAttrib3fARB = _save_VertexAttrib3fARB;
- vfmt->VertexAttrib3fvARB = _save_VertexAttrib3fvARB;
- vfmt->VertexAttrib4fARB = _save_VertexAttrib4fARB;
- vfmt->VertexAttrib4fvARB = _save_VertexAttrib4fvARB;
-
- vfmt->VertexAttrib1fNV = _save_VertexAttrib1fNV;
- vfmt->VertexAttrib1fvNV = _save_VertexAttrib1fvNV;
- vfmt->VertexAttrib2fNV = _save_VertexAttrib2fNV;
- vfmt->VertexAttrib2fvNV = _save_VertexAttrib2fvNV;
- vfmt->VertexAttrib3fNV = _save_VertexAttrib3fNV;
- vfmt->VertexAttrib3fvNV = _save_VertexAttrib3fvNV;
- vfmt->VertexAttrib4fNV = _save_VertexAttrib4fNV;
- vfmt->VertexAttrib4fvNV = _save_VertexAttrib4fvNV;
-
- /* integer-valued */
- vfmt->VertexAttribI1i = _save_VertexAttribI1i;
- vfmt->VertexAttribI2i = _save_VertexAttribI2i;
- vfmt->VertexAttribI3i = _save_VertexAttribI3i;
- vfmt->VertexAttribI4i = _save_VertexAttribI4i;
- vfmt->VertexAttribI2iv = _save_VertexAttribI2iv;
- vfmt->VertexAttribI3iv = _save_VertexAttribI3iv;
- vfmt->VertexAttribI4iv = _save_VertexAttribI4iv;
-
- /* unsigned integer-valued */
- vfmt->VertexAttribI1ui = _save_VertexAttribI1ui;
- vfmt->VertexAttribI2ui = _save_VertexAttribI2ui;
- vfmt->VertexAttribI3ui = _save_VertexAttribI3ui;
- vfmt->VertexAttribI4ui = _save_VertexAttribI4ui;
- vfmt->VertexAttribI2uiv = _save_VertexAttribI2uiv;
- vfmt->VertexAttribI3uiv = _save_VertexAttribI3uiv;
- vfmt->VertexAttribI4uiv = _save_VertexAttribI4uiv;
-
- /* This will all require us to fallback to saving the list as opcodes:
- */
- _MESA_INIT_DLIST_VTXFMT(vfmt, _save_); /* inside begin/end */
-
- _MESA_INIT_EVAL_VTXFMT(vfmt, _save_);
-
- /* These are all errors as we at least know we are in some sort of
- * begin/end pair:
- */
- vfmt->Begin = _save_Begin;
- vfmt->Rectf = _save_Rectf;
- vfmt->DrawArrays = _save_DrawArrays;
- vfmt->DrawElements = _save_DrawElements;
- vfmt->DrawRangeElements = _save_DrawRangeElements;
- vfmt->DrawElementsBaseVertex = _save_DrawElementsBaseVertex;
- vfmt->DrawRangeElementsBaseVertex = _save_DrawRangeElementsBaseVertex;
- /* Loops back into vfmt->DrawElements */
- vfmt->MultiDrawElementsEXT = _mesa_noop_MultiDrawElements;
- vfmt->MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex;
-}
-
-
-void vbo_save_SaveFlushVertices( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
-
- /* Noop when we are actually active:
- */
- if (ctx->Driver.CurrentSavePrimitive == PRIM_INSIDE_UNKNOWN_PRIM ||
- ctx->Driver.CurrentSavePrimitive <= GL_POLYGON)
- return;
-
- if (save->vert_count ||
- save->prim_count)
- _save_compile_vertex_list( ctx );
-
- _save_copy_to_current( ctx );
- _save_reset_vertex( ctx );
- _save_reset_counters( ctx );
- ctx->Driver.SaveNeedFlush = 0;
-}
-
-void vbo_save_NewList( struct gl_context *ctx, GLuint list, GLenum mode )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
-
- (void) list; (void) mode;
-
- if (!save->prim_store)
- save->prim_store = alloc_prim_store( ctx );
-
- if (!save->vertex_store)
- save->vertex_store = alloc_vertex_store( ctx );
-
- save->buffer_ptr = map_vertex_store( ctx, save->vertex_store );
-
- _save_reset_vertex( ctx );
- _save_reset_counters( ctx );
- ctx->Driver.SaveNeedFlush = 0;
-}
-
-void vbo_save_EndList( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
-
- /* EndList called inside a (saved) Begin/End pair?
- */
- if (ctx->Driver.CurrentSavePrimitive != PRIM_OUTSIDE_BEGIN_END) {
-
- if (save->prim_count > 0) {
- GLint i = save->prim_count - 1;
- ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
- save->prim[i].end = 0;
- save->prim[i].count = (save->vert_count -
- save->prim[i].start);
- }
-
- /* Make sure this vertex list gets replayed by the "loopback"
- * mechanism:
- */
- save->dangling_attr_ref = 1;
- vbo_save_SaveFlushVertices( ctx );
-
- /* Swap out this vertex format while outside begin/end. Any color,
- * etc. received between here and the next begin will be compiled
- * as opcodes.
- */
- _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
- }
-
- unmap_vertex_store( ctx, save->vertex_store );
-
- assert(save->vertex_size == 0);
-}
-
-void vbo_save_BeginCallList( struct gl_context *ctx, struct gl_display_list *dlist )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- save->replay_flags |= dlist->Flags;
-}
-
-void vbo_save_EndCallList( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
-
- if (ctx->ListState.CallDepth == 1) {
- /* This is correct: want to keep only the VBO_SAVE_FALLBACK
- * flag, if it is set:
- */
- save->replay_flags &= VBO_SAVE_FALLBACK;
- }
-}
-
-
-static void vbo_destroy_vertex_list( struct gl_context *ctx, void *data )
-{
- struct vbo_save_vertex_list *node = (struct vbo_save_vertex_list *)data;
- (void) ctx;
-
- if ( --node->vertex_store->refcount == 0 )
- free_vertex_store( ctx, node->vertex_store );
-
- if ( --node->prim_store->refcount == 0 )
- FREE( node->prim_store );
-
- if (node->current_data) {
- FREE(node->current_data);
- node->current_data = NULL;
- }
-}
-
-
-static void vbo_print_vertex_list( struct gl_context *ctx, void *data )
-{
- struct vbo_save_vertex_list *node = (struct vbo_save_vertex_list *)data;
- GLuint i;
- (void) ctx;
-
- printf("VBO-VERTEX-LIST, %u vertices %d primitives, %d vertsize\n",
- node->count,
- node->prim_count,
- node->vertex_size);
-
- for (i = 0 ; i < node->prim_count ; i++) {
- struct _mesa_prim *prim = &node->prim[i];
- _mesa_debug(NULL, " prim %d: %s%s %d..%d %s %s\n",
- i,
- _mesa_lookup_prim_by_nr(prim->mode),
- prim->weak ? " (weak)" : "",
- prim->start,
- prim->start + prim->count,
- (prim->begin) ? "BEGIN" : "(wrap)",
- (prim->end) ? "END" : "(wrap)");
- }
-}
-
-
-static void _save_current_init( struct gl_context *ctx )
-{
- struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLint i;
-
- for (i = VBO_ATTRIB_POS; i <= VBO_ATTRIB_GENERIC15; i++) {
- const GLuint j = i - VBO_ATTRIB_POS;
- ASSERT(j < VERT_ATTRIB_MAX);
- save->currentsz[i] = &ctx->ListState.ActiveAttribSize[j];
- save->current[i] = ctx->ListState.CurrentAttrib[j];
- }
-
- for (i = VBO_ATTRIB_FIRST_MATERIAL; i <= VBO_ATTRIB_LAST_MATERIAL; i++) {
- const GLuint j = i - VBO_ATTRIB_FIRST_MATERIAL;
- ASSERT(j < MAT_ATTRIB_MAX);
- save->currentsz[i] = &ctx->ListState.ActiveMaterialSize[j];
- save->current[i] = ctx->ListState.CurrentMaterial[j];
- }
-}
-
-/**
- * Initialize the display list compiler
- */
-void vbo_save_api_init( struct vbo_save_context *save )
-{
- struct gl_context *ctx = save->ctx;
- GLuint i;
-
- save->opcode_vertex_list =
- _mesa_dlist_alloc_opcode( ctx,
- sizeof(struct vbo_save_vertex_list),
- vbo_save_playback_vertex_list,
- vbo_destroy_vertex_list,
- vbo_print_vertex_list );
-
- ctx->Driver.NotifySaveBegin = vbo_save_NotifyBegin;
-
- _save_vtxfmt_init( ctx );
- _save_current_init( ctx );
-
- /* These will actually get set again when binding/drawing */
- for (i = 0; i < VBO_ATTRIB_MAX; i++)
- save->inputs[i] = &save->arrays[i];
-
- /* Hook our array functions into the outside-begin-end vtxfmt in
- * ctx->ListState.
- */
- ctx->ListState.ListVtxfmt.Rectf = _save_OBE_Rectf;
- ctx->ListState.ListVtxfmt.DrawArrays = _save_OBE_DrawArrays;
- ctx->ListState.ListVtxfmt.DrawElements = _save_OBE_DrawElements;
- ctx->ListState.ListVtxfmt.DrawRangeElements = _save_OBE_DrawRangeElements;
- /* loops back into _save_OBE_DrawElements */
- ctx->ListState.ListVtxfmt.MultiDrawElementsEXT = _mesa_noop_MultiDrawElements;
- ctx->ListState.ListVtxfmt.MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex;
- _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
-}
-
-
-#endif /* FEATURE_dlist */
+/**************************************************************************
+
+Copyright 2002-2008 Tungsten Graphics Inc., Cedar Park, Texas.
+
+All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+on the rights to use, copy, modify, merge, publish, distribute, sub
+license, and/or sell copies of the Software, and to permit persons to whom
+the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+
+/* Display list compiler attempts to store lists of vertices with the
+ * same vertex layout. Additionally it attempts to minimize the need
+ * for execute-time fixup of these vertex lists, allowing them to be
+ * cached on hardware.
+ *
+ * There are still some circumstances where this can be thwarted, for
+ * example by building a list that consists of one very long primitive
+ * (eg Begin(Triangles), 1000 vertices, End), and calling that list
+ * from inside a different begin/end object (Begin(Lines), CallList,
+ * End).
+ *
+ * In that case the code will have to replay the list as individual
+ * commands through the Exec dispatch table, or fix up the copied
+ * vertices at execute-time.
+ *
+ * The other case where fixup is required is when a vertex attribute
+ * is introduced in the middle of a primitive. Eg:
+ * Begin(Lines)
+ * TexCoord1f() Vertex2f()
+ * TexCoord1f() Color3f() Vertex2f()
+ * End()
+ *
+ * If the current value of Color isn't known at compile-time, this
+ * primitive will require fixup.
+ *
+ *
+ * The list compiler currently doesn't attempt to compile lists
+ * containing EvalCoord or EvalPoint commands. On encountering one of
+ * these, compilation falls back to opcodes.
+ *
+ * This could be improved to fallback only when a mix of EvalCoord and
+ * Vertex commands are issued within a single primitive.
+ */
+
+
+#include "main/glheader.h"
+#include "main/bufferobj.h"
+#include "main/context.h"
+#include "main/dlist.h"
+#include "main/enums.h"
+#include "main/eval.h"
+#include "main/macros.h"
+#include "main/mfeatures.h"
+#include "main/api_noop.h"
+#include "main/api_validate.h"
+#include "main/api_arrayelt.h"
+#include "main/vtxfmt.h"
+#include "main/dispatch.h"
+
+#include "vbo_context.h"
+
+
+#if FEATURE_dlist
+
+
+#ifdef ERROR
+#undef ERROR
+#endif
+
+
+/* An interesting VBO number/name to help with debugging */
+#define VBO_BUF_ID 12345
+
+
+/*
+ * NOTE: Old 'parity' issue is gone, but copying can still be
+ * wrong-footed on replay.
+ */
+static GLuint _save_copy_vertices( struct gl_context *ctx,
+ const struct vbo_save_vertex_list *node,
+ const GLfloat *src_buffer)
+{
+ struct vbo_save_context *save = &vbo_context( ctx )->save;
+ const struct _mesa_prim *prim = &node->prim[node->prim_count-1];
+ GLuint nr = prim->count;
+ GLuint sz = save->vertex_size;
+ const GLfloat *src = src_buffer + prim->start * sz;
+ GLfloat *dst = save->copied.buffer;
+ GLuint ovf, i;
+
+ if (prim->end)
+ return 0;
+
+ switch( prim->mode )
+ {
+ case GL_POINTS:
+ return 0;
+ case GL_LINES:
+ ovf = nr&1;
+ for (i = 0 ; i < ovf ; i++)
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
+ return i;
+ case GL_TRIANGLES:
+ ovf = nr%3;
+ for (i = 0 ; i < ovf ; i++)
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
+ return i;
+ case GL_QUADS:
+ ovf = nr&3;
+ for (i = 0 ; i < ovf ; i++)
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
+ return i;
+ case GL_LINE_STRIP:
+ if (nr == 0)
+ return 0;
+ else {
+ memcpy( dst, src+(nr-1)*sz, sz*sizeof(GLfloat) );
+ return 1;
+ }
+ case GL_LINE_LOOP:
+ case GL_TRIANGLE_FAN:
+ case GL_POLYGON:
+ if (nr == 0)
+ return 0;
+ else if (nr == 1) {
+ memcpy( dst, src+0, sz*sizeof(GLfloat) );
+ return 1;
+ } else {
+ memcpy( dst, src+0, sz*sizeof(GLfloat) );
+ memcpy( dst+sz, src+(nr-1)*sz, sz*sizeof(GLfloat) );
+ return 2;
+ }
+ case GL_TRIANGLE_STRIP:
+ case GL_QUAD_STRIP:
+ switch (nr) {
+ case 0: ovf = 0; break;
+ case 1: ovf = 1; break;
+ default: ovf = 2 + (nr&1); break;
+ }
+ for (i = 0 ; i < ovf ; i++)
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
+ return i;
+ default:
+ assert(0);
+ return 0;
+ }
+}
+
+
+static struct vbo_save_vertex_store *alloc_vertex_store( struct gl_context *ctx )
+{
+ struct vbo_save_vertex_store *vertex_store = CALLOC_STRUCT(vbo_save_vertex_store);
+
+ /* obj->Name needs to be non-zero, but won't ever be examined more
+ * closely than that. In particular these buffers won't be entered
+ * into the hash and can never be confused with ones visible to the
+ * user. Perhaps there could be a special number for internal
+ * buffers:
+ */
+ vertex_store->bufferobj = ctx->Driver.NewBufferObject(ctx,
+ VBO_BUF_ID,
+ GL_ARRAY_BUFFER_ARB);
+
+ ctx->Driver.BufferData( ctx,
+ GL_ARRAY_BUFFER_ARB,
+ VBO_SAVE_BUFFER_SIZE * sizeof(GLfloat),
+ NULL,
+ GL_STATIC_DRAW_ARB,
+ vertex_store->bufferobj);
+
+ vertex_store->buffer = NULL;
+ vertex_store->used = 0;
+ vertex_store->refcount = 1;
+
+ return vertex_store;
+}
+
+static void free_vertex_store( struct gl_context *ctx, struct vbo_save_vertex_store *vertex_store )
+{
+ assert(!vertex_store->buffer);
+
+ if (vertex_store->bufferobj) {
+ _mesa_reference_buffer_object(ctx, &vertex_store->bufferobj, NULL);
+ }
+
+ FREE( vertex_store );
+}
+
+static GLfloat *map_vertex_store( struct gl_context *ctx, struct vbo_save_vertex_store *vertex_store )
+{
+ assert(vertex_store->bufferobj);
+ assert(!vertex_store->buffer);
+ vertex_store->buffer = (GLfloat *)ctx->Driver.MapBuffer(ctx,
+ GL_ARRAY_BUFFER_ARB, /* not used */
+ GL_WRITE_ONLY, /* not used */
+ vertex_store->bufferobj);
+
+ assert(vertex_store->buffer);
+ return vertex_store->buffer + vertex_store->used;
+}
+
+static void unmap_vertex_store( struct gl_context *ctx, struct vbo_save_vertex_store *vertex_store )
+{
+ ctx->Driver.UnmapBuffer( ctx, GL_ARRAY_BUFFER_ARB, vertex_store->bufferobj );
+ vertex_store->buffer = NULL;
+}
+
+
+static struct vbo_save_primitive_store *alloc_prim_store( struct gl_context *ctx )
+{
+ struct vbo_save_primitive_store *store = CALLOC_STRUCT(vbo_save_primitive_store);
+ (void) ctx;
+ store->used = 0;
+ store->refcount = 1;
+ return store;
+}
+
+static void _save_reset_counters( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+
+ save->prim = save->prim_store->buffer + save->prim_store->used;
+ save->buffer = (save->vertex_store->buffer +
+ save->vertex_store->used);
+
+ assert(save->buffer == save->buffer_ptr);
+
+ if (save->vertex_size)
+ save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
+ save->vertex_size);
+ else
+ save->max_vert = 0;
+
+ save->vert_count = 0;
+ save->prim_count = 0;
+ save->prim_max = VBO_SAVE_PRIM_SIZE - save->prim_store->used;
+ save->dangling_attr_ref = 0;
+}
+
+
+/* Insert the active immediate struct onto the display list currently
+ * being built.
+ */
+static void _save_compile_vertex_list( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ struct vbo_save_vertex_list *node;
+
+ /* Allocate space for this structure in the display list currently
+ * being compiled.
+ */
+ node = (struct vbo_save_vertex_list *)
+ _mesa_dlist_alloc(ctx, save->opcode_vertex_list, sizeof(*node));
+
+ if (!node)
+ return;
+
+ /* Duplicate our template, increment refcounts to the storage structs:
+ */
+ memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
+ node->vertex_size = save->vertex_size;
+ node->buffer_offset = (save->buffer - save->vertex_store->buffer) * sizeof(GLfloat);
+ node->count = save->vert_count;
+ node->wrap_count = save->copied.nr;
+ node->dangling_attr_ref = save->dangling_attr_ref;
+ node->prim = save->prim;
+ node->prim_count = save->prim_count;
+ node->vertex_store = save->vertex_store;
+ node->prim_store = save->prim_store;
+
+ node->vertex_store->refcount++;
+ node->prim_store->refcount++;
+
+ if (node->prim[0].no_current_update) {
+ node->current_size = 0;
+ node->current_data = NULL;
+ } else {
+ node->current_size = node->vertex_size - node->attrsz[0];
+ node->current_data = NULL;
+
+ if (node->current_size) {
+ /* If the malloc fails, we just pull the data out of the VBO
+ * later instead.
+ */
+ node->current_data = MALLOC( node->current_size * sizeof(GLfloat) );
+ if (node->current_data) {
+ const char *buffer = (const char *)save->vertex_store->buffer;
+ unsigned attr_offset = node->attrsz[0] * sizeof(GLfloat);
+ unsigned vertex_offset = 0;
+
+ if (node->count)
+ vertex_offset = (node->count-1) * node->vertex_size * sizeof(GLfloat);
+
+ memcpy( node->current_data,
+ buffer + node->buffer_offset + vertex_offset + attr_offset,
+ node->current_size * sizeof(GLfloat) );
+ }
+ }
+ }
+
+
+
+ assert(node->attrsz[VBO_ATTRIB_POS] != 0 ||
+ node->count == 0);
+
+ if (save->dangling_attr_ref)
+ ctx->ListState.CurrentList->Flags |= DLIST_DANGLING_REFS;
+
+ save->vertex_store->used += save->vertex_size * node->count;
+ save->prim_store->used += node->prim_count;
+
+
+ /* Copy duplicated vertices
+ */
+ save->copied.nr = _save_copy_vertices( ctx, node, save->buffer );
+
+
+ /* Deal with GL_COMPILE_AND_EXECUTE:
+ */
+ if (ctx->ExecuteFlag) {
+ struct _glapi_table *dispatch = GET_DISPATCH();
+
+ _glapi_set_dispatch(ctx->Exec);
+
+ vbo_loopback_vertex_list( ctx,
+ (const GLfloat *)((const char *)save->vertex_store->buffer +
+ node->buffer_offset),
+ node->attrsz,
+ node->prim,
+ node->prim_count,
+ node->wrap_count,
+ node->vertex_size);
+
+ _glapi_set_dispatch(dispatch);
+ }
+
+
+ /* Decide whether the storage structs are full, or can be used for
+ * the next vertex lists as well.
+ */
+ if (save->vertex_store->used >
+ VBO_SAVE_BUFFER_SIZE - 16 * (save->vertex_size + 4)) {
+
+ /* Unmap old store:
+ */
+ unmap_vertex_store( ctx, save->vertex_store );
+
+ /* Release old reference:
+ */
+ save->vertex_store->refcount--;
+ assert(save->vertex_store->refcount != 0);
+ save->vertex_store = NULL;
+
+ /* Allocate and map new store:
+ */
+ save->vertex_store = alloc_vertex_store( ctx );
+ save->buffer_ptr = map_vertex_store( ctx, save->vertex_store );
+ }
+
+ if (save->prim_store->used > VBO_SAVE_PRIM_SIZE - 6) {
+ save->prim_store->refcount--;
+ assert(save->prim_store->refcount != 0);
+ save->prim_store = alloc_prim_store( ctx );
+ }
+
+ /* Reset our structures for the next run of vertices:
+ */
+ _save_reset_counters( ctx );
+}
+
+
+/* TODO -- If no new vertices have been stored, don't bother saving
+ * it.
+ */
+static void _save_wrap_buffers( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ GLint i = save->prim_count - 1;
+ GLenum mode;
+ GLboolean weak;
+ GLboolean no_current_update;
+
+ assert(i < (GLint) save->prim_max);
+ assert(i >= 0);
+
+ /* Close off in-progress primitive.
+ */
+ save->prim[i].count = (save->vert_count -
+ save->prim[i].start);
+ mode = save->prim[i].mode;
+ weak = save->prim[i].weak;
+ no_current_update = save->prim[i].no_current_update;
+
+ /* store the copied vertices, and allocate a new list.
+ */
+ _save_compile_vertex_list( ctx );
+
+ /* Restart interrupted primitive
+ */
+ save->prim[0].mode = mode;
+ save->prim[0].weak = weak;
+ save->prim[0].no_current_update = no_current_update;
+ save->prim[0].begin = 0;
+ save->prim[0].end = 0;
+ save->prim[0].pad = 0;
+ save->prim[0].start = 0;
+ save->prim[0].count = 0;
+ save->prim[0].num_instances = 1;
+ save->prim_count = 1;
+}
+
+
+
+/* Called only when buffers are wrapped as the result of filling the
+ * vertex_store struct.
+ */
+static void _save_wrap_filled_vertex( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ GLfloat *data = save->copied.buffer;
+ GLuint i;
+
+ /* Emit a glEnd to close off the last vertex list.
+ */
+ _save_wrap_buffers( ctx );
+
+ /* Copy stored stored vertices to start of new list.
+ */
+ assert(save->max_vert - save->vert_count > save->copied.nr);
+
+ for (i = 0 ; i < save->copied.nr ; i++) {
+ memcpy( save->buffer_ptr, data, save->vertex_size * sizeof(GLfloat));
+ data += save->vertex_size;
+ save->buffer_ptr += save->vertex_size;
+ save->vert_count++;
+ }
+}
+
+
+static void _save_copy_to_current( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ GLuint i;
+
+ for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
+ if (save->attrsz[i]) {
+ save->currentsz[i][0] = save->attrsz[i];
+ COPY_CLEAN_4V(save->current[i],
+ save->attrsz[i],
+ save->attrptr[i]);
+ }
+ }
+}
+
+
+static void _save_copy_from_current( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ GLint i;
+
+ for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
+ switch (save->attrsz[i]) {
+ case 4: save->attrptr[i][3] = save->current[i][3];
+ case 3: save->attrptr[i][2] = save->current[i][2];
+ case 2: save->attrptr[i][1] = save->current[i][1];
+ case 1: save->attrptr[i][0] = save->current[i][0];
+ case 0: break;
+ }
+ }
+}
+
+
+
+
+/* Flush existing data, set new attrib size, replay copied vertices.
+ */
+static void _save_upgrade_vertex( struct gl_context *ctx,
+ GLuint attr,
+ GLuint newsz )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ GLuint oldsz;
+ GLuint i;
+ GLfloat *tmp;
+
+ /* Store the current run of vertices, and emit a GL_END. Emit a
+ * BEGIN in the new buffer.
+ */
+ if (save->vert_count)
+ _save_wrap_buffers( ctx );
+ else
+ assert( save->copied.nr == 0 );
+
+ /* Do a COPY_TO_CURRENT to ensure back-copying works for the case
+ * when the attribute already exists in the vertex and is having
+ * its size increased.
+ */
+ _save_copy_to_current( ctx );
+
+ /* Fix up sizes:
+ */
+ oldsz = save->attrsz[attr];
+ save->attrsz[attr] = newsz;
+
+ save->vertex_size += newsz - oldsz;
+ save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
+ save->vertex_size);
+ save->vert_count = 0;
+
+ /* Recalculate all the attrptr[] values:
+ */
+ for (i = 0, tmp = save->vertex ; i < VBO_ATTRIB_MAX ; i++) {
+ if (save->attrsz[i]) {
+ save->attrptr[i] = tmp;
+ tmp += save->attrsz[i];
+ }
+ else
+ save->attrptr[i] = NULL; /* will not be dereferenced. */
+ }
+
+ /* Copy from current to repopulate the vertex with correct values.
+ */
+ _save_copy_from_current( ctx );
+
+ /* Replay stored vertices to translate them to new format here.
+ *
+ * If there are copied vertices and the new (upgraded) attribute
+ * has not been defined before, this list is somewhat degenerate,
+ * and will need fixup at runtime.
+ */
+ if (save->copied.nr)
+ {
+ GLfloat *data = save->copied.buffer;
+ GLfloat *dest = save->buffer;
+ GLuint j;
+
+ /* Need to note this and fix up at runtime (or loopback):
+ */
+ if (attr != VBO_ATTRIB_POS && save->currentsz[attr][0] == 0) {
+ assert(oldsz == 0);
+ save->dangling_attr_ref = GL_TRUE;
+ }
+
+ for (i = 0 ; i < save->copied.nr ; i++) {
+ for (j = 0 ; j < VBO_ATTRIB_MAX ; j++) {
+ if (save->attrsz[j]) {
+ if (j == attr) {
+ if (oldsz) {
+ COPY_CLEAN_4V( dest, oldsz, data );
+ data += oldsz;
+ dest += newsz;
+ }
+ else {
+ COPY_SZ_4V( dest, newsz, save->current[attr] );
+ dest += newsz;
+ }
+ }
+ else {
+ GLint sz = save->attrsz[j];
+ COPY_SZ_4V( dest, sz, data );
+ data += sz;
+ dest += sz;
+ }
+ }
+ }
+ }
+
+ save->buffer_ptr = dest;
+ save->vert_count += save->copied.nr;
+ }
+}
+
+static void save_fixup_vertex( struct gl_context *ctx, GLuint attr, GLuint sz )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+
+ if (sz > save->attrsz[attr]) {
+ /* New size is larger. Need to flush existing vertices and get
+ * an enlarged vertex format.
+ */
+ _save_upgrade_vertex( ctx, attr, sz );
+ }
+ else if (sz < save->active_sz[attr]) {
+ static GLfloat id[4] = { 0, 0, 0, 1 };
+ GLuint i;
+
+ /* New size is equal or smaller - just need to fill in some
+ * zeros.
+ */
+ for (i = sz ; i <= save->attrsz[attr] ; i++)
+ save->attrptr[attr][i-1] = id[i-1];
+ }
+
+ save->active_sz[attr] = sz;
+}
+
+static void _save_reset_vertex( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ GLuint i;
+
+ for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) {
+ save->attrsz[i] = 0;
+ save->active_sz[i] = 0;
+ }
+
+ save->vertex_size = 0;
+}
+
+
+
+#define ERROR(err) _mesa_compile_error( ctx, GL_INVALID_ENUM, __FUNCTION__ );
+
+
+/* Only one size for each attribute may be active at once. Eg. if
+ * Color3f is installed/active, then Color4f may not be, even if the
+ * vertex actually contains 4 color coordinates. This is because the
+ * 3f version won't otherwise set color[3] to 1.0 -- this is the job
+ * of the chooser function when switching between Color4f and Color3f.
+ */
+#define ATTR( A, N, V0, V1, V2, V3 ) \
+do { \
+ struct vbo_save_context *save = &vbo_context(ctx)->save; \
+ \
+ if (save->active_sz[A] != N) \
+ save_fixup_vertex(ctx, A, N); \
+ \
+ { \
+ GLfloat *dest = save->attrptr[A]; \
+ if (N>0) dest[0] = V0; \
+ if (N>1) dest[1] = V1; \
+ if (N>2) dest[2] = V2; \
+ if (N>3) dest[3] = V3; \
+ } \
+ \
+ if ((A) == 0) { \
+ GLuint i; \
+ \
+ for (i = 0; i < save->vertex_size; i++) \
+ save->buffer_ptr[i] = save->vertex[i]; \
+ \
+ save->buffer_ptr += save->vertex_size; \
+ \
+ if (++save->vert_count >= save->max_vert) \
+ _save_wrap_filled_vertex( ctx ); \
+ } \
+} while (0)
+
+#define TAG(x) _save_##x
+
+#include "vbo_attrib_tmp.h"
+
+
+
+
+/* Cope with EvalCoord/CallList called within a begin/end object:
+ * -- Flush current buffer
+ * -- Fallback to opcodes for the rest of the begin/end object.
+ */
+static void DO_FALLBACK( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+
+ if (save->vert_count || save->prim_count) {
+ GLint i = save->prim_count - 1;
+
+ /* Close off in-progress primitive.
+ */
+ save->prim[i].count = (save->vert_count -
+ save->prim[i].start);
+
+ /* Need to replay this display list with loopback,
+ * unfortunately, otherwise this primitive won't be handled
+ * properly:
+ */
+ save->dangling_attr_ref = 1;
+
+ _save_compile_vertex_list( ctx );
+ }
+
+ _save_copy_to_current( ctx );
+ _save_reset_vertex( ctx );
+ _save_reset_counters( ctx );
+ _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
+ ctx->Driver.SaveNeedFlush = 0;
+}
+
+static void GLAPIENTRY _save_EvalCoord1f( GLfloat u )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ DO_FALLBACK(ctx);
+ CALL_EvalCoord1f(ctx->Save, (u));
+}
+
+static void GLAPIENTRY _save_EvalCoord1fv( const GLfloat *v )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ DO_FALLBACK(ctx);
+ CALL_EvalCoord1fv(ctx->Save, (v));
+}
+
+static void GLAPIENTRY _save_EvalCoord2f( GLfloat u, GLfloat v )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ DO_FALLBACK(ctx);
+ CALL_EvalCoord2f(ctx->Save, (u, v));
+}
+
+static void GLAPIENTRY _save_EvalCoord2fv( const GLfloat *v )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ DO_FALLBACK(ctx);
+ CALL_EvalCoord2fv(ctx->Save, (v));
+}
+
+static void GLAPIENTRY _save_EvalPoint1( GLint i )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ DO_FALLBACK(ctx);
+ CALL_EvalPoint1(ctx->Save, (i));
+}
+
+static void GLAPIENTRY _save_EvalPoint2( GLint i, GLint j )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ DO_FALLBACK(ctx);
+ CALL_EvalPoint2(ctx->Save, (i, j));
+}
+
+static void GLAPIENTRY _save_CallList( GLuint l )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ DO_FALLBACK(ctx);
+ CALL_CallList(ctx->Save, (l));
+}
+
+static void GLAPIENTRY _save_CallLists( GLsizei n, GLenum type, const GLvoid *v )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ DO_FALLBACK(ctx);
+ CALL_CallLists(ctx->Save, (n, type, v));
+}
+
+
+
+
+/* This begin is hooked into ... Updating of
+ * ctx->Driver.CurrentSavePrimitive is already taken care of.
+ */
+GLboolean vbo_save_NotifyBegin( struct gl_context *ctx, GLenum mode )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+
+ GLuint i = save->prim_count++;
+
+ assert(i < save->prim_max);
+ save->prim[i].mode = mode & VBO_SAVE_PRIM_MODE_MASK;
+ save->prim[i].begin = 1;
+ save->prim[i].end = 0;
+ save->prim[i].weak = (mode & VBO_SAVE_PRIM_WEAK) ? 1 : 0;
+ save->prim[i].no_current_update = (mode & VBO_SAVE_PRIM_NO_CURRENT_UPDATE) ? 1 : 0;
+ save->prim[i].pad = 0;
+ save->prim[i].start = save->vert_count;
+ save->prim[i].count = 0;
+ save->prim[i].num_instances = 1;
+
+ _mesa_install_save_vtxfmt( ctx, &save->vtxfmt );
+ ctx->Driver.SaveNeedFlush = 1;
+ return GL_TRUE;
+}
+
+
+
+static void GLAPIENTRY _save_End( void )
+{
+ GET_CURRENT_CONTEXT( ctx );
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ GLint i = save->prim_count - 1;
+
+ ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
+ save->prim[i].end = 1;
+ save->prim[i].count = (save->vert_count -
+ save->prim[i].start);
+
+ if (i == (GLint) save->prim_max - 1) {
+ _save_compile_vertex_list( ctx );
+ assert(save->copied.nr == 0);
+ }
+
+ /* Swap out this vertex format while outside begin/end. Any color,
+ * etc. received between here and the next begin will be compiled
+ * as opcodes.
+ */
+ _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
+}
+
+
+/* These are all errors as this vtxfmt is only installed inside
+ * begin/end pairs.
+ */
+static void GLAPIENTRY _save_DrawElements(GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) mode; (void) count; (void) type; (void) indices;
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawElements" );
+}
+
+
+static void GLAPIENTRY _save_DrawRangeElements(GLenum mode,
+ GLuint start, GLuint end,
+ GLsizei count, GLenum type,
+ const GLvoid *indices)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) mode; (void) start; (void) end; (void) count; (void) type; (void) indices;
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawRangeElements" );
+}
+
+static void GLAPIENTRY _save_DrawElementsBaseVertex(GLenum mode,
+ GLsizei count,
+ GLenum type,
+ const GLvoid *indices,
+ GLint basevertex)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) mode; (void) count; (void) type; (void) indices; (void)basevertex;
+
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawElements" );
+}
+
+static void GLAPIENTRY _save_DrawRangeElementsBaseVertex(GLenum mode,
+ GLuint start,
+ GLuint end,
+ GLsizei count,
+ GLenum type,
+ const GLvoid *indices,
+ GLint basevertex)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) mode; (void) start; (void) end; (void) count; (void) type;
+ (void) indices; (void)basevertex;
+
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawRangeElements" );
+}
+
+static void GLAPIENTRY _save_DrawArrays(GLenum mode, GLint start, GLsizei count)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) mode; (void) start; (void) count;
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawArrays" );
+}
+
+static void GLAPIENTRY _save_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) x1; (void) y1; (void) x2; (void) y2;
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glRectf" );
+}
+
+static void GLAPIENTRY _save_EvalMesh1( GLenum mode, GLint i1, GLint i2 )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) mode; (void) i1; (void) i2;
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glEvalMesh1" );
+}
+
+static void GLAPIENTRY _save_EvalMesh2( GLenum mode, GLint i1, GLint i2,
+ GLint j1, GLint j2 )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) mode; (void) i1; (void) i2; (void) j1; (void) j2;
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glEvalMesh2" );
+}
+
+static void GLAPIENTRY _save_Begin( GLenum mode )
+{
+ GET_CURRENT_CONTEXT( ctx );
+ (void) mode;
+ _mesa_compile_error( ctx, GL_INVALID_OPERATION, "Recursive glBegin" );
+}
+
+
+static void GLAPIENTRY _save_PrimitiveRestartNV( void )
+{
+ GLenum curPrim;
+ GET_CURRENT_CONTEXT( ctx );
+
+ curPrim = ctx->Driver.CurrentSavePrimitive;
+
+ _save_End();
+ _save_Begin(curPrim);
+}
+
+
+/* Unlike the functions above, these are to be hooked into the vtxfmt
+ * maintained in ctx->ListState, active when the list is known or
+ * suspected to be outside any begin/end primitive.
+ */
+static void GLAPIENTRY _save_OBE_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ vbo_save_NotifyBegin( ctx, GL_QUADS | VBO_SAVE_PRIM_WEAK );
+ CALL_Vertex2f(GET_DISPATCH(), ( x1, y1 ));
+ CALL_Vertex2f(GET_DISPATCH(), ( x2, y1 ));
+ CALL_Vertex2f(GET_DISPATCH(), ( x2, y2 ));
+ CALL_Vertex2f(GET_DISPATCH(), ( x1, y2 ));
+ CALL_End(GET_DISPATCH(), ());
+}
+
+
+static void GLAPIENTRY _save_OBE_DrawArrays(GLenum mode, GLint start, GLsizei count)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+
+ if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
+ return;
+
+ _ae_map_vbos( ctx );
+
+ vbo_save_NotifyBegin( ctx, mode | VBO_SAVE_PRIM_WEAK | VBO_SAVE_PRIM_NO_CURRENT_UPDATE);
+
+ for (i = 0; i < count; i++)
+ CALL_ArrayElement(GET_DISPATCH(), (start + i));
+ CALL_End(GET_DISPATCH(), ());
+
+ _ae_unmap_vbos( ctx );
+}
+
+/* Could do better by copying the arrays and element list intact and
+ * then emitting an indexed prim at runtime.
+ */
+static void GLAPIENTRY _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+
+ if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, 0 ))
+ return;
+
+ _ae_map_vbos( ctx );
+
+ if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj))
+ indices = ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Pointer, indices);
+
+ vbo_save_NotifyBegin( ctx, mode | VBO_SAVE_PRIM_WEAK | VBO_SAVE_PRIM_NO_CURRENT_UPDATE );
+
+ switch (type) {
+ case GL_UNSIGNED_BYTE:
+ for (i = 0 ; i < count ; i++)
+ CALL_ArrayElement(GET_DISPATCH(), ( ((GLubyte *)indices)[i] ));
+ break;
+ case GL_UNSIGNED_SHORT:
+ for (i = 0 ; i < count ; i++)
+ CALL_ArrayElement(GET_DISPATCH(), ( ((GLushort *)indices)[i] ));
+ break;
+ case GL_UNSIGNED_INT:
+ for (i = 0 ; i < count ; i++)
+ CALL_ArrayElement(GET_DISPATCH(), ( ((GLuint *)indices)[i] ));
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
+ break;
+ }
+
+ CALL_End(GET_DISPATCH(), ());
+
+ _ae_unmap_vbos( ctx );
+}
+
+static void GLAPIENTRY _save_OBE_DrawRangeElements(GLenum mode,
+ GLuint start, GLuint end,
+ GLsizei count, GLenum type,
+ const GLvoid *indices)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (_mesa_validate_DrawRangeElements( ctx, mode,
+ start, end,
+ count, type, indices, 0 ))
+ _save_OBE_DrawElements( mode, count, type, indices );
+}
+
+
+
+
+
+static void _save_vtxfmt_init( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ GLvertexformat *vfmt = &save->vtxfmt;
+
+ _MESA_INIT_ARRAYELT_VTXFMT(vfmt, _ae_);
+
+ vfmt->Begin = _save_Begin;
+ vfmt->Color3f = _save_Color3f;
+ vfmt->Color3fv = _save_Color3fv;
+ vfmt->Color4f = _save_Color4f;
+ vfmt->Color4fv = _save_Color4fv;
+ vfmt->EdgeFlag = _save_EdgeFlag;
+ vfmt->End = _save_End;
+ vfmt->PrimitiveRestartNV = _save_PrimitiveRestartNV;
+ vfmt->FogCoordfEXT = _save_FogCoordfEXT;
+ vfmt->FogCoordfvEXT = _save_FogCoordfvEXT;
+ vfmt->Indexf = _save_Indexf;
+ vfmt->Indexfv = _save_Indexfv;
+ vfmt->Materialfv = _save_Materialfv;
+ vfmt->MultiTexCoord1fARB = _save_MultiTexCoord1f;
+ vfmt->MultiTexCoord1fvARB = _save_MultiTexCoord1fv;
+ vfmt->MultiTexCoord2fARB = _save_MultiTexCoord2f;
+ vfmt->MultiTexCoord2fvARB = _save_MultiTexCoord2fv;
+ vfmt->MultiTexCoord3fARB = _save_MultiTexCoord3f;
+ vfmt->MultiTexCoord3fvARB = _save_MultiTexCoord3fv;
+ vfmt->MultiTexCoord4fARB = _save_MultiTexCoord4f;
+ vfmt->MultiTexCoord4fvARB = _save_MultiTexCoord4fv;
+ vfmt->Normal3f = _save_Normal3f;
+ vfmt->Normal3fv = _save_Normal3fv;
+ vfmt->SecondaryColor3fEXT = _save_SecondaryColor3fEXT;
+ vfmt->SecondaryColor3fvEXT = _save_SecondaryColor3fvEXT;
+ vfmt->TexCoord1f = _save_TexCoord1f;
+ vfmt->TexCoord1fv = _save_TexCoord1fv;
+ vfmt->TexCoord2f = _save_TexCoord2f;
+ vfmt->TexCoord2fv = _save_TexCoord2fv;
+ vfmt->TexCoord3f = _save_TexCoord3f;
+ vfmt->TexCoord3fv = _save_TexCoord3fv;
+ vfmt->TexCoord4f = _save_TexCoord4f;
+ vfmt->TexCoord4fv = _save_TexCoord4fv;
+ vfmt->Vertex2f = _save_Vertex2f;
+ vfmt->Vertex2fv = _save_Vertex2fv;
+ vfmt->Vertex3f = _save_Vertex3f;
+ vfmt->Vertex3fv = _save_Vertex3fv;
+ vfmt->Vertex4f = _save_Vertex4f;
+ vfmt->Vertex4fv = _save_Vertex4fv;
+ vfmt->VertexAttrib1fARB = _save_VertexAttrib1fARB;
+ vfmt->VertexAttrib1fvARB = _save_VertexAttrib1fvARB;
+ vfmt->VertexAttrib2fARB = _save_VertexAttrib2fARB;
+ vfmt->VertexAttrib2fvARB = _save_VertexAttrib2fvARB;
+ vfmt->VertexAttrib3fARB = _save_VertexAttrib3fARB;
+ vfmt->VertexAttrib3fvARB = _save_VertexAttrib3fvARB;
+ vfmt->VertexAttrib4fARB = _save_VertexAttrib4fARB;
+ vfmt->VertexAttrib4fvARB = _save_VertexAttrib4fvARB;
+
+ vfmt->VertexAttrib1fNV = _save_VertexAttrib1fNV;
+ vfmt->VertexAttrib1fvNV = _save_VertexAttrib1fvNV;
+ vfmt->VertexAttrib2fNV = _save_VertexAttrib2fNV;
+ vfmt->VertexAttrib2fvNV = _save_VertexAttrib2fvNV;
+ vfmt->VertexAttrib3fNV = _save_VertexAttrib3fNV;
+ vfmt->VertexAttrib3fvNV = _save_VertexAttrib3fvNV;
+ vfmt->VertexAttrib4fNV = _save_VertexAttrib4fNV;
+ vfmt->VertexAttrib4fvNV = _save_VertexAttrib4fvNV;
+
+ /* integer-valued */
+ vfmt->VertexAttribI1i = _save_VertexAttribI1i;
+ vfmt->VertexAttribI2i = _save_VertexAttribI2i;
+ vfmt->VertexAttribI3i = _save_VertexAttribI3i;
+ vfmt->VertexAttribI4i = _save_VertexAttribI4i;
+ vfmt->VertexAttribI2iv = _save_VertexAttribI2iv;
+ vfmt->VertexAttribI3iv = _save_VertexAttribI3iv;
+ vfmt->VertexAttribI4iv = _save_VertexAttribI4iv;
+
+ /* unsigned integer-valued */
+ vfmt->VertexAttribI1ui = _save_VertexAttribI1ui;
+ vfmt->VertexAttribI2ui = _save_VertexAttribI2ui;
+ vfmt->VertexAttribI3ui = _save_VertexAttribI3ui;
+ vfmt->VertexAttribI4ui = _save_VertexAttribI4ui;
+ vfmt->VertexAttribI2uiv = _save_VertexAttribI2uiv;
+ vfmt->VertexAttribI3uiv = _save_VertexAttribI3uiv;
+ vfmt->VertexAttribI4uiv = _save_VertexAttribI4uiv;
+
+ /* This will all require us to fallback to saving the list as opcodes:
+ */
+ _MESA_INIT_DLIST_VTXFMT(vfmt, _save_); /* inside begin/end */
+
+ _MESA_INIT_EVAL_VTXFMT(vfmt, _save_);
+
+ /* These are all errors as we at least know we are in some sort of
+ * begin/end pair:
+ */
+ vfmt->Begin = _save_Begin;
+ vfmt->Rectf = _save_Rectf;
+ vfmt->DrawArrays = _save_DrawArrays;
+ vfmt->DrawElements = _save_DrawElements;
+ vfmt->DrawRangeElements = _save_DrawRangeElements;
+ vfmt->DrawElementsBaseVertex = _save_DrawElementsBaseVertex;
+ vfmt->DrawRangeElementsBaseVertex = _save_DrawRangeElementsBaseVertex;
+ /* Loops back into vfmt->DrawElements */
+ vfmt->MultiDrawElementsEXT = _mesa_noop_MultiDrawElements;
+ vfmt->MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex;
+}
+
+
+void vbo_save_SaveFlushVertices( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+
+ /* Noop when we are actually active:
+ */
+ if (ctx->Driver.CurrentSavePrimitive == PRIM_INSIDE_UNKNOWN_PRIM ||
+ ctx->Driver.CurrentSavePrimitive <= GL_POLYGON)
+ return;
+
+ if (save->vert_count ||
+ save->prim_count)
+ _save_compile_vertex_list( ctx );
+
+ _save_copy_to_current( ctx );
+ _save_reset_vertex( ctx );
+ _save_reset_counters( ctx );
+ ctx->Driver.SaveNeedFlush = 0;
+}
+
+void vbo_save_NewList( struct gl_context *ctx, GLuint list, GLenum mode )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+
+ (void) list; (void) mode;
+
+ if (!save->prim_store)
+ save->prim_store = alloc_prim_store( ctx );
+
+ if (!save->vertex_store)
+ save->vertex_store = alloc_vertex_store( ctx );
+
+ save->buffer_ptr = map_vertex_store( ctx, save->vertex_store );
+
+ _save_reset_vertex( ctx );
+ _save_reset_counters( ctx );
+ ctx->Driver.SaveNeedFlush = 0;
+}
+
+void vbo_save_EndList( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+
+ /* EndList called inside a (saved) Begin/End pair?
+ */
+ if (ctx->Driver.CurrentSavePrimitive != PRIM_OUTSIDE_BEGIN_END) {
+
+ if (save->prim_count > 0) {
+ GLint i = save->prim_count - 1;
+ ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
+ save->prim[i].end = 0;
+ save->prim[i].count = (save->vert_count -
+ save->prim[i].start);
+ }
+
+ /* Make sure this vertex list gets replayed by the "loopback"
+ * mechanism:
+ */
+ save->dangling_attr_ref = 1;
+ vbo_save_SaveFlushVertices( ctx );
+
+ /* Swap out this vertex format while outside begin/end. Any color,
+ * etc. received between here and the next begin will be compiled
+ * as opcodes.
+ */
+ _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
+ }
+
+ unmap_vertex_store( ctx, save->vertex_store );
+
+ assert(save->vertex_size == 0);
+}
+
+void vbo_save_BeginCallList( struct gl_context *ctx, struct gl_display_list *dlist )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ save->replay_flags |= dlist->Flags;
+}
+
+void vbo_save_EndCallList( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+
+ if (ctx->ListState.CallDepth == 1) {
+ /* This is correct: want to keep only the VBO_SAVE_FALLBACK
+ * flag, if it is set:
+ */
+ save->replay_flags &= VBO_SAVE_FALLBACK;
+ }
+}
+
+
+static void vbo_destroy_vertex_list( struct gl_context *ctx, void *data )
+{
+ struct vbo_save_vertex_list *node = (struct vbo_save_vertex_list *)data;
+ (void) ctx;
+
+ if ( --node->vertex_store->refcount == 0 )
+ free_vertex_store( ctx, node->vertex_store );
+
+ if ( --node->prim_store->refcount == 0 )
+ FREE( node->prim_store );
+
+ if (node->current_data) {
+ FREE(node->current_data);
+ node->current_data = NULL;
+ }
+}
+
+
+static void vbo_print_vertex_list( struct gl_context *ctx, void *data )
+{
+ struct vbo_save_vertex_list *node = (struct vbo_save_vertex_list *)data;
+ GLuint i;
+ (void) ctx;
+
+ printf("VBO-VERTEX-LIST, %u vertices %d primitives, %d vertsize\n",
+ node->count,
+ node->prim_count,
+ node->vertex_size);
+
+ for (i = 0 ; i < node->prim_count ; i++) {
+ struct _mesa_prim *prim = &node->prim[i];
+ _mesa_debug(NULL, " prim %d: %s%s %d..%d %s %s\n",
+ i,
+ _mesa_lookup_prim_by_nr(prim->mode),
+ prim->weak ? " (weak)" : "",
+ prim->start,
+ prim->start + prim->count,
+ (prim->begin) ? "BEGIN" : "(wrap)",
+ (prim->end) ? "END" : "(wrap)");
+ }
+}
+
+
+static void _save_current_init( struct gl_context *ctx )
+{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+ GLint i;
+
+ for (i = VBO_ATTRIB_POS; i <= VBO_ATTRIB_GENERIC15; i++) {
+ const GLuint j = i - VBO_ATTRIB_POS;
+ ASSERT(j < VERT_ATTRIB_MAX);
+ save->currentsz[i] = &ctx->ListState.ActiveAttribSize[j];
+ save->current[i] = ctx->ListState.CurrentAttrib[j];
+ }
+
+ for (i = VBO_ATTRIB_FIRST_MATERIAL; i <= VBO_ATTRIB_LAST_MATERIAL; i++) {
+ const GLuint j = i - VBO_ATTRIB_FIRST_MATERIAL;
+ ASSERT(j < MAT_ATTRIB_MAX);
+ save->currentsz[i] = &ctx->ListState.ActiveMaterialSize[j];
+ save->current[i] = ctx->ListState.CurrentMaterial[j];
+ }
+}
+
+/**
+ * Initialize the display list compiler
+ */
+void vbo_save_api_init( struct vbo_save_context *save )
+{
+ struct gl_context *ctx = save->ctx;
+ GLuint i;
+
+ save->opcode_vertex_list =
+ _mesa_dlist_alloc_opcode( ctx,
+ sizeof(struct vbo_save_vertex_list),
+ vbo_save_playback_vertex_list,
+ vbo_destroy_vertex_list,
+ vbo_print_vertex_list );
+
+ ctx->Driver.NotifySaveBegin = vbo_save_NotifyBegin;
+
+ _save_vtxfmt_init( ctx );
+ _save_current_init( ctx );
+
+ /* These will actually get set again when binding/drawing */
+ for (i = 0; i < VBO_ATTRIB_MAX; i++)
+ save->inputs[i] = &save->arrays[i];
+
+ /* Hook our array functions into the outside-begin-end vtxfmt in
+ * ctx->ListState.
+ */
+ ctx->ListState.ListVtxfmt.Rectf = _save_OBE_Rectf;
+ ctx->ListState.ListVtxfmt.DrawArrays = _save_OBE_DrawArrays;
+ ctx->ListState.ListVtxfmt.DrawElements = _save_OBE_DrawElements;
+ ctx->ListState.ListVtxfmt.DrawRangeElements = _save_OBE_DrawRangeElements;
+ /* loops back into _save_OBE_DrawElements */
+ ctx->ListState.ListVtxfmt.MultiDrawElementsEXT = _mesa_noop_MultiDrawElements;
+ ctx->ListState.ListVtxfmt.MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex;
+ _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
+}
+
+
+#endif /* FEATURE_dlist */
diff --git a/mesalib/src/mesa/vbo/vbo_save_draw.c b/mesalib/src/mesa/vbo/vbo_save_draw.c
index 634a6d3f8..5a19b0d62 100644
--- a/mesalib/src/mesa/vbo/vbo_save_draw.c
+++ b/mesalib/src/mesa/vbo/vbo_save_draw.c
@@ -1,305 +1,305 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.2
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/* Author:
- * Keith Whitwell <keith@tungstengraphics.com>
- */
-
-#include "main/glheader.h"
-#include "main/bufferobj.h"
-#include "main/context.h"
-#include "main/imports.h"
-#include "main/mfeatures.h"
-#include "main/mtypes.h"
-#include "main/macros.h"
-#include "main/light.h"
-#include "main/state.h"
-
-#include "vbo_context.h"
-
-
-#if FEATURE_dlist
-
-
-/**
- * After playback, copy everything but the position from the
- * last vertex to the saved state
- */
-static void
-_playback_copy_to_current(struct gl_context *ctx,
- const struct vbo_save_vertex_list *node)
-{
- struct vbo_context *vbo = vbo_context(ctx);
- GLfloat vertex[VBO_ATTRIB_MAX * 4];
- GLfloat *data;
- GLuint i, offset;
-
- if (node->current_size == 0)
- return;
-
- if (node->current_data) {
- data = node->current_data;
- }
- else {
- data = vertex;
-
- if (node->count)
- offset = (node->buffer_offset +
- (node->count-1) * node->vertex_size * sizeof(GLfloat));
- else
- offset = node->buffer_offset;
-
- ctx->Driver.GetBufferSubData( ctx, 0, offset,
- node->vertex_size * sizeof(GLfloat),
- data, node->vertex_store->bufferobj );
-
- data += node->attrsz[0]; /* skip vertex position */
- }
-
- for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
- if (node->attrsz[i]) {
- GLfloat *current = (GLfloat *)vbo->currval[i].Ptr;
- GLfloat tmp[4];
-
- COPY_CLEAN_4V(tmp,
- node->attrsz[i],
- data);
-
- if (memcmp(current, tmp, 4 * sizeof(GLfloat)) != 0) {
- memcpy(current, tmp, 4 * sizeof(GLfloat));
-
- vbo->currval[i].Size = node->attrsz[i];
-
- if (i >= VBO_ATTRIB_FIRST_MATERIAL &&
- i <= VBO_ATTRIB_LAST_MATERIAL)
- ctx->NewState |= _NEW_LIGHT;
-
- ctx->NewState |= _NEW_CURRENT_ATTRIB;
- }
-
- data += node->attrsz[i];
- }
- }
-
- /* Colormaterial -- this kindof sucks.
- */
- if (ctx->Light.ColorMaterialEnabled) {
- _mesa_update_color_material(ctx, ctx->Current.Attrib[VBO_ATTRIB_COLOR0]);
- }
-
- /* CurrentExecPrimitive
- */
- if (node->prim_count) {
- const struct _mesa_prim *prim = &node->prim[node->prim_count - 1];
- if (prim->end)
- ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
- else
- ctx->Driver.CurrentExecPrimitive = prim->mode;
- }
-}
-
-
-
-/**
- * Treat the vertex storage as a VBO, define vertex arrays pointing
- * into it:
- */
-static void vbo_bind_vertex_list(struct gl_context *ctx,
- const struct vbo_save_vertex_list *node)
-{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_save_context *save = &vbo->save;
- struct gl_client_array *arrays = save->arrays;
- GLuint buffer_offset = node->buffer_offset;
- const GLuint *map;
- GLuint attr;
- GLubyte node_attrsz[VBO_ATTRIB_MAX]; /* copy of node->attrsz[] */
- GLbitfield varying_inputs = 0x0;
-
- memcpy(node_attrsz, node->attrsz, sizeof(node->attrsz));
-
- /* Install the default (ie Current) attributes first, then overlay
- * all active ones.
- */
- switch (get_program_mode(ctx)) {
- case VP_NONE:
- for (attr = 0; attr < 16; attr++) {
- save->inputs[attr] = &vbo->legacy_currval[attr];
- }
- for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) {
- save->inputs[attr + 16] = &vbo->mat_currval[attr];
- }
- map = vbo->map_vp_none;
- break;
- case VP_NV:
- case VP_ARB:
- /* The aliasing of attributes for NV vertex programs has already
- * occurred. NV vertex programs cannot access material values,
- * nor attributes greater than VERT_ATTRIB_TEX7.
- */
- for (attr = 0; attr < 16; attr++) {
- save->inputs[attr] = &vbo->legacy_currval[attr];
- save->inputs[attr + 16] = &vbo->generic_currval[attr];
- }
- map = vbo->map_vp_arb;
-
- /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read.
- * In that case we effectively need to route the data from
- * glVertexAttrib(0, val) calls to feed into the GENERIC0 input.
- */
- if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 &&
- (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) {
- save->inputs[16] = save->inputs[0];
- node_attrsz[16] = node_attrsz[0];
- node_attrsz[0] = 0;
- }
- break;
- default:
- assert(0);
- }
-
- for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
- const GLuint src = map[attr];
-
- if (node_attrsz[src]) {
- /* override the default array set above */
- save->inputs[attr] = &arrays[attr];
-
- arrays[attr].Ptr = (const GLubyte *) NULL + buffer_offset;
- arrays[attr].Size = node->attrsz[src];
- arrays[attr].StrideB = node->vertex_size * sizeof(GLfloat);
- arrays[attr].Stride = node->vertex_size * sizeof(GLfloat);
- arrays[attr].Type = GL_FLOAT;
- arrays[attr].Format = GL_RGBA;
- arrays[attr].Enabled = 1;
- _mesa_reference_buffer_object(ctx,
- &arrays[attr].BufferObj,
- node->vertex_store->bufferobj);
- arrays[attr]._MaxElement = node->count; /* ??? */
-
- assert(arrays[attr].BufferObj->Name);
-
- buffer_offset += node->attrsz[src] * sizeof(GLfloat);
- varying_inputs |= 1<<attr;
- ctx->NewState |= _NEW_ARRAY;
- }
- }
-
- _mesa_set_varying_vp_inputs( ctx, varying_inputs );
-}
-
-
-static void
-vbo_save_loopback_vertex_list(struct gl_context *ctx,
- const struct vbo_save_vertex_list *list)
-{
- const char *buffer = ctx->Driver.MapBuffer(ctx,
- GL_ARRAY_BUFFER_ARB,
- GL_READ_ONLY, /* ? */
- list->vertex_store->bufferobj);
-
- vbo_loopback_vertex_list(ctx,
- (const GLfloat *)(buffer + list->buffer_offset),
- list->attrsz,
- list->prim,
- list->prim_count,
- list->wrap_count,
- list->vertex_size);
-
- ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB,
- list->vertex_store->bufferobj);
-}
-
-
-/**
- * Execute the buffer and save copied verts.
- * This is called from the display list code when executing
- * a drawing command.
- */
-void
-vbo_save_playback_vertex_list(struct gl_context *ctx, void *data)
-{
- const struct vbo_save_vertex_list *node =
- (const struct vbo_save_vertex_list *) data;
- struct vbo_save_context *save = &vbo_context(ctx)->save;
-
- FLUSH_CURRENT(ctx, 0);
-
- if (node->prim_count > 0 && node->count > 0) {
-
- if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END &&
- node->prim[0].begin) {
-
- /* Degenerate case: list is called inside begin/end pair and
- * includes operations such as glBegin or glDrawArrays.
- */
- if (0)
- printf("displaylist recursive begin");
-
- vbo_save_loopback_vertex_list( ctx, node );
- return;
- }
- else if (save->replay_flags) {
- /* Various degnerate cases: translate into immediate mode
- * calls rather than trying to execute in place.
- */
- vbo_save_loopback_vertex_list( ctx, node );
- return;
- }
-
- if (ctx->NewState)
- _mesa_update_state( ctx );
-
- /* XXX also need to check if shader enabled, but invalid */
- if ((ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) ||
- (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBegin (invalid vertex/fragment program)");
- return;
- }
-
- vbo_bind_vertex_list( ctx, node );
-
- /* Again...
- */
- if (ctx->NewState)
- _mesa_update_state( ctx );
-
- vbo_context(ctx)->draw_prims(ctx,
- save->inputs,
- node->prim,
- node->prim_count,
- NULL,
- GL_TRUE,
- 0, /* Node is a VBO, so this is ok */
- node->count - 1);
- }
-
- /* Copy to current?
- */
- _playback_copy_to_current( ctx, node );
-}
-
-
-#endif /* FEATURE_dlist */
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.2
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/* Author:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "main/glheader.h"
+#include "main/bufferobj.h"
+#include "main/context.h"
+#include "main/imports.h"
+#include "main/mfeatures.h"
+#include "main/mtypes.h"
+#include "main/macros.h"
+#include "main/light.h"
+#include "main/state.h"
+
+#include "vbo_context.h"
+
+
+#if FEATURE_dlist
+
+
+/**
+ * After playback, copy everything but the position from the
+ * last vertex to the saved state
+ */
+static void
+_playback_copy_to_current(struct gl_context *ctx,
+ const struct vbo_save_vertex_list *node)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ GLfloat vertex[VBO_ATTRIB_MAX * 4];
+ GLfloat *data;
+ GLuint i, offset;
+
+ if (node->current_size == 0)
+ return;
+
+ if (node->current_data) {
+ data = node->current_data;
+ }
+ else {
+ data = vertex;
+
+ if (node->count)
+ offset = (node->buffer_offset +
+ (node->count-1) * node->vertex_size * sizeof(GLfloat));
+ else
+ offset = node->buffer_offset;
+
+ ctx->Driver.GetBufferSubData( ctx, 0, offset,
+ node->vertex_size * sizeof(GLfloat),
+ data, node->vertex_store->bufferobj );
+
+ data += node->attrsz[0]; /* skip vertex position */
+ }
+
+ for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
+ if (node->attrsz[i]) {
+ GLfloat *current = (GLfloat *)vbo->currval[i].Ptr;
+ GLfloat tmp[4];
+
+ COPY_CLEAN_4V(tmp,
+ node->attrsz[i],
+ data);
+
+ if (memcmp(current, tmp, 4 * sizeof(GLfloat)) != 0) {
+ memcpy(current, tmp, 4 * sizeof(GLfloat));
+
+ vbo->currval[i].Size = node->attrsz[i];
+
+ if (i >= VBO_ATTRIB_FIRST_MATERIAL &&
+ i <= VBO_ATTRIB_LAST_MATERIAL)
+ ctx->NewState |= _NEW_LIGHT;
+
+ ctx->NewState |= _NEW_CURRENT_ATTRIB;
+ }
+
+ data += node->attrsz[i];
+ }
+ }
+
+ /* Colormaterial -- this kindof sucks.
+ */
+ if (ctx->Light.ColorMaterialEnabled) {
+ _mesa_update_color_material(ctx, ctx->Current.Attrib[VBO_ATTRIB_COLOR0]);
+ }
+
+ /* CurrentExecPrimitive
+ */
+ if (node->prim_count) {
+ const struct _mesa_prim *prim = &node->prim[node->prim_count - 1];
+ if (prim->end)
+ ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
+ else
+ ctx->Driver.CurrentExecPrimitive = prim->mode;
+ }
+}
+
+
+
+/**
+ * Treat the vertex storage as a VBO, define vertex arrays pointing
+ * into it:
+ */
+static void vbo_bind_vertex_list(struct gl_context *ctx,
+ const struct vbo_save_vertex_list *node)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_save_context *save = &vbo->save;
+ struct gl_client_array *arrays = save->arrays;
+ GLuint buffer_offset = node->buffer_offset;
+ const GLuint *map;
+ GLuint attr;
+ GLubyte node_attrsz[VBO_ATTRIB_MAX]; /* copy of node->attrsz[] */
+ GLbitfield varying_inputs = 0x0;
+
+ memcpy(node_attrsz, node->attrsz, sizeof(node->attrsz));
+
+ /* Install the default (ie Current) attributes first, then overlay
+ * all active ones.
+ */
+ switch (get_program_mode(ctx)) {
+ case VP_NONE:
+ for (attr = 0; attr < 16; attr++) {
+ save->inputs[attr] = &vbo->legacy_currval[attr];
+ }
+ for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) {
+ save->inputs[attr + 16] = &vbo->mat_currval[attr];
+ }
+ map = vbo->map_vp_none;
+ break;
+ case VP_NV:
+ case VP_ARB:
+ /* The aliasing of attributes for NV vertex programs has already
+ * occurred. NV vertex programs cannot access material values,
+ * nor attributes greater than VERT_ATTRIB_TEX7.
+ */
+ for (attr = 0; attr < 16; attr++) {
+ save->inputs[attr] = &vbo->legacy_currval[attr];
+ save->inputs[attr + 16] = &vbo->generic_currval[attr];
+ }
+ map = vbo->map_vp_arb;
+
+ /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read.
+ * In that case we effectively need to route the data from
+ * glVertexAttrib(0, val) calls to feed into the GENERIC0 input.
+ */
+ if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 &&
+ (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) {
+ save->inputs[16] = save->inputs[0];
+ node_attrsz[16] = node_attrsz[0];
+ node_attrsz[0] = 0;
+ }
+ break;
+ default:
+ assert(0);
+ }
+
+ for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
+ const GLuint src = map[attr];
+
+ if (node_attrsz[src]) {
+ /* override the default array set above */
+ save->inputs[attr] = &arrays[attr];
+
+ arrays[attr].Ptr = (const GLubyte *) NULL + buffer_offset;
+ arrays[attr].Size = node->attrsz[src];
+ arrays[attr].StrideB = node->vertex_size * sizeof(GLfloat);
+ arrays[attr].Stride = node->vertex_size * sizeof(GLfloat);
+ arrays[attr].Type = GL_FLOAT;
+ arrays[attr].Format = GL_RGBA;
+ arrays[attr].Enabled = 1;
+ _mesa_reference_buffer_object(ctx,
+ &arrays[attr].BufferObj,
+ node->vertex_store->bufferobj);
+ arrays[attr]._MaxElement = node->count; /* ??? */
+
+ assert(arrays[attr].BufferObj->Name);
+
+ buffer_offset += node->attrsz[src] * sizeof(GLfloat);
+ varying_inputs |= 1<<attr;
+ ctx->NewState |= _NEW_ARRAY;
+ }
+ }
+
+ _mesa_set_varying_vp_inputs( ctx, varying_inputs );
+}
+
+
+static void
+vbo_save_loopback_vertex_list(struct gl_context *ctx,
+ const struct vbo_save_vertex_list *list)
+{
+ const char *buffer = ctx->Driver.MapBuffer(ctx,
+ GL_ARRAY_BUFFER_ARB,
+ GL_READ_ONLY, /* ? */
+ list->vertex_store->bufferobj);
+
+ vbo_loopback_vertex_list(ctx,
+ (const GLfloat *)(buffer + list->buffer_offset),
+ list->attrsz,
+ list->prim,
+ list->prim_count,
+ list->wrap_count,
+ list->vertex_size);
+
+ ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB,
+ list->vertex_store->bufferobj);
+}
+
+
+/**
+ * Execute the buffer and save copied verts.
+ * This is called from the display list code when executing
+ * a drawing command.
+ */
+void
+vbo_save_playback_vertex_list(struct gl_context *ctx, void *data)
+{
+ const struct vbo_save_vertex_list *node =
+ (const struct vbo_save_vertex_list *) data;
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+
+ FLUSH_CURRENT(ctx, 0);
+
+ if (node->prim_count > 0 && node->count > 0) {
+
+ if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END &&
+ node->prim[0].begin) {
+
+ /* Degenerate case: list is called inside begin/end pair and
+ * includes operations such as glBegin or glDrawArrays.
+ */
+ if (0)
+ printf("displaylist recursive begin");
+
+ vbo_save_loopback_vertex_list( ctx, node );
+ return;
+ }
+ else if (save->replay_flags) {
+ /* Various degnerate cases: translate into immediate mode
+ * calls rather than trying to execute in place.
+ */
+ vbo_save_loopback_vertex_list( ctx, node );
+ return;
+ }
+
+ if (ctx->NewState)
+ _mesa_update_state( ctx );
+
+ /* XXX also need to check if shader enabled, but invalid */
+ if ((ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) ||
+ (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBegin (invalid vertex/fragment program)");
+ return;
+ }
+
+ vbo_bind_vertex_list( ctx, node );
+
+ /* Again...
+ */
+ if (ctx->NewState)
+ _mesa_update_state( ctx );
+
+ vbo_context(ctx)->draw_prims(ctx,
+ save->inputs,
+ node->prim,
+ node->prim_count,
+ NULL,
+ GL_TRUE,
+ 0, /* Node is a VBO, so this is ok */
+ node->count - 1);
+ }
+
+ /* Copy to current?
+ */
+ _playback_copy_to_current( ctx, node );
+}
+
+
+#endif /* FEATURE_dlist */
diff --git a/mesalib/windows/VC8/mesa/gdi/gdi.vcproj b/mesalib/windows/VC8/mesa/gdi/gdi.vcproj
deleted file mode 100644
index 220923f90..000000000
--- a/mesalib/windows/VC8/mesa/gdi/gdi.vcproj
+++ /dev/null
@@ -1,445 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="8.00"
- Name="gdi"
- ProjectGUID="{A1B24907-E196-4826-B6AF-26723629B633}"
- RootNamespace="gdi"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="2"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="_DEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName=".\Debug/gdi.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="../../../../include,../../../../src/mesa,../../../../src/mesa/main,../../../../src/mesa/glapi,../../../../src/mesa/swrast,../../../../src/mesa/shader"
- PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;_USRDLL;GDI_EXPORTS;_DLL;BUILD_GL32;MESA_MINWARN"
- BasicRuntimeChecks="3"
- RuntimeLibrary="3"
- BrowseInformation="1"
- WarningLevel="3"
- SuppressStartupBanner="true"
- DebugInformationFormat="3"
- CompileAs="0"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="gdi32.lib user32.lib"
- OutputFile="$(OutDir)\OPENGL32.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\mesa\drivers\windows\gdi\mesa.def"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(TargetDir)OPENGL32.pdb"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OPENGL32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OPENGL32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)OPENGL32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="2"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName=".\Release/gdi.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="../../main,../../../../include,../../../../src/mesa,../../../../src/mesa/main,../../../../src/mesa/glapi,../../../../src/mesa/swrast,../../../../src/mesa/shader"
- PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;_USRDLL;GDI_EXPORTS;_DLL;BUILD_GL32;MESA_MINWARN"
- StringPooling="true"
- RuntimeLibrary="2"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile=".\Release/gdi.pch"
- WarningLevel="3"
- SuppressStartupBanner="true"
- CompileAs="0"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="gdi32.lib user32.lib"
- OutputFile="$(OutDir)\OPENGL32.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\mesa\drivers\windows\gdi\mesa.def"
- ProgramDatabaseFile="$(TargetDir)OPENGL32.pdb"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OPENGL32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OPENGL32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)OPENGL32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
- />
- </Configuration>
- <Configuration
- Name="Debug Static CRT|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="2"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="_DEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName=".\Debug/gdi.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="../../../../include,../../../../src/mesa,../../../../src/mesa/main,../../../../src/mesa/glapi,../../../../src/mesa/swrast,../../../../src/mesa/shader"
- PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;_USRDLL;GDI_EXPORTS;BUILD_GL32;MESA_MINWARN"
- BasicRuntimeChecks="3"
- RuntimeLibrary="1"
- BrowseInformation="1"
- WarningLevel="3"
- SuppressStartupBanner="true"
- DebugInformationFormat="3"
- CompileAs="0"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="gdi32.lib user32.lib"
- OutputFile="$(OutDir)\OPENGL32.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\mesa\drivers\windows\gdi\mesa.def"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(TargetDir)OPENGL32.pdb"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OPENGL32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OPENGL32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)OPENGL32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
- />
- </Configuration>
- <Configuration
- Name="Release Static CRT|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="2"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName=".\Release/gdi.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="../../main,../../../../include,../../../../src/mesa,../../../../src/mesa/main,../../../../src/mesa/glapi,../../../../src/mesa/swrast,../../../../src/mesa/shader"
- PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;_USRDLL;GDI_EXPORTS;BUILD_GL32;MESA_MINWARN"
- StringPooling="true"
- RuntimeLibrary="0"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile=".\Release/gdi.pch"
- WarningLevel="3"
- SuppressStartupBanner="true"
- CompileAs="0"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="gdi32.lib user32.lib"
- OutputFile="$(OutDir)\OPENGL32.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\mesa\drivers\windows\gdi\mesa.def"
- ProgramDatabaseFile="$(TargetDir)OPENGL32.pdb"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OPENGL32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OPENGL32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)OPENGL32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
- >
- <File
- RelativePath="..\..\..\..\src\mesa\drivers\common\driverfuncs.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\mesa\drivers\windows\gdi\mesa.def"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\mesa\drivers\common\meta.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\mesa\drivers\windows\gdi\wgl.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\mesa\drivers\windows\gdi\wmesa.c"
- >
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl"
- >
- <File
- RelativePath="..\..\..\..\src\mesa\drivers\windows\gdi\colors.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\mesa\drivers\common\driverfuncs.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\mesa\drivers\common\meta.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\include\GL\wmesa.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\mesa\drivers\windows\gdi\wmesadef.h"
- >
- </File>
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
- >
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcproj b/mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcproj
index 6e9aef2e1..3fed6b466 100644
--- a/mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcproj
+++ b/mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcproj
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="8.00"
+ Version="9,00"
Name="glsl_apps_compile"
ProjectGUID="{98AB3D51-1820-4D14-9195-75FCA6997784}"
RootNamespace="glsl_apps_compile"
Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
@@ -64,6 +65,8 @@
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
@@ -85,9 +88,6 @@
Name="VCAppVerifierTool"
/>
<Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
Name="VCPostBuildEventTool"
CommandLine="copy &quot;$(OutDir)\compile.exe&quot; ..\..\..\..\src\glsl\apps"
/>
@@ -141,6 +141,8 @@
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
@@ -162,9 +164,6 @@
Name="VCAppVerifierTool"
/>
<Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
Name="VCPostBuildEventTool"
CommandLine="copy &quot;$(OutDir)\compile.exe&quot; ..\..\..\..\src\glsl\apps"
/>
diff --git a/mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcxproj b/mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcxproj
new file mode 100644
index 000000000..ab9cbd982
--- /dev/null
+++ b/mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcxproj
@@ -0,0 +1,187 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{98AB3D51-1820-4D14-9195-75FCA6997784}</ProjectGuid>
+ <RootNamespace>glsl_apps_compile</RootNamespace>
+ <Keyword>Win32Proj</Keyword>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <CharacterSet>MultiByte</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
+ <TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">compile</TargetName>
+ <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">compile</TargetName>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>_DEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;INSERVER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>true</MinimalRebuild>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\..\src\mesa;..\..\..\..\src\glsl;..\..\..\..\src\mapi;..\..\..\..\..\include</AdditionalIncludeDirectories>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Console</SubSystem>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ <DataExecutionPrevention>
+ </DataExecutionPrevention>
+ <TargetMachine>MachineX86</TargetMachine>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <PreprocessorDefinitions>NDEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;INSERVER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\..\src\mesa;..\..\..\..\src\glsl;..\..\..\..\src\mapi;..\..\..\..\..\include</AdditionalIncludeDirectories>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Console</SubSystem>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ <DataExecutionPrevention>
+ </DataExecutionPrevention>
+ <TargetMachine>MachineX86</TargetMachine>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\..\..\src\glsl\ast_expr.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ast_function.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ast_to_hir.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ast_type.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\builtin_stubs.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\getopt.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\glcpp-lex.c" />
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\glcpp-parse.c" />
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\pp.c" />
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_lexer.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_parser.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_parser_extras.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_symbol_table.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_types.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\hir_field_selection.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_basic_block.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_clone.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_constant_expression.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_expression_flattening.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_function.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_function_can_inline.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_hierarchical_visitor.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_hv_accept.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_import_prototypes.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_print_visitor.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_reader.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_rvalue_visitor.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_set_program_inouts.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_validate.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_variable.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_variable_refcount.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\linker.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\link_functions.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\loop_analysis.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\loop_controls.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\loop_unroll.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_discard.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_if_to_cond_assign.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_instructions.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_jumps.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_mat_op_to_vec.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_noise.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_texture_projection.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_variable_index_to_cond_assign.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vector.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vec_index_to_cond_assign.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vec_index_to_swizzle.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\main.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_algebraic.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_folding.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_propagation.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_variable.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_copy_propagation.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_copy_propagation_elements.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_code.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_code_local.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_functions.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_discard_simplification.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_function_inlining.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_if_simplification.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_noop_swizzle.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_redundant_jumps.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_structure_splitting.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_swizzle_swizzle.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_tree_grafting.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ralloc.c" />
+ <ClCompile Include="..\..\..\..\src\glsl\strtod.c" />
+ <ClCompile Include="..\..\..\..\src\glsl\s_expression.cpp" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\hash_table.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\symbol_table.c" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\..\src\glsl\strtod.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="..\..\..\..\src\glsl\glsl_lexer.ll">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\..\src\glsl\doflex.bat</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\..\src\glsl\glsl_lexer.cpp ..\..\..\..\src\glsl\glcpp\glcpp-lex.c</Outputs>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\..\src\glsl\doflex.bat</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\..\src\glsl\glsl_lexer.cpp ..\..\..\..\src\glsl\glcpp\glcpp-lex.c</Outputs>
+ </CustomBuild>
+ <CustomBuild Include="..\..\..\..\src\glsl\glsl_parser.yy">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\..\src\glsl\dobison.bat</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\..\src\glsl\glsl_parser.cpp;..\..\..\..\src\glsl\glsl_parser.h;..\..\..\..\src\glsl\glcpp\glcpp-parse.c;..\..\..\..\src\glsl\glcpp\glcpp-parse.h</Outputs>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\..\src\glsl\dobison.bat</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\..\src\glsl\glsl_parser.cpp;..\..\..\..\src\glsl\glsl_parser.h;..\..\..\..\src\glsl\glcpp\glcpp-parse.c;..\..\..\..\src\glsl\glcpp\glcpp-parse.h</Outputs>
+ </CustomBuild>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcxproj.filters b/mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcxproj.filters
new file mode 100644
index 000000000..d087667c0
--- /dev/null
+++ b/mesalib/windows/VC8/mesa/glsl_apps_compile/glsl_apps_compile.vcxproj.filters
@@ -0,0 +1,245 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\..\..\src\glsl\ast_expr.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ast_function.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ast_to_hir.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ast_type.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_lexer.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_parser.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_parser_extras.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_symbol_table.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_types.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\hir_field_selection.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_basic_block.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_clone.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_constant_expression.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_expression_flattening.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_function.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_function_can_inline.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_hierarchical_visitor.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_hv_accept.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_import_prototypes.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_print_visitor.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_reader.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_rvalue_visitor.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_set_program_inouts.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_validate.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_variable.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_variable_refcount.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\link_functions.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\linker.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\loop_analysis.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\loop_controls.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\loop_unroll.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_noise.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_variable_index_to_cond_assign.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\main.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_redundant_jumps.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ralloc.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\s_expression.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\hash_table.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\symbol_table.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\pp.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\glcpp-lex.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\glcpp-parse.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\getopt.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vec_index_to_swizzle.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_folding.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_structure_splitting.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_variable.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_algebraic.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_if_simplification.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_instructions.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_code_local.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_discard_simplification.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vec_index_to_cond_assign.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_function_inlining.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_texture_projection.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_functions.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vector.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\strtod.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_copy_propagation.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_code.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_discard.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_mat_op_to_vec.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_tree_grafting.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_noop_swizzle.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_jumps.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_propagation.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_if_to_cond_assign.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_swizzle_swizzle.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\builtin_stubs.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_copy_propagation_elements.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\..\src\glsl\strtod.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="..\..\..\..\src\glsl\glsl_lexer.ll">
+ <Filter>Source Files</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\..\..\src\glsl\glsl_parser.yy">
+ <Filter>Source Files</Filter>
+ </CustomBuild>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/mesalib/windows/VC8/mesa/glu/glu.vcproj b/mesalib/windows/VC8/mesa/glu/glu.vcproj
deleted file mode 100644
index b3b4b10d7..000000000
--- a/mesalib/windows/VC8/mesa/glu/glu.vcproj
+++ /dev/null
@@ -1,1202 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="8.00"
- Name="glu"
- ProjectGUID="{2E50FDAF-430B-475B-AE6B-60B68F2875BA}"
- RootNamespace="glu"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="2"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName=".\Release/glu.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="../../../../include;../../../../src/glu/sgi/include;../../../../src/glu/sgi/libnurbs/interface;../../../../src/glu/sgi/libnurbs/internals;../../../../src/glu/sgi/libnurbs/nurbtess"
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GLU_EXPORTS;BUILD_GLU32;LIBRARYBUILD;_CRT_SECURE_NO_DEPRECATE"
- StringPooling="true"
- RuntimeLibrary="2"
- EnableFunctionLevelLinking="true"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- OutputFile="$(OutDir)\GLU32.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\glu\sgi\glu.def"
- ProgramDatabaseFile="$(TargetDir)GLU32.pdb"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)GLU32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)GLU32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)GLU32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
- />
- </Configuration>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="2"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="_DEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName=".\Debug/glu.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="../../../../include;../../../../src/glu/sgi/include;../../../../src/glu/sgi/libnurbs/interface;../../../../src/glu/sgi/libnurbs/internals;../../../../src/glu/sgi/libnurbs/nurbtess"
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GLU_EXPORTS;BUILD_GLU32;LIBRARYBUILD;_CRT_SECURE_NO_DEPRECATE"
- BasicRuntimeChecks="3"
- RuntimeLibrary="3"
- WarningLevel="3"
- SuppressStartupBanner="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- OutputFile="$(OutDir)\GLU32.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\glu\sgi\glu.def"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(TargetDir)GLU32.pdb"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)GLU32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)GLU32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)GLU32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
- />
- </Configuration>
- <Configuration
- Name="Debug Static CRT|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="2"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="_DEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName=".\Debug/glu.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="../../../../include;../../../../src/glu/sgi/include;../../../../src/glu/sgi/libnurbs/interface;../../../../src/glu/sgi/libnurbs/internals;../../../../src/glu/sgi/libnurbs/nurbtess"
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GLU_EXPORTS;BUILD_GLU32;LIBRARYBUILD;_CRT_SECURE_NO_DEPRECATE"
- BasicRuntimeChecks="3"
- RuntimeLibrary="1"
- WarningLevel="3"
- SuppressStartupBanner="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- OutputFile="$(OutDir)\GLU32.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\glu\sgi\glu.def"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(TargetDir)GLU32.pdb"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)GLU32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)GLU32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)GLU32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
- />
- </Configuration>
- <Configuration
- Name="Release Static CRT|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="2"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName=".\Release/glu.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="../../../../include;../../../../src/glu/sgi/include;../../../../src/glu/sgi/libnurbs/interface;../../../../src/glu/sgi/libnurbs/internals;../../../../src/glu/sgi/libnurbs/nurbtess"
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GLU_EXPORTS;BUILD_GLU32;LIBRARYBUILD;_CRT_SECURE_NO_DEPRECATE"
- StringPooling="true"
- RuntimeLibrary="0"
- EnableFunctionLevelLinking="true"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- OutputFile="$(OutDir)\GLU32.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\glu\sgi\glu.def"
- ProgramDatabaseFile="$(TargetDir)GLU32.pdb"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)GLU32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)GLU32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)GLU32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
- >
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\dict.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libutil\error.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\geom.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\glu.def"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libutil\glue.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\memalloc.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\mesh.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libutil\mipmap.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\normal.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\priorityq-heap.c"
- >
- <FileConfiguration
- Name="Release|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug Static CRT|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release Static CRT|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\priorityq.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libutil\project.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libutil\quad.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libutil\registry.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\render.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\sweep.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\tess.c"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\tessmono.c"
- >
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl"
- >
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\arc.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\arcsorter.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\arctess.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\backend.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\basiccrveval.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\basicsurfeval.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\bezierarc.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\bezierEval.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\bezierPatch.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\bezierPatchMesh.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\bin.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\bufpool.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\cachingeval.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\coveandtiler.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\curve.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\curvelist.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\dataTransform.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\defines.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\definitions.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\dict-list.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\dict.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\directedLine.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\displaylist.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\displaymode.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\flist.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\flistsorter.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\geom.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\glcurveval.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\glimports.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\glimports.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\glrenderer.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\glsurfeval.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libutil\gluint.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\include\gluos.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\gridline.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\gridtrimvertex.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\gridvertex.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\gridWrap.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\hull.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\jarcloc.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\knotvector.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\mapdesc.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\maplist.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\memalloc.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\mesh.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\mesher.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\monoChain.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\monoPolyPart.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\monotonizer.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\monoTriangulation.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\myassert.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\mymath.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\mysetjmp.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\mystdio.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\mystdio.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\mystdlib.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\mystdlib.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\mystring.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\normal.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\nurbsconsts.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\nurbstess.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\partitionX.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\partitionY.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\patch.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\patchlist.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\polyDBG.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\polyUtil.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\primitiveStream.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\priorityq-heap.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\priorityq-sort.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\priorityq.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\pwlarc.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\quicksort.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\quilt.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\reader.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\rectBlock.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\render.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\renderhints.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampleComp.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampleCompBot.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampleCompRight.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampleCompTop.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampledLine.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampleMonoPoly.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\searchTree.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\simplemath.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\slicer.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\sorter.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\subdivider.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\sweep.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\tess.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\tessmono.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\trimline.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\trimregion.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\trimvertex.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\trimvertpool.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\types.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\uarray.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\varray.h"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\zlassert.h"
- >
- </File>
- </Filter>
- <Filter
- Name="C++ files"
- Filter=".cc"
- >
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\arc.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\arcsorter.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\arctess.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\backend.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\basiccrveval.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\basicsurfeval.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\bezierEval.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\bezierPatch.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\bezierPatchMesh.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\bin.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\bufpool.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\cachingeval.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\ccw.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\coveandtiler.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\curve.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\curvelist.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\curvesub.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\dataTransform.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\directedLine.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\displaylist.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\flist.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\flistsorter.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\glcurveval.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\glinterface.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\glrenderer.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\glsurfeval.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\gridWrap.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\hull.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\incurveeval.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\interface\insurfeval.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\intersect.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\knotvector.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\mapdesc.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\mapdescv.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\maplist.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\mesher.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\monoChain.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\monoPolyPart.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\monotonizer.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\monoTriangulation.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\monoTriangulationBackend.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\mycode.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\nurbsinterfac.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\nurbstess.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\partitionX.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\partitionY.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\patch.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\patchlist.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\polyDBG.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\polyUtil.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\primitiveStream.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\quicksort.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\quilt.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\reader.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\README"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\rectBlock.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\renderhints.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampleComp.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampleCompBot.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampleCompRight.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampleCompTop.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampledLine.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\sampleMonoPoly.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\nurbtess\searchTree.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\slicer.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\sorter.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\splitarcs.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\subdivider.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\tobezier.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\trimline.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\trimregion.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\trimvertpool.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\uarray.cc"
- >
- </File>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libnurbs\internals\varray.cc"
- >
- </File>
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
- >
- </Filter>
- <File
- RelativePath="..\..\..\..\src\glu\sgi\libtess\alg-outline"
- >
- </File>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/mesalib/windows/VC8/mesa/makefile b/mesalib/windows/VC8/mesa/makefile
new file mode 100644
index 000000000..727065a40
--- /dev/null
+++ b/mesalib/windows/VC8/mesa/makefile
@@ -0,0 +1,58 @@
+ifdef VS2008
+MHMAKESLNFILE=mesa.sln
+BUILDCMD=vcbuild $(MHMAKESLNFILE)
+else
+MHMAKESLNFILE=mesavc10.sln
+BUILDCMD=devenv.com $(MHMAKESLNFILE) /build
+endif
+
+DEPS:=$(wildcard ..\..\..\src\mesa\swrast\*.c) \
+ $(wildcard ..\..\..\src\mesa\swrast\*.h) \
+ $(wildcard ..\..\..\src\mesa\swrast_setup\*.c) \
+ $(wildcard ..\..\..\src\mesa\swrast_setup\*.h) \
+ $(wildcard ..\..\..\src\mesa\main\*.c) \
+ $(wildcard ..\..\..\src\mesa\main\*.h) \
+ $(wildcard ..\..\..\src\mesa\math\*.c) \
+ $(wildcard ..\..\..\src\mesa\math\*.h) \
+ $(wildcard ..\..\..\src\mesa\program\*.c) \
+ $(wildcard ..\..\..\src\mesa\program\*.cpp) \
+ $(wildcard ..\..\..\src\mesa\program\*.h) \
+ $(wildcard ..\..\..\src\mesa\shader\*.c) \
+ $(wildcard ..\..\..\src\mesa\shader\*.h) \
+ $(wildcard ..\..\..\src\mesa\shader\slang\*.c) \
+ $(wildcard ..\..\..\src\mesa\shader\slang\*.h) \
+ $(wildcard ..\..\..\src\mesa\shader\slang\library\*.c) \
+ $(wildcard ..\..\..\src\mesa\shader\slang\library\*.h) \
+ $(wildcard ..\..\..\src\mesa\glapi\*.c) \
+ $(wildcard ..\..\..\src\mesa\glapi\*.h) \
+ $(wildcard ..\..\..\src\mesa\math\*.c) \
+ $(wildcard ..\..\..\src\mesa\math\*.h) \
+ $(wildcard ..\..\..\src\mesa\tnl\*.c) \
+ $(wildcard ..\..\..\src\mesa\tnl\*.h) \
+ $(wildcard ..\..\..\src\mesa\vbo\*.c) \
+ $(wildcard ..\..\..\src\mesa\vbo\*.h) \
+ $(wildcard ..\..\..\src\glsl\glcpp\*.c) \
+ $(wildcard ..\..\..\src\glsl\glcpp\*.h) \
+ $(wildcard ..\..\..\src\glsl\*.c) \
+ $(wildcard ..\..\..\src\glsl\*.h) \
+ $(wildcard ..\..\..\src\glsl\*.cpp) \
+ $(wildcard ..\..\..\src\mesa\drivers\dri\swrast\*.c) \
+ $(wildcard ..\..\..\src\mesa\drivers\dri\swrast\*.h) \
+ $(wildcard ..\..\..\src\mesa\drivers\dri\common\*.c) \
+ $(wildcard ..\..\..\src\mesa\drivers\dri\common\*.h) \
+ $(wildcard ..\..\..\src\mesa\drivers\common\*.c) \
+ $(wildcard ..\..\..\src\mesa\drivers\common\*.h)
+
+all: Release\swrast_dri.dll Debug\swrast_dri.dll
+
+Debug\swrast_dri.dll: $(DEPS)
+ $(BUILDCMD) "Debug|Win32"
+
+Release\swrast_dri.dll: $(DEPS)
+ $(BUILDCMD) "Release|Win32"
+
+clean: cleanthis
+
+cleanthis:
+ del -e Debug
+ del -e Release
diff --git a/mesalib/windows/VC8/mesa/mesa.sln b/mesalib/windows/VC8/mesa/mesa.sln
index 915e00026..9d232353b 100644
--- a/mesalib/windows/VC8/mesa/mesa.sln
+++ b/mesalib/windows/VC8/mesa/mesa.sln
@@ -1,27 +1,17 @@
-Microsoft Visual Studio Solution File, Format Version 9.00
-# Visual Studio 2005
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gdi", "gdi\gdi.vcproj", "{A1B24907-E196-4826-B6AF-26723629B633}"
- ProjectSection(ProjectDependencies) = postProject
- {2120C974-2717-4709-B44F-D6E6D0A56448} = {2120C974-2717-4709-B44F-D6E6D0A56448}
- EndProjectSection
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glu", "glu\glu.vcproj", "{2E50FDAF-430B-475B-AE6B-60B68F2875BA}"
- ProjectSection(ProjectDependencies) = postProject
- {A1B24907-E196-4826-B6AF-26723629B633} = {A1B24907-E196-4826-B6AF-26723629B633}
- EndProjectSection
-EndProject
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mesa", "mesa\mesa.vcproj", "{2120C974-2717-4709-B44F-D6E6D0A56448}"
ProjectSection(ProjectDependencies) = postProject
{98AB3D51-1820-4D14-9195-75FCA6997784} = {98AB3D51-1820-4D14-9195-75FCA6997784}
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "osmesa", "osmesa\osmesa.vcproj", "{8D6CD423-383B-49E7-81BC-D20C70B07DF5}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glsl_apps_compile", "glsl_apps_compile\glsl_apps_compile.vcproj", "{98AB3D51-1820-4D14-9195-75FCA6997784}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "swrast_dri", "swrast_dri\swrast_dri.vcproj", "{FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}"
ProjectSection(ProjectDependencies) = postProject
- {A1B24907-E196-4826-B6AF-26723629B633} = {A1B24907-E196-4826-B6AF-26723629B633}
+ {2120C974-2717-4709-B44F-D6E6D0A56448} = {2120C974-2717-4709-B44F-D6E6D0A56448}
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glsl_apps_compile", "glsl_apps_compile\glsl_apps_compile.vcproj", "{98AB3D51-1820-4D14-9195-75FCA6997784}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Static CRT|Win32 = Debug Static CRT|Win32
@@ -31,21 +21,13 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A1B24907-E196-4826-B6AF-26723629B633}.Debug Static CRT|Win32.ActiveCfg = Debug Static CRT|Win32
- {A1B24907-E196-4826-B6AF-26723629B633}.Debug Static CRT|Win32.Build.0 = Debug Static CRT|Win32
{A1B24907-E196-4826-B6AF-26723629B633}.Debug|Win32.ActiveCfg = Debug|Win32
- {A1B24907-E196-4826-B6AF-26723629B633}.Debug|Win32.Build.0 = Debug|Win32
{A1B24907-E196-4826-B6AF-26723629B633}.Release Static CRT|Win32.ActiveCfg = Release Static CRT|Win32
- {A1B24907-E196-4826-B6AF-26723629B633}.Release Static CRT|Win32.Build.0 = Release Static CRT|Win32
{A1B24907-E196-4826-B6AF-26723629B633}.Release|Win32.ActiveCfg = Release|Win32
- {A1B24907-E196-4826-B6AF-26723629B633}.Release|Win32.Build.0 = Release|Win32
{2E50FDAF-430B-475B-AE6B-60B68F2875BA}.Debug Static CRT|Win32.ActiveCfg = Debug Static CRT|Win32
- {2E50FDAF-430B-475B-AE6B-60B68F2875BA}.Debug Static CRT|Win32.Build.0 = Debug Static CRT|Win32
{2E50FDAF-430B-475B-AE6B-60B68F2875BA}.Debug|Win32.ActiveCfg = Debug|Win32
- {2E50FDAF-430B-475B-AE6B-60B68F2875BA}.Debug|Win32.Build.0 = Debug|Win32
{2E50FDAF-430B-475B-AE6B-60B68F2875BA}.Release Static CRT|Win32.ActiveCfg = Release Static CRT|Win32
- {2E50FDAF-430B-475B-AE6B-60B68F2875BA}.Release Static CRT|Win32.Build.0 = Release Static CRT|Win32
{2E50FDAF-430B-475B-AE6B-60B68F2875BA}.Release|Win32.ActiveCfg = Release|Win32
- {2E50FDAF-430B-475B-AE6B-60B68F2875BA}.Release|Win32.Build.0 = Release|Win32
{2120C974-2717-4709-B44F-D6E6D0A56448}.Debug Static CRT|Win32.ActiveCfg = Debug Static CRT|Win32
{2120C974-2717-4709-B44F-D6E6D0A56448}.Debug Static CRT|Win32.Build.0 = Debug Static CRT|Win32
{2120C974-2717-4709-B44F-D6E6D0A56448}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -55,13 +37,17 @@ Global
{2120C974-2717-4709-B44F-D6E6D0A56448}.Release|Win32.ActiveCfg = Release|Win32
{2120C974-2717-4709-B44F-D6E6D0A56448}.Release|Win32.Build.0 = Release|Win32
{8D6CD423-383B-49E7-81BC-D20C70B07DF5}.Debug Static CRT|Win32.ActiveCfg = Debug Static CRT|Win32
- {8D6CD423-383B-49E7-81BC-D20C70B07DF5}.Debug Static CRT|Win32.Build.0 = Debug Static CRT|Win32
{8D6CD423-383B-49E7-81BC-D20C70B07DF5}.Debug|Win32.ActiveCfg = Debug|Win32
- {8D6CD423-383B-49E7-81BC-D20C70B07DF5}.Debug|Win32.Build.0 = Debug|Win32
{8D6CD423-383B-49E7-81BC-D20C70B07DF5}.Release Static CRT|Win32.ActiveCfg = Release Static CRT|Win32
- {8D6CD423-383B-49E7-81BC-D20C70B07DF5}.Release Static CRT|Win32.Build.0 = Release Static CRT|Win32
{8D6CD423-383B-49E7-81BC-D20C70B07DF5}.Release|Win32.ActiveCfg = Release|Win32
- {8D6CD423-383B-49E7-81BC-D20C70B07DF5}.Release|Win32.Build.0 = Release|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Debug Static CRT|Win32.ActiveCfg = Debug Static CRT|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Debug Static CRT|Win32.Build.0 = Debug Static CRT|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Debug|Win32.ActiveCfg = Debug|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Debug|Win32.Build.0 = Debug|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Release Static CRT|Win32.ActiveCfg = Release Static CRT|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Release Static CRT|Win32.Build.0 = Release Static CRT|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Release|Win32.ActiveCfg = Release|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Release|Win32.Build.0 = Release|Win32
{98AB3D51-1820-4D14-9195-75FCA6997784}.Debug Static CRT|Win32.ActiveCfg = Debug|Win32
{98AB3D51-1820-4D14-9195-75FCA6997784}.Debug Static CRT|Win32.Build.0 = Debug|Win32
{98AB3D51-1820-4D14-9195-75FCA6997784}.Debug|Win32.ActiveCfg = Debug|Win32
diff --git a/mesalib/windows/VC8/mesa/mesa/mesa.vcproj b/mesalib/windows/VC8/mesa/mesa/mesa.vcproj
index 5a5b93a77..eb78e6c60 100644
--- a/mesalib/windows/VC8/mesa/mesa/mesa.vcproj
+++ b/mesalib/windows/VC8/mesa/mesa/mesa.vcproj
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="8.00"
+ Version="9,00"
Name="mesa"
ProjectGUID="{2120C974-2717-4709-B44F-D6E6D0A56448}"
RootNamespace="mesa"
+ TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
@@ -46,9 +47,11 @@
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/Zm1000 "
- InlineFunctionExpansion="1"
+ InlineFunctionExpansion="2"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
AdditionalIncludeDirectories="../../../../include,../../../../src/mesa,../../../../src/mesa/glapi,../../../../src/mesa/main,../../../../src/mesa/shader,../../../../src/mesa/shader/slang"
- PreprocessorDefinitions="NDEBUG;WIN32;_LIB;_DLL;BUILD_GL32;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE"
+ PreprocessorDefinitions="NDEBUG;WIN32;_LIB;_DLL;BUILD_GL32;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE;INSERVER"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
@@ -123,7 +126,7 @@
AdditionalOptions="/Zm1000 "
Optimization="0"
AdditionalIncludeDirectories="../../../../include,../../../../src/mesa,../../../../src/mesa/glapi,../../../../src/mesa/main,../../../../src/mesa/shader,../../../../src/mesa/shader/slang"
- PreprocessorDefinitions="_DEBUG;WIN32;_LIB;_DLL;BUILD_GL32;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE"
+ PreprocessorDefinitions="_DEBUG;WIN32;_LIB;_DLL;BUILD_GL32;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE;INSERVER"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BrowseInformation="1"
@@ -198,7 +201,7 @@
AdditionalOptions="/Zm1000 "
Optimization="0"
AdditionalIncludeDirectories="../../../../include,../../../../src/mesa,../../../../src/mesa/glapi,../../../../src/mesa/main,../../../../src/mesa/shader,../../../../src/mesa/shader/slang"
- PreprocessorDefinitions="_DEBUG;WIN32;_LIB;BUILD_GL32;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE"
+ PreprocessorDefinitions="_DEBUG;WIN32;_LIB;BUILD_GL32;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE;INSERVER"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
BrowseInformation="1"
@@ -271,12 +274,17 @@
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/Zm1000 "
- InlineFunctionExpansion="1"
+ InlineFunctionExpansion="2"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
AdditionalIncludeDirectories="../../../../include,../../../../src/mesa,../../../../src/mesa/glapi,../../../../src/mesa/main,../../../../src/mesa/shader,../../../../src/mesa/shader/slang"
- PreprocessorDefinitions="NDEBUG;WIN32;_LIB;BUILD_GL32;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE"
+ PreprocessorDefinitions="NDEBUG;WIN32;_LIB;BUILD_GL32;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE;INSERVER"
StringPooling="true"
+ ExceptionHandling="0"
RuntimeLibrary="0"
+ BufferSecurityCheck="false"
EnableFunctionLevelLinking="true"
+ EnableEnhancedInstructionSet="2"
UsePrecompiledHeader="0"
WarningLevel="3"
SuppressStartupBanner="true"
@@ -519,6 +527,10 @@
>
</File>
<File
+ RelativePath="..\..\..\..\src\mesa\shader\hash_table.c"
+ >
+ </File>
+ <File
RelativePath="..\..\..\..\src\mesa\main\hint.c"
>
</File>
@@ -571,6 +583,42 @@
</FileConfiguration>
</File>
<File
+ RelativePath="..\..\..\..\src\mesa\shader\lex.yy.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="YY_NO_UNISTD_H"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="YY_NO_UNISTD_H"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug Static CRT|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="YY_NO_UNISTD_H"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release Static CRT|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="YY_NO_UNISTD_H"
+ />
+ </FileConfiguration>
+ </File>
+ <File
RelativePath="..\..\..\..\src\mesa\main\light.c"
>
</File>
@@ -759,10 +807,6 @@
>
</File>
<File
- RelativePath="..\..\..\..\src\mesa\main\remap.c"
- >
- </File>
- <File
RelativePath="..\..\..\..\src\mesa\main\renderbuffer.c"
>
</File>
@@ -1051,6 +1095,14 @@
>
</File>
<File
+ RelativePath="..\..\..\..\src\mesa\shader\symbol_table.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\src\mesa\main\syncobj.c"
+ >
+ </File>
+ <File
RelativePath="..\..\..\..\src\mesa\main\syncobj.c"
>
</File>
diff --git a/mesalib/windows/VC8/mesa/mesa/mesa.vcxproj b/mesalib/windows/VC8/mesa/mesa/mesa.vcxproj
new file mode 100644
index 000000000..87d0d6888
--- /dev/null
+++ b/mesalib/windows/VC8/mesa/mesa/mesa.vcxproj
@@ -0,0 +1,355 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{2120C974-2717-4709-B44F-D6E6D0A56448}</ProjectGuid>
+ <RootNamespace>mesa</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseOfMfc>false</UseOfMfc>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseOfMfc>false</UseOfMfc>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
+ <PreBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</PreBuildEventUseInBuild>
+ <PreLinkEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</PreLinkEventUseInBuild>
+ <PostBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</PostBuildEventUseInBuild>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <OmitFramePointers>true</OmitFramePointers>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <AdditionalIncludeDirectories>../../../../include;../../../../src/mesa;../../../../src/glsl;../../../../src/mapi;../../../../src/mesa/main;../../../../src/mesa/shader;../../../../src/mesa/shader/slang;../../../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>NDEBUG;WIN32;_LIB;_DLL;_GDI32_;BUILD_GL32;WIN32_THREADS;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE;INSERVER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <StringPooling>true</StringPooling>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <ForcedIncludeFiles>../../../../src/mesa/main/compiler.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <Culture>0x0409</Culture>
+ </ResourceCompile>
+ <Lib>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <AdditionalIncludeDirectories>../../../../include;../../../../src/mesa;../../../../src/glsl;../../../../src/mapi;../../../../src/mesa/main;../../../../src/mesa/shader;../../../../src/mesa/shader/slang;../../../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>_DEBUG;DEBUG;WIN32;_LIB;_DLL;_GDI32_;BUILD_GL32;WIN32_THREADS;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE;INSERVER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <BrowseInformation>true</BrowseInformation>
+ <WarningLevel>Level3</WarningLevel>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <ForcedIncludeFiles>../../../../src/mesa/main/compiler.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <Culture>0x0409</Culture>
+ </ResourceCompile>
+ <Lib>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\glsl_apps_compile\glsl_apps_compile.vcxproj">
+ <Project>{98ab3d51-1820-4d14-9195-75fca6997784}</Project>
+ <CopyLocalSatelliteAssemblies>true</CopyLocalSatelliteAssemblies>
+ <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\..\..\src\glsl\ast_expr.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ast_function.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ast_to_hir.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ast_type.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\builtin_stubs.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\glcpp-lex.c" />
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\glcpp-parse.c" />
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\pp.c" />
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_lexer.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_parser.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_parser_extras.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_symbol_table.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_types.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\hir_field_selection.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_basic_block.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_clone.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_constant_expression.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_expression_flattening.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_function.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_function_can_inline.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_hierarchical_visitor.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_hv_accept.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_import_prototypes.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_print_visitor.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_reader.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_rvalue_visitor.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_set_program_inouts.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ir_validate.cpp">
+ <ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ </ForcedIncludeFiles>
+ <ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ </ForcedIncludeFiles>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_variable.cpp">
+ <ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ </ForcedIncludeFiles>
+ <ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ </ForcedIncludeFiles>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_variable_refcount.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\linker.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\link_functions.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\loop_analysis.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\loop_controls.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\loop_unroll.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_discard.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_if_to_cond_assign.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_instructions.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_jumps.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_mat_op_to_vec.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_noise.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_texture_projection.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_variable_index_to_cond_assign.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vector.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vec_index_to_cond_assign.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vec_index_to_swizzle.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_algebraic.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_folding.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_propagation.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_variable.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_copy_propagation.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_copy_propagation_elements.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_code.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_code_local.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_functions.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_discard_simplification.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_function_inlining.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_if_simplification.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_noop_swizzle.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_redundant_jumps.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_structure_splitting.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_swizzle_swizzle.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\opt_tree_grafting.cpp" />
+ <ClCompile Include="..\..\..\..\src\glsl\ralloc.c" />
+ <ClCompile Include="..\..\..\..\src\glsl\strtod.c" />
+ <ClCompile Include="..\..\..\..\src\glsl\s_expression.cpp" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\accum.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\api_arrayelt.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\api_exec.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\api_loopback.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\api_noop.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\api_validate.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\arbprogram.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\atifragshader.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\nvprogram.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\pack.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\pixeltransfer.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\querymatrix.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\shaderapi.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\shaderobj.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\transformfeedback.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\uniforms.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\arbprogparse.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\arrayobj.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\attrib.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\blend.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\bufferobj.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\buffers.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\clear.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\clip.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\colortab.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\condrender.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\context.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\convolve.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\cpuinfo.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\debug.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\depth.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\depthstencil.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\dlist.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\dlopen.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\drawpix.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\enable.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\enums.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\eval.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\execmem.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\extensions.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\fbobject.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\feedback.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\ffvertex_prog.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\fog.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\formats.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\framebuffer.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\get.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\getstring.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\hash.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\hash_table.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\ir_to_mesa.cpp" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\lex.yy.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\nvfragparse.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\nvvertparse.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\program.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\programopt.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\program_parse.tab.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\program_parse_extra.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_cache.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_execute.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_instruction.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_noise.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_optimize.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_parameter.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_parameter_layout.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_print.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_statevars.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_uniform.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\register_allocate.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\sampler.cpp" />
+ <ClCompile Include="..\..\..\..\src\mesa\program\symbol_table.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\hint.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\histogram.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\image.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\imports.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\light.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\lines.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\math\m_eval.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\math\m_matrix.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\math\m_translate.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\math\m_vector.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\math\m_xform.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\matrix.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\mipmap.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\mm.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\multisample.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\pbo.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\pixel.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\pixelstore.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\points.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\polygon.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\queryobj.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\rastpos.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\readpix.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\renderbuffer.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\scissor.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\shared.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\state.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\stencil.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\syncobj.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_context.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_draw.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_pipeline.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_rasterpos.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_fog.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_light.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_normals.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_points.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_program.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_render.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_texgen.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_texmat.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_vertex.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vertex.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vertex_generic.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vp_build.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texcompress.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texcompress_fxt1.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texcompress_rgtc.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texcompress_s3tc.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texenv.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texenvprogram.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texfetch.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texformat.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texgen.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texgetimage.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\teximage.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texobj.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texparam.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texrender.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texstate.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\texstore.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\varray.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_context.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_exec.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_exec_api.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_exec_array.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_exec_draw.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_exec_eval.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_rebase.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_save.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_save_api.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_save_draw.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_save_loopback.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_split.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_split_copy.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_split_inplace.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\version.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\viewport.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\main\vtxfmt.c" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\..\src\glsl\strtod.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="..\..\..\..\src\mesa\program\program_lexer.l">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\..\src\mesa\program\doflex.bat</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\..\src\mesa\program\lex.yy.c;%(Outputs)</Outputs>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\..\src\mesa\program\doflex.bat</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\..\src\mesa\program\lex.yy.c;%(Outputs)</Outputs>
+ </CustomBuild>
+ <CustomBuild Include="..\..\..\..\src\mesa\program\program_parse.y">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\..\src\mesa\program\dobison.bat</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\..\src\mesa\program\program_parse.tab.c;..\..\..\..\src\mesa\program\program_parse.tab.h;%(Outputs)</Outputs>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\..\src\mesa\program\dobison.bat</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\..\src\mesa\program\program_parse.tab.c;..\..\..\..\src\mesa\program\program_parse.tab.h;%(Outputs)</Outputs>
+ </CustomBuild>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/mesalib/windows/VC8/mesa/mesa/mesa.vcxproj.filters b/mesalib/windows/VC8/mesa/mesa/mesa.vcxproj.filters
new file mode 100644
index 000000000..7b2efa709
--- /dev/null
+++ b/mesalib/windows/VC8/mesa/mesa/mesa.vcxproj.filters
@@ -0,0 +1,679 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{8411a2f0-9621-4bb9-9aec-30713df37794}</UniqueIdentifier>
+ <Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{82940400-de84-4aa3-8c90-a68fc32ae059}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\..\..\src\mesa\main\api_arrayelt.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\api_exec.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\api_loopback.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\api_noop.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\api_validate.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\arrayobj.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\attrib.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\blend.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\bufferobj.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\buffers.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\clear.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\clip.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\colortab.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\condrender.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\context.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\convolve.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\cpuinfo.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\debug.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\depth.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\depthstencil.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\dlist.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\dlopen.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\drawpix.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\enable.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\enums.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\eval.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\execmem.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\extensions.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\fbobject.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\feedback.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\ffvertex_prog.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\fog.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\formats.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\framebuffer.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\get.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\getstring.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\hash.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\hint.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\histogram.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\image.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\imports.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\light.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\lines.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\math\m_eval.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\math\m_matrix.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\math\m_translate.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\math\m_vector.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\math\m_xform.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\matrix.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\mipmap.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\mm.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\multisample.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\pixel.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\pixelstore.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\points.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\polygon.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\queryobj.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\rastpos.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\readpix.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\renderbuffer.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\scissor.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\shared.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\state.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\stencil.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\syncobj.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_context.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_draw.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_pipeline.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_rasterpos.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_fog.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_light.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_normals.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_points.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_program.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_render.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_texgen.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_texmat.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vb_vertex.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vertex.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vertex_generic.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\tnl\t_vp_build.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texcompress.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texcompress_fxt1.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texcompress_s3tc.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texenv.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texenvprogram.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texfetch.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texformat.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texgen.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texgetimage.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\teximage.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texobj.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texparam.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texrender.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texstate.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texstore.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\varray.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_context.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_exec.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_exec_api.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_exec_array.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_exec_draw.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_exec_eval.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_rebase.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_save.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_save_api.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_save_draw.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_save_loopback.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_split.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_split_copy.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\vbo\vbo_split_inplace.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\version.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\viewport.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\vtxfmt.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\arbprogparse.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\arbprogram.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\atifragshader.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\symbol_table.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\programopt.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_uniform.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\program.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\program_parse_extra.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_cache.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_execute.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_instruction.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_noise.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_optimize.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_parameter.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_parameter_layout.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_print.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\prog_statevars.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\hash_table.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\nvfragparse.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\nvvertparse.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\nvprogram.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\lex.yy.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\program_parse.tab.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\transformfeedback.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\shaderobj.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\shaderapi.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\accum.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\querymatrix.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\uniforms.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\ir_to_mesa.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ralloc.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_variable_index_to_cond_assign.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_hierarchical_visitor.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_types.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_variable.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_function.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_function_can_inline.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_rvalue_visitor.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_hv_accept.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_symbol_table.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_constant_expression.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_clone.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\linker.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_parser_extras.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_variable_refcount.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_basic_block.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\loop_analysis.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\loop_controls.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_expression_flattening.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_import_prototypes.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\link_functions.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\loop_unroll.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_redundant_jumps.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ast_to_hir.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ast_expr.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\hir_field_selection.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_lexer.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ast_type.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\pp.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\glcpp-parse.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glcpp\glcpp-lex.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_reader.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\glsl_parser.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_print_visitor.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_validate.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ir_set_program_inouts.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_noise.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\ast_function.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\s_expression.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\pack.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\pixeltransfer.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\register_allocate.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vec_index_to_swizzle.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_folding.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_structure_splitting.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_variable.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_algebraic.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_if_simplification.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_instructions.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_code_local.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_discard_simplification.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vec_index_to_cond_assign.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_function_inlining.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_texture_projection.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_functions.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_vector.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\strtod.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_copy_propagation.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_dead_code.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_discard.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_mat_op_to_vec.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_tree_grafting.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_noop_swizzle.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_jumps.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_constant_propagation.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\lower_if_to_cond_assign.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_swizzle_swizzle.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\program\sampler.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\builtin_stubs.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\glsl\opt_copy_propagation_elements.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\pbo.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\main\texcompress_rgtc.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\..\src\glsl\strtod.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="..\..\..\..\src\mesa\program\program_lexer.l">
+ <Filter>Source Files</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\..\..\src\mesa\program\program_parse.y">
+ <Filter>Source Files</Filter>
+ </CustomBuild>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/mesalib/windows/VC8/mesa/mesavc10.sln b/mesalib/windows/VC8/mesa/mesavc10.sln
new file mode 100644
index 000000000..92fcf6f6d
--- /dev/null
+++ b/mesalib/windows/VC8/mesa/mesavc10.sln
@@ -0,0 +1,31 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mesa", "mesa\mesa.vcxproj", "{2120C974-2717-4709-B44F-D6E6D0A56448}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glsl_apps_compile", "glsl_apps_compile\glsl_apps_compile.vcxproj", "{98AB3D51-1820-4D14-9195-75FCA6997784}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "swrast_dri", "swrast_dri\swrast_dri.vcxproj", "{FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {2120C974-2717-4709-B44F-D6E6D0A56448}.Debug|Win32.ActiveCfg = Debug|Win32
+ {2120C974-2717-4709-B44F-D6E6D0A56448}.Debug|Win32.Build.0 = Debug|Win32
+ {2120C974-2717-4709-B44F-D6E6D0A56448}.Release|Win32.ActiveCfg = Release|Win32
+ {2120C974-2717-4709-B44F-D6E6D0A56448}.Release|Win32.Build.0 = Release|Win32
+ {98AB3D51-1820-4D14-9195-75FCA6997784}.Debug|Win32.ActiveCfg = Debug|Win32
+ {98AB3D51-1820-4D14-9195-75FCA6997784}.Debug|Win32.Build.0 = Debug|Win32
+ {98AB3D51-1820-4D14-9195-75FCA6997784}.Release|Win32.ActiveCfg = Release|Win32
+ {98AB3D51-1820-4D14-9195-75FCA6997784}.Release|Win32.Build.0 = Release|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Debug|Win32.ActiveCfg = Debug|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Debug|Win32.Build.0 = Debug|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Release|Win32.ActiveCfg = Release|Win32
+ {FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/mesalib/windows/VC8/mesa/osmesa/osmesa.vcproj b/mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcproj
index 10f2dc971..d4086f118 100644
--- a/mesalib/windows/VC8/mesa/osmesa/osmesa.vcproj
+++ b/mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcproj
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="8.00"
- Name="osmesa"
- ProjectGUID="{8D6CD423-383B-49E7-81BC-D20C70B07DF5}"
- RootNamespace="osmesa"
+ Version="9,00"
+ Name="swrast_dri"
+ ProjectGUID="{FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}"
+ RootNamespace="swrast_dri"
+ TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
@@ -15,7 +16,7 @@
</ToolFiles>
<Configurations>
<Configuration
- Name="Release|Win32"
+ Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
@@ -38,31 +39,31 @@
/>
<Tool
Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
+ PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
- TypeLibraryName=".\Release/osmesa.tlb"
+ TypeLibraryName=".\Debug/swrast_dri.tlb"
/>
<Tool
Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="../../../../include,../../../../src/mesa,../../../../src/mesa/main,../../../../src/mesa/glapi,../../../../src/mesa/swrast,../../../../src/mesa/shader"
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OSMESA_EXPORTS;BUILD_GL32"
- StringPooling="true"
- RuntimeLibrary="2"
- EnableFunctionLevelLinking="true"
+ Optimization="0"
+ AdditionalIncludeDirectories="../../../../include;../../../../src/mesa/drivers/dri/common;../../../../src/mesa"
+ PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;_USRDLL;SWRAST_DRI_EXPORTS;_DLL;BUILD_GL32;MESA_MINWARN;IN_DRI_DRIVER;INSERVER"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
+ DebugInformationFormat="3"
CompileAs="0"
- ForcedIncludeFiles="../../../../src/mesa/main/compiler.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
+ PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
@@ -71,13 +72,15 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="gdi32.lib user32.lib"
- OutputFile="$(OutDir)\OSMESA32.dll"
+ AdditionalDependencies="gdi32.lib user32.lib vcxsrv_dbg.lib"
+ OutputFile="$(OutDir)\swrast_dri.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\mesa\drivers\osmesa\osmesa.def"
- ProgramDatabaseFile="$(TargetDir)OSMESA32.pdb"
+ AdditionalLibraryDirectories="&quot;$(TargetDir)&quot;;&quot;..\..\..\..\..\xorg-server\obj\servdebug&quot;"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(TargetDir)swrast_dri.pdb"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
@@ -98,15 +101,11 @@
Name="VCAppVerifierTool"
/>
<Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OSMESA32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OSMESA32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)OSMESA32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
/>
</Configuration>
<Configuration
- Name="Debug|Win32"
+ Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
@@ -129,31 +128,36 @@
/>
<Tool
Name="VCMIDLTool"
- PreprocessorDefinitions="_DEBUG"
+ PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
- TypeLibraryName=".\Debug/osmesa.tlb"
+ TypeLibraryName=".\Release/swrast_dri.tlb"
/>
<Tool
Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="../../../../include,../../../../src/mesa,../../../../src/mesa/main,../../../../src/mesa/glapi,../../../../src/mesa/swrast,../../../../src/mesa/shader"
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;OSMESA_EXPORTS;BUILD_GL32"
- BasicRuntimeChecks="3"
- RuntimeLibrary="3"
+ InlineFunctionExpansion="2"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="../../../../include;../../../../src/mesa/drivers/dri/common;../../../../src/mesa"
+ PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;_USRDLL;SWRAST_DRI_EXPORTS;_DLL;BUILD_GL32;MESA_MINWARN;IN_DRI_DRIVER;INSERVER"
+ StringPooling="true"
+ ExceptionHandling="0"
+ RuntimeLibrary="2"
+ BufferSecurityCheck="false"
+ EnableFunctionLevelLinking="true"
+ EnableEnhancedInstructionSet="2"
+ PrecompiledHeaderFile=".\Release/swrast_dri.pch"
WarningLevel="3"
SuppressStartupBanner="true"
- DebugInformationFormat="3"
CompileAs="0"
- ForcedIncludeFiles="../../../../src/mesa/main/compiler.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
+ PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
@@ -162,14 +166,15 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="gdi32.lib user32.lib"
- OutputFile="$(OutDir)\OSMESA32.dll"
+ AdditionalDependencies="gdi32.lib user32.lib vcxsrv.lib"
+ OutputFile="$(OutDir)\swrast_dri.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\mesa\drivers\osmesa\osmesa.def"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(TargetDir)OSMESA32.pdb"
+ AdditionalLibraryDirectories="$(TargetDir);&quot;..\..\..\..\..\xorg-server\obj\servrelease&quot;"
+ ProgramDatabaseFile="$(TargetDir)swrast_dri.pdb"
+ LinkTimeCodeGeneration="1"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
@@ -190,11 +195,7 @@
Name="VCAppVerifierTool"
/>
<Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OSMESA32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OSMESA32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)OSMESA32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
/>
</Configuration>
<Configuration
@@ -225,20 +226,20 @@
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
- TypeLibraryName=".\Debug/osmesa.tlb"
+ TypeLibraryName=".\Debug/swrast_dri.tlb"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories="../../../../include,../../../../src/mesa,../../../../src/mesa/main,../../../../src/mesa/glapi,../../../../src/mesa/swrast,../../../../src/mesa/shader"
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;OSMESA_EXPORTS;BUILD_GL32"
+ AdditionalIncludeDirectories="../../../../include;../../../../src/mesa/drivers/dri/common;../../../../src/mesa"
+ PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;_USRDLL;SWRAST_DRI_EXPORTS;BUILD_GL32;MESA_MINWARN;IN_DRI_DRIVER;INSERVER"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
+ BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
CompileAs="0"
- ForcedIncludeFiles="../../../../src/mesa/main/compiler.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@@ -254,14 +255,15 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="gdi32.lib user32.lib"
- OutputFile="$(OutDir)\OSMESA32.dll"
+ AdditionalDependencies="gdi32.lib user32.lib vcxsrv_dbg.lib"
+ OutputFile="$(OutDir)\swrast_dri.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\mesa\drivers\osmesa\osmesa.def"
+ AdditionalLibraryDirectories="$(TargetDir);&quot;..\..\..\..\..\xorg-server\obj\servdebug&quot;"
GenerateDebugInformation="true"
- ProgramDatabaseFile="$(TargetDir)OSMESA32.pdb"
+ ProgramDatabaseFile="$(TargetDir)swrast_dri.pdb"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
@@ -282,11 +284,7 @@
Name="VCAppVerifierTool"
/>
<Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OSMESA32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OSMESA32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)OSMESA32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
/>
</Configuration>
<Configuration
@@ -317,20 +315,25 @@
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
- TypeLibraryName=".\Release/osmesa.tlb"
+ TypeLibraryName=".\Release/swrast_dri.tlb"
/>
<Tool
Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="../../../../include,../../../../src/mesa,../../../../src/mesa/main,../../../../src/mesa/glapi,../../../../src/mesa/swrast,../../../../src/mesa/shader"
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OSMESA_EXPORTS;BUILD_GL32"
+ InlineFunctionExpansion="2"
+ OmitFramePointers="true"
+ WholeProgramOptimization="true"
+ AdditionalIncludeDirectories="../../../../include;../../../../src/mesa/drivers/dri/common;../../../../src/mesa"
+ PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;_USRDLL;SWRAST_DRI_EXPORTS;BUILD_GL32;MESA_MINWARN;IN_DRI_DRIVER;INSERVER"
StringPooling="true"
+ ExceptionHandling="0"
RuntimeLibrary="0"
+ BufferSecurityCheck="false"
EnableFunctionLevelLinking="true"
+ EnableEnhancedInstructionSet="2"
+ PrecompiledHeaderFile=".\Release/swrast_dri.pch"
WarningLevel="3"
SuppressStartupBanner="true"
CompileAs="0"
- ForcedIncludeFiles="../../../../src/mesa/main/compiler.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@@ -346,13 +349,15 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="gdi32.lib user32.lib"
- OutputFile="$(OutDir)\OSMESA32.dll"
+ AdditionalDependencies="gdi32.lib user32.lib vcxsrv.lib"
+ OutputFile="$(OutDir)\swrast_dri.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
- AdditionalLibraryDirectories="$(TargetDir)"
- ModuleDefinitionFile="..\..\..\..\src\mesa\drivers\osmesa\osmesa.def"
- ProgramDatabaseFile="$(TargetDir)OSMESA32.pdb"
+ AdditionalLibraryDirectories="$(TargetDir);&quot;..\..\..\..\..\xorg-server\obj\servrelease&quot;"
+ ProgramDatabaseFile="$(TargetDir)swrast_dri.pdb"
+ LinkTimeCodeGeneration="1"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
@@ -373,11 +378,7 @@
Name="VCAppVerifierTool"
/>
<Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
Name="VCPostBuildEventTool"
- CommandLine="if not exist ..\..\..\..\lib md ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OSMESA32.LIB&quot; ..\..\..\..\lib&#x0D;&#x0A;copy &quot;$(TargetDir)OSMESA32.DLL&quot; ..\..\..\..\lib&#x0D;&#x0A;if exist ..\..\..\..\progs\demos copy &quot;$(TargetDir)OSMESA32.DLL&quot; ..\..\..\..\progs\demos&#x0D;&#x0A;"
/>
</Configuration>
</Configurations>
@@ -389,11 +390,31 @@
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
- RelativePath="..\..\..\..\src\mesa\drivers\osmesa\osmesa.c"
+ RelativePath="..\..\..\..\src\mesa\drivers\common\driverfuncs.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\src\mesa\drivers\common\meta.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\src\mesa\main\remap.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\src\mesa\drivers\dri\swrast\swrast.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\src\mesa\drivers\dri\swrast\swrast_priv.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\src\mesa\drivers\dri\swrast\swrast_span.c"
>
</File>
<File
- RelativePath="..\..\..\..\src\mesa\drivers\osmesa\osmesa.def"
+ RelativePath="..\..\..\..\src\mesa\drivers\dri\common\utils.c"
>
</File>
</Filter>
diff --git a/mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcxproj b/mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcxproj
new file mode 100644
index 000000000..16e22f71c
--- /dev/null
+++ b/mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcxproj
@@ -0,0 +1,178 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{FEF62E6F-A7E0-47BE-99A0-2494717DBDB7}</ProjectGuid>
+ <RootNamespace>swrast_dri</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseOfMfc>false</UseOfMfc>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseOfMfc>false</UseOfMfc>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Midl>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MkTypLibCompatible>true</MkTypLibCompatible>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <TargetEnvironment>Win32</TargetEnvironment>
+ <TypeLibraryName>.\Debug/swrast_dri.tlb</TypeLibraryName>
+ </Midl>
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <AdditionalIncludeDirectories>../../../../include;../../../../src/mesa;../../../../src/glsl;../../../../src/mapi;../../../../src/mesa/main;../../../../src/mesa/shader;../../../../src/mesa/shader/slang;../../../../../include;../../../../src/mesa/drivers/dri/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>_DEBUG;DEBUG;WIN32;_DLL;SWRAST_DRI_EXPORTS;_GDI32_;BUILD_GL32;WIN32_THREADS;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE;INSERVER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <BrowseInformation>true</BrowseInformation>
+ <WarningLevel>Level3</WarningLevel>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <CompileAs>Default</CompileAs>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <Culture>0x0409</Culture>
+ </ResourceCompile>
+ <Link>
+ <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalDependencies>gdi32.lib;user32.lib;vcxsrv_dbg.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <OutputFile>$(OutDir)swrast_dri.dll</OutputFile>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <AdditionalLibraryDirectories>$(TargetDir);..\..\..\..\..\xorg-server\obj\servdebug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <ProgramDatabaseFile>$(TargetDir)swrast_dri.pdb</ProgramDatabaseFile>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ <DataExecutionPrevention>
+ </DataExecutionPrevention>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Midl>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MkTypLibCompatible>true</MkTypLibCompatible>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <TargetEnvironment>Win32</TargetEnvironment>
+ <TypeLibraryName>.\Release/swrast_dri.tlb</TypeLibraryName>
+ </Midl>
+ <ClCompile>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <OmitFramePointers>true</OmitFramePointers>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <AdditionalIncludeDirectories>../../../../include;../../../../src/mesa;../../../../src/glsl;../../../../src/mapi;../../../../src/mesa/main;../../../../src/mesa/shader;../../../../src/mesa/shader/slang;../../../../../include;../../../../src/mesa/drivers/dri/common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>NDEBUG;WIN32;_DLL;SWRAST_DRI_EXPORTS;_GDI32_;BUILD_GL32;WIN32_THREADS;MESA_MINWARN;_CRT_SECURE_NO_DEPRECATE;INSERVER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <StringPooling>true</StringPooling>
+ <ExceptionHandling>
+ </ExceptionHandling>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
+ <PrecompiledHeaderOutputFile>.\Release/swrast_dri.pch</PrecompiledHeaderOutputFile>
+ <WarningLevel>Level3</WarningLevel>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <CompileAs>Default</CompileAs>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <Culture>0x0409</Culture>
+ </ResourceCompile>
+ <Link>
+ <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalDependencies>gdi32.lib;user32.lib;vcxsrv.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <OutputFile>$(OutDir)swrast_dri.dll</OutputFile>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <AdditionalLibraryDirectories>$(TargetDir);..\..\..\..\..\xorg-server\obj\servrelease;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <ProgramDatabaseFile>$(TargetDir)swrast_dri.pdb</ProgramDatabaseFile>
+ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ <DataExecutionPrevention>
+ </DataExecutionPrevention>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\common\driverfuncs.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\common\meta.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\dri\common\drisw_util.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\dri\swrast\swrast.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\dri\swrast\swrast_span.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\dri\common\utils.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_aaline.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_aatriangle.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_accum.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_alpha.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_atifragshader.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_bitmap.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_blend.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_blit.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_clear.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_context.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_copypix.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_depth.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_drawpix.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_feedback.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_fog.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_fragprog.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_lines.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_logic.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_masking.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_points.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_readpix.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_span.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_stencil.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_texcombine.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_texfilter.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_triangle.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_zoom.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast_setup\ss_context.c" />
+ <ClCompile Include="..\..\..\..\src\mesa\swrast_setup\ss_triangle.c" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\..\src\mesa\drivers\dri\swrast\swrast_priv.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\mesa\mesa.vcxproj">
+ <Project>{2120c974-2717-4709-b44f-d6e6d0a56448}</Project>
+ <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcxproj.filters b/mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcxproj.filters
new file mode 100644
index 000000000..375cfd711
--- /dev/null
+++ b/mesalib/windows/VC8/mesa/swrast_dri/swrast_dri.vcxproj.filters
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{3f55ce52-2780-4f28-bb1f-06759ea15ba4}</UniqueIdentifier>
+ <Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{b64ef3e4-df7d-40b7-8ecd-4805cbbdc8b8}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl</Extensions>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{aaf2266b-a56e-474d-926c-d8a91f25992f}</UniqueIdentifier>
+ <Extensions>ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\common\driverfuncs.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\common\meta.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\dri\swrast\swrast.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\dri\swrast\swrast_span.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\dri\common\utils.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\drivers\dri\common\drisw_util.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast_setup\ss_context.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_context.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_lines.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_bitmap.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_accum.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_clear.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_copypix.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_drawpix.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_readpix.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_zoom.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast_setup\ss_triangle.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_masking.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_aaline.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_points.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_feedback.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_triangle.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_depth.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_texfilter.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_aatriangle.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_alpha.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_atifragshader.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_blend.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_blit.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_fog.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_fragprog.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_logic.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_span.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_stencil.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\..\src\mesa\swrast\s_texcombine.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\..\src\mesa\drivers\dri\swrast\swrast_priv.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+</Project> \ No newline at end of file