aboutsummaryrefslogtreecommitdiff
path: root/mesalib
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib')
-rw-r--r--mesalib/Makefile1038
-rw-r--r--mesalib/docs/GL3.txt238
-rw-r--r--mesalib/docs/relnotes-7.11.html155
-rw-r--r--mesalib/include/EGL/eglext.h794
-rw-r--r--mesalib/include/EGL/eglplatform.h252
-rw-r--r--mesalib/src/mesa/drivers/common/meta.c5847
-rw-r--r--mesalib/src/mesa/main/extensions.c1999
-rw-r--r--mesalib/src/mesa/main/fbobject.c5065
-rw-r--r--mesalib/src/mesa/main/formats.c3668
-rw-r--r--mesalib/src/mesa/main/formats.h531
-rw-r--r--mesalib/src/mesa/main/image.c3848
-rw-r--r--mesalib/src/mesa/main/mipmap.c4308
-rw-r--r--mesalib/src/mesa/main/pack.c10249
-rw-r--r--mesalib/src/mesa/main/texfetch.c2084
-rw-r--r--mesalib/src/mesa/main/texfetch_tmp.h4716
-rw-r--r--mesalib/src/mesa/main/texformat.c1506
-rw-r--r--mesalib/src/mesa/main/texparam.c2918
-rw-r--r--mesalib/src/mesa/main/texrender.c7
-rw-r--r--mesalib/src/mesa/main/texstore.c9860
-rw-r--r--mesalib/src/mesa/main/transformfeedback.c18
-rw-r--r--mesalib/src/mesa/main/varray.c2413
-rw-r--r--mesalib/src/mesa/program/register_allocate.c972
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_drawpixels.c3078
-rw-r--r--mesalib/src/mesa/state_tracker/st_extensions.c1177
-rw-r--r--mesalib/src/mesa/state_tracker/st_format.c3360
25 files changed, 35352 insertions, 34749 deletions
diff --git a/mesalib/Makefile b/mesalib/Makefile
index 41d1654b4..4b12dba40 100644
--- a/mesalib/Makefile
+++ b/mesalib/Makefile
@@ -1,519 +1,519 @@
-# Top-level Mesa makefile
-
-TOP = .
-
-SUBDIRS = src
-
-
-# The git command below generates an empty string when we're not
-# building in a GIT tree (i.e., building from a release tarball).
-default: $(TOP)/configs/current
- @$(TOP)/bin/extract_git_sha1
- @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)/SConstruct \
- $(DIRECTORY)/common.py \
- $(DIRECTORY)/scons/*py \
- $(DIRECTORY)/bin/config.guess \
- $(DIRECTORY)/bin/config.sub \
- $(DIRECTORY)/bin/extract_git_sha1 \
- $(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/getopt/SConscript \
- $(DIRECTORY)/src/getopt/getopt*.[ch] \
- $(DIRECTORY)/src/glsl/Makefile \
- $(DIRECTORY)/src/glsl/Makefile.template \
- $(DIRECTORY)/src/glsl/SConscript \
- $(DIRECTORY)/src/glsl/*.[ch] \
- $(DIRECTORY)/src/glsl/*.ll \
- $(DIRECTORY)/src/glsl/*.yy \
- $(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/SConscript \
- $(DIRECTORY)/src/mesa/Makefile* \
- $(DIRECTORY)/src/mesa/SConscript \
- $(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/*.cpp \
- $(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/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/vf/*.[ch] \
- $(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/dri/r300/compiler/*.[ch] \
- $(DIRECTORY)/src/mesa/drivers/dri/r300/compiler/Makefile \
- $(DIRECTORY)/src/mesa/drivers/dri/r300/compiler/SConscript \
- $(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/shared-glapi/SConscript \
- $(DIRECTORY)/src/mapi/vgapi/Makefile \
- $(DIRECTORY)/src/mapi/vgapi/SConscript \
- $(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/SConscript \
- $(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/SConscript \
- $(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
+
+
+# The git command below generates an empty string when we're not
+# building in a GIT tree (i.e., building from a release tarball).
+default: $(TOP)/configs/current
+ @$(TOP)/bin/extract_git_sha1
+ @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)/SConstruct \
+ $(DIRECTORY)/common.py \
+ $(DIRECTORY)/scons/*py \
+ $(DIRECTORY)/bin/config.guess \
+ $(DIRECTORY)/bin/config.sub \
+ $(DIRECTORY)/bin/extract_git_sha1 \
+ $(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/getopt/SConscript \
+ $(DIRECTORY)/src/getopt/getopt*.[ch] \
+ $(DIRECTORY)/src/glsl/Makefile \
+ $(DIRECTORY)/src/glsl/Makefile.template \
+ $(DIRECTORY)/src/glsl/SConscript \
+ $(DIRECTORY)/src/glsl/*.[ch] \
+ $(DIRECTORY)/src/glsl/*.ll \
+ $(DIRECTORY)/src/glsl/*.yy \
+ $(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/SConscript \
+ $(DIRECTORY)/src/mesa/Makefile* \
+ $(DIRECTORY)/src/mesa/SConscript \
+ $(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/*.cpp \
+ $(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/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/dri/r300/compiler/*.[ch] \
+ $(DIRECTORY)/src/mesa/drivers/dri/r300/compiler/Makefile \
+ $(DIRECTORY)/src/mesa/drivers/dri/r300/compiler/SConscript \
+ $(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/shared-glapi/SConscript \
+ $(DIRECTORY)/src/mapi/shared-glapi/Makefile \
+ $(DIRECTORY)/src/mapi/vgapi/Makefile \
+ $(DIRECTORY)/src/mapi/vgapi/SConscript \
+ $(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/SConscript \
+ $(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/SConscript \
+ $(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/docs/GL3.txt b/mesalib/docs/GL3.txt
index 27762b516..d57d56366 100644
--- a/mesalib/docs/GL3.txt
+++ b/mesalib/docs/GL3.txt
@@ -1,119 +1,119 @@
-
-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 1.30 (GL_EXT_gpu_shader4, etc.) started
-Conditional rendering (GL_NV_conditional_render) DONE (swrast, softpipe, i965)
-Map buffer subranges (GL_ARB_map_buffer_range) DONE
-Clamping controls (GL_ARB_color_buffer_float) DONE
-Float textures, renderbuffers (GL_ARB_texture_float) DONE (gallium r300)
-GL_EXT_packed_float started
-GL_EXT_texture_shared_exponent 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)
-Depth format cube textures 0% done
-
-
-
-GL 3.1:
-
-GLSL 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) DONE (gallium)
-
-
-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 DONE (gallium)
-GL_ARB_texture_rgb10_a2ui not started
-GL_ARB_texture_swizzle DONE (same as EXT version)
-GL_ARB_timer_query ~60% done (the EXT variant)
-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 DONE (i965)
-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 1.30 (GL_EXT_gpu_shader4, etc.) started
+Conditional rendering (GL_NV_conditional_render) DONE (swrast, softpipe, i965)
+Map buffer subranges (GL_ARB_map_buffer_range) DONE
+Clamping controls (GL_ARB_color_buffer_float) DONE
+Float textures, renderbuffers (GL_ARB_texture_float) DONE (gallium r300)
+GL_EXT_packed_float DONE (gallium r600)
+GL_EXT_texture_shared_exponent DONE (gallium, swrast)
+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)
+Depth format cube textures 0% done
+
+
+
+GL 3.1:
+
+GLSL 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) DONE (gallium)
+
+
+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 DONE (gallium)
+GL_ARB_texture_rgb10_a2ui not started
+GL_ARB_texture_swizzle DONE (same as EXT version)
+GL_ARB_timer_query ~60% done (the EXT variant)
+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 DONE (i965)
+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 3b7f9a21d..6951984bd 100644
--- a/mesalib/docs/relnotes-7.11.html
+++ b/mesalib/docs/relnotes-7.11.html
@@ -1,76 +1,79 @@
-<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_color_buffer_float (gallium drivers, i965)
-<li>GL_ARB_draw_buffers_blend (gallium)
-<li>GL_ARB_draw_instanced extension (gallium drivers, swrast)
-<li>GL_ARB_instanced_arrays extension (gallium drivers)
-<li>GL_ARB_occlusion_query2 (gallium drivers, swrast)
-<li>GL_ARB_robustness (all drivers)
-<li>GL_ARB_sampler_objects (gallium drivers)
-<li>GL_ARB_texture_compression_rgtc (gallium drivers, swrast, i965)
-<li>GL_ARB_texture_float (gallium, i965)
-<li>GL_EXT_texture_compression_latc (gallium drivers, swrast)
-<li>GL_EXT_texture_compression_rgtc (gallium drivers, swrast, i965)
-<li>GL_EXT_texture_sRGB_decode (gallium drivers, swrast, i965)
-<li>GL_EXT_texture_snorm (gallium drivers)
-<li>GL_ATI_draw_buffers (all drivers)
-<li>GL_ATI_texture_compression_3dc (gallium drivers, swrast)
-<li>GL_ATI_texture_float (gallium, i965)
-<li>GL_NV_conditional_render (i965)
-<li>GL_NV_texture_barrier (gallium drivers)
-</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 alternative.
-<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_ES2_compatibility (gallium drivers)
+<li>GL_ARB_color_buffer_float (gallium drivers, i965)
+<li>GL_ARB_draw_buffers_blend (gallium)
+<li>GL_ARB_draw_instanced extension (gallium drivers, swrast)
+<li>GL_ARB_instanced_arrays extension (gallium drivers)
+<li>GL_ARB_occlusion_query2 (gallium drivers, swrast)
+<li>GL_ARB_robustness (all drivers)
+<li>GL_ARB_sampler_objects (gallium drivers)
+<li>GL_ARB_texture_compression_rgtc (gallium drivers, swrast, i965)
+<li>GL_ARB_texture_float (gallium, i965)
+<li>GL_EXT_packed_float (gallium r600)
+<li>GL_EXT_texture_compression_latc (gallium drivers, swrast)
+<li>GL_EXT_texture_compression_rgtc (gallium drivers, swrast, i965)
+<li>GL_EXT_texture_shared_exponent (gallium drivers, swrast)
+<li>GL_EXT_texture_sRGB_decode (gallium drivers, swrast, i965)
+<li>GL_EXT_texture_snorm (gallium drivers)
+<li>GL_ATI_draw_buffers (all drivers)
+<li>GL_ATI_texture_compression_3dc (gallium drivers, swrast)
+<li>GL_ATI_texture_float (gallium, i965)
+<li>GL_NV_conditional_render (i965)
+<li>GL_NV_texture_barrier (gallium drivers)
+</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 alternative.
+<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 a93cfb556..43eff8e99 100644
--- a/mesalib/include/EGL/eglext.h
+++ b/mesalib/include/EGL/eglext.h
@@ -1,397 +1,397 @@
-#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);
-#endif
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
-#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);
+#endif
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
+#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/EGL/eglplatform.h b/mesalib/include/EGL/eglplatform.h
index b632a47fb..caa9acd40 100644
--- a/mesalib/include/EGL/eglplatform.h
+++ b/mesalib/include/EGL/eglplatform.h
@@ -1,126 +1,126 @@
-#ifndef __eglplatform_h_
-#define __eglplatform_h_
-
-/*
-** Copyright (c) 2007-2009 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.
-*/
-
-/* Platform-specific types and definitions for egl.h
- * $Revision$ on $Date: 2009-12-02 02:05:33 -0800 (Wed, 02 Dec 2009) $
- *
- * Adopters may modify khrplatform.h and this file to suit their platform.
- * You are encouraged to submit all modifications to the Khronos group so that
- * they can be included in future versions of this file. Please submit changes
- * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
- * by filing a bug against product "EGL" component "Registry".
- */
-
-#include <KHR/khrplatform.h>
-
-/* Macros used in EGL function prototype declarations.
- *
- * EGL functions should be prototyped as:
- *
- * EGLAPI return-type EGLAPIENTRY eglFunction(arguments);
- * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments);
- *
- * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h
- */
-
-#ifndef EGLAPI
-#define EGLAPI KHRONOS_APICALL
-#endif
-
-#ifndef EGLAPIENTRY
-#define EGLAPIENTRY KHRONOS_APIENTRY
-#endif
-#define EGLAPIENTRYP EGLAPIENTRY*
-
-/* The types NativeDisplayType, NativeWindowType, and NativePixmapType
- * are aliases of window-system-dependent types, such as X Display * or
- * Windows Device Context. They must be defined in platform-specific
- * code below. The EGL-prefixed versions of Native*Type are the same
- * types, renamed in EGL 1.3 so all types in the API start with "EGL".
- */
-
-#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN 1
-#endif
-#include <windows.h>
-
-typedef HDC EGLNativeDisplayType;
-typedef HBITMAP EGLNativePixmapType;
-typedef HWND EGLNativeWindowType;
-
-#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
-
-typedef int EGLNativeDisplayType;
-typedef void *EGLNativeWindowType;
-typedef void *EGLNativePixmapType;
-
-#elif defined(WL_EGL_PLATFORM)
-
-typedef struct wl_display *EGLNativeDisplayType;
-typedef struct wl_egl_pixmap *EGLNativePixmapType;
-typedef struct wl_egl_window *EGLNativeWindowType;
-
-#elif defined(__unix__) || defined(__unix)
-
-#ifdef MESA_EGL_NO_X11_HEADERS
-
-typedef void *EGLNativeDisplayType;
-typedef khronos_uint32_t EGLNativePixmapType;
-typedef khronos_uint32_t EGLNativeWindowType;
-
-#else
-
-/* X11 (tentative) */
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-
-typedef Display *EGLNativeDisplayType;
-typedef Pixmap EGLNativePixmapType;
-typedef Window EGLNativeWindowType;
-
-#endif /* MESA_EGL_NO_X11_HEADERS */
-
-#else
-#error "Platform not recognized"
-#endif
-
-/* EGL 1.2 types, renamed for consistency in EGL 1.3 */
-typedef EGLNativeDisplayType NativeDisplayType;
-typedef EGLNativePixmapType NativePixmapType;
-typedef EGLNativeWindowType NativeWindowType;
-
-
-/* Define EGLint. This must be a signed integral type large enough to contain
- * all legal attribute names and values passed into and out of EGL, whether
- * their type is boolean, bitmask, enumerant (symbolic constant), integer,
- * handle, or other. While in general a 32-bit integer will suffice, if
- * handles are 64 bit types, then EGLint should be defined as a signed 64-bit
- * integer type.
- */
-typedef khronos_int32_t EGLint;
-
-#endif /* __eglplatform_h */
+#ifndef __eglplatform_h_
+#define __eglplatform_h_
+
+/*
+** Copyright (c) 2007-2009 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.
+*/
+
+/* Platform-specific types and definitions for egl.h
+ * $Revision$ on $Date: 2009-12-02 02:05:33 -0800 (Wed, 02 Dec 2009) $
+ *
+ * Adopters may modify khrplatform.h and this file to suit their platform.
+ * You are encouraged to submit all modifications to the Khronos group so that
+ * they can be included in future versions of this file. Please submit changes
+ * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
+ * by filing a bug against product "EGL" component "Registry".
+ */
+
+#include <KHR/khrplatform.h>
+
+/* Macros used in EGL function prototype declarations.
+ *
+ * EGL functions should be prototyped as:
+ *
+ * EGLAPI return-type EGLAPIENTRY eglFunction(arguments);
+ * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments);
+ *
+ * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h
+ */
+
+#ifndef EGLAPI
+#define EGLAPI KHRONOS_APICALL
+#endif
+
+#ifndef EGLAPIENTRY
+#define EGLAPIENTRY KHRONOS_APIENTRY
+#endif
+#define EGLAPIENTRYP EGLAPIENTRY*
+
+/* The types NativeDisplayType, NativeWindowType, and NativePixmapType
+ * are aliases of window-system-dependent types, such as X Display * or
+ * Windows Device Context. They must be defined in platform-specific
+ * code below. The EGL-prefixed versions of Native*Type are the same
+ * types, renamed in EGL 1.3 so all types in the API start with "EGL".
+ */
+
+#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#include <windows.h>
+
+typedef HDC EGLNativeDisplayType;
+typedef HBITMAP EGLNativePixmapType;
+typedef HWND EGLNativeWindowType;
+
+#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
+
+typedef int EGLNativeDisplayType;
+typedef void *EGLNativeWindowType;
+typedef void *EGLNativePixmapType;
+
+#elif defined(WL_EGL_PLATFORM)
+
+typedef struct wl_display *EGLNativeDisplayType;
+typedef struct wl_egl_pixmap *EGLNativePixmapType;
+typedef struct wl_egl_window *EGLNativeWindowType;
+
+#elif defined(__unix__) || defined(__unix)
+
+#ifdef MESA_EGL_NO_X11_HEADERS
+
+typedef void *EGLNativeDisplayType;
+typedef khronos_uint32_t EGLNativePixmapType;
+typedef khronos_uint32_t EGLNativeWindowType;
+
+#else
+
+/* X11 (tentative) */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+typedef Display *EGLNativeDisplayType;
+typedef Pixmap EGLNativePixmapType;
+typedef Window EGLNativeWindowType;
+
+#endif /* MESA_EGL_NO_X11_HEADERS */
+
+#else
+#error "Platform not recognized"
+#endif
+
+/* EGL 1.2 types, renamed for consistency in EGL 1.3 */
+typedef EGLNativeDisplayType NativeDisplayType;
+typedef EGLNativePixmapType NativePixmapType;
+typedef EGLNativeWindowType NativeWindowType;
+
+
+/* Define EGLint. This must be a signed integral type large enough to contain
+ * all legal attribute names and values passed into and out of EGL, whether
+ * their type is boolean, bitmask, enumerant (symbolic constant), integer,
+ * handle, or other. While in general a 32-bit integer will suffice, if
+ * handles are 64 bit types, then EGLint should be defined as a signed 64-bit
+ * integer type.
+ */
+typedef khronos_int32_t EGLint;
+
+#endif /* __eglplatform_h */
diff --git a/mesalib/src/mesa/drivers/common/meta.c b/mesalib/src/mesa/drivers/common/meta.c
index a3964798b..06d4337f8 100644
--- a/mesalib/src/mesa/drivers/common/meta.c
+++ b/mesalib/src/mesa/drivers/common/meta.c
@@ -1,2923 +1,2924 @@
-/*
- * 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/condrender.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
-#define META_CLAMP_FRAGMENT_COLOR 0x8000
-#define META_CLAMP_VERTEX_COLOR 0x10000
-#define META_CONDITIONAL_RENDER 0x20000
-/*@}*/
-
-
-/**
- * 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;
-
- /** META_CLAMP_FRAGMENT_COLOR */
- GLenum ClampFragmentColor;
-
- /** META_CLAMP_VERTEX_COLOR */
- GLenum ClampVertexColor;
-
- /** META_CONDITIONAL_RENDER */
- struct gl_query_object *CondRenderQuery;
- GLenum CondRenderMode;
-
- /** 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);
- }
-
- if (state & META_CLAMP_FRAGMENT_COLOR) {
- save->ClampFragmentColor = ctx->Color.ClampFragmentColor;
-
- /* Generally in here we want to do clamping according to whether
- * it's for the pixel path (ClampFragmentColor is GL_TRUE),
- * regardless of the internal implementation of the metaops.
- */
- if (ctx->Color.ClampFragmentColor != GL_TRUE)
- _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE);
- }
-
- if (state & META_CLAMP_VERTEX_COLOR) {
- save->ClampVertexColor = ctx->Light.ClampVertexColor;
-
- /* Generally in here we never want vertex color clamping --
- * result clamping is only dependent on fragment clamping.
- */
- _mesa_ClampColorARB(GL_CLAMP_VERTEX_COLOR, GL_FALSE);
- }
-
- if (state & META_CONDITIONAL_RENDER) {
- save->CondRenderQuery = ctx->Query.CondRenderQuery;
- save->CondRenderMode = ctx->Query.CondRenderMode;
-
- if (ctx->Query.CondRenderQuery)
- _mesa_EndConditionalRender();
- }
-
- /* 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);
- }
-
- if (state & META_CLAMP_FRAGMENT_COLOR) {
- _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR, save->ClampFragmentColor);
- }
-
- if (state & META_CLAMP_VERTEX_COLOR) {
- _mesa_ClampColorARB(GL_CLAMP_VERTEX_COLOR, save->ClampVertexColor);
- }
-
- if (state & META_CONDITIONAL_RENDER) {
- if (save->CondRenderQuery)
- _mesa_BeginConditionalRender(save->CondRenderQuery->Id,
- save->CondRenderMode);
- }
-
- /* 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->Sampler.MinFilter;
- const GLenum magFilterSave = texObj->Sampler.MagFilter;
- const GLint baseLevelSave = texObj->BaseLevel;
- const GLint maxLevelSave = texObj->MaxLevel;
- const GLenum wrapSSave = texObj->Sampler.WrapS;
- const GLenum wrapTSave = texObj->Sampler.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 -
- META_CONDITIONAL_RENDER);
- 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 */
-
- /* Clears never have the color clamped. */
- _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE);
- }
- 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.ClearColorUnclamped[0];
- verts[i].g = ctx->Color.ClearColorUnclamped[1];
- verts[i].b = ctx->Color.ClearColorUnclamped[2];
- verts[i].a = ctx->Color.ClearColorUnclamped[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;
-
- /* If we're not supposed to clamp the resulting color, then just
- * promote our texture to fully float. We could do better by
- * just going for the matching set of channels, in floating
- * point.
- */
- if (ctx->Color.ClampFragmentColor != GL_TRUE)
- texIntFormat = GL_RGBA32F;
- }
- 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 |
- META_CLAMP_FRAGMENT_COLOR |
- 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->Sampler.MinFilter;
- const GLenum magFilterSave = texObj->Sampler.MagFilter;
- const GLint maxLevelSave = texObj->MaxLevel;
- const GLboolean genMipmapSave = texObj->GenerateMipmap;
- const GLenum wrapSSave = texObj->Sampler.WrapS;
- const GLenum wrapTSave = texObj->Sampler.WrapT;
- const GLenum wrapRSave = texObj->Sampler.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/condrender.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
+#define META_CLAMP_FRAGMENT_COLOR 0x8000
+#define META_CLAMP_VERTEX_COLOR 0x10000
+#define META_CONDITIONAL_RENDER 0x20000
+/*@}*/
+
+
+/**
+ * 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;
+
+ /** META_CLAMP_FRAGMENT_COLOR */
+ GLenum ClampFragmentColor;
+
+ /** META_CLAMP_VERTEX_COLOR */
+ GLenum ClampVertexColor;
+
+ /** META_CONDITIONAL_RENDER */
+ struct gl_query_object *CondRenderQuery;
+ GLenum CondRenderMode;
+
+ /** 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);
+ }
+
+ if (state & META_CLAMP_FRAGMENT_COLOR) {
+ save->ClampFragmentColor = ctx->Color.ClampFragmentColor;
+
+ /* Generally in here we want to do clamping according to whether
+ * it's for the pixel path (ClampFragmentColor is GL_TRUE),
+ * regardless of the internal implementation of the metaops.
+ */
+ if (ctx->Color.ClampFragmentColor != GL_TRUE)
+ _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE);
+ }
+
+ if (state & META_CLAMP_VERTEX_COLOR) {
+ save->ClampVertexColor = ctx->Light.ClampVertexColor;
+
+ /* Generally in here we never want vertex color clamping --
+ * result clamping is only dependent on fragment clamping.
+ */
+ _mesa_ClampColorARB(GL_CLAMP_VERTEX_COLOR, GL_FALSE);
+ }
+
+ if (state & META_CONDITIONAL_RENDER) {
+ save->CondRenderQuery = ctx->Query.CondRenderQuery;
+ save->CondRenderMode = ctx->Query.CondRenderMode;
+
+ if (ctx->Query.CondRenderQuery)
+ _mesa_EndConditionalRender();
+ }
+
+ /* 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);
+ }
+
+ if (state & META_CLAMP_FRAGMENT_COLOR) {
+ _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR, save->ClampFragmentColor);
+ }
+
+ if (state & META_CLAMP_VERTEX_COLOR) {
+ _mesa_ClampColorARB(GL_CLAMP_VERTEX_COLOR, save->ClampVertexColor);
+ }
+
+ if (state & META_CONDITIONAL_RENDER) {
+ if (save->CondRenderQuery)
+ _mesa_BeginConditionalRender(save->CondRenderQuery->Id,
+ save->CondRenderMode);
+ }
+
+ /* 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->Sampler.MinFilter;
+ const GLenum magFilterSave = texObj->Sampler.MagFilter;
+ const GLint baseLevelSave = texObj->BaseLevel;
+ const GLint maxLevelSave = texObj->MaxLevel;
+ const GLenum wrapSSave = texObj->Sampler.WrapS;
+ const GLenum wrapTSave = texObj->Sampler.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 -
+ META_CONDITIONAL_RENDER);
+ 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 */
+
+ /* Clears never have the color clamped. */
+ _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE);
+ }
+ 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.ClearColorUnclamped[0];
+ verts[i].g = ctx->Color.ClearColorUnclamped[1];
+ verts[i].b = ctx->Color.ClearColorUnclamped[2];
+ verts[i].a = ctx->Color.ClearColorUnclamped[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;
+
+ /* If we're not supposed to clamp the resulting color, then just
+ * promote our texture to fully float. We could do better by
+ * just going for the matching set of channels, in floating
+ * point.
+ */
+ if (ctx->Color.ClampFragmentColor != GL_TRUE &&
+ ctx->Extensions.ARB_texture_float)
+ texIntFormat = GL_RGBA32F;
+ }
+ 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 |
+ META_CLAMP_FRAGMENT_COLOR |
+ 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->Sampler.MinFilter;
+ const GLenum magFilterSave = texObj->Sampler.MagFilter;
+ const GLint maxLevelSave = texObj->MaxLevel;
+ const GLboolean genMipmapSave = texObj->GenerateMipmap;
+ const GLenum wrapSSave = texObj->Sampler.WrapS;
+ const GLenum wrapTSave = texObj->Sampler.WrapT;
+ const GLenum wrapRSave = texObj->Sampler.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/main/extensions.c b/mesalib/src/mesa/main/extensions.c
index 82474cf41..d31477731 100644
--- a/mesalib/src/mesa/main/extensions.c
+++ b/mesalib/src/mesa/main/extensions.c
@@ -1,999 +1,1000 @@
-/*
- * 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;
-
- /** Year the extension was proposed or approved. Used to sort the
- * extension string chronologically. */
- uint16_t year;
-};
-
-
-/**
- * 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, 2009 },
- { "GL_ARB_blend_func_extended", o(ARB_blend_func_extended), GL, 2009 },
- { "GL_ARB_color_buffer_float", o(ARB_color_buffer_float), GL, 2004 },
- { "GL_ARB_copy_buffer", o(ARB_copy_buffer), GL, 2008 },
- { "GL_ARB_depth_buffer_float", o(ARB_depth_buffer_float), GL, 2008 },
- { "GL_ARB_depth_clamp", o(ARB_depth_clamp), GL, 2003 },
- { "GL_ARB_depth_texture", o(ARB_depth_texture), GL, 2001 },
- { "GL_ARB_draw_buffers", o(ARB_draw_buffers), GL, 2002 },
- { "GL_ARB_draw_buffers_blend", o(ARB_draw_buffers_blend), GL, 2009 },
- { "GL_ARB_draw_elements_base_vertex", o(ARB_draw_elements_base_vertex), GL, 2009 },
- { "GL_ARB_draw_instanced", o(ARB_draw_instanced), GL, 2008 },
- { "GL_ARB_explicit_attrib_location", o(ARB_explicit_attrib_location), GL, 2009 },
- { "GL_ARB_fragment_coord_conventions", o(ARB_fragment_coord_conventions), GL, 2009 },
- { "GL_ARB_fragment_program", o(ARB_fragment_program), GL, 2002 },
- { "GL_ARB_fragment_program_shadow", o(ARB_fragment_program_shadow), GL, 2003 },
- { "GL_ARB_fragment_shader", o(ARB_fragment_shader), GL, 2002 },
- { "GL_ARB_framebuffer_object", o(ARB_framebuffer_object), GL, 2005 },
- { "GL_ARB_framebuffer_sRGB", o(EXT_framebuffer_sRGB), GL, 1998 },
- { "GL_ARB_half_float_pixel", o(ARB_half_float_pixel), GL, 2003 },
- { "GL_ARB_half_float_vertex", o(ARB_half_float_vertex), GL, 2008 },
- { "GL_ARB_instanced_arrays", o(ARB_instanced_arrays), GL, 2008 },
- { "GL_ARB_map_buffer_range", o(ARB_map_buffer_range), GL, 2008 },
- { "GL_ARB_multisample", o(ARB_multisample), GL, 1994 },
- { "GL_ARB_multitexture", o(ARB_multitexture), GL, 1998 },
- { "GL_ARB_occlusion_query2", o(ARB_occlusion_query2), GL, 2003 },
- { "GL_ARB_occlusion_query", o(ARB_occlusion_query), GL, 2001 },
- { "GL_ARB_pixel_buffer_object", o(EXT_pixel_buffer_object), GL, 2004 },
- { "GL_ARB_point_parameters", o(EXT_point_parameters), GL, 1997 },
- { "GL_ARB_point_sprite", o(ARB_point_sprite), GL, 2003 },
- { "GL_ARB_provoking_vertex", o(EXT_provoking_vertex), GL, 2009 },
- { "GL_ARB_robustness", o(dummy_true), GL, 2010 },
- { "GL_ARB_sampler_objects", o(ARB_sampler_objects), GL, 2009 },
- { "GL_ARB_seamless_cube_map", o(ARB_seamless_cube_map), GL, 2009 },
- { "GL_ARB_shader_objects", o(ARB_shader_objects), GL, 2002 },
- { "GL_ARB_shader_stencil_export", o(ARB_shader_stencil_export), GL, 2009 },
- { "GL_ARB_shading_language_100", o(ARB_shading_language_100), GL, 2003 },
- { "GL_ARB_shadow_ambient", o(ARB_shadow_ambient), GL, 2001 },
- { "GL_ARB_shadow", o(ARB_shadow), GL, 2001 },
- { "GL_ARB_sync", o(ARB_sync), GL, 2003 },
- { "GL_ARB_texture_border_clamp", o(ARB_texture_border_clamp), GL, 2000 },
- { "GL_ARB_texture_buffer_object", o(ARB_texture_buffer_object), GL, 2008 },
- { "GL_ARB_texture_compression", o(ARB_texture_compression), GL, 2000 },
- { "GL_ARB_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL, 2004 },
- { "GL_ARB_texture_cube_map", o(ARB_texture_cube_map), GL, 1999 },
- { "GL_ARB_texture_env_add", o(EXT_texture_env_add), GL, 1999 },
- { "GL_ARB_texture_env_combine", o(ARB_texture_env_combine), GL, 2001 },
- { "GL_ARB_texture_env_crossbar", o(ARB_texture_env_crossbar), GL, 2001 },
- { "GL_ARB_texture_env_dot3", o(ARB_texture_env_dot3), GL, 2001 },
- { "GL_ARB_texture_float", o(ARB_texture_float), GL, 2004 },
- { "GL_ARB_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL, 2001 },
- { "GL_ARB_texture_multisample", o(ARB_texture_multisample), GL, 2009 },
- { "GL_ARB_texture_non_power_of_two", o(ARB_texture_non_power_of_two), GL, 2003 },
- { "GL_ARB_texture_rectangle", o(NV_texture_rectangle), GL, 2004 },
- { "GL_ARB_texture_rgb10_a2ui", o(ARB_texture_rgb10_a2ui), GL, 2009 },
- { "GL_ARB_texture_rg", o(ARB_texture_rg), GL, 2008 },
- { "GL_ARB_texture_swizzle", o(EXT_texture_swizzle), GL, 2008 },
- { "GL_ARB_transform_feedback2", o(ARB_transform_feedback2), GL, 2010 },
- { "GL_ARB_transpose_matrix", o(ARB_transpose_matrix), GL, 1999 },
- { "GL_ARB_uniform_buffer_object", o(ARB_uniform_buffer_object), GL, 2002 },
- { "GL_ARB_vertex_array_bgra", o(EXT_vertex_array_bgra), GL, 2008 },
- { "GL_ARB_vertex_array_object", o(ARB_vertex_array_object), GL, 2006 },
- { "GL_ARB_vertex_buffer_object", o(ARB_vertex_buffer_object), GL, 2003 },
- { "GL_ARB_vertex_program", o(ARB_vertex_program), GL, 2002 },
- { "GL_ARB_vertex_shader", o(ARB_vertex_shader), GL, 2002 },
- { "GL_ARB_vertex_type_2_10_10_10_rev", o(ARB_vertex_type_2_10_10_10_rev), GL, 2009 },
- { "GL_ARB_window_pos", o(ARB_window_pos), GL, 2001 },
-
- /* EXT extensions */
- { "GL_EXT_abgr", o(EXT_abgr), GL, 1995 },
- { "GL_EXT_bgra", o(EXT_bgra), GL, 1995 },
- { "GL_EXT_blend_color", o(EXT_blend_color), GL, 1995 },
- { "GL_EXT_blend_equation_separate", o(EXT_blend_equation_separate), GL, 2003 },
- { "GL_EXT_blend_func_separate", o(EXT_blend_func_separate), GL, 1999 },
- { "GL_EXT_blend_logic_op", o(EXT_blend_logic_op), GL, 1995 },
- { "GL_EXT_blend_minmax", o(EXT_blend_minmax), GL | ES1 | ES2, 1995 },
- { "GL_EXT_blend_subtract", o(EXT_blend_subtract), GL, 1995 },
- { "GL_EXT_clip_volume_hint", o(EXT_clip_volume_hint), GL, 1996 },
- { "GL_EXT_compiled_vertex_array", o(EXT_compiled_vertex_array), GL, 1996 },
- { "GL_EXT_copy_texture", o(EXT_copy_texture), GL, 1995 },
- { "GL_EXT_depth_bounds_test", o(EXT_depth_bounds_test), GL, 2002 },
- { "GL_EXT_draw_buffers2", o(EXT_draw_buffers2), GL, 2006 },
- { "GL_EXT_draw_instanced", o(ARB_draw_instanced), GL, 2006 },
- { "GL_EXT_draw_range_elements", o(EXT_draw_range_elements), GL, 1997 },
- { "GL_EXT_fog_coord", o(EXT_fog_coord), GL, 1999 },
- { "GL_EXT_framebuffer_blit", o(EXT_framebuffer_blit), GL, 2005 },
- { "GL_EXT_framebuffer_multisample", o(EXT_framebuffer_multisample), GL, 2005 },
- { "GL_EXT_framebuffer_object", o(EXT_framebuffer_object), GL, 2000 },
- { "GL_EXT_framebuffer_sRGB", o(EXT_framebuffer_sRGB), GL, 1998 },
- { "GL_EXT_gpu_program_parameters", o(EXT_gpu_program_parameters), GL, 2006 },
- { "GL_EXT_gpu_shader4", o(EXT_gpu_shader4), GL, 2006 },
- { "GL_EXT_multi_draw_arrays", o(EXT_multi_draw_arrays), GL | ES1 | ES2, 1999 },
- { "GL_EXT_packed_depth_stencil", o(EXT_packed_depth_stencil), GL, 2005 },
- { "GL_EXT_packed_float", o(EXT_packed_float), GL, 2004 },
- { "GL_EXT_packed_pixels", o(EXT_packed_pixels), GL, 1997 },
- { "GL_EXT_paletted_texture", o(EXT_paletted_texture), GL, 1995 },
- { "GL_EXT_pixel_buffer_object", o(EXT_pixel_buffer_object), GL, 2004 },
- { "GL_EXT_point_parameters", o(EXT_point_parameters), GL, 1997 },
- { "GL_EXT_polygon_offset", o(EXT_polygon_offset), GL, 1995 },
- { "GL_EXT_provoking_vertex", o(EXT_provoking_vertex), GL, 2009 },
- { "GL_EXT_rescale_normal", o(EXT_rescale_normal), GL, 1997 },
- { "GL_EXT_secondary_color", o(EXT_secondary_color), GL, 1999 },
- { "GL_EXT_separate_shader_objects", o(EXT_separate_shader_objects), GL, 2008 },
- { "GL_EXT_separate_specular_color", o(EXT_separate_specular_color), GL, 1997 },
- { "GL_EXT_shadow_funcs", o(EXT_shadow_funcs), GL, 2002 },
- { "GL_EXT_shared_texture_palette", o(EXT_shared_texture_palette), GL, 2000 },
- { "GL_EXT_stencil_two_side", o(EXT_stencil_two_side), GL, 2001 },
- { "GL_EXT_stencil_wrap", o(EXT_stencil_wrap), GL, 2002 },
- { "GL_EXT_subtexture", o(EXT_subtexture), GL, 1995 },
- { "GL_EXT_texture3D", o(EXT_texture3D), GL, 1996 },
- { "GL_EXT_texture_array", o(EXT_texture_array), GL, 2006 },
- { "GL_EXT_texture_compression_dxt1", o(EXT_texture_compression_s3tc), GL | ES1 | ES2, 2004 },
- { "GL_EXT_texture_compression_latc", o(EXT_texture_compression_latc), GL, 2006 },
- { "GL_EXT_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL, 2004 },
- { "GL_EXT_texture_compression_s3tc", o(EXT_texture_compression_s3tc), GL, 2000 },
- { "GL_EXT_texture_cube_map", o(ARB_texture_cube_map), GL, 2001 },
- { "GL_EXT_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL, 1997 },
- { "GL_EXT_texture_env_add", o(EXT_texture_env_add), GL, 1999 },
- { "GL_EXT_texture_env_combine", o(EXT_texture_env_combine), GL, 2006 },
- { "GL_EXT_texture_env_dot3", o(EXT_texture_env_dot3), GL, 2000 },
- { "GL_EXT_texture_filter_anisotropic", o(EXT_texture_filter_anisotropic), GL | ES1 | ES2, 1999 },
- { "GL_EXT_texture_format_BGRA8888", o(EXT_texture_format_BGRA8888), ES1 | ES2, 2009 },
- { "GL_EXT_texture_integer", o(EXT_texture_integer), GL, 2006 },
- { "GL_EXT_texture_lod_bias", o(EXT_texture_lod_bias), GL | ES1, 1999 },
- { "GL_EXT_texture_mirror_clamp", o(EXT_texture_mirror_clamp), GL, 2004 },
- { "GL_EXT_texture_object", o(EXT_texture_object), GL, 1995 },
- { "GL_EXT_texture", o(EXT_texture), GL, 1996 },
- { "GL_EXT_texture_rectangle", o(NV_texture_rectangle), GL, 2004 },
- { "GL_EXT_texture_shared_exponent", o(EXT_texture_shared_exponent), GL, 2004 },
- { "GL_EXT_texture_snorm", o(EXT_texture_snorm), GL, 2009 },
- { "GL_EXT_texture_sRGB", o(EXT_texture_sRGB), GL, 2004 },
- { "GL_EXT_texture_sRGB_decode", o(EXT_texture_sRGB_decode), GL, 2006 },
- { "GL_EXT_texture_swizzle", o(EXT_texture_swizzle), GL, 2008 },
- { "GL_EXT_texture_type_2_10_10_10_REV", o(dummy_true), ES2, 2008 },
- { "GL_EXT_timer_query", o(EXT_timer_query), GL, 2006 },
- { "GL_EXT_transform_feedback", o(EXT_transform_feedback), GL, 2011 },
- { "GL_EXT_vertex_array_bgra", o(EXT_vertex_array_bgra), GL, 2008 },
- { "GL_EXT_vertex_array", o(EXT_vertex_array), GL, 1995 },
- { "GL_EXT_vertex_array_set", o(EXT_vertex_array_set), GL, 1997 },
-
- /* OES extensions */
- { "GL_OES_blend_equation_separate", o(EXT_blend_equation_separate), ES1, 2009 },
- { "GL_OES_blend_func_separate", o(EXT_blend_func_separate), ES1, 2009 },
- { "GL_OES_blend_subtract", o(EXT_blend_subtract), ES1, 2009 },
- { "GL_OES_byte_coordinates", o(dummy_true), ES1, 2002 },
- { "GL_OES_compressed_paletted_texture", o(dummy_false), DISABLE, 2003 },
- { "GL_OES_depth24", o(EXT_framebuffer_object), ES1 | ES2, 2005 },
- { "GL_OES_depth32", o(dummy_false), DISABLE, 2005 },
- { "GL_OES_depth_texture", o(ARB_depth_texture), ES2, 2006 },
-#if FEATURE_OES_draw_texture
- { "GL_OES_draw_texture", o(OES_draw_texture), ES1 | ES2, 2004 },
-#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, 2006 },
-#endif
- { "GL_OES_element_index_uint", o(EXT_vertex_array), ES1 | ES2, 2005 },
- { "GL_OES_fbo_render_mipmap", o(EXT_framebuffer_object), ES1 | ES2, 2005 },
- { "GL_OES_fixed_point", o(dummy_true), ES1, 2002 },
- { "GL_OES_framebuffer_object", o(EXT_framebuffer_object), ES1, 2005 },
- { "GL_OES_mapbuffer", o(ARB_vertex_buffer_object), ES1 | ES2, 2005 },
- { "GL_OES_matrix_get", o(dummy_true), ES1, 2004 },
- { "GL_OES_packed_depth_stencil", o(EXT_packed_depth_stencil), ES1 | ES2, 2007 },
- { "GL_OES_point_size_array", o(dummy_true), ES1, 2004 },
- { "GL_OES_point_sprite", o(ARB_point_sprite), ES1, 2004 },
- { "GL_OES_query_matrix", o(dummy_true), ES1, 2003 },
- { "GL_OES_read_format", o(OES_read_format), GL | ES1, 2003 },
- { "GL_OES_rgb8_rgba8", o(EXT_framebuffer_object), ES1 | ES2, 2005 },
- { "GL_OES_single_precision", o(dummy_true), ES1, 2003 },
- { "GL_OES_standard_derivatives", o(OES_standard_derivatives), ES2, 2005 },
- { "GL_OES_stencil1", o(dummy_false), DISABLE, 2005 },
- { "GL_OES_stencil4", o(dummy_false), DISABLE, 2005 },
- { "GL_OES_stencil8", o(EXT_framebuffer_object), ES1 | ES2, 2005 },
- { "GL_OES_stencil_wrap", o(EXT_stencil_wrap), ES1, 2002 },
- { "GL_OES_texture_3D", o(EXT_texture3D), ES2, 2005 },
- { "GL_OES_texture_cube_map", o(ARB_texture_cube_map), ES1, 2007 },
- { "GL_OES_texture_env_crossbar", o(ARB_texture_env_crossbar), ES1, 2005 },
- { "GL_OES_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), ES1, 2005 },
- { "GL_OES_texture_npot", o(ARB_texture_non_power_of_two), ES2, 2005 },
-
- /* Vendor extensions */
- { "GL_3DFX_texture_compression_FXT1", o(TDFX_texture_compression_FXT1), GL, 1999 },
- { "GL_AMD_conservative_depth", o(AMD_conservative_depth), GL, 2009 },
- { "GL_APPLE_client_storage", o(APPLE_client_storage), GL, 2002 },
- { "GL_APPLE_object_purgeable", o(APPLE_object_purgeable), GL, 2006 },
- { "GL_APPLE_packed_pixels", o(APPLE_packed_pixels), GL, 2002 },
- { "GL_APPLE_vertex_array_object", o(APPLE_vertex_array_object), GL, 2002 },
- { "GL_ATI_blend_equation_separate", o(EXT_blend_equation_separate), GL, 2003 },
- { "GL_ATI_draw_buffers", o(ARB_draw_buffers), GL, 2002 },
- { "GL_ATI_envmap_bumpmap", o(ATI_envmap_bumpmap), GL, 2001 },
- { "GL_ATI_fragment_shader", o(ATI_fragment_shader), GL, 2001 },
- { "GL_ATI_separate_stencil", o(ATI_separate_stencil), GL, 2006 },
- { "GL_ATI_texture_compression_3dc", o(ATI_texture_compression_3dc), GL, 2004 },
- { "GL_ATI_texture_env_combine3", o(ATI_texture_env_combine3), GL, 2002 },
- { "GL_ATI_texture_float", o(ARB_texture_float), GL, 2002 },
- { "GL_ATI_texture_mirror_once", o(ATI_texture_mirror_once), GL, 2006 },
- { "GL_IBM_multimode_draw_arrays", o(IBM_multimode_draw_arrays), GL, 1998 },
- { "GL_IBM_rasterpos_clip", o(IBM_rasterpos_clip), GL, 1996 },
- { "GL_IBM_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL, 1998 },
- { "GL_INGR_blend_func_separate", o(EXT_blend_func_separate), GL, 1999 },
- { "GL_MESA_pack_invert", o(MESA_pack_invert), GL, 2002 },
- { "GL_MESA_resize_buffers", o(MESA_resize_buffers), GL, 1999 },
- { "GL_MESA_texture_array", o(MESA_texture_array), GL, 2007 },
- { "GL_MESA_texture_signed_rgba", o(EXT_texture_snorm), GL, 2009 },
- { "GL_MESA_window_pos", o(ARB_window_pos), GL, 2000 },
- { "GL_MESA_ycbcr_texture", o(MESA_ycbcr_texture), GL, 2002 },
- { "GL_NV_blend_square", o(NV_blend_square), GL, 1999 },
- { "GL_NV_conditional_render", o(NV_conditional_render), GL, 2008 },
- { "GL_NV_depth_clamp", o(ARB_depth_clamp), GL, 2001 },
- { "GL_NV_fragment_program", o(NV_fragment_program), GL, 2001 },
- { "GL_NV_fragment_program_option", o(NV_fragment_program_option), GL, 2005 },
- { "GL_NV_light_max_exponent", o(NV_light_max_exponent), GL, 1999 },
- { "GL_NV_packed_depth_stencil", o(EXT_packed_depth_stencil), GL, 2000 },
- { "GL_NV_point_sprite", o(NV_point_sprite), GL, 2001 },
- { "GL_NV_primitive_restart", o(NV_primitive_restart), GL, 2002 },
- { "GL_NV_texgen_reflection", o(NV_texgen_reflection), GL, 1999 },
- { "GL_NV_texture_barrier", o(NV_texture_barrier), GL, 2009 },
- { "GL_NV_texture_env_combine4", o(NV_texture_env_combine4), GL, 1999 },
- { "GL_NV_texture_rectangle", o(NV_texture_rectangle), GL, 2000 },
- { "GL_NV_vertex_program1_1", o(NV_vertex_program1_1), GL, 2001 },
- { "GL_NV_vertex_program", o(NV_vertex_program), GL, 2000 },
- { "GL_S3_s3tc", o(S3_s3tc), GL, 1999 },
- { "GL_SGIS_generate_mipmap", o(SGIS_generate_mipmap), GL, 1997 },
- { "GL_SGIS_texture_border_clamp", o(ARB_texture_border_clamp), GL, 1997 },
- { "GL_SGIS_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL, 1997 },
- { "GL_SGIS_texture_lod", o(SGIS_texture_lod), GL, 1997 },
- { "GL_SUN_multi_draw_arrays", o(EXT_multi_draw_arrays), GL, 1999 },
-
- { 0, 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_compression_3dc = GL_TRUE;
- 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_compression_latc = 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;
-}
-
-
-typedef unsigned short extension_index;
-
-
-/**
- * Compare two entries of the extensions table. Sorts first by year,
- * then by name.
- *
- * Arguments are indices into extension_table.
- */
-static int
-extension_compare(const void *p1, const void *p2)
-{
- extension_index i1 = * (const extension_index *) p1;
- extension_index i2 = * (const extension_index *) p2;
- const struct extension *e1 = &extension_table[i1];
- const struct extension *e2 = &extension_table[i2];
- int res;
-
- res = (int)e1->year - (int)e2->year;
-
- if (res == 0) {
- res = strcmp(e1->name, e2->name);
- }
-
- return res;
-}
-
-
-/**
- * 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;
- /* Number of extensions */
- unsigned count;
- /* Indices of the extensions sorted by year */
- extension_index *extension_indices;
- /* String of extra extensions. */
- char *extra_extensions = get_extension_override(ctx);
- GLboolean *base = (GLboolean *) &ctx->Extensions;
- const struct extension *i;
- unsigned j;
- unsigned maxYear = ~0;
-
- /* Check if the MESA_EXTENSION_MAX_YEAR env var is set */
- {
- const char *env = getenv("MESA_EXTENSION_MAX_YEAR");
- if (env) {
- maxYear = atoi(env);
- _mesa_debug(ctx, "Note: limiting GL extensions to %u or earlier\n",
- maxYear);
- }
- }
-
- /* Compute length of the extension string. */
- count = 0;
- for (i = extension_table; i->name != 0; ++i) {
- if (base[i->offset] &&
- i->year <= maxYear &&
- (i->api_set & (1 << ctx->API))) {
- length += strlen(i->name) + 1; /* +1 for space */
- ++count;
- }
- }
- 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;
- }
-
- extension_indices = malloc(count * sizeof(extension_index));
- if (extension_indices == NULL) {
- free(exts);
- free(extra_extensions);
- return NULL;
- }
-
- /* Sort extensions in chronological order because certain old applications (e.g.,
- * Quake3 demo) store the extension list in a static size buffer so chronologically
- * order ensure that the extensions that such applications expect will fit into
- * that buffer.
- */
- j = 0;
- for (i = extension_table; i->name != 0; ++i) {
- if (base[i->offset] &&
- i->year <= maxYear &&
- (i->api_set & (1 << ctx->API))) {
- extension_indices[j++] = i - extension_table;
- }
- }
- assert(j == count);
- qsort(extension_indices, count, sizeof *extension_indices, extension_compare);
-
- /* Build the extension string.*/
- for (j = 0; j < count; ++j) {
- i = &extension_table[extension_indices[j]];
- assert(base[i->offset] && (i->api_set & (1 << ctx->API)));
- strcat(exts, i->name);
- strcat(exts, " ");
- }
- free(extension_indices);
- 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;
+
+ /** Year the extension was proposed or approved. Used to sort the
+ * extension string chronologically. */
+ uint16_t year;
+};
+
+
+/**
+ * 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, 2009 },
+ { "GL_ARB_blend_func_extended", o(ARB_blend_func_extended), GL, 2009 },
+ { "GL_ARB_color_buffer_float", o(ARB_color_buffer_float), GL, 2004 },
+ { "GL_ARB_copy_buffer", o(ARB_copy_buffer), GL, 2008 },
+ { "GL_ARB_depth_buffer_float", o(ARB_depth_buffer_float), GL, 2008 },
+ { "GL_ARB_depth_clamp", o(ARB_depth_clamp), GL, 2003 },
+ { "GL_ARB_depth_texture", o(ARB_depth_texture), GL, 2001 },
+ { "GL_ARB_draw_buffers", o(ARB_draw_buffers), GL, 2002 },
+ { "GL_ARB_draw_buffers_blend", o(ARB_draw_buffers_blend), GL, 2009 },
+ { "GL_ARB_draw_elements_base_vertex", o(ARB_draw_elements_base_vertex), GL, 2009 },
+ { "GL_ARB_draw_instanced", o(ARB_draw_instanced), GL, 2008 },
+ { "GL_ARB_explicit_attrib_location", o(ARB_explicit_attrib_location), GL, 2009 },
+ { "GL_ARB_fragment_coord_conventions", o(ARB_fragment_coord_conventions), GL, 2009 },
+ { "GL_ARB_fragment_program", o(ARB_fragment_program), GL, 2002 },
+ { "GL_ARB_fragment_program_shadow", o(ARB_fragment_program_shadow), GL, 2003 },
+ { "GL_ARB_fragment_shader", o(ARB_fragment_shader), GL, 2002 },
+ { "GL_ARB_framebuffer_object", o(ARB_framebuffer_object), GL, 2005 },
+ { "GL_ARB_framebuffer_sRGB", o(EXT_framebuffer_sRGB), GL, 1998 },
+ { "GL_ARB_half_float_pixel", o(ARB_half_float_pixel), GL, 2003 },
+ { "GL_ARB_half_float_vertex", o(ARB_half_float_vertex), GL, 2008 },
+ { "GL_ARB_instanced_arrays", o(ARB_instanced_arrays), GL, 2008 },
+ { "GL_ARB_map_buffer_range", o(ARB_map_buffer_range), GL, 2008 },
+ { "GL_ARB_multisample", o(ARB_multisample), GL, 1994 },
+ { "GL_ARB_multitexture", o(ARB_multitexture), GL, 1998 },
+ { "GL_ARB_occlusion_query2", o(ARB_occlusion_query2), GL, 2003 },
+ { "GL_ARB_occlusion_query", o(ARB_occlusion_query), GL, 2001 },
+ { "GL_ARB_pixel_buffer_object", o(EXT_pixel_buffer_object), GL, 2004 },
+ { "GL_ARB_point_parameters", o(EXT_point_parameters), GL, 1997 },
+ { "GL_ARB_point_sprite", o(ARB_point_sprite), GL, 2003 },
+ { "GL_ARB_provoking_vertex", o(EXT_provoking_vertex), GL, 2009 },
+ { "GL_ARB_robustness", o(dummy_true), GL, 2010 },
+ { "GL_ARB_sampler_objects", o(ARB_sampler_objects), GL, 2009 },
+ { "GL_ARB_seamless_cube_map", o(ARB_seamless_cube_map), GL, 2009 },
+ { "GL_ARB_shader_objects", o(ARB_shader_objects), GL, 2002 },
+ { "GL_ARB_shader_stencil_export", o(ARB_shader_stencil_export), GL, 2009 },
+ { "GL_ARB_shading_language_100", o(ARB_shading_language_100), GL, 2003 },
+ { "GL_ARB_shadow_ambient", o(ARB_shadow_ambient), GL, 2001 },
+ { "GL_ARB_shadow", o(ARB_shadow), GL, 2001 },
+ { "GL_ARB_sync", o(ARB_sync), GL, 2003 },
+ { "GL_ARB_texture_border_clamp", o(ARB_texture_border_clamp), GL, 2000 },
+ { "GL_ARB_texture_buffer_object", o(ARB_texture_buffer_object), GL, 2008 },
+ { "GL_ARB_texture_compression", o(ARB_texture_compression), GL, 2000 },
+ { "GL_ARB_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL, 2004 },
+ { "GL_ARB_texture_cube_map", o(ARB_texture_cube_map), GL, 1999 },
+ { "GL_ARB_texture_env_add", o(EXT_texture_env_add), GL, 1999 },
+ { "GL_ARB_texture_env_combine", o(ARB_texture_env_combine), GL, 2001 },
+ { "GL_ARB_texture_env_crossbar", o(ARB_texture_env_crossbar), GL, 2001 },
+ { "GL_ARB_texture_env_dot3", o(ARB_texture_env_dot3), GL, 2001 },
+ { "GL_ARB_texture_float", o(ARB_texture_float), GL, 2004 },
+ { "GL_ARB_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL, 2001 },
+ { "GL_ARB_texture_multisample", o(ARB_texture_multisample), GL, 2009 },
+ { "GL_ARB_texture_non_power_of_two", o(ARB_texture_non_power_of_two), GL, 2003 },
+ { "GL_ARB_texture_rectangle", o(NV_texture_rectangle), GL, 2004 },
+ { "GL_ARB_texture_rgb10_a2ui", o(ARB_texture_rgb10_a2ui), GL, 2009 },
+ { "GL_ARB_texture_rg", o(ARB_texture_rg), GL, 2008 },
+ { "GL_ARB_texture_swizzle", o(EXT_texture_swizzle), GL, 2008 },
+ { "GL_ARB_transform_feedback2", o(ARB_transform_feedback2), GL, 2010 },
+ { "GL_ARB_transpose_matrix", o(ARB_transpose_matrix), GL, 1999 },
+ { "GL_ARB_uniform_buffer_object", o(ARB_uniform_buffer_object), GL, 2002 },
+ { "GL_ARB_vertex_array_bgra", o(EXT_vertex_array_bgra), GL, 2008 },
+ { "GL_ARB_vertex_array_object", o(ARB_vertex_array_object), GL, 2006 },
+ { "GL_ARB_vertex_buffer_object", o(ARB_vertex_buffer_object), GL, 2003 },
+ { "GL_ARB_vertex_program", o(ARB_vertex_program), GL, 2002 },
+ { "GL_ARB_vertex_shader", o(ARB_vertex_shader), GL, 2002 },
+ { "GL_ARB_vertex_type_2_10_10_10_rev", o(ARB_vertex_type_2_10_10_10_rev), GL, 2009 },
+ { "GL_ARB_window_pos", o(ARB_window_pos), GL, 2001 },
+
+ /* EXT extensions */
+ { "GL_EXT_abgr", o(EXT_abgr), GL, 1995 },
+ { "GL_EXT_bgra", o(EXT_bgra), GL, 1995 },
+ { "GL_EXT_blend_color", o(EXT_blend_color), GL, 1995 },
+ { "GL_EXT_blend_equation_separate", o(EXT_blend_equation_separate), GL, 2003 },
+ { "GL_EXT_blend_func_separate", o(EXT_blend_func_separate), GL, 1999 },
+ { "GL_EXT_blend_logic_op", o(EXT_blend_logic_op), GL, 1995 },
+ { "GL_EXT_blend_minmax", o(EXT_blend_minmax), GL | ES1 | ES2, 1995 },
+ { "GL_EXT_blend_subtract", o(EXT_blend_subtract), GL, 1995 },
+ { "GL_EXT_clip_volume_hint", o(EXT_clip_volume_hint), GL, 1996 },
+ { "GL_EXT_compiled_vertex_array", o(EXT_compiled_vertex_array), GL, 1996 },
+ { "GL_EXT_copy_texture", o(EXT_copy_texture), GL, 1995 },
+ { "GL_EXT_depth_bounds_test", o(EXT_depth_bounds_test), GL, 2002 },
+ { "GL_EXT_draw_buffers2", o(EXT_draw_buffers2), GL, 2006 },
+ { "GL_EXT_draw_instanced", o(ARB_draw_instanced), GL, 2006 },
+ { "GL_EXT_draw_range_elements", o(EXT_draw_range_elements), GL, 1997 },
+ { "GL_EXT_fog_coord", o(EXT_fog_coord), GL, 1999 },
+ { "GL_EXT_framebuffer_blit", o(EXT_framebuffer_blit), GL, 2005 },
+ { "GL_EXT_framebuffer_multisample", o(EXT_framebuffer_multisample), GL, 2005 },
+ { "GL_EXT_framebuffer_object", o(EXT_framebuffer_object), GL, 2000 },
+ { "GL_EXT_framebuffer_sRGB", o(EXT_framebuffer_sRGB), GL, 1998 },
+ { "GL_EXT_gpu_program_parameters", o(EXT_gpu_program_parameters), GL, 2006 },
+ { "GL_EXT_gpu_shader4", o(EXT_gpu_shader4), GL, 2006 },
+ { "GL_EXT_multi_draw_arrays", o(EXT_multi_draw_arrays), GL | ES1 | ES2, 1999 },
+ { "GL_EXT_packed_depth_stencil", o(EXT_packed_depth_stencil), GL, 2005 },
+ { "GL_EXT_packed_float", o(EXT_packed_float), GL, 2004 },
+ { "GL_EXT_packed_pixels", o(EXT_packed_pixels), GL, 1997 },
+ { "GL_EXT_paletted_texture", o(EXT_paletted_texture), GL, 1995 },
+ { "GL_EXT_pixel_buffer_object", o(EXT_pixel_buffer_object), GL, 2004 },
+ { "GL_EXT_point_parameters", o(EXT_point_parameters), GL, 1997 },
+ { "GL_EXT_polygon_offset", o(EXT_polygon_offset), GL, 1995 },
+ { "GL_EXT_provoking_vertex", o(EXT_provoking_vertex), GL, 2009 },
+ { "GL_EXT_rescale_normal", o(EXT_rescale_normal), GL, 1997 },
+ { "GL_EXT_secondary_color", o(EXT_secondary_color), GL, 1999 },
+ { "GL_EXT_separate_shader_objects", o(EXT_separate_shader_objects), GL, 2008 },
+ { "GL_EXT_separate_specular_color", o(EXT_separate_specular_color), GL, 1997 },
+ { "GL_EXT_shadow_funcs", o(EXT_shadow_funcs), GL, 2002 },
+ { "GL_EXT_shared_texture_palette", o(EXT_shared_texture_palette), GL, 2000 },
+ { "GL_EXT_stencil_two_side", o(EXT_stencil_two_side), GL, 2001 },
+ { "GL_EXT_stencil_wrap", o(EXT_stencil_wrap), GL, 2002 },
+ { "GL_EXT_subtexture", o(EXT_subtexture), GL, 1995 },
+ { "GL_EXT_texture3D", o(EXT_texture3D), GL, 1996 },
+ { "GL_EXT_texture_array", o(EXT_texture_array), GL, 2006 },
+ { "GL_EXT_texture_compression_dxt1", o(EXT_texture_compression_s3tc), GL | ES1 | ES2, 2004 },
+ { "GL_EXT_texture_compression_latc", o(EXT_texture_compression_latc), GL, 2006 },
+ { "GL_EXT_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL, 2004 },
+ { "GL_EXT_texture_compression_s3tc", o(EXT_texture_compression_s3tc), GL, 2000 },
+ { "GL_EXT_texture_cube_map", o(ARB_texture_cube_map), GL, 2001 },
+ { "GL_EXT_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL, 1997 },
+ { "GL_EXT_texture_env_add", o(EXT_texture_env_add), GL, 1999 },
+ { "GL_EXT_texture_env_combine", o(EXT_texture_env_combine), GL, 2006 },
+ { "GL_EXT_texture_env_dot3", o(EXT_texture_env_dot3), GL, 2000 },
+ { "GL_EXT_texture_filter_anisotropic", o(EXT_texture_filter_anisotropic), GL | ES1 | ES2, 1999 },
+ { "GL_EXT_texture_format_BGRA8888", o(EXT_texture_format_BGRA8888), ES1 | ES2, 2009 },
+ { "GL_EXT_texture_integer", o(EXT_texture_integer), GL, 2006 },
+ { "GL_EXT_texture_lod_bias", o(EXT_texture_lod_bias), GL | ES1, 1999 },
+ { "GL_EXT_texture_mirror_clamp", o(EXT_texture_mirror_clamp), GL, 2004 },
+ { "GL_EXT_texture_object", o(EXT_texture_object), GL, 1995 },
+ { "GL_EXT_texture", o(EXT_texture), GL, 1996 },
+ { "GL_EXT_texture_rectangle", o(NV_texture_rectangle), GL, 2004 },
+ { "GL_EXT_texture_shared_exponent", o(EXT_texture_shared_exponent), GL, 2004 },
+ { "GL_EXT_texture_snorm", o(EXT_texture_snorm), GL, 2009 },
+ { "GL_EXT_texture_sRGB", o(EXT_texture_sRGB), GL, 2004 },
+ { "GL_EXT_texture_sRGB_decode", o(EXT_texture_sRGB_decode), GL, 2006 },
+ { "GL_EXT_texture_swizzle", o(EXT_texture_swizzle), GL, 2008 },
+ { "GL_EXT_texture_type_2_10_10_10_REV", o(dummy_true), ES2, 2008 },
+ { "GL_EXT_timer_query", o(EXT_timer_query), GL, 2006 },
+ { "GL_EXT_transform_feedback", o(EXT_transform_feedback), GL, 2011 },
+ { "GL_EXT_vertex_array_bgra", o(EXT_vertex_array_bgra), GL, 2008 },
+ { "GL_EXT_vertex_array", o(EXT_vertex_array), GL, 1995 },
+ { "GL_EXT_vertex_array_set", o(EXT_vertex_array_set), GL, 1997 },
+
+ /* OES extensions */
+ { "GL_OES_blend_equation_separate", o(EXT_blend_equation_separate), ES1, 2009 },
+ { "GL_OES_blend_func_separate", o(EXT_blend_func_separate), ES1, 2009 },
+ { "GL_OES_blend_subtract", o(EXT_blend_subtract), ES1, 2009 },
+ { "GL_OES_byte_coordinates", o(dummy_true), ES1, 2002 },
+ { "GL_OES_compressed_paletted_texture", o(dummy_false), DISABLE, 2003 },
+ { "GL_OES_depth24", o(EXT_framebuffer_object), ES1 | ES2, 2005 },
+ { "GL_OES_depth32", o(dummy_false), DISABLE, 2005 },
+ { "GL_OES_depth_texture", o(ARB_depth_texture), ES2, 2006 },
+#if FEATURE_OES_draw_texture
+ { "GL_OES_draw_texture", o(OES_draw_texture), ES1 | ES2, 2004 },
+#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, 2006 },
+#endif
+ { "GL_OES_element_index_uint", o(EXT_vertex_array), ES1 | ES2, 2005 },
+ { "GL_OES_fbo_render_mipmap", o(EXT_framebuffer_object), ES1 | ES2, 2005 },
+ { "GL_OES_fixed_point", o(dummy_true), ES1, 2002 },
+ { "GL_OES_framebuffer_object", o(EXT_framebuffer_object), ES1, 2005 },
+ { "GL_OES_mapbuffer", o(ARB_vertex_buffer_object), ES1 | ES2, 2005 },
+ { "GL_OES_matrix_get", o(dummy_true), ES1, 2004 },
+ { "GL_OES_packed_depth_stencil", o(EXT_packed_depth_stencil), ES1 | ES2, 2007 },
+ { "GL_OES_point_size_array", o(dummy_true), ES1, 2004 },
+ { "GL_OES_point_sprite", o(ARB_point_sprite), ES1, 2004 },
+ { "GL_OES_query_matrix", o(dummy_true), ES1, 2003 },
+ { "GL_OES_read_format", o(OES_read_format), GL | ES1, 2003 },
+ { "GL_OES_rgb8_rgba8", o(EXT_framebuffer_object), ES1 | ES2, 2005 },
+ { "GL_OES_single_precision", o(dummy_true), ES1, 2003 },
+ { "GL_OES_standard_derivatives", o(OES_standard_derivatives), ES2, 2005 },
+ { "GL_OES_stencil1", o(dummy_false), DISABLE, 2005 },
+ { "GL_OES_stencil4", o(dummy_false), DISABLE, 2005 },
+ { "GL_OES_stencil8", o(EXT_framebuffer_object), ES1 | ES2, 2005 },
+ { "GL_OES_stencil_wrap", o(EXT_stencil_wrap), ES1, 2002 },
+ { "GL_OES_texture_3D", o(EXT_texture3D), ES2, 2005 },
+ { "GL_OES_texture_cube_map", o(ARB_texture_cube_map), ES1, 2007 },
+ { "GL_OES_texture_env_crossbar", o(ARB_texture_env_crossbar), ES1, 2005 },
+ { "GL_OES_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), ES1, 2005 },
+ { "GL_OES_texture_npot", o(ARB_texture_non_power_of_two), ES2, 2005 },
+
+ /* Vendor extensions */
+ { "GL_3DFX_texture_compression_FXT1", o(TDFX_texture_compression_FXT1), GL, 1999 },
+ { "GL_AMD_conservative_depth", o(AMD_conservative_depth), GL, 2009 },
+ { "GL_APPLE_client_storage", o(APPLE_client_storage), GL, 2002 },
+ { "GL_APPLE_object_purgeable", o(APPLE_object_purgeable), GL, 2006 },
+ { "GL_APPLE_packed_pixels", o(APPLE_packed_pixels), GL, 2002 },
+ { "GL_APPLE_vertex_array_object", o(APPLE_vertex_array_object), GL, 2002 },
+ { "GL_ATI_blend_equation_separate", o(EXT_blend_equation_separate), GL, 2003 },
+ { "GL_ATI_draw_buffers", o(ARB_draw_buffers), GL, 2002 },
+ { "GL_ATI_envmap_bumpmap", o(ATI_envmap_bumpmap), GL, 2001 },
+ { "GL_ATI_fragment_shader", o(ATI_fragment_shader), GL, 2001 },
+ { "GL_ATI_separate_stencil", o(ATI_separate_stencil), GL, 2006 },
+ { "GL_ATI_texture_compression_3dc", o(ATI_texture_compression_3dc), GL, 2004 },
+ { "GL_ATI_texture_env_combine3", o(ATI_texture_env_combine3), GL, 2002 },
+ { "GL_ATI_texture_float", o(ARB_texture_float), GL, 2002 },
+ { "GL_ATI_texture_mirror_once", o(ATI_texture_mirror_once), GL, 2006 },
+ { "GL_IBM_multimode_draw_arrays", o(IBM_multimode_draw_arrays), GL, 1998 },
+ { "GL_IBM_rasterpos_clip", o(IBM_rasterpos_clip), GL, 1996 },
+ { "GL_IBM_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL, 1998 },
+ { "GL_INGR_blend_func_separate", o(EXT_blend_func_separate), GL, 1999 },
+ { "GL_MESA_pack_invert", o(MESA_pack_invert), GL, 2002 },
+ { "GL_MESA_resize_buffers", o(MESA_resize_buffers), GL, 1999 },
+ { "GL_MESA_texture_array", o(MESA_texture_array), GL, 2007 },
+ { "GL_MESA_texture_signed_rgba", o(EXT_texture_snorm), GL, 2009 },
+ { "GL_MESA_window_pos", o(ARB_window_pos), GL, 2000 },
+ { "GL_MESA_ycbcr_texture", o(MESA_ycbcr_texture), GL, 2002 },
+ { "GL_NV_blend_square", o(NV_blend_square), GL, 1999 },
+ { "GL_NV_conditional_render", o(NV_conditional_render), GL, 2008 },
+ { "GL_NV_depth_clamp", o(ARB_depth_clamp), GL, 2001 },
+ { "GL_NV_fragment_program", o(NV_fragment_program), GL, 2001 },
+ { "GL_NV_fragment_program_option", o(NV_fragment_program_option), GL, 2005 },
+ { "GL_NV_light_max_exponent", o(NV_light_max_exponent), GL, 1999 },
+ { "GL_NV_packed_depth_stencil", o(EXT_packed_depth_stencil), GL, 2000 },
+ { "GL_NV_point_sprite", o(NV_point_sprite), GL, 2001 },
+ { "GL_NV_primitive_restart", o(NV_primitive_restart), GL, 2002 },
+ { "GL_NV_texgen_reflection", o(NV_texgen_reflection), GL, 1999 },
+ { "GL_NV_texture_barrier", o(NV_texture_barrier), GL, 2009 },
+ { "GL_NV_texture_env_combine4", o(NV_texture_env_combine4), GL, 1999 },
+ { "GL_NV_texture_rectangle", o(NV_texture_rectangle), GL, 2000 },
+ { "GL_NV_vertex_program1_1", o(NV_vertex_program1_1), GL, 2001 },
+ { "GL_NV_vertex_program", o(NV_vertex_program), GL, 2000 },
+ { "GL_S3_s3tc", o(S3_s3tc), GL, 1999 },
+ { "GL_SGIS_generate_mipmap", o(SGIS_generate_mipmap), GL, 1997 },
+ { "GL_SGIS_texture_border_clamp", o(ARB_texture_border_clamp), GL, 1997 },
+ { "GL_SGIS_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL, 1997 },
+ { "GL_SGIS_texture_lod", o(SGIS_texture_lod), GL, 1997 },
+ { "GL_SUN_multi_draw_arrays", o(EXT_multi_draw_arrays), GL, 1999 },
+
+ { 0, 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_compression_3dc = GL_TRUE;
+ 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_compression_latc = 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;
+ ctx->Extensions.EXT_texture_shared_exponent = 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;
+}
+
+
+typedef unsigned short extension_index;
+
+
+/**
+ * Compare two entries of the extensions table. Sorts first by year,
+ * then by name.
+ *
+ * Arguments are indices into extension_table.
+ */
+static int
+extension_compare(const void *p1, const void *p2)
+{
+ extension_index i1 = * (const extension_index *) p1;
+ extension_index i2 = * (const extension_index *) p2;
+ const struct extension *e1 = &extension_table[i1];
+ const struct extension *e2 = &extension_table[i2];
+ int res;
+
+ res = (int)e1->year - (int)e2->year;
+
+ if (res == 0) {
+ res = strcmp(e1->name, e2->name);
+ }
+
+ return res;
+}
+
+
+/**
+ * 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;
+ /* Number of extensions */
+ unsigned count;
+ /* Indices of the extensions sorted by year */
+ extension_index *extension_indices;
+ /* String of extra extensions. */
+ char *extra_extensions = get_extension_override(ctx);
+ GLboolean *base = (GLboolean *) &ctx->Extensions;
+ const struct extension *i;
+ unsigned j;
+ unsigned maxYear = ~0;
+
+ /* Check if the MESA_EXTENSION_MAX_YEAR env var is set */
+ {
+ const char *env = getenv("MESA_EXTENSION_MAX_YEAR");
+ if (env) {
+ maxYear = atoi(env);
+ _mesa_debug(ctx, "Note: limiting GL extensions to %u or earlier\n",
+ maxYear);
+ }
+ }
+
+ /* Compute length of the extension string. */
+ count = 0;
+ for (i = extension_table; i->name != 0; ++i) {
+ if (base[i->offset] &&
+ i->year <= maxYear &&
+ (i->api_set & (1 << ctx->API))) {
+ length += strlen(i->name) + 1; /* +1 for space */
+ ++count;
+ }
+ }
+ 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;
+ }
+
+ extension_indices = malloc(count * sizeof(extension_index));
+ if (extension_indices == NULL) {
+ free(exts);
+ free(extra_extensions);
+ return NULL;
+ }
+
+ /* Sort extensions in chronological order because certain old applications (e.g.,
+ * Quake3 demo) store the extension list in a static size buffer so chronologically
+ * order ensure that the extensions that such applications expect will fit into
+ * that buffer.
+ */
+ j = 0;
+ for (i = extension_table; i->name != 0; ++i) {
+ if (base[i->offset] &&
+ i->year <= maxYear &&
+ (i->api_set & (1 << ctx->API))) {
+ extension_indices[j++] = i - extension_table;
+ }
+ }
+ assert(j == count);
+ qsort(extension_indices, count, sizeof *extension_indices, extension_compare);
+
+ /* Build the extension string.*/
+ for (j = 0; j < count; ++j) {
+ i = &extension_table[extension_indices[j]];
+ assert(base[i->offset] && (i->api_set & (1 << ctx->API)));
+ strcat(exts, i->name);
+ strcat(exts, " ");
+ }
+ free(extension_indices);
+ 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 1edb310ea..68a141d29 100644
--- a/mesalib/src/mesa/main/fbobject.c
+++ b/mesalib/src/mesa/main/fbobject.c
@@ -1,2526 +1,2539 @@
-/*
- * 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 (_mesa_get_attachment_teximage(att)) {
- 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);
- }
- rb->AttachedAnytime = GL_TRUE;
- }
- 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 =
- _mesa_get_attachment_teximage(att);
- 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 (att->Renderbuffer && 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_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;
- /* signed normalized texture formats */
- case GL_RED_SNORM:
- case GL_R8_SNORM:
- case GL_R16_SNORM:
- return ctx->Extensions.EXT_texture_snorm ? GL_RED : 0;
- case GL_RG_SNORM:
- case GL_RG8_SNORM:
- case GL_RG16_SNORM:
- return ctx->Extensions.EXT_texture_snorm ? GL_RG : 0;
- case GL_RGB_SNORM:
- case GL_RGB8_SNORM:
- case GL_RGB16_SNORM:
- return ctx->Extensions.EXT_texture_snorm ? GL_RGB : 0;
- case GL_RGBA_SNORM:
- case GL_RGBA8_SNORM:
- case GL_RGBA16_SNORM:
- return ctx->Extensions.EXT_texture_snorm ? GL_RGBA : 0;
- case GL_ALPHA_SNORM:
- case GL_ALPHA8_SNORM:
- case GL_ALPHA16_SNORM:
- return ctx->Extensions.EXT_texture_snorm &&
- ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
- case GL_LUMINANCE_SNORM:
- case GL_LUMINANCE8_SNORM:
- case GL_LUMINANCE16_SNORM:
- return ctx->Extensions.EXT_texture_snorm &&
- ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
- case GL_LUMINANCE_ALPHA_SNORM:
- case GL_LUMINANCE8_ALPHA8_SNORM:
- case GL_LUMINANCE16_ALPHA16_SNORM:
- return ctx->Extensions.EXT_texture_snorm &&
- ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
- case GL_INTENSITY_SNORM:
- case GL_INTENSITY8_SNORM:
- case GL_INTENSITY16_SNORM:
- return ctx->Extensions.EXT_texture_snorm &&
- ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
- case GL_R16F:
- case GL_R32F:
- return ctx->Extensions.ARB_texture_rg &&
- ctx->Extensions.ARB_texture_float ? GL_RED : 0;
- case GL_RG16F:
- case GL_RG32F:
- return ctx->Extensions.ARB_texture_rg &&
- ctx->Extensions.ARB_texture_float ? GL_RG : 0;
- case GL_RGB16F:
- case GL_RGB32F:
- return ctx->Extensions.ARB_texture_float ? GL_RGB : 0;
- case GL_RGBA16F:
- case GL_RGBA32F:
- return ctx->Extensions.ARB_texture_float ? GL_RGBA : 0;
- case GL_ALPHA16F_ARB:
- case GL_ALPHA32F_ARB:
- return ctx->Extensions.ARB_texture_float &&
- ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
- case GL_LUMINANCE16F_ARB:
- case GL_LUMINANCE32F_ARB:
- return ctx->Extensions.ARB_texture_float &&
- ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
- case GL_LUMINANCE_ALPHA16F_ARB:
- case GL_LUMINANCE_ALPHA32F_ARB:
- return ctx->Extensions.ARB_texture_float &&
- ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
- case GL_INTENSITY16F_ARB:
- case GL_INTENSITY32F_ARB:
- return ctx->Extensions.ARB_texture_float &&
- ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
- /* XXX add integer formats eventually */
- default:
- return 0;
- }
-}
-
-
-/**
- * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
- */
-static void
-invalidate_rb(GLuint key, void *data, void *userData)
-{
- struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
- struct gl_renderbuffer *rb = (struct gl_renderbuffer *) userData;
-
- /* If this is a user-created FBO */
- if (fb->Name) {
- GLuint i;
- for (i = 0; i < BUFFER_COUNT; i++) {
- struct gl_renderbuffer_attachment *att = fb->Attachment + i;
- if (att->Type == GL_RENDERBUFFER &&
- att->Renderbuffer == rb) {
- /* Mark fb status as indeterminate to force re-validation */
- fb->_Status = 0;
- return;
- }
- }
- }
-}
-
-
-/** 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;
- }
-
- /* Invalidate the framebuffers the renderbuffer is attached in. */
- if (rb->AttachedAnytime) {
- _mesa_HashWalk(ctx->Shared->FrameBuffers, invalidate_rb, rb);
- }
-}
-
-
-#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;
- if (att->Texture && _mesa_get_attachment_teximage(att)) {
- 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 (_mesa_get_attachment_teximage(att)) {
+ 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);
+ }
+ rb->AttachedAnytime = GL_TRUE;
+ }
+ 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;
+ case GL_RGB:
+ switch (rb->Format) {
+ case MESA_FORMAT_RGB9_E5_FLOAT:
+ fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
+ return;
+ default:;
+ }
+ break;
+
+ 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 =
+ _mesa_get_attachment_teximage(att);
+ 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 (att->Renderbuffer && 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_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;
+ /* signed normalized texture formats */
+ case GL_RED_SNORM:
+ case GL_R8_SNORM:
+ case GL_R16_SNORM:
+ return ctx->Extensions.EXT_texture_snorm ? GL_RED : 0;
+ case GL_RG_SNORM:
+ case GL_RG8_SNORM:
+ case GL_RG16_SNORM:
+ return ctx->Extensions.EXT_texture_snorm ? GL_RG : 0;
+ case GL_RGB_SNORM:
+ case GL_RGB8_SNORM:
+ case GL_RGB16_SNORM:
+ return ctx->Extensions.EXT_texture_snorm ? GL_RGB : 0;
+ case GL_RGBA_SNORM:
+ case GL_RGBA8_SNORM:
+ case GL_RGBA16_SNORM:
+ return ctx->Extensions.EXT_texture_snorm ? GL_RGBA : 0;
+ case GL_ALPHA_SNORM:
+ case GL_ALPHA8_SNORM:
+ case GL_ALPHA16_SNORM:
+ return ctx->Extensions.EXT_texture_snorm &&
+ ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
+ case GL_LUMINANCE_SNORM:
+ case GL_LUMINANCE8_SNORM:
+ case GL_LUMINANCE16_SNORM:
+ return ctx->Extensions.EXT_texture_snorm &&
+ ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
+ case GL_LUMINANCE_ALPHA_SNORM:
+ case GL_LUMINANCE8_ALPHA8_SNORM:
+ case GL_LUMINANCE16_ALPHA16_SNORM:
+ return ctx->Extensions.EXT_texture_snorm &&
+ ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
+ case GL_INTENSITY_SNORM:
+ case GL_INTENSITY8_SNORM:
+ case GL_INTENSITY16_SNORM:
+ return ctx->Extensions.EXT_texture_snorm &&
+ ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
+ case GL_R16F:
+ case GL_R32F:
+ return ctx->Extensions.ARB_texture_rg &&
+ ctx->Extensions.ARB_texture_float ? GL_RED : 0;
+ case GL_RG16F:
+ case GL_RG32F:
+ return ctx->Extensions.ARB_texture_rg &&
+ ctx->Extensions.ARB_texture_float ? GL_RG : 0;
+ case GL_RGB16F:
+ case GL_RGB32F:
+ return ctx->Extensions.ARB_texture_float ? GL_RGB : 0;
+ case GL_RGBA16F:
+ case GL_RGBA32F:
+ return ctx->Extensions.ARB_texture_float ? GL_RGBA : 0;
+ case GL_ALPHA16F_ARB:
+ case GL_ALPHA32F_ARB:
+ return ctx->Extensions.ARB_texture_float &&
+ ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
+ case GL_LUMINANCE16F_ARB:
+ case GL_LUMINANCE32F_ARB:
+ return ctx->Extensions.ARB_texture_float &&
+ ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
+ case GL_LUMINANCE_ALPHA16F_ARB:
+ case GL_LUMINANCE_ALPHA32F_ARB:
+ return ctx->Extensions.ARB_texture_float &&
+ ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
+ case GL_INTENSITY16F_ARB:
+ case GL_INTENSITY32F_ARB:
+ return ctx->Extensions.ARB_texture_float &&
+ ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
+ case GL_RGB9_E5:
+ return ctx->Extensions.EXT_texture_shared_exponent ? GL_RGB : 0;
+ case GL_R11F_G11F_B10F:
+ return ctx->Extensions.EXT_packed_float ? GL_RGB : 0;
+ /* XXX add integer formats eventually */
+ default:
+ return 0;
+ }
+}
+
+
+/**
+ * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
+ */
+static void
+invalidate_rb(GLuint key, void *data, void *userData)
+{
+ struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
+ struct gl_renderbuffer *rb = (struct gl_renderbuffer *) userData;
+
+ /* If this is a user-created FBO */
+ if (fb->Name) {
+ GLuint i;
+ for (i = 0; i < BUFFER_COUNT; i++) {
+ struct gl_renderbuffer_attachment *att = fb->Attachment + i;
+ if (att->Type == GL_RENDERBUFFER &&
+ att->Renderbuffer == rb) {
+ /* Mark fb status as indeterminate to force re-validation */
+ fb->_Status = 0;
+ return;
+ }
+ }
+ }
+}
+
+
+/** 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;
+ }
+
+ /* Invalidate the framebuffers the renderbuffer is attached in. */
+ if (rb->AttachedAnytime) {
+ _mesa_HashWalk(ctx->Shared->FrameBuffers, invalidate_rb, rb);
+ }
+}
+
+
+#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;
+ if (att->Texture && _mesa_get_attachment_teximage(att)) {
+ 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 4c31ccb76..f0f30fe0a 100644
--- a/mesalib/src/mesa/main/formats.c
+++ b/mesalib/src/mesa/main/formats.c
@@ -1,1820 +1,1848 @@
-/*
- * 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_LUMINANCE,
- GL_FLOAT,
- 0, 0, 0, 0,
- 32, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_LUMINANCE_FLOAT16,
- "MESA_FORMAT_LUMINANCE_FLOAT16",
- GL_LUMINANCE,
- 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
- },
- {
- MESA_FORMAT_R_FLOAT32,
- "MESA_FORMAT_R_FLOAT32",
- GL_RED,
- GL_FLOAT,
- 32, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_R_FLOAT16,
- "MESA_FORMAT_R_FLOAT16",
- GL_RED,
- GL_FLOAT,
- 16, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_RG_FLOAT32,
- "MESA_FORMAT_RG_FLOAT32",
- GL_RG,
- GL_FLOAT,
- 32, 32, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 8
- },
- {
- MESA_FORMAT_RG_FLOAT16,
- "MESA_FORMAT_RG_FLOAT16",
- GL_RG,
- GL_FLOAT,
- 16, 16, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 4
- },
-
- /* 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_REV,
- "MESA_FORMAT_SIGNED_RG88_REV",
- 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_R16,
- "MESA_FORMAT_SIGNED_R16",
- GL_RED,
- GL_SIGNED_NORMALIZED,
- 16, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_SIGNED_GR1616,
- "MESA_FORMAT_SIGNED_GR1616",
- 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 */
- },
- {
- MESA_FORMAT_L_LATC1,
- "MESA_FORMAT_L_LATC1",
- GL_LUMINANCE,
- GL_UNSIGNED_NORMALIZED,
- 0, 0, 0, 0,
- 4, 0, 0, 0, 0,
- 4, 4, 8 /* 8 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_SIGNED_L_LATC1,
- "MESA_FORMAT_SIGNED_L_LATC1",
- GL_LUMINANCE,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 0,
- 4, 0, 0, 0, 0,
- 4, 4, 8 /* 8 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_LA_LATC2,
- "MESA_FORMAT_LA_LATC2",
- GL_LUMINANCE_ALPHA,
- GL_UNSIGNED_NORMALIZED,
- 0, 0, 0, 4,
- 4, 0, 0, 0, 0,
- 4, 4, 16 /* 16 bytes per 4x4 block */
- },
- {
- MESA_FORMAT_SIGNED_LA_LATC2,
- "MESA_FORMAT_SIGNED_LA_LATC2",
- GL_LUMINANCE_ALPHA,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 4,
- 4, 0, 0, 0, 0,
- 4, 4, 16 /* 16 bytes per 4x4 block */
- },
-
- /* Signed formats from EXT_texture_snorm that are not in GL3.1 */
- {
- MESA_FORMAT_SIGNED_A8,
- "MESA_FORMAT_SIGNED_A8",
- GL_ALPHA,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 8,
- 0, 0, 0, 0, 0,
- 1, 1, 1
- },
- {
- MESA_FORMAT_SIGNED_L8,
- "MESA_FORMAT_SIGNED_L8",
- GL_LUMINANCE,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 0,
- 8, 0, 0, 0, 0,
- 1, 1, 1
- },
- {
- MESA_FORMAT_SIGNED_AL88,
- "MESA_FORMAT_SIGNED_AL88",
- GL_LUMINANCE_ALPHA,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 8,
- 8, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_SIGNED_I8,
- "MESA_FORMAT_SIGNED_I8",
- GL_INTENSITY,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 0,
- 0, 8, 0, 0, 0,
- 1, 1, 1
- },
- {
- MESA_FORMAT_SIGNED_A16,
- "MESA_FORMAT_SIGNED_A16",
- GL_ALPHA,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 16,
- 0, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_SIGNED_L16,
- "MESA_FORMAT_SIGNED_L16",
- GL_LUMINANCE,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 0,
- 16, 0, 0, 0, 0,
- 1, 1, 2
- },
- {
- MESA_FORMAT_SIGNED_AL1616,
- "MESA_FORMAT_SIGNED_AL1616",
- GL_LUMINANCE_ALPHA,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 16,
- 16, 0, 0, 0, 0,
- 1, 1, 4
- },
- {
- MESA_FORMAT_SIGNED_I16,
- "MESA_FORMAT_SIGNED_I16",
- GL_INTENSITY,
- GL_SIGNED_NORMALIZED,
- 0, 0, 0, 0,
- 0, 16, 0, 0, 0,
- 1, 1, 2
- }
-};
-
-
-
-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:
- case MESA_FORMAT_SIGNED_A8:
- case MESA_FORMAT_SIGNED_L8:
- case MESA_FORMAT_SIGNED_I8:
- *datatype = GL_BYTE;
- *comps = 1;
- return;
- case MESA_FORMAT_SIGNED_RG88_REV:
- case MESA_FORMAT_SIGNED_AL88:
- *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_R16:
- case MESA_FORMAT_SIGNED_A16:
- case MESA_FORMAT_SIGNED_L16:
- case MESA_FORMAT_SIGNED_I16:
- *datatype = GL_SHORT;
- *comps = 1;
- return;
- case MESA_FORMAT_SIGNED_GR1616:
- case MESA_FORMAT_SIGNED_AL1616:
- *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:
- case MESA_FORMAT_L_LATC1:
- case MESA_FORMAT_SIGNED_L_LATC1:
- case MESA_FORMAT_LA_LATC2:
- case MESA_FORMAT_SIGNED_LA_LATC2:
- /* 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:
- case MESA_FORMAT_RG_FLOAT32:
- *datatype = GL_FLOAT;
- *comps = 2;
- return;
- case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
- case MESA_FORMAT_RG_FLOAT16:
- *datatype = GL_HALF_FLOAT_ARB;
- *comps = 2;
- return;
- case MESA_FORMAT_ALPHA_FLOAT32:
- case MESA_FORMAT_LUMINANCE_FLOAT32:
- case MESA_FORMAT_INTENSITY_FLOAT32:
- case MESA_FORMAT_R_FLOAT32:
- *datatype = GL_FLOAT;
- *comps = 1;
- return;
- case MESA_FORMAT_ALPHA_FLOAT16:
- case MESA_FORMAT_LUMINANCE_FLOAT16:
- case MESA_FORMAT_INTENSITY_FLOAT16:
- case MESA_FORMAT_R_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_LUMINANCE,
+ GL_FLOAT,
+ 0, 0, 0, 0,
+ 32, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_LUMINANCE_FLOAT16,
+ "MESA_FORMAT_LUMINANCE_FLOAT16",
+ GL_LUMINANCE,
+ 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
+ },
+ {
+ MESA_FORMAT_R_FLOAT32,
+ "MESA_FORMAT_R_FLOAT32",
+ GL_RED,
+ GL_FLOAT,
+ 32, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_R_FLOAT16,
+ "MESA_FORMAT_R_FLOAT16",
+ GL_RED,
+ GL_FLOAT,
+ 16, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_RG_FLOAT32,
+ "MESA_FORMAT_RG_FLOAT32",
+ GL_RG,
+ GL_FLOAT,
+ 32, 32, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 8
+ },
+ {
+ MESA_FORMAT_RG_FLOAT16,
+ "MESA_FORMAT_RG_FLOAT16",
+ GL_RG,
+ GL_FLOAT,
+ 16, 16, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+
+ /* 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_REV,
+ "MESA_FORMAT_SIGNED_RG88_REV",
+ 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_R16,
+ "MESA_FORMAT_SIGNED_R16",
+ GL_RED,
+ GL_SIGNED_NORMALIZED,
+ 16, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_SIGNED_GR1616,
+ "MESA_FORMAT_SIGNED_GR1616",
+ 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 */
+ },
+ {
+ MESA_FORMAT_L_LATC1,
+ "MESA_FORMAT_L_LATC1",
+ GL_LUMINANCE,
+ GL_UNSIGNED_NORMALIZED,
+ 0, 0, 0, 0,
+ 4, 0, 0, 0, 0,
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_SIGNED_L_LATC1,
+ "MESA_FORMAT_SIGNED_L_LATC1",
+ GL_LUMINANCE,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 0,
+ 4, 0, 0, 0, 0,
+ 4, 4, 8 /* 8 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_LA_LATC2,
+ "MESA_FORMAT_LA_LATC2",
+ GL_LUMINANCE_ALPHA,
+ GL_UNSIGNED_NORMALIZED,
+ 0, 0, 0, 4,
+ 4, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+ {
+ MESA_FORMAT_SIGNED_LA_LATC2,
+ "MESA_FORMAT_SIGNED_LA_LATC2",
+ GL_LUMINANCE_ALPHA,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 4,
+ 4, 0, 0, 0, 0,
+ 4, 4, 16 /* 16 bytes per 4x4 block */
+ },
+
+ /* Signed formats from EXT_texture_snorm that are not in GL3.1 */
+ {
+ MESA_FORMAT_SIGNED_A8,
+ "MESA_FORMAT_SIGNED_A8",
+ GL_ALPHA,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 8,
+ 0, 0, 0, 0, 0,
+ 1, 1, 1
+ },
+ {
+ MESA_FORMAT_SIGNED_L8,
+ "MESA_FORMAT_SIGNED_L8",
+ GL_LUMINANCE,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 0,
+ 8, 0, 0, 0, 0,
+ 1, 1, 1
+ },
+ {
+ MESA_FORMAT_SIGNED_AL88,
+ "MESA_FORMAT_SIGNED_AL88",
+ GL_LUMINANCE_ALPHA,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 8,
+ 8, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_SIGNED_I8,
+ "MESA_FORMAT_SIGNED_I8",
+ GL_INTENSITY,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 0,
+ 0, 8, 0, 0, 0,
+ 1, 1, 1
+ },
+ {
+ MESA_FORMAT_SIGNED_A16,
+ "MESA_FORMAT_SIGNED_A16",
+ GL_ALPHA,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 16,
+ 0, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_SIGNED_L16,
+ "MESA_FORMAT_SIGNED_L16",
+ GL_LUMINANCE,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 0,
+ 16, 0, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_SIGNED_AL1616,
+ "MESA_FORMAT_SIGNED_AL1616",
+ GL_LUMINANCE_ALPHA,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 16,
+ 16, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_SIGNED_I16,
+ "MESA_FORMAT_SIGNED_I16",
+ GL_INTENSITY,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 0,
+ 0, 16, 0, 0, 0,
+ 1, 1, 2
+ },
+ {
+ MESA_FORMAT_RGB9_E5_FLOAT,
+ "MESA_FORMAT_RGB9_E5",
+ GL_RGB,
+ GL_FLOAT,
+ 9, 9, 9, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+ {
+ MESA_FORMAT_R11_G11_B10_FLOAT,
+ "MESA_FORMAT_R11_G11_B10_FLOAT",
+ GL_RGB,
+ GL_FLOAT,
+ 11, 11, 10, 0,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
+};
+
+
+
+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:
+ case MESA_FORMAT_SIGNED_A8:
+ case MESA_FORMAT_SIGNED_L8:
+ case MESA_FORMAT_SIGNED_I8:
+ *datatype = GL_BYTE;
+ *comps = 1;
+ return;
+ case MESA_FORMAT_SIGNED_RG88_REV:
+ case MESA_FORMAT_SIGNED_AL88:
+ *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_R16:
+ case MESA_FORMAT_SIGNED_A16:
+ case MESA_FORMAT_SIGNED_L16:
+ case MESA_FORMAT_SIGNED_I16:
+ *datatype = GL_SHORT;
+ *comps = 1;
+ return;
+ case MESA_FORMAT_SIGNED_GR1616:
+ case MESA_FORMAT_SIGNED_AL1616:
+ *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:
+ case MESA_FORMAT_L_LATC1:
+ case MESA_FORMAT_SIGNED_L_LATC1:
+ case MESA_FORMAT_LA_LATC2:
+ case MESA_FORMAT_SIGNED_LA_LATC2:
+ /* 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:
+ case MESA_FORMAT_RG_FLOAT32:
+ *datatype = GL_FLOAT;
+ *comps = 2;
+ return;
+ case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
+ case MESA_FORMAT_RG_FLOAT16:
+ *datatype = GL_HALF_FLOAT_ARB;
+ *comps = 2;
+ return;
+ case MESA_FORMAT_ALPHA_FLOAT32:
+ case MESA_FORMAT_LUMINANCE_FLOAT32:
+ case MESA_FORMAT_INTENSITY_FLOAT32:
+ case MESA_FORMAT_R_FLOAT32:
+ *datatype = GL_FLOAT;
+ *comps = 1;
+ return;
+ case MESA_FORMAT_ALPHA_FLOAT16:
+ case MESA_FORMAT_LUMINANCE_FLOAT16:
+ case MESA_FORMAT_INTENSITY_FLOAT16:
+ case MESA_FORMAT_R_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_RGB9_E5_FLOAT:
+ *datatype = GL_UNSIGNED_INT_5_9_9_9_REV;
+ *comps = 3;
+ return;
+
+ case MESA_FORMAT_R11_G11_B10_FLOAT:
+ *datatype = GL_UNSIGNED_INT_10F_11F_11F_REV;
+ *comps = 3;
+ 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 15ac62cfe..c9fd0baab 100644
--- a/mesalib/src/mesa/main/formats.h
+++ b/mesalib/src/mesa/main/formats.h
@@ -1,264 +1,267 @@
-/*
- * 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,
- MESA_FORMAT_R_FLOAT32,
- MESA_FORMAT_R_FLOAT16,
- MESA_FORMAT_RG_FLOAT32,
- MESA_FORMAT_RG_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_REV, /* GGGG GGGG RRRR RRRR */
- 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_R16, /* RRRR RRRR RRRR RRRR */
- MESA_FORMAT_SIGNED_GR1616, /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
- 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_L_LATC1,
- MESA_FORMAT_SIGNED_L_LATC1,
- MESA_FORMAT_LA_LATC2,
- MESA_FORMAT_SIGNED_LA_LATC2,
- /*@}*/
-
- MESA_FORMAT_SIGNED_A8, /* AAAA AAAA */
- MESA_FORMAT_SIGNED_L8, /* LLLL LLLL */
- MESA_FORMAT_SIGNED_AL88, /* AAAA AAAA LLLL LLLL */
- MESA_FORMAT_SIGNED_I8, /* IIII IIII */
- MESA_FORMAT_SIGNED_A16, /* AAAA AAAA AAAA AAAA */
- MESA_FORMAT_SIGNED_L16, /* LLLL LLLL LLLL LLLL */
- MESA_FORMAT_SIGNED_AL1616, /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
- MESA_FORMAT_SIGNED_I16, /* IIII IIII IIII IIII */
-
- 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,
+ MESA_FORMAT_R_FLOAT32,
+ MESA_FORMAT_R_FLOAT16,
+ MESA_FORMAT_RG_FLOAT32,
+ MESA_FORMAT_RG_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_REV, /* GGGG GGGG RRRR RRRR */
+ 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_R16, /* RRRR RRRR RRRR RRRR */
+ MESA_FORMAT_SIGNED_GR1616, /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
+ 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_L_LATC1,
+ MESA_FORMAT_SIGNED_L_LATC1,
+ MESA_FORMAT_LA_LATC2,
+ MESA_FORMAT_SIGNED_LA_LATC2,
+ /*@}*/
+
+ MESA_FORMAT_SIGNED_A8, /* AAAA AAAA */
+ MESA_FORMAT_SIGNED_L8, /* LLLL LLLL */
+ MESA_FORMAT_SIGNED_AL88, /* AAAA AAAA LLLL LLLL */
+ MESA_FORMAT_SIGNED_I8, /* IIII IIII */
+ MESA_FORMAT_SIGNED_A16, /* AAAA AAAA AAAA AAAA */
+ MESA_FORMAT_SIGNED_L16, /* LLLL LLLL LLLL LLLL */
+ MESA_FORMAT_SIGNED_AL1616, /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
+ MESA_FORMAT_SIGNED_I16, /* IIII IIII IIII IIII */
+
+ MESA_FORMAT_RGB9_E5_FLOAT,
+ MESA_FORMAT_R11_G11_B10_FLOAT,
+
+ 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/image.c b/mesalib/src/mesa/main/image.c
index 28841c251..a5cd5ac03 100644
--- a/mesalib/src/mesa/main/image.c
+++ b/mesalib/src/mesa/main/image.c
@@ -1,1913 +1,1935 @@
-/*
- * 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.
- */
-
-
-/**
- * \file image.c
- * Image handling.
- */
-
-
-#include "glheader.h"
-#include "colormac.h"
-#include "image.h"
-#include "imports.h"
-#include "macros.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-
-
-/**
- * NOTE:
- * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
- * we later convert the float to a packed integer value (such as for
- * GL_RGB5_A1) because we'll wind up with a non-zero value.
- *
- * We redefine the macros here so zero is handled correctly.
- */
-#undef BYTE_TO_FLOAT
-#define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
-
-#undef SHORT_TO_FLOAT
-#define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
-
-
-
-/** Compute ceiling of integer quotient of A divided by B. */
-#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
-
-
-/**
- * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
- */
-GLboolean
-_mesa_type_is_packed(GLenum type)
-{
- switch (type) {
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- case MESA_UNSIGNED_BYTE_4_4:
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- case GL_UNSIGNED_SHORT_8_8_MESA:
- case GL_UNSIGNED_SHORT_8_8_REV_MESA:
- case GL_UNSIGNED_INT_24_8_EXT:
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-
-
-/**
- * Flip the order of the 2 bytes in each word in the given array.
- *
- * \param p array.
- * \param n number of words.
- */
-void
-_mesa_swap2( GLushort *p, GLuint n )
-{
- GLuint i;
- for (i = 0; i < n; i++) {
- p[i] = (p[i] >> 8) | ((p[i] << 8) & 0xff00);
- }
-}
-
-
-
-/*
- * Flip the order of the 4 bytes in each word in the given array.
- */
-void
-_mesa_swap4( GLuint *p, GLuint n )
-{
- GLuint i, a, b;
- for (i = 0; i < n; i++) {
- b = p[i];
- a = (b >> 24)
- | ((b >> 8) & 0xff00)
- | ((b << 8) & 0xff0000)
- | ((b << 24) & 0xff000000);
- p[i] = a;
- }
-}
-
-
-/**
- * Get the size of a GL data type.
- *
- * \param type GL data type.
- *
- * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
- * if an invalid type enum.
- */
-GLint
-_mesa_sizeof_type( GLenum type )
-{
- switch (type) {
- case GL_BITMAP:
- return 0;
- case GL_UNSIGNED_BYTE:
- return sizeof(GLubyte);
- case GL_BYTE:
- return sizeof(GLbyte);
- case GL_UNSIGNED_SHORT:
- return sizeof(GLushort);
- case GL_SHORT:
- return sizeof(GLshort);
- case GL_UNSIGNED_INT:
- return sizeof(GLuint);
- case GL_INT:
- return sizeof(GLint);
- case GL_FLOAT:
- return sizeof(GLfloat);
- case GL_DOUBLE:
- return sizeof(GLdouble);
- case GL_HALF_FLOAT_ARB:
- return sizeof(GLhalfARB);
- case GL_FIXED:
- return sizeof(GLfixed);
- default:
- return -1;
- }
-}
-
-
-/**
- * Same as _mesa_sizeof_type() but also accepting the packed pixel
- * format data types.
- */
-GLint
-_mesa_sizeof_packed_type( GLenum type )
-{
- switch (type) {
- case GL_BITMAP:
- return 0;
- case GL_UNSIGNED_BYTE:
- return sizeof(GLubyte);
- case GL_BYTE:
- return sizeof(GLbyte);
- case GL_UNSIGNED_SHORT:
- return sizeof(GLushort);
- case GL_SHORT:
- return sizeof(GLshort);
- case GL_UNSIGNED_INT:
- return sizeof(GLuint);
- case GL_INT:
- return sizeof(GLint);
- case GL_HALF_FLOAT_ARB:
- return sizeof(GLhalfARB);
- case GL_FLOAT:
- return sizeof(GLfloat);
- case GL_UNSIGNED_BYTE_3_3_2:
- return sizeof(GLubyte);
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- return sizeof(GLubyte);
- case MESA_UNSIGNED_BYTE_4_4:
- return sizeof(GLubyte);
- case GL_UNSIGNED_SHORT_5_6_5:
- return sizeof(GLushort);
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- return sizeof(GLushort);
- case GL_UNSIGNED_SHORT_4_4_4_4:
- return sizeof(GLushort);
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- return sizeof(GLushort);
- case GL_UNSIGNED_SHORT_5_5_5_1:
- return sizeof(GLushort);
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- return sizeof(GLushort);
- case GL_UNSIGNED_INT_8_8_8_8:
- return sizeof(GLuint);
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- return sizeof(GLuint);
- case GL_UNSIGNED_INT_10_10_10_2:
- return sizeof(GLuint);
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- return sizeof(GLuint);
- case GL_UNSIGNED_SHORT_8_8_MESA:
- case GL_UNSIGNED_SHORT_8_8_REV_MESA:
- return sizeof(GLushort);
- case GL_UNSIGNED_INT_24_8_EXT:
- return sizeof(GLuint);
- default:
- return -1;
- }
-}
-
-
-/**
- * Get the number of components in a pixel format.
- *
- * \param format pixel format.
- *
- * \return the number of components in the given format, or -1 if a bad format.
- */
-GLint
-_mesa_components_in_format( GLenum format )
-{
- switch (format) {
- 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:
- case GL_STENCIL_INDEX:
- case GL_DEPTH_COMPONENT:
- case GL_RED:
- case GL_RED_INTEGER_EXT:
- case GL_GREEN:
- case GL_GREEN_INTEGER_EXT:
- case GL_BLUE:
- case GL_BLUE_INTEGER_EXT:
- case GL_ALPHA:
- case GL_ALPHA_INTEGER_EXT:
- case GL_LUMINANCE:
- case GL_LUMINANCE_INTEGER_EXT:
- case GL_INTENSITY:
- return 1;
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- case GL_RG:
- return 2;
- case GL_RGB:
- case GL_RGB_INTEGER_EXT:
- return 3;
- case GL_RGBA:
- case GL_RGBA_INTEGER_EXT:
- return 4;
- case GL_BGR:
- return 3;
- case GL_BGRA:
- return 4;
- case GL_ABGR_EXT:
- return 4;
- case GL_YCBCR_MESA:
- return 2;
- case GL_DEPTH_STENCIL_EXT:
- return 2;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- return 2;
- default:
- return -1;
- }
-}
-
-
-/**
- * Get the bytes per pixel of pixel format type pair.
- *
- * \param format pixel format.
- * \param type pixel type.
- *
- * \return bytes per pixel, or -1 if a bad format or type was given.
- */
-GLint
-_mesa_bytes_per_pixel( GLenum format, GLenum type )
-{
- GLint comps = _mesa_components_in_format( format );
- if (comps < 0)
- return -1;
-
- switch (type) {
- case GL_BITMAP:
- return 0; /* special case */
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- return comps * sizeof(GLubyte);
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- return comps * sizeof(GLshort);
- case GL_INT:
- case GL_UNSIGNED_INT:
- return comps * sizeof(GLint);
- case GL_FLOAT:
- return comps * sizeof(GLfloat);
- case GL_HALF_FLOAT_ARB:
- return comps * sizeof(GLhalfARB);
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- if (format == GL_RGB || format == GL_BGR ||
- format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT)
- return sizeof(GLubyte);
- else
- return -1; /* error */
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- if (format == GL_RGB || format == GL_BGR ||
- format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT)
- return sizeof(GLushort);
- else
- return -1; /* error */
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT ||
- format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT)
- return sizeof(GLushort);
- else
- return -1;
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT ||
- format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT)
- return sizeof(GLuint);
- else
- return -1;
- case GL_UNSIGNED_SHORT_8_8_MESA:
- case GL_UNSIGNED_SHORT_8_8_REV_MESA:
- if (format == GL_YCBCR_MESA)
- return sizeof(GLushort);
- else
- return -1;
- case GL_UNSIGNED_INT_24_8_EXT:
- if (format == GL_DEPTH_STENCIL_EXT)
- return sizeof(GLuint);
- else
- return -1;
- default:
- return -1;
- }
-}
-
-
-/**
- * Test for a legal pixel format and type.
- *
- * \param format pixel format.
- * \param type pixel type.
- *
- * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
- * otherwise.
- */
-GLboolean
-_mesa_is_legal_format_and_type(const struct gl_context *ctx,
- GLenum format, GLenum type)
-{
- switch (format) {
- case GL_COLOR_INDEX:
- case GL_STENCIL_INDEX:
- switch (type) {
- case GL_BITMAP:
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- return GL_TRUE;
- case GL_HALF_FLOAT_ARB:
- return ctx->Extensions.ARB_half_float_pixel;
- default:
- return GL_FALSE;
- }
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
-#if 0 /* not legal! see table 3.6 of the 1.5 spec */
- case GL_INTENSITY:
-#endif
- case GL_LUMINANCE:
- case GL_LUMINANCE_ALPHA:
- case GL_DEPTH_COMPONENT:
- 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:
- return GL_TRUE;
- case GL_HALF_FLOAT_ARB:
- return ctx->Extensions.ARB_half_float_pixel;
- default:
- return GL_FALSE;
- }
- case GL_RG:
- if (!ctx->Extensions.ARB_texture_rg)
- return GL_FALSE;
-
- 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:
- return GL_TRUE;
- case GL_HALF_FLOAT_ARB:
- return ctx->Extensions.ARB_half_float_pixel;
- default:
- return GL_FALSE;
- }
- case GL_RGB:
- 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_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- return GL_TRUE;
- case GL_HALF_FLOAT_ARB:
- return ctx->Extensions.ARB_half_float_pixel;
- default:
- return GL_FALSE;
- }
- case GL_BGR:
- switch (type) {
- /* NOTE: no packed types are supported with BGR. That's
- * intentional, according to the GL spec.
- */
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- return GL_TRUE;
- case GL_HALF_FLOAT_ARB:
- return ctx->Extensions.ARB_half_float_pixel;
- default:
- return GL_FALSE;
- }
- case GL_RGBA:
- case GL_BGRA:
- case GL_ABGR_EXT:
- 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_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- return GL_TRUE;
- case GL_HALF_FLOAT_ARB:
- return ctx->Extensions.ARB_half_float_pixel;
- default:
- return GL_FALSE;
- }
- case GL_YCBCR_MESA:
- if (type == GL_UNSIGNED_SHORT_8_8_MESA ||
- type == GL_UNSIGNED_SHORT_8_8_REV_MESA)
- return GL_TRUE;
- else
- return GL_FALSE;
- case GL_DEPTH_STENCIL_EXT:
- if (ctx->Extensions.EXT_packed_depth_stencil
- && type == GL_UNSIGNED_INT_24_8_EXT)
- return GL_TRUE;
- else
- return GL_FALSE;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- 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:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-
- /* integer-valued formats */
- case GL_RED_INTEGER_EXT:
- case GL_GREEN_INTEGER_EXT:
- case GL_BLUE_INTEGER_EXT:
- case GL_ALPHA_INTEGER_EXT:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- return ctx->Extensions.EXT_texture_integer;
- default:
- return GL_FALSE;
- }
-
- case GL_RGB_INTEGER_EXT:
- 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_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- return ctx->Extensions.EXT_texture_integer;
- default:
- return GL_FALSE;
- }
-
- case GL_BGR_INTEGER_EXT:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- /* NOTE: no packed formats w/ BGR format */
- return ctx->Extensions.EXT_texture_integer;
- default:
- return GL_FALSE;
- }
-
- case GL_RGBA_INTEGER_EXT:
- case GL_BGRA_INTEGER_EXT:
- 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_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- return ctx->Extensions.EXT_texture_integer;
- default:
- return GL_FALSE;
- }
-
- case GL_LUMINANCE_INTEGER_EXT:
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- return ctx->Extensions.EXT_texture_integer;
- default:
- return GL_FALSE;
- }
-
- default:
- ; /* fall-through */
- }
- return GL_FALSE;
-}
-
-
-/**
- * Test if the given image format is a color/RGBA format (i.e., not color
- * index, depth, stencil, etc).
- * \param format the image format value (may by an internal texture format)
- * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
- */
-GLboolean
-_mesa_is_color_format(GLenum format)
-{
- switch (format) {
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
- case GL_ALPHA4:
- case GL_ALPHA8:
- case GL_ALPHA12:
- case GL_ALPHA16:
- case 1:
- case GL_LUMINANCE:
- case GL_LUMINANCE4:
- case GL_LUMINANCE8:
- case GL_LUMINANCE12:
- case GL_LUMINANCE16:
- 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:
- case GL_INTENSITY:
- case GL_INTENSITY4:
- case GL_INTENSITY8:
- case GL_INTENSITY12:
- case GL_INTENSITY16:
- case GL_R8:
- case GL_R16:
- case GL_RG:
- case GL_RG8:
- case GL_RG16:
- case 3:
- case GL_RGB:
- case GL_BGR:
- case GL_R3_G3_B2:
- case GL_RGB4:
- case GL_RGB5:
- case GL_RGB8:
- case GL_RGB10:
- case GL_RGB12:
- case GL_RGB16:
- case 4:
- case GL_ABGR_EXT:
- case GL_RGBA:
- case GL_BGRA:
- case GL_RGBA2:
- case GL_RGBA4:
- case GL_RGB5_A1:
- case GL_RGBA8:
- case GL_RGB10_A2:
- case GL_RGBA12:
- case GL_RGBA16:
- /* float texture formats */
- case GL_ALPHA16F_ARB:
- case GL_ALPHA32F_ARB:
- case GL_LUMINANCE16F_ARB:
- case GL_LUMINANCE32F_ARB:
- case GL_LUMINANCE_ALPHA16F_ARB:
- case GL_LUMINANCE_ALPHA32F_ARB:
- case GL_INTENSITY16F_ARB:
- case GL_INTENSITY32F_ARB:
- case GL_R16F:
- case GL_R32F:
- case GL_RG16F:
- case GL_RG32F:
- case GL_RGB16F_ARB:
- case GL_RGB32F_ARB:
- case GL_RGBA16F_ARB:
- case GL_RGBA32F_ARB:
- /* compressed formats */
- case GL_COMPRESSED_ALPHA:
- case GL_COMPRESSED_LUMINANCE:
- case GL_COMPRESSED_LUMINANCE_ALPHA:
- case GL_COMPRESSED_INTENSITY:
- case GL_COMPRESSED_RED:
- case GL_COMPRESSED_RG:
- case GL_COMPRESSED_RGB:
- case GL_COMPRESSED_RGBA:
- case GL_RGB_S3TC:
- case GL_RGB4_S3TC:
- case GL_RGBA_S3TC:
- case GL_RGBA4_S3TC:
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- case GL_COMPRESSED_RGB_FXT1_3DFX:
- case GL_COMPRESSED_RGBA_FXT1_3DFX:
-#if FEATURE_EXT_texture_sRGB
- case GL_SRGB_EXT:
- case GL_SRGB8_EXT:
- case GL_SRGB_ALPHA_EXT:
- case GL_SRGB8_ALPHA8_EXT:
- case GL_SLUMINANCE_ALPHA_EXT:
- case GL_SLUMINANCE8_ALPHA8_EXT:
- case GL_SLUMINANCE_EXT:
- case GL_SLUMINANCE8_EXT:
- case GL_COMPRESSED_SRGB_EXT:
- case GL_COMPRESSED_SRGB_S3TC_DXT1_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:
- case GL_COMPRESSED_SLUMINANCE_EXT:
- case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
-#endif /* FEATURE_EXT_texture_sRGB */
- case GL_COMPRESSED_RED_RGTC1:
- case GL_COMPRESSED_SIGNED_RED_RGTC1:
- case GL_COMPRESSED_RG_RGTC2:
- case GL_COMPRESSED_SIGNED_RG_RGTC2:
- case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
- case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
- case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
- case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
- case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
- /* generic integer formats */
- 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:
- /* sized integer formats */
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- /* signed, normalized texture formats */
- case GL_RED_SNORM:
- case GL_R8_SNORM:
- case GL_R16_SNORM:
- case GL_RG_SNORM:
- case GL_RG8_SNORM:
- case GL_RG16_SNORM:
- case GL_RGB_SNORM:
- case GL_RGB8_SNORM:
- case GL_RGB16_SNORM:
- case GL_RGBA_SNORM:
- case GL_RGBA8_SNORM:
- case GL_RGBA16_SNORM:
- case GL_ALPHA_SNORM:
- case GL_ALPHA8_SNORM:
- case GL_ALPHA16_SNORM:
- case GL_LUMINANCE_SNORM:
- case GL_LUMINANCE8_SNORM:
- case GL_LUMINANCE16_SNORM:
- case GL_LUMINANCE_ALPHA_SNORM:
- case GL_LUMINANCE8_ALPHA8_SNORM:
- case GL_LUMINANCE16_ALPHA16_SNORM:
- case GL_INTENSITY_SNORM:
- case GL_INTENSITY8_SNORM:
- case GL_INTENSITY16_SNORM:
- return GL_TRUE;
- case GL_YCBCR_MESA: /* not considered to be RGB */
- /* fall-through */
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test if the given image format is a color index format.
- */
-GLboolean
-_mesa_is_index_format(GLenum format)
-{
- switch (format) {
- 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_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test if the given image format is a depth component format.
- */
-GLboolean
-_mesa_is_depth_format(GLenum format)
-{
- switch (format) {
- case GL_DEPTH_COMPONENT:
- case GL_DEPTH_COMPONENT16:
- case GL_DEPTH_COMPONENT24:
- case GL_DEPTH_COMPONENT32:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test if the given image format is a stencil format.
- */
-GLboolean
-_mesa_is_stencil_format(GLenum format)
-{
- switch (format) {
- case GL_STENCIL_INDEX:
- case GL_DEPTH_STENCIL:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test if the given image format is a YCbCr format.
- */
-GLboolean
-_mesa_is_ycbcr_format(GLenum format)
-{
- switch (format) {
- case GL_YCBCR_MESA:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test if the given image format is a depth+stencil format.
- */
-GLboolean
-_mesa_is_depthstencil_format(GLenum format)
-{
- switch (format) {
- case GL_DEPTH24_STENCIL8_EXT:
- case GL_DEPTH_STENCIL_EXT:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test if the given image format is a depth or stencil format.
- */
-GLboolean
-_mesa_is_depth_or_stencil_format(GLenum format)
-{
- switch (format) {
- case GL_DEPTH_COMPONENT:
- case GL_DEPTH_COMPONENT16:
- case GL_DEPTH_COMPONENT24:
- case GL_DEPTH_COMPONENT32:
- case GL_STENCIL_INDEX:
- case GL_STENCIL_INDEX1_EXT:
- case GL_STENCIL_INDEX4_EXT:
- case GL_STENCIL_INDEX8_EXT:
- case GL_STENCIL_INDEX16_EXT:
- case GL_DEPTH_STENCIL_EXT:
- case GL_DEPTH24_STENCIL8_EXT:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test if the given image format is a dudv format.
- */
-GLboolean
-_mesa_is_dudv_format(GLenum format)
-{
- switch (format) {
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test if the given format is an integer (non-normalized) format.
- */
-GLboolean
-_mesa_is_integer_format(GLenum format)
-{
- switch (format) {
- /* generic integer formats */
- 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:
- /* specific integer formats */
- 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:
- 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:
- 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:
- 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:
- 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:
- 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 GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Test if an image format is a supported compressed format.
- * \param format the internal format token provided by the user.
- * \return GL_TRUE if compressed, GL_FALSE if uncompressed
- */
-GLboolean
-_mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
-{
- switch (format) {
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- return ctx->Extensions.EXT_texture_compression_s3tc;
- case GL_RGB_S3TC:
- case GL_RGB4_S3TC:
- case GL_RGBA_S3TC:
- case GL_RGBA4_S3TC:
- return ctx->Extensions.S3_s3tc;
- case GL_COMPRESSED_SRGB_S3TC_DXT1_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 ctx->Extensions.EXT_texture_sRGB
- && ctx->Extensions.EXT_texture_compression_s3tc;
- case GL_COMPRESSED_RGB_FXT1_3DFX:
- case GL_COMPRESSED_RGBA_FXT1_3DFX:
- return ctx->Extensions.TDFX_texture_compression_FXT1;
- case GL_COMPRESSED_RED_RGTC1:
- case GL_COMPRESSED_SIGNED_RED_RGTC1:
- case GL_COMPRESSED_RG_RGTC2:
- case GL_COMPRESSED_SIGNED_RG_RGTC2:
- return ctx->Extensions.ARB_texture_compression_rgtc;
- case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
- case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
- case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
- case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
- return ctx->Extensions.EXT_texture_compression_latc;
- case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
- return ctx->Extensions.ATI_texture_compression_3dc;
- default:
- return GL_FALSE;
- }
-}
-
-
-/**
- * Return the address of a specific pixel in an image (1D, 2D or 3D).
- *
- * Pixel unpacking/packing parameters are observed according to \p packing.
- *
- * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
- * \param image starting address of image data
- * \param width the image width
- * \param height theimage height
- * \param format the pixel format
- * \param type the pixel data type
- * \param packing the pixelstore attributes
- * \param img which image in the volume (0 for 1D or 2D images)
- * \param row row of pixel in the image (0 for 1D images)
- * \param column column of pixel in the image
- *
- * \return address of pixel on success, or NULL on error.
- *
- * \sa gl_pixelstore_attrib.
- */
-GLvoid *
-_mesa_image_address( GLuint dimensions,
- const struct gl_pixelstore_attrib *packing,
- const GLvoid *image,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLint img, GLint row, GLint column )
-{
- GLint alignment; /* 1, 2 or 4 */
- GLint pixels_per_row;
- GLint rows_per_image;
- GLint skiprows;
- GLint skippixels;
- GLint skipimages; /* for 3-D volume images */
- GLubyte *pixel_addr;
-
- ASSERT(dimensions >= 1 && dimensions <= 3);
-
- alignment = packing->Alignment;
- if (packing->RowLength > 0) {
- pixels_per_row = packing->RowLength;
- }
- else {
- pixels_per_row = width;
- }
- if (packing->ImageHeight > 0) {
- rows_per_image = packing->ImageHeight;
- }
- else {
- rows_per_image = height;
- }
-
- skippixels = packing->SkipPixels;
- /* Note: SKIP_ROWS _is_ used for 1D images */
- skiprows = packing->SkipRows;
- /* Note: SKIP_IMAGES is only used for 3D images */
- skipimages = (dimensions == 3) ? packing->SkipImages : 0;
-
- if (type == GL_BITMAP) {
- /* BITMAP data */
- GLint comp_per_pixel; /* components per pixel */
- GLint bytes_per_comp; /* bytes per component */
- GLint bytes_per_row;
- GLint bytes_per_image;
-
- /* Compute bytes per component */
- bytes_per_comp = _mesa_sizeof_packed_type( type );
- if (bytes_per_comp < 0) {
- return NULL;
- }
-
- /* Compute number of components per pixel */
- comp_per_pixel = _mesa_components_in_format( format );
- if (comp_per_pixel < 0) {
- return NULL;
- }
-
- bytes_per_row = alignment
- * CEILING( comp_per_pixel*pixels_per_row, 8*alignment );
-
- bytes_per_image = bytes_per_row * rows_per_image;
-
- pixel_addr = (GLubyte *) image
- + (skipimages + img) * bytes_per_image
- + (skiprows + row) * bytes_per_row
- + (skippixels + column) / 8;
- }
- else {
- /* Non-BITMAP data */
- GLint bytes_per_pixel, bytes_per_row, remainder, bytes_per_image;
- GLint topOfImage;
-
- bytes_per_pixel = _mesa_bytes_per_pixel( format, type );
-
- /* The pixel type and format should have been error checked earlier */
- assert(bytes_per_pixel > 0);
-
- bytes_per_row = pixels_per_row * bytes_per_pixel;
- remainder = bytes_per_row % alignment;
- if (remainder > 0)
- bytes_per_row += (alignment - remainder);
-
- ASSERT(bytes_per_row % alignment == 0);
-
- bytes_per_image = bytes_per_row * rows_per_image;
-
- if (packing->Invert) {
- /* set pixel_addr to the last row */
- topOfImage = bytes_per_row * (height - 1);
- bytes_per_row = -bytes_per_row;
- }
- else {
- topOfImage = 0;
- }
-
- /* compute final pixel address */
- pixel_addr = (GLubyte *) image
- + (skipimages + img) * bytes_per_image
- + topOfImage
- + (skiprows + row) * bytes_per_row
- + (skippixels + column) * bytes_per_pixel;
- }
-
- return (GLvoid *) pixel_addr;
-}
-
-
-GLvoid *
-_mesa_image_address1d( const struct gl_pixelstore_attrib *packing,
- const GLvoid *image,
- GLsizei width,
- GLenum format, GLenum type,
- GLint column )
-{
- return _mesa_image_address(1, packing, image, width, 1,
- format, type, 0, 0, column);
-}
-
-
-GLvoid *
-_mesa_image_address2d( const struct gl_pixelstore_attrib *packing,
- const GLvoid *image,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLint row, GLint column )
-{
- return _mesa_image_address(2, packing, image, width, height,
- format, type, 0, row, column);
-}
-
-
-GLvoid *
-_mesa_image_address3d( const struct gl_pixelstore_attrib *packing,
- const GLvoid *image,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLint img, GLint row, GLint column )
-{
- return _mesa_image_address(3, packing, image, width, height,
- format, type, img, row, column);
-}
-
-
-
-/**
- * Compute the stride (in bytes) between image rows.
- *
- * \param packing the pixelstore attributes
- * \param width image width.
- * \param format pixel format.
- * \param type pixel data type.
- *
- * \return the stride in bytes for the given parameters, or -1 if error
- */
-GLint
-_mesa_image_row_stride( const struct gl_pixelstore_attrib *packing,
- GLint width, GLenum format, GLenum type )
-{
- GLint bytesPerRow, remainder;
-
- ASSERT(packing);
-
- if (type == GL_BITMAP) {
- if (packing->RowLength == 0) {
- bytesPerRow = (width + 7) / 8;
- }
- else {
- bytesPerRow = (packing->RowLength + 7) / 8;
- }
- }
- else {
- /* Non-BITMAP data */
- const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
- if (bytesPerPixel <= 0)
- return -1; /* error */
- if (packing->RowLength == 0) {
- bytesPerRow = bytesPerPixel * width;
- }
- else {
- bytesPerRow = bytesPerPixel * packing->RowLength;
- }
- }
-
- remainder = bytesPerRow % packing->Alignment;
- if (remainder > 0) {
- bytesPerRow += (packing->Alignment - remainder);
- }
-
- if (packing->Invert) {
- /* negate the bytes per row (negative row stride) */
- bytesPerRow = -bytesPerRow;
- }
-
- return bytesPerRow;
-}
-
-
-/*
- * Compute the stride between images in a 3D texture (in bytes) for the given
- * pixel packing parameters and image width, format and type.
- */
-GLint
-_mesa_image_image_stride( const struct gl_pixelstore_attrib *packing,
- GLint width, GLint height,
- GLenum format, GLenum type )
-{
- GLint bytesPerRow, bytesPerImage, remainder;
-
- ASSERT(packing);
-
- if (type == GL_BITMAP) {
- if (packing->RowLength == 0) {
- bytesPerRow = (width + 7) / 8;
- }
- else {
- bytesPerRow = (packing->RowLength + 7) / 8;
- }
- }
- else {
- const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
-
- if (bytesPerPixel <= 0)
- return -1; /* error */
- if (packing->RowLength == 0) {
- bytesPerRow = bytesPerPixel * width;
- }
- else {
- bytesPerRow = bytesPerPixel * packing->RowLength;
- }
- }
-
- remainder = bytesPerRow % packing->Alignment;
- if (remainder > 0)
- bytesPerRow += (packing->Alignment - remainder);
-
- if (packing->ImageHeight == 0)
- bytesPerImage = bytesPerRow * height;
- else
- bytesPerImage = bytesPerRow * packing->ImageHeight;
-
- return bytesPerImage;
-}
-
-
-
-/**
- * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
- * This is typically used to convert a bitmap into a GLubyte/pixel texture.
- * "On" bits will set texels to \p onValue.
- * "Off" bits will not modify texels.
- * \param width src bitmap width in pixels
- * \param height src bitmap height in pixels
- * \param unpack bitmap unpacking state
- * \param bitmap the src bitmap data
- * \param destBuffer start of dest buffer
- * \param destStride row stride in dest buffer
- * \param onValue if bit is 1, set destBuffer pixel to this value
- */
-void
-_mesa_expand_bitmap(GLsizei width, GLsizei height,
- const struct gl_pixelstore_attrib *unpack,
- const GLubyte *bitmap,
- GLubyte *destBuffer, GLint destStride,
- GLubyte onValue)
-{
- const GLubyte *srcRow = (const GLubyte *)
- _mesa_image_address2d(unpack, bitmap, width, height,
- GL_COLOR_INDEX, GL_BITMAP, 0, 0);
- const GLint srcStride = _mesa_image_row_stride(unpack, width,
- GL_COLOR_INDEX, GL_BITMAP);
- GLint row, col;
-
-#define SET_PIXEL(COL, ROW) \
- destBuffer[(ROW) * destStride + (COL)] = onValue;
-
- for (row = 0; row < height; row++) {
- const GLubyte *src = srcRow;
-
- if (unpack->LsbFirst) {
- /* Lsb first */
- GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
- for (col = 0; col < width; col++) {
-
- if (*src & mask) {
- SET_PIXEL(col, row);
- }
-
- 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) {
- SET_PIXEL(col, row);
- }
-
- if (mask == 1U) {
- src++;
- mask = 128U;
- }
- else {
- mask = mask >> 1;
- }
- }
-
- /* get ready for next row */
- if (mask != 128)
- src++;
- }
-
- srcRow += srcStride;
- } /* row */
-
-#undef SET_PIXEL
-}
-
-
-
-
-/**
- * Convert an array of RGBA colors from one datatype to another.
- * NOTE: src may equal dst. In that case, we use a temporary buffer.
- */
-void
-_mesa_convert_colors(GLenum srcType, const GLvoid *src,
- GLenum dstType, GLvoid *dst,
- GLuint count, const GLubyte mask[])
-{
- GLuint tempBuffer[MAX_WIDTH][4];
- const GLboolean useTemp = (src == dst);
-
- ASSERT(srcType != dstType);
-
- switch (srcType) {
- case GL_UNSIGNED_BYTE:
- if (dstType == GL_UNSIGNED_SHORT) {
- const GLubyte (*src1)[4] = (const GLubyte (*)[4]) src;
- GLushort (*dst2)[4] = (GLushort (*)[4]) (useTemp ? tempBuffer : dst);
- GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst2[i][RCOMP] = UBYTE_TO_USHORT(src1[i][RCOMP]);
- dst2[i][GCOMP] = UBYTE_TO_USHORT(src1[i][GCOMP]);
- dst2[i][BCOMP] = UBYTE_TO_USHORT(src1[i][BCOMP]);
- dst2[i][ACOMP] = UBYTE_TO_USHORT(src1[i][ACOMP]);
- }
- }
- if (useTemp)
- memcpy(dst, tempBuffer, count * 4 * sizeof(GLushort));
- }
- else {
- const GLubyte (*src1)[4] = (const GLubyte (*)[4]) src;
- GLfloat (*dst4)[4] = (GLfloat (*)[4]) (useTemp ? tempBuffer : dst);
- GLuint i;
- ASSERT(dstType == GL_FLOAT);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst4[i][RCOMP] = UBYTE_TO_FLOAT(src1[i][RCOMP]);
- dst4[i][GCOMP] = UBYTE_TO_FLOAT(src1[i][GCOMP]);
- dst4[i][BCOMP] = UBYTE_TO_FLOAT(src1[i][BCOMP]);
- dst4[i][ACOMP] = UBYTE_TO_FLOAT(src1[i][ACOMP]);
- }
- }
- if (useTemp)
- memcpy(dst, tempBuffer, count * 4 * sizeof(GLfloat));
- }
- break;
- case GL_UNSIGNED_SHORT:
- if (dstType == GL_UNSIGNED_BYTE) {
- const GLushort (*src2)[4] = (const GLushort (*)[4]) src;
- GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst);
- GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst1[i][RCOMP] = USHORT_TO_UBYTE(src2[i][RCOMP]);
- dst1[i][GCOMP] = USHORT_TO_UBYTE(src2[i][GCOMP]);
- dst1[i][BCOMP] = USHORT_TO_UBYTE(src2[i][BCOMP]);
- dst1[i][ACOMP] = USHORT_TO_UBYTE(src2[i][ACOMP]);
- }
- }
- if (useTemp)
- memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte));
- }
- else {
- const GLushort (*src2)[4] = (const GLushort (*)[4]) src;
- GLfloat (*dst4)[4] = (GLfloat (*)[4]) (useTemp ? tempBuffer : dst);
- GLuint i;
- ASSERT(dstType == GL_FLOAT);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- dst4[i][RCOMP] = USHORT_TO_FLOAT(src2[i][RCOMP]);
- dst4[i][GCOMP] = USHORT_TO_FLOAT(src2[i][GCOMP]);
- dst4[i][BCOMP] = USHORT_TO_FLOAT(src2[i][BCOMP]);
- dst4[i][ACOMP] = USHORT_TO_FLOAT(src2[i][ACOMP]);
- }
- }
- if (useTemp)
- memcpy(dst, tempBuffer, count * 4 * sizeof(GLfloat));
- }
- break;
- case GL_FLOAT:
- if (dstType == GL_UNSIGNED_BYTE) {
- const GLfloat (*src4)[4] = (const GLfloat (*)[4]) src;
- GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst);
- GLuint i;
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][RCOMP], src4[i][RCOMP]);
- UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][GCOMP], src4[i][GCOMP]);
- UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][BCOMP], src4[i][BCOMP]);
- UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][ACOMP], src4[i][ACOMP]);
- }
- }
- if (useTemp)
- memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte));
- }
- else {
- const GLfloat (*src4)[4] = (const GLfloat (*)[4]) src;
- GLushort (*dst2)[4] = (GLushort (*)[4]) (useTemp ? tempBuffer : dst);
- GLuint i;
- ASSERT(dstType == GL_UNSIGNED_SHORT);
- for (i = 0; i < count; i++) {
- if (!mask || mask[i]) {
- UNCLAMPED_FLOAT_TO_USHORT(dst2[i][RCOMP], src4[i][RCOMP]);
- UNCLAMPED_FLOAT_TO_USHORT(dst2[i][GCOMP], src4[i][GCOMP]);
- UNCLAMPED_FLOAT_TO_USHORT(dst2[i][BCOMP], src4[i][BCOMP]);
- UNCLAMPED_FLOAT_TO_USHORT(dst2[i][ACOMP], src4[i][ACOMP]);
- }
- }
- if (useTemp)
- memcpy(dst, tempBuffer, count * 4 * sizeof(GLushort));
- }
- break;
- default:
- _mesa_problem(NULL, "Invalid datatype in _mesa_convert_colors");
- }
-}
-
-
-
-
-/**
- * Perform basic clipping for glDrawPixels. The image's position and size
- * and the unpack SkipPixels and SkipRows are adjusted so that the image
- * region is entirely within the window and scissor bounds.
- * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
- * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
- * we'll actually write. Beforehand, *destY-1 is the first drawing row.
- *
- * \return GL_TRUE if image is ready for drawing or
- * GL_FALSE if image was completely clipped away (draw nothing)
- */
-GLboolean
-_mesa_clip_drawpixels(const struct gl_context *ctx,
- GLint *destX, GLint *destY,
- GLsizei *width, GLsizei *height,
- struct gl_pixelstore_attrib *unpack)
-{
- const struct gl_framebuffer *buffer = ctx->DrawBuffer;
-
- if (unpack->RowLength == 0) {
- unpack->RowLength = *width;
- }
-
- ASSERT(ctx->Pixel.ZoomX == 1.0F);
- ASSERT(ctx->Pixel.ZoomY == 1.0F || ctx->Pixel.ZoomY == -1.0F);
-
- /* left clipping */
- if (*destX < buffer->_Xmin) {
- unpack->SkipPixels += (buffer->_Xmin - *destX);
- *width -= (buffer->_Xmin - *destX);
- *destX = buffer->_Xmin;
- }
- /* right clipping */
- if (*destX + *width > buffer->_Xmax)
- *width -= (*destX + *width - buffer->_Xmax);
-
- if (*width <= 0)
- return GL_FALSE;
-
- if (ctx->Pixel.ZoomY == 1.0F) {
- /* bottom clipping */
- if (*destY < buffer->_Ymin) {
- unpack->SkipRows += (buffer->_Ymin - *destY);
- *height -= (buffer->_Ymin - *destY);
- *destY = buffer->_Ymin;
- }
- /* top clipping */
- if (*destY + *height > buffer->_Ymax)
- *height -= (*destY + *height - buffer->_Ymax);
- }
- else { /* upside down */
- /* top clipping */
- if (*destY > buffer->_Ymax) {
- unpack->SkipRows += (*destY - buffer->_Ymax);
- *height -= (*destY - buffer->_Ymax);
- *destY = buffer->_Ymax;
- }
- /* bottom clipping */
- if (*destY - *height < buffer->_Ymin)
- *height -= (buffer->_Ymin - (*destY - *height));
- /* adjust destY so it's the first row to write to */
- (*destY)--;
- }
-
- if (*height <= 0)
- return GL_FALSE;
-
- return GL_TRUE;
-}
-
-
-/**
- * Perform clipping for glReadPixels. The image's window position
- * and size, and the pack skipPixels, skipRows and rowLength are adjusted
- * so that the image region is entirely within the window bounds.
- * Note: this is different from _mesa_clip_drawpixels() in that the
- * scissor box is ignored, and we use the bounds of the current readbuffer
- * surface.
- *
- * \return GL_TRUE if region to read is in bounds
- * GL_FALSE if region is completely out of bounds (nothing to read)
- */
-GLboolean
-_mesa_clip_readpixels(const struct gl_context *ctx,
- GLint *srcX, GLint *srcY,
- GLsizei *width, GLsizei *height,
- struct gl_pixelstore_attrib *pack)
-{
- const struct gl_framebuffer *buffer = ctx->ReadBuffer;
-
- if (pack->RowLength == 0) {
- pack->RowLength = *width;
- }
-
- /* left clipping */
- if (*srcX < 0) {
- pack->SkipPixels += (0 - *srcX);
- *width -= (0 - *srcX);
- *srcX = 0;
- }
- /* right clipping */
- if (*srcX + *width > (GLsizei) buffer->Width)
- *width -= (*srcX + *width - buffer->Width);
-
- if (*width <= 0)
- return GL_FALSE;
-
- /* bottom clipping */
- if (*srcY < 0) {
- pack->SkipRows += (0 - *srcY);
- *height -= (0 - *srcY);
- *srcY = 0;
- }
- /* top clipping */
- if (*srcY + *height > (GLsizei) buffer->Height)
- *height -= (*srcY + *height - buffer->Height);
-
- if (*height <= 0)
- return GL_FALSE;
-
- return GL_TRUE;
-}
-
-
-/**
- * Do clipping for a glCopyTexSubImage call.
- * The framebuffer source region might extend outside the framebuffer
- * bounds. Clip the source region against the framebuffer bounds and
- * adjust the texture/dest position and size accordingly.
- *
- * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
- */
-GLboolean
-_mesa_clip_copytexsubimage(const struct gl_context *ctx,
- GLint *destX, GLint *destY,
- GLint *srcX, GLint *srcY,
- GLsizei *width, GLsizei *height)
-{
- const struct gl_framebuffer *fb = ctx->ReadBuffer;
- const GLint srcX0 = *srcX, srcY0 = *srcY;
-
- if (_mesa_clip_to_region(0, 0, fb->Width, fb->Height,
- srcX, srcY, width, height)) {
- *destX = *destX + *srcX - srcX0;
- *destY = *destY + *srcY - srcY0;
-
- return GL_TRUE;
- }
- else {
- return GL_FALSE;
- }
-}
-
-
-
-/**
- * Clip the rectangle defined by (x, y, width, height) against the bounds
- * specified by [xmin, xmax) and [ymin, ymax).
- * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
- */
-GLboolean
-_mesa_clip_to_region(GLint xmin, GLint ymin,
- GLint xmax, GLint ymax,
- GLint *x, GLint *y,
- GLsizei *width, GLsizei *height )
-{
- /* left clipping */
- if (*x < xmin) {
- *width -= (xmin - *x);
- *x = xmin;
- }
-
- /* right clipping */
- if (*x + *width > xmax)
- *width -= (*x + *width - xmax);
-
- if (*width <= 0)
- return GL_FALSE;
-
- /* bottom (or top) clipping */
- if (*y < ymin) {
- *height -= (ymin - *y);
- *y = ymin;
- }
-
- /* top (or bottom) clipping */
- if (*y + *height > ymax)
- *height -= (*y + *height - ymax);
-
- if (*height <= 0)
- return GL_FALSE;
-
- return GL_TRUE;
-}
-
-
-/**
- * Clip dst coords against Xmax (or Ymax).
- */
-static INLINE void
-clip_right_or_top(GLint *srcX0, GLint *srcX1,
- GLint *dstX0, GLint *dstX1,
- GLint maxValue)
-{
- GLfloat t, bias;
-
- if (*dstX1 > maxValue) {
- /* X1 outside right edge */
- ASSERT(*dstX0 < maxValue); /* X0 should be inside right edge */
- t = (GLfloat) (maxValue - *dstX0) / (GLfloat) (*dstX1 - *dstX0);
- /* chop off [t, 1] part */
- ASSERT(t >= 0.0 && t <= 1.0);
- *dstX1 = maxValue;
- bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
- *srcX1 = *srcX0 + (GLint) (t * (*srcX1 - *srcX0) + bias);
- }
- else if (*dstX0 > maxValue) {
- /* X0 outside right edge */
- ASSERT(*dstX1 < maxValue); /* X1 should be inside right edge */
- t = (GLfloat) (maxValue - *dstX1) / (GLfloat) (*dstX0 - *dstX1);
- /* chop off [t, 1] part */
- ASSERT(t >= 0.0 && t <= 1.0);
- *dstX0 = maxValue;
- bias = (*srcX0 < *srcX1) ? -0.5F : 0.5F;
- *srcX0 = *srcX1 + (GLint) (t * (*srcX0 - *srcX1) + bias);
- }
-}
-
-
-/**
- * Clip dst coords against Xmin (or Ymin).
- */
-static INLINE void
-clip_left_or_bottom(GLint *srcX0, GLint *srcX1,
- GLint *dstX0, GLint *dstX1,
- GLint minValue)
-{
- GLfloat t, bias;
-
- if (*dstX0 < minValue) {
- /* X0 outside left edge */
- ASSERT(*dstX1 > minValue); /* X1 should be inside left edge */
- t = (GLfloat) (minValue - *dstX0) / (GLfloat) (*dstX1 - *dstX0);
- /* chop off [0, t] part */
- ASSERT(t >= 0.0 && t <= 1.0);
- *dstX0 = minValue;
- bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F; /* flipped??? */
- *srcX0 = *srcX0 + (GLint) (t * (*srcX1 - *srcX0) + bias);
- }
- else if (*dstX1 < minValue) {
- /* X1 outside left edge */
- ASSERT(*dstX0 > minValue); /* X0 should be inside left edge */
- t = (GLfloat) (minValue - *dstX1) / (GLfloat) (*dstX0 - *dstX1);
- /* chop off [0, t] part */
- ASSERT(t >= 0.0 && t <= 1.0);
- *dstX1 = minValue;
- bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
- *srcX1 = *srcX1 + (GLint) (t * (*srcX0 - *srcX1) + bias);
- }
-}
-
-
-/**
- * Do clipping of blit src/dest rectangles.
- * The dest rect is clipped against both the buffer bounds and scissor bounds.
- * The src rect is just clipped against the buffer bounds.
- *
- * When either the src or dest rect is clipped, the other is also clipped
- * proportionately!
- *
- * Note that X0 need not be less than X1 (same for Y) for either the source
- * and dest rects. That makes the clipping a little trickier.
- *
- * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
- */
-GLboolean
-_mesa_clip_blit(struct gl_context *ctx,
- GLint *srcX0, GLint *srcY0, GLint *srcX1, GLint *srcY1,
- GLint *dstX0, GLint *dstY0, GLint *dstX1, GLint *dstY1)
-{
- const GLint srcXmin = 0;
- const GLint srcXmax = ctx->ReadBuffer->Width;
- const GLint srcYmin = 0;
- const GLint srcYmax = ctx->ReadBuffer->Height;
-
- /* these include scissor bounds */
- const GLint dstXmin = ctx->DrawBuffer->_Xmin;
- const GLint dstXmax = ctx->DrawBuffer->_Xmax;
- const GLint dstYmin = ctx->DrawBuffer->_Ymin;
- const GLint dstYmax = ctx->DrawBuffer->_Ymax;
-
- /*
- printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
- *srcX0, *srcX1, *dstX0, *dstX1);
- printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
- *srcY0, *srcY1, *dstY0, *dstY1);
- */
-
- /* trivial rejection tests */
- if (*dstX0 == *dstX1)
- return GL_FALSE; /* no width */
- if (*dstX0 <= dstXmin && *dstX1 <= dstXmin)
- return GL_FALSE; /* totally out (left) of bounds */
- if (*dstX0 >= dstXmax && *dstX1 >= dstXmax)
- return GL_FALSE; /* totally out (right) of bounds */
-
- if (*dstY0 == *dstY1)
- return GL_FALSE;
- if (*dstY0 <= dstYmin && *dstY1 <= dstYmin)
- return GL_FALSE;
- if (*dstY0 >= dstYmax && *dstY1 >= dstYmax)
- return GL_FALSE;
-
- if (*srcX0 == *srcX1)
- return GL_FALSE;
- if (*srcX0 <= srcXmin && *srcX1 <= srcXmin)
- return GL_FALSE;
- if (*srcX0 >= srcXmax && *srcX1 >= srcXmax)
- return GL_FALSE;
-
- if (*srcY0 == *srcY1)
- return GL_FALSE;
- if (*srcY0 <= srcYmin && *srcY1 <= srcYmin)
- return GL_FALSE;
- if (*srcY0 >= srcYmax && *srcY1 >= srcYmax)
- return GL_FALSE;
-
- /*
- * dest clip
- */
- clip_right_or_top(srcX0, srcX1, dstX0, dstX1, dstXmax);
- clip_right_or_top(srcY0, srcY1, dstY0, dstY1, dstYmax);
- clip_left_or_bottom(srcX0, srcX1, dstX0, dstX1, dstXmin);
- clip_left_or_bottom(srcY0, srcY1, dstY0, dstY1, dstYmin);
-
- /*
- * src clip (just swap src/dst values from above)
- */
- clip_right_or_top(dstX0, dstX1, srcX0, srcX1, srcXmax);
- clip_right_or_top(dstY0, dstY1, srcY0, srcY1, srcYmax);
- clip_left_or_bottom(dstX0, dstX1, srcX0, srcX1, srcXmin);
- clip_left_or_bottom(dstY0, dstY1, srcY0, srcY1, srcYmin);
-
- /*
- printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
- *srcX0, *srcX1, *dstX0, *dstX1);
- printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
- *srcY0, *srcY1, *dstY0, *dstY1);
- */
-
- ASSERT(*dstX0 >= dstXmin);
- ASSERT(*dstX0 <= dstXmax);
- ASSERT(*dstX1 >= dstXmin);
- ASSERT(*dstX1 <= dstXmax);
-
- ASSERT(*dstY0 >= dstYmin);
- ASSERT(*dstY0 <= dstYmax);
- ASSERT(*dstY1 >= dstYmin);
- ASSERT(*dstY1 <= dstYmax);
-
- ASSERT(*srcX0 >= srcXmin);
- ASSERT(*srcX0 <= srcXmax);
- ASSERT(*srcX1 >= srcXmin);
- ASSERT(*srcX1 <= srcXmax);
-
- ASSERT(*srcY0 >= srcYmin);
- ASSERT(*srcY0 <= srcYmax);
- ASSERT(*srcY1 >= srcYmin);
- ASSERT(*srcY1 <= srcYmax);
-
- return GL_TRUE;
-}
+/*
+ * 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.
+ */
+
+
+/**
+ * \file image.c
+ * Image handling.
+ */
+
+
+#include "glheader.h"
+#include "colormac.h"
+#include "image.h"
+#include "imports.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+
+
+/**
+ * NOTE:
+ * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
+ * we later convert the float to a packed integer value (such as for
+ * GL_RGB5_A1) because we'll wind up with a non-zero value.
+ *
+ * We redefine the macros here so zero is handled correctly.
+ */
+#undef BYTE_TO_FLOAT
+#define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
+
+#undef SHORT_TO_FLOAT
+#define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
+
+
+
+/** Compute ceiling of integer quotient of A divided by B. */
+#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
+
+
+/**
+ * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
+ */
+GLboolean
+_mesa_type_is_packed(GLenum type)
+{
+ switch (type) {
+ case GL_UNSIGNED_BYTE_3_3_2:
+ case GL_UNSIGNED_BYTE_2_3_3_REV:
+ case MESA_UNSIGNED_BYTE_4_4:
+ case GL_UNSIGNED_SHORT_5_6_5:
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ case GL_UNSIGNED_INT_8_8_8_8:
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ case GL_UNSIGNED_INT_10_10_10_2:
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ case GL_UNSIGNED_SHORT_8_8_MESA:
+ case GL_UNSIGNED_SHORT_8_8_REV_MESA:
+ case GL_UNSIGNED_INT_24_8_EXT:
+ case GL_UNSIGNED_INT_5_9_9_9_REV:
+ case GL_UNSIGNED_INT_10F_11F_11F_REV:
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+
+
+/**
+ * Flip the order of the 2 bytes in each word in the given array.
+ *
+ * \param p array.
+ * \param n number of words.
+ */
+void
+_mesa_swap2( GLushort *p, GLuint n )
+{
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ p[i] = (p[i] >> 8) | ((p[i] << 8) & 0xff00);
+ }
+}
+
+
+
+/*
+ * Flip the order of the 4 bytes in each word in the given array.
+ */
+void
+_mesa_swap4( GLuint *p, GLuint n )
+{
+ GLuint i, a, b;
+ for (i = 0; i < n; i++) {
+ b = p[i];
+ a = (b >> 24)
+ | ((b >> 8) & 0xff00)
+ | ((b << 8) & 0xff0000)
+ | ((b << 24) & 0xff000000);
+ p[i] = a;
+ }
+}
+
+
+/**
+ * Get the size of a GL data type.
+ *
+ * \param type GL data type.
+ *
+ * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
+ * if an invalid type enum.
+ */
+GLint
+_mesa_sizeof_type( GLenum type )
+{
+ switch (type) {
+ case GL_BITMAP:
+ return 0;
+ case GL_UNSIGNED_BYTE:
+ return sizeof(GLubyte);
+ case GL_BYTE:
+ return sizeof(GLbyte);
+ case GL_UNSIGNED_SHORT:
+ return sizeof(GLushort);
+ case GL_SHORT:
+ return sizeof(GLshort);
+ case GL_UNSIGNED_INT:
+ return sizeof(GLuint);
+ case GL_INT:
+ return sizeof(GLint);
+ case GL_FLOAT:
+ return sizeof(GLfloat);
+ case GL_DOUBLE:
+ return sizeof(GLdouble);
+ case GL_HALF_FLOAT_ARB:
+ return sizeof(GLhalfARB);
+ case GL_FIXED:
+ return sizeof(GLfixed);
+ default:
+ return -1;
+ }
+}
+
+
+/**
+ * Same as _mesa_sizeof_type() but also accepting the packed pixel
+ * format data types.
+ */
+GLint
+_mesa_sizeof_packed_type( GLenum type )
+{
+ switch (type) {
+ case GL_BITMAP:
+ return 0;
+ case GL_UNSIGNED_BYTE:
+ return sizeof(GLubyte);
+ case GL_BYTE:
+ return sizeof(GLbyte);
+ case GL_UNSIGNED_SHORT:
+ return sizeof(GLushort);
+ case GL_SHORT:
+ return sizeof(GLshort);
+ case GL_UNSIGNED_INT:
+ return sizeof(GLuint);
+ case GL_INT:
+ return sizeof(GLint);
+ case GL_HALF_FLOAT_ARB:
+ return sizeof(GLhalfARB);
+ case GL_FLOAT:
+ return sizeof(GLfloat);
+ case GL_UNSIGNED_BYTE_3_3_2:
+ return sizeof(GLubyte);
+ case GL_UNSIGNED_BYTE_2_3_3_REV:
+ return sizeof(GLubyte);
+ case MESA_UNSIGNED_BYTE_4_4:
+ return sizeof(GLubyte);
+ case GL_UNSIGNED_SHORT_5_6_5:
+ return sizeof(GLushort);
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
+ return sizeof(GLushort);
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ return sizeof(GLushort);
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ return sizeof(GLushort);
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ return sizeof(GLushort);
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ return sizeof(GLushort);
+ case GL_UNSIGNED_INT_8_8_8_8:
+ return sizeof(GLuint);
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ return sizeof(GLuint);
+ case GL_UNSIGNED_INT_10_10_10_2:
+ return sizeof(GLuint);
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ return sizeof(GLuint);
+ case GL_UNSIGNED_SHORT_8_8_MESA:
+ case GL_UNSIGNED_SHORT_8_8_REV_MESA:
+ return sizeof(GLushort);
+ case GL_UNSIGNED_INT_24_8_EXT:
+ return sizeof(GLuint);
+ case GL_UNSIGNED_INT_5_9_9_9_REV:
+ return sizeof(GLuint);
+ case GL_UNSIGNED_INT_10F_11F_11F_REV:
+ return sizeof(GLuint);
+ default:
+ return -1;
+ }
+}
+
+
+/**
+ * Get the number of components in a pixel format.
+ *
+ * \param format pixel format.
+ *
+ * \return the number of components in the given format, or -1 if a bad format.
+ */
+GLint
+_mesa_components_in_format( GLenum format )
+{
+ switch (format) {
+ 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:
+ case GL_STENCIL_INDEX:
+ case GL_DEPTH_COMPONENT:
+ case GL_RED:
+ case GL_RED_INTEGER_EXT:
+ case GL_GREEN:
+ case GL_GREEN_INTEGER_EXT:
+ case GL_BLUE:
+ case GL_BLUE_INTEGER_EXT:
+ case GL_ALPHA:
+ case GL_ALPHA_INTEGER_EXT:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE_INTEGER_EXT:
+ case GL_INTENSITY:
+ return 1;
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ case GL_RG:
+ return 2;
+ case GL_RGB:
+ case GL_RGB_INTEGER_EXT:
+ return 3;
+ case GL_RGBA:
+ case GL_RGBA_INTEGER_EXT:
+ return 4;
+ case GL_BGR:
+ return 3;
+ case GL_BGRA:
+ return 4;
+ case GL_ABGR_EXT:
+ return 4;
+ case GL_YCBCR_MESA:
+ return 2;
+ case GL_DEPTH_STENCIL_EXT:
+ return 2;
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ return 2;
+ default:
+ return -1;
+ }
+}
+
+
+/**
+ * Get the bytes per pixel of pixel format type pair.
+ *
+ * \param format pixel format.
+ * \param type pixel type.
+ *
+ * \return bytes per pixel, or -1 if a bad format or type was given.
+ */
+GLint
+_mesa_bytes_per_pixel( GLenum format, GLenum type )
+{
+ GLint comps = _mesa_components_in_format( format );
+ if (comps < 0)
+ return -1;
+
+ switch (type) {
+ case GL_BITMAP:
+ return 0; /* special case */
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ return comps * sizeof(GLubyte);
+ case GL_SHORT:
+ case GL_UNSIGNED_SHORT:
+ return comps * sizeof(GLshort);
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ return comps * sizeof(GLint);
+ case GL_FLOAT:
+ return comps * sizeof(GLfloat);
+ case GL_HALF_FLOAT_ARB:
+ return comps * sizeof(GLhalfARB);
+ case GL_UNSIGNED_BYTE_3_3_2:
+ case GL_UNSIGNED_BYTE_2_3_3_REV:
+ if (format == GL_RGB || format == GL_BGR ||
+ format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT)
+ return sizeof(GLubyte);
+ else
+ return -1; /* error */
+ case GL_UNSIGNED_SHORT_5_6_5:
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
+ if (format == GL_RGB || format == GL_BGR ||
+ format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT)
+ return sizeof(GLushort);
+ else
+ return -1; /* error */
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT ||
+ format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT)
+ return sizeof(GLushort);
+ else
+ return -1;
+ case GL_UNSIGNED_INT_8_8_8_8:
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ case GL_UNSIGNED_INT_10_10_10_2:
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT ||
+ format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT)
+ return sizeof(GLuint);
+ else
+ return -1;
+ case GL_UNSIGNED_SHORT_8_8_MESA:
+ case GL_UNSIGNED_SHORT_8_8_REV_MESA:
+ if (format == GL_YCBCR_MESA)
+ return sizeof(GLushort);
+ else
+ return -1;
+ case GL_UNSIGNED_INT_24_8_EXT:
+ if (format == GL_DEPTH_STENCIL_EXT)
+ return sizeof(GLuint);
+ else
+ return -1;
+ case GL_UNSIGNED_INT_5_9_9_9_REV:
+ if (format == GL_RGB)
+ return sizeof(GLuint);
+ else
+ return -1;
+ case GL_UNSIGNED_INT_10F_11F_11F_REV:
+ if (format == GL_RGB)
+ return sizeof(GLuint);
+ else
+ return -1;
+ default:
+ return -1;
+ }
+}
+
+
+/**
+ * Test for a legal pixel format and type.
+ *
+ * \param format pixel format.
+ * \param type pixel type.
+ *
+ * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
+ * otherwise.
+ */
+GLboolean
+_mesa_is_legal_format_and_type(const struct gl_context *ctx,
+ GLenum format, GLenum type)
+{
+ switch (format) {
+ case GL_COLOR_INDEX:
+ case GL_STENCIL_INDEX:
+ switch (type) {
+ case GL_BITMAP:
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ case GL_SHORT:
+ case GL_UNSIGNED_SHORT:
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ case GL_FLOAT:
+ return GL_TRUE;
+ case GL_HALF_FLOAT_ARB:
+ return ctx->Extensions.ARB_half_float_pixel;
+ default:
+ return GL_FALSE;
+ }
+ case GL_RED:
+ case GL_GREEN:
+ case GL_BLUE:
+ case GL_ALPHA:
+#if 0 /* not legal! see table 3.6 of the 1.5 spec */
+ case GL_INTENSITY:
+#endif
+ case GL_LUMINANCE:
+ case GL_LUMINANCE_ALPHA:
+ case GL_DEPTH_COMPONENT:
+ 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:
+ return GL_TRUE;
+ case GL_HALF_FLOAT_ARB:
+ return ctx->Extensions.ARB_half_float_pixel;
+ default:
+ return GL_FALSE;
+ }
+ case GL_RG:
+ if (!ctx->Extensions.ARB_texture_rg)
+ return GL_FALSE;
+
+ 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:
+ return GL_TRUE;
+ case GL_HALF_FLOAT_ARB:
+ return ctx->Extensions.ARB_half_float_pixel;
+ default:
+ return GL_FALSE;
+ }
+ case GL_RGB:
+ 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_UNSIGNED_BYTE_3_3_2:
+ case GL_UNSIGNED_BYTE_2_3_3_REV:
+ case GL_UNSIGNED_SHORT_5_6_5:
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
+ return GL_TRUE;
+ case GL_HALF_FLOAT_ARB:
+ return ctx->Extensions.ARB_half_float_pixel;
+ case GL_UNSIGNED_INT_5_9_9_9_REV:
+ return ctx->Extensions.EXT_texture_shared_exponent;
+ case GL_UNSIGNED_INT_10F_11F_11F_REV:
+ return ctx->Extensions.EXT_packed_float;
+ default:
+ return GL_FALSE;
+ }
+ case GL_BGR:
+ switch (type) {
+ /* NOTE: no packed types are supported with BGR. That's
+ * intentional, according to the GL spec.
+ */
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ case GL_SHORT:
+ case GL_UNSIGNED_SHORT:
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ case GL_FLOAT:
+ return GL_TRUE;
+ case GL_HALF_FLOAT_ARB:
+ return ctx->Extensions.ARB_half_float_pixel;
+ default:
+ return GL_FALSE;
+ }
+ case GL_RGBA:
+ case GL_BGRA:
+ case GL_ABGR_EXT:
+ 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_UNSIGNED_SHORT_4_4_4_4:
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ case GL_UNSIGNED_INT_8_8_8_8:
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ case GL_UNSIGNED_INT_10_10_10_2:
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ return GL_TRUE;
+ case GL_HALF_FLOAT_ARB:
+ return ctx->Extensions.ARB_half_float_pixel;
+ default:
+ return GL_FALSE;
+ }
+ case GL_YCBCR_MESA:
+ if (type == GL_UNSIGNED_SHORT_8_8_MESA ||
+ type == GL_UNSIGNED_SHORT_8_8_REV_MESA)
+ return GL_TRUE;
+ else
+ return GL_FALSE;
+ case GL_DEPTH_STENCIL_EXT:
+ if (ctx->Extensions.EXT_packed_depth_stencil
+ && type == GL_UNSIGNED_INT_24_8_EXT)
+ return GL_TRUE;
+ else
+ return GL_FALSE;
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ 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:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+
+ /* integer-valued formats */
+ case GL_RED_INTEGER_EXT:
+ case GL_GREEN_INTEGER_EXT:
+ case GL_BLUE_INTEGER_EXT:
+ case GL_ALPHA_INTEGER_EXT:
+ switch (type) {
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ case GL_SHORT:
+ case GL_UNSIGNED_SHORT:
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ return ctx->Extensions.EXT_texture_integer;
+ default:
+ return GL_FALSE;
+ }
+
+ case GL_RGB_INTEGER_EXT:
+ 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_UNSIGNED_BYTE_3_3_2:
+ case GL_UNSIGNED_BYTE_2_3_3_REV:
+ case GL_UNSIGNED_SHORT_5_6_5:
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
+ return ctx->Extensions.EXT_texture_integer;
+ default:
+ return GL_FALSE;
+ }
+
+ case GL_BGR_INTEGER_EXT:
+ switch (type) {
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ case GL_SHORT:
+ case GL_UNSIGNED_SHORT:
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ /* NOTE: no packed formats w/ BGR format */
+ return ctx->Extensions.EXT_texture_integer;
+ default:
+ return GL_FALSE;
+ }
+
+ case GL_RGBA_INTEGER_EXT:
+ case GL_BGRA_INTEGER_EXT:
+ 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_UNSIGNED_SHORT_4_4_4_4:
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ case GL_UNSIGNED_INT_8_8_8_8:
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ case GL_UNSIGNED_INT_10_10_10_2:
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ return ctx->Extensions.EXT_texture_integer;
+ default:
+ return GL_FALSE;
+ }
+
+ case GL_LUMINANCE_INTEGER_EXT:
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ switch (type) {
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ case GL_SHORT:
+ case GL_UNSIGNED_SHORT:
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ return ctx->Extensions.EXT_texture_integer;
+ default:
+ return GL_FALSE;
+ }
+
+ default:
+ ; /* fall-through */
+ }
+ return GL_FALSE;
+}
+
+
+/**
+ * Test if the given image format is a color/RGBA format (i.e., not color
+ * index, depth, stencil, etc).
+ * \param format the image format value (may by an internal texture format)
+ * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
+ */
+GLboolean
+_mesa_is_color_format(GLenum format)
+{
+ switch (format) {
+ case GL_RED:
+ case GL_GREEN:
+ case GL_BLUE:
+ case GL_ALPHA:
+ case GL_ALPHA4:
+ case GL_ALPHA8:
+ case GL_ALPHA12:
+ case GL_ALPHA16:
+ case 1:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE4:
+ case GL_LUMINANCE8:
+ case GL_LUMINANCE12:
+ case GL_LUMINANCE16:
+ 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:
+ case GL_INTENSITY:
+ case GL_INTENSITY4:
+ case GL_INTENSITY8:
+ case GL_INTENSITY12:
+ case GL_INTENSITY16:
+ case GL_R8:
+ case GL_R16:
+ case GL_RG:
+ case GL_RG8:
+ case GL_RG16:
+ case 3:
+ case GL_RGB:
+ case GL_BGR:
+ case GL_R3_G3_B2:
+ case GL_RGB4:
+ case GL_RGB5:
+ case GL_RGB8:
+ case GL_RGB10:
+ case GL_RGB12:
+ case GL_RGB16:
+ case 4:
+ case GL_ABGR_EXT:
+ case GL_RGBA:
+ case GL_BGRA:
+ case GL_RGBA2:
+ case GL_RGBA4:
+ case GL_RGB5_A1:
+ case GL_RGBA8:
+ case GL_RGB10_A2:
+ case GL_RGBA12:
+ case GL_RGBA16:
+ /* float texture formats */
+ case GL_ALPHA16F_ARB:
+ case GL_ALPHA32F_ARB:
+ case GL_LUMINANCE16F_ARB:
+ case GL_LUMINANCE32F_ARB:
+ case GL_LUMINANCE_ALPHA16F_ARB:
+ case GL_LUMINANCE_ALPHA32F_ARB:
+ case GL_INTENSITY16F_ARB:
+ case GL_INTENSITY32F_ARB:
+ case GL_R16F:
+ case GL_R32F:
+ case GL_RG16F:
+ case GL_RG32F:
+ case GL_RGB16F_ARB:
+ case GL_RGB32F_ARB:
+ case GL_RGBA16F_ARB:
+ case GL_RGBA32F_ARB:
+ /* compressed formats */
+ case GL_COMPRESSED_ALPHA:
+ case GL_COMPRESSED_LUMINANCE:
+ case GL_COMPRESSED_LUMINANCE_ALPHA:
+ case GL_COMPRESSED_INTENSITY:
+ case GL_COMPRESSED_RED:
+ case GL_COMPRESSED_RG:
+ case GL_COMPRESSED_RGB:
+ case GL_COMPRESSED_RGBA:
+ case GL_RGB_S3TC:
+ case GL_RGB4_S3TC:
+ case GL_RGBA_S3TC:
+ case GL_RGBA4_S3TC:
+ case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+ case GL_COMPRESSED_RGB_FXT1_3DFX:
+ case GL_COMPRESSED_RGBA_FXT1_3DFX:
+#if FEATURE_EXT_texture_sRGB
+ case GL_SRGB_EXT:
+ case GL_SRGB8_EXT:
+ case GL_SRGB_ALPHA_EXT:
+ case GL_SRGB8_ALPHA8_EXT:
+ case GL_SLUMINANCE_ALPHA_EXT:
+ case GL_SLUMINANCE8_ALPHA8_EXT:
+ case GL_SLUMINANCE_EXT:
+ case GL_SLUMINANCE8_EXT:
+ case GL_COMPRESSED_SRGB_EXT:
+ case GL_COMPRESSED_SRGB_S3TC_DXT1_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:
+ case GL_COMPRESSED_SLUMINANCE_EXT:
+ case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
+#endif /* FEATURE_EXT_texture_sRGB */
+ case GL_COMPRESSED_RED_RGTC1:
+ case GL_COMPRESSED_SIGNED_RED_RGTC1:
+ case GL_COMPRESSED_RG_RGTC2:
+ case GL_COMPRESSED_SIGNED_RG_RGTC2:
+ case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
+ case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
+ case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
+ case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
+ case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
+ /* generic integer formats */
+ 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:
+ /* sized integer formats */
+ 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:
+ 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:
+ 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:
+ 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:
+ 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:
+ 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:
+ /* signed, normalized texture formats */
+ case GL_RED_SNORM:
+ case GL_R8_SNORM:
+ case GL_R16_SNORM:
+ case GL_RG_SNORM:
+ case GL_RG8_SNORM:
+ case GL_RG16_SNORM:
+ case GL_RGB_SNORM:
+ case GL_RGB8_SNORM:
+ case GL_RGB16_SNORM:
+ case GL_RGBA_SNORM:
+ case GL_RGBA8_SNORM:
+ case GL_RGBA16_SNORM:
+ case GL_ALPHA_SNORM:
+ case GL_ALPHA8_SNORM:
+ case GL_ALPHA16_SNORM:
+ case GL_LUMINANCE_SNORM:
+ case GL_LUMINANCE8_SNORM:
+ case GL_LUMINANCE16_SNORM:
+ case GL_LUMINANCE_ALPHA_SNORM:
+ case GL_LUMINANCE8_ALPHA8_SNORM:
+ case GL_LUMINANCE16_ALPHA16_SNORM:
+ case GL_INTENSITY_SNORM:
+ case GL_INTENSITY8_SNORM:
+ case GL_INTENSITY16_SNORM:
+ case GL_RGB9_E5:
+ case GL_R11F_G11F_B10F:
+ return GL_TRUE;
+ case GL_YCBCR_MESA: /* not considered to be RGB */
+ /* fall-through */
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test if the given image format is a color index format.
+ */
+GLboolean
+_mesa_is_index_format(GLenum format)
+{
+ switch (format) {
+ 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_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test if the given image format is a depth component format.
+ */
+GLboolean
+_mesa_is_depth_format(GLenum format)
+{
+ switch (format) {
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_COMPONENT16:
+ case GL_DEPTH_COMPONENT24:
+ case GL_DEPTH_COMPONENT32:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test if the given image format is a stencil format.
+ */
+GLboolean
+_mesa_is_stencil_format(GLenum format)
+{
+ switch (format) {
+ case GL_STENCIL_INDEX:
+ case GL_DEPTH_STENCIL:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test if the given image format is a YCbCr format.
+ */
+GLboolean
+_mesa_is_ycbcr_format(GLenum format)
+{
+ switch (format) {
+ case GL_YCBCR_MESA:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test if the given image format is a depth+stencil format.
+ */
+GLboolean
+_mesa_is_depthstencil_format(GLenum format)
+{
+ switch (format) {
+ case GL_DEPTH24_STENCIL8_EXT:
+ case GL_DEPTH_STENCIL_EXT:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test if the given image format is a depth or stencil format.
+ */
+GLboolean
+_mesa_is_depth_or_stencil_format(GLenum format)
+{
+ switch (format) {
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_COMPONENT16:
+ case GL_DEPTH_COMPONENT24:
+ case GL_DEPTH_COMPONENT32:
+ case GL_STENCIL_INDEX:
+ case GL_STENCIL_INDEX1_EXT:
+ case GL_STENCIL_INDEX4_EXT:
+ case GL_STENCIL_INDEX8_EXT:
+ case GL_STENCIL_INDEX16_EXT:
+ case GL_DEPTH_STENCIL_EXT:
+ case GL_DEPTH24_STENCIL8_EXT:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test if the given image format is a dudv format.
+ */
+GLboolean
+_mesa_is_dudv_format(GLenum format)
+{
+ switch (format) {
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test if the given format is an integer (non-normalized) format.
+ */
+GLboolean
+_mesa_is_integer_format(GLenum format)
+{
+ switch (format) {
+ /* generic integer formats */
+ 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:
+ /* specific integer formats */
+ 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:
+ 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:
+ 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:
+ 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:
+ 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:
+ 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 GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Test if an image format is a supported compressed format.
+ * \param format the internal format token provided by the user.
+ * \return GL_TRUE if compressed, GL_FALSE if uncompressed
+ */
+GLboolean
+_mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
+{
+ switch (format) {
+ case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+ return ctx->Extensions.EXT_texture_compression_s3tc;
+ case GL_RGB_S3TC:
+ case GL_RGB4_S3TC:
+ case GL_RGBA_S3TC:
+ case GL_RGBA4_S3TC:
+ return ctx->Extensions.S3_s3tc;
+ case GL_COMPRESSED_SRGB_S3TC_DXT1_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 ctx->Extensions.EXT_texture_sRGB
+ && ctx->Extensions.EXT_texture_compression_s3tc;
+ case GL_COMPRESSED_RGB_FXT1_3DFX:
+ case GL_COMPRESSED_RGBA_FXT1_3DFX:
+ return ctx->Extensions.TDFX_texture_compression_FXT1;
+ case GL_COMPRESSED_RED_RGTC1:
+ case GL_COMPRESSED_SIGNED_RED_RGTC1:
+ case GL_COMPRESSED_RG_RGTC2:
+ case GL_COMPRESSED_SIGNED_RG_RGTC2:
+ return ctx->Extensions.ARB_texture_compression_rgtc;
+ case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
+ case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
+ case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
+ case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
+ return ctx->Extensions.EXT_texture_compression_latc;
+ case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
+ return ctx->Extensions.ATI_texture_compression_3dc;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Return the address of a specific pixel in an image (1D, 2D or 3D).
+ *
+ * Pixel unpacking/packing parameters are observed according to \p packing.
+ *
+ * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
+ * \param image starting address of image data
+ * \param width the image width
+ * \param height theimage height
+ * \param format the pixel format
+ * \param type the pixel data type
+ * \param packing the pixelstore attributes
+ * \param img which image in the volume (0 for 1D or 2D images)
+ * \param row row of pixel in the image (0 for 1D images)
+ * \param column column of pixel in the image
+ *
+ * \return address of pixel on success, or NULL on error.
+ *
+ * \sa gl_pixelstore_attrib.
+ */
+GLvoid *
+_mesa_image_address( GLuint dimensions,
+ const struct gl_pixelstore_attrib *packing,
+ const GLvoid *image,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLint img, GLint row, GLint column )
+{
+ GLint alignment; /* 1, 2 or 4 */
+ GLint pixels_per_row;
+ GLint rows_per_image;
+ GLint skiprows;
+ GLint skippixels;
+ GLint skipimages; /* for 3-D volume images */
+ GLubyte *pixel_addr;
+
+ ASSERT(dimensions >= 1 && dimensions <= 3);
+
+ alignment = packing->Alignment;
+ if (packing->RowLength > 0) {
+ pixels_per_row = packing->RowLength;
+ }
+ else {
+ pixels_per_row = width;
+ }
+ if (packing->ImageHeight > 0) {
+ rows_per_image = packing->ImageHeight;
+ }
+ else {
+ rows_per_image = height;
+ }
+
+ skippixels = packing->SkipPixels;
+ /* Note: SKIP_ROWS _is_ used for 1D images */
+ skiprows = packing->SkipRows;
+ /* Note: SKIP_IMAGES is only used for 3D images */
+ skipimages = (dimensions == 3) ? packing->SkipImages : 0;
+
+ if (type == GL_BITMAP) {
+ /* BITMAP data */
+ GLint comp_per_pixel; /* components per pixel */
+ GLint bytes_per_comp; /* bytes per component */
+ GLint bytes_per_row;
+ GLint bytes_per_image;
+
+ /* Compute bytes per component */
+ bytes_per_comp = _mesa_sizeof_packed_type( type );
+ if (bytes_per_comp < 0) {
+ return NULL;
+ }
+
+ /* Compute number of components per pixel */
+ comp_per_pixel = _mesa_components_in_format( format );
+ if (comp_per_pixel < 0) {
+ return NULL;
+ }
+
+ bytes_per_row = alignment
+ * CEILING( comp_per_pixel*pixels_per_row, 8*alignment );
+
+ bytes_per_image = bytes_per_row * rows_per_image;
+
+ pixel_addr = (GLubyte *) image
+ + (skipimages + img) * bytes_per_image
+ + (skiprows + row) * bytes_per_row
+ + (skippixels + column) / 8;
+ }
+ else {
+ /* Non-BITMAP data */
+ GLint bytes_per_pixel, bytes_per_row, remainder, bytes_per_image;
+ GLint topOfImage;
+
+ bytes_per_pixel = _mesa_bytes_per_pixel( format, type );
+
+ /* The pixel type and format should have been error checked earlier */
+ assert(bytes_per_pixel > 0);
+
+ bytes_per_row = pixels_per_row * bytes_per_pixel;
+ remainder = bytes_per_row % alignment;
+ if (remainder > 0)
+ bytes_per_row += (alignment - remainder);
+
+ ASSERT(bytes_per_row % alignment == 0);
+
+ bytes_per_image = bytes_per_row * rows_per_image;
+
+ if (packing->Invert) {
+ /* set pixel_addr to the last row */
+ topOfImage = bytes_per_row * (height - 1);
+ bytes_per_row = -bytes_per_row;
+ }
+ else {
+ topOfImage = 0;
+ }
+
+ /* compute final pixel address */
+ pixel_addr = (GLubyte *) image
+ + (skipimages + img) * bytes_per_image
+ + topOfImage
+ + (skiprows + row) * bytes_per_row
+ + (skippixels + column) * bytes_per_pixel;
+ }
+
+ return (GLvoid *) pixel_addr;
+}
+
+
+GLvoid *
+_mesa_image_address1d( const struct gl_pixelstore_attrib *packing,
+ const GLvoid *image,
+ GLsizei width,
+ GLenum format, GLenum type,
+ GLint column )
+{
+ return _mesa_image_address(1, packing, image, width, 1,
+ format, type, 0, 0, column);
+}
+
+
+GLvoid *
+_mesa_image_address2d( const struct gl_pixelstore_attrib *packing,
+ const GLvoid *image,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLint row, GLint column )
+{
+ return _mesa_image_address(2, packing, image, width, height,
+ format, type, 0, row, column);
+}
+
+
+GLvoid *
+_mesa_image_address3d( const struct gl_pixelstore_attrib *packing,
+ const GLvoid *image,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLint img, GLint row, GLint column )
+{
+ return _mesa_image_address(3, packing, image, width, height,
+ format, type, img, row, column);
+}
+
+
+
+/**
+ * Compute the stride (in bytes) between image rows.
+ *
+ * \param packing the pixelstore attributes
+ * \param width image width.
+ * \param format pixel format.
+ * \param type pixel data type.
+ *
+ * \return the stride in bytes for the given parameters, or -1 if error
+ */
+GLint
+_mesa_image_row_stride( const struct gl_pixelstore_attrib *packing,
+ GLint width, GLenum format, GLenum type )
+{
+ GLint bytesPerRow, remainder;
+
+ ASSERT(packing);
+
+ if (type == GL_BITMAP) {
+ if (packing->RowLength == 0) {
+ bytesPerRow = (width + 7) / 8;
+ }
+ else {
+ bytesPerRow = (packing->RowLength + 7) / 8;
+ }
+ }
+ else {
+ /* Non-BITMAP data */
+ const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
+ if (bytesPerPixel <= 0)
+ return -1; /* error */
+ if (packing->RowLength == 0) {
+ bytesPerRow = bytesPerPixel * width;
+ }
+ else {
+ bytesPerRow = bytesPerPixel * packing->RowLength;
+ }
+ }
+
+ remainder = bytesPerRow % packing->Alignment;
+ if (remainder > 0) {
+ bytesPerRow += (packing->Alignment - remainder);
+ }
+
+ if (packing->Invert) {
+ /* negate the bytes per row (negative row stride) */
+ bytesPerRow = -bytesPerRow;
+ }
+
+ return bytesPerRow;
+}
+
+
+/*
+ * Compute the stride between images in a 3D texture (in bytes) for the given
+ * pixel packing parameters and image width, format and type.
+ */
+GLint
+_mesa_image_image_stride( const struct gl_pixelstore_attrib *packing,
+ GLint width, GLint height,
+ GLenum format, GLenum type )
+{
+ GLint bytesPerRow, bytesPerImage, remainder;
+
+ ASSERT(packing);
+
+ if (type == GL_BITMAP) {
+ if (packing->RowLength == 0) {
+ bytesPerRow = (width + 7) / 8;
+ }
+ else {
+ bytesPerRow = (packing->RowLength + 7) / 8;
+ }
+ }
+ else {
+ const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
+
+ if (bytesPerPixel <= 0)
+ return -1; /* error */
+ if (packing->RowLength == 0) {
+ bytesPerRow = bytesPerPixel * width;
+ }
+ else {
+ bytesPerRow = bytesPerPixel * packing->RowLength;
+ }
+ }
+
+ remainder = bytesPerRow % packing->Alignment;
+ if (remainder > 0)
+ bytesPerRow += (packing->Alignment - remainder);
+
+ if (packing->ImageHeight == 0)
+ bytesPerImage = bytesPerRow * height;
+ else
+ bytesPerImage = bytesPerRow * packing->ImageHeight;
+
+ return bytesPerImage;
+}
+
+
+
+/**
+ * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
+ * This is typically used to convert a bitmap into a GLubyte/pixel texture.
+ * "On" bits will set texels to \p onValue.
+ * "Off" bits will not modify texels.
+ * \param width src bitmap width in pixels
+ * \param height src bitmap height in pixels
+ * \param unpack bitmap unpacking state
+ * \param bitmap the src bitmap data
+ * \param destBuffer start of dest buffer
+ * \param destStride row stride in dest buffer
+ * \param onValue if bit is 1, set destBuffer pixel to this value
+ */
+void
+_mesa_expand_bitmap(GLsizei width, GLsizei height,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLubyte *bitmap,
+ GLubyte *destBuffer, GLint destStride,
+ GLubyte onValue)
+{
+ const GLubyte *srcRow = (const GLubyte *)
+ _mesa_image_address2d(unpack, bitmap, width, height,
+ GL_COLOR_INDEX, GL_BITMAP, 0, 0);
+ const GLint srcStride = _mesa_image_row_stride(unpack, width,
+ GL_COLOR_INDEX, GL_BITMAP);
+ GLint row, col;
+
+#define SET_PIXEL(COL, ROW) \
+ destBuffer[(ROW) * destStride + (COL)] = onValue;
+
+ for (row = 0; row < height; row++) {
+ const GLubyte *src = srcRow;
+
+ if (unpack->LsbFirst) {
+ /* Lsb first */
+ GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
+ for (col = 0; col < width; col++) {
+
+ if (*src & mask) {
+ SET_PIXEL(col, row);
+ }
+
+ 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) {
+ SET_PIXEL(col, row);
+ }
+
+ if (mask == 1U) {
+ src++;
+ mask = 128U;
+ }
+ else {
+ mask = mask >> 1;
+ }
+ }
+
+ /* get ready for next row */
+ if (mask != 128)
+ src++;
+ }
+
+ srcRow += srcStride;
+ } /* row */
+
+#undef SET_PIXEL
+}
+
+
+
+
+/**
+ * Convert an array of RGBA colors from one datatype to another.
+ * NOTE: src may equal dst. In that case, we use a temporary buffer.
+ */
+void
+_mesa_convert_colors(GLenum srcType, const GLvoid *src,
+ GLenum dstType, GLvoid *dst,
+ GLuint count, const GLubyte mask[])
+{
+ GLuint tempBuffer[MAX_WIDTH][4];
+ const GLboolean useTemp = (src == dst);
+
+ ASSERT(srcType != dstType);
+
+ switch (srcType) {
+ case GL_UNSIGNED_BYTE:
+ if (dstType == GL_UNSIGNED_SHORT) {
+ const GLubyte (*src1)[4] = (const GLubyte (*)[4]) src;
+ GLushort (*dst2)[4] = (GLushort (*)[4]) (useTemp ? tempBuffer : dst);
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst2[i][RCOMP] = UBYTE_TO_USHORT(src1[i][RCOMP]);
+ dst2[i][GCOMP] = UBYTE_TO_USHORT(src1[i][GCOMP]);
+ dst2[i][BCOMP] = UBYTE_TO_USHORT(src1[i][BCOMP]);
+ dst2[i][ACOMP] = UBYTE_TO_USHORT(src1[i][ACOMP]);
+ }
+ }
+ if (useTemp)
+ memcpy(dst, tempBuffer, count * 4 * sizeof(GLushort));
+ }
+ else {
+ const GLubyte (*src1)[4] = (const GLubyte (*)[4]) src;
+ GLfloat (*dst4)[4] = (GLfloat (*)[4]) (useTemp ? tempBuffer : dst);
+ GLuint i;
+ ASSERT(dstType == GL_FLOAT);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst4[i][RCOMP] = UBYTE_TO_FLOAT(src1[i][RCOMP]);
+ dst4[i][GCOMP] = UBYTE_TO_FLOAT(src1[i][GCOMP]);
+ dst4[i][BCOMP] = UBYTE_TO_FLOAT(src1[i][BCOMP]);
+ dst4[i][ACOMP] = UBYTE_TO_FLOAT(src1[i][ACOMP]);
+ }
+ }
+ if (useTemp)
+ memcpy(dst, tempBuffer, count * 4 * sizeof(GLfloat));
+ }
+ break;
+ case GL_UNSIGNED_SHORT:
+ if (dstType == GL_UNSIGNED_BYTE) {
+ const GLushort (*src2)[4] = (const GLushort (*)[4]) src;
+ GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst);
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst1[i][RCOMP] = USHORT_TO_UBYTE(src2[i][RCOMP]);
+ dst1[i][GCOMP] = USHORT_TO_UBYTE(src2[i][GCOMP]);
+ dst1[i][BCOMP] = USHORT_TO_UBYTE(src2[i][BCOMP]);
+ dst1[i][ACOMP] = USHORT_TO_UBYTE(src2[i][ACOMP]);
+ }
+ }
+ if (useTemp)
+ memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte));
+ }
+ else {
+ const GLushort (*src2)[4] = (const GLushort (*)[4]) src;
+ GLfloat (*dst4)[4] = (GLfloat (*)[4]) (useTemp ? tempBuffer : dst);
+ GLuint i;
+ ASSERT(dstType == GL_FLOAT);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ dst4[i][RCOMP] = USHORT_TO_FLOAT(src2[i][RCOMP]);
+ dst4[i][GCOMP] = USHORT_TO_FLOAT(src2[i][GCOMP]);
+ dst4[i][BCOMP] = USHORT_TO_FLOAT(src2[i][BCOMP]);
+ dst4[i][ACOMP] = USHORT_TO_FLOAT(src2[i][ACOMP]);
+ }
+ }
+ if (useTemp)
+ memcpy(dst, tempBuffer, count * 4 * sizeof(GLfloat));
+ }
+ break;
+ case GL_FLOAT:
+ if (dstType == GL_UNSIGNED_BYTE) {
+ const GLfloat (*src4)[4] = (const GLfloat (*)[4]) src;
+ GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst);
+ GLuint i;
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][RCOMP], src4[i][RCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][GCOMP], src4[i][GCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][BCOMP], src4[i][BCOMP]);
+ UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][ACOMP], src4[i][ACOMP]);
+ }
+ }
+ if (useTemp)
+ memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte));
+ }
+ else {
+ const GLfloat (*src4)[4] = (const GLfloat (*)[4]) src;
+ GLushort (*dst2)[4] = (GLushort (*)[4]) (useTemp ? tempBuffer : dst);
+ GLuint i;
+ ASSERT(dstType == GL_UNSIGNED_SHORT);
+ for (i = 0; i < count; i++) {
+ if (!mask || mask[i]) {
+ UNCLAMPED_FLOAT_TO_USHORT(dst2[i][RCOMP], src4[i][RCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(dst2[i][GCOMP], src4[i][GCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(dst2[i][BCOMP], src4[i][BCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(dst2[i][ACOMP], src4[i][ACOMP]);
+ }
+ }
+ if (useTemp)
+ memcpy(dst, tempBuffer, count * 4 * sizeof(GLushort));
+ }
+ break;
+ default:
+ _mesa_problem(NULL, "Invalid datatype in _mesa_convert_colors");
+ }
+}
+
+
+
+
+/**
+ * Perform basic clipping for glDrawPixels. The image's position and size
+ * and the unpack SkipPixels and SkipRows are adjusted so that the image
+ * region is entirely within the window and scissor bounds.
+ * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
+ * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
+ * we'll actually write. Beforehand, *destY-1 is the first drawing row.
+ *
+ * \return GL_TRUE if image is ready for drawing or
+ * GL_FALSE if image was completely clipped away (draw nothing)
+ */
+GLboolean
+_mesa_clip_drawpixels(const struct gl_context *ctx,
+ GLint *destX, GLint *destY,
+ GLsizei *width, GLsizei *height,
+ struct gl_pixelstore_attrib *unpack)
+{
+ const struct gl_framebuffer *buffer = ctx->DrawBuffer;
+
+ if (unpack->RowLength == 0) {
+ unpack->RowLength = *width;
+ }
+
+ ASSERT(ctx->Pixel.ZoomX == 1.0F);
+ ASSERT(ctx->Pixel.ZoomY == 1.0F || ctx->Pixel.ZoomY == -1.0F);
+
+ /* left clipping */
+ if (*destX < buffer->_Xmin) {
+ unpack->SkipPixels += (buffer->_Xmin - *destX);
+ *width -= (buffer->_Xmin - *destX);
+ *destX = buffer->_Xmin;
+ }
+ /* right clipping */
+ if (*destX + *width > buffer->_Xmax)
+ *width -= (*destX + *width - buffer->_Xmax);
+
+ if (*width <= 0)
+ return GL_FALSE;
+
+ if (ctx->Pixel.ZoomY == 1.0F) {
+ /* bottom clipping */
+ if (*destY < buffer->_Ymin) {
+ unpack->SkipRows += (buffer->_Ymin - *destY);
+ *height -= (buffer->_Ymin - *destY);
+ *destY = buffer->_Ymin;
+ }
+ /* top clipping */
+ if (*destY + *height > buffer->_Ymax)
+ *height -= (*destY + *height - buffer->_Ymax);
+ }
+ else { /* upside down */
+ /* top clipping */
+ if (*destY > buffer->_Ymax) {
+ unpack->SkipRows += (*destY - buffer->_Ymax);
+ *height -= (*destY - buffer->_Ymax);
+ *destY = buffer->_Ymax;
+ }
+ /* bottom clipping */
+ if (*destY - *height < buffer->_Ymin)
+ *height -= (buffer->_Ymin - (*destY - *height));
+ /* adjust destY so it's the first row to write to */
+ (*destY)--;
+ }
+
+ if (*height <= 0)
+ return GL_FALSE;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Perform clipping for glReadPixels. The image's window position
+ * and size, and the pack skipPixels, skipRows and rowLength are adjusted
+ * so that the image region is entirely within the window bounds.
+ * Note: this is different from _mesa_clip_drawpixels() in that the
+ * scissor box is ignored, and we use the bounds of the current readbuffer
+ * surface.
+ *
+ * \return GL_TRUE if region to read is in bounds
+ * GL_FALSE if region is completely out of bounds (nothing to read)
+ */
+GLboolean
+_mesa_clip_readpixels(const struct gl_context *ctx,
+ GLint *srcX, GLint *srcY,
+ GLsizei *width, GLsizei *height,
+ struct gl_pixelstore_attrib *pack)
+{
+ const struct gl_framebuffer *buffer = ctx->ReadBuffer;
+
+ if (pack->RowLength == 0) {
+ pack->RowLength = *width;
+ }
+
+ /* left clipping */
+ if (*srcX < 0) {
+ pack->SkipPixels += (0 - *srcX);
+ *width -= (0 - *srcX);
+ *srcX = 0;
+ }
+ /* right clipping */
+ if (*srcX + *width > (GLsizei) buffer->Width)
+ *width -= (*srcX + *width - buffer->Width);
+
+ if (*width <= 0)
+ return GL_FALSE;
+
+ /* bottom clipping */
+ if (*srcY < 0) {
+ pack->SkipRows += (0 - *srcY);
+ *height -= (0 - *srcY);
+ *srcY = 0;
+ }
+ /* top clipping */
+ if (*srcY + *height > (GLsizei) buffer->Height)
+ *height -= (*srcY + *height - buffer->Height);
+
+ if (*height <= 0)
+ return GL_FALSE;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Do clipping for a glCopyTexSubImage call.
+ * The framebuffer source region might extend outside the framebuffer
+ * bounds. Clip the source region against the framebuffer bounds and
+ * adjust the texture/dest position and size accordingly.
+ *
+ * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
+ */
+GLboolean
+_mesa_clip_copytexsubimage(const struct gl_context *ctx,
+ GLint *destX, GLint *destY,
+ GLint *srcX, GLint *srcY,
+ GLsizei *width, GLsizei *height)
+{
+ const struct gl_framebuffer *fb = ctx->ReadBuffer;
+ const GLint srcX0 = *srcX, srcY0 = *srcY;
+
+ if (_mesa_clip_to_region(0, 0, fb->Width, fb->Height,
+ srcX, srcY, width, height)) {
+ *destX = *destX + *srcX - srcX0;
+ *destY = *destY + *srcY - srcY0;
+
+ return GL_TRUE;
+ }
+ else {
+ return GL_FALSE;
+ }
+}
+
+
+
+/**
+ * Clip the rectangle defined by (x, y, width, height) against the bounds
+ * specified by [xmin, xmax) and [ymin, ymax).
+ * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
+ */
+GLboolean
+_mesa_clip_to_region(GLint xmin, GLint ymin,
+ GLint xmax, GLint ymax,
+ GLint *x, GLint *y,
+ GLsizei *width, GLsizei *height )
+{
+ /* left clipping */
+ if (*x < xmin) {
+ *width -= (xmin - *x);
+ *x = xmin;
+ }
+
+ /* right clipping */
+ if (*x + *width > xmax)
+ *width -= (*x + *width - xmax);
+
+ if (*width <= 0)
+ return GL_FALSE;
+
+ /* bottom (or top) clipping */
+ if (*y < ymin) {
+ *height -= (ymin - *y);
+ *y = ymin;
+ }
+
+ /* top (or bottom) clipping */
+ if (*y + *height > ymax)
+ *height -= (*y + *height - ymax);
+
+ if (*height <= 0)
+ return GL_FALSE;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Clip dst coords against Xmax (or Ymax).
+ */
+static INLINE void
+clip_right_or_top(GLint *srcX0, GLint *srcX1,
+ GLint *dstX0, GLint *dstX1,
+ GLint maxValue)
+{
+ GLfloat t, bias;
+
+ if (*dstX1 > maxValue) {
+ /* X1 outside right edge */
+ ASSERT(*dstX0 < maxValue); /* X0 should be inside right edge */
+ t = (GLfloat) (maxValue - *dstX0) / (GLfloat) (*dstX1 - *dstX0);
+ /* chop off [t, 1] part */
+ ASSERT(t >= 0.0 && t <= 1.0);
+ *dstX1 = maxValue;
+ bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
+ *srcX1 = *srcX0 + (GLint) (t * (*srcX1 - *srcX0) + bias);
+ }
+ else if (*dstX0 > maxValue) {
+ /* X0 outside right edge */
+ ASSERT(*dstX1 < maxValue); /* X1 should be inside right edge */
+ t = (GLfloat) (maxValue - *dstX1) / (GLfloat) (*dstX0 - *dstX1);
+ /* chop off [t, 1] part */
+ ASSERT(t >= 0.0 && t <= 1.0);
+ *dstX0 = maxValue;
+ bias = (*srcX0 < *srcX1) ? -0.5F : 0.5F;
+ *srcX0 = *srcX1 + (GLint) (t * (*srcX0 - *srcX1) + bias);
+ }
+}
+
+
+/**
+ * Clip dst coords against Xmin (or Ymin).
+ */
+static INLINE void
+clip_left_or_bottom(GLint *srcX0, GLint *srcX1,
+ GLint *dstX0, GLint *dstX1,
+ GLint minValue)
+{
+ GLfloat t, bias;
+
+ if (*dstX0 < minValue) {
+ /* X0 outside left edge */
+ ASSERT(*dstX1 > minValue); /* X1 should be inside left edge */
+ t = (GLfloat) (minValue - *dstX0) / (GLfloat) (*dstX1 - *dstX0);
+ /* chop off [0, t] part */
+ ASSERT(t >= 0.0 && t <= 1.0);
+ *dstX0 = minValue;
+ bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F; /* flipped??? */
+ *srcX0 = *srcX0 + (GLint) (t * (*srcX1 - *srcX0) + bias);
+ }
+ else if (*dstX1 < minValue) {
+ /* X1 outside left edge */
+ ASSERT(*dstX0 > minValue); /* X0 should be inside left edge */
+ t = (GLfloat) (minValue - *dstX1) / (GLfloat) (*dstX0 - *dstX1);
+ /* chop off [0, t] part */
+ ASSERT(t >= 0.0 && t <= 1.0);
+ *dstX1 = minValue;
+ bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
+ *srcX1 = *srcX1 + (GLint) (t * (*srcX0 - *srcX1) + bias);
+ }
+}
+
+
+/**
+ * Do clipping of blit src/dest rectangles.
+ * The dest rect is clipped against both the buffer bounds and scissor bounds.
+ * The src rect is just clipped against the buffer bounds.
+ *
+ * When either the src or dest rect is clipped, the other is also clipped
+ * proportionately!
+ *
+ * Note that X0 need not be less than X1 (same for Y) for either the source
+ * and dest rects. That makes the clipping a little trickier.
+ *
+ * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
+ */
+GLboolean
+_mesa_clip_blit(struct gl_context *ctx,
+ GLint *srcX0, GLint *srcY0, GLint *srcX1, GLint *srcY1,
+ GLint *dstX0, GLint *dstY0, GLint *dstX1, GLint *dstY1)
+{
+ const GLint srcXmin = 0;
+ const GLint srcXmax = ctx->ReadBuffer->Width;
+ const GLint srcYmin = 0;
+ const GLint srcYmax = ctx->ReadBuffer->Height;
+
+ /* these include scissor bounds */
+ const GLint dstXmin = ctx->DrawBuffer->_Xmin;
+ const GLint dstXmax = ctx->DrawBuffer->_Xmax;
+ const GLint dstYmin = ctx->DrawBuffer->_Ymin;
+ const GLint dstYmax = ctx->DrawBuffer->_Ymax;
+
+ /*
+ printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
+ *srcX0, *srcX1, *dstX0, *dstX1);
+ printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
+ *srcY0, *srcY1, *dstY0, *dstY1);
+ */
+
+ /* trivial rejection tests */
+ if (*dstX0 == *dstX1)
+ return GL_FALSE; /* no width */
+ if (*dstX0 <= dstXmin && *dstX1 <= dstXmin)
+ return GL_FALSE; /* totally out (left) of bounds */
+ if (*dstX0 >= dstXmax && *dstX1 >= dstXmax)
+ return GL_FALSE; /* totally out (right) of bounds */
+
+ if (*dstY0 == *dstY1)
+ return GL_FALSE;
+ if (*dstY0 <= dstYmin && *dstY1 <= dstYmin)
+ return GL_FALSE;
+ if (*dstY0 >= dstYmax && *dstY1 >= dstYmax)
+ return GL_FALSE;
+
+ if (*srcX0 == *srcX1)
+ return GL_FALSE;
+ if (*srcX0 <= srcXmin && *srcX1 <= srcXmin)
+ return GL_FALSE;
+ if (*srcX0 >= srcXmax && *srcX1 >= srcXmax)
+ return GL_FALSE;
+
+ if (*srcY0 == *srcY1)
+ return GL_FALSE;
+ if (*srcY0 <= srcYmin && *srcY1 <= srcYmin)
+ return GL_FALSE;
+ if (*srcY0 >= srcYmax && *srcY1 >= srcYmax)
+ return GL_FALSE;
+
+ /*
+ * dest clip
+ */
+ clip_right_or_top(srcX0, srcX1, dstX0, dstX1, dstXmax);
+ clip_right_or_top(srcY0, srcY1, dstY0, dstY1, dstYmax);
+ clip_left_or_bottom(srcX0, srcX1, dstX0, dstX1, dstXmin);
+ clip_left_or_bottom(srcY0, srcY1, dstY0, dstY1, dstYmin);
+
+ /*
+ * src clip (just swap src/dst values from above)
+ */
+ clip_right_or_top(dstX0, dstX1, srcX0, srcX1, srcXmax);
+ clip_right_or_top(dstY0, dstY1, srcY0, srcY1, srcYmax);
+ clip_left_or_bottom(dstX0, dstX1, srcX0, srcX1, srcXmin);
+ clip_left_or_bottom(dstY0, dstY1, srcY0, srcY1, srcYmin);
+
+ /*
+ printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
+ *srcX0, *srcX1, *dstX0, *dstX1);
+ printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
+ *srcY0, *srcY1, *dstY0, *dstY1);
+ */
+
+ ASSERT(*dstX0 >= dstXmin);
+ ASSERT(*dstX0 <= dstXmax);
+ ASSERT(*dstX1 >= dstXmin);
+ ASSERT(*dstX1 <= dstXmax);
+
+ ASSERT(*dstY0 >= dstYmin);
+ ASSERT(*dstY0 <= dstYmax);
+ ASSERT(*dstY1 >= dstYmin);
+ ASSERT(*dstY1 <= dstYmax);
+
+ ASSERT(*srcX0 >= srcXmin);
+ ASSERT(*srcX0 <= srcXmax);
+ ASSERT(*srcX1 >= srcXmin);
+ ASSERT(*srcX1 <= srcXmax);
+
+ ASSERT(*srcY0 >= srcYmin);
+ ASSERT(*srcY0 <= srcYmax);
+ ASSERT(*srcY1 >= srcYmin);
+ ASSERT(*srcY1 <= srcYmax);
+
+ return GL_TRUE;
+}
diff --git a/mesalib/src/mesa/main/mipmap.c b/mesalib/src/mesa/main/mipmap.c
index 0578631ef..ed93cbc6c 100644
--- a/mesalib/src/mesa/main/mipmap.c
+++ b/mesalib/src/mesa/main/mipmap.c
@@ -1,2106 +1,2202 @@
-/*
- * 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 if (datatype == GL_UNSIGNED_INT_2_10_10_10_REV && comps == 4) {
- 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) {
- const GLint rowAr0 = rowA[j] & 0x3ff;
- const GLint rowAr1 = rowA[k] & 0x3ff;
- const GLint rowBr0 = rowB[j] & 0x3ff;
- const GLint rowBr1 = rowB[k] & 0x3ff;
- const GLint rowAg0 = (rowA[j] >> 10) & 0x3ff;
- const GLint rowAg1 = (rowA[k] >> 10) & 0x3ff;
- const GLint rowBg0 = (rowB[j] >> 10) & 0x3ff;
- const GLint rowBg1 = (rowB[k] >> 10) & 0x3ff;
- const GLint rowAb0 = (rowA[j] >> 20) & 0x3ff;
- const GLint rowAb1 = (rowA[k] >> 20) & 0x3ff;
- const GLint rowBb0 = (rowB[j] >> 20) & 0x3ff;
- const GLint rowBb1 = (rowB[k] >> 20) & 0x3ff;
- const GLint rowAa0 = (rowA[j] >> 30) & 0x3;
- const GLint rowAa1 = (rowA[k] >> 30) & 0x3;
- const GLint rowBa0 = (rowB[j] >> 30) & 0x3;
- const GLint rowBa1 = (rowB[k] >> 30) & 0x3;
- 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 << 30) | (blue << 20) | (green << 10) | red;
- }
- }
-
- 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 if ((datatype == GL_UNSIGNED_INT_2_10_10_10_REV) && (comps == 4)) {
- DECLARE_ROW_POINTERS0(GLuint);
-
- for (i = j = 0, k = k0; i < (GLuint) dstWidth;
- i++, j += colStride, k += colStride) {
- const GLint rowAr0 = rowA[j] & 0x3ff;
- const GLint rowAr1 = rowA[k] & 0x3ff;
- const GLint rowBr0 = rowB[j] & 0x3ff;
- const GLint rowBr1 = rowB[k] & 0x3ff;
- const GLint rowCr0 = rowC[j] & 0x3ff;
- const GLint rowCr1 = rowC[k] & 0x3ff;
- const GLint rowDr0 = rowD[j] & 0x3ff;
- const GLint rowDr1 = rowD[k] & 0x3ff;
- const GLint rowAg0 = (rowA[j] >> 10) & 0x3ff;
- const GLint rowAg1 = (rowA[k] >> 10) & 0x3ff;
- const GLint rowBg0 = (rowB[j] >> 10) & 0x3ff;
- const GLint rowBg1 = (rowB[k] >> 10) & 0x3ff;
- const GLint rowCg0 = (rowC[j] >> 10) & 0x3ff;
- const GLint rowCg1 = (rowC[k] >> 10) & 0x3ff;
- const GLint rowDg0 = (rowD[j] >> 10) & 0x3ff;
- const GLint rowDg1 = (rowD[k] >> 10) & 0x3ff;
- const GLint rowAb0 = (rowA[j] >> 20) & 0x3ff;
- const GLint rowAb1 = (rowA[k] >> 20) & 0x3ff;
- const GLint rowBb0 = (rowB[j] >> 20) & 0x3ff;
- const GLint rowBb1 = (rowB[k] >> 20) & 0x3ff;
- const GLint rowCb0 = (rowC[j] >> 20) & 0x3ff;
- const GLint rowCb1 = (rowC[k] >> 20) & 0x3ff;
- const GLint rowDb0 = (rowD[j] >> 20) & 0x3ff;
- const GLint rowDb1 = (rowD[k] >> 20) & 0x3ff;
- const GLint rowAa0 = (rowA[j] >> 30) & 0x3;
- const GLint rowAa1 = (rowA[k] >> 30) & 0x3;
- const GLint rowBa0 = (rowB[j] >> 30) & 0x3;
- const GLint rowBa1 = (rowB[k] >> 30) & 0x3;
- const GLint rowCa0 = (rowC[j] >> 30) & 0x3;
- const GLint rowCa1 = (rowC[k] >> 30) & 0x3;
- const GLint rowDa0 = (rowD[j] >> 30) & 0x3;
- const GLint rowDa1 = (rowD[k] >> 30) & 0x3;
- 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 << 30) | (b << 20) | (g << 10) | 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 if (srcImage->_BaseFormat == GL_LUMINANCE) {
- convertFormat = MESA_FORMAT_L8;
- components = 1;
- } else if (srcImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
- convertFormat = MESA_FORMAT_AL88;
- components = 2;
- } 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);
-
- _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"
+#include "macros.h"
+#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
+#include "../../gallium/auxiliary/util/u_format_r11g11b10f.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 if (datatype == GL_UNSIGNED_INT_2_10_10_10_REV && comps == 4) {
+ 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) {
+ const GLint rowAr0 = rowA[j] & 0x3ff;
+ const GLint rowAr1 = rowA[k] & 0x3ff;
+ const GLint rowBr0 = rowB[j] & 0x3ff;
+ const GLint rowBr1 = rowB[k] & 0x3ff;
+ const GLint rowAg0 = (rowA[j] >> 10) & 0x3ff;
+ const GLint rowAg1 = (rowA[k] >> 10) & 0x3ff;
+ const GLint rowBg0 = (rowB[j] >> 10) & 0x3ff;
+ const GLint rowBg1 = (rowB[k] >> 10) & 0x3ff;
+ const GLint rowAb0 = (rowA[j] >> 20) & 0x3ff;
+ const GLint rowAb1 = (rowA[k] >> 20) & 0x3ff;
+ const GLint rowBb0 = (rowB[j] >> 20) & 0x3ff;
+ const GLint rowBb1 = (rowB[k] >> 20) & 0x3ff;
+ const GLint rowAa0 = (rowA[j] >> 30) & 0x3;
+ const GLint rowAa1 = (rowA[k] >> 30) & 0x3;
+ const GLint rowBa0 = (rowB[j] >> 30) & 0x3;
+ const GLint rowBa1 = (rowB[k] >> 30) & 0x3;
+ 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 << 30) | (blue << 20) | (green << 10) | red;
+ }
+ }
+
+ else if (datatype == GL_UNSIGNED_INT_5_9_9_9_REV && comps == 3) {
+ GLuint i, j, k;
+ const GLuint *rowA = (const GLuint*) srcRowA;
+ const GLuint *rowB = (const GLuint*) srcRowB;
+ GLuint *dst = (GLuint*)dstRow;
+ GLfloat res[3], rowAj[3], rowBj[3], rowAk[3], rowBk[3];
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ rgb9e5_to_float3(rowA[j], rowAj);
+ rgb9e5_to_float3(rowB[j], rowBj);
+ rgb9e5_to_float3(rowA[k], rowAk);
+ rgb9e5_to_float3(rowB[k], rowBk);
+ res[0] = (rowAj[0] + rowAk[0] + rowBj[0] + rowBk[0]) * 0.25F;
+ res[1] = (rowAj[1] + rowAk[1] + rowBj[1] + rowBk[1]) * 0.25F;
+ res[2] = (rowAj[2] + rowAk[2] + rowBj[2] + rowBk[2]) * 0.25F;
+ dst[i] = float3_to_rgb9e5(res);
+ }
+ }
+
+ else if (datatype == GL_UNSIGNED_INT_10F_11F_11F_REV && comps == 3) {
+ GLuint i, j, k;
+ const GLuint *rowA = (const GLuint*) srcRowA;
+ const GLuint *rowB = (const GLuint*) srcRowB;
+ GLuint *dst = (GLuint*)dstRow;
+ GLfloat res[3], rowAj[3], rowBj[3], rowAk[3], rowBk[3];
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ r11g11b10f_to_float3(rowA[j], rowAj);
+ r11g11b10f_to_float3(rowB[j], rowBj);
+ r11g11b10f_to_float3(rowA[k], rowAk);
+ r11g11b10f_to_float3(rowB[k], rowBk);
+ res[0] = (rowAj[0] + rowAk[0] + rowBj[0] + rowBk[0]) * 0.25F;
+ res[1] = (rowAj[1] + rowAk[1] + rowBj[1] + rowBk[1]) * 0.25F;
+ res[2] = (rowAj[2] + rowAk[2] + rowBj[2] + rowBk[2]) * 0.25F;
+ dst[i] = float3_to_r11g11b10f(res);
+ }
+ }
+
+ 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 if ((datatype == GL_UNSIGNED_INT_2_10_10_10_REV) && (comps == 4)) {
+ DECLARE_ROW_POINTERS0(GLuint);
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ const GLint rowAr0 = rowA[j] & 0x3ff;
+ const GLint rowAr1 = rowA[k] & 0x3ff;
+ const GLint rowBr0 = rowB[j] & 0x3ff;
+ const GLint rowBr1 = rowB[k] & 0x3ff;
+ const GLint rowCr0 = rowC[j] & 0x3ff;
+ const GLint rowCr1 = rowC[k] & 0x3ff;
+ const GLint rowDr0 = rowD[j] & 0x3ff;
+ const GLint rowDr1 = rowD[k] & 0x3ff;
+ const GLint rowAg0 = (rowA[j] >> 10) & 0x3ff;
+ const GLint rowAg1 = (rowA[k] >> 10) & 0x3ff;
+ const GLint rowBg0 = (rowB[j] >> 10) & 0x3ff;
+ const GLint rowBg1 = (rowB[k] >> 10) & 0x3ff;
+ const GLint rowCg0 = (rowC[j] >> 10) & 0x3ff;
+ const GLint rowCg1 = (rowC[k] >> 10) & 0x3ff;
+ const GLint rowDg0 = (rowD[j] >> 10) & 0x3ff;
+ const GLint rowDg1 = (rowD[k] >> 10) & 0x3ff;
+ const GLint rowAb0 = (rowA[j] >> 20) & 0x3ff;
+ const GLint rowAb1 = (rowA[k] >> 20) & 0x3ff;
+ const GLint rowBb0 = (rowB[j] >> 20) & 0x3ff;
+ const GLint rowBb1 = (rowB[k] >> 20) & 0x3ff;
+ const GLint rowCb0 = (rowC[j] >> 20) & 0x3ff;
+ const GLint rowCb1 = (rowC[k] >> 20) & 0x3ff;
+ const GLint rowDb0 = (rowD[j] >> 20) & 0x3ff;
+ const GLint rowDb1 = (rowD[k] >> 20) & 0x3ff;
+ const GLint rowAa0 = (rowA[j] >> 30) & 0x3;
+ const GLint rowAa1 = (rowA[k] >> 30) & 0x3;
+ const GLint rowBa0 = (rowB[j] >> 30) & 0x3;
+ const GLint rowBa1 = (rowB[k] >> 30) & 0x3;
+ const GLint rowCa0 = (rowC[j] >> 30) & 0x3;
+ const GLint rowCa1 = (rowC[k] >> 30) & 0x3;
+ const GLint rowDa0 = (rowD[j] >> 30) & 0x3;
+ const GLint rowDa1 = (rowD[k] >> 30) & 0x3;
+ 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 << 30) | (b << 20) | (g << 10) | r;
+ }
+ }
+
+ else if (datatype == GL_UNSIGNED_INT_5_9_9_9_REV && comps == 3) {
+ DECLARE_ROW_POINTERS0(GLuint);
+
+ GLfloat res[3];
+ GLfloat rowAj[3], rowBj[3], rowCj[3], rowDj[3];
+ GLfloat rowAk[3], rowBk[3], rowCk[3], rowDk[3];
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ rgb9e5_to_float3(rowA[j], rowAj);
+ rgb9e5_to_float3(rowB[j], rowBj);
+ rgb9e5_to_float3(rowC[j], rowCj);
+ rgb9e5_to_float3(rowD[j], rowDj);
+ rgb9e5_to_float3(rowA[k], rowAk);
+ rgb9e5_to_float3(rowB[k], rowBk);
+ rgb9e5_to_float3(rowC[k], rowCk);
+ rgb9e5_to_float3(rowD[k], rowDk);
+ res[0] = (rowAj[0] + rowAk[0] + rowBj[0] + rowBk[0] +
+ rowCj[0] + rowCk[0] + rowDj[0] + rowDk[0]) * 0.125F;
+ res[1] = (rowAj[1] + rowAk[1] + rowBj[1] + rowBk[1] +
+ rowCj[1] + rowCk[1] + rowDj[1] + rowDk[1]) * 0.125F;
+ res[2] = (rowAj[2] + rowAk[2] + rowBj[2] + rowBk[2] +
+ rowCj[2] + rowCk[2] + rowDj[2] + rowDk[2]) * 0.125F;
+ dst[i] = float3_to_rgb9e5(res);
+ }
+ }
+
+ else if (datatype == GL_UNSIGNED_INT_10F_11F_11F_REV && comps == 3) {
+ DECLARE_ROW_POINTERS0(GLuint);
+
+ GLfloat res[3];
+ GLfloat rowAj[3], rowBj[3], rowCj[3], rowDj[3];
+ GLfloat rowAk[3], rowBk[3], rowCk[3], rowDk[3];
+
+ for (i = j = 0, k = k0; i < (GLuint) dstWidth;
+ i++, j += colStride, k += colStride) {
+ r11g11b10f_to_float3(rowA[j], rowAj);
+ r11g11b10f_to_float3(rowB[j], rowBj);
+ r11g11b10f_to_float3(rowC[j], rowCj);
+ r11g11b10f_to_float3(rowD[j], rowDj);
+ r11g11b10f_to_float3(rowA[k], rowAk);
+ r11g11b10f_to_float3(rowB[k], rowBk);
+ r11g11b10f_to_float3(rowC[k], rowCk);
+ r11g11b10f_to_float3(rowD[k], rowDk);
+ res[0] = (rowAj[0] + rowAk[0] + rowBj[0] + rowBk[0] +
+ rowCj[0] + rowCk[0] + rowDj[0] + rowDk[0]) * 0.125F;
+ res[1] = (rowAj[1] + rowAk[1] + rowBj[1] + rowBk[1] +
+ rowCj[1] + rowCk[1] + rowDj[1] + rowDk[1]) * 0.125F;
+ res[2] = (rowAj[2] + rowAk[2] + rowBj[2] + rowBk[2] +
+ rowCj[2] + rowCk[2] + rowDj[2] + rowDk[2]) * 0.125F;
+ dst[i] = float3_to_r11g11b10f(res);
+ }
+ }
+
+ 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 if (srcImage->_BaseFormat == GL_LUMINANCE) {
+ convertFormat = MESA_FORMAT_L8;
+ components = 1;
+ } else if (srcImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
+ convertFormat = MESA_FORMAT_AL88;
+ components = 2;
+ } 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);
+
+ _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/pack.c b/mesalib/src/mesa/main/pack.c
index ad8ab9d00..e6734bbbc 100644
--- a/mesalib/src/mesa/main/pack.c
+++ b/mesalib/src/mesa/main/pack.c
@@ -1,5053 +1,5196 @@
-/*
- * Mesa 3-D graphics library
- *
- * Copyright (C) 1999-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
- * THEA AUTHORS 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 pack.c
- * Image and pixel span packing and unpacking.
- */
-
-
-#include "glheader.h"
-#include "colormac.h"
-#include "enums.h"
-#include "image.h"
-#include "imports.h"
-#include "mtypes.h"
-#include "pack.h"
-#include "pixeltransfer.h"
-
-
-/**
- * NOTE:
- * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
- * we later convert the float to a packed integer value (such as for
- * GL_RGB5_A1) because we'll wind up with a non-zero value.
- *
- * We redefine the macros here so zero is handled correctly.
- */
-#undef BYTE_TO_FLOAT
-#define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
-
-#undef SHORT_TO_FLOAT
-#define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
-
-
-
-/** Compute ceiling of integer quotient of A divided by B. */
-#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
-
-
-/**
- * Flip the 8 bits in each byte of the given array.
- *
- * \param p array.
- * \param n number of bytes.
- *
- * \todo try this trick to flip bytes someday:
- * \code
- * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
- * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
- * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
- * \endcode
- */
-static void
-flip_bytes( GLubyte *p, GLuint n )
-{
- GLuint i, a, b;
- for (i = 0; i < n; i++) {
- b = (GLuint) p[i]; /* words are often faster than bytes */
- a = ((b & 0x01) << 7) |
- ((b & 0x02) << 5) |
- ((b & 0x04) << 3) |
- ((b & 0x08) << 1) |
- ((b & 0x10) >> 1) |
- ((b & 0x20) >> 3) |
- ((b & 0x40) >> 5) |
- ((b & 0x80) >> 7);
- p[i] = (GLubyte) a;
- }
-}
-
-
-
-/*
- * Unpack a 32x32 pixel polygon stipple from user memory using the
- * current pixel unpack settings.
- */
-void
-_mesa_unpack_polygon_stipple( const GLubyte *pattern, GLuint dest[32],
- const struct gl_pixelstore_attrib *unpacking )
-{
- GLubyte *ptrn = (GLubyte *) _mesa_unpack_bitmap(32, 32, pattern, unpacking);
- if (ptrn) {
- /* Convert pattern from GLubytes to GLuints and handle big/little
- * endian differences
- */
- GLubyte *p = ptrn;
- GLint i;
- for (i = 0; i < 32; i++) {
- dest[i] = (p[0] << 24)
- | (p[1] << 16)
- | (p[2] << 8)
- | (p[3] );
- p += 4;
- }
- free(ptrn);
- }
-}
-
-
-/*
- * Pack polygon stipple into user memory given current pixel packing
- * settings.
- */
-void
-_mesa_pack_polygon_stipple( const GLuint pattern[32], GLubyte *dest,
- const struct gl_pixelstore_attrib *packing )
-{
- /* Convert pattern from GLuints to GLubytes to handle big/little
- * endian differences.
- */
- GLubyte ptrn[32*4];
- GLint i;
- for (i = 0; i < 32; i++) {
- ptrn[i * 4 + 0] = (GLubyte) ((pattern[i] >> 24) & 0xff);
- ptrn[i * 4 + 1] = (GLubyte) ((pattern[i] >> 16) & 0xff);
- ptrn[i * 4 + 2] = (GLubyte) ((pattern[i] >> 8 ) & 0xff);
- ptrn[i * 4 + 3] = (GLubyte) ((pattern[i] ) & 0xff);
- }
-
- _mesa_pack_bitmap(32, 32, ptrn, dest, packing);
-}
-
-
-/*
- * Unpack bitmap data. Resulting data will be in most-significant-bit-first
- * order with row alignment = 1 byte.
- */
-GLvoid *
-_mesa_unpack_bitmap( GLint width, GLint height, const GLubyte *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
- GLint bytes, row, width_in_bytes;
- GLubyte *buffer, *dst;
-
- if (!pixels)
- return NULL;
-
- /* Alloc dest storage */
- bytes = ((width + 7) / 8 * height);
- buffer = (GLubyte *) malloc( bytes );
- if (!buffer)
- return NULL;
-
- width_in_bytes = CEILING( width, 8 );
- dst = buffer;
- for (row = 0; row < height; row++) {
- const GLubyte *src = (const GLubyte *)
- _mesa_image_address2d(packing, pixels, width, height,
- GL_COLOR_INDEX, GL_BITMAP, row, 0);
- if (!src) {
- free(buffer);
- return NULL;
- }
-
- if ((packing->SkipPixels & 7) == 0) {
- memcpy( dst, src, width_in_bytes );
- if (packing->LsbFirst) {
- flip_bytes( dst, width_in_bytes );
- }
- }
- else {
- /* handling SkipPixels is a bit tricky (no pun intended!) */
- GLint i;
- if (packing->LsbFirst) {
- GLubyte srcMask = 1 << (packing->SkipPixels & 0x7);
- GLubyte dstMask = 128;
- const GLubyte *s = src;
- GLubyte *d = dst;
- *d = 0;
- for (i = 0; i < width; i++) {
- if (*s & srcMask) {
- *d |= dstMask;
- }
- if (srcMask == 128) {
- srcMask = 1;
- s++;
- }
- else {
- srcMask = srcMask << 1;
- }
- if (dstMask == 1) {
- dstMask = 128;
- d++;
- *d = 0;
- }
- else {
- dstMask = dstMask >> 1;
- }
- }
- }
- else {
- GLubyte srcMask = 128 >> (packing->SkipPixels & 0x7);
- GLubyte dstMask = 128;
- const GLubyte *s = src;
- GLubyte *d = dst;
- *d = 0;
- for (i = 0; i < width; i++) {
- if (*s & srcMask) {
- *d |= dstMask;
- }
- if (srcMask == 1) {
- srcMask = 128;
- s++;
- }
- else {
- srcMask = srcMask >> 1;
- }
- if (dstMask == 1) {
- dstMask = 128;
- d++;
- *d = 0;
- }
- else {
- dstMask = dstMask >> 1;
- }
- }
- }
- }
- dst += width_in_bytes;
- }
-
- return buffer;
-}
-
-
-/*
- * Pack bitmap data.
- */
-void
-_mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source,
- GLubyte *dest, const struct gl_pixelstore_attrib *packing )
-{
- GLint row, width_in_bytes;
- const GLubyte *src;
-
- if (!source)
- return;
-
- width_in_bytes = CEILING( width, 8 );
- src = source;
- for (row = 0; row < height; row++) {
- GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, dest,
- width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
- if (!dst)
- return;
-
- if ((packing->SkipPixels & 7) == 0) {
- memcpy( dst, src, width_in_bytes );
- if (packing->LsbFirst) {
- flip_bytes( dst, width_in_bytes );
- }
- }
- else {
- /* handling SkipPixels is a bit tricky (no pun intended!) */
- GLint i;
- if (packing->LsbFirst) {
- GLubyte srcMask = 128;
- GLubyte dstMask = 1 << (packing->SkipPixels & 0x7);
- const GLubyte *s = src;
- GLubyte *d = dst;
- *d = 0;
- for (i = 0; i < width; i++) {
- if (*s & srcMask) {
- *d |= dstMask;
- }
- if (srcMask == 1) {
- srcMask = 128;
- s++;
- }
- else {
- srcMask = srcMask >> 1;
- }
- if (dstMask == 128) {
- dstMask = 1;
- d++;
- *d = 0;
- }
- else {
- dstMask = dstMask << 1;
- }
- }
- }
- else {
- GLubyte srcMask = 128;
- GLubyte dstMask = 128 >> (packing->SkipPixels & 0x7);
- const GLubyte *s = src;
- GLubyte *d = dst;
- *d = 0;
- for (i = 0; i < width; i++) {
- if (*s & srcMask) {
- *d |= dstMask;
- }
- if (srcMask == 1) {
- srcMask = 128;
- s++;
- }
- else {
- srcMask = srcMask >> 1;
- }
- if (dstMask == 1) {
- dstMask = 128;
- d++;
- *d = 0;
- }
- else {
- dstMask = dstMask >> 1;
- }
- }
- }
- }
- src += width_in_bytes;
- }
-}
-
-
-/**
- * Get indexes of color components for a basic color format, such as
- * GL_RGBA, GL_RED, GL_LUMINANCE_ALPHA, etc. Return -1 for indexes
- * that do not apply.
- */
-static void
-get_component_indexes(GLenum format,
- GLint *redIndex,
- GLint *greenIndex,
- GLint *blueIndex,
- GLint *alphaIndex,
- GLint *luminanceIndex,
- GLint *intensityIndex)
-{
- *redIndex = -1;
- *greenIndex = -1;
- *blueIndex = -1;
- *alphaIndex = -1;
- *luminanceIndex = -1;
- *intensityIndex = -1;
-
- switch (format) {
- case GL_LUMINANCE:
- case GL_LUMINANCE_INTEGER_EXT:
- *luminanceIndex = 0;
- break;
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- *luminanceIndex = 0;
- *alphaIndex = 1;
- break;
- case GL_INTENSITY:
- *intensityIndex = 0;
- break;
- case GL_RED:
- case GL_RED_INTEGER_EXT:
- *redIndex = 0;
- break;
- case GL_GREEN:
- case GL_GREEN_INTEGER_EXT:
- *greenIndex = 0;
- break;
- case GL_BLUE:
- case GL_BLUE_INTEGER_EXT:
- *blueIndex = 0;
- break;
- case GL_ALPHA:
- case GL_ALPHA_INTEGER_EXT:
- *alphaIndex = 0;
- break;
- case GL_RG:
- case GL_RG_INTEGER:
- *redIndex = 0;
- *greenIndex = 1;
- break;
- case GL_RGB:
- case GL_RGB_INTEGER_EXT:
- *redIndex = 0;
- *greenIndex = 1;
- *blueIndex = 2;
- break;
- case GL_BGR:
- case GL_BGR_INTEGER_EXT:
- *blueIndex = 0;
- *greenIndex = 1;
- *redIndex = 2;
- break;
- case GL_RGBA:
- case GL_RGBA_INTEGER_EXT:
- *redIndex = 0;
- *greenIndex = 1;
- *blueIndex = 2;
- *alphaIndex = 3;
- break;
- case GL_BGRA:
- case GL_BGRA_INTEGER:
- *redIndex = 2;
- *greenIndex = 1;
- *blueIndex = 0;
- *alphaIndex = 3;
- break;
- case GL_ABGR_EXT:
- *redIndex = 3;
- *greenIndex = 2;
- *blueIndex = 1;
- *alphaIndex = 0;
- break;
- case GL_DU8DV8_ATI:
- case GL_DUDV_ATI:
- *redIndex = 0;
- *greenIndex = 1;
- break;
- default:
- assert(0 && "bad format in get_component_indexes()");
- }
-}
-
-
-
-/**
- * For small integer types, return the min and max possible values.
- * Used for clamping floats to unscaled integer types.
- * \return GL_TRUE if type is handled, GL_FALSE otherwise.
- */
-static GLboolean
-get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
-{
- switch (type) {
- case GL_BYTE:
- *min = -128.0;
- *max = 127.0;
- return GL_TRUE;
- case GL_UNSIGNED_BYTE:
- *min = 0.0;
- *max = 255.0;
- return GL_TRUE;
- case GL_SHORT:
- *min = -32768.0;
- *max = 32767.0;
- return GL_TRUE;
- case GL_UNSIGNED_SHORT:
- *min = 0.0;
- *max = 65535.0;
- return GL_TRUE;
- default:
- return GL_FALSE;
- }
-}
-
-
-
-/**
- * Used to pack an array [][4] of RGBA float colors as specified
- * by the dstFormat, dstType and dstPacking. Used by glReadPixels.
- * Historically, the RGBA values were in [0,1] and rescaled to fit
- * into GLubytes, etc. But with new integer formats, the RGBA values
- * may have any value and we don't always rescale when converting to
- * integers.
- *
- * Note: the rgba values will be modified by this function when any pixel
- * transfer ops are enabled.
- */
-void
-_mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
- GLenum dstFormat, GLenum dstType,
- GLvoid *dstAddr,
- const struct gl_pixelstore_attrib *dstPacking,
- GLbitfield transferOps)
-{
- GLfloat *luminance;
- const GLint comps = _mesa_components_in_format(dstFormat);
- const GLboolean intDstFormat = _mesa_is_integer_format(dstFormat);
- GLuint i;
-
- if (dstFormat == GL_LUMINANCE ||
- dstFormat == GL_LUMINANCE_ALPHA ||
- dstFormat == GL_LUMINANCE_INTEGER_EXT ||
- dstFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT) {
- luminance = (GLfloat *) malloc(n * sizeof(GLfloat));
- if (!luminance) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
- return;
- }
- }
- else {
- luminance = NULL;
- }
-
- if (transferOps) {
- _mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
- }
-
- /*
- * Component clamping (besides clamping to [0,1] in
- * _mesa_apply_rgba_transfer_ops()).
- */
- if (intDstFormat) {
- /* clamping to dest type's min/max values */
- GLfloat min, max;
- if (get_type_min_max(dstType, &min, &max)) {
- for (i = 0; i < n; i++) {
- rgba[i][RCOMP] = CLAMP(rgba[i][RCOMP], min, max);
- rgba[i][GCOMP] = CLAMP(rgba[i][GCOMP], min, max);
- rgba[i][BCOMP] = CLAMP(rgba[i][BCOMP], min, max);
- rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], min, max);
- }
- }
- }
- else if (dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA) {
- /* compute luminance values */
- if (transferOps & IMAGE_CLAMP_BIT) {
- for (i = 0; i < n; i++) {
- GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
- luminance[i] = CLAMP(sum, 0.0F, 1.0F);
- }
- }
- else {
- for (i = 0; i < n; i++) {
- luminance[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
- }
- }
- }
-
- /*
- * Pack/store the pixels. Ugh! Lots of cases!!!
- */
- switch (dstType) {
- case GL_UNSIGNED_BYTE:
- {
- GLubyte *dst = (GLubyte *) dstAddr;
- switch (dstFormat) {
- case GL_RED:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
- break;
- case GL_GREEN:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
- break;
- case GL_BLUE:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
- break;
- case GL_ALPHA:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
- break;
- case GL_LUMINANCE:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_UBYTE(luminance[i]);
- break;
- case GL_LUMINANCE_ALPHA:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_UBYTE(luminance[i]);
- dst[i*2+1] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
- }
- break;
- case GL_RG:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
- }
- break;
- case GL_RGB:
- for (i=0;i<n;i++) {
- dst[i*3+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
- dst[i*3+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
- dst[i*3+2] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
- }
- break;
- case GL_RGBA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
- dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
- dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
- dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
- }
- break;
- case GL_BGR:
- for (i=0;i<n;i++) {
- dst[i*3+0] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
- dst[i*3+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
- dst[i*3+2] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
- }
- break;
- case GL_BGRA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
- dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
- dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
- dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
- }
- break;
- case GL_ABGR_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
- dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
- dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
- dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
- }
- break;
- case GL_RED_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLubyte) rgba[i][RCOMP];
- }
- break;
- case GL_GREEN_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLubyte) rgba[i][GCOMP];
- }
- break;
- case GL_BLUE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLubyte) rgba[i][BCOMP];
- }
- break;
- case GL_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLubyte) rgba[i][ACOMP];
- }
- break;
- case GL_RGB_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLubyte) rgba[i][RCOMP];
- dst[i*3+1] = (GLubyte) rgba[i][GCOMP];
- dst[i*3+2] = (GLubyte) rgba[i][BCOMP];
- }
- break;
- case GL_RGBA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLubyte) rgba[i][RCOMP];
- dst[i*4+1] = (GLubyte) rgba[i][GCOMP];
- dst[i*4+2] = (GLubyte) rgba[i][BCOMP];
- dst[i*4+3] = (GLubyte) rgba[i][ACOMP];
- }
- break;
- case GL_BGR_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLubyte) rgba[i][BCOMP];
- dst[i*3+1] = (GLubyte) rgba[i][GCOMP];
- dst[i*3+2] = (GLubyte) rgba[i][RCOMP];
- }
- break;
- case GL_BGRA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLubyte) rgba[i][BCOMP];
- dst[i*4+1] = (GLubyte) rgba[i][GCOMP];
- dst[i*4+2] = (GLubyte) rgba[i][RCOMP];
- dst[i*4+3] = (GLubyte) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*2+0] = (GLubyte) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- dst[i*2+1] = (GLubyte) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLubyte) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- }
- break;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
- }
- break;
- default:
- _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
- }
- }
- break;
- case GL_BYTE:
- {
- GLbyte *dst = (GLbyte *) dstAddr;
- switch (dstFormat) {
- case GL_RED:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
- break;
- case GL_GREEN:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
- break;
- case GL_BLUE:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
- break;
- case GL_ALPHA:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
- break;
- case GL_LUMINANCE:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_BYTE(luminance[i]);
- break;
- case GL_LUMINANCE_ALPHA:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_BYTE(luminance[i]);
- dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
- }
- break;
- case GL_RG:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
- }
- break;
- case GL_RGB:
- for (i=0;i<n;i++) {
- dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
- dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
- dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
- }
- break;
- case GL_RGBA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
- dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
- dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
- dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
- }
- break;
- case GL_BGR:
- for (i=0;i<n;i++) {
- dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
- dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
- dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
- }
- break;
- case GL_BGRA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
- dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
- dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
- dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
- }
- break;
- case GL_ABGR_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
- dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
- dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
- dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
- }
- break;
- case GL_RED_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLbyte) rgba[i][RCOMP];
- }
- break;
- case GL_GREEN_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLbyte) rgba[i][GCOMP];
- }
- break;
- case GL_BLUE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLbyte) rgba[i][BCOMP];
- }
- break;
- case GL_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLbyte) rgba[i][ACOMP];
- }
- break;
- case GL_RGB_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLbyte) rgba[i][RCOMP];
- dst[i*3+1] = (GLbyte) rgba[i][GCOMP];
- dst[i*3+2] = (GLbyte) rgba[i][BCOMP];
- }
- break;
- case GL_RGBA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLbyte) rgba[i][RCOMP];
- dst[i*4+1] = (GLbyte) rgba[i][GCOMP];
- dst[i*4+2] = (GLbyte) rgba[i][BCOMP];
- dst[i*4+3] = (GLbyte) rgba[i][ACOMP];
- }
- break;
- case GL_BGR_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLbyte) rgba[i][BCOMP];
- dst[i*3+1] = (GLbyte) rgba[i][GCOMP];
- dst[i*3+2] = (GLbyte) rgba[i][RCOMP];
- }
- break;
- case GL_BGRA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLbyte) rgba[i][BCOMP];
- dst[i*4+1] = (GLbyte) rgba[i][GCOMP];
- dst[i*4+2] = (GLbyte) rgba[i][RCOMP];
- dst[i*4+3] = (GLbyte) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*2+0] = (GLbyte) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- dst[i*2+1] = (GLbyte) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLbyte) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- }
- break;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
- }
- break;
- default:
- _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
- }
- }
- break;
- case GL_UNSIGNED_SHORT:
- {
- GLushort *dst = (GLushort *) dstAddr;
- switch (dstFormat) {
- case GL_RED:
- for (i=0;i<n;i++)
- CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][RCOMP]);
- break;
- case GL_GREEN:
- for (i=0;i<n;i++)
- CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][GCOMP]);
- break;
- case GL_BLUE:
- for (i=0;i<n;i++)
- CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][BCOMP]);
- break;
- case GL_ALPHA:
- for (i=0;i<n;i++)
- CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][ACOMP]);
- break;
- case GL_LUMINANCE:
- for (i=0;i<n;i++)
- UNCLAMPED_FLOAT_TO_USHORT(dst[i], luminance[i]);
- break;
- case GL_LUMINANCE_ALPHA:
- for (i=0;i<n;i++) {
- UNCLAMPED_FLOAT_TO_USHORT(dst[i*2+0], luminance[i]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*2+1], rgba[i][ACOMP]);
- }
- break;
- case GL_RG:
- for (i=0;i<n;i++) {
- CLAMPED_FLOAT_TO_USHORT(dst[i*2+0], rgba[i][RCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*2+1], rgba[i][GCOMP]);
- }
- break;
- case GL_RGB:
- for (i=0;i<n;i++) {
- CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][RCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][BCOMP]);
- }
- break;
- case GL_RGBA:
- for (i=0;i<n;i++) {
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][RCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][BCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]);
- }
- break;
- case GL_BGR:
- for (i=0;i<n;i++) {
- CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][BCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][RCOMP]);
- }
- break;
- case GL_BGRA:
- for (i=0;i<n;i++) {
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][BCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][RCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]);
- }
- break;
- case GL_ABGR_EXT:
- for (i=0;i<n;i++) {
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][ACOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][BCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][GCOMP]);
- CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][RCOMP]);
- }
- break;
- case GL_RED_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLushort) rgba[i][RCOMP];
- }
- break;
- case GL_GREEN_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLushort) rgba[i][GCOMP];
- }
- break;
- case GL_BLUE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLushort) rgba[i][BCOMP];
- }
- break;
- case GL_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLushort) rgba[i][ACOMP];
- }
- break;
- case GL_RGB_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLushort) rgba[i][RCOMP];
- dst[i*3+1] = (GLushort) rgba[i][GCOMP];
- dst[i*3+2] = (GLushort) rgba[i][BCOMP];
- }
- break;
- case GL_RGBA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLushort) rgba[i][RCOMP];
- dst[i*4+1] = (GLushort) rgba[i][GCOMP];
- dst[i*4+2] = (GLushort) rgba[i][BCOMP];
- dst[i*4+3] = (GLushort) rgba[i][ACOMP];
- }
- break;
- case GL_BGR_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLushort) rgba[i][BCOMP];
- dst[i*3+1] = (GLushort) rgba[i][GCOMP];
- dst[i*3+2] = (GLushort) rgba[i][RCOMP];
- }
- break;
- case GL_BGRA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLushort) rgba[i][BCOMP];
- dst[i*4+1] = (GLushort) rgba[i][GCOMP];
- dst[i*4+2] = (GLushort) rgba[i][RCOMP];
- dst[i*4+3] = (GLushort) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*2+0] = (GLushort) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- dst[i*2+1] = (GLushort) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLushort) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- }
- break;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_USHORT(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_USHORT(rgba[i][GCOMP]);
- }
- break;
- default:
- _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
- }
- }
- break;
- case GL_SHORT:
- {
- GLshort *dst = (GLshort *) dstAddr;
- switch (dstFormat) {
- case GL_RED:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
- break;
- case GL_GREEN:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
- break;
- case GL_BLUE:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
- break;
- case GL_ALPHA:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
- break;
- case GL_LUMINANCE:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_SHORT(luminance[i]);
- break;
- case GL_LUMINANCE_ALPHA:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_SHORT(luminance[i]);
- dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
- }
- break;
- case GL_RG:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
- }
- break;
- case GL_RGB:
- for (i=0;i<n;i++) {
- dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
- dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
- dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
- }
- break;
- case GL_RGBA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
- dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
- dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
- dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
- }
- break;
- case GL_BGR:
- for (i=0;i<n;i++) {
- dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
- dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
- dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
- }
- break;
- case GL_BGRA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
- dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
- dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
- dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
- }
- break;
- case GL_ABGR_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
- dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
- dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
- dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
- }
- break;
- case GL_RED_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLshort) rgba[i][RCOMP];
- }
- break;
- case GL_GREEN_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLshort) rgba[i][GCOMP];
- }
- break;
- case GL_BLUE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLshort) rgba[i][BCOMP];
- }
- break;
- case GL_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLshort) rgba[i][ACOMP];
- }
- break;
- case GL_RGB_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLshort) rgba[i][RCOMP];
- dst[i*3+1] = (GLshort) rgba[i][GCOMP];
- dst[i*3+2] = (GLshort) rgba[i][BCOMP];
- }
- break;
- case GL_RGBA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLshort) rgba[i][RCOMP];
- dst[i*4+1] = (GLshort) rgba[i][GCOMP];
- dst[i*4+2] = (GLshort) rgba[i][BCOMP];
- dst[i*4+3] = (GLshort) rgba[i][ACOMP];
- }
- break;
- case GL_BGR_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLshort) rgba[i][BCOMP];
- dst[i*3+1] = (GLshort) rgba[i][GCOMP];
- dst[i*3+2] = (GLshort) rgba[i][RCOMP];
- }
- break;
- case GL_BGRA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLshort) rgba[i][BCOMP];
- dst[i*4+1] = (GLshort) rgba[i][GCOMP];
- dst[i*4+2] = (GLshort) rgba[i][RCOMP];
- dst[i*4+3] = (GLshort) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*2+0] = (GLshort) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- dst[i*2+1] = (GLshort) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLshort) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- }
- break;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
- }
- break;
- default:
- _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
- }
- }
- break;
- case GL_UNSIGNED_INT:
- {
- GLuint *dst = (GLuint *) dstAddr;
- switch (dstFormat) {
- case GL_RED:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_UINT(rgba[i][RCOMP]);
- break;
- case GL_GREEN:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_UINT(rgba[i][GCOMP]);
- break;
- case GL_BLUE:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_UINT(rgba[i][BCOMP]);
- break;
- case GL_ALPHA:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_UINT(rgba[i][ACOMP]);
- break;
- case GL_LUMINANCE:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_UINT(luminance[i]);
- break;
- case GL_LUMINANCE_ALPHA:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_UINT(luminance[i]);
- dst[i*2+1] = FLOAT_TO_UINT(rgba[i][ACOMP]);
- }
- break;
- case GL_RG:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
- }
- break;
- case GL_RGB:
- for (i=0;i<n;i++) {
- dst[i*3+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
- dst[i*3+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
- dst[i*3+2] = FLOAT_TO_UINT(rgba[i][BCOMP]);
- }
- break;
- case GL_RGBA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
- dst[i*4+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
- dst[i*4+2] = FLOAT_TO_UINT(rgba[i][BCOMP]);
- dst[i*4+3] = FLOAT_TO_UINT(rgba[i][ACOMP]);
- }
- break;
- case GL_BGR:
- for (i=0;i<n;i++) {
- dst[i*3+0] = FLOAT_TO_UINT(rgba[i][BCOMP]);
- dst[i*3+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
- dst[i*3+2] = FLOAT_TO_UINT(rgba[i][RCOMP]);
- }
- break;
- case GL_BGRA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_UINT(rgba[i][BCOMP]);
- dst[i*4+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
- dst[i*4+2] = FLOAT_TO_UINT(rgba[i][RCOMP]);
- dst[i*4+3] = FLOAT_TO_UINT(rgba[i][ACOMP]);
- }
- break;
- case GL_ABGR_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_UINT(rgba[i][ACOMP]);
- dst[i*4+1] = FLOAT_TO_UINT(rgba[i][BCOMP]);
- dst[i*4+2] = FLOAT_TO_UINT(rgba[i][GCOMP]);
- dst[i*4+3] = FLOAT_TO_UINT(rgba[i][RCOMP]);
- }
- break;
- case GL_RED_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLuint) rgba[i][RCOMP];
- }
- break;
- case GL_GREEN_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLuint) rgba[i][GCOMP];
- }
- break;
- case GL_BLUE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLuint) rgba[i][BCOMP];
- }
- break;
- case GL_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLuint) rgba[i][ACOMP];
- }
- break;
- case GL_RGB_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLuint) rgba[i][RCOMP];
- dst[i*3+1] = (GLuint) rgba[i][GCOMP];
- dst[i*3+2] = (GLuint) rgba[i][BCOMP];
- }
- break;
- case GL_RGBA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLuint) rgba[i][RCOMP];
- dst[i*4+1] = (GLuint) rgba[i][GCOMP];
- dst[i*4+2] = (GLuint) rgba[i][BCOMP];
- dst[i*4+3] = (GLuint) rgba[i][ACOMP];
- }
- break;
- case GL_BGR_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLuint) rgba[i][BCOMP];
- dst[i*3+1] = (GLuint) rgba[i][GCOMP];
- dst[i*3+2] = (GLuint) rgba[i][RCOMP];
- }
- break;
- case GL_BGRA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLuint) rgba[i][BCOMP];
- dst[i*4+1] = (GLuint) rgba[i][GCOMP];
- dst[i*4+2] = (GLuint) rgba[i][RCOMP];
- dst[i*4+3] = (GLuint) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*2+0] = (GLuint) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- dst[i*2+1] = (GLuint) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLuint) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- }
- break;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
- }
- break;
- default:
- _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
- }
- }
- break;
- case GL_INT:
- {
- GLint *dst = (GLint *) dstAddr;
- switch (dstFormat) {
- case GL_RED:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_INT(rgba[i][RCOMP]);
- break;
- case GL_GREEN:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_INT(rgba[i][GCOMP]);
- break;
- case GL_BLUE:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_INT(rgba[i][BCOMP]);
- break;
- case GL_ALPHA:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_INT(rgba[i][ACOMP]);
- break;
- case GL_LUMINANCE:
- for (i=0;i<n;i++)
- dst[i] = FLOAT_TO_INT(luminance[i]);
- break;
- case GL_LUMINANCE_ALPHA:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_INT(luminance[i]);
- dst[i*2+1] = FLOAT_TO_INT(rgba[i][ACOMP]);
- }
- break;
- case GL_RG:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
- }
- break;
- case GL_RGB:
- for (i=0;i<n;i++) {
- dst[i*3+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
- dst[i*3+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
- dst[i*3+2] = FLOAT_TO_INT(rgba[i][BCOMP]);
- }
- break;
- case GL_RGBA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
- dst[i*4+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
- dst[i*4+2] = FLOAT_TO_INT(rgba[i][BCOMP]);
- dst[i*4+3] = FLOAT_TO_INT(rgba[i][ACOMP]);
- }
- break;
- case GL_BGR:
- for (i=0;i<n;i++) {
- dst[i*3+0] = FLOAT_TO_INT(rgba[i][BCOMP]);
- dst[i*3+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
- dst[i*3+2] = FLOAT_TO_INT(rgba[i][RCOMP]);
- }
- break;
- case GL_BGRA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_INT(rgba[i][BCOMP]);
- dst[i*4+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
- dst[i*4+2] = FLOAT_TO_INT(rgba[i][RCOMP]);
- dst[i*4+3] = FLOAT_TO_INT(rgba[i][ACOMP]);
- }
- break;
- case GL_ABGR_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = FLOAT_TO_INT(rgba[i][ACOMP]);
- dst[i*4+1] = FLOAT_TO_INT(rgba[i][BCOMP]);
- dst[i*4+2] = FLOAT_TO_INT(rgba[i][GCOMP]);
- dst[i*4+3] = FLOAT_TO_INT(rgba[i][RCOMP]);
- }
- break;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- for (i=0;i<n;i++) {
- dst[i*2+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
- dst[i*2+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
- }
- break;
- case GL_RED_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLint) rgba[i][RCOMP];
- }
- break;
- case GL_GREEN_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLint) rgba[i][GCOMP];
- }
- break;
- case GL_BLUE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLint) rgba[i][BCOMP];
- }
- break;
- case GL_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLint) rgba[i][ACOMP];
- }
- break;
- case GL_RGB_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLint) rgba[i][RCOMP];
- dst[i*3+1] = (GLint) rgba[i][GCOMP];
- dst[i*3+2] = (GLint) rgba[i][BCOMP];
- }
- break;
- case GL_RGBA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLint) rgba[i][RCOMP];
- dst[i*4+1] = (GLint) rgba[i][GCOMP];
- dst[i*4+2] = (GLint) rgba[i][BCOMP];
- dst[i*4+3] = (GLint) rgba[i][ACOMP];
- }
- break;
- case GL_BGR_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*3+0] = (GLint) rgba[i][BCOMP];
- dst[i*3+1] = (GLint) rgba[i][GCOMP];
- dst[i*3+2] = (GLint) rgba[i][RCOMP];
- }
- break;
- case GL_BGRA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = (GLint) rgba[i][BCOMP];
- dst[i*4+1] = (GLint) rgba[i][GCOMP];
- dst[i*4+2] = (GLint) rgba[i][RCOMP];
- dst[i*4+3] = (GLint) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i*2+0] = (GLint) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- dst[i*2+1] = (GLint) rgba[i][ACOMP];
- }
- break;
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- for (i=0;i<n;i++) {
- dst[i] = (GLint) (rgba[i][RCOMP] +
- rgba[i][GCOMP] +
- rgba[i][BCOMP]);
- }
- break;
- default:
- _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
- }
- }
- break;
- case GL_FLOAT:
- {
- GLfloat *dst = (GLfloat *) dstAddr;
- switch (dstFormat) {
- case GL_RED:
- for (i=0;i<n;i++)
- dst[i] = rgba[i][RCOMP];
- break;
- case GL_GREEN:
- for (i=0;i<n;i++)
- dst[i] = rgba[i][GCOMP];
- break;
- case GL_BLUE:
- for (i=0;i<n;i++)
- dst[i] = rgba[i][BCOMP];
- break;
- case GL_ALPHA:
- for (i=0;i<n;i++)
- dst[i] = rgba[i][ACOMP];
- break;
- case GL_LUMINANCE:
- for (i=0;i<n;i++)
- dst[i] = luminance[i];
- break;
- case GL_LUMINANCE_ALPHA:
- for (i=0;i<n;i++) {
- dst[i*2+0] = luminance[i];
- dst[i*2+1] = rgba[i][ACOMP];
- }
- break;
- case GL_RG:
- for (i=0;i<n;i++) {
- dst[i*2+0] = rgba[i][RCOMP];
- dst[i*2+1] = rgba[i][GCOMP];
- }
- break;
- case GL_RGB:
- for (i=0;i<n;i++) {
- dst[i*3+0] = rgba[i][RCOMP];
- dst[i*3+1] = rgba[i][GCOMP];
- dst[i*3+2] = rgba[i][BCOMP];
- }
- break;
- case GL_RGBA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = rgba[i][RCOMP];
- dst[i*4+1] = rgba[i][GCOMP];
- dst[i*4+2] = rgba[i][BCOMP];
- dst[i*4+3] = rgba[i][ACOMP];
- }
- break;
- case GL_BGR:
- for (i=0;i<n;i++) {
- dst[i*3+0] = rgba[i][BCOMP];
- dst[i*3+1] = rgba[i][GCOMP];
- dst[i*3+2] = rgba[i][RCOMP];
- }
- break;
- case GL_BGRA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = rgba[i][BCOMP];
- dst[i*4+1] = rgba[i][GCOMP];
- dst[i*4+2] = rgba[i][RCOMP];
- dst[i*4+3] = rgba[i][ACOMP];
- }
- break;
- case GL_ABGR_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = rgba[i][ACOMP];
- dst[i*4+1] = rgba[i][BCOMP];
- dst[i*4+2] = rgba[i][GCOMP];
- dst[i*4+3] = rgba[i][RCOMP];
- }
- break;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- for (i=0;i<n;i++) {
- dst[i*2+0] = rgba[i][RCOMP];
- dst[i*2+1] = rgba[i][GCOMP];
- }
- break;
- default:
- _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
- }
- }
- break;
- case GL_HALF_FLOAT_ARB:
- {
- GLhalfARB *dst = (GLhalfARB *) dstAddr;
- switch (dstFormat) {
- case GL_RED:
- for (i=0;i<n;i++)
- dst[i] = _mesa_float_to_half(rgba[i][RCOMP]);
- break;
- case GL_GREEN:
- for (i=0;i<n;i++)
- dst[i] = _mesa_float_to_half(rgba[i][GCOMP]);
- break;
- case GL_BLUE:
- for (i=0;i<n;i++)
- dst[i] = _mesa_float_to_half(rgba[i][BCOMP]);
- break;
- case GL_ALPHA:
- for (i=0;i<n;i++)
- dst[i] = _mesa_float_to_half(rgba[i][ACOMP]);
- break;
- case GL_LUMINANCE:
- for (i=0;i<n;i++)
- dst[i] = _mesa_float_to_half(luminance[i]);
- break;
- case GL_LUMINANCE_ALPHA:
- for (i=0;i<n;i++) {
- dst[i*2+0] = _mesa_float_to_half(luminance[i]);
- dst[i*2+1] = _mesa_float_to_half(rgba[i][ACOMP]);
- }
- break;
- case GL_RG:
- for (i=0;i<n;i++) {
- dst[i*2+0] = _mesa_float_to_half(rgba[i][RCOMP]);
- dst[i*2+1] = _mesa_float_to_half(rgba[i][GCOMP]);
- }
- break;
- case GL_RGB:
- for (i=0;i<n;i++) {
- dst[i*3+0] = _mesa_float_to_half(rgba[i][RCOMP]);
- dst[i*3+1] = _mesa_float_to_half(rgba[i][GCOMP]);
- dst[i*3+2] = _mesa_float_to_half(rgba[i][BCOMP]);
- }
- break;
- case GL_RGBA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = _mesa_float_to_half(rgba[i][RCOMP]);
- dst[i*4+1] = _mesa_float_to_half(rgba[i][GCOMP]);
- dst[i*4+2] = _mesa_float_to_half(rgba[i][BCOMP]);
- dst[i*4+3] = _mesa_float_to_half(rgba[i][ACOMP]);
- }
- break;
- case GL_BGR:
- for (i=0;i<n;i++) {
- dst[i*3+0] = _mesa_float_to_half(rgba[i][BCOMP]);
- dst[i*3+1] = _mesa_float_to_half(rgba[i][GCOMP]);
- dst[i*3+2] = _mesa_float_to_half(rgba[i][RCOMP]);
- }
- break;
- case GL_BGRA:
- for (i=0;i<n;i++) {
- dst[i*4+0] = _mesa_float_to_half(rgba[i][BCOMP]);
- dst[i*4+1] = _mesa_float_to_half(rgba[i][GCOMP]);
- dst[i*4+2] = _mesa_float_to_half(rgba[i][RCOMP]);
- dst[i*4+3] = _mesa_float_to_half(rgba[i][ACOMP]);
- }
- break;
- case GL_ABGR_EXT:
- for (i=0;i<n;i++) {
- dst[i*4+0] = _mesa_float_to_half(rgba[i][ACOMP]);
- dst[i*4+1] = _mesa_float_to_half(rgba[i][BCOMP]);
- dst[i*4+2] = _mesa_float_to_half(rgba[i][GCOMP]);
- dst[i*4+3] = _mesa_float_to_half(rgba[i][RCOMP]);
- }
- break;
- case GL_DUDV_ATI:
- case GL_DU8DV8_ATI:
- for (i=0;i<n;i++) {
- dst[i*2+0] = _mesa_float_to_half(rgba[i][RCOMP]);
- dst[i*2+1] = _mesa_float_to_half(rgba[i][GCOMP]);
- }
- break;
- default:
- _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
- }
- }
- break;
- case GL_UNSIGNED_BYTE_3_3_2:
- if (dstFormat == GL_RGB) {
- GLubyte *dst = (GLubyte *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 7.0F) << 5)
- | (IROUND(rgba[i][GCOMP] * 7.0F) << 2)
- | (IROUND(rgba[i][BCOMP] * 3.0F) );
- }
- }
- break;
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- if (dstFormat == GL_RGB) {
- GLubyte *dst = (GLubyte *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 7.0F) )
- | (IROUND(rgba[i][GCOMP] * 7.0F) << 3)
- | (IROUND(rgba[i][BCOMP] * 3.0F) << 6);
- }
- }
- break;
- case GL_UNSIGNED_SHORT_5_6_5:
- if (dstFormat == GL_RGB) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) << 11)
- | (IROUND(rgba[i][GCOMP] * 63.0F) << 5)
- | (IROUND(rgba[i][BCOMP] * 31.0F) );
- }
- }
- break;
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- if (dstFormat == GL_RGB) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) )
- | (IROUND(rgba[i][GCOMP] * 63.0F) << 5)
- | (IROUND(rgba[i][BCOMP] * 31.0F) << 11);
- }
- }
- break;
- case GL_UNSIGNED_SHORT_4_4_4_4:
- if (dstFormat == GL_RGBA) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 15.0F) << 12)
- | (IROUND(rgba[i][GCOMP] * 15.0F) << 8)
- | (IROUND(rgba[i][BCOMP] * 15.0F) << 4)
- | (IROUND(rgba[i][ACOMP] * 15.0F) );
- }
- }
- else if (dstFormat == GL_BGRA) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][BCOMP] * 15.0F) << 12)
- | (IROUND(rgba[i][GCOMP] * 15.0F) << 8)
- | (IROUND(rgba[i][RCOMP] * 15.0F) << 4)
- | (IROUND(rgba[i][ACOMP] * 15.0F) );
- }
- }
- else if (dstFormat == GL_ABGR_EXT) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][ACOMP] * 15.0F) << 12)
- | (IROUND(rgba[i][BCOMP] * 15.0F) << 8)
- | (IROUND(rgba[i][GCOMP] * 15.0F) << 4)
- | (IROUND(rgba[i][RCOMP] * 15.0F) );
- }
- }
- break;
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- if (dstFormat == GL_RGBA) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 15.0F) )
- | (IROUND(rgba[i][GCOMP] * 15.0F) << 4)
- | (IROUND(rgba[i][BCOMP] * 15.0F) << 8)
- | (IROUND(rgba[i][ACOMP] * 15.0F) << 12);
- }
- }
- else if (dstFormat == GL_BGRA) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][BCOMP] * 15.0F) )
- | (IROUND(rgba[i][GCOMP] * 15.0F) << 4)
- | (IROUND(rgba[i][RCOMP] * 15.0F) << 8)
- | (IROUND(rgba[i][ACOMP] * 15.0F) << 12);
- }
- }
- else if (dstFormat == GL_ABGR_EXT) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][ACOMP] * 15.0F) )
- | (IROUND(rgba[i][BCOMP] * 15.0F) << 4)
- | (IROUND(rgba[i][GCOMP] * 15.0F) << 8)
- | (IROUND(rgba[i][RCOMP] * 15.0F) << 12);
- }
- }
- break;
- case GL_UNSIGNED_SHORT_5_5_5_1:
- if (dstFormat == GL_RGBA) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) << 11)
- | (IROUND(rgba[i][GCOMP] * 31.0F) << 6)
- | (IROUND(rgba[i][BCOMP] * 31.0F) << 1)
- | (IROUND(rgba[i][ACOMP] * 1.0F) );
- }
- }
- else if (dstFormat == GL_BGRA) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][BCOMP] * 31.0F) << 11)
- | (IROUND(rgba[i][GCOMP] * 31.0F) << 6)
- | (IROUND(rgba[i][RCOMP] * 31.0F) << 1)
- | (IROUND(rgba[i][ACOMP] * 1.0F) );
- }
- }
- else if (dstFormat == GL_ABGR_EXT) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][ACOMP] * 31.0F) << 11)
- | (IROUND(rgba[i][BCOMP] * 31.0F) << 6)
- | (IROUND(rgba[i][GCOMP] * 31.0F) << 1)
- | (IROUND(rgba[i][RCOMP] * 1.0F) );
- }
- }
- break;
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- if (dstFormat == GL_RGBA) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) )
- | (IROUND(rgba[i][GCOMP] * 31.0F) << 5)
- | (IROUND(rgba[i][BCOMP] * 31.0F) << 10)
- | (IROUND(rgba[i][ACOMP] * 1.0F) << 15);
- }
- }
- else if (dstFormat == GL_BGRA) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][BCOMP] * 31.0F) )
- | (IROUND(rgba[i][GCOMP] * 31.0F) << 5)
- | (IROUND(rgba[i][RCOMP] * 31.0F) << 10)
- | (IROUND(rgba[i][ACOMP] * 1.0F) << 15);
- }
- }
- else if (dstFormat == GL_ABGR_EXT) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][ACOMP] * 31.0F) )
- | (IROUND(rgba[i][BCOMP] * 31.0F) << 5)
- | (IROUND(rgba[i][GCOMP] * 31.0F) << 10)
- | (IROUND(rgba[i][RCOMP] * 1.0F) << 15);
- }
- }
- break;
- case GL_UNSIGNED_INT_8_8_8_8:
- if (dstFormat == GL_RGBA) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 255.F) << 24)
- | (IROUND(rgba[i][GCOMP] * 255.F) << 16)
- | (IROUND(rgba[i][BCOMP] * 255.F) << 8)
- | (IROUND(rgba[i][ACOMP] * 255.F) );
- }
- }
- else if (dstFormat == GL_BGRA) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][BCOMP] * 255.F) << 24)
- | (IROUND(rgba[i][GCOMP] * 255.F) << 16)
- | (IROUND(rgba[i][RCOMP] * 255.F) << 8)
- | (IROUND(rgba[i][ACOMP] * 255.F) );
- }
- }
- else if (dstFormat == GL_ABGR_EXT) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][ACOMP] * 255.F) << 24)
- | (IROUND(rgba[i][BCOMP] * 255.F) << 16)
- | (IROUND(rgba[i][GCOMP] * 255.F) << 8)
- | (IROUND(rgba[i][RCOMP] * 255.F) );
- }
- }
- break;
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- if (dstFormat == GL_RGBA) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 255.0F) )
- | (IROUND(rgba[i][GCOMP] * 255.0F) << 8)
- | (IROUND(rgba[i][BCOMP] * 255.0F) << 16)
- | (IROUND(rgba[i][ACOMP] * 255.0F) << 24);
- }
- }
- else if (dstFormat == GL_BGRA) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][BCOMP] * 255.0F) )
- | (IROUND(rgba[i][GCOMP] * 255.0F) << 8)
- | (IROUND(rgba[i][RCOMP] * 255.0F) << 16)
- | (IROUND(rgba[i][ACOMP] * 255.0F) << 24);
- }
- }
- else if (dstFormat == GL_ABGR_EXT) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][ACOMP] * 255.0F) )
- | (IROUND(rgba[i][BCOMP] * 255.0F) << 8)
- | (IROUND(rgba[i][GCOMP] * 255.0F) << 16)
- | (IROUND(rgba[i][RCOMP] * 255.0F) << 24);
- }
- }
- break;
- case GL_UNSIGNED_INT_10_10_10_2:
- if (dstFormat == GL_RGBA) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 1023.0F) << 22)
- | (IROUND(rgba[i][GCOMP] * 1023.0F) << 12)
- | (IROUND(rgba[i][BCOMP] * 1023.0F) << 2)
- | (IROUND(rgba[i][ACOMP] * 3.0F) );
- }
- }
- else if (dstFormat == GL_BGRA) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][BCOMP] * 1023.0F) << 22)
- | (IROUND(rgba[i][GCOMP] * 1023.0F) << 12)
- | (IROUND(rgba[i][RCOMP] * 1023.0F) << 2)
- | (IROUND(rgba[i][ACOMP] * 3.0F) );
- }
- }
- else if (dstFormat == GL_ABGR_EXT) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][ACOMP] * 1023.0F) << 22)
- | (IROUND(rgba[i][BCOMP] * 1023.0F) << 12)
- | (IROUND(rgba[i][GCOMP] * 1023.0F) << 2)
- | (IROUND(rgba[i][RCOMP] * 3.0F) );
- }
- }
- break;
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- if (dstFormat == GL_RGBA) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][RCOMP] * 1023.0F) )
- | (IROUND(rgba[i][GCOMP] * 1023.0F) << 10)
- | (IROUND(rgba[i][BCOMP] * 1023.0F) << 20)
- | (IROUND(rgba[i][ACOMP] * 3.0F) << 30);
- }
- }
- else if (dstFormat == GL_BGRA) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][BCOMP] * 1023.0F) )
- | (IROUND(rgba[i][GCOMP] * 1023.0F) << 10)
- | (IROUND(rgba[i][RCOMP] * 1023.0F) << 20)
- | (IROUND(rgba[i][ACOMP] * 3.0F) << 30);
- }
- }
- else if (dstFormat == GL_ABGR_EXT) {
- GLuint *dst = (GLuint *) dstAddr;
- for (i=0;i<n;i++) {
- dst[i] = (IROUND(rgba[i][ACOMP] * 1023.0F) )
- | (IROUND(rgba[i][BCOMP] * 1023.0F) << 10)
- | (IROUND(rgba[i][GCOMP] * 1023.0F) << 20)
- | (IROUND(rgba[i][RCOMP] * 3.0F) << 30);
- }
- }
- break;
- default:
- _mesa_problem(ctx, "bad type in _mesa_pack_rgba_span_float");
- return;
- }
-
- if (dstPacking->SwapBytes) {
- GLint swapSize = _mesa_sizeof_packed_type(dstType);
- if (swapSize == 2) {
- if (dstPacking->SwapBytes) {
- _mesa_swap2((GLushort *) dstAddr, n * comps);
- }
- }
- else if (swapSize == 4) {
- if (dstPacking->SwapBytes) {
- _mesa_swap4((GLuint *) dstAddr, n * comps);
- }
- }
- }
-
- free(luminance);
-}
-
-
-
-#define SWAP2BYTE(VALUE) \
- { \
- GLubyte *bytes = (GLubyte *) &(VALUE); \
- GLubyte tmp = bytes[0]; \
- bytes[0] = bytes[1]; \
- bytes[1] = tmp; \
- }
-
-#define SWAP4BYTE(VALUE) \
- { \
- GLubyte *bytes = (GLubyte *) &(VALUE); \
- GLubyte tmp = bytes[0]; \
- bytes[0] = bytes[3]; \
- bytes[3] = tmp; \
- tmp = bytes[1]; \
- bytes[1] = bytes[2]; \
- bytes[2] = tmp; \
- }
-
-
-static void
-extract_uint_indexes(GLuint n, GLuint indexes[],
- GLenum srcFormat, GLenum srcType, const GLvoid *src,
- const struct gl_pixelstore_attrib *unpack )
-{
- ASSERT(srcFormat == GL_COLOR_INDEX || srcFormat == GL_STENCIL_INDEX);
-
- ASSERT(srcType == GL_BITMAP ||
- srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_BYTE ||
- srcType == GL_UNSIGNED_SHORT ||
- srcType == GL_SHORT ||
- srcType == GL_UNSIGNED_INT ||
- srcType == GL_INT ||
- srcType == GL_UNSIGNED_INT_24_8_EXT ||
- srcType == GL_HALF_FLOAT_ARB ||
- srcType == GL_FLOAT);
-
- switch (srcType) {
- case GL_BITMAP:
- {
- GLubyte *ubsrc = (GLubyte *) src;
- if (unpack->LsbFirst) {
- GLubyte mask = 1 << (unpack->SkipPixels & 0x7);
- GLuint i;
- for (i = 0; i < n; i++) {
- indexes[i] = (*ubsrc & mask) ? 1 : 0;
- if (mask == 128) {
- mask = 1;
- ubsrc++;
- }
- else {
- mask = mask << 1;
- }
- }
- }
- else {
- GLubyte mask = 128 >> (unpack->SkipPixels & 0x7);
- GLuint i;
- for (i = 0; i < n; i++) {
- indexes[i] = (*ubsrc & mask) ? 1 : 0;
- if (mask == 1) {
- mask = 128;
- ubsrc++;
- }
- else {
- mask = mask >> 1;
- }
- }
- }
- }
- break;
- case GL_UNSIGNED_BYTE:
- {
- GLuint i;
- const GLubyte *s = (const GLubyte *) src;
- for (i = 0; i < n; i++)
- indexes[i] = s[i];
- }
- break;
- case GL_BYTE:
- {
- GLuint i;
- const GLbyte *s = (const GLbyte *) src;
- for (i = 0; i < n; i++)
- indexes[i] = s[i];
- }
- break;
- case GL_UNSIGNED_SHORT:
- {
- GLuint i;
- const GLushort *s = (const GLushort *) src;
- if (unpack->SwapBytes) {
- for (i = 0; i < n; i++) {
- GLushort value = s[i];
- SWAP2BYTE(value);
- indexes[i] = value;
- }
- }
- else {
- for (i = 0; i < n; i++)
- indexes[i] = s[i];
- }
- }
- break;
- case GL_SHORT:
- {
- GLuint i;
- const GLshort *s = (const GLshort *) src;
- if (unpack->SwapBytes) {
- for (i = 0; i < n; i++) {
- GLshort value = s[i];
- SWAP2BYTE(value);
- indexes[i] = value;
- }
- }
- else {
- for (i = 0; i < n; i++)
- indexes[i] = s[i];
- }
- }
- break;
- case GL_UNSIGNED_INT:
- {
- GLuint i;
- const GLuint *s = (const GLuint *) src;
- if (unpack->SwapBytes) {
- for (i = 0; i < n; i++) {
- GLuint value = s[i];
- SWAP4BYTE(value);
- indexes[i] = value;
- }
- }
- else {
- for (i = 0; i < n; i++)
- indexes[i] = s[i];
- }
- }
- break;
- case GL_INT:
- {
- GLuint i;
- const GLint *s = (const GLint *) src;
- if (unpack->SwapBytes) {
- for (i = 0; i < n; i++) {
- GLint value = s[i];
- SWAP4BYTE(value);
- indexes[i] = value;
- }
- }
- else {
- for (i = 0; i < n; i++)
- indexes[i] = s[i];
- }
- }
- break;
- case GL_FLOAT:
- {
- GLuint i;
- const GLfloat *s = (const GLfloat *) src;
- if (unpack->SwapBytes) {
- for (i = 0; i < n; i++) {
- GLfloat value = s[i];
- SWAP4BYTE(value);
- indexes[i] = (GLuint) value;
- }
- }
- else {
- for (i = 0; i < n; i++)
- indexes[i] = (GLuint) s[i];
- }
- }
- break;
- case GL_HALF_FLOAT_ARB:
- {
- GLuint i;
- const GLhalfARB *s = (const GLhalfARB *) src;
- if (unpack->SwapBytes) {
- for (i = 0; i < n; i++) {
- GLhalfARB value = s[i];
- SWAP2BYTE(value);
- indexes[i] = (GLuint) _mesa_half_to_float(value);
- }
- }
- else {
- for (i = 0; i < n; i++)
- indexes[i] = (GLuint) _mesa_half_to_float(s[i]);
- }
- }
- break;
- case GL_UNSIGNED_INT_24_8_EXT:
- {
- GLuint i;
- const GLuint *s = (const GLuint *) src;
- if (unpack->SwapBytes) {
- for (i = 0; i < n; i++) {
- GLuint value = s[i];
- SWAP4BYTE(value);
- indexes[i] = value & 0xff; /* lower 8 bits */
- }
- }
- else {
- for (i = 0; i < n; i++)
- indexes[i] = s[i] & 0xff; /* lower 8 bits */
- }
- }
- break;
-
- default:
- _mesa_problem(NULL, "bad srcType in extract_uint_indexes");
- return;
- }
-}
-
-
-/**
- * Return source/dest RGBA indexes for unpacking pixels.
- */
-static void
-get_component_mapping(GLenum format,
- GLint *rSrc,
- GLint *gSrc,
- GLint *bSrc,
- GLint *aSrc,
- GLint *rDst,
- GLint *gDst,
- GLint *bDst,
- GLint *aDst)
-{
- switch (format) {
- case GL_RED:
- case GL_RED_INTEGER_EXT:
- *rSrc = 0;
- *gSrc = *bSrc = *aSrc = -1;
- break;
- case GL_GREEN:
- case GL_GREEN_INTEGER_EXT:
- *gSrc = 0;
- *rSrc = *bSrc = *aSrc = -1;
- break;
- case GL_BLUE:
- case GL_BLUE_INTEGER_EXT:
- *bSrc = 0;
- *rSrc = *gSrc = *aSrc = -1;
- break;
- case GL_ALPHA:
- case GL_ALPHA_INTEGER_EXT:
- *rSrc = *gSrc = *bSrc = -1;
- *aSrc = 0;
- break;
- case GL_LUMINANCE:
- case GL_LUMINANCE_INTEGER_EXT:
- *rSrc = *gSrc = *bSrc = 0;
- *aSrc = -1;
- break;
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:
- *rSrc = *gSrc = *bSrc = 0;
- *aSrc = 1;
- break;
- case GL_INTENSITY:
- *rSrc = *gSrc = *bSrc = *aSrc = 0;
- break;
- case GL_RG:
- case GL_RG_INTEGER:
- *rSrc = 0;
- *gSrc = 1;
- *bSrc = -1;
- *aSrc = -1;
- *rDst = 0;
- *gDst = 1;
- *bDst = 2;
- *aDst = 3;
- break;
- case GL_RGB:
- case GL_RGB_INTEGER:
- *rSrc = 0;
- *gSrc = 1;
- *bSrc = 2;
- *aSrc = -1;
- *rDst = 0;
- *gDst = 1;
- *bDst = 2;
- *aDst = 3;
- break;
- case GL_BGR:
- *rSrc = 2;
- *gSrc = 1;
- *bSrc = 0;
- *aSrc = -1;
- *rDst = 2;
- *gDst = 1;
- *bDst = 0;
- *aDst = 3;
- break;
- case GL_RGBA:
- case GL_RGBA_INTEGER:
- *rSrc = 0;
- *gSrc = 1;
- *bSrc = 2;
- *aSrc = 3;
- *rDst = 0;
- *gDst = 1;
- *bDst = 2;
- *aDst = 3;
- break;
- case GL_BGRA:
- *rSrc = 2;
- *gSrc = 1;
- *bSrc = 0;
- *aSrc = 3;
- *rDst = 2;
- *gDst = 1;
- *bDst = 0;
- *aDst = 3;
- break;
- case GL_ABGR_EXT:
- *rSrc = 3;
- *gSrc = 2;
- *bSrc = 1;
- *aSrc = 0;
- *rDst = 3;
- *gDst = 2;
- *bDst = 1;
- *aDst = 0;
- break;
- case GL_DU8DV8_ATI:
- case GL_DUDV_ATI:
- *rSrc = 0;
- *gSrc = 1;
- *bSrc = -1;
- *aSrc = -1;
- break;
- default:
- _mesa_problem(NULL, "bad srcFormat %s in get_component_mapping",
- _mesa_lookup_enum_by_nr(format));
- return;
- }
-}
-
-
-
-/*
- * This function extracts floating point RGBA values from arbitrary
- * image data. srcFormat and srcType are the format and type parameters
- * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
- *
- * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
- * implements the "Conversion to floating point", "Conversion to RGB",
- * and "Final Expansion to RGBA" operations.
- *
- * Args: n - number of pixels
- * rgba - output colors
- * srcFormat - format of incoming data
- * srcType - data type of incoming data
- * src - source data pointer
- * swapBytes - perform byteswapping of incoming data?
- */
-static void
-extract_float_rgba(GLuint n, GLfloat rgba[][4],
- GLenum srcFormat, GLenum srcType, const GLvoid *src,
- GLboolean swapBytes)
-{
- GLint rSrc, gSrc, bSrc, aSrc;
- GLint stride;
- GLint rDst, bDst, gDst, aDst;
- GLboolean intFormat;
- GLfloat rs = 1.0f, gs = 1.0f, bs = 1.0f, as = 1.0f; /* scale factors */
-
- ASSERT(srcFormat == GL_RED ||
- srcFormat == GL_GREEN ||
- srcFormat == GL_BLUE ||
- srcFormat == GL_ALPHA ||
- srcFormat == GL_LUMINANCE ||
- srcFormat == GL_LUMINANCE_ALPHA ||
- srcFormat == GL_INTENSITY ||
- srcFormat == GL_RG ||
- srcFormat == GL_RGB ||
- srcFormat == GL_BGR ||
- srcFormat == GL_RGBA ||
- srcFormat == GL_BGRA ||
- srcFormat == GL_ABGR_EXT ||
- srcFormat == GL_DU8DV8_ATI ||
- srcFormat == GL_DUDV_ATI ||
- srcFormat == GL_RED_INTEGER_EXT ||
- srcFormat == GL_GREEN_INTEGER_EXT ||
- srcFormat == GL_BLUE_INTEGER_EXT ||
- srcFormat == GL_ALPHA_INTEGER_EXT ||
- srcFormat == GL_RGB_INTEGER_EXT ||
- srcFormat == GL_RGBA_INTEGER_EXT ||
- srcFormat == GL_BGR_INTEGER_EXT ||
- srcFormat == GL_BGRA_INTEGER_EXT ||
- srcFormat == GL_LUMINANCE_INTEGER_EXT ||
- srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT);
-
- ASSERT(srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_BYTE ||
- srcType == GL_UNSIGNED_SHORT ||
- srcType == GL_SHORT ||
- srcType == GL_UNSIGNED_INT ||
- srcType == GL_INT ||
- srcType == GL_HALF_FLOAT_ARB ||
- srcType == GL_FLOAT ||
- srcType == GL_UNSIGNED_BYTE_3_3_2 ||
- srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
- srcType == GL_UNSIGNED_SHORT_5_6_5 ||
- srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
- srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
- srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
- srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
- srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
- srcType == GL_UNSIGNED_INT_8_8_8_8 ||
- srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
- srcType == GL_UNSIGNED_INT_10_10_10_2 ||
- srcType == GL_UNSIGNED_INT_2_10_10_10_REV);
-
- get_component_mapping(srcFormat,
- &rSrc, &gSrc, &bSrc, &aSrc,
- &rDst, &gDst, &bDst, &aDst);
-
- stride = _mesa_components_in_format(srcFormat);
-
- intFormat = _mesa_is_integer_format(srcFormat);
-
-#define PROCESS(SRC_INDEX, DST_INDEX, DEFAULT_FLT, DEFAULT_INT, TYPE, CONVERSION) \
- if ((SRC_INDEX) < 0) { \
- GLuint i; \
- if (intFormat) { \
- for (i = 0; i < n; i++) { \
- rgba[i][DST_INDEX] = DEFAULT_INT; \
- } \
- } \
- else { \
- for (i = 0; i < n; i++) { \
- rgba[i][DST_INDEX] = DEFAULT_FLT; \
- } \
- } \
- } \
- else if (swapBytes) { \
- const TYPE *s = (const TYPE *) src; \
- GLuint i; \
- for (i = 0; i < n; i++) { \
- TYPE value = s[SRC_INDEX]; \
- if (sizeof(TYPE) == 2) { \
- SWAP2BYTE(value); \
- } \
- else if (sizeof(TYPE) == 4) { \
- SWAP4BYTE(value); \
- } \
- if (intFormat) \
- rgba[i][DST_INDEX] = (GLfloat) value; \
- else \
- rgba[i][DST_INDEX] = (GLfloat) CONVERSION(value); \
- s += stride; \
- } \
- } \
- else { \
- const TYPE *s = (const TYPE *) src; \
- GLuint i; \
- if (intFormat) { \
- for (i = 0; i < n; i++) { \
- rgba[i][DST_INDEX] = (GLfloat) s[SRC_INDEX]; \
- s += stride; \
- } \
- } \
- else { \
- for (i = 0; i < n; i++) { \
- rgba[i][DST_INDEX] = (GLfloat) CONVERSION(s[SRC_INDEX]); \
- s += stride; \
- } \
- } \
- }
-
- switch (srcType) {
- case GL_UNSIGNED_BYTE:
- PROCESS(rSrc, RCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT);
- PROCESS(gSrc, GCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT);
- PROCESS(bSrc, BCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT);
- PROCESS(aSrc, ACOMP, 1.0F, 255, GLubyte, UBYTE_TO_FLOAT);
- break;
- case GL_BYTE:
- PROCESS(rSrc, RCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
- PROCESS(gSrc, GCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
- PROCESS(bSrc, BCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
- PROCESS(aSrc, ACOMP, 1.0F, 127, GLbyte, BYTE_TO_FLOAT);
- break;
- case GL_UNSIGNED_SHORT:
- PROCESS(rSrc, RCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
- PROCESS(gSrc, GCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
- PROCESS(bSrc, BCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
- PROCESS(aSrc, ACOMP, 1.0F, 0xffff, GLushort, USHORT_TO_FLOAT);
- break;
- case GL_SHORT:
- PROCESS(rSrc, RCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
- PROCESS(gSrc, GCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
- PROCESS(bSrc, BCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
- PROCESS(aSrc, ACOMP, 1.0F, 32767, GLshort, SHORT_TO_FLOAT);
- break;
- case GL_UNSIGNED_INT:
- PROCESS(rSrc, RCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
- PROCESS(gSrc, GCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
- PROCESS(bSrc, BCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
- PROCESS(aSrc, ACOMP, 1.0F, 0xffffffff, GLuint, UINT_TO_FLOAT);
- break;
- case GL_INT:
- PROCESS(rSrc, RCOMP, 0.0F, 0, GLint, INT_TO_FLOAT);
- PROCESS(gSrc, GCOMP, 0.0F, 0, GLint, INT_TO_FLOAT);
- PROCESS(bSrc, BCOMP, 0.0F, 0, GLint, INT_TO_FLOAT);
- PROCESS(aSrc, ACOMP, 1.0F, 2147483647, GLint, INT_TO_FLOAT);
- break;
- case GL_FLOAT:
- PROCESS(rSrc, RCOMP, 0.0F, 0.0F, GLfloat, (GLfloat));
- PROCESS(gSrc, GCOMP, 0.0F, 0.0F, GLfloat, (GLfloat));
- PROCESS(bSrc, BCOMP, 0.0F, 0.0F, GLfloat, (GLfloat));
- PROCESS(aSrc, ACOMP, 1.0F, 1.0F, GLfloat, (GLfloat));
- break;
- case GL_HALF_FLOAT_ARB:
- PROCESS(rSrc, RCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
- PROCESS(gSrc, GCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
- PROCESS(bSrc, BCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
- PROCESS(aSrc, ACOMP, 1.0F, 1.0F, GLhalfARB, _mesa_half_to_float);
- break;
- case GL_UNSIGNED_BYTE_3_3_2:
- {
- const GLubyte *ubsrc = (const GLubyte *) src;
- GLuint i;
- if (!intFormat) {
- rs = 1.0F / 7.0F;
- gs = 1.0F / 7.0F;
- bs = 1.0F / 3.0F;
- }
- for (i = 0; i < n; i ++) {
- GLubyte p = ubsrc[i];
- rgba[i][rDst] = ((p >> 5) ) * rs;
- rgba[i][gDst] = ((p >> 2) & 0x7) * gs;
- rgba[i][bDst] = ((p ) & 0x3) * bs;
- rgba[i][aDst] = 1.0F;
- }
- }
- break;
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- {
- const GLubyte *ubsrc = (const GLubyte *) src;
- GLuint i;
- if (!intFormat) {
- rs = 1.0F / 7.0F;
- gs = 1.0F / 7.0F;
- bs = 1.0F / 3.0F;
- }
- for (i = 0; i < n; i ++) {
- GLubyte p = ubsrc[i];
- rgba[i][rDst] = ((p ) & 0x7) * rs;
- rgba[i][gDst] = ((p >> 3) & 0x7) * gs;
- rgba[i][bDst] = ((p >> 6) ) * bs;
- rgba[i][aDst] = 1.0F;
- }
- }
- break;
- case GL_UNSIGNED_SHORT_5_6_5:
- if (!intFormat) {
- rs = 1.0F / 31.0F;
- gs = 1.0F / 63.0F;
- bs = 1.0F / 31.0F;
- }
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p >> 11) ) * rs;
- rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
- rgba[i][bDst] = ((p ) & 0x1f) * bs;
- rgba[i][aDst] = 1.0F;
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p >> 11) ) * rs;
- rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
- rgba[i][bDst] = ((p ) & 0x1f) * bs;
- rgba[i][aDst] = 1.0F;
- }
- }
- break;
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- if (!intFormat) {
- rs = 1.0F / 31.0F;
- gs = 1.0F / 63.0F;
- bs = 1.0F / 31.0F;
- }
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p ) & 0x1f) * rs;
- rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
- rgba[i][bDst] = ((p >> 11) ) * bs;
- rgba[i][aDst] = 1.0F;
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p ) & 0x1f) * rs;
- rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
- rgba[i][bDst] = ((p >> 11) ) * bs;
- rgba[i][aDst] = 1.0F;
- }
- }
- break;
- case GL_UNSIGNED_SHORT_4_4_4_4:
- if (!intFormat) {
- rs = gs = bs = as = 1.0F / 15.0F;
- }
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p >> 12) ) * rs;
- rgba[i][gDst] = ((p >> 8) & 0xf) * gs;
- rgba[i][bDst] = ((p >> 4) & 0xf) * bs;
- rgba[i][aDst] = ((p ) & 0xf) * as;
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p >> 12) ) * rs;
- rgba[i][gDst] = ((p >> 8) & 0xf) * gs;
- rgba[i][bDst] = ((p >> 4) & 0xf) * bs;
- rgba[i][aDst] = ((p ) & 0xf) * as;
- }
- }
- break;
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- if (!intFormat) {
- rs = gs = bs = as = 1.0F / 15.0F;
- }
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p ) & 0xf) * rs;
- rgba[i][gDst] = ((p >> 4) & 0xf) * gs;
- rgba[i][bDst] = ((p >> 8) & 0xf) * bs;
- rgba[i][aDst] = ((p >> 12) ) * as;
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p ) & 0xf) * rs;
- rgba[i][gDst] = ((p >> 4) & 0xf) * gs;
- rgba[i][bDst] = ((p >> 8) & 0xf) * bs;
- rgba[i][aDst] = ((p >> 12) ) * as;
- }
- }
- break;
- case GL_UNSIGNED_SHORT_5_5_5_1:
- if (!intFormat) {
- rs = gs = bs = 1.0F / 31.0F;
- }
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p >> 11) ) * rs;
- rgba[i][gDst] = ((p >> 6) & 0x1f) * gs;
- rgba[i][bDst] = ((p >> 1) & 0x1f) * bs;
- rgba[i][aDst] = ((p ) & 0x1) * as;
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p >> 11) ) * rs;
- rgba[i][gDst] = ((p >> 6) & 0x1f) * gs;
- rgba[i][bDst] = ((p >> 1) & 0x1f) * bs;
- rgba[i][aDst] = ((p ) & 0x1) * as;
- }
- }
- break;
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- if (!intFormat) {
- rs = gs = bs = 1.0F / 31.0F;
- }
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p ) & 0x1f) * rs;
- rgba[i][gDst] = ((p >> 5) & 0x1f) * gs;
- rgba[i][bDst] = ((p >> 10) & 0x1f) * bs;
- rgba[i][aDst] = ((p >> 15) ) * as;
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p ) & 0x1f) * rs;
- rgba[i][gDst] = ((p >> 5) & 0x1f) * gs;
- rgba[i][bDst] = ((p >> 10) & 0x1f) * bs;
- rgba[i][aDst] = ((p >> 15) ) * as;
- }
- }
- break;
- case GL_UNSIGNED_INT_8_8_8_8:
- if (swapBytes) {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- if (intFormat) {
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = (GLfloat) ((p ) & 0xff);
- rgba[i][gDst] = (GLfloat) ((p >> 8) & 0xff);
- rgba[i][bDst] = (GLfloat) ((p >> 16) & 0xff);
- rgba[i][aDst] = (GLfloat) ((p >> 24) );
- }
- }
- else {
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = UBYTE_TO_FLOAT((p ) & 0xff);
- rgba[i][gDst] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
- rgba[i][bDst] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
- rgba[i][aDst] = UBYTE_TO_FLOAT((p >> 24) );
- }
- }
- }
- else {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- if (intFormat) {
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = (GLfloat) ((p >> 24) );
- rgba[i][gDst] = (GLfloat) ((p >> 16) & 0xff);
- rgba[i][bDst] = (GLfloat) ((p >> 8) & 0xff);
- rgba[i][aDst] = (GLfloat) ((p ) & 0xff);
- }
- }
- else {
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = UBYTE_TO_FLOAT((p >> 24) );
- rgba[i][gDst] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
- rgba[i][bDst] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
- rgba[i][aDst] = UBYTE_TO_FLOAT((p ) & 0xff);
- }
- }
- }
- break;
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- if (swapBytes) {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- if (intFormat) {
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = (GLfloat) ((p >> 24) );
- rgba[i][gDst] = (GLfloat) ((p >> 16) & 0xff);
- rgba[i][bDst] = (GLfloat) ((p >> 8) & 0xff);
- rgba[i][aDst] = (GLfloat) ((p ) & 0xff);
- }
- }
- else {
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = UBYTE_TO_FLOAT((p >> 24) );
- rgba[i][gDst] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
- rgba[i][bDst] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
- rgba[i][aDst] = UBYTE_TO_FLOAT((p ) & 0xff);
- }
- }
- }
- else {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- if (intFormat) {
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = (GLfloat) ((p ) & 0xff);
- rgba[i][gDst] = (GLfloat) ((p >> 8) & 0xff);
- rgba[i][bDst] = (GLfloat) ((p >> 16) & 0xff);
- rgba[i][aDst] = (GLfloat) ((p >> 24) );
- }
- }
- else {
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = UBYTE_TO_FLOAT((p ) & 0xff);
- rgba[i][gDst] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
- rgba[i][bDst] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
- rgba[i][aDst] = UBYTE_TO_FLOAT((p >> 24) );
- }
- }
- }
- break;
- case GL_UNSIGNED_INT_10_10_10_2:
- if (!intFormat) {
- rs = 1.0F / 1023.0F;
- gs = 1.0F / 1023.0F;
- bs = 1.0F / 1023.0F;
- as = 1.0F / 3.0F;
- }
- if (swapBytes) {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- SWAP4BYTE(p);
- rgba[i][rDst] = ((p >> 22) ) * rs;
- rgba[i][gDst] = ((p >> 12) & 0x3ff) * gs;
- rgba[i][bDst] = ((p >> 2) & 0x3ff) * bs;
- rgba[i][aDst] = ((p ) & 0x3 ) * as;
- }
- }
- else {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = ((p >> 22) ) * rs;
- rgba[i][gDst] = ((p >> 12) & 0x3ff) * gs;
- rgba[i][bDst] = ((p >> 2) & 0x3ff) * bs;
- rgba[i][aDst] = ((p ) & 0x3 ) * as;
- }
- }
- break;
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- if (!intFormat) {
- rs = 1.0F / 1023.0F;
- gs = 1.0F / 1023.0F;
- bs = 1.0F / 1023.0F;
- as = 1.0F / 3.0F;
- }
- if (swapBytes) {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- SWAP4BYTE(p);
- rgba[i][rDst] = ((p ) & 0x3ff) * rs;
- rgba[i][gDst] = ((p >> 10) & 0x3ff) * gs;
- rgba[i][bDst] = ((p >> 20) & 0x3ff) * bs;
- rgba[i][aDst] = ((p >> 30) ) * as;
- }
- }
- else {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = ((p ) & 0x3ff) * rs;
- rgba[i][gDst] = ((p >> 10) & 0x3ff) * gs;
- rgba[i][bDst] = ((p >> 20) & 0x3ff) * bs;
- rgba[i][aDst] = ((p >> 30) ) * as;
- }
- }
- break;
- default:
- _mesa_problem(NULL, "bad srcType in extract float data");
- break;
- }
-#undef PROCESS
-}
-
-
-static INLINE GLuint
-clamp_byte_to_uint(GLbyte b)
-{
- return b < 0 ? 0 : b;
-}
-
-
-static INLINE GLuint
-clamp_short_to_uint(GLshort s)
-{
- return s < 0 ? 0 : s;
-}
-
-
-static INLINE GLuint
-clamp_int_to_uint(GLint i)
-{
- return i < 0 ? 0 : i;
-}
-
-
-static INLINE GLuint
-clamp_float_to_uint(GLfloat f)
-{
- return f < 0.0F ? 0 : IROUND(f);
-}
-
-
-static INLINE GLuint
-clamp_half_to_uint(GLhalfARB h)
-{
- GLfloat f = _mesa_half_to_float(h);
- return f < 0.0F ? 0 : IROUND(f);
-}
-
-
-/**
- * \sa extract_float_rgba()
- */
-static void
-extract_uint_rgba(GLuint n, GLuint rgba[][4],
- GLenum srcFormat, GLenum srcType, const GLvoid *src,
- GLboolean swapBytes)
-{
- GLint rSrc, gSrc, bSrc, aSrc;
- GLint stride;
- GLint rDst, bDst, gDst, aDst;
- GLboolean intFormat;
-
- ASSERT(srcFormat == GL_RED ||
- srcFormat == GL_GREEN ||
- srcFormat == GL_BLUE ||
- srcFormat == GL_ALPHA ||
- srcFormat == GL_LUMINANCE ||
- srcFormat == GL_LUMINANCE_ALPHA ||
- srcFormat == GL_INTENSITY ||
- srcFormat == GL_RG ||
- srcFormat == GL_RGB ||
- srcFormat == GL_BGR ||
- srcFormat == GL_RGBA ||
- srcFormat == GL_BGRA ||
- srcFormat == GL_ABGR_EXT ||
- srcFormat == GL_DU8DV8_ATI ||
- srcFormat == GL_DUDV_ATI ||
- srcFormat == GL_RED_INTEGER_EXT ||
- srcFormat == GL_GREEN_INTEGER_EXT ||
- srcFormat == GL_BLUE_INTEGER_EXT ||
- srcFormat == GL_ALPHA_INTEGER_EXT ||
- srcFormat == GL_RGB_INTEGER_EXT ||
- srcFormat == GL_RGBA_INTEGER_EXT ||
- srcFormat == GL_BGR_INTEGER_EXT ||
- srcFormat == GL_BGRA_INTEGER_EXT ||
- srcFormat == GL_LUMINANCE_INTEGER_EXT ||
- srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT);
-
- ASSERT(srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_BYTE ||
- srcType == GL_UNSIGNED_SHORT ||
- srcType == GL_SHORT ||
- srcType == GL_UNSIGNED_INT ||
- srcType == GL_INT ||
- srcType == GL_HALF_FLOAT_ARB ||
- srcType == GL_FLOAT ||
- srcType == GL_UNSIGNED_BYTE_3_3_2 ||
- srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
- srcType == GL_UNSIGNED_SHORT_5_6_5 ||
- srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
- srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
- srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
- srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
- srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
- srcType == GL_UNSIGNED_INT_8_8_8_8 ||
- srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
- srcType == GL_UNSIGNED_INT_10_10_10_2 ||
- srcType == GL_UNSIGNED_INT_2_10_10_10_REV);
-
- get_component_mapping(srcFormat,
- &rSrc, &gSrc, &bSrc, &aSrc,
- &rDst, &gDst, &bDst, &aDst);
-
- stride = _mesa_components_in_format(srcFormat);
-
- intFormat = _mesa_is_integer_format(srcFormat);
-
-#define PROCESS(SRC_INDEX, DST_INDEX, DEFAULT, TYPE, CONVERSION) \
- if ((SRC_INDEX) < 0) { \
- GLuint i; \
- for (i = 0; i < n; i++) { \
- rgba[i][DST_INDEX] = DEFAULT; \
- } \
- } \
- else if (swapBytes) { \
- const TYPE *s = (const TYPE *) src; \
- GLuint i; \
- for (i = 0; i < n; i++) { \
- TYPE value = s[SRC_INDEX]; \
- if (sizeof(TYPE) == 2) { \
- SWAP2BYTE(value); \
- } \
- else if (sizeof(TYPE) == 4) { \
- SWAP4BYTE(value); \
- } \
- rgba[i][DST_INDEX] = CONVERSION(value); \
- s += stride; \
- } \
- } \
- else { \
- const TYPE *s = (const TYPE *) src; \
- GLuint i; \
- for (i = 0; i < n; i++) { \
- rgba[i][DST_INDEX] = CONVERSION(s[SRC_INDEX]); \
- s += stride; \
- } \
- }
-
- switch (srcType) {
- case GL_UNSIGNED_BYTE:
- PROCESS(rSrc, RCOMP, 0, GLubyte, (GLuint));
- PROCESS(gSrc, GCOMP, 0, GLubyte, (GLuint));
- PROCESS(bSrc, BCOMP, 0, GLubyte, (GLuint));
- PROCESS(aSrc, ACOMP, 1, GLubyte, (GLuint));
- break;
- case GL_BYTE:
- PROCESS(rSrc, RCOMP, 0, GLbyte, clamp_byte_to_uint);
- PROCESS(gSrc, GCOMP, 0, GLbyte, clamp_byte_to_uint);
- PROCESS(bSrc, BCOMP, 0, GLbyte, clamp_byte_to_uint);
- PROCESS(aSrc, ACOMP, 1, GLbyte, clamp_byte_to_uint);
- break;
- case GL_UNSIGNED_SHORT:
- PROCESS(rSrc, RCOMP, 0, GLushort, (GLuint));
- PROCESS(gSrc, GCOMP, 0, GLushort, (GLuint));
- PROCESS(bSrc, BCOMP, 0, GLushort, (GLuint));
- PROCESS(aSrc, ACOMP, 1, GLushort, (GLuint));
- break;
- case GL_SHORT:
- PROCESS(rSrc, RCOMP, 0, GLshort, clamp_short_to_uint);
- PROCESS(gSrc, GCOMP, 0, GLshort, clamp_short_to_uint);
- PROCESS(bSrc, BCOMP, 0, GLshort, clamp_short_to_uint);
- PROCESS(aSrc, ACOMP, 1, GLshort, clamp_short_to_uint);
- break;
- case GL_UNSIGNED_INT:
- PROCESS(rSrc, RCOMP, 0, GLuint, (GLuint));
- PROCESS(gSrc, GCOMP, 0, GLuint, (GLuint));
- PROCESS(bSrc, BCOMP, 0, GLuint, (GLuint));
- PROCESS(aSrc, ACOMP, 1, GLuint, (GLuint));
- break;
- case GL_INT:
- PROCESS(rSrc, RCOMP, 0, GLint, clamp_int_to_uint);
- PROCESS(gSrc, GCOMP, 0, GLint, clamp_int_to_uint);
- PROCESS(bSrc, BCOMP, 0, GLint, clamp_int_to_uint);
- PROCESS(aSrc, ACOMP, 1, GLint, clamp_int_to_uint);
- break;
- case GL_FLOAT:
- PROCESS(rSrc, RCOMP, 0, GLfloat, clamp_float_to_uint);
- PROCESS(gSrc, GCOMP, 0, GLfloat, clamp_float_to_uint);
- PROCESS(bSrc, BCOMP, 0, GLfloat, clamp_float_to_uint);
- PROCESS(aSrc, ACOMP, 1, GLfloat, clamp_float_to_uint);
- break;
- case GL_HALF_FLOAT_ARB:
- PROCESS(rSrc, RCOMP, 0, GLhalfARB, clamp_half_to_uint);
- PROCESS(gSrc, GCOMP, 0, GLhalfARB, clamp_half_to_uint);
- PROCESS(bSrc, BCOMP, 0, GLhalfARB, clamp_half_to_uint);
- PROCESS(aSrc, ACOMP, 1, GLhalfARB, clamp_half_to_uint);
- break;
- case GL_UNSIGNED_BYTE_3_3_2:
- {
- const GLubyte *ubsrc = (const GLubyte *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLubyte p = ubsrc[i];
- rgba[i][rDst] = ((p >> 5) );
- rgba[i][gDst] = ((p >> 2) & 0x7);
- rgba[i][bDst] = ((p ) & 0x3);
- rgba[i][aDst] = 1;
- }
- }
- break;
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- {
- const GLubyte *ubsrc = (const GLubyte *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLubyte p = ubsrc[i];
- rgba[i][rDst] = ((p ) & 0x7);
- rgba[i][gDst] = ((p >> 3) & 0x7);
- rgba[i][bDst] = ((p >> 6) );
- rgba[i][aDst] = 1;
- }
- }
- break;
- case GL_UNSIGNED_SHORT_5_6_5:
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p >> 11) );
- rgba[i][gDst] = ((p >> 5) & 0x3f);
- rgba[i][bDst] = ((p ) & 0x1f);
- rgba[i][aDst] = 1;
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p >> 11) );
- rgba[i][gDst] = ((p >> 5) & 0x3f);
- rgba[i][bDst] = ((p ) & 0x1f);
- rgba[i][aDst] = 1;
- }
- }
- break;
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p ) & 0x1f);
- rgba[i][gDst] = ((p >> 5) & 0x3f);
- rgba[i][bDst] = ((p >> 11) );
- rgba[i][aDst] = 1;
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p ) & 0x1f);
- rgba[i][gDst] = ((p >> 5) & 0x3f);
- rgba[i][bDst] = ((p >> 11) );
- rgba[i][aDst] = 1;
- }
- }
- break;
- case GL_UNSIGNED_SHORT_4_4_4_4:
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p >> 12) );
- rgba[i][gDst] = ((p >> 8) & 0xf);
- rgba[i][bDst] = ((p >> 4) & 0xf);
- rgba[i][aDst] = ((p ) & 0xf);
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p >> 12) );
- rgba[i][gDst] = ((p >> 8) & 0xf);
- rgba[i][bDst] = ((p >> 4) & 0xf);
- rgba[i][aDst] = ((p ) & 0xf);
- }
- }
- break;
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p ) & 0xf);
- rgba[i][gDst] = ((p >> 4) & 0xf);
- rgba[i][bDst] = ((p >> 8) & 0xf);
- rgba[i][aDst] = ((p >> 12) );
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p ) & 0xf);
- rgba[i][gDst] = ((p >> 4) & 0xf);
- rgba[i][bDst] = ((p >> 8) & 0xf);
- rgba[i][aDst] = ((p >> 12) );
- }
- }
- break;
- case GL_UNSIGNED_SHORT_5_5_5_1:
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p >> 11) );
- rgba[i][gDst] = ((p >> 6) & 0x1f);
- rgba[i][bDst] = ((p >> 1) & 0x1f);
- rgba[i][aDst] = ((p ) & 0x1 );
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p >> 11) );
- rgba[i][gDst] = ((p >> 6) & 0x1f);
- rgba[i][bDst] = ((p >> 1) & 0x1f);
- rgba[i][aDst] = ((p ) & 0x1 );
- }
- }
- break;
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- if (swapBytes) {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- SWAP2BYTE(p);
- rgba[i][rDst] = ((p ) & 0x1f);
- rgba[i][gDst] = ((p >> 5) & 0x1f);
- rgba[i][bDst] = ((p >> 10) & 0x1f);
- rgba[i][aDst] = ((p >> 15) );
- }
- }
- else {
- const GLushort *ussrc = (const GLushort *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLushort p = ussrc[i];
- rgba[i][rDst] = ((p ) & 0x1f);
- rgba[i][gDst] = ((p >> 5) & 0x1f);
- rgba[i][bDst] = ((p >> 10) & 0x1f);
- rgba[i][aDst] = ((p >> 15) );
- }
- }
- break;
- case GL_UNSIGNED_INT_8_8_8_8:
- if (swapBytes) {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = ((p ) & 0xff);
- rgba[i][gDst] = ((p >> 8) & 0xff);
- rgba[i][bDst] = ((p >> 16) & 0xff);
- rgba[i][aDst] = ((p >> 24) );
- }
- }
- else {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = ((p >> 24) );
- rgba[i][gDst] = ((p >> 16) & 0xff);
- rgba[i][bDst] = ((p >> 8) & 0xff);
- rgba[i][aDst] = ((p ) & 0xff);
- }
- }
- break;
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- if (swapBytes) {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = ((p >> 24) );
- rgba[i][gDst] = ((p >> 16) & 0xff);
- rgba[i][bDst] = ((p >> 8) & 0xff);
- rgba[i][aDst] = ((p ) & 0xff);
- }
- }
- else {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = ((p ) & 0xff);
- rgba[i][gDst] = ((p >> 8) & 0xff);
- rgba[i][bDst] = ((p >> 16) & 0xff);
- rgba[i][aDst] = ((p >> 24) );
- }
- }
- break;
- case GL_UNSIGNED_INT_10_10_10_2:
- if (swapBytes) {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- SWAP4BYTE(p);
- rgba[i][rDst] = ((p >> 22) );
- rgba[i][gDst] = ((p >> 12) & 0x3ff);
- rgba[i][bDst] = ((p >> 2) & 0x3ff);
- rgba[i][aDst] = ((p ) & 0x3 );
- }
- }
- else {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = ((p >> 22) );
- rgba[i][gDst] = ((p >> 12) & 0x3ff);
- rgba[i][bDst] = ((p >> 2) & 0x3ff);
- rgba[i][aDst] = ((p ) & 0x3 );
- }
- }
- break;
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- if (swapBytes) {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- SWAP4BYTE(p);
- rgba[i][rDst] = ((p ) & 0x3ff);
- rgba[i][gDst] = ((p >> 10) & 0x3ff);
- rgba[i][bDst] = ((p >> 20) & 0x3ff);
- rgba[i][aDst] = ((p >> 30) );
- }
- }
- else {
- const GLuint *uisrc = (const GLuint *) src;
- GLuint i;
- for (i = 0; i < n; i ++) {
- GLuint p = uisrc[i];
- rgba[i][rDst] = ((p ) & 0x3ff);
- rgba[i][gDst] = ((p >> 10) & 0x3ff);
- rgba[i][bDst] = ((p >> 20) & 0x3ff);
- rgba[i][aDst] = ((p >> 30) );
- }
- }
- break;
- default:
- _mesa_problem(NULL, "bad srcType in extract uint data");
- break;
- }
-#undef PROCESS
-}
-
-
-
-/*
- * Unpack a row of color image data from a client buffer according to
- * the pixel unpacking parameters.
- * Return GLchan values in the specified dest image format.
- * This is used by glDrawPixels and glTexImage?D().
- * \param ctx - the context
- * n - number of pixels in the span
- * dstFormat - format of destination color array
- * dest - the destination color array
- * srcFormat - source image format
- * srcType - source image data type
- * source - source image pointer
- * srcPacking - pixel unpacking parameters
- * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
- *
- * XXX perhaps expand this to process whole images someday.
- */
-void
-_mesa_unpack_color_span_chan( struct gl_context *ctx,
- GLuint n, GLenum dstFormat, GLchan dest[],
- GLenum srcFormat, GLenum srcType,
- const GLvoid *source,
- const struct gl_pixelstore_attrib *srcPacking,
- GLbitfield transferOps )
-{
- ASSERT(dstFormat == GL_ALPHA ||
- dstFormat == GL_LUMINANCE ||
- dstFormat == GL_LUMINANCE_ALPHA ||
- dstFormat == GL_INTENSITY ||
- dstFormat == GL_RED ||
- dstFormat == GL_RG ||
- dstFormat == GL_RGB ||
- dstFormat == GL_RGBA ||
- dstFormat == GL_COLOR_INDEX);
-
- ASSERT(srcFormat == GL_RED ||
- srcFormat == GL_GREEN ||
- srcFormat == GL_BLUE ||
- srcFormat == GL_ALPHA ||
- srcFormat == GL_LUMINANCE ||
- srcFormat == GL_LUMINANCE_ALPHA ||
- srcFormat == GL_INTENSITY ||
- srcFormat == GL_RG ||
- srcFormat == GL_RGB ||
- srcFormat == GL_BGR ||
- srcFormat == GL_RGBA ||
- srcFormat == GL_BGRA ||
- srcFormat == GL_ABGR_EXT ||
- srcFormat == GL_COLOR_INDEX);
-
- ASSERT(srcType == GL_BITMAP ||
- srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_BYTE ||
- srcType == GL_UNSIGNED_SHORT ||
- srcType == GL_SHORT ||
- srcType == GL_UNSIGNED_INT ||
- srcType == GL_INT ||
- srcType == GL_HALF_FLOAT_ARB ||
- srcType == GL_FLOAT ||
- srcType == GL_UNSIGNED_BYTE_3_3_2 ||
- srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
- srcType == GL_UNSIGNED_SHORT_5_6_5 ||
- srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
- srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
- srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
- srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
- srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
- srcType == GL_UNSIGNED_INT_8_8_8_8 ||
- srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
- srcType == GL_UNSIGNED_INT_10_10_10_2 ||
- srcType == GL_UNSIGNED_INT_2_10_10_10_REV);
-
- /* Try simple cases first */
- if (transferOps == 0) {
- if (srcType == CHAN_TYPE) {
- if (dstFormat == GL_RGBA) {
- if (srcFormat == GL_RGBA) {
- memcpy( dest, source, n * 4 * sizeof(GLchan) );
- return;
- }
- else if (srcFormat == GL_RGB) {
- GLuint i;
- const GLchan *src = (const GLchan *) source;
- GLchan *dst = dest;
- for (i = 0; i < n; i++) {
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- dst[3] = CHAN_MAX;
- src += 3;
- dst += 4;
- }
- return;
- }
- }
- else if (dstFormat == GL_RGB) {
- if (srcFormat == GL_RGB) {
- memcpy( dest, source, n * 3 * sizeof(GLchan) );
- return;
- }
- else if (srcFormat == GL_RGBA) {
- GLuint i;
- const GLchan *src = (const GLchan *) source;
- GLchan *dst = dest;
- for (i = 0; i < n; i++) {
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- src += 4;
- dst += 3;
- }
- return;
- }
- }
- else if (dstFormat == srcFormat) {
- GLint comps = _mesa_components_in_format(srcFormat);
- assert(comps > 0);
- memcpy( dest, source, n * comps * sizeof(GLchan) );
- return;
- }
- }
- /*
- * Common situation, loading 8bit RGBA/RGB source images
- * into 16/32 bit destination. (OSMesa16/32)
- */
- else if (srcType == GL_UNSIGNED_BYTE) {
- if (dstFormat == GL_RGBA) {
- if (srcFormat == GL_RGB) {
- GLuint i;
- const GLubyte *src = (const GLubyte *) source;
- GLchan *dst = dest;
- for (i = 0; i < n; i++) {
- dst[0] = UBYTE_TO_CHAN(src[0]);
- dst[1] = UBYTE_TO_CHAN(src[1]);
- dst[2] = UBYTE_TO_CHAN(src[2]);
- dst[3] = CHAN_MAX;
- src += 3;
- dst += 4;
- }
- return;
- }
- else if (srcFormat == GL_RGBA) {
- GLuint i;
- const GLubyte *src = (const GLubyte *) source;
- GLchan *dst = dest;
- for (i = 0; i < n; i++) {
- dst[0] = UBYTE_TO_CHAN(src[0]);
- dst[1] = UBYTE_TO_CHAN(src[1]);
- dst[2] = UBYTE_TO_CHAN(src[2]);
- dst[3] = UBYTE_TO_CHAN(src[3]);
- src += 4;
- dst += 4;
- }
- return;
- }
- }
- else if (dstFormat == GL_RGB) {
- if (srcFormat == GL_RGB) {
- GLuint i;
- const GLubyte *src = (const GLubyte *) source;
- GLchan *dst = dest;
- for (i = 0; i < n; i++) {
- dst[0] = UBYTE_TO_CHAN(src[0]);
- dst[1] = UBYTE_TO_CHAN(src[1]);
- dst[2] = UBYTE_TO_CHAN(src[2]);
- src += 3;
- dst += 3;
- }
- return;
- }
- else if (srcFormat == GL_RGBA) {
- GLuint i;
- const GLubyte *src = (const GLubyte *) source;
- GLchan *dst = dest;
- for (i = 0; i < n; i++) {
- dst[0] = UBYTE_TO_CHAN(src[0]);
- dst[1] = UBYTE_TO_CHAN(src[1]);
- dst[2] = UBYTE_TO_CHAN(src[2]);
- src += 4;
- dst += 3;
- }
- return;
- }
- }
- }
- }
-
-
- /* general solution begins here */
- {
- GLint dstComponents;
- GLint rDst, gDst, bDst, aDst, lDst, iDst;
- GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * n * sizeof(GLfloat));
-
- if (!rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
- return;
- }
-
- dstComponents = _mesa_components_in_format( dstFormat );
- /* source & dest image formats should have been error checked by now */
- assert(dstComponents > 0);
-
- /*
- * Extract image data and convert to RGBA floats
- */
- if (srcFormat == GL_COLOR_INDEX) {
- GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
-
- if (!indexes) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
- return;
- }
-
- extract_uint_indexes(n, indexes, srcFormat, srcType, source,
- srcPacking);
-
- if (dstFormat == GL_COLOR_INDEX) {
- GLuint i;
- _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
- /* convert to GLchan and return */
- for (i = 0; i < n; i++) {
- dest[i] = (GLchan) (indexes[i] & 0xff);
- }
- free(indexes);
- free(rgba);
- return;
- }
- else {
- /* Convert indexes to RGBA */
- if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
- _mesa_shift_and_offset_ci(ctx, n, indexes);
- }
- _mesa_map_ci_to_rgba(ctx, n, indexes, rgba);
- }
-
- /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
- * with color indexes.
- */
- transferOps &= ~(IMAGE_SCALE_BIAS_BIT | IMAGE_MAP_COLOR_BIT);
-
- free(indexes);
- }
- else {
- /* non-color index data */
- extract_float_rgba(n, rgba, srcFormat, srcType, source,
- srcPacking->SwapBytes);
- }
-
- /* Need to clamp if returning GLubytes or GLushorts */
-#if CHAN_TYPE != GL_FLOAT
- transferOps |= IMAGE_CLAMP_BIT;
-#endif
-
- if (transferOps) {
- _mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
- }
-
- get_component_indexes(dstFormat,
- &rDst, &gDst, &bDst, &aDst, &lDst, &iDst);
-
- /* Now return the GLchan data in the requested dstFormat */
- if (rDst >= 0) {
- GLchan *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- CLAMPED_FLOAT_TO_CHAN(dst[rDst], rgba[i][RCOMP]);
- dst += dstComponents;
- }
- }
-
- if (gDst >= 0) {
- GLchan *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- CLAMPED_FLOAT_TO_CHAN(dst[gDst], rgba[i][GCOMP]);
- dst += dstComponents;
- }
- }
-
- if (bDst >= 0) {
- GLchan *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- CLAMPED_FLOAT_TO_CHAN(dst[bDst], rgba[i][BCOMP]);
- dst += dstComponents;
- }
- }
-
- if (aDst >= 0) {
- GLchan *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- CLAMPED_FLOAT_TO_CHAN(dst[aDst], rgba[i][ACOMP]);
- dst += dstComponents;
- }
- }
-
- if (iDst >= 0) {
- GLchan *dst = dest;
- GLuint i;
- assert(iDst == 0);
- assert(dstComponents == 1);
- for (i = 0; i < n; i++) {
- /* Intensity comes from red channel */
- CLAMPED_FLOAT_TO_CHAN(dst[i], rgba[i][RCOMP]);
- }
- }
-
- if (lDst >= 0) {
- GLchan *dst = dest;
- GLuint i;
- assert(lDst == 0);
- for (i = 0; i < n; i++) {
- /* Luminance comes from red channel */
- CLAMPED_FLOAT_TO_CHAN(dst[0], rgba[i][RCOMP]);
- dst += dstComponents;
- }
- }
-
- free(rgba);
- }
-}
-
-
-/**
- * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
- * instead of GLchan.
- */
-void
-_mesa_unpack_color_span_float( struct gl_context *ctx,
- GLuint n, GLenum dstFormat, GLfloat dest[],
- GLenum srcFormat, GLenum srcType,
- const GLvoid *source,
- const struct gl_pixelstore_attrib *srcPacking,
- GLbitfield transferOps )
-{
- ASSERT(dstFormat == GL_ALPHA ||
- dstFormat == GL_LUMINANCE ||
- dstFormat == GL_LUMINANCE_ALPHA ||
- dstFormat == GL_INTENSITY ||
- dstFormat == GL_RED ||
- dstFormat == GL_RG ||
- dstFormat == GL_RGB ||
- dstFormat == GL_RGBA ||
- dstFormat == GL_COLOR_INDEX);
-
- ASSERT(srcFormat == GL_RED ||
- srcFormat == GL_GREEN ||
- srcFormat == GL_BLUE ||
- srcFormat == GL_ALPHA ||
- srcFormat == GL_LUMINANCE ||
- srcFormat == GL_LUMINANCE_ALPHA ||
- srcFormat == GL_INTENSITY ||
- srcFormat == GL_RG ||
- srcFormat == GL_RGB ||
- srcFormat == GL_BGR ||
- srcFormat == GL_RGBA ||
- srcFormat == GL_BGRA ||
- srcFormat == GL_ABGR_EXT ||
- srcFormat == GL_RED_INTEGER_EXT ||
- srcFormat == GL_GREEN_INTEGER_EXT ||
- srcFormat == GL_BLUE_INTEGER_EXT ||
- srcFormat == GL_ALPHA_INTEGER_EXT ||
- srcFormat == GL_RGB_INTEGER_EXT ||
- srcFormat == GL_RGBA_INTEGER_EXT ||
- srcFormat == GL_BGR_INTEGER_EXT ||
- srcFormat == GL_BGRA_INTEGER_EXT ||
- srcFormat == GL_LUMINANCE_INTEGER_EXT ||
- srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT ||
- srcFormat == GL_COLOR_INDEX);
-
- ASSERT(srcType == GL_BITMAP ||
- srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_BYTE ||
- srcType == GL_UNSIGNED_SHORT ||
- srcType == GL_SHORT ||
- srcType == GL_UNSIGNED_INT ||
- srcType == GL_INT ||
- srcType == GL_HALF_FLOAT_ARB ||
- srcType == GL_FLOAT ||
- srcType == GL_UNSIGNED_BYTE_3_3_2 ||
- srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
- srcType == GL_UNSIGNED_SHORT_5_6_5 ||
- srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
- srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
- srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
- srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
- srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
- srcType == GL_UNSIGNED_INT_8_8_8_8 ||
- srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
- srcType == GL_UNSIGNED_INT_10_10_10_2 ||
- srcType == GL_UNSIGNED_INT_2_10_10_10_REV);
-
- /* general solution, no special cases, yet */
- {
- GLint dstComponents;
- GLint rDst, gDst, bDst, aDst, lDst, iDst;
- GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * n * sizeof(GLfloat));
-
- if (!rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
- return;
- }
-
- dstComponents = _mesa_components_in_format( dstFormat );
- /* source & dest image formats should have been error checked by now */
- assert(dstComponents > 0);
-
- /*
- * Extract image data and convert to RGBA floats
- */
- if (srcFormat == GL_COLOR_INDEX) {
- GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
-
- if (!indexes) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
- free(rgba);
- return;
- }
-
- extract_uint_indexes(n, indexes, srcFormat, srcType, source,
- srcPacking);
-
- if (dstFormat == GL_COLOR_INDEX) {
- GLuint i;
- _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
- /* convert to GLchan and return */
- for (i = 0; i < n; i++) {
- dest[i] = (GLchan) (indexes[i] & 0xff);
- }
- free(indexes);
- free(rgba);
- return;
- }
- else {
- /* Convert indexes to RGBA */
- if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
- _mesa_shift_and_offset_ci(ctx, n, indexes);
- }
- _mesa_map_ci_to_rgba(ctx, n, indexes, rgba);
- }
-
- /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
- * with color indexes.
- */
- transferOps &= ~(IMAGE_SCALE_BIAS_BIT | IMAGE_MAP_COLOR_BIT);
-
- free(indexes);
- }
- else {
- /* non-color index data */
- extract_float_rgba(n, rgba, srcFormat, srcType, source,
- srcPacking->SwapBytes);
- }
-
- if (transferOps) {
- _mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
- }
-
- get_component_indexes(dstFormat,
- &rDst, &gDst, &bDst, &aDst, &lDst, &iDst);
-
- /* Now pack results in the requested dstFormat */
- if (rDst >= 0) {
- GLfloat *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[rDst] = rgba[i][RCOMP];
- dst += dstComponents;
- }
- }
-
- if (gDst >= 0) {
- GLfloat *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[gDst] = rgba[i][GCOMP];
- dst += dstComponents;
- }
- }
-
- if (bDst >= 0) {
- GLfloat *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[bDst] = rgba[i][BCOMP];
- dst += dstComponents;
- }
- }
-
- if (aDst >= 0) {
- GLfloat *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[aDst] = rgba[i][ACOMP];
- dst += dstComponents;
- }
- }
-
- if (iDst >= 0) {
- GLfloat *dst = dest;
- GLuint i;
- assert(iDst == 0);
- assert(dstComponents == 1);
- for (i = 0; i < n; i++) {
- /* Intensity comes from red channel */
- dst[i] = rgba[i][RCOMP];
- }
- }
-
- if (lDst >= 0) {
- GLfloat *dst = dest;
- GLuint i;
- assert(lDst == 0);
- for (i = 0; i < n; i++) {
- /* Luminance comes from red channel */
- dst[0] = rgba[i][RCOMP];
- dst += dstComponents;
- }
- }
-
- free(rgba);
- }
-}
-
-
-/**
- * Same as _mesa_unpack_color_span_chan(), but return GLuint data
- * instead of GLchan.
- * No pixel transfer ops are applied.
- */
-void
-_mesa_unpack_color_span_uint(struct gl_context *ctx,
- GLuint n, GLenum dstFormat, GLuint *dest,
- GLenum srcFormat, GLenum srcType,
- const GLvoid *source,
- const struct gl_pixelstore_attrib *srcPacking)
-{
- GLuint (*rgba)[4] = (GLuint (*)[4]) malloc(n * 4 * sizeof(GLfloat));
-
- if (!rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
- return;
- }
-
- ASSERT(dstFormat == GL_ALPHA ||
- dstFormat == GL_LUMINANCE ||
- dstFormat == GL_LUMINANCE_ALPHA ||
- dstFormat == GL_INTENSITY ||
- dstFormat == GL_RED ||
- dstFormat == GL_RG ||
- dstFormat == GL_RGB ||
- dstFormat == GL_RGBA);
-
- ASSERT(srcFormat == GL_RED ||
- srcFormat == GL_GREEN ||
- srcFormat == GL_BLUE ||
- srcFormat == GL_ALPHA ||
- srcFormat == GL_LUMINANCE ||
- srcFormat == GL_LUMINANCE_ALPHA ||
- srcFormat == GL_INTENSITY ||
- srcFormat == GL_RG ||
- srcFormat == GL_RGB ||
- srcFormat == GL_BGR ||
- srcFormat == GL_RGBA ||
- srcFormat == GL_BGRA ||
- srcFormat == GL_ABGR_EXT ||
- srcFormat == GL_RED_INTEGER_EXT ||
- srcFormat == GL_GREEN_INTEGER_EXT ||
- srcFormat == GL_BLUE_INTEGER_EXT ||
- srcFormat == GL_ALPHA_INTEGER_EXT ||
- srcFormat == GL_RGB_INTEGER_EXT ||
- srcFormat == GL_RGBA_INTEGER_EXT ||
- srcFormat == GL_BGR_INTEGER_EXT ||
- srcFormat == GL_BGRA_INTEGER_EXT ||
- srcFormat == GL_LUMINANCE_INTEGER_EXT ||
- srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT);
-
- ASSERT(srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_BYTE ||
- srcType == GL_UNSIGNED_SHORT ||
- srcType == GL_SHORT ||
- srcType == GL_UNSIGNED_INT ||
- srcType == GL_INT ||
- srcType == GL_HALF_FLOAT_ARB ||
- srcType == GL_FLOAT ||
- srcType == GL_UNSIGNED_BYTE_3_3_2 ||
- srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
- srcType == GL_UNSIGNED_SHORT_5_6_5 ||
- srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
- srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
- srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
- srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
- srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
- srcType == GL_UNSIGNED_INT_8_8_8_8 ||
- srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
- srcType == GL_UNSIGNED_INT_10_10_10_2 ||
- srcType == GL_UNSIGNED_INT_2_10_10_10_REV);
-
-
- /* Extract image data as uint[4] pixels */
- extract_uint_rgba(n, rgba, srcFormat, srcType, source,
- srcPacking->SwapBytes);
-
- if (dstFormat == GL_RGBA) {
- /* simple case */
- memcpy(dest, rgba, 4 * sizeof(GLuint) * n);
- }
- else {
- /* general case */
- GLint rDst, gDst, bDst, aDst, lDst, iDst;
- GLint dstComponents = _mesa_components_in_format( dstFormat );
-
- assert(dstComponents > 0);
-
- get_component_indexes(dstFormat,
- &rDst, &gDst, &bDst, &aDst, &lDst, &iDst);
-
- /* Now pack values in the requested dest format */
- if (rDst >= 0) {
- GLuint *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[rDst] = rgba[i][RCOMP];
- dst += dstComponents;
- }
- }
-
- if (gDst >= 0) {
- GLuint *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[gDst] = rgba[i][GCOMP];
- dst += dstComponents;
- }
- }
-
- if (bDst >= 0) {
- GLuint *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[bDst] = rgba[i][BCOMP];
- dst += dstComponents;
- }
- }
-
- if (aDst >= 0) {
- GLuint *dst = dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[aDst] = rgba[i][ACOMP];
- dst += dstComponents;
- }
- }
-
- if (iDst >= 0) {
- GLuint *dst = dest;
- GLuint i;
- assert(iDst == 0);
- assert(dstComponents == 1);
- for (i = 0; i < n; i++) {
- /* Intensity comes from red channel */
- dst[i] = rgba[i][RCOMP];
- }
- }
-
- if (lDst >= 0) {
- GLuint *dst = dest;
- GLuint i;
- assert(lDst == 0);
- for (i = 0; i < n; i++) {
- /* Luminance comes from red channel */
- dst[0] = rgba[i][RCOMP];
- dst += dstComponents;
- }
- }
- }
-
- free(rgba);
-}
-
-
-
-/**
- * Similar to _mesa_unpack_color_span_float(), but for dudv data instead of rgba,
- * directly return GLbyte data, no transfer ops apply.
- */
-void
-_mesa_unpack_dudv_span_byte( struct gl_context *ctx,
- GLuint n, GLenum dstFormat, GLbyte dest[],
- GLenum srcFormat, GLenum srcType,
- const GLvoid *source,
- const struct gl_pixelstore_attrib *srcPacking,
- GLbitfield transferOps )
-{
- ASSERT(dstFormat == GL_DUDV_ATI);
- ASSERT(srcFormat == GL_DUDV_ATI ||
- srcFormat == GL_DU8DV8_ATI);
-
- ASSERT(srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_BYTE ||
- srcType == GL_UNSIGNED_SHORT ||
- srcType == GL_SHORT ||
- srcType == GL_UNSIGNED_INT ||
- srcType == GL_INT ||
- srcType == GL_HALF_FLOAT_ARB ||
- srcType == GL_FLOAT);
-
- /* general solution */
- {
- GLint dstComponents;
- GLbyte *dst = dest;
- GLuint i;
- GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * n * sizeof(GLfloat));
-
- if (!rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
- return;
- }
-
- dstComponents = _mesa_components_in_format( dstFormat );
- /* source & dest image formats should have been error checked by now */
- assert(dstComponents > 0);
-
- /*
- * Extract image data and convert to RGBA floats
- */
- extract_float_rgba(n, rgba, srcFormat, srcType, source,
- srcPacking->SwapBytes);
-
-
- /* Now determine which color channels we need to produce.
- * And determine the dest index (offset) within each color tuple.
- */
-
- /* Now pack results in the requested dstFormat */
- for (i = 0; i < n; i++) {
- /* not sure - need clamp[-1,1] here? */
- dst[0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
- dst[1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
- dst += dstComponents;
- }
-
- free(rgba);
- }
-}
-
-/*
- * Unpack a row of color index data from a client buffer according to
- * the pixel unpacking parameters.
- * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
- *
- * Args: ctx - the context
- * n - number of pixels
- * dstType - destination data type
- * dest - destination array
- * srcType - source pixel type
- * source - source data pointer
- * srcPacking - pixel unpacking parameters
- * transferOps - the pixel transfer operations to apply
- */
-void
-_mesa_unpack_index_span( struct gl_context *ctx, GLuint n,
- GLenum dstType, GLvoid *dest,
- GLenum srcType, const GLvoid *source,
- const struct gl_pixelstore_attrib *srcPacking,
- GLbitfield transferOps )
-{
- ASSERT(srcType == GL_BITMAP ||
- srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_BYTE ||
- srcType == GL_UNSIGNED_SHORT ||
- srcType == GL_SHORT ||
- srcType == GL_UNSIGNED_INT ||
- srcType == GL_INT ||
- srcType == GL_HALF_FLOAT_ARB ||
- srcType == GL_FLOAT);
-
- ASSERT(dstType == GL_UNSIGNED_BYTE ||
- dstType == GL_UNSIGNED_SHORT ||
- dstType == GL_UNSIGNED_INT);
-
-
- transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT);
-
- /*
- * Try simple cases first
- */
- if (transferOps == 0 && srcType == GL_UNSIGNED_BYTE
- && dstType == GL_UNSIGNED_BYTE) {
- memcpy(dest, source, n * sizeof(GLubyte));
- }
- else if (transferOps == 0 && srcType == GL_UNSIGNED_INT
- && dstType == GL_UNSIGNED_INT && !srcPacking->SwapBytes) {
- memcpy(dest, source, n * sizeof(GLuint));
- }
- else {
- /*
- * general solution
- */
- GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
-
- if (!indexes) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
- return;
- }
-
- extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source,
- srcPacking);
-
- if (transferOps)
- _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
-
- /* convert to dest type */
- switch (dstType) {
- case GL_UNSIGNED_BYTE:
- {
- GLubyte *dst = (GLubyte *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = (GLubyte) (indexes[i] & 0xff);
- }
- }
- break;
- case GL_UNSIGNED_SHORT:
- {
- GLuint *dst = (GLuint *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = (GLushort) (indexes[i] & 0xffff);
- }
- }
- break;
- case GL_UNSIGNED_INT:
- memcpy(dest, indexes, n * sizeof(GLuint));
- break;
- default:
- _mesa_problem(ctx, "bad dstType in _mesa_unpack_index_span");
- }
-
- free(indexes);
- }
-}
-
-
-void
-_mesa_pack_index_span( struct gl_context *ctx, GLuint n,
- GLenum dstType, GLvoid *dest, const GLuint *source,
- const struct gl_pixelstore_attrib *dstPacking,
- GLbitfield transferOps )
-{
- GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
-
- if (!indexes) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
- return;
- }
-
- transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT);
-
- if (transferOps & (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT)) {
- /* make a copy of input */
- memcpy(indexes, source, n * sizeof(GLuint));
- _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
- source = indexes;
- }
-
- switch (dstType) {
- case GL_UNSIGNED_BYTE:
- {
- GLubyte *dst = (GLubyte *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- *dst++ = (GLubyte) source[i];
- }
- }
- break;
- case GL_BYTE:
- {
- GLbyte *dst = (GLbyte *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = (GLbyte) source[i];
- }
- }
- break;
- case GL_UNSIGNED_SHORT:
- {
- GLushort *dst = (GLushort *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = (GLushort) source[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, n );
- }
- }
- break;
- case GL_SHORT:
- {
- GLshort *dst = (GLshort *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = (GLshort) source[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, n );
- }
- }
- break;
- case GL_UNSIGNED_INT:
- {
- GLuint *dst = (GLuint *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = (GLuint) source[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, n );
- }
- }
- break;
- case GL_INT:
- {
- GLint *dst = (GLint *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = (GLint) source[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, n );
- }
- }
- break;
- case GL_FLOAT:
- {
- GLfloat *dst = (GLfloat *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = (GLfloat) source[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, n );
- }
- }
- break;
- case GL_HALF_FLOAT_ARB:
- {
- GLhalfARB *dst = (GLhalfARB *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = _mesa_float_to_half((GLfloat) source[i]);
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, n );
- }
- }
- break;
- default:
- _mesa_problem(ctx, "bad type in _mesa_pack_index_span");
- }
-
- free(indexes);
-}
-
-
-/*
- * Unpack a row of stencil data from a client buffer according to
- * the pixel unpacking parameters.
- * This is (or will be) used by glDrawPixels
- *
- * Args: ctx - the context
- * n - number of pixels
- * dstType - destination data type
- * dest - destination array
- * srcType - source pixel type
- * source - source data pointer
- * srcPacking - pixel unpacking parameters
- * transferOps - apply offset/bias/lookup ops?
- */
-void
-_mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
- GLenum dstType, GLvoid *dest,
- GLenum srcType, const GLvoid *source,
- const struct gl_pixelstore_attrib *srcPacking,
- GLbitfield transferOps )
-{
- ASSERT(srcType == GL_BITMAP ||
- srcType == GL_UNSIGNED_BYTE ||
- srcType == GL_BYTE ||
- srcType == GL_UNSIGNED_SHORT ||
- srcType == GL_SHORT ||
- srcType == GL_UNSIGNED_INT ||
- srcType == GL_INT ||
- srcType == GL_UNSIGNED_INT_24_8_EXT ||
- srcType == GL_HALF_FLOAT_ARB ||
- srcType == GL_FLOAT);
-
- ASSERT(dstType == GL_UNSIGNED_BYTE ||
- dstType == GL_UNSIGNED_SHORT ||
- dstType == GL_UNSIGNED_INT);
-
- /* only shift and offset apply to stencil */
- transferOps &= IMAGE_SHIFT_OFFSET_BIT;
-
- /*
- * Try simple cases first
- */
- if (transferOps == 0 &&
- !ctx->Pixel.MapStencilFlag &&
- srcType == GL_UNSIGNED_BYTE &&
- dstType == GL_UNSIGNED_BYTE) {
- memcpy(dest, source, n * sizeof(GLubyte));
- }
- else if (transferOps == 0 &&
- !ctx->Pixel.MapStencilFlag &&
- srcType == GL_UNSIGNED_INT &&
- dstType == GL_UNSIGNED_INT &&
- !srcPacking->SwapBytes) {
- memcpy(dest, source, n * sizeof(GLuint));
- }
- else {
- /*
- * general solution
- */
- GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
-
- if (!indexes) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "stencil unpacking");
- return;
- }
-
- extract_uint_indexes(n, indexes, GL_STENCIL_INDEX, srcType, source,
- srcPacking);
-
- if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
- /* shift and offset indexes */
- _mesa_shift_and_offset_ci(ctx, n, indexes);
- }
-
- if (ctx->Pixel.MapStencilFlag) {
- /* Apply stencil lookup table */
- const GLuint mask = ctx->PixelMaps.StoS.Size - 1;
- GLuint i;
- for (i = 0; i < n; i++) {
- indexes[i] = (GLuint)ctx->PixelMaps.StoS.Map[ indexes[i] & mask ];
- }
- }
-
- /* convert to dest type */
- switch (dstType) {
- case GL_UNSIGNED_BYTE:
- {
- GLubyte *dst = (GLubyte *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = (GLubyte) (indexes[i] & 0xff);
- }
- }
- break;
- case GL_UNSIGNED_SHORT:
- {
- GLuint *dst = (GLuint *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = (GLushort) (indexes[i] & 0xffff);
- }
- }
- break;
- case GL_UNSIGNED_INT:
- memcpy(dest, indexes, n * sizeof(GLuint));
- break;
- default:
- _mesa_problem(ctx, "bad dstType in _mesa_unpack_stencil_span");
- }
-
- free(indexes);
- }
-}
-
-
-void
-_mesa_pack_stencil_span( struct gl_context *ctx, GLuint n,
- GLenum dstType, GLvoid *dest, const GLstencil *source,
- const struct gl_pixelstore_attrib *dstPacking )
-{
- GLstencil *stencil = (GLstencil *) malloc(n * sizeof(GLstencil));
-
- if (!stencil) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "stencil packing");
- return;
- }
-
- if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset ||
- ctx->Pixel.MapStencilFlag) {
- /* make a copy of input */
- memcpy(stencil, source, n * sizeof(GLstencil));
- _mesa_apply_stencil_transfer_ops(ctx, n, stencil);
- source = stencil;
- }
-
- switch (dstType) {
- case GL_UNSIGNED_BYTE:
- if (sizeof(GLstencil) == 1) {
- memcpy( dest, source, n );
- }
- else {
- GLubyte *dst = (GLubyte *) dest;
- GLuint i;
- for (i=0;i<n;i++) {
- dst[i] = (GLubyte) source[i];
- }
- }
- break;
- case GL_BYTE:
- {
- GLbyte *dst = (GLbyte *) dest;
- GLuint i;
- for (i=0;i<n;i++) {
- dst[i] = (GLbyte) (source[i] & 0x7f);
- }
- }
- break;
- case GL_UNSIGNED_SHORT:
- {
- GLushort *dst = (GLushort *) dest;
- GLuint i;
- for (i=0;i<n;i++) {
- dst[i] = (GLushort) source[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, n );
- }
- }
- break;
- case GL_SHORT:
- {
- GLshort *dst = (GLshort *) dest;
- GLuint i;
- for (i=0;i<n;i++) {
- dst[i] = (GLshort) source[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, n );
- }
- }
- break;
- case GL_UNSIGNED_INT:
- {
- GLuint *dst = (GLuint *) dest;
- GLuint i;
- for (i=0;i<n;i++) {
- dst[i] = (GLuint) source[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, n );
- }
- }
- break;
- case GL_INT:
- {
- GLint *dst = (GLint *) dest;
- GLuint i;
- for (i=0;i<n;i++) {
- dst[i] = (GLint) source[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, n );
- }
- }
- break;
- case GL_FLOAT:
- {
- GLfloat *dst = (GLfloat *) dest;
- GLuint i;
- for (i=0;i<n;i++) {
- dst[i] = (GLfloat) source[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, n );
- }
- }
- break;
- case GL_HALF_FLOAT_ARB:
- {
- GLhalfARB *dst = (GLhalfARB *) dest;
- GLuint i;
- for (i=0;i<n;i++) {
- dst[i] = _mesa_float_to_half( (float) source[i] );
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, n );
- }
- }
- break;
- case GL_BITMAP:
- if (dstPacking->LsbFirst) {
- GLubyte *dst = (GLubyte *) dest;
- GLint shift = 0;
- GLuint i;
- for (i = 0; i < n; i++) {
- if (shift == 0)
- *dst = 0;
- *dst |= ((source[i] != 0) << shift);
- shift++;
- if (shift == 8) {
- shift = 0;
- dst++;
- }
- }
- }
- else {
- GLubyte *dst = (GLubyte *) dest;
- GLint shift = 7;
- GLuint i;
- for (i = 0; i < n; i++) {
- if (shift == 7)
- *dst = 0;
- *dst |= ((source[i] != 0) << shift);
- shift--;
- if (shift < 0) {
- shift = 7;
- dst++;
- }
- }
- }
- break;
- default:
- _mesa_problem(ctx, "bad type in _mesa_pack_index_span");
- }
-
- free(stencil);
-}
-
-#define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
- do { \
- GLuint i; \
- const GLTYPE *src = (const GLTYPE *)source; \
- for (i = 0; i < n; i++) { \
- GLTYPE value = src[i]; \
- if (srcPacking->SwapBytes) { \
- if (sizeof(GLTYPE) == 2) { \
- SWAP2BYTE(value); \
- } else if (sizeof(GLTYPE) == 4) { \
- SWAP4BYTE(value); \
- } \
- } \
- depthValues[i] = GLTYPE2FLOAT(value); \
- } \
- } while (0)
-
-
-/**
- * Unpack a row of depth/z values from memory, returning GLushort, GLuint
- * or GLfloat values.
- * The glPixelTransfer (scale/bias) params will be applied.
- *
- * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
- * \param depthMax max value for returned GLushort or GLuint values
- * (ignored for GLfloat).
- */
-void
-_mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
- GLenum dstType, GLvoid *dest, GLuint depthMax,
- GLenum srcType, const GLvoid *source,
- const struct gl_pixelstore_attrib *srcPacking )
-{
- GLfloat *depthTemp, *depthValues;
- GLboolean needClamp = GL_FALSE;
-
- /* Look for special cases first.
- * Not only are these faster, they're less prone to numeric conversion
- * problems. Otherwise, converting from an int type to a float then
- * back to an int type can introduce errors that will show up as
- * artifacts in things like depth peeling which uses glCopyTexImage.
- */
- if (ctx->Pixel.DepthScale == 1.0 && ctx->Pixel.DepthBias == 0.0) {
- if (srcType == GL_UNSIGNED_INT && dstType == GL_UNSIGNED_SHORT) {
- const GLuint *src = (const GLuint *) source;
- GLushort *dst = (GLushort *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = src[i] >> 16;
- }
- return;
- }
- if (srcType == GL_UNSIGNED_SHORT
- && dstType == GL_UNSIGNED_INT
- && depthMax == 0xffffffff) {
- const GLushort *src = (const GLushort *) source;
- GLuint *dst = (GLuint *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = src[i] | (src[i] << 16);
- }
- return;
- }
- if (srcType == GL_UNSIGNED_INT_24_8
- && dstType == GL_UNSIGNED_INT
- && depthMax == 0xffffff) {
- const GLuint *src = (const GLuint *) source;
- GLuint *dst = (GLuint *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = src[i] >> 8;
- }
- return;
- }
- /* XXX may want to add additional cases here someday */
- }
-
- /* general case path follows */
-
- depthTemp = (GLfloat *) malloc(n * sizeof(GLfloat));
- if (!depthTemp) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
- return;
- }
-
- if (dstType == GL_FLOAT) {
- depthValues = (GLfloat *) dest;
- }
- else {
- depthValues = depthTemp;
- }
-
- /* Convert incoming values to GLfloat. Some conversions will require
- * clamping, below.
- */
- switch (srcType) {
- case GL_BYTE:
- DEPTH_VALUES(GLbyte, BYTE_TO_FLOAT);
- needClamp = GL_TRUE;
- break;
- case GL_UNSIGNED_BYTE:
- DEPTH_VALUES(GLubyte, UBYTE_TO_FLOAT);
- break;
- case GL_SHORT:
- DEPTH_VALUES(GLshort, SHORT_TO_FLOAT);
- needClamp = GL_TRUE;
- break;
- case GL_UNSIGNED_SHORT:
- DEPTH_VALUES(GLushort, USHORT_TO_FLOAT);
- break;
- case GL_INT:
- DEPTH_VALUES(GLint, INT_TO_FLOAT);
- needClamp = GL_TRUE;
- break;
- case GL_UNSIGNED_INT:
- DEPTH_VALUES(GLuint, UINT_TO_FLOAT);
- break;
- case GL_UNSIGNED_INT_24_8_EXT: /* GL_EXT_packed_depth_stencil */
- if (dstType == GL_UNSIGNED_INT_24_8_EXT &&
- depthMax == 0xffffff &&
- ctx->Pixel.DepthScale == 1.0 &&
- ctx->Pixel.DepthBias == 0.0) {
- const GLuint *src = (const GLuint *) source;
- GLuint *zValues = (GLuint *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- GLuint value = src[i];
- if (srcPacking->SwapBytes) {
- SWAP4BYTE(value);
- }
- zValues[i] = value & 0xffffff00;
- }
- return;
- }
- else {
- const GLuint *src = (const GLuint *) source;
- const GLfloat scale = 1.0f / 0xffffff;
- GLuint i;
- for (i = 0; i < n; i++) {
- GLuint value = src[i];
- if (srcPacking->SwapBytes) {
- SWAP4BYTE(value);
- }
- depthValues[i] = (value >> 8) * scale;
- }
- }
- break;
- case GL_FLOAT:
- DEPTH_VALUES(GLfloat, 1*);
- needClamp = GL_TRUE;
- break;
- case GL_HALF_FLOAT_ARB:
- {
- GLuint i;
- const GLhalfARB *src = (const GLhalfARB *) source;
- for (i = 0; i < n; i++) {
- GLhalfARB value = src[i];
- if (srcPacking->SwapBytes) {
- SWAP2BYTE(value);
- }
- depthValues[i] = _mesa_half_to_float(value);
- }
- needClamp = GL_TRUE;
- }
- break;
- default:
- _mesa_problem(NULL, "bad type in _mesa_unpack_depth_span()");
- free(depthTemp);
- return;
- }
-
- /* apply depth scale and bias */
- {
- const GLfloat scale = ctx->Pixel.DepthScale;
- const GLfloat bias = ctx->Pixel.DepthBias;
- if (scale != 1.0 || bias != 0.0) {
- GLuint i;
- for (i = 0; i < n; i++) {
- depthValues[i] = depthValues[i] * scale + bias;
- }
- needClamp = GL_TRUE;
- }
- }
-
- /* clamp to [0, 1] */
- if (needClamp) {
- GLuint i;
- for (i = 0; i < n; i++) {
- depthValues[i] = (GLfloat)CLAMP(depthValues[i], 0.0, 1.0);
- }
- }
-
- /*
- * Convert values to dstType
- */
- if (dstType == GL_UNSIGNED_INT) {
- GLuint *zValues = (GLuint *) dest;
- GLuint i;
- if (depthMax <= 0xffffff) {
- /* no overflow worries */
- for (i = 0; i < n; i++) {
- zValues[i] = (GLuint) (depthValues[i] * (GLfloat) depthMax);
- }
- }
- else {
- /* need to use double precision to prevent overflow problems */
- for (i = 0; i < n; i++) {
- GLdouble z = depthValues[i] * (GLfloat) depthMax;
- if (z >= (GLdouble) 0xffffffff)
- zValues[i] = 0xffffffff;
- else
- zValues[i] = (GLuint) z;
- }
- }
- }
- else if (dstType == GL_UNSIGNED_SHORT) {
- GLushort *zValues = (GLushort *) dest;
- GLuint i;
- ASSERT(depthMax <= 0xffff);
- for (i = 0; i < n; i++) {
- zValues[i] = (GLushort) (depthValues[i] * (GLfloat) depthMax);
- }
- }
- else {
- ASSERT(dstType == GL_FLOAT);
- /*ASSERT(depthMax == 1.0F);*/
- }
-
- free(depthTemp);
-}
-
-
-/*
- * Pack an array of depth values. The values are floats in [0,1].
- */
-void
-_mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
- GLenum dstType, const GLfloat *depthSpan,
- const struct gl_pixelstore_attrib *dstPacking )
-{
- GLfloat *depthCopy = (GLfloat *) malloc(n * sizeof(GLfloat));
- if (!depthCopy) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
- return;
- }
-
- if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
- memcpy(depthCopy, depthSpan, n * sizeof(GLfloat));
- _mesa_scale_and_bias_depth(ctx, n, depthCopy);
- depthSpan = depthCopy;
- }
-
- switch (dstType) {
- case GL_UNSIGNED_BYTE:
- {
- GLubyte *dst = (GLubyte *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = FLOAT_TO_UBYTE( depthSpan[i] );
- }
- }
- break;
- case GL_BYTE:
- {
- GLbyte *dst = (GLbyte *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = FLOAT_TO_BYTE( depthSpan[i] );
- }
- }
- break;
- case GL_UNSIGNED_SHORT:
- {
- GLushort *dst = (GLushort *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- CLAMPED_FLOAT_TO_USHORT(dst[i], depthSpan[i]);
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, n );
- }
- }
- break;
- case GL_SHORT:
- {
- GLshort *dst = (GLshort *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = FLOAT_TO_SHORT( depthSpan[i] );
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, n );
- }
- }
- break;
- case GL_UNSIGNED_INT:
- {
- GLuint *dst = (GLuint *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = FLOAT_TO_UINT( depthSpan[i] );
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, n );
- }
- }
- break;
- case GL_INT:
- {
- GLint *dst = (GLint *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = FLOAT_TO_INT( depthSpan[i] );
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, n );
- }
- }
- break;
- case GL_FLOAT:
- {
- GLfloat *dst = (GLfloat *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = depthSpan[i];
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap4( (GLuint *) dst, n );
- }
- }
- break;
- case GL_HALF_FLOAT_ARB:
- {
- GLhalfARB *dst = (GLhalfARB *) dest;
- GLuint i;
- for (i = 0; i < n; i++) {
- dst[i] = _mesa_float_to_half(depthSpan[i]);
- }
- if (dstPacking->SwapBytes) {
- _mesa_swap2( (GLushort *) dst, n );
- }
- }
- break;
- default:
- _mesa_problem(ctx, "bad type in _mesa_pack_depth_span");
- }
-
- free(depthCopy);
-}
-
-
-
-/**
- * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
- */
-void
-_mesa_pack_depth_stencil_span(struct gl_context *ctx, GLuint n, GLuint *dest,
- const GLfloat *depthVals,
- const GLstencil *stencilVals,
- const struct gl_pixelstore_attrib *dstPacking)
-{
- GLfloat *depthCopy = (GLfloat *) malloc(n * sizeof(GLfloat));
- GLstencil *stencilCopy = (GLstencil *) malloc(n * sizeof(GLstencil));
- GLuint i;
-
- if (!depthCopy || !stencilCopy) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
- free(depthCopy);
- free(stencilCopy);
- return;
- }
-
- if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
- memcpy(depthCopy, depthVals, n * sizeof(GLfloat));
- _mesa_scale_and_bias_depth(ctx, n, depthCopy);
- depthVals = depthCopy;
- }
-
- if (ctx->Pixel.IndexShift ||
- ctx->Pixel.IndexOffset ||
- ctx->Pixel.MapStencilFlag) {
- memcpy(stencilCopy, stencilVals, n * sizeof(GLstencil));
- _mesa_apply_stencil_transfer_ops(ctx, n, stencilCopy);
- stencilVals = stencilCopy;
- }
-
- for (i = 0; i < n; i++) {
- GLuint z = (GLuint) (depthVals[i] * 0xffffff);
- dest[i] = (z << 8) | (stencilVals[i] & 0xff);
- }
-
- if (dstPacking->SwapBytes) {
- _mesa_swap4(dest, n);
- }
-
- free(depthCopy);
- free(stencilCopy);
-}
-
-
-
-
-/**
- * Unpack image data. Apply byte swapping, byte flipping (bitmap).
- * Return all image data in a contiguous block. This is used when we
- * compile glDrawPixels, glTexImage, etc into a display list. We
- * need a copy of the data in a standard format.
- */
-void *
-_mesa_unpack_image( GLuint dimensions,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLenum type, const GLvoid *pixels,
- const struct gl_pixelstore_attrib *unpack )
-{
- GLint bytesPerRow, compsPerRow;
- GLboolean flipBytes, swap2, swap4;
-
- if (!pixels)
- return NULL; /* not necessarily an error */
-
- if (width <= 0 || height <= 0 || depth <= 0)
- return NULL; /* generate error later */
-
- if (type == GL_BITMAP) {
- bytesPerRow = (width + 7) >> 3;
- flipBytes = unpack->LsbFirst;
- swap2 = swap4 = GL_FALSE;
- compsPerRow = 0;
- }
- else {
- const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
- GLint components = _mesa_components_in_format(format);
- GLint bytesPerComp;
-
- if (_mesa_type_is_packed(type))
- components = 1;
-
- if (bytesPerPixel <= 0 || components <= 0)
- return NULL; /* bad format or type. generate error later */
- bytesPerRow = bytesPerPixel * width;
- bytesPerComp = bytesPerPixel / components;
- flipBytes = GL_FALSE;
- swap2 = (bytesPerComp == 2) && unpack->SwapBytes;
- swap4 = (bytesPerComp == 4) && unpack->SwapBytes;
- compsPerRow = components * width;
- assert(compsPerRow >= width);
- }
-
- {
- GLubyte *destBuffer
- = (GLubyte *) malloc(bytesPerRow * height * depth);
- GLubyte *dst;
- GLint img, row;
- if (!destBuffer)
- return NULL; /* generate GL_OUT_OF_MEMORY later */
-
- dst = destBuffer;
- for (img = 0; img < depth; img++) {
- for (row = 0; row < height; row++) {
- const GLvoid *src = _mesa_image_address(dimensions, unpack, pixels,
- width, height, format, type, img, row, 0);
-
- if ((type == GL_BITMAP) && (unpack->SkipPixels & 0x7)) {
- GLint i;
- flipBytes = GL_FALSE;
- if (unpack->LsbFirst) {
- GLubyte srcMask = 1 << (unpack->SkipPixels & 0x7);
- GLubyte dstMask = 128;
- const GLubyte *s = src;
- GLubyte *d = dst;
- *d = 0;
- for (i = 0; i < width; i++) {
- if (*s & srcMask) {
- *d |= dstMask;
- }
- if (srcMask == 128) {
- srcMask = 1;
- s++;
- }
- else {
- srcMask = srcMask << 1;
- }
- if (dstMask == 1) {
- dstMask = 128;
- d++;
- *d = 0;
- }
- else {
- dstMask = dstMask >> 1;
- }
- }
- }
- else {
- GLubyte srcMask = 128 >> (unpack->SkipPixels & 0x7);
- GLubyte dstMask = 128;
- const GLubyte *s = src;
- GLubyte *d = dst;
- *d = 0;
- for (i = 0; i < width; i++) {
- if (*s & srcMask) {
- *d |= dstMask;
- }
- if (srcMask == 1) {
- srcMask = 128;
- s++;
- }
- else {
- srcMask = srcMask >> 1;
- }
- if (dstMask == 1) {
- dstMask = 128;
- d++;
- *d = 0;
- }
- else {
- dstMask = dstMask >> 1;
- }
- }
- }
- }
- else {
- memcpy(dst, src, bytesPerRow);
- }
-
- /* byte flipping/swapping */
- if (flipBytes) {
- flip_bytes((GLubyte *) dst, bytesPerRow);
- }
- else if (swap2) {
- _mesa_swap2((GLushort*) dst, compsPerRow);
- }
- else if (swap4) {
- _mesa_swap4((GLuint*) dst, compsPerRow);
- }
- dst += bytesPerRow;
- }
- }
- return destBuffer;
- }
-}
-
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 1999-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
+ * THEA AUTHORS 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 pack.c
+ * Image and pixel span packing and unpacking.
+ */
+
+
+#include "glheader.h"
+#include "colormac.h"
+#include "enums.h"
+#include "image.h"
+#include "imports.h"
+#include "mtypes.h"
+#include "pack.h"
+#include "pixeltransfer.h"
+#include "imports.h"
+#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
+#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
+
+
+/**
+ * NOTE:
+ * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
+ * we later convert the float to a packed integer value (such as for
+ * GL_RGB5_A1) because we'll wind up with a non-zero value.
+ *
+ * We redefine the macros here so zero is handled correctly.
+ */
+#undef BYTE_TO_FLOAT
+#define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
+
+#undef SHORT_TO_FLOAT
+#define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
+
+
+
+/** Compute ceiling of integer quotient of A divided by B. */
+#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
+
+
+/**
+ * Flip the 8 bits in each byte of the given array.
+ *
+ * \param p array.
+ * \param n number of bytes.
+ *
+ * \todo try this trick to flip bytes someday:
+ * \code
+ * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
+ * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
+ * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
+ * \endcode
+ */
+static void
+flip_bytes( GLubyte *p, GLuint n )
+{
+ GLuint i, a, b;
+ for (i = 0; i < n; i++) {
+ b = (GLuint) p[i]; /* words are often faster than bytes */
+ a = ((b & 0x01) << 7) |
+ ((b & 0x02) << 5) |
+ ((b & 0x04) << 3) |
+ ((b & 0x08) << 1) |
+ ((b & 0x10) >> 1) |
+ ((b & 0x20) >> 3) |
+ ((b & 0x40) >> 5) |
+ ((b & 0x80) >> 7);
+ p[i] = (GLubyte) a;
+ }
+}
+
+
+
+/*
+ * Unpack a 32x32 pixel polygon stipple from user memory using the
+ * current pixel unpack settings.
+ */
+void
+_mesa_unpack_polygon_stipple( const GLubyte *pattern, GLuint dest[32],
+ const struct gl_pixelstore_attrib *unpacking )
+{
+ GLubyte *ptrn = (GLubyte *) _mesa_unpack_bitmap(32, 32, pattern, unpacking);
+ if (ptrn) {
+ /* Convert pattern from GLubytes to GLuints and handle big/little
+ * endian differences
+ */
+ GLubyte *p = ptrn;
+ GLint i;
+ for (i = 0; i < 32; i++) {
+ dest[i] = (p[0] << 24)
+ | (p[1] << 16)
+ | (p[2] << 8)
+ | (p[3] );
+ p += 4;
+ }
+ free(ptrn);
+ }
+}
+
+
+/*
+ * Pack polygon stipple into user memory given current pixel packing
+ * settings.
+ */
+void
+_mesa_pack_polygon_stipple( const GLuint pattern[32], GLubyte *dest,
+ const struct gl_pixelstore_attrib *packing )
+{
+ /* Convert pattern from GLuints to GLubytes to handle big/little
+ * endian differences.
+ */
+ GLubyte ptrn[32*4];
+ GLint i;
+ for (i = 0; i < 32; i++) {
+ ptrn[i * 4 + 0] = (GLubyte) ((pattern[i] >> 24) & 0xff);
+ ptrn[i * 4 + 1] = (GLubyte) ((pattern[i] >> 16) & 0xff);
+ ptrn[i * 4 + 2] = (GLubyte) ((pattern[i] >> 8 ) & 0xff);
+ ptrn[i * 4 + 3] = (GLubyte) ((pattern[i] ) & 0xff);
+ }
+
+ _mesa_pack_bitmap(32, 32, ptrn, dest, packing);
+}
+
+
+/*
+ * Unpack bitmap data. Resulting data will be in most-significant-bit-first
+ * order with row alignment = 1 byte.
+ */
+GLvoid *
+_mesa_unpack_bitmap( GLint width, GLint height, const GLubyte *pixels,
+ const struct gl_pixelstore_attrib *packing )
+{
+ GLint bytes, row, width_in_bytes;
+ GLubyte *buffer, *dst;
+
+ if (!pixels)
+ return NULL;
+
+ /* Alloc dest storage */
+ bytes = ((width + 7) / 8 * height);
+ buffer = (GLubyte *) malloc( bytes );
+ if (!buffer)
+ return NULL;
+
+ width_in_bytes = CEILING( width, 8 );
+ dst = buffer;
+ for (row = 0; row < height; row++) {
+ const GLubyte *src = (const GLubyte *)
+ _mesa_image_address2d(packing, pixels, width, height,
+ GL_COLOR_INDEX, GL_BITMAP, row, 0);
+ if (!src) {
+ free(buffer);
+ return NULL;
+ }
+
+ if ((packing->SkipPixels & 7) == 0) {
+ memcpy( dst, src, width_in_bytes );
+ if (packing->LsbFirst) {
+ flip_bytes( dst, width_in_bytes );
+ }
+ }
+ else {
+ /* handling SkipPixels is a bit tricky (no pun intended!) */
+ GLint i;
+ if (packing->LsbFirst) {
+ GLubyte srcMask = 1 << (packing->SkipPixels & 0x7);
+ GLubyte dstMask = 128;
+ const GLubyte *s = src;
+ GLubyte *d = dst;
+ *d = 0;
+ for (i = 0; i < width; i++) {
+ if (*s & srcMask) {
+ *d |= dstMask;
+ }
+ if (srcMask == 128) {
+ srcMask = 1;
+ s++;
+ }
+ else {
+ srcMask = srcMask << 1;
+ }
+ if (dstMask == 1) {
+ dstMask = 128;
+ d++;
+ *d = 0;
+ }
+ else {
+ dstMask = dstMask >> 1;
+ }
+ }
+ }
+ else {
+ GLubyte srcMask = 128 >> (packing->SkipPixels & 0x7);
+ GLubyte dstMask = 128;
+ const GLubyte *s = src;
+ GLubyte *d = dst;
+ *d = 0;
+ for (i = 0; i < width; i++) {
+ if (*s & srcMask) {
+ *d |= dstMask;
+ }
+ if (srcMask == 1) {
+ srcMask = 128;
+ s++;
+ }
+ else {
+ srcMask = srcMask >> 1;
+ }
+ if (dstMask == 1) {
+ dstMask = 128;
+ d++;
+ *d = 0;
+ }
+ else {
+ dstMask = dstMask >> 1;
+ }
+ }
+ }
+ }
+ dst += width_in_bytes;
+ }
+
+ return buffer;
+}
+
+
+/*
+ * Pack bitmap data.
+ */
+void
+_mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source,
+ GLubyte *dest, const struct gl_pixelstore_attrib *packing )
+{
+ GLint row, width_in_bytes;
+ const GLubyte *src;
+
+ if (!source)
+ return;
+
+ width_in_bytes = CEILING( width, 8 );
+ src = source;
+ for (row = 0; row < height; row++) {
+ GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, dest,
+ width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
+ if (!dst)
+ return;
+
+ if ((packing->SkipPixels & 7) == 0) {
+ memcpy( dst, src, width_in_bytes );
+ if (packing->LsbFirst) {
+ flip_bytes( dst, width_in_bytes );
+ }
+ }
+ else {
+ /* handling SkipPixels is a bit tricky (no pun intended!) */
+ GLint i;
+ if (packing->LsbFirst) {
+ GLubyte srcMask = 128;
+ GLubyte dstMask = 1 << (packing->SkipPixels & 0x7);
+ const GLubyte *s = src;
+ GLubyte *d = dst;
+ *d = 0;
+ for (i = 0; i < width; i++) {
+ if (*s & srcMask) {
+ *d |= dstMask;
+ }
+ if (srcMask == 1) {
+ srcMask = 128;
+ s++;
+ }
+ else {
+ srcMask = srcMask >> 1;
+ }
+ if (dstMask == 128) {
+ dstMask = 1;
+ d++;
+ *d = 0;
+ }
+ else {
+ dstMask = dstMask << 1;
+ }
+ }
+ }
+ else {
+ GLubyte srcMask = 128;
+ GLubyte dstMask = 128 >> (packing->SkipPixels & 0x7);
+ const GLubyte *s = src;
+ GLubyte *d = dst;
+ *d = 0;
+ for (i = 0; i < width; i++) {
+ if (*s & srcMask) {
+ *d |= dstMask;
+ }
+ if (srcMask == 1) {
+ srcMask = 128;
+ s++;
+ }
+ else {
+ srcMask = srcMask >> 1;
+ }
+ if (dstMask == 1) {
+ dstMask = 128;
+ d++;
+ *d = 0;
+ }
+ else {
+ dstMask = dstMask >> 1;
+ }
+ }
+ }
+ }
+ src += width_in_bytes;
+ }
+}
+
+
+/**
+ * Get indexes of color components for a basic color format, such as
+ * GL_RGBA, GL_RED, GL_LUMINANCE_ALPHA, etc. Return -1 for indexes
+ * that do not apply.
+ */
+static void
+get_component_indexes(GLenum format,
+ GLint *redIndex,
+ GLint *greenIndex,
+ GLint *blueIndex,
+ GLint *alphaIndex,
+ GLint *luminanceIndex,
+ GLint *intensityIndex)
+{
+ *redIndex = -1;
+ *greenIndex = -1;
+ *blueIndex = -1;
+ *alphaIndex = -1;
+ *luminanceIndex = -1;
+ *intensityIndex = -1;
+
+ switch (format) {
+ case GL_LUMINANCE:
+ case GL_LUMINANCE_INTEGER_EXT:
+ *luminanceIndex = 0;
+ break;
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ *luminanceIndex = 0;
+ *alphaIndex = 1;
+ break;
+ case GL_INTENSITY:
+ *intensityIndex = 0;
+ break;
+ case GL_RED:
+ case GL_RED_INTEGER_EXT:
+ *redIndex = 0;
+ break;
+ case GL_GREEN:
+ case GL_GREEN_INTEGER_EXT:
+ *greenIndex = 0;
+ break;
+ case GL_BLUE:
+ case GL_BLUE_INTEGER_EXT:
+ *blueIndex = 0;
+ break;
+ case GL_ALPHA:
+ case GL_ALPHA_INTEGER_EXT:
+ *alphaIndex = 0;
+ break;
+ case GL_RG:
+ case GL_RG_INTEGER:
+ *redIndex = 0;
+ *greenIndex = 1;
+ break;
+ case GL_RGB:
+ case GL_RGB_INTEGER_EXT:
+ *redIndex = 0;
+ *greenIndex = 1;
+ *blueIndex = 2;
+ break;
+ case GL_BGR:
+ case GL_BGR_INTEGER_EXT:
+ *blueIndex = 0;
+ *greenIndex = 1;
+ *redIndex = 2;
+ break;
+ case GL_RGBA:
+ case GL_RGBA_INTEGER_EXT:
+ *redIndex = 0;
+ *greenIndex = 1;
+ *blueIndex = 2;
+ *alphaIndex = 3;
+ break;
+ case GL_BGRA:
+ case GL_BGRA_INTEGER:
+ *redIndex = 2;
+ *greenIndex = 1;
+ *blueIndex = 0;
+ *alphaIndex = 3;
+ break;
+ case GL_ABGR_EXT:
+ *redIndex = 3;
+ *greenIndex = 2;
+ *blueIndex = 1;
+ *alphaIndex = 0;
+ break;
+ case GL_DU8DV8_ATI:
+ case GL_DUDV_ATI:
+ *redIndex = 0;
+ *greenIndex = 1;
+ break;
+ default:
+ assert(0 && "bad format in get_component_indexes()");
+ }
+}
+
+
+
+/**
+ * For small integer types, return the min and max possible values.
+ * Used for clamping floats to unscaled integer types.
+ * \return GL_TRUE if type is handled, GL_FALSE otherwise.
+ */
+static GLboolean
+get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
+{
+ switch (type) {
+ case GL_BYTE:
+ *min = -128.0;
+ *max = 127.0;
+ return GL_TRUE;
+ case GL_UNSIGNED_BYTE:
+ *min = 0.0;
+ *max = 255.0;
+ return GL_TRUE;
+ case GL_SHORT:
+ *min = -32768.0;
+ *max = 32767.0;
+ return GL_TRUE;
+ case GL_UNSIGNED_SHORT:
+ *min = 0.0;
+ *max = 65535.0;
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
+
+/**
+ * Used to pack an array [][4] of RGBA float colors as specified
+ * by the dstFormat, dstType and dstPacking. Used by glReadPixels.
+ * Historically, the RGBA values were in [0,1] and rescaled to fit
+ * into GLubytes, etc. But with new integer formats, the RGBA values
+ * may have any value and we don't always rescale when converting to
+ * integers.
+ *
+ * Note: the rgba values will be modified by this function when any pixel
+ * transfer ops are enabled.
+ */
+void
+_mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
+ GLenum dstFormat, GLenum dstType,
+ GLvoid *dstAddr,
+ const struct gl_pixelstore_attrib *dstPacking,
+ GLbitfield transferOps)
+{
+ GLfloat *luminance;
+ const GLint comps = _mesa_components_in_format(dstFormat);
+ const GLboolean intDstFormat = _mesa_is_integer_format(dstFormat);
+ GLuint i;
+
+ if (dstFormat == GL_LUMINANCE ||
+ dstFormat == GL_LUMINANCE_ALPHA ||
+ dstFormat == GL_LUMINANCE_INTEGER_EXT ||
+ dstFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT) {
+ luminance = (GLfloat *) malloc(n * sizeof(GLfloat));
+ if (!luminance) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
+ return;
+ }
+ }
+ else {
+ luminance = NULL;
+ }
+
+ if (transferOps) {
+ _mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
+ }
+
+ /*
+ * Component clamping (besides clamping to [0,1] in
+ * _mesa_apply_rgba_transfer_ops()).
+ */
+ if (intDstFormat) {
+ /* clamping to dest type's min/max values */
+ GLfloat min, max;
+ if (get_type_min_max(dstType, &min, &max)) {
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = CLAMP(rgba[i][RCOMP], min, max);
+ rgba[i][GCOMP] = CLAMP(rgba[i][GCOMP], min, max);
+ rgba[i][BCOMP] = CLAMP(rgba[i][BCOMP], min, max);
+ rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], min, max);
+ }
+ }
+ }
+ else if (dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA) {
+ /* compute luminance values */
+ if (transferOps & IMAGE_CLAMP_BIT) {
+ for (i = 0; i < n; i++) {
+ GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+ luminance[i] = CLAMP(sum, 0.0F, 1.0F);
+ }
+ }
+ else {
+ for (i = 0; i < n; i++) {
+ luminance[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+ }
+ }
+ }
+
+ /*
+ * Pack/store the pixels. Ugh! Lots of cases!!!
+ */
+ switch (dstType) {
+ case GL_UNSIGNED_BYTE:
+ {
+ GLubyte *dst = (GLubyte *) dstAddr;
+ switch (dstFormat) {
+ case GL_RED:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
+ break;
+ case GL_GREEN:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
+ break;
+ case GL_BLUE:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
+ break;
+ case GL_ALPHA:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
+ break;
+ case GL_LUMINANCE:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_UBYTE(luminance[i]);
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_UBYTE(luminance[i]);
+ dst[i*2+1] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_RG:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
+ }
+ break;
+ case GL_RGB:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
+ dst[i*3+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
+ }
+ break;
+ case GL_RGBA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
+ dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
+ dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_BGR:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
+ dst[i*3+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_BGRA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
+ dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
+ dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_ABGR_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
+ dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
+ dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
+ dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_RED_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLubyte) rgba[i][RCOMP];
+ }
+ break;
+ case GL_GREEN_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLubyte) rgba[i][GCOMP];
+ }
+ break;
+ case GL_BLUE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLubyte) rgba[i][BCOMP];
+ }
+ break;
+ case GL_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLubyte) rgba[i][ACOMP];
+ }
+ break;
+ case GL_RGB_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLubyte) rgba[i][RCOMP];
+ dst[i*3+1] = (GLubyte) rgba[i][GCOMP];
+ dst[i*3+2] = (GLubyte) rgba[i][BCOMP];
+ }
+ break;
+ case GL_RGBA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLubyte) rgba[i][RCOMP];
+ dst[i*4+1] = (GLubyte) rgba[i][GCOMP];
+ dst[i*4+2] = (GLubyte) rgba[i][BCOMP];
+ dst[i*4+3] = (GLubyte) rgba[i][ACOMP];
+ }
+ break;
+ case GL_BGR_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLubyte) rgba[i][BCOMP];
+ dst[i*3+1] = (GLubyte) rgba[i][GCOMP];
+ dst[i*3+2] = (GLubyte) rgba[i][RCOMP];
+ }
+ break;
+ case GL_BGRA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLubyte) rgba[i][BCOMP];
+ dst[i*4+1] = (GLubyte) rgba[i][GCOMP];
+ dst[i*4+2] = (GLubyte) rgba[i][RCOMP];
+ dst[i*4+3] = (GLubyte) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = (GLubyte) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ dst[i*2+1] = (GLubyte) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLubyte) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ }
+ break;
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
+ }
+ }
+ break;
+ case GL_BYTE:
+ {
+ GLbyte *dst = (GLbyte *) dstAddr;
+ switch (dstFormat) {
+ case GL_RED:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
+ break;
+ case GL_GREEN:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
+ break;
+ case GL_BLUE:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
+ break;
+ case GL_ALPHA:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
+ break;
+ case GL_LUMINANCE:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_BYTE(luminance[i]);
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_BYTE(luminance[i]);
+ dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_RG:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
+ }
+ break;
+ case GL_RGB:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
+ dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
+ }
+ break;
+ case GL_RGBA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
+ dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
+ dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_BGR:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
+ dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_BGRA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
+ dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
+ dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_ABGR_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
+ dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
+ dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
+ dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_RED_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLbyte) rgba[i][RCOMP];
+ }
+ break;
+ case GL_GREEN_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLbyte) rgba[i][GCOMP];
+ }
+ break;
+ case GL_BLUE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLbyte) rgba[i][BCOMP];
+ }
+ break;
+ case GL_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLbyte) rgba[i][ACOMP];
+ }
+ break;
+ case GL_RGB_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLbyte) rgba[i][RCOMP];
+ dst[i*3+1] = (GLbyte) rgba[i][GCOMP];
+ dst[i*3+2] = (GLbyte) rgba[i][BCOMP];
+ }
+ break;
+ case GL_RGBA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLbyte) rgba[i][RCOMP];
+ dst[i*4+1] = (GLbyte) rgba[i][GCOMP];
+ dst[i*4+2] = (GLbyte) rgba[i][BCOMP];
+ dst[i*4+3] = (GLbyte) rgba[i][ACOMP];
+ }
+ break;
+ case GL_BGR_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLbyte) rgba[i][BCOMP];
+ dst[i*3+1] = (GLbyte) rgba[i][GCOMP];
+ dst[i*3+2] = (GLbyte) rgba[i][RCOMP];
+ }
+ break;
+ case GL_BGRA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLbyte) rgba[i][BCOMP];
+ dst[i*4+1] = (GLbyte) rgba[i][GCOMP];
+ dst[i*4+2] = (GLbyte) rgba[i][RCOMP];
+ dst[i*4+3] = (GLbyte) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = (GLbyte) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ dst[i*2+1] = (GLbyte) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLbyte) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ }
+ break;
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT:
+ {
+ GLushort *dst = (GLushort *) dstAddr;
+ switch (dstFormat) {
+ case GL_RED:
+ for (i=0;i<n;i++)
+ CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][RCOMP]);
+ break;
+ case GL_GREEN:
+ for (i=0;i<n;i++)
+ CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][GCOMP]);
+ break;
+ case GL_BLUE:
+ for (i=0;i<n;i++)
+ CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][BCOMP]);
+ break;
+ case GL_ALPHA:
+ for (i=0;i<n;i++)
+ CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][ACOMP]);
+ break;
+ case GL_LUMINANCE:
+ for (i=0;i<n;i++)
+ UNCLAMPED_FLOAT_TO_USHORT(dst[i], luminance[i]);
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i=0;i<n;i++) {
+ UNCLAMPED_FLOAT_TO_USHORT(dst[i*2+0], luminance[i]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*2+1], rgba[i][ACOMP]);
+ }
+ break;
+ case GL_RG:
+ for (i=0;i<n;i++) {
+ CLAMPED_FLOAT_TO_USHORT(dst[i*2+0], rgba[i][RCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*2+1], rgba[i][GCOMP]);
+ }
+ break;
+ case GL_RGB:
+ for (i=0;i<n;i++) {
+ CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][RCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][BCOMP]);
+ }
+ break;
+ case GL_RGBA:
+ for (i=0;i<n;i++) {
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][RCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][BCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]);
+ }
+ break;
+ case GL_BGR:
+ for (i=0;i<n;i++) {
+ CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][BCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][RCOMP]);
+ }
+ break;
+ case GL_BGRA:
+ for (i=0;i<n;i++) {
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][BCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][RCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]);
+ }
+ break;
+ case GL_ABGR_EXT:
+ for (i=0;i<n;i++) {
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][ACOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][BCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][GCOMP]);
+ CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][RCOMP]);
+ }
+ break;
+ case GL_RED_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLushort) rgba[i][RCOMP];
+ }
+ break;
+ case GL_GREEN_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLushort) rgba[i][GCOMP];
+ }
+ break;
+ case GL_BLUE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLushort) rgba[i][BCOMP];
+ }
+ break;
+ case GL_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLushort) rgba[i][ACOMP];
+ }
+ break;
+ case GL_RGB_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLushort) rgba[i][RCOMP];
+ dst[i*3+1] = (GLushort) rgba[i][GCOMP];
+ dst[i*3+2] = (GLushort) rgba[i][BCOMP];
+ }
+ break;
+ case GL_RGBA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLushort) rgba[i][RCOMP];
+ dst[i*4+1] = (GLushort) rgba[i][GCOMP];
+ dst[i*4+2] = (GLushort) rgba[i][BCOMP];
+ dst[i*4+3] = (GLushort) rgba[i][ACOMP];
+ }
+ break;
+ case GL_BGR_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLushort) rgba[i][BCOMP];
+ dst[i*3+1] = (GLushort) rgba[i][GCOMP];
+ dst[i*3+2] = (GLushort) rgba[i][RCOMP];
+ }
+ break;
+ case GL_BGRA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLushort) rgba[i][BCOMP];
+ dst[i*4+1] = (GLushort) rgba[i][GCOMP];
+ dst[i*4+2] = (GLushort) rgba[i][RCOMP];
+ dst[i*4+3] = (GLushort) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = (GLushort) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ dst[i*2+1] = (GLushort) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLushort) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ }
+ break;
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_USHORT(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_USHORT(rgba[i][GCOMP]);
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
+ }
+ }
+ break;
+ case GL_SHORT:
+ {
+ GLshort *dst = (GLshort *) dstAddr;
+ switch (dstFormat) {
+ case GL_RED:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
+ break;
+ case GL_GREEN:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
+ break;
+ case GL_BLUE:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
+ break;
+ case GL_ALPHA:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
+ break;
+ case GL_LUMINANCE:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_SHORT(luminance[i]);
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_SHORT(luminance[i]);
+ dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_RG:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
+ }
+ break;
+ case GL_RGB:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
+ dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
+ }
+ break;
+ case GL_RGBA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
+ dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
+ dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_BGR:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
+ dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_BGRA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
+ dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
+ dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_ABGR_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
+ dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
+ dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
+ dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_RED_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLshort) rgba[i][RCOMP];
+ }
+ break;
+ case GL_GREEN_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLshort) rgba[i][GCOMP];
+ }
+ break;
+ case GL_BLUE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLshort) rgba[i][BCOMP];
+ }
+ break;
+ case GL_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLshort) rgba[i][ACOMP];
+ }
+ break;
+ case GL_RGB_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLshort) rgba[i][RCOMP];
+ dst[i*3+1] = (GLshort) rgba[i][GCOMP];
+ dst[i*3+2] = (GLshort) rgba[i][BCOMP];
+ }
+ break;
+ case GL_RGBA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLshort) rgba[i][RCOMP];
+ dst[i*4+1] = (GLshort) rgba[i][GCOMP];
+ dst[i*4+2] = (GLshort) rgba[i][BCOMP];
+ dst[i*4+3] = (GLshort) rgba[i][ACOMP];
+ }
+ break;
+ case GL_BGR_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLshort) rgba[i][BCOMP];
+ dst[i*3+1] = (GLshort) rgba[i][GCOMP];
+ dst[i*3+2] = (GLshort) rgba[i][RCOMP];
+ }
+ break;
+ case GL_BGRA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLshort) rgba[i][BCOMP];
+ dst[i*4+1] = (GLshort) rgba[i][GCOMP];
+ dst[i*4+2] = (GLshort) rgba[i][RCOMP];
+ dst[i*4+3] = (GLshort) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = (GLshort) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ dst[i*2+1] = (GLshort) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLshort) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ }
+ break;
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT:
+ {
+ GLuint *dst = (GLuint *) dstAddr;
+ switch (dstFormat) {
+ case GL_RED:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_UINT(rgba[i][RCOMP]);
+ break;
+ case GL_GREEN:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_UINT(rgba[i][GCOMP]);
+ break;
+ case GL_BLUE:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_UINT(rgba[i][BCOMP]);
+ break;
+ case GL_ALPHA:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_UINT(rgba[i][ACOMP]);
+ break;
+ case GL_LUMINANCE:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_UINT(luminance[i]);
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_UINT(luminance[i]);
+ dst[i*2+1] = FLOAT_TO_UINT(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_RG:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
+ }
+ break;
+ case GL_RGB:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
+ dst[i*3+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_TO_UINT(rgba[i][BCOMP]);
+ }
+ break;
+ case GL_RGBA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
+ dst[i*4+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_TO_UINT(rgba[i][BCOMP]);
+ dst[i*4+3] = FLOAT_TO_UINT(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_BGR:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = FLOAT_TO_UINT(rgba[i][BCOMP]);
+ dst[i*3+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_TO_UINT(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_BGRA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_UINT(rgba[i][BCOMP]);
+ dst[i*4+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_TO_UINT(rgba[i][RCOMP]);
+ dst[i*4+3] = FLOAT_TO_UINT(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_ABGR_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_UINT(rgba[i][ACOMP]);
+ dst[i*4+1] = FLOAT_TO_UINT(rgba[i][BCOMP]);
+ dst[i*4+2] = FLOAT_TO_UINT(rgba[i][GCOMP]);
+ dst[i*4+3] = FLOAT_TO_UINT(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_RED_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLuint) rgba[i][RCOMP];
+ }
+ break;
+ case GL_GREEN_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLuint) rgba[i][GCOMP];
+ }
+ break;
+ case GL_BLUE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLuint) rgba[i][BCOMP];
+ }
+ break;
+ case GL_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLuint) rgba[i][ACOMP];
+ }
+ break;
+ case GL_RGB_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLuint) rgba[i][RCOMP];
+ dst[i*3+1] = (GLuint) rgba[i][GCOMP];
+ dst[i*3+2] = (GLuint) rgba[i][BCOMP];
+ }
+ break;
+ case GL_RGBA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLuint) rgba[i][RCOMP];
+ dst[i*4+1] = (GLuint) rgba[i][GCOMP];
+ dst[i*4+2] = (GLuint) rgba[i][BCOMP];
+ dst[i*4+3] = (GLuint) rgba[i][ACOMP];
+ }
+ break;
+ case GL_BGR_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLuint) rgba[i][BCOMP];
+ dst[i*3+1] = (GLuint) rgba[i][GCOMP];
+ dst[i*3+2] = (GLuint) rgba[i][RCOMP];
+ }
+ break;
+ case GL_BGRA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLuint) rgba[i][BCOMP];
+ dst[i*4+1] = (GLuint) rgba[i][GCOMP];
+ dst[i*4+2] = (GLuint) rgba[i][RCOMP];
+ dst[i*4+3] = (GLuint) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = (GLuint) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ dst[i*2+1] = (GLuint) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLuint) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ }
+ break;
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
+ }
+ }
+ break;
+ case GL_INT:
+ {
+ GLint *dst = (GLint *) dstAddr;
+ switch (dstFormat) {
+ case GL_RED:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_INT(rgba[i][RCOMP]);
+ break;
+ case GL_GREEN:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_INT(rgba[i][GCOMP]);
+ break;
+ case GL_BLUE:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_INT(rgba[i][BCOMP]);
+ break;
+ case GL_ALPHA:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_INT(rgba[i][ACOMP]);
+ break;
+ case GL_LUMINANCE:
+ for (i=0;i<n;i++)
+ dst[i] = FLOAT_TO_INT(luminance[i]);
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_INT(luminance[i]);
+ dst[i*2+1] = FLOAT_TO_INT(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_RG:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
+ }
+ break;
+ case GL_RGB:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
+ dst[i*3+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_TO_INT(rgba[i][BCOMP]);
+ }
+ break;
+ case GL_RGBA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
+ dst[i*4+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_TO_INT(rgba[i][BCOMP]);
+ dst[i*4+3] = FLOAT_TO_INT(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_BGR:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = FLOAT_TO_INT(rgba[i][BCOMP]);
+ dst[i*3+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_TO_INT(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_BGRA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_INT(rgba[i][BCOMP]);
+ dst[i*4+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_TO_INT(rgba[i][RCOMP]);
+ dst[i*4+3] = FLOAT_TO_INT(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_ABGR_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = FLOAT_TO_INT(rgba[i][ACOMP]);
+ dst[i*4+1] = FLOAT_TO_INT(rgba[i][BCOMP]);
+ dst[i*4+2] = FLOAT_TO_INT(rgba[i][GCOMP]);
+ dst[i*4+3] = FLOAT_TO_INT(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
+ }
+ break;
+ case GL_RED_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLint) rgba[i][RCOMP];
+ }
+ break;
+ case GL_GREEN_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLint) rgba[i][GCOMP];
+ }
+ break;
+ case GL_BLUE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLint) rgba[i][BCOMP];
+ }
+ break;
+ case GL_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLint) rgba[i][ACOMP];
+ }
+ break;
+ case GL_RGB_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLint) rgba[i][RCOMP];
+ dst[i*3+1] = (GLint) rgba[i][GCOMP];
+ dst[i*3+2] = (GLint) rgba[i][BCOMP];
+ }
+ break;
+ case GL_RGBA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLint) rgba[i][RCOMP];
+ dst[i*4+1] = (GLint) rgba[i][GCOMP];
+ dst[i*4+2] = (GLint) rgba[i][BCOMP];
+ dst[i*4+3] = (GLint) rgba[i][ACOMP];
+ }
+ break;
+ case GL_BGR_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = (GLint) rgba[i][BCOMP];
+ dst[i*3+1] = (GLint) rgba[i][GCOMP];
+ dst[i*3+2] = (GLint) rgba[i][RCOMP];
+ }
+ break;
+ case GL_BGRA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = (GLint) rgba[i][BCOMP];
+ dst[i*4+1] = (GLint) rgba[i][GCOMP];
+ dst[i*4+2] = (GLint) rgba[i][RCOMP];
+ dst[i*4+3] = (GLint) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = (GLint) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ dst[i*2+1] = (GLint) rgba[i][ACOMP];
+ }
+ break;
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ for (i=0;i<n;i++) {
+ dst[i] = (GLint) (rgba[i][RCOMP] +
+ rgba[i][GCOMP] +
+ rgba[i][BCOMP]);
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
+ }
+ }
+ break;
+ case GL_FLOAT:
+ {
+ GLfloat *dst = (GLfloat *) dstAddr;
+ switch (dstFormat) {
+ case GL_RED:
+ for (i=0;i<n;i++)
+ dst[i] = rgba[i][RCOMP];
+ break;
+ case GL_GREEN:
+ for (i=0;i<n;i++)
+ dst[i] = rgba[i][GCOMP];
+ break;
+ case GL_BLUE:
+ for (i=0;i<n;i++)
+ dst[i] = rgba[i][BCOMP];
+ break;
+ case GL_ALPHA:
+ for (i=0;i<n;i++)
+ dst[i] = rgba[i][ACOMP];
+ break;
+ case GL_LUMINANCE:
+ for (i=0;i<n;i++)
+ dst[i] = luminance[i];
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = luminance[i];
+ dst[i*2+1] = rgba[i][ACOMP];
+ }
+ break;
+ case GL_RG:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = rgba[i][RCOMP];
+ dst[i*2+1] = rgba[i][GCOMP];
+ }
+ break;
+ case GL_RGB:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = rgba[i][RCOMP];
+ dst[i*3+1] = rgba[i][GCOMP];
+ dst[i*3+2] = rgba[i][BCOMP];
+ }
+ break;
+ case GL_RGBA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = rgba[i][RCOMP];
+ dst[i*4+1] = rgba[i][GCOMP];
+ dst[i*4+2] = rgba[i][BCOMP];
+ dst[i*4+3] = rgba[i][ACOMP];
+ }
+ break;
+ case GL_BGR:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = rgba[i][BCOMP];
+ dst[i*3+1] = rgba[i][GCOMP];
+ dst[i*3+2] = rgba[i][RCOMP];
+ }
+ break;
+ case GL_BGRA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = rgba[i][BCOMP];
+ dst[i*4+1] = rgba[i][GCOMP];
+ dst[i*4+2] = rgba[i][RCOMP];
+ dst[i*4+3] = rgba[i][ACOMP];
+ }
+ break;
+ case GL_ABGR_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = rgba[i][ACOMP];
+ dst[i*4+1] = rgba[i][BCOMP];
+ dst[i*4+2] = rgba[i][GCOMP];
+ dst[i*4+3] = rgba[i][RCOMP];
+ }
+ break;
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = rgba[i][RCOMP];
+ dst[i*2+1] = rgba[i][GCOMP];
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
+ }
+ }
+ break;
+ case GL_HALF_FLOAT_ARB:
+ {
+ GLhalfARB *dst = (GLhalfARB *) dstAddr;
+ switch (dstFormat) {
+ case GL_RED:
+ for (i=0;i<n;i++)
+ dst[i] = _mesa_float_to_half(rgba[i][RCOMP]);
+ break;
+ case GL_GREEN:
+ for (i=0;i<n;i++)
+ dst[i] = _mesa_float_to_half(rgba[i][GCOMP]);
+ break;
+ case GL_BLUE:
+ for (i=0;i<n;i++)
+ dst[i] = _mesa_float_to_half(rgba[i][BCOMP]);
+ break;
+ case GL_ALPHA:
+ for (i=0;i<n;i++)
+ dst[i] = _mesa_float_to_half(rgba[i][ACOMP]);
+ break;
+ case GL_LUMINANCE:
+ for (i=0;i<n;i++)
+ dst[i] = _mesa_float_to_half(luminance[i]);
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = _mesa_float_to_half(luminance[i]);
+ dst[i*2+1] = _mesa_float_to_half(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_RG:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = _mesa_float_to_half(rgba[i][RCOMP]);
+ dst[i*2+1] = _mesa_float_to_half(rgba[i][GCOMP]);
+ }
+ break;
+ case GL_RGB:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = _mesa_float_to_half(rgba[i][RCOMP]);
+ dst[i*3+1] = _mesa_float_to_half(rgba[i][GCOMP]);
+ dst[i*3+2] = _mesa_float_to_half(rgba[i][BCOMP]);
+ }
+ break;
+ case GL_RGBA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = _mesa_float_to_half(rgba[i][RCOMP]);
+ dst[i*4+1] = _mesa_float_to_half(rgba[i][GCOMP]);
+ dst[i*4+2] = _mesa_float_to_half(rgba[i][BCOMP]);
+ dst[i*4+3] = _mesa_float_to_half(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_BGR:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = _mesa_float_to_half(rgba[i][BCOMP]);
+ dst[i*3+1] = _mesa_float_to_half(rgba[i][GCOMP]);
+ dst[i*3+2] = _mesa_float_to_half(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_BGRA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = _mesa_float_to_half(rgba[i][BCOMP]);
+ dst[i*4+1] = _mesa_float_to_half(rgba[i][GCOMP]);
+ dst[i*4+2] = _mesa_float_to_half(rgba[i][RCOMP]);
+ dst[i*4+3] = _mesa_float_to_half(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_ABGR_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = _mesa_float_to_half(rgba[i][ACOMP]);
+ dst[i*4+1] = _mesa_float_to_half(rgba[i][BCOMP]);
+ dst[i*4+2] = _mesa_float_to_half(rgba[i][GCOMP]);
+ dst[i*4+3] = _mesa_float_to_half(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_DUDV_ATI:
+ case GL_DU8DV8_ATI:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = _mesa_float_to_half(rgba[i][RCOMP]);
+ dst[i*2+1] = _mesa_float_to_half(rgba[i][GCOMP]);
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
+ }
+ }
+ break;
+ case GL_UNSIGNED_BYTE_3_3_2:
+ if (dstFormat == GL_RGB) {
+ GLubyte *dst = (GLubyte *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 7.0F) << 5)
+ | (IROUND(rgba[i][GCOMP] * 7.0F) << 2)
+ | (IROUND(rgba[i][BCOMP] * 3.0F) );
+ }
+ }
+ break;
+ case GL_UNSIGNED_BYTE_2_3_3_REV:
+ if (dstFormat == GL_RGB) {
+ GLubyte *dst = (GLubyte *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 7.0F) )
+ | (IROUND(rgba[i][GCOMP] * 7.0F) << 3)
+ | (IROUND(rgba[i][BCOMP] * 3.0F) << 6);
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_5_6_5:
+ if (dstFormat == GL_RGB) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) << 11)
+ | (IROUND(rgba[i][GCOMP] * 63.0F) << 5)
+ | (IROUND(rgba[i][BCOMP] * 31.0F) );
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
+ if (dstFormat == GL_RGB) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) )
+ | (IROUND(rgba[i][GCOMP] * 63.0F) << 5)
+ | (IROUND(rgba[i][BCOMP] * 31.0F) << 11);
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ if (dstFormat == GL_RGBA) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 15.0F) << 12)
+ | (IROUND(rgba[i][GCOMP] * 15.0F) << 8)
+ | (IROUND(rgba[i][BCOMP] * 15.0F) << 4)
+ | (IROUND(rgba[i][ACOMP] * 15.0F) );
+ }
+ }
+ else if (dstFormat == GL_BGRA) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][BCOMP] * 15.0F) << 12)
+ | (IROUND(rgba[i][GCOMP] * 15.0F) << 8)
+ | (IROUND(rgba[i][RCOMP] * 15.0F) << 4)
+ | (IROUND(rgba[i][ACOMP] * 15.0F) );
+ }
+ }
+ else if (dstFormat == GL_ABGR_EXT) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][ACOMP] * 15.0F) << 12)
+ | (IROUND(rgba[i][BCOMP] * 15.0F) << 8)
+ | (IROUND(rgba[i][GCOMP] * 15.0F) << 4)
+ | (IROUND(rgba[i][RCOMP] * 15.0F) );
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ if (dstFormat == GL_RGBA) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 15.0F) )
+ | (IROUND(rgba[i][GCOMP] * 15.0F) << 4)
+ | (IROUND(rgba[i][BCOMP] * 15.0F) << 8)
+ | (IROUND(rgba[i][ACOMP] * 15.0F) << 12);
+ }
+ }
+ else if (dstFormat == GL_BGRA) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][BCOMP] * 15.0F) )
+ | (IROUND(rgba[i][GCOMP] * 15.0F) << 4)
+ | (IROUND(rgba[i][RCOMP] * 15.0F) << 8)
+ | (IROUND(rgba[i][ACOMP] * 15.0F) << 12);
+ }
+ }
+ else if (dstFormat == GL_ABGR_EXT) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][ACOMP] * 15.0F) )
+ | (IROUND(rgba[i][BCOMP] * 15.0F) << 4)
+ | (IROUND(rgba[i][GCOMP] * 15.0F) << 8)
+ | (IROUND(rgba[i][RCOMP] * 15.0F) << 12);
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ if (dstFormat == GL_RGBA) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) << 11)
+ | (IROUND(rgba[i][GCOMP] * 31.0F) << 6)
+ | (IROUND(rgba[i][BCOMP] * 31.0F) << 1)
+ | (IROUND(rgba[i][ACOMP] * 1.0F) );
+ }
+ }
+ else if (dstFormat == GL_BGRA) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][BCOMP] * 31.0F) << 11)
+ | (IROUND(rgba[i][GCOMP] * 31.0F) << 6)
+ | (IROUND(rgba[i][RCOMP] * 31.0F) << 1)
+ | (IROUND(rgba[i][ACOMP] * 1.0F) );
+ }
+ }
+ else if (dstFormat == GL_ABGR_EXT) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][ACOMP] * 31.0F) << 11)
+ | (IROUND(rgba[i][BCOMP] * 31.0F) << 6)
+ | (IROUND(rgba[i][GCOMP] * 31.0F) << 1)
+ | (IROUND(rgba[i][RCOMP] * 1.0F) );
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ if (dstFormat == GL_RGBA) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) )
+ | (IROUND(rgba[i][GCOMP] * 31.0F) << 5)
+ | (IROUND(rgba[i][BCOMP] * 31.0F) << 10)
+ | (IROUND(rgba[i][ACOMP] * 1.0F) << 15);
+ }
+ }
+ else if (dstFormat == GL_BGRA) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][BCOMP] * 31.0F) )
+ | (IROUND(rgba[i][GCOMP] * 31.0F) << 5)
+ | (IROUND(rgba[i][RCOMP] * 31.0F) << 10)
+ | (IROUND(rgba[i][ACOMP] * 1.0F) << 15);
+ }
+ }
+ else if (dstFormat == GL_ABGR_EXT) {
+ GLushort *dst = (GLushort *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][ACOMP] * 31.0F) )
+ | (IROUND(rgba[i][BCOMP] * 31.0F) << 5)
+ | (IROUND(rgba[i][GCOMP] * 31.0F) << 10)
+ | (IROUND(rgba[i][RCOMP] * 1.0F) << 15);
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_8_8_8_8:
+ if (dstFormat == GL_RGBA) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 255.F) << 24)
+ | (IROUND(rgba[i][GCOMP] * 255.F) << 16)
+ | (IROUND(rgba[i][BCOMP] * 255.F) << 8)
+ | (IROUND(rgba[i][ACOMP] * 255.F) );
+ }
+ }
+ else if (dstFormat == GL_BGRA) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][BCOMP] * 255.F) << 24)
+ | (IROUND(rgba[i][GCOMP] * 255.F) << 16)
+ | (IROUND(rgba[i][RCOMP] * 255.F) << 8)
+ | (IROUND(rgba[i][ACOMP] * 255.F) );
+ }
+ }
+ else if (dstFormat == GL_ABGR_EXT) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][ACOMP] * 255.F) << 24)
+ | (IROUND(rgba[i][BCOMP] * 255.F) << 16)
+ | (IROUND(rgba[i][GCOMP] * 255.F) << 8)
+ | (IROUND(rgba[i][RCOMP] * 255.F) );
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ if (dstFormat == GL_RGBA) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 255.0F) )
+ | (IROUND(rgba[i][GCOMP] * 255.0F) << 8)
+ | (IROUND(rgba[i][BCOMP] * 255.0F) << 16)
+ | (IROUND(rgba[i][ACOMP] * 255.0F) << 24);
+ }
+ }
+ else if (dstFormat == GL_BGRA) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][BCOMP] * 255.0F) )
+ | (IROUND(rgba[i][GCOMP] * 255.0F) << 8)
+ | (IROUND(rgba[i][RCOMP] * 255.0F) << 16)
+ | (IROUND(rgba[i][ACOMP] * 255.0F) << 24);
+ }
+ }
+ else if (dstFormat == GL_ABGR_EXT) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][ACOMP] * 255.0F) )
+ | (IROUND(rgba[i][BCOMP] * 255.0F) << 8)
+ | (IROUND(rgba[i][GCOMP] * 255.0F) << 16)
+ | (IROUND(rgba[i][RCOMP] * 255.0F) << 24);
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_10_10_10_2:
+ if (dstFormat == GL_RGBA) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 1023.0F) << 22)
+ | (IROUND(rgba[i][GCOMP] * 1023.0F) << 12)
+ | (IROUND(rgba[i][BCOMP] * 1023.0F) << 2)
+ | (IROUND(rgba[i][ACOMP] * 3.0F) );
+ }
+ }
+ else if (dstFormat == GL_BGRA) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][BCOMP] * 1023.0F) << 22)
+ | (IROUND(rgba[i][GCOMP] * 1023.0F) << 12)
+ | (IROUND(rgba[i][RCOMP] * 1023.0F) << 2)
+ | (IROUND(rgba[i][ACOMP] * 3.0F) );
+ }
+ }
+ else if (dstFormat == GL_ABGR_EXT) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][ACOMP] * 1023.0F) << 22)
+ | (IROUND(rgba[i][BCOMP] * 1023.0F) << 12)
+ | (IROUND(rgba[i][GCOMP] * 1023.0F) << 2)
+ | (IROUND(rgba[i][RCOMP] * 3.0F) );
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ if (dstFormat == GL_RGBA) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][RCOMP] * 1023.0F) )
+ | (IROUND(rgba[i][GCOMP] * 1023.0F) << 10)
+ | (IROUND(rgba[i][BCOMP] * 1023.0F) << 20)
+ | (IROUND(rgba[i][ACOMP] * 3.0F) << 30);
+ }
+ }
+ else if (dstFormat == GL_BGRA) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][BCOMP] * 1023.0F) )
+ | (IROUND(rgba[i][GCOMP] * 1023.0F) << 10)
+ | (IROUND(rgba[i][RCOMP] * 1023.0F) << 20)
+ | (IROUND(rgba[i][ACOMP] * 3.0F) << 30);
+ }
+ }
+ else if (dstFormat == GL_ABGR_EXT) {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i=0;i<n;i++) {
+ dst[i] = (IROUND(rgba[i][ACOMP] * 1023.0F) )
+ | (IROUND(rgba[i][BCOMP] * 1023.0F) << 10)
+ | (IROUND(rgba[i][GCOMP] * 1023.0F) << 20)
+ | (IROUND(rgba[i][RCOMP] * 3.0F) << 30);
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_5_9_9_9_REV:
+ {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i = 0; i < n; i++) {
+ dst[i] = float3_to_rgb9e5(rgba[i]);
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_10F_11F_11F_REV:
+ {
+ GLuint *dst = (GLuint *) dstAddr;
+ for (i = 0; i < n; i++) {
+ dst[i] = float3_to_r11g11b10f(rgba[i]);
+ }
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad type in _mesa_pack_rgba_span_float");
+ return;
+ }
+
+ if (dstPacking->SwapBytes) {
+ GLint swapSize = _mesa_sizeof_packed_type(dstType);
+ if (swapSize == 2) {
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2((GLushort *) dstAddr, n * comps);
+ }
+ }
+ else if (swapSize == 4) {
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4((GLuint *) dstAddr, n * comps);
+ }
+ }
+ }
+
+ free(luminance);
+}
+
+
+
+#define SWAP2BYTE(VALUE) \
+ { \
+ GLubyte *bytes = (GLubyte *) &(VALUE); \
+ GLubyte tmp = bytes[0]; \
+ bytes[0] = bytes[1]; \
+ bytes[1] = tmp; \
+ }
+
+#define SWAP4BYTE(VALUE) \
+ { \
+ GLubyte *bytes = (GLubyte *) &(VALUE); \
+ GLubyte tmp = bytes[0]; \
+ bytes[0] = bytes[3]; \
+ bytes[3] = tmp; \
+ tmp = bytes[1]; \
+ bytes[1] = bytes[2]; \
+ bytes[2] = tmp; \
+ }
+
+
+static void
+extract_uint_indexes(GLuint n, GLuint indexes[],
+ GLenum srcFormat, GLenum srcType, const GLvoid *src,
+ const struct gl_pixelstore_attrib *unpack )
+{
+ ASSERT(srcFormat == GL_COLOR_INDEX || srcFormat == GL_STENCIL_INDEX);
+
+ ASSERT(srcType == GL_BITMAP ||
+ srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_BYTE ||
+ srcType == GL_UNSIGNED_SHORT ||
+ srcType == GL_SHORT ||
+ srcType == GL_UNSIGNED_INT ||
+ srcType == GL_INT ||
+ srcType == GL_UNSIGNED_INT_24_8_EXT ||
+ srcType == GL_HALF_FLOAT_ARB ||
+ srcType == GL_FLOAT);
+
+ switch (srcType) {
+ case GL_BITMAP:
+ {
+ GLubyte *ubsrc = (GLubyte *) src;
+ if (unpack->LsbFirst) {
+ GLubyte mask = 1 << (unpack->SkipPixels & 0x7);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ indexes[i] = (*ubsrc & mask) ? 1 : 0;
+ if (mask == 128) {
+ mask = 1;
+ ubsrc++;
+ }
+ else {
+ mask = mask << 1;
+ }
+ }
+ }
+ else {
+ GLubyte mask = 128 >> (unpack->SkipPixels & 0x7);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ indexes[i] = (*ubsrc & mask) ? 1 : 0;
+ if (mask == 1) {
+ mask = 128;
+ ubsrc++;
+ }
+ else {
+ mask = mask >> 1;
+ }
+ }
+ }
+ }
+ break;
+ case GL_UNSIGNED_BYTE:
+ {
+ GLuint i;
+ const GLubyte *s = (const GLubyte *) src;
+ for (i = 0; i < n; i++)
+ indexes[i] = s[i];
+ }
+ break;
+ case GL_BYTE:
+ {
+ GLuint i;
+ const GLbyte *s = (const GLbyte *) src;
+ for (i = 0; i < n; i++)
+ indexes[i] = s[i];
+ }
+ break;
+ case GL_UNSIGNED_SHORT:
+ {
+ GLuint i;
+ const GLushort *s = (const GLushort *) src;
+ if (unpack->SwapBytes) {
+ for (i = 0; i < n; i++) {
+ GLushort value = s[i];
+ SWAP2BYTE(value);
+ indexes[i] = value;
+ }
+ }
+ else {
+ for (i = 0; i < n; i++)
+ indexes[i] = s[i];
+ }
+ }
+ break;
+ case GL_SHORT:
+ {
+ GLuint i;
+ const GLshort *s = (const GLshort *) src;
+ if (unpack->SwapBytes) {
+ for (i = 0; i < n; i++) {
+ GLshort value = s[i];
+ SWAP2BYTE(value);
+ indexes[i] = value;
+ }
+ }
+ else {
+ for (i = 0; i < n; i++)
+ indexes[i] = s[i];
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT:
+ {
+ GLuint i;
+ const GLuint *s = (const GLuint *) src;
+ if (unpack->SwapBytes) {
+ for (i = 0; i < n; i++) {
+ GLuint value = s[i];
+ SWAP4BYTE(value);
+ indexes[i] = value;
+ }
+ }
+ else {
+ for (i = 0; i < n; i++)
+ indexes[i] = s[i];
+ }
+ }
+ break;
+ case GL_INT:
+ {
+ GLuint i;
+ const GLint *s = (const GLint *) src;
+ if (unpack->SwapBytes) {
+ for (i = 0; i < n; i++) {
+ GLint value = s[i];
+ SWAP4BYTE(value);
+ indexes[i] = value;
+ }
+ }
+ else {
+ for (i = 0; i < n; i++)
+ indexes[i] = s[i];
+ }
+ }
+ break;
+ case GL_FLOAT:
+ {
+ GLuint i;
+ const GLfloat *s = (const GLfloat *) src;
+ if (unpack->SwapBytes) {
+ for (i = 0; i < n; i++) {
+ GLfloat value = s[i];
+ SWAP4BYTE(value);
+ indexes[i] = (GLuint) value;
+ }
+ }
+ else {
+ for (i = 0; i < n; i++)
+ indexes[i] = (GLuint) s[i];
+ }
+ }
+ break;
+ case GL_HALF_FLOAT_ARB:
+ {
+ GLuint i;
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ if (unpack->SwapBytes) {
+ for (i = 0; i < n; i++) {
+ GLhalfARB value = s[i];
+ SWAP2BYTE(value);
+ indexes[i] = (GLuint) _mesa_half_to_float(value);
+ }
+ }
+ else {
+ for (i = 0; i < n; i++)
+ indexes[i] = (GLuint) _mesa_half_to_float(s[i]);
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_24_8_EXT:
+ {
+ GLuint i;
+ const GLuint *s = (const GLuint *) src;
+ if (unpack->SwapBytes) {
+ for (i = 0; i < n; i++) {
+ GLuint value = s[i];
+ SWAP4BYTE(value);
+ indexes[i] = value & 0xff; /* lower 8 bits */
+ }
+ }
+ else {
+ for (i = 0; i < n; i++)
+ indexes[i] = s[i] & 0xff; /* lower 8 bits */
+ }
+ }
+ break;
+
+ default:
+ _mesa_problem(NULL, "bad srcType in extract_uint_indexes");
+ return;
+ }
+}
+
+
+/**
+ * Return source/dest RGBA indexes for unpacking pixels.
+ */
+static void
+get_component_mapping(GLenum format,
+ GLint *rSrc,
+ GLint *gSrc,
+ GLint *bSrc,
+ GLint *aSrc,
+ GLint *rDst,
+ GLint *gDst,
+ GLint *bDst,
+ GLint *aDst)
+{
+ switch (format) {
+ case GL_RED:
+ case GL_RED_INTEGER_EXT:
+ *rSrc = 0;
+ *gSrc = *bSrc = *aSrc = -1;
+ break;
+ case GL_GREEN:
+ case GL_GREEN_INTEGER_EXT:
+ *gSrc = 0;
+ *rSrc = *bSrc = *aSrc = -1;
+ break;
+ case GL_BLUE:
+ case GL_BLUE_INTEGER_EXT:
+ *bSrc = 0;
+ *rSrc = *gSrc = *aSrc = -1;
+ break;
+ case GL_ALPHA:
+ case GL_ALPHA_INTEGER_EXT:
+ *rSrc = *gSrc = *bSrc = -1;
+ *aSrc = 0;
+ break;
+ case GL_LUMINANCE:
+ case GL_LUMINANCE_INTEGER_EXT:
+ *rSrc = *gSrc = *bSrc = 0;
+ *aSrc = -1;
+ break;
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+ *rSrc = *gSrc = *bSrc = 0;
+ *aSrc = 1;
+ break;
+ case GL_INTENSITY:
+ *rSrc = *gSrc = *bSrc = *aSrc = 0;
+ break;
+ case GL_RG:
+ case GL_RG_INTEGER:
+ *rSrc = 0;
+ *gSrc = 1;
+ *bSrc = -1;
+ *aSrc = -1;
+ *rDst = 0;
+ *gDst = 1;
+ *bDst = 2;
+ *aDst = 3;
+ break;
+ case GL_RGB:
+ case GL_RGB_INTEGER:
+ *rSrc = 0;
+ *gSrc = 1;
+ *bSrc = 2;
+ *aSrc = -1;
+ *rDst = 0;
+ *gDst = 1;
+ *bDst = 2;
+ *aDst = 3;
+ break;
+ case GL_BGR:
+ *rSrc = 2;
+ *gSrc = 1;
+ *bSrc = 0;
+ *aSrc = -1;
+ *rDst = 2;
+ *gDst = 1;
+ *bDst = 0;
+ *aDst = 3;
+ break;
+ case GL_RGBA:
+ case GL_RGBA_INTEGER:
+ *rSrc = 0;
+ *gSrc = 1;
+ *bSrc = 2;
+ *aSrc = 3;
+ *rDst = 0;
+ *gDst = 1;
+ *bDst = 2;
+ *aDst = 3;
+ break;
+ case GL_BGRA:
+ *rSrc = 2;
+ *gSrc = 1;
+ *bSrc = 0;
+ *aSrc = 3;
+ *rDst = 2;
+ *gDst = 1;
+ *bDst = 0;
+ *aDst = 3;
+ break;
+ case GL_ABGR_EXT:
+ *rSrc = 3;
+ *gSrc = 2;
+ *bSrc = 1;
+ *aSrc = 0;
+ *rDst = 3;
+ *gDst = 2;
+ *bDst = 1;
+ *aDst = 0;
+ break;
+ case GL_DU8DV8_ATI:
+ case GL_DUDV_ATI:
+ *rSrc = 0;
+ *gSrc = 1;
+ *bSrc = -1;
+ *aSrc = -1;
+ break;
+ default:
+ _mesa_problem(NULL, "bad srcFormat %s in get_component_mapping",
+ _mesa_lookup_enum_by_nr(format));
+ return;
+ }
+}
+
+
+
+/*
+ * This function extracts floating point RGBA values from arbitrary
+ * image data. srcFormat and srcType are the format and type parameters
+ * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
+ *
+ * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
+ * implements the "Conversion to floating point", "Conversion to RGB",
+ * and "Final Expansion to RGBA" operations.
+ *
+ * Args: n - number of pixels
+ * rgba - output colors
+ * srcFormat - format of incoming data
+ * srcType - data type of incoming data
+ * src - source data pointer
+ * swapBytes - perform byteswapping of incoming data?
+ */
+static void
+extract_float_rgba(GLuint n, GLfloat rgba[][4],
+ GLenum srcFormat, GLenum srcType, const GLvoid *src,
+ GLboolean swapBytes)
+{
+ GLint rSrc, gSrc, bSrc, aSrc;
+ GLint stride;
+ GLint rDst, bDst, gDst, aDst;
+ GLboolean intFormat;
+ GLfloat rs = 1.0f, gs = 1.0f, bs = 1.0f, as = 1.0f; /* scale factors */
+
+ ASSERT(srcFormat == GL_RED ||
+ srcFormat == GL_GREEN ||
+ srcFormat == GL_BLUE ||
+ srcFormat == GL_ALPHA ||
+ srcFormat == GL_LUMINANCE ||
+ srcFormat == GL_LUMINANCE_ALPHA ||
+ srcFormat == GL_INTENSITY ||
+ srcFormat == GL_RG ||
+ srcFormat == GL_RGB ||
+ srcFormat == GL_BGR ||
+ srcFormat == GL_RGBA ||
+ srcFormat == GL_BGRA ||
+ srcFormat == GL_ABGR_EXT ||
+ srcFormat == GL_DU8DV8_ATI ||
+ srcFormat == GL_DUDV_ATI ||
+ srcFormat == GL_RED_INTEGER_EXT ||
+ srcFormat == GL_GREEN_INTEGER_EXT ||
+ srcFormat == GL_BLUE_INTEGER_EXT ||
+ srcFormat == GL_ALPHA_INTEGER_EXT ||
+ srcFormat == GL_RGB_INTEGER_EXT ||
+ srcFormat == GL_RGBA_INTEGER_EXT ||
+ srcFormat == GL_BGR_INTEGER_EXT ||
+ srcFormat == GL_BGRA_INTEGER_EXT ||
+ srcFormat == GL_LUMINANCE_INTEGER_EXT ||
+ srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT);
+
+ ASSERT(srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_BYTE ||
+ srcType == GL_UNSIGNED_SHORT ||
+ srcType == GL_SHORT ||
+ srcType == GL_UNSIGNED_INT ||
+ srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_ARB ||
+ srcType == GL_FLOAT ||
+ srcType == GL_UNSIGNED_BYTE_3_3_2 ||
+ srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
+ srcType == GL_UNSIGNED_SHORT_5_6_5 ||
+ srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
+ srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
+ srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8 ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
+ srcType == GL_UNSIGNED_INT_10_10_10_2 ||
+ srcType == GL_UNSIGNED_INT_2_10_10_10_REV ||
+ srcType == GL_UNSIGNED_INT_5_9_9_9_REV ||
+ srcType == GL_UNSIGNED_INT_10F_11F_11F_REV);
+
+ get_component_mapping(srcFormat,
+ &rSrc, &gSrc, &bSrc, &aSrc,
+ &rDst, &gDst, &bDst, &aDst);
+
+ stride = _mesa_components_in_format(srcFormat);
+
+ intFormat = _mesa_is_integer_format(srcFormat);
+
+#define PROCESS(SRC_INDEX, DST_INDEX, DEFAULT_FLT, DEFAULT_INT, TYPE, CONVERSION) \
+ if ((SRC_INDEX) < 0) { \
+ GLuint i; \
+ if (intFormat) { \
+ for (i = 0; i < n; i++) { \
+ rgba[i][DST_INDEX] = DEFAULT_INT; \
+ } \
+ } \
+ else { \
+ for (i = 0; i < n; i++) { \
+ rgba[i][DST_INDEX] = DEFAULT_FLT; \
+ } \
+ } \
+ } \
+ else if (swapBytes) { \
+ const TYPE *s = (const TYPE *) src; \
+ GLuint i; \
+ for (i = 0; i < n; i++) { \
+ TYPE value = s[SRC_INDEX]; \
+ if (sizeof(TYPE) == 2) { \
+ SWAP2BYTE(value); \
+ } \
+ else if (sizeof(TYPE) == 4) { \
+ SWAP4BYTE(value); \
+ } \
+ if (intFormat) \
+ rgba[i][DST_INDEX] = (GLfloat) value; \
+ else \
+ rgba[i][DST_INDEX] = (GLfloat) CONVERSION(value); \
+ s += stride; \
+ } \
+ } \
+ else { \
+ const TYPE *s = (const TYPE *) src; \
+ GLuint i; \
+ if (intFormat) { \
+ for (i = 0; i < n; i++) { \
+ rgba[i][DST_INDEX] = (GLfloat) s[SRC_INDEX]; \
+ s += stride; \
+ } \
+ } \
+ else { \
+ for (i = 0; i < n; i++) { \
+ rgba[i][DST_INDEX] = (GLfloat) CONVERSION(s[SRC_INDEX]); \
+ s += stride; \
+ } \
+ } \
+ }
+
+ switch (srcType) {
+ case GL_UNSIGNED_BYTE:
+ PROCESS(rSrc, RCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT);
+ PROCESS(gSrc, GCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT);
+ PROCESS(bSrc, BCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT);
+ PROCESS(aSrc, ACOMP, 1.0F, 255, GLubyte, UBYTE_TO_FLOAT);
+ break;
+ case GL_BYTE:
+ PROCESS(rSrc, RCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
+ PROCESS(gSrc, GCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
+ PROCESS(bSrc, BCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
+ PROCESS(aSrc, ACOMP, 1.0F, 127, GLbyte, BYTE_TO_FLOAT);
+ break;
+ case GL_UNSIGNED_SHORT:
+ PROCESS(rSrc, RCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
+ PROCESS(gSrc, GCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
+ PROCESS(bSrc, BCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
+ PROCESS(aSrc, ACOMP, 1.0F, 0xffff, GLushort, USHORT_TO_FLOAT);
+ break;
+ case GL_SHORT:
+ PROCESS(rSrc, RCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
+ PROCESS(gSrc, GCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
+ PROCESS(bSrc, BCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
+ PROCESS(aSrc, ACOMP, 1.0F, 32767, GLshort, SHORT_TO_FLOAT);
+ break;
+ case GL_UNSIGNED_INT:
+ PROCESS(rSrc, RCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
+ PROCESS(gSrc, GCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
+ PROCESS(bSrc, BCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
+ PROCESS(aSrc, ACOMP, 1.0F, 0xffffffff, GLuint, UINT_TO_FLOAT);
+ break;
+ case GL_INT:
+ PROCESS(rSrc, RCOMP, 0.0F, 0, GLint, INT_TO_FLOAT);
+ PROCESS(gSrc, GCOMP, 0.0F, 0, GLint, INT_TO_FLOAT);
+ PROCESS(bSrc, BCOMP, 0.0F, 0, GLint, INT_TO_FLOAT);
+ PROCESS(aSrc, ACOMP, 1.0F, 2147483647, GLint, INT_TO_FLOAT);
+ break;
+ case GL_FLOAT:
+ PROCESS(rSrc, RCOMP, 0.0F, 0.0F, GLfloat, (GLfloat));
+ PROCESS(gSrc, GCOMP, 0.0F, 0.0F, GLfloat, (GLfloat));
+ PROCESS(bSrc, BCOMP, 0.0F, 0.0F, GLfloat, (GLfloat));
+ PROCESS(aSrc, ACOMP, 1.0F, 1.0F, GLfloat, (GLfloat));
+ break;
+ case GL_HALF_FLOAT_ARB:
+ PROCESS(rSrc, RCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
+ PROCESS(gSrc, GCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
+ PROCESS(bSrc, BCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
+ PROCESS(aSrc, ACOMP, 1.0F, 1.0F, GLhalfARB, _mesa_half_to_float);
+ break;
+ case GL_UNSIGNED_BYTE_3_3_2:
+ {
+ const GLubyte *ubsrc = (const GLubyte *) src;
+ GLuint i;
+ if (!intFormat) {
+ rs = 1.0F / 7.0F;
+ gs = 1.0F / 7.0F;
+ bs = 1.0F / 3.0F;
+ }
+ for (i = 0; i < n; i ++) {
+ GLubyte p = ubsrc[i];
+ rgba[i][rDst] = ((p >> 5) ) * rs;
+ rgba[i][gDst] = ((p >> 2) & 0x7) * gs;
+ rgba[i][bDst] = ((p ) & 0x3) * bs;
+ rgba[i][aDst] = 1.0F;
+ }
+ }
+ break;
+ case GL_UNSIGNED_BYTE_2_3_3_REV:
+ {
+ const GLubyte *ubsrc = (const GLubyte *) src;
+ GLuint i;
+ if (!intFormat) {
+ rs = 1.0F / 7.0F;
+ gs = 1.0F / 7.0F;
+ bs = 1.0F / 3.0F;
+ }
+ for (i = 0; i < n; i ++) {
+ GLubyte p = ubsrc[i];
+ rgba[i][rDst] = ((p ) & 0x7) * rs;
+ rgba[i][gDst] = ((p >> 3) & 0x7) * gs;
+ rgba[i][bDst] = ((p >> 6) ) * bs;
+ rgba[i][aDst] = 1.0F;
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_5_6_5:
+ if (!intFormat) {
+ rs = 1.0F / 31.0F;
+ gs = 1.0F / 63.0F;
+ bs = 1.0F / 31.0F;
+ }
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p >> 11) ) * rs;
+ rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
+ rgba[i][bDst] = ((p ) & 0x1f) * bs;
+ rgba[i][aDst] = 1.0F;
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p >> 11) ) * rs;
+ rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
+ rgba[i][bDst] = ((p ) & 0x1f) * bs;
+ rgba[i][aDst] = 1.0F;
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
+ if (!intFormat) {
+ rs = 1.0F / 31.0F;
+ gs = 1.0F / 63.0F;
+ bs = 1.0F / 31.0F;
+ }
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p ) & 0x1f) * rs;
+ rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
+ rgba[i][bDst] = ((p >> 11) ) * bs;
+ rgba[i][aDst] = 1.0F;
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p ) & 0x1f) * rs;
+ rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
+ rgba[i][bDst] = ((p >> 11) ) * bs;
+ rgba[i][aDst] = 1.0F;
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ if (!intFormat) {
+ rs = gs = bs = as = 1.0F / 15.0F;
+ }
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p >> 12) ) * rs;
+ rgba[i][gDst] = ((p >> 8) & 0xf) * gs;
+ rgba[i][bDst] = ((p >> 4) & 0xf) * bs;
+ rgba[i][aDst] = ((p ) & 0xf) * as;
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p >> 12) ) * rs;
+ rgba[i][gDst] = ((p >> 8) & 0xf) * gs;
+ rgba[i][bDst] = ((p >> 4) & 0xf) * bs;
+ rgba[i][aDst] = ((p ) & 0xf) * as;
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ if (!intFormat) {
+ rs = gs = bs = as = 1.0F / 15.0F;
+ }
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p ) & 0xf) * rs;
+ rgba[i][gDst] = ((p >> 4) & 0xf) * gs;
+ rgba[i][bDst] = ((p >> 8) & 0xf) * bs;
+ rgba[i][aDst] = ((p >> 12) ) * as;
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p ) & 0xf) * rs;
+ rgba[i][gDst] = ((p >> 4) & 0xf) * gs;
+ rgba[i][bDst] = ((p >> 8) & 0xf) * bs;
+ rgba[i][aDst] = ((p >> 12) ) * as;
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ if (!intFormat) {
+ rs = gs = bs = 1.0F / 31.0F;
+ }
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p >> 11) ) * rs;
+ rgba[i][gDst] = ((p >> 6) & 0x1f) * gs;
+ rgba[i][bDst] = ((p >> 1) & 0x1f) * bs;
+ rgba[i][aDst] = ((p ) & 0x1) * as;
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p >> 11) ) * rs;
+ rgba[i][gDst] = ((p >> 6) & 0x1f) * gs;
+ rgba[i][bDst] = ((p >> 1) & 0x1f) * bs;
+ rgba[i][aDst] = ((p ) & 0x1) * as;
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ if (!intFormat) {
+ rs = gs = bs = 1.0F / 31.0F;
+ }
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p ) & 0x1f) * rs;
+ rgba[i][gDst] = ((p >> 5) & 0x1f) * gs;
+ rgba[i][bDst] = ((p >> 10) & 0x1f) * bs;
+ rgba[i][aDst] = ((p >> 15) ) * as;
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p ) & 0x1f) * rs;
+ rgba[i][gDst] = ((p >> 5) & 0x1f) * gs;
+ rgba[i][bDst] = ((p >> 10) & 0x1f) * bs;
+ rgba[i][aDst] = ((p >> 15) ) * as;
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_8_8_8_8:
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ if (intFormat) {
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = (GLfloat) ((p ) & 0xff);
+ rgba[i][gDst] = (GLfloat) ((p >> 8) & 0xff);
+ rgba[i][bDst] = (GLfloat) ((p >> 16) & 0xff);
+ rgba[i][aDst] = (GLfloat) ((p >> 24) );
+ }
+ }
+ else {
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = UBYTE_TO_FLOAT((p ) & 0xff);
+ rgba[i][gDst] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
+ rgba[i][bDst] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
+ rgba[i][aDst] = UBYTE_TO_FLOAT((p >> 24) );
+ }
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ if (intFormat) {
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = (GLfloat) ((p >> 24) );
+ rgba[i][gDst] = (GLfloat) ((p >> 16) & 0xff);
+ rgba[i][bDst] = (GLfloat) ((p >> 8) & 0xff);
+ rgba[i][aDst] = (GLfloat) ((p ) & 0xff);
+ }
+ }
+ else {
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = UBYTE_TO_FLOAT((p >> 24) );
+ rgba[i][gDst] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
+ rgba[i][bDst] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
+ rgba[i][aDst] = UBYTE_TO_FLOAT((p ) & 0xff);
+ }
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ if (intFormat) {
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = (GLfloat) ((p >> 24) );
+ rgba[i][gDst] = (GLfloat) ((p >> 16) & 0xff);
+ rgba[i][bDst] = (GLfloat) ((p >> 8) & 0xff);
+ rgba[i][aDst] = (GLfloat) ((p ) & 0xff);
+ }
+ }
+ else {
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = UBYTE_TO_FLOAT((p >> 24) );
+ rgba[i][gDst] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
+ rgba[i][bDst] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
+ rgba[i][aDst] = UBYTE_TO_FLOAT((p ) & 0xff);
+ }
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ if (intFormat) {
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = (GLfloat) ((p ) & 0xff);
+ rgba[i][gDst] = (GLfloat) ((p >> 8) & 0xff);
+ rgba[i][bDst] = (GLfloat) ((p >> 16) & 0xff);
+ rgba[i][aDst] = (GLfloat) ((p >> 24) );
+ }
+ }
+ else {
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = UBYTE_TO_FLOAT((p ) & 0xff);
+ rgba[i][gDst] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
+ rgba[i][bDst] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
+ rgba[i][aDst] = UBYTE_TO_FLOAT((p >> 24) );
+ }
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_10_10_10_2:
+ if (!intFormat) {
+ rs = 1.0F / 1023.0F;
+ gs = 1.0F / 1023.0F;
+ bs = 1.0F / 1023.0F;
+ as = 1.0F / 3.0F;
+ }
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ SWAP4BYTE(p);
+ rgba[i][rDst] = ((p >> 22) ) * rs;
+ rgba[i][gDst] = ((p >> 12) & 0x3ff) * gs;
+ rgba[i][bDst] = ((p >> 2) & 0x3ff) * bs;
+ rgba[i][aDst] = ((p ) & 0x3 ) * as;
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = ((p >> 22) ) * rs;
+ rgba[i][gDst] = ((p >> 12) & 0x3ff) * gs;
+ rgba[i][bDst] = ((p >> 2) & 0x3ff) * bs;
+ rgba[i][aDst] = ((p ) & 0x3 ) * as;
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ if (!intFormat) {
+ rs = 1.0F / 1023.0F;
+ gs = 1.0F / 1023.0F;
+ bs = 1.0F / 1023.0F;
+ as = 1.0F / 3.0F;
+ }
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ SWAP4BYTE(p);
+ rgba[i][rDst] = ((p ) & 0x3ff) * rs;
+ rgba[i][gDst] = ((p >> 10) & 0x3ff) * gs;
+ rgba[i][bDst] = ((p >> 20) & 0x3ff) * bs;
+ rgba[i][aDst] = ((p >> 30) ) * as;
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = ((p ) & 0x3ff) * rs;
+ rgba[i][gDst] = ((p >> 10) & 0x3ff) * gs;
+ rgba[i][bDst] = ((p >> 20) & 0x3ff) * bs;
+ rgba[i][aDst] = ((p >> 30) ) * as;
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_5_9_9_9_REV:
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ GLfloat f[3];
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ SWAP4BYTE(p);
+ rgb9e5_to_float3(p, f);
+ rgba[i][rDst] = f[0];
+ rgba[i][gDst] = f[1];
+ rgba[i][bDst] = f[2];
+ rgba[i][aDst] = 1.0F;
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ GLfloat f[3];
+ for (i = 0; i < n; i ++) {
+ rgb9e5_to_float3(uisrc[i], f);
+ rgba[i][rDst] = f[0];
+ rgba[i][gDst] = f[1];
+ rgba[i][bDst] = f[2];
+ rgba[i][aDst] = 1.0F;
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_10F_11F_11F_REV:
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ GLfloat f[3];
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ SWAP4BYTE(p);
+ r11g11b10f_to_float3(p, f);
+ rgba[i][rDst] = f[0];
+ rgba[i][gDst] = f[1];
+ rgba[i][bDst] = f[2];
+ rgba[i][aDst] = 1.0F;
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ GLfloat f[3];
+ for (i = 0; i < n; i ++) {
+ r11g11b10f_to_float3(uisrc[i], f);
+ rgba[i][rDst] = f[0];
+ rgba[i][gDst] = f[1];
+ rgba[i][bDst] = f[2];
+ rgba[i][aDst] = 1.0F;
+ }
+ }
+ break;
+ default:
+ _mesa_problem(NULL, "bad srcType in extract float data");
+ break;
+ }
+#undef PROCESS
+}
+
+
+static INLINE GLuint
+clamp_byte_to_uint(GLbyte b)
+{
+ return b < 0 ? 0 : b;
+}
+
+
+static INLINE GLuint
+clamp_short_to_uint(GLshort s)
+{
+ return s < 0 ? 0 : s;
+}
+
+
+static INLINE GLuint
+clamp_int_to_uint(GLint i)
+{
+ return i < 0 ? 0 : i;
+}
+
+
+static INLINE GLuint
+clamp_float_to_uint(GLfloat f)
+{
+ return f < 0.0F ? 0 : IROUND(f);
+}
+
+
+static INLINE GLuint
+clamp_half_to_uint(GLhalfARB h)
+{
+ GLfloat f = _mesa_half_to_float(h);
+ return f < 0.0F ? 0 : IROUND(f);
+}
+
+
+/**
+ * \sa extract_float_rgba()
+ */
+static void
+extract_uint_rgba(GLuint n, GLuint rgba[][4],
+ GLenum srcFormat, GLenum srcType, const GLvoid *src,
+ GLboolean swapBytes)
+{
+ GLint rSrc, gSrc, bSrc, aSrc;
+ GLint stride;
+ GLint rDst, bDst, gDst, aDst;
+ GLboolean intFormat;
+
+ ASSERT(srcFormat == GL_RED ||
+ srcFormat == GL_GREEN ||
+ srcFormat == GL_BLUE ||
+ srcFormat == GL_ALPHA ||
+ srcFormat == GL_LUMINANCE ||
+ srcFormat == GL_LUMINANCE_ALPHA ||
+ srcFormat == GL_INTENSITY ||
+ srcFormat == GL_RG ||
+ srcFormat == GL_RGB ||
+ srcFormat == GL_BGR ||
+ srcFormat == GL_RGBA ||
+ srcFormat == GL_BGRA ||
+ srcFormat == GL_ABGR_EXT ||
+ srcFormat == GL_DU8DV8_ATI ||
+ srcFormat == GL_DUDV_ATI ||
+ srcFormat == GL_RED_INTEGER_EXT ||
+ srcFormat == GL_GREEN_INTEGER_EXT ||
+ srcFormat == GL_BLUE_INTEGER_EXT ||
+ srcFormat == GL_ALPHA_INTEGER_EXT ||
+ srcFormat == GL_RGB_INTEGER_EXT ||
+ srcFormat == GL_RGBA_INTEGER_EXT ||
+ srcFormat == GL_BGR_INTEGER_EXT ||
+ srcFormat == GL_BGRA_INTEGER_EXT ||
+ srcFormat == GL_LUMINANCE_INTEGER_EXT ||
+ srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT);
+
+ ASSERT(srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_BYTE ||
+ srcType == GL_UNSIGNED_SHORT ||
+ srcType == GL_SHORT ||
+ srcType == GL_UNSIGNED_INT ||
+ srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_ARB ||
+ srcType == GL_FLOAT ||
+ srcType == GL_UNSIGNED_BYTE_3_3_2 ||
+ srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
+ srcType == GL_UNSIGNED_SHORT_5_6_5 ||
+ srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
+ srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
+ srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8 ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
+ srcType == GL_UNSIGNED_INT_10_10_10_2 ||
+ srcType == GL_UNSIGNED_INT_2_10_10_10_REV ||
+ srcType == GL_UNSIGNED_INT_5_9_9_9_REV ||
+ srcType == GL_UNSIGNED_INT_10F_11F_11F_REV);
+
+ get_component_mapping(srcFormat,
+ &rSrc, &gSrc, &bSrc, &aSrc,
+ &rDst, &gDst, &bDst, &aDst);
+
+ stride = _mesa_components_in_format(srcFormat);
+
+ intFormat = _mesa_is_integer_format(srcFormat);
+
+#define PROCESS(SRC_INDEX, DST_INDEX, DEFAULT, TYPE, CONVERSION) \
+ if ((SRC_INDEX) < 0) { \
+ GLuint i; \
+ for (i = 0; i < n; i++) { \
+ rgba[i][DST_INDEX] = DEFAULT; \
+ } \
+ } \
+ else if (swapBytes) { \
+ const TYPE *s = (const TYPE *) src; \
+ GLuint i; \
+ for (i = 0; i < n; i++) { \
+ TYPE value = s[SRC_INDEX]; \
+ if (sizeof(TYPE) == 2) { \
+ SWAP2BYTE(value); \
+ } \
+ else if (sizeof(TYPE) == 4) { \
+ SWAP4BYTE(value); \
+ } \
+ rgba[i][DST_INDEX] = CONVERSION(value); \
+ s += stride; \
+ } \
+ } \
+ else { \
+ const TYPE *s = (const TYPE *) src; \
+ GLuint i; \
+ for (i = 0; i < n; i++) { \
+ rgba[i][DST_INDEX] = CONVERSION(s[SRC_INDEX]); \
+ s += stride; \
+ } \
+ }
+
+ switch (srcType) {
+ case GL_UNSIGNED_BYTE:
+ PROCESS(rSrc, RCOMP, 0, GLubyte, (GLuint));
+ PROCESS(gSrc, GCOMP, 0, GLubyte, (GLuint));
+ PROCESS(bSrc, BCOMP, 0, GLubyte, (GLuint));
+ PROCESS(aSrc, ACOMP, 1, GLubyte, (GLuint));
+ break;
+ case GL_BYTE:
+ PROCESS(rSrc, RCOMP, 0, GLbyte, clamp_byte_to_uint);
+ PROCESS(gSrc, GCOMP, 0, GLbyte, clamp_byte_to_uint);
+ PROCESS(bSrc, BCOMP, 0, GLbyte, clamp_byte_to_uint);
+ PROCESS(aSrc, ACOMP, 1, GLbyte, clamp_byte_to_uint);
+ break;
+ case GL_UNSIGNED_SHORT:
+ PROCESS(rSrc, RCOMP, 0, GLushort, (GLuint));
+ PROCESS(gSrc, GCOMP, 0, GLushort, (GLuint));
+ PROCESS(bSrc, BCOMP, 0, GLushort, (GLuint));
+ PROCESS(aSrc, ACOMP, 1, GLushort, (GLuint));
+ break;
+ case GL_SHORT:
+ PROCESS(rSrc, RCOMP, 0, GLshort, clamp_short_to_uint);
+ PROCESS(gSrc, GCOMP, 0, GLshort, clamp_short_to_uint);
+ PROCESS(bSrc, BCOMP, 0, GLshort, clamp_short_to_uint);
+ PROCESS(aSrc, ACOMP, 1, GLshort, clamp_short_to_uint);
+ break;
+ case GL_UNSIGNED_INT:
+ PROCESS(rSrc, RCOMP, 0, GLuint, (GLuint));
+ PROCESS(gSrc, GCOMP, 0, GLuint, (GLuint));
+ PROCESS(bSrc, BCOMP, 0, GLuint, (GLuint));
+ PROCESS(aSrc, ACOMP, 1, GLuint, (GLuint));
+ break;
+ case GL_INT:
+ PROCESS(rSrc, RCOMP, 0, GLint, clamp_int_to_uint);
+ PROCESS(gSrc, GCOMP, 0, GLint, clamp_int_to_uint);
+ PROCESS(bSrc, BCOMP, 0, GLint, clamp_int_to_uint);
+ PROCESS(aSrc, ACOMP, 1, GLint, clamp_int_to_uint);
+ break;
+ case GL_FLOAT:
+ PROCESS(rSrc, RCOMP, 0, GLfloat, clamp_float_to_uint);
+ PROCESS(gSrc, GCOMP, 0, GLfloat, clamp_float_to_uint);
+ PROCESS(bSrc, BCOMP, 0, GLfloat, clamp_float_to_uint);
+ PROCESS(aSrc, ACOMP, 1, GLfloat, clamp_float_to_uint);
+ break;
+ case GL_HALF_FLOAT_ARB:
+ PROCESS(rSrc, RCOMP, 0, GLhalfARB, clamp_half_to_uint);
+ PROCESS(gSrc, GCOMP, 0, GLhalfARB, clamp_half_to_uint);
+ PROCESS(bSrc, BCOMP, 0, GLhalfARB, clamp_half_to_uint);
+ PROCESS(aSrc, ACOMP, 1, GLhalfARB, clamp_half_to_uint);
+ break;
+ case GL_UNSIGNED_BYTE_3_3_2:
+ {
+ const GLubyte *ubsrc = (const GLubyte *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLubyte p = ubsrc[i];
+ rgba[i][rDst] = ((p >> 5) );
+ rgba[i][gDst] = ((p >> 2) & 0x7);
+ rgba[i][bDst] = ((p ) & 0x3);
+ rgba[i][aDst] = 1;
+ }
+ }
+ break;
+ case GL_UNSIGNED_BYTE_2_3_3_REV:
+ {
+ const GLubyte *ubsrc = (const GLubyte *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLubyte p = ubsrc[i];
+ rgba[i][rDst] = ((p ) & 0x7);
+ rgba[i][gDst] = ((p >> 3) & 0x7);
+ rgba[i][bDst] = ((p >> 6) );
+ rgba[i][aDst] = 1;
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_5_6_5:
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p >> 11) );
+ rgba[i][gDst] = ((p >> 5) & 0x3f);
+ rgba[i][bDst] = ((p ) & 0x1f);
+ rgba[i][aDst] = 1;
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p >> 11) );
+ rgba[i][gDst] = ((p >> 5) & 0x3f);
+ rgba[i][bDst] = ((p ) & 0x1f);
+ rgba[i][aDst] = 1;
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p ) & 0x1f);
+ rgba[i][gDst] = ((p >> 5) & 0x3f);
+ rgba[i][bDst] = ((p >> 11) );
+ rgba[i][aDst] = 1;
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p ) & 0x1f);
+ rgba[i][gDst] = ((p >> 5) & 0x3f);
+ rgba[i][bDst] = ((p >> 11) );
+ rgba[i][aDst] = 1;
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p >> 12) );
+ rgba[i][gDst] = ((p >> 8) & 0xf);
+ rgba[i][bDst] = ((p >> 4) & 0xf);
+ rgba[i][aDst] = ((p ) & 0xf);
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p >> 12) );
+ rgba[i][gDst] = ((p >> 8) & 0xf);
+ rgba[i][bDst] = ((p >> 4) & 0xf);
+ rgba[i][aDst] = ((p ) & 0xf);
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p ) & 0xf);
+ rgba[i][gDst] = ((p >> 4) & 0xf);
+ rgba[i][bDst] = ((p >> 8) & 0xf);
+ rgba[i][aDst] = ((p >> 12) );
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p ) & 0xf);
+ rgba[i][gDst] = ((p >> 4) & 0xf);
+ rgba[i][bDst] = ((p >> 8) & 0xf);
+ rgba[i][aDst] = ((p >> 12) );
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p >> 11) );
+ rgba[i][gDst] = ((p >> 6) & 0x1f);
+ rgba[i][bDst] = ((p >> 1) & 0x1f);
+ rgba[i][aDst] = ((p ) & 0x1 );
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p >> 11) );
+ rgba[i][gDst] = ((p >> 6) & 0x1f);
+ rgba[i][bDst] = ((p >> 1) & 0x1f);
+ rgba[i][aDst] = ((p ) & 0x1 );
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ if (swapBytes) {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ SWAP2BYTE(p);
+ rgba[i][rDst] = ((p ) & 0x1f);
+ rgba[i][gDst] = ((p >> 5) & 0x1f);
+ rgba[i][bDst] = ((p >> 10) & 0x1f);
+ rgba[i][aDst] = ((p >> 15) );
+ }
+ }
+ else {
+ const GLushort *ussrc = (const GLushort *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLushort p = ussrc[i];
+ rgba[i][rDst] = ((p ) & 0x1f);
+ rgba[i][gDst] = ((p >> 5) & 0x1f);
+ rgba[i][bDst] = ((p >> 10) & 0x1f);
+ rgba[i][aDst] = ((p >> 15) );
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_8_8_8_8:
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = ((p ) & 0xff);
+ rgba[i][gDst] = ((p >> 8) & 0xff);
+ rgba[i][bDst] = ((p >> 16) & 0xff);
+ rgba[i][aDst] = ((p >> 24) );
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = ((p >> 24) );
+ rgba[i][gDst] = ((p >> 16) & 0xff);
+ rgba[i][bDst] = ((p >> 8) & 0xff);
+ rgba[i][aDst] = ((p ) & 0xff);
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = ((p >> 24) );
+ rgba[i][gDst] = ((p >> 16) & 0xff);
+ rgba[i][bDst] = ((p >> 8) & 0xff);
+ rgba[i][aDst] = ((p ) & 0xff);
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = ((p ) & 0xff);
+ rgba[i][gDst] = ((p >> 8) & 0xff);
+ rgba[i][bDst] = ((p >> 16) & 0xff);
+ rgba[i][aDst] = ((p >> 24) );
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_10_10_10_2:
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ SWAP4BYTE(p);
+ rgba[i][rDst] = ((p >> 22) );
+ rgba[i][gDst] = ((p >> 12) & 0x3ff);
+ rgba[i][bDst] = ((p >> 2) & 0x3ff);
+ rgba[i][aDst] = ((p ) & 0x3 );
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = ((p >> 22) );
+ rgba[i][gDst] = ((p >> 12) & 0x3ff);
+ rgba[i][bDst] = ((p >> 2) & 0x3ff);
+ rgba[i][aDst] = ((p ) & 0x3 );
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ SWAP4BYTE(p);
+ rgba[i][rDst] = ((p ) & 0x3ff);
+ rgba[i][gDst] = ((p >> 10) & 0x3ff);
+ rgba[i][bDst] = ((p >> 20) & 0x3ff);
+ rgba[i][aDst] = ((p >> 30) );
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgba[i][rDst] = ((p ) & 0x3ff);
+ rgba[i][gDst] = ((p >> 10) & 0x3ff);
+ rgba[i][bDst] = ((p >> 20) & 0x3ff);
+ rgba[i][aDst] = ((p >> 30) );
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_5_9_9_9_REV:
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ float f[3];
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ SWAP4BYTE(p);
+ rgb9e5_to_float3(p, f);
+ rgba[i][rDst] = clamp_float_to_uint(f[0]);
+ rgba[i][gDst] = clamp_float_to_uint(f[1]);
+ rgba[i][bDst] = clamp_float_to_uint(f[2]);
+ rgba[i][aDst] = 1;
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ float f[3];
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ rgb9e5_to_float3(p, f);
+ rgba[i][rDst] = clamp_float_to_uint(f[0]);
+ rgba[i][gDst] = clamp_float_to_uint(f[1]);
+ rgba[i][bDst] = clamp_float_to_uint(f[2]);
+ rgba[i][aDst] = 1;
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT_10F_11F_11F_REV:
+ if (swapBytes) {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ float f[3];
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ SWAP4BYTE(p);
+ r11g11b10f_to_float3(p, f);
+ rgba[i][rDst] = clamp_float_to_uint(f[0]);
+ rgba[i][gDst] = clamp_float_to_uint(f[1]);
+ rgba[i][bDst] = clamp_float_to_uint(f[2]);
+ rgba[i][aDst] = 1;
+ }
+ }
+ else {
+ const GLuint *uisrc = (const GLuint *) src;
+ GLuint i;
+ float f[3];
+ for (i = 0; i < n; i ++) {
+ GLuint p = uisrc[i];
+ r11g11b10f_to_float3(p, f);
+ rgba[i][rDst] = clamp_float_to_uint(f[0]);
+ rgba[i][gDst] = clamp_float_to_uint(f[1]);
+ rgba[i][bDst] = clamp_float_to_uint(f[2]);
+ rgba[i][aDst] = 1;
+ }
+ }
+ break;
+ default:
+ _mesa_problem(NULL, "bad srcType in extract uint data");
+ break;
+ }
+#undef PROCESS
+}
+
+
+
+/*
+ * Unpack a row of color image data from a client buffer according to
+ * the pixel unpacking parameters.
+ * Return GLchan values in the specified dest image format.
+ * This is used by glDrawPixels and glTexImage?D().
+ * \param ctx - the context
+ * n - number of pixels in the span
+ * dstFormat - format of destination color array
+ * dest - the destination color array
+ * srcFormat - source image format
+ * srcType - source image data type
+ * source - source image pointer
+ * srcPacking - pixel unpacking parameters
+ * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
+ *
+ * XXX perhaps expand this to process whole images someday.
+ */
+void
+_mesa_unpack_color_span_chan( struct gl_context *ctx,
+ GLuint n, GLenum dstFormat, GLchan dest[],
+ GLenum srcFormat, GLenum srcType,
+ const GLvoid *source,
+ const struct gl_pixelstore_attrib *srcPacking,
+ GLbitfield transferOps )
+{
+ ASSERT(dstFormat == GL_ALPHA ||
+ dstFormat == GL_LUMINANCE ||
+ dstFormat == GL_LUMINANCE_ALPHA ||
+ dstFormat == GL_INTENSITY ||
+ dstFormat == GL_RED ||
+ dstFormat == GL_RG ||
+ dstFormat == GL_RGB ||
+ dstFormat == GL_RGBA ||
+ dstFormat == GL_COLOR_INDEX);
+
+ ASSERT(srcFormat == GL_RED ||
+ srcFormat == GL_GREEN ||
+ srcFormat == GL_BLUE ||
+ srcFormat == GL_ALPHA ||
+ srcFormat == GL_LUMINANCE ||
+ srcFormat == GL_LUMINANCE_ALPHA ||
+ srcFormat == GL_INTENSITY ||
+ srcFormat == GL_RG ||
+ srcFormat == GL_RGB ||
+ srcFormat == GL_BGR ||
+ srcFormat == GL_RGBA ||
+ srcFormat == GL_BGRA ||
+ srcFormat == GL_ABGR_EXT ||
+ srcFormat == GL_COLOR_INDEX);
+
+ ASSERT(srcType == GL_BITMAP ||
+ srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_BYTE ||
+ srcType == GL_UNSIGNED_SHORT ||
+ srcType == GL_SHORT ||
+ srcType == GL_UNSIGNED_INT ||
+ srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_ARB ||
+ srcType == GL_FLOAT ||
+ srcType == GL_UNSIGNED_BYTE_3_3_2 ||
+ srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
+ srcType == GL_UNSIGNED_SHORT_5_6_5 ||
+ srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
+ srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
+ srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8 ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
+ srcType == GL_UNSIGNED_INT_10_10_10_2 ||
+ srcType == GL_UNSIGNED_INT_2_10_10_10_REV ||
+ srcType == GL_UNSIGNED_INT_5_9_9_9_REV ||
+ srcType == GL_UNSIGNED_INT_10F_11F_11F_REV);
+
+ /* Try simple cases first */
+ if (transferOps == 0) {
+ if (srcType == CHAN_TYPE) {
+ if (dstFormat == GL_RGBA) {
+ if (srcFormat == GL_RGBA) {
+ memcpy( dest, source, n * 4 * sizeof(GLchan) );
+ return;
+ }
+ else if (srcFormat == GL_RGB) {
+ GLuint i;
+ const GLchan *src = (const GLchan *) source;
+ GLchan *dst = dest;
+ for (i = 0; i < n; i++) {
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+ dst[3] = CHAN_MAX;
+ src += 3;
+ dst += 4;
+ }
+ return;
+ }
+ }
+ else if (dstFormat == GL_RGB) {
+ if (srcFormat == GL_RGB) {
+ memcpy( dest, source, n * 3 * sizeof(GLchan) );
+ return;
+ }
+ else if (srcFormat == GL_RGBA) {
+ GLuint i;
+ const GLchan *src = (const GLchan *) source;
+ GLchan *dst = dest;
+ for (i = 0; i < n; i++) {
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+ src += 4;
+ dst += 3;
+ }
+ return;
+ }
+ }
+ else if (dstFormat == srcFormat) {
+ GLint comps = _mesa_components_in_format(srcFormat);
+ assert(comps > 0);
+ memcpy( dest, source, n * comps * sizeof(GLchan) );
+ return;
+ }
+ }
+ /*
+ * Common situation, loading 8bit RGBA/RGB source images
+ * into 16/32 bit destination. (OSMesa16/32)
+ */
+ else if (srcType == GL_UNSIGNED_BYTE) {
+ if (dstFormat == GL_RGBA) {
+ if (srcFormat == GL_RGB) {
+ GLuint i;
+ const GLubyte *src = (const GLubyte *) source;
+ GLchan *dst = dest;
+ for (i = 0; i < n; i++) {
+ dst[0] = UBYTE_TO_CHAN(src[0]);
+ dst[1] = UBYTE_TO_CHAN(src[1]);
+ dst[2] = UBYTE_TO_CHAN(src[2]);
+ dst[3] = CHAN_MAX;
+ src += 3;
+ dst += 4;
+ }
+ return;
+ }
+ else if (srcFormat == GL_RGBA) {
+ GLuint i;
+ const GLubyte *src = (const GLubyte *) source;
+ GLchan *dst = dest;
+ for (i = 0; i < n; i++) {
+ dst[0] = UBYTE_TO_CHAN(src[0]);
+ dst[1] = UBYTE_TO_CHAN(src[1]);
+ dst[2] = UBYTE_TO_CHAN(src[2]);
+ dst[3] = UBYTE_TO_CHAN(src[3]);
+ src += 4;
+ dst += 4;
+ }
+ return;
+ }
+ }
+ else if (dstFormat == GL_RGB) {
+ if (srcFormat == GL_RGB) {
+ GLuint i;
+ const GLubyte *src = (const GLubyte *) source;
+ GLchan *dst = dest;
+ for (i = 0; i < n; i++) {
+ dst[0] = UBYTE_TO_CHAN(src[0]);
+ dst[1] = UBYTE_TO_CHAN(src[1]);
+ dst[2] = UBYTE_TO_CHAN(src[2]);
+ src += 3;
+ dst += 3;
+ }
+ return;
+ }
+ else if (srcFormat == GL_RGBA) {
+ GLuint i;
+ const GLubyte *src = (const GLubyte *) source;
+ GLchan *dst = dest;
+ for (i = 0; i < n; i++) {
+ dst[0] = UBYTE_TO_CHAN(src[0]);
+ dst[1] = UBYTE_TO_CHAN(src[1]);
+ dst[2] = UBYTE_TO_CHAN(src[2]);
+ src += 4;
+ dst += 3;
+ }
+ return;
+ }
+ }
+ }
+ }
+
+
+ /* general solution begins here */
+ {
+ GLint dstComponents;
+ GLint rDst, gDst, bDst, aDst, lDst, iDst;
+ GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * n * sizeof(GLfloat));
+
+ if (!rgba) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+ return;
+ }
+
+ dstComponents = _mesa_components_in_format( dstFormat );
+ /* source & dest image formats should have been error checked by now */
+ assert(dstComponents > 0);
+
+ /*
+ * Extract image data and convert to RGBA floats
+ */
+ if (srcFormat == GL_COLOR_INDEX) {
+ GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
+
+ if (!indexes) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+ return;
+ }
+
+ extract_uint_indexes(n, indexes, srcFormat, srcType, source,
+ srcPacking);
+
+ if (dstFormat == GL_COLOR_INDEX) {
+ GLuint i;
+ _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
+ /* convert to GLchan and return */
+ for (i = 0; i < n; i++) {
+ dest[i] = (GLchan) (indexes[i] & 0xff);
+ }
+ free(indexes);
+ free(rgba);
+ return;
+ }
+ else {
+ /* Convert indexes to RGBA */
+ if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
+ _mesa_shift_and_offset_ci(ctx, n, indexes);
+ }
+ _mesa_map_ci_to_rgba(ctx, n, indexes, rgba);
+ }
+
+ /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
+ * with color indexes.
+ */
+ transferOps &= ~(IMAGE_SCALE_BIAS_BIT | IMAGE_MAP_COLOR_BIT);
+
+ free(indexes);
+ }
+ else {
+ /* non-color index data */
+ extract_float_rgba(n, rgba, srcFormat, srcType, source,
+ srcPacking->SwapBytes);
+ }
+
+ /* Need to clamp if returning GLubytes or GLushorts */
+#if CHAN_TYPE != GL_FLOAT
+ transferOps |= IMAGE_CLAMP_BIT;
+#endif
+
+ if (transferOps) {
+ _mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
+ }
+
+ get_component_indexes(dstFormat,
+ &rDst, &gDst, &bDst, &aDst, &lDst, &iDst);
+
+ /* Now return the GLchan data in the requested dstFormat */
+ if (rDst >= 0) {
+ GLchan *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ CLAMPED_FLOAT_TO_CHAN(dst[rDst], rgba[i][RCOMP]);
+ dst += dstComponents;
+ }
+ }
+
+ if (gDst >= 0) {
+ GLchan *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ CLAMPED_FLOAT_TO_CHAN(dst[gDst], rgba[i][GCOMP]);
+ dst += dstComponents;
+ }
+ }
+
+ if (bDst >= 0) {
+ GLchan *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ CLAMPED_FLOAT_TO_CHAN(dst[bDst], rgba[i][BCOMP]);
+ dst += dstComponents;
+ }
+ }
+
+ if (aDst >= 0) {
+ GLchan *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ CLAMPED_FLOAT_TO_CHAN(dst[aDst], rgba[i][ACOMP]);
+ dst += dstComponents;
+ }
+ }
+
+ if (iDst >= 0) {
+ GLchan *dst = dest;
+ GLuint i;
+ assert(iDst == 0);
+ assert(dstComponents == 1);
+ for (i = 0; i < n; i++) {
+ /* Intensity comes from red channel */
+ CLAMPED_FLOAT_TO_CHAN(dst[i], rgba[i][RCOMP]);
+ }
+ }
+
+ if (lDst >= 0) {
+ GLchan *dst = dest;
+ GLuint i;
+ assert(lDst == 0);
+ for (i = 0; i < n; i++) {
+ /* Luminance comes from red channel */
+ CLAMPED_FLOAT_TO_CHAN(dst[0], rgba[i][RCOMP]);
+ dst += dstComponents;
+ }
+ }
+
+ free(rgba);
+ }
+}
+
+
+/**
+ * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
+ * instead of GLchan.
+ */
+void
+_mesa_unpack_color_span_float( struct gl_context *ctx,
+ GLuint n, GLenum dstFormat, GLfloat dest[],
+ GLenum srcFormat, GLenum srcType,
+ const GLvoid *source,
+ const struct gl_pixelstore_attrib *srcPacking,
+ GLbitfield transferOps )
+{
+ ASSERT(dstFormat == GL_ALPHA ||
+ dstFormat == GL_LUMINANCE ||
+ dstFormat == GL_LUMINANCE_ALPHA ||
+ dstFormat == GL_INTENSITY ||
+ dstFormat == GL_RED ||
+ dstFormat == GL_RG ||
+ dstFormat == GL_RGB ||
+ dstFormat == GL_RGBA ||
+ dstFormat == GL_COLOR_INDEX);
+
+ ASSERT(srcFormat == GL_RED ||
+ srcFormat == GL_GREEN ||
+ srcFormat == GL_BLUE ||
+ srcFormat == GL_ALPHA ||
+ srcFormat == GL_LUMINANCE ||
+ srcFormat == GL_LUMINANCE_ALPHA ||
+ srcFormat == GL_INTENSITY ||
+ srcFormat == GL_RG ||
+ srcFormat == GL_RGB ||
+ srcFormat == GL_BGR ||
+ srcFormat == GL_RGBA ||
+ srcFormat == GL_BGRA ||
+ srcFormat == GL_ABGR_EXT ||
+ srcFormat == GL_RED_INTEGER_EXT ||
+ srcFormat == GL_GREEN_INTEGER_EXT ||
+ srcFormat == GL_BLUE_INTEGER_EXT ||
+ srcFormat == GL_ALPHA_INTEGER_EXT ||
+ srcFormat == GL_RGB_INTEGER_EXT ||
+ srcFormat == GL_RGBA_INTEGER_EXT ||
+ srcFormat == GL_BGR_INTEGER_EXT ||
+ srcFormat == GL_BGRA_INTEGER_EXT ||
+ srcFormat == GL_LUMINANCE_INTEGER_EXT ||
+ srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT ||
+ srcFormat == GL_COLOR_INDEX);
+
+ ASSERT(srcType == GL_BITMAP ||
+ srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_BYTE ||
+ srcType == GL_UNSIGNED_SHORT ||
+ srcType == GL_SHORT ||
+ srcType == GL_UNSIGNED_INT ||
+ srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_ARB ||
+ srcType == GL_FLOAT ||
+ srcType == GL_UNSIGNED_BYTE_3_3_2 ||
+ srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
+ srcType == GL_UNSIGNED_SHORT_5_6_5 ||
+ srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
+ srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
+ srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8 ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
+ srcType == GL_UNSIGNED_INT_10_10_10_2 ||
+ srcType == GL_UNSIGNED_INT_2_10_10_10_REV ||
+ srcType == GL_UNSIGNED_INT_5_9_9_9_REV ||
+ srcType == GL_UNSIGNED_INT_10F_11F_11F_REV);
+
+ /* general solution, no special cases, yet */
+ {
+ GLint dstComponents;
+ GLint rDst, gDst, bDst, aDst, lDst, iDst;
+ GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * n * sizeof(GLfloat));
+
+ if (!rgba) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+ return;
+ }
+
+ dstComponents = _mesa_components_in_format( dstFormat );
+ /* source & dest image formats should have been error checked by now */
+ assert(dstComponents > 0);
+
+ /*
+ * Extract image data and convert to RGBA floats
+ */
+ if (srcFormat == GL_COLOR_INDEX) {
+ GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
+
+ if (!indexes) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+ free(rgba);
+ return;
+ }
+
+ extract_uint_indexes(n, indexes, srcFormat, srcType, source,
+ srcPacking);
+
+ if (dstFormat == GL_COLOR_INDEX) {
+ GLuint i;
+ _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
+ /* convert to GLchan and return */
+ for (i = 0; i < n; i++) {
+ dest[i] = (GLchan) (indexes[i] & 0xff);
+ }
+ free(indexes);
+ free(rgba);
+ return;
+ }
+ else {
+ /* Convert indexes to RGBA */
+ if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
+ _mesa_shift_and_offset_ci(ctx, n, indexes);
+ }
+ _mesa_map_ci_to_rgba(ctx, n, indexes, rgba);
+ }
+
+ /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
+ * with color indexes.
+ */
+ transferOps &= ~(IMAGE_SCALE_BIAS_BIT | IMAGE_MAP_COLOR_BIT);
+
+ free(indexes);
+ }
+ else {
+ /* non-color index data */
+ extract_float_rgba(n, rgba, srcFormat, srcType, source,
+ srcPacking->SwapBytes);
+ }
+
+ if (transferOps) {
+ _mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
+ }
+
+ get_component_indexes(dstFormat,
+ &rDst, &gDst, &bDst, &aDst, &lDst, &iDst);
+
+ /* Now pack results in the requested dstFormat */
+ if (rDst >= 0) {
+ GLfloat *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[rDst] = rgba[i][RCOMP];
+ dst += dstComponents;
+ }
+ }
+
+ if (gDst >= 0) {
+ GLfloat *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[gDst] = rgba[i][GCOMP];
+ dst += dstComponents;
+ }
+ }
+
+ if (bDst >= 0) {
+ GLfloat *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[bDst] = rgba[i][BCOMP];
+ dst += dstComponents;
+ }
+ }
+
+ if (aDst >= 0) {
+ GLfloat *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[aDst] = rgba[i][ACOMP];
+ dst += dstComponents;
+ }
+ }
+
+ if (iDst >= 0) {
+ GLfloat *dst = dest;
+ GLuint i;
+ assert(iDst == 0);
+ assert(dstComponents == 1);
+ for (i = 0; i < n; i++) {
+ /* Intensity comes from red channel */
+ dst[i] = rgba[i][RCOMP];
+ }
+ }
+
+ if (lDst >= 0) {
+ GLfloat *dst = dest;
+ GLuint i;
+ assert(lDst == 0);
+ for (i = 0; i < n; i++) {
+ /* Luminance comes from red channel */
+ dst[0] = rgba[i][RCOMP];
+ dst += dstComponents;
+ }
+ }
+
+ free(rgba);
+ }
+}
+
+
+/**
+ * Same as _mesa_unpack_color_span_chan(), but return GLuint data
+ * instead of GLchan.
+ * No pixel transfer ops are applied.
+ */
+void
+_mesa_unpack_color_span_uint(struct gl_context *ctx,
+ GLuint n, GLenum dstFormat, GLuint *dest,
+ GLenum srcFormat, GLenum srcType,
+ const GLvoid *source,
+ const struct gl_pixelstore_attrib *srcPacking)
+{
+ GLuint (*rgba)[4] = (GLuint (*)[4]) malloc(n * 4 * sizeof(GLfloat));
+
+ if (!rgba) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+ return;
+ }
+
+ ASSERT(dstFormat == GL_ALPHA ||
+ dstFormat == GL_LUMINANCE ||
+ dstFormat == GL_LUMINANCE_ALPHA ||
+ dstFormat == GL_INTENSITY ||
+ dstFormat == GL_RED ||
+ dstFormat == GL_RG ||
+ dstFormat == GL_RGB ||
+ dstFormat == GL_RGBA);
+
+ ASSERT(srcFormat == GL_RED ||
+ srcFormat == GL_GREEN ||
+ srcFormat == GL_BLUE ||
+ srcFormat == GL_ALPHA ||
+ srcFormat == GL_LUMINANCE ||
+ srcFormat == GL_LUMINANCE_ALPHA ||
+ srcFormat == GL_INTENSITY ||
+ srcFormat == GL_RG ||
+ srcFormat == GL_RGB ||
+ srcFormat == GL_BGR ||
+ srcFormat == GL_RGBA ||
+ srcFormat == GL_BGRA ||
+ srcFormat == GL_ABGR_EXT ||
+ srcFormat == GL_RED_INTEGER_EXT ||
+ srcFormat == GL_GREEN_INTEGER_EXT ||
+ srcFormat == GL_BLUE_INTEGER_EXT ||
+ srcFormat == GL_ALPHA_INTEGER_EXT ||
+ srcFormat == GL_RGB_INTEGER_EXT ||
+ srcFormat == GL_RGBA_INTEGER_EXT ||
+ srcFormat == GL_BGR_INTEGER_EXT ||
+ srcFormat == GL_BGRA_INTEGER_EXT ||
+ srcFormat == GL_LUMINANCE_INTEGER_EXT ||
+ srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT);
+
+ ASSERT(srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_BYTE ||
+ srcType == GL_UNSIGNED_SHORT ||
+ srcType == GL_SHORT ||
+ srcType == GL_UNSIGNED_INT ||
+ srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_ARB ||
+ srcType == GL_FLOAT ||
+ srcType == GL_UNSIGNED_BYTE_3_3_2 ||
+ srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
+ srcType == GL_UNSIGNED_SHORT_5_6_5 ||
+ srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
+ srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
+ srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
+ srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8 ||
+ srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
+ srcType == GL_UNSIGNED_INT_10_10_10_2 ||
+ srcType == GL_UNSIGNED_INT_2_10_10_10_REV ||
+ srcType == GL_UNSIGNED_INT_5_9_9_9_REV ||
+ srcType == GL_UNSIGNED_INT_10F_11F_11F_REV);
+
+
+ /* Extract image data as uint[4] pixels */
+ extract_uint_rgba(n, rgba, srcFormat, srcType, source,
+ srcPacking->SwapBytes);
+
+ if (dstFormat == GL_RGBA) {
+ /* simple case */
+ memcpy(dest, rgba, 4 * sizeof(GLuint) * n);
+ }
+ else {
+ /* general case */
+ GLint rDst, gDst, bDst, aDst, lDst, iDst;
+ GLint dstComponents = _mesa_components_in_format( dstFormat );
+
+ assert(dstComponents > 0);
+
+ get_component_indexes(dstFormat,
+ &rDst, &gDst, &bDst, &aDst, &lDst, &iDst);
+
+ /* Now pack values in the requested dest format */
+ if (rDst >= 0) {
+ GLuint *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[rDst] = rgba[i][RCOMP];
+ dst += dstComponents;
+ }
+ }
+
+ if (gDst >= 0) {
+ GLuint *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[gDst] = rgba[i][GCOMP];
+ dst += dstComponents;
+ }
+ }
+
+ if (bDst >= 0) {
+ GLuint *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[bDst] = rgba[i][BCOMP];
+ dst += dstComponents;
+ }
+ }
+
+ if (aDst >= 0) {
+ GLuint *dst = dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[aDst] = rgba[i][ACOMP];
+ dst += dstComponents;
+ }
+ }
+
+ if (iDst >= 0) {
+ GLuint *dst = dest;
+ GLuint i;
+ assert(iDst == 0);
+ assert(dstComponents == 1);
+ for (i = 0; i < n; i++) {
+ /* Intensity comes from red channel */
+ dst[i] = rgba[i][RCOMP];
+ }
+ }
+
+ if (lDst >= 0) {
+ GLuint *dst = dest;
+ GLuint i;
+ assert(lDst == 0);
+ for (i = 0; i < n; i++) {
+ /* Luminance comes from red channel */
+ dst[0] = rgba[i][RCOMP];
+ dst += dstComponents;
+ }
+ }
+ }
+
+ free(rgba);
+}
+
+
+
+/**
+ * Similar to _mesa_unpack_color_span_float(), but for dudv data instead of rgba,
+ * directly return GLbyte data, no transfer ops apply.
+ */
+void
+_mesa_unpack_dudv_span_byte( struct gl_context *ctx,
+ GLuint n, GLenum dstFormat, GLbyte dest[],
+ GLenum srcFormat, GLenum srcType,
+ const GLvoid *source,
+ const struct gl_pixelstore_attrib *srcPacking,
+ GLbitfield transferOps )
+{
+ ASSERT(dstFormat == GL_DUDV_ATI);
+ ASSERT(srcFormat == GL_DUDV_ATI ||
+ srcFormat == GL_DU8DV8_ATI);
+
+ ASSERT(srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_BYTE ||
+ srcType == GL_UNSIGNED_SHORT ||
+ srcType == GL_SHORT ||
+ srcType == GL_UNSIGNED_INT ||
+ srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_ARB ||
+ srcType == GL_FLOAT);
+
+ /* general solution */
+ {
+ GLint dstComponents;
+ GLbyte *dst = dest;
+ GLuint i;
+ GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * n * sizeof(GLfloat));
+
+ if (!rgba) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+ return;
+ }
+
+ dstComponents = _mesa_components_in_format( dstFormat );
+ /* source & dest image formats should have been error checked by now */
+ assert(dstComponents > 0);
+
+ /*
+ * Extract image data and convert to RGBA floats
+ */
+ extract_float_rgba(n, rgba, srcFormat, srcType, source,
+ srcPacking->SwapBytes);
+
+
+ /* Now determine which color channels we need to produce.
+ * And determine the dest index (offset) within each color tuple.
+ */
+
+ /* Now pack results in the requested dstFormat */
+ for (i = 0; i < n; i++) {
+ /* not sure - need clamp[-1,1] here? */
+ dst[0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
+ dst[1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
+ dst += dstComponents;
+ }
+
+ free(rgba);
+ }
+}
+
+/*
+ * Unpack a row of color index data from a client buffer according to
+ * the pixel unpacking parameters.
+ * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
+ *
+ * Args: ctx - the context
+ * n - number of pixels
+ * dstType - destination data type
+ * dest - destination array
+ * srcType - source pixel type
+ * source - source data pointer
+ * srcPacking - pixel unpacking parameters
+ * transferOps - the pixel transfer operations to apply
+ */
+void
+_mesa_unpack_index_span( struct gl_context *ctx, GLuint n,
+ GLenum dstType, GLvoid *dest,
+ GLenum srcType, const GLvoid *source,
+ const struct gl_pixelstore_attrib *srcPacking,
+ GLbitfield transferOps )
+{
+ ASSERT(srcType == GL_BITMAP ||
+ srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_BYTE ||
+ srcType == GL_UNSIGNED_SHORT ||
+ srcType == GL_SHORT ||
+ srcType == GL_UNSIGNED_INT ||
+ srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_ARB ||
+ srcType == GL_FLOAT);
+
+ ASSERT(dstType == GL_UNSIGNED_BYTE ||
+ dstType == GL_UNSIGNED_SHORT ||
+ dstType == GL_UNSIGNED_INT);
+
+
+ transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT);
+
+ /*
+ * Try simple cases first
+ */
+ if (transferOps == 0 && srcType == GL_UNSIGNED_BYTE
+ && dstType == GL_UNSIGNED_BYTE) {
+ memcpy(dest, source, n * sizeof(GLubyte));
+ }
+ else if (transferOps == 0 && srcType == GL_UNSIGNED_INT
+ && dstType == GL_UNSIGNED_INT && !srcPacking->SwapBytes) {
+ memcpy(dest, source, n * sizeof(GLuint));
+ }
+ else {
+ /*
+ * general solution
+ */
+ GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
+
+ if (!indexes) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+ return;
+ }
+
+ extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source,
+ srcPacking);
+
+ if (transferOps)
+ _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
+
+ /* convert to dest type */
+ switch (dstType) {
+ case GL_UNSIGNED_BYTE:
+ {
+ GLubyte *dst = (GLubyte *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (GLubyte) (indexes[i] & 0xff);
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT:
+ {
+ GLuint *dst = (GLuint *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (GLushort) (indexes[i] & 0xffff);
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT:
+ memcpy(dest, indexes, n * sizeof(GLuint));
+ break;
+ default:
+ _mesa_problem(ctx, "bad dstType in _mesa_unpack_index_span");
+ }
+
+ free(indexes);
+ }
+}
+
+
+void
+_mesa_pack_index_span( struct gl_context *ctx, GLuint n,
+ GLenum dstType, GLvoid *dest, const GLuint *source,
+ const struct gl_pixelstore_attrib *dstPacking,
+ GLbitfield transferOps )
+{
+ GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
+
+ if (!indexes) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
+ return;
+ }
+
+ transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT);
+
+ if (transferOps & (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT)) {
+ /* make a copy of input */
+ memcpy(indexes, source, n * sizeof(GLuint));
+ _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
+ source = indexes;
+ }
+
+ switch (dstType) {
+ case GL_UNSIGNED_BYTE:
+ {
+ GLubyte *dst = (GLubyte *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ *dst++ = (GLubyte) source[i];
+ }
+ }
+ break;
+ case GL_BYTE:
+ {
+ GLbyte *dst = (GLbyte *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (GLbyte) source[i];
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT:
+ {
+ GLushort *dst = (GLushort *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (GLushort) source[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
+ case GL_SHORT:
+ {
+ GLshort *dst = (GLshort *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (GLshort) source[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT:
+ {
+ GLuint *dst = (GLuint *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (GLuint) source[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4( (GLuint *) dst, n );
+ }
+ }
+ break;
+ case GL_INT:
+ {
+ GLint *dst = (GLint *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (GLint) source[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4( (GLuint *) dst, n );
+ }
+ }
+ break;
+ case GL_FLOAT:
+ {
+ GLfloat *dst = (GLfloat *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (GLfloat) source[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4( (GLuint *) dst, n );
+ }
+ }
+ break;
+ case GL_HALF_FLOAT_ARB:
+ {
+ GLhalfARB *dst = (GLhalfARB *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = _mesa_float_to_half((GLfloat) source[i]);
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad type in _mesa_pack_index_span");
+ }
+
+ free(indexes);
+}
+
+
+/*
+ * Unpack a row of stencil data from a client buffer according to
+ * the pixel unpacking parameters.
+ * This is (or will be) used by glDrawPixels
+ *
+ * Args: ctx - the context
+ * n - number of pixels
+ * dstType - destination data type
+ * dest - destination array
+ * srcType - source pixel type
+ * source - source data pointer
+ * srcPacking - pixel unpacking parameters
+ * transferOps - apply offset/bias/lookup ops?
+ */
+void
+_mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
+ GLenum dstType, GLvoid *dest,
+ GLenum srcType, const GLvoid *source,
+ const struct gl_pixelstore_attrib *srcPacking,
+ GLbitfield transferOps )
+{
+ ASSERT(srcType == GL_BITMAP ||
+ srcType == GL_UNSIGNED_BYTE ||
+ srcType == GL_BYTE ||
+ srcType == GL_UNSIGNED_SHORT ||
+ srcType == GL_SHORT ||
+ srcType == GL_UNSIGNED_INT ||
+ srcType == GL_INT ||
+ srcType == GL_UNSIGNED_INT_24_8_EXT ||
+ srcType == GL_HALF_FLOAT_ARB ||
+ srcType == GL_FLOAT);
+
+ ASSERT(dstType == GL_UNSIGNED_BYTE ||
+ dstType == GL_UNSIGNED_SHORT ||
+ dstType == GL_UNSIGNED_INT);
+
+ /* only shift and offset apply to stencil */
+ transferOps &= IMAGE_SHIFT_OFFSET_BIT;
+
+ /*
+ * Try simple cases first
+ */
+ if (transferOps == 0 &&
+ !ctx->Pixel.MapStencilFlag &&
+ srcType == GL_UNSIGNED_BYTE &&
+ dstType == GL_UNSIGNED_BYTE) {
+ memcpy(dest, source, n * sizeof(GLubyte));
+ }
+ else if (transferOps == 0 &&
+ !ctx->Pixel.MapStencilFlag &&
+ srcType == GL_UNSIGNED_INT &&
+ dstType == GL_UNSIGNED_INT &&
+ !srcPacking->SwapBytes) {
+ memcpy(dest, source, n * sizeof(GLuint));
+ }
+ else {
+ /*
+ * general solution
+ */
+ GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
+
+ if (!indexes) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "stencil unpacking");
+ return;
+ }
+
+ extract_uint_indexes(n, indexes, GL_STENCIL_INDEX, srcType, source,
+ srcPacking);
+
+ if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
+ /* shift and offset indexes */
+ _mesa_shift_and_offset_ci(ctx, n, indexes);
+ }
+
+ if (ctx->Pixel.MapStencilFlag) {
+ /* Apply stencil lookup table */
+ const GLuint mask = ctx->PixelMaps.StoS.Size - 1;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ indexes[i] = (GLuint)ctx->PixelMaps.StoS.Map[ indexes[i] & mask ];
+ }
+ }
+
+ /* convert to dest type */
+ switch (dstType) {
+ case GL_UNSIGNED_BYTE:
+ {
+ GLubyte *dst = (GLubyte *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (GLubyte) (indexes[i] & 0xff);
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT:
+ {
+ GLuint *dst = (GLuint *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = (GLushort) (indexes[i] & 0xffff);
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT:
+ memcpy(dest, indexes, n * sizeof(GLuint));
+ break;
+ default:
+ _mesa_problem(ctx, "bad dstType in _mesa_unpack_stencil_span");
+ }
+
+ free(indexes);
+ }
+}
+
+
+void
+_mesa_pack_stencil_span( struct gl_context *ctx, GLuint n,
+ GLenum dstType, GLvoid *dest, const GLstencil *source,
+ const struct gl_pixelstore_attrib *dstPacking )
+{
+ GLstencil *stencil = (GLstencil *) malloc(n * sizeof(GLstencil));
+
+ if (!stencil) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "stencil packing");
+ return;
+ }
+
+ if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset ||
+ ctx->Pixel.MapStencilFlag) {
+ /* make a copy of input */
+ memcpy(stencil, source, n * sizeof(GLstencil));
+ _mesa_apply_stencil_transfer_ops(ctx, n, stencil);
+ source = stencil;
+ }
+
+ switch (dstType) {
+ case GL_UNSIGNED_BYTE:
+ if (sizeof(GLstencil) == 1) {
+ memcpy( dest, source, n );
+ }
+ else {
+ GLubyte *dst = (GLubyte *) dest;
+ GLuint i;
+ for (i=0;i<n;i++) {
+ dst[i] = (GLubyte) source[i];
+ }
+ }
+ break;
+ case GL_BYTE:
+ {
+ GLbyte *dst = (GLbyte *) dest;
+ GLuint i;
+ for (i=0;i<n;i++) {
+ dst[i] = (GLbyte) (source[i] & 0x7f);
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT:
+ {
+ GLushort *dst = (GLushort *) dest;
+ GLuint i;
+ for (i=0;i<n;i++) {
+ dst[i] = (GLushort) source[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
+ case GL_SHORT:
+ {
+ GLshort *dst = (GLshort *) dest;
+ GLuint i;
+ for (i=0;i<n;i++) {
+ dst[i] = (GLshort) source[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT:
+ {
+ GLuint *dst = (GLuint *) dest;
+ GLuint i;
+ for (i=0;i<n;i++) {
+ dst[i] = (GLuint) source[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4( (GLuint *) dst, n );
+ }
+ }
+ break;
+ case GL_INT:
+ {
+ GLint *dst = (GLint *) dest;
+ GLuint i;
+ for (i=0;i<n;i++) {
+ dst[i] = (GLint) source[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4( (GLuint *) dst, n );
+ }
+ }
+ break;
+ case GL_FLOAT:
+ {
+ GLfloat *dst = (GLfloat *) dest;
+ GLuint i;
+ for (i=0;i<n;i++) {
+ dst[i] = (GLfloat) source[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4( (GLuint *) dst, n );
+ }
+ }
+ break;
+ case GL_HALF_FLOAT_ARB:
+ {
+ GLhalfARB *dst = (GLhalfARB *) dest;
+ GLuint i;
+ for (i=0;i<n;i++) {
+ dst[i] = _mesa_float_to_half( (float) source[i] );
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
+ case GL_BITMAP:
+ if (dstPacking->LsbFirst) {
+ GLubyte *dst = (GLubyte *) dest;
+ GLint shift = 0;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ if (shift == 0)
+ *dst = 0;
+ *dst |= ((source[i] != 0) << shift);
+ shift++;
+ if (shift == 8) {
+ shift = 0;
+ dst++;
+ }
+ }
+ }
+ else {
+ GLubyte *dst = (GLubyte *) dest;
+ GLint shift = 7;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ if (shift == 7)
+ *dst = 0;
+ *dst |= ((source[i] != 0) << shift);
+ shift--;
+ if (shift < 0) {
+ shift = 7;
+ dst++;
+ }
+ }
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad type in _mesa_pack_index_span");
+ }
+
+ free(stencil);
+}
+
+#define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
+ do { \
+ GLuint i; \
+ const GLTYPE *src = (const GLTYPE *)source; \
+ for (i = 0; i < n; i++) { \
+ GLTYPE value = src[i]; \
+ if (srcPacking->SwapBytes) { \
+ if (sizeof(GLTYPE) == 2) { \
+ SWAP2BYTE(value); \
+ } else if (sizeof(GLTYPE) == 4) { \
+ SWAP4BYTE(value); \
+ } \
+ } \
+ depthValues[i] = GLTYPE2FLOAT(value); \
+ } \
+ } while (0)
+
+
+/**
+ * Unpack a row of depth/z values from memory, returning GLushort, GLuint
+ * or GLfloat values.
+ * The glPixelTransfer (scale/bias) params will be applied.
+ *
+ * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
+ * \param depthMax max value for returned GLushort or GLuint values
+ * (ignored for GLfloat).
+ */
+void
+_mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
+ GLenum dstType, GLvoid *dest, GLuint depthMax,
+ GLenum srcType, const GLvoid *source,
+ const struct gl_pixelstore_attrib *srcPacking )
+{
+ GLfloat *depthTemp, *depthValues;
+ GLboolean needClamp = GL_FALSE;
+
+ /* Look for special cases first.
+ * Not only are these faster, they're less prone to numeric conversion
+ * problems. Otherwise, converting from an int type to a float then
+ * back to an int type can introduce errors that will show up as
+ * artifacts in things like depth peeling which uses glCopyTexImage.
+ */
+ if (ctx->Pixel.DepthScale == 1.0 && ctx->Pixel.DepthBias == 0.0) {
+ if (srcType == GL_UNSIGNED_INT && dstType == GL_UNSIGNED_SHORT) {
+ const GLuint *src = (const GLuint *) source;
+ GLushort *dst = (GLushort *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = src[i] >> 16;
+ }
+ return;
+ }
+ if (srcType == GL_UNSIGNED_SHORT
+ && dstType == GL_UNSIGNED_INT
+ && depthMax == 0xffffffff) {
+ const GLushort *src = (const GLushort *) source;
+ GLuint *dst = (GLuint *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = src[i] | (src[i] << 16);
+ }
+ return;
+ }
+ if (srcType == GL_UNSIGNED_INT_24_8
+ && dstType == GL_UNSIGNED_INT
+ && depthMax == 0xffffff) {
+ const GLuint *src = (const GLuint *) source;
+ GLuint *dst = (GLuint *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = src[i] >> 8;
+ }
+ return;
+ }
+ /* XXX may want to add additional cases here someday */
+ }
+
+ /* general case path follows */
+
+ depthTemp = (GLfloat *) malloc(n * sizeof(GLfloat));
+ if (!depthTemp) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+ return;
+ }
+
+ if (dstType == GL_FLOAT) {
+ depthValues = (GLfloat *) dest;
+ }
+ else {
+ depthValues = depthTemp;
+ }
+
+ /* Convert incoming values to GLfloat. Some conversions will require
+ * clamping, below.
+ */
+ switch (srcType) {
+ case GL_BYTE:
+ DEPTH_VALUES(GLbyte, BYTE_TO_FLOAT);
+ needClamp = GL_TRUE;
+ break;
+ case GL_UNSIGNED_BYTE:
+ DEPTH_VALUES(GLubyte, UBYTE_TO_FLOAT);
+ break;
+ case GL_SHORT:
+ DEPTH_VALUES(GLshort, SHORT_TO_FLOAT);
+ needClamp = GL_TRUE;
+ break;
+ case GL_UNSIGNED_SHORT:
+ DEPTH_VALUES(GLushort, USHORT_TO_FLOAT);
+ break;
+ case GL_INT:
+ DEPTH_VALUES(GLint, INT_TO_FLOAT);
+ needClamp = GL_TRUE;
+ break;
+ case GL_UNSIGNED_INT:
+ DEPTH_VALUES(GLuint, UINT_TO_FLOAT);
+ break;
+ case GL_UNSIGNED_INT_24_8_EXT: /* GL_EXT_packed_depth_stencil */
+ if (dstType == GL_UNSIGNED_INT_24_8_EXT &&
+ depthMax == 0xffffff &&
+ ctx->Pixel.DepthScale == 1.0 &&
+ ctx->Pixel.DepthBias == 0.0) {
+ const GLuint *src = (const GLuint *) source;
+ GLuint *zValues = (GLuint *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLuint value = src[i];
+ if (srcPacking->SwapBytes) {
+ SWAP4BYTE(value);
+ }
+ zValues[i] = value & 0xffffff00;
+ }
+ return;
+ }
+ else {
+ const GLuint *src = (const GLuint *) source;
+ const GLfloat scale = 1.0f / 0xffffff;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLuint value = src[i];
+ if (srcPacking->SwapBytes) {
+ SWAP4BYTE(value);
+ }
+ depthValues[i] = (value >> 8) * scale;
+ }
+ }
+ break;
+ case GL_FLOAT:
+ DEPTH_VALUES(GLfloat, 1*);
+ needClamp = GL_TRUE;
+ break;
+ case GL_HALF_FLOAT_ARB:
+ {
+ GLuint i;
+ const GLhalfARB *src = (const GLhalfARB *) source;
+ for (i = 0; i < n; i++) {
+ GLhalfARB value = src[i];
+ if (srcPacking->SwapBytes) {
+ SWAP2BYTE(value);
+ }
+ depthValues[i] = _mesa_half_to_float(value);
+ }
+ needClamp = GL_TRUE;
+ }
+ break;
+ default:
+ _mesa_problem(NULL, "bad type in _mesa_unpack_depth_span()");
+ free(depthTemp);
+ return;
+ }
+
+ /* apply depth scale and bias */
+ {
+ const GLfloat scale = ctx->Pixel.DepthScale;
+ const GLfloat bias = ctx->Pixel.DepthBias;
+ if (scale != 1.0 || bias != 0.0) {
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ depthValues[i] = depthValues[i] * scale + bias;
+ }
+ needClamp = GL_TRUE;
+ }
+ }
+
+ /* clamp to [0, 1] */
+ if (needClamp) {
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ depthValues[i] = (GLfloat)CLAMP(depthValues[i], 0.0, 1.0);
+ }
+ }
+
+ /*
+ * Convert values to dstType
+ */
+ if (dstType == GL_UNSIGNED_INT) {
+ GLuint *zValues = (GLuint *) dest;
+ GLuint i;
+ if (depthMax <= 0xffffff) {
+ /* no overflow worries */
+ for (i = 0; i < n; i++) {
+ zValues[i] = (GLuint) (depthValues[i] * (GLfloat) depthMax);
+ }
+ }
+ else {
+ /* need to use double precision to prevent overflow problems */
+ for (i = 0; i < n; i++) {
+ GLdouble z = depthValues[i] * (GLfloat) depthMax;
+ if (z >= (GLdouble) 0xffffffff)
+ zValues[i] = 0xffffffff;
+ else
+ zValues[i] = (GLuint) z;
+ }
+ }
+ }
+ else if (dstType == GL_UNSIGNED_SHORT) {
+ GLushort *zValues = (GLushort *) dest;
+ GLuint i;
+ ASSERT(depthMax <= 0xffff);
+ for (i = 0; i < n; i++) {
+ zValues[i] = (GLushort) (depthValues[i] * (GLfloat) depthMax);
+ }
+ }
+ else {
+ ASSERT(dstType == GL_FLOAT);
+ /*ASSERT(depthMax == 1.0F);*/
+ }
+
+ free(depthTemp);
+}
+
+
+/*
+ * Pack an array of depth values. The values are floats in [0,1].
+ */
+void
+_mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
+ GLenum dstType, const GLfloat *depthSpan,
+ const struct gl_pixelstore_attrib *dstPacking )
+{
+ GLfloat *depthCopy = (GLfloat *) malloc(n * sizeof(GLfloat));
+ if (!depthCopy) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
+ return;
+ }
+
+ if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
+ memcpy(depthCopy, depthSpan, n * sizeof(GLfloat));
+ _mesa_scale_and_bias_depth(ctx, n, depthCopy);
+ depthSpan = depthCopy;
+ }
+
+ switch (dstType) {
+ case GL_UNSIGNED_BYTE:
+ {
+ GLubyte *dst = (GLubyte *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = FLOAT_TO_UBYTE( depthSpan[i] );
+ }
+ }
+ break;
+ case GL_BYTE:
+ {
+ GLbyte *dst = (GLbyte *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = FLOAT_TO_BYTE( depthSpan[i] );
+ }
+ }
+ break;
+ case GL_UNSIGNED_SHORT:
+ {
+ GLushort *dst = (GLushort *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ CLAMPED_FLOAT_TO_USHORT(dst[i], depthSpan[i]);
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
+ case GL_SHORT:
+ {
+ GLshort *dst = (GLshort *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = FLOAT_TO_SHORT( depthSpan[i] );
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
+ case GL_UNSIGNED_INT:
+ {
+ GLuint *dst = (GLuint *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = FLOAT_TO_UINT( depthSpan[i] );
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4( (GLuint *) dst, n );
+ }
+ }
+ break;
+ case GL_INT:
+ {
+ GLint *dst = (GLint *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = FLOAT_TO_INT( depthSpan[i] );
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4( (GLuint *) dst, n );
+ }
+ }
+ break;
+ case GL_FLOAT:
+ {
+ GLfloat *dst = (GLfloat *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = depthSpan[i];
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4( (GLuint *) dst, n );
+ }
+ }
+ break;
+ case GL_HALF_FLOAT_ARB:
+ {
+ GLhalfARB *dst = (GLhalfARB *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = _mesa_float_to_half(depthSpan[i]);
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad type in _mesa_pack_depth_span");
+ }
+
+ free(depthCopy);
+}
+
+
+
+/**
+ * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
+ */
+void
+_mesa_pack_depth_stencil_span(struct gl_context *ctx, GLuint n, GLuint *dest,
+ const GLfloat *depthVals,
+ const GLstencil *stencilVals,
+ const struct gl_pixelstore_attrib *dstPacking)
+{
+ GLfloat *depthCopy = (GLfloat *) malloc(n * sizeof(GLfloat));
+ GLstencil *stencilCopy = (GLstencil *) malloc(n * sizeof(GLstencil));
+ GLuint i;
+
+ if (!depthCopy || !stencilCopy) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
+ free(depthCopy);
+ free(stencilCopy);
+ return;
+ }
+
+ if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
+ memcpy(depthCopy, depthVals, n * sizeof(GLfloat));
+ _mesa_scale_and_bias_depth(ctx, n, depthCopy);
+ depthVals = depthCopy;
+ }
+
+ if (ctx->Pixel.IndexShift ||
+ ctx->Pixel.IndexOffset ||
+ ctx->Pixel.MapStencilFlag) {
+ memcpy(stencilCopy, stencilVals, n * sizeof(GLstencil));
+ _mesa_apply_stencil_transfer_ops(ctx, n, stencilCopy);
+ stencilVals = stencilCopy;
+ }
+
+ for (i = 0; i < n; i++) {
+ GLuint z = (GLuint) (depthVals[i] * 0xffffff);
+ dest[i] = (z << 8) | (stencilVals[i] & 0xff);
+ }
+
+ if (dstPacking->SwapBytes) {
+ _mesa_swap4(dest, n);
+ }
+
+ free(depthCopy);
+ free(stencilCopy);
+}
+
+
+
+
+/**
+ * Unpack image data. Apply byte swapping, byte flipping (bitmap).
+ * Return all image data in a contiguous block. This is used when we
+ * compile glDrawPixels, glTexImage, etc into a display list. We
+ * need a copy of the data in a standard format.
+ */
+void *
+_mesa_unpack_image( GLuint dimensions,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, const GLvoid *pixels,
+ const struct gl_pixelstore_attrib *unpack )
+{
+ GLint bytesPerRow, compsPerRow;
+ GLboolean flipBytes, swap2, swap4;
+
+ if (!pixels)
+ return NULL; /* not necessarily an error */
+
+ if (width <= 0 || height <= 0 || depth <= 0)
+ return NULL; /* generate error later */
+
+ if (type == GL_BITMAP) {
+ bytesPerRow = (width + 7) >> 3;
+ flipBytes = unpack->LsbFirst;
+ swap2 = swap4 = GL_FALSE;
+ compsPerRow = 0;
+ }
+ else {
+ const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
+ GLint components = _mesa_components_in_format(format);
+ GLint bytesPerComp;
+
+ if (_mesa_type_is_packed(type))
+ components = 1;
+
+ if (bytesPerPixel <= 0 || components <= 0)
+ return NULL; /* bad format or type. generate error later */
+ bytesPerRow = bytesPerPixel * width;
+ bytesPerComp = bytesPerPixel / components;
+ flipBytes = GL_FALSE;
+ swap2 = (bytesPerComp == 2) && unpack->SwapBytes;
+ swap4 = (bytesPerComp == 4) && unpack->SwapBytes;
+ compsPerRow = components * width;
+ assert(compsPerRow >= width);
+ }
+
+ {
+ GLubyte *destBuffer
+ = (GLubyte *) malloc(bytesPerRow * height * depth);
+ GLubyte *dst;
+ GLint img, row;
+ if (!destBuffer)
+ return NULL; /* generate GL_OUT_OF_MEMORY later */
+
+ dst = destBuffer;
+ for (img = 0; img < depth; img++) {
+ for (row = 0; row < height; row++) {
+ const GLvoid *src = _mesa_image_address(dimensions, unpack, pixels,
+ width, height, format, type, img, row, 0);
+
+ if ((type == GL_BITMAP) && (unpack->SkipPixels & 0x7)) {
+ GLint i;
+ flipBytes = GL_FALSE;
+ if (unpack->LsbFirst) {
+ GLubyte srcMask = 1 << (unpack->SkipPixels & 0x7);
+ GLubyte dstMask = 128;
+ const GLubyte *s = src;
+ GLubyte *d = dst;
+ *d = 0;
+ for (i = 0; i < width; i++) {
+ if (*s & srcMask) {
+ *d |= dstMask;
+ }
+ if (srcMask == 128) {
+ srcMask = 1;
+ s++;
+ }
+ else {
+ srcMask = srcMask << 1;
+ }
+ if (dstMask == 1) {
+ dstMask = 128;
+ d++;
+ *d = 0;
+ }
+ else {
+ dstMask = dstMask >> 1;
+ }
+ }
+ }
+ else {
+ GLubyte srcMask = 128 >> (unpack->SkipPixels & 0x7);
+ GLubyte dstMask = 128;
+ const GLubyte *s = src;
+ GLubyte *d = dst;
+ *d = 0;
+ for (i = 0; i < width; i++) {
+ if (*s & srcMask) {
+ *d |= dstMask;
+ }
+ if (srcMask == 1) {
+ srcMask = 128;
+ s++;
+ }
+ else {
+ srcMask = srcMask >> 1;
+ }
+ if (dstMask == 1) {
+ dstMask = 128;
+ d++;
+ *d = 0;
+ }
+ else {
+ dstMask = dstMask >> 1;
+ }
+ }
+ }
+ }
+ else {
+ memcpy(dst, src, bytesPerRow);
+ }
+
+ /* byte flipping/swapping */
+ if (flipBytes) {
+ flip_bytes((GLubyte *) dst, bytesPerRow);
+ }
+ else if (swap2) {
+ _mesa_swap2((GLushort*) dst, compsPerRow);
+ }
+ else if (swap4) {
+ _mesa_swap4((GLuint*) dst, compsPerRow);
+ }
+ dst += bytesPerRow;
+ }
+ }
+ return destBuffer;
+ }
+}
+
diff --git a/mesalib/src/mesa/main/texfetch.c b/mesalib/src/mesa/main/texfetch.c
index d091789ff..ab3abf657 100644
--- a/mesalib/src/mesa/main/texfetch.c
+++ b/mesalib/src/mesa/main/texfetch.c
@@ -1,1034 +1,1050 @@
-/*
- * 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
- },
- {
- MESA_FORMAT_R_FLOAT32,
- fetch_texel_1d_f_r_f32,
- fetch_texel_2d_f_r_f32,
- fetch_texel_3d_f_r_f32,
- store_texel_r_f32
- },
- {
- MESA_FORMAT_R_FLOAT16,
- fetch_texel_1d_f_r_f16,
- fetch_texel_2d_f_r_f16,
- fetch_texel_3d_f_r_f16,
- store_texel_r_f16
- },
- {
- MESA_FORMAT_RG_FLOAT32,
- fetch_texel_1d_f_rg_f32,
- fetch_texel_2d_f_rg_f32,
- fetch_texel_3d_f_rg_f32,
- store_texel_rg_f32
- },
- {
- MESA_FORMAT_RG_FLOAT16,
- fetch_texel_1d_f_rg_f16,
- fetch_texel_2d_f_rg_f16,
- fetch_texel_3d_f_rg_f16,
- store_texel_rg_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_REV,
- fetch_texel_1d_signed_rg88_rev,
- fetch_texel_2d_signed_rg88_rev,
- fetch_texel_3d_signed_rg88_rev,
- store_texel_signed_rg88_rev
- },
- {
- 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_R16,
- fetch_texel_1d_signed_r16,
- fetch_texel_2d_signed_r16,
- fetch_texel_3d_signed_r16,
- store_texel_signed_r16
- },
- {
- MESA_FORMAT_SIGNED_GR1616,
- fetch_texel_1d_signed_rg1616,
- fetch_texel_2d_signed_rg1616,
- fetch_texel_3d_signed_rg1616,
- store_texel_signed_rg1616
- },
- {
- 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
- },
- {
- MESA_FORMAT_L_LATC1,
- NULL,
- _mesa_fetch_texel_2d_f_l_latc1,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_SIGNED_L_LATC1,
- NULL,
- _mesa_fetch_texel_2d_f_signed_l_latc1,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_LA_LATC2,
- NULL,
- _mesa_fetch_texel_2d_f_la_latc2,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_SIGNED_LA_LATC2,
- NULL,
- _mesa_fetch_texel_2d_f_signed_la_latc2,
- NULL,
- NULL
- },
- {
- MESA_FORMAT_SIGNED_A8,
- fetch_texel_1d_signed_a8,
- fetch_texel_2d_signed_a8,
- fetch_texel_3d_signed_a8,
- store_texel_signed_a8
- },
- {
- MESA_FORMAT_SIGNED_L8,
- fetch_texel_1d_signed_l8,
- fetch_texel_2d_signed_l8,
- fetch_texel_3d_signed_l8,
- store_texel_signed_l8
- },
- {
- MESA_FORMAT_SIGNED_AL88,
- fetch_texel_1d_signed_al88,
- fetch_texel_2d_signed_al88,
- fetch_texel_3d_signed_al88,
- store_texel_signed_al88
- },
- {
- MESA_FORMAT_SIGNED_I8,
- fetch_texel_1d_signed_i8,
- fetch_texel_2d_signed_i8,
- fetch_texel_3d_signed_i8,
- store_texel_signed_i8
- },
- {
- MESA_FORMAT_SIGNED_A16,
- fetch_texel_1d_signed_a16,
- fetch_texel_2d_signed_a16,
- fetch_texel_3d_signed_a16,
- store_texel_signed_a16
- },
- {
- MESA_FORMAT_SIGNED_L16,
- fetch_texel_1d_signed_l16,
- fetch_texel_2d_signed_l16,
- fetch_texel_3d_signed_l16,
- store_texel_signed_l16
- },
- {
- MESA_FORMAT_SIGNED_AL1616,
- fetch_texel_1d_signed_al1616,
- fetch_texel_2d_signed_al1616,
- fetch_texel_3d_signed_al1616,
- store_texel_signed_al1616
- },
- {
- MESA_FORMAT_SIGNED_I16,
- fetch_texel_1d_signed_i16,
- fetch_texel_2d_signed_i16,
- fetch_texel_3d_signed_i16,
- store_texel_signed_i16
- },
-};
-
-
-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->Sampler.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"
+#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
+#include "../../gallium/auxiliary/util/u_format_r11g11b10f.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
+ },
+ {
+ MESA_FORMAT_R_FLOAT32,
+ fetch_texel_1d_f_r_f32,
+ fetch_texel_2d_f_r_f32,
+ fetch_texel_3d_f_r_f32,
+ store_texel_r_f32
+ },
+ {
+ MESA_FORMAT_R_FLOAT16,
+ fetch_texel_1d_f_r_f16,
+ fetch_texel_2d_f_r_f16,
+ fetch_texel_3d_f_r_f16,
+ store_texel_r_f16
+ },
+ {
+ MESA_FORMAT_RG_FLOAT32,
+ fetch_texel_1d_f_rg_f32,
+ fetch_texel_2d_f_rg_f32,
+ fetch_texel_3d_f_rg_f32,
+ store_texel_rg_f32
+ },
+ {
+ MESA_FORMAT_RG_FLOAT16,
+ fetch_texel_1d_f_rg_f16,
+ fetch_texel_2d_f_rg_f16,
+ fetch_texel_3d_f_rg_f16,
+ store_texel_rg_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_REV,
+ fetch_texel_1d_signed_rg88_rev,
+ fetch_texel_2d_signed_rg88_rev,
+ fetch_texel_3d_signed_rg88_rev,
+ store_texel_signed_rg88_rev
+ },
+ {
+ 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_R16,
+ fetch_texel_1d_signed_r16,
+ fetch_texel_2d_signed_r16,
+ fetch_texel_3d_signed_r16,
+ store_texel_signed_r16
+ },
+ {
+ MESA_FORMAT_SIGNED_GR1616,
+ fetch_texel_1d_signed_rg1616,
+ fetch_texel_2d_signed_rg1616,
+ fetch_texel_3d_signed_rg1616,
+ store_texel_signed_rg1616
+ },
+ {
+ 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
+ },
+ {
+ MESA_FORMAT_L_LATC1,
+ NULL,
+ _mesa_fetch_texel_2d_f_l_latc1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SIGNED_L_LATC1,
+ NULL,
+ _mesa_fetch_texel_2d_f_signed_l_latc1,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_LA_LATC2,
+ NULL,
+ _mesa_fetch_texel_2d_f_la_latc2,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SIGNED_LA_LATC2,
+ NULL,
+ _mesa_fetch_texel_2d_f_signed_la_latc2,
+ NULL,
+ NULL
+ },
+ {
+ MESA_FORMAT_SIGNED_A8,
+ fetch_texel_1d_signed_a8,
+ fetch_texel_2d_signed_a8,
+ fetch_texel_3d_signed_a8,
+ store_texel_signed_a8
+ },
+ {
+ MESA_FORMAT_SIGNED_L8,
+ fetch_texel_1d_signed_l8,
+ fetch_texel_2d_signed_l8,
+ fetch_texel_3d_signed_l8,
+ store_texel_signed_l8
+ },
+ {
+ MESA_FORMAT_SIGNED_AL88,
+ fetch_texel_1d_signed_al88,
+ fetch_texel_2d_signed_al88,
+ fetch_texel_3d_signed_al88,
+ store_texel_signed_al88
+ },
+ {
+ MESA_FORMAT_SIGNED_I8,
+ fetch_texel_1d_signed_i8,
+ fetch_texel_2d_signed_i8,
+ fetch_texel_3d_signed_i8,
+ store_texel_signed_i8
+ },
+ {
+ MESA_FORMAT_SIGNED_A16,
+ fetch_texel_1d_signed_a16,
+ fetch_texel_2d_signed_a16,
+ fetch_texel_3d_signed_a16,
+ store_texel_signed_a16
+ },
+ {
+ MESA_FORMAT_SIGNED_L16,
+ fetch_texel_1d_signed_l16,
+ fetch_texel_2d_signed_l16,
+ fetch_texel_3d_signed_l16,
+ store_texel_signed_l16
+ },
+ {
+ MESA_FORMAT_SIGNED_AL1616,
+ fetch_texel_1d_signed_al1616,
+ fetch_texel_2d_signed_al1616,
+ fetch_texel_3d_signed_al1616,
+ store_texel_signed_al1616
+ },
+ {
+ MESA_FORMAT_SIGNED_I16,
+ fetch_texel_1d_signed_i16,
+ fetch_texel_2d_signed_i16,
+ fetch_texel_3d_signed_i16,
+ store_texel_signed_i16
+ },
+ {
+ MESA_FORMAT_RGB9_E5_FLOAT,
+ fetch_texel_1d_rgb9_e5,
+ fetch_texel_2d_rgb9_e5,
+ fetch_texel_3d_rgb9_e5,
+ store_texel_rgb9_e5
+ },
+ {
+ MESA_FORMAT_R11_G11_B10_FLOAT,
+ fetch_texel_1d_r11_g11_b10f,
+ fetch_texel_2d_r11_g11_b10f,
+ fetch_texel_3d_r11_g11_b10f,
+ store_texel_r11_g11_b10f
+ }
+};
+
+
+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->Sampler.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/texfetch_tmp.h b/mesalib/src/mesa/main/texfetch_tmp.h
index 0b9d5da07..278becc11 100644
--- a/mesalib/src/mesa/main/texfetch_tmp.h
+++ b/mesalib/src/mesa/main/texfetch_tmp.h
@@ -1,2337 +1,2379 @@
-/*
- * 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 texfetch_tmp.h
- * Texel fetch functions template.
- *
- * This template file is used by texfetch.c to generate texel fetch functions
- * for 1-D, 2-D and 3-D texture images.
- *
- * It should be expanded by defining \p DIM as the number texture dimensions
- * (1, 2 or 3). According to the value of \p DIM a series of macros is defined
- * for the texel lookup in the gl_texture_image::Data.
- *
- * \author Gareth Hughes
- * \author Brian Paul
- */
-
-
-#if DIM == 1
-
-#define TEXEL_ADDR( type, image, i, j, k, size ) \
- ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
-
-#define FETCH(x) fetch_texel_1d_##x
-
-#elif DIM == 2
-
-#define TEXEL_ADDR( type, image, i, j, k, size ) \
- ((void) (k), \
- ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
-
-#define FETCH(x) fetch_texel_2d_##x
-
-#elif DIM == 3
-
-#define TEXEL_ADDR( type, image, i, j, k, size ) \
- ((type *)(image)->Data + ((image)->ImageOffsets[k] \
- + (image)->RowStride * (j) + (i)) * (size))
-
-#define FETCH(x) fetch_texel_3d_##x
-
-#else
-#error illegal number of texture dimensions
-#endif
-
-
-/* MESA_FORMAT_Z32 ***********************************************************/
-
-/* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
- * returning 1 GLfloat.
- * Note: no GLchan version of this function.
- */
-static void FETCH(f_z32)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[0] = src[0] * (1.0F / 0xffffffff);
-}
-
-#if DIM == 3
-static void store_texel_z32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLuint *depth = (const GLuint *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- dst[0] = *depth;
-}
-#endif
-
-
-/* MESA_FORMAT_Z16 ***********************************************************/
-
-/* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
- * returning 1 GLfloat.
- * Note: no GLchan version of this function.
- */
-static void FETCH(f_z16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- texel[0] = src[0] * (1.0F / 65535.0F);
-}
-
-#if DIM == 3
-static void store_texel_z16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLushort *depth = (const GLushort *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- dst[0] = *depth;
-}
-#endif
-
-
-/* MESA_FORMAT_RGBA_F32 ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
- */
-static void FETCH(f_rgba_f32)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
- texel[RCOMP] = src[0];
- texel[GCOMP] = src[1];
- texel[BCOMP] = src[2];
- texel[ACOMP] = src[3];
-}
-
-#if DIM == 3
-static void store_texel_rgba_f32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *depth = (const GLfloat *) texel;
- GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
- dst[0] = depth[RCOMP];
- dst[1] = depth[GCOMP];
- dst[2] = depth[BCOMP];
- dst[3] = depth[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_RGBA_F16 ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_rgba_f16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
- texel[RCOMP] = _mesa_half_to_float(src[0]);
- texel[GCOMP] = _mesa_half_to_float(src[1]);
- texel[BCOMP] = _mesa_half_to_float(src[2]);
- texel[ACOMP] = _mesa_half_to_float(src[3]);
-}
-
-#if DIM == 3
-static void store_texel_rgba_f16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *src = (const GLfloat *) texel;
- GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
- dst[0] = _mesa_float_to_half(src[RCOMP]);
- dst[1] = _mesa_float_to_half(src[GCOMP]);
- dst[2] = _mesa_float_to_half(src[BCOMP]);
- dst[3] = _mesa_float_to_half(src[ACOMP]);
-}
-#endif
-
-/* MESA_FORMAT_RGB_F32 *******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
- texel[RCOMP] = src[0];
- texel[GCOMP] = src[1];
- texel[BCOMP] = src[2];
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_rgb_f32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *src = (const GLfloat *) texel;
- GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
- dst[0] = src[RCOMP];
- dst[1] = src[GCOMP];
- dst[2] = src[BCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_RGB_F16 *******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
- texel[RCOMP] = _mesa_half_to_float(src[0]);
- texel[GCOMP] = _mesa_half_to_float(src[1]);
- texel[BCOMP] = _mesa_half_to_float(src[2]);
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_rgb_f16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *src = (const GLfloat *) texel;
- GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
- dst[0] = _mesa_float_to_half(src[RCOMP]);
- dst[1] = _mesa_float_to_half(src[GCOMP]);
- dst[2] = _mesa_float_to_half(src[BCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_ALPHA_F32 *****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_alpha_f32)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = src[0];
-}
-
-#if DIM == 3
-static void store_texel_alpha_f32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
- dst[0] = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_ALPHA_F32 *****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_alpha_f16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = _mesa_half_to_float(src[0]);
-}
-
-#if DIM == 3
-static void store_texel_alpha_f16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
- dst[0] = _mesa_float_to_half(rgba[ACOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_LUMINANCE_F32 *************************************************/
-
-/* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_luminance_f32)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = src[0];
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_luminance_f32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
- dst[0] = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_LUMINANCE_F16 *************************************************/
-
-/* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_luminance_f16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = _mesa_half_to_float(src[0]);
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_luminance_f16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
- dst[0] = _mesa_float_to_half(rgba[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
-
-/* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_luminance_alpha_f32)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = src[0];
- texel[ACOMP] = src[1];
-}
-
-#if DIM == 3
-static void store_texel_luminance_alpha_f32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
-
-/* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_luminance_alpha_f16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = _mesa_half_to_float(src[0]);
- texel[ACOMP] = _mesa_half_to_float(src[1]);
-}
-
-#if DIM == 3
-static void store_texel_luminance_alpha_f16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
- dst[0] = _mesa_float_to_half(rgba[RCOMP]);
- dst[1] = _mesa_float_to_half(rgba[ACOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_INTENSITY_F32 *************************************************/
-
-/* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_intensity_f32)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] =
- texel[ACOMP] = src[0];
-}
-
-#if DIM == 3
-static void store_texel_intensity_f32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
- dst[0] = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_INTENSITY_F16 *************************************************/
-
-/* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_intensity_f16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] =
- texel[ACOMP] = _mesa_half_to_float(src[0]);
-}
-
-#if DIM == 3
-static void store_texel_intensity_f16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
- dst[0] = _mesa_float_to_half(rgba[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_R_FLOAT32 *****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D R_FLOAT32 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_r_f32)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
- texel[RCOMP] = src[0];
- texel[GCOMP] = 0.0F;
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_r_f32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
- dst[0] = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_R_FLOAT16 *****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D R_FLOAT16 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_r_f16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
- texel[RCOMP] = _mesa_half_to_float(src[0]);
- texel[GCOMP] = 0.0F;
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_r_f16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
- dst[0] = _mesa_float_to_half(rgba[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_RG_FLOAT32 ****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D RG_FLOAT32 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_rg_f32)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
- texel[RCOMP] = src[0];
- texel[GCOMP] = src[1];
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_rg_f32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_RG_FLOAT16 ****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D RG_FLOAT16 texture,
- * returning 4 GLfloats.
- */
-static void FETCH(f_rg_f16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
- texel[RCOMP] = _mesa_half_to_float(src[0]);
- texel[GCOMP] = _mesa_half_to_float(src[1]);
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_rg_f16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLfloat *rgba = (const GLfloat *) texel;
- GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
- dst[0] = _mesa_float_to_half(rgba[RCOMP]);
- dst[1] = _mesa_float_to_half(rgba[GCOMP]);
-}
-#endif
-
-
-/*
- * Begin Hardware formats
- */
-
-/* MESA_FORMAT_RGBA8888 ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
-static void FETCH(f_rgba8888)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
- texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
- texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
- texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
-}
-
-
-
-#if DIM == 3
-static void store_texel_rgba8888(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_RGBA888_REV ***************************************************/
-
-/* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
-static void FETCH(f_rgba8888_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
- texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
- texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
- texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
-}
-
-#if DIM == 3
-static void store_texel_rgba8888_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_ARGB8888 ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
-static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
- texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
- texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
- texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
-}
-
-#if DIM == 3
-static void store_texel_argb8888(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_ARGB8888_REV **************************************************/
-
-/* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
-static void FETCH(f_argb8888_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
- texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
- texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
- texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
-}
-
-#if DIM == 3
-static void store_texel_argb8888_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_XRGB8888 ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
-static void FETCH(f_xrgb8888)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
- texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
- texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
- texel[ACOMP] = 1.0f;
-}
-
-#if DIM == 3
-static void store_texel_xrgb8888(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_XRGB8888_REV **************************************************/
-
-/* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
-static void FETCH(f_xrgb8888_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
- texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
- texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
- texel[ACOMP] = 1.0f;
-}
-
-#if DIM == 3
-static void store_texel_xrgb8888_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], 0xff);
-}
-#endif
-
-
-/* MESA_FORMAT_RGB888 ********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
-static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
- texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
- texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
- texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_rgb888(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
- dst[0] = rgba[BCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_BGR888 ********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
-static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
- texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
- texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
- texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_bgr888(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
-}
-#endif
-
-
-/* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
- instead of slow (g << 2) * 255 / 252 (always rounds down) */
-
-/* MESA_FORMAT_RGB565 ********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
-static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- const GLushort s = *src;
- texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
- texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
- texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_rgb565(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_RGB565_REV ****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
-static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
- texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
- texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
- texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_ARGB4444 ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
-static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- const GLushort s = *src;
- texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
- texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
- texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
- texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
-}
-
-#if DIM == 3
-static void store_texel_argb4444(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_ARGB4444_REV **************************************************/
-
-/* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
-static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
- texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
- texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
- texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
-}
-
-#if DIM == 3
-static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
-}
-#endif
-
-/* MESA_FORMAT_RGBA5551 ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
-static void FETCH(f_rgba5551)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- const GLushort s = *src;
- texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
- texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
- texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
- texel[ACOMP] = ((s ) & 0x01) * 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_rgba5551(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
-
-/* MESA_FORMAT_ARGB1555 ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
-static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- const GLushort s = *src;
- texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
- texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
- texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
- texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_argb1555(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_ARGB1555_REV **************************************************/
-
-/* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
-static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
- texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
- texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
- texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
- texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
-}
-
-#if DIM == 3
-static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_ARGB2101010 ***************************************************/
-
-/* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
-static void FETCH(f_argb2101010)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- const GLuint s = *src;
- texel[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
- texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
- texel[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F);
- texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
-}
-
-#if DIM == 3
-static void store_texel_argb2101010(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_2101010_UB(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_RG88 **********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
-static void FETCH(f_rg88)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
- texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 1.0;
-}
-
-#if DIM == 3
-static void store_texel_rg88(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_88(rgba[RCOMP], rgba[GCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_RG88_REV ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
-static void FETCH(f_rg88_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
- texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 1.0;
-}
-
-#if DIM == 3
-static void store_texel_rg88_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_88(rgba[GCOMP], rgba[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_AL44 **********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
-static void FETCH(f_al44)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
- texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
-}
-
-#if DIM == 3
-static void store_texel_al44(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- *dst = PACK_COLOR_44(rgba[ACOMP], rgba[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_AL88 **********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
-static void FETCH(f_al88)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
- texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
-}
-
-#if DIM == 3
-static void store_texel_al88(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_R8 ************************************************************/
-
-/* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
-static void FETCH(f_r8)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- texel[RCOMP] = UBYTE_TO_FLOAT(s);
- texel[GCOMP] = 0.0;
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 1.0;
-}
-
-#if DIM == 3
-static void store_texel_r8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_R16 ***********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
-static void FETCH(f_r16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- texel[RCOMP] = USHORT_TO_FLOAT(s);
- texel[GCOMP] = 0.0;
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 1.0;
-}
-
-#if DIM == 3
-static void store_texel_r16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLushort *rgba = (const GLushort *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_AL88_REV ******************************************************/
-
-/* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
-static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
- texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
-}
-
-#if DIM == 3
-static void store_texel_al88_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_RG1616 ********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
-static void FETCH(f_rg1616)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
- texel[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 1.0;
-}
-
-#if DIM == 3
-static void store_texel_rg1616(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[GCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_RG1616_REV ****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
-static void FETCH(f_rg1616_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
- texel[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
- texel[BCOMP] = 0.0;
- texel[ACOMP] = 1.0;
-}
-
-#if DIM == 3
-static void store_texel_rg1616_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = PACK_COLOR_1616(rgba[GCOMP], rgba[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_AL1616 ********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
-static void FETCH(f_al1616)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
- texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
-}
-
-#if DIM == 3
-static void store_texel_al1616(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLushort *rgba = (const GLushort *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_1616(rgba[ACOMP], rgba[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_AL1616_REV ****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
-static void FETCH(f_al1616_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
- texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
-}
-
-#if DIM == 3
-static void store_texel_al1616_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLushort *rgba = (const GLushort *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[ACOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_RGB332 ********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
-static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- const GLubyte s = *src;
- texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
- texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
- texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_rgb332(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_A8 ************************************************************/
-
-/* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
-static void FETCH(f_a8)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
-}
-
-#if DIM == 3
-static void store_texel_a8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- *dst = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_A16 ************************************************************/
-
-/* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
-static void FETCH(f_a16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
-}
-
-#if DIM == 3
-static void store_texel_a16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLushort *rgba = (const GLushort *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_L8 ************************************************************/
-
-/* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
-static void FETCH(f_l8)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_l8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_L16 ***********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
-static void FETCH(f_l16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = USHORT_TO_FLOAT( src[0] );
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_l16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLushort *rgba = (const GLushort *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_I8 ************************************************************/
-
-/* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
-static void FETCH(f_i8)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] =
- texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
-}
-
-#if DIM == 3
-static void store_texel_i8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_I16 ***********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
-static void FETCH(f_i16)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] =
- texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
-}
-
-#if DIM == 3
-static void store_texel_i16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLushort *rgba = (const GLushort *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_CI8 ***********************************************************/
-
-/* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
- * color table, and return 4 GLchans.
- */
-static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- const struct gl_color_table *palette;
- GLuint index;
- GET_CURRENT_CONTEXT(ctx);
-
- if (ctx->Texture.SharedPalette) {
- palette = &ctx->Texture.Palette;
- }
- else {
- palette = &texImage->TexObject->Palette;
- }
- if (palette->Size == 0)
- return; /* undefined results */
-
- /* Mask the index against size of palette to avoid going out of bounds */
- index = (*src) & (palette->Size - 1);
-
- {
- const GLfloat *table = palette->TableF;
- switch (palette->_BaseFormat) {
- case GL_ALPHA:
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = table[index];
- break;
- case GL_LUMINANCE:
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = table[index];
- texel[ACOMP] = 1.0F;
- break;
- case GL_INTENSITY:
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] =
- texel[ACOMP] = table[index];
- break;
- case GL_LUMINANCE_ALPHA:
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = table[index * 2 + 0];
- texel[ACOMP] = table[index * 2 + 1];
- break;
- case GL_RGB:
- texel[RCOMP] = table[index * 3 + 0];
- texel[GCOMP] = table[index * 3 + 1];
- texel[BCOMP] = table[index * 3 + 2];
- texel[ACOMP] = 1.0F;
- break;
- case GL_RGBA:
- texel[RCOMP] = table[index * 4 + 0];
- texel[GCOMP] = table[index * 4 + 1];
- texel[BCOMP] = table[index * 4 + 2];
- texel[ACOMP] = table[index * 4 + 3];
- break;
- default:
- _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
- return;
- }
- }
-}
-
-#if DIM == 3
-static void store_texel_ci8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *index = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- *dst = *index;
-}
-#endif
-
-
-/* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
-/* Note: component order is same as for MESA_FORMAT_RGB888 */
-static void FETCH(srgb8)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
- texel[RCOMP] = nonlinear_to_linear(src[2]);
- texel[GCOMP] = nonlinear_to_linear(src[1]);
- texel[BCOMP] = nonlinear_to_linear(src[0]);
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_srgb8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
- dst[0] = rgba[BCOMP]; /* no conversion */
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[RCOMP];
-}
-#endif
-
-/* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
-static void FETCH(srgba8)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
- texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
- texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
- texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
-}
-
-#if DIM == 3
-static void store_texel_srgba8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
-
-/* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
-static void FETCH(sargb8)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
- texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
- texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
- texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
-}
-
-#if DIM == 3
-static void store_texel_sargb8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
-
-/* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
-static void FETCH(sl8)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = nonlinear_to_linear(src[0]);
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_sl8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
- dst[0] = rgba[RCOMP];
-}
-#endif
-
-/* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
-static void FETCH(sla8)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = nonlinear_to_linear(src[0]);
- texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
-}
-
-#if DIM == 3
-static void store_texel_sla8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_RGBA_INT8 **************************************************/
-
-static void
-FETCH(rgba_int8)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
- texel[RCOMP] = (GLfloat) src[0];
- texel[GCOMP] = (GLfloat) src[1];
- texel[BCOMP] = (GLfloat) src[2];
- texel[ACOMP] = (GLfloat) src[3];
-}
-
-#if DIM == 3
-static void
-store_texel_rgba_int8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLbyte *rgba = (const GLbyte *) texel;
- GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
- dst[3] = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_RGBA_INT16 **************************************************/
-
-static void
-FETCH(rgba_int16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
- texel[RCOMP] = (GLfloat) src[0];
- texel[GCOMP] = (GLfloat) src[1];
- texel[BCOMP] = (GLfloat) src[2];
- texel[ACOMP] = (GLfloat) src[3];
-}
-
-#if DIM == 3
-static void
-store_texel_rgba_int16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLshort *rgba = (const GLshort *) texel;
- GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
- dst[3] = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_RGBA_INT32 **************************************************/
-
-static void
-FETCH(rgba_int32)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
- texel[RCOMP] = (GLfloat) src[0];
- texel[GCOMP] = (GLfloat) src[1];
- texel[BCOMP] = (GLfloat) src[2];
- texel[ACOMP] = (GLfloat) src[3];
-}
-
-#if DIM == 3
-static void
-store_texel_rgba_int32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLint *rgba = (const GLint *) texel;
- GLint *dst = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
- dst[3] = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_RGBA_UINT8 **************************************************/
-
-static void
-FETCH(rgba_uint8)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
- texel[RCOMP] = (GLfloat) src[0];
- texel[GCOMP] = (GLfloat) src[1];
- texel[BCOMP] = (GLfloat) src[2];
- texel[ACOMP] = (GLfloat) src[3];
-}
-
-#if DIM == 3
-static void
-store_texel_rgba_uint8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
- dst[3] = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_RGBA_UINT16 **************************************************/
-
-static void
-FETCH(rgba_uint16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
- texel[RCOMP] = (GLfloat) src[0];
- texel[GCOMP] = (GLfloat) src[1];
- texel[BCOMP] = (GLfloat) src[2];
- texel[ACOMP] = (GLfloat) src[3];
-}
-
-#if DIM == 3
-static void
-store_texel_rgba_uint16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLushort *rgba = (const GLushort *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
- dst[3] = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_RGBA_UINT32 **************************************************/
-
-static void
-FETCH(rgba_uint32)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
- texel[RCOMP] = (GLfloat) src[0];
- texel[GCOMP] = (GLfloat) src[1];
- texel[BCOMP] = (GLfloat) src[2];
- texel[ACOMP] = (GLfloat) src[3];
-}
-
-#if DIM == 3
-static void
-store_texel_rgba_uint32(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLuint *rgba = (const GLuint *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
- dst[3] = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_DUDV8 ********************************************************/
-
-/* this format by definition produces 0,0,0,1 as rgba values,
- however we'll return the dudv values as rg and fix up elsewhere */
-static void FETCH(dudv8)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
- texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
- texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
- texel[BCOMP] = 0;
- texel[ACOMP] = 0;
-}
-
-
-/* MESA_FORMAT_SIGNED_R8 ***********************************************/
-
-static void FETCH(signed_r8)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
- texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
- texel[GCOMP] = 0.0F;
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_signed_r8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLbyte *rgba = (const GLbyte *) texel;
- GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_A8 ***********************************************/
-
-static void FETCH(signed_a8)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
- texel[RCOMP] = 0.0F;
- texel[GCOMP] = 0.0F;
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
-}
-
-#if DIM == 3
-static void store_texel_signed_a8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLbyte *rgba = (const GLbyte *) texel;
- GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
- *dst = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_L8 ***********************************************/
-
-static void FETCH(signed_l8)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = BYTE_TO_FLOAT_TEX( s );
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_signed_l8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLbyte *rgba = (const GLbyte *) texel;
- GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_I8 ***********************************************/
-
-static void FETCH(signed_i8)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] =
- texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
-}
-
-#if DIM == 3
-static void store_texel_signed_i8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLbyte *rgba = (const GLbyte *) texel;
- GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_RG88_REV ***********************************************/
-
-static void FETCH(signed_rg88_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
- texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
- texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_signed_rg88_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLbyte *rg = (const GLbyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- dst[0] = PACK_COLOR_88(rg[GCOMP], rg[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_AL88 ***********************************************/
-
-static void FETCH(signed_al88)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
- texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
-}
-
-#if DIM == 3
-static void store_texel_signed_al88(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLbyte *rg = (const GLbyte *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
- dst[0] = PACK_COLOR_88(rg[ACOMP], rg[RCOMP]);
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
-
-static void FETCH(signed_rgbx8888)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
- texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
- texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
- texel[ACOMP] = 1.0f;
-}
-
-#if DIM == 3
-static void store_texel_signed_rgbx8888(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLbyte *rgba = (const GLbyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
-
-static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
- texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
- texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
- texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
-}
-
-#if DIM == 3
-static void store_texel_signed_rgba8888(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLbyte *rgba = (const GLbyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
-
-static void FETCH(signed_rgba8888_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
- texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
- texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
- texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
-}
-
-#if DIM == 3
-static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLubyte *rgba = (const GLubyte *) texel;
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
-
-
-
-/* MESA_FORMAT_SIGNED_R16 ***********************************************/
-
-static void
-FETCH(signed_r16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
- texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
- texel[GCOMP] = 0.0F;
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void
-store_texel_signed_r16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLshort *rgba = (const GLshort *) texel;
- GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
- *dst = rgba[0];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_A16 ***********************************************/
-
-static void
-FETCH(signed_a16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
- texel[RCOMP] = 0.0F;
- texel[GCOMP] = 0.0F;
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
-}
-
-#if DIM == 3
-static void
-store_texel_signed_a16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLshort *rgba = (const GLshort *) texel;
- GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
- *dst = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_L16 ***********************************************/
-
-static void
-FETCH(signed_l16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = SHORT_TO_FLOAT_TEX( s );
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void
-store_texel_signed_l16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLshort *rgba = (const GLshort *) texel;
- GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_I16 ***********************************************/
-
-static void
-FETCH(signed_i16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] =
- texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
-}
-
-#if DIM == 3
-static void
-store_texel_signed_i16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLshort *rgba = (const GLshort *) texel;
- GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
- *dst = rgba[RCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_RG1616 ***********************************************/
-
-static void
-FETCH(signed_rg1616)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
- texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
- texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
- texel[BCOMP] = 0.0F;
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void
-store_texel_signed_rg1616(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLshort *rgba = (const GLshort *) texel;
- GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_AL1616 ***********************************************/
-
-static void
-FETCH(signed_al1616)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
- texel[RCOMP] =
- texel[GCOMP] =
- texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
- texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
-}
-
-#if DIM == 3
-static void
-store_texel_signed_al1616(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLshort *rgba = (const GLshort *) texel;
- GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[ACOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
-
-static void
-FETCH(signed_rgb_16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
- texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
- texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
- texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void
-store_texel_signed_rgb_16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLshort *rgba = (const GLshort *) texel;
- GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
-}
-#endif
-
-
-/* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
-
-static void
-FETCH(signed_rgba_16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
- texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
- texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
- texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
- texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
-}
-
-#if DIM == 3
-static void
-store_texel_signed_rgba_16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLshort *rgba = (const GLshort *) texel;
- GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
- dst[3] = rgba[ACOMP];
-}
-#endif
-
-
-
-/* MESA_FORMAT_RGBA_16 ***********************************************/
-
-static void
-FETCH(rgba_16)(const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
- const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
- texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
- texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
- texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
- texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
-}
-
-#if DIM == 3
-static void
-store_texel_rgba_16(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- const GLushort *rgba = (const GLushort *) texel;
- GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
- dst[0] = rgba[RCOMP];
- dst[1] = rgba[GCOMP];
- dst[2] = rgba[BCOMP];
- dst[3] = rgba[ACOMP];
-}
-#endif
-
-
-
-/* MESA_FORMAT_YCBCR *********************************************************/
-
-/* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
- * We convert YCbCr to RGB here.
- */
-static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
- const GLushort *src1 = src0 + 1; /* odd */
- const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
- const GLubyte cb = *src0 & 0xff; /* chroma U */
- const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
- const GLubyte cr = *src1 & 0xff; /* chroma V */
- const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
- GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
- GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
- GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
- r *= (1.0F / 255.0F);
- g *= (1.0F / 255.0F);
- b *= (1.0F / 255.0F);
- texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
- texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
- texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_ycbcr(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- (void) texImage;
- (void) i;
- (void) j;
- (void) k;
- (void) texel;
- /* XXX to do */
-}
-#endif
-
-
-/* MESA_FORMAT_YCBCR_REV *****************************************************/
-
-/* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
- * We convert YCbCr to RGB here.
- */
-static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
- const GLushort *src1 = src0 + 1; /* odd */
- const GLubyte y0 = *src0 & 0xff; /* luminance */
- const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
- const GLubyte y1 = *src1 & 0xff; /* luminance */
- const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
- const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
- GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
- GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
- GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
- r *= (1.0F / 255.0F);
- g *= (1.0F / 255.0F);
- b *= (1.0F / 255.0F);
- texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
- texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
- texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
- texel[ACOMP] = 1.0F;
-}
-
-#if DIM == 3
-static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- (void) texImage;
- (void) i;
- (void) j;
- (void) k;
- (void) texel;
- /* XXX to do */
-}
-#endif
-
-
-/* MESA_TEXFORMAT_Z24_S8 ***************************************************/
-
-static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- /* only return Z, not stencil data */
- const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
- texel[0] = ((*src) >> 8) * scale;
- ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8);
- ASSERT(texel[0] >= 0.0F);
- ASSERT(texel[0] <= 1.0F);
-}
-
-#if DIM == 3
-static void store_texel_z24_s8(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- /* only store Z, not stencil */
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- GLfloat depth = *((GLfloat *) texel);
- GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
- *dst = zi | (*dst & 0xff);
-}
-#endif
-
-
-/* MESA_TEXFORMAT_S8_Z24 ***************************************************/
-
-static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- /* only return Z, not stencil data */
- const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
- texel[0] = ((*src) & 0x00ffffff) * scale;
- ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24);
- ASSERT(texel[0] >= 0.0F);
- ASSERT(texel[0] <= 1.0F);
-}
-
-#if DIM == 3
-static void store_texel_s8_z24(struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, const void *texel)
-{
- /* only store Z, not stencil */
- GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
- GLfloat depth = *((GLfloat *) texel);
- GLuint zi = (GLuint) (depth * 0xffffff);
- *dst = zi | (*dst & 0xff000000);
-}
-#endif
-
-
-#undef TEXEL_ADDR
-#undef DIM
-#undef FETCH
+/*
+ * 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 texfetch_tmp.h
+ * Texel fetch functions template.
+ *
+ * This template file is used by texfetch.c to generate texel fetch functions
+ * for 1-D, 2-D and 3-D texture images.
+ *
+ * It should be expanded by defining \p DIM as the number texture dimensions
+ * (1, 2 or 3). According to the value of \p DIM a series of macros is defined
+ * for the texel lookup in the gl_texture_image::Data.
+ *
+ * \author Gareth Hughes
+ * \author Brian Paul
+ */
+
+
+#if DIM == 1
+
+#define TEXEL_ADDR( type, image, i, j, k, size ) \
+ ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
+
+#define FETCH(x) fetch_texel_1d_##x
+
+#elif DIM == 2
+
+#define TEXEL_ADDR( type, image, i, j, k, size ) \
+ ((void) (k), \
+ ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
+
+#define FETCH(x) fetch_texel_2d_##x
+
+#elif DIM == 3
+
+#define TEXEL_ADDR( type, image, i, j, k, size ) \
+ ((type *)(image)->Data + ((image)->ImageOffsets[k] \
+ + (image)->RowStride * (j) + (i)) * (size))
+
+#define FETCH(x) fetch_texel_3d_##x
+
+#else
+#error illegal number of texture dimensions
+#endif
+
+
+/* MESA_FORMAT_Z32 ***********************************************************/
+
+/* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
+ * returning 1 GLfloat.
+ * Note: no GLchan version of this function.
+ */
+static void FETCH(f_z32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[0] = src[0] * (1.0F / 0xffffffff);
+}
+
+#if DIM == 3
+static void store_texel_z32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLuint *depth = (const GLuint *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ dst[0] = *depth;
+}
+#endif
+
+
+/* MESA_FORMAT_Z16 ***********************************************************/
+
+/* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
+ * returning 1 GLfloat.
+ * Note: no GLchan version of this function.
+ */
+static void FETCH(f_z16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ texel[0] = src[0] * (1.0F / 65535.0F);
+}
+
+#if DIM == 3
+static void store_texel_z16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLushort *depth = (const GLushort *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ dst[0] = *depth;
+}
+#endif
+
+
+/* MESA_FORMAT_RGBA_F32 ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
+ */
+static void FETCH(f_rgba_f32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
+ texel[RCOMP] = src[0];
+ texel[GCOMP] = src[1];
+ texel[BCOMP] = src[2];
+ texel[ACOMP] = src[3];
+}
+
+#if DIM == 3
+static void store_texel_rgba_f32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *depth = (const GLfloat *) texel;
+ GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
+ dst[0] = depth[RCOMP];
+ dst[1] = depth[GCOMP];
+ dst[2] = depth[BCOMP];
+ dst[3] = depth[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RGBA_F16 ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_rgba_f16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
+ texel[RCOMP] = _mesa_half_to_float(src[0]);
+ texel[GCOMP] = _mesa_half_to_float(src[1]);
+ texel[BCOMP] = _mesa_half_to_float(src[2]);
+ texel[ACOMP] = _mesa_half_to_float(src[3]);
+}
+
+#if DIM == 3
+static void store_texel_rgba_f16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *src = (const GLfloat *) texel;
+ GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
+ dst[0] = _mesa_float_to_half(src[RCOMP]);
+ dst[1] = _mesa_float_to_half(src[GCOMP]);
+ dst[2] = _mesa_float_to_half(src[BCOMP]);
+ dst[3] = _mesa_float_to_half(src[ACOMP]);
+}
+#endif
+
+/* MESA_FORMAT_RGB_F32 *******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
+ texel[RCOMP] = src[0];
+ texel[GCOMP] = src[1];
+ texel[BCOMP] = src[2];
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rgb_f32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *src = (const GLfloat *) texel;
+ GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
+ dst[0] = src[RCOMP];
+ dst[1] = src[GCOMP];
+ dst[2] = src[BCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RGB_F16 *******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
+ texel[RCOMP] = _mesa_half_to_float(src[0]);
+ texel[GCOMP] = _mesa_half_to_float(src[1]);
+ texel[BCOMP] = _mesa_half_to_float(src[2]);
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rgb_f16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *src = (const GLfloat *) texel;
+ GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
+ dst[0] = _mesa_float_to_half(src[RCOMP]);
+ dst[1] = _mesa_float_to_half(src[GCOMP]);
+ dst[2] = _mesa_float_to_half(src[BCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_ALPHA_F32 *****************************************************/
+
+/* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_alpha_f32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = src[0];
+}
+
+#if DIM == 3
+static void store_texel_alpha_f32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
+ dst[0] = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_ALPHA_F32 *****************************************************/
+
+/* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_alpha_f16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = _mesa_half_to_float(src[0]);
+}
+
+#if DIM == 3
+static void store_texel_alpha_f16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
+ dst[0] = _mesa_float_to_half(rgba[ACOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_LUMINANCE_F32 *************************************************/
+
+/* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_luminance_f32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = src[0];
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_luminance_f32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
+ dst[0] = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_LUMINANCE_F16 *************************************************/
+
+/* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_luminance_f16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = _mesa_half_to_float(src[0]);
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_luminance_f16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
+ dst[0] = _mesa_float_to_half(rgba[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
+
+/* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_luminance_alpha_f32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = src[0];
+ texel[ACOMP] = src[1];
+}
+
+#if DIM == 3
+static void store_texel_luminance_alpha_f32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
+
+/* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_luminance_alpha_f16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = _mesa_half_to_float(src[0]);
+ texel[ACOMP] = _mesa_half_to_float(src[1]);
+}
+
+#if DIM == 3
+static void store_texel_luminance_alpha_f16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
+ dst[0] = _mesa_float_to_half(rgba[RCOMP]);
+ dst[1] = _mesa_float_to_half(rgba[ACOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_INTENSITY_F32 *************************************************/
+
+/* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_intensity_f32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] =
+ texel[ACOMP] = src[0];
+}
+
+#if DIM == 3
+static void store_texel_intensity_f32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
+ dst[0] = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_INTENSITY_F16 *************************************************/
+
+/* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_intensity_f16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] =
+ texel[ACOMP] = _mesa_half_to_float(src[0]);
+}
+
+#if DIM == 3
+static void store_texel_intensity_f16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
+ dst[0] = _mesa_float_to_half(rgba[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_R_FLOAT32 *****************************************************/
+
+/* Fetch texel from 1D, 2D or 3D R_FLOAT32 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_r_f32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
+ texel[RCOMP] = src[0];
+ texel[GCOMP] = 0.0F;
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_r_f32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
+ dst[0] = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_R_FLOAT16 *****************************************************/
+
+/* Fetch texel from 1D, 2D or 3D R_FLOAT16 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_r_f16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
+ texel[RCOMP] = _mesa_half_to_float(src[0]);
+ texel[GCOMP] = 0.0F;
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_r_f16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
+ dst[0] = _mesa_float_to_half(rgba[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_RG_FLOAT32 ****************************************************/
+
+/* Fetch texel from 1D, 2D or 3D RG_FLOAT32 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_rg_f32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
+ texel[RCOMP] = src[0];
+ texel[GCOMP] = src[1];
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rg_f32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RG_FLOAT16 ****************************************************/
+
+/* Fetch texel from 1D, 2D or 3D RG_FLOAT16 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_rg_f16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
+ texel[RCOMP] = _mesa_half_to_float(src[0]);
+ texel[GCOMP] = _mesa_half_to_float(src[1]);
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rg_f16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *rgba = (const GLfloat *) texel;
+ GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
+ dst[0] = _mesa_float_to_half(rgba[RCOMP]);
+ dst[1] = _mesa_float_to_half(rgba[GCOMP]);
+}
+#endif
+
+
+/*
+ * Begin Hardware formats
+ */
+
+/* MESA_FORMAT_RGBA8888 ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
+static void FETCH(f_rgba8888)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+ texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+}
+
+
+
+#if DIM == 3
+static void store_texel_rgba8888(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_RGBA888_REV ***************************************************/
+
+/* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
+static void FETCH(f_rgba8888_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+ texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+}
+
+#if DIM == 3
+static void store_texel_rgba8888_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_ARGB8888 ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
+static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+ texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+}
+
+#if DIM == 3
+static void store_texel_argb8888(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_ARGB8888_REV **************************************************/
+
+/* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
+static void FETCH(f_argb8888_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+ texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+}
+
+#if DIM == 3
+static void store_texel_argb8888_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_XRGB8888 ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
+static void FETCH(f_xrgb8888)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+ texel[ACOMP] = 1.0f;
+}
+
+#if DIM == 3
+static void store_texel_xrgb8888(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_XRGB8888_REV **************************************************/
+
+/* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
+static void FETCH(f_xrgb8888_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+ texel[ACOMP] = 1.0f;
+}
+
+#if DIM == 3
+static void store_texel_xrgb8888_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], 0xff);
+}
+#endif
+
+
+/* MESA_FORMAT_RGB888 ********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
+static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
+ texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
+ texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
+ texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rgb888(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
+ dst[0] = rgba[BCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_BGR888 ********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
+static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
+ texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
+ texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
+ texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_bgr888(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+}
+#endif
+
+
+/* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
+ instead of slow (g << 2) * 255 / 252 (always rounds down) */
+
+/* MESA_FORMAT_RGB565 ********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
+static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ const GLushort s = *src;
+ texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
+ texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
+ texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rgb565(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_RGB565_REV ****************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
+static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
+ texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
+ texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
+ texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_ARGB4444 ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
+static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ const GLushort s = *src;
+ texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
+ texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
+ texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
+ texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
+}
+
+#if DIM == 3
+static void store_texel_argb4444(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_ARGB4444_REV **************************************************/
+
+/* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
+static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
+ texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
+ texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
+ texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
+}
+
+#if DIM == 3
+static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
+}
+#endif
+
+/* MESA_FORMAT_RGBA5551 ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
+static void FETCH(f_rgba5551)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ const GLushort s = *src;
+ texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
+ texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
+ texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
+ texel[ACOMP] = ((s ) & 0x01) * 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rgba5551(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
+}
+#endif
+
+/* MESA_FORMAT_ARGB1555 ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
+static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ const GLushort s = *src;
+ texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
+ texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
+ texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
+ texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_argb1555(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_ARGB1555_REV **************************************************/
+
+/* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
+static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
+ texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
+ texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
+ texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
+ texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
+}
+
+#if DIM == 3
+static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_ARGB2101010 ***************************************************/
+
+/* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
+static void FETCH(f_argb2101010)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ const GLuint s = *src;
+ texel[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
+ texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
+ texel[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F);
+ texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
+}
+
+#if DIM == 3
+static void store_texel_argb2101010(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_2101010_UB(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_RG88 **********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
+static void FETCH(f_rg88)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+ texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 1.0;
+}
+
+#if DIM == 3
+static void store_texel_rg88(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_88(rgba[RCOMP], rgba[GCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_RG88_REV ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
+static void FETCH(f_rg88_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+ texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 1.0;
+}
+
+#if DIM == 3
+static void store_texel_rg88_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_88(rgba[GCOMP], rgba[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_AL44 **********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
+static void FETCH(f_al44)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
+ texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
+}
+
+#if DIM == 3
+static void store_texel_al44(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_44(rgba[ACOMP], rgba[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_AL88 **********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
+static void FETCH(f_al88)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+ texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
+}
+
+#if DIM == 3
+static void store_texel_al88(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_R8 ************************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
+static void FETCH(f_r8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ texel[RCOMP] = UBYTE_TO_FLOAT(s);
+ texel[GCOMP] = 0.0;
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 1.0;
+}
+
+#if DIM == 3
+static void store_texel_r8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_R16 ***********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
+static void FETCH(f_r16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ texel[RCOMP] = USHORT_TO_FLOAT(s);
+ texel[GCOMP] = 0.0;
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 1.0;
+}
+
+#if DIM == 3
+static void store_texel_r16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLushort *rgba = (const GLushort *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_AL88_REV ******************************************************/
+
+/* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
+static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+ texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
+}
+
+#if DIM == 3
+static void store_texel_al88_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_RG1616 ********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
+static void FETCH(f_rg1616)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
+ texel[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 1.0;
+}
+
+#if DIM == 3
+static void store_texel_rg1616(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[GCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_RG1616_REV ****************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
+static void FETCH(f_rg1616_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
+ texel[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
+ texel[BCOMP] = 0.0;
+ texel[ACOMP] = 1.0;
+}
+
+#if DIM == 3
+static void store_texel_rg1616_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_1616(rgba[GCOMP], rgba[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_AL1616 ********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
+static void FETCH(f_al1616)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
+ texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
+}
+
+#if DIM == 3
+static void store_texel_al1616(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLushort *rgba = (const GLushort *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_1616(rgba[ACOMP], rgba[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_AL1616_REV ****************************************************/
+
+/* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
+static void FETCH(f_al1616_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
+ texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
+}
+
+#if DIM == 3
+static void store_texel_al1616_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLushort *rgba = (const GLushort *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[ACOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_RGB332 ********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
+static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ const GLubyte s = *src;
+ texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
+ texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
+ texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rgb332(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_A8 ************************************************************/
+
+/* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
+static void FETCH(f_a8)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
+}
+
+#if DIM == 3
+static void store_texel_a8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ *dst = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_A16 ************************************************************/
+
+/* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
+static void FETCH(f_a16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
+}
+
+#if DIM == 3
+static void store_texel_a16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLushort *rgba = (const GLushort *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_L8 ************************************************************/
+
+/* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
+static void FETCH(f_l8)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_l8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_L16 ***********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
+static void FETCH(f_l16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = USHORT_TO_FLOAT( src[0] );
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_l16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLushort *rgba = (const GLushort *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_I8 ************************************************************/
+
+/* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
+static void FETCH(f_i8)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] =
+ texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
+}
+
+#if DIM == 3
+static void store_texel_i8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_I16 ***********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
+static void FETCH(f_i16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] =
+ texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
+}
+
+#if DIM == 3
+static void store_texel_i16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLushort *rgba = (const GLushort *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_CI8 ***********************************************************/
+
+/* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
+ * color table, and return 4 GLchans.
+ */
+static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ const struct gl_color_table *palette;
+ GLuint index;
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (ctx->Texture.SharedPalette) {
+ palette = &ctx->Texture.Palette;
+ }
+ else {
+ palette = &texImage->TexObject->Palette;
+ }
+ if (palette->Size == 0)
+ return; /* undefined results */
+
+ /* Mask the index against size of palette to avoid going out of bounds */
+ index = (*src) & (palette->Size - 1);
+
+ {
+ const GLfloat *table = palette->TableF;
+ switch (palette->_BaseFormat) {
+ case GL_ALPHA:
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = table[index];
+ break;
+ case GL_LUMINANCE:
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = table[index];
+ texel[ACOMP] = 1.0F;
+ break;
+ case GL_INTENSITY:
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] =
+ texel[ACOMP] = table[index];
+ break;
+ case GL_LUMINANCE_ALPHA:
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = table[index * 2 + 0];
+ texel[ACOMP] = table[index * 2 + 1];
+ break;
+ case GL_RGB:
+ texel[RCOMP] = table[index * 3 + 0];
+ texel[GCOMP] = table[index * 3 + 1];
+ texel[BCOMP] = table[index * 3 + 2];
+ texel[ACOMP] = 1.0F;
+ break;
+ case GL_RGBA:
+ texel[RCOMP] = table[index * 4 + 0];
+ texel[GCOMP] = table[index * 4 + 1];
+ texel[BCOMP] = table[index * 4 + 2];
+ texel[ACOMP] = table[index * 4 + 3];
+ break;
+ default:
+ _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
+ return;
+ }
+ }
+}
+
+#if DIM == 3
+static void store_texel_ci8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *index = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ *dst = *index;
+}
+#endif
+
+
+/* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
+/* Note: component order is same as for MESA_FORMAT_RGB888 */
+static void FETCH(srgb8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
+ texel[RCOMP] = nonlinear_to_linear(src[2]);
+ texel[GCOMP] = nonlinear_to_linear(src[1]);
+ texel[BCOMP] = nonlinear_to_linear(src[0]);
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_srgb8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
+ dst[0] = rgba[BCOMP]; /* no conversion */
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[RCOMP];
+}
+#endif
+
+/* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
+static void FETCH(srgba8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
+ texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
+ texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
+ texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
+}
+
+#if DIM == 3
+static void store_texel_srgba8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
+}
+#endif
+
+/* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
+static void FETCH(sargb8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
+ texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
+ texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
+ texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
+}
+
+#if DIM == 3
+static void store_texel_sargb8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+/* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
+static void FETCH(sl8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = nonlinear_to_linear(src[0]);
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_sl8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ dst[0] = rgba[RCOMP];
+}
+#endif
+
+/* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
+static void FETCH(sla8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = nonlinear_to_linear(src[0]);
+ texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
+}
+
+#if DIM == 3
+static void store_texel_sla8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RGBA_INT8 **************************************************/
+
+static void
+FETCH(rgba_int8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
+ texel[RCOMP] = (GLfloat) src[0];
+ texel[GCOMP] = (GLfloat) src[1];
+ texel[BCOMP] = (GLfloat) src[2];
+ texel[ACOMP] = (GLfloat) src[3];
+}
+
+#if DIM == 3
+static void
+store_texel_rgba_int8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLbyte *rgba = (const GLbyte *) texel;
+ GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+ dst[3] = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RGBA_INT16 **************************************************/
+
+static void
+FETCH(rgba_int16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
+ texel[RCOMP] = (GLfloat) src[0];
+ texel[GCOMP] = (GLfloat) src[1];
+ texel[BCOMP] = (GLfloat) src[2];
+ texel[ACOMP] = (GLfloat) src[3];
+}
+
+#if DIM == 3
+static void
+store_texel_rgba_int16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLshort *rgba = (const GLshort *) texel;
+ GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+ dst[3] = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RGBA_INT32 **************************************************/
+
+static void
+FETCH(rgba_int32)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
+ texel[RCOMP] = (GLfloat) src[0];
+ texel[GCOMP] = (GLfloat) src[1];
+ texel[BCOMP] = (GLfloat) src[2];
+ texel[ACOMP] = (GLfloat) src[3];
+}
+
+#if DIM == 3
+static void
+store_texel_rgba_int32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLint *rgba = (const GLint *) texel;
+ GLint *dst = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+ dst[3] = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RGBA_UINT8 **************************************************/
+
+static void
+FETCH(rgba_uint8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
+ texel[RCOMP] = (GLfloat) src[0];
+ texel[GCOMP] = (GLfloat) src[1];
+ texel[BCOMP] = (GLfloat) src[2];
+ texel[ACOMP] = (GLfloat) src[3];
+}
+
+#if DIM == 3
+static void
+store_texel_rgba_uint8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+ dst[3] = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RGBA_UINT16 **************************************************/
+
+static void
+FETCH(rgba_uint16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
+ texel[RCOMP] = (GLfloat) src[0];
+ texel[GCOMP] = (GLfloat) src[1];
+ texel[BCOMP] = (GLfloat) src[2];
+ texel[ACOMP] = (GLfloat) src[3];
+}
+
+#if DIM == 3
+static void
+store_texel_rgba_uint16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLushort *rgba = (const GLushort *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+ dst[3] = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_RGBA_UINT32 **************************************************/
+
+static void
+FETCH(rgba_uint32)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
+ texel[RCOMP] = (GLfloat) src[0];
+ texel[GCOMP] = (GLfloat) src[1];
+ texel[BCOMP] = (GLfloat) src[2];
+ texel[ACOMP] = (GLfloat) src[3];
+}
+
+#if DIM == 3
+static void
+store_texel_rgba_uint32(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLuint *rgba = (const GLuint *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+ dst[3] = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_DUDV8 ********************************************************/
+
+/* this format by definition produces 0,0,0,1 as rgba values,
+ however we'll return the dudv values as rg and fix up elsewhere */
+static void FETCH(dudv8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
+ texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
+ texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
+ texel[BCOMP] = 0;
+ texel[ACOMP] = 0;
+}
+
+
+/* MESA_FORMAT_SIGNED_R8 ***********************************************/
+
+static void FETCH(signed_r8)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
+ texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
+ texel[GCOMP] = 0.0F;
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_signed_r8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLbyte *rgba = (const GLbyte *) texel;
+ GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_A8 ***********************************************/
+
+static void FETCH(signed_a8)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
+ texel[RCOMP] = 0.0F;
+ texel[GCOMP] = 0.0F;
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
+}
+
+#if DIM == 3
+static void store_texel_signed_a8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLbyte *rgba = (const GLbyte *) texel;
+ GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
+ *dst = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_L8 ***********************************************/
+
+static void FETCH(signed_l8)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = BYTE_TO_FLOAT_TEX( s );
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_signed_l8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLbyte *rgba = (const GLbyte *) texel;
+ GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_I8 ***********************************************/
+
+static void FETCH(signed_i8)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] =
+ texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
+}
+
+#if DIM == 3
+static void store_texel_signed_i8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLbyte *rgba = (const GLbyte *) texel;
+ GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_RG88_REV ***********************************************/
+
+static void FETCH(signed_rg88_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+ texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
+ texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_signed_rg88_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLbyte *rg = (const GLbyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ dst[0] = PACK_COLOR_88(rg[GCOMP], rg[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_AL88 ***********************************************/
+
+static void FETCH(signed_al88)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
+ texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+}
+
+#if DIM == 3
+static void store_texel_signed_al88(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLbyte *rg = (const GLbyte *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
+ dst[0] = PACK_COLOR_88(rg[ACOMP], rg[RCOMP]);
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
+
+static void FETCH(signed_rgbx8888)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
+ texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
+ texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ texel[ACOMP] = 1.0f;
+}
+
+#if DIM == 3
+static void store_texel_signed_rgbx8888(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLbyte *rgba = (const GLbyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
+
+static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
+ texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
+ texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
+}
+
+#if DIM == 3
+static void store_texel_signed_rgba8888(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLbyte *rgba = (const GLbyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
+}
+#endif
+
+static void FETCH(signed_rgba8888_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
+ texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
+ texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
+}
+
+#if DIM == 3
+static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
+}
+#endif
+
+
+
+/* MESA_FORMAT_SIGNED_R16 ***********************************************/
+
+static void
+FETCH(signed_r16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+ texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
+ texel[GCOMP] = 0.0F;
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void
+store_texel_signed_r16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLshort *rgba = (const GLshort *) texel;
+ GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+ *dst = rgba[0];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_A16 ***********************************************/
+
+static void
+FETCH(signed_a16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+ texel[RCOMP] = 0.0F;
+ texel[GCOMP] = 0.0F;
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
+}
+
+#if DIM == 3
+static void
+store_texel_signed_a16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLshort *rgba = (const GLshort *) texel;
+ GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+ *dst = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_L16 ***********************************************/
+
+static void
+FETCH(signed_l16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = SHORT_TO_FLOAT_TEX( s );
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void
+store_texel_signed_l16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLshort *rgba = (const GLshort *) texel;
+ GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_I16 ***********************************************/
+
+static void
+FETCH(signed_i16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] =
+ texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
+}
+
+#if DIM == 3
+static void
+store_texel_signed_i16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLshort *rgba = (const GLshort *) texel;
+ GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+ *dst = rgba[RCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_RG1616 ***********************************************/
+
+static void
+FETCH(signed_rg1616)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
+ texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
+ texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
+ texel[BCOMP] = 0.0F;
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void
+store_texel_signed_rg1616(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLshort *rgba = (const GLshort *) texel;
+ GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_AL1616 ***********************************************/
+
+static void
+FETCH(signed_al1616)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
+ texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
+}
+
+#if DIM == 3
+static void
+store_texel_signed_al1616(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLshort *rgba = (const GLshort *) texel;
+ GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[ACOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
+
+static void
+FETCH(signed_rgb_16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
+ texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
+ texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
+ texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void
+store_texel_signed_rgb_16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLshort *rgba = (const GLshort *) texel;
+ GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+}
+#endif
+
+
+/* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
+
+static void
+FETCH(signed_rgba_16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
+ texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
+ texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
+ texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
+ texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
+}
+
+#if DIM == 3
+static void
+store_texel_signed_rgba_16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLshort *rgba = (const GLshort *) texel;
+ GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+ dst[3] = rgba[ACOMP];
+}
+#endif
+
+
+
+/* MESA_FORMAT_RGBA_16 ***********************************************/
+
+static void
+FETCH(rgba_16)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel)
+{
+ const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
+ texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
+ texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
+ texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
+ texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
+}
+
+#if DIM == 3
+static void
+store_texel_rgba_16(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLushort *rgba = (const GLushort *) texel;
+ GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+ dst[3] = rgba[ACOMP];
+}
+#endif
+
+
+
+/* MESA_FORMAT_YCBCR *********************************************************/
+
+/* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
+ * We convert YCbCr to RGB here.
+ */
+static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
+ const GLushort *src1 = src0 + 1; /* odd */
+ const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
+ const GLubyte cb = *src0 & 0xff; /* chroma U */
+ const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
+ const GLubyte cr = *src1 & 0xff; /* chroma V */
+ const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
+ GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
+ GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
+ GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
+ r *= (1.0F / 255.0F);
+ g *= (1.0F / 255.0F);
+ b *= (1.0F / 255.0F);
+ texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
+ texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
+ texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_ycbcr(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ (void) texImage;
+ (void) i;
+ (void) j;
+ (void) k;
+ (void) texel;
+ /* XXX to do */
+}
+#endif
+
+
+/* MESA_FORMAT_YCBCR_REV *****************************************************/
+
+/* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
+ * We convert YCbCr to RGB here.
+ */
+static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
+ const GLushort *src1 = src0 + 1; /* odd */
+ const GLubyte y0 = *src0 & 0xff; /* luminance */
+ const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
+ const GLubyte y1 = *src1 & 0xff; /* luminance */
+ const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
+ const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
+ GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
+ GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
+ GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
+ r *= (1.0F / 255.0F);
+ g *= (1.0F / 255.0F);
+ b *= (1.0F / 255.0F);
+ texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
+ texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
+ texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ (void) texImage;
+ (void) i;
+ (void) j;
+ (void) k;
+ (void) texel;
+ /* XXX to do */
+}
+#endif
+
+
+/* MESA_TEXFORMAT_Z24_S8 ***************************************************/
+
+static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ /* only return Z, not stencil data */
+ const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ texel[0] = ((*src) >> 8) * scale;
+ ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8);
+ ASSERT(texel[0] >= 0.0F);
+ ASSERT(texel[0] <= 1.0F);
+}
+
+#if DIM == 3
+static void store_texel_z24_s8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ /* only store Z, not stencil */
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ GLfloat depth = *((GLfloat *) texel);
+ GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
+ *dst = zi | (*dst & 0xff);
+}
+#endif
+
+
+/* MESA_TEXFORMAT_S8_Z24 ***************************************************/
+
+static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ /* only return Z, not stencil data */
+ const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ texel[0] = ((*src) & 0x00ffffff) * scale;
+ ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24);
+ ASSERT(texel[0] >= 0.0F);
+ ASSERT(texel[0] <= 1.0F);
+}
+
+#if DIM == 3
+static void store_texel_s8_z24(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ /* only store Z, not stencil */
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ GLfloat depth = *((GLfloat *) texel);
+ GLuint zi = (GLuint) (depth * 0xffffff);
+ *dst = zi | (*dst & 0xff000000);
+}
+#endif
+
+
+/* MESA_FORMAT_RGB9_E5 ******************************************************/
+
+static void FETCH(rgb9_e5)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ rgb9e5_to_float3(*src, texel);
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_rgb9_e5(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *src = (const GLfloat *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = float3_to_rgb9e5(src);
+}
+#endif
+
+
+/* MESA_FORMAT_R11_G11_B10_FLOAT *********************************************/
+
+static void FETCH(r11_g11_b10f)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ r11g11b10f_to_float3(*src, texel);
+ texel[ACOMP] = 1.0F;
+}
+
+#if DIM == 3
+static void store_texel_r11_g11_b10f(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLfloat *src = (const GLfloat *) texel;
+ GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+ *dst = float3_to_r11g11b10f(src);
+}
+#endif
+
+
+#undef TEXEL_ADDR
+#undef DIM
+#undef FETCH
diff --git a/mesalib/src/mesa/main/texformat.c b/mesalib/src/mesa/main/texformat.c
index cbebec9aa..41d9e9599 100644
--- a/mesalib/src/mesa/main/texformat.c
+++ b/mesalib/src/mesa/main/texformat.c
@@ -1,743 +1,763 @@
-/*
- * 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);
- RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_ALPHA32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_LUMINANCE16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_LUMINANCE32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_LUMINANCE_ALPHA16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_LUMINANCE_ALPHA32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_INTENSITY16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_INTENSITY32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_RGB16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_RGB32F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_RGBA16F_ARB:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- 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.EXT_texture_snorm) {
- 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_REV);
- break;
- case GL_RGB_SNORM:
- case GL_RGB8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888);
- /* FALLTHROUGH */
- case GL_RGBA_SNORM:
- case GL_RGBA8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
- break;
- case GL_ALPHA_SNORM:
- case GL_ALPHA8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_A8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
- break;
- case GL_LUMINANCE_SNORM:
- case GL_LUMINANCE8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
- break;
- case GL_LUMINANCE_ALPHA_SNORM:
- case GL_LUMINANCE8_ALPHA8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_AL88);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
- break;
- case GL_INTENSITY_SNORM:
- case GL_INTENSITY8_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_I8);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
- break;
- case GL_R16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R16);
- break;
- case GL_RG16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_GR1616);
- break;
- case GL_RGB16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGB_16);
- /* FALLTHROUGH */
- case GL_RGBA16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
- break;
- case GL_ALPHA16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_A16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
- break;
- case GL_LUMINANCE16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L16);
- /* FALLTHROUGH */
- case GL_LUMINANCE16_ALPHA16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_AL1616);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
- break;
- case GL_INTENSITY16_SNORM:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_I16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
- 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:
- RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
- break;
-
- case GL_COMPRESSED_RED:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RED_RGTC1);
- RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
- break;
-
- case GL_R16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_R16);
- break;
-
- case GL_RG:
- case GL_RG8:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RG88);
- break;
-
- case GL_COMPRESSED_RG:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RG88);
- break;
-
- case GL_RG16:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RG1616);
- break;
-
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.ARB_texture_rg && ctx->Extensions.ARB_texture_float) {
- switch (internalFormat) {
- case GL_R16F:
- RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_R32F:
- RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_RG16F:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- break;
- case GL_RG32F:
- RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
- RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
- 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 */
- }
- }
-
- if (ctx->Extensions.EXT_texture_compression_latc) {
- switch (internalFormat) {
- case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_L_LATC1);
- break;
- case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L_LATC1);
- break;
- case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_LA_LATC2);
- break;
- case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
- RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_LA_LATC2);
- break;
- default:
- ; /* fallthrough */
- }
- }
-
- if (ctx->Extensions.ATI_texture_compression_3dc) {
- switch (internalFormat) {
- case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
- RETURN_IF_SUPPORTED(MESA_FORMAT_LA_LATC2);
- 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);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_ALPHA32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_LUMINANCE16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_LUMINANCE32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_LUMINANCE_ALPHA16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_LUMINANCE_ALPHA32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_INTENSITY16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_INTENSITY32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_RGB16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_RGB32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_RGBA16F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_RGBA32F_ARB:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.EXT_texture_shared_exponent) {
+ switch (internalFormat) {
+ case GL_RGB9_E5:
+ ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_RGB9_E5_FLOAT]);
+ return MESA_FORMAT_RGB9_E5_FLOAT;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.EXT_packed_float) {
+ switch (internalFormat) {
+ case GL_R11F_G11F_B10F:
+ ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_R11_G11_B10_FLOAT]);
+ return MESA_FORMAT_R11_G11_B10_FLOAT;
+ 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.EXT_texture_snorm) {
+ 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_REV);
+ break;
+ case GL_RGB_SNORM:
+ case GL_RGB8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888);
+ /* FALLTHROUGH */
+ case GL_RGBA_SNORM:
+ case GL_RGBA8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
+ break;
+ case GL_ALPHA_SNORM:
+ case GL_ALPHA8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_A8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
+ break;
+ case GL_LUMINANCE_SNORM:
+ case GL_LUMINANCE8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
+ break;
+ case GL_LUMINANCE_ALPHA_SNORM:
+ case GL_LUMINANCE8_ALPHA8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_AL88);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
+ break;
+ case GL_INTENSITY_SNORM:
+ case GL_INTENSITY8_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_I8);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
+ break;
+ case GL_R16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R16);
+ break;
+ case GL_RG16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_GR1616);
+ break;
+ case GL_RGB16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGB_16);
+ /* FALLTHROUGH */
+ case GL_RGBA16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
+ break;
+ case GL_ALPHA16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_A16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
+ break;
+ case GL_LUMINANCE16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L16);
+ /* FALLTHROUGH */
+ case GL_LUMINANCE16_ALPHA16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_AL1616);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
+ break;
+ case GL_INTENSITY16_SNORM:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_I16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
+ 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:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
+ break;
+
+ case GL_COMPRESSED_RED:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RED_RGTC1);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
+ break;
+
+ case GL_R16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_R16);
+ break;
+
+ case GL_RG:
+ case GL_RG8:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RG88);
+ break;
+
+ case GL_COMPRESSED_RG:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RG88);
+ break;
+
+ case GL_RG16:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RG1616);
+ break;
+
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.ARB_texture_rg && ctx->Extensions.ARB_texture_float) {
+ switch (internalFormat) {
+ case GL_R16F:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_R32F:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_RG16F:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ break;
+ case GL_RG32F:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+ 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 */
+ }
+ }
+
+ if (ctx->Extensions.EXT_texture_compression_latc) {
+ switch (internalFormat) {
+ case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_L_LATC1);
+ break;
+ case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L_LATC1);
+ break;
+ case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LA_LATC2);
+ break;
+ case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_LA_LATC2);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ if (ctx->Extensions.ATI_texture_compression_3dc) {
+ switch (internalFormat) {
+ case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
+ RETURN_IF_SUPPORTED(MESA_FORMAT_LA_LATC2);
+ break;
+ default:
+ ; /* fallthrough */
+ }
+ }
+
+ _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
+ return MESA_FORMAT_NONE;
+}
+
diff --git a/mesalib/src/mesa/main/texparam.c b/mesalib/src/mesa/main/texparam.c
index 3d56dac3f..74e1f4a1b 100644
--- a/mesalib/src/mesa/main/texparam.c
+++ b/mesalib/src/mesa/main/texparam.c
@@ -1,1460 +1,1458 @@
-/*
- * 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.
- */
-
-/**
- * \file texparam.c
- *
- * glTexParameter-related functions
- */
-
-
-#include "main/glheader.h"
-#include "main/colormac.h"
-#include "main/context.h"
-#include "main/enums.h"
-#include "main/formats.h"
-#include "main/macros.h"
-#include "main/mfeatures.h"
-#include "main/mtypes.h"
-#include "main/state.h"
-#include "main/texcompress.h"
-#include "main/texparam.h"
-#include "main/teximage.h"
-#include "main/texstate.h"
-#include "main/texfetch.h"
-#include "program/prog_instruction.h"
-
-
-/**
- * Check if a coordinate wrap mode is supported for the texture target.
- * \return GL_TRUE if legal, GL_FALSE otherwise
- */
-static GLboolean
-validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
-{
- const struct gl_extensions * const e = & ctx->Extensions;
-
- if (wrap == GL_CLAMP || wrap == GL_CLAMP_TO_EDGE ||
- (wrap == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp)) {
- /* any texture target */
- return GL_TRUE;
- }
- else if (target != GL_TEXTURE_RECTANGLE_NV &&
- (wrap == GL_REPEAT ||
- (wrap == GL_MIRRORED_REPEAT &&
- e->ARB_texture_mirrored_repeat) ||
- (wrap == GL_MIRROR_CLAMP_EXT &&
- (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
- (wrap == GL_MIRROR_CLAMP_TO_EDGE_EXT &&
- (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
- (wrap == GL_MIRROR_CLAMP_TO_BORDER_EXT &&
- (e->EXT_texture_mirror_clamp)))) {
- /* non-rectangle texture */
- return GL_TRUE;
- }
-
- _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
- return GL_FALSE;
-}
-
-
-/**
- * Get current texture object for given target.
- * Return NULL if any error (and record the error).
- * Note that this is different from _mesa_select_tex_object() in that proxy
- * targets are not accepted.
- * Only the glGetTexLevelParameter() functions accept proxy targets.
- */
-static struct gl_texture_object *
-get_texobj(struct gl_context *ctx, GLenum target, GLboolean get)
-{
- struct gl_texture_unit *texUnit;
-
- if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "gl%sTexParameter(current unit)", get ? "Get" : "");
- return NULL;
- }
-
- texUnit = _mesa_get_current_tex_unit(ctx);
-
- switch (target) {
- case GL_TEXTURE_1D:
- return texUnit->CurrentTex[TEXTURE_1D_INDEX];
- case GL_TEXTURE_2D:
- return texUnit->CurrentTex[TEXTURE_2D_INDEX];
- case GL_TEXTURE_3D:
- return texUnit->CurrentTex[TEXTURE_3D_INDEX];
- case GL_TEXTURE_CUBE_MAP:
- if (ctx->Extensions.ARB_texture_cube_map) {
- return texUnit->CurrentTex[TEXTURE_CUBE_INDEX];
- }
- break;
- case GL_TEXTURE_RECTANGLE_NV:
- if (ctx->Extensions.NV_texture_rectangle) {
- return texUnit->CurrentTex[TEXTURE_RECT_INDEX];
- }
- break;
- case GL_TEXTURE_1D_ARRAY_EXT:
- if (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array) {
- return texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX];
- }
- break;
- case GL_TEXTURE_2D_ARRAY_EXT:
- if (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array) {
- return texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX];
- }
- break;
- default:
- ;
- }
-
- _mesa_error(ctx, GL_INVALID_ENUM,
- "gl%sTexParameter(target)", get ? "Get" : "");
- return NULL;
-}
-
-
-/**
- * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
- * \return -1 if error.
- */
-static GLint
-comp_to_swizzle(GLenum comp)
-{
- switch (comp) {
- case GL_RED:
- return SWIZZLE_X;
- case GL_GREEN:
- return SWIZZLE_Y;
- case GL_BLUE:
- return SWIZZLE_Z;
- case GL_ALPHA:
- return SWIZZLE_W;
- case GL_ZERO:
- return SWIZZLE_ZERO;
- case GL_ONE:
- return SWIZZLE_ONE;
- default:
- return -1;
- }
-}
-
-
-static void
-set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
-{
- ASSERT(comp < 4);
- ASSERT(swz <= SWIZZLE_NIL);
- {
- GLuint mask = 0x7 << (3 * comp);
- GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
- *swizzle = s;
- }
-}
-
-
-/**
- * This is called just prior to changing any texture object state which
- * will not effect texture completeness.
- */
-static INLINE void
-flush(struct gl_context *ctx)
-{
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-}
-
-
-/**
- * This is called just prior to changing any texture object state which
- * can effect texture completeness (texture base level, max level,
- * minification filter).
- * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
- * state flag and then mark the texture object as 'incomplete' so that any
- * per-texture derived state gets recomputed.
- */
-static INLINE void
-incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
-{
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texObj->_Complete = GL_FALSE;
-}
-
-
-/**
- * Set an integer-valued texture parameter
- * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
- */
-static GLboolean
-set_tex_parameteri(struct gl_context *ctx,
- struct gl_texture_object *texObj,
- GLenum pname, const GLint *params)
-{
- switch (pname) {
- case GL_TEXTURE_MIN_FILTER:
- if (texObj->Sampler.MinFilter == params[0])
- return GL_FALSE;
- switch (params[0]) {
- case GL_NEAREST:
- case GL_LINEAR:
- incomplete(ctx, texObj);
- texObj->Sampler.MinFilter = params[0];
- return GL_TRUE;
- case GL_NEAREST_MIPMAP_NEAREST:
- case GL_LINEAR_MIPMAP_NEAREST:
- case GL_NEAREST_MIPMAP_LINEAR:
- case GL_LINEAR_MIPMAP_LINEAR:
- if (texObj->Target != GL_TEXTURE_RECTANGLE_NV) {
- incomplete(ctx, texObj);
- texObj->Sampler.MinFilter = params[0];
- return GL_TRUE;
- }
- /* fall-through */
- default:
- goto invalid_param;
- }
- return GL_FALSE;
-
- case GL_TEXTURE_MAG_FILTER:
- if (texObj->Sampler.MagFilter == params[0])
- return GL_FALSE;
- switch (params[0]) {
- case GL_NEAREST:
- case GL_LINEAR:
- flush(ctx); /* does not effect completeness */
- texObj->Sampler.MagFilter = params[0];
- return GL_TRUE;
- default:
- goto invalid_param;
- }
- return GL_FALSE;
-
- case GL_TEXTURE_WRAP_S:
- if (texObj->Sampler.WrapS == params[0])
- return GL_FALSE;
- if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
- flush(ctx);
- texObj->Sampler.WrapS = params[0];
- return GL_TRUE;
- }
- return GL_FALSE;
-
- case GL_TEXTURE_WRAP_T:
- if (texObj->Sampler.WrapT == params[0])
- return GL_FALSE;
- if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
- flush(ctx);
- texObj->Sampler.WrapT = params[0];
- return GL_TRUE;
- }
- return GL_FALSE;
-
- case GL_TEXTURE_WRAP_R:
- if (texObj->Sampler.WrapR == params[0])
- return GL_FALSE;
- if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
- flush(ctx);
- texObj->Sampler.WrapR = params[0];
- return GL_TRUE;
- }
- return GL_FALSE;
-
- case GL_TEXTURE_BASE_LEVEL:
- if (texObj->BaseLevel == params[0])
- return GL_FALSE;
- if (params[0] < 0 ||
- (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0)) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexParameter(param=%d)", params[0]);
- return GL_FALSE;
- }
- incomplete(ctx, texObj);
- texObj->BaseLevel = params[0];
- return GL_TRUE;
-
- case GL_TEXTURE_MAX_LEVEL:
- if (texObj->MaxLevel == params[0])
- return GL_FALSE;
- if (params[0] < 0 || texObj->Target == GL_TEXTURE_RECTANGLE_ARB) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexParameter(param=%d)", params[0]);
- return GL_FALSE;
- }
- incomplete(ctx, texObj);
- texObj->MaxLevel = params[0];
- return GL_TRUE;
-
- case GL_GENERATE_MIPMAP_SGIS:
- if (texObj->GenerateMipmap != params[0]) {
- /* no flush() */
- texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
- return GL_TRUE;
- }
- return GL_FALSE;
-
- case GL_TEXTURE_COMPARE_MODE_ARB:
- if (ctx->Extensions.ARB_shadow) {
- if (texObj->Sampler.CompareMode == params[0])
- return GL_FALSE;
- if (params[0] == GL_NONE ||
- params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
- flush(ctx);
- texObj->Sampler.CompareMode = params[0];
- return GL_TRUE;
- }
- goto invalid_param;
- }
- goto invalid_pname;
-
- case GL_TEXTURE_COMPARE_FUNC_ARB:
- if (ctx->Extensions.ARB_shadow) {
- if (texObj->Sampler.CompareFunc == params[0])
- return GL_FALSE;
- switch (params[0]) {
- case GL_LEQUAL:
- case GL_GEQUAL:
- flush(ctx);
- texObj->Sampler.CompareFunc = params[0];
- return GL_TRUE;
- case GL_EQUAL:
- case GL_NOTEQUAL:
- case GL_LESS:
- case GL_GREATER:
- case GL_ALWAYS:
- case GL_NEVER:
- if (ctx->Extensions.EXT_shadow_funcs) {
- flush(ctx);
- texObj->Sampler.CompareFunc = params[0];
- return GL_TRUE;
- }
- /* fall-through */
- default:
- goto invalid_param;
- }
- }
- goto invalid_pname;
-
- case GL_DEPTH_TEXTURE_MODE_ARB:
- if (ctx->Extensions.ARB_depth_texture) {
- if (texObj->Sampler.DepthMode == params[0])
- return GL_FALSE;
- if (params[0] == GL_LUMINANCE ||
- params[0] == GL_INTENSITY ||
- params[0] == GL_ALPHA ||
- (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
- flush(ctx);
- texObj->Sampler.DepthMode = params[0];
- return GL_TRUE;
- }
- goto invalid_param;
- }
- goto invalid_pname;
-
-#if FEATURE_OES_draw_texture
- case GL_TEXTURE_CROP_RECT_OES:
- texObj->CropRect[0] = params[0];
- texObj->CropRect[1] = params[1];
- texObj->CropRect[2] = params[2];
- texObj->CropRect[3] = params[3];
- return GL_TRUE;
-#endif
-
- case GL_TEXTURE_SWIZZLE_R_EXT:
- case GL_TEXTURE_SWIZZLE_G_EXT:
- case GL_TEXTURE_SWIZZLE_B_EXT:
- case GL_TEXTURE_SWIZZLE_A_EXT:
- if (ctx->Extensions.EXT_texture_swizzle) {
- const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
- const GLint swz = comp_to_swizzle(params[0]);
- if (swz < 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexParameter(swizzle 0x%x)", params[0]);
- return GL_FALSE;
- }
- ASSERT(comp < 4);
- if (swz >= 0) {
- flush(ctx);
- texObj->Swizzle[comp] = params[0];
- set_swizzle_component(&texObj->_Swizzle, comp, swz);
- return GL_TRUE;
- }
- }
- goto invalid_pname;
-
- case GL_TEXTURE_SWIZZLE_RGBA_EXT:
- if (ctx->Extensions.EXT_texture_swizzle) {
- GLuint comp;
- flush(ctx);
- for (comp = 0; comp < 4; comp++) {
- const GLint swz = comp_to_swizzle(params[comp]);
- if (swz >= 0) {
- texObj->Swizzle[comp] = params[comp];
- set_swizzle_component(&texObj->_Swizzle, comp, swz);
- }
- else {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexParameter(swizzle 0x%x)", params[comp]);
- return GL_FALSE;
- }
- }
- return GL_TRUE;
- }
- goto invalid_pname;
-
- case GL_TEXTURE_SRGB_DECODE_EXT:
- if (ctx->Extensions.EXT_texture_sRGB_decode) {
- GLenum decode = params[0];
- if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
- if (texObj->Sampler.sRGBDecode != decode) {
- flush(ctx);
- texObj->Sampler.sRGBDecode = decode;
- _mesa_update_fetch_functions(texObj);
- }
- return GL_TRUE;
- }
- }
- goto invalid_pname;
-
- default:
- goto invalid_pname;
- }
-
-invalid_pname:
- _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
- _mesa_lookup_enum_by_nr(pname));
- return GL_FALSE;
-
-invalid_param:
- _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param=%s)",
- _mesa_lookup_enum_by_nr(params[0]));
- return GL_FALSE;
-}
-
-
-/**
- * Set a float-valued texture parameter
- * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
- */
-static GLboolean
-set_tex_parameterf(struct gl_context *ctx,
- struct gl_texture_object *texObj,
- GLenum pname, const GLfloat *params)
-{
- switch (pname) {
- case GL_TEXTURE_MIN_LOD:
- if (texObj->Sampler.MinLod == params[0])
- return GL_FALSE;
- flush(ctx);
- texObj->Sampler.MinLod = params[0];
- return GL_TRUE;
-
- case GL_TEXTURE_MAX_LOD:
- if (texObj->Sampler.MaxLod == params[0])
- return GL_FALSE;
- flush(ctx);
- texObj->Sampler.MaxLod = params[0];
- return GL_TRUE;
-
- case GL_TEXTURE_PRIORITY:
- flush(ctx);
- texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
- return GL_TRUE;
-
- case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- if (ctx->Extensions.EXT_texture_filter_anisotropic) {
- if (texObj->Sampler.MaxAnisotropy == params[0])
- return GL_FALSE;
- if (params[0] < 1.0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
- return GL_FALSE;
- }
- flush(ctx);
- /* clamp to max, that's what NVIDIA does */
- texObj->Sampler.MaxAnisotropy = MIN2(params[0],
- ctx->Const.MaxTextureMaxAnisotropy);
- return GL_TRUE;
- }
- else {
- static GLuint count = 0;
- if (count++ < 10)
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
- }
- return GL_FALSE;
-
- case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
- if (ctx->Extensions.ARB_shadow_ambient) {
- if (texObj->Sampler.CompareFailValue != params[0]) {
- flush(ctx);
- texObj->Sampler.CompareFailValue = CLAMP(params[0], 0.0F, 1.0F);
- return GL_TRUE;
- }
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
- }
- return GL_FALSE;
-
- case GL_TEXTURE_LOD_BIAS:
- /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
- if (ctx->Extensions.EXT_texture_lod_bias) {
- if (texObj->Sampler.LodBias != params[0]) {
- flush(ctx);
- texObj->Sampler.LodBias = params[0];
- return GL_TRUE;
- }
- return GL_FALSE;
- }
- break;
-
- case GL_TEXTURE_BORDER_COLOR:
- flush(ctx);
- /* ARB_texture_float disables clamping */
- if (ctx->Extensions.ARB_texture_float) {
- texObj->Sampler.BorderColor.f[RCOMP] = params[0];
- texObj->Sampler.BorderColor.f[GCOMP] = params[1];
- texObj->Sampler.BorderColor.f[BCOMP] = params[2];
- texObj->Sampler.BorderColor.f[ACOMP] = params[3];
- } else {
- texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
- texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
- texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
- texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
- }
- return GL_TRUE;
-
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
- }
- return GL_FALSE;
-}
-
-
-void GLAPIENTRY
-_mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
-{
- GLboolean need_update;
- struct gl_texture_object *texObj;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- texObj = get_texobj(ctx, target, GL_FALSE);
- if (!texObj)
- return;
-
- switch (pname) {
- case GL_TEXTURE_MIN_FILTER:
- case GL_TEXTURE_MAG_FILTER:
- case GL_TEXTURE_WRAP_S:
- case GL_TEXTURE_WRAP_T:
- case GL_TEXTURE_WRAP_R:
- case GL_TEXTURE_BASE_LEVEL:
- case GL_TEXTURE_MAX_LEVEL:
- case GL_GENERATE_MIPMAP_SGIS:
- case GL_TEXTURE_COMPARE_MODE_ARB:
- case GL_TEXTURE_COMPARE_FUNC_ARB:
- case GL_DEPTH_TEXTURE_MODE_ARB:
- case GL_TEXTURE_SRGB_DECODE_EXT:
- {
- /* convert float param to int */
- GLint p[4];
- p[0] = (GLint) param;
- p[1] = p[2] = p[3] = 0;
- need_update = set_tex_parameteri(ctx, texObj, pname, p);
- }
- break;
- default:
- {
- /* this will generate an error if pname is illegal */
- GLfloat p[4];
- p[0] = param;
- p[1] = p[2] = p[3] = 0.0F;
- need_update = set_tex_parameterf(ctx, texObj, pname, p);
- }
- }
-
- if (ctx->Driver.TexParameter && need_update) {
- ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
- }
-}
-
-
-void GLAPIENTRY
-_mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
-{
- GLboolean need_update;
- struct gl_texture_object *texObj;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- texObj = get_texobj(ctx, target, GL_FALSE);
- if (!texObj)
- return;
-
- switch (pname) {
- case GL_TEXTURE_MIN_FILTER:
- case GL_TEXTURE_MAG_FILTER:
- case GL_TEXTURE_WRAP_S:
- case GL_TEXTURE_WRAP_T:
- case GL_TEXTURE_WRAP_R:
- case GL_TEXTURE_BASE_LEVEL:
- case GL_TEXTURE_MAX_LEVEL:
- case GL_GENERATE_MIPMAP_SGIS:
- case GL_TEXTURE_COMPARE_MODE_ARB:
- case GL_TEXTURE_COMPARE_FUNC_ARB:
- case GL_DEPTH_TEXTURE_MODE_ARB:
- case GL_TEXTURE_SRGB_DECODE_EXT:
- {
- /* convert float param to int */
- GLint p[4];
- p[0] = (GLint) params[0];
- p[1] = p[2] = p[3] = 0;
- need_update = set_tex_parameteri(ctx, texObj, pname, p);
- }
- break;
-
-#if FEATURE_OES_draw_texture
- case GL_TEXTURE_CROP_RECT_OES:
- {
- /* convert float params to int */
- GLint iparams[4];
- iparams[0] = (GLint) params[0];
- iparams[1] = (GLint) params[1];
- iparams[2] = (GLint) params[2];
- iparams[3] = (GLint) params[3];
- need_update = set_tex_parameteri(ctx, texObj, pname, iparams);
- }
- break;
-#endif
-
- default:
- /* this will generate an error if pname is illegal */
- need_update = set_tex_parameterf(ctx, texObj, pname, params);
- }
-
- if (ctx->Driver.TexParameter && need_update) {
- ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
- }
-}
-
-
-void GLAPIENTRY
-_mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
-{
- GLboolean need_update;
- struct gl_texture_object *texObj;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- texObj = get_texobj(ctx, target, GL_FALSE);
- if (!texObj)
- return;
-
- switch (pname) {
- case GL_TEXTURE_MIN_LOD:
- case GL_TEXTURE_MAX_LOD:
- case GL_TEXTURE_PRIORITY:
- case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- case GL_TEXTURE_LOD_BIAS:
- case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
- {
- GLfloat fparam[4];
- fparam[0] = (GLfloat) param;
- fparam[1] = fparam[2] = fparam[3] = 0.0F;
- /* convert int param to float */
- need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
- }
- break;
- default:
- /* this will generate an error if pname is illegal */
- {
- GLint iparam[4];
- iparam[0] = param;
- iparam[1] = iparam[2] = iparam[3] = 0;
- need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
- }
- }
-
- if (ctx->Driver.TexParameter && need_update) {
- GLfloat fparam = (GLfloat) param;
- ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
- }
-}
-
-
-void GLAPIENTRY
-_mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
-{
- GLboolean need_update;
- struct gl_texture_object *texObj;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- texObj = get_texobj(ctx, target, GL_FALSE);
- if (!texObj)
- return;
-
- switch (pname) {
- case GL_TEXTURE_BORDER_COLOR:
- {
- /* convert int params to float */
- GLfloat fparams[4];
- fparams[0] = INT_TO_FLOAT(params[0]);
- fparams[1] = INT_TO_FLOAT(params[1]);
- fparams[2] = INT_TO_FLOAT(params[2]);
- fparams[3] = INT_TO_FLOAT(params[3]);
- need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
- }
- break;
- case GL_TEXTURE_MIN_LOD:
- case GL_TEXTURE_MAX_LOD:
- case GL_TEXTURE_PRIORITY:
- case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- case GL_TEXTURE_LOD_BIAS:
- case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
- {
- /* convert int param to float */
- GLfloat fparams[4];
- fparams[0] = (GLfloat) params[0];
- fparams[1] = fparams[2] = fparams[3] = 0.0F;
- need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
- }
- break;
- default:
- /* this will generate an error if pname is illegal */
- need_update = set_tex_parameteri(ctx, texObj, pname, params);
- }
-
- if (ctx->Driver.TexParameter && need_update) {
- GLfloat fparams[4];
- fparams[0] = INT_TO_FLOAT(params[0]);
- if (pname == GL_TEXTURE_BORDER_COLOR ||
- pname == GL_TEXTURE_CROP_RECT_OES) {
- fparams[1] = INT_TO_FLOAT(params[1]);
- fparams[2] = INT_TO_FLOAT(params[2]);
- fparams[3] = INT_TO_FLOAT(params[3]);
- }
- ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
- }
-}
-
-
-/**
- * Set tex parameter to integer value(s). Primarily intended to set
- * integer-valued texture border color (for integer-valued textures).
- * New in GL 3.0.
- */
-void GLAPIENTRY
-_mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
-{
- struct gl_texture_object *texObj;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- texObj = get_texobj(ctx, target, GL_FALSE);
- if (!texObj)
- return;
-
- switch (pname) {
- case GL_TEXTURE_BORDER_COLOR:
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- /* set the integer-valued border color */
- COPY_4V(texObj->Sampler.BorderColor.i, params);
- break;
- default:
- _mesa_TexParameteriv(target, pname, params);
- break;
- }
- /* XXX no driver hook for TexParameterIiv() yet */
-}
-
-
-/**
- * Set tex parameter to unsigned integer value(s). Primarily intended to set
- * uint-valued texture border color (for integer-valued textures).
- * New in GL 3.0
- */
-void GLAPIENTRY
-_mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
-{
- struct gl_texture_object *texObj;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- texObj = get_texobj(ctx, target, GL_FALSE);
- if (!texObj)
- return;
-
- switch (pname) {
- case GL_TEXTURE_BORDER_COLOR:
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- /* set the unsigned integer-valued border color */
- COPY_4V(texObj->Sampler.BorderColor.ui, params);
- break;
- default:
- _mesa_TexParameteriv(target, pname, (const GLint *) params);
- break;
- }
- /* XXX no driver hook for TexParameterIuiv() yet */
-}
-
-
-
-
-void GLAPIENTRY
-_mesa_GetTexLevelParameterfv( GLenum target, GLint level,
- GLenum pname, GLfloat *params )
-{
- GLint iparam;
- _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
- *params = (GLfloat) iparam;
-}
-
-
-void GLAPIENTRY
-_mesa_GetTexLevelParameteriv( GLenum target, GLint level,
- GLenum pname, GLint *params )
-{
- const struct gl_texture_unit *texUnit;
- struct gl_texture_object *texObj;
- const struct gl_texture_image *img = NULL;
- GLint maxLevels;
- gl_format texFormat;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTexLevelParameteriv(current unit)");
- return;
- }
-
- texUnit = _mesa_get_current_tex_unit(ctx);
-
- /* this will catch bad target values */
- maxLevels = _mesa_max_texture_levels(ctx, target);
- if (maxLevels == 0) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetTexLevelParameter[if]v(target=0x%x)", target);
- return;
- }
-
- if (level < 0 || level >= maxLevels) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
- return;
- }
-
- texObj = _mesa_select_tex_object(ctx, texUnit, target);
-
- img = _mesa_select_tex_image(ctx, texObj, target, level);
- if (!img || !img->TexFormat) {
- /* undefined texture image */
- if (pname == GL_TEXTURE_COMPONENTS)
- *params = 1;
- else
- *params = 0;
- return;
- }
-
- texFormat = img->TexFormat;
-
- switch (pname) {
- case GL_TEXTURE_WIDTH:
- *params = img->Width;
- break;
- case GL_TEXTURE_HEIGHT:
- *params = img->Height;
- break;
- case GL_TEXTURE_DEPTH:
- *params = img->Depth;
- break;
- case GL_TEXTURE_INTERNAL_FORMAT:
- if (_mesa_is_format_compressed(texFormat)) {
- /* need to return the actual compressed format */
- *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
- }
- else {
- /* return the user's requested internal format */
- *params = img->InternalFormat;
- }
- break;
- case GL_TEXTURE_BORDER:
- *params = img->Border;
- break;
- case GL_TEXTURE_RED_SIZE:
- if (img->_BaseFormat == GL_RED) {
- *params = _mesa_get_format_bits(texFormat, pname);
- break;
- }
- /* FALLTHROUGH */
- case GL_TEXTURE_GREEN_SIZE:
- if (img->_BaseFormat == GL_RG) {
- *params = _mesa_get_format_bits(texFormat, pname);
- break;
- }
- /* FALLTHROUGH */
- case GL_TEXTURE_BLUE_SIZE:
- if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
- *params = _mesa_get_format_bits(texFormat, pname);
- else
- *params = 0;
- break;
- case GL_TEXTURE_ALPHA_SIZE:
- if (img->_BaseFormat == GL_ALPHA ||
- img->_BaseFormat == GL_LUMINANCE_ALPHA ||
- img->_BaseFormat == GL_RGBA)
- *params = _mesa_get_format_bits(texFormat, pname);
- else
- *params = 0;
- break;
- case GL_TEXTURE_INTENSITY_SIZE:
- if (img->_BaseFormat != GL_INTENSITY)
- *params = 0;
- else {
- *params = _mesa_get_format_bits(texFormat, pname);
- if (*params == 0) {
- /* intensity probably stored as rgb texture */
- *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
- _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
- }
- }
- break;
- case GL_TEXTURE_LUMINANCE_SIZE:
- if (img->_BaseFormat != GL_LUMINANCE &&
- img->_BaseFormat != GL_LUMINANCE_ALPHA)
- *params = 0;
- else {
- *params = _mesa_get_format_bits(texFormat, pname);
- if (*params == 0) {
- /* luminance probably stored as rgb texture */
- *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
- _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
- }
- }
- break;
- case GL_TEXTURE_INDEX_SIZE_EXT:
- if (img->_BaseFormat == GL_COLOR_INDEX)
- *params = _mesa_get_format_bits(texFormat, pname);
- else
- *params = 0;
- break;
- case GL_TEXTURE_DEPTH_SIZE_ARB:
- if (ctx->Extensions.ARB_depth_texture)
- *params = _mesa_get_format_bits(texFormat, pname);
- else
- goto invalid_pname;
- break;
- case GL_TEXTURE_STENCIL_SIZE_EXT:
- if (ctx->Extensions.EXT_packed_depth_stencil ||
- ctx->Extensions.ARB_framebuffer_object) {
- *params = _mesa_get_format_bits(texFormat, pname);
- }
- else {
- goto invalid_pname;
- }
- break;
- case GL_TEXTURE_SHARED_SIZE:
- if (ctx->VersionMajor >= 3) {
- /* XXX return number of exponent bits for shared exponent texture
- * formats, like GL_RGB9_E5.
- */
- *params = 0;
- }
- else {
- goto invalid_pname;
- }
- break;
-
- /* GL_ARB_texture_compression */
- case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
- if (_mesa_is_format_compressed(texFormat) &&
- !_mesa_is_proxy_texture(target)) {
- *params = _mesa_format_image_size(texFormat, img->Width,
- img->Height, img->Depth);
- }
- else {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTexLevelParameter[if]v(pname)");
- }
- break;
- case GL_TEXTURE_COMPRESSED:
- *params = (GLint) _mesa_is_format_compressed(texFormat);
- break;
-
- /* GL_ARB_texture_float */
- case GL_TEXTURE_RED_TYPE_ARB:
- if (ctx->Extensions.ARB_texture_float) {
- *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE) ?
- _mesa_get_format_datatype(texFormat) : GL_NONE;
- }
- else {
- goto invalid_pname;
- }
- break;
- case GL_TEXTURE_GREEN_TYPE_ARB:
- if (ctx->Extensions.ARB_texture_float) {
- *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE) ?
- _mesa_get_format_datatype(texFormat) : GL_NONE;
- }
- else {
- goto invalid_pname;
- }
- break;
- case GL_TEXTURE_BLUE_TYPE_ARB:
- if (ctx->Extensions.ARB_texture_float) {
- *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_BLUE_SIZE) ?
- _mesa_get_format_datatype(texFormat) : GL_NONE;
- }
- else {
- goto invalid_pname;
- }
- break;
- case GL_TEXTURE_ALPHA_TYPE_ARB:
- if (ctx->Extensions.ARB_texture_float) {
- *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_ALPHA_SIZE) ?
- _mesa_get_format_datatype(texFormat) : GL_NONE;
- }
- else {
- goto invalid_pname;
- }
- break;
- case GL_TEXTURE_LUMINANCE_TYPE_ARB:
- if (ctx->Extensions.ARB_texture_float) {
- *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_LUMINANCE_SIZE) ?
- _mesa_get_format_datatype(texFormat) : GL_NONE;
- }
- else {
- goto invalid_pname;
- }
- break;
- case GL_TEXTURE_INTENSITY_TYPE_ARB:
- if (ctx->Extensions.ARB_texture_float) {
- *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_INTENSITY_SIZE) ?
- _mesa_get_format_datatype(texFormat) : GL_NONE;
- }
- else {
- goto invalid_pname;
- }
- break;
- case GL_TEXTURE_DEPTH_TYPE_ARB:
- if (ctx->Extensions.ARB_texture_float) {
- *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_DEPTH_SIZE) ?
- _mesa_get_format_datatype(texFormat) : GL_NONE;
- }
- else {
- goto invalid_pname;
- }
- break;
-
- default:
- goto invalid_pname;
- }
-
- /* no error if we get here */
- return;
-
-invalid_pname:
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetTexLevelParameter[if]v(pname=%s)",
- _mesa_lookup_enum_by_nr(pname));
-}
-
-
-
-void GLAPIENTRY
-_mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
-{
- struct gl_texture_object *obj;
- GLboolean error = GL_FALSE;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- obj = get_texobj(ctx, target, GL_TRUE);
- if (!obj)
- return;
-
- _mesa_lock_texture(ctx, obj);
- switch (pname) {
- case GL_TEXTURE_MAG_FILTER:
- *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
- break;
- case GL_TEXTURE_MIN_FILTER:
- *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
- break;
- case GL_TEXTURE_WRAP_S:
- *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
- break;
- case GL_TEXTURE_WRAP_T:
- *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
- break;
- case GL_TEXTURE_WRAP_R:
- *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
- break;
- case GL_TEXTURE_BORDER_COLOR:
- if(ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
- _mesa_update_state_locked(ctx);
- if(ctx->Color._ClampFragmentColor)
- {
- params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
- params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
- params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
- params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
- }
- else
- {
- params[0] = obj->Sampler.BorderColor.f[0];
- params[1] = obj->Sampler.BorderColor.f[1];
- params[2] = obj->Sampler.BorderColor.f[2];
- params[3] = obj->Sampler.BorderColor.f[3];
- }
- break;
- case GL_TEXTURE_RESIDENT:
- {
- GLboolean resident;
- if (ctx->Driver.IsTextureResident)
- resident = ctx->Driver.IsTextureResident(ctx, obj);
- else
- resident = GL_TRUE;
- *params = ENUM_TO_FLOAT(resident);
- }
- break;
- case GL_TEXTURE_PRIORITY:
- *params = obj->Priority;
- break;
- case GL_TEXTURE_MIN_LOD:
- *params = obj->Sampler.MinLod;
- break;
- case GL_TEXTURE_MAX_LOD:
- *params = obj->Sampler.MaxLod;
- break;
- case GL_TEXTURE_BASE_LEVEL:
- *params = (GLfloat) obj->BaseLevel;
- break;
- case GL_TEXTURE_MAX_LEVEL:
- *params = (GLfloat) obj->MaxLevel;
- break;
- case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- if (ctx->Extensions.EXT_texture_filter_anisotropic) {
- *params = obj->Sampler.MaxAnisotropy;
- }
- else
- error = GL_TRUE;
- break;
- case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
- if (ctx->Extensions.ARB_shadow_ambient) {
- *params = obj->Sampler.CompareFailValue;
- }
- else
- error = GL_TRUE;
- break;
- case GL_GENERATE_MIPMAP_SGIS:
- *params = (GLfloat) obj->GenerateMipmap;
- break;
- case GL_TEXTURE_COMPARE_MODE_ARB:
- if (ctx->Extensions.ARB_shadow) {
- *params = (GLfloat) obj->Sampler.CompareMode;
- }
- else
- error = GL_TRUE;
- break;
- case GL_TEXTURE_COMPARE_FUNC_ARB:
- if (ctx->Extensions.ARB_shadow) {
- *params = (GLfloat) obj->Sampler.CompareFunc;
- }
- else
- error = GL_TRUE;
- break;
- case GL_DEPTH_TEXTURE_MODE_ARB:
- if (ctx->Extensions.ARB_depth_texture) {
- *params = (GLfloat) obj->Sampler.DepthMode;
- }
- else
- error = GL_TRUE;
- break;
- case GL_TEXTURE_LOD_BIAS:
- if (ctx->Extensions.EXT_texture_lod_bias) {
- *params = obj->Sampler.LodBias;
- }
- else
- error = GL_TRUE;
- break;
-#if FEATURE_OES_draw_texture
- case GL_TEXTURE_CROP_RECT_OES:
- params[0] = obj->CropRect[0];
- params[1] = obj->CropRect[1];
- params[2] = obj->CropRect[2];
- params[3] = obj->CropRect[3];
- break;
-#endif
-
- case GL_TEXTURE_SWIZZLE_R_EXT:
- case GL_TEXTURE_SWIZZLE_G_EXT:
- case GL_TEXTURE_SWIZZLE_B_EXT:
- case GL_TEXTURE_SWIZZLE_A_EXT:
- if (ctx->Extensions.EXT_texture_swizzle) {
- GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
- *params = (GLfloat) obj->Swizzle[comp];
- }
- else {
- error = GL_TRUE;
- }
- break;
-
- case GL_TEXTURE_SWIZZLE_RGBA_EXT:
- if (ctx->Extensions.EXT_texture_swizzle) {
- GLuint comp;
- for (comp = 0; comp < 4; comp++) {
- params[comp] = (GLfloat) obj->Swizzle[comp];
- }
- }
- else {
- error = GL_TRUE;
- }
- break;
-
- default:
- error = GL_TRUE;
- break;
- }
-
- if (error)
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)",
- pname);
-
- _mesa_unlock_texture(ctx, obj);
-}
-
-
-void GLAPIENTRY
-_mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
-{
- struct gl_texture_object *obj;
- GLboolean error = GL_FALSE;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- obj = get_texobj(ctx, target, GL_TRUE);
- if (!obj)
- return;
-
- _mesa_lock_texture(ctx, obj);
- switch (pname) {
- case GL_TEXTURE_MAG_FILTER:
- *params = (GLint) obj->Sampler.MagFilter;
- break;;
- case GL_TEXTURE_MIN_FILTER:
- *params = (GLint) obj->Sampler.MinFilter;
- break;;
- case GL_TEXTURE_WRAP_S:
- *params = (GLint) obj->Sampler.WrapS;
- break;;
- case GL_TEXTURE_WRAP_T:
- *params = (GLint) obj->Sampler.WrapT;
- break;;
- case GL_TEXTURE_WRAP_R:
- *params = (GLint) obj->Sampler.WrapR;
- break;;
- case GL_TEXTURE_BORDER_COLOR:
- {
- GLfloat b[4];
- b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
- b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
- b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
- b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
- params[0] = FLOAT_TO_INT(b[0]);
- params[1] = FLOAT_TO_INT(b[1]);
- params[2] = FLOAT_TO_INT(b[2]);
- params[3] = FLOAT_TO_INT(b[3]);
- }
- break;;
- case GL_TEXTURE_RESIDENT:
- {
- GLboolean resident;
- if (ctx->Driver.IsTextureResident)
- resident = ctx->Driver.IsTextureResident(ctx, obj);
- else
- resident = GL_TRUE;
- *params = (GLint) resident;
- }
- break;;
- case GL_TEXTURE_PRIORITY:
- *params = FLOAT_TO_INT(obj->Priority);
- break;;
- case GL_TEXTURE_MIN_LOD:
- *params = (GLint) obj->Sampler.MinLod;
- break;;
- case GL_TEXTURE_MAX_LOD:
- *params = (GLint) obj->Sampler.MaxLod;
- break;;
- case GL_TEXTURE_BASE_LEVEL:
- *params = obj->BaseLevel;
- break;;
- case GL_TEXTURE_MAX_LEVEL:
- *params = obj->MaxLevel;
- break;;
- case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- if (ctx->Extensions.EXT_texture_filter_anisotropic) {
- *params = (GLint) obj->Sampler.MaxAnisotropy;
- }
- else {
- error = GL_TRUE;
- }
- break;
- case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
- if (ctx->Extensions.ARB_shadow_ambient) {
- *params = (GLint) FLOAT_TO_INT(obj->Sampler.CompareFailValue);
- }
- else {
- error = GL_TRUE;
- }
- break;
- case GL_GENERATE_MIPMAP_SGIS:
- *params = (GLint) obj->GenerateMipmap;
- break;
- case GL_TEXTURE_COMPARE_MODE_ARB:
- if (ctx->Extensions.ARB_shadow) {
- *params = (GLint) obj->Sampler.CompareMode;
- }
- else {
- error = GL_TRUE;
- }
- break;
- case GL_TEXTURE_COMPARE_FUNC_ARB:
- if (ctx->Extensions.ARB_shadow) {
- *params = (GLint) obj->Sampler.CompareFunc;
- }
- else {
- error = GL_TRUE;
- }
- break;
- case GL_DEPTH_TEXTURE_MODE_ARB:
- if (ctx->Extensions.ARB_depth_texture) {
- *params = (GLint) obj->Sampler.DepthMode;
- }
- else {
- error = GL_TRUE;
- }
- break;
- case GL_TEXTURE_LOD_BIAS:
- if (ctx->Extensions.EXT_texture_lod_bias) {
- *params = (GLint) obj->Sampler.LodBias;
- }
- else {
- error = GL_TRUE;
- }
- break;
-#if FEATURE_OES_draw_texture
- case GL_TEXTURE_CROP_RECT_OES:
- params[0] = obj->CropRect[0];
- params[1] = obj->CropRect[1];
- params[2] = obj->CropRect[2];
- params[3] = obj->CropRect[3];
- break;
-#endif
- case GL_TEXTURE_SWIZZLE_R_EXT:
- case GL_TEXTURE_SWIZZLE_G_EXT:
- case GL_TEXTURE_SWIZZLE_B_EXT:
- case GL_TEXTURE_SWIZZLE_A_EXT:
- if (ctx->Extensions.EXT_texture_swizzle) {
- GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
- *params = obj->Swizzle[comp];
- }
- else {
- error = GL_TRUE;
- }
- break;
-
- case GL_TEXTURE_SWIZZLE_RGBA_EXT:
- if (ctx->Extensions.EXT_texture_swizzle) {
- COPY_4V(params, obj->Swizzle);
- }
- else {
- error = GL_TRUE;
- }
- break;
-
- default:
- ; /* silence warnings */
- }
-
- if (error)
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)",
- pname);
-
- _mesa_unlock_texture(ctx, obj);
-}
-
-
-/** New in GL 3.0 */
-void GLAPIENTRY
-_mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
-{
- struct gl_texture_object *texObj;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- texObj = get_texobj(ctx, target, GL_TRUE);
-
- switch (pname) {
- case GL_TEXTURE_BORDER_COLOR:
- COPY_4V(params, texObj->Sampler.BorderColor.i);
- break;
- default:
- _mesa_GetTexParameteriv(target, pname, params);
- }
-}
-
-
-/** New in GL 3.0 */
-void GLAPIENTRY
-_mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
-{
- struct gl_texture_object *texObj;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- texObj = get_texobj(ctx, target, GL_TRUE);
-
- switch (pname) {
- case GL_TEXTURE_BORDER_COLOR:
- COPY_4V(params, texObj->Sampler.BorderColor.i);
- break;
- default:
- {
- GLint ip[4];
- _mesa_GetTexParameteriv(target, pname, ip);
- params[0] = ip[0];
- if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
- pname == GL_TEXTURE_CROP_RECT_OES) {
- params[1] = ip[1];
- params[2] = ip[2];
- params[3] = ip[3];
- }
- }
- }
-}
+/*
+ * 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.
+ */
+
+/**
+ * \file texparam.c
+ *
+ * glTexParameter-related functions
+ */
+
+
+#include "main/glheader.h"
+#include "main/colormac.h"
+#include "main/context.h"
+#include "main/enums.h"
+#include "main/formats.h"
+#include "main/macros.h"
+#include "main/mfeatures.h"
+#include "main/mtypes.h"
+#include "main/state.h"
+#include "main/texcompress.h"
+#include "main/texparam.h"
+#include "main/teximage.h"
+#include "main/texstate.h"
+#include "main/texfetch.h"
+#include "program/prog_instruction.h"
+
+
+/**
+ * Check if a coordinate wrap mode is supported for the texture target.
+ * \return GL_TRUE if legal, GL_FALSE otherwise
+ */
+static GLboolean
+validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
+{
+ const struct gl_extensions * const e = & ctx->Extensions;
+
+ if (wrap == GL_CLAMP || wrap == GL_CLAMP_TO_EDGE ||
+ (wrap == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp)) {
+ /* any texture target */
+ return GL_TRUE;
+ }
+ else if (target != GL_TEXTURE_RECTANGLE_NV &&
+ (wrap == GL_REPEAT ||
+ (wrap == GL_MIRRORED_REPEAT &&
+ e->ARB_texture_mirrored_repeat) ||
+ (wrap == GL_MIRROR_CLAMP_EXT &&
+ (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
+ (wrap == GL_MIRROR_CLAMP_TO_EDGE_EXT &&
+ (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
+ (wrap == GL_MIRROR_CLAMP_TO_BORDER_EXT &&
+ (e->EXT_texture_mirror_clamp)))) {
+ /* non-rectangle texture */
+ return GL_TRUE;
+ }
+
+ _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
+ return GL_FALSE;
+}
+
+
+/**
+ * Get current texture object for given target.
+ * Return NULL if any error (and record the error).
+ * Note that this is different from _mesa_select_tex_object() in that proxy
+ * targets are not accepted.
+ * Only the glGetTexLevelParameter() functions accept proxy targets.
+ */
+static struct gl_texture_object *
+get_texobj(struct gl_context *ctx, GLenum target, GLboolean get)
+{
+ struct gl_texture_unit *texUnit;
+
+ if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "gl%sTexParameter(current unit)", get ? "Get" : "");
+ return NULL;
+ }
+
+ texUnit = _mesa_get_current_tex_unit(ctx);
+
+ switch (target) {
+ case GL_TEXTURE_1D:
+ return texUnit->CurrentTex[TEXTURE_1D_INDEX];
+ case GL_TEXTURE_2D:
+ return texUnit->CurrentTex[TEXTURE_2D_INDEX];
+ case GL_TEXTURE_3D:
+ return texUnit->CurrentTex[TEXTURE_3D_INDEX];
+ case GL_TEXTURE_CUBE_MAP:
+ if (ctx->Extensions.ARB_texture_cube_map) {
+ return texUnit->CurrentTex[TEXTURE_CUBE_INDEX];
+ }
+ break;
+ case GL_TEXTURE_RECTANGLE_NV:
+ if (ctx->Extensions.NV_texture_rectangle) {
+ return texUnit->CurrentTex[TEXTURE_RECT_INDEX];
+ }
+ break;
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ if (ctx->Extensions.MESA_texture_array ||
+ ctx->Extensions.EXT_texture_array) {
+ return texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX];
+ }
+ break;
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ if (ctx->Extensions.MESA_texture_array ||
+ ctx->Extensions.EXT_texture_array) {
+ return texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX];
+ }
+ break;
+ default:
+ ;
+ }
+
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "gl%sTexParameter(target)", get ? "Get" : "");
+ return NULL;
+}
+
+
+/**
+ * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
+ * \return -1 if error.
+ */
+static GLint
+comp_to_swizzle(GLenum comp)
+{
+ switch (comp) {
+ case GL_RED:
+ return SWIZZLE_X;
+ case GL_GREEN:
+ return SWIZZLE_Y;
+ case GL_BLUE:
+ return SWIZZLE_Z;
+ case GL_ALPHA:
+ return SWIZZLE_W;
+ case GL_ZERO:
+ return SWIZZLE_ZERO;
+ case GL_ONE:
+ return SWIZZLE_ONE;
+ default:
+ return -1;
+ }
+}
+
+
+static void
+set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
+{
+ ASSERT(comp < 4);
+ ASSERT(swz <= SWIZZLE_NIL);
+ {
+ GLuint mask = 0x7 << (3 * comp);
+ GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
+ *swizzle = s;
+ }
+}
+
+
+/**
+ * This is called just prior to changing any texture object state which
+ * will not effect texture completeness.
+ */
+static INLINE void
+flush(struct gl_context *ctx)
+{
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+}
+
+
+/**
+ * This is called just prior to changing any texture object state which
+ * can effect texture completeness (texture base level, max level,
+ * minification filter).
+ * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
+ * state flag and then mark the texture object as 'incomplete' so that any
+ * per-texture derived state gets recomputed.
+ */
+static INLINE void
+incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
+{
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ texObj->_Complete = GL_FALSE;
+}
+
+
+/**
+ * Set an integer-valued texture parameter
+ * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
+ */
+static GLboolean
+set_tex_parameteri(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ GLenum pname, const GLint *params)
+{
+ switch (pname) {
+ case GL_TEXTURE_MIN_FILTER:
+ if (texObj->Sampler.MinFilter == params[0])
+ return GL_FALSE;
+ switch (params[0]) {
+ case GL_NEAREST:
+ case GL_LINEAR:
+ incomplete(ctx, texObj);
+ texObj->Sampler.MinFilter = params[0];
+ return GL_TRUE;
+ case GL_NEAREST_MIPMAP_NEAREST:
+ case GL_LINEAR_MIPMAP_NEAREST:
+ case GL_NEAREST_MIPMAP_LINEAR:
+ case GL_LINEAR_MIPMAP_LINEAR:
+ if (texObj->Target != GL_TEXTURE_RECTANGLE_NV) {
+ incomplete(ctx, texObj);
+ texObj->Sampler.MinFilter = params[0];
+ return GL_TRUE;
+ }
+ /* fall-through */
+ default:
+ goto invalid_param;
+ }
+ return GL_FALSE;
+
+ case GL_TEXTURE_MAG_FILTER:
+ if (texObj->Sampler.MagFilter == params[0])
+ return GL_FALSE;
+ switch (params[0]) {
+ case GL_NEAREST:
+ case GL_LINEAR:
+ flush(ctx); /* does not effect completeness */
+ texObj->Sampler.MagFilter = params[0];
+ return GL_TRUE;
+ default:
+ goto invalid_param;
+ }
+ return GL_FALSE;
+
+ case GL_TEXTURE_WRAP_S:
+ if (texObj->Sampler.WrapS == params[0])
+ return GL_FALSE;
+ if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
+ flush(ctx);
+ texObj->Sampler.WrapS = params[0];
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+
+ case GL_TEXTURE_WRAP_T:
+ if (texObj->Sampler.WrapT == params[0])
+ return GL_FALSE;
+ if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
+ flush(ctx);
+ texObj->Sampler.WrapT = params[0];
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+
+ case GL_TEXTURE_WRAP_R:
+ if (texObj->Sampler.WrapR == params[0])
+ return GL_FALSE;
+ if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
+ flush(ctx);
+ texObj->Sampler.WrapR = params[0];
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+
+ case GL_TEXTURE_BASE_LEVEL:
+ if (texObj->BaseLevel == params[0])
+ return GL_FALSE;
+ if (params[0] < 0 ||
+ (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTexParameter(param=%d)", params[0]);
+ return GL_FALSE;
+ }
+ incomplete(ctx, texObj);
+ texObj->BaseLevel = params[0];
+ return GL_TRUE;
+
+ case GL_TEXTURE_MAX_LEVEL:
+ if (texObj->MaxLevel == params[0])
+ return GL_FALSE;
+ if (params[0] < 0 || texObj->Target == GL_TEXTURE_RECTANGLE_ARB) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glTexParameter(param=%d)", params[0]);
+ return GL_FALSE;
+ }
+ incomplete(ctx, texObj);
+ texObj->MaxLevel = params[0];
+ return GL_TRUE;
+
+ case GL_GENERATE_MIPMAP_SGIS:
+ if (texObj->GenerateMipmap != params[0]) {
+ /* no flush() */
+ texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+
+ case GL_TEXTURE_COMPARE_MODE_ARB:
+ if (ctx->Extensions.ARB_shadow) {
+ if (texObj->Sampler.CompareMode == params[0])
+ return GL_FALSE;
+ if (params[0] == GL_NONE ||
+ params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
+ flush(ctx);
+ texObj->Sampler.CompareMode = params[0];
+ return GL_TRUE;
+ }
+ goto invalid_param;
+ }
+ goto invalid_pname;
+
+ case GL_TEXTURE_COMPARE_FUNC_ARB:
+ if (ctx->Extensions.ARB_shadow) {
+ if (texObj->Sampler.CompareFunc == params[0])
+ return GL_FALSE;
+ switch (params[0]) {
+ case GL_LEQUAL:
+ case GL_GEQUAL:
+ flush(ctx);
+ texObj->Sampler.CompareFunc = params[0];
+ return GL_TRUE;
+ case GL_EQUAL:
+ case GL_NOTEQUAL:
+ case GL_LESS:
+ case GL_GREATER:
+ case GL_ALWAYS:
+ case GL_NEVER:
+ if (ctx->Extensions.EXT_shadow_funcs) {
+ flush(ctx);
+ texObj->Sampler.CompareFunc = params[0];
+ return GL_TRUE;
+ }
+ /* fall-through */
+ default:
+ goto invalid_param;
+ }
+ }
+ goto invalid_pname;
+
+ case GL_DEPTH_TEXTURE_MODE_ARB:
+ if (ctx->Extensions.ARB_depth_texture) {
+ if (texObj->Sampler.DepthMode == params[0])
+ return GL_FALSE;
+ if (params[0] == GL_LUMINANCE ||
+ params[0] == GL_INTENSITY ||
+ params[0] == GL_ALPHA ||
+ (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
+ flush(ctx);
+ texObj->Sampler.DepthMode = params[0];
+ return GL_TRUE;
+ }
+ goto invalid_param;
+ }
+ goto invalid_pname;
+
+#if FEATURE_OES_draw_texture
+ case GL_TEXTURE_CROP_RECT_OES:
+ texObj->CropRect[0] = params[0];
+ texObj->CropRect[1] = params[1];
+ texObj->CropRect[2] = params[2];
+ texObj->CropRect[3] = params[3];
+ return GL_TRUE;
+#endif
+
+ case GL_TEXTURE_SWIZZLE_R_EXT:
+ case GL_TEXTURE_SWIZZLE_G_EXT:
+ case GL_TEXTURE_SWIZZLE_B_EXT:
+ case GL_TEXTURE_SWIZZLE_A_EXT:
+ if (ctx->Extensions.EXT_texture_swizzle) {
+ const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
+ const GLint swz = comp_to_swizzle(params[0]);
+ if (swz < 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glTexParameter(swizzle 0x%x)", params[0]);
+ return GL_FALSE;
+ }
+ ASSERT(comp < 4);
+ if (swz >= 0) {
+ flush(ctx);
+ texObj->Swizzle[comp] = params[0];
+ set_swizzle_component(&texObj->_Swizzle, comp, swz);
+ return GL_TRUE;
+ }
+ }
+ goto invalid_pname;
+
+ case GL_TEXTURE_SWIZZLE_RGBA_EXT:
+ if (ctx->Extensions.EXT_texture_swizzle) {
+ GLuint comp;
+ flush(ctx);
+ for (comp = 0; comp < 4; comp++) {
+ const GLint swz = comp_to_swizzle(params[comp]);
+ if (swz >= 0) {
+ texObj->Swizzle[comp] = params[comp];
+ set_swizzle_component(&texObj->_Swizzle, comp, swz);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glTexParameter(swizzle 0x%x)", params[comp]);
+ return GL_FALSE;
+ }
+ }
+ return GL_TRUE;
+ }
+ goto invalid_pname;
+
+ case GL_TEXTURE_SRGB_DECODE_EXT:
+ if (ctx->Extensions.EXT_texture_sRGB_decode) {
+ GLenum decode = params[0];
+ if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
+ if (texObj->Sampler.sRGBDecode != decode) {
+ flush(ctx);
+ texObj->Sampler.sRGBDecode = decode;
+ _mesa_update_fetch_functions(texObj);
+ }
+ return GL_TRUE;
+ }
+ }
+ goto invalid_pname;
+
+ default:
+ goto invalid_pname;
+ }
+
+invalid_pname:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
+ _mesa_lookup_enum_by_nr(pname));
+ return GL_FALSE;
+
+invalid_param:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param=%s)",
+ _mesa_lookup_enum_by_nr(params[0]));
+ return GL_FALSE;
+}
+
+
+/**
+ * Set a float-valued texture parameter
+ * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
+ */
+static GLboolean
+set_tex_parameterf(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ GLenum pname, const GLfloat *params)
+{
+ switch (pname) {
+ case GL_TEXTURE_MIN_LOD:
+ if (texObj->Sampler.MinLod == params[0])
+ return GL_FALSE;
+ flush(ctx);
+ texObj->Sampler.MinLod = params[0];
+ return GL_TRUE;
+
+ case GL_TEXTURE_MAX_LOD:
+ if (texObj->Sampler.MaxLod == params[0])
+ return GL_FALSE;
+ flush(ctx);
+ texObj->Sampler.MaxLod = params[0];
+ return GL_TRUE;
+
+ case GL_TEXTURE_PRIORITY:
+ flush(ctx);
+ texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
+ return GL_TRUE;
+
+ case GL_TEXTURE_MAX_ANISOTROPY_EXT:
+ if (ctx->Extensions.EXT_texture_filter_anisotropic) {
+ if (texObj->Sampler.MaxAnisotropy == params[0])
+ return GL_FALSE;
+ if (params[0] < 1.0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
+ return GL_FALSE;
+ }
+ flush(ctx);
+ /* clamp to max, that's what NVIDIA does */
+ texObj->Sampler.MaxAnisotropy = MIN2(params[0],
+ ctx->Const.MaxTextureMaxAnisotropy);
+ return GL_TRUE;
+ }
+ else {
+ static GLuint count = 0;
+ if (count++ < 10)
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
+ }
+ return GL_FALSE;
+
+ case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
+ if (ctx->Extensions.ARB_shadow_ambient) {
+ if (texObj->Sampler.CompareFailValue != params[0]) {
+ flush(ctx);
+ texObj->Sampler.CompareFailValue = CLAMP(params[0], 0.0F, 1.0F);
+ return GL_TRUE;
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
+ }
+ return GL_FALSE;
+
+ case GL_TEXTURE_LOD_BIAS:
+ /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
+ if (ctx->Extensions.EXT_texture_lod_bias) {
+ if (texObj->Sampler.LodBias != params[0]) {
+ flush(ctx);
+ texObj->Sampler.LodBias = params[0];
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+ }
+ break;
+
+ case GL_TEXTURE_BORDER_COLOR:
+ flush(ctx);
+ /* ARB_texture_float disables clamping */
+ if (ctx->Extensions.ARB_texture_float) {
+ texObj->Sampler.BorderColor.f[RCOMP] = params[0];
+ texObj->Sampler.BorderColor.f[GCOMP] = params[1];
+ texObj->Sampler.BorderColor.f[BCOMP] = params[2];
+ texObj->Sampler.BorderColor.f[ACOMP] = params[3];
+ } else {
+ texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
+ texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
+ texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
+ texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
+ }
+ return GL_TRUE;
+
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
+ }
+ return GL_FALSE;
+}
+
+
+void GLAPIENTRY
+_mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
+{
+ GLboolean need_update;
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ texObj = get_texobj(ctx, target, GL_FALSE);
+ if (!texObj)
+ return;
+
+ switch (pname) {
+ case GL_TEXTURE_MIN_FILTER:
+ case GL_TEXTURE_MAG_FILTER:
+ case GL_TEXTURE_WRAP_S:
+ case GL_TEXTURE_WRAP_T:
+ case GL_TEXTURE_WRAP_R:
+ case GL_TEXTURE_BASE_LEVEL:
+ case GL_TEXTURE_MAX_LEVEL:
+ case GL_GENERATE_MIPMAP_SGIS:
+ case GL_TEXTURE_COMPARE_MODE_ARB:
+ case GL_TEXTURE_COMPARE_FUNC_ARB:
+ case GL_DEPTH_TEXTURE_MODE_ARB:
+ case GL_TEXTURE_SRGB_DECODE_EXT:
+ {
+ /* convert float param to int */
+ GLint p[4];
+ p[0] = (GLint) param;
+ p[1] = p[2] = p[3] = 0;
+ need_update = set_tex_parameteri(ctx, texObj, pname, p);
+ }
+ break;
+ default:
+ {
+ /* this will generate an error if pname is illegal */
+ GLfloat p[4];
+ p[0] = param;
+ p[1] = p[2] = p[3] = 0.0F;
+ need_update = set_tex_parameterf(ctx, texObj, pname, p);
+ }
+ }
+
+ if (ctx->Driver.TexParameter && need_update) {
+ ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
+{
+ GLboolean need_update;
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ texObj = get_texobj(ctx, target, GL_FALSE);
+ if (!texObj)
+ return;
+
+ switch (pname) {
+ case GL_TEXTURE_MIN_FILTER:
+ case GL_TEXTURE_MAG_FILTER:
+ case GL_TEXTURE_WRAP_S:
+ case GL_TEXTURE_WRAP_T:
+ case GL_TEXTURE_WRAP_R:
+ case GL_TEXTURE_BASE_LEVEL:
+ case GL_TEXTURE_MAX_LEVEL:
+ case GL_GENERATE_MIPMAP_SGIS:
+ case GL_TEXTURE_COMPARE_MODE_ARB:
+ case GL_TEXTURE_COMPARE_FUNC_ARB:
+ case GL_DEPTH_TEXTURE_MODE_ARB:
+ case GL_TEXTURE_SRGB_DECODE_EXT:
+ {
+ /* convert float param to int */
+ GLint p[4];
+ p[0] = (GLint) params[0];
+ p[1] = p[2] = p[3] = 0;
+ need_update = set_tex_parameteri(ctx, texObj, pname, p);
+ }
+ break;
+
+#if FEATURE_OES_draw_texture
+ case GL_TEXTURE_CROP_RECT_OES:
+ {
+ /* convert float params to int */
+ GLint iparams[4];
+ iparams[0] = (GLint) params[0];
+ iparams[1] = (GLint) params[1];
+ iparams[2] = (GLint) params[2];
+ iparams[3] = (GLint) params[3];
+ need_update = set_tex_parameteri(ctx, texObj, pname, iparams);
+ }
+ break;
+#endif
+
+ default:
+ /* this will generate an error if pname is illegal */
+ need_update = set_tex_parameterf(ctx, texObj, pname, params);
+ }
+
+ if (ctx->Driver.TexParameter && need_update) {
+ ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
+{
+ GLboolean need_update;
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ texObj = get_texobj(ctx, target, GL_FALSE);
+ if (!texObj)
+ return;
+
+ switch (pname) {
+ case GL_TEXTURE_MIN_LOD:
+ case GL_TEXTURE_MAX_LOD:
+ case GL_TEXTURE_PRIORITY:
+ case GL_TEXTURE_MAX_ANISOTROPY_EXT:
+ case GL_TEXTURE_LOD_BIAS:
+ case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
+ {
+ GLfloat fparam[4];
+ fparam[0] = (GLfloat) param;
+ fparam[1] = fparam[2] = fparam[3] = 0.0F;
+ /* convert int param to float */
+ need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
+ }
+ break;
+ default:
+ /* this will generate an error if pname is illegal */
+ {
+ GLint iparam[4];
+ iparam[0] = param;
+ iparam[1] = iparam[2] = iparam[3] = 0;
+ need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
+ }
+ }
+
+ if (ctx->Driver.TexParameter && need_update) {
+ GLfloat fparam = (GLfloat) param;
+ ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
+{
+ GLboolean need_update;
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ texObj = get_texobj(ctx, target, GL_FALSE);
+ if (!texObj)
+ return;
+
+ switch (pname) {
+ case GL_TEXTURE_BORDER_COLOR:
+ {
+ /* convert int params to float */
+ GLfloat fparams[4];
+ fparams[0] = INT_TO_FLOAT(params[0]);
+ fparams[1] = INT_TO_FLOAT(params[1]);
+ fparams[2] = INT_TO_FLOAT(params[2]);
+ fparams[3] = INT_TO_FLOAT(params[3]);
+ need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
+ }
+ break;
+ case GL_TEXTURE_MIN_LOD:
+ case GL_TEXTURE_MAX_LOD:
+ case GL_TEXTURE_PRIORITY:
+ case GL_TEXTURE_MAX_ANISOTROPY_EXT:
+ case GL_TEXTURE_LOD_BIAS:
+ case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
+ {
+ /* convert int param to float */
+ GLfloat fparams[4];
+ fparams[0] = (GLfloat) params[0];
+ fparams[1] = fparams[2] = fparams[3] = 0.0F;
+ need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
+ }
+ break;
+ default:
+ /* this will generate an error if pname is illegal */
+ need_update = set_tex_parameteri(ctx, texObj, pname, params);
+ }
+
+ if (ctx->Driver.TexParameter && need_update) {
+ GLfloat fparams[4];
+ fparams[0] = INT_TO_FLOAT(params[0]);
+ if (pname == GL_TEXTURE_BORDER_COLOR ||
+ pname == GL_TEXTURE_CROP_RECT_OES) {
+ fparams[1] = INT_TO_FLOAT(params[1]);
+ fparams[2] = INT_TO_FLOAT(params[2]);
+ fparams[3] = INT_TO_FLOAT(params[3]);
+ }
+ ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
+ }
+}
+
+
+/**
+ * Set tex parameter to integer value(s). Primarily intended to set
+ * integer-valued texture border color (for integer-valued textures).
+ * New in GL 3.0.
+ */
+void GLAPIENTRY
+_mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
+{
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ texObj = get_texobj(ctx, target, GL_FALSE);
+ if (!texObj)
+ return;
+
+ switch (pname) {
+ case GL_TEXTURE_BORDER_COLOR:
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ /* set the integer-valued border color */
+ COPY_4V(texObj->Sampler.BorderColor.i, params);
+ break;
+ default:
+ _mesa_TexParameteriv(target, pname, params);
+ break;
+ }
+ /* XXX no driver hook for TexParameterIiv() yet */
+}
+
+
+/**
+ * Set tex parameter to unsigned integer value(s). Primarily intended to set
+ * uint-valued texture border color (for integer-valued textures).
+ * New in GL 3.0
+ */
+void GLAPIENTRY
+_mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
+{
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ texObj = get_texobj(ctx, target, GL_FALSE);
+ if (!texObj)
+ return;
+
+ switch (pname) {
+ case GL_TEXTURE_BORDER_COLOR:
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ /* set the unsigned integer-valued border color */
+ COPY_4V(texObj->Sampler.BorderColor.ui, params);
+ break;
+ default:
+ _mesa_TexParameteriv(target, pname, (const GLint *) params);
+ break;
+ }
+ /* XXX no driver hook for TexParameterIuiv() yet */
+}
+
+
+
+
+void GLAPIENTRY
+_mesa_GetTexLevelParameterfv( GLenum target, GLint level,
+ GLenum pname, GLfloat *params )
+{
+ GLint iparam;
+ _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
+ *params = (GLfloat) iparam;
+}
+
+
+void GLAPIENTRY
+_mesa_GetTexLevelParameteriv( GLenum target, GLint level,
+ GLenum pname, GLint *params )
+{
+ const struct gl_texture_unit *texUnit;
+ struct gl_texture_object *texObj;
+ const struct gl_texture_image *img = NULL;
+ GLint maxLevels;
+ gl_format texFormat;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetTexLevelParameteriv(current unit)");
+ return;
+ }
+
+ texUnit = _mesa_get_current_tex_unit(ctx);
+
+ /* this will catch bad target values */
+ maxLevels = _mesa_max_texture_levels(ctx, target);
+ if (maxLevels == 0) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetTexLevelParameter[if]v(target=0x%x)", target);
+ return;
+ }
+
+ if (level < 0 || level >= maxLevels) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
+ return;
+ }
+
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+
+ img = _mesa_select_tex_image(ctx, texObj, target, level);
+ if (!img || !img->TexFormat) {
+ /* undefined texture image */
+ if (pname == GL_TEXTURE_COMPONENTS)
+ *params = 1;
+ else
+ *params = 0;
+ return;
+ }
+
+ texFormat = img->TexFormat;
+
+ switch (pname) {
+ case GL_TEXTURE_WIDTH:
+ *params = img->Width;
+ break;
+ case GL_TEXTURE_HEIGHT:
+ *params = img->Height;
+ break;
+ case GL_TEXTURE_DEPTH:
+ *params = img->Depth;
+ break;
+ case GL_TEXTURE_INTERNAL_FORMAT:
+ if (_mesa_is_format_compressed(texFormat)) {
+ /* need to return the actual compressed format */
+ *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
+ }
+ else {
+ /* return the user's requested internal format */
+ *params = img->InternalFormat;
+ }
+ break;
+ case GL_TEXTURE_BORDER:
+ *params = img->Border;
+ break;
+ case GL_TEXTURE_RED_SIZE:
+ if (img->_BaseFormat == GL_RED) {
+ *params = _mesa_get_format_bits(texFormat, pname);
+ break;
+ }
+ /* FALLTHROUGH */
+ case GL_TEXTURE_GREEN_SIZE:
+ if (img->_BaseFormat == GL_RG) {
+ *params = _mesa_get_format_bits(texFormat, pname);
+ break;
+ }
+ /* FALLTHROUGH */
+ case GL_TEXTURE_BLUE_SIZE:
+ if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
+ *params = _mesa_get_format_bits(texFormat, pname);
+ else
+ *params = 0;
+ break;
+ case GL_TEXTURE_ALPHA_SIZE:
+ if (img->_BaseFormat == GL_ALPHA ||
+ img->_BaseFormat == GL_LUMINANCE_ALPHA ||
+ img->_BaseFormat == GL_RGBA)
+ *params = _mesa_get_format_bits(texFormat, pname);
+ else
+ *params = 0;
+ break;
+ case GL_TEXTURE_INTENSITY_SIZE:
+ if (img->_BaseFormat != GL_INTENSITY)
+ *params = 0;
+ else {
+ *params = _mesa_get_format_bits(texFormat, pname);
+ if (*params == 0) {
+ /* intensity probably stored as rgb texture */
+ *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
+ _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
+ }
+ }
+ break;
+ case GL_TEXTURE_LUMINANCE_SIZE:
+ if (img->_BaseFormat != GL_LUMINANCE &&
+ img->_BaseFormat != GL_LUMINANCE_ALPHA)
+ *params = 0;
+ else {
+ *params = _mesa_get_format_bits(texFormat, pname);
+ if (*params == 0) {
+ /* luminance probably stored as rgb texture */
+ *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
+ _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
+ }
+ }
+ break;
+ case GL_TEXTURE_INDEX_SIZE_EXT:
+ if (img->_BaseFormat == GL_COLOR_INDEX)
+ *params = _mesa_get_format_bits(texFormat, pname);
+ else
+ *params = 0;
+ break;
+ case GL_TEXTURE_DEPTH_SIZE_ARB:
+ if (ctx->Extensions.ARB_depth_texture)
+ *params = _mesa_get_format_bits(texFormat, pname);
+ else
+ goto invalid_pname;
+ break;
+ case GL_TEXTURE_STENCIL_SIZE_EXT:
+ if (ctx->Extensions.EXT_packed_depth_stencil ||
+ ctx->Extensions.ARB_framebuffer_object) {
+ *params = _mesa_get_format_bits(texFormat, pname);
+ }
+ else {
+ goto invalid_pname;
+ }
+ break;
+ case GL_TEXTURE_SHARED_SIZE:
+ if (ctx->VersionMajor >= 3 ||
+ ctx->Extensions.EXT_texture_shared_exponent) {
+ *params = texFormat == MESA_FORMAT_RGB9_E5_FLOAT ? 5 : 0;
+ }
+ else {
+ goto invalid_pname;
+ }
+ break;
+
+ /* GL_ARB_texture_compression */
+ case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
+ if (_mesa_is_format_compressed(texFormat) &&
+ !_mesa_is_proxy_texture(target)) {
+ *params = _mesa_format_image_size(texFormat, img->Width,
+ img->Height, img->Depth);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetTexLevelParameter[if]v(pname)");
+ }
+ break;
+ case GL_TEXTURE_COMPRESSED:
+ *params = (GLint) _mesa_is_format_compressed(texFormat);
+ break;
+
+ /* GL_ARB_texture_float */
+ case GL_TEXTURE_RED_TYPE_ARB:
+ if (ctx->Extensions.ARB_texture_float) {
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
+ }
+ else {
+ goto invalid_pname;
+ }
+ break;
+ case GL_TEXTURE_GREEN_TYPE_ARB:
+ if (ctx->Extensions.ARB_texture_float) {
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
+ }
+ else {
+ goto invalid_pname;
+ }
+ break;
+ case GL_TEXTURE_BLUE_TYPE_ARB:
+ if (ctx->Extensions.ARB_texture_float) {
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_BLUE_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
+ }
+ else {
+ goto invalid_pname;
+ }
+ break;
+ case GL_TEXTURE_ALPHA_TYPE_ARB:
+ if (ctx->Extensions.ARB_texture_float) {
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_ALPHA_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
+ }
+ else {
+ goto invalid_pname;
+ }
+ break;
+ case GL_TEXTURE_LUMINANCE_TYPE_ARB:
+ if (ctx->Extensions.ARB_texture_float) {
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_LUMINANCE_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
+ }
+ else {
+ goto invalid_pname;
+ }
+ break;
+ case GL_TEXTURE_INTENSITY_TYPE_ARB:
+ if (ctx->Extensions.ARB_texture_float) {
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_INTENSITY_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
+ }
+ else {
+ goto invalid_pname;
+ }
+ break;
+ case GL_TEXTURE_DEPTH_TYPE_ARB:
+ if (ctx->Extensions.ARB_texture_float) {
+ *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_DEPTH_SIZE) ?
+ _mesa_get_format_datatype(texFormat) : GL_NONE;
+ }
+ else {
+ goto invalid_pname;
+ }
+ break;
+
+ default:
+ goto invalid_pname;
+ }
+
+ /* no error if we get here */
+ return;
+
+invalid_pname:
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetTexLevelParameter[if]v(pname=%s)",
+ _mesa_lookup_enum_by_nr(pname));
+}
+
+
+
+void GLAPIENTRY
+_mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
+{
+ struct gl_texture_object *obj;
+ GLboolean error = GL_FALSE;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ obj = get_texobj(ctx, target, GL_TRUE);
+ if (!obj)
+ return;
+
+ _mesa_lock_texture(ctx, obj);
+ switch (pname) {
+ case GL_TEXTURE_MAG_FILTER:
+ *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
+ break;
+ case GL_TEXTURE_MIN_FILTER:
+ *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
+ break;
+ case GL_TEXTURE_WRAP_S:
+ *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
+ break;
+ case GL_TEXTURE_WRAP_T:
+ *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
+ break;
+ case GL_TEXTURE_WRAP_R:
+ *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
+ break;
+ case GL_TEXTURE_BORDER_COLOR:
+ if(ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
+ _mesa_update_state_locked(ctx);
+ if(ctx->Color._ClampFragmentColor)
+ {
+ params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
+ params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
+ params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
+ params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
+ }
+ else
+ {
+ params[0] = obj->Sampler.BorderColor.f[0];
+ params[1] = obj->Sampler.BorderColor.f[1];
+ params[2] = obj->Sampler.BorderColor.f[2];
+ params[3] = obj->Sampler.BorderColor.f[3];
+ }
+ break;
+ case GL_TEXTURE_RESIDENT:
+ {
+ GLboolean resident;
+ if (ctx->Driver.IsTextureResident)
+ resident = ctx->Driver.IsTextureResident(ctx, obj);
+ else
+ resident = GL_TRUE;
+ *params = ENUM_TO_FLOAT(resident);
+ }
+ break;
+ case GL_TEXTURE_PRIORITY:
+ *params = obj->Priority;
+ break;
+ case GL_TEXTURE_MIN_LOD:
+ *params = obj->Sampler.MinLod;
+ break;
+ case GL_TEXTURE_MAX_LOD:
+ *params = obj->Sampler.MaxLod;
+ break;
+ case GL_TEXTURE_BASE_LEVEL:
+ *params = (GLfloat) obj->BaseLevel;
+ break;
+ case GL_TEXTURE_MAX_LEVEL:
+ *params = (GLfloat) obj->MaxLevel;
+ break;
+ case GL_TEXTURE_MAX_ANISOTROPY_EXT:
+ if (ctx->Extensions.EXT_texture_filter_anisotropic) {
+ *params = obj->Sampler.MaxAnisotropy;
+ }
+ else
+ error = GL_TRUE;
+ break;
+ case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
+ if (ctx->Extensions.ARB_shadow_ambient) {
+ *params = obj->Sampler.CompareFailValue;
+ }
+ else
+ error = GL_TRUE;
+ break;
+ case GL_GENERATE_MIPMAP_SGIS:
+ *params = (GLfloat) obj->GenerateMipmap;
+ break;
+ case GL_TEXTURE_COMPARE_MODE_ARB:
+ if (ctx->Extensions.ARB_shadow) {
+ *params = (GLfloat) obj->Sampler.CompareMode;
+ }
+ else
+ error = GL_TRUE;
+ break;
+ case GL_TEXTURE_COMPARE_FUNC_ARB:
+ if (ctx->Extensions.ARB_shadow) {
+ *params = (GLfloat) obj->Sampler.CompareFunc;
+ }
+ else
+ error = GL_TRUE;
+ break;
+ case GL_DEPTH_TEXTURE_MODE_ARB:
+ if (ctx->Extensions.ARB_depth_texture) {
+ *params = (GLfloat) obj->Sampler.DepthMode;
+ }
+ else
+ error = GL_TRUE;
+ break;
+ case GL_TEXTURE_LOD_BIAS:
+ if (ctx->Extensions.EXT_texture_lod_bias) {
+ *params = obj->Sampler.LodBias;
+ }
+ else
+ error = GL_TRUE;
+ break;
+#if FEATURE_OES_draw_texture
+ case GL_TEXTURE_CROP_RECT_OES:
+ params[0] = obj->CropRect[0];
+ params[1] = obj->CropRect[1];
+ params[2] = obj->CropRect[2];
+ params[3] = obj->CropRect[3];
+ break;
+#endif
+
+ case GL_TEXTURE_SWIZZLE_R_EXT:
+ case GL_TEXTURE_SWIZZLE_G_EXT:
+ case GL_TEXTURE_SWIZZLE_B_EXT:
+ case GL_TEXTURE_SWIZZLE_A_EXT:
+ if (ctx->Extensions.EXT_texture_swizzle) {
+ GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
+ *params = (GLfloat) obj->Swizzle[comp];
+ }
+ else {
+ error = GL_TRUE;
+ }
+ break;
+
+ case GL_TEXTURE_SWIZZLE_RGBA_EXT:
+ if (ctx->Extensions.EXT_texture_swizzle) {
+ GLuint comp;
+ for (comp = 0; comp < 4; comp++) {
+ params[comp] = (GLfloat) obj->Swizzle[comp];
+ }
+ }
+ else {
+ error = GL_TRUE;
+ }
+ break;
+
+ default:
+ error = GL_TRUE;
+ break;
+ }
+
+ if (error)
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)",
+ pname);
+
+ _mesa_unlock_texture(ctx, obj);
+}
+
+
+void GLAPIENTRY
+_mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
+{
+ struct gl_texture_object *obj;
+ GLboolean error = GL_FALSE;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ obj = get_texobj(ctx, target, GL_TRUE);
+ if (!obj)
+ return;
+
+ _mesa_lock_texture(ctx, obj);
+ switch (pname) {
+ case GL_TEXTURE_MAG_FILTER:
+ *params = (GLint) obj->Sampler.MagFilter;
+ break;;
+ case GL_TEXTURE_MIN_FILTER:
+ *params = (GLint) obj->Sampler.MinFilter;
+ break;;
+ case GL_TEXTURE_WRAP_S:
+ *params = (GLint) obj->Sampler.WrapS;
+ break;;
+ case GL_TEXTURE_WRAP_T:
+ *params = (GLint) obj->Sampler.WrapT;
+ break;;
+ case GL_TEXTURE_WRAP_R:
+ *params = (GLint) obj->Sampler.WrapR;
+ break;;
+ case GL_TEXTURE_BORDER_COLOR:
+ {
+ GLfloat b[4];
+ b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
+ b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
+ b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
+ b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
+ params[0] = FLOAT_TO_INT(b[0]);
+ params[1] = FLOAT_TO_INT(b[1]);
+ params[2] = FLOAT_TO_INT(b[2]);
+ params[3] = FLOAT_TO_INT(b[3]);
+ }
+ break;;
+ case GL_TEXTURE_RESIDENT:
+ {
+ GLboolean resident;
+ if (ctx->Driver.IsTextureResident)
+ resident = ctx->Driver.IsTextureResident(ctx, obj);
+ else
+ resident = GL_TRUE;
+ *params = (GLint) resident;
+ }
+ break;;
+ case GL_TEXTURE_PRIORITY:
+ *params = FLOAT_TO_INT(obj->Priority);
+ break;;
+ case GL_TEXTURE_MIN_LOD:
+ *params = (GLint) obj->Sampler.MinLod;
+ break;;
+ case GL_TEXTURE_MAX_LOD:
+ *params = (GLint) obj->Sampler.MaxLod;
+ break;;
+ case GL_TEXTURE_BASE_LEVEL:
+ *params = obj->BaseLevel;
+ break;;
+ case GL_TEXTURE_MAX_LEVEL:
+ *params = obj->MaxLevel;
+ break;;
+ case GL_TEXTURE_MAX_ANISOTROPY_EXT:
+ if (ctx->Extensions.EXT_texture_filter_anisotropic) {
+ *params = (GLint) obj->Sampler.MaxAnisotropy;
+ }
+ else {
+ error = GL_TRUE;
+ }
+ break;
+ case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
+ if (ctx->Extensions.ARB_shadow_ambient) {
+ *params = (GLint) FLOAT_TO_INT(obj->Sampler.CompareFailValue);
+ }
+ else {
+ error = GL_TRUE;
+ }
+ break;
+ case GL_GENERATE_MIPMAP_SGIS:
+ *params = (GLint) obj->GenerateMipmap;
+ break;
+ case GL_TEXTURE_COMPARE_MODE_ARB:
+ if (ctx->Extensions.ARB_shadow) {
+ *params = (GLint) obj->Sampler.CompareMode;
+ }
+ else {
+ error = GL_TRUE;
+ }
+ break;
+ case GL_TEXTURE_COMPARE_FUNC_ARB:
+ if (ctx->Extensions.ARB_shadow) {
+ *params = (GLint) obj->Sampler.CompareFunc;
+ }
+ else {
+ error = GL_TRUE;
+ }
+ break;
+ case GL_DEPTH_TEXTURE_MODE_ARB:
+ if (ctx->Extensions.ARB_depth_texture) {
+ *params = (GLint) obj->Sampler.DepthMode;
+ }
+ else {
+ error = GL_TRUE;
+ }
+ break;
+ case GL_TEXTURE_LOD_BIAS:
+ if (ctx->Extensions.EXT_texture_lod_bias) {
+ *params = (GLint) obj->Sampler.LodBias;
+ }
+ else {
+ error = GL_TRUE;
+ }
+ break;
+#if FEATURE_OES_draw_texture
+ case GL_TEXTURE_CROP_RECT_OES:
+ params[0] = obj->CropRect[0];
+ params[1] = obj->CropRect[1];
+ params[2] = obj->CropRect[2];
+ params[3] = obj->CropRect[3];
+ break;
+#endif
+ case GL_TEXTURE_SWIZZLE_R_EXT:
+ case GL_TEXTURE_SWIZZLE_G_EXT:
+ case GL_TEXTURE_SWIZZLE_B_EXT:
+ case GL_TEXTURE_SWIZZLE_A_EXT:
+ if (ctx->Extensions.EXT_texture_swizzle) {
+ GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
+ *params = obj->Swizzle[comp];
+ }
+ else {
+ error = GL_TRUE;
+ }
+ break;
+
+ case GL_TEXTURE_SWIZZLE_RGBA_EXT:
+ if (ctx->Extensions.EXT_texture_swizzle) {
+ COPY_4V(params, obj->Swizzle);
+ }
+ else {
+ error = GL_TRUE;
+ }
+ break;
+
+ default:
+ ; /* silence warnings */
+ }
+
+ if (error)
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)",
+ pname);
+
+ _mesa_unlock_texture(ctx, obj);
+}
+
+
+/** New in GL 3.0 */
+void GLAPIENTRY
+_mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
+{
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ texObj = get_texobj(ctx, target, GL_TRUE);
+
+ switch (pname) {
+ case GL_TEXTURE_BORDER_COLOR:
+ COPY_4V(params, texObj->Sampler.BorderColor.i);
+ break;
+ default:
+ _mesa_GetTexParameteriv(target, pname, params);
+ }
+}
+
+
+/** New in GL 3.0 */
+void GLAPIENTRY
+_mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
+{
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ texObj = get_texobj(ctx, target, GL_TRUE);
+
+ switch (pname) {
+ case GL_TEXTURE_BORDER_COLOR:
+ COPY_4V(params, texObj->Sampler.BorderColor.i);
+ break;
+ default:
+ {
+ GLint ip[4];
+ _mesa_GetTexParameteriv(target, pname, ip);
+ params[0] = ip[0];
+ if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
+ pname == GL_TEXTURE_CROP_RECT_OES) {
+ params[1] = ip[1];
+ params[2] = ip[2];
+ params[3] = ip[3];
+ }
+ }
+ }
+}
diff --git a/mesalib/src/mesa/main/texrender.c b/mesalib/src/mesa/main/texrender.c
index 2766bd6c5..4bcef9899 100644
--- a/mesalib/src/mesa/main/texrender.c
+++ b/mesalib/src/mesa/main/texrender.c
@@ -530,6 +530,7 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
{
struct texture_renderbuffer *trb
= (struct texture_renderbuffer *) att->Renderbuffer;
+ GLuint unused;
(void) ctx;
ASSERT(trb);
@@ -602,8 +603,10 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
trb->Base._BaseFormat = GL_RGBA;
break;
default:
- trb->Base.DataType = CHAN_TYPE;
- trb->Base._BaseFormat = GL_RGBA;
+ _mesa_format_to_type_and_comps(trb->TexImage->TexFormat,
+ &trb->Base.DataType, &unused);
+ trb->Base._BaseFormat =
+ _mesa_base_fbo_format(ctx, trb->TexImage->InternalFormat);
}
trb->Base.Data = trb->TexImage->Data;
}
diff --git a/mesalib/src/mesa/main/texstore.c b/mesalib/src/mesa/main/texstore.c
index c4fe82a0b..ea116a011 100644
--- a/mesalib/src/mesa/main/texstore.c
+++ b/mesalib/src/mesa/main/texstore.c
@@ -1,4875 +1,4985 @@
-/*
- * 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 "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 &&
- baseInternalFormat == GL_LUMINANCE_ALPHA &&
- srcFormat == GL_LUMINANCE_ALPHA) ||
- (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 &&
- baseInternalFormat == GL_LUMINANCE_ALPHA &&
- srcFormat == GL_LUMINANCE_ALPHA) ||
- (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_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;
- if (dstFormat == MESA_FORMAT_SIGNED_RGBA_16) {
- 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;
- } else {
- for (col = 0; col < srcWidth; col++) {
- GLuint c;
- for (c = 0; c < comps; c++) {
- GLshort p;
- UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 3 + c]);
- dstRowS[col * comps + c] = p;
- }
- }
- dstRow += dstRowStride;
- src += 3 * 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_unorm8(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 a signed normalized 8-bit format.
- */
-static GLboolean
-_mesa_texstore_snorm8(TEXSTORE_PARAMS)
-{
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_SIGNED_A8 ||
- dstFormat == MESA_FORMAT_SIGNED_L8 ||
- dstFormat == MESA_FORMAT_SIGNED_I8 ||
- dstFormat == MESA_FORMAT_SIGNED_R8);
- ASSERT(texelBytes == 1);
-
- if (!ctx->_ImageTransferState &&
- !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,
- ctx->_ImageTransferState);
- const GLfloat *src = tempImage;
- GLint img, row, col;
- if (!tempImage)
- return GL_FALSE;
- for (img = 0; img < srcDepth; img++) {
- GLbyte *dstRow = (GLbyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- for (col = 0; col < srcWidth; col++) {
- dstRow[col] = FLOAT_TO_BYTE_TEX(src[col]);
- }
- dstRow += dstRowStride;
- src += srcWidth;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-/**
- * Store a texture in a signed normalized two-channel 16-bit format.
- */
-static GLboolean
-_mesa_texstore_snorm88(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_AL88 ||
- dstFormat == MESA_FORMAT_SIGNED_RG88_REV);
- ASSERT(texelBytes == 2);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- 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 {
- /* 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++) {
- GLbyte *dstRow = (GLbyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLbyte *dst = dstRow;
- for (col = 0; col < srcWidth; col++) {
- dst[0] = FLOAT_TO_BYTE_TEX(src[0]);
- dst[1] = FLOAT_TO_BYTE_TEX(src[1]);
- src += 2;
- dst += 2;
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-/* Texstore for signed R16, A16, L16, I16. */
-static GLboolean
-_mesa_texstore_snorm16(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_R16 ||
- dstFormat == MESA_FORMAT_SIGNED_A16 ||
- dstFormat == MESA_FORMAT_SIGNED_L16 ||
- dstFormat == MESA_FORMAT_SIGNED_I16);
- ASSERT(texelBytes == 2);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_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++) {
- GLshort *dstUS = (GLshort *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- GLushort r;
-
- UNCLAMPED_FLOAT_TO_SHORT(r, src[0]);
- dstUS[col] = r;
- src += 1;
- }
- dstRow += dstRowStride;
- }
- }
- free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-/**
- * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
- */
-static GLboolean
-_mesa_texstore_snorm1616(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_AL1616 ||
- dstFormat == MESA_FORMAT_SIGNED_GR1616);
- ASSERT(texelBytes == 4);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- srcType == GL_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++) {
- GLshort *dst = (GLshort *) dstRow;
- for (col = 0; col < srcWidth; col++) {
- GLushort l, a;
-
- UNCLAMPED_FLOAT_TO_SHORT(l, src[0]);
- UNCLAMPED_FLOAT_TO_SHORT(a, src[1]);
- dst[0] = l;
- dst[1] = a;
- src += 2;
- dst += 2;
- }
- 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++) {
- GLbyte *dstRow = (GLbyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLbyte *dst = dstRow;
- for (col = 0; col < srcWidth; col++) {
- dst[3] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]);
- dst[2] = FLOAT_TO_BYTE_TEX(srcRow[GCOMP]);
- dst[1] = FLOAT_TO_BYTE_TEX(srcRow[BCOMP]);
- dst[0] = 127;
- srcRow += 3;
- dst += 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 {
- /* 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++) {
- GLbyte *dstRow = (GLbyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLbyte *dst = dstRow;
- if (dstFormat == MESA_FORMAT_SIGNED_RGBA8888) {
- for (col = 0; col < srcWidth; col++) {
- dst[3] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]);
- dst[2] = FLOAT_TO_BYTE_TEX(srcRow[GCOMP]);
- dst[1] = FLOAT_TO_BYTE_TEX(srcRow[BCOMP]);
- dst[0] = FLOAT_TO_BYTE_TEX(srcRow[ACOMP]);
- srcRow += 4;
- dst += 4;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- dst[0] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]);
- dst[1] = FLOAT_TO_BYTE_TEX(srcRow[GCOMP]);
- dst[2] = FLOAT_TO_BYTE_TEX(srcRow[BCOMP]);
- dst[3] = FLOAT_TO_BYTE_TEX(srcRow[ACOMP]);
- srcRow += 4;
- dst += 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 ||
- dstFormat == MESA_FORMAT_R_FLOAT32 ||
- dstFormat == MESA_FORMAT_RG_FLOAT32);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY ||
- baseInternalFormat == GL_RED ||
- baseInternalFormat == GL_RG);
- ASSERT(texelBytes == components * sizeof(GLfloat));
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- baseInternalFormat == baseFormat &&
- 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 ||
- dstFormat == MESA_FORMAT_R_FLOAT16 ||
- dstFormat == MESA_FORMAT_RG_FLOAT16);
- ASSERT(baseInternalFormat == GL_RGBA ||
- baseInternalFormat == GL_RGB ||
- baseInternalFormat == GL_ALPHA ||
- baseInternalFormat == GL_LUMINANCE ||
- baseInternalFormat == GL_LUMINANCE_ALPHA ||
- baseInternalFormat == GL_INTENSITY ||
- baseInternalFormat == GL_RED ||
- baseInternalFormat == GL_RG);
- ASSERT(texelBytes == components * sizeof(GLhalfARB));
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- baseInternalFormat == srcFormat &&
- baseInternalFormat == baseFormat &&
- 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_unorm8(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_unorm8 },
- { MESA_FORMAT_A16, _mesa_texstore_unorm16 },
- { MESA_FORMAT_L8, _mesa_texstore_unorm8 },
- { MESA_FORMAT_L16, _mesa_texstore_unorm16 },
- { MESA_FORMAT_I8, _mesa_texstore_unorm8 },
- { 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_unorm8 },
- { 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_R_FLOAT32, _mesa_texstore_rgba_float32 },
- { MESA_FORMAT_R_FLOAT16, _mesa_texstore_rgba_float16 },
- { MESA_FORMAT_RG_FLOAT32, _mesa_texstore_rgba_float32 },
- { MESA_FORMAT_RG_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_snorm8 },
- { MESA_FORMAT_SIGNED_RG88_REV, _mesa_texstore_snorm88 },
- { 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_R16, _mesa_texstore_snorm16 },
- { MESA_FORMAT_SIGNED_GR1616, _mesa_texstore_snorm1616 },
- { 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 },
-
- /* Re-use the R/RG texstore functions.
- * The code is generic enough to handle LATC too. */
- { MESA_FORMAT_L_LATC1, _mesa_texstore_red_rgtc1 },
- { MESA_FORMAT_SIGNED_L_LATC1, _mesa_texstore_signed_red_rgtc1 },
- { MESA_FORMAT_LA_LATC2, _mesa_texstore_rg_rgtc2 },
- { MESA_FORMAT_SIGNED_LA_LATC2, _mesa_texstore_signed_rg_rgtc2 },
-
- { MESA_FORMAT_SIGNED_A8, _mesa_texstore_snorm8 },
- { MESA_FORMAT_SIGNED_L8, _mesa_texstore_snorm8 },
- { MESA_FORMAT_SIGNED_AL88, _mesa_texstore_snorm88 },
- { MESA_FORMAT_SIGNED_I8, _mesa_texstore_snorm8 },
-
- { MESA_FORMAT_SIGNED_A16, _mesa_texstore_snorm16 },
- { MESA_FORMAT_SIGNED_L16, _mesa_texstore_snorm16 },
- { MESA_FORMAT_SIGNED_AL1616, _mesa_texstore_snorm1616 },
- { MESA_FORMAT_SIGNED_I16, _mesa_texstore_snorm16 },
-};
-
-
-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 "texcompress.h"
+#include "texcompress_fxt1.h"
+#include "texcompress_rgtc.h"
+#include "texcompress_s3tc.h"
+#include "teximage.h"
+#include "texstore.h"
+#include "enums.h"
+#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
+#include "../../gallium/auxiliary/util/u_format_r11g11b10f.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 &&
+ baseInternalFormat == GL_LUMINANCE_ALPHA &&
+ srcFormat == GL_LUMINANCE_ALPHA) ||
+ (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 &&
+ baseInternalFormat == GL_LUMINANCE_ALPHA &&
+ srcFormat == GL_LUMINANCE_ALPHA) ||
+ (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_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;
+ if (dstFormat == MESA_FORMAT_SIGNED_RGBA_16) {
+ 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;
+ } else {
+ for (col = 0; col < srcWidth; col++) {
+ GLuint c;
+ for (c = 0; c < comps; c++) {
+ GLshort p;
+ UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 3 + c]);
+ dstRowS[col * comps + c] = p;
+ }
+ }
+ dstRow += dstRowStride;
+ src += 3 * 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_unorm8(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 a signed normalized 8-bit format.
+ */
+static GLboolean
+_mesa_texstore_snorm8(TEXSTORE_PARAMS)
+{
+ const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_SIGNED_A8 ||
+ dstFormat == MESA_FORMAT_SIGNED_L8 ||
+ dstFormat == MESA_FORMAT_SIGNED_I8 ||
+ dstFormat == MESA_FORMAT_SIGNED_R8);
+ ASSERT(texelBytes == 1);
+
+ if (!ctx->_ImageTransferState &&
+ !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,
+ ctx->_ImageTransferState);
+ const GLfloat *src = tempImage;
+ GLint img, row, col;
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLbyte *dstRow = (GLbyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ for (col = 0; col < srcWidth; col++) {
+ dstRow[col] = FLOAT_TO_BYTE_TEX(src[col]);
+ }
+ dstRow += dstRowStride;
+ src += srcWidth;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+/**
+ * Store a texture in a signed normalized two-channel 16-bit format.
+ */
+static GLboolean
+_mesa_texstore_snorm88(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_AL88 ||
+ dstFormat == MESA_FORMAT_SIGNED_RG88_REV);
+ ASSERT(texelBytes == 2);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ 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 {
+ /* 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++) {
+ GLbyte *dstRow = (GLbyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLbyte *dst = dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ dst[0] = FLOAT_TO_BYTE_TEX(src[0]);
+ dst[1] = FLOAT_TO_BYTE_TEX(src[1]);
+ src += 2;
+ dst += 2;
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+/* Texstore for signed R16, A16, L16, I16. */
+static GLboolean
+_mesa_texstore_snorm16(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_R16 ||
+ dstFormat == MESA_FORMAT_SIGNED_A16 ||
+ dstFormat == MESA_FORMAT_SIGNED_L16 ||
+ dstFormat == MESA_FORMAT_SIGNED_I16);
+ ASSERT(texelBytes == 2);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_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++) {
+ GLshort *dstUS = (GLshort *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ GLushort r;
+
+ UNCLAMPED_FLOAT_TO_SHORT(r, src[0]);
+ dstUS[col] = r;
+ src += 1;
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+/**
+ * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
+ */
+static GLboolean
+_mesa_texstore_snorm1616(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_AL1616 ||
+ dstFormat == MESA_FORMAT_SIGNED_GR1616);
+ ASSERT(texelBytes == 4);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ srcType == GL_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++) {
+ GLshort *dst = (GLshort *) dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ GLushort l, a;
+
+ UNCLAMPED_FLOAT_TO_SHORT(l, src[0]);
+ UNCLAMPED_FLOAT_TO_SHORT(a, src[1]);
+ dst[0] = l;
+ dst[1] = a;
+ src += 2;
+ dst += 2;
+ }
+ 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++) {
+ GLbyte *dstRow = (GLbyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLbyte *dst = dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ dst[3] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]);
+ dst[2] = FLOAT_TO_BYTE_TEX(srcRow[GCOMP]);
+ dst[1] = FLOAT_TO_BYTE_TEX(srcRow[BCOMP]);
+ dst[0] = 127;
+ srcRow += 3;
+ dst += 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 {
+ /* 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++) {
+ GLbyte *dstRow = (GLbyte *) dstAddr
+ + dstImageOffsets[dstZoffset + img] * texelBytes
+ + dstYoffset * dstRowStride
+ + dstXoffset * texelBytes;
+ for (row = 0; row < srcHeight; row++) {
+ GLbyte *dst = dstRow;
+ if (dstFormat == MESA_FORMAT_SIGNED_RGBA8888) {
+ for (col = 0; col < srcWidth; col++) {
+ dst[3] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]);
+ dst[2] = FLOAT_TO_BYTE_TEX(srcRow[GCOMP]);
+ dst[1] = FLOAT_TO_BYTE_TEX(srcRow[BCOMP]);
+ dst[0] = FLOAT_TO_BYTE_TEX(srcRow[ACOMP]);
+ srcRow += 4;
+ dst += 4;
+ }
+ }
+ else {
+ for (col = 0; col < srcWidth; col++) {
+ dst[0] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]);
+ dst[1] = FLOAT_TO_BYTE_TEX(srcRow[GCOMP]);
+ dst[2] = FLOAT_TO_BYTE_TEX(srcRow[BCOMP]);
+ dst[3] = FLOAT_TO_BYTE_TEX(srcRow[ACOMP]);
+ srcRow += 4;
+ dst += 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 ||
+ dstFormat == MESA_FORMAT_R_FLOAT32 ||
+ dstFormat == MESA_FORMAT_RG_FLOAT32);
+ ASSERT(baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_ALPHA ||
+ baseInternalFormat == GL_LUMINANCE ||
+ baseInternalFormat == GL_LUMINANCE_ALPHA ||
+ baseInternalFormat == GL_INTENSITY ||
+ baseInternalFormat == GL_RED ||
+ baseInternalFormat == GL_RG);
+ ASSERT(texelBytes == components * sizeof(GLfloat));
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ baseInternalFormat == baseFormat &&
+ 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 ||
+ dstFormat == MESA_FORMAT_R_FLOAT16 ||
+ dstFormat == MESA_FORMAT_RG_FLOAT16);
+ ASSERT(baseInternalFormat == GL_RGBA ||
+ baseInternalFormat == GL_RGB ||
+ baseInternalFormat == GL_ALPHA ||
+ baseInternalFormat == GL_LUMINANCE ||
+ baseInternalFormat == GL_LUMINANCE_ALPHA ||
+ baseInternalFormat == GL_INTENSITY ||
+ baseInternalFormat == GL_RED ||
+ baseInternalFormat == GL_RG);
+ ASSERT(texelBytes == components * sizeof(GLhalfARB));
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ baseInternalFormat == srcFormat &&
+ baseInternalFormat == baseFormat &&
+ 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_unorm8(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 */
+
+static GLboolean
+_mesa_texstore_rgb9_e5(TEXSTORE_PARAMS)
+{
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_RGB9_E5_FLOAT);
+ ASSERT(baseInternalFormat == GL_RGB);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ srcFormat == GL_RGB &&
+ srcType == GL_UNSIGNED_INT_5_9_9_9_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 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] * 4
+ + dstYoffset * dstRowStride
+ + dstXoffset * 4;
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstUI = (GLuint*)dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = float3_to_rgb9e5(&srcRow[col * 3]);
+ }
+ dstRow += dstRowStride;
+ srcRow += srcWidth * 3;
+ }
+ }
+
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+static GLboolean
+_mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS)
+{
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_R11_G11_B10_FLOAT);
+ ASSERT(baseInternalFormat == GL_RGB);
+
+ if (!ctx->_ImageTransferState &&
+ !srcPacking->SwapBytes &&
+ srcFormat == GL_RGB &&
+ srcType == GL_UNSIGNED_INT_10F_11F_11F_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 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] * 4
+ + dstYoffset * dstRowStride
+ + dstXoffset * 4;
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstUI = (GLuint*)dstRow;
+ for (col = 0; col < srcWidth; col++) {
+ dstUI[col] = float3_to_r11g11b10f(&srcRow[col * 3]);
+ }
+ dstRow += dstRowStride;
+ srcRow += srcWidth * 3;
+ }
+ }
+
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+
+
+/**
+ * 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_unorm8 },
+ { MESA_FORMAT_A16, _mesa_texstore_unorm16 },
+ { MESA_FORMAT_L8, _mesa_texstore_unorm8 },
+ { MESA_FORMAT_L16, _mesa_texstore_unorm16 },
+ { MESA_FORMAT_I8, _mesa_texstore_unorm8 },
+ { 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_unorm8 },
+ { 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_R_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_R_FLOAT16, _mesa_texstore_rgba_float16 },
+ { MESA_FORMAT_RG_FLOAT32, _mesa_texstore_rgba_float32 },
+ { MESA_FORMAT_RG_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_snorm8 },
+ { MESA_FORMAT_SIGNED_RG88_REV, _mesa_texstore_snorm88 },
+ { 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_R16, _mesa_texstore_snorm16 },
+ { MESA_FORMAT_SIGNED_GR1616, _mesa_texstore_snorm1616 },
+ { 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 },
+
+ /* Re-use the R/RG texstore functions.
+ * The code is generic enough to handle LATC too. */
+ { MESA_FORMAT_L_LATC1, _mesa_texstore_red_rgtc1 },
+ { MESA_FORMAT_SIGNED_L_LATC1, _mesa_texstore_signed_red_rgtc1 },
+ { MESA_FORMAT_LA_LATC2, _mesa_texstore_rg_rgtc2 },
+ { MESA_FORMAT_SIGNED_LA_LATC2, _mesa_texstore_signed_rg_rgtc2 },
+
+ { MESA_FORMAT_SIGNED_A8, _mesa_texstore_snorm8 },
+ { MESA_FORMAT_SIGNED_L8, _mesa_texstore_snorm8 },
+ { MESA_FORMAT_SIGNED_AL88, _mesa_texstore_snorm88 },
+ { MESA_FORMAT_SIGNED_I8, _mesa_texstore_snorm8 },
+
+ { MESA_FORMAT_SIGNED_A16, _mesa_texstore_snorm16 },
+ { MESA_FORMAT_SIGNED_L16, _mesa_texstore_snorm16 },
+ { MESA_FORMAT_SIGNED_AL1616, _mesa_texstore_snorm1616 },
+ { MESA_FORMAT_SIGNED_I16, _mesa_texstore_snorm16 },
+
+ { MESA_FORMAT_RGB9_E5_FLOAT, _mesa_texstore_rgb9_e5 },
+ { MESA_FORMAT_R11_G11_B10_FLOAT, _mesa_texstore_r11_g11_b10f },
+};
+
+
+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/transformfeedback.c b/mesalib/src/mesa/main/transformfeedback.c
index 2ff262fc6..85c213552 100644
--- a/mesalib/src/mesa/main/transformfeedback.c
+++ b/mesalib/src/mesa/main/transformfeedback.c
@@ -42,7 +42,6 @@
#include "main/dispatch.h"
#include "program/prog_parameter.h"
-//#include "program/shader_api.h"
#if FEATURE_EXT_transform_feedback
@@ -507,7 +506,7 @@ _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer)
if (obj->Active) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glBindBufferRange(transform feedback active)");
+ "glBindBufferBase(transform feedback active)");
return;
}
@@ -555,7 +554,7 @@ _mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
if (obj->Active) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glBindBufferRange(transform feedback active)");
+ "glBindBufferOffsetEXT(transform feedback active)");
return;
}
@@ -885,7 +884,7 @@ _mesa_ResumeTransformFeedback(void)
if (!obj->Active || !obj->Paused) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glPauseTransformFeedback(feedback not active or not paused)");
+ "glResumeTransformFeedback(feedback not active or not paused)");
return;
}
@@ -932,15 +931,4 @@ _mesa_DrawTransformFeedback(GLenum mode, GLuint name)
}
-/*
-XXX misc to do:
-
-glGet*() for
-
-GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED
-GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE
-GL_TRANSFORM_FEEDBACK_BINDING
-*/
-
-
#endif /* FEATURE_EXT_transform_feedback */
diff --git a/mesalib/src/mesa/main/varray.c b/mesalib/src/mesa/main/varray.c
index d20e2c719..6b888b485 100644
--- a/mesalib/src/mesa/main/varray.c
+++ b/mesalib/src/mesa/main/varray.c
@@ -1,1205 +1,1208 @@
-/*
- * 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 "bufferobj.h"
-#include "context.h"
-#include "enable.h"
-#include "enums.h"
-#include "hash.h"
-#include "image.h"
-#include "macros.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "varray.h"
-#include "arrayobj.h"
-#include "main/dispatch.h"
-
-
-/** Used to do error checking for GL_EXT_vertex_array_bgra */
-#define BGRA_OR_4 5
-
-
-/** Used to indicate which GL datatypes are accepted by each of the
- * glVertex/Color/Attrib/EtcPointer() functions.
- */
-#define BOOL_BIT 0x1
-#define BYTE_BIT 0x2
-#define UNSIGNED_BYTE_BIT 0x4
-#define SHORT_BIT 0x8
-#define UNSIGNED_SHORT_BIT 0x10
-#define INT_BIT 0x20
-#define UNSIGNED_INT_BIT 0x40
-#define HALF_BIT 0x80
-#define FLOAT_BIT 0x100
-#define DOUBLE_BIT 0x200
-#define FIXED_BIT 0x400
-
-
-
-/** Convert GL datatype enum into a <type>_BIT value seen above */
-static GLbitfield
-type_to_bit(const struct gl_context *ctx, GLenum type)
-{
- switch (type) {
- case GL_BOOL:
- return BOOL_BIT;
- case GL_BYTE:
- return BYTE_BIT;
- case GL_UNSIGNED_BYTE:
- return UNSIGNED_BYTE_BIT;
- case GL_SHORT:
- return SHORT_BIT;
- case GL_UNSIGNED_SHORT:
- return UNSIGNED_SHORT_BIT;
- case GL_INT:
- return INT_BIT;
- case GL_UNSIGNED_INT:
- return UNSIGNED_INT_BIT;
- case GL_HALF_FLOAT:
- if (ctx->Extensions.ARB_half_float_vertex)
- return HALF_BIT;
- else
- return 0x0;
- case GL_FLOAT:
- return FLOAT_BIT;
- case GL_DOUBLE:
- return DOUBLE_BIT;
- case GL_FIXED:
- return FIXED_BIT;
- default:
- return 0;
- }
-}
-
-
-/**
- * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
- * functions.
- *
- * \param func name of calling function used for error reporting
- * \param array the array to update
- * \param dirtyBit which bit to set in ctx->Array.NewState for this array
- * \param legalTypes bitmask of *_BIT above indicating legal datatypes
- * \param sizeMin min allowable size value
- * \param sizeMax max allowable size value (may also be BGRA_OR_4)
- * \param size components per element (1, 2, 3 or 4)
- * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
- * \param stride stride between elements, in elements
- * \param normalized are integer types converted to floats in [-1, 1]?
- * \param integer integer-valued values (will not be normalized to [-1,1])
- * \param ptr the address (or offset inside VBO) of the array data
- */
-static void
-update_array(struct gl_context *ctx,
- const char *func,
- struct gl_client_array *array,
- GLbitfield dirtyBit, GLbitfield legalTypesMask,
- GLint sizeMin, GLint sizeMax,
- GLint size, GLenum type, GLsizei stride,
- GLboolean normalized, GLboolean integer,
- const GLvoid *ptr)
-{
- GLbitfield typeBit;
- GLsizei elementSize;
- GLenum format = GL_RGBA;
-
- if (ctx->API != API_OPENGLES && ctx->API != API_OPENGLES2) {
- /* fixed point arrays / data is only allowed with OpenGL ES 1.x/2.0 */
- legalTypesMask &= ~FIXED_BIT;
- }
-
- typeBit = type_to_bit(ctx, type);
- if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
- func, _mesa_lookup_enum_by_nr(type));
- return;
- }
-
- /* Do size parameter checking.
- * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
- * must be handled specially.
- */
- if (ctx->Extensions.EXT_vertex_array_bgra &&
- sizeMax == BGRA_OR_4 &&
- size == GL_BGRA) {
- if (type != GL_UNSIGNED_BYTE) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(GL_BGRA/GLubyte)", func);
- return;
- }
- format = GL_BGRA;
- size = 4;
- }
- else if (size < sizeMin || size > sizeMax || size > 4) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
- return;
- }
-
- ASSERT(size <= 4);
-
- if (stride < 0) {
- _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
- return;
- }
-
- if (ctx->Array.ArrayObj->VBOonly &&
- ctx->Array.ArrayBufferObj->Name == 0) {
- /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
- * Generate GL_INVALID_OPERATION if that's not true.
- */
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
- return;
- }
-
- elementSize = _mesa_sizeof_type(type) * size;
-
- array->Size = size;
- array->Type = type;
- array->Format = format;
- array->Stride = stride;
- array->StrideB = stride ? stride : elementSize;
- array->Normalized = normalized;
- array->Ptr = (const GLubyte *) ptr;
- array->_ElementSize = elementSize;
-
- _mesa_reference_buffer_object(ctx, &array->BufferObj,
- ctx->Array.ArrayBufferObj);
-
- ctx->NewState |= _NEW_ARRAY;
- ctx->Array.NewState |= dirtyBit;
-}
-
-
-void GLAPIENTRY
-_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- GLbitfield legalTypes = (SHORT_BIT | INT_BIT | FLOAT_BIT |
- DOUBLE_BIT | HALF_BIT | FIXED_BIT);
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (ctx->API == API_OPENGLES)
- legalTypes |= BYTE_BIT;
-
- update_array(ctx, "glVertexPointer",
- &ctx->Array.ArrayObj->Vertex, _NEW_ARRAY_VERTEX,
- legalTypes, 2, 4,
- size, type, stride, GL_FALSE, GL_FALSE, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
-{
- const GLbitfield legalTypes = (BYTE_BIT | SHORT_BIT | INT_BIT |
- HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
- FIXED_BIT);
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- update_array(ctx, "glNormalPointer",
- &ctx->Array.ArrayObj->Normal, _NEW_ARRAY_NORMAL,
- legalTypes, 3, 3,
- 3, type, stride, GL_TRUE, GL_FALSE, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
- SHORT_BIT | UNSIGNED_SHORT_BIT |
- INT_BIT | UNSIGNED_INT_BIT |
- HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
- FIXED_BIT);
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- update_array(ctx, "glColorPointer",
- &ctx->Array.ArrayObj->Color, _NEW_ARRAY_COLOR0,
- legalTypes, 3, BGRA_OR_4,
- size, type, stride, GL_TRUE, GL_FALSE, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- update_array(ctx, "glFogCoordPointer",
- &ctx->Array.ArrayObj->FogCoord, _NEW_ARRAY_FOGCOORD,
- legalTypes, 1, 1,
- 1, type, stride, GL_FALSE, GL_FALSE, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
- FLOAT_BIT | DOUBLE_BIT);
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- update_array(ctx, "glIndexPointer",
- &ctx->Array.ArrayObj->Index, _NEW_ARRAY_INDEX,
- legalTypes, 1, 1,
- 1, type, stride, GL_FALSE, GL_FALSE, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
- GLsizei stride, const GLvoid *ptr)
-{
- const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
- SHORT_BIT | UNSIGNED_SHORT_BIT |
- INT_BIT | UNSIGNED_INT_BIT |
- HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- update_array(ctx, "glSecondaryColorPointer",
- &ctx->Array.ArrayObj->SecondaryColor, _NEW_ARRAY_COLOR1,
- legalTypes, 3, BGRA_OR_4,
- size, type, stride, GL_TRUE, GL_FALSE, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
- const GLvoid *ptr)
-{
- GLbitfield legalTypes = (SHORT_BIT | INT_BIT |
- HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
- FIXED_BIT);
- GET_CURRENT_CONTEXT(ctx);
- const GLuint unit = ctx->Array.ActiveTexture;
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (ctx->API == API_OPENGLES)
- legalTypes |= BYTE_BIT;
-
- ASSERT(unit < Elements(ctx->Array.ArrayObj->TexCoord));
-
- update_array(ctx, "glTexCoordPointer",
- &ctx->Array.ArrayObj->TexCoord[unit],
- _NEW_ARRAY_TEXCOORD(unit),
- legalTypes, 1, 4,
- size, type, stride, GL_FALSE, GL_FALSE,
- ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
-{
- const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
- /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
- const GLboolean integer = GL_TRUE;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- update_array(ctx, "glEdgeFlagPointer",
- &ctx->Array.ArrayObj->EdgeFlag, _NEW_ARRAY_EDGEFLAG,
- legalTypes, 1, 1,
- 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_PointSizePointer(GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- const GLbitfield legalTypes = (FLOAT_BIT | FIXED_BIT);
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (ctx->API != API_OPENGLES) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glPointSizePointer(ES 1.x only)");
- return;
- }
-
- update_array(ctx, "glPointSizePointer",
- &ctx->Array.ArrayObj->PointSize, _NEW_ARRAY_POINT_SIZE,
- legalTypes, 1, 1,
- 1, type, stride, GL_FALSE, GL_FALSE, ptr);
-}
-
-
-#if FEATURE_NV_vertex_program
-/**
- * Set a vertex attribute array.
- * Note that these arrays DO alias the conventional GL vertex arrays
- * (position, normal, color, fog, texcoord, etc).
- * The generic attribute slots at #16 and above are not touched.
- */
-void GLAPIENTRY
-_mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type,
- GLsizei stride, const GLvoid *ptr)
-{
- const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT |
- FLOAT_BIT | DOUBLE_BIT);
- GLboolean normalized = GL_FALSE;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)");
- return;
- }
-
- if (type == GL_UNSIGNED_BYTE && size != 4) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size!=4)");
- return;
- }
-
- update_array(ctx, "glVertexAttribPointerNV",
- &ctx->Array.ArrayObj->VertexAttrib[index],
- _NEW_ARRAY_ATTRIB(index),
- legalTypes, 1, BGRA_OR_4,
- size, type, stride, normalized, GL_FALSE, ptr);
-}
-#endif
-
-
-#if FEATURE_ARB_vertex_program
-/**
- * Set a generic vertex attribute array.
- * Note that these arrays DO NOT alias the conventional GL vertex arrays
- * (position, normal, color, fog, texcoord, etc).
- */
-void GLAPIENTRY
-_mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
- GLboolean normalized,
- GLsizei stride, const GLvoid *ptr)
-{
- const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
- SHORT_BIT | UNSIGNED_SHORT_BIT |
- INT_BIT | UNSIGNED_INT_BIT |
- HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
- FIXED_BIT);
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (index >= ctx->Const.VertexProgram.MaxAttribs) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
- return;
- }
-
- update_array(ctx, "glVertexAttribPointer",
- &ctx->Array.ArrayObj->VertexAttrib[index],
- _NEW_ARRAY_ATTRIB(index),
- legalTypes, 1, BGRA_OR_4,
- size, type, stride, normalized, GL_FALSE, ptr);
-}
-#endif
-
-
-/**
- * GL_EXT_gpu_shader4 / GL 3.0.
- * Set an integer-valued vertex attribute array.
- * Note that these arrays DO NOT alias the conventional GL vertex arrays
- * (position, normal, color, fog, texcoord, etc).
- */
-void GLAPIENTRY
-_mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
- GLsizei stride, const GLvoid *ptr)
-{
- const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
- SHORT_BIT | UNSIGNED_SHORT_BIT |
- INT_BIT | UNSIGNED_INT_BIT);
- const GLboolean normalized = GL_FALSE;
- const GLboolean integer = GL_TRUE;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (index >= ctx->Const.VertexProgram.MaxAttribs) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
- return;
- }
-
- update_array(ctx, "glVertexAttribIPointer",
- &ctx->Array.ArrayObj->VertexAttrib[index],
- _NEW_ARRAY_ATTRIB(index),
- legalTypes, 1, 4,
- size, type, stride, normalized, integer, ptr);
-}
-
-
-
-void GLAPIENTRY
-_mesa_EnableVertexAttribArrayARB(GLuint index)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (index >= ctx->Const.VertexProgram.MaxAttribs) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glEnableVertexAttribArrayARB(index)");
- return;
- }
-
- ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
-
- FLUSH_VERTICES(ctx, _NEW_ARRAY);
- ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_TRUE;
- ctx->Array.ArrayObj->_Enabled |= _NEW_ARRAY_ATTRIB(index);
- ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
-}
-
-
-void GLAPIENTRY
-_mesa_DisableVertexAttribArrayARB(GLuint index)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (index >= ctx->Const.VertexProgram.MaxAttribs) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glDisableVertexAttribArrayARB(index)");
- return;
- }
-
- ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
-
- FLUSH_VERTICES(ctx, _NEW_ARRAY);
- ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_FALSE;
- ctx->Array.ArrayObj->_Enabled &= ~_NEW_ARRAY_ATTRIB(index);
- ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
-}
-
-
-/**
- * Return info for a vertex attribute array (no alias with legacy
- * vertex attributes (pos, normal, color, etc)). This function does
- * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
- */
-static GLuint
-get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
- const char *caller)
-{
- const struct gl_client_array *array;
-
- if (index >= ctx->Const.VertexProgram.MaxAttribs) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
- return 0;
- }
-
- ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
-
- array = &ctx->Array.ArrayObj->VertexAttrib[index];
-
- switch (pname) {
- case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
- return array->Enabled;
- case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
- return array->Size;
- case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
- return array->Stride;
- case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
- return array->Type;
- case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
- return array->Normalized;
- case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
- return array->BufferObj->Name;
- case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
- if (ctx->Extensions.EXT_gpu_shader4) {
- return array->Integer;
- }
- goto error;
- case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
- if (ctx->Extensions.ARB_instanced_arrays) {
- return array->InstanceDivisor;
- }
- goto error;
- default:
- ; /* fall-through */
- }
-
-error:
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
- return 0;
-}
-
-
-static const GLfloat *
-get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
-{
- if (index == 0) {
- if (ctx->API != API_OPENGLES2) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
- return NULL;
- }
- }
- else if (index >= ctx->Const.VertexProgram.MaxAttribs) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
- return NULL;
- }
-
- FLUSH_CURRENT(ctx, 0);
- return ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index];
-}
-
-void GLAPIENTRY
-_mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
- const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
- if (v != NULL) {
- COPY_4V(params, v);
- }
- }
- else {
- params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
- "glGetVertexAttribfv");
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
- const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
- if (v != NULL) {
- params[0] = (GLdouble) v[0];
- params[1] = (GLdouble) v[1];
- params[2] = (GLdouble) v[2];
- params[3] = (GLdouble) v[3];
- }
- }
- else {
- params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
- "glGetVertexAttribdv");
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
- const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
- if (v != NULL) {
- /* XXX should floats in[0,1] be scaled to full int range? */
- params[0] = (GLint) v[0];
- params[1] = (GLint) v[1];
- params[2] = (GLint) v[2];
- params[3] = (GLint) v[3];
- }
- }
- else {
- params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
- "glGetVertexAttribiv");
- }
-}
-
-
-/** GL 3.0 */
-void GLAPIENTRY
-_mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
- const GLfloat *v =
- get_current_attrib(ctx, index, "glGetVertexAttribIiv");
- if (v != NULL) {
- /* XXX we don't have true integer-valued vertex attribs yet */
- params[0] = (GLint) v[0];
- params[1] = (GLint) v[1];
- params[2] = (GLint) v[2];
- params[3] = (GLint) v[3];
- }
- }
- else {
- params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
- "glGetVertexAttribIiv");
- }
-}
-
-
-/** GL 3.0 */
-void GLAPIENTRY
-_mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
- const GLfloat *v =
- get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
- if (v != NULL) {
- /* XXX we don't have true integer-valued vertex attribs yet */
- params[0] = (GLuint) v[0];
- params[1] = (GLuint) v[1];
- params[2] = (GLuint) v[2];
- params[3] = (GLuint) v[3];
- }
- }
- else {
- params[0] = get_vertex_array_attrib(ctx, index, pname,
- "glGetVertexAttribIuiv");
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (index >= ctx->Const.VertexProgram.MaxAttribs) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
- return;
- }
-
- if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
- return;
- }
-
- ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
-
- *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
-}
-
-
-void GLAPIENTRY
-_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
- GLsizei count, const GLvoid *ptr)
-{
- (void) count;
- _mesa_VertexPointer(size, type, stride, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
- const GLvoid *ptr)
-{
- (void) count;
- _mesa_NormalPointer(type, stride, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
- const GLvoid *ptr)
-{
- (void) count;
- _mesa_ColorPointer(size, type, stride, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
- const GLvoid *ptr)
-{
- (void) count;
- _mesa_IndexPointer(type, stride, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
- GLsizei count, const GLvoid *ptr)
-{
- (void) count;
- _mesa_TexCoordPointer(size, type, stride, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
-{
- (void) count;
- _mesa_EdgeFlagPointer(stride, ptr);
-}
-
-
-void GLAPIENTRY
-_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
-{
- GET_CURRENT_CONTEXT(ctx);
- GLboolean tflag, cflag, nflag; /* enable/disable flags */
- GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
- GLenum ctype = 0; /* color type */
- GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
- const GLint toffset = 0; /* always zero */
- GLint defstride; /* default stride */
- GLint c, f;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- f = sizeof(GLfloat);
- c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
-
- if (stride < 0) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
- return;
- }
-
- switch (format) {
- case GL_V2F:
- tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
- tcomps = 0; ccomps = 0; vcomps = 2;
- voffset = 0;
- defstride = 2*f;
- break;
- case GL_V3F:
- tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
- tcomps = 0; ccomps = 0; vcomps = 3;
- voffset = 0;
- defstride = 3*f;
- break;
- case GL_C4UB_V2F:
- tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
- tcomps = 0; ccomps = 4; vcomps = 2;
- ctype = GL_UNSIGNED_BYTE;
- coffset = 0;
- voffset = c;
- defstride = c + 2*f;
- break;
- case GL_C4UB_V3F:
- tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
- tcomps = 0; ccomps = 4; vcomps = 3;
- ctype = GL_UNSIGNED_BYTE;
- coffset = 0;
- voffset = c;
- defstride = c + 3*f;
- break;
- case GL_C3F_V3F:
- tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
- tcomps = 0; ccomps = 3; vcomps = 3;
- ctype = GL_FLOAT;
- coffset = 0;
- voffset = 3*f;
- defstride = 6*f;
- break;
- case GL_N3F_V3F:
- tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
- tcomps = 0; ccomps = 0; vcomps = 3;
- noffset = 0;
- voffset = 3*f;
- defstride = 6*f;
- break;
- case GL_C4F_N3F_V3F:
- tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
- tcomps = 0; ccomps = 4; vcomps = 3;
- ctype = GL_FLOAT;
- coffset = 0;
- noffset = 4*f;
- voffset = 7*f;
- defstride = 10*f;
- break;
- case GL_T2F_V3F:
- tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
- tcomps = 2; ccomps = 0; vcomps = 3;
- voffset = 2*f;
- defstride = 5*f;
- break;
- case GL_T4F_V4F:
- tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
- tcomps = 4; ccomps = 0; vcomps = 4;
- voffset = 4*f;
- defstride = 8*f;
- break;
- case GL_T2F_C4UB_V3F:
- tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
- tcomps = 2; ccomps = 4; vcomps = 3;
- ctype = GL_UNSIGNED_BYTE;
- coffset = 2*f;
- voffset = c+2*f;
- defstride = c+5*f;
- break;
- case GL_T2F_C3F_V3F:
- tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
- tcomps = 2; ccomps = 3; vcomps = 3;
- ctype = GL_FLOAT;
- coffset = 2*f;
- voffset = 5*f;
- defstride = 8*f;
- break;
- case GL_T2F_N3F_V3F:
- tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
- tcomps = 2; ccomps = 0; vcomps = 3;
- noffset = 2*f;
- voffset = 5*f;
- defstride = 8*f;
- break;
- case GL_T2F_C4F_N3F_V3F:
- tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
- tcomps = 2; ccomps = 4; vcomps = 3;
- ctype = GL_FLOAT;
- coffset = 2*f;
- noffset = 6*f;
- voffset = 9*f;
- defstride = 12*f;
- break;
- case GL_T4F_C4F_N3F_V4F:
- tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
- tcomps = 4; ccomps = 4; vcomps = 4;
- ctype = GL_FLOAT;
- coffset = 4*f;
- noffset = 8*f;
- voffset = 11*f;
- defstride = 15*f;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
- return;
- }
-
- if (stride==0) {
- stride = defstride;
- }
-
- _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
- _mesa_DisableClientState( GL_INDEX_ARRAY );
- /* XXX also disable secondary color and generic arrays? */
-
- /* Texcoords */
- if (tflag) {
- _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
- _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
- (GLubyte *) pointer + toffset );
- }
- else {
- _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
- }
-
- /* Color */
- if (cflag) {
- _mesa_EnableClientState( GL_COLOR_ARRAY );
- _mesa_ColorPointer( ccomps, ctype, stride,
- (GLubyte *) pointer + coffset );
- }
- else {
- _mesa_DisableClientState( GL_COLOR_ARRAY );
- }
-
-
- /* Normals */
- if (nflag) {
- _mesa_EnableClientState( GL_NORMAL_ARRAY );
- _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
- }
- else {
- _mesa_DisableClientState( GL_NORMAL_ARRAY );
- }
-
- /* Vertices */
- _mesa_EnableClientState( GL_VERTEX_ARRAY );
- _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
- (GLubyte *) pointer + voffset );
-}
-
-
-void GLAPIENTRY
-_mesa_LockArraysEXT(GLint first, GLsizei count)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
-
- if (first < 0) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
- return;
- }
- if (count <= 0) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
- return;
- }
- if (ctx->Array.LockCount != 0) {
- _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
- return;
- }
-
- ctx->Array.LockFirst = first;
- ctx->Array.LockCount = count;
-
- ctx->NewState |= _NEW_ARRAY;
- ctx->Array.NewState |= _NEW_ARRAY_ALL;
-}
-
-
-void GLAPIENTRY
-_mesa_UnlockArraysEXT( void )
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "glUnlockArrays\n");
-
- if (ctx->Array.LockCount == 0) {
- _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
- return;
- }
-
- ctx->Array.LockFirst = 0;
- ctx->Array.LockCount = 0;
- ctx->NewState |= _NEW_ARRAY;
- ctx->Array.NewState |= _NEW_ARRAY_ALL;
-}
-
-
-/* GL_EXT_multi_draw_arrays */
-void GLAPIENTRY
-_mesa_MultiDrawArraysEXT( GLenum mode, const GLint *first,
- const GLsizei *count, GLsizei primcount )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- for (i = 0; i < primcount; i++) {
- if (count[i] > 0) {
- CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
- }
- }
-}
-
-
-/* GL_IBM_multimode_draw_arrays */
-void GLAPIENTRY
-_mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
- const GLsizei * count,
- GLsizei primcount, GLint modestride )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- for ( i = 0 ; i < primcount ; i++ ) {
- if ( count[i] > 0 ) {
- GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
- CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
- }
- }
-}
-
-
-/* GL_IBM_multimode_draw_arrays */
-void GLAPIENTRY
-_mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
- GLenum type, const GLvoid * const * indices,
- GLsizei primcount, GLint modestride )
-{
- GET_CURRENT_CONTEXT(ctx);
- GLint i;
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- /* XXX not sure about ARB_vertex_buffer_object handling here */
-
- for ( i = 0 ; i < primcount ; i++ ) {
- if ( count[i] > 0 ) {
- GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
- CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
- }
- }
-}
-
-
-/**
- * GL_NV_primitive_restart and GL 3.1
- */
-void GLAPIENTRY
-_mesa_PrimitiveRestartIndex(GLuint index)
-{
- GET_CURRENT_CONTEXT(ctx);
-
- if (!ctx->Extensions.NV_primitive_restart &&
- ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
- return;
- }
-
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
-
- ctx->Array.RestartIndex = index;
-}
-
-
-/**
- * See GL_ARB_instanced_arrays.
- * Note that the instance divisor only applies to generic arrays, not
- * the legacy vertex arrays.
- */
-void GLAPIENTRY
-_mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (!ctx->Extensions.ARB_instanced_arrays) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
- return;
- }
-
- if (index >= ctx->Const.VertexProgram.MaxAttribs) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glVertexAttribDivisor(index = %u)",
- index);
- return;
- }
-
- ctx->Array.ArrayObj->VertexAttrib[index].InstanceDivisor = divisor;
-}
-
-
-
-/**
- * Copy one client vertex array to another.
- */
-void
-_mesa_copy_client_array(struct gl_context *ctx,
- struct gl_client_array *dst,
- struct gl_client_array *src)
-{
- dst->Size = src->Size;
- dst->Type = src->Type;
- dst->Format = src->Format;
- dst->Stride = src->Stride;
- dst->StrideB = src->StrideB;
- dst->Ptr = src->Ptr;
- dst->Enabled = src->Enabled;
- dst->Normalized = src->Normalized;
- dst->Integer = src->Integer;
- dst->InstanceDivisor = src->InstanceDivisor;
- dst->_ElementSize = src->_ElementSize;
- _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
- dst->_MaxElement = src->_MaxElement;
-}
-
-
-
-/**
- * Print vertex array's fields.
- */
-static void
-print_array(const char *name, GLint index, const struct gl_client_array *array)
-{
- if (index >= 0)
- printf(" %s[%d]: ", name, index);
- else
- printf(" %s: ", name);
- printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
- array->Ptr, array->Type, array->Size,
- array->_ElementSize, array->StrideB,
- array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
- array->_MaxElement);
-}
-
-
-/**
- * Print current vertex object/array info. For debug.
- */
-void
-_mesa_print_arrays(struct gl_context *ctx)
-{
- struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
- GLuint i;
-
- _mesa_update_array_object_max_element(ctx, arrayObj);
-
- printf("Array Object %u\n", arrayObj->Name);
- if (arrayObj->Vertex.Enabled)
- print_array("Vertex", -1, &arrayObj->Vertex);
- if (arrayObj->Normal.Enabled)
- print_array("Normal", -1, &arrayObj->Normal);
- if (arrayObj->Color.Enabled)
- print_array("Color", -1, &arrayObj->Color);
- for (i = 0; i < Elements(arrayObj->TexCoord); i++)
- if (arrayObj->TexCoord[i].Enabled)
- print_array("TexCoord", i, &arrayObj->TexCoord[i]);
- for (i = 0; i < Elements(arrayObj->VertexAttrib); i++)
- if (arrayObj->VertexAttrib[i].Enabled)
- print_array("Attrib", i, &arrayObj->VertexAttrib[i]);
- printf(" _MaxElement = %u\n", arrayObj->_MaxElement);
-}
-
-
-/**
- * Initialize vertex array state for given context.
- */
-void
-_mesa_init_varray(struct gl_context *ctx)
-{
- ctx->Array.DefaultArrayObj = _mesa_new_array_object(ctx, 0);
- _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
- ctx->Array.DefaultArrayObj);
- ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
-
- ctx->Array.Objects = _mesa_NewHashTable();
-}
-
-
-/**
- * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
- */
-static void
-delete_arrayobj_cb(GLuint id, void *data, void *userData)
-{
- struct gl_array_object *arrayObj = (struct gl_array_object *) data;
- struct gl_context *ctx = (struct gl_context *) userData;
- _mesa_delete_array_object(ctx, arrayObj);
-}
-
-
-/**
- * Free vertex array state for given context.
- */
-void
-_mesa_free_varray_data(struct gl_context *ctx)
-{
- _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
- _mesa_DeleteHashTable(ctx->Array.Objects);
-}
+/*
+ * 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 "bufferobj.h"
+#include "context.h"
+#include "enable.h"
+#include "enums.h"
+#include "hash.h"
+#include "image.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "varray.h"
+#include "arrayobj.h"
+#include "main/dispatch.h"
+
+
+/** Used to do error checking for GL_EXT_vertex_array_bgra */
+#define BGRA_OR_4 5
+
+
+/** Used to indicate which GL datatypes are accepted by each of the
+ * glVertex/Color/Attrib/EtcPointer() functions.
+ */
+#define BOOL_BIT 0x1
+#define BYTE_BIT 0x2
+#define UNSIGNED_BYTE_BIT 0x4
+#define SHORT_BIT 0x8
+#define UNSIGNED_SHORT_BIT 0x10
+#define INT_BIT 0x20
+#define UNSIGNED_INT_BIT 0x40
+#define HALF_BIT 0x80
+#define FLOAT_BIT 0x100
+#define DOUBLE_BIT 0x200
+#define FIXED_ES_BIT 0x400
+#define FIXED_GL_BIT 0x800
+
+
+/** Convert GL datatype enum into a <type>_BIT value seen above */
+static GLbitfield
+type_to_bit(const struct gl_context *ctx, GLenum type)
+{
+ switch (type) {
+ case GL_BOOL:
+ return BOOL_BIT;
+ case GL_BYTE:
+ return BYTE_BIT;
+ case GL_UNSIGNED_BYTE:
+ return UNSIGNED_BYTE_BIT;
+ case GL_SHORT:
+ return SHORT_BIT;
+ case GL_UNSIGNED_SHORT:
+ return UNSIGNED_SHORT_BIT;
+ case GL_INT:
+ return INT_BIT;
+ case GL_UNSIGNED_INT:
+ return UNSIGNED_INT_BIT;
+ case GL_HALF_FLOAT:
+ if (ctx->Extensions.ARB_half_float_vertex)
+ return HALF_BIT;
+ else
+ return 0x0;
+ case GL_FLOAT:
+ return FLOAT_BIT;
+ case GL_DOUBLE:
+ return DOUBLE_BIT;
+ case GL_FIXED:
+ return ctx->API == API_OPENGL ? FIXED_GL_BIT : FIXED_ES_BIT;
+ default:
+ return 0;
+ }
+}
+
+
+/**
+ * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
+ * functions.
+ *
+ * \param func name of calling function used for error reporting
+ * \param array the array to update
+ * \param dirtyBit which bit to set in ctx->Array.NewState for this array
+ * \param legalTypes bitmask of *_BIT above indicating legal datatypes
+ * \param sizeMin min allowable size value
+ * \param sizeMax max allowable size value (may also be BGRA_OR_4)
+ * \param size components per element (1, 2, 3 or 4)
+ * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
+ * \param stride stride between elements, in elements
+ * \param normalized are integer types converted to floats in [-1, 1]?
+ * \param integer integer-valued values (will not be normalized to [-1,1])
+ * \param ptr the address (or offset inside VBO) of the array data
+ */
+static void
+update_array(struct gl_context *ctx,
+ const char *func,
+ struct gl_client_array *array,
+ GLbitfield dirtyBit, GLbitfield legalTypesMask,
+ GLint sizeMin, GLint sizeMax,
+ GLint size, GLenum type, GLsizei stride,
+ GLboolean normalized, GLboolean integer,
+ const GLvoid *ptr)
+{
+ GLbitfield typeBit;
+ GLsizei elementSize;
+ GLenum format = GL_RGBA;
+
+ if (ctx->API != API_OPENGLES && ctx->API != API_OPENGLES2) {
+ /* fixed point arrays / data is only allowed with OpenGL ES 1.x/2.0 */
+ legalTypesMask &= ~FIXED_ES_BIT;
+ }
+ if (!ctx->Extensions.ARB_ES2_compatibility) {
+ legalTypesMask &= ~FIXED_GL_BIT;
+ }
+
+ typeBit = type_to_bit(ctx, type);
+ if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
+ func, _mesa_lookup_enum_by_nr(type));
+ return;
+ }
+
+ /* Do size parameter checking.
+ * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
+ * must be handled specially.
+ */
+ if (ctx->Extensions.EXT_vertex_array_bgra &&
+ sizeMax == BGRA_OR_4 &&
+ size == GL_BGRA) {
+ if (type != GL_UNSIGNED_BYTE) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(GL_BGRA/GLubyte)", func);
+ return;
+ }
+ format = GL_BGRA;
+ size = 4;
+ }
+ else if (size < sizeMin || size > sizeMax || size > 4) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
+ return;
+ }
+
+ ASSERT(size <= 4);
+
+ if (stride < 0) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
+ return;
+ }
+
+ if (ctx->Array.ArrayObj->VBOonly &&
+ ctx->Array.ArrayBufferObj->Name == 0) {
+ /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
+ * Generate GL_INVALID_OPERATION if that's not true.
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
+ return;
+ }
+
+ elementSize = _mesa_sizeof_type(type) * size;
+
+ array->Size = size;
+ array->Type = type;
+ array->Format = format;
+ array->Stride = stride;
+ array->StrideB = stride ? stride : elementSize;
+ array->Normalized = normalized;
+ array->Ptr = (const GLubyte *) ptr;
+ array->_ElementSize = elementSize;
+
+ _mesa_reference_buffer_object(ctx, &array->BufferObj,
+ ctx->Array.ArrayBufferObj);
+
+ ctx->NewState |= _NEW_ARRAY;
+ ctx->Array.NewState |= dirtyBit;
+}
+
+
+void GLAPIENTRY
+_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
+{
+ GLbitfield legalTypes = (SHORT_BIT | INT_BIT | FLOAT_BIT |
+ DOUBLE_BIT | HALF_BIT | FIXED_ES_BIT);
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (ctx->API == API_OPENGLES)
+ legalTypes |= BYTE_BIT;
+
+ update_array(ctx, "glVertexPointer",
+ &ctx->Array.ArrayObj->Vertex, _NEW_ARRAY_VERTEX,
+ legalTypes, 2, 4,
+ size, type, stride, GL_FALSE, GL_FALSE, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
+{
+ const GLbitfield legalTypes = (BYTE_BIT | SHORT_BIT | INT_BIT |
+ HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
+ FIXED_ES_BIT);
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ update_array(ctx, "glNormalPointer",
+ &ctx->Array.ArrayObj->Normal, _NEW_ARRAY_NORMAL,
+ legalTypes, 3, 3,
+ 3, type, stride, GL_TRUE, GL_FALSE, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
+{
+ const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
+ SHORT_BIT | UNSIGNED_SHORT_BIT |
+ INT_BIT | UNSIGNED_INT_BIT |
+ HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
+ FIXED_ES_BIT);
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ update_array(ctx, "glColorPointer",
+ &ctx->Array.ArrayObj->Color, _NEW_ARRAY_COLOR0,
+ legalTypes, 3, BGRA_OR_4,
+ size, type, stride, GL_TRUE, GL_FALSE, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
+{
+ const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ update_array(ctx, "glFogCoordPointer",
+ &ctx->Array.ArrayObj->FogCoord, _NEW_ARRAY_FOGCOORD,
+ legalTypes, 1, 1,
+ 1, type, stride, GL_FALSE, GL_FALSE, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
+{
+ const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
+ FLOAT_BIT | DOUBLE_BIT);
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ update_array(ctx, "glIndexPointer",
+ &ctx->Array.ArrayObj->Index, _NEW_ARRAY_INDEX,
+ legalTypes, 1, 1,
+ 1, type, stride, GL_FALSE, GL_FALSE, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
+ GLsizei stride, const GLvoid *ptr)
+{
+ const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
+ SHORT_BIT | UNSIGNED_SHORT_BIT |
+ INT_BIT | UNSIGNED_INT_BIT |
+ HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ update_array(ctx, "glSecondaryColorPointer",
+ &ctx->Array.ArrayObj->SecondaryColor, _NEW_ARRAY_COLOR1,
+ legalTypes, 3, BGRA_OR_4,
+ size, type, stride, GL_TRUE, GL_FALSE, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
+ const GLvoid *ptr)
+{
+ GLbitfield legalTypes = (SHORT_BIT | INT_BIT |
+ HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
+ FIXED_ES_BIT);
+ GET_CURRENT_CONTEXT(ctx);
+ const GLuint unit = ctx->Array.ActiveTexture;
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (ctx->API == API_OPENGLES)
+ legalTypes |= BYTE_BIT;
+
+ ASSERT(unit < Elements(ctx->Array.ArrayObj->TexCoord));
+
+ update_array(ctx, "glTexCoordPointer",
+ &ctx->Array.ArrayObj->TexCoord[unit],
+ _NEW_ARRAY_TEXCOORD(unit),
+ legalTypes, 1, 4,
+ size, type, stride, GL_FALSE, GL_FALSE,
+ ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
+{
+ const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
+ /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
+ const GLboolean integer = GL_TRUE;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ update_array(ctx, "glEdgeFlagPointer",
+ &ctx->Array.ArrayObj->EdgeFlag, _NEW_ARRAY_EDGEFLAG,
+ legalTypes, 1, 1,
+ 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_PointSizePointer(GLenum type, GLsizei stride, const GLvoid *ptr)
+{
+ const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (ctx->API != API_OPENGLES) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glPointSizePointer(ES 1.x only)");
+ return;
+ }
+
+ update_array(ctx, "glPointSizePointer",
+ &ctx->Array.ArrayObj->PointSize, _NEW_ARRAY_POINT_SIZE,
+ legalTypes, 1, 1,
+ 1, type, stride, GL_FALSE, GL_FALSE, ptr);
+}
+
+
+#if FEATURE_NV_vertex_program
+/**
+ * Set a vertex attribute array.
+ * Note that these arrays DO alias the conventional GL vertex arrays
+ * (position, normal, color, fog, texcoord, etc).
+ * The generic attribute slots at #16 and above are not touched.
+ */
+void GLAPIENTRY
+_mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type,
+ GLsizei stride, const GLvoid *ptr)
+{
+ const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT |
+ FLOAT_BIT | DOUBLE_BIT);
+ GLboolean normalized = GL_FALSE;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)");
+ return;
+ }
+
+ if (type == GL_UNSIGNED_BYTE && size != 4) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size!=4)");
+ return;
+ }
+
+ update_array(ctx, "glVertexAttribPointerNV",
+ &ctx->Array.ArrayObj->VertexAttrib[index],
+ _NEW_ARRAY_ATTRIB(index),
+ legalTypes, 1, BGRA_OR_4,
+ size, type, stride, normalized, GL_FALSE, ptr);
+}
+#endif
+
+
+#if FEATURE_ARB_vertex_program
+/**
+ * Set a generic vertex attribute array.
+ * Note that these arrays DO NOT alias the conventional GL vertex arrays
+ * (position, normal, color, fog, texcoord, etc).
+ */
+void GLAPIENTRY
+_mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
+ GLboolean normalized,
+ GLsizei stride, const GLvoid *ptr)
+{
+ const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
+ SHORT_BIT | UNSIGNED_SHORT_BIT |
+ INT_BIT | UNSIGNED_INT_BIT |
+ HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
+ FIXED_ES_BIT | FIXED_GL_BIT);
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (index >= ctx->Const.VertexProgram.MaxAttribs) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
+ return;
+ }
+
+ update_array(ctx, "glVertexAttribPointer",
+ &ctx->Array.ArrayObj->VertexAttrib[index],
+ _NEW_ARRAY_ATTRIB(index),
+ legalTypes, 1, BGRA_OR_4,
+ size, type, stride, normalized, GL_FALSE, ptr);
+}
+#endif
+
+
+/**
+ * GL_EXT_gpu_shader4 / GL 3.0.
+ * Set an integer-valued vertex attribute array.
+ * Note that these arrays DO NOT alias the conventional GL vertex arrays
+ * (position, normal, color, fog, texcoord, etc).
+ */
+void GLAPIENTRY
+_mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
+ GLsizei stride, const GLvoid *ptr)
+{
+ const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
+ SHORT_BIT | UNSIGNED_SHORT_BIT |
+ INT_BIT | UNSIGNED_INT_BIT);
+ const GLboolean normalized = GL_FALSE;
+ const GLboolean integer = GL_TRUE;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (index >= ctx->Const.VertexProgram.MaxAttribs) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
+ return;
+ }
+
+ update_array(ctx, "glVertexAttribIPointer",
+ &ctx->Array.ArrayObj->VertexAttrib[index],
+ _NEW_ARRAY_ATTRIB(index),
+ legalTypes, 1, 4,
+ size, type, stride, normalized, integer, ptr);
+}
+
+
+
+void GLAPIENTRY
+_mesa_EnableVertexAttribArrayARB(GLuint index)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (index >= ctx->Const.VertexProgram.MaxAttribs) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glEnableVertexAttribArrayARB(index)");
+ return;
+ }
+
+ ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
+
+ FLUSH_VERTICES(ctx, _NEW_ARRAY);
+ ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_TRUE;
+ ctx->Array.ArrayObj->_Enabled |= _NEW_ARRAY_ATTRIB(index);
+ ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
+}
+
+
+void GLAPIENTRY
+_mesa_DisableVertexAttribArrayARB(GLuint index)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (index >= ctx->Const.VertexProgram.MaxAttribs) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glDisableVertexAttribArrayARB(index)");
+ return;
+ }
+
+ ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
+
+ FLUSH_VERTICES(ctx, _NEW_ARRAY);
+ ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_FALSE;
+ ctx->Array.ArrayObj->_Enabled &= ~_NEW_ARRAY_ATTRIB(index);
+ ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
+}
+
+
+/**
+ * Return info for a vertex attribute array (no alias with legacy
+ * vertex attributes (pos, normal, color, etc)). This function does
+ * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
+ */
+static GLuint
+get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
+ const char *caller)
+{
+ const struct gl_client_array *array;
+
+ if (index >= ctx->Const.VertexProgram.MaxAttribs) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
+ return 0;
+ }
+
+ ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
+
+ array = &ctx->Array.ArrayObj->VertexAttrib[index];
+
+ switch (pname) {
+ case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
+ return array->Enabled;
+ case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
+ return array->Size;
+ case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
+ return array->Stride;
+ case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
+ return array->Type;
+ case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
+ return array->Normalized;
+ case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
+ return array->BufferObj->Name;
+ case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
+ if (ctx->Extensions.EXT_gpu_shader4) {
+ return array->Integer;
+ }
+ goto error;
+ case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
+ if (ctx->Extensions.ARB_instanced_arrays) {
+ return array->InstanceDivisor;
+ }
+ goto error;
+ default:
+ ; /* fall-through */
+ }
+
+error:
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
+ return 0;
+}
+
+
+static const GLfloat *
+get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
+{
+ if (index == 0) {
+ if (ctx->API != API_OPENGLES2) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
+ return NULL;
+ }
+ }
+ else if (index >= ctx->Const.VertexProgram.MaxAttribs) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
+ return NULL;
+ }
+
+ FLUSH_CURRENT(ctx, 0);
+ return ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index];
+}
+
+void GLAPIENTRY
+_mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
+ const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
+ if (v != NULL) {
+ COPY_4V(params, v);
+ }
+ }
+ else {
+ params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
+ "glGetVertexAttribfv");
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
+ const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
+ if (v != NULL) {
+ params[0] = (GLdouble) v[0];
+ params[1] = (GLdouble) v[1];
+ params[2] = (GLdouble) v[2];
+ params[3] = (GLdouble) v[3];
+ }
+ }
+ else {
+ params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
+ "glGetVertexAttribdv");
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
+ const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
+ if (v != NULL) {
+ /* XXX should floats in[0,1] be scaled to full int range? */
+ params[0] = (GLint) v[0];
+ params[1] = (GLint) v[1];
+ params[2] = (GLint) v[2];
+ params[3] = (GLint) v[3];
+ }
+ }
+ else {
+ params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
+ "glGetVertexAttribiv");
+ }
+}
+
+
+/** GL 3.0 */
+void GLAPIENTRY
+_mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
+ const GLfloat *v =
+ get_current_attrib(ctx, index, "glGetVertexAttribIiv");
+ if (v != NULL) {
+ /* XXX we don't have true integer-valued vertex attribs yet */
+ params[0] = (GLint) v[0];
+ params[1] = (GLint) v[1];
+ params[2] = (GLint) v[2];
+ params[3] = (GLint) v[3];
+ }
+ }
+ else {
+ params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
+ "glGetVertexAttribIiv");
+ }
+}
+
+
+/** GL 3.0 */
+void GLAPIENTRY
+_mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
+ const GLfloat *v =
+ get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
+ if (v != NULL) {
+ /* XXX we don't have true integer-valued vertex attribs yet */
+ params[0] = (GLuint) v[0];
+ params[1] = (GLuint) v[1];
+ params[2] = (GLuint) v[2];
+ params[3] = (GLuint) v[3];
+ }
+ }
+ else {
+ params[0] = get_vertex_array_attrib(ctx, index, pname,
+ "glGetVertexAttribIuiv");
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (index >= ctx->Const.VertexProgram.MaxAttribs) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
+ return;
+ }
+
+ if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
+ return;
+ }
+
+ ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
+
+ *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
+}
+
+
+void GLAPIENTRY
+_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
+ GLsizei count, const GLvoid *ptr)
+{
+ (void) count;
+ _mesa_VertexPointer(size, type, stride, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
+ const GLvoid *ptr)
+{
+ (void) count;
+ _mesa_NormalPointer(type, stride, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
+ const GLvoid *ptr)
+{
+ (void) count;
+ _mesa_ColorPointer(size, type, stride, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
+ const GLvoid *ptr)
+{
+ (void) count;
+ _mesa_IndexPointer(type, stride, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
+ GLsizei count, const GLvoid *ptr)
+{
+ (void) count;
+ _mesa_TexCoordPointer(size, type, stride, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
+{
+ (void) count;
+ _mesa_EdgeFlagPointer(stride, ptr);
+}
+
+
+void GLAPIENTRY
+_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLboolean tflag, cflag, nflag; /* enable/disable flags */
+ GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
+ GLenum ctype = 0; /* color type */
+ GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
+ const GLint toffset = 0; /* always zero */
+ GLint defstride; /* default stride */
+ GLint c, f;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ f = sizeof(GLfloat);
+ c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
+
+ if (stride < 0) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
+ return;
+ }
+
+ switch (format) {
+ case GL_V2F:
+ tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
+ tcomps = 0; ccomps = 0; vcomps = 2;
+ voffset = 0;
+ defstride = 2*f;
+ break;
+ case GL_V3F:
+ tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
+ tcomps = 0; ccomps = 0; vcomps = 3;
+ voffset = 0;
+ defstride = 3*f;
+ break;
+ case GL_C4UB_V2F:
+ tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
+ tcomps = 0; ccomps = 4; vcomps = 2;
+ ctype = GL_UNSIGNED_BYTE;
+ coffset = 0;
+ voffset = c;
+ defstride = c + 2*f;
+ break;
+ case GL_C4UB_V3F:
+ tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
+ tcomps = 0; ccomps = 4; vcomps = 3;
+ ctype = GL_UNSIGNED_BYTE;
+ coffset = 0;
+ voffset = c;
+ defstride = c + 3*f;
+ break;
+ case GL_C3F_V3F:
+ tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
+ tcomps = 0; ccomps = 3; vcomps = 3;
+ ctype = GL_FLOAT;
+ coffset = 0;
+ voffset = 3*f;
+ defstride = 6*f;
+ break;
+ case GL_N3F_V3F:
+ tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
+ tcomps = 0; ccomps = 0; vcomps = 3;
+ noffset = 0;
+ voffset = 3*f;
+ defstride = 6*f;
+ break;
+ case GL_C4F_N3F_V3F:
+ tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
+ tcomps = 0; ccomps = 4; vcomps = 3;
+ ctype = GL_FLOAT;
+ coffset = 0;
+ noffset = 4*f;
+ voffset = 7*f;
+ defstride = 10*f;
+ break;
+ case GL_T2F_V3F:
+ tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
+ tcomps = 2; ccomps = 0; vcomps = 3;
+ voffset = 2*f;
+ defstride = 5*f;
+ break;
+ case GL_T4F_V4F:
+ tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
+ tcomps = 4; ccomps = 0; vcomps = 4;
+ voffset = 4*f;
+ defstride = 8*f;
+ break;
+ case GL_T2F_C4UB_V3F:
+ tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
+ tcomps = 2; ccomps = 4; vcomps = 3;
+ ctype = GL_UNSIGNED_BYTE;
+ coffset = 2*f;
+ voffset = c+2*f;
+ defstride = c+5*f;
+ break;
+ case GL_T2F_C3F_V3F:
+ tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
+ tcomps = 2; ccomps = 3; vcomps = 3;
+ ctype = GL_FLOAT;
+ coffset = 2*f;
+ voffset = 5*f;
+ defstride = 8*f;
+ break;
+ case GL_T2F_N3F_V3F:
+ tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
+ tcomps = 2; ccomps = 0; vcomps = 3;
+ noffset = 2*f;
+ voffset = 5*f;
+ defstride = 8*f;
+ break;
+ case GL_T2F_C4F_N3F_V3F:
+ tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
+ tcomps = 2; ccomps = 4; vcomps = 3;
+ ctype = GL_FLOAT;
+ coffset = 2*f;
+ noffset = 6*f;
+ voffset = 9*f;
+ defstride = 12*f;
+ break;
+ case GL_T4F_C4F_N3F_V4F:
+ tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
+ tcomps = 4; ccomps = 4; vcomps = 4;
+ ctype = GL_FLOAT;
+ coffset = 4*f;
+ noffset = 8*f;
+ voffset = 11*f;
+ defstride = 15*f;
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
+ return;
+ }
+
+ if (stride==0) {
+ stride = defstride;
+ }
+
+ _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
+ _mesa_DisableClientState( GL_INDEX_ARRAY );
+ /* XXX also disable secondary color and generic arrays? */
+
+ /* Texcoords */
+ if (tflag) {
+ _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
+ _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
+ (GLubyte *) pointer + toffset );
+ }
+ else {
+ _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
+ }
+
+ /* Color */
+ if (cflag) {
+ _mesa_EnableClientState( GL_COLOR_ARRAY );
+ _mesa_ColorPointer( ccomps, ctype, stride,
+ (GLubyte *) pointer + coffset );
+ }
+ else {
+ _mesa_DisableClientState( GL_COLOR_ARRAY );
+ }
+
+
+ /* Normals */
+ if (nflag) {
+ _mesa_EnableClientState( GL_NORMAL_ARRAY );
+ _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
+ }
+ else {
+ _mesa_DisableClientState( GL_NORMAL_ARRAY );
+ }
+
+ /* Vertices */
+ _mesa_EnableClientState( GL_VERTEX_ARRAY );
+ _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
+ (GLubyte *) pointer + voffset );
+}
+
+
+void GLAPIENTRY
+_mesa_LockArraysEXT(GLint first, GLsizei count)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
+
+ if (first < 0) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
+ return;
+ }
+ if (count <= 0) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
+ return;
+ }
+ if (ctx->Array.LockCount != 0) {
+ _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
+ return;
+ }
+
+ ctx->Array.LockFirst = first;
+ ctx->Array.LockCount = count;
+
+ ctx->NewState |= _NEW_ARRAY;
+ ctx->Array.NewState |= _NEW_ARRAY_ALL;
+}
+
+
+void GLAPIENTRY
+_mesa_UnlockArraysEXT( void )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glUnlockArrays\n");
+
+ if (ctx->Array.LockCount == 0) {
+ _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
+ return;
+ }
+
+ ctx->Array.LockFirst = 0;
+ ctx->Array.LockCount = 0;
+ ctx->NewState |= _NEW_ARRAY;
+ ctx->Array.NewState |= _NEW_ARRAY_ALL;
+}
+
+
+/* GL_EXT_multi_draw_arrays */
+void GLAPIENTRY
+_mesa_MultiDrawArraysEXT( GLenum mode, const GLint *first,
+ const GLsizei *count, GLsizei primcount )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ for (i = 0; i < primcount; i++) {
+ if (count[i] > 0) {
+ CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
+ }
+ }
+}
+
+
+/* GL_IBM_multimode_draw_arrays */
+void GLAPIENTRY
+_mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
+ const GLsizei * count,
+ GLsizei primcount, GLint modestride )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ for ( i = 0 ; i < primcount ; i++ ) {
+ if ( count[i] > 0 ) {
+ GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
+ CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
+ }
+ }
+}
+
+
+/* GL_IBM_multimode_draw_arrays */
+void GLAPIENTRY
+_mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
+ GLenum type, const GLvoid * const * indices,
+ GLsizei primcount, GLint modestride )
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ /* XXX not sure about ARB_vertex_buffer_object handling here */
+
+ for ( i = 0 ; i < primcount ; i++ ) {
+ if ( count[i] > 0 ) {
+ GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
+ CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
+ }
+ }
+}
+
+
+/**
+ * GL_NV_primitive_restart and GL 3.1
+ */
+void GLAPIENTRY
+_mesa_PrimitiveRestartIndex(GLuint index)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (!ctx->Extensions.NV_primitive_restart &&
+ ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
+ return;
+ }
+
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+
+ ctx->Array.RestartIndex = index;
+}
+
+
+/**
+ * See GL_ARB_instanced_arrays.
+ * Note that the instance divisor only applies to generic arrays, not
+ * the legacy vertex arrays.
+ */
+void GLAPIENTRY
+_mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (!ctx->Extensions.ARB_instanced_arrays) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
+ return;
+ }
+
+ if (index >= ctx->Const.VertexProgram.MaxAttribs) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glVertexAttribDivisor(index = %u)",
+ index);
+ return;
+ }
+
+ ctx->Array.ArrayObj->VertexAttrib[index].InstanceDivisor = divisor;
+}
+
+
+
+/**
+ * Copy one client vertex array to another.
+ */
+void
+_mesa_copy_client_array(struct gl_context *ctx,
+ struct gl_client_array *dst,
+ struct gl_client_array *src)
+{
+ dst->Size = src->Size;
+ dst->Type = src->Type;
+ dst->Format = src->Format;
+ dst->Stride = src->Stride;
+ dst->StrideB = src->StrideB;
+ dst->Ptr = src->Ptr;
+ dst->Enabled = src->Enabled;
+ dst->Normalized = src->Normalized;
+ dst->Integer = src->Integer;
+ dst->InstanceDivisor = src->InstanceDivisor;
+ dst->_ElementSize = src->_ElementSize;
+ _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
+ dst->_MaxElement = src->_MaxElement;
+}
+
+
+
+/**
+ * Print vertex array's fields.
+ */
+static void
+print_array(const char *name, GLint index, const struct gl_client_array *array)
+{
+ if (index >= 0)
+ printf(" %s[%d]: ", name, index);
+ else
+ printf(" %s: ", name);
+ printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
+ array->Ptr, array->Type, array->Size,
+ array->_ElementSize, array->StrideB,
+ array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
+ array->_MaxElement);
+}
+
+
+/**
+ * Print current vertex object/array info. For debug.
+ */
+void
+_mesa_print_arrays(struct gl_context *ctx)
+{
+ struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
+ GLuint i;
+
+ _mesa_update_array_object_max_element(ctx, arrayObj);
+
+ printf("Array Object %u\n", arrayObj->Name);
+ if (arrayObj->Vertex.Enabled)
+ print_array("Vertex", -1, &arrayObj->Vertex);
+ if (arrayObj->Normal.Enabled)
+ print_array("Normal", -1, &arrayObj->Normal);
+ if (arrayObj->Color.Enabled)
+ print_array("Color", -1, &arrayObj->Color);
+ for (i = 0; i < Elements(arrayObj->TexCoord); i++)
+ if (arrayObj->TexCoord[i].Enabled)
+ print_array("TexCoord", i, &arrayObj->TexCoord[i]);
+ for (i = 0; i < Elements(arrayObj->VertexAttrib); i++)
+ if (arrayObj->VertexAttrib[i].Enabled)
+ print_array("Attrib", i, &arrayObj->VertexAttrib[i]);
+ printf(" _MaxElement = %u\n", arrayObj->_MaxElement);
+}
+
+
+/**
+ * Initialize vertex array state for given context.
+ */
+void
+_mesa_init_varray(struct gl_context *ctx)
+{
+ ctx->Array.DefaultArrayObj = _mesa_new_array_object(ctx, 0);
+ _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
+ ctx->Array.DefaultArrayObj);
+ ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
+
+ ctx->Array.Objects = _mesa_NewHashTable();
+}
+
+
+/**
+ * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
+ */
+static void
+delete_arrayobj_cb(GLuint id, void *data, void *userData)
+{
+ struct gl_array_object *arrayObj = (struct gl_array_object *) data;
+ struct gl_context *ctx = (struct gl_context *) userData;
+ _mesa_delete_array_object(ctx, arrayObj);
+}
+
+
+/**
+ * Free vertex array state for given context.
+ */
+void
+_mesa_free_varray_data(struct gl_context *ctx)
+{
+ _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
+ _mesa_DeleteHashTable(ctx->Array.Objects);
+}
diff --git a/mesalib/src/mesa/program/register_allocate.c b/mesalib/src/mesa/program/register_allocate.c
index 95a9bde40..e78db24a4 100644
--- a/mesalib/src/mesa/program/register_allocate.c
+++ b/mesalib/src/mesa/program/register_allocate.c
@@ -1,455 +1,517 @@
-/*
- * 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.
- *
- * Authors:
- * Eric Anholt <eric@anholt.net>
- *
- */
-
-/** @file register_allocate.c
- *
- * Graph-coloring register allocator.
- */
-
-#include <ralloc.h>
-
-#include "main/imports.h"
-#include "main/macros.h"
-#include "main/mtypes.h"
-#include "register_allocate.h"
-
-struct ra_reg {
- GLboolean *conflicts;
- unsigned int *conflict_list;
- unsigned int conflict_list_size;
- unsigned int num_conflicts;
-};
-
-struct ra_regs {
- struct ra_reg *regs;
- unsigned int count;
-
- struct ra_class **classes;
- unsigned int class_count;
-};
-
-struct ra_class {
- GLboolean *regs;
-
- /**
- * p_B in Runeson/Nyström paper.
- *
- * This is "how many regs are in the set."
- */
- unsigned int p;
-
- /**
- * q_B,C in Runeson/Nyström paper.
- */
- unsigned int *q;
-};
-
-struct ra_node {
- GLboolean *adjacency;
- unsigned int *adjacency_list;
- unsigned int class;
- unsigned int adjacency_count;
- unsigned int reg;
- GLboolean in_stack;
- float spill_cost;
-};
-
-struct ra_graph {
- struct ra_regs *regs;
- /**
- * the variables that need register allocation.
- */
- struct ra_node *nodes;
- unsigned int count; /**< count of nodes. */
-
- unsigned int *stack;
- unsigned int stack_count;
-};
-
-struct ra_regs *
-ra_alloc_reg_set(unsigned int count)
-{
- unsigned int i;
- struct ra_regs *regs;
-
- regs = rzalloc(NULL, struct ra_regs);
- regs->count = count;
- regs->regs = rzalloc_array(regs, struct ra_reg, count);
-
- for (i = 0; i < count; i++) {
- regs->regs[i].conflicts = rzalloc_array(regs->regs, GLboolean, count);
- regs->regs[i].conflicts[i] = GL_TRUE;
-
- regs->regs[i].conflict_list = ralloc_array(regs->regs, unsigned int, 4);
- regs->regs[i].conflict_list_size = 4;
- regs->regs[i].conflict_list[0] = i;
- regs->regs[i].num_conflicts = 1;
- }
-
- return regs;
-}
-
-static void
-ra_add_conflict_list(struct ra_regs *regs, unsigned int r1, unsigned int r2)
-{
- struct ra_reg *reg1 = &regs->regs[r1];
-
- if (reg1->conflict_list_size == reg1->num_conflicts) {
- reg1->conflict_list_size *= 2;
- reg1->conflict_list = reralloc(regs->regs, reg1->conflict_list,
- unsigned int, reg1->conflict_list_size);
- }
- reg1->conflict_list[reg1->num_conflicts++] = r2;
- reg1->conflicts[r2] = GL_TRUE;
-}
-
-void
-ra_add_reg_conflict(struct ra_regs *regs, unsigned int r1, unsigned int r2)
-{
- if (!regs->regs[r1].conflicts[r2]) {
- ra_add_conflict_list(regs, r1, r2);
- ra_add_conflict_list(regs, r2, r1);
- }
-}
-
-unsigned int
-ra_alloc_reg_class(struct ra_regs *regs)
-{
- struct ra_class *class;
-
- regs->classes = reralloc(regs->regs, regs->classes, struct ra_class *,
- regs->class_count + 1);
-
- class = rzalloc(regs, struct ra_class);
- regs->classes[regs->class_count] = class;
-
- class->regs = rzalloc_array(class, GLboolean, regs->count);
-
- return regs->class_count++;
-}
-
-void
-ra_class_add_reg(struct ra_regs *regs, unsigned int c, unsigned int r)
-{
- struct ra_class *class = regs->classes[c];
-
- class->regs[r] = GL_TRUE;
- class->p++;
-}
-
-/**
- * Must be called after all conflicts and register classes have been
- * set up and before the register set is used for allocation.
- */
-void
-ra_set_finalize(struct ra_regs *regs)
-{
- unsigned int b, c;
-
- for (b = 0; b < regs->class_count; b++) {
- regs->classes[b]->q = ralloc_array(regs, unsigned int, regs->class_count);
- }
-
- /* Compute, for each class B and C, how many regs of B an
- * allocation to C could conflict with.
- */
- for (b = 0; b < regs->class_count; b++) {
- for (c = 0; c < regs->class_count; c++) {
- unsigned int rc;
- int max_conflicts = 0;
-
- for (rc = 0; rc < regs->count; rc++) {
- int conflicts = 0;
- int i;
-
- if (!regs->classes[c]->regs[rc])
- continue;
-
- for (i = 0; i < regs->regs[rc].num_conflicts; i++) {
- unsigned int rb = regs->regs[rc].conflict_list[i];
- if (regs->classes[b]->regs[rb])
- conflicts++;
- }
- max_conflicts = MAX2(max_conflicts, conflicts);
- }
- regs->classes[b]->q[c] = max_conflicts;
- }
- }
-}
-
-static void
-ra_add_node_adjacency(struct ra_graph *g, unsigned int n1, unsigned int n2)
-{
- g->nodes[n1].adjacency[n2] = GL_TRUE;
- g->nodes[n1].adjacency_list[g->nodes[n1].adjacency_count] = n2;
- g->nodes[n1].adjacency_count++;
-}
-
-struct ra_graph *
-ra_alloc_interference_graph(struct ra_regs *regs, unsigned int count)
-{
- struct ra_graph *g;
- unsigned int i;
-
- g = rzalloc(regs, struct ra_graph);
- g->regs = regs;
- g->nodes = rzalloc_array(g, struct ra_node, count);
- g->count = count;
-
- g->stack = rzalloc_array(g, unsigned int, count);
-
- for (i = 0; i < count; i++) {
- g->nodes[i].adjacency = rzalloc_array(g, GLboolean, count);
- g->nodes[i].adjacency_list = ralloc_array(g, unsigned int, count);
- g->nodes[i].adjacency_count = 0;
- ra_add_node_adjacency(g, i, i);
- g->nodes[i].reg = ~0;
- }
-
- return g;
-}
-
-void
-ra_set_node_class(struct ra_graph *g,
- unsigned int n, unsigned int class)
-{
- g->nodes[n].class = class;
-}
-
-void
-ra_add_node_interference(struct ra_graph *g,
- unsigned int n1, unsigned int n2)
-{
- if (!g->nodes[n1].adjacency[n2]) {
- ra_add_node_adjacency(g, n1, n2);
- ra_add_node_adjacency(g, n2, n1);
- }
-}
-
-static GLboolean pq_test(struct ra_graph *g, unsigned int n)
-{
- unsigned int j;
- unsigned int q = 0;
- int n_class = g->nodes[n].class;
-
- for (j = 0; j < g->nodes[n].adjacency_count; j++) {
- unsigned int n2 = g->nodes[n].adjacency_list[j];
- unsigned int n2_class = g->nodes[n2].class;
-
- if (n != n2 && !g->nodes[n2].in_stack) {
- q += g->regs->classes[n_class]->q[n2_class];
- }
- }
-
- return q < g->regs->classes[n_class]->p;
-}
-
-/**
- * Simplifies the interference graph by pushing all
- * trivially-colorable nodes into a stack of nodes to be colored,
- * removing them from the graph, and rinsing and repeating.
- *
- * Returns GL_TRUE if all nodes were removed from the graph. GL_FALSE
- * means that either spilling will be required, or optimistic coloring
- * should be applied.
- */
-GLboolean
-ra_simplify(struct ra_graph *g)
-{
- GLboolean progress = GL_TRUE;
- int i;
-
- while (progress) {
- progress = GL_FALSE;
-
- for (i = g->count - 1; i >= 0; i--) {
- if (g->nodes[i].in_stack)
- continue;
-
- if (pq_test(g, i)) {
- g->stack[g->stack_count] = i;
- g->stack_count++;
- g->nodes[i].in_stack = GL_TRUE;
- progress = GL_TRUE;
- }
- }
- }
-
- for (i = 0; i < g->count; i++) {
- if (!g->nodes[i].in_stack)
- return GL_FALSE;
- }
-
- return GL_TRUE;
-}
-
-/**
- * Pops nodes from the stack back into the graph, coloring them with
- * registers as they go.
- *
- * If all nodes were trivially colorable, then this must succeed. If
- * not (optimistic coloring), then it may return GL_FALSE;
- */
-GLboolean
-ra_select(struct ra_graph *g)
-{
- int i;
-
- while (g->stack_count != 0) {
- unsigned int r;
- int n = g->stack[g->stack_count - 1];
- struct ra_class *c = g->regs->classes[g->nodes[n].class];
-
- /* Find the lowest-numbered reg which is not used by a member
- * of the graph adjacent to us.
- */
- for (r = 0; r < g->regs->count; r++) {
- if (!c->regs[r])
- continue;
-
- /* Check if any of our neighbors conflict with this register choice. */
- for (i = 0; i < g->nodes[n].adjacency_count; i++) {
- unsigned int n2 = g->nodes[n].adjacency_list[i];
-
- if (!g->nodes[n2].in_stack &&
- g->regs->regs[r].conflicts[g->nodes[n2].reg]) {
- break;
- }
- }
- if (i == g->nodes[n].adjacency_count)
- break;
- }
- if (r == g->regs->count)
- return GL_FALSE;
-
- g->nodes[n].reg = r;
- g->nodes[n].in_stack = GL_FALSE;
- g->stack_count--;
- }
-
- return GL_TRUE;
-}
-
-/**
- * Optimistic register coloring: Just push the remaining nodes
- * on the stack. They'll be colored first in ra_select(), and
- * if they succeed then the locally-colorable nodes are still
- * locally-colorable and the rest of the register allocation
- * will succeed.
- */
-void
-ra_optimistic_color(struct ra_graph *g)
-{
- unsigned int i;
-
- for (i = 0; i < g->count; i++) {
- if (g->nodes[i].in_stack)
- continue;
-
- g->stack[g->stack_count] = i;
- g->stack_count++;
- g->nodes[i].in_stack = GL_TRUE;
- }
-}
-
-GLboolean
-ra_allocate_no_spills(struct ra_graph *g)
-{
- if (!ra_simplify(g)) {
- ra_optimistic_color(g);
- }
- return ra_select(g);
-}
-
-unsigned int
-ra_get_node_reg(struct ra_graph *g, unsigned int n)
-{
- return g->nodes[n].reg;
-}
-
-static float
-ra_get_spill_benefit(struct ra_graph *g, unsigned int n)
-{
- int j;
- float benefit = 0;
- int n_class = g->nodes[n].class;
-
- /* Define the benefit of eliminating an interference between n, n2
- * through spilling as q(C, B) / p(C). This is similar to the
- * "count number of edges" approach of traditional graph coloring,
- * but takes classes into account.
- */
- for (j = 0; j < g->nodes[n].adjacency_count; j++) {
- unsigned int n2 = g->nodes[n].adjacency_list[j];
- if (n != n2) {
- unsigned int n2_class = g->nodes[n2].class;
- benefit += ((float)g->regs->classes[n_class]->q[n2_class] /
- g->regs->classes[n_class]->p);
- }
- }
-
- return benefit;
-}
-
-/**
- * Returns a node number to be spilled according to the cost/benefit using
- * the pq test, or -1 if there are no spillable nodes.
- */
-int
-ra_get_best_spill_node(struct ra_graph *g)
-{
- unsigned int best_node = -1;
- unsigned int best_benefit = 0.0;
- unsigned int n;
-
- for (n = 0; n < g->count; n++) {
- float cost = g->nodes[n].spill_cost;
- float benefit;
-
- if (cost <= 0.0)
- continue;
-
- benefit = ra_get_spill_benefit(g, n);
-
- if (benefit / cost > best_benefit) {
- best_benefit = benefit / cost;
- best_node = n;
- }
- }
-
- return best_node;
-}
-
-/**
- * Only nodes with a spill cost set (cost != 0.0) will be considered
- * for register spilling.
- */
-void
-ra_set_node_spill_cost(struct ra_graph *g, unsigned int n, float cost)
-{
- g->nodes[n].spill_cost = cost;
-}
+/*
+ * 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.
+ *
+ * Authors:
+ * Eric Anholt <eric@anholt.net>
+ *
+ */
+
+/** @file register_allocate.c
+ *
+ * Graph-coloring register allocator.
+ *
+ * The basic idea of graph coloring is to make a node in a graph for
+ * every thing that needs a register (color) number assigned, and make
+ * edges in the graph between nodes that interfere (can't be allocated
+ * to the same register at the same time).
+ *
+ * During the "simplify" process, any any node with fewer edges than
+ * there are registers means that that edge can get assigned a
+ * register regardless of what its neighbors choose, so that node is
+ * pushed on a stack and removed (with its edges) from the graph.
+ * That likely causes other nodes to become trivially colorable as well.
+ *
+ * Then during the "select" process, nodes are popped off of that
+ * stack, their edges restored, and assigned a color different from
+ * their neighbors. Because they were pushed on the stack only when
+ * they were trivially colorable, any color chosen won't interfere
+ * with the registers to be popped later.
+ *
+ * The downside to most graph coloring is that real hardware often has
+ * limitations, like registers that need to be allocated to a node in
+ * pairs, or aligned on some boundary. This implementation follows
+ * the paper "Retargetable Graph-Coloring Register Allocation for
+ * Irregular Architectures" by Johan Runeson and Sven-Olof Nyström.
+ *
+ * In this system, there are register classes each containing various
+ * registers, and registers may interfere with other registers. For
+ * example, one might have a class of base registers, and a class of
+ * aligned register pairs that would each interfere with their pair of
+ * the base registers. Each node has a register class it needs to be
+ * assigned to. Define p(B) to be the size of register class B, and
+ * q(B,C) to be the number of registers in B that the worst choice
+ * register in C could conflict with. Then, this system replaces the
+ * basic graph coloring test of "fewer edges from this node than there
+ * are registers" with "For this node of class B, the sum of q(B,C)
+ * for each neighbor node of class C is less than pB".
+ *
+ * A nice feature of the pq test is that q(B,C) can be computed once
+ * up front and stored in a 2-dimensional array, so that the cost of
+ * coloring a node is constant with the number of registers. We do
+ * this during ra_set_finalize().
+ */
+
+#include <ralloc.h>
+
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/mtypes.h"
+#include "register_allocate.h"
+
+struct ra_reg {
+ GLboolean *conflicts;
+ unsigned int *conflict_list;
+ unsigned int conflict_list_size;
+ unsigned int num_conflicts;
+};
+
+struct ra_regs {
+ struct ra_reg *regs;
+ unsigned int count;
+
+ struct ra_class **classes;
+ unsigned int class_count;
+};
+
+struct ra_class {
+ GLboolean *regs;
+
+ /**
+ * p(B) in Runeson/Nyström paper.
+ *
+ * This is "how many regs are in the set."
+ */
+ unsigned int p;
+
+ /**
+ * q(B,C) (indexed by C, B is this register class) in
+ * Runeson/Nyström paper. This is "how many registers of B could
+ * the worst choice register from C conflict with".
+ */
+ unsigned int *q;
+};
+
+struct ra_node {
+ /** @{
+ *
+ * List of which nodes this node interferes with. This should be
+ * symmetric with the other node.
+ */
+ GLboolean *adjacency;
+ unsigned int *adjacency_list;
+ unsigned int adjacency_count;
+ /** @} */
+
+ unsigned int class;
+
+ /* Register, if assigned, or ~0. */
+ unsigned int reg;
+
+ /**
+ * Set when the node is in the trivially colorable stack. When
+ * set, the adjacency to this node is ignored, to implement the
+ * "remove the edge from the graph" in simplification without
+ * having to actually modify the adjacency_list.
+ */
+ GLboolean in_stack;
+
+ /* For an implementation that needs register spilling, this is the
+ * approximate cost of spilling this node.
+ */
+ float spill_cost;
+};
+
+struct ra_graph {
+ struct ra_regs *regs;
+ /**
+ * the variables that need register allocation.
+ */
+ struct ra_node *nodes;
+ unsigned int count; /**< count of nodes. */
+
+ unsigned int *stack;
+ unsigned int stack_count;
+};
+
+struct ra_regs *
+ra_alloc_reg_set(unsigned int count)
+{
+ unsigned int i;
+ struct ra_regs *regs;
+
+ regs = rzalloc(NULL, struct ra_regs);
+ regs->count = count;
+ regs->regs = rzalloc_array(regs, struct ra_reg, count);
+
+ for (i = 0; i < count; i++) {
+ regs->regs[i].conflicts = rzalloc_array(regs->regs, GLboolean, count);
+ regs->regs[i].conflicts[i] = GL_TRUE;
+
+ regs->regs[i].conflict_list = ralloc_array(regs->regs, unsigned int, 4);
+ regs->regs[i].conflict_list_size = 4;
+ regs->regs[i].conflict_list[0] = i;
+ regs->regs[i].num_conflicts = 1;
+ }
+
+ return regs;
+}
+
+static void
+ra_add_conflict_list(struct ra_regs *regs, unsigned int r1, unsigned int r2)
+{
+ struct ra_reg *reg1 = &regs->regs[r1];
+
+ if (reg1->conflict_list_size == reg1->num_conflicts) {
+ reg1->conflict_list_size *= 2;
+ reg1->conflict_list = reralloc(regs->regs, reg1->conflict_list,
+ unsigned int, reg1->conflict_list_size);
+ }
+ reg1->conflict_list[reg1->num_conflicts++] = r2;
+ reg1->conflicts[r2] = GL_TRUE;
+}
+
+void
+ra_add_reg_conflict(struct ra_regs *regs, unsigned int r1, unsigned int r2)
+{
+ if (!regs->regs[r1].conflicts[r2]) {
+ ra_add_conflict_list(regs, r1, r2);
+ ra_add_conflict_list(regs, r2, r1);
+ }
+}
+
+unsigned int
+ra_alloc_reg_class(struct ra_regs *regs)
+{
+ struct ra_class *class;
+
+ regs->classes = reralloc(regs->regs, regs->classes, struct ra_class *,
+ regs->class_count + 1);
+
+ class = rzalloc(regs, struct ra_class);
+ regs->classes[regs->class_count] = class;
+
+ class->regs = rzalloc_array(class, GLboolean, regs->count);
+
+ return regs->class_count++;
+}
+
+void
+ra_class_add_reg(struct ra_regs *regs, unsigned int c, unsigned int r)
+{
+ struct ra_class *class = regs->classes[c];
+
+ class->regs[r] = GL_TRUE;
+ class->p++;
+}
+
+/**
+ * Must be called after all conflicts and register classes have been
+ * set up and before the register set is used for allocation.
+ */
+void
+ra_set_finalize(struct ra_regs *regs)
+{
+ unsigned int b, c;
+
+ for (b = 0; b < regs->class_count; b++) {
+ regs->classes[b]->q = ralloc_array(regs, unsigned int, regs->class_count);
+ }
+
+ /* Compute, for each class B and C, how many regs of B an
+ * allocation to C could conflict with.
+ */
+ for (b = 0; b < regs->class_count; b++) {
+ for (c = 0; c < regs->class_count; c++) {
+ unsigned int rc;
+ int max_conflicts = 0;
+
+ for (rc = 0; rc < regs->count; rc++) {
+ int conflicts = 0;
+ int i;
+
+ if (!regs->classes[c]->regs[rc])
+ continue;
+
+ for (i = 0; i < regs->regs[rc].num_conflicts; i++) {
+ unsigned int rb = regs->regs[rc].conflict_list[i];
+ if (regs->classes[b]->regs[rb])
+ conflicts++;
+ }
+ max_conflicts = MAX2(max_conflicts, conflicts);
+ }
+ regs->classes[b]->q[c] = max_conflicts;
+ }
+ }
+}
+
+static void
+ra_add_node_adjacency(struct ra_graph *g, unsigned int n1, unsigned int n2)
+{
+ g->nodes[n1].adjacency[n2] = GL_TRUE;
+ g->nodes[n1].adjacency_list[g->nodes[n1].adjacency_count] = n2;
+ g->nodes[n1].adjacency_count++;
+}
+
+struct ra_graph *
+ra_alloc_interference_graph(struct ra_regs *regs, unsigned int count)
+{
+ struct ra_graph *g;
+ unsigned int i;
+
+ g = rzalloc(regs, struct ra_graph);
+ g->regs = regs;
+ g->nodes = rzalloc_array(g, struct ra_node, count);
+ g->count = count;
+
+ g->stack = rzalloc_array(g, unsigned int, count);
+
+ for (i = 0; i < count; i++) {
+ g->nodes[i].adjacency = rzalloc_array(g, GLboolean, count);
+ g->nodes[i].adjacency_list = ralloc_array(g, unsigned int, count);
+ g->nodes[i].adjacency_count = 0;
+ ra_add_node_adjacency(g, i, i);
+ g->nodes[i].reg = ~0;
+ }
+
+ return g;
+}
+
+void
+ra_set_node_class(struct ra_graph *g,
+ unsigned int n, unsigned int class)
+{
+ g->nodes[n].class = class;
+}
+
+void
+ra_add_node_interference(struct ra_graph *g,
+ unsigned int n1, unsigned int n2)
+{
+ if (!g->nodes[n1].adjacency[n2]) {
+ ra_add_node_adjacency(g, n1, n2);
+ ra_add_node_adjacency(g, n2, n1);
+ }
+}
+
+static GLboolean pq_test(struct ra_graph *g, unsigned int n)
+{
+ unsigned int j;
+ unsigned int q = 0;
+ int n_class = g->nodes[n].class;
+
+ for (j = 0; j < g->nodes[n].adjacency_count; j++) {
+ unsigned int n2 = g->nodes[n].adjacency_list[j];
+ unsigned int n2_class = g->nodes[n2].class;
+
+ if (n != n2 && !g->nodes[n2].in_stack) {
+ q += g->regs->classes[n_class]->q[n2_class];
+ }
+ }
+
+ return q < g->regs->classes[n_class]->p;
+}
+
+/**
+ * Simplifies the interference graph by pushing all
+ * trivially-colorable nodes into a stack of nodes to be colored,
+ * removing them from the graph, and rinsing and repeating.
+ *
+ * Returns GL_TRUE if all nodes were removed from the graph. GL_FALSE
+ * means that either spilling will be required, or optimistic coloring
+ * should be applied.
+ */
+GLboolean
+ra_simplify(struct ra_graph *g)
+{
+ GLboolean progress = GL_TRUE;
+ int i;
+
+ while (progress) {
+ progress = GL_FALSE;
+
+ for (i = g->count - 1; i >= 0; i--) {
+ if (g->nodes[i].in_stack)
+ continue;
+
+ if (pq_test(g, i)) {
+ g->stack[g->stack_count] = i;
+ g->stack_count++;
+ g->nodes[i].in_stack = GL_TRUE;
+ progress = GL_TRUE;
+ }
+ }
+ }
+
+ for (i = 0; i < g->count; i++) {
+ if (!g->nodes[i].in_stack)
+ return GL_FALSE;
+ }
+
+ return GL_TRUE;
+}
+
+/**
+ * Pops nodes from the stack back into the graph, coloring them with
+ * registers as they go.
+ *
+ * If all nodes were trivially colorable, then this must succeed. If
+ * not (optimistic coloring), then it may return GL_FALSE;
+ */
+GLboolean
+ra_select(struct ra_graph *g)
+{
+ int i;
+
+ while (g->stack_count != 0) {
+ unsigned int r;
+ int n = g->stack[g->stack_count - 1];
+ struct ra_class *c = g->regs->classes[g->nodes[n].class];
+
+ /* Find the lowest-numbered reg which is not used by a member
+ * of the graph adjacent to us.
+ */
+ for (r = 0; r < g->regs->count; r++) {
+ if (!c->regs[r])
+ continue;
+
+ /* Check if any of our neighbors conflict with this register choice. */
+ for (i = 0; i < g->nodes[n].adjacency_count; i++) {
+ unsigned int n2 = g->nodes[n].adjacency_list[i];
+
+ if (!g->nodes[n2].in_stack &&
+ g->regs->regs[r].conflicts[g->nodes[n2].reg]) {
+ break;
+ }
+ }
+ if (i == g->nodes[n].adjacency_count)
+ break;
+ }
+ if (r == g->regs->count)
+ return GL_FALSE;
+
+ g->nodes[n].reg = r;
+ g->nodes[n].in_stack = GL_FALSE;
+ g->stack_count--;
+ }
+
+ return GL_TRUE;
+}
+
+/**
+ * Optimistic register coloring: Just push the remaining nodes
+ * on the stack. They'll be colored first in ra_select(), and
+ * if they succeed then the locally-colorable nodes are still
+ * locally-colorable and the rest of the register allocation
+ * will succeed.
+ */
+void
+ra_optimistic_color(struct ra_graph *g)
+{
+ unsigned int i;
+
+ for (i = 0; i < g->count; i++) {
+ if (g->nodes[i].in_stack)
+ continue;
+
+ g->stack[g->stack_count] = i;
+ g->stack_count++;
+ g->nodes[i].in_stack = GL_TRUE;
+ }
+}
+
+GLboolean
+ra_allocate_no_spills(struct ra_graph *g)
+{
+ if (!ra_simplify(g)) {
+ ra_optimistic_color(g);
+ }
+ return ra_select(g);
+}
+
+unsigned int
+ra_get_node_reg(struct ra_graph *g, unsigned int n)
+{
+ return g->nodes[n].reg;
+}
+
+static float
+ra_get_spill_benefit(struct ra_graph *g, unsigned int n)
+{
+ int j;
+ float benefit = 0;
+ int n_class = g->nodes[n].class;
+
+ /* Define the benefit of eliminating an interference between n, n2
+ * through spilling as q(C, B) / p(C). This is similar to the
+ * "count number of edges" approach of traditional graph coloring,
+ * but takes classes into account.
+ */
+ for (j = 0; j < g->nodes[n].adjacency_count; j++) {
+ unsigned int n2 = g->nodes[n].adjacency_list[j];
+ if (n != n2) {
+ unsigned int n2_class = g->nodes[n2].class;
+ benefit += ((float)g->regs->classes[n_class]->q[n2_class] /
+ g->regs->classes[n_class]->p);
+ }
+ }
+
+ return benefit;
+}
+
+/**
+ * Returns a node number to be spilled according to the cost/benefit using
+ * the pq test, or -1 if there are no spillable nodes.
+ */
+int
+ra_get_best_spill_node(struct ra_graph *g)
+{
+ unsigned int best_node = -1;
+ unsigned int best_benefit = 0.0;
+ unsigned int n;
+
+ for (n = 0; n < g->count; n++) {
+ float cost = g->nodes[n].spill_cost;
+ float benefit;
+
+ if (cost <= 0.0)
+ continue;
+
+ benefit = ra_get_spill_benefit(g, n);
+
+ if (benefit / cost > best_benefit) {
+ best_benefit = benefit / cost;
+ best_node = n;
+ }
+ }
+
+ return best_node;
+}
+
+/**
+ * Only nodes with a spill cost set (cost != 0.0) will be considered
+ * for register spilling.
+ */
+void
+ra_set_node_spill_cost(struct ra_graph *g, unsigned int n, float cost)
+{
+ g->nodes[n].spill_cost = cost;
+}
diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
index 1707f827c..9cc40c3d9 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -1,1535 +1,1543 @@
-/**************************************************************************
- *
- * 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 |= BITFIELD64_BIT(FRAG_RESULT_DEPTH);
- if (write_stencil)
- p->OutputsWritten |= BITFIELD64_BIT(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(struct gl_context *ctx, 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 {
- switch (type) {
- case GL_UNSIGNED_BYTE:
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- default:
- return GL_RGBA8;
-
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- return GL_RGBA4;
-
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- return GL_RGB5_A1;
-
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- return GL_RGB10_A2;
-
- case GL_UNSIGNED_SHORT:
- case GL_UNSIGNED_INT:
- return GL_RGBA16;
-
- case GL_BYTE:
- return
- ctx->Extensions.EXT_texture_snorm ? GL_RGBA8_SNORM : GL_RGBA8;
-
- case GL_SHORT:
- case GL_INT:
- return
- ctx->Extensions.EXT_texture_snorm ? GL_RGBA16_SNORM : GL_RGBA16;
-
- case GL_HALF_FLOAT_ARB:
- return
- ctx->Extensions.ARB_texture_float ? GL_RGBA16F :
- ctx->Extensions.EXT_texture_snorm ? GL_RGBA16_SNORM : GL_RGBA16;
-
- case GL_FLOAT:
- case GL_DOUBLE:
- return
- ctx->Extensions.ARB_texture_float ? GL_RGBA32F :
- ctx->Extensions.EXT_texture_snorm ? GL_RGBA16_SNORM : GL_RGBA16;
- }
- }
- }
-}
-
-
-/**
- * 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(ctx, 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.clamp_fragment_color = ctx->Color._ClampFragmentColor;
- 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)) {
- 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 |= BITFIELD64_BIT(FRAG_RESULT_DEPTH);
+ if (write_stencil)
+ p->OutputsWritten |= BITFIELD64_BIT(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(struct gl_context *ctx, 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 {
+ switch (type) {
+ case GL_UNSIGNED_BYTE:
+ case GL_UNSIGNED_INT_8_8_8_8:
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ default:
+ return GL_RGBA8;
+
+ case GL_UNSIGNED_BYTE_3_3_2:
+ case GL_UNSIGNED_BYTE_2_3_3_REV:
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ return GL_RGBA4;
+
+ case GL_UNSIGNED_SHORT_5_6_5:
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ return GL_RGB5_A1;
+
+ case GL_UNSIGNED_INT_10_10_10_2:
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ return GL_RGB10_A2;
+
+ case GL_UNSIGNED_SHORT:
+ case GL_UNSIGNED_INT:
+ return GL_RGBA16;
+
+ case GL_BYTE:
+ return
+ ctx->Extensions.EXT_texture_snorm ? GL_RGBA8_SNORM : GL_RGBA8;
+
+ case GL_SHORT:
+ case GL_INT:
+ return
+ ctx->Extensions.EXT_texture_snorm ? GL_RGBA16_SNORM : GL_RGBA16;
+
+ case GL_HALF_FLOAT_ARB:
+ return
+ ctx->Extensions.ARB_texture_float ? GL_RGBA16F :
+ ctx->Extensions.EXT_texture_snorm ? GL_RGBA16_SNORM : GL_RGBA16;
+
+ case GL_FLOAT:
+ case GL_DOUBLE:
+ return
+ ctx->Extensions.ARB_texture_float ? GL_RGBA32F :
+ ctx->Extensions.EXT_texture_snorm ? GL_RGBA16_SNORM : GL_RGBA16;
+
+ case GL_UNSIGNED_INT_5_9_9_9_REV:
+ assert(ctx->Extensions.EXT_texture_shared_exponent);
+ return GL_RGB9_E5;
+
+ case GL_UNSIGNED_INT_10F_11F_11F_REV:
+ assert(ctx->Extensions.EXT_packed_float);
+ return GL_R11F_G11F_B10F;
+ }
+ }
+ }
+}
+
+
+/**
+ * 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(ctx, 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.clamp_fragment_color = ctx->Color._ClampFragmentColor;
+ 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)) {
+ 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_extensions.c b/mesalib/src/mesa/state_tracker/st_extensions.c
index 339e00d30..0c5e1991c 100644
--- a/mesalib/src/mesa/state_tracker/st_extensions.c
+++ b/mesalib/src/mesa/state_tracker/st_extensions.c
@@ -1,579 +1,598 @@
-/**************************************************************************
- *
- * 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);
- /* raise MaxParameters if native support is higher */
- pc->MaxParameters = MAX2(pc->MaxParameters, pc->MaxNativeParameters);
-
- 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_sampler_objects = 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) &&
- screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW)) {
- 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) &&
- screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW)) {
- ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
- }
-
- /* float support - assume nothing exclusively supports 64-bit floats */
- if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FLOAT,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW |
- PIPE_BIND_RENDER_TARGET) &&
- screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW |
- PIPE_BIND_RENDER_TARGET)) {
- ctx->Extensions.ARB_texture_float = GL_TRUE;
- }
-
- /* sRGB support */
- if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW) ||
- screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW)) {
- 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) ||
- screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET)) {
- 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)) {
- 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) &&
- 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) &&
- screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_SNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW) &&
- screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW) &&
- screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_SNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW)
- ) {
- ctx->Extensions.ARB_texture_compression_rgtc = GL_TRUE;
- }
-
- if (screen->is_format_supported(screen, PIPE_FORMAT_LATC1_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW) &&
- screen->is_format_supported(screen, PIPE_FORMAT_LATC1_SNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW) &&
- screen->is_format_supported(screen, PIPE_FORMAT_LATC2_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW) &&
- screen->is_format_supported(screen, PIPE_FORMAT_LATC2_SNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW)) {
- ctx->Extensions.EXT_texture_compression_latc = GL_TRUE;
- }
-
- if (screen->is_format_supported(screen, PIPE_FORMAT_LATC2_UNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW)) {
- ctx->Extensions.ATI_texture_compression_3dc = GL_TRUE;
- }
-
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW)) {
- ctx->Extensions.EXT_texture_snorm = GL_TRUE;
- }
-
- /* ycbcr support */
- if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW) ||
- screen->is_format_supported(screen, PIPE_FORMAT_YUYV,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_SAMPLER_VIEW)) {
- 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)) {
- 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;
- }
-
- /* This extension does not actually require support of floating point
- * render targets, just clamping controls.
- * Advertise this extension if either fragment color clamping is supported
- * or no render targets having color values outside of the range [0, 1]
- * are supported, in which case the fragment color clamping has no effect
- * on rendering.
- */
- if (screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL) ||
- (!screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET) &&
- !screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET) &&
- !screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET) &&
- !screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FLOAT,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET) &&
- !screen->is_format_supported(screen, PIPE_FORMAT_R11G11B10_FLOAT,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET) &&
- !screen->is_format_supported(screen, PIPE_FORMAT_R9G9B9E5_FLOAT,
- PIPE_TEXTURE_2D, 0,
- PIPE_BIND_RENDER_TARGET))) {
- ctx->Extensions.ARB_color_buffer_float = 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_TGSI_INSTANCEID)) {
- ctx->Extensions.ARB_draw_instanced = GL_TRUE;
- }
- if (screen->get_param(screen, PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR)) {
- ctx->Extensions.ARB_instanced_arrays = GL_TRUE;
- }
-
- if (screen->fence_finish) {
- ctx->Extensions.ARB_sync = GL_TRUE;
- }
-
- if (st->pipe->texture_barrier) {
- ctx->Extensions.NV_texture_barrier = 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);
+ /* raise MaxParameters if native support is higher */
+ pc->MaxParameters = MAX2(pc->MaxParameters, pc->MaxNativeParameters);
+
+ 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_sampler_objects = 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) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW)) {
+ 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) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW)) {
+ ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
+ }
+
+ /* float support - assume nothing exclusively supports 64-bit floats */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW |
+ PIPE_BIND_RENDER_TARGET) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW |
+ PIPE_BIND_RENDER_TARGET)) {
+ ctx->Extensions.ARB_texture_float = GL_TRUE;
+ }
+
+ /* sRGB support */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW) ||
+ screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW)) {
+ 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) ||
+ screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET)) {
+ 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)) {
+ 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) &&
+ 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) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_SNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_SNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW)
+ ) {
+ ctx->Extensions.ARB_texture_compression_rgtc = GL_TRUE;
+ }
+
+ if (screen->is_format_supported(screen, PIPE_FORMAT_LATC1_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_LATC1_SNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_LATC2_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW) &&
+ screen->is_format_supported(screen, PIPE_FORMAT_LATC2_SNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW)) {
+ ctx->Extensions.EXT_texture_compression_latc = GL_TRUE;
+ }
+
+ if (screen->is_format_supported(screen, PIPE_FORMAT_LATC2_UNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW)) {
+ ctx->Extensions.ATI_texture_compression_3dc = GL_TRUE;
+ }
+
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW)) {
+ ctx->Extensions.EXT_texture_snorm = GL_TRUE;
+ }
+
+ /* ycbcr support */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW) ||
+ screen->is_format_supported(screen, PIPE_FORMAT_YUYV,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW)) {
+ 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)) {
+ ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
+ }
+
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FIXED,
+ PIPE_BUFFER, 0,
+ PIPE_BIND_VERTEX_BUFFER)) {
+ ctx->Extensions.ARB_ES2_compatibility = 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;
+ }
+
+ /* This extension does not actually require support of floating point
+ * render targets, just clamping controls.
+ * Advertise this extension if either fragment color clamping is supported
+ * or no render targets having color values outside of the range [0, 1]
+ * are supported, in which case the fragment color clamping has no effect
+ * on rendering.
+ */
+ if (screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL) ||
+ (!screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET) &&
+ !screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET) &&
+ !screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET) &&
+ !screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET) &&
+ !screen->is_format_supported(screen, PIPE_FORMAT_R11G11B10_FLOAT,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET) &&
+ !screen->is_format_supported(screen, PIPE_FORMAT_R9G9B9E5_FLOAT,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET))) {
+ ctx->Extensions.ARB_color_buffer_float = 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_TGSI_INSTANCEID)) {
+ ctx->Extensions.ARB_draw_instanced = GL_TRUE;
+ }
+ if (screen->get_param(screen, PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR)) {
+ ctx->Extensions.ARB_instanced_arrays = GL_TRUE;
+ }
+
+ if (screen->fence_finish) {
+ ctx->Extensions.ARB_sync = GL_TRUE;
+ }
+
+ if (st->pipe->texture_barrier) {
+ ctx->Extensions.NV_texture_barrier = GL_TRUE;
+ }
+
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R9G9B9E5_FLOAT,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_SAMPLER_VIEW)) {
+ ctx->Extensions.EXT_texture_shared_exponent = GL_TRUE;
+ }
+
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R11G11B10_FLOAT,
+ PIPE_TEXTURE_2D, 0,
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_SAMPLER_VIEW)) {
+ ctx->Extensions.EXT_packed_float = GL_TRUE;
+ }
+}
diff --git a/mesalib/src/mesa/state_tracker/st_format.c b/mesalib/src/mesa/state_tracker/st_format.c
index 4e7bef2d2..8568c68e1 100644
--- a/mesalib/src/mesa/state_tracker/st_format.c
+++ b/mesalib/src/mesa/state_tracker/st_format.c
@@ -1,1668 +1,1692 @@
-/**************************************************************************
- *
- * 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_RGBA_FLOAT32:
- return PIPE_FORMAT_R32G32B32A32_FLOAT;
- case MESA_FORMAT_RGBA_FLOAT16:
- return PIPE_FORMAT_R16G16B16A16_FLOAT;
- case MESA_FORMAT_RGB_FLOAT32:
- return PIPE_FORMAT_R32G32B32_FLOAT;
- case MESA_FORMAT_RGB_FLOAT16:
- return PIPE_FORMAT_R16G16B16_FLOAT;
- case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
- return PIPE_FORMAT_L32A32_FLOAT;
- case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
- return PIPE_FORMAT_L16A16_FLOAT;
- case MESA_FORMAT_LUMINANCE_FLOAT32:
- return PIPE_FORMAT_L32_FLOAT;
- case MESA_FORMAT_LUMINANCE_FLOAT16:
- return PIPE_FORMAT_L16_FLOAT;
- case MESA_FORMAT_ALPHA_FLOAT32:
- return PIPE_FORMAT_A32_FLOAT;
- case MESA_FORMAT_ALPHA_FLOAT16:
- return PIPE_FORMAT_A16_FLOAT;
- case MESA_FORMAT_INTENSITY_FLOAT32:
- return PIPE_FORMAT_I32_FLOAT;
- case MESA_FORMAT_INTENSITY_FLOAT16:
- return PIPE_FORMAT_I16_FLOAT;
- case MESA_FORMAT_R_FLOAT32:
- return PIPE_FORMAT_R32_FLOAT;
- case MESA_FORMAT_R_FLOAT16:
- return PIPE_FORMAT_R16_FLOAT;
- case MESA_FORMAT_RG_FLOAT32:
- return PIPE_FORMAT_R32G32_FLOAT;
- case MESA_FORMAT_RG_FLOAT16:
- return PIPE_FORMAT_R16G16_FLOAT;
-
- 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;
-
- case MESA_FORMAT_L_LATC1:
- return PIPE_FORMAT_LATC1_UNORM;
- case MESA_FORMAT_SIGNED_L_LATC1:
- return PIPE_FORMAT_LATC1_SNORM;
- case MESA_FORMAT_LA_LATC2:
- return PIPE_FORMAT_LATC2_UNORM;
- case MESA_FORMAT_SIGNED_LA_LATC2:
- return PIPE_FORMAT_LATC2_SNORM;
-
- /* signed normalized formats */
- case MESA_FORMAT_SIGNED_R8:
- return PIPE_FORMAT_R8_SNORM;
- case MESA_FORMAT_SIGNED_RG88_REV:
- return PIPE_FORMAT_R8G8_SNORM;
- case MESA_FORMAT_SIGNED_RGBA8888_REV:
- return PIPE_FORMAT_R8G8B8A8_SNORM;
-
- case MESA_FORMAT_SIGNED_A8:
- return PIPE_FORMAT_A8_SNORM;
- case MESA_FORMAT_SIGNED_L8:
- return PIPE_FORMAT_L8_SNORM;
- case MESA_FORMAT_SIGNED_AL88:
- return PIPE_FORMAT_L8A8_SNORM;
- case MESA_FORMAT_SIGNED_I8:
- return PIPE_FORMAT_I8_SNORM;
-
- case MESA_FORMAT_SIGNED_R16:
- return PIPE_FORMAT_R16_SNORM;
- case MESA_FORMAT_SIGNED_GR1616:
- return PIPE_FORMAT_R16G16_SNORM;
- case MESA_FORMAT_SIGNED_RGBA_16:
- return PIPE_FORMAT_R16G16B16A16_SNORM;
-
- case MESA_FORMAT_SIGNED_A16:
- return PIPE_FORMAT_A16_SNORM;
- case MESA_FORMAT_SIGNED_L16:
- return PIPE_FORMAT_L16_SNORM;
- case MESA_FORMAT_SIGNED_AL1616:
- return PIPE_FORMAT_L16A16_SNORM;
- case MESA_FORMAT_SIGNED_I16:
- return PIPE_FORMAT_I16_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_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_R32G32B32A32_FLOAT:
- return MESA_FORMAT_RGBA_FLOAT32;
- case PIPE_FORMAT_R16G16B16A16_FLOAT:
- return MESA_FORMAT_RGBA_FLOAT16;
- case PIPE_FORMAT_R32G32B32_FLOAT:
- return MESA_FORMAT_RGB_FLOAT32;
- case PIPE_FORMAT_R16G16B16_FLOAT:
- return MESA_FORMAT_RGB_FLOAT16;
- case PIPE_FORMAT_L32A32_FLOAT:
- return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32;
- case PIPE_FORMAT_L16A16_FLOAT:
- return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16;
- case PIPE_FORMAT_L32_FLOAT:
- return MESA_FORMAT_LUMINANCE_FLOAT32;
- case PIPE_FORMAT_L16_FLOAT:
- return MESA_FORMAT_LUMINANCE_FLOAT16;
- case PIPE_FORMAT_A32_FLOAT:
- return MESA_FORMAT_ALPHA_FLOAT32;
- case PIPE_FORMAT_A16_FLOAT:
- return MESA_FORMAT_ALPHA_FLOAT16;
- case PIPE_FORMAT_I32_FLOAT:
- return MESA_FORMAT_INTENSITY_FLOAT32;
- case PIPE_FORMAT_I16_FLOAT:
- return MESA_FORMAT_INTENSITY_FLOAT16;
- case PIPE_FORMAT_R32_FLOAT:
- return MESA_FORMAT_R_FLOAT32;
- case PIPE_FORMAT_R16_FLOAT:
- return MESA_FORMAT_R_FLOAT16;
- case PIPE_FORMAT_R32G32_FLOAT:
- return MESA_FORMAT_RG_FLOAT32;
- case PIPE_FORMAT_R16G16_FLOAT:
- return MESA_FORMAT_RG_FLOAT16;
-
- 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;
-
- case PIPE_FORMAT_LATC1_UNORM:
- return MESA_FORMAT_L_LATC1;
- case PIPE_FORMAT_LATC1_SNORM:
- return MESA_FORMAT_SIGNED_L_LATC1;
- case PIPE_FORMAT_LATC2_UNORM:
- return MESA_FORMAT_LA_LATC2;
- case PIPE_FORMAT_LATC2_SNORM:
- return MESA_FORMAT_SIGNED_LA_LATC2;
-
- /* signed normalized formats */
- case PIPE_FORMAT_R8_SNORM:
- return MESA_FORMAT_SIGNED_R8;
- case PIPE_FORMAT_R8G8_SNORM:
- return MESA_FORMAT_SIGNED_RG88_REV;
- case PIPE_FORMAT_R8G8B8A8_SNORM:
- return MESA_FORMAT_SIGNED_RGBA8888_REV;
-
- case PIPE_FORMAT_A8_SNORM:
- return MESA_FORMAT_SIGNED_A8;
- case PIPE_FORMAT_L8_SNORM:
- return MESA_FORMAT_SIGNED_L8;
- case PIPE_FORMAT_L8A8_SNORM:
- return MESA_FORMAT_SIGNED_AL88;
- case PIPE_FORMAT_I8_SNORM:
- return MESA_FORMAT_SIGNED_I8;
-
- case PIPE_FORMAT_R16_SNORM:
- return MESA_FORMAT_SIGNED_R16;
- case PIPE_FORMAT_R16G16_SNORM:
- return MESA_FORMAT_SIGNED_GR1616;
- case PIPE_FORMAT_R16G16B16A16_SNORM:
- return MESA_FORMAT_SIGNED_RGBA_16;
-
- case PIPE_FORMAT_A16_SNORM:
- return MESA_FORMAT_SIGNED_A16;
- case PIPE_FORMAT_L16_SNORM:
- return MESA_FORMAT_SIGNED_L16;
- case PIPE_FORMAT_L16A16_SNORM:
- return MESA_FORMAT_SIGNED_AL1616;
- case PIPE_FORMAT_I16_SNORM:
- return MESA_FORMAT_SIGNED_I16;
-
- 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)
-{
- uint i;
- for (i = 0; i < num_formats; i++) {
- if (screen->is_format_supported(screen, formats[i], target,
- sample_count, tex_usage)) {
- 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)
-{
- 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);
-}
-
-
-/**
- * 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)
-{
- 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);
-}
-
-/**
- * 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)
-{
- 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);
-}
-
-
-/**
- * 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)
-{
-
- switch (internalFormat) {
- case GL_RGB10:
- case GL_RGB10_A2:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B10G10R10A2_UNORM,
- target, sample_count, bindings))
- return PIPE_FORMAT_B10G10R10A2_UNORM;
- /* Pass through. */
- case 4:
- case GL_RGBA:
- case GL_RGBA8:
- return default_rgba_format( screen, target, sample_count, bindings);
-
- case GL_BGRA:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B8G8R8A8_UNORM,
- target, sample_count, bindings))
- return PIPE_FORMAT_B8G8R8A8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings);
-
- case 3:
- case GL_RGB:
- case GL_RGB8:
- return default_rgb_format( screen, target, sample_count, bindings);
-
- 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))
- return PIPE_FORMAT_R16G16B16A16_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings);
-
- case GL_RGBA4:
- case GL_RGBA2:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B4G4R4A4_UNORM,
- target, sample_count, bindings))
- return PIPE_FORMAT_B4G4R4A4_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings);
-
- case GL_RGB5_A1:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM,
- target, sample_count, bindings))
- return PIPE_FORMAT_B5G5R5A1_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings);
-
- case GL_R3_G3_B2:
- if (screen->is_format_supported( screen, PIPE_FORMAT_B2G3R3_UNORM,
- target, sample_count, bindings))
- 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))
- return PIPE_FORMAT_B5G6R5_UNORM;
- if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM,
- target, sample_count, bindings))
- return PIPE_FORMAT_B5G5R5A1_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings);
-
- case GL_ALPHA12:
- case GL_ALPHA16:
- if (screen->is_format_supported( screen, PIPE_FORMAT_A16_UNORM, target,
- sample_count, bindings))
- 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))
- return PIPE_FORMAT_A8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings);
-
- case GL_LUMINANCE12:
- case GL_LUMINANCE16:
- if (screen->is_format_supported( screen, PIPE_FORMAT_L16_UNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_L16_UNORM;
- /* Pass through. */
- case 1:
- case GL_LUMINANCE:
- case GL_LUMINANCE4:
- case GL_LUMINANCE8:
- if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_L8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings);
-
- 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))
- return PIPE_FORMAT_L16A16_UNORM;
- /* Pass through. */
- case 2:
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE6_ALPHA2:
- case GL_LUMINANCE8_ALPHA8:
- if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_UNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_L8A8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings);
-
- case GL_LUMINANCE4_ALPHA4:
- if (screen->is_format_supported( screen, PIPE_FORMAT_L4A4_UNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_L4A4_UNORM;
- if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_UNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_L8A8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings);
-
- case GL_INTENSITY12:
- case GL_INTENSITY16:
- if (screen->is_format_supported( screen, PIPE_FORMAT_I16_UNORM, target,
- sample_count, bindings))
- 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))
- return PIPE_FORMAT_I8_UNORM;
- return default_rgba_format( screen, target, sample_count, bindings);
-
- case GL_YCBCR_MESA:
- if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY, target,
- sample_count, bindings)) {
- return PIPE_FORMAT_UYVY;
- }
- if (screen->is_format_supported(screen, PIPE_FORMAT_YUYV, target,
- sample_count, bindings)) {
- 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))
- return PIPE_FORMAT_DXT1_RGB;
- else
- return default_rgb_format(screen, target, sample_count, bindings);
-
- 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))
- return PIPE_FORMAT_DXT3_RGBA;
- else
- return default_rgba_format(screen, target, sample_count, bindings);
-
- 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))
- 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))
- 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))
- 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))
- 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))
- 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))
- return PIPE_FORMAT_Z24_UNORM_S8_USCALED;
- if (screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
- target, sample_count, bindings))
- 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))
- 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);
- }
-
- 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);
- }
-
- 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);
- }
-
- 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);
-
- 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))
- return PIPE_FORMAT_DXT1_SRGB;
- return default_srgba_format( screen, target, sample_count, bindings);
-
- 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))
- return PIPE_FORMAT_DXT3_SRGBA;
- return default_srgba_format( screen, target, sample_count, bindings);
-
- 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))
- return PIPE_FORMAT_L8A8_SRGB;
- return default_srgba_format( screen, target, sample_count, bindings);
-
- case GL_SLUMINANCE_EXT:
- case GL_SLUMINANCE8_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_L8_SRGB, target,
- sample_count, bindings))
- return PIPE_FORMAT_L8_SRGB;
- return default_srgba_format( screen, target, sample_count, bindings);
-
- /* prefer formats in order of data size, choosing 16-bit ones if equal sized */
- case GL_RGBA16F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_RGB16F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R16G16B16_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_FORMAT_R32G32B32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_LUMINANCE_ALPHA16F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_L16A16_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_FORMAT_L32A32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_ALPHA16F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_A16_FLOAT,
- PIPE_FORMAT_L16A16_FLOAT,
- PIPE_FORMAT_A32_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_FORMAT_L32A32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_INTENSITY16F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_I16_FLOAT,
- PIPE_FORMAT_L16A16_FLOAT,
- PIPE_FORMAT_I32_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_FORMAT_L32A32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_LUMINANCE16F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_L16_FLOAT,
- PIPE_FORMAT_L16A16_FLOAT,
- PIPE_FORMAT_L32_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_FORMAT_L32A32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_R16F:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R16_FLOAT,
- PIPE_FORMAT_R16G16_FLOAT,
- PIPE_FORMAT_R32_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_FORMAT_R32G32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_RG16F:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R16G16_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT,
- PIPE_FORMAT_R32G32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- /* try a 32-bit format if available, otherwise fallback to a 16-bit one */
- case GL_RGBA32F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R32G32B32A32_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_RGB32F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R32G32B32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_LUMINANCE_ALPHA32F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_L32A32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT,
- PIPE_FORMAT_L16A16_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_ALPHA32F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_A32_FLOAT,
- PIPE_FORMAT_L32A32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT,
- PIPE_FORMAT_A16_FLOAT,
- PIPE_FORMAT_L16A16_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_INTENSITY32F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_I32_FLOAT,
- PIPE_FORMAT_L32A32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT,
- PIPE_FORMAT_I16_FLOAT,
- PIPE_FORMAT_L16A16_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_LUMINANCE32F_ARB:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_L32_FLOAT,
- PIPE_FORMAT_L32A32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT,
- PIPE_FORMAT_L16_FLOAT,
- PIPE_FORMAT_L16A16_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_R32F:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R32_FLOAT,
- PIPE_FORMAT_R32G32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT,
- PIPE_FORMAT_R16_FLOAT,
- PIPE_FORMAT_R16G16_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
- case GL_RG32F:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R32G32_FLOAT,
- PIPE_FORMAT_R32G32B32A32_FLOAT,
- PIPE_FORMAT_R16G16_FLOAT,
- PIPE_FORMAT_R16G16B16A16_FLOAT
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_RED:
- case GL_R8:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM, target,
- sample_count, bindings))
- 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))
- 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))
- 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))
- 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))
- return PIPE_FORMAT_RGTC1_UNORM;
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM, target,
- sample_count, bindings))
- 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))
- 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))
- return PIPE_FORMAT_RGTC2_UNORM;
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM, target,
- sample_count, bindings))
- 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))
- return PIPE_FORMAT_RGTC2_SNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_LUMINANCE:
- case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_LATC1_UNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_LATC1_UNORM;
- if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_L8_UNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_LATC1_SNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_LATC1_SNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_LUMINANCE_ALPHA:
- case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
- case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
- if (screen->is_format_supported(screen, PIPE_FORMAT_LATC2_UNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_LATC2_UNORM;
- if (screen->is_format_supported(screen, PIPE_FORMAT_L8A8_UNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_L8A8_UNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
- if (screen->is_format_supported(screen, PIPE_FORMAT_LATC2_SNORM, target,
- sample_count, bindings))
- return PIPE_FORMAT_LATC2_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))
- 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))
- 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))
- 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))
- 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))
- 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))
- return PIPE_FORMAT_R32G32B32A32_USCALED;
- return PIPE_FORMAT_NONE;
-
- /* signed normalized formats */
- case GL_RED_SNORM:
- case GL_R8_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R8_SNORM,
- PIPE_FORMAT_R8G8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_R16_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R16_SNORM,
- PIPE_FORMAT_R16G16_SNORM,
- PIPE_FORMAT_R16G16B16A16_SNORM,
- PIPE_FORMAT_R8_SNORM,
- PIPE_FORMAT_R8G8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_RG_SNORM:
- case GL_RG8_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R8G8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_RG16_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R16G16_SNORM,
- PIPE_FORMAT_R16G16B16A16_SNORM,
- PIPE_FORMAT_R8G8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_RGB_SNORM:
- case GL_RGB8_SNORM:
- case GL_RGBA_SNORM:
- case GL_RGBA8_SNORM:
- if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
- target,
- sample_count, bindings))
- return PIPE_FORMAT_R8G8B8A8_SNORM;
- return PIPE_FORMAT_NONE;
-
- case GL_RGB16_SNORM:
- case GL_RGBA16_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_R16G16B16A16_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
-
- case GL_ALPHA_SNORM:
- case GL_ALPHA8_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_A8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_ALPHA16_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_A16_SNORM,
- PIPE_FORMAT_R16G16B16A16_SNORM,
- PIPE_FORMAT_A8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_LUMINANCE_SNORM:
- case GL_LUMINANCE8_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_L8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_LUMINANCE16_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_L16_SNORM,
- PIPE_FORMAT_R16G16B16A16_SNORM,
- PIPE_FORMAT_L8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_LUMINANCE_ALPHA_SNORM:
- case GL_LUMINANCE8_ALPHA8_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_L8A8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_LUMINANCE16_ALPHA16_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_L16A16_SNORM,
- PIPE_FORMAT_R16G16B16A16_SNORM,
- PIPE_FORMAT_L8A8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_INTENSITY_SNORM:
- case GL_INTENSITY8_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_I8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- case GL_INTENSITY16_SNORM:
- {
- static const enum pipe_format formats[] = {
- PIPE_FORMAT_I16_SNORM,
- PIPE_FORMAT_R16G16B16A16_SNORM,
- PIPE_FORMAT_I8_SNORM,
- PIPE_FORMAT_R8G8B8A8_SNORM,
- };
- return find_supported_format(screen, formats, Elements(formats),
- target, sample_count, bindings);
- }
-
- 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_RGBA_FLOAT32:
+ return PIPE_FORMAT_R32G32B32A32_FLOAT;
+ case MESA_FORMAT_RGBA_FLOAT16:
+ return PIPE_FORMAT_R16G16B16A16_FLOAT;
+ case MESA_FORMAT_RGB_FLOAT32:
+ return PIPE_FORMAT_R32G32B32_FLOAT;
+ case MESA_FORMAT_RGB_FLOAT16:
+ return PIPE_FORMAT_R16G16B16_FLOAT;
+ case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
+ return PIPE_FORMAT_L32A32_FLOAT;
+ case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
+ return PIPE_FORMAT_L16A16_FLOAT;
+ case MESA_FORMAT_LUMINANCE_FLOAT32:
+ return PIPE_FORMAT_L32_FLOAT;
+ case MESA_FORMAT_LUMINANCE_FLOAT16:
+ return PIPE_FORMAT_L16_FLOAT;
+ case MESA_FORMAT_ALPHA_FLOAT32:
+ return PIPE_FORMAT_A32_FLOAT;
+ case MESA_FORMAT_ALPHA_FLOAT16:
+ return PIPE_FORMAT_A16_FLOAT;
+ case MESA_FORMAT_INTENSITY_FLOAT32:
+ return PIPE_FORMAT_I32_FLOAT;
+ case MESA_FORMAT_INTENSITY_FLOAT16:
+ return PIPE_FORMAT_I16_FLOAT;
+ case MESA_FORMAT_R_FLOAT32:
+ return PIPE_FORMAT_R32_FLOAT;
+ case MESA_FORMAT_R_FLOAT16:
+ return PIPE_FORMAT_R16_FLOAT;
+ case MESA_FORMAT_RG_FLOAT32:
+ return PIPE_FORMAT_R32G32_FLOAT;
+ case MESA_FORMAT_RG_FLOAT16:
+ return PIPE_FORMAT_R16G16_FLOAT;
+
+ 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;
+
+ case MESA_FORMAT_L_LATC1:
+ return PIPE_FORMAT_LATC1_UNORM;
+ case MESA_FORMAT_SIGNED_L_LATC1:
+ return PIPE_FORMAT_LATC1_SNORM;
+ case MESA_FORMAT_LA_LATC2:
+ return PIPE_FORMAT_LATC2_UNORM;
+ case MESA_FORMAT_SIGNED_LA_LATC2:
+ return PIPE_FORMAT_LATC2_SNORM;
+
+ /* signed normalized formats */
+ case MESA_FORMAT_SIGNED_R8:
+ return PIPE_FORMAT_R8_SNORM;
+ case MESA_FORMAT_SIGNED_RG88_REV:
+ return PIPE_FORMAT_R8G8_SNORM;
+ case MESA_FORMAT_SIGNED_RGBA8888_REV:
+ return PIPE_FORMAT_R8G8B8A8_SNORM;
+
+ case MESA_FORMAT_SIGNED_A8:
+ return PIPE_FORMAT_A8_SNORM;
+ case MESA_FORMAT_SIGNED_L8:
+ return PIPE_FORMAT_L8_SNORM;
+ case MESA_FORMAT_SIGNED_AL88:
+ return PIPE_FORMAT_L8A8_SNORM;
+ case MESA_FORMAT_SIGNED_I8:
+ return PIPE_FORMAT_I8_SNORM;
+
+ case MESA_FORMAT_SIGNED_R16:
+ return PIPE_FORMAT_R16_SNORM;
+ case MESA_FORMAT_SIGNED_GR1616:
+ return PIPE_FORMAT_R16G16_SNORM;
+ case MESA_FORMAT_SIGNED_RGBA_16:
+ return PIPE_FORMAT_R16G16B16A16_SNORM;
+
+ case MESA_FORMAT_SIGNED_A16:
+ return PIPE_FORMAT_A16_SNORM;
+ case MESA_FORMAT_SIGNED_L16:
+ return PIPE_FORMAT_L16_SNORM;
+ case MESA_FORMAT_SIGNED_AL1616:
+ return PIPE_FORMAT_L16A16_SNORM;
+ case MESA_FORMAT_SIGNED_I16:
+ return PIPE_FORMAT_I16_SNORM;
+
+ case MESA_FORMAT_RGB9_E5_FLOAT:
+ return PIPE_FORMAT_R9G9B9E5_FLOAT;
+ case MESA_FORMAT_R11_G11_B10_FLOAT:
+ return PIPE_FORMAT_R11G11B10_FLOAT;
+
+ 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_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_R32G32B32A32_FLOAT:
+ return MESA_FORMAT_RGBA_FLOAT32;
+ case PIPE_FORMAT_R16G16B16A16_FLOAT:
+ return MESA_FORMAT_RGBA_FLOAT16;
+ case PIPE_FORMAT_R32G32B32_FLOAT:
+ return MESA_FORMAT_RGB_FLOAT32;
+ case PIPE_FORMAT_R16G16B16_FLOAT:
+ return MESA_FORMAT_RGB_FLOAT16;
+ case PIPE_FORMAT_L32A32_FLOAT:
+ return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32;
+ case PIPE_FORMAT_L16A16_FLOAT:
+ return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16;
+ case PIPE_FORMAT_L32_FLOAT:
+ return MESA_FORMAT_LUMINANCE_FLOAT32;
+ case PIPE_FORMAT_L16_FLOAT:
+ return MESA_FORMAT_LUMINANCE_FLOAT16;
+ case PIPE_FORMAT_A32_FLOAT:
+ return MESA_FORMAT_ALPHA_FLOAT32;
+ case PIPE_FORMAT_A16_FLOAT:
+ return MESA_FORMAT_ALPHA_FLOAT16;
+ case PIPE_FORMAT_I32_FLOAT:
+ return MESA_FORMAT_INTENSITY_FLOAT32;
+ case PIPE_FORMAT_I16_FLOAT:
+ return MESA_FORMAT_INTENSITY_FLOAT16;
+ case PIPE_FORMAT_R32_FLOAT:
+ return MESA_FORMAT_R_FLOAT32;
+ case PIPE_FORMAT_R16_FLOAT:
+ return MESA_FORMAT_R_FLOAT16;
+ case PIPE_FORMAT_R32G32_FLOAT:
+ return MESA_FORMAT_RG_FLOAT32;
+ case PIPE_FORMAT_R16G16_FLOAT:
+ return MESA_FORMAT_RG_FLOAT16;
+
+ 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;
+
+ case PIPE_FORMAT_LATC1_UNORM:
+ return MESA_FORMAT_L_LATC1;
+ case PIPE_FORMAT_LATC1_SNORM:
+ return MESA_FORMAT_SIGNED_L_LATC1;
+ case PIPE_FORMAT_LATC2_UNORM:
+ return MESA_FORMAT_LA_LATC2;
+ case PIPE_FORMAT_LATC2_SNORM:
+ return MESA_FORMAT_SIGNED_LA_LATC2;
+
+ /* signed normalized formats */
+ case PIPE_FORMAT_R8_SNORM:
+ return MESA_FORMAT_SIGNED_R8;
+ case PIPE_FORMAT_R8G8_SNORM:
+ return MESA_FORMAT_SIGNED_RG88_REV;
+ case PIPE_FORMAT_R8G8B8A8_SNORM:
+ return MESA_FORMAT_SIGNED_RGBA8888_REV;
+
+ case PIPE_FORMAT_A8_SNORM:
+ return MESA_FORMAT_SIGNED_A8;
+ case PIPE_FORMAT_L8_SNORM:
+ return MESA_FORMAT_SIGNED_L8;
+ case PIPE_FORMAT_L8A8_SNORM:
+ return MESA_FORMAT_SIGNED_AL88;
+ case PIPE_FORMAT_I8_SNORM:
+ return MESA_FORMAT_SIGNED_I8;
+
+ case PIPE_FORMAT_R16_SNORM:
+ return MESA_FORMAT_SIGNED_R16;
+ case PIPE_FORMAT_R16G16_SNORM:
+ return MESA_FORMAT_SIGNED_GR1616;
+ case PIPE_FORMAT_R16G16B16A16_SNORM:
+ return MESA_FORMAT_SIGNED_RGBA_16;
+
+ case PIPE_FORMAT_A16_SNORM:
+ return MESA_FORMAT_SIGNED_A16;
+ case PIPE_FORMAT_L16_SNORM:
+ return MESA_FORMAT_SIGNED_L16;
+ case PIPE_FORMAT_L16A16_SNORM:
+ return MESA_FORMAT_SIGNED_AL1616;
+ case PIPE_FORMAT_I16_SNORM:
+ return MESA_FORMAT_SIGNED_I16;
+
+ case PIPE_FORMAT_R9G9B9E5_FLOAT:
+ return MESA_FORMAT_RGB9_E5_FLOAT;
+ case PIPE_FORMAT_R11G11B10_FLOAT:
+ return MESA_FORMAT_R11_G11_B10_FLOAT;
+
+ 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)
+{
+ uint i;
+ for (i = 0; i < num_formats; i++) {
+ if (screen->is_format_supported(screen, formats[i], target,
+ sample_count, tex_usage)) {
+ 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)
+{
+ 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);
+}
+
+
+/**
+ * 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)
+{
+ 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);
+}
+
+/**
+ * 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)
+{
+ 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);
+}
+
+
+/**
+ * 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)
+{
+
+ switch (internalFormat) {
+ case GL_RGB10:
+ case GL_RGB10_A2:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B10G10R10A2_UNORM,
+ target, sample_count, bindings))
+ return PIPE_FORMAT_B10G10R10A2_UNORM;
+ /* Pass through. */
+ case 4:
+ case GL_RGBA:
+ case GL_RGBA8:
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ case GL_BGRA:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B8G8R8A8_UNORM,
+ target, sample_count, bindings))
+ return PIPE_FORMAT_B8G8R8A8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ case 3:
+ case GL_RGB:
+ case GL_RGB8:
+ return default_rgb_format( screen, target, sample_count, bindings);
+
+ 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))
+ return PIPE_FORMAT_R16G16B16A16_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ case GL_RGBA4:
+ case GL_RGBA2:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B4G4R4A4_UNORM,
+ target, sample_count, bindings))
+ return PIPE_FORMAT_B4G4R4A4_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ case GL_RGB5_A1:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM,
+ target, sample_count, bindings))
+ return PIPE_FORMAT_B5G5R5A1_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ case GL_R3_G3_B2:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B2G3R3_UNORM,
+ target, sample_count, bindings))
+ 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))
+ return PIPE_FORMAT_B5G6R5_UNORM;
+ if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM,
+ target, sample_count, bindings))
+ return PIPE_FORMAT_B5G5R5A1_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ case GL_ALPHA12:
+ case GL_ALPHA16:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_A16_UNORM, target,
+ sample_count, bindings))
+ 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))
+ return PIPE_FORMAT_A8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ case GL_LUMINANCE12:
+ case GL_LUMINANCE16:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L16_UNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_L16_UNORM;
+ /* Pass through. */
+ case 1:
+ case GL_LUMINANCE:
+ case GL_LUMINANCE4:
+ case GL_LUMINANCE8:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_L8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ 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))
+ return PIPE_FORMAT_L16A16_UNORM;
+ /* Pass through. */
+ case 2:
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE6_ALPHA2:
+ case GL_LUMINANCE8_ALPHA8:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_UNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_L8A8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ case GL_LUMINANCE4_ALPHA4:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L4A4_UNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_L4A4_UNORM;
+ if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_UNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_L8A8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ case GL_INTENSITY12:
+ case GL_INTENSITY16:
+ if (screen->is_format_supported( screen, PIPE_FORMAT_I16_UNORM, target,
+ sample_count, bindings))
+ 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))
+ return PIPE_FORMAT_I8_UNORM;
+ return default_rgba_format( screen, target, sample_count, bindings);
+
+ case GL_YCBCR_MESA:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY, target,
+ sample_count, bindings)) {
+ return PIPE_FORMAT_UYVY;
+ }
+ if (screen->is_format_supported(screen, PIPE_FORMAT_YUYV, target,
+ sample_count, bindings)) {
+ 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))
+ return PIPE_FORMAT_DXT1_RGB;
+ else
+ return default_rgb_format(screen, target, sample_count, bindings);
+
+ 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))
+ return PIPE_FORMAT_DXT3_RGBA;
+ else
+ return default_rgba_format(screen, target, sample_count, bindings);
+
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ return PIPE_FORMAT_Z24_UNORM_S8_USCALED;
+ if (screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
+ target, sample_count, bindings))
+ 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))
+ 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);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+ 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);
+
+ 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))
+ return PIPE_FORMAT_DXT1_SRGB;
+ return default_srgba_format( screen, target, sample_count, bindings);
+
+ 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))
+ return PIPE_FORMAT_DXT3_SRGBA;
+ return default_srgba_format( screen, target, sample_count, bindings);
+
+ 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))
+ return PIPE_FORMAT_L8A8_SRGB;
+ return default_srgba_format( screen, target, sample_count, bindings);
+
+ case GL_SLUMINANCE_EXT:
+ case GL_SLUMINANCE8_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_L8_SRGB, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_L8_SRGB;
+ return default_srgba_format( screen, target, sample_count, bindings);
+
+ /* prefer formats in order of data size, choosing 16-bit ones if equal sized */
+ case GL_RGBA16F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_RGB16F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R16G16B16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_FORMAT_R32G32B32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_LUMINANCE_ALPHA16F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_L16A16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_FORMAT_L32A32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_ALPHA16F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_A16_FLOAT,
+ PIPE_FORMAT_L16A16_FLOAT,
+ PIPE_FORMAT_A32_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_FORMAT_L32A32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_INTENSITY16F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_I16_FLOAT,
+ PIPE_FORMAT_L16A16_FLOAT,
+ PIPE_FORMAT_I32_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_FORMAT_L32A32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_LUMINANCE16F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_L16_FLOAT,
+ PIPE_FORMAT_L16A16_FLOAT,
+ PIPE_FORMAT_L32_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_FORMAT_L32A32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_R16F:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R16_FLOAT,
+ PIPE_FORMAT_R16G16_FLOAT,
+ PIPE_FORMAT_R32_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_FORMAT_R32G32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_RG16F:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R16G16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_FORMAT_R32G32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ /* try a 32-bit format if available, otherwise fallback to a 16-bit one */
+ case GL_RGBA32F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_RGB32F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R32G32B32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_LUMINANCE_ALPHA32F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_L32A32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_FORMAT_L16A16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_ALPHA32F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_A32_FLOAT,
+ PIPE_FORMAT_L32A32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_FORMAT_A16_FLOAT,
+ PIPE_FORMAT_L16A16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_INTENSITY32F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_I32_FLOAT,
+ PIPE_FORMAT_L32A32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_FORMAT_I16_FLOAT,
+ PIPE_FORMAT_L16A16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_LUMINANCE32F_ARB:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_L32_FLOAT,
+ PIPE_FORMAT_L32A32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_FORMAT_L16_FLOAT,
+ PIPE_FORMAT_L16A16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_R32F:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R32_FLOAT,
+ PIPE_FORMAT_R32G32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_FORMAT_R16_FLOAT,
+ PIPE_FORMAT_R16G16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+ case GL_RG32F:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R32G32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_FORMAT_R16G16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_FLOAT
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_RED:
+ case GL_R8:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM, target,
+ sample_count, bindings))
+ 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))
+ 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))
+ 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))
+ 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))
+ return PIPE_FORMAT_RGTC1_UNORM;
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM, target,
+ sample_count, bindings))
+ 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))
+ 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))
+ return PIPE_FORMAT_RGTC2_UNORM;
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM, target,
+ sample_count, bindings))
+ 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))
+ return PIPE_FORMAT_RGTC2_SNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_LUMINANCE:
+ case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_LATC1_UNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_LATC1_UNORM;
+ if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_L8_UNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_LATC1_SNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_LATC1_SNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_LUMINANCE_ALPHA:
+ case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
+ case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_LATC2_UNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_LATC2_UNORM;
+ if (screen->is_format_supported(screen, PIPE_FORMAT_L8A8_UNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_L8A8_UNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_LATC2_SNORM, target,
+ sample_count, bindings))
+ return PIPE_FORMAT_LATC2_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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ return PIPE_FORMAT_R32G32B32A32_USCALED;
+ return PIPE_FORMAT_NONE;
+
+ /* signed normalized formats */
+ case GL_RED_SNORM:
+ case GL_R8_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R8_SNORM,
+ PIPE_FORMAT_R8G8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_R16_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R16_SNORM,
+ PIPE_FORMAT_R16G16_SNORM,
+ PIPE_FORMAT_R16G16B16A16_SNORM,
+ PIPE_FORMAT_R8_SNORM,
+ PIPE_FORMAT_R8G8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_RG_SNORM:
+ case GL_RG8_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R8G8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_RG16_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R16G16_SNORM,
+ PIPE_FORMAT_R16G16B16A16_SNORM,
+ PIPE_FORMAT_R8G8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_RGB_SNORM:
+ case GL_RGB8_SNORM:
+ case GL_RGBA_SNORM:
+ case GL_RGBA8_SNORM:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
+ target,
+ sample_count, bindings))
+ return PIPE_FORMAT_R8G8B8A8_SNORM;
+ return PIPE_FORMAT_NONE;
+
+ case GL_RGB16_SNORM:
+ case GL_RGBA16_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_R16G16B16A16_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+
+ case GL_ALPHA_SNORM:
+ case GL_ALPHA8_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_A8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_ALPHA16_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_A16_SNORM,
+ PIPE_FORMAT_R16G16B16A16_SNORM,
+ PIPE_FORMAT_A8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_LUMINANCE_SNORM:
+ case GL_LUMINANCE8_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_L8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_LUMINANCE16_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_L16_SNORM,
+ PIPE_FORMAT_R16G16B16A16_SNORM,
+ PIPE_FORMAT_L8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_LUMINANCE_ALPHA_SNORM:
+ case GL_LUMINANCE8_ALPHA8_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_L8A8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_LUMINANCE16_ALPHA16_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_L16A16_SNORM,
+ PIPE_FORMAT_R16G16B16A16_SNORM,
+ PIPE_FORMAT_L8A8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_INTENSITY_SNORM:
+ case GL_INTENSITY8_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_I8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_INTENSITY16_SNORM:
+ {
+ static const enum pipe_format formats[] = {
+ PIPE_FORMAT_I16_SNORM,
+ PIPE_FORMAT_R16G16B16A16_SNORM,
+ PIPE_FORMAT_I8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ };
+ return find_supported_format(screen, formats, Elements(formats),
+ target, sample_count, bindings);
+ }
+
+ case GL_RGB9_E5:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R9G9B9E5_FLOAT, target,
+ sample_count, bindings)) {
+ return PIPE_FORMAT_R9G9B9E5_FLOAT;
+ }
+ return PIPE_FORMAT_NONE;
+
+ case GL_R11F_G11F_B10F:
+ if (screen->is_format_supported(screen, PIPE_FORMAT_R11G11B10_FLOAT, target,
+ sample_count, bindings)) {
+ return PIPE_FORMAT_R11G11B10_FLOAT;
+ }
+ 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);
+ }
+}